aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-21 15:11:44 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-21 15:11:44 -0500
commitb5c78e04dd061b776978dad61dd85357081147b0 (patch)
tree2416b2dc61c452c3aeb2a32bcedf15e6257be638
parent06991c28f37ad68e5c03777f5c3b679b56e3dac1 (diff)
parent951348b377385475aa256c27e1c9e2564c9ec160 (diff)
Merge tag 'staging-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging tree update from Greg Kroah-Hartman: "Here's the big staging tree merge for 3.9-rc1 Lots of cleanups and updates for drivers all through the staging tree. We are pretty much "code neutral" here, adding just about as many lines as we removed. All of these have been in linux-next for a while." * tag 'staging-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (804 commits) staging: comedi: vmk80xx: wait for URBs to complete staging: comedi: drivers: addi-data: hwdrv_apci3200.c: Add a missing semicolon staging: et131x: Update TODO list staging: et131x: Remove assignment of skb->dev staging: wlan-ng: hfa384x.h: fix for error reported by smatch staging/zache checkpatch ERROR: spaces prohibited around that staging/ozwpan: Mark read only parameters and structs as const staging/ozwpan: Remove empty and unused function oz_cdev_heartbeat staging/ozwpan: Mark local functions as static (fix sparse warnings) staging/ozwpan: Add missing header includes staging/usbip: Mark local functions as static (fix sparse warnings) staging/xgifb: Remove duplicated code in loops. staging/xgifb: Consolidate return paths staging/xgifb: Remove code without effect staging/xgifb: Remove unnecessary casts staging/xgifb: Consolidate if/else if with identical code branches staging: vt6656: replaced custom TRUE definition with true staging: vt6656: replaced custom FALSE definition with false staging: vt6656: replace custom BOOL definition with bool staging/rtl8187se: Mark functions as static to silence sparse ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio-mpu605013
-rw-r--r--Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt6
-rw-r--r--MAINTAINERS3
-rw-r--r--arch/arm/boot/dts/imx23.dtsi2
-rw-r--r--arch/arm/mach-omap2/board-rx51-peripherals.c2
-rw-r--r--drivers/extcon/extcon-adc-jack.c3
-rw-r--r--drivers/iio/accel/Kconfig38
-rw-r--r--drivers/iio/accel/Makefile9
-rw-r--r--drivers/iio/accel/hid-sensor-accel-3d.c3
-rw-r--r--drivers/iio/accel/kxsd9.c (renamed from drivers/staging/iio/accel/kxsd9.c)16
-rw-r--r--drivers/iio/accel/st_accel.h47
-rw-r--r--drivers/iio/accel/st_accel_buffer.c114
-rw-r--r--drivers/iio/accel/st_accel_core.c500
-rw-r--r--drivers/iio/accel/st_accel_i2c.c86
-rw-r--r--drivers/iio/accel/st_accel_spi.c85
-rw-r--r--drivers/iio/adc/Kconfig4
-rw-r--r--drivers/iio/adc/lp8788_adc.c18
-rw-r--r--drivers/iio/adc/max1363.c167
-rw-r--r--drivers/iio/buffer_cb.c4
-rw-r--r--drivers/iio/common/Kconfig1
-rw-r--r--drivers/iio/common/Makefile1
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-attributes.c11
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-attributes.h57
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-trigger.c5
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-trigger.h2
-rw-r--r--drivers/iio/common/st_sensors/Kconfig14
-rw-r--r--drivers/iio/common/st_sensors/Makefile10
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_buffer.c116
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c446
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_i2c.c81
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_spi.c128
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_trigger.c77
-rw-r--r--drivers/iio/dac/ad5360.c7
-rw-r--r--drivers/iio/dac/ad5421.c7
-rw-r--r--drivers/iio/dac/ad5504.c6
-rw-r--r--drivers/iio/dac/ad5686.c7
-rw-r--r--drivers/iio/dac/ad5755.c7
-rw-r--r--drivers/iio/dac/ad5764.c7
-rw-r--r--drivers/iio/dac/ad5791.c6
-rw-r--r--drivers/iio/frequency/ad9523.c14
-rw-r--r--drivers/iio/gyro/Kconfig55
-rw-r--r--drivers/iio/gyro/Makefile14
-rw-r--r--drivers/iio/gyro/adis16080.c (renamed from drivers/staging/iio/gyro/adis16080_core.c)154
-rw-r--r--drivers/iio/gyro/adxrs450.c (renamed from drivers/staging/iio/gyro/adxrs450_core.c)202
-rw-r--r--drivers/iio/gyro/hid-sensor-gyro-3d.c3
-rw-r--r--drivers/iio/gyro/itg3200_buffer.c156
-rw-r--r--drivers/iio/gyro/itg3200_core.c401
-rw-r--r--drivers/iio/gyro/st_gyro.h45
-rw-r--r--drivers/iio/gyro/st_gyro_buffer.c114
-rw-r--r--drivers/iio/gyro/st_gyro_core.c368
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c84
-rw-r--r--drivers/iio/gyro/st_gyro_spi.c83
-rw-r--r--drivers/iio/imu/Kconfig13
-rw-r--r--drivers/iio/imu/Makefile5
-rw-r--r--drivers/iio/imu/adis16400.h (renamed from drivers/staging/iio/imu/adis16400.h)141
-rw-r--r--drivers/iio/imu/adis16400_buffer.c96
-rw-r--r--drivers/iio/imu/adis16400_core.c965
-rw-r--r--drivers/iio/imu/inv_mpu6050/Kconfig13
-rw-r--r--drivers/iio/imu/inv_mpu6050/Makefile6
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_core.c795
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h246
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c196
-rw-r--r--drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c155
-rw-r--r--drivers/iio/industrialio-trigger.c12
-rw-r--r--drivers/iio/inkern.c53
-rw-r--r--drivers/iio/kfifo_buf.c1
-rw-r--r--drivers/iio/light/Kconfig10
-rw-r--r--drivers/iio/light/Makefile1
-rw-r--r--drivers/iio/light/hid-sensor-als.c3
-rw-r--r--drivers/iio/light/tsl2563.c (renamed from drivers/staging/iio/light/tsl2563.c)96
-rw-r--r--drivers/iio/magnetometer/Kconfig30
-rw-r--r--drivers/iio/magnetometer/Makefile7
-rw-r--r--drivers/iio/magnetometer/hid-sensor-magn-3d.c3
-rw-r--r--drivers/iio/magnetometer/st_magn.h45
-rw-r--r--drivers/iio/magnetometer/st_magn_buffer.c98
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c400
-rw-r--r--drivers/iio/magnetometer/st_magn_i2c.c80
-rw-r--r--drivers/iio/magnetometer/st_magn_spi.c79
-rw-r--r--drivers/platform/Kconfig4
-rw-r--r--drivers/platform/Makefile1
-rw-r--r--drivers/platform/goldfish/Kconfig5
-rw-r--r--drivers/platform/goldfish/Makefile5
-rw-r--r--drivers/platform/goldfish/goldfish_pipe.c612
-rw-r--r--drivers/platform/goldfish/pdev_bus.c240
-rw-r--r--drivers/power/generic-adc-battery.c4
-rw-r--r--drivers/power/lp8788-charger.c8
-rw-r--r--drivers/rtc/Kconfig16
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-hid-sensor-time.c292
-rw-r--r--drivers/staging/Kconfig8
-rw-r--r--drivers/staging/Makefile4
-rw-r--r--drivers/staging/android/Kconfig29
-rw-r--r--drivers/staging/android/alarm-dev.c277
-rw-r--r--drivers/staging/android/android_alarm.h19
-rw-r--r--drivers/staging/android/binder.c6
-rw-r--r--drivers/staging/android/binder.h4
-rw-r--r--drivers/staging/asus_oled/asus_oled.c15
-rw-r--r--drivers/staging/bcm/Adapter.h20
-rw-r--r--drivers/staging/bcm/Bcmchar.c14
-rw-r--r--drivers/staging/bcm/CmHost.c6
-rw-r--r--drivers/staging/bcm/CmHost.h12
-rw-r--r--drivers/staging/bcm/Debug.h356
-rw-r--r--drivers/staging/bcm/IPv6Protocol.c34
-rw-r--r--drivers/staging/bcm/IPv6ProtocolHdr.h149
-rw-r--r--drivers/staging/bcm/InterfaceDld.c6
-rw-r--r--drivers/staging/bcm/InterfaceInit.c14
-rw-r--r--drivers/staging/bcm/Ioctl.h6
-rw-r--r--drivers/staging/bcm/Macros.h25
-rw-r--r--drivers/staging/bcm/Misc.c10
-rw-r--r--drivers/staging/bcm/PHSDefines.h200
-rw-r--r--drivers/staging/bcm/PHSModule.c160
-rw-r--r--drivers/staging/bcm/PHSModule.h14
-rw-r--r--drivers/staging/bcm/Protocol.h177
-rw-r--r--drivers/staging/bcm/Prototypes.h6
-rw-r--r--drivers/staging/bcm/Qos.c46
-rw-r--r--drivers/staging/bcm/hostmibs.c12
-rw-r--r--drivers/staging/bcm/led_control.c8
-rw-r--r--drivers/staging/bcm/led_control.h138
-rw-r--r--drivers/staging/bcm/nvm.c87
-rw-r--r--drivers/staging/bcm/nvm.h665
-rw-r--r--drivers/staging/bcm/target_params.h128
-rw-r--r--drivers/staging/bcm/vendorspecificextn.c2
-rw-r--r--drivers/staging/bcm/vendorspecificextn.h2
-rw-r--r--drivers/staging/ced1401/ced_ioc.c18
-rw-r--r--drivers/staging/ced1401/usb1401.c14
-rw-r--r--drivers/staging/ced1401/usb1401.h2
-rw-r--r--drivers/staging/comedi/Kconfig46
-rw-r--r--drivers/staging/comedi/Makefile19
-rw-r--r--drivers/staging/comedi/comedi.h12
-rw-r--r--drivers/staging/comedi/comedi_buf.c415
-rw-r--r--drivers/staging/comedi/comedi_compat32.c4
-rw-r--r--drivers/staging/comedi/comedi_fops.c1007
-rw-r--r--drivers/staging/comedi/comedi_internal.h33
-rw-r--r--drivers/staging/comedi/comedi_pci.c140
-rw-r--r--drivers/staging/comedi/comedi_pcmcia.c160
-rw-r--r--drivers/staging/comedi/comedi_usb.c108
-rw-r--r--drivers/staging/comedi/comedidev.h370
-rw-r--r--drivers/staging/comedi/drivers.c859
-rw-r--r--drivers/staging/comedi/drivers/8255_pci.c9
-rw-r--r--drivers/staging/comedi/drivers/Makefile4
-rw-r--r--drivers/staging/comedi/drivers/addi-data/addi_common.c26
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c807
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c263
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c2
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c589
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_035.c9
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1032.c10
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1500.c9
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1516.c114
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1564.c9
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_16xx.c257
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1710.c9
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_2032.c282
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_2200.c187
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3120.c9
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3200.c9
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3501.c482
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3xxx.c9
-rw-r--r--drivers/staging/comedi/drivers/addi_watchdog.c172
-rw-r--r--drivers/staging/comedi/drivers/addi_watchdog.h10
-rw-r--r--drivers/staging/comedi/drivers/adl_pci6208.c9
-rw-r--r--drivers/staging/comedi/drivers/adl_pci7x3x.c17
-rw-r--r--drivers/staging/comedi/drivers/adl_pci8164.c39
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9111.c12
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9118.c13
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1710.c8
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1723.c9
-rw-r--r--drivers/staging/comedi/drivers/adv_pci_dio.c12
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200.c20
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc236.c8
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc263.c9
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci224.c8
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci230.c12
-rw-r--r--drivers/staging/comedi/drivers/cb_das16_cs.c132
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas.c11
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas64.c12
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidda.c9
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdas.c12
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdda.c9
-rw-r--r--drivers/staging/comedi/drivers/comedi_bond.c5
-rw-r--r--drivers/staging/comedi/drivers/comedi_test.c75
-rw-r--r--drivers/staging/comedi/drivers/contec_pci_dio.c9
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c14
-rw-r--r--drivers/staging/comedi/drivers/das08.c358
-rw-r--r--drivers/staging/comedi/drivers/das08.h2
-rw-r--r--drivers/staging/comedi/drivers/das08_cs.c152
-rw-r--r--drivers/staging/comedi/drivers/das08_isa.c217
-rw-r--r--drivers/staging/comedi/drivers/das08_pci.c121
-rw-r--r--drivers/staging/comedi/drivers/das16.c2
-rw-r--r--drivers/staging/comedi/drivers/dt3000.c11
-rw-r--r--drivers/staging/comedi/drivers/dt9812.c30
-rw-r--r--drivers/staging/comedi/drivers/dyna_pci10xx.c11
-rw-r--r--drivers/staging/comedi/drivers/gsc_hpdi.c11
-rw-r--r--drivers/staging/comedi/drivers/icp_multi.c13
-rw-r--r--drivers/staging/comedi/drivers/jr3_pci.c15
-rw-r--r--drivers/staging/comedi/drivers/ke_counter.c9
-rw-r--r--drivers/staging/comedi/drivers/me4000.c14
-rw-r--r--drivers/staging/comedi/drivers/me_daq.c9
-rw-r--r--drivers/staging/comedi/drivers/mite.c5
-rw-r--r--drivers/staging/comedi/drivers/ni_6527.c9
-rw-r--r--drivers/staging/comedi/drivers/ni_65xx.c10
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c10
-rw-r--r--drivers/staging/comedi/drivers/ni_670x.c9
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_700.c119
-rw-r--r--drivers/staging/comedi/drivers/ni_daq_dio24.c303
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc.c55
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_cs.c257
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_common.c4
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_cs.c399
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c9
-rw-r--r--drivers/staging/comedi/drivers/ni_pcimio.c11
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.c2
-rw-r--r--drivers/staging/comedi/drivers/ni_tiocmd.c1
-rw-r--r--drivers/staging/comedi/drivers/pcl818.c19
-rw-r--r--drivers/staging/comedi/drivers/pcm_common.c63
-rw-r--r--drivers/staging/comedi/drivers/pcm_common.h8
-rw-r--r--drivers/staging/comedi/drivers/pcmda12.c3
-rw-r--r--drivers/staging/comedi/drivers/pcmmio.c62
-rw-r--r--drivers/staging/comedi/drivers/pcmuio.c72
-rw-r--r--drivers/staging/comedi/drivers/quatech_daqp_cs.c589
-rw-r--r--drivers/staging/comedi/drivers/rtd520.c10
-rw-r--r--drivers/staging/comedi/drivers/s626.c8
-rw-r--r--drivers/staging/comedi/drivers/skel.c12
-rw-r--r--drivers/staging/comedi/drivers/unioxx5.c6
-rw-r--r--drivers/staging/comedi/drivers/usbdux.c29
-rw-r--r--drivers/staging/comedi/drivers/usbduxfast.c8
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c33
-rw-r--r--drivers/staging/comedi/drivers/vmk80xx.c1272
-rw-r--r--drivers/staging/comedi/kcomedilib/kcomedilib_main.c8
-rw-r--r--drivers/staging/comedi/proc.c9
-rw-r--r--drivers/staging/cptm1217/clearpad_tm1217.c5
-rw-r--r--drivers/staging/csr/drv.c6
-rw-r--r--drivers/staging/csr/sme_sys.c41
-rw-r--r--drivers/staging/csr/unifi_sme.c1
-rw-r--r--drivers/staging/cxt1e1/linux.c4
-rw-r--r--drivers/staging/dgrp/dgrp_specproc.c81
-rw-r--r--drivers/staging/echo/echo.c42
-rw-r--r--drivers/staging/et131x/README4
-rw-r--r--drivers/staging/et131x/et131x.c791
-rw-r--r--drivers/staging/et131x/et131x.h96
-rw-r--r--drivers/staging/frontier/alphatrack.c51
-rw-r--r--drivers/staging/frontier/tranzport.c26
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000.h33
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c21
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c10
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_debug.c153
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_download.c110
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_hw.c166
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_proc.c6
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.c39
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.h84
-rw-r--r--drivers/staging/ft1000/ft1000.h35
-rw-r--r--drivers/staging/fwserial/TODO15
-rw-r--r--drivers/staging/fwserial/fwserial.c361
-rw-r--r--drivers/staging/fwserial/fwserial.h25
-rw-r--r--drivers/staging/gdm72xx/gdm_sdio.c8
-rw-r--r--drivers/staging/gdm72xx/sdio_boot.c9
-rw-r--r--drivers/staging/gdm72xx/usb_boot.c8
-rw-r--r--drivers/staging/goldfish/Kconfig13
-rw-r--r--drivers/staging/goldfish/Makefile6
-rw-r--r--drivers/staging/goldfish/README12
-rw-r--r--drivers/staging/goldfish/goldfish_audio.c363
-rw-r--r--drivers/staging/goldfish/goldfish_nand.c444
-rw-r--r--drivers/staging/goldfish/goldfish_nand_reg.h72
-rw-r--r--drivers/staging/iio/Kconfig14
-rw-r--r--drivers/staging/iio/Makefile3
-rw-r--r--drivers/staging/iio/accel/Kconfig30
-rw-r--r--drivers/staging/iio/accel/Makefile2
-rw-r--r--drivers/staging/iio/accel/lis3l02dq.h8
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_core.c18
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c12
-rw-r--r--drivers/staging/iio/accel/sca3000_core.c13
-rw-r--r--drivers/staging/iio/accel/sca3000_ring.c6
-rw-r--r--drivers/staging/iio/adc/Kconfig4
-rw-r--r--drivers/staging/iio/adc/ad7280a.c6
-rw-r--r--drivers/staging/iio/adc/mxs-lradc.c525
-rw-r--r--drivers/staging/iio/frequency/ad5930.c5
-rw-r--r--drivers/staging/iio/frequency/ad9850.c5
-rw-r--r--drivers/staging/iio/frequency/ad9852.c5
-rw-r--r--drivers/staging/iio/gyro/Kconfig17
-rw-r--r--drivers/staging/iio/gyro/Makefile9
-rw-r--r--drivers/staging/iio/gyro/adxrs450.h62
-rw-r--r--drivers/staging/iio/iio_hwmon.c83
-rw-r--r--drivers/staging/iio/iio_simple_dummy.c4
-rw-r--r--drivers/staging/iio/iio_simple_dummy_buffer.c2
-rw-r--r--drivers/staging/iio/impedance-analyzer/Kconfig2
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c8
-rw-r--r--drivers/staging/iio/imu/Kconfig17
-rw-r--r--drivers/staging/iio/imu/Makefile7
-rw-r--r--drivers/staging/iio/imu/adis16400_core.c1320
-rw-r--r--drivers/staging/iio/imu/adis16400_ring.c204
-rw-r--r--drivers/staging/iio/imu/adis16400_trigger.c74
-rw-r--r--drivers/staging/iio/light/Kconfig10
-rw-r--r--drivers/staging/iio/light/Makefile1
-rw-r--r--drivers/staging/iio/light/tsl2x7x_core.c78
-rw-r--r--drivers/staging/iio/meter/Kconfig2
-rw-r--r--drivers/staging/iio/meter/ade7753.c6
-rw-r--r--drivers/staging/iio/meter/ade7754.c5
-rw-r--r--drivers/staging/iio/meter/ade7758_core.c28
-rw-r--r--drivers/staging/iio/meter/ade7758_ring.c12
-rw-r--r--drivers/staging/iio/meter/ade7759.c5
-rw-r--r--drivers/staging/iio/meter/ade7854-spi.c44
-rw-r--r--drivers/staging/iio/resolver/ad2s1210.c5
-rw-r--r--drivers/staging/iio/ring_sw.c366
-rw-r--r--drivers/staging/iio/ring_sw.h30
-rw-r--r--drivers/staging/imx-drm/ipu-v3/ipu-common.c3
-rw-r--r--drivers/staging/imx-drm/ipu-v3/ipu-di.c2
-rw-r--r--drivers/staging/keucr/usb.c188
-rw-r--r--drivers/staging/line6/Kconfig10
-rw-r--r--drivers/staging/line6/capture.c10
-rw-r--r--drivers/staging/line6/driver.c86
-rw-r--r--drivers/staging/line6/driver.h13
-rw-r--r--drivers/staging/line6/midi.c2
-rw-r--r--drivers/staging/line6/midi.h4
-rw-r--r--drivers/staging/line6/midibuf.c25
-rw-r--r--drivers/staging/line6/midibuf.h22
-rw-r--r--drivers/staging/line6/pcm.c36
-rw-r--r--drivers/staging/line6/playback.c9
-rw-r--r--drivers/staging/line6/pod.c105
-rw-r--r--drivers/staging/line6/toneport.c6
-rw-r--r--drivers/staging/line6/variax.c14
-rw-r--r--drivers/staging/nvec/nvec.c82
-rw-r--r--drivers/staging/nvec/nvec.h5
-rw-r--r--drivers/staging/nvec/nvec_kbd.c42
-rw-r--r--drivers/staging/nvec/nvec_power.c8
-rw-r--r--drivers/staging/nvec/nvec_ps2.c37
-rw-r--r--drivers/staging/omap-thermal/omap-bandgap.c2
-rw-r--r--drivers/staging/omap-thermal/omap-thermal-common.c4
-rw-r--r--drivers/staging/omapdrm/omap_connector.c4
-rw-r--r--drivers/staging/omapdrm/omap_crtc.c5
-rw-r--r--drivers/staging/omapdrm/omap_dmm_priv.h5
-rw-r--r--drivers/staging/omapdrm/omap_dmm_tiler.c172
-rw-r--r--drivers/staging/omapdrm/omap_drv.c18
-rw-r--r--drivers/staging/omapdrm/omap_drv.h4
-rw-r--r--drivers/staging/omapdrm/omap_encoder.c4
-rw-r--r--drivers/staging/omapdrm/omap_fb.c1
-rw-r--r--drivers/staging/omapdrm/omap_fbdev.c4
-rw-r--r--drivers/staging/omapdrm/omap_gem.c42
-rw-r--r--drivers/staging/omapdrm/omap_gem_dmabuf.c6
-rw-r--r--drivers/staging/omapdrm/omap_plane.c4
-rw-r--r--drivers/staging/omapdrm/tcm.h2
-rw-r--r--drivers/staging/ozwpan/TODO3
-rw-r--r--drivers/staging/ozwpan/ozcdev.c52
-rw-r--r--drivers/staging/ozwpan/ozcdev.h1
-rw-r--r--drivers/staging/ozwpan/ozeltbuf.c18
-rw-r--r--drivers/staging/ozwpan/ozevent.c8
-rw-r--r--drivers/staging/ozwpan/ozhcd.c152
-rw-r--r--drivers/staging/ozwpan/ozmain.c2
-rw-r--r--drivers/staging/ozwpan/ozpd.c88
-rw-r--r--drivers/staging/ozwpan/ozpd.h4
-rw-r--r--drivers/staging/ozwpan/ozproto.c84
-rw-r--r--drivers/staging/ozwpan/ozproto.h2
-rw-r--r--drivers/staging/ozwpan/ozusbif.h8
-rw-r--r--drivers/staging/ozwpan/ozusbsvc.c22
-rw-r--r--drivers/staging/ozwpan/ozusbsvc1.c26
-rw-r--r--drivers/staging/panel/panel.c31
-rw-r--r--drivers/staging/ramster/Kconfig31
-rw-r--r--drivers/staging/ramster/Makefile6
-rw-r--r--drivers/staging/ramster/tmem.c894
-rw-r--r--drivers/staging/ramster/tmem.h259
-rw-r--r--drivers/staging/ramster/zcache-main.c1820
-rw-r--r--drivers/staging/rtl8187se/ieee80211/dot11d.c71
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_module.c4
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c6
-rw-r--r--drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c408
-rw-r--r--drivers/staging/rtl8187se/r8185b_init.c301
-rw-r--r--drivers/staging/rtl8192u/changes1
-rw-r--r--drivers/staging/rtl8192u/ieee80211/Makefile1
-rw-r--r--drivers/staging/rtl8192u/ieee80211/aes.c3
-rw-r--r--drivers/staging/rtl8192u/ieee80211/arc4.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/crypto_compat.h2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/dot11d.c1
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211.h102
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_module.c8
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c394
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c280
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c31
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c54
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/internal.h1
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h6
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c63
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h13
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c124
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h83
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h3
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c18
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl_crypto.h93
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.c2
-rw-r--r--drivers/staging/rtl8192u/r8180_pm.h2
-rw-r--r--drivers/staging/rtl8192u/r8190_rtl8256.c13
-rw-r--r--drivers/staging/rtl8192u/r8192U.h299
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c589
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.c197
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.h24
-rw-r--r--drivers/staging/rtl8192u/r8192U_hw.h16
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.c37
-rw-r--r--drivers/staging/rtl8192u/r819xU_HTGen.h1
-rw-r--r--drivers/staging/rtl8192u/r819xU_HTType.h9
-rw-r--r--drivers/staging/rtl8192u/r819xU_cmdpkt.c38
-rw-r--r--drivers/staging/rtl8192u/r819xU_cmdpkt.h44
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.c109
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.h1
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.c127
-rw-r--r--drivers/staging/rtl8192u/r819xU_phyreg.h1044
-rw-r--r--drivers/staging/rtl8712/ethernet.h7
-rw-r--r--drivers/staging/rtl8712/hal_init.c17
-rw-r--r--drivers/staging/rtl8712/ieee80211.h2
-rw-r--r--drivers/staging/rtl8712/mlme_linux.c2
-rw-r--r--drivers/staging/rtl8712/os_intfs.c3
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.c1
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c66
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_rtl.c181
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.c2
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c9
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp.h56
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp_ioctl.c393
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.h6
-rw-r--r--drivers/staging/rtl8712/sta_info.h2
-rw-r--r--drivers/staging/rtl8712/usb_intf.c33
-rw-r--r--drivers/staging/rtl8712/usb_ops_linux.c15
-rw-r--r--drivers/staging/rtl8712/wifi.h171
-rw-r--r--drivers/staging/rtl8712/xmit_linux.c3
-rw-r--r--drivers/staging/sb105x/sb_mp_register.h2
-rw-r--r--drivers/staging/sb105x/sb_pci_mp.c18
-rw-r--r--drivers/staging/sbe-2t3e3/dc.c9
-rw-r--r--drivers/staging/sbe-2t3e3/module.c7
-rw-r--r--drivers/staging/sep/sep_crypto.c10
-rw-r--r--drivers/staging/sep/sep_main.c44
-rw-r--r--drivers/staging/slicoss/slic.h504
-rw-r--r--drivers/staging/slicoss/slichw.h6
-rw-r--r--drivers/staging/slicoss/slicoss.c35
-rw-r--r--drivers/staging/speakup/Kconfig2
-rw-r--r--drivers/staging/speakup/buffers.c14
-rw-r--r--drivers/staging/speakup/fakekey.c2
-rw-r--r--drivers/staging/speakup/i18n.c12
-rw-r--r--drivers/staging/speakup/i18n.h12
-rw-r--r--drivers/staging/speakup/keyhelp.c39
-rw-r--r--drivers/staging/speakup/kobjects.c84
-rw-r--r--drivers/staging/speakup/main.c370
-rw-r--r--drivers/staging/speakup/selection.c15
-rw-r--r--drivers/staging/speakup/serialio.c6
-rw-r--r--drivers/staging/speakup/speakup.h72
-rw-r--r--drivers/staging/speakup/speakup_acntpc.c6
-rw-r--r--drivers/staging/speakup/speakup_acntsa.c2
-rw-r--r--drivers/staging/speakup/speakup_apollo.c8
-rw-r--r--drivers/staging/speakup/speakup_audptr.c2
-rw-r--r--drivers/staging/speakup/speakup_bns.c2
-rw-r--r--drivers/staging/speakup/speakup_decext.c6
-rw-r--r--drivers/staging/speakup/speakup_decpc.c4
-rw-r--r--drivers/staging/speakup/speakup_dectlk.c6
-rw-r--r--drivers/staging/speakup/speakup_dtlk.c4
-rw-r--r--drivers/staging/speakup/speakup_dummy.c2
-rw-r--r--drivers/staging/speakup/speakup_keypc.c6
-rw-r--r--drivers/staging/speakup/speakup_ltlk.c2
-rw-r--r--drivers/staging/speakup/speakup_spkout.c2
-rw-r--r--drivers/staging/speakup/speakup_txprt.c2
-rw-r--r--drivers/staging/speakup/spk_priv.h8
-rw-r--r--drivers/staging/speakup/synth.c38
-rw-r--r--drivers/staging/speakup/thread.c4
-rw-r--r--drivers/staging/speakup/varhandlers.c66
-rw-r--r--drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c18
-rw-r--r--drivers/staging/tidspbridge/core/msg_sm.c3
-rw-r--r--drivers/staging/tidspbridge/core/tiomap3430.c34
-rw-r--r--drivers/staging/tidspbridge/include/dspbridge/proc.h2
-rw-r--r--drivers/staging/tidspbridge/pmgr/cod.c2
-rw-r--r--drivers/staging/tidspbridge/pmgr/dbll.c2
-rw-r--r--drivers/staging/tidspbridge/pmgr/dspapi.c11
-rw-r--r--drivers/staging/tidspbridge/rmgr/dbdcd.c3
-rw-r--r--drivers/staging/tidspbridge/rmgr/drv_interface.c1
-rw-r--r--drivers/staging/tidspbridge/rmgr/nldr.c6
-rw-r--r--drivers/staging/tidspbridge/rmgr/node.c12
-rw-r--r--drivers/staging/tidspbridge/rmgr/proc.c23
-rw-r--r--drivers/staging/usbip/Kconfig2
-rw-r--r--drivers/staging/usbip/stub_dev.c42
-rw-r--r--drivers/staging/usbip/stub_rx.c5
-rw-r--r--drivers/staging/usbip/stub_tx.c1
-rw-r--r--drivers/staging/usbip/usbip_common.c3
-rw-r--r--drivers/staging/usbip/usbip_event.c6
-rw-r--r--drivers/staging/usbip/userspace/.gitignore28
-rw-r--r--drivers/staging/usbip/userspace/Makefile.am2
-rw-r--r--drivers/staging/usbip/userspace/README2
-rw-r--r--drivers/staging/usbip/userspace/configure.ac20
-rw-r--r--drivers/staging/usbip/userspace/src/Makefile.am4
-rw-r--r--drivers/staging/usbip/userspace/src/usbip_attach.c15
-rw-r--r--drivers/staging/usbip/userspace/src/usbipd.c96
-rw-r--r--drivers/staging/usbip/vhci_hcd.c80
-rw-r--r--drivers/staging/usbip/vhci_rx.c10
-rw-r--r--drivers/staging/usbip/vhci_tx.c14
-rw-r--r--drivers/staging/vme/devices/Kconfig2
-rw-r--r--drivers/staging/vme/devices/vme_pio2_core.c1
-rw-r--r--drivers/staging/vme/devices/vme_pio2_gpio.c4
-rw-r--r--drivers/staging/vme/devices/vme_user.c2
-rw-r--r--drivers/staging/vt6655/channel.c11
-rw-r--r--drivers/staging/vt6655/device.h24
-rw-r--r--drivers/staging/vt6655/rxtx.c6
-rw-r--r--drivers/staging/vt6655/wcmd.c2
-rw-r--r--drivers/staging/vt6655/wmgr.c2
-rw-r--r--drivers/staging/vt6656/80211mgr.c36
-rw-r--r--drivers/staging/vt6656/80211mgr.h169
-rw-r--r--drivers/staging/vt6656/aes_ccmp.c10
-rw-r--r--drivers/staging/vt6656/aes_ccmp.h2
-rw-r--r--drivers/staging/vt6656/baseband.c91
-rw-r--r--drivers/staging/vt6656/baseband.h70
-rw-r--r--drivers/staging/vt6656/bssdb.c435
-rw-r--r--drivers/staging/vt6656/bssdb.h172
-rw-r--r--drivers/staging/vt6656/card.c366
-rw-r--r--drivers/staging/vt6656/card.h47
-rw-r--r--drivers/staging/vt6656/channel.c157
-rw-r--r--drivers/staging/vt6656/channel.h9
-rw-r--r--drivers/staging/vt6656/control.c55
-rw-r--r--drivers/staging/vt6656/control.h26
-rw-r--r--drivers/staging/vt6656/datarate.c109
-rw-r--r--drivers/staging/vt6656/datarate.h43
-rw-r--r--drivers/staging/vt6656/desc.h195
-rw-r--r--drivers/staging/vt6656/device.h879
-rw-r--r--drivers/staging/vt6656/device_cfg.h12
-rw-r--r--drivers/staging/vt6656/dpc.c470
-rw-r--r--drivers/staging/vt6656/dpc.h16
-rw-r--r--drivers/staging/vt6656/firmware.c33
-rw-r--r--drivers/staging/vt6656/firmware.h17
-rw-r--r--drivers/staging/vt6656/hostap.c147
-rw-r--r--drivers/staging/vt6656/hostap.h4
-rw-r--r--drivers/staging/vt6656/int.c22
-rw-r--r--drivers/staging/vt6656/int.h7
-rw-r--r--drivers/staging/vt6656/iocmd.h22
-rw-r--r--drivers/staging/vt6656/iwctl.c184
-rw-r--r--drivers/staging/vt6656/key.c364
-rw-r--r--drivers/staging/vt6656/key.h104
-rw-r--r--drivers/staging/vt6656/mac.c92
-rw-r--r--drivers/staging/vt6656/mac.h35
-rw-r--r--drivers/staging/vt6656/main_usb.c530
-rw-r--r--drivers/staging/vt6656/power.c104
-rw-r--r--drivers/staging/vt6656/power.h16
-rw-r--r--drivers/staging/vt6656/rf.c178
-rw-r--r--drivers/staging/vt6656/rf.h26
-rw-r--r--drivers/staging/vt6656/rxtx.c965
-rw-r--r--drivers/staging/vt6656/rxtx.h31
-rw-r--r--drivers/staging/vt6656/tether.c8
-rw-r--r--drivers/staging/vt6656/tether.h2
-rw-r--r--drivers/staging/vt6656/ttype.h23
-rw-r--r--drivers/staging/vt6656/usbpipe.c216
-rw-r--r--drivers/staging/vt6656/usbpipe.h40
-rw-r--r--drivers/staging/vt6656/wcmd.c323
-rw-r--r--drivers/staging/vt6656/wcmd.h18
-rw-r--r--drivers/staging/vt6656/wctl.c50
-rw-r--r--drivers/staging/vt6656/wctl.h10
-rw-r--r--drivers/staging/vt6656/wmgr.c1406
-rw-r--r--drivers/staging/vt6656/wmgr.h394
-rw-r--r--drivers/staging/vt6656/wpa.c30
-rw-r--r--drivers/staging/vt6656/wpa.h4
-rw-r--r--drivers/staging/vt6656/wpa2.c41
-rw-r--r--drivers/staging/vt6656/wpactl.c34
-rw-r--r--drivers/staging/vt6656/wpactl.h2
-rw-r--r--drivers/staging/winbond/Kconfig2
-rw-r--r--drivers/staging/wlags49_h2/ap_h2.c8
-rw-r--r--drivers/staging/wlags49_h2/ap_h25.c78
-rw-r--r--drivers/staging/wlags49_h2/sta_h2.c80
-rw-r--r--drivers/staging/wlags49_h2/wl_enc.c128
-rw-r--r--drivers/staging/wlags49_h2/wl_netdev.h94
-rw-r--r--drivers/staging/wlags49_h2/wl_priv.c1113
-rw-r--r--drivers/staging/wlags49_h2/wl_priv.h58
-rw-r--r--drivers/staging/wlags49_h2/wl_profile.h12
-rw-r--r--drivers/staging/wlags49_h2/wl_util.h38
-rw-r--r--drivers/staging/wlags49_h2/wl_wext.c2
-rw-r--r--drivers/staging/wlan-ng/hfa384x.h31
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c2
-rw-r--r--drivers/staging/wlan-ng/prism2mgmt.c40
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c84
-rw-r--r--drivers/staging/xgifb/XGIfb.h2
-rw-r--r--drivers/staging/xgifb/vb_init.c119
-rw-r--r--drivers/staging/xgifb/vb_init.h1
-rw-r--r--drivers/staging/xgifb/vb_setmode.c684
-rw-r--r--drivers/staging/xgifb/vb_struct.h5
-rw-r--r--drivers/staging/xgifb/vb_table.h168
-rw-r--r--drivers/staging/zcache/Kconfig34
-rw-r--r--drivers/staging/zcache/Makefile5
-rw-r--r--drivers/staging/zcache/TODO69
-rw-r--r--drivers/staging/zcache/ramster.h (renamed from drivers/staging/ramster/ramster.h)0
-rw-r--r--drivers/staging/zcache/ramster/heartbeat.c (renamed from drivers/staging/ramster/ramster/heartbeat.c)0
-rw-r--r--drivers/staging/zcache/ramster/heartbeat.h (renamed from drivers/staging/ramster/ramster/heartbeat.h)0
-rw-r--r--drivers/staging/zcache/ramster/masklog.c (renamed from drivers/staging/ramster/ramster/masklog.c)0
-rw-r--r--drivers/staging/zcache/ramster/masklog.h (renamed from drivers/staging/ramster/ramster/masklog.h)0
-rw-r--r--drivers/staging/zcache/ramster/nodemanager.c (renamed from drivers/staging/ramster/ramster/nodemanager.c)0
-rw-r--r--drivers/staging/zcache/ramster/nodemanager.h (renamed from drivers/staging/ramster/ramster/nodemanager.h)0
-rw-r--r--drivers/staging/zcache/ramster/r2net.c (renamed from drivers/staging/ramster/ramster/r2net.c)0
-rw-r--r--drivers/staging/zcache/ramster/ramster.c (renamed from drivers/staging/ramster/ramster/ramster.c)34
-rw-r--r--drivers/staging/zcache/ramster/ramster.h (renamed from drivers/staging/ramster/ramster/ramster.h)0
-rw-r--r--drivers/staging/zcache/ramster/ramster_nodemanager.h (renamed from drivers/staging/ramster/ramster/ramster_nodemanager.h)0
-rw-r--r--drivers/staging/zcache/ramster/tcp.c (renamed from drivers/staging/ramster/ramster/tcp.c)0
-rw-r--r--drivers/staging/zcache/ramster/tcp.h (renamed from drivers/staging/ramster/ramster/tcp.h)0
-rw-r--r--drivers/staging/zcache/ramster/tcp_internal.h (renamed from drivers/staging/ramster/ramster/tcp_internal.h)0
-rw-r--r--drivers/staging/zcache/tmem.c327
-rw-r--r--drivers/staging/zcache/tmem.h83
-rw-r--r--drivers/staging/zcache/zbud.c (renamed from drivers/staging/ramster/zbud.c)41
-rw-r--r--drivers/staging/zcache/zbud.h (renamed from drivers/staging/ramster/zbud.h)0
-rw-r--r--drivers/staging/zcache/zcache-main.c2558
-rw-r--r--drivers/staging/zcache/zcache.h (renamed from drivers/staging/ramster/zcache.h)0
-rw-r--r--drivers/staging/zram/Kconfig2
-rw-r--r--drivers/staging/zram/zram.txt27
-rw-r--r--drivers/staging/zram/zram_drv.c294
-rw-r--r--drivers/staging/zram/zram_drv.h17
-rw-r--r--drivers/staging/zram/zram_sysfs.c16
-rw-r--r--drivers/staging/zsmalloc/zsmalloc-main.c29
-rw-r--r--drivers/staging/zsmalloc/zsmalloc.h2
-rw-r--r--include/linux/hid-sensor-hub.h38
-rw-r--r--include/linux/hid-sensor-ids.h9
-rw-r--r--include/linux/iio/buffer.h13
-rw-r--r--include/linux/iio/common/st_sensors.h280
-rw-r--r--include/linux/iio/common/st_sensors_i2c.h20
-rw-r--r--include/linux/iio/common/st_sensors_spi.h20
-rw-r--r--include/linux/iio/consumer.h14
-rw-r--r--include/linux/iio/driver.h9
-rw-r--r--include/linux/iio/gyro/itg3200.h154
-rw-r--r--include/linux/iio/trigger.h5
-rw-r--r--include/linux/pci_ids.h10
-rw-r--r--include/linux/platform_data/invensense_mpu6050.h31
-rw-r--r--include/linux/platform_data/tsl2563.h (renamed from drivers/staging/iio/light/tsl2563.h)1
-rw-r--r--include/linux/spi/spi.h44
621 files changed, 28210 insertions, 28359 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-mpu6050 b/Documentation/ABI/testing/sysfs-bus-iio-mpu6050
new file mode 100644
index 000000000000..cb53737aacbf
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-iio-mpu6050
@@ -0,0 +1,13 @@
1What: /sys/bus/iio/devices/iio:deviceX/in_gyro_matrix
2What: /sys/bus/iio/devices/iio:deviceX/in_accel_matrix
3What: /sys/bus/iio/devices/iio:deviceX/in_magn_matrix
4KernelVersion: 3.4.0
5Contact: linux-iio@vger.kernel.org
6Description:
7 This is mounting matrix for motion sensors. Mounting matrix
8 is a 3x3 unitary matrix. A typical mounting matrix would look like
9 [0, 1, 0; 1, 0, 0; 0, 0, -1]. Using this information, it would be
10 easy to tell the relative positions among sensors as well as their
11 positions relative to the board that holds these sensors. Identity matrix
12 [1, 0, 0; 0, 1, 0; 0, 0, 1] means sensor chip and device are perfectly
13 aligned with each other. All axes are exactly the same.
diff --git a/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
index 801d58cb6d4d..46882058b59b 100644
--- a/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
+++ b/Documentation/devicetree/bindings/staging/iio/adc/mxs-lradc.txt
@@ -5,6 +5,12 @@ Required properties:
5- reg: Address and length of the register set for the device 5- reg: Address and length of the register set for the device
6- interrupts: Should contain the LRADC interrupts 6- interrupts: Should contain the LRADC interrupts
7 7
8Optional properties:
9- fsl,lradc-touchscreen-wires: Number of wires used to connect the touchscreen
10 to LRADC. Valid value is either 4 or 5. If this
11 property is not present, then the touchscreen is
12 disabled.
13
8Examples: 14Examples:
9 15
10 lradc@80050000 { 16 lradc@80050000 {
diff --git a/MAINTAINERS b/MAINTAINERS
index cdb8fe8b6182..1a3963a3a330 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7299,8 +7299,7 @@ S: Odd Fixes
7299F: drivers/staging/olpc_dcon/ 7299F: drivers/staging/olpc_dcon/
7300 7300
7301STAGING - OZMO DEVICES USB OVER WIFI DRIVER 7301STAGING - OZMO DEVICES USB OVER WIFI DRIVER
7302M: Rupesh Gujare <rgujare@ozmodevices.com> 7302M: Rupesh Gujare <rupesh.gujare@atmel.com>
7303M: Chris Kelly <ckelly@ozmodevices.com>
7304S: Maintained 7303S: Maintained
7305F: drivers/staging/ozwpan/ 7304F: drivers/staging/ozwpan/
7306 7305
diff --git a/arch/arm/boot/dts/imx23.dtsi b/arch/arm/boot/dts/imx23.dtsi
index 65415c598a5e..56afcf41aae0 100644
--- a/arch/arm/boot/dts/imx23.dtsi
+++ b/arch/arm/boot/dts/imx23.dtsi
@@ -391,7 +391,9 @@
391 }; 391 };
392 392
393 lradc@80050000 { 393 lradc@80050000 {
394 compatible = "fsl,imx23-lradc";
394 reg = <0x80050000 0x2000>; 395 reg = <0x80050000 0x2000>;
396 interrupts = <36 37 38 39 40 41 42 43 44>;
395 status = "disabled"; 397 status = "disabled";
396 }; 398 };
397 399
diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
index cf07e289b4ea..f3d075baebb6 100644
--- a/arch/arm/mach-omap2/board-rx51-peripherals.c
+++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
@@ -42,7 +42,7 @@
42#include <media/si4713.h> 42#include <media/si4713.h>
43#include <linux/leds-lp5523.h> 43#include <linux/leds-lp5523.h>
44 44
45#include <../drivers/staging/iio/light/tsl2563.h> 45#include <linux/platform_data/tsl2563.h>
46#include <linux/lis3lv02d.h> 46#include <linux/lis3lv02d.h>
47 47
48#if defined(CONFIG_IR_RX51) || defined(CONFIG_IR_RX51_MODULE) 48#if defined(CONFIG_IR_RX51) || defined(CONFIG_IR_RX51_MODULE)
diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c
index eda2a1aa4adb..d0233cd18ffa 100644
--- a/drivers/extcon/extcon-adc-jack.c
+++ b/drivers/extcon/extcon-adc-jack.c
@@ -135,8 +135,7 @@ static int adc_jack_probe(struct platform_device *pdev)
135 ; 135 ;
136 data->num_conditions = i; 136 data->num_conditions = i;
137 137
138 data->chan = iio_channel_get(dev_name(&pdev->dev), 138 data->chan = iio_channel_get(&pdev->dev, pdata->consumer_channel);
139 pdata->consumer_channel);
140 if (IS_ERR(data->chan)) { 139 if (IS_ERR(data->chan)) {
141 err = PTR_ERR(data->chan); 140 err = PTR_ERR(data->chan);
142 goto out; 141 goto out;
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index 05e996fafc9d..bb594963f91e 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -14,4 +14,42 @@ config HID_SENSOR_ACCEL_3D
14 Say yes here to build support for the HID SENSOR 14 Say yes here to build support for the HID SENSOR
15 accelerometers 3D. 15 accelerometers 3D.
16 16
17config KXSD9
18 tristate "Kionix KXSD9 Accelerometer Driver"
19 depends on SPI
20 help
21 Say yes here to build support for the Kionix KXSD9 accelerometer.
22 Currently this only supports the device via an SPI interface.
23
24config IIO_ST_ACCEL_3AXIS
25 tristate "STMicroelectronics accelerometers 3-Axis Driver"
26 depends on (I2C || SPI_MASTER) && SYSFS
27 select IIO_ST_SENSORS_CORE
28 select IIO_ST_ACCEL_I2C_3AXIS if (I2C)
29 select IIO_ST_ACCEL_SPI_3AXIS if (SPI_MASTER)
30 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
31 select IIO_ST_ACCEL_BUFFER if (IIO_TRIGGERED_BUFFER)
32 help
33 Say yes here to build support for STMicroelectronics accelerometers:
34 LSM303DLH, LSM303DLHC, LIS3DH, LSM330D, LSM330DL, LSM330DLC,
35 LIS331DLH, LSM303DL, LSM303DLM, LSM330.
36
37 This driver can also be built as a module. If so, will be created
38 these modules:
39 - st_accel (core functions for the driver [it is mandatory]);
40 - st_accel_i2c (necessary for the I2C devices [optional*]);
41 - st_accel_spi (necessary for the SPI devices [optional*]);
42
43 (*) one of these is necessary to do something.
44
45config IIO_ST_ACCEL_I2C_3AXIS
46 tristate
47 depends on IIO_ST_ACCEL_3AXIS
48 depends on IIO_ST_SENSORS_I2C
49
50config IIO_ST_ACCEL_SPI_3AXIS
51 tristate
52 depends on IIO_ST_ACCEL_3AXIS
53 depends on IIO_ST_SENSORS_SPI
54
17endmenu 55endmenu
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 5bc6855a973e..87d8fa264894 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/Makefile
@@ -3,3 +3,12 @@
3# 3#
4 4
5obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o 5obj-$(CONFIG_HID_SENSOR_ACCEL_3D) += hid-sensor-accel-3d.o
6
7obj-$(CONFIG_IIO_ST_ACCEL_3AXIS) += st_accel.o
8st_accel-y := st_accel_core.o
9st_accel-$(CONFIG_IIO_BUFFER) += st_accel_buffer.o
10
11obj-$(CONFIG_IIO_ST_ACCEL_I2C_3AXIS) += st_accel_i2c.o
12obj-$(CONFIG_IIO_ST_ACCEL_SPI_3AXIS) += st_accel_spi.o
13
14obj-$(CONFIG_KXSD9) += kxsd9.o
diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 0b0c3c66f6c0..dd8ea4284934 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -28,7 +28,6 @@
28#include <linux/iio/buffer.h> 28#include <linux/iio/buffer.h>
29#include <linux/iio/trigger_consumer.h> 29#include <linux/iio/trigger_consumer.h>
30#include <linux/iio/triggered_buffer.h> 30#include <linux/iio/triggered_buffer.h>
31#include "../common/hid-sensors/hid-sensor-attributes.h"
32#include "../common/hid-sensors/hid-sensor-trigger.h" 31#include "../common/hid-sensors/hid-sensor-trigger.h"
33 32
34/*Format: HID-SENSOR-usage_id_in_hex*/ 33/*Format: HID-SENSOR-usage_id_in_hex*/
@@ -44,7 +43,7 @@ enum accel_3d_channel {
44 43
45struct accel_3d_state { 44struct accel_3d_state {
46 struct hid_sensor_hub_callbacks callbacks; 45 struct hid_sensor_hub_callbacks callbacks;
47 struct hid_sensor_iio_common common_attributes; 46 struct hid_sensor_common common_attributes;
48 struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX]; 47 struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
49 u32 accel_val[ACCEL_3D_CHANNEL_MAX]; 48 u32 accel_val[ACCEL_3D_CHANNEL_MAX];
50}; 49};
diff --git a/drivers/staging/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
index 318331f08d9c..c2229a521ab9 100644
--- a/drivers/staging/iio/accel/kxsd9.c
+++ b/drivers/iio/accel/kxsd9.c
@@ -94,7 +94,6 @@ error_ret:
94 94
95static int kxsd9_read(struct iio_dev *indio_dev, u8 address) 95static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
96{ 96{
97 struct spi_message msg;
98 int ret; 97 int ret;
99 struct kxsd9_state *st = iio_priv(indio_dev); 98 struct kxsd9_state *st = iio_priv(indio_dev);
100 struct spi_transfer xfers[] = { 99 struct spi_transfer xfers[] = {
@@ -112,10 +111,7 @@ static int kxsd9_read(struct iio_dev *indio_dev, u8 address)
112 111
113 mutex_lock(&st->buf_lock); 112 mutex_lock(&st->buf_lock);
114 st->tx[0] = KXSD9_READ(address); 113 st->tx[0] = KXSD9_READ(address);
115 spi_message_init(&msg); 114 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
116 spi_message_add_tail(&xfers[0], &msg);
117 spi_message_add_tail(&xfers[1], &msg);
118 ret = spi_sync(st->us, &msg);
119 if (ret) 115 if (ret)
120 return ret; 116 return ret;
121 return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0); 117 return (((u16)(st->rx[0])) << 8) | (st->rx[1] & 0xF0);
@@ -226,7 +222,7 @@ static int kxsd9_probe(struct spi_device *spi)
226{ 222{
227 struct iio_dev *indio_dev; 223 struct iio_dev *indio_dev;
228 struct kxsd9_state *st; 224 struct kxsd9_state *st;
229 int ret = 0; 225 int ret;
230 226
231 indio_dev = iio_device_alloc(sizeof(*st)); 227 indio_dev = iio_device_alloc(sizeof(*st));
232 if (indio_dev == NULL) { 228 if (indio_dev == NULL) {
@@ -245,14 +241,14 @@ static int kxsd9_probe(struct spi_device *spi)
245 indio_dev->info = &kxsd9_info; 241 indio_dev->info = &kxsd9_info;
246 indio_dev->modes = INDIO_DIRECT_MODE; 242 indio_dev->modes = INDIO_DIRECT_MODE;
247 243
248 ret = iio_device_register(indio_dev);
249 if (ret)
250 goto error_free_dev;
251
252 spi->mode = SPI_MODE_0; 244 spi->mode = SPI_MODE_0;
253 spi_setup(spi); 245 spi_setup(spi);
254 kxsd9_power_up(st); 246 kxsd9_power_up(st);
255 247
248 ret = iio_device_register(indio_dev);
249 if (ret)
250 goto error_free_dev;
251
256 return 0; 252 return 0;
257 253
258error_free_dev: 254error_free_dev:
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
new file mode 100644
index 000000000000..37949b94377d
--- /dev/null
+++ b/drivers/iio/accel/st_accel.h
@@ -0,0 +1,47 @@
1/*
2 * STMicroelectronics accelerometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 * v. 1.0.0
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_ACCEL_H
12#define ST_ACCEL_H
13
14#include <linux/types.h>
15#include <linux/iio/common/st_sensors.h>
16
17#define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel"
18#define LIS3DH_ACCEL_DEV_NAME "lis3dh"
19#define LSM330D_ACCEL_DEV_NAME "lsm330d_accel"
20#define LSM330DL_ACCEL_DEV_NAME "lsm330dl_accel"
21#define LSM330DLC_ACCEL_DEV_NAME "lsm330dlc_accel"
22#define LIS331DLH_ACCEL_DEV_NAME "lis331dlh"
23#define LSM303DL_ACCEL_DEV_NAME "lsm303dl_accel"
24#define LSM303DLH_ACCEL_DEV_NAME "lsm303dlh_accel"
25#define LSM303DLM_ACCEL_DEV_NAME "lsm303dlm_accel"
26#define LSM330_ACCEL_DEV_NAME "lsm330_accel"
27
28int st_accel_common_probe(struct iio_dev *indio_dev);
29void st_accel_common_remove(struct iio_dev *indio_dev);
30
31#ifdef CONFIG_IIO_BUFFER
32int st_accel_allocate_ring(struct iio_dev *indio_dev);
33void st_accel_deallocate_ring(struct iio_dev *indio_dev);
34int st_accel_trig_set_state(struct iio_trigger *trig, bool state);
35#define ST_ACCEL_TRIGGER_SET_STATE (&st_accel_trig_set_state)
36#else /* CONFIG_IIO_BUFFER */
37static inline int st_accel_allocate_ring(struct iio_dev *indio_dev)
38{
39 return 0;
40}
41static inline void st_accel_deallocate_ring(struct iio_dev *indio_dev)
42{
43}
44#define ST_ACCEL_TRIGGER_SET_STATE NULL
45#endif /* CONFIG_IIO_BUFFER */
46
47#endif /* ST_ACCEL_H */
diff --git a/drivers/iio/accel/st_accel_buffer.c b/drivers/iio/accel/st_accel_buffer.c
new file mode 100644
index 000000000000..6bd82c7f769c
--- /dev/null
+++ b/drivers/iio/accel/st_accel_buffer.c
@@ -0,0 +1,114 @@
1/*
2 * STMicroelectronics accelerometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/stat.h>
15#include <linux/interrupt.h>
16#include <linux/i2c.h>
17#include <linux/delay.h>
18#include <linux/iio/iio.h>
19#include <linux/iio/buffer.h>
20#include <linux/iio/trigger_consumer.h>
21#include <linux/iio/triggered_buffer.h>
22
23#include <linux/iio/common/st_sensors.h>
24#include "st_accel.h"
25
26int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
27{
28 struct iio_dev *indio_dev = trig->private_data;
29
30 return st_sensors_set_dataready_irq(indio_dev, state);
31}
32
33static int st_accel_buffer_preenable(struct iio_dev *indio_dev)
34{
35 int err;
36
37 err = st_sensors_set_enable(indio_dev, true);
38 if (err < 0)
39 goto st_accel_set_enable_error;
40
41 err = iio_sw_buffer_preenable(indio_dev);
42
43st_accel_set_enable_error:
44 return err;
45}
46
47static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
48{
49 int err;
50 struct st_sensor_data *adata = iio_priv(indio_dev);
51
52 adata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
53 if (adata->buffer_data == NULL) {
54 err = -ENOMEM;
55 goto allocate_memory_error;
56 }
57
58 err = st_sensors_set_axis_enable(indio_dev,
59 (u8)indio_dev->active_scan_mask[0]);
60 if (err < 0)
61 goto st_accel_buffer_postenable_error;
62
63 err = iio_triggered_buffer_postenable(indio_dev);
64 if (err < 0)
65 goto st_accel_buffer_postenable_error;
66
67 return err;
68
69st_accel_buffer_postenable_error:
70 kfree(adata->buffer_data);
71allocate_memory_error:
72 return err;
73}
74
75static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
76{
77 int err;
78 struct st_sensor_data *adata = iio_priv(indio_dev);
79
80 err = iio_triggered_buffer_predisable(indio_dev);
81 if (err < 0)
82 goto st_accel_buffer_predisable_error;
83
84 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
85 if (err < 0)
86 goto st_accel_buffer_predisable_error;
87
88 err = st_sensors_set_enable(indio_dev, false);
89
90st_accel_buffer_predisable_error:
91 kfree(adata->buffer_data);
92 return err;
93}
94
95static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
96 .preenable = &st_accel_buffer_preenable,
97 .postenable = &st_accel_buffer_postenable,
98 .predisable = &st_accel_buffer_predisable,
99};
100
101int st_accel_allocate_ring(struct iio_dev *indio_dev)
102{
103 return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
104 &st_sensors_trigger_handler, &st_accel_buffer_setup_ops);
105}
106
107void st_accel_deallocate_ring(struct iio_dev *indio_dev)
108{
109 iio_triggered_buffer_cleanup(indio_dev);
110}
111
112MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
113MODULE_DESCRIPTION("STMicroelectronics accelerometers buffer");
114MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
new file mode 100644
index 000000000000..e0f5a3ceba5e
--- /dev/null
+++ b/drivers/iio/accel/st_accel_core.c
@@ -0,0 +1,500 @@
1/*
2 * STMicroelectronics accelerometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/errno.h>
15#include <linux/types.h>
16#include <linux/mutex.h>
17#include <linux/interrupt.h>
18#include <linux/i2c.h>
19#include <linux/gpio.h>
20#include <linux/irq.h>
21#include <linux/iio/iio.h>
22#include <linux/iio/sysfs.h>
23#include <linux/iio/trigger.h>
24#include <linux/iio/buffer.h>
25
26#include <linux/iio/common/st_sensors.h>
27#include "st_accel.h"
28
29/* DEFAULT VALUE FOR SENSORS */
30#define ST_ACCEL_DEFAULT_OUT_X_L_ADDR 0x28
31#define ST_ACCEL_DEFAULT_OUT_Y_L_ADDR 0x2a
32#define ST_ACCEL_DEFAULT_OUT_Z_L_ADDR 0x2c
33
34/* FULLSCALE */
35#define ST_ACCEL_FS_AVL_2G 2
36#define ST_ACCEL_FS_AVL_4G 4
37#define ST_ACCEL_FS_AVL_6G 6
38#define ST_ACCEL_FS_AVL_8G 8
39#define ST_ACCEL_FS_AVL_16G 16
40
41/* CUSTOM VALUES FOR SENSOR 1 */
42#define ST_ACCEL_1_WAI_EXP 0x33
43#define ST_ACCEL_1_ODR_ADDR 0x20
44#define ST_ACCEL_1_ODR_MASK 0xf0
45#define ST_ACCEL_1_ODR_AVL_1HZ_VAL 0x01
46#define ST_ACCEL_1_ODR_AVL_10HZ_VAL 0x02
47#define ST_ACCEL_1_ODR_AVL_25HZ_VAL 0x03
48#define ST_ACCEL_1_ODR_AVL_50HZ_VAL 0x04
49#define ST_ACCEL_1_ODR_AVL_100HZ_VAL 0x05
50#define ST_ACCEL_1_ODR_AVL_200HZ_VAL 0x06
51#define ST_ACCEL_1_ODR_AVL_400HZ_VAL 0x07
52#define ST_ACCEL_1_ODR_AVL_1600HZ_VAL 0x08
53#define ST_ACCEL_1_FS_ADDR 0x23
54#define ST_ACCEL_1_FS_MASK 0x30
55#define ST_ACCEL_1_FS_AVL_2_VAL 0x00
56#define ST_ACCEL_1_FS_AVL_4_VAL 0x01
57#define ST_ACCEL_1_FS_AVL_8_VAL 0x02
58#define ST_ACCEL_1_FS_AVL_16_VAL 0x03
59#define ST_ACCEL_1_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1000)
60#define ST_ACCEL_1_FS_AVL_4_GAIN IIO_G_TO_M_S_2(2000)
61#define ST_ACCEL_1_FS_AVL_8_GAIN IIO_G_TO_M_S_2(4000)
62#define ST_ACCEL_1_FS_AVL_16_GAIN IIO_G_TO_M_S_2(12000)
63#define ST_ACCEL_1_BDU_ADDR 0x23
64#define ST_ACCEL_1_BDU_MASK 0x80
65#define ST_ACCEL_1_DRDY_IRQ_ADDR 0x22
66#define ST_ACCEL_1_DRDY_IRQ_MASK 0x10
67#define ST_ACCEL_1_MULTIREAD_BIT true
68
69/* CUSTOM VALUES FOR SENSOR 2 */
70#define ST_ACCEL_2_WAI_EXP 0x32
71#define ST_ACCEL_2_ODR_ADDR 0x20
72#define ST_ACCEL_2_ODR_MASK 0x18
73#define ST_ACCEL_2_ODR_AVL_50HZ_VAL 0x00
74#define ST_ACCEL_2_ODR_AVL_100HZ_VAL 0x01
75#define ST_ACCEL_2_ODR_AVL_400HZ_VAL 0x02
76#define ST_ACCEL_2_ODR_AVL_1000HZ_VAL 0x03
77#define ST_ACCEL_2_PW_ADDR 0x20
78#define ST_ACCEL_2_PW_MASK 0xe0
79#define ST_ACCEL_2_FS_ADDR 0x23
80#define ST_ACCEL_2_FS_MASK 0x30
81#define ST_ACCEL_2_FS_AVL_2_VAL 0X00
82#define ST_ACCEL_2_FS_AVL_4_VAL 0X01
83#define ST_ACCEL_2_FS_AVL_8_VAL 0x03
84#define ST_ACCEL_2_FS_AVL_2_GAIN IIO_G_TO_M_S_2(1000)
85#define ST_ACCEL_2_FS_AVL_4_GAIN IIO_G_TO_M_S_2(2000)
86#define ST_ACCEL_2_FS_AVL_8_GAIN IIO_G_TO_M_S_2(3900)
87#define ST_ACCEL_2_BDU_ADDR 0x23
88#define ST_ACCEL_2_BDU_MASK 0x80
89#define ST_ACCEL_2_DRDY_IRQ_ADDR 0x22
90#define ST_ACCEL_2_DRDY_IRQ_MASK 0x02
91#define ST_ACCEL_2_MULTIREAD_BIT true
92
93/* CUSTOM VALUES FOR SENSOR 3 */
94#define ST_ACCEL_3_WAI_EXP 0x40
95#define ST_ACCEL_3_ODR_ADDR 0x20
96#define ST_ACCEL_3_ODR_MASK 0xf0
97#define ST_ACCEL_3_ODR_AVL_3HZ_VAL 0x01
98#define ST_ACCEL_3_ODR_AVL_6HZ_VAL 0x02
99#define ST_ACCEL_3_ODR_AVL_12HZ_VAL 0x03
100#define ST_ACCEL_3_ODR_AVL_25HZ_VAL 0x04
101#define ST_ACCEL_3_ODR_AVL_50HZ_VAL 0x05
102#define ST_ACCEL_3_ODR_AVL_100HZ_VAL 0x06
103#define ST_ACCEL_3_ODR_AVL_200HZ_VAL 0x07
104#define ST_ACCEL_3_ODR_AVL_400HZ_VAL 0x08
105#define ST_ACCEL_3_ODR_AVL_800HZ_VAL 0x09
106#define ST_ACCEL_3_ODR_AVL_1600HZ_VAL 0x0a
107#define ST_ACCEL_3_FS_ADDR 0x24
108#define ST_ACCEL_3_FS_MASK 0x38
109#define ST_ACCEL_3_FS_AVL_2_VAL 0X00
110#define ST_ACCEL_3_FS_AVL_4_VAL 0X01
111#define ST_ACCEL_3_FS_AVL_6_VAL 0x02
112#define ST_ACCEL_3_FS_AVL_8_VAL 0x03
113#define ST_ACCEL_3_FS_AVL_16_VAL 0x04
114#define ST_ACCEL_3_FS_AVL_2_GAIN IIO_G_TO_M_S_2(61)
115#define ST_ACCEL_3_FS_AVL_4_GAIN IIO_G_TO_M_S_2(122)
116#define ST_ACCEL_3_FS_AVL_6_GAIN IIO_G_TO_M_S_2(183)
117#define ST_ACCEL_3_FS_AVL_8_GAIN IIO_G_TO_M_S_2(244)
118#define ST_ACCEL_3_FS_AVL_16_GAIN IIO_G_TO_M_S_2(732)
119#define ST_ACCEL_3_BDU_ADDR 0x20
120#define ST_ACCEL_3_BDU_MASK 0x08
121#define ST_ACCEL_3_DRDY_IRQ_ADDR 0x23
122#define ST_ACCEL_3_DRDY_IRQ_MASK 0x80
123#define ST_ACCEL_3_IG1_EN_ADDR 0x23
124#define ST_ACCEL_3_IG1_EN_MASK 0x08
125#define ST_ACCEL_3_MULTIREAD_BIT false
126
127static const struct iio_chan_spec st_accel_12bit_channels[] = {
128 ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
129 ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR),
130 ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
131 ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR),
132 ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
133 ST_SENSORS_DEFAULT_12_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR),
134 IIO_CHAN_SOFT_TIMESTAMP(3)
135};
136
137static const struct iio_chan_spec st_accel_16bit_channels[] = {
138 ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
139 ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_X_L_ADDR),
140 ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
141 ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Y_L_ADDR),
142 ST_SENSORS_LSM_CHANNELS(IIO_ACCEL, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
143 ST_SENSORS_DEFAULT_16_REALBITS, ST_ACCEL_DEFAULT_OUT_Z_L_ADDR),
144 IIO_CHAN_SOFT_TIMESTAMP(3)
145};
146
147static const struct st_sensors st_accel_sensors[] = {
148 {
149 .wai = ST_ACCEL_1_WAI_EXP,
150 .sensors_supported = {
151 [0] = LIS3DH_ACCEL_DEV_NAME,
152 [1] = LSM303DLHC_ACCEL_DEV_NAME,
153 [2] = LSM330D_ACCEL_DEV_NAME,
154 [3] = LSM330DL_ACCEL_DEV_NAME,
155 [4] = LSM330DLC_ACCEL_DEV_NAME,
156 },
157 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
158 .odr = {
159 .addr = ST_ACCEL_1_ODR_ADDR,
160 .mask = ST_ACCEL_1_ODR_MASK,
161 .odr_avl = {
162 { 1, ST_ACCEL_1_ODR_AVL_1HZ_VAL, },
163 { 10, ST_ACCEL_1_ODR_AVL_10HZ_VAL, },
164 { 25, ST_ACCEL_1_ODR_AVL_25HZ_VAL, },
165 { 50, ST_ACCEL_1_ODR_AVL_50HZ_VAL, },
166 { 100, ST_ACCEL_1_ODR_AVL_100HZ_VAL, },
167 { 200, ST_ACCEL_1_ODR_AVL_200HZ_VAL, },
168 { 400, ST_ACCEL_1_ODR_AVL_400HZ_VAL, },
169 { 1600, ST_ACCEL_1_ODR_AVL_1600HZ_VAL, },
170 },
171 },
172 .pw = {
173 .addr = ST_ACCEL_1_ODR_ADDR,
174 .mask = ST_ACCEL_1_ODR_MASK,
175 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
176 },
177 .enable_axis = {
178 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
179 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
180 },
181 .fs = {
182 .addr = ST_ACCEL_1_FS_ADDR,
183 .mask = ST_ACCEL_1_FS_MASK,
184 .fs_avl = {
185 [0] = {
186 .num = ST_ACCEL_FS_AVL_2G,
187 .value = ST_ACCEL_1_FS_AVL_2_VAL,
188 .gain = ST_ACCEL_1_FS_AVL_2_GAIN,
189 },
190 [1] = {
191 .num = ST_ACCEL_FS_AVL_4G,
192 .value = ST_ACCEL_1_FS_AVL_4_VAL,
193 .gain = ST_ACCEL_1_FS_AVL_4_GAIN,
194 },
195 [2] = {
196 .num = ST_ACCEL_FS_AVL_8G,
197 .value = ST_ACCEL_1_FS_AVL_8_VAL,
198 .gain = ST_ACCEL_1_FS_AVL_8_GAIN,
199 },
200 [3] = {
201 .num = ST_ACCEL_FS_AVL_16G,
202 .value = ST_ACCEL_1_FS_AVL_16_VAL,
203 .gain = ST_ACCEL_1_FS_AVL_16_GAIN,
204 },
205 },
206 },
207 .bdu = {
208 .addr = ST_ACCEL_1_BDU_ADDR,
209 .mask = ST_ACCEL_1_BDU_MASK,
210 },
211 .drdy_irq = {
212 .addr = ST_ACCEL_1_DRDY_IRQ_ADDR,
213 .mask = ST_ACCEL_1_DRDY_IRQ_MASK,
214 },
215 .multi_read_bit = ST_ACCEL_1_MULTIREAD_BIT,
216 .bootime = 2,
217 },
218 {
219 .wai = ST_ACCEL_2_WAI_EXP,
220 .sensors_supported = {
221 [0] = LIS331DLH_ACCEL_DEV_NAME,
222 [1] = LSM303DL_ACCEL_DEV_NAME,
223 [2] = LSM303DLH_ACCEL_DEV_NAME,
224 [3] = LSM303DLM_ACCEL_DEV_NAME,
225 },
226 .ch = (struct iio_chan_spec *)st_accel_12bit_channels,
227 .odr = {
228 .addr = ST_ACCEL_2_ODR_ADDR,
229 .mask = ST_ACCEL_2_ODR_MASK,
230 .odr_avl = {
231 { 50, ST_ACCEL_2_ODR_AVL_50HZ_VAL, },
232 { 100, ST_ACCEL_2_ODR_AVL_100HZ_VAL, },
233 { 400, ST_ACCEL_2_ODR_AVL_400HZ_VAL, },
234 { 1000, ST_ACCEL_2_ODR_AVL_1000HZ_VAL, },
235 },
236 },
237 .pw = {
238 .addr = ST_ACCEL_2_PW_ADDR,
239 .mask = ST_ACCEL_2_PW_MASK,
240 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
241 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
242 },
243 .enable_axis = {
244 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
245 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
246 },
247 .fs = {
248 .addr = ST_ACCEL_2_FS_ADDR,
249 .mask = ST_ACCEL_2_FS_MASK,
250 .fs_avl = {
251 [0] = {
252 .num = ST_ACCEL_FS_AVL_2G,
253 .value = ST_ACCEL_2_FS_AVL_2_VAL,
254 .gain = ST_ACCEL_2_FS_AVL_2_GAIN,
255 },
256 [1] = {
257 .num = ST_ACCEL_FS_AVL_4G,
258 .value = ST_ACCEL_2_FS_AVL_4_VAL,
259 .gain = ST_ACCEL_2_FS_AVL_4_GAIN,
260 },
261 [2] = {
262 .num = ST_ACCEL_FS_AVL_8G,
263 .value = ST_ACCEL_2_FS_AVL_8_VAL,
264 .gain = ST_ACCEL_2_FS_AVL_8_GAIN,
265 },
266 },
267 },
268 .bdu = {
269 .addr = ST_ACCEL_2_BDU_ADDR,
270 .mask = ST_ACCEL_2_BDU_MASK,
271 },
272 .drdy_irq = {
273 .addr = ST_ACCEL_2_DRDY_IRQ_ADDR,
274 .mask = ST_ACCEL_2_DRDY_IRQ_MASK,
275 },
276 .multi_read_bit = ST_ACCEL_2_MULTIREAD_BIT,
277 .bootime = 2,
278 },
279 {
280 .wai = ST_ACCEL_3_WAI_EXP,
281 .sensors_supported = {
282 [0] = LSM330_ACCEL_DEV_NAME,
283 },
284 .ch = (struct iio_chan_spec *)st_accel_16bit_channels,
285 .odr = {
286 .addr = ST_ACCEL_3_ODR_ADDR,
287 .mask = ST_ACCEL_3_ODR_MASK,
288 .odr_avl = {
289 { 3, ST_ACCEL_3_ODR_AVL_3HZ_VAL },
290 { 6, ST_ACCEL_3_ODR_AVL_6HZ_VAL, },
291 { 12, ST_ACCEL_3_ODR_AVL_12HZ_VAL, },
292 { 25, ST_ACCEL_3_ODR_AVL_25HZ_VAL, },
293 { 50, ST_ACCEL_3_ODR_AVL_50HZ_VAL, },
294 { 100, ST_ACCEL_3_ODR_AVL_100HZ_VAL, },
295 { 200, ST_ACCEL_3_ODR_AVL_200HZ_VAL, },
296 { 400, ST_ACCEL_3_ODR_AVL_400HZ_VAL, },
297 { 800, ST_ACCEL_3_ODR_AVL_800HZ_VAL, },
298 { 1600, ST_ACCEL_3_ODR_AVL_1600HZ_VAL, },
299 },
300 },
301 .pw = {
302 .addr = ST_ACCEL_3_ODR_ADDR,
303 .mask = ST_ACCEL_3_ODR_MASK,
304 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
305 },
306 .enable_axis = {
307 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
308 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
309 },
310 .fs = {
311 .addr = ST_ACCEL_3_FS_ADDR,
312 .mask = ST_ACCEL_3_FS_MASK,
313 .fs_avl = {
314 [0] = {
315 .num = ST_ACCEL_FS_AVL_2G,
316 .value = ST_ACCEL_3_FS_AVL_2_VAL,
317 .gain = ST_ACCEL_3_FS_AVL_2_GAIN,
318 },
319 [1] = {
320 .num = ST_ACCEL_FS_AVL_4G,
321 .value = ST_ACCEL_3_FS_AVL_4_VAL,
322 .gain = ST_ACCEL_3_FS_AVL_4_GAIN,
323 },
324 [2] = {
325 .num = ST_ACCEL_FS_AVL_6G,
326 .value = ST_ACCEL_3_FS_AVL_6_VAL,
327 .gain = ST_ACCEL_3_FS_AVL_6_GAIN,
328 },
329 [3] = {
330 .num = ST_ACCEL_FS_AVL_8G,
331 .value = ST_ACCEL_3_FS_AVL_8_VAL,
332 .gain = ST_ACCEL_3_FS_AVL_8_GAIN,
333 },
334 [4] = {
335 .num = ST_ACCEL_FS_AVL_16G,
336 .value = ST_ACCEL_3_FS_AVL_16_VAL,
337 .gain = ST_ACCEL_3_FS_AVL_16_GAIN,
338 },
339 },
340 },
341 .bdu = {
342 .addr = ST_ACCEL_3_BDU_ADDR,
343 .mask = ST_ACCEL_3_BDU_MASK,
344 },
345 .drdy_irq = {
346 .addr = ST_ACCEL_3_DRDY_IRQ_ADDR,
347 .mask = ST_ACCEL_3_DRDY_IRQ_MASK,
348 .ig1 = {
349 .en_addr = ST_ACCEL_3_IG1_EN_ADDR,
350 .en_mask = ST_ACCEL_3_IG1_EN_MASK,
351 },
352 },
353 .multi_read_bit = ST_ACCEL_3_MULTIREAD_BIT,
354 .bootime = 2,
355 },
356};
357
358static int st_accel_read_raw(struct iio_dev *indio_dev,
359 struct iio_chan_spec const *ch, int *val,
360 int *val2, long mask)
361{
362 int err;
363 struct st_sensor_data *adata = iio_priv(indio_dev);
364
365 switch (mask) {
366 case IIO_CHAN_INFO_RAW:
367 err = st_sensors_read_info_raw(indio_dev, ch, val);
368 if (err < 0)
369 goto read_error;
370
371 return IIO_VAL_INT;
372 case IIO_CHAN_INFO_SCALE:
373 *val = 0;
374 *val2 = adata->current_fullscale->gain;
375 return IIO_VAL_INT_PLUS_MICRO;
376 default:
377 return -EINVAL;
378 }
379
380read_error:
381 return err;
382}
383
384static int st_accel_write_raw(struct iio_dev *indio_dev,
385 struct iio_chan_spec const *chan, int val, int val2, long mask)
386{
387 int err;
388
389 switch (mask) {
390 case IIO_CHAN_INFO_SCALE:
391 err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
392 break;
393 default:
394 return -EINVAL;
395 }
396
397 return err;
398}
399
400static ST_SENSOR_DEV_ATTR_SAMP_FREQ();
401static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
402static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_accel_scale_available);
403
404static struct attribute *st_accel_attributes[] = {
405 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
406 &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
407 &iio_dev_attr_sampling_frequency.dev_attr.attr,
408 NULL,
409};
410
411static const struct attribute_group st_accel_attribute_group = {
412 .attrs = st_accel_attributes,
413};
414
415static const struct iio_info accel_info = {
416 .driver_module = THIS_MODULE,
417 .attrs = &st_accel_attribute_group,
418 .read_raw = &st_accel_read_raw,
419 .write_raw = &st_accel_write_raw,
420};
421
422#ifdef CONFIG_IIO_TRIGGER
423static const struct iio_trigger_ops st_accel_trigger_ops = {
424 .owner = THIS_MODULE,
425 .set_trigger_state = ST_ACCEL_TRIGGER_SET_STATE,
426};
427#define ST_ACCEL_TRIGGER_OPS (&st_accel_trigger_ops)
428#else
429#define ST_ACCEL_TRIGGER_OPS NULL
430#endif
431
432int st_accel_common_probe(struct iio_dev *indio_dev)
433{
434 int err;
435 struct st_sensor_data *adata = iio_priv(indio_dev);
436
437 indio_dev->modes = INDIO_DIRECT_MODE;
438 indio_dev->info = &accel_info;
439
440 err = st_sensors_check_device_support(indio_dev,
441 ARRAY_SIZE(st_accel_sensors), st_accel_sensors);
442 if (err < 0)
443 goto st_accel_common_probe_error;
444
445 adata->multiread_bit = adata->sensor->multi_read_bit;
446 indio_dev->channels = adata->sensor->ch;
447 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
448
449 adata->current_fullscale = (struct st_sensor_fullscale_avl *)
450 &adata->sensor->fs.fs_avl[0];
451 adata->odr = adata->sensor->odr.odr_avl[0].hz;
452
453 err = st_sensors_init_sensor(indio_dev);
454 if (err < 0)
455 goto st_accel_common_probe_error;
456
457 if (adata->get_irq_data_ready(indio_dev) > 0) {
458 err = st_accel_allocate_ring(indio_dev);
459 if (err < 0)
460 goto st_accel_common_probe_error;
461
462 err = st_sensors_allocate_trigger(indio_dev,
463 ST_ACCEL_TRIGGER_OPS);
464 if (err < 0)
465 goto st_accel_probe_trigger_error;
466 }
467
468 err = iio_device_register(indio_dev);
469 if (err)
470 goto st_accel_device_register_error;
471
472 return err;
473
474st_accel_device_register_error:
475 if (adata->get_irq_data_ready(indio_dev) > 0)
476 st_sensors_deallocate_trigger(indio_dev);
477st_accel_probe_trigger_error:
478 if (adata->get_irq_data_ready(indio_dev) > 0)
479 st_accel_deallocate_ring(indio_dev);
480st_accel_common_probe_error:
481 return err;
482}
483EXPORT_SYMBOL(st_accel_common_probe);
484
485void st_accel_common_remove(struct iio_dev *indio_dev)
486{
487 struct st_sensor_data *adata = iio_priv(indio_dev);
488
489 iio_device_unregister(indio_dev);
490 if (adata->get_irq_data_ready(indio_dev) > 0) {
491 st_sensors_deallocate_trigger(indio_dev);
492 st_accel_deallocate_ring(indio_dev);
493 }
494 iio_device_free(indio_dev);
495}
496EXPORT_SYMBOL(st_accel_common_remove);
497
498MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
499MODULE_DESCRIPTION("STMicroelectronics accelerometers driver");
500MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
new file mode 100644
index 000000000000..ffc9d097e484
--- /dev/null
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -0,0 +1,86 @@
1/*
2 * STMicroelectronics accelerometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/iio/iio.h>
16
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_accel.h"
20
21static int st_accel_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id)
23{
24 struct iio_dev *indio_dev;
25 struct st_sensor_data *adata;
26 int err;
27
28 indio_dev = iio_device_alloc(sizeof(*adata));
29 if (indio_dev == NULL) {
30 err = -ENOMEM;
31 goto iio_device_alloc_error;
32 }
33
34 adata = iio_priv(indio_dev);
35 adata->dev = &client->dev;
36
37 st_sensors_i2c_configure(indio_dev, client, adata);
38
39 err = st_accel_common_probe(indio_dev);
40 if (err < 0)
41 goto st_accel_common_probe_error;
42
43 return 0;
44
45st_accel_common_probe_error:
46 iio_device_free(indio_dev);
47iio_device_alloc_error:
48 return err;
49}
50
51static int st_accel_i2c_remove(struct i2c_client *client)
52{
53 st_accel_common_remove(i2c_get_clientdata(client));
54
55 return 0;
56}
57
58static const struct i2c_device_id st_accel_id_table[] = {
59 { LSM303DLH_ACCEL_DEV_NAME },
60 { LSM303DLHC_ACCEL_DEV_NAME },
61 { LIS3DH_ACCEL_DEV_NAME },
62 { LSM330D_ACCEL_DEV_NAME },
63 { LSM330DL_ACCEL_DEV_NAME },
64 { LSM330DLC_ACCEL_DEV_NAME },
65 { LIS331DLH_ACCEL_DEV_NAME },
66 { LSM303DL_ACCEL_DEV_NAME },
67 { LSM303DLM_ACCEL_DEV_NAME },
68 { LSM330_ACCEL_DEV_NAME },
69 {},
70};
71MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
72
73static struct i2c_driver st_accel_driver = {
74 .driver = {
75 .owner = THIS_MODULE,
76 .name = "st-accel-i2c",
77 },
78 .probe = st_accel_i2c_probe,
79 .remove = st_accel_i2c_remove,
80 .id_table = st_accel_id_table,
81};
82module_i2c_driver(st_accel_driver);
83
84MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
85MODULE_DESCRIPTION("STMicroelectronics accelerometers i2c driver");
86MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
new file mode 100644
index 000000000000..22b35bfea7d2
--- /dev/null
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -0,0 +1,85 @@
1/*
2 * STMicroelectronics accelerometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/spi/spi.h>
15#include <linux/iio/iio.h>
16
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_spi.h>
19#include "st_accel.h"
20
21static int st_accel_spi_probe(struct spi_device *spi)
22{
23 struct iio_dev *indio_dev;
24 struct st_sensor_data *adata;
25 int err;
26
27 indio_dev = iio_device_alloc(sizeof(*adata));
28 if (indio_dev == NULL) {
29 err = -ENOMEM;
30 goto iio_device_alloc_error;
31 }
32
33 adata = iio_priv(indio_dev);
34 adata->dev = &spi->dev;
35
36 st_sensors_spi_configure(indio_dev, spi, adata);
37
38 err = st_accel_common_probe(indio_dev);
39 if (err < 0)
40 goto st_accel_common_probe_error;
41
42 return 0;
43
44st_accel_common_probe_error:
45 iio_device_free(indio_dev);
46iio_device_alloc_error:
47 return err;
48}
49
50static int st_accel_spi_remove(struct spi_device *spi)
51{
52 st_accel_common_remove(spi_get_drvdata(spi));
53
54 return 0;
55}
56
57static const struct spi_device_id st_accel_id_table[] = {
58 { LSM303DLH_ACCEL_DEV_NAME },
59 { LSM303DLHC_ACCEL_DEV_NAME },
60 { LIS3DH_ACCEL_DEV_NAME },
61 { LSM330D_ACCEL_DEV_NAME },
62 { LSM330DL_ACCEL_DEV_NAME },
63 { LSM330DLC_ACCEL_DEV_NAME },
64 { LIS331DLH_ACCEL_DEV_NAME },
65 { LSM303DL_ACCEL_DEV_NAME },
66 { LSM303DLM_ACCEL_DEV_NAME },
67 { LSM330_ACCEL_DEV_NAME },
68 {},
69};
70MODULE_DEVICE_TABLE(spi, st_accel_id_table);
71
72static struct spi_driver st_accel_driver = {
73 .driver = {
74 .owner = THIS_MODULE,
75 .name = "st-accel-spi",
76 },
77 .probe = st_accel_spi_probe,
78 .remove = st_accel_spi_remove,
79 .id_table = st_accel_id_table,
80};
81module_spi_driver(st_accel_driver);
82
83MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
84MODULE_DESCRIPTION("STMicroelectronics accelerometers spi driver");
85MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index fe822a14d130..e372257a8494 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -100,10 +100,8 @@ config LP8788_ADC
100config MAX1363 100config MAX1363
101 tristate "Maxim max1363 ADC driver" 101 tristate "Maxim max1363 ADC driver"
102 depends on I2C 102 depends on I2C
103 select IIO_TRIGGER
104 select MAX1363_RING_BUFFER
105 select IIO_BUFFER 103 select IIO_BUFFER
106 select IIO_KFIFO_BUF 104 select IIO_TRIGGERED_BUFFER
107 help 105 help
108 Say yes here to build support for many Maxim i2c analog to digital 106 Say yes here to build support for many Maxim i2c analog to digital
109 converters (ADC). (max1361, max1362, max1363, max1364, max1036, 107 converters (ADC). (max1361, max1362, max1363, max1364, max1036,
diff --git a/drivers/iio/adc/lp8788_adc.c b/drivers/iio/adc/lp8788_adc.c
index 72955e45e9e0..763f57565ee4 100644
--- a/drivers/iio/adc/lp8788_adc.c
+++ b/drivers/iio/adc/lp8788_adc.c
@@ -179,7 +179,7 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
179 179
180 ret = iio_map_array_register(indio_dev, map); 180 ret = iio_map_array_register(indio_dev, map);
181 if (ret) { 181 if (ret) {
182 dev_err(adc->lp->dev, "iio map err: %d\n", ret); 182 dev_err(&indio_dev->dev, "iio map err: %d\n", ret);
183 return ret; 183 return ret;
184 } 184 }
185 185
@@ -187,12 +187,6 @@ static int lp8788_iio_map_register(struct iio_dev *indio_dev,
187 return 0; 187 return 0;
188} 188}
189 189
190static inline void lp8788_iio_map_unregister(struct iio_dev *indio_dev,
191 struct lp8788_adc *adc)
192{
193 iio_map_array_unregister(indio_dev, adc->map);
194}
195
196static int lp8788_adc_probe(struct platform_device *pdev) 190static int lp8788_adc_probe(struct platform_device *pdev)
197{ 191{
198 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent); 192 struct lp8788 *lp = dev_get_drvdata(pdev->dev.parent);
@@ -208,13 +202,14 @@ static int lp8788_adc_probe(struct platform_device *pdev)
208 adc->lp = lp; 202 adc->lp = lp;
209 platform_set_drvdata(pdev, indio_dev); 203 platform_set_drvdata(pdev, indio_dev);
210 204
205 indio_dev->dev.of_node = pdev->dev.of_node;
211 ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc); 206 ret = lp8788_iio_map_register(indio_dev, lp->pdata, adc);
212 if (ret) 207 if (ret)
213 goto err_iio_map; 208 goto err_iio_map;
214 209
215 mutex_init(&adc->lock); 210 mutex_init(&adc->lock);
216 211
217 indio_dev->dev.parent = lp->dev; 212 indio_dev->dev.parent = &pdev->dev;
218 indio_dev->name = pdev->name; 213 indio_dev->name = pdev->name;
219 indio_dev->modes = INDIO_DIRECT_MODE; 214 indio_dev->modes = INDIO_DIRECT_MODE;
220 indio_dev->info = &lp8788_adc_info; 215 indio_dev->info = &lp8788_adc_info;
@@ -223,14 +218,14 @@ static int lp8788_adc_probe(struct platform_device *pdev)
223 218
224 ret = iio_device_register(indio_dev); 219 ret = iio_device_register(indio_dev);
225 if (ret) { 220 if (ret) {
226 dev_err(lp->dev, "iio dev register err: %d\n", ret); 221 dev_err(&pdev->dev, "iio dev register err: %d\n", ret);
227 goto err_iio_device; 222 goto err_iio_device;
228 } 223 }
229 224
230 return 0; 225 return 0;
231 226
232err_iio_device: 227err_iio_device:
233 lp8788_iio_map_unregister(indio_dev, adc); 228 iio_map_array_unregister(indio_dev);
234err_iio_map: 229err_iio_map:
235 iio_device_free(indio_dev); 230 iio_device_free(indio_dev);
236 return ret; 231 return ret;
@@ -239,10 +234,9 @@ err_iio_map:
239static int lp8788_adc_remove(struct platform_device *pdev) 234static int lp8788_adc_remove(struct platform_device *pdev)
240{ 235{
241 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 236 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
242 struct lp8788_adc *adc = iio_priv(indio_dev);
243 237
244 iio_device_unregister(indio_dev); 238 iio_device_unregister(indio_dev);
245 lp8788_iio_map_unregister(indio_dev, adc); 239 iio_map_array_unregister(indio_dev);
246 iio_device_free(indio_dev); 240 iio_device_free(indio_dev);
247 241
248 return 0; 242 return 0;
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 03b25b3dc71e..6c1cfb74bdfc 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -39,6 +39,7 @@
39#include <linux/iio/driver.h> 39#include <linux/iio/driver.h>
40#include <linux/iio/kfifo_buf.h> 40#include <linux/iio/kfifo_buf.h>
41#include <linux/iio/trigger_consumer.h> 41#include <linux/iio/trigger_consumer.h>
42#include <linux/iio/triggered_buffer.h>
42 43
43#define MAX1363_SETUP_BYTE(a) ((a) | 0x80) 44#define MAX1363_SETUP_BYTE(a) ((a) | 0x80)
44 45
@@ -55,7 +56,7 @@
55#define MAX1363_SETUP_POWER_UP_INT_REF 0x10 56#define MAX1363_SETUP_POWER_UP_INT_REF 0x10
56#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00 57#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00
57 58
58/* think about includeing max11600 etc - more settings */ 59/* think about including max11600 etc - more settings */
59#define MAX1363_SETUP_EXT_CLOCK 0x08 60#define MAX1363_SETUP_EXT_CLOCK 0x08
60#define MAX1363_SETUP_INT_CLOCK 0x00 61#define MAX1363_SETUP_INT_CLOCK 0x00
61#define MAX1363_SETUP_UNIPOLAR 0x00 62#define MAX1363_SETUP_UNIPOLAR 0x00
@@ -86,7 +87,7 @@
86/* max123{6-9} only */ 87/* max123{6-9} only */
87#define MAX1236_SCAN_MID_TO_CHANNEL 0x40 88#define MAX1236_SCAN_MID_TO_CHANNEL 0x40
88 89
89/* max1363 only - merely part of channel selects or don't care for others*/ 90/* max1363 only - merely part of channel selects or don't care for others */
90#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18 91#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18
91 92
92#define MAX1363_CHANNEL_SEL(a) ((a) << 1) 93#define MAX1363_CHANNEL_SEL(a) ((a) << 1)
@@ -133,7 +134,7 @@ enum max1363_modes {
133 * @mode_list: array of available scan modes 134 * @mode_list: array of available scan modes
134 * @default_mode: the scan mode in which the chip starts up 135 * @default_mode: the scan mode in which the chip starts up
135 * @int_vref_mv: the internal reference voltage 136 * @int_vref_mv: the internal reference voltage
136 * @num_channels: number of channels 137 * @num_modes: number of modes
137 * @bits: accuracy of the adc in bits 138 * @bits: accuracy of the adc in bits
138 */ 139 */
139struct max1363_chip_info { 140struct max1363_chip_info {
@@ -152,7 +153,7 @@ struct max1363_chip_info {
152 * @client: i2c_client 153 * @client: i2c_client
153 * @setupbyte: cache of current device setup byte 154 * @setupbyte: cache of current device setup byte
154 * @configbyte: cache of current device config byte 155 * @configbyte: cache of current device config byte
155 * @chip_info: chip model specific constants, available modes etc 156 * @chip_info: chip model specific constants, available modes, etc.
156 * @current_mode: the scan mode of this chip 157 * @current_mode: the scan mode of this chip
157 * @requestedmask: a valid requested set of channels 158 * @requestedmask: a valid requested set of channels
158 * @reg: supply regulator 159 * @reg: supply regulator
@@ -162,6 +163,8 @@ struct max1363_chip_info {
162 * @mask_low: bitmask for enabled low thresholds 163 * @mask_low: bitmask for enabled low thresholds
163 * @thresh_high: high threshold values 164 * @thresh_high: high threshold values
164 * @thresh_low: low threshold values 165 * @thresh_low: low threshold values
166 * @vref: Reference voltage regulator
167 * @vref_uv: Actual (external or internal) reference voltage
165 */ 168 */
166struct max1363_state { 169struct max1363_state {
167 struct i2c_client *client; 170 struct i2c_client *client;
@@ -181,6 +184,8 @@ struct max1363_state {
181 /* 4x unipolar first then the fours bipolar ones */ 184 /* 4x unipolar first then the fours bipolar ones */
182 s16 thresh_high[8]; 185 s16 thresh_high[8];
183 s16 thresh_low[8]; 186 s16 thresh_low[8];
187 struct regulator *vref;
188 u32 vref_uv;
184}; 189};
185 190
186#define MAX1363_MODE_SINGLE(_num, _mask) { \ 191#define MAX1363_MODE_SINGLE(_num, _mask) { \
@@ -293,7 +298,7 @@ static const struct max1363_mode max1363_mode_table[] = {
293 298
294static const struct max1363_mode 299static const struct max1363_mode
295*max1363_match_mode(const unsigned long *mask, 300*max1363_match_mode(const unsigned long *mask,
296const struct max1363_chip_info *ci) 301 const struct max1363_chip_info *ci)
297{ 302{
298 int i; 303 int i;
299 if (mask) 304 if (mask)
@@ -334,7 +339,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
334{ 339{
335 int ret = 0; 340 int ret = 0;
336 s32 data; 341 s32 data;
337 char rxbuf[2]; 342 u8 rxbuf[2];
338 struct max1363_state *st = iio_priv(indio_dev); 343 struct max1363_state *st = iio_priv(indio_dev);
339 struct i2c_client *client = st->client; 344 struct i2c_client *client = st->client;
340 345
@@ -366,7 +371,8 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev,
366 ret = data; 371 ret = data;
367 goto error_ret; 372 goto error_ret;
368 } 373 }
369 data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; 374 data = (rxbuf[1] | rxbuf[0] << 8) &
375 ((1 << st->chip_info->bits) - 1);
370 } else { 376 } else {
371 /* Get reading */ 377 /* Get reading */
372 data = i2c_master_recv(client, rxbuf, 1); 378 data = i2c_master_recv(client, rxbuf, 1);
@@ -391,6 +397,8 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
391{ 397{
392 struct max1363_state *st = iio_priv(indio_dev); 398 struct max1363_state *st = iio_priv(indio_dev);
393 int ret; 399 int ret;
400 unsigned long scale_uv;
401
394 switch (m) { 402 switch (m) {
395 case IIO_CHAN_INFO_RAW: 403 case IIO_CHAN_INFO_RAW:
396 ret = max1363_read_single_chan(indio_dev, chan, val, m); 404 ret = max1363_read_single_chan(indio_dev, chan, val, m);
@@ -398,16 +406,10 @@ static int max1363_read_raw(struct iio_dev *indio_dev,
398 return ret; 406 return ret;
399 return IIO_VAL_INT; 407 return IIO_VAL_INT;
400 case IIO_CHAN_INFO_SCALE: 408 case IIO_CHAN_INFO_SCALE:
401 if ((1 << (st->chip_info->bits + 1)) > 409 scale_uv = st->vref_uv >> st->chip_info->bits;
402 st->chip_info->int_vref_mv) { 410 *val = scale_uv / 1000;
403 *val = 0; 411 *val2 = (scale_uv % 1000) * 1000;
404 *val2 = 500000; 412 return IIO_VAL_INT_PLUS_MICRO;
405 return IIO_VAL_INT_PLUS_MICRO;
406 } else {
407 *val = (st->chip_info->int_vref_mv)
408 >> st->chip_info->bits;
409 return IIO_VAL_INT;
410 }
411 default: 413 default:
412 return -EINVAL; 414 return -EINVAL;
413 } 415 }
@@ -1388,13 +1390,17 @@ static const struct max1363_chip_info max1363_chip_info_tbl[] = {
1388 1390
1389static int max1363_initial_setup(struct max1363_state *st) 1391static int max1363_initial_setup(struct max1363_state *st)
1390{ 1392{
1391 st->setupbyte = MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD 1393 st->setupbyte = MAX1363_SETUP_INT_CLOCK
1392 | MAX1363_SETUP_POWER_UP_INT_REF
1393 | MAX1363_SETUP_INT_CLOCK
1394 | MAX1363_SETUP_UNIPOLAR 1394 | MAX1363_SETUP_UNIPOLAR
1395 | MAX1363_SETUP_NORESET; 1395 | MAX1363_SETUP_NORESET;
1396 1396
1397 /* Set scan mode writes the config anyway so wait until then*/ 1397 if (st->vref)
1398 st->setupbyte |= MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF;
1399 else
1400 st->setupbyte |= MAX1363_SETUP_POWER_UP_INT_REF
1401 | MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT;
1402
1403 /* Set scan mode writes the config anyway so wait until then */
1398 st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte); 1404 st->setupbyte = MAX1363_SETUP_BYTE(st->setupbyte);
1399 st->current_mode = &max1363_mode_table[st->chip_info->default_mode]; 1405 st->current_mode = &max1363_mode_table[st->chip_info->default_mode];
1400 st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte); 1406 st->configbyte = MAX1363_CONFIG_BYTE(st->configbyte);
@@ -1408,8 +1414,9 @@ static int max1363_alloc_scan_masks(struct iio_dev *indio_dev)
1408 unsigned long *masks; 1414 unsigned long *masks;
1409 int i; 1415 int i;
1410 1416
1411 masks = kzalloc(BITS_TO_LONGS(MAX1363_MAX_CHANNELS)*sizeof(long)* 1417 masks = devm_kzalloc(&indio_dev->dev,
1412 (st->chip_info->num_modes + 1), GFP_KERNEL); 1418 BITS_TO_LONGS(MAX1363_MAX_CHANNELS) * sizeof(long) *
1419 (st->chip_info->num_modes + 1), GFP_KERNEL);
1413 if (!masks) 1420 if (!masks)
1414 return -ENOMEM; 1421 return -ENOMEM;
1415 1422
@@ -1423,7 +1430,6 @@ static int max1363_alloc_scan_masks(struct iio_dev *indio_dev)
1423 return 0; 1430 return 0;
1424} 1431}
1425 1432
1426
1427static irqreturn_t max1363_trigger_handler(int irq, void *p) 1433static irqreturn_t max1363_trigger_handler(int irq, void *p)
1428{ 1434{
1429 struct iio_poll_func *pf = p; 1435 struct iio_poll_func *pf = p;
@@ -1483,54 +1489,13 @@ static const struct iio_buffer_setup_ops max1363_buffered_setup_ops = {
1483 .predisable = &iio_triggered_buffer_predisable, 1489 .predisable = &iio_triggered_buffer_predisable,
1484}; 1490};
1485 1491
1486static int max1363_register_buffered_funcs_and_init(struct iio_dev *indio_dev)
1487{
1488 struct max1363_state *st = iio_priv(indio_dev);
1489 int ret = 0;
1490
1491 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
1492 if (!indio_dev->buffer) {
1493 ret = -ENOMEM;
1494 goto error_ret;
1495 }
1496 indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
1497 &max1363_trigger_handler,
1498 IRQF_ONESHOT,
1499 indio_dev,
1500 "%s_consumer%d",
1501 st->client->name,
1502 indio_dev->id);
1503 if (indio_dev->pollfunc == NULL) {
1504 ret = -ENOMEM;
1505 goto error_deallocate_sw_rb;
1506 }
1507 /* Buffer functions - here trigger setup related */
1508 indio_dev->setup_ops = &max1363_buffered_setup_ops;
1509
1510 /* Flag that polled buffering is possible */
1511 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
1512
1513 return 0;
1514
1515error_deallocate_sw_rb:
1516 iio_kfifo_free(indio_dev->buffer);
1517error_ret:
1518 return ret;
1519}
1520
1521static void max1363_buffer_cleanup(struct iio_dev *indio_dev)
1522{
1523 /* ensure that the trigger has been detached */
1524 iio_dealloc_pollfunc(indio_dev->pollfunc);
1525 iio_kfifo_free(indio_dev->buffer);
1526}
1527
1528static int max1363_probe(struct i2c_client *client, 1492static int max1363_probe(struct i2c_client *client,
1529 const struct i2c_device_id *id) 1493 const struct i2c_device_id *id)
1530{ 1494{
1531 int ret; 1495 int ret;
1532 struct max1363_state *st; 1496 struct max1363_state *st;
1533 struct iio_dev *indio_dev; 1497 struct iio_dev *indio_dev;
1498 struct regulator *vref;
1534 1499
1535 indio_dev = iio_device_alloc(sizeof(struct max1363_state)); 1500 indio_dev = iio_device_alloc(sizeof(struct max1363_state));
1536 if (indio_dev == NULL) { 1501 if (indio_dev == NULL) {
@@ -1538,13 +1503,14 @@ static int max1363_probe(struct i2c_client *client,
1538 goto error_out; 1503 goto error_out;
1539 } 1504 }
1540 1505
1506 indio_dev->dev.of_node = client->dev.of_node;
1541 ret = iio_map_array_register(indio_dev, client->dev.platform_data); 1507 ret = iio_map_array_register(indio_dev, client->dev.platform_data);
1542 if (ret < 0) 1508 if (ret < 0)
1543 goto error_free_device; 1509 goto error_free_device;
1544 1510
1545 st = iio_priv(indio_dev); 1511 st = iio_priv(indio_dev);
1546 1512
1547 st->reg = regulator_get(&client->dev, "vcc"); 1513 st->reg = devm_regulator_get(&client->dev, "vcc");
1548 if (IS_ERR(st->reg)) { 1514 if (IS_ERR(st->reg)) {
1549 ret = PTR_ERR(st->reg); 1515 ret = PTR_ERR(st->reg);
1550 goto error_unregister_map; 1516 goto error_unregister_map;
@@ -1552,7 +1518,7 @@ static int max1363_probe(struct i2c_client *client,
1552 1518
1553 ret = regulator_enable(st->reg); 1519 ret = regulator_enable(st->reg);
1554 if (ret) 1520 if (ret)
1555 goto error_put_reg; 1521 goto error_unregister_map;
1556 1522
1557 /* this is only used for device removal purposes */ 1523 /* this is only used for device removal purposes */
1558 i2c_set_clientdata(client, indio_dev); 1524 i2c_set_clientdata(client, indio_dev);
@@ -1560,35 +1526,45 @@ static int max1363_probe(struct i2c_client *client,
1560 st->chip_info = &max1363_chip_info_tbl[id->driver_data]; 1526 st->chip_info = &max1363_chip_info_tbl[id->driver_data];
1561 st->client = client; 1527 st->client = client;
1562 1528
1529 st->vref_uv = st->chip_info->int_vref_mv * 1000;
1530 vref = devm_regulator_get(&client->dev, "vref");
1531 if (!IS_ERR(vref)) {
1532 int vref_uv;
1533
1534 ret = regulator_enable(vref);
1535 if (ret)
1536 goto error_disable_reg;
1537 st->vref = vref;
1538 vref_uv = regulator_get_voltage(vref);
1539 if (vref_uv <= 0) {
1540 ret = -EINVAL;
1541 goto error_disable_reg;
1542 }
1543 st->vref_uv = vref_uv;
1544 }
1545
1563 ret = max1363_alloc_scan_masks(indio_dev); 1546 ret = max1363_alloc_scan_masks(indio_dev);
1564 if (ret) 1547 if (ret)
1565 goto error_disable_reg; 1548 goto error_disable_reg;
1566 1549
1567 /* Estabilish that the iio_dev is a child of the i2c device */ 1550 /* Establish that the iio_dev is a child of the i2c device */
1568 indio_dev->dev.parent = &client->dev; 1551 indio_dev->dev.parent = &client->dev;
1569 indio_dev->name = id->name; 1552 indio_dev->name = id->name;
1570 indio_dev->channels = st->chip_info->channels; 1553 indio_dev->channels = st->chip_info->channels;
1571 indio_dev->num_channels = st->chip_info->num_channels; 1554 indio_dev->num_channels = st->chip_info->num_channels;
1572 indio_dev->info = st->chip_info->info; 1555 indio_dev->info = st->chip_info->info;
1573 indio_dev->modes = INDIO_DIRECT_MODE; 1556 indio_dev->modes = INDIO_DIRECT_MODE;
1574 indio_dev->channels = st->chip_info->channels;
1575 indio_dev->num_channels = st->chip_info->num_channels;
1576 ret = max1363_initial_setup(st); 1557 ret = max1363_initial_setup(st);
1577 if (ret < 0) 1558 if (ret < 0)
1578 goto error_free_available_scan_masks; 1559 goto error_disable_reg;
1579
1580 ret = max1363_register_buffered_funcs_and_init(indio_dev);
1581 if (ret)
1582 goto error_free_available_scan_masks;
1583 1560
1584 ret = iio_buffer_register(indio_dev, 1561 ret = iio_triggered_buffer_setup(indio_dev, NULL,
1585 st->chip_info->channels, 1562 &max1363_trigger_handler, &max1363_buffered_setup_ops);
1586 st->chip_info->num_channels);
1587 if (ret) 1563 if (ret)
1588 goto error_cleanup_buffer; 1564 goto error_disable_reg;
1589 1565
1590 if (client->irq) { 1566 if (client->irq) {
1591 ret = request_threaded_irq(st->client->irq, 1567 ret = devm_request_threaded_irq(&client->dev, st->client->irq,
1592 NULL, 1568 NULL,
1593 &max1363_event_handler, 1569 &max1363_event_handler,
1594 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 1570 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
@@ -1601,24 +1577,18 @@ static int max1363_probe(struct i2c_client *client,
1601 1577
1602 ret = iio_device_register(indio_dev); 1578 ret = iio_device_register(indio_dev);
1603 if (ret < 0) 1579 if (ret < 0)
1604 goto error_free_irq; 1580 goto error_uninit_buffer;
1605 1581
1606 return 0; 1582 return 0;
1607error_free_irq: 1583
1608 if (client->irq)
1609 free_irq(st->client->irq, indio_dev);
1610error_uninit_buffer: 1584error_uninit_buffer:
1611 iio_buffer_unregister(indio_dev); 1585 iio_triggered_buffer_cleanup(indio_dev);
1612error_cleanup_buffer:
1613 max1363_buffer_cleanup(indio_dev);
1614error_free_available_scan_masks:
1615 kfree(indio_dev->available_scan_masks);
1616error_disable_reg: 1586error_disable_reg:
1587 if (st->vref)
1588 regulator_disable(st->vref);
1617 regulator_disable(st->reg); 1589 regulator_disable(st->reg);
1618error_put_reg:
1619 regulator_put(st->reg);
1620error_unregister_map: 1590error_unregister_map:
1621 iio_map_array_unregister(indio_dev, client->dev.platform_data); 1591 iio_map_array_unregister(indio_dev);
1622error_free_device: 1592error_free_device:
1623 iio_device_free(indio_dev); 1593 iio_device_free(indio_dev);
1624error_out: 1594error_out:
@@ -1631,14 +1601,11 @@ static int max1363_remove(struct i2c_client *client)
1631 struct max1363_state *st = iio_priv(indio_dev); 1601 struct max1363_state *st = iio_priv(indio_dev);
1632 1602
1633 iio_device_unregister(indio_dev); 1603 iio_device_unregister(indio_dev);
1634 if (client->irq) 1604 iio_triggered_buffer_cleanup(indio_dev);
1635 free_irq(st->client->irq, indio_dev); 1605 if (st->vref)
1636 iio_buffer_unregister(indio_dev); 1606 regulator_disable(st->vref);
1637 max1363_buffer_cleanup(indio_dev);
1638 kfree(indio_dev->available_scan_masks);
1639 regulator_disable(st->reg); 1607 regulator_disable(st->reg);
1640 regulator_put(st->reg); 1608 iio_map_array_unregister(indio_dev);
1641 iio_map_array_unregister(indio_dev, client->dev.platform_data);
1642 iio_device_free(indio_dev); 1609 iio_device_free(indio_dev);
1643 1610
1644 return 0; 1611 return 0;
diff --git a/drivers/iio/buffer_cb.c b/drivers/iio/buffer_cb.c
index 4d40e24f3721..9201022945e9 100644
--- a/drivers/iio/buffer_cb.c
+++ b/drivers/iio/buffer_cb.c
@@ -25,7 +25,7 @@ static struct iio_buffer_access_funcs iio_cb_access = {
25 .store_to = &iio_buffer_cb_store_to, 25 .store_to = &iio_buffer_cb_store_to,
26}; 26};
27 27
28struct iio_cb_buffer *iio_channel_get_all_cb(const char *name, 28struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
29 int (*cb)(u8 *data, 29 int (*cb)(u8 *data,
30 void *private), 30 void *private),
31 void *private) 31 void *private)
@@ -46,7 +46,7 @@ struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,
46 cb_buff->buffer.access = &iio_cb_access; 46 cb_buff->buffer.access = &iio_cb_access;
47 INIT_LIST_HEAD(&cb_buff->buffer.demux_list); 47 INIT_LIST_HEAD(&cb_buff->buffer.demux_list);
48 48
49 cb_buff->channels = iio_channel_get_all(name); 49 cb_buff->channels = iio_channel_get_all(dev);
50 if (IS_ERR(cb_buff->channels)) { 50 if (IS_ERR(cb_buff->channels)) {
51 ret = PTR_ERR(cb_buff->channels); 51 ret = PTR_ERR(cb_buff->channels);
52 goto error_free_cb_buff; 52 goto error_free_cb_buff;
diff --git a/drivers/iio/common/Kconfig b/drivers/iio/common/Kconfig
index ed45ee54500c..0b6e97d18fa0 100644
--- a/drivers/iio/common/Kconfig
+++ b/drivers/iio/common/Kconfig
@@ -3,3 +3,4 @@
3# 3#
4 4
5source "drivers/iio/common/hid-sensors/Kconfig" 5source "drivers/iio/common/hid-sensors/Kconfig"
6source "drivers/iio/common/st_sensors/Kconfig"
diff --git a/drivers/iio/common/Makefile b/drivers/iio/common/Makefile
index 81584009b21b..c2352beb5d97 100644
--- a/drivers/iio/common/Makefile
+++ b/drivers/iio/common/Makefile
@@ -7,3 +7,4 @@
7# 7#
8 8
9obj-y += hid-sensors/ 9obj-y += hid-sensors/
10obj-y += st_sensors/
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 75374955caba..75b54730a963 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -25,7 +25,6 @@
25#include <linux/hid-sensor-hub.h> 25#include <linux/hid-sensor-hub.h>
26#include <linux/iio/iio.h> 26#include <linux/iio/iio.h>
27#include <linux/iio/sysfs.h> 27#include <linux/iio/sysfs.h>
28#include "hid-sensor-attributes.h"
29 28
30static int pow_10(unsigned power) 29static int pow_10(unsigned power)
31{ 30{
@@ -114,7 +113,7 @@ static u32 convert_to_vtf_format(int size, int exp, int val1, int val2)
114 return value; 113 return value;
115} 114}
116 115
117int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st, 116int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
118 int *val1, int *val2) 117 int *val1, int *val2)
119{ 118{
120 s32 value; 119 s32 value;
@@ -141,7 +140,7 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
141} 140}
142EXPORT_SYMBOL(hid_sensor_read_samp_freq_value); 141EXPORT_SYMBOL(hid_sensor_read_samp_freq_value);
143 142
144int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st, 143int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
145 int val1, int val2) 144 int val1, int val2)
146{ 145{
147 s32 value; 146 s32 value;
@@ -169,7 +168,7 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
169} 168}
170EXPORT_SYMBOL(hid_sensor_write_samp_freq_value); 169EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
171 170
172int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st, 171int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
173 int *val1, int *val2) 172 int *val1, int *val2)
174{ 173{
175 s32 value; 174 s32 value;
@@ -191,7 +190,7 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
191} 190}
192EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value); 191EXPORT_SYMBOL(hid_sensor_read_raw_hyst_value);
193 192
194int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st, 193int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
195 int val1, int val2) 194 int val1, int val2)
196{ 195{
197 s32 value; 196 s32 value;
@@ -212,7 +211,7 @@ EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
212 211
213int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev, 212int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
214 u32 usage_id, 213 u32 usage_id,
215 struct hid_sensor_iio_common *st) 214 struct hid_sensor_common *st)
216{ 215{
217 216
218 sensor_hub_input_get_attribute_info(hsdev, 217 sensor_hub_input_get_attribute_info(hsdev,
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h b/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
deleted file mode 100644
index a4676a0c3de5..000000000000
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.h
+++ /dev/null
@@ -1,57 +0,0 @@
1/*
2 * HID Sensors Driver
3 * Copyright (c) 2012, Intel Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19#ifndef _HID_SENSORS_ATTRIBUTES_H
20#define _HID_SENSORS_ATTRIBUTES_H
21
22/* Common hid sensor iio structure */
23struct hid_sensor_iio_common {
24 struct hid_sensor_hub_device *hsdev;
25 struct platform_device *pdev;
26 unsigned usage_id;
27 bool data_ready;
28 struct hid_sensor_hub_attribute_info poll;
29 struct hid_sensor_hub_attribute_info report_state;
30 struct hid_sensor_hub_attribute_info power_state;
31 struct hid_sensor_hub_attribute_info sensitivity;
32};
33
34/*Convert from hid unit expo to regular exponent*/
35static inline int hid_sensor_convert_exponent(int unit_expo)
36{
37 if (unit_expo < 0x08)
38 return unit_expo;
39 else if (unit_expo <= 0x0f)
40 return -(0x0f-unit_expo+1);
41 else
42 return 0;
43}
44
45int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
46 u32 usage_id,
47 struct hid_sensor_iio_common *st);
48int hid_sensor_write_raw_hyst_value(struct hid_sensor_iio_common *st,
49 int val1, int val2);
50int hid_sensor_read_raw_hyst_value(struct hid_sensor_iio_common *st,
51 int *val1, int *val2);
52int hid_sensor_write_samp_freq_value(struct hid_sensor_iio_common *st,
53 int val1, int val2);
54int hid_sensor_read_samp_freq_value(struct hid_sensor_iio_common *st,
55 int *val1, int *val2);
56
57#endif
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index d60198a6ca29..7a525a91105d 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -26,13 +26,12 @@
26#include <linux/iio/iio.h> 26#include <linux/iio/iio.h>
27#include <linux/iio/trigger.h> 27#include <linux/iio/trigger.h>
28#include <linux/iio/sysfs.h> 28#include <linux/iio/sysfs.h>
29#include "hid-sensor-attributes.h"
30#include "hid-sensor-trigger.h" 29#include "hid-sensor-trigger.h"
31 30
32static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, 31static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
33 bool state) 32 bool state)
34{ 33{
35 struct hid_sensor_iio_common *st = trig->private_data; 34 struct hid_sensor_common *st = trig->private_data;
36 int state_val; 35 int state_val;
37 36
38 state_val = state ? 1 : 0; 37 state_val = state ? 1 : 0;
@@ -64,7 +63,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {
64}; 63};
65 64
66int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, 65int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
67 struct hid_sensor_iio_common *attrb) 66 struct hid_sensor_common *attrb)
68{ 67{
69 int ret; 68 int ret;
70 struct iio_trigger *trig; 69 struct iio_trigger *trig;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
index fd982971b1b8..9a8731478eda 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
@@ -20,7 +20,7 @@
20#define _HID_SENSOR_TRIGGER_H 20#define _HID_SENSOR_TRIGGER_H
21 21
22int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, 22int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
23 struct hid_sensor_iio_common *attrb); 23 struct hid_sensor_common *attrb);
24void hid_sensor_remove_trigger(struct iio_dev *indio_dev); 24void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
25 25
26#endif 26#endif
diff --git a/drivers/iio/common/st_sensors/Kconfig b/drivers/iio/common/st_sensors/Kconfig
new file mode 100644
index 000000000000..865f1ca33eb9
--- /dev/null
+++ b/drivers/iio/common/st_sensors/Kconfig
@@ -0,0 +1,14 @@
1#
2# STMicroelectronics sensors common library
3#
4
5config IIO_ST_SENSORS_I2C
6 tristate
7
8config IIO_ST_SENSORS_SPI
9 tristate
10
11config IIO_ST_SENSORS_CORE
12 tristate
13 select IIO_ST_SENSORS_I2C if I2C
14 select IIO_ST_SENSORS_SPI if SPI_MASTER
diff --git a/drivers/iio/common/st_sensors/Makefile b/drivers/iio/common/st_sensors/Makefile
new file mode 100644
index 000000000000..9f3e24f3024b
--- /dev/null
+++ b/drivers/iio/common/st_sensors/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for the STMicroelectronics sensor common modules.
3#
4
5obj-$(CONFIG_IIO_ST_SENSORS_I2C) += st_sensors_i2c.o
6obj-$(CONFIG_IIO_ST_SENSORS_SPI) += st_sensors_spi.o
7obj-$(CONFIG_IIO_ST_SENSORS_CORE) += st_sensors.o
8st_sensors-y := st_sensors_core.o
9st_sensors-$(CONFIG_IIO_BUFFER) += st_sensors_buffer.o
10st_sensors-$(CONFIG_IIO_TRIGGER) += st_sensors_trigger.o
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
new file mode 100644
index 000000000000..09b236d6ee89
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
@@ -0,0 +1,116 @@
1/*
2 * STMicroelectronics sensors buffer library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/iio/iio.h>
15#include <linux/iio/trigger.h>
16#include <linux/interrupt.h>
17#include <linux/iio/buffer.h>
18#include <linux/iio/trigger_consumer.h>
19#include <linux/iio/triggered_buffer.h>
20#include <linux/irqreturn.h>
21
22#include <linux/iio/common/st_sensors.h>
23
24
25int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
26{
27 int i, n = 0, len;
28 u8 addr[ST_SENSORS_NUMBER_DATA_CHANNELS];
29 struct st_sensor_data *sdata = iio_priv(indio_dev);
30
31 for (i = 0; i < ST_SENSORS_NUMBER_DATA_CHANNELS; i++) {
32 if (test_bit(i, indio_dev->active_scan_mask)) {
33 addr[n] = indio_dev->channels[i].address;
34 n++;
35 }
36 }
37 switch (n) {
38 case 1:
39 len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
40 addr[0], ST_SENSORS_BYTE_FOR_CHANNEL, buf,
41 sdata->multiread_bit);
42 break;
43 case 2:
44 if ((addr[1] - addr[0]) == ST_SENSORS_BYTE_FOR_CHANNEL) {
45 len = sdata->tf->read_multiple_byte(&sdata->tb,
46 sdata->dev, addr[0],
47 ST_SENSORS_BYTE_FOR_CHANNEL*n,
48 buf, sdata->multiread_bit);
49 } else {
50 u8 rx_array[ST_SENSORS_BYTE_FOR_CHANNEL*
51 ST_SENSORS_NUMBER_DATA_CHANNELS];
52 len = sdata->tf->read_multiple_byte(&sdata->tb,
53 sdata->dev, addr[0],
54 ST_SENSORS_BYTE_FOR_CHANNEL*
55 ST_SENSORS_NUMBER_DATA_CHANNELS,
56 rx_array, sdata->multiread_bit);
57 if (len < 0)
58 goto read_data_channels_error;
59
60 for (i = 0; i < n * ST_SENSORS_NUMBER_DATA_CHANNELS;
61 i++) {
62 if (i < n)
63 buf[i] = rx_array[i];
64 else
65 buf[i] = rx_array[n + i];
66 }
67 len = ST_SENSORS_BYTE_FOR_CHANNEL*n;
68 }
69 break;
70 case 3:
71 len = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
72 addr[0], ST_SENSORS_BYTE_FOR_CHANNEL*
73 ST_SENSORS_NUMBER_DATA_CHANNELS,
74 buf, sdata->multiread_bit);
75 break;
76 default:
77 len = -EINVAL;
78 goto read_data_channels_error;
79 }
80 if (len != ST_SENSORS_BYTE_FOR_CHANNEL*n) {
81 len = -EIO;
82 goto read_data_channels_error;
83 }
84
85read_data_channels_error:
86 return len;
87}
88EXPORT_SYMBOL(st_sensors_get_buffer_element);
89
90irqreturn_t st_sensors_trigger_handler(int irq, void *p)
91{
92 int len;
93 struct iio_poll_func *pf = p;
94 struct iio_dev *indio_dev = pf->indio_dev;
95 struct st_sensor_data *sdata = iio_priv(indio_dev);
96
97 len = st_sensors_get_buffer_element(indio_dev, sdata->buffer_data);
98 if (len < 0)
99 goto st_sensors_get_buffer_element_error;
100
101 if (indio_dev->scan_timestamp)
102 *(s64 *)((u8 *)sdata->buffer_data +
103 ALIGN(len, sizeof(s64))) = pf->timestamp;
104
105 iio_push_to_buffers(indio_dev, sdata->buffer_data);
106
107st_sensors_get_buffer_element_error:
108 iio_trigger_notify_done(indio_dev->trig);
109
110 return IRQ_HANDLED;
111}
112EXPORT_SYMBOL(st_sensors_trigger_handler);
113
114MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
115MODULE_DESCRIPTION("STMicroelectronics ST-sensors buffer");
116MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
new file mode 100644
index 000000000000..0198324a8b0c
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -0,0 +1,446 @@
1/*
2 * STMicroelectronics sensors core library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/delay.h>
15#include <linux/iio/iio.h>
16#include <asm/unaligned.h>
17
18#include <linux/iio/common/st_sensors.h>
19
20
21#define ST_SENSORS_WAI_ADDRESS 0x0f
22
23static int st_sensors_write_data_with_mask(struct iio_dev *indio_dev,
24 u8 reg_addr, u8 mask, u8 data)
25{
26 int err;
27 u8 new_data;
28 struct st_sensor_data *sdata = iio_priv(indio_dev);
29
30 err = sdata->tf->read_byte(&sdata->tb, sdata->dev, reg_addr, &new_data);
31 if (err < 0)
32 goto st_sensors_write_data_with_mask_error;
33
34 new_data = ((new_data & (~mask)) | ((data << __ffs(mask)) & mask));
35 err = sdata->tf->write_byte(&sdata->tb, sdata->dev, reg_addr, new_data);
36
37st_sensors_write_data_with_mask_error:
38 return err;
39}
40
41static int st_sensors_match_odr(struct st_sensors *sensor,
42 unsigned int odr, struct st_sensor_odr_avl *odr_out)
43{
44 int i, ret = -EINVAL;
45
46 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
47 if (sensor->odr.odr_avl[i].hz == 0)
48 goto st_sensors_match_odr_error;
49
50 if (sensor->odr.odr_avl[i].hz == odr) {
51 odr_out->hz = sensor->odr.odr_avl[i].hz;
52 odr_out->value = sensor->odr.odr_avl[i].value;
53 ret = 0;
54 break;
55 }
56 }
57
58st_sensors_match_odr_error:
59 return ret;
60}
61
62int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr)
63{
64 int err;
65 struct st_sensor_odr_avl odr_out;
66 struct st_sensor_data *sdata = iio_priv(indio_dev);
67
68 err = st_sensors_match_odr(sdata->sensor, odr, &odr_out);
69 if (err < 0)
70 goto st_sensors_match_odr_error;
71
72 if ((sdata->sensor->odr.addr == sdata->sensor->pw.addr) &&
73 (sdata->sensor->odr.mask == sdata->sensor->pw.mask)) {
74 if (sdata->enabled == true) {
75 err = st_sensors_write_data_with_mask(indio_dev,
76 sdata->sensor->odr.addr,
77 sdata->sensor->odr.mask,
78 odr_out.value);
79 } else {
80 err = 0;
81 }
82 } else {
83 err = st_sensors_write_data_with_mask(indio_dev,
84 sdata->sensor->odr.addr, sdata->sensor->odr.mask,
85 odr_out.value);
86 }
87 if (err >= 0)
88 sdata->odr = odr_out.hz;
89
90st_sensors_match_odr_error:
91 return err;
92}
93EXPORT_SYMBOL(st_sensors_set_odr);
94
95static int st_sensors_match_fs(struct st_sensors *sensor,
96 unsigned int fs, int *index_fs_avl)
97{
98 int i, ret = -EINVAL;
99
100 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
101 if (sensor->fs.fs_avl[i].num == 0)
102 goto st_sensors_match_odr_error;
103
104 if (sensor->fs.fs_avl[i].num == fs) {
105 *index_fs_avl = i;
106 ret = 0;
107 break;
108 }
109 }
110
111st_sensors_match_odr_error:
112 return ret;
113}
114
115static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs)
116{
117 int err, i;
118 struct st_sensor_data *sdata = iio_priv(indio_dev);
119
120 err = st_sensors_match_fs(sdata->sensor, fs, &i);
121 if (err < 0)
122 goto st_accel_set_fullscale_error;
123
124 err = st_sensors_write_data_with_mask(indio_dev,
125 sdata->sensor->fs.addr,
126 sdata->sensor->fs.mask,
127 sdata->sensor->fs.fs_avl[i].value);
128 if (err < 0)
129 goto st_accel_set_fullscale_error;
130
131 sdata->current_fullscale = (struct st_sensor_fullscale_avl *)
132 &sdata->sensor->fs.fs_avl[i];
133 return err;
134
135st_accel_set_fullscale_error:
136 dev_err(&indio_dev->dev, "failed to set new fullscale.\n");
137 return err;
138}
139
140int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable)
141{
142 bool found;
143 u8 tmp_value;
144 int err = -EINVAL;
145 struct st_sensor_odr_avl odr_out;
146 struct st_sensor_data *sdata = iio_priv(indio_dev);
147
148 if (enable) {
149 found = false;
150 tmp_value = sdata->sensor->pw.value_on;
151 if ((sdata->sensor->odr.addr == sdata->sensor->pw.addr) &&
152 (sdata->sensor->odr.mask == sdata->sensor->pw.mask)) {
153 err = st_sensors_match_odr(sdata->sensor,
154 sdata->odr, &odr_out);
155 if (err < 0)
156 goto set_enable_error;
157 tmp_value = odr_out.value;
158 found = true;
159 }
160 err = st_sensors_write_data_with_mask(indio_dev,
161 sdata->sensor->pw.addr,
162 sdata->sensor->pw.mask, tmp_value);
163 if (err < 0)
164 goto set_enable_error;
165
166 sdata->enabled = true;
167
168 if (found)
169 sdata->odr = odr_out.hz;
170 } else {
171 err = st_sensors_write_data_with_mask(indio_dev,
172 sdata->sensor->pw.addr,
173 sdata->sensor->pw.mask,
174 sdata->sensor->pw.value_off);
175 if (err < 0)
176 goto set_enable_error;
177
178 sdata->enabled = false;
179 }
180
181set_enable_error:
182 return err;
183}
184EXPORT_SYMBOL(st_sensors_set_enable);
185
186int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
187{
188 struct st_sensor_data *sdata = iio_priv(indio_dev);
189
190 return st_sensors_write_data_with_mask(indio_dev,
191 sdata->sensor->enable_axis.addr,
192 sdata->sensor->enable_axis.mask, axis_enable);
193}
194EXPORT_SYMBOL(st_sensors_set_axis_enable);
195
196int st_sensors_init_sensor(struct iio_dev *indio_dev)
197{
198 int err;
199 struct st_sensor_data *sdata = iio_priv(indio_dev);
200
201 mutex_init(&sdata->tb.buf_lock);
202
203 err = st_sensors_set_enable(indio_dev, false);
204 if (err < 0)
205 goto init_error;
206
207 err = st_sensors_set_fullscale(indio_dev,
208 sdata->current_fullscale->num);
209 if (err < 0)
210 goto init_error;
211
212 err = st_sensors_set_odr(indio_dev, sdata->odr);
213 if (err < 0)
214 goto init_error;
215
216 /* set BDU */
217 err = st_sensors_write_data_with_mask(indio_dev,
218 sdata->sensor->bdu.addr, sdata->sensor->bdu.mask, true);
219 if (err < 0)
220 goto init_error;
221
222 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
223
224init_error:
225 return err;
226}
227EXPORT_SYMBOL(st_sensors_init_sensor);
228
229int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
230{
231 int err;
232 struct st_sensor_data *sdata = iio_priv(indio_dev);
233
234 /* Enable/Disable the interrupt generator 1. */
235 if (sdata->sensor->drdy_irq.ig1.en_addr > 0) {
236 err = st_sensors_write_data_with_mask(indio_dev,
237 sdata->sensor->drdy_irq.ig1.en_addr,
238 sdata->sensor->drdy_irq.ig1.en_mask, (int)enable);
239 if (err < 0)
240 goto st_accel_set_dataready_irq_error;
241 }
242
243 /* Enable/Disable the interrupt generator for data ready. */
244 err = st_sensors_write_data_with_mask(indio_dev,
245 sdata->sensor->drdy_irq.addr,
246 sdata->sensor->drdy_irq.mask, (int)enable);
247
248st_accel_set_dataready_irq_error:
249 return err;
250}
251EXPORT_SYMBOL(st_sensors_set_dataready_irq);
252
253int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale)
254{
255 int err = -EINVAL, i;
256 struct st_sensor_data *sdata = iio_priv(indio_dev);
257
258 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
259 if ((sdata->sensor->fs.fs_avl[i].gain == scale) &&
260 (sdata->sensor->fs.fs_avl[i].gain != 0)) {
261 err = 0;
262 break;
263 }
264 }
265 if (err < 0)
266 goto st_sensors_match_scale_error;
267
268 err = st_sensors_set_fullscale(indio_dev,
269 sdata->sensor->fs.fs_avl[i].num);
270
271st_sensors_match_scale_error:
272 return err;
273}
274EXPORT_SYMBOL(st_sensors_set_fullscale_by_gain);
275
276static int st_sensors_read_axis_data(struct iio_dev *indio_dev,
277 u8 ch_addr, int *data)
278{
279 int err;
280 u8 outdata[ST_SENSORS_BYTE_FOR_CHANNEL];
281 struct st_sensor_data *sdata = iio_priv(indio_dev);
282
283 err = sdata->tf->read_multiple_byte(&sdata->tb, sdata->dev,
284 ch_addr, ST_SENSORS_BYTE_FOR_CHANNEL,
285 outdata, sdata->multiread_bit);
286 if (err < 0)
287 goto read_error;
288
289 *data = (s16)get_unaligned_le16(outdata);
290
291read_error:
292 return err;
293}
294
295int st_sensors_read_info_raw(struct iio_dev *indio_dev,
296 struct iio_chan_spec const *ch, int *val)
297{
298 int err;
299 struct st_sensor_data *sdata = iio_priv(indio_dev);
300
301 mutex_lock(&indio_dev->mlock);
302 if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) {
303 err = -EBUSY;
304 goto read_error;
305 } else {
306 err = st_sensors_set_enable(indio_dev, true);
307 if (err < 0)
308 goto read_error;
309
310 msleep((sdata->sensor->bootime * 1000) / sdata->odr);
311 err = st_sensors_read_axis_data(indio_dev, ch->address, val);
312 if (err < 0)
313 goto read_error;
314
315 *val = *val >> ch->scan_type.shift;
316 }
317 mutex_unlock(&indio_dev->mlock);
318
319 return err;
320
321read_error:
322 mutex_unlock(&indio_dev->mlock);
323 return err;
324}
325EXPORT_SYMBOL(st_sensors_read_info_raw);
326
327int st_sensors_check_device_support(struct iio_dev *indio_dev,
328 int num_sensors_list, const struct st_sensors *sensors)
329{
330 u8 wai;
331 int i, n, err;
332 struct st_sensor_data *sdata = iio_priv(indio_dev);
333
334 err = sdata->tf->read_byte(&sdata->tb, sdata->dev,
335 ST_SENSORS_DEFAULT_WAI_ADDRESS, &wai);
336 if (err < 0) {
337 dev_err(&indio_dev->dev, "failed to read Who-Am-I register.\n");
338 goto read_wai_error;
339 }
340
341 for (i = 0; i < num_sensors_list; i++) {
342 if (sensors[i].wai == wai)
343 break;
344 }
345 if (i == num_sensors_list)
346 goto device_not_supported;
347
348 for (n = 0; n < ARRAY_SIZE(sensors[i].sensors_supported); n++) {
349 if (strcmp(indio_dev->name,
350 &sensors[i].sensors_supported[n][0]) == 0)
351 break;
352 }
353 if (n == ARRAY_SIZE(sensors[i].sensors_supported)) {
354 dev_err(&indio_dev->dev, "device name and WhoAmI mismatch.\n");
355 goto sensor_name_mismatch;
356 }
357
358 sdata->sensor = (struct st_sensors *)&sensors[i];
359
360 return i;
361
362device_not_supported:
363 dev_err(&indio_dev->dev, "device not supported: WhoAmI (0x%x).\n", wai);
364sensor_name_mismatch:
365 err = -ENODEV;
366read_wai_error:
367 return err;
368}
369EXPORT_SYMBOL(st_sensors_check_device_support);
370
371ssize_t st_sensors_sysfs_get_sampling_frequency(struct device *dev,
372 struct device_attribute *attr, char *buf)
373{
374 struct st_sensor_data *adata = iio_priv(dev_get_drvdata(dev));
375
376 return sprintf(buf, "%d\n", adata->odr);
377}
378EXPORT_SYMBOL(st_sensors_sysfs_get_sampling_frequency);
379
380ssize_t st_sensors_sysfs_set_sampling_frequency(struct device *dev,
381 struct device_attribute *attr, const char *buf, size_t size)
382{
383 int err;
384 unsigned int odr;
385 struct iio_dev *indio_dev = dev_get_drvdata(dev);
386
387 err = kstrtoint(buf, 10, &odr);
388 if (err < 0)
389 goto conversion_error;
390
391 mutex_lock(&indio_dev->mlock);
392 err = st_sensors_set_odr(indio_dev, odr);
393 mutex_unlock(&indio_dev->mlock);
394
395conversion_error:
396 return err < 0 ? err : size;
397}
398EXPORT_SYMBOL(st_sensors_sysfs_set_sampling_frequency);
399
400ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
401 struct device_attribute *attr, char *buf)
402{
403 int i, len = 0;
404 struct iio_dev *indio_dev = dev_get_drvdata(dev);
405 struct st_sensor_data *sdata = iio_priv(indio_dev);
406
407 mutex_lock(&indio_dev->mlock);
408 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
409 if (sdata->sensor->odr.odr_avl[i].hz == 0)
410 break;
411
412 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
413 sdata->sensor->odr.odr_avl[i].hz);
414 }
415 mutex_unlock(&indio_dev->mlock);
416 buf[len - 1] = '\n';
417
418 return len;
419}
420EXPORT_SYMBOL(st_sensors_sysfs_sampling_frequency_avail);
421
422ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
423 struct device_attribute *attr, char *buf)
424{
425 int i, len = 0;
426 struct iio_dev *indio_dev = dev_get_drvdata(dev);
427 struct st_sensor_data *sdata = iio_priv(indio_dev);
428
429 mutex_lock(&indio_dev->mlock);
430 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
431 if (sdata->sensor->fs.fs_avl[i].num == 0)
432 break;
433
434 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
435 sdata->sensor->fs.fs_avl[i].gain);
436 }
437 mutex_unlock(&indio_dev->mlock);
438 buf[len - 1] = '\n';
439
440 return len;
441}
442EXPORT_SYMBOL(st_sensors_sysfs_scale_avail);
443
444MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
445MODULE_DESCRIPTION("STMicroelectronics ST-sensors core");
446MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
new file mode 100644
index 000000000000..38af9440c103
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -0,0 +1,81 @@
1/*
2 * STMicroelectronics sensors i2c library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/iio/iio.h>
15
16#include <linux/iio/common/st_sensors_i2c.h>
17
18
19#define ST_SENSORS_I2C_MULTIREAD 0x80
20
21static unsigned int st_sensors_i2c_get_irq(struct iio_dev *indio_dev)
22{
23 struct st_sensor_data *sdata = iio_priv(indio_dev);
24
25 return to_i2c_client(sdata->dev)->irq;
26}
27
28static int st_sensors_i2c_read_byte(struct st_sensor_transfer_buffer *tb,
29 struct device *dev, u8 reg_addr, u8 *res_byte)
30{
31 int err;
32
33 err = i2c_smbus_read_byte_data(to_i2c_client(dev), reg_addr);
34 if (err < 0)
35 goto st_accel_i2c_read_byte_error;
36
37 *res_byte = err & 0xff;
38
39st_accel_i2c_read_byte_error:
40 return err < 0 ? err : 0;
41}
42
43static int st_sensors_i2c_read_multiple_byte(
44 struct st_sensor_transfer_buffer *tb, struct device *dev,
45 u8 reg_addr, int len, u8 *data, bool multiread_bit)
46{
47 if (multiread_bit)
48 reg_addr |= ST_SENSORS_I2C_MULTIREAD;
49
50 return i2c_smbus_read_i2c_block_data(to_i2c_client(dev),
51 reg_addr, len, data);
52}
53
54static int st_sensors_i2c_write_byte(struct st_sensor_transfer_buffer *tb,
55 struct device *dev, u8 reg_addr, u8 data)
56{
57 return i2c_smbus_write_byte_data(to_i2c_client(dev), reg_addr, data);
58}
59
60static const struct st_sensor_transfer_function st_sensors_tf_i2c = {
61 .read_byte = st_sensors_i2c_read_byte,
62 .write_byte = st_sensors_i2c_write_byte,
63 .read_multiple_byte = st_sensors_i2c_read_multiple_byte,
64};
65
66void st_sensors_i2c_configure(struct iio_dev *indio_dev,
67 struct i2c_client *client, struct st_sensor_data *sdata)
68{
69 i2c_set_clientdata(client, indio_dev);
70
71 indio_dev->dev.parent = &client->dev;
72 indio_dev->name = client->name;
73
74 sdata->tf = &st_sensors_tf_i2c;
75 sdata->get_irq_data_ready = st_sensors_i2c_get_irq;
76}
77EXPORT_SYMBOL(st_sensors_i2c_configure);
78
79MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
80MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
81MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c
new file mode 100644
index 000000000000..f0aa2f105222
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_spi.c
@@ -0,0 +1,128 @@
1/*
2 * STMicroelectronics sensors spi library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/iio/iio.h>
15
16#include <linux/iio/common/st_sensors_spi.h>
17
18
19#define ST_SENSORS_SPI_MULTIREAD 0xc0
20#define ST_SENSORS_SPI_READ 0x80
21
22static unsigned int st_sensors_spi_get_irq(struct iio_dev *indio_dev)
23{
24 struct st_sensor_data *sdata = iio_priv(indio_dev);
25
26 return to_spi_device(sdata->dev)->irq;
27}
28
29static int st_sensors_spi_read(struct st_sensor_transfer_buffer *tb,
30 struct device *dev, u8 reg_addr, int len, u8 *data, bool multiread_bit)
31{
32 struct spi_message msg;
33 int err;
34
35 struct spi_transfer xfers[] = {
36 {
37 .tx_buf = tb->tx_buf,
38 .bits_per_word = 8,
39 .len = 1,
40 },
41 {
42 .rx_buf = tb->rx_buf,
43 .bits_per_word = 8,
44 .len = len,
45 }
46 };
47
48 mutex_lock(&tb->buf_lock);
49 if ((multiread_bit) && (len > 1))
50 tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_MULTIREAD;
51 else
52 tb->tx_buf[0] = reg_addr | ST_SENSORS_SPI_READ;
53
54 spi_message_init(&msg);
55 spi_message_add_tail(&xfers[0], &msg);
56 spi_message_add_tail(&xfers[1], &msg);
57 err = spi_sync(to_spi_device(dev), &msg);
58 if (err)
59 goto acc_spi_read_error;
60
61 memcpy(data, tb->rx_buf, len*sizeof(u8));
62 mutex_unlock(&tb->buf_lock);
63 return len;
64
65acc_spi_read_error:
66 mutex_unlock(&tb->buf_lock);
67 return err;
68}
69
70static int st_sensors_spi_read_byte(struct st_sensor_transfer_buffer *tb,
71 struct device *dev, u8 reg_addr, u8 *res_byte)
72{
73 return st_sensors_spi_read(tb, dev, reg_addr, 1, res_byte, false);
74}
75
76static int st_sensors_spi_read_multiple_byte(
77 struct st_sensor_transfer_buffer *tb, struct device *dev,
78 u8 reg_addr, int len, u8 *data, bool multiread_bit)
79{
80 return st_sensors_spi_read(tb, dev, reg_addr, len, data, multiread_bit);
81}
82
83static int st_sensors_spi_write_byte(struct st_sensor_transfer_buffer *tb,
84 struct device *dev, u8 reg_addr, u8 data)
85{
86 struct spi_message msg;
87 int err;
88
89 struct spi_transfer xfers = {
90 .tx_buf = tb->tx_buf,
91 .bits_per_word = 8,
92 .len = 2,
93 };
94
95 mutex_lock(&tb->buf_lock);
96 tb->tx_buf[0] = reg_addr;
97 tb->tx_buf[1] = data;
98
99 spi_message_init(&msg);
100 spi_message_add_tail(&xfers, &msg);
101 err = spi_sync(to_spi_device(dev), &msg);
102 mutex_unlock(&tb->buf_lock);
103
104 return err;
105}
106
107static const struct st_sensor_transfer_function st_sensors_tf_spi = {
108 .read_byte = st_sensors_spi_read_byte,
109 .write_byte = st_sensors_spi_write_byte,
110 .read_multiple_byte = st_sensors_spi_read_multiple_byte,
111};
112
113void st_sensors_spi_configure(struct iio_dev *indio_dev,
114 struct spi_device *spi, struct st_sensor_data *sdata)
115{
116 spi_set_drvdata(spi, indio_dev);
117
118 indio_dev->dev.parent = &spi->dev;
119 indio_dev->name = spi->modalias;
120
121 sdata->tf = &st_sensors_tf_spi;
122 sdata->get_irq_data_ready = st_sensors_spi_get_irq;
123}
124EXPORT_SYMBOL(st_sensors_spi_configure);
125
126MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
127MODULE_DESCRIPTION("STMicroelectronics ST-sensors spi driver");
128MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/common/st_sensors/st_sensors_trigger.c b/drivers/iio/common/st_sensors/st_sensors_trigger.c
new file mode 100644
index 000000000000..139ed030abb0
--- /dev/null
+++ b/drivers/iio/common/st_sensors/st_sensors_trigger.c
@@ -0,0 +1,77 @@
1/*
2 * STMicroelectronics sensors trigger library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/iio/iio.h>
15#include <linux/iio/trigger.h>
16#include <linux/interrupt.h>
17
18#include <linux/iio/common/st_sensors.h>
19
20
21int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
22 const struct iio_trigger_ops *trigger_ops)
23{
24 int err;
25 struct st_sensor_data *sdata = iio_priv(indio_dev);
26
27 sdata->trig = iio_trigger_alloc("%s-trigger", indio_dev->name);
28 if (sdata->trig == NULL) {
29 err = -ENOMEM;
30 dev_err(&indio_dev->dev, "failed to allocate iio trigger.\n");
31 goto iio_trigger_alloc_error;
32 }
33
34 err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev),
35 iio_trigger_generic_data_rdy_poll,
36 NULL,
37 IRQF_TRIGGER_RISING,
38 sdata->trig->name,
39 sdata->trig);
40 if (err)
41 goto request_irq_error;
42
43 sdata->trig->private_data = indio_dev;
44 sdata->trig->ops = trigger_ops;
45 sdata->trig->dev.parent = sdata->dev;
46
47 err = iio_trigger_register(sdata->trig);
48 if (err < 0) {
49 dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
50 goto iio_trigger_register_error;
51 }
52 indio_dev->trig = sdata->trig;
53
54 return 0;
55
56iio_trigger_register_error:
57 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
58request_irq_error:
59 iio_trigger_free(sdata->trig);
60iio_trigger_alloc_error:
61 return err;
62}
63EXPORT_SYMBOL(st_sensors_allocate_trigger);
64
65void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
66{
67 struct st_sensor_data *sdata = iio_priv(indio_dev);
68
69 iio_trigger_unregister(sdata->trig);
70 free_irq(sdata->get_irq_data_ready(indio_dev), sdata->trig);
71 iio_trigger_free(sdata->trig);
72}
73EXPORT_SYMBOL(st_sensors_deallocate_trigger);
74
75MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
76MODULE_DESCRIPTION("STMicroelectronics ST-sensors trigger");
77MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/ad5360.c b/drivers/iio/dac/ad5360.c
index 54b46fd3aede..92771217f665 100644
--- a/drivers/iio/dac/ad5360.c
+++ b/drivers/iio/dac/ad5360.c
@@ -213,7 +213,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
213 unsigned int addr) 213 unsigned int addr)
214{ 214{
215 struct ad5360_state *st = iio_priv(indio_dev); 215 struct ad5360_state *st = iio_priv(indio_dev);
216 struct spi_message m;
217 int ret; 216 int ret;
218 struct spi_transfer t[] = { 217 struct spi_transfer t[] = {
219 { 218 {
@@ -226,10 +225,6 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
226 }, 225 },
227 }; 226 };
228 227
229 spi_message_init(&m);
230 spi_message_add_tail(&t[0], &m);
231 spi_message_add_tail(&t[1], &m);
232
233 mutex_lock(&indio_dev->mlock); 228 mutex_lock(&indio_dev->mlock);
234 229
235 st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) | 230 st->data[0].d32 = cpu_to_be32(AD5360_CMD(AD5360_CMD_SPECIAL_FUNCTION) |
@@ -237,7 +232,7 @@ static int ad5360_read(struct iio_dev *indio_dev, unsigned int type,
237 AD5360_READBACK_TYPE(type) | 232 AD5360_READBACK_TYPE(type) |
238 AD5360_READBACK_ADDR(addr)); 233 AD5360_READBACK_ADDR(addr));
239 234
240 ret = spi_sync(st->spi, &m); 235 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
241 if (ret >= 0) 236 if (ret >= 0)
242 ret = be32_to_cpu(st->data[1].d32) & 0xffff; 237 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
243 238
diff --git a/drivers/iio/dac/ad5421.c b/drivers/iio/dac/ad5421.c
index 43be948db83e..6b86a638dad0 100644
--- a/drivers/iio/dac/ad5421.c
+++ b/drivers/iio/dac/ad5421.c
@@ -127,7 +127,6 @@ static int ad5421_write(struct iio_dev *indio_dev, unsigned int reg,
127static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg) 127static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
128{ 128{
129 struct ad5421_state *st = iio_priv(indio_dev); 129 struct ad5421_state *st = iio_priv(indio_dev);
130 struct spi_message m;
131 int ret; 130 int ret;
132 struct spi_transfer t[] = { 131 struct spi_transfer t[] = {
133 { 132 {
@@ -140,15 +139,11 @@ static int ad5421_read(struct iio_dev *indio_dev, unsigned int reg)
140 }, 139 },
141 }; 140 };
142 141
143 spi_message_init(&m);
144 spi_message_add_tail(&t[0], &m);
145 spi_message_add_tail(&t[1], &m);
146
147 mutex_lock(&indio_dev->mlock); 142 mutex_lock(&indio_dev->mlock);
148 143
149 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); 144 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
150 145
151 ret = spi_sync(st->spi, &m); 146 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
152 if (ret >= 0) 147 if (ret >= 0)
153 ret = be32_to_cpu(st->data[1].d32) & 0xffff; 148 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
154 149
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 0661829f2773..e5e59749f109 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -85,11 +85,7 @@ static int ad5504_spi_read(struct spi_device *spi, u8 addr)
85 .rx_buf = &val, 85 .rx_buf = &val,
86 .len = 2, 86 .len = 2,
87 }; 87 };
88 struct spi_message m; 88 ret = spi_sync_transfer(spi, &t, 1);
89
90 spi_message_init(&m);
91 spi_message_add_tail(&t, &m);
92 ret = spi_sync(spi, &m);
93 89
94 if (ret < 0) 90 if (ret < 0)
95 return ret; 91 return ret;
diff --git a/drivers/iio/dac/ad5686.c b/drivers/iio/dac/ad5686.c
index ca9609d7a15c..5e554af21703 100644
--- a/drivers/iio/dac/ad5686.c
+++ b/drivers/iio/dac/ad5686.c
@@ -117,18 +117,13 @@ static int ad5686_spi_read(struct ad5686_state *st, u8 addr)
117 .len = 3, 117 .len = 3,
118 }, 118 },
119 }; 119 };
120 struct spi_message m;
121 int ret; 120 int ret;
122 121
123 spi_message_init(&m);
124 spi_message_add_tail(&t[0], &m);
125 spi_message_add_tail(&t[1], &m);
126
127 st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) | 122 st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_READBACK_ENABLE) |
128 AD5686_ADDR(addr)); 123 AD5686_ADDR(addr));
129 st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP)); 124 st->data[1].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP));
130 125
131 ret = spi_sync(st->spi, &m); 126 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
132 if (ret < 0) 127 if (ret < 0)
133 return ret; 128 return ret;
134 129
diff --git a/drivers/iio/dac/ad5755.c b/drivers/iio/dac/ad5755.c
index 0869bbd27d30..71faabc6b14e 100644
--- a/drivers/iio/dac/ad5755.c
+++ b/drivers/iio/dac/ad5755.c
@@ -153,7 +153,6 @@ static int ad5755_write_ctrl(struct iio_dev *indio_dev, unsigned int channel,
153static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr) 153static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
154{ 154{
155 struct ad5755_state *st = iio_priv(indio_dev); 155 struct ad5755_state *st = iio_priv(indio_dev);
156 struct spi_message m;
157 int ret; 156 int ret;
158 struct spi_transfer t[] = { 157 struct spi_transfer t[] = {
159 { 158 {
@@ -167,16 +166,12 @@ static int ad5755_read(struct iio_dev *indio_dev, unsigned int addr)
167 }, 166 },
168 }; 167 };
169 168
170 spi_message_init(&m);
171 spi_message_add_tail(&t[0], &m);
172 spi_message_add_tail(&t[1], &m);
173
174 mutex_lock(&indio_dev->mlock); 169 mutex_lock(&indio_dev->mlock);
175 170
176 st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16)); 171 st->data[0].d32 = cpu_to_be32(AD5755_READ_FLAG | (addr << 16));
177 st->data[1].d32 = cpu_to_be32(AD5755_NOOP); 172 st->data[1].d32 = cpu_to_be32(AD5755_NOOP);
178 173
179 ret = spi_sync(st->spi, &m); 174 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
180 if (ret >= 0) 175 if (ret >= 0)
181 ret = be32_to_cpu(st->data[1].d32) & 0xffff; 176 ret = be32_to_cpu(st->data[1].d32) & 0xffff;
182 177
diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c
index 7f9045e6daa4..5b7acd3a2c77 100644
--- a/drivers/iio/dac/ad5764.c
+++ b/drivers/iio/dac/ad5764.c
@@ -135,7 +135,6 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
135 unsigned int *val) 135 unsigned int *val)
136{ 136{
137 struct ad5764_state *st = iio_priv(indio_dev); 137 struct ad5764_state *st = iio_priv(indio_dev);
138 struct spi_message m;
139 int ret; 138 int ret;
140 struct spi_transfer t[] = { 139 struct spi_transfer t[] = {
141 { 140 {
@@ -148,15 +147,11 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg,
148 }, 147 },
149 }; 148 };
150 149
151 spi_message_init(&m);
152 spi_message_add_tail(&t[0], &m);
153 spi_message_add_tail(&t[1], &m);
154
155 mutex_lock(&indio_dev->mlock); 150 mutex_lock(&indio_dev->mlock);
156 151
157 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16)); 152 st->data[0].d32 = cpu_to_be32((1 << 23) | (reg << 16));
158 153
159 ret = spi_sync(st->spi, &m); 154 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
160 if (ret >= 0) 155 if (ret >= 0)
161 *val = be32_to_cpu(st->data[1].d32) & 0xffff; 156 *val = be32_to_cpu(st->data[1].d32) & 0xffff;
162 157
diff --git a/drivers/iio/dac/ad5791.c b/drivers/iio/dac/ad5791.c
index 6407b5407ddd..8dfd3da8a07b 100644
--- a/drivers/iio/dac/ad5791.c
+++ b/drivers/iio/dac/ad5791.c
@@ -125,7 +125,6 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
125 u8 d8[4]; 125 u8 d8[4];
126 } data[3]; 126 } data[3];
127 int ret; 127 int ret;
128 struct spi_message msg;
129 struct spi_transfer xfers[] = { 128 struct spi_transfer xfers[] = {
130 { 129 {
131 .tx_buf = &data[0].d8[1], 130 .tx_buf = &data[0].d8[1],
@@ -144,10 +143,7 @@ static int ad5791_spi_read(struct spi_device *spi, u8 addr, u32 *val)
144 AD5791_ADDR(addr)); 143 AD5791_ADDR(addr));
145 data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP)); 144 data[1].d32 = cpu_to_be32(AD5791_ADDR(AD5791_ADDR_NOOP));
146 145
147 spi_message_init(&msg); 146 ret = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
148 spi_message_add_tail(&xfers[0], &msg);
149 spi_message_add_tail(&xfers[1], &msg);
150 ret = spi_sync(spi, &msg);
151 147
152 *val = be32_to_cpu(data[2].d32); 148 *val = be32_to_cpu(data[2].d32);
153 149
diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index 80307473e3a9..1ea132e239ea 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -287,7 +287,6 @@ struct ad9523_state {
287static int ad9523_read(struct iio_dev *indio_dev, unsigned addr) 287static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
288{ 288{
289 struct ad9523_state *st = iio_priv(indio_dev); 289 struct ad9523_state *st = iio_priv(indio_dev);
290 struct spi_message m;
291 int ret; 290 int ret;
292 291
293 /* We encode the register size 1..3 bytes into the register address. 292 /* We encode the register size 1..3 bytes into the register address.
@@ -305,15 +304,11 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
305 }, 304 },
306 }; 305 };
307 306
308 spi_message_init(&m);
309 spi_message_add_tail(&t[0], &m);
310 spi_message_add_tail(&t[1], &m);
311
312 st->data[0].d32 = cpu_to_be32(AD9523_READ | 307 st->data[0].d32 = cpu_to_be32(AD9523_READ |
313 AD9523_CNT(AD9523_TRANSF_LEN(addr)) | 308 AD9523_CNT(AD9523_TRANSF_LEN(addr)) |
314 AD9523_ADDR(addr)); 309 AD9523_ADDR(addr));
315 310
316 ret = spi_sync(st->spi, &m); 311 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
317 if (ret < 0) 312 if (ret < 0)
318 dev_err(&indio_dev->dev, "read failed (%d)", ret); 313 dev_err(&indio_dev->dev, "read failed (%d)", ret);
319 else 314 else
@@ -326,7 +321,6 @@ static int ad9523_read(struct iio_dev *indio_dev, unsigned addr)
326static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val) 321static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val)
327{ 322{
328 struct ad9523_state *st = iio_priv(indio_dev); 323 struct ad9523_state *st = iio_priv(indio_dev);
329 struct spi_message m;
330 int ret; 324 int ret;
331 struct spi_transfer t[] = { 325 struct spi_transfer t[] = {
332 { 326 {
@@ -338,16 +332,12 @@ static int ad9523_write(struct iio_dev *indio_dev, unsigned addr, unsigned val)
338 }, 332 },
339 }; 333 };
340 334
341 spi_message_init(&m);
342 spi_message_add_tail(&t[0], &m);
343 spi_message_add_tail(&t[1], &m);
344
345 st->data[0].d32 = cpu_to_be32(AD9523_WRITE | 335 st->data[0].d32 = cpu_to_be32(AD9523_WRITE |
346 AD9523_CNT(AD9523_TRANSF_LEN(addr)) | 336 AD9523_CNT(AD9523_TRANSF_LEN(addr)) |
347 AD9523_ADDR(addr)); 337 AD9523_ADDR(addr));
348 st->data[1].d32 = cpu_to_be32(val); 338 st->data[1].d32 = cpu_to_be32(val);
349 339
350 ret = spi_sync(st->spi, &m); 340 ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
351 341
352 if (ret < 0) 342 if (ret < 0)
353 dev_err(&indio_dev->dev, "write failed (%d)", ret); 343 dev_err(&indio_dev->dev, "write failed (%d)", ret);
diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 96b68f63a902..6be4628faffe 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -3,6 +3,13 @@
3# 3#
4menu "Digital gyroscope sensors" 4menu "Digital gyroscope sensors"
5 5
6config ADIS16080
7 tristate "Analog Devices ADIS16080/100 Yaw Rate Gyroscope with SPI driver"
8 depends on SPI
9 help
10 Say yes here to build support for Analog Devices ADIS16080, ADIS16100 Yaw
11 Rate Gyroscope with SPI.
12
6config ADIS16136 13config ADIS16136
7 tristate "Analog devices ADIS16136 and similar gyroscopes driver" 14 tristate "Analog devices ADIS16136 and similar gyroscopes driver"
8 depends on SPI_MASTER 15 depends on SPI_MASTER
@@ -12,6 +19,16 @@ config ADIS16136
12 Say yes here to build support for the Analog Devices ADIS16133, ADIS16135, 19 Say yes here to build support for the Analog Devices ADIS16133, ADIS16135,
13 ADIS16136 gyroscope devices. 20 ADIS16136 gyroscope devices.
14 21
22config ADXRS450
23 tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver"
24 depends on SPI
25 help
26 Say yes here to build support for Analog Devices ADXRS450 and ADXRS453
27 programmable digital output gyroscope.
28
29 This driver can also be built as a module. If so, the module
30 will be called adxrs450.
31
15config HID_SENSOR_GYRO_3D 32config HID_SENSOR_GYRO_3D
16 depends on HID_SENSOR_HUB 33 depends on HID_SENSOR_HUB
17 select IIO_BUFFER 34 select IIO_BUFFER
@@ -23,4 +40,42 @@ config HID_SENSOR_GYRO_3D
23 Say yes here to build support for the HID SENSOR 40 Say yes here to build support for the HID SENSOR
24 Gyroscope 3D. 41 Gyroscope 3D.
25 42
43config IIO_ST_GYRO_3AXIS
44 tristate "STMicroelectronics gyroscopes 3-Axis Driver"
45 depends on (I2C || SPI_MASTER) && SYSFS
46 select IIO_ST_SENSORS_CORE
47 select IIO_ST_GYRO_I2C_3AXIS if (I2C)
48 select IIO_ST_GYRO_SPI_3AXIS if (SPI_MASTER)
49 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
50 select IIO_ST_GYRO_BUFFER if (IIO_TRIGGERED_BUFFER)
51 help
52 Say yes here to build support for STMicroelectronics gyroscopes:
53 L3G4200D, LSM330DL, L3GD20, L3GD20H, LSM330DLC, L3G4IS, LSM330.
54
55 This driver can also be built as a module. If so, will be created
56 these modules:
57 - st_gyro (core functions for the driver [it is mandatory]);
58 - st_gyro_i2c (necessary for the I2C devices [optional*]);
59 - st_gyro_spi (necessary for the SPI devices [optional*]);
60
61 (*) one of these is necessary to do something.
62
63config IIO_ST_GYRO_I2C_3AXIS
64 tristate
65 depends on IIO_ST_GYRO_3AXIS
66 depends on IIO_ST_SENSORS_I2C
67
68config IIO_ST_GYRO_SPI_3AXIS
69 tristate
70 depends on IIO_ST_GYRO_3AXIS
71 depends on IIO_ST_SENSORS_SPI
72
73config ITG3200
74 tristate "InvenSense ITG3200 Digital 3-Axis Gyroscope I2C driver"
75 depends on I2C
76 select IIO_TRIGGERED_BUFFER if IIO_BUFFER
77 help
78 Say yes here to add support for the InvenSense ITG3200 digital
79 3-axis gyroscope sensor.
80
26endmenu 81endmenu
diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
index 702a058907e3..225d289082e6 100644
--- a/drivers/iio/gyro/Makefile
+++ b/drivers/iio/gyro/Makefile
@@ -2,5 +2,19 @@
2# Makefile for industrial I/O gyroscope sensor drivers 2# Makefile for industrial I/O gyroscope sensor drivers
3# 3#
4 4
5obj-$(CONFIG_ADIS16080) += adis16080.o
5obj-$(CONFIG_ADIS16136) += adis16136.o 6obj-$(CONFIG_ADIS16136) += adis16136.o
7obj-$(CONFIG_ADXRS450) += adxrs450.o
8
6obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o 9obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
10
11itg3200-y := itg3200_core.o
12itg3200-$(CONFIG_IIO_BUFFER) += itg3200_buffer.o
13obj-$(CONFIG_ITG3200) += itg3200.o
14
15obj-$(CONFIG_IIO_ST_GYRO_3AXIS) += st_gyro.o
16st_gyro-y := st_gyro_core.o
17st_gyro-$(CONFIG_IIO_BUFFER) += st_gyro_buffer.o
18
19obj-$(CONFIG_IIO_ST_GYRO_I2C_3AXIS) += st_gyro_i2c.o
20obj-$(CONFIG_IIO_ST_GYRO_SPI_3AXIS) += st_gyro_spi.o
diff --git a/drivers/staging/iio/gyro/adis16080_core.c b/drivers/iio/gyro/adis16080.c
index 41d7350d030f..1861287911f1 100644
--- a/drivers/staging/iio/gyro/adis16080_core.c
+++ b/drivers/iio/gyro/adis16080.c
@@ -29,48 +29,50 @@
29 29
30#define ADIS16080_DIN_WRITE (1 << 15) 30#define ADIS16080_DIN_WRITE (1 << 15)
31 31
32struct adis16080_chip_info {
33 int scale_val;
34 int scale_val2;
35};
36
32/** 37/**
33 * struct adis16080_state - device instance specific data 38 * struct adis16080_state - device instance specific data
34 * @us: actual spi_device to write data 39 * @us: actual spi_device to write data
40 * @info: chip specific parameters
35 * @buf: transmit or receive buffer 41 * @buf: transmit or receive buffer
36 * @buf_lock: mutex to protect tx and rx
37 **/ 42 **/
38struct adis16080_state { 43struct adis16080_state {
39 struct spi_device *us; 44 struct spi_device *us;
40 struct mutex buf_lock; 45 const struct adis16080_chip_info *info;
41 46
42 u8 buf[2] ____cacheline_aligned; 47 __be16 buf ____cacheline_aligned;
43}; 48};
44 49
45static int adis16080_spi_write(struct iio_dev *indio_dev, 50static int adis16080_read_sample(struct iio_dev *indio_dev,
46 u16 val) 51 u16 addr, int *val)
47{ 52{
48 int ret;
49 struct adis16080_state *st = iio_priv(indio_dev); 53 struct adis16080_state *st = iio_priv(indio_dev);
50 54 struct spi_message m;
51 mutex_lock(&st->buf_lock);
52 st->buf[0] = val >> 8;
53 st->buf[1] = val;
54
55 ret = spi_write(st->us, st->buf, 2);
56 mutex_unlock(&st->buf_lock);
57
58 return ret;
59}
60
61static int adis16080_spi_read(struct iio_dev *indio_dev,
62 u16 *val)
63{
64 int ret; 55 int ret;
65 struct adis16080_state *st = iio_priv(indio_dev); 56 struct spi_transfer t[] = {
57 {
58 .tx_buf = &st->buf,
59 .len = 2,
60 .cs_change = 1,
61 }, {
62 .rx_buf = &st->buf,
63 .len = 2,
64 },
65 };
66 66
67 mutex_lock(&st->buf_lock); 67 st->buf = cpu_to_be16(addr | ADIS16080_DIN_WRITE);
68 68
69 ret = spi_read(st->us, st->buf, 2); 69 spi_message_init(&m);
70 spi_message_add_tail(&t[0], &m);
71 spi_message_add_tail(&t[1], &m);
70 72
73 ret = spi_sync(st->us, &m);
71 if (ret == 0) 74 if (ret == 0)
72 *val = sign_extend32(((st->buf[0] & 0xF) << 8) | st->buf[1], 11); 75 *val = sign_extend32(be16_to_cpu(st->buf), 11);
73 mutex_unlock(&st->buf_lock);
74 76
75 return ret; 77 return ret;
76} 78}
@@ -81,28 +83,52 @@ static int adis16080_read_raw(struct iio_dev *indio_dev,
81 int *val2, 83 int *val2,
82 long mask) 84 long mask)
83{ 85{
84 int ret = -EINVAL; 86 struct adis16080_state *st = iio_priv(indio_dev);
85 u16 ut = 0; 87 int ret;
86 /* Take the iio_dev status lock */
87 88
88 mutex_lock(&indio_dev->mlock);
89 switch (mask) { 89 switch (mask) {
90 case IIO_CHAN_INFO_RAW: 90 case IIO_CHAN_INFO_RAW:
91 ret = adis16080_spi_write(indio_dev, 91 mutex_lock(&indio_dev->mlock);
92 chan->address | 92 ret = adis16080_read_sample(indio_dev, chan->address, val);
93 ADIS16080_DIN_WRITE); 93 mutex_unlock(&indio_dev->mlock);
94 if (ret < 0) 94 return ret ? ret : IIO_VAL_INT;
95 break; 95 case IIO_CHAN_INFO_SCALE:
96 ret = adis16080_spi_read(indio_dev, &ut); 96 switch (chan->type) {
97 if (ret < 0) 97 case IIO_ANGL_VEL:
98 break; 98 *val = st->info->scale_val;
99 *val = ut; 99 *val2 = st->info->scale_val2;
100 ret = IIO_VAL_INT; 100 return IIO_VAL_FRACTIONAL;
101 case IIO_VOLTAGE:
102 /* VREF = 5V, 12 bits */
103 *val = 5000;
104 *val2 = 12;
105 return IIO_VAL_FRACTIONAL_LOG2;
106 case IIO_TEMP:
107 /* 85 C = 585, 25 C = 0 */
108 *val = 85000 - 25000;
109 *val2 = 585;
110 return IIO_VAL_FRACTIONAL;
111 default:
112 return -EINVAL;
113 }
114 case IIO_CHAN_INFO_OFFSET:
115 switch (chan->type) {
116 case IIO_VOLTAGE:
117 /* 2.5 V = 0 */
118 *val = 2048;
119 return IIO_VAL_INT;
120 case IIO_TEMP:
121 /* 85 C = 585, 25 C = 0 */
122 *val = DIV_ROUND_CLOSEST(25 * 585, 85 - 25);
123 return IIO_VAL_INT;
124 default:
125 return -EINVAL;
126 }
127 default:
101 break; 128 break;
102 } 129 }
103 mutex_unlock(&indio_dev->mlock);
104 130
105 return ret; 131 return -EINVAL;
106} 132}
107 133
108static const struct iio_chan_spec adis16080_channels[] = { 134static const struct iio_chan_spec adis16080_channels[] = {
@@ -110,25 +136,32 @@ static const struct iio_chan_spec adis16080_channels[] = {
110 .type = IIO_ANGL_VEL, 136 .type = IIO_ANGL_VEL,
111 .modified = 1, 137 .modified = 1,
112 .channel2 = IIO_MOD_Z, 138 .channel2 = IIO_MOD_Z,
113 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, 139 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
140 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
114 .address = ADIS16080_DIN_GYRO, 141 .address = ADIS16080_DIN_GYRO,
115 }, { 142 }, {
116 .type = IIO_VOLTAGE, 143 .type = IIO_VOLTAGE,
117 .indexed = 1, 144 .indexed = 1,
118 .channel = 0, 145 .channel = 0,
119 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, 146 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
147 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
148 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
120 .address = ADIS16080_DIN_AIN1, 149 .address = ADIS16080_DIN_AIN1,
121 }, { 150 }, {
122 .type = IIO_VOLTAGE, 151 .type = IIO_VOLTAGE,
123 .indexed = 1, 152 .indexed = 1,
124 .channel = 1, 153 .channel = 1,
125 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, 154 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
155 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
156 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
126 .address = ADIS16080_DIN_AIN2, 157 .address = ADIS16080_DIN_AIN2,
127 }, { 158 }, {
128 .type = IIO_TEMP, 159 .type = IIO_TEMP,
129 .indexed = 1, 160 .indexed = 1,
130 .channel = 0, 161 .channel = 0,
131 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT, 162 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
163 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
164 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
132 .address = ADIS16080_DIN_TEMP, 165 .address = ADIS16080_DIN_TEMP,
133 } 166 }
134}; 167};
@@ -138,8 +171,27 @@ static const struct iio_info adis16080_info = {
138 .driver_module = THIS_MODULE, 171 .driver_module = THIS_MODULE,
139}; 172};
140 173
174enum {
175 ID_ADIS16080,
176 ID_ADIS16100,
177};
178
179static const struct adis16080_chip_info adis16080_chip_info[] = {
180 [ID_ADIS16080] = {
181 /* 80 degree = 819, 819 rad = 46925 degree */
182 .scale_val = 80,
183 .scale_val2 = 46925,
184 },
185 [ID_ADIS16100] = {
186 /* 300 degree = 1230, 1230 rad = 70474 degree */
187 .scale_val = 300,
188 .scale_val2 = 70474,
189 },
190};
191
141static int adis16080_probe(struct spi_device *spi) 192static int adis16080_probe(struct spi_device *spi)
142{ 193{
194 const struct spi_device_id *id = spi_get_device_id(spi);
143 int ret; 195 int ret;
144 struct adis16080_state *st; 196 struct adis16080_state *st;
145 struct iio_dev *indio_dev; 197 struct iio_dev *indio_dev;
@@ -156,7 +208,7 @@ static int adis16080_probe(struct spi_device *spi)
156 208
157 /* Allocate the comms buffers */ 209 /* Allocate the comms buffers */
158 st->us = spi; 210 st->us = spi;
159 mutex_init(&st->buf_lock); 211 st->info = &adis16080_chip_info[id->driver_data];
160 212
161 indio_dev->name = spi->dev.driver->name; 213 indio_dev->name = spi->dev.driver->name;
162 indio_dev->channels = adis16080_channels; 214 indio_dev->channels = adis16080_channels;
@@ -176,7 +228,6 @@ error_ret:
176 return ret; 228 return ret;
177} 229}
178 230
179/* fixme, confirm ordering in this function */
180static int adis16080_remove(struct spi_device *spi) 231static int adis16080_remove(struct spi_device *spi)
181{ 232{
182 iio_device_unregister(spi_get_drvdata(spi)); 233 iio_device_unregister(spi_get_drvdata(spi));
@@ -185,6 +236,13 @@ static int adis16080_remove(struct spi_device *spi)
185 return 0; 236 return 0;
186} 237}
187 238
239static const struct spi_device_id adis16080_ids[] = {
240 { "adis16080", ID_ADIS16080 },
241 { "adis16100", ID_ADIS16100 },
242 {},
243};
244MODULE_DEVICE_TABLE(spi, adis16080_ids);
245
188static struct spi_driver adis16080_driver = { 246static struct spi_driver adis16080_driver = {
189 .driver = { 247 .driver = {
190 .name = "adis16080", 248 .name = "adis16080",
@@ -192,10 +250,10 @@ static struct spi_driver adis16080_driver = {
192 }, 250 },
193 .probe = adis16080_probe, 251 .probe = adis16080_probe,
194 .remove = adis16080_remove, 252 .remove = adis16080_remove,
253 .id_table = adis16080_ids,
195}; 254};
196module_spi_driver(adis16080_driver); 255module_spi_driver(adis16080_driver);
197 256
198MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 257MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
199MODULE_DESCRIPTION("Analog Devices ADIS16080/100 Yaw Rate Gyroscope Driver"); 258MODULE_DESCRIPTION("Analog Devices ADIS16080/100 Yaw Rate Gyroscope Driver");
200MODULE_LICENSE("GPL v2"); 259MODULE_LICENSE("GPL v2");
201MODULE_ALIAS("spi:adis16080");
diff --git a/drivers/staging/iio/gyro/adxrs450_core.c b/drivers/iio/gyro/adxrs450.c
index f0ce81da8aca..5b79953f7011 100644
--- a/drivers/staging/iio/gyro/adxrs450_core.c
+++ b/drivers/iio/gyro/adxrs450.c
@@ -21,45 +21,110 @@
21#include <linux/iio/iio.h> 21#include <linux/iio/iio.h>
22#include <linux/iio/sysfs.h> 22#include <linux/iio/sysfs.h>
23 23
24#include "adxrs450.h" 24#define ADXRS450_STARTUP_DELAY 50 /* ms */
25
26/* The MSB for the spi commands */
27#define ADXRS450_SENSOR_DATA (0x20 << 24)
28#define ADXRS450_WRITE_DATA (0x40 << 24)
29#define ADXRS450_READ_DATA (0x80 << 24)
30
31#define ADXRS450_RATE1 0x00 /* Rate Registers */
32#define ADXRS450_TEMP1 0x02 /* Temperature Registers */
33#define ADXRS450_LOCST1 0x04 /* Low CST Memory Registers */
34#define ADXRS450_HICST1 0x06 /* High CST Memory Registers */
35#define ADXRS450_QUAD1 0x08 /* Quad Memory Registers */
36#define ADXRS450_FAULT1 0x0A /* Fault Registers */
37#define ADXRS450_PID1 0x0C /* Part ID Register 1 */
38#define ADXRS450_SNH 0x0E /* Serial Number Registers, 4 bytes */
39#define ADXRS450_SNL 0x10
40#define ADXRS450_DNC1 0x12 /* Dynamic Null Correction Registers */
41/* Check bits */
42#define ADXRS450_P 0x01
43#define ADXRS450_CHK 0x02
44#define ADXRS450_CST 0x04
45#define ADXRS450_PWR 0x08
46#define ADXRS450_POR 0x10
47#define ADXRS450_NVM 0x20
48#define ADXRS450_Q 0x40
49#define ADXRS450_PLL 0x80
50#define ADXRS450_UV 0x100
51#define ADXRS450_OV 0x200
52#define ADXRS450_AMP 0x400
53#define ADXRS450_FAIL 0x800
54
55#define ADXRS450_WRERR_MASK (0x7 << 29)
56
57#define ADXRS450_MAX_RX 4
58#define ADXRS450_MAX_TX 4
59
60#define ADXRS450_GET_ST(a) ((a >> 26) & 0x3)
61
62enum {
63 ID_ADXRS450,
64 ID_ADXRS453,
65};
66
67/**
68 * struct adxrs450_state - device instance specific data
69 * @us: actual spi_device
70 * @buf_lock: mutex to protect tx and rx
71 * @tx: transmit buffer
72 * @rx: receive buffer
73 **/
74struct adxrs450_state {
75 struct spi_device *us;
76 struct mutex buf_lock;
77 __be32 tx ____cacheline_aligned;
78 __be32 rx;
79
80};
25 81
26/** 82/**
27 * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair 83 * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair
28 * @dev: device associated with child of actual iio_dev 84 * @indio_dev: device associated with child of actual iio_dev
29 * @reg_address: the address of the lower of the two registers,which should be an even address, 85 * @reg_address: the address of the lower of the two registers, which should be
30 * Second register's address is reg_address + 1. 86 * an even address, the second register's address is reg_address + 1.
31 * @val: somewhere to pass back the value read 87 * @val: somewhere to pass back the value read
32 **/ 88 **/
33static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev, 89static int adxrs450_spi_read_reg_16(struct iio_dev *indio_dev,
34 u8 reg_address, 90 u8 reg_address,
35 u16 *val) 91 u16 *val)
36{ 92{
93 struct spi_message msg;
37 struct adxrs450_state *st = iio_priv(indio_dev); 94 struct adxrs450_state *st = iio_priv(indio_dev);
95 u32 tx;
38 int ret; 96 int ret;
97 struct spi_transfer xfers[] = {
98 {
99 .tx_buf = &st->tx,
100 .bits_per_word = 8,
101 .len = sizeof(st->tx),
102 .cs_change = 1,
103 }, {
104 .rx_buf = &st->rx,
105 .bits_per_word = 8,
106 .len = sizeof(st->rx),
107 },
108 };
39 109
40 mutex_lock(&st->buf_lock); 110 mutex_lock(&st->buf_lock);
41 st->tx[0] = ADXRS450_READ_DATA | (reg_address >> 7); 111 tx = ADXRS450_READ_DATA | (reg_address << 17);
42 st->tx[1] = reg_address << 1;
43 st->tx[2] = 0;
44 st->tx[3] = 0;
45 112
46 if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1)) 113 if (!(hweight32(tx) & 1))
47 st->tx[3] |= ADXRS450_P; 114 tx |= ADXRS450_P;
48 115
49 ret = spi_write(st->us, st->tx, 4); 116 st->tx = cpu_to_be32(tx);
50 if (ret) { 117 spi_message_init(&msg);
51 dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", 118 spi_message_add_tail(&xfers[0], &msg);
52 reg_address); 119 spi_message_add_tail(&xfers[1], &msg);
53 goto error_ret; 120 ret = spi_sync(st->us, &msg);
54 }
55 ret = spi_read(st->us, st->rx, 4);
56 if (ret) { 121 if (ret) {
57 dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", 122 dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n",
58 reg_address); 123 reg_address);
59 goto error_ret; 124 goto error_ret;
60 } 125 }
61 126
62 *val = (be32_to_cpu(*(u32 *)st->rx) >> 5) & 0xFFFF; 127 *val = (be32_to_cpu(st->rx) >> 5) & 0xFFFF;
63 128
64error_ret: 129error_ret:
65 mutex_unlock(&st->buf_lock); 130 mutex_unlock(&st->buf_lock);
@@ -68,9 +133,9 @@ error_ret:
68 133
69/** 134/**
70 * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair 135 * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair
71 * @dev: device associated with child of actual actual iio_dev 136 * @indio_dev: device associated with child of actual actual iio_dev
72 * @reg_address: the address of the lower of the two registers,which should be an even address, 137 * @reg_address: the address of the lower of the two registers,which should be
73 * Second register's address is reg_address + 1. 138 * an even address, the second register's address is reg_address + 1.
74 * @val: value to be written. 139 * @val: value to be written.
75 **/ 140 **/
76static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev, 141static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,
@@ -78,55 +143,61 @@ static int adxrs450_spi_write_reg_16(struct iio_dev *indio_dev,
78 u16 val) 143 u16 val)
79{ 144{
80 struct adxrs450_state *st = iio_priv(indio_dev); 145 struct adxrs450_state *st = iio_priv(indio_dev);
146 u32 tx;
81 int ret; 147 int ret;
82 148
83 mutex_lock(&st->buf_lock); 149 mutex_lock(&st->buf_lock);
84 st->tx[0] = ADXRS450_WRITE_DATA | reg_address >> 7; 150 tx = ADXRS450_WRITE_DATA | (reg_address << 17) | (val << 1);
85 st->tx[1] = reg_address << 1 | val >> 15;
86 st->tx[2] = val >> 7;
87 st->tx[3] = val << 1;
88 151
89 if (!(hweight32(be32_to_cpu(*(u32 *)st->tx)) & 1)) 152 if (!(hweight32(tx) & 1))
90 st->tx[3] |= ADXRS450_P; 153 tx |= ADXRS450_P;
91 154
92 ret = spi_write(st->us, st->tx, 4); 155 st->tx = cpu_to_be32(tx);
156 ret = spi_write(st->us, &st->tx, sizeof(st->tx));
93 if (ret) 157 if (ret)
94 dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", 158 dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n",
95 reg_address); 159 reg_address);
96 msleep(1); /* enforce sequential transfer delay 0.1ms */ 160 usleep_range(100, 1000); /* enforce sequential transfer delay 0.1ms */
97 mutex_unlock(&st->buf_lock); 161 mutex_unlock(&st->buf_lock);
98 return ret; 162 return ret;
99} 163}
100 164
101/** 165/**
102 * adxrs450_spi_sensor_data() - read 2 bytes sensor data 166 * adxrs450_spi_sensor_data() - read 2 bytes sensor data
103 * @dev: device associated with child of actual iio_dev 167 * @indio_dev: device associated with child of actual iio_dev
104 * @val: somewhere to pass back the value read 168 * @val: somewhere to pass back the value read
105 **/ 169 **/
106static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val) 170static int adxrs450_spi_sensor_data(struct iio_dev *indio_dev, s16 *val)
107{ 171{
172 struct spi_message msg;
108 struct adxrs450_state *st = iio_priv(indio_dev); 173 struct adxrs450_state *st = iio_priv(indio_dev);
109 int ret; 174 int ret;
175 struct spi_transfer xfers[] = {
176 {
177 .tx_buf = &st->tx,
178 .bits_per_word = 8,
179 .len = sizeof(st->tx),
180 .cs_change = 1,
181 }, {
182 .rx_buf = &st->rx,
183 .bits_per_word = 8,
184 .len = sizeof(st->rx),
185 },
186 };
110 187
111 mutex_lock(&st->buf_lock); 188 mutex_lock(&st->buf_lock);
112 st->tx[0] = ADXRS450_SENSOR_DATA; 189 st->tx = cpu_to_be32(ADXRS450_SENSOR_DATA);
113 st->tx[1] = 0;
114 st->tx[2] = 0;
115 st->tx[3] = 0;
116
117 ret = spi_write(st->us, st->tx, 4);
118 if (ret) {
119 dev_err(&st->us->dev, "Problem while reading sensor data\n");
120 goto error_ret;
121 }
122 190
123 ret = spi_read(st->us, st->rx, 4); 191 spi_message_init(&msg);
192 spi_message_add_tail(&xfers[0], &msg);
193 spi_message_add_tail(&xfers[1], &msg);
194 ret = spi_sync(st->us, &msg);
124 if (ret) { 195 if (ret) {
125 dev_err(&st->us->dev, "Problem while reading sensor data\n"); 196 dev_err(&st->us->dev, "Problem while reading sensor data\n");
126 goto error_ret; 197 goto error_ret;
127 } 198 }
128 199
129 *val = (be32_to_cpu(*(u32 *)st->rx) >> 10) & 0xFFFF; 200 *val = (be32_to_cpu(st->rx) >> 10) & 0xFFFF;
130 201
131error_ret: 202error_ret:
132 mutex_unlock(&st->buf_lock); 203 mutex_unlock(&st->buf_lock);
@@ -137,35 +208,32 @@ error_ret:
137 * adxrs450_spi_initial() - use for initializing procedure. 208 * adxrs450_spi_initial() - use for initializing procedure.
138 * @st: device instance specific data 209 * @st: device instance specific data
139 * @val: somewhere to pass back the value read 210 * @val: somewhere to pass back the value read
211 * @chk: Whether to perform fault check
140 **/ 212 **/
141static int adxrs450_spi_initial(struct adxrs450_state *st, 213static int adxrs450_spi_initial(struct adxrs450_state *st,
142 u32 *val, char chk) 214 u32 *val, char chk)
143{ 215{
144 struct spi_message msg;
145 int ret; 216 int ret;
217 u32 tx;
146 struct spi_transfer xfers = { 218 struct spi_transfer xfers = {
147 .tx_buf = st->tx, 219 .tx_buf = &st->tx,
148 .rx_buf = st->rx, 220 .rx_buf = &st->rx,
149 .bits_per_word = 8, 221 .bits_per_word = 8,
150 .len = 4, 222 .len = sizeof(st->tx),
151 }; 223 };
152 224
153 mutex_lock(&st->buf_lock); 225 mutex_lock(&st->buf_lock);
154 st->tx[0] = ADXRS450_SENSOR_DATA; 226 tx = ADXRS450_SENSOR_DATA;
155 st->tx[1] = 0;
156 st->tx[2] = 0;
157 st->tx[3] = 0;
158 if (chk) 227 if (chk)
159 st->tx[3] |= (ADXRS450_CHK | ADXRS450_P); 228 tx |= (ADXRS450_CHK | ADXRS450_P);
160 spi_message_init(&msg); 229 st->tx = cpu_to_be32(tx);
161 spi_message_add_tail(&xfers, &msg); 230 ret = spi_sync_transfer(st->us, &xfers, 1);
162 ret = spi_sync(st->us, &msg);
163 if (ret) { 231 if (ret) {
164 dev_err(&st->us->dev, "Problem while reading initializing data\n"); 232 dev_err(&st->us->dev, "Problem while reading initializing data\n");
165 goto error_ret; 233 goto error_ret;
166 } 234 }
167 235
168 *val = be32_to_cpu(*(u32 *)st->rx); 236 *val = be32_to_cpu(st->rx);
169 237
170error_ret: 238error_ret:
171 mutex_unlock(&st->buf_lock); 239 mutex_unlock(&st->buf_lock);
@@ -185,8 +253,7 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev)
185 if (ret) 253 if (ret)
186 return ret; 254 return ret;
187 if (t != 0x01) 255 if (t != 0x01)
188 dev_warn(&st->us->dev, "The initial power on response " 256 dev_warn(&st->us->dev, "The initial power on response is not correct! Restart without reset?\n");
189 "is not correct! Restart without reset?\n");
190 257
191 msleep(ADXRS450_STARTUP_DELAY); 258 msleep(ADXRS450_STARTUP_DELAY);
192 ret = adxrs450_spi_initial(st, &t, 0); 259 ret = adxrs450_spi_initial(st, &t, 0);
@@ -217,20 +284,6 @@ static int adxrs450_initial_setup(struct iio_dev *indio_dev)
217 dev_err(&st->us->dev, "The device is not in normal status!\n"); 284 dev_err(&st->us->dev, "The device is not in normal status!\n");
218 return -EINVAL; 285 return -EINVAL;
219 } 286 }
220 ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_PID1, &data);
221 if (ret)
222 return ret;
223 dev_info(&st->us->dev, "The Part ID is 0x%x\n", data);
224
225 ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_SNL, &data);
226 if (ret)
227 return ret;
228 t = data;
229 ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_SNH, &data);
230 if (ret)
231 return ret;
232 t |= data << 16;
233 dev_info(&st->us->dev, "The Serial Number is 0x%x\n", t);
234 287
235 return 0; 288 return 0;
236} 289}
@@ -244,9 +297,10 @@ static int adxrs450_write_raw(struct iio_dev *indio_dev,
244 int ret; 297 int ret;
245 switch (mask) { 298 switch (mask) {
246 case IIO_CHAN_INFO_CALIBBIAS: 299 case IIO_CHAN_INFO_CALIBBIAS:
300 if (val < -0x400 || val >= 0x400)
301 return -EINVAL;
247 ret = adxrs450_spi_write_reg_16(indio_dev, 302 ret = adxrs450_spi_write_reg_16(indio_dev,
248 ADXRS450_DNC1, 303 ADXRS450_DNC1, val);
249 val & 0x3FF);
250 break; 304 break;
251 default: 305 default:
252 ret = -EINVAL; 306 ret = -EINVAL;
@@ -312,7 +366,7 @@ static int adxrs450_read_raw(struct iio_dev *indio_dev,
312 ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_DNC1, &t); 366 ret = adxrs450_spi_read_reg_16(indio_dev, ADXRS450_DNC1, &t);
313 if (ret) 367 if (ret)
314 break; 368 break;
315 *val = t; 369 *val = sign_extend32(t, 9);
316 ret = IIO_VAL_INT; 370 ret = IIO_VAL_INT;
317 break; 371 break;
318 default: 372 default:
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 06e7cc35450c..fcfc83a9f861 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -28,7 +28,6 @@
28#include <linux/iio/buffer.h> 28#include <linux/iio/buffer.h>
29#include <linux/iio/trigger_consumer.h> 29#include <linux/iio/trigger_consumer.h>
30#include <linux/iio/triggered_buffer.h> 30#include <linux/iio/triggered_buffer.h>
31#include "../common/hid-sensors/hid-sensor-attributes.h"
32#include "../common/hid-sensors/hid-sensor-trigger.h" 31#include "../common/hid-sensors/hid-sensor-trigger.h"
33 32
34/*Format: HID-SENSOR-usage_id_in_hex*/ 33/*Format: HID-SENSOR-usage_id_in_hex*/
@@ -44,7 +43,7 @@ enum gyro_3d_channel {
44 43
45struct gyro_3d_state { 44struct gyro_3d_state {
46 struct hid_sensor_hub_callbacks callbacks; 45 struct hid_sensor_hub_callbacks callbacks;
47 struct hid_sensor_iio_common common_attributes; 46 struct hid_sensor_common common_attributes;
48 struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX]; 47 struct hid_sensor_hub_attribute_info gyro[GYRO_3D_CHANNEL_MAX];
49 u32 gyro_val[GYRO_3D_CHANNEL_MAX]; 48 u32 gyro_val[GYRO_3D_CHANNEL_MAX];
50}; 49};
diff --git a/drivers/iio/gyro/itg3200_buffer.c b/drivers/iio/gyro/itg3200_buffer.c
new file mode 100644
index 000000000000..f667d2c8c00f
--- /dev/null
+++ b/drivers/iio/gyro/itg3200_buffer.c
@@ -0,0 +1,156 @@
1/*
2 * itg3200_buffer.c -- support InvenSense ITG3200
3 * Digital 3-Axis Gyroscope driver
4 *
5 * Copyright (c) 2011 Christian Strobel <christian.strobel@iis.fraunhofer.de>
6 * Copyright (c) 2011 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
7 * Copyright (c) 2012 Thorsten Nowak <thorsten.nowak@iis.fraunhofer.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/slab.h>
15#include <linux/i2c.h>
16#include <linux/interrupt.h>
17
18#include <linux/iio/iio.h>
19#include <linux/iio/buffer.h>
20#include <linux/iio/trigger.h>
21#include <linux/iio/trigger_consumer.h>
22#include <linux/iio/triggered_buffer.h>
23#include <linux/iio/gyro/itg3200.h>
24
25
26static int itg3200_read_all_channels(struct i2c_client *i2c, __be16 *buf)
27{
28 u8 tx = 0x80 | ITG3200_REG_TEMP_OUT_H;
29 struct i2c_msg msg[2] = {
30 {
31 .addr = i2c->addr,
32 .flags = i2c->flags,
33 .len = 1,
34 .buf = &tx,
35 },
36 {
37 .addr = i2c->addr,
38 .flags = i2c->flags | I2C_M_RD,
39 .len = ITG3200_SCAN_ELEMENTS * sizeof(s16),
40 .buf = (char *)&buf,
41 },
42 };
43
44 return i2c_transfer(i2c->adapter, msg, 2);
45}
46
47static irqreturn_t itg3200_trigger_handler(int irq, void *p)
48{
49 struct iio_poll_func *pf = p;
50 struct iio_dev *indio_dev = pf->indio_dev;
51 struct itg3200 *st = iio_priv(indio_dev);
52 __be16 buf[ITG3200_SCAN_ELEMENTS + sizeof(s64)/sizeof(u16)];
53
54 int ret = itg3200_read_all_channels(st->i2c, buf);
55 if (ret < 0)
56 goto error_ret;
57
58 if (indio_dev->scan_timestamp)
59 memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
60 &pf->timestamp, sizeof(pf->timestamp));
61
62 iio_push_to_buffers(indio_dev, (u8 *)buf);
63 iio_trigger_notify_done(indio_dev->trig);
64
65error_ret:
66 return IRQ_HANDLED;
67}
68
69int itg3200_buffer_configure(struct iio_dev *indio_dev)
70{
71 return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
72 itg3200_trigger_handler, NULL);
73}
74
75void itg3200_buffer_unconfigure(struct iio_dev *indio_dev)
76{
77 iio_triggered_buffer_cleanup(indio_dev);
78}
79
80
81static int itg3200_data_rdy_trigger_set_state(struct iio_trigger *trig,
82 bool state)
83{
84 struct iio_dev *indio_dev = trig->private_data;
85 int ret;
86 u8 msc;
87
88 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_IRQ_CONFIG, &msc);
89 if (ret)
90 goto error_ret;
91
92 if (state)
93 msc |= ITG3200_IRQ_DATA_RDY_ENABLE;
94 else
95 msc &= ~ITG3200_IRQ_DATA_RDY_ENABLE;
96
97 ret = itg3200_write_reg_8(indio_dev, ITG3200_REG_IRQ_CONFIG, msc);
98 if (ret)
99 goto error_ret;
100
101error_ret:
102 return ret;
103
104}
105
106static const struct iio_trigger_ops itg3200_trigger_ops = {
107 .owner = THIS_MODULE,
108 .set_trigger_state = &itg3200_data_rdy_trigger_set_state,
109};
110
111int itg3200_probe_trigger(struct iio_dev *indio_dev)
112{
113 int ret;
114 struct itg3200 *st = iio_priv(indio_dev);
115
116 st->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
117 indio_dev->id);
118 if (!st->trig)
119 return -ENOMEM;
120
121 ret = request_irq(st->i2c->irq,
122 &iio_trigger_generic_data_rdy_poll,
123 IRQF_TRIGGER_RISING,
124 "itg3200_data_rdy",
125 st->trig);
126 if (ret)
127 goto error_free_trig;
128
129
130 st->trig->dev.parent = &st->i2c->dev;
131 st->trig->ops = &itg3200_trigger_ops;
132 st->trig->private_data = indio_dev;
133 ret = iio_trigger_register(st->trig);
134 if (ret)
135 goto error_free_irq;
136
137 /* select default trigger */
138 indio_dev->trig = st->trig;
139
140 return 0;
141
142error_free_irq:
143 free_irq(st->i2c->irq, st->trig);
144error_free_trig:
145 iio_trigger_free(st->trig);
146 return ret;
147}
148
149void itg3200_remove_trigger(struct iio_dev *indio_dev)
150{
151 struct itg3200 *st = iio_priv(indio_dev);
152
153 iio_trigger_unregister(st->trig);
154 free_irq(st->i2c->irq, st->trig);
155 iio_trigger_free(st->trig);
156}
diff --git a/drivers/iio/gyro/itg3200_core.c b/drivers/iio/gyro/itg3200_core.c
new file mode 100644
index 000000000000..df2e6aa5d73b
--- /dev/null
+++ b/drivers/iio/gyro/itg3200_core.c
@@ -0,0 +1,401 @@
1/*
2 * itg3200_core.c -- support InvenSense ITG3200
3 * Digital 3-Axis Gyroscope driver
4 *
5 * Copyright (c) 2011 Christian Strobel <christian.strobel@iis.fraunhofer.de>
6 * Copyright (c) 2011 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
7 * Copyright (c) 2012 Thorsten Nowak <thorsten.nowak@iis.fraunhofer.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * TODO:
14 * - Support digital low pass filter
15 * - Support power management
16 */
17
18#include <linux/interrupt.h>
19#include <linux/irq.h>
20#include <linux/i2c.h>
21#include <linux/gpio.h>
22#include <linux/slab.h>
23#include <linux/stat.h>
24#include <linux/module.h>
25#include <linux/delay.h>
26
27#include <linux/iio/iio.h>
28#include <linux/iio/sysfs.h>
29#include <linux/iio/events.h>
30#include <linux/iio/buffer.h>
31
32#include <linux/iio/gyro/itg3200.h>
33
34
35int itg3200_write_reg_8(struct iio_dev *indio_dev,
36 u8 reg_address, u8 val)
37{
38 struct itg3200 *st = iio_priv(indio_dev);
39
40 return i2c_smbus_write_byte_data(st->i2c, 0x80 | reg_address, val);
41}
42
43int itg3200_read_reg_8(struct iio_dev *indio_dev,
44 u8 reg_address, u8 *val)
45{
46 struct itg3200 *st = iio_priv(indio_dev);
47 int ret;
48
49 ret = i2c_smbus_read_byte_data(st->i2c, reg_address);
50 if (ret < 0)
51 return ret;
52 *val = ret;
53 return 0;
54}
55
56static int itg3200_read_reg_s16(struct iio_dev *indio_dev, u8 lower_reg_address,
57 int *val)
58{
59 struct itg3200 *st = iio_priv(indio_dev);
60 struct i2c_client *client = st->i2c;
61 int ret;
62 s16 out;
63
64 struct i2c_msg msg[2] = {
65 {
66 .addr = client->addr,
67 .flags = client->flags,
68 .len = 1,
69 .buf = (char *)&lower_reg_address,
70 },
71 {
72 .addr = client->addr,
73 .flags = client->flags | I2C_M_RD,
74 .len = 2,
75 .buf = (char *)&out,
76 },
77 };
78
79 lower_reg_address |= 0x80;
80 ret = i2c_transfer(client->adapter, msg, 2);
81 be16_to_cpus(&out);
82 *val = out;
83
84 return (ret == 2) ? 0 : ret;
85}
86
87static int itg3200_read_raw(struct iio_dev *indio_dev,
88 const struct iio_chan_spec *chan,
89 int *val, int *val2, long info)
90{
91 int ret = 0;
92 u8 reg;
93
94 switch (info) {
95 case IIO_CHAN_INFO_RAW:
96 reg = (u8)chan->address;
97 ret = itg3200_read_reg_s16(indio_dev, reg, val);
98 return IIO_VAL_INT;
99 case IIO_CHAN_INFO_SCALE:
100 *val = 0;
101 if (chan->type == IIO_TEMP)
102 *val2 = 1000000000/280;
103 else
104 *val2 = 1214142; /* (1 / 14,375) * (PI / 180) */
105 return IIO_VAL_INT_PLUS_NANO;
106 case IIO_CHAN_INFO_OFFSET:
107 /* Only the temperature channel has an offset */
108 *val = 23000;
109 return IIO_VAL_INT;
110 default:
111 return -EINVAL;
112 }
113
114 return ret;
115}
116
117static ssize_t itg3200_read_frequency(struct device *dev,
118 struct device_attribute *attr, char *buf)
119{
120 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
121 int ret, sps;
122 u8 val;
123
124 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &val);
125 if (ret)
126 return ret;
127
128 sps = (val & ITG3200_DLPF_CFG_MASK) ? 1000 : 8000;
129
130 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_SAMPLE_RATE_DIV, &val);
131 if (ret)
132 return ret;
133
134 sps /= val + 1;
135
136 return sprintf(buf, "%d\n", sps);
137}
138
139static ssize_t itg3200_write_frequency(struct device *dev,
140 struct device_attribute *attr,
141 const char *buf,
142 size_t len)
143{
144 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
145 unsigned val;
146 int ret;
147 u8 t;
148
149 ret = kstrtouint(buf, 10, &val);
150 if (ret)
151 return ret;
152
153 mutex_lock(&indio_dev->mlock);
154
155 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &t);
156 if (ret)
157 goto err_ret;
158
159 if (val == 0) {
160 ret = -EINVAL;
161 goto err_ret;
162 }
163 t = ((t & ITG3200_DLPF_CFG_MASK) ? 1000u : 8000u) / val - 1;
164
165 ret = itg3200_write_reg_8(indio_dev, ITG3200_REG_SAMPLE_RATE_DIV, t);
166
167err_ret:
168 mutex_unlock(&indio_dev->mlock);
169
170 return ret ? ret : len;
171}
172
173/*
174 * Reset device and internal registers to the power-up-default settings
175 * Use the gyro clock as reference, as suggested by the datasheet
176 */
177static int itg3200_reset(struct iio_dev *indio_dev)
178{
179 struct itg3200 *st = iio_priv(indio_dev);
180 int ret;
181
182 dev_dbg(&st->i2c->dev, "reset device");
183
184 ret = itg3200_write_reg_8(indio_dev,
185 ITG3200_REG_POWER_MANAGEMENT,
186 ITG3200_RESET);
187 if (ret) {
188 dev_err(&st->i2c->dev, "error resetting device");
189 goto error_ret;
190 }
191
192 /* Wait for PLL (1ms according to datasheet) */
193 udelay(1500);
194
195 ret = itg3200_write_reg_8(indio_dev,
196 ITG3200_REG_IRQ_CONFIG,
197 ITG3200_IRQ_ACTIVE_HIGH |
198 ITG3200_IRQ_PUSH_PULL |
199 ITG3200_IRQ_LATCH_50US_PULSE |
200 ITG3200_IRQ_LATCH_CLEAR_ANY);
201
202 if (ret)
203 dev_err(&st->i2c->dev, "error init device");
204
205error_ret:
206 return ret;
207}
208
209/* itg3200_enable_full_scale() - Disables the digital low pass filter */
210static int itg3200_enable_full_scale(struct iio_dev *indio_dev)
211{
212 u8 val;
213 int ret;
214
215 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &val);
216 if (ret)
217 goto err_ret;
218
219 val |= ITG3200_DLPF_FS_SEL_2000;
220 return itg3200_write_reg_8(indio_dev, ITG3200_REG_DLPF, val);
221
222err_ret:
223 return ret;
224}
225
226static int itg3200_initial_setup(struct iio_dev *indio_dev)
227{
228 struct itg3200 *st = iio_priv(indio_dev);
229 int ret;
230 u8 val;
231
232 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_ADDRESS, &val);
233 if (ret)
234 goto err_ret;
235
236 if (((val >> 1) & 0x3f) != 0x34) {
237 dev_err(&st->i2c->dev, "invalid reg value 0x%02x", val);
238 ret = -ENXIO;
239 goto err_ret;
240 }
241
242 ret = itg3200_reset(indio_dev);
243 if (ret)
244 goto err_ret;
245
246 ret = itg3200_enable_full_scale(indio_dev);
247err_ret:
248 return ret;
249}
250
251#define ITG3200_TEMP_INFO_MASK (IIO_CHAN_INFO_OFFSET_SHARED_BIT | \
252 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
253 IIO_CHAN_INFO_RAW_SEPARATE_BIT)
254#define ITG3200_GYRO_INFO_MASK (IIO_CHAN_INFO_SCALE_SHARED_BIT | \
255 IIO_CHAN_INFO_RAW_SEPARATE_BIT)
256
257#define ITG3200_ST \
258 { .sign = 's', .realbits = 16, .storagebits = 16, .endianness = IIO_BE }
259
260#define ITG3200_GYRO_CHAN(_mod) { \
261 .type = IIO_ANGL_VEL, \
262 .modified = 1, \
263 .channel2 = IIO_MOD_ ## _mod, \
264 .info_mask = ITG3200_GYRO_INFO_MASK, \
265 .address = ITG3200_REG_GYRO_ ## _mod ## OUT_H, \
266 .scan_index = ITG3200_SCAN_GYRO_ ## _mod, \
267 .scan_type = ITG3200_ST, \
268}
269
270static const struct iio_chan_spec itg3200_channels[] = {
271 {
272 .type = IIO_TEMP,
273 .channel2 = IIO_NO_MOD,
274 .info_mask = ITG3200_TEMP_INFO_MASK,
275 .address = ITG3200_REG_TEMP_OUT_H,
276 .scan_index = ITG3200_SCAN_TEMP,
277 .scan_type = ITG3200_ST,
278 },
279 ITG3200_GYRO_CHAN(X),
280 ITG3200_GYRO_CHAN(Y),
281 ITG3200_GYRO_CHAN(Z),
282 IIO_CHAN_SOFT_TIMESTAMP(ITG3200_SCAN_ELEMENTS),
283};
284
285/* IIO device attributes */
286static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, itg3200_read_frequency,
287 itg3200_write_frequency);
288
289static struct attribute *itg3200_attributes[] = {
290 &iio_dev_attr_sampling_frequency.dev_attr.attr,
291 NULL
292};
293
294static const struct attribute_group itg3200_attribute_group = {
295 .attrs = itg3200_attributes,
296};
297
298static const struct iio_info itg3200_info = {
299 .attrs = &itg3200_attribute_group,
300 .read_raw = &itg3200_read_raw,
301 .driver_module = THIS_MODULE,
302};
303
304static const unsigned long itg3200_available_scan_masks[] = { 0xffffffff, 0x0 };
305
306static int itg3200_probe(struct i2c_client *client,
307 const struct i2c_device_id *id)
308{
309 int ret;
310 struct itg3200 *st;
311 struct iio_dev *indio_dev;
312
313 dev_dbg(&client->dev, "probe I2C dev with IRQ %i", client->irq);
314
315 indio_dev = iio_device_alloc(sizeof(*st));
316 if (indio_dev == NULL) {
317 ret = -ENOMEM;
318 goto error_ret;
319 }
320
321 st = iio_priv(indio_dev);
322
323 i2c_set_clientdata(client, indio_dev);
324 st->i2c = client;
325
326 indio_dev->dev.parent = &client->dev;
327 indio_dev->name = client->dev.driver->name;
328 indio_dev->channels = itg3200_channels;
329 indio_dev->num_channels = ARRAY_SIZE(itg3200_channels);
330 indio_dev->available_scan_masks = itg3200_available_scan_masks;
331 indio_dev->info = &itg3200_info;
332 indio_dev->modes = INDIO_DIRECT_MODE;
333
334 ret = itg3200_buffer_configure(indio_dev);
335 if (ret)
336 goto error_free_dev;
337
338 if (client->irq) {
339 ret = itg3200_probe_trigger(indio_dev);
340 if (ret)
341 goto error_unconfigure_buffer;
342 }
343
344 ret = itg3200_initial_setup(indio_dev);
345 if (ret)
346 goto error_remove_trigger;
347
348 ret = iio_device_register(indio_dev);
349 if (ret)
350 goto error_remove_trigger;
351
352 return 0;
353
354error_remove_trigger:
355 if (client->irq)
356 itg3200_remove_trigger(indio_dev);
357error_unconfigure_buffer:
358 itg3200_buffer_unconfigure(indio_dev);
359error_free_dev:
360 iio_device_free(indio_dev);
361error_ret:
362 return ret;
363}
364
365static int itg3200_remove(struct i2c_client *client)
366{
367 struct iio_dev *indio_dev = i2c_get_clientdata(client);
368
369 iio_device_unregister(indio_dev);
370
371 if (client->irq)
372 itg3200_remove_trigger(indio_dev);
373
374 itg3200_buffer_unconfigure(indio_dev);
375
376 iio_device_free(indio_dev);
377
378 return 0;
379}
380
381static const struct i2c_device_id itg3200_id[] = {
382 { "itg3200", 0 },
383 { }
384};
385MODULE_DEVICE_TABLE(i2c, itg3200_id);
386
387static struct i2c_driver itg3200_driver = {
388 .driver = {
389 .owner = THIS_MODULE,
390 .name = "itg3200",
391 },
392 .id_table = itg3200_id,
393 .probe = itg3200_probe,
394 .remove = itg3200_remove,
395};
396
397module_i2c_driver(itg3200_driver);
398
399MODULE_AUTHOR("Christian Strobel <christian.strobel@iis.fraunhofer.de>");
400MODULE_DESCRIPTION("ITG3200 Gyroscope I2C driver");
401MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
new file mode 100644
index 000000000000..3ad9907bb154
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro.h
@@ -0,0 +1,45 @@
1/*
2 * STMicroelectronics gyroscopes driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 * v. 1.0.0
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_GYRO_H
12#define ST_GYRO_H
13
14#include <linux/types.h>
15#include <linux/iio/common/st_sensors.h>
16
17#define L3G4200D_GYRO_DEV_NAME "l3g4200d"
18#define LSM330D_GYRO_DEV_NAME "lsm330d_gyro"
19#define LSM330DL_GYRO_DEV_NAME "lsm330dl_gyro"
20#define LSM330DLC_GYRO_DEV_NAME "lsm330dlc_gyro"
21#define L3GD20_GYRO_DEV_NAME "l3gd20"
22#define L3GD20H_GYRO_DEV_NAME "l3gd20h"
23#define L3G4IS_GYRO_DEV_NAME "l3g4is_ui"
24#define LSM330_GYRO_DEV_NAME "lsm330_gyro"
25
26int st_gyro_common_probe(struct iio_dev *indio_dev);
27void st_gyro_common_remove(struct iio_dev *indio_dev);
28
29#ifdef CONFIG_IIO_BUFFER
30int st_gyro_allocate_ring(struct iio_dev *indio_dev);
31void st_gyro_deallocate_ring(struct iio_dev *indio_dev);
32int st_gyro_trig_set_state(struct iio_trigger *trig, bool state);
33#define ST_GYRO_TRIGGER_SET_STATE (&st_gyro_trig_set_state)
34#else /* CONFIG_IIO_BUFFER */
35static inline int st_gyro_allocate_ring(struct iio_dev *indio_dev)
36{
37 return 0;
38}
39static inline void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
40{
41}
42#define ST_GYRO_TRIGGER_SET_STATE NULL
43#endif /* CONFIG_IIO_BUFFER */
44
45#endif /* ST_GYRO_H */
diff --git a/drivers/iio/gyro/st_gyro_buffer.c b/drivers/iio/gyro/st_gyro_buffer.c
new file mode 100644
index 000000000000..da4d122ec7dc
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_buffer.c
@@ -0,0 +1,114 @@
1/*
2 * STMicroelectronics gyroscopes driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/stat.h>
15#include <linux/interrupt.h>
16#include <linux/i2c.h>
17#include <linux/delay.h>
18#include <linux/iio/iio.h>
19#include <linux/iio/buffer.h>
20#include <linux/iio/trigger_consumer.h>
21#include <linux/iio/triggered_buffer.h>
22
23#include <linux/iio/common/st_sensors.h>
24#include "st_gyro.h"
25
26int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
27{
28 struct iio_dev *indio_dev = trig->private_data;
29
30 return st_sensors_set_dataready_irq(indio_dev, state);
31}
32
33static int st_gyro_buffer_preenable(struct iio_dev *indio_dev)
34{
35 int err;
36
37 err = st_sensors_set_enable(indio_dev, true);
38 if (err < 0)
39 goto st_gyro_set_enable_error;
40
41 err = iio_sw_buffer_preenable(indio_dev);
42
43st_gyro_set_enable_error:
44 return err;
45}
46
47static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
48{
49 int err;
50 struct st_sensor_data *gdata = iio_priv(indio_dev);
51
52 gdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
53 if (gdata->buffer_data == NULL) {
54 err = -ENOMEM;
55 goto allocate_memory_error;
56 }
57
58 err = st_sensors_set_axis_enable(indio_dev,
59 (u8)indio_dev->active_scan_mask[0]);
60 if (err < 0)
61 goto st_gyro_buffer_postenable_error;
62
63 err = iio_triggered_buffer_postenable(indio_dev);
64 if (err < 0)
65 goto st_gyro_buffer_postenable_error;
66
67 return err;
68
69st_gyro_buffer_postenable_error:
70 kfree(gdata->buffer_data);
71allocate_memory_error:
72 return err;
73}
74
75static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
76{
77 int err;
78 struct st_sensor_data *gdata = iio_priv(indio_dev);
79
80 err = iio_triggered_buffer_predisable(indio_dev);
81 if (err < 0)
82 goto st_gyro_buffer_predisable_error;
83
84 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
85 if (err < 0)
86 goto st_gyro_buffer_predisable_error;
87
88 err = st_sensors_set_enable(indio_dev, false);
89
90st_gyro_buffer_predisable_error:
91 kfree(gdata->buffer_data);
92 return err;
93}
94
95static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
96 .preenable = &st_gyro_buffer_preenable,
97 .postenable = &st_gyro_buffer_postenable,
98 .predisable = &st_gyro_buffer_predisable,
99};
100
101int st_gyro_allocate_ring(struct iio_dev *indio_dev)
102{
103 return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
104 &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops);
105}
106
107void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
108{
109 iio_triggered_buffer_cleanup(indio_dev);
110}
111
112MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
113MODULE_DESCRIPTION("STMicroelectronics gyroscopes buffer");
114MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
new file mode 100644
index 000000000000..fa9b24219987
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -0,0 +1,368 @@
1/*
2 * STMicroelectronics gyroscopes driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/errno.h>
15#include <linux/types.h>
16#include <linux/mutex.h>
17#include <linux/interrupt.h>
18#include <linux/i2c.h>
19#include <linux/gpio.h>
20#include <linux/irq.h>
21#include <linux/delay.h>
22#include <linux/iio/iio.h>
23#include <linux/iio/sysfs.h>
24#include <linux/iio/trigger.h>
25#include <linux/iio/buffer.h>
26
27#include <linux/iio/common/st_sensors.h>
28#include "st_gyro.h"
29
30/* DEFAULT VALUE FOR SENSORS */
31#define ST_GYRO_DEFAULT_OUT_X_L_ADDR 0x28
32#define ST_GYRO_DEFAULT_OUT_Y_L_ADDR 0x2a
33#define ST_GYRO_DEFAULT_OUT_Z_L_ADDR 0x2c
34
35/* FULLSCALE */
36#define ST_GYRO_FS_AVL_250DPS 250
37#define ST_GYRO_FS_AVL_500DPS 500
38#define ST_GYRO_FS_AVL_2000DPS 2000
39
40/* CUSTOM VALUES FOR SENSOR 1 */
41#define ST_GYRO_1_WAI_EXP 0xd3
42#define ST_GYRO_1_ODR_ADDR 0x20
43#define ST_GYRO_1_ODR_MASK 0xc0
44#define ST_GYRO_1_ODR_AVL_100HZ_VAL 0x00
45#define ST_GYRO_1_ODR_AVL_200HZ_VAL 0x01
46#define ST_GYRO_1_ODR_AVL_400HZ_VAL 0x02
47#define ST_GYRO_1_ODR_AVL_800HZ_VAL 0x03
48#define ST_GYRO_1_PW_ADDR 0x20
49#define ST_GYRO_1_PW_MASK 0x08
50#define ST_GYRO_1_FS_ADDR 0x23
51#define ST_GYRO_1_FS_MASK 0x30
52#define ST_GYRO_1_FS_AVL_250_VAL 0x00
53#define ST_GYRO_1_FS_AVL_500_VAL 0x01
54#define ST_GYRO_1_FS_AVL_2000_VAL 0x02
55#define ST_GYRO_1_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750)
56#define ST_GYRO_1_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500)
57#define ST_GYRO_1_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000)
58#define ST_GYRO_1_BDU_ADDR 0x23
59#define ST_GYRO_1_BDU_MASK 0x80
60#define ST_GYRO_1_DRDY_IRQ_ADDR 0x22
61#define ST_GYRO_1_DRDY_IRQ_MASK 0x08
62#define ST_GYRO_1_MULTIREAD_BIT true
63
64/* CUSTOM VALUES FOR SENSOR 2 */
65#define ST_GYRO_2_WAI_EXP 0xd4
66#define ST_GYRO_2_ODR_ADDR 0x20
67#define ST_GYRO_2_ODR_MASK 0xc0
68#define ST_GYRO_2_ODR_AVL_95HZ_VAL 0x00
69#define ST_GYRO_2_ODR_AVL_190HZ_VAL 0x01
70#define ST_GYRO_2_ODR_AVL_380HZ_VAL 0x02
71#define ST_GYRO_2_ODR_AVL_760HZ_VAL 0x03
72#define ST_GYRO_2_PW_ADDR 0x20
73#define ST_GYRO_2_PW_MASK 0x08
74#define ST_GYRO_2_FS_ADDR 0x23
75#define ST_GYRO_2_FS_MASK 0x30
76#define ST_GYRO_2_FS_AVL_250_VAL 0x00
77#define ST_GYRO_2_FS_AVL_500_VAL 0x01
78#define ST_GYRO_2_FS_AVL_2000_VAL 0x02
79#define ST_GYRO_2_FS_AVL_250_GAIN IIO_DEGREE_TO_RAD(8750)
80#define ST_GYRO_2_FS_AVL_500_GAIN IIO_DEGREE_TO_RAD(17500)
81#define ST_GYRO_2_FS_AVL_2000_GAIN IIO_DEGREE_TO_RAD(70000)
82#define ST_GYRO_2_BDU_ADDR 0x23
83#define ST_GYRO_2_BDU_MASK 0x80
84#define ST_GYRO_2_DRDY_IRQ_ADDR 0x22
85#define ST_GYRO_2_DRDY_IRQ_MASK 0x08
86#define ST_GYRO_2_MULTIREAD_BIT true
87
88static const struct iio_chan_spec st_gyro_16bit_channels[] = {
89 ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_X,
90 IIO_MOD_X, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS,
91 ST_GYRO_DEFAULT_OUT_X_L_ADDR),
92 ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Y,
93 IIO_MOD_Y, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS,
94 ST_GYRO_DEFAULT_OUT_Y_L_ADDR),
95 ST_SENSORS_LSM_CHANNELS(IIO_ANGL_VEL, ST_SENSORS_SCAN_Z,
96 IIO_MOD_Z, IIO_LE, ST_SENSORS_DEFAULT_16_REALBITS,
97 ST_GYRO_DEFAULT_OUT_Z_L_ADDR),
98 IIO_CHAN_SOFT_TIMESTAMP(3)
99};
100
101static const struct st_sensors st_gyro_sensors[] = {
102 {
103 .wai = ST_GYRO_1_WAI_EXP,
104 .sensors_supported = {
105 [0] = L3G4200D_GYRO_DEV_NAME,
106 [1] = LSM330DL_GYRO_DEV_NAME,
107 },
108 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
109 .odr = {
110 .addr = ST_GYRO_1_ODR_ADDR,
111 .mask = ST_GYRO_1_ODR_MASK,
112 .odr_avl = {
113 { 100, ST_GYRO_1_ODR_AVL_100HZ_VAL, },
114 { 200, ST_GYRO_1_ODR_AVL_200HZ_VAL, },
115 { 400, ST_GYRO_1_ODR_AVL_400HZ_VAL, },
116 { 800, ST_GYRO_1_ODR_AVL_800HZ_VAL, },
117 },
118 },
119 .pw = {
120 .addr = ST_GYRO_1_PW_ADDR,
121 .mask = ST_GYRO_1_PW_MASK,
122 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
123 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
124 },
125 .enable_axis = {
126 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
127 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
128 },
129 .fs = {
130 .addr = ST_GYRO_1_FS_ADDR,
131 .mask = ST_GYRO_1_FS_MASK,
132 .fs_avl = {
133 [0] = {
134 .num = ST_GYRO_FS_AVL_250DPS,
135 .value = ST_GYRO_1_FS_AVL_250_VAL,
136 .gain = ST_GYRO_1_FS_AVL_250_GAIN,
137 },
138 [1] = {
139 .num = ST_GYRO_FS_AVL_500DPS,
140 .value = ST_GYRO_1_FS_AVL_500_VAL,
141 .gain = ST_GYRO_1_FS_AVL_500_GAIN,
142 },
143 [2] = {
144 .num = ST_GYRO_FS_AVL_2000DPS,
145 .value = ST_GYRO_1_FS_AVL_2000_VAL,
146 .gain = ST_GYRO_1_FS_AVL_2000_GAIN,
147 },
148 },
149 },
150 .bdu = {
151 .addr = ST_GYRO_1_BDU_ADDR,
152 .mask = ST_GYRO_1_BDU_MASK,
153 },
154 .drdy_irq = {
155 .addr = ST_GYRO_1_DRDY_IRQ_ADDR,
156 .mask = ST_GYRO_1_DRDY_IRQ_MASK,
157 },
158 .multi_read_bit = ST_GYRO_1_MULTIREAD_BIT,
159 .bootime = 2,
160 },
161 {
162 .wai = ST_GYRO_2_WAI_EXP,
163 .sensors_supported = {
164 [0] = L3GD20_GYRO_DEV_NAME,
165 [1] = L3GD20H_GYRO_DEV_NAME,
166 [2] = LSM330D_GYRO_DEV_NAME,
167 [3] = LSM330DLC_GYRO_DEV_NAME,
168 [4] = L3G4IS_GYRO_DEV_NAME,
169 [5] = LSM330_GYRO_DEV_NAME,
170 },
171 .ch = (struct iio_chan_spec *)st_gyro_16bit_channels,
172 .odr = {
173 .addr = ST_GYRO_2_ODR_ADDR,
174 .mask = ST_GYRO_2_ODR_MASK,
175 .odr_avl = {
176 { 95, ST_GYRO_2_ODR_AVL_95HZ_VAL, },
177 { 190, ST_GYRO_2_ODR_AVL_190HZ_VAL, },
178 { 380, ST_GYRO_2_ODR_AVL_380HZ_VAL, },
179 { 760, ST_GYRO_2_ODR_AVL_760HZ_VAL, },
180 },
181 },
182 .pw = {
183 .addr = ST_GYRO_2_PW_ADDR,
184 .mask = ST_GYRO_2_PW_MASK,
185 .value_on = ST_SENSORS_DEFAULT_POWER_ON_VALUE,
186 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
187 },
188 .enable_axis = {
189 .addr = ST_SENSORS_DEFAULT_AXIS_ADDR,
190 .mask = ST_SENSORS_DEFAULT_AXIS_MASK,
191 },
192 .fs = {
193 .addr = ST_GYRO_2_FS_ADDR,
194 .mask = ST_GYRO_2_FS_MASK,
195 .fs_avl = {
196 [0] = {
197 .num = ST_GYRO_FS_AVL_250DPS,
198 .value = ST_GYRO_2_FS_AVL_250_VAL,
199 .gain = ST_GYRO_2_FS_AVL_250_GAIN,
200 },
201 [1] = {
202 .num = ST_GYRO_FS_AVL_500DPS,
203 .value = ST_GYRO_2_FS_AVL_500_VAL,
204 .gain = ST_GYRO_2_FS_AVL_500_GAIN,
205 },
206 [2] = {
207 .num = ST_GYRO_FS_AVL_2000DPS,
208 .value = ST_GYRO_2_FS_AVL_2000_VAL,
209 .gain = ST_GYRO_2_FS_AVL_2000_GAIN,
210 },
211 },
212 },
213 .bdu = {
214 .addr = ST_GYRO_2_BDU_ADDR,
215 .mask = ST_GYRO_2_BDU_MASK,
216 },
217 .drdy_irq = {
218 .addr = ST_GYRO_2_DRDY_IRQ_ADDR,
219 .mask = ST_GYRO_2_DRDY_IRQ_MASK,
220 },
221 .multi_read_bit = ST_GYRO_2_MULTIREAD_BIT,
222 .bootime = 2,
223 },
224};
225
226static int st_gyro_read_raw(struct iio_dev *indio_dev,
227 struct iio_chan_spec const *ch, int *val,
228 int *val2, long mask)
229{
230 int err;
231 struct st_sensor_data *gdata = iio_priv(indio_dev);
232
233 switch (mask) {
234 case IIO_CHAN_INFO_RAW:
235 err = st_sensors_read_info_raw(indio_dev, ch, val);
236 if (err < 0)
237 goto read_error;
238
239 return IIO_VAL_INT;
240 case IIO_CHAN_INFO_SCALE:
241 *val = 0;
242 *val2 = gdata->current_fullscale->gain;
243 return IIO_VAL_INT_PLUS_MICRO;
244 default:
245 return -EINVAL;
246 }
247
248read_error:
249 return err;
250}
251
252static int st_gyro_write_raw(struct iio_dev *indio_dev,
253 struct iio_chan_spec const *chan, int val, int val2, long mask)
254{
255 int err;
256
257 switch (mask) {
258 case IIO_CHAN_INFO_SCALE:
259 err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
260 break;
261 default:
262 err = -EINVAL;
263 }
264
265 return err;
266}
267
268static ST_SENSOR_DEV_ATTR_SAMP_FREQ();
269static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
270static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_anglvel_scale_available);
271
272static struct attribute *st_gyro_attributes[] = {
273 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
274 &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr,
275 &iio_dev_attr_sampling_frequency.dev_attr.attr,
276 NULL,
277};
278
279static const struct attribute_group st_gyro_attribute_group = {
280 .attrs = st_gyro_attributes,
281};
282
283static const struct iio_info gyro_info = {
284 .driver_module = THIS_MODULE,
285 .attrs = &st_gyro_attribute_group,
286 .read_raw = &st_gyro_read_raw,
287 .write_raw = &st_gyro_write_raw,
288};
289
290#ifdef CONFIG_IIO_TRIGGER
291static const struct iio_trigger_ops st_gyro_trigger_ops = {
292 .owner = THIS_MODULE,
293 .set_trigger_state = ST_GYRO_TRIGGER_SET_STATE,
294};
295#define ST_GYRO_TRIGGER_OPS (&st_gyro_trigger_ops)
296#else
297#define ST_GYRO_TRIGGER_OPS NULL
298#endif
299
300int st_gyro_common_probe(struct iio_dev *indio_dev)
301{
302 int err;
303 struct st_sensor_data *gdata = iio_priv(indio_dev);
304
305 indio_dev->modes = INDIO_DIRECT_MODE;
306 indio_dev->info = &gyro_info;
307
308 err = st_sensors_check_device_support(indio_dev,
309 ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors);
310 if (err < 0)
311 goto st_gyro_common_probe_error;
312
313 gdata->multiread_bit = gdata->sensor->multi_read_bit;
314 indio_dev->channels = gdata->sensor->ch;
315 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
316
317 gdata->current_fullscale = (struct st_sensor_fullscale_avl *)
318 &gdata->sensor->fs.fs_avl[0];
319 gdata->odr = gdata->sensor->odr.odr_avl[0].hz;
320
321 err = st_sensors_init_sensor(indio_dev);
322 if (err < 0)
323 goto st_gyro_common_probe_error;
324
325 if (gdata->get_irq_data_ready(indio_dev) > 0) {
326 err = st_gyro_allocate_ring(indio_dev);
327 if (err < 0)
328 goto st_gyro_common_probe_error;
329
330 err = st_sensors_allocate_trigger(indio_dev,
331 ST_GYRO_TRIGGER_OPS);
332 if (err < 0)
333 goto st_gyro_probe_trigger_error;
334 }
335
336 err = iio_device_register(indio_dev);
337 if (err)
338 goto st_gyro_device_register_error;
339
340 return err;
341
342st_gyro_device_register_error:
343 if (gdata->get_irq_data_ready(indio_dev) > 0)
344 st_sensors_deallocate_trigger(indio_dev);
345st_gyro_probe_trigger_error:
346 if (gdata->get_irq_data_ready(indio_dev) > 0)
347 st_gyro_deallocate_ring(indio_dev);
348st_gyro_common_probe_error:
349 return err;
350}
351EXPORT_SYMBOL(st_gyro_common_probe);
352
353void st_gyro_common_remove(struct iio_dev *indio_dev)
354{
355 struct st_sensor_data *gdata = iio_priv(indio_dev);
356
357 iio_device_unregister(indio_dev);
358 if (gdata->get_irq_data_ready(indio_dev) > 0) {
359 st_sensors_deallocate_trigger(indio_dev);
360 st_gyro_deallocate_ring(indio_dev);
361 }
362 iio_device_free(indio_dev);
363}
364EXPORT_SYMBOL(st_gyro_common_remove);
365
366MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
367MODULE_DESCRIPTION("STMicroelectronics gyroscopes driver");
368MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
new file mode 100644
index 000000000000..8a310500573d
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -0,0 +1,84 @@
1/*
2 * STMicroelectronics gyroscopes driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/iio/iio.h>
16
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_gyro.h"
20
21static int st_gyro_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id)
23{
24 struct iio_dev *indio_dev;
25 struct st_sensor_data *gdata;
26 int err;
27
28 indio_dev = iio_device_alloc(sizeof(*gdata));
29 if (indio_dev == NULL) {
30 err = -ENOMEM;
31 goto iio_device_alloc_error;
32 }
33
34 gdata = iio_priv(indio_dev);
35 gdata->dev = &client->dev;
36
37 st_sensors_i2c_configure(indio_dev, client, gdata);
38
39 err = st_gyro_common_probe(indio_dev);
40 if (err < 0)
41 goto st_gyro_common_probe_error;
42
43 return 0;
44
45st_gyro_common_probe_error:
46 iio_device_free(indio_dev);
47iio_device_alloc_error:
48 return err;
49}
50
51static int st_gyro_i2c_remove(struct i2c_client *client)
52{
53 st_gyro_common_remove(i2c_get_clientdata(client));
54
55 return 0;
56}
57
58static const struct i2c_device_id st_gyro_id_table[] = {
59 { L3G4200D_GYRO_DEV_NAME },
60 { LSM330D_GYRO_DEV_NAME },
61 { LSM330DL_GYRO_DEV_NAME },
62 { LSM330DLC_GYRO_DEV_NAME },
63 { L3GD20_GYRO_DEV_NAME },
64 { L3GD20H_GYRO_DEV_NAME },
65 { L3G4IS_GYRO_DEV_NAME },
66 { LSM330_GYRO_DEV_NAME },
67 {},
68};
69MODULE_DEVICE_TABLE(i2c, st_gyro_id_table);
70
71static struct i2c_driver st_gyro_driver = {
72 .driver = {
73 .owner = THIS_MODULE,
74 .name = "st-gyro-i2c",
75 },
76 .probe = st_gyro_i2c_probe,
77 .remove = st_gyro_i2c_remove,
78 .id_table = st_gyro_id_table,
79};
80module_i2c_driver(st_gyro_driver);
81
82MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
83MODULE_DESCRIPTION("STMicroelectronics gyroscopes i2c driver");
84MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
new file mode 100644
index 000000000000..f3540390eb22
--- /dev/null
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -0,0 +1,83 @@
1/*
2 * STMicroelectronics gyroscopes driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/spi/spi.h>
15#include <linux/iio/iio.h>
16
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_spi.h>
19#include "st_gyro.h"
20
21static int st_gyro_spi_probe(struct spi_device *spi)
22{
23 struct iio_dev *indio_dev;
24 struct st_sensor_data *gdata;
25 int err;
26
27 indio_dev = iio_device_alloc(sizeof(*gdata));
28 if (indio_dev == NULL) {
29 err = -ENOMEM;
30 goto iio_device_alloc_error;
31 }
32
33 gdata = iio_priv(indio_dev);
34 gdata->dev = &spi->dev;
35
36 st_sensors_spi_configure(indio_dev, spi, gdata);
37
38 err = st_gyro_common_probe(indio_dev);
39 if (err < 0)
40 goto st_gyro_common_probe_error;
41
42 return 0;
43
44st_gyro_common_probe_error:
45 iio_device_free(indio_dev);
46iio_device_alloc_error:
47 return err;
48}
49
50static int st_gyro_spi_remove(struct spi_device *spi)
51{
52 st_gyro_common_remove(spi_get_drvdata(spi));
53
54 return 0;
55}
56
57static const struct spi_device_id st_gyro_id_table[] = {
58 { L3G4200D_GYRO_DEV_NAME },
59 { LSM330D_GYRO_DEV_NAME },
60 { LSM330DL_GYRO_DEV_NAME },
61 { LSM330DLC_GYRO_DEV_NAME },
62 { L3GD20_GYRO_DEV_NAME },
63 { L3GD20H_GYRO_DEV_NAME },
64 { L3G4IS_GYRO_DEV_NAME },
65 { LSM330_GYRO_DEV_NAME },
66 {},
67};
68MODULE_DEVICE_TABLE(spi, st_gyro_id_table);
69
70static struct spi_driver st_gyro_driver = {
71 .driver = {
72 .owner = THIS_MODULE,
73 .name = "st-gyro-spi",
74 },
75 .probe = st_gyro_spi_probe,
76 .remove = st_gyro_spi_remove,
77 .id_table = st_gyro_id_table,
78};
79module_spi_driver(st_gyro_driver);
80
81MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
82MODULE_DESCRIPTION("STMicroelectronics gyroscopes spi driver");
83MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig
index 3d79a40e916b..4f40a10cb74f 100644
--- a/drivers/iio/imu/Kconfig
+++ b/drivers/iio/imu/Kconfig
@@ -3,6 +3,17 @@
3# 3#
4menu "Inertial measurement units" 4menu "Inertial measurement units"
5 5
6config ADIS16400
7 tristate "Analog Devices ADIS16400 and similar IMU SPI driver"
8 depends on SPI
9 select IIO_ADIS_LIB
10 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
11 help
12 Say yes here to build support for Analog Devices adis16300, adis16344,
13 adis16350, adis16354, adis16355, adis16360, adis16362, adis16364,
14 adis16365, adis16400 and adis16405 triaxial inertial sensors
15 (adis16400 series also have magnetometers).
16
6config ADIS16480 17config ADIS16480
7 tristate "Analog Devices ADIS16480 and similar IMU driver" 18 tristate "Analog Devices ADIS16480 and similar IMU driver"
8 depends on SPI 19 depends on SPI
@@ -25,3 +36,5 @@ config IIO_ADIS_LIB_BUFFER
25 help 36 help
26 A set of buffer helper functions for the Analog Devices ADIS* device 37 A set of buffer helper functions for the Analog Devices ADIS* device
27 family. 38 family.
39
40source "drivers/iio/imu/inv_mpu6050/Kconfig"
diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile
index cfe57638f6f9..f2f56ceaed26 100644
--- a/drivers/iio/imu/Makefile
+++ b/drivers/iio/imu/Makefile
@@ -2,9 +2,14 @@
2# Makefile for Inertial Measurement Units 2# Makefile for Inertial Measurement Units
3# 3#
4 4
5adis16400-y := adis16400_core.o
6adis16400-$(CONFIG_IIO_BUFFER) += adis16400_buffer.o
7obj-$(CONFIG_ADIS16400) += adis16400.o
5obj-$(CONFIG_ADIS16480) += adis16480.o 8obj-$(CONFIG_ADIS16480) += adis16480.o
6 9
7adis_lib-y += adis.o 10adis_lib-y += adis.o
8adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o 11adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_trigger.o
9adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o 12adis_lib-$(CONFIG_IIO_ADIS_LIB_BUFFER) += adis_buffer.o
10obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o 13obj-$(CONFIG_IIO_ADIS_LIB) += adis_lib.o
14
15obj-y += inv_mpu6050/
diff --git a/drivers/staging/iio/imu/adis16400.h b/drivers/iio/imu/adis16400.h
index 7a105e966464..2f8f9d632386 100644
--- a/drivers/staging/iio/imu/adis16400.h
+++ b/drivers/iio/imu/adis16400.h
@@ -17,12 +17,11 @@
17#ifndef SPI_ADIS16400_H_ 17#ifndef SPI_ADIS16400_H_
18#define SPI_ADIS16400_H_ 18#define SPI_ADIS16400_H_
19 19
20#include <linux/iio/imu/adis.h>
21
20#define ADIS16400_STARTUP_DELAY 290 /* ms */ 22#define ADIS16400_STARTUP_DELAY 290 /* ms */
21#define ADIS16400_MTEST_DELAY 90 /* ms */ 23#define ADIS16400_MTEST_DELAY 90 /* ms */
22 24
23#define ADIS16400_READ_REG(a) a
24#define ADIS16400_WRITE_REG(a) ((a) | 0x80)
25
26#define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */ 25#define ADIS16400_FLASH_CNT 0x00 /* Flash memory write count */
27#define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */ 26#define ADIS16400_SUPPLY_OUT 0x02 /* Power supply measurement */
28#define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */ 27#define ADIS16400_XGYRO_OUT 0x04 /* X-axis gyroscope output */
@@ -45,6 +44,9 @@
45#define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */ 44#define ADIS16300_ROLL_OUT 0x14 /* Y axis inclinometer output measurement */
46#define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */ 45#define ADIS16300_AUX_ADC 0x16 /* Auxiliary ADC measurement */
47 46
47#define ADIS16448_BARO_OUT 0x16 /* Barometric pressure output */
48#define ADIS16448_TEMP_OUT 0x18 /* Temperature output */
49
48/* Calibration parameters */ 50/* Calibration parameters */
49#define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */ 51#define ADIS16400_XGYRO_OFF 0x1A /* X-axis gyroscope bias offset factor */
50#define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */ 52#define ADIS16400_YGYRO_OFF 0x1C /* Y-axis gyroscope bias offset factor */
@@ -75,7 +77,10 @@
75#define ADIS16400_ALM_CTRL 0x48 /* Alarm control */ 77#define ADIS16400_ALM_CTRL 0x48 /* Alarm control */
76#define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */ 78#define ADIS16400_AUX_DAC 0x4A /* Auxiliary DAC data */
77 79
80#define ADIS16334_LOT_ID1 0x52 /* Lot identification code 1 */
81#define ADIS16334_LOT_ID2 0x54 /* Lot identification code 2 */
78#define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */ 82#define ADIS16400_PRODUCT_ID 0x56 /* Product identifier */
83#define ADIS16334_SERIAL_NUMBER 0x58 /* Serial number, lot specific */
79 84
80#define ADIS16400_ERROR_ACTIVE (1<<14) 85#define ADIS16400_ERROR_ACTIVE (1<<14)
81#define ADIS16400_NEW_DATA (1<<14) 86#define ADIS16400_NEW_DATA (1<<14)
@@ -96,21 +101,21 @@
96#define ADIS16400_SMPL_PRD_DIV_MASK 0x7F 101#define ADIS16400_SMPL_PRD_DIV_MASK 0x7F
97 102
98/* DIAG_STAT */ 103/* DIAG_STAT */
99#define ADIS16400_DIAG_STAT_ZACCL_FAIL (1<<15) 104#define ADIS16400_DIAG_STAT_ZACCL_FAIL 15
100#define ADIS16400_DIAG_STAT_YACCL_FAIL (1<<14) 105#define ADIS16400_DIAG_STAT_YACCL_FAIL 14
101#define ADIS16400_DIAG_STAT_XACCL_FAIL (1<<13) 106#define ADIS16400_DIAG_STAT_XACCL_FAIL 13
102#define ADIS16400_DIAG_STAT_XGYRO_FAIL (1<<12) 107#define ADIS16400_DIAG_STAT_XGYRO_FAIL 12
103#define ADIS16400_DIAG_STAT_YGYRO_FAIL (1<<11) 108#define ADIS16400_DIAG_STAT_YGYRO_FAIL 11
104#define ADIS16400_DIAG_STAT_ZGYRO_FAIL (1<<10) 109#define ADIS16400_DIAG_STAT_ZGYRO_FAIL 10
105#define ADIS16400_DIAG_STAT_ALARM2 (1<<9) 110#define ADIS16400_DIAG_STAT_ALARM2 9
106#define ADIS16400_DIAG_STAT_ALARM1 (1<<8) 111#define ADIS16400_DIAG_STAT_ALARM1 8
107#define ADIS16400_DIAG_STAT_FLASH_CHK (1<<6) 112#define ADIS16400_DIAG_STAT_FLASH_CHK 6
108#define ADIS16400_DIAG_STAT_SELF_TEST (1<<5) 113#define ADIS16400_DIAG_STAT_SELF_TEST 5
109#define ADIS16400_DIAG_STAT_OVERFLOW (1<<4) 114#define ADIS16400_DIAG_STAT_OVERFLOW 4
110#define ADIS16400_DIAG_STAT_SPI_FAIL (1<<3) 115#define ADIS16400_DIAG_STAT_SPI_FAIL 3
111#define ADIS16400_DIAG_STAT_FLASH_UPT (1<<2) 116#define ADIS16400_DIAG_STAT_FLASH_UPT 2
112#define ADIS16400_DIAG_STAT_POWER_HIGH (1<<1) 117#define ADIS16400_DIAG_STAT_POWER_HIGH 1
113#define ADIS16400_DIAG_STAT_POWER_LOW (1<<0) 118#define ADIS16400_DIAG_STAT_POWER_LOW 0
114 119
115/* GLOB_CMD */ 120/* GLOB_CMD */
116#define ADIS16400_GLOB_CMD_SW_RESET (1<<7) 121#define ADIS16400_GLOB_CMD_SW_RESET (1<<7)
@@ -126,9 +131,6 @@
126#define ADIS16334_RATE_DIV_SHIFT 8 131#define ADIS16334_RATE_DIV_SHIFT 8
127#define ADIS16334_RATE_INT_CLK BIT(0) 132#define ADIS16334_RATE_INT_CLK BIT(0)
128 133
129#define ADIS16400_MAX_TX 24
130#define ADIS16400_MAX_RX 24
131
132#define ADIS16400_SPI_SLOW (u32)(300 * 1000) 134#define ADIS16400_SPI_SLOW (u32)(300 * 1000)
133#define ADIS16400_SPI_BURST (u32)(1000 * 1000) 135#define ADIS16400_SPI_BURST (u32)(1000 * 1000)
134#define ADIS16400_SPI_FAST (u32)(2000 * 1000) 136#define ADIS16400_SPI_FAST (u32)(2000 * 1000)
@@ -136,6 +138,9 @@
136#define ADIS16400_HAS_PROD_ID BIT(0) 138#define ADIS16400_HAS_PROD_ID BIT(0)
137#define ADIS16400_NO_BURST BIT(1) 139#define ADIS16400_NO_BURST BIT(1)
138#define ADIS16400_HAS_SLOW_MODE BIT(2) 140#define ADIS16400_HAS_SLOW_MODE BIT(2)
141#define ADIS16400_HAS_SERIAL_NUMBER BIT(3)
142
143struct adis16400_state;
139 144
140struct adis16400_chip_info { 145struct adis16400_chip_info {
141 const struct iio_chan_spec *channels; 146 const struct iio_chan_spec *channels;
@@ -145,95 +150,63 @@ struct adis16400_chip_info {
145 unsigned int accel_scale_micro; 150 unsigned int accel_scale_micro;
146 int temp_scale_nano; 151 int temp_scale_nano;
147 int temp_offset; 152 int temp_offset;
148 unsigned long default_scan_mask; 153 int (*set_freq)(struct adis16400_state *st, unsigned int freq);
149 int (*set_freq)(struct iio_dev *indio_dev, unsigned int freq); 154 int (*get_freq)(struct adis16400_state *st);
150 int (*get_freq)(struct iio_dev *indio_dev);
151}; 155};
152 156
153/** 157/**
154 * struct adis16400_state - device instance specific data 158 * struct adis16400_state - device instance specific data
155 * @us: actual spi_device 159 * @variant: chip variant info
156 * @trig: data ready trigger registered with iio 160 * @filt_int: integer part of requested filter frequency
157 * @tx: transmit buffer 161 * @adis: adis device
158 * @rx: receive buffer
159 * @buf_lock: mutex to protect tx and rx
160 * @filt_int: integer part of requested filter frequency
161 **/ 162 **/
162struct adis16400_state { 163struct adis16400_state {
163 struct spi_device *us;
164 struct iio_trigger *trig;
165 struct mutex buf_lock;
166 struct adis16400_chip_info *variant; 164 struct adis16400_chip_info *variant;
167 int filt_int; 165 int filt_int;
168 166
169 u8 tx[ADIS16400_MAX_TX] ____cacheline_aligned; 167 struct adis adis;
170 u8 rx[ADIS16400_MAX_RX] ____cacheline_aligned;
171}; 168};
172 169
173int adis16400_set_irq(struct iio_dev *indio_dev, bool enable);
174
175/* At the moment triggers are only used for ring buffer 170/* At the moment triggers are only used for ring buffer
176 * filling. This may change! 171 * filling. This may change!
177 */ 172 */
178 173
179#define ADIS16400_SCAN_SUPPLY 0 174enum {
180#define ADIS16400_SCAN_GYRO_X 1 175 ADIS16400_SCAN_SUPPLY,
181#define ADIS16400_SCAN_GYRO_Y 2 176 ADIS16400_SCAN_GYRO_X,
182#define ADIS16400_SCAN_GYRO_Z 3 177 ADIS16400_SCAN_GYRO_Y,
183#define ADIS16400_SCAN_ACC_X 4 178 ADIS16400_SCAN_GYRO_Z,
184#define ADIS16400_SCAN_ACC_Y 5 179 ADIS16400_SCAN_ACC_X,
185#define ADIS16400_SCAN_ACC_Z 6 180 ADIS16400_SCAN_ACC_Y,
186#define ADIS16400_SCAN_MAGN_X 7 181 ADIS16400_SCAN_ACC_Z,
187#define ADIS16350_SCAN_TEMP_X 7 182 ADIS16400_SCAN_MAGN_X,
188#define ADIS16400_SCAN_MAGN_Y 8 183 ADIS16400_SCAN_MAGN_Y,
189#define ADIS16350_SCAN_TEMP_Y 8 184 ADIS16400_SCAN_MAGN_Z,
190#define ADIS16400_SCAN_MAGN_Z 9 185 ADIS16400_SCAN_BARO,
191#define ADIS16350_SCAN_TEMP_Z 9 186 ADIS16350_SCAN_TEMP_X,
192#define ADIS16400_SCAN_TEMP 10 187 ADIS16350_SCAN_TEMP_Y,
193#define ADIS16350_SCAN_ADC_0 10 188 ADIS16350_SCAN_TEMP_Z,
194#define ADIS16400_SCAN_ADC_0 11 189 ADIS16300_SCAN_INCLI_X,
195#define ADIS16300_SCAN_INCLI_X 12 190 ADIS16300_SCAN_INCLI_Y,
196#define ADIS16300_SCAN_INCLI_Y 13 191 ADIS16400_SCAN_ADC,
192};
197 193
198#ifdef CONFIG_IIO_BUFFER 194#ifdef CONFIG_IIO_BUFFER
199void adis16400_remove_trigger(struct iio_dev *indio_dev);
200int adis16400_probe_trigger(struct iio_dev *indio_dev);
201 195
202ssize_t adis16400_read_data_from_ring(struct device *dev, 196ssize_t adis16400_read_data_from_ring(struct device *dev,
203 struct device_attribute *attr, 197 struct device_attribute *attr,
204 char *buf); 198 char *buf);
205 199
206 200
207int adis16400_configure_ring(struct iio_dev *indio_dev); 201int adis16400_update_scan_mode(struct iio_dev *indio_dev,
208void adis16400_unconfigure_ring(struct iio_dev *indio_dev); 202 const unsigned long *scan_mask);
203irqreturn_t adis16400_trigger_handler(int irq, void *p);
209 204
210#else /* CONFIG_IIO_BUFFER */ 205#else /* CONFIG_IIO_BUFFER */
211 206
212static inline void adis16400_remove_trigger(struct iio_dev *indio_dev) 207#define adis16400_update_scan_mode NULL
213{ 208#define adis16400_trigger_handler NULL
214}
215
216static inline int adis16400_probe_trigger(struct iio_dev *indio_dev)
217{
218 return 0;
219}
220
221static inline ssize_t
222adis16400_read_data_from_ring(struct device *dev,
223 struct device_attribute *attr,
224 char *buf)
225{
226 return 0;
227}
228
229static int adis16400_configure_ring(struct iio_dev *indio_dev)
230{
231 return 0;
232}
233
234static inline void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
235{
236}
237 209
238#endif /* CONFIG_IIO_BUFFER */ 210#endif /* CONFIG_IIO_BUFFER */
211
239#endif /* SPI_ADIS16400_H_ */ 212#endif /* SPI_ADIS16400_H_ */
diff --git a/drivers/iio/imu/adis16400_buffer.c b/drivers/iio/imu/adis16400_buffer.c
new file mode 100644
index 000000000000..054c01d6e73c
--- /dev/null
+++ b/drivers/iio/imu/adis16400_buffer.c
@@ -0,0 +1,96 @@
1#include <linux/interrupt.h>
2#include <linux/mutex.h>
3#include <linux/kernel.h>
4#include <linux/spi/spi.h>
5#include <linux/slab.h>
6#include <linux/bitops.h>
7#include <linux/export.h>
8
9#include <linux/iio/iio.h>
10#include <linux/iio/buffer.h>
11#include <linux/iio/triggered_buffer.h>
12#include <linux/iio/trigger_consumer.h>
13
14#include "adis16400.h"
15
16int adis16400_update_scan_mode(struct iio_dev *indio_dev,
17 const unsigned long *scan_mask)
18{
19 struct adis16400_state *st = iio_priv(indio_dev);
20 struct adis *adis = &st->adis;
21 uint16_t *tx, *rx;
22
23 if (st->variant->flags & ADIS16400_NO_BURST)
24 return adis_update_scan_mode(indio_dev, scan_mask);
25
26 kfree(adis->xfer);
27 kfree(adis->buffer);
28
29 adis->xfer = kcalloc(2, sizeof(*adis->xfer), GFP_KERNEL);
30 if (!adis->xfer)
31 return -ENOMEM;
32
33 adis->buffer = kzalloc(indio_dev->scan_bytes + sizeof(u16),
34 GFP_KERNEL);
35 if (!adis->buffer)
36 return -ENOMEM;
37
38 rx = adis->buffer;
39 tx = adis->buffer + indio_dev->scan_bytes;
40
41 tx[0] = ADIS_READ_REG(ADIS16400_GLOB_CMD);
42 tx[1] = 0;
43
44 adis->xfer[0].tx_buf = tx;
45 adis->xfer[0].bits_per_word = 8;
46 adis->xfer[0].len = 2;
47 adis->xfer[1].tx_buf = tx;
48 adis->xfer[1].bits_per_word = 8;
49 adis->xfer[1].len = indio_dev->scan_bytes;
50
51 spi_message_init(&adis->msg);
52 spi_message_add_tail(&adis->xfer[0], &adis->msg);
53 spi_message_add_tail(&adis->xfer[1], &adis->msg);
54
55 return 0;
56}
57
58irqreturn_t adis16400_trigger_handler(int irq, void *p)
59{
60 struct iio_poll_func *pf = p;
61 struct iio_dev *indio_dev = pf->indio_dev;
62 struct adis16400_state *st = iio_priv(indio_dev);
63 struct adis *adis = &st->adis;
64 u32 old_speed_hz = st->adis.spi->max_speed_hz;
65 int ret;
66
67 if (!adis->buffer)
68 return -ENOMEM;
69
70 if (!(st->variant->flags & ADIS16400_NO_BURST) &&
71 st->adis.spi->max_speed_hz > ADIS16400_SPI_BURST) {
72 st->adis.spi->max_speed_hz = ADIS16400_SPI_BURST;
73 spi_setup(st->adis.spi);
74 }
75
76 ret = spi_sync(adis->spi, &adis->msg);
77 if (ret)
78 dev_err(&adis->spi->dev, "Failed to read data: %d\n", ret);
79
80 if (!(st->variant->flags & ADIS16400_NO_BURST)) {
81 st->adis.spi->max_speed_hz = old_speed_hz;
82 spi_setup(st->adis.spi);
83 }
84
85 /* Guaranteed to be aligned with 8 byte boundary */
86 if (indio_dev->scan_timestamp) {
87 void *b = adis->buffer + indio_dev->scan_bytes - sizeof(s64);
88 *(s64 *)b = pf->timestamp;
89 }
90
91 iio_push_to_buffers(indio_dev, adis->buffer);
92
93 iio_trigger_notify_done(indio_dev->trig);
94
95 return IRQ_HANDLED;
96}
diff --git a/drivers/iio/imu/adis16400_core.c b/drivers/iio/imu/adis16400_core.c
new file mode 100644
index 000000000000..b7f215eab5de
--- /dev/null
+++ b/drivers/iio/imu/adis16400_core.c
@@ -0,0 +1,965 @@
1/*
2 * adis16400.c support Analog Devices ADIS16400/5
3 * 3d 2g Linear Accelerometers,
4 * 3d Gyroscopes,
5 * 3d Magnetometers via SPI
6 *
7 * Copyright (c) 2009 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
8 * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org>
9 * Copyright (c) 2011 Analog Devices Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 */
16
17#include <linux/interrupt.h>
18#include <linux/irq.h>
19#include <linux/delay.h>
20#include <linux/mutex.h>
21#include <linux/device.h>
22#include <linux/kernel.h>
23#include <linux/spi/spi.h>
24#include <linux/slab.h>
25#include <linux/sysfs.h>
26#include <linux/list.h>
27#include <linux/module.h>
28#include <linux/debugfs.h>
29
30#include <linux/iio/iio.h>
31#include <linux/iio/sysfs.h>
32#include <linux/iio/buffer.h>
33
34#include "adis16400.h"
35
36#ifdef CONFIG_DEBUG_FS
37
38static ssize_t adis16400_show_serial_number(struct file *file,
39 char __user *userbuf, size_t count, loff_t *ppos)
40{
41 struct adis16400_state *st = file->private_data;
42 u16 lot1, lot2, serial_number;
43 char buf[16];
44 size_t len;
45 int ret;
46
47 ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID1, &lot1);
48 if (ret < 0)
49 return ret;
50
51 ret = adis_read_reg_16(&st->adis, ADIS16334_LOT_ID2, &lot2);
52 if (ret < 0)
53 return ret;
54
55 ret = adis_read_reg_16(&st->adis, ADIS16334_SERIAL_NUMBER,
56 &serial_number);
57 if (ret < 0)
58 return ret;
59
60 len = snprintf(buf, sizeof(buf), "%.4x-%.4x-%.4x\n", lot1, lot2,
61 serial_number);
62
63 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
64}
65
66static const struct file_operations adis16400_serial_number_fops = {
67 .open = simple_open,
68 .read = adis16400_show_serial_number,
69 .llseek = default_llseek,
70 .owner = THIS_MODULE,
71};
72
73static int adis16400_show_product_id(void *arg, u64 *val)
74{
75 struct adis16400_state *st = arg;
76 uint16_t prod_id;
77 int ret;
78
79 ret = adis_read_reg_16(&st->adis, ADIS16400_PRODUCT_ID, &prod_id);
80 if (ret < 0)
81 return ret;
82
83 *val = prod_id;
84
85 return 0;
86}
87DEFINE_SIMPLE_ATTRIBUTE(adis16400_product_id_fops,
88 adis16400_show_product_id, NULL, "%lld\n");
89
90static int adis16400_show_flash_count(void *arg, u64 *val)
91{
92 struct adis16400_state *st = arg;
93 uint16_t flash_count;
94 int ret;
95
96 ret = adis_read_reg_16(&st->adis, ADIS16400_FLASH_CNT, &flash_count);
97 if (ret < 0)
98 return ret;
99
100 *val = flash_count;
101
102 return 0;
103}
104DEFINE_SIMPLE_ATTRIBUTE(adis16400_flash_count_fops,
105 adis16400_show_flash_count, NULL, "%lld\n");
106
107static int adis16400_debugfs_init(struct iio_dev *indio_dev)
108{
109 struct adis16400_state *st = iio_priv(indio_dev);
110
111 if (st->variant->flags & ADIS16400_HAS_SERIAL_NUMBER)
112 debugfs_create_file("serial_number", 0400,
113 indio_dev->debugfs_dentry, st,
114 &adis16400_serial_number_fops);
115 if (st->variant->flags & ADIS16400_HAS_PROD_ID)
116 debugfs_create_file("product_id", 0400,
117 indio_dev->debugfs_dentry, st,
118 &adis16400_product_id_fops);
119 debugfs_create_file("flash_count", 0400, indio_dev->debugfs_dentry,
120 st, &adis16400_flash_count_fops);
121
122 return 0;
123}
124
125#else
126
127static int adis16400_debugfs_init(struct iio_dev *indio_dev)
128{
129 return 0;
130}
131
132#endif
133
134enum adis16400_chip_variant {
135 ADIS16300,
136 ADIS16334,
137 ADIS16350,
138 ADIS16360,
139 ADIS16362,
140 ADIS16364,
141 ADIS16400,
142 ADIS16448,
143};
144
145static int adis16334_get_freq(struct adis16400_state *st)
146{
147 int ret;
148 uint16_t t;
149
150 ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t);
151 if (ret < 0)
152 return ret;
153
154 t >>= ADIS16334_RATE_DIV_SHIFT;
155
156 return 819200 >> t;
157}
158
159static int adis16334_set_freq(struct adis16400_state *st, unsigned int freq)
160{
161 unsigned int t;
162
163 if (freq < 819200)
164 t = ilog2(819200 / freq);
165 else
166 t = 0;
167
168 if (t > 0x31)
169 t = 0x31;
170
171 t <<= ADIS16334_RATE_DIV_SHIFT;
172 t |= ADIS16334_RATE_INT_CLK;
173
174 return adis_write_reg_16(&st->adis, ADIS16400_SMPL_PRD, t);
175}
176
177static int adis16400_get_freq(struct adis16400_state *st)
178{
179 int sps, ret;
180 uint16_t t;
181
182 ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &t);
183 if (ret < 0)
184 return ret;
185
186 sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 52851 : 1638404;
187 sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1;
188
189 return sps;
190}
191
192static int adis16400_set_freq(struct adis16400_state *st, unsigned int freq)
193{
194 unsigned int t;
195 uint8_t val = 0;
196
197 t = 1638404 / freq;
198 if (t >= 128) {
199 val |= ADIS16400_SMPL_PRD_TIME_BASE;
200 t = 52851 / freq;
201 if (t >= 128)
202 t = 127;
203 } else if (t != 0) {
204 t--;
205 }
206
207 val |= t;
208
209 if (t >= 0x0A || (val & ADIS16400_SMPL_PRD_TIME_BASE))
210 st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW;
211 else
212 st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST;
213
214 return adis_write_reg_8(&st->adis, ADIS16400_SMPL_PRD, val);
215}
216
217static ssize_t adis16400_read_frequency(struct device *dev,
218 struct device_attribute *attr,
219 char *buf)
220{
221 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
222 struct adis16400_state *st = iio_priv(indio_dev);
223 int ret;
224
225 ret = st->variant->get_freq(st);
226 if (ret < 0)
227 return ret;
228
229 return sprintf(buf, "%d.%.3d\n", ret / 1000, ret % 1000);
230}
231
232static const unsigned adis16400_3db_divisors[] = {
233 [0] = 2, /* Special case */
234 [1] = 6,
235 [2] = 12,
236 [3] = 25,
237 [4] = 50,
238 [5] = 100,
239 [6] = 200,
240 [7] = 200, /* Not a valid setting */
241};
242
243static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val)
244{
245 struct adis16400_state *st = iio_priv(indio_dev);
246 uint16_t val16;
247 int i, ret;
248
249 for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 1; i--) {
250 if (sps / adis16400_3db_divisors[i] >= val)
251 break;
252 }
253
254 ret = adis_read_reg_16(&st->adis, ADIS16400_SENS_AVG, &val16);
255 if (ret < 0)
256 return ret;
257
258 ret = adis_write_reg_16(&st->adis, ADIS16400_SENS_AVG,
259 (val16 & ~0x07) | i);
260 return ret;
261}
262
263static ssize_t adis16400_write_frequency(struct device *dev,
264 struct device_attribute *attr, const char *buf, size_t len)
265{
266 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
267 struct adis16400_state *st = iio_priv(indio_dev);
268 int i, f, val;
269 int ret;
270
271 ret = iio_str_to_fixpoint(buf, 100, &i, &f);
272 if (ret)
273 return ret;
274
275 val = i * 1000 + f;
276
277 if (val <= 0)
278 return -EINVAL;
279
280 mutex_lock(&indio_dev->mlock);
281 st->variant->set_freq(st, val);
282 mutex_unlock(&indio_dev->mlock);
283
284 return ret ? ret : len;
285}
286
287/* Power down the device */
288static int adis16400_stop_device(struct iio_dev *indio_dev)
289{
290 struct adis16400_state *st = iio_priv(indio_dev);
291 int ret;
292
293 ret = adis_write_reg_16(&st->adis, ADIS16400_SLP_CNT,
294 ADIS16400_SLP_CNT_POWER_OFF);
295 if (ret)
296 dev_err(&indio_dev->dev,
297 "problem with turning device off: SLP_CNT");
298
299 return ret;
300}
301
302static int adis16400_initial_setup(struct iio_dev *indio_dev)
303{
304 struct adis16400_state *st = iio_priv(indio_dev);
305 uint16_t prod_id, smp_prd;
306 unsigned int device_id;
307 int ret;
308
309 /* use low spi speed for init if the device has a slow mode */
310 if (st->variant->flags & ADIS16400_HAS_SLOW_MODE)
311 st->adis.spi->max_speed_hz = ADIS16400_SPI_SLOW;
312 else
313 st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST;
314 st->adis.spi->mode = SPI_MODE_3;
315 spi_setup(st->adis.spi);
316
317 ret = adis_initial_startup(&st->adis);
318 if (ret)
319 return ret;
320
321 if (st->variant->flags & ADIS16400_HAS_PROD_ID) {
322 ret = adis_read_reg_16(&st->adis,
323 ADIS16400_PRODUCT_ID, &prod_id);
324 if (ret)
325 goto err_ret;
326
327 sscanf(indio_dev->name, "adis%u\n", &device_id);
328
329 if (prod_id != device_id)
330 dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.",
331 device_id, prod_id);
332
333 dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n",
334 indio_dev->name, prod_id,
335 st->adis.spi->chip_select, st->adis.spi->irq);
336 }
337 /* use high spi speed if possible */
338 if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) {
339 ret = adis_read_reg_16(&st->adis, ADIS16400_SMPL_PRD, &smp_prd);
340 if (ret)
341 goto err_ret;
342
343 if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) {
344 st->adis.spi->max_speed_hz = ADIS16400_SPI_FAST;
345 spi_setup(st->adis.spi);
346 }
347 }
348
349err_ret:
350 return ret;
351}
352
353static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
354 adis16400_read_frequency,
355 adis16400_write_frequency);
356
357static const uint8_t adis16400_addresses[] = {
358 [ADIS16400_SCAN_GYRO_X] = ADIS16400_XGYRO_OFF,
359 [ADIS16400_SCAN_GYRO_Y] = ADIS16400_YGYRO_OFF,
360 [ADIS16400_SCAN_GYRO_Z] = ADIS16400_ZGYRO_OFF,
361 [ADIS16400_SCAN_ACC_X] = ADIS16400_XACCL_OFF,
362 [ADIS16400_SCAN_ACC_Y] = ADIS16400_YACCL_OFF,
363 [ADIS16400_SCAN_ACC_Z] = ADIS16400_ZACCL_OFF,
364};
365
366static int adis16400_write_raw(struct iio_dev *indio_dev,
367 struct iio_chan_spec const *chan, int val, int val2, long info)
368{
369 struct adis16400_state *st = iio_priv(indio_dev);
370 int ret, sps;
371
372 switch (info) {
373 case IIO_CHAN_INFO_CALIBBIAS:
374 mutex_lock(&indio_dev->mlock);
375 ret = adis_write_reg_16(&st->adis,
376 adis16400_addresses[chan->scan_index], val);
377 mutex_unlock(&indio_dev->mlock);
378 return ret;
379 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
380 /*
381 * Need to cache values so we can update if the frequency
382 * changes.
383 */
384 mutex_lock(&indio_dev->mlock);
385 st->filt_int = val;
386 /* Work out update to current value */
387 sps = st->variant->get_freq(st);
388 if (sps < 0) {
389 mutex_unlock(&indio_dev->mlock);
390 return sps;
391 }
392
393 ret = adis16400_set_filter(indio_dev, sps,
394 val * 1000 + val2 / 1000);
395 mutex_unlock(&indio_dev->mlock);
396 return ret;
397 default:
398 return -EINVAL;
399 }
400}
401
402static int adis16400_read_raw(struct iio_dev *indio_dev,
403 struct iio_chan_spec const *chan, int *val, int *val2, long info)
404{
405 struct adis16400_state *st = iio_priv(indio_dev);
406 int16_t val16;
407 int ret;
408
409 switch (info) {
410 case IIO_CHAN_INFO_RAW:
411 return adis_single_conversion(indio_dev, chan, 0, val);
412 case IIO_CHAN_INFO_SCALE:
413 switch (chan->type) {
414 case IIO_ANGL_VEL:
415 *val = 0;
416 *val2 = st->variant->gyro_scale_micro;
417 return IIO_VAL_INT_PLUS_MICRO;
418 case IIO_VOLTAGE:
419 *val = 0;
420 if (chan->channel == 0) {
421 *val = 2;
422 *val2 = 418000; /* 2.418 mV */
423 } else {
424 *val = 0;
425 *val2 = 805800; /* 805.8 uV */
426 }
427 return IIO_VAL_INT_PLUS_MICRO;
428 case IIO_ACCEL:
429 *val = 0;
430 *val2 = st->variant->accel_scale_micro;
431 return IIO_VAL_INT_PLUS_MICRO;
432 case IIO_MAGN:
433 *val = 0;
434 *val2 = 500; /* 0.5 mgauss */
435 return IIO_VAL_INT_PLUS_MICRO;
436 case IIO_TEMP:
437 *val = st->variant->temp_scale_nano / 1000000;
438 *val2 = (st->variant->temp_scale_nano % 1000000);
439 return IIO_VAL_INT_PLUS_MICRO;
440 default:
441 return -EINVAL;
442 }
443 case IIO_CHAN_INFO_CALIBBIAS:
444 mutex_lock(&indio_dev->mlock);
445 ret = adis_read_reg_16(&st->adis,
446 adis16400_addresses[chan->scan_index], &val16);
447 mutex_unlock(&indio_dev->mlock);
448 if (ret)
449 return ret;
450 val16 = ((val16 & 0xFFF) << 4) >> 4;
451 *val = val16;
452 return IIO_VAL_INT;
453 case IIO_CHAN_INFO_OFFSET:
454 /* currently only temperature */
455 *val = st->variant->temp_offset;
456 return IIO_VAL_INT;
457 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
458 mutex_lock(&indio_dev->mlock);
459 /* Need both the number of taps and the sampling frequency */
460 ret = adis_read_reg_16(&st->adis,
461 ADIS16400_SENS_AVG,
462 &val16);
463 if (ret < 0) {
464 mutex_unlock(&indio_dev->mlock);
465 return ret;
466 }
467 ret = st->variant->get_freq(st);
468 if (ret >= 0) {
469 ret /= adis16400_3db_divisors[val16 & 0x07];
470 *val = ret / 1000;
471 *val2 = (ret % 1000) * 1000;
472 }
473 mutex_unlock(&indio_dev->mlock);
474 if (ret < 0)
475 return ret;
476 return IIO_VAL_INT_PLUS_MICRO;
477 default:
478 return -EINVAL;
479 }
480}
481
482#define ADIS16400_VOLTAGE_CHAN(addr, bits, name, si) { \
483 .type = IIO_VOLTAGE, \
484 .indexed = 1, \
485 .channel = 0, \
486 .extend_name = name, \
487 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
488 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
489 .address = (addr), \
490 .scan_index = (si), \
491 .scan_type = { \
492 .sign = 'u', \
493 .realbits = (bits), \
494 .storagebits = 16, \
495 .shift = 0, \
496 .endianness = IIO_BE, \
497 }, \
498}
499
500#define ADIS16400_SUPPLY_CHAN(addr, bits) \
501 ADIS16400_VOLTAGE_CHAN(addr, bits, "supply", ADIS16400_SCAN_SUPPLY)
502
503#define ADIS16400_AUX_ADC_CHAN(addr, bits) \
504 ADIS16400_VOLTAGE_CHAN(addr, bits, NULL, ADIS16400_SCAN_ADC)
505
506#define ADIS16400_GYRO_CHAN(mod, addr, bits) { \
507 .type = IIO_ANGL_VEL, \
508 .modified = 1, \
509 .channel2 = IIO_MOD_ ## mod, \
510 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
511 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
512 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
513 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
514 .address = addr, \
515 .scan_index = ADIS16400_SCAN_GYRO_ ## mod, \
516 .scan_type = { \
517 .sign = 's', \
518 .realbits = (bits), \
519 .storagebits = 16, \
520 .shift = 0, \
521 .endianness = IIO_BE, \
522 }, \
523}
524
525#define ADIS16400_ACCEL_CHAN(mod, addr, bits) { \
526 .type = IIO_ACCEL, \
527 .modified = 1, \
528 .channel2 = IIO_MOD_ ## mod, \
529 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
530 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT | \
531 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
532 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
533 .address = (addr), \
534 .scan_index = ADIS16400_SCAN_ACC_ ## mod, \
535 .scan_type = { \
536 .sign = 's', \
537 .realbits = (bits), \
538 .storagebits = 16, \
539 .shift = 0, \
540 .endianness = IIO_BE, \
541 }, \
542}
543
544#define ADIS16400_MAGN_CHAN(mod, addr, bits) { \
545 .type = IIO_MAGN, \
546 .modified = 1, \
547 .channel2 = IIO_MOD_ ## mod, \
548 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
549 IIO_CHAN_INFO_SCALE_SHARED_BIT | \
550 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
551 .address = (addr), \
552 .scan_index = ADIS16400_SCAN_MAGN_ ## mod, \
553 .scan_type = { \
554 .sign = 's', \
555 .realbits = (bits), \
556 .storagebits = 16, \
557 .shift = 0, \
558 .endianness = IIO_BE, \
559 }, \
560}
561
562#define ADIS16400_MOD_TEMP_NAME_X "x"
563#define ADIS16400_MOD_TEMP_NAME_Y "y"
564#define ADIS16400_MOD_TEMP_NAME_Z "z"
565
566#define ADIS16400_MOD_TEMP_CHAN(mod, addr, bits) { \
567 .type = IIO_TEMP, \
568 .indexed = 1, \
569 .channel = 0, \
570 .extend_name = ADIS16400_MOD_TEMP_NAME_ ## mod, \
571 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
572 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \
573 IIO_CHAN_INFO_SCALE_SEPARATE_BIT | \
574 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT, \
575 .address = (addr), \
576 .scan_index = ADIS16350_SCAN_TEMP_ ## mod, \
577 .scan_type = { \
578 .sign = 's', \
579 .realbits = (bits), \
580 .storagebits = 16, \
581 .shift = 0, \
582 .endianness = IIO_BE, \
583 }, \
584}
585
586#define ADIS16400_TEMP_CHAN(addr, bits) { \
587 .type = IIO_TEMP, \
588 .indexed = 1, \
589 .channel = 0, \
590 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
591 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT | \
592 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
593 .address = (addr), \
594 .scan_index = ADIS16350_SCAN_TEMP_X, \
595 .scan_type = { \
596 .sign = 's', \
597 .realbits = (bits), \
598 .storagebits = 16, \
599 .shift = 0, \
600 .endianness = IIO_BE, \
601 }, \
602}
603
604#define ADIS16400_INCLI_CHAN(mod, addr, bits) { \
605 .type = IIO_INCLI, \
606 .modified = 1, \
607 .channel2 = IIO_MOD_ ## mod, \
608 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
609 IIO_CHAN_INFO_SCALE_SHARED_BIT, \
610 .address = (addr), \
611 .scan_index = ADIS16300_SCAN_INCLI_ ## mod, \
612 .scan_type = { \
613 .sign = 's', \
614 .realbits = (bits), \
615 .storagebits = 16, \
616 .shift = 0, \
617 .endianness = IIO_BE, \
618 }, \
619}
620
621static const struct iio_chan_spec adis16400_channels[] = {
622 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 14),
623 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14),
624 ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14),
625 ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14),
626 ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14),
627 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14),
628 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14),
629 ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14),
630 ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14),
631 ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14),
632 ADIS16400_TEMP_CHAN(ADIS16400_TEMP_OUT, 12),
633 ADIS16400_AUX_ADC_CHAN(ADIS16400_AUX_ADC, 12),
634 IIO_CHAN_SOFT_TIMESTAMP(12)
635};
636
637static const struct iio_chan_spec adis16448_channels[] = {
638 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 16),
639 ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 16),
640 ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 16),
641 ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 16),
642 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 16),
643 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 16),
644 ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 16),
645 ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 16),
646 ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 16),
647 {
648 .type = IIO_PRESSURE,
649 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
650 IIO_CHAN_INFO_SCALE_SHARED_BIT,
651 .address = ADIS16448_BARO_OUT,
652 .scan_index = ADIS16400_SCAN_BARO,
653 .scan_type = IIO_ST('s', 16, 16, 0),
654 },
655 ADIS16400_TEMP_CHAN(ADIS16448_TEMP_OUT, 12),
656 IIO_CHAN_SOFT_TIMESTAMP(11)
657};
658
659static const struct iio_chan_spec adis16350_channels[] = {
660 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12),
661 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14),
662 ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14),
663 ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14),
664 ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14),
665 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14),
666 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14),
667 ADIS16400_MAGN_CHAN(X, ADIS16400_XMAGN_OUT, 14),
668 ADIS16400_MAGN_CHAN(Y, ADIS16400_YMAGN_OUT, 14),
669 ADIS16400_MAGN_CHAN(Z, ADIS16400_ZMAGN_OUT, 14),
670 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12),
671 ADIS16400_MOD_TEMP_CHAN(X, ADIS16350_XTEMP_OUT, 12),
672 ADIS16400_MOD_TEMP_CHAN(Y, ADIS16350_YTEMP_OUT, 12),
673 ADIS16400_MOD_TEMP_CHAN(Z, ADIS16350_ZTEMP_OUT, 12),
674 IIO_CHAN_SOFT_TIMESTAMP(11)
675};
676
677static const struct iio_chan_spec adis16300_channels[] = {
678 ADIS16400_SUPPLY_CHAN(ADIS16400_SUPPLY_OUT, 12),
679 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14),
680 ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14),
681 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14),
682 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14),
683 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12),
684 ADIS16400_AUX_ADC_CHAN(ADIS16300_AUX_ADC, 12),
685 ADIS16400_INCLI_CHAN(X, ADIS16300_PITCH_OUT, 13),
686 ADIS16400_INCLI_CHAN(Y, ADIS16300_ROLL_OUT, 13),
687 IIO_CHAN_SOFT_TIMESTAMP(14)
688};
689
690static const struct iio_chan_spec adis16334_channels[] = {
691 ADIS16400_GYRO_CHAN(X, ADIS16400_XGYRO_OUT, 14),
692 ADIS16400_GYRO_CHAN(Y, ADIS16400_YGYRO_OUT, 14),
693 ADIS16400_GYRO_CHAN(Z, ADIS16400_ZGYRO_OUT, 14),
694 ADIS16400_ACCEL_CHAN(X, ADIS16400_XACCL_OUT, 14),
695 ADIS16400_ACCEL_CHAN(Y, ADIS16400_YACCL_OUT, 14),
696 ADIS16400_ACCEL_CHAN(Z, ADIS16400_ZACCL_OUT, 14),
697 ADIS16400_TEMP_CHAN(ADIS16350_XTEMP_OUT, 12),
698 IIO_CHAN_SOFT_TIMESTAMP(8)
699};
700
701static struct attribute *adis16400_attributes[] = {
702 &iio_dev_attr_sampling_frequency.dev_attr.attr,
703 NULL
704};
705
706static const struct attribute_group adis16400_attribute_group = {
707 .attrs = adis16400_attributes,
708};
709
710static struct adis16400_chip_info adis16400_chips[] = {
711 [ADIS16300] = {
712 .channels = adis16300_channels,
713 .num_channels = ARRAY_SIZE(adis16300_channels),
714 .flags = ADIS16400_HAS_SLOW_MODE,
715 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
716 .accel_scale_micro = 5884,
717 .temp_scale_nano = 140000000, /* 0.14 C */
718 .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */
719 .set_freq = adis16400_set_freq,
720 .get_freq = adis16400_get_freq,
721 },
722 [ADIS16334] = {
723 .channels = adis16334_channels,
724 .num_channels = ARRAY_SIZE(adis16334_channels),
725 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_NO_BURST |
726 ADIS16400_HAS_SERIAL_NUMBER,
727 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
728 .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
729 .temp_scale_nano = 67850000, /* 0.06785 C */
730 .temp_offset = 25000000 / 67850, /* 25 C = 0x00 */
731 .set_freq = adis16334_set_freq,
732 .get_freq = adis16334_get_freq,
733 },
734 [ADIS16350] = {
735 .channels = adis16350_channels,
736 .num_channels = ARRAY_SIZE(adis16350_channels),
737 .gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */
738 .accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */
739 .temp_scale_nano = 145300000, /* 0.1453 C */
740 .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */
741 .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE,
742 .set_freq = adis16400_set_freq,
743 .get_freq = adis16400_get_freq,
744 },
745 [ADIS16360] = {
746 .channels = adis16350_channels,
747 .num_channels = ARRAY_SIZE(adis16350_channels),
748 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
749 ADIS16400_HAS_SERIAL_NUMBER,
750 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
751 .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
752 .temp_scale_nano = 136000000, /* 0.136 C */
753 .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
754 .set_freq = adis16400_set_freq,
755 .get_freq = adis16400_get_freq,
756 },
757 [ADIS16362] = {
758 .channels = adis16350_channels,
759 .num_channels = ARRAY_SIZE(adis16350_channels),
760 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
761 ADIS16400_HAS_SERIAL_NUMBER,
762 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
763 .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */
764 .temp_scale_nano = 136000000, /* 0.136 C */
765 .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
766 .set_freq = adis16400_set_freq,
767 .get_freq = adis16400_get_freq,
768 },
769 [ADIS16364] = {
770 .channels = adis16350_channels,
771 .num_channels = ARRAY_SIZE(adis16350_channels),
772 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE |
773 ADIS16400_HAS_SERIAL_NUMBER,
774 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
775 .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
776 .temp_scale_nano = 136000000, /* 0.136 C */
777 .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
778 .set_freq = adis16400_set_freq,
779 .get_freq = adis16400_get_freq,
780 },
781 [ADIS16400] = {
782 .channels = adis16400_channels,
783 .num_channels = ARRAY_SIZE(adis16400_channels),
784 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
785 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
786 .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
787 .temp_scale_nano = 140000000, /* 0.14 C */
788 .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */
789 .set_freq = adis16400_set_freq,
790 .get_freq = adis16400_get_freq,
791 },
792 [ADIS16448] = {
793 .channels = adis16448_channels,
794 .num_channels = ARRAY_SIZE(adis16448_channels),
795 .flags = ADIS16400_HAS_PROD_ID |
796 ADIS16400_HAS_SERIAL_NUMBER,
797 .gyro_scale_micro = IIO_DEGREE_TO_RAD(10000), /* 0.01 deg/s */
798 .accel_scale_micro = IIO_G_TO_M_S_2(833), /* 1/1200 g */
799 .temp_scale_nano = 73860000, /* 0.07386 C */
800 .temp_offset = 31000000 / 73860, /* 31 C = 0x00 */
801 .set_freq = adis16334_set_freq,
802 .get_freq = adis16334_get_freq,
803 }
804};
805
806static const struct iio_info adis16400_info = {
807 .driver_module = THIS_MODULE,
808 .read_raw = &adis16400_read_raw,
809 .write_raw = &adis16400_write_raw,
810 .attrs = &adis16400_attribute_group,
811 .update_scan_mode = adis16400_update_scan_mode,
812 .debugfs_reg_access = adis_debugfs_reg_access,
813};
814
815static const unsigned long adis16400_burst_scan_mask[] = {
816 ~0UL,
817 0,
818};
819
820static const char * const adis16400_status_error_msgs[] = {
821 [ADIS16400_DIAG_STAT_ZACCL_FAIL] = "Z-axis accelerometer self-test failure",
822 [ADIS16400_DIAG_STAT_YACCL_FAIL] = "Y-axis accelerometer self-test failure",
823 [ADIS16400_DIAG_STAT_XACCL_FAIL] = "X-axis accelerometer self-test failure",
824 [ADIS16400_DIAG_STAT_XGYRO_FAIL] = "X-axis gyroscope self-test failure",
825 [ADIS16400_DIAG_STAT_YGYRO_FAIL] = "Y-axis gyroscope self-test failure",
826 [ADIS16400_DIAG_STAT_ZGYRO_FAIL] = "Z-axis gyroscope self-test failure",
827 [ADIS16400_DIAG_STAT_ALARM2] = "Alarm 2 active",
828 [ADIS16400_DIAG_STAT_ALARM1] = "Alarm 1 active",
829 [ADIS16400_DIAG_STAT_FLASH_CHK] = "Flash checksum error",
830 [ADIS16400_DIAG_STAT_SELF_TEST] = "Self test error",
831 [ADIS16400_DIAG_STAT_OVERFLOW] = "Sensor overrange",
832 [ADIS16400_DIAG_STAT_SPI_FAIL] = "SPI failure",
833 [ADIS16400_DIAG_STAT_FLASH_UPT] = "Flash update failed",
834 [ADIS16400_DIAG_STAT_POWER_HIGH] = "Power supply above 5.25V",
835 [ADIS16400_DIAG_STAT_POWER_LOW] = "Power supply below 4.75V",
836};
837
838static const struct adis_data adis16400_data = {
839 .msc_ctrl_reg = ADIS16400_MSC_CTRL,
840 .glob_cmd_reg = ADIS16400_GLOB_CMD,
841 .diag_stat_reg = ADIS16400_DIAG_STAT,
842
843 .read_delay = 50,
844 .write_delay = 50,
845
846 .self_test_mask = ADIS16400_MSC_CTRL_MEM_TEST,
847 .startup_delay = ADIS16400_STARTUP_DELAY,
848
849 .status_error_msgs = adis16400_status_error_msgs,
850 .status_error_mask = BIT(ADIS16400_DIAG_STAT_ZACCL_FAIL) |
851 BIT(ADIS16400_DIAG_STAT_YACCL_FAIL) |
852 BIT(ADIS16400_DIAG_STAT_XACCL_FAIL) |
853 BIT(ADIS16400_DIAG_STAT_XGYRO_FAIL) |
854 BIT(ADIS16400_DIAG_STAT_YGYRO_FAIL) |
855 BIT(ADIS16400_DIAG_STAT_ZGYRO_FAIL) |
856 BIT(ADIS16400_DIAG_STAT_ALARM2) |
857 BIT(ADIS16400_DIAG_STAT_ALARM1) |
858 BIT(ADIS16400_DIAG_STAT_FLASH_CHK) |
859 BIT(ADIS16400_DIAG_STAT_SELF_TEST) |
860 BIT(ADIS16400_DIAG_STAT_OVERFLOW) |
861 BIT(ADIS16400_DIAG_STAT_SPI_FAIL) |
862 BIT(ADIS16400_DIAG_STAT_FLASH_UPT) |
863 BIT(ADIS16400_DIAG_STAT_POWER_HIGH) |
864 BIT(ADIS16400_DIAG_STAT_POWER_LOW),
865};
866
867static int adis16400_probe(struct spi_device *spi)
868{
869 struct adis16400_state *st;
870 struct iio_dev *indio_dev;
871 int ret;
872
873 indio_dev = iio_device_alloc(sizeof(*st));
874 if (indio_dev == NULL)
875 return -ENOMEM;
876
877 st = iio_priv(indio_dev);
878 /* this is only used for removal purposes */
879 spi_set_drvdata(spi, indio_dev);
880
881 /* setup the industrialio driver allocated elements */
882 st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];
883 indio_dev->dev.parent = &spi->dev;
884 indio_dev->name = spi_get_device_id(spi)->name;
885 indio_dev->channels = st->variant->channels;
886 indio_dev->num_channels = st->variant->num_channels;
887 indio_dev->info = &adis16400_info;
888 indio_dev->modes = INDIO_DIRECT_MODE;
889
890 if (!(st->variant->flags & ADIS16400_NO_BURST))
891 indio_dev->available_scan_masks = adis16400_burst_scan_mask;
892
893 ret = adis_init(&st->adis, indio_dev, spi, &adis16400_data);
894 if (ret)
895 goto error_free_dev;
896
897 ret = adis_setup_buffer_and_trigger(&st->adis, indio_dev,
898 adis16400_trigger_handler);
899 if (ret)
900 goto error_free_dev;
901
902 /* Get the device into a sane initial state */
903 ret = adis16400_initial_setup(indio_dev);
904 if (ret)
905 goto error_cleanup_buffer;
906 ret = iio_device_register(indio_dev);
907 if (ret)
908 goto error_cleanup_buffer;
909
910 adis16400_debugfs_init(indio_dev);
911 return 0;
912
913error_cleanup_buffer:
914 adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
915error_free_dev:
916 iio_device_free(indio_dev);
917 return ret;
918}
919
920static int adis16400_remove(struct spi_device *spi)
921{
922 struct iio_dev *indio_dev = spi_get_drvdata(spi);
923 struct adis16400_state *st = iio_priv(indio_dev);
924
925 iio_device_unregister(indio_dev);
926 adis16400_stop_device(indio_dev);
927
928 adis_cleanup_buffer_and_trigger(&st->adis, indio_dev);
929
930 iio_device_free(indio_dev);
931
932 return 0;
933}
934
935static const struct spi_device_id adis16400_id[] = {
936 {"adis16300", ADIS16300},
937 {"adis16334", ADIS16334},
938 {"adis16350", ADIS16350},
939 {"adis16354", ADIS16350},
940 {"adis16355", ADIS16350},
941 {"adis16360", ADIS16360},
942 {"adis16362", ADIS16362},
943 {"adis16364", ADIS16364},
944 {"adis16365", ADIS16360},
945 {"adis16400", ADIS16400},
946 {"adis16405", ADIS16400},
947 {"adis16448", ADIS16448},
948 {}
949};
950MODULE_DEVICE_TABLE(spi, adis16400_id);
951
952static struct spi_driver adis16400_driver = {
953 .driver = {
954 .name = "adis16400",
955 .owner = THIS_MODULE,
956 },
957 .id_table = adis16400_id,
958 .probe = adis16400_probe,
959 .remove = adis16400_remove,
960};
961module_spi_driver(adis16400_driver);
962
963MODULE_AUTHOR("Manuel Stahl <manuel.stahl@iis.fraunhofer.de>");
964MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver");
965MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/imu/inv_mpu6050/Kconfig b/drivers/iio/imu/inv_mpu6050/Kconfig
new file mode 100644
index 000000000000..b5cfa3a354cf
--- /dev/null
+++ b/drivers/iio/imu/inv_mpu6050/Kconfig
@@ -0,0 +1,13 @@
1#
2# inv-mpu6050 drivers for Invensense MPU devices and combos
3#
4
5config INV_MPU6050_IIO
6 tristate "Invensense MPU6050 devices"
7 depends on I2C && SYSFS
8 select IIO_TRIGGERED_BUFFER
9 help
10 This driver supports the Invensense MPU6050 devices.
11 It is a gyroscope/accelerometer combo device.
12 This driver can be built as a module. The module will be called
13 inv-mpu6050.
diff --git a/drivers/iio/imu/inv_mpu6050/Makefile b/drivers/iio/imu/inv_mpu6050/Makefile
new file mode 100644
index 000000000000..3a677c778afb
--- /dev/null
+++ b/drivers/iio/imu/inv_mpu6050/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for Invensense MPU6050 device.
3#
4
5obj-$(CONFIG_INV_MPU6050_IIO) += inv-mpu6050.o
6inv-mpu6050-objs := inv_mpu_core.o inv_mpu_ring.o inv_mpu_trigger.o
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
new file mode 100644
index 000000000000..37ca05b47e4b
--- /dev/null
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -0,0 +1,795 @@
1/*
2* Copyright (C) 2012 Invensense, Inc.
3*
4* This software is licensed under the terms of the GNU General Public
5* License version 2, as published by the Free Software Foundation, and
6* may be copied, distributed, and modified under those terms.
7*
8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*/
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/slab.h>
17#include <linux/i2c.h>
18#include <linux/err.h>
19#include <linux/delay.h>
20#include <linux/sysfs.h>
21#include <linux/jiffies.h>
22#include <linux/irq.h>
23#include <linux/interrupt.h>
24#include <linux/kfifo.h>
25#include <linux/spinlock.h>
26#include "inv_mpu_iio.h"
27
28/*
29 * this is the gyro scale translated from dynamic range plus/minus
30 * {250, 500, 1000, 2000} to rad/s
31 */
32static const int gyro_scale_6050[] = {133090, 266181, 532362, 1064724};
33
34/*
35 * this is the accel scale translated from dynamic range plus/minus
36 * {2, 4, 8, 16} to m/s^2
37 */
38static const int accel_scale[] = {598, 1196, 2392, 4785};
39
40static const struct inv_mpu6050_reg_map reg_set_6050 = {
41 .sample_rate_div = INV_MPU6050_REG_SAMPLE_RATE_DIV,
42 .lpf = INV_MPU6050_REG_CONFIG,
43 .user_ctrl = INV_MPU6050_REG_USER_CTRL,
44 .fifo_en = INV_MPU6050_REG_FIFO_EN,
45 .gyro_config = INV_MPU6050_REG_GYRO_CONFIG,
46 .accl_config = INV_MPU6050_REG_ACCEL_CONFIG,
47 .fifo_count_h = INV_MPU6050_REG_FIFO_COUNT_H,
48 .fifo_r_w = INV_MPU6050_REG_FIFO_R_W,
49 .raw_gyro = INV_MPU6050_REG_RAW_GYRO,
50 .raw_accl = INV_MPU6050_REG_RAW_ACCEL,
51 .temperature = INV_MPU6050_REG_TEMPERATURE,
52 .int_enable = INV_MPU6050_REG_INT_ENABLE,
53 .pwr_mgmt_1 = INV_MPU6050_REG_PWR_MGMT_1,
54 .pwr_mgmt_2 = INV_MPU6050_REG_PWR_MGMT_2,
55};
56
57static const struct inv_mpu6050_chip_config chip_config_6050 = {
58 .fsr = INV_MPU6050_FSR_2000DPS,
59 .lpf = INV_MPU6050_FILTER_20HZ,
60 .fifo_rate = INV_MPU6050_INIT_FIFO_RATE,
61 .gyro_fifo_enable = false,
62 .accl_fifo_enable = false,
63 .accl_fs = INV_MPU6050_FS_02G,
64};
65
66static const struct inv_mpu6050_hw hw_info[INV_NUM_PARTS] = {
67 {
68 .num_reg = 117,
69 .name = "MPU6050",
70 .reg = &reg_set_6050,
71 .config = &chip_config_6050,
72 },
73};
74
75int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 d)
76{
77 return i2c_smbus_write_i2c_block_data(st->client, reg, 1, &d);
78}
79
80int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask)
81{
82 u8 d, mgmt_1;
83 int result;
84
85 /* switch clock needs to be careful. Only when gyro is on, can
86 clock source be switched to gyro. Otherwise, it must be set to
87 internal clock */
88 if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) {
89 result = i2c_smbus_read_i2c_block_data(st->client,
90 st->reg->pwr_mgmt_1, 1, &mgmt_1);
91 if (result != 1)
92 return result;
93
94 mgmt_1 &= ~INV_MPU6050_BIT_CLK_MASK;
95 }
96
97 if ((INV_MPU6050_BIT_PWR_GYRO_STBY == mask) && (!en)) {
98 /* turning off gyro requires switch to internal clock first.
99 Then turn off gyro engine */
100 mgmt_1 |= INV_CLK_INTERNAL;
101 result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, mgmt_1);
102 if (result)
103 return result;
104 }
105
106 result = i2c_smbus_read_i2c_block_data(st->client,
107 st->reg->pwr_mgmt_2, 1, &d);
108 if (result != 1)
109 return result;
110 if (en)
111 d &= ~mask;
112 else
113 d |= mask;
114 result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_2, d);
115 if (result)
116 return result;
117
118 if (en) {
119 /* Wait for output stablize */
120 msleep(INV_MPU6050_TEMP_UP_TIME);
121 if (INV_MPU6050_BIT_PWR_GYRO_STBY == mask) {
122 /* switch internal clock to PLL */
123 mgmt_1 |= INV_CLK_PLL;
124 result = inv_mpu6050_write_reg(st,
125 st->reg->pwr_mgmt_1, mgmt_1);
126 if (result)
127 return result;
128 }
129 }
130
131 return 0;
132}
133
134int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)
135{
136 int result;
137
138 if (power_on)
139 result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1, 0);
140 else
141 result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1,
142 INV_MPU6050_BIT_SLEEP);
143 if (result)
144 return result;
145
146 if (power_on)
147 msleep(INV_MPU6050_REG_UP_TIME);
148
149 return 0;
150}
151
152/**
153 * inv_mpu6050_init_config() - Initialize hardware, disable FIFO.
154 *
155 * Initial configuration:
156 * FSR: ± 2000DPS
157 * DLPF: 20Hz
158 * FIFO rate: 50Hz
159 * Clock source: Gyro PLL
160 */
161static int inv_mpu6050_init_config(struct iio_dev *indio_dev)
162{
163 int result;
164 u8 d;
165 struct inv_mpu6050_state *st = iio_priv(indio_dev);
166
167 result = inv_mpu6050_set_power_itg(st, true);
168 if (result)
169 return result;
170 d = (INV_MPU6050_FSR_2000DPS << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
171 result = inv_mpu6050_write_reg(st, st->reg->gyro_config, d);
172 if (result)
173 return result;
174
175 d = INV_MPU6050_FILTER_20HZ;
176 result = inv_mpu6050_write_reg(st, st->reg->lpf, d);
177 if (result)
178 return result;
179
180 d = INV_MPU6050_ONE_K_HZ / INV_MPU6050_INIT_FIFO_RATE - 1;
181 result = inv_mpu6050_write_reg(st, st->reg->sample_rate_div, d);
182 if (result)
183 return result;
184
185 d = (INV_MPU6050_FS_02G << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT);
186 result = inv_mpu6050_write_reg(st, st->reg->accl_config, d);
187 if (result)
188 return result;
189
190 memcpy(&st->chip_config, hw_info[st->chip_type].config,
191 sizeof(struct inv_mpu6050_chip_config));
192 result = inv_mpu6050_set_power_itg(st, false);
193
194 return result;
195}
196
197static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg,
198 int axis, int *val)
199{
200 int ind, result;
201 __be16 d;
202
203 ind = (axis - IIO_MOD_X) * 2;
204 result = i2c_smbus_read_i2c_block_data(st->client, reg + ind, 2,
205 (u8 *)&d);
206 if (result != 2)
207 return -EINVAL;
208 *val = (short)be16_to_cpup(&d);
209
210 return IIO_VAL_INT;
211}
212
213static int inv_mpu6050_read_raw(struct iio_dev *indio_dev,
214 struct iio_chan_spec const *chan,
215 int *val,
216 int *val2,
217 long mask) {
218 struct inv_mpu6050_state *st = iio_priv(indio_dev);
219
220 switch (mask) {
221 case IIO_CHAN_INFO_RAW:
222 {
223 int ret, result;
224
225 ret = IIO_VAL_INT;
226 result = 0;
227 mutex_lock(&indio_dev->mlock);
228 if (!st->chip_config.enable) {
229 result = inv_mpu6050_set_power_itg(st, true);
230 if (result)
231 goto error_read_raw;
232 }
233 /* when enable is on, power is already on */
234 switch (chan->type) {
235 case IIO_ANGL_VEL:
236 if (!st->chip_config.gyro_fifo_enable ||
237 !st->chip_config.enable) {
238 result = inv_mpu6050_switch_engine(st, true,
239 INV_MPU6050_BIT_PWR_GYRO_STBY);
240 if (result)
241 goto error_read_raw;
242 }
243 ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro,
244 chan->channel2, val);
245 if (!st->chip_config.gyro_fifo_enable ||
246 !st->chip_config.enable) {
247 result = inv_mpu6050_switch_engine(st, false,
248 INV_MPU6050_BIT_PWR_GYRO_STBY);
249 if (result)
250 goto error_read_raw;
251 }
252 break;
253 case IIO_ACCEL:
254 if (!st->chip_config.accl_fifo_enable ||
255 !st->chip_config.enable) {
256 result = inv_mpu6050_switch_engine(st, true,
257 INV_MPU6050_BIT_PWR_ACCL_STBY);
258 if (result)
259 goto error_read_raw;
260 }
261 ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl,
262 chan->channel2, val);
263 if (!st->chip_config.accl_fifo_enable ||
264 !st->chip_config.enable) {
265 result = inv_mpu6050_switch_engine(st, false,
266 INV_MPU6050_BIT_PWR_ACCL_STBY);
267 if (result)
268 goto error_read_raw;
269 }
270 break;
271 case IIO_TEMP:
272 /* wait for stablization */
273 msleep(INV_MPU6050_SENSOR_UP_TIME);
274 inv_mpu6050_sensor_show(st, st->reg->temperature,
275 IIO_MOD_X, val);
276 break;
277 default:
278 ret = -EINVAL;
279 break;
280 }
281error_read_raw:
282 if (!st->chip_config.enable)
283 result |= inv_mpu6050_set_power_itg(st, false);
284 mutex_unlock(&indio_dev->mlock);
285 if (result)
286 return result;
287
288 return ret;
289 }
290 case IIO_CHAN_INFO_SCALE:
291 switch (chan->type) {
292 case IIO_ANGL_VEL:
293 *val = 0;
294 *val2 = gyro_scale_6050[st->chip_config.fsr];
295
296 return IIO_VAL_INT_PLUS_NANO;
297 case IIO_ACCEL:
298 *val = 0;
299 *val2 = accel_scale[st->chip_config.accl_fs];
300
301 return IIO_VAL_INT_PLUS_MICRO;
302 case IIO_TEMP:
303 *val = 0;
304 *val2 = INV_MPU6050_TEMP_SCALE;
305
306 return IIO_VAL_INT_PLUS_MICRO;
307 default:
308 return -EINVAL;
309 }
310 case IIO_CHAN_INFO_OFFSET:
311 switch (chan->type) {
312 case IIO_TEMP:
313 *val = INV_MPU6050_TEMP_OFFSET;
314
315 return IIO_VAL_INT;
316 default:
317 return -EINVAL;
318 }
319 default:
320 return -EINVAL;
321 }
322}
323
324static int inv_mpu6050_write_fsr(struct inv_mpu6050_state *st, int fsr)
325{
326 int result;
327 u8 d;
328
329 if (fsr < 0 || fsr > INV_MPU6050_MAX_GYRO_FS_PARAM)
330 return -EINVAL;
331 if (fsr == st->chip_config.fsr)
332 return 0;
333
334 d = (fsr << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
335 result = inv_mpu6050_write_reg(st, st->reg->gyro_config, d);
336 if (result)
337 return result;
338 st->chip_config.fsr = fsr;
339
340 return 0;
341}
342
343static int inv_mpu6050_write_accel_fs(struct inv_mpu6050_state *st, int fs)
344{
345 int result;
346 u8 d;
347
348 if (fs < 0 || fs > INV_MPU6050_MAX_ACCL_FS_PARAM)
349 return -EINVAL;
350 if (fs == st->chip_config.accl_fs)
351 return 0;
352
353 d = (fs << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT);
354 result = inv_mpu6050_write_reg(st, st->reg->accl_config, d);
355 if (result)
356 return result;
357 st->chip_config.accl_fs = fs;
358
359 return 0;
360}
361
362static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
363 struct iio_chan_spec const *chan,
364 int val,
365 int val2,
366 long mask) {
367 struct inv_mpu6050_state *st = iio_priv(indio_dev);
368 int result;
369
370 mutex_lock(&indio_dev->mlock);
371 /* we should only update scale when the chip is disabled, i.e.,
372 not running */
373 if (st->chip_config.enable) {
374 result = -EBUSY;
375 goto error_write_raw;
376 }
377 result = inv_mpu6050_set_power_itg(st, true);
378 if (result)
379 goto error_write_raw;
380
381 switch (mask) {
382 case IIO_CHAN_INFO_SCALE:
383 switch (chan->type) {
384 case IIO_ANGL_VEL:
385 result = inv_mpu6050_write_fsr(st, val);
386 break;
387 case IIO_ACCEL:
388 result = inv_mpu6050_write_accel_fs(st, val);
389 break;
390 default:
391 result = -EINVAL;
392 break;
393 }
394 break;
395 default:
396 result = -EINVAL;
397 break;
398 }
399
400error_write_raw:
401 result |= inv_mpu6050_set_power_itg(st, false);
402 mutex_unlock(&indio_dev->mlock);
403
404 return result;
405}
406
407/**
408 * inv_mpu6050_set_lpf() - set low pass filer based on fifo rate.
409 *
410 * Based on the Nyquist principle, the sampling rate must
411 * exceed twice of the bandwidth of the signal, or there
412 * would be alising. This function basically search for the
413 * correct low pass parameters based on the fifo rate, e.g,
414 * sampling frequency.
415 */
416static int inv_mpu6050_set_lpf(struct inv_mpu6050_state *st, int rate)
417{
418 const int hz[] = {188, 98, 42, 20, 10, 5};
419 const int d[] = {INV_MPU6050_FILTER_188HZ, INV_MPU6050_FILTER_98HZ,
420 INV_MPU6050_FILTER_42HZ, INV_MPU6050_FILTER_20HZ,
421 INV_MPU6050_FILTER_10HZ, INV_MPU6050_FILTER_5HZ};
422 int i, h, result;
423 u8 data;
424
425 h = (rate >> 1);
426 i = 0;
427 while ((h < hz[i]) && (i < ARRAY_SIZE(d) - 1))
428 i++;
429 data = d[i];
430 result = inv_mpu6050_write_reg(st, st->reg->lpf, data);
431 if (result)
432 return result;
433 st->chip_config.lpf = data;
434
435 return 0;
436}
437
438/**
439 * inv_mpu6050_fifo_rate_store() - Set fifo rate.
440 */
441static ssize_t inv_mpu6050_fifo_rate_store(struct device *dev,
442 struct device_attribute *attr, const char *buf, size_t count)
443{
444 s32 fifo_rate;
445 u8 d;
446 int result;
447 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
448 struct inv_mpu6050_state *st = iio_priv(indio_dev);
449
450 if (kstrtoint(buf, 10, &fifo_rate))
451 return -EINVAL;
452 if (fifo_rate < INV_MPU6050_MIN_FIFO_RATE ||
453 fifo_rate > INV_MPU6050_MAX_FIFO_RATE)
454 return -EINVAL;
455 if (fifo_rate == st->chip_config.fifo_rate)
456 return count;
457
458 mutex_lock(&indio_dev->mlock);
459 if (st->chip_config.enable) {
460 result = -EBUSY;
461 goto fifo_rate_fail;
462 }
463 result = inv_mpu6050_set_power_itg(st, true);
464 if (result)
465 goto fifo_rate_fail;
466
467 d = INV_MPU6050_ONE_K_HZ / fifo_rate - 1;
468 result = inv_mpu6050_write_reg(st, st->reg->sample_rate_div, d);
469 if (result)
470 goto fifo_rate_fail;
471 st->chip_config.fifo_rate = fifo_rate;
472
473 result = inv_mpu6050_set_lpf(st, fifo_rate);
474 if (result)
475 goto fifo_rate_fail;
476
477fifo_rate_fail:
478 result |= inv_mpu6050_set_power_itg(st, false);
479 mutex_unlock(&indio_dev->mlock);
480 if (result)
481 return result;
482
483 return count;
484}
485
486/**
487 * inv_fifo_rate_show() - Get the current sampling rate.
488 */
489static ssize_t inv_fifo_rate_show(struct device *dev,
490 struct device_attribute *attr, char *buf)
491{
492 struct inv_mpu6050_state *st = iio_priv(dev_to_iio_dev(dev));
493
494 return sprintf(buf, "%d\n", st->chip_config.fifo_rate);
495}
496
497/**
498 * inv_attr_show() - calling this function will show current
499 * parameters.
500 */
501static ssize_t inv_attr_show(struct device *dev,
502 struct device_attribute *attr, char *buf)
503{
504 struct inv_mpu6050_state *st = iio_priv(dev_to_iio_dev(dev));
505 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
506 s8 *m;
507
508 switch (this_attr->address) {
509 /* In MPU6050, the two matrix are the same because gyro and accel
510 are integrated in one chip */
511 case ATTR_GYRO_MATRIX:
512 case ATTR_ACCL_MATRIX:
513 m = st->plat_data.orientation;
514
515 return sprintf(buf, "%d, %d, %d; %d, %d, %d; %d, %d, %d\n",
516 m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
517 default:
518 return -EINVAL;
519 }
520}
521
522/**
523 * inv_mpu6050_validate_trigger() - validate_trigger callback for invensense
524 * MPU6050 device.
525 * @indio_dev: The IIO device
526 * @trig: The new trigger
527 *
528 * Returns: 0 if the 'trig' matches the trigger registered by the MPU6050
529 * device, -EINVAL otherwise.
530 */
531static int inv_mpu6050_validate_trigger(struct iio_dev *indio_dev,
532 struct iio_trigger *trig)
533{
534 struct inv_mpu6050_state *st = iio_priv(indio_dev);
535
536 if (st->trig != trig)
537 return -EINVAL;
538
539 return 0;
540}
541
542#define INV_MPU6050_CHAN(_type, _channel2, _index) \
543 { \
544 .type = _type, \
545 .modified = 1, \
546 .channel2 = _channel2, \
547 .info_mask = IIO_CHAN_INFO_SCALE_SHARED_BIT \
548 | IIO_CHAN_INFO_RAW_SEPARATE_BIT, \
549 .scan_index = _index, \
550 .scan_type = { \
551 .sign = 's', \
552 .realbits = 16, \
553 .storagebits = 16, \
554 .shift = 0 , \
555 .endianness = IIO_BE, \
556 }, \
557 }
558
559static const struct iio_chan_spec inv_mpu_channels[] = {
560 IIO_CHAN_SOFT_TIMESTAMP(INV_MPU6050_SCAN_TIMESTAMP),
561 /*
562 * Note that temperature should only be via polled reading only,
563 * not the final scan elements output.
564 */
565 {
566 .type = IIO_TEMP,
567 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT
568 | IIO_CHAN_INFO_OFFSET_SEPARATE_BIT
569 | IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
570 .scan_index = -1,
571 },
572 INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_X, INV_MPU6050_SCAN_GYRO_X),
573 INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Y, INV_MPU6050_SCAN_GYRO_Y),
574 INV_MPU6050_CHAN(IIO_ANGL_VEL, IIO_MOD_Z, INV_MPU6050_SCAN_GYRO_Z),
575
576 INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_X, INV_MPU6050_SCAN_ACCL_X),
577 INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Y, INV_MPU6050_SCAN_ACCL_Y),
578 INV_MPU6050_CHAN(IIO_ACCEL, IIO_MOD_Z, INV_MPU6050_SCAN_ACCL_Z),
579};
580
581/* constant IIO attribute */
582static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 20 50 100 200 500");
583static IIO_DEV_ATTR_SAMP_FREQ(S_IRUGO | S_IWUSR, inv_fifo_rate_show,
584 inv_mpu6050_fifo_rate_store);
585static IIO_DEVICE_ATTR(in_gyro_matrix, S_IRUGO, inv_attr_show, NULL,
586 ATTR_GYRO_MATRIX);
587static IIO_DEVICE_ATTR(in_accel_matrix, S_IRUGO, inv_attr_show, NULL,
588 ATTR_ACCL_MATRIX);
589
590static struct attribute *inv_attributes[] = {
591 &iio_dev_attr_in_gyro_matrix.dev_attr.attr,
592 &iio_dev_attr_in_accel_matrix.dev_attr.attr,
593 &iio_dev_attr_sampling_frequency.dev_attr.attr,
594 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
595 NULL,
596};
597
598static const struct attribute_group inv_attribute_group = {
599 .attrs = inv_attributes
600};
601
602static const struct iio_info mpu_info = {
603 .driver_module = THIS_MODULE,
604 .read_raw = &inv_mpu6050_read_raw,
605 .write_raw = &inv_mpu6050_write_raw,
606 .attrs = &inv_attribute_group,
607 .validate_trigger = inv_mpu6050_validate_trigger,
608};
609
610/**
611 * inv_check_and_setup_chip() - check and setup chip.
612 */
613static int inv_check_and_setup_chip(struct inv_mpu6050_state *st,
614 const struct i2c_device_id *id)
615{
616 int result;
617
618 st->chip_type = INV_MPU6050;
619 st->hw = &hw_info[st->chip_type];
620 st->reg = hw_info[st->chip_type].reg;
621
622 /* reset to make sure previous state are not there */
623 result = inv_mpu6050_write_reg(st, st->reg->pwr_mgmt_1,
624 INV_MPU6050_BIT_H_RESET);
625 if (result)
626 return result;
627 msleep(INV_MPU6050_POWER_UP_TIME);
628 /* toggle power state. After reset, the sleep bit could be on
629 or off depending on the OTP settings. Toggling power would
630 make it in a definite state as well as making the hardware
631 state align with the software state */
632 result = inv_mpu6050_set_power_itg(st, false);
633 if (result)
634 return result;
635 result = inv_mpu6050_set_power_itg(st, true);
636 if (result)
637 return result;
638
639 result = inv_mpu6050_switch_engine(st, false,
640 INV_MPU6050_BIT_PWR_ACCL_STBY);
641 if (result)
642 return result;
643 result = inv_mpu6050_switch_engine(st, false,
644 INV_MPU6050_BIT_PWR_GYRO_STBY);
645 if (result)
646 return result;
647
648 return 0;
649}
650
651/**
652 * inv_mpu_probe() - probe function.
653 * @client: i2c client.
654 * @id: i2c device id.
655 *
656 * Returns 0 on success, a negative error code otherwise.
657 */
658static int inv_mpu_probe(struct i2c_client *client,
659 const struct i2c_device_id *id)
660{
661 struct inv_mpu6050_state *st;
662 struct iio_dev *indio_dev;
663 int result;
664
665 if (!i2c_check_functionality(client->adapter,
666 I2C_FUNC_SMBUS_READ_I2C_BLOCK |
667 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
668 result = -ENOSYS;
669 goto out_no_free;
670 }
671 indio_dev = iio_device_alloc(sizeof(*st));
672 if (indio_dev == NULL) {
673 result = -ENOMEM;
674 goto out_no_free;
675 }
676 st = iio_priv(indio_dev);
677 st->client = client;
678 st->plat_data = *(struct inv_mpu6050_platform_data
679 *)dev_get_platdata(&client->dev);
680 /* power is turned on inside check chip type*/
681 result = inv_check_and_setup_chip(st, id);
682 if (result)
683 goto out_free;
684
685 result = inv_mpu6050_init_config(indio_dev);
686 if (result) {
687 dev_err(&client->dev,
688 "Could not initialize device.\n");
689 goto out_free;
690 }
691
692 i2c_set_clientdata(client, indio_dev);
693 indio_dev->dev.parent = &client->dev;
694 indio_dev->name = id->name;
695 indio_dev->channels = inv_mpu_channels;
696 indio_dev->num_channels = ARRAY_SIZE(inv_mpu_channels);
697
698 indio_dev->info = &mpu_info;
699 indio_dev->modes = INDIO_BUFFER_TRIGGERED;
700
701 result = iio_triggered_buffer_setup(indio_dev,
702 inv_mpu6050_irq_handler,
703 inv_mpu6050_read_fifo,
704 NULL);
705 if (result) {
706 dev_err(&st->client->dev, "configure buffer fail %d\n",
707 result);
708 goto out_free;
709 }
710 result = inv_mpu6050_probe_trigger(indio_dev);
711 if (result) {
712 dev_err(&st->client->dev, "trigger probe fail %d\n", result);
713 goto out_unreg_ring;
714 }
715
716 INIT_KFIFO(st->timestamps);
717 spin_lock_init(&st->time_stamp_lock);
718 result = iio_device_register(indio_dev);
719 if (result) {
720 dev_err(&st->client->dev, "IIO register fail %d\n", result);
721 goto out_remove_trigger;
722 }
723
724 return 0;
725
726out_remove_trigger:
727 inv_mpu6050_remove_trigger(st);
728out_unreg_ring:
729 iio_triggered_buffer_cleanup(indio_dev);
730out_free:
731 iio_device_free(indio_dev);
732out_no_free:
733
734 return result;
735}
736
737static int inv_mpu_remove(struct i2c_client *client)
738{
739 struct iio_dev *indio_dev = i2c_get_clientdata(client);
740 struct inv_mpu6050_state *st = iio_priv(indio_dev);
741
742 iio_device_unregister(indio_dev);
743 inv_mpu6050_remove_trigger(st);
744 iio_triggered_buffer_cleanup(indio_dev);
745 iio_device_free(indio_dev);
746
747 return 0;
748}
749#ifdef CONFIG_PM_SLEEP
750
751static int inv_mpu_resume(struct device *dev)
752{
753 return inv_mpu6050_set_power_itg(
754 iio_priv(i2c_get_clientdata(to_i2c_client(dev))), true);
755}
756
757static int inv_mpu_suspend(struct device *dev)
758{
759 return inv_mpu6050_set_power_itg(
760 iio_priv(i2c_get_clientdata(to_i2c_client(dev))), false);
761}
762static SIMPLE_DEV_PM_OPS(inv_mpu_pmops, inv_mpu_suspend, inv_mpu_resume);
763
764#define INV_MPU6050_PMOPS (&inv_mpu_pmops)
765#else
766#define INV_MPU6050_PMOPS NULL
767#endif /* CONFIG_PM_SLEEP */
768
769/*
770 * device id table is used to identify what device can be
771 * supported by this driver
772 */
773static const struct i2c_device_id inv_mpu_id[] = {
774 {"mpu6050", INV_MPU6050},
775 {}
776};
777
778MODULE_DEVICE_TABLE(i2c, inv_mpu_id);
779
780static struct i2c_driver inv_mpu_driver = {
781 .probe = inv_mpu_probe,
782 .remove = inv_mpu_remove,
783 .id_table = inv_mpu_id,
784 .driver = {
785 .owner = THIS_MODULE,
786 .name = "inv-mpu6050",
787 .pm = INV_MPU6050_PMOPS,
788 },
789};
790
791module_i2c_driver(inv_mpu_driver);
792
793MODULE_AUTHOR("Invensense Corporation");
794MODULE_DESCRIPTION("Invensense device MPU6050 driver");
795MODULE_LICENSE("GPL");
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
new file mode 100644
index 000000000000..f38395529a44
--- /dev/null
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -0,0 +1,246 @@
1/*
2* Copyright (C) 2012 Invensense, Inc.
3*
4* This software is licensed under the terms of the GNU General Public
5* License version 2, as published by the Free Software Foundation, and
6* may be copied, distributed, and modified under those terms.
7*
8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*/
13#include <linux/i2c.h>
14#include <linux/kfifo.h>
15#include <linux/spinlock.h>
16#include <linux/iio/iio.h>
17#include <linux/iio/buffer.h>
18#include <linux/iio/sysfs.h>
19#include <linux/iio/kfifo_buf.h>
20#include <linux/iio/trigger.h>
21#include <linux/iio/triggered_buffer.h>
22#include <linux/iio/trigger_consumer.h>
23#include <linux/platform_data/invensense_mpu6050.h>
24
25/**
26 * struct inv_mpu6050_reg_map - Notable registers.
27 * @sample_rate_div: Divider applied to gyro output rate.
28 * @lpf: Configures internal low pass filter.
29 * @user_ctrl: Enables/resets the FIFO.
30 * @fifo_en: Determines which data will appear in FIFO.
31 * @gyro_config: gyro config register.
32 * @accl_config: accel config register
33 * @fifo_count_h: Upper byte of FIFO count.
34 * @fifo_r_w: FIFO register.
35 * @raw_gyro: Address of first gyro register.
36 * @raw_accl: Address of first accel register.
37 * @temperature: temperature register
38 * @int_enable: Interrupt enable register.
39 * @pwr_mgmt_1: Controls chip's power state and clock source.
40 * @pwr_mgmt_2: Controls power state of individual sensors.
41 */
42struct inv_mpu6050_reg_map {
43 u8 sample_rate_div;
44 u8 lpf;
45 u8 user_ctrl;
46 u8 fifo_en;
47 u8 gyro_config;
48 u8 accl_config;
49 u8 fifo_count_h;
50 u8 fifo_r_w;
51 u8 raw_gyro;
52 u8 raw_accl;
53 u8 temperature;
54 u8 int_enable;
55 u8 pwr_mgmt_1;
56 u8 pwr_mgmt_2;
57};
58
59/*device enum */
60enum inv_devices {
61 INV_MPU6050,
62 INV_NUM_PARTS
63};
64
65/**
66 * struct inv_mpu6050_chip_config - Cached chip configuration data.
67 * @fsr: Full scale range.
68 * @lpf: Digital low pass filter frequency.
69 * @accl_fs: accel full scale range.
70 * @enable: master enable state.
71 * @accl_fifo_enable: enable accel data output
72 * @gyro_fifo_enable: enable gyro data output
73 * @fifo_rate: FIFO update rate.
74 */
75struct inv_mpu6050_chip_config {
76 unsigned int fsr:2;
77 unsigned int lpf:3;
78 unsigned int accl_fs:2;
79 unsigned int enable:1;
80 unsigned int accl_fifo_enable:1;
81 unsigned int gyro_fifo_enable:1;
82 u16 fifo_rate;
83};
84
85/**
86 * struct inv_mpu6050_hw - Other important hardware information.
87 * @num_reg: Number of registers on device.
88 * @name: name of the chip.
89 * @reg: register map of the chip.
90 * @config: configuration of the chip.
91 */
92struct inv_mpu6050_hw {
93 u8 num_reg;
94 u8 *name;
95 const struct inv_mpu6050_reg_map *reg;
96 const struct inv_mpu6050_chip_config *config;
97};
98
99/*
100 * struct inv_mpu6050_state - Driver state variables.
101 * @TIMESTAMP_FIFO_SIZE: fifo size for timestamp.
102 * @trig: IIO trigger.
103 * @chip_config: Cached attribute information.
104 * @reg: Map of important registers.
105 * @hw: Other hardware-specific information.
106 * @chip_type: chip type.
107 * @time_stamp_lock: spin lock to time stamp.
108 * @client: i2c client handle.
109 * @plat_data: platform data.
110 * @timestamps: kfifo queue to store time stamp.
111 */
112struct inv_mpu6050_state {
113#define TIMESTAMP_FIFO_SIZE 16
114 struct iio_trigger *trig;
115 struct inv_mpu6050_chip_config chip_config;
116 const struct inv_mpu6050_reg_map *reg;
117 const struct inv_mpu6050_hw *hw;
118 enum inv_devices chip_type;
119 spinlock_t time_stamp_lock;
120 struct i2c_client *client;
121 struct inv_mpu6050_platform_data plat_data;
122 DECLARE_KFIFO(timestamps, long long, TIMESTAMP_FIFO_SIZE);
123};
124
125/*register and associated bit definition*/
126#define INV_MPU6050_REG_SAMPLE_RATE_DIV 0x19
127#define INV_MPU6050_REG_CONFIG 0x1A
128#define INV_MPU6050_REG_GYRO_CONFIG 0x1B
129#define INV_MPU6050_REG_ACCEL_CONFIG 0x1C
130
131#define INV_MPU6050_REG_FIFO_EN 0x23
132#define INV_MPU6050_BIT_ACCEL_OUT 0x08
133#define INV_MPU6050_BITS_GYRO_OUT 0x70
134
135#define INV_MPU6050_REG_INT_ENABLE 0x38
136#define INV_MPU6050_BIT_DATA_RDY_EN 0x01
137#define INV_MPU6050_BIT_DMP_INT_EN 0x02
138
139#define INV_MPU6050_REG_RAW_ACCEL 0x3B
140#define INV_MPU6050_REG_TEMPERATURE 0x41
141#define INV_MPU6050_REG_RAW_GYRO 0x43
142
143#define INV_MPU6050_REG_USER_CTRL 0x6A
144#define INV_MPU6050_BIT_FIFO_RST 0x04
145#define INV_MPU6050_BIT_DMP_RST 0x08
146#define INV_MPU6050_BIT_I2C_MST_EN 0x20
147#define INV_MPU6050_BIT_FIFO_EN 0x40
148#define INV_MPU6050_BIT_DMP_EN 0x80
149
150#define INV_MPU6050_REG_PWR_MGMT_1 0x6B
151#define INV_MPU6050_BIT_H_RESET 0x80
152#define INV_MPU6050_BIT_SLEEP 0x40
153#define INV_MPU6050_BIT_CLK_MASK 0x7
154
155#define INV_MPU6050_REG_PWR_MGMT_2 0x6C
156#define INV_MPU6050_BIT_PWR_ACCL_STBY 0x38
157#define INV_MPU6050_BIT_PWR_GYRO_STBY 0x07
158
159#define INV_MPU6050_REG_FIFO_COUNT_H 0x72
160#define INV_MPU6050_REG_FIFO_R_W 0x74
161
162#define INV_MPU6050_BYTES_PER_3AXIS_SENSOR 6
163#define INV_MPU6050_FIFO_COUNT_BYTE 2
164#define INV_MPU6050_FIFO_THRESHOLD 500
165#define INV_MPU6050_POWER_UP_TIME 100
166#define INV_MPU6050_TEMP_UP_TIME 100
167#define INV_MPU6050_SENSOR_UP_TIME 30
168#define INV_MPU6050_REG_UP_TIME 5
169
170#define INV_MPU6050_TEMP_OFFSET 12421
171#define INV_MPU6050_TEMP_SCALE 2941
172#define INV_MPU6050_MAX_GYRO_FS_PARAM 3
173#define INV_MPU6050_MAX_ACCL_FS_PARAM 3
174#define INV_MPU6050_THREE_AXIS 3
175#define INV_MPU6050_GYRO_CONFIG_FSR_SHIFT 3
176#define INV_MPU6050_ACCL_CONFIG_FSR_SHIFT 3
177
178/* 6 + 6 round up and plus 8 */
179#define INV_MPU6050_OUTPUT_DATA_SIZE 24
180
181/* init parameters */
182#define INV_MPU6050_INIT_FIFO_RATE 50
183#define INV_MPU6050_TIME_STAMP_TOR 5
184#define INV_MPU6050_MAX_FIFO_RATE 1000
185#define INV_MPU6050_MIN_FIFO_RATE 4
186#define INV_MPU6050_ONE_K_HZ 1000
187
188/* scan element definition */
189enum inv_mpu6050_scan {
190 INV_MPU6050_SCAN_ACCL_X,
191 INV_MPU6050_SCAN_ACCL_Y,
192 INV_MPU6050_SCAN_ACCL_Z,
193 INV_MPU6050_SCAN_GYRO_X,
194 INV_MPU6050_SCAN_GYRO_Y,
195 INV_MPU6050_SCAN_GYRO_Z,
196 INV_MPU6050_SCAN_TIMESTAMP,
197};
198
199enum inv_mpu6050_filter_e {
200 INV_MPU6050_FILTER_256HZ_NOLPF2 = 0,
201 INV_MPU6050_FILTER_188HZ,
202 INV_MPU6050_FILTER_98HZ,
203 INV_MPU6050_FILTER_42HZ,
204 INV_MPU6050_FILTER_20HZ,
205 INV_MPU6050_FILTER_10HZ,
206 INV_MPU6050_FILTER_5HZ,
207 INV_MPU6050_FILTER_2100HZ_NOLPF,
208 NUM_MPU6050_FILTER
209};
210
211/* IIO attribute address */
212enum INV_MPU6050_IIO_ATTR_ADDR {
213 ATTR_GYRO_MATRIX,
214 ATTR_ACCL_MATRIX,
215};
216
217enum inv_mpu6050_accl_fs_e {
218 INV_MPU6050_FS_02G = 0,
219 INV_MPU6050_FS_04G,
220 INV_MPU6050_FS_08G,
221 INV_MPU6050_FS_16G,
222 NUM_ACCL_FSR
223};
224
225enum inv_mpu6050_fsr_e {
226 INV_MPU6050_FSR_250DPS = 0,
227 INV_MPU6050_FSR_500DPS,
228 INV_MPU6050_FSR_1000DPS,
229 INV_MPU6050_FSR_2000DPS,
230 NUM_MPU6050_FSR
231};
232
233enum inv_mpu6050_clock_sel_e {
234 INV_CLK_INTERNAL = 0,
235 INV_CLK_PLL,
236 NUM_CLK
237};
238
239irqreturn_t inv_mpu6050_irq_handler(int irq, void *p);
240irqreturn_t inv_mpu6050_read_fifo(int irq, void *p);
241int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev);
242void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st);
243int inv_reset_fifo(struct iio_dev *indio_dev);
244int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask);
245int inv_mpu6050_write_reg(struct inv_mpu6050_state *st, int reg, u8 val);
246int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on);
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
new file mode 100644
index 000000000000..331781ffbb15
--- /dev/null
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c
@@ -0,0 +1,196 @@
1/*
2* Copyright (C) 2012 Invensense, Inc.
3*
4* This software is licensed under the terms of the GNU General Public
5* License version 2, as published by the Free Software Foundation, and
6* may be copied, distributed, and modified under those terms.
7*
8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*/
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/slab.h>
17#include <linux/i2c.h>
18#include <linux/err.h>
19#include <linux/delay.h>
20#include <linux/sysfs.h>
21#include <linux/jiffies.h>
22#include <linux/irq.h>
23#include <linux/interrupt.h>
24#include <linux/kfifo.h>
25#include <linux/poll.h>
26#include "inv_mpu_iio.h"
27
28int inv_reset_fifo(struct iio_dev *indio_dev)
29{
30 int result;
31 u8 d;
32 struct inv_mpu6050_state *st = iio_priv(indio_dev);
33
34 /* disable interrupt */
35 result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0);
36 if (result) {
37 dev_err(&st->client->dev, "int_enable failed %d\n", result);
38 return result;
39 }
40 /* disable the sensor output to FIFO */
41 result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0);
42 if (result)
43 goto reset_fifo_fail;
44 /* disable fifo reading */
45 result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0);
46 if (result)
47 goto reset_fifo_fail;
48
49 /* reset FIFO*/
50 result = inv_mpu6050_write_reg(st, st->reg->user_ctrl,
51 INV_MPU6050_BIT_FIFO_RST);
52 if (result)
53 goto reset_fifo_fail;
54 /* enable interrupt */
55 if (st->chip_config.accl_fifo_enable ||
56 st->chip_config.gyro_fifo_enable) {
57 result = inv_mpu6050_write_reg(st, st->reg->int_enable,
58 INV_MPU6050_BIT_DATA_RDY_EN);
59 if (result)
60 return result;
61 }
62 /* enable FIFO reading and I2C master interface*/
63 result = inv_mpu6050_write_reg(st, st->reg->user_ctrl,
64 INV_MPU6050_BIT_FIFO_EN);
65 if (result)
66 goto reset_fifo_fail;
67 /* enable sensor output to FIFO */
68 d = 0;
69 if (st->chip_config.gyro_fifo_enable)
70 d |= INV_MPU6050_BITS_GYRO_OUT;
71 if (st->chip_config.accl_fifo_enable)
72 d |= INV_MPU6050_BIT_ACCEL_OUT;
73 result = inv_mpu6050_write_reg(st, st->reg->fifo_en, d);
74 if (result)
75 goto reset_fifo_fail;
76
77 return 0;
78
79reset_fifo_fail:
80 dev_err(&st->client->dev, "reset fifo failed %d\n", result);
81 result = inv_mpu6050_write_reg(st, st->reg->int_enable,
82 INV_MPU6050_BIT_DATA_RDY_EN);
83
84 return result;
85}
86
87static void inv_clear_kfifo(struct inv_mpu6050_state *st)
88{
89 unsigned long flags;
90
91 /* take the spin lock sem to avoid interrupt kick in */
92 spin_lock_irqsave(&st->time_stamp_lock, flags);
93 kfifo_reset(&st->timestamps);
94 spin_unlock_irqrestore(&st->time_stamp_lock, flags);
95}
96
97/**
98 * inv_mpu6050_irq_handler() - Cache a timestamp at each data ready interrupt.
99 */
100irqreturn_t inv_mpu6050_irq_handler(int irq, void *p)
101{
102 struct iio_poll_func *pf = p;
103 struct iio_dev *indio_dev = pf->indio_dev;
104 struct inv_mpu6050_state *st = iio_priv(indio_dev);
105 s64 timestamp;
106
107 timestamp = iio_get_time_ns();
108 spin_lock(&st->time_stamp_lock);
109 kfifo_in(&st->timestamps, &timestamp, 1);
110 spin_unlock(&st->time_stamp_lock);
111
112 return IRQ_WAKE_THREAD;
113}
114
115/**
116 * inv_mpu6050_read_fifo() - Transfer data from hardware FIFO to KFIFO.
117 */
118irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
119{
120 struct iio_poll_func *pf = p;
121 struct iio_dev *indio_dev = pf->indio_dev;
122 struct inv_mpu6050_state *st = iio_priv(indio_dev);
123 size_t bytes_per_datum;
124 int result;
125 u8 data[INV_MPU6050_OUTPUT_DATA_SIZE];
126 u16 fifo_count;
127 s64 timestamp;
128 u64 *tmp;
129
130 mutex_lock(&indio_dev->mlock);
131 if (!(st->chip_config.accl_fifo_enable |
132 st->chip_config.gyro_fifo_enable))
133 goto end_session;
134 bytes_per_datum = 0;
135 if (st->chip_config.accl_fifo_enable)
136 bytes_per_datum += INV_MPU6050_BYTES_PER_3AXIS_SENSOR;
137
138 if (st->chip_config.gyro_fifo_enable)
139 bytes_per_datum += INV_MPU6050_BYTES_PER_3AXIS_SENSOR;
140
141 /*
142 * read fifo_count register to know how many bytes inside FIFO
143 * right now
144 */
145 result = i2c_smbus_read_i2c_block_data(st->client,
146 st->reg->fifo_count_h,
147 INV_MPU6050_FIFO_COUNT_BYTE, data);
148 if (result != INV_MPU6050_FIFO_COUNT_BYTE)
149 goto end_session;
150 fifo_count = be16_to_cpup((__be16 *)(&data[0]));
151 if (fifo_count < bytes_per_datum)
152 goto end_session;
153 /* fifo count can't be odd number, if it is odd, reset fifo*/
154 if (fifo_count & 1)
155 goto flush_fifo;
156 if (fifo_count > INV_MPU6050_FIFO_THRESHOLD)
157 goto flush_fifo;
158 /* Timestamp mismatch. */
159 if (kfifo_len(&st->timestamps) >
160 fifo_count / bytes_per_datum + INV_MPU6050_TIME_STAMP_TOR)
161 goto flush_fifo;
162 while (fifo_count >= bytes_per_datum) {
163 result = i2c_smbus_read_i2c_block_data(st->client,
164 st->reg->fifo_r_w,
165 bytes_per_datum, data);
166 if (result != bytes_per_datum)
167 goto flush_fifo;
168
169 result = kfifo_out(&st->timestamps, &timestamp, 1);
170 /* when there is no timestamp, put timestamp as 0 */
171 if (0 == result)
172 timestamp = 0;
173
174 tmp = (u64 *)data;
175 tmp[DIV_ROUND_UP(bytes_per_datum, 8)] = timestamp;
176 result = iio_push_to_buffers(indio_dev, data);
177 if (result)
178 goto flush_fifo;
179 fifo_count -= bytes_per_datum;
180 }
181
182end_session:
183 mutex_unlock(&indio_dev->mlock);
184 iio_trigger_notify_done(indio_dev->trig);
185
186 return IRQ_HANDLED;
187
188flush_fifo:
189 /* Flush HW and SW FIFOs. */
190 inv_reset_fifo(indio_dev);
191 inv_clear_kfifo(st);
192 mutex_unlock(&indio_dev->mlock);
193 iio_trigger_notify_done(indio_dev->trig);
194
195 return IRQ_HANDLED;
196}
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
new file mode 100644
index 000000000000..e1d0869e0ad1
--- /dev/null
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c
@@ -0,0 +1,155 @@
1/*
2* Copyright (C) 2012 Invensense, Inc.
3*
4* This software is licensed under the terms of the GNU General Public
5* License version 2, as published by the Free Software Foundation, and
6* may be copied, distributed, and modified under those terms.
7*
8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*/
13
14#include "inv_mpu_iio.h"
15
16static void inv_scan_query(struct iio_dev *indio_dev)
17{
18 struct inv_mpu6050_state *st = iio_priv(indio_dev);
19
20 st->chip_config.gyro_fifo_enable =
21 test_bit(INV_MPU6050_SCAN_GYRO_X,
22 indio_dev->active_scan_mask) ||
23 test_bit(INV_MPU6050_SCAN_GYRO_Y,
24 indio_dev->active_scan_mask) ||
25 test_bit(INV_MPU6050_SCAN_GYRO_Z,
26 indio_dev->active_scan_mask);
27
28 st->chip_config.accl_fifo_enable =
29 test_bit(INV_MPU6050_SCAN_ACCL_X,
30 indio_dev->active_scan_mask) ||
31 test_bit(INV_MPU6050_SCAN_ACCL_Y,
32 indio_dev->active_scan_mask) ||
33 test_bit(INV_MPU6050_SCAN_ACCL_Z,
34 indio_dev->active_scan_mask);
35}
36
37/**
38 * inv_mpu6050_set_enable() - enable chip functions.
39 * @indio_dev: Device driver instance.
40 * @enable: enable/disable
41 */
42static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
43{
44 struct inv_mpu6050_state *st = iio_priv(indio_dev);
45 int result;
46
47 if (enable) {
48 result = inv_mpu6050_set_power_itg(st, true);
49 if (result)
50 return result;
51 inv_scan_query(indio_dev);
52 if (st->chip_config.gyro_fifo_enable) {
53 result = inv_mpu6050_switch_engine(st, true,
54 INV_MPU6050_BIT_PWR_GYRO_STBY);
55 if (result)
56 return result;
57 }
58 if (st->chip_config.accl_fifo_enable) {
59 result = inv_mpu6050_switch_engine(st, true,
60 INV_MPU6050_BIT_PWR_ACCL_STBY);
61 if (result)
62 return result;
63 }
64 result = inv_reset_fifo(indio_dev);
65 if (result)
66 return result;
67 } else {
68 result = inv_mpu6050_write_reg(st, st->reg->fifo_en, 0);
69 if (result)
70 return result;
71
72 result = inv_mpu6050_write_reg(st, st->reg->int_enable, 0);
73 if (result)
74 return result;
75
76 result = inv_mpu6050_write_reg(st, st->reg->user_ctrl, 0);
77 if (result)
78 return result;
79
80 result = inv_mpu6050_switch_engine(st, false,
81 INV_MPU6050_BIT_PWR_GYRO_STBY);
82 if (result)
83 return result;
84
85 result = inv_mpu6050_switch_engine(st, false,
86 INV_MPU6050_BIT_PWR_ACCL_STBY);
87 if (result)
88 return result;
89 result = inv_mpu6050_set_power_itg(st, false);
90 if (result)
91 return result;
92 }
93 st->chip_config.enable = enable;
94
95 return 0;
96}
97
98/**
99 * inv_mpu_data_rdy_trigger_set_state() - set data ready interrupt state
100 * @trig: Trigger instance
101 * @state: Desired trigger state
102 */
103static int inv_mpu_data_rdy_trigger_set_state(struct iio_trigger *trig,
104 bool state)
105{
106 return inv_mpu6050_set_enable(trig->private_data, state);
107}
108
109static const struct iio_trigger_ops inv_mpu_trigger_ops = {
110 .owner = THIS_MODULE,
111 .set_trigger_state = &inv_mpu_data_rdy_trigger_set_state,
112};
113
114int inv_mpu6050_probe_trigger(struct iio_dev *indio_dev)
115{
116 int ret;
117 struct inv_mpu6050_state *st = iio_priv(indio_dev);
118
119 st->trig = iio_trigger_alloc("%s-dev%d",
120 indio_dev->name,
121 indio_dev->id);
122 if (st->trig == NULL) {
123 ret = -ENOMEM;
124 goto error_ret;
125 }
126 ret = request_irq(st->client->irq, &iio_trigger_generic_data_rdy_poll,
127 IRQF_TRIGGER_RISING,
128 "inv_mpu",
129 st->trig);
130 if (ret)
131 goto error_free_trig;
132 st->trig->dev.parent = &st->client->dev;
133 st->trig->private_data = indio_dev;
134 st->trig->ops = &inv_mpu_trigger_ops;
135 ret = iio_trigger_register(st->trig);
136 if (ret)
137 goto error_free_irq;
138 indio_dev->trig = st->trig;
139
140 return 0;
141
142error_free_irq:
143 free_irq(st->client->irq, st->trig);
144error_free_trig:
145 iio_trigger_free(st->trig);
146error_ret:
147 return ret;
148}
149
150void inv_mpu6050_remove_trigger(struct inv_mpu6050_state *st)
151{
152 iio_trigger_unregister(st->trig);
153 free_irq(st->client->irq, st->trig);
154 iio_trigger_free(st->trig);
155}
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 4fe0ead84213..4d6c7d84e155 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -160,7 +160,7 @@ void iio_trigger_notify_done(struct iio_trigger *trig)
160 trig->use_count--; 160 trig->use_count--;
161 if (trig->use_count == 0 && trig->ops && trig->ops->try_reenable) 161 if (trig->use_count == 0 && trig->ops && trig->ops->try_reenable)
162 if (trig->ops->try_reenable(trig)) 162 if (trig->ops->try_reenable(trig))
163 /* Missed and interrupt so launch new poll now */ 163 /* Missed an interrupt so launch new poll now */
164 iio_trigger_poll(trig, 0); 164 iio_trigger_poll(trig, 0);
165} 165}
166EXPORT_SYMBOL(iio_trigger_notify_done); 166EXPORT_SYMBOL(iio_trigger_notify_done);
@@ -193,7 +193,7 @@ static void iio_trigger_put_irq(struct iio_trigger *trig, int irq)
193 * This is not currently handled. Alternative of not enabling trigger unless 193 * This is not currently handled. Alternative of not enabling trigger unless
194 * the relevant function is in there may be the best option. 194 * the relevant function is in there may be the best option.
195 */ 195 */
196/* Worth protecting against double additions?*/ 196/* Worth protecting against double additions? */
197static int iio_trigger_attach_poll_func(struct iio_trigger *trig, 197static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
198 struct iio_poll_func *pf) 198 struct iio_poll_func *pf)
199{ 199{
@@ -201,7 +201,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
201 bool notinuse 201 bool notinuse
202 = bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER); 202 = bitmap_empty(trig->pool, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
203 203
204 /* Prevent the module being removed whilst attached to a trigger */ 204 /* Prevent the module from being removed whilst attached to a trigger */
205 __module_get(pf->indio_dev->info->driver_module); 205 __module_get(pf->indio_dev->info->driver_module);
206 pf->irq = iio_trigger_get_irq(trig); 206 pf->irq = iio_trigger_get_irq(trig);
207 ret = request_threaded_irq(pf->irq, pf->h, pf->thread, 207 ret = request_threaded_irq(pf->irq, pf->h, pf->thread,
@@ -288,7 +288,7 @@ void iio_dealloc_pollfunc(struct iio_poll_func *pf)
288EXPORT_SYMBOL_GPL(iio_dealloc_pollfunc); 288EXPORT_SYMBOL_GPL(iio_dealloc_pollfunc);
289 289
290/** 290/**
291 * iio_trigger_read_current() - trigger consumer sysfs query which trigger 291 * iio_trigger_read_current() - trigger consumer sysfs query current trigger
292 * 292 *
293 * For trigger consumers the current_trigger interface allows the trigger 293 * For trigger consumers the current_trigger interface allows the trigger
294 * used by the device to be queried. 294 * used by the device to be queried.
@@ -305,7 +305,7 @@ static ssize_t iio_trigger_read_current(struct device *dev,
305} 305}
306 306
307/** 307/**
308 * iio_trigger_write_current() trigger consumer sysfs set current trigger 308 * iio_trigger_write_current() - trigger consumer sysfs set current trigger
309 * 309 *
310 * For trigger consumers the current_trigger interface allows the trigger 310 * For trigger consumers the current_trigger interface allows the trigger
311 * used for this device to be specified at run time based on the triggers 311 * used for this device to be specified at run time based on the triggers
@@ -476,7 +476,7 @@ void iio_device_register_trigger_consumer(struct iio_dev *indio_dev)
476 476
477void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev) 477void iio_device_unregister_trigger_consumer(struct iio_dev *indio_dev)
478{ 478{
479 /* Clean up and associated but not attached triggers references */ 479 /* Clean up an associated but not attached trigger reference */
480 if (indio_dev->trig) 480 if (indio_dev->trig)
481 iio_trigger_put(indio_dev->trig); 481 iio_trigger_put(indio_dev->trig);
482} 482}
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index d55e98fb300e..b289915b8469 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -54,39 +54,25 @@ error_ret:
54EXPORT_SYMBOL_GPL(iio_map_array_register); 54EXPORT_SYMBOL_GPL(iio_map_array_register);
55 55
56 56
57/* Assumes the exact same array (e.g. memory locations) 57/*
58 * used at unregistration as used at registration rather than 58 * Remove all map entries associated with the given iio device
59 * more complex checking of contents.
60 */ 59 */
61int iio_map_array_unregister(struct iio_dev *indio_dev, 60int iio_map_array_unregister(struct iio_dev *indio_dev)
62 struct iio_map *maps)
63{ 61{
64 int i = 0, ret = 0; 62 int ret = -ENODEV;
65 bool found_it;
66 struct iio_map_internal *mapi; 63 struct iio_map_internal *mapi;
67 64 struct list_head *pos, *tmp;
68 if (maps == NULL)
69 return 0;
70 65
71 mutex_lock(&iio_map_list_lock); 66 mutex_lock(&iio_map_list_lock);
72 while (maps[i].consumer_dev_name != NULL) { 67 list_for_each_safe(pos, tmp, &iio_map_list) {
73 found_it = false; 68 mapi = list_entry(pos, struct iio_map_internal, l);
74 list_for_each_entry(mapi, &iio_map_list, l) 69 if (indio_dev == mapi->indio_dev) {
75 if (&maps[i] == mapi->map) { 70 list_del(&mapi->l);
76 list_del(&mapi->l); 71 kfree(mapi);
77 kfree(mapi); 72 ret = 0;
78 found_it = true;
79 break;
80 }
81 if (!found_it) {
82 ret = -ENODEV;
83 goto error_ret;
84 } 73 }
85 i++;
86 } 74 }
87error_ret:
88 mutex_unlock(&iio_map_list_lock); 75 mutex_unlock(&iio_map_list_lock);
89
90 return ret; 76 return ret;
91} 77}
92EXPORT_SYMBOL_GPL(iio_map_array_unregister); 78EXPORT_SYMBOL_GPL(iio_map_array_unregister);
@@ -107,7 +93,8 @@ static const struct iio_chan_spec
107} 93}
108 94
109 95
110struct iio_channel *iio_channel_get(const char *name, const char *channel_name) 96static struct iio_channel *iio_channel_get_sys(const char *name,
97 const char *channel_name)
111{ 98{
112 struct iio_map_internal *c_i = NULL, *c = NULL; 99 struct iio_map_internal *c_i = NULL, *c = NULL;
113 struct iio_channel *channel; 100 struct iio_channel *channel;
@@ -158,6 +145,14 @@ error_no_mem:
158 iio_device_put(c->indio_dev); 145 iio_device_put(c->indio_dev);
159 return ERR_PTR(err); 146 return ERR_PTR(err);
160} 147}
148
149struct iio_channel *iio_channel_get(struct device *dev,
150 const char *channel_name)
151{
152 const char *name = dev ? dev_name(dev) : NULL;
153
154 return iio_channel_get_sys(name, channel_name);
155}
161EXPORT_SYMBOL_GPL(iio_channel_get); 156EXPORT_SYMBOL_GPL(iio_channel_get);
162 157
163void iio_channel_release(struct iio_channel *channel) 158void iio_channel_release(struct iio_channel *channel)
@@ -167,16 +162,18 @@ void iio_channel_release(struct iio_channel *channel)
167} 162}
168EXPORT_SYMBOL_GPL(iio_channel_release); 163EXPORT_SYMBOL_GPL(iio_channel_release);
169 164
170struct iio_channel *iio_channel_get_all(const char *name) 165struct iio_channel *iio_channel_get_all(struct device *dev)
171{ 166{
167 const char *name;
172 struct iio_channel *chans; 168 struct iio_channel *chans;
173 struct iio_map_internal *c = NULL; 169 struct iio_map_internal *c = NULL;
174 int nummaps = 0; 170 int nummaps = 0;
175 int mapind = 0; 171 int mapind = 0;
176 int i, ret; 172 int i, ret;
177 173
178 if (name == NULL) 174 if (dev == NULL)
179 return ERR_PTR(-EINVAL); 175 return ERR_PTR(-EINVAL);
176 name = dev_name(dev);
180 177
181 mutex_lock(&iio_map_list_lock); 178 mutex_lock(&iio_map_list_lock);
182 /* first count the matching maps */ 179 /* first count the matching maps */
diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
index 5bc5c860e9ca..a923c78d5cb4 100644
--- a/drivers/iio/kfifo_buf.c
+++ b/drivers/iio/kfifo_buf.c
@@ -22,7 +22,6 @@ static inline int __iio_allocate_kfifo(struct iio_kfifo *buf,
22 if ((length == 0) || (bytes_per_datum == 0)) 22 if ((length == 0) || (bytes_per_datum == 0))
23 return -EINVAL; 23 return -EINVAL;
24 24
25 __iio_update_buffer(&buf->buffer, bytes_per_datum, length);
26 return __kfifo_alloc((struct __kfifo *)&buf->kf, length, 25 return __kfifo_alloc((struct __kfifo *)&buf->kf, length,
27 bytes_per_datum, GFP_KERNEL); 26 bytes_per_datum, GFP_KERNEL);
28} 27}
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index dbf80abc834f..5ef1a396e0c9 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -32,6 +32,16 @@ config SENSORS_LM3533
32 changes. The ALS-control output values can be set per zone for the 32 changes. The ALS-control output values can be set per zone for the
33 three current output channels. 33 three current output channels.
34 34
35config SENSORS_TSL2563
36 tristate "TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light sensors"
37 depends on I2C
38 help
39 If you say yes here you get support for the Taos TSL2560,
40 TSL2561, TSL2562 and TSL2563 ambient light sensors.
41
42 This driver can also be built as a module. If so, the module
43 will be called tsl2563.
44
35config VCNL4000 45config VCNL4000
36 tristate "VCNL4000 combined ALS and proximity sensor" 46 tristate "VCNL4000 combined ALS and proximity sensor"
37 depends on I2C 47 depends on I2C
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index 21a8f0df1407..040d9c75f8e6 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -4,5 +4,6 @@
4 4
5obj-$(CONFIG_ADJD_S311) += adjd_s311.o 5obj-$(CONFIG_ADJD_S311) += adjd_s311.o
6obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o 6obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o
7obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o
7obj-$(CONFIG_VCNL4000) += vcnl4000.o 8obj-$(CONFIG_VCNL4000) += vcnl4000.o
8obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o 9obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index e2d042f2a544..3d7e8c9b4beb 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -28,7 +28,6 @@
28#include <linux/iio/buffer.h> 28#include <linux/iio/buffer.h>
29#include <linux/iio/trigger_consumer.h> 29#include <linux/iio/trigger_consumer.h>
30#include <linux/iio/triggered_buffer.h> 30#include <linux/iio/triggered_buffer.h>
31#include "../common/hid-sensors/hid-sensor-attributes.h"
32#include "../common/hid-sensors/hid-sensor-trigger.h" 31#include "../common/hid-sensors/hid-sensor-trigger.h"
33 32
34/*Format: HID-SENSOR-usage_id_in_hex*/ 33/*Format: HID-SENSOR-usage_id_in_hex*/
@@ -39,7 +38,7 @@
39 38
40struct als_state { 39struct als_state {
41 struct hid_sensor_hub_callbacks callbacks; 40 struct hid_sensor_hub_callbacks callbacks;
42 struct hid_sensor_iio_common common_attributes; 41 struct hid_sensor_common common_attributes;
43 struct hid_sensor_hub_attribute_info als_illum; 42 struct hid_sensor_hub_attribute_info als_illum;
44 u32 illum; 43 u32 illum;
45}; 44};
diff --git a/drivers/staging/iio/light/tsl2563.c b/drivers/iio/light/tsl2563.c
index 1a9adc020f64..fd8be69b7d05 100644
--- a/drivers/staging/iio/light/tsl2563.c
+++ b/drivers/iio/light/tsl2563.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * drivers/i2c/chips/tsl2563.c 2 * drivers/iio/light/tsl2563.c
3 * 3 *
4 * Copyright (C) 2008 Nokia Corporation 4 * Copyright (C) 2008 Nokia Corporation
5 * 5 *
@@ -38,52 +38,52 @@
38#include <linux/iio/iio.h> 38#include <linux/iio/iio.h>
39#include <linux/iio/sysfs.h> 39#include <linux/iio/sysfs.h>
40#include <linux/iio/events.h> 40#include <linux/iio/events.h>
41#include "tsl2563.h" 41#include <linux/platform_data/tsl2563.h>
42 42
43/* Use this many bits for fraction part. */ 43/* Use this many bits for fraction part. */
44#define ADC_FRAC_BITS (14) 44#define ADC_FRAC_BITS 14
45 45
46/* Given number of 1/10000's in ADC_FRAC_BITS precision. */ 46/* Given number of 1/10000's in ADC_FRAC_BITS precision. */
47#define FRAC10K(f) (((f) * (1L << (ADC_FRAC_BITS))) / (10000)) 47#define FRAC10K(f) (((f) * (1L << (ADC_FRAC_BITS))) / (10000))
48 48
49/* Bits used for fraction in calibration coefficients.*/ 49/* Bits used for fraction in calibration coefficients.*/
50#define CALIB_FRAC_BITS (10) 50#define CALIB_FRAC_BITS 10
51/* 0.5 in CALIB_FRAC_BITS precision */ 51/* 0.5 in CALIB_FRAC_BITS precision */
52#define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1)) 52#define CALIB_FRAC_HALF (1 << (CALIB_FRAC_BITS - 1))
53/* Make a fraction from a number n that was multiplied with b. */ 53/* Make a fraction from a number n that was multiplied with b. */
54#define CALIB_FRAC(n, b) (((n) << CALIB_FRAC_BITS) / (b)) 54#define CALIB_FRAC(n, b) (((n) << CALIB_FRAC_BITS) / (b))
55/* Decimal 10^(digits in sysfs presentation) */ 55/* Decimal 10^(digits in sysfs presentation) */
56#define CALIB_BASE_SYSFS (1000) 56#define CALIB_BASE_SYSFS 1000
57 57
58#define TSL2563_CMD (0x80) 58#define TSL2563_CMD 0x80
59#define TSL2563_CLEARINT (0x40) 59#define TSL2563_CLEARINT 0x40
60 60
61#define TSL2563_REG_CTRL (0x00) 61#define TSL2563_REG_CTRL 0x00
62#define TSL2563_REG_TIMING (0x01) 62#define TSL2563_REG_TIMING 0x01
63#define TSL2563_REG_LOWLOW (0x02) /* data0 low threshold, 2 bytes */ 63#define TSL2563_REG_LOWLOW 0x02 /* data0 low threshold, 2 bytes */
64#define TSL2563_REG_LOWHIGH (0x03) 64#define TSL2563_REG_LOWHIGH 0x03
65#define TSL2563_REG_HIGHLOW (0x04) /* data0 high threshold, 2 bytes */ 65#define TSL2563_REG_HIGHLOW 0x04 /* data0 high threshold, 2 bytes */
66#define TSL2563_REG_HIGHHIGH (0x05) 66#define TSL2563_REG_HIGHHIGH 0x05
67#define TSL2563_REG_INT (0x06) 67#define TSL2563_REG_INT 0x06
68#define TSL2563_REG_ID (0x0a) 68#define TSL2563_REG_ID 0x0a
69#define TSL2563_REG_DATA0LOW (0x0c) /* broadband sensor value, 2 bytes */ 69#define TSL2563_REG_DATA0LOW 0x0c /* broadband sensor value, 2 bytes */
70#define TSL2563_REG_DATA0HIGH (0x0d) 70#define TSL2563_REG_DATA0HIGH 0x0d
71#define TSL2563_REG_DATA1LOW (0x0e) /* infrared sensor value, 2 bytes */ 71#define TSL2563_REG_DATA1LOW 0x0e /* infrared sensor value, 2 bytes */
72#define TSL2563_REG_DATA1HIGH (0x0f) 72#define TSL2563_REG_DATA1HIGH 0x0f
73 73
74#define TSL2563_CMD_POWER_ON (0x03) 74#define TSL2563_CMD_POWER_ON 0x03
75#define TSL2563_CMD_POWER_OFF (0x00) 75#define TSL2563_CMD_POWER_OFF 0x00
76#define TSL2563_CTRL_POWER_MASK (0x03) 76#define TSL2563_CTRL_POWER_MASK 0x03
77 77
78#define TSL2563_TIMING_13MS (0x00) 78#define TSL2563_TIMING_13MS 0x00
79#define TSL2563_TIMING_100MS (0x01) 79#define TSL2563_TIMING_100MS 0x01
80#define TSL2563_TIMING_400MS (0x02) 80#define TSL2563_TIMING_400MS 0x02
81#define TSL2563_TIMING_MASK (0x03) 81#define TSL2563_TIMING_MASK 0x03
82#define TSL2563_TIMING_GAIN16 (0x10) 82#define TSL2563_TIMING_GAIN16 0x10
83#define TSL2563_TIMING_GAIN1 (0x00) 83#define TSL2563_TIMING_GAIN1 0x00
84 84
85#define TSL2563_INT_DISBLED (0x00) 85#define TSL2563_INT_DISBLED 0x00
86#define TSL2563_INT_LEVEL (0x10) 86#define TSL2563_INT_LEVEL 0x10
87#define TSL2563_INT_PERSIST(n) ((n) & 0x0F) 87#define TSL2563_INT_PERSIST(n) ((n) & 0x0F)
88 88
89struct tsl2563_gainlevel_coeff { 89struct tsl2563_gainlevel_coeff {
@@ -190,8 +190,10 @@ static int tsl2563_configure(struct tsl2563_chip *chip)
190 ret = i2c_smbus_write_byte_data(chip->client, 190 ret = i2c_smbus_write_byte_data(chip->client,
191 TSL2563_CMD | TSL2563_REG_LOWHIGH, 191 TSL2563_CMD | TSL2563_REG_LOWHIGH,
192 (chip->low_thres >> 8) & 0xFF); 192 (chip->low_thres >> 8) & 0xFF);
193/* Interrupt register is automatically written anyway if it is relevant 193/*
194 so is not here */ 194 * Interrupt register is automatically written anyway if it is relevant
195 * so is not here.
196 */
195error_ret: 197error_ret:
196 return ret; 198 return ret;
197} 199}
@@ -423,9 +425,7 @@ static const struct tsl2563_lux_coeff lux_table[] = {
423 }, 425 },
424}; 426};
425 427
426/* 428/* Convert normalized, scaled ADC values to lux. */
427 * Convert normalized, scaled ADC values to lux.
428 */
429static unsigned int adc_to_lux(u32 adc0, u32 adc1) 429static unsigned int adc_to_lux(u32 adc0, u32 adc1)
430{ 430{
431 const struct tsl2563_lux_coeff *lp = lux_table; 431 const struct tsl2563_lux_coeff *lp = lux_table;
@@ -441,11 +441,6 @@ static unsigned int adc_to_lux(u32 adc0, u32 adc1)
441 return (unsigned int) (lux >> ADC_FRAC_BITS); 441 return (unsigned int) (lux >> ADC_FRAC_BITS);
442} 442}
443 443
444/*--------------------------------------------------------------*/
445/* Sysfs interface */
446/*--------------------------------------------------------------*/
447
448
449/* Apply calibration coefficient to ADC count. */ 444/* Apply calibration coefficient to ADC count. */
450static u32 calib_adc(u32 adc, u32 calib) 445static u32 calib_adc(u32 adc, u32 calib)
451{ 446{
@@ -677,18 +672,11 @@ static int tsl2563_read_interrupt_config(struct iio_dev *indio_dev,
677 TSL2563_CMD | TSL2563_REG_INT); 672 TSL2563_CMD | TSL2563_REG_INT);
678 mutex_unlock(&chip->lock); 673 mutex_unlock(&chip->lock);
679 if (ret < 0) 674 if (ret < 0)
680 goto error_ret; 675 return ret;
681 ret = !!(ret & 0x30);
682error_ret:
683 676
684 return ret; 677 return !!(ret & 0x30);
685} 678}
686 679
687/*--------------------------------------------------------------*/
688/* Probe, Attach, Remove */
689/*--------------------------------------------------------------*/
690static struct i2c_driver tsl2563_i2c_driver;
691
692static const struct iio_info tsl2563_info_no_irq = { 680static const struct iio_info tsl2563_info_no_irq = {
693 .driver_module = THIS_MODULE, 681 .driver_module = THIS_MODULE,
694 .read_raw = &tsl2563_read_raw, 682 .read_raw = &tsl2563_read_raw,
diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
index ff11d68225cf..cd29be54f643 100644
--- a/drivers/iio/magnetometer/Kconfig
+++ b/drivers/iio/magnetometer/Kconfig
@@ -14,4 +14,34 @@ config HID_SENSOR_MAGNETOMETER_3D
14 Say yes here to build support for the HID SENSOR 14 Say yes here to build support for the HID SENSOR
15 Magnetometer 3D. 15 Magnetometer 3D.
16 16
17config IIO_ST_MAGN_3AXIS
18 tristate "STMicroelectronics magnetometers 3-Axis Driver"
19 depends on (I2C || SPI_MASTER) && SYSFS
20 select IIO_ST_SENSORS_CORE
21 select IIO_ST_MAGN_I2C_3AXIS if (I2C)
22 select IIO_ST_MAGN_SPI_3AXIS if (SPI_MASTER)
23 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
24 select IIO_ST_MAGN_BUFFER if (IIO_TRIGGERED_BUFFER)
25 help
26 Say yes here to build support for STMicroelectronics magnetometers:
27 LSM303DLHC, LSM303DLM, LIS3MDL.
28
29 This driver can also be built as a module. If so, will be created
30 these modules:
31 - st_magn (core functions for the driver [it is mandatory]);
32 - st_magn_i2c (necessary for the I2C devices [optional*]);
33 - st_magn_spi (necessary for the SPI devices [optional*]);
34
35 (*) one of these is necessary to do something.
36
37config IIO_ST_MAGN_I2C_3AXIS
38 tristate
39 depends on IIO_ST_MAGN_3AXIS
40 depends on IIO_ST_SENSORS_I2C
41
42config IIO_ST_MAGN_SPI_3AXIS
43 tristate
44 depends on IIO_ST_MAGN_3AXIS
45 depends on IIO_ST_SENSORS_SPI
46
17endmenu 47endmenu
diff --git a/drivers/iio/magnetometer/Makefile b/drivers/iio/magnetometer/Makefile
index 60dc4f2b1963..e78672876dc2 100644
--- a/drivers/iio/magnetometer/Makefile
+++ b/drivers/iio/magnetometer/Makefile
@@ -3,3 +3,10 @@
3# 3#
4 4
5obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o 5obj-$(CONFIG_HID_SENSOR_MAGNETOMETER_3D) += hid-sensor-magn-3d.o
6
7obj-$(CONFIG_IIO_ST_MAGN_3AXIS) += st_magn.o
8st_magn-y := st_magn_core.o
9st_magn-$(CONFIG_IIO_BUFFER) += st_magn_buffer.o
10
11obj-$(CONFIG_IIO_ST_MAGN_I2C_3AXIS) += st_magn_i2c.o
12obj-$(CONFIG_IIO_ST_MAGN_SPI_3AXIS) += st_magn_spi.o
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index 7ac2c7483ba8..d8d01265220b 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -28,7 +28,6 @@
28#include <linux/iio/buffer.h> 28#include <linux/iio/buffer.h>
29#include <linux/iio/trigger_consumer.h> 29#include <linux/iio/trigger_consumer.h>
30#include <linux/iio/triggered_buffer.h> 30#include <linux/iio/triggered_buffer.h>
31#include "../common/hid-sensors/hid-sensor-attributes.h"
32#include "../common/hid-sensors/hid-sensor-trigger.h" 31#include "../common/hid-sensors/hid-sensor-trigger.h"
33 32
34/*Format: HID-SENSOR-usage_id_in_hex*/ 33/*Format: HID-SENSOR-usage_id_in_hex*/
@@ -44,7 +43,7 @@ enum magn_3d_channel {
44 43
45struct magn_3d_state { 44struct magn_3d_state {
46 struct hid_sensor_hub_callbacks callbacks; 45 struct hid_sensor_hub_callbacks callbacks;
47 struct hid_sensor_iio_common common_attributes; 46 struct hid_sensor_common common_attributes;
48 struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX]; 47 struct hid_sensor_hub_attribute_info magn[MAGN_3D_CHANNEL_MAX];
49 u32 magn_val[MAGN_3D_CHANNEL_MAX]; 48 u32 magn_val[MAGN_3D_CHANNEL_MAX];
50}; 49};
diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
new file mode 100644
index 000000000000..7e81d00ef0c3
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -0,0 +1,45 @@
1/*
2 * STMicroelectronics magnetometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 * v. 1.0.0
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_MAGN_H
12#define ST_MAGN_H
13
14#include <linux/types.h>
15#include <linux/iio/common/st_sensors.h>
16
17#define LSM303DLHC_MAGN_DEV_NAME "lsm303dlhc_magn"
18#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn"
19#define LIS3MDL_MAGN_DEV_NAME "lis3mdl"
20
21int st_magn_common_probe(struct iio_dev *indio_dev);
22void st_magn_common_remove(struct iio_dev *indio_dev);
23
24#ifdef CONFIG_IIO_BUFFER
25int st_magn_allocate_ring(struct iio_dev *indio_dev);
26void st_magn_deallocate_ring(struct iio_dev *indio_dev);
27#else /* CONFIG_IIO_BUFFER */
28static inline int st_magn_probe_trigger(struct iio_dev *indio_dev, int irq)
29{
30 return 0;
31}
32static inline void st_magn_remove_trigger(struct iio_dev *indio_dev, int irq)
33{
34 return;
35}
36static inline int st_magn_allocate_ring(struct iio_dev *indio_dev)
37{
38 return 0;
39}
40static inline void st_magn_deallocate_ring(struct iio_dev *indio_dev)
41{
42}
43#endif /* CONFIG_IIO_BUFFER */
44
45#endif /* ST_MAGN_H */
diff --git a/drivers/iio/magnetometer/st_magn_buffer.c b/drivers/iio/magnetometer/st_magn_buffer.c
new file mode 100644
index 000000000000..708857bdb47d
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_buffer.c
@@ -0,0 +1,98 @@
1/*
2 * STMicroelectronics magnetometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/stat.h>
15#include <linux/interrupt.h>
16#include <linux/i2c.h>
17#include <linux/delay.h>
18#include <linux/iio/iio.h>
19#include <linux/iio/buffer.h>
20#include <linux/iio/trigger_consumer.h>
21#include <linux/iio/triggered_buffer.h>
22
23#include <linux/iio/common/st_sensors.h>
24#include "st_magn.h"
25
26static int st_magn_buffer_preenable(struct iio_dev *indio_dev)
27{
28 int err;
29
30 err = st_sensors_set_enable(indio_dev, true);
31 if (err < 0)
32 goto st_magn_set_enable_error;
33
34 err = iio_sw_buffer_preenable(indio_dev);
35
36st_magn_set_enable_error:
37 return err;
38}
39
40static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
41{
42 int err;
43 struct st_sensor_data *mdata = iio_priv(indio_dev);
44
45 mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
46 if (mdata->buffer_data == NULL) {
47 err = -ENOMEM;
48 goto allocate_memory_error;
49 }
50
51 err = iio_triggered_buffer_postenable(indio_dev);
52 if (err < 0)
53 goto st_magn_buffer_postenable_error;
54
55 return err;
56
57st_magn_buffer_postenable_error:
58 kfree(mdata->buffer_data);
59allocate_memory_error:
60 return err;
61}
62
63static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
64{
65 int err;
66 struct st_sensor_data *mdata = iio_priv(indio_dev);
67
68 err = iio_triggered_buffer_predisable(indio_dev);
69 if (err < 0)
70 goto st_magn_buffer_predisable_error;
71
72 err = st_sensors_set_enable(indio_dev, false);
73
74st_magn_buffer_predisable_error:
75 kfree(mdata->buffer_data);
76 return err;
77}
78
79static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
80 .preenable = &st_magn_buffer_preenable,
81 .postenable = &st_magn_buffer_postenable,
82 .predisable = &st_magn_buffer_predisable,
83};
84
85int st_magn_allocate_ring(struct iio_dev *indio_dev)
86{
87 return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
88 &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
89}
90
91void st_magn_deallocate_ring(struct iio_dev *indio_dev)
92{
93 iio_triggered_buffer_cleanup(indio_dev);
94}
95
96MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
97MODULE_DESCRIPTION("STMicroelectronics magnetometers buffer");
98MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
new file mode 100644
index 000000000000..16f0d6df239f
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -0,0 +1,400 @@
1/*
2 * STMicroelectronics magnetometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/errno.h>
15#include <linux/types.h>
16#include <linux/mutex.h>
17#include <linux/interrupt.h>
18#include <linux/i2c.h>
19#include <linux/gpio.h>
20#include <linux/irq.h>
21#include <linux/delay.h>
22#include <linux/iio/iio.h>
23#include <linux/iio/sysfs.h>
24#include <linux/iio/buffer.h>
25
26#include <linux/iio/common/st_sensors.h>
27#include "st_magn.h"
28
29/* DEFAULT VALUE FOR SENSORS */
30#define ST_MAGN_DEFAULT_OUT_X_L_ADDR 0X04
31#define ST_MAGN_DEFAULT_OUT_Y_L_ADDR 0X08
32#define ST_MAGN_DEFAULT_OUT_Z_L_ADDR 0X06
33
34/* FULLSCALE */
35#define ST_MAGN_FS_AVL_1300MG 1300
36#define ST_MAGN_FS_AVL_1900MG 1900
37#define ST_MAGN_FS_AVL_2500MG 2500
38#define ST_MAGN_FS_AVL_4000MG 4000
39#define ST_MAGN_FS_AVL_4700MG 4700
40#define ST_MAGN_FS_AVL_5600MG 5600
41#define ST_MAGN_FS_AVL_8000MG 8000
42#define ST_MAGN_FS_AVL_8100MG 8100
43#define ST_MAGN_FS_AVL_10000MG 10000
44
45/* CUSTOM VALUES FOR SENSOR 1 */
46#define ST_MAGN_1_WAI_EXP 0x3c
47#define ST_MAGN_1_ODR_ADDR 0x00
48#define ST_MAGN_1_ODR_MASK 0x1c
49#define ST_MAGN_1_ODR_AVL_1HZ_VAL 0x00
50#define ST_MAGN_1_ODR_AVL_2HZ_VAL 0x01
51#define ST_MAGN_1_ODR_AVL_3HZ_VAL 0x02
52#define ST_MAGN_1_ODR_AVL_8HZ_VAL 0x03
53#define ST_MAGN_1_ODR_AVL_15HZ_VAL 0x04
54#define ST_MAGN_1_ODR_AVL_30HZ_VAL 0x05
55#define ST_MAGN_1_ODR_AVL_75HZ_VAL 0x06
56#define ST_MAGN_1_ODR_AVL_220HZ_VAL 0x07
57#define ST_MAGN_1_PW_ADDR 0x02
58#define ST_MAGN_1_PW_MASK 0x03
59#define ST_MAGN_1_PW_ON 0x00
60#define ST_MAGN_1_PW_OFF 0x03
61#define ST_MAGN_1_FS_ADDR 0x01
62#define ST_MAGN_1_FS_MASK 0xe0
63#define ST_MAGN_1_FS_AVL_1300_VAL 0x01
64#define ST_MAGN_1_FS_AVL_1900_VAL 0x02
65#define ST_MAGN_1_FS_AVL_2500_VAL 0x03
66#define ST_MAGN_1_FS_AVL_4000_VAL 0x04
67#define ST_MAGN_1_FS_AVL_4700_VAL 0x05
68#define ST_MAGN_1_FS_AVL_5600_VAL 0x06
69#define ST_MAGN_1_FS_AVL_8100_VAL 0x07
70#define ST_MAGN_1_FS_AVL_1300_GAIN_XY 1100
71#define ST_MAGN_1_FS_AVL_1900_GAIN_XY 855
72#define ST_MAGN_1_FS_AVL_2500_GAIN_XY 670
73#define ST_MAGN_1_FS_AVL_4000_GAIN_XY 450
74#define ST_MAGN_1_FS_AVL_4700_GAIN_XY 400
75#define ST_MAGN_1_FS_AVL_5600_GAIN_XY 330
76#define ST_MAGN_1_FS_AVL_8100_GAIN_XY 230
77#define ST_MAGN_1_FS_AVL_1300_GAIN_Z 980
78#define ST_MAGN_1_FS_AVL_1900_GAIN_Z 760
79#define ST_MAGN_1_FS_AVL_2500_GAIN_Z 600
80#define ST_MAGN_1_FS_AVL_4000_GAIN_Z 400
81#define ST_MAGN_1_FS_AVL_4700_GAIN_Z 355
82#define ST_MAGN_1_FS_AVL_5600_GAIN_Z 295
83#define ST_MAGN_1_FS_AVL_8100_GAIN_Z 205
84#define ST_MAGN_1_MULTIREAD_BIT false
85
86/* CUSTOM VALUES FOR SENSOR 2 */
87#define ST_MAGN_2_WAI_EXP 0x3d
88#define ST_MAGN_2_ODR_ADDR 0x20
89#define ST_MAGN_2_ODR_MASK 0x1c
90#define ST_MAGN_2_ODR_AVL_1HZ_VAL 0x00
91#define ST_MAGN_2_ODR_AVL_2HZ_VAL 0x01
92#define ST_MAGN_2_ODR_AVL_3HZ_VAL 0x02
93#define ST_MAGN_2_ODR_AVL_5HZ_VAL 0x03
94#define ST_MAGN_2_ODR_AVL_10HZ_VAL 0x04
95#define ST_MAGN_2_ODR_AVL_20HZ_VAL 0x05
96#define ST_MAGN_2_ODR_AVL_40HZ_VAL 0x06
97#define ST_MAGN_2_ODR_AVL_80HZ_VAL 0x07
98#define ST_MAGN_2_PW_ADDR 0x22
99#define ST_MAGN_2_PW_MASK 0x03
100#define ST_MAGN_2_PW_ON 0x00
101#define ST_MAGN_2_PW_OFF 0x03
102#define ST_MAGN_2_FS_ADDR 0x21
103#define ST_MAGN_2_FS_MASK 0x60
104#define ST_MAGN_2_FS_AVL_4000_VAL 0x00
105#define ST_MAGN_2_FS_AVL_8000_VAL 0x01
106#define ST_MAGN_2_FS_AVL_10000_VAL 0x02
107#define ST_MAGN_2_FS_AVL_4000_GAIN 430
108#define ST_MAGN_2_FS_AVL_8000_GAIN 230
109#define ST_MAGN_2_FS_AVL_10000_GAIN 230
110#define ST_MAGN_2_MULTIREAD_BIT false
111#define ST_MAGN_2_OUT_X_L_ADDR 0x28
112#define ST_MAGN_2_OUT_Y_L_ADDR 0x2a
113#define ST_MAGN_2_OUT_Z_L_ADDR 0x2c
114
115static const struct iio_chan_spec st_magn_16bit_channels[] = {
116 ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
117 ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_X_L_ADDR),
118 ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
119 ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Y_L_ADDR),
120 ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
121 ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_DEFAULT_OUT_Z_L_ADDR),
122 IIO_CHAN_SOFT_TIMESTAMP(3)
123};
124
125static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
126 ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_X, IIO_MOD_X, IIO_LE,
127 ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_X_L_ADDR),
128 ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Y, IIO_MOD_Y, IIO_LE,
129 ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Y_L_ADDR),
130 ST_SENSORS_LSM_CHANNELS(IIO_MAGN, ST_SENSORS_SCAN_Z, IIO_MOD_Z, IIO_LE,
131 ST_SENSORS_DEFAULT_16_REALBITS, ST_MAGN_2_OUT_Z_L_ADDR),
132 IIO_CHAN_SOFT_TIMESTAMP(3)
133};
134
135static const struct st_sensors st_magn_sensors[] = {
136 {
137 .wai = ST_MAGN_1_WAI_EXP,
138 .sensors_supported = {
139 [0] = LSM303DLHC_MAGN_DEV_NAME,
140 [1] = LSM303DLM_MAGN_DEV_NAME,
141 },
142 .ch = (struct iio_chan_spec *)st_magn_16bit_channels,
143 .odr = {
144 .addr = ST_MAGN_1_ODR_ADDR,
145 .mask = ST_MAGN_1_ODR_MASK,
146 .odr_avl = {
147 { 1, ST_MAGN_1_ODR_AVL_1HZ_VAL, },
148 { 2, ST_MAGN_1_ODR_AVL_2HZ_VAL, },
149 { 3, ST_MAGN_1_ODR_AVL_3HZ_VAL, },
150 { 8, ST_MAGN_1_ODR_AVL_8HZ_VAL, },
151 { 15, ST_MAGN_1_ODR_AVL_15HZ_VAL, },
152 { 30, ST_MAGN_1_ODR_AVL_30HZ_VAL, },
153 { 75, ST_MAGN_1_ODR_AVL_75HZ_VAL, },
154 { 220, ST_MAGN_1_ODR_AVL_220HZ_VAL, },
155 },
156 },
157 .pw = {
158 .addr = ST_MAGN_1_PW_ADDR,
159 .mask = ST_MAGN_1_PW_MASK,
160 .value_on = ST_MAGN_1_PW_ON,
161 .value_off = ST_MAGN_1_PW_OFF,
162 },
163 .fs = {
164 .addr = ST_MAGN_1_FS_ADDR,
165 .mask = ST_MAGN_1_FS_MASK,
166 .fs_avl = {
167 [0] = {
168 .num = ST_MAGN_FS_AVL_1300MG,
169 .value = ST_MAGN_1_FS_AVL_1300_VAL,
170 .gain = ST_MAGN_1_FS_AVL_1300_GAIN_XY,
171 .gain2 = ST_MAGN_1_FS_AVL_1300_GAIN_Z,
172 },
173 [1] = {
174 .num = ST_MAGN_FS_AVL_1900MG,
175 .value = ST_MAGN_1_FS_AVL_1900_VAL,
176 .gain = ST_MAGN_1_FS_AVL_1900_GAIN_XY,
177 .gain2 = ST_MAGN_1_FS_AVL_1900_GAIN_Z,
178 },
179 [2] = {
180 .num = ST_MAGN_FS_AVL_2500MG,
181 .value = ST_MAGN_1_FS_AVL_2500_VAL,
182 .gain = ST_MAGN_1_FS_AVL_2500_GAIN_XY,
183 .gain2 = ST_MAGN_1_FS_AVL_2500_GAIN_Z,
184 },
185 [3] = {
186 .num = ST_MAGN_FS_AVL_4000MG,
187 .value = ST_MAGN_1_FS_AVL_4000_VAL,
188 .gain = ST_MAGN_1_FS_AVL_4000_GAIN_XY,
189 .gain2 = ST_MAGN_1_FS_AVL_4000_GAIN_Z,
190 },
191 [4] = {
192 .num = ST_MAGN_FS_AVL_4700MG,
193 .value = ST_MAGN_1_FS_AVL_4700_VAL,
194 .gain = ST_MAGN_1_FS_AVL_4700_GAIN_XY,
195 .gain2 = ST_MAGN_1_FS_AVL_4700_GAIN_Z,
196 },
197 [5] = {
198 .num = ST_MAGN_FS_AVL_5600MG,
199 .value = ST_MAGN_1_FS_AVL_5600_VAL,
200 .gain = ST_MAGN_1_FS_AVL_5600_GAIN_XY,
201 .gain2 = ST_MAGN_1_FS_AVL_5600_GAIN_Z,
202 },
203 [6] = {
204 .num = ST_MAGN_FS_AVL_8100MG,
205 .value = ST_MAGN_1_FS_AVL_8100_VAL,
206 .gain = ST_MAGN_1_FS_AVL_8100_GAIN_XY,
207 .gain2 = ST_MAGN_1_FS_AVL_8100_GAIN_Z,
208 },
209 },
210 },
211 .multi_read_bit = ST_MAGN_1_MULTIREAD_BIT,
212 .bootime = 2,
213 },
214 {
215 .wai = ST_MAGN_2_WAI_EXP,
216 .sensors_supported = {
217 [0] = LIS3MDL_MAGN_DEV_NAME,
218 },
219 .ch = (struct iio_chan_spec *)st_magn_2_16bit_channels,
220 .odr = {
221 .addr = ST_MAGN_2_ODR_ADDR,
222 .mask = ST_MAGN_2_ODR_MASK,
223 .odr_avl = {
224 { 1, ST_MAGN_2_ODR_AVL_1HZ_VAL, },
225 { 2, ST_MAGN_2_ODR_AVL_2HZ_VAL, },
226 { 3, ST_MAGN_2_ODR_AVL_3HZ_VAL, },
227 { 5, ST_MAGN_2_ODR_AVL_5HZ_VAL, },
228 { 10, ST_MAGN_2_ODR_AVL_10HZ_VAL, },
229 { 20, ST_MAGN_2_ODR_AVL_20HZ_VAL, },
230 { 40, ST_MAGN_2_ODR_AVL_40HZ_VAL, },
231 { 80, ST_MAGN_2_ODR_AVL_80HZ_VAL, },
232 },
233 },
234 .pw = {
235 .addr = ST_MAGN_2_PW_ADDR,
236 .mask = ST_MAGN_2_PW_MASK,
237 .value_on = ST_MAGN_2_PW_ON,
238 .value_off = ST_MAGN_2_PW_OFF,
239 },
240 .fs = {
241 .addr = ST_MAGN_2_FS_ADDR,
242 .mask = ST_MAGN_2_FS_MASK,
243 .fs_avl = {
244 [0] = {
245 .num = ST_MAGN_FS_AVL_4000MG,
246 .value = ST_MAGN_2_FS_AVL_4000_VAL,
247 .gain = ST_MAGN_2_FS_AVL_4000_GAIN,
248 },
249 [1] = {
250 .num = ST_MAGN_FS_AVL_8000MG,
251 .value = ST_MAGN_2_FS_AVL_8000_VAL,
252 .gain = ST_MAGN_2_FS_AVL_8000_GAIN,
253 },
254 [2] = {
255 .num = ST_MAGN_FS_AVL_10000MG,
256 .value = ST_MAGN_2_FS_AVL_10000_VAL,
257 .gain = ST_MAGN_2_FS_AVL_10000_GAIN,
258 },
259 },
260 },
261 .multi_read_bit = ST_MAGN_2_MULTIREAD_BIT,
262 .bootime = 2,
263 },
264};
265
266static int st_magn_read_raw(struct iio_dev *indio_dev,
267 struct iio_chan_spec const *ch, int *val,
268 int *val2, long mask)
269{
270 int err;
271 struct st_sensor_data *mdata = iio_priv(indio_dev);
272
273 switch (mask) {
274 case IIO_CHAN_INFO_RAW:
275 err = st_sensors_read_info_raw(indio_dev, ch, val);
276 if (err < 0)
277 goto read_error;
278
279 return IIO_VAL_INT;
280 case IIO_CHAN_INFO_SCALE:
281 *val = 0;
282 if ((ch->scan_index == ST_SENSORS_SCAN_Z) &&
283 (mdata->current_fullscale->gain2 != 0))
284 *val2 = mdata->current_fullscale->gain2;
285 else
286 *val2 = mdata->current_fullscale->gain;
287 return IIO_VAL_INT_PLUS_MICRO;
288 default:
289 return -EINVAL;
290 }
291
292read_error:
293 return err;
294}
295
296static int st_magn_write_raw(struct iio_dev *indio_dev,
297 struct iio_chan_spec const *chan, int val, int val2, long mask)
298{
299 int err;
300
301 switch (mask) {
302 case IIO_CHAN_INFO_SCALE:
303 err = st_sensors_set_fullscale_by_gain(indio_dev, val2);
304 break;
305 default:
306 err = -EINVAL;
307 }
308
309 return err;
310}
311
312static ST_SENSOR_DEV_ATTR_SAMP_FREQ();
313static ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL();
314static ST_SENSORS_DEV_ATTR_SCALE_AVAIL(in_magn_scale_available);
315
316static struct attribute *st_magn_attributes[] = {
317 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
318 &iio_dev_attr_in_magn_scale_available.dev_attr.attr,
319 &iio_dev_attr_sampling_frequency.dev_attr.attr,
320 NULL,
321};
322
323static const struct attribute_group st_magn_attribute_group = {
324 .attrs = st_magn_attributes,
325};
326
327static const struct iio_info magn_info = {
328 .driver_module = THIS_MODULE,
329 .attrs = &st_magn_attribute_group,
330 .read_raw = &st_magn_read_raw,
331 .write_raw = &st_magn_write_raw,
332};
333
334int st_magn_common_probe(struct iio_dev *indio_dev)
335{
336 int err;
337 struct st_sensor_data *mdata = iio_priv(indio_dev);
338
339 indio_dev->modes = INDIO_DIRECT_MODE;
340 indio_dev->info = &magn_info;
341
342 err = st_sensors_check_device_support(indio_dev,
343 ARRAY_SIZE(st_magn_sensors), st_magn_sensors);
344 if (err < 0)
345 goto st_magn_common_probe_error;
346
347 mdata->multiread_bit = mdata->sensor->multi_read_bit;
348 indio_dev->channels = mdata->sensor->ch;
349 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
350
351 mdata->current_fullscale = (struct st_sensor_fullscale_avl *)
352 &mdata->sensor->fs.fs_avl[0];
353 mdata->odr = mdata->sensor->odr.odr_avl[0].hz;
354
355 err = st_sensors_init_sensor(indio_dev);
356 if (err < 0)
357 goto st_magn_common_probe_error;
358
359 if (mdata->get_irq_data_ready(indio_dev) > 0) {
360 err = st_magn_allocate_ring(indio_dev);
361 if (err < 0)
362 goto st_magn_common_probe_error;
363 err = st_sensors_allocate_trigger(indio_dev, NULL);
364 if (err < 0)
365 goto st_magn_probe_trigger_error;
366 }
367
368 err = iio_device_register(indio_dev);
369 if (err)
370 goto st_magn_device_register_error;
371
372 return err;
373
374st_magn_device_register_error:
375 if (mdata->get_irq_data_ready(indio_dev) > 0)
376 st_sensors_deallocate_trigger(indio_dev);
377st_magn_probe_trigger_error:
378 if (mdata->get_irq_data_ready(indio_dev) > 0)
379 st_magn_deallocate_ring(indio_dev);
380st_magn_common_probe_error:
381 return err;
382}
383EXPORT_SYMBOL(st_magn_common_probe);
384
385void st_magn_common_remove(struct iio_dev *indio_dev)
386{
387 struct st_sensor_data *mdata = iio_priv(indio_dev);
388
389 iio_device_unregister(indio_dev);
390 if (mdata->get_irq_data_ready(indio_dev) > 0) {
391 st_sensors_deallocate_trigger(indio_dev);
392 st_magn_deallocate_ring(indio_dev);
393 }
394 iio_device_free(indio_dev);
395}
396EXPORT_SYMBOL(st_magn_common_remove);
397
398MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
399MODULE_DESCRIPTION("STMicroelectronics magnetometers driver");
400MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
new file mode 100644
index 000000000000..e6adc4a86425
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -0,0 +1,80 @@
1/*
2 * STMicroelectronics magnetometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/iio/iio.h>
16
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_i2c.h>
19#include "st_magn.h"
20
21static int st_magn_i2c_probe(struct i2c_client *client,
22 const struct i2c_device_id *id)
23{
24 struct iio_dev *indio_dev;
25 struct st_sensor_data *mdata;
26 int err;
27
28 indio_dev = iio_device_alloc(sizeof(*mdata));
29 if (indio_dev == NULL) {
30 err = -ENOMEM;
31 goto iio_device_alloc_error;
32 }
33
34 mdata = iio_priv(indio_dev);
35 mdata->dev = &client->dev;
36
37 st_sensors_i2c_configure(indio_dev, client, mdata);
38
39 err = st_magn_common_probe(indio_dev);
40 if (err < 0)
41 goto st_magn_common_probe_error;
42
43 return 0;
44
45st_magn_common_probe_error:
46 iio_device_free(indio_dev);
47iio_device_alloc_error:
48 return err;
49}
50
51static int st_magn_i2c_remove(struct i2c_client *client)
52{
53 struct iio_dev *indio_dev = i2c_get_clientdata(client);
54 st_magn_common_remove(indio_dev);
55
56 return 0;
57}
58
59static const struct i2c_device_id st_magn_id_table[] = {
60 { LSM303DLHC_MAGN_DEV_NAME },
61 { LSM303DLM_MAGN_DEV_NAME },
62 { LIS3MDL_MAGN_DEV_NAME },
63 {},
64};
65MODULE_DEVICE_TABLE(i2c, st_magn_id_table);
66
67static struct i2c_driver st_magn_driver = {
68 .driver = {
69 .owner = THIS_MODULE,
70 .name = "st-magn-i2c",
71 },
72 .probe = st_magn_i2c_probe,
73 .remove = st_magn_i2c_remove,
74 .id_table = st_magn_id_table,
75};
76module_i2c_driver(st_magn_driver);
77
78MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
79MODULE_DESCRIPTION("STMicroelectronics magnetometers i2c driver");
80MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
new file mode 100644
index 000000000000..51adb797cb7d
--- /dev/null
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -0,0 +1,79 @@
1/*
2 * STMicroelectronics magnetometers driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/spi/spi.h>
15#include <linux/iio/iio.h>
16
17#include <linux/iio/common/st_sensors.h>
18#include <linux/iio/common/st_sensors_spi.h>
19#include "st_magn.h"
20
21static int st_magn_spi_probe(struct spi_device *spi)
22{
23 struct iio_dev *indio_dev;
24 struct st_sensor_data *mdata;
25 int err;
26
27 indio_dev = iio_device_alloc(sizeof(*mdata));
28 if (indio_dev == NULL) {
29 err = -ENOMEM;
30 goto iio_device_alloc_error;
31 }
32
33 mdata = iio_priv(indio_dev);
34 mdata->dev = &spi->dev;
35
36 st_sensors_spi_configure(indio_dev, spi, mdata);
37
38 err = st_magn_common_probe(indio_dev);
39 if (err < 0)
40 goto st_magn_common_probe_error;
41
42 return 0;
43
44st_magn_common_probe_error:
45 iio_device_free(indio_dev);
46iio_device_alloc_error:
47 return err;
48}
49
50static int st_magn_spi_remove(struct spi_device *spi)
51{
52 struct iio_dev *indio_dev = spi_get_drvdata(spi);
53 st_magn_common_remove(indio_dev);
54
55 return 0;
56}
57
58static const struct spi_device_id st_magn_id_table[] = {
59 { LSM303DLHC_MAGN_DEV_NAME },
60 { LSM303DLM_MAGN_DEV_NAME },
61 { LIS3MDL_MAGN_DEV_NAME },
62 {},
63};
64MODULE_DEVICE_TABLE(spi, st_magn_id_table);
65
66static struct spi_driver st_magn_driver = {
67 .driver = {
68 .owner = THIS_MODULE,
69 .name = "st-magn-spi",
70 },
71 .probe = st_magn_spi_probe,
72 .remove = st_magn_spi_remove,
73 .id_table = st_magn_id_table,
74};
75module_spi_driver(st_magn_driver);
76
77MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
78MODULE_DESCRIPTION("STMicroelectronics magnetometers spi driver");
79MODULE_LICENSE("GPL v2");
diff --git a/drivers/platform/Kconfig b/drivers/platform/Kconfig
index 8390dca2b4e1..69616aeaa966 100644
--- a/drivers/platform/Kconfig
+++ b/drivers/platform/Kconfig
@@ -1,3 +1,7 @@
1if X86 1if X86
2source "drivers/platform/x86/Kconfig" 2source "drivers/platform/x86/Kconfig"
3endif 3endif
4if GOLDFISH
5source "drivers/platform/goldfish/Kconfig"
6endif
7
diff --git a/drivers/platform/Makefile b/drivers/platform/Makefile
index b17c16ce54ad..8a44a4cd6d1e 100644
--- a/drivers/platform/Makefile
+++ b/drivers/platform/Makefile
@@ -4,3 +4,4 @@
4 4
5obj-$(CONFIG_X86) += x86/ 5obj-$(CONFIG_X86) += x86/
6obj-$(CONFIG_OLPC) += olpc/ 6obj-$(CONFIG_OLPC) += olpc/
7obj-$(CONFIG_GOLDFISH) += goldfish/
diff --git a/drivers/platform/goldfish/Kconfig b/drivers/platform/goldfish/Kconfig
new file mode 100644
index 000000000000..635ef25cc722
--- /dev/null
+++ b/drivers/platform/goldfish/Kconfig
@@ -0,0 +1,5 @@
1config GOLDFISH_PIPE
2 tristate "Goldfish virtual device for QEMU pipes"
3 ---help---
4 This is a virtual device to drive the QEMU pipe interface used by
5 the Goldfish Android Virtual Device.
diff --git a/drivers/platform/goldfish/Makefile b/drivers/platform/goldfish/Makefile
new file mode 100644
index 000000000000..a0022395eee9
--- /dev/null
+++ b/drivers/platform/goldfish/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for Goldfish platform specific drivers
3#
4obj-$(CONFIG_GOLDFISH) += pdev_bus.o
5obj-$(CONFIG_GOLDFISH_PIPE) += goldfish_pipe.o
diff --git a/drivers/platform/goldfish/goldfish_pipe.c b/drivers/platform/goldfish/goldfish_pipe.c
new file mode 100644
index 000000000000..4f5aa831f549
--- /dev/null
+++ b/drivers/platform/goldfish/goldfish_pipe.c
@@ -0,0 +1,612 @@
1/*
2 * Copyright (C) 2011 Google, Inc.
3 * Copyright (C) 2012 Intel, Inc.
4 * Copyright (C) 2013 Intel, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17/* This source file contains the implementation of a special device driver
18 * that intends to provide a *very* fast communication channel between the
19 * guest system and the QEMU emulator.
20 *
21 * Usage from the guest is simply the following (error handling simplified):
22 *
23 * int fd = open("/dev/qemu_pipe",O_RDWR);
24 * .... write() or read() through the pipe.
25 *
26 * This driver doesn't deal with the exact protocol used during the session.
27 * It is intended to be as simple as something like:
28 *
29 * // do this _just_ after opening the fd to connect to a specific
30 * // emulator service.
31 * const char* msg = "<pipename>";
32 * if (write(fd, msg, strlen(msg)+1) < 0) {
33 * ... could not connect to <pipename> service
34 * close(fd);
35 * }
36 *
37 * // after this, simply read() and write() to communicate with the
38 * // service. Exact protocol details left as an exercise to the reader.
39 *
40 * This driver is very fast because it doesn't copy any data through
41 * intermediate buffers, since the emulator is capable of translating
42 * guest user addresses into host ones.
43 *
44 * Note that we must however ensure that each user page involved in the
45 * exchange is properly mapped during a transfer.
46 */
47
48#include <linux/module.h>
49#include <linux/interrupt.h>
50#include <linux/kernel.h>
51#include <linux/spinlock.h>
52#include <linux/miscdevice.h>
53#include <linux/platform_device.h>
54#include <linux/poll.h>
55#include <linux/sched.h>
56#include <linux/bitops.h>
57#include <linux/slab.h>
58#include <linux/io.h>
59
60/*
61 * IMPORTANT: The following constants must match the ones used and defined
62 * in external/qemu/hw/goldfish_pipe.c in the Android source tree.
63 */
64
65/* pipe device registers */
66#define PIPE_REG_COMMAND 0x00 /* write: value = command */
67#define PIPE_REG_STATUS 0x04 /* read */
68#define PIPE_REG_CHANNEL 0x08 /* read/write: channel id */
69#define PIPE_REG_SIZE 0x0c /* read/write: buffer size */
70#define PIPE_REG_ADDRESS 0x10 /* write: physical address */
71#define PIPE_REG_WAKES 0x14 /* read: wake flags */
72#define PIPE_REG_PARAMS_ADDR_LOW 0x18 /* read/write: batch data address */
73#define PIPE_REG_PARAMS_ADDR_HIGH 0x1c /* read/write: batch data address */
74#define PIPE_REG_ACCESS_PARAMS 0x20 /* write: batch access */
75
76/* list of commands for PIPE_REG_COMMAND */
77#define CMD_OPEN 1 /* open new channel */
78#define CMD_CLOSE 2 /* close channel (from guest) */
79#define CMD_POLL 3 /* poll read/write status */
80
81/* List of bitflags returned in status of CMD_POLL command */
82#define PIPE_POLL_IN (1 << 0)
83#define PIPE_POLL_OUT (1 << 1)
84#define PIPE_POLL_HUP (1 << 2)
85
86/* The following commands are related to write operations */
87#define CMD_WRITE_BUFFER 4 /* send a user buffer to the emulator */
88#define CMD_WAKE_ON_WRITE 5 /* tell the emulator to wake us when writing
89 is possible */
90
91/* The following commands are related to read operations, they must be
92 * listed in the same order than the corresponding write ones, since we
93 * will use (CMD_READ_BUFFER - CMD_WRITE_BUFFER) as a special offset
94 * in goldfish_pipe_read_write() below.
95 */
96#define CMD_READ_BUFFER 6 /* receive a user buffer from the emulator */
97#define CMD_WAKE_ON_READ 7 /* tell the emulator to wake us when reading
98 * is possible */
99
100/* Possible status values used to signal errors - see goldfish_pipe_error_convert */
101#define PIPE_ERROR_INVAL -1
102#define PIPE_ERROR_AGAIN -2
103#define PIPE_ERROR_NOMEM -3
104#define PIPE_ERROR_IO -4
105
106/* Bit-flags used to signal events from the emulator */
107#define PIPE_WAKE_CLOSED (1 << 0) /* emulator closed pipe */
108#define PIPE_WAKE_READ (1 << 1) /* pipe can now be read from */
109#define PIPE_WAKE_WRITE (1 << 2) /* pipe can now be written to */
110
111struct access_params {
112 u32 channel;
113 u32 size;
114 u32 address;
115 u32 cmd;
116 u32 result;
117 /* reserved for future extension */
118 u32 flags;
119};
120
121/* The global driver data. Holds a reference to the i/o page used to
122 * communicate with the emulator, and a wake queue for blocked tasks
123 * waiting to be awoken.
124 */
125struct goldfish_pipe_dev {
126 spinlock_t lock;
127 unsigned char __iomem *base;
128 struct access_params *aps;
129 int irq;
130};
131
132static struct goldfish_pipe_dev pipe_dev[1];
133
134/* This data type models a given pipe instance */
135struct goldfish_pipe {
136 struct goldfish_pipe_dev *dev;
137 struct mutex lock;
138 unsigned long flags;
139 wait_queue_head_t wake_queue;
140};
141
142
143/* Bit flags for the 'flags' field */
144enum {
145 BIT_CLOSED_ON_HOST = 0, /* pipe closed by host */
146 BIT_WAKE_ON_WRITE = 1, /* want to be woken on writes */
147 BIT_WAKE_ON_READ = 2, /* want to be woken on reads */
148};
149
150
151static u32 goldfish_cmd_status(struct goldfish_pipe *pipe, u32 cmd)
152{
153 unsigned long flags;
154 u32 status;
155 struct goldfish_pipe_dev *dev = pipe->dev;
156
157 spin_lock_irqsave(&dev->lock, flags);
158 writel((u32)pipe, dev->base + PIPE_REG_CHANNEL);
159 writel(cmd, dev->base + PIPE_REG_COMMAND);
160 status = readl(dev->base + PIPE_REG_STATUS);
161 spin_unlock_irqrestore(&dev->lock, flags);
162 return status;
163}
164
165static void goldfish_cmd(struct goldfish_pipe *pipe, u32 cmd)
166{
167 unsigned long flags;
168 struct goldfish_pipe_dev *dev = pipe->dev;
169
170 spin_lock_irqsave(&dev->lock, flags);
171 writel((u32)pipe, dev->base + PIPE_REG_CHANNEL);
172 writel(cmd, dev->base + PIPE_REG_COMMAND);
173 spin_unlock_irqrestore(&dev->lock, flags);
174}
175
176/* This function converts an error code returned by the emulator through
177 * the PIPE_REG_STATUS i/o register into a valid negative errno value.
178 */
179static int goldfish_pipe_error_convert(int status)
180{
181 switch (status) {
182 case PIPE_ERROR_AGAIN:
183 return -EAGAIN;
184 case PIPE_ERROR_NOMEM:
185 return -ENOMEM;
186 case PIPE_ERROR_IO:
187 return -EIO;
188 default:
189 return -EINVAL;
190 }
191}
192
193/*
194 * Notice: QEMU will return 0 for un-known register access, indicating
195 * param_acess is supported or not
196 */
197static int valid_batchbuffer_addr(struct goldfish_pipe_dev *dev,
198 struct access_params *aps)
199{
200 u32 aph, apl;
201 u64 paddr;
202 aph = readl(dev->base + PIPE_REG_PARAMS_ADDR_HIGH);
203 apl = readl(dev->base + PIPE_REG_PARAMS_ADDR_LOW);
204
205 paddr = ((u64)aph << 32) | apl;
206 if (paddr != (__pa(aps)))
207 return 0;
208 return 1;
209}
210
211/* 0 on success */
212static int setup_access_params_addr(struct platform_device *pdev,
213 struct goldfish_pipe_dev *dev)
214{
215 u64 paddr;
216 struct access_params *aps;
217
218 aps = devm_kzalloc(&pdev->dev, sizeof(struct access_params), GFP_KERNEL);
219 if (!aps)
220 return -1;
221
222 /* FIXME */
223 paddr = __pa(aps);
224 writel((u32)(paddr >> 32), dev->base + PIPE_REG_PARAMS_ADDR_HIGH);
225 writel((u32)paddr, dev->base + PIPE_REG_PARAMS_ADDR_LOW);
226
227 if (valid_batchbuffer_addr(dev, aps)) {
228 dev->aps = aps;
229 return 0;
230 } else
231 return -1;
232}
233
234/* A value that will not be set by qemu emulator */
235#define INITIAL_BATCH_RESULT (0xdeadbeaf)
236static int access_with_param(struct goldfish_pipe_dev *dev, const int cmd,
237 unsigned long address, unsigned long avail,
238 struct goldfish_pipe *pipe, int *status)
239{
240 struct access_params *aps = dev->aps;
241
242 if (aps == NULL)
243 return -1;
244
245 aps->result = INITIAL_BATCH_RESULT;
246 aps->channel = (unsigned long)pipe;
247 aps->size = avail;
248 aps->address = address;
249 aps->cmd = cmd;
250 writel(cmd, dev->base + PIPE_REG_ACCESS_PARAMS);
251 /*
252 * If the aps->result has not changed, that means
253 * that the batch command failed
254 */
255 if (aps->result == INITIAL_BATCH_RESULT)
256 return -1;
257 *status = aps->result;
258 return 0;
259}
260
261/* This function is used for both reading from and writing to a given
262 * pipe.
263 */
264static ssize_t goldfish_pipe_read_write(struct file *filp, char __user *buffer,
265 size_t bufflen, int is_write)
266{
267 unsigned long irq_flags;
268 struct goldfish_pipe *pipe = filp->private_data;
269 struct goldfish_pipe_dev *dev = pipe->dev;
270 const int cmd_offset = is_write ? 0
271 : (CMD_READ_BUFFER - CMD_WRITE_BUFFER);
272 unsigned long address, address_end;
273 int ret = 0;
274
275 /* If the emulator already closed the pipe, no need to go further */
276 if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))
277 return -EIO;
278
279 /* Null reads or writes succeeds */
280 if (unlikely(bufflen) == 0)
281 return 0;
282
283 /* Check the buffer range for access */
284 if (!access_ok(is_write ? VERIFY_WRITE : VERIFY_READ,
285 buffer, bufflen))
286 return -EFAULT;
287
288 /* Serialize access to the pipe */
289 if (mutex_lock_interruptible(&pipe->lock))
290 return -ERESTARTSYS;
291
292 address = (unsigned long)(void *)buffer;
293 address_end = address + bufflen;
294
295 while (address < address_end) {
296 unsigned long page_end = (address & PAGE_MASK) + PAGE_SIZE;
297 unsigned long next = page_end < address_end ? page_end
298 : address_end;
299 unsigned long avail = next - address;
300 int status, wakeBit;
301
302 /* Ensure that the corresponding page is properly mapped */
303 /* FIXME: this isn't safe or sufficient - use get_user_pages */
304 if (is_write) {
305 char c;
306 /* Ensure that the page is mapped and readable */
307 if (__get_user(c, (char __user *)address)) {
308 if (!ret)
309 ret = -EFAULT;
310 break;
311 }
312 } else {
313 /* Ensure that the page is mapped and writable */
314 if (__put_user(0, (char __user *)address)) {
315 if (!ret)
316 ret = -EFAULT;
317 break;
318 }
319 }
320
321 /* Now, try to transfer the bytes in the current page */
322 spin_lock_irqsave(&dev->lock, irq_flags);
323 if (access_with_param(dev, CMD_WRITE_BUFFER + cmd_offset,
324 address, avail, pipe, &status)) {
325 writel((u32)pipe, dev->base + PIPE_REG_CHANNEL);
326 writel(avail, dev->base + PIPE_REG_SIZE);
327 writel(address, dev->base + PIPE_REG_ADDRESS);
328 writel(CMD_WRITE_BUFFER + cmd_offset,
329 dev->base + PIPE_REG_COMMAND);
330 status = readl(dev->base + PIPE_REG_STATUS);
331 }
332 spin_unlock_irqrestore(&dev->lock, irq_flags);
333
334 if (status > 0) { /* Correct transfer */
335 ret += status;
336 address += status;
337 continue;
338 }
339
340 if (status == 0) /* EOF */
341 break;
342
343 /* An error occured. If we already transfered stuff, just
344 * return with its count. We expect the next call to return
345 * an error code */
346 if (ret > 0)
347 break;
348
349 /* If the error is not PIPE_ERROR_AGAIN, or if we are not in
350 * non-blocking mode, just return the error code.
351 */
352 if (status != PIPE_ERROR_AGAIN ||
353 (filp->f_flags & O_NONBLOCK) != 0) {
354 ret = goldfish_pipe_error_convert(status);
355 break;
356 }
357
358 /* We will have to wait until more data/space is available.
359 * First, mark the pipe as waiting for a specific wake signal.
360 */
361 wakeBit = is_write ? BIT_WAKE_ON_WRITE : BIT_WAKE_ON_READ;
362 set_bit(wakeBit, &pipe->flags);
363
364 /* Tell the emulator we're going to wait for a wake event */
365 goldfish_cmd(pipe, CMD_WAKE_ON_WRITE + cmd_offset);
366
367 /* Unlock the pipe, then wait for the wake signal */
368 mutex_unlock(&pipe->lock);
369
370 while (test_bit(wakeBit, &pipe->flags)) {
371 if (wait_event_interruptible(
372 pipe->wake_queue,
373 !test_bit(wakeBit, &pipe->flags)))
374 return -ERESTARTSYS;
375
376 if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))
377 return -EIO;
378 }
379
380 /* Try to re-acquire the lock */
381 if (mutex_lock_interruptible(&pipe->lock))
382 return -ERESTARTSYS;
383
384 /* Try the transfer again */
385 continue;
386 }
387 mutex_unlock(&pipe->lock);
388 return ret;
389}
390
391static ssize_t goldfish_pipe_read(struct file *filp, char __user *buffer,
392 size_t bufflen, loff_t *ppos)
393{
394 return goldfish_pipe_read_write(filp, buffer, bufflen, 0);
395}
396
397static ssize_t goldfish_pipe_write(struct file *filp,
398 const char __user *buffer, size_t bufflen,
399 loff_t *ppos)
400{
401 return goldfish_pipe_read_write(filp, (char __user *)buffer,
402 bufflen, 1);
403}
404
405
406static unsigned int goldfish_pipe_poll(struct file *filp, poll_table *wait)
407{
408 struct goldfish_pipe *pipe = filp->private_data;
409 unsigned int mask = 0;
410 int status;
411
412 mutex_lock(&pipe->lock);
413
414 poll_wait(filp, &pipe->wake_queue, wait);
415
416 status = goldfish_cmd_status(pipe, CMD_POLL);
417
418 mutex_unlock(&pipe->lock);
419
420 if (status & PIPE_POLL_IN)
421 mask |= POLLIN | POLLRDNORM;
422
423 if (status & PIPE_POLL_OUT)
424 mask |= POLLOUT | POLLWRNORM;
425
426 if (status & PIPE_POLL_HUP)
427 mask |= POLLHUP;
428
429 if (test_bit(BIT_CLOSED_ON_HOST, &pipe->flags))
430 mask |= POLLERR;
431
432 return mask;
433}
434
435static irqreturn_t goldfish_pipe_interrupt(int irq, void *dev_id)
436{
437 struct goldfish_pipe_dev *dev = dev_id;
438 unsigned long irq_flags;
439 int count = 0;
440
441 /* We're going to read from the emulator a list of (channel,flags)
442 * pairs corresponding to the wake events that occured on each
443 * blocked pipe (i.e. channel).
444 */
445 spin_lock_irqsave(&dev->lock, irq_flags);
446 for (;;) {
447 /* First read the channel, 0 means the end of the list */
448 struct goldfish_pipe *pipe;
449 unsigned long wakes;
450 unsigned long channel = readl(dev->base + PIPE_REG_CHANNEL);
451
452 if (channel == 0)
453 break;
454
455 /* Convert channel to struct pipe pointer + read wake flags */
456 wakes = readl(dev->base + PIPE_REG_WAKES);
457 pipe = (struct goldfish_pipe *)(ptrdiff_t)channel;
458
459 /* Did the emulator just closed a pipe? */
460 if (wakes & PIPE_WAKE_CLOSED) {
461 set_bit(BIT_CLOSED_ON_HOST, &pipe->flags);
462 wakes |= PIPE_WAKE_READ | PIPE_WAKE_WRITE;
463 }
464 if (wakes & PIPE_WAKE_READ)
465 clear_bit(BIT_WAKE_ON_READ, &pipe->flags);
466 if (wakes & PIPE_WAKE_WRITE)
467 clear_bit(BIT_WAKE_ON_WRITE, &pipe->flags);
468
469 wake_up_interruptible(&pipe->wake_queue);
470 count++;
471 }
472 spin_unlock_irqrestore(&dev->lock, irq_flags);
473
474 return (count == 0) ? IRQ_NONE : IRQ_HANDLED;
475}
476
477/**
478 * goldfish_pipe_open - open a channel to the AVD
479 * @inode: inode of device
480 * @file: file struct of opener
481 *
482 * Create a new pipe link between the emulator and the use application.
483 * Each new request produces a new pipe.
484 *
485 * Note: we use the pipe ID as a mux. All goldfish emulations are 32bit
486 * right now so this is fine. A move to 64bit will need this addressing
487 */
488static int goldfish_pipe_open(struct inode *inode, struct file *file)
489{
490 struct goldfish_pipe *pipe;
491 struct goldfish_pipe_dev *dev = pipe_dev;
492 int32_t status;
493
494 /* Allocate new pipe kernel object */
495 pipe = kzalloc(sizeof(*pipe), GFP_KERNEL);
496 if (pipe == NULL)
497 return -ENOMEM;
498
499 pipe->dev = dev;
500 mutex_init(&pipe->lock);
501 init_waitqueue_head(&pipe->wake_queue);
502
503 /*
504 * Now, tell the emulator we're opening a new pipe. We use the
505 * pipe object's address as the channel identifier for simplicity.
506 */
507
508 status = goldfish_cmd_status(pipe, CMD_OPEN);
509 if (status < 0) {
510 kfree(pipe);
511 return status;
512 }
513
514 /* All is done, save the pipe into the file's private data field */
515 file->private_data = pipe;
516 return 0;
517}
518
519static int goldfish_pipe_release(struct inode *inode, struct file *filp)
520{
521 struct goldfish_pipe *pipe = filp->private_data;
522
523 /* The guest is closing the channel, so tell the emulator right now */
524 goldfish_cmd(pipe, CMD_CLOSE);
525 kfree(pipe);
526 filp->private_data = NULL;
527 return 0;
528}
529
530static const struct file_operations goldfish_pipe_fops = {
531 .owner = THIS_MODULE,
532 .read = goldfish_pipe_read,
533 .write = goldfish_pipe_write,
534 .poll = goldfish_pipe_poll,
535 .open = goldfish_pipe_open,
536 .release = goldfish_pipe_release,
537};
538
539static struct miscdevice goldfish_pipe_device = {
540 .minor = MISC_DYNAMIC_MINOR,
541 .name = "goldfish_pipe",
542 .fops = &goldfish_pipe_fops,
543};
544
545static int goldfish_pipe_probe(struct platform_device *pdev)
546{
547 int err;
548 struct resource *r;
549 struct goldfish_pipe_dev *dev = pipe_dev;
550
551 /* not thread safe, but this should not happen */
552 WARN_ON(dev->base != NULL);
553
554 spin_lock_init(&dev->lock);
555
556 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
557 if (r == NULL || resource_size(r) < PAGE_SIZE) {
558 dev_err(&pdev->dev, "can't allocate i/o page\n");
559 return -EINVAL;
560 }
561 dev->base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE);
562 if (dev->base == NULL) {
563 dev_err(&pdev->dev, "ioremap failed\n");
564 return -EINVAL;
565 }
566
567 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
568 if (r == NULL) {
569 err = -EINVAL;
570 goto error;
571 }
572 dev->irq = r->start;
573
574 err = devm_request_irq(&pdev->dev, dev->irq, goldfish_pipe_interrupt,
575 IRQF_SHARED, "goldfish_pipe", dev);
576 if (err) {
577 dev_err(&pdev->dev, "unable to allocate IRQ\n");
578 goto error;
579 }
580
581 err = misc_register(&goldfish_pipe_device);
582 if (err) {
583 dev_err(&pdev->dev, "unable to register device\n");
584 goto error;
585 }
586 setup_access_params_addr(pdev, dev);
587 return 0;
588
589error:
590 dev->base = NULL;
591 return err;
592}
593
594static int goldfish_pipe_remove(struct platform_device *pdev)
595{
596 struct goldfish_pipe_dev *dev = pipe_dev;
597 misc_deregister(&goldfish_pipe_device);
598 dev->base = NULL;
599 return 0;
600}
601
602static struct platform_driver goldfish_pipe = {
603 .probe = goldfish_pipe_probe,
604 .remove = goldfish_pipe_remove,
605 .driver = {
606 .name = "goldfish_pipe"
607 }
608};
609
610module_platform_driver(goldfish_pipe);
611MODULE_AUTHOR("David Turner <digit@google.com>");
612MODULE_LICENSE("GPL");
diff --git a/drivers/platform/goldfish/pdev_bus.c b/drivers/platform/goldfish/pdev_bus.c
new file mode 100644
index 000000000000..92cc4cfafde5
--- /dev/null
+++ b/drivers/platform/goldfish/pdev_bus.c
@@ -0,0 +1,240 @@
1/*
2 * Copyright (C) 2007 Google, Inc.
3 * Copyright (C) 2011 Intel, Inc.
4 * Copyright (C) 2013 Intel, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/interrupt.h>
20#include <linux/irq.h>
21#include <linux/platform_device.h>
22#include <linux/slab.h>
23#include <linux/io.h>
24
25#define PDEV_BUS_OP_DONE (0x00)
26#define PDEV_BUS_OP_REMOVE_DEV (0x04)
27#define PDEV_BUS_OP_ADD_DEV (0x08)
28
29#define PDEV_BUS_OP_INIT (0x00)
30
31#define PDEV_BUS_OP (0x00)
32#define PDEV_BUS_GET_NAME (0x04)
33#define PDEV_BUS_NAME_LEN (0x08)
34#define PDEV_BUS_ID (0x0c)
35#define PDEV_BUS_IO_BASE (0x10)
36#define PDEV_BUS_IO_SIZE (0x14)
37#define PDEV_BUS_IRQ (0x18)
38#define PDEV_BUS_IRQ_COUNT (0x1c)
39
40struct pdev_bus_dev {
41 struct list_head list;
42 struct platform_device pdev;
43 struct resource resources[0];
44};
45
46static void goldfish_pdev_worker(struct work_struct *work);
47
48static void __iomem *pdev_bus_base;
49static unsigned long pdev_bus_addr;
50static unsigned long pdev_bus_len;
51static u32 pdev_bus_irq;
52static LIST_HEAD(pdev_bus_new_devices);
53static LIST_HEAD(pdev_bus_registered_devices);
54static LIST_HEAD(pdev_bus_removed_devices);
55static DECLARE_WORK(pdev_bus_worker, goldfish_pdev_worker);
56
57
58static void goldfish_pdev_worker(struct work_struct *work)
59{
60 int ret;
61 struct pdev_bus_dev *pos, *n;
62
63 list_for_each_entry_safe(pos, n, &pdev_bus_removed_devices, list) {
64 list_del(&pos->list);
65 platform_device_unregister(&pos->pdev);
66 kfree(pos);
67 }
68 list_for_each_entry_safe(pos, n, &pdev_bus_new_devices, list) {
69 list_del(&pos->list);
70 ret = platform_device_register(&pos->pdev);
71 if (ret)
72 pr_err("goldfish_pdev_worker failed to register device, %s\n",
73 pos->pdev.name);
74 list_add_tail(&pos->list, &pdev_bus_registered_devices);
75 }
76}
77
78static void goldfish_pdev_remove(void)
79{
80 struct pdev_bus_dev *pos, *n;
81 u32 base;
82
83 base = readl(pdev_bus_base + PDEV_BUS_IO_BASE);
84
85 list_for_each_entry_safe(pos, n, &pdev_bus_new_devices, list) {
86 if (pos->resources[0].start == base) {
87 list_del(&pos->list);
88 kfree(pos);
89 return;
90 }
91 }
92 list_for_each_entry_safe(pos, n, &pdev_bus_registered_devices, list) {
93 if (pos->resources[0].start == base) {
94 list_del(&pos->list);
95 list_add_tail(&pos->list, &pdev_bus_removed_devices);
96 schedule_work(&pdev_bus_worker);
97 return;
98 }
99 };
100 pr_err("goldfish_pdev_remove could not find device at %x\n", base);
101}
102
103static int goldfish_new_pdev(void)
104{
105 struct pdev_bus_dev *dev;
106 u32 name_len;
107 u32 irq = -1, irq_count;
108 int resource_count = 2;
109 u32 base;
110 char *name;
111
112 base = readl(pdev_bus_base + PDEV_BUS_IO_BASE);
113
114 irq_count = readl(pdev_bus_base + PDEV_BUS_IRQ_COUNT);
115 name_len = readl(pdev_bus_base + PDEV_BUS_NAME_LEN);
116 if (irq_count)
117 resource_count++;
118
119 dev = kzalloc(sizeof(*dev) +
120 sizeof(struct resource) * resource_count +
121 name_len + 1 + sizeof(*dev->pdev.dev.dma_mask), GFP_ATOMIC);
122 if (dev == NULL)
123 return -ENOMEM;
124
125 dev->pdev.num_resources = resource_count;
126 dev->pdev.resource = (struct resource *)(dev + 1);
127 dev->pdev.name = name = (char *)(dev->pdev.resource + resource_count);
128 dev->pdev.dev.coherent_dma_mask = ~0;
129 dev->pdev.dev.dma_mask = (void *)(dev->pdev.name + name_len + 1);
130 *dev->pdev.dev.dma_mask = ~0;
131
132 writel((unsigned long)name, pdev_bus_base + PDEV_BUS_GET_NAME);
133 name[name_len] = '\0';
134 dev->pdev.id = readl(pdev_bus_base + PDEV_BUS_ID);
135 dev->pdev.resource[0].start = base;
136 dev->pdev.resource[0].end = base +
137 readl(pdev_bus_base + PDEV_BUS_IO_SIZE) - 1;
138 dev->pdev.resource[0].flags = IORESOURCE_MEM;
139 if (irq_count) {
140 irq = readl(pdev_bus_base + PDEV_BUS_IRQ);
141 dev->pdev.resource[1].start = irq;
142 dev->pdev.resource[1].end = irq + irq_count - 1;
143 dev->pdev.resource[1].flags = IORESOURCE_IRQ;
144 }
145
146 pr_debug("goldfish_new_pdev %s at %x irq %d\n", name, base, irq);
147 list_add_tail(&dev->list, &pdev_bus_new_devices);
148 schedule_work(&pdev_bus_worker);
149
150 return 0;
151}
152
153static irqreturn_t goldfish_pdev_bus_interrupt(int irq, void *dev_id)
154{
155 irqreturn_t ret = IRQ_NONE;
156 while (1) {
157 u32 op = readl(pdev_bus_base + PDEV_BUS_OP);
158 switch (op) {
159 case PDEV_BUS_OP_DONE:
160 return IRQ_NONE;
161
162 case PDEV_BUS_OP_REMOVE_DEV:
163 goldfish_pdev_remove();
164 break;
165
166 case PDEV_BUS_OP_ADD_DEV:
167 goldfish_new_pdev();
168 break;
169 }
170 ret = IRQ_HANDLED;
171 }
172 return ret;
173}
174
175static int goldfish_pdev_bus_probe(struct platform_device *pdev)
176{
177 int ret;
178 struct resource *r;
179
180 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
181 if (r == NULL)
182 return -EINVAL;
183
184 pdev_bus_addr = r->start;
185 pdev_bus_len = resource_size(r);
186
187 if (request_mem_region(pdev_bus_addr, pdev_bus_len, "goldfish")) {
188 dev_err(&pdev->dev, "unable to reserve Goldfish MMIO.\n");
189 return -EBUSY;
190 }
191
192 pdev_bus_base = ioremap(pdev_bus_addr, pdev_bus_len);
193 if (pdev_bus_base == NULL) {
194 ret = -ENOMEM;
195 dev_err(&pdev->dev, "unable to map Goldfish MMIO.\n");
196 goto free_resources;
197 }
198
199 r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
200 if (r == NULL) {
201 ret = -ENOENT;
202 goto free_map;
203 }
204
205 pdev_bus_irq = r->start;
206
207 ret = request_irq(pdev_bus_irq, goldfish_pdev_bus_interrupt,
208 IRQF_SHARED, "goldfish_pdev_bus", pdev);
209 if (ret) {
210 dev_err(&pdev->dev, "unable to request Goldfish IRQ\n");
211 goto free_map;
212 }
213
214 writel(PDEV_BUS_OP_INIT, pdev_bus_base + PDEV_BUS_OP);
215 return 0;
216
217free_map:
218 iounmap(pdev_bus_base);
219free_resources:
220 release_mem_region(pdev_bus_addr, pdev_bus_len);
221 return ret;
222}
223
224static int goldfish_pdev_bus_remove(struct platform_device *pdev)
225{
226 iounmap(pdev_bus_base);
227 free_irq(pdev_bus_irq, pdev);
228 release_mem_region(pdev_bus_addr, pdev_bus_len);
229 return 0;
230}
231
232static struct platform_driver goldfish_pdev_bus_driver = {
233 .probe = goldfish_pdev_bus_probe,
234 .remove = goldfish_pdev_bus_remove,
235 .driver = {
236 .name = "goldfish_pdev_bus"
237 }
238};
239
240module_platform_driver(goldfish_pdev_bus_driver);
diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
index 836816b82cbc..8cb5d7f67ace 100644
--- a/drivers/power/generic-adc-battery.c
+++ b/drivers/power/generic-adc-battery.c
@@ -284,8 +284,8 @@ static int gab_probe(struct platform_device *pdev)
284 * based on the channel supported by consumer device. 284 * based on the channel supported by consumer device.
285 */ 285 */
286 for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { 286 for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
287 adc_bat->channel[chan] = iio_channel_get(dev_name(&pdev->dev), 287 adc_bat->channel[chan] = iio_channel_get(&pdev->dev,
288 gab_chan_name[chan]); 288 gab_chan_name[chan]);
289 if (IS_ERR(adc_bat->channel[chan])) { 289 if (IS_ERR(adc_bat->channel[chan])) {
290 ret = PTR_ERR(adc_bat->channel[chan]); 290 ret = PTR_ERR(adc_bat->channel[chan]);
291 adc_bat->channel[chan] = NULL; 291 adc_bat->channel[chan] = NULL;
diff --git a/drivers/power/lp8788-charger.c b/drivers/power/lp8788-charger.c
index e33d6b2a7a56..6d1f452810b8 100644
--- a/drivers/power/lp8788-charger.c
+++ b/drivers/power/lp8788-charger.c
@@ -580,7 +580,7 @@ static void lp8788_irq_unregister(struct platform_device *pdev,
580 } 580 }
581} 581}
582 582
583static void lp8788_setup_adc_channel(const char *consumer_name, 583static void lp8788_setup_adc_channel(struct device *dev,
584 struct lp8788_charger *pchg) 584 struct lp8788_charger *pchg)
585{ 585{
586 struct lp8788_charger_platform_data *pdata = pchg->pdata; 586 struct lp8788_charger_platform_data *pdata = pchg->pdata;
@@ -590,11 +590,11 @@ static void lp8788_setup_adc_channel(const char *consumer_name,
590 return; 590 return;
591 591
592 /* ADC channel for battery voltage */ 592 /* ADC channel for battery voltage */
593 chan = iio_channel_get(consumer_name, pdata->adc_vbatt); 593 chan = iio_channel_get(dev, pdata->adc_vbatt);
594 pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan; 594 pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan;
595 595
596 /* ADC channel for battery temperature */ 596 /* ADC channel for battery temperature */
597 chan = iio_channel_get(consumer_name, pdata->adc_batt_temp); 597 chan = iio_channel_get(dev, pdata->adc_batt_temp);
598 pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan; 598 pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan;
599} 599}
600 600
@@ -705,7 +705,7 @@ static int lp8788_charger_probe(struct platform_device *pdev)
705 if (ret) 705 if (ret)
706 return ret; 706 return ret;
707 707
708 lp8788_setup_adc_channel(pdev->name, pchg); 708 lp8788_setup_adc_channel(&pdev->dev, pchg);
709 709
710 ret = lp8788_psy_register(pdev, pchg); 710 ret = lp8788_psy_register(pdev, pchg);
711 if (ret) 711 if (ret)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 5e44eaabf457..aa64d5d3fb20 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1183,4 +1183,20 @@ config RTC_DRV_SNVS
1183 This driver can also be built as a module, if so, the module 1183 This driver can also be built as a module, if so, the module
1184 will be called "rtc-snvs". 1184 will be called "rtc-snvs".
1185 1185
1186comment "HID Sensor RTC drivers"
1187
1188config RTC_DRV_HID_SENSOR_TIME
1189 tristate "HID Sensor Time"
1190 depends on USB_HID
1191 select IIO
1192 select HID_SENSOR_HUB
1193 select HID_SENSOR_IIO_COMMON
1194 help
1195 Say yes here to build support for the HID Sensors of type Time.
1196 This drivers makes such sensors available as RTCs.
1197
1198 If this driver is compiled as a module, it will be named
1199 rtc-hid-sensor-time.
1200
1201
1186endif # RTC_CLASS 1202endif # RTC_CLASS
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index ec2988b00a44..60c0414d67fa 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_RTC_DRV_EM3027) += rtc-em3027.o
53obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 53obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
54obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 54obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
55obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o 55obj-$(CONFIG_RTC_DRV_GENERIC) += rtc-generic.o
56obj-$(CONFIG_RTC_DRV_HID_SENSOR_TIME) += rtc-hid-sensor-time.o
56obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o 57obj-$(CONFIG_RTC_DRV_IMXDI) += rtc-imxdi.o
57obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 58obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
58obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o 59obj-$(CONFIG_RTC_DRV_ISL12022) += rtc-isl12022.o
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
new file mode 100644
index 000000000000..31c5728ef629
--- /dev/null
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -0,0 +1,292 @@
1/*
2 * HID Sensor Time Driver
3 * Copyright (c) 2012, Alexander Holler.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19#include <linux/device.h>
20#include <linux/platform_device.h>
21#include <linux/module.h>
22#include <linux/hid-sensor-hub.h>
23#include <linux/iio/iio.h>
24#include <linux/rtc.h>
25
26/* Format: HID-SENSOR-usage_id_in_hex */
27/* Usage ID from spec for Time: 0x2000A0 */
28#define DRIVER_NAME "HID-SENSOR-2000a0" /* must be lowercase */
29
30enum hid_time_channel {
31 CHANNEL_SCAN_INDEX_YEAR,
32 CHANNEL_SCAN_INDEX_MONTH,
33 CHANNEL_SCAN_INDEX_DAY,
34 CHANNEL_SCAN_INDEX_HOUR,
35 CHANNEL_SCAN_INDEX_MINUTE,
36 CHANNEL_SCAN_INDEX_SECOND,
37 TIME_RTC_CHANNEL_MAX,
38};
39
40struct hid_time_state {
41 struct hid_sensor_hub_callbacks callbacks;
42 struct hid_sensor_common common_attributes;
43 struct hid_sensor_hub_attribute_info info[TIME_RTC_CHANNEL_MAX];
44 struct rtc_time last_time;
45 spinlock_t lock_last_time;
46 struct completion comp_last_time;
47 struct rtc_time time_buf;
48 struct rtc_device *rtc;
49};
50
51static const u32 hid_time_addresses[TIME_RTC_CHANNEL_MAX] = {
52 HID_USAGE_SENSOR_TIME_YEAR,
53 HID_USAGE_SENSOR_TIME_MONTH,
54 HID_USAGE_SENSOR_TIME_DAY,
55 HID_USAGE_SENSOR_TIME_HOUR,
56 HID_USAGE_SENSOR_TIME_MINUTE,
57 HID_USAGE_SENSOR_TIME_SECOND,
58};
59
60/* Channel names for verbose error messages */
61static const char * const hid_time_channel_names[TIME_RTC_CHANNEL_MAX] = {
62 "year", "month", "day", "hour", "minute", "second",
63};
64
65/* Callback handler to send event after all samples are received and captured */
66static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
67 unsigned usage_id, void *priv)
68{
69 unsigned long flags;
70 struct hid_time_state *time_state = platform_get_drvdata(priv);
71
72 spin_lock_irqsave(&time_state->lock_last_time, flags);
73 time_state->last_time = time_state->time_buf;
74 spin_unlock_irqrestore(&time_state->lock_last_time, flags);
75 complete(&time_state->comp_last_time);
76 return 0;
77}
78
79static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
80 unsigned usage_id, size_t raw_len,
81 char *raw_data, void *priv)
82{
83 struct hid_time_state *time_state = platform_get_drvdata(priv);
84 struct rtc_time *time_buf = &time_state->time_buf;
85
86 switch (usage_id) {
87 case HID_USAGE_SENSOR_TIME_YEAR:
88 time_buf->tm_year = *(u8 *)raw_data;
89 if (time_buf->tm_year < 70)
90 /* assume we are in 1970...2069 */
91 time_buf->tm_year += 100;
92 break;
93 case HID_USAGE_SENSOR_TIME_MONTH:
94 /* sensor sending the month as 1-12, we need 0-11 */
95 time_buf->tm_mon = *(u8 *)raw_data-1;
96 break;
97 case HID_USAGE_SENSOR_TIME_DAY:
98 time_buf->tm_mday = *(u8 *)raw_data;
99 break;
100 case HID_USAGE_SENSOR_TIME_HOUR:
101 time_buf->tm_hour = *(u8 *)raw_data;
102 break;
103 case HID_USAGE_SENSOR_TIME_MINUTE:
104 time_buf->tm_min = *(u8 *)raw_data;
105 break;
106 case HID_USAGE_SENSOR_TIME_SECOND:
107 time_buf->tm_sec = *(u8 *)raw_data;
108 break;
109 default:
110 return -EINVAL;
111 }
112 return 0;
113}
114
115/* small helper, haven't found any other way */
116static const char *hid_time_attrib_name(u32 attrib_id)
117{
118 static const char unknown[] = "unknown";
119 unsigned i;
120
121 for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
122 if (hid_time_addresses[i] == attrib_id)
123 return hid_time_channel_names[i];
124 }
125 return unknown; /* should never happen */
126}
127
128static int hid_time_parse_report(struct platform_device *pdev,
129 struct hid_sensor_hub_device *hsdev,
130 unsigned usage_id,
131 struct hid_time_state *time_state)
132{
133 int report_id, i;
134
135 for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i)
136 if (sensor_hub_input_get_attribute_info(hsdev,
137 HID_INPUT_REPORT, usage_id,
138 hid_time_addresses[i],
139 &time_state->info[i]) < 0)
140 return -EINVAL;
141 /* Check the (needed) attributes for sanity */
142 report_id = time_state->info[0].report_id;
143 if (report_id < 0) {
144 dev_err(&pdev->dev, "bad report ID!\n");
145 return -EINVAL;
146 }
147 for (i = 0; i < TIME_RTC_CHANNEL_MAX; ++i) {
148 if (time_state->info[i].report_id != report_id) {
149 dev_err(&pdev->dev,
150 "not all needed attributes inside the same report!\n");
151 return -EINVAL;
152 }
153 if (time_state->info[i].size != 1) {
154 dev_err(&pdev->dev,
155 "attribute '%s' not 8 bits wide!\n",
156 hid_time_attrib_name(
157 time_state->info[i].attrib_id));
158 return -EINVAL;
159 }
160 if (time_state->info[i].units !=
161 HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
162 /* allow attribute seconds with unit seconds */
163 !(time_state->info[i].attrib_id ==
164 HID_USAGE_SENSOR_TIME_SECOND &&
165 time_state->info[i].units ==
166 HID_USAGE_SENSOR_UNITS_SECOND)) {
167 dev_err(&pdev->dev,
168 "attribute '%s' hasn't a unit of type 'none'!\n",
169 hid_time_attrib_name(
170 time_state->info[i].attrib_id));
171 return -EINVAL;
172 }
173 if (time_state->info[i].unit_expo) {
174 dev_err(&pdev->dev,
175 "attribute '%s' hasn't a unit exponent of 1!\n",
176 hid_time_attrib_name(
177 time_state->info[i].attrib_id));
178 return -EINVAL;
179 }
180 }
181
182 return 0;
183}
184
185static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
186{
187 unsigned long flags;
188 struct hid_time_state *time_state =
189 platform_get_drvdata(to_platform_device(dev));
190 int ret;
191
192 INIT_COMPLETION(time_state->comp_last_time);
193 /* get a report with all values through requesting one value */
194 sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
195 HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
196 time_state->info[0].report_id);
197 /* wait for all values (event) */
198 ret = wait_for_completion_killable_timeout(
199 &time_state->comp_last_time, HZ*6);
200 if (ret > 0) {
201 /* no error */
202 spin_lock_irqsave(&time_state->lock_last_time, flags);
203 *tm = time_state->last_time;
204 spin_unlock_irqrestore(&time_state->lock_last_time, flags);
205 return 0;
206 }
207 if (!ret)
208 return -EIO; /* timeouted */
209 return ret; /* killed (-ERESTARTSYS) */
210}
211
212static const struct rtc_class_ops hid_time_rtc_ops = {
213 .read_time = hid_rtc_read_time,
214};
215
216static int hid_time_probe(struct platform_device *pdev)
217{
218 int ret = 0;
219 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
220 struct hid_time_state *time_state = devm_kzalloc(&pdev->dev,
221 sizeof(struct hid_time_state), GFP_KERNEL);
222
223 if (time_state == NULL)
224 return -ENOMEM;
225
226 platform_set_drvdata(pdev, time_state);
227
228 spin_lock_init(&time_state->lock_last_time);
229 init_completion(&time_state->comp_last_time);
230 time_state->common_attributes.hsdev = hsdev;
231 time_state->common_attributes.pdev = pdev;
232
233 ret = hid_sensor_parse_common_attributes(hsdev,
234 HID_USAGE_SENSOR_TIME,
235 &time_state->common_attributes);
236 if (ret) {
237 dev_err(&pdev->dev, "failed to setup common attributes!\n");
238 return ret;
239 }
240
241 ret = hid_time_parse_report(pdev, hsdev, HID_USAGE_SENSOR_TIME,
242 time_state);
243 if (ret) {
244 dev_err(&pdev->dev, "failed to setup attributes!\n");
245 return ret;
246 }
247
248 time_state->callbacks.send_event = hid_time_proc_event;
249 time_state->callbacks.capture_sample = hid_time_capture_sample;
250 time_state->callbacks.pdev = pdev;
251 ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_TIME,
252 &time_state->callbacks);
253 if (ret < 0) {
254 dev_err(&pdev->dev, "register callback failed!\n");
255 return ret;
256 }
257
258 time_state->rtc = rtc_device_register("hid-sensor-time",
259 &pdev->dev, &hid_time_rtc_ops, THIS_MODULE);
260
261 if (IS_ERR(time_state->rtc)) {
262 dev_err(&pdev->dev, "rtc device register failed!\n");
263 return PTR_ERR(time_state->rtc);
264 }
265
266 return ret;
267}
268
269static int hid_time_remove(struct platform_device *pdev)
270{
271 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
272 struct hid_time_state *time_state = platform_get_drvdata(pdev);
273
274 rtc_device_unregister(time_state->rtc);
275 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
276
277 return 0;
278}
279
280static struct platform_driver hid_time_platform_driver = {
281 .driver = {
282 .name = DRIVER_NAME,
283 .owner = THIS_MODULE,
284 },
285 .probe = hid_time_probe,
286 .remove = hid_time_remove,
287};
288module_platform_driver(hid_time_platform_driver);
289
290MODULE_DESCRIPTION("HID Sensor Time");
291MODULE_AUTHOR("Alexander Holler <holler@ahsoftware.de>");
292MODULE_LICENSE("GPL");
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 329bdb42109f..3a7965d6ac28 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -74,8 +74,6 @@ source "drivers/staging/iio/Kconfig"
74 74
75source "drivers/staging/zram/Kconfig" 75source "drivers/staging/zram/Kconfig"
76 76
77source "drivers/staging/zcache/Kconfig"
78
79source "drivers/staging/zsmalloc/Kconfig" 77source "drivers/staging/zsmalloc/Kconfig"
80 78
81source "drivers/staging/wlags49_h2/Kconfig" 79source "drivers/staging/wlags49_h2/Kconfig"
@@ -128,8 +126,6 @@ source "drivers/staging/csr/Kconfig"
128 126
129source "drivers/staging/omap-thermal/Kconfig" 127source "drivers/staging/omap-thermal/Kconfig"
130 128
131source "drivers/staging/ramster/Kconfig"
132
133source "drivers/staging/silicom/Kconfig" 129source "drivers/staging/silicom/Kconfig"
134 130
135source "drivers/staging/ced1401/Kconfig" 131source "drivers/staging/ced1401/Kconfig"
@@ -142,4 +138,8 @@ source "drivers/staging/sb105x/Kconfig"
142 138
143source "drivers/staging/fwserial/Kconfig" 139source "drivers/staging/fwserial/Kconfig"
144 140
141source "drivers/staging/zcache/Kconfig"
142
143source "drivers/staging/goldfish/Kconfig"
144
145endif # STAGING 145endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index c7ec486680f7..5971865d0c61 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -31,7 +31,6 @@ obj-$(CONFIG_VME_BUS) += vme/
31obj-$(CONFIG_DX_SEP) += sep/ 31obj-$(CONFIG_DX_SEP) += sep/
32obj-$(CONFIG_IIO) += iio/ 32obj-$(CONFIG_IIO) += iio/
33obj-$(CONFIG_ZRAM) += zram/ 33obj-$(CONFIG_ZRAM) += zram/
34obj-$(CONFIG_ZCACHE) += zcache/
35obj-$(CONFIG_ZSMALLOC) += zsmalloc/ 34obj-$(CONFIG_ZSMALLOC) += zsmalloc/
36obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/ 35obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
37obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/ 36obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
@@ -56,10 +55,11 @@ obj-$(CONFIG_USB_G_CCG) += ccg/
56obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/ 55obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/
57obj-$(CONFIG_CSR_WIFI) += csr/ 56obj-$(CONFIG_CSR_WIFI) += csr/
58obj-$(CONFIG_OMAP_BANDGAP) += omap-thermal/ 57obj-$(CONFIG_OMAP_BANDGAP) += omap-thermal/
59obj-$(CONFIG_ZCACHE2) += ramster/
60obj-$(CONFIG_NET_VENDOR_SILICOM) += silicom/ 58obj-$(CONFIG_NET_VENDOR_SILICOM) += silicom/
61obj-$(CONFIG_CED1401) += ced1401/ 59obj-$(CONFIG_CED1401) += ced1401/
62obj-$(CONFIG_DRM_IMX) += imx-drm/ 60obj-$(CONFIG_DRM_IMX) += imx-drm/
63obj-$(CONFIG_DGRP) += dgrp/ 61obj-$(CONFIG_DGRP) += dgrp/
64obj-$(CONFIG_SB105X) += sb105x/ 62obj-$(CONFIG_SB105X) += sb105x/
65obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/ 63obj-$(CONFIG_FIREWIRE_SERIAL) += fwserial/
64obj-$(CONFIG_ZCACHE) += zcache/
65obj-$(CONFIG_GOLDFISH) += goldfish/
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 0ce50d12c30f..465a28c08f20 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -11,19 +11,42 @@ if ANDROID
11config ANDROID_BINDER_IPC 11config ANDROID_BINDER_IPC
12 bool "Android Binder IPC Driver" 12 bool "Android Binder IPC Driver"
13 default n 13 default n
14 ---help---
15 Binder is used in Android for both communication between processes,
16 and remote method invocation.
17
18 This means one Android process can call a method/routine in another
19 Android process, using Binder to identify, invoke and pass arguments
20 between said processes.
14 21
15config ASHMEM 22config ASHMEM
16 bool "Enable the Anonymous Shared Memory Subsystem" 23 bool "Enable the Anonymous Shared Memory Subsystem"
17 default n 24 default n
18 depends on SHMEM || TINY_SHMEM 25 depends on SHMEM || TINY_SHMEM
19 help 26 ---help---
20 The ashmem subsystem is a new shared memory allocator, similar to 27 The ashmem subsystem is a new shared memory allocator, similar to
21 POSIX SHM but with different behavior and sporting a simpler 28 POSIX SHM but with different behavior and sporting a simpler
22 file-based API. 29 file-based API.
23 30
31 It is, in theory, a good memory allocator for low-memory devices,
32 because it can discard shared memory units when under memory pressure.
33
24config ANDROID_LOGGER 34config ANDROID_LOGGER
25 tristate "Android log driver" 35 tristate "Android log driver"
26 default n 36 default n
37 ---help---
38 This adds support for system-wide logging using four log buffers.
39
40 These are:
41
42 1: main
43 2: events
44 3: radio
45 4: system
46
47 Log reading and writing is performed via normal Linux reads and
48 optimized writes. This optimization avoids logging having too
49 much overhead in the system.
27 50
28config ANDROID_TIMED_OUTPUT 51config ANDROID_TIMED_OUTPUT
29 bool "Timed output class driver" 52 bool "Timed output class driver"
@@ -38,13 +61,13 @@ config ANDROID_LOW_MEMORY_KILLER
38 bool "Android Low Memory Killer" 61 bool "Android Low Memory Killer"
39 default N 62 default N
40 ---help--- 63 ---help---
41 Register processes to be killed when memory is low 64 Registers processes to be killed when memory is low
42 65
43config ANDROID_INTF_ALARM_DEV 66config ANDROID_INTF_ALARM_DEV
44 bool "Android alarm driver" 67 bool "Android alarm driver"
45 depends on RTC_CLASS 68 depends on RTC_CLASS
46 default n 69 default n
47 help 70 ---help---
48 Provides non-wakeup and rtc backed wakeup alarms based on rtc or 71 Provides non-wakeup and rtc backed wakeup alarms based on rtc or
49 elapsed realtime, and a non-wakeup alarm on the monotonic clock. 72 elapsed realtime, and a non-wakeup alarm on the monotonic clock.
50 Also exports the alarm interface to user-space. 73 Also exports the alarm interface to user-space.
diff --git a/drivers/staging/android/alarm-dev.c b/drivers/staging/android/alarm-dev.c
index a9b293ff3cc8..ceb1c643753d 100644
--- a/drivers/staging/android/alarm-dev.c
+++ b/drivers/staging/android/alarm-dev.c
@@ -42,10 +42,6 @@ do { \
42 ANDROID_ALARM_RTC_WAKEUP_MASK | \ 42 ANDROID_ALARM_RTC_WAKEUP_MASK | \
43 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK) 43 ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP_MASK)
44 44
45/* support old userspace code */
46#define ANDROID_ALARM_SET_OLD _IOW('a', 2, time_t) /* set alarm */
47#define ANDROID_ALARM_SET_AND_WAIT_OLD _IOW('a', 3, time_t)
48
49static int alarm_opened; 45static int alarm_opened;
50static DEFINE_SPINLOCK(alarm_slock); 46static DEFINE_SPINLOCK(alarm_slock);
51static struct wakeup_source alarm_wake_lock; 47static struct wakeup_source alarm_wake_lock;
@@ -96,18 +92,116 @@ static void devalarm_cancel(struct devalarm *alrm)
96 hrtimer_cancel(&alrm->u.hrt); 92 hrtimer_cancel(&alrm->u.hrt);
97} 93}
98 94
95static void alarm_clear(enum android_alarm_type alarm_type)
96{
97 uint32_t alarm_type_mask = 1U << alarm_type;
98 unsigned long flags;
99 99
100static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 100 spin_lock_irqsave(&alarm_slock, flags);
101 alarm_dbg(IO, "alarm %d clear\n", alarm_type);
102 devalarm_try_to_cancel(&alarms[alarm_type]);
103 if (alarm_pending) {
104 alarm_pending &= ~alarm_type_mask;
105 if (!alarm_pending && !wait_pending)
106 __pm_relax(&alarm_wake_lock);
107 }
108 alarm_enabled &= ~alarm_type_mask;
109 spin_unlock_irqrestore(&alarm_slock, flags);
110
111}
112
113static void alarm_set(enum android_alarm_type alarm_type,
114 struct timespec *ts)
101{ 115{
102 int rv = 0; 116 uint32_t alarm_type_mask = 1U << alarm_type;
103 unsigned long flags; 117 unsigned long flags;
104 struct timespec new_alarm_time; 118
105 struct timespec new_rtc_time; 119 spin_lock_irqsave(&alarm_slock, flags);
106 struct timespec tmp_time; 120 alarm_dbg(IO, "alarm %d set %ld.%09ld\n",
121 alarm_type, ts->tv_sec, ts->tv_nsec);
122 alarm_enabled |= alarm_type_mask;
123 devalarm_start(&alarms[alarm_type], timespec_to_ktime(*ts));
124 spin_unlock_irqrestore(&alarm_slock, flags);
125}
126
127static int alarm_wait(void)
128{
129 unsigned long flags;
130 int rv = 0;
131
132 spin_lock_irqsave(&alarm_slock, flags);
133 alarm_dbg(IO, "alarm wait\n");
134 if (!alarm_pending && wait_pending) {
135 __pm_relax(&alarm_wake_lock);
136 wait_pending = 0;
137 }
138 spin_unlock_irqrestore(&alarm_slock, flags);
139
140 rv = wait_event_interruptible(alarm_wait_queue, alarm_pending);
141 if (rv)
142 return rv;
143
144 spin_lock_irqsave(&alarm_slock, flags);
145 rv = alarm_pending;
146 wait_pending = 1;
147 alarm_pending = 0;
148 spin_unlock_irqrestore(&alarm_slock, flags);
149
150 return rv;
151}
152
153static int alarm_set_rtc(struct timespec *ts)
154{
107 struct rtc_time new_rtc_tm; 155 struct rtc_time new_rtc_tm;
108 struct rtc_device *rtc_dev; 156 struct rtc_device *rtc_dev;
157 unsigned long flags;
158 int rv = 0;
159
160 rtc_time_to_tm(ts->tv_sec, &new_rtc_tm);
161 rtc_dev = alarmtimer_get_rtcdev();
162 rv = do_settimeofday(ts);
163 if (rv < 0)
164 return rv;
165 if (rtc_dev)
166 rv = rtc_set_time(rtc_dev, &new_rtc_tm);
167
168 spin_lock_irqsave(&alarm_slock, flags);
169 alarm_pending |= ANDROID_ALARM_TIME_CHANGE_MASK;
170 wake_up(&alarm_wait_queue);
171 spin_unlock_irqrestore(&alarm_slock, flags);
172
173 return rv;
174}
175
176static int alarm_get_time(enum android_alarm_type alarm_type,
177 struct timespec *ts)
178{
179 int rv = 0;
180
181 switch (alarm_type) {
182 case ANDROID_ALARM_RTC_WAKEUP:
183 case ANDROID_ALARM_RTC:
184 getnstimeofday(ts);
185 break;
186 case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP:
187 case ANDROID_ALARM_ELAPSED_REALTIME:
188 get_monotonic_boottime(ts);
189 break;
190 case ANDROID_ALARM_SYSTEMTIME:
191 ktime_get_ts(ts);
192 break;
193 default:
194 rv = -EINVAL;
195 }
196 return rv;
197}
198
199static long alarm_do_ioctl(struct file *file, unsigned int cmd,
200 struct timespec *ts)
201{
202 int rv = 0;
203 unsigned long flags;
109 enum android_alarm_type alarm_type = ANDROID_ALARM_IOCTL_TO_TYPE(cmd); 204 enum android_alarm_type alarm_type = ANDROID_ALARM_IOCTL_TO_TYPE(cmd);
110 uint32_t alarm_type_mask = 1U << alarm_type;
111 205
112 if (alarm_type >= ANDROID_ALARM_TYPE_COUNT) 206 if (alarm_type >= ANDROID_ALARM_TYPE_COUNT)
113 return -EINVAL; 207 return -EINVAL;
@@ -130,115 +224,89 @@ static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
130 224
131 switch (ANDROID_ALARM_BASE_CMD(cmd)) { 225 switch (ANDROID_ALARM_BASE_CMD(cmd)) {
132 case ANDROID_ALARM_CLEAR(0): 226 case ANDROID_ALARM_CLEAR(0):
133 spin_lock_irqsave(&alarm_slock, flags); 227 alarm_clear(alarm_type);
134 alarm_dbg(IO, "alarm %d clear\n", alarm_type);
135 devalarm_try_to_cancel(&alarms[alarm_type]);
136 if (alarm_pending) {
137 alarm_pending &= ~alarm_type_mask;
138 if (!alarm_pending && !wait_pending)
139 __pm_relax(&alarm_wake_lock);
140 }
141 alarm_enabled &= ~alarm_type_mask;
142 spin_unlock_irqrestore(&alarm_slock, flags);
143 break; 228 break;
144
145 case ANDROID_ALARM_SET_OLD:
146 case ANDROID_ALARM_SET_AND_WAIT_OLD:
147 if (get_user(new_alarm_time.tv_sec, (int __user *)arg)) {
148 rv = -EFAULT;
149 goto err1;
150 }
151 new_alarm_time.tv_nsec = 0;
152 goto from_old_alarm_set;
153
154 case ANDROID_ALARM_SET_AND_WAIT(0):
155 case ANDROID_ALARM_SET(0): 229 case ANDROID_ALARM_SET(0):
156 if (copy_from_user(&new_alarm_time, (void __user *)arg, 230 alarm_set(alarm_type, ts);
157 sizeof(new_alarm_time))) { 231 break;
158 rv = -EFAULT; 232 case ANDROID_ALARM_SET_AND_WAIT(0):
159 goto err1; 233 alarm_set(alarm_type, ts);
160 }
161from_old_alarm_set:
162 spin_lock_irqsave(&alarm_slock, flags);
163 alarm_dbg(IO, "alarm %d set %ld.%09ld\n",
164 alarm_type,
165 new_alarm_time.tv_sec, new_alarm_time.tv_nsec);
166 alarm_enabled |= alarm_type_mask;
167 devalarm_start(&alarms[alarm_type],
168 timespec_to_ktime(new_alarm_time));
169 spin_unlock_irqrestore(&alarm_slock, flags);
170 if (ANDROID_ALARM_BASE_CMD(cmd) != ANDROID_ALARM_SET_AND_WAIT(0)
171 && cmd != ANDROID_ALARM_SET_AND_WAIT_OLD)
172 break;
173 /* fall though */ 234 /* fall though */
174 case ANDROID_ALARM_WAIT: 235 case ANDROID_ALARM_WAIT:
175 spin_lock_irqsave(&alarm_slock, flags); 236 rv = alarm_wait();
176 alarm_dbg(IO, "alarm wait\n");
177 if (!alarm_pending && wait_pending) {
178 __pm_relax(&alarm_wake_lock);
179 wait_pending = 0;
180 }
181 spin_unlock_irqrestore(&alarm_slock, flags);
182 rv = wait_event_interruptible(alarm_wait_queue, alarm_pending);
183 if (rv)
184 goto err1;
185 spin_lock_irqsave(&alarm_slock, flags);
186 rv = alarm_pending;
187 wait_pending = 1;
188 alarm_pending = 0;
189 spin_unlock_irqrestore(&alarm_slock, flags);
190 break; 237 break;
191 case ANDROID_ALARM_SET_RTC: 238 case ANDROID_ALARM_SET_RTC:
192 if (copy_from_user(&new_rtc_time, (void __user *)arg, 239 rv = alarm_set_rtc(ts);
193 sizeof(new_rtc_time))) {
194 rv = -EFAULT;
195 goto err1;
196 }
197 rtc_time_to_tm(new_rtc_time.tv_sec, &new_rtc_tm);
198 rtc_dev = alarmtimer_get_rtcdev();
199 rv = do_settimeofday(&new_rtc_time);
200 if (rv < 0)
201 goto err1;
202 if (rtc_dev)
203 rv = rtc_set_time(rtc_dev, &new_rtc_tm);
204 spin_lock_irqsave(&alarm_slock, flags);
205 alarm_pending |= ANDROID_ALARM_TIME_CHANGE_MASK;
206 wake_up(&alarm_wait_queue);
207 spin_unlock_irqrestore(&alarm_slock, flags);
208 if (rv < 0)
209 goto err1;
210 break; 240 break;
211 case ANDROID_ALARM_GET_TIME(0): 241 case ANDROID_ALARM_GET_TIME(0):
212 switch (alarm_type) { 242 rv = alarm_get_time(alarm_type, ts);
213 case ANDROID_ALARM_RTC_WAKEUP:
214 case ANDROID_ALARM_RTC:
215 getnstimeofday(&tmp_time);
216 break;
217 case ANDROID_ALARM_ELAPSED_REALTIME_WAKEUP:
218 case ANDROID_ALARM_ELAPSED_REALTIME:
219 get_monotonic_boottime(&tmp_time);
220 break;
221 case ANDROID_ALARM_SYSTEMTIME:
222 ktime_get_ts(&tmp_time);
223 break;
224 default:
225 rv = -EINVAL;
226 goto err1;
227 }
228 if (copy_to_user((void __user *)arg, &tmp_time,
229 sizeof(tmp_time))) {
230 rv = -EFAULT;
231 goto err1;
232 }
233 break; 243 break;
234 244
235 default: 245 default:
236 rv = -EINVAL; 246 rv = -EINVAL;
237 } 247 }
238err1:
239 return rv; 248 return rv;
240} 249}
241 250
251static long alarm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
252{
253
254 struct timespec ts;
255 int rv;
256
257 switch (ANDROID_ALARM_BASE_CMD(cmd)) {
258 case ANDROID_ALARM_SET_AND_WAIT(0):
259 case ANDROID_ALARM_SET(0):
260 case ANDROID_ALARM_SET_RTC:
261 if (copy_from_user(&ts, (void __user *)arg, sizeof(ts)))
262 return -EFAULT;
263 break;
264 }
265
266 rv = alarm_do_ioctl(file, cmd, &ts);
267
268 switch (ANDROID_ALARM_BASE_CMD(cmd)) {
269 case ANDROID_ALARM_GET_TIME(0):
270 if (copy_to_user((void __user *)arg, &ts, sizeof(ts)))
271 return -EFAULT;
272 break;
273 }
274
275 return rv;
276}
277#ifdef CONFIG_COMPAT
278static long alarm_compat_ioctl(struct file *file, unsigned int cmd,
279 unsigned long arg)
280{
281
282 struct timespec ts;
283 int rv;
284
285 switch (ANDROID_ALARM_BASE_CMD(cmd)) {
286 case ANDROID_ALARM_SET_AND_WAIT_COMPAT(0):
287 case ANDROID_ALARM_SET_COMPAT(0):
288 case ANDROID_ALARM_SET_RTC_COMPAT:
289 if (compat_get_timespec(&ts, (void __user *)arg))
290 return -EFAULT;
291 /* fall through */
292 case ANDROID_ALARM_GET_TIME_COMPAT(0):
293 cmd = ANDROID_ALARM_COMPAT_TO_NORM(cmd);
294 break;
295 }
296
297 rv = alarm_do_ioctl(file, cmd, &ts);
298
299 switch (ANDROID_ALARM_BASE_CMD(cmd)) {
300 case ANDROID_ALARM_GET_TIME(0): /* NOTE: we modified cmd above */
301 if (compat_put_timespec(&ts, (void __user *)arg))
302 return -EFAULT;
303 break;
304 }
305
306 return rv;
307}
308#endif
309
242static int alarm_open(struct inode *inode, struct file *file) 310static int alarm_open(struct inode *inode, struct file *file)
243{ 311{
244 file->private_data = NULL; 312 file->private_data = NULL;
@@ -319,6 +387,9 @@ static const struct file_operations alarm_fops = {
319 .unlocked_ioctl = alarm_ioctl, 387 .unlocked_ioctl = alarm_ioctl,
320 .open = alarm_open, 388 .open = alarm_open,
321 .release = alarm_release, 389 .release = alarm_release,
390#ifdef CONFIG_COMPAT
391 .compat_ioctl = alarm_compat_ioctl,
392#endif
322}; 393};
323 394
324static struct miscdevice alarm_device = { 395static struct miscdevice alarm_device = {
diff --git a/drivers/staging/android/android_alarm.h b/drivers/staging/android/android_alarm.h
index d0cafd637199..4fd32f337f9c 100644
--- a/drivers/staging/android/android_alarm.h
+++ b/drivers/staging/android/android_alarm.h
@@ -18,6 +18,7 @@
18 18
19#include <linux/ioctl.h> 19#include <linux/ioctl.h>
20#include <linux/time.h> 20#include <linux/time.h>
21#include <linux/compat.h>
21 22
22enum android_alarm_type { 23enum android_alarm_type {
23 /* return code bit numbers or set alarm arg */ 24 /* return code bit numbers or set alarm arg */
@@ -59,4 +60,22 @@ enum android_alarm_return_flags {
59#define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0))) 60#define ANDROID_ALARM_BASE_CMD(cmd) (cmd & ~(_IOC(0, 0, 0xf0, 0)))
60#define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4) 61#define ANDROID_ALARM_IOCTL_TO_TYPE(cmd) (_IOC_NR(cmd) >> 4)
61 62
63
64#ifdef CONFIG_COMPAT
65#define ANDROID_ALARM_SET_COMPAT(type) ALARM_IOW(2, type, \
66 struct compat_timespec)
67#define ANDROID_ALARM_SET_AND_WAIT_COMPAT(type) ALARM_IOW(3, type, \
68 struct compat_timespec)
69#define ANDROID_ALARM_GET_TIME_COMPAT(type) ALARM_IOW(4, type, \
70 struct compat_timespec)
71#define ANDROID_ALARM_SET_RTC_COMPAT _IOW('a', 5, \
72 struct compat_timespec)
73#define ANDROID_ALARM_IOCTL_NR(cmd) (_IOC_NR(cmd) & ((1<<4)-1))
74#define ANDROID_ALARM_COMPAT_TO_NORM(cmd) \
75 ALARM_IOW(ANDROID_ALARM_IOCTL_NR(cmd), \
76 ANDROID_ALARM_IOCTL_TO_TYPE(cmd), \
77 struct timespec)
78
79#endif
80
62#endif 81#endif
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index 2d12e8a1f82e..538ebe213129 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -3227,7 +3227,7 @@ static void print_binder_proc(struct seq_file *m,
3227 m->count = start_pos; 3227 m->count = start_pos;
3228} 3228}
3229 3229
3230static const char *binder_return_strings[] = { 3230static const char * const binder_return_strings[] = {
3231 "BR_ERROR", 3231 "BR_ERROR",
3232 "BR_OK", 3232 "BR_OK",
3233 "BR_TRANSACTION", 3233 "BR_TRANSACTION",
@@ -3248,7 +3248,7 @@ static const char *binder_return_strings[] = {
3248 "BR_FAILED_REPLY" 3248 "BR_FAILED_REPLY"
3249}; 3249};
3250 3250
3251static const char *binder_command_strings[] = { 3251static const char * const binder_command_strings[] = {
3252 "BC_TRANSACTION", 3252 "BC_TRANSACTION",
3253 "BC_REPLY", 3253 "BC_REPLY",
3254 "BC_ACQUIRE_RESULT", 3254 "BC_ACQUIRE_RESULT",
@@ -3268,7 +3268,7 @@ static const char *binder_command_strings[] = {
3268 "BC_DEAD_BINDER_DONE" 3268 "BC_DEAD_BINDER_DONE"
3269}; 3269};
3270 3270
3271static const char *binder_objstat_strings[] = { 3271static const char * const binder_objstat_strings[] = {
3272 "proc", 3272 "proc",
3273 "thread", 3273 "thread",
3274 "node", 3274 "node",
diff --git a/drivers/staging/android/binder.h b/drivers/staging/android/binder.h
index 2f7d195d8b15..76ead8dac265 100644
--- a/drivers/staging/android/binder.h
+++ b/drivers/staging/android/binder.h
@@ -163,7 +163,7 @@ struct binder_pri_ptr_cookie {
163 void *cookie; 163 void *cookie;
164}; 164};
165 165
166enum BinderDriverReturnProtocol { 166enum binder_driver_return_protocol {
167 BR_ERROR = _IOR('r', 0, int), 167 BR_ERROR = _IOR('r', 0, int),
168 /* 168 /*
169 * int: error code 169 * int: error code
@@ -251,7 +251,7 @@ enum BinderDriverReturnProtocol {
251 */ 251 */
252}; 252};
253 253
254enum BinderDriverCommandProtocol { 254enum binder_driver_command_protocol {
255 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data), 255 BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data),
256 BC_REPLY = _IOW('c', 1, struct binder_transaction_data), 256 BC_REPLY = _IOW('c', 1, struct binder_transaction_data),
257 /* 257 /*
diff --git a/drivers/staging/asus_oled/asus_oled.c b/drivers/staging/asus_oled/asus_oled.c
index 00185478647a..d0a5a28a8fe2 100644
--- a/drivers/staging/asus_oled/asus_oled.c
+++ b/drivers/staging/asus_oled/asus_oled.c
@@ -164,11 +164,8 @@ static void enable_oled(struct asus_oled_dev *odev, uint8_t enabl)
164 struct asus_oled_packet *packet; 164 struct asus_oled_packet *packet;
165 165
166 packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); 166 packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL);
167 167 if (!packet)
168 if (!packet) {
169 dev_err(&odev->udev->dev, "out of memory\n");
170 return; 168 return;
171 }
172 169
173 setup_packet_header(packet, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00); 170 setup_packet_header(packet, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00);
174 171
@@ -323,11 +320,8 @@ static void send_data(struct asus_oled_dev *odev)
323 struct asus_oled_packet *packet; 320 struct asus_oled_packet *packet;
324 321
325 packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL); 322 packet = kzalloc(sizeof(struct asus_oled_packet), GFP_KERNEL);
326 323 if (!packet)
327 if (!packet) {
328 dev_err(&odev->udev->dev, "out of memory\n");
329 return; 324 return;
330 }
331 325
332 if (odev->pack_mode == PACK_MODE_G1) { 326 if (odev->pack_mode == PACK_MODE_G1) {
333 /* When sending roll-mode data the display updated only 327 /* When sending roll-mode data the display updated only
@@ -665,11 +659,8 @@ static int asus_oled_probe(struct usb_interface *interface,
665 } 659 }
666 660
667 odev = kzalloc(sizeof(struct asus_oled_dev), GFP_KERNEL); 661 odev = kzalloc(sizeof(struct asus_oled_dev), GFP_KERNEL);
668 662 if (odev == NULL)
669 if (odev == NULL) {
670 dev_err(&interface->dev, "Out of memory\n");
671 return -ENOMEM; 663 return -ENOMEM;
672 }
673 664
674 odev->udev = usb_get_dev(udev); 665 odev->udev = usb_get_dev(udev);
675 odev->pic_mode = ASUS_OLED_STATIC; 666 odev->pic_mode = ASUS_OLED_STATIC;
diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h
index f57794827f73..1d8bf08b5bfd 100644
--- a/drivers/staging/bcm/Adapter.h
+++ b/drivers/staging/bcm/Adapter.h
@@ -95,7 +95,7 @@ struct bcm_classifier_rule {
95 UCHAR ucDirection; 95 UCHAR ucDirection;
96 BOOLEAN bIpv6Protocol; 96 BOOLEAN bIpv6Protocol;
97 UINT32 u32PHSRuleID; 97 UINT32 u32PHSRuleID;
98 S_PHS_RULE sPhsRule; 98 struct bcm_phs_rule sPhsRule;
99 UCHAR u8AssociatedPHSI; 99 UCHAR u8AssociatedPHSI;
100 100
101 /* Classification fields for ETH CS */ 101 /* Classification fields for ETH CS */
@@ -288,7 +288,7 @@ struct bcm_mini_adapter {
288 wait_queue_head_t ioctl_fw_dnld_wait_queue; 288 wait_queue_head_t ioctl_fw_dnld_wait_queue;
289 BOOLEAN waiting_to_fw_download_done; 289 BOOLEAN waiting_to_fw_download_done;
290 pid_t fw_download_process_pid; 290 pid_t fw_download_process_pid;
291 PSTARGETPARAMS pstargetparams; 291 struct bcm_target_params *pstargetparams;
292 BOOLEAN device_removed; 292 BOOLEAN device_removed;
293 BOOLEAN DeviceAccess; 293 BOOLEAN DeviceAccess;
294 BOOLEAN bIsAutoCorrectEnabled; 294 BOOLEAN bIsAutoCorrectEnabled;
@@ -303,10 +303,10 @@ struct bcm_mini_adapter {
303 struct task_struct *transmit_packet_thread; 303 struct task_struct *transmit_packet_thread;
304 304
305 /* LED Related Structures */ 305 /* LED Related Structures */
306 LED_INFO_STRUCT LEDInfo; 306 struct bcm_led_info LEDInfo;
307 307
308 /* Driver State for LED Blinking */ 308 /* Driver State for LED Blinking */
309 LedEventInfo_t DriverState; 309 enum bcm_led_events DriverState;
310 /* Interface Specific */ 310 /* Interface Specific */
311 PVOID pvInterfaceAdapter; 311 PVOID pvInterfaceAdapter;
312 int (*bcm_file_download)(PVOID, 312 int (*bcm_file_download)(PVOID,
@@ -333,7 +333,7 @@ struct bcm_mini_adapter {
333 /* BOOLEAN bTriedToWakeUpFromShutdown; */ 333 /* BOOLEAN bTriedToWakeUpFromShutdown; */
334 BOOLEAN bLinkDownRequested; 334 BOOLEAN bLinkDownRequested;
335 int downloadDDR; 335 int downloadDDR;
336 PHS_DEVICE_EXTENSION stBCMPhsContext; 336 struct bcm_phs_extension stBCMPhsContext;
337 struct bcm_hdr_suppression_contextinfo stPhsTxContextInfo; 337 struct bcm_hdr_suppression_contextinfo stPhsTxContextInfo;
338 uint8_t ucaPHSPktRestoreBuf[2048]; 338 uint8_t ucaPHSPktRestoreBuf[2048];
339 uint8_t bPHSEnabled; 339 uint8_t bPHSEnabled;
@@ -345,7 +345,7 @@ struct bcm_mini_adapter {
345 struct bcm_fragmented_packet_info astFragmentedPktClassifierTable[MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES]; 345 struct bcm_fragmented_packet_info astFragmentedPktClassifierTable[MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES];
346 atomic_t uiMBupdate; 346 atomic_t uiMBupdate;
347 UINT32 PmuMode; 347 UINT32 PmuMode;
348 NVM_TYPE eNVMType; 348 enum bcm_nvm_type eNVMType;
349 UINT uiSectorSize; 349 UINT uiSectorSize;
350 UINT uiSectorSizeInCFG; 350 UINT uiSectorSizeInCFG;
351 BOOLEAN bSectorSizeOverride; 351 BOOLEAN bSectorSizeOverride;
@@ -366,9 +366,9 @@ struct bcm_mini_adapter {
366 struct device *pstCreatedClassDevice; 366 struct device *pstCreatedClassDevice;
367 367
368 /* BOOLEAN InterfaceUpStatus; */ 368 /* BOOLEAN InterfaceUpStatus; */
369 PFLASH2X_CS_INFO psFlash2xCSInfo; 369 struct bcm_flash2x_cs_info *psFlash2xCSInfo;
370 PFLASH_CS_INFO psFlashCSInfo; 370 struct bcm_flash_cs_info *psFlashCSInfo;
371 PFLASH2X_VENDORSPECIFIC_INFO psFlash2xVendorInfo; 371 struct bcm_flash2x_vendor_info *psFlash2xVendorInfo;
372 UINT uiFlashBaseAdd; /* Flash start address */ 372 UINT uiFlashBaseAdd; /* Flash start address */
373 UINT uiActiveISOOffset; /* Active ISO offset chosen before f/w download */ 373 UINT uiActiveISOOffset; /* Active ISO offset chosen before f/w download */
374 enum bcm_flash2x_section_val eActiveISO; /* Active ISO section val */ 374 enum bcm_flash2x_section_val eActiveISO; /* Active ISO section val */
@@ -392,7 +392,7 @@ struct bcm_mini_adapter {
392 struct semaphore LowPowerModeSync; 392 struct semaphore LowPowerModeSync;
393 ULONG liDrainCalculated; 393 ULONG liDrainCalculated;
394 UINT gpioBitMap; 394 UINT gpioBitMap;
395 S_BCM_DEBUG_STATE stDebugState; 395 struct bcm_debug_state stDebugState;
396}; 396};
397 397
398#define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev) 398#define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev)
diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c
index efad33e3ba73..491e2bfbc464 100644
--- a/drivers/staging/bcm/Bcmchar.c
+++ b/drivers/staging/bcm/Bcmchar.c
@@ -1013,7 +1013,7 @@ cntrlEnd:
1013 } 1013 }
1014 1014
1015 case IOCTL_BCM_GET_CURRENT_STATUS: { 1015 case IOCTL_BCM_GET_CURRENT_STATUS: {
1016 LINK_STATE link_state; 1016 struct bcm_link_state link_state;
1017 1017
1018 /* Copy Ioctl Buffer structure */ 1018 /* Copy Ioctl Buffer structure */
1019 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) { 1019 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) {
@@ -1229,13 +1229,13 @@ cntrlEnd:
1229 case IOCTL_BCM_SET_DEBUG: 1229 case IOCTL_BCM_SET_DEBUG:
1230#ifdef DEBUG 1230#ifdef DEBUG
1231 { 1231 {
1232 USER_BCM_DBG_STATE sUserDebugState; 1232 struct bcm_user_debug_state sUserDebugState;
1233 1233
1234 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n"); 1234 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "In SET_DEBUG ioctl\n");
1235 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer))) 1235 if (copy_from_user(&IoBuffer, argp, sizeof(struct bcm_ioctl_buffer)))
1236 return -EFAULT; 1236 return -EFAULT;
1237 1237
1238 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(USER_BCM_DBG_STATE))) 1238 if (copy_from_user(&sUserDebugState, IoBuffer.InputBuffer, sizeof(struct bcm_user_debug_state)))
1239 return -EFAULT; 1239 return -EFAULT;
1240 1240
1241 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ", 1241 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
@@ -1783,16 +1783,16 @@ cntrlEnd:
1783 } 1783 }
1784 1784
1785 if (IsFlash2x(Adapter) == TRUE) { 1785 if (IsFlash2x(Adapter) == TRUE) {
1786 if (IoBuffer.OutputLength < sizeof(FLASH2X_CS_INFO)) 1786 if (IoBuffer.OutputLength < sizeof(struct bcm_flash2x_cs_info))
1787 return -EINVAL; 1787 return -EINVAL;
1788 1788
1789 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(FLASH2X_CS_INFO))) 1789 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlash2xCSInfo, sizeof(struct bcm_flash2x_cs_info)))
1790 return -EFAULT; 1790 return -EFAULT;
1791 } else { 1791 } else {
1792 if (IoBuffer.OutputLength < sizeof(FLASH_CS_INFO)) 1792 if (IoBuffer.OutputLength < sizeof(struct bcm_flash_cs_info))
1793 return -EINVAL; 1793 return -EINVAL;
1794 1794
1795 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(FLASH_CS_INFO))) 1795 if (copy_to_user(IoBuffer.OutputBuffer, Adapter->psFlashCSInfo, sizeof(struct bcm_flash_cs_info)))
1796 return -EFAULT; 1796 return -EFAULT;
1797 } 1797 }
1798 } 1798 }
diff --git a/drivers/staging/bcm/CmHost.c b/drivers/staging/bcm/CmHost.c
index 23ddc3d7c9ea..976514502927 100644
--- a/drivers/staging/bcm/CmHost.c
+++ b/drivers/staging/bcm/CmHost.c
@@ -113,7 +113,7 @@ static VOID deleteSFBySfid(struct bcm_mini_adapter *Adapter, UINT uiSearchRuleIn
113static inline VOID 113static inline VOID
114CopyIpAddrToClassifier(struct bcm_classifier_rule *pstClassifierEntry, 114CopyIpAddrToClassifier(struct bcm_classifier_rule *pstClassifierEntry,
115 B_UINT8 u8IpAddressLen, B_UINT8 *pu8IpAddressMaskSrc, 115 B_UINT8 u8IpAddressLen, B_UINT8 *pu8IpAddressMaskSrc,
116 BOOLEAN bIpVersion6, E_IPADDR_CONTEXT eIpAddrContext) 116 BOOLEAN bIpVersion6, enum bcm_ipaddr_context eIpAddrContext)
117{ 117{
118 int i = 0; 118 int i = 0;
119 UINT nSizeOfIPAddressInBytes = IP_LENGTH_OF_ADDRESS; 119 UINT nSizeOfIPAddressInBytes = IP_LENGTH_OF_ADDRESS;
@@ -440,7 +440,7 @@ static VOID CopyToAdapter(register struct bcm_mini_adapter *Adapter, /* <Pointer
440 B_UINT16 u16PacketClassificationRuleIndex = 0; 440 B_UINT16 u16PacketClassificationRuleIndex = 0;
441 int i; 441 int i;
442 struct bcm_convergence_types *psfCSType = NULL; 442 struct bcm_convergence_types *psfCSType = NULL;
443 S_PHS_RULE sPhsRule; 443 struct bcm_phs_rule sPhsRule;
444 USHORT uVCID = Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value; 444 USHORT uVCID = Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value;
445 UINT UGIValue = 0; 445 UINT UGIValue = 0;
446 446
@@ -703,7 +703,7 @@ static VOID CopyToAdapter(register struct bcm_mini_adapter *Adapter, /* <Pointer
703 /* Update PHS Rule For the Classifier */ 703 /* Update PHS Rule For the Classifier */
704 if (sPhsRule.u8PHSI) { 704 if (sPhsRule.u8PHSI) {
705 Adapter->astClassifierTable[uiClassifierIndex].u32PHSRuleID = sPhsRule.u8PHSI; 705 Adapter->astClassifierTable[uiClassifierIndex].u32PHSRuleID = sPhsRule.u8PHSI;
706 memcpy(&Adapter->astClassifierTable[uiClassifierIndex].sPhsRule, &sPhsRule, sizeof(S_PHS_RULE)); 706 memcpy(&Adapter->astClassifierTable[uiClassifierIndex].sPhsRule, &sPhsRule, sizeof(struct bcm_phs_rule));
707 } 707 }
708 } 708 }
709 } 709 }
diff --git a/drivers/staging/bcm/CmHost.h b/drivers/staging/bcm/CmHost.h
index eecad8d90aea..4ddfc3d45bc0 100644
--- a/drivers/staging/bcm/CmHost.h
+++ b/drivers/staging/bcm/CmHost.h
@@ -27,32 +27,28 @@ struct bcm_add_indication_alt {
27 u8 u8Type; 27 u8 u8Type;
28 u8 u8Direction; 28 u8 u8Direction;
29 u16 u16TID; 29 u16 u16TID;
30 /* brief 16bitCID */
31 u16 u16CID; 30 u16 u16CID;
32 /* brief 16bitVCID */
33 u16 u16VCID; 31 u16 u16VCID;
34 struct bcm_connect_mgr_params sfAuthorizedSet; 32 struct bcm_connect_mgr_params sfAuthorizedSet;
35 struct bcm_connect_mgr_params sfAdmittedSet; 33 struct bcm_connect_mgr_params sfAdmittedSet;
36 struct bcm_connect_mgr_params sfActiveSet; 34 struct bcm_connect_mgr_params sfActiveSet;
37 u8 u8CC; /* < Confirmation Code */ 35 u8 u8CC; /* < Confirmation Code */
38 u8 u8Padd; /* < 8-bit Padding */ 36 u8 u8Padd;
39 u16 u16Padd; /* < 16 bit Padding */ 37 u16 u16Padd;
40}; 38};
41 39
42struct bcm_change_indication { 40struct bcm_change_indication {
43 u8 u8Type; 41 u8 u8Type;
44 u8 u8Direction; 42 u8 u8Direction;
45 u16 u16TID; 43 u16 u16TID;
46 /* brief 16bitCID */
47 u16 u16CID; 44 u16 u16CID;
48 /* brief 16bitVCID */
49 u16 u16VCID; 45 u16 u16VCID;
50 struct bcm_connect_mgr_params sfAuthorizedSet; 46 struct bcm_connect_mgr_params sfAuthorizedSet;
51 struct bcm_connect_mgr_params sfAdmittedSet; 47 struct bcm_connect_mgr_params sfAdmittedSet;
52 struct bcm_connect_mgr_params sfActiveSet; 48 struct bcm_connect_mgr_params sfActiveSet;
53 u8 u8CC; /* < Confirmation Code */ 49 u8 u8CC; /* < Confirmation Code */
54 u8 u8Padd; /* < 8-bit Padding */ 50 u8 u8Padd;
55 u16 u16Padd; /* < 16 bit */ 51 u16 u16Padd;
56}; 52};
57 53
58unsigned long StoreCmControlResponseMessage(struct bcm_mini_adapter *Adapter, void *pvBuffer, unsigned int *puBufferLength); 54unsigned long StoreCmControlResponseMessage(struct bcm_mini_adapter *Adapter, void *pvBuffer, unsigned int *puBufferLength);
diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h
index 8018a189f817..7b331215c1ac 100644
--- a/drivers/staging/bcm/Debug.h
+++ b/drivers/staging/bcm/Debug.h
@@ -9,142 +9,129 @@
9#include <linux/string.h> 9#include <linux/string.h>
10#define NONE 0xFFFF 10#define NONE 0xFFFF
11 11
12
13//--------------------------------------------------------------------------------
14
15/* TYPE and SUBTYPE 12/* TYPE and SUBTYPE
16 * Define valid TYPE (or category or code-path, however you like to think of it) 13 * Define valid TYPE (or category or code-path, however you like to think of it)
17 * and SUBTYPE s. 14 * and SUBTYPE s.
18 * Type and SubType are treated as bitmasks. 15 * Type and SubType are treated as bitmasks.
19 */ 16 */
20/*-----------------BEGIN TYPEs------------------------------------------*/ 17#define DBG_TYPE_INITEXIT (1 << 0) /* 1 */
21#define DBG_TYPE_INITEXIT (1 << 0) // 1 18#define DBG_TYPE_TX (1 << 1) /* 2 */
22#define DBG_TYPE_TX (1 << 1) // 2 19#define DBG_TYPE_RX (1 << 2) /* 4 */
23#define DBG_TYPE_RX (1 << 2) // 4 20#define DBG_TYPE_OTHERS (1 << 3) /* 8 */
24#define DBG_TYPE_OTHERS (1 << 3) // 8 21#define NUMTYPES 4
25/*-----------------END TYPEs------------------------------------------*/ 22
26#define NUMTYPES 4 // careful! 23/* -SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----//
27 24 * Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c
28/*-----------------BEGIN SUBTYPEs---------------------------------------*/ 25 * total 17 macros
29 26 */
30/*-SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----// 27/* Transmit.c */
31 Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c 28#define TX 1
32 total 17 macros */ 29#define MP_SEND (TX << 0)
33// Transmit.c 30#define NEXT_SEND (TX << 1)
34#define TX 1 31#define TX_FIFO (TX << 2)
35#define MP_SEND (TX<<0) 32#define TX_CONTROL (TX << 3)
36#define NEXT_SEND (TX<<1) 33
37#define TX_FIFO (TX<<2) 34/* Arp.c */
38#define TX_CONTROL (TX<<3) 35#define IP_ADDR (TX << 4)
39 36#define ARP_REQ (TX << 5)
40// Arp.c 37#define ARP_RESP (TX << 6)
41#define IP_ADDR (TX<<4) 38
42#define ARP_REQ (TX<<5) 39/* Leakybucket.c */
43#define ARP_RESP (TX<<6) 40#define TOKEN_COUNTS (TX << 8)
44 41#define CHECK_TOKENS (TX << 9)
45// Leakybucket.c 42#define TX_PACKETS (TX << 10)
46#define TOKEN_COUNTS (TX<<8) 43#define TIMER (TX << 11)
47#define CHECK_TOKENS (TX<<9) 44
48#define TX_PACKETS (TX<<10) 45/* Qos.c */
49#define TIMER (TX<<11) 46#define QOS TX
50 47#define QUEUE_INDEX (QOS << 12)
51// Qos.c 48#define IPV4_DBG (QOS << 13)
52#define QOS TX 49#define IPV6_DBG (QOS << 14)
53#define QUEUE_INDEX (QOS<<12) 50#define PRUNE_QUEUE (QOS << 15)
54#define IPV4_DBG (QOS<<13) 51#define SEND_QUEUE (QOS << 16)
55#define IPV6_DBG (QOS<<14) 52
56#define PRUNE_QUEUE (QOS<<15) 53/* TX_Misc */
57#define SEND_QUEUE (QOS<<16) 54#define TX_OSAL_DBG (TX << 17)
58 55
59//TX_Misc 56/* --SUBTYPEs for ------INIT & EXIT---------------------
60#define TX_OSAL_DBG (TX<<17) 57 * ------------ TYPE is DBG_TYPE_INITEXIT -----//
61 58 * DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c
62 59 */
63//--SUBTYPEs for ------INIT & EXIT--------------------- 60#define MP 1
64/*------------ TYPE is DBG_TYPE_INITEXIT -----// 61#define DRV_ENTRY (MP << 0)
65DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */ 62#define MP_INIT (MP << 1)
66#define MP 1 63#define READ_REG (MP << 3)
67#define DRV_ENTRY (MP<<0) 64#define DISPATCH (MP << 2)
68#define MP_INIT (MP<<1) 65#define CLAIM_ADAP (MP << 4)
69#define READ_REG (MP<<3) 66#define REG_IO_PORT (MP << 5)
70#define DISPATCH (MP<<2) 67#define INIT_DISP (MP << 6)
71#define CLAIM_ADAP (MP<<4) 68#define RX_INIT (MP << 7)
72#define REG_IO_PORT (MP<<5) 69
73#define INIT_DISP (MP<<6) 70/* -SUBTYPEs for --RX----------------------------------
74#define RX_INIT (MP<<7) 71 * ------------RX : TYPE is DBG_TYPE_RX -----//
75 72 * Receive.c
76 73 */
77//-SUBTYPEs for --RX---------------------------------- 74#define RX 1
78//------------RX : TYPE is DBG_TYPE_RX -----// 75#define RX_DPC (RX << 0)
79// Receive.c 76#define RX_CTRL (RX << 3)
80#define RX 1 77#define RX_DATA (RX << 4)
81#define RX_DPC (RX<<0) 78#define MP_RETURN (RX << 1)
82#define RX_CTRL (RX<<3) 79#define LINK_MSG (RX << 2)
83#define RX_DATA (RX<<4) 80
84#define MP_RETURN (RX<<1) 81/* -SUBTYPEs for ----OTHER ROUTINES------------------
85#define LINK_MSG (RX<<2) 82 * ------------OTHERS : TYPE is DBG_TYPE_OTHER -----//
86 83 * HaltnReset,CheckForHang,PnP,Misc,CmHost
87 84 * total 12 macros
88//-SUBTYPEs for ----OTHER ROUTINES------------------ 85 */
89//------------OTHERS : TYPE is DBG_TYPE_OTHER -----// 86#define OTHERS 1
90// HaltnReset,CheckForHang,PnP,Misc,CmHost 87#define ISR OTHERS
91// total 12 macros 88#define MP_DPC (ISR << 0)
92#define OTHERS 1 89
93// ??ISR.C 90/* HaltnReset.c */
94 91#define HALT OTHERS
95#define ISR OTHERS 92#define MP_HALT (HALT << 1)
96#define MP_DPC (ISR<<0) 93#define CHECK_HANG (HALT << 2)
97 94#define MP_RESET (HALT << 3)
98// HaltnReset.c 95#define MP_SHUTDOWN (HALT << 4)
99#define HALT OTHERS 96
100#define MP_HALT (HALT<<1) 97/* pnp.c */
101#define CHECK_HANG (HALT<<2) 98#define PNP OTHERS
102#define MP_RESET (HALT<<3) 99#define MP_PNP (PNP << 5)
103#define MP_SHUTDOWN (HALT<<4) 100
104 101/* Misc.c */
105// pnp.c 102#define MISC OTHERS
106#define PNP OTHERS 103#define DUMP_INFO (MISC << 6)
107#define MP_PNP (PNP<<5) 104#define CLASSIFY (MISC << 7)
108 105#define LINK_UP_MSG (MISC << 8)
109// Misc.c 106#define CP_CTRL_PKT (MISC << 9)
110#define MISC OTHERS 107#define DUMP_CONTROL (MISC << 10)
111#define DUMP_INFO (MISC<<6) 108#define LED_DUMP_INFO (MISC << 11)
112#define CLASSIFY (MISC<<7) 109
113#define LINK_UP_MSG (MISC<<8) 110/* CmHost.c */
114#define CP_CTRL_PKT (MISC<<9) 111#define CMHOST OTHERS
115#define DUMP_CONTROL (MISC<<10) 112#define SERIAL (OTHERS << 12)
116#define LED_DUMP_INFO (MISC<<11) 113#define IDLE_MODE (OTHERS << 13)
117 114#define WRM (OTHERS << 14)
118// CmHost.c 115#define RDM (OTHERS << 15)
119#define CMHOST OTHERS 116
120 117/* TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ? */
121 118#define PHS_SEND (OTHERS << 16)
122#define SERIAL (OTHERS<<12) 119#define PHS_RECEIVE (OTHERS << 17)
123#define IDLE_MODE (OTHERS<<13) 120#define PHS_MODULE (OTHERS << 18)
124 121
125#define WRM (OTHERS<<14) 122#define INTF_INIT (OTHERS << 19)
126#define RDM (OTHERS<<15) 123#define INTF_ERR (OTHERS << 20)
127 124#define INTF_WARN (OTHERS << 21)
128// TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ? 125#define INTF_NORM (OTHERS << 22)
129#define PHS_SEND (OTHERS<<16) 126
130#define PHS_RECEIVE (OTHERS<<17) 127#define IRP_COMPLETION (OTHERS << 23)
131#define PHS_MODULE (OTHERS<<18) 128#define SF_DESCRIPTOR_CNTS (OTHERS << 24)
132 129#define PHS_DISPATCH (OTHERS << 25)
133#define INTF_INIT (OTHERS<<19) 130#define OSAL_DBG (OTHERS << 26)
134#define INTF_ERR (OTHERS<<20) 131#define NVM_RW (OTHERS << 27)
135#define INTF_WARN (OTHERS<<21) 132
136#define INTF_NORM (OTHERS<<22) 133#define HOST_MIBS (OTHERS << 28)
137 134#define CONN_MSG (CMHOST << 29)
138#define IRP_COMPLETION (OTHERS<<23)
139#define SF_DESCRIPTOR_CNTS (OTHERS<<24)
140#define PHS_DISPATCH (OTHERS << 25)
141#define OSAL_DBG (OTHERS << 26)
142#define NVM_RW (OTHERS << 27)
143
144#define HOST_MIBS (OTHERS << 28)
145#define CONN_MSG (CMHOST << 29)
146/*-----------------END SUBTYPEs------------------------------------------*/
147
148 135
149/* Debug level 136/* Debug level
150 * We have 8 debug levels, in (numerical) increasing order of verbosity. 137 * We have 8 debug levels, in (numerical) increasing order of verbosity.
@@ -157,57 +144,58 @@ DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c */
157 * You can compile-time change that to any of the below, if you wish to. However, as of now, there's 144 * You can compile-time change that to any of the below, if you wish to. However, as of now, there's
158 * no dynamic facility to have the userspace 'TestApp' set debug_level. Slated for future expansion. 145 * no dynamic facility to have the userspace 'TestApp' set debug_level. Slated for future expansion.
159 */ 146 */
160#define BCM_ALL 7 147#define BCM_ALL 7
161#define BCM_LOW 6 148#define BCM_LOW 6
162#define BCM_PRINT 5 149#define BCM_PRINT 5
163#define BCM_NORMAL 4 150#define BCM_NORMAL 4
164#define BCM_MEDIUM 3 151#define BCM_MEDIUM 3
165#define BCM_SCREAM 2 152#define BCM_SCREAM 2
166#define BCM_ERR 1 153#define BCM_ERR 1
167/* Not meant for developer in debug prints. 154/* Not meant for developer in debug prints.
168 * To be used to disable all prints by setting the DBG_LVL_CURR to this value */ 155 * To be used to disable all prints by setting the DBG_LVL_CURR to this value
169#define BCM_NONE 0 156 */
157#define BCM_NONE 0
170 158
171/* The current driver logging level. 159/* The current driver logging level.
172 * Everything at this level and (numerically) lower (meaning higher prio) 160 * Everything at this level and (numerically) lower (meaning higher prio)
173 * is logged. 161 * is logged.
174* Replace 'BCM_ALL' in the DBG_LVL_CURR macro with the logging level desired. 162 * Replace 'BCM_ALL' in the DBG_LVL_CURR macro with the logging level desired.
175 * For eg. to set the logging level to 'errors only' use: 163 * For eg. to set the logging level to 'errors only' use:
176 * #define DBG_LVL_CURR (BCM_ERR) 164 * #define DBG_LVL_CURR (BCM_ERR)
177 */ 165 */
178 166
179#define DBG_LVL_CURR (BCM_ALL) 167#define DBG_LVL_CURR (BCM_ALL)
180#define DBG_LVL_ALL BCM_ALL 168#define DBG_LVL_ALL BCM_ALL
181 169
182/*---Userspace mapping of Debug State. 170/* ---Userspace mapping of Debug State.
183 * Delibrately matches that of the Windows driver.. 171 * Delibrately matches that of the Windows driver..
184 * The TestApp's ioctl passes this struct to us. 172 * The TestApp's ioctl passes this struct to us.
185 */ 173 */
186typedef struct 174struct bcm_user_debug_state {
187{
188 unsigned int Subtype, Type; 175 unsigned int Subtype, Type;
189 unsigned int OnOff; 176 unsigned int OnOff;
190// unsigned int debug_level; /* future expansion */ 177/* unsigned int debug_level; future expansion */
191} __attribute__((packed)) USER_BCM_DBG_STATE; 178} __packed;
192 179
193//---Kernel-space mapping of Debug State 180/* ---Kernel-space mapping of Debug State */
194typedef struct _S_BCM_DEBUG_STATE { 181struct bcm_debug_state {
195 UINT type; 182 unsigned int type;
196 /* A bitmap of 32 bits for Subtype per Type. 183 /* A bitmap of 32 bits for Subtype per Type.
197 * Valid indexes in 'subtype' array are *only* 1,2,4 and 8, 184 * Valid indexes in 'subtype' array are *only* 1,2,4 and 8,
198 * corresponding to valid Type values. Hence we use the 'Type' field 185 * corresponding to valid Type values. Hence we use the 'Type' field
199 * as the index value, ignoring the array entries 0,3,5,6,7 ! 186 * as the index value, ignoring the array entries 0,3,5,6,7 !
200 */ 187 */
201 UINT subtype[(NUMTYPES*2)+1]; 188 unsigned int subtype[(NUMTYPES*2)+1];
202 UINT debug_level; 189 unsigned int debug_level;
203} S_BCM_DEBUG_STATE; 190};
204/* Instantiated in the Adapter structure */ 191/* Instantiated in the Adapter structure
205/* We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not 192 * We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not
206 * we want the function's name printed. */ 193 * we want the function's name printed.
207#define DBG_NO_FUNC_PRINT 1 << 31 194 */
195#define DBG_NO_FUNC_PRINT (1 << 31)
208#define DBG_LVL_BITMASK 0xFF 196#define DBG_LVL_BITMASK 0xFF
209 197
210//--- Only for direct printk's; "hidden" to API. 198/* --- Only for direct printk's; "hidden" to API. */
211#define DBG_TYPE_PRINTK 3 199#define DBG_TYPE_PRINTK 3
212 200
213#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \ 201#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \
@@ -215,40 +203,40 @@ typedef struct _S_BCM_DEBUG_STATE {
215 if (DBG_TYPE_PRINTK == Type) \ 203 if (DBG_TYPE_PRINTK == Type) \
216 pr_info("%s:" string, __func__, ##args); \ 204 pr_info("%s:" string, __func__, ##args); \
217 else if (Adapter && \ 205 else if (Adapter && \
218 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \ 206 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
219 (Type & Adapter->stDebugState.type) && \ 207 (Type & Adapter->stDebugState.type) && \
220 (SubType & Adapter->stDebugState.subtype[Type])) { \ 208 (SubType & Adapter->stDebugState.subtype[Type])) { \
221 if (dbg_level & DBG_NO_FUNC_PRINT) \ 209 if (dbg_level & DBG_NO_FUNC_PRINT) \
222 printk(KERN_DEBUG string, ##args); \ 210 pr_debug("%s:\n", string); \
223 else \ 211 else \
224 printk(KERN_DEBUG "%s:" string, __func__, ##args); \ 212 pr_debug("%s:\n" string, __func__, ##args); \
225 } \ 213 } \
226 } while (0) 214 } while (0)
227 215
228#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) do { \ 216#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) \
229 if (DBG_TYPE_PRINTK == Type || \ 217 do { \
230 (Adapter && \ 218 if (DBG_TYPE_PRINTK == Type || \
231 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \ 219 (Adapter && \
232 (Type & Adapter->stDebugState.type) && \ 220 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
233 (SubType & Adapter->stDebugState.subtype[Type]))) { \ 221 (Type & Adapter->stDebugState.type) && \
234 printk(KERN_DEBUG "%s:\n", __func__); \ 222 (SubType & Adapter->stDebugState.subtype[Type]))) { \
235 print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, \ 223 pr_debug("%s:\n", __func__); \
236 16, 1, buffer, bufferlen, false); \ 224 print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, \
237 } \ 225 16, 1, buffer, bufferlen, false); \
238} while(0) 226 } \
239 227 } while (0)
240 228
241#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \ 229#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \
242 int i; \ 230 int i; \
243 for (i=0; i<(NUMTYPES*2)+1; i++) { \ 231 for (i = 0; i < (NUMTYPES * 2) + 1; i++) { \
244 if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) { \ 232 if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) { \
245 /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \ 233 /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \
246 Adapter->stDebugState.subtype[i] = 0xffffffff; */ \ 234 * Adapter->stDebugState.subtype[i] = 0xffffffff; \
247 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \ 235 */ \
248 i, Adapter->stDebugState.subtype[i]); \ 236 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \
237 i, Adapter->stDebugState.subtype[i]); \
249 } \ 238 } \
250 } \ 239 } \
251} while (0) 240} while (0)
252 241
253#endif 242#endif
254
diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c
index 4745ddd62f5b..6d803e7b094a 100644
--- a/drivers/staging/bcm/IPv6Protocol.c
+++ b/drivers/staging/bcm/IPv6Protocol.c
@@ -1,10 +1,10 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule, 3static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
4 IPV6Header *pstIpv6Header); 4 struct bcm_ipv6_hdr *pstIpv6Header);
5static BOOLEAN MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule, 5static BOOLEAN MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
6 IPV6Header *pstIpv6Header); 6 struct bcm_ipv6_hdr *pstIpv6Header);
7static VOID DumpIpv6Header(IPV6Header *pstIpv6Header); 7static VOID DumpIpv6Header(struct bcm_ipv6_hdr *pstIpv6Header);
8 8
9static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload, 9static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload,
10 UCHAR *pucNextHeader, BOOLEAN *bParseDone, USHORT *pusPayloadLength) 10 UCHAR *pucNextHeader, BOOLEAN *bParseDone, USHORT *pusPayloadLength)
@@ -38,17 +38,17 @@ static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload,
38 38
39 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, 39 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
40 DBG_LVL_ALL, "\nIPv6 HopByHop Header"); 40 DBG_LVL_ALL, "\nIPv6 HopByHop Header");
41 usNextHeaderOffset += sizeof(IPV6HopByHopOptionsHeader); 41 usNextHeaderOffset += sizeof(struct bcm_ipv6_options_hdr);
42 } 42 }
43 break; 43 break;
44 44
45 case IPV6HDR_TYPE_ROUTING: 45 case IPV6HDR_TYPE_ROUTING:
46 { 46 {
47 IPV6RoutingHeader *pstIpv6RoutingHeader; 47 struct bcm_ipv6_routing_hdr *pstIpv6RoutingHeader;
48 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, 48 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
49 DBG_LVL_ALL, "\nIPv6 Routing Header"); 49 DBG_LVL_ALL, "\nIPv6 Routing Header");
50 pstIpv6RoutingHeader = (IPV6RoutingHeader *)pucPayloadPtr; 50 pstIpv6RoutingHeader = (struct bcm_ipv6_routing_hdr *)pucPayloadPtr;
51 usNextHeaderOffset += sizeof(IPV6RoutingHeader); 51 usNextHeaderOffset += sizeof(struct bcm_ipv6_routing_hdr);
52 usNextHeaderOffset += pstIpv6RoutingHeader->ucNumAddresses * IPV6_ADDRESS_SIZEINBYTES; 52 usNextHeaderOffset += pstIpv6RoutingHeader->ucNumAddresses * IPV6_ADDRESS_SIZEINBYTES;
53 53
54 } 54 }
@@ -58,25 +58,25 @@ static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload,
58 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, 58 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
59 DBG_LVL_ALL, 59 DBG_LVL_ALL,
60 "\nIPv6 Fragmentation Header"); 60 "\nIPv6 Fragmentation Header");
61 usNextHeaderOffset += sizeof(IPV6FragmentHeader); 61 usNextHeaderOffset += sizeof(struct bcm_ipv6_fragment_hdr);
62 62
63 } 63 }
64 break; 64 break;
65 case IPV6HDR_TYPE_DESTOPTS: 65 case IPV6HDR_TYPE_DESTOPTS:
66 { 66 {
67 IPV6DestOptionsHeader *pstIpv6DestOptsHdr = (IPV6DestOptionsHeader *)pucPayloadPtr; 67 struct bcm_ipv6_dest_options_hdr *pstIpv6DestOptsHdr = (struct bcm_ipv6_dest_options_hdr *)pucPayloadPtr;
68 int nTotalOptions = pstIpv6DestOptsHdr->ucHdrExtLen; 68 int nTotalOptions = pstIpv6DestOptsHdr->ucHdrExtLen;
69 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, 69 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
70 DBG_LVL_ALL, 70 DBG_LVL_ALL,
71 "\nIPv6 DestOpts Header Header"); 71 "\nIPv6 DestOpts Header Header");
72 usNextHeaderOffset += sizeof(IPV6DestOptionsHeader); 72 usNextHeaderOffset += sizeof(struct bcm_ipv6_dest_options_hdr);
73 usNextHeaderOffset += nTotalOptions * IPV6_DESTOPTS_HDR_OPTIONSIZE ; 73 usNextHeaderOffset += nTotalOptions * IPV6_DESTOPTS_HDR_OPTIONSIZE ;
74 74
75 } 75 }
76 break; 76 break;
77 case IPV6HDR_TYPE_AUTHENTICATION: 77 case IPV6HDR_TYPE_AUTHENTICATION:
78 { 78 {
79 IPV6AuthenticationHeader *pstIpv6AuthHdr = (IPV6AuthenticationHeader *)pucPayloadPtr; 79 struct bcm_ipv6_authentication_hdr *pstIpv6AuthHdr = (struct bcm_ipv6_authentication_hdr *)pucPayloadPtr;
80 int nHdrLen = pstIpv6AuthHdr->ucLength; 80 int nHdrLen = pstIpv6AuthHdr->ucLength;
81 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, 81 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
82 DBG_LVL_ALL, 82 DBG_LVL_ALL,
@@ -186,13 +186,13 @@ USHORT IpVersion6(struct bcm_mini_adapter *Adapter, PVOID pcIpHeader,
186 USHORT ushDestPort = 0; 186 USHORT ushDestPort = 0;
187 USHORT ushSrcPort = 0; 187 USHORT ushSrcPort = 0;
188 UCHAR ucNextProtocolAboveIP = 0; 188 UCHAR ucNextProtocolAboveIP = 0;
189 IPV6Header *pstIpv6Header = NULL; 189 struct bcm_ipv6_hdr *pstIpv6Header = NULL;
190 BOOLEAN bClassificationSucceed = FALSE; 190 BOOLEAN bClassificationSucceed = FALSE;
191 191
192 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, 192 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
193 DBG_LVL_ALL, "IpVersion6 ==========>\n"); 193 DBG_LVL_ALL, "IpVersion6 ==========>\n");
194 194
195 pstIpv6Header = (IPV6Header *)pcIpHeader; 195 pstIpv6Header = (struct bcm_ipv6_hdr *)pcIpHeader;
196 196
197 DumpIpv6Header(pstIpv6Header); 197 DumpIpv6Header(pstIpv6Header);
198 198
@@ -200,7 +200,7 @@ USHORT IpVersion6(struct bcm_mini_adapter *Adapter, PVOID pcIpHeader,
200 * Try to get the next higher layer protocol 200 * Try to get the next higher layer protocol
201 * and the Ports Nos if TCP or UDP 201 * and the Ports Nos if TCP or UDP
202 */ 202 */
203 ucNextProtocolAboveIP = GetIpv6ProtocolPorts((UCHAR *)(pcIpHeader + sizeof(IPV6Header)), 203 ucNextProtocolAboveIP = GetIpv6ProtocolPorts((UCHAR *)(pcIpHeader + sizeof(struct bcm_ipv6_hdr)),
204 &ushSrcPort, 204 &ushSrcPort,
205 &ushDestPort, 205 &ushDestPort,
206 pstIpv6Header->usPayloadLength, 206 pstIpv6Header->usPayloadLength,
@@ -289,7 +289,7 @@ USHORT IpVersion6(struct bcm_mini_adapter *Adapter, PVOID pcIpHeader,
289 289
290 290
291static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule, 291static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
292 IPV6Header *pstIpv6Header) 292 struct bcm_ipv6_hdr *pstIpv6Header)
293{ 293{
294 UINT uiLoopIndex = 0; 294 UINT uiLoopIndex = 0;
295 UINT uiIpv6AddIndex = 0; 295 UINT uiIpv6AddIndex = 0;
@@ -345,7 +345,7 @@ static BOOLEAN MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule
345} 345}
346 346
347static BOOLEAN MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule, 347static BOOLEAN MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
348 IPV6Header *pstIpv6Header) 348 struct bcm_ipv6_hdr *pstIpv6Header)
349{ 349{
350 UINT uiLoopIndex = 0; 350 UINT uiLoopIndex = 0;
351 UINT uiIpv6AddIndex = 0; 351 UINT uiIpv6AddIndex = 0;
@@ -414,7 +414,7 @@ VOID DumpIpv6Address(ULONG *puIpv6Address)
414 414
415} 415}
416 416
417static VOID DumpIpv6Header(IPV6Header *pstIpv6Header) 417static VOID DumpIpv6Header(struct bcm_ipv6_hdr *pstIpv6Header)
418{ 418{
419 UCHAR ucVersion; 419 UCHAR ucVersion;
420 UCHAR ucPrio; 420 UCHAR ucPrio;
diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h
index 8ba88a5b081c..96b36a579af2 100644
--- a/drivers/staging/bcm/IPv6ProtocolHdr.h
+++ b/drivers/staging/bcm/IPv6ProtocolHdr.h
@@ -1,7 +1,6 @@
1#ifndef _IPV6_PROTOCOL_DEFINES_ 1#ifndef _IPV6_PROTOCOL_DEFINES_
2#define _IPV6_PROTOCOL_DEFINES_ 2#define _IPV6_PROTOCOL_DEFINES_
3 3
4
5#define IPV6HDR_TYPE_HOPBYHOP 0x0 4#define IPV6HDR_TYPE_HOPBYHOP 0x0
6#define IPV6HDR_TYPE_ROUTING 0x2B 5#define IPV6HDR_TYPE_ROUTING 0x2B
7#define IPV6HDR_TYPE_FRAGMENTATION 0x2C 6#define IPV6HDR_TYPE_FRAGMENTATION 0x2C
@@ -10,107 +9,77 @@
10#define IPV6HDR_TYPE_ENCRYPTEDSECURITYPAYLOAD 0x34 9#define IPV6HDR_TYPE_ENCRYPTEDSECURITYPAYLOAD 0x34
11#define MASK_IPV6_CS_SPEC 0x2 10#define MASK_IPV6_CS_SPEC 0x2
12 11
13 12#define TCP_HEADER_TYPE 0x6
14#define TCP_HEADER_TYPE 0x6 13#define UDP_HEADER_TYPE 0x11
15#define UDP_HEADER_TYPE 0x11
16#define IPV6_ICMP_HDR_TYPE 0x2 14#define IPV6_ICMP_HDR_TYPE 0x2
17#define IPV6_FLOWLABEL_BITOFFSET 9 15#define IPV6_FLOWLABEL_BITOFFSET 9
18 16
19#define IPV6_MAX_CHAINEDHDR_BUFFBYTES 0x64 17#define IPV6_MAX_CHAINEDHDR_BUFFBYTES 0x64
20/* 18/*
21// Size of Dest Options field of Destinations Options Header 19 * Size of Dest Options field of Destinations Options Header
22// in bytes. 20 * in bytes.
23*/ 21 */
24#define IPV6_DESTOPTS_HDR_OPTIONSIZE 0x8 22#define IPV6_DESTOPTS_HDR_OPTIONSIZE 0x8
25 23
26//typedef unsigned char UCHAR; 24struct bcm_ipv6_hdr {
27//typedef unsigned short USHORT; 25 unsigned char ucVersionPrio;
28//typedef unsigned long int ULONG; 26 unsigned char aucFlowLabel[3];
29 27 unsigned short usPayloadLength;
30typedef struct IPV6HeaderFormatTag 28 unsigned char ucNextHeader;
31{ 29 unsigned char ucHopLimit;
32 UCHAR ucVersionPrio; 30 unsigned long ulSrcIpAddress[4];
33 UCHAR aucFlowLabel[3]; 31 unsigned long ulDestIpAddress[4];
34 USHORT usPayloadLength; 32};
35 UCHAR ucNextHeader; 33
36 UCHAR ucHopLimit; 34struct bcm_ipv6_routing_hdr {
37 ULONG ulSrcIpAddress[4]; 35 unsigned char ucNextHeader;
38 ULONG ulDestIpAddress[4]; 36 unsigned char ucRoutingType;
39}IPV6Header; 37 unsigned char ucNumAddresses;
40 38 unsigned char ucNextAddress;
41typedef struct IPV6RoutingHeaderFormatTag 39 unsigned long ulReserved;
42{ 40};
43 UCHAR ucNextHeader; 41
44 UCHAR ucRoutingType; 42struct bcm_ipv6_fragment_hdr {
45 UCHAR ucNumAddresses; 43 unsigned char ucNextHeader;
46 UCHAR ucNextAddress; 44 unsigned char ucReserved;
47 ULONG ulReserved; 45 unsigned short usFragmentOffset;
48 //UCHAR aucAddressList[0]; 46 unsigned long ulIdentification;
49 47};
50}IPV6RoutingHeader; 48
51 49struct bcm_ipv6_dest_options_hdr {
52typedef struct IPV6FragmentHeaderFormatTag 50 unsigned char ucNextHeader;
53{ 51 unsigned char ucHdrExtLen;
54 UCHAR ucNextHeader; 52 unsigned char ucDestOptions[6];
55 UCHAR ucReserved; 53};
56 USHORT usFragmentOffset; 54
57 ULONG ulIdentification; 55struct bcm_ipv6_options_hdr {
58}IPV6FragmentHeader; 56 unsigned char ucNextHeader;
59 57 unsigned char ucMisc[3];
60typedef struct IPV6DestOptionsHeaderFormatTag 58 unsigned long ulJumboPayloadLen;
61{ 59};
62 UCHAR ucNextHeader; 60
63 UCHAR ucHdrExtLen; 61struct bcm_ipv6_authentication_hdr {
64 UCHAR ucDestOptions[6]; 62 unsigned char ucNextHeader;
65 //UCHAR udExtDestOptions[0]; 63 unsigned char ucLength;
66}IPV6DestOptionsHeader; 64 unsigned short usReserved;
67 65 unsigned long ulSecurityParametersIndex;
68typedef struct IPV6HopByHopOptionsHeaderFormatTag 66};
69{ 67
70 UCHAR ucNextHeader; 68enum bcm_ipaddr_context {
71 UCHAR ucMisc[3];
72 ULONG ulJumboPayloadLen;
73}IPV6HopByHopOptionsHeader;
74
75typedef struct IPV6AuthenticationHeaderFormatTag
76{
77 UCHAR ucNextHeader;
78 UCHAR ucLength;
79 USHORT usReserved;
80 ULONG ulSecurityParametersIndex;
81 //UCHAR ucAuthenticationData[0];
82
83}IPV6AuthenticationHeader;
84
85typedef struct IPV6IcmpHeaderFormatTag
86{
87 UCHAR ucType;
88 UCHAR ucCode;
89 USHORT usChecksum;
90 //UCHAR ucIcmpMsg[0];
91
92}IPV6IcmpHeader;
93
94typedef enum _E_IPADDR_CONTEXT
95{
96 eSrcIpAddress, 69 eSrcIpAddress,
97 eDestIpAddress 70 eDestIpAddress
71};
98 72
99}E_IPADDR_CONTEXT; 73/* Function Prototypes */
100
101
102
103//Function Prototypes
104
105USHORT IpVersion6(struct bcm_mini_adapter *Adapter, /**< Pointer to the driver control structure */
106 PVOID pcIpHeader, /**<Pointer to the IP Hdr of the packet*/
107 struct bcm_classifier_rule *pstClassifierRule );
108 74
109VOID DumpIpv6Address(ULONG *puIpv6Address); 75unsigned short IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the driver control structure */
76 void *pcIpHeader, /* <Pointer to the IP Hdr of the packet */
77 struct bcm_classifier_rule *pstClassifierRule);
110 78
111extern BOOLEAN MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort); 79void DumpIpv6Address(unsigned long *puIpv6Address);
112extern BOOLEAN MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort);
113extern BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProtocol);
114 80
81extern bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort);
82extern bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort);
83extern bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, unsigned char ucProtocol);
115 84
116#endif 85#endif
diff --git a/drivers/staging/bcm/InterfaceDld.c b/drivers/staging/bcm/InterfaceDld.c
index 87117a797d5b..64ea6edb9dc2 100644
--- a/drivers/staging/bcm/InterfaceDld.c
+++ b/drivers/staging/bcm/InterfaceDld.c
@@ -138,12 +138,12 @@ static int bcm_download_config_file(struct bcm_mini_adapter *Adapter, struct bcm
138 B_UINT32 value = 0; 138 B_UINT32 value = 0;
139 139
140 if (Adapter->pstargetparams == NULL) { 140 if (Adapter->pstargetparams == NULL) {
141 Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL); 141 Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
142 if (Adapter->pstargetparams == NULL) 142 if (Adapter->pstargetparams == NULL)
143 return -ENOMEM; 143 return -ENOMEM;
144 } 144 }
145 145
146 if (psFwInfo->u32FirmwareLength != sizeof(STARGETPARAMS)) 146 if (psFwInfo->u32FirmwareLength != sizeof(struct bcm_target_params))
147 return -EIO; 147 return -EIO;
148 148
149 retval = copy_from_user(Adapter->pstargetparams, psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength); 149 retval = copy_from_user(Adapter->pstargetparams, psFwInfo->pvMappedFirmwareAddress, psFwInfo->u32FirmwareLength);
@@ -195,7 +195,7 @@ static int bcm_download_config_file(struct bcm_mini_adapter *Adapter, struct bcm
195 } 195 }
196 } 196 }
197 197
198 retval = buffDnldVerify(Adapter, (PUCHAR)Adapter->pstargetparams, sizeof(STARGETPARAMS), CONFIG_BEGIN_ADDR); 198 retval = buffDnldVerify(Adapter, (PUCHAR)Adapter->pstargetparams, sizeof(struct bcm_target_params), CONFIG_BEGIN_ADDR);
199 199
200 if (retval) 200 if (retval)
201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "configuration file not downloaded properly"); 201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "configuration file not downloaded properly");
diff --git a/drivers/staging/bcm/InterfaceInit.c b/drivers/staging/bcm/InterfaceInit.c
index eb246430b320..79058ce5b332 100644
--- a/drivers/staging/bcm/InterfaceInit.c
+++ b/drivers/staging/bcm/InterfaceInit.c
@@ -190,9 +190,9 @@ static int usbbcm_device_probe(struct usb_interface *intf, const struct usb_devi
190 } 190 }
191 191
192 /* Allocate interface adapter structure */ 192 /* Allocate interface adapter structure */
193 psIntfAdapter = kzalloc(sizeof(struct bcm_interface_adapter), GFP_KERNEL); 193 psIntfAdapter = kzalloc(sizeof(struct bcm_interface_adapter),
194 GFP_KERNEL);
194 if (psIntfAdapter == NULL) { 195 if (psIntfAdapter == NULL) {
195 dev_err(&udev->dev, DRV_NAME ": no memory for Interface adapter\n");
196 AdapterFree(psAdapter); 196 AdapterFree(psAdapter);
197 return -ENOMEM; 197 return -ENOMEM;
198 } 198 }
@@ -564,11 +564,8 @@ static int InterfaceAdapterInit(struct bcm_interface_adapter *psIntfAdapter)
564 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval; 564 psIntfAdapter->sIntrIn.int_in_interval = endpoint->bInterval;
565 psIntfAdapter->sIntrIn.int_in_buffer = 565 psIntfAdapter->sIntrIn.int_in_buffer =
566 kmalloc(buffer_size, GFP_KERNEL); 566 kmalloc(buffer_size, GFP_KERNEL);
567 if (!psIntfAdapter->sIntrIn.int_in_buffer) { 567 if (!psIntfAdapter->sIntrIn.int_in_buffer)
568 dev_err(&psIntfAdapter->udev->dev,
569 "could not allocate interrupt_in_buffer\n");
570 return -EINVAL; 568 return -EINVAL;
571 }
572 } 569 }
573 570
574 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) { 571 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr && bcm_usb_endpoint_is_int_out(endpoint)) {
@@ -587,11 +584,8 @@ static int InterfaceAdapterInit(struct bcm_interface_adapter *psIntfAdapter)
587 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress; 584 psIntfAdapter->sIntrOut.int_out_endpointAddr = endpoint->bEndpointAddress;
588 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval; 585 psIntfAdapter->sIntrOut.int_out_interval = endpoint->bInterval;
589 psIntfAdapter->sIntrOut.int_out_buffer = kmalloc(buffer_size, GFP_KERNEL); 586 psIntfAdapter->sIntrOut.int_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
590 if (!psIntfAdapter->sIntrOut.int_out_buffer) { 587 if (!psIntfAdapter->sIntrOut.int_out_buffer)
591 dev_err(&psIntfAdapter->udev->dev,
592 "could not allocate interrupt_out_buffer\n");
593 return -EINVAL; 588 return -EINVAL;
594 }
595 } 589 }
596 } 590 }
597 } 591 }
diff --git a/drivers/staging/bcm/Ioctl.h b/drivers/staging/bcm/Ioctl.h
index 8c70af90969b..e253c080a787 100644
--- a/drivers/staging/bcm/Ioctl.h
+++ b/drivers/staging/bcm/Ioctl.h
@@ -108,7 +108,7 @@ enum bcm_interface_type {
108}; 108};
109 109
110struct bcm_driver_info { 110struct bcm_driver_info {
111 NVM_TYPE u32NVMType; 111 enum bcm_nvm_type u32NVMType;
112 unsigned int MaxRDMBufferSize; 112 unsigned int MaxRDMBufferSize;
113 enum bcm_interface_type u32InterfaceType; 113 enum bcm_interface_type u32InterfaceType;
114 unsigned int u32DSDStartOffset; 114 unsigned int u32DSDStartOffset;
@@ -202,8 +202,8 @@ struct bcm_flash2x_bitmap {
202}; 202};
203 203
204struct bcm_time_elapsed { 204struct bcm_time_elapsed {
205 unsigned long long ul64TimeElapsedSinceNetEntry; 205 u64 ul64TimeElapsedSinceNetEntry;
206 u32 uiReserved[4]; 206 u32 uiReserved[4];
207}; 207};
208 208
209enum { 209enum {
diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h
index 46f5f0feea88..dc01e3016d4f 100644
--- a/drivers/staging/bcm/Macros.h
+++ b/drivers/staging/bcm/Macros.h
@@ -162,13 +162,11 @@
162#define GPIO_MODE_REGISTER 0x0F000034 162#define GPIO_MODE_REGISTER 0x0F000034
163#define GPIO_PIN_STATE_REGISTER 0x0F000038 163#define GPIO_PIN_STATE_REGISTER 0x0F000038
164 164
165 165struct bcm_link_state {
166typedef struct _LINK_STATE { 166 unsigned char ucLinkStatus;
167 UCHAR ucLinkStatus; 167 unsigned char bIdleMode;
168 UCHAR bIdleMode; 168 unsigned char bShutdownMode;
169 UCHAR bShutdownMode; 169};
170} LINK_STATE, *PLINK_STATE;
171
172 170
173enum enLinkStatus { 171enum enLinkStatus {
174 WAIT_FOR_SYNC = 1, 172 WAIT_FOR_SYNC = 1,
@@ -182,13 +180,12 @@ enum enLinkStatus {
182 COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW = 9 180 COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW = 9
183}; 181};
184 182
185typedef enum _E_PHS_DSC_ACTION { 183enum bcm_phs_dsc_action {
186 eAddPHSRule = 0, 184 eAddPHSRule = 0,
187 eSetPHSRule, 185 eSetPHSRule,
188 eDeletePHSRule, 186 eDeletePHSRule,
189 eDeleteAllPHSRules 187 eDeleteAllPHSRules
190} E_PHS_DSC_ACTION; 188};
191
192 189
193#define CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ 0x89 /* Host to Mac */ 190#define CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ 0x89 /* Host to Mac */
194#define CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP 0xA9 /* Mac to Host */ 191#define CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP 0xA9 /* Mac to Host */
@@ -324,18 +321,18 @@ typedef enum _E_PHS_DSC_ACTION {
324#define HPM_CONFIG_MSW 0x0F000D58 321#define HPM_CONFIG_MSW 0x0F000D58
325 322
326#define T3B 0xbece0310 323#define T3B 0xbece0310
327typedef enum eNVM_TYPE { 324enum bcm_nvm_type {
328 NVM_AUTODETECT = 0, 325 NVM_AUTODETECT = 0,
329 NVM_EEPROM, 326 NVM_EEPROM,
330 NVM_FLASH, 327 NVM_FLASH,
331 NVM_UNKNOWN 328 NVM_UNKNOWN
332} NVM_TYPE; 329};
333 330
334typedef enum ePMU_MODES { 331enum bcm_pmu_modes {
335 HYBRID_MODE_7C = 0, 332 HYBRID_MODE_7C = 0,
336 INTERNAL_MODE_6 = 1, 333 INTERNAL_MODE_6 = 1,
337 HYBRID_MODE_6 = 2 334 HYBRID_MODE_6 = 2
338} PMU_MODE; 335};
339 336
340#define MAX_RDM_WRM_RETIRES 1 337#define MAX_RDM_WRM_RETIRES 1
341 338
diff --git a/drivers/staging/bcm/Misc.c b/drivers/staging/bcm/Misc.c
index c92078e7fe86..b5c2c4c15f92 100644
--- a/drivers/staging/bcm/Misc.c
+++ b/drivers/staging/bcm/Misc.c
@@ -956,7 +956,7 @@ int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
956 /* Download cfg file */ 956 /* Download cfg file */
957 status = buffDnldVerify(ps_adapter, 957 status = buffDnldVerify(ps_adapter,
958 (PUCHAR)ps_adapter->pstargetparams, 958 (PUCHAR)ps_adapter->pstargetparams,
959 sizeof(STARGETPARAMS), 959 sizeof(struct bcm_target_params),
960 CONFIG_BEGIN_ADDR); 960 CONFIG_BEGIN_ADDR);
961 if (status) { 961 if (status) {
962 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file"); 962 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
@@ -1053,7 +1053,7 @@ static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1053 if (!buff) 1053 if (!buff)
1054 return -ENOMEM; 1054 return -ENOMEM;
1055 1055
1056 Adapter->pstargetparams = kmalloc(sizeof(STARGETPARAMS), GFP_KERNEL); 1056 Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
1057 if (Adapter->pstargetparams == NULL) { 1057 if (Adapter->pstargetparams == NULL) {
1058 kfree(buff); 1058 kfree(buff);
1059 return -ENOMEM; 1059 return -ENOMEM;
@@ -1070,7 +1070,7 @@ static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1070 len = kernel_read(flp, 0, buff, BUFFER_1K); 1070 len = kernel_read(flp, 0, buff, BUFFER_1K);
1071 filp_close(flp, NULL); 1071 filp_close(flp, NULL);
1072 1072
1073 if (len != sizeof(STARGETPARAMS)) { 1073 if (len != sizeof(struct bcm_target_params)) {
1074 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n"); 1074 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
1075 kfree(buff); 1075 kfree(buff);
1076 kfree(Adapter->pstargetparams); 1076 kfree(Adapter->pstargetparams);
@@ -1082,7 +1082,7 @@ static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1082 /* 1082 /*
1083 * Values in Adapter->pstargetparams are in network byte order 1083 * Values in Adapter->pstargetparams are in network byte order
1084 */ 1084 */
1085 memcpy(Adapter->pstargetparams, buff, sizeof(STARGETPARAMS)); 1085 memcpy(Adapter->pstargetparams, buff, sizeof(struct bcm_target_params));
1086 kfree(buff); 1086 kfree(buff);
1087 beceem_parse_target_struct(Adapter); 1087 beceem_parse_target_struct(Adapter);
1088 return STATUS_SUCCESS; 1088 return STATUS_SUCCESS;
@@ -1134,7 +1134,7 @@ void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
1134 1134
1135 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag); 1135 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1136 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag); 1136 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
1137 Adapter->eNVMType = (NVM_TYPE)((uiEEPROMFlag>>4)&0x3); 1137 Adapter->eNVMType = (enum bcm_nvm_type)((uiEEPROMFlag>>4)&0x3);
1138 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1; 1138 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1139 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4)); 1139 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1140 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1; 1140 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h
index 6016fc502d2d..cd78ee4ffa22 100644
--- a/drivers/staging/bcm/PHSDefines.h
+++ b/drivers/staging/bcm/PHSDefines.h
@@ -1,124 +1,94 @@
1#ifndef BCM_PHS_DEFINES_H 1#ifndef BCM_PHS_DEFINES_H
2#define BCM_PHS_DEFINES_H 2#define BCM_PHS_DEFINES_H
3 3
4#define PHS_INVALID_TABLE_INDEX 0xffffffff 4#define PHS_INVALID_TABLE_INDEX 0xffffffff
5
6/************************* MACROS **********************************************/
7#define PHS_MEM_TAG "_SHP" 5#define PHS_MEM_TAG "_SHP"
8 6
9 7/* PHS Defines */
10 8#define STATUS_PHS_COMPRESSED 0xa1
11//PHS Defines 9#define STATUS_PHS_NOCOMPRESSION 0xa2
12#define STATUS_PHS_COMPRESSED 0xa1 10#define APPLY_PHS 1
13#define STATUS_PHS_NOCOMPRESSION 0xa2 11#define MAX_NO_BIT 7
14#define APPLY_PHS 1 12#define ZERO_PHSI 0
15#define MAX_NO_BIT 7 13#define VERIFY 0
16#define ZERO_PHSI 0 14#define SIZE_MULTIPLE_32 4
17#define VERIFY 0 15#define UNCOMPRESSED_PACKET 0
18#define SIZE_MULTIPLE_32 4 16#define DYNAMIC 0
19#define UNCOMPRESSED_PACKET 0 17#define SUPPRESS 0x80
20#define DYNAMIC 0 18#define NO_CLASSIFIER_MATCH 0
21#define SUPPRESS 0x80 19#define SEND_PACKET_UNCOMPRESSED 0
22#define NO_CLASSIFIER_MATCH 0 20#define PHSI_IS_ZERO 0
23#define SEND_PACKET_UNCOMPRESSED 0 21#define PHSI_LEN 1
24#define PHSI_IS_ZERO 0 22#define ERROR_LEN 0
25#define PHSI_LEN 1 23#define PHS_BUFFER_SIZE 1532
26#define ERROR_LEN 0 24#define MAX_PHSRULE_PER_SF 20
27#define PHS_BUFFER_SIZE 1532 25#define MAX_SERVICEFLOWS 17
28 26
29 27/* PHS Error Defines */
30#define MAX_PHSRULE_PER_SF 20 28#define PHS_SUCCESS 0
31#define MAX_SERVICEFLOWS 17 29#define ERR_PHS_INVALID_DEVICE_EXETENSION 0x800
32 30#define ERR_PHS_INVALID_PHS_RULE 0x801
33//PHS Error Defines 31#define ERR_PHS_RULE_ALREADY_EXISTS 0x802
34#define PHS_SUCCESS 0 32#define ERR_SF_MATCH_FAIL 0x803
35#define ERR_PHS_INVALID_DEVICE_EXETENSION 0x800 33#define ERR_INVALID_CLASSIFIERTABLE_FOR_SF 0x804
36#define ERR_PHS_INVALID_PHS_RULE 0x801 34#define ERR_SFTABLE_FULL 0x805
37#define ERR_PHS_RULE_ALREADY_EXISTS 0x802 35#define ERR_CLSASSIFIER_TABLE_FULL 0x806
38#define ERR_SF_MATCH_FAIL 0x803 36#define ERR_PHSRULE_MEMALLOC_FAIL 0x807
39#define ERR_INVALID_CLASSIFIERTABLE_FOR_SF 0x804 37#define ERR_CLSID_MATCH_FAIL 0x808
40#define ERR_SFTABLE_FULL 0x805 38#define ERR_PHSRULE_MATCH_FAIL 0x809
41#define ERR_CLSASSIFIER_TABLE_FULL 0x806 39
42#define ERR_PHSRULE_MEMALLOC_FAIL 0x807 40struct bcm_phs_rule {
43#define ERR_CLSID_MATCH_FAIL 0x808 41 u8 u8PHSI;
44#define ERR_PHSRULE_MATCH_FAIL 0x809 42 u8 u8PHSFLength;
45 43 u8 u8PHSF[MAX_PHS_LENGTHS];
46typedef struct _S_PHS_RULE 44 u8 u8PHSMLength;
47{ 45 u8 u8PHSM[MAX_PHS_LENGTHS];
48 /// brief 8bit PHSI Of The Service Flow 46 u8 u8PHSS;
49 B_UINT8 u8PHSI; 47 u8 u8PHSV;
50 /// brief PHSF Of The Service Flow 48 u8 u8RefCnt;
51 B_UINT8 u8PHSFLength; 49 u8 bUnclassifiedPHSRule;
52 B_UINT8 u8PHSF[MAX_PHS_LENGTHS]; 50 u8 u8Reserved[3];
53 /// brief PHSM Of The Service Flow 51 long PHSModifiedBytes;
54 B_UINT8 u8PHSMLength; 52 unsigned long PHSModifiedNumPackets;
55 B_UINT8 u8PHSM[MAX_PHS_LENGTHS]; 53 unsigned long PHSErrorNumPackets;
56 /// brief 8bit PHSS Of The Service Flow 54};
57 B_UINT8 u8PHSS; 55
58 /// brief 8bit PHSV Of The Service Flow 56enum bcm_phs_classifier_context {
59 B_UINT8 u8PHSV;
60 //Reference Count for this PHS Rule
61 B_UINT8 u8RefCnt;
62 //Flag to Store Unclassified PHS rules only in DL
63 B_UINT8 bUnclassifiedPHSRule;
64
65 B_UINT8 u8Reserved[3];
66
67 LONG PHSModifiedBytes;
68 ULONG PHSModifiedNumPackets;
69 ULONG PHSErrorNumPackets;
70}S_PHS_RULE;
71
72
73typedef enum _E_CLASSIFIER_ENTRY_CONTEXT
74{
75 eActiveClassifierRuleContext, 57 eActiveClassifierRuleContext,
76 eOldClassifierRuleContext 58 eOldClassifierRuleContext
77}E_CLASSIFIER_ENTRY_CONTEXT; 59};
78 60
79typedef struct _S_CLASSIFIER_ENTRY 61struct bcm_phs_classifier_entry {
80{ 62 u8 bUsed;
81 B_UINT8 bUsed; 63 u16 uiClassifierRuleId;
82 B_UINT16 uiClassifierRuleId; 64 u8 u8PHSI;
83 B_UINT8 u8PHSI; 65 struct bcm_phs_rule *pstPhsRule;
84 S_PHS_RULE *pstPhsRule; 66 u8 bUnclassifiedPHSRule;
85 B_UINT8 bUnclassifiedPHSRule; 67};
86 68
87}S_CLASSIFIER_ENTRY; 69struct bcm_phs_classifier_table {
88 70 u16 uiTotalClassifiers;
89 71 struct bcm_phs_classifier_entry stActivePhsRulesList[MAX_PHSRULE_PER_SF];
90typedef struct _S_CLASSIFIER_TABLE 72 struct bcm_phs_classifier_entry stOldPhsRulesList[MAX_PHSRULE_PER_SF];
91{ 73 u16 uiOldestPhsRuleIndex;
92 B_UINT16 uiTotalClassifiers; 74};
93 S_CLASSIFIER_ENTRY stActivePhsRulesList[MAX_PHSRULE_PER_SF]; 75
94 S_CLASSIFIER_ENTRY stOldPhsRulesList[MAX_PHSRULE_PER_SF]; 76struct bcm_phs_entry {
95 B_UINT16 uiOldestPhsRuleIndex; 77 u8 bUsed;
96 78 u16 uiVcid;
97}S_CLASSIFIER_TABLE; 79 struct bcm_phs_classifier_table *pstClassifierTable;
98 80};
99 81
100typedef struct _S_SERVICEFLOW_ENTRY 82struct bcm_phs_table {
101{ 83 u16 uiTotalServiceFlows;
102 B_UINT8 bUsed; 84 struct bcm_phs_entry stSFList[MAX_SERVICEFLOWS];
103 B_UINT16 uiVcid; 85};
104 S_CLASSIFIER_TABLE *pstClassifierTable; 86
105}S_SERVICEFLOW_ENTRY; 87struct bcm_phs_extension {
106 88 /* PHS Specific data */
107typedef struct _S_SERVICEFLOW_TABLE 89 struct bcm_phs_table *pstServiceFlowPhsRulesTable;
108{ 90 void *CompressedTxBuffer;
109 B_UINT16 uiTotalServiceFlows; 91 void *UnCompressedRxBuffer;
110 S_SERVICEFLOW_ENTRY stSFList[MAX_SERVICEFLOWS]; 92};
111
112}S_SERVICEFLOW_TABLE;
113
114
115typedef struct _PHS_DEVICE_EXTENSION
116{
117 /* PHS Specific data*/
118 S_SERVICEFLOW_TABLE *pstServiceFlowPhsRulesTable;
119 void *CompressedTxBuffer;
120 void *UnCompressedRxBuffer;
121}PHS_DEVICE_EXTENSION,*PPHS_DEVICE_EXTENSION;
122
123 93
124#endif 94#endif
diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c
index 6dc0bbcfeab0..7028bc95b4f9 100644
--- a/drivers/staging/bcm/PHSModule.c
+++ b/drivers/staging/bcm/PHSModule.c
@@ -1,24 +1,24 @@
1#include "headers.h" 1#include "headers.h"
2 2
3static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_TABLE *psServiceFlowTable,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); 3static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
4 4
5static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId,S_SERVICEFLOW_ENTRY *pstServiceFlowEntry,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); 5static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_entry *pstServiceFlowEntry, struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI);
6 6
7static UINT CreateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI); 7static 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);
8 8
9static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId,S_CLASSIFIER_ENTRY *pstClassifierEntry,S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI); 9static 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);
10 10
11static BOOLEAN ValidatePHSRuleComplete(S_PHS_RULE *psPhsRule); 11static BOOLEAN ValidatePHSRuleComplete(struct bcm_phs_rule *psPhsRule);
12 12
13static BOOLEAN DerefPhsRule(B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule); 13static BOOLEAN DerefPhsRule(B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule);
14 14
15static UINT GetClassifierEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, S_CLASSIFIER_ENTRY **ppstClassifierEntry); 15static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_classifier_entry **ppstClassifierEntry);
16 16
17static UINT GetPhsRuleEntry(S_CLASSIFIER_TABLE *pstClassifierTable,B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext,S_PHS_RULE **ppstPhsRule); 17static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext, struct bcm_phs_rule **ppstPhsRule);
18 18
19static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable); 19static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable);
20 20
21static int phs_compress(S_PHS_RULE *phs_members,unsigned char *in_buf, 21static int phs_compress(struct bcm_phs_rule *phs_members, unsigned char *in_buf,
22 unsigned char *out_buf,unsigned int *header_size,UINT *new_header_size ); 22 unsigned char *out_buf,unsigned int *header_size,UINT *new_header_size );
23 23
24 24
@@ -26,7 +26,7 @@ static int verify_suppress_phsf(unsigned char *in_buffer,unsigned char *out_buff
26 unsigned char *phsf,unsigned char *phsm,unsigned int phss,unsigned int phsv,UINT *new_header_size ); 26 unsigned char *phsf,unsigned char *phsm,unsigned int phss,unsigned int phsv,UINT *new_header_size );
27 27
28static int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,\ 28static int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,\
29 S_PHS_RULE *phs_rules,UINT *header_size); 29 struct bcm_phs_rule *phs_rules, UINT *header_size);
30 30
31 31
32static ULONG PhsCompress(void* pvContext, 32static ULONG PhsCompress(void* pvContext,
@@ -291,17 +291,17 @@ void DumpFullPacket(UCHAR *pBuf,UINT nPktLen)
291// TRUE(1) -If allocation of memory was success full. 291// TRUE(1) -If allocation of memory was success full.
292// FALSE -If allocation of memory fails. 292// FALSE -If allocation of memory fails.
293//----------------------------------------------------------------------------- 293//-----------------------------------------------------------------------------
294int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension, struct bcm_mini_adapter *Adapter) 294int phs_init(struct bcm_phs_extension *pPhsdeviceExtension, struct bcm_mini_adapter *Adapter)
295{ 295{
296 int i; 296 int i;
297 S_SERVICEFLOW_TABLE *pstServiceFlowTable; 297 struct bcm_phs_table *pstServiceFlowTable;
298 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nPHS:phs_init function "); 298 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nPHS:phs_init function ");
299 299
300 if(pPhsdeviceExtension->pstServiceFlowPhsRulesTable) 300 if(pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
301 return -EINVAL; 301 return -EINVAL;
302 302
303 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = 303 pPhsdeviceExtension->pstServiceFlowPhsRulesTable =
304 kzalloc(sizeof(S_SERVICEFLOW_TABLE), GFP_KERNEL); 304 kzalloc(sizeof(struct bcm_phs_table), GFP_KERNEL);
305 305
306 if(!pPhsdeviceExtension->pstServiceFlowPhsRulesTable) 306 if(!pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
307 { 307 {
@@ -312,8 +312,8 @@ int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension, struct bcm_mini_adapter
312 pstServiceFlowTable = pPhsdeviceExtension->pstServiceFlowPhsRulesTable; 312 pstServiceFlowTable = pPhsdeviceExtension->pstServiceFlowPhsRulesTable;
313 for(i=0;i<MAX_SERVICEFLOWS;i++) 313 for(i=0;i<MAX_SERVICEFLOWS;i++)
314 { 314 {
315 S_SERVICEFLOW_ENTRY sServiceFlow = pstServiceFlowTable->stSFList[i]; 315 struct bcm_phs_entry sServiceFlow = pstServiceFlowTable->stSFList[i];
316 sServiceFlow.pstClassifierTable = kzalloc(sizeof(S_CLASSIFIER_TABLE), GFP_KERNEL); 316 sServiceFlow.pstClassifierTable = kzalloc(sizeof(struct bcm_phs_classifier_table), GFP_KERNEL);
317 if(!sServiceFlow.pstClassifierTable) 317 if(!sServiceFlow.pstClassifierTable)
318 { 318 {
319 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed"); 319 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "\nAllocation failed");
@@ -351,7 +351,7 @@ int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension, struct bcm_mini_adapter
351} 351}
352 352
353 353
354int PhsCleanup(IN PPHS_DEVICE_EXTENSION pPHSDeviceExt) 354int PhsCleanup(IN struct bcm_phs_extension *pPHSDeviceExt)
355{ 355{
356 if(pPHSDeviceExt->pstServiceFlowPhsRulesTable) 356 if(pPHSDeviceExt->pstServiceFlowPhsRulesTable)
357 { 357 {
@@ -381,7 +381,7 @@ Arguments:
381 IN void* pvContext - PHS Driver Specific Context 381 IN void* pvContext - PHS Driver Specific Context
382 IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies 382 IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies
383 IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies. 383 IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies.
384 IN S_PHS_RULE *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table. 384 IN struct bcm_phs_rule *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table.
385 385
386Return Value: 386Return Value:
387 387
@@ -392,17 +392,17 @@ Return Value:
392ULONG PhsUpdateClassifierRule(IN void* pvContext, 392ULONG PhsUpdateClassifierRule(IN void* pvContext,
393 IN B_UINT16 uiVcid , 393 IN B_UINT16 uiVcid ,
394 IN B_UINT16 uiClsId , 394 IN B_UINT16 uiClsId ,
395 IN S_PHS_RULE *psPhsRule, 395 IN struct bcm_phs_rule *psPhsRule,
396 IN B_UINT8 u8AssociatedPHSI) 396 IN B_UINT8 u8AssociatedPHSI)
397{ 397{
398 ULONG lStatus =0; 398 ULONG lStatus =0;
399 UINT nSFIndex =0 ; 399 UINT nSFIndex =0 ;
400 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 400 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
401 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 401 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
402 402
403 403
404 404
405 PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; 405 struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
406 406
407 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"PHS With Corr2 Changes \n"); 407 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"PHS With Corr2 Changes \n");
408 408
@@ -460,12 +460,12 @@ ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI)
460{ 460{
461 ULONG lStatus =0; 461 ULONG lStatus =0;
462 UINT nSFIndex =0, nClsidIndex =0 ; 462 UINT nSFIndex =0, nClsidIndex =0 ;
463 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 463 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
464 S_CLASSIFIER_TABLE *pstClassifierRulesTable = NULL; 464 struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
465 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 465 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
466 466
467 467
468 PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; 468 struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
469 469
470 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "======>\n"); 470 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL, "======>\n");
471 471
@@ -495,7 +495,7 @@ ULONG PhsDeletePHSRule(IN void* pvContext,IN B_UINT16 uiVcid,IN B_UINT8 u8PHSI)
495 if(0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt) 495 if(0 == pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule->u8RefCnt)
496 kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule); 496 kfree(pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex].pstPhsRule);
497 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, 497 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0,
498 sizeof(S_CLASSIFIER_ENTRY)); 498 sizeof(struct bcm_phs_classifier_entry));
499 } 499 }
500 } 500 }
501 } 501 }
@@ -526,10 +526,10 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16
526{ 526{
527 ULONG lStatus =0; 527 ULONG lStatus =0;
528 UINT nSFIndex =0, nClsidIndex =0 ; 528 UINT nSFIndex =0, nClsidIndex =0 ;
529 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 529 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
530 S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; 530 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
531 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 531 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
532 PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; 532 struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
533 533
534 if(pDeviceExtension) 534 if(pDeviceExtension)
535 { 535 {
@@ -554,7 +554,7 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16
554 kfree(pstClassifierEntry->pstPhsRule); 554 kfree(pstClassifierEntry->pstPhsRule);
555 555
556 } 556 }
557 memset(pstClassifierEntry, 0, sizeof(S_CLASSIFIER_ENTRY)); 557 memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry));
558 } 558 }
559 559
560 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable, 560 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
@@ -563,7 +563,7 @@ ULONG PhsDeleteClassifierRule(IN void* pvContext,IN B_UINT16 uiVcid ,IN B_UINT16
563 if((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule)) 563 if((nClsidIndex != PHS_INVALID_TABLE_INDEX) && (!pstClassifierEntry->bUnclassifiedPHSRule))
564 { 564 {
565 kfree(pstClassifierEntry->pstPhsRule); 565 kfree(pstClassifierEntry->pstPhsRule);
566 memset(pstClassifierEntry, 0, sizeof(S_CLASSIFIER_ENTRY)); 566 memset(pstClassifierEntry, 0, sizeof(struct bcm_phs_classifier_entry));
567 } 567 }
568 } 568 }
569 return lStatus; 569 return lStatus;
@@ -590,10 +590,10 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid)
590 590
591 ULONG lStatus =0; 591 ULONG lStatus =0;
592 UINT nSFIndex =0, nClsidIndex =0 ; 592 UINT nSFIndex =0, nClsidIndex =0 ;
593 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 593 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
594 S_CLASSIFIER_TABLE *pstClassifierRulesTable = NULL; 594 struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
595 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 595 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
596 PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; 596 struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
597 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"====> \n"); 597 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"====> \n");
598 598
599 if(pDeviceExtension) 599 if(pDeviceExtension)
@@ -624,7 +624,7 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid)
624 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex] 624 pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex]
625 .pstPhsRule = NULL; 625 .pstPhsRule = NULL;
626 } 626 }
627 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(S_CLASSIFIER_ENTRY)); 627 memset(&pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry));
628 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule) 628 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex].pstPhsRule)
629 { 629 {
630 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex] 630 if(pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
@@ -638,7 +638,7 @@ ULONG PhsDeleteSFRules(IN void* pvContext,IN B_UINT16 uiVcid)
638 pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex] 638 pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex]
639 .pstPhsRule = NULL; 639 .pstPhsRule = NULL;
640 } 640 }
641 memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(S_CLASSIFIER_ENTRY)); 641 memset(&pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex], 0, sizeof(struct bcm_phs_classifier_entry));
642 } 642 }
643 } 643 }
644 pstServiceFlowEntry->bUsed = FALSE; 644 pstServiceFlowEntry->bUsed = FALSE;
@@ -680,15 +680,15 @@ ULONG PhsCompress(IN void* pvContext,
680 OUT UINT *pNewHeaderSize ) 680 OUT UINT *pNewHeaderSize )
681{ 681{
682 UINT nSFIndex =0, nClsidIndex =0 ; 682 UINT nSFIndex =0, nClsidIndex =0 ;
683 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 683 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
684 S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; 684 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
685 S_PHS_RULE *pstPhsRule = NULL; 685 struct bcm_phs_rule *pstPhsRule = NULL;
686 ULONG lStatus =0; 686 ULONG lStatus =0;
687 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 687 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
688 688
689 689
690 690
691 PPHS_DEVICE_EXTENSION pDeviceExtension= (PPHS_DEVICE_EXTENSION)pvContext; 691 struct bcm_phs_extension *pDeviceExtension= (struct bcm_phs_extension *)pvContext;
692 692
693 693
694 if(pDeviceExtension == NULL) 694 if(pDeviceExtension == NULL)
@@ -775,12 +775,12 @@ ULONG PhsDeCompress(IN void* pvContext,
775 OUT UINT *pOutHeaderSize ) 775 OUT UINT *pOutHeaderSize )
776{ 776{
777 UINT nSFIndex =0, nPhsRuleIndex =0 ; 777 UINT nSFIndex =0, nPhsRuleIndex =0 ;
778 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 778 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
779 S_PHS_RULE *pstPhsRule = NULL; 779 struct bcm_phs_rule *pstPhsRule = NULL;
780 UINT phsi; 780 UINT phsi;
781 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 781 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
782 PPHS_DEVICE_EXTENSION pDeviceExtension= 782 struct bcm_phs_extension *pDeviceExtension=
783 (PPHS_DEVICE_EXTENSION)pvContext; 783 (struct bcm_phs_extension *)pvContext;
784 784
785 *pInHeaderSize = 0; 785 *pInHeaderSize = 0;
786 786
@@ -844,7 +844,7 @@ ULONG PhsDeCompress(IN void* pvContext,
844// Does not return any value. 844// Does not return any value.
845//----------------------------------------------------------------------------- 845//-----------------------------------------------------------------------------
846 846
847static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTable) 847static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable)
848{ 848{
849 int i,j; 849 int i,j;
850 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 850 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -854,9 +854,9 @@ static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTa
854 { 854 {
855 for(i=0;i<MAX_SERVICEFLOWS;i++) 855 for(i=0;i<MAX_SERVICEFLOWS;i++)
856 { 856 {
857 S_SERVICEFLOW_ENTRY stServiceFlowEntry = 857 struct bcm_phs_entry stServiceFlowEntry =
858 psServiceFlowRulesTable->stSFList[i]; 858 psServiceFlowRulesTable->stSFList[i];
859 S_CLASSIFIER_TABLE *pstClassifierRulesTable = 859 struct bcm_phs_classifier_table *pstClassifierRulesTable =
860 stServiceFlowEntry.pstClassifierTable; 860 stServiceFlowEntry.pstClassifierTable;
861 861
862 if(pstClassifierRulesTable) 862 if(pstClassifierRulesTable)
@@ -898,7 +898,7 @@ static void free_phs_serviceflow_rules(S_SERVICEFLOW_TABLE *psServiceFlowRulesTa
898 898
899 899
900 900
901static BOOLEAN ValidatePHSRuleComplete(IN S_PHS_RULE *psPhsRule) 901static BOOLEAN ValidatePHSRuleComplete(IN struct bcm_phs_rule *psPhsRule)
902{ 902{
903 if(psPhsRule) 903 if(psPhsRule)
904 { 904 {
@@ -927,8 +927,8 @@ static BOOLEAN ValidatePHSRuleComplete(IN S_PHS_RULE *psPhsRule)
927 } 927 }
928} 928}
929 929
930UINT GetServiceFlowEntry(IN S_SERVICEFLOW_TABLE *psServiceFlowTable, 930UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable,
931 IN B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry) 931 IN B_UINT16 uiVcid, struct bcm_phs_entry **ppstServiceFlowEntry)
932{ 932{
933 int i; 933 int i;
934 for(i=0;i<MAX_SERVICEFLOWS;i++) 934 for(i=0;i<MAX_SERVICEFLOWS;i++)
@@ -948,12 +948,12 @@ UINT GetServiceFlowEntry(IN S_SERVICEFLOW_TABLE *psServiceFlowTable,
948} 948}
949 949
950 950
951UINT GetClassifierEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable, 951UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
952 IN B_UINT32 uiClsid,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, 952 IN B_UINT32 uiClsid, enum bcm_phs_classifier_context eClsContext,
953 OUT S_CLASSIFIER_ENTRY **ppstClassifierEntry) 953 OUT struct bcm_phs_classifier_entry **ppstClassifierEntry)
954{ 954{
955 int i; 955 int i;
956 S_CLASSIFIER_ENTRY *psClassifierRules = NULL; 956 struct bcm_phs_classifier_entry *psClassifierRules = NULL;
957 for(i=0;i<MAX_PHSRULE_PER_SF;i++) 957 for(i=0;i<MAX_PHSRULE_PER_SF;i++)
958 { 958 {
959 959
@@ -981,12 +981,12 @@ UINT GetClassifierEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable,
981 return PHS_INVALID_TABLE_INDEX; 981 return PHS_INVALID_TABLE_INDEX;
982} 982}
983 983
984static UINT GetPhsRuleEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable, 984static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
985 IN B_UINT32 uiPHSI,E_CLASSIFIER_ENTRY_CONTEXT eClsContext, 985 IN B_UINT32 uiPHSI, enum bcm_phs_classifier_context eClsContext,
986 OUT S_PHS_RULE **ppstPhsRule) 986 OUT struct bcm_phs_rule **ppstPhsRule)
987{ 987{
988 int i; 988 int i;
989 S_CLASSIFIER_ENTRY *pstClassifierRule = NULL; 989 struct bcm_phs_classifier_entry *pstClassifierRule = NULL;
990 for(i=0;i<MAX_PHSRULE_PER_SF;i++) 990 for(i=0;i<MAX_PHSRULE_PER_SF;i++)
991 { 991 {
992 if(eClsContext == eActiveClassifierRuleContext) 992 if(eClsContext == eActiveClassifierRuleContext)
@@ -1013,11 +1013,11 @@ static UINT GetPhsRuleEntry(IN S_CLASSIFIER_TABLE *pstClassifierTable,
1013} 1013}
1014 1014
1015UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16 uiClsId, 1015UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16 uiClsId,
1016 IN S_SERVICEFLOW_TABLE *psServiceFlowTable,S_PHS_RULE *psPhsRule, 1016 IN struct bcm_phs_table *psServiceFlowTable, struct bcm_phs_rule *psPhsRule,
1017 B_UINT8 u8AssociatedPHSI) 1017 B_UINT8 u8AssociatedPHSI)
1018{ 1018{
1019 1019
1020 S_CLASSIFIER_TABLE *psaClassifiertable = NULL; 1020 struct bcm_phs_classifier_table *psaClassifiertable = NULL;
1021 UINT uiStatus = 0; 1021 UINT uiStatus = 0;
1022 int iSfIndex; 1022 int iSfIndex;
1023 BOOLEAN bFreeEntryFound =FALSE; 1023 BOOLEAN bFreeEntryFound =FALSE;
@@ -1050,13 +1050,13 @@ UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,IN B_UINT16 uiClsId,
1050} 1050}
1051 1051
1052UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid, 1052UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
1053 IN B_UINT16 uiClsId,IN S_SERVICEFLOW_ENTRY *pstServiceFlowEntry, 1053 IN B_UINT16 uiClsId,IN struct bcm_phs_entry *pstServiceFlowEntry,
1054 S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI) 1054 struct bcm_phs_rule *psPhsRule, B_UINT8 u8AssociatedPHSI)
1055{ 1055{
1056 S_CLASSIFIER_ENTRY *pstClassifierEntry = NULL; 1056 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
1057 UINT uiStatus =PHS_SUCCESS; 1057 UINT uiStatus =PHS_SUCCESS;
1058 UINT nClassifierIndex = 0; 1058 UINT nClassifierIndex = 0;
1059 S_CLASSIFIER_TABLE *psaClassifiertable = NULL; 1059 struct bcm_phs_classifier_table *psaClassifiertable = NULL;
1060 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 1060 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1061 psaClassifiertable = pstServiceFlowEntry->pstClassifierTable; 1061 psaClassifiertable = pstServiceFlowEntry->pstClassifierTable;
1062 1062
@@ -1141,12 +1141,12 @@ UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
1141} 1141}
1142 1142
1143static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId, 1143static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1144 S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule, 1144 struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule,
1145 E_CLASSIFIER_ENTRY_CONTEXT eClsContext,B_UINT8 u8AssociatedPHSI) 1145 enum bcm_phs_classifier_context eClsContext,B_UINT8 u8AssociatedPHSI)
1146{ 1146{
1147 UINT iClassifierIndex = 0; 1147 UINT iClassifierIndex = 0;
1148 BOOLEAN bFreeEntryFound = FALSE; 1148 BOOLEAN bFreeEntryFound = FALSE;
1149 S_CLASSIFIER_ENTRY *psClassifierRules = NULL; 1149 struct bcm_phs_classifier_entry *psClassifierRules = NULL;
1150 UINT nStatus = PHS_SUCCESS; 1150 UINT nStatus = PHS_SUCCESS;
1151 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 1151 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1152 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"Inside CreateClassifierPHSRule"); 1152 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,"Inside CreateClassifierPHSRule");
@@ -1227,7 +1227,7 @@ static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1227 { 1227 {
1228 if(psClassifierRules->pstPhsRule == NULL) 1228 if(psClassifierRules->pstPhsRule == NULL)
1229 { 1229 {
1230 psClassifierRules->pstPhsRule = kmalloc(sizeof(S_PHS_RULE),GFP_KERNEL); 1230 psClassifierRules->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule),GFP_KERNEL);
1231 1231
1232 if(NULL == psClassifierRules->pstPhsRule) 1232 if(NULL == psClassifierRules->pstPhsRule)
1233 return ERR_PHSRULE_MEMALLOC_FAIL; 1233 return ERR_PHSRULE_MEMALLOC_FAIL;
@@ -1240,7 +1240,7 @@ static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1240 1240
1241 /* Update The PHS rule */ 1241 /* Update The PHS rule */
1242 memcpy(psClassifierRules->pstPhsRule, 1242 memcpy(psClassifierRules->pstPhsRule,
1243 psPhsRule, sizeof(S_PHS_RULE)); 1243 psPhsRule, sizeof(struct bcm_phs_rule));
1244 } 1244 }
1245 else 1245 else
1246 { 1246 {
@@ -1252,11 +1252,11 @@ static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1252 1252
1253 1253
1254static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId, 1254static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1255 IN S_CLASSIFIER_ENTRY *pstClassifierEntry, 1255 IN struct bcm_phs_classifier_entry *pstClassifierEntry,
1256 S_CLASSIFIER_TABLE *psaClassifiertable ,S_PHS_RULE *psPhsRule, 1256 struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *psPhsRule,
1257 B_UINT8 u8AssociatedPHSI) 1257 B_UINT8 u8AssociatedPHSI)
1258{ 1258{
1259 S_PHS_RULE *pstAddPhsRule = NULL; 1259 struct bcm_phs_rule *pstAddPhsRule = NULL;
1260 UINT nPhsRuleIndex = 0; 1260 UINT nPhsRuleIndex = 0;
1261 BOOLEAN bPHSRuleOrphaned = FALSE; 1261 BOOLEAN bPHSRuleOrphaned = FALSE;
1262 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 1262 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -1281,13 +1281,13 @@ static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1281 //Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId 1281 //Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for uiClsId
1282 if(FALSE == bPHSRuleOrphaned) 1282 if(FALSE == bPHSRuleOrphaned)
1283 { 1283 {
1284 pstClassifierEntry->pstPhsRule = kmalloc(sizeof(S_PHS_RULE), GFP_KERNEL); 1284 pstClassifierEntry->pstPhsRule = kmalloc(sizeof(struct bcm_phs_rule), GFP_KERNEL);
1285 if(NULL == pstClassifierEntry->pstPhsRule) 1285 if(NULL == pstClassifierEntry->pstPhsRule)
1286 { 1286 {
1287 return ERR_PHSRULE_MEMALLOC_FAIL; 1287 return ERR_PHSRULE_MEMALLOC_FAIL;
1288 } 1288 }
1289 } 1289 }
1290 memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(S_PHS_RULE)); 1290 memcpy(pstClassifierEntry->pstPhsRule, psPhsRule, sizeof(struct bcm_phs_rule));
1291 1291
1292 } 1292 }
1293 else 1293 else
@@ -1312,7 +1312,7 @@ static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1312 1312
1313} 1313}
1314 1314
1315static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifiertable,S_PHS_RULE *pstPhsRule) 1315static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId, struct bcm_phs_classifier_table *psaClassifiertable, struct bcm_phs_rule *pstPhsRule)
1316{ 1316{
1317 if(pstPhsRule==NULL) 1317 if(pstPhsRule==NULL)
1318 return FALSE; 1318 return FALSE;
@@ -1331,14 +1331,14 @@ static BOOLEAN DerefPhsRule(IN B_UINT16 uiClsId,S_CLASSIFIER_TABLE *psaClassifi
1331 } 1331 }
1332} 1332}
1333 1333
1334void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension) 1334void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension)
1335{ 1335{
1336 int i,j,k,l; 1336 int i,j,k,l;
1337 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 1337 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1338 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n Dumping PHS Rules : \n"); 1338 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n Dumping PHS Rules : \n");
1339 for(i=0;i<MAX_SERVICEFLOWS;i++) 1339 for(i=0;i<MAX_SERVICEFLOWS;i++)
1340 { 1340 {
1341 S_SERVICEFLOW_ENTRY stServFlowEntry = 1341 struct bcm_phs_entry stServFlowEntry =
1342 pDeviceExtension->pstServiceFlowPhsRulesTable->stSFList[i]; 1342 pDeviceExtension->pstServiceFlowPhsRulesTable->stSFList[i];
1343 if(stServFlowEntry.bUsed) 1343 if(stServFlowEntry.bUsed)
1344 { 1344 {
@@ -1346,7 +1346,7 @@ void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension)
1346 { 1346 {
1347 for(l=0;l<2;l++) 1347 for(l=0;l<2;l++)
1348 { 1348 {
1349 S_CLASSIFIER_ENTRY stClsEntry; 1349 struct bcm_phs_classifier_entry stClsEntry;
1350 if(l==0) 1350 if(l==0)
1351 { 1351 {
1352 stClsEntry = stServFlowEntry.pstClassifierTable->stActivePhsRulesList[j]; 1352 stClsEntry = stServFlowEntry.pstClassifierTable->stActivePhsRulesList[j];
@@ -1408,10 +1408,10 @@ void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension)
1408//----------------------------------------------------------------------------- 1408//-----------------------------------------------------------------------------
1409 1409
1410int phs_decompress(unsigned char *in_buf,unsigned char *out_buf, 1410int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,
1411 S_PHS_RULE *decomp_phs_rules,UINT *header_size) 1411 struct bcm_phs_rule *decomp_phs_rules, UINT *header_size)
1412{ 1412{
1413 int phss,size=0; 1413 int phss,size=0;
1414 S_PHS_RULE *tmp_memb; 1414 struct bcm_phs_rule *tmp_memb;
1415 int bit,i=0; 1415 int bit,i=0;
1416 unsigned char *phsf,*phsm; 1416 unsigned char *phsf,*phsm;
1417 int in_buf_len = *header_size-1; 1417 int in_buf_len = *header_size-1;
@@ -1490,7 +1490,7 @@ int phs_decompress(unsigned char *in_buf,unsigned char *out_buf,
1490// size-The number of bytes copied into the output buffer i.e dynamic fields 1490// size-The number of bytes copied into the output buffer i.e dynamic fields
1491// 0 -If PHS rule is NULL.If PHSV field is not set.If the verification fails. 1491// 0 -If PHS rule is NULL.If PHSV field is not set.If the verification fails.
1492//----------------------------------------------------------------------------- 1492//-----------------------------------------------------------------------------
1493static int phs_compress(S_PHS_RULE *phs_rule,unsigned char *in_buf 1493static int phs_compress(struct bcm_phs_rule *phs_rule, unsigned char *in_buf
1494 ,unsigned char *out_buf,UINT *header_size,UINT *new_header_size) 1494 ,unsigned char *out_buf,UINT *header_size,UINT *new_header_size)
1495{ 1495{
1496 unsigned char *old_addr = out_buf; 1496 unsigned char *old_addr = out_buf;
diff --git a/drivers/staging/bcm/PHSModule.h b/drivers/staging/bcm/PHSModule.h
index b5f21157ac47..82d868284180 100644
--- a/drivers/staging/bcm/PHSModule.h
+++ b/drivers/staging/bcm/PHSModule.h
@@ -22,15 +22,15 @@ void DumpDataPacketHeader(PUCHAR pPkt);
22 22
23void DumpFullPacket(UCHAR *pBuf,UINT nPktLen); 23void DumpFullPacket(UCHAR *pBuf,UINT nPktLen);
24 24
25void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension); 25void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension);
26 26
27 27
28int phs_init(PPHS_DEVICE_EXTENSION pPhsdeviceExtension,struct bcm_mini_adapter *Adapter); 28int phs_init(struct bcm_phs_extension *pPhsdeviceExtension,struct bcm_mini_adapter *Adapter);
29 29
30int PhsCleanup(PPHS_DEVICE_EXTENSION pPHSDeviceExt); 30int PhsCleanup(struct bcm_phs_extension *pPHSDeviceExt);
31 31
32//Utility Functions 32//Utility Functions
33ULONG PhsUpdateClassifierRule(void* pvContext,B_UINT16 uiVcid,B_UINT16 uiClsId,S_PHS_RULE *psPhsRule,B_UINT8 u8AssociatedPHSI ); 33ULONG PhsUpdateClassifierRule(void* pvContext,B_UINT16 uiVcid,B_UINT16 uiClsId, struct bcm_phs_rule *psPhsRule,B_UINT8 u8AssociatedPHSI );
34 34
35ULONG PhsDeletePHSRule(void* pvContext,B_UINT16 uiVcid,B_UINT8 u8PHSI); 35ULONG PhsDeletePHSRule(void* pvContext,B_UINT16 uiVcid,B_UINT8 u8PHSI);
36 36
@@ -39,12 +39,12 @@ ULONG PhsDeleteClassifierRule(void* pvContext, B_UINT16 uiVcid ,B_UINT16 uiClsI
39ULONG PhsDeleteSFRules(void* pvContext,B_UINT16 uiVcid) ; 39ULONG PhsDeleteSFRules(void* pvContext,B_UINT16 uiVcid) ;
40 40
41 41
42BOOLEAN ValidatePHSRule(S_PHS_RULE *psPhsRule); 42BOOLEAN ValidatePHSRule(struct bcm_phs_rule *psPhsRule);
43 43
44UINT GetServiceFlowEntry(S_SERVICEFLOW_TABLE *psServiceFlowTable,B_UINT16 uiVcid,S_SERVICEFLOW_ENTRY **ppstServiceFlowEntry); 44UINT GetServiceFlowEntry(struct bcm_phs_table *psServiceFlowTable,B_UINT16 uiVcid, struct bcm_phs_entry **ppstServiceFlowEntry);
45 45
46 46
47void DumpPhsRules(PPHS_DEVICE_EXTENSION pDeviceExtension); 47void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension);
48 48
49 49
50#endif 50#endif
diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h
index 562d4dd81a7c..9818128d9320 100644
--- a/drivers/staging/bcm/Protocol.h
+++ b/drivers/staging/bcm/Protocol.h
@@ -1,98 +1,83 @@
1/************************************ 1/************************************
2* Protocol.h 2* Protocol.h
3*************************************/ 3*************************************/
4#ifndef __PROTOCOL_H__ 4#ifndef __PROTOCOL_H__
5#define __PROTOCOL_H__ 5#define __PROTOCOL_H__
6 6
7 7#define IPV4 4
8#define IPV4 4 8#define IPV6 6
9#define IPV6 6
10
11 9
12struct ArpHeader { 10struct ArpHeader {
13 struct arphdr arp; 11 struct arphdr arp;
14 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ 12 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
15 unsigned char ar_sip[4]; /* sender IP address */ 13 unsigned char ar_sip[4]; /* sender IP address */
16 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ 14 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
17 unsigned char ar_tip[4]; /* target IP address */ 15 unsigned char ar_tip[4]; /* target IP address */
18}/*__attribute__((packed))*/; 16};
19 17
20 18struct bcm_transport_header {
21struct TransportHeaderT 19 union {
22{
23 union
24 {
25 struct udphdr uhdr; 20 struct udphdr uhdr;
26 struct tcphdr thdr; 21 struct tcphdr thdr;
27 }; 22 };
28} __attribute__((packed)); 23} __packed;
29typedef struct TransportHeaderT xporthdr;
30
31 24
32typedef enum _E_NWPKT_IPFRAME_TYPE 25enum bcm_ip_frame_type {
33{
34 eNonIPPacket, 26 eNonIPPacket,
35 eIPv4Packet, 27 eIPv4Packet,
36 eIPv6Packet 28 eIPv6Packet
37}E_NWPKT_IPFRAME_TYPE; 29};
38 30
39typedef enum _E_NWPKT_ETHFRAME_TYPE 31enum bcm_eth_frame_type {
40{
41 eEthUnsupportedFrame, 32 eEthUnsupportedFrame,
42 eEth802LLCFrame, 33 eEth802LLCFrame,
43 eEth802LLCSNAPFrame, 34 eEth802LLCSNAPFrame,
44 eEth802QVLANFrame, 35 eEth802QVLANFrame,
45 eEthOtherFrame 36 eEthOtherFrame
46} E_NWPKT_ETHFRAME_TYPE; 37};
47 38
48typedef struct _S_ETHCS_PKT_INFO 39struct bcm_eth_packet_info {
49{ 40 enum bcm_ip_frame_type eNwpktIPFrameType;
50 E_NWPKT_IPFRAME_TYPE eNwpktIPFrameType; 41 enum bcm_eth_frame_type eNwpktEthFrameType;
51 E_NWPKT_ETHFRAME_TYPE eNwpktEthFrameType; 42 unsigned short usEtherType;
52 USHORT usEtherType; 43 unsigned char ucDSAP;
53 UCHAR ucDSAP; 44};
54}S_ETHCS_PKT_INFO,*PS_ETHCS_PKT_INFO; 45
55 46struct bcm_eth_q_frame {
56typedef struct _ETH_CS_802_Q_FRAME
57{
58 struct bcm_eth_header EThHdr; 47 struct bcm_eth_header EThHdr;
59 USHORT UserPriority:3; 48 unsigned short UserPriority:3;
60 USHORT CFI:1; 49 unsigned short CFI:1;
61 USHORT VLANID:12; 50 unsigned short VLANID:12;
62 USHORT EthType; 51 unsigned short EthType;
63} __attribute__((packed)) ETH_CS_802_Q_FRAME; 52} __packed;
64 53
65typedef struct _ETH_CS_802_LLC_FRAME 54struct bcm_eth_llc_frame {
66{
67 struct bcm_eth_header EThHdr; 55 struct bcm_eth_header EThHdr;
68 unsigned char DSAP; 56 unsigned char DSAP;
69 unsigned char SSAP; 57 unsigned char SSAP;
70 unsigned char Control; 58 unsigned char Control;
71}__attribute__((packed)) ETH_CS_802_LLC_FRAME; 59} __packed;
72 60
73typedef struct _ETH_CS_802_LLC_SNAP_FRAME 61struct bcm_eth_llc_snap_frame {
74{
75 struct bcm_eth_header EThHdr; 62 struct bcm_eth_header EThHdr;
76 unsigned char DSAP; 63 unsigned char DSAP;
77 unsigned char SSAP; 64 unsigned char SSAP;
78 unsigned char Control; 65 unsigned char Control;
79 unsigned char OUI[3]; 66 unsigned char OUI[3];
80 unsigned short usEtherType; 67 unsigned short usEtherType;
81} __attribute__((packed)) ETH_CS_802_LLC_SNAP_FRAME; 68} __packed;
82 69
83typedef struct _ETH_CS_ETH2_FRAME 70struct bcm_ethernet2_frame {
84{
85 struct bcm_eth_header EThHdr; 71 struct bcm_eth_header EThHdr;
86} __attribute__((packed)) ETH_CS_ETH2_FRAME; 72} __packed;
87 73
88#define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800) 74#define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800)
89#define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd) 75#define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd)
90#define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100) 76#define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100)
91 77
92//Per SF CS Specification Encodings 78/* Per SF CS Specification Encodings */
93typedef enum _E_SERVICEFLOW_CS_SPEC_ 79enum bcm_spec_encoding {
94{ 80 eCSSpecUnspecified = 0,
95 eCSSpecUnspecified =0,
96 eCSPacketIPV4, 81 eCSPacketIPV4,
97 eCSPacketIPV6, 82 eCSPacketIPV6,
98 eCS802_3PacketEthernet, 83 eCS802_3PacketEthernet,
@@ -102,50 +87,42 @@ typedef enum _E_SERVICEFLOW_CS_SPEC_
102 eCSPacketIPV4Over802_1QVLAN, 87 eCSPacketIPV4Over802_1QVLAN,
103 eCSPacketIPV6Over802_1QVLAN, 88 eCSPacketIPV6Over802_1QVLAN,
104 eCSPacketUnsupported 89 eCSPacketUnsupported
105}E_SERVICEFLOW_CS_SPEC; 90};
106
107
108#define IP6_HEADER_LEN 40
109
110#define IP_VERSION(byte) (((byte&0xF0)>>4))
111
112 91
92#define IP6_HEADER_LEN 40
93#define IP_VERSION(byte) (((byte&0xF0)>>4))
113 94
114#define MAC_ADDRESS_SIZE 6 95#define MAC_ADDRESS_SIZE 6
115#define ETH_AND_IP_HEADER_LEN 14 + 20 96#define ETH_AND_IP_HEADER_LEN (14 + 20)
116#define L4_SRC_PORT_LEN 2 97#define L4_SRC_PORT_LEN 2
117#define L4_DEST_PORT_LEN 2 98#define L4_DEST_PORT_LEN 2
118 99#define CTRL_PKT_LEN (8 + ETH_AND_IP_HEADER_LEN)
119 100
120 101#define ETH_ARP_FRAME 0x806
121#define CTRL_PKT_LEN 8 + ETH_AND_IP_HEADER_LEN 102#define ETH_IPV4_FRAME 0x800
122 103#define ETH_IPV6_FRAME 0x86DD
123#define ETH_ARP_FRAME 0x806 104#define UDP 0x11
124#define ETH_IPV4_FRAME 0x800 105#define TCP 0x06
125#define ETH_IPV6_FRAME 0x86DD 106
126#define UDP 0x11 107#define ARP_OP_REQUEST 0x01
127#define TCP 0x06 108#define ARP_OP_REPLY 0x02
128 109#define ARP_PKT_SIZE 60
129#define ARP_OP_REQUEST 0x01 110
130#define ARP_OP_REPLY 0x02 111/* This is the format for the TCP packet header */
131#define ARP_PKT_SIZE 60 112struct bcm_tcp_header {
132 113 unsigned short usSrcPort;
133// This is the format for the TCP packet header 114 unsigned short usDestPort;
134typedef struct _TCP_HEADER 115 unsigned long ulSeqNumber;
135{ 116 unsigned long ulAckNumber;
136 USHORT usSrcPort; 117 unsigned char HeaderLength;
137 USHORT usDestPort; 118 unsigned char ucFlags;
138 ULONG ulSeqNumber; 119 unsigned short usWindowsSize;
139 ULONG ulAckNumber; 120 unsigned short usChkSum;
140 UCHAR HeaderLength; 121 unsigned short usUrgetPtr;
141 UCHAR ucFlags; 122};
142 USHORT usWindowsSize; 123
143 USHORT usChkSum; 124#define TCP_HEADER_LEN sizeof(struct bcm_tcp_header)
144 USHORT usUrgetPtr; 125#define TCP_ACK 0x10 /* Bit 4 in tcpflags field. */
145} TCP_HEADER,*PTCP_HEADER;
146#define TCP_HEADER_LEN sizeof(TCP_HEADER)
147#define TCP_ACK 0x10 //Bit 4 in tcpflags field.
148#define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4) 126#define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4)
149 127
150 128#endif /* __PROTOCOL_H__ */
151#endif //__PROTOCOL_H__
diff --git a/drivers/staging/bcm/Prototypes.h b/drivers/staging/bcm/Prototypes.h
index 90dbe0f4785e..2a673b125f00 100644
--- a/drivers/staging/bcm/Prototypes.h
+++ b/drivers/staging/bcm/Prototypes.h
@@ -33,9 +33,9 @@ INT SearchSfid(struct bcm_mini_adapter *Adapter,UINT uiSfid);
33 33
34USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb); 34USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb);
35 35
36BOOLEAN MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort); 36bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort);
37BOOLEAN MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort); 37bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort);
38BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProtocol); 38bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProtocol);
39 39
40 40
41INT SetupNextSend(struct bcm_mini_adapter *Adapter, /**<Logical Adapter*/ 41INT SetupNextSend(struct bcm_mini_adapter *Adapter, /**<Logical Adapter*/
diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c
index 1b857bd887f0..8d142a547e7f 100644
--- a/drivers/staging/bcm/Qos.c
+++ b/drivers/staging/bcm/Qos.c
@@ -4,8 +4,8 @@ This file contains the routines related to Quality of Service.
4*/ 4*/
5#include "headers.h" 5#include "headers.h"
6 6
7static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload,PS_ETHCS_PKT_INFO pstEthCsPktInfo); 7static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload, struct bcm_eth_packet_info *pstEthCsPktInfo);
8static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo,struct bcm_classifier_rule *pstClassifierRule, B_UINT8 EthCSCupport); 8static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo,struct bcm_classifier_rule *pstClassifierRule, B_UINT8 EthCSCupport);
9 9
10static USHORT IpVersion4(struct bcm_mini_adapter *Adapter, struct iphdr *iphd, 10static USHORT IpVersion4(struct bcm_mini_adapter *Adapter, struct iphdr *iphd,
11 struct bcm_classifier_rule *pstClassifierRule ); 11 struct bcm_classifier_rule *pstClassifierRule );
@@ -117,7 +117,7 @@ BOOLEAN MatchTos(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucTypeOfSer
117* 117*
118* Returns - TRUE(If address matches) else FAIL. 118* Returns - TRUE(If address matches) else FAIL.
119****************************************************************************/ 119****************************************************************************/
120BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProtocol) 120bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProtocol)
121{ 121{
122 UCHAR ucLoopIndex=0; 122 UCHAR ucLoopIndex=0;
123 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 123 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -146,7 +146,7 @@ BOOLEAN MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,UCHAR ucProt
146* 146*
147* Returns - TRUE(If address matches) else FAIL. 147* Returns - TRUE(If address matches) else FAIL.
148***************************************************************************/ 148***************************************************************************/
149BOOLEAN MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort) 149bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrcPort)
150{ 150{
151 UCHAR ucLoopIndex=0; 151 UCHAR ucLoopIndex=0;
152 152
@@ -178,7 +178,7 @@ BOOLEAN MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushSrc
178* 178*
179* Returns - TRUE(If address matches) else FAIL. 179* Returns - TRUE(If address matches) else FAIL.
180***************************************************************************/ 180***************************************************************************/
181BOOLEAN MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushDestPort) 181bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,USHORT ushDestPort)
182{ 182{
183 UCHAR ucLoopIndex=0; 183 UCHAR ucLoopIndex=0;
184 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 184 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
@@ -208,12 +208,12 @@ static USHORT IpVersion4(struct bcm_mini_adapter *Adapter,
208 struct iphdr *iphd, 208 struct iphdr *iphd,
209 struct bcm_classifier_rule *pstClassifierRule) 209 struct bcm_classifier_rule *pstClassifierRule)
210{ 210{
211 xporthdr *xprt_hdr=NULL; 211 struct bcm_transport_header *xprt_hdr = NULL;
212 BOOLEAN bClassificationSucceed=FALSE; 212 BOOLEAN bClassificationSucceed=FALSE;
213 213
214 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "========>"); 214 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "========>");
215 215
216 xprt_hdr=(xporthdr *)((PUCHAR)iphd + sizeof(struct iphdr)); 216 xprt_hdr=(struct bcm_transport_header *)((PUCHAR)iphd + sizeof(struct iphdr));
217 217
218 do { 218 do {
219 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Trying to see Direction = %d %d", 219 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "Trying to see Direction = %d %d",
@@ -446,7 +446,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb)
446{ 446{
447 INT uiLoopIndex=0; 447 INT uiLoopIndex=0;
448 struct bcm_classifier_rule *pstClassifierRule = NULL; 448 struct bcm_classifier_rule *pstClassifierRule = NULL;
449 S_ETHCS_PKT_INFO stEthCsPktInfo; 449 struct bcm_eth_packet_info stEthCsPktInfo;
450 PVOID pvEThPayload = NULL; 450 PVOID pvEThPayload = NULL;
451 struct iphdr *pIpHeader = NULL; 451 struct iphdr *pIpHeader = NULL;
452 INT uiSfIndex=0; 452 INT uiSfIndex=0;
@@ -454,7 +454,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb)
454 BOOLEAN bFragmentedPkt=FALSE,bClassificationSucceed=FALSE; 454 BOOLEAN bFragmentedPkt=FALSE,bClassificationSucceed=FALSE;
455 USHORT usCurrFragment =0; 455 USHORT usCurrFragment =0;
456 456
457 PTCP_HEADER pTcpHeader; 457 struct bcm_tcp_header *pTcpHeader;
458 UCHAR IpHeaderLength; 458 UCHAR IpHeaderLength;
459 UCHAR TcpHeaderLength; 459 UCHAR TcpHeaderLength;
460 460
@@ -467,32 +467,32 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb)
467 case eEth802LLCFrame: 467 case eEth802LLCFrame:
468 { 468 {
469 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLCFrame\n"); 469 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLCFrame\n");
470 pIpHeader = pvEThPayload + sizeof(ETH_CS_802_LLC_FRAME); 470 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_llc_frame);
471 break; 471 break;
472 } 472 }
473 473
474 case eEth802LLCSNAPFrame: 474 case eEth802LLCSNAPFrame:
475 { 475 {
476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLC SNAP Frame\n"); 476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802LLC SNAP Frame\n");
477 pIpHeader = pvEThPayload + sizeof(ETH_CS_802_LLC_SNAP_FRAME); 477 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_llc_snap_frame);
478 break; 478 break;
479 } 479 }
480 case eEth802QVLANFrame: 480 case eEth802QVLANFrame:
481 { 481 {
482 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802.1Q VLANFrame\n"); 482 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : 802.1Q VLANFrame\n");
483 pIpHeader = pvEThPayload + sizeof(ETH_CS_802_Q_FRAME); 483 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_q_frame);
484 break; 484 break;
485 } 485 }
486 case eEthOtherFrame: 486 case eEthOtherFrame:
487 { 487 {
488 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : ETH Other Frame\n"); 488 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : ETH Other Frame\n");
489 pIpHeader = pvEThPayload + sizeof(ETH_CS_ETH2_FRAME); 489 pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame);
490 break; 490 break;
491 } 491 }
492 default: 492 default:
493 { 493 {
494 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : Unrecognized ETH Frame\n"); 494 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "ClassifyPacket : Unrecognized ETH Frame\n");
495 pIpHeader = pvEThPayload + sizeof(ETH_CS_ETH2_FRAME); 495 pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame);
496 break; 496 break;
497 } 497 }
498 } 498 }
@@ -614,7 +614,7 @@ USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter,struct sk_buff* skb)
614 if((TCP == pIpHeader->protocol ) && !bFragmentedPkt && (ETH_AND_IP_HEADER_LEN + TCP_HEADER_LEN <= skb->len) ) 614 if((TCP == pIpHeader->protocol ) && !bFragmentedPkt && (ETH_AND_IP_HEADER_LEN + TCP_HEADER_LEN <= skb->len) )
615 { 615 {
616 IpHeaderLength = pIpHeader->ihl; 616 IpHeaderLength = pIpHeader->ihl;
617 pTcpHeader = (PTCP_HEADER)(((PUCHAR)pIpHeader)+(IpHeaderLength*4)); 617 pTcpHeader = (struct bcm_tcp_header *)(((PUCHAR)pIpHeader)+(IpHeaderLength*4));
618 TcpHeaderLength = GET_TCP_HEADER_LEN(pTcpHeader->HeaderLength); 618 TcpHeaderLength = GET_TCP_HEADER_LEN(pTcpHeader->HeaderLength);
619 619
620 if((pTcpHeader->ucFlags & TCP_ACK) && 620 if((pTcpHeader->ucFlags & TCP_ACK) &&
@@ -683,7 +683,7 @@ static BOOLEAN EthCSMatchDestMACAddress(struct bcm_classifier_rule *pstClassifie
683 return TRUE; 683 return TRUE;
684} 684}
685 685
686static BOOLEAN EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo) 686static BOOLEAN EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo)
687{ 687{
688 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev); 688 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
689 if((pstClassifierRule->ucEtherTypeLen==0)|| 689 if((pstClassifierRule->ucEtherTypeLen==0)||
@@ -718,7 +718,7 @@ static BOOLEAN EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRul
718 718
719} 719}
720 720
721static BOOLEAN EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb,PS_ETHCS_PKT_INFO pstEthCsPktInfo) 721static BOOLEAN EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule,struct sk_buff* skb, struct bcm_eth_packet_info *pstEthCsPktInfo)
722{ 722{
723 BOOLEAN bClassificationSucceed = FALSE; 723 BOOLEAN bClassificationSucceed = FALSE;
724 USHORT usVLANID; 724 USHORT usVLANID;
@@ -769,7 +769,7 @@ static BOOLEAN EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule
769 769
770 770
771static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* skb, 771static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff* skb,
772 PS_ETHCS_PKT_INFO pstEthCsPktInfo, 772 struct bcm_eth_packet_info *pstEthCsPktInfo,
773 struct bcm_classifier_rule *pstClassifierRule, 773 struct bcm_classifier_rule *pstClassifierRule,
774 B_UINT8 EthCSCupport) 774 B_UINT8 EthCSCupport)
775{ 775{
@@ -802,7 +802,7 @@ static BOOLEAN EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,struct sk_buff*
802} 802}
803 803
804static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload, 804static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload,
805 PS_ETHCS_PKT_INFO pstEthCsPktInfo) 805 struct bcm_eth_packet_info *pstEthCsPktInfo)
806{ 806{
807 USHORT u16Etype = ntohs(((struct bcm_eth_header *)pvEthPayload)->u16Etype); 807 USHORT u16Etype = ntohs(((struct bcm_eth_header *)pvEthPayload)->u16Etype);
808 808
@@ -815,7 +815,7 @@ static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload,
815 { 815 {
816 //802.1Q VLAN Header 816 //802.1Q VLAN Header
817 pstEthCsPktInfo->eNwpktEthFrameType = eEth802QVLANFrame; 817 pstEthCsPktInfo->eNwpktEthFrameType = eEth802QVLANFrame;
818 u16Etype = ((ETH_CS_802_Q_FRAME*)pvEthPayload)->EthType; 818 u16Etype = ((struct bcm_eth_q_frame *)pvEthPayload)->EthType;
819 //((ETH_CS_802_Q_FRAME*)pvEthPayload)->UserPriority 819 //((ETH_CS_802_Q_FRAME*)pvEthPayload)->UserPriority
820 } 820 }
821 else 821 else
@@ -830,12 +830,12 @@ static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,PVOID pvEthPayload,
830 //802.2 LLC 830 //802.2 LLC
831 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "802.2 LLC Frame \n"); 831 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL, "802.2 LLC Frame \n");
832 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCFrame; 832 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCFrame;
833 pstEthCsPktInfo->ucDSAP = ((ETH_CS_802_LLC_FRAME*)pvEthPayload)->DSAP; 833 pstEthCsPktInfo->ucDSAP = ((struct bcm_eth_llc_frame *)pvEthPayload)->DSAP;
834 if(pstEthCsPktInfo->ucDSAP == 0xAA && ((ETH_CS_802_LLC_FRAME*)pvEthPayload)->SSAP == 0xAA) 834 if(pstEthCsPktInfo->ucDSAP == 0xAA && ((struct bcm_eth_llc_frame *)pvEthPayload)->SSAP == 0xAA)
835 { 835 {
836 //SNAP Frame 836 //SNAP Frame
837 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCSNAPFrame; 837 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCSNAPFrame;
838 u16Etype = ((ETH_CS_802_LLC_SNAP_FRAME*)pvEthPayload)->usEtherType; 838 u16Etype = ((struct bcm_eth_llc_snap_frame *)pvEthPayload)->usEtherType;
839 } 839 }
840 } 840 }
841 if(u16Etype == ETHERNET_FRAMETYPE_IPV4) 841 if(u16Etype == ETHERNET_FRAMETYPE_IPV4)
diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c
index 3c5f4a5f0376..f55300db1d48 100644
--- a/drivers/staging/bcm/hostmibs.c
+++ b/drivers/staging/bcm/hostmibs.c
@@ -11,11 +11,11 @@
11 11
12INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_mibs *pstHostMibs) 12INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_mibs *pstHostMibs)
13{ 13{
14 S_SERVICEFLOW_ENTRY *pstServiceFlowEntry = NULL; 14 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
15 S_PHS_RULE *pstPhsRule = NULL; 15 struct bcm_phs_rule *pstPhsRule = NULL;
16 S_CLASSIFIER_TABLE *pstClassifierTable = NULL; 16 struct bcm_phs_classifier_table *pstClassifierTable = NULL;
17 S_CLASSIFIER_ENTRY *pstClassifierRule = NULL; 17 struct bcm_phs_classifier_entry *pstClassifierRule = NULL;
18 PPHS_DEVICE_EXTENSION pDeviceExtension = (PPHS_DEVICE_EXTENSION) &Adapter->stBCMPhsContext; 18 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *) &Adapter->stBCMPhsContext;
19 19
20 UINT nClassifierIndex = 0, nPhsTableIndex = 0, nSfIndex = 0, uiIndex = 0; 20 UINT nClassifierIndex = 0, nPhsTableIndex = 0, nSfIndex = 0, uiIndex = 0;
21 21
@@ -70,7 +70,7 @@ INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_m
70 70
71 memcpy(&pstHostMibs-> 71 memcpy(&pstHostMibs->
72 astPhsRulesTable[nPhsTableIndex].u8PHSI, 72 astPhsRulesTable[nPhsTableIndex].u8PHSI,
73 &pstPhsRule->u8PHSI, sizeof(S_PHS_RULE)); 73 &pstPhsRule->u8PHSI, sizeof(struct bcm_phs_rule));
74 nPhsTableIndex++; 74 nPhsTableIndex++;
75 75
76 } 76 }
diff --git a/drivers/staging/bcm/led_control.c b/drivers/staging/bcm/led_control.c
index 252a1b31d618..05a948a3698c 100644
--- a/drivers/staging/bcm/led_control.c
+++ b/drivers/staging/bcm/led_control.c
@@ -24,7 +24,7 @@ BOOLEAN IsReqGpioIsLedInNVM(struct bcm_mini_adapter *Adapter, UINT gpios)
24} 24}
25 25
26static INT LED_Blink(struct bcm_mini_adapter *Adapter, UINT GPIO_Num, UCHAR uiLedIndex, 26static INT LED_Blink(struct bcm_mini_adapter *Adapter, UINT GPIO_Num, UCHAR uiLedIndex,
27 ULONG timeout, INT num_of_time, LedEventInfo_t currdriverstate) 27 ULONG timeout, INT num_of_time, enum bcm_led_events currdriverstate)
28{ 28{
29 int Status = STATUS_SUCCESS; 29 int Status = STATUS_SUCCESS;
30 BOOLEAN bInfinite = FALSE; 30 BOOLEAN bInfinite = FALSE;
@@ -97,7 +97,7 @@ static INT ScaleRateofTransfer(ULONG rate)
97 97
98static INT LED_Proportional_Blink(struct bcm_mini_adapter *Adapter, UCHAR GPIO_Num_tx, 98static INT LED_Proportional_Blink(struct bcm_mini_adapter *Adapter, UCHAR GPIO_Num_tx,
99 UCHAR uiTxLedIndex, UCHAR GPIO_Num_rx, UCHAR uiRxLedIndex, 99 UCHAR uiTxLedIndex, UCHAR GPIO_Num_rx, UCHAR uiRxLedIndex,
100 LedEventInfo_t currdriverstate) 100 enum bcm_led_events currdriverstate)
101{ 101{
102 /* Initial values of TX and RX packets */ 102 /* Initial values of TX and RX packets */
103 ULONG64 Initial_num_of_packts_tx = 0, Initial_num_of_packts_rx = 0; 103 ULONG64 Initial_num_of_packts_tx = 0, Initial_num_of_packts_rx = 0;
@@ -607,7 +607,7 @@ static VOID LedGpioInit(struct bcm_mini_adapter *Adapter)
607 607
608static INT BcmGetGPIOPinInfo(struct bcm_mini_adapter *Adapter, UCHAR *GPIO_num_tx, 608static INT BcmGetGPIOPinInfo(struct bcm_mini_adapter *Adapter, UCHAR *GPIO_num_tx,
609 UCHAR *GPIO_num_rx, UCHAR *uiLedTxIndex, UCHAR *uiLedRxIndex, 609 UCHAR *GPIO_num_rx, UCHAR *uiLedTxIndex, UCHAR *uiLedRxIndex,
610 LedEventInfo_t currdriverstate) 610 enum bcm_led_events currdriverstate)
611{ 611{
612 UINT uiIndex = 0; 612 UINT uiIndex = 0;
613 613
@@ -651,7 +651,7 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
651 UCHAR GPIO_num = 0; 651 UCHAR GPIO_num = 0;
652 UCHAR uiLedIndex = 0; 652 UCHAR uiLedIndex = 0;
653 UINT uiResetValue = 0; 653 UINT uiResetValue = 0;
654 LedEventInfo_t currdriverstate = 0; 654 enum bcm_led_events currdriverstate = 0;
655 ulong timeout = 0; 655 ulong timeout = 0;
656 656
657 INT Status = 0; 657 INT Status = 0;
diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h
index ed8fbc091115..bae40e22e11b 100644
--- a/drivers/staging/bcm/led_control.h
+++ b/drivers/staging/bcm/led_control.h
@@ -1,102 +1,84 @@
1#ifndef _LED_CONTROL_H 1#ifndef _LED_CONTROL_H
2#define _LED_CONTROL_H 2#define _LED_CONTROL_H
3 3
4/*************************TYPE DEF**********************/ 4#define NUM_OF_LEDS 4
5#define NUM_OF_LEDS 4
6
7#define DSD_START_OFFSET 0x0200 5#define DSD_START_OFFSET 0x0200
8#define EEPROM_VERSION_OFFSET 0x020E 6#define EEPROM_VERSION_OFFSET 0x020E
9#define EEPROM_HW_PARAM_POINTER_ADDRESS 0x0218 7#define EEPROM_HW_PARAM_POINTER_ADDRESS 0x0218
10#define EEPROM_HW_PARAM_POINTER_ADDRRES_MAP5 0x0220 8#define EEPROM_HW_PARAM_POINTER_ADDRRES_MAP5 0x0220
11#define GPIO_SECTION_START_OFFSET 0x03 9#define GPIO_SECTION_START_OFFSET 0x03
12 10#define COMPATIBILITY_SECTION_LENGTH 42
13#define COMPATIBILITY_SECTION_LENGTH 42 11#define COMPATIBILITY_SECTION_LENGTH_MAP5 84
14#define COMPATIBILITY_SECTION_LENGTH_MAP5 84 12#define EEPROM_MAP5_MAJORVERSION 5
15 13#define EEPROM_MAP5_MINORVERSION 0
16
17#define EEPROM_MAP5_MAJORVERSION 5
18#define EEPROM_MAP5_MINORVERSION 0
19
20
21#define MAX_NUM_OF_BLINKS 10 14#define MAX_NUM_OF_BLINKS 10
22#define NUM_OF_GPIO_PINS 16 15#define NUM_OF_GPIO_PINS 16
23
24#define DISABLE_GPIO_NUM 0xFF 16#define DISABLE_GPIO_NUM 0xFF
25#define EVENT_SIGNALED 1 17#define EVENT_SIGNALED 1
26
27#define MAX_FILE_NAME_BUFFER_SIZE 100 18#define MAX_FILE_NAME_BUFFER_SIZE 100
28 19
29#define TURN_ON_LED(GPIO, index) do { \ 20#define TURN_ON_LED(GPIO, index) do { \
30 UINT gpio_val = GPIO; \ 21 unsigned int gpio_val = GPIO; \
31 (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ 22 (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \
32 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)) : \ 23 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)) : \
33 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)); \ 24 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)); \
34 } while (0); 25 } while (0)
35 26
36#define TURN_OFF_LED(GPIO, index) do { \ 27#define TURN_OFF_LED(GPIO, index) do { \
37 UINT gpio_val = GPIO; \ 28 unsigned int gpio_val = GPIO; \
38 (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \ 29 (Adapter->LEDInfo.LEDState[index].BitPolarity == 1) ? \
39 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)) : \ 30 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)) : \
40 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \ 31 wrmaltWithLock(Adapter, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \
41 } while (0); 32 } while (0)
42 33
43#define B_ULONG32 unsigned long 34enum bcm_led_colors {
44 35 RED_LED = 1,
45/*******************************************************/ 36 BLUE_LED = 2,
46 37 YELLOW_LED = 3,
47 38 GREEN_LED = 4
48typedef enum _LEDColors{ 39};
49 RED_LED = 1, 40
50 BLUE_LED = 2, 41enum bcm_led_events {
51 YELLOW_LED = 3, 42 SHUTDOWN_EXIT = 0x00,
52 GREEN_LED = 4 43 DRIVER_INIT = 0x1,
53} LEDColors; /*Enumerated values of different LED types*/ 44 FW_DOWNLOAD = 0x2,
54 45 FW_DOWNLOAD_DONE = 0x4,
55typedef enum LedEvents { 46 NO_NETWORK_ENTRY = 0x8,
56 SHUTDOWN_EXIT = 0x00, 47 NORMAL_OPERATION = 0x10,
57 DRIVER_INIT = 0x1, 48 LOWPOWER_MODE_ENTER = 0x20,
58 FW_DOWNLOAD = 0x2, 49 IDLEMODE_CONTINUE = 0x40,
59 FW_DOWNLOAD_DONE = 0x4, 50 IDLEMODE_EXIT = 0x80,
60 NO_NETWORK_ENTRY = 0x8, 51 LED_THREAD_INACTIVE = 0x100, /* Makes the LED thread Inactivce. It wil be equivallent to putting the thread on hold. */
61 NORMAL_OPERATION = 0x10, 52 LED_THREAD_ACTIVE = 0x200, /* Makes the LED Thread Active back. */
62 LOWPOWER_MODE_ENTER = 0x20, 53 DRIVER_HALT = 0xff
63 IDLEMODE_CONTINUE = 0x40, 54}; /* Enumerated values of different driver states */
64 IDLEMODE_EXIT = 0x80,
65 LED_THREAD_INACTIVE = 0x100, /* Makes the LED thread Inactivce. It wil be equivallent to putting the thread on hold. */
66 LED_THREAD_ACTIVE = 0x200, /* Makes the LED Thread Active back. */
67 DRIVER_HALT = 0xff
68} LedEventInfo_t; /* Enumerated values of different driver states */
69 55
70/* 56/*
71 * Structure which stores the information of different LED types 57 * Structure which stores the information of different LED types
72 * and corresponding LED state information of driver states 58 * and corresponding LED state information of driver states
73 */ 59 */
74typedef struct LedStateInfo_t { 60struct bcm_led_state_info {
75 UCHAR LED_Type; /* specify GPIO number - use 0xFF if not used */ 61 unsigned char LED_Type; /* specify GPIO number - use 0xFF if not used */
76 UCHAR LED_On_State; /* Bits set or reset for different states */ 62 unsigned char LED_On_State; /* Bits set or reset for different states */
77 UCHAR LED_Blink_State; /* Bits set or reset for blinking LEDs for different states */ 63 unsigned char LED_Blink_State; /* Bits set or reset for blinking LEDs for different states */
78 UCHAR GPIO_Num; 64 unsigned char GPIO_Num;
79 UCHAR BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */ 65 unsigned char BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */
80} LEDStateInfo, *pLEDStateInfo; 66};
81 67
82 68struct bcm_led_info {
83typedef struct _LED_INFO_STRUCT { 69 struct bcm_led_state_info LEDState[NUM_OF_LEDS];
84 LEDStateInfo LEDState[NUM_OF_LEDS]; 70 bool bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target */
85 BOOLEAN bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target*/ 71 bool bIdle_led_off;
86 BOOLEAN bIdle_led_off; 72 wait_queue_head_t notify_led_event;
87 wait_queue_head_t notify_led_event;
88 wait_queue_head_t idleModeSyncEvent; 73 wait_queue_head_t idleModeSyncEvent;
89 struct task_struct *led_cntrl_threadid; 74 struct task_struct *led_cntrl_threadid;
90 int led_thread_running; 75 int led_thread_running;
91 BOOLEAN bLedInitDone; 76 bool bLedInitDone;
77};
92 78
93} LED_INFO_STRUCT, *PLED_INFO_STRUCT;
94/* LED Thread state. */ 79/* LED Thread state. */
95#define BCM_LED_THREAD_DISABLED 0 /* LED Thread is not running. */ 80#define BCM_LED_THREAD_DISABLED 0 /* LED Thread is not running. */
96#define BCM_LED_THREAD_RUNNING_ACTIVELY 1 /* LED thread is running. */ 81#define BCM_LED_THREAD_RUNNING_ACTIVELY 1 /* LED thread is running. */
97#define BCM_LED_THREAD_RUNNING_INACTIVELY 2 /*LED thread has been put on hold*/ 82#define BCM_LED_THREAD_RUNNING_INACTIVELY 2 /* LED thread has been put on hold */
98
99
100 83
101#endif 84#endif
102
diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c
index eab676fe53a6..e6152f4df14b 100644
--- a/drivers/staging/bcm/nvm.c
+++ b/drivers/staging/bcm/nvm.c
@@ -12,7 +12,7 @@ static unsigned int BcmGetFlashSectorSize(struct bcm_mini_adapter *Adapter, unsi
12static VOID BcmValidateNvmType(struct bcm_mini_adapter *Adapter); 12static VOID BcmValidateNvmType(struct bcm_mini_adapter *Adapter);
13static int BcmGetNvmSize(struct bcm_mini_adapter *Adapter); 13static int BcmGetNvmSize(struct bcm_mini_adapter *Adapter);
14static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter); 14static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter);
15static NVM_TYPE BcmGetNvmType(struct bcm_mini_adapter *Adapter); 15static enum bcm_nvm_type BcmGetNvmType(struct bcm_mini_adapter *Adapter);
16 16
17static int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal); 17static int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal);
18 18
@@ -472,7 +472,7 @@ static int BeceemFlashBulkRead(struct bcm_mini_adapter *Adapter,
472static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter) 472static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter)
473{ 473{
474 if (IsFlash2x(Adapter)) 474 if (IsFlash2x(Adapter))
475 return Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER); 475 return Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header);
476 else 476 else
477 return 32 * 1024; 477 return 32 * 1024;
478} 478}
@@ -1978,7 +1978,7 @@ int BeceemNVMWrite(struct bcm_mini_adapter *Adapter,
1978int BcmUpdateSectorSize(struct bcm_mini_adapter *Adapter, unsigned int uiSectorSize) 1978int BcmUpdateSectorSize(struct bcm_mini_adapter *Adapter, unsigned int uiSectorSize)
1979{ 1979{
1980 int Status = -1; 1980 int Status = -1;
1981 FLASH_CS_INFO sFlashCsInfo = {0}; 1981 struct bcm_flash_cs_info sFlashCsInfo = {0};
1982 unsigned int uiTemp = 0; 1982 unsigned int uiTemp = 0;
1983 unsigned int uiSectorSig = 0; 1983 unsigned int uiSectorSig = 0;
1984 unsigned int uiCurrentSectorSize = 0; 1984 unsigned int uiCurrentSectorSize = 0;
@@ -2228,20 +2228,20 @@ int BcmAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter)
2228 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL"); 2228 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL");
2229 return -EINVAL; 2229 return -EINVAL;
2230 } 2230 }
2231 psAdapter->psFlashCSInfo = (PFLASH_CS_INFO)kzalloc(sizeof(FLASH_CS_INFO), GFP_KERNEL); 2231 psAdapter->psFlashCSInfo = (struct bcm_flash_cs_info *)kzalloc(sizeof(struct bcm_flash_cs_info), GFP_KERNEL);
2232 if (psAdapter->psFlashCSInfo == NULL) { 2232 if (psAdapter->psFlashCSInfo == NULL) {
2233 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 1.x"); 2233 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 1.x");
2234 return -ENOMEM; 2234 return -ENOMEM;
2235 } 2235 }
2236 2236
2237 psAdapter->psFlash2xCSInfo = (PFLASH2X_CS_INFO)kzalloc(sizeof(FLASH2X_CS_INFO), GFP_KERNEL); 2237 psAdapter->psFlash2xCSInfo = (struct bcm_flash2x_cs_info *)kzalloc(sizeof(struct bcm_flash2x_cs_info), GFP_KERNEL);
2238 if (!psAdapter->psFlash2xCSInfo) { 2238 if (!psAdapter->psFlash2xCSInfo) {
2239 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 2.x"); 2239 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 2.x");
2240 kfree(psAdapter->psFlashCSInfo); 2240 kfree(psAdapter->psFlashCSInfo);
2241 return -ENOMEM; 2241 return -ENOMEM;
2242 } 2242 }
2243 2243
2244 psAdapter->psFlash2xVendorInfo = (PFLASH2X_VENDORSPECIFIC_INFO)kzalloc(sizeof(FLASH2X_VENDORSPECIFIC_INFO), GFP_KERNEL); 2244 psAdapter->psFlash2xVendorInfo = (struct bcm_flash2x_vendor_info *)kzalloc(sizeof(struct bcm_flash2x_vendor_info), GFP_KERNEL);
2245 if (!psAdapter->psFlash2xVendorInfo) { 2245 if (!psAdapter->psFlash2xVendorInfo) {
2246 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate Vendor Info Memory for Flash 2.x"); 2246 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate Vendor Info Memory for Flash 2.x");
2247 kfree(psAdapter->psFlashCSInfo); 2247 kfree(psAdapter->psFlashCSInfo);
@@ -2264,7 +2264,7 @@ int BcmDeAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter)
2264 return STATUS_SUCCESS; 2264 return STATUS_SUCCESS;
2265} 2265}
2266 2266
2267static int BcmDumpFlash2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo, struct bcm_mini_adapter *Adapter) 2267static int BcmDumpFlash2XCSStructure(struct bcm_flash2x_cs_info *psFlash2xCSInfo, struct bcm_mini_adapter *Adapter)
2268{ 2268{
2269 unsigned int Index = 0; 2269 unsigned int Index = 0;
2270 2270
@@ -2324,7 +2324,7 @@ static int BcmDumpFlash2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo, struct bc
2324 return STATUS_SUCCESS; 2324 return STATUS_SUCCESS;
2325} 2325}
2326 2326
2327static int ConvertEndianOf2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo) 2327static int ConvertEndianOf2XCSStructure(struct bcm_flash2x_cs_info *psFlash2xCSInfo)
2328{ 2328{
2329 unsigned int Index = 0; 2329 unsigned int Index = 0;
2330 2330
@@ -2381,7 +2381,7 @@ static int ConvertEndianOf2XCSStructure(PFLASH2X_CS_INFO psFlash2xCSInfo)
2381 return STATUS_SUCCESS; 2381 return STATUS_SUCCESS;
2382} 2382}
2383 2383
2384static int ConvertEndianOfCSStructure(PFLASH_CS_INFO psFlashCSInfo) 2384static int ConvertEndianOfCSStructure(struct bcm_flash_cs_info *psFlashCSInfo)
2385{ 2385{
2386 /* unsigned int Index = 0; */ 2386 /* unsigned int Index = 0; */
2387 psFlashCSInfo->MagicNumber = ntohl(psFlashCSInfo->MagicNumber); 2387 psFlashCSInfo->MagicNumber = ntohl(psFlashCSInfo->MagicNumber);
@@ -2446,7 +2446,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter)
2446 2446
2447 switch (i) { 2447 switch (i) {
2448 case DSD0: 2448 case DSD0:
2449 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) && 2449 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) &&
2450 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)) 2450 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2451 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = VENDOR_PTR_IN_CS; 2451 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = VENDOR_PTR_IN_CS;
2452 else 2452 else
@@ -2454,7 +2454,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter)
2454 break; 2454 break;
2455 2455
2456 case DSD1: 2456 case DSD1:
2457 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) && 2457 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) &&
2458 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)) 2458 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2459 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = VENDOR_PTR_IN_CS; 2459 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = VENDOR_PTR_IN_CS;
2460 else 2460 else
@@ -2462,7 +2462,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter)
2462 break; 2462 break;
2463 2463
2464 case DSD2: 2464 case DSD2:
2465 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER))) && 2465 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) &&
2466 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)) 2466 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2467 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = VENDOR_PTR_IN_CS; 2467 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = VENDOR_PTR_IN_CS;
2468 else 2468 else
@@ -2509,7 +2509,7 @@ static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter)
2509 2509
2510static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter) 2510static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter)
2511{ 2511{
2512 /* FLASH_CS_INFO sFlashCsInfo = {0}; */ 2512 /* struct bcm_flash_cs_info sFlashCsInfo = {0}; */
2513 2513
2514 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS) 2514 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2515 unsigned int value; 2515 unsigned int value;
@@ -2522,8 +2522,8 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter)
2522 2522
2523 Adapter->uiFlashBaseAdd = 0; 2523 Adapter->uiFlashBaseAdd = 0;
2524 Adapter->ulFlashCalStart = 0; 2524 Adapter->ulFlashCalStart = 0;
2525 memset(Adapter->psFlashCSInfo, 0 , sizeof(FLASH_CS_INFO)); 2525 memset(Adapter->psFlashCSInfo, 0 , sizeof(struct bcm_flash_cs_info));
2526 memset(Adapter->psFlash2xCSInfo, 0 , sizeof(FLASH2X_CS_INFO)); 2526 memset(Adapter->psFlash2xCSInfo, 0 , sizeof(struct bcm_flash2x_cs_info));
2527 2527
2528 if (!Adapter->bDDRInitDone) { 2528 if (!Adapter->bDDRInitDone) {
2529 value = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT; 2529 value = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
@@ -2551,7 +2551,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter)
2551 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FLASH LAYOUT MAJOR VERSION :%X", uiFlashLayoutMajorVersion); 2551 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FLASH LAYOUT MAJOR VERSION :%X", uiFlashLayoutMajorVersion);
2552 2552
2553 if (uiFlashLayoutMajorVersion < FLASH_2X_MAJOR_NUMBER) { 2553 if (uiFlashLayoutMajorVersion < FLASH_2X_MAJOR_NUMBER) {
2554 BeceemFlashBulkRead(Adapter, (PUINT)Adapter->psFlashCSInfo, Adapter->ulFlashControlSectionStart, sizeof(FLASH_CS_INFO)); 2554 BeceemFlashBulkRead(Adapter, (PUINT)Adapter->psFlashCSInfo, Adapter->ulFlashControlSectionStart, sizeof(struct bcm_flash_cs_info));
2555 ConvertEndianOfCSStructure(Adapter->psFlashCSInfo); 2555 ConvertEndianOfCSStructure(Adapter->psFlashCSInfo);
2556 Adapter->ulFlashCalStart = (Adapter->psFlashCSInfo->OffsetFromZeroForCalibrationStart); 2556 Adapter->ulFlashCalStart = (Adapter->psFlashCSInfo->OffsetFromZeroForCalibrationStart);
2557 2557
@@ -2576,7 +2576,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter)
2576 Adapter->uiFlashBaseAdd = Adapter->psFlashCSInfo->FlashBaseAddr & 0xFCFFFFFF; 2576 Adapter->uiFlashBaseAdd = Adapter->psFlashCSInfo->FlashBaseAddr & 0xFCFFFFFF;
2577 } else { 2577 } else {
2578 if (BcmFlash2xBulkRead(Adapter, (PUINT)Adapter->psFlash2xCSInfo, NO_SECTION_VAL, 2578 if (BcmFlash2xBulkRead(Adapter, (PUINT)Adapter->psFlash2xCSInfo, NO_SECTION_VAL,
2579 Adapter->ulFlashControlSectionStart, sizeof(FLASH2X_CS_INFO))) { 2579 Adapter->ulFlashControlSectionStart, sizeof(struct bcm_flash2x_cs_info))) {
2580 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to read CS structure\n"); 2580 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to read CS structure\n");
2581 return STATUS_FAILURE; 2581 return STATUS_FAILURE;
2582 } 2582 }
@@ -2629,7 +2629,7 @@ static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter)
2629 * 2629 *
2630 */ 2630 */
2631 2631
2632static NVM_TYPE BcmGetNvmType(struct bcm_mini_adapter *Adapter) 2632static enum bcm_nvm_type BcmGetNvmType(struct bcm_mini_adapter *Adapter)
2633{ 2633{
2634 unsigned int uiData = 0; 2634 unsigned int uiData = 0;
2635 2635
@@ -2810,6 +2810,7 @@ int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x
2810 case CONTROL_SECTION: 2810 case CONTROL_SECTION:
2811 /* Not Clear So Putting failure. confirm and fix it. */ 2811 /* Not Clear So Putting failure. confirm and fix it. */
2812 SectEndOffset = STATUS_FAILURE; 2812 SectEndOffset = STATUS_FAILURE;
2813 break;
2813 case ISO_IMAGE1_PART2: 2814 case ISO_IMAGE1_PART2:
2814 if (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End != UNINIT_PTR_IN_CS) 2815 if (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End != UNINIT_PTR_IN_CS)
2815 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End); 2816 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End);
@@ -3101,7 +3102,7 @@ static int BcmDumpFlash2xSectionBitMap(struct bcm_flash2x_bitmap *psFlash2xBitMa
3101 3102
3102int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_bitmap *psFlash2xBitMap) 3103int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_bitmap *psFlash2xBitMap)
3103{ 3104{
3104 PFLASH2X_CS_INFO psFlash2xCSInfo = Adapter->psFlash2xCSInfo; 3105 struct bcm_flash2x_cs_info *psFlash2xCSInfo = Adapter->psFlash2xCSInfo;
3105 enum bcm_flash2x_section_val uiHighestPriDSD = 0; 3106 enum bcm_flash2x_section_val uiHighestPriDSD = 0;
3106 enum bcm_flash2x_section_val uiHighestPriISO = 0; 3107 enum bcm_flash2x_section_val uiHighestPriISO = 0;
3107 BOOLEAN SetActiveDSDDone = FALSE; 3108 BOOLEAN SetActiveDSDDone = FALSE;
@@ -3354,8 +3355,8 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti
3354 unsigned int SectImagePriority = 0; 3355 unsigned int SectImagePriority = 0;
3355 int Status = STATUS_SUCCESS; 3356 int Status = STATUS_SUCCESS;
3356 3357
3357 /* DSD_HEADER sDSD = {0}; 3358 /* struct bcm_dsd_header sDSD = {0};
3358 * ISO_HEADER sISO = {0}; 3359 * struct bcm_iso_header sISO = {0};
3359 */ 3360 */
3360 int HighestPriDSD = 0 ; 3361 int HighestPriDSD = 0 ;
3361 int HighestPriISO = 0; 3362 int HighestPriISO = 0;
@@ -3391,7 +3392,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti
3391 Status = BcmFlash2xBulkWrite(Adapter, 3392 Status = BcmFlash2xBulkWrite(Adapter,
3392 &SectImagePriority, 3393 &SectImagePriority,
3393 HighestPriISO, 3394 HighestPriISO,
3394 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority), 3395 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority),
3395 SIGNATURE_SIZE, 3396 SIGNATURE_SIZE,
3396 TRUE); 3397 TRUE);
3397 if (Status) { 3398 if (Status) {
@@ -3416,7 +3417,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti
3416 Status = BcmFlash2xBulkWrite(Adapter, 3417 Status = BcmFlash2xBulkWrite(Adapter,
3417 &SectImagePriority, 3418 &SectImagePriority,
3418 eFlash2xSectVal, 3419 eFlash2xSectVal,
3419 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority), 3420 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority),
3420 SIGNATURE_SIZE, 3421 SIGNATURE_SIZE,
3421 TRUE); 3422 TRUE);
3422 if (Status) { 3423 if (Status) {
@@ -3452,7 +3453,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti
3452 Status = BcmFlash2xBulkWrite(Adapter, 3453 Status = BcmFlash2xBulkWrite(Adapter,
3453 &SectImagePriority, 3454 &SectImagePriority,
3454 HighestPriDSD, 3455 HighestPriDSD,
3455 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), 3456 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
3456 SIGNATURE_SIZE, 3457 SIGNATURE_SIZE,
3457 TRUE); 3458 TRUE);
3458 if (Status) { 3459 if (Status) {
@@ -3472,7 +3473,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti
3472 Status = BcmFlash2xBulkWrite(Adapter, 3473 Status = BcmFlash2xBulkWrite(Adapter,
3473 &SectImagePriority, 3474 &SectImagePriority,
3474 HighestPriDSD, 3475 HighestPriDSD,
3475 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), 3476 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
3476 SIGNATURE_SIZE, 3477 SIGNATURE_SIZE,
3477 TRUE); 3478 TRUE);
3478 if (Status) { 3479 if (Status) {
@@ -3492,7 +3493,7 @@ int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_secti
3492 Status = BcmFlash2xBulkWrite(Adapter, 3493 Status = BcmFlash2xBulkWrite(Adapter,
3493 &SectImagePriority, 3494 &SectImagePriority,
3494 eFlash2xSectVal, 3495 eFlash2xSectVal,
3495 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), 3496 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
3496 SIGNATURE_SIZE, 3497 SIGNATURE_SIZE,
3497 TRUE); 3498 TRUE);
3498 if (Status) { 3499 if (Status) {
@@ -3550,7 +3551,7 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section
3550 Status = BcmFlash2xBulkRead(Adapter, 3551 Status = BcmFlash2xBulkRead(Adapter,
3551 &ISOLength, 3552 &ISOLength,
3552 sCopySectStrut.SrcSection, 3553 sCopySectStrut.SrcSection,
3553 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageSize), 3554 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageSize),
3554 4); 3555 4);
3555 if (Status) { 3556 if (Status) {
3556 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO\n"); 3557 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO\n");
@@ -3561,7 +3562,7 @@ int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section
3561 if (ISOLength % Adapter->uiSectorSize) 3562 if (ISOLength % Adapter->uiSectorSize)
3562 ISOLength = Adapter->uiSectorSize * (1 + ISOLength/Adapter->uiSectorSize); 3563 ISOLength = Adapter->uiSectorSize * (1 + ISOLength/Adapter->uiSectorSize);
3563 3564
3564 sigOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber); 3565 sigOffset = FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber);
3565 3566
3566 Buff = kzalloc(Adapter->uiSectorSize, GFP_KERNEL); 3567 Buff = kzalloc(Adapter->uiSectorSize, GFP_KERNEL);
3567 3568
@@ -3846,7 +3847,7 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio
3846 unsigned int uiSignature = 0; 3847 unsigned int uiSignature = 0;
3847 unsigned int uiOffset = 0; 3848 unsigned int uiOffset = 0;
3848 3849
3849 /* DSD_HEADER dsdHeader = {0}; */ 3850 /* struct bcm_dsd_header dsdHeader = {0}; */
3850 if (Adapter->bSigCorrupted == FALSE) { 3851 if (Adapter->bSigCorrupted == FALSE) {
3851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is not corrupted by driver, hence not restoring\n"); 3852 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is not corrupted by driver, hence not restoring\n");
3852 return STATUS_SUCCESS; 3853 return STATUS_SUCCESS;
@@ -3863,7 +3864,7 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio
3863 uiSignature = htonl(DSD_IMAGE_MAGIC_NUMBER); 3864 uiSignature = htonl(DSD_IMAGE_MAGIC_NUMBER);
3864 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader; 3865 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader;
3865 3866
3866 uiOffset += FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber); 3867 uiOffset += FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber);
3867 3868
3868 if ((ReadDSDSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) { 3869 if ((ReadDSDSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) {
3869 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Corrupted Pattern is not there. Hence won't write sig"); 3870 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Corrupted Pattern is not there. Hence won't write sig");
@@ -3872,7 +3873,7 @@ int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sectio
3872 } else if ((eFlashSectionVal == ISO_IMAGE1) || (eFlashSectionVal == ISO_IMAGE2)) { 3873 } else if ((eFlashSectionVal == ISO_IMAGE1) || (eFlashSectionVal == ISO_IMAGE2)) {
3873 uiSignature = htonl(ISO_IMAGE_MAGIC_NUMBER); 3874 uiSignature = htonl(ISO_IMAGE_MAGIC_NUMBER);
3874 /* uiOffset = 0; */ 3875 /* uiOffset = 0; */
3875 uiOffset = FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber); 3876 uiOffset = FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber);
3876 if ((ReadISOSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) { 3877 if ((ReadISOSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) {
3877 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Currupted Pattern is not there. Hence won't write sig"); 3878 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Currupted Pattern is not there. Hence won't write sig");
3878 return STATUS_FAILURE; 3879 return STATUS_FAILURE;
@@ -4141,14 +4142,14 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned
4141 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter, DSD0) - Adapter->uiSectorSize)) { 4142 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter, DSD0) - Adapter->uiSectorSize)) {
4142 /* offset from the sector boundary having the header map */ 4143 /* offset from the sector boundary having the header map */
4143 offsetToProtect = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader % Adapter->uiSectorSize; 4144 offsetToProtect = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader % Adapter->uiSectorSize;
4144 HeaderSizeToProtect = sizeof(DSD_HEADER); 4145 HeaderSizeToProtect = sizeof(struct bcm_dsd_header);
4145 bHasHeader = TRUE; 4146 bHasHeader = TRUE;
4146 } 4147 }
4147 4148
4148 if (uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE1) || 4149 if (uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE1) ||
4149 uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE2)) { 4150 uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE2)) {
4150 offsetToProtect = 0; 4151 offsetToProtect = 0;
4151 HeaderSizeToProtect = sizeof(ISO_HEADER); 4152 HeaderSizeToProtect = sizeof(struct bcm_iso_header);
4152 bHasHeader = TRUE; 4153 bHasHeader = TRUE;
4153 } 4154 }
4154 /* If Header is present overwrite passed buffer with this */ 4155 /* If Header is present overwrite passed buffer with this */
@@ -4167,7 +4168,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned
4167 kfree(pTempBuff); 4168 kfree(pTempBuff);
4168 } 4169 }
4169 if (bHasHeader && Adapter->bSigCorrupted) { 4170 if (bHasHeader && Adapter->bSigCorrupted) {
4170 sig = *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber))); 4171 sig = *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber)));
4171 sig = ntohl(sig); 4172 sig = ntohl(sig);
4172 if ((sig & 0xFF000000) != CORRUPTED_PATTERN) { 4173 if ((sig & 0xFF000000) != CORRUPTED_PATTERN) {
4173 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Desired pattern is not at sig offset. Hence won't restore"); 4174 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Desired pattern is not at sig offset. Hence won't restore");
@@ -4175,7 +4176,7 @@ int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned
4175 return STATUS_SUCCESS; 4176 return STATUS_SUCCESS;
4176 } 4177 }
4177 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Corrupted sig is :%X", sig); 4178 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Corrupted sig is :%X", sig);
4178 *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber))) = htonl(DSD_IMAGE_MAGIC_NUMBER); 4179 *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber))) = htonl(DSD_IMAGE_MAGIC_NUMBER);
4179 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Restoring the signature in Header Write only"); 4180 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Restoring the signature in Header Write only");
4180 Adapter->bSigCorrupted = FALSE; 4181 Adapter->bSigCorrupted = FALSE;
4181 } 4182 }
@@ -4268,7 +4269,7 @@ int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_
4268{ 4269{
4269 unsigned int uiDSDsig = 0; 4270 unsigned int uiDSDsig = 0;
4270 /* unsigned int sigoffsetInMap = 0; 4271 /* unsigned int sigoffsetInMap = 0;
4271 * DSD_HEADER dsdHeader = {0}; 4272 * struct bcm_dsd_header dsdHeader = {0};
4272 */ 4273 */
4273 4274
4274 /* sigoffsetInMap =(PUCHAR)&(dsdHeader.DSDImageMagicNumber) -(PUCHAR)&dsdHeader; */ 4275 /* sigoffsetInMap =(PUCHAR)&(dsdHeader.DSDImageMagicNumber) -(PUCHAR)&dsdHeader; */
@@ -4280,7 +4281,7 @@ int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_
4280 BcmFlash2xBulkRead(Adapter, 4281 BcmFlash2xBulkRead(Adapter,
4281 &uiDSDsig, 4282 &uiDSDsig,
4282 dsd, 4283 dsd,
4283 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImageMagicNumber), 4284 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber),
4284 SIGNATURE_SIZE); 4285 SIGNATURE_SIZE);
4285 4286
4286 uiDSDsig = ntohl(uiDSDsig); 4287 uiDSDsig = ntohl(uiDSDsig);
@@ -4293,7 +4294,7 @@ int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v
4293{ 4294{
4294 /* unsigned int priOffsetInMap = 0 ; */ 4295 /* unsigned int priOffsetInMap = 0 ; */
4295 unsigned int uiDSDPri = STATUS_FAILURE; 4296 unsigned int uiDSDPri = STATUS_FAILURE;
4296 /* DSD_HEADER dsdHeader = {0}; 4297 /* struct bcm_dsd_header dsdHeader = {0};
4297 * priOffsetInMap = (PUCHAR)&(dsdHeader.DSDImagePriority) -(PUCHAR)&dsdHeader; 4298 * priOffsetInMap = (PUCHAR)&(dsdHeader.DSDImagePriority) -(PUCHAR)&dsdHeader;
4298 */ 4299 */
4299 if (IsSectionWritable(Adapter, dsd)) { 4300 if (IsSectionWritable(Adapter, dsd)) {
@@ -4301,7 +4302,7 @@ int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v
4301 BcmFlash2xBulkRead(Adapter, 4302 BcmFlash2xBulkRead(Adapter,
4302 &uiDSDPri, 4303 &uiDSDPri,
4303 dsd, 4304 dsd,
4304 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(PDSD_HEADER, DSDImagePriority), 4305 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
4305 4); 4306 4);
4306 4307
4307 uiDSDPri = ntohl(uiDSDPri); 4308 uiDSDPri = ntohl(uiDSDPri);
@@ -4348,7 +4349,7 @@ int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_
4348{ 4349{
4349 unsigned int uiISOsig = 0; 4350 unsigned int uiISOsig = 0;
4350 /* unsigned int sigoffsetInMap = 0; 4351 /* unsigned int sigoffsetInMap = 0;
4351 * ISO_HEADER ISOHeader = {0}; 4352 * struct bcm_iso_header ISOHeader = {0};
4352 * sigoffsetInMap =(PUCHAR)&(ISOHeader.ISOImageMagicNumber) -(PUCHAR)&ISOHeader; 4353 * sigoffsetInMap =(PUCHAR)&(ISOHeader.ISOImageMagicNumber) -(PUCHAR)&ISOHeader;
4353 */ 4354 */
4354 if (iso != ISO_IMAGE1 && iso != ISO_IMAGE2) { 4355 if (iso != ISO_IMAGE1 && iso != ISO_IMAGE2) {
@@ -4358,7 +4359,7 @@ int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_
4358 BcmFlash2xBulkRead(Adapter, 4359 BcmFlash2xBulkRead(Adapter,
4359 &uiISOsig, 4360 &uiISOsig,
4360 iso, 4361 iso,
4361 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImageMagicNumber), 4362 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber),
4362 SIGNATURE_SIZE); 4363 SIGNATURE_SIZE);
4363 4364
4364 uiISOsig = ntohl(uiISOsig); 4365 uiISOsig = ntohl(uiISOsig);
@@ -4375,7 +4376,7 @@ int ReadISOPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_v
4375 BcmFlash2xBulkRead(Adapter, 4376 BcmFlash2xBulkRead(Adapter,
4376 &ISOPri, 4377 &ISOPri,
4377 iso, 4378 iso,
4378 0 + FIELD_OFFSET_IN_HEADER(PISO_HEADER, ISOImagePriority), 4379 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority),
4379 4); 4380 4);
4380 4381
4381 ISOPri = ntohl(ISOPri); 4382 ISOPri = ntohl(ISOPri);
@@ -4568,7 +4569,7 @@ static int CorruptDSDSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_sect
4568 return -ENOMEM; 4569 return -ENOMEM;
4569 } 4570 }
4570 4571
4571 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(DSD_HEADER); 4572 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header);
4572 uiOffset -= MAX_RW_SIZE; 4573 uiOffset -= MAX_RW_SIZE;
4573 4574
4574 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, eFlash2xSectionVal, uiOffset, MAX_RW_SIZE); 4575 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, eFlash2xSectionVal, uiOffset, MAX_RW_SIZE);
diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h
index 651b5a455b32..e765cca5d966 100644
--- a/drivers/staging/bcm/nvm.h
+++ b/drivers/staging/bcm/nvm.h
@@ -1,409 +1,286 @@
1/*************************************************************************************** 1/***************************************************************************************
2// 2 *
3// Copyright (c) Beceem Communications Inc. 3 * Copyright (c) Beceem Communications Inc.
4// 4 *
5// Module Name: 5 * Module Name:
6// NVM.h 6 * NVM.h
7// 7 *
8// Abstract: 8 * Abstract:
9// This file has the prototypes,preprocessors and definitions various NVM libraries. 9 * This file has the prototypes,preprocessors and definitions various NVM libraries.
10// 10 *
11// 11 *
12// Revision History: 12 * Revision History:
13// Who When What 13 * Who When What
14// -------- -------- ---------------------------------------------- 14 * -------- -------- ----------------------------------------------
15// Name Date Created/reviewed/modified 15 * Name Date Created/reviewed/modified
16// 16 *
17// Notes: 17 * Notes:
18// 18 *
19****************************************************************************************/ 19 ****************************************************************************************/
20
21 20
22#ifndef _NVM_H_ 21#ifndef _NVM_H_
23#define _NVM_H_ 22#define _NVM_H_
24 23
25typedef struct _FLASH_SECTOR_INFO 24struct bcm_flash_cs_info {
26{ 25 u32 MagicNumber;
27 UINT uiSectorSig; 26 /* let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" */
28 UINT uiSectorSize; 27 u32 FlashLayoutVersion;
29 28 u32 ISOImageVersion;
30}FLASH_SECTOR_INFO,*PFLASH_SECTOR_INFO; 29 u32 SCSIFirmwareVersion;
31 30 u32 OffsetFromZeroForPart1ISOImage;
32typedef struct _FLASH_CS_INFO 31 u32 OffsetFromZeroForScsiFirmware;
33{ 32 u32 SizeOfScsiFirmware;
34 B_UINT32 MagicNumber; 33 u32 OffsetFromZeroForPart2ISOImage;
35// let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" 34 u32 OffsetFromZeroForCalibrationStart;
36 35 u32 OffsetFromZeroForCalibrationEnd;
37 B_UINT32 FlashLayoutVersion ; 36 u32 OffsetFromZeroForVSAStart;
38 37 u32 OffsetFromZeroForVSAEnd;
39 // ISO Image/Format/BuildTool versioning 38 u32 OffsetFromZeroForControlSectionStart;
40 B_UINT32 ISOImageVersion; 39 u32 OffsetFromZeroForControlSectionData;
41 40 u32 CDLessInactivityTimeout;
42 // SCSI/Flash BootLoader versioning 41 u32 NewImageSignature;
43 B_UINT32 SCSIFirmwareVersion; 42 u32 FlashSectorSizeSig;
44 43 u32 FlashSectorSize;
45 44 u32 FlashWriteSupportSize;
46 B_UINT32 OffsetFromZeroForPart1ISOImage; 45 u32 TotalFlashSize;
47// typically 0 46 u32 FlashBaseAddr;
48 47 u32 FlashPartMaxSize;
49 B_UINT32 OffsetFromZeroForScsiFirmware; 48 u32 IsCDLessDeviceBootSig;
50//typically at 12MB 49 /* MSC Timeout after reset to switch from MSC to NW Mode */
51 50 u32 MassStorageTimeout;
52 B_UINT32 SizeOfScsiFirmware ; 51};
53//size of the firmware - depends on binary size 52
54 53#define FLASH2X_TOTAL_SIZE (64 * 1024 * 1024)
55 B_UINT32 OffsetFromZeroForPart2ISOImage; 54#define DEFAULT_SECTOR_SIZE (64 * 1024)
56// typically at first Word Aligned offset 12MB + sizeOfScsiFirmware. 55
57 56struct bcm_flash2x_cs_info {
58 B_UINT32 OffsetFromZeroForCalibrationStart; 57 /* magic number as 0xBECE-F1A5 - F1A5 for "flas-h" */
59// typically at 15MB 58 u32 MagicNumber;
60 59 u32 FlashLayoutVersion;
61 B_UINT32 OffsetFromZeroForCalibrationEnd; 60 u32 ISOImageVersion;
62 61 u32 SCSIFirmwareVersion;
63// VSA0 offsets 62 u32 OffsetFromZeroForPart1ISOImage;
64 B_UINT32 OffsetFromZeroForVSAStart; 63 u32 OffsetFromZeroForScsiFirmware;
65 B_UINT32 OffsetFromZeroForVSAEnd; 64 u32 SizeOfScsiFirmware;
66 65 u32 OffsetFromZeroForPart2ISOImage;
67// Control Section offsets 66 u32 OffsetFromZeroForDSDStart;
68 B_UINT32 OffsetFromZeroForControlSectionStart; 67 u32 OffsetFromZeroForDSDEnd;
69 B_UINT32 OffsetFromZeroForControlSectionData; 68 u32 OffsetFromZeroForVSAStart;
70 69 u32 OffsetFromZeroForVSAEnd;
71// NO Data Activity timeout to switch from MSC to NW Mode 70 u32 OffsetFromZeroForControlSectionStart;
72 B_UINT32 CDLessInactivityTimeout; 71 u32 OffsetFromZeroForControlSectionData;
73 72 /* NO Data Activity timeout to switch from MSC to NW Mode */
74// New ISO Image Signature 73 u32 CDLessInactivityTimeout;
75 B_UINT32 NewImageSignature; 74 u32 NewImageSignature;
76 75 u32 FlashSectorSizeSig;
77// Signature to validate the sector size. 76 u32 FlashSectorSize;
78 B_UINT32 FlashSectorSizeSig; 77 u32 FlashWriteSupportSize;
79 78 u32 TotalFlashSize;
80// Sector Size 79 u32 FlashBaseAddr;
81 B_UINT32 FlashSectorSize; 80 u32 FlashPartMaxSize;
82 81 u32 IsCDLessDeviceBootSig;
83// Write Size Support 82 /* MSC Timeout after reset to switch from MSC to NW Mode */
84 B_UINT32 FlashWriteSupportSize; 83 u32 MassStorageTimeout;
85
86// Total Flash Size
87 B_UINT32 TotalFlashSize;
88
89// Flash Base Address for offset specified
90 B_UINT32 FlashBaseAddr;
91
92// Flash Part Max Size
93 B_UINT32 FlashPartMaxSize;
94
95// Is CDLess or Flash Bootloader
96 B_UINT32 IsCDLessDeviceBootSig;
97
98// MSC Timeout after reset to switch from MSC to NW Mode
99 B_UINT32 MassStorageTimeout;
100
101
102}FLASH_CS_INFO,*PFLASH_CS_INFO;
103
104#define FLASH2X_TOTAL_SIZE (64*1024*1024)
105#define DEFAULT_SECTOR_SIZE (64*1024)
106
107typedef struct _FLASH_2X_CS_INFO
108{
109
110 // magic number as 0xBECE-F1A5 - F1A5 for "flas-h"
111 B_UINT32 MagicNumber;
112
113 B_UINT32 FlashLayoutVersion ;
114
115 // ISO Image/Format/BuildTool versioning
116 B_UINT32 ISOImageVersion;
117
118 // SCSI/Flash BootLoader versioning
119 B_UINT32 SCSIFirmwareVersion;
120
121 // ISO Image1 Part1/SCSI Firmware/Flash Bootloader Start offset, size
122 B_UINT32 OffsetFromZeroForPart1ISOImage;
123 B_UINT32 OffsetFromZeroForScsiFirmware;
124 B_UINT32 SizeOfScsiFirmware ;
125
126 // ISO Image1 Part2 start offset
127 B_UINT32 OffsetFromZeroForPart2ISOImage;
128
129
130 // DSD0 offset
131 B_UINT32 OffsetFromZeroForDSDStart;
132 B_UINT32 OffsetFromZeroForDSDEnd;
133
134 // VSA0 offset
135 B_UINT32 OffsetFromZeroForVSAStart;
136 B_UINT32 OffsetFromZeroForVSAEnd;
137
138 // Control Section offset
139 B_UINT32 OffsetFromZeroForControlSectionStart;
140 B_UINT32 OffsetFromZeroForControlSectionData;
141
142 // NO Data Activity timeout to switch from MSC to NW Mode
143 B_UINT32 CDLessInactivityTimeout;
144
145 // New ISO Image Signature
146 B_UINT32 NewImageSignature;
147
148 B_UINT32 FlashSectorSizeSig; // Sector Size Signature
149 B_UINT32 FlashSectorSize; // Sector Size
150 B_UINT32 FlashWriteSupportSize; // Write Size Support
151
152 B_UINT32 TotalFlashSize; // Total Flash Size
153
154 // Flash Base Address for offset specified
155 B_UINT32 FlashBaseAddr;
156 B_UINT32 FlashPartMaxSize; // Flash Part Max Size
157
158 // Is CDLess or Flash Bootloader
159 B_UINT32 IsCDLessDeviceBootSig;
160
161 // MSC Timeout after reset to switch from MSC to NW Mode
162 B_UINT32 MassStorageTimeout;
163
164 /* Flash Map 2.0 Field */ 84 /* Flash Map 2.0 Field */
165 B_UINT32 OffsetISOImage1Part1Start; // ISO Image1 Part1 offset 85 u32 OffsetISOImage1Part1Start;
166 B_UINT32 OffsetISOImage1Part1End; 86 u32 OffsetISOImage1Part1End;
167 B_UINT32 OffsetISOImage1Part2Start; // ISO Image1 Part2 offset 87 u32 OffsetISOImage1Part2Start;
168 B_UINT32 OffsetISOImage1Part2End; 88 u32 OffsetISOImage1Part2End;
169 B_UINT32 OffsetISOImage1Part3Start; // ISO Image1 Part3 offset 89 u32 OffsetISOImage1Part3Start;
170 B_UINT32 OffsetISOImage1Part3End; 90 u32 OffsetISOImage1Part3End;
171 91 u32 OffsetISOImage2Part1Start;
172 B_UINT32 OffsetISOImage2Part1Start; // ISO Image2 Part1 offset 92 u32 OffsetISOImage2Part1End;
173 B_UINT32 OffsetISOImage2Part1End; 93 u32 OffsetISOImage2Part2Start;
174 B_UINT32 OffsetISOImage2Part2Start; // ISO Image2 Part2 offset 94 u32 OffsetISOImage2Part2End;
175 B_UINT32 OffsetISOImage2Part2End; 95 u32 OffsetISOImage2Part3Start;
176 B_UINT32 OffsetISOImage2Part3Start; // ISO Image2 Part3 offset 96 u32 OffsetISOImage2Part3End;
177 B_UINT32 OffsetISOImage2Part3End; 97 /* DSD Header offset from start of DSD */
178 98 u32 OffsetFromDSDStartForDSDHeader;
179 99 u32 OffsetFromZeroForDSD1Start;
180 // DSD Header offset from start of DSD 100 u32 OffsetFromZeroForDSD1End;
181 B_UINT32 OffsetFromDSDStartForDSDHeader; 101 u32 OffsetFromZeroForDSD2Start;
182 B_UINT32 OffsetFromZeroForDSD1Start; // DSD 1 offset 102 u32 OffsetFromZeroForDSD2End;
183 B_UINT32 OffsetFromZeroForDSD1End; 103 u32 OffsetFromZeroForVSA1Start;
184 B_UINT32 OffsetFromZeroForDSD2Start; // DSD 2 offset 104 u32 OffsetFromZeroForVSA1End;
185 B_UINT32 OffsetFromZeroForDSD2End; 105 u32 OffsetFromZeroForVSA2Start;
186 106 u32 OffsetFromZeroForVSA2End;
187 B_UINT32 OffsetFromZeroForVSA1Start; // VSA 1 offset
188 B_UINT32 OffsetFromZeroForVSA1End;
189 B_UINT32 OffsetFromZeroForVSA2Start; // VSA 2 offset
190 B_UINT32 OffsetFromZeroForVSA2End;
191
192 /* 107 /*
193* ACCESS_BITS_PER_SECTOR 2 108 * ACCESS_BITS_PER_SECTOR 2
194* ACCESS_RW 0 109 * ACCESS_RW 0
195* ACCESS_RO 1 110 * ACCESS_RO 1
196* ACCESS_RESVD 2 111 * ACCESS_RESVD 2
197* ACCESS_RESVD 3 112 * ACCESS_RESVD 3
198* */ 113 */
199 B_UINT32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE/(DEFAULT_SECTOR_SIZE *16)]; 114 u32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)];
200 115 /* All expansions to the control data structure should add here */
201// All expansions to the control data structure should add here 116};
202 117
203}FLASH2X_CS_INFO,*PFLASH2X_CS_INFO; 118struct bcm_vendor_section_info {
204 119 u32 OffsetFromZeroForSectionStart;
205typedef struct _VENDOR_SECTION_INFO 120 u32 OffsetFromZeroForSectionEnd;
206{ 121 u32 AccessFlags;
207 B_UINT32 OffsetFromZeroForSectionStart; 122 u32 Reserved[16];
208 B_UINT32 OffsetFromZeroForSectionEnd; 123};
209 B_UINT32 AccessFlags; 124
210 B_UINT32 Reserved[16]; 125struct bcm_flash2x_vendor_info {
211 126 struct bcm_vendor_section_info VendorSection[TOTAL_SECTIONS];
212} VENDOR_SECTION_INFO, *PVENDOR_SECTION_INFO; 127 u32 Reserved[16];
213 128};
214typedef struct _FLASH2X_VENDORSPECIFIC_INFO 129
215{ 130struct bcm_dsd_header {
216 VENDOR_SECTION_INFO VendorSection[TOTAL_SECTIONS]; 131 u32 DSDImageSize;
217 B_UINT32 Reserved[16]; 132 u32 DSDImageCRC;
218 133 u32 DSDImagePriority;
219} FLASH2X_VENDORSPECIFIC_INFO, *PFLASH2X_VENDORSPECIFIC_INFO; 134 /* We should not consider right now. Reading reserve is worthless. */
220 135 u32 Reserved[252]; /* Resvd for DSD Header */
221typedef struct _DSD_HEADER 136 u32 DSDImageMagicNumber;
222{ 137};
223 B_UINT32 DSDImageSize; 138
224 B_UINT32 DSDImageCRC; 139struct bcm_iso_header {
225 B_UINT32 DSDImagePriority; 140 u32 ISOImageMagicNumber;
226 //We should not consider right now. Reading reserve is worthless. 141 u32 ISOImageSize;
227 B_UINT32 Reserved[252]; // Resvd for DSD Header 142 u32 ISOImageCRC;
228 B_UINT32 DSDImageMagicNumber; 143 u32 ISOImagePriority;
229 144 /* We should not consider right now. Reading reserve is worthless. */
230}DSD_HEADER, *PDSD_HEADER; 145 u32 Reserved[60]; /* Resvd for ISO Header extension */
231 146};
232typedef struct _ISO_HEADER 147
233{ 148#define EEPROM_BEGIN_CIS (0)
234 B_UINT32 ISOImageMagicNumber; 149#define EEPROM_BEGIN_NON_CIS (0x200)
235 B_UINT32 ISOImageSize; 150#define EEPROM_END (0x2000)
236 B_UINT32 ISOImageCRC; 151#define INIT_PARAMS_SIGNATURE (0x95a7a597)
237 B_UINT32 ISOImagePriority; 152#define MAX_INIT_PARAMS_LENGTH (2048)
238 //We should not consider right now. Reading reserve is worthless. 153#define MAC_ADDRESS_OFFSET 0x200
239 B_UINT32 Reserved[60]; //Resvd for ISO Header extension 154
240 155#define INIT_PARAMS_1_SIGNATURE_ADDRESS EEPROM_BEGIN_NON_CIS
241}ISO_HEADER, *PISO_HEADER; 156#define INIT_PARAMS_1_DATA_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+16)
242 157#define INIT_PARAMS_1_MACADDRESS_ADDRESS (MAC_ADDRESS_OFFSET)
243#define EEPROM_BEGIN_CIS (0) 158#define INIT_PARAMS_1_LENGTH_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+4)
244#define EEPROM_BEGIN_NON_CIS (0x200) 159
245#define EEPROM_END (0x2000) 160#define INIT_PARAMS_2_SIGNATURE_ADDRESS (EEPROM_BEGIN_NON_CIS + 2048 + 16)
246 161#define INIT_PARAMS_2_DATA_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 16)
247#define INIT_PARAMS_SIGNATURE (0x95a7a597) 162#define INIT_PARAMS_2_MACADDRESS_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 8)
248 163#define INIT_PARAMS_2_LENGTH_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 4)
249#define MAX_INIT_PARAMS_LENGTH (2048) 164
250 165#define EEPROM_SPI_DEV_CONFIG_REG 0x0F003000
251 166#define EEPROM_SPI_Q_STATUS1_REG 0x0F003004
252#define MAC_ADDRESS_OFFSET 0x200 167#define EEPROM_SPI_Q_STATUS1_MASK_REG 0x0F00300C
253 168
254 169#define EEPROM_SPI_Q_STATUS_REG 0x0F003008
255#define INIT_PARAMS_1_SIGNATURE_ADDRESS EEPROM_BEGIN_NON_CIS 170#define EEPROM_CMDQ_SPI_REG 0x0F003018
256#define INIT_PARAMS_1_DATA_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+16) 171#define EEPROM_WRITE_DATAQ_REG 0x0F00301C
257#define INIT_PARAMS_1_MACADDRESS_ADDRESS (MAC_ADDRESS_OFFSET) 172#define EEPROM_READ_DATAQ_REG 0x0F003020
258#define INIT_PARAMS_1_LENGTH_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+4) 173#define SPI_FLUSH_REG 0x0F00304C
259 174
260#define INIT_PARAMS_2_SIGNATURE_ADDRESS (EEPROM_BEGIN_NON_CIS+2048+16) 175#define EEPROM_WRITE_ENABLE 0x06000000
261#define INIT_PARAMS_2_DATA_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS+16) 176#define EEPROM_READ_STATUS_REGISTER 0x05000000
262#define INIT_PARAMS_2_MACADDRESS_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS+8) 177#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000
263#define INIT_PARAMS_2_LENGTH_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS+4) 178#define EEPROM_WRITE_QUEUE_EMPTY 0x00001000
264 179#define EEPROM_WRITE_QUEUE_AVAIL 0x00002000
265#define EEPROM_SPI_DEV_CONFIG_REG 0x0F003000 180#define EEPROM_WRITE_QUEUE_FULL 0x00004000
266#define EEPROM_SPI_Q_STATUS1_REG 0x0F003004 181#define EEPROM_16_BYTE_PAGE_READ 0xFB000000
267#define EEPROM_SPI_Q_STATUS1_MASK_REG 0x0F00300C 182#define EEPROM_4_BYTE_PAGE_READ 0x3B000000
268 183
269#define EEPROM_SPI_Q_STATUS_REG 0x0F003008 184#define EEPROM_CMD_QUEUE_FLUSH 0x00000001
270#define EEPROM_CMDQ_SPI_REG 0x0F003018 185#define EEPROM_WRITE_QUEUE_FLUSH 0x00000002
271#define EEPROM_WRITE_DATAQ_REG 0x0F00301C 186#define EEPROM_READ_QUEUE_FLUSH 0x00000004
272#define EEPROM_READ_DATAQ_REG 0x0F003020 187#define EEPROM_ETH_QUEUE_FLUSH 0x00000008
273#define SPI_FLUSH_REG 0x0F00304C 188#define EEPROM_ALL_QUEUE_FLUSH 0x0000000f
274 189#define EEPROM_READ_ENABLE 0x06000000
275#define EEPROM_WRITE_ENABLE 0x06000000 190#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000
276#define EEPROM_READ_STATUS_REGISTER 0x05000000 191#define EEPROM_READ_DATA_FULL 0x00000010
277#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000 192#define EEPROM_READ_DATA_AVAIL 0x00000020
278#define EEPROM_WRITE_QUEUE_EMPTY 0x00001000 193#define EEPROM_READ_QUEUE_EMPTY 0x00000002
279#define EEPROM_WRITE_QUEUE_AVAIL 0x00002000 194#define EEPROM_CMD_QUEUE_EMPTY 0x00000100
280#define EEPROM_WRITE_QUEUE_FULL 0x00004000 195#define EEPROM_CMD_QUEUE_AVAIL 0x00000200
281#define EEPROM_16_BYTE_PAGE_READ 0xFB000000 196#define EEPROM_CMD_QUEUE_FULL 0x00000400
282#define EEPROM_4_BYTE_PAGE_READ 0x3B000000
283
284#define EEPROM_CMD_QUEUE_FLUSH 0x00000001
285#define EEPROM_WRITE_QUEUE_FLUSH 0x00000002
286#define EEPROM_READ_QUEUE_FLUSH 0x00000004
287#define EEPROM_ETH_QUEUE_FLUSH 0x00000008
288#define EEPROM_ALL_QUEUE_FLUSH 0x0000000f
289#define EEPROM_READ_ENABLE 0x06000000
290#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000
291#define EEPROM_READ_DATA_FULL 0x00000010
292#define EEPROM_READ_DATA_AVAIL 0x00000020
293#define EEPROM_READ_QUEUE_EMPTY 0x00000002
294#define EEPROM_CMD_QUEUE_EMPTY 0x00000100
295#define EEPROM_CMD_QUEUE_AVAIL 0x00000200
296#define EEPROM_CMD_QUEUE_FULL 0x00000400
297 197
298/* Most EEPROM status register bit 0 indicates if the EEPROM is busy 198/* Most EEPROM status register bit 0 indicates if the EEPROM is busy
299 * with a write if set 1. See the details of the EEPROM Status Register 199 * with a write if set 1. See the details of the EEPROM Status Register
300 * in the EEPROM data sheet. */ 200 * in the EEPROM data sheet.
301#define EEPROM_STATUS_REG_WRITE_BUSY 0x00000001 201 */
302 202#define EEPROM_STATUS_REG_WRITE_BUSY 0x00000001
303// We will have 1 mSec for every RETRIES_PER_DELAY count and have a max attempts of MAX_EEPROM_RETRIES 203
304// This will give us 80 mSec minimum of delay = 80mSecs 204/* We will have 1 mSec for every RETRIES_PER_DELAY count and have a max attempts of MAX_EEPROM_RETRIES
305#define MAX_EEPROM_RETRIES 80 205 * This will give us 80 mSec minimum of delay = 80mSecs
306#define RETRIES_PER_DELAY 64 206 */
307 207#define MAX_EEPROM_RETRIES 80
308 208#define RETRIES_PER_DELAY 64
309#define MAX_RW_SIZE 0x10 209#define MAX_RW_SIZE 0x10
310#define MAX_READ_SIZE 0x10 210#define MAX_READ_SIZE 0x10
311#define MAX_SECTOR_SIZE (512*1024) 211#define MAX_SECTOR_SIZE (512 * 1024)
312#define MIN_SECTOR_SIZE (1024) 212#define MIN_SECTOR_SIZE (1024)
313#define FLASH_SECTOR_SIZE_OFFSET 0xEFFFC 213#define FLASH_SECTOR_SIZE_OFFSET 0xEFFFC
314#define FLASH_SECTOR_SIZE_SIG_OFFSET 0xEFFF8 214#define FLASH_SECTOR_SIZE_SIG_OFFSET 0xEFFF8
315#define FLASH_SECTOR_SIZE_SIG 0xCAFEBABE 215#define FLASH_SECTOR_SIZE_SIG 0xCAFEBABE
316#define FLASH_CS_INFO_START_ADDR 0xFF0000 216#define FLASH_CS_INFO_START_ADDR 0xFF0000
317#define FLASH_CONTROL_STRUCT_SIGNATURE 0xBECEF1A5 217#define FLASH_CONTROL_STRUCT_SIGNATURE 0xBECEF1A5
318#define SCSI_FIRMWARE_MAJOR_VERSION 0x1 218#define SCSI_FIRMWARE_MAJOR_VERSION 0x1
319#define SCSI_FIRMWARE_MINOR_VERSION 0x5 219#define SCSI_FIRMWARE_MINOR_VERSION 0x5
320#define BYTE_WRITE_SUPPORT 0x1 220#define BYTE_WRITE_SUPPORT 0x1
321 221#define FLASH_AUTO_INIT_BASE_ADDR 0xF00000
322#define FLASH_AUTO_INIT_BASE_ADDR 0xF00000 222#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000
323 223#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000
324 224#define FLASH_CONTIGIOUS_START_ADDR_BCS350 0x08000000
325 225#define FLASH_CONTIGIOUS_END_ADDR_BCS350 0x08FFFFFF
326 226#define FLASH_SIZE_ADDR 0xFFFFEC
327#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000 227#define FLASH_SPI_CMDQ_REG 0xAF003040
328#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000 228#define FLASH_SPI_WRITEQ_REG 0xAF003044
329 229#define FLASH_SPI_READQ_REG 0xAF003048
330#define FLASH_CONTIGIOUS_START_ADDR_BCS350 0x08000000 230#define FLASH_CONFIG_REG 0xAF003050
331#define FLASH_CONTIGIOUS_END_ADDR_BCS350 0x08FFFFFF 231#define FLASH_GPIO_CONFIG_REG 0xAF000030
332 232#define FLASH_CMD_WRITE_ENABLE 0x06
333 233#define FLASH_CMD_READ_ENABLE 0x03
334 234#define FLASH_CMD_RESET_WRITE_ENABLE 0x04
335#define FLASH_SIZE_ADDR 0xFFFFEC 235#define FLASH_CMD_STATUS_REG_READ 0x05
336 236#define FLASH_CMD_STATUS_REG_WRITE 0x01
337#define FLASH_SPI_CMDQ_REG 0xAF003040 237#define FLASH_CMD_READ_ID 0x9F
338#define FLASH_SPI_WRITEQ_REG 0xAF003044 238#define PAD_SELECT_REGISTER 0xAF000410
339#define FLASH_SPI_READQ_REG 0xAF003048 239#define FLASH_PART_SST25VF080B 0xBF258E
340#define FLASH_CONFIG_REG 0xAF003050 240#define EEPROM_CAL_DATA_INTERNAL_LOC 0xbFB00008
341#define FLASH_GPIO_CONFIG_REG 0xAF000030 241#define EEPROM_CALPARAM_START 0x200
342 242#define EEPROM_SIZE_OFFSET 524
343#define FLASH_CMD_WRITE_ENABLE 0x06 243
344#define FLASH_CMD_READ_ENABLE 0x03 244/* As Read/Write time vaires from 1.5 to 3.0 ms.
345#define FLASH_CMD_RESET_WRITE_ENABLE 0x04 245 * so After Ignoring the rdm/wrm time(that is dependent on many factor like interface etc.),
346#define FLASH_CMD_STATUS_REG_READ 0x05 246 * here time calculated meets the worst case delay, 3.0 ms
347#define FLASH_CMD_STATUS_REG_WRITE 0x01 247 */
348#define FLASH_CMD_READ_ID 0x9F 248#define MAX_FLASH_RETRIES 4
349 249#define FLASH_PER_RETRIES_DELAY 16
350#define PAD_SELECT_REGISTER 0xAF000410 250#define EEPROM_MAX_CAL_AREA_SIZE 0xF0000
351 251#define BECM ntohl(0x4245434d)
352#define FLASH_PART_SST25VF080B 0xBF258E 252#define FLASH_2X_MAJOR_NUMBER 0x2
353 253#define DSD_IMAGE_MAGIC_NUMBER 0xBECE0D5D
354#define EEPROM_CAL_DATA_INTERNAL_LOC 0xbFB00008 254#define ISO_IMAGE_MAGIC_NUMBER 0xBECE0150
355 255#define NON_CDLESS_DEVICE_BOOT_SIG 0xBECEB007
356#define EEPROM_CALPARAM_START 0x200 256
357#define EEPROM_SIZE_OFFSET 524 257#define MINOR_VERSION(x) ((x >> 16) & 0xFFFF)
358
359//As Read/Write time vaires from 1.5 to 3.0 ms.
360//so After Ignoring the rdm/wrm time(that is dependent on many factor like interface etc.),
361//here time calculated meets the worst case delay, 3.0 ms
362#define MAX_FLASH_RETRIES 4
363#define FLASH_PER_RETRIES_DELAY 16
364
365
366#define EEPROM_MAX_CAL_AREA_SIZE 0xF0000
367
368
369
370#define BECM ntohl(0x4245434d)
371
372#define FLASH_2X_MAJOR_NUMBER 0x2
373#define DSD_IMAGE_MAGIC_NUMBER 0xBECE0D5D
374#define ISO_IMAGE_MAGIC_NUMBER 0xBECE0150
375#define NON_CDLESS_DEVICE_BOOT_SIG 0xBECEB007
376#define MINOR_VERSION(x) ((x >>16) & 0xFFFF)
377#define MAJOR_VERSION(x) (x & 0xFFFF) 258#define MAJOR_VERSION(x) (x & 0xFFFF)
378#define CORRUPTED_PATTERN 0x0
379#define UNINIT_PTR_IN_CS 0xBBBBDDDD
380
381#define VENDOR_PTR_IN_CS 0xAAAACCCC
382
383
384#define FLASH2X_SECTION_PRESENT 1<<0
385#define FLASH2X_SECTION_VALID 1<<1
386#define FLASH2X_SECTION_RO 1<<2
387#define FLASH2X_SECTION_ACT 1<<3
388#define SECTOR_IS_NOT_WRITABLE STATUS_FAILURE
389#define INVALID_OFFSET STATUS_FAILURE
390#define INVALID_SECTION STATUS_FAILURE
391#define SECTOR_1K 1024
392#define SECTOR_64K (64 *SECTOR_1K)
393#define SECTOR_128K (2 * SECTOR_64K)
394#define SECTOR_256k (2 * SECTOR_128K)
395#define SECTOR_512K (2 * SECTOR_256k)
396#define FLASH_PART_SIZE (16 * 1024 * 1024)
397#define RESET_CHIP_SELECT -1
398#define CHIP_SELECT_BIT12 12
399
400#define SECTOR_READWRITE_PERMISSION 0
401#define SECTOR_READONLY 1
402#define SIGNATURE_SIZE 4
403#define DEFAULT_BUFF_SIZE 0x10000
404
405 259
406#define FIELD_OFFSET_IN_HEADER(HeaderPointer,Field) ((PUCHAR)&((HeaderPointer)(NULL))->Field - (PUCHAR)(NULL)) 260#define CORRUPTED_PATTERN 0x0
261#define UNINIT_PTR_IN_CS 0xBBBBDDDD
262#define VENDOR_PTR_IN_CS 0xAAAACCCC
263#define FLASH2X_SECTION_PRESENT (1 << 0)
264#define FLASH2X_SECTION_VALID (1 << 1)
265#define FLASH2X_SECTION_RO (1 << 2)
266#define FLASH2X_SECTION_ACT (1 << 3)
267#define SECTOR_IS_NOT_WRITABLE STATUS_FAILURE
268#define INVALID_OFFSET STATUS_FAILURE
269#define INVALID_SECTION STATUS_FAILURE
270#define SECTOR_1K 1024
271#define SECTOR_64K (64 * SECTOR_1K)
272#define SECTOR_128K (2 * SECTOR_64K)
273#define SECTOR_256k (2 * SECTOR_128K)
274#define SECTOR_512K (2 * SECTOR_256k)
275#define FLASH_PART_SIZE (16 * 1024 * 1024)
276#define RESET_CHIP_SELECT -1
277#define CHIP_SELECT_BIT12 12
278#define SECTOR_READWRITE_PERMISSION 0
279#define SECTOR_READONLY 1
280#define SIGNATURE_SIZE 4
281#define DEFAULT_BUFF_SIZE 0x10000
282
283#define FIELD_OFFSET_IN_HEADER(HeaderPointer, Field) ((u8 *)&((HeaderPointer)(NULL))->Field - (u8 *)(NULL))
407 284
408#endif 285#endif
409 286
diff --git a/drivers/staging/bcm/target_params.h b/drivers/staging/bcm/target_params.h
index ad7ec0054938..dc45f9ab854d 100644
--- a/drivers/staging/bcm/target_params.h
+++ b/drivers/staging/bcm/target_params.h
@@ -1,81 +1,57 @@
1#ifndef TARGET_PARAMS_H 1#ifndef TARGET_PARAMS_H
2#define TARGET_PARAMS_H 2#define TARGET_PARAMS_H
3 3
4typedef struct _TARGET_PARAMS 4struct bcm_target_params {
5{ 5 u32 m_u32CfgVersion;
6 B_UINT32 m_u32CfgVersion; 6 u32 m_u32CenterFrequency;
7 7 u32 m_u32BandAScan;
8 // Scanning Related Params 8 u32 m_u32BandBScan;
9 B_UINT32 m_u32CenterFrequency; 9 u32 m_u32BandCScan;
10 B_UINT32 m_u32BandAScan; 10 u32 m_u32ErtpsOptions;
11 B_UINT32 m_u32BandBScan; 11 u32 m_u32PHSEnable;
12 B_UINT32 m_u32BandCScan; 12 u32 m_u32HoEnable;
13 13 u32 m_u32HoReserved1;
14 14 u32 m_u32HoReserved2;
15 // QoS Params 15 u32 m_u32MimoEnable;
16 B_UINT32 m_u32ErtpsOptions; 16 u32 m_u32SecurityEnable;
17 17 u32 m_u32PowerSavingModesEnable; /* bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable */
18 B_UINT32 m_u32PHSEnable; 18 /* PowerSaving Mode Options:
19 19 * bit 0 = 1: CPE mode - to keep pcmcia if alive;
20 20 * bit 1 = 1: CINR reporting in Idlemode Msg
21 // HO Params 21 * bit 2 = 1: Default PSC Enable in sleepmode
22 B_UINT32 m_u32HoEnable; 22 */
23 23 u32 m_u32PowerSavingModeOptions;
24 B_UINT32 m_u32HoReserved1; 24 u32 m_u32ArqEnable;
25 B_UINT32 m_u32HoReserved2; 25 /* From Version #3, the HARQ section renamed as general */
26 // Power Control Params 26 u32 m_u32HarqEnable;
27 27 u32 m_u32EEPROMFlag;
28 B_UINT32 m_u32MimoEnable; 28 /* BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte
29 29 * Unused - LSByte
30 B_UINT32 m_u32SecurityEnable; 30 */
31 31 u32 m_u32Customize;
32 B_UINT32 m_u32PowerSavingModesEnable; //bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable 32 u32 m_u32ConfigBW; /* In Hz */
33 /* PowerSaving Mode Options: 33 u32 m_u32ShutDownInitThresholdTimer;
34 bit 0 = 1: CPE mode - to keep pcmcia if alive; 34 u32 m_u32RadioParameter;
35 bit 1 = 1: CINR reporting in Idlemode Msg 35 u32 m_u32PhyParameter1;
36 bit 2 = 1: Default PSC Enable in sleepmode*/ 36 u32 m_u32PhyParameter2;
37 B_UINT32 m_u32PowerSavingModeOptions; 37 u32 m_u32PhyParameter3;
38 38 u32 m_u32TestOptions; /* in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack */
39 B_UINT32 m_u32ArqEnable; 39 u32 m_u32MaxMACDataperDLFrame;
40 40 u32 m_u32MaxMACDataperULFrame;
41 // From Version #3, the HARQ section renamed as general 41 u32 m_u32Corr2MacFlags;
42 B_UINT32 m_u32HarqEnable; 42 u32 HostDrvrConfig1;
43 // EEPROM Param Location 43 u32 HostDrvrConfig2;
44 B_UINT32 m_u32EEPROMFlag; 44 u32 HostDrvrConfig3;
45 // BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte 45 u32 HostDrvrConfig4;
46 // Unused - LSByte 46 u32 HostDrvrConfig5;
47 B_UINT32 m_u32Customize; 47 u32 HostDrvrConfig6;
48 B_UINT32 m_u32ConfigBW; /* In Hz */ 48 u32 m_u32SegmentedPUSCenable;
49 B_UINT32 m_u32ShutDownInitThresholdTimer; 49 /* removed SHUT down related 'unused' params from here to sync 4.x and 5.x CFG files..
50 50 * BAMC Related Parameters
51 B_UINT32 m_u32RadioParameter; 51 * Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling.
52 B_UINT32 m_u32PhyParameter1; 52 * bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support.
53 B_UINT32 m_u32PhyParameter2; 53 */
54 B_UINT32 m_u32PhyParameter3; 54 u32 m_u32BandAMCEnable;
55 55};
56 B_UINT32 m_u32TestOptions; // in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack
57
58 B_UINT32 m_u32MaxMACDataperDLFrame;
59 B_UINT32 m_u32MaxMACDataperULFrame;
60
61 B_UINT32 m_u32Corr2MacFlags;
62
63 //adding driver params.
64 B_UINT32 HostDrvrConfig1;
65 B_UINT32 HostDrvrConfig2;
66 B_UINT32 HostDrvrConfig3;
67 B_UINT32 HostDrvrConfig4;
68 B_UINT32 HostDrvrConfig5;
69 B_UINT32 HostDrvrConfig6;
70 B_UINT32 m_u32SegmentedPUSCenable;
71
72 // removed SHUT down related 'unused' params from here to sync 4.x and 5.x CFG files..
73
74 //BAMC Related Parameters
75 //Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling.
76 //bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support.
77 B_UINT32 m_u32BandAMCEnable;
78
79} stTargetParams,TARGET_PARAMS,*PTARGET_PARAMS, STARGETPARAMS, *PSTARGETPARAMS;
80 56
81#endif 57#endif
diff --git a/drivers/staging/bcm/vendorspecificextn.c b/drivers/staging/bcm/vendorspecificextn.c
index 40be60aa909a..be1f91d955aa 100644
--- a/drivers/staging/bcm/vendorspecificextn.c
+++ b/drivers/staging/bcm/vendorspecificextn.c
@@ -11,7 +11,7 @@
11// STATUS_SUCCESS/STATUS_FAILURE 11// STATUS_SUCCESS/STATUS_FAILURE
12// 12//
13//----------------------------------------------------------------------------- 13//-----------------------------------------------------------------------------
14INT vendorextnGetSectionInfo(PVOID pContext,PFLASH2X_VENDORSPECIFIC_INFO pVendorInfo) 14INT vendorextnGetSectionInfo(PVOID pContext, struct bcm_flash2x_vendor_info *pVendorInfo)
15{ 15{
16 return STATUS_FAILURE; 16 return STATUS_FAILURE;
17} 17}
diff --git a/drivers/staging/bcm/vendorspecificextn.h b/drivers/staging/bcm/vendorspecificextn.h
index 834410e29e75..52890d216edf 100644
--- a/drivers/staging/bcm/vendorspecificextn.h
+++ b/drivers/staging/bcm/vendorspecificextn.h
@@ -4,7 +4,7 @@
4 4
5#define CONTINUE_COMMON_PATH 0xFFFF 5#define CONTINUE_COMMON_PATH 0xFFFF
6 6
7INT vendorextnGetSectionInfo(PVOID pContext,PFLASH2X_VENDORSPECIFIC_INFO pVendorInfo); 7INT vendorextnGetSectionInfo(PVOID pContext, struct bcm_flash2x_vendor_info *pVendorInfo);
8INT vendorextnExit(struct bcm_mini_adapter *Adapter); 8INT vendorextnExit(struct bcm_mini_adapter *Adapter);
9INT vendorextnInit(struct bcm_mini_adapter *Adapter); 9INT vendorextnInit(struct bcm_mini_adapter *Adapter);
10INT vendorextnIoctl(struct bcm_mini_adapter *Adapter, UINT cmd, ULONG arg); 10INT vendorextnIoctl(struct bcm_mini_adapter *Adapter, UINT cmd, ULONG arg);
diff --git a/drivers/staging/ced1401/ced_ioc.c b/drivers/staging/ced1401/ced_ioc.c
index d0434714afd3..82a333f6433e 100644
--- a/drivers/staging/ced1401/ced_ioc.c
+++ b/drivers/staging/ced1401/ced_ioc.c
@@ -123,7 +123,7 @@ int SendString(DEVICE_EXTENSION * pdx, const char __user * pData,
123 iReturn = PutChars(pdx, buffer, n); 123 iReturn = PutChars(pdx, buffer, n);
124 } 124 }
125 125
126 Allowi(pdx, false); // make sure we have input int 126 Allowi(pdx); // make sure we have input int
127 mutex_unlock(&pdx->io_mutex); 127 mutex_unlock(&pdx->io_mutex);
128 128
129 return iReturn; 129 return iReturn;
@@ -140,7 +140,7 @@ int SendChar(DEVICE_EXTENSION * pdx, char c)
140 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o 140 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
141 iReturn = PutChars(pdx, &c, 1); 141 iReturn = PutChars(pdx, &c, 1);
142 dev_dbg(&pdx->interface->dev, "SendChar >%c< (0x%02x)", c, c); 142 dev_dbg(&pdx->interface->dev, "SendChar >%c< (0x%02x)", c, c);
143 Allowi(pdx, false); // Make sure char reads are running 143 Allowi(pdx); // Make sure char reads are running
144 mutex_unlock(&pdx->io_mutex); 144 mutex_unlock(&pdx->io_mutex);
145 return iReturn; 145 return iReturn;
146} 146}
@@ -433,8 +433,8 @@ int GetChar(DEVICE_EXTENSION * pdx)
433 433
434 dev_dbg(&pdx->interface->dev, "GetChar"); 434 dev_dbg(&pdx->interface->dev, "GetChar");
435 435
436 Allowi(pdx, false); // Make sure char reads are running 436 Allowi(pdx); // Make sure char reads are running
437 SendChars(pdx); // and send any buffered chars 437 SendChars(pdx); // and send any buffered chars
438 438
439 spin_lock_irq(&pdx->charInLock); 439 spin_lock_irq(&pdx->charInLock);
440 if (pdx->dwNumInput > 0) // worth looking 440 if (pdx->dwNumInput > 0) // worth looking
@@ -447,7 +447,7 @@ int GetChar(DEVICE_EXTENSION * pdx)
447 iReturn = U14ERR_NOIN; // no input data to read 447 iReturn = U14ERR_NOIN; // no input data to read
448 spin_unlock_irq(&pdx->charInLock); 448 spin_unlock_irq(&pdx->charInLock);
449 449
450 Allowi(pdx, false); // Make sure char reads are running 450 Allowi(pdx); // Make sure char reads are running
451 451
452 mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o 452 mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
453 return iReturn; 453 return iReturn;
@@ -472,7 +472,7 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n)
472 return -ENOMEM; 472 return -ENOMEM;
473 473
474 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o 474 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
475 Allowi(pdx, false); // Make sure char reads are running 475 Allowi(pdx); // Make sure char reads are running
476 SendChars(pdx); // and send any buffered chars 476 SendChars(pdx); // and send any buffered chars
477 477
478 spin_lock_irq(&pdx->charInLock); 478 spin_lock_irq(&pdx->charInLock);
@@ -518,7 +518,7 @@ int GetString(DEVICE_EXTENSION * pdx, char __user * pUser, int n)
518 } else 518 } else
519 spin_unlock_irq(&pdx->charInLock); 519 spin_unlock_irq(&pdx->charInLock);
520 520
521 Allowi(pdx, false); // Make sure char reads are running 521 Allowi(pdx); // Make sure char reads are running
522 mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o 522 mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
523 523
524 return iReturn; 524 return iReturn;
@@ -531,7 +531,7 @@ int Stat1401(DEVICE_EXTENSION * pdx)
531{ 531{
532 int iReturn; 532 int iReturn;
533 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o 533 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
534 Allowi(pdx, false); // make sure we allow pending chars 534 Allowi(pdx); // make sure we allow pending chars
535 SendChars(pdx); // in both directions 535 SendChars(pdx); // in both directions
536 iReturn = pdx->dwNumInput; // no lock as single read 536 iReturn = pdx->dwNumInput; // no lock as single read
537 mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o 537 mutex_unlock(&pdx->io_mutex); // Protect disconnect from new i/o
@@ -550,7 +550,7 @@ int LineCount(DEVICE_EXTENSION * pdx)
550 int iReturn = 0; // will be count of line ends 550 int iReturn = 0; // will be count of line ends
551 551
552 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o 552 mutex_lock(&pdx->io_mutex); // Protect disconnect from new i/o
553 Allowi(pdx, false); // Make sure char reads are running 553 Allowi(pdx); // Make sure char reads are running
554 SendChars(pdx); // and send any buffered chars 554 SendChars(pdx); // and send any buffered chars
555 spin_lock_irq(&pdx->charInLock); // Get protection 555 spin_lock_irq(&pdx->charInLock); // Get protection
556 556
diff --git a/drivers/staging/ced1401/usb1401.c b/drivers/staging/ced1401/usb1401.c
index a27043a2f8c5..254131d8be5f 100644
--- a/drivers/staging/ced1401/usb1401.c
+++ b/drivers/staging/ced1401/usb1401.c
@@ -697,7 +697,7 @@ static void staged_callback(struct urb *pUrb)
697 // in Allowi as if it were protected by the char lock. In any case, most systems will 697 // in Allowi as if it were protected by the char lock. In any case, most systems will
698 // not be upset by char input during DMA... sigh. Needs sorting out. 698 // not be upset by char input during DMA... sigh. Needs sorting out.
699 if (bRestartCharInput) // may be out of date, but... 699 if (bRestartCharInput) // may be out of date, but...
700 Allowi(pdx, true); // ...Allowi tests a lock too. 700 Allowi(pdx); // ...Allowi tests a lock too.
701 dev_dbg(&pdx->interface->dev, "%s done", __func__); 701 dev_dbg(&pdx->interface->dev, "%s done", __func__);
702} 702}
703 703
@@ -1172,7 +1172,7 @@ static void ced_readchar_callback(struct urb *pUrb)
1172 pdx->bReadCharsPending = false; // No longer have a pending read 1172 pdx->bReadCharsPending = false; // No longer have a pending read
1173 spin_unlock(&pdx->charInLock); // already at irq level 1173 spin_unlock(&pdx->charInLock); // already at irq level
1174 1174
1175 Allowi(pdx, true); // see if we can do the next one 1175 Allowi(pdx); // see if we can do the next one
1176} 1176}
1177 1177
1178/**************************************************************************** 1178/****************************************************************************
@@ -1182,7 +1182,7 @@ static void ced_readchar_callback(struct urb *pUrb)
1182** we can pick up any inward transfers. This can be called in multiple contexts 1182** we can pick up any inward transfers. This can be called in multiple contexts
1183** so we use the irqsave version of the spinlock. 1183** so we use the irqsave version of the spinlock.
1184****************************************************************************/ 1184****************************************************************************/
1185int Allowi(DEVICE_EXTENSION * pdx, bool bInCallback) 1185int Allowi(DEVICE_EXTENSION * pdx)
1186{ 1186{
1187 int iReturn = U14ERR_NOERROR; 1187 int iReturn = U14ERR_NOERROR;
1188 unsigned long flags; 1188 unsigned long flags;
@@ -1211,9 +1211,7 @@ int Allowi(DEVICE_EXTENSION * pdx, bool bInCallback)
1211 pdx, pdx->bInterval); 1211 pdx, pdx->bInterval);
1212 pdx->pUrbCharIn->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; // short xfers are OK by default 1212 pdx->pUrbCharIn->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; // short xfers are OK by default
1213 usb_anchor_urb(pdx->pUrbCharIn, &pdx->submitted); // in case we need to kill it 1213 usb_anchor_urb(pdx->pUrbCharIn, &pdx->submitted); // in case we need to kill it
1214 iReturn = 1214 iReturn = usb_submit_urb(pdx->pUrbCharIn, GFP_ATOMIC);
1215 usb_submit_urb(pdx->pUrbCharIn,
1216 bInCallback ? GFP_ATOMIC : GFP_KERNEL);
1217 if (iReturn) { 1215 if (iReturn) {
1218 usb_unanchor_urb(pdx->pUrbCharIn); // remove from list of active Urbs 1216 usb_unanchor_urb(pdx->pUrbCharIn); // remove from list of active Urbs
1219 pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later 1217 pdx->bPipeError[nPipe] = 1; // Flag an error to be handled later
@@ -1393,10 +1391,8 @@ static int ced_probe(struct usb_interface *interface,
1393 1391
1394 // allocate memory for our device extension and initialize it 1392 // allocate memory for our device extension and initialize it
1395 pdx = kzalloc(sizeof(*pdx), GFP_KERNEL); 1393 pdx = kzalloc(sizeof(*pdx), GFP_KERNEL);
1396 if (!pdx) { 1394 if (!pdx)
1397 dev_err(&interface->dev, "Out of memory\n");
1398 goto error; 1395 goto error;
1399 }
1400 1396
1401 for (i = 0; i < MAX_TRANSAREAS; ++i) // Initialise the wait queues 1397 for (i = 0; i < MAX_TRANSAREAS; ++i) // Initialise the wait queues
1402 { 1398 {
diff --git a/drivers/staging/ced1401/usb1401.h b/drivers/staging/ced1401/usb1401.h
index adb5fa402bd4..8fc6958b6f08 100644
--- a/drivers/staging/ced1401/usb1401.h
+++ b/drivers/staging/ced1401/usb1401.h
@@ -204,7 +204,7 @@ typedef struct _DEVICE_EXTENSION
204 204
205/// Definitions of routimes used between compilation object files 205/// Definitions of routimes used between compilation object files
206// in usb1401.c 206// in usb1401.c
207extern int Allowi(DEVICE_EXTENSION* pdx, bool bInCallback); 207extern int Allowi(DEVICE_EXTENSION* pdx);
208extern int SendChars(DEVICE_EXTENSION* pdx); 208extern int SendChars(DEVICE_EXTENSION* pdx);
209extern void ced_draw_down(DEVICE_EXTENSION *pdx); 209extern void ced_draw_down(DEVICE_EXTENSION *pdx);
210extern int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent, 210extern int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent,
diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 36eec320569c..1967852eeb17 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1,7 +1,6 @@
1config COMEDI 1config COMEDI
2 tristate "Data acquisition support (comedi)" 2 tristate "Data acquisition support (comedi)"
3 depends on m 3 depends on m
4 depends on BROKEN || FRV || M32R || MN10300 || SUPERH || TILE || X86
5 ---help--- 4 ---help---
6 Enable support a wide range of data acquisition devices 5 Enable support a wide range of data acquisition devices
7 for Linux. 6 for Linux.
@@ -165,7 +164,7 @@ config COMEDI_PCL730
165 164
166config COMEDI_PCL812 165config COMEDI_PCL812
167 tristate "Advantech PCL-812/813 and ADlink ACL-8112/8113/8113/8216" 166 tristate "Advantech PCL-812/813 and ADlink ACL-8112/8113/8113/8216"
168 depends on VIRT_TO_BUS 167 depends on VIRT_TO_BUS && ISA_DMA_API
169 ---help--- 168 ---help---
170 Enable support for Advantech PCL-812/PG, PCL-813/B, ADLink 169 Enable support for Advantech PCL-812/PG, PCL-813/B, ADLink
171 ACL-8112DG/HG/PG, ACL-8113, ACL-8216, ICP DAS A-821PGH/PGL/PGL-NDA, 170 ACL-8112DG/HG/PG, ACL-8113, ACL-8216, ICP DAS A-821PGH/PGL/PGL-NDA,
@@ -176,7 +175,7 @@ config COMEDI_PCL812
176 175
177config COMEDI_PCL816 176config COMEDI_PCL816
178 tristate "Advantech PCL-814 and PCL-816 ISA card support" 177 tristate "Advantech PCL-814 and PCL-816 ISA card support"
179 depends on VIRT_TO_BUS 178 depends on VIRT_TO_BUS && ISA_DMA_API
180 ---help--- 179 ---help---
181 Enable support for Advantech PCL-814 and PCL-816 ISA cards 180 Enable support for Advantech PCL-814 and PCL-816 ISA cards
182 181
@@ -185,7 +184,7 @@ config COMEDI_PCL816
185 184
186config COMEDI_PCL818 185config COMEDI_PCL818
187 tristate "Advantech PCL-718 and PCL-818 ISA card support" 186 tristate "Advantech PCL-718 and PCL-818 ISA card support"
188 depends on VIRT_TO_BUS 187 depends on VIRT_TO_BUS && ISA_DMA_API
189 ---help--- 188 ---help---
190 Enable support for Advantech PCL-818 ISA cards 189 Enable support for Advantech PCL-818 ISA cards
191 PCL-818L, PCL-818H, PCL-818HD, PCL-818HG, PCL-818 and PCL-718 190 PCL-818L, PCL-818H, PCL-818HD, PCL-818HG, PCL-818 and PCL-718
@@ -275,10 +274,11 @@ config COMEDI_DAS08_ISA
275 DAS08/JR-16-AO, PC104-DAS08, DAS08/JR/16. 274 DAS08/JR-16-AO, PC104-DAS08, DAS08/JR/16.
276 275
277 To compile this driver as a module, choose M here: the module will be 276 To compile this driver as a module, choose M here: the module will be
278 called das08. 277 called das08_isa.
279 278
280config COMEDI_DAS16 279config COMEDI_DAS16
281 tristate "DAS-16 compatible ISA and PC/104 card support" 280 tristate "DAS-16 compatible ISA and PC/104 card support"
281 depends on ISA_DMA_API
282 select COMEDI_8255 282 select COMEDI_8255
283 select COMEDI_FC 283 select COMEDI_FC
284 ---help--- 284 ---help---
@@ -308,7 +308,7 @@ config COMEDI_DAS800
308 308
309config COMEDI_DAS1800 309config COMEDI_DAS1800
310 tristate "DAS1800 and compatible ISA card support" 310 tristate "DAS1800 and compatible ISA card support"
311 depends on VIRT_TO_BUS 311 depends on VIRT_TO_BUS && ISA_DMA_API
312 select COMEDI_FC 312 select COMEDI_FC
313 ---help--- 313 ---help---
314 Enable support for DAS1800 and compatible ISA cards 314 Enable support for DAS1800 and compatible ISA cards
@@ -373,7 +373,7 @@ config COMEDI_DT2817
373config COMEDI_DT282X 373config COMEDI_DT282X
374 tristate "Data Translation DT2821 series and DT-EZ ISA card support" 374 tristate "Data Translation DT2821 series and DT-EZ ISA card support"
375 select COMEDI_FC 375 select COMEDI_FC
376 depends on VIRT_TO_BUS 376 depends on VIRT_TO_BUS && ISA_DMA_API
377 ---help--- 377 ---help---
378 Enable support for Data Translation DT2821 series including DT-EZ 378 Enable support for Data Translation DT2821 series including DT-EZ
379 DT2821, DT2821-F-16SE, DT2821-F-8DI, DT2821-G-16SE, DT2821-G-8DI, 379 DT2821, DT2821-F-16SE, DT2821-F-8DI, DT2821-G-16SE, DT2821-G-8DI,
@@ -445,7 +445,7 @@ config COMEDI_ADQ12B
445config COMEDI_NI_AT_A2150 445config COMEDI_NI_AT_A2150
446 tristate "NI AT-A2150 ISA card support" 446 tristate "NI AT-A2150 ISA card support"
447 select COMEDI_FC 447 select COMEDI_FC
448 depends on VIRT_TO_BUS 448 depends on VIRT_TO_BUS && ISA_DMA_API
449 ---help--- 449 ---help---
450 Enable support for National Instruments AT-A2150 cards 450 Enable support for National Instruments AT-A2150 cards
451 451
@@ -542,11 +542,7 @@ menuconfig COMEDI_PCI_DRIVERS
542 bool "Comedi PCI drivers" 542 bool "Comedi PCI drivers"
543 depends on PCI 543 depends on PCI
544 ---help--- 544 ---help---
545 Enable comedi PCI drivers to be built 545 Enable support for comedi PCI drivers.
546
547 Note that the answer to this question won't directly affect the
548 kernel: saying N will just cause the configurator to skip all
549 the questions about PCI comedi drivers.
550 546
551if COMEDI_PCI_DRIVERS 547if COMEDI_PCI_DRIVERS
552 548
@@ -567,6 +563,13 @@ config COMEDI_8255_PCI
567 To compile this driver as a module, choose M here: the module will 563 To compile this driver as a module, choose M here: the module will
568 be called 8255_pci. 564 be called 8255_pci.
569 565
566config COMEDI_ADDI_WATCHDOG
567 tristate
568 ---help---
569 Provides support for the watchdog subdevice found on many ADDI-DATA
570 boards. This module will be automatically selected when needed. The
571 module will be called addi_watchdog.
572
570config COMEDI_ADDI_APCI_035 573config COMEDI_ADDI_APCI_035
571 tristate "ADDI-DATA APCI_035 support" 574 tristate "ADDI-DATA APCI_035 support"
572 ---help--- 575 ---help---
@@ -593,6 +596,7 @@ config COMEDI_ADDI_APCI_1500
593 596
594config COMEDI_ADDI_APCI_1516 597config COMEDI_ADDI_APCI_1516
595 tristate "ADDI-DATA APCI-1016/1516/2016 support" 598 tristate "ADDI-DATA APCI-1016/1516/2016 support"
599 select COMEDI_ADDI_WATCHDOG
596 ---help--- 600 ---help---
597 Enable support for ADDI-DATA APCI-1016, APCI-1516 and APCI-2016 boards. 601 Enable support for ADDI-DATA APCI-1016, APCI-1516 and APCI-2016 boards.
598 These are 16 channel, optically isolated, digital I/O boards. The 1516 602 These are 16 channel, optically isolated, digital I/O boards. The 1516
@@ -619,6 +623,7 @@ config COMEDI_ADDI_APCI_16XX
619 623
620config COMEDI_ADDI_APCI_2032 624config COMEDI_ADDI_APCI_2032
621 tristate "ADDI-DATA APCI_2032 support" 625 tristate "ADDI-DATA APCI_2032 support"
626 select COMEDI_ADDI_WATCHDOG
622 ---help--- 627 ---help---
623 Enable support for ADDI-DATA APCI_2032 cards 628 Enable support for ADDI-DATA APCI_2032 cards
624 629
@@ -627,6 +632,7 @@ config COMEDI_ADDI_APCI_2032
627 632
628config COMEDI_ADDI_APCI_2200 633config COMEDI_ADDI_APCI_2200
629 tristate "ADDI-DATA APCI_2200 support" 634 tristate "ADDI-DATA APCI_2200 support"
635 select COMEDI_ADDI_WATCHDOG
630 ---help--- 636 ---help---
631 Enable support for ADDI-DATA APCI_2200 cards 637 Enable support for ADDI-DATA APCI_2200 cards
632 638
@@ -796,7 +802,7 @@ config COMEDI_DAS08_PCI
796 Enable support for PCI DAS-08 cards. 802 Enable support for PCI DAS-08 cards.
797 803
798 To compile this driver as a module, choose M here: the module will be 804 To compile this driver as a module, choose M here: the module will be
799 called das08. 805 called das08_pci.
800 806
801config COMEDI_DT3000 807config COMEDI_DT3000
802 tristate "Data Translation DT3000 series support" 808 tristate "Data Translation DT3000 series support"
@@ -1084,11 +1090,7 @@ menuconfig COMEDI_PCMCIA_DRIVERS
1084 bool "Comedi PCMCIA drivers" 1090 bool "Comedi PCMCIA drivers"
1085 depends on PCMCIA 1091 depends on PCMCIA
1086 ---help--- 1092 ---help---
1087 Enable comedi PCMCIA and PCCARD drivers to be built 1093 Enable support for comedi PCMCIA drivers.
1088
1089 Note that the answer to this question won't directly affect the
1090 kernel: saying N will just cause the configurator to skip all
1091 the questions about PCMCIA comedi drivers.
1092 1094
1093if COMEDI_PCMCIA_DRIVERS 1095if COMEDI_PCMCIA_DRIVERS
1094 1096
@@ -1165,11 +1167,7 @@ menuconfig COMEDI_USB_DRIVERS
1165 bool "Comedi USB drivers" 1167 bool "Comedi USB drivers"
1166 depends on USB 1168 depends on USB
1167 ---help--- 1169 ---help---
1168 Enable comedi USB drivers to be built 1170 Enable support for comedi USB drivers.
1169
1170 Note that the answer to this question won't directly affect the
1171 kernel: saying N will just cause the configurator to skip all
1172 the questions about USB comedi drivers.
1173 1171
1174if COMEDI_USB_DRIVERS 1172if COMEDI_USB_DRIVERS
1175 1173
diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile
index 8dbd306fef88..e6dfc98f8c8e 100644
--- a/drivers/staging/comedi/Makefile
+++ b/drivers/staging/comedi/Makefile
@@ -1,11 +1,12 @@
1obj-$(CONFIG_COMEDI) += comedi.o 1comedi-y := comedi_fops.o range.o drivers.o \
2 comedi_buf.o
3comedi-$(CONFIG_COMEDI_PCI_DRIVERS) += comedi_pci.o
4comedi-$(CONFIG_COMEDI_PCMCIA_DRIVERS) += comedi_pcmcia.o
5comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o
6comedi-$(CONFIG_PROC_FS) += proc.o
7comedi-$(CONFIG_COMPAT) += comedi_compat32.o
2 8
3obj-$(CONFIG_COMEDI) += kcomedilib/ 9obj-$(CONFIG_COMEDI) += comedi.o
4obj-$(CONFIG_COMEDI) += drivers/
5 10
6comedi-y := \ 11obj-$(CONFIG_COMEDI) += kcomedilib/
7 comedi_fops.o \ 12obj-$(CONFIG_COMEDI) += drivers/
8 proc.o \
9 range.o \
10 drivers.o \
11 comedi_compat32.o \
diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index c8a8ca126127..4233605df30a 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -41,7 +41,17 @@
41 41
42/* number of config options in the config structure */ 42/* number of config options in the config structure */
43#define COMEDI_NDEVCONFOPTS 32 43#define COMEDI_NDEVCONFOPTS 32
44/*length of nth chunk of firmware data*/ 44
45/*
46 * NOTE: 'comedi_config --init-data' is deprecated
47 *
48 * The following indexes in the config options were used by
49 * comedi_config to pass firmware blobs from user space to the
50 * comedi drivers. The request_firmware() hotplug interface is
51 * now used by all comedi drivers instead.
52 */
53
54/* length of nth chunk of firmware data -*/
45#define COMEDI_DEVCONF_AUX_DATA3_LENGTH 25 55#define COMEDI_DEVCONF_AUX_DATA3_LENGTH 25
46#define COMEDI_DEVCONF_AUX_DATA2_LENGTH 26 56#define COMEDI_DEVCONF_AUX_DATA2_LENGTH 26
47#define COMEDI_DEVCONF_AUX_DATA1_LENGTH 27 57#define COMEDI_DEVCONF_AUX_DATA1_LENGTH 27
diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
new file mode 100644
index 000000000000..9b997ae67796
--- /dev/null
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -0,0 +1,415 @@
1/*
2 * comedi_buf.c
3 *
4 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include "comedidev.h"
23#include "comedi_internal.h"
24
25#ifdef PAGE_KERNEL_NOCACHE
26#define COMEDI_PAGE_PROTECTION PAGE_KERNEL_NOCACHE
27#else
28#define COMEDI_PAGE_PROTECTION PAGE_KERNEL
29#endif
30
31static void __comedi_buf_free(struct comedi_device *dev,
32 struct comedi_subdevice *s,
33 unsigned n_pages)
34{
35 struct comedi_async *async = s->async;
36 struct comedi_buf_page *buf;
37 unsigned i;
38
39 if (async->prealloc_buf) {
40 vunmap(async->prealloc_buf);
41 async->prealloc_buf = NULL;
42 async->prealloc_bufsz = 0;
43 }
44
45 if (!async->buf_page_list)
46 return;
47
48 for (i = 0; i < n_pages; ++i) {
49 buf = &async->buf_page_list[i];
50 if (buf->virt_addr) {
51 clear_bit(PG_reserved,
52 &(virt_to_page(buf->virt_addr)->flags));
53 if (s->async_dma_dir != DMA_NONE) {
54 dma_free_coherent(dev->hw_dev,
55 PAGE_SIZE,
56 buf->virt_addr,
57 buf->dma_addr);
58 } else {
59 free_page((unsigned long)buf->virt_addr);
60 }
61 }
62 }
63 vfree(async->buf_page_list);
64 async->buf_page_list = NULL;
65 async->n_buf_pages = 0;
66}
67
68static void __comedi_buf_alloc(struct comedi_device *dev,
69 struct comedi_subdevice *s,
70 unsigned n_pages)
71{
72 struct comedi_async *async = s->async;
73 struct page **pages = NULL;
74 struct comedi_buf_page *buf;
75 unsigned i;
76
77 async->buf_page_list = vzalloc(sizeof(*buf) * n_pages);
78 if (async->buf_page_list)
79 pages = vmalloc(sizeof(struct page *) * n_pages);
80
81 if (!pages)
82 return;
83
84 for (i = 0; i < n_pages; i++) {
85 buf = &async->buf_page_list[i];
86 if (s->async_dma_dir != DMA_NONE)
87 buf->virt_addr = dma_alloc_coherent(dev->hw_dev,
88 PAGE_SIZE,
89 &buf->dma_addr,
90 GFP_KERNEL |
91 __GFP_COMP);
92 else
93 buf->virt_addr = (void *)get_zeroed_page(GFP_KERNEL);
94 if (!buf->virt_addr)
95 break;
96
97 set_bit(PG_reserved, &(virt_to_page(buf->virt_addr)->flags));
98
99 pages[i] = virt_to_page(buf->virt_addr);
100 }
101
102 /* vmap the prealloc_buf if all the pages were allocated */
103 if (i == n_pages)
104 async->prealloc_buf = vmap(pages, n_pages, VM_MAP,
105 COMEDI_PAGE_PROTECTION);
106
107 vfree(pages);
108}
109
110int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
111 unsigned long new_size)
112{
113 struct comedi_async *async = s->async;
114
115 /* Round up new_size to multiple of PAGE_SIZE */
116 new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK;
117
118 /* if no change is required, do nothing */
119 if (async->prealloc_buf && async->prealloc_bufsz == new_size)
120 return 0;
121
122 /* deallocate old buffer */
123 __comedi_buf_free(dev, s, async->n_buf_pages);
124
125 /* allocate new buffer */
126 if (new_size) {
127 unsigned n_pages = new_size >> PAGE_SHIFT;
128
129 __comedi_buf_alloc(dev, s, n_pages);
130
131 if (!async->prealloc_buf) {
132 /* allocation failed */
133 __comedi_buf_free(dev, s, n_pages);
134 return -ENOMEM;
135 }
136 async->n_buf_pages = n_pages;
137 }
138 async->prealloc_bufsz = new_size;
139
140 return 0;
141}
142
143void comedi_buf_reset(struct comedi_async *async)
144{
145 async->buf_write_alloc_count = 0;
146 async->buf_write_count = 0;
147 async->buf_read_alloc_count = 0;
148 async->buf_read_count = 0;
149
150 async->buf_write_ptr = 0;
151 async->buf_read_ptr = 0;
152
153 async->cur_chan = 0;
154 async->scan_progress = 0;
155 async->munge_chan = 0;
156 async->munge_count = 0;
157 async->munge_ptr = 0;
158
159 async->events = 0;
160}
161
162static unsigned int comedi_buf_write_n_available(struct comedi_async *async)
163{
164 unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
165
166 return free_end - async->buf_write_alloc_count;
167}
168
169static unsigned int __comedi_buf_write_alloc(struct comedi_async *async,
170 unsigned int nbytes,
171 int strict)
172{
173 unsigned int available = comedi_buf_write_n_available(async);
174
175 if (nbytes > available)
176 nbytes = strict ? 0 : available;
177
178 async->buf_write_alloc_count += nbytes;
179
180 /*
181 * ensure the async buffer 'counts' are read and updated
182 * before we write data to the write-alloc'ed buffer space
183 */
184 smp_mb();
185
186 return nbytes;
187}
188
189/* allocates chunk for the writer from free buffer space */
190unsigned int comedi_buf_write_alloc(struct comedi_async *async,
191 unsigned int nbytes)
192{
193 return __comedi_buf_write_alloc(async, nbytes, 0);
194}
195EXPORT_SYMBOL(comedi_buf_write_alloc);
196
197/*
198 * munging is applied to data by core as it passes between user
199 * and kernel space
200 */
201static unsigned int comedi_buf_munge(struct comedi_async *async,
202 unsigned int num_bytes)
203{
204 struct comedi_subdevice *s = async->subdevice;
205 unsigned int count = 0;
206 const unsigned num_sample_bytes = bytes_per_sample(s);
207
208 if (!s->munge || (async->cmd.flags & CMDF_RAWDATA)) {
209 async->munge_count += num_bytes;
210 count = num_bytes;
211 } else {
212 /* don't munge partial samples */
213 num_bytes -= num_bytes % num_sample_bytes;
214 while (count < num_bytes) {
215 int block_size = num_bytes - count;
216 unsigned int buf_end;
217
218 buf_end = async->prealloc_bufsz - async->munge_ptr;
219 if (block_size > buf_end)
220 block_size = buf_end;
221
222 s->munge(s->device, s,
223 async->prealloc_buf + async->munge_ptr,
224 block_size, async->munge_chan);
225
226 /*
227 * ensure data is munged in buffer before the
228 * async buffer munge_count is incremented
229 */
230 smp_wmb();
231
232 async->munge_chan += block_size / num_sample_bytes;
233 async->munge_chan %= async->cmd.chanlist_len;
234 async->munge_count += block_size;
235 async->munge_ptr += block_size;
236 async->munge_ptr %= async->prealloc_bufsz;
237 count += block_size;
238 }
239 }
240
241 return count;
242}
243
244unsigned int comedi_buf_write_n_allocated(struct comedi_async *async)
245{
246 return async->buf_write_alloc_count - async->buf_write_count;
247}
248
249/* transfers a chunk from writer to filled buffer space */
250unsigned int comedi_buf_write_free(struct comedi_async *async,
251 unsigned int nbytes)
252{
253 unsigned int allocated = comedi_buf_write_n_allocated(async);
254
255 if (nbytes > allocated)
256 nbytes = allocated;
257
258 async->buf_write_count += nbytes;
259 async->buf_write_ptr += nbytes;
260 comedi_buf_munge(async, async->buf_write_count - async->munge_count);
261 if (async->buf_write_ptr >= async->prealloc_bufsz)
262 async->buf_write_ptr %= async->prealloc_bufsz;
263
264 return nbytes;
265}
266EXPORT_SYMBOL(comedi_buf_write_free);
267
268unsigned int comedi_buf_read_n_available(struct comedi_async *async)
269{
270 unsigned num_bytes;
271
272 if (!async)
273 return 0;
274
275 num_bytes = async->munge_count - async->buf_read_count;
276
277 /*
278 * ensure the async buffer 'counts' are read before we
279 * attempt to read data from the buffer
280 */
281 smp_rmb();
282
283 return num_bytes;
284}
285EXPORT_SYMBOL(comedi_buf_read_n_available);
286
287/* allocates a chunk for the reader from filled (and munged) buffer space */
288unsigned int comedi_buf_read_alloc(struct comedi_async *async,
289 unsigned int nbytes)
290{
291 unsigned int available;
292
293 available = async->munge_count - async->buf_read_alloc_count;
294 if (nbytes > available)
295 nbytes = available;
296
297 async->buf_read_alloc_count += nbytes;
298
299 /*
300 * ensure the async buffer 'counts' are read before we
301 * attempt to read data from the read-alloc'ed buffer space
302 */
303 smp_rmb();
304
305 return nbytes;
306}
307EXPORT_SYMBOL(comedi_buf_read_alloc);
308
309static unsigned int comedi_buf_read_n_allocated(struct comedi_async *async)
310{
311 return async->buf_read_alloc_count - async->buf_read_count;
312}
313
314/* transfers control of a chunk from reader to free buffer space */
315unsigned int comedi_buf_read_free(struct comedi_async *async,
316 unsigned int nbytes)
317{
318 unsigned int allocated;
319
320 /*
321 * ensure data has been read out of buffer before
322 * the async read count is incremented
323 */
324 smp_mb();
325
326 allocated = comedi_buf_read_n_allocated(async);
327 if (nbytes > allocated)
328 nbytes = allocated;
329
330 async->buf_read_count += nbytes;
331 async->buf_read_ptr += nbytes;
332 async->buf_read_ptr %= async->prealloc_bufsz;
333 return nbytes;
334}
335EXPORT_SYMBOL(comedi_buf_read_free);
336
337int comedi_buf_put(struct comedi_async *async, short x)
338{
339 unsigned int n = __comedi_buf_write_alloc(async, sizeof(short), 1);
340
341 if (n < sizeof(short)) {
342 async->events |= COMEDI_CB_ERROR;
343 return 0;
344 }
345 *(short *)(async->prealloc_buf + async->buf_write_ptr) = x;
346 comedi_buf_write_free(async, sizeof(short));
347 return 1;
348}
349EXPORT_SYMBOL(comedi_buf_put);
350
351int comedi_buf_get(struct comedi_async *async, short *x)
352{
353 unsigned int n = comedi_buf_read_n_available(async);
354
355 if (n < sizeof(short))
356 return 0;
357 comedi_buf_read_alloc(async, sizeof(short));
358 *x = *(short *)(async->prealloc_buf + async->buf_read_ptr);
359 comedi_buf_read_free(async, sizeof(short));
360 return 1;
361}
362EXPORT_SYMBOL(comedi_buf_get);
363
364void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset,
365 const void *data, unsigned int num_bytes)
366{
367 unsigned int write_ptr = async->buf_write_ptr + offset;
368
369 if (write_ptr >= async->prealloc_bufsz)
370 write_ptr %= async->prealloc_bufsz;
371
372 while (num_bytes) {
373 unsigned int block_size;
374
375 if (write_ptr + num_bytes > async->prealloc_bufsz)
376 block_size = async->prealloc_bufsz - write_ptr;
377 else
378 block_size = num_bytes;
379
380 memcpy(async->prealloc_buf + write_ptr, data, block_size);
381
382 data += block_size;
383 num_bytes -= block_size;
384
385 write_ptr = 0;
386 }
387}
388EXPORT_SYMBOL(comedi_buf_memcpy_to);
389
390void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
391 void *dest, unsigned int nbytes)
392{
393 void *src;
394 unsigned int read_ptr = async->buf_read_ptr + offset;
395
396 if (read_ptr >= async->prealloc_bufsz)
397 read_ptr %= async->prealloc_bufsz;
398
399 while (nbytes) {
400 unsigned int block_size;
401
402 src = async->prealloc_buf + read_ptr;
403
404 if (nbytes >= async->prealloc_bufsz - read_ptr)
405 block_size = async->prealloc_bufsz - read_ptr;
406 else
407 block_size = nbytes;
408
409 memcpy(dest, src, block_size);
410 nbytes -= block_size;
411 dest += block_size;
412 read_ptr = 0;
413 }
414}
415EXPORT_SYMBOL(comedi_buf_memcpy_from);
diff --git a/drivers/staging/comedi/comedi_compat32.c b/drivers/staging/comedi/comedi_compat32.c
index 4b7cbfad1d74..ad208cdd53d4 100644
--- a/drivers/staging/comedi/comedi_compat32.c
+++ b/drivers/staging/comedi/comedi_compat32.c
@@ -30,8 +30,6 @@
30#include "comedi.h" 30#include "comedi.h"
31#include "comedi_compat32.h" 31#include "comedi_compat32.h"
32 32
33#ifdef CONFIG_COMPAT
34
35#define COMEDI32_CHANINFO _IOR(CIO, 3, struct comedi32_chaninfo_struct) 33#define COMEDI32_CHANINFO _IOR(CIO, 3, struct comedi32_chaninfo_struct)
36#define COMEDI32_RANGEINFO _IOR(CIO, 8, struct comedi32_rangeinfo_struct) 34#define COMEDI32_RANGEINFO _IOR(CIO, 8, struct comedi32_rangeinfo_struct)
37/* N.B. COMEDI32_CMD and COMEDI_CMD ought to use _IOWR, not _IOR. 35/* N.B. COMEDI32_CMD and COMEDI_CMD ought to use _IOWR, not _IOR.
@@ -460,5 +458,3 @@ long comedi_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
460{ 458{
461 return raw_ioctl(file, cmd, arg); 459 return raw_ioctl(file, cmd, arg);
462} 460}
463
464#endif /* CONFIG_COMPAT */
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 9b038e4a7e71..195d56d8a1ee 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -49,10 +49,6 @@
49 49
50#include "comedi_internal.h" 50#include "comedi_internal.h"
51 51
52MODULE_AUTHOR("http://www.comedi.org");
53MODULE_DESCRIPTION("Comedi core module");
54MODULE_LICENSE("GPL");
55
56#ifdef CONFIG_COMEDI_DEBUG 52#ifdef CONFIG_COMEDI_DEBUG
57int comedi_debug; 53int comedi_debug;
58EXPORT_SYMBOL(comedi_debug); 54EXPORT_SYMBOL(comedi_debug);
@@ -62,11 +58,6 @@ MODULE_PARM_DESC(comedi_debug,
62 ); 58 );
63#endif 59#endif
64 60
65bool comedi_autoconfig = 1;
66module_param(comedi_autoconfig, bool, S_IRUGO);
67MODULE_PARM_DESC(comedi_autoconfig,
68 "enable drivers to auto-configure comedi devices (default 1)");
69
70static int comedi_num_legacy_minors; 61static int comedi_num_legacy_minors;
71module_param(comedi_num_legacy_minors, int, S_IRUGO); 62module_param(comedi_num_legacy_minors, int, S_IRUGO);
72MODULE_PARM_DESC(comedi_num_legacy_minors, 63MODULE_PARM_DESC(comedi_num_legacy_minors,
@@ -86,17 +77,58 @@ MODULE_PARM_DESC(comedi_default_buf_maxsize_kb,
86 "default maximum size of asynchronous buffer in KiB (default " 77 "default maximum size of asynchronous buffer in KiB (default "
87 __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB) ")"); 78 __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB) ")");
88 79
80struct comedi_file_info {
81 struct comedi_device *device;
82 struct comedi_subdevice *read_subdevice;
83 struct comedi_subdevice *write_subdevice;
84 struct device *hardware_device;
85};
86
89static DEFINE_SPINLOCK(comedi_file_info_table_lock); 87static DEFINE_SPINLOCK(comedi_file_info_table_lock);
90static struct comedi_device_file_info 88static struct comedi_file_info *comedi_file_info_table[COMEDI_NUM_MINORS];
91*comedi_file_info_table[COMEDI_NUM_MINORS];
92 89
93static void do_become_nonbusy(struct comedi_device *dev, 90static struct comedi_file_info *comedi_file_info_from_minor(unsigned minor)
94 struct comedi_subdevice *s); 91{
95static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s); 92 struct comedi_file_info *info;
93
94 BUG_ON(minor >= COMEDI_NUM_MINORS);
95 spin_lock(&comedi_file_info_table_lock);
96 info = comedi_file_info_table[minor];
97 spin_unlock(&comedi_file_info_table_lock);
98 return info;
99}
100
101static struct comedi_device *
102comedi_dev_from_file_info(struct comedi_file_info *info)
103{
104 return info ? info->device : NULL;
105}
106
107struct comedi_device *comedi_dev_from_minor(unsigned minor)
108{
109 return comedi_dev_from_file_info(comedi_file_info_from_minor(minor));
110}
111EXPORT_SYMBOL_GPL(comedi_dev_from_minor);
96 112
97static int comedi_fasync(int fd, struct file *file, int on); 113static struct comedi_subdevice *
114comedi_read_subdevice(const struct comedi_file_info *info)
115{
116 if (info->read_subdevice)
117 return info->read_subdevice;
118 if (info->device)
119 return info->device->read_subdev;
120 return NULL;
121}
98 122
99static int is_device_busy(struct comedi_device *dev); 123static struct comedi_subdevice *
124comedi_write_subdevice(const struct comedi_file_info *info)
125{
126 if (info->write_subdevice)
127 return info->write_subdevice;
128 if (info->device)
129 return info->device->write_subdev;
130 return NULL;
131}
100 132
101static int resize_async_buffer(struct comedi_device *dev, 133static int resize_async_buffer(struct comedi_device *dev,
102 struct comedi_subdevice *s, 134 struct comedi_subdevice *s,
@@ -134,7 +166,7 @@ static int resize_async_buffer(struct comedi_device *dev,
134 } 166 }
135 167
136 DPRINTK("comedi%i subd %d buffer resized to %i bytes\n", 168 DPRINTK("comedi%i subd %d buffer resized to %i bytes\n",
137 dev->minor, (int)(s - dev->subdevices), async->prealloc_bufsz); 169 dev->minor, s->index, async->prealloc_bufsz);
138 return 0; 170 return 0;
139} 171}
140 172
@@ -143,8 +175,8 @@ static int resize_async_buffer(struct comedi_device *dev,
143static ssize_t show_max_read_buffer_kb(struct device *dev, 175static ssize_t show_max_read_buffer_kb(struct device *dev,
144 struct device_attribute *attr, char *buf) 176 struct device_attribute *attr, char *buf)
145{ 177{
146 struct comedi_device_file_info *info = dev_get_drvdata(dev); 178 struct comedi_file_info *info = dev_get_drvdata(dev);
147 struct comedi_subdevice *s = comedi_get_read_subdevice(info); 179 struct comedi_subdevice *s = comedi_read_subdevice(info);
148 unsigned int size = 0; 180 unsigned int size = 0;
149 181
150 mutex_lock(&info->device->mutex); 182 mutex_lock(&info->device->mutex);
@@ -159,8 +191,8 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
159 struct device_attribute *attr, 191 struct device_attribute *attr,
160 const char *buf, size_t count) 192 const char *buf, size_t count)
161{ 193{
162 struct comedi_device_file_info *info = dev_get_drvdata(dev); 194 struct comedi_file_info *info = dev_get_drvdata(dev);
163 struct comedi_subdevice *s = comedi_get_read_subdevice(info); 195 struct comedi_subdevice *s = comedi_read_subdevice(info);
164 unsigned int size; 196 unsigned int size;
165 int err; 197 int err;
166 198
@@ -184,8 +216,8 @@ static ssize_t store_max_read_buffer_kb(struct device *dev,
184static ssize_t show_read_buffer_kb(struct device *dev, 216static ssize_t show_read_buffer_kb(struct device *dev,
185 struct device_attribute *attr, char *buf) 217 struct device_attribute *attr, char *buf)
186{ 218{
187 struct comedi_device_file_info *info = dev_get_drvdata(dev); 219 struct comedi_file_info *info = dev_get_drvdata(dev);
188 struct comedi_subdevice *s = comedi_get_read_subdevice(info); 220 struct comedi_subdevice *s = comedi_read_subdevice(info);
189 unsigned int size = 0; 221 unsigned int size = 0;
190 222
191 mutex_lock(&info->device->mutex); 223 mutex_lock(&info->device->mutex);
@@ -200,8 +232,8 @@ static ssize_t store_read_buffer_kb(struct device *dev,
200 struct device_attribute *attr, 232 struct device_attribute *attr,
201 const char *buf, size_t count) 233 const char *buf, size_t count)
202{ 234{
203 struct comedi_device_file_info *info = dev_get_drvdata(dev); 235 struct comedi_file_info *info = dev_get_drvdata(dev);
204 struct comedi_subdevice *s = comedi_get_read_subdevice(info); 236 struct comedi_subdevice *s = comedi_read_subdevice(info);
205 unsigned int size; 237 unsigned int size;
206 int err; 238 int err;
207 239
@@ -226,8 +258,8 @@ static ssize_t show_max_write_buffer_kb(struct device *dev,
226 struct device_attribute *attr, 258 struct device_attribute *attr,
227 char *buf) 259 char *buf)
228{ 260{
229 struct comedi_device_file_info *info = dev_get_drvdata(dev); 261 struct comedi_file_info *info = dev_get_drvdata(dev);
230 struct comedi_subdevice *s = comedi_get_write_subdevice(info); 262 struct comedi_subdevice *s = comedi_write_subdevice(info);
231 unsigned int size = 0; 263 unsigned int size = 0;
232 264
233 mutex_lock(&info->device->mutex); 265 mutex_lock(&info->device->mutex);
@@ -242,8 +274,8 @@ static ssize_t store_max_write_buffer_kb(struct device *dev,
242 struct device_attribute *attr, 274 struct device_attribute *attr,
243 const char *buf, size_t count) 275 const char *buf, size_t count)
244{ 276{
245 struct comedi_device_file_info *info = dev_get_drvdata(dev); 277 struct comedi_file_info *info = dev_get_drvdata(dev);
246 struct comedi_subdevice *s = comedi_get_write_subdevice(info); 278 struct comedi_subdevice *s = comedi_write_subdevice(info);
247 unsigned int size; 279 unsigned int size;
248 int err; 280 int err;
249 281
@@ -267,8 +299,8 @@ static ssize_t store_max_write_buffer_kb(struct device *dev,
267static ssize_t show_write_buffer_kb(struct device *dev, 299static ssize_t show_write_buffer_kb(struct device *dev,
268 struct device_attribute *attr, char *buf) 300 struct device_attribute *attr, char *buf)
269{ 301{
270 struct comedi_device_file_info *info = dev_get_drvdata(dev); 302 struct comedi_file_info *info = dev_get_drvdata(dev);
271 struct comedi_subdevice *s = comedi_get_write_subdevice(info); 303 struct comedi_subdevice *s = comedi_write_subdevice(info);
272 unsigned int size = 0; 304 unsigned int size = 0;
273 305
274 mutex_lock(&info->device->mutex); 306 mutex_lock(&info->device->mutex);
@@ -283,8 +315,8 @@ static ssize_t store_write_buffer_kb(struct device *dev,
283 struct device_attribute *attr, 315 struct device_attribute *attr,
284 const char *buf, size_t count) 316 const char *buf, size_t count)
285{ 317{
286 struct comedi_device_file_info *info = dev_get_drvdata(dev); 318 struct comedi_file_info *info = dev_get_drvdata(dev);
287 struct comedi_subdevice *s = comedi_get_write_subdevice(info); 319 struct comedi_subdevice *s = comedi_write_subdevice(info);
288 unsigned int size; 320 unsigned int size;
289 int err; 321 int err;
290 322
@@ -317,6 +349,103 @@ static struct device_attribute comedi_dev_attrs[] = {
317 __ATTR_NULL 349 __ATTR_NULL
318}; 350};
319 351
352static void comedi_set_subdevice_runflags(struct comedi_subdevice *s,
353 unsigned mask, unsigned bits)
354{
355 unsigned long flags;
356
357 spin_lock_irqsave(&s->spin_lock, flags);
358 s->runflags &= ~mask;
359 s->runflags |= (bits & mask);
360 spin_unlock_irqrestore(&s->spin_lock, flags);
361}
362
363static unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s)
364{
365 unsigned long flags;
366 unsigned runflags;
367
368 spin_lock_irqsave(&s->spin_lock, flags);
369 runflags = s->runflags;
370 spin_unlock_irqrestore(&s->spin_lock, flags);
371 return runflags;
372}
373
374bool comedi_is_subdevice_running(struct comedi_subdevice *s)
375{
376 unsigned runflags = comedi_get_subdevice_runflags(s);
377
378 return (runflags & SRF_RUNNING) ? true : false;
379}
380EXPORT_SYMBOL_GPL(comedi_is_subdevice_running);
381
382static bool comedi_is_subdevice_in_error(struct comedi_subdevice *s)
383{
384 unsigned runflags = comedi_get_subdevice_runflags(s);
385
386 return (runflags & SRF_ERROR) ? true : false;
387}
388
389static bool comedi_is_subdevice_idle(struct comedi_subdevice *s)
390{
391 unsigned runflags = comedi_get_subdevice_runflags(s);
392
393 return (runflags & (SRF_ERROR | SRF_RUNNING)) ? false : true;
394}
395
396/*
397 This function restores a subdevice to an idle state.
398 */
399static void do_become_nonbusy(struct comedi_device *dev,
400 struct comedi_subdevice *s)
401{
402 struct comedi_async *async = s->async;
403
404 comedi_set_subdevice_runflags(s, SRF_RUNNING, 0);
405 if (async) {
406 comedi_buf_reset(async);
407 async->inttrig = NULL;
408 kfree(async->cmd.chanlist);
409 async->cmd.chanlist = NULL;
410 } else {
411 dev_err(dev->class_dev,
412 "BUG: (?) do_become_nonbusy called with async=NULL\n");
413 }
414
415 s->busy = NULL;
416}
417
418static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
419{
420 int ret = 0;
421
422 if (comedi_is_subdevice_running(s) && s->cancel)
423 ret = s->cancel(dev, s);
424
425 do_become_nonbusy(dev, s);
426
427 return ret;
428}
429
430static int is_device_busy(struct comedi_device *dev)
431{
432 struct comedi_subdevice *s;
433 int i;
434
435 if (!dev->attached)
436 return 0;
437
438 for (i = 0; i < dev->n_subdevices; i++) {
439 s = &dev->subdevices[i];
440 if (s->busy)
441 return 1;
442 if (s->async && s->async->mmap_count)
443 return 1;
444 }
445
446 return 0;
447}
448
320/* 449/*
321 COMEDI_DEVCONFIG 450 COMEDI_DEVCONFIG
322 device config ioctl 451 device config ioctl
@@ -335,8 +464,6 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
335{ 464{
336 struct comedi_devconfig it; 465 struct comedi_devconfig it;
337 int ret; 466 int ret;
338 unsigned char *aux_data = NULL;
339 int aux_len;
340 467
341 if (!capable(CAP_SYS_ADMIN)) 468 if (!capable(CAP_SYS_ADMIN))
342 return -EPERM; 469 return -EPERM;
@@ -352,36 +479,15 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
352 return 0; 479 return 0;
353 } 480 }
354 481
355 if (copy_from_user(&it, arg, sizeof(struct comedi_devconfig))) 482 if (copy_from_user(&it, arg, sizeof(it)))
356 return -EFAULT; 483 return -EFAULT;
357 484
358 it.board_name[COMEDI_NAMELEN - 1] = 0; 485 it.board_name[COMEDI_NAMELEN - 1] = 0;
359 486
360 if (comedi_aux_data(it.options, 0) && 487 if (it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) {
361 it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]) { 488 dev_warn(dev->class_dev,
362 int bit_shift; 489 "comedi_config --init_data is deprecated\n");
363 aux_len = it.options[COMEDI_DEVCONF_AUX_DATA_LENGTH]; 490 return -EINVAL;
364 if (aux_len < 0)
365 return -EFAULT;
366
367 aux_data = vmalloc(aux_len);
368 if (!aux_data)
369 return -ENOMEM;
370
371 if (copy_from_user(aux_data,
372 (unsigned char __user *
373 )comedi_aux_data(it.options, 0), aux_len)) {
374 vfree(aux_data);
375 return -EFAULT;
376 }
377 it.options[COMEDI_DEVCONF_AUX_DATA_LO] =
378 (unsigned long)aux_data;
379 if (sizeof(void *) > sizeof(int)) {
380 bit_shift = sizeof(int) * 8;
381 it.options[COMEDI_DEVCONF_AUX_DATA_HI] =
382 ((unsigned long)aux_data) >> bit_shift;
383 } else
384 it.options[COMEDI_DEVCONF_AUX_DATA_HI] = 0;
385 } 491 }
386 492
387 ret = comedi_device_attach(dev, &it); 493 ret = comedi_device_attach(dev, &it);
@@ -392,9 +498,6 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
392 } 498 }
393 } 499 }
394 500
395 if (aux_data)
396 vfree(aux_data);
397
398 return ret; 501 return ret;
399} 502}
400 503
@@ -420,7 +523,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev,
420 struct comedi_subdevice *s; 523 struct comedi_subdevice *s;
421 int retval = 0; 524 int retval = 0;
422 525
423 if (copy_from_user(&bc, arg, sizeof(struct comedi_bufconfig))) 526 if (copy_from_user(&bc, arg, sizeof(bc)))
424 return -EFAULT; 527 return -EFAULT;
425 528
426 if (bc.subdevice >= dev->n_subdevices || bc.subdevice < 0) 529 if (bc.subdevice >= dev->n_subdevices || bc.subdevice < 0)
@@ -453,7 +556,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev,
453 bc.maximum_size = async->max_bufsize; 556 bc.maximum_size = async->max_bufsize;
454 557
455copyback: 558copyback:
456 if (copy_to_user(arg, &bc, sizeof(struct comedi_bufconfig))) 559 if (copy_to_user(arg, &bc, sizeof(bc)))
457 return -EFAULT; 560 return -EFAULT;
458 561
459 return 0; 562 return 0;
@@ -477,14 +580,10 @@ static int do_devinfo_ioctl(struct comedi_device *dev,
477 struct comedi_devinfo __user *arg, 580 struct comedi_devinfo __user *arg,
478 struct file *file) 581 struct file *file)
479{ 582{
480 struct comedi_devinfo devinfo;
481 const unsigned minor = iminor(file->f_dentry->d_inode); 583 const unsigned minor = iminor(file->f_dentry->d_inode);
482 struct comedi_device_file_info *dev_file_info = 584 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
483 comedi_get_device_file_info(minor); 585 struct comedi_subdevice *s;
484 struct comedi_subdevice *read_subdev = 586 struct comedi_devinfo devinfo;
485 comedi_get_read_subdevice(dev_file_info);
486 struct comedi_subdevice *write_subdev =
487 comedi_get_write_subdevice(dev_file_info);
488 587
489 memset(&devinfo, 0, sizeof(devinfo)); 588 memset(&devinfo, 0, sizeof(devinfo));
490 589
@@ -494,17 +593,19 @@ static int do_devinfo_ioctl(struct comedi_device *dev,
494 strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN); 593 strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN);
495 strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN); 594 strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN);
496 595
497 if (read_subdev) 596 s = comedi_read_subdevice(info);
498 devinfo.read_subdevice = read_subdev - dev->subdevices; 597 if (s)
598 devinfo.read_subdevice = s->index;
499 else 599 else
500 devinfo.read_subdevice = -1; 600 devinfo.read_subdevice = -1;
501 601
502 if (write_subdev) 602 s = comedi_write_subdevice(info);
503 devinfo.write_subdevice = write_subdev - dev->subdevices; 603 if (s)
604 devinfo.write_subdevice = s->index;
504 else 605 else
505 devinfo.write_subdevice = -1; 606 devinfo.write_subdevice = -1;
506 607
507 if (copy_to_user(arg, &devinfo, sizeof(struct comedi_devinfo))) 608 if (copy_to_user(arg, &devinfo, sizeof(devinfo)))
508 return -EFAULT; 609 return -EFAULT;
509 610
510 return 0; 611 return 0;
@@ -531,9 +632,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev,
531 struct comedi_subdinfo *tmp, *us; 632 struct comedi_subdinfo *tmp, *us;
532 struct comedi_subdevice *s; 633 struct comedi_subdevice *s;
533 634
534 tmp = 635 tmp = kcalloc(dev->n_subdevices, sizeof(*tmp), GFP_KERNEL);
535 kcalloc(dev->n_subdevices, sizeof(struct comedi_subdinfo),
536 GFP_KERNEL);
537 if (!tmp) 636 if (!tmp)
538 return -ENOMEM; 637 return -ENOMEM;
539 638
@@ -545,7 +644,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev,
545 us->type = s->type; 644 us->type = s->type;
546 us->n_chan = s->n_chan; 645 us->n_chan = s->n_chan;
547 us->subd_flags = s->subdev_flags; 646 us->subd_flags = s->subdev_flags;
548 if (comedi_get_subdevice_runflags(s) & SRF_RUNNING) 647 if (comedi_is_subdevice_running(s))
549 us->subd_flags |= SDF_RUNNING; 648 us->subd_flags |= SDF_RUNNING;
550#define TIMER_nanosec 5 /* backwards compatibility */ 649#define TIMER_nanosec 5 /* backwards compatibility */
551 us->timer_type = TIMER_nanosec; 650 us->timer_type = TIMER_nanosec;
@@ -584,8 +683,7 @@ static int do_subdinfo_ioctl(struct comedi_device *dev,
584 us->settling_time_0 = s->settling_time_0; 683 us->settling_time_0 = s->settling_time_0;
585 } 684 }
586 685
587 ret = copy_to_user(arg, tmp, 686 ret = copy_to_user(arg, tmp, dev->n_subdevices * sizeof(*tmp));
588 dev->n_subdevices * sizeof(struct comedi_subdinfo));
589 687
590 kfree(tmp); 688 kfree(tmp);
591 689
@@ -612,7 +710,7 @@ static int do_chaninfo_ioctl(struct comedi_device *dev,
612 struct comedi_subdevice *s; 710 struct comedi_subdevice *s;
613 struct comedi_chaninfo it; 711 struct comedi_chaninfo it;
614 712
615 if (copy_from_user(&it, arg, sizeof(struct comedi_chaninfo))) 713 if (copy_from_user(&it, arg, sizeof(it)))
616 return -EFAULT; 714 return -EFAULT;
617 715
618 if (it.subdev >= dev->n_subdevices) 716 if (it.subdev >= dev->n_subdevices)
@@ -679,7 +777,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
679 struct comedi_subdevice *s; 777 struct comedi_subdevice *s;
680 struct comedi_async *async; 778 struct comedi_async *async;
681 779
682 if (copy_from_user(&bi, arg, sizeof(struct comedi_bufinfo))) 780 if (copy_from_user(&bi, arg, sizeof(bi)))
683 return -EFAULT; 781 return -EFAULT;
684 782
685 if (bi.subdevice >= dev->n_subdevices || bi.subdevice < 0) 783 if (bi.subdevice >= dev->n_subdevices || bi.subdevice < 0)
@@ -714,9 +812,8 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
714 bi.bytes_read = comedi_buf_read_alloc(async, bi.bytes_read); 812 bi.bytes_read = comedi_buf_read_alloc(async, bi.bytes_read);
715 comedi_buf_read_free(async, bi.bytes_read); 813 comedi_buf_read_free(async, bi.bytes_read);
716 814
717 if (!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | 815 if (comedi_is_subdevice_idle(s) &&
718 SRF_RUNNING)) 816 async->buf_write_count == async->buf_read_count) {
719 && async->buf_write_count == async->buf_read_count) {
720 do_become_nonbusy(dev, s); 817 do_become_nonbusy(dev, s);
721 } 818 }
722 } 819 }
@@ -734,103 +831,12 @@ copyback_position:
734 bi.buf_read_ptr = async->buf_read_ptr; 831 bi.buf_read_ptr = async->buf_read_ptr;
735 832
736copyback: 833copyback:
737 if (copy_to_user(arg, &bi, sizeof(struct comedi_bufinfo))) 834 if (copy_to_user(arg, &bi, sizeof(bi)))
738 return -EFAULT; 835 return -EFAULT;
739 836
740 return 0; 837 return 0;
741} 838}
742 839
743static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
744 unsigned int *data, void *file);
745/*
746 * COMEDI_INSNLIST
747 * synchronous instructions
748 *
749 * arg:
750 * pointer to sync cmd structure
751 *
752 * reads:
753 * sync cmd struct at arg
754 * instruction list
755 * data (for writes)
756 *
757 * writes:
758 * data (for reads)
759 */
760/* arbitrary limits */
761#define MAX_SAMPLES 256
762static int do_insnlist_ioctl(struct comedi_device *dev,
763 struct comedi_insnlist __user *arg, void *file)
764{
765 struct comedi_insnlist insnlist;
766 struct comedi_insn *insns = NULL;
767 unsigned int *data = NULL;
768 int i = 0;
769 int ret = 0;
770
771 if (copy_from_user(&insnlist, arg, sizeof(struct comedi_insnlist)))
772 return -EFAULT;
773
774 data = kmalloc(sizeof(unsigned int) * MAX_SAMPLES, GFP_KERNEL);
775 if (!data) {
776 DPRINTK("kmalloc failed\n");
777 ret = -ENOMEM;
778 goto error;
779 }
780
781 insns =
782 kcalloc(insnlist.n_insns, sizeof(struct comedi_insn), GFP_KERNEL);
783 if (!insns) {
784 DPRINTK("kmalloc failed\n");
785 ret = -ENOMEM;
786 goto error;
787 }
788
789 if (copy_from_user(insns, insnlist.insns,
790 sizeof(struct comedi_insn) * insnlist.n_insns)) {
791 DPRINTK("copy_from_user failed\n");
792 ret = -EFAULT;
793 goto error;
794 }
795
796 for (i = 0; i < insnlist.n_insns; i++) {
797 if (insns[i].n > MAX_SAMPLES) {
798 DPRINTK("number of samples too large\n");
799 ret = -EINVAL;
800 goto error;
801 }
802 if (insns[i].insn & INSN_MASK_WRITE) {
803 if (copy_from_user(data, insns[i].data,
804 insns[i].n * sizeof(unsigned int))) {
805 DPRINTK("copy_from_user failed\n");
806 ret = -EFAULT;
807 goto error;
808 }
809 }
810 ret = parse_insn(dev, insns + i, data, file);
811 if (ret < 0)
812 goto error;
813 if (insns[i].insn & INSN_MASK_READ) {
814 if (copy_to_user(insns[i].data, data,
815 insns[i].n * sizeof(unsigned int))) {
816 DPRINTK("copy_to_user failed\n");
817 ret = -EFAULT;
818 goto error;
819 }
820 }
821 if (need_resched())
822 schedule();
823 }
824
825error:
826 kfree(insns);
827 kfree(data);
828
829 if (ret < 0)
830 return ret;
831 return i;
832}
833
834static int check_insn_config_length(struct comedi_insn *insn, 840static int check_insn_config_length(struct comedi_insn *insn,
835 unsigned int *data) 841 unsigned int *data)
836{ 842{
@@ -1062,6 +1068,94 @@ out:
1062} 1068}
1063 1069
1064/* 1070/*
1071 * COMEDI_INSNLIST
1072 * synchronous instructions
1073 *
1074 * arg:
1075 * pointer to sync cmd structure
1076 *
1077 * reads:
1078 * sync cmd struct at arg
1079 * instruction list
1080 * data (for writes)
1081 *
1082 * writes:
1083 * data (for reads)
1084 */
1085/* arbitrary limits */
1086#define MAX_SAMPLES 256
1087static int do_insnlist_ioctl(struct comedi_device *dev,
1088 struct comedi_insnlist __user *arg, void *file)
1089{
1090 struct comedi_insnlist insnlist;
1091 struct comedi_insn *insns = NULL;
1092 unsigned int *data = NULL;
1093 int i = 0;
1094 int ret = 0;
1095
1096 if (copy_from_user(&insnlist, arg, sizeof(insnlist)))
1097 return -EFAULT;
1098
1099 data = kmalloc(sizeof(unsigned int) * MAX_SAMPLES, GFP_KERNEL);
1100 if (!data) {
1101 DPRINTK("kmalloc failed\n");
1102 ret = -ENOMEM;
1103 goto error;
1104 }
1105
1106 insns = kcalloc(insnlist.n_insns, sizeof(*insns), GFP_KERNEL);
1107 if (!insns) {
1108 DPRINTK("kmalloc failed\n");
1109 ret = -ENOMEM;
1110 goto error;
1111 }
1112
1113 if (copy_from_user(insns, insnlist.insns,
1114 sizeof(*insns) * insnlist.n_insns)) {
1115 DPRINTK("copy_from_user failed\n");
1116 ret = -EFAULT;
1117 goto error;
1118 }
1119
1120 for (i = 0; i < insnlist.n_insns; i++) {
1121 if (insns[i].n > MAX_SAMPLES) {
1122 DPRINTK("number of samples too large\n");
1123 ret = -EINVAL;
1124 goto error;
1125 }
1126 if (insns[i].insn & INSN_MASK_WRITE) {
1127 if (copy_from_user(data, insns[i].data,
1128 insns[i].n * sizeof(unsigned int))) {
1129 DPRINTK("copy_from_user failed\n");
1130 ret = -EFAULT;
1131 goto error;
1132 }
1133 }
1134 ret = parse_insn(dev, insns + i, data, file);
1135 if (ret < 0)
1136 goto error;
1137 if (insns[i].insn & INSN_MASK_READ) {
1138 if (copy_to_user(insns[i].data, data,
1139 insns[i].n * sizeof(unsigned int))) {
1140 DPRINTK("copy_to_user failed\n");
1141 ret = -EFAULT;
1142 goto error;
1143 }
1144 }
1145 if (need_resched())
1146 schedule();
1147 }
1148
1149error:
1150 kfree(insns);
1151 kfree(data);
1152
1153 if (ret < 0)
1154 return ret;
1155 return i;
1156}
1157
1158/*
1065 * COMEDI_INSN 1159 * COMEDI_INSN
1066 * synchronous instructions 1160 * synchronous instructions
1067 * 1161 *
@@ -1088,7 +1182,7 @@ static int do_insn_ioctl(struct comedi_device *dev,
1088 goto error; 1182 goto error;
1089 } 1183 }
1090 1184
1091 if (copy_from_user(&insn, arg, sizeof(struct comedi_insn))) { 1185 if (copy_from_user(&insn, arg, sizeof(insn))) {
1092 ret = -EFAULT; 1186 ret = -EFAULT;
1093 goto error; 1187 goto error;
1094 } 1188 }
@@ -1123,17 +1217,6 @@ error:
1123 return ret; 1217 return ret;
1124} 1218}
1125 1219
1126static void comedi_set_subdevice_runflags(struct comedi_subdevice *s,
1127 unsigned mask, unsigned bits)
1128{
1129 unsigned long flags;
1130
1131 spin_lock_irqsave(&s->spin_lock, flags);
1132 s->runflags &= ~mask;
1133 s->runflags |= (bits & mask);
1134 spin_unlock_irqrestore(&s->spin_lock, flags);
1135}
1136
1137static int do_cmd_ioctl(struct comedi_device *dev, 1220static int do_cmd_ioctl(struct comedi_device *dev,
1138 struct comedi_cmd __user *arg, void *file) 1221 struct comedi_cmd __user *arg, void *file)
1139{ 1222{
@@ -1143,7 +1226,7 @@ static int do_cmd_ioctl(struct comedi_device *dev,
1143 int ret = 0; 1226 int ret = 0;
1144 unsigned int __user *user_chanlist; 1227 unsigned int __user *user_chanlist;
1145 1228
1146 if (copy_from_user(&cmd, arg, sizeof(struct comedi_cmd))) { 1229 if (copy_from_user(&cmd, arg, sizeof(cmd))) {
1147 DPRINTK("bad cmd address\n"); 1230 DPRINTK("bad cmd address\n");
1148 return -EFAULT; 1231 return -EFAULT;
1149 } 1232 }
@@ -1233,7 +1316,7 @@ static int do_cmd_ioctl(struct comedi_device *dev,
1233 /* restore chanlist pointer before copying back */ 1316 /* restore chanlist pointer before copying back */
1234 cmd.chanlist = (unsigned int __force *)user_chanlist; 1317 cmd.chanlist = (unsigned int __force *)user_chanlist;
1235 cmd.data = NULL; 1318 cmd.data = NULL;
1236 if (copy_to_user(arg, &cmd, sizeof(struct comedi_cmd))) { 1319 if (copy_to_user(arg, &cmd, sizeof(cmd))) {
1237 DPRINTK("fault writing cmd\n"); 1320 DPRINTK("fault writing cmd\n");
1238 ret = -EFAULT; 1321 ret = -EFAULT;
1239 goto cleanup; 1322 goto cleanup;
@@ -1248,7 +1331,7 @@ static int do_cmd_ioctl(struct comedi_device *dev,
1248 goto cleanup; 1331 goto cleanup;
1249 } 1332 }
1250 1333
1251 comedi_reset_async_buf(async); 1334 comedi_buf_reset(async);
1252 1335
1253 async->cb_mask = 1336 async->cb_mask =
1254 COMEDI_CB_EOA | COMEDI_CB_BLOCK | COMEDI_CB_ERROR | 1337 COMEDI_CB_EOA | COMEDI_CB_BLOCK | COMEDI_CB_ERROR |
@@ -1292,7 +1375,7 @@ static int do_cmdtest_ioctl(struct comedi_device *dev,
1292 unsigned int *chanlist = NULL; 1375 unsigned int *chanlist = NULL;
1293 unsigned int __user *user_chanlist; 1376 unsigned int __user *user_chanlist;
1294 1377
1295 if (copy_from_user(&cmd, arg, sizeof(struct comedi_cmd))) { 1378 if (copy_from_user(&cmd, arg, sizeof(cmd))) {
1296 DPRINTK("bad cmd address\n"); 1379 DPRINTK("bad cmd address\n");
1297 return -EFAULT; 1380 return -EFAULT;
1298 } 1381 }
@@ -1356,7 +1439,7 @@ static int do_cmdtest_ioctl(struct comedi_device *dev,
1356 /* restore chanlist pointer before copying back */ 1439 /* restore chanlist pointer before copying back */
1357 cmd.chanlist = (unsigned int __force *)user_chanlist; 1440 cmd.chanlist = (unsigned int __force *)user_chanlist;
1358 1441
1359 if (copy_to_user(arg, &cmd, sizeof(struct comedi_cmd))) { 1442 if (copy_to_user(arg, &cmd, sizeof(cmd))) {
1360 DPRINTK("bad cmd address\n"); 1443 DPRINTK("bad cmd address\n");
1361 ret = -EFAULT; 1444 ret = -EFAULT;
1362 goto cleanup; 1445 goto cleanup;
@@ -1533,25 +1616,28 @@ static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
1533 unsigned long arg) 1616 unsigned long arg)
1534{ 1617{
1535 const unsigned minor = iminor(file->f_dentry->d_inode); 1618 const unsigned minor = iminor(file->f_dentry->d_inode);
1536 struct comedi_device_file_info *dev_file_info = 1619 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
1537 comedi_get_device_file_info(minor); 1620 struct comedi_device *dev = comedi_dev_from_file_info(info);
1538 struct comedi_device *dev;
1539 int rc; 1621 int rc;
1540 1622
1541 if (dev_file_info == NULL || dev_file_info->device == NULL) 1623 if (!dev)
1542 return -ENODEV; 1624 return -ENODEV;
1543 dev = dev_file_info->device;
1544 1625
1545 mutex_lock(&dev->mutex); 1626 mutex_lock(&dev->mutex);
1546 1627
1547 /* Device config is special, because it must work on 1628 /* Device config is special, because it must work on
1548 * an unconfigured device. */ 1629 * an unconfigured device. */
1549 if (cmd == COMEDI_DEVCONFIG) { 1630 if (cmd == COMEDI_DEVCONFIG) {
1631 if (minor >= COMEDI_NUM_BOARD_MINORS) {
1632 /* Device config not appropriate on non-board minors. */
1633 rc = -ENOTTY;
1634 goto done;
1635 }
1550 rc = do_devconfig_ioctl(dev, 1636 rc = do_devconfig_ioctl(dev,
1551 (struct comedi_devconfig __user *)arg); 1637 (struct comedi_devconfig __user *)arg);
1552 if (rc == 0) 1638 if (rc == 0)
1553 /* Evade comedi_auto_unconfig(). */ 1639 /* Evade comedi_auto_unconfig(). */
1554 dev_file_info->hardware_device = NULL; 1640 info->hardware_device = NULL;
1555 goto done; 1641 goto done;
1556 } 1642 }
1557 1643
@@ -1624,19 +1710,6 @@ done:
1624 return rc; 1710 return rc;
1625} 1711}
1626 1712
1627static int do_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
1628{
1629 int ret = 0;
1630
1631 if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) && s->cancel)
1632 ret = s->cancel(dev, s);
1633
1634 do_become_nonbusy(dev, s);
1635
1636 return ret;
1637}
1638
1639
1640static void comedi_vm_open(struct vm_area_struct *area) 1713static void comedi_vm_open(struct vm_area_struct *area)
1641{ 1714{
1642 struct comedi_async *async; 1715 struct comedi_async *async;
@@ -1671,40 +1744,38 @@ static struct vm_operations_struct comedi_vm_ops = {
1671static int comedi_mmap(struct file *file, struct vm_area_struct *vma) 1744static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
1672{ 1745{
1673 const unsigned minor = iminor(file->f_dentry->d_inode); 1746 const unsigned minor = iminor(file->f_dentry->d_inode);
1674 struct comedi_async *async = NULL; 1747 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
1748 struct comedi_device *dev = comedi_dev_from_file_info(info);
1749 struct comedi_subdevice *s;
1750 struct comedi_async *async;
1675 unsigned long start = vma->vm_start; 1751 unsigned long start = vma->vm_start;
1676 unsigned long size; 1752 unsigned long size;
1677 int n_pages; 1753 int n_pages;
1678 int i; 1754 int i;
1679 int retval; 1755 int retval;
1680 struct comedi_subdevice *s;
1681 struct comedi_device_file_info *dev_file_info;
1682 struct comedi_device *dev;
1683 1756
1684 dev_file_info = comedi_get_device_file_info(minor); 1757 if (!dev)
1685 if (dev_file_info == NULL)
1686 return -ENODEV;
1687 dev = dev_file_info->device;
1688 if (dev == NULL)
1689 return -ENODEV; 1758 return -ENODEV;
1690 1759
1691 mutex_lock(&dev->mutex); 1760 mutex_lock(&dev->mutex);
1761
1692 if (!dev->attached) { 1762 if (!dev->attached) {
1693 DPRINTK("no driver configured on comedi%i\n", dev->minor); 1763 DPRINTK("no driver configured on comedi%i\n", dev->minor);
1694 retval = -ENODEV; 1764 retval = -ENODEV;
1695 goto done; 1765 goto done;
1696 } 1766 }
1767
1697 if (vma->vm_flags & VM_WRITE) 1768 if (vma->vm_flags & VM_WRITE)
1698 s = comedi_get_write_subdevice(dev_file_info); 1769 s = comedi_write_subdevice(info);
1699 else 1770 else
1700 s = comedi_get_read_subdevice(dev_file_info); 1771 s = comedi_read_subdevice(info);
1701 1772 if (!s) {
1702 if (s == NULL) {
1703 retval = -EINVAL; 1773 retval = -EINVAL;
1704 goto done; 1774 goto done;
1705 } 1775 }
1776
1706 async = s->async; 1777 async = s->async;
1707 if (async == NULL) { 1778 if (!async) {
1708 retval = -EINVAL; 1779 retval = -EINVAL;
1709 goto done; 1780 goto done;
1710 } 1781 }
@@ -1727,11 +1798,11 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
1727 1798
1728 n_pages = size >> PAGE_SHIFT; 1799 n_pages = size >> PAGE_SHIFT;
1729 for (i = 0; i < n_pages; ++i) { 1800 for (i = 0; i < n_pages; ++i) {
1801 struct comedi_buf_page *buf = &async->buf_page_list[i];
1802
1730 if (remap_pfn_range(vma, start, 1803 if (remap_pfn_range(vma, start,
1731 page_to_pfn(virt_to_page 1804 page_to_pfn(virt_to_page(buf->virt_addr)),
1732 (async->buf_page_list 1805 PAGE_SIZE, PAGE_SHARED)) {
1733 [i].virt_addr)), PAGE_SIZE,
1734 PAGE_SHARED)) {
1735 retval = -EAGAIN; 1806 retval = -EAGAIN;
1736 goto done; 1807 goto done;
1737 } 1808 }
@@ -1753,50 +1824,40 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
1753{ 1824{
1754 unsigned int mask = 0; 1825 unsigned int mask = 0;
1755 const unsigned minor = iminor(file->f_dentry->d_inode); 1826 const unsigned minor = iminor(file->f_dentry->d_inode);
1756 struct comedi_subdevice *read_subdev; 1827 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
1757 struct comedi_subdevice *write_subdev; 1828 struct comedi_device *dev = comedi_dev_from_file_info(info);
1758 struct comedi_device_file_info *dev_file_info; 1829 struct comedi_subdevice *s;
1759 struct comedi_device *dev;
1760 dev_file_info = comedi_get_device_file_info(minor);
1761 1830
1762 if (dev_file_info == NULL) 1831 if (!dev)
1763 return -ENODEV;
1764 dev = dev_file_info->device;
1765 if (dev == NULL)
1766 return -ENODEV; 1832 return -ENODEV;
1767 1833
1768 mutex_lock(&dev->mutex); 1834 mutex_lock(&dev->mutex);
1835
1769 if (!dev->attached) { 1836 if (!dev->attached) {
1770 DPRINTK("no driver configured on comedi%i\n", dev->minor); 1837 DPRINTK("no driver configured on comedi%i\n", dev->minor);
1771 mutex_unlock(&dev->mutex); 1838 goto done;
1772 return 0;
1773 } 1839 }
1774 1840
1775 mask = 0; 1841 s = comedi_read_subdevice(info);
1776 read_subdev = comedi_get_read_subdevice(dev_file_info); 1842 if (s && s->async) {
1777 if (read_subdev) { 1843 poll_wait(file, &s->async->wait_head, wait);
1778 poll_wait(file, &read_subdev->async->wait_head, wait); 1844 if (!s->busy || !comedi_is_subdevice_running(s) ||
1779 if (!read_subdev->busy 1845 comedi_buf_read_n_available(s->async) > 0)
1780 || comedi_buf_read_n_available(read_subdev->async) > 0
1781 || !(comedi_get_subdevice_runflags(read_subdev) &
1782 SRF_RUNNING)) {
1783 mask |= POLLIN | POLLRDNORM; 1846 mask |= POLLIN | POLLRDNORM;
1784 }
1785 } 1847 }
1786 write_subdev = comedi_get_write_subdevice(dev_file_info); 1848
1787 if (write_subdev) { 1849 s = comedi_write_subdevice(info);
1788 poll_wait(file, &write_subdev->async->wait_head, wait); 1850 if (s && s->async) {
1789 comedi_buf_write_alloc(write_subdev->async, 1851 unsigned int bps = bytes_per_sample(s->async->subdevice);
1790 write_subdev->async->prealloc_bufsz); 1852
1791 if (!write_subdev->busy 1853 poll_wait(file, &s->async->wait_head, wait);
1792 || !(comedi_get_subdevice_runflags(write_subdev) & 1854 comedi_buf_write_alloc(s->async, s->async->prealloc_bufsz);
1793 SRF_RUNNING) 1855 if (!s->busy || !comedi_is_subdevice_running(s) ||
1794 || comedi_buf_write_n_allocated(write_subdev->async) >= 1856 comedi_buf_write_n_allocated(s->async) >= bps)
1795 bytes_per_sample(write_subdev->async->subdevice)) {
1796 mask |= POLLOUT | POLLWRNORM; 1857 mask |= POLLOUT | POLLWRNORM;
1797 }
1798 } 1858 }
1799 1859
1860done:
1800 mutex_unlock(&dev->mutex); 1861 mutex_unlock(&dev->mutex);
1801 return mask; 1862 return mask;
1802} 1863}
@@ -1809,53 +1870,38 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
1809 int n, m, count = 0, retval = 0; 1870 int n, m, count = 0, retval = 0;
1810 DECLARE_WAITQUEUE(wait, current); 1871 DECLARE_WAITQUEUE(wait, current);
1811 const unsigned minor = iminor(file->f_dentry->d_inode); 1872 const unsigned minor = iminor(file->f_dentry->d_inode);
1812 struct comedi_device_file_info *dev_file_info; 1873 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
1813 struct comedi_device *dev; 1874 struct comedi_device *dev = comedi_dev_from_file_info(info);
1814 dev_file_info = comedi_get_device_file_info(minor);
1815 1875
1816 if (dev_file_info == NULL) 1876 if (!dev)
1817 return -ENODEV;
1818 dev = dev_file_info->device;
1819 if (dev == NULL)
1820 return -ENODEV; 1877 return -ENODEV;
1821 1878
1822 if (!dev->attached) { 1879 if (!dev->attached) {
1823 DPRINTK("no driver configured on comedi%i\n", dev->minor); 1880 DPRINTK("no driver configured on comedi%i\n", dev->minor);
1824 retval = -ENODEV; 1881 return -ENODEV;
1825 goto done;
1826 } 1882 }
1827 1883
1828 s = comedi_get_write_subdevice(dev_file_info); 1884 s = comedi_write_subdevice(info);
1829 if (s == NULL) { 1885 if (!s || !s->async)
1830 retval = -EIO; 1886 return -EIO;
1831 goto done; 1887
1832 }
1833 async = s->async; 1888 async = s->async;
1834 1889
1835 if (!nbytes) { 1890 if (!s->busy || !nbytes)
1836 retval = 0; 1891 return 0;
1837 goto done; 1892 if (s->busy != file)
1838 } 1893 return -EACCES;
1839 if (!s->busy) { 1894
1840 retval = 0;
1841 goto done;
1842 }
1843 if (s->busy != file) {
1844 retval = -EACCES;
1845 goto done;
1846 }
1847 add_wait_queue(&async->wait_head, &wait); 1895 add_wait_queue(&async->wait_head, &wait);
1848 while (nbytes > 0 && !retval) { 1896 while (nbytes > 0 && !retval) {
1849 set_current_state(TASK_INTERRUPTIBLE); 1897 set_current_state(TASK_INTERRUPTIBLE);
1850 1898
1851 if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { 1899 if (!comedi_is_subdevice_running(s)) {
1852 if (count == 0) { 1900 if (count == 0) {
1853 if (comedi_get_subdevice_runflags(s) & 1901 if (comedi_is_subdevice_in_error(s))
1854 SRF_ERROR) {
1855 retval = -EPIPE; 1902 retval = -EPIPE;
1856 } else { 1903 else
1857 retval = 0; 1904 retval = 0;
1858 }
1859 do_become_nonbusy(dev, s); 1905 do_become_nonbusy(dev, s);
1860 } 1906 }
1861 break; 1907 break;
@@ -1908,7 +1954,6 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
1908 set_current_state(TASK_RUNNING); 1954 set_current_state(TASK_RUNNING);
1909 remove_wait_queue(&async->wait_head, &wait); 1955 remove_wait_queue(&async->wait_head, &wait);
1910 1956
1911done:
1912 return count ? count : retval; 1957 return count ? count : retval;
1913} 1958}
1914 1959
@@ -1920,40 +1965,26 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
1920 int n, m, count = 0, retval = 0; 1965 int n, m, count = 0, retval = 0;
1921 DECLARE_WAITQUEUE(wait, current); 1966 DECLARE_WAITQUEUE(wait, current);
1922 const unsigned minor = iminor(file->f_dentry->d_inode); 1967 const unsigned minor = iminor(file->f_dentry->d_inode);
1923 struct comedi_device_file_info *dev_file_info; 1968 struct comedi_file_info *info = comedi_file_info_from_minor(minor);
1924 struct comedi_device *dev; 1969 struct comedi_device *dev = comedi_dev_from_file_info(info);
1925 dev_file_info = comedi_get_device_file_info(minor);
1926 1970
1927 if (dev_file_info == NULL) 1971 if (!dev)
1928 return -ENODEV;
1929 dev = dev_file_info->device;
1930 if (dev == NULL)
1931 return -ENODEV; 1972 return -ENODEV;
1932 1973
1933 if (!dev->attached) { 1974 if (!dev->attached) {
1934 DPRINTK("no driver configured on comedi%i\n", dev->minor); 1975 DPRINTK("no driver configured on comedi%i\n", dev->minor);
1935 retval = -ENODEV; 1976 return -ENODEV;
1936 goto done;
1937 } 1977 }
1938 1978
1939 s = comedi_get_read_subdevice(dev_file_info); 1979 s = comedi_read_subdevice(info);
1940 if (s == NULL) { 1980 if (!s || !s->async)
1941 retval = -EIO; 1981 return -EIO;
1942 goto done; 1982
1943 }
1944 async = s->async; 1983 async = s->async;
1945 if (!nbytes) { 1984 if (!s->busy || !nbytes)
1946 retval = 0; 1985 return 0;
1947 goto done; 1986 if (s->busy != file)
1948 } 1987 return -EACCES;
1949 if (!s->busy) {
1950 retval = 0;
1951 goto done;
1952 }
1953 if (s->busy != file) {
1954 retval = -EACCES;
1955 goto done;
1956 }
1957 1988
1958 add_wait_queue(&async->wait_head, &wait); 1989 add_wait_queue(&async->wait_head, &wait);
1959 while (nbytes > 0 && !retval) { 1990 while (nbytes > 0 && !retval) {
@@ -1970,14 +2001,12 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
1970 n = m; 2001 n = m;
1971 2002
1972 if (n == 0) { 2003 if (n == 0) {
1973 if (!(comedi_get_subdevice_runflags(s) & SRF_RUNNING)) { 2004 if (!comedi_is_subdevice_running(s)) {
1974 do_become_nonbusy(dev, s); 2005 do_become_nonbusy(dev, s);
1975 if (comedi_get_subdevice_runflags(s) & 2006 if (comedi_is_subdevice_in_error(s))
1976 SRF_ERROR) {
1977 retval = -EPIPE; 2007 retval = -EPIPE;
1978 } else { 2008 else
1979 retval = 0; 2009 retval = 0;
1980 }
1981 break; 2010 break;
1982 } 2011 }
1983 if (file->f_flags & O_NONBLOCK) { 2012 if (file->f_flags & O_NONBLOCK) {
@@ -2015,48 +2044,22 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
2015 buf += n; 2044 buf += n;
2016 break; /* makes device work like a pipe */ 2045 break; /* makes device work like a pipe */
2017 } 2046 }
2018 if (!(comedi_get_subdevice_runflags(s) & (SRF_ERROR | SRF_RUNNING)) && 2047 if (comedi_is_subdevice_idle(s) &&
2019 async->buf_read_count - async->buf_write_count == 0) { 2048 async->buf_read_count - async->buf_write_count == 0) {
2020 do_become_nonbusy(dev, s); 2049 do_become_nonbusy(dev, s);
2021 } 2050 }
2022 set_current_state(TASK_RUNNING); 2051 set_current_state(TASK_RUNNING);
2023 remove_wait_queue(&async->wait_head, &wait); 2052 remove_wait_queue(&async->wait_head, &wait);
2024 2053
2025done:
2026 return count ? count : retval; 2054 return count ? count : retval;
2027} 2055}
2028 2056
2029/*
2030 This function restores a subdevice to an idle state.
2031 */
2032static void do_become_nonbusy(struct comedi_device *dev,
2033 struct comedi_subdevice *s)
2034{
2035 struct comedi_async *async = s->async;
2036
2037 comedi_set_subdevice_runflags(s, SRF_RUNNING, 0);
2038 if (async) {
2039 comedi_reset_async_buf(async);
2040 async->inttrig = NULL;
2041 kfree(async->cmd.chanlist);
2042 async->cmd.chanlist = NULL;
2043 } else {
2044 dev_err(dev->class_dev,
2045 "BUG: (?) do_become_nonbusy called with async=NULL\n");
2046 }
2047
2048 s->busy = NULL;
2049}
2050
2051static int comedi_open(struct inode *inode, struct file *file) 2057static int comedi_open(struct inode *inode, struct file *file)
2052{ 2058{
2053 const unsigned minor = iminor(inode); 2059 const unsigned minor = iminor(inode);
2054 struct comedi_device_file_info *dev_file_info = 2060 struct comedi_device *dev = comedi_dev_from_minor(minor);
2055 comedi_get_device_file_info(minor);
2056 struct comedi_device *dev =
2057 dev_file_info ? dev_file_info->device : NULL;
2058 2061
2059 if (dev == NULL) { 2062 if (!dev) {
2060 DPRINTK("invalid minor number\n"); 2063 DPRINTK("invalid minor number\n");
2061 return -ENODEV; 2064 return -ENODEV;
2062 } 2065 }
@@ -2128,19 +2131,25 @@ ok:
2128 return 0; 2131 return 0;
2129} 2132}
2130 2133
2134static int comedi_fasync(int fd, struct file *file, int on)
2135{
2136 const unsigned minor = iminor(file->f_dentry->d_inode);
2137 struct comedi_device *dev = comedi_dev_from_minor(minor);
2138
2139 if (!dev)
2140 return -ENODEV;
2141
2142 return fasync_helper(fd, file, on, &dev->async_queue);
2143}
2144
2131static int comedi_close(struct inode *inode, struct file *file) 2145static int comedi_close(struct inode *inode, struct file *file)
2132{ 2146{
2133 const unsigned minor = iminor(inode); 2147 const unsigned minor = iminor(inode);
2148 struct comedi_device *dev = comedi_dev_from_minor(minor);
2134 struct comedi_subdevice *s = NULL; 2149 struct comedi_subdevice *s = NULL;
2135 int i; 2150 int i;
2136 struct comedi_device_file_info *dev_file_info;
2137 struct comedi_device *dev;
2138 dev_file_info = comedi_get_device_file_info(minor);
2139 2151
2140 if (dev_file_info == NULL) 2152 if (!dev)
2141 return -ENODEV;
2142 dev = dev_file_info->device;
2143 if (dev == NULL)
2144 return -ENODEV; 2153 return -ENODEV;
2145 2154
2146 mutex_lock(&dev->mutex); 2155 mutex_lock(&dev->mutex);
@@ -2172,22 +2181,6 @@ static int comedi_close(struct inode *inode, struct file *file)
2172 return 0; 2181 return 0;
2173} 2182}
2174 2183
2175static int comedi_fasync(int fd, struct file *file, int on)
2176{
2177 const unsigned minor = iminor(file->f_dentry->d_inode);
2178 struct comedi_device_file_info *dev_file_info;
2179 struct comedi_device *dev;
2180 dev_file_info = comedi_get_device_file_info(minor);
2181
2182 if (dev_file_info == NULL)
2183 return -ENODEV;
2184 dev = dev_file_info->device;
2185 if (dev == NULL)
2186 return -ENODEV;
2187
2188 return fasync_helper(fd, file, on, &dev->async_queue);
2189}
2190
2191static const struct file_operations comedi_fops = { 2184static const struct file_operations comedi_fops = {
2192 .owner = THIS_MODULE, 2185 .owner = THIS_MODULE,
2193 .unlocked_ioctl = comedi_unlocked_ioctl, 2186 .unlocked_ioctl = comedi_unlocked_ioctl,
@@ -2205,99 +2198,6 @@ static const struct file_operations comedi_fops = {
2205static struct class *comedi_class; 2198static struct class *comedi_class;
2206static struct cdev comedi_cdev; 2199static struct cdev comedi_cdev;
2207 2200
2208static void comedi_cleanup_legacy_minors(void)
2209{
2210 unsigned i;
2211
2212 for (i = 0; i < comedi_num_legacy_minors; i++)
2213 comedi_free_board_minor(i);
2214}
2215
2216static int __init comedi_init(void)
2217{
2218 int i;
2219 int retval;
2220
2221 pr_info("comedi: version " COMEDI_RELEASE " - http://www.comedi.org\n");
2222
2223 if (comedi_num_legacy_minors < 0 ||
2224 comedi_num_legacy_minors > COMEDI_NUM_BOARD_MINORS) {
2225 pr_err("comedi: error: invalid value for module parameter \"comedi_num_legacy_minors\". Valid values are 0 through %i.\n",
2226 COMEDI_NUM_BOARD_MINORS);
2227 return -EINVAL;
2228 }
2229
2230 /*
2231 * comedi is unusable if both comedi_autoconfig and
2232 * comedi_num_legacy_minors are zero, so we might as well adjust the
2233 * defaults in that case
2234 */
2235 if (comedi_autoconfig == 0 && comedi_num_legacy_minors == 0)
2236 comedi_num_legacy_minors = 16;
2237
2238 memset(comedi_file_info_table, 0,
2239 sizeof(struct comedi_device_file_info *) * COMEDI_NUM_MINORS);
2240
2241 retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2242 COMEDI_NUM_MINORS, "comedi");
2243 if (retval)
2244 return -EIO;
2245 cdev_init(&comedi_cdev, &comedi_fops);
2246 comedi_cdev.owner = THIS_MODULE;
2247 kobject_set_name(&comedi_cdev.kobj, "comedi");
2248 if (cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS)) {
2249 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2250 COMEDI_NUM_MINORS);
2251 return -EIO;
2252 }
2253 comedi_class = class_create(THIS_MODULE, "comedi");
2254 if (IS_ERR(comedi_class)) {
2255 pr_err("comedi: failed to create class\n");
2256 cdev_del(&comedi_cdev);
2257 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2258 COMEDI_NUM_MINORS);
2259 return PTR_ERR(comedi_class);
2260 }
2261
2262 comedi_class->dev_attrs = comedi_dev_attrs;
2263
2264 /* XXX requires /proc interface */
2265 comedi_proc_init();
2266
2267 /* create devices files for legacy/manual use */
2268 for (i = 0; i < comedi_num_legacy_minors; i++) {
2269 int minor;
2270 minor = comedi_alloc_board_minor(NULL);
2271 if (minor < 0) {
2272 comedi_cleanup_legacy_minors();
2273 cdev_del(&comedi_cdev);
2274 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2275 COMEDI_NUM_MINORS);
2276 return minor;
2277 }
2278 }
2279
2280 return 0;
2281}
2282
2283static void __exit comedi_cleanup(void)
2284{
2285 int i;
2286
2287 comedi_cleanup_legacy_minors();
2288 for (i = 0; i < COMEDI_NUM_MINORS; ++i)
2289 BUG_ON(comedi_file_info_table[i]);
2290
2291 class_destroy(comedi_class);
2292 cdev_del(&comedi_cdev);
2293 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS);
2294
2295 comedi_proc_cleanup();
2296}
2297
2298module_init(comedi_init);
2299module_exit(comedi_cleanup);
2300
2301void comedi_error(const struct comedi_device *dev, const char *s) 2201void comedi_error(const struct comedi_device *dev, const char *s)
2302{ 2202{
2303 dev_err(dev->class_dev, "%s: %s\n", dev->driver->driver_name, s); 2203 dev_err(dev->class_dev, "%s: %s\n", dev->driver->driver_name, s);
@@ -2312,7 +2212,7 @@ void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s)
2312 2212
2313 /* DPRINTK("comedi_event 0x%x\n",mask); */ 2213 /* DPRINTK("comedi_event 0x%x\n",mask); */
2314 2214
2315 if ((comedi_get_subdevice_runflags(s) & SRF_RUNNING) == 0) 2215 if (!comedi_is_subdevice_running(s))
2316 return; 2216 return;
2317 2217
2318 if (s-> 2218 if (s->
@@ -2347,40 +2247,9 @@ void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s)
2347} 2247}
2348EXPORT_SYMBOL(comedi_event); 2248EXPORT_SYMBOL(comedi_event);
2349 2249
2350unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s)
2351{
2352 unsigned long flags;
2353 unsigned runflags;
2354
2355 spin_lock_irqsave(&s->spin_lock, flags);
2356 runflags = s->runflags;
2357 spin_unlock_irqrestore(&s->spin_lock, flags);
2358 return runflags;
2359}
2360EXPORT_SYMBOL(comedi_get_subdevice_runflags);
2361
2362static int is_device_busy(struct comedi_device *dev)
2363{
2364 struct comedi_subdevice *s;
2365 int i;
2366
2367 if (!dev->attached)
2368 return 0;
2369
2370 for (i = 0; i < dev->n_subdevices; i++) {
2371 s = &dev->subdevices[i];
2372 if (s->busy)
2373 return 1;
2374 if (s->async && s->async->mmap_count)
2375 return 1;
2376 }
2377
2378 return 0;
2379}
2380
2381static void comedi_device_init(struct comedi_device *dev) 2250static void comedi_device_init(struct comedi_device *dev)
2382{ 2251{
2383 memset(dev, 0, sizeof(struct comedi_device)); 2252 memset(dev, 0, sizeof(*dev));
2384 spin_lock_init(&dev->spinlock); 2253 spin_lock_init(&dev->spinlock);
2385 mutex_init(&dev->mutex); 2254 mutex_init(&dev->mutex);
2386 dev->minor = -1; 2255 dev->minor = -1;
@@ -2398,11 +2267,11 @@ static void comedi_device_cleanup(struct comedi_device *dev)
2398 2267
2399int comedi_alloc_board_minor(struct device *hardware_device) 2268int comedi_alloc_board_minor(struct device *hardware_device)
2400{ 2269{
2401 struct comedi_device_file_info *info; 2270 struct comedi_file_info *info;
2402 struct device *csdev; 2271 struct device *csdev;
2403 unsigned i; 2272 unsigned i;
2404 2273
2405 info = kzalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); 2274 info = kzalloc(sizeof(*info), GFP_KERNEL);
2406 if (info == NULL) 2275 if (info == NULL)
2407 return -ENOMEM; 2276 return -ENOMEM;
2408 info->device = kzalloc(sizeof(struct comedi_device), GFP_KERNEL); 2277 info->device = kzalloc(sizeof(struct comedi_device), GFP_KERNEL);
@@ -2439,7 +2308,7 @@ int comedi_alloc_board_minor(struct device *hardware_device)
2439 2308
2440void comedi_free_board_minor(unsigned minor) 2309void comedi_free_board_minor(unsigned minor)
2441{ 2310{
2442 struct comedi_device_file_info *info; 2311 struct comedi_file_info *info;
2443 2312
2444 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS); 2313 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
2445 spin_lock(&comedi_file_info_table_lock); 2314 spin_lock(&comedi_file_info_table_lock);
@@ -2464,7 +2333,7 @@ void comedi_free_board_minor(unsigned minor)
2464int comedi_find_board_minor(struct device *hardware_device) 2333int comedi_find_board_minor(struct device *hardware_device)
2465{ 2334{
2466 int minor; 2335 int minor;
2467 struct comedi_device_file_info *info; 2336 struct comedi_file_info *info;
2468 2337
2469 for (minor = 0; minor < COMEDI_NUM_BOARD_MINORS; minor++) { 2338 for (minor = 0; minor < COMEDI_NUM_BOARD_MINORS; minor++) {
2470 spin_lock(&comedi_file_info_table_lock); 2339 spin_lock(&comedi_file_info_table_lock);
@@ -2478,19 +2347,21 @@ int comedi_find_board_minor(struct device *hardware_device)
2478 return -ENODEV; 2347 return -ENODEV;
2479} 2348}
2480 2349
2481int comedi_alloc_subdevice_minor(struct comedi_device *dev, 2350int comedi_alloc_subdevice_minor(struct comedi_subdevice *s)
2482 struct comedi_subdevice *s)
2483{ 2351{
2484 struct comedi_device_file_info *info; 2352 struct comedi_device *dev = s->device;
2353 struct comedi_file_info *info;
2485 struct device *csdev; 2354 struct device *csdev;
2486 unsigned i; 2355 unsigned i;
2487 2356
2488 info = kmalloc(sizeof(struct comedi_device_file_info), GFP_KERNEL); 2357 info = kzalloc(sizeof(*info), GFP_KERNEL);
2489 if (info == NULL) 2358 if (!info)
2490 return -ENOMEM; 2359 return -ENOMEM;
2491 info->device = dev; 2360 info->device = dev;
2492 info->read_subdevice = s; 2361 if (s->subdev_flags & SDF_CMD_READ)
2493 info->write_subdevice = s; 2362 info->read_subdevice = s;
2363 if (s->subdev_flags & SDF_CMD_WRITE)
2364 info->write_subdevice = s;
2494 spin_lock(&comedi_file_info_table_lock); 2365 spin_lock(&comedi_file_info_table_lock);
2495 for (i = COMEDI_FIRST_SUBDEVICE_MINOR; i < COMEDI_NUM_MINORS; ++i) { 2366 for (i = COMEDI_FIRST_SUBDEVICE_MINOR; i < COMEDI_NUM_MINORS; ++i) {
2496 if (comedi_file_info_table[i] == NULL) { 2367 if (comedi_file_info_table[i] == NULL) {
@@ -2501,23 +2372,23 @@ int comedi_alloc_subdevice_minor(struct comedi_device *dev,
2501 spin_unlock(&comedi_file_info_table_lock); 2372 spin_unlock(&comedi_file_info_table_lock);
2502 if (i == COMEDI_NUM_MINORS) { 2373 if (i == COMEDI_NUM_MINORS) {
2503 kfree(info); 2374 kfree(info);
2504 pr_err("comedi: error: ran out of minor numbers for board device files.\n"); 2375 pr_err("comedi: error: ran out of minor numbers for subdevice files.\n");
2505 return -EBUSY; 2376 return -EBUSY;
2506 } 2377 }
2507 s->minor = i; 2378 s->minor = i;
2508 csdev = device_create(comedi_class, dev->class_dev, 2379 csdev = device_create(comedi_class, dev->class_dev,
2509 MKDEV(COMEDI_MAJOR, i), NULL, "comedi%i_subd%i", 2380 MKDEV(COMEDI_MAJOR, i), NULL, "comedi%i_subd%i",
2510 dev->minor, (int)(s - dev->subdevices)); 2381 dev->minor, s->index);
2511 if (!IS_ERR(csdev)) 2382 if (!IS_ERR(csdev))
2512 s->class_dev = csdev; 2383 s->class_dev = csdev;
2513 dev_set_drvdata(csdev, info); 2384 dev_set_drvdata(csdev, info);
2514 2385
2515 return i; 2386 return 0;
2516} 2387}
2517 2388
2518void comedi_free_subdevice_minor(struct comedi_subdevice *s) 2389void comedi_free_subdevice_minor(struct comedi_subdevice *s)
2519{ 2390{
2520 struct comedi_device_file_info *info; 2391 struct comedi_file_info *info;
2521 2392
2522 if (s == NULL) 2393 if (s == NULL)
2523 return; 2394 return;
@@ -2539,14 +2410,90 @@ void comedi_free_subdevice_minor(struct comedi_subdevice *s)
2539 kfree(info); 2410 kfree(info);
2540} 2411}
2541 2412
2542struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor) 2413static void comedi_cleanup_board_minors(void)
2543{ 2414{
2544 struct comedi_device_file_info *info; 2415 unsigned i;
2545 2416
2546 BUG_ON(minor >= COMEDI_NUM_MINORS); 2417 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++)
2547 spin_lock(&comedi_file_info_table_lock); 2418 comedi_free_board_minor(i);
2548 info = comedi_file_info_table[minor]; 2419}
2549 spin_unlock(&comedi_file_info_table_lock); 2420
2550 return info; 2421static int __init comedi_init(void)
2422{
2423 int i;
2424 int retval;
2425
2426 pr_info("comedi: version " COMEDI_RELEASE " - http://www.comedi.org\n");
2427
2428 if (comedi_num_legacy_minors < 0 ||
2429 comedi_num_legacy_minors > COMEDI_NUM_BOARD_MINORS) {
2430 pr_err("comedi: error: invalid value for module parameter \"comedi_num_legacy_minors\". Valid values are 0 through %i.\n",
2431 COMEDI_NUM_BOARD_MINORS);
2432 return -EINVAL;
2433 }
2434
2435 memset(comedi_file_info_table, 0,
2436 sizeof(struct comedi_file_info *) * COMEDI_NUM_MINORS);
2437
2438 retval = register_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2439 COMEDI_NUM_MINORS, "comedi");
2440 if (retval)
2441 return -EIO;
2442 cdev_init(&comedi_cdev, &comedi_fops);
2443 comedi_cdev.owner = THIS_MODULE;
2444 kobject_set_name(&comedi_cdev.kobj, "comedi");
2445 if (cdev_add(&comedi_cdev, MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS)) {
2446 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2447 COMEDI_NUM_MINORS);
2448 return -EIO;
2449 }
2450 comedi_class = class_create(THIS_MODULE, "comedi");
2451 if (IS_ERR(comedi_class)) {
2452 pr_err("comedi: failed to create class\n");
2453 cdev_del(&comedi_cdev);
2454 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2455 COMEDI_NUM_MINORS);
2456 return PTR_ERR(comedi_class);
2457 }
2458
2459 comedi_class->dev_attrs = comedi_dev_attrs;
2460
2461 /* XXX requires /proc interface */
2462 comedi_proc_init();
2463
2464 /* create devices files for legacy/manual use */
2465 for (i = 0; i < comedi_num_legacy_minors; i++) {
2466 int minor;
2467 minor = comedi_alloc_board_minor(NULL);
2468 if (minor < 0) {
2469 comedi_cleanup_board_minors();
2470 cdev_del(&comedi_cdev);
2471 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0),
2472 COMEDI_NUM_MINORS);
2473 return minor;
2474 }
2475 }
2476
2477 return 0;
2551} 2478}
2552EXPORT_SYMBOL_GPL(comedi_get_device_file_info); 2479module_init(comedi_init);
2480
2481static void __exit comedi_cleanup(void)
2482{
2483 int i;
2484
2485 comedi_cleanup_board_minors();
2486 for (i = 0; i < COMEDI_NUM_MINORS; ++i)
2487 BUG_ON(comedi_file_info_table[i]);
2488
2489 class_destroy(comedi_class);
2490 cdev_del(&comedi_cdev);
2491 unregister_chrdev_region(MKDEV(COMEDI_MAJOR, 0), COMEDI_NUM_MINORS);
2492
2493 comedi_proc_cleanup();
2494}
2495module_exit(comedi_cleanup);
2496
2497MODULE_AUTHOR("http://www.comedi.org");
2498MODULE_DESCRIPTION("Comedi core module");
2499MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h
index e70ef0515d9a..b3743135f4aa 100644
--- a/drivers/staging/comedi/comedi_internal.h
+++ b/drivers/staging/comedi/comedi_internal.h
@@ -8,18 +8,43 @@
8 */ 8 */
9int do_rangeinfo_ioctl(struct comedi_device *dev, 9int do_rangeinfo_ioctl(struct comedi_device *dev,
10 struct comedi_rangeinfo __user *arg); 10 struct comedi_rangeinfo __user *arg);
11int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
12 struct comedi_insn *insn, unsigned int *data);
13int comedi_alloc_board_minor(struct device *hardware_device); 11int comedi_alloc_board_minor(struct device *hardware_device);
14void comedi_free_board_minor(unsigned minor); 12void comedi_free_board_minor(unsigned minor);
15int comedi_find_board_minor(struct device *hardware_device); 13int comedi_find_board_minor(struct device *hardware_device);
16void comedi_reset_async_buf(struct comedi_async *async); 14int comedi_alloc_subdevice_minor(struct comedi_subdevice *s);
15void comedi_free_subdevice_minor(struct comedi_subdevice *s);
16
17int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, 17int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
18 unsigned long new_size); 18 unsigned long new_size);
19void comedi_buf_reset(struct comedi_async *async);
20unsigned int comedi_buf_write_n_allocated(struct comedi_async *async);
19 21
20extern unsigned int comedi_default_buf_size_kb; 22extern unsigned int comedi_default_buf_size_kb;
21extern unsigned int comedi_default_buf_maxsize_kb; 23extern unsigned int comedi_default_buf_maxsize_kb;
22extern bool comedi_autoconfig; 24
25/* drivers.c */
26
23extern struct comedi_driver *comedi_drivers; 27extern struct comedi_driver *comedi_drivers;
24 28
29int insn_inval(struct comedi_device *, struct comedi_subdevice *,
30 struct comedi_insn *, unsigned int *);
31
32void comedi_device_detach(struct comedi_device *);
33int comedi_device_attach(struct comedi_device *, struct comedi_devconfig *);
34
35#ifdef CONFIG_PROC_FS
36
37/* proc.c */
38
39void comedi_proc_init(void);
40void comedi_proc_cleanup(void);
41#else
42static inline void comedi_proc_init(void)
43{
44}
45static inline void comedi_proc_cleanup(void)
46{
47}
48#endif
49
25#endif /* _COMEDI_INTERNAL_H */ 50#endif /* _COMEDI_INTERNAL_H */
diff --git a/drivers/staging/comedi/comedi_pci.c b/drivers/staging/comedi/comedi_pci.c
new file mode 100644
index 000000000000..37d2e4677360
--- /dev/null
+++ b/drivers/staging/comedi/comedi_pci.c
@@ -0,0 +1,140 @@
1/*
2 * comedi_pci.c
3 * Comedi PCI driver specific functions.
4 *
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/pci.h>
24
25#include "comedidev.h"
26
27/**
28 * comedi_to_pci_dev() - comedi_device pointer to pci_dev pointer.
29 * @dev: comedi_device struct
30 */
31struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
32{
33 return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;
34}
35EXPORT_SYMBOL_GPL(comedi_to_pci_dev);
36
37/**
38 * comedi_pci_enable() - Enable the PCI device and request the regions.
39 * @pcidev: pci_dev struct
40 * @res_name: name for the requested reqource
41 */
42int comedi_pci_enable(struct pci_dev *pcidev, const char *res_name)
43{
44 int rc;
45
46 rc = pci_enable_device(pcidev);
47 if (rc < 0)
48 return rc;
49
50 rc = pci_request_regions(pcidev, res_name);
51 if (rc < 0)
52 pci_disable_device(pcidev);
53
54 return rc;
55}
56EXPORT_SYMBOL_GPL(comedi_pci_enable);
57
58/**
59 * comedi_pci_disable() - Release the regions and disable the PCI device.
60 * @pcidev: pci_dev struct
61 *
62 * This must be matched with a previous successful call to comedi_pci_enable().
63 */
64void comedi_pci_disable(struct pci_dev *pcidev)
65{
66 pci_release_regions(pcidev);
67 pci_disable_device(pcidev);
68}
69EXPORT_SYMBOL_GPL(comedi_pci_disable);
70
71/**
72 * comedi_pci_auto_config() - Configure/probe a comedi PCI driver.
73 * @pcidev: pci_dev struct
74 * @driver: comedi_driver struct
75 *
76 * Typically called from the pci_driver (*probe) function.
77 */
78int comedi_pci_auto_config(struct pci_dev *pcidev,
79 struct comedi_driver *driver)
80{
81 return comedi_auto_config(&pcidev->dev, driver, 0);
82}
83EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
84
85/**
86 * comedi_pci_auto_unconfig() - Unconfigure/remove a comedi PCI driver.
87 * @pcidev: pci_dev struct
88 *
89 * Typically called from the pci_driver (*remove) function.
90 */
91void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
92{
93 comedi_auto_unconfig(&pcidev->dev);
94}
95EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig);
96
97/**
98 * comedi_pci_driver_register() - Register a comedi PCI driver.
99 * @comedi_driver: comedi_driver struct
100 * @pci_driver: pci_driver struct
101 *
102 * This function is used for the module_init() of comedi PCI drivers.
103 * Do not call it directly, use the module_comedi_pci_driver() helper
104 * macro instead.
105 */
106int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
107 struct pci_driver *pci_driver)
108{
109 int ret;
110
111 ret = comedi_driver_register(comedi_driver);
112 if (ret < 0)
113 return ret;
114
115 ret = pci_register_driver(pci_driver);
116 if (ret < 0) {
117 comedi_driver_unregister(comedi_driver);
118 return ret;
119 }
120
121 return 0;
122}
123EXPORT_SYMBOL_GPL(comedi_pci_driver_register);
124
125/**
126 * comedi_pci_driver_unregister() - Unregister a comedi PCI driver.
127 * @comedi_driver: comedi_driver struct
128 * @pci_driver: pci_driver struct
129 *
130 * This function is used for the module_exit() of comedi PCI drivers.
131 * Do not call it directly, use the module_comedi_pci_driver() helper
132 * macro instead.
133 */
134void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver,
135 struct pci_driver *pci_driver)
136{
137 pci_unregister_driver(pci_driver);
138 comedi_driver_unregister(comedi_driver);
139}
140EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister);
diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c
new file mode 100644
index 000000000000..453ff3b28617
--- /dev/null
+++ b/drivers/staging/comedi/comedi_pcmcia.c
@@ -0,0 +1,160 @@
1/*
2 * comedi_pcmcia.c
3 * Comedi PCMCIA driver specific functions.
4 *
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/kernel.h>
24
25#include <pcmcia/cistpl.h>
26#include <pcmcia/ds.h>
27
28#include "comedidev.h"
29
30/**
31 * comedi_to_pcmcia_dev() - comedi_device pointer to pcmcia_device pointer.
32 * @dev: comedi_device struct
33 */
34struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev)
35{
36 return dev->hw_dev ? to_pcmcia_dev(dev->hw_dev) : NULL;
37}
38EXPORT_SYMBOL_GPL(comedi_to_pcmcia_dev);
39
40static int comedi_pcmcia_conf_check(struct pcmcia_device *link,
41 void *priv_data)
42{
43 if (link->config_index == 0)
44 return -EINVAL;
45
46 return pcmcia_request_io(link);
47}
48
49/**
50 * comedi_pcmcia_enable() - Request the regions and enable the PCMCIA device.
51 * @dev: comedi_device struct
52 * @conf_check: optional callback to check the pcmcia_device configuration
53 *
54 * The comedi PCMCIA driver needs to set the link->config_flags, as
55 * appropriate for that driver, before calling this function in order
56 * to allow pcmcia_loop_config() to do its internal autoconfiguration.
57 */
58int comedi_pcmcia_enable(struct comedi_device *dev,
59 int (*conf_check)(struct pcmcia_device *, void *))
60{
61 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
62 int ret;
63
64 if (!link)
65 return -ENODEV;
66
67 if (!conf_check)
68 conf_check = comedi_pcmcia_conf_check;
69
70 ret = pcmcia_loop_config(link, conf_check, NULL);
71 if (ret)
72 return ret;
73
74 return pcmcia_enable_device(link);
75}
76EXPORT_SYMBOL_GPL(comedi_pcmcia_enable);
77
78/**
79 * comedi_pcmcia_disable() - Disable the PCMCIA device and release the regions.
80 * @dev: comedi_device struct
81 */
82void comedi_pcmcia_disable(struct comedi_device *dev)
83{
84 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
85
86 if (link)
87 pcmcia_disable_device(link);
88}
89EXPORT_SYMBOL_GPL(comedi_pcmcia_disable);
90
91/**
92 * comedi_pcmcia_auto_config() - Configure/probe a comedi PCMCIA driver.
93 * @link: pcmcia_device struct
94 * @driver: comedi_driver struct
95 *
96 * Typically called from the pcmcia_driver (*probe) function.
97 */
98int comedi_pcmcia_auto_config(struct pcmcia_device *link,
99 struct comedi_driver *driver)
100{
101 return comedi_auto_config(&link->dev, driver, 0);
102}
103EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_config);
104
105/**
106 * comedi_pcmcia_auto_unconfig() - Unconfigure/remove a comedi PCMCIA driver.
107 * @link: pcmcia_device struct
108 *
109 * Typically called from the pcmcia_driver (*remove) function.
110 */
111void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link)
112{
113 comedi_auto_unconfig(&link->dev);
114}
115EXPORT_SYMBOL_GPL(comedi_pcmcia_auto_unconfig);
116
117/**
118 * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver.
119 * @comedi_driver: comedi_driver struct
120 * @pcmcia_driver: pcmcia_driver struct
121 *
122 * This function is used for the module_init() of comedi USB drivers.
123 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
124 * macro instead.
125 */
126int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver,
127 struct pcmcia_driver *pcmcia_driver)
128{
129 int ret;
130
131 ret = comedi_driver_register(comedi_driver);
132 if (ret < 0)
133 return ret;
134
135 ret = pcmcia_register_driver(pcmcia_driver);
136 if (ret < 0) {
137 comedi_driver_unregister(comedi_driver);
138 return ret;
139 }
140
141 return 0;
142}
143EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register);
144
145/**
146 * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver.
147 * @comedi_driver: comedi_driver struct
148 * @pcmcia_driver: pcmcia_driver struct
149 *
150 * This function is used for the module_exit() of comedi PCMCIA drivers.
151 * Do not call it directly, use the module_comedi_pcmcia_driver() helper
152 * macro instead.
153 */
154void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
155 struct pcmcia_driver *pcmcia_driver)
156{
157 pcmcia_unregister_driver(pcmcia_driver);
158 comedi_driver_unregister(comedi_driver);
159}
160EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister);
diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c
new file mode 100644
index 000000000000..9d9716a248f1
--- /dev/null
+++ b/drivers/staging/comedi/comedi_usb.c
@@ -0,0 +1,108 @@
1/*
2 * comedi_usb.c
3 * Comedi USB driver specific functions.
4 *
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/usb.h>
24
25#include "comedidev.h"
26
27/**
28 * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer.
29 * @dev: comedi_device struct
30 */
31struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
32{
33 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
34}
35EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
36
37/**
38 * comedi_usb_auto_config() - Configure/probe a comedi USB driver.
39 * @intf: usb_interface struct
40 * @driver: comedi_driver struct
41 * @context: driver specific data, passed to comedi_auto_config()
42 *
43 * Typically called from the usb_driver (*probe) function.
44 */
45int comedi_usb_auto_config(struct usb_interface *intf,
46 struct comedi_driver *driver,
47 unsigned long context)
48{
49 return comedi_auto_config(&intf->dev, driver, context);
50}
51EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
52
53/**
54 * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver.
55 * @intf: usb_interface struct
56 *
57 * Typically called from the usb_driver (*disconnect) function.
58 */
59void comedi_usb_auto_unconfig(struct usb_interface *intf)
60{
61 comedi_auto_unconfig(&intf->dev);
62}
63EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
64
65/**
66 * comedi_usb_driver_register() - Register a comedi USB driver.
67 * @comedi_driver: comedi_driver struct
68 * @usb_driver: usb_driver struct
69 *
70 * This function is used for the module_init() of comedi USB drivers.
71 * Do not call it directly, use the module_comedi_usb_driver() helper
72 * macro instead.
73 */
74int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
75 struct usb_driver *usb_driver)
76{
77 int ret;
78
79 ret = comedi_driver_register(comedi_driver);
80 if (ret < 0)
81 return ret;
82
83 ret = usb_register(usb_driver);
84 if (ret < 0) {
85 comedi_driver_unregister(comedi_driver);
86 return ret;
87 }
88
89 return 0;
90}
91EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
92
93/**
94 * comedi_usb_driver_unregister() - Unregister a comedi USB driver.
95 * @comedi_driver: comedi_driver struct
96 * @usb_driver: usb_driver struct
97 *
98 * This function is used for the module_exit() of comedi USB drivers.
99 * Do not call it directly, use the module_comedi_usb_driver() helper
100 * macro instead.
101 */
102void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
103 struct usb_driver *usb_driver)
104{
105 usb_deregister(usb_driver);
106 comedi_driver_unregister(comedi_driver);
107}
108EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index 692e1e615d44..f3a990b45df5 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -40,8 +40,6 @@
40#include <linux/uaccess.h> 40#include <linux/uaccess.h>
41#include <linux/io.h> 41#include <linux/io.h>
42#include <linux/timer.h> 42#include <linux/timer.h>
43#include <linux/pci.h>
44#include <linux/usb.h>
45 43
46#include "comedi.h" 44#include "comedi.h"
47 45
@@ -55,28 +53,13 @@
55 COMEDI_MINORVERSION, COMEDI_MICROVERSION) 53 COMEDI_MINORVERSION, COMEDI_MICROVERSION)
56#define COMEDI_RELEASE VERSION 54#define COMEDI_RELEASE VERSION
57 55
58/*
59 * PCI Vendor IDs not in <linux/pci_ids.h>
60 */
61#define PCI_VENDOR_ID_KOLTER 0x1001
62#define PCI_VENDOR_ID_ICP 0x104c
63#define PCI_VENDOR_ID_AMCC 0x10e8
64#define PCI_VENDOR_ID_DT 0x1116
65#define PCI_VENDOR_ID_IOTECH 0x1616
66#define PCI_VENDOR_ID_CONTEC 0x1221
67#define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */
68#define PCI_VENDOR_ID_ADVANTECH 0x13fe
69#define PCI_VENDOR_ID_MEILHAUS 0x1402
70#define PCI_VENDOR_ID_RTD 0x1435
71#define PCI_VENDOR_ID_ADLINK 0x144a
72#define PCI_VENDOR_ID_AMPLICON 0x14dc
73
74#define COMEDI_NUM_MINORS 0x100 56#define COMEDI_NUM_MINORS 0x100
75#define COMEDI_NUM_BOARD_MINORS 0x30 57#define COMEDI_NUM_BOARD_MINORS 0x30
76#define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS 58#define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS
77 59
78struct comedi_subdevice { 60struct comedi_subdevice {
79 struct comedi_device *device; 61 struct comedi_device *device;
62 int index;
80 int type; 63 int type;
81 int n_chan; 64 int n_chan;
82 int subdev_flags; 65 int subdev_flags;
@@ -250,13 +233,6 @@ static inline const void *comedi_board(const struct comedi_device *dev)
250 return dev->board_ptr; 233 return dev->board_ptr;
251} 234}
252 235
253struct comedi_device_file_info {
254 struct comedi_device *device;
255 struct comedi_subdevice *read_subdevice;
256 struct comedi_subdevice *write_subdevice;
257 struct device *hardware_device;
258};
259
260#ifdef CONFIG_COMEDI_DEBUG 236#ifdef CONFIG_COMEDI_DEBUG
261extern int comedi_debug; 237extern int comedi_debug;
262#else 238#else
@@ -280,105 +256,13 @@ enum comedi_minor_bits {
280static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4; 256static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4;
281static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; 257static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1;
282 258
283struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor); 259struct comedi_device *comedi_dev_from_minor(unsigned minor);
284
285static inline struct comedi_subdevice *comedi_get_read_subdevice(
286 const struct comedi_device_file_info *info)
287{
288 if (info->read_subdevice)
289 return info->read_subdevice;
290 if (info->device == NULL)
291 return NULL;
292 return info->device->read_subdev;
293}
294
295static inline struct comedi_subdevice *comedi_get_write_subdevice(
296 const struct comedi_device_file_info *info)
297{
298 if (info->write_subdevice)
299 return info->write_subdevice;
300 if (info->device == NULL)
301 return NULL;
302 return info->device->write_subdev;
303}
304
305int comedi_alloc_subdevices(struct comedi_device *, int);
306
307void comedi_device_detach(struct comedi_device *dev);
308int comedi_device_attach(struct comedi_device *dev,
309 struct comedi_devconfig *it);
310int comedi_driver_register(struct comedi_driver *);
311int comedi_driver_unregister(struct comedi_driver *);
312
313/**
314 * module_comedi_driver() - Helper macro for registering a comedi driver
315 * @__comedi_driver: comedi_driver struct
316 *
317 * Helper macro for comedi drivers which do not do anything special in module
318 * init/exit. This eliminates a lot of boilerplate. Each module may only use
319 * this macro once, and calling it replaces module_init() and module_exit().
320 */
321#define module_comedi_driver(__comedi_driver) \
322 module_driver(__comedi_driver, comedi_driver_register, \
323 comedi_driver_unregister)
324
325int comedi_pci_enable(struct pci_dev *, const char *);
326void comedi_pci_disable(struct pci_dev *);
327
328int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
329void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *);
330
331/**
332 * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver
333 * @__comedi_driver: comedi_driver struct
334 * @__pci_driver: pci_driver struct
335 *
336 * Helper macro for comedi PCI drivers which do not do anything special
337 * in module init/exit. This eliminates a lot of boilerplate. Each
338 * module may only use this macro once, and calling it replaces
339 * module_init() and module_exit()
340 */
341#define module_comedi_pci_driver(__comedi_driver, __pci_driver) \
342 module_driver(__comedi_driver, comedi_pci_driver_register, \
343 comedi_pci_driver_unregister, &(__pci_driver))
344
345struct usb_driver;
346
347int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *);
348void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *);
349
350/**
351 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver
352 * @__comedi_driver: comedi_driver struct
353 * @__usb_driver: usb_driver struct
354 *
355 * Helper macro for comedi USB drivers which do not do anything special
356 * in module init/exit. This eliminates a lot of boilerplate. Each
357 * module may only use this macro once, and calling it replaces
358 * module_init() and module_exit()
359 */
360#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \
361 module_driver(__comedi_driver, comedi_usb_driver_register, \
362 comedi_usb_driver_unregister, &(__usb_driver))
363 260
364void init_polling(void); 261void init_polling(void);
365void cleanup_polling(void); 262void cleanup_polling(void);
366void start_polling(struct comedi_device *); 263void start_polling(struct comedi_device *);
367void stop_polling(struct comedi_device *); 264void stop_polling(struct comedi_device *);
368 265
369#ifdef CONFIG_PROC_FS
370void comedi_proc_init(void);
371void comedi_proc_cleanup(void);
372#else
373static inline void comedi_proc_init(void)
374{
375}
376
377static inline void comedi_proc_cleanup(void)
378{
379}
380#endif
381
382/* subdevice runflags */ 266/* subdevice runflags */
383enum subdevice_runflags { 267enum subdevice_runflags {
384 SRF_USER = 0x00000001, 268 SRF_USER = 0x00000001,
@@ -389,10 +273,11 @@ enum subdevice_runflags {
389 SRF_RUNNING = 0x08000000 273 SRF_RUNNING = 0x08000000
390}; 274};
391 275
276bool comedi_is_subdevice_running(struct comedi_subdevice *s);
277
392int comedi_check_chanlist(struct comedi_subdevice *s, 278int comedi_check_chanlist(struct comedi_subdevice *s,
393 int n, 279 int n,
394 unsigned int *chanlist); 280 unsigned int *chanlist);
395unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s);
396 281
397/* range stuff */ 282/* range stuff */
398 283
@@ -433,111 +318,186 @@ static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd)
433 return sizeof(short); 318 return sizeof(short);
434} 319}
435 320
436/* must be used in attach to set dev->hw_dev if you wish to dma directly 321/*
437into comedi's buffer */ 322 * Must set dev->hw_dev if you wish to dma directly into comedi's buffer.
438static inline void comedi_set_hw_dev(struct comedi_device *dev, 323 * Also useful for retrieving a previously configured hardware device of
439 struct device *hw_dev) 324 * known bus type. Set automatically for auto-configured devices.
440{ 325 * Automatically set to NULL when detaching hardware device.
441 if (dev->hw_dev == hw_dev) 326 */
442 return; 327int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev);
443 if (dev->hw_dev)
444 put_device(dev->hw_dev);
445 dev->hw_dev = hw_dev;
446 if (dev->hw_dev) {
447 dev->hw_dev = get_device(dev->hw_dev);
448 BUG_ON(dev->hw_dev == NULL);
449 }
450}
451 328
452static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) 329unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int);
453{ 330unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int);
454 return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;
455}
456 331
457static inline struct usb_interface * 332unsigned int comedi_buf_read_n_available(struct comedi_async *);
458comedi_to_usb_interface(struct comedi_device *dev) 333unsigned int comedi_buf_read_alloc(struct comedi_async *, unsigned int);
459{ 334unsigned int comedi_buf_read_free(struct comedi_async *, unsigned int);
460 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; 335
461} 336int comedi_buf_put(struct comedi_async *, short);
337int comedi_buf_get(struct comedi_async *, short *);
462 338
463int comedi_buf_put(struct comedi_async *async, short x);
464int comedi_buf_get(struct comedi_async *async, short *x);
465
466unsigned int comedi_buf_write_n_available(struct comedi_async *async);
467unsigned int comedi_buf_write_alloc(struct comedi_async *async,
468 unsigned int nbytes);
469unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async,
470 unsigned int nbytes);
471unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes);
472unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes);
473unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes);
474unsigned int comedi_buf_read_n_available(struct comedi_async *async);
475void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, 339void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset,
476 const void *source, unsigned int num_bytes); 340 const void *source, unsigned int num_bytes);
477void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, 341void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
478 void *destination, unsigned int num_bytes); 342 void *destination, unsigned int num_bytes);
479static inline unsigned comedi_buf_write_n_allocated(struct comedi_async *async)
480{
481 return async->buf_write_alloc_count - async->buf_write_count;
482}
483 343
484static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) 344/* drivers.c - general comedi driver functions */
485{
486 return async->buf_read_alloc_count - async->buf_read_count;
487}
488 345
489static inline void *comedi_aux_data(int options[], int n) 346int comedi_alloc_subdevices(struct comedi_device *, int);
490{
491 unsigned long address;
492 unsigned long addressLow;
493 int bit_shift;
494 if (sizeof(int) >= sizeof(void *))
495 address = options[COMEDI_DEVCONF_AUX_DATA_LO];
496 else {
497 address = options[COMEDI_DEVCONF_AUX_DATA_HI];
498 bit_shift = sizeof(int) * 8;
499 address <<= bit_shift;
500 addressLow = options[COMEDI_DEVCONF_AUX_DATA_LO];
501 addressLow &= (1UL << bit_shift) - 1;
502 address |= addressLow;
503 }
504 if (n >= 1)
505 address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH];
506 if (n >= 2)
507 address += options[COMEDI_DEVCONF_AUX_DATA1_LENGTH];
508 if (n >= 3)
509 address += options[COMEDI_DEVCONF_AUX_DATA2_LENGTH];
510 BUG_ON(n > 3);
511 return (void *)address;
512}
513 347
514int comedi_alloc_subdevice_minor(struct comedi_device *dev, 348int comedi_auto_config(struct device *, struct comedi_driver *,
515 struct comedi_subdevice *s); 349 unsigned long context);
516void comedi_free_subdevice_minor(struct comedi_subdevice *s); 350void comedi_auto_unconfig(struct device *);
517int comedi_auto_config(struct device *hardware_device,
518 struct comedi_driver *driver, unsigned long context);
519void comedi_auto_unconfig(struct device *hardware_device);
520 351
521static inline int comedi_pci_auto_config(struct pci_dev *pcidev, 352int comedi_driver_register(struct comedi_driver *);
522 struct comedi_driver *driver) 353int comedi_driver_unregister(struct comedi_driver *);
523{ 354
524 return comedi_auto_config(&pcidev->dev, driver, 0); 355/**
525} 356 * module_comedi_driver() - Helper macro for registering a comedi driver
357 * @__comedi_driver: comedi_driver struct
358 *
359 * Helper macro for comedi drivers which do not do anything special in module
360 * init/exit. This eliminates a lot of boilerplate. Each module may only use
361 * this macro once, and calling it replaces module_init() and module_exit().
362 */
363#define module_comedi_driver(__comedi_driver) \
364 module_driver(__comedi_driver, comedi_driver_register, \
365 comedi_driver_unregister)
366
367#ifdef CONFIG_COMEDI_PCI_DRIVERS
368
369/* comedi_pci.c - comedi PCI driver specific functions */
370
371/*
372 * PCI Vendor IDs not in <linux/pci_ids.h>
373 */
374#define PCI_VENDOR_ID_KOLTER 0x1001
375#define PCI_VENDOR_ID_ICP 0x104c
376#define PCI_VENDOR_ID_AMCC 0x10e8
377#define PCI_VENDOR_ID_DT 0x1116
378#define PCI_VENDOR_ID_IOTECH 0x1616
379#define PCI_VENDOR_ID_CONTEC 0x1221
380#define PCI_VENDOR_ID_RTD 0x1435
381
382struct pci_dev;
383struct pci_driver;
384
385struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
386
387int comedi_pci_enable(struct pci_dev *, const char *);
388void comedi_pci_disable(struct pci_dev *);
389
390int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *);
391void comedi_pci_auto_unconfig(struct pci_dev *);
392
393int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
394void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *);
395
396/**
397 * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver
398 * @__comedi_driver: comedi_driver struct
399 * @__pci_driver: pci_driver struct
400 *
401 * Helper macro for comedi PCI drivers which do not do anything special
402 * in module init/exit. This eliminates a lot of boilerplate. Each
403 * module may only use this macro once, and calling it replaces
404 * module_init() and module_exit()
405 */
406#define module_comedi_pci_driver(__comedi_driver, __pci_driver) \
407 module_driver(__comedi_driver, comedi_pci_driver_register, \
408 comedi_pci_driver_unregister, &(__pci_driver))
526 409
527static inline void comedi_pci_auto_unconfig(struct pci_dev *pcidev) 410#else
411
412/*
413 * Some of the comedi mixed ISA/PCI drivers call the PCI specific
414 * functions. Provide some dummy functions if CONFIG_COMEDI_PCI_DRIVERS
415 * is not enabled.
416 */
417
418static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
528{ 419{
529 comedi_auto_unconfig(&pcidev->dev); 420 return NULL;
530} 421}
531 422
532static inline int comedi_usb_auto_config(struct usb_interface *intf, 423static inline int comedi_pci_enable(struct pci_dev *dev, const char *name)
533 struct comedi_driver *driver)
534{ 424{
535 return comedi_auto_config(&intf->dev, driver, 0); 425 return -ENOSYS;
536} 426}
537 427
538static inline void comedi_usb_auto_unconfig(struct usb_interface *intf) 428static inline void comedi_pci_disable(struct pci_dev *dev)
539{ 429{
540 comedi_auto_unconfig(&intf->dev);
541} 430}
542 431
432#endif /* CONFIG_COMEDI_PCI_DRIVERS */
433
434#ifdef CONFIG_COMEDI_PCMCIA_DRIVERS
435
436/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */
437
438struct pcmcia_driver;
439struct pcmcia_device;
440
441struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *);
442
443int comedi_pcmcia_enable(struct comedi_device *,
444 int (*conf_check)(struct pcmcia_device *, void *));
445void comedi_pcmcia_disable(struct comedi_device *);
446
447int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *);
448void comedi_pcmcia_auto_unconfig(struct pcmcia_device *);
449
450int comedi_pcmcia_driver_register(struct comedi_driver *,
451 struct pcmcia_driver *);
452void comedi_pcmcia_driver_unregister(struct comedi_driver *,
453 struct pcmcia_driver *);
454
455/**
456 * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver
457 * @__comedi_driver: comedi_driver struct
458 * @__pcmcia_driver: pcmcia_driver struct
459 *
460 * Helper macro for comedi PCMCIA drivers which do not do anything special
461 * in module init/exit. This eliminates a lot of boilerplate. Each
462 * module may only use this macro once, and calling it replaces
463 * module_init() and module_exit()
464 */
465#define module_comedi_pcmcia_driver(__comedi_driver, __pcmcia_driver) \
466 module_driver(__comedi_driver, comedi_pcmcia_driver_register, \
467 comedi_pcmcia_driver_unregister, &(__pcmcia_driver))
468
469#endif /* CONFIG_COMEDI_PCMCIA_DRIVERS */
470
471#ifdef CONFIG_COMEDI_USB_DRIVERS
472
473/* comedi_usb.c - comedi USB driver specific functions */
474
475struct usb_driver;
476struct usb_interface;
477
478struct usb_interface *comedi_to_usb_interface(struct comedi_device *);
479
480int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *,
481 unsigned long context);
482void comedi_usb_auto_unconfig(struct usb_interface *);
483
484int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *);
485void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *);
486
487/**
488 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver
489 * @__comedi_driver: comedi_driver struct
490 * @__usb_driver: usb_driver struct
491 *
492 * Helper macro for comedi USB drivers which do not do anything special
493 * in module init/exit. This eliminates a lot of boilerplate. Each
494 * module may only use this macro once, and calling it replaces
495 * module_init() and module_exit()
496 */
497#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \
498 module_driver(__comedi_driver, comedi_usb_driver_register, \
499 comedi_usb_driver_unregister, &(__usb_driver))
500
501#endif /* CONFIG_COMEDI_USB_DRIVERS */
502
543#endif /* _COMEDIDEV_H */ 503#endif /* _COMEDIDEV_H */
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 50cf498698e2..64be7c5e891e 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -23,8 +23,6 @@
23 23
24#include <linux/device.h> 24#include <linux/device.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/pci.h>
27#include <linux/usb.h>
28#include <linux/errno.h> 26#include <linux/errno.h>
29#include <linux/kconfig.h> 27#include <linux/kconfig.h>
30#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -43,16 +41,25 @@
43#include "comedidev.h" 41#include "comedidev.h"
44#include "comedi_internal.h" 42#include "comedi_internal.h"
45 43
46static int postconfig(struct comedi_device *dev);
47static int insn_rw_emulate_bits(struct comedi_device *dev,
48 struct comedi_subdevice *s,
49 struct comedi_insn *insn, unsigned int *data);
50static void *comedi_recognize(struct comedi_driver *driv, const char *name);
51static void comedi_report_boards(struct comedi_driver *driv);
52static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s);
53
54struct comedi_driver *comedi_drivers; 44struct comedi_driver *comedi_drivers;
55 45
46int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev)
47{
48 if (hw_dev == dev->hw_dev)
49 return 0;
50 if (dev->hw_dev != NULL)
51 return -EEXIST;
52 dev->hw_dev = get_device(hw_dev);
53 return 0;
54}
55EXPORT_SYMBOL_GPL(comedi_set_hw_dev);
56
57static void comedi_clear_hw_dev(struct comedi_device *dev)
58{
59 put_device(dev->hw_dev);
60 dev->hw_dev = NULL;
61}
62
56int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices) 63int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
57{ 64{
58 struct comedi_subdevice *s; 65 struct comedi_subdevice *s;
@@ -70,6 +77,7 @@ int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices)
70 for (i = 0; i < num_subdevices; ++i) { 77 for (i = 0; i < num_subdevices; ++i) {
71 s = &dev->subdevices[i]; 78 s = &dev->subdevices[i];
72 s->device = dev; 79 s->device = dev;
80 s->index = i;
73 s->async_dma_dir = DMA_NONE; 81 s->async_dma_dir = DMA_NONE;
74 spin_lock_init(&s->spin_lock); 82 spin_lock_init(&s->spin_lock);
75 s->minor = -1; 83 s->minor = -1;
@@ -107,7 +115,7 @@ static void cleanup_device(struct comedi_device *dev)
107 dev->write_subdev = NULL; 115 dev->write_subdev = NULL;
108 dev->open = NULL; 116 dev->open = NULL;
109 dev->close = NULL; 117 dev->close = NULL;
110 comedi_set_hw_dev(dev, NULL); 118 comedi_clear_hw_dev(dev);
111} 119}
112 120
113static void __comedi_device_detach(struct comedi_device *dev) 121static void __comedi_device_detach(struct comedi_device *dev)
@@ -128,131 +136,105 @@ void comedi_device_detach(struct comedi_device *dev)
128 __comedi_device_detach(dev); 136 __comedi_device_detach(dev);
129} 137}
130 138
131/* do a little post-config cleanup */ 139static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
132/* called with module refcount incremented, decrements it */
133static int comedi_device_postconfig(struct comedi_device *dev)
134{ 140{
135 int ret = postconfig(dev); 141 return -EINVAL;
136 module_put(dev->driver->module);
137 if (ret < 0) {
138 __comedi_device_detach(dev);
139 return ret;
140 }
141 if (!dev->board_name) {
142 dev_warn(dev->class_dev, "BUG: dev->board_name=NULL\n");
143 dev->board_name = "BUG";
144 }
145 smp_wmb();
146 dev->attached = 1;
147 return 0;
148} 142}
149 143
150int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) 144int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
145 struct comedi_insn *insn, unsigned int *data)
151{ 146{
152 struct comedi_driver *driv; 147 return -EINVAL;
148}
149
150static int insn_rw_emulate_bits(struct comedi_device *dev,
151 struct comedi_subdevice *s,
152 struct comedi_insn *insn, unsigned int *data)
153{
154 struct comedi_insn new_insn;
153 int ret; 155 int ret;
156 static const unsigned channels_per_bitfield = 32;
154 157
155 if (dev->attached) 158 unsigned chan = CR_CHAN(insn->chanspec);
156 return -EBUSY; 159 const unsigned base_bitfield_channel =
160 (chan < channels_per_bitfield) ? 0 : chan;
161 unsigned int new_data[2];
162 memset(new_data, 0, sizeof(new_data));
163 memset(&new_insn, 0, sizeof(new_insn));
164 new_insn.insn = INSN_BITS;
165 new_insn.chanspec = base_bitfield_channel;
166 new_insn.n = 2;
167 new_insn.subdev = insn->subdev;
157 168
158 for (driv = comedi_drivers; driv; driv = driv->next) { 169 if (insn->insn == INSN_WRITE) {
159 if (!try_module_get(driv->module)) 170 if (!(s->subdev_flags & SDF_WRITABLE))
160 continue; 171 return -EINVAL;
161 if (driv->num_names) { 172 new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */
162 dev->board_ptr = comedi_recognize(driv, it->board_name); 173 new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel))
163 if (dev->board_ptr) 174 : 0; /* bits */
164 break;
165 } else if (strcmp(driv->driver_name, it->board_name) == 0)
166 break;
167 module_put(driv->module);
168 }
169 if (driv == NULL) {
170 /* recognize has failed if we get here */
171 /* report valid board names before returning error */
172 for (driv = comedi_drivers; driv; driv = driv->next) {
173 if (!try_module_get(driv->module))
174 continue;
175 comedi_report_boards(driv);
176 module_put(driv->module);
177 }
178 return -EIO;
179 }
180 if (driv->attach == NULL) {
181 /* driver does not support manual configuration */
182 dev_warn(dev->class_dev,
183 "driver '%s' does not support attach using comedi_config\n",
184 driv->driver_name);
185 module_put(driv->module);
186 return -ENOSYS;
187 } 175 }
188 /* initialize dev->driver here so 176
189 * comedi_error() can be called from attach */ 177 ret = s->insn_bits(dev, s, &new_insn, new_data);
190 dev->driver = driv; 178 if (ret < 0)
191 ret = driv->attach(dev, it);
192 if (ret < 0) {
193 module_put(dev->driver->module);
194 __comedi_device_detach(dev);
195 return ret; 179 return ret;
196 }
197 return comedi_device_postconfig(dev);
198}
199 180
200int comedi_driver_register(struct comedi_driver *driver) 181 if (insn->insn == INSN_READ)
201{ 182 data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1;
202 driver->next = comedi_drivers;
203 comedi_drivers = driver;
204 183
205 return 0; 184 return 1;
206} 185}
207EXPORT_SYMBOL(comedi_driver_register);
208 186
209int comedi_driver_unregister(struct comedi_driver *driver) 187static int __comedi_device_postconfig_async(struct comedi_device *dev,
188 struct comedi_subdevice *s)
210{ 189{
211 struct comedi_driver *prev; 190 struct comedi_async *async;
212 int i; 191 unsigned int buf_size;
192 int ret;
213 193
214 /* check for devices using this driver */ 194 if ((s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) == 0) {
215 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { 195 dev_warn(dev->class_dev,
216 struct comedi_device_file_info *dev_file_info = 196 "async subdevices must support SDF_CMD_READ or SDF_CMD_WRITE\n");
217 comedi_get_device_file_info(i); 197 return -EINVAL;
218 struct comedi_device *dev; 198 }
199 if (!s->do_cmdtest) {
200 dev_warn(dev->class_dev,
201 "async subdevices must have a do_cmdtest() function\n");
202 return -EINVAL;
203 }
219 204
220 if (dev_file_info == NULL) 205 async = kzalloc(sizeof(*async), GFP_KERNEL);
221 continue; 206 if (!async)
222 dev = dev_file_info->device; 207 return -ENOMEM;
223 208
224 mutex_lock(&dev->mutex); 209 init_waitqueue_head(&async->wait_head);
225 if (dev->attached && dev->driver == driver) { 210 async->subdevice = s;
226 if (dev->use_count) 211 s->async = async;
227 dev_warn(dev->class_dev,
228 "BUG! detaching device with use_count=%d\n",
229 dev->use_count);
230 comedi_device_detach(dev);
231 }
232 mutex_unlock(&dev->mutex);
233 }
234 212
235 if (comedi_drivers == driver) { 213 async->max_bufsize = comedi_default_buf_maxsize_kb * 1024;
236 comedi_drivers = driver->next; 214 buf_size = comedi_default_buf_size_kb * 1024;
237 return 0; 215 if (buf_size > async->max_bufsize)
238 } 216 buf_size = async->max_bufsize;
239 217
240 for (prev = comedi_drivers; prev->next; prev = prev->next) { 218 if (comedi_buf_alloc(dev, s, buf_size) < 0) {
241 if (prev->next == driver) { 219 dev_warn(dev->class_dev, "Buffer allocation failed\n");
242 prev->next = driver->next; 220 return -ENOMEM;
243 return 0;
244 }
245 } 221 }
246 return -EINVAL; 222 if (s->buf_change) {
223 ret = s->buf_change(dev, s, buf_size);
224 if (ret < 0)
225 return ret;
226 }
227
228 comedi_alloc_subdevice_minor(s);
229
230 return 0;
247} 231}
248EXPORT_SYMBOL(comedi_driver_unregister);
249 232
250static int postconfig(struct comedi_device *dev) 233static int __comedi_device_postconfig(struct comedi_device *dev)
251{ 234{
252 int i;
253 struct comedi_subdevice *s; 235 struct comedi_subdevice *s;
254 struct comedi_async *async = NULL;
255 int ret; 236 int ret;
237 int i;
256 238
257 for (i = 0; i < dev->n_subdevices; i++) { 239 for (i = 0; i < dev->n_subdevices; i++) {
258 s = &dev->subdevices[i]; 240 s = &dev->subdevices[i];
@@ -264,42 +246,9 @@ static int postconfig(struct comedi_device *dev)
264 s->len_chanlist = 1; 246 s->len_chanlist = 1;
265 247
266 if (s->do_cmd) { 248 if (s->do_cmd) {
267 unsigned int buf_size; 249 ret = __comedi_device_postconfig_async(dev, s);
268 250 if (ret)
269 BUG_ON((s->subdev_flags & (SDF_CMD_READ | 251 return ret;
270 SDF_CMD_WRITE)) == 0);
271 BUG_ON(!s->do_cmdtest);
272
273 async =
274 kzalloc(sizeof(struct comedi_async), GFP_KERNEL);
275 if (async == NULL) {
276 dev_warn(dev->class_dev,
277 "failed to allocate async struct\n");
278 return -ENOMEM;
279 }
280 init_waitqueue_head(&async->wait_head);
281 async->subdevice = s;
282 s->async = async;
283
284 async->max_bufsize =
285 comedi_default_buf_maxsize_kb * 1024;
286 buf_size = comedi_default_buf_size_kb * 1024;
287 if (buf_size > async->max_bufsize)
288 buf_size = async->max_bufsize;
289
290 async->prealloc_buf = NULL;
291 async->prealloc_bufsz = 0;
292 if (comedi_buf_alloc(dev, s, buf_size) < 0) {
293 dev_warn(dev->class_dev,
294 "Buffer allocation failed\n");
295 return -ENOMEM;
296 }
297 if (s->buf_change) {
298 ret = s->buf_change(dev, s, buf_size);
299 if (ret < 0)
300 return ret;
301 }
302 comedi_alloc_subdevice_minor(dev, s);
303 } 252 }
304 253
305 if (!s->range_table && !s->range_table_list) 254 if (!s->range_table && !s->range_table_list)
@@ -326,6 +275,25 @@ static int postconfig(struct comedi_device *dev)
326 return 0; 275 return 0;
327} 276}
328 277
278/* do a little post-config cleanup */
279/* called with module refcount incremented, decrements it */
280static int comedi_device_postconfig(struct comedi_device *dev)
281{
282 int ret = __comedi_device_postconfig(dev);
283 module_put(dev->driver->module);
284 if (ret < 0) {
285 __comedi_device_detach(dev);
286 return ret;
287 }
288 if (!dev->board_name) {
289 dev_warn(dev->class_dev, "BUG: dev->board_name=NULL\n");
290 dev->board_name = "BUG";
291 }
292 smp_wmb();
293 dev->attached = 1;
294 return 0;
295}
296
329/* 297/*
330 * Generic recognize function for drivers that register their supported 298 * Generic recognize function for drivers that register their supported
331 * board names. 299 * board names.
@@ -384,463 +352,63 @@ static void comedi_report_boards(struct comedi_driver *driv)
384 pr_info(" %s\n", driv->driver_name); 352 pr_info(" %s\n", driv->driver_name);
385} 353}
386 354
387static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s) 355int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
388{
389 return -EINVAL;
390}
391
392int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
393 struct comedi_insn *insn, unsigned int *data)
394{
395 return -EINVAL;
396}
397
398static int insn_rw_emulate_bits(struct comedi_device *dev,
399 struct comedi_subdevice *s,
400 struct comedi_insn *insn, unsigned int *data)
401{ 356{
402 struct comedi_insn new_insn; 357 struct comedi_driver *driv;
403 int ret; 358 int ret;
404 static const unsigned channels_per_bitfield = 32;
405
406 unsigned chan = CR_CHAN(insn->chanspec);
407 const unsigned base_bitfield_channel =
408 (chan < channels_per_bitfield) ? 0 : chan;
409 unsigned int new_data[2];
410 memset(new_data, 0, sizeof(new_data));
411 memset(&new_insn, 0, sizeof(new_insn));
412 new_insn.insn = INSN_BITS;
413 new_insn.chanspec = base_bitfield_channel;
414 new_insn.n = 2;
415 new_insn.subdev = insn->subdev;
416 359
417 if (insn->insn == INSN_WRITE) { 360 if (dev->attached)
418 if (!(s->subdev_flags & SDF_WRITABLE)) 361 return -EBUSY;
419 return -EINVAL;
420 new_data[0] = 1 << (chan - base_bitfield_channel); /* mask */
421 new_data[1] = data[0] ? (1 << (chan - base_bitfield_channel))
422 : 0; /* bits */
423 }
424
425 ret = s->insn_bits(dev, s, &new_insn, new_data);
426 if (ret < 0)
427 return ret;
428
429 if (insn->insn == INSN_READ)
430 data[0] = (new_data[1] >> (chan - base_bitfield_channel)) & 1;
431
432 return 1;
433}
434
435int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
436 unsigned long new_size)
437{
438 struct comedi_async *async = s->async;
439
440 /* Round up new_size to multiple of PAGE_SIZE */
441 new_size = (new_size + PAGE_SIZE - 1) & PAGE_MASK;
442
443 /* if no change is required, do nothing */
444 if (async->prealloc_buf && async->prealloc_bufsz == new_size)
445 return 0;
446
447 /* deallocate old buffer */
448 if (async->prealloc_buf) {
449 vunmap(async->prealloc_buf);
450 async->prealloc_buf = NULL;
451 async->prealloc_bufsz = 0;
452 }
453 if (async->buf_page_list) {
454 unsigned i;
455 for (i = 0; i < async->n_buf_pages; ++i) {
456 if (async->buf_page_list[i].virt_addr) {
457 clear_bit(PG_reserved,
458 &(virt_to_page(async->buf_page_list[i].
459 virt_addr)->flags));
460 if (s->async_dma_dir != DMA_NONE) {
461 dma_free_coherent(dev->hw_dev,
462 PAGE_SIZE,
463 async->
464 buf_page_list
465 [i].virt_addr,
466 async->
467 buf_page_list
468 [i].dma_addr);
469 } else {
470 free_page((unsigned long)
471 async->buf_page_list[i].
472 virt_addr);
473 }
474 }
475 }
476 vfree(async->buf_page_list);
477 async->buf_page_list = NULL;
478 async->n_buf_pages = 0;
479 }
480 /* allocate new buffer */
481 if (new_size) {
482 unsigned i = 0;
483 unsigned n_pages = new_size >> PAGE_SHIFT;
484 struct page **pages = NULL;
485
486 async->buf_page_list =
487 vzalloc(sizeof(struct comedi_buf_page) * n_pages);
488 if (async->buf_page_list)
489 pages = vmalloc(sizeof(struct page *) * n_pages);
490
491 if (pages) {
492 for (i = 0; i < n_pages; i++) {
493 if (s->async_dma_dir != DMA_NONE) {
494 async->buf_page_list[i].virt_addr =
495 dma_alloc_coherent(dev->hw_dev,
496 PAGE_SIZE,
497 &async->
498 buf_page_list
499 [i].dma_addr,
500 GFP_KERNEL |
501 __GFP_COMP);
502 } else {
503 async->buf_page_list[i].virt_addr =
504 (void *)
505 get_zeroed_page(GFP_KERNEL);
506 }
507 if (async->buf_page_list[i].virt_addr == NULL)
508 break;
509
510 set_bit(PG_reserved,
511 &(virt_to_page(async->buf_page_list[i].
512 virt_addr)->flags));
513 pages[i] = virt_to_page(async->buf_page_list[i].
514 virt_addr);
515 }
516 }
517 if (i == n_pages) {
518 async->prealloc_buf =
519#ifdef PAGE_KERNEL_NOCACHE
520 vmap(pages, n_pages, VM_MAP, PAGE_KERNEL_NOCACHE);
521#else
522 vmap(pages, n_pages, VM_MAP, PAGE_KERNEL);
523#endif
524 }
525 vfree(pages);
526
527 if (async->prealloc_buf == NULL) {
528 /* Some allocation failed above. */
529 if (async->buf_page_list) {
530 for (i = 0; i < n_pages; i++) {
531 if (async->buf_page_list[i].virt_addr ==
532 NULL) {
533 break;
534 }
535 clear_bit(PG_reserved,
536 &(virt_to_page(async->
537 buf_page_list[i].
538 virt_addr)->flags));
539 if (s->async_dma_dir != DMA_NONE) {
540 dma_free_coherent(dev->hw_dev,
541 PAGE_SIZE,
542 async->
543 buf_page_list
544 [i].virt_addr,
545 async->
546 buf_page_list
547 [i].dma_addr);
548 } else {
549 free_page((unsigned long)
550 async->buf_page_list
551 [i].virt_addr);
552 }
553 }
554 vfree(async->buf_page_list);
555 async->buf_page_list = NULL;
556 }
557 return -ENOMEM;
558 }
559 async->n_buf_pages = n_pages;
560 }
561 async->prealloc_bufsz = new_size;
562
563 return 0;
564}
565 362
566/* munging is applied to data by core as it passes between user 363 for (driv = comedi_drivers; driv; driv = driv->next) {
567 * and kernel space */ 364 if (!try_module_get(driv->module))
568static unsigned int comedi_buf_munge(struct comedi_async *async, 365 continue;
569 unsigned int num_bytes) 366 if (driv->num_names) {
570{ 367 dev->board_ptr = comedi_recognize(driv, it->board_name);
571 struct comedi_subdevice *s = async->subdevice; 368 if (dev->board_ptr)
572 unsigned int count = 0; 369 break;
573 const unsigned num_sample_bytes = bytes_per_sample(s); 370 } else if (strcmp(driv->driver_name, it->board_name) == 0)
574
575 if (s->munge == NULL || (async->cmd.flags & CMDF_RAWDATA)) {
576 async->munge_count += num_bytes;
577 BUG_ON((int)(async->munge_count - async->buf_write_count) > 0);
578 return num_bytes;
579 }
580 /* don't munge partial samples */
581 num_bytes -= num_bytes % num_sample_bytes;
582 while (count < num_bytes) {
583 int block_size;
584
585 block_size = num_bytes - count;
586 if (block_size < 0) {
587 dev_warn(s->device->class_dev,
588 "%s: %s: bug! block_size is negative\n",
589 __FILE__, __func__);
590 break; 371 break;
591 } 372 module_put(driv->module);
592 if ((int)(async->munge_ptr + block_size -
593 async->prealloc_bufsz) > 0)
594 block_size = async->prealloc_bufsz - async->munge_ptr;
595
596 s->munge(s->device, s, async->prealloc_buf + async->munge_ptr,
597 block_size, async->munge_chan);
598
599 smp_wmb(); /* barrier insures data is munged in buffer
600 * before munge_count is incremented */
601
602 async->munge_chan += block_size / num_sample_bytes;
603 async->munge_chan %= async->cmd.chanlist_len;
604 async->munge_count += block_size;
605 async->munge_ptr += block_size;
606 async->munge_ptr %= async->prealloc_bufsz;
607 count += block_size;
608 }
609 BUG_ON((int)(async->munge_count - async->buf_write_count) > 0);
610 return count;
611}
612
613unsigned int comedi_buf_write_n_available(struct comedi_async *async)
614{
615 unsigned int free_end;
616 unsigned int nbytes;
617
618 if (async == NULL)
619 return 0;
620
621 free_end = async->buf_read_count + async->prealloc_bufsz;
622 nbytes = free_end - async->buf_write_alloc_count;
623 nbytes -= nbytes % bytes_per_sample(async->subdevice);
624 /* barrier insures the read of buf_read_count in this
625 query occurs before any following writes to the buffer which
626 might be based on the return value from this query.
627 */
628 smp_mb();
629 return nbytes;
630}
631
632/* allocates chunk for the writer from free buffer space */
633unsigned int comedi_buf_write_alloc(struct comedi_async *async,
634 unsigned int nbytes)
635{
636 unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
637
638 if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0)
639 nbytes = free_end - async->buf_write_alloc_count;
640
641 async->buf_write_alloc_count += nbytes;
642 /* barrier insures the read of buf_read_count above occurs before
643 we write data to the write-alloc'ed buffer space */
644 smp_mb();
645 return nbytes;
646}
647EXPORT_SYMBOL(comedi_buf_write_alloc);
648
649/* allocates nothing unless it can completely fulfill the request */
650unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async,
651 unsigned int nbytes)
652{
653 unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
654
655 if ((int)(async->buf_write_alloc_count + nbytes - free_end) > 0)
656 nbytes = 0;
657
658 async->buf_write_alloc_count += nbytes;
659 /* barrier insures the read of buf_read_count above occurs before
660 we write data to the write-alloc'ed buffer space */
661 smp_mb();
662 return nbytes;
663}
664
665/* transfers a chunk from writer to filled buffer space */
666unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes)
667{
668 if ((int)(async->buf_write_count + nbytes -
669 async->buf_write_alloc_count) > 0) {
670 dev_info(async->subdevice->device->class_dev,
671 "attempted to write-free more bytes than have been write-allocated.\n");
672 nbytes = async->buf_write_alloc_count - async->buf_write_count;
673 }
674 async->buf_write_count += nbytes;
675 async->buf_write_ptr += nbytes;
676 comedi_buf_munge(async, async->buf_write_count - async->munge_count);
677 if (async->buf_write_ptr >= async->prealloc_bufsz)
678 async->buf_write_ptr %= async->prealloc_bufsz;
679
680 return nbytes;
681}
682EXPORT_SYMBOL(comedi_buf_write_free);
683
684/* allocates a chunk for the reader from filled (and munged) buffer space */
685unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes)
686{
687 if ((int)(async->buf_read_alloc_count + nbytes - async->munge_count) >
688 0) {
689 nbytes = async->munge_count - async->buf_read_alloc_count;
690 }
691 async->buf_read_alloc_count += nbytes;
692 /* barrier insures read of munge_count occurs before we actually read
693 data out of buffer */
694 smp_rmb();
695 return nbytes;
696}
697EXPORT_SYMBOL(comedi_buf_read_alloc);
698
699/* transfers control of a chunk from reader to free buffer space */
700unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes)
701{
702 /* barrier insures data has been read out of
703 * buffer before read count is incremented */
704 smp_mb();
705 if ((int)(async->buf_read_count + nbytes -
706 async->buf_read_alloc_count) > 0) {
707 dev_info(async->subdevice->device->class_dev,
708 "attempted to read-free more bytes than have been read-allocated.\n");
709 nbytes = async->buf_read_alloc_count - async->buf_read_count;
710 } 373 }
711 async->buf_read_count += nbytes; 374 if (driv == NULL) {
712 async->buf_read_ptr += nbytes; 375 /* recognize has failed if we get here */
713 async->buf_read_ptr %= async->prealloc_bufsz; 376 /* report valid board names before returning error */
714 return nbytes; 377 for (driv = comedi_drivers; driv; driv = driv->next) {
715} 378 if (!try_module_get(driv->module))
716EXPORT_SYMBOL(comedi_buf_read_free); 379 continue;
717 380 comedi_report_boards(driv);
718void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, 381 module_put(driv->module);
719 const void *data, unsigned int num_bytes) 382 }
720{ 383 return -EIO;
721 unsigned int write_ptr = async->buf_write_ptr + offset;
722
723 if (write_ptr >= async->prealloc_bufsz)
724 write_ptr %= async->prealloc_bufsz;
725
726 while (num_bytes) {
727 unsigned int block_size;
728
729 if (write_ptr + num_bytes > async->prealloc_bufsz)
730 block_size = async->prealloc_bufsz - write_ptr;
731 else
732 block_size = num_bytes;
733
734 memcpy(async->prealloc_buf + write_ptr, data, block_size);
735
736 data += block_size;
737 num_bytes -= block_size;
738
739 write_ptr = 0;
740 } 384 }
741} 385 if (driv->attach == NULL) {
742EXPORT_SYMBOL(comedi_buf_memcpy_to); 386 /* driver does not support manual configuration */
743 387 dev_warn(dev->class_dev,
744void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, 388 "driver '%s' does not support attach using comedi_config\n",
745 void *dest, unsigned int nbytes) 389 driv->driver_name);
746{ 390 module_put(driv->module);
747 void *src; 391 return -ENOSYS;
748 unsigned int read_ptr = async->buf_read_ptr + offset;
749
750 if (read_ptr >= async->prealloc_bufsz)
751 read_ptr %= async->prealloc_bufsz;
752
753 while (nbytes) {
754 unsigned int block_size;
755
756 src = async->prealloc_buf + read_ptr;
757
758 if (nbytes >= async->prealloc_bufsz - read_ptr)
759 block_size = async->prealloc_bufsz - read_ptr;
760 else
761 block_size = nbytes;
762
763 memcpy(dest, src, block_size);
764 nbytes -= block_size;
765 dest += block_size;
766 read_ptr = 0;
767 } 392 }
768} 393 /* initialize dev->driver here so
769EXPORT_SYMBOL(comedi_buf_memcpy_from); 394 * comedi_error() can be called from attach */
770 395 dev->driver = driv;
771unsigned int comedi_buf_read_n_available(struct comedi_async *async) 396 ret = driv->attach(dev, it);
772{ 397 if (ret < 0) {
773 unsigned num_bytes; 398 module_put(dev->driver->module);
774 399 __comedi_device_detach(dev);
775 if (async == NULL) 400 return ret;
776 return 0;
777 num_bytes = async->munge_count - async->buf_read_count;
778 /* barrier insures the read of munge_count in this
779 query occurs before any following reads of the buffer which
780 might be based on the return value from this query.
781 */
782 smp_rmb();
783 return num_bytes;
784}
785EXPORT_SYMBOL(comedi_buf_read_n_available);
786
787int comedi_buf_get(struct comedi_async *async, short *x)
788{
789 unsigned int n = comedi_buf_read_n_available(async);
790
791 if (n < sizeof(short))
792 return 0;
793 comedi_buf_read_alloc(async, sizeof(short));
794 *x = *(short *)(async->prealloc_buf + async->buf_read_ptr);
795 comedi_buf_read_free(async, sizeof(short));
796 return 1;
797}
798EXPORT_SYMBOL(comedi_buf_get);
799
800int comedi_buf_put(struct comedi_async *async, short x)
801{
802 unsigned int n = comedi_buf_write_alloc_strict(async, sizeof(short));
803
804 if (n < sizeof(short)) {
805 async->events |= COMEDI_CB_ERROR;
806 return 0;
807 } 401 }
808 *(short *)(async->prealloc_buf + async->buf_write_ptr) = x; 402 return comedi_device_postconfig(dev);
809 comedi_buf_write_free(async, sizeof(short));
810 return 1;
811}
812EXPORT_SYMBOL(comedi_buf_put);
813
814void comedi_reset_async_buf(struct comedi_async *async)
815{
816 async->buf_write_alloc_count = 0;
817 async->buf_write_count = 0;
818 async->buf_read_alloc_count = 0;
819 async->buf_read_count = 0;
820
821 async->buf_write_ptr = 0;
822 async->buf_read_ptr = 0;
823
824 async->cur_chan = 0;
825 async->scan_progress = 0;
826 async->munge_chan = 0;
827 async->munge_count = 0;
828 async->munge_ptr = 0;
829
830 async->events = 0;
831} 403}
832 404
833int comedi_auto_config(struct device *hardware_device, 405int comedi_auto_config(struct device *hardware_device,
834 struct comedi_driver *driver, unsigned long context) 406 struct comedi_driver *driver, unsigned long context)
835{ 407{
836 int minor; 408 int minor;
837 struct comedi_device_file_info *dev_file_info;
838 struct comedi_device *comedi_dev; 409 struct comedi_device *comedi_dev;
839 int ret; 410 int ret;
840 411
841 if (!comedi_autoconfig)
842 return 0;
843
844 if (!driver->auto_attach) { 412 if (!driver->auto_attach) {
845 dev_warn(hardware_device, 413 dev_warn(hardware_device,
846 "BUG! comedi driver '%s' has no auto_attach handler\n", 414 "BUG! comedi driver '%s' has no auto_attach handler\n",
@@ -852,8 +420,7 @@ int comedi_auto_config(struct device *hardware_device,
852 if (minor < 0) 420 if (minor < 0)
853 return minor; 421 return minor;
854 422
855 dev_file_info = comedi_get_device_file_info(minor); 423 comedi_dev = comedi_dev_from_minor(minor);
856 comedi_dev = dev_file_info->device;
857 424
858 mutex_lock(&comedi_dev->mutex); 425 mutex_lock(&comedi_dev->mutex);
859 if (comedi_dev->attached) 426 if (comedi_dev->attached)
@@ -888,103 +455,53 @@ void comedi_auto_unconfig(struct device *hardware_device)
888 minor = comedi_find_board_minor(hardware_device); 455 minor = comedi_find_board_minor(hardware_device);
889 if (minor < 0) 456 if (minor < 0)
890 return; 457 return;
891 BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
892 comedi_free_board_minor(minor); 458 comedi_free_board_minor(minor);
893} 459}
894EXPORT_SYMBOL_GPL(comedi_auto_unconfig); 460EXPORT_SYMBOL_GPL(comedi_auto_unconfig);
895 461
896/** 462int comedi_driver_register(struct comedi_driver *driver)
897 * comedi_pci_enable() - Enable the PCI device and request the regions.
898 * @pdev: pci_dev struct
899 * @res_name: name for the requested reqource
900 */
901int comedi_pci_enable(struct pci_dev *pdev, const char *res_name)
902{
903 int rc;
904
905 rc = pci_enable_device(pdev);
906 if (rc < 0)
907 return rc;
908
909 rc = pci_request_regions(pdev, res_name);
910 if (rc < 0)
911 pci_disable_device(pdev);
912
913 return rc;
914}
915EXPORT_SYMBOL_GPL(comedi_pci_enable);
916
917/**
918 * comedi_pci_disable() - Release the regions and disable the PCI device.
919 * @pdev: pci_dev struct
920 *
921 * This must be matched with a previous successful call to comedi_pci_enable().
922 */
923void comedi_pci_disable(struct pci_dev *pdev)
924{
925 pci_release_regions(pdev);
926 pci_disable_device(pdev);
927}
928EXPORT_SYMBOL_GPL(comedi_pci_disable);
929
930int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
931 struct pci_driver *pci_driver)
932{ 463{
933 int ret; 464 driver->next = comedi_drivers;
934 465 comedi_drivers = driver;
935 ret = comedi_driver_register(comedi_driver);
936 if (ret < 0)
937 return ret;
938
939 /* FIXME: Remove this test after auditing all comedi pci drivers */
940 if (!pci_driver->name)
941 pci_driver->name = comedi_driver->driver_name;
942
943 ret = pci_register_driver(pci_driver);
944 if (ret < 0) {
945 comedi_driver_unregister(comedi_driver);
946 return ret;
947 }
948 466
949 return 0; 467 return 0;
950} 468}
951EXPORT_SYMBOL_GPL(comedi_pci_driver_register); 469EXPORT_SYMBOL(comedi_driver_register);
952 470
953void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver, 471int comedi_driver_unregister(struct comedi_driver *driver)
954 struct pci_driver *pci_driver)
955{ 472{
956 pci_unregister_driver(pci_driver); 473 struct comedi_driver *prev;
957 comedi_driver_unregister(comedi_driver); 474 int i;
958}
959EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister);
960
961#if IS_ENABLED(CONFIG_USB)
962 475
963int comedi_usb_driver_register(struct comedi_driver *comedi_driver, 476 /* check for devices using this driver */
964 struct usb_driver *usb_driver) 477 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
965{ 478 struct comedi_device *dev = comedi_dev_from_minor(i);
966 int ret;
967 479
968 ret = comedi_driver_register(comedi_driver); 480 if (!dev)
969 if (ret < 0) 481 continue;
970 return ret;
971 482
972 ret = usb_register(usb_driver); 483 mutex_lock(&dev->mutex);
973 if (ret < 0) { 484 if (dev->attached && dev->driver == driver) {
974 comedi_driver_unregister(comedi_driver); 485 if (dev->use_count)
975 return ret; 486 dev_warn(dev->class_dev,
487 "BUG! detaching device with use_count=%d\n",
488 dev->use_count);
489 comedi_device_detach(dev);
490 }
491 mutex_unlock(&dev->mutex);
976 } 492 }
977 493
978 return 0; 494 if (comedi_drivers == driver) {
979} 495 comedi_drivers = driver->next;
980EXPORT_SYMBOL_GPL(comedi_usb_driver_register); 496 return 0;
497 }
981 498
982void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver, 499 for (prev = comedi_drivers; prev->next; prev = prev->next) {
983 struct usb_driver *usb_driver) 500 if (prev->next == driver) {
984{ 501 prev->next = driver->next;
985 usb_deregister(usb_driver); 502 return 0;
986 comedi_driver_unregister(comedi_driver); 503 }
504 }
505 return -EINVAL;
987} 506}
988EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister); 507EXPORT_SYMBOL(comedi_driver_unregister);
989
990#endif
diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c
index e0a79521f35a..0ae356ae56ea 100644
--- a/drivers/staging/comedi/drivers/8255_pci.c
+++ b/drivers/staging/comedi/drivers/8255_pci.c
@@ -54,6 +54,8 @@ Interrupt support for these boards is also not currently supported.
54Configuration Options: not applicable, uses PCI auto config 54Configuration Options: not applicable, uses PCI auto config
55*/ 55*/
56 56
57#include <linux/pci.h>
58
57#include "../comedidev.h" 59#include "../comedidev.h"
58 60
59#include "8255.h" 61#include "8255.h"
@@ -314,11 +316,6 @@ static int pci_8255_pci_probe(struct pci_dev *dev,
314 return comedi_pci_auto_config(dev, &pci_8255_driver); 316 return comedi_pci_auto_config(dev, &pci_8255_driver);
315} 317}
316 318
317static void pci_8255_pci_remove(struct pci_dev *dev)
318{
319 comedi_pci_auto_unconfig(dev);
320}
321
322static DEFINE_PCI_DEVICE_TABLE(pci_8255_pci_table) = { 319static DEFINE_PCI_DEVICE_TABLE(pci_8255_pci_table) = {
323 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7224) }, 320 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7224) },
324 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7248) }, 321 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_ADLINK_PCI7248) },
@@ -342,7 +339,7 @@ static struct pci_driver pci_8255_pci_driver = {
342 .name = "8255_pci", 339 .name = "8255_pci",
343 .id_table = pci_8255_pci_table, 340 .id_table = pci_8255_pci_table,
344 .probe = pci_8255_pci_probe, 341 .probe = pci_8255_pci_probe,
345 .remove = pci_8255_pci_remove, 342 .remove = comedi_pci_auto_unconfig,
346}; 343};
347module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver); 344module_comedi_pci_driver(pci_8255_driver, pci_8255_pci_driver);
348 345
diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile
index 0de4d2eb76fc..315e836ff99b 100644
--- a/drivers/staging/comedi/drivers/Makefile
+++ b/drivers/staging/comedi/drivers/Makefile
@@ -2,7 +2,6 @@
2# 2#
3 3
4# Comedi "helper" modules 4# Comedi "helper" modules
5obj-$(CONFIG_COMEDI) += pcm_common.o
6 5
7# Comedi misc drivers 6# Comedi misc drivers
8obj-$(CONFIG_COMEDI_BOND) += comedi_bond.o 7obj-$(CONFIG_COMEDI_BOND) += comedi_bond.o
@@ -26,6 +25,7 @@ obj-$(CONFIG_COMEDI_PCM3730) += pcm3730.o
26obj-$(CONFIG_COMEDI_RTI800) += rti800.o 25obj-$(CONFIG_COMEDI_RTI800) += rti800.o
27obj-$(CONFIG_COMEDI_RTI802) += rti802.o 26obj-$(CONFIG_COMEDI_RTI802) += rti802.o
28obj-$(CONFIG_COMEDI_DAS16M1) += das16m1.o 27obj-$(CONFIG_COMEDI_DAS16M1) += das16m1.o
28obj-$(CONFIG_COMEDI_DAS08_ISA) += das08_isa.o
29obj-$(CONFIG_COMEDI_DAS16) += das16.o 29obj-$(CONFIG_COMEDI_DAS16) += das16.o
30obj-$(CONFIG_COMEDI_DAS800) += das800.o 30obj-$(CONFIG_COMEDI_DAS800) += das800.o
31obj-$(CONFIG_COMEDI_DAS1800) += das1800.o 31obj-$(CONFIG_COMEDI_DAS1800) += das1800.o
@@ -56,6 +56,7 @@ obj-$(CONFIG_COMEDI_POC) += poc.o
56 56
57# Comedi PCI drivers 57# Comedi PCI drivers
58obj-$(CONFIG_COMEDI_8255_PCI) += 8255_pci.o 58obj-$(CONFIG_COMEDI_8255_PCI) += 8255_pci.o
59obj-$(CONFIG_COMEDI_ADDI_WATCHDOG) += addi_watchdog.o
59obj-$(CONFIG_COMEDI_ADDI_APCI_035) += addi_apci_035.o 60obj-$(CONFIG_COMEDI_ADDI_APCI_035) += addi_apci_035.o
60obj-$(CONFIG_COMEDI_ADDI_APCI_1032) += addi_apci_1032.o 61obj-$(CONFIG_COMEDI_ADDI_APCI_1032) += addi_apci_1032.o
61obj-$(CONFIG_COMEDI_ADDI_APCI_1500) += addi_apci_1500.o 62obj-$(CONFIG_COMEDI_ADDI_APCI_1500) += addi_apci_1500.o
@@ -81,6 +82,7 @@ obj-$(CONFIG_COMEDI_AMPLC_PC263) += amplc_pc263.o
81obj-$(CONFIG_COMEDI_AMPLC_PCI224) += amplc_pci224.o 82obj-$(CONFIG_COMEDI_AMPLC_PCI224) += amplc_pci224.o
82obj-$(CONFIG_COMEDI_AMPLC_PCI230) += amplc_pci230.o 83obj-$(CONFIG_COMEDI_AMPLC_PCI230) += amplc_pci230.o
83obj-$(CONFIG_COMEDI_CONTEC_PCI_DIO) += contec_pci_dio.o 84obj-$(CONFIG_COMEDI_CONTEC_PCI_DIO) += contec_pci_dio.o
85obj-$(CONFIG_COMEDI_DAS08_PCI) += das08_pci.o
84obj-$(CONFIG_COMEDI_DT3000) += dt3000.o 86obj-$(CONFIG_COMEDI_DT3000) += dt3000.o
85obj-$(CONFIG_COMEDI_DYNA_PCI10XX) += dyna_pci10xx.o 87obj-$(CONFIG_COMEDI_DYNA_PCI10XX) += dyna_pci10xx.o
86obj-$(CONFIG_COMEDI_UNIOXX5) += unioxx5.o 88obj-$(CONFIG_COMEDI_UNIOXX5) += unioxx5.o
diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c b/drivers/staging/comedi/drivers/addi-data/addi_common.c
index 90cc43263aee..1051fa5ce8f7 100644
--- a/drivers/staging/comedi/drivers/addi-data/addi_common.c
+++ b/drivers/staging/comedi/drivers/addi-data/addi_common.c
@@ -11,13 +11,21 @@ Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
11 http://www.addi-data.com 11 http://www.addi-data.com
12 info@addi-data.com 12 info@addi-data.com
13 13
14This 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. 14This program is free software; you can redistribute it and/or modify it under
15the terms of the GNU General Public License as published by the Free Software
16Foundation; either version 2 of the License, or (at your option) any later
17version.
15 18
16This 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. 19This program is distributed in the hope that it will be useful, but WITHOUT ANY
20WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 22
18You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23You should have received a copy of the GNU General Public License along with
24this program; if not, write to the Free Software Foundation, Inc.,
2559 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 26
20You should also find the complete GPL in the COPYING file accompanying this source code. 27You should also find the complete GPL in the COPYING file accompanying this
28source code.
21 29
22@endverbatim 30@endverbatim
23*/ 31*/
@@ -29,10 +37,10 @@ You should also find the complete GPL in the COPYING file accompanying this sour
29 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com | 37 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
30 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com | 38 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31 +-----------------------------------------------------------------------+ 39 +-----------------------------------------------------------------------+
32 | Project : ADDI DATA | Compiler : GCC | 40 | Project : ADDI DATA | Compiler : GCC |
33 | Modulname : addi_common.c | Version : 2.96 | 41 | Modulname : addi_common.c | Version : 2.96 |
34 +-------------------------------+---------------------------------------+ 42 +-------------------------------+---------------------------------------+
35 | Author : | Date : | 43 | Author : | Date : |
36 +-----------------------------------------------------------------------+ 44 +-----------------------------------------------------------------------+
37 | Description : ADDI COMMON Main Module | 45 | Description : ADDI COMMON Main Module |
38 +-----------------------------------------------------------------------+ 46 +-----------------------------------------------------------------------+
@@ -167,11 +175,11 @@ static int addi_auto_attach(struct comedi_device *dev,
167 if (this_board->i_PCIEeprom) { 175 if (this_board->i_PCIEeprom) {
168 if (!(strcmp(this_board->pc_EepromChip, "S5920"))) { 176 if (!(strcmp(this_board->pc_EepromChip, "S5920"))) {
169 /* Set 3 wait stait */ 177 /* Set 3 wait stait */
170 if (!(strcmp(dev->board_name, "apci035"))) { 178 if (!(strcmp(dev->board_name, "apci035")))
171 outl(0x80808082, devpriv->i_IobaseAmcc + 0x60); 179 outl(0x80808082, devpriv->i_IobaseAmcc + 0x60);
172 } else { 180 else
173 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60); 181 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60);
174 } 182
175 /* Enable the interrupt for the controller */ 183 /* Enable the interrupt for the controller */
176 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38); 184 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38);
177 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38); 185 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38);
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c
deleted file mode 100644
index 5958a9cb2a38..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci16xx.c
+++ /dev/null
@@ -1,807 +0,0 @@
1/**
2@verbatim
3
4Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
5
6 ADDI-DATA GmbH
7 Dieselstrasse 3
8 D-77833 Ottersweier
9 Tel: +19(0)7223/9493-0
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
12 info@addi-data.com
13
14This 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.
15
16This 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.
17
18You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20You should also find the complete GPL in the COPYING file accompanying this source code.
21
22@endverbatim
23*/
24/*
25
26 +-----------------------------------------------------------------------+
27 | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier |
28 +-----------------------------------------------------------------------+
29 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
30 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31 +-----------------------------------------------------------------------+
32 | Project : API APCI1648 | Compiler : gcc |
33 | Module name : TTL.C | Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: S. Weber | Date : 25/05/2005 |
36 +-----------------------------------------------------------------------+
37 | Description : APCI-16XX TTL I/O module |
38 | |
39 | |
40 +-----------------------------------------------------------------------+
41 | UPDATES |
42 +-----------------------------------------------------------------------+
43 | Date | Author | Description of updates |
44 +----------+-----------+------------------------------------------------+
45 |25.05.2005| S.Weber | Creation |
46 | | | |
47 +-----------------------------------------------------------------------+
48*/
49
50#ifndef COMEDI_SUBD_TTLIO
51#define COMEDI_SUBD_TTLIO 11 /* Digital Input Output But TTL */
52#endif
53
54#define APCI16XX_TTL_INIT 0
55#define APCI16XX_TTL_INITDIRECTION 1
56#define APCI16XX_TTL_OUTPUTMEMORY 2
57
58#define APCI16XX_TTL_READCHANNEL 0
59#define APCI16XX_TTL_READPORT 1
60
61#define APCI16XX_TTL_WRITECHANNEL_ON 0
62#define APCI16XX_TTL_WRITECHANNEL_OFF 1
63#define APCI16XX_TTL_WRITEPORT_ON 2
64#define APCI16XX_TTL_WRITEPORT_OFF 3
65
66#define APCI16XX_TTL_READ_ALL_INPUTS 0
67#define APCI16XX_TTL_READ_ALL_OUTPUTS 1
68
69/*
70+----------------------------------------------------------------------------+
71| Function Name : int i_APCI16XX_InsnConfigInitTTLIO |
72| (struct comedi_device *dev, |
73| struct comedi_subdevice *s, |
74| struct comedi_insn *insn, |
75| unsigned int *data) |
76+----------------------------------------------------------------------------+
77| Task APCI16XX_TTL_INIT (using defaults) : |
78| Configure the TTL I/O operating mode from all ports |
79| You must calling this function be |
80| for you call any other function witch access of TTL. |
81| APCI16XX_TTL_INITDIRECTION(user inputs for direction) |
82+----------------------------------------------------------------------------+
83| Input Parameters : b_InitType = (unsigned char) data[0]; |
84| b_Port0Mode = (unsigned char) data[1]; |
85| b_Port1Mode = (unsigned char) data[2]; |
86| b_Port2Mode = (unsigned char) data[3]; |
87| b_Port3Mode = (unsigned char) data[4]; |
88| ........ |
89+----------------------------------------------------------------------------+
90| Output Parameters : - |
91+----------------------------------------------------------------------------+
92| Return Value :>0: No error |
93| -1: Port 0 mode selection is wrong |
94| -2: Port 1 mode selection is wrong |
95| -3: Port 2 mode selection is wrong |
96| -4: Port 3 mode selection is wrong |
97| -X: Port X-1 mode selection is wrong |
98| .... |
99| -100 : Config command error |
100| -101 : Data size error |
101+----------------------------------------------------------------------------+
102*/
103
104static int i_APCI16XX_InsnConfigInitTTLIO(struct comedi_device *dev,
105 struct comedi_subdevice *s,
106 struct comedi_insn *insn,
107 unsigned int *data)
108{
109 const struct addi_board *this_board = comedi_board(dev);
110 struct addi_private *devpriv = dev->private;
111 int i_ReturnValue = insn->n;
112 unsigned char b_Command = 0;
113 unsigned char b_Cpt = 0;
114 unsigned char b_NumberOfPort =
115 (unsigned char) (this_board->i_NbrTTLChannel / 8);
116
117 /************************/
118 /* Test the buffer size */
119 /************************/
120
121 if (insn->n >= 1) {
122 /*******************/
123 /* Get the command */
124 /* **************** */
125
126 b_Command = (unsigned char) data[0];
127
128 /********************/
129 /* Test the command */
130 /********************/
131
132 if ((b_Command == APCI16XX_TTL_INIT) ||
133 (b_Command == APCI16XX_TTL_INITDIRECTION) ||
134 (b_Command == APCI16XX_TTL_OUTPUTMEMORY)) {
135 /***************************************/
136 /* Test the initialisation buffer size */
137 /***************************************/
138
139 if ((b_Command == APCI16XX_TTL_INITDIRECTION)
140 && ((unsigned char) (insn->n - 1) != b_NumberOfPort)) {
141 /*******************/
142 /* Data size error */
143 /*******************/
144
145 printk("\nBuffer size error");
146 i_ReturnValue = -101;
147 }
148
149 if ((b_Command == APCI16XX_TTL_OUTPUTMEMORY)
150 && ((unsigned char) (insn->n) != 2)) {
151 /*******************/
152 /* Data size error */
153 /*******************/
154
155 printk("\nBuffer size error");
156 i_ReturnValue = -101;
157 }
158 } else {
159 /************************/
160 /* Config command error */
161 /************************/
162
163 printk("\nCommand selection error");
164 i_ReturnValue = -100;
165 }
166 } else {
167 /*******************/
168 /* Data size error */
169 /*******************/
170
171 printk("\nBuffer size error");
172 i_ReturnValue = -101;
173 }
174
175 /**************************************************************************/
176 /* Test if no error occur and APCI16XX_TTL_INITDIRECTION command selected */
177 /**************************************************************************/
178
179 if ((i_ReturnValue >= 0) && (b_Command == APCI16XX_TTL_INITDIRECTION)) {
180 memset(devpriv->ul_TTLPortConfiguration, 0,
181 sizeof(devpriv->ul_TTLPortConfiguration));
182
183 /*************************************/
184 /* Test the port direction selection */
185 /*************************************/
186
187 for (b_Cpt = 1;
188 (b_Cpt <= b_NumberOfPort) && (i_ReturnValue >= 0);
189 b_Cpt++) {
190 /**********************/
191 /* Test the direction */
192 /**********************/
193
194 if ((data[b_Cpt] != 0) && (data[b_Cpt] != 0xFF)) {
195 /************************/
196 /* Port direction error */
197 /************************/
198
199 printk("\nPort %d direction selection error",
200 (int) b_Cpt);
201 i_ReturnValue = -(int) b_Cpt;
202 }
203
204 /**************************/
205 /* Save the configuration */
206 /**************************/
207
208 devpriv->ul_TTLPortConfiguration[(b_Cpt - 1) / 4] =
209 devpriv->ul_TTLPortConfiguration[(b_Cpt -
210 1) / 4] | (data[b_Cpt] << (8 * ((b_Cpt -
211 1) % 4)));
212 }
213 }
214
215 /**************************/
216 /* Test if no error occur */
217 /**************************/
218
219 if (i_ReturnValue >= 0) {
220 /***********************************/
221 /* Test if TTL port initilaisation */
222 /***********************************/
223
224 if ((b_Command == APCI16XX_TTL_INIT)
225 || (b_Command == APCI16XX_TTL_INITDIRECTION)) {
226 /******************************/
227 /* Set all port configuration */
228 /******************************/
229
230 for (b_Cpt = 0; b_Cpt <= b_NumberOfPort; b_Cpt++) {
231 if ((b_Cpt % 4) == 0) {
232 /*************************/
233 /* Set the configuration */
234 /*************************/
235
236 outl(devpriv->
237 ul_TTLPortConfiguration[b_Cpt /
238 4],
239 devpriv->iobase + 32 + b_Cpt);
240 }
241 }
242 }
243 }
244
245 /************************************************/
246 /* Test if output memory initialisation command */
247 /************************************************/
248
249 if (b_Command == APCI16XX_TTL_OUTPUTMEMORY) {
250 if (data[1]) {
251 devpriv->b_OutputMemoryStatus = ADDIDATA_ENABLE;
252 } else {
253 devpriv->b_OutputMemoryStatus = ADDIDATA_DISABLE;
254 }
255 }
256
257 return i_ReturnValue;
258}
259
260/*
261+----------------------------------------------------------------------------+
262| INPUT FUNCTIONS |
263+----------------------------------------------------------------------------+
264*/
265
266/*
267+----------------------------------------------------------------------------+
268| Function Name : int i_APCI16XX_InsnBitsReadTTLIO |
269| (struct comedi_device *dev, |
270| struct comedi_subdevice *s, |
271| struct comedi_insn *insn, |
272| unsigned int *data) |
273+----------------------------------------------------------------------------+
274| Task : Read the status from selected TTL digital input |
275| (b_InputChannel) |
276+----------------------------------------------------------------------------+
277| Task : Read the status from digital input port |
278| (b_SelectedPort) |
279+----------------------------------------------------------------------------+
280| Input Parameters : |
281| APCI16XX_TTL_READCHANNEL |
282| b_SelectedPort= CR_RANGE(insn->chanspec); |
283| b_InputChannel= CR_CHAN(insn->chanspec); |
284| b_ReadType = (unsigned char) data[0]; |
285| |
286| APCI16XX_TTL_READPORT |
287| b_SelectedPort= CR_RANGE(insn->chanspec); |
288| b_ReadType = (unsigned char) data[0]; |
289+----------------------------------------------------------------------------+
290| Output Parameters : data[0] 0 : Channle is not active |
291| 1 : Channle is active |
292+----------------------------------------------------------------------------+
293| Return Value : >0 : No error |
294| -100 : Config command error |
295| -101 : Data size error |
296| -102 : The selected TTL input port is wrong |
297| -103 : The selected TTL digital input is wrong |
298+----------------------------------------------------------------------------+
299*/
300
301static int i_APCI16XX_InsnBitsReadTTLIO(struct comedi_device *dev,
302 struct comedi_subdevice *s,
303 struct comedi_insn *insn,
304 unsigned int *data)
305{
306 const struct addi_board *this_board = comedi_board(dev);
307 struct addi_private *devpriv = dev->private;
308 int i_ReturnValue = insn->n;
309 unsigned char b_Command = 0;
310 unsigned char b_NumberOfPort =
311 (unsigned char) (this_board->i_NbrTTLChannel / 8);
312 unsigned char b_SelectedPort = CR_RANGE(insn->chanspec);
313 unsigned char b_InputChannel = CR_CHAN(insn->chanspec);
314 unsigned char *pb_Status;
315 unsigned int dw_Status;
316
317 /************************/
318 /* Test the buffer size */
319 /************************/
320
321 if (insn->n >= 1) {
322 /*******************/
323 /* Get the command */
324 /* **************** */
325
326 b_Command = (unsigned char) data[0];
327
328 /********************/
329 /* Test the command */
330 /********************/
331
332 if ((b_Command == APCI16XX_TTL_READCHANNEL)
333 || (b_Command == APCI16XX_TTL_READPORT)) {
334 /**************************/
335 /* Test the selected port */
336 /**************************/
337
338 if (b_SelectedPort < b_NumberOfPort) {
339 /**********************/
340 /* Test if input port */
341 /**********************/
342
343 if (((devpriv->ul_TTLPortConfiguration
344 [b_SelectedPort /
345 4] >> (8 *
346 (b_SelectedPort
347 %
348 4))) &
349 0xFF) == 0) {
350 /***************************/
351 /* Test the channel number */
352 /***************************/
353
354 if ((b_Command ==
355 APCI16XX_TTL_READCHANNEL)
356 && (b_InputChannel > 7)) {
357 /*******************************************/
358 /* The selected TTL digital input is wrong */
359 /*******************************************/
360
361 printk("\nChannel selection error");
362 i_ReturnValue = -103;
363 }
364 } else {
365 /****************************************/
366 /* The selected TTL input port is wrong */
367 /****************************************/
368
369 printk("\nPort selection error");
370 i_ReturnValue = -102;
371 }
372 } else {
373 /****************************************/
374 /* The selected TTL input port is wrong */
375 /****************************************/
376
377 printk("\nPort selection error");
378 i_ReturnValue = -102;
379 }
380 } else {
381 /************************/
382 /* Config command error */
383 /************************/
384
385 printk("\nCommand selection error");
386 i_ReturnValue = -100;
387 }
388 } else {
389 /*******************/
390 /* Data size error */
391 /*******************/
392
393 printk("\nBuffer size error");
394 i_ReturnValue = -101;
395 }
396
397 /**************************/
398 /* Test if no error occur */
399 /**************************/
400
401 if (i_ReturnValue >= 0) {
402 pb_Status = (unsigned char *) &data[0];
403
404 /*******************************/
405 /* Get the digital inpu status */
406 /*******************************/
407
408 dw_Status =
409 inl(devpriv->iobase + 8 + ((b_SelectedPort / 4) * 4));
410 dw_Status = (dw_Status >> (8 * (b_SelectedPort % 4))) & 0xFF;
411
412 /***********************/
413 /* Save the port value */
414 /***********************/
415
416 *pb_Status = (unsigned char) dw_Status;
417
418 /***************************************/
419 /* Test if read channel status command */
420 /***************************************/
421
422 if (b_Command == APCI16XX_TTL_READCHANNEL) {
423 *pb_Status = (*pb_Status >> b_InputChannel) & 1;
424 }
425 }
426
427 return i_ReturnValue;
428}
429
430/*
431+----------------------------------------------------------------------------+
432| Function Name : int i_APCI16XX_InsnReadTTLIOAllPortValue |
433| (struct comedi_device *dev, |
434| struct comedi_subdevice *s, |
435| struct comedi_insn *insn, |
436| unsigned int *data) |
437+----------------------------------------------------------------------------+
438| Task : Read the status from all digital input ports |
439+----------------------------------------------------------------------------+
440| Input Parameters : - |
441+----------------------------------------------------------------------------+
442| Output Parameters : data[0] : Port 0 to 3 data |
443| data[1] : Port 4 to 7 data |
444| .... |
445+----------------------------------------------------------------------------+
446| Return Value : 0: No error |
447| -100 : Read command error |
448| -101 : Data size error |
449+----------------------------------------------------------------------------+
450*/
451
452static int i_APCI16XX_InsnReadTTLIOAllPortValue(struct comedi_device *dev,
453 struct comedi_subdevice *s,
454 struct comedi_insn *insn,
455 unsigned int *data)
456{
457 const struct addi_board *this_board = comedi_board(dev);
458 struct addi_private *devpriv = dev->private;
459 unsigned char b_Command = (unsigned char) CR_AREF(insn->chanspec);
460 int i_ReturnValue = insn->n;
461 unsigned char b_Cpt = 0;
462 unsigned char b_NumberOfPort = 0;
463 unsigned int *pls_ReadData = data;
464
465 /********************/
466 /* Test the command */
467 /********************/
468
469 if ((b_Command == APCI16XX_TTL_READ_ALL_INPUTS)
470 || (b_Command == APCI16XX_TTL_READ_ALL_OUTPUTS)) {
471 /**********************************/
472 /* Get the number of 32-Bit ports */
473 /**********************************/
474
475 b_NumberOfPort =
476 (unsigned char) (this_board->i_NbrTTLChannel / 32);
477 if ((b_NumberOfPort * 32) <
478 this_board->i_NbrTTLChannel) {
479 b_NumberOfPort = b_NumberOfPort + 1;
480 }
481
482 /************************/
483 /* Test the buffer size */
484 /************************/
485
486 if (insn->n >= b_NumberOfPort) {
487 if (b_Command == APCI16XX_TTL_READ_ALL_INPUTS) {
488 /**************************/
489 /* Read all digital input */
490 /**************************/
491
492 for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) {
493 /************************/
494 /* Read the 32-Bit port */
495 /************************/
496
497 pls_ReadData[b_Cpt] =
498 inl(devpriv->iobase + 8 +
499 (b_Cpt * 4));
500
501 /**************************************/
502 /* Mask all channels used als outputs */
503 /**************************************/
504
505 pls_ReadData[b_Cpt] =
506 pls_ReadData[b_Cpt] &
507 (~devpriv->
508 ul_TTLPortConfiguration[b_Cpt]);
509 }
510 } else {
511 /****************************/
512 /* Read all digital outputs */
513 /****************************/
514
515 for (b_Cpt = 0; b_Cpt < b_NumberOfPort; b_Cpt++) {
516 /************************/
517 /* Read the 32-Bit port */
518 /************************/
519
520 pls_ReadData[b_Cpt] =
521 inl(devpriv->iobase + 20 +
522 (b_Cpt * 4));
523
524 /**************************************/
525 /* Mask all channels used als outputs */
526 /**************************************/
527
528 pls_ReadData[b_Cpt] =
529 pls_ReadData[b_Cpt] & devpriv->
530 ul_TTLPortConfiguration[b_Cpt];
531 }
532 }
533 } else {
534 /*******************/
535 /* Data size error */
536 /*******************/
537
538 printk("\nBuffer size error");
539 i_ReturnValue = -101;
540 }
541 } else {
542 /*****************/
543 /* Command error */
544 /*****************/
545
546 printk("\nCommand selection error");
547 i_ReturnValue = -100;
548 }
549
550 return i_ReturnValue;
551}
552
553/*
554+----------------------------------------------------------------------------+
555| OUTPUT FUNCTIONS |
556+----------------------------------------------------------------------------+
557*/
558
559/*
560+----------------------------------------------------------------------------+
561| Function Name : int i_APCI16XX_InsnBitsWriteTTLIO |
562| (struct comedi_device *dev, |
563| struct comedi_subdevice *s, |
564| struct comedi_insn *insn, |
565| unsigned int *data) |
566+----------------------------------------------------------------------------+
567| Task : Set the state from selected TTL digital output |
568| (b_OutputChannel) |
569+----------------------------------------------------------------------------+
570| Task : Set the state from digital output port |
571| (b_SelectedPort) |
572+----------------------------------------------------------------------------+
573| Input Parameters : |
574| APCI16XX_TTL_WRITECHANNEL_ON | APCI16XX_TTL_WRITECHANNEL_OFF |
575| b_SelectedPort = CR_RANGE(insn->chanspec); |
576| b_OutputChannel= CR_CHAN(insn->chanspec); |
577| b_Command = (unsigned char) data[0]; |
578| |
579| APCI16XX_TTL_WRITEPORT_ON | APCI16XX_TTL_WRITEPORT_OFF |
580| b_SelectedPort = CR_RANGE(insn->chanspec); |
581| b_Command = (unsigned char) data[0]; |
582+----------------------------------------------------------------------------+
583| Output Parameters : data[0] : TTL output port 0 to 3 data |
584| data[1] : TTL output port 4 to 7 data |
585| .... |
586+----------------------------------------------------------------------------+
587| Return Value : >0 : No error |
588| -100 : Command error |
589| -101 : Data size error |
590| -102 : The selected TTL output port is wrong |
591| -103 : The selected TTL digital output is wrong |
592| -104 : Output memory disabled |
593+----------------------------------------------------------------------------+
594*/
595
596static int i_APCI16XX_InsnBitsWriteTTLIO(struct comedi_device *dev,
597 struct comedi_subdevice *s,
598 struct comedi_insn *insn,
599 unsigned int *data)
600{
601 const struct addi_board *this_board = comedi_board(dev);
602 struct addi_private *devpriv = dev->private;
603 int i_ReturnValue = insn->n;
604 unsigned char b_Command = 0;
605 unsigned char b_NumberOfPort =
606 (unsigned char) (this_board->i_NbrTTLChannel / 8);
607 unsigned char b_SelectedPort = CR_RANGE(insn->chanspec);
608 unsigned char b_OutputChannel = CR_CHAN(insn->chanspec);
609 unsigned int dw_Status = 0;
610
611 /************************/
612 /* Test the buffer size */
613 /************************/
614
615 if (insn->n >= 1) {
616 /*******************/
617 /* Get the command */
618 /* **************** */
619
620 b_Command = (unsigned char) data[0];
621
622 /********************/
623 /* Test the command */
624 /********************/
625
626 if ((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) ||
627 (b_Command == APCI16XX_TTL_WRITEPORT_ON) ||
628 (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) ||
629 (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) {
630 /**************************/
631 /* Test the selected port */
632 /**************************/
633
634 if (b_SelectedPort < b_NumberOfPort) {
635 /***********************/
636 /* Test if output port */
637 /***********************/
638
639 if (((devpriv->ul_TTLPortConfiguration
640 [b_SelectedPort /
641 4] >> (8 *
642 (b_SelectedPort
643 %
644 4))) &
645 0xFF) == 0xFF) {
646 /***************************/
647 /* Test the channel number */
648 /***************************/
649
650 if (((b_Command == APCI16XX_TTL_WRITECHANNEL_ON) || (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF)) && (b_OutputChannel > 7)) {
651 /********************************************/
652 /* The selected TTL digital output is wrong */
653 /********************************************/
654
655 printk("\nChannel selection error");
656 i_ReturnValue = -103;
657 }
658
659 if (((b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE)) {
660 /********************************************/
661 /* The selected TTL digital output is wrong */
662 /********************************************/
663
664 printk("\nOutput memory disabled");
665 i_ReturnValue = -104;
666 }
667
668 /************************/
669 /* Test the buffer size */
670 /************************/
671
672 if (((b_Command == APCI16XX_TTL_WRITEPORT_ON) || (b_Command == APCI16XX_TTL_WRITEPORT_OFF)) && (insn->n < 2)) {
673 /*******************/
674 /* Data size error */
675 /*******************/
676
677 printk("\nBuffer size error");
678 i_ReturnValue = -101;
679 }
680 } else {
681 /*****************************************/
682 /* The selected TTL output port is wrong */
683 /*****************************************/
684
685 printk("\nPort selection error %lX",
686 (unsigned long)devpriv->
687 ul_TTLPortConfiguration[0]);
688 i_ReturnValue = -102;
689 }
690 } else {
691 /****************************************/
692 /* The selected TTL output port is wrong */
693 /****************************************/
694
695 printk("\nPort selection error %d %d",
696 b_SelectedPort, b_NumberOfPort);
697 i_ReturnValue = -102;
698 }
699 } else {
700 /************************/
701 /* Config command error */
702 /************************/
703
704 printk("\nCommand selection error");
705 i_ReturnValue = -100;
706 }
707 } else {
708 /*******************/
709 /* Data size error */
710 /*******************/
711
712 printk("\nBuffer size error");
713 i_ReturnValue = -101;
714 }
715
716 /**************************/
717 /* Test if no error occur */
718 /**************************/
719
720 if (i_ReturnValue >= 0) {
721 /********************************/
722 /* Get the digital output state */
723 /********************************/
724
725 dw_Status =
726 inl(devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));
727
728 /**********************************/
729 /* Test if output memory not used */
730 /**********************************/
731
732 if (devpriv->b_OutputMemoryStatus == ADDIDATA_DISABLE) {
733 /*********************************/
734 /* Clear the selected port value */
735 /*********************************/
736
737 dw_Status =
738 dw_Status & (0xFFFFFFFFUL -
739 (0xFFUL << (8 * (b_SelectedPort % 4))));
740 }
741
742 /******************************/
743 /* Test if setting channel ON */
744 /******************************/
745
746 if (b_Command == APCI16XX_TTL_WRITECHANNEL_ON) {
747 dw_Status =
748 dw_Status | (1UL << ((8 * (b_SelectedPort %
749 4)) + b_OutputChannel));
750 }
751
752 /***************************/
753 /* Test if setting port ON */
754 /***************************/
755
756 if (b_Command == APCI16XX_TTL_WRITEPORT_ON) {
757 dw_Status =
758 dw_Status | ((data[1] & 0xFF) << (8 *
759 (b_SelectedPort % 4)));
760 }
761
762 /*******************************/
763 /* Test if setting channel OFF */
764 /*******************************/
765
766 if (b_Command == APCI16XX_TTL_WRITECHANNEL_OFF) {
767 dw_Status =
768 dw_Status & (0xFFFFFFFFUL -
769 (1UL << ((8 * (b_SelectedPort % 4)) +
770 b_OutputChannel)));
771 }
772
773 /****************************/
774 /* Test if setting port OFF */
775 /****************************/
776
777 if (b_Command == APCI16XX_TTL_WRITEPORT_OFF) {
778 dw_Status =
779 dw_Status & (0xFFFFFFFFUL -
780 ((data[1] & 0xFF) << (8 * (b_SelectedPort %
781 4))));
782 }
783
784 outl(dw_Status,
785 devpriv->iobase + 20 + ((b_SelectedPort / 4) * 4));
786 }
787
788 return i_ReturnValue;
789}
790
791/*
792+----------------------------------------------------------------------------+
793| Function Name : int i_APCI2200_Reset(struct comedi_device *dev) | +----------------------------------------------------------------------------+
794| Task :resets all the registers |
795+----------------------------------------------------------------------------+
796| Input Parameters : struct comedi_device *dev |
797+----------------------------------------------------------------------------+
798| Output Parameters : - |
799+----------------------------------------------------------------------------+
800| Return Value : - |
801+----------------------------------------------------------------------------+
802*/
803
804static int i_APCI16XX_Reset(struct comedi_device *dev)
805{
806 return 0;
807}
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c
deleted file mode 100644
index 9d4a117aad43..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci2200.c
+++ /dev/null
@@ -1,263 +0,0 @@
1/**
2@verbatim
3
4Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
5
6 ADDI-DATA GmbH
7 Dieselstrasse 3
8 D-77833 Ottersweier
9 Tel: +19(0)7223/9493-0
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
12 info@addi-data.com
13
14This 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.
15
16This 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.
17
18You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20You should also find the complete GPL in the COPYING file accompanying this source code.
21
22@endverbatim
23*/
24/*
25
26 +-----------------------------------------------------------------------+
27 | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier |
28 +-----------------------------------------------------------------------+
29 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
30 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31 +-------------------------------+---------------------------------------+
32 | Project : APCI-2200 | Compiler : GCC |
33 | Module name : hwdrv_apci2200.c| Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: Eric Stolz | Date : 02/12/2002 |
36 +-------------------------------+---------------------------------------+
37 | Description : Hardware Layer Access For APCI-2200 |
38 +-----------------------------------------------------------------------+
39 | UPDATES |
40 +----------+-----------+------------------------------------------------+
41 | Date | Author | Description of updates |
42 +----------+-----------+------------------------------------------------+
43 | | | |
44 | | | |
45 | | | |
46 +----------+-----------+------------------------------------------------+
47*/
48
49/********* Definitions for APCI-2200 card *****/
50
51/* Card Specific information */
52#define APCI2200_ADDRESS_RANGE 64
53
54/* DIGITAL INPUT-OUTPUT DEFINE */
55
56#define APCI2200_DIGITAL_OP 4
57#define APCI2200_DIGITAL_IP 0
58
59/* TIMER COUNTER WATCHDOG DEFINES */
60
61#define APCI2200_WATCHDOG 0x08
62#define APCI2200_WATCHDOG_ENABLEDISABLE 12
63#define APCI2200_WATCHDOG_RELOAD_VALUE 4
64#define APCI2200_WATCHDOG_STATUS 16
65
66static int apci2200_di_insn_bits(struct comedi_device *dev,
67 struct comedi_subdevice *s,
68 struct comedi_insn *insn,
69 unsigned int *data)
70{
71 struct addi_private *devpriv = dev->private;
72
73 data[1] = inw(devpriv->iobase + APCI2200_DIGITAL_IP);
74
75 return insn->n;
76}
77
78static int apci2200_do_insn_bits(struct comedi_device *dev,
79 struct comedi_subdevice *s,
80 struct comedi_insn *insn,
81 unsigned int *data)
82{
83 struct addi_private *devpriv = dev->private;
84 unsigned int mask = data[0];
85 unsigned int bits = data[1];
86
87 s->state = inw(devpriv->iobase + APCI2200_DIGITAL_OP);
88 if (mask) {
89 s->state &= ~mask;
90 s->state |= (bits & mask);
91
92 outw(s->state, devpriv->iobase + APCI2200_DIGITAL_OP);
93 }
94
95 data[1] = s->state;
96
97 return insn->n;
98}
99
100/*
101+----------------------------------------------------------------------------+
102| Function Name : int i_APCI2200_ConfigWatchdog(struct comedi_device *dev,
103| struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data) |
104| |
105+----------------------------------------------------------------------------+
106| Task : Configures The Watchdog |
107+----------------------------------------------------------------------------+
108| Input Parameters : struct comedi_device *dev : Driver handle |
109| struct comedi_subdevice *s, :pointer to subdevice structure
110| struct comedi_insn *insn :pointer to insn structure |
111| unsigned int *data : Data Pointer to read status |
112+----------------------------------------------------------------------------+
113| Output Parameters : -- |
114+----------------------------------------------------------------------------+
115| Return Value : TRUE : No error occur |
116| : FALSE : Error occur. Return the error |
117| |
118+----------------------------------------------------------------------------+
119*/
120
121static int i_APCI2200_ConfigWatchdog(struct comedi_device *dev,
122 struct comedi_subdevice *s,
123 struct comedi_insn *insn,
124 unsigned int *data)
125{
126 struct addi_private *devpriv = dev->private;
127
128 if (data[0] == 0) {
129 /* Disable the watchdog */
130 outw(0x0,
131 devpriv->iobase + APCI2200_WATCHDOG +
132 APCI2200_WATCHDOG_ENABLEDISABLE);
133 /* Loading the Reload value */
134 outw(data[1],
135 devpriv->iobase + APCI2200_WATCHDOG +
136 APCI2200_WATCHDOG_RELOAD_VALUE);
137 data[1] = data[1] >> 16;
138 outw(data[1],
139 devpriv->iobase + APCI2200_WATCHDOG +
140 APCI2200_WATCHDOG_RELOAD_VALUE + 2);
141 } /* if(data[0]==0) */
142 else {
143 printk("\nThe input parameters are wrong\n");
144 return -EINVAL;
145 } /* elseif(data[0]==0) */
146
147 return insn->n;
148}
149
150 /*
151 +----------------------------------------------------------------------------+
152 | Function Name : int i_APCI2200_StartStopWriteWatchdog |
153 | (struct comedi_device *dev,struct comedi_subdevice *s,
154 struct comedi_insn *insn,unsigned int *data); |
155 +----------------------------------------------------------------------------+
156 | Task : Start / Stop The Watchdog |
157 +----------------------------------------------------------------------------+
158 | Input Parameters : struct comedi_device *dev : Driver handle |
159 | struct comedi_subdevice *s, :pointer to subdevice structure
160 struct comedi_insn *insn :pointer to insn structure |
161 | unsigned int *data : Data Pointer to read status |
162 +----------------------------------------------------------------------------+
163 | Output Parameters : -- |
164 +----------------------------------------------------------------------------+
165 | Return Value : TRUE : No error occur |
166 | : FALSE : Error occur. Return the error |
167 | |
168 +----------------------------------------------------------------------------+
169 */
170
171static int i_APCI2200_StartStopWriteWatchdog(struct comedi_device *dev,
172 struct comedi_subdevice *s,
173 struct comedi_insn *insn,
174 unsigned int *data)
175{
176 struct addi_private *devpriv = dev->private;
177
178 switch (data[0]) {
179 case 0: /* stop the watchdog */
180 outw(0x0, devpriv->iobase + APCI2200_WATCHDOG + APCI2200_WATCHDOG_ENABLEDISABLE); /* disable the watchdog */
181 break;
182 case 1: /* start the watchdog */
183 outw(0x0001,
184 devpriv->iobase + APCI2200_WATCHDOG +
185 APCI2200_WATCHDOG_ENABLEDISABLE);
186 break;
187 case 2: /* Software trigger */
188 outw(0x0201,
189 devpriv->iobase + APCI2200_WATCHDOG +
190 APCI2200_WATCHDOG_ENABLEDISABLE);
191 break;
192 default:
193 printk("\nSpecified functionality does not exist\n");
194 return -EINVAL;
195 } /* switch(data[0]) */
196 return insn->n;
197}
198
199/*
200+----------------------------------------------------------------------------+
201| Function Name : int i_APCI2200_ReadWatchdog |
202| (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,
203| unsigned int *data); |
204+----------------------------------------------------------------------------+
205| Task : Read The Watchdog |
206+----------------------------------------------------------------------------+
207| Input Parameters : struct comedi_device *dev : Driver handle |
208| struct comedi_subdevice *s, :pointer to subdevice structure
209| struct comedi_insn *insn :pointer to insn structure |
210| unsigned int *data : Data Pointer to read status |
211+----------------------------------------------------------------------------+
212| Output Parameters : -- |
213+----------------------------------------------------------------------------+
214| Return Value : TRUE : No error occur |
215| : FALSE : Error occur. Return the error |
216| |
217+----------------------------------------------------------------------------+
218*/
219
220static int i_APCI2200_ReadWatchdog(struct comedi_device *dev,
221 struct comedi_subdevice *s,
222 struct comedi_insn *insn,
223 unsigned int *data)
224{
225 struct addi_private *devpriv = dev->private;
226
227 data[0] =
228 inw(devpriv->iobase + APCI2200_WATCHDOG +
229 APCI2200_WATCHDOG_STATUS) & 0x1;
230 return insn->n;
231}
232
233/*
234+----------------------------------------------------------------------------+
235| Function Name : int i_APCI2200_Reset(struct comedi_device *dev) | |
236+----------------------------------------------------------------------------+
237| Task :resets all the registers |
238+----------------------------------------------------------------------------+
239| Input Parameters : struct comedi_device *dev
240+----------------------------------------------------------------------------+
241| Output Parameters : -- |
242+----------------------------------------------------------------------------+
243| Return Value : |
244| |
245+----------------------------------------------------------------------------+
246*/
247
248static int i_APCI2200_Reset(struct comedi_device *dev)
249{
250 struct addi_private *devpriv = dev->private;
251
252 outw(0x0, devpriv->iobase + APCI2200_DIGITAL_OP); /* RESETS THE DIGITAL OUTPUTS */
253 outw(0x0,
254 devpriv->iobase + APCI2200_WATCHDOG +
255 APCI2200_WATCHDOG_ENABLEDISABLE);
256 outw(0x0,
257 devpriv->iobase + APCI2200_WATCHDOG +
258 APCI2200_WATCHDOG_RELOAD_VALUE);
259 outw(0x0,
260 devpriv->iobase + APCI2200_WATCHDOG +
261 APCI2200_WATCHDOG_RELOAD_VALUE + 2);
262 return 0;
263}
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
index 829af187b249..c7908730caa5 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
@@ -633,7 +633,7 @@ static int apci3200_do_insn_bits(struct comedi_device *dev,
633 s->state = inl(devpriv->i_IobaseAddon) & 0xf; 633 s->state = inl(devpriv->i_IobaseAddon) & 0xf;
634 if (mask) { 634 if (mask) {
635 s->state &= ~mask; 635 s->state &= ~mask;
636 s->state |= (bits & mask) 636 s->state |= (bits & mask);
637 637
638 outl(s->state, devpriv->i_IobaseAddon); 638 outl(s->state, devpriv->i_IobaseAddon);
639 } 639 }
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
index 7a18ce704ba4..ebc1534a8df8 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
@@ -1,274 +1,27 @@
1/**
2@verbatim
3
4Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
5
6 ADDI-DATA GmbH
7 Dieselstrasse 3
8 D-77833 Ottersweier
9 Tel: +19(0)7223/9493-0
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
12 info@addi-data.com
13
14This 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.
15
16This 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.
17
18You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20You should also find the complete GPL in the COPYING file accompanying this source code.
21
22@endverbatim
23*/
24/*.
25
26 +-----------------------------------------------------------------------+
27 | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier |
28 +-----------------------------------------------------------------------+
29 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
30 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
31 +-------------------------------+---------------------------------------+
32 | Project : APCI-3501 | Compiler : GCC |
33 | Module name : hwdrv_apci3501.c| Version : 2.96 |
34 +-------------------------------+---------------------------------------+
35 | Project manager: Eric Stolz | Date : 02/12/2002 |
36 +-------------------------------+---------------------------------------+
37 | Description : Hardware Layer Access For APCI-3501 |
38 +-----------------------------------------------------------------------+
39 | UPDATES |
40 +----------+-----------+------------------------------------------------+
41 | Date | Author | Description of updates |
42 +----------+-----------+------------------------------------------------+
43 | | | |
44 | | | |
45 | | | |
46 +----------+-----------+------------------------------------------------+
47*/
48
49/* Card Specific information */
50#define APCI3501_ADDRESS_RANGE 255
51
52#define APCI3501_DIGITAL_IP 0x50
53#define APCI3501_DIGITAL_OP 0x40
54#define APCI3501_ANALOG_OUTPUT 0x00
55
56/* Analog Output related Defines */
57#define APCI3501_AO_VOLT_MODE 0
58#define APCI3501_AO_PROG 4
59#define APCI3501_AO_TRIG_SCS 8
60#define UNIPOLAR 0
61#define BIPOLAR 1
62#define MODE0 0
63#define MODE1 1
64
65/* Watchdog Related Defines */ 1/* Watchdog Related Defines */
66 2
67#define APCI3501_WATCHDOG 0x20
68#define APCI3501_TCW_SYNC_ENABLEDISABLE 0
69#define APCI3501_TCW_RELOAD_VALUE 4
70#define APCI3501_TCW_TIMEBASE 8
71#define APCI3501_TCW_PROG 12
72#define APCI3501_TCW_TRIG_STATUS 16
73#define APCI3501_TCW_IRQ 20
74#define APCI3501_TCW_WARN_TIMEVAL 24
75#define APCI3501_TCW_WARN_TIMEBASE 28
76#define ADDIDATA_TIMER 0 3#define ADDIDATA_TIMER 0
77#define ADDIDATA_WATCHDOG 2 4#define ADDIDATA_WATCHDOG 2
78 5
79/* ANALOG OUTPUT RANGE */
80static struct comedi_lrange range_apci3501_ao = {
81 2, {
82 BIP_RANGE(10),
83 UNI_RANGE(10)
84 }
85};
86
87static int apci3501_di_insn_bits(struct comedi_device *dev,
88 struct comedi_subdevice *s,
89 struct comedi_insn *insn,
90 unsigned int *data)
91{
92 struct addi_private *devpriv = dev->private;
93
94 data[1] = inl(devpriv->iobase + APCI3501_DIGITAL_IP) & 0x3;
95
96 return insn->n;
97}
98
99static int apci3501_do_insn_bits(struct comedi_device *dev,
100 struct comedi_subdevice *s,
101 struct comedi_insn *insn,
102 unsigned int *data)
103{
104 struct addi_private *devpriv = dev->private;
105 unsigned int mask = data[0];
106 unsigned int bits = data[1];
107
108 s->state = inl(devpriv->iobase + APCI3501_DIGITAL_OP);
109 if (mask) {
110 s->state &= ~mask;
111 s->state |= (bits & mask);
112
113 outl(s->state, devpriv->iobase + APCI3501_DIGITAL_OP);
114 }
115
116 data[1] = s->state;
117
118 return insn->n;
119}
120
121/*
122+----------------------------------------------------------------------------+
123| Function Name : int i_APCI3501_ConfigAnalogOutput |
124| (struct comedi_device *dev,struct comedi_subdevice *s, |
125| struct comedi_insn *insn,unsigned int *data) |
126+----------------------------------------------------------------------------+
127| Task : Configures The Analog Output Subdevice |
128+----------------------------------------------------------------------------+
129| Input Parameters : struct comedi_device *dev : Driver handle |
130| struct comedi_subdevice *s : Subdevice Pointer |
131| struct comedi_insn *insn : Insn Structure Pointer |
132| unsigned int *data : Data Pointer contains |
133| configuration parameters as below |
134| |
135| data[0] : Voltage Mode |
136| 0:Mode 0 |
137| 1:Mode 1 |
138| |
139+----------------------------------------------------------------------------+
140| Output Parameters : -- |
141+----------------------------------------------------------------------------+
142| Return Value : TRUE : No error occur |
143| : FALSE : Error occur. Return the error |
144| |
145+----------------------------------------------------------------------------+
146*/
147static int i_APCI3501_ConfigAnalogOutput(struct comedi_device *dev,
148 struct comedi_subdevice *s,
149 struct comedi_insn *insn,
150 unsigned int *data)
151{
152 struct addi_private *devpriv = dev->private;
153
154 outl(data[0],
155 devpriv->iobase + APCI3501_ANALOG_OUTPUT +
156 APCI3501_AO_VOLT_MODE);
157
158 if (data[0]) {
159 devpriv->b_InterruptMode = MODE1;
160 } else {
161 devpriv->b_InterruptMode = MODE0;
162 }
163 return insn->n;
164}
165
166/*
167+----------------------------------------------------------------------------+
168| Function Name : int i_APCI3501_WriteAnalogOutput |
169| (struct comedi_device *dev,struct comedi_subdevice *s, |
170| struct comedi_insn *insn,unsigned int *data) |
171+----------------------------------------------------------------------------+
172| Task : Writes To the Selected Anlog Output Channel |
173+----------------------------------------------------------------------------+
174| Input Parameters : struct comedi_device *dev : Driver handle |
175| struct comedi_subdevice *s : Subdevice Pointer |
176| struct comedi_insn *insn : Insn Structure Pointer |
177| unsigned int *data : Data Pointer contains |
178| configuration parameters as below |
179| |
180| |
181+----------------------------------------------------------------------------+
182| Output Parameters : -- |
183+----------------------------------------------------------------------------+
184| Return Value : TRUE : No error occur |
185| : FALSE : Error occur. Return the error |
186| |
187+----------------------------------------------------------------------------+
188*/
189static int i_APCI3501_WriteAnalogOutput(struct comedi_device *dev,
190 struct comedi_subdevice *s,
191 struct comedi_insn *insn,
192 unsigned int *data)
193{
194 struct addi_private *devpriv = dev->private;
195 unsigned int ul_Command1 = 0, ul_Channel_no, ul_Polarity, ul_DAC_Ready = 0;
196
197 ul_Channel_no = CR_CHAN(insn->chanspec);
198
199 if (devpriv->b_InterruptMode == MODE1) {
200 ul_Polarity = 0x80000000;
201 if ((*data < 0) || (*data > 16384)) {
202 printk("\nIn WriteAnalogOutput :: Not Valid Data\n");
203 }
204
205 } /* end if(devpriv->b_InterruptMode==MODE1) */
206 else {
207 ul_Polarity = 0;
208 if ((*data < 0) || (*data > 8192)) {
209 printk("\nIn WriteAnalogOutput :: Not Valid Data\n");
210 }
211
212 } /* end else */
213
214 if ((ul_Channel_no < 0) || (ul_Channel_no > 7)) {
215 printk("\nIn WriteAnalogOutput :: Not Valid Channel\n");
216 } /* end if((ul_Channel_no<0)||(ul_Channel_no>7)) */
217
218 ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT);
219
220 while (ul_DAC_Ready == 0) {
221 ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT);
222 ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1;
223 }
224
225 if (ul_DAC_Ready) {
226/* Output the Value on the output channels. */
227 ul_Command1 =
228 (unsigned int) ((unsigned int) (ul_Channel_no & 0xFF) |
229 (unsigned int) ((*data << 0x8) & 0x7FFFFF00L) |
230 (unsigned int) (ul_Polarity));
231 outl(ul_Command1,
232 devpriv->iobase + APCI3501_ANALOG_OUTPUT +
233 APCI3501_AO_PROG);
234 }
235
236 return insn->n;
237}
238
239/* 6/*
240+----------------------------------------------------------------------------+ 7 * (*insn_config) for the timer subdevice
241| Function Name : int i_APCI3501_ConfigTimerCounterWatchdog | 8 *
242| (struct comedi_device *dev,struct comedi_subdevice *s, | 9 * Configures The Timer, Counter or Watchdog
243| struct comedi_insn *insn,unsigned int *data) | 10 * Data Pointer contains configuration parameters as below
244+----------------------------------------------------------------------------+ 11 * data[0] : 0 Configure As Timer
245| Task : Configures The Timer , Counter or Watchdog | 12 * 1 Configure As Counter
246+----------------------------------------------------------------------------+ 13 * 2 Configure As Watchdog
247| Input Parameters : struct comedi_device *dev : Driver handle | 14 * data[1] : 1 Enable Interrupt
248| unsigned int *data : Data Pointer contains | 15 * 0 Disable Interrupt
249| configuration parameters as below | 16 * data[2] : Time Unit
250| | 17 * data[3] : Reload Value
251| data[0] : 0 Configure As Timer | 18 */
252| 1 Configure As Counter |
253| 2 Configure As Watchdog |
254| data[1] : 1 Enable Interrupt |
255| 0 Disable Interrupt |
256| data[2] : Time Unit |
257| data[3] : Reload Value |
258+----------------------------------------------------------------------------+
259| Output Parameters : -- |
260+----------------------------------------------------------------------------+
261| Return Value : TRUE : No error occur |
262| : FALSE : Error occur. Return the error |
263| |
264+----------------------------------------------------------------------------+
265*/
266static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev, 19static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev,
267 struct comedi_subdevice *s, 20 struct comedi_subdevice *s,
268 struct comedi_insn *insn, 21 struct comedi_insn *insn,
269 unsigned int *data) 22 unsigned int *data)
270{ 23{
271 struct addi_private *devpriv = dev->private; 24 struct apci3501_private *devpriv = dev->private;
272 unsigned int ul_Command1 = 0; 25 unsigned int ul_Command1 = 0;
273 26
274 devpriv->tsk_Current = current; 27 devpriv->tsk_Current = current;
@@ -276,224 +29,146 @@ static int i_APCI3501_ConfigTimerCounterWatchdog(struct comedi_device *dev,
276 29
277 devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG; 30 devpriv->b_TimerSelectMode = ADDIDATA_WATCHDOG;
278 /* Disable the watchdog */ 31 /* Disable the watchdog */
279 outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Wa */ 32 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
280 33
281 if (data[1] == 1) { 34 if (data[1] == 1) {
282 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */ 35 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
283 outl(0x02, 36 outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG);
284 devpriv->iobase + APCI3501_WATCHDOG +
285 APCI3501_TCW_PROG);
286 } else { 37 } else {
287 outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ 38 /* disable Timer interrupt */
39 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
288 } 40 }
289 41
290 /* Loading the Timebase value */ 42 outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG);
291 outl(data[2], 43 outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
292 devpriv->iobase + APCI3501_WATCHDOG +
293 APCI3501_TCW_TIMEBASE);
294 44
295 /* Loading the Reload value */ 45 /* Set the mode (e2->e0) */
296 outl(data[3], 46 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG) | 0xFFF819E0UL;
297 devpriv->iobase + APCI3501_WATCHDOG + 47 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
298 APCI3501_TCW_RELOAD_VALUE); 48 }
299 /* Set the mode */
300 ul_Command1 = inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG) | 0xFFF819E0UL; /* e2->e0 */
301 outl(ul_Command1,
302 devpriv->iobase + APCI3501_WATCHDOG +
303 APCI3501_TCW_PROG);
304 } /* end if(data[0]==ADDIDATA_WATCHDOG) */
305 49
306 else if (data[0] == ADDIDATA_TIMER) { 50 else if (data[0] == ADDIDATA_TIMER) {
307 /* First Stop The Timer */ 51 /* First Stop The Timer */
308 ul_Command1 = 52 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
309 inl(devpriv->iobase + APCI3501_WATCHDOG +
310 APCI3501_TCW_PROG);
311 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; 53 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
312 outl(ul_Command1, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* Stop The Timer */ 54 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
313 devpriv->b_TimerSelectMode = ADDIDATA_TIMER; 55 devpriv->b_TimerSelectMode = ADDIDATA_TIMER;
314 if (data[1] == 1) { 56 if (data[1] == 1) {
315 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */ 57 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
316 outl(0x02, 58 outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG);
317 devpriv->iobase + APCI3501_WATCHDOG +
318 APCI3501_TCW_PROG);
319 } else { 59 } else {
320 outl(0x0, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* disable Timer interrupt */ 60 /* disable Timer interrupt */
61 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
321 } 62 }
322 63
323 /* Loading Timebase */ 64 outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG);
324 outl(data[2], 65 outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
325 devpriv->iobase + APCI3501_WATCHDOG +
326 APCI3501_TCW_TIMEBASE);
327
328 /* Loading the Reload value */
329 outl(data[3],
330 devpriv->iobase + APCI3501_WATCHDOG +
331 APCI3501_TCW_RELOAD_VALUE);
332 66
333 /* printk ("\nTimer Address :: %x\n", (devpriv->iobase+APCI3501_WATCHDOG)); */ 67 /* mode 2 */
334 ul_Command1 = 68 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
335 inl(devpriv->iobase + APCI3501_WATCHDOG +
336 APCI3501_TCW_PROG);
337 ul_Command1 = 69 ul_Command1 =
338 (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; 70 (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL;
339 outl(ul_Command1, devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG); /* mode 2 */ 71 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
340 72 }
341 } /* end if(data[0]==ADDIDATA_TIMER) */
342 73
343 return insn->n; 74 return insn->n;
344} 75}
345 76
346/* 77/*
347+----------------------------------------------------------------------------+ 78 * (*insn_write) for the timer subdevice
348| Function Name : int i_APCI3501_StartStopWriteTimerCounterWatchdog | 79 *
349| (struct comedi_device *dev,struct comedi_subdevice *s, | 80 * Start / Stop The Selected Timer , Counter or Watchdog
350| struct comedi_insn *insn,unsigned int *data) | 81 * Data Pointer contains configuration parameters as below
351+----------------------------------------------------------------------------+ 82 * data[0] : 0 Timer
352| Task : Start / Stop The Selected Timer , Counter or Watchdog | 83 * 1 Counter
353+----------------------------------------------------------------------------+ 84 * 2 Watchdog
354| Input Parameters : struct comedi_device *dev : Driver handle | 85 * data[1] : 1 Start
355| unsigned int *data : Data Pointer contains | 86 * 0 Stop
356| configuration parameters as below | 87 * 2 Trigger
357| | 88 */
358| data[0] : 0 Timer |
359| 1 Counter |
360| 2 Watchdog | | data[1] : 1 Start |
361| 0 Stop | 2 Trigger |
362+----------------------------------------------------------------------------+
363| Output Parameters : -- |
364+----------------------------------------------------------------------------+
365| Return Value : TRUE : No error occur |
366| : FALSE : Error occur. Return the error |
367| |
368+----------------------------------------------------------------------------+
369*/
370
371static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *dev, 89static int i_APCI3501_StartStopWriteTimerCounterWatchdog(struct comedi_device *dev,
372 struct comedi_subdevice *s, 90 struct comedi_subdevice *s,
373 struct comedi_insn *insn, 91 struct comedi_insn *insn,
374 unsigned int *data) 92 unsigned int *data)
375{ 93{
376 struct addi_private *devpriv = dev->private; 94 struct apci3501_private *devpriv = dev->private;
377 unsigned int ul_Command1 = 0; 95 unsigned int ul_Command1 = 0;
378 int i_Temp; 96 int i_Temp;
379 97
380 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { 98 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) {
381 99
382 if (data[1] == 1) { 100 if (data[1] == 1) {
383 ul_Command1 = 101 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
384 inl(devpriv->iobase + APCI3501_WATCHDOG +
385 APCI3501_TCW_PROG);
386 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; 102 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
387 /* Enable the Watchdog */ 103 /* Enable the Watchdog */
388 outl(ul_Command1, 104 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
389 devpriv->iobase + APCI3501_WATCHDOG +
390 APCI3501_TCW_PROG);
391 } 105 }
392 106
393 else if (data[1] == 0) /* Stop The Watchdog */ 107 else if (data[1] == 0) /* Stop The Watchdog */
394 { 108 {
395 /* Stop The Watchdog */ 109 /* Stop The Watchdog */
396 ul_Command1 = 110 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
397 inl(devpriv->iobase + APCI3501_WATCHDOG +
398 APCI3501_TCW_PROG);
399 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; 111 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
400 outl(0x0, 112 outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
401 devpriv->iobase + APCI3501_WATCHDOG +
402 APCI3501_TCW_PROG);
403 } else if (data[1] == 2) { 113 } else if (data[1] == 2) {
404 ul_Command1 = 114 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
405 inl(devpriv->iobase + APCI3501_WATCHDOG +
406 APCI3501_TCW_PROG);
407 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; 115 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL;
408 outl(ul_Command1, 116 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
409 devpriv->iobase + APCI3501_WATCHDOG + 117 }
410 APCI3501_TCW_PROG); 118 }
411 } /* if(data[1]==2) */
412 } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */
413 119
414 if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { 120 if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) {
415 if (data[1] == 1) { 121 if (data[1] == 1) {
416 122
417 ul_Command1 = 123 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
418 inl(devpriv->iobase + APCI3501_WATCHDOG +
419 APCI3501_TCW_PROG);
420 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL; 124 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
421 /* Enable the Timer */ 125 /* Enable the Timer */
422 outl(ul_Command1, 126 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
423 devpriv->iobase + APCI3501_WATCHDOG +
424 APCI3501_TCW_PROG);
425 } else if (data[1] == 0) { 127 } else if (data[1] == 0) {
426 /* Stop The Timer */ 128 /* Stop The Timer */
427 ul_Command1 = 129 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
428 inl(devpriv->iobase + APCI3501_WATCHDOG +
429 APCI3501_TCW_PROG);
430 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; 130 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
431 outl(ul_Command1, 131 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
432 devpriv->iobase + APCI3501_WATCHDOG +
433 APCI3501_TCW_PROG);
434 } 132 }
435 133
436 else if (data[1] == 2) { 134 else if (data[1] == 2) {
437 /* Trigger the Timer */ 135 /* Trigger the Timer */
438 ul_Command1 = 136 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
439 inl(devpriv->iobase + APCI3501_WATCHDOG +
440 APCI3501_TCW_PROG);
441 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL; 137 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x200UL;
442 outl(ul_Command1, 138 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
443 devpriv->iobase + APCI3501_WATCHDOG +
444 APCI3501_TCW_PROG);
445 } 139 }
140 }
446 141
447 } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */ 142 i_Temp = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1;
448 i_Temp = inl(devpriv->iobase + APCI3501_WATCHDOG +
449 APCI3501_TCW_TRIG_STATUS) & 0x1;
450 return insn->n; 143 return insn->n;
451} 144}
452 145
453/* 146/*
454+----------------------------------------------------------------------------+ 147 * (*insn_read) for the timer subdevice
455| Function Name : int i_APCI3501_ReadTimerCounterWatchdog | 148 *
456| (struct comedi_device *dev,struct comedi_subdevice *s, | 149 * Read The Selected Timer, Counter or Watchdog
457| struct comedi_insn *insn,unsigned int *data) | 150 * Data Pointer contains configuration parameters as below
458+----------------------------------------------------------------------------+ 151 * data[0] : 0 Timer
459| Task : Read The Selected Timer , Counter or Watchdog | 152 * 1 Counter
460+----------------------------------------------------------------------------+ 153 * 2 Watchdog
461| Input Parameters : struct comedi_device *dev : Driver handle | 154 * data[1] : Timer Counter Watchdog Number
462| unsigned int *data : Data Pointer contains | 155 */
463| configuration parameters as below |
464| |
465| data[0] : 0 Timer |
466| 1 Counter |
467| 2 Watchdog | | data[1] : Timer Counter Watchdog Number |
468+----------------------------------------------------------------------------+
469| Output Parameters : -- |
470+----------------------------------------------------------------------------+
471| Return Value : TRUE : No error occur |
472| : FALSE : Error occur. Return the error |
473| |
474+----------------------------------------------------------------------------+
475*/
476
477static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev, 156static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev,
478 struct comedi_subdevice *s, 157 struct comedi_subdevice *s,
479 struct comedi_insn *insn, 158 struct comedi_insn *insn,
480 unsigned int *data) 159 unsigned int *data)
481{ 160{
482 struct addi_private *devpriv = dev->private; 161 struct apci3501_private *devpriv = dev->private;
483 162
484 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) { 163 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG) {
485 data[0] = 164 data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1;
486 inl(devpriv->iobase + APCI3501_WATCHDOG + 165 data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG);
487 APCI3501_TCW_TRIG_STATUS) & 0x1; 166 }
488 data[1] = inl(devpriv->iobase + APCI3501_WATCHDOG);
489 } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_WATCHDOG) */
490 167
491 else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) { 168 else if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER) {
492 data[0] = 169 data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1;
493 inl(devpriv->iobase + APCI3501_WATCHDOG + 170 data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG);
494 APCI3501_TCW_TRIG_STATUS) & 0x1; 171 }
495 data[1] = inl(devpriv->iobase + APCI3501_WATCHDOG);
496 } /* end if (devpriv->b_TimerSelectMode==ADDIDATA_TIMER) */
497 172
498 else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER) 173 else if ((devpriv->b_TimerSelectMode != ADDIDATA_TIMER)
499 && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG)) { 174 && (devpriv->b_TimerSelectMode != ADDIDATA_WATCHDOG)) {
@@ -501,111 +176,3 @@ static int i_APCI3501_ReadTimerCounterWatchdog(struct comedi_device *dev,
501 } 176 }
502 return insn->n; 177 return insn->n;
503} 178}
504
505/*
506+----------------------------------------------------------------------------+
507| Function Name : int i_APCI3501_Reset(struct comedi_device *dev) |
508| |
509+----------------------------------------------------------------------------+
510| Task :Resets the registers of the card |
511+----------------------------------------------------------------------------+
512| Input Parameters : |
513+----------------------------------------------------------------------------+
514| Output Parameters : -- |
515+----------------------------------------------------------------------------+
516| Return Value : |
517| |
518+----------------------------------------------------------------------------+
519*/
520
521static int i_APCI3501_Reset(struct comedi_device *dev)
522{
523 struct addi_private *devpriv = dev->private;
524 int i_Count = 0, i_temp = 0;
525 unsigned int ul_Command1 = 0, ul_Polarity, ul_DAC_Ready = 0;
526
527 outl(0x0, devpriv->iobase + APCI3501_DIGITAL_OP);
528 outl(1, devpriv->iobase + APCI3501_ANALOG_OUTPUT +
529 APCI3501_AO_VOLT_MODE);
530
531 ul_Polarity = 0x80000000;
532
533 for (i_Count = 0; i_Count <= 7; i_Count++) {
534 ul_DAC_Ready = inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT);
535
536 while (ul_DAC_Ready == 0) {
537 ul_DAC_Ready =
538 inl(devpriv->iobase + APCI3501_ANALOG_OUTPUT);
539 ul_DAC_Ready = (ul_DAC_Ready >> 8) & 1;
540 }
541
542 if (ul_DAC_Ready) {
543 /* Output the Value on the output channels. */
544 ul_Command1 =
545 (unsigned int) ((unsigned int) (i_Count & 0xFF) |
546 (unsigned int) ((i_temp << 0x8) & 0x7FFFFF00L) |
547 (unsigned int) (ul_Polarity));
548 outl(ul_Command1,
549 devpriv->iobase + APCI3501_ANALOG_OUTPUT +
550 APCI3501_AO_PROG);
551 }
552 }
553
554 return 0;
555}
556
557/*
558+----------------------------------------------------------------------------+
559| Function Name : static void v_APCI3501_Interrupt |
560| (int irq , void *d) |
561+----------------------------------------------------------------------------+
562| Task : Interrupt processing Routine |
563+----------------------------------------------------------------------------+
564| Input Parameters : int irq : irq number |
565| void *d : void pointer |
566+----------------------------------------------------------------------------+
567| Output Parameters : -- |
568+----------------------------------------------------------------------------+
569| Return Value : TRUE : No error occur |
570| : FALSE : Error occur. Return the error |
571| |
572+----------------------------------------------------------------------------+
573*/
574static void v_APCI3501_Interrupt(int irq, void *d)
575{
576 int i_temp;
577 struct comedi_device *dev = d;
578 struct addi_private *devpriv = dev->private;
579 unsigned int ui_Timer_AOWatchdog;
580 unsigned long ul_Command1;
581
582 /* Disable Interrupt */
583 ul_Command1 =
584 inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG);
585
586 ul_Command1 = (ul_Command1 & 0xFFFFF9FDul);
587 outl(ul_Command1,
588 devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG);
589
590 ui_Timer_AOWatchdog =
591 inl(devpriv->iobase + APCI3501_WATCHDOG +
592 APCI3501_TCW_IRQ) & 0x1;
593
594 if ((!ui_Timer_AOWatchdog)) {
595 comedi_error(dev, "IRQ from unknown source");
596 return;
597 }
598
599/*
600* Enable Interrupt Send a signal to from kernel to user space
601*/
602 send_sig(SIGIO, devpriv->tsk_Current, 0);
603 ul_Command1 =
604 inl(devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG);
605 ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1);
606 outl(ul_Command1,
607 devpriv->iobase + APCI3501_WATCHDOG + APCI3501_TCW_PROG);
608 i_temp = inl(devpriv->iobase + APCI3501_WATCHDOG +
609 APCI3501_TCW_TRIG_STATUS) & 0x1;
610 return;
611}
diff --git a/drivers/staging/comedi/drivers/addi_apci_035.c b/drivers/staging/comedi/drivers/addi_apci_035.c
index c981d4b1cc73..5a53e58258a0 100644
--- a/drivers/staging/comedi/drivers/addi_apci_035.c
+++ b/drivers/staging/comedi/drivers/addi_apci_035.c
@@ -1,3 +1,5 @@
1#include <linux/pci.h>
2
1#include "../comedidev.h" 3#include "../comedidev.h"
2#include "comedi_fc.h" 4#include "comedi_fc.h"
3#include "amcc_s5933.h" 5#include "amcc_s5933.h"
@@ -53,11 +55,6 @@ static int apci035_pci_probe(struct pci_dev *dev,
53 return comedi_pci_auto_config(dev, &apci035_driver); 55 return comedi_pci_auto_config(dev, &apci035_driver);
54} 56}
55 57
56static void apci035_pci_remove(struct pci_dev *dev)
57{
58 comedi_pci_auto_unconfig(dev);
59}
60
61static DEFINE_PCI_DEVICE_TABLE(apci035_pci_table) = { 58static DEFINE_PCI_DEVICE_TABLE(apci035_pci_table) = {
62 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x0300) }, 59 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x0300) },
63 { 0 } 60 { 0 }
@@ -68,7 +65,7 @@ static struct pci_driver apci035_pci_driver = {
68 .name = "addi_apci_035", 65 .name = "addi_apci_035",
69 .id_table = apci035_pci_table, 66 .id_table = apci035_pci_table,
70 .probe = apci035_pci_probe, 67 .probe = apci035_pci_probe,
71 .remove = apci035_pci_remove, 68 .remove = comedi_pci_auto_unconfig,
72}; 69};
73module_comedi_pci_driver(apci035_driver, apci035_pci_driver); 70module_comedi_pci_driver(apci035_driver, apci035_pci_driver);
74 71
diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c
index 7f9424205a64..c0d0429c35c8 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1032.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1032.c
@@ -29,6 +29,9 @@
29 * source code. 29 * source code.
30 */ 30 */
31 31
32#include <linux/pci.h>
33#include <linux/interrupt.h>
34
32#include "../comedidev.h" 35#include "../comedidev.h"
33#include "comedi_fc.h" 36#include "comedi_fc.h"
34#include "amcc_s5933.h" 37#include "amcc_s5933.h"
@@ -375,11 +378,6 @@ static int apci1032_pci_probe(struct pci_dev *dev,
375 return comedi_pci_auto_config(dev, &apci1032_driver); 378 return comedi_pci_auto_config(dev, &apci1032_driver);
376} 379}
377 380
378static void apci1032_pci_remove(struct pci_dev *dev)
379{
380 comedi_pci_auto_unconfig(dev);
381}
382
383static DEFINE_PCI_DEVICE_TABLE(apci1032_pci_table) = { 381static DEFINE_PCI_DEVICE_TABLE(apci1032_pci_table) = {
384 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1003) }, 382 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1003) },
385 { 0 } 383 { 0 }
@@ -390,7 +388,7 @@ static struct pci_driver apci1032_pci_driver = {
390 .name = "addi_apci_1032", 388 .name = "addi_apci_1032",
391 .id_table = apci1032_pci_table, 389 .id_table = apci1032_pci_table,
392 .probe = apci1032_pci_probe, 390 .probe = apci1032_pci_probe,
393 .remove = apci1032_pci_remove, 391 .remove = comedi_pci_auto_unconfig,
394}; 392};
395module_comedi_pci_driver(apci1032_driver, apci1032_pci_driver); 393module_comedi_pci_driver(apci1032_driver, apci1032_pci_driver);
396 394
diff --git a/drivers/staging/comedi/drivers/addi_apci_1500.c b/drivers/staging/comedi/drivers/addi_apci_1500.c
index 8e686a9b811b..9c2f8eeb7977 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1500.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1500.c
@@ -1,3 +1,5 @@
1#include <linux/pci.h>
2
1#include "../comedidev.h" 3#include "../comedidev.h"
2#include "comedi_fc.h" 4#include "comedi_fc.h"
3#include "amcc_s5933.h" 5#include "amcc_s5933.h"
@@ -53,11 +55,6 @@ static int apci1500_pci_probe(struct pci_dev *dev,
53 return comedi_pci_auto_config(dev, &apci1500_driver); 55 return comedi_pci_auto_config(dev, &apci1500_driver);
54} 56}
55 57
56static void apci1500_pci_remove(struct pci_dev *dev)
57{
58 comedi_pci_auto_unconfig(dev);
59}
60
61static DEFINE_PCI_DEVICE_TABLE(apci1500_pci_table) = { 58static DEFINE_PCI_DEVICE_TABLE(apci1500_pci_table) = {
62 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x80fc) }, 59 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x80fc) },
63 { 0 } 60 { 0 }
@@ -68,7 +65,7 @@ static struct pci_driver apci1500_pci_driver = {
68 .name = "addi_apci_1500", 65 .name = "addi_apci_1500",
69 .id_table = apci1500_pci_table, 66 .id_table = apci1500_pci_table,
70 .probe = apci1500_pci_probe, 67 .probe = apci1500_pci_probe,
71 .remove = apci1500_pci_remove, 68 .remove = comedi_pci_auto_unconfig,
72}; 69};
73module_comedi_pci_driver(apci1500_driver, apci1500_pci_driver); 70module_comedi_pci_driver(apci1500_driver, apci1500_pci_driver);
74 71
diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c
index 8fef04b4d197..69e399638419 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1516.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1516.c
@@ -29,7 +29,10 @@
29 * this source code. 29 * this source code.
30 */ 30 */
31 31
32#include <linux/pci.h>
33
32#include "../comedidev.h" 34#include "../comedidev.h"
35#include "addi_watchdog.h"
33#include "comedi_fc.h" 36#include "comedi_fc.h"
34 37
35/* 38/*
@@ -49,13 +52,6 @@
49 * PCI bar 2 I/O Register map - Watchdog (APCI-1516 and APCI-2016) 52 * PCI bar 2 I/O Register map - Watchdog (APCI-1516 and APCI-2016)
50 */ 53 */
51#define APCI1516_WDOG_REG 0x00 54#define APCI1516_WDOG_REG 0x00
52#define APCI1516_WDOG_RELOAD_REG 0x04
53#define APCI1516_WDOG_CTRL_REG 0x0c
54#define APCI1516_WDOG_CTRL_ENABLE (1 << 0)
55#define APCI1516_WDOG_CTRL_SW_TRIG (1 << 9)
56#define APCI1516_WDOG_STATUS_REG 0x10
57#define APCI1516_WDOG_STATUS_ENABLED (1 << 0)
58#define APCI1516_WDOG_STATUS_SW_TRIG (1 << 1)
59 55
60struct apci1516_boardinfo { 56struct apci1516_boardinfo {
61 const char *name; 57 const char *name;
@@ -86,7 +82,6 @@ static const struct apci1516_boardinfo apci1516_boardtypes[] = {
86 82
87struct apci1516_private { 83struct apci1516_private {
88 unsigned long wdog_iobase; 84 unsigned long wdog_iobase;
89 unsigned int ctrl;
90}; 85};
91 86
92static int apci1516_di_insn_bits(struct comedi_device *dev, 87static int apci1516_di_insn_bits(struct comedi_device *dev,
@@ -120,82 +115,6 @@ static int apci1516_do_insn_bits(struct comedi_device *dev,
120 return insn->n; 115 return insn->n;
121} 116}
122 117
123/*
124 * The watchdog subdevice is configured with two INSN_CONFIG instructions:
125 *
126 * Enable the watchdog and set the reload timeout:
127 * data[0] = INSN_CONFIG_ARM
128 * data[1] = timeout reload value
129 *
130 * Disable the watchdog:
131 * data[0] = INSN_CONFIG_DISARM
132 */
133static int apci1516_wdog_insn_config(struct comedi_device *dev,
134 struct comedi_subdevice *s,
135 struct comedi_insn *insn,
136 unsigned int *data)
137{
138 struct apci1516_private *devpriv = dev->private;
139 unsigned int reload;
140
141 switch (data[0]) {
142 case INSN_CONFIG_ARM:
143 devpriv->ctrl = APCI1516_WDOG_CTRL_ENABLE;
144 reload = data[1] & s->maxdata;
145 outw(reload, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG);
146
147 /* Time base is 20ms, let the user know the timeout */
148 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
149 20 * reload + 20);
150 break;
151 case INSN_CONFIG_DISARM:
152 devpriv->ctrl = 0;
153 break;
154 default:
155 return -EINVAL;
156 }
157
158 outw(devpriv->ctrl, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG);
159
160 return insn->n;
161}
162
163static int apci1516_wdog_insn_write(struct comedi_device *dev,
164 struct comedi_subdevice *s,
165 struct comedi_insn *insn,
166 unsigned int *data)
167{
168 struct apci1516_private *devpriv = dev->private;
169 int i;
170
171 if (devpriv->ctrl == 0) {
172 dev_warn(dev->class_dev, "watchdog is disabled\n");
173 return -EINVAL;
174 }
175
176 /* "ping" the watchdog */
177 for (i = 0; i < insn->n; i++) {
178 outw(devpriv->ctrl | APCI1516_WDOG_CTRL_SW_TRIG,
179 devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG);
180 }
181
182 return insn->n;
183}
184
185static int apci1516_wdog_insn_read(struct comedi_device *dev,
186 struct comedi_subdevice *s,
187 struct comedi_insn *insn,
188 unsigned int *data)
189{
190 struct apci1516_private *devpriv = dev->private;
191 int i;
192
193 for (i = 0; i < insn->n; i++)
194 data[i] = inw(devpriv->wdog_iobase + APCI1516_WDOG_STATUS_REG);
195
196 return insn->n;
197}
198
199static int apci1516_reset(struct comedi_device *dev) 118static int apci1516_reset(struct comedi_device *dev)
200{ 119{
201 const struct apci1516_boardinfo *this_board = comedi_board(dev); 120 const struct apci1516_boardinfo *this_board = comedi_board(dev);
@@ -205,8 +124,8 @@ static int apci1516_reset(struct comedi_device *dev)
205 return 0; 124 return 0;
206 125
207 outw(0x0, dev->iobase + APCI1516_DO_REG); 126 outw(0x0, dev->iobase + APCI1516_DO_REG);
208 outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG); 127
209 outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG); 128 addi_watchdog_reset(devpriv->wdog_iobase);
210 129
211 return 0; 130 return 0;
212} 131}
@@ -285,13 +204,9 @@ static int apci1516_auto_attach(struct comedi_device *dev,
285 /* Initialize the watchdog subdevice */ 204 /* Initialize the watchdog subdevice */
286 s = &dev->subdevices[2]; 205 s = &dev->subdevices[2];
287 if (this_board->has_wdog) { 206 if (this_board->has_wdog) {
288 s->type = COMEDI_SUBD_TIMER; 207 ret = addi_watchdog_init(s, devpriv->wdog_iobase);
289 s->subdev_flags = SDF_WRITEABLE; 208 if (ret)
290 s->n_chan = 1; 209 return ret;
291 s->maxdata = 0xff;
292 s->insn_write = apci1516_wdog_insn_write;
293 s->insn_read = apci1516_wdog_insn_read;
294 s->insn_config = apci1516_wdog_insn_config;
295 } else { 210 } else {
296 s->type = COMEDI_SUBD_UNUSED; 211 s->type = COMEDI_SUBD_UNUSED;
297 } 212 }
@@ -304,10 +219,12 @@ static void apci1516_detach(struct comedi_device *dev)
304{ 219{
305 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 220 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
306 221
307 if (dev->iobase) { 222 if (dev->iobase)
308 apci1516_reset(dev); 223 apci1516_reset(dev);
224 if (dev->subdevices)
225 addi_watchdog_cleanup(&dev->subdevices[2]);
226 if (dev->iobase)
309 comedi_pci_disable(pcidev); 227 comedi_pci_disable(pcidev);
310 }
311} 228}
312 229
313static struct comedi_driver apci1516_driver = { 230static struct comedi_driver apci1516_driver = {
@@ -323,11 +240,6 @@ static int apci1516_pci_probe(struct pci_dev *dev,
323 return comedi_pci_auto_config(dev, &apci1516_driver); 240 return comedi_pci_auto_config(dev, &apci1516_driver);
324} 241}
325 242
326static void apci1516_pci_remove(struct pci_dev *dev)
327{
328 comedi_pci_auto_unconfig(dev);
329}
330
331static DEFINE_PCI_DEVICE_TABLE(apci1516_pci_table) = { 243static DEFINE_PCI_DEVICE_TABLE(apci1516_pci_table) = {
332 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1016) }, 244 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1016) },
333 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1516) }, 245 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1516) },
@@ -340,7 +252,7 @@ static struct pci_driver apci1516_pci_driver = {
340 .name = "addi_apci_1516", 252 .name = "addi_apci_1516",
341 .id_table = apci1516_pci_table, 253 .id_table = apci1516_pci_table,
342 .probe = apci1516_pci_probe, 254 .probe = apci1516_pci_probe,
343 .remove = apci1516_pci_remove, 255 .remove = comedi_pci_auto_unconfig,
344}; 256};
345module_comedi_pci_driver(apci1516_driver, apci1516_pci_driver); 257module_comedi_pci_driver(apci1516_driver, apci1516_pci_driver);
346 258
diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c
index 513e536f292f..ddea64df9180 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1564.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1564.c
@@ -1,3 +1,5 @@
1#include <linux/pci.h>
2
1#include "../comedidev.h" 3#include "../comedidev.h"
2#include "comedi_fc.h" 4#include "comedi_fc.h"
3#include "amcc_s5933.h" 5#include "amcc_s5933.h"
@@ -50,11 +52,6 @@ static int apci1564_pci_probe(struct pci_dev *dev,
50 return comedi_pci_auto_config(dev, &apci1564_driver); 52 return comedi_pci_auto_config(dev, &apci1564_driver);
51} 53}
52 54
53static void apci1564_pci_remove(struct pci_dev *dev)
54{
55 comedi_pci_auto_unconfig(dev);
56}
57
58static DEFINE_PCI_DEVICE_TABLE(apci1564_pci_table) = { 55static DEFINE_PCI_DEVICE_TABLE(apci1564_pci_table) = {
59 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1006) }, 56 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1006) },
60 { 0 } 57 { 0 }
@@ -65,7 +62,7 @@ static struct pci_driver apci1564_pci_driver = {
65 .name = "addi_apci_1564", 62 .name = "addi_apci_1564",
66 .id_table = apci1564_pci_table, 63 .id_table = apci1564_pci_table,
67 .probe = apci1564_pci_probe, 64 .probe = apci1564_pci_probe,
68 .remove = apci1564_pci_remove, 65 .remove = comedi_pci_auto_unconfig,
69}; 66};
70module_comedi_pci_driver(apci1564_driver, apci1564_pci_driver); 67module_comedi_pci_driver(apci1564_driver, apci1564_pci_driver);
71 68
diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c
index ab9a96ac8180..e51f80001363 100644
--- a/drivers/staging/comedi/drivers/addi_apci_16xx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c
@@ -1,49 +1,227 @@
1/*
2 * addi_apci_16xx.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 * Project manager: S. Weber
5 *
6 * ADDI-DATA GmbH
7 * Dieselstrasse 3
8 * D-77833 Ottersweier
9 * Tel: +19(0)7223/9493-0
10 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com
12 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 * You should also find the complete GPL in the COPYING file accompanying
29 * this source code.
30 */
31
32#include <linux/pci.h>
33
1#include "../comedidev.h" 34#include "../comedidev.h"
2#include "comedi_fc.h"
3#include "amcc_s5933.h"
4 35
5#include "addi-data/addi_common.h" 36/*
37 * PCI device ids supported by this driver
38 */
39#define PCI_DEVICE_ID_APCI1648 0x1009
40#define PCI_DEVICE_ID_APCI1696 0x100a
6 41
7#include "addi-data/addi_eeprom.c" 42/*
8#include "addi-data/hwdrv_apci16xx.c" 43 * Register I/O map
9#include "addi-data/addi_common.c" 44 */
45#define APCI16XX_IN_REG(x) (((x) * 4) + 0x08)
46#define APCI16XX_OUT_REG(x) (((x) * 4) + 0x14)
47#define APCI16XX_DIR_REG(x) (((x) * 4) + 0x20)
10 48
11static const struct addi_board apci16xx_boardtypes[] = { 49struct apci16xx_boardinfo {
50 const char *name;
51 unsigned short vendor;
52 unsigned short device;
53 int n_chan;
54};
55
56static const struct apci16xx_boardinfo apci16xx_boardtypes[] = {
12 { 57 {
13 .pc_DriverName = "apci1648", 58 .name = "apci1648",
14 .i_VendorId = PCI_VENDOR_ID_ADDIDATA, 59 .vendor = PCI_VENDOR_ID_ADDIDATA,
15 .i_DeviceId = 0x1009, 60 .device = PCI_DEVICE_ID_APCI1648,
16 .i_IorangeBase0 = 128, 61 .n_chan = 48, /* 2 subdevices */
17 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
18 .i_NbrTTLChannel = 48,
19 .reset = i_APCI16XX_Reset,
20 .ttl_config = i_APCI16XX_InsnConfigInitTTLIO,
21 .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO,
22 .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue,
23 .ttl_write = i_APCI16XX_InsnBitsWriteTTLIO,
24 }, { 62 }, {
25 .pc_DriverName = "apci1696", 63 .name = "apci1696",
26 .i_VendorId = PCI_VENDOR_ID_ADDIDATA, 64 .vendor = PCI_VENDOR_ID_ADDIDATA,
27 .i_DeviceId = 0x100A, 65 .device = PCI_DEVICE_ID_APCI1696,
28 .i_IorangeBase0 = 128, 66 .n_chan = 96, /* 3 subdevices */
29 .i_PCIEeprom = ADDIDATA_NO_EEPROM,
30 .i_NbrTTLChannel = 96,
31 .reset = i_APCI16XX_Reset,
32 .ttl_config = i_APCI16XX_InsnConfigInitTTLIO,
33 .ttl_bits = i_APCI16XX_InsnBitsReadTTLIO,
34 .ttl_read = i_APCI16XX_InsnReadTTLIOAllPortValue,
35 .ttl_write = i_APCI16XX_InsnBitsWriteTTLIO,
36 }, 67 },
37}; 68};
38 69
70static int apci16xx_insn_config(struct comedi_device *dev,
71 struct comedi_subdevice *s,
72 struct comedi_insn *insn,
73 unsigned int *data)
74{
75 unsigned int chan_mask = 1 << CR_CHAN(insn->chanspec);
76 unsigned int bits;
77
78 /*
79 * Each 8-bit "port" is configurable as either input or
80 * output. Changing the configuration of any channel in
81 * a port changes the entire port.
82 */
83 if (chan_mask & 0x000000ff)
84 bits = 0x000000ff;
85 else if (chan_mask & 0x0000ff00)
86 bits = 0x0000ff00;
87 else if (chan_mask & 0x00ff0000)
88 bits = 0x00ff0000;
89 else
90 bits = 0xff000000;
91
92 switch (data[0]) {
93 case INSN_CONFIG_DIO_INPUT:
94 s->io_bits &= ~bits;
95 break;
96 case INSN_CONFIG_DIO_OUTPUT:
97 s->io_bits |= bits;
98 break;
99 case INSN_CONFIG_DIO_QUERY:
100 data[1] = (s->io_bits & bits) ? COMEDI_INPUT : COMEDI_OUTPUT;
101 return insn->n;
102 default:
103 return -EINVAL;
104 }
105
106 outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(s->index));
107
108 return insn->n;
109}
110
111static int apci16xx_dio_insn_bits(struct comedi_device *dev,
112 struct comedi_subdevice *s,
113 struct comedi_insn *insn,
114 unsigned int *data)
115{
116 unsigned int mask = data[0];
117 unsigned int bits = data[1];
118
119 /* Only update the channels configured as outputs */
120 mask &= s->io_bits;
121 if (mask) {
122 s->state &= ~mask;
123 s->state |= (bits & mask);
124
125 outl(s->state, dev->iobase + APCI16XX_OUT_REG(s->index));
126 }
127
128 data[1] = inl(dev->iobase + APCI16XX_IN_REG(s->index));
129
130 return insn->n;
131}
132
133static const void *apci16xx_find_boardinfo(struct comedi_device *dev,
134 struct pci_dev *pcidev)
135{
136 const struct apci16xx_boardinfo *board;
137 int i;
138
139 for (i = 0; i < ARRAY_SIZE(apci16xx_boardtypes); i++) {
140 board = &apci16xx_boardtypes[i];
141 if (board->vendor == pcidev->vendor &&
142 board->device == pcidev->device)
143 return board;
144 }
145 return NULL;
146}
147
148static int apci16xx_auto_attach(struct comedi_device *dev,
149 unsigned long context_unused)
150{
151 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
152 const struct apci16xx_boardinfo *board;
153 struct comedi_subdevice *s;
154 unsigned int n_subdevs;
155 unsigned int last;
156 int i;
157 int ret;
158
159 board = apci16xx_find_boardinfo(dev, pcidev);
160 if (!board)
161 return -ENODEV;
162 dev->board_ptr = board;
163 dev->board_name = board->name;
164
165 ret = comedi_pci_enable(pcidev, dev->board_name);
166 if (ret)
167 return ret;
168
169 dev->iobase = pci_resource_start(pcidev, 0);
170
171 /*
172 * Work out the nubmer of subdevices needed to support all the
173 * digital i/o channels on the board. Each subdevice supports
174 * up to 32 channels.
175 */
176 n_subdevs = board->n_chan / 32;
177 if ((n_subdevs * 32) < board->n_chan) {
178 last = board->n_chan - (n_subdevs * 32);
179 n_subdevs++;
180 } else {
181 last = 0;
182 }
183
184 ret = comedi_alloc_subdevices(dev, n_subdevs);
185 if (ret)
186 return ret;
187
188 /* Initialize the TTL digital i/o subdevices */
189 for (i = 0; i < n_subdevs; i++) {
190 s = &dev->subdevices[i];
191 s->type = COMEDI_SUBD_DIO;
192 s->subdev_flags = SDF_WRITEABLE | SDF_READABLE;
193 s->n_chan = ((i * 32) < board->n_chan) ? 32 : last;
194 s->maxdata = 1;
195 s->range_table = &range_digital;
196 s->insn_config = apci16xx_insn_config;
197 s->insn_bits = apci16xx_dio_insn_bits;
198
199 /* Default all channels to inputs */
200 s->io_bits = 0;
201 outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(i));
202 }
203
204 return 0;
205}
206
207static void apci16xx_detach(struct comedi_device *dev)
208{
209 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
210
211 if (pcidev) {
212 if (dev->iobase)
213 comedi_pci_disable(pcidev);
214 }
215}
216
39static struct comedi_driver apci16xx_driver = { 217static struct comedi_driver apci16xx_driver = {
40 .driver_name = "addi_apci_16xx", 218 .driver_name = "addi_apci_16xx",
41 .module = THIS_MODULE, 219 .module = THIS_MODULE,
42 .auto_attach = addi_auto_attach, 220 .auto_attach = apci16xx_auto_attach,
43 .detach = i_ADDI_Detach, 221 .detach = apci16xx_detach,
44 .num_names = ARRAY_SIZE(apci16xx_boardtypes), 222 .num_names = ARRAY_SIZE(apci16xx_boardtypes),
45 .board_name = &apci16xx_boardtypes[0].pc_DriverName, 223 .board_name = &apci16xx_boardtypes[0].name,
46 .offset = sizeof(struct addi_board), 224 .offset = sizeof(struct apci16xx_boardinfo),
47}; 225};
48 226
49static int apci16xx_pci_probe(struct pci_dev *dev, 227static int apci16xx_pci_probe(struct pci_dev *dev,
@@ -52,14 +230,9 @@ static int apci16xx_pci_probe(struct pci_dev *dev,
52 return comedi_pci_auto_config(dev, &apci16xx_driver); 230 return comedi_pci_auto_config(dev, &apci16xx_driver);
53} 231}
54 232
55static void apci16xx_pci_remove(struct pci_dev *dev)
56{
57 comedi_pci_auto_unconfig(dev);
58}
59
60static DEFINE_PCI_DEVICE_TABLE(apci16xx_pci_table) = { 233static DEFINE_PCI_DEVICE_TABLE(apci16xx_pci_table) = {
61 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1009) }, 234 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1648) },
62 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x100a) }, 235 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1696) },
63 { 0 } 236 { 0 }
64}; 237};
65MODULE_DEVICE_TABLE(pci, apci16xx_pci_table); 238MODULE_DEVICE_TABLE(pci, apci16xx_pci_table);
@@ -68,10 +241,10 @@ static struct pci_driver apci16xx_pci_driver = {
68 .name = "addi_apci_16xx", 241 .name = "addi_apci_16xx",
69 .id_table = apci16xx_pci_table, 242 .id_table = apci16xx_pci_table,
70 .probe = apci16xx_pci_probe, 243 .probe = apci16xx_pci_probe,
71 .remove = apci16xx_pci_remove, 244 .remove = comedi_pci_auto_unconfig,
72}; 245};
73module_comedi_pci_driver(apci16xx_driver, apci16xx_pci_driver); 246module_comedi_pci_driver(apci16xx_driver, apci16xx_pci_driver);
74 247
248MODULE_DESCRIPTION("ADDI-DATA APCI-1648/1696, TTL I/O boards");
75MODULE_AUTHOR("Comedi http://www.comedi.org"); 249MODULE_AUTHOR("Comedi http://www.comedi.org");
76MODULE_DESCRIPTION("Comedi low-level driver");
77MODULE_LICENSE("GPL"); 250MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/addi_apci_1710.c b/drivers/staging/comedi/drivers/addi_apci_1710.c
index 152e7ef9b17b..e83e829831b0 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1710.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1710.c
@@ -1,3 +1,5 @@
1#include <linux/pci.h>
2
1#include <asm/i387.h> 3#include <asm/i387.h>
2 4
3#include "../comedidev.h" 5#include "../comedidev.h"
@@ -128,11 +130,6 @@ static int apci1710_pci_probe(struct pci_dev *dev,
128 return comedi_pci_auto_config(dev, &apci1710_driver); 130 return comedi_pci_auto_config(dev, &apci1710_driver);
129} 131}
130 132
131static void apci1710_pci_remove(struct pci_dev *dev)
132{
133 comedi_pci_auto_unconfig(dev);
134}
135
136static DEFINE_PCI_DEVICE_TABLE(apci1710_pci_table) = { 133static DEFINE_PCI_DEVICE_TABLE(apci1710_pci_table) = {
137 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, APCI1710_BOARD_DEVICE_ID) }, 134 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, APCI1710_BOARD_DEVICE_ID) },
138 { 0 } 135 { 0 }
@@ -143,7 +140,7 @@ static struct pci_driver apci1710_pci_driver = {
143 .name = "addi_apci_1710", 140 .name = "addi_apci_1710",
144 .id_table = apci1710_pci_table, 141 .id_table = apci1710_pci_table,
145 .probe = apci1710_pci_probe, 142 .probe = apci1710_pci_probe,
146 .remove = apci1710_pci_remove, 143 .remove = comedi_pci_auto_unconfig,
147}; 144};
148module_comedi_pci_driver(apci1710_driver, apci1710_pci_driver); 145module_comedi_pci_driver(apci1710_driver, apci1710_pci_driver);
149 146
diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c
index 8f8d3e95fc78..9ce1d26aff2f 100644
--- a/drivers/staging/comedi/drivers/addi_apci_2032.c
+++ b/drivers/staging/comedi/drivers/addi_apci_2032.c
@@ -29,7 +29,11 @@
29 * this source code. 29 * this source code.
30 */ 30 */
31 31
32#include <linux/pci.h>
33#include <linux/interrupt.h>
34
32#include "../comedidev.h" 35#include "../comedidev.h"
36#include "addi_watchdog.h"
33#include "comedi_fc.h" 37#include "comedi_fc.h"
34 38
35/* 39/*
@@ -45,17 +49,12 @@
45#define APCI2032_STATUS_REG 0x0c 49#define APCI2032_STATUS_REG 0x0c
46#define APCI2032_STATUS_IRQ (1 << 0) 50#define APCI2032_STATUS_IRQ (1 << 0)
47#define APCI2032_WDOG_REG 0x10 51#define APCI2032_WDOG_REG 0x10
48#define APCI2032_WDOG_RELOAD_REG 0x14 52
49#define APCI2032_WDOG_TIMEBASE 0x18 53struct apci2032_int_private {
50#define APCI2032_WDOG_CTRL_REG 0x1c 54 spinlock_t spinlock;
51#define APCI2032_WDOG_CTRL_ENABLE (1 << 0) 55 unsigned int stop_count;
52#define APCI2032_WDOG_CTRL_SW_TRIG (1 << 9) 56 bool active;
53#define APCI2032_WDOG_STATUS_REG 0x20 57 unsigned char enabled_isns;
54#define APCI2032_WDOG_STATUS_ENABLED (1 << 0)
55#define APCI2032_WDOG_STATUS_SW_TRIG (1 << 1)
56
57struct apci2032_private {
58 unsigned int wdog_ctrl;
59}; 58};
60 59
61static int apci2032_do_insn_bits(struct comedi_device *dev, 60static int apci2032_do_insn_bits(struct comedi_device *dev,
@@ -79,88 +78,47 @@ static int apci2032_do_insn_bits(struct comedi_device *dev,
79 return insn->n; 78 return insn->n;
80} 79}
81 80
82/* 81static int apci2032_int_insn_bits(struct comedi_device *dev,
83 * The watchdog subdevice is configured with two INSN_CONFIG instructions: 82 struct comedi_subdevice *s,
84 * 83 struct comedi_insn *insn,
85 * Enable the watchdog and set the reload timeout: 84 unsigned int *data)
86 * data[0] = INSN_CONFIG_ARM
87 * data[1] = timeout reload value
88 *
89 * Disable the watchdog:
90 * data[0] = INSN_CONFIG_DISARM
91 */
92static int apci2032_wdog_insn_config(struct comedi_device *dev,
93 struct comedi_subdevice *s,
94 struct comedi_insn *insn,
95 unsigned int *data)
96{ 85{
97 struct apci2032_private *devpriv = dev->private; 86 data[1] = inl(dev->iobase + APCI2032_INT_STATUS_REG) & 3;
98 unsigned int reload;
99
100 switch (data[0]) {
101 case INSN_CONFIG_ARM:
102 devpriv->wdog_ctrl = APCI2032_WDOG_CTRL_ENABLE;
103 reload = data[1] & s->maxdata;
104 outw(reload, dev->iobase + APCI2032_WDOG_RELOAD_REG);
105
106 /* Time base is 20ms, let the user know the timeout */
107 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
108 20 * reload + 20);
109 break;
110 case INSN_CONFIG_DISARM:
111 devpriv->wdog_ctrl = 0;
112 break;
113 default:
114 return -EINVAL;
115 }
116
117 outw(devpriv->wdog_ctrl, dev->iobase + APCI2032_WDOG_CTRL_REG);
118
119 return insn->n; 87 return insn->n;
120} 88}
121 89
122static int apci2032_wdog_insn_write(struct comedi_device *dev, 90static void apci2032_int_stop(struct comedi_device *dev,
123 struct comedi_subdevice *s, 91 struct comedi_subdevice *s)
124 struct comedi_insn *insn,
125 unsigned int *data)
126{ 92{
127 struct apci2032_private *devpriv = dev->private; 93 struct apci2032_int_private *subpriv = s->private;
128 int i;
129
130 if (devpriv->wdog_ctrl == 0) {
131 dev_warn(dev->class_dev, "watchdog is disabled\n");
132 return -EINVAL;
133 }
134
135 /* "ping" the watchdog */
136 for (i = 0; i < insn->n; i++) {
137 outw(devpriv->wdog_ctrl | APCI2032_WDOG_CTRL_SW_TRIG,
138 dev->iobase + APCI2032_WDOG_CTRL_REG);
139 }
140 94
141 return insn->n; 95 subpriv->active = false;
96 subpriv->enabled_isns = 0;
97 outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG);
142} 98}
143 99
144static int apci2032_wdog_insn_read(struct comedi_device *dev, 100static bool apci2032_int_start(struct comedi_device *dev,
145 struct comedi_subdevice *s, 101 struct comedi_subdevice *s,
146 struct comedi_insn *insn, 102 unsigned char enabled_isns)
147 unsigned int *data)
148{ 103{
149 int i; 104 struct apci2032_int_private *subpriv = s->private;
150 105 struct comedi_cmd *cmd = &s->async->cmd;
151 for (i = 0; i < insn->n; i++) 106 bool do_event;
152 data[i] = inl(dev->iobase + APCI2032_WDOG_STATUS_REG); 107
153 108 subpriv->enabled_isns = enabled_isns;
154 return insn->n; 109 subpriv->stop_count = cmd->stop_arg;
155} 110 if (cmd->stop_src == TRIG_COUNT && subpriv->stop_count == 0) {
111 /* An empty acquisition! */
112 s->async->events |= COMEDI_CB_EOA;
113 subpriv->active = false;
114 do_event = true;
115 } else {
116 subpriv->active = true;
117 outl(enabled_isns, dev->iobase + APCI2032_INT_CTRL_REG);
118 do_event = false;
119 }
156 120
157static int apci2032_int_insn_bits(struct comedi_device *dev, 121 return do_event;
158 struct comedi_subdevice *s,
159 struct comedi_insn *insn,
160 unsigned int *data)
161{
162 data[1] = s->state;
163 return insn->n;
164} 122}
165 123
166static int apci2032_int_cmdtest(struct comedi_device *dev, 124static int apci2032_int_cmdtest(struct comedi_device *dev,
@@ -172,15 +130,17 @@ static int apci2032_int_cmdtest(struct comedi_device *dev,
172 /* Step 1 : check if triggers are trivially valid */ 130 /* Step 1 : check if triggers are trivially valid */
173 131
174 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW); 132 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
175 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_OTHER); 133 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
176 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW); 134 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
177 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); 135 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
178 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_NONE); 136 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
179 137
180 if (err) 138 if (err)
181 return 1; 139 return 1;
182 140
183 /* Step 2a : make sure trigger sources are unique */ 141 /* Step 2a : make sure trigger sources are unique */
142 err |= cfc_check_trigger_is_unique(cmd->stop_src);
143
184 /* Step 2b : and mutually compatible */ 144 /* Step 2b : and mutually compatible */
185 145
186 if (err) 146 if (err)
@@ -189,18 +149,11 @@ static int apci2032_int_cmdtest(struct comedi_device *dev,
189 /* Step 3: check if arguments are trivially valid */ 149 /* Step 3: check if arguments are trivially valid */
190 150
191 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); 151 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
192 152 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
193 /*
194 * 0 == no trigger
195 * 1 == trigger on VCC interrupt
196 * 2 == trigger on CC interrupt
197 * 3 == trigger on either VCC or CC interrupt
198 */
199 err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg, 3);
200
201 err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0); 153 err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
202 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, 1); 154 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
203 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); 155 if (cmd->stop_src == TRIG_NONE)
156 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
204 157
205 if (err) 158 if (err)
206 return 3; 159 return 3;
@@ -217,8 +170,22 @@ static int apci2032_int_cmd(struct comedi_device *dev,
217 struct comedi_subdevice *s) 170 struct comedi_subdevice *s)
218{ 171{
219 struct comedi_cmd *cmd = &s->async->cmd; 172 struct comedi_cmd *cmd = &s->async->cmd;
173 struct apci2032_int_private *subpriv = s->private;
174 unsigned char enabled_isns;
175 unsigned int n;
176 unsigned long flags;
177 bool do_event;
178
179 enabled_isns = 0;
180 for (n = 0; n < cmd->chanlist_len; n++)
181 enabled_isns |= 1 << CR_CHAN(cmd->chanlist[n]);
182
183 spin_lock_irqsave(&subpriv->spinlock, flags);
184 do_event = apci2032_int_start(dev, s, enabled_isns);
185 spin_unlock_irqrestore(&subpriv->spinlock, flags);
220 186
221 outl(cmd->scan_begin_arg, dev->iobase + APCI2032_INT_CTRL_REG); 187 if (do_event)
188 comedi_event(dev, s);
222 189
223 return 0; 190 return 0;
224} 191}
@@ -226,7 +193,13 @@ static int apci2032_int_cmd(struct comedi_device *dev,
226static int apci2032_int_cancel(struct comedi_device *dev, 193static int apci2032_int_cancel(struct comedi_device *dev,
227 struct comedi_subdevice *s) 194 struct comedi_subdevice *s)
228{ 195{
229 outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); 196 struct apci2032_int_private *subpriv = s->private;
197 unsigned long flags;
198
199 spin_lock_irqsave(&subpriv->spinlock, flags);
200 if (subpriv->active)
201 apci2032_int_stop(dev, s);
202 spin_unlock_irqrestore(&subpriv->spinlock, flags);
230 203
231 return 0; 204 return 0;
232} 205}
@@ -235,19 +208,64 @@ static irqreturn_t apci2032_interrupt(int irq, void *d)
235{ 208{
236 struct comedi_device *dev = d; 209 struct comedi_device *dev = d;
237 struct comedi_subdevice *s = dev->read_subdev; 210 struct comedi_subdevice *s = dev->read_subdev;
211 struct apci2032_int_private *subpriv;
238 unsigned int val; 212 unsigned int val;
213 bool do_event = false;
214
215 if (!dev->attached)
216 return IRQ_NONE;
239 217
240 /* Check if VCC OR CC interrupt has occurred */ 218 /* Check if VCC OR CC interrupt has occurred */
241 val = inl(dev->iobase + APCI2032_STATUS_REG) & APCI2032_STATUS_IRQ; 219 val = inl(dev->iobase + APCI2032_STATUS_REG) & APCI2032_STATUS_IRQ;
242 if (!val) 220 if (!val)
243 return IRQ_NONE; 221 return IRQ_NONE;
244 222
245 s->state = inl(dev->iobase + APCI2032_INT_STATUS_REG); 223 subpriv = s->private;
246 outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); 224 spin_lock(&subpriv->spinlock);
225
226 val = inl(dev->iobase + APCI2032_INT_STATUS_REG) & 3;
227 /* Disable triggered interrupt sources. */
228 outl(~val & 3, dev->iobase + APCI2032_INT_CTRL_REG);
229 /*
230 * Note: We don't reenable the triggered interrupt sources because they
231 * are level-sensitive, hardware error status interrupt sources and
232 * they'd keep triggering interrupts repeatedly.
233 */
247 234
248 comedi_buf_put(s->async, s->state); 235 if (subpriv->active && (val & subpriv->enabled_isns) != 0) {
249 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 236 unsigned short bits;
250 comedi_event(dev, s); 237 unsigned int n, len;
238 unsigned int *chanlist;
239
240 /* Bits in scan data correspond to indices in channel list. */
241 bits = 0;
242 len = s->async->cmd.chanlist_len;
243 chanlist = &s->async->cmd.chanlist[0];
244 for (n = 0; n < len; n++)
245 if ((val & (1U << CR_CHAN(chanlist[n]))) != 0)
246 bits |= 1U << n;
247
248 if (comedi_buf_put(s->async, bits)) {
249 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS;
250 if (s->async->cmd.stop_src == TRIG_COUNT &&
251 subpriv->stop_count > 0) {
252 subpriv->stop_count--;
253 if (subpriv->stop_count == 0) {
254 /* end of acquisition */
255 s->async->events |= COMEDI_CB_EOA;
256 apci2032_int_stop(dev, s);
257 }
258 }
259 } else {
260 apci2032_int_stop(dev, s);
261 s->async->events |= COMEDI_CB_OVERFLOW;
262 }
263 do_event = true;
264 }
265
266 spin_unlock(&subpriv->spinlock);
267 if (do_event)
268 comedi_event(dev, s);
251 269
252 return IRQ_HANDLED; 270 return IRQ_HANDLED;
253} 271}
@@ -256,8 +274,8 @@ static int apci2032_reset(struct comedi_device *dev)
256{ 274{
257 outl(0x0, dev->iobase + APCI2032_DO_REG); 275 outl(0x0, dev->iobase + APCI2032_DO_REG);
258 outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG); 276 outl(0x0, dev->iobase + APCI2032_INT_CTRL_REG);
259 outl(0x0, dev->iobase + APCI2032_WDOG_CTRL_REG); 277
260 outl(0x0, dev->iobase + APCI2032_WDOG_RELOAD_REG); 278 addi_watchdog_reset(dev->iobase + APCI2032_WDOG_REG);
261 279
262 return 0; 280 return 0;
263} 281}
@@ -266,21 +284,16 @@ static int apci2032_auto_attach(struct comedi_device *dev,
266 unsigned long context_unused) 284 unsigned long context_unused)
267{ 285{
268 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 286 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
269 struct apci2032_private *devpriv;
270 struct comedi_subdevice *s; 287 struct comedi_subdevice *s;
271 int ret; 288 int ret;
272 289
273 dev->board_name = dev->driver->driver_name; 290 dev->board_name = dev->driver->driver_name;
274 291
275 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
276 if (!devpriv)
277 return -ENOMEM;
278 dev->private = devpriv;
279
280 ret = comedi_pci_enable(pcidev, dev->board_name); 292 ret = comedi_pci_enable(pcidev, dev->board_name);
281 if (ret) 293 if (ret)
282 return ret; 294 return ret;
283 dev->iobase = pci_resource_start(pcidev, 1); 295 dev->iobase = pci_resource_start(pcidev, 1);
296 apci2032_reset(dev);
284 297
285 if (pcidev->irq > 0) { 298 if (pcidev->irq > 0) {
286 ret = request_irq(pcidev->irq, apci2032_interrupt, 299 ret = request_irq(pcidev->irq, apci2032_interrupt,
@@ -304,32 +317,34 @@ static int apci2032_auto_attach(struct comedi_device *dev,
304 317
305 /* Initialize the watchdog subdevice */ 318 /* Initialize the watchdog subdevice */
306 s = &dev->subdevices[1]; 319 s = &dev->subdevices[1];
307 s->type = COMEDI_SUBD_TIMER; 320 ret = addi_watchdog_init(s, dev->iobase + APCI2032_WDOG_REG);
308 s->subdev_flags = SDF_WRITEABLE; 321 if (ret)
309 s->n_chan = 1; 322 return ret;
310 s->maxdata = 0xff;
311 s->insn_write = apci2032_wdog_insn_write;
312 s->insn_read = apci2032_wdog_insn_read;
313 s->insn_config = apci2032_wdog_insn_config;
314 323
315 /* Initialize the interrupt subdevice */ 324 /* Initialize the interrupt subdevice */
316 s = &dev->subdevices[2]; 325 s = &dev->subdevices[2];
326 s->type = COMEDI_SUBD_DI;
327 s->subdev_flags = SDF_READABLE;
328 s->n_chan = 2;
329 s->maxdata = 1;
330 s->range_table = &range_digital;
331 s->insn_bits = apci2032_int_insn_bits;
317 if (dev->irq) { 332 if (dev->irq) {
333 struct apci2032_int_private *subpriv;
334
318 dev->read_subdev = s; 335 dev->read_subdev = s;
319 s->type = COMEDI_SUBD_DI | SDF_CMD_READ; 336 subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
320 s->subdev_flags = SDF_READABLE; 337 if (!subpriv)
321 s->n_chan = 1; 338 return -ENOMEM;
322 s->maxdata = 1; 339 spin_lock_init(&subpriv->spinlock);
323 s->range_table = &range_digital; 340 s->private = subpriv;
324 s->insn_bits = apci2032_int_insn_bits; 341 s->subdev_flags = SDF_READABLE | SDF_CMD_READ;
342 s->len_chanlist = 2;
325 s->do_cmdtest = apci2032_int_cmdtest; 343 s->do_cmdtest = apci2032_int_cmdtest;
326 s->do_cmd = apci2032_int_cmd; 344 s->do_cmd = apci2032_int_cmd;
327 s->cancel = apci2032_int_cancel; 345 s->cancel = apci2032_int_cancel;
328 } else {
329 s->type = COMEDI_SUBD_UNUSED;
330 } 346 }
331 347
332 apci2032_reset(dev);
333 return 0; 348 return 0;
334} 349}
335 350
@@ -341,6 +356,10 @@ static void apci2032_detach(struct comedi_device *dev)
341 apci2032_reset(dev); 356 apci2032_reset(dev);
342 if (dev->irq) 357 if (dev->irq)
343 free_irq(dev->irq, dev); 358 free_irq(dev->irq, dev);
359 if (dev->read_subdev)
360 kfree(dev->read_subdev->private);
361 if (dev->subdevices)
362 addi_watchdog_cleanup(&dev->subdevices[1]);
344 if (pcidev) { 363 if (pcidev) {
345 if (dev->iobase) 364 if (dev->iobase)
346 comedi_pci_disable(pcidev); 365 comedi_pci_disable(pcidev);
@@ -360,11 +379,6 @@ static int apci2032_pci_probe(struct pci_dev *dev,
360 return comedi_pci_auto_config(dev, &apci2032_driver); 379 return comedi_pci_auto_config(dev, &apci2032_driver);
361} 380}
362 381
363static void apci2032_pci_remove(struct pci_dev *dev)
364{
365 comedi_pci_auto_unconfig(dev);
366}
367
368static DEFINE_PCI_DEVICE_TABLE(apci2032_pci_table) = { 382static DEFINE_PCI_DEVICE_TABLE(apci2032_pci_table) = {
369 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1004) }, 383 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1004) },
370 { 0 } 384 { 0 }
@@ -375,7 +389,7 @@ static struct pci_driver apci2032_pci_driver = {
375 .name = "addi_apci_2032", 389 .name = "addi_apci_2032",
376 .id_table = apci2032_pci_table, 390 .id_table = apci2032_pci_table,
377 .probe = apci2032_pci_probe, 391 .probe = apci2032_pci_probe,
378 .remove = apci2032_pci_remove, 392 .remove = comedi_pci_auto_unconfig,
379}; 393};
380module_comedi_pci_driver(apci2032_driver, apci2032_pci_driver); 394module_comedi_pci_driver(apci2032_driver, apci2032_pci_driver);
381 395
diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c
index 7c2c5db01218..b1c4226902e1 100644
--- a/drivers/staging/comedi/drivers/addi_apci_2200.c
+++ b/drivers/staging/comedi/drivers/addi_apci_2200.c
@@ -1,42 +1,152 @@
1/*
2 * addi_apci_2200.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 * Project manager: Eric Stolz
5 *
6 * ADDI-DATA GmbH
7 * Dieselstrasse 3
8 * D-77833 Ottersweier
9 * Tel: +19(0)7223/9493-0
10 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com
12 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 * You should also find the complete GPL in the COPYING file accompanying
29 * this source code.
30 */
31
32#include <linux/pci.h>
33
1#include "../comedidev.h" 34#include "../comedidev.h"
2#include "comedi_fc.h" 35#include "addi_watchdog.h"
3#include "amcc_s5933.h" 36
4 37/*
5#include "addi-data/addi_common.h" 38 * I/O Register Map
6 39 */
7#include "addi-data/addi_eeprom.c" 40#define APCI2200_DI_REG 0x00
8#include "addi-data/hwdrv_apci2200.c" 41#define APCI2200_DO_REG 0x04
9#include "addi-data/addi_common.c" 42#define APCI2200_WDOG_REG 0x08
10 43
11static const struct addi_board apci2200_boardtypes[] = { 44static int apci2200_di_insn_bits(struct comedi_device *dev,
12 { 45 struct comedi_subdevice *s,
13 .pc_DriverName = "apci2200", 46 struct comedi_insn *insn,
14 .i_VendorId = PCI_VENDOR_ID_ADDIDATA, 47 unsigned int *data)
15 .i_DeviceId = 0x1005, 48{
16 .i_IorangeBase0 = 4, 49 data[1] = inw(dev->iobase + APCI2200_DI_REG);
17 .i_IorangeBase1 = APCI2200_ADDRESS_RANGE, 50
18 .i_PCIEeprom = ADDIDATA_EEPROM, 51 return insn->n;
19 .pc_EepromChip = ADDIDATA_93C76, 52}
20 .i_NbrDiChannel = 8, 53
21 .i_NbrDoChannel = 16, 54static int apci2200_do_insn_bits(struct comedi_device *dev,
22 .i_Timer = 1, 55 struct comedi_subdevice *s,
23 .reset = i_APCI2200_Reset, 56 struct comedi_insn *insn,
24 .di_bits = apci2200_di_insn_bits, 57 unsigned int *data)
25 .do_bits = apci2200_do_insn_bits, 58{
26 .timer_config = i_APCI2200_ConfigWatchdog, 59 unsigned int mask = data[0];
27 .timer_write = i_APCI2200_StartStopWriteWatchdog, 60 unsigned int bits = data[1];
28 .timer_read = i_APCI2200_ReadWatchdog, 61
29 }, 62 s->state = inw(dev->iobase + APCI2200_DO_REG);
30}; 63 if (mask) {
64 s->state &= ~mask;
65 s->state |= (bits & mask);
66
67 outw(s->state, dev->iobase + APCI2200_DO_REG);
68 }
69
70 data[1] = s->state;
71
72 return insn->n;
73}
74
75static int apci2200_reset(struct comedi_device *dev)
76{
77 outw(0x0, dev->iobase + APCI2200_DO_REG);
78
79 addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG);
80
81 return 0;
82}
83
84static int apci2200_auto_attach(struct comedi_device *dev,
85 unsigned long context_unused)
86{
87 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
88 struct comedi_subdevice *s;
89 int ret;
90
91 dev->board_name = dev->driver->driver_name;
92
93 ret = comedi_pci_enable(pcidev, dev->board_name);
94 if (ret)
95 return ret;
96
97 dev->iobase = pci_resource_start(pcidev, 1);
98
99 ret = comedi_alloc_subdevices(dev, 3);
100 if (ret)
101 return ret;
102
103 /* Initialize the digital input subdevice */
104 s = &dev->subdevices[0];
105 s->type = COMEDI_SUBD_DI;
106 s->subdev_flags = SDF_READABLE;
107 s->n_chan = 8;
108 s->maxdata = 1;
109 s->range_table = &range_digital;
110 s->insn_bits = apci2200_di_insn_bits;
111
112 /* Initialize the digital output subdevice */
113 s = &dev->subdevices[1];
114 s->type = COMEDI_SUBD_DO;
115 s->subdev_flags = SDF_WRITEABLE;
116 s->n_chan = 16;
117 s->maxdata = 1;
118 s->range_table = &range_digital;
119 s->insn_bits = apci2200_do_insn_bits;
120
121 /* Initialize the watchdog subdevice */
122 s = &dev->subdevices[2];
123 ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG);
124 if (ret)
125 return ret;
126
127 apci2200_reset(dev);
128 return 0;
129}
130
131static void apci2200_detach(struct comedi_device *dev)
132{
133 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
134
135 if (dev->iobase)
136 apci2200_reset(dev);
137 if (dev->subdevices)
138 addi_watchdog_cleanup(&dev->subdevices[2]);
139 if (pcidev) {
140 if (dev->iobase)
141 comedi_pci_disable(pcidev);
142 }
143}
31 144
32static struct comedi_driver apci2200_driver = { 145static struct comedi_driver apci2200_driver = {
33 .driver_name = "addi_apci_2200", 146 .driver_name = "addi_apci_2200",
34 .module = THIS_MODULE, 147 .module = THIS_MODULE,
35 .auto_attach = addi_auto_attach, 148 .auto_attach = apci2200_auto_attach,
36 .detach = i_ADDI_Detach, 149 .detach = apci2200_detach,
37 .num_names = ARRAY_SIZE(apci2200_boardtypes),
38 .board_name = &apci2200_boardtypes[0].pc_DriverName,
39 .offset = sizeof(struct addi_board),
40}; 150};
41 151
42static int apci2200_pci_probe(struct pci_dev *dev, 152static int apci2200_pci_probe(struct pci_dev *dev,
@@ -45,11 +155,6 @@ static int apci2200_pci_probe(struct pci_dev *dev,
45 return comedi_pci_auto_config(dev, &apci2200_driver); 155 return comedi_pci_auto_config(dev, &apci2200_driver);
46} 156}
47 157
48static void apci2200_pci_remove(struct pci_dev *dev)
49{
50 comedi_pci_auto_unconfig(dev);
51}
52
53static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = { 158static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = {
54 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) }, 159 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) },
55 { 0 } 160 { 0 }
@@ -60,10 +165,10 @@ static struct pci_driver apci2200_pci_driver = {
60 .name = "addi_apci_2200", 165 .name = "addi_apci_2200",
61 .id_table = apci2200_pci_table, 166 .id_table = apci2200_pci_table,
62 .probe = apci2200_pci_probe, 167 .probe = apci2200_pci_probe,
63 .remove = apci2200_pci_remove, 168 .remove = comedi_pci_auto_unconfig,
64}; 169};
65module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver); 170module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver);
66 171
172MODULE_DESCRIPTION("ADDI-DATA APCI-2200 Relay board, optically isolated");
67MODULE_AUTHOR("Comedi http://www.comedi.org"); 173MODULE_AUTHOR("Comedi http://www.comedi.org");
68MODULE_DESCRIPTION("Comedi low-level driver");
69MODULE_LICENSE("GPL"); 174MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c
index fec2962affc7..917234d24e99 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3120.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3120.c
@@ -1,3 +1,5 @@
1#include <linux/pci.h>
2
1#include "../comedidev.h" 3#include "../comedidev.h"
2#include "comedi_fc.h" 4#include "comedi_fc.h"
3#include "amcc_s5933.h" 5#include "amcc_s5933.h"
@@ -251,11 +253,6 @@ static int apci3120_pci_probe(struct pci_dev *dev,
251 return comedi_pci_auto_config(dev, &apci3120_driver); 253 return comedi_pci_auto_config(dev, &apci3120_driver);
252} 254}
253 255
254static void apci3120_pci_remove(struct pci_dev *dev)
255{
256 comedi_pci_auto_unconfig(dev);
257}
258
259static DEFINE_PCI_DEVICE_TABLE(apci3120_pci_table) = { 256static DEFINE_PCI_DEVICE_TABLE(apci3120_pci_table) = {
260 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x818d) }, 257 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x818d) },
261 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x828d) }, 258 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA_OLD, 0x828d) },
@@ -267,7 +264,7 @@ static struct pci_driver apci3120_pci_driver = {
267 .name = "addi_apci_3120", 264 .name = "addi_apci_3120",
268 .id_table = apci3120_pci_table, 265 .id_table = apci3120_pci_table,
269 .probe = apci3120_pci_probe, 266 .probe = apci3120_pci_probe,
270 .remove = apci3120_pci_remove, 267 .remove = comedi_pci_auto_unconfig,
271}; 268};
272module_comedi_pci_driver(apci3120_driver, apci3120_pci_driver); 269module_comedi_pci_driver(apci3120_driver, apci3120_pci_driver);
273 270
diff --git a/drivers/staging/comedi/drivers/addi_apci_3200.c b/drivers/staging/comedi/drivers/addi_apci_3200.c
index 9085b774b48d..90ee4f844f91 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3200.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3200.c
@@ -1,3 +1,5 @@
1#include <linux/pci.h>
2
1#include <asm/i387.h> 3#include <asm/i387.h>
2 4
3#include "../comedidev.h" 5#include "../comedidev.h"
@@ -106,15 +108,10 @@ static int apci3200_pci_probe(struct pci_dev *dev,
106 return comedi_pci_auto_config(dev, &apci3200_driver); 108 return comedi_pci_auto_config(dev, &apci3200_driver);
107} 109}
108 110
109static void apci3200_pci_remove(struct pci_dev *dev)
110{
111 comedi_pci_auto_unconfig(dev);
112}
113
114static struct pci_driver apci3200_pci_driver = { 111static struct pci_driver apci3200_pci_driver = {
115 .name = "addi_apci_3200", 112 .name = "addi_apci_3200",
116 .id_table = apci3200_pci_table, 113 .id_table = apci3200_pci_table,
117 .probe = apci3200_pci_probe, 114 .probe = apci3200_pci_probe,
118 .remove = apci3200_pci_remove, 115 .remove = comedi_pci_auto_unconfig,
119}; 116};
120module_comedi_pci_driver(apci3200_driver, apci3200_pci_driver); 117module_comedi_pci_driver(apci3200_driver, apci3200_pci_driver);
diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c
index ed297deb8634..786fcaf82c32 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3501.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3501.c
@@ -1,54 +1,445 @@
1/*
2 * addi_apci_3501.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 * Project manager: Eric Stolz
5 *
6 * ADDI-DATA GmbH
7 * Dieselstrasse 3
8 * D-77833 Ottersweier
9 * Tel: +19(0)7223/9493-0
10 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com
12 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 * You should also find the complete GPL in the COPYING file accompanying
29 * this source code.
30 */
31
32#include <linux/pci.h>
33#include <linux/interrupt.h>
34#include <linux/sched.h>
35
1#include "../comedidev.h" 36#include "../comedidev.h"
2#include "comedi_fc.h" 37#include "comedi_fc.h"
3#include "amcc_s5933.h" 38#include "amcc_s5933.h"
4 39
5#include "addi-data/addi_common.h" 40/*
41 * PCI bar 1 register I/O map
42 */
43#define APCI3501_AO_CTRL_STATUS_REG 0x00
44#define APCI3501_AO_CTRL_BIPOLAR (1 << 0)
45#define APCI3501_AO_STATUS_READY (1 << 8)
46#define APCI3501_AO_DATA_REG 0x04
47#define APCI3501_AO_DATA_CHAN(x) ((x) << 0)
48#define APCI3501_AO_DATA_VAL(x) ((x) << 8)
49#define APCI3501_AO_DATA_BIPOLAR (1 << 31)
50#define APCI3501_AO_TRIG_SCS_REG 0x08
51#define APCI3501_TIMER_SYNC_REG 0x20
52#define APCI3501_TIMER_RELOAD_REG 0x24
53#define APCI3501_TIMER_TIMEBASE_REG 0x28
54#define APCI3501_TIMER_CTRL_REG 0x2c
55#define APCI3501_TIMER_STATUS_REG 0x30
56#define APCI3501_TIMER_IRQ_REG 0x34
57#define APCI3501_TIMER_WARN_RELOAD_REG 0x38
58#define APCI3501_TIMER_WARN_TIMEBASE_REG 0x3c
59#define APCI3501_DO_REG 0x40
60#define APCI3501_DI_REG 0x50
6 61
7#include "addi-data/addi_eeprom.c" 62/*
8#include "addi-data/hwdrv_apci3501.c" 63 * AMCC S5933 NVRAM
9#include "addi-data/addi_common.c" 64 */
10 65#define NVRAM_USER_DATA_START 0x100
11static const struct addi_board apci3501_boardtypes[] = { 66
12 { 67#define NVCMD_BEGIN_READ (0x7 << 5)
13 .pc_DriverName = "apci3501", 68#define NVCMD_LOAD_LOW (0x4 << 5)
14 .i_VendorId = PCI_VENDOR_ID_ADDIDATA, 69#define NVCMD_LOAD_HIGH (0x5 << 5)
15 .i_DeviceId = 0x3001, 70
16 .i_IorangeBase0 = 64, 71/*
17 .i_IorangeBase1 = APCI3501_ADDRESS_RANGE, 72 * Function types stored in the eeprom
18 .i_PCIEeprom = ADDIDATA_EEPROM, 73 */
19 .pc_EepromChip = ADDIDATA_S5933, 74#define EEPROM_DIGITALINPUT 0
20 .i_AoMaxdata = 16383, 75#define EEPROM_DIGITALOUTPUT 1
21 .pr_AoRangelist = &range_apci3501_ao, 76#define EEPROM_ANALOGINPUT 2
22 .i_NbrDiChannel = 2, 77#define EEPROM_ANALOGOUTPUT 3
23 .i_NbrDoChannel = 2, 78#define EEPROM_TIMER 4
24 .i_DoMaxdata = 0x3, 79#define EEPROM_WATCHDOG 5
25 .i_Timer = 1, 80#define EEPROM_TIMER_WATCHDOG_COUNTER 10
26 .interrupt = v_APCI3501_Interrupt, 81
27 .reset = i_APCI3501_Reset, 82struct apci3501_private {
28 .ao_config = i_APCI3501_ConfigAnalogOutput, 83 int i_IobaseAmcc;
29 .ao_write = i_APCI3501_WriteAnalogOutput, 84 struct task_struct *tsk_Current;
30 .di_bits = apci3501_di_insn_bits, 85 unsigned char b_TimerSelectMode;
31 .do_bits = apci3501_do_insn_bits,
32 .timer_config = i_APCI3501_ConfigTimerCounterWatchdog,
33 .timer_write = i_APCI3501_StartStopWriteTimerCounterWatchdog,
34 .timer_read = i_APCI3501_ReadTimerCounterWatchdog,
35 },
36}; 86};
37 87
38static DEFINE_PCI_DEVICE_TABLE(apci3501_pci_table) = { 88static struct comedi_lrange apci3501_ao_range = {
39 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3001) }, 89 2, {
40 { 0 } 90 BIP_RANGE(10),
91 UNI_RANGE(10)
92 }
41}; 93};
42MODULE_DEVICE_TABLE(pci, apci3501_pci_table); 94
95static int apci3501_wait_for_dac(struct comedi_device *dev)
96{
97 unsigned int status;
98
99 do {
100 status = inl(dev->iobase + APCI3501_AO_CTRL_STATUS_REG);
101 } while (!(status & APCI3501_AO_STATUS_READY));
102
103 return 0;
104}
105
106static int apci3501_ao_insn_write(struct comedi_device *dev,
107 struct comedi_subdevice *s,
108 struct comedi_insn *insn,
109 unsigned int *data)
110{
111 unsigned int chan = CR_CHAN(insn->chanspec);
112 unsigned int range = CR_RANGE(insn->chanspec);
113 unsigned int val = 0;
114 int i;
115 int ret;
116
117 /*
118 * All analog output channels have the same output range.
119 * 14-bit bipolar: 0-10V
120 * 13-bit unipolar: +/-10V
121 * Changing the range of one channel changes all of them!
122 */
123 if (range) {
124 outl(0, dev->iobase + APCI3501_AO_CTRL_STATUS_REG);
125 } else {
126 val |= APCI3501_AO_DATA_BIPOLAR;
127 outl(APCI3501_AO_CTRL_BIPOLAR,
128 dev->iobase + APCI3501_AO_CTRL_STATUS_REG);
129 }
130
131 val |= APCI3501_AO_DATA_CHAN(chan);
132
133 for (i = 0; i < insn->n; i++) {
134 if (range == 1) {
135 if (data[i] > 0x1fff) {
136 dev_err(dev->class_dev,
137 "Unipolar resolution is only 13-bits\n");
138 return -EINVAL;
139 }
140 }
141
142 ret = apci3501_wait_for_dac(dev);
143 if (ret)
144 return ret;
145
146 outl(val | APCI3501_AO_DATA_VAL(data[i]),
147 dev->iobase + APCI3501_AO_DATA_REG);
148 }
149
150 return insn->n;
151}
152
153#include "addi-data/hwdrv_apci3501.c"
154
155static int apci3501_di_insn_bits(struct comedi_device *dev,
156 struct comedi_subdevice *s,
157 struct comedi_insn *insn,
158 unsigned int *data)
159{
160 data[1] = inl(dev->iobase + APCI3501_DI_REG) & 0x3;
161
162 return insn->n;
163}
164
165static int apci3501_do_insn_bits(struct comedi_device *dev,
166 struct comedi_subdevice *s,
167 struct comedi_insn *insn,
168 unsigned int *data)
169{
170 unsigned int mask = data[0];
171 unsigned int bits = data[1];
172
173 s->state = inl(dev->iobase + APCI3501_DO_REG);
174 if (mask) {
175 s->state &= ~mask;
176 s->state |= (bits & mask);
177
178 outl(s->state, dev->iobase + APCI3501_DO_REG);
179 }
180
181 data[1] = s->state;
182
183 return insn->n;
184}
185
186static void apci3501_eeprom_wait(unsigned long iobase)
187{
188 unsigned char val;
189
190 do {
191 val = inb(iobase + AMCC_OP_REG_MCSR_NVCMD);
192 } while (val & 0x80);
193}
194
195static unsigned short apci3501_eeprom_readw(unsigned long iobase,
196 unsigned short addr)
197{
198 unsigned short val = 0;
199 unsigned char tmp;
200 unsigned char i;
201
202 /* Add the offset to the start of the user data */
203 addr += NVRAM_USER_DATA_START;
204
205 for (i = 0; i < 2; i++) {
206 /* Load the low 8 bit address */
207 outb(NVCMD_LOAD_LOW, iobase + AMCC_OP_REG_MCSR_NVCMD);
208 apci3501_eeprom_wait(iobase);
209 outb((addr + i) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA);
210 apci3501_eeprom_wait(iobase);
211
212 /* Load the high 8 bit address */
213 outb(NVCMD_LOAD_HIGH, iobase + AMCC_OP_REG_MCSR_NVCMD);
214 apci3501_eeprom_wait(iobase);
215 outb(((addr + i) >> 8) & 0xff,
216 iobase + AMCC_OP_REG_MCSR_NVDATA);
217 apci3501_eeprom_wait(iobase);
218
219 /* Read the eeprom data byte */
220 outb(NVCMD_BEGIN_READ, iobase + AMCC_OP_REG_MCSR_NVCMD);
221 apci3501_eeprom_wait(iobase);
222 tmp = inb(iobase + AMCC_OP_REG_MCSR_NVDATA);
223 apci3501_eeprom_wait(iobase);
224
225 if (i == 0)
226 val |= tmp;
227 else
228 val |= (tmp << 8);
229 }
230
231 return val;
232}
233
234static int apci3501_eeprom_get_ao_n_chan(struct comedi_device *dev)
235{
236 struct apci3501_private *devpriv = dev->private;
237 unsigned long iobase = devpriv->i_IobaseAmcc;
238 unsigned char nfuncs;
239 int i;
240
241 nfuncs = apci3501_eeprom_readw(iobase, 10) & 0xff;
242
243 /* Read functionality details */
244 for (i = 0; i < nfuncs; i++) {
245 unsigned short offset = i * 4;
246 unsigned short addr;
247 unsigned char func;
248 unsigned short val;
249
250 func = apci3501_eeprom_readw(iobase, 12 + offset) & 0x3f;
251 addr = apci3501_eeprom_readw(iobase, 14 + offset);
252
253 if (func == EEPROM_ANALOGOUTPUT) {
254 val = apci3501_eeprom_readw(iobase, addr + 10);
255 return (val >> 4) & 0x3ff;
256 }
257 }
258 return 0;
259}
260
261static int apci3501_eeprom_insn_read(struct comedi_device *dev,
262 struct comedi_subdevice *s,
263 struct comedi_insn *insn,
264 unsigned int *data)
265{
266 struct apci3501_private *devpriv = dev->private;
267 unsigned short addr = CR_CHAN(insn->chanspec);
268
269 data[0] = apci3501_eeprom_readw(devpriv->i_IobaseAmcc, 2 * addr);
270
271 return insn->n;
272}
273
274static irqreturn_t apci3501_interrupt(int irq, void *d)
275{
276 struct comedi_device *dev = d;
277 struct apci3501_private *devpriv = dev->private;
278 unsigned int ui_Timer_AOWatchdog;
279 unsigned long ul_Command1;
280 int i_temp;
281
282 /* Disable Interrupt */
283 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
284 ul_Command1 = (ul_Command1 & 0xFFFFF9FDul);
285 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
286
287 ui_Timer_AOWatchdog = inl(dev->iobase + APCI3501_TIMER_IRQ_REG) & 0x1;
288 if ((!ui_Timer_AOWatchdog)) {
289 comedi_error(dev, "IRQ from unknown source");
290 return IRQ_NONE;
291 }
292
293 /* Enable Interrupt Send a signal to from kernel to user space */
294 send_sig(SIGIO, devpriv->tsk_Current, 0);
295 ul_Command1 = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
296 ul_Command1 = ((ul_Command1 & 0xFFFFF9FDul) | 1 << 1);
297 outl(ul_Command1, dev->iobase + APCI3501_TIMER_CTRL_REG);
298 i_temp = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1;
299
300 return IRQ_HANDLED;
301}
302
303static int apci3501_reset(struct comedi_device *dev)
304{
305 unsigned int val;
306 int chan;
307 int ret;
308
309 /* Reset all digital outputs to "0" */
310 outl(0x0, dev->iobase + APCI3501_DO_REG);
311
312 /* Default all analog outputs to 0V (bipolar) */
313 outl(APCI3501_AO_CTRL_BIPOLAR,
314 dev->iobase + APCI3501_AO_CTRL_STATUS_REG);
315 val = APCI3501_AO_DATA_BIPOLAR | APCI3501_AO_DATA_VAL(0);
316
317 /* Set all analog output channels */
318 for (chan = 0; chan < 8; chan++) {
319 ret = apci3501_wait_for_dac(dev);
320 if (ret) {
321 dev_warn(dev->class_dev,
322 "%s: DAC not-ready for channel %i\n",
323 __func__, chan);
324 } else {
325 outl(val | APCI3501_AO_DATA_CHAN(chan),
326 dev->iobase + APCI3501_AO_DATA_REG);
327 }
328 }
329
330 return 0;
331}
332
333static int apci3501_auto_attach(struct comedi_device *dev,
334 unsigned long context_unused)
335{
336 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
337 struct apci3501_private *devpriv;
338 struct comedi_subdevice *s;
339 int ao_n_chan;
340 int ret;
341
342 dev->board_name = dev->driver->driver_name;
343
344 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
345 if (!devpriv)
346 return -ENOMEM;
347 dev->private = devpriv;
348
349 ret = comedi_pci_enable(pcidev, dev->board_name);
350 if (ret)
351 return ret;
352
353 dev->iobase = pci_resource_start(pcidev, 1);
354 devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0);
355
356 ao_n_chan = apci3501_eeprom_get_ao_n_chan(dev);
357
358 if (pcidev->irq > 0) {
359 ret = request_irq(pcidev->irq, apci3501_interrupt, IRQF_SHARED,
360 dev->board_name, dev);
361 if (ret == 0)
362 dev->irq = pcidev->irq;
363 }
364
365 ret = comedi_alloc_subdevices(dev, 5);
366 if (ret)
367 return ret;
368
369 /* Initialize the analog output subdevice */
370 s = &dev->subdevices[0];
371 if (ao_n_chan) {
372 s->type = COMEDI_SUBD_AO;
373 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
374 s->n_chan = ao_n_chan;
375 s->maxdata = 0x3fff;
376 s->range_table = &apci3501_ao_range;
377 s->insn_write = apci3501_ao_insn_write;
378 } else {
379 s->type = COMEDI_SUBD_UNUSED;
380 }
381
382 /* Initialize the digital input subdevice */
383 s = &dev->subdevices[1];
384 s->type = COMEDI_SUBD_DI;
385 s->subdev_flags = SDF_READABLE;
386 s->n_chan = 2;
387 s->maxdata = 1;
388 s->range_table = &range_digital;
389 s->insn_bits = apci3501_di_insn_bits;
390
391 /* Initialize the digital output subdevice */
392 s = &dev->subdevices[2];
393 s->type = COMEDI_SUBD_DO;
394 s->subdev_flags = SDF_WRITEABLE;
395 s->n_chan = 2;
396 s->maxdata = 1;
397 s->range_table = &range_digital;
398 s->insn_bits = apci3501_do_insn_bits;
399
400 /* Initialize the timer/watchdog subdevice */
401 s = &dev->subdevices[3];
402 s->type = COMEDI_SUBD_TIMER;
403 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
404 s->n_chan = 1;
405 s->maxdata = 0;
406 s->len_chanlist = 1;
407 s->range_table = &range_digital;
408 s->insn_write = i_APCI3501_StartStopWriteTimerCounterWatchdog;
409 s->insn_read = i_APCI3501_ReadTimerCounterWatchdog;
410 s->insn_config = i_APCI3501_ConfigTimerCounterWatchdog;
411
412 /* Initialize the eeprom subdevice */
413 s = &dev->subdevices[4];
414 s->type = COMEDI_SUBD_MEMORY;
415 s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
416 s->n_chan = 256;
417 s->maxdata = 0xffff;
418 s->insn_read = apci3501_eeprom_insn_read;
419
420 apci3501_reset(dev);
421 return 0;
422}
423
424static void apci3501_detach(struct comedi_device *dev)
425{
426 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
427
428 if (dev->iobase)
429 apci3501_reset(dev);
430 if (dev->irq)
431 free_irq(dev->irq, dev);
432 if (pcidev) {
433 if (dev->iobase)
434 comedi_pci_disable(pcidev);
435 }
436}
43 437
44static struct comedi_driver apci3501_driver = { 438static struct comedi_driver apci3501_driver = {
45 .driver_name = "addi_apci_3501", 439 .driver_name = "addi_apci_3501",
46 .module = THIS_MODULE, 440 .module = THIS_MODULE,
47 .auto_attach = addi_auto_attach, 441 .auto_attach = apci3501_auto_attach,
48 .detach = i_ADDI_Detach, 442 .detach = apci3501_detach,
49 .num_names = ARRAY_SIZE(apci3501_boardtypes),
50 .board_name = &apci3501_boardtypes[0].pc_DriverName,
51 .offset = sizeof(struct addi_board),
52}; 443};
53 444
54static int apci3501_pci_probe(struct pci_dev *dev, 445static int apci3501_pci_probe(struct pci_dev *dev,
@@ -57,19 +448,20 @@ static int apci3501_pci_probe(struct pci_dev *dev,
57 return comedi_pci_auto_config(dev, &apci3501_driver); 448 return comedi_pci_auto_config(dev, &apci3501_driver);
58} 449}
59 450
60static void apci3501_pci_remove(struct pci_dev *dev) 451static DEFINE_PCI_DEVICE_TABLE(apci3501_pci_table) = {
61{ 452 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3001) },
62 comedi_pci_auto_unconfig(dev); 453 { 0 }
63} 454};
455MODULE_DEVICE_TABLE(pci, apci3501_pci_table);
64 456
65static struct pci_driver apci3501_pci_driver = { 457static struct pci_driver apci3501_pci_driver = {
66 .name = "addi_apci_3501", 458 .name = "addi_apci_3501",
67 .id_table = apci3501_pci_table, 459 .id_table = apci3501_pci_table,
68 .probe = apci3501_pci_probe, 460 .probe = apci3501_pci_probe,
69 .remove = apci3501_pci_remove, 461 .remove = comedi_pci_auto_unconfig,
70}; 462};
71module_comedi_pci_driver(apci3501_driver, apci3501_pci_driver); 463module_comedi_pci_driver(apci3501_driver, apci3501_pci_driver);
72 464
465MODULE_DESCRIPTION("ADDI-DATA APCI-3501 Analog output board");
73MODULE_AUTHOR("Comedi http://www.comedi.org"); 466MODULE_AUTHOR("Comedi http://www.comedi.org");
74MODULE_DESCRIPTION("Comedi low-level driver");
75MODULE_LICENSE("GPL"); 467MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
index 1562347ed64b..09d4b21fce23 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
@@ -1,3 +1,5 @@
1#include <linux/pci.h>
2
1#include "../comedidev.h" 3#include "../comedidev.h"
2#include "comedi_fc.h" 4#include "comedi_fc.h"
3#include "amcc_s5933.h" 5#include "amcc_s5933.h"
@@ -751,11 +753,6 @@ static int apci3xxx_pci_probe(struct pci_dev *dev,
751 return comedi_pci_auto_config(dev, &apci3xxx_driver); 753 return comedi_pci_auto_config(dev, &apci3xxx_driver);
752} 754}
753 755
754static void apci3xxx_pci_remove(struct pci_dev *dev)
755{
756 comedi_pci_auto_unconfig(dev);
757}
758
759static DEFINE_PCI_DEVICE_TABLE(apci3xxx_pci_table) = { 756static DEFINE_PCI_DEVICE_TABLE(apci3xxx_pci_table) = {
760 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3010) }, 757 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3010) },
761 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x300f) }, 758 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x300f) },
@@ -790,7 +787,7 @@ static struct pci_driver apci3xxx_pci_driver = {
790 .name = "addi_apci_3xxx", 787 .name = "addi_apci_3xxx",
791 .id_table = apci3xxx_pci_table, 788 .id_table = apci3xxx_pci_table,
792 .probe = apci3xxx_pci_probe, 789 .probe = apci3xxx_pci_probe,
793 .remove = apci3xxx_pci_remove, 790 .remove = comedi_pci_auto_unconfig,
794}; 791};
795module_comedi_pci_driver(apci3xxx_driver, apci3xxx_pci_driver); 792module_comedi_pci_driver(apci3xxx_driver, apci3xxx_pci_driver);
796 793
diff --git a/drivers/staging/comedi/drivers/addi_watchdog.c b/drivers/staging/comedi/drivers/addi_watchdog.c
new file mode 100644
index 000000000000..375ab665e091
--- /dev/null
+++ b/drivers/staging/comedi/drivers/addi_watchdog.c
@@ -0,0 +1,172 @@
1/*
2 * COMEDI driver for the watchdog subdevice found on some addi-data boards
3 * Copyright (c) 2013 H Hartley Sweeten <hsweeten@visionengravers.com>
4 *
5 * Based on implementations in various addi-data COMEDI drivers.
6 *
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#include "../comedidev.h"
26#include "addi_watchdog.h"
27
28/*
29 * Register offsets/defines for the addi-data watchdog
30 */
31#define ADDI_WDOG_REG 0x00
32#define ADDI_WDOG_RELOAD_REG 0x04
33#define ADDI_WDOG_TIMEBASE 0x08
34#define ADDI_WDOG_CTRL_REG 0x0c
35#define ADDI_WDOG_CTRL_ENABLE (1 << 0)
36#define ADDI_WDOG_CTRL_SW_TRIG (1 << 9)
37#define ADDI_WDOG_STATUS_REG 0x10
38#define ADDI_WDOG_STATUS_ENABLED (1 << 0)
39#define ADDI_WDOG_STATUS_SW_TRIG (1 << 1)
40
41struct addi_watchdog_private {
42 unsigned long iobase;
43 unsigned int wdog_ctrl;
44};
45
46/*
47 * The watchdog subdevice is configured with two INSN_CONFIG instructions:
48 *
49 * Enable the watchdog and set the reload timeout:
50 * data[0] = INSN_CONFIG_ARM
51 * data[1] = timeout reload value
52 *
53 * Disable the watchdog:
54 * data[0] = INSN_CONFIG_DISARM
55 */
56static int addi_watchdog_insn_config(struct comedi_device *dev,
57 struct comedi_subdevice *s,
58 struct comedi_insn *insn,
59 unsigned int *data)
60{
61 struct addi_watchdog_private *spriv = s->private;
62 unsigned int reload;
63
64 switch (data[0]) {
65 case INSN_CONFIG_ARM:
66 spriv->wdog_ctrl = ADDI_WDOG_CTRL_ENABLE;
67 reload = data[1] & s->maxdata;
68 outl(reload, spriv->iobase + ADDI_WDOG_RELOAD_REG);
69
70 /* Time base is 20ms, let the user know the timeout */
71 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
72 20 * reload + 20);
73 break;
74 case INSN_CONFIG_DISARM:
75 spriv->wdog_ctrl = 0;
76 break;
77 default:
78 return -EINVAL;
79 }
80
81 outl(spriv->wdog_ctrl, spriv->iobase + ADDI_WDOG_CTRL_REG);
82
83 return insn->n;
84}
85
86static int addi_watchdog_insn_read(struct comedi_device *dev,
87 struct comedi_subdevice *s,
88 struct comedi_insn *insn,
89 unsigned int *data)
90{
91 struct addi_watchdog_private *spriv = s->private;
92 int i;
93
94 for (i = 0; i < insn->n; i++)
95 data[i] = inl(spriv->iobase + ADDI_WDOG_STATUS_REG);
96
97 return insn->n;
98}
99
100static int addi_watchdog_insn_write(struct comedi_device *dev,
101 struct comedi_subdevice *s,
102 struct comedi_insn *insn,
103 unsigned int *data)
104{
105 struct addi_watchdog_private *spriv = s->private;
106 int i;
107
108 if (spriv->wdog_ctrl == 0) {
109 dev_warn(dev->class_dev, "watchdog is disabled\n");
110 return -EINVAL;
111 }
112
113 /* "ping" the watchdog */
114 for (i = 0; i < insn->n; i++) {
115 outl(spriv->wdog_ctrl | ADDI_WDOG_CTRL_SW_TRIG,
116 spriv->iobase + ADDI_WDOG_CTRL_REG);
117 }
118
119 return insn->n;
120}
121
122void addi_watchdog_reset(unsigned long iobase)
123{
124 outl(0x0, iobase + ADDI_WDOG_CTRL_REG);
125 outl(0x0, iobase + ADDI_WDOG_RELOAD_REG);
126}
127EXPORT_SYMBOL_GPL(addi_watchdog_reset);
128
129int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase)
130{
131 struct addi_watchdog_private *spriv;
132
133 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
134 if (!spriv)
135 return -ENOMEM;
136
137 spriv->iobase = iobase;
138
139 s->private = spriv;
140
141 s->type = COMEDI_SUBD_TIMER;
142 s->subdev_flags = SDF_WRITEABLE;
143 s->n_chan = 1;
144 s->maxdata = 0xff;
145 s->insn_config = addi_watchdog_insn_config;
146 s->insn_read = addi_watchdog_insn_read;
147 s->insn_write = addi_watchdog_insn_write;
148
149 return 0;
150}
151EXPORT_SYMBOL_GPL(addi_watchdog_init);
152
153void addi_watchdog_cleanup(struct comedi_subdevice *s)
154{
155 kfree(s->private);
156}
157EXPORT_SYMBOL_GPL(addi_watchdog_cleanup);
158
159static int __init addi_watchdog_module_init(void)
160{
161 return 0;
162}
163module_init(addi_watchdog_module_init);
164
165static void __exit addi_watchdog_module_exit(void)
166{
167}
168module_exit(addi_watchdog_module_exit);
169
170MODULE_DESCRIPTION("ADDI-DATA Watchdog subdevice");
171MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
172MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/addi_watchdog.h b/drivers/staging/comedi/drivers/addi_watchdog.h
new file mode 100644
index 000000000000..f374a7bff44d
--- /dev/null
+++ b/drivers/staging/comedi/drivers/addi_watchdog.h
@@ -0,0 +1,10 @@
1#ifndef _ADDI_WATCHDOG_H
2#define _ADDI_WATCHDOG_H
3
4#include "../comedidev.h"
5
6void addi_watchdog_reset(unsigned long iobase);
7int addi_watchdog_init(struct comedi_subdevice *, unsigned long iobase);
8void addi_watchdog_cleanup(struct comedi_subdevice *s);
9
10#endif
diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c
index 9a56eed3910f..7b3e331616ed 100644
--- a/drivers/staging/comedi/drivers/adl_pci6208.c
+++ b/drivers/staging/comedi/drivers/adl_pci6208.c
@@ -42,6 +42,8 @@ References:
42 - adl_pci9118.c 42 - adl_pci9118.c
43*/ 43*/
44 44
45#include <linux/pci.h>
46
45#include "../comedidev.h" 47#include "../comedidev.h"
46 48
47/* 49/*
@@ -270,11 +272,6 @@ static int adl_pci6208_pci_probe(struct pci_dev *dev,
270 return comedi_pci_auto_config(dev, &adl_pci6208_driver); 272 return comedi_pci_auto_config(dev, &adl_pci6208_driver);
271} 273}
272 274
273static void adl_pci6208_pci_remove(struct pci_dev *dev)
274{
275 comedi_pci_auto_unconfig(dev);
276}
277
278static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = { 275static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
279 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6208) }, 276 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6208) },
280 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6216) }, 277 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI6216) },
@@ -286,7 +283,7 @@ static struct pci_driver adl_pci6208_pci_driver = {
286 .name = "adl_pci6208", 283 .name = "adl_pci6208",
287 .id_table = adl_pci6208_pci_table, 284 .id_table = adl_pci6208_pci_table,
288 .probe = adl_pci6208_pci_probe, 285 .probe = adl_pci6208_pci_probe,
289 .remove = adl_pci6208_pci_remove, 286 .remove = comedi_pci_auto_unconfig,
290}; 287};
291module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver); 288module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
292 289
diff --git a/drivers/staging/comedi/drivers/adl_pci7x3x.c b/drivers/staging/comedi/drivers/adl_pci7x3x.c
index 772edc02f5ce..f27f48e6e702 100644
--- a/drivers/staging/comedi/drivers/adl_pci7x3x.c
+++ b/drivers/staging/comedi/drivers/adl_pci7x3x.c
@@ -38,12 +38,6 @@ Author: H Hartley Sweeten <hsweeten@visionengravers.com>
38Updated: Thu, 02 Aug 2012 14:27:46 -0700 38Updated: Thu, 02 Aug 2012 14:27:46 -0700
39Status: untested 39Status: untested
40 40
41This driver only attaches using the PCI PnP auto config support
42in the comedi core. The module parameter 'comedi_autoconfig'
43must be 1 (default) to enable this feature. The COMEDI_DEVCONFIG
44ioctl, used by the comedi_config utility, is not supported by
45this driver.
46
47The PCI-7230, PCI-7432 and PCI-7433 boards also support external 41The PCI-7230, PCI-7432 and PCI-7433 boards also support external
48interrupt signals on digital input channels 0 and 1. The PCI-7233 42interrupt signals on digital input channels 0 and 1. The PCI-7233
49has dual-interrupt sources for change-of-state (COS) on any 16 43has dual-interrupt sources for change-of-state (COS) on any 16
@@ -51,9 +45,11 @@ digital input channels of LSB and for COS on any 16 digital input
51lines of MSB. Interrupts are not currently supported by this 45lines of MSB. Interrupts are not currently supported by this
52driver. 46driver.
53 47
54Configuration Options: not applicable 48Configuration Options: not applicable, uses comedi PCI auto config
55*/ 49*/
56 50
51#include <linux/pci.h>
52
57#include "../comedidev.h" 53#include "../comedidev.h"
58 54
59/* 55/*
@@ -302,11 +298,6 @@ static int adl_pci7x3x_pci_probe(struct pci_dev *dev,
302 return comedi_pci_auto_config(dev, &adl_pci7x3x_driver); 298 return comedi_pci_auto_config(dev, &adl_pci7x3x_driver);
303} 299}
304 300
305static void adl_pci7x3x_pci_remove(struct pci_dev *dev)
306{
307 comedi_pci_auto_unconfig(dev);
308}
309
310static DEFINE_PCI_DEVICE_TABLE(adl_pci7x3x_pci_table) = { 301static DEFINE_PCI_DEVICE_TABLE(adl_pci7x3x_pci_table) = {
311 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7230) }, 302 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7230) },
312 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7233) }, 303 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7233) },
@@ -322,7 +313,7 @@ static struct pci_driver adl_pci7x3x_pci_driver = {
322 .name = "adl_pci7x3x", 313 .name = "adl_pci7x3x",
323 .id_table = adl_pci7x3x_pci_table, 314 .id_table = adl_pci7x3x_pci_table,
324 .probe = adl_pci7x3x_pci_probe, 315 .probe = adl_pci7x3x_pci_probe,
325 .remove = adl_pci7x3x_pci_remove, 316 .remove = comedi_pci_auto_unconfig,
326}; 317};
327module_comedi_pci_driver(adl_pci7x3x_driver, adl_pci7x3x_pci_driver); 318module_comedi_pci_driver(adl_pci7x3x_driver, adl_pci7x3x_pci_driver);
328 319
diff --git a/drivers/staging/comedi/drivers/adl_pci8164.c b/drivers/staging/comedi/drivers/adl_pci8164.c
index 4dd9d707a79d..d06b83f38653 100644
--- a/drivers/staging/comedi/drivers/adl_pci8164.c
+++ b/drivers/staging/comedi/drivers/adl_pci8164.c
@@ -30,9 +30,11 @@ Updated: Mon, 14 Apr 2008 15:10:32 +0100
30Configuration Options: not applicable, uses PCI auto config 30Configuration Options: not applicable, uses PCI auto config
31*/ 31*/
32 32
33#include "../comedidev.h"
34#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/pci.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36
37#include "../comedidev.h"
36#include "comedi_fc.h" 38#include "comedi_fc.h"
37#include "8253.h" 39#include "8253.h"
38 40
@@ -62,35 +64,35 @@ static void adl_pci8164_insn_read(struct comedi_device *dev,
62 char *action, unsigned short offset) 64 char *action, unsigned short offset)
63{ 65{
64 int axis, axis_reg; 66 int axis, axis_reg;
65 char *axisname; 67 char axisname;
66 68
67 axis = CR_CHAN(insn->chanspec); 69 axis = CR_CHAN(insn->chanspec);
68 70
69 switch (axis) { 71 switch (axis) {
70 case 0: 72 case 0:
71 axis_reg = PCI8164_AXIS_X; 73 axis_reg = PCI8164_AXIS_X;
72 axisname = "X"; 74 axisname = 'X';
73 break; 75 break;
74 case 1: 76 case 1:
75 axis_reg = PCI8164_AXIS_Y; 77 axis_reg = PCI8164_AXIS_Y;
76 axisname = "Y"; 78 axisname = 'Y';
77 break; 79 break;
78 case 2: 80 case 2:
79 axis_reg = PCI8164_AXIS_Z; 81 axis_reg = PCI8164_AXIS_Z;
80 axisname = "Z"; 82 axisname = 'Z';
81 break; 83 break;
82 case 3: 84 case 3:
83 axis_reg = PCI8164_AXIS_U; 85 axis_reg = PCI8164_AXIS_U;
84 axisname = "U"; 86 axisname = 'U';
85 break; 87 break;
86 default: 88 default:
87 axis_reg = PCI8164_AXIS_X; 89 axis_reg = PCI8164_AXIS_X;
88 axisname = "X"; 90 axisname = 'X';
89 } 91 }
90 92
91 data[0] = inw(dev->iobase + axis_reg + offset); 93 data[0] = inw(dev->iobase + axis_reg + offset);
92 dev_dbg(dev->class_dev, 94 dev_dbg(dev->class_dev,
93 "pci8164 %s read -> %04X:%04X on axis %s\n", 95 "pci8164 %s read -> %04X:%04X on axis %c\n",
94 action, data[0], data[1], axisname); 96 action, data[0], data[1], axisname);
95} 97}
96 98
@@ -142,36 +144,36 @@ static void adl_pci8164_insn_out(struct comedi_device *dev,
142{ 144{
143 unsigned int axis, axis_reg; 145 unsigned int axis, axis_reg;
144 146
145 char *axisname; 147 char axisname;
146 148
147 axis = CR_CHAN(insn->chanspec); 149 axis = CR_CHAN(insn->chanspec);
148 150
149 switch (axis) { 151 switch (axis) {
150 case 0: 152 case 0:
151 axis_reg = PCI8164_AXIS_X; 153 axis_reg = PCI8164_AXIS_X;
152 axisname = "X"; 154 axisname = 'X';
153 break; 155 break;
154 case 1: 156 case 1:
155 axis_reg = PCI8164_AXIS_Y; 157 axis_reg = PCI8164_AXIS_Y;
156 axisname = "Y"; 158 axisname = 'Y';
157 break; 159 break;
158 case 2: 160 case 2:
159 axis_reg = PCI8164_AXIS_Z; 161 axis_reg = PCI8164_AXIS_Z;
160 axisname = "Z"; 162 axisname = 'Z';
161 break; 163 break;
162 case 3: 164 case 3:
163 axis_reg = PCI8164_AXIS_U; 165 axis_reg = PCI8164_AXIS_U;
164 axisname = "U"; 166 axisname = 'U';
165 break; 167 break;
166 default: 168 default:
167 axis_reg = PCI8164_AXIS_X; 169 axis_reg = PCI8164_AXIS_X;
168 axisname = "X"; 170 axisname = 'X';
169 } 171 }
170 172
171 outw(data[0], dev->iobase + axis_reg + offset); 173 outw(data[0], dev->iobase + axis_reg + offset);
172 174
173 dev_dbg(dev->class_dev, 175 dev_dbg(dev->class_dev,
174 "pci8164 %s write -> %04X:%04X on axis %s\n", 176 "pci8164 %s write -> %04X:%04X on axis %c\n",
175 action, data[0], data[1], axisname); 177 action, data[0], data[1], axisname);
176 178
177} 179}
@@ -298,11 +300,6 @@ static int adl_pci8164_pci_probe(struct pci_dev *dev,
298 return comedi_pci_auto_config(dev, &adl_pci8164_driver); 300 return comedi_pci_auto_config(dev, &adl_pci8164_driver);
299} 301}
300 302
301static void adl_pci8164_pci_remove(struct pci_dev *dev)
302{
303 comedi_pci_auto_unconfig(dev);
304}
305
306static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = { 303static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = {
307 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164) }, 304 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164) },
308 {0} 305 {0}
@@ -313,7 +310,7 @@ static struct pci_driver adl_pci8164_pci_driver = {
313 .name = "adl_pci8164", 310 .name = "adl_pci8164",
314 .id_table = adl_pci8164_pci_table, 311 .id_table = adl_pci8164_pci_table,
315 .probe = adl_pci8164_pci_probe, 312 .probe = adl_pci8164_pci_probe,
316 .remove = adl_pci8164_pci_remove, 313 .remove = comedi_pci_auto_unconfig,
317}; 314};
318module_comedi_pci_driver(adl_pci8164_driver, adl_pci8164_pci_driver); 315module_comedi_pci_driver(adl_pci8164_driver, adl_pci8164_pci_driver);
319 316
diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c
index a339b9dd27cf..eeb10ec7f178 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -68,11 +68,12 @@ TODO:
68 68
69*/ 69*/
70 70
71#include "../comedidev.h" 71#include <linux/pci.h>
72
73#include <linux/delay.h> 72#include <linux/delay.h>
74#include <linux/interrupt.h> 73#include <linux/interrupt.h>
75 74
75#include "../comedidev.h"
76
76#include "8253.h" 77#include "8253.h"
77#include "comedi_fc.h" 78#include "comedi_fc.h"
78 79
@@ -963,11 +964,6 @@ static int pci9111_pci_probe(struct pci_dev *dev,
963 return comedi_pci_auto_config(dev, &adl_pci9111_driver); 964 return comedi_pci_auto_config(dev, &adl_pci9111_driver);
964} 965}
965 966
966static void pci9111_pci_remove(struct pci_dev *dev)
967{
968 comedi_pci_auto_unconfig(dev);
969}
970
971static DEFINE_PCI_DEVICE_TABLE(pci9111_pci_table) = { 967static DEFINE_PCI_DEVICE_TABLE(pci9111_pci_table) = {
972 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HR_DEVICE_ID) }, 968 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HR_DEVICE_ID) },
973 /* { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HG_DEVICE_ID) }, */ 969 /* { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI9111_HG_DEVICE_ID) }, */
@@ -979,7 +975,7 @@ static struct pci_driver adl_pci9111_pci_driver = {
979 .name = "adl_pci9111", 975 .name = "adl_pci9111",
980 .id_table = pci9111_pci_table, 976 .id_table = pci9111_pci_table,
981 .probe = pci9111_pci_probe, 977 .probe = pci9111_pci_probe,
982 .remove = pci9111_pci_remove, 978 .remove = comedi_pci_auto_unconfig,
983}; 979};
984module_comedi_pci_driver(adl_pci9111_driver, adl_pci9111_pci_driver); 980module_comedi_pci_driver(adl_pci9111_driver, adl_pci9111_pci_driver);
985 981
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index b6dda809bd13..4dbac7459a48 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -76,13 +76,15 @@ Configuration options:
76 * attachment if necessary, and possibly to set other options supported by 76 * attachment if necessary, and possibly to set other options supported by
77 * manual attachment. 77 * manual attachment.
78 */ 78 */
79#include "../comedidev.h"
80 79
80#include <linux/pci.h>
81#include <linux/delay.h> 81#include <linux/delay.h>
82#include <linux/gfp.h> 82#include <linux/gfp.h>
83#include <linux/interrupt.h> 83#include <linux/interrupt.h>
84#include <linux/io.h> 84#include <linux/io.h>
85 85
86#include "../comedidev.h"
87
86#include "amcc_s5933.h" 88#include "amcc_s5933.h"
87#include "8253.h" 89#include "8253.h"
88#include "comedi_fc.h" 90#include "comedi_fc.h"
@@ -808,7 +810,7 @@ static void pci9118_calc_divisors(char mode, struct comedi_device *dev,
808 *tim2 = *div1 * devpriv->i8254_osc_base; 810 *tim2 = *div1 * devpriv->i8254_osc_base;
809 /* real convert timer */ 811 /* real convert timer */
810 812
811 if (usessh & (chnsshfront == 0)) /* use BSSH signal */ 813 if (usessh && (chnsshfront == 0)) /* use BSSH signal */
812 if (*div2 < (chans + 2)) 814 if (*div2 < (chans + 2))
813 *div2 = chans + 2; 815 *div2 = chans + 2;
814 816
@@ -2225,11 +2227,6 @@ static int adl_pci9118_pci_probe(struct pci_dev *dev,
2225 return comedi_pci_auto_config(dev, &adl_pci9118_driver); 2227 return comedi_pci_auto_config(dev, &adl_pci9118_driver);
2226} 2228}
2227 2229
2228static void adl_pci9118_pci_remove(struct pci_dev *dev)
2229{
2230 comedi_pci_auto_unconfig(dev);
2231}
2232
2233static DEFINE_PCI_DEVICE_TABLE(adl_pci9118_pci_table) = { 2230static DEFINE_PCI_DEVICE_TABLE(adl_pci9118_pci_table) = {
2234 { PCI_DEVICE(PCI_VENDOR_ID_AMCC, 0x80d9) }, 2231 { PCI_DEVICE(PCI_VENDOR_ID_AMCC, 0x80d9) },
2235 { 0 } 2232 { 0 }
@@ -2240,7 +2237,7 @@ static struct pci_driver adl_pci9118_pci_driver = {
2240 .name = "adl_pci9118", 2237 .name = "adl_pci9118",
2241 .id_table = adl_pci9118_pci_table, 2238 .id_table = adl_pci9118_pci_table,
2242 .probe = adl_pci9118_pci_probe, 2239 .probe = adl_pci9118_pci_probe,
2243 .remove = adl_pci9118_pci_remove, 2240 .remove = comedi_pci_auto_unconfig,
2244}; 2241};
2245module_comedi_pci_driver(adl_pci9118_driver, adl_pci9118_pci_driver); 2242module_comedi_pci_driver(adl_pci9118_driver, adl_pci9118_pci_driver);
2246 2243
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index a6fd8c2c16ca..3d788c76d648 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -41,6 +41,7 @@ Configuration options:
41 device will be used. 41 device will be used.
42*/ 42*/
43 43
44#include <linux/pci.h>
44#include <linux/interrupt.h> 45#include <linux/interrupt.h>
45 46
46#include "../comedidev.h" 47#include "../comedidev.h"
@@ -1402,11 +1403,6 @@ static int adv_pci1710_pci_probe(struct pci_dev *dev,
1402 return comedi_pci_auto_config(dev, &adv_pci1710_driver); 1403 return comedi_pci_auto_config(dev, &adv_pci1710_driver);
1403} 1404}
1404 1405
1405static void adv_pci1710_pci_remove(struct pci_dev *dev)
1406{
1407 comedi_pci_auto_unconfig(dev);
1408}
1409
1410static DEFINE_PCI_DEVICE_TABLE(adv_pci1710_pci_table) = { 1406static DEFINE_PCI_DEVICE_TABLE(adv_pci1710_pci_table) = {
1411 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1710) }, 1407 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1710) },
1412 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1711) }, 1408 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1711) },
@@ -1421,7 +1417,7 @@ static struct pci_driver adv_pci1710_pci_driver = {
1421 .name = "adv_pci1710", 1417 .name = "adv_pci1710",
1422 .id_table = adv_pci1710_pci_table, 1418 .id_table = adv_pci1710_pci_table,
1423 .probe = adv_pci1710_pci_probe, 1419 .probe = adv_pci1710_pci_probe,
1424 .remove = adv_pci1710_pci_remove, 1420 .remove = comedi_pci_auto_unconfig,
1425}; 1421};
1426module_comedi_pci_driver(adv_pci1710_driver, adv_pci1710_pci_driver); 1422module_comedi_pci_driver(adv_pci1710_driver, adv_pci1710_pci_driver);
1427 1423
diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c
index 5af73146dd85..02ce55a01d2a 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -48,6 +48,8 @@ TODO:
483. Implement calibration. 483. Implement calibration.
49*/ 49*/
50 50
51#include <linux/pci.h>
52
51#include "../comedidev.h" 53#include "../comedidev.h"
52 54
53/* all the registers for the pci1723 board */ 55/* all the registers for the pci1723 board */
@@ -327,11 +329,6 @@ static int adv_pci1723_pci_probe(struct pci_dev *dev,
327 return comedi_pci_auto_config(dev, &adv_pci1723_driver); 329 return comedi_pci_auto_config(dev, &adv_pci1723_driver);
328} 330}
329 331
330static void adv_pci1723_pci_remove(struct pci_dev *dev)
331{
332 comedi_pci_auto_unconfig(dev);
333}
334
335static DEFINE_PCI_DEVICE_TABLE(adv_pci1723_pci_table) = { 332static DEFINE_PCI_DEVICE_TABLE(adv_pci1723_pci_table) = {
336 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1723) }, 333 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1723) },
337 { 0 } 334 { 0 }
@@ -342,7 +339,7 @@ static struct pci_driver adv_pci1723_pci_driver = {
342 .name = "adv_pci1723", 339 .name = "adv_pci1723",
343 .id_table = adv_pci1723_pci_table, 340 .id_table = adv_pci1723_pci_table,
344 .probe = adv_pci1723_pci_probe, 341 .probe = adv_pci1723_pci_probe,
345 .remove = adv_pci1723_pci_remove, 342 .remove = comedi_pci_auto_unconfig,
346}; 343};
347module_comedi_pci_driver(adv_pci1723_driver, adv_pci1723_pci_driver); 344module_comedi_pci_driver(adv_pci1723_driver, adv_pci1723_pci_driver);
348 345
diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c
index 05a663e970c6..338c43e716ba 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -29,10 +29,11 @@ Configuration options:
29 29
30*/ 30*/
31 31
32#include "../comedidev.h" 32#include <linux/pci.h>
33
34#include <linux/delay.h> 33#include <linux/delay.h>
35 34
35#include "../comedidev.h"
36
36#include "8255.h" 37#include "8255.h"
37#include "8253.h" 38#include "8253.h"
38 39
@@ -1206,11 +1207,6 @@ static int adv_pci_dio_pci_probe(struct pci_dev *dev,
1206 return comedi_pci_auto_config(dev, &adv_pci_dio_driver); 1207 return comedi_pci_auto_config(dev, &adv_pci_dio_driver);
1207} 1208}
1208 1209
1209static void adv_pci_dio_pci_remove(struct pci_dev *dev)
1210{
1211 comedi_pci_auto_unconfig(dev);
1212}
1213
1214static DEFINE_PCI_DEVICE_TABLE(adv_pci_dio_pci_table) = { 1210static DEFINE_PCI_DEVICE_TABLE(adv_pci_dio_pci_table) = {
1215 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) }, 1211 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1730) },
1216 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) }, 1212 { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1733) },
@@ -1234,7 +1230,7 @@ static struct pci_driver adv_pci_dio_pci_driver = {
1234 .name = "adv_pci_dio", 1230 .name = "adv_pci_dio",
1235 .id_table = adv_pci_dio_pci_table, 1231 .id_table = adv_pci_dio_pci_table,
1236 .probe = adv_pci_dio_pci_probe, 1232 .probe = adv_pci_dio_pci_probe,
1237 .remove = adv_pci_dio_pci_remove, 1233 .remove = comedi_pci_auto_unconfig,
1238}; 1234};
1239module_comedi_pci_driver(adv_pci_dio_driver, adv_pci_dio_pci_driver); 1235module_comedi_pci_driver(adv_pci_dio_driver, adv_pci_dio_pci_driver);
1240 1236
diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c
index 5f309ba88a1a..7c53dea12c76 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200.c
@@ -258,6 +258,7 @@
258 * order they appear in the channel list. 258 * order they appear in the channel list.
259 */ 259 */
260 260
261#include <linux/pci.h>
261#include <linux/interrupt.h> 262#include <linux/interrupt.h>
262#include <linux/slab.h> 263#include <linux/slab.h>
263 264
@@ -1104,10 +1105,9 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s,
1104 struct dio200_subdev_intr *subpriv; 1105 struct dio200_subdev_intr *subpriv;
1105 1106
1106 subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); 1107 subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
1107 if (!subpriv) { 1108 if (!subpriv)
1108 dev_err(dev->class_dev, "error! out of memory!\n");
1109 return -ENOMEM; 1109 return -ENOMEM;
1110 } 1110
1111 subpriv->ofs = offset; 1111 subpriv->ofs = offset;
1112 subpriv->valid_isns = valid_isns; 1112 subpriv->valid_isns = valid_isns;
1113 spin_lock_init(&subpriv->spinlock); 1113 spin_lock_init(&subpriv->spinlock);
@@ -1443,10 +1443,8 @@ dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s,
1443 unsigned int chan; 1443 unsigned int chan;
1444 1444
1445 subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL); 1445 subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
1446 if (!subpriv) { 1446 if (!subpriv)
1447 dev_err(dev->class_dev, "error! out of memory!\n");
1448 return -ENOMEM; 1447 return -ENOMEM;
1449 }
1450 1448
1451 s->private = subpriv; 1449 s->private = subpriv;
1452 s->type = COMEDI_SUBD_COUNTER; 1450 s->type = COMEDI_SUBD_COUNTER;
@@ -1977,8 +1975,7 @@ static int dio200_auto_attach(struct comedi_device *dev,
1977 devpriv->io.u.iobase = (unsigned long)base; 1975 devpriv->io.u.iobase = (unsigned long)base;
1978 devpriv->io.regtype = io_regtype; 1976 devpriv->io.regtype = io_regtype;
1979 } 1977 }
1980 switch (thisboard->model) 1978 switch (thisboard->model) {
1981 {
1982 case pcie215_model: 1979 case pcie215_model:
1983 case pcie236_model: 1980 case pcie236_model:
1984 case pcie296_model: 1981 case pcie296_model:
@@ -2079,16 +2076,11 @@ static int amplc_dio200_pci_probe(struct pci_dev *dev,
2079 return comedi_pci_auto_config(dev, &amplc_dio200_driver); 2076 return comedi_pci_auto_config(dev, &amplc_dio200_driver);
2080} 2077}
2081 2078
2082static void amplc_dio200_pci_remove(struct pci_dev *dev)
2083{
2084 comedi_pci_auto_unconfig(dev);
2085}
2086
2087static struct pci_driver amplc_dio200_pci_driver = { 2079static struct pci_driver amplc_dio200_pci_driver = {
2088 .name = DIO200_DRIVER_NAME, 2080 .name = DIO200_DRIVER_NAME,
2089 .id_table = dio200_pci_table, 2081 .id_table = dio200_pci_table,
2090 .probe = &amplc_dio200_pci_probe, 2082 .probe = &amplc_dio200_pci_probe,
2091 .remove = &amplc_dio200_pci_remove 2083 .remove = comedi_pci_auto_unconfig,
2092}; 2084};
2093module_comedi_pci_driver(amplc_dio200_driver, amplc_dio200_pci_driver); 2085module_comedi_pci_driver(amplc_dio200_driver, amplc_dio200_pci_driver);
2094#else 2086#else
diff --git a/drivers/staging/comedi/drivers/amplc_pc236.c b/drivers/staging/comedi/drivers/amplc_pc236.c
index 289835419577..479e10fddd22 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236.c
@@ -52,6 +52,7 @@ the IRQ jumper. If no interrupt is connected, then subdevice 1 is
52unused. 52unused.
53*/ 53*/
54 54
55#include <linux/pci.h>
55#include <linux/interrupt.h> 56#include <linux/interrupt.h>
56 57
57#include "../comedidev.h" 58#include "../comedidev.h"
@@ -614,16 +615,11 @@ static int amplc_pc236_pci_probe(struct pci_dev *dev,
614 return comedi_pci_auto_config(dev, &amplc_pc236_driver); 615 return comedi_pci_auto_config(dev, &amplc_pc236_driver);
615} 616}
616 617
617static void amplc_pc236_pci_remove(struct pci_dev *dev)
618{
619 comedi_pci_auto_unconfig(dev);
620}
621
622static struct pci_driver amplc_pc236_pci_driver = { 618static struct pci_driver amplc_pc236_pci_driver = {
623 .name = PC236_DRIVER_NAME, 619 .name = PC236_DRIVER_NAME,
624 .id_table = pc236_pci_table, 620 .id_table = pc236_pci_table,
625 .probe = &amplc_pc236_pci_probe, 621 .probe = &amplc_pc236_pci_probe,
626 .remove = &amplc_pc236_pci_remove 622 .remove = comedi_pci_auto_unconfig,
627}; 623};
628 624
629module_comedi_pci_driver(amplc_pc236_driver, amplc_pc236_pci_driver); 625module_comedi_pci_driver(amplc_pc236_driver, amplc_pc236_pci_driver);
diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c
index dfbff77cd795..11c1f4764eac 100644
--- a/drivers/staging/comedi/drivers/amplc_pc263.c
+++ b/drivers/staging/comedi/drivers/amplc_pc263.c
@@ -44,6 +44,8 @@ connected to a reed-relay. Relay contacts are closed when output is 1.
44The state of the outputs can be read. 44The state of the outputs can be read.
45*/ 45*/
46 46
47#include <linux/pci.h>
48
47#include "../comedidev.h" 49#include "../comedidev.h"
48 50
49#define PC263_DRIVER_NAME "amplc_pc263" 51#define PC263_DRIVER_NAME "amplc_pc263"
@@ -372,16 +374,11 @@ static int amplc_pc263_pci_probe(struct pci_dev *dev,
372 return comedi_pci_auto_config(dev, &amplc_pc263_driver); 374 return comedi_pci_auto_config(dev, &amplc_pc263_driver);
373} 375}
374 376
375static void amplc_pc263_pci_remove(struct pci_dev *dev)
376{
377 comedi_pci_auto_unconfig(dev);
378}
379
380static struct pci_driver amplc_pc263_pci_driver = { 377static struct pci_driver amplc_pc263_pci_driver = {
381 .name = PC263_DRIVER_NAME, 378 .name = PC263_DRIVER_NAME,
382 .id_table = pc263_pci_table, 379 .id_table = pc263_pci_table,
383 .probe = &amplc_pc263_pci_probe, 380 .probe = &amplc_pc263_pci_probe,
384 .remove = &amplc_pc263_pci_remove 381 .remove = comedi_pci_auto_unconfig,
385}; 382};
386module_comedi_pci_driver(amplc_pc263_driver, amplc_pc263_pci_driver); 383module_comedi_pci_driver(amplc_pc263_driver, amplc_pc263_pci_driver);
387#else 384#else
diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index 6e2566a2dd57..c9da4cd74baa 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -103,6 +103,7 @@ Caveats:
103 correctly. 103 correctly.
104*/ 104*/
105 105
106#include <linux/pci.h>
106#include <linux/interrupt.h> 107#include <linux/interrupt.h>
107#include <linux/slab.h> 108#include <linux/slab.h>
108 109
@@ -1512,11 +1513,6 @@ static int amplc_pci224_pci_probe(struct pci_dev *dev,
1512 return comedi_pci_auto_config(dev, &amplc_pci224_driver); 1513 return comedi_pci_auto_config(dev, &amplc_pci224_driver);
1513} 1514}
1514 1515
1515static void amplc_pci224_pci_remove(struct pci_dev *dev)
1516{
1517 comedi_pci_auto_unconfig(dev);
1518}
1519
1520static DEFINE_PCI_DEVICE_TABLE(amplc_pci224_pci_table) = { 1516static DEFINE_PCI_DEVICE_TABLE(amplc_pci224_pci_table) = {
1521 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224) }, 1517 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI224) },
1522 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234) }, 1518 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI234) },
@@ -1528,7 +1524,7 @@ static struct pci_driver amplc_pci224_pci_driver = {
1528 .name = "amplc_pci224", 1524 .name = "amplc_pci224",
1529 .id_table = amplc_pci224_pci_table, 1525 .id_table = amplc_pci224_pci_table,
1530 .probe = amplc_pci224_pci_probe, 1526 .probe = amplc_pci224_pci_probe,
1531 .remove = amplc_pci224_pci_remove, 1527 .remove = comedi_pci_auto_unconfig,
1532}; 1528};
1533module_comedi_pci_driver(amplc_pci224_driver, amplc_pci224_pci_driver); 1529module_comedi_pci_driver(amplc_pci224_driver, amplc_pci224_pci_driver);
1534 1530
diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
index 366c68be56bd..e2244c6e536b 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -188,11 +188,12 @@ Support for PCI230+/260+, more triggered scan functionality, and workarounds
188for (or detection of) various hardware problems added by Ian Abbott. 188for (or detection of) various hardware problems added by Ian Abbott.
189*/ 189*/
190 190
191#include "../comedidev.h" 191#include <linux/pci.h>
192
193#include <linux/delay.h> 192#include <linux/delay.h>
194#include <linux/interrupt.h> 193#include <linux/interrupt.h>
195 194
195#include "../comedidev.h"
196
196#include "comedi_fc.h" 197#include "comedi_fc.h"
197#include "8253.h" 198#include "8253.h"
198#include "8255.h" 199#include "8255.h"
@@ -2863,11 +2864,6 @@ static int amplc_pci230_pci_probe(struct pci_dev *dev,
2863 return comedi_pci_auto_config(dev, &amplc_pci230_driver); 2864 return comedi_pci_auto_config(dev, &amplc_pci230_driver);
2864} 2865}
2865 2866
2866static void amplc_pci230_pci_remove(struct pci_dev *dev)
2867{
2868 comedi_pci_auto_unconfig(dev);
2869}
2870
2871static DEFINE_PCI_DEVICE_TABLE(amplc_pci230_pci_table) = { 2867static DEFINE_PCI_DEVICE_TABLE(amplc_pci230_pci_table) = {
2872 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI230) }, 2868 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI230) },
2873 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI260) }, 2869 { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_PCI260) },
@@ -2879,7 +2875,7 @@ static struct pci_driver amplc_pci230_pci_driver = {
2879 .name = "amplc_pci230", 2875 .name = "amplc_pci230",
2880 .id_table = amplc_pci230_pci_table, 2876 .id_table = amplc_pci230_pci_table,
2881 .probe = amplc_pci230_pci_probe, 2877 .probe = amplc_pci230_pci_probe,
2882 .remove = amplc_pci230_pci_remove 2878 .remove = comedi_pci_auto_unconfig,
2883}; 2879};
2884module_comedi_pci_driver(amplc_pci230_driver, amplc_pci230_pci_driver); 2880module_comedi_pci_driver(amplc_pci230_driver, amplc_pci230_pci_driver);
2885 2881
diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c
index 93731de1f2b1..f874fff44523 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -40,9 +40,10 @@ Status: experimental
40 40
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include "../comedidev.h"
44#include <linux/delay.h> 43#include <linux/delay.h>
45 44
45#include "../comedidev.h"
46
46#include <pcmcia/cistpl.h> 47#include <pcmcia/cistpl.h>
47#include <pcmcia/ds.h> 48#include <pcmcia/ds.h>
48 49
@@ -89,8 +90,6 @@ struct das16cs_private {
89 unsigned short status2; 90 unsigned short status2;
90}; 91};
91 92
92static struct pcmcia_device *cur_dev;
93
94static const struct comedi_lrange das16cs_ai_range = { 93static const struct comedi_lrange das16cs_ai_range = {
95 4, { 94 4, {
96 BIP_RANGE(10), 95 BIP_RANGE(10),
@@ -383,46 +382,45 @@ static int das16cs_dio_insn_config(struct comedi_device *dev,
383 return insn->n; 382 return insn->n;
384} 383}
385 384
386static const struct das16cs_board *das16cs_probe(struct comedi_device *dev, 385static const void *das16cs_find_boardinfo(struct comedi_device *dev,
387 struct pcmcia_device *link) 386 struct pcmcia_device *link)
388{ 387{
388 const struct das16cs_board *board;
389 int i; 389 int i;
390 390
391 for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) { 391 for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
392 if (das16cs_boards[i].device_id == link->card_id) 392 board = &das16cs_boards[i];
393 return das16cs_boards + i; 393 if (board->device_id == link->card_id)
394 return board;
394 } 395 }
395 396
396 dev_dbg(dev->class_dev, "unknown board!\n");
397
398 return NULL; 397 return NULL;
399} 398}
400 399
401static int das16cs_attach(struct comedi_device *dev, 400static int das16cs_auto_attach(struct comedi_device *dev,
402 struct comedi_devconfig *it) 401 unsigned long context)
403{ 402{
404 const struct das16cs_board *thisboard; 403 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
404 const struct das16cs_board *board;
405 struct das16cs_private *devpriv; 405 struct das16cs_private *devpriv;
406 struct pcmcia_device *link;
407 struct comedi_subdevice *s; 406 struct comedi_subdevice *s;
408 int ret; 407 int ret;
409 408
410 link = cur_dev; /* XXX hack */ 409 board = das16cs_find_boardinfo(dev, link);
411 if (!link) 410 if (!board)
412 return -EIO; 411 return -ENODEV;
413 412 dev->board_ptr = board;
414 dev->board_ptr = das16cs_probe(dev, link); 413 dev->board_name = board->name;
415 if (!dev->board_ptr)
416 return -EIO;
417 thisboard = comedi_board(dev);
418
419 dev->board_name = thisboard->name;
420 414
415 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
416 ret = comedi_pcmcia_enable(dev, NULL);
417 if (ret)
418 return ret;
421 dev->iobase = link->resource[0]->start; 419 dev->iobase = link->resource[0]->start;
422 420
423 ret = request_irq(link->irq, das16cs_interrupt, 421 link->priv = dev;
424 IRQF_SHARED, "cb_das16_cs", dev); 422 ret = pcmcia_request_irq(link, das16cs_interrupt);
425 if (ret < 0) 423 if (ret)
426 return ret; 424 return ret;
427 dev->irq = link->irq; 425 dev->irq = link->irq;
428 426
@@ -450,10 +448,10 @@ static int das16cs_attach(struct comedi_device *dev,
450 448
451 s = &dev->subdevices[1]; 449 s = &dev->subdevices[1];
452 /* analog output subdevice */ 450 /* analog output subdevice */
453 if (thisboard->n_ao_chans) { 451 if (board->n_ao_chans) {
454 s->type = COMEDI_SUBD_AO; 452 s->type = COMEDI_SUBD_AO;
455 s->subdev_flags = SDF_WRITABLE; 453 s->subdev_flags = SDF_WRITABLE;
456 s->n_chan = thisboard->n_ao_chans; 454 s->n_chan = board->n_ao_chans;
457 s->maxdata = 0xffff; 455 s->maxdata = 0xffff;
458 s->range_table = &range_bipolar10; 456 s->range_table = &range_bipolar10;
459 s->insn_write = &das16cs_ao_winsn; 457 s->insn_write = &das16cs_ao_winsn;
@@ -479,58 +477,16 @@ static int das16cs_attach(struct comedi_device *dev,
479 return 0; 477 return 0;
480} 478}
481 479
482static void das16cs_detach(struct comedi_device *dev)
483{
484 if (dev->irq)
485 free_irq(dev->irq, dev);
486}
487
488static struct comedi_driver driver_das16cs = { 480static struct comedi_driver driver_das16cs = {
489 .driver_name = "cb_das16_cs", 481 .driver_name = "cb_das16_cs",
490 .module = THIS_MODULE, 482 .module = THIS_MODULE,
491 .attach = das16cs_attach, 483 .auto_attach = das16cs_auto_attach,
492 .detach = das16cs_detach, 484 .detach = comedi_pcmcia_disable,
493}; 485};
494 486
495static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev,
496 void *priv_data)
497{
498 if (p_dev->config_index == 0)
499 return -EINVAL;
500
501 return pcmcia_request_io(p_dev);
502}
503
504static int das16cs_pcmcia_attach(struct pcmcia_device *link) 487static int das16cs_pcmcia_attach(struct pcmcia_device *link)
505{ 488{
506 int ret; 489 return comedi_pcmcia_auto_config(link, &driver_das16cs);
507
508 /* Do we need to allocate an interrupt? */
509 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
510
511 ret = pcmcia_loop_config(link, das16cs_pcmcia_config_loop, NULL);
512 if (ret)
513 goto failed;
514
515 if (!link->irq)
516 goto failed;
517
518 ret = pcmcia_enable_device(link);
519 if (ret)
520 goto failed;
521
522 cur_dev = link;
523 return 0;
524
525failed:
526 pcmcia_disable_device(link);
527 return ret;
528}
529
530static void das16cs_pcmcia_detach(struct pcmcia_device *link)
531{
532 pcmcia_disable_device(link);
533 cur_dev = NULL;
534} 490}
535 491
536static const struct pcmcia_device_id das16cs_id_table[] = { 492static const struct pcmcia_device_id das16cs_id_table[] = {
@@ -543,35 +499,11 @@ MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table);
543static struct pcmcia_driver das16cs_driver = { 499static struct pcmcia_driver das16cs_driver = {
544 .name = "cb_das16_cs", 500 .name = "cb_das16_cs",
545 .owner = THIS_MODULE, 501 .owner = THIS_MODULE,
546 .probe = das16cs_pcmcia_attach,
547 .remove = das16cs_pcmcia_detach,
548 .id_table = das16cs_id_table, 502 .id_table = das16cs_id_table,
503 .probe = das16cs_pcmcia_attach,
504 .remove = comedi_pcmcia_auto_unconfig,
549}; 505};
550 506module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
551static int __init das16cs_init(void)
552{
553 int ret;
554
555 ret = comedi_driver_register(&driver_das16cs);
556 if (ret < 0)
557 return ret;
558
559 ret = pcmcia_register_driver(&das16cs_driver);
560 if (ret < 0) {
561 comedi_driver_unregister(&driver_das16cs);
562 return ret;
563 }
564
565 return 0;
566}
567module_init(das16cs_init);
568
569static void __exit das16cs_exit(void)
570{
571 pcmcia_unregister_driver(&das16cs_driver);
572 comedi_driver_unregister(&driver_das16cs);
573}
574module_exit(das16cs_exit);
575 507
576MODULE_AUTHOR("David A. Schleef <ds@schleef.org>"); 508MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
577MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16"); 509MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16");
diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c
index aed68639cc9a..79c72118a090 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas.c
@@ -67,10 +67,12 @@ TODO:
67analog triggering on 1602 series 67analog triggering on 1602 series
68*/ 68*/
69 69
70#include "../comedidev.h" 70#include <linux/pci.h>
71#include <linux/delay.h> 71#include <linux/delay.h>
72#include <linux/interrupt.h> 72#include <linux/interrupt.h>
73 73
74#include "../comedidev.h"
75
74#include "8253.h" 76#include "8253.h"
75#include "8255.h" 77#include "8255.h"
76#include "amcc_s5933.h" 78#include "amcc_s5933.h"
@@ -1632,11 +1634,6 @@ static int cb_pcidas_pci_probe(struct pci_dev *dev,
1632 return comedi_pci_auto_config(dev, &cb_pcidas_driver); 1634 return comedi_pci_auto_config(dev, &cb_pcidas_driver);
1633} 1635}
1634 1636
1635static void cb_pcidas_pci_remove(struct pci_dev *dev)
1636{
1637 comedi_pci_auto_unconfig(dev);
1638}
1639
1640static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = { 1637static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = {
1641 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) }, 1638 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) },
1642 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) }, 1639 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) },
@@ -1654,7 +1651,7 @@ static struct pci_driver cb_pcidas_pci_driver = {
1654 .name = "cb_pcidas", 1651 .name = "cb_pcidas",
1655 .id_table = cb_pcidas_pci_table, 1652 .id_table = cb_pcidas_pci_table,
1656 .probe = cb_pcidas_pci_probe, 1653 .probe = cb_pcidas_pci_probe,
1657 .remove = cb_pcidas_pci_remove 1654 .remove = comedi_pci_auto_unconfig,
1658}; 1655};
1659module_comedi_pci_driver(cb_pcidas_driver, cb_pcidas_pci_driver); 1656module_comedi_pci_driver(cb_pcidas_driver, cb_pcidas_pci_driver);
1660 1657
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index d72b46cc06bc..9f3112cb7a21 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -87,10 +87,12 @@ TODO:
87 87
88#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 88#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
89 89
90#include "../comedidev.h" 90#include <linux/pci.h>
91#include <linux/delay.h> 91#include <linux/delay.h>
92#include <linux/interrupt.h> 92#include <linux/interrupt.h>
93 93
94#include "../comedidev.h"
95
94#include "8253.h" 96#include "8253.h"
95#include "8255.h" 97#include "8255.h"
96#include "plx9080.h" 98#include "plx9080.h"
@@ -3299,7 +3301,6 @@ static int prep_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd)
3299 num_bytes = load_ao_dma_buffer(dev, cmd); 3301 num_bytes = load_ao_dma_buffer(dev, cmd);
3300 if (num_bytes == 0) 3302 if (num_bytes == 0)
3301 return -1; 3303 return -1;
3302 if (num_bytes >= DMA_BUFFER_SIZE) ;
3303 load_ao_dma(dev, cmd); 3304 load_ao_dma(dev, cmd);
3304 3305
3305 dma_start_sync(dev, 0); 3306 dma_start_sync(dev, 0);
@@ -4220,11 +4221,6 @@ static int cb_pcidas64_pci_probe(struct pci_dev *dev,
4220 return comedi_pci_auto_config(dev, &cb_pcidas64_driver); 4221 return comedi_pci_auto_config(dev, &cb_pcidas64_driver);
4221} 4222}
4222 4223
4223static void cb_pcidas64_pci_remove(struct pci_dev *dev)
4224{
4225 comedi_pci_auto_unconfig(dev);
4226}
4227
4228static DEFINE_PCI_DEVICE_TABLE(cb_pcidas64_pci_table) = { 4224static DEFINE_PCI_DEVICE_TABLE(cb_pcidas64_pci_table) = {
4229 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001d) }, 4225 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001d) },
4230 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001e) }, 4226 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001e) },
@@ -4253,7 +4249,7 @@ static struct pci_driver cb_pcidas64_pci_driver = {
4253 .name = "cb_pcidas64", 4249 .name = "cb_pcidas64",
4254 .id_table = cb_pcidas64_pci_table, 4250 .id_table = cb_pcidas64_pci_table,
4255 .probe = cb_pcidas64_pci_probe, 4251 .probe = cb_pcidas64_pci_probe,
4256 .remove = cb_pcidas64_pci_remove, 4252 .remove = comedi_pci_auto_unconfig,
4257}; 4253};
4258module_comedi_pci_driver(cb_pcidas64_driver, cb_pcidas64_pci_driver); 4254module_comedi_pci_driver(cb_pcidas64_driver, cb_pcidas64_pci_driver);
4259 4255
diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c
index 7c6029a8c3e1..e2cadc728455 100644
--- a/drivers/staging/comedi/drivers/cb_pcidda.c
+++ b/drivers/staging/comedi/drivers/cb_pcidda.c
@@ -41,6 +41,8 @@
41 * Only simple analog output writing is supported. 41 * Only simple analog output writing is supported.
42 */ 42 */
43 43
44#include <linux/pci.h>
45
44#include "../comedidev.h" 46#include "../comedidev.h"
45 47
46#include "comedi_fc.h" 48#include "comedi_fc.h"
@@ -438,11 +440,6 @@ static int cb_pcidda_pci_probe(struct pci_dev *dev,
438 return comedi_pci_auto_config(dev, &cb_pcidda_driver); 440 return comedi_pci_auto_config(dev, &cb_pcidda_driver);
439} 441}
440 442
441static void cb_pcidda_pci_remove(struct pci_dev *dev)
442{
443 comedi_pci_auto_unconfig(dev);
444}
445
446static DEFINE_PCI_DEVICE_TABLE(cb_pcidda_pci_table) = { 443static DEFINE_PCI_DEVICE_TABLE(cb_pcidda_pci_table) = {
447 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA02_12) }, 444 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA02_12) },
448 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA04_12) }, 445 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_DDA04_12) },
@@ -458,7 +455,7 @@ static struct pci_driver cb_pcidda_pci_driver = {
458 .name = "cb_pcidda", 455 .name = "cb_pcidda",
459 .id_table = cb_pcidda_pci_table, 456 .id_table = cb_pcidda_pci_table,
460 .probe = cb_pcidda_pci_probe, 457 .probe = cb_pcidda_pci_probe,
461 .remove = cb_pcidda_pci_remove, 458 .remove = comedi_pci_auto_unconfig,
462}; 459};
463module_comedi_pci_driver(cb_pcidda_driver, cb_pcidda_pci_driver); 460module_comedi_pci_driver(cb_pcidda_driver, cb_pcidda_pci_driver);
464 461
diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c
index b43a5f80ac26..aae063ca85a0 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -40,11 +40,12 @@ No interrupts, multi channel or FIFO AI, although the card looks like it could s
40See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details. 40See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details.
41*/ 41*/
42 42
43#include "../comedidev.h" 43#include <linux/pci.h>
44
45#include <linux/delay.h> 44#include <linux/delay.h>
46#include <linux/interrupt.h> 45#include <linux/interrupt.h>
47 46
47#include "../comedidev.h"
48
48#include "plx9052.h" 49#include "plx9052.h"
49#include "8255.h" 50#include "8255.h"
50 51
@@ -299,11 +300,6 @@ static int cb_pcimdas_pci_probe(struct pci_dev *dev,
299 return comedi_pci_auto_config(dev, &cb_pcimdas_driver); 300 return comedi_pci_auto_config(dev, &cb_pcimdas_driver);
300} 301}
301 302
302static void cb_pcimdas_pci_remove(struct pci_dev *dev)
303{
304 comedi_pci_auto_unconfig(dev);
305}
306
307static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = { 303static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
308 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) }, 304 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) },
309 { 0 } 305 { 0 }
@@ -314,7 +310,7 @@ static struct pci_driver cb_pcimdas_pci_driver = {
314 .name = "cb_pcimdas", 310 .name = "cb_pcimdas",
315 .id_table = cb_pcimdas_pci_table, 311 .id_table = cb_pcimdas_pci_table,
316 .probe = cb_pcimdas_pci_probe, 312 .probe = cb_pcimdas_pci_probe,
317 .remove = cb_pcimdas_pci_remove, 313 .remove = comedi_pci_auto_unconfig,
318}; 314};
319module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver); 315module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver);
320 316
diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c
index 699b84f54cc7..63cfbaf3a3fe 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdda.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdda.c
@@ -79,6 +79,8 @@ Configuration Options: not applicable, uses PCI auto config
79 -Calin Culianu <calin@ajvar.org> 79 -Calin Culianu <calin@ajvar.org>
80 */ 80 */
81 81
82#include <linux/pci.h>
83
82#include "../comedidev.h" 84#include "../comedidev.h"
83 85
84#include "8255.h" 86#include "8255.h"
@@ -222,11 +224,6 @@ static int cb_pcimdda_pci_probe(struct pci_dev *dev,
222 return comedi_pci_auto_config(dev, &cb_pcimdda_driver); 224 return comedi_pci_auto_config(dev, &cb_pcimdda_driver);
223} 225}
224 226
225static void cb_pcimdda_pci_remove(struct pci_dev *dev)
226{
227 comedi_pci_auto_unconfig(dev);
228}
229
230static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = { 227static DEFINE_PCI_DEVICE_TABLE(cb_pcimdda_pci_table) = {
231 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) }, 228 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_ID_PCIM_DDA06_16) },
232 { 0 } 229 { 0 }
@@ -237,7 +234,7 @@ static struct pci_driver cb_pcimdda_driver_pci_driver = {
237 .name = "cb_pcimdda", 234 .name = "cb_pcimdda",
238 .id_table = cb_pcimdda_pci_table, 235 .id_table = cb_pcimdda_pci_table,
239 .probe = cb_pcimdda_pci_probe, 236 .probe = cb_pcimdda_pci_probe,
240 .remove = cb_pcimdda_pci_remove, 237 .remove = comedi_pci_auto_unconfig,
241}; 238};
242module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver); 239module_comedi_pci_driver(cb_pcimdda_driver, cb_pcimdda_driver_pci_driver);
243 240
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c
index 31515999bb97..1bb53816eca3 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -245,10 +245,9 @@ static int doDevConfig(struct comedi_device *dev, struct comedi_devconfig *it)
245 return 0; 245 return 0;
246 } 246 }
247 bdev = kmalloc(sizeof(*bdev), GFP_KERNEL); 247 bdev = kmalloc(sizeof(*bdev), GFP_KERNEL);
248 if (!bdev) { 248 if (!bdev)
249 dev_err(dev->class_dev, "Out of memory\n");
250 return 0; 249 return 0;
251 } 250
252 bdev->dev = d; 251 bdev->dev = d;
253 bdev->minor = minor; 252 bdev->minor = minor;
254 bdev->subdev = sdev; 253 bdev->subdev = sdev;
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index 01de996239f1..270fea5c6b51 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -62,15 +62,14 @@ zero volts).
62/* Data unique to this driver */ 62/* Data unique to this driver */
63struct waveform_private { 63struct waveform_private {
64 struct timer_list timer; 64 struct timer_list timer;
65 struct timeval last; /* time at which last timer interrupt occurred */ 65 struct timeval last; /* time last timer interrupt occurred */
66 unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */ 66 unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */
67 unsigned long usec_period; /* waveform period in microseconds */ 67 unsigned long usec_period; /* waveform period in microseconds */
68 unsigned long usec_current; /* current time (modulo waveform period) */ 68 unsigned long usec_current; /* current time (mod waveform period) */
69 unsigned long usec_remainder; /* usec since last scan; */ 69 unsigned long usec_remainder; /* usec since last scan */
70 unsigned long ai_count; /* number of conversions remaining */ 70 unsigned long ai_count; /* number of conversions remaining */
71 unsigned int scan_period; /* scan period in usec */ 71 unsigned int scan_period; /* scan period in usec */
72 unsigned int convert_period; /* conversion period in usec */ 72 unsigned int convert_period; /* conversion period in usec */
73 unsigned timer_running:1;
74 unsigned int ao_loopbacks[N_CHANS]; 73 unsigned int ao_loopbacks[N_CHANS];
75}; 74};
76 75
@@ -86,8 +85,9 @@ static const struct comedi_lrange waveform_ai_ranges = {
86 } 85 }
87}; 86};
88 87
89static short fake_sawtooth(struct comedi_device *dev, unsigned int range_index, 88static unsigned short fake_sawtooth(struct comedi_device *dev,
90 unsigned long current_time) 89 unsigned int range_index,
90 unsigned long current_time)
91{ 91{
92 struct waveform_private *devpriv = dev->private; 92 struct waveform_private *devpriv = dev->private;
93 struct comedi_subdevice *s = dev->read_subdev; 93 struct comedi_subdevice *s = dev->read_subdev;
@@ -110,9 +110,9 @@ static short fake_sawtooth(struct comedi_device *dev, unsigned int range_index,
110 return offset + value; 110 return offset + value;
111} 111}
112 112
113static short fake_squarewave(struct comedi_device *dev, 113static unsigned short fake_squarewave(struct comedi_device *dev,
114 unsigned int range_index, 114 unsigned int range_index,
115 unsigned long current_time) 115 unsigned long current_time)
116{ 116{
117 struct waveform_private *devpriv = dev->private; 117 struct waveform_private *devpriv = dev->private;
118 struct comedi_subdevice *s = dev->read_subdev; 118 struct comedi_subdevice *s = dev->read_subdev;
@@ -132,15 +132,17 @@ static short fake_squarewave(struct comedi_device *dev,
132 return offset + value; 132 return offset + value;
133} 133}
134 134
135static short fake_flatline(struct comedi_device *dev, unsigned int range_index, 135static unsigned short fake_flatline(struct comedi_device *dev,
136 unsigned long current_time) 136 unsigned int range_index,
137 unsigned long current_time)
137{ 138{
138 return dev->read_subdev->maxdata / 2; 139 return dev->read_subdev->maxdata / 2;
139} 140}
140 141
141/* generates a different waveform depending on what channel is read */ 142/* generates a different waveform depending on what channel is read */
142static short fake_waveform(struct comedi_device *dev, unsigned int channel, 143static unsigned short fake_waveform(struct comedi_device *dev,
143 unsigned int range, unsigned long current_time) 144 unsigned int channel, unsigned int range,
145 unsigned long current_time)
144{ 146{
145 enum { 147 enum {
146 SAWTOOTH_CHAN, 148 SAWTOOTH_CHAN,
@@ -176,6 +178,7 @@ static void waveform_ai_interrupt(unsigned long arg)
176 unsigned long elapsed_time; 178 unsigned long elapsed_time;
177 unsigned int num_scans; 179 unsigned int num_scans;
178 struct timeval now; 180 struct timeval now;
181 bool stopping = false;
179 182
180 do_gettimeofday(&now); 183 do_gettimeofday(&now);
181 184
@@ -189,37 +192,35 @@ static void waveform_ai_interrupt(unsigned long arg)
189 (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period; 192 (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period;
190 async->events = 0; 193 async->events = 0;
191 194
195 if (cmd->stop_src == TRIG_COUNT) {
196 unsigned int remaining = cmd->stop_arg - devpriv->ai_count;
197 if (num_scans >= remaining) {
198 /* about to finish */
199 num_scans = remaining;
200 stopping = true;
201 }
202 }
203
192 for (i = 0; i < num_scans; i++) { 204 for (i = 0; i < num_scans; i++) {
193 for (j = 0; j < cmd->chanlist_len; j++) { 205 for (j = 0; j < cmd->chanlist_len; j++) {
194 cfc_write_to_buffer(dev->read_subdev, 206 unsigned short sample;
195 fake_waveform(dev, 207 sample = fake_waveform(dev, CR_CHAN(cmd->chanlist[j]),
196 CR_CHAN(cmd-> 208 CR_RANGE(cmd->chanlist[j]),
197 chanlist[j]), 209 devpriv->usec_current +
198 CR_RANGE(cmd-> 210 i * devpriv->scan_period +
199 chanlist[j]), 211 j * devpriv->convert_period);
200 devpriv-> 212 cfc_write_to_buffer(dev->read_subdev, sample);
201 usec_current +
202 i *
203 devpriv->scan_period +
204 j *
205 devpriv->
206 convert_period));
207 }
208 devpriv->ai_count++;
209 if (cmd->stop_src == TRIG_COUNT
210 && devpriv->ai_count >= cmd->stop_arg) {
211 async->events |= COMEDI_CB_EOA;
212 break;
213 } 213 }
214 } 214 }
215 215
216 devpriv->ai_count += i;
216 devpriv->usec_current += elapsed_time; 217 devpriv->usec_current += elapsed_time;
217 devpriv->usec_current %= devpriv->usec_period; 218 devpriv->usec_current %= devpriv->usec_period;
218 219
219 if ((async->events & COMEDI_CB_EOA) == 0 && devpriv->timer_running) 220 if (stopping)
220 mod_timer(&devpriv->timer, jiffies + 1); 221 async->events |= COMEDI_CB_EOA;
221 else 222 else
222 del_timer(&devpriv->timer); 223 mod_timer(&devpriv->timer, jiffies + 1);
223 224
224 comedi_event(dev, dev->read_subdev); 225 comedi_event(dev, dev->read_subdev);
225} 226}
@@ -317,7 +318,6 @@ static int waveform_ai_cmd(struct comedi_device *dev,
317 return -1; 318 return -1;
318 } 319 }
319 320
320 devpriv->timer_running = 1;
321 devpriv->ai_count = 0; 321 devpriv->ai_count = 0;
322 devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro; 322 devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro;
323 323
@@ -344,7 +344,6 @@ static int waveform_ai_cancel(struct comedi_device *dev,
344{ 344{
345 struct waveform_private *devpriv = dev->private; 345 struct waveform_private *devpriv = dev->private;
346 346
347 devpriv->timer_running = 0;
348 del_timer_sync(&devpriv->timer); 347 del_timer_sync(&devpriv->timer);
349 return 0; 348 return 0;
350} 349}
diff --git a/drivers/staging/comedi/drivers/contec_pci_dio.c b/drivers/staging/comedi/drivers/contec_pci_dio.c
index 1a18fa37bfd0..182dea669ef2 100644
--- a/drivers/staging/comedi/drivers/contec_pci_dio.c
+++ b/drivers/staging/comedi/drivers/contec_pci_dio.c
@@ -30,6 +30,8 @@ Status: works
30Configuration Options: not applicable, uses comedi PCI auto config 30Configuration Options: not applicable, uses comedi PCI auto config
31*/ 31*/
32 32
33#include <linux/pci.h>
34
33#include "../comedidev.h" 35#include "../comedidev.h"
34 36
35#define PCI_DEVICE_ID_PIO1616L 0x8172 37#define PCI_DEVICE_ID_PIO1616L 0x8172
@@ -130,11 +132,6 @@ static int contec_pci_dio_pci_probe(struct pci_dev *dev,
130 return comedi_pci_auto_config(dev, &contec_pci_dio_driver); 132 return comedi_pci_auto_config(dev, &contec_pci_dio_driver);
131} 133}
132 134
133static void contec_pci_dio_pci_remove(struct pci_dev *dev)
134{
135 comedi_pci_auto_unconfig(dev);
136}
137
138static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = { 135static DEFINE_PCI_DEVICE_TABLE(contec_pci_dio_pci_table) = {
139 { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L) }, 136 { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L) },
140 { 0 } 137 { 0 }
@@ -145,7 +142,7 @@ static struct pci_driver contec_pci_dio_pci_driver = {
145 .name = "contec_pci_dio", 142 .name = "contec_pci_dio",
146 .id_table = contec_pci_dio_pci_table, 143 .id_table = contec_pci_dio_pci_table,
147 .probe = contec_pci_dio_pci_probe, 144 .probe = contec_pci_dio_pci_probe,
148 .remove = contec_pci_dio_pci_remove, 145 .remove = comedi_pci_auto_unconfig,
149}; 146};
150module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver); 147module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver);
151 148
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index 992e557e6ae1..50b450f09c65 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -107,12 +107,13 @@ Configuration options: not applicable, uses PCI auto config
107 107
108 */ 108 */
109 109
110#include "../comedidev.h" 110#include <linux/pci.h>
111
112#include <linux/delay.h> 111#include <linux/delay.h>
113#include <linux/interrupt.h> 112#include <linux/interrupt.h>
114#include <linux/firmware.h> 113#include <linux/firmware.h>
115 114
115#include "../comedidev.h"
116
116#include "8255.h" 117#include "8255.h"
117 118
118#define DAQBOARD2000_FIRMWARE "daqboard2000_firmware.bin" 119#define DAQBOARD2000_FIRMWARE "daqboard2000_firmware.bin"
@@ -485,7 +486,7 @@ static void daqboard2000_pulseProgPin(struct comedi_device *dev)
485 writel(DAQBOARD2000_SECRProgPinHi, devpriv->plx + 0x6c); 486 writel(DAQBOARD2000_SECRProgPinHi, devpriv->plx + 0x6c);
486 udelay(10000); 487 udelay(10000);
487 writel(DAQBOARD2000_SECRProgPinLo, devpriv->plx + 0x6c); 488 writel(DAQBOARD2000_SECRProgPinLo, devpriv->plx + 0x6c);
488 udelay(10000); /* Not in the original code, but I like symmetry... */ 489 udelay(10000); /* Not in the original code, but I like symmetry... */
489} 490}
490 491
491static int daqboard2000_pollCPLD(struct comedi_device *dev, int mask) 492static int daqboard2000_pollCPLD(struct comedi_device *dev, int mask)
@@ -799,11 +800,6 @@ static int daqboard2000_pci_probe(struct pci_dev *dev,
799 return comedi_pci_auto_config(dev, &daqboard2000_driver); 800 return comedi_pci_auto_config(dev, &daqboard2000_driver);
800} 801}
801 802
802static void daqboard2000_pci_remove(struct pci_dev *dev)
803{
804 comedi_pci_auto_unconfig(dev);
805}
806
807static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = { 803static DEFINE_PCI_DEVICE_TABLE(daqboard2000_pci_table) = {
808 { PCI_DEVICE(PCI_VENDOR_ID_IOTECH, 0x0409) }, 804 { PCI_DEVICE(PCI_VENDOR_ID_IOTECH, 0x0409) },
809 { 0 } 805 { 0 }
@@ -814,7 +810,7 @@ static struct pci_driver daqboard2000_pci_driver = {
814 .name = "daqboard2000", 810 .name = "daqboard2000",
815 .id_table = daqboard2000_pci_table, 811 .id_table = daqboard2000_pci_table,
816 .probe = daqboard2000_pci_probe, 812 .probe = daqboard2000_pci_probe,
817 .remove = daqboard2000_pci_remove, 813 .remove = comedi_pci_auto_unconfig,
818}; 814};
819module_comedi_pci_driver(daqboard2000_driver, daqboard2000_pci_driver); 815module_comedi_pci_driver(daqboard2000_driver, daqboard2000_pci_driver);
820 816
diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c
index b15e05808cb0..9823aa06787a 100644
--- a/drivers/staging/comedi/drivers/das08.c
+++ b/drivers/staging/comedi/drivers/das08.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * comedi/drivers/das08.c 2 * comedi/drivers/das08.c
3 * DAS08 driver 3 * comedi driver for common DAS08 support (used by ISA/PCI/PCMCIA drivers)
4 * 4 *
5 * COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
@@ -27,57 +27,26 @@
27/* 27/*
28 * Driver: das08 28 * Driver: das08
29 * Description: DAS-08 compatible boards 29 * Description: DAS-08 compatible boards
30 * Devices: various, see das08_isa, das08_cs, and das08_pci drivers
30 * Author: Warren Jasper, ds, Frank Hess 31 * Author: Warren Jasper, ds, Frank Hess
31 * Devices: [Keithley Metrabyte] DAS08 (isa-das08),
32 * [ComputerBoards] DAS08 (isa-das08), DAS08-PGM (das08-pgm),
33 * DAS08-PGH (das08-pgh), DAS08-PGL (das08-pgl), DAS08-AOH (das08-aoh),
34 * DAS08-AOL (das08-aol), DAS08-AOM (das08-aom), DAS08/JR-AO (das08/jr-ao),
35 * DAS08/JR-16-AO (das08jr-16-ao), PCI-DAS08 (pci-das08),
36 * PC104-DAS08 (pc104-das08), DAS08/JR/16 (das08jr/16)
37 * Updated: Fri, 31 Aug 2012 19:19:06 +0100 32 * Updated: Fri, 31 Aug 2012 19:19:06 +0100
38 * Status: works 33 * Status: works
39 * 34 *
40 * This is a rewrite of the das08 and das08jr drivers. 35 * This driver is used by the das08_isa, das08_cs, and das08_pci
36 * drivers to provide the common support for the DAS-08 hardware.
41 * 37 *
42 * Options (for ISA cards): 38 * The driver doesn't support asynchronous commands, since the
43 * [0] - base io address 39 * cheap das08 hardware doesn't really support them.
44 *
45 * Manual configuration of PCI cards is not supported; they are
46 * configured automatically.
47 *
48 * The das08 driver doesn't support asynchronous commands, since
49 * the cheap das08 hardware doesn't really support them. The
50 * comedi_rt_timer driver can be used to emulate commands for this
51 * driver.
52 */ 40 */
53 41
54#include "../comedidev.h"
55
56#include <linux/delay.h> 42#include <linux/delay.h>
57 43
44#include "../comedidev.h"
45
58#include "8255.h" 46#include "8255.h"
59#include "8253.h" 47#include "8253.h"
60#include "das08.h" 48#include "das08.h"
61 49
62#define DRV_NAME "das08"
63
64#define DO_ISA IS_ENABLED(CONFIG_COMEDI_DAS08_ISA)
65#define DO_PCI IS_ENABLED(CONFIG_COMEDI_DAS08_PCI)
66#define DO_COMEDI_DRIVER_REGISTER (DO_ISA || DO_PCI)
67
68#define PCI_DEVICE_ID_PCIDAS08 0x29
69#define PCIDAS08_SIZE 0x54
70
71/* pci configuration registers */
72#define INTCSR 0x4c
73#define INTR1_ENABLE 0x1
74#define INTR1_HIGH_POLARITY 0x2
75#define PCI_INTR_ENABLE 0x40
76#define INTR1_EDGE_TRIG 0x100 /* requires high polarity */
77#define CNTRL 0x50
78#define CNTRL_DIR 0x2
79#define CNTRL_INTR 0x4
80
81/* 50/*
82 cio-das08.pdf 51 cio-das08.pdf
83 52
@@ -235,16 +204,6 @@ static const int *const das08_gainlists[] = {
235 das08_pgm_gainlist, 204 das08_pgm_gainlist,
236}; 205};
237 206
238static inline bool is_isa_board(const struct das08_board_struct *board)
239{
240 return DO_ISA && board->bustype == isa;
241}
242
243static inline bool is_pci_board(const struct das08_board_struct *board)
244{
245 return DO_PCI && board->bustype == pci;
246}
247
248#define TIMEOUT 100000 207#define TIMEOUT 100000
249 208
250static int das08_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, 209static int das08_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -501,159 +460,6 @@ static int das08_counter_config(struct comedi_device *dev,
501 return 2; 460 return 2;
502} 461}
503 462
504#if DO_COMEDI_DRIVER_REGISTER
505static const struct das08_board_struct das08_boards[] = {
506#if DO_ISA
507 {
508 .name = "isa-das08", /* cio-das08.pdf */
509 .bustype = isa,
510 .ai_nbits = 12,
511 .ai_pg = das08_pg_none,
512 .ai_encoding = das08_encode12,
513 .di_nchan = 3,
514 .do_nchan = 4,
515 .i8255_offset = 8,
516 .i8254_offset = 4,
517 .iosize = 16, /* unchecked */
518 },
519 {
520 .name = "das08-pgm", /* cio-das08pgx.pdf */
521 .bustype = isa,
522 .ai_nbits = 12,
523 .ai_pg = das08_pgm,
524 .ai_encoding = das08_encode12,
525 .di_nchan = 3,
526 .do_nchan = 4,
527 .i8255_offset = 0,
528 .i8254_offset = 0x04,
529 .iosize = 16, /* unchecked */
530 },
531 {
532 .name = "das08-pgh", /* cio-das08pgx.pdf */
533 .bustype = isa,
534 .ai_nbits = 12,
535 .ai_pg = das08_pgh,
536 .ai_encoding = das08_encode12,
537 .di_nchan = 3,
538 .do_nchan = 4,
539 .i8254_offset = 0x04,
540 .iosize = 16, /* unchecked */
541 },
542 {
543 .name = "das08-pgl", /* cio-das08pgx.pdf */
544 .bustype = isa,
545 .ai_nbits = 12,
546 .ai_pg = das08_pgl,
547 .ai_encoding = das08_encode12,
548 .di_nchan = 3,
549 .do_nchan = 4,
550 .i8254_offset = 0x04,
551 .iosize = 16, /* unchecked */
552 },
553 {
554 .name = "das08-aoh", /* cio-das08_aox.pdf */
555 .bustype = isa,
556 .ai_nbits = 12,
557 .ai_pg = das08_pgh,
558 .ai_encoding = das08_encode12,
559 .ao_nbits = 12,
560 .di_nchan = 3,
561 .do_nchan = 4,
562 .i8255_offset = 0x0c,
563 .i8254_offset = 0x04,
564 .iosize = 16, /* unchecked */
565 },
566 {
567 .name = "das08-aol", /* cio-das08_aox.pdf */
568 .bustype = isa,
569 .ai_nbits = 12,
570 .ai_pg = das08_pgl,
571 .ai_encoding = das08_encode12,
572 .ao_nbits = 12,
573 .di_nchan = 3,
574 .do_nchan = 4,
575 .i8255_offset = 0x0c,
576 .i8254_offset = 0x04,
577 .iosize = 16, /* unchecked */
578 },
579 {
580 .name = "das08-aom", /* cio-das08_aox.pdf */
581 .bustype = isa,
582 .ai_nbits = 12,
583 .ai_pg = das08_pgm,
584 .ai_encoding = das08_encode12,
585 .ao_nbits = 12,
586 .di_nchan = 3,
587 .do_nchan = 4,
588 .i8255_offset = 0x0c,
589 .i8254_offset = 0x04,
590 .iosize = 16, /* unchecked */
591 },
592 {
593 .name = "das08/jr-ao", /* cio-das08-jr-ao.pdf */
594 .bustype = isa,
595 .is_jr = true,
596 .ai_nbits = 12,
597 .ai_pg = das08_pg_none,
598 .ai_encoding = das08_encode12,
599 .ao_nbits = 12,
600 .di_nchan = 8,
601 .do_nchan = 8,
602 .iosize = 16, /* unchecked */
603 },
604 {
605 .name = "das08jr-16-ao", /* cio-das08jr-16-ao.pdf */
606 .bustype = isa,
607 .is_jr = true,
608 .ai_nbits = 16,
609 .ai_pg = das08_pg_none,
610 .ai_encoding = das08_encode16,
611 .ao_nbits = 16,
612 .di_nchan = 8,
613 .do_nchan = 8,
614 .i8254_offset = 0x04,
615 .iosize = 16, /* unchecked */
616 },
617 {
618 .name = "pc104-das08",
619 .bustype = isa,
620 .ai_nbits = 12,
621 .ai_pg = das08_pg_none,
622 .ai_encoding = das08_encode12,
623 .di_nchan = 3,
624 .do_nchan = 4,
625 .i8254_offset = 4,
626 .iosize = 16, /* unchecked */
627 },
628 {
629 .name = "das08jr/16",
630 .bustype = isa,
631 .is_jr = true,
632 .ai_nbits = 16,
633 .ai_pg = das08_pg_none,
634 .ai_encoding = das08_encode16,
635 .di_nchan = 8,
636 .do_nchan = 8,
637 .iosize = 16, /* unchecked */
638 },
639#endif /* DO_ISA */
640#if DO_PCI
641 {
642 .name = "pci-das08", /* pci-das08 */
643 .id = PCI_DEVICE_ID_PCIDAS08,
644 .bustype = pci,
645 .ai_nbits = 12,
646 .ai_pg = das08_bipolar5,
647 .ai_encoding = das08_encode12,
648 .di_nchan = 3,
649 .do_nchan = 4,
650 .i8254_offset = 4,
651 .iosize = 8,
652 },
653#endif /* DO_PCI */
654};
655#endif /* DO_COMEDI_DRIVER_REGISTER */
656
657int das08_common_attach(struct comedi_device *dev, unsigned long iobase) 463int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
658{ 464{
659 const struct das08_board_struct *thisboard = comedi_board(dev); 465 const struct das08_board_struct *thisboard = comedi_board(dev);
@@ -760,84 +566,6 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
760} 566}
761EXPORT_SYMBOL_GPL(das08_common_attach); 567EXPORT_SYMBOL_GPL(das08_common_attach);
762 568
763static const struct das08_board_struct *
764das08_find_pci_board(struct pci_dev *pdev)
765{
766#if DO_COMEDI_DRIVER_REGISTER
767 unsigned int i;
768 for (i = 0; i < ARRAY_SIZE(das08_boards); i++)
769 if (is_pci_board(&das08_boards[i]) &&
770 pdev->device == das08_boards[i].id)
771 return &das08_boards[i];
772#endif
773 return NULL;
774}
775
776/* only called in the PCI probe path, via comedi_pci_auto_config() */
777static int __maybe_unused
778das08_auto_attach(struct comedi_device *dev, unsigned long context_unused)
779{
780 struct pci_dev *pdev;
781 struct das08_private_struct *devpriv;
782 unsigned long iobase;
783
784 if (!DO_PCI)
785 return -EINVAL;
786
787 pdev = comedi_to_pci_dev(dev);
788 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
789 if (!devpriv)
790 return -ENOMEM;
791 dev->private = devpriv;
792
793 dev_info(dev->class_dev, "attach pci %s\n", pci_name(pdev));
794 dev->board_ptr = das08_find_pci_board(pdev);
795 if (dev->board_ptr == NULL) {
796 dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
797 return -EINVAL;
798 }
799
800 /* enable PCI device and reserve I/O spaces */
801 if (comedi_pci_enable(pdev, dev->driver->driver_name)) {
802 dev_err(dev->class_dev,
803 "Error enabling PCI device and requesting regions\n");
804 return -EIO;
805 }
806 /* read base addresses */
807 iobase = pci_resource_start(pdev, 2);
808 return das08_common_attach(dev, iobase);
809}
810
811static int __maybe_unused
812das08_attach(struct comedi_device *dev, struct comedi_devconfig *it)
813{
814 const struct das08_board_struct *thisboard = comedi_board(dev);
815 struct das08_private_struct *devpriv;
816 unsigned long iobase;
817
818 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
819 if (!devpriv)
820 return -ENOMEM;
821 dev->private = devpriv;
822
823 dev_info(dev->class_dev, "attach\n");
824 if (is_pci_board(thisboard)) {
825 dev_err(dev->class_dev,
826 "Manual configuration of PCI board '%s' is not supported\n",
827 thisboard->name);
828 return -EIO;
829 } else if (is_isa_board(thisboard)) {
830 iobase = it->options[0];
831 dev_info(dev->class_dev, "iobase 0x%lx\n", iobase);
832 if (!request_region(iobase, thisboard->iosize, DRV_NAME)) {
833 dev_err(dev->class_dev, "I/O port conflict\n");
834 return -EIO;
835 }
836 return das08_common_attach(dev, iobase);
837 } else
838 return -EIO;
839}
840
841void das08_common_detach(struct comedi_device *dev) 569void das08_common_detach(struct comedi_device *dev)
842{ 570{
843 if (dev->subdevices) 571 if (dev->subdevices)
@@ -845,84 +573,16 @@ void das08_common_detach(struct comedi_device *dev)
845} 573}
846EXPORT_SYMBOL_GPL(das08_common_detach); 574EXPORT_SYMBOL_GPL(das08_common_detach);
847 575
848static void __maybe_unused das08_detach(struct comedi_device *dev)
849{
850 const struct das08_board_struct *thisboard = comedi_board(dev);
851
852 if (!thisboard)
853 return;
854 das08_common_detach(dev);
855 if (is_isa_board(thisboard)) {
856 if (dev->iobase)
857 release_region(dev->iobase, thisboard->iosize);
858 } else if (is_pci_board(thisboard)) {
859 struct pci_dev *pdev = comedi_to_pci_dev(dev);
860 if (pdev) {
861 if (dev->iobase)
862 comedi_pci_disable(pdev);
863 }
864 }
865}
866
867#if DO_COMEDI_DRIVER_REGISTER
868static struct comedi_driver das08_driver = {
869 .driver_name = DRV_NAME,
870 .module = THIS_MODULE,
871 .attach = das08_attach,
872 .auto_attach = das08_auto_attach,
873 .detach = das08_detach,
874 .board_name = &das08_boards[0].name,
875 .num_names = sizeof(das08_boards) / sizeof(struct das08_board_struct),
876 .offset = sizeof(struct das08_board_struct),
877};
878#endif
879
880#if DO_PCI
881static DEFINE_PCI_DEVICE_TABLE(das08_pci_table) = {
882 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_PCIDAS08) },
883 {0}
884};
885
886MODULE_DEVICE_TABLE(pci, das08_pci_table);
887
888static int das08_pci_probe(struct pci_dev *dev,
889 const struct pci_device_id *ent)
890{
891 return comedi_pci_auto_config(dev, &das08_driver);
892}
893
894static void das08_pci_remove(struct pci_dev *dev)
895{
896 comedi_pci_auto_unconfig(dev);
897}
898
899static struct pci_driver das08_pci_driver = {
900 .id_table = das08_pci_table,
901 .name = DRV_NAME,
902 .probe = &das08_pci_probe,
903 .remove = &das08_pci_remove
904};
905#endif /* DO_PCI */
906
907#if DO_COMEDI_DRIVER_REGISTER
908#if DO_PCI
909module_comedi_pci_driver(das08_driver, das08_pci_driver);
910#else
911module_comedi_driver(das08_driver);
912#endif
913#else /* DO_COMEDI_DRIVER_REGISTER */
914static int __init das08_init(void) 576static int __init das08_init(void)
915{ 577{
916 return 0; 578 return 0;
917} 579}
580module_init(das08_init);
918 581
919static void __exit das08_exit(void) 582static void __exit das08_exit(void)
920{ 583{
921} 584}
922
923module_init(das08_init);
924module_exit(das08_exit); 585module_exit(das08_exit);
925#endif /* DO_COMEDI_DRIVER_REGISTER */
926 586
927MODULE_AUTHOR("Comedi http://www.comedi.org"); 587MODULE_AUTHOR("Comedi http://www.comedi.org");
928MODULE_DESCRIPTION("Comedi low-level driver"); 588MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/das08.h b/drivers/staging/comedi/drivers/das08.h
index 0314baebae39..b102ad4918c4 100644
--- a/drivers/staging/comedi/drivers/das08.h
+++ b/drivers/staging/comedi/drivers/das08.h
@@ -24,7 +24,6 @@
24#ifndef _DAS08_H 24#ifndef _DAS08_H
25#define _DAS08_H 25#define _DAS08_H
26 26
27enum das08_bustype { isa, pci, pcmcia };
28/* different ways ai data is encoded in first two registers */ 27/* different ways ai data is encoded in first two registers */
29enum das08_ai_encoding { das08_encode12, das08_encode16, das08_pcm_encode12 }; 28enum das08_ai_encoding { das08_encode12, das08_encode16, das08_pcm_encode12 };
30enum das08_lrange { das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl, 29enum das08_lrange { das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl,
@@ -34,7 +33,6 @@ enum das08_lrange { das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl,
34struct das08_board_struct { 33struct das08_board_struct {
35 const char *name; 34 const char *name;
36 unsigned int id; /* id for pci/pcmcia boards */ 35 unsigned int id; /* id for pci/pcmcia boards */
37 enum das08_bustype bustype;
38 bool is_jr; /* true for 'JR' boards */ 36 bool is_jr; /* true for 'JR' boards */
39 unsigned int ai_nbits; 37 unsigned int ai_nbits;
40 enum das08_lrange ai_pg; 38 enum das08_lrange ai_pg;
diff --git a/drivers/staging/comedi/drivers/das08_cs.c b/drivers/staging/comedi/drivers/das08_cs.c
index 024262375e3c..cfeebe4d1ddd 100644
--- a/drivers/staging/comedi/drivers/das08_cs.c
+++ b/drivers/staging/comedi/drivers/das08_cs.c
@@ -46,125 +46,70 @@ Options (for pcm-das08):
46Command support does not exist, but could be added for this board. 46Command support does not exist, but could be added for this board.
47*/ 47*/
48 48
49#include "../comedidev.h"
50
51#include <linux/delay.h> 49#include <linux/delay.h>
52#include <linux/pci.h>
53#include <linux/slab.h> 50#include <linux/slab.h>
54 51
55#include "das08.h" 52#include "../comedidev.h"
56 53
57/* pcmcia includes */
58#include <pcmcia/cistpl.h> 54#include <pcmcia/cistpl.h>
59#include <pcmcia/ds.h> 55#include <pcmcia/ds.h>
60 56
57#include "das08.h"
58
61static const struct das08_board_struct das08_cs_boards[] = { 59static const struct das08_board_struct das08_cs_boards[] = {
62 { 60 {
63 .name = "pcm-das08", 61 .name = "pcm-das08",
64 .id = 0x0, /* XXX */ 62 .id = 0x0, /* XXX */
65 .bustype = pcmcia, 63 .ai_nbits = 12,
66 .ai_nbits = 12, 64 .ai_pg = das08_bipolar5,
67 .ai_pg = das08_bipolar5, 65 .ai_encoding = das08_pcm_encode12,
68 .ai_encoding = das08_pcm_encode12, 66 .di_nchan = 3,
69 .di_nchan = 3, 67 .do_nchan = 3,
70 .do_nchan = 3, 68 .iosize = 16,
71 .iosize = 16,
72 },
73 /* duplicate so driver name can be used also */
74 {
75 .name = "das08_cs",
76 .id = 0x0, /* XXX */
77 .bustype = pcmcia,
78 .ai_nbits = 12,
79 .ai_pg = das08_bipolar5,
80 .ai_encoding = das08_pcm_encode12,
81 .di_nchan = 3,
82 .do_nchan = 3,
83 .iosize = 16,
84 }, 69 },
85}; 70};
86 71
87static struct pcmcia_device *cur_dev; 72static int das08_cs_auto_attach(struct comedi_device *dev,
88 73 unsigned long context)
89static int das08_cs_attach(struct comedi_device *dev,
90 struct comedi_devconfig *it)
91{ 74{
92 const struct das08_board_struct *thisboard = comedi_board(dev); 75 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
93 struct das08_private_struct *devpriv; 76 struct das08_private_struct *devpriv;
94 unsigned long iobase; 77 unsigned long iobase;
95 struct pcmcia_device *link = cur_dev; /* XXX hack */ 78 int ret;
79
80 /* The das08 driver needs the board_ptr */
81 dev->board_ptr = &das08_cs_boards[0];
82
83 link->config_flags |= CONF_AUTO_SET_IO;
84 ret = comedi_pcmcia_enable(dev, NULL);
85 if (ret)
86 return ret;
87 iobase = link->resource[0]->start;
96 88
97 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); 89 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
98 if (!devpriv) 90 if (!devpriv)
99 return -ENOMEM; 91 return -ENOMEM;
100 dev->private = devpriv; 92 dev->private = devpriv;
101 93
102 dev_info(dev->class_dev, "das08_cs: attach\n");
103 /* deal with a pci board */
104
105 if (thisboard->bustype == pcmcia) {
106 if (link == NULL) {
107 dev_err(dev->class_dev, "no pcmcia cards found\n");
108 return -EIO;
109 }
110 iobase = link->resource[0]->start;
111 } else {
112 dev_err(dev->class_dev,
113 "bug! board does not have PCMCIA bustype\n");
114 return -EINVAL;
115 }
116
117 return das08_common_attach(dev, iobase); 94 return das08_common_attach(dev, iobase);
118} 95}
119 96
97static void das08_cs_detach(struct comedi_device *dev)
98{
99 das08_common_detach(dev);
100 comedi_pcmcia_disable(dev);
101}
102
120static struct comedi_driver driver_das08_cs = { 103static struct comedi_driver driver_das08_cs = {
121 .driver_name = "das08_cs", 104 .driver_name = "das08_cs",
122 .module = THIS_MODULE, 105 .module = THIS_MODULE,
123 .attach = das08_cs_attach, 106 .auto_attach = das08_cs_auto_attach,
124 .detach = das08_common_detach, 107 .detach = das08_cs_detach,
125 .board_name = &das08_cs_boards[0].name,
126 .num_names = ARRAY_SIZE(das08_cs_boards),
127 .offset = sizeof(struct das08_board_struct),
128}; 108};
129 109
130static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev,
131 void *priv_data)
132{
133 if (p_dev->config_index == 0)
134 return -EINVAL;
135
136 return pcmcia_request_io(p_dev);
137}
138
139static int das08_pcmcia_attach(struct pcmcia_device *link) 110static int das08_pcmcia_attach(struct pcmcia_device *link)
140{ 111{
141 int ret; 112 return comedi_pcmcia_auto_config(link, &driver_das08_cs);
142
143 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
144
145 ret = pcmcia_loop_config(link, das08_pcmcia_config_loop, NULL);
146 if (ret)
147 goto failed;
148
149 if (!link->irq)
150 goto failed;
151
152 ret = pcmcia_enable_device(link);
153 if (ret)
154 goto failed;
155
156 cur_dev = link;
157 return 0;
158
159failed:
160 pcmcia_disable_device(link);
161 return ret;
162}
163
164static void das08_pcmcia_detach(struct pcmcia_device *link)
165{
166 pcmcia_disable_device(link);
167 cur_dev = NULL;
168} 113}
169 114
170static const struct pcmcia_device_id das08_cs_id_table[] = { 115static const struct pcmcia_device_id das08_cs_id_table[] = {
@@ -176,36 +121,11 @@ MODULE_DEVICE_TABLE(pcmcia, das08_cs_id_table);
176static struct pcmcia_driver das08_cs_driver = { 121static struct pcmcia_driver das08_cs_driver = {
177 .name = "pcm-das08", 122 .name = "pcm-das08",
178 .owner = THIS_MODULE, 123 .owner = THIS_MODULE,
179 .probe = das08_pcmcia_attach,
180 .remove = das08_pcmcia_detach,
181 .id_table = das08_cs_id_table, 124 .id_table = das08_cs_id_table,
125 .probe = das08_pcmcia_attach,
126 .remove = comedi_pcmcia_auto_unconfig,
182}; 127};
183 128module_comedi_pcmcia_driver(driver_das08_cs, das08_cs_driver);
184static int __init das08_cs_init_module(void)
185{
186 int ret;
187
188 ret = comedi_driver_register(&driver_das08_cs);
189 if (ret < 0)
190 return ret;
191
192 ret = pcmcia_register_driver(&das08_cs_driver);
193 if (ret < 0) {
194 comedi_driver_unregister(&driver_das08_cs);
195 return ret;
196 }
197
198 return 0;
199
200}
201module_init(das08_cs_init_module);
202
203static void __exit das08_cs_exit_module(void)
204{
205 pcmcia_unregister_driver(&das08_cs_driver);
206 comedi_driver_unregister(&driver_das08_cs);
207}
208module_exit(das08_cs_exit_module);
209 129
210MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, " 130MODULE_AUTHOR("David A. Schleef <ds@schleef.org>, "
211 "Frank Mori Hess <fmhess@users.sourceforge.net>"); 131 "Frank Mori Hess <fmhess@users.sourceforge.net>");
diff --git a/drivers/staging/comedi/drivers/das08_isa.c b/drivers/staging/comedi/drivers/das08_isa.c
new file mode 100644
index 000000000000..f12078247163
--- /dev/null
+++ b/drivers/staging/comedi/drivers/das08_isa.c
@@ -0,0 +1,217 @@
1/*
2 * das08_isa.c
3 * comedi driver for DAS08 ISA/PC-104 boards
4 *
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25/*
26 * Driver: das08_isa
27 * Description: DAS-08 ISA/PC-104 compatible boards
28 * Devices: (Keithley Metrabyte) DAS08 [isa-das08],
29 * (ComputerBoards) DAS08 [isa-das08]
30 * (ComputerBoards) DAS08-PGM [das08-pgm]
31 * (ComputerBoards) DAS08-PGH [das08-pgh]
32 * (ComputerBoards) DAS08-PGL [das08-pgl]
33 * (ComputerBoards) DAS08-AOH [das08-aoh]
34 * (ComputerBoards) DAS08-AOL [das08-aol]
35 * (ComputerBoards) DAS08-AOM [das08-aom]
36 * (ComputerBoards) DAS08/JR-AO [das08/jr-ao]
37 * (ComputerBoards) DAS08/JR-16-AO [das08jr-16-ao]
38 * (ComputerBoards) PC104-DAS08 [pc104-das08]
39 * (ComputerBoards) DAS08/JR/16 [das08jr/16]
40 * Author: Warren Jasper, ds, Frank Hess
41 * Updated: Fri, 31 Aug 2012 19:19:06 +0100
42 * Status: works
43 *
44 * This is the ISA/PC-104-specific support split off from the das08 driver.
45 *
46 * Configuration Options:
47 * [0] - base io address
48 */
49
50#include "../comedidev.h"
51
52#include "das08.h"
53
54static const struct das08_board_struct das08_isa_boards[] = {
55 {
56 /* cio-das08.pdf */
57 .name = "isa-das08",
58 .ai_nbits = 12,
59 .ai_pg = das08_pg_none,
60 .ai_encoding = das08_encode12,
61 .di_nchan = 3,
62 .do_nchan = 4,
63 .i8255_offset = 8,
64 .i8254_offset = 4,
65 .iosize = 16, /* unchecked */
66 }, {
67 /* cio-das08pgx.pdf */
68 .name = "das08-pgm",
69 .ai_nbits = 12,
70 .ai_pg = das08_pgm,
71 .ai_encoding = das08_encode12,
72 .di_nchan = 3,
73 .do_nchan = 4,
74 .i8255_offset = 0,
75 .i8254_offset = 0x04,
76 .iosize = 16, /* unchecked */
77 }, {
78 /* cio-das08pgx.pdf */
79 .name = "das08-pgh",
80 .ai_nbits = 12,
81 .ai_pg = das08_pgh,
82 .ai_encoding = das08_encode12,
83 .di_nchan = 3,
84 .do_nchan = 4,
85 .i8254_offset = 0x04,
86 .iosize = 16, /* unchecked */
87 }, {
88 /* cio-das08pgx.pdf */
89 .name = "das08-pgl",
90 .ai_nbits = 12,
91 .ai_pg = das08_pgl,
92 .ai_encoding = das08_encode12,
93 .di_nchan = 3,
94 .do_nchan = 4,
95 .i8254_offset = 0x04,
96 .iosize = 16, /* unchecked */
97 }, {
98 /* cio-das08_aox.pdf */
99 .name = "das08-aoh",
100 .ai_nbits = 12,
101 .ai_pg = das08_pgh,
102 .ai_encoding = das08_encode12,
103 .ao_nbits = 12,
104 .di_nchan = 3,
105 .do_nchan = 4,
106 .i8255_offset = 0x0c,
107 .i8254_offset = 0x04,
108 .iosize = 16, /* unchecked */
109 }, {
110 /* cio-das08_aox.pdf */
111 .name = "das08-aol",
112 .ai_nbits = 12,
113 .ai_pg = das08_pgl,
114 .ai_encoding = das08_encode12,
115 .ao_nbits = 12,
116 .di_nchan = 3,
117 .do_nchan = 4,
118 .i8255_offset = 0x0c,
119 .i8254_offset = 0x04,
120 .iosize = 16, /* unchecked */
121 }, {
122 /* cio-das08_aox.pdf */
123 .name = "das08-aom",
124 .ai_nbits = 12,
125 .ai_pg = das08_pgm,
126 .ai_encoding = das08_encode12,
127 .ao_nbits = 12,
128 .di_nchan = 3,
129 .do_nchan = 4,
130 .i8255_offset = 0x0c,
131 .i8254_offset = 0x04,
132 .iosize = 16, /* unchecked */
133 }, {
134 /* cio-das08-jr-ao.pdf */
135 .name = "das08/jr-ao",
136 .is_jr = true,
137 .ai_nbits = 12,
138 .ai_pg = das08_pg_none,
139 .ai_encoding = das08_encode12,
140 .ao_nbits = 12,
141 .di_nchan = 8,
142 .do_nchan = 8,
143 .iosize = 16, /* unchecked */
144 }, {
145 /* cio-das08jr-16-ao.pdf */
146 .name = "das08jr-16-ao",
147 .is_jr = true,
148 .ai_nbits = 16,
149 .ai_pg = das08_pg_none,
150 .ai_encoding = das08_encode16,
151 .ao_nbits = 16,
152 .di_nchan = 8,
153 .do_nchan = 8,
154 .i8254_offset = 0x04,
155 .iosize = 16, /* unchecked */
156 }, {
157 .name = "pc104-das08",
158 .ai_nbits = 12,
159 .ai_pg = das08_pg_none,
160 .ai_encoding = das08_encode12,
161 .di_nchan = 3,
162 .do_nchan = 4,
163 .i8254_offset = 4,
164 .iosize = 16, /* unchecked */
165 }, {
166 .name = "das08jr/16",
167 .is_jr = true,
168 .ai_nbits = 16,
169 .ai_pg = das08_pg_none,
170 .ai_encoding = das08_encode16,
171 .di_nchan = 8,
172 .do_nchan = 8,
173 .iosize = 16, /* unchecked */
174 },
175};
176
177static int das08_isa_attach(struct comedi_device *dev,
178 struct comedi_devconfig *it)
179{
180 const struct das08_board_struct *thisboard = comedi_board(dev);
181 struct das08_private_struct *devpriv;
182
183 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
184 if (!devpriv)
185 return -ENOMEM;
186 dev->private = devpriv;
187
188 if (!request_region(it->options[0], thisboard->iosize,
189 thisboard->name))
190 return -EIO;
191
192 return das08_common_attach(dev, it->options[0]);
193}
194
195static void das08_isa_detach(struct comedi_device *dev)
196{
197 const struct das08_board_struct *thisboard = comedi_board(dev);
198
199 das08_common_detach(dev);
200 if (dev->iobase)
201 release_region(dev->iobase, thisboard->iosize);
202}
203
204static struct comedi_driver das08_isa_driver = {
205 .driver_name = "isa-das08",
206 .module = THIS_MODULE,
207 .attach = das08_isa_attach,
208 .detach = das08_isa_detach,
209 .board_name = &das08_isa_boards[0].name,
210 .num_names = ARRAY_SIZE(das08_isa_boards),
211 .offset = sizeof(das08_isa_boards[0]),
212};
213module_comedi_driver(das08_isa_driver);
214
215MODULE_AUTHOR("Comedi http://www.comedi.org");
216MODULE_DESCRIPTION("Comedi low-level driver");
217MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/das08_pci.c b/drivers/staging/comedi/drivers/das08_pci.c
new file mode 100644
index 000000000000..c405876ddcf7
--- /dev/null
+++ b/drivers/staging/comedi/drivers/das08_pci.c
@@ -0,0 +1,121 @@
1/*
2 * das08_pci.c
3 * comedi driver for DAS08 PCI boards
4 *
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 * Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8 * Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25/*
26 * Driver: das08_pci
27 * Description: DAS-08 PCI compatible boards
28 * Devices: (ComputerBoards) PCI-DAS08 [pci-das08]
29 * Author: Warren Jasper, ds, Frank Hess
30 * Updated: Fri, 31 Aug 2012 19:19:06 +0100
31 * Status: works
32 *
33 * This is the PCI-specific support split off from the das08 driver.
34 *
35 * Configuration Options: not applicable, uses PCI auto config
36 */
37
38#include <linux/pci.h>
39
40#include "../comedidev.h"
41
42#include "das08.h"
43
44#define PCI_DEVICE_ID_PCIDAS08 0x0029
45
46static const struct das08_board_struct das08_pci_boards[] = {
47 {
48 .name = "pci-das08",
49 .id = PCI_DEVICE_ID_PCIDAS08,
50 .ai_nbits = 12,
51 .ai_pg = das08_bipolar5,
52 .ai_encoding = das08_encode12,
53 .di_nchan = 3,
54 .do_nchan = 4,
55 .i8254_offset = 4,
56 .iosize = 8,
57 },
58};
59
60static int das08_pci_auto_attach(struct comedi_device *dev,
61 unsigned long context_unused)
62{
63 struct pci_dev *pdev = comedi_to_pci_dev(dev);
64 struct das08_private_struct *devpriv;
65 int ret;
66
67 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
68 if (!devpriv)
69 return -ENOMEM;
70 dev->private = devpriv;
71
72 /* The das08 driver needs the board_ptr */
73 dev->board_ptr = &das08_pci_boards[0];
74
75 ret = comedi_pci_enable(pdev, dev->driver->driver_name);
76 if (ret)
77 return ret;
78 dev->iobase = pci_resource_start(pdev, 2);
79
80 return das08_common_attach(dev, dev->iobase);
81}
82
83static void das08_pci_detach(struct comedi_device *dev)
84{
85 struct pci_dev *pdev = comedi_to_pci_dev(dev);
86
87 das08_common_detach(dev);
88 if (dev->iobase)
89 comedi_pci_disable(pdev);
90}
91
92static struct comedi_driver das08_pci_comedi_driver = {
93 .driver_name = "pci-das08",
94 .module = THIS_MODULE,
95 .auto_attach = das08_pci_auto_attach,
96 .detach = das08_pci_detach,
97};
98
99static int das08_pci_probe(struct pci_dev *dev,
100 const struct pci_device_id *ent)
101{
102 return comedi_pci_auto_config(dev, &das08_pci_comedi_driver);
103}
104
105static DEFINE_PCI_DEVICE_TABLE(das08_pci_table) = {
106 { PCI_DEVICE(PCI_VENDOR_ID_CB, PCI_DEVICE_ID_PCIDAS08) },
107 { 0 }
108};
109MODULE_DEVICE_TABLE(pci, das08_pci_table);
110
111static struct pci_driver das08_pci_driver = {
112 .name = "pci-das08",
113 .id_table = das08_pci_table,
114 .probe = das08_pci_probe,
115 .remove = comedi_pci_auto_unconfig,
116};
117module_comedi_pci_driver(das08_pci_comedi_driver, das08_pci_driver);
118
119MODULE_AUTHOR("Comedi http://www.comedi.org");
120MODULE_DESCRIPTION("Comedi low-level driver");
121MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index b159f44d694f..f238a1fbccbf 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -82,7 +82,9 @@ www.measurementcomputing.com
82#include <linux/pci.h> 82#include <linux/pci.h>
83#include <linux/slab.h> 83#include <linux/slab.h>
84#include <linux/interrupt.h> 84#include <linux/interrupt.h>
85
85#include <asm/dma.h> 86#include <asm/dma.h>
87
86#include "../comedidev.h" 88#include "../comedidev.h"
87 89
88#include "8253.h" 90#include "8253.h"
diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c
index 960da8debe17..3ce499fa5dbf 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -55,9 +55,11 @@ AO commands are not supported.
55 55
56#define DEBUG 1 56#define DEBUG 1
57 57
58#include <linux/pci.h>
59#include <linux/delay.h>
58#include <linux/interrupt.h> 60#include <linux/interrupt.h>
61
59#include "../comedidev.h" 62#include "../comedidev.h"
60#include <linux/delay.h>
61 63
62#include "comedi_fc.h" 64#include "comedi_fc.h"
63 65
@@ -856,11 +858,6 @@ static int dt3000_pci_probe(struct pci_dev *dev,
856 return comedi_pci_auto_config(dev, &dt3000_driver); 858 return comedi_pci_auto_config(dev, &dt3000_driver);
857} 859}
858 860
859static void dt3000_pci_remove(struct pci_dev *dev)
860{
861 comedi_pci_auto_unconfig(dev);
862}
863
864static DEFINE_PCI_DEVICE_TABLE(dt3000_pci_table) = { 861static DEFINE_PCI_DEVICE_TABLE(dt3000_pci_table) = {
865 { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001) }, 862 { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001) },
866 { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001_PGL) }, 863 { PCI_DEVICE(PCI_VENDOR_ID_DT, PCI_DEVICE_ID_DT3001_PGL) },
@@ -877,7 +874,7 @@ static struct pci_driver dt3000_pci_driver = {
877 .name = "dt3000", 874 .name = "dt3000",
878 .id_table = dt3000_pci_table, 875 .id_table = dt3000_pci_table,
879 .probe = dt3000_pci_probe, 876 .probe = dt3000_pci_probe,
880 .remove = dt3000_pci_remove, 877 .remove = comedi_pci_auto_unconfig,
881}; 878};
882module_comedi_pci_driver(dt3000_driver, dt3000_pci_driver); 879module_comedi_pci_driver(dt3000_driver, dt3000_pci_driver);
883 880
diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c
index 176799849d20..192cf088f834 100644
--- a/drivers/staging/comedi/drivers/dt9812.c
+++ b/drivers/staging/comedi/drivers/dt9812.c
@@ -702,10 +702,9 @@ static int dt9812_probe(struct usb_interface *interface,
702 702
703 /* allocate memory for our device state and initialize it */ 703 /* allocate memory for our device state and initialize it */
704 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 704 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
705 if (dev == NULL) { 705 if (dev == NULL)
706 dev_err(&interface->dev, "Out of memory\n");
707 goto error; 706 goto error;
708 } 707
709 kref_init(&dev->kref); 708 kref_init(&dev->kref);
710 709
711 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 710 dev->udev = usb_get_dev(interface_to_usbdev(interface));
@@ -1133,7 +1132,7 @@ static struct comedi_driver dt9812_comedi_driver = {
1133 1132
1134static int __init usb_dt9812_init(void) 1133static int __init usb_dt9812_init(void)
1135{ 1134{
1136 int result, i; 1135 int i;
1137 1136
1138 /* Initialize all driver slots */ 1137 /* Initialize all driver slots */
1139 for (i = 0; i < DT9812_NUM_SLOTS; i++) { 1138 for (i = 0; i < DT9812_NUM_SLOTS; i++) {
@@ -1144,30 +1143,13 @@ static int __init usb_dt9812_init(void)
1144 } 1143 }
1145 dt9812[12].serial = 0x0; 1144 dt9812[12].serial = 0x0;
1146 1145
1147 /* register with the USB subsystem */ 1146 return comedi_usb_driver_register(&dt9812_comedi_driver,
1148 result = usb_register(&dt9812_usb_driver); 1147 &dt9812_usb_driver);
1149 if (result) {
1150 pr_err("usb_register failed. Error number %d\n", result);
1151 return result;
1152 }
1153 /* register with comedi */
1154 result = comedi_driver_register(&dt9812_comedi_driver);
1155 if (result) {
1156 usb_deregister(&dt9812_usb_driver);
1157 pr_err("comedi_driver_register failed. Error number %d\n",
1158 result);
1159 }
1160
1161 return result;
1162} 1148}
1163 1149
1164static void __exit usb_dt9812_exit(void) 1150static void __exit usb_dt9812_exit(void)
1165{ 1151{
1166 /* unregister with comedi */ 1152 comedi_usb_driver_unregister(&dt9812_comedi_driver, &dt9812_usb_driver);
1167 comedi_driver_unregister(&dt9812_comedi_driver);
1168
1169 /* deregister this driver with the USB subsystem */
1170 usb_deregister(&dt9812_usb_driver);
1171} 1153}
1172 1154
1173module_init(usb_dt9812_init); 1155module_init(usb_dt9812_init);
diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 8497a36db7db..decc17f1867e 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -37,9 +37,11 @@
37 their cards in their manuals. 37 their cards in their manuals.
38*/ 38*/
39 39
40#include "../comedidev.h" 40#include <linux/pci.h>
41#include <linux/mutex.h> 41#include <linux/mutex.h>
42 42
43#include "../comedidev.h"
44
43#define READ_TIMEOUT 50 45#define READ_TIMEOUT 50
44 46
45static const struct comedi_lrange range_pci1050_ai = { 3, { 47static const struct comedi_lrange range_pci1050_ai = { 3, {
@@ -276,11 +278,6 @@ static int dyna_pci10xx_pci_probe(struct pci_dev *dev,
276 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver); 278 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver);
277} 279}
278 280
279static void dyna_pci10xx_pci_remove(struct pci_dev *dev)
280{
281 comedi_pci_auto_unconfig(dev);
282}
283
284static DEFINE_PCI_DEVICE_TABLE(dyna_pci10xx_pci_table) = { 281static DEFINE_PCI_DEVICE_TABLE(dyna_pci10xx_pci_table) = {
285 { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) }, 282 { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) },
286 { 0 } 283 { 0 }
@@ -291,7 +288,7 @@ static struct pci_driver dyna_pci10xx_pci_driver = {
291 .name = "dyna_pci10xx", 288 .name = "dyna_pci10xx",
292 .id_table = dyna_pci10xx_pci_table, 289 .id_table = dyna_pci10xx_pci_table,
293 .probe = dyna_pci10xx_pci_probe, 290 .probe = dyna_pci10xx_pci_probe,
294 .remove = dyna_pci10xx_pci_remove, 291 .remove = comedi_pci_auto_unconfig,
295}; 292};
296module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver); 293module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver);
297 294
diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c
index 154598f6d5e3..b60c97562676 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -47,9 +47,11 @@
47 47
48#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 48#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
49 49
50#include <linux/pci.h>
51#include <linux/delay.h>
50#include <linux/interrupt.h> 52#include <linux/interrupt.h>
53
51#include "../comedidev.h" 54#include "../comedidev.h"
52#include <linux/delay.h>
53 55
54#include "plx9080.h" 56#include "plx9080.h"
55#include "comedi_fc.h" 57#include "comedi_fc.h"
@@ -946,11 +948,6 @@ static int gsc_hpdi_pci_probe(struct pci_dev *dev,
946 return comedi_pci_auto_config(dev, &gsc_hpdi_driver); 948 return comedi_pci_auto_config(dev, &gsc_hpdi_driver);
947} 949}
948 950
949static void gsc_hpdi_pci_remove(struct pci_dev *dev)
950{
951 comedi_pci_auto_unconfig(dev);
952}
953
954static DEFINE_PCI_DEVICE_TABLE(gsc_hpdi_pci_table) = { 951static DEFINE_PCI_DEVICE_TABLE(gsc_hpdi_pci_table) = {
955 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX, 952 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9080, PCI_VENDOR_ID_PLX,
956 0x2400, 0, 0, 0}, 953 0x2400, 0, 0, 0},
@@ -962,7 +959,7 @@ static struct pci_driver gsc_hpdi_pci_driver = {
962 .name = "gsc_hpdi", 959 .name = "gsc_hpdi",
963 .id_table = gsc_hpdi_pci_table, 960 .id_table = gsc_hpdi_pci_table,
964 .probe = gsc_hpdi_pci_probe, 961 .probe = gsc_hpdi_pci_probe,
965 .remove = gsc_hpdi_pci_remove 962 .remove = comedi_pci_auto_unconfig,
966}; 963};
967module_comedi_pci_driver(gsc_hpdi_driver, gsc_hpdi_pci_driver); 964module_comedi_pci_driver(gsc_hpdi_driver, gsc_hpdi_pci_driver);
968 965
diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c
index a91a448ba0f0..1e08f9141fad 100644
--- a/drivers/staging/comedi/drivers/icp_multi.c
+++ b/drivers/staging/comedi/drivers/icp_multi.c
@@ -47,11 +47,11 @@ There are 4 x 12-bit Analogue Outputs. Ranges : 5V, 10V, +/-5V, +/-10V
47Configuration options: not applicable, uses PCI auto config 47Configuration options: not applicable, uses PCI auto config
48*/ 48*/
49 49
50#include <linux/pci.h>
51#include <linux/delay.h>
50#include <linux/interrupt.h> 52#include <linux/interrupt.h>
51#include "../comedidev.h"
52 53
53#include <linux/delay.h> 54#include "../comedidev.h"
54#include <linux/pci.h>
55 55
56#define PCI_DEVICE_ID_ICP_MULTI 0x8000 56#define PCI_DEVICE_ID_ICP_MULTI 0x8000
57 57
@@ -623,11 +623,6 @@ static int icp_multi_pci_probe(struct pci_dev *dev,
623 return comedi_pci_auto_config(dev, &icp_multi_driver); 623 return comedi_pci_auto_config(dev, &icp_multi_driver);
624} 624}
625 625
626static void icp_multi_pci_remove(struct pci_dev *dev)
627{
628 comedi_pci_auto_unconfig(dev);
629}
630
631static DEFINE_PCI_DEVICE_TABLE(icp_multi_pci_table) = { 626static DEFINE_PCI_DEVICE_TABLE(icp_multi_pci_table) = {
632 { PCI_DEVICE(PCI_VENDOR_ID_ICP, PCI_DEVICE_ID_ICP_MULTI) }, 627 { PCI_DEVICE(PCI_VENDOR_ID_ICP, PCI_DEVICE_ID_ICP_MULTI) },
633 { 0 } 628 { 0 }
@@ -638,7 +633,7 @@ static struct pci_driver icp_multi_pci_driver = {
638 .name = "icp_multi", 633 .name = "icp_multi",
639 .id_table = icp_multi_pci_table, 634 .id_table = icp_multi_pci_table,
640 .probe = icp_multi_pci_probe, 635 .probe = icp_multi_pci_probe,
641 .remove = icp_multi_pci_remove, 636 .remove = comedi_pci_auto_unconfig,
642}; 637};
643module_comedi_pci_driver(icp_multi_driver, icp_multi_pci_driver); 638module_comedi_pci_driver(icp_multi_driver, icp_multi_pci_driver);
644 639
diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c
index c756a35ce31a..17ba75e0ab89 100644
--- a/drivers/staging/comedi/drivers/jr3_pci.c
+++ b/drivers/staging/comedi/drivers/jr3_pci.c
@@ -42,15 +42,17 @@
42 * comedi_nonfree_firmware tarball. The file is called "jr3pci.idm". 42 * comedi_nonfree_firmware tarball. The file is called "jr3pci.idm".
43 */ 43 */
44 44
45#include "../comedidev.h" 45#include <linux/kernel.h>
46 46#include <linux/pci.h>
47#include <linux/delay.h> 47#include <linux/delay.h>
48#include <linux/ctype.h> 48#include <linux/ctype.h>
49#include <linux/firmware.h> 49#include <linux/firmware.h>
50#include <linux/jiffies.h> 50#include <linux/jiffies.h>
51#include <linux/slab.h> 51#include <linux/slab.h>
52#include <linux/timer.h> 52#include <linux/timer.h>
53#include <linux/kernel.h> 53
54#include "../comedidev.h"
55
54#include "jr3_pci.h" 56#include "jr3_pci.h"
55 57
56#define PCI_VENDOR_ID_JR3 0x1762 58#define PCI_VENDOR_ID_JR3 0x1762
@@ -844,11 +846,6 @@ static int jr3_pci_pci_probe(struct pci_dev *dev,
844 return comedi_pci_auto_config(dev, &jr3_pci_driver); 846 return comedi_pci_auto_config(dev, &jr3_pci_driver);
845} 847}
846 848
847static void jr3_pci_pci_remove(struct pci_dev *dev)
848{
849 comedi_pci_auto_unconfig(dev);
850}
851
852static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table) = { 849static DEFINE_PCI_DEVICE_TABLE(jr3_pci_pci_table) = {
853 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL) }, 850 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL) },
854 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW) }, 851 { PCI_DEVICE(PCI_VENDOR_ID_JR3, PCI_DEVICE_ID_JR3_1_CHANNEL_NEW) },
@@ -863,7 +860,7 @@ static struct pci_driver jr3_pci_pci_driver = {
863 .name = "jr3_pci", 860 .name = "jr3_pci",
864 .id_table = jr3_pci_pci_table, 861 .id_table = jr3_pci_pci_table,
865 .probe = jr3_pci_pci_probe, 862 .probe = jr3_pci_pci_probe,
866 .remove = jr3_pci_pci_remove, 863 .remove = comedi_pci_auto_unconfig,
867}; 864};
868module_comedi_pci_driver(jr3_pci_driver, jr3_pci_pci_driver); 865module_comedi_pci_driver(jr3_pci_driver, jr3_pci_pci_driver);
869 866
diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c
index 19c94282ac3f..8c09c026508a 100644
--- a/drivers/staging/comedi/drivers/ke_counter.c
+++ b/drivers/staging/comedi/drivers/ke_counter.c
@@ -34,6 +34,8 @@ This driver is a simple driver to read the counter values from
34Kolter Electronic PCI Counter Card. 34Kolter Electronic PCI Counter Card.
35*/ 35*/
36 36
37#include <linux/pci.h>
38
37#include "../comedidev.h" 39#include "../comedidev.h"
38 40
39#define CNT_CARD_DEVICE_ID 0x0014 41#define CNT_CARD_DEVICE_ID 0x0014
@@ -152,11 +154,6 @@ static int ke_counter_pci_probe(struct pci_dev *dev,
152 return comedi_pci_auto_config(dev, &ke_counter_driver); 154 return comedi_pci_auto_config(dev, &ke_counter_driver);
153} 155}
154 156
155static void ke_counter_pci_remove(struct pci_dev *dev)
156{
157 comedi_pci_auto_unconfig(dev);
158}
159
160static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = { 157static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
161 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) }, 158 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
162 { 0 } 159 { 0 }
@@ -167,7 +164,7 @@ static struct pci_driver ke_counter_pci_driver = {
167 .name = "ke_counter", 164 .name = "ke_counter",
168 .id_table = ke_counter_pci_table, 165 .id_table = ke_counter_pci_table,
169 .probe = ke_counter_pci_probe, 166 .probe = ke_counter_pci_probe,
170 .remove = ke_counter_pci_remove, 167 .remove = comedi_pci_auto_unconfig,
171}; 168};
172module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver); 169module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
173 170
diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c
index 3c4b0228e8dc..b766bb93efd6 100644
--- a/drivers/staging/comedi/drivers/me4000.c
+++ b/drivers/staging/comedi/drivers/me4000.c
@@ -45,13 +45,14 @@ broken.
45 45
46 */ 46 */
47 47
48#include <linux/interrupt.h> 48#include <linux/pci.h>
49#include "../comedidev.h"
50
51#include <linux/delay.h> 49#include <linux/delay.h>
50#include <linux/interrupt.h>
52#include <linux/list.h> 51#include <linux/list.h>
53#include <linux/spinlock.h> 52#include <linux/spinlock.h>
54 53
54#include "../comedidev.h"
55
55#include "comedi_fc.h" 56#include "comedi_fc.h"
56#include "8253.h" 57#include "8253.h"
57 58
@@ -1734,11 +1735,6 @@ static int me4000_pci_probe(struct pci_dev *dev,
1734 return comedi_pci_auto_config(dev, &me4000_driver); 1735 return comedi_pci_auto_config(dev, &me4000_driver);
1735} 1736}
1736 1737
1737static void me4000_pci_remove(struct pci_dev *dev)
1738{
1739 comedi_pci_auto_unconfig(dev);
1740}
1741
1742static DEFINE_PCI_DEVICE_TABLE(me4000_pci_table) = { 1738static DEFINE_PCI_DEVICE_TABLE(me4000_pci_table) = {
1743 {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4650)}, 1739 {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4650)},
1744 {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660)}, 1740 {PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, PCI_DEVICE_ID_MEILHAUS_ME4660)},
@@ -1761,7 +1757,7 @@ static struct pci_driver me4000_pci_driver = {
1761 .name = "me4000", 1757 .name = "me4000",
1762 .id_table = me4000_pci_table, 1758 .id_table = me4000_pci_table,
1763 .probe = me4000_pci_probe, 1759 .probe = me4000_pci_probe,
1764 .remove = me4000_pci_remove, 1760 .remove = comedi_pci_auto_unconfig,
1765}; 1761};
1766module_comedi_pci_driver(me4000_driver, me4000_pci_driver); 1762module_comedi_pci_driver(me4000_driver, me4000_pci_driver);
1767 1763
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c
index ce8e3d3f135c..06490ebc8cc8 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -34,9 +34,11 @@
34 * Analog Input, Analog Output, Digital I/O 34 * Analog Input, Analog Output, Digital I/O
35 */ 35 */
36 36
37#include <linux/pci.h>
37#include <linux/interrupt.h> 38#include <linux/interrupt.h>
38#include <linux/sched.h> 39#include <linux/sched.h>
39#include <linux/firmware.h> 40#include <linux/firmware.h>
41
40#include "../comedidev.h" 42#include "../comedidev.h"
41 43
42#define ME2600_FIRMWARE "me2600_firmware.bin" 44#define ME2600_FIRMWARE "me2600_firmware.bin"
@@ -619,11 +621,6 @@ static int me_daq_pci_probe(struct pci_dev *dev,
619 return comedi_pci_auto_config(dev, &me_daq_driver); 621 return comedi_pci_auto_config(dev, &me_daq_driver);
620} 622}
621 623
622static void me_daq_pci_remove(struct pci_dev *dev)
623{
624 comedi_pci_auto_unconfig(dev);
625}
626
627static DEFINE_PCI_DEVICE_TABLE(me_daq_pci_table) = { 624static DEFINE_PCI_DEVICE_TABLE(me_daq_pci_table) = {
628 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID) }, 625 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID) },
629 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID) }, 626 { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID) },
@@ -635,7 +632,7 @@ static struct pci_driver me_daq_pci_driver = {
635 .name = "me_daq", 632 .name = "me_daq",
636 .id_table = me_daq_pci_table, 633 .id_table = me_daq_pci_table,
637 .probe = me_daq_pci_probe, 634 .probe = me_daq_pci_probe,
638 .remove = me_daq_pci_remove, 635 .remove = comedi_pci_auto_unconfig,
639}; 636};
640module_comedi_pci_driver(me_daq_driver, me_daq_pci_driver); 637module_comedi_pci_driver(me_daq_driver, me_daq_pci_driver);
641 638
diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c
index e27850f628ce..be2c15f84614 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -51,11 +51,12 @@
51 51
52#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 52#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
53 53
54#include "mite.h" 54#include <linux/pci.h>
55 55
56#include "comedi_fc.h"
57#include "../comedidev.h" 56#include "../comedidev.h"
58 57
58#include "comedi_fc.h"
59#include "mite.h"
59 60
60#define PCI_MITE_SIZE 4096 61#define PCI_MITE_SIZE 4096
61#define PCI_DAQ_SIZE 4096 62#define PCI_DAQ_SIZE 4096
diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c
index 5196b460ce11..bcd4df290ec4 100644
--- a/drivers/staging/comedi/drivers/ni_6527.c
+++ b/drivers/staging/comedi/drivers/ni_6527.c
@@ -41,7 +41,9 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800
41#define DEBUG 1 41#define DEBUG 1
42#define DEBUG_FLAGS 42#define DEBUG_FLAGS
43 43
44#include <linux/pci.h>
44#include <linux/interrupt.h> 45#include <linux/interrupt.h>
46
45#include "../comedidev.h" 47#include "../comedidev.h"
46 48
47#include "comedi_fc.h" 49#include "comedi_fc.h"
@@ -452,16 +454,11 @@ static int ni6527_pci_probe(struct pci_dev *dev,
452 return comedi_pci_auto_config(dev, &ni6527_driver); 454 return comedi_pci_auto_config(dev, &ni6527_driver);
453} 455}
454 456
455static void ni6527_pci_remove(struct pci_dev *dev)
456{
457 comedi_pci_auto_unconfig(dev);
458}
459
460static struct pci_driver ni6527_pci_driver = { 457static struct pci_driver ni6527_pci_driver = {
461 .name = DRIVER_NAME, 458 .name = DRIVER_NAME,
462 .id_table = ni6527_pci_table, 459 .id_table = ni6527_pci_table,
463 .probe = ni6527_pci_probe, 460 .probe = ni6527_pci_probe,
464 .remove = ni6527_pci_remove 461 .remove = comedi_pci_auto_unconfig,
465}; 462};
466module_comedi_pci_driver(ni6527_driver, ni6527_pci_driver); 463module_comedi_pci_driver(ni6527_driver, ni6527_pci_driver);
467 464
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 2fb4b7790aeb..bfa790ecf41d 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -50,8 +50,11 @@ except maybe the 6514.
50 50
51#define DEBUG 1 51#define DEBUG 1
52#define DEBUG_FLAGS 52#define DEBUG_FLAGS
53
54#include <linux/pci.h>
53#include <linux/interrupt.h> 55#include <linux/interrupt.h>
54#include <linux/slab.h> 56#include <linux/slab.h>
57
55#include "../comedidev.h" 58#include "../comedidev.h"
56 59
57#include "comedi_fc.h" 60#include "comedi_fc.h"
@@ -787,16 +790,11 @@ static int ni_65xx_pci_probe(struct pci_dev *dev,
787 return comedi_pci_auto_config(dev, &ni_65xx_driver); 790 return comedi_pci_auto_config(dev, &ni_65xx_driver);
788} 791}
789 792
790static void ni_65xx_pci_remove(struct pci_dev *dev)
791{
792 comedi_pci_auto_unconfig(dev);
793}
794
795static struct pci_driver ni_65xx_pci_driver = { 793static struct pci_driver ni_65xx_pci_driver = {
796 .name = "ni_65xx", 794 .name = "ni_65xx",
797 .id_table = ni_65xx_pci_table, 795 .id_table = ni_65xx_pci_table,
798 .probe = ni_65xx_pci_probe, 796 .probe = ni_65xx_pci_probe,
799 .remove = ni_65xx_pci_remove 797 .remove = comedi_pci_auto_unconfig,
800}; 798};
801module_comedi_pci_driver(ni_65xx_driver, ni_65xx_pci_driver); 799module_comedi_pci_driver(ni_65xx_driver, ni_65xx_pci_driver);
802 800
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 26baf9c96fff..e46dd7a1a724 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -40,8 +40,11 @@ DAQ 6601/6602 User Manual (NI 322137B-01)
40 40
41*/ 41*/
42 42
43#include <linux/pci.h>
43#include <linux/interrupt.h> 44#include <linux/interrupt.h>
45
44#include "../comedidev.h" 46#include "../comedidev.h"
47
45#include "mite.h" 48#include "mite.h"
46#include "ni_tio.h" 49#include "ni_tio.h"
47 50
@@ -1327,11 +1330,6 @@ static int ni_660x_pci_probe(struct pci_dev *dev,
1327 return comedi_pci_auto_config(dev, &ni_660x_driver); 1330 return comedi_pci_auto_config(dev, &ni_660x_driver);
1328} 1331}
1329 1332
1330static void ni_660x_pci_remove(struct pci_dev *dev)
1331{
1332 comedi_pci_auto_unconfig(dev);
1333}
1334
1335static DEFINE_PCI_DEVICE_TABLE(ni_660x_pci_table) = { 1333static DEFINE_PCI_DEVICE_TABLE(ni_660x_pci_table) = {
1336 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c60)}, 1334 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c60)},
1337 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1310)}, 1335 {PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1310)},
@@ -1345,7 +1343,7 @@ static struct pci_driver ni_660x_pci_driver = {
1345 .name = "ni_660x", 1343 .name = "ni_660x",
1346 .id_table = ni_660x_pci_table, 1344 .id_table = ni_660x_pci_table,
1347 .probe = ni_660x_pci_probe, 1345 .probe = ni_660x_pci_probe,
1348 .remove = ni_660x_pci_remove, 1346 .remove = comedi_pci_auto_unconfig,
1349}; 1347};
1350module_comedi_pci_driver(ni_660x_driver, ni_660x_pci_driver); 1348module_comedi_pci_driver(ni_660x_driver, ni_660x_pci_driver);
1351 1349
diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c
index 272caeb6ecee..2faf86c83dc5 100644
--- a/drivers/staging/comedi/drivers/ni_670x.c
+++ b/drivers/staging/comedi/drivers/ni_670x.c
@@ -41,8 +41,10 @@ Commands are not supported.
41 41
42*/ 42*/
43 43
44#include <linux/pci.h>
44#include <linux/interrupt.h> 45#include <linux/interrupt.h>
45#include <linux/slab.h> 46#include <linux/slab.h>
47
46#include "../comedidev.h" 48#include "../comedidev.h"
47 49
48#include "mite.h" 50#include "mite.h"
@@ -309,11 +311,6 @@ static int ni_670x_pci_probe(struct pci_dev *dev,
309 return comedi_pci_auto_config(dev, &ni_670x_driver); 311 return comedi_pci_auto_config(dev, &ni_670x_driver);
310} 312}
311 313
312static void ni_670x_pci_remove(struct pci_dev *dev)
313{
314 comedi_pci_auto_unconfig(dev);
315}
316
317static DEFINE_PCI_DEVICE_TABLE(ni_670x_pci_table) = { 314static DEFINE_PCI_DEVICE_TABLE(ni_670x_pci_table) = {
318 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c90) }, 315 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2c90) },
319 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1920) }, 316 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1920) },
@@ -325,7 +322,7 @@ static struct pci_driver ni_670x_pci_driver = {
325 .name = "ni_670x", 322 .name = "ni_670x",
326 .id_table = ni_670x_pci_table, 323 .id_table = ni_670x_pci_table,
327 .probe = ni_670x_pci_probe, 324 .probe = ni_670x_pci_probe,
328 .remove = ni_670x_pci_remove, 325 .remove = comedi_pci_auto_unconfig,
329}; 326};
330module_comedi_pci_driver(ni_670x_driver, ni_670x_pci_driver); 327module_comedi_pci_driver(ni_670x_driver, ni_670x_pci_driver);
331 328
diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c
index 68d7c6a5db7d..9cc6092eacdd 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -50,22 +50,15 @@ Manuals: Register level: http://www.ni.com/pdf/manuals/340698.pdf
50 User Manual: http://www.ni.com/pdf/manuals/320676d.pdf 50 User Manual: http://www.ni.com/pdf/manuals/320676d.pdf
51*/ 51*/
52 52
53#include <linux/ioport.h>
53#include <linux/interrupt.h> 54#include <linux/interrupt.h>
54#include <linux/slab.h> 55#include <linux/slab.h>
55#include "../comedidev.h"
56 56
57#include <linux/ioport.h> 57#include "../comedidev.h"
58 58
59#include <pcmcia/cistpl.h> 59#include <pcmcia/cistpl.h>
60#include <pcmcia/cisreg.h>
61#include <pcmcia/ds.h> 60#include <pcmcia/ds.h>
62 61
63static struct pcmcia_device *pcmcia_cur_dev;
64
65struct daq700_board {
66 const char *name;
67};
68
69/* daqcard700 registers */ 62/* daqcard700 registers */
70#define DIO_W 0x04 /* WO 8bit */ 63#define DIO_W 0x04 /* WO 8bit */
71#define DIO_R 0x05 /* RO 8bit */ 64#define DIO_R 0x05 /* RO 8bit */
@@ -202,24 +195,20 @@ static void daq700_ai_config(struct comedi_device *dev,
202 inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */ 195 inw(iobase + ADFIFO_R); /* read 16bit junk from FIFO to clear */
203} 196}
204 197
205static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it) 198static int daq700_auto_attach(struct comedi_device *dev,
199 unsigned long context)
206{ 200{
207 const struct daq700_board *thisboard = comedi_board(dev); 201 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
208 struct comedi_subdevice *s; 202 struct comedi_subdevice *s;
209 struct pcmcia_device *link;
210 int ret; 203 int ret;
211 204
212 link = pcmcia_cur_dev; /* XXX hack */ 205 dev->board_name = dev->driver->driver_name;
213 if (!link)
214 return -EIO;
215 206
207 link->config_flags |= CONF_AUTO_SET_IO;
208 ret = comedi_pcmcia_enable(dev, NULL);
209 if (ret)
210 return ret;
216 dev->iobase = link->resource[0]->start; 211 dev->iobase = link->resource[0]->start;
217 if (!dev->iobase) {
218 dev_err(dev->class_dev, "io base address is zero!\n");
219 return -EINVAL;
220 }
221
222 dev->board_name = thisboard->name;
223 212
224 ret = comedi_alloc_subdevices(dev, 2); 213 ret = comedi_alloc_subdevices(dev, 2);
225 if (ret) 214 if (ret)
@@ -256,68 +245,16 @@ static int daq700_attach(struct comedi_device *dev, struct comedi_devconfig *it)
256 return 0; 245 return 0;
257} 246}
258 247
259static void daq700_detach(struct comedi_device *dev)
260{
261 /* nothing to cleanup */
262}
263
264static const struct daq700_board daq700_boards[] = {
265 {
266 .name = "daqcard-700",
267 }, {
268 .name = "ni_daq_700",
269 },
270};
271
272static struct comedi_driver daq700_driver = { 248static struct comedi_driver daq700_driver = {
273 .driver_name = "ni_daq_700", 249 .driver_name = "ni_daq_700",
274 .module = THIS_MODULE, 250 .module = THIS_MODULE,
275 .attach = daq700_attach, 251 .auto_attach = daq700_auto_attach,
276 .detach = daq700_detach, 252 .detach = comedi_pcmcia_disable,
277 .board_name = &daq700_boards[0].name,
278 .num_names = ARRAY_SIZE(daq700_boards),
279 .offset = sizeof(struct daq700_board),
280}; 253};
281 254
282static int daq700_pcmcia_config_loop(struct pcmcia_device *p_dev,
283 void *priv_data)
284{
285 if (p_dev->config_index == 0)
286 return -EINVAL;
287
288 return pcmcia_request_io(p_dev);
289}
290
291static int daq700_cs_attach(struct pcmcia_device *link) 255static int daq700_cs_attach(struct pcmcia_device *link)
292{ 256{
293 int ret; 257 return comedi_pcmcia_auto_config(link, &daq700_driver);
294
295 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO |
296 CONF_AUTO_SET_IO;
297
298 ret = pcmcia_loop_config(link, daq700_pcmcia_config_loop, NULL);
299 if (ret)
300 goto failed;
301
302 if (!link->irq)
303 goto failed;
304
305 ret = pcmcia_enable_device(link);
306 if (ret)
307 goto failed;
308
309 pcmcia_cur_dev = link;
310 return 0;
311
312failed:
313 pcmcia_disable_device(link);
314 return ret;
315}
316
317static void daq700_cs_detach(struct pcmcia_device *link)
318{
319 pcmcia_disable_device(link);
320 pcmcia_cur_dev = NULL;
321} 258}
322 259
323static const struct pcmcia_device_id daq700_cs_ids[] = { 260static const struct pcmcia_device_id daq700_cs_ids[] = {
@@ -329,35 +266,11 @@ MODULE_DEVICE_TABLE(pcmcia, daq700_cs_ids);
329static struct pcmcia_driver daq700_cs_driver = { 266static struct pcmcia_driver daq700_cs_driver = {
330 .name = "ni_daq_700", 267 .name = "ni_daq_700",
331 .owner = THIS_MODULE, 268 .owner = THIS_MODULE,
332 .probe = daq700_cs_attach,
333 .remove = daq700_cs_detach,
334 .id_table = daq700_cs_ids, 269 .id_table = daq700_cs_ids,
270 .probe = daq700_cs_attach,
271 .remove = comedi_pcmcia_auto_unconfig,
335}; 272};
336 273module_comedi_pcmcia_driver(daq700_driver, daq700_cs_driver);
337static int __init daq700_cs_init(void)
338{
339 int ret;
340
341 ret = comedi_driver_register(&daq700_driver);
342 if (ret < 0)
343 return ret;
344
345 ret = pcmcia_register_driver(&daq700_cs_driver);
346 if (ret < 0) {
347 comedi_driver_unregister(&daq700_driver);
348 return ret;
349 }
350
351 return 0;
352}
353module_init(daq700_cs_init);
354
355static void __exit daq700_cs_exit(void)
356{
357 pcmcia_unregister_driver(&daq700_cs_driver);
358 comedi_driver_unregister(&daq700_driver);
359}
360module_exit(daq700_cs_exit);
361 274
362MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>"); 275MODULE_AUTHOR("Fred Brooks <nsaspook@nsaspook.com>");
363MODULE_DESCRIPTION( 276MODULE_DESCRIPTION(
diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c
index 7b333353c5d9..e1cc9d01f200 100644
--- a/drivers/staging/comedi/drivers/ni_daq_dio24.c
+++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c
@@ -37,127 +37,28 @@ This is just a wrapper around the 8255.o driver to properly handle
37the PCMCIA interface. 37the PCMCIA interface.
38*/ 38*/
39 39
40 /* #define LABPC_DEBUG *//* enable debugging messages */
41#undef LABPC_DEBUG
42
43#include <linux/interrupt.h>
44#include <linux/slab.h>
45#include "../comedidev.h" 40#include "../comedidev.h"
46 41
47#include <linux/ioport.h>
48
49#include "8255.h"
50
51#include <pcmcia/cistpl.h> 42#include <pcmcia/cistpl.h>
52#include <pcmcia/cisreg.h> 43#include <pcmcia/cisreg.h>
53#include <pcmcia/ds.h> 44#include <pcmcia/ds.h>
54 45
55static struct pcmcia_device *pcmcia_cur_dev; 46#include "8255.h"
56
57#define DIO24_SIZE 4 /* size of io region used by board */
58
59static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it);
60static void dio24_detach(struct comedi_device *dev);
61
62enum dio24_bustype { pcmcia_bustype };
63
64struct dio24_board_struct {
65 const char *name;
66 int device_id; /* device id for pcmcia board */
67 enum dio24_bustype bustype; /* PCMCIA */
68 int have_dio; /* have 8255 chip */
69 /* function pointers so we can use inb/outb or readb/writeb as appropriate */
70 unsigned int (*read_byte) (unsigned int address);
71 void (*write_byte) (unsigned int byte, unsigned int address);
72};
73
74static const struct dio24_board_struct dio24_boards[] = {
75 {
76 .name = "daqcard-dio24",
77 .device_id = 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */
78 .bustype = pcmcia_bustype,
79 .have_dio = 1,
80 },
81 {
82 .name = "ni_daq_dio24",
83 .device_id = 0x475c, /* 0x10b is manufacturer id, 0x475c is device id */
84 .bustype = pcmcia_bustype,
85 .have_dio = 1,
86 },
87};
88
89/*
90 * Useful for shorthand access to the particular board structure
91 */
92#define thisboard ((const struct dio24_board_struct *)dev->board_ptr)
93
94struct dio24_private {
95
96 int data; /* number of data points left to be taken */
97};
98
99static struct comedi_driver driver_dio24 = {
100 .driver_name = "ni_daq_dio24",
101 .module = THIS_MODULE,
102 .attach = dio24_attach,
103 .detach = dio24_detach,
104 .num_names = ARRAY_SIZE(dio24_boards),
105 .board_name = &dio24_boards[0].name,
106 .offset = sizeof(struct dio24_board_struct),
107};
108 47
109static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it) 48static int dio24_auto_attach(struct comedi_device *dev,
49 unsigned long context)
110{ 50{
111 struct dio24_private *devpriv; 51 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
112 struct comedi_subdevice *s; 52 struct comedi_subdevice *s;
113 unsigned long iobase = 0;
114#ifdef incomplete
115 unsigned int irq = 0;
116#endif
117 struct pcmcia_device *link;
118 int ret; 53 int ret;
119 54
120 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); 55 dev->board_name = dev->driver->driver_name;
121 if (!devpriv)
122 return -ENOMEM;
123 dev->private = devpriv;
124
125 /* get base address, irq etc. based on bustype */
126 switch (thisboard->bustype) {
127 case pcmcia_bustype:
128 link = pcmcia_cur_dev; /* XXX hack */
129 if (!link)
130 return -EIO;
131 iobase = link->resource[0]->start;
132#ifdef incomplete
133 irq = link->irq;
134#endif
135 break;
136 default:
137 pr_err("bug! couldn't determine board type\n");
138 return -EINVAL;
139 break;
140 }
141 pr_debug("comedi%d: ni_daq_dio24: %s, io 0x%lx", dev->minor,
142 thisboard->name, iobase);
143#ifdef incomplete
144 if (irq)
145 pr_debug("irq %u\n", irq);
146#endif
147
148 if (iobase == 0) {
149 pr_err("io base address is zero!\n");
150 return -EINVAL;
151 }
152 56
153 dev->iobase = iobase; 57 link->config_flags |= CONF_AUTO_SET_IO;
154 58 ret = comedi_pcmcia_enable(dev, NULL);
155#ifdef incomplete 59 if (ret)
156 /* grab our IRQ */ 60 return ret;
157 dev->irq = irq; 61 dev->iobase = link->resource[0]->start;
158#endif
159
160 dev->board_name = thisboard->name;
161 62
162 ret = comedi_alloc_subdevices(dev, 1); 63 ret = comedi_alloc_subdevices(dev, 1);
163 if (ret) 64 if (ret)
@@ -165,184 +66,48 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it)
165 66
166 /* 8255 dio */ 67 /* 8255 dio */
167 s = &dev->subdevices[0]; 68 s = &dev->subdevices[0];
168 subdev_8255_init(dev, s, NULL, dev->iobase); 69 ret = subdev_8255_init(dev, s, NULL, dev->iobase);
70 if (ret)
71 return ret;
169 72
170 return 0; 73 return 0;
171}; 74}
172 75
173static void dio24_detach(struct comedi_device *dev) 76static void dio24_detach(struct comedi_device *dev)
174{ 77{
175 struct comedi_subdevice *s; 78 if (dev->subdevices)
176 79 subdev_8255_cleanup(dev, &dev->subdevices[0]);
177 if (dev->subdevices) { 80 comedi_pcmcia_disable(dev);
178 s = &dev->subdevices[0]; 81}
179 subdev_8255_cleanup(dev, s);
180 }
181 if (thisboard->bustype != pcmcia_bustype && dev->iobase)
182 release_region(dev->iobase, DIO24_SIZE);
183 if (dev->irq)
184 free_irq(dev->irq, dev);
185};
186
187static void dio24_config(struct pcmcia_device *link);
188static void dio24_release(struct pcmcia_device *link);
189static int dio24_cs_suspend(struct pcmcia_device *p_dev);
190static int dio24_cs_resume(struct pcmcia_device *p_dev);
191
192static int dio24_cs_attach(struct pcmcia_device *);
193static void dio24_cs_detach(struct pcmcia_device *);
194 82
195struct local_info_t { 83static struct comedi_driver driver_dio24 = {
196 struct pcmcia_device *link; 84 .driver_name = "ni_daq_dio24",
197 int stop; 85 .module = THIS_MODULE,
198 struct bus_operations *bus; 86 .auto_attach = dio24_auto_attach,
87 .detach = dio24_detach,
199}; 88};
200 89
201static int dio24_cs_attach(struct pcmcia_device *link) 90static int dio24_cs_attach(struct pcmcia_device *link)
202{ 91{
203 struct local_info_t *local; 92 return comedi_pcmcia_auto_config(link, &driver_dio24);
204
205 dev_info(&link->dev, "ni_daq_dio24: HOLA SOY YO - CS-attach!\n");
206
207 dev_dbg(&link->dev, "dio24_cs_attach()\n");
208
209 /* Allocate space for private device-specific data */
210 local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL);
211 if (!local)
212 return -ENOMEM;
213 local->link = link;
214 link->priv = local;
215
216 pcmcia_cur_dev = link;
217
218 dio24_config(link);
219
220 return 0;
221} /* dio24_cs_attach */
222
223static void dio24_cs_detach(struct pcmcia_device *link)
224{
225 ((struct local_info_t *)link->priv)->stop = 1;
226 dio24_release(link);
227
228 /* This points to the parent local_info_t struct */
229 kfree(link->priv);
230} 93}
231 94
232static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev,
233 void *priv_data)
234{
235 if (p_dev->config_index == 0)
236 return -EINVAL;
237
238 return pcmcia_request_io(p_dev);
239}
240
241static void dio24_config(struct pcmcia_device *link)
242{
243 int ret;
244
245 dev_info(&link->dev, "ni_daq_dio24: HOLA SOY YO! - config\n");
246
247 dev_dbg(&link->dev, "dio24_config\n");
248
249 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_AUDIO |
250 CONF_AUTO_SET_IO;
251
252 ret = pcmcia_loop_config(link, dio24_pcmcia_config_loop, NULL);
253 if (ret) {
254 dev_warn(&link->dev, "no configuration found\n");
255 goto failed;
256 }
257
258 if (!link->irq)
259 goto failed;
260
261 ret = pcmcia_enable_device(link);
262 if (ret)
263 goto failed;
264
265 return;
266
267failed:
268 dev_info(&link->dev, "Fallo");
269 dio24_release(link);
270
271} /* dio24_config */
272
273static void dio24_release(struct pcmcia_device *link)
274{
275 dev_dbg(&link->dev, "dio24_release\n");
276
277 pcmcia_disable_device(link);
278} /* dio24_release */
279
280static int dio24_cs_suspend(struct pcmcia_device *link)
281{
282 struct local_info_t *local = link->priv;
283
284 /* Mark the device as stopped, to block IO until later */
285 local->stop = 1;
286 return 0;
287} /* dio24_cs_suspend */
288
289static int dio24_cs_resume(struct pcmcia_device *link)
290{
291 struct local_info_t *local = link->priv;
292
293 local->stop = 0;
294 return 0;
295} /* dio24_cs_resume */
296
297/*====================================================================*/
298
299static const struct pcmcia_device_id dio24_cs_ids[] = { 95static const struct pcmcia_device_id dio24_cs_ids[] = {
300 /* N.B. These IDs should match those in dio24_boards */
301 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */ 96 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x475c), /* daqcard-dio24 */
302 PCMCIA_DEVICE_NULL 97 PCMCIA_DEVICE_NULL
303}; 98};
304
305MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids); 99MODULE_DEVICE_TABLE(pcmcia, dio24_cs_ids);
306MODULE_AUTHOR("Daniel Vecino Castel <dvecino@able.es>");
307MODULE_DESCRIPTION("Comedi driver for National Instruments "
308 "PCMCIA DAQ-Card DIO-24");
309MODULE_LICENSE("GPL");
310 100
311static struct pcmcia_driver dio24_cs_driver = { 101static struct pcmcia_driver dio24_cs_driver = {
312 .probe = dio24_cs_attach, 102 .name = "ni_daq_dio24",
313 .remove = dio24_cs_detach, 103 .owner = THIS_MODULE,
314 .suspend = dio24_cs_suspend, 104 .id_table = dio24_cs_ids,
315 .resume = dio24_cs_resume, 105 .probe = dio24_cs_attach,
316 .id_table = dio24_cs_ids, 106 .remove = comedi_pcmcia_auto_unconfig,
317 .owner = THIS_MODULE,
318 .name = "ni_daq_dio24",
319}; 107};
108module_comedi_pcmcia_driver(driver_dio24, dio24_cs_driver);
320 109
321static int __init init_dio24_cs(void) 110MODULE_AUTHOR("Daniel Vecino Castel <dvecino@able.es>");
322{ 111MODULE_DESCRIPTION(
323 printk("ni_daq_dio24: HOLA SOY YO!\n"); 112 "Comedi driver for National Instruments PCMCIA DAQ-Card DIO-24");
324 pcmcia_register_driver(&dio24_cs_driver); 113MODULE_LICENSE("GPL");
325 return 0;
326}
327
328static void __exit exit_dio24_cs(void)
329{
330 pcmcia_unregister_driver(&dio24_cs_driver);
331}
332
333int __init init_module(void)
334{
335 int ret;
336
337 ret = init_dio24_cs();
338 if (ret < 0)
339 return ret;
340
341 return comedi_driver_register(&driver_dio24);
342}
343
344void __exit cleanup_module(void)
345{
346 exit_dio24_cs();
347 comedi_driver_unregister(&driver_dio24);
348}
diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c
index d29c4d761bac..f957b8859b3d 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.c
+++ b/drivers/staging/comedi/drivers/ni_labpc.c
@@ -73,12 +73,14 @@ NI manuals:
73 73
74*/ 74*/
75 75
76#include <linux/pci.h>
76#include <linux/interrupt.h> 77#include <linux/interrupt.h>
77#include <linux/slab.h> 78#include <linux/slab.h>
78#include <linux/io.h> 79#include <linux/io.h>
80#include <linux/delay.h>
81
79#include "../comedidev.h" 82#include "../comedidev.h"
80 83
81#include <linux/delay.h>
82#include <asm/dma.h> 84#include <asm/dma.h>
83 85
84#include "8253.h" 86#include "8253.h"
@@ -568,13 +570,11 @@ int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
568 return -EINVAL; 570 return -EINVAL;
569 } else if (dma_chan) { 571 } else if (dma_chan) {
570 /* allocate dma buffer */ 572 /* allocate dma buffer */
571 devpriv->dma_buffer = 573 devpriv->dma_buffer = kmalloc(dma_buffer_size,
572 kmalloc(dma_buffer_size, GFP_KERNEL | GFP_DMA); 574 GFP_KERNEL | GFP_DMA);
573 if (devpriv->dma_buffer == NULL) { 575 if (devpriv->dma_buffer == NULL)
574 dev_err(dev->class_dev,
575 "failed to allocate dma buffer\n");
576 return -ENOMEM; 576 return -ENOMEM;
577 } 577
578 if (request_dma(dma_chan, DRV_NAME)) { 578 if (request_dma(dma_chan, DRV_NAME)) {
579 dev_err(dev->class_dev, 579 dev_err(dev->class_dev,
580 "failed to allocate dma channel %u\n", 580 "failed to allocate dma channel %u\n",
@@ -1202,7 +1202,8 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1202 else 1202 else
1203 channel = CR_CHAN(cmd->chanlist[0]); 1203 channel = CR_CHAN(cmd->chanlist[0]);
1204 /* munge channel bits for differential / scan disabled mode */ 1204 /* munge channel bits for differential / scan disabled mode */
1205 if (mode != MODE_SINGLE_CHAN && aref == AREF_DIFF) 1205 if ((mode == MODE_SINGLE_CHAN || mode == MODE_SINGLE_CHAN_INTERVAL) &&
1206 aref == AREF_DIFF)
1206 channel *= 2; 1207 channel *= 2;
1207 devpriv->command1_bits |= ADC_CHAN_BITS(channel); 1208 devpriv->command1_bits |= ADC_CHAN_BITS(channel);
1208 devpriv->command1_bits |= thisboard->ai_range_code[range]; 1209 devpriv->command1_bits |= thisboard->ai_range_code[range];
@@ -1217,21 +1218,6 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1217 devpriv->write_byte(devpriv->command1_bits, 1218 devpriv->write_byte(devpriv->command1_bits,
1218 dev->iobase + COMMAND1_REG); 1219 dev->iobase + COMMAND1_REG);
1219 } 1220 }
1220 /* setup any external triggering/pacing (command4 register) */
1221 devpriv->command4_bits = 0;
1222 if (cmd->convert_src != TRIG_EXT)
1223 devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT;
1224 /* XXX should discard first scan when using interval scanning
1225 * since manual says it is not synced with scan clock */
1226 if (labpc_use_continuous_mode(cmd, mode) == 0) {
1227 devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT;
1228 if (cmd->scan_begin_src == TRIG_EXT)
1229 devpriv->command4_bits |= EXT_SCAN_EN_BIT;
1230 }
1231 /* single-ended/differential */
1232 if (aref == AREF_DIFF)
1233 devpriv->command4_bits |= ADC_DIFF_BIT;
1234 devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG);
1235 1221
1236 devpriv->write_byte(cmd->chanlist_len, 1222 devpriv->write_byte(cmd->chanlist_len,
1237 dev->iobase + INTERVAL_COUNT_REG); 1223 dev->iobase + INTERVAL_COUNT_REG);
@@ -1311,6 +1297,22 @@ static int labpc_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1311 devpriv->command3_bits &= ~ADC_FNE_INTR_EN_BIT; 1297 devpriv->command3_bits &= ~ADC_FNE_INTR_EN_BIT;
1312 devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG); 1298 devpriv->write_byte(devpriv->command3_bits, dev->iobase + COMMAND3_REG);
1313 1299
1300 /* setup any external triggering/pacing (command4 register) */
1301 devpriv->command4_bits = 0;
1302 if (cmd->convert_src != TRIG_EXT)
1303 devpriv->command4_bits |= EXT_CONVERT_DISABLE_BIT;
1304 /* XXX should discard first scan when using interval scanning
1305 * since manual says it is not synced with scan clock */
1306 if (labpc_use_continuous_mode(cmd, mode) == 0) {
1307 devpriv->command4_bits |= INTERVAL_SCAN_EN_BIT;
1308 if (cmd->scan_begin_src == TRIG_EXT)
1309 devpriv->command4_bits |= EXT_SCAN_EN_BIT;
1310 }
1311 /* single-ended/differential */
1312 if (aref == AREF_DIFF)
1313 devpriv->command4_bits |= ADC_DIFF_BIT;
1314 devpriv->write_byte(devpriv->command4_bits, dev->iobase + COMMAND4_REG);
1315
1314 /* startup acquisition */ 1316 /* startup acquisition */
1315 1317
1316 /* command2 reg */ 1318 /* command2 reg */
@@ -2116,16 +2118,11 @@ static int labpc_pci_probe(struct pci_dev *dev,
2116 return comedi_pci_auto_config(dev, &labpc_driver); 2118 return comedi_pci_auto_config(dev, &labpc_driver);
2117} 2119}
2118 2120
2119static void labpc_pci_remove(struct pci_dev *dev)
2120{
2121 comedi_pci_auto_unconfig(dev);
2122}
2123
2124static struct pci_driver labpc_pci_driver = { 2121static struct pci_driver labpc_pci_driver = {
2125 .name = DRV_NAME, 2122 .name = DRV_NAME,
2126 .id_table = labpc_pci_table, 2123 .id_table = labpc_pci_table,
2127 .probe = labpc_pci_probe, 2124 .probe = labpc_pci_probe,
2128 .remove = labpc_pci_remove 2125 .remove = comedi_pci_auto_unconfig,
2129}; 2126};
2130module_comedi_pci_driver(labpc_driver, labpc_pci_driver); 2127module_comedi_pci_driver(labpc_driver, labpc_pci_driver);
2131#else 2128#else
diff --git a/drivers/staging/comedi/drivers/ni_labpc_cs.c b/drivers/staging/comedi/drivers/ni_labpc_cs.c
index bfe19fa7d66f..be7d1413b2e5 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_cs.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_cs.c
@@ -59,8 +59,6 @@ NI manuals:
59 59
60*/ 60*/
61 61
62#undef LABPC_DEBUG /* debugging messages */
63
64#include "../comedidev.h" 62#include "../comedidev.h"
65 63
66#include <linux/delay.h> 64#include <linux/delay.h>
@@ -75,240 +73,81 @@ NI manuals:
75#include <pcmcia/cisreg.h> 73#include <pcmcia/cisreg.h>
76#include <pcmcia/ds.h> 74#include <pcmcia/ds.h>
77 75
78static struct pcmcia_device *pcmcia_cur_dev;
79
80static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it);
81
82static const struct labpc_board_struct labpc_cs_boards[] = { 76static const struct labpc_board_struct labpc_cs_boards[] = {
83 { 77 {
84 .name = "daqcard-1200", 78 .name = "daqcard-1200",
85 .device_id = 0x103, /* 0x10b is manufacturer id, 79 .device_id = 0x103,
86 0x103 is device id */ 80 .ai_speed = 10000,
87 .ai_speed = 10000, 81 .bustype = pcmcia_bustype,
88 .bustype = pcmcia_bustype, 82 .register_layout = labpc_1200_layout,
89 .register_layout = labpc_1200_layout, 83 .has_ao = 1,
90 .has_ao = 1, 84 .ai_range_table = &range_labpc_1200_ai,
91 .ai_range_table = &range_labpc_1200_ai, 85 .ai_range_code = labpc_1200_ai_gain_bits,
92 .ai_range_code = labpc_1200_ai_gain_bits, 86 .ai_range_is_unipolar = labpc_1200_is_unipolar,
93 .ai_range_is_unipolar = labpc_1200_is_unipolar, 87 },
94 .ai_scan_up = 0,
95 .memory_mapped_io = 0,
96 },
97 /* duplicate entry, to support using alternate name */
98 {
99 .name = "ni_labpc_cs",
100 .device_id = 0x103,
101 .ai_speed = 10000,
102 .bustype = pcmcia_bustype,
103 .register_layout = labpc_1200_layout,
104 .has_ao = 1,
105 .ai_range_table = &range_labpc_1200_ai,
106 .ai_range_code = labpc_1200_ai_gain_bits,
107 .ai_range_is_unipolar = labpc_1200_is_unipolar,
108 .ai_scan_up = 0,
109 .memory_mapped_io = 0,
110 },
111}; 88};
112 89
113/* 90static int labpc_auto_attach(struct comedi_device *dev,
114 * Useful for shorthand access to the particular board structure 91 unsigned long context)
115 */
116#define thisboard ((const struct labpc_board_struct *)dev->board_ptr)
117
118static struct comedi_driver driver_labpc_cs = {
119 .driver_name = "ni_labpc_cs",
120 .module = THIS_MODULE,
121 .attach = &labpc_attach,
122 .detach = &labpc_common_detach,
123 .num_names = ARRAY_SIZE(labpc_cs_boards),
124 .board_name = &labpc_cs_boards[0].name,
125 .offset = sizeof(struct labpc_board_struct),
126};
127
128static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
129{ 92{
93 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
130 struct labpc_private *devpriv; 94 struct labpc_private *devpriv;
131 unsigned long iobase = 0; 95 int ret;
132 unsigned int irq = 0; 96
133 struct pcmcia_device *link; 97 /* The ni_labpc driver needs the board_ptr */
98 dev->board_ptr = &labpc_cs_boards[0];
99
100 link->config_flags |= CONF_AUTO_SET_IO |
101 CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;
102 ret = comedi_pcmcia_enable(dev, NULL);
103 if (ret)
104 return ret;
105 dev->iobase = link->resource[0]->start;
106
107 if (!link->irq)
108 return -EINVAL;
134 109
135 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); 110 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
136 if (!devpriv) 111 if (!devpriv)
137 return -ENOMEM; 112 return -ENOMEM;
138 dev->private = devpriv; 113 dev->private = devpriv;
139 114
140 /* get base address, irq etc. based on bustype */ 115 return labpc_common_attach(dev, dev->iobase, link->irq, 0);
141 switch (thisboard->bustype) {
142 case pcmcia_bustype:
143 link = pcmcia_cur_dev; /* XXX hack */
144 if (!link)
145 return -EIO;
146 iobase = link->resource[0]->start;
147 irq = link->irq;
148 break;
149 default:
150 pr_err("bug! couldn't determine board type\n");
151 return -EINVAL;
152 break;
153 }
154 return labpc_common_attach(dev, iobase, irq, 0);
155} 116}
156 117
157static void labpc_config(struct pcmcia_device *link); 118static void labpc_detach(struct comedi_device *dev)
158static void labpc_release(struct pcmcia_device *link); 119{
159static int labpc_cs_suspend(struct pcmcia_device *p_dev); 120 labpc_common_detach(dev);
160static int labpc_cs_resume(struct pcmcia_device *p_dev); 121 comedi_pcmcia_disable(dev);
161 122}
162static int labpc_cs_attach(struct pcmcia_device *);
163static void labpc_cs_detach(struct pcmcia_device *);
164 123
165struct local_info_t { 124static struct comedi_driver driver_labpc_cs = {
166 struct pcmcia_device *link; 125 .driver_name = "ni_labpc_cs",
167 int stop; 126 .module = THIS_MODULE,
168 struct bus_operations *bus; 127 .auto_attach = labpc_auto_attach,
128 .detach = labpc_detach,
169}; 129};
170 130
171static int labpc_cs_attach(struct pcmcia_device *link) 131static int labpc_cs_attach(struct pcmcia_device *link)
172{ 132{
173 struct local_info_t *local; 133 return comedi_pcmcia_auto_config(link, &driver_labpc_cs);
174
175 dev_dbg(&link->dev, "labpc_cs_attach()\n");
176
177 /* Allocate space for private device-specific data */
178 local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL);
179 if (!local)
180 return -ENOMEM;
181 local->link = link;
182 link->priv = local;
183
184 pcmcia_cur_dev = link;
185
186 labpc_config(link);
187
188 return 0;
189} /* labpc_cs_attach */
190
191static void labpc_cs_detach(struct pcmcia_device *link)
192{
193 ((struct local_info_t *)link->priv)->stop = 1;
194 labpc_release(link);
195
196 /* This points to the parent local_info_t struct (may be null) */
197 kfree(link->priv);
198
199} 134}
200 135
201static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev,
202 void *priv_data)
203{
204 if (p_dev->config_index == 0)
205 return -EINVAL;
206
207 return pcmcia_request_io(p_dev);
208}
209
210
211static void labpc_config(struct pcmcia_device *link)
212{
213 int ret;
214
215 dev_dbg(&link->dev, "labpc_config\n");
216
217 link->config_flags |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ |
218 CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
219
220 ret = pcmcia_loop_config(link, labpc_pcmcia_config_loop, NULL);
221 if (ret) {
222 dev_warn(&link->dev, "no configuration found\n");
223 goto failed;
224 }
225
226 if (!link->irq)
227 goto failed;
228
229 ret = pcmcia_enable_device(link);
230 if (ret)
231 goto failed;
232
233 return;
234
235failed:
236 labpc_release(link);
237
238} /* labpc_config */
239
240static void labpc_release(struct pcmcia_device *link)
241{
242 dev_dbg(&link->dev, "labpc_release\n");
243
244 pcmcia_disable_device(link);
245} /* labpc_release */
246
247static int labpc_cs_suspend(struct pcmcia_device *link)
248{
249 struct local_info_t *local = link->priv;
250
251 /* Mark the device as stopped, to block IO until later */
252 local->stop = 1;
253 return 0;
254} /* labpc_cs_suspend */
255
256static int labpc_cs_resume(struct pcmcia_device *link)
257{
258 struct local_info_t *local = link->priv;
259
260 local->stop = 0;
261 return 0;
262} /* labpc_cs_resume */
263
264static const struct pcmcia_device_id labpc_cs_ids[] = { 136static const struct pcmcia_device_id labpc_cs_ids[] = {
265 /* N.B. These IDs should match those in labpc_cs_boards (ni_labpc.c) */
266 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */ 137 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0103), /* daqcard-1200 */
267 PCMCIA_DEVICE_NULL 138 PCMCIA_DEVICE_NULL
268}; 139};
269
270MODULE_DEVICE_TABLE(pcmcia, labpc_cs_ids); 140MODULE_DEVICE_TABLE(pcmcia, labpc_cs_ids);
271MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
272MODULE_DESCRIPTION("Comedi driver for National Instruments Lab-PC");
273MODULE_LICENSE("GPL");
274 141
275static struct pcmcia_driver labpc_cs_driver = { 142static struct pcmcia_driver labpc_cs_driver = {
276 .probe = labpc_cs_attach, 143 .name = "daqcard-1200",
277 .remove = labpc_cs_detach, 144 .owner = THIS_MODULE,
278 .suspend = labpc_cs_suspend, 145 .id_table = labpc_cs_ids,
279 .resume = labpc_cs_resume, 146 .probe = labpc_cs_attach,
280 .id_table = labpc_cs_ids, 147 .remove = comedi_pcmcia_auto_unconfig,
281 .owner = THIS_MODULE,
282 .name = "daqcard-1200",
283}; 148};
149module_comedi_pcmcia_driver(driver_labpc_cs, labpc_cs_driver);
284 150
285static int __init init_labpc_cs(void) 151MODULE_DESCRIPTION("Comedi driver for National Instruments Lab-PC");
286{ 152MODULE_AUTHOR("Frank Mori Hess <fmhess@users.sourceforge.net>");
287 pcmcia_register_driver(&labpc_cs_driver); 153MODULE_LICENSE("GPL");
288 return 0;
289}
290
291static void __exit exit_labpc_cs(void)
292{
293 pcmcia_unregister_driver(&labpc_cs_driver);
294}
295
296static int __init labpc_init_module(void)
297{
298 int ret;
299
300 ret = init_labpc_cs();
301 if (ret < 0)
302 return ret;
303
304 return comedi_driver_register(&driver_labpc_cs);
305}
306
307static void __exit labpc_exit_module(void)
308{
309 exit_labpc_cs();
310 comedi_driver_unregister(&driver_labpc_cs);
311}
312
313module_init(labpc_init_module);
314module_exit(labpc_exit_module);
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index 56dc59908d36..b7403597e905 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -986,7 +986,7 @@ static void ni_event(struct comedi_device *dev, struct comedi_subdevice *s)
986 if (s-> 986 if (s->
987 async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW | 987 async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW |
988 COMEDI_CB_EOA)) { 988 COMEDI_CB_EOA)) {
989 switch (s - dev->subdevices) { 989 switch (s->index) {
990 case NI_AI_SUBDEV: 990 case NI_AI_SUBDEV:
991 ni_ai_reset(dev, s); 991 ni_ai_reset(dev, s);
992 break; 992 break;
@@ -1086,7 +1086,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status,
1086 ("ni_mio_common: a_status=0xffff. Card removed?\n"); 1086 ("ni_mio_common: a_status=0xffff. Card removed?\n");
1087 /* we probably aren't even running a command now, 1087 /* we probably aren't even running a command now,
1088 * so it's a good idea to be careful. */ 1088 * so it's a good idea to be careful. */
1089 if (comedi_get_subdevice_runflags(s) & SRF_RUNNING) { 1089 if (comedi_is_subdevice_running(s)) {
1090 s->async->events |= 1090 s->async->events |=
1091 COMEDI_CB_ERROR | COMEDI_CB_EOA; 1091 COMEDI_CB_ERROR | COMEDI_CB_EOA;
1092 ni_event(dev, s); 1092 ni_event(dev, s);
diff --git a/drivers/staging/comedi/drivers/ni_mio_cs.c b/drivers/staging/comedi/drivers/ni_mio_cs.c
index 76c6a13ea9d6..888be7b89d2d 100644
--- a/drivers/staging/comedi/drivers/ni_mio_cs.c
+++ b/drivers/staging/comedi/drivers/ni_mio_cs.c
@@ -65,112 +65,90 @@ See the notes in the ni_atmio.o driver.
65#define MAX_N_CALDACS 32 65#define MAX_N_CALDACS 32
66 66
67static const struct ni_board_struct ni_boards[] = { 67static const struct ni_board_struct ni_boards[] = {
68 {.device_id = 0x010d, 68 {
69 .name = "DAQCard-ai-16xe-50", 69 .device_id = 0x010d,
70 .n_adchan = 16, 70 .name = "DAQCard-ai-16xe-50",
71 .adbits = 16, 71 .n_adchan = 16,
72 .ai_fifo_depth = 1024, 72 .adbits = 16,
73 .alwaysdither = 0, 73 .ai_fifo_depth = 1024,
74 .gainlkup = ai_gain_8, 74 .gainlkup = ai_gain_8,
75 .ai_speed = 5000, 75 .ai_speed = 5000,
76 .n_aochan = 0, 76 .num_p0_dio_channels = 8,
77 .aobits = 0, 77 .caldac = { dac8800, dac8043 },
78 .ao_fifo_depth = 0, 78 }, {
79 .ao_unipolar = 0, 79 .device_id = 0x010c,
80 .num_p0_dio_channels = 8, 80 .name = "DAQCard-ai-16e-4",
81 .has_8255 = 0, 81 .n_adchan = 16,
82 .caldac = {dac8800, dac8043}, 82 .adbits = 12,
83 }, 83 .ai_fifo_depth = 1024,
84 {.device_id = 0x010c, 84 .gainlkup = ai_gain_16,
85 .name = "DAQCard-ai-16e-4", 85 .ai_speed = 4000,
86 .n_adchan = 16, 86 .num_p0_dio_channels = 8,
87 .adbits = 12, 87 .caldac = { mb88341 }, /* verified */
88 .ai_fifo_depth = 1024, 88 }, {
89 .alwaysdither = 0, 89 .device_id = 0x02c4,
90 .gainlkup = ai_gain_16, 90 .name = "DAQCard-6062E",
91 .ai_speed = 4000, 91 .n_adchan = 16,
92 .n_aochan = 0, 92 .adbits = 12,
93 .aobits = 0, 93 .ai_fifo_depth = 8192,
94 .ao_fifo_depth = 0, 94 .gainlkup = ai_gain_16,
95 .ao_unipolar = 0, 95 .ai_speed = 2000,
96 .num_p0_dio_channels = 8, 96 .n_aochan = 2,
97 .has_8255 = 0, 97 .aobits = 12,
98 .caldac = {mb88341}, /* verified */ 98 .ao_fifo_depth = 2048,
99 }, 99 .ao_range_table = &range_bipolar10,
100 {.device_id = 0x02c4, 100 .ao_speed = 1176,
101 .name = "DAQCard-6062E", 101 .num_p0_dio_channels = 8,
102 .n_adchan = 16, 102 .caldac = { ad8804_debug }, /* verified */
103 .adbits = 12, 103 }, {
104 .ai_fifo_depth = 8192, 104 /* specs incorrect! */
105 .alwaysdither = 0, 105 .device_id = 0x075e,
106 .gainlkup = ai_gain_16, 106 .name = "DAQCard-6024E",
107 .ai_speed = 2000, 107 .n_adchan = 16,
108 .n_aochan = 2, 108 .adbits = 12,
109 .aobits = 12, 109 .ai_fifo_depth = 1024,
110 .ao_fifo_depth = 2048, 110 .gainlkup = ai_gain_4,
111 .ao_range_table = &range_bipolar10, 111 .ai_speed = 5000,
112 .ao_unipolar = 0, 112 .n_aochan = 2,
113 .ao_speed = 1176, 113 .aobits = 12,
114 .num_p0_dio_channels = 8, 114 .ao_range_table = &range_bipolar10,
115 .has_8255 = 0, 115 .ao_speed = 1000000,
116 .caldac = {ad8804_debug}, /* verified */ 116 .num_p0_dio_channels = 8,
117 }, 117 .caldac = { ad8804_debug },
118 {.device_id = 0x075e, 118 }, {
119 .name = "DAQCard-6024E", /* specs incorrect! */ 119 /* specs incorrect! */
120 .n_adchan = 16, 120 .device_id = 0x0245,
121 .adbits = 12, 121 .name = "DAQCard-6036E",
122 .ai_fifo_depth = 1024, 122 .n_adchan = 16,
123 .alwaysdither = 0, 123 .adbits = 16,
124 .gainlkup = ai_gain_4, 124 .ai_fifo_depth = 1024,
125 .ai_speed = 5000, 125 .alwaysdither = 1,
126 .n_aochan = 2, 126 .gainlkup = ai_gain_4,
127 .aobits = 12, 127 .ai_speed = 5000,
128 .ao_fifo_depth = 0, 128 .n_aochan = 2,
129 .ao_range_table = &range_bipolar10, 129 .aobits = 16,
130 .ao_unipolar = 0, 130 .ao_range_table = &range_bipolar10,
131 .ao_speed = 1000000, 131 .ao_speed = 1000000,
132 .num_p0_dio_channels = 8, 132 .num_p0_dio_channels = 8,
133 .has_8255 = 0, 133 .caldac = { ad8804_debug },
134 .caldac = {ad8804_debug},
135 },
136 {.device_id = 0x0245,
137 .name = "DAQCard-6036E", /* specs incorrect! */
138 .n_adchan = 16,
139 .adbits = 16,
140 .ai_fifo_depth = 1024,
141 .alwaysdither = 1,
142 .gainlkup = ai_gain_4,
143 .ai_speed = 5000,
144 .n_aochan = 2,
145 .aobits = 16,
146 .ao_fifo_depth = 0,
147 .ao_range_table = &range_bipolar10,
148 .ao_unipolar = 0,
149 .ao_speed = 1000000,
150 .num_p0_dio_channels = 8,
151 .has_8255 = 0,
152 .caldac = {ad8804_debug},
153 }, 134 },
154#if 0 135#if 0
155 {.device_id = 0x0000, /* unknown */ 136 {
156 .name = "DAQCard-6715", 137 .device_id = 0x0000, /* unknown */
157 .n_adchan = 0, 138 .name = "DAQCard-6715",
158 .n_aochan = 8, 139 .n_aochan = 8,
159 .aobits = 12, 140 .aobits = 12,
160 .ao_671x = 8192, 141 .ao_671x = 8192,
161 .num_p0_dio_channels = 8, 142 .num_p0_dio_channels = 8,
162 .caldac = {mb88341, mb88341}, 143 .caldac = { mb88341, mb88341 },
163 }, 144 },
164#endif 145#endif
165 /* N.B. Update ni_mio_cs_ids[] when entries added above. */
166}; 146};
167 147
168#define interrupt_pin(a) 0 148#define interrupt_pin(a) 0
169 149
170#define IRQ_POLARITY 1 150#define IRQ_POLARITY 1
171 151
172#define NI_E_IRQ_FLAGS IRQF_SHARED
173
174struct ni_private { 152struct ni_private {
175 153
176 struct pcmcia_device *link; 154 struct pcmcia_device *link;
@@ -225,67 +203,22 @@ static uint16_t mio_cs_win_in(struct comedi_device *dev, int addr)
225 return ret; 203 return ret;
226} 204}
227 205
228static int mio_cs_attach(struct comedi_device *dev,
229 struct comedi_devconfig *it);
230static void mio_cs_detach(struct comedi_device *dev);
231static struct comedi_driver driver_ni_mio_cs = {
232 .driver_name = "ni_mio_cs",
233 .module = THIS_MODULE,
234 .attach = mio_cs_attach,
235 .detach = mio_cs_detach,
236};
237
238#include "ni_mio_common.c" 206#include "ni_mio_common.c"
239 207
240static int ni_getboardtype(struct comedi_device *dev, 208static const void *ni_getboardtype(struct comedi_device *dev,
241 struct pcmcia_device *link); 209 struct pcmcia_device *link)
242
243static void mio_cs_detach(struct comedi_device *dev)
244{
245 mio_common_detach(dev);
246 if (dev->irq)
247 free_irq(dev->irq, dev);
248}
249
250static void mio_cs_config(struct pcmcia_device *link);
251static void cs_release(struct pcmcia_device *link);
252static void cs_detach(struct pcmcia_device *);
253
254static struct pcmcia_device *cur_dev;
255
256static int cs_attach(struct pcmcia_device *link)
257{ 210{
258 cur_dev = link; 211 static const struct ni_board_struct *board;
259 212 int i;
260 mio_cs_config(link);
261
262 return 0;
263}
264
265static void cs_release(struct pcmcia_device *link)
266{
267 pcmcia_disable_device(link);
268}
269
270static void cs_detach(struct pcmcia_device *link)
271{
272 cs_release(link);
273}
274
275static int mio_cs_suspend(struct pcmcia_device *link)
276{
277 DPRINTK("pm suspend\n");
278
279 return 0;
280}
281 213
282static int mio_cs_resume(struct pcmcia_device *link) 214 for (i = 0; i < ARRAY_SIZE(ni_boards); i++) {
283{ 215 board = &ni_boards[i];
284 DPRINTK("pm resume\n"); 216 if (board->device_id == link->card_id)
285 return 0; 217 return board;
218 }
219 return NULL;
286} 220}
287 221
288
289static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) 222static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
290{ 223{
291 int base, ret; 224 int base, ret;
@@ -302,114 +235,63 @@ static int mio_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data)
302 return -ENODEV; 235 return -ENODEV;
303} 236}
304 237
305 238static int mio_cs_auto_attach(struct comedi_device *dev,
306static void mio_cs_config(struct pcmcia_device *link) 239 unsigned long context)
307{
308 int ret;
309
310 DPRINTK("mio_cs_config(link=%p)\n", link);
311 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
312
313 ret = pcmcia_loop_config(link, mio_pcmcia_config_loop, NULL);
314 if (ret) {
315 dev_warn(&link->dev, "no configuration found\n");
316 return;
317 }
318
319 if (!link->irq)
320 dev_info(&link->dev, "no IRQ available\n");
321
322 ret = pcmcia_enable_device(link);
323}
324
325static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it)
326{ 240{
241 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
242 static const struct ni_board_struct *board;
327 struct ni_private *devpriv; 243 struct ni_private *devpriv;
328 struct pcmcia_device *link;
329 unsigned int irq;
330 int ret; 244 int ret;
331 245
332 DPRINTK("mio_cs_attach(dev=%p,it=%p)\n", dev, it); 246 board = ni_getboardtype(dev, link);
333 247 if (!board)
334 link = cur_dev; /* XXX hack */ 248 return -ENODEV;
335 if (!link) 249 dev->board_ptr = board;
336 return -EIO; 250 dev->board_name = board->name;
337 251
338 dev->driver = &driver_ni_mio_cs; 252 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
253 ret = comedi_pcmcia_enable(dev, mio_pcmcia_config_loop);
254 if (ret)
255 return ret;
339 dev->iobase = link->resource[0]->start; 256 dev->iobase = link->resource[0]->start;
340 257
341 irq = link->irq; 258 link->priv = dev;
342 259 ret = pcmcia_request_irq(link, ni_E_interrupt);
343 dev->board_ptr = ni_boards + ni_getboardtype(dev, link); 260 if (ret)
344 261 return ret;
345#if 0 262 dev->irq = link->irq;
346 {
347 int i;
348
349 printk("comedi%d: %s: DAQCard: io 0x%04lx, irq %u, ",
350 dev->minor, dev->driver->driver_name, dev->iobase, irq);
351
352 printk(" board fingerprint:");
353 for (i = 0; i < 32; i += 2) {
354 printk(" %04x %02x", inw(dev->iobase + i),
355 inb(dev->iobase + i + 1));
356 }
357 printk("\n");
358 printk(" board fingerprint (windowed):");
359 for (i = 0; i < 10; i++)
360 printk(" 0x%04x", win_in(i));
361 printk("\n");
362
363 printk("boardtype.name: %s\n", boardtype.name);
364 }
365#endif
366
367 dev->board_name = boardtype.name;
368
369 ret = request_irq(irq, ni_E_interrupt, NI_E_IRQ_FLAGS,
370 "ni_mio_cs", dev);
371 if (ret < 0) {
372 dev_err(dev->class_dev, "irq not available\n");
373 return -EINVAL;
374 }
375 dev->irq = irq;
376 263
377 ret = ni_alloc_private(dev); 264 ret = ni_alloc_private(dev);
378 if (ret) 265 if (ret)
379 return ret; 266 return ret;
380 devpriv = dev->private;
381
382 devpriv->stc_writew = &mio_cs_win_out;
383 devpriv->stc_readw = &mio_cs_win_in;
384 devpriv->stc_writel = &win_out2;
385 devpriv->stc_readl = &win_in2;
386
387 ret = ni_E_init(dev);
388 267
389 if (ret < 0) 268 devpriv = dev->private;
390 return ret; 269 devpriv->stc_writew = mio_cs_win_out;
270 devpriv->stc_readw = mio_cs_win_in;
271 devpriv->stc_writel = win_out2;
272 devpriv->stc_readl = win_in2;
391 273
392 return 0; 274 return ni_E_init(dev);
393} 275}
394 276
395static int ni_getboardtype(struct comedi_device *dev, 277static void mio_cs_detach(struct comedi_device *dev)
396 struct pcmcia_device *link)
397{ 278{
398 int i; 279 mio_common_detach(dev);
399 280 comedi_pcmcia_disable(dev);
400 for (i = 0; i < n_ni_boards; i++) { 281}
401 if (ni_boards[i].device_id == link->card_id)
402 return i;
403 }
404 282
405 dev_err(dev->class_dev, 283static struct comedi_driver driver_ni_mio_cs = {
406 "unknown board 0x%04x -- pretend it is a ", link->card_id); 284 .driver_name = "ni_mio_cs",
285 .module = THIS_MODULE,
286 .auto_attach = mio_cs_auto_attach,
287 .detach = mio_cs_detach,
288};
407 289
408 return 0; 290static int cs_attach(struct pcmcia_device *link)
291{
292 return comedi_pcmcia_auto_config(link, &driver_ni_mio_cs);
409} 293}
410 294
411#ifdef MODULE
412
413static const struct pcmcia_device_id ni_mio_cs_ids[] = { 295static const struct pcmcia_device_id ni_mio_cs_ids[] = {
414 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */ 296 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010d), /* DAQCard-ai-16xe-50 */
415 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */ 297 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x010c), /* DAQCard-ai-16e-4 */
@@ -418,36 +300,17 @@ static const struct pcmcia_device_id ni_mio_cs_ids[] = {
418 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */ 300 PCMCIA_DEVICE_MANF_CARD(0x010b, 0x0245), /* DAQCard-6036E */
419 PCMCIA_DEVICE_NULL 301 PCMCIA_DEVICE_NULL
420}; 302};
421
422MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids); 303MODULE_DEVICE_TABLE(pcmcia, ni_mio_cs_ids);
423MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
424MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
425MODULE_LICENSE("GPL");
426 304
427static struct pcmcia_driver ni_mio_cs_driver = { 305static struct pcmcia_driver ni_mio_cs_driver = {
428 .probe = &cs_attach, 306 .name = "ni_mio_cs",
429 .remove = &cs_detach, 307 .owner = THIS_MODULE,
430 .suspend = &mio_cs_suspend, 308 .id_table = ni_mio_cs_ids,
431 .resume = &mio_cs_resume, 309 .probe = cs_attach,
432 .id_table = ni_mio_cs_ids, 310 .remove = comedi_pcmcia_auto_unconfig,
433 .owner = THIS_MODULE,
434 .name = "ni_mio_cs",
435}; 311};
312module_comedi_pcmcia_driver(driver_ni_mio_cs, ni_mio_cs_driver);
436 313
437int init_module(void) 314MODULE_DESCRIPTION("Comedi driver for National Instruments DAQCard E series");
438{ 315MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
439 pcmcia_register_driver(&ni_mio_cs_driver); 316MODULE_LICENSE("GPL");
440 comedi_driver_register(&driver_ni_mio_cs);
441 return 0;
442}
443
444void cleanup_module(void)
445{
446 pcmcia_unregister_driver(&ni_mio_cs_driver);
447#if 0
448 while (cur_dev != NULL)
449 cs_detach(cur_dev->handle);
450#endif
451 comedi_driver_unregister(&driver_ni_mio_cs);
452}
453#endif
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index 084ebea33ab9..0a00260d11f3 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -55,9 +55,11 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org
55/* #define DEBUG 1 */ 55/* #define DEBUG 1 */
56/* #define DEBUG_FLAGS */ 56/* #define DEBUG_FLAGS */
57 57
58#include <linux/delay.h>
58#include <linux/interrupt.h> 59#include <linux/interrupt.h>
59#include <linux/sched.h> 60#include <linux/sched.h>
60#include <linux/firmware.h> 61#include <linux/firmware.h>
62
61#include "../comedidev.h" 63#include "../comedidev.h"
62 64
63#include "comedi_fc.h" 65#include "comedi_fc.h"
@@ -1224,11 +1226,6 @@ static int ni_pcidio_pci_probe(struct pci_dev *dev,
1224 return comedi_pci_auto_config(dev, &ni_pcidio_driver); 1226 return comedi_pci_auto_config(dev, &ni_pcidio_driver);
1225} 1227}
1226 1228
1227static void ni_pcidio_pci_remove(struct pci_dev *dev)
1228{
1229 comedi_pci_auto_unconfig(dev);
1230}
1231
1232static DEFINE_PCI_DEVICE_TABLE(ni_pcidio_pci_table) = { 1229static DEFINE_PCI_DEVICE_TABLE(ni_pcidio_pci_table) = {
1233 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1150) }, 1230 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1150) },
1234 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1320) }, 1231 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1320) },
@@ -1241,7 +1238,7 @@ static struct pci_driver ni_pcidio_pci_driver = {
1241 .name = "ni_pcidio", 1238 .name = "ni_pcidio",
1242 .id_table = ni_pcidio_pci_table, 1239 .id_table = ni_pcidio_pci_table,
1243 .probe = ni_pcidio_pci_probe, 1240 .probe = ni_pcidio_pci_probe,
1244 .remove = ni_pcidio_pci_remove, 1241 .remove = comedi_pci_auto_unconfig,
1245}; 1242};
1246module_comedi_pci_driver(ni_pcidio_driver, ni_pcidio_pci_driver); 1243module_comedi_pci_driver(ni_pcidio_driver, ni_pcidio_pci_driver);
1247 1244
diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index fd1662b4175d..98b43f2fc65d 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -110,10 +110,12 @@ Bugs:
110 110
111*/ 111*/
112 112
113#include <linux/delay.h>
114#include <linux/delay.h>
115
113#include "../comedidev.h" 116#include "../comedidev.h"
114 117
115#include <asm/byteorder.h> 118#include <asm/byteorder.h>
116#include <linux/delay.h>
117 119
118#include "ni_stc.h" 120#include "ni_stc.h"
119#include "mite.h" 121#include "mite.h"
@@ -1791,11 +1793,6 @@ static int ni_pcimio_pci_probe(struct pci_dev *dev,
1791 return comedi_pci_auto_config(dev, &ni_pcimio_driver); 1793 return comedi_pci_auto_config(dev, &ni_pcimio_driver);
1792} 1794}
1793 1795
1794static void ni_pcimio_pci_remove(struct pci_dev *dev)
1795{
1796 comedi_pci_auto_unconfig(dev);
1797}
1798
1799static DEFINE_PCI_DEVICE_TABLE(ni_pcimio_pci_table) = { 1796static DEFINE_PCI_DEVICE_TABLE(ni_pcimio_pci_table) = {
1800 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162) }, 1797 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x0162) },
1801 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170) }, 1798 { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1170) },
@@ -1858,7 +1855,7 @@ static struct pci_driver ni_pcimio_pci_driver = {
1858 .name = "ni_pcimio", 1855 .name = "ni_pcimio",
1859 .id_table = ni_pcimio_pci_table, 1856 .id_table = ni_pcimio_pci_table,
1860 .probe = ni_pcimio_pci_probe, 1857 .probe = ni_pcimio_pci_probe,
1861 .remove = ni_pcimio_pci_remove 1858 .remove = comedi_pci_auto_unconfig,
1862}; 1859};
1863module_comedi_pci_driver(ni_pcimio_driver, ni_pcimio_pci_driver); 1860module_comedi_pci_driver(ni_pcimio_driver, ni_pcimio_pci_driver);
1864 1861
diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c
index 98f87897e2a8..225287769dc1 100644
--- a/drivers/staging/comedi/drivers/ni_tio.c
+++ b/drivers/staging/comedi/drivers/ni_tio.c
@@ -276,7 +276,7 @@ static inline unsigned NI_660x_RTSI_Second_Gate_Select(unsigned n)
276} 276}
277 277
278static const unsigned int counter_status_mask = 278static const unsigned int counter_status_mask =
279 COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING; 279 COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING;
280 280
281static int __init ni_tio_init_module(void) 281static int __init ni_tio_init_module(void)
282{ 282{
diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c
index 0c991b99da13..13747f324936 100644
--- a/drivers/staging/comedi/drivers/ni_tiocmd.c
+++ b/drivers/staging/comedi/drivers/ni_tiocmd.c
@@ -159,6 +159,7 @@ static int ni_tio_input_cmd(struct ni_gpct *counter, struct comedi_async *async)
159 async->inttrig = NULL; 159 async->inttrig = NULL;
160 mite_dma_arm(counter->mite_chan); 160 mite_dma_arm(counter->mite_chan);
161 retval = ni_tio_arm(counter, 1, cmd->start_arg); 161 retval = ni_tio_arm(counter, 1, cmd->start_arg);
162 break;
162 case TRIG_OTHER: 163 case TRIG_OTHER:
163 async->inttrig = NULL; 164 async->inttrig = NULL;
164 mite_dma_arm(counter->mite_chan); 165 mite_dma_arm(counter->mite_chan);
diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c
index 06127a5f62a0..b5af22eb7c37 100644
--- a/drivers/staging/comedi/drivers/pcl818.c
+++ b/drivers/staging/comedi/drivers/pcl818.c
@@ -243,8 +243,8 @@ static const struct comedi_lrange range_pcl818l_h_ai = { 4, {
243}; 243};
244 244
245static const struct comedi_lrange range718_bipolar1 = { 1, {BIP_RANGE(1),} }; 245static const struct comedi_lrange range718_bipolar1 = { 1, {BIP_RANGE(1),} };
246static const struct comedi_lrange range718_bipolar0_5 = 246static const struct comedi_lrange range718_bipolar0_5 = {
247 { 1, {BIP_RANGE(0.5),} }; 247 1, {BIP_RANGE(0.5),} };
248static const struct comedi_lrange range718_unipolar2 = { 1, {UNI_RANGE(2),} }; 248static const struct comedi_lrange range718_unipolar2 = { 1, {UNI_RANGE(2),} };
249static const struct comedi_lrange range718_unipolar1 = { 1, {BIP_RANGE(1),} }; 249static const struct comedi_lrange range718_unipolar1 = { 1, {BIP_RANGE(1),} };
250 250
@@ -1005,17 +1005,14 @@ static int pcl818_ai_cmd_mode(int mode, struct comedi_device *dev,
1005 switch (devpriv->dma) { 1005 switch (devpriv->dma) {
1006 case 1: /* DMA */ 1006 case 1: /* DMA */
1007 case 3: 1007 case 3:
1008 if (devpriv->dma_rtc == 0) { 1008 if (devpriv->dma_rtc == 0)
1009 pcl818_ai_mode13dma_int(mode, dev, s); 1009 pcl818_ai_mode13dma_int(mode, dev, s);
1010 }
1011#ifdef unused 1010#ifdef unused
1012 else { 1011 else
1013 pcl818_ai_mode13dma_rtc(mode, dev, s); 1012 pcl818_ai_mode13dma_rtc(mode, dev, s);
1014 }
1015#else 1013#else
1016 else { 1014 else
1017 return -EINVAL; 1015 return -EINVAL;
1018 }
1019#endif 1016#endif
1020 break; 1017 break;
1021 case 0: 1018 case 0:
@@ -1069,7 +1066,7 @@ static int pcl818_ai_cmd_mode(int mode, struct comedi_device *dev,
1069*/ 1066*/
1070#ifdef PCL818_MODE13_AO 1067#ifdef PCL818_MODE13_AO
1071static int pcl818_ao_mode13(int mode, struct comedi_device *dev, 1068static int pcl818_ao_mode13(int mode, struct comedi_device *dev,
1072 struct comedi_subdevice *s, comedi_trig * it) 1069 struct comedi_subdevice *s, comedi_trig *it)
1073{ 1070{
1074 struct pcl818_private *devpriv = dev->private; 1071 struct pcl818_private *devpriv = dev->private;
1075 int divisor1 = 0, divisor2 = 0; 1072 int divisor1 = 0, divisor2 = 0;
@@ -1124,7 +1121,7 @@ static int pcl818_ao_mode13(int mode, struct comedi_device *dev,
1124 ANALOG OUTPUT MODE 1, 818 cards 1121 ANALOG OUTPUT MODE 1, 818 cards
1125*/ 1122*/
1126static int pcl818_ao_mode1(struct comedi_device *dev, 1123static int pcl818_ao_mode1(struct comedi_device *dev,
1127 struct comedi_subdevice *s, comedi_trig * it) 1124 struct comedi_subdevice *s, comedi_trig *it)
1128{ 1125{
1129 return pcl818_ao_mode13(1, dev, s, it); 1126 return pcl818_ao_mode13(1, dev, s, it);
1130} 1127}
@@ -1134,7 +1131,7 @@ static int pcl818_ao_mode1(struct comedi_device *dev,
1134 ANALOG OUTPUT MODE 3, 818 cards 1131 ANALOG OUTPUT MODE 3, 818 cards
1135*/ 1132*/
1136static int pcl818_ao_mode3(struct comedi_device *dev, 1133static int pcl818_ao_mode3(struct comedi_device *dev,
1137 struct comedi_subdevice *s, comedi_trig * it) 1134 struct comedi_subdevice *s, comedi_trig *it)
1138{ 1135{
1139 return pcl818_ao_mode13(3, dev, s, it); 1136 return pcl818_ao_mode13(3, dev, s, it);
1140} 1137}
diff --git a/drivers/staging/comedi/drivers/pcm_common.c b/drivers/staging/comedi/drivers/pcm_common.c
deleted file mode 100644
index 8a718aea6f3c..000000000000
--- a/drivers/staging/comedi/drivers/pcm_common.c
+++ /dev/null
@@ -1,63 +0,0 @@
1#include "../comedidev.h"
2
3#include "comedi_fc.h"
4#include "pcm_common.h"
5
6int comedi_pcm_cmdtest(struct comedi_device *dev,
7 struct comedi_subdevice *s, struct comedi_cmd *cmd)
8{
9 int err = 0;
10
11 /* Step 1 : check if triggers are trivially valid */
12
13 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
14 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
15 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
16 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
17 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
18
19 if (err)
20 return 1;
21
22 /* Step 2a : make sure trigger sources are unique */
23
24 err |= cfc_check_trigger_is_unique(cmd->start_src);
25 err |= cfc_check_trigger_is_unique(cmd->stop_src);
26
27 /* Step 2b : and mutually compatible */
28
29 if (err)
30 return 2;
31
32 /* Step 3: check if arguments are trivially valid */
33
34 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
35 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
36 err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
37 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
38
39 switch (cmd->stop_src) {
40 case TRIG_COUNT:
41 /* any count allowed */
42 break;
43 case TRIG_NONE:
44 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
45 break;
46 default:
47 break;
48 }
49
50 if (err)
51 return 3;
52
53 /* step 4: fix up any arguments */
54
55 /* if (err) return 4; */
56
57 return 0;
58}
59EXPORT_SYMBOL(comedi_pcm_cmdtest);
60
61MODULE_AUTHOR("Comedi http://www.comedi.org");
62MODULE_DESCRIPTION("Comedi low-level driver");
63MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/pcm_common.h b/drivers/staging/comedi/drivers/pcm_common.h
deleted file mode 100644
index cd4840c11444..000000000000
--- a/drivers/staging/comedi/drivers/pcm_common.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef _comedi_common_H
2#define _comedi_common_H
3
4extern int comedi_pcm_cmdtest(struct comedi_device *dev,
5 struct comedi_subdevice *s,
6 struct comedi_cmd *cmd);
7
8#endif
diff --git a/drivers/staging/comedi/drivers/pcmda12.c b/drivers/staging/comedi/drivers/pcmda12.c
index 0882dafaf57b..13f79f49748a 100644
--- a/drivers/staging/comedi/drivers/pcmda12.c
+++ b/drivers/staging/comedi/drivers/pcmda12.c
@@ -53,9 +53,6 @@ Configuration Options:
53 53
54#include "../comedidev.h" 54#include "../comedidev.h"
55 55
56#include <linux/pci.h> /* for PCI devices */
57
58#define SDEV_NO ((int)(s - dev->subdevices))
59#define CHANS 8 56#define CHANS 8
60#define IOSIZE 16 57#define IOSIZE 16
61#define LSB(x) ((unsigned char)((x) & 0xff)) 58#define LSB(x) ((unsigned char)((x) & 0xff))
diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c
index 7522bfb6db08..5fa1fe08eb97 100644
--- a/drivers/staging/comedi/drivers/pcmmio.c
+++ b/drivers/staging/comedi/drivers/pcmmio.c
@@ -78,9 +78,10 @@ Configuration Options:
78 78
79#include <linux/interrupt.h> 79#include <linux/interrupt.h>
80#include <linux/slab.h> 80#include <linux/slab.h>
81
81#include "../comedidev.h" 82#include "../comedidev.h"
82#include "pcm_common.h" 83
83#include <linux/pci.h> /* for PCI devices */ 84#include "comedi_fc.h"
84 85
85/* This stuff is all from pcmuio.c -- it refers to the DIO subdevices only */ 86/* This stuff is all from pcmuio.c -- it refers to the DIO subdevices only */
86#define CHANS_PER_PORT 8 87#define CHANS_PER_PORT 8
@@ -93,7 +94,6 @@ Configuration Options:
93#define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT) 94#define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT)
94#define MAX_DIO_CHANS (PORTS_PER_ASIC*1*CHANS_PER_PORT) 95#define MAX_DIO_CHANS (PORTS_PER_ASIC*1*CHANS_PER_PORT)
95#define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC) 96#define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC)
96#define SDEV_NO ((int)(s - dev->subdevices))
97#define CALC_N_DIO_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/) 97#define CALC_N_DIO_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/)
98/* IO Memory sizes */ 98/* IO Memory sizes */
99#define ASIC_IOSIZE (0x0B) 99#define ASIC_IOSIZE (0x0B)
@@ -802,11 +802,59 @@ static int pcmmio_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
802 return 0; 802 return 0;
803} 803}
804 804
805static int 805static int pcmmio_cmdtest(struct comedi_device *dev,
806pcmmio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, 806 struct comedi_subdevice *s,
807 struct comedi_cmd *cmd) 807 struct comedi_cmd *cmd)
808{ 808{
809 return comedi_pcm_cmdtest(dev, s, cmd); 809 int err = 0;
810
811 /* Step 1 : check if triggers are trivially valid */
812
813 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
814 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
815 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
816 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
817 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
818
819 if (err)
820 return 1;
821
822 /* Step 2a : make sure trigger sources are unique */
823
824 err |= cfc_check_trigger_is_unique(cmd->start_src);
825 err |= cfc_check_trigger_is_unique(cmd->stop_src);
826
827 /* Step 2b : and mutually compatible */
828
829 if (err)
830 return 2;
831
832 /* Step 3: check if arguments are trivially valid */
833
834 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
835 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
836 err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
837 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
838
839 switch (cmd->stop_src) {
840 case TRIG_COUNT:
841 /* any count allowed */
842 break;
843 case TRIG_NONE:
844 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
845 break;
846 default:
847 break;
848 }
849
850 if (err)
851 return 3;
852
853 /* step 4: fix up any arguments */
854
855 /* if (err) return 4; */
856
857 return 0;
810} 858}
811 859
812static int adc_wait_ready(unsigned long iobase) 860static int adc_wait_ready(unsigned long iobase)
diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c
index 31ea20c2d39e..433270ceda4f 100644
--- a/drivers/staging/comedi/drivers/pcmuio.c
+++ b/drivers/staging/comedi/drivers/pcmuio.c
@@ -77,10 +77,10 @@ Configuration Options:
77 77
78#include <linux/interrupt.h> 78#include <linux/interrupt.h>
79#include <linux/slab.h> 79#include <linux/slab.h>
80
80#include "../comedidev.h" 81#include "../comedidev.h"
81#include "pcm_common.h"
82 82
83#include <linux/pci.h> /* for PCI devices */ 83#include "comedi_fc.h"
84 84
85#define CHANS_PER_PORT 8 85#define CHANS_PER_PORT 8
86#define PORTS_PER_ASIC 6 86#define PORTS_PER_ASIC 6
@@ -92,7 +92,6 @@ Configuration Options:
92#define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT) 92#define INTR_PORTS_PER_SUBDEV (INTR_CHANS_PER_ASIC/CHANS_PER_PORT)
93#define MAX_DIO_CHANS (PORTS_PER_ASIC*2*CHANS_PER_PORT) 93#define MAX_DIO_CHANS (PORTS_PER_ASIC*2*CHANS_PER_PORT)
94#define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC) 94#define MAX_ASICS (MAX_DIO_CHANS/CHANS_PER_ASIC)
95#define SDEV_NO ((int)(s - dev->subdevices))
96#define CALC_N_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/) 95#define CALC_N_SUBDEVS(nchans) ((nchans)/MAX_CHANS_PER_SUBDEV + (!!((nchans)%MAX_CHANS_PER_SUBDEV)) /*+ (nchans > INTR_CHANS_PER_ASIC ? 2 : 1)*/)
97/* IO Memory sizes */ 96/* IO Memory sizes */
98#define ASIC_IOSIZE (0x10) 97#define ASIC_IOSIZE (0x10)
@@ -740,11 +739,59 @@ static int pcmuio_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
740 return 0; 739 return 0;
741} 740}
742 741
743static int 742static int pcmuio_cmdtest(struct comedi_device *dev,
744pcmuio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, 743 struct comedi_subdevice *s,
745 struct comedi_cmd *cmd) 744 struct comedi_cmd *cmd)
746{ 745{
747 return comedi_pcm_cmdtest(dev, s, cmd); 746 int err = 0;
747
748 /* Step 1 : check if triggers are trivially valid */
749
750 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_INT);
751 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
752 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_NOW);
753 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
754 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
755
756 if (err)
757 return 1;
758
759 /* Step 2a : make sure trigger sources are unique */
760
761 err |= cfc_check_trigger_is_unique(cmd->start_src);
762 err |= cfc_check_trigger_is_unique(cmd->stop_src);
763
764 /* Step 2b : and mutually compatible */
765
766 if (err)
767 return 2;
768
769 /* Step 3: check if arguments are trivially valid */
770
771 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
772 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
773 err |= cfc_check_trigger_arg_is(&cmd->convert_arg, 0);
774 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
775
776 switch (cmd->stop_src) {
777 case TRIG_COUNT:
778 /* any count allowed */
779 break;
780 case TRIG_NONE:
781 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
782 break;
783 default:
784 break;
785 }
786
787 if (err)
788 return 3;
789
790 /* step 4: fix up any arguments */
791
792 /* if (err) return 4; */
793
794 return 0;
748} 795}
749 796
750static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it) 797static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
@@ -791,14 +838,11 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
791 838
792 chans_left = CHANS_PER_ASIC * board->num_asics; 839 chans_left = CHANS_PER_ASIC * board->num_asics;
793 n_subdevs = CALC_N_SUBDEVS(chans_left); 840 n_subdevs = CALC_N_SUBDEVS(chans_left);
794 devpriv->sprivs = 841 devpriv->sprivs = kcalloc(n_subdevs,
795 kcalloc(n_subdevs, sizeof(struct pcmuio_subdev_private), 842 sizeof(struct pcmuio_subdev_private),
796 GFP_KERNEL); 843 GFP_KERNEL);
797 if (!devpriv->sprivs) { 844 if (!devpriv->sprivs)
798 dev_warn(dev->class_dev,
799 "cannot allocate subdevice private data structures\n");
800 return -ENOMEM; 845 return -ENOMEM;
801 }
802 846
803 ret = comedi_alloc_subdevices(dev, n_subdevs); 847 ret = comedi_alloc_subdevices(dev, n_subdevs);
804 if (ret) 848 if (ret)
diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index ef0cdaa7f02e..911eb6b32296 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -47,8 +47,6 @@ Status: works
47Devices: [Quatech] DAQP-208 (daqp), DAQP-308 47Devices: [Quatech] DAQP-208 (daqp), DAQP-308
48*/ 48*/
49 49
50#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
51
52#include "../comedidev.h" 50#include "../comedidev.h"
53#include <linux/semaphore.h> 51#include <linux/semaphore.h>
54 52
@@ -60,28 +58,16 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308
60 58
61#include "comedi_fc.h" 59#include "comedi_fc.h"
62 60
63/* Maximum number of separate DAQP devices we'll allow */ 61struct daqp_private {
64#define MAX_DEV 4
65
66struct local_info_t {
67 struct pcmcia_device *link;
68 int stop; 62 int stop;
69 int table_index;
70 char board_name[32];
71 63
72 enum { semaphore, buffer } interrupt_mode; 64 enum { semaphore, buffer } interrupt_mode;
73 65
74 struct completion eos; 66 struct completion eos;
75 67
76 struct comedi_device *dev;
77 struct comedi_subdevice *s;
78 int count; 68 int count;
79}; 69};
80 70
81/* A list of "instances" of the device. */
82
83static struct local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ };
84
85/* The DAQP communicates with the system through a 16 byte I/O window. */ 71/* The DAQP communicates with the system through a 16 byte I/O window. */
86 72
87#define DAQP_FIFO_SIZE 4096 73#define DAQP_FIFO_SIZE 4096
@@ -165,84 +151,38 @@ static struct local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ };
165#define DAQP_AUX_FIFO_NEARFULL 0x02 151#define DAQP_AUX_FIFO_NEARFULL 0x02
166#define DAQP_AUX_FIFO_EMPTY 0x01 152#define DAQP_AUX_FIFO_EMPTY 0x01
167 153
168/* These range structures tell COMEDI how the sample values map to 154static const struct comedi_lrange range_daqp_ai = {
169 * voltages. The A/D converter has four .ranges = +/- 10V through 155 4, {
170 * +/- 1.25V, and the D/A converter has only .one = +/- 5V. 156 BIP_RANGE(10),
171 */ 157 BIP_RANGE(5),
172 158 BIP_RANGE(2.5),
173static const struct comedi_lrange range_daqp_ai = { 4, { 159 BIP_RANGE(1.25)
174 BIP_RANGE(10),
175 BIP_RANGE(5),
176 BIP_RANGE(2.5),
177 BIP_RANGE(1.25)
178 }
179};
180
181static const struct comedi_lrange range_daqp_ao = { 1, {BIP_RANGE(5)} };
182
183/*====================================================================*/
184
185/* comedi interface code */
186
187static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it);
188static void daqp_detach(struct comedi_device *dev);
189static struct comedi_driver driver_daqp = {
190 .driver_name = "quatech_daqp_cs",
191 .module = THIS_MODULE,
192 .attach = daqp_attach,
193 .detach = daqp_detach,
194};
195
196#ifdef DAQP_DEBUG
197
198static void daqp_dump(struct comedi_device *dev)
199{
200 dev_info(dev->class_dev, "status %02x; aux status %02x\n",
201 inb(dev->iobase + DAQP_STATUS), inb(dev->iobase + DAQP_AUX));
202}
203
204static void hex_dump(char *str, void *ptr, int len)
205{
206 unsigned char *cptr = ptr;
207 int i;
208
209 printk(str);
210
211 for (i = 0; i < len; i++) {
212 if (i % 16 == 0)
213 printk("\n%p:", cptr);
214
215 printk(" %02x", *(cptr++));
216 } 160 }
217 printk("\n"); 161};
218}
219
220#endif
221 162
222/* Cancel a running acquisition */ 163/* Cancel a running acquisition */
223 164
224static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s) 165static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
225{ 166{
226 struct local_info_t *local = (struct local_info_t *)s->private; 167 struct daqp_private *devpriv = dev->private;
227 168
228 if (local->stop) 169 if (devpriv->stop)
229 return -EIO; 170 return -EIO;
230 171
231
232 outb(DAQP_COMMAND_STOP, dev->iobase + DAQP_COMMAND); 172 outb(DAQP_COMMAND_STOP, dev->iobase + DAQP_COMMAND);
233 173
234 /* flush any linguring data in FIFO - superfluous here */ 174 /* flush any linguring data in FIFO - superfluous here */
235 /* outb(DAQP_COMMAND_RSTF, dev->iobase+DAQP_COMMAND); */ 175 /* outb(DAQP_COMMAND_RSTF, dev->iobase+DAQP_COMMAND); */
236 176
237 local->interrupt_mode = semaphore; 177 devpriv->interrupt_mode = semaphore;
238 178
239 return 0; 179 return 0;
240} 180}
241 181
242/* Interrupt handler 182/* Interrupt handler
243 * 183 *
244 * Operates in one of two modes. If local->interrupt_mode is 184 * Operates in one of two modes. If devpriv->interrupt_mode is
245 * 'semaphore', just signal the local->eos completion and return 185 * 'semaphore', just signal the devpriv->eos completion and return
246 * (one-shot mode). Otherwise (continuous mode), read data in from 186 * (one-shot mode). Otherwise (continuous mode), read data in from
247 * the card, transfer it to the buffer provided by the higher-level 187 * the card, transfer it to the buffer provided by the higher-level
248 * comedi kernel module, and signal various comedi callback routines, 188 * comedi kernel module, and signal various comedi callback routines,
@@ -250,48 +190,21 @@ static int daqp_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
250 */ 190 */
251static enum irqreturn daqp_interrupt(int irq, void *dev_id) 191static enum irqreturn daqp_interrupt(int irq, void *dev_id)
252{ 192{
253 struct local_info_t *local = (struct local_info_t *)dev_id; 193 struct comedi_device *dev = dev_id;
254 struct comedi_device *dev; 194 struct daqp_private *devpriv = dev->private;
255 struct comedi_subdevice *s; 195 struct comedi_subdevice *s = dev->read_subdev;
256 int loop_limit = 10000; 196 int loop_limit = 10000;
257 int status; 197 int status;
258 198
259 if (local == NULL) { 199 if (!dev->attached)
260 pr_warn("irq %d for unknown device.\n", irq);
261 return IRQ_NONE; 200 return IRQ_NONE;
262 }
263
264 dev = local->dev;
265 if (dev == NULL) {
266 pr_warn("NULL comedi_device.\n");
267 return IRQ_NONE;
268 }
269
270 if (!dev->attached) {
271 pr_warn("struct comedi_device not yet attached.\n");
272 return IRQ_NONE;
273 }
274
275 s = local->s;
276 if (s == NULL) {
277 pr_warn("NULL comedi_subdevice.\n");
278 return IRQ_NONE;
279 }
280
281 if ((struct local_info_t *)s->private != local) {
282 pr_warn("invalid comedi_subdevice.\n");
283 return IRQ_NONE;
284 }
285
286 switch (local->interrupt_mode) {
287 201
202 switch (devpriv->interrupt_mode) {
288 case semaphore: 203 case semaphore:
289 204 complete(&devpriv->eos);
290 complete(&local->eos);
291 break; 205 break;
292 206
293 case buffer: 207 case buffer:
294
295 while (!((status = inb(dev->iobase + DAQP_STATUS)) 208 while (!((status = inb(dev->iobase + DAQP_STATUS))
296 & DAQP_STATUS_FIFO_EMPTY)) { 209 & DAQP_STATUS_FIFO_EMPTY)) {
297 210
@@ -315,9 +228,9 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
315 * and stop conversion if zero 228 * and stop conversion if zero
316 */ 229 */
317 230
318 if (local->count > 0) { 231 if (devpriv->count > 0) {
319 local->count--; 232 devpriv->count--;
320 if (local->count == 0) { 233 if (devpriv->count == 0) {
321 daqp_ai_cancel(dev, s); 234 daqp_ai_cancel(dev, s);
322 s->async->events |= COMEDI_CB_EOA; 235 s->async->events |= COMEDI_CB_EOA;
323 break; 236 break;
@@ -342,21 +255,41 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
342 return IRQ_HANDLED; 255 return IRQ_HANDLED;
343} 256}
344 257
258static void daqp_ai_set_one_scanlist_entry(struct comedi_device *dev,
259 unsigned int chanspec,
260 int start)
261{
262 unsigned int chan = CR_CHAN(chanspec);
263 unsigned int range = CR_RANGE(chanspec);
264 unsigned int aref = CR_AREF(chanspec);
265 unsigned int val;
266
267 val = DAQP_SCANLIST_CHANNEL(chan) | DAQP_SCANLIST_GAIN(range);
268
269 if (aref == AREF_DIFF)
270 val |= DAQP_SCANLIST_DIFFERENTIAL;
271
272 if (start)
273 val |= DAQP_SCANLIST_START;
274
275 outb(val & 0xff, dev->iobase + DAQP_SCANLIST);
276 outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST);
277}
278
345/* One-shot analog data acquisition routine */ 279/* One-shot analog data acquisition routine */
346 280
347static int daqp_ai_insn_read(struct comedi_device *dev, 281static int daqp_ai_insn_read(struct comedi_device *dev,
348 struct comedi_subdevice *s, 282 struct comedi_subdevice *s,
349 struct comedi_insn *insn, unsigned int *data) 283 struct comedi_insn *insn, unsigned int *data)
350{ 284{
351 struct local_info_t *local = (struct local_info_t *)s->private; 285 struct daqp_private *devpriv = dev->private;
352 int i; 286 int i;
353 int v; 287 int v;
354 int counter = 10000; 288 int counter = 10000;
355 289
356 if (local->stop) 290 if (devpriv->stop)
357 return -EIO; 291 return -EIO;
358 292
359
360 /* Stop any running conversion */ 293 /* Stop any running conversion */
361 daqp_ai_cancel(dev, s); 294 daqp_ai_cancel(dev, s);
362 295
@@ -366,18 +299,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev,
366 outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND); 299 outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND);
367 300
368 /* Program one scan list entry */ 301 /* Program one scan list entry */
369 302 daqp_ai_set_one_scanlist_entry(dev, insn->chanspec, 1);
370 v = DAQP_SCANLIST_CHANNEL(CR_CHAN(insn->chanspec))
371 | DAQP_SCANLIST_GAIN(CR_RANGE(insn->chanspec));
372
373 if (CR_AREF(insn->chanspec) == AREF_DIFF)
374 v |= DAQP_SCANLIST_DIFFERENTIAL;
375
376
377 v |= DAQP_SCANLIST_START;
378
379 outb(v & 0xff, dev->iobase + DAQP_SCANLIST);
380 outb(v >> 8, dev->iobase + DAQP_SCANLIST);
381 303
382 /* Reset data FIFO (see page 28 of DAQP User's Manual) */ 304 /* Reset data FIFO (see page 28 of DAQP User's Manual) */
383 305
@@ -403,10 +325,8 @@ static int daqp_ai_insn_read(struct comedi_device *dev,
403 return -1; 325 return -1;
404 } 326 }
405 327
406 init_completion(&local->eos); 328 init_completion(&devpriv->eos);
407 local->interrupt_mode = semaphore; 329 devpriv->interrupt_mode = semaphore;
408 local->dev = dev;
409 local->s = s;
410 330
411 for (i = 0; i < insn->n; i++) { 331 for (i = 0; i < insn->n; i++) {
412 332
@@ -416,7 +336,7 @@ static int daqp_ai_insn_read(struct comedi_device *dev,
416 336
417 /* Wait for interrupt service routine to unblock completion */ 337 /* Wait for interrupt service routine to unblock completion */
418 /* Maybe could use a timeout here, but it's interruptible */ 338 /* Maybe could use a timeout here, but it's interruptible */
419 if (wait_for_completion_interruptible(&local->eos)) 339 if (wait_for_completion_interruptible(&devpriv->eos))
420 return -EINTR; 340 return -EINTR;
421 341
422 data[i] = inb(dev->iobase + DAQP_FIFO); 342 data[i] = inb(dev->iobase + DAQP_FIFO);
@@ -541,7 +461,7 @@ static int daqp_ai_cmdtest(struct comedi_device *dev,
541 461
542static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) 462static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
543{ 463{
544 struct local_info_t *local = (struct local_info_t *)s->private; 464 struct daqp_private *devpriv = dev->private;
545 struct comedi_cmd *cmd = &s->async->cmd; 465 struct comedi_cmd *cmd = &s->async->cmd;
546 int counter; 466 int counter;
547 int scanlist_start_on_every_entry; 467 int scanlist_start_on_every_entry;
@@ -550,10 +470,9 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
550 int i; 470 int i;
551 int v; 471 int v;
552 472
553 if (local->stop) 473 if (devpriv->stop)
554 return -EIO; 474 return -EIO;
555 475
556
557 /* Stop any running conversion */ 476 /* Stop any running conversion */
558 daqp_ai_cancel(dev, s); 477 daqp_ai_cancel(dev, s);
559 478
@@ -592,24 +511,10 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
592 } 511 }
593 512
594 /* Program scan list */ 513 /* Program scan list */
595
596 for (i = 0; i < cmd->chanlist_len; i++) { 514 for (i = 0; i < cmd->chanlist_len; i++) {
515 int start = (i == 0 || scanlist_start_on_every_entry);
597 516
598 int chanspec = cmd->chanlist[i]; 517 daqp_ai_set_one_scanlist_entry(dev, cmd->chanlist[i], start);
599
600 /* Program one scan list entry */
601
602 v = DAQP_SCANLIST_CHANNEL(CR_CHAN(chanspec))
603 | DAQP_SCANLIST_GAIN(CR_RANGE(chanspec));
604
605 if (CR_AREF(chanspec) == AREF_DIFF)
606 v |= DAQP_SCANLIST_DIFFERENTIAL;
607
608 if (i == 0 || scanlist_start_on_every_entry)
609 v |= DAQP_SCANLIST_START;
610
611 outb(v & 0xff, dev->iobase + DAQP_SCANLIST);
612 outb(v >> 8, dev->iobase + DAQP_SCANLIST);
613 } 518 }
614 519
615 /* Now it's time to program the FIFO threshold, basically the 520 /* Now it's time to program the FIFO threshold, basically the
@@ -675,16 +580,16 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
675 580
676 /* Save away the number of conversions we should perform, and 581 /* Save away the number of conversions we should perform, and
677 * compute the FIFO threshold (in bytes, not samples - that's 582 * compute the FIFO threshold (in bytes, not samples - that's
678 * why we multiple local->count by 2 = sizeof(sample)) 583 * why we multiple devpriv->count by 2 = sizeof(sample))
679 */ 584 */
680 585
681 if (cmd->stop_src == TRIG_COUNT) { 586 if (cmd->stop_src == TRIG_COUNT) {
682 local->count = cmd->stop_arg * cmd->scan_end_arg; 587 devpriv->count = cmd->stop_arg * cmd->scan_end_arg;
683 threshold = 2 * local->count; 588 threshold = 2 * devpriv->count;
684 while (threshold > DAQP_FIFO_SIZE * 3 / 4) 589 while (threshold > DAQP_FIFO_SIZE * 3 / 4)
685 threshold /= 2; 590 threshold /= 2;
686 } else { 591 } else {
687 local->count = -1; 592 devpriv->count = -1;
688 threshold = DAQP_FIFO_SIZE / 2; 593 threshold = DAQP_FIFO_SIZE / 2;
689 } 594 }
690 595
@@ -726,9 +631,7 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
726 return -1; 631 return -1;
727 } 632 }
728 633
729 local->interrupt_mode = buffer; 634 devpriv->interrupt_mode = buffer;
730 local->dev = dev;
731 local->s = s;
732 635
733 /* Start conversion */ 636 /* Start conversion */
734 outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA, 637 outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA,
@@ -737,341 +640,193 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
737 return 0; 640 return 0;
738} 641}
739 642
740/* Single-shot analog output routine */
741
742static int daqp_ao_insn_write(struct comedi_device *dev, 643static int daqp_ao_insn_write(struct comedi_device *dev,
743 struct comedi_subdevice *s, 644 struct comedi_subdevice *s,
744 struct comedi_insn *insn, unsigned int *data) 645 struct comedi_insn *insn,
646 unsigned int *data)
745{ 647{
746 struct local_info_t *local = (struct local_info_t *)s->private; 648 struct daqp_private *devpriv = dev->private;
747 int d; 649 unsigned int chan = CR_CHAN(insn->chanspec);
748 unsigned int chan; 650 unsigned int val;
651 int i;
749 652
750 if (local->stop) 653 if (devpriv->stop)
751 return -EIO; 654 return -EIO;
752 655
753 chan = CR_CHAN(insn->chanspec);
754 d = data[0];
755 d &= 0x0fff;
756 d ^= 0x0800; /* Flip the sign */
757 d |= chan << 12;
758
759 /* Make sure D/A update mode is direct update */ 656 /* Make sure D/A update mode is direct update */
760 outb(0, dev->iobase + DAQP_AUX); 657 outb(0, dev->iobase + DAQP_AUX);
761 658
762 outw(d, dev->iobase + DAQP_DA); 659 for (i = 0; i > insn->n; i++) {
660 val = data[0];
661 val &= 0x0fff;
662 val ^= 0x0800; /* Flip the sign */
663 val |= (chan << 12);
763 664
764 return 1; 665 outw(val, dev->iobase + DAQP_DA);
765} 666 }
766 667
767/* Digital input routine */ 668 return insn->n;
669}
768 670
769static int daqp_di_insn_read(struct comedi_device *dev, 671static int daqp_di_insn_bits(struct comedi_device *dev,
770 struct comedi_subdevice *s, 672 struct comedi_subdevice *s,
771 struct comedi_insn *insn, unsigned int *data) 673 struct comedi_insn *insn,
674 unsigned int *data)
772{ 675{
773 struct local_info_t *local = (struct local_info_t *)s->private; 676 struct daqp_private *devpriv = dev->private;
774 677
775 if (local->stop) 678 if (devpriv->stop)
776 return -EIO; 679 return -EIO;
777 680
778 data[0] = inb(dev->iobase + DAQP_DIGITAL_IO); 681 data[0] = inb(dev->iobase + DAQP_DIGITAL_IO);
779 682
780 return 1; 683 return insn->n;
781} 684}
782 685
783/* Digital output routine */ 686static int daqp_do_insn_bits(struct comedi_device *dev,
784 687 struct comedi_subdevice *s,
785static int daqp_do_insn_write(struct comedi_device *dev, 688 struct comedi_insn *insn,
786 struct comedi_subdevice *s, 689 unsigned int *data)
787 struct comedi_insn *insn, unsigned int *data)
788{ 690{
789 struct local_info_t *local = (struct local_info_t *)s->private; 691 struct daqp_private *devpriv = dev->private;
692 unsigned int mask = data[0];
693 unsigned int bits = data[1];
790 694
791 if (local->stop) 695 if (devpriv->stop)
792 return -EIO; 696 return -EIO;
793 697
794 outw(data[0] & 0xf, dev->iobase + DAQP_DIGITAL_IO); 698 if (mask) {
699 s->state &= ~mask;
700 s->state |= (bits & mask);
795 701
796 return 1; 702 outb(s->state, dev->iobase + DAQP_DIGITAL_IO);
797} 703 }
798 704
799/* daqp_attach is called via comedi_config to attach a comedi device 705 data[1] = s->state;
800 * to a /dev/comedi*. Note that this is different from daqp_cs_attach()
801 * which is called by the pcmcia subsystem to attach the PCMCIA card
802 * when it is inserted.
803 */
804 706
805static int daqp_attach(struct comedi_device *dev, struct comedi_devconfig *it) 707 return insn->n;
708}
709
710static int daqp_auto_attach(struct comedi_device *dev,
711 unsigned long context)
806{ 712{
807 int ret; 713 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
808 struct local_info_t *local = dev_table[it->options[0]]; 714 struct daqp_private *devpriv;
809 struct comedi_subdevice *s; 715 struct comedi_subdevice *s;
716 int ret;
810 717
811 if (it->options[0] < 0 || it->options[0] >= MAX_DEV || !local) { 718 dev->board_name = dev->driver->driver_name;
812 dev_err(dev->class_dev, "No such daqp device %d\n",
813 it->options[0]);
814 return -EIO;
815 }
816 719
817 /* Typically brittle code that I don't completely understand, 720 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
818 * but "it works on my card". The intent is to pull the model 721 if (!devpriv)
819 * number of the card out the PCMCIA CIS and stash it away as 722 return -ENOMEM;
820 * the COMEDI board_name. Looks like the third field in 723 dev->private = devpriv;
821 * CISTPL_VERS_1 (offset 2) holds what we're looking for. If
822 * it doesn't work, who cares, just leave it as "DAQP".
823 */
824 724
825 strcpy(local->board_name, "DAQP"); 725 link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
826 dev->board_name = local->board_name; 726 ret = comedi_pcmcia_enable(dev, NULL);
827 if (local->link->prod_id[2]) { 727 if (ret)
828 if (strncmp(local->link->prod_id[2], "DAQP", 4) == 0) { 728 return ret;
829 strncpy(local->board_name, local->link->prod_id[2], 729 dev->iobase = link->resource[0]->start;
830 sizeof(local->board_name));
831 }
832 }
833 730
834 dev->iobase = local->link->resource[0]->start; 731 link->priv = dev;
732 ret = pcmcia_request_irq(link, daqp_interrupt);
733 if (ret)
734 return ret;
835 735
836 ret = comedi_alloc_subdevices(dev, 4); 736 ret = comedi_alloc_subdevices(dev, 4);
837 if (ret) 737 if (ret)
838 return ret; 738 return ret;
839 739
840 dev_info(dev->class_dev, "attaching daqp%d (io 0x%04lx)\n",
841 it->options[0], dev->iobase);
842
843 s = &dev->subdevices[0]; 740 s = &dev->subdevices[0];
844 dev->read_subdev = s; 741 dev->read_subdev = s;
845 s->private = local; 742 s->type = COMEDI_SUBD_AI;
846 s->type = COMEDI_SUBD_AI; 743 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
847 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ; 744 s->n_chan = 8;
848 s->n_chan = 8; 745 s->len_chanlist = 2048;
849 s->len_chanlist = 2048; 746 s->maxdata = 0xffff;
850 s->maxdata = 0xffff; 747 s->range_table = &range_daqp_ai;
851 s->range_table = &range_daqp_ai; 748 s->insn_read = daqp_ai_insn_read;
852 s->insn_read = daqp_ai_insn_read; 749 s->do_cmdtest = daqp_ai_cmdtest;
853 s->do_cmdtest = daqp_ai_cmdtest; 750 s->do_cmd = daqp_ai_cmd;
854 s->do_cmd = daqp_ai_cmd; 751 s->cancel = daqp_ai_cancel;
855 s->cancel = daqp_ai_cancel;
856 752
857 s = &dev->subdevices[1]; 753 s = &dev->subdevices[1];
858 dev->write_subdev = s; 754 s->type = COMEDI_SUBD_AO;
859 s->private = local; 755 s->subdev_flags = SDF_WRITEABLE;
860 s->type = COMEDI_SUBD_AO; 756 s->n_chan = 2;
861 s->subdev_flags = SDF_WRITEABLE; 757 s->maxdata = 0x0fff;
862 s->n_chan = 2; 758 s->range_table = &range_bipolar5;
863 s->len_chanlist = 1; 759 s->insn_write = daqp_ao_insn_write;
864 s->maxdata = 0x0fff;
865 s->range_table = &range_daqp_ao;
866 s->insn_write = daqp_ao_insn_write;
867 760
868 s = &dev->subdevices[2]; 761 s = &dev->subdevices[2];
869 s->private = local; 762 s->type = COMEDI_SUBD_DI;
870 s->type = COMEDI_SUBD_DI; 763 s->subdev_flags = SDF_READABLE;
871 s->subdev_flags = SDF_READABLE; 764 s->n_chan = 1;
872 s->n_chan = 1; 765 s->maxdata = 1;
873 s->len_chanlist = 1; 766 s->insn_bits = daqp_di_insn_bits;
874 s->insn_read = daqp_di_insn_read;
875 767
876 s = &dev->subdevices[3]; 768 s = &dev->subdevices[3];
877 s->private = local; 769 s->type = COMEDI_SUBD_DO;
878 s->type = COMEDI_SUBD_DO; 770 s->subdev_flags = SDF_WRITEABLE;
879 s->subdev_flags = SDF_WRITEABLE; 771 s->n_chan = 1;
880 s->n_chan = 1; 772 s->maxdata = 1;
881 s->len_chanlist = 1; 773 s->insn_bits = daqp_do_insn_bits;
882 s->insn_write = daqp_do_insn_write;
883
884 return 1;
885}
886
887static void daqp_detach(struct comedi_device *dev)
888{
889 /* Nothing to cleanup */
890}
891
892/*====================================================================
893
894 PCMCIA interface code
895
896 The rest of the code in this file is based on dummy_cs.c v1.24
897 from the Linux pcmcia_cs distribution v3.1.8 and is subject
898 to the following license agreement.
899
900 The remaining contents of this file are subject to the Mozilla Public
901 License Version 1.1 (the "License"); you may not use this file
902 except in compliance with the License. You may obtain a copy of
903 the License at http://www.mozilla.org/MPL/
904
905 Software distributed under the License is distributed on an "AS
906 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
907 implied. See the License for the specific language governing
908 rights and limitations under the License.
909
910 The initial developer of the original code is David A. Hinds
911 <dhinds@pcmcia.sourceforge.org>. Portions created by David A. Hinds
912 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
913
914 Alternatively, the contents of this file may be used under the
915 terms of the GNU Public License version 2 (the "GPL"), in which
916 case the provisions of the GPL are applicable instead of the
917 above. If you wish to allow the use of your version of this file
918 only under the terms of the GPL and not to allow others to use
919 your version of this file under the MPL, indicate your decision
920 by deleting the provisions above and replace them with the notice
921 and other provisions required by the GPL. If you do not delete
922 the provisions above, a recipient may use your version of this
923 file under either the MPL or the GPL.
924
925======================================================================*/
926
927static void daqp_cs_config(struct pcmcia_device *link);
928static void daqp_cs_release(struct pcmcia_device *link);
929static int daqp_cs_suspend(struct pcmcia_device *p_dev);
930static int daqp_cs_resume(struct pcmcia_device *p_dev);
931
932static int daqp_cs_attach(struct pcmcia_device *);
933static void daqp_cs_detach(struct pcmcia_device *);
934
935static int daqp_cs_attach(struct pcmcia_device *link)
936{
937 struct local_info_t *local;
938 int i;
939
940 dev_dbg(&link->dev, "daqp_cs_attach()\n");
941
942 for (i = 0; i < MAX_DEV; i++)
943 if (dev_table[i] == NULL)
944 break;
945 if (i == MAX_DEV) {
946 dev_notice(&link->dev, "no devices available\n");
947 return -ENODEV;
948 }
949
950 /* Allocate space for private device-specific data */
951 local = kzalloc(sizeof(struct local_info_t), GFP_KERNEL);
952 if (!local)
953 return -ENOMEM;
954
955 local->table_index = i;
956 dev_table[i] = local;
957 local->link = link;
958 link->priv = local;
959
960 daqp_cs_config(link);
961 774
962 return 0; 775 return 0;
963} /* daqp_cs_attach */
964
965static void daqp_cs_detach(struct pcmcia_device *link)
966{
967 struct local_info_t *dev = link->priv;
968
969 dev->stop = 1;
970 daqp_cs_release(link);
971
972 /* Unlink device structure, and free it */
973 dev_table[dev->table_index] = NULL;
974 kfree(dev);
975
976} 776}
977 777
978static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev, void *priv_data) 778static struct comedi_driver driver_daqp = {
979{ 779 .driver_name = "quatech_daqp_cs",
980 if (p_dev->config_index == 0) 780 .module = THIS_MODULE,
981 return -EINVAL; 781 .auto_attach = daqp_auto_attach,
982 782 .detach = comedi_pcmcia_disable,
983 return pcmcia_request_io(p_dev); 783};
984}
985
986static void daqp_cs_config(struct pcmcia_device *link)
987{
988 int ret;
989
990 dev_dbg(&link->dev, "daqp_cs_config\n");
991
992 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
993
994 ret = pcmcia_loop_config(link, daqp_pcmcia_config_loop, NULL);
995 if (ret) {
996 dev_warn(&link->dev, "no configuration found\n");
997 goto failed;
998 }
999
1000 ret = pcmcia_request_irq(link, daqp_interrupt);
1001 if (ret)
1002 goto failed;
1003
1004 ret = pcmcia_enable_device(link);
1005 if (ret)
1006 goto failed;
1007
1008 return;
1009
1010failed:
1011 daqp_cs_release(link);
1012
1013} /* daqp_cs_config */
1014
1015static void daqp_cs_release(struct pcmcia_device *link)
1016{
1017 dev_dbg(&link->dev, "daqp_cs_release\n");
1018
1019 pcmcia_disable_device(link);
1020} /* daqp_cs_release */
1021 784
1022static int daqp_cs_suspend(struct pcmcia_device *link) 785static int daqp_cs_suspend(struct pcmcia_device *link)
1023{ 786{
1024 struct local_info_t *local = link->priv; 787 struct comedi_device *dev = link->priv;
788 struct daqp_private *devpriv = dev ? dev->private : NULL;
1025 789
1026 /* Mark the device as stopped, to block IO until later */ 790 /* Mark the device as stopped, to block IO until later */
1027 local->stop = 1; 791 if (devpriv)
792 devpriv->stop = 1;
793
1028 return 0; 794 return 0;
1029} 795}
1030 796
1031static int daqp_cs_resume(struct pcmcia_device *link) 797static int daqp_cs_resume(struct pcmcia_device *link)
1032{ 798{
1033 struct local_info_t *local = link->priv; 799 struct comedi_device *dev = link->priv;
800 struct daqp_private *devpriv = dev ? dev->private : NULL;
1034 801
1035 local->stop = 0; 802 if (devpriv)
803 devpriv->stop = 0;
1036 804
1037 return 0; 805 return 0;
1038} 806}
1039 807
1040/*====================================================================*/ 808static int daqp_cs_attach(struct pcmcia_device *link)
1041 809{
1042#ifdef MODULE 810 return comedi_pcmcia_auto_config(link, &driver_daqp);
811}
1043 812
1044static const struct pcmcia_device_id daqp_cs_id_table[] = { 813static const struct pcmcia_device_id daqp_cs_id_table[] = {
1045 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0027), 814 PCMCIA_DEVICE_MANF_CARD(0x0137, 0x0027),
1046 PCMCIA_DEVICE_NULL 815 PCMCIA_DEVICE_NULL
1047}; 816};
1048
1049MODULE_DEVICE_TABLE(pcmcia, daqp_cs_id_table); 817MODULE_DEVICE_TABLE(pcmcia, daqp_cs_id_table);
1050MODULE_AUTHOR("Brent Baccala <baccala@freesoft.org>");
1051MODULE_DESCRIPTION("Comedi driver for Quatech DAQP PCMCIA data capture cards");
1052MODULE_LICENSE("GPL");
1053 818
1054static struct pcmcia_driver daqp_cs_driver = { 819static struct pcmcia_driver daqp_cs_driver = {
1055 .probe = daqp_cs_attach, 820 .name = "quatech_daqp_cs",
1056 .remove = daqp_cs_detach, 821 .owner = THIS_MODULE,
1057 .suspend = daqp_cs_suspend, 822 .id_table = daqp_cs_id_table,
1058 .resume = daqp_cs_resume, 823 .probe = daqp_cs_attach,
1059 .id_table = daqp_cs_id_table, 824 .remove = comedi_pcmcia_auto_unconfig,
1060 .owner = THIS_MODULE, 825 .suspend = daqp_cs_suspend,
1061 .name = "quatech_daqp_cs", 826 .resume = daqp_cs_resume,
1062}; 827};
828module_comedi_pcmcia_driver(driver_daqp, daqp_cs_driver);
1063 829
1064int __init init_module(void) 830MODULE_DESCRIPTION("Comedi driver for Quatech DAQP PCMCIA data capture cards");
1065{ 831MODULE_AUTHOR("Brent Baccala <baccala@freesoft.org>");
1066 pcmcia_register_driver(&daqp_cs_driver); 832MODULE_LICENSE("GPL");
1067 comedi_driver_register(&driver_daqp);
1068 return 0;
1069}
1070
1071void __exit cleanup_module(void)
1072{
1073 comedi_driver_unregister(&driver_daqp);
1074 pcmcia_unregister_driver(&daqp_cs_driver);
1075}
1076
1077#endif
diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c
index 8d7c948a919c..6a5c914fa501 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -101,8 +101,9 @@ Configuration options:
101 101
102*/ 102*/
103 103
104#include <linux/interrupt.h> 104#include <linux/pci.h>
105#include <linux/delay.h> 105#include <linux/delay.h>
106#include <linux/interrupt.h>
106 107
107#include "../comedidev.h" 108#include "../comedidev.h"
108 109
@@ -1420,11 +1421,6 @@ static int rtd520_pci_probe(struct pci_dev *dev,
1420 return comedi_pci_auto_config(dev, &rtd520_driver); 1421 return comedi_pci_auto_config(dev, &rtd520_driver);
1421} 1422}
1422 1423
1423static void rtd520_pci_remove(struct pci_dev *dev)
1424{
1425 comedi_pci_auto_unconfig(dev);
1426}
1427
1428static DEFINE_PCI_DEVICE_TABLE(rtd520_pci_table) = { 1424static DEFINE_PCI_DEVICE_TABLE(rtd520_pci_table) = {
1429 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x7520) }, 1425 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x7520) },
1430 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x4520) }, 1426 { PCI_DEVICE(PCI_VENDOR_ID_RTD, 0x4520) },
@@ -1436,7 +1432,7 @@ static struct pci_driver rtd520_pci_driver = {
1436 .name = "rtd520", 1432 .name = "rtd520",
1437 .id_table = rtd520_pci_table, 1433 .id_table = rtd520_pci_table,
1438 .probe = rtd520_pci_probe, 1434 .probe = rtd520_pci_probe,
1439 .remove = rtd520_pci_remove, 1435 .remove = comedi_pci_auto_unconfig,
1440}; 1436};
1441module_comedi_pci_driver(rtd520_driver, rtd520_pci_driver); 1437module_comedi_pci_driver(rtd520_driver, rtd520_pci_driver);
1442 1438
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index 6dc1d2812865..81a1fe661579 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -64,6 +64,7 @@ INSN_CONFIG instructions:
64 comedi_do_insn(cf,&insn); //executing configuration 64 comedi_do_insn(cf,&insn); //executing configuration
65*/ 65*/
66 66
67#include <linux/pci.h>
67#include <linux/interrupt.h> 68#include <linux/interrupt.h>
68#include <linux/kernel.h> 69#include <linux/kernel.h>
69#include <linux/types.h> 70#include <linux/types.h>
@@ -2836,11 +2837,6 @@ static int s626_pci_probe(struct pci_dev *dev,
2836 return comedi_pci_auto_config(dev, &s626_driver); 2837 return comedi_pci_auto_config(dev, &s626_driver);
2837} 2838}
2838 2839
2839static void s626_pci_remove(struct pci_dev *dev)
2840{
2841 comedi_pci_auto_unconfig(dev);
2842}
2843
2844/* 2840/*
2845 * For devices with vendor:device id == 0x1131:0x7146 you must specify 2841 * For devices with vendor:device id == 0x1131:0x7146 you must specify
2846 * also subvendor:subdevice ids, because otherwise it will conflict with 2842 * also subvendor:subdevice ids, because otherwise it will conflict with
@@ -2857,7 +2853,7 @@ static struct pci_driver s626_pci_driver = {
2857 .name = "s626", 2853 .name = "s626",
2858 .id_table = s626_pci_table, 2854 .id_table = s626_pci_table,
2859 .probe = s626_pci_probe, 2855 .probe = s626_pci_probe,
2860 .remove = s626_pci_remove, 2856 .remove = comedi_pci_auto_unconfig,
2861}; 2857};
2862module_comedi_pci_driver(s626_driver, s626_pci_driver); 2858module_comedi_pci_driver(s626_driver, s626_pci_driver);
2863 2859
diff --git a/drivers/staging/comedi/drivers/skel.c b/drivers/staging/comedi/drivers/skel.c
index e2d79700a615..cb83f6ae48b9 100644
--- a/drivers/staging/comedi/drivers/skel.c
+++ b/drivers/staging/comedi/drivers/skel.c
@@ -72,9 +72,9 @@ Configuration Options:
72 * options that are used with comedi_config. 72 * options that are used with comedi_config.
73 */ 73 */
74 74
75#include "../comedidev.h" 75#include <linux/pci.h>
76 76
77#include <linux/pci.h> /* for PCI devices */ 77#include "../comedidev.h"
78 78
79#include "comedi_fc.h" 79#include "comedi_fc.h"
80 80
@@ -707,15 +707,11 @@ static int skel_pci_probe(struct pci_dev *dev,
707 return comedi_pci_auto_config(dev, &skel_driver); 707 return comedi_pci_auto_config(dev, &skel_driver);
708} 708}
709 709
710static void skel_pci_remove(struct pci_dev *dev)
711{
712 comedi_pci_auto_unconfig(dev);
713}
714
715static struct pci_driver skel_pci_driver = { 710static struct pci_driver skel_pci_driver = {
711 .name = "dummy",
716 .id_table = skel_pci_table, 712 .id_table = skel_pci_table,
717 .probe = &skel_pci_probe, 713 .probe = &skel_pci_probe,
718 .remove = &skel_pci_remove 714 .remove = comedi_pci_auto_unconfig,
719}; 715};
720module_comedi_pci_driver(skel_driver, skel_pci_driver); 716module_comedi_pci_driver(skel_driver, skel_pci_driver);
721#else 717#else
diff --git a/drivers/staging/comedi/drivers/unioxx5.c b/drivers/staging/comedi/drivers/unioxx5.c
index c9ded938314f..74b974bf1032 100644
--- a/drivers/staging/comedi/drivers/unioxx5.c
+++ b/drivers/staging/comedi/drivers/unioxx5.c
@@ -380,12 +380,8 @@ static int __unioxx5_subdev_init(struct comedi_subdevice *subdev,
380 } 380 }
381 381
382 usp = kzalloc(sizeof(*usp), GFP_KERNEL); 382 usp = kzalloc(sizeof(*usp), GFP_KERNEL);
383 383 if (usp == NULL)
384 if (usp == NULL) {
385 dev_err(subdev->class_dev,
386 "comedi%d: error! --> out of memory!\n", minor);
387 return -1; 384 return -1;
388 }
389 385
390 usp->usp_iobase = subdev_iobase; 386 usp->usp_iobase = subdev_iobase;
391 dev_info(subdev->class_dev, "comedi%d: |", minor); 387 dev_info(subdev->class_dev, "comedi%d: |", minor);
diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
index 17b45ebb0553..1a0062a04456 100644
--- a/drivers/staging/comedi/drivers/usbdux.c
+++ b/drivers/staging/comedi/drivers/usbdux.c
@@ -2388,7 +2388,7 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
2388 "Could not upload firmware (err=%d)\n", ret); 2388 "Could not upload firmware (err=%d)\n", ret);
2389 goto out; 2389 goto out;
2390 } 2390 }
2391 comedi_usb_auto_config(uinterf, &usbdux_driver); 2391 comedi_usb_auto_config(uinterf, &usbdux_driver, 0);
2392 out: 2392 out:
2393 release_firmware(fw); 2393 release_firmware(fw);
2394} 2394}
@@ -2445,8 +2445,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2445 /* create space for the commands of the DA converter */ 2445 /* create space for the commands of the DA converter */
2446 usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); 2446 usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL);
2447 if (!usbduxsub[index].dac_commands) { 2447 if (!usbduxsub[index].dac_commands) {
2448 dev_err(dev, "comedi_: usbdux: "
2449 "error alloc space for dac commands\n");
2450 tidy_up(&(usbduxsub[index])); 2448 tidy_up(&(usbduxsub[index]));
2451 up(&start_stop_sem); 2449 up(&start_stop_sem);
2452 return -ENOMEM; 2450 return -ENOMEM;
@@ -2454,8 +2452,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2454 /* create space for the commands going to the usb device */ 2452 /* create space for the commands going to the usb device */
2455 usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); 2453 usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL);
2456 if (!usbduxsub[index].dux_commands) { 2454 if (!usbduxsub[index].dux_commands) {
2457 dev_err(dev, "comedi_: usbdux: "
2458 "error alloc space for dux commands\n");
2459 tidy_up(&(usbduxsub[index])); 2455 tidy_up(&(usbduxsub[index]));
2460 up(&start_stop_sem); 2456 up(&start_stop_sem);
2461 return -ENOMEM; 2457 return -ENOMEM;
@@ -2463,8 +2459,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2463 /* create space for the in buffer and set it to zero */ 2459 /* create space for the in buffer and set it to zero */
2464 usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL); 2460 usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL);
2465 if (!(usbduxsub[index].inBuffer)) { 2461 if (!(usbduxsub[index].inBuffer)) {
2466 dev_err(dev, "comedi_: usbdux: "
2467 "could not alloc space for inBuffer\n");
2468 tidy_up(&(usbduxsub[index])); 2462 tidy_up(&(usbduxsub[index]));
2469 up(&start_stop_sem); 2463 up(&start_stop_sem);
2470 return -ENOMEM; 2464 return -ENOMEM;
@@ -2472,8 +2466,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2472 /* create space of the instruction buffer */ 2466 /* create space of the instruction buffer */
2473 usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL); 2467 usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
2474 if (!(usbduxsub[index].insnBuffer)) { 2468 if (!(usbduxsub[index].insnBuffer)) {
2475 dev_err(dev, "comedi_: usbdux: "
2476 "could not alloc space for insnBuffer\n");
2477 tidy_up(&(usbduxsub[index])); 2469 tidy_up(&(usbduxsub[index]));
2478 up(&start_stop_sem); 2470 up(&start_stop_sem);
2479 return -ENOMEM; 2471 return -ENOMEM;
@@ -2481,8 +2473,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2481 /* create space for the outbuffer */ 2473 /* create space for the outbuffer */
2482 usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); 2474 usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
2483 if (!(usbduxsub[index].outBuffer)) { 2475 if (!(usbduxsub[index].outBuffer)) {
2484 dev_err(dev, "comedi_: usbdux: "
2485 "could not alloc space for outBuffer\n");
2486 tidy_up(&(usbduxsub[index])); 2476 tidy_up(&(usbduxsub[index]));
2487 up(&start_stop_sem); 2477 up(&start_stop_sem);
2488 return -ENOMEM; 2478 return -ENOMEM;
@@ -2504,10 +2494,9 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2504 usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL; 2494 usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL;
2505 2495
2506 usbduxsub[index].urbIn = 2496 usbduxsub[index].urbIn =
2507 kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfInBuffers, 2497 kcalloc(usbduxsub[index].numOfInBuffers, sizeof(struct urb *),
2508 GFP_KERNEL); 2498 GFP_KERNEL);
2509 if (!(usbduxsub[index].urbIn)) { 2499 if (!(usbduxsub[index].urbIn)) {
2510 dev_err(dev, "comedi_: usbdux: Could not alloc. urbIn array\n");
2511 tidy_up(&(usbduxsub[index])); 2500 tidy_up(&(usbduxsub[index]));
2512 up(&start_stop_sem); 2501 up(&start_stop_sem);
2513 return -ENOMEM; 2502 return -ENOMEM;
@@ -2532,8 +2521,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2532 usbduxsub[index].urbIn[i]->transfer_buffer = 2521 usbduxsub[index].urbIn[i]->transfer_buffer =
2533 kzalloc(SIZEINBUF, GFP_KERNEL); 2522 kzalloc(SIZEINBUF, GFP_KERNEL);
2534 if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) { 2523 if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) {
2535 dev_err(dev, "comedi_: usbdux%d: "
2536 "could not alloc. transb.\n", index);
2537 tidy_up(&(usbduxsub[index])); 2524 tidy_up(&(usbduxsub[index]));
2538 up(&start_stop_sem); 2525 up(&start_stop_sem);
2539 return -ENOMEM; 2526 return -ENOMEM;
@@ -2552,11 +2539,9 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2552 usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL; 2539 usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL;
2553 2540
2554 usbduxsub[index].urbOut = 2541 usbduxsub[index].urbOut =
2555 kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfOutBuffers, 2542 kcalloc(usbduxsub[index].numOfOutBuffers, sizeof(struct urb *),
2556 GFP_KERNEL); 2543 GFP_KERNEL);
2557 if (!(usbduxsub[index].urbOut)) { 2544 if (!(usbduxsub[index].urbOut)) {
2558 dev_err(dev, "comedi_: usbdux: "
2559 "Could not alloc. urbOut array\n");
2560 tidy_up(&(usbduxsub[index])); 2545 tidy_up(&(usbduxsub[index]));
2561 up(&start_stop_sem); 2546 up(&start_stop_sem);
2562 return -ENOMEM; 2547 return -ENOMEM;
@@ -2581,8 +2566,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2581 usbduxsub[index].urbOut[i]->transfer_buffer = 2566 usbduxsub[index].urbOut[i]->transfer_buffer =
2582 kzalloc(SIZEOUTBUF, GFP_KERNEL); 2567 kzalloc(SIZEOUTBUF, GFP_KERNEL);
2583 if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) { 2568 if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) {
2584 dev_err(dev, "comedi_: usbdux%d: "
2585 "could not alloc. transb.\n", index);
2586 tidy_up(&(usbduxsub[index])); 2569 tidy_up(&(usbduxsub[index]));
2587 up(&start_stop_sem); 2570 up(&start_stop_sem);
2588 return -ENOMEM; 2571 return -ENOMEM;
@@ -2617,8 +2600,6 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
2617 usbduxsub[index].urbPwm->transfer_buffer = 2600 usbduxsub[index].urbPwm->transfer_buffer =
2618 kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL); 2601 kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL);
2619 if (!(usbduxsub[index].urbPwm->transfer_buffer)) { 2602 if (!(usbduxsub[index].urbPwm->transfer_buffer)) {
2620 dev_err(dev, "comedi_: usbdux%d: "
2621 "could not alloc. transb. for pwm\n", index);
2622 tidy_up(&(usbduxsub[index])); 2603 tidy_up(&(usbduxsub[index]));
2623 up(&start_stop_sem); 2604 up(&start_stop_sem);
2624 return -ENOMEM; 2605 return -ENOMEM;
diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
index 4e19f6186f28..4bf5dd094dc9 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -1490,7 +1490,7 @@ static void usbduxfast_firmware_request_complete_handler(const struct firmware
1490 goto out; 1490 goto out;
1491 } 1491 }
1492 1492
1493 comedi_usb_auto_config(uinterf, &usbduxfast_driver); 1493 comedi_usb_auto_config(uinterf, &usbduxfast_driver, 0);
1494 out: 1494 out:
1495 release_firmware(fw); 1495 release_firmware(fw);
1496} 1496}
@@ -1556,8 +1556,6 @@ static int usbduxfast_usb_probe(struct usb_interface *uinterf,
1556 usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER, 1556 usbduxfastsub[index].dux_commands = kmalloc(SIZEOFDUXBUFFER,
1557 GFP_KERNEL); 1557 GFP_KERNEL);
1558 if (!usbduxfastsub[index].dux_commands) { 1558 if (!usbduxfastsub[index].dux_commands) {
1559 dev_err(&uinterf->dev,
1560 "error alloc space for dac commands\n");
1561 tidy_up(&(usbduxfastsub[index])); 1559 tidy_up(&(usbduxfastsub[index]));
1562 up(&start_stop_sem); 1560 up(&start_stop_sem);
1563 return -ENOMEM; 1561 return -ENOMEM;
@@ -1565,8 +1563,6 @@ static int usbduxfast_usb_probe(struct usb_interface *uinterf,
1565 /* create space of the instruction buffer */ 1563 /* create space of the instruction buffer */
1566 usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL); 1564 usbduxfastsub[index].insnBuffer = kmalloc(SIZEINSNBUF, GFP_KERNEL);
1567 if (!usbduxfastsub[index].insnBuffer) { 1565 if (!usbduxfastsub[index].insnBuffer) {
1568 dev_err(&uinterf->dev,
1569 "could not alloc space for insnBuffer\n");
1570 tidy_up(&(usbduxfastsub[index])); 1566 tidy_up(&(usbduxfastsub[index]));
1571 up(&start_stop_sem); 1567 up(&start_stop_sem);
1572 return -ENOMEM; 1568 return -ENOMEM;
@@ -1592,8 +1588,6 @@ static int usbduxfast_usb_probe(struct usb_interface *uinterf,
1592 } 1588 }
1593 usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL); 1589 usbduxfastsub[index].transfer_buffer = kmalloc(SIZEINBUF, GFP_KERNEL);
1594 if (!usbduxfastsub[index].transfer_buffer) { 1590 if (!usbduxfastsub[index].transfer_buffer) {
1595 dev_err(&uinterf->dev,
1596 "usbduxfast%d: could not alloc. transb.\n", index);
1597 tidy_up(&(usbduxfastsub[index])); 1591 tidy_up(&(usbduxfastsub[index]));
1598 up(&start_stop_sem); 1592 up(&start_stop_sem);
1599 return -ENOMEM; 1593 return -ENOMEM;
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index cdd279b1f61e..d066351a71b2 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -2374,7 +2374,7 @@ static void usbdux_firmware_request_complete_handler(const struct firmware *fw,
2374 "Could not upload firmware (err=%d)\n", ret); 2374 "Could not upload firmware (err=%d)\n", ret);
2375 goto out; 2375 goto out;
2376 } 2376 }
2377 comedi_usb_auto_config(uinterf, &usbduxsigma_driver); 2377 comedi_usb_auto_config(uinterf, &usbduxsigma_driver, 0);
2378out: 2378out:
2379 release_firmware(fw); 2379 release_firmware(fw);
2380} 2380}
@@ -2431,8 +2431,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2431 /* create space for the commands of the DA converter */ 2431 /* create space for the commands of the DA converter */
2432 usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); 2432 usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL);
2433 if (!usbduxsub[index].dac_commands) { 2433 if (!usbduxsub[index].dac_commands) {
2434 dev_err(dev, "comedi_: usbduxsigma: "
2435 "error alloc space for dac commands\n");
2436 tidy_up(&(usbduxsub[index])); 2434 tidy_up(&(usbduxsub[index]));
2437 up(&start_stop_sem); 2435 up(&start_stop_sem);
2438 return -ENOMEM; 2436 return -ENOMEM;
@@ -2440,8 +2438,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2440 /* create space for the commands going to the usb device */ 2438 /* create space for the commands going to the usb device */
2441 usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); 2439 usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL);
2442 if (!usbduxsub[index].dux_commands) { 2440 if (!usbduxsub[index].dux_commands) {
2443 dev_err(dev, "comedi_: usbduxsigma: "
2444 "error alloc space for dux commands\n");
2445 tidy_up(&(usbduxsub[index])); 2441 tidy_up(&(usbduxsub[index]));
2446 up(&start_stop_sem); 2442 up(&start_stop_sem);
2447 return -ENOMEM; 2443 return -ENOMEM;
@@ -2449,8 +2445,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2449 /* create space for the in buffer and set it to zero */ 2445 /* create space for the in buffer and set it to zero */
2450 usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL); 2446 usbduxsub[index].inBuffer = kzalloc(SIZEINBUF, GFP_KERNEL);
2451 if (!(usbduxsub[index].inBuffer)) { 2447 if (!(usbduxsub[index].inBuffer)) {
2452 dev_err(dev, "comedi_: usbduxsigma: "
2453 "could not alloc space for inBuffer\n");
2454 tidy_up(&(usbduxsub[index])); 2448 tidy_up(&(usbduxsub[index]));
2455 up(&start_stop_sem); 2449 up(&start_stop_sem);
2456 return -ENOMEM; 2450 return -ENOMEM;
@@ -2458,8 +2452,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2458 /* create space of the instruction buffer */ 2452 /* create space of the instruction buffer */
2459 usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL); 2453 usbduxsub[index].insnBuffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
2460 if (!(usbduxsub[index].insnBuffer)) { 2454 if (!(usbduxsub[index].insnBuffer)) {
2461 dev_err(dev, "comedi_: usbduxsigma: "
2462 "could not alloc space for insnBuffer\n");
2463 tidy_up(&(usbduxsub[index])); 2455 tidy_up(&(usbduxsub[index]));
2464 up(&start_stop_sem); 2456 up(&start_stop_sem);
2465 return -ENOMEM; 2457 return -ENOMEM;
@@ -2467,8 +2459,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2467 /* create space for the outbuffer */ 2459 /* create space for the outbuffer */
2468 usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); 2460 usbduxsub[index].outBuffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
2469 if (!(usbduxsub[index].outBuffer)) { 2461 if (!(usbduxsub[index].outBuffer)) {
2470 dev_err(dev, "comedi_: usbduxsigma: "
2471 "could not alloc space for outBuffer\n");
2472 tidy_up(&(usbduxsub[index])); 2462 tidy_up(&(usbduxsub[index]));
2473 up(&start_stop_sem); 2463 up(&start_stop_sem);
2474 return -ENOMEM; 2464 return -ENOMEM;
@@ -2489,12 +2479,10 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2489 else 2479 else
2490 usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL; 2480 usbduxsub[index].numOfInBuffers = NUMOFINBUFFERSFULL;
2491 2481
2492 usbduxsub[index].urbIn = 2482 usbduxsub[index].urbIn = kcalloc(usbduxsub[index].numOfInBuffers,
2493 kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfInBuffers, 2483 sizeof(struct urb *),
2494 GFP_KERNEL); 2484 GFP_KERNEL);
2495 if (!(usbduxsub[index].urbIn)) { 2485 if (!(usbduxsub[index].urbIn)) {
2496 dev_err(dev, "comedi_: usbduxsigma: "
2497 "Could not alloc. urbIn array\n");
2498 tidy_up(&(usbduxsub[index])); 2486 tidy_up(&(usbduxsub[index]));
2499 up(&start_stop_sem); 2487 up(&start_stop_sem);
2500 return -ENOMEM; 2488 return -ENOMEM;
@@ -2519,8 +2507,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2519 usbduxsub[index].urbIn[i]->transfer_buffer = 2507 usbduxsub[index].urbIn[i]->transfer_buffer =
2520 kzalloc(SIZEINBUF, GFP_KERNEL); 2508 kzalloc(SIZEINBUF, GFP_KERNEL);
2521 if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) { 2509 if (!(usbduxsub[index].urbIn[i]->transfer_buffer)) {
2522 dev_err(dev, "comedi_: usbduxsigma%d: "
2523 "could not alloc. transb.\n", index);
2524 tidy_up(&(usbduxsub[index])); 2510 tidy_up(&(usbduxsub[index]));
2525 up(&start_stop_sem); 2511 up(&start_stop_sem);
2526 return -ENOMEM; 2512 return -ENOMEM;
@@ -2539,12 +2525,9 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2539 else 2525 else
2540 usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL; 2526 usbduxsub[index].numOfOutBuffers = NUMOFOUTBUFFERSFULL;
2541 2527
2542 usbduxsub[index].urbOut = 2528 usbduxsub[index].urbOut = kcalloc(usbduxsub[index].numOfOutBuffers,
2543 kzalloc(sizeof(struct urb *) * usbduxsub[index].numOfOutBuffers, 2529 sizeof(struct urb *), GFP_KERNEL);
2544 GFP_KERNEL);
2545 if (!(usbduxsub[index].urbOut)) { 2530 if (!(usbduxsub[index].urbOut)) {
2546 dev_err(dev, "comedi_: usbduxsigma: "
2547 "Could not alloc. urbOut array\n");
2548 tidy_up(&(usbduxsub[index])); 2531 tidy_up(&(usbduxsub[index]));
2549 up(&start_stop_sem); 2532 up(&start_stop_sem);
2550 return -ENOMEM; 2533 return -ENOMEM;
@@ -2569,8 +2552,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2569 usbduxsub[index].urbOut[i]->transfer_buffer = 2552 usbduxsub[index].urbOut[i]->transfer_buffer =
2570 kzalloc(SIZEOUTBUF, GFP_KERNEL); 2553 kzalloc(SIZEOUTBUF, GFP_KERNEL);
2571 if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) { 2554 if (!(usbduxsub[index].urbOut[i]->transfer_buffer)) {
2572 dev_err(dev, "comedi_: usbduxsigma%d: "
2573 "could not alloc. transb.\n", index);
2574 tidy_up(&(usbduxsub[index])); 2555 tidy_up(&(usbduxsub[index]));
2575 up(&start_stop_sem); 2556 up(&start_stop_sem);
2576 return -ENOMEM; 2557 return -ENOMEM;
@@ -2606,8 +2587,6 @@ static int usbduxsigma_usb_probe(struct usb_interface *uinterf,
2606 usbduxsub[index].urbPwm->transfer_buffer = 2587 usbduxsub[index].urbPwm->transfer_buffer =
2607 kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL); 2588 kzalloc(usbduxsub[index].sizePwmBuf, GFP_KERNEL);
2608 if (!(usbduxsub[index].urbPwm->transfer_buffer)) { 2589 if (!(usbduxsub[index].urbPwm->transfer_buffer)) {
2609 dev_err(dev, "comedi_: usbduxsigma%d: "
2610 "could not alloc. transb. for pwm\n", index);
2611 tidy_up(&(usbduxsub[index])); 2590 tidy_up(&(usbduxsub[index]));
2612 up(&start_stop_sem); 2591 up(&start_stop_sem);
2613 return -ENOMEM; 2592 return -ENOMEM;
diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c
index 609dc6915997..2be5087414f6 100644
--- a/drivers/staging/comedi/drivers/vmk80xx.c
+++ b/drivers/staging/comedi/drivers/vmk80xx.c
@@ -38,19 +38,6 @@ Supports:
38 - counter 38 - counter
39 - pwm 39 - pwm
40*/ 40*/
41/*
42Changelog:
43
440.8.81 -3- code completely rewritten (adjust driver logic)
450.8.81 -2- full support for K8061
460.8.81 -1- fix some mistaken among others the number of
47 supported boards and I/O handling
48
490.7.76 -4- renamed to vmk80xx
500.7.76 -3- detect K8061 (only theoretically supported)
510.7.76 -2- code completely rewritten (adjust driver logic)
520.7.76 -1- support for digital and counter subdevice
53*/
54 41
55#include <linux/kernel.h> 42#include <linux/kernel.h>
56#include <linux/module.h> 43#include <linux/module.h>
@@ -113,30 +100,9 @@ enum {
113#define VMK8061_CMD_RD_AO 0x0f 100#define VMK8061_CMD_RD_AO 0x0f
114#define VMK8061_CMD_RD_PWM 0x10 101#define VMK8061_CMD_RD_PWM 0x10
115 102
116#define VMK80XX_MAX_BOARDS COMEDI_NUM_BOARD_MINORS
117
118#define TRANS_OUT_BUSY 1
119#define TRANS_IN_BUSY 2
120#define TRANS_IN_RUNNING 3
121
122#define IC3_VERSION (1 << 0) 103#define IC3_VERSION (1 << 0)
123#define IC6_VERSION (1 << 1) 104#define IC6_VERSION (1 << 1)
124 105
125#define URB_RCV_FLAG (1 << 0)
126#define URB_SND_FLAG (1 << 1)
127
128#ifdef CONFIG_COMEDI_DEBUG
129static int dbgcm = 1;
130#else
131static int dbgcm;
132#endif
133
134#define dbgcm(fmt, arg...) \
135do { \
136 if (dbgcm) \
137 printk(KERN_DEBUG fmt, ##arg); \
138} while (0)
139
140enum vmk80xx_model { 106enum vmk80xx_model {
141 VMK8055_MODEL, 107 VMK8055_MODEL,
142 VMK8061_MODEL 108 VMK8061_MODEL
@@ -147,130 +113,73 @@ struct firmware_version {
147 unsigned char ic6_vers[32]; /* CPU */ 113 unsigned char ic6_vers[32]; /* CPU */
148}; 114};
149 115
150static const struct comedi_lrange vmk8055_range = {
151 1, {UNI_RANGE(5)}
152};
153
154static const struct comedi_lrange vmk8061_range = { 116static const struct comedi_lrange vmk8061_range = {
155 2, {UNI_RANGE(5), UNI_RANGE(10)} 117 2, {
118 UNI_RANGE(5),
119 UNI_RANGE(10)
120 }
156}; 121};
157 122
158struct vmk80xx_board { 123struct vmk80xx_board {
159 const char *name; 124 const char *name;
160 enum vmk80xx_model model; 125 enum vmk80xx_model model;
161 const struct comedi_lrange *range; 126 const struct comedi_lrange *range;
162 __u8 ai_chans; 127 int ai_nchans;
163 __le16 ai_bits; 128 unsigned int ai_maxdata;
164 __u8 ao_chans; 129 int ao_nchans;
165 __le16 ao_bits; 130 int di_nchans;
166 __u8 di_chans; 131 unsigned int cnt_maxdata;
167 __le16 di_bits; 132 int pwm_nchans;
168 __u8 do_chans; 133 unsigned int pwm_maxdata;
169 __le16 do_bits;
170 __u8 cnt_chans;
171 __le16 cnt_bits;
172 __u8 pwm_chans;
173 __le16 pwm_bits;
174}; 134};
175 135
176enum { 136static const struct vmk80xx_board vmk80xx_boardinfo[] = {
177 VMK80XX_SUBD_AI, 137 [DEVICE_VMK8055] = {
178 VMK80XX_SUBD_AO, 138 .name = "K8055 (VM110)",
179 VMK80XX_SUBD_DI, 139 .model = VMK8055_MODEL,
180 VMK80XX_SUBD_DO, 140 .range = &range_unipolar5,
181 VMK80XX_SUBD_CNT, 141 .ai_nchans = 2,
182 VMK80XX_SUBD_PWM, 142 .ai_maxdata = 0x00ff,
143 .ao_nchans = 2,
144 .di_nchans = 6,
145 .cnt_maxdata = 0xffff,
146 },
147 [DEVICE_VMK8061] = {
148 .name = "K8061 (VM140)",
149 .model = VMK8061_MODEL,
150 .range = &vmk8061_range,
151 .ai_nchans = 8,
152 .ai_maxdata = 0x03ff,
153 .ao_nchans = 8,
154 .di_nchans = 8,
155 .cnt_maxdata = 0, /* unknown, device is not writeable */
156 .pwm_nchans = 1,
157 .pwm_maxdata = 0x03ff,
158 },
183}; 159};
184 160
185struct vmk80xx_usb { 161struct vmk80xx_private {
186 struct usb_device *udev; 162 struct usb_device *usb;
187 struct usb_interface *intf; 163 struct usb_interface *intf;
188 struct usb_endpoint_descriptor *ep_rx; 164 struct usb_endpoint_descriptor *ep_rx;
189 struct usb_endpoint_descriptor *ep_tx; 165 struct usb_endpoint_descriptor *ep_tx;
190 struct usb_anchor rx_anchor;
191 struct usb_anchor tx_anchor;
192 struct vmk80xx_board board;
193 struct firmware_version fw; 166 struct firmware_version fw;
194 struct semaphore limit_sem; 167 struct semaphore limit_sem;
195 wait_queue_head_t read_wait;
196 wait_queue_head_t write_wait;
197 unsigned char *usb_rx_buf; 168 unsigned char *usb_rx_buf;
198 unsigned char *usb_tx_buf; 169 unsigned char *usb_tx_buf;
199 unsigned long flags; 170 enum vmk80xx_model model;
200 int probed;
201 int attached;
202 int count;
203}; 171};
204 172
205static struct vmk80xx_usb vmb[VMK80XX_MAX_BOARDS]; 173static int vmk80xx_check_data_link(struct vmk80xx_private *devpriv)
206
207static DEFINE_MUTEX(glb_mutex);
208
209static void vmk80xx_tx_callback(struct urb *urb)
210{
211 struct vmk80xx_usb *dev = urb->context;
212 int stat = urb->status;
213
214 if (stat && !(stat == -ENOENT
215 || stat == -ECONNRESET || stat == -ESHUTDOWN))
216 dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n",
217 __func__, stat);
218
219 if (!test_bit(TRANS_OUT_BUSY, &dev->flags))
220 return;
221
222 clear_bit(TRANS_OUT_BUSY, &dev->flags);
223
224 wake_up_interruptible(&dev->write_wait);
225}
226
227static void vmk80xx_rx_callback(struct urb *urb)
228{
229 struct vmk80xx_usb *dev = urb->context;
230 int stat = urb->status;
231
232 switch (stat) {
233 case 0:
234 break;
235 case -ENOENT:
236 case -ECONNRESET:
237 case -ESHUTDOWN:
238 break;
239 default:
240 dbgcm("comedi#: vmk80xx: %s - nonzero urb status (%d)\n",
241 __func__, stat);
242 goto resubmit;
243 }
244
245 goto exit;
246resubmit:
247 if (test_bit(TRANS_IN_RUNNING, &dev->flags) && dev->intf) {
248 usb_anchor_urb(urb, &dev->rx_anchor);
249
250 if (!usb_submit_urb(urb, GFP_KERNEL))
251 goto exit;
252
253 dev_err(&urb->dev->dev,
254 "comedi#: vmk80xx: %s - submit urb failed\n",
255 __func__);
256
257 usb_unanchor_urb(urb);
258 }
259exit:
260 clear_bit(TRANS_IN_BUSY, &dev->flags);
261
262 wake_up_interruptible(&dev->read_wait);
263}
264
265static int vmk80xx_check_data_link(struct vmk80xx_usb *dev)
266{ 174{
175 struct usb_device *usb = devpriv->usb;
267 unsigned int tx_pipe; 176 unsigned int tx_pipe;
268 unsigned int rx_pipe; 177 unsigned int rx_pipe;
269 unsigned char tx[1]; 178 unsigned char tx[1];
270 unsigned char rx[2]; 179 unsigned char rx[2];
271 180
272 tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); 181 tx_pipe = usb_sndbulkpipe(usb, 0x01);
273 rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); 182 rx_pipe = usb_rcvbulkpipe(usb, 0x81);
274 183
275 tx[0] = VMK8061_CMD_RD_PWR_STAT; 184 tx[0] = VMK8061_CMD_RD_PWR_STAT;
276 185
@@ -279,22 +188,23 @@ static int vmk80xx_check_data_link(struct vmk80xx_usb *dev)
279 * running and the data link between IC3 and 188 * running and the data link between IC3 and
280 * IC6 is working properly 189 * IC6 is working properly
281 */ 190 */
282 usb_bulk_msg(dev->udev, tx_pipe, tx, 1, NULL, dev->ep_tx->bInterval); 191 usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval);
283 usb_bulk_msg(dev->udev, rx_pipe, rx, 2, NULL, HZ * 10); 192 usb_bulk_msg(usb, rx_pipe, rx, 2, NULL, HZ * 10);
284 193
285 return (int)rx[1]; 194 return (int)rx[1];
286} 195}
287 196
288static void vmk80xx_read_eeprom(struct vmk80xx_usb *dev, int flag) 197static void vmk80xx_read_eeprom(struct vmk80xx_private *devpriv, int flag)
289{ 198{
199 struct usb_device *usb = devpriv->usb;
290 unsigned int tx_pipe; 200 unsigned int tx_pipe;
291 unsigned int rx_pipe; 201 unsigned int rx_pipe;
292 unsigned char tx[1]; 202 unsigned char tx[1];
293 unsigned char rx[64]; 203 unsigned char rx[64];
294 int cnt; 204 int cnt;
295 205
296 tx_pipe = usb_sndbulkpipe(dev->udev, 0x01); 206 tx_pipe = usb_sndbulkpipe(usb, 0x01);
297 rx_pipe = usb_rcvbulkpipe(dev->udev, 0x81); 207 rx_pipe = usb_rcvbulkpipe(usb, 0x81);
298 208
299 tx[0] = VMK8061_CMD_RD_VERSION; 209 tx[0] = VMK8061_CMD_RD_VERSION;
300 210
@@ -302,243 +212,116 @@ static void vmk80xx_read_eeprom(struct vmk80xx_usb *dev, int flag)
302 * Read the firmware version info of IC3 and 212 * Read the firmware version info of IC3 and
303 * IC6 from the internal EEPROM of the IC 213 * IC6 from the internal EEPROM of the IC
304 */ 214 */
305 usb_bulk_msg(dev->udev, tx_pipe, tx, 1, NULL, dev->ep_tx->bInterval); 215 usb_bulk_msg(usb, tx_pipe, tx, 1, NULL, devpriv->ep_tx->bInterval);
306 usb_bulk_msg(dev->udev, rx_pipe, rx, 64, &cnt, HZ * 10); 216 usb_bulk_msg(usb, rx_pipe, rx, 64, &cnt, HZ * 10);
307 217
308 rx[cnt] = '\0'; 218 rx[cnt] = '\0';
309 219
310 if (flag & IC3_VERSION) 220 if (flag & IC3_VERSION)
311 strncpy(dev->fw.ic3_vers, rx + 1, 24); 221 strncpy(devpriv->fw.ic3_vers, rx + 1, 24);
312 else /* IC6_VERSION */ 222 else /* IC6_VERSION */
313 strncpy(dev->fw.ic6_vers, rx + 25, 24); 223 strncpy(devpriv->fw.ic6_vers, rx + 25, 24);
314} 224}
315 225
316static int vmk80xx_reset_device(struct vmk80xx_usb *dev) 226static void vmk80xx_do_bulk_msg(struct vmk80xx_private *devpriv)
317{
318 struct urb *urb;
319 unsigned int tx_pipe;
320 int ival;
321 size_t size;
322
323 urb = usb_alloc_urb(0, GFP_KERNEL);
324 if (!urb)
325 return -ENOMEM;
326
327 tx_pipe = usb_sndintpipe(dev->udev, 0x01);
328
329 ival = dev->ep_tx->bInterval;
330 size = le16_to_cpu(dev->ep_tx->wMaxPacketSize);
331
332 dev->usb_tx_buf[0] = VMK8055_CMD_RST;
333 dev->usb_tx_buf[1] = 0x00;
334 dev->usb_tx_buf[2] = 0x00;
335 dev->usb_tx_buf[3] = 0x00;
336 dev->usb_tx_buf[4] = 0x00;
337 dev->usb_tx_buf[5] = 0x00;
338 dev->usb_tx_buf[6] = 0x00;
339 dev->usb_tx_buf[7] = 0x00;
340
341 usb_fill_int_urb(urb, dev->udev, tx_pipe, dev->usb_tx_buf,
342 size, vmk80xx_tx_callback, dev, ival);
343
344 usb_anchor_urb(urb, &dev->tx_anchor);
345
346 return usb_submit_urb(urb, GFP_KERNEL);
347}
348
349static void vmk80xx_build_int_urb(struct urb *urb, int flag)
350{
351 struct vmk80xx_usb *dev = urb->context;
352 __u8 rx_addr;
353 __u8 tx_addr;
354 unsigned int pipe;
355 unsigned char *buf;
356 size_t size;
357 void (*callback) (struct urb *);
358 int ival;
359
360 if (flag & URB_RCV_FLAG) {
361 rx_addr = dev->ep_rx->bEndpointAddress;
362 pipe = usb_rcvintpipe(dev->udev, rx_addr);
363 buf = dev->usb_rx_buf;
364 size = le16_to_cpu(dev->ep_rx->wMaxPacketSize);
365 callback = vmk80xx_rx_callback;
366 ival = dev->ep_rx->bInterval;
367 } else { /* URB_SND_FLAG */
368 tx_addr = dev->ep_tx->bEndpointAddress;
369 pipe = usb_sndintpipe(dev->udev, tx_addr);
370 buf = dev->usb_tx_buf;
371 size = le16_to_cpu(dev->ep_tx->wMaxPacketSize);
372 callback = vmk80xx_tx_callback;
373 ival = dev->ep_tx->bInterval;
374 }
375
376 usb_fill_int_urb(urb, dev->udev, pipe, buf, size, callback, dev, ival);
377}
378
379static void vmk80xx_do_bulk_msg(struct vmk80xx_usb *dev)
380{ 227{
228 struct usb_device *usb = devpriv->usb;
381 __u8 tx_addr; 229 __u8 tx_addr;
382 __u8 rx_addr; 230 __u8 rx_addr;
383 unsigned int tx_pipe; 231 unsigned int tx_pipe;
384 unsigned int rx_pipe; 232 unsigned int rx_pipe;
385 size_t size; 233 size_t size;
386 234
387 set_bit(TRANS_IN_BUSY, &dev->flags); 235 tx_addr = devpriv->ep_tx->bEndpointAddress;
388 set_bit(TRANS_OUT_BUSY, &dev->flags); 236 rx_addr = devpriv->ep_rx->bEndpointAddress;
389 237 tx_pipe = usb_sndbulkpipe(usb, tx_addr);
390 tx_addr = dev->ep_tx->bEndpointAddress; 238 rx_pipe = usb_rcvbulkpipe(usb, rx_addr);
391 rx_addr = dev->ep_rx->bEndpointAddress;
392 tx_pipe = usb_sndbulkpipe(dev->udev, tx_addr);
393 rx_pipe = usb_rcvbulkpipe(dev->udev, rx_addr);
394 239
395 /* 240 /*
396 * The max packet size attributes of the K8061 241 * The max packet size attributes of the K8061
397 * input/output endpoints are identical 242 * input/output endpoints are identical
398 */ 243 */
399 size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); 244 size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
400
401 usb_bulk_msg(dev->udev, tx_pipe, dev->usb_tx_buf,
402 size, NULL, dev->ep_tx->bInterval);
403 usb_bulk_msg(dev->udev, rx_pipe, dev->usb_rx_buf, size, NULL, HZ * 10);
404 245
405 clear_bit(TRANS_OUT_BUSY, &dev->flags); 246 usb_bulk_msg(usb, tx_pipe, devpriv->usb_tx_buf,
406 clear_bit(TRANS_IN_BUSY, &dev->flags); 247 size, NULL, devpriv->ep_tx->bInterval);
248 usb_bulk_msg(usb, rx_pipe, devpriv->usb_rx_buf, size, NULL, HZ * 10);
407} 249}
408 250
409static int vmk80xx_read_packet(struct vmk80xx_usb *dev) 251static int vmk80xx_read_packet(struct vmk80xx_private *devpriv)
410{ 252{
411 struct urb *urb; 253 struct usb_device *usb;
412 int retval; 254 struct usb_endpoint_descriptor *ep;
255 unsigned int pipe;
413 256
414 if (!dev->intf) 257 if (!devpriv->intf)
415 return -ENODEV; 258 return -ENODEV;
416 259
417 /* Only useful for interrupt transfers */ 260 if (devpriv->model == VMK8061_MODEL) {
418 if (test_bit(TRANS_IN_BUSY, &dev->flags)) 261 vmk80xx_do_bulk_msg(devpriv);
419 if (wait_event_interruptible(dev->read_wait,
420 !test_bit(TRANS_IN_BUSY,
421 &dev->flags)))
422 return -ERESTART;
423
424 if (dev->board.model == VMK8061_MODEL) {
425 vmk80xx_do_bulk_msg(dev);
426
427 return 0; 262 return 0;
428 } 263 }
429 264
430 urb = usb_alloc_urb(0, GFP_KERNEL); 265 usb = devpriv->usb;
431 if (!urb) 266 ep = devpriv->ep_rx;
432 return -ENOMEM; 267 pipe = usb_rcvintpipe(usb, ep->bEndpointAddress);
433 268 return usb_interrupt_msg(usb, pipe, devpriv->usb_rx_buf,
434 urb->context = dev; 269 le16_to_cpu(ep->wMaxPacketSize), NULL,
435 vmk80xx_build_int_urb(urb, URB_RCV_FLAG); 270 HZ * 10);
436
437 set_bit(TRANS_IN_RUNNING, &dev->flags);
438 set_bit(TRANS_IN_BUSY, &dev->flags);
439
440 usb_anchor_urb(urb, &dev->rx_anchor);
441
442 retval = usb_submit_urb(urb, GFP_KERNEL);
443 if (!retval)
444 goto exit;
445
446 clear_bit(TRANS_IN_RUNNING, &dev->flags);
447 usb_unanchor_urb(urb);
448
449exit:
450 usb_free_urb(urb);
451
452 return retval;
453} 271}
454 272
455static int vmk80xx_write_packet(struct vmk80xx_usb *dev, int cmd) 273static int vmk80xx_write_packet(struct vmk80xx_private *devpriv, int cmd)
456{ 274{
457 struct urb *urb; 275 struct usb_device *usb;
458 int retval; 276 struct usb_endpoint_descriptor *ep;
277 unsigned int pipe;
459 278
460 if (!dev->intf) 279 if (!devpriv->intf)
461 return -ENODEV; 280 return -ENODEV;
462 281
463 if (test_bit(TRANS_OUT_BUSY, &dev->flags)) 282 devpriv->usb_tx_buf[0] = cmd;
464 if (wait_event_interruptible(dev->write_wait,
465 !test_bit(TRANS_OUT_BUSY,
466 &dev->flags)))
467 return -ERESTART;
468
469 if (dev->board.model == VMK8061_MODEL) {
470 dev->usb_tx_buf[0] = cmd;
471 vmk80xx_do_bulk_msg(dev);
472 283
284 if (devpriv->model == VMK8061_MODEL) {
285 vmk80xx_do_bulk_msg(devpriv);
473 return 0; 286 return 0;
474 } 287 }
475 288
476 urb = usb_alloc_urb(0, GFP_KERNEL); 289 usb = devpriv->usb;
477 if (!urb) 290 ep = devpriv->ep_tx;
478 return -ENOMEM; 291 pipe = usb_sndintpipe(usb, ep->bEndpointAddress);
479 292 return usb_interrupt_msg(usb, pipe, devpriv->usb_tx_buf,
480 urb->context = dev; 293 le16_to_cpu(ep->wMaxPacketSize), NULL,
481 vmk80xx_build_int_urb(urb, URB_SND_FLAG); 294 HZ * 10);
482
483 set_bit(TRANS_OUT_BUSY, &dev->flags);
484
485 usb_anchor_urb(urb, &dev->tx_anchor);
486
487 dev->usb_tx_buf[0] = cmd;
488
489 retval = usb_submit_urb(urb, GFP_KERNEL);
490 if (!retval)
491 goto exit;
492
493 clear_bit(TRANS_OUT_BUSY, &dev->flags);
494 usb_unanchor_urb(urb);
495
496exit:
497 usb_free_urb(urb);
498
499 return retval;
500} 295}
501 296
502#define DIR_IN 1 297static int vmk80xx_reset_device(struct vmk80xx_private *devpriv)
503#define DIR_OUT 2
504
505static int rudimentary_check(struct vmk80xx_usb *dev, int dir)
506{ 298{
507 if (!dev) 299 size_t size;
508 return -EFAULT; 300 int retval;
509 if (!dev->probed)
510 return -ENODEV;
511 if (!dev->attached)
512 return -ENODEV;
513 if (dir & DIR_IN) {
514 if (test_bit(TRANS_IN_BUSY, &dev->flags))
515 return -EBUSY;
516 }
517 if (dir & DIR_OUT) {
518 if (test_bit(TRANS_OUT_BUSY, &dev->flags))
519 return -EBUSY;
520 }
521 301
522 return 0; 302 size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
303 memset(devpriv->usb_tx_buf, 0, size);
304 retval = vmk80xx_write_packet(devpriv, VMK8055_CMD_RST);
305 if (retval)
306 return retval;
307 /* set outputs to known state as we cannot read them */
308 return vmk80xx_write_packet(devpriv, VMK8055_CMD_WRT_AD);
523} 309}
524 310
525static int vmk80xx_ai_rinsn(struct comedi_device *cdev, 311static int vmk80xx_ai_insn_read(struct comedi_device *dev,
526 struct comedi_subdevice *s, 312 struct comedi_subdevice *s,
527 struct comedi_insn *insn, unsigned int *data) 313 struct comedi_insn *insn,
314 unsigned int *data)
528{ 315{
529 struct vmk80xx_usb *dev = cdev->private; 316 struct vmk80xx_private *devpriv = dev->private;
530 int chan; 317 int chan;
531 int reg[2]; 318 int reg[2];
532 int n; 319 int n;
533 320
534 n = rudimentary_check(dev, DIR_IN); 321 down(&devpriv->limit_sem);
535 if (n)
536 return n;
537
538 down(&dev->limit_sem);
539 chan = CR_CHAN(insn->chanspec); 322 chan = CR_CHAN(insn->chanspec);
540 323
541 switch (dev->board.model) { 324 switch (devpriv->model) {
542 case VMK8055_MODEL: 325 case VMK8055_MODEL:
543 if (!chan) 326 if (!chan)
544 reg[0] = VMK8055_AI1_REG; 327 reg[0] = VMK8055_AI1_REG;
@@ -549,48 +332,45 @@ static int vmk80xx_ai_rinsn(struct comedi_device *cdev,
549 default: 332 default:
550 reg[0] = VMK8061_AI_REG1; 333 reg[0] = VMK8061_AI_REG1;
551 reg[1] = VMK8061_AI_REG2; 334 reg[1] = VMK8061_AI_REG2;
552 dev->usb_tx_buf[0] = VMK8061_CMD_RD_AI; 335 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AI;
553 dev->usb_tx_buf[VMK8061_CH_REG] = chan; 336 devpriv->usb_tx_buf[VMK8061_CH_REG] = chan;
554 break; 337 break;
555 } 338 }
556 339
557 for (n = 0; n < insn->n; n++) { 340 for (n = 0; n < insn->n; n++) {
558 if (vmk80xx_read_packet(dev)) 341 if (vmk80xx_read_packet(devpriv))
559 break; 342 break;
560 343
561 if (dev->board.model == VMK8055_MODEL) { 344 if (devpriv->model == VMK8055_MODEL) {
562 data[n] = dev->usb_rx_buf[reg[0]]; 345 data[n] = devpriv->usb_rx_buf[reg[0]];
563 continue; 346 continue;
564 } 347 }
565 348
566 /* VMK8061_MODEL */ 349 /* VMK8061_MODEL */
567 data[n] = dev->usb_rx_buf[reg[0]] + 256 * 350 data[n] = devpriv->usb_rx_buf[reg[0]] + 256 *
568 dev->usb_rx_buf[reg[1]]; 351 devpriv->usb_rx_buf[reg[1]];
569 } 352 }
570 353
571 up(&dev->limit_sem); 354 up(&devpriv->limit_sem);
572 355
573 return n; 356 return n;
574} 357}
575 358
576static int vmk80xx_ao_winsn(struct comedi_device *cdev, 359static int vmk80xx_ao_insn_write(struct comedi_device *dev,
577 struct comedi_subdevice *s, 360 struct comedi_subdevice *s,
578 struct comedi_insn *insn, unsigned int *data) 361 struct comedi_insn *insn,
362 unsigned int *data)
579{ 363{
580 struct vmk80xx_usb *dev = cdev->private; 364 struct vmk80xx_private *devpriv = dev->private;
581 int chan; 365 int chan;
582 int cmd; 366 int cmd;
583 int reg; 367 int reg;
584 int n; 368 int n;
585 369
586 n = rudimentary_check(dev, DIR_OUT); 370 down(&devpriv->limit_sem);
587 if (n)
588 return n;
589
590 down(&dev->limit_sem);
591 chan = CR_CHAN(insn->chanspec); 371 chan = CR_CHAN(insn->chanspec);
592 372
593 switch (dev->board.model) { 373 switch (devpriv->model) {
594 case VMK8055_MODEL: 374 case VMK8055_MODEL:
595 cmd = VMK8055_CMD_WRT_AD; 375 cmd = VMK8055_CMD_WRT_AD;
596 if (!chan) 376 if (!chan)
@@ -601,82 +381,76 @@ static int vmk80xx_ao_winsn(struct comedi_device *cdev,
601 default: /* NOTE: avoid compiler warnings */ 381 default: /* NOTE: avoid compiler warnings */
602 cmd = VMK8061_CMD_SET_AO; 382 cmd = VMK8061_CMD_SET_AO;
603 reg = VMK8061_AO_REG; 383 reg = VMK8061_AO_REG;
604 dev->usb_tx_buf[VMK8061_CH_REG] = chan; 384 devpriv->usb_tx_buf[VMK8061_CH_REG] = chan;
605 break; 385 break;
606 } 386 }
607 387
608 for (n = 0; n < insn->n; n++) { 388 for (n = 0; n < insn->n; n++) {
609 dev->usb_tx_buf[reg] = data[n]; 389 devpriv->usb_tx_buf[reg] = data[n];
610 390
611 if (vmk80xx_write_packet(dev, cmd)) 391 if (vmk80xx_write_packet(devpriv, cmd))
612 break; 392 break;
613 } 393 }
614 394
615 up(&dev->limit_sem); 395 up(&devpriv->limit_sem);
616 396
617 return n; 397 return n;
618} 398}
619 399
620static int vmk80xx_ao_rinsn(struct comedi_device *cdev, 400static int vmk80xx_ao_insn_read(struct comedi_device *dev,
621 struct comedi_subdevice *s, 401 struct comedi_subdevice *s,
622 struct comedi_insn *insn, unsigned int *data) 402 struct comedi_insn *insn,
403 unsigned int *data)
623{ 404{
624 struct vmk80xx_usb *dev = cdev->private; 405 struct vmk80xx_private *devpriv = dev->private;
625 int chan; 406 int chan;
626 int reg; 407 int reg;
627 int n; 408 int n;
628 409
629 n = rudimentary_check(dev, DIR_IN); 410 down(&devpriv->limit_sem);
630 if (n)
631 return n;
632
633 down(&dev->limit_sem);
634 chan = CR_CHAN(insn->chanspec); 411 chan = CR_CHAN(insn->chanspec);
635 412
636 reg = VMK8061_AO_REG - 1; 413 reg = VMK8061_AO_REG - 1;
637 414
638 dev->usb_tx_buf[0] = VMK8061_CMD_RD_AO; 415 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_AO;
639 416
640 for (n = 0; n < insn->n; n++) { 417 for (n = 0; n < insn->n; n++) {
641 if (vmk80xx_read_packet(dev)) 418 if (vmk80xx_read_packet(devpriv))
642 break; 419 break;
643 420
644 data[n] = dev->usb_rx_buf[reg + chan]; 421 data[n] = devpriv->usb_rx_buf[reg + chan];
645 } 422 }
646 423
647 up(&dev->limit_sem); 424 up(&devpriv->limit_sem);
648 425
649 return n; 426 return n;
650} 427}
651 428
652static int vmk80xx_di_bits(struct comedi_device *cdev, 429static int vmk80xx_di_insn_bits(struct comedi_device *dev,
653 struct comedi_subdevice *s, 430 struct comedi_subdevice *s,
654 struct comedi_insn *insn, unsigned int *data) 431 struct comedi_insn *insn,
432 unsigned int *data)
655{ 433{
656 struct vmk80xx_usb *dev = cdev->private; 434 struct vmk80xx_private *devpriv = dev->private;
657 unsigned char *rx_buf; 435 unsigned char *rx_buf;
658 int reg; 436 int reg;
659 int retval; 437 int retval;
660 438
661 retval = rudimentary_check(dev, DIR_IN); 439 down(&devpriv->limit_sem);
662 if (retval)
663 return retval;
664
665 down(&dev->limit_sem);
666 440
667 rx_buf = dev->usb_rx_buf; 441 rx_buf = devpriv->usb_rx_buf;
668 442
669 if (dev->board.model == VMK8061_MODEL) { 443 if (devpriv->model == VMK8061_MODEL) {
670 reg = VMK8061_DI_REG; 444 reg = VMK8061_DI_REG;
671 dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI; 445 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_DI;
672 } else { 446 } else {
673 reg = VMK8055_DI_REG; 447 reg = VMK8055_DI_REG;
674 } 448 }
675 449
676 retval = vmk80xx_read_packet(dev); 450 retval = vmk80xx_read_packet(devpriv);
677 451
678 if (!retval) { 452 if (!retval) {
679 if (dev->board.model == VMK8055_MODEL) 453 if (devpriv->model == VMK8055_MODEL)
680 data[1] = (((rx_buf[reg] >> 4) & 0x03) | 454 data[1] = (((rx_buf[reg] >> 4) & 0x03) |
681 ((rx_buf[reg] << 2) & 0x04) | 455 ((rx_buf[reg] << 2) & 0x04) |
682 ((rx_buf[reg] >> 3) & 0x18)); 456 ((rx_buf[reg] >> 3) & 0x18));
@@ -686,185 +460,48 @@ static int vmk80xx_di_bits(struct comedi_device *cdev,
686 retval = 2; 460 retval = 2;
687 } 461 }
688 462
689 up(&dev->limit_sem); 463 up(&devpriv->limit_sem);
690 464
691 return retval; 465 return retval;
692} 466}
693 467
694static int vmk80xx_di_rinsn(struct comedi_device *cdev, 468static int vmk80xx_do_insn_bits(struct comedi_device *dev,
695 struct comedi_subdevice *s, 469 struct comedi_subdevice *s,
696 struct comedi_insn *insn, unsigned int *data) 470 struct comedi_insn *insn,
471 unsigned int *data)
697{ 472{
698 struct vmk80xx_usb *dev = cdev->private; 473 struct vmk80xx_private *devpriv = dev->private;
699 int chan;
700 unsigned char *rx_buf;
701 int reg;
702 int inp;
703 int n;
704
705 n = rudimentary_check(dev, DIR_IN);
706 if (n)
707 return n;
708
709 down(&dev->limit_sem);
710 chan = CR_CHAN(insn->chanspec);
711
712 rx_buf = dev->usb_rx_buf;
713
714 if (dev->board.model == VMK8061_MODEL) {
715 reg = VMK8061_DI_REG;
716 dev->usb_tx_buf[0] = VMK8061_CMD_RD_DI;
717 } else {
718 reg = VMK8055_DI_REG;
719 }
720 for (n = 0; n < insn->n; n++) {
721 if (vmk80xx_read_packet(dev))
722 break;
723
724 if (dev->board.model == VMK8055_MODEL)
725 inp = (((rx_buf[reg] >> 4) & 0x03) |
726 ((rx_buf[reg] << 2) & 0x04) |
727 ((rx_buf[reg] >> 3) & 0x18));
728 else
729 inp = rx_buf[reg];
730
731 data[n] = (inp >> chan) & 1;
732 }
733
734 up(&dev->limit_sem);
735
736 return n;
737}
738
739static int vmk80xx_do_winsn(struct comedi_device *cdev,
740 struct comedi_subdevice *s,
741 struct comedi_insn *insn, unsigned int *data)
742{
743 struct vmk80xx_usb *dev = cdev->private;
744 int chan;
745 unsigned char *tx_buf;
746 int reg;
747 int cmd;
748 int n;
749
750 n = rudimentary_check(dev, DIR_OUT);
751 if (n)
752 return n;
753
754 down(&dev->limit_sem);
755 chan = CR_CHAN(insn->chanspec);
756
757 tx_buf = dev->usb_tx_buf;
758
759 for (n = 0; n < insn->n; n++) {
760 if (dev->board.model == VMK8055_MODEL) {
761 reg = VMK8055_DO_REG;
762 cmd = VMK8055_CMD_WRT_AD;
763 if (data[n] == 1)
764 tx_buf[reg] |= (1 << chan);
765 else
766 tx_buf[reg] ^= (1 << chan);
767 } else { /* VMK8061_MODEL */
768 reg = VMK8061_DO_REG;
769 if (data[n] == 1) {
770 cmd = VMK8061_CMD_SET_DO;
771 tx_buf[reg] = 1 << chan;
772 } else {
773 cmd = VMK8061_CMD_CLR_DO;
774 tx_buf[reg] = 0xff - (1 << chan);
775 }
776 }
777
778 if (vmk80xx_write_packet(dev, cmd))
779 break;
780 }
781
782 up(&dev->limit_sem);
783
784 return n;
785}
786
787static int vmk80xx_do_rinsn(struct comedi_device *cdev,
788 struct comedi_subdevice *s,
789 struct comedi_insn *insn, unsigned int *data)
790{
791 struct vmk80xx_usb *dev = cdev->private;
792 int chan;
793 int reg;
794 int n;
795
796 n = rudimentary_check(dev, DIR_IN);
797 if (n)
798 return n;
799
800 down(&dev->limit_sem);
801 chan = CR_CHAN(insn->chanspec);
802
803 reg = VMK8061_DO_REG;
804
805 dev->usb_tx_buf[0] = VMK8061_CMD_RD_DO;
806
807 for (n = 0; n < insn->n; n++) {
808 if (vmk80xx_read_packet(dev))
809 break;
810
811 data[n] = (dev->usb_rx_buf[reg] >> chan) & 1;
812 }
813
814 up(&dev->limit_sem);
815
816 return n;
817}
818
819static int vmk80xx_do_bits(struct comedi_device *cdev,
820 struct comedi_subdevice *s,
821 struct comedi_insn *insn, unsigned int *data)
822{
823 struct vmk80xx_usb *dev = cdev->private;
824 unsigned char *rx_buf, *tx_buf; 474 unsigned char *rx_buf, *tx_buf;
825 int dir, reg, cmd; 475 int reg, cmd;
826 int retval; 476 int retval;
827 477
828 dir = 0; 478 if (devpriv->model == VMK8061_MODEL) {
829 479 reg = VMK8061_DO_REG;
830 if (data[0]) 480 cmd = VMK8061_CMD_DO;
831 dir |= DIR_OUT; 481 } else { /* VMK8055_MODEL */
832 482 reg = VMK8055_DO_REG;
833 if (dev->board.model == VMK8061_MODEL) 483 cmd = VMK8055_CMD_WRT_AD;
834 dir |= DIR_IN; 484 }
835
836 retval = rudimentary_check(dev, dir);
837 if (retval)
838 return retval;
839 485
840 down(&dev->limit_sem); 486 down(&devpriv->limit_sem);
841 487
842 rx_buf = dev->usb_rx_buf; 488 rx_buf = devpriv->usb_rx_buf;
843 tx_buf = dev->usb_tx_buf; 489 tx_buf = devpriv->usb_tx_buf;
844 490
845 if (data[0]) { 491 if (data[0]) {
846 if (dev->board.model == VMK8055_MODEL) {
847 reg = VMK8055_DO_REG;
848 cmd = VMK8055_CMD_WRT_AD;
849 } else { /* VMK8061_MODEL */
850 reg = VMK8061_DO_REG;
851 cmd = VMK8061_CMD_DO;
852 }
853
854 tx_buf[reg] &= ~data[0]; 492 tx_buf[reg] &= ~data[0];
855 tx_buf[reg] |= (data[0] & data[1]); 493 tx_buf[reg] |= (data[0] & data[1]);
856 494
857 retval = vmk80xx_write_packet(dev, cmd); 495 retval = vmk80xx_write_packet(devpriv, cmd);
858 496
859 if (retval) 497 if (retval)
860 goto out; 498 goto out;
861 } 499 }
862 500
863 if (dev->board.model == VMK8061_MODEL) { 501 if (devpriv->model == VMK8061_MODEL) {
864 reg = VMK8061_DO_REG;
865 tx_buf[0] = VMK8061_CMD_RD_DO; 502 tx_buf[0] = VMK8061_CMD_RD_DO;
866 503
867 retval = vmk80xx_read_packet(dev); 504 retval = vmk80xx_read_packet(devpriv);
868 505
869 if (!retval) { 506 if (!retval) {
870 data[1] = rx_buf[reg]; 507 data[1] = rx_buf[reg];
@@ -876,28 +513,25 @@ static int vmk80xx_do_bits(struct comedi_device *cdev,
876 } 513 }
877 514
878out: 515out:
879 up(&dev->limit_sem); 516 up(&devpriv->limit_sem);
880 517
881 return retval; 518 return retval;
882} 519}
883 520
884static int vmk80xx_cnt_rinsn(struct comedi_device *cdev, 521static int vmk80xx_cnt_insn_read(struct comedi_device *dev,
885 struct comedi_subdevice *s, 522 struct comedi_subdevice *s,
886 struct comedi_insn *insn, unsigned int *data) 523 struct comedi_insn *insn,
524 unsigned int *data)
887{ 525{
888 struct vmk80xx_usb *dev = cdev->private; 526 struct vmk80xx_private *devpriv = dev->private;
889 int chan; 527 int chan;
890 int reg[2]; 528 int reg[2];
891 int n; 529 int n;
892 530
893 n = rudimentary_check(dev, DIR_IN); 531 down(&devpriv->limit_sem);
894 if (n)
895 return n;
896
897 down(&dev->limit_sem);
898 chan = CR_CHAN(insn->chanspec); 532 chan = CR_CHAN(insn->chanspec);
899 533
900 switch (dev->board.model) { 534 switch (devpriv->model) {
901 case VMK8055_MODEL: 535 case VMK8055_MODEL:
902 if (!chan) 536 if (!chan)
903 reg[0] = VMK8055_CNT1_REG; 537 reg[0] = VMK8055_CNT1_REG;
@@ -908,50 +542,47 @@ static int vmk80xx_cnt_rinsn(struct comedi_device *cdev,
908 default: 542 default:
909 reg[0] = VMK8061_CNT_REG; 543 reg[0] = VMK8061_CNT_REG;
910 reg[1] = VMK8061_CNT_REG; 544 reg[1] = VMK8061_CNT_REG;
911 dev->usb_tx_buf[0] = VMK8061_CMD_RD_CNT; 545 devpriv->usb_tx_buf[0] = VMK8061_CMD_RD_CNT;
912 break; 546 break;
913 } 547 }
914 548
915 for (n = 0; n < insn->n; n++) { 549 for (n = 0; n < insn->n; n++) {
916 if (vmk80xx_read_packet(dev)) 550 if (vmk80xx_read_packet(devpriv))
917 break; 551 break;
918 552
919 if (dev->board.model == VMK8055_MODEL) 553 if (devpriv->model == VMK8055_MODEL)
920 data[n] = dev->usb_rx_buf[reg[0]]; 554 data[n] = devpriv->usb_rx_buf[reg[0]];
921 else /* VMK8061_MODEL */ 555 else /* VMK8061_MODEL */
922 data[n] = dev->usb_rx_buf[reg[0] * (chan + 1) + 1] 556 data[n] = devpriv->usb_rx_buf[reg[0] * (chan + 1) + 1]
923 + 256 * dev->usb_rx_buf[reg[1] * 2 + 2]; 557 + 256 * devpriv->usb_rx_buf[reg[1] * 2 + 2];
924 } 558 }
925 559
926 up(&dev->limit_sem); 560 up(&devpriv->limit_sem);
927 561
928 return n; 562 return n;
929} 563}
930 564
931static int vmk80xx_cnt_cinsn(struct comedi_device *cdev, 565static int vmk80xx_cnt_insn_config(struct comedi_device *dev,
932 struct comedi_subdevice *s, 566 struct comedi_subdevice *s,
933 struct comedi_insn *insn, unsigned int *data) 567 struct comedi_insn *insn,
568 unsigned int *data)
934{ 569{
935 struct vmk80xx_usb *dev = cdev->private; 570 struct vmk80xx_private *devpriv = dev->private;
936 unsigned int insn_cmd; 571 unsigned int insn_cmd;
937 int chan; 572 int chan;
938 int cmd; 573 int cmd;
939 int reg; 574 int reg;
940 int n; 575 int n;
941 576
942 n = rudimentary_check(dev, DIR_OUT);
943 if (n)
944 return n;
945
946 insn_cmd = data[0]; 577 insn_cmd = data[0];
947 if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET) 578 if (insn_cmd != INSN_CONFIG_RESET && insn_cmd != GPCT_RESET)
948 return -EINVAL; 579 return -EINVAL;
949 580
950 down(&dev->limit_sem); 581 down(&devpriv->limit_sem);
951 582
952 chan = CR_CHAN(insn->chanspec); 583 chan = CR_CHAN(insn->chanspec);
953 584
954 if (dev->board.model == VMK8055_MODEL) { 585 if (devpriv->model == VMK8055_MODEL) {
955 if (!chan) { 586 if (!chan) {
956 cmd = VMK8055_CMD_RST_CNT1; 587 cmd = VMK8055_CMD_RST_CNT1;
957 reg = VMK8055_CNT1_REG; 588 reg = VMK8055_CNT1_REG;
@@ -960,36 +591,33 @@ static int vmk80xx_cnt_cinsn(struct comedi_device *cdev,
960 reg = VMK8055_CNT2_REG; 591 reg = VMK8055_CNT2_REG;
961 } 592 }
962 593
963 dev->usb_tx_buf[reg] = 0x00; 594 devpriv->usb_tx_buf[reg] = 0x00;
964 } else { 595 } else {
965 cmd = VMK8061_CMD_RST_CNT; 596 cmd = VMK8061_CMD_RST_CNT;
966 } 597 }
967 598
968 for (n = 0; n < insn->n; n++) 599 for (n = 0; n < insn->n; n++)
969 if (vmk80xx_write_packet(dev, cmd)) 600 if (vmk80xx_write_packet(devpriv, cmd))
970 break; 601 break;
971 602
972 up(&dev->limit_sem); 603 up(&devpriv->limit_sem);
973 604
974 return n; 605 return n;
975} 606}
976 607
977static int vmk80xx_cnt_winsn(struct comedi_device *cdev, 608static int vmk80xx_cnt_insn_write(struct comedi_device *dev,
978 struct comedi_subdevice *s, 609 struct comedi_subdevice *s,
979 struct comedi_insn *insn, unsigned int *data) 610 struct comedi_insn *insn,
611 unsigned int *data)
980{ 612{
981 struct vmk80xx_usb *dev = cdev->private; 613 struct vmk80xx_private *devpriv = dev->private;
982 unsigned long debtime; 614 unsigned long debtime;
983 unsigned long val; 615 unsigned long val;
984 int chan; 616 int chan;
985 int cmd; 617 int cmd;
986 int n; 618 int n;
987 619
988 n = rudimentary_check(dev, DIR_OUT); 620 down(&devpriv->limit_sem);
989 if (n)
990 return n;
991
992 down(&dev->limit_sem);
993 chan = CR_CHAN(insn->chanspec); 621 chan = CR_CHAN(insn->chanspec);
994 622
995 if (!chan) 623 if (!chan)
@@ -1010,65 +638,64 @@ static int vmk80xx_cnt_winsn(struct comedi_device *cdev,
1010 if (((val + 1) * val) < debtime * 1000 / 115) 638 if (((val + 1) * val) < debtime * 1000 / 115)
1011 val += 1; 639 val += 1;
1012 640
1013 dev->usb_tx_buf[6 + chan] = val; 641 devpriv->usb_tx_buf[6 + chan] = val;
1014 642
1015 if (vmk80xx_write_packet(dev, cmd)) 643 if (vmk80xx_write_packet(devpriv, cmd))
1016 break; 644 break;
1017 } 645 }
1018 646
1019 up(&dev->limit_sem); 647 up(&devpriv->limit_sem);
1020 648
1021 return n; 649 return n;
1022} 650}
1023 651
1024static int vmk80xx_pwm_rinsn(struct comedi_device *cdev, 652static int vmk80xx_pwm_insn_read(struct comedi_device *dev,
1025 struct comedi_subdevice *s, 653 struct comedi_subdevice *s,
1026 struct comedi_insn *insn, unsigned int *data) 654 struct comedi_insn *insn,
655 unsigned int *data)
1027{ 656{
1028 struct vmk80xx_usb *dev = cdev->private; 657 struct vmk80xx_private *devpriv = dev->private;
658 unsigned char *tx_buf;
659 unsigned char *rx_buf;
1029 int reg[2]; 660 int reg[2];
1030 int n; 661 int n;
1031 662
1032 n = rudimentary_check(dev, DIR_IN); 663 down(&devpriv->limit_sem);
1033 if (n)
1034 return n;
1035 664
1036 down(&dev->limit_sem); 665 tx_buf = devpriv->usb_tx_buf;
666 rx_buf = devpriv->usb_rx_buf;
1037 667
1038 reg[0] = VMK8061_PWM_REG1; 668 reg[0] = VMK8061_PWM_REG1;
1039 reg[1] = VMK8061_PWM_REG2; 669 reg[1] = VMK8061_PWM_REG2;
1040 670
1041 dev->usb_tx_buf[0] = VMK8061_CMD_RD_PWM; 671 tx_buf[0] = VMK8061_CMD_RD_PWM;
1042 672
1043 for (n = 0; n < insn->n; n++) { 673 for (n = 0; n < insn->n; n++) {
1044 if (vmk80xx_read_packet(dev)) 674 if (vmk80xx_read_packet(devpriv))
1045 break; 675 break;
1046 676
1047 data[n] = dev->usb_rx_buf[reg[0]] + 4 * dev->usb_rx_buf[reg[1]]; 677 data[n] = rx_buf[reg[0]] + 4 * rx_buf[reg[1]];
1048 } 678 }
1049 679
1050 up(&dev->limit_sem); 680 up(&devpriv->limit_sem);
1051 681
1052 return n; 682 return n;
1053} 683}
1054 684
1055static int vmk80xx_pwm_winsn(struct comedi_device *cdev, 685static int vmk80xx_pwm_insn_write(struct comedi_device *dev,
1056 struct comedi_subdevice *s, 686 struct comedi_subdevice *s,
1057 struct comedi_insn *insn, unsigned int *data) 687 struct comedi_insn *insn,
688 unsigned int *data)
1058{ 689{
1059 struct vmk80xx_usb *dev = cdev->private; 690 struct vmk80xx_private *devpriv = dev->private;
1060 unsigned char *tx_buf; 691 unsigned char *tx_buf;
1061 int reg[2]; 692 int reg[2];
1062 int cmd; 693 int cmd;
1063 int n; 694 int n;
1064 695
1065 n = rudimentary_check(dev, DIR_OUT); 696 down(&devpriv->limit_sem);
1066 if (n)
1067 return n;
1068
1069 down(&dev->limit_sem);
1070 697
1071 tx_buf = dev->usb_tx_buf; 698 tx_buf = devpriv->usb_tx_buf;
1072 699
1073 reg[0] = VMK8061_PWM_REG1; 700 reg[0] = VMK8061_PWM_REG1;
1074 reg[1] = VMK8061_PWM_REG2; 701 reg[1] = VMK8061_PWM_REG2;
@@ -1092,341 +719,236 @@ static int vmk80xx_pwm_winsn(struct comedi_device *cdev,
1092 tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03); 719 tx_buf[reg[0]] = (unsigned char)(data[n] & 0x03);
1093 tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff; 720 tx_buf[reg[1]] = (unsigned char)(data[n] >> 2) & 0xff;
1094 721
1095 if (vmk80xx_write_packet(dev, cmd)) 722 if (vmk80xx_write_packet(devpriv, cmd))
1096 break; 723 break;
1097 } 724 }
1098 725
1099 up(&dev->limit_sem); 726 up(&devpriv->limit_sem);
1100 727
1101 return n; 728 return n;
1102} 729}
1103 730
1104static int vmk80xx_attach_common(struct comedi_device *cdev, 731static int vmk80xx_find_usb_endpoints(struct comedi_device *dev)
1105 struct vmk80xx_usb *dev)
1106{ 732{
1107 int n_subd; 733 struct vmk80xx_private *devpriv = dev->private;
1108 struct comedi_subdevice *s; 734 struct usb_interface *intf = devpriv->intf;
1109 int ret; 735 struct usb_host_interface *iface_desc = intf->cur_altsetting;
736 struct usb_endpoint_descriptor *ep_desc;
737 int i;
1110 738
1111 down(&dev->limit_sem); 739 if (iface_desc->desc.bNumEndpoints != 2)
1112 cdev->board_name = dev->board.name; 740 return -ENODEV;
1113 cdev->private = dev;
1114 if (dev->board.model == VMK8055_MODEL)
1115 n_subd = 5;
1116 else
1117 n_subd = 6;
1118 ret = comedi_alloc_subdevices(cdev, n_subd);
1119 if (ret) {
1120 up(&dev->limit_sem);
1121 return ret;
1122 }
1123 /* Analog input subdevice */
1124 s = &cdev->subdevices[VMK80XX_SUBD_AI];
1125 s->type = COMEDI_SUBD_AI;
1126 s->subdev_flags = SDF_READABLE | SDF_GROUND;
1127 s->n_chan = dev->board.ai_chans;
1128 s->maxdata = (1 << dev->board.ai_bits) - 1;
1129 s->range_table = dev->board.range;
1130 s->insn_read = vmk80xx_ai_rinsn;
1131 /* Analog output subdevice */
1132 s = &cdev->subdevices[VMK80XX_SUBD_AO];
1133 s->type = COMEDI_SUBD_AO;
1134 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
1135 s->n_chan = dev->board.ao_chans;
1136 s->maxdata = (1 << dev->board.ao_bits) - 1;
1137 s->range_table = dev->board.range;
1138 s->insn_write = vmk80xx_ao_winsn;
1139 if (dev->board.model == VMK8061_MODEL) {
1140 s->subdev_flags |= SDF_READABLE;
1141 s->insn_read = vmk80xx_ao_rinsn;
1142 }
1143 /* Digital input subdevice */
1144 s = &cdev->subdevices[VMK80XX_SUBD_DI];
1145 s->type = COMEDI_SUBD_DI;
1146 s->subdev_flags = SDF_READABLE | SDF_GROUND;
1147 s->n_chan = dev->board.di_chans;
1148 s->maxdata = 1;
1149 s->insn_read = vmk80xx_di_rinsn;
1150 s->insn_bits = vmk80xx_di_bits;
1151 /* Digital output subdevice */
1152 s = &cdev->subdevices[VMK80XX_SUBD_DO];
1153 s->type = COMEDI_SUBD_DO;
1154 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
1155 s->n_chan = dev->board.do_chans;
1156 s->maxdata = 1;
1157 s->insn_write = vmk80xx_do_winsn;
1158 s->insn_bits = vmk80xx_do_bits;
1159 if (dev->board.model == VMK8061_MODEL) {
1160 s->subdev_flags |= SDF_READABLE;
1161 s->insn_read = vmk80xx_do_rinsn;
1162 }
1163 /* Counter subdevice */
1164 s = &cdev->subdevices[VMK80XX_SUBD_CNT];
1165 s->type = COMEDI_SUBD_COUNTER;
1166 s->subdev_flags = SDF_READABLE;
1167 s->n_chan = dev->board.cnt_chans;
1168 s->insn_read = vmk80xx_cnt_rinsn;
1169 s->insn_config = vmk80xx_cnt_cinsn;
1170 if (dev->board.model == VMK8055_MODEL) {
1171 s->subdev_flags |= SDF_WRITEABLE;
1172 s->maxdata = (1 << dev->board.cnt_bits) - 1;
1173 s->insn_write = vmk80xx_cnt_winsn;
1174 }
1175 /* PWM subdevice */
1176 if (dev->board.model == VMK8061_MODEL) {
1177 s = &cdev->subdevices[VMK80XX_SUBD_PWM];
1178 s->type = COMEDI_SUBD_PWM;
1179 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE;
1180 s->n_chan = dev->board.pwm_chans;
1181 s->maxdata = (1 << dev->board.pwm_bits) - 1;
1182 s->insn_read = vmk80xx_pwm_rinsn;
1183 s->insn_write = vmk80xx_pwm_winsn;
1184 }
1185 dev->attached = 1;
1186 dev_info(cdev->class_dev, "vmk80xx: board #%d [%s] attached\n",
1187 dev->count, dev->board.name);
1188 up(&dev->limit_sem);
1189 return 0;
1190}
1191 741
1192/* called for COMEDI_DEVCONFIG ioctl for board_name "vmk80xx" */ 742 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
1193static int vmk80xx_attach(struct comedi_device *cdev, 743 ep_desc = &iface_desc->endpoint[i].desc;
1194 struct comedi_devconfig *it)
1195{
1196 int i;
1197 int ret;
1198 744
1199 mutex_lock(&glb_mutex); 745 if (usb_endpoint_is_int_in(ep_desc) ||
1200 for (i = 0; i < VMK80XX_MAX_BOARDS; i++) 746 usb_endpoint_is_bulk_in(ep_desc)) {
1201 if (vmb[i].probed && !vmb[i].attached) 747 if (!devpriv->ep_rx)
1202 break; 748 devpriv->ep_rx = ep_desc;
1203 if (i == VMK80XX_MAX_BOARDS) 749 continue;
1204 ret = -ENODEV; 750 }
1205 else
1206 ret = vmk80xx_attach_common(cdev, &vmb[i]);
1207 mutex_unlock(&glb_mutex);
1208 return ret;
1209}
1210 751
1211/* called via comedi_usb_auto_config() */ 752 if (usb_endpoint_is_int_out(ep_desc) ||
1212static int vmk80xx_auto_attach(struct comedi_device *cdev, 753 usb_endpoint_is_bulk_out(ep_desc)) {
1213 unsigned long context_unused) 754 if (!devpriv->ep_tx)
1214{ 755 devpriv->ep_tx = ep_desc;
1215 struct usb_interface *intf = comedi_to_usb_interface(cdev); 756 continue;
1216 int i; 757 }
1217 int ret; 758 }
1218 759
1219 mutex_lock(&glb_mutex); 760 if (!devpriv->ep_rx || !devpriv->ep_tx)
1220 for (i = 0; i < VMK80XX_MAX_BOARDS; i++) 761 return -ENODEV;
1221 if (vmb[i].probed && vmb[i].intf == intf) 762
1222 break; 763 return 0;
1223 if (i == VMK80XX_MAX_BOARDS)
1224 ret = -ENODEV;
1225 else if (vmb[i].attached)
1226 ret = -EBUSY;
1227 else
1228 ret = vmk80xx_attach_common(cdev, &vmb[i]);
1229 mutex_unlock(&glb_mutex);
1230 return ret;
1231} 764}
1232 765
1233static void vmk80xx_detach(struct comedi_device *dev) 766static int vmk80xx_alloc_usb_buffers(struct comedi_device *dev)
1234{ 767{
1235 struct vmk80xx_usb *usb = dev->private; 768 struct vmk80xx_private *devpriv = dev->private;
769 size_t size;
770
771 size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize);
772 devpriv->usb_rx_buf = kzalloc(size, GFP_KERNEL);
773 if (!devpriv->usb_rx_buf)
774 return -ENOMEM;
1236 775
1237 if (usb) { 776 size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
1238 down(&usb->limit_sem); 777 devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL);
1239 dev->private = NULL; 778 if (!devpriv->usb_tx_buf) {
1240 usb->attached = 0; 779 kfree(devpriv->usb_rx_buf);
1241 up(&usb->limit_sem); 780 return -ENOMEM;
1242 } 781 }
1243}
1244 782
1245static struct comedi_driver vmk80xx_driver = { 783 return 0;
1246 .module = THIS_MODULE, 784}
1247 .driver_name = "vmk80xx",
1248 .attach = vmk80xx_attach,
1249 .detach = vmk80xx_detach,
1250 .auto_attach = vmk80xx_auto_attach,
1251};
1252 785
1253static int vmk80xx_usb_probe(struct usb_interface *intf, 786static int vmk80xx_init_subdevices(struct comedi_device *dev)
1254 const struct usb_device_id *id)
1255{ 787{
1256 int i; 788 const struct vmk80xx_board *boardinfo = comedi_board(dev);
1257 struct vmk80xx_usb *dev; 789 struct vmk80xx_private *devpriv = dev->private;
1258 struct usb_host_interface *iface_desc; 790 struct comedi_subdevice *s;
1259 struct usb_endpoint_descriptor *ep_desc; 791 int n_subd;
1260 size_t size; 792 int ret;
1261
1262 mutex_lock(&glb_mutex);
1263 793
1264 for (i = 0; i < VMK80XX_MAX_BOARDS; i++) 794 down(&devpriv->limit_sem);
1265 if (!vmb[i].probed)
1266 break;
1267 795
1268 if (i == VMK80XX_MAX_BOARDS) { 796 if (devpriv->model == VMK8055_MODEL)
1269 mutex_unlock(&glb_mutex); 797 n_subd = 5;
1270 return -EMFILE; 798 else
799 n_subd = 6;
800 ret = comedi_alloc_subdevices(dev, n_subd);
801 if (ret) {
802 up(&devpriv->limit_sem);
803 return ret;
1271 } 804 }
1272 805
1273 dev = &vmb[i]; 806 /* Analog input subdevice */
807 s = &dev->subdevices[0];
808 s->type = COMEDI_SUBD_AI;
809 s->subdev_flags = SDF_READABLE | SDF_GROUND;
810 s->n_chan = boardinfo->ai_nchans;
811 s->maxdata = boardinfo->ai_maxdata;
812 s->range_table = boardinfo->range;
813 s->insn_read = vmk80xx_ai_insn_read;
1274 814
1275 memset(dev, 0x00, sizeof(struct vmk80xx_usb)); 815 /* Analog output subdevice */
1276 dev->count = i; 816 s = &dev->subdevices[1];
817 s->type = COMEDI_SUBD_AO;
818 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND;
819 s->n_chan = boardinfo->ao_nchans;
820 s->maxdata = 0x00ff;
821 s->range_table = boardinfo->range;
822 s->insn_write = vmk80xx_ao_insn_write;
823 if (devpriv->model == VMK8061_MODEL) {
824 s->subdev_flags |= SDF_READABLE;
825 s->insn_read = vmk80xx_ao_insn_read;
826 }
1277 827
1278 iface_desc = intf->cur_altsetting; 828 /* Digital input subdevice */
1279 if (iface_desc->desc.bNumEndpoints != 2) 829 s = &dev->subdevices[2];
1280 goto error; 830 s->type = COMEDI_SUBD_DI;
831 s->subdev_flags = SDF_READABLE;
832 s->n_chan = boardinfo->di_nchans;
833 s->maxdata = 1;
834 s->range_table = &range_digital;
835 s->insn_bits = vmk80xx_di_insn_bits;
1281 836
1282 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 837 /* Digital output subdevice */
1283 ep_desc = &iface_desc->endpoint[i].desc; 838 s = &dev->subdevices[3];
839 s->type = COMEDI_SUBD_DO;
840 s->subdev_flags = SDF_WRITEABLE;
841 s->n_chan = 8;
842 s->maxdata = 1;
843 s->range_table = &range_digital;
844 s->insn_bits = vmk80xx_do_insn_bits;
1284 845
1285 if (usb_endpoint_is_int_in(ep_desc)) { 846 /* Counter subdevice */
1286 dev->ep_rx = ep_desc; 847 s = &dev->subdevices[4];
1287 continue; 848 s->type = COMEDI_SUBD_COUNTER;
1288 } 849 s->subdev_flags = SDF_READABLE;
850 s->n_chan = 2;
851 s->maxdata = boardinfo->cnt_maxdata;
852 s->insn_read = vmk80xx_cnt_insn_read;
853 s->insn_config = vmk80xx_cnt_insn_config;
854 if (devpriv->model == VMK8055_MODEL) {
855 s->subdev_flags |= SDF_WRITEABLE;
856 s->insn_write = vmk80xx_cnt_insn_write;
857 }
1289 858
1290 if (usb_endpoint_is_int_out(ep_desc)) { 859 /* PWM subdevice */
1291 dev->ep_tx = ep_desc; 860 if (devpriv->model == VMK8061_MODEL) {
1292 continue; 861 s = &dev->subdevices[5];
1293 } 862 s->type = COMEDI_SUBD_PWM;
863 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE;
864 s->n_chan = boardinfo->pwm_nchans;
865 s->maxdata = boardinfo->pwm_maxdata;
866 s->insn_read = vmk80xx_pwm_insn_read;
867 s->insn_write = vmk80xx_pwm_insn_write;
868 }
1294 869
1295 if (usb_endpoint_is_bulk_in(ep_desc)) { 870 up(&devpriv->limit_sem);
1296 dev->ep_rx = ep_desc;
1297 continue;
1298 }
1299 871
1300 if (usb_endpoint_is_bulk_out(ep_desc)) { 872 return 0;
1301 dev->ep_tx = ep_desc; 873}
1302 continue;
1303 }
1304 }
1305 874
1306 if (!dev->ep_rx || !dev->ep_tx) 875static int vmk80xx_auto_attach(struct comedi_device *dev,
1307 goto error; 876 unsigned long context)
877{
878 struct usb_interface *intf = comedi_to_usb_interface(dev);
879 const struct vmk80xx_board *boardinfo;
880 struct vmk80xx_private *devpriv;
881 int ret;
1308 882
1309 size = le16_to_cpu(dev->ep_rx->wMaxPacketSize); 883 boardinfo = &vmk80xx_boardinfo[context];
1310 dev->usb_rx_buf = kmalloc(size, GFP_KERNEL); 884 dev->board_ptr = boardinfo;
1311 if (!dev->usb_rx_buf) { 885 dev->board_name = boardinfo->name;
1312 mutex_unlock(&glb_mutex);
1313 return -ENOMEM;
1314 }
1315 886
1316 size = le16_to_cpu(dev->ep_tx->wMaxPacketSize); 887 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
1317 dev->usb_tx_buf = kmalloc(size, GFP_KERNEL); 888 if (!devpriv)
1318 if (!dev->usb_tx_buf) {
1319 kfree(dev->usb_rx_buf);
1320 mutex_unlock(&glb_mutex);
1321 return -ENOMEM; 889 return -ENOMEM;
1322 } 890 dev->private = devpriv;
1323
1324 dev->udev = interface_to_usbdev(intf);
1325 dev->intf = intf;
1326
1327 sema_init(&dev->limit_sem, 8);
1328 init_waitqueue_head(&dev->read_wait);
1329 init_waitqueue_head(&dev->write_wait);
1330
1331 init_usb_anchor(&dev->rx_anchor);
1332 init_usb_anchor(&dev->tx_anchor);
1333
1334 usb_set_intfdata(intf, dev);
1335
1336 switch (id->driver_info) {
1337 case DEVICE_VMK8055:
1338 dev->board.name = "K8055 (VM110)";
1339 dev->board.model = VMK8055_MODEL;
1340 dev->board.range = &vmk8055_range;
1341 dev->board.ai_chans = 2;
1342 dev->board.ai_bits = 8;
1343 dev->board.ao_chans = 2;
1344 dev->board.ao_bits = 8;
1345 dev->board.di_chans = 5;
1346 dev->board.di_bits = 1;
1347 dev->board.do_chans = 8;
1348 dev->board.do_bits = 1;
1349 dev->board.cnt_chans = 2;
1350 dev->board.cnt_bits = 16;
1351 dev->board.pwm_chans = 0;
1352 dev->board.pwm_bits = 0;
1353 break;
1354 case DEVICE_VMK8061:
1355 dev->board.name = "K8061 (VM140)";
1356 dev->board.model = VMK8061_MODEL;
1357 dev->board.range = &vmk8061_range;
1358 dev->board.ai_chans = 8;
1359 dev->board.ai_bits = 10;
1360 dev->board.ao_chans = 8;
1361 dev->board.ao_bits = 8;
1362 dev->board.di_chans = 8;
1363 dev->board.di_bits = 1;
1364 dev->board.do_chans = 8;
1365 dev->board.do_bits = 1;
1366 dev->board.cnt_chans = 2;
1367 dev->board.cnt_bits = 0;
1368 dev->board.pwm_chans = 1;
1369 dev->board.pwm_bits = 10;
1370 break;
1371 }
1372 891
1373 if (dev->board.model == VMK8061_MODEL) { 892 devpriv->usb = interface_to_usbdev(intf);
1374 vmk80xx_read_eeprom(dev, IC3_VERSION); 893 devpriv->intf = intf;
1375 dev_info(&intf->dev, "%s\n", dev->fw.ic3_vers); 894 devpriv->model = boardinfo->model;
1376 895
1377 if (vmk80xx_check_data_link(dev)) { 896 ret = vmk80xx_find_usb_endpoints(dev);
1378 vmk80xx_read_eeprom(dev, IC6_VERSION); 897 if (ret)
1379 dev_info(&intf->dev, "%s\n", dev->fw.ic6_vers); 898 return ret;
1380 } else {
1381 dbgcm("comedi#: vmk80xx: no conn. to CPU\n");
1382 }
1383 }
1384 899
1385 if (dev->board.model == VMK8055_MODEL) 900 ret = vmk80xx_alloc_usb_buffers(dev);
1386 vmk80xx_reset_device(dev); 901 if (ret)
902 return ret;
1387 903
1388 dev->probed = 1; 904 sema_init(&devpriv->limit_sem, 8);
1389 905
1390 dev_info(&intf->dev, "board #%d [%s] now attached\n", 906 usb_set_intfdata(intf, devpriv);
1391 dev->count, dev->board.name);
1392 907
1393 mutex_unlock(&glb_mutex); 908 if (devpriv->model == VMK8061_MODEL) {
909 vmk80xx_read_eeprom(devpriv, IC3_VERSION);
910 dev_info(&intf->dev, "%s\n", devpriv->fw.ic3_vers);
1394 911
1395 comedi_usb_auto_config(intf, &vmk80xx_driver); 912 if (vmk80xx_check_data_link(devpriv)) {
913 vmk80xx_read_eeprom(devpriv, IC6_VERSION);
914 dev_info(&intf->dev, "%s\n", devpriv->fw.ic6_vers);
915 }
916 }
1396 917
1397 return 0; 918 if (devpriv->model == VMK8055_MODEL)
1398error: 919 vmk80xx_reset_device(devpriv);
1399 mutex_unlock(&glb_mutex);
1400 920
1401 return -ENODEV; 921 return vmk80xx_init_subdevices(dev);
1402} 922}
1403 923
1404static void vmk80xx_usb_disconnect(struct usb_interface *intf) 924static void vmk80xx_detach(struct comedi_device *dev)
1405{ 925{
1406 struct vmk80xx_usb *dev = usb_get_intfdata(intf); 926 struct vmk80xx_private *devpriv = dev->private;
1407 927
1408 if (!dev) 928 if (!devpriv)
1409 return; 929 return;
1410 930
1411 comedi_usb_auto_unconfig(intf); 931 down(&devpriv->limit_sem);
1412
1413 mutex_lock(&glb_mutex);
1414 down(&dev->limit_sem);
1415 932
1416 dev->probed = 0; 933 usb_set_intfdata(devpriv->intf, NULL);
1417 usb_set_intfdata(dev->intf, NULL);
1418 934
1419 usb_kill_anchored_urbs(&dev->rx_anchor); 935 kfree(devpriv->usb_rx_buf);
1420 usb_kill_anchored_urbs(&dev->tx_anchor); 936 kfree(devpriv->usb_tx_buf);
1421 937
1422 kfree(dev->usb_rx_buf); 938 up(&devpriv->limit_sem);
1423 kfree(dev->usb_tx_buf); 939}
1424 940
1425 dev_info(&intf->dev, "board #%d [%s] now detached\n", 941static struct comedi_driver vmk80xx_driver = {
1426 dev->count, dev->board.name); 942 .module = THIS_MODULE,
943 .driver_name = "vmk80xx",
944 .auto_attach = vmk80xx_auto_attach,
945 .detach = vmk80xx_detach,
946};
1427 947
1428 up(&dev->limit_sem); 948static int vmk80xx_usb_probe(struct usb_interface *intf,
1429 mutex_unlock(&glb_mutex); 949 const struct usb_device_id *id)
950{
951 return comedi_usb_auto_config(intf, &vmk80xx_driver, id->driver_info);
1430} 952}
1431 953
1432static const struct usb_device_id vmk80xx_usb_id_table[] = { 954static const struct usb_device_id vmk80xx_usb_id_table[] = {
@@ -1446,13 +968,11 @@ static const struct usb_device_id vmk80xx_usb_id_table[] = {
1446}; 968};
1447MODULE_DEVICE_TABLE(usb, vmk80xx_usb_id_table); 969MODULE_DEVICE_TABLE(usb, vmk80xx_usb_id_table);
1448 970
1449/* TODO: Add support for suspend, resume, pre_reset,
1450 * post_reset and flush */
1451static struct usb_driver vmk80xx_usb_driver = { 971static struct usb_driver vmk80xx_usb_driver = {
1452 .name = "vmk80xx", 972 .name = "vmk80xx",
1453 .probe = vmk80xx_usb_probe,
1454 .disconnect = vmk80xx_usb_disconnect,
1455 .id_table = vmk80xx_usb_id_table, 973 .id_table = vmk80xx_usb_id_table,
974 .probe = vmk80xx_usb_probe,
975 .disconnect = comedi_usb_auto_unconfig,
1456}; 976};
1457module_comedi_usb_driver(vmk80xx_driver, vmk80xx_usb_driver); 977module_comedi_usb_driver(vmk80xx_driver, vmk80xx_usb_driver);
1458 978
diff --git a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c
index 4dc09a210883..8932a510d96c 100644
--- a/drivers/staging/comedi/kcomedilib/kcomedilib_main.c
+++ b/drivers/staging/comedi/kcomedilib/kcomedilib_main.c
@@ -42,7 +42,6 @@ MODULE_LICENSE("GPL");
42 42
43struct comedi_device *comedi_open(const char *filename) 43struct comedi_device *comedi_open(const char *filename)
44{ 44{
45 struct comedi_device_file_info *dev_file_info;
46 struct comedi_device *dev; 45 struct comedi_device *dev;
47 unsigned int minor; 46 unsigned int minor;
48 47
@@ -54,12 +53,9 @@ struct comedi_device *comedi_open(const char *filename)
54 if (minor >= COMEDI_NUM_BOARD_MINORS) 53 if (minor >= COMEDI_NUM_BOARD_MINORS)
55 return NULL; 54 return NULL;
56 55
57 dev_file_info = comedi_get_device_file_info(minor); 56 dev = comedi_dev_from_minor(minor);
58 if (dev_file_info == NULL)
59 return NULL;
60 dev = dev_file_info->device;
61 57
62 if (dev == NULL || !dev->attached) 58 if (!dev || !dev->attached)
63 return NULL; 59 return NULL;
64 60
65 if (!try_module_get(dev->driver->module)) 61 if (!try_module_get(dev->driver->module))
diff --git a/drivers/staging/comedi/proc.c b/drivers/staging/comedi/proc.c
index 01acbe97653c..362c214bcc0b 100644
--- a/drivers/staging/comedi/proc.c
+++ b/drivers/staging/comedi/proc.c
@@ -33,7 +33,6 @@
33#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
34#include <linux/string.h> 34#include <linux/string.h>
35 35
36#ifdef CONFIG_PROC_FS
37static int comedi_read(char *buf, char **start, off_t offset, int len, 36static int comedi_read(char *buf, char **start, off_t offset, int len,
38 int *eof, void *data) 37 int *eof, void *data)
39{ 38{
@@ -49,13 +48,10 @@ static int comedi_read(char *buf, char **start, off_t offset, int len,
49 "driver_name, board_name, n_subdevices"); 48 "driver_name, board_name, n_subdevices");
50 49
51 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) { 50 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
52 struct comedi_device_file_info *dev_file_info = 51 struct comedi_device *dev = comedi_dev_from_minor(i);
53 comedi_get_device_file_info(i);
54 struct comedi_device *dev;
55 52
56 if (dev_file_info == NULL) 53 if (!dev)
57 continue; 54 continue;
58 dev = dev_file_info->device;
59 55
60 if (dev->attached) { 56 if (dev->attached) {
61 devices_q = 1; 57 devices_q = 1;
@@ -95,4 +91,3 @@ void comedi_proc_cleanup(void)
95{ 91{
96 remove_proc_entry("comedi", NULL); 92 remove_proc_entry("comedi", NULL);
97} 93}
98#endif
diff --git a/drivers/staging/cptm1217/clearpad_tm1217.c b/drivers/staging/cptm1217/clearpad_tm1217.c
index a49b0da60049..31fb5d31bb3a 100644
--- a/drivers/staging/cptm1217/clearpad_tm1217.c
+++ b/drivers/staging/cptm1217/clearpad_tm1217.c
@@ -421,11 +421,8 @@ static int cp_tm1217_probe(struct i2c_client *client,
421 pdata = client->dev.platform_data; 421 pdata = client->dev.platform_data;
422 422
423 ts = kzalloc(sizeof(struct cp_tm1217_device), GFP_KERNEL); 423 ts = kzalloc(sizeof(struct cp_tm1217_device), GFP_KERNEL);
424 if (!ts) { 424 if (!ts)
425 dev_err(&client->dev,
426 "cp_tm1217: Private Device Struct alloc failed\n");
427 return -ENOMEM; 425 return -ENOMEM;
428 }
429 426
430 ts->client = client; 427 ts->client = client;
431 ts->dev = &client->dev; 428 ts->dev = &client->dev;
diff --git a/drivers/staging/csr/drv.c b/drivers/staging/csr/drv.c
index 4780c32c2fe3..3bd52fdeac3b 100644
--- a/drivers/staging/csr/drv.c
+++ b/drivers/staging/csr/drv.c
@@ -819,15 +819,15 @@ unifi_write(struct file *filp, const char *p, size_t len, loff_t *poff)
819 unifi_trace(priv, UDBG2, "unifi_write: signal 0x%.4X len:%d\n", 819 unifi_trace(priv, UDBG2, "unifi_write: signal 0x%.4X len:%d\n",
820 sig_id, signal_size); 820 sig_id, signal_size);
821 821
822 /* Allocate a buffer for the signal */ 822 /* Allocate a buffer for the signal */
823 signal_buf = kmalloc(signal_size, GFP_KERNEL); 823 signal_buf = kmemdup(bulkdata.d[0].os_data_ptr, signal_size,
824 GFP_KERNEL);
824 if (!signal_buf) { 825 if (!signal_buf) {
825 unifi_net_data_free(priv, &bulkdata.d[0]); 826 unifi_net_data_free(priv, &bulkdata.d[0]);
826 return -ENOMEM; 827 return -ENOMEM;
827 } 828 }
828 829
829 /* Get the signal from the os_data_ptr */ 830 /* Get the signal from the os_data_ptr */
830 memcpy(signal_buf, bulkdata.d[0].os_data_ptr, signal_size);
831 signal_buf[5] = (pcli->sender_id >> 8) & 0xff; 831 signal_buf[5] = (pcli->sender_id >> 8) & 0xff;
832 832
833 if (signal_size < len) { 833 if (signal_size < len) {
diff --git a/drivers/staging/csr/sme_sys.c b/drivers/staging/csr/sme_sys.c
index 2b068197ed44..b1151a28d8e3 100644
--- a/drivers/staging/csr/sme_sys.c
+++ b/drivers/staging/csr/sme_sys.c
@@ -280,7 +280,7 @@ void CsrWifiRouterCtrlHipReqHandler(void* drvpriv, CsrWifiFsmEvent* msg)
280 CSR_SIGNAL *signal; 280 CSR_SIGNAL *signal;
281 u16 interfaceTag = 0; 281 u16 interfaceTag = 0;
282 CSR_MA_PACKET_REQUEST *req; 282 CSR_MA_PACKET_REQUEST *req;
283 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; 283 netInterface_priv_t *interfacePriv;
284 284
285 if (priv == NULL) { 285 if (priv == NULL) {
286 return; 286 return;
@@ -294,6 +294,8 @@ void CsrWifiRouterCtrlHipReqHandler(void* drvpriv, CsrWifiFsmEvent* msg)
294 return; 294 return;
295 } 295 }
296 296
297 interfacePriv = priv->interfacePriv[interfaceTag];
298
297 /* Initialize bulkdata to avoid os_net_buf is garbage */ 299 /* Initialize bulkdata to avoid os_net_buf is garbage */
298 memset(&bulkdata, 0, sizeof(bulk_data_param_t)); 300 memset(&bulkdata, 0, sizeof(bulk_data_param_t));
299 301
@@ -1498,7 +1500,7 @@ void CsrWifiRouterMaPacketReqHandler(void* drvpriv, CsrWifiFsmEvent* msg)
1498 u8 *daddr, *saddr; 1500 u8 *daddr, *saddr;
1499 u16 interfaceTag = mareq->interfaceTag & 0x00ff; 1501 u16 interfaceTag = mareq->interfaceTag & 0x00ff;
1500 int queue; 1502 int queue;
1501 netInterface_priv_t *interfacePriv = priv->interfacePriv[interfaceTag]; 1503 netInterface_priv_t *interfacePriv;
1502 1504
1503 if (!mareq->frame || !priv || !priv->smepriv) 1505 if (!mareq->frame || !priv || !priv->smepriv)
1504 { 1506 {
@@ -1510,6 +1512,8 @@ void CsrWifiRouterMaPacketReqHandler(void* drvpriv, CsrWifiFsmEvent* msg)
1510 unifi_error(priv, "CsrWifiRouterMaPacketReqHandler: interfaceID >= CSR_WIFI_NUM_INTERFACES.\n"); 1512 unifi_error(priv, "CsrWifiRouterMaPacketReqHandler: interfaceID >= CSR_WIFI_NUM_INTERFACES.\n");
1511 return; 1513 return;
1512 } 1514 }
1515
1516 interfacePriv = priv->interfacePriv[interfaceTag];
1513 /* get a pointer to dest & source Mac address */ 1517 /* get a pointer to dest & source Mac address */
1514 daddr = mareq->frame; 1518 daddr = mareq->frame;
1515 saddr = (mareq->frame + ETH_ALEN); 1519 saddr = (mareq->frame + ETH_ALEN);
@@ -2056,9 +2060,9 @@ void CsrWifiRouterCtrlPeerDelReqHandler(void* drvpriv, CsrWifiFsmEvent* msg)
2056 CsrWifiRouterCtrlPeerDelReq* req = (CsrWifiRouterCtrlPeerDelReq*)msg; 2060 CsrWifiRouterCtrlPeerDelReq* req = (CsrWifiRouterCtrlPeerDelReq*)msg;
2057 CsrResult status = CSR_RESULT_SUCCESS; 2061 CsrResult status = CSR_RESULT_SUCCESS;
2058 unifi_priv_t *priv = (unifi_priv_t*)drvpriv; 2062 unifi_priv_t *priv = (unifi_priv_t*)drvpriv;
2059 netInterface_priv_t *interfacePriv = priv->interfacePriv[req->interfaceTag]; 2063 netInterface_priv_t *interfacePriv;
2060 2064
2061 unifi_trace(priv, UDBG2, "entering CsrWifiRouterCtrlPeerDelReqHandler \n"); 2065 unifi_trace(priv, UDBG2, "entering CsrWifiRouterCtrlPeerDelReqHandler\n");
2062 if (priv == NULL) 2066 if (priv == NULL)
2063 { 2067 {
2064 unifi_error(priv, "CsrWifiRouterCtrlPeerDelReqHandler: invalid smepriv\n"); 2068 unifi_error(priv, "CsrWifiRouterCtrlPeerDelReqHandler: invalid smepriv\n");
@@ -2071,6 +2075,8 @@ void CsrWifiRouterCtrlPeerDelReqHandler(void* drvpriv, CsrWifiFsmEvent* msg)
2071 return; 2075 return;
2072 } 2076 }
2073 2077
2078 interfacePriv = priv->interfacePriv[req->interfaceTag];
2079
2074 switch(interfacePriv->interfaceMode) 2080 switch(interfacePriv->interfaceMode)
2075 { 2081 {
2076 case CSR_WIFI_ROUTER_CTRL_MODE_AP: 2082 case CSR_WIFI_ROUTER_CTRL_MODE_AP:
@@ -2471,7 +2477,7 @@ void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv,CsrWifiFsmEvent* msg)
2471 CsrResult status = CSR_RESULT_SUCCESS; 2477 CsrResult status = CSR_RESULT_SUCCESS;
2472 unifi_priv_t *priv = (unifi_priv_t*)drvpriv; 2478 unifi_priv_t *priv = (unifi_priv_t*)drvpriv;
2473 u32 handle = 0; 2479 u32 handle = 0;
2474 netInterface_priv_t *interfacePriv = priv->interfacePriv[req->interfaceTag]; 2480 netInterface_priv_t *interfacePriv;
2475 2481
2476 unifi_trace(priv, UDBG2, "entering CsrWifiRouterCtrlPeerAddReqHandler \n"); 2482 unifi_trace(priv, UDBG2, "entering CsrWifiRouterCtrlPeerAddReqHandler \n");
2477 if (priv == NULL) 2483 if (priv == NULL)
@@ -2486,6 +2492,8 @@ void CsrWifiRouterCtrlPeerAddReqHandler(void* drvpriv,CsrWifiFsmEvent* msg)
2486 return; 2492 return;
2487 } 2493 }
2488 2494
2495 interfacePriv = priv->interfacePriv[req->interfaceTag];
2496
2489 switch(interfacePriv->interfaceMode) 2497 switch(interfacePriv->interfaceMode)
2490 { 2498 {
2491 case CSR_WIFI_ROUTER_CTRL_MODE_AP: 2499 case CSR_WIFI_ROUTER_CTRL_MODE_AP:
@@ -3036,21 +3044,24 @@ void CsrWifiRouterCtrlWapiRxPktReqHandler(void* drvpriv, CsrWifiFsmEvent* msg)
3036 ul_client_t *client; 3044 ul_client_t *client;
3037 CSR_SIGNAL signal; 3045 CSR_SIGNAL signal;
3038 CSR_MA_PACKET_INDICATION *pkt_ind; 3046 CSR_MA_PACKET_INDICATION *pkt_ind;
3039 netInterface_priv_t *interfacePriv = priv->interfacePriv[req->interfaceTag]; 3047 netInterface_priv_t *interfacePriv;
3048
3049 if (priv == NULL) {
3050 unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid priv\n", __func__);
3051 return;
3052 }
3053
3054 if (priv->smepriv == NULL) {
3055 unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid sme priv\n", __func__);
3056 return;
3057 }
3058
3059 interfacePriv = priv->interfacePriv[req->interfaceTag];
3040 3060
3041 if (CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) { 3061 if (CSR_WIFI_ROUTER_CTRL_MODE_STA == interfacePriv->interfaceMode) {
3042 3062
3043 unifi_trace(priv, UDBG6, ">>%s\n", __FUNCTION__); 3063 unifi_trace(priv, UDBG6, ">>%s\n", __FUNCTION__);
3044 3064
3045 if (priv == NULL) {
3046 unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid priv\n",__FUNCTION__);
3047 return;
3048 }
3049
3050 if (priv->smepriv == NULL) {
3051 unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq : invalid sme priv\n",__FUNCTION__);
3052 return;
3053 }
3054 3065
3055 if (req->dataLength == 0 || req->data == NULL) { 3066 if (req->dataLength == 0 || req->data == NULL) {
3056 unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq: invalid request\n",__FUNCTION__); 3067 unifi_error(priv, "CsrWifiRouterCtrlWapiRxPktReq: invalid request\n",__FUNCTION__);
diff --git a/drivers/staging/csr/unifi_sme.c b/drivers/staging/csr/unifi_sme.c
index 49395da34b7f..7d19e632a5e4 100644
--- a/drivers/staging/csr/unifi_sme.c
+++ b/drivers/staging/csr/unifi_sme.c
@@ -1196,7 +1196,6 @@ void uf_send_pkt_to_encrypt(struct work_struct *work)
1196 1196
1197 if (pktBulkDataLength > 0) { 1197 if (pktBulkDataLength > 0) {
1198 pktBulkData = kmalloc(pktBulkDataLength, GFP_KERNEL); 1198 pktBulkData = kmalloc(pktBulkDataLength, GFP_KERNEL);
1199 memset(pktBulkData, 0, pktBulkDataLength);
1200 } else { 1199 } else {
1201 unifi_error(priv, "uf_send_pkt_to_encrypt() : invalid buffer\n"); 1200 unifi_error(priv, "uf_send_pkt_to_encrypt() : invalid buffer\n");
1202 return; 1201 return;
diff --git a/drivers/staging/cxt1e1/linux.c b/drivers/staging/cxt1e1/linux.c
index 0ff2865edec8..a829b6231a66 100644
--- a/drivers/staging/cxt1e1/linux.c
+++ b/drivers/staging/cxt1e1/linux.c
@@ -773,7 +773,9 @@ do_del_chan (struct net_device * musycc_dev, void *data)
773 if (copy_from_user (&cp, data, 773 if (copy_from_user (&cp, data,
774 sizeof (struct sbecom_chan_param))) 774 sizeof (struct sbecom_chan_param)))
775 return -EFAULT; 775 return -EFAULT;
776 sprintf (buf, CHANNAME "%d", cp.channum); 776 if (cp.channum > 999)
777 return -EINVAL;
778 snprintf (buf, sizeof(buf), CHANNAME "%d", cp.channum);
777 if (!(dev = dev_get_by_name (&init_net, buf))) 779 if (!(dev = dev_get_by_name (&init_net, buf)))
778 return -ENOENT; 780 return -ENOENT;
779 dev_put (dev); 781 dev_put (dev);
diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c
index c214078a89e9..13c7ccf163c5 100644
--- a/drivers/staging/dgrp/dgrp_specproc.c
+++ b/drivers/staging/dgrp/dgrp_specproc.c
@@ -81,33 +81,34 @@ static struct dgrp_proc_entry dgrp_mon_table[];
81static struct dgrp_proc_entry dgrp_ports_table[]; 81static struct dgrp_proc_entry dgrp_ports_table[];
82static struct dgrp_proc_entry dgrp_dpa_table[]; 82static struct dgrp_proc_entry dgrp_dpa_table[];
83 83
84static ssize_t config_proc_write(struct file *file, const char __user *buffer, 84static ssize_t dgrp_config_proc_write(struct file *file,
85 size_t count, loff_t *pos); 85 const char __user *buffer,
86 size_t count, loff_t *pos);
86 87
87static int nodeinfo_proc_open(struct inode *inode, struct file *file); 88static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file);
88static int info_proc_open(struct inode *inode, struct file *file); 89static int dgrp_info_proc_open(struct inode *inode, struct file *file);
89static int config_proc_open(struct inode *inode, struct file *file); 90static int dgrp_config_proc_open(struct inode *inode, struct file *file);
90 91
91static struct file_operations config_proc_file_ops = { 92static struct file_operations config_proc_file_ops = {
92 .owner = THIS_MODULE, 93 .owner = THIS_MODULE,
93 .open = config_proc_open, 94 .open = dgrp_config_proc_open,
94 .read = seq_read, 95 .read = seq_read,
95 .llseek = seq_lseek, 96 .llseek = seq_lseek,
96 .release = seq_release, 97 .release = seq_release,
97 .write = config_proc_write 98 .write = dgrp_config_proc_write,
98}; 99};
99 100
100static struct file_operations info_proc_file_ops = { 101static struct file_operations info_proc_file_ops = {
101 .owner = THIS_MODULE, 102 .owner = THIS_MODULE,
102 .open = info_proc_open, 103 .open = dgrp_info_proc_open,
103 .read = seq_read, 104 .read = seq_read,
104 .llseek = seq_lseek, 105 .llseek = seq_lseek,
105 .release = seq_release, 106 .release = single_release,
106}; 107};
107 108
108static struct file_operations nodeinfo_proc_file_ops = { 109static struct file_operations nodeinfo_proc_file_ops = {
109 .owner = THIS_MODULE, 110 .owner = THIS_MODULE,
110 .open = nodeinfo_proc_open, 111 .open = dgrp_nodeinfo_proc_open,
111 .read = seq_read, 112 .read = seq_read,
112 .llseek = seq_lseek, 113 .llseek = seq_lseek,
113 .release = seq_release, 114 .release = seq_release,
@@ -181,13 +182,13 @@ static struct dgrp_proc_entry dgrp_dpa_table[] = {
181 182
182void dgrp_unregister_proc(void) 183void dgrp_unregister_proc(void)
183{ 184{
184 unregister_proc_table(dgrp_table, dgrp_proc_dir_entry);
185 net_entry_pointer = NULL; 185 net_entry_pointer = NULL;
186 mon_entry_pointer = NULL; 186 mon_entry_pointer = NULL;
187 dpa_entry_pointer = NULL; 187 dpa_entry_pointer = NULL;
188 ports_entry_pointer = NULL; 188 ports_entry_pointer = NULL;
189 189
190 if (dgrp_proc_dir_entry) { 190 if (dgrp_proc_dir_entry) {
191 unregister_proc_table(dgrp_table, dgrp_proc_dir_entry);
191 remove_proc_entry(dgrp_proc_dir_entry->name, 192 remove_proc_entry(dgrp_proc_dir_entry->name,
192 dgrp_proc_dir_entry->parent); 193 dgrp_proc_dir_entry->parent);
193 dgrp_proc_dir_entry = NULL; 194 dgrp_proc_dir_entry = NULL;
@@ -231,6 +232,8 @@ static void register_proc_table(struct dgrp_proc_entry *table,
231 232
232 if (table == NULL) 233 if (table == NULL)
233 return; 234 return;
235 if (root == NULL)
236 return;
234 237
235 for (; table->id; table++) { 238 for (; table->id; table++) {
236 /* Can't do anything without a proc name. */ 239 /* Can't do anything without a proc name. */
@@ -403,21 +406,21 @@ done:
403 return 0; 406 return 0;
404} 407}
405 408
406static void *config_proc_start(struct seq_file *m, loff_t *pos) 409static void *dgrp_config_proc_start(struct seq_file *m, loff_t *pos)
407{ 410{
408 return seq_list_start_head(&nd_struct_list, *pos); 411 return seq_list_start_head(&nd_struct_list, *pos);
409} 412}
410 413
411static void *config_proc_next(struct seq_file *p, void *v, loff_t *pos) 414static void *dgrp_config_proc_next(struct seq_file *p, void *v, loff_t *pos)
412{ 415{
413 return seq_list_next(v, &nd_struct_list, pos); 416 return seq_list_next(v, &nd_struct_list, pos);
414} 417}
415 418
416static void config_proc_stop(struct seq_file *m, void *v) 419static void dgrp_config_proc_stop(struct seq_file *m, void *v)
417{ 420{
418} 421}
419 422
420static int config_proc_show(struct seq_file *m, void *v) 423static int dgrp_config_proc_show(struct seq_file *m, void *v)
421{ 424{
422 struct nd_struct *nd; 425 struct nd_struct *nd;
423 char tmp_id[4]; 426 char tmp_id[4];
@@ -443,13 +446,13 @@ static int config_proc_show(struct seq_file *m, void *v)
443} 446}
444 447
445static const struct seq_operations proc_config_ops = { 448static const struct seq_operations proc_config_ops = {
446 .start = config_proc_start, 449 .start = dgrp_config_proc_start,
447 .next = config_proc_next, 450 .next = dgrp_config_proc_next,
448 .stop = config_proc_stop, 451 .stop = dgrp_config_proc_stop,
449 .show = config_proc_show 452 .show = dgrp_config_proc_show,
450}; 453};
451 454
452static int config_proc_open(struct inode *inode, struct file *file) 455static int dgrp_config_proc_open(struct inode *inode, struct file *file)
453{ 456{
454 return seq_open(file, &proc_config_ops); 457 return seq_open(file, &proc_config_ops);
455} 458}
@@ -460,8 +463,9 @@ static int config_proc_open(struct inode *inode, struct file *file)
460 * write) is treated as an independent request. See the "parse" 463 * write) is treated as an independent request. See the "parse"
461 * description for more details. 464 * description for more details.
462 */ 465 */
463static ssize_t config_proc_write(struct file *file, const char __user *buffer, 466static ssize_t dgrp_config_proc_write(struct file *file,
464 size_t count, loff_t *pos) 467 const char __user *buffer,
468 size_t count, loff_t *pos)
465{ 469{
466 ssize_t retval; 470 ssize_t retval;
467 char *inbuf, *sp; 471 char *inbuf, *sp;
@@ -625,7 +629,7 @@ static int parse_write_config(char *buf)
625 return retval; 629 return retval;
626} 630}
627 631
628static int info_proc_show(struct seq_file *m, void *v) 632static int dgrp_info_proc_show(struct seq_file *m, void *v)
629{ 633{
630 seq_printf(m, "version: %s\n", DIGI_VERSION); 634 seq_printf(m, "version: %s\n", DIGI_VERSION);
631 seq_puts(m, "register_with_sysfs: 1\n"); 635 seq_puts(m, "register_with_sysfs: 1\n");
@@ -635,27 +639,27 @@ static int info_proc_show(struct seq_file *m, void *v)
635 return 0; 639 return 0;
636} 640}
637 641
638static int info_proc_open(struct inode *inode, struct file *file) 642static int dgrp_info_proc_open(struct inode *inode, struct file *file)
639{ 643{
640 return single_open(file, info_proc_show, NULL); 644 return single_open(file, dgrp_info_proc_show, NULL);
641} 645}
642 646
643 647
644static void *nodeinfo_start(struct seq_file *m, loff_t *pos) 648static void *dgrp_nodeinfo_start(struct seq_file *m, loff_t *pos)
645{ 649{
646 return seq_list_start_head(&nd_struct_list, *pos); 650 return seq_list_start_head(&nd_struct_list, *pos);
647} 651}
648 652
649static void *nodeinfo_next(struct seq_file *p, void *v, loff_t *pos) 653static void *dgrp_nodeinfo_next(struct seq_file *p, void *v, loff_t *pos)
650{ 654{
651 return seq_list_next(v, &nd_struct_list, pos); 655 return seq_list_next(v, &nd_struct_list, pos);
652} 656}
653 657
654static void nodeinfo_stop(struct seq_file *m, void *v) 658static void dgrp_nodeinfo_stop(struct seq_file *m, void *v)
655{ 659{
656} 660}
657 661
658static int nodeinfo_show(struct seq_file *m, void *v) 662static int dgrp_nodeinfo_show(struct seq_file *m, void *v)
659{ 663{
660 struct nd_struct *nd; 664 struct nd_struct *nd;
661 char hwver[8]; 665 char hwver[8];
@@ -697,13 +701,13 @@ static int nodeinfo_show(struct seq_file *m, void *v)
697 701
698 702
699static const struct seq_operations nodeinfo_ops = { 703static const struct seq_operations nodeinfo_ops = {
700 .start = nodeinfo_start, 704 .start = dgrp_nodeinfo_start,
701 .next = nodeinfo_next, 705 .next = dgrp_nodeinfo_next,
702 .stop = nodeinfo_stop, 706 .stop = dgrp_nodeinfo_stop,
703 .show = nodeinfo_show 707 .show = dgrp_nodeinfo_show,
704}; 708};
705 709
706static int nodeinfo_proc_open(struct inode *inode, struct file *file) 710static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file)
707{ 711{
708 return seq_open(file, &nodeinfo_ops); 712 return seq_open(file, &nodeinfo_ops);
709} 713}
@@ -773,14 +777,11 @@ static int dgrp_remove_nd(struct nd_struct *nd)
773 dgrp_remove_node_class_sysfs_files(nd); 777 dgrp_remove_node_class_sysfs_files(nd);
774 } 778 }
775 779
776 if (nd->nd_mon_de) 780 unregister_dgrp_device(nd->nd_mon_de);
777 unregister_dgrp_device(nd->nd_mon_de);
778 781
779 if (nd->nd_ports_de) 782 unregister_dgrp_device(nd->nd_ports_de);
780 unregister_dgrp_device(nd->nd_ports_de);
781 783
782 if (nd->nd_dpa_de) 784 unregister_dgrp_device(nd->nd_dpa_de);
783 unregister_dgrp_device(nd->nd_dpa_de);
784 785
785 dgrp_tty_uninit(nd); 786 dgrp_tty_uninit(nd);
786 787
diff --git a/drivers/staging/echo/echo.c b/drivers/staging/echo/echo.c
index ca87ce9874b1..5882139d49af 100644
--- a/drivers/staging/echo/echo.c
+++ b/drivers/staging/echo/echo.c
@@ -119,7 +119,6 @@
119static inline void lms_adapt_bg(struct oslec_state *ec, int clean, int shift) 119static inline void lms_adapt_bg(struct oslec_state *ec, int clean, int shift)
120{ 120{
121 int i; 121 int i;
122 int j;
123 int offset1; 122 int offset1;
124 int offset2; 123 int offset2;
125 int factor; 124 int factor;
@@ -142,7 +141,7 @@ static inline void lms_adapt_bg(struct oslec_state *ec, int clean, int shift)
142 141
143 /* asm("st:"); */ 142 /* asm("st:"); */
144 n = ec->taps; 143 n = ec->taps;
145 for (i = 0, j = offset2; i < n; i++, j++) { 144 for (i = 0; i < n; i++) {
146 exp = *phist++ * factor; 145 exp = *phist++ * factor;
147 ec->fir_taps16[1][i] += (int16_t) ((exp + (1 << 14)) >> 15); 146 ec->fir_taps16[1][i] += (int16_t) ((exp + (1 << 14)) >> 15);
148 } 147 }
@@ -230,6 +229,7 @@ struct oslec_state *oslec_create(int len, int adaption_mode)
230{ 229{
231 struct oslec_state *ec; 230 struct oslec_state *ec;
232 int i; 231 int i;
232 const int16_t *history;
233 233
234 ec = kzalloc(sizeof(*ec), GFP_KERNEL); 234 ec = kzalloc(sizeof(*ec), GFP_KERNEL);
235 if (!ec) 235 if (!ec)
@@ -239,15 +239,22 @@ struct oslec_state *oslec_create(int len, int adaption_mode)
239 ec->log2taps = top_bit(len); 239 ec->log2taps = top_bit(len);
240 ec->curr_pos = ec->taps - 1; 240 ec->curr_pos = ec->taps - 1;
241 241
242 for (i = 0; i < 2; i++) { 242 ec->fir_taps16[0] =
243 ec->fir_taps16[i] = 243 kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL);
244 kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); 244 if (!ec->fir_taps16[0])
245 if (!ec->fir_taps16[i]) 245 goto error_oom_0;
246 goto error_oom; 246
247 } 247 ec->fir_taps16[1] =
248 kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL);
249 if (!ec->fir_taps16[1])
250 goto error_oom_1;
248 251
249 fir16_create(&ec->fir_state, ec->fir_taps16[0], ec->taps); 252 history = fir16_create(&ec->fir_state, ec->fir_taps16[0], ec->taps);
250 fir16_create(&ec->fir_state_bg, ec->fir_taps16[1], ec->taps); 253 if (!history)
254 goto error_state;
255 history = fir16_create(&ec->fir_state_bg, ec->fir_taps16[1], ec->taps);
256 if (!history)
257 goto error_state_bg;
251 258
252 for (i = 0; i < 5; i++) 259 for (i = 0; i < 5; i++)
253 ec->xvtx[i] = ec->yvtx[i] = ec->xvrx[i] = ec->yvrx[i] = 0; 260 ec->xvtx[i] = ec->yvtx[i] = ec->xvrx[i] = ec->yvrx[i] = 0;
@@ -257,7 +264,7 @@ struct oslec_state *oslec_create(int len, int adaption_mode)
257 264
258 ec->snapshot = kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL); 265 ec->snapshot = kcalloc(ec->taps, sizeof(int16_t), GFP_KERNEL);
259 if (!ec->snapshot) 266 if (!ec->snapshot)
260 goto error_oom; 267 goto error_snap;
261 268
262 ec->cond_met = 0; 269 ec->cond_met = 0;
263 ec->Pstates = 0; 270 ec->Pstates = 0;
@@ -270,10 +277,15 @@ struct oslec_state *oslec_create(int len, int adaption_mode)
270 277
271 return ec; 278 return ec;
272 279
273error_oom: 280error_snap:
274 for (i = 0; i < 2; i++) 281 fir16_free(&ec->fir_state_bg);
275 kfree(ec->fir_taps16[i]); 282error_state_bg:
276 283 fir16_free(&ec->fir_state);
284error_state:
285 kfree(ec->fir_taps16[1]);
286error_oom_1:
287 kfree(ec->fir_taps16[0]);
288error_oom_0:
277 kfree(ec); 289 kfree(ec);
278 return NULL; 290 return NULL;
279} 291}
diff --git a/drivers/staging/et131x/README b/drivers/staging/et131x/README
index 38537d4c4e14..05ad08501663 100644
--- a/drivers/staging/et131x/README
+++ b/drivers/staging/et131x/README
@@ -9,6 +9,10 @@ driver as they did not build properly at the time.
9 9
10TODO: 10TODO:
11 - some rx packets have CRC/code/frame errors 11 - some rx packets have CRC/code/frame errors
12 - Look at reducing the number of spinlocks
13 - Simplify code in nic_rx_pkts(), when determining multicast_pkts_rcvd
14 - Implement NAPI support
15 - in et131x_tx(), don't return NETDEV_TX_BUSY, just drop the packet with kfree_skb().
12 16
13Please send patches to: 17Please send patches to:
14 Greg Kroah-Hartman <gregkh@linuxfoundation.org> 18 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff --git a/drivers/staging/et131x/et131x.c b/drivers/staging/et131x/et131x.c
index a0a30b3f2dcd..42ae5e83f907 100644
--- a/drivers/staging/et131x/et131x.c
+++ b/drivers/staging/et131x/et131x.c
@@ -1,5 +1,4 @@
1/* 1/* Agere Systems Inc.
2 * Agere Systems Inc.
3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs 2 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4 * 3 *
5 * Copyright © 2005 Agere Systems Inc. 4 * Copyright © 2005 Agere Systems Inc.
@@ -50,7 +49,6 @@
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
52 * DAMAGE. 51 * DAMAGE.
53 *
54 */ 52 */
55 53
56#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 54#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
@@ -102,8 +100,7 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S
102#define INTERNAL_MEM_RX_OFFSET 0x1FF /* 50% Tx, 50% Rx */ 100#define INTERNAL_MEM_RX_OFFSET 0x1FF /* 50% Tx, 50% Rx */
103 101
104/* ISR defines */ 102/* ISR defines */
105/* 103/* For interrupts, normal running is:
106 * For interrupts, normal running is:
107 * rxdma_xfr_done, phy_interrupt, mac_stat_interrupt, 104 * rxdma_xfr_done, phy_interrupt, mac_stat_interrupt,
108 * watchdog_interrupt & txdma_xfer_done 105 * watchdog_interrupt & txdma_xfer_done
109 * 106 *
@@ -139,19 +136,19 @@ MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere S
139#define NIC_SEND_HANG_THRESHOLD 0 136#define NIC_SEND_HANG_THRESHOLD 0
140 137
141/* MP_TCB flags */ 138/* MP_TCB flags */
142#define fMP_DEST_MULTI 0x00000001 139#define FMP_DEST_MULTI 0x00000001
143#define fMP_DEST_BROAD 0x00000002 140#define FMP_DEST_BROAD 0x00000002
144 141
145/* MP_ADAPTER flags */ 142/* MP_ADAPTER flags */
146#define fMP_ADAPTER_INTERRUPT_IN_USE 0x00000008 143#define FMP_ADAPTER_INTERRUPT_IN_USE 0x00000008
147 144
148/* MP_SHARED flags */ 145/* MP_SHARED flags */
149#define fMP_ADAPTER_LOWER_POWER 0x00200000 146#define FMP_ADAPTER_LOWER_POWER 0x00200000
150 147
151#define fMP_ADAPTER_NON_RECOVER_ERROR 0x00800000 148#define FMP_ADAPTER_NON_RECOVER_ERROR 0x00800000
152#define fMP_ADAPTER_HARDWARE_ERROR 0x04000000 149#define FMP_ADAPTER_HARDWARE_ERROR 0x04000000
153 150
154#define fMP_ADAPTER_FAIL_SEND_MASK 0x3ff00000 151#define FMP_ADAPTER_FAIL_SEND_MASK 0x3ff00000
155 152
156/* Some offsets in PCI config space that are actually used. */ 153/* Some offsets in PCI config space that are actually used. */
157#define ET1310_PCI_MAC_ADDRESS 0xA4 154#define ET1310_PCI_MAC_ADDRESS 0xA4
@@ -245,8 +242,7 @@ struct pkt_stat_desc {
245 242
246/* Typedefs for the RX DMA status word */ 243/* Typedefs for the RX DMA status word */
247 244
248/* 245/* rx status word 0 holds part of the status bits of the Rx DMA engine
249 * rx status word 0 holds part of the status bits of the Rx DMA engine
250 * that get copied out to memory by the ET-1310. Word 0 is a 32 bit word 246 * that get copied out to memory by the ET-1310. Word 0 is a 32 bit word
251 * which contains the Free Buffer ring 0 and 1 available offset. 247 * which contains the Free Buffer ring 0 and 1 available offset.
252 * 248 *
@@ -256,8 +252,7 @@ struct pkt_stat_desc {
256 * bit 26 Wrap flag for FBR0 252 * bit 26 Wrap flag for FBR0
257 */ 253 */
258 254
259/* 255/* RXSTAT_WORD1_t structure holds part of the status bits of the Rx DMA engine
260 * RXSTAT_WORD1_t structure holds part of the status bits of the Rx DMA engine
261 * that get copied out to memory by the ET-1310. Word 3 is a 32 bit word 256 * that get copied out to memory by the ET-1310. Word 3 is a 32 bit word
262 * which contains the Packet Status Ring available offset. 257 * which contains the Packet Status Ring available offset.
263 * 258 *
@@ -267,8 +262,7 @@ struct pkt_stat_desc {
267 * bit 29-31 unused 262 * bit 29-31 unused
268 */ 263 */
269 264
270/* 265/* struct rx_status_block is a structure representing the status of the Rx
271 * struct rx_status_block is a structure representing the status of the Rx
272 * DMA engine it sits in free memory, and is pointed to by 0x101c / 0x1020 266 * DMA engine it sits in free memory, and is pointed to by 0x101c / 0x1020
273 */ 267 */
274struct rx_status_block { 268struct rx_status_block {
@@ -276,8 +270,7 @@ struct rx_status_block {
276 u32 word1; 270 u32 word1;
277}; 271};
278 272
279/* 273/* Structure for look-up table holding free buffer ring pointers, addresses
280 * Structure for look-up table holding free buffer ring pointers, addresses
281 * and state. 274 * and state.
282 */ 275 */
283struct fbr_lookup { 276struct fbr_lookup {
@@ -293,8 +286,7 @@ struct fbr_lookup {
293 dma_addr_t buffsize; 286 dma_addr_t buffsize;
294}; 287};
295 288
296/* 289/* struct rx_ring is the sructure representing the adaptor's local
297 * struct rx_ring is the sructure representing the adaptor's local
298 * reference(s) to the rings 290 * reference(s) to the rings
299 */ 291 */
300struct rx_ring { 292struct rx_ring {
@@ -317,8 +309,7 @@ struct rx_ring {
317}; 309};
318 310
319/* TX defines */ 311/* TX defines */
320/* 312/* word 2 of the control bits in the Tx Descriptor ring for the ET-1310
321 * word 2 of the control bits in the Tx Descriptor ring for the ET-1310
322 * 313 *
323 * 0-15: length of packet 314 * 0-15: length of packet
324 * 16-27: VLAN tag 315 * 16-27: VLAN tag
@@ -344,6 +335,10 @@ struct rx_ring {
344 * 14: UDP checksum assist 335 * 14: UDP checksum assist
345 */ 336 */
346 337
338#define TXDESC_FLAG_LASTPKT 0x0001
339#define TXDESC_FLAG_FIRSTPKT 0x0002
340#define TXDESC_FLAG_INTPROC 0x0004
341
347/* struct tx_desc represents each descriptor on the ring */ 342/* struct tx_desc represents each descriptor on the ring */
348struct tx_desc { 343struct tx_desc {
349 u32 addr_hi; 344 u32 addr_hi;
@@ -352,8 +347,7 @@ struct tx_desc {
352 u32 flags; /* data (detailed above) */ 347 u32 flags; /* data (detailed above) */
353}; 348};
354 349
355/* 350/* The status of the Tx DMA engine it sits in free memory, and is pointed to
356 * The status of the Tx DMA engine it sits in free memory, and is pointed to
357 * by 0x101c / 0x1020. This is a DMA10 type 351 * by 0x101c / 0x1020. This is a DMA10 type
358 */ 352 */
359 353
@@ -402,15 +396,13 @@ struct tx_ring {
402 int since_irq; 396 int since_irq;
403}; 397};
404 398
405/* 399/* Do not change these values: if changed, then change also in respective
406 * Do not change these values: if changed, then change also in respective
407 * TXdma and Rxdma engines 400 * TXdma and Rxdma engines
408 */ 401 */
409#define NUM_DESC_PER_RING_TX 512 /* TX Do not change these values */ 402#define NUM_DESC_PER_RING_TX 512 /* TX Do not change these values */
410#define NUM_TCB 64 403#define NUM_TCB 64
411 404
412/* 405/* These values are all superseded by registry entries to facilitate tuning.
413 * These values are all superseded by registry entries to facilitate tuning.
414 * Once the desired performance has been achieved, the optimal registry values 406 * Once the desired performance has been achieved, the optimal registry values
415 * should be re-populated to these #defines: 407 * should be re-populated to these #defines:
416 */ 408 */
@@ -555,8 +547,7 @@ static int eeprom_wait_ready(struct pci_dev *pdev, u32 *status)
555 u32 reg; 547 u32 reg;
556 int i; 548 int i;
557 549
558 /* 550 /* 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and
559 * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and
560 * bits 7,1:0 both equal to 1, at least once after reset. 551 * bits 7,1:0 both equal to 1, at least once after reset.
561 * Subsequent operations need only to check that bits 1:0 are equal 552 * Subsequent operations need only to check that bits 1:0 are equal
562 * to 1 prior to starting a single byte read/write 553 * to 1 prior to starting a single byte read/write
@@ -577,9 +568,7 @@ static int eeprom_wait_ready(struct pci_dev *pdev, u32 *status)
577 return -ETIMEDOUT; 568 return -ETIMEDOUT;
578} 569}
579 570
580 571/* eeprom_write - Write a byte to the ET1310's EEPROM
581/**
582 * eeprom_write - Write a byte to the ET1310's EEPROM
583 * @adapter: pointer to our private adapter structure 572 * @adapter: pointer to our private adapter structure
584 * @addr: the address to write 573 * @addr: the address to write
585 * @data: the value to write 574 * @data: the value to write
@@ -597,8 +586,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
597 u32 status; 586 u32 status;
598 u32 val = 0; 587 u32 val = 0;
599 588
600 /* 589 /* For an EEPROM, an I2C single byte write is defined as a START
601 * For an EEPROM, an I2C single byte write is defined as a START
602 * condition followed by the device address, EEPROM address, one byte 590 * condition followed by the device address, EEPROM address, one byte
603 * of data and a STOP condition. The STOP condition will trigger the 591 * of data and a STOP condition. The STOP condition will trigger the
604 * EEPROM's internally timed write cycle to the nonvolatile memory. 592 * EEPROM's internally timed write cycle to the nonvolatile memory.
@@ -610,12 +598,11 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
610 if (err) 598 if (err)
611 return err; 599 return err;
612 600
613 /* 601 /* 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0,
614 * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0, 602 * and bits 1:0 both =0. Bit 5 should be set according to the
615 * and bits 1:0 both =0. Bit 5 should be set according to the 603 * type of EEPROM being accessed (1=two byte addressing, 0=one
616 * type of EEPROM being accessed (1=two byte addressing, 0=one 604 * byte addressing).
617 * byte addressing). 605 */
618 */
619 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER, 606 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER,
620 LBCIF_CONTROL_LBCIF_ENABLE | LBCIF_CONTROL_I2C_WRITE)) 607 LBCIF_CONTROL_LBCIF_ENABLE | LBCIF_CONTROL_I2C_WRITE))
621 return -EIO; 608 return -EIO;
@@ -628,14 +615,12 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
628 /* Write the address to the LBCIF Address Register */ 615 /* Write the address to the LBCIF Address Register */
629 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr)) 616 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr))
630 break; 617 break;
631 /* 618 /* Write the data to the LBCIF Data Register (the I2C write
632 * Write the data to the LBCIF Data Register (the I2C write
633 * will begin). 619 * will begin).
634 */ 620 */
635 if (pci_write_config_byte(pdev, LBCIF_DATA_REGISTER, data)) 621 if (pci_write_config_byte(pdev, LBCIF_DATA_REGISTER, data))
636 break; 622 break;
637 /* 623 /* Monitor bit 1:0 of the LBCIF Status Register. When bits
638 * Monitor bit 1:0 of the LBCIF Status Register. When bits
639 * 1:0 are both equal to 1, the I2C write has completed and the 624 * 1:0 are both equal to 1, the I2C write has completed and the
640 * internal write cycle of the EEPROM is about to start. 625 * internal write cycle of the EEPROM is about to start.
641 * (bits 1:0 = 01 is a legal state while waiting from both 626 * (bits 1:0 = 01 is a legal state while waiting from both
@@ -646,8 +631,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
646 if (err < 0) 631 if (err < 0)
647 return 0; 632 return 0;
648 633
649 /* 634 /* Check bit 3 of the LBCIF Status Register. If equal to 1,
650 * Check bit 3 of the LBCIF Status Register. If equal to 1,
651 * an error has occurred.Don't break here if we are revision 635 * an error has occurred.Don't break here if we are revision
652 * 1, this is so we do a blind write for load bug. 636 * 1, this is so we do a blind write for load bug.
653 */ 637 */
@@ -655,8 +639,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
655 && adapter->pdev->revision == 0) 639 && adapter->pdev->revision == 0)
656 break; 640 break;
657 641
658 /* 642 /* Check bit 2 of the LBCIF Status Register. If equal to 1 an
659 * Check bit 2 of the LBCIF Status Register. If equal to 1 an
660 * ACK error has occurred on the address phase of the write. 643 * ACK error has occurred on the address phase of the write.
661 * This could be due to an actual hardware failure or the 644 * This could be due to an actual hardware failure or the
662 * EEPROM may still be in its internal write cycle from a 645 * EEPROM may still be in its internal write cycle from a
@@ -664,8 +647,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
664 *repeated later. 647 *repeated later.
665 */ 648 */
666 if (status & LBCIF_STATUS_ACK_ERROR) { 649 if (status & LBCIF_STATUS_ACK_ERROR) {
667 /* 650 /* This could be due to an actual hardware failure
668 * This could be due to an actual hardware failure
669 * or the EEPROM may still be in its internal write 651 * or the EEPROM may still be in its internal write
670 * cycle from a previous write. This write operation 652 * cycle from a previous write. This write operation
671 * was ignored and must be repeated later. 653 * was ignored and must be repeated later.
@@ -678,8 +660,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
678 break; 660 break;
679 } 661 }
680 662
681 /* 663 /* Set bit 6 of the LBCIF Control Register = 0.
682 * Set bit 6 of the LBCIF Control Register = 0.
683 */ 664 */
684 udelay(10); 665 udelay(10);
685 666
@@ -708,8 +689,7 @@ static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data)
708 return writeok ? 0 : -EIO; 689 return writeok ? 0 : -EIO;
709} 690}
710 691
711/** 692/* eeprom_read - Read a byte from the ET1310's EEPROM
712 * eeprom_read - Read a byte from the ET1310's EEPROM
713 * @adapter: pointer to our private adapter structure 693 * @adapter: pointer to our private adapter structure
714 * @addr: the address from which to read 694 * @addr: the address from which to read
715 * @pdata: a pointer to a byte in which to store the value of the read 695 * @pdata: a pointer to a byte in which to store the value of the read
@@ -724,16 +704,14 @@ static int eeprom_read(struct et131x_adapter *adapter, u32 addr, u8 *pdata)
724 int err; 704 int err;
725 u32 status; 705 u32 status;
726 706
727 /* 707 /* A single byte read is similar to the single byte write, with the
728 * A single byte read is similar to the single byte write, with the
729 * exception of the data flow: 708 * exception of the data flow:
730 */ 709 */
731 710
732 err = eeprom_wait_ready(pdev, NULL); 711 err = eeprom_wait_ready(pdev, NULL);
733 if (err) 712 if (err)
734 return err; 713 return err;
735 /* 714 /* Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0,
736 * Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0,
737 * and bits 1:0 both =0. Bit 5 should be set according to the type 715 * and bits 1:0 both =0. Bit 5 should be set according to the type
738 * of EEPROM being accessed (1=two byte addressing, 0=one byte 716 * of EEPROM being accessed (1=two byte addressing, 0=one byte
739 * addressing). 717 * addressing).
@@ -741,27 +719,23 @@ static int eeprom_read(struct et131x_adapter *adapter, u32 addr, u8 *pdata)
741 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER, 719 if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER,
742 LBCIF_CONTROL_LBCIF_ENABLE)) 720 LBCIF_CONTROL_LBCIF_ENABLE))
743 return -EIO; 721 return -EIO;
744 /* 722 /* Write the address to the LBCIF Address Register (I2C read will
745 * Write the address to the LBCIF Address Register (I2C read will
746 * begin). 723 * begin).
747 */ 724 */
748 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr)) 725 if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr))
749 return -EIO; 726 return -EIO;
750 /* 727 /* Monitor bit 0 of the LBCIF Status Register. When = 1, I2C read
751 * Monitor bit 0 of the LBCIF Status Register. When = 1, I2C read
752 * is complete. (if bit 1 =1 and bit 0 stays = 0, a hardware failure 728 * is complete. (if bit 1 =1 and bit 0 stays = 0, a hardware failure
753 * has occurred). 729 * has occurred).
754 */ 730 */
755 err = eeprom_wait_ready(pdev, &status); 731 err = eeprom_wait_ready(pdev, &status);
756 if (err < 0) 732 if (err < 0)
757 return err; 733 return err;
758 /* 734 /* Regardless of error status, read data byte from LBCIF Data
759 * Regardless of error status, read data byte from LBCIF Data
760 * Register. 735 * Register.
761 */ 736 */
762 *pdata = err; 737 *pdata = err;
763 /* 738 /* Check bit 2 of the LBCIF Status Register. If = 1,
764 * Check bit 2 of the LBCIF Status Register. If = 1,
765 * then an error has occurred. 739 * then an error has occurred.
766 */ 740 */
767 return (status & LBCIF_STATUS_ACK_ERROR) ? -EIO : 0; 741 return (status & LBCIF_STATUS_ACK_ERROR) ? -EIO : 0;
@@ -775,13 +749,12 @@ static int et131x_init_eeprom(struct et131x_adapter *adapter)
775 /* We first need to check the EEPROM Status code located at offset 749 /* We first need to check the EEPROM Status code located at offset
776 * 0xB2 of config space 750 * 0xB2 of config space
777 */ 751 */
778 pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, 752 pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus);
779 &eestatus);
780 753
781 /* THIS IS A WORKAROUND: 754 /* THIS IS A WORKAROUND:
782 * I need to call this function twice to get my card in a 755 * I need to call this function twice to get my card in a
783 * LG M1 Express Dual running. I tried also a msleep before this 756 * LG M1 Express Dual running. I tried also a msleep before this
784 * function, because I thought there could be some time condidions 757 * function, because I thought there could be some time conditions
785 * but it didn't work. Call the whole function twice also work. 758 * but it didn't work. Call the whole function twice also work.
786 */ 759 */
787 if (pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus)) { 760 if (pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus)) {
@@ -836,36 +809,35 @@ static int et131x_init_eeprom(struct et131x_adapter *adapter)
836 return 0; 809 return 0;
837} 810}
838 811
839/** 812/* et131x_rx_dma_enable - re-start of Rx_DMA on the ET1310.
840 * et131x_rx_dma_enable - re-start of Rx_DMA on the ET1310.
841 * @adapter: pointer to our adapter structure 813 * @adapter: pointer to our adapter structure
842 */ 814 */
843static void et131x_rx_dma_enable(struct et131x_adapter *adapter) 815static void et131x_rx_dma_enable(struct et131x_adapter *adapter)
844{ 816{
845 /* Setup the receive dma configuration register for normal operation */ 817 /* Setup the receive dma configuration register for normal operation */
846 u32 csr = 0x2000; /* FBR1 enable */ 818 u32 csr = ET_RXDMA_CSR_FBR1_ENABLE;
847 819
848 if (adapter->rx_ring.fbr[1]->buffsize == 4096) 820 if (adapter->rx_ring.fbr[1]->buffsize == 4096)
849 csr |= 0x0800; 821 csr |= ET_RXDMA_CSR_FBR1_SIZE_LO;
850 else if (adapter->rx_ring.fbr[1]->buffsize == 8192) 822 else if (adapter->rx_ring.fbr[1]->buffsize == 8192)
851 csr |= 0x1000; 823 csr |= ET_RXDMA_CSR_FBR1_SIZE_HI;
852 else if (adapter->rx_ring.fbr[1]->buffsize == 16384) 824 else if (adapter->rx_ring.fbr[1]->buffsize == 16384)
853 csr |= 0x1800; 825 csr |= ET_RXDMA_CSR_FBR1_SIZE_LO | ET_RXDMA_CSR_FBR1_SIZE_HI;
854 826
855 csr |= 0x0400; /* FBR0 enable */ 827 csr |= ET_RXDMA_CSR_FBR0_ENABLE;
856 if (adapter->rx_ring.fbr[0]->buffsize == 256) 828 if (adapter->rx_ring.fbr[0]->buffsize == 256)
857 csr |= 0x0100; 829 csr |= ET_RXDMA_CSR_FBR0_SIZE_LO;
858 else if (adapter->rx_ring.fbr[0]->buffsize == 512) 830 else if (adapter->rx_ring.fbr[0]->buffsize == 512)
859 csr |= 0x0200; 831 csr |= ET_RXDMA_CSR_FBR0_SIZE_HI;
860 else if (adapter->rx_ring.fbr[0]->buffsize == 1024) 832 else if (adapter->rx_ring.fbr[0]->buffsize == 1024)
861 csr |= 0x0300; 833 csr |= ET_RXDMA_CSR_FBR0_SIZE_LO | ET_RXDMA_CSR_FBR0_SIZE_HI;
862 writel(csr, &adapter->regs->rxdma.csr); 834 writel(csr, &adapter->regs->rxdma.csr);
863 835
864 csr = readl(&adapter->regs->rxdma.csr); 836 csr = readl(&adapter->regs->rxdma.csr);
865 if (csr & 0x00020000) { 837 if (csr & ET_RXDMA_CSR_HALT_STATUS) {
866 udelay(5); 838 udelay(5);
867 csr = readl(&adapter->regs->rxdma.csr); 839 csr = readl(&adapter->regs->rxdma.csr);
868 if (csr & 0x00020000) { 840 if (csr & ET_RXDMA_CSR_HALT_STATUS) {
869 dev_err(&adapter->pdev->dev, 841 dev_err(&adapter->pdev->dev,
870 "RX Dma failed to exit halt state. CSR 0x%08x\n", 842 "RX Dma failed to exit halt state. CSR 0x%08x\n",
871 csr); 843 csr);
@@ -873,28 +845,27 @@ static void et131x_rx_dma_enable(struct et131x_adapter *adapter)
873 } 845 }
874} 846}
875 847
876/** 848/* et131x_rx_dma_disable - Stop of Rx_DMA on the ET1310
877 * et131x_rx_dma_disable - Stop of Rx_DMA on the ET1310
878 * @adapter: pointer to our adapter structure 849 * @adapter: pointer to our adapter structure
879 */ 850 */
880static void et131x_rx_dma_disable(struct et131x_adapter *adapter) 851static void et131x_rx_dma_disable(struct et131x_adapter *adapter)
881{ 852{
882 u32 csr; 853 u32 csr;
883 /* Setup the receive dma configuration register */ 854 /* Setup the receive dma configuration register */
884 writel(0x00002001, &adapter->regs->rxdma.csr); 855 writel(ET_RXDMA_CSR_HALT | ET_RXDMA_CSR_FBR1_ENABLE,
856 &adapter->regs->rxdma.csr);
885 csr = readl(&adapter->regs->rxdma.csr); 857 csr = readl(&adapter->regs->rxdma.csr);
886 if ((csr & 0x00020000) == 0) { /* Check halt status (bit 17) */ 858 if (!(csr & ET_RXDMA_CSR_HALT_STATUS)) {
887 udelay(5); 859 udelay(5);
888 csr = readl(&adapter->regs->rxdma.csr); 860 csr = readl(&adapter->regs->rxdma.csr);
889 if ((csr & 0x00020000) == 0) 861 if (!(csr & ET_RXDMA_CSR_HALT_STATUS))
890 dev_err(&adapter->pdev->dev, 862 dev_err(&adapter->pdev->dev,
891 "RX Dma failed to enter halt state. CSR 0x%08x\n", 863 "RX Dma failed to enter halt state. CSR 0x%08x\n",
892 csr); 864 csr);
893 } 865 }
894} 866}
895 867
896/** 868/* et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310.
897 * et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310.
898 * @adapter: pointer to our adapter structure 869 * @adapter: pointer to our adapter structure
899 * 870 *
900 * Mainly used after a return to the D0 (full-power) state from a lower state. 871 * Mainly used after a return to the D0 (full-power) state from a lower state.
@@ -918,8 +889,7 @@ static inline void add_12bit(u32 *v, int n)
918 *v = INDEX12(*v + n) | (*v & ET_DMA12_WRAP); 889 *v = INDEX12(*v + n) | (*v & ET_DMA12_WRAP);
919} 890}
920 891
921/** 892/* et1310_config_mac_regs1 - Initialize the first part of MAC regs
922 * et1310_config_mac_regs1 - Initialize the first part of MAC regs
923 * @adapter: pointer to our adapter structure 893 * @adapter: pointer to our adapter structure
924 */ 894 */
925static void et1310_config_mac_regs1(struct et131x_adapter *adapter) 895static void et1310_config_mac_regs1(struct et131x_adapter *adapter)
@@ -932,7 +902,10 @@ static void et1310_config_mac_regs1(struct et131x_adapter *adapter)
932 /* First we need to reset everything. Write to MAC configuration 902 /* First we need to reset everything. Write to MAC configuration
933 * register 1 to perform reset. 903 * register 1 to perform reset.
934 */ 904 */
935 writel(0xC00F0000, &macregs->cfg1); 905 writel(ET_MAC_CFG1_SOFT_RESET | ET_MAC_CFG1_SIM_RESET |
906 ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC |
907 ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC,
908 &macregs->cfg1);
936 909
937 /* Next lets configure the MAC Inter-packet gap register */ 910 /* Next lets configure the MAC Inter-packet gap register */
938 ipg = 0x38005860; /* IPG1 0x38 IPG2 0x58 B2B 0x60 */ 911 ipg = 0x38005860; /* IPG1 0x38 IPG2 0x58 B2B 0x60 */
@@ -947,7 +920,7 @@ static void et1310_config_mac_regs1(struct et131x_adapter *adapter)
947 writel(0, &macregs->if_ctrl); 920 writel(0, &macregs->if_ctrl);
948 921
949 /* Let's move on to setting up the mii management configuration */ 922 /* Let's move on to setting up the mii management configuration */
950 writel(0x07, &macregs->mii_mgmt_cfg); /* Clock reset 0x7 */ 923 writel(ET_MAC_MIIMGMT_CLK_RST, &macregs->mii_mgmt_cfg);
951 924
952 /* Next lets configure the MAC Station Address register. These 925 /* Next lets configure the MAC Station Address register. These
953 * values are read from the EEPROM during initialization and stored 926 * values are read from the EEPROM during initialization and stored
@@ -978,8 +951,7 @@ static void et1310_config_mac_regs1(struct et131x_adapter *adapter)
978 writel(0, &macregs->cfg1); 951 writel(0, &macregs->cfg1);
979} 952}
980 953
981/** 954/* et1310_config_mac_regs2 - Initialize the second part of MAC regs
982 * et1310_config_mac_regs2 - Initialize the second part of MAC regs
983 * @adapter: pointer to our adapter structure 955 * @adapter: pointer to our adapter structure
984 */ 956 */
985static void et1310_config_mac_regs2(struct et131x_adapter *adapter) 957static void et1310_config_mac_regs2(struct et131x_adapter *adapter)
@@ -998,38 +970,44 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter)
998 ifctrl = readl(&mac->if_ctrl); 970 ifctrl = readl(&mac->if_ctrl);
999 971
1000 /* Set up the if mode bits */ 972 /* Set up the if mode bits */
1001 cfg2 &= ~0x300; 973 cfg2 &= ~ET_MAC_CFG2_IFMODE_MASK;
1002 if (phydev && phydev->speed == SPEED_1000) { 974 if (phydev && phydev->speed == SPEED_1000) {
1003 cfg2 |= 0x200; 975 cfg2 |= ET_MAC_CFG2_IFMODE_1000;
1004 /* Phy mode bit */ 976 /* Phy mode bit */
1005 ifctrl &= ~(1 << 24); 977 ifctrl &= ~ET_MAC_IFCTRL_PHYMODE;
1006 } else { 978 } else {
1007 cfg2 |= 0x100; 979 cfg2 |= ET_MAC_CFG2_IFMODE_100;
1008 ifctrl |= (1 << 24); 980 ifctrl |= ET_MAC_IFCTRL_PHYMODE;
1009 } 981 }
1010 982
1011 /* We need to enable Rx/Tx */ 983 /* We need to enable Rx/Tx */
1012 cfg1 |= CFG1_RX_ENABLE | CFG1_TX_ENABLE | CFG1_TX_FLOW; 984 cfg1 |= ET_MAC_CFG1_RX_ENABLE | ET_MAC_CFG1_TX_ENABLE |
985 ET_MAC_CFG1_TX_FLOW;
1013 /* Initialize loop back to off */ 986 /* Initialize loop back to off */
1014 cfg1 &= ~(CFG1_LOOPBACK | CFG1_RX_FLOW); 987 cfg1 &= ~(ET_MAC_CFG1_LOOPBACK | ET_MAC_CFG1_RX_FLOW);
1015 if (adapter->flowcontrol == FLOW_RXONLY || 988 if (adapter->flowcontrol == FLOW_RXONLY ||
1016 adapter->flowcontrol == FLOW_BOTH) 989 adapter->flowcontrol == FLOW_BOTH)
1017 cfg1 |= CFG1_RX_FLOW; 990 cfg1 |= ET_MAC_CFG1_RX_FLOW;
1018 writel(cfg1, &mac->cfg1); 991 writel(cfg1, &mac->cfg1);
1019 992
1020 /* Now we need to initialize the MAC Configuration 2 register */ 993 /* Now we need to initialize the MAC Configuration 2 register */
1021 /* preamble 7, check length, huge frame off, pad crc, crc enable 994 /* preamble 7, check length, huge frame off, pad crc, crc enable
1022 full duplex off */ 995 * full duplex off
1023 cfg2 |= 0x7016; 996 */
1024 cfg2 &= ~0x0021; 997 cfg2 |= 0x7 << ET_MAC_CFG2_PREAMBLE_SHIFT;
998 cfg2 |= ET_MAC_CFG2_IFMODE_LEN_CHECK;
999 cfg2 |= ET_MAC_CFG2_IFMODE_PAD_CRC;
1000 cfg2 |= ET_MAC_CFG2_IFMODE_CRC_ENABLE;
1001 cfg2 &= ~ET_MAC_CFG2_IFMODE_HUGE_FRAME;
1002 cfg2 &= ~ET_MAC_CFG2_IFMODE_FULL_DPLX;
1025 1003
1026 /* Turn on duplex if needed */ 1004 /* Turn on duplex if needed */
1027 if (phydev && phydev->duplex == DUPLEX_FULL) 1005 if (phydev && phydev->duplex == DUPLEX_FULL)
1028 cfg2 |= 0x01; 1006 cfg2 |= ET_MAC_CFG2_IFMODE_FULL_DPLX;
1029 1007
1030 ifctrl &= ~(1 << 26); 1008 ifctrl &= ~ET_MAC_IFCTRL_GHDMODE;
1031 if (phydev && phydev->duplex == DUPLEX_HALF) 1009 if (phydev && phydev->duplex == DUPLEX_HALF)
1032 ifctrl |= (1<<26); /* Enable ghd */ 1010 ifctrl |= ET_MAC_IFCTRL_GHDMODE;
1033 1011
1034 writel(ifctrl, &mac->if_ctrl); 1012 writel(ifctrl, &mac->if_ctrl);
1035 writel(cfg2, &mac->cfg2); 1013 writel(cfg2, &mac->cfg2);
@@ -1038,7 +1016,7 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter)
1038 udelay(10); 1016 udelay(10);
1039 delay++; 1017 delay++;
1040 cfg1 = readl(&mac->cfg1); 1018 cfg1 = readl(&mac->cfg1);
1041 } while ((cfg1 & CFG1_WAIT) != CFG1_WAIT && delay < 100); 1019 } while ((cfg1 & ET_MAC_CFG1_WAIT) != ET_MAC_CFG1_WAIT && delay < 100);
1042 1020
1043 if (delay == 100) { 1021 if (delay == 100) {
1044 dev_warn(&adapter->pdev->dev, 1022 dev_warn(&adapter->pdev->dev,
@@ -1047,18 +1025,17 @@ static void et1310_config_mac_regs2(struct et131x_adapter *adapter)
1047 } 1025 }
1048 1026
1049 /* Enable txmac */ 1027 /* Enable txmac */
1050 ctl |= 0x09; /* TX mac enable, FC disable */ 1028 ctl |= ET_TX_CTRL_TXMAC_ENABLE | ET_TX_CTRL_FC_DISABLE;
1051 writel(ctl, &adapter->regs->txmac.ctl); 1029 writel(ctl, &adapter->regs->txmac.ctl);
1052 1030
1053 /* Ready to start the RXDMA/TXDMA engine */ 1031 /* Ready to start the RXDMA/TXDMA engine */
1054 if (adapter->flags & fMP_ADAPTER_LOWER_POWER) { 1032 if (adapter->flags & FMP_ADAPTER_LOWER_POWER) {
1055 et131x_rx_dma_enable(adapter); 1033 et131x_rx_dma_enable(adapter);
1056 et131x_tx_dma_enable(adapter); 1034 et131x_tx_dma_enable(adapter);
1057 } 1035 }
1058} 1036}
1059 1037
1060/** 1038/* et1310_in_phy_coma - check if the device is in phy coma
1061 * et1310_in_phy_coma - check if the device is in phy coma
1062 * @adapter: pointer to our adapter structure 1039 * @adapter: pointer to our adapter structure
1063 * 1040 *
1064 * Returns 0 if the device is not in phy coma, 1 if it is in phy coma 1041 * Returns 0 if the device is not in phy coma, 1 if it is in phy coma
@@ -1139,19 +1116,19 @@ static void et1310_setup_device_for_unicast(struct et131x_adapter *adapter)
1139 * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the 1116 * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the
1140 * MAC address for first address 1117 * MAC address for first address
1141 */ 1118 */
1142 uni_pf3 = (adapter->addr[0] << ET_UNI_PF_ADDR2_1_SHIFT) | 1119 uni_pf3 = (adapter->addr[0] << ET_RX_UNI_PF_ADDR2_1_SHIFT) |
1143 (adapter->addr[1] << ET_UNI_PF_ADDR2_2_SHIFT) | 1120 (adapter->addr[1] << ET_RX_UNI_PF_ADDR2_2_SHIFT) |
1144 (adapter->addr[0] << ET_UNI_PF_ADDR1_1_SHIFT) | 1121 (adapter->addr[0] << ET_RX_UNI_PF_ADDR1_1_SHIFT) |
1145 adapter->addr[1]; 1122 adapter->addr[1];
1146 1123
1147 uni_pf2 = (adapter->addr[2] << ET_UNI_PF_ADDR2_3_SHIFT) | 1124 uni_pf2 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR2_3_SHIFT) |
1148 (adapter->addr[3] << ET_UNI_PF_ADDR2_4_SHIFT) | 1125 (adapter->addr[3] << ET_RX_UNI_PF_ADDR2_4_SHIFT) |
1149 (adapter->addr[4] << ET_UNI_PF_ADDR2_5_SHIFT) | 1126 (adapter->addr[4] << ET_RX_UNI_PF_ADDR2_5_SHIFT) |
1150 adapter->addr[5]; 1127 adapter->addr[5];
1151 1128
1152 uni_pf1 = (adapter->addr[2] << ET_UNI_PF_ADDR1_3_SHIFT) | 1129 uni_pf1 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR1_3_SHIFT) |
1153 (adapter->addr[3] << ET_UNI_PF_ADDR1_4_SHIFT) | 1130 (adapter->addr[3] << ET_RX_UNI_PF_ADDR1_4_SHIFT) |
1154 (adapter->addr[4] << ET_UNI_PF_ADDR1_5_SHIFT) | 1131 (adapter->addr[4] << ET_RX_UNI_PF_ADDR1_5_SHIFT) |
1155 adapter->addr[5]; 1132 adapter->addr[5];
1156 1133
1157 pm_csr = readl(&adapter->regs->global.pm_csr); 1134 pm_csr = readl(&adapter->regs->global.pm_csr);
@@ -1208,13 +1185,13 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter)
1208 writel(0, &rxmac->mask4_word3); 1185 writel(0, &rxmac->mask4_word3);
1209 1186
1210 /* Lets setup the WOL Source Address */ 1187 /* Lets setup the WOL Source Address */
1211 sa_lo = (adapter->addr[2] << ET_WOL_LO_SA3_SHIFT) | 1188 sa_lo = (adapter->addr[2] << ET_RX_WOL_LO_SA3_SHIFT) |
1212 (adapter->addr[3] << ET_WOL_LO_SA4_SHIFT) | 1189 (adapter->addr[3] << ET_RX_WOL_LO_SA4_SHIFT) |
1213 (adapter->addr[4] << ET_WOL_LO_SA5_SHIFT) | 1190 (adapter->addr[4] << ET_RX_WOL_LO_SA5_SHIFT) |
1214 adapter->addr[5]; 1191 adapter->addr[5];
1215 writel(sa_lo, &rxmac->sa_lo); 1192 writel(sa_lo, &rxmac->sa_lo);
1216 1193
1217 sa_hi = (u32) (adapter->addr[0] << ET_WOL_HI_SA1_SHIFT) | 1194 sa_hi = (u32) (adapter->addr[0] << ET_RX_WOL_HI_SA1_SHIFT) |
1218 adapter->addr[1]; 1195 adapter->addr[1];
1219 writel(sa_hi, &rxmac->sa_hi); 1196 writel(sa_hi, &rxmac->sa_hi);
1220 1197
@@ -1224,7 +1201,7 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter)
1224 /* Let's initialize the Unicast Packet filtering address */ 1201 /* Let's initialize the Unicast Packet filtering address */
1225 if (adapter->packet_filter & ET131X_PACKET_TYPE_DIRECTED) { 1202 if (adapter->packet_filter & ET131X_PACKET_TYPE_DIRECTED) {
1226 et1310_setup_device_for_unicast(adapter); 1203 et1310_setup_device_for_unicast(adapter);
1227 pf_ctrl |= 4; /* Unicast filter */ 1204 pf_ctrl |= ET_RX_PFCTRL_UNICST_FILTER_ENABLE;
1228 } else { 1205 } else {
1229 writel(0, &rxmac->uni_pf_addr1); 1206 writel(0, &rxmac->uni_pf_addr1);
1230 writel(0, &rxmac->uni_pf_addr2); 1207 writel(0, &rxmac->uni_pf_addr2);
@@ -1233,13 +1210,13 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter)
1233 1210
1234 /* Let's initialize the Multicast hash */ 1211 /* Let's initialize the Multicast hash */
1235 if (!(adapter->packet_filter & ET131X_PACKET_TYPE_ALL_MULTICAST)) { 1212 if (!(adapter->packet_filter & ET131X_PACKET_TYPE_ALL_MULTICAST)) {
1236 pf_ctrl |= 2; /* Multicast filter */ 1213 pf_ctrl |= ET_RX_PFCTRL_MLTCST_FILTER_ENABLE;
1237 et1310_setup_device_for_multicast(adapter); 1214 et1310_setup_device_for_multicast(adapter);
1238 } 1215 }
1239 1216
1240 /* Runt packet filtering. Didn't work in version A silicon. */ 1217 /* Runt packet filtering. Didn't work in version A silicon. */
1241 pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << 16; 1218 pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << ET_RX_PFCTRL_MIN_PKT_SZ_SHIFT;
1242 pf_ctrl |= 8; /* Fragment filter */ 1219 pf_ctrl |= ET_RX_PFCTRL_FRAG_FILTER_ENABLE;
1243 1220
1244 if (adapter->registry_jumbo_packet > 8192) 1221 if (adapter->registry_jumbo_packet > 8192)
1245 /* In order to transmit jumbo packets greater than 8k, the 1222 /* In order to transmit jumbo packets greater than 8k, the
@@ -1290,7 +1267,7 @@ static void et1310_config_rxmac_regs(struct et131x_adapter *adapter)
1290 * but we still leave the packet filter on. 1267 * but we still leave the packet filter on.
1291 */ 1268 */
1292 writel(pf_ctrl, &rxmac->pf_ctrl); 1269 writel(pf_ctrl, &rxmac->pf_ctrl);
1293 writel(0x9, &rxmac->ctrl); 1270 writel(ET_RX_CTRL_RXMAC_ENABLE | ET_RX_CTRL_WOL_DISABLE, &rxmac->ctrl);
1294} 1271}
1295 1272
1296static void et1310_config_txmac_regs(struct et131x_adapter *adapter) 1273static void et1310_config_txmac_regs(struct et131x_adapter *adapter)
@@ -1372,8 +1349,7 @@ static void et1310_config_macstat_regs(struct et131x_adapter *adapter)
1372 writel(0xFFFE7E8B, &macstat->carry_reg2_mask); 1349 writel(0xFFFE7E8B, &macstat->carry_reg2_mask);
1373} 1350}
1374 1351
1375/** 1352/* et131x_phy_mii_read - Read from the PHY through the MII Interface on the MAC
1376 * et131x_phy_mii_read - Read from the PHY through the MII Interface on the MAC
1377 * @adapter: pointer to our private adapter structure 1353 * @adapter: pointer to our private adapter structure
1378 * @addr: the address of the transceiver 1354 * @addr: the address of the transceiver
1379 * @reg: the register to read 1355 * @reg: the register to read
@@ -1401,7 +1377,7 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr,
1401 writel(0, &mac->mii_mgmt_cmd); 1377 writel(0, &mac->mii_mgmt_cmd);
1402 1378
1403 /* Set up the register we need to read from on the correct PHY */ 1379 /* Set up the register we need to read from on the correct PHY */
1404 writel(MII_ADDR(addr, reg), &mac->mii_mgmt_addr); 1380 writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr);
1405 1381
1406 writel(0x1, &mac->mii_mgmt_cmd); 1382 writel(0x1, &mac->mii_mgmt_cmd);
1407 1383
@@ -1409,7 +1385,7 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr,
1409 udelay(50); 1385 udelay(50);
1410 delay++; 1386 delay++;
1411 mii_indicator = readl(&mac->mii_mgmt_indicator); 1387 mii_indicator = readl(&mac->mii_mgmt_indicator);
1412 } while ((mii_indicator & MGMT_WAIT) && delay < 50); 1388 } while ((mii_indicator & ET_MAC_MGMT_WAIT) && delay < 50);
1413 1389
1414 /* If we hit the max delay, we could not read the register */ 1390 /* If we hit the max delay, we could not read the register */
1415 if (delay == 50) { 1391 if (delay == 50) {
@@ -1422,8 +1398,9 @@ static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr,
1422 } 1398 }
1423 1399
1424 /* If we hit here we were able to read the register and we need to 1400 /* If we hit here we were able to read the register and we need to
1425 * return the value to the caller */ 1401 * return the value to the caller
1426 *value = readl(&mac->mii_mgmt_stat) & 0xFFFF; 1402 */
1403 *value = readl(&mac->mii_mgmt_stat) & ET_MAC_MIIMGMT_STAT_PHYCRTL_MASK;
1427 1404
1428 /* Stop the read operation */ 1405 /* Stop the read operation */
1429 writel(0, &mac->mii_mgmt_cmd); 1406 writel(0, &mac->mii_mgmt_cmd);
@@ -1447,8 +1424,7 @@ static int et131x_mii_read(struct et131x_adapter *adapter, u8 reg, u16 *value)
1447 return et131x_phy_mii_read(adapter, phydev->addr, reg, value); 1424 return et131x_phy_mii_read(adapter, phydev->addr, reg, value);
1448} 1425}
1449 1426
1450/** 1427/* et131x_mii_write - Write to a PHY reg through the MII interface of the MAC
1451 * et131x_mii_write - Write to a PHY register through the MII interface of the MAC
1452 * @adapter: pointer to our private adapter structure 1428 * @adapter: pointer to our private adapter structure
1453 * @reg: the register to read 1429 * @reg: the register to read
1454 * @value: 16-bit value to write 1430 * @value: 16-bit value to write
@@ -1483,7 +1459,7 @@ static int et131x_mii_write(struct et131x_adapter *adapter, u8 reg, u16 value)
1483 writel(0, &mac->mii_mgmt_cmd); 1459 writel(0, &mac->mii_mgmt_cmd);
1484 1460
1485 /* Set up the register we need to write to on the correct PHY */ 1461 /* Set up the register we need to write to on the correct PHY */
1486 writel(MII_ADDR(addr, reg), &mac->mii_mgmt_addr); 1462 writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr);
1487 1463
1488 /* Add the value to write to the registers to the mac */ 1464 /* Add the value to write to the registers to the mac */
1489 writel(value, &mac->mii_mgmt_ctrl); 1465 writel(value, &mac->mii_mgmt_ctrl);
@@ -1492,7 +1468,7 @@ static int et131x_mii_write(struct et131x_adapter *adapter, u8 reg, u16 value)
1492 udelay(50); 1468 udelay(50);
1493 delay++; 1469 delay++;
1494 mii_indicator = readl(&mac->mii_mgmt_indicator); 1470 mii_indicator = readl(&mac->mii_mgmt_indicator);
1495 } while ((mii_indicator & MGMT_BUSY) && delay < 100); 1471 } while ((mii_indicator & ET_MAC_MGMT_BUSY) && delay < 100);
1496 1472
1497 /* If we hit the max delay, we could not write the register */ 1473 /* If we hit the max delay, we could not write the register */
1498 if (delay == 100) { 1474 if (delay == 100) {
@@ -1512,8 +1488,7 @@ static int et131x_mii_write(struct et131x_adapter *adapter, u8 reg, u16 value)
1512 /* Stop the write operation */ 1488 /* Stop the write operation */
1513 writel(0, &mac->mii_mgmt_cmd); 1489 writel(0, &mac->mii_mgmt_cmd);
1514 1490
1515 /* 1491 /* set the registers we touched back to the state at which we entered
1516 * set the registers we touched back to the state at which we entered
1517 * this function 1492 * this function
1518 */ 1493 */
1519 writel(mii_addr, &mac->mii_mgmt_addr); 1494 writel(mii_addr, &mac->mii_mgmt_addr);
@@ -1528,7 +1503,7 @@ static void et1310_phy_access_mii_bit(struct et131x_adapter *adapter,
1528 u8 *value) 1503 u8 *value)
1529{ 1504{
1530 u16 reg; 1505 u16 reg;
1531 u16 mask = 0x0001 << bitnum; 1506 u16 mask = 1 << bitnum;
1532 1507
1533 /* Read the requested register */ 1508 /* Read the requested register */
1534 et131x_mii_read(adapter, regnum, &reg); 1509 et131x_mii_read(adapter, regnum, &reg);
@@ -1579,7 +1554,8 @@ static void et1310_config_flow_control(struct et131x_adapter *adapter)
1579 (remote_async_pause == TRUEPHY_BIT_CLEAR)) { 1554 (remote_async_pause == TRUEPHY_BIT_CLEAR)) {
1580 adapter->flowcontrol = FLOW_NONE; 1555 adapter->flowcontrol = FLOW_NONE;
1581 } else {/* if (remote_pause == TRUEPHY_CLEAR_BIT && 1556 } else {/* if (remote_pause == TRUEPHY_CLEAR_BIT &&
1582 remote_async_pause == TRUEPHY_SET_BIT) */ 1557 * remote_async_pause == TRUEPHY_SET_BIT)
1558 */
1583 if (adapter->wanted_flow == FLOW_BOTH) 1559 if (adapter->wanted_flow == FLOW_BOTH)
1584 adapter->flowcontrol = FLOW_RXONLY; 1560 adapter->flowcontrol = FLOW_RXONLY;
1585 else 1561 else
@@ -1588,8 +1564,7 @@ static void et1310_config_flow_control(struct et131x_adapter *adapter)
1588 } 1564 }
1589} 1565}
1590 1566
1591/** 1567/* et1310_update_macstat_host_counters - Update the local copy of the statistics
1592 * et1310_update_macstat_host_counters - Update the local copy of the statistics
1593 * @adapter: pointer to the adapter structure 1568 * @adapter: pointer to the adapter structure
1594 */ 1569 */
1595static void et1310_update_macstat_host_counters(struct et131x_adapter *adapter) 1570static void et1310_update_macstat_host_counters(struct et131x_adapter *adapter)
@@ -1616,8 +1591,7 @@ static void et1310_update_macstat_host_counters(struct et131x_adapter *adapter)
1616 stats->rx_other_errs += readl(&macstat->rx_fragment_packets); 1591 stats->rx_other_errs += readl(&macstat->rx_fragment_packets);
1617} 1592}
1618 1593
1619/** 1594/* et1310_handle_macstat_interrupt
1620 * et1310_handle_macstat_interrupt
1621 * @adapter: pointer to the adapter structure 1595 * @adapter: pointer to the adapter structure
1622 * 1596 *
1623 * One of the MACSTAT counters has wrapped. Update the local copy of 1597 * One of the MACSTAT counters has wrapped. Update the local copy of
@@ -1708,8 +1682,7 @@ static int et131x_mdio_reset(struct mii_bus *bus)
1708 return 0; 1682 return 0;
1709} 1683}
1710 1684
1711/** 1685/* et1310_phy_power_down - PHY power control
1712 * et1310_phy_power_down - PHY power control
1713 * @adapter: device to control 1686 * @adapter: device to control
1714 * @down: true for off/false for back on 1687 * @down: true for off/false for back on
1715 * 1688 *
@@ -1729,8 +1702,7 @@ static void et1310_phy_power_down(struct et131x_adapter *adapter, bool down)
1729 et131x_mii_write(adapter, MII_BMCR, data); 1702 et131x_mii_write(adapter, MII_BMCR, data);
1730} 1703}
1731 1704
1732/** 1705/* et131x_xcvr_init - Init the phy if we are setting it into force mode
1733 * et131x_xcvr_init - Init the phy if we are setting it into force mode
1734 * @adapter: pointer to our private adapter structure 1706 * @adapter: pointer to our private adapter structure
1735 * 1707 *
1736 */ 1708 */
@@ -1761,8 +1733,7 @@ static void et131x_xcvr_init(struct et131x_adapter *adapter)
1761 } 1733 }
1762} 1734}
1763 1735
1764/** 1736/* et131x_configure_global_regs - configure JAGCore global regs
1765 * et131x_configure_global_regs - configure JAGCore global regs
1766 * @adapter: pointer to our adapter structure 1737 * @adapter: pointer to our adapter structure
1767 * 1738 *
1768 * Used to configure the global registers on the JAGCore 1739 * Used to configure the global registers on the JAGCore
@@ -1808,8 +1779,7 @@ static void et131x_configure_global_regs(struct et131x_adapter *adapter)
1808 writel(0, &regs->watchdog_timer); 1779 writel(0, &regs->watchdog_timer);
1809} 1780}
1810 1781
1811/** 1782/* et131x_config_rx_dma_regs - Start of Rx_DMA init sequence
1812 * et131x_config_rx_dma_regs - Start of Rx_DMA init sequence
1813 * @adapter: pointer to our adapter structure 1783 * @adapter: pointer to our adapter structure
1814 */ 1784 */
1815static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter) 1785static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
@@ -1839,7 +1809,7 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
1839 writel(rx_local->psr_num_entries - 1, &rx_dma->psr_num_des); 1809 writel(rx_local->psr_num_entries - 1, &rx_dma->psr_num_des);
1840 writel(0, &rx_dma->psr_full_offset); 1810 writel(0, &rx_dma->psr_full_offset);
1841 1811
1842 psr_num_des = readl(&rx_dma->psr_num_des) & 0xFFF; 1812 psr_num_des = readl(&rx_dma->psr_num_des) & ET_RXDMA_PSR_NUM_DES_MASK;
1843 writel((psr_num_des * LO_MARK_PERCENT_FOR_PSR) / 100, 1813 writel((psr_num_des * LO_MARK_PERCENT_FOR_PSR) / 100,
1844 &rx_dma->psr_min_des); 1814 &rx_dma->psr_min_des);
1845 1815
@@ -1849,11 +1819,11 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
1849 rx_local->local_psr_full = 0; 1819 rx_local->local_psr_full = 0;
1850 1820
1851 for (id = 0; id < NUM_FBRS; id++) { 1821 for (id = 0; id < NUM_FBRS; id++) {
1852 u32 *num_des; 1822 u32 __iomem *num_des;
1853 u32 *full_offset; 1823 u32 __iomem *full_offset;
1854 u32 *min_des; 1824 u32 __iomem *min_des;
1855 u32 *base_hi; 1825 u32 __iomem *base_hi;
1856 u32 *base_lo; 1826 u32 __iomem *base_lo;
1857 1827
1858 if (id == 0) { 1828 if (id == 0) {
1859 num_des = &rx_dma->fbr0_num_des; 1829 num_des = &rx_dma->fbr0_num_des;
@@ -1916,8 +1886,7 @@ static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter)
1916 spin_unlock_irqrestore(&adapter->rcv_lock, flags); 1886 spin_unlock_irqrestore(&adapter->rcv_lock, flags);
1917} 1887}
1918 1888
1919/** 1889/* et131x_config_tx_dma_regs - Set up the tx dma section of the JAGCore.
1920 * et131x_config_tx_dma_regs - Set up the tx dma section of the JAGCore.
1921 * @adapter: pointer to our private adapter structure 1890 * @adapter: pointer to our private adapter structure
1922 * 1891 *
1923 * Configure the transmit engine with the ring buffers we have created 1892 * Configure the transmit engine with the ring buffers we have created
@@ -1948,8 +1917,7 @@ static void et131x_config_tx_dma_regs(struct et131x_adapter *adapter)
1948 adapter->tx_ring.send_idx = 0; 1917 adapter->tx_ring.send_idx = 0;
1949} 1918}
1950 1919
1951/** 1920/* et131x_adapter_setup - Set the adapter up as per cassini+ documentation
1952 * et131x_adapter_setup - Set the adapter up as per cassini+ documentation
1953 * @adapter: pointer to our private adapter structure 1921 * @adapter: pointer to our private adapter structure
1954 * 1922 *
1955 * Returns 0 on success, errno on failure (as defined in errno.h) 1923 * Returns 0 on success, errno on failure (as defined in errno.h)
@@ -1977,23 +1945,29 @@ static void et131x_adapter_setup(struct et131x_adapter *adapter)
1977 et131x_xcvr_init(adapter); 1945 et131x_xcvr_init(adapter);
1978} 1946}
1979 1947
1980/** 1948/* et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310
1981 * et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310
1982 * @adapter: pointer to our private adapter structure 1949 * @adapter: pointer to our private adapter structure
1983 */ 1950 */
1984static void et131x_soft_reset(struct et131x_adapter *adapter) 1951static void et131x_soft_reset(struct et131x_adapter *adapter)
1985{ 1952{
1986 /* Disable MAC Core */ 1953 u32 reg;
1987 writel(0xc00f0000, &adapter->regs->mac.cfg1);
1988 1954
1989 /* Set everything to a reset value */ 1955 /* Disable MAC Core */
1990 writel(0x7F, &adapter->regs->global.sw_reset); 1956 reg = ET_MAC_CFG1_SOFT_RESET | ET_MAC_CFG1_SIM_RESET |
1991 writel(0x000f0000, &adapter->regs->mac.cfg1); 1957 ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC |
1992 writel(0x00000000, &adapter->regs->mac.cfg1); 1958 ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC;
1959 writel(reg, &adapter->regs->mac.cfg1);
1960
1961 reg = ET_RESET_ALL;
1962 writel(reg, &adapter->regs->global.sw_reset);
1963
1964 reg = ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC |
1965 ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC;
1966 writel(reg, &adapter->regs->mac.cfg1);
1967 writel(0, &adapter->regs->mac.cfg1);
1993} 1968}
1994 1969
1995/** 1970/* et131x_enable_interrupts - enable interrupt
1996 * et131x_enable_interrupts - enable interrupt
1997 * @adapter: et131x device 1971 * @adapter: et131x device
1998 * 1972 *
1999 * Enable the appropriate interrupts on the ET131x according to our 1973 * Enable the appropriate interrupts on the ET131x according to our
@@ -2013,8 +1987,7 @@ static void et131x_enable_interrupts(struct et131x_adapter *adapter)
2013 writel(mask, &adapter->regs->global.int_mask); 1987 writel(mask, &adapter->regs->global.int_mask);
2014} 1988}
2015 1989
2016/** 1990/* et131x_disable_interrupts - interrupt disable
2017 * et131x_disable_interrupts - interrupt disable
2018 * @adapter: et131x device 1991 * @adapter: et131x device
2019 * 1992 *
2020 * Block all interrupts from the et131x device at the device itself 1993 * Block all interrupts from the et131x device at the device itself
@@ -2025,19 +1998,17 @@ static void et131x_disable_interrupts(struct et131x_adapter *adapter)
2025 writel(INT_MASK_DISABLE, &adapter->regs->global.int_mask); 1998 writel(INT_MASK_DISABLE, &adapter->regs->global.int_mask);
2026} 1999}
2027 2000
2028/** 2001/* et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310
2029 * et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310
2030 * @adapter: pointer to our adapter structure 2002 * @adapter: pointer to our adapter structure
2031 */ 2003 */
2032static void et131x_tx_dma_disable(struct et131x_adapter *adapter) 2004static void et131x_tx_dma_disable(struct et131x_adapter *adapter)
2033{ 2005{
2034 /* Setup the tramsmit dma configuration register */ 2006 /* Setup the tramsmit dma configuration register */
2035 writel(ET_TXDMA_CSR_HALT|ET_TXDMA_SNGL_EPKT, 2007 writel(ET_TXDMA_CSR_HALT | ET_TXDMA_SNGL_EPKT,
2036 &adapter->regs->txdma.csr); 2008 &adapter->regs->txdma.csr);
2037} 2009}
2038 2010
2039/** 2011/* et131x_enable_txrx - Enable tx/rx queues
2040 * et131x_enable_txrx - Enable tx/rx queues
2041 * @netdev: device to be enabled 2012 * @netdev: device to be enabled
2042 */ 2013 */
2043static void et131x_enable_txrx(struct net_device *netdev) 2014static void et131x_enable_txrx(struct net_device *netdev)
@@ -2049,15 +2020,14 @@ static void et131x_enable_txrx(struct net_device *netdev)
2049 et131x_tx_dma_enable(adapter); 2020 et131x_tx_dma_enable(adapter);
2050 2021
2051 /* Enable device interrupts */ 2022 /* Enable device interrupts */
2052 if (adapter->flags & fMP_ADAPTER_INTERRUPT_IN_USE) 2023 if (adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE)
2053 et131x_enable_interrupts(adapter); 2024 et131x_enable_interrupts(adapter);
2054 2025
2055 /* We're ready to move some data, so start the queue */ 2026 /* We're ready to move some data, so start the queue */
2056 netif_start_queue(netdev); 2027 netif_start_queue(netdev);
2057} 2028}
2058 2029
2059/** 2030/* et131x_disable_txrx - Disable tx/rx queues
2060 * et131x_disable_txrx - Disable tx/rx queues
2061 * @netdev: device to be disabled 2031 * @netdev: device to be disabled
2062 */ 2032 */
2063static void et131x_disable_txrx(struct net_device *netdev) 2033static void et131x_disable_txrx(struct net_device *netdev)
@@ -2075,8 +2045,7 @@ static void et131x_disable_txrx(struct net_device *netdev)
2075 et131x_disable_interrupts(adapter); 2045 et131x_disable_interrupts(adapter);
2076} 2046}
2077 2047
2078/** 2048/* et131x_init_send - Initialize send data structures
2079 * et131x_init_send - Initialize send data structures
2080 * @adapter: pointer to our private adapter structure 2049 * @adapter: pointer to our private adapter structure
2081 */ 2050 */
2082static void et131x_init_send(struct et131x_adapter *adapter) 2051static void et131x_init_send(struct et131x_adapter *adapter)
@@ -2109,8 +2078,7 @@ static void et131x_init_send(struct et131x_adapter *adapter)
2109 tx_ring->send_tail = NULL; 2078 tx_ring->send_tail = NULL;
2110} 2079}
2111 2080
2112/** 2081/* et1310_enable_phy_coma - called when network cable is unplugged
2113 * et1310_enable_phy_coma - called when network cable is unplugged
2114 * @adapter: pointer to our adapter structure 2082 * @adapter: pointer to our adapter structure
2115 * 2083 *
2116 * driver receive an phy status change interrupt while in D0 and check that 2084 * driver receive an phy status change interrupt while in D0 and check that
@@ -2139,8 +2107,7 @@ static void et1310_enable_phy_coma(struct et131x_adapter *adapter)
2139 /* Save the GbE PHY speed and duplex modes. Need to restore this 2107 /* Save the GbE PHY speed and duplex modes. Need to restore this
2140 * when cable is plugged back in 2108 * when cable is plugged back in
2141 */ 2109 */
2142 /* 2110 /* TODO - when PM is re-enabled, check if we need to
2143 * TODO - when PM is re-enabled, check if we need to
2144 * perform a similar task as this - 2111 * perform a similar task as this -
2145 * adapter->pdown_speed = adapter->ai_force_speed; 2112 * adapter->pdown_speed = adapter->ai_force_speed;
2146 * adapter->pdown_duplex = adapter->ai_force_duplex; 2113 * adapter->pdown_duplex = adapter->ai_force_duplex;
@@ -2148,7 +2115,7 @@ static void et1310_enable_phy_coma(struct et131x_adapter *adapter)
2148 2115
2149 /* Stop sending packets. */ 2116 /* Stop sending packets. */
2150 spin_lock_irqsave(&adapter->send_hw_lock, flags); 2117 spin_lock_irqsave(&adapter->send_hw_lock, flags);
2151 adapter->flags |= fMP_ADAPTER_LOWER_POWER; 2118 adapter->flags |= FMP_ADAPTER_LOWER_POWER;
2152 spin_unlock_irqrestore(&adapter->send_hw_lock, flags); 2119 spin_unlock_irqrestore(&adapter->send_hw_lock, flags);
2153 2120
2154 /* Wait for outstanding Receive packets */ 2121 /* Wait for outstanding Receive packets */
@@ -2164,8 +2131,7 @@ static void et1310_enable_phy_coma(struct et131x_adapter *adapter)
2164 writel(pmcsr, &adapter->regs->global.pm_csr); 2131 writel(pmcsr, &adapter->regs->global.pm_csr);
2165} 2132}
2166 2133
2167/** 2134/* et1310_disable_phy_coma - Disable the Phy Coma Mode
2168 * et1310_disable_phy_coma - Disable the Phy Coma Mode
2169 * @adapter: pointer to our adapter structure 2135 * @adapter: pointer to our adapter structure
2170 */ 2136 */
2171static void et1310_disable_phy_coma(struct et131x_adapter *adapter) 2137static void et1310_disable_phy_coma(struct et131x_adapter *adapter)
@@ -2201,7 +2167,7 @@ static void et1310_disable_phy_coma(struct et131x_adapter *adapter)
2201 et131x_adapter_setup(adapter); 2167 et131x_adapter_setup(adapter);
2202 2168
2203 /* Allow Tx to restart */ 2169 /* Allow Tx to restart */
2204 adapter->flags &= ~fMP_ADAPTER_LOWER_POWER; 2170 adapter->flags &= ~FMP_ADAPTER_LOWER_POWER;
2205 2171
2206 et131x_enable_txrx(adapter->netdev); 2172 et131x_enable_txrx(adapter->netdev);
2207} 2173}
@@ -2211,9 +2177,10 @@ static inline u32 bump_free_buff_ring(u32 *free_buff_ring, u32 limit)
2211 u32 tmp_free_buff_ring = *free_buff_ring; 2177 u32 tmp_free_buff_ring = *free_buff_ring;
2212 tmp_free_buff_ring++; 2178 tmp_free_buff_ring++;
2213 /* This works for all cases where limit < 1024. The 1023 case 2179 /* This works for all cases where limit < 1024. The 1023 case
2214 works because 1023++ is 1024 which means the if condition is not 2180 * works because 1023++ is 1024 which means the if condition is not
2215 taken but the carry of the bit into the wrap bit toggles the wrap 2181 * taken but the carry of the bit into the wrap bit toggles the wrap
2216 value correctly */ 2182 * value correctly
2183 */
2217 if ((tmp_free_buff_ring & ET_DMA10_MASK) > limit) { 2184 if ((tmp_free_buff_ring & ET_DMA10_MASK) > limit) {
2218 tmp_free_buff_ring &= ~ET_DMA10_MASK; 2185 tmp_free_buff_ring &= ~ET_DMA10_MASK;
2219 tmp_free_buff_ring ^= ET_DMA10_WRAP; 2186 tmp_free_buff_ring ^= ET_DMA10_WRAP;
@@ -2224,8 +2191,7 @@ static inline u32 bump_free_buff_ring(u32 *free_buff_ring, u32 limit)
2224 return tmp_free_buff_ring; 2191 return tmp_free_buff_ring;
2225} 2192}
2226 2193
2227/** 2194/* et131x_rx_dma_memory_alloc
2228 * et131x_rx_dma_memory_alloc
2229 * @adapter: pointer to our private adapter structure 2195 * @adapter: pointer to our private adapter structure
2230 * 2196 *
2231 * Returns 0 on success and errno on failure (as defined in errno.h) 2197 * Returns 0 on success and errno on failure (as defined in errno.h)
@@ -2365,8 +2331,7 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
2365 pr_info("Packet Status Ring %llx\n", 2331 pr_info("Packet Status Ring %llx\n",
2366 (unsigned long long) rx_ring->ps_ring_physaddr); 2332 (unsigned long long) rx_ring->ps_ring_physaddr);
2367 2333
2368 /* 2334 /* NOTE : dma_alloc_coherent(), used above to alloc DMA regions,
2369 * NOTE : dma_alloc_coherent(), used above to alloc DMA regions,
2370 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses 2335 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
2371 * are ever returned, make sure the high part is retrieved here before 2336 * are ever returned, make sure the high part is retrieved here before
2372 * storing the adjusted address. 2337 * storing the adjusted address.
@@ -2392,8 +2357,7 @@ static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter)
2392 return 0; 2357 return 0;
2393} 2358}
2394 2359
2395/** 2360/* et131x_rx_dma_memory_free - Free all memory allocated within this module.
2396 * et131x_rx_dma_memory_free - Free all memory allocated within this module.
2397 * @adapter: pointer to our private adapter structure 2361 * @adapter: pointer to our private adapter structure
2398 */ 2362 */
2399static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) 2363static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
@@ -2480,8 +2444,7 @@ static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter)
2480 rx_ring->num_ready_recv = 0; 2444 rx_ring->num_ready_recv = 0;
2481} 2445}
2482 2446
2483/** 2447/* et131x_init_recv - Initialize receive data structures.
2484 * et131x_init_recv - Initialize receive data structures.
2485 * @adapter: pointer to our private adapter structure 2448 * @adapter: pointer to our private adapter structure
2486 * 2449 *
2487 * Returns 0 on success and errno on failure (as defined in errno.h) 2450 * Returns 0 on success and errno on failure (as defined in errno.h)
@@ -2499,11 +2462,8 @@ static int et131x_init_recv(struct et131x_adapter *adapter)
2499 /* Setup each RFD */ 2462 /* Setup each RFD */
2500 for (rfdct = 0; rfdct < rx_ring->num_rfd; rfdct++) { 2463 for (rfdct = 0; rfdct < rx_ring->num_rfd; rfdct++) {
2501 rfd = kzalloc(sizeof(struct rfd), GFP_ATOMIC | GFP_DMA); 2464 rfd = kzalloc(sizeof(struct rfd), GFP_ATOMIC | GFP_DMA);
2502 2465 if (!rfd)
2503 if (!rfd) {
2504 dev_err(&adapter->pdev->dev, "Couldn't alloc RFD\n");
2505 return -ENOMEM; 2466 return -ENOMEM;
2506 }
2507 2467
2508 rfd->skb = NULL; 2468 rfd->skb = NULL;
2509 2469
@@ -2518,8 +2478,7 @@ static int et131x_init_recv(struct et131x_adapter *adapter)
2518 return 0; 2478 return 0;
2519} 2479}
2520 2480
2521/** 2481/* et131x_set_rx_dma_timer - Set the heartbeat timer according to line rate.
2522 * et131x_set_rx_dma_timer - Set the heartbeat timer according to line rate.
2523 * @adapter: pointer to our adapter structure 2482 * @adapter: pointer to our adapter structure
2524 */ 2483 */
2525static void et131x_set_rx_dma_timer(struct et131x_adapter *adapter) 2484static void et131x_set_rx_dma_timer(struct et131x_adapter *adapter)
@@ -2538,8 +2497,7 @@ static void et131x_set_rx_dma_timer(struct et131x_adapter *adapter)
2538 } 2497 }
2539} 2498}
2540 2499
2541/** 2500/* NICReturnRFD - Recycle a RFD and put it back onto the receive list
2542 * NICReturnRFD - Recycle a RFD and put it back onto the receive list
2543 * @adapter: pointer to our adapter 2501 * @adapter: pointer to our adapter
2544 * @rfd: pointer to the RFD 2502 * @rfd: pointer to the RFD
2545 */ 2503 */
@@ -2555,7 +2513,7 @@ static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd)
2555 * need to clean up OOB data 2513 * need to clean up OOB data
2556 */ 2514 */
2557 if (buff_index < rx_local->fbr[ring_index]->num_entries) { 2515 if (buff_index < rx_local->fbr[ring_index]->num_entries) {
2558 u32 *offset; 2516 u32 __iomem *offset;
2559 struct fbr_desc *next; 2517 struct fbr_desc *next;
2560 2518
2561 spin_lock_irqsave(&adapter->fbr_lock, flags); 2519 spin_lock_irqsave(&adapter->fbr_lock, flags);
@@ -2599,8 +2557,7 @@ static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd)
2599 WARN_ON(rx_local->num_ready_recv > rx_local->num_rfd); 2557 WARN_ON(rx_local->num_ready_recv > rx_local->num_rfd);
2600} 2558}
2601 2559
2602/** 2560/* nic_rx_pkts - Checks the hardware for available packets
2603 * nic_rx_pkts - Checks the hardware for available packets
2604 * @adapter: pointer to our adapter 2561 * @adapter: pointer to our adapter
2605 * 2562 *
2606 * Returns rfd, a pointer to our MPRFD. 2563 * Returns rfd, a pointer to our MPRFD.
@@ -2773,7 +2730,6 @@ static struct rfd *nic_rx_pkts(struct et131x_adapter *adapter)
2773 rx_local->fbr[ring_index]->virt[buff_index], 2730 rx_local->fbr[ring_index]->virt[buff_index],
2774 rfd->len); 2731 rfd->len);
2775 2732
2776 skb->dev = adapter->netdev;
2777 skb->protocol = eth_type_trans(skb, adapter->netdev); 2733 skb->protocol = eth_type_trans(skb, adapter->netdev);
2778 skb->ip_summed = CHECKSUM_NONE; 2734 skb->ip_summed = CHECKSUM_NONE;
2779 netif_rx_ni(skb); 2735 netif_rx_ni(skb);
@@ -2783,8 +2739,7 @@ out:
2783 return rfd; 2739 return rfd;
2784} 2740}
2785 2741
2786/** 2742/* et131x_handle_recv_interrupt - Interrupt handler for receive processing
2787 * et131x_handle_recv_interrupt - Interrupt handler for receive processing
2788 * @adapter: pointer to our adapter 2743 * @adapter: pointer to our adapter
2789 * 2744 *
2790 * Assumption, Rcv spinlock has been acquired. 2745 * Assumption, Rcv spinlock has been acquired.
@@ -2838,8 +2793,7 @@ static void et131x_handle_recv_interrupt(struct et131x_adapter *adapter)
2838 adapter->rx_ring.unfinished_receives = false; 2793 adapter->rx_ring.unfinished_receives = false;
2839} 2794}
2840 2795
2841/** 2796/* et131x_tx_dma_memory_alloc
2842 * et131x_tx_dma_memory_alloc
2843 * @adapter: pointer to our private adapter structure 2797 * @adapter: pointer to our private adapter structure
2844 * 2798 *
2845 * Returns 0 on success and errno on failure (as defined in errno.h). 2799 * Returns 0 on success and errno on failure (as defined in errno.h).
@@ -2856,12 +2810,10 @@ static int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter)
2856 struct tx_ring *tx_ring = &adapter->tx_ring; 2810 struct tx_ring *tx_ring = &adapter->tx_ring;
2857 2811
2858 /* Allocate memory for the TCB's (Transmit Control Block) */ 2812 /* Allocate memory for the TCB's (Transmit Control Block) */
2859 adapter->tx_ring.tcb_ring = 2813 adapter->tx_ring.tcb_ring = kcalloc(NUM_TCB, sizeof(struct tcb),
2860 kcalloc(NUM_TCB, sizeof(struct tcb), GFP_ATOMIC | GFP_DMA); 2814 GFP_ATOMIC | GFP_DMA);
2861 if (!adapter->tx_ring.tcb_ring) { 2815 if (!adapter->tx_ring.tcb_ring)
2862 dev_err(&adapter->pdev->dev, "Cannot alloc memory for TCBs\n");
2863 return -ENOMEM; 2816 return -ENOMEM;
2864 }
2865 2817
2866 desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX); 2818 desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX);
2867 tx_ring->tx_desc_ring = 2819 tx_ring->tx_desc_ring =
@@ -2895,8 +2847,7 @@ static int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter)
2895 return 0; 2847 return 0;
2896} 2848}
2897 2849
2898/** 2850/* et131x_tx_dma_memory_free - Free all memory allocated within this module
2899 * et131x_tx_dma_memory_free - Free all memory allocated within this module
2900 * @adapter: pointer to our private adapter structure 2851 * @adapter: pointer to our private adapter structure
2901 * 2852 *
2902 * Returns 0 on success and errno on failure (as defined in errno.h). 2853 * Returns 0 on success and errno on failure (as defined in errno.h).
@@ -2928,8 +2879,7 @@ static void et131x_tx_dma_memory_free(struct et131x_adapter *adapter)
2928 kfree(adapter->tx_ring.tcb_ring); 2879 kfree(adapter->tx_ring.tcb_ring);
2929} 2880}
2930 2881
2931/** 2882/* nic_send_packet - NIC specific send handler for version B silicon.
2932 * nic_send_packet - NIC specific send handler for version B silicon.
2933 * @adapter: pointer to our adapter 2883 * @adapter: pointer to our adapter
2934 * @tcb: pointer to struct tcb 2884 * @tcb: pointer to struct tcb
2935 * 2885 *
@@ -2977,7 +2927,8 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
2977 */ 2927 */
2978 if (skb_headlen(skb) <= 1514) { 2928 if (skb_headlen(skb) <= 1514) {
2979 /* Low 16bits are length, high is vlan and 2929 /* Low 16bits are length, high is vlan and
2980 unused currently so zero */ 2930 * unused currently so zero
2931 */
2981 desc[frag].len_vlan = skb_headlen(skb); 2932 desc[frag].len_vlan = skb_headlen(skb);
2982 dma_addr = dma_map_single(&adapter->pdev->dev, 2933 dma_addr = dma_map_single(&adapter->pdev->dev,
2983 skb->data, 2934 skb->data,
@@ -3022,23 +2973,24 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
3022 if (phydev && phydev->speed == SPEED_1000) { 2973 if (phydev && phydev->speed == SPEED_1000) {
3023 if (++adapter->tx_ring.since_irq == PARM_TX_NUM_BUFS_DEF) { 2974 if (++adapter->tx_ring.since_irq == PARM_TX_NUM_BUFS_DEF) {
3024 /* Last element & Interrupt flag */ 2975 /* Last element & Interrupt flag */
3025 desc[frag - 1].flags = 0x5; 2976 desc[frag - 1].flags =
2977 TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT;
3026 adapter->tx_ring.since_irq = 0; 2978 adapter->tx_ring.since_irq = 0;
3027 } else { /* Last element */ 2979 } else { /* Last element */
3028 desc[frag - 1].flags = 0x1; 2980 desc[frag - 1].flags = TXDESC_FLAG_LASTPKT;
3029 } 2981 }
3030 } else 2982 } else
3031 desc[frag - 1].flags = 0x5; 2983 desc[frag - 1].flags =
2984 TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT;
3032 2985
3033 desc[0].flags |= 2; /* First element flag */ 2986 desc[0].flags |= TXDESC_FLAG_FIRSTPKT;
3034 2987
3035 tcb->index_start = adapter->tx_ring.send_idx; 2988 tcb->index_start = adapter->tx_ring.send_idx;
3036 tcb->stale = 0; 2989 tcb->stale = 0;
3037 2990
3038 spin_lock_irqsave(&adapter->send_hw_lock, flags); 2991 spin_lock_irqsave(&adapter->send_hw_lock, flags);
3039 2992
3040 thiscopy = NUM_DESC_PER_RING_TX - 2993 thiscopy = NUM_DESC_PER_RING_TX - INDEX10(adapter->tx_ring.send_idx);
3041 INDEX10(adapter->tx_ring.send_idx);
3042 2994
3043 if (thiscopy >= frag) { 2995 if (thiscopy >= frag) {
3044 remainder = 0; 2996 remainder = 0;
@@ -3106,8 +3058,7 @@ static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb)
3106 return 0; 3058 return 0;
3107} 3059}
3108 3060
3109/** 3061/* send_packet - Do the work to send a packet
3110 * send_packet - Do the work to send a packet
3111 * @skb: the packet(s) to send 3062 * @skb: the packet(s) to send
3112 * @adapter: a pointer to the device's private adapter structure 3063 * @adapter: a pointer to the device's private adapter structure
3113 * 3064 *
@@ -3150,9 +3101,9 @@ static int send_packet(struct sk_buff *skb, struct et131x_adapter *adapter)
3150 3101
3151 if ((shbufva[0] == 0xffff) && 3102 if ((shbufva[0] == 0xffff) &&
3152 (shbufva[1] == 0xffff) && (shbufva[2] == 0xffff)) { 3103 (shbufva[1] == 0xffff) && (shbufva[2] == 0xffff)) {
3153 tcb->flags |= fMP_DEST_BROAD; 3104 tcb->flags |= FMP_DEST_BROAD;
3154 } else if ((shbufva[0] & 0x3) == 0x0001) { 3105 } else if ((shbufva[0] & 0x3) == 0x0001) {
3155 tcb->flags |= fMP_DEST_MULTI; 3106 tcb->flags |= FMP_DEST_MULTI;
3156 } 3107 }
3157 } 3108 }
3158 3109
@@ -3178,8 +3129,7 @@ static int send_packet(struct sk_buff *skb, struct et131x_adapter *adapter)
3178 return 0; 3129 return 0;
3179} 3130}
3180 3131
3181/** 3132/* et131x_send_packets - This function is called by the OS to send packets
3182 * et131x_send_packets - This function is called by the OS to send packets
3183 * @skb: the packet(s) to send 3133 * @skb: the packet(s) to send
3184 * @netdev:device on which to TX the above packet(s) 3134 * @netdev:device on which to TX the above packet(s)
3185 * 3135 *
@@ -3207,7 +3157,7 @@ static int et131x_send_packets(struct sk_buff *skb, struct net_device *netdev)
3207 /* We need to see if the link is up; if it's not, make the 3157 /* We need to see if the link is up; if it's not, make the
3208 * netif layer think we're good and drop the packet 3158 * netif layer think we're good and drop the packet
3209 */ 3159 */
3210 if ((adapter->flags & fMP_ADAPTER_FAIL_SEND_MASK) || 3160 if ((adapter->flags & FMP_ADAPTER_FAIL_SEND_MASK) ||
3211 !netif_carrier_ok(netdev)) { 3161 !netif_carrier_ok(netdev)) {
3212 dev_kfree_skb_any(skb); 3162 dev_kfree_skb_any(skb);
3213 skb = NULL; 3163 skb = NULL;
@@ -3228,8 +3178,7 @@ static int et131x_send_packets(struct sk_buff *skb, struct net_device *netdev)
3228 return status; 3178 return status;
3229} 3179}
3230 3180
3231/** 3181/* free_send_packet - Recycle a struct tcb
3232 * free_send_packet - Recycle a struct tcb
3233 * @adapter: pointer to our adapter 3182 * @adapter: pointer to our adapter
3234 * @tcb: pointer to struct tcb 3183 * @tcb: pointer to struct tcb
3235 * 3184 *
@@ -3244,9 +3193,9 @@ static inline void free_send_packet(struct et131x_adapter *adapter,
3244 struct net_device_stats *stats = &adapter->net_stats; 3193 struct net_device_stats *stats = &adapter->net_stats;
3245 u64 dma_addr; 3194 u64 dma_addr;
3246 3195
3247 if (tcb->flags & fMP_DEST_BROAD) 3196 if (tcb->flags & FMP_DEST_BROAD)
3248 atomic_inc(&adapter->stats.broadcast_pkts_xmtd); 3197 atomic_inc(&adapter->stats.broadcast_pkts_xmtd);
3249 else if (tcb->flags & fMP_DEST_MULTI) 3198 else if (tcb->flags & FMP_DEST_MULTI)
3250 atomic_inc(&adapter->stats.multicast_pkts_xmtd); 3199 atomic_inc(&adapter->stats.multicast_pkts_xmtd);
3251 else 3200 else
3252 atomic_inc(&adapter->stats.unicast_pkts_xmtd); 3201 atomic_inc(&adapter->stats.unicast_pkts_xmtd);
@@ -3301,8 +3250,7 @@ static inline void free_send_packet(struct et131x_adapter *adapter,
3301 WARN_ON(adapter->tx_ring.used < 0); 3250 WARN_ON(adapter->tx_ring.used < 0);
3302} 3251}
3303 3252
3304/** 3253/* et131x_free_busy_send_packets - Free and complete the stopped active sends
3305 * et131x_free_busy_send_packets - Free and complete the stopped active sends
3306 * @adapter: pointer to our adapter 3254 * @adapter: pointer to our adapter
3307 * 3255 *
3308 * Assumption - Send spinlock has been acquired 3256 * Assumption - Send spinlock has been acquired
@@ -3345,8 +3293,7 @@ static void et131x_free_busy_send_packets(struct et131x_adapter *adapter)
3345 adapter->tx_ring.used = 0; 3293 adapter->tx_ring.used = 0;
3346} 3294}
3347 3295
3348/** 3296/* et131x_handle_send_interrupt - Interrupt handler for sending processing
3349 * et131x_handle_send_interrupt - Interrupt handler for sending processing
3350 * @adapter: pointer to our adapter 3297 * @adapter: pointer to our adapter
3351 * 3298 *
3352 * Re-claim the send resources, complete sends and get more to send from 3299 * Re-claim the send resources, complete sends and get more to send from
@@ -3438,6 +3385,7 @@ static void et131x_get_regs(struct net_device *netdev,
3438 struct address_map __iomem *aregs = adapter->regs; 3385 struct address_map __iomem *aregs = adapter->regs;
3439 u32 *regs_buff = regs_data; 3386 u32 *regs_buff = regs_data;
3440 u32 num = 0; 3387 u32 num = 0;
3388 u16 tmp;
3441 3389
3442 memset(regs_data, 0, et131x_get_regs_len(netdev)); 3390 memset(regs_data, 0, et131x_get_regs_len(netdev));
3443 3391
@@ -3445,44 +3393,68 @@ static void et131x_get_regs(struct net_device *netdev,
3445 adapter->pdev->device; 3393 adapter->pdev->device;
3446 3394
3447 /* PHY regs */ 3395 /* PHY regs */
3448 et131x_mii_read(adapter, MII_BMCR, (u16 *)&regs_buff[num++]); 3396 et131x_mii_read(adapter, MII_BMCR, &tmp);
3449 et131x_mii_read(adapter, MII_BMSR, (u16 *)&regs_buff[num++]); 3397 regs_buff[num++] = tmp;
3450 et131x_mii_read(adapter, MII_PHYSID1, (u16 *)&regs_buff[num++]); 3398 et131x_mii_read(adapter, MII_BMSR, &tmp);
3451 et131x_mii_read(adapter, MII_PHYSID2, (u16 *)&regs_buff[num++]); 3399 regs_buff[num++] = tmp;
3452 et131x_mii_read(adapter, MII_ADVERTISE, (u16 *)&regs_buff[num++]); 3400 et131x_mii_read(adapter, MII_PHYSID1, &tmp);
3453 et131x_mii_read(adapter, MII_LPA, (u16 *)&regs_buff[num++]); 3401 regs_buff[num++] = tmp;
3454 et131x_mii_read(adapter, MII_EXPANSION, (u16 *)&regs_buff[num++]); 3402 et131x_mii_read(adapter, MII_PHYSID2, &tmp);
3403 regs_buff[num++] = tmp;
3404 et131x_mii_read(adapter, MII_ADVERTISE, &tmp);
3405 regs_buff[num++] = tmp;
3406 et131x_mii_read(adapter, MII_LPA, &tmp);
3407 regs_buff[num++] = tmp;
3408 et131x_mii_read(adapter, MII_EXPANSION, &tmp);
3409 regs_buff[num++] = tmp;
3455 /* Autoneg next page transmit reg */ 3410 /* Autoneg next page transmit reg */
3456 et131x_mii_read(adapter, 0x07, (u16 *)&regs_buff[num++]); 3411 et131x_mii_read(adapter, 0x07, &tmp);
3412 regs_buff[num++] = tmp;
3457 /* Link partner next page reg */ 3413 /* Link partner next page reg */
3458 et131x_mii_read(adapter, 0x08, (u16 *)&regs_buff[num++]); 3414 et131x_mii_read(adapter, 0x08, &tmp);
3459 et131x_mii_read(adapter, MII_CTRL1000, (u16 *)&regs_buff[num++]); 3415 regs_buff[num++] = tmp;
3460 et131x_mii_read(adapter, MII_STAT1000, (u16 *)&regs_buff[num++]); 3416 et131x_mii_read(adapter, MII_CTRL1000, &tmp);
3461 et131x_mii_read(adapter, 0x0b, (u16 *)&regs_buff[num++]); 3417 regs_buff[num++] = tmp;
3462 et131x_mii_read(adapter, 0x0c, (u16 *)&regs_buff[num++]); 3418 et131x_mii_read(adapter, MII_STAT1000, &tmp);
3463 et131x_mii_read(adapter, MII_MMD_CTRL, (u16 *)&regs_buff[num++]); 3419 regs_buff[num++] = tmp;
3464 et131x_mii_read(adapter, MII_MMD_DATA, (u16 *)&regs_buff[num++]); 3420 et131x_mii_read(adapter, 0x0b, &tmp);
3465 et131x_mii_read(adapter, MII_ESTATUS, (u16 *)&regs_buff[num++]); 3421 regs_buff[num++] = tmp;
3466 3422 et131x_mii_read(adapter, 0x0c, &tmp);
3467 et131x_mii_read(adapter, PHY_INDEX_REG, (u16 *)&regs_buff[num++]); 3423 regs_buff[num++] = tmp;
3468 et131x_mii_read(adapter, PHY_DATA_REG, (u16 *)&regs_buff[num++]); 3424 et131x_mii_read(adapter, MII_MMD_CTRL, &tmp);
3469 et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, 3425 regs_buff[num++] = tmp;
3470 (u16 *)&regs_buff[num++]); 3426 et131x_mii_read(adapter, MII_MMD_DATA, &tmp);
3471 et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL, 3427 regs_buff[num++] = tmp;
3472 (u16 *)&regs_buff[num++]); 3428 et131x_mii_read(adapter, MII_ESTATUS, &tmp);
3473 et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL+1, 3429 regs_buff[num++] = tmp;
3474 (u16 *)&regs_buff[num++]); 3430
3475 3431 et131x_mii_read(adapter, PHY_INDEX_REG, &tmp);
3476 et131x_mii_read(adapter, PHY_REGISTER_MGMT_CONTROL, 3432 regs_buff[num++] = tmp;
3477 (u16 *)&regs_buff[num++]); 3433 et131x_mii_read(adapter, PHY_DATA_REG, &tmp);
3478 et131x_mii_read(adapter, PHY_CONFIG, (u16 *)&regs_buff[num++]); 3434 regs_buff[num++] = tmp;
3479 et131x_mii_read(adapter, PHY_PHY_CONTROL, (u16 *)&regs_buff[num++]); 3435 et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, &tmp);
3480 et131x_mii_read(adapter, PHY_INTERRUPT_MASK, (u16 *)&regs_buff[num++]); 3436 regs_buff[num++] = tmp;
3481 et131x_mii_read(adapter, PHY_INTERRUPT_STATUS, 3437 et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL, &tmp);
3482 (u16 *)&regs_buff[num++]); 3438 regs_buff[num++] = tmp;
3483 et131x_mii_read(adapter, PHY_PHY_STATUS, (u16 *)&regs_buff[num++]); 3439 et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL + 1, &tmp);
3484 et131x_mii_read(adapter, PHY_LED_1, (u16 *)&regs_buff[num++]); 3440 regs_buff[num++] = tmp;
3485 et131x_mii_read(adapter, PHY_LED_2, (u16 *)&regs_buff[num++]); 3441
3442 et131x_mii_read(adapter, PHY_REGISTER_MGMT_CONTROL, &tmp);
3443 regs_buff[num++] = tmp;
3444 et131x_mii_read(adapter, PHY_CONFIG, &tmp);
3445 regs_buff[num++] = tmp;
3446 et131x_mii_read(adapter, PHY_PHY_CONTROL, &tmp);
3447 regs_buff[num++] = tmp;
3448 et131x_mii_read(adapter, PHY_INTERRUPT_MASK, &tmp);
3449 regs_buff[num++] = tmp;
3450 et131x_mii_read(adapter, PHY_INTERRUPT_STATUS, &tmp);
3451 regs_buff[num++] = tmp;
3452 et131x_mii_read(adapter, PHY_PHY_STATUS, &tmp);
3453 regs_buff[num++] = tmp;
3454 et131x_mii_read(adapter, PHY_LED_1, &tmp);
3455 regs_buff[num++] = tmp;
3456 et131x_mii_read(adapter, PHY_LED_2, &tmp);
3457 regs_buff[num++] = tmp;
3486 3458
3487 /* Global regs */ 3459 /* Global regs */
3488 regs_buff[num++] = readl(&aregs->global.txq_start_addr); 3460 regs_buff[num++] = readl(&aregs->global.txq_start_addr);
@@ -3579,8 +3551,8 @@ static struct ethtool_ops et131x_ethtool_ops = {
3579 .get_regs = et131x_get_regs, 3551 .get_regs = et131x_get_regs,
3580 .get_link = ethtool_op_get_link, 3552 .get_link = ethtool_op_get_link,
3581}; 3553};
3582/** 3554
3583 * et131x_hwaddr_init - set up the MAC Address on the ET1310 3555/* et131x_hwaddr_init - set up the MAC Address on the ET1310
3584 * @adapter: pointer to our private adapter structure 3556 * @adapter: pointer to our private adapter structure
3585 */ 3557 */
3586static void et131x_hwaddr_init(struct et131x_adapter *adapter) 3558static void et131x_hwaddr_init(struct et131x_adapter *adapter)
@@ -3590,14 +3562,12 @@ static void et131x_hwaddr_init(struct et131x_adapter *adapter)
3590 * device 3562 * device
3591 */ 3563 */
3592 if (is_zero_ether_addr(adapter->rom_addr)) { 3564 if (is_zero_ether_addr(adapter->rom_addr)) {
3593 /* 3565 /* We need to randomly generate the last octet so we
3594 * We need to randomly generate the last octet so we
3595 * decrease our chances of setting the mac address to 3566 * decrease our chances of setting the mac address to
3596 * same as another one of our cards in the system 3567 * same as another one of our cards in the system
3597 */ 3568 */
3598 get_random_bytes(&adapter->addr[5], 1); 3569 get_random_bytes(&adapter->addr[5], 1);
3599 /* 3570 /* We have the default value in the register we are
3600 * We have the default value in the register we are
3601 * working with so we need to copy the current 3571 * working with so we need to copy the current
3602 * address into the permanent address 3572 * address into the permanent address
3603 */ 3573 */
@@ -3613,8 +3583,7 @@ static void et131x_hwaddr_init(struct et131x_adapter *adapter)
3613 } 3583 }
3614} 3584}
3615 3585
3616/** 3586/* et131x_pci_init - initial PCI setup
3617 * et131x_pci_init - initial PCI setup
3618 * @adapter: pointer to our private adapter structure 3587 * @adapter: pointer to our private adapter structure
3619 * @pdev: our PCI device 3588 * @pdev: our PCI device
3620 * 3589 *
@@ -3706,8 +3675,7 @@ err_out:
3706 goto out; 3675 goto out;
3707} 3676}
3708 3677
3709/** 3678/* et131x_error_timer_handler
3710 * et131x_error_timer_handler
3711 * @data: timer-specific variable; here a pointer to our adapter structure 3679 * @data: timer-specific variable; here a pointer to our adapter structure
3712 * 3680 *
3713 * The routine called when the error timer expires, to track the number of 3681 * The routine called when the error timer expires, to track the number of
@@ -3721,7 +3689,8 @@ static void et131x_error_timer_handler(unsigned long data)
3721 if (et1310_in_phy_coma(adapter)) { 3689 if (et1310_in_phy_coma(adapter)) {
3722 /* Bring the device immediately out of coma, to 3690 /* Bring the device immediately out of coma, to
3723 * prevent it from sleeping indefinitely, this 3691 * prevent it from sleeping indefinitely, this
3724 * mechanism could be improved! */ 3692 * mechanism could be improved!
3693 */
3725 et1310_disable_phy_coma(adapter); 3694 et1310_disable_phy_coma(adapter);
3726 adapter->boot_coma = 20; 3695 adapter->boot_coma = 20;
3727 } else { 3696 } else {
@@ -3747,8 +3716,7 @@ static void et131x_error_timer_handler(unsigned long data)
3747 mod_timer(&adapter->error_timer, jiffies + TX_ERROR_PERIOD * HZ / 1000); 3716 mod_timer(&adapter->error_timer, jiffies + TX_ERROR_PERIOD * HZ / 1000);
3748} 3717}
3749 3718
3750/** 3719/* et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx
3751 * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx
3752 * @adapter: pointer to our private adapter structure 3720 * @adapter: pointer to our private adapter structure
3753 */ 3721 */
3754static void et131x_adapter_memory_free(struct et131x_adapter *adapter) 3722static void et131x_adapter_memory_free(struct et131x_adapter *adapter)
@@ -3758,8 +3726,7 @@ static void et131x_adapter_memory_free(struct et131x_adapter *adapter)
3758 et131x_rx_dma_memory_free(adapter); 3726 et131x_rx_dma_memory_free(adapter);
3759} 3727}
3760 3728
3761/** 3729/* et131x_adapter_memory_alloc
3762 * et131x_adapter_memory_alloc
3763 * @adapter: pointer to our private adapter structure 3730 * @adapter: pointer to our private adapter structure
3764 * 3731 *
3765 * Returns 0 on success, errno on failure (as defined in errno.h). 3732 * Returns 0 on success, errno on failure (as defined in errno.h).
@@ -3801,60 +3768,54 @@ static void et131x_adjust_link(struct net_device *netdev)
3801 struct et131x_adapter *adapter = netdev_priv(netdev); 3768 struct et131x_adapter *adapter = netdev_priv(netdev);
3802 struct phy_device *phydev = adapter->phydev; 3769 struct phy_device *phydev = adapter->phydev;
3803 3770
3804 if (netif_carrier_ok(netdev)) {
3805 adapter->boot_coma = 20;
3806
3807 if (phydev && phydev->speed == SPEED_10) {
3808 /*
3809 * NOTE - Is there a way to query this without
3810 * TruePHY?
3811 * && TRU_QueryCoreType(adapter->hTruePhy, 0)==
3812 * EMI_TRUEPHY_A13O) {
3813 */
3814 u16 register18;
3815
3816 et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG,
3817 &register18);
3818 et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG,
3819 register18 | 0x4);
3820 et131x_mii_write(adapter, PHY_INDEX_REG,
3821 register18 | 0x8402);
3822 et131x_mii_write(adapter, PHY_DATA_REG,
3823 register18 | 511);
3824 et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG,
3825 register18);
3826 }
3827
3828 et1310_config_flow_control(adapter);
3829
3830 if (phydev && phydev->speed == SPEED_1000 &&
3831 adapter->registry_jumbo_packet > 2048) {
3832 u16 reg;
3833
3834 et131x_mii_read(adapter, PHY_CONFIG, &reg);
3835 reg &= ~ET_PHY_CONFIG_TX_FIFO_DEPTH;
3836 reg |= ET_PHY_CONFIG_FIFO_DEPTH_32;
3837 et131x_mii_write(adapter, PHY_CONFIG, reg);
3838 }
3839
3840 et131x_set_rx_dma_timer(adapter);
3841 et1310_config_mac_regs2(adapter);
3842 }
3843
3844 if (phydev && phydev->link != adapter->link) { 3771 if (phydev && phydev->link != adapter->link) {
3845 /* 3772 /* Check to see if we are in coma mode and if
3846 * Check to see if we are in coma mode and if
3847 * so, disable it because we will not be able 3773 * so, disable it because we will not be able
3848 * to read PHY values until we are out. 3774 * to read PHY values until we are out.
3849 */ 3775 */
3850 if (et1310_in_phy_coma(adapter)) 3776 if (et1310_in_phy_coma(adapter))
3851 et1310_disable_phy_coma(adapter); 3777 et1310_disable_phy_coma(adapter);
3852 3778
3779 adapter->link = phydev->link;
3780 phy_print_status(phydev);
3781
3853 if (phydev->link) { 3782 if (phydev->link) {
3854 adapter->boot_coma = 20; 3783 adapter->boot_coma = 20;
3784 if (phydev && phydev->speed == SPEED_10) {
3785 /* NOTE - Is there a way to query this without
3786 * TruePHY?
3787 * && TRU_QueryCoreType(adapter->hTruePhy, 0)==
3788 * EMI_TRUEPHY_A13O) {
3789 */
3790 u16 register18;
3791
3792 et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG,
3793 &register18);
3794 et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG,
3795 register18 | 0x4);
3796 et131x_mii_write(adapter, PHY_INDEX_REG,
3797 register18 | 0x8402);
3798 et131x_mii_write(adapter, PHY_DATA_REG,
3799 register18 | 511);
3800 et131x_mii_write(adapter, PHY_MPHY_CONTROL_REG,
3801 register18);
3802 }
3803
3804 et1310_config_flow_control(adapter);
3805
3806 if (phydev && phydev->speed == SPEED_1000 &&
3807 adapter->registry_jumbo_packet > 2048) {
3808 u16 reg;
3809
3810 et131x_mii_read(adapter, PHY_CONFIG, &reg);
3811 reg &= ~ET_PHY_CONFIG_TX_FIFO_DEPTH;
3812 reg |= ET_PHY_CONFIG_FIFO_DEPTH_32;
3813 et131x_mii_write(adapter, PHY_CONFIG, reg);
3814 }
3815
3816 et131x_set_rx_dma_timer(adapter);
3817 et1310_config_mac_regs2(adapter);
3855 } else { 3818 } else {
3856 dev_warn(&adapter->pdev->dev,
3857 "Link down - cable problem ?\n");
3858 adapter->boot_coma = 0; 3819 adapter->boot_coma = 0;
3859 3820
3860 if (phydev->speed == SPEED_10) { 3821 if (phydev->speed == SPEED_10) {
@@ -3883,8 +3844,7 @@ static void et131x_adjust_link(struct net_device *netdev)
3883 /* Re-initialize the send structures */ 3844 /* Re-initialize the send structures */
3884 et131x_init_send(adapter); 3845 et131x_init_send(adapter);
3885 3846
3886 /* 3847 /* Bring the device back to the state it was during
3887 * Bring the device back to the state it was during
3888 * init prior to autonegotiation being complete. This 3848 * init prior to autonegotiation being complete. This
3889 * way, when we get the auto-neg complete interrupt, 3849 * way, when we get the auto-neg complete interrupt,
3890 * we can complete init by calling config_mac_regs2. 3850 * we can complete init by calling config_mac_regs2.
@@ -3899,9 +3859,6 @@ static void et131x_adjust_link(struct net_device *netdev)
3899 et131x_enable_txrx(netdev); 3859 et131x_enable_txrx(netdev);
3900 } 3860 }
3901 3861
3902 adapter->link = phydev->link;
3903
3904 phy_print_status(phydev);
3905 } 3862 }
3906} 3863}
3907 3864
@@ -3944,8 +3901,7 @@ static int et131x_mii_probe(struct net_device *netdev)
3944 return 0; 3901 return 0;
3945} 3902}
3946 3903
3947/** 3904/* et131x_adapter_init
3948 * et131x_adapter_init
3949 * @adapter: pointer to the private adapter struct 3905 * @adapter: pointer to the private adapter struct
3950 * @pdev: pointer to the PCI device 3906 * @pdev: pointer to the PCI device
3951 * 3907 *
@@ -3982,8 +3938,7 @@ static struct et131x_adapter *et131x_adapter_init(struct net_device *netdev,
3982 return adapter; 3938 return adapter;
3983} 3939}
3984 3940
3985/** 3941/* et131x_pci_remove
3986 * et131x_pci_remove
3987 * @pdev: a pointer to the device's pci_dev structure 3942 * @pdev: a pointer to the device's pci_dev structure
3988 * 3943 *
3989 * Registered in the pci_driver structure, this function is called when the 3944 * Registered in the pci_driver structure, this function is called when the
@@ -4010,8 +3965,7 @@ static void et131x_pci_remove(struct pci_dev *pdev)
4010 pci_disable_device(pdev); 3965 pci_disable_device(pdev);
4011} 3966}
4012 3967
4013/** 3968/* et131x_up - Bring up a device for use.
4014 * et131x_up - Bring up a device for use.
4015 * @netdev: device to be opened 3969 * @netdev: device to be opened
4016 */ 3970 */
4017static void et131x_up(struct net_device *netdev) 3971static void et131x_up(struct net_device *netdev)
@@ -4022,8 +3976,7 @@ static void et131x_up(struct net_device *netdev)
4022 phy_start(adapter->phydev); 3976 phy_start(adapter->phydev);
4023} 3977}
4024 3978
4025/** 3979/* et131x_down - Bring down the device
4026 * et131x_down - Bring down the device
4027 * @netdev: device to be brought down 3980 * @netdev: device to be brought down
4028 */ 3981 */
4029static void et131x_down(struct net_device *netdev) 3982static void et131x_down(struct net_device *netdev)
@@ -4072,14 +4025,13 @@ static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume);
4072#define ET131X_PM_OPS NULL 4025#define ET131X_PM_OPS NULL
4073#endif 4026#endif
4074 4027
4075/** 4028/* et131x_isr - The Interrupt Service Routine for the driver.
4076 * et131x_isr - The Interrupt Service Routine for the driver.
4077 * @irq: the IRQ on which the interrupt was received. 4029 * @irq: the IRQ on which the interrupt was received.
4078 * @dev_id: device-specific info (here a pointer to a net_device struct) 4030 * @dev_id: device-specific info (here a pointer to a net_device struct)
4079 * 4031 *
4080 * Returns a value indicating if the interrupt was handled. 4032 * Returns a value indicating if the interrupt was handled.
4081 */ 4033 */
4082irqreturn_t et131x_isr(int irq, void *dev_id) 4034static irqreturn_t et131x_isr(int irq, void *dev_id)
4083{ 4035{
4084 bool handled = true; 4036 bool handled = true;
4085 struct net_device *netdev = (struct net_device *)dev_id; 4037 struct net_device *netdev = (struct net_device *)dev_id;
@@ -4161,8 +4113,7 @@ out:
4161 return IRQ_RETVAL(handled); 4113 return IRQ_RETVAL(handled);
4162} 4114}
4163 4115
4164/** 4116/* et131x_isr_handler - The ISR handler
4165 * et131x_isr_handler - The ISR handler
4166 * @p_adapter, a pointer to the device's private adapter structure 4117 * @p_adapter, a pointer to the device's private adapter structure
4167 * 4118 *
4168 * scheduled to run in a deferred context by the ISR. This is where the ISR's 4119 * scheduled to run in a deferred context by the ISR. This is where the ISR's
@@ -4175,8 +4126,7 @@ static void et131x_isr_handler(struct work_struct *work)
4175 u32 status = adapter->stats.interrupt_status; 4126 u32 status = adapter->stats.interrupt_status;
4176 struct address_map __iomem *iomem = adapter->regs; 4127 struct address_map __iomem *iomem = adapter->regs;
4177 4128
4178 /* 4129 /* These first two are by far the most common. Once handled, we clear
4179 * These first two are by far the most common. Once handled, we clear
4180 * their two bits in the status word. If the word is now zero, we 4130 * their two bits in the status word. If the word is now zero, we
4181 * exit. 4131 * exit.
4182 */ 4132 */
@@ -4207,8 +4157,7 @@ static void et131x_isr_handler(struct work_struct *work)
4207 4157
4208 /* Handle Free Buffer Ring 0 and 1 Low interrupt */ 4158 /* Handle Free Buffer Ring 0 and 1 Low interrupt */
4209 if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) { 4159 if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) {
4210 /* 4160 /* This indicates the number of unused buffers in RXDMA free
4211 * This indicates the number of unused buffers in RXDMA free
4212 * buffer ring 0 is <= the limit you programmed. Free buffer 4161 * buffer ring 0 is <= the limit you programmed. Free buffer
4213 * resources need to be returned. Free buffers are consumed as 4162 * resources need to be returned. Free buffers are consumed as
4214 * packets are passed from the network to the host. The host 4163 * packets are passed from the network to the host. The host
@@ -4220,16 +4169,14 @@ static void et131x_isr_handler(struct work_struct *work)
4220 * method of returning resources. 4169 * method of returning resources.
4221 */ 4170 */
4222 4171
4223 /* 4172 /* If the user has flow control on, then we will
4224 * If the user has flow control on, then we will
4225 * send a pause packet, otherwise just exit 4173 * send a pause packet, otherwise just exit
4226 */ 4174 */
4227 if (adapter->flowcontrol == FLOW_TXONLY || 4175 if (adapter->flowcontrol == FLOW_TXONLY ||
4228 adapter->flowcontrol == FLOW_BOTH) { 4176 adapter->flowcontrol == FLOW_BOTH) {
4229 u32 pm_csr; 4177 u32 pm_csr;
4230 4178
4231 /* 4179 /* Tell the device to send a pause packet via the back
4232 * Tell the device to send a pause packet via the back
4233 * pressure register (bp req and bp xon/xoff) 4180 * pressure register (bp req and bp xon/xoff)
4234 */ 4181 */
4235 pm_csr = readl(&iomem->global.pm_csr); 4182 pm_csr = readl(&iomem->global.pm_csr);
@@ -4240,8 +4187,7 @@ static void et131x_isr_handler(struct work_struct *work)
4240 4187
4241 /* Handle Packet Status Ring Low Interrupt */ 4188 /* Handle Packet Status Ring Low Interrupt */
4242 if (status & ET_INTR_RXDMA_STAT_LOW) { 4189 if (status & ET_INTR_RXDMA_STAT_LOW) {
4243 /* 4190 /* Same idea as with the two Free Buffer Rings. Packets going
4244 * Same idea as with the two Free Buffer Rings. Packets going
4245 * from the network to the host each consume a free buffer 4191 * from the network to the host each consume a free buffer
4246 * resource and a packet status resource. These resoures are 4192 * resource and a packet status resource. These resoures are
4247 * passed to the OS. When the OS is done with the resources, 4193 * passed to the OS. When the OS is done with the resources,
@@ -4252,8 +4198,7 @@ static void et131x_isr_handler(struct work_struct *work)
4252 4198
4253 /* Handle RXDMA Error Interrupt */ 4199 /* Handle RXDMA Error Interrupt */
4254 if (status & ET_INTR_RXDMA_ERR) { 4200 if (status & ET_INTR_RXDMA_ERR) {
4255 /* 4201 /* The rxdma_error interrupt is sent when a time-out on a
4256 * The rxdma_error interrupt is sent when a time-out on a
4257 * request issued by the JAGCore has occurred or a completion is 4202 * request issued by the JAGCore has occurred or a completion is
4258 * returned with an un-successful status. In both cases the 4203 * returned with an un-successful status. In both cases the
4259 * request is considered complete. The JAGCore will 4204 * request is considered complete. The JAGCore will
@@ -4276,8 +4221,7 @@ static void et131x_isr_handler(struct work_struct *work)
4276 4221
4277 /* Handle the Wake on LAN Event */ 4222 /* Handle the Wake on LAN Event */
4278 if (status & ET_INTR_WOL) { 4223 if (status & ET_INTR_WOL) {
4279 /* 4224 /* This is a secondary interrupt for wake on LAN. The driver
4280 * This is a secondary interrupt for wake on LAN. The driver
4281 * should never see this, if it does, something serious is 4225 * should never see this, if it does, something serious is
4282 * wrong. We will TRAP the message when we are in DBG mode, 4226 * wrong. We will TRAP the message when we are in DBG mode,
4283 * otherwise we will ignore it. 4227 * otherwise we will ignore it.
@@ -4289,8 +4233,7 @@ static void et131x_isr_handler(struct work_struct *work)
4289 if (status & ET_INTR_TXMAC) { 4233 if (status & ET_INTR_TXMAC) {
4290 u32 err = readl(&iomem->txmac.err); 4234 u32 err = readl(&iomem->txmac.err);
4291 4235
4292 /* 4236 /* When any of the errors occur and TXMAC generates an
4293 * When any of the errors occur and TXMAC generates an
4294 * interrupt to report these errors, it usually means that 4237 * interrupt to report these errors, it usually means that
4295 * TXMAC has detected an error in the data stream retrieved 4238 * TXMAC has detected an error in the data stream retrieved
4296 * from the on-chip Tx Q. All of these errors are catastrophic 4239 * from the on-chip Tx Q. All of these errors are catastrophic
@@ -4302,20 +4245,18 @@ static void et131x_isr_handler(struct work_struct *work)
4302 "TXMAC interrupt, error 0x%08x\n", 4245 "TXMAC interrupt, error 0x%08x\n",
4303 err); 4246 err);
4304 4247
4305 /* 4248 /* If we are debugging, we want to see this error, otherwise we
4306 * If we are debugging, we want to see this error, otherwise we
4307 * just want the device to be reset and continue 4249 * just want the device to be reset and continue
4308 */ 4250 */
4309 } 4251 }
4310 4252
4311 /* Handle RXMAC Interrupt */ 4253 /* Handle RXMAC Interrupt */
4312 if (status & ET_INTR_RXMAC) { 4254 if (status & ET_INTR_RXMAC) {
4313 /* 4255 /* These interrupts are catastrophic to the device, what we need
4314 * These interrupts are catastrophic to the device, what we need
4315 * to do is disable the interrupts and set the flag to cause us 4256 * to do is disable the interrupts and set the flag to cause us
4316 * to reset so we can solve this issue. 4257 * to reset so we can solve this issue.
4317 */ 4258 */
4318 /* MP_SET_FLAG( adapter, fMP_ADAPTER_HARDWARE_ERROR); */ 4259 /* MP_SET_FLAG( adapter, FMP_ADAPTER_HARDWARE_ERROR); */
4319 4260
4320 dev_warn(&adapter->pdev->dev, 4261 dev_warn(&adapter->pdev->dev,
4321 "RXMAC interrupt, error 0x%08x. Requesting reset\n", 4262 "RXMAC interrupt, error 0x%08x. Requesting reset\n",
@@ -4326,16 +4267,14 @@ static void et131x_isr_handler(struct work_struct *work)
4326 readl(&iomem->rxmac.ctrl), 4267 readl(&iomem->rxmac.ctrl),
4327 readl(&iomem->rxmac.rxq_diag)); 4268 readl(&iomem->rxmac.rxq_diag));
4328 4269
4329 /* 4270 /* If we are debugging, we want to see this error, otherwise we
4330 * If we are debugging, we want to see this error, otherwise we
4331 * just want the device to be reset and continue 4271 * just want the device to be reset and continue
4332 */ 4272 */
4333 } 4273 }
4334 4274
4335 /* Handle MAC_STAT Interrupt */ 4275 /* Handle MAC_STAT Interrupt */
4336 if (status & ET_INTR_MAC_STAT) { 4276 if (status & ET_INTR_MAC_STAT) {
4337 /* 4277 /* This means at least one of the un-masked counters in the
4338 * This means at least one of the un-masked counters in the
4339 * MAC_STAT block has rolled over. Use this to maintain the top, 4278 * MAC_STAT block has rolled over. Use this to maintain the top,
4340 * software managed bits of the counter(s). 4279 * software managed bits of the counter(s).
4341 */ 4280 */
@@ -4344,8 +4283,7 @@ static void et131x_isr_handler(struct work_struct *work)
4344 4283
4345 /* Handle SLV Timeout Interrupt */ 4284 /* Handle SLV Timeout Interrupt */
4346 if (status & ET_INTR_SLV_TIMEOUT) { 4285 if (status & ET_INTR_SLV_TIMEOUT) {
4347 /* 4286 /* This means a timeout has occurred on a read or write request
4348 * This means a timeout has occurred on a read or write request
4349 * to one of the JAGCore registers. The Global Resources block 4287 * to one of the JAGCore registers. The Global Resources block
4350 * has terminated the request and on a read request, returned a 4288 * has terminated the request and on a read request, returned a
4351 * "fake" value. The most likely reasons are: Bad Address or the 4289 * "fake" value. The most likely reasons are: Bad Address or the
@@ -4356,8 +4294,7 @@ out:
4356 et131x_enable_interrupts(adapter); 4294 et131x_enable_interrupts(adapter);
4357} 4295}
4358 4296
4359/** 4297/* et131x_stats - Return the current device statistics.
4360 * et131x_stats - Return the current device statistics.
4361 * @netdev: device whose stats are being queried 4298 * @netdev: device whose stats are being queried
4362 * 4299 *
4363 * Returns 0 on success, errno on failure (as defined in errno.h) 4300 * Returns 0 on success, errno on failure (as defined in errno.h)
@@ -4403,8 +4340,7 @@ static struct net_device_stats *et131x_stats(struct net_device *netdev)
4403 return stats; 4340 return stats;
4404} 4341}
4405 4342
4406/** 4343/* et131x_open - Open the device for use.
4407 * et131x_open - Open the device for use.
4408 * @netdev: device to be opened 4344 * @netdev: device to be opened
4409 * 4345 *
4410 * Returns 0 on success, errno on failure (as defined in errno.h) 4346 * Returns 0 on success, errno on failure (as defined in errno.h)
@@ -4430,15 +4366,14 @@ static int et131x_open(struct net_device *netdev)
4430 return result; 4366 return result;
4431 } 4367 }
4432 4368
4433 adapter->flags |= fMP_ADAPTER_INTERRUPT_IN_USE; 4369 adapter->flags |= FMP_ADAPTER_INTERRUPT_IN_USE;
4434 4370
4435 et131x_up(netdev); 4371 et131x_up(netdev);
4436 4372
4437 return result; 4373 return result;
4438} 4374}
4439 4375
4440/** 4376/* et131x_close - Close the device
4441 * et131x_close - Close the device
4442 * @netdev: device to be closed 4377 * @netdev: device to be closed
4443 * 4378 *
4444 * Returns 0 on success, errno on failure (as defined in errno.h) 4379 * Returns 0 on success, errno on failure (as defined in errno.h)
@@ -4449,15 +4384,14 @@ static int et131x_close(struct net_device *netdev)
4449 4384
4450 et131x_down(netdev); 4385 et131x_down(netdev);
4451 4386
4452 adapter->flags &= ~fMP_ADAPTER_INTERRUPT_IN_USE; 4387 adapter->flags &= ~FMP_ADAPTER_INTERRUPT_IN_USE;
4453 free_irq(adapter->pdev->irq, netdev); 4388 free_irq(adapter->pdev->irq, netdev);
4454 4389
4455 /* Stop the error timer */ 4390 /* Stop the error timer */
4456 return del_timer_sync(&adapter->error_timer); 4391 return del_timer_sync(&adapter->error_timer);
4457} 4392}
4458 4393
4459/** 4394/* et131x_ioctl - The I/O Control handler for the driver
4460 * et131x_ioctl - The I/O Control handler for the driver
4461 * @netdev: device on which the control request is being made 4395 * @netdev: device on which the control request is being made
4462 * @reqbuf: a pointer to the IOCTL request buffer 4396 * @reqbuf: a pointer to the IOCTL request buffer
4463 * @cmd: the IOCTL command code 4397 * @cmd: the IOCTL command code
@@ -4475,8 +4409,7 @@ static int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf,
4475 return phy_mii_ioctl(adapter->phydev, reqbuf, cmd); 4409 return phy_mii_ioctl(adapter->phydev, reqbuf, cmd);
4476} 4410}
4477 4411
4478/** 4412/* et131x_set_packet_filter - Configures the Rx Packet filtering on the device
4479 * et131x_set_packet_filter - Configures the Rx Packet filtering on the device
4480 * @adapter: pointer to our private adapter structure 4413 * @adapter: pointer to our private adapter structure
4481 * 4414 *
4482 * FIXME: lot of dups with MAC code 4415 * FIXME: lot of dups with MAC code
@@ -4504,8 +4437,7 @@ static int et131x_set_packet_filter(struct et131x_adapter *adapter)
4504 if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) 4437 if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0)
4505 pf_ctrl &= ~7; /* Clear filter bits */ 4438 pf_ctrl &= ~7; /* Clear filter bits */
4506 else { 4439 else {
4507 /* 4440 /* Set us up with Multicast packet filtering. Three cases are
4508 * Set us up with Multicast packet filtering. Three cases are
4509 * possible - (1) we have a multi-cast list, (2) we receive ALL 4441 * possible - (1) we have a multi-cast list, (2) we receive ALL
4510 * multicast entries or (3) we receive none. 4442 * multicast entries or (3) we receive none.
4511 */ 4443 */
@@ -4541,8 +4473,7 @@ static int et131x_set_packet_filter(struct et131x_adapter *adapter)
4541 return status; 4473 return status;
4542} 4474}
4543 4475
4544/** 4476/* et131x_multicast - The handler to configure multicasting on the interface
4545 * et131x_multicast - The handler to configure multicasting on the interface
4546 * @netdev: a pointer to a net_device struct representing the device 4477 * @netdev: a pointer to a net_device struct representing the device
4547 */ 4478 */
4548static void et131x_multicast(struct net_device *netdev) 4479static void et131x_multicast(struct net_device *netdev)
@@ -4611,8 +4542,7 @@ static void et131x_multicast(struct net_device *netdev)
4611 spin_unlock_irqrestore(&adapter->lock, flags); 4542 spin_unlock_irqrestore(&adapter->lock, flags);
4612} 4543}
4613 4544
4614/** 4545/* et131x_tx - The handler to tx a packet on the device
4615 * et131x_tx - The handler to tx a packet on the device
4616 * @skb: data to be Tx'd 4546 * @skb: data to be Tx'd
4617 * @netdev: device on which data is to be Tx'd 4547 * @netdev: device on which data is to be Tx'd
4618 * 4548 *
@@ -4644,8 +4574,7 @@ static int et131x_tx(struct sk_buff *skb, struct net_device *netdev)
4644 return status; 4574 return status;
4645} 4575}
4646 4576
4647/** 4577/* et131x_tx_timeout - Timeout handler
4648 * et131x_tx_timeout - Timeout handler
4649 * @netdev: a pointer to a net_device struct representing the device 4578 * @netdev: a pointer to a net_device struct representing the device
4650 * 4579 *
4651 * The handler called when a Tx request times out. The timeout period is 4580 * The handler called when a Tx request times out. The timeout period is
@@ -4659,17 +4588,17 @@ static void et131x_tx_timeout(struct net_device *netdev)
4659 unsigned long flags; 4588 unsigned long flags;
4660 4589
4661 /* If the device is closed, ignore the timeout */ 4590 /* If the device is closed, ignore the timeout */
4662 if (~(adapter->flags & fMP_ADAPTER_INTERRUPT_IN_USE)) 4591 if (~(adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE))
4663 return; 4592 return;
4664 4593
4665 /* Any nonrecoverable hardware error? 4594 /* Any nonrecoverable hardware error?
4666 * Checks adapter->flags for any failure in phy reading 4595 * Checks adapter->flags for any failure in phy reading
4667 */ 4596 */
4668 if (adapter->flags & fMP_ADAPTER_NON_RECOVER_ERROR) 4597 if (adapter->flags & FMP_ADAPTER_NON_RECOVER_ERROR)
4669 return; 4598 return;
4670 4599
4671 /* Hardware failure? */ 4600 /* Hardware failure? */
4672 if (adapter->flags & fMP_ADAPTER_HARDWARE_ERROR) { 4601 if (adapter->flags & FMP_ADAPTER_HARDWARE_ERROR) {
4673 dev_err(&adapter->pdev->dev, "hardware error - reset\n"); 4602 dev_err(&adapter->pdev->dev, "hardware error - reset\n");
4674 return; 4603 return;
4675 } 4604 }
@@ -4703,8 +4632,7 @@ static void et131x_tx_timeout(struct net_device *netdev)
4703 spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 4632 spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags);
4704} 4633}
4705 4634
4706/** 4635/* et131x_change_mtu - The handler called to change the MTU for the device
4707 * et131x_change_mtu - The handler called to change the MTU for the device
4708 * @netdev: device whose MTU is to be changed 4636 * @netdev: device whose MTU is to be changed
4709 * @new_mtu: the desired MTU 4637 * @new_mtu: the desired MTU
4710 * 4638 *
@@ -4754,8 +4682,7 @@ static int et131x_change_mtu(struct net_device *netdev, int new_mtu)
4754 return result; 4682 return result;
4755} 4683}
4756 4684
4757/** 4685/* et131x_set_mac_addr - handler to change the MAC address for the device
4758 * et131x_set_mac_addr - handler to change the MAC address for the device
4759 * @netdev: device whose MAC is to be changed 4686 * @netdev: device whose MAC is to be changed
4760 * @new_mac: the desired MAC address 4687 * @new_mac: the desired MAC address
4761 * 4688 *
@@ -4828,8 +4755,7 @@ static const struct net_device_ops et131x_netdev_ops = {
4828 .ndo_do_ioctl = et131x_ioctl, 4755 .ndo_do_ioctl = et131x_ioctl,
4829}; 4756};
4830 4757
4831/** 4758/* et131x_pci_setup - Perform device initialization
4832 * et131x_pci_setup - Perform device initialization
4833 * @pdev: a pointer to the device's pci_dev structure 4759 * @pdev: a pointer to the device's pci_dev structure
4834 * @ent: this device's entry in the pci_device_id table 4760 * @ent: this device's entry in the pci_device_id table
4835 * 4761 *
@@ -4963,11 +4889,10 @@ static int et131x_pci_setup(struct pci_dev *pdev,
4963 adapter->mii_bus->read = et131x_mdio_read; 4889 adapter->mii_bus->read = et131x_mdio_read;
4964 adapter->mii_bus->write = et131x_mdio_write; 4890 adapter->mii_bus->write = et131x_mdio_write;
4965 adapter->mii_bus->reset = et131x_mdio_reset; 4891 adapter->mii_bus->reset = et131x_mdio_reset;
4966 adapter->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 4892 adapter->mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int),
4967 if (!adapter->mii_bus->irq) { 4893 GFP_KERNEL);
4968 dev_err(&pdev->dev, "mii_bus irq allocation failed\n"); 4894 if (!adapter->mii_bus->irq)
4969 goto err_mdio_free; 4895 goto err_mdio_free;
4970 }
4971 4896
4972 for (ii = 0; ii < PHY_MAX_ADDR; ii++) 4897 for (ii = 0; ii < PHY_MAX_ADDR; ii++)
4973 adapter->mii_bus->irq[ii] = PHY_POLL; 4898 adapter->mii_bus->irq[ii] = PHY_POLL;
diff --git a/drivers/staging/et131x/et131x.h b/drivers/staging/et131x/et131x.h
index 347e63ddde1f..bbe78a703a23 100644
--- a/drivers/staging/et131x/et131x.h
+++ b/drivers/staging/et131x/et131x.h
@@ -145,6 +145,8 @@
145 *31: selfclr_disable 145 *31: selfclr_disable
146 */ 146 */
147 147
148#define ET_RESET_ALL 0x007F;
149
148/* 150/*
149 * SLV Timer reg at address 0x002C (low 24 bits) 151 * SLV Timer reg at address 0x002C (low 24 bits)
150 */ 152 */
@@ -317,6 +319,14 @@ struct txdma_regs { /* Location: */
317 * 18-31: unused 319 * 18-31: unused
318 */ 320 */
319 321
322#define ET_RXDMA_CSR_HALT 0x0001
323#define ET_RXDMA_CSR_FBR0_SIZE_LO 0x0100
324#define ET_RXDMA_CSR_FBR0_SIZE_HI 0x0200
325#define ET_RXDMA_CSR_FBR0_ENABLE 0x0400
326#define ET_RXDMA_CSR_FBR1_SIZE_LO 0x0800
327#define ET_RXDMA_CSR_FBR1_SIZE_HI 0x1000
328#define ET_RXDMA_CSR_FBR1_ENABLE 0x2000
329#define ET_RXDMA_CSR_HALT_STATUS 0x00020000
320 330
321/* 331/*
322 * structure for dma writeback lo reg in rxdma address map 332 * structure for dma writeback lo reg in rxdma address map
@@ -384,6 +394,8 @@ struct txdma_regs { /* Location: */
384 * 11-0: psr ndes 394 * 11-0: psr ndes
385 */ 395 */
386 396
397#define ET_RXDMA_PSR_NUM_DES_MASK 0xFFF;
398
387/* 399/*
388 * structure for packet status ring available offset reg in rxdma address map 400 * structure for packet status ring available offset reg in rxdma address map
389 * located at address 0x202C 401 * located at address 0x202C
@@ -559,6 +571,9 @@ struct rxdma_regs { /* Location: */
559 * 0: txmac_en 571 * 0: txmac_en
560 */ 572 */
561 573
574#define ET_TX_CTRL_FC_DISABLE 0x0008
575#define ET_TX_CTRL_TXMAC_ENABLE 0x0001
576
562/* 577/*
563 * structure for shadow pointer reg in txmac address map 578 * structure for shadow pointer reg in txmac address map
564 * located at address 0x3004 579 * located at address 0x3004
@@ -674,6 +689,9 @@ struct txmac_regs { /* Location: */
674 * 0: rxmac_en 689 * 0: rxmac_en
675 */ 690 */
676 691
692#define ET_RX_CTRL_WOL_DISABLE 0x0008
693#define ET_RX_CTRL_RXMAC_ENABLE 0x0001
694
677/* 695/*
678 * structure for Wake On Lan Control and CRC 0 reg in rxmac address map 696 * structure for Wake On Lan Control and CRC 0 reg in rxmac address map
679 * located at address 0x4004 697 * located at address 0x4004
@@ -715,9 +733,9 @@ struct txmac_regs { /* Location: */
715 * 7-0: sa6 733 * 7-0: sa6
716 */ 734 */
717 735
718#define ET_WOL_LO_SA3_SHIFT 24 736#define ET_RX_WOL_LO_SA3_SHIFT 24
719#define ET_WOL_LO_SA4_SHIFT 16 737#define ET_RX_WOL_LO_SA4_SHIFT 16
720#define ET_WOL_LO_SA5_SHIFT 8 738#define ET_RX_WOL_LO_SA5_SHIFT 8
721 739
722/* 740/*
723 * structure for Wake On Lan Source Address Hi reg in rxmac address map 741 * structure for Wake On Lan Source Address Hi reg in rxmac address map
@@ -728,7 +746,7 @@ struct txmac_regs { /* Location: */
728 * 7-0: sa2 746 * 7-0: sa2
729 */ 747 */
730 748
731#define ET_WOL_HI_SA1_SHIFT 8 749#define ET_RX_WOL_HI_SA1_SHIFT 8
732 750
733/* 751/*
734 * structure for Wake On Lan mask reg in rxmac address map 752 * structure for Wake On Lan mask reg in rxmac address map
@@ -746,9 +764,9 @@ struct txmac_regs { /* Location: */
746 * 7-0: addr1_6 764 * 7-0: addr1_6
747 */ 765 */
748 766
749#define ET_UNI_PF_ADDR1_3_SHIFT 24 767#define ET_RX_UNI_PF_ADDR1_3_SHIFT 24
750#define ET_UNI_PF_ADDR1_4_SHIFT 16 768#define ET_RX_UNI_PF_ADDR1_4_SHIFT 16
751#define ET_UNI_PF_ADDR1_5_SHIFT 8 769#define ET_RX_UNI_PF_ADDR1_5_SHIFT 8
752 770
753/* 771/*
754 * structure for Unicast Paket Filter Address 2 reg in rxmac address map 772 * structure for Unicast Paket Filter Address 2 reg in rxmac address map
@@ -760,9 +778,9 @@ struct txmac_regs { /* Location: */
760 * 7-0: addr2_6 778 * 7-0: addr2_6
761 */ 779 */
762 780
763#define ET_UNI_PF_ADDR2_3_SHIFT 24 781#define ET_RX_UNI_PF_ADDR2_3_SHIFT 24
764#define ET_UNI_PF_ADDR2_4_SHIFT 16 782#define ET_RX_UNI_PF_ADDR2_4_SHIFT 16
765#define ET_UNI_PF_ADDR2_5_SHIFT 8 783#define ET_RX_UNI_PF_ADDR2_5_SHIFT 8
766 784
767/* 785/*
768 * structure for Unicast Paket Filter Address 1 & 2 reg in rxmac address map 786 * structure for Unicast Paket Filter Address 1 & 2 reg in rxmac address map
@@ -774,10 +792,9 @@ struct txmac_regs { /* Location: */
774 * 7-0: addr1_2 792 * 7-0: addr1_2
775 */ 793 */
776 794
777#define ET_UNI_PF_ADDR2_1_SHIFT 24 795#define ET_RX_UNI_PF_ADDR2_1_SHIFT 24
778#define ET_UNI_PF_ADDR2_2_SHIFT 16 796#define ET_RX_UNI_PF_ADDR2_2_SHIFT 16
779#define ET_UNI_PF_ADDR1_1_SHIFT 8 797#define ET_RX_UNI_PF_ADDR1_1_SHIFT 8
780
781 798
782/* 799/*
783 * structure for Multicast Hash reg in rxmac address map 800 * structure for Multicast Hash reg in rxmac address map
@@ -798,6 +815,12 @@ struct txmac_regs { /* Location: */
798 * 0: filter_broad_en 815 * 0: filter_broad_en
799 */ 816 */
800 817
818#define ET_RX_PFCTRL_MIN_PKT_SZ_SHIFT 16;
819#define ET_RX_PFCTRL_FRAG_FILTER_ENABLE 0x0008;
820#define ET_RX_PFCTRL_UNICST_FILTER_ENABLE 0x0004;
821#define ET_RX_PFCTRL_MLTCST_FILTER_ENABLE 0x0002;
822#define ET_RX_PFCTRL_BRDCST_FILTER_ENABLE 0x0001;
823
801/* 824/*
802 * structure for Memory Controller Interface Control Max Segment reg in rxmac 825 * structure for Memory Controller Interface Control Max Segment reg in rxmac
803 * address map. Located at address 0x4088 826 * address map. Located at address 0x4088
@@ -808,6 +831,10 @@ struct txmac_regs { /* Location: */
808 * 0: seg_en 831 * 0: seg_en
809 */ 832 */
810 833
834#define ET_RX_MCIF_CTRL_MAX_SEG_SIZE_SHIFT 2;
835#define ET_RX_MCIF_CTRL_MAX_SEG_FC_ENABLE 0x0002;
836#define ET_RX_MCIF_CTRL_MAX_SEG_ENABLE 0x0001;
837
811/* 838/*
812 * structure for Memory Controller Interface Water Mark reg in rxmac address 839 * structure for Memory Controller Interface Water Mark reg in rxmac address
813 * map. Located at address 0x408C 840 * map. Located at address 0x408C
@@ -907,7 +934,6 @@ struct rxmac_regs { /* Location: */
907 934
908/* END OF RXMAC REGISTER ADDRESS MAP */ 935/* END OF RXMAC REGISTER ADDRESS MAP */
909 936
910
911/* START OF MAC REGISTER ADDRESS MAP */ 937/* START OF MAC REGISTER ADDRESS MAP */
912 938
913/* 939/*
@@ -932,12 +958,18 @@ struct rxmac_regs { /* Location: */
932 * 0: tx enable 958 * 0: tx enable
933 */ 959 */
934 960
935#define CFG1_LOOPBACK 0x00000100 961#define ET_MAC_CFG1_SOFT_RESET 0x80000000
936#define CFG1_RX_FLOW 0x00000020 962#define ET_MAC_CFG1_SIM_RESET 0x40000000
937#define CFG1_TX_FLOW 0x00000010 963#define ET_MAC_CFG1_RESET_RXMC 0x00080000
938#define CFG1_RX_ENABLE 0x00000004 964#define ET_MAC_CFG1_RESET_TXMC 0x00040000
939#define CFG1_TX_ENABLE 0x00000001 965#define ET_MAC_CFG1_RESET_RXFUNC 0x00020000
940#define CFG1_WAIT 0x0000000A /* RX & TX syncd */ 966#define ET_MAC_CFG1_RESET_TXFUNC 0x00010000
967#define ET_MAC_CFG1_LOOPBACK 0x00000100
968#define ET_MAC_CFG1_RX_FLOW 0x00000020
969#define ET_MAC_CFG1_TX_FLOW 0x00000010
970#define ET_MAC_CFG1_RX_ENABLE 0x00000004
971#define ET_MAC_CFG1_TX_ENABLE 0x00000001
972#define ET_MAC_CFG1_WAIT 0x0000000A /* RX & TX syncd */
941 973
942/* 974/*
943 * structure for configuration #2 reg in mac address map. 975 * structure for configuration #2 reg in mac address map.
@@ -955,6 +987,15 @@ struct rxmac_regs { /* Location: */
955 * 0: full duplex 987 * 0: full duplex
956 */ 988 */
957 989
990#define ET_MAC_CFG2_PREAMBLE_SHIFT 12;
991#define ET_MAC_CFG2_IFMODE_MASK 0x0300;
992#define ET_MAC_CFG2_IFMODE_1000 0x0200;
993#define ET_MAC_CFG2_IFMODE_100 0x0100;
994#define ET_MAC_CFG2_IFMODE_HUGE_FRAME 0x0020;
995#define ET_MAC_CFG2_IFMODE_LEN_CHECK 0x0010;
996#define ET_MAC_CFG2_IFMODE_PAD_CRC 0x0004;
997#define ET_MAC_CFG2_IFMODE_CRC_ENABLE 0x0002;
998#define ET_MAC_CFG2_IFMODE_FULL_DPLX 0x0001;
958 999
959/* 1000/*
960 * structure for Interpacket gap reg in mac address map. 1001 * structure for Interpacket gap reg in mac address map.
@@ -1009,6 +1050,8 @@ struct rxmac_regs { /* Location: */
1009 * 2-0: mgmt clock reset 1050 * 2-0: mgmt clock reset
1010 */ 1051 */
1011 1052
1053#define ET_MAC_MIIMGMT_CLK_RST 0x0007
1054
1012/* 1055/*
1013 * structure for MII Management Command reg in mac address map. 1056 * structure for MII Management Command reg in mac address map.
1014 * located at address 0x5024 1057 * located at address 0x5024
@@ -1025,7 +1068,7 @@ struct rxmac_regs { /* Location: */
1025 * 4-0: register 1068 * 4-0: register
1026 */ 1069 */
1027 1070
1028#define MII_ADDR(phy, reg) ((phy) << 8 | (reg)) 1071#define ET_MAC_MII_ADDR(phy, reg) ((phy) << 8 | (reg))
1029 1072
1030/* 1073/*
1031 * structure for MII Management Control reg in mac address map. 1074 * structure for MII Management Control reg in mac address map.
@@ -1041,6 +1084,8 @@ struct rxmac_regs { /* Location: */
1041 * 15-0: phy control 1084 * 15-0: phy control
1042 */ 1085 */
1043 1086
1087#define ET_MAC_MIIMGMT_STAT_PHYCRTL_MASK 0xFFFF;
1088
1044/* 1089/*
1045 * structure for MII Management Indicators reg in mac address map. 1090 * structure for MII Management Indicators reg in mac address map.
1046 * located at address 0x5034 1091 * located at address 0x5034
@@ -1050,8 +1095,8 @@ struct rxmac_regs { /* Location: */
1050 * 0: busy 1095 * 0: busy
1051 */ 1096 */
1052 1097
1053#define MGMT_BUSY 0x00000001 /* busy */ 1098#define ET_MAC_MGMT_BUSY 0x00000001 /* busy */
1054#define MGMT_WAIT 0x00000005 /* busy | not valid */ 1099#define ET_MAC_MGMT_WAIT 0x00000005 /* busy | not valid */
1055 1100
1056/* 1101/*
1057 * structure for Interface Control reg in mac address map. 1102 * structure for Interface Control reg in mac address map.
@@ -1076,6 +1121,9 @@ struct rxmac_regs { /* Location: */
1076 * 0: enable jabber protection 1121 * 0: enable jabber protection
1077 */ 1122 */
1078 1123
1124#define ET_MAC_IFCTRL_GHDMODE (1 << 26)
1125#define ET_MAC_IFCTRL_PHYMODE (1 << 24)
1126
1079/* 1127/*
1080 * structure for Interface Status reg in mac address map. 1128 * structure for Interface Status reg in mac address map.
1081 * located at address 0x503C 1129 * located at address 0x503C
diff --git a/drivers/staging/frontier/alphatrack.c b/drivers/staging/frontier/alphatrack.c
index 33085782689e..ea9362d7e589 100644
--- a/drivers/staging/frontier/alphatrack.c
+++ b/drivers/staging/frontier/alphatrack.c
@@ -678,10 +678,9 @@ static int usb_alphatrack_probe(struct usb_interface *intf,
678 /* allocate memory for our device state and initialize it */ 678 /* allocate memory for our device state and initialize it */
679 679
680 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 680 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
681 if (dev == NULL) { 681 if (dev == NULL)
682 dev_err(&intf->dev, "Out of memory\n");
683 goto exit; 682 goto exit;
684 } 683
685 mutex_init(&dev->mtx); 684 mutex_init(&dev->mtx);
686 dev->intf = intf; 685 dev->intf = intf;
687 init_waitqueue_head(&dev->read_wait); 686 init_waitqueue_head(&dev->read_wait);
@@ -721,28 +720,21 @@ static int usb_alphatrack_probe(struct usb_interface *intf,
721 720
722 /* FIXME - there are more usb_alloc routines for dma correctness. 721 /* FIXME - there are more usb_alloc routines for dma correctness.
723 Needed? */ 722 Needed? */
724 dev->ring_buffer = 723 dev->ring_buffer = kmalloc_array(true_size,
725 kmalloc((true_size * sizeof(struct alphatrack_icmd)), GFP_KERNEL); 724 sizeof(struct alphatrack_icmd),
726 725 GFP_KERNEL);
727 if (!dev->ring_buffer) { 726 if (!dev->ring_buffer)
728 dev_err(&intf->dev,
729 "Couldn't allocate input ring_buffer of size %d\n",
730 true_size);
731 goto error; 727 goto error;
732 }
733 728
734 dev->interrupt_in_buffer = 729 dev->interrupt_in_buffer = kmalloc(dev->interrupt_in_endpoint_size,
735 kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); 730 GFP_KERNEL);
736 731 if (!dev->interrupt_in_buffer)
737 if (!dev->interrupt_in_buffer) {
738 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
739 goto error; 732 goto error;
740 } 733
741 dev->oldi_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); 734 dev->oldi_buffer = kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
742 if (!dev->oldi_buffer) { 735 if (!dev->oldi_buffer)
743 dev_err(&intf->dev, "Couldn't allocate old buffer\n");
744 goto error; 736 goto error;
745 } 737
746 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 738 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
747 if (!dev->interrupt_in_urb) { 739 if (!dev->interrupt_in_urb) {
748 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n"); 740 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
@@ -764,20 +756,17 @@ static int usb_alphatrack_probe(struct usb_interface *intf,
764 true_size = min(write_buffer_size, WRITE_BUFFER_SIZE); 756 true_size = min(write_buffer_size, WRITE_BUFFER_SIZE);
765 757
766 dev->interrupt_out_buffer = 758 dev->interrupt_out_buffer =
767 kmalloc(true_size * dev->interrupt_out_endpoint_size, GFP_KERNEL); 759 kmalloc_array(true_size,
768 760 dev->interrupt_out_endpoint_size,
769 if (!dev->interrupt_out_buffer) { 761 GFP_KERNEL);
770 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n"); 762 if (!dev->interrupt_out_buffer)
771 goto error; 763 goto error;
772 }
773
774 dev->write_buffer =
775 kmalloc(true_size * sizeof(struct alphatrack_ocmd), GFP_KERNEL);
776 764
777 if (!dev->write_buffer) { 765 dev->write_buffer = kmalloc_array(true_size,
778 dev_err(&intf->dev, "Couldn't allocate write_buffer\n"); 766 sizeof(struct alphatrack_ocmd),
767 GFP_KERNEL);
768 if (!dev->write_buffer)
779 goto error; 769 goto error;
780 }
781 770
782 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 771 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
783 if (!dev->interrupt_out_urb) { 772 if (!dev->interrupt_out_urb) {
diff --git a/drivers/staging/frontier/tranzport.c b/drivers/staging/frontier/tranzport.c
index 5196a4e053e6..04b5e66d9861 100644
--- a/drivers/staging/frontier/tranzport.c
+++ b/drivers/staging/frontier/tranzport.c
@@ -803,10 +803,9 @@ static int usb_tranzport_probe(struct usb_interface *intf,
803 /* allocate memory for our device state and initialize it */ 803 /* allocate memory for our device state and initialize it */
804 804
805 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 805 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
806 if (dev == NULL) { 806 if (dev == NULL)
807 dev_err(&intf->dev, "Out of memory\n");
808 goto exit; 807 goto exit;
809 } 808
810 mutex_init(&dev->mtx); 809 mutex_init(&dev->mtx);
811 dev->intf = intf; 810 dev->intf = intf;
812 init_waitqueue_head(&dev->read_wait); 811 init_waitqueue_head(&dev->read_wait);
@@ -848,18 +847,14 @@ static int usb_tranzport_probe(struct usb_interface *intf,
848 847
849 dev->ring_buffer = 848 dev->ring_buffer =
850 kmalloc((true_size * sizeof(struct tranzport_cmd)) + 8, GFP_KERNEL); 849 kmalloc((true_size * sizeof(struct tranzport_cmd)) + 8, GFP_KERNEL);
851 850 if (!dev->ring_buffer)
852 if (!dev->ring_buffer) {
853 dev_err(&intf->dev,
854 "Couldn't allocate ring_buffer size %d\n", true_size);
855 goto error; 851 goto error;
856 } 852
857 dev->interrupt_in_buffer = 853 dev->interrupt_in_buffer =
858 kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL); 854 kmalloc(dev->interrupt_in_endpoint_size, GFP_KERNEL);
859 if (!dev->interrupt_in_buffer) { 855 if (!dev->interrupt_in_buffer)
860 dev_err(&intf->dev, "Couldn't allocate interrupt_in_buffer\n");
861 goto error; 856 goto error;
862 } 857
863 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 858 dev->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL);
864 if (!dev->interrupt_in_urb) { 859 if (!dev->interrupt_in_urb) {
865 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n"); 860 dev_err(&intf->dev, "Couldn't allocate interrupt_in_urb\n");
@@ -875,12 +870,11 @@ static int usb_tranzport_probe(struct usb_interface *intf,
875 "Interrupt out endpoint size is not 8!)\n"); 870 "Interrupt out endpoint size is not 8!)\n");
876 871
877 dev->interrupt_out_buffer = 872 dev->interrupt_out_buffer =
878 kmalloc(write_buffer_size * dev->interrupt_out_endpoint_size, 873 kmalloc_array(write_buffer_size,
879 GFP_KERNEL); 874 dev->interrupt_out_endpoint_size, GFP_KERNEL);
880 if (!dev->interrupt_out_buffer) { 875 if (!dev->interrupt_out_buffer)
881 dev_err(&intf->dev, "Couldn't allocate interrupt_out_buffer\n");
882 goto error; 876 goto error;
883 } 877
884 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 878 dev->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL);
885 if (!dev->interrupt_out_urb) { 879 if (!dev->interrupt_out_urb) {
886 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n"); 880 dev_err(&intf->dev, "Couldn't allocate interrupt_out_urb\n");
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
index adb436ed2511..65f7ab6cb467 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
@@ -31,41 +31,10 @@
31#define SUCCESS 0x00 31#define SUCCESS 0x00
32#define FAILURE 0x01 32#define FAILURE 0x01
33 33
34struct ft1000_info { 34struct ft1000_pcmcia {
35 struct net_device_stats stats;
36 u16 DrvErrNum;
37 u16 AsicID;
38 int PktIntfErr; 35 int PktIntfErr;
39 int CardReady;
40 int registered;
41 int mediastate;
42 u16 packetseqnum; 36 u16 packetseqnum;
43 u8 squeseqnum; /* sequence number on slow queue */
44 spinlock_t dpram_lock;
45 u16 fifo_cnt;
46 u8 DspVer[DSPVERSZ]; /* DSP version number */
47 u8 HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */
48 u8 Sku[SKUSZ]; /* SKU */
49 u8 eui64[EUISZ]; /* EUI64 */
50 time_t ConTm; /* Connection Time */
51 u16 LedStat;
52 u16 ConStat;
53 u16 ProgConStat;
54 u8 ProductMode[MODESZ];
55 u8 RfCalVer[CALVERSZ];
56 u8 RfCalDate[CALDATESZ];
57 u16 DSP_TIME[4];
58 struct list_head prov_list;
59 u16 DSPInfoBlklen;
60 int (*ft1000_reset)(void *);
61 void *link; 37 void *link;
62 u16 DSPInfoBlk[MAX_DSP_SESS_REC];
63 union {
64 u16 Rec[MAX_DSP_SESS_REC];
65 u32 MagRec[MAX_DSP_SESS_REC/2];
66 } DSPSess;
67 struct proc_dir_entry *proc_ft1000;
68 char netdevname[IFNAMSIZ];
69}; 38};
70 39
71struct pcmcia_device; 40struct pcmcia_device;
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
index 67ca5c990437..29d0a72f0d65 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
@@ -328,11 +328,12 @@ static void ft1000_disable_interrupts(struct net_device *dev)
328static void ft1000_reset_asic(struct net_device *dev) 328static void ft1000_reset_asic(struct net_device *dev)
329{ 329{
330 struct ft1000_info *info = netdev_priv(dev); 330 struct ft1000_info *info = netdev_priv(dev);
331 struct ft1000_pcmcia *pcmcia = info->priv;
331 u16 tempword; 332 u16 tempword;
332 333
333 DEBUG(1, "ft1000_hw:ft1000_reset_asic called\n"); 334 DEBUG(1, "ft1000_hw:ft1000_reset_asic called\n");
334 335
335 (*info->ft1000_reset) (info->link); 336 (*info->ft1000_reset) (pcmcia->link);
336 337
337 // Let's use the register provided by the Magnemite ASIC to reset the 338 // Let's use the register provided by the Magnemite ASIC to reset the
338 // ASIC and DSP. 339 // ASIC and DSP.
@@ -1397,12 +1398,13 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1397static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum) 1398static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1398{ 1399{
1399 struct ft1000_info *info = netdev_priv(dev); 1400 struct ft1000_info *info = netdev_priv(dev);
1401 struct ft1000_pcmcia *pcmcia = info->priv;
1400 u16 i; 1402 u16 i;
1401 u32 templong; 1403 u32 templong;
1402 u16 tempword; 1404 u16 tempword;
1403 1405
1404 DEBUG(1, "ft1000:ft1000_hw:ft1000_flush_fifo called\n"); 1406 DEBUG(1, "ft1000:ft1000_hw:ft1000_flush_fifo called\n");
1405 if (info->PktIntfErr > MAX_PH_ERR) { 1407 if (pcmcia->PktIntfErr > MAX_PH_ERR) {
1406 if (info->AsicID == ELECTRABUZZ_ID) { 1408 if (info->AsicID == ELECTRABUZZ_ID) {
1407 info->DSP_TIME[0] = 1409 info->DSP_TIME[0] =
1408 ft1000_read_dpram(dev, FT1000_DSP_TIMER0); 1410 ft1000_read_dpram(dev, FT1000_DSP_TIMER0);
@@ -1491,7 +1493,7 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1491 FIFO_FLUSH_BADCNT; 1493 FIFO_FLUSH_BADCNT;
1492 } else { 1494 } else {
1493 // Let's assume that we really flush the FIFO 1495 // Let's assume that we really flush the FIFO
1494 info->PktIntfErr++; 1496 pcmcia->PktIntfErr++;
1495 return; 1497 return;
1496 } 1498 }
1497 } else { 1499 } else {
@@ -1522,7 +1524,7 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1522 DEBUG(0, "FT1000_REG_MAG_DFSR = 0x%x\n", tempword); 1524 DEBUG(0, "FT1000_REG_MAG_DFSR = 0x%x\n", tempword);
1523 } 1525 }
1524 if (DrvErrNum) { 1526 if (DrvErrNum) {
1525 info->PktIntfErr++; 1527 pcmcia->PktIntfErr++;
1526 } 1528 }
1527 } 1529 }
1528} 1530}
@@ -1731,6 +1733,7 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1731static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len) 1733static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1732{ 1734{
1733 struct ft1000_info *info = netdev_priv(dev); 1735 struct ft1000_info *info = netdev_priv(dev);
1736 struct ft1000_pcmcia *pcmcia = info->priv;
1734 union { 1737 union {
1735 struct pseudo_hdr blk; 1738 struct pseudo_hdr blk;
1736 u16 buff[sizeof(struct pseudo_hdr) >> 1]; 1739 u16 buff[sizeof(struct pseudo_hdr) >> 1];
@@ -1780,7 +1783,7 @@ static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1780 pseudo.blk.control = 0; 1783 pseudo.blk.control = 0;
1781 pseudo.blk.rsvd1 = 0; 1784 pseudo.blk.rsvd1 = 0;
1782 pseudo.blk.seq_num = 0; 1785 pseudo.blk.seq_num = 0;
1783 pseudo.blk.rsvd2 = info->packetseqnum++; 1786 pseudo.blk.rsvd2 = pcmcia->packetseqnum++;
1784 pseudo.blk.qos_class = 0; 1787 pseudo.blk.qos_class = 0;
1785 /* Calculate pseudo header checksum */ 1788 /* Calculate pseudo header checksum */
1786 pseudo.blk.checksum = pseudo.buff[0]; 1789 pseudo.blk.checksum = pseudo.buff[0];
@@ -2058,6 +2061,8 @@ void stop_ft1000_card(struct net_device *dev)
2058 kfree(ptr); 2061 kfree(ptr);
2059 } 2062 }
2060 2063
2064 kfree(info->priv);
2065
2061 if (info->registered) { 2066 if (info->registered) {
2062 unregister_netdev(dev); 2067 unregister_netdev(dev);
2063 info->registered = 0; 2068 info->registered = 0;
@@ -2101,6 +2106,7 @@ struct net_device *init_ft1000_card(struct pcmcia_device *link,
2101 void *ft1000_reset) 2106 void *ft1000_reset)
2102{ 2107{
2103 struct ft1000_info *info; 2108 struct ft1000_info *info;
2109 struct ft1000_pcmcia *pcmcia;
2104 struct net_device *dev; 2110 struct net_device *dev;
2105 2111
2106 static const struct net_device_ops ft1000ops = // Slavius 21.10.2009 due to kernel changes 2112 static const struct net_device_ops ft1000ops = // Slavius 21.10.2009 due to kernel changes
@@ -2142,10 +2148,13 @@ struct net_device *init_ft1000_card(struct pcmcia_device *link,
2142 2148
2143 memset(&info->stats, 0, sizeof(struct net_device_stats)); 2149 memset(&info->stats, 0, sizeof(struct net_device_stats));
2144 2150
2151 info->priv = kzalloc(sizeof(struct ft1000_pcmcia), GFP_KERNEL);
2152 pcmcia = info->priv;
2153 pcmcia->link = link;
2154
2145 spin_lock_init(&info->dpram_lock); 2155 spin_lock_init(&info->dpram_lock);
2146 info->DrvErrNum = 0; 2156 info->DrvErrNum = 0;
2147 info->registered = 1; 2157 info->registered = 1;
2148 info->link = link;
2149 info->ft1000_reset = ft1000_reset; 2158 info->ft1000_reset = ft1000_reset;
2150 info->mediastate = 0; 2159 info->mediastate = 0;
2151 info->fifo_cnt = 0; 2160 info->fifo_cnt = 0;
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c
index 72727c6b9e2e..5337b415d450 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_proc.c
@@ -175,8 +175,8 @@ static int ft1000NotifyProc(struct notifier_block *this, unsigned long event,
175 175
176 switch (event) { 176 switch (event) {
177 case NETDEV_CHANGENAME: 177 case NETDEV_CHANGENAME:
178 remove_proc_entry(info->netdevname, info->proc_ft1000); 178 remove_proc_entry(info->netdevname, info->ft1000_proc_dir);
179 create_proc_read_entry(dev->name, 0644, info->proc_ft1000, 179 create_proc_read_entry(dev->name, 0644, info->ft1000_proc_dir,
180 ft1000ReadProc, dev); 180 ft1000ReadProc, dev);
181 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name); 181 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
182 break; 182 break;
@@ -194,8 +194,8 @@ void ft1000InitProc(struct net_device *dev)
194 194
195 info = netdev_priv(dev); 195 info = netdev_priv(dev);
196 196
197 info->proc_ft1000 = proc_mkdir(FT1000_PROC, init_net.proc_net); 197 info->ft1000_proc_dir = proc_mkdir(FT1000_PROC, init_net.proc_net);
198 create_proc_read_entry(dev->name, 0644, info->proc_ft1000, 198 create_proc_read_entry(dev->name, 0644, info->ft1000_proc_dir,
199 ft1000ReadProc, dev); 199 ft1000ReadProc, dev);
200 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name); 200 snprintf(info->netdevname, IFNAMSIZ, "%s", dev->name);
201 register_netdevice_notifier(&ft1000_netdev_notifier); 201 register_netdevice_notifier(&ft1000_netdev_notifier);
@@ -207,7 +207,7 @@ void ft1000CleanupProc(struct net_device *dev)
207 207
208 info = netdev_priv(dev); 208 info = netdev_priv(dev);
209 209
210 remove_proc_entry(dev->name, info->proc_ft1000); 210 remove_proc_entry(dev->name, info->ft1000_proc_dir);
211 remove_proc_entry(FT1000_PROC, init_net.proc_net); 211 remove_proc_entry(FT1000_PROC, init_net.proc_net);
212 unregister_netdevice_notifier(&ft1000_netdev_notifier); 212 unregister_netdevice_notifier(&ft1000_netdev_notifier);
213} 213}
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
index 6d911fda47fb..297389e8c608 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
@@ -137,29 +137,28 @@ void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist)
137// Notes: Only called by init_module(). 137// Notes: Only called by init_module().
138// 138//
139//--------------------------------------------------------------------------- 139//---------------------------------------------------------------------------
140int ft1000_create_dev(struct ft1000_device *dev) 140int ft1000_create_dev(struct ft1000_usb *dev)
141{ 141{
142 struct ft1000_info *info = netdev_priv(dev->net);
143 int result; 142 int result;
144 int i; 143 int i;
145 struct dentry *dir, *file; 144 struct dentry *dir, *file;
146 struct ft1000_debug_dirs *tmp; 145 struct ft1000_debug_dirs *tmp;
147 146
148 // make a new device name 147 // make a new device name
149 sprintf(info->DeviceName, "%s%d", "FT1000_", info->CardNumber); 148 sprintf(dev->DeviceName, "%s%d", "FT1000_", dev->CardNumber);
150 149
151 DEBUG("%s: number of instance = %d\n", __func__, ft1000_flarion_cnt); 150 DEBUG("%s: number of instance = %d\n", __func__, ft1000_flarion_cnt);
152 DEBUG("DeviceCreated = %x\n", info->DeviceCreated); 151 DEBUG("DeviceCreated = %x\n", dev->DeviceCreated);
153 152
154 if (info->DeviceCreated) 153 if (dev->DeviceCreated)
155 { 154 {
156 DEBUG("%s: \"%s\" already registered\n", __func__, info->DeviceName); 155 DEBUG("%s: \"%s\" already registered\n", __func__, dev->DeviceName);
157 return -EIO; 156 return -EIO;
158 } 157 }
159 158
160 159
161 // register the device 160 // register the device
162 DEBUG("%s: \"%s\" debugfs device registration\n", __func__, info->DeviceName); 161 DEBUG("%s: \"%s\" debugfs device registration\n", __func__, dev->DeviceName);
163 162
164 tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL); 163 tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL);
165 if (tmp == NULL) { 164 if (tmp == NULL) {
@@ -167,7 +166,7 @@ int ft1000_create_dev(struct ft1000_device *dev)
167 goto fail; 166 goto fail;
168 } 167 }
169 168
170 dir = debugfs_create_dir(info->DeviceName, NULL); 169 dir = debugfs_create_dir(dev->DeviceName, NULL);
171 if (IS_ERR(dir)) { 170 if (IS_ERR(dir)) {
172 result = PTR_ERR(dir); 171 result = PTR_ERR(dir);
173 goto debug_dir_fail; 172 goto debug_dir_fail;
@@ -182,27 +181,27 @@ int ft1000_create_dev(struct ft1000_device *dev)
182 181
183 tmp->dent = dir; 182 tmp->dent = dir;
184 tmp->file = file; 183 tmp->file = file;
185 tmp->int_number = info->CardNumber; 184 tmp->int_number = dev->CardNumber;
186 list_add(&(tmp->list), &(info->nodes.list)); 185 list_add(&(tmp->list), &(dev->nodes.list));
187 186
188 DEBUG("%s: registered debugfs directory \"%s\"\n", __func__, info->DeviceName); 187 DEBUG("%s: registered debugfs directory \"%s\"\n", __func__, dev->DeviceName);
189 188
190 // initialize application information 189 // initialize application information
191 info->appcnt = 0; 190 dev->appcnt = 0;
192 for (i=0; i<MAX_NUM_APP; i++) { 191 for (i=0; i<MAX_NUM_APP; i++) {
193 info->app_info[i].nTxMsg = 0; 192 dev->app_info[i].nTxMsg = 0;
194 info->app_info[i].nRxMsg = 0; 193 dev->app_info[i].nRxMsg = 0;
195 info->app_info[i].nTxMsgReject = 0; 194 dev->app_info[i].nTxMsgReject = 0;
196 info->app_info[i].nRxMsgMiss = 0; 195 dev->app_info[i].nRxMsgMiss = 0;
197 info->app_info[i].fileobject = NULL; 196 dev->app_info[i].fileobject = NULL;
198 info->app_info[i].app_id = i+1; 197 dev->app_info[i].app_id = i+1;
199 info->app_info[i].DspBCMsgFlag = 0; 198 dev->app_info[i].DspBCMsgFlag = 0;
200 info->app_info[i].NumOfMsg = 0; 199 dev->app_info[i].NumOfMsg = 0;
201 init_waitqueue_head(&info->app_info[i].wait_dpram_msg); 200 init_waitqueue_head(&dev->app_info[i].wait_dpram_msg);
202 INIT_LIST_HEAD (&info->app_info[i].app_sqlist); 201 INIT_LIST_HEAD (&dev->app_info[i].app_sqlist);
203 } 202 }
204 203
205 info->DeviceCreated = TRUE; 204 dev->DeviceCreated = TRUE;
206 ft1000_flarion_cnt++; 205 ft1000_flarion_cnt++;
207 206
208 return 0; 207 return 0;
@@ -225,9 +224,10 @@ fail:
225// Notes: Only called by cleanup_module(). 224// Notes: Only called by cleanup_module().
226// 225//
227//--------------------------------------------------------------------------- 226//---------------------------------------------------------------------------
228void ft1000_destroy_dev(struct net_device *dev) 227void ft1000_destroy_dev(struct net_device *netdev)
229{ 228{
230 struct ft1000_info *info = netdev_priv(dev); 229 struct ft1000_info *info = netdev_priv(netdev);
230 struct ft1000_usb *dev = info->priv;
231 int i; 231 int i;
232 struct dpram_blk *pdpram_blk; 232 struct dpram_blk *pdpram_blk;
233 struct dpram_blk *ptr; 233 struct dpram_blk *ptr;
@@ -238,12 +238,12 @@ void ft1000_destroy_dev(struct net_device *dev)
238 238
239 239
240 240
241 if (info->DeviceCreated) 241 if (dev->DeviceCreated)
242 { 242 {
243 ft1000_flarion_cnt--; 243 ft1000_flarion_cnt--;
244 list_for_each_safe(pos, q, &info->nodes.list) { 244 list_for_each_safe(pos, q, &dev->nodes.list) {
245 dir = list_entry(pos, struct ft1000_debug_dirs, list); 245 dir = list_entry(pos, struct ft1000_debug_dirs, list);
246 if (dir->int_number == info->CardNumber) { 246 if (dir->int_number == dev->CardNumber) {
247 debugfs_remove(dir->file); 247 debugfs_remove(dir->file);
248 debugfs_remove(dir->dent); 248 debugfs_remove(dir->dent);
249 list_del(pos); 249 list_del(pos);
@@ -251,17 +251,17 @@ void ft1000_destroy_dev(struct net_device *dev)
251 } 251 }
252 } 252 }
253 DEBUG("%s: unregistered device \"%s\"\n", __func__, 253 DEBUG("%s: unregistered device \"%s\"\n", __func__,
254 info->DeviceName); 254 dev->DeviceName);
255 255
256 // Make sure we free any memory reserve for slow Queue 256 // Make sure we free any memory reserve for slow Queue
257 for (i=0; i<MAX_NUM_APP; i++) { 257 for (i=0; i<MAX_NUM_APP; i++) {
258 while (list_empty(&info->app_info[i].app_sqlist) == 0) { 258 while (list_empty(&dev->app_info[i].app_sqlist) == 0) {
259 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list); 259 pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next, struct dpram_blk, list);
260 list_del(&pdpram_blk->list); 260 list_del(&pdpram_blk->list);
261 ft1000_free_buffer(pdpram_blk, &freercvpool); 261 ft1000_free_buffer(pdpram_blk, &freercvpool);
262 262
263 } 263 }
264 wake_up_interruptible(&info->app_info[i].wait_dpram_msg); 264 wake_up_interruptible(&dev->app_info[i].wait_dpram_msg);
265 } 265 }
266 266
267 // Remove buffer allocated for receive command data 267 // Remove buffer allocated for receive command data
@@ -273,7 +273,7 @@ void ft1000_destroy_dev(struct net_device *dev)
273 kfree(ptr); 273 kfree(ptr);
274 } 274 }
275 } 275 }
276 info->DeviceCreated = FALSE; 276 dev->DeviceCreated = FALSE;
277 } 277 }
278 278
279 279
@@ -292,7 +292,7 @@ void ft1000_destroy_dev(struct net_device *dev)
292static int ft1000_open (struct inode *inode, struct file *file) 292static int ft1000_open (struct inode *inode, struct file *file)
293{ 293{
294 struct ft1000_info *info; 294 struct ft1000_info *info;
295 struct ft1000_device *dev = (struct ft1000_device *)inode->i_private; 295 struct ft1000_usb *dev = (struct ft1000_usb *)inode->i_private;
296 int i,num; 296 int i,num;
297 297
298 DEBUG("%s called\n", __func__); 298 DEBUG("%s called\n", __func__);
@@ -301,17 +301,17 @@ static int ft1000_open (struct inode *inode, struct file *file)
301 301
302 info = file->private_data = netdev_priv(dev->net); 302 info = file->private_data = netdev_priv(dev->net);
303 303
304 DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), info->appcnt ); 304 DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), dev->appcnt );
305 305
306 // Check if maximum number of application exceeded 306 // Check if maximum number of application exceeded
307 if (info->appcnt > MAX_NUM_APP) { 307 if (dev->appcnt > MAX_NUM_APP) {
308 DEBUG("Maximum number of application exceeded\n"); 308 DEBUG("Maximum number of application exceeded\n");
309 return -EACCES; 309 return -EACCES;
310 } 310 }
311 311
312 // Search for available application info block 312 // Search for available application info block
313 for (i=0; i<MAX_NUM_APP; i++) { 313 for (i=0; i<MAX_NUM_APP; i++) {
314 if ( (info->app_info[i].fileobject == NULL) ) { 314 if ( (dev->app_info[i].fileobject == NULL) ) {
315 break; 315 break;
316 } 316 }
317 } 317 }
@@ -322,12 +322,12 @@ static int ft1000_open (struct inode *inode, struct file *file)
322 return -EACCES; 322 return -EACCES;
323 } 323 }
324 324
325 info->appcnt++; 325 dev->appcnt++;
326 info->app_info[i].fileobject = &file->f_owner; 326 dev->app_info[i].fileobject = &file->f_owner;
327 info->app_info[i].nTxMsg = 0; 327 dev->app_info[i].nTxMsg = 0;
328 info->app_info[i].nRxMsg = 0; 328 dev->app_info[i].nRxMsg = 0;
329 info->app_info[i].nTxMsgReject = 0; 329 dev->app_info[i].nTxMsgReject = 0;
330 info->app_info[i].nRxMsgMiss = 0; 330 dev->app_info[i].nRxMsgMiss = 0;
331 331
332 nonseekable_open(inode, file); 332 nonseekable_open(inode, file);
333 return 0; 333 return 0;
@@ -347,8 +347,9 @@ static int ft1000_open (struct inode *inode, struct file *file)
347 347
348static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) 348static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait)
349{ 349{
350 struct net_device *dev = file->private_data; 350 struct net_device *netdev = file->private_data;
351 struct ft1000_info *info; 351 struct ft1000_info *info = netdev_priv(netdev);
352 struct ft1000_usb *dev = info->priv;
352 int i; 353 int i;
353 354
354 //DEBUG("ft1000_poll_dev called\n"); 355 //DEBUG("ft1000_poll_dev called\n");
@@ -357,12 +358,10 @@ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait)
357 return (-EBADF); 358 return (-EBADF);
358 } 359 }
359 360
360 info = netdev_priv(dev);
361
362 // Search for matching file object 361 // Search for matching file object
363 for (i=0; i<MAX_NUM_APP; i++) { 362 for (i=0; i<MAX_NUM_APP; i++) {
364 if ( info->app_info[i].fileobject == &file->f_owner) { 363 if ( dev->app_info[i].fileobject == &file->f_owner) {
365 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id); 364 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", dev->app_info[i].app_id);
366 break; 365 break;
367 } 366 }
368 } 367 }
@@ -373,12 +372,12 @@ static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait)
373 return ( -EACCES ); 372 return ( -EACCES );
374 } 373 }
375 374
376 if (list_empty(&info->app_info[i].app_sqlist) == 0) { 375 if (list_empty(&dev->app_info[i].app_sqlist) == 0) {
377 DEBUG("FT1000:ft1000_poll_dev:Message detected in slow queue\n"); 376 DEBUG("FT1000:ft1000_poll_dev:Message detected in slow queue\n");
378 return(POLLIN | POLLRDNORM | POLLPRI); 377 return(POLLIN | POLLRDNORM | POLLPRI);
379 } 378 }
380 379
381 poll_wait (file, &info->app_info[i].wait_dpram_msg, wait); 380 poll_wait (file, &dev->app_info[i].wait_dpram_msg, wait);
382 //DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n"); 381 //DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n");
383 382
384 return (0); 383 return (0);
@@ -399,7 +398,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
399{ 398{
400 void __user *argp = (void __user *)argument; 399 void __user *argp = (void __user *)argument;
401 struct ft1000_info *info; 400 struct ft1000_info *info;
402 struct ft1000_device *ft1000dev; 401 struct ft1000_usb *ft1000dev;
403 int result=0; 402 int result=0;
404 int cmd; 403 int cmd;
405 int i; 404 int i;
@@ -428,7 +427,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
428 //DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument); 427 //DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument);
429 428
430 info = file->private_data; 429 info = file->private_data;
431 ft1000dev = info->pFt1000Dev; 430 ft1000dev = info->priv;
432 cmd = _IOC_NR(command); 431 cmd = _IOC_NR(command);
433 //DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd); 432 //DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd);
434 433
@@ -444,8 +443,8 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
444 if (tempword == DSPBCMSGID) { 443 if (tempword == DSPBCMSGID) {
445 // Search for matching file object 444 // Search for matching file object
446 for (i=0; i<MAX_NUM_APP; i++) { 445 for (i=0; i<MAX_NUM_APP; i++) {
447 if ( info->app_info[i].fileobject == &file->f_owner) { 446 if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
448 info->app_info[i].DspBCMsgFlag = 1; 447 ft1000dev->app_info[i].DspBCMsgFlag = 1;
449 DEBUG("FT1000:ft1000_ioctl:Registered for broadcast messages\n"); 448 DEBUG("FT1000:ft1000_ioctl:Registered for broadcast messages\n");
450 break; 449 break;
451 } 450 }
@@ -534,15 +533,15 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
534 return (-EBADF); 533 return (-EBADF);
535 } 534 }
536 535
537 if (info->DrvMsgPend) { 536 if (ft1000dev->DrvMsgPend) {
538 return (-ENOTTY); 537 return (-ENOTTY);
539 } 538 }
540 539
541 if ( (info->DspAsicReset) || (info->fProvComplete == 0) ) { 540 if (ft1000dev->fProvComplete == 0) {
542 return (-EACCES); 541 return (-EACCES);
543 } 542 }
544 543
545 info->fAppMsgPend = 1; 544 ft1000dev->fAppMsgPend = 1;
546 545
547 if (info->CardReady) { 546 if (info->CardReady) {
548 547
@@ -571,7 +570,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
571 else { 570 else {
572 // Check if this message came from a registered application 571 // Check if this message came from a registered application
573 for (i=0; i<MAX_NUM_APP; i++) { 572 for (i=0; i<MAX_NUM_APP; i++) {
574 if ( info->app_info[i].fileobject == &file->f_owner) { 573 if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
575 break; 574 break;
576 } 575 }
577 } 576 }
@@ -632,7 +631,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
632 631
633 // Insert slow queue sequence number 632 // Insert slow queue sequence number
634 ppseudo_hdr->seq_num = info->squeseqnum++; 633 ppseudo_hdr->seq_num = info->squeseqnum++;
635 ppseudo_hdr->portsrc = info->app_info[app_index].app_id; 634 ppseudo_hdr->portsrc = ft1000dev->app_info[app_index].app_id;
636 // Calculate new checksum 635 // Calculate new checksum
637 ppseudo_hdr->checksum = *pmsg++; 636 ppseudo_hdr->checksum = *pmsg++;
638 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); 637 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
@@ -645,7 +644,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
645 card_send_command(ft1000dev,(unsigned short*)dpram_data,total_len+2); 644 card_send_command(ft1000dev,(unsigned short*)dpram_data,total_len+2);
646 645
647 646
648 info->app_info[app_index].nTxMsg++; 647 ft1000dev->app_info[app_index].nTxMsg++;
649 } 648 }
650 else { 649 else {
651 result = -EINVAL; 650 result = -EINVAL;
@@ -675,8 +674,8 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
675 674
676 // Search for matching file object 675 // Search for matching file object
677 for (i=0; i<MAX_NUM_APP; i++) { 676 for (i=0; i<MAX_NUM_APP; i++) {
678 if ( info->app_info[i].fileobject == &file->f_owner) { 677 if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
679 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id); 678 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id);
680 break; 679 break;
681 } 680 }
682 } 681 }
@@ -690,13 +689,13 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
690 689
691 result = 0; 690 result = 0;
692 pioctl_dpram = argp; 691 pioctl_dpram = argp;
693 if (list_empty(&info->app_info[i].app_sqlist) == 0) { 692 if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) {
694 //DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n"); 693 //DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n");
695 spin_lock_irqsave(&free_buff_lock, flags); 694 spin_lock_irqsave(&free_buff_lock, flags);
696 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list); 695 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list);
697 list_del(&pdpram_blk->list); 696 list_del(&pdpram_blk->list);
698 info->app_info[i].NumOfMsg--; 697 ft1000dev->app_info[i].NumOfMsg--;
699 //DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg); 698 //DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg);
700 spin_unlock_irqrestore(&free_buff_lock, flags); 699 spin_unlock_irqrestore(&free_buff_lock, flags);
701 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ; 700 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
702 result = get_user(msglen, &pioctl_dpram->total_len); 701 result = get_user(msglen, &pioctl_dpram->total_len);
@@ -723,7 +722,7 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
723 result = -ENOTTY; 722 result = -ENOTTY;
724 break; 723 break;
725 } 724 }
726 info->fAppMsgPend = 0; 725 ft1000dev->fAppMsgPend = 0;
727 return result; 726 return result;
728} 727}
729 728
@@ -741,6 +740,7 @@ static int ft1000_release (struct inode *inode, struct file *file)
741{ 740{
742 struct ft1000_info *info; 741 struct ft1000_info *info;
743 struct net_device *dev; 742 struct net_device *dev;
743 struct ft1000_usb *ft1000dev;
744 int i; 744 int i;
745 struct dpram_blk *pdpram_blk; 745 struct dpram_blk *pdpram_blk;
746 746
@@ -748,16 +748,17 @@ static int ft1000_release (struct inode *inode, struct file *file)
748 748
749 dev = file->private_data; 749 dev = file->private_data;
750 info = netdev_priv(dev); 750 info = netdev_priv(dev);
751 ft1000dev = info->priv;
751 752
752 if (ft1000_flarion_cnt == 0) { 753 if (ft1000_flarion_cnt == 0) {
753 info->appcnt--; 754 ft1000dev->appcnt--;
754 return (-EBADF); 755 return (-EBADF);
755 } 756 }
756 757
757 // Search for matching file object 758 // Search for matching file object
758 for (i=0; i<MAX_NUM_APP; i++) { 759 for (i=0; i<MAX_NUM_APP; i++) {
759 if ( info->app_info[i].fileobject == &file->f_owner) { 760 if ( ft1000dev->app_info[i].fileobject == &file->f_owner) {
760 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id); 761 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id);
761 break; 762 break;
762 } 763 }
763 } 764 }
@@ -765,17 +766,17 @@ static int ft1000_release (struct inode *inode, struct file *file)
765 if (i==MAX_NUM_APP) 766 if (i==MAX_NUM_APP)
766 return 0; 767 return 0;
767 768
768 while (list_empty(&info->app_info[i].app_sqlist) == 0) { 769 while (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) {
769 DEBUG("Remove and free memory queue up on slow queue\n"); 770 DEBUG("Remove and free memory queue up on slow queue\n");
770 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list); 771 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list);
771 list_del(&pdpram_blk->list); 772 list_del(&pdpram_blk->list);
772 ft1000_free_buffer(pdpram_blk, &freercvpool); 773 ft1000_free_buffer(pdpram_blk, &freercvpool);
773 } 774 }
774 775
775 // initialize application information 776 // initialize application information
776 info->appcnt--; 777 ft1000dev->appcnt--;
777 DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, info->appcnt); 778 DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, ft1000dev->appcnt);
778 info->app_info[i].fileobject = NULL; 779 ft1000dev->app_info[i].fileobject = NULL;
779 780
780 return 0; 781 return 0;
781} 782}
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
index 1972b72450d4..5190c8ac4e0a 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
@@ -114,7 +114,7 @@ struct dsp_image_info {
114//--------------------------------------------------------------------------- 114//---------------------------------------------------------------------------
115// Function: check_usb_db 115// Function: check_usb_db
116// 116//
117// Parameters: struct ft1000_device - device structure 117// Parameters: struct ft1000_usb - device structure
118// 118//
119// Returns: 0 - success 119// Returns: 0 - success
120// 120//
@@ -123,7 +123,7 @@ struct dsp_image_info {
123// Notes: 123// Notes:
124// 124//
125//--------------------------------------------------------------------------- 125//---------------------------------------------------------------------------
126static u32 check_usb_db (struct ft1000_device *ft1000dev) 126static u32 check_usb_db (struct ft1000_usb *ft1000dev)
127{ 127{
128 int loopcnt; 128 int loopcnt;
129 u16 temp; 129 u16 temp;
@@ -172,7 +172,7 @@ static u32 check_usb_db (struct ft1000_device *ft1000dev)
172//--------------------------------------------------------------------------- 172//---------------------------------------------------------------------------
173// Function: get_handshake 173// Function: get_handshake
174// 174//
175// Parameters: struct ft1000_device - device structure 175// Parameters: struct ft1000_usb - device structure
176// u16 expected_value - the handshake value expected 176// u16 expected_value - the handshake value expected
177// 177//
178// Returns: handshakevalue - success 178// Returns: handshakevalue - success
@@ -183,12 +183,11 @@ static u32 check_usb_db (struct ft1000_device *ft1000dev)
183// Notes: 183// Notes:
184// 184//
185//--------------------------------------------------------------------------- 185//---------------------------------------------------------------------------
186static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value) 186static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value)
187{ 187{
188 u16 handshake; 188 u16 handshake;
189 int loopcnt; 189 int loopcnt;
190 u32 status = 0; 190 u32 status = 0;
191 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
192 191
193 loopcnt = 0; 192 loopcnt = 0;
194 193
@@ -196,10 +195,10 @@ static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value)
196 /* Need to clear downloader doorbell if Hartley ASIC */ 195 /* Need to clear downloader doorbell if Hartley ASIC */
197 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_RX, 196 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_RX,
198 FT1000_REG_DOORBELL); 197 FT1000_REG_DOORBELL);
199 if (pft1000info->fcodeldr) { 198 if (ft1000dev->fcodeldr) {
200 DEBUG(" get_handshake: fcodeldr is %d\n", 199 DEBUG(" get_handshake: fcodeldr is %d\n",
201 pft1000info->fcodeldr); 200 ft1000dev->fcodeldr);
202 pft1000info->fcodeldr = 0; 201 ft1000dev->fcodeldr = 0;
203 status = check_usb_db(ft1000dev); 202 status = check_usb_db(ft1000dev);
204 if (status != STATUS_SUCCESS) { 203 if (status != STATUS_SUCCESS) {
205 DEBUG("get_handshake: check_usb_db failed\n"); 204 DEBUG("get_handshake: check_usb_db failed\n");
@@ -233,7 +232,7 @@ static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value)
233//--------------------------------------------------------------------------- 232//---------------------------------------------------------------------------
234// Function: put_handshake 233// Function: put_handshake
235// 234//
236// Parameters: struct ft1000_device - device structure 235// Parameters: struct ft1000_usb - device structure
237// u16 handshake_value - handshake to be written 236// u16 handshake_value - handshake to be written
238// 237//
239// Returns: none 238// Returns: none
@@ -244,7 +243,7 @@ static u16 get_handshake(struct ft1000_device *ft1000dev, u16 expected_value)
244// Notes: 243// Notes:
245// 244//
246//--------------------------------------------------------------------------- 245//---------------------------------------------------------------------------
247static void put_handshake(struct ft1000_device *ft1000dev,u16 handshake_value) 246static void put_handshake(struct ft1000_usb *ft1000dev,u16 handshake_value)
248{ 247{
249 u32 tempx; 248 u32 tempx;
250 u16 tempword; 249 u16 tempword;
@@ -263,36 +262,35 @@ static void put_handshake(struct ft1000_device *ft1000dev,u16 handshake_value)
263 FT1000_REG_DOORBELL); 262 FT1000_REG_DOORBELL);
264} 263}
265 264
266static u16 get_handshake_usb(struct ft1000_device *ft1000dev, u16 expected_value) 265static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value)
267{ 266{
268 u16 handshake; 267 u16 handshake;
269 int loopcnt; 268 int loopcnt;
270 u16 temp; 269 u16 temp;
271 u32 status = 0; 270 u32 status = 0;
272 271
273 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
274 loopcnt = 0; 272 loopcnt = 0;
275 handshake = 0; 273 handshake = 0;
276 274
277 while (loopcnt < 100) { 275 while (loopcnt < 100) {
278 if (pft1000info->usbboot == 2) { 276 if (ft1000dev->usbboot == 2) {
279 status = ft1000_read_dpram32(ft1000dev, 0, 277 status = ft1000_read_dpram32(ft1000dev, 0,
280 (u8 *)&(pft1000info->tempbuf[0]), 64); 278 (u8 *)&(ft1000dev->tempbuf[0]), 64);
281 for (temp = 0; temp < 16; temp++) { 279 for (temp = 0; temp < 16; temp++) {
282 DEBUG("tempbuf %d = 0x%x\n", temp, 280 DEBUG("tempbuf %d = 0x%x\n", temp,
283 pft1000info->tempbuf[temp]); 281 ft1000dev->tempbuf[temp]);
284 } 282 }
285 status = ft1000_read_dpram16(ft1000dev, 283 status = ft1000_read_dpram16(ft1000dev,
286 DWNLD_MAG1_HANDSHAKE_LOC, 284 DWNLD_MAG1_HANDSHAKE_LOC,
287 (u8 *)&handshake, 1); 285 (u8 *)&handshake, 1);
288 DEBUG("handshake from read_dpram16 = 0x%x\n", 286 DEBUG("handshake from read_dpram16 = 0x%x\n",
289 handshake); 287 handshake);
290 if (pft1000info->dspalive == pft1000info->tempbuf[6]) { 288 if (ft1000dev->dspalive == ft1000dev->tempbuf[6]) {
291 handshake = 0; 289 handshake = 0;
292 } else { 290 } else {
293 handshake = pft1000info->tempbuf[1]; 291 handshake = ft1000dev->tempbuf[1];
294 pft1000info->dspalive = 292 ft1000dev->dspalive =
295 pft1000info->tempbuf[6]; 293 ft1000dev->tempbuf[6];
296 } 294 }
297 } else { 295 } else {
298 status = ft1000_read_dpram16(ft1000dev, 296 status = ft1000_read_dpram16(ft1000dev,
@@ -311,7 +309,7 @@ static u16 get_handshake_usb(struct ft1000_device *ft1000dev, u16 expected_value
311 return HANDSHAKE_TIMEOUT_VALUE; 309 return HANDSHAKE_TIMEOUT_VALUE;
312} 310}
313 311
314static void put_handshake_usb(struct ft1000_device *ft1000dev,u16 handshake_value) 312static void put_handshake_usb(struct ft1000_usb *ft1000dev,u16 handshake_value)
315{ 313{
316 int i; 314 int i;
317 315
@@ -321,7 +319,7 @@ static void put_handshake_usb(struct ft1000_device *ft1000dev,u16 handshake_valu
321//--------------------------------------------------------------------------- 319//---------------------------------------------------------------------------
322// Function: get_request_type 320// Function: get_request_type
323// 321//
324// Parameters: struct ft1000_device - device structure 322// Parameters: struct ft1000_usb - device structure
325// 323//
326// Returns: request type - success 324// Returns: request type - success
327// 325//
@@ -330,15 +328,14 @@ static void put_handshake_usb(struct ft1000_device *ft1000dev,u16 handshake_valu
330// Notes: 328// Notes:
331// 329//
332//--------------------------------------------------------------------------- 330//---------------------------------------------------------------------------
333static u16 get_request_type(struct ft1000_device *ft1000dev) 331static u16 get_request_type(struct ft1000_usb *ft1000dev)
334{ 332{
335 u16 request_type; 333 u16 request_type;
336 u32 status; 334 u32 status;
337 u16 tempword; 335 u16 tempword;
338 u32 tempx; 336 u32 tempx;
339 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
340 337
341 if (pft1000info->bootmode == 1) { 338 if (ft1000dev->bootmode == 1) {
342 status = fix_ft1000_read_dpram32(ft1000dev, 339 status = fix_ft1000_read_dpram32(ft1000dev,
343 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); 340 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
344 tempx = ntohl(tempx); 341 tempx = ntohl(tempx);
@@ -354,22 +351,21 @@ static u16 get_request_type(struct ft1000_device *ft1000dev)
354 return request_type; 351 return request_type;
355} 352}
356 353
357static u16 get_request_type_usb(struct ft1000_device *ft1000dev) 354static u16 get_request_type_usb(struct ft1000_usb *ft1000dev)
358{ 355{
359 u16 request_type; 356 u16 request_type;
360 u32 status; 357 u32 status;
361 u16 tempword; 358 u16 tempword;
362 u32 tempx; 359 u32 tempx;
363 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
364 360
365 if (pft1000info->bootmode == 1) { 361 if (ft1000dev->bootmode == 1) {
366 status = fix_ft1000_read_dpram32(ft1000dev, 362 status = fix_ft1000_read_dpram32(ft1000dev,
367 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); 363 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
368 tempx = ntohl(tempx); 364 tempx = ntohl(tempx);
369 } else { 365 } else {
370 if (pft1000info->usbboot == 2) { 366 if (ft1000dev->usbboot == 2) {
371 tempx = pft1000info->tempbuf[2]; 367 tempx = ft1000dev->tempbuf[2];
372 tempword = pft1000info->tempbuf[3]; 368 tempword = ft1000dev->tempbuf[3];
373 } else { 369 } else {
374 tempx = 0; 370 tempx = 0;
375 status = ft1000_read_dpram16(ft1000dev, 371 status = ft1000_read_dpram16(ft1000dev,
@@ -387,7 +383,7 @@ static u16 get_request_type_usb(struct ft1000_device *ft1000dev)
387//--------------------------------------------------------------------------- 383//---------------------------------------------------------------------------
388// Function: get_request_value 384// Function: get_request_value
389// 385//
390// Parameters: struct ft1000_device - device structure 386// Parameters: struct ft1000_usb - device structure
391// 387//
392// Returns: request value - success 388// Returns: request value - success
393// 389//
@@ -396,14 +392,13 @@ static u16 get_request_type_usb(struct ft1000_device *ft1000dev)
396// Notes: 392// Notes:
397// 393//
398//--------------------------------------------------------------------------- 394//---------------------------------------------------------------------------
399static long get_request_value(struct ft1000_device *ft1000dev) 395static long get_request_value(struct ft1000_usb *ft1000dev)
400{ 396{
401 u32 value; 397 u32 value;
402 u16 tempword; 398 u16 tempword;
403 u32 status; 399 u32 status;
404 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
405 400
406 if (pft1000info->bootmode == 1) { 401 if (ft1000dev->bootmode == 1) {
407 status = fix_ft1000_read_dpram32(ft1000dev, 402 status = fix_ft1000_read_dpram32(ft1000dev,
408 DWNLD_MAG1_SIZE_LOC, (u8 *)&value); 403 DWNLD_MAG1_SIZE_LOC, (u8 *)&value);
409 value = ntohl(value); 404 value = ntohl(value);
@@ -424,7 +419,7 @@ static long get_request_value(struct ft1000_device *ft1000dev)
424//--------------------------------------------------------------------------- 419//---------------------------------------------------------------------------
425// Function: put_request_value 420// Function: put_request_value
426// 421//
427// Parameters: struct ft1000_device - device structure 422// Parameters: struct ft1000_usb - device structure
428// long lvalue - value to be put into DPRAM location DWNLD_MAG1_SIZE_LOC 423// long lvalue - value to be put into DPRAM location DWNLD_MAG1_SIZE_LOC
429// 424//
430// Returns: none 425// Returns: none
@@ -434,7 +429,7 @@ static long get_request_value(struct ft1000_device *ft1000dev)
434// Notes: 429// Notes:
435// 430//
436//--------------------------------------------------------------------------- 431//---------------------------------------------------------------------------
437static void put_request_value(struct ft1000_device *ft1000dev, long lvalue) 432static void put_request_value(struct ft1000_usb *ft1000dev, long lvalue)
438{ 433{
439 u32 tempx; 434 u32 tempx;
440 u32 status; 435 u32 status;
@@ -485,7 +480,7 @@ static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset)
485//--------------------------------------------------------------------------- 480//---------------------------------------------------------------------------
486// Function: write_blk 481// Function: write_blk
487// 482//
488// Parameters: struct ft1000_device - device structure 483// Parameters: struct ft1000_usb - device structure
489// u16 **pUsFile - DSP image file pointer in u16 484// u16 **pUsFile - DSP image file pointer in u16
490// u8 **pUcFile - DSP image file pointer in u8 485// u8 **pUcFile - DSP image file pointer in u8
491// long word_length - length of the buffer to be written 486// long word_length - length of the buffer to be written
@@ -499,7 +494,7 @@ static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset)
499// Notes: 494// Notes:
500// 495//
501//--------------------------------------------------------------------------- 496//---------------------------------------------------------------------------
502static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length) 497static u32 write_blk (struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile, long word_length)
503{ 498{
504 u32 Status = STATUS_SUCCESS; 499 u32 Status = STATUS_SUCCESS;
505 u16 dpram; 500 u16 dpram;
@@ -507,7 +502,6 @@ static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFi
507 u16 tempword; 502 u16 tempword;
508 u16 tempbuffer[64]; 503 u16 tempbuffer[64];
509 u16 resultbuffer[64]; 504 u16 resultbuffer[64];
510 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
511 505
512 //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); 506 //DEBUG("FT1000:download:start word_length = %d\n",(int)word_length);
513 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC; 507 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
@@ -548,7 +542,7 @@ static u32 write_blk (struct ft1000_device *ft1000dev, u16 **pUsFile, u8 **pUcFi
548 //DEBUG("write_blk: loopcnt is %d\n", loopcnt); 542 //DEBUG("write_blk: loopcnt is %d\n", loopcnt);
549 //DEBUG("write_blk: bootmode = %d\n", bootmode); 543 //DEBUG("write_blk: bootmode = %d\n", bootmode);
550 //DEBUG("write_blk: dpram = %x\n", dpram); 544 //DEBUG("write_blk: dpram = %x\n", dpram);
551 if (pft1000info->bootmode == 0) 545 if (ft1000dev->bootmode == 0)
552 { 546 {
553 if (dpram >= 0x3F4) 547 if (dpram >= 0x3F4)
554 Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 8); 548 Status = ft1000_write_dpram32 (ft1000dev, dpram, (u8 *)&tempbuffer[0], 8);
@@ -625,7 +619,7 @@ static void usb_dnld_complete (struct urb *urb)
625//--------------------------------------------------------------------------- 619//---------------------------------------------------------------------------
626// Function: write_blk_fifo 620// Function: write_blk_fifo
627// 621//
628// Parameters: struct ft1000_device - device structure 622// Parameters: struct ft1000_usb - device structure
629// u16 **pUsFile - DSP image file pointer in u16 623// u16 **pUsFile - DSP image file pointer in u16
630// u8 **pUcFile - DSP image file pointer in u8 624// u8 **pUcFile - DSP image file pointer in u8
631// long word_length - length of the buffer to be written 625// long word_length - length of the buffer to be written
@@ -639,7 +633,7 @@ static void usb_dnld_complete (struct urb *urb)
639// Notes: 633// Notes:
640// 634//
641//--------------------------------------------------------------------------- 635//---------------------------------------------------------------------------
642static u32 write_blk_fifo(struct ft1000_device *ft1000dev, u16 **pUsFile, 636static u32 write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile,
643 u8 **pUcFile, long word_length) 637 u8 **pUcFile, long word_length)
644{ 638{
645 u32 Status = STATUS_SUCCESS; 639 u32 Status = STATUS_SUCCESS;
@@ -682,7 +676,7 @@ static u32 write_blk_fifo(struct ft1000_device *ft1000dev, u16 **pUsFile,
682// Returns: status - return code 676// Returns: status - return code
683//--------------------------------------------------------------------------- 677//---------------------------------------------------------------------------
684 678
685u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, 679u16 scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
686 u32 FileLength) 680 u32 FileLength)
687{ 681{
688 u16 status = STATUS_SUCCESS; 682 u16 status = STATUS_SUCCESS;
@@ -718,9 +712,9 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
718 712
719 DEBUG("Entered scram_dnldr...\n"); 713 DEBUG("Entered scram_dnldr...\n");
720 714
721 pft1000info->fcodeldr = 0; 715 ft1000dev->fcodeldr = 0;
722 pft1000info->usbboot = 0; 716 ft1000dev->usbboot = 0;
723 pft1000info->dspalive = 0xffff; 717 ft1000dev->dspalive = 0xffff;
724 718
725 // 719 //
726 // Get version id of file, at first 4 bytes of file, for newer files. 720 // Get version id of file, at first 4 bytes of file, for newer files.
@@ -745,7 +739,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
745 switch (state) { 739 switch (state) {
746 case STATE_START_DWNLD: 740 case STATE_START_DWNLD:
747 DEBUG("FT1000:STATE_START_DWNLD\n"); 741 DEBUG("FT1000:STATE_START_DWNLD\n");
748 if (pft1000info->usbboot) 742 if (ft1000dev->usbboot)
749 handshake = 743 handshake =
750 get_handshake_usb(ft1000dev, 744 get_handshake_usb(ft1000dev,
751 HANDSHAKE_DSP_BL_READY); 745 HANDSHAKE_DSP_BL_READY);
@@ -771,7 +765,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
771 765
772 case STATE_BOOT_DWNLD: 766 case STATE_BOOT_DWNLD:
773 DEBUG("FT1000:STATE_BOOT_DWNLD\n"); 767 DEBUG("FT1000:STATE_BOOT_DWNLD\n");
774 pft1000info->bootmode = 1; 768 ft1000dev->bootmode = 1;
775 handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST); 769 handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST);
776 if (handshake == HANDSHAKE_REQUEST) { 770 if (handshake == HANDSHAKE_REQUEST) {
777 /* 771 /*
@@ -797,7 +791,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
797 //DEBUG("FT1000:download:s_file = 0x%8x\n", (int)s_file); 791 //DEBUG("FT1000:download:s_file = 0x%8x\n", (int)s_file);
798 //DEBUG("FT1000:download:c_file = 0x%8x\n", (int)c_file); 792 //DEBUG("FT1000:download:c_file = 0x%8x\n", (int)c_file);
799 state = STATE_CODE_DWNLD; 793 state = STATE_CODE_DWNLD;
800 pft1000info->fcodeldr = 1; 794 ft1000dev->fcodeldr = 1;
801 break; 795 break;
802 case REQUEST_CODE_SEGMENT: 796 case REQUEST_CODE_SEGMENT:
803 //DEBUG("FT1000:REQUEST_CODE_SEGMENT\n"); 797 //DEBUG("FT1000:REQUEST_CODE_SEGMENT\n");
@@ -842,7 +836,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
842 status = STATUS_FAILURE; 836 status = STATUS_FAILURE;
843 break; 837 break;
844 } 838 }
845 if (pft1000info->usbboot) 839 if (ft1000dev->usbboot)
846 put_handshake_usb(ft1000dev, 840 put_handshake_usb(ft1000dev,
847 HANDSHAKE_RESPONSE); 841 HANDSHAKE_RESPONSE);
848 else 842 else
@@ -858,8 +852,8 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
858 852
859 case STATE_CODE_DWNLD: 853 case STATE_CODE_DWNLD:
860 //DEBUG("FT1000:STATE_CODE_DWNLD\n"); 854 //DEBUG("FT1000:STATE_CODE_DWNLD\n");
861 pft1000info->bootmode = 0; 855 ft1000dev->bootmode = 0;
862 if (pft1000info->usbboot) 856 if (ft1000dev->usbboot)
863 handshake = 857 handshake =
864 get_handshake_usb(ft1000dev, 858 get_handshake_usb(ft1000dev,
865 HANDSHAKE_REQUEST); 859 HANDSHAKE_REQUEST);
@@ -870,7 +864,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
870 /* 864 /*
871 * Get type associated with the request. 865 * Get type associated with the request.
872 */ 866 */
873 if (pft1000info->usbboot) 867 if (ft1000dev->usbboot)
874 request = 868 request =
875 get_request_type_usb(ft1000dev); 869 get_request_type_usb(ft1000dev);
876 else 870 else
@@ -916,7 +910,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
916 } 910 }
917 break; 911 break;
918 case REQUEST_DONE_CL: 912 case REQUEST_DONE_CL:
919 pft1000info->usbboot = 3; 913 ft1000dev->usbboot = 3;
920 /* Reposition ptrs to beginning of provisioning section */ 914 /* Reposition ptrs to beginning of provisioning section */
921 s_file = 915 s_file =
922 (u16 *) (pFileStart + 916 (u16 *) (pFileStart +
@@ -965,9 +959,9 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
965 959
966 write_blk_fifo(ft1000dev, &s_file, 960 write_blk_fifo(ft1000dev, &s_file,
967 &c_file, word_length); 961 &c_file, word_length);
968 if (pft1000info->usbboot == 0) 962 if (ft1000dev->usbboot == 0)
969 pft1000info->usbboot++; 963 ft1000dev->usbboot++;
970 if (pft1000info->usbboot == 1) { 964 if (ft1000dev->usbboot == 1) {
971 tempword = 0; 965 tempword = 0;
972 ft1000_write_dpram16(ft1000dev, 966 ft1000_write_dpram16(ft1000dev,
973 DWNLD_MAG1_PS_HDR_LOC, 967 DWNLD_MAG1_PS_HDR_LOC,
@@ -1117,7 +1111,7 @@ u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart,
1117 status = STATUS_FAILURE; 1111 status = STATUS_FAILURE;
1118 break; 1112 break;
1119 } 1113 }
1120 if (pft1000info->usbboot) 1114 if (ft1000dev->usbboot)
1121 put_handshake_usb(ft1000dev, 1115 put_handshake_usb(ft1000dev,
1122 HANDSHAKE_RESPONSE); 1116 HANDSHAKE_RESPONSE);
1123 else 1117 else
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
index 809fa4886961..9b8fed7b405b 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
@@ -29,12 +29,12 @@
29 29
30//#define JDEBUG 30//#define JDEBUG
31 31
32static int ft1000_reset(struct net_device *ft1000dev); 32static int ft1000_reset(void *ft1000dev);
33static int ft1000_submit_rx_urb(struct ft1000_info *info); 33static int ft1000_submit_rx_urb(struct ft1000_info *info);
34static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev); 34static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev);
35static int ft1000_open (struct net_device *dev); 35static int ft1000_open (struct net_device *dev);
36static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev); 36static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev);
37static int ft1000_chkcard (struct ft1000_device *dev); 37static int ft1000_chkcard (struct ft1000_usb *dev);
38 38
39static u8 tempbuffer[1600]; 39static u8 tempbuffer[1600];
40 40
@@ -43,7 +43,7 @@ static u8 tempbuffer[1600];
43//--------------------------------------------------------------------------- 43//---------------------------------------------------------------------------
44// Function: ft1000_control 44// Function: ft1000_control
45// 45//
46// Parameters: ft1000_device - device structure 46// Parameters: ft1000_usb - device structure
47// pipe - usb control message pipe 47// pipe - usb control message pipe
48// request - control request 48// request - control request
49// requesttype - control message request type 49// requesttype - control message request type
@@ -61,7 +61,7 @@ static u8 tempbuffer[1600];
61// Notes: 61// Notes:
62// 62//
63//--------------------------------------------------------------------------- 63//---------------------------------------------------------------------------
64static int ft1000_control(struct ft1000_device *ft1000dev, unsigned int pipe, 64static int ft1000_control(struct ft1000_usb *ft1000dev, unsigned int pipe,
65 u8 request, u8 requesttype, u16 value, u16 index, 65 u8 request, u8 requesttype, u16 value, u16 index,
66 void *data, u16 size, int timeout) 66 void *data, u16 size, int timeout)
67{ 67{
@@ -84,7 +84,7 @@ static int ft1000_control(struct ft1000_device *ft1000dev, unsigned int pipe,
84//--------------------------------------------------------------------------- 84//---------------------------------------------------------------------------
85// Function: ft1000_read_register 85// Function: ft1000_read_register
86// 86//
87// Parameters: ft1000_device - device structure 87// Parameters: ft1000_usb - device structure
88// Data - data buffer to hold the value read 88// Data - data buffer to hold the value read
89// nRegIndex - register index 89// nRegIndex - register index
90// 90//
@@ -97,7 +97,7 @@ static int ft1000_control(struct ft1000_device *ft1000dev, unsigned int pipe,
97// 97//
98//--------------------------------------------------------------------------- 98//---------------------------------------------------------------------------
99 99
100int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, 100int ft1000_read_register(struct ft1000_usb *ft1000dev, u16* Data,
101 u16 nRegIndx) 101 u16 nRegIndx)
102{ 102{
103 int ret = STATUS_SUCCESS; 103 int ret = STATUS_SUCCESS;
@@ -118,7 +118,7 @@ int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data,
118//--------------------------------------------------------------------------- 118//---------------------------------------------------------------------------
119// Function: ft1000_write_register 119// Function: ft1000_write_register
120// 120//
121// Parameters: ft1000_device - device structure 121// Parameters: ft1000_usb - device structure
122// value - value to write into a register 122// value - value to write into a register
123// nRegIndex - register index 123// nRegIndex - register index
124// 124//
@@ -130,7 +130,7 @@ int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data,
130// Notes: 130// Notes:
131// 131//
132//--------------------------------------------------------------------------- 132//---------------------------------------------------------------------------
133int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value, 133int ft1000_write_register(struct ft1000_usb *ft1000dev, u16 value,
134 u16 nRegIndx) 134 u16 nRegIndx)
135{ 135{
136 int ret = STATUS_SUCCESS; 136 int ret = STATUS_SUCCESS;
@@ -151,7 +151,7 @@ int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value,
151//--------------------------------------------------------------------------- 151//---------------------------------------------------------------------------
152// Function: ft1000_read_dpram32 152// Function: ft1000_read_dpram32
153// 153//
154// Parameters: ft1000_device - device structure 154// Parameters: ft1000_usb - device structure
155// indx - starting address to read 155// indx - starting address to read
156// buffer - data buffer to hold the data read 156// buffer - data buffer to hold the data read
157// cnt - number of byte read from DPRAM 157// cnt - number of byte read from DPRAM
@@ -165,7 +165,7 @@ int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value,
165// 165//
166//--------------------------------------------------------------------------- 166//---------------------------------------------------------------------------
167 167
168int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, 168int ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer,
169 u16 cnt) 169 u16 cnt)
170{ 170{
171 int ret = STATUS_SUCCESS; 171 int ret = STATUS_SUCCESS;
@@ -186,7 +186,7 @@ int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
186//--------------------------------------------------------------------------- 186//---------------------------------------------------------------------------
187// Function: ft1000_write_dpram32 187// Function: ft1000_write_dpram32
188// 188//
189// Parameters: ft1000_device - device structure 189// Parameters: ft1000_usb - device structure
190// indx - starting address to write the data 190// indx - starting address to write the data
191// buffer - data buffer to write into DPRAM 191// buffer - data buffer to write into DPRAM
192// cnt - number of bytes to write 192// cnt - number of bytes to write
@@ -199,7 +199,7 @@ int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
199// Notes: 199// Notes:
200// 200//
201//--------------------------------------------------------------------------- 201//---------------------------------------------------------------------------
202int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, 202int ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer,
203 u16 cnt) 203 u16 cnt)
204{ 204{
205 int ret = STATUS_SUCCESS; 205 int ret = STATUS_SUCCESS;
@@ -223,7 +223,7 @@ int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
223//--------------------------------------------------------------------------- 223//---------------------------------------------------------------------------
224// Function: ft1000_read_dpram16 224// Function: ft1000_read_dpram16
225// 225//
226// Parameters: ft1000_device - device structure 226// Parameters: ft1000_usb - device structure
227// indx - starting address to read 227// indx - starting address to read
228// buffer - data buffer to hold the data read 228// buffer - data buffer to hold the data read
229// hightlow - high or low 16 bit word 229// hightlow - high or low 16 bit word
@@ -236,7 +236,7 @@ int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
236// Notes: 236// Notes:
237// 237//
238//--------------------------------------------------------------------------- 238//---------------------------------------------------------------------------
239int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, 239int ft1000_read_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer,
240 u8 highlow) 240 u8 highlow)
241{ 241{
242 int ret = STATUS_SUCCESS; 242 int ret = STATUS_SUCCESS;
@@ -263,7 +263,7 @@ int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
263//--------------------------------------------------------------------------- 263//---------------------------------------------------------------------------
264// Function: ft1000_write_dpram16 264// Function: ft1000_write_dpram16
265// 265//
266// Parameters: ft1000_device - device structure 266// Parameters: ft1000_usb - device structure
267// indx - starting address to write the data 267// indx - starting address to write the data
268// value - 16bits value to write 268// value - 16bits value to write
269// hightlow - high or low 16 bit word 269// hightlow - high or low 16 bit word
@@ -276,7 +276,7 @@ int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
276// Notes: 276// Notes:
277// 277//
278//--------------------------------------------------------------------------- 278//---------------------------------------------------------------------------
279int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u8 highlow) 279int ft1000_write_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u16 value, u8 highlow)
280{ 280{
281 int ret = STATUS_SUCCESS; 281 int ret = STATUS_SUCCESS;
282 u8 request; 282 u8 request;
@@ -302,7 +302,7 @@ int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u
302//--------------------------------------------------------------------------- 302//---------------------------------------------------------------------------
303// Function: fix_ft1000_read_dpram32 303// Function: fix_ft1000_read_dpram32
304// 304//
305// Parameters: ft1000_device - device structure 305// Parameters: ft1000_usb - device structure
306// indx - starting address to read 306// indx - starting address to read
307// buffer - data buffer to hold the data read 307// buffer - data buffer to hold the data read
308// 308//
@@ -315,7 +315,7 @@ int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u
315// Notes: 315// Notes:
316// 316//
317//--------------------------------------------------------------------------- 317//---------------------------------------------------------------------------
318int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, 318int fix_ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx,
319 u8 *buffer) 319 u8 *buffer)
320{ 320{
321 u8 buf[16]; 321 u8 buf[16];
@@ -346,7 +346,7 @@ int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx,
346//--------------------------------------------------------------------------- 346//---------------------------------------------------------------------------
347// Function: fix_ft1000_write_dpram32 347// Function: fix_ft1000_write_dpram32
348// 348//
349// Parameters: ft1000_device - device structure 349// Parameters: ft1000_usb - device structure
350// indx - starting address to write 350// indx - starting address to write
351// buffer - data buffer to write 351// buffer - data buffer to write
352// 352//
@@ -359,7 +359,7 @@ int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx,
359// Notes: 359// Notes:
360// 360//
361//--------------------------------------------------------------------------- 361//---------------------------------------------------------------------------
362int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer) 362int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer)
363{ 363{
364 u16 pos1; 364 u16 pos1;
365 u16 pos2; 365 u16 pos2;
@@ -426,7 +426,7 @@ int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buff
426// 426//
427// Returns: None 427// Returns: None
428//----------------------------------------------------------------------- 428//-----------------------------------------------------------------------
429static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value) 429static void card_reset_dsp(struct ft1000_usb *ft1000dev, bool value)
430{ 430{
431 u16 status = STATUS_SUCCESS; 431 u16 status = STATUS_SUCCESS;
432 u16 tempword; 432 u16 tempword;
@@ -465,7 +465,7 @@ static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value)
465//--------------------------------------------------------------------------- 465//---------------------------------------------------------------------------
466// Function: card_send_command 466// Function: card_send_command
467// 467//
468// Parameters: ft1000_device - device structure 468// Parameters: ft1000_usb - device structure
469// ptempbuffer - command buffer 469// ptempbuffer - command buffer
470// size - command buffer size 470// size - command buffer size
471// 471//
@@ -477,7 +477,7 @@ static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value)
477// Notes: 477// Notes:
478// 478//
479//--------------------------------------------------------------------------- 479//---------------------------------------------------------------------------
480void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer, 480void card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer,
481 int size) 481 int size)
482{ 482{
483 unsigned short temp; 483 unsigned short temp;
@@ -524,7 +524,7 @@ void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer,
524// 524//
525// Returns: None 525// Returns: None
526//----------------------------------------------------------------------- 526//-----------------------------------------------------------------------
527int dsp_reload(struct ft1000_device *ft1000dev) 527int dsp_reload(struct ft1000_usb *ft1000dev)
528{ 528{
529 u16 status; 529 u16 status;
530 u16 tempword; 530 u16 tempword;
@@ -588,7 +588,7 @@ int dsp_reload(struct ft1000_device *ft1000dev)
588static void ft1000_reset_asic(struct net_device *dev) 588static void ft1000_reset_asic(struct net_device *dev)
589{ 589{
590 struct ft1000_info *info = netdev_priv(dev); 590 struct ft1000_info *info = netdev_priv(dev);
591 struct ft1000_device *ft1000dev = info->pFt1000Dev; 591 struct ft1000_usb *ft1000dev = info->priv;
592 u16 tempword; 592 u16 tempword;
593 593
594 DEBUG("ft1000_hw:ft1000_reset_asic called\n"); 594 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
@@ -627,15 +627,15 @@ static void ft1000_reset_asic(struct net_device *dev)
627static int ft1000_reset_card(struct net_device *dev) 627static int ft1000_reset_card(struct net_device *dev)
628{ 628{
629 struct ft1000_info *info = netdev_priv(dev); 629 struct ft1000_info *info = netdev_priv(dev);
630 struct ft1000_device *ft1000dev = info->pFt1000Dev; 630 struct ft1000_usb *ft1000dev = info->priv;
631 u16 tempword; 631 u16 tempword;
632 struct prov_record *ptr; 632 struct prov_record *ptr;
633 633
634 DEBUG("ft1000_hw:ft1000_reset_card called.....\n"); 634 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
635 635
636 info->fCondResetPend = 1; 636 ft1000dev->fCondResetPend = 1;
637 info->CardReady = 0; 637 info->CardReady = 0;
638 info->fProvComplete = 0; 638 ft1000dev->fProvComplete = 0;
639 639
640 /* Make sure we free any memory reserve for provisioning */ 640 /* Make sure we free any memory reserve for provisioning */
641 while (list_empty(&info->prov_list) == 0) { 641 while (list_empty(&info->prov_list) == 0) {
@@ -666,7 +666,7 @@ static int ft1000_reset_card(struct net_device *dev)
666 666
667 info->CardReady = 1; 667 info->CardReady = 1;
668 668
669 info->fCondResetPend = 0; 669 ft1000dev->fCondResetPend = 0;
670 670
671 return TRUE; 671 return TRUE;
672} 672}
@@ -694,7 +694,7 @@ static const struct net_device_ops ftnet_ops =
694// Notes: 694// Notes:
695// 695//
696//--------------------------------------------------------------------------- 696//---------------------------------------------------------------------------
697int init_ft1000_netdev(struct ft1000_device *ft1000dev) 697int init_ft1000_netdev(struct ft1000_usb *ft1000dev)
698{ 698{
699 struct net_device *netdev; 699 struct net_device *netdev;
700 struct ft1000_info *pInfo = NULL; 700 struct ft1000_info *pInfo = NULL;
@@ -702,7 +702,7 @@ int init_ft1000_netdev(struct ft1000_device *ft1000dev)
702 int i, ret_val; 702 int i, ret_val;
703 struct list_head *cur, *tmp; 703 struct list_head *cur, *tmp;
704 char card_nr[2]; 704 char card_nr[2];
705 unsigned long gCardIndex = 0; 705 u8 gCardIndex = 0;
706 706
707 DEBUG("Enter init_ft1000_netdev...\n"); 707 DEBUG("Enter init_ft1000_netdev...\n");
708 708
@@ -723,14 +723,14 @@ int init_ft1000_netdev(struct ft1000_device *ft1000dev)
723 if (strncmp(netdev->name, "eth", 3) == 0) { 723 if (strncmp(netdev->name, "eth", 3) == 0) {
724 card_nr[0] = netdev->name[3]; 724 card_nr[0] = netdev->name[3];
725 card_nr[1] = '\0'; 725 card_nr[1] = '\0';
726 ret_val = strict_strtoul(card_nr, 10, &gCardIndex); 726 ret_val = kstrtou8(card_nr, 10, &gCardIndex);
727 if (ret_val) { 727 if (ret_val) {
728 printk(KERN_ERR "Can't parse netdev\n"); 728 printk(KERN_ERR "Can't parse netdev\n");
729 goto err_net; 729 goto err_net;
730 } 730 }
731 731
732 pInfo->CardNumber = gCardIndex; 732 ft1000dev->CardNumber = gCardIndex;
733 DEBUG("card number = %d\n", pInfo->CardNumber); 733 DEBUG("card number = %d\n", ft1000dev->CardNumber);
734 } else { 734 } else {
735 printk(KERN_ERR "ft1000: Invalid device name\n"); 735 printk(KERN_ERR "ft1000: Invalid device name\n");
736 ret_val = -ENXIO; 736 ret_val = -ENXIO;
@@ -740,27 +740,27 @@ int init_ft1000_netdev(struct ft1000_device *ft1000dev)
740 memset(&pInfo->stats, 0, sizeof(struct net_device_stats)); 740 memset(&pInfo->stats, 0, sizeof(struct net_device_stats));
741 741
742 spin_lock_init(&pInfo->dpram_lock); 742 spin_lock_init(&pInfo->dpram_lock);
743 pInfo->pFt1000Dev = ft1000dev; 743 pInfo->priv = ft1000dev;
744 pInfo->DrvErrNum = 0; 744 pInfo->DrvErrNum = 0;
745 pInfo->registered = 1; 745 pInfo->registered = 1;
746 pInfo->ft1000_reset = ft1000_reset; 746 pInfo->ft1000_reset = ft1000_reset;
747 pInfo->mediastate = 0; 747 pInfo->mediastate = 0;
748 pInfo->fifo_cnt = 0; 748 pInfo->fifo_cnt = 0;
749 pInfo->DeviceCreated = FALSE; 749 ft1000dev->DeviceCreated = FALSE;
750 pInfo->CardReady = 0; 750 pInfo->CardReady = 0;
751 pInfo->DSP_TIME[0] = 0; 751 pInfo->DSP_TIME[0] = 0;
752 pInfo->DSP_TIME[1] = 0; 752 pInfo->DSP_TIME[1] = 0;
753 pInfo->DSP_TIME[2] = 0; 753 pInfo->DSP_TIME[2] = 0;
754 pInfo->DSP_TIME[3] = 0; 754 pInfo->DSP_TIME[3] = 0;
755 pInfo->fAppMsgPend = 0; 755 ft1000dev->fAppMsgPend = 0;
756 pInfo->fCondResetPend = 0; 756 ft1000dev->fCondResetPend = 0;
757 pInfo->usbboot = 0; 757 ft1000dev->usbboot = 0;
758 pInfo->dspalive = 0; 758 ft1000dev->dspalive = 0;
759 memset(&pInfo->tempbuf[0], 0, sizeof(pInfo->tempbuf)); 759 memset(&ft1000dev->tempbuf[0], 0, sizeof(ft1000dev->tempbuf));
760 760
761 INIT_LIST_HEAD(&pInfo->prov_list); 761 INIT_LIST_HEAD(&pInfo->prov_list);
762 762
763 INIT_LIST_HEAD(&pInfo->nodes.list); 763 INIT_LIST_HEAD(&ft1000dev->nodes.list);
764 764
765 netdev->netdev_ops = &ftnet_ops; 765 netdev->netdev_ops = &ftnet_ops;
766 766
@@ -822,7 +822,7 @@ err_net:
822// Notes: 822// Notes:
823// 823//
824//--------------------------------------------------------------------------- 824//---------------------------------------------------------------------------
825int reg_ft1000_netdev(struct ft1000_device *ft1000dev, 825int reg_ft1000_netdev(struct ft1000_usb *ft1000dev,
826 struct usb_interface *intf) 826 struct usb_interface *intf)
827{ 827{
828 struct net_device *netdev; 828 struct net_device *netdev;
@@ -854,7 +854,7 @@ int reg_ft1000_netdev(struct ft1000_device *ft1000dev,
854 return 0; 854 return 0;
855} 855}
856 856
857static int ft1000_reset(struct net_device *dev) 857int ft1000_reset(void *dev)
858{ 858{
859 ft1000_reset_card(dev); 859 ft1000_reset_card(dev);
860 return 0; 860 return 0;
@@ -876,7 +876,7 @@ static int ft1000_reset(struct net_device *dev)
876static void ft1000_usb_transmit_complete(struct urb *urb) 876static void ft1000_usb_transmit_complete(struct urb *urb)
877{ 877{
878 878
879 struct ft1000_device *ft1000dev = urb->context; 879 struct ft1000_usb *ft1000dev = urb->context;
880 880
881 if (urb->status) 881 if (urb->status)
882 pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status); 882 pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status);
@@ -902,7 +902,7 @@ static void ft1000_usb_transmit_complete(struct urb *urb)
902static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) 902static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len)
903{ 903{
904 struct ft1000_info *pInfo = netdev_priv(netdev); 904 struct ft1000_info *pInfo = netdev_priv(netdev);
905 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev; 905 struct ft1000_usb *pFt1000Dev = pInfo->priv;
906 906
907 int count, ret; 907 int count, ret;
908 u8 *t; 908 u8 *t;
@@ -981,7 +981,7 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len)
981static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) 981static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
982{ 982{
983 struct ft1000_info *pInfo = netdev_priv(dev); 983 struct ft1000_info *pInfo = netdev_priv(dev);
984 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev; 984 struct ft1000_usb *pFt1000Dev = pInfo->priv;
985 u8 *pdata; 985 u8 *pdata;
986 int maxlen, pipe; 986 int maxlen, pipe;
987 987
@@ -1039,7 +1039,7 @@ err:
1039static int ft1000_copy_up_pkt(struct urb *urb) 1039static int ft1000_copy_up_pkt(struct urb *urb)
1040{ 1040{
1041 struct ft1000_info *info = urb->context; 1041 struct ft1000_info *info = urb->context;
1042 struct ft1000_device *ft1000dev = info->pFt1000Dev; 1042 struct ft1000_usb *ft1000dev = info->priv;
1043 struct net_device *net = ft1000dev->net; 1043 struct net_device *net = ft1000dev->net;
1044 1044
1045 u16 tempword; 1045 u16 tempword;
@@ -1134,7 +1134,7 @@ static int ft1000_copy_up_pkt(struct urb *urb)
1134static int ft1000_submit_rx_urb(struct ft1000_info *info) 1134static int ft1000_submit_rx_urb(struct ft1000_info *info)
1135{ 1135{
1136 int result; 1136 int result;
1137 struct ft1000_device *pFt1000Dev = info->pFt1000Dev; 1137 struct ft1000_usb *pFt1000Dev = info->priv;
1138 1138
1139 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { 1139 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
1140 DEBUG("network driver is closed, return\n"); 1140 DEBUG("network driver is closed, return\n");
@@ -1177,9 +1177,10 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info)
1177static int ft1000_open(struct net_device *dev) 1177static int ft1000_open(struct net_device *dev)
1178{ 1178{
1179 struct ft1000_info *pInfo = netdev_priv(dev); 1179 struct ft1000_info *pInfo = netdev_priv(dev);
1180 struct ft1000_usb *pFt1000Dev = pInfo->priv;
1180 struct timeval tv; 1181 struct timeval tv;
1181 1182
1182 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber); 1183 DEBUG("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber);
1183 1184
1184 pInfo->stats.rx_bytes = 0; 1185 pInfo->stats.rx_bytes = 0;
1185 pInfo->stats.tx_bytes = 0; 1186 pInfo->stats.tx_bytes = 0;
@@ -1213,7 +1214,7 @@ static int ft1000_open(struct net_device *dev)
1213int ft1000_close(struct net_device *net) 1214int ft1000_close(struct net_device *net)
1214{ 1215{
1215 struct ft1000_info *pInfo = netdev_priv(net); 1216 struct ft1000_info *pInfo = netdev_priv(net);
1216 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev; 1217 struct ft1000_usb *ft1000dev = pInfo->priv;
1217 1218
1218 ft1000dev->status |= FT1000_STATUS_CLOSING; 1219 ft1000dev->status |= FT1000_STATUS_CLOSING;
1219 1220
@@ -1247,13 +1248,12 @@ static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1247// TRUE (device is present) 1248// TRUE (device is present)
1248// 1249//
1249//--------------------------------------------------------------------------- 1250//---------------------------------------------------------------------------
1250static int ft1000_chkcard(struct ft1000_device *dev) 1251static int ft1000_chkcard(struct ft1000_usb *dev)
1251{ 1252{
1252 u16 tempword; 1253 u16 tempword;
1253 u16 status; 1254 u16 status;
1254 struct ft1000_info *info = netdev_priv(dev->net);
1255 1255
1256 if (info->fCondResetPend) { 1256 if (dev->fCondResetPend) {
1257 DEBUG 1257 DEBUG
1258 ("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n"); 1258 ("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1259 return TRUE; 1259 return TRUE;
@@ -1293,7 +1293,7 @@ static int ft1000_chkcard(struct ft1000_device *dev)
1293// = 1 (successful) 1293// = 1 (successful)
1294// 1294//
1295//--------------------------------------------------------------------------- 1295//---------------------------------------------------------------------------
1296static bool ft1000_receive_cmd(struct ft1000_device *dev, u16 *pbuffer, 1296static bool ft1000_receive_cmd(struct ft1000_usb *dev, u16 *pbuffer,
1297 int maxsz, u16 *pnxtph) 1297 int maxsz, u16 *pnxtph)
1298{ 1298{
1299 u16 size, ret; 1299 u16 size, ret;
@@ -1360,7 +1360,7 @@ static bool ft1000_receive_cmd(struct ft1000_device *dev, u16 *pbuffer,
1360 1360
1361static int ft1000_dsp_prov(void *arg) 1361static int ft1000_dsp_prov(void *arg)
1362{ 1362{
1363 struct ft1000_device *dev = (struct ft1000_device *)arg; 1363 struct ft1000_usb *dev = (struct ft1000_usb *)arg;
1364 struct ft1000_info *info = netdev_priv(dev->net); 1364 struct ft1000_info *info = netdev_priv(dev->net);
1365 u16 tempword; 1365 u16 tempword;
1366 u16 len; 1366 u16 len;
@@ -1441,13 +1441,13 @@ static int ft1000_dsp_prov(void *arg)
1441 1441
1442 msleep(100); 1442 msleep(100);
1443 1443
1444 info->fProvComplete = 1; 1444 dev->fProvComplete = 1;
1445 info->CardReady = 1; 1445 info->CardReady = 1;
1446 1446
1447 return STATUS_SUCCESS; 1447 return STATUS_SUCCESS;
1448} 1448}
1449 1449
1450static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) 1450static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1451{ 1451{
1452 struct ft1000_info *info = netdev_priv(dev->net); 1452 struct ft1000_info *info = netdev_priv(dev->net);
1453 u16 msgtype; 1453 u16 msgtype;
@@ -1498,7 +1498,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1498 if (pmediamsg->state) { 1498 if (pmediamsg->state) {
1499 DEBUG("Media is up\n"); 1499 DEBUG("Media is up\n");
1500 if (info->mediastate == 0) { 1500 if (info->mediastate == 0) {
1501 if (info->NetDevRegDone) { 1501 if (dev->NetDevRegDone) {
1502 netif_wake_queue(dev-> 1502 netif_wake_queue(dev->
1503 net); 1503 net);
1504 } 1504 }
@@ -1508,7 +1508,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1508 DEBUG("Media is down\n"); 1508 DEBUG("Media is down\n");
1509 if (info->mediastate == 1) { 1509 if (info->mediastate == 1) {
1510 info->mediastate = 0; 1510 info->mediastate = 0;
1511 if (info->NetDevRegDone) { 1511 if (dev->NetDevRegDone) {
1512 } 1512 }
1513 info->ConTm = 0; 1513 info->ConTm = 0;
1514 } 1514 }
@@ -1567,12 +1567,12 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1567 * Send provisioning data to DSP 1567 * Send provisioning data to DSP
1568 */ 1568 */
1569 if (list_empty(&info->prov_list) == 0) { 1569 if (list_empty(&info->prov_list) == 0) {
1570 info->fProvComplete = 0; 1570 dev->fProvComplete = 0;
1571 status = ft1000_dsp_prov(dev); 1571 status = ft1000_dsp_prov(dev);
1572 if (status != STATUS_SUCCESS) 1572 if (status != STATUS_SUCCESS)
1573 goto out; 1573 goto out;
1574 } else { 1574 } else {
1575 info->fProvComplete = 1; 1575 dev->fProvComplete = 1;
1576 status = 1576 status =
1577 ft1000_write_register(dev, FT1000_DB_HB, 1577 ft1000_write_register(dev, FT1000_DB_HB,
1578 FT1000_REG_DOORBELL); 1578 FT1000_REG_DOORBELL);
@@ -1605,7 +1605,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1605 case DSP_GET_INFO:{ 1605 case DSP_GET_INFO:{
1606 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n"); 1606 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
1607 /* copy dsp info block to dsp */ 1607 /* copy dsp info block to dsp */
1608 info->DrvMsgPend = 1; 1608 dev->DrvMsgPend = 1;
1609 /* allow any outstanding ioctl to finish */ 1609 /* allow any outstanding ioctl to finish */
1610 mdelay(10); 1610 mdelay(10);
1611 status = 1611 status =
@@ -1667,7 +1667,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1667 status = 1667 status =
1668 ft1000_write_register(dev, FT1000_DB_DPRAM_TX, 1668 ft1000_write_register(dev, FT1000_DB_DPRAM_TX,
1669 FT1000_REG_DOORBELL); 1669 FT1000_REG_DOORBELL);
1670 info->DrvMsgPend = 0; 1670 dev->DrvMsgPend = 0;
1671 1671
1672 break; 1672 break;
1673 } 1673 }
@@ -1675,7 +1675,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1675 case GET_DRV_ERR_RPT_MSG:{ 1675 case GET_DRV_ERR_RPT_MSG:{
1676 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n"); 1676 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
1677 /* copy driver error message to dsp */ 1677 /* copy driver error message to dsp */
1678 info->DrvMsgPend = 1; 1678 dev->DrvMsgPend = 1;
1679 /* allow any outstanding ioctl to finish */ 1679 /* allow any outstanding ioctl to finish */
1680 mdelay(10); 1680 mdelay(10);
1681 status = 1681 status =
@@ -1735,7 +1735,7 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1735 (u16) (0x0012 + PSEUDOSZ)); 1735 (u16) (0x0012 + PSEUDOSZ));
1736 info->DrvErrNum = 0; 1736 info->DrvErrNum = 0;
1737 } 1737 }
1738 info->DrvMsgPend = 0; 1738 dev->DrvMsgPend = 0;
1739 1739
1740 break; 1740 break;
1741 } 1741 }
@@ -1753,7 +1753,7 @@ out:
1753 1753
1754int ft1000_poll(void* dev_id) 1754int ft1000_poll(void* dev_id)
1755{ 1755{
1756 struct ft1000_device *dev = (struct ft1000_device *)dev_id; 1756 struct ft1000_usb *dev = (struct ft1000_usb *)dev_id;
1757 struct ft1000_info *info = netdev_priv(dev->net); 1757 struct ft1000_info *info = netdev_priv(dev->net);
1758 1758
1759 u16 tempword; 1759 u16 tempword;
@@ -1804,8 +1804,8 @@ int ft1000_poll(void* dev_id)
1804 // Check which application has registered for dsp broadcast messages 1804 // Check which application has registered for dsp broadcast messages
1805 1805
1806 for (i=0; i<MAX_NUM_APP; i++) { 1806 for (i=0; i<MAX_NUM_APP; i++) {
1807 if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) && 1807 if ( (dev->app_info[i].DspBCMsgFlag) && (dev->app_info[i].fileobject) &&
1808 (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) ) 1808 (dev->app_info[i].NumOfMsg < MAX_MSG_LIMIT) )
1809 { 1809 {
1810 nxtph = FT1000_DPRAM_RX_BASE + 2; 1810 nxtph = FT1000_DPRAM_RX_BASE + 2;
1811 pdpram_blk = ft1000_get_buffer (&freercvpool); 1811 pdpram_blk = ft1000_get_buffer (&freercvpool);
@@ -1813,15 +1813,15 @@ int ft1000_poll(void* dev_id)
1813 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) { 1813 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
1814 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer; 1814 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
1815 // Put message into the appropriate application block 1815 // Put message into the appropriate application block
1816 info->app_info[i].nRxMsg++; 1816 dev->app_info[i].nRxMsg++;
1817 spin_lock_irqsave(&free_buff_lock, flags); 1817 spin_lock_irqsave(&free_buff_lock, flags);
1818 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist); 1818 list_add_tail(&pdpram_blk->list, &dev->app_info[i].app_sqlist);
1819 info->app_info[i].NumOfMsg++; 1819 dev->app_info[i].NumOfMsg++;
1820 spin_unlock_irqrestore(&free_buff_lock, flags); 1820 spin_unlock_irqrestore(&free_buff_lock, flags);
1821 wake_up_interruptible(&info->app_info[i].wait_dpram_msg); 1821 wake_up_interruptible(&dev->app_info[i].wait_dpram_msg);
1822 } 1822 }
1823 else { 1823 else {
1824 info->app_info[i].nRxMsgMiss++; 1824 dev->app_info[i].nRxMsgMiss++;
1825 // Put memory back to free pool 1825 // Put memory back to free pool
1826 ft1000_free_buffer(pdpram_blk, &freercvpool); 1826 ft1000_free_buffer(pdpram_blk, &freercvpool);
1827 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n"); 1827 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
@@ -1829,7 +1829,7 @@ int ft1000_poll(void* dev_id)
1829 } 1829 }
1830 else { 1830 else {
1831 DEBUG("Out of memory in free receive command pool\n"); 1831 DEBUG("Out of memory in free receive command pool\n");
1832 info->app_info[i].nRxMsgMiss++; 1832 dev->app_info[i].nRxMsgMiss++;
1833 } 1833 }
1834 } 1834 }
1835 } 1835 }
@@ -1842,7 +1842,7 @@ int ft1000_poll(void* dev_id)
1842 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer; 1842 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
1843 // Search for correct application block 1843 // Search for correct application block
1844 for (i=0; i<MAX_NUM_APP; i++) { 1844 for (i=0; i<MAX_NUM_APP; i++) {
1845 if (info->app_info[i].app_id == ppseudo_hdr->portdest) { 1845 if (dev->app_info[i].app_id == ppseudo_hdr->portdest) {
1846 break; 1846 break;
1847 } 1847 }
1848 } 1848 }
@@ -1853,15 +1853,15 @@ int ft1000_poll(void* dev_id)
1853 ft1000_free_buffer(pdpram_blk, &freercvpool); 1853 ft1000_free_buffer(pdpram_blk, &freercvpool);
1854 } 1854 }
1855 else { 1855 else {
1856 if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) { 1856 if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
1857 // Put memory back to free pool 1857 // Put memory back to free pool
1858 ft1000_free_buffer(pdpram_blk, &freercvpool); 1858 ft1000_free_buffer(pdpram_blk, &freercvpool);
1859 } 1859 }
1860 else { 1860 else {
1861 info->app_info[i].nRxMsg++; 1861 dev->app_info[i].nRxMsg++;
1862 // Put message into the appropriate application block 1862 // Put message into the appropriate application block
1863 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist); 1863 list_add_tail(&pdpram_blk->list, &dev->app_info[i].app_sqlist);
1864 info->app_info[i].NumOfMsg++; 1864 dev->app_info[i].NumOfMsg++;
1865 } 1865 }
1866 } 1866 }
1867 } 1867 }
@@ -1921,7 +1921,7 @@ int ft1000_poll(void* dev_id)
1921 else if (tempword & FT1000_DB_COND_RESET) { 1921 else if (tempword & FT1000_DB_COND_RESET) {
1922 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n"); 1922 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
1923 1923
1924 if (info->fAppMsgPend == 0) { 1924 if (dev->fAppMsgPend == 0) {
1925 // Reset ASIC and DSP 1925 // Reset ASIC and DSP
1926 1926
1927 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); 1927 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
@@ -1934,8 +1934,8 @@ int ft1000_poll(void* dev_id)
1934 info->ft1000_reset(dev->net); 1934 info->ft1000_reset(dev->net);
1935 } 1935 }
1936 else { 1936 else {
1937 info->fProvComplete = 0; 1937 dev->fProvComplete = 0;
1938 info->fCondResetPend = 1; 1938 dev->fCondResetPend = 1;
1939 } 1939 }
1940 1940
1941 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL); 1941 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c
index 1edaddba816f..b99640637fe0 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_proc.c
@@ -51,7 +51,7 @@
51#define FTNET_PROC init_net.proc_net 51#define FTNET_PROC init_net.proc_net
52 52
53 53
54int ft1000_read_dpram16 (struct ft1000_device *ft1000dev, u16 indx, 54int ft1000_read_dpram16 (struct ft1000_usb *ft1000dev, u16 indx,
55 u8 *buffer, u8 highlow); 55 u8 *buffer, u8 highlow);
56 56
57 57
@@ -94,11 +94,11 @@ ft1000ReadProc(char *page, char **start, off_t off, int count, int *eof,
94 94
95 95
96 if (info->ProgConStat != 0xFF) { 96 if (info->ProgConStat != 0xFF) {
97 ft1000_read_dpram16(info->pFt1000Dev, FT1000_MAG_DSP_LED, 97 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_LED,
98 (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX); 98 (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
99 info->LedStat = ntohs(ledStat); 99 info->LedStat = ntohs(ledStat);
100 100
101 ft1000_read_dpram16(info->pFt1000Dev, FT1000_MAG_DSP_CON_STATE, 101 ft1000_read_dpram16(info->priv, FT1000_MAG_DSP_CON_STATE,
102 (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX); 102 (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
103 info->ConStat = ntohs(conStat); 103 info->ConStat = ntohs(conStat);
104 do_gettimeofday(&tv); 104 do_gettimeofday(&tv);
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
index b2ecd0e6780e..614db55a8171 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
@@ -63,16 +63,13 @@ static int ft1000_probe(struct usb_interface *interface,
63 unsigned numaltsetting; 63 unsigned numaltsetting;
64 int i, ret = 0, size; 64 int i, ret = 0, size;
65 65
66 struct ft1000_device *ft1000dev; 66 struct ft1000_usb *ft1000dev;
67 struct ft1000_info *pft1000info = NULL; 67 struct ft1000_info *pft1000info = NULL;
68 const struct firmware *dsp_fw; 68 const struct firmware *dsp_fw;
69 69
70 ft1000dev = kzalloc(sizeof(struct ft1000_device), GFP_KERNEL); 70 ft1000dev = kzalloc(sizeof(struct ft1000_usb), GFP_KERNEL);
71 71 if (!ft1000dev)
72 if (!ft1000dev) {
73 pr_err("out of memory allocating device structure\n");
74 return -ENOMEM; 72 return -ENOMEM;
75 }
76 73
77 dev = interface_to_usbdev(interface); 74 dev = interface_to_usbdev(interface);
78 DEBUG("ft1000_probe: usb device descriptor info:\n"); 75 DEBUG("ft1000_probe: usb device descriptor info:\n");
@@ -171,11 +168,11 @@ static int ft1000_probe(struct usb_interface *interface,
171 } 168 }
172 169
173 gPollingfailed = FALSE; 170 gPollingfailed = FALSE;
174 pft1000info->pPollThread = 171 ft1000dev->pPollThread =
175 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll"); 172 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll");
176 173
177 if (IS_ERR(pft1000info->pPollThread)) { 174 if (IS_ERR(ft1000dev->pPollThread)) {
178 ret = PTR_ERR(pft1000info->pPollThread); 175 ret = PTR_ERR(ft1000dev->pPollThread);
179 goto err_load; 176 goto err_load;
180 } 177 }
181 178
@@ -200,7 +197,7 @@ static int ft1000_probe(struct usb_interface *interface,
200 if (ret) 197 if (ret)
201 goto err_proc; 198 goto err_proc;
202 199
203 pft1000info->NetDevRegDone = 1; 200 ft1000dev->NetDevRegDone = 1;
204 201
205 return 0; 202 return 0;
206 203
@@ -208,7 +205,7 @@ err_proc:
208 unregister_netdev(ft1000dev->net); 205 unregister_netdev(ft1000dev->net);
209 free_netdev(ft1000dev->net); 206 free_netdev(ft1000dev->net);
210err_thread: 207err_thread:
211 kthread_stop(pft1000info->pPollThread); 208 kthread_stop(ft1000dev->pPollThread);
212err_load: 209err_load:
213 kfree(pFileStart); 210 kfree(pFileStart);
214err_fw: 211err_fw:
@@ -219,6 +216,7 @@ err_fw:
219static void ft1000_disconnect(struct usb_interface *interface) 216static void ft1000_disconnect(struct usb_interface *interface)
220{ 217{
221 struct ft1000_info *pft1000info; 218 struct ft1000_info *pft1000info;
219 struct ft1000_usb *ft1000dev;
222 220
223 DEBUG("ft1000_disconnect is called\n"); 221 DEBUG("ft1000_disconnect is called\n");
224 222
@@ -226,28 +224,29 @@ static void ft1000_disconnect(struct usb_interface *interface)
226 DEBUG("In disconnect pft1000info=%p\n", pft1000info); 224 DEBUG("In disconnect pft1000info=%p\n", pft1000info);
227 225
228 if (pft1000info) { 226 if (pft1000info) {
227 ft1000dev = pft1000info->priv;
229 ft1000_cleanup_proc(pft1000info); 228 ft1000_cleanup_proc(pft1000info);
230 if (pft1000info->pPollThread) 229 if (ft1000dev->pPollThread)
231 kthread_stop(pft1000info->pPollThread); 230 kthread_stop(ft1000dev->pPollThread);
232 231
233 DEBUG("ft1000_disconnect: threads are terminated\n"); 232 DEBUG("ft1000_disconnect: threads are terminated\n");
234 233
235 if (pft1000info->pFt1000Dev->net) { 234 if (ft1000dev->net) {
236 DEBUG("ft1000_disconnect: destroy char driver\n"); 235 DEBUG("ft1000_disconnect: destroy char driver\n");
237 ft1000_destroy_dev(pft1000info->pFt1000Dev->net); 236 ft1000_destroy_dev(ft1000dev->net);
238 unregister_netdev(pft1000info->pFt1000Dev->net); 237 unregister_netdev(ft1000dev->net);
239 DEBUG 238 DEBUG
240 ("ft1000_disconnect: network device unregistered\n"); 239 ("ft1000_disconnect: network device unregistered\n");
241 free_netdev(pft1000info->pFt1000Dev->net); 240 free_netdev(ft1000dev->net);
242 241
243 } 242 }
244 243
245 usb_free_urb(pft1000info->pFt1000Dev->rx_urb); 244 usb_free_urb(ft1000dev->rx_urb);
246 usb_free_urb(pft1000info->pFt1000Dev->tx_urb); 245 usb_free_urb(ft1000dev->tx_urb);
247 246
248 DEBUG("ft1000_disconnect: urb freed\n"); 247 DEBUG("ft1000_disconnect: urb freed\n");
249 248
250 kfree(pft1000info->pFt1000Dev); 249 kfree(ft1000dev);
251 } 250 }
252 kfree(pFileStart); 251 kfree(pFileStart);
253 252
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
index 2aa6a1c7fd38..bd1da1f19cd2 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
@@ -55,7 +55,14 @@ struct app_info_block {
55 55
56#define MAX_BUF_SIZE 4096 56#define MAX_BUF_SIZE 4096
57 57
58struct ft1000_device { 58struct ft1000_debug_dirs {
59 struct list_head list;
60 struct dentry *dent;
61 struct dentry *file;
62 int int_number;
63};
64
65struct ft1000_usb {
59 struct usb_device *dev; 66 struct usb_device *dev;
60 struct net_device *net; 67 struct net_device *net;
61 68
@@ -69,71 +76,26 @@ struct ft1000_device {
69 76
70 u8 bulk_in_endpointAddr; 77 u8 bulk_in_endpointAddr;
71 u8 bulk_out_endpointAddr; 78 u8 bulk_out_endpointAddr;
72} __packed;
73
74struct ft1000_debug_dirs {
75 struct list_head list;
76 struct dentry *dent;
77 struct dentry *file;
78 int int_number;
79};
80
81struct ft1000_info {
82 struct ft1000_device *pFt1000Dev;
83 struct net_device_stats stats;
84 79
85 struct task_struct *pPollThread; 80 struct task_struct *pPollThread;
86
87 unsigned char fcodeldr; 81 unsigned char fcodeldr;
88 unsigned char bootmode; 82 unsigned char bootmode;
89 unsigned char usbboot; 83 unsigned char usbboot;
90 unsigned short dspalive; 84 unsigned short dspalive;
91 u16 ASIC_ID;
92 bool fProvComplete; 85 bool fProvComplete;
93 bool fCondResetPend; 86 bool fCondResetPend;
94 bool fAppMsgPend; 87 bool fAppMsgPend;
95 u16 DrvErrNum;
96 u16 AsicID;
97 int DspAsicReset;
98 int DeviceCreated; 88 int DeviceCreated;
99 int CardReady;
100 int NetDevRegDone; 89 int NetDevRegDone;
101 u8 CardNumber; 90 u8 CardNumber;
102 u8 DeviceName[15]; 91 u8 DeviceName[15];
103 struct ft1000_debug_dirs nodes; 92 struct ft1000_debug_dirs nodes;
104 int registered;
105 int mediastate;
106 u8 squeseqnum; /* sequence number on slow queue */
107 spinlock_t dpram_lock;
108 spinlock_t fifo_lock; 93 spinlock_t fifo_lock;
109 u16 fifo_cnt;
110 u8 DspVer[DSPVERSZ]; /* DSP version number */
111 u8 HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */
112 u8 Sku[SKUSZ]; /* SKU */
113 u8 eui64[EUISZ]; /* EUI64 */
114 time_t ConTm; /* Connection Time */
115 u8 ProductMode[MODESZ];
116 u8 RfCalVer[CALVERSZ];
117 u8 RfCalDate[CALDATESZ];
118 u16 DSP_TIME[4];
119 u16 LedStat;
120 u16 ConStat;
121 u16 ProgConStat;
122 struct list_head prov_list;
123 int appcnt; 94 int appcnt;
124 struct app_info_block app_info[MAX_NUM_APP]; 95 struct app_info_block app_info[MAX_NUM_APP];
125 u16 DSPInfoBlklen;
126 u16 DrvMsgPend; 96 u16 DrvMsgPend;
127 int (*ft1000_reset)(struct net_device *dev);
128 u16 DSPInfoBlk[MAX_DSP_SESS_REC];
129 union {
130 u16 Rec[MAX_DSP_SESS_REC];
131 u32 MagRec[MAX_DSP_SESS_REC/2];
132 } DSPSess;
133 unsigned short tempbuf[32]; 97 unsigned short tempbuf[32];
134 char netdevname[IFNAMSIZ]; 98} __packed;
135 struct proc_dir_entry *ft1000_proc_dir;
136};
137 99
138 100
139struct dpram_blk { 101struct dpram_blk {
@@ -141,21 +103,21 @@ struct dpram_blk {
141 u16 *pbuffer; 103 u16 *pbuffer;
142} __packed; 104} __packed;
143 105
144int ft1000_read_register(struct ft1000_device *ft1000dev, 106int ft1000_read_register(struct ft1000_usb *ft1000dev,
145 u16 *Data, u16 nRegIndx); 107 u16 *Data, u16 nRegIndx);
146int ft1000_write_register(struct ft1000_device *ft1000dev, 108int ft1000_write_register(struct ft1000_usb *ft1000dev,
147 u16 value, u16 nRegIndx); 109 u16 value, u16 nRegIndx);
148int ft1000_read_dpram32(struct ft1000_device *ft1000dev, 110int ft1000_read_dpram32(struct ft1000_usb *ft1000dev,
149 u16 indx, u8 *buffer, u16 cnt); 111 u16 indx, u8 *buffer, u16 cnt);
150int ft1000_write_dpram32(struct ft1000_device *ft1000dev, 112int ft1000_write_dpram32(struct ft1000_usb *ft1000dev,
151 u16 indx, u8 *buffer, u16 cnt); 113 u16 indx, u8 *buffer, u16 cnt);
152int ft1000_read_dpram16(struct ft1000_device *ft1000dev, 114int ft1000_read_dpram16(struct ft1000_usb *ft1000dev,
153 u16 indx, u8 *buffer, u8 highlow); 115 u16 indx, u8 *buffer, u8 highlow);
154int ft1000_write_dpram16(struct ft1000_device *ft1000dev, 116int ft1000_write_dpram16(struct ft1000_usb *ft1000dev,
155 u16 indx, u16 value, u8 highlow); 117 u16 indx, u16 value, u8 highlow);
156int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, 118int fix_ft1000_read_dpram32(struct ft1000_usb *ft1000dev,
157 u16 indx, u8 *buffer); 119 u16 indx, u8 *buffer);
158int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, 120int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev,
159 u16 indx, u8 *buffer); 121 u16 indx, u8 *buffer);
160 122
161extern void *pFileStart; 123extern void *pFileStart;
@@ -163,25 +125,25 @@ extern size_t FileLength;
163extern int numofmsgbuf; 125extern int numofmsgbuf;
164 126
165int ft1000_close(struct net_device *dev); 127int ft1000_close(struct net_device *dev);
166u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, 128u16 scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
167 u32 FileLength); 129 u32 FileLength);
168 130
169extern struct list_head freercvpool; 131extern struct list_head freercvpool;
170 132
171extern spinlock_t free_buff_lock; /* lock to arbitrate free buffer list for receive command data */ 133extern spinlock_t free_buff_lock; /* lock to arbitrate free buffer list for receive command data */
172 134
173int ft1000_create_dev(struct ft1000_device *dev); 135int ft1000_create_dev(struct ft1000_usb *dev);
174void ft1000_destroy_dev(struct net_device *dev); 136void ft1000_destroy_dev(struct net_device *dev);
175extern void card_send_command(struct ft1000_device *ft1000dev, 137extern void card_send_command(struct ft1000_usb *ft1000dev,
176 void *ptempbuffer, int size); 138 void *ptempbuffer, int size);
177 139
178struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist); 140struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist);
179void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist); 141void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist);
180 142
181int dsp_reload(struct ft1000_device *ft1000dev); 143int dsp_reload(struct ft1000_usb *ft1000dev);
182int init_ft1000_netdev(struct ft1000_device *ft1000dev); 144int init_ft1000_netdev(struct ft1000_usb *ft1000dev);
183struct usb_interface; 145struct usb_interface;
184int reg_ft1000_netdev(struct ft1000_device *ft1000dev, 146int reg_ft1000_netdev(struct ft1000_usb *ft1000dev,
185 struct usb_interface *intf); 147 struct usb_interface *intf);
186int ft1000_poll(void *dev_id); 148int ft1000_poll(void *dev_id);
187 149
diff --git a/drivers/staging/ft1000/ft1000.h b/drivers/staging/ft1000/ft1000.h
index 03baa5779234..175abfa7682e 100644
--- a/drivers/staging/ft1000/ft1000.h
+++ b/drivers/staging/ft1000/ft1000.h
@@ -250,3 +250,38 @@ struct prov_record {
250 struct list_head list; 250 struct list_head list;
251 u8 *pprov_data; 251 u8 *pprov_data;
252}; 252};
253
254struct ft1000_info {
255 void *priv;
256 struct net_device_stats stats;
257 u16 DrvErrNum;
258 u16 AsicID;
259 int CardReady;
260 int registered;
261 int mediastate;
262 u8 squeseqnum; /* sequence number on slow queue */
263 spinlock_t dpram_lock;
264 u16 fifo_cnt;
265 u8 DspVer[DSPVERSZ]; /* DSP version number */
266 u8 HwSerNum[HWSERNUMSZ]; /* Hardware Serial Number */
267 u8 Sku[SKUSZ]; /* SKU */
268 u8 eui64[EUISZ]; /* EUI64 */
269 time_t ConTm; /* Connection Time */
270 u8 ProductMode[MODESZ];
271 u8 RfCalVer[CALVERSZ];
272 u8 RfCalDate[CALDATESZ];
273 u16 DSP_TIME[4];
274 u16 LedStat;
275 u16 ConStat;
276 u16 ProgConStat;
277 struct list_head prov_list;
278 u16 DSPInfoBlklen;
279 int (*ft1000_reset)(void *);
280 u16 DSPInfoBlk[MAX_DSP_SESS_REC];
281 union {
282 u16 Rec[MAX_DSP_SESS_REC];
283 u32 MagRec[MAX_DSP_SESS_REC/2];
284 } DSPSess;
285 struct proc_dir_entry *ft1000_proc_dir;
286 char netdevname[IFNAMSIZ];
287};
diff --git a/drivers/staging/fwserial/TODO b/drivers/staging/fwserial/TODO
index 8dae8fb25223..382a7959407c 100644
--- a/drivers/staging/fwserial/TODO
+++ b/drivers/staging/fwserial/TODO
@@ -12,18 +12,3 @@ TODOs prior to this driver moving out of staging
121. This driver uses the same unregistered vendor id that the firewire core does 121. This driver uses the same unregistered vendor id that the firewire core does
13 (0xd00d1e). Perhaps this could be exposed as a define in 13 (0xd00d1e). Perhaps this could be exposed as a define in
14 firewire.h? 14 firewire.h?
153. Maybe device_max_receive() and link_speed_to_max_payload() should be
16 taken up by the firewire core?
17
18-- Issues with TTY core --
19 1. Hack for alternate device name scheme
20 - because udev no longer allows device renaming, devices should have
21 their proper names on creation. This is an issue for creating the
22 fwloop<n> device with the fwtty<n> devices because although duplicating
23 roughly the same operations as tty_port_register_device() isn't difficult,
24 access to the tty_class & tty_fops is restricted in scope.
25
26 This is currently being worked around in create_loop_device() by
27 extracting the tty_class ptr and tty_fops ptr from the previously created
28 tty devices. Perhaps an add'l api can be added -- eg.,
29 tty_{port_}register_named_device().
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index d03a7f57e8d4..8859c75f16fa 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -40,12 +40,10 @@ static int num_ttys = 4; /* # of std ttys to create per fw_card */
40 /* - doubles as loopback port index */ 40 /* - doubles as loopback port index */
41static bool auto_connect = true; /* try to VIRT_CABLE to every peer */ 41static bool auto_connect = true; /* try to VIRT_CABLE to every peer */
42static bool create_loop_dev = true; /* create a loopback device for each card */ 42static bool create_loop_dev = true; /* create a loopback device for each card */
43bool limit_bw; /* limit async bandwidth to 20% of max */
44 43
45module_param_named(ttys, num_ttys, int, S_IRUGO | S_IWUSR); 44module_param_named(ttys, num_ttys, int, S_IRUGO | S_IWUSR);
46module_param_named(auto, auto_connect, bool, S_IRUGO | S_IWUSR); 45module_param_named(auto, auto_connect, bool, S_IRUGO | S_IWUSR);
47module_param_named(loop, create_loop_dev, bool, S_IRUGO | S_IWUSR); 46module_param_named(loop, create_loop_dev, bool, S_IRUGO | S_IWUSR);
48module_param(limit_bw, bool, S_IRUGO | S_IWUSR);
49 47
50/* 48/*
51 * Threshold below which the tty is woken for writing 49 * Threshold below which the tty is woken for writing
@@ -74,12 +72,20 @@ static DEFINE_MUTEX(port_table_lock);
74static bool port_table_corrupt; 72static bool port_table_corrupt;
75#define FWTTY_INVALID_INDEX MAX_TOTAL_PORTS 73#define FWTTY_INVALID_INDEX MAX_TOTAL_PORTS
76 74
75#define loop_idx(port) (((port)->index) / num_ports)
76#define table_idx(loop) ((loop) * num_ports + num_ttys)
77
77/* total # of tty ports created per fw_card */ 78/* total # of tty ports created per fw_card */
78static int num_ports; 79static int num_ports;
79 80
80/* slab used as pool for struct fwtty_transactions */ 81/* slab used as pool for struct fwtty_transactions */
81static struct kmem_cache *fwtty_txn_cache; 82static struct kmem_cache *fwtty_txn_cache;
82 83
84struct tty_driver *fwtty_driver;
85static struct tty_driver *fwloop_driver;
86
87static struct dentry *fwserial_debugfs;
88
83struct fwtty_transaction; 89struct fwtty_transaction;
84typedef void (*fwtty_transaction_cb)(struct fw_card *card, int rcode, 90typedef void (*fwtty_transaction_cb)(struct fw_card *card, int rcode,
85 void *data, size_t length, 91 void *data, size_t length,
@@ -176,10 +182,15 @@ static void dump_profile(struct seq_file *m, struct stats *stats)
176#define dump_profile(m, stats) 182#define dump_profile(m, stats)
177#endif 183#endif
178 184
179/* Returns the max receive packet size for the given card */ 185/*
186 * Returns the max receive packet size for the given node
187 * Devices which are OHCI v1.0/ v1.1/ v1.2-draft or RFC 2734 compliant
188 * are required by specification to support max_rec of 8 (512 bytes) or more.
189 */
180static inline int device_max_receive(struct fw_device *fw_device) 190static inline int device_max_receive(struct fw_device *fw_device)
181{ 191{
182 return 1 << (clamp_t(int, fw_device->max_rec, 8U, 11U) + 1); 192 /* see IEEE 1394-2008 table 8-8 */
193 return min(2 << fw_device->max_rec, 4096);
183} 194}
184 195
185static void fwtty_log_tx_error(struct fwtty_port *port, int rcode) 196static void fwtty_log_tx_error(struct fwtty_port *port, int rcode)
@@ -566,8 +577,11 @@ static int fwtty_buffer_rx(struct fwtty_port *port, unsigned char *d, size_t n)
566 struct buffered_rx *buf; 577 struct buffered_rx *buf;
567 size_t size = (n + sizeof(struct buffered_rx) + 0xFF) & ~0xFF; 578 size_t size = (n + sizeof(struct buffered_rx) + 0xFF) & ~0xFF;
568 579
569 if (port->buffered + n > HIGH_WATERMARK) 580 if (port->buffered + n > HIGH_WATERMARK) {
581 fwtty_err_ratelimited(port, "overflowed rx buffer: buffered: %d new: %zu wtrmk: %d",
582 port->buffered, n, HIGH_WATERMARK);
570 return 0; 583 return 0;
584 }
571 buf = kmalloc(size, GFP_ATOMIC); 585 buf = kmalloc(size, GFP_ATOMIC);
572 if (!buf) 586 if (!buf)
573 return 0; 587 return 0;
@@ -1160,6 +1174,19 @@ static int fwtty_install(struct tty_driver *driver, struct tty_struct *tty)
1160 return err; 1174 return err;
1161} 1175}
1162 1176
1177static int fwloop_install(struct tty_driver *driver, struct tty_struct *tty)
1178{
1179 struct fwtty_port *port = fwtty_port_get(table_idx(tty->index));
1180 int err;
1181
1182 err = tty_standard_install(driver, tty);
1183 if (!err)
1184 tty->driver_data = port;
1185 else
1186 fwtty_port_put(port);
1187 return err;
1188}
1189
1163static int fwtty_write(struct tty_struct *tty, const unsigned char *buf, int c) 1190static int fwtty_write(struct tty_struct *tty, const unsigned char *buf, int c)
1164{ 1191{
1165 struct fwtty_port *port = tty->driver_data; 1192 struct fwtty_port *port = tty->driver_data;
@@ -1487,17 +1514,26 @@ static void fwtty_proc_show_port(struct seq_file *m, struct fwtty_port *port)
1487 if (port->port.console) 1514 if (port->port.console)
1488 (*port->fwcon_ops->stats)(&stats, port->con_data); 1515 (*port->fwcon_ops->stats)(&stats, port->con_data);
1489 1516
1490 seq_printf(m, " tx:%d rx:%d", port->icount.tx + stats.xchars, 1517 seq_printf(m, " addr:%012llx tx:%d rx:%d", port->rx_handler.offset,
1491 port->icount.rx); 1518 port->icount.tx + stats.xchars, port->icount.rx);
1492 seq_printf(m, " cts:%d dsr:%d rng:%d dcd:%d", port->icount.cts, 1519 seq_printf(m, " cts:%d dsr:%d rng:%d dcd:%d", port->icount.cts,
1493 port->icount.dsr, port->icount.rng, port->icount.dcd); 1520 port->icount.dsr, port->icount.rng, port->icount.dcd);
1494 seq_printf(m, " fe:%d oe:%d pe:%d brk:%d", port->icount.frame, 1521 seq_printf(m, " fe:%d oe:%d pe:%d brk:%d", port->icount.frame,
1495 port->icount.overrun, port->icount.parity, port->icount.brk); 1522 port->icount.overrun, port->icount.parity, port->icount.brk);
1523}
1524
1525static void fwtty_debugfs_show_port(struct seq_file *m, struct fwtty_port *port)
1526{
1527 struct stats stats;
1528
1529 memcpy(&stats, &port->stats, sizeof(stats));
1530 if (port->port.console)
1531 (*port->fwcon_ops->stats)(&stats, port->con_data);
1532
1496 seq_printf(m, " dr:%d st:%d err:%d lost:%d", stats.dropped, 1533 seq_printf(m, " dr:%d st:%d err:%d lost:%d", stats.dropped,
1497 stats.tx_stall, stats.fifo_errs, stats.lost); 1534 stats.tx_stall, stats.fifo_errs, stats.lost);
1498 seq_printf(m, " pkts:%d thr:%d wtrmk:%d", stats.sent, stats.throttled, 1535 seq_printf(m, " pkts:%d thr:%d wtrmk:%d", stats.sent, stats.throttled,
1499 stats.watermark); 1536 stats.watermark);
1500 seq_printf(m, " addr:%012llx", port->rx_handler.offset);
1501 1537
1502 if (port->port.console) { 1538 if (port->port.console) {
1503 seq_printf(m, "\n "); 1539 seq_printf(m, "\n ");
@@ -1507,7 +1543,7 @@ static void fwtty_proc_show_port(struct seq_file *m, struct fwtty_port *port)
1507 dump_profile(m, &port->stats); 1543 dump_profile(m, &port->stats);
1508} 1544}
1509 1545
1510static void fwtty_proc_show_peer(struct seq_file *m, struct fwtty_peer *peer) 1546static void fwtty_debugfs_show_peer(struct seq_file *m, struct fwtty_peer *peer)
1511{ 1547{
1512 int generation = peer->generation; 1548 int generation = peer->generation;
1513 1549
@@ -1516,21 +1552,14 @@ static void fwtty_proc_show_peer(struct seq_file *m, struct fwtty_peer *peer)
1516 seq_printf(m, " node:%04x gen:%d", peer->node_id, generation); 1552 seq_printf(m, " node:%04x gen:%d", peer->node_id, generation);
1517 seq_printf(m, " sp:%d max:%d guid:%016llx", peer->speed, 1553 seq_printf(m, " sp:%d max:%d guid:%016llx", peer->speed,
1518 peer->max_payload, (unsigned long long) peer->guid); 1554 peer->max_payload, (unsigned long long) peer->guid);
1519 1555 seq_printf(m, " mgmt:%012llx", (unsigned long long) peer->mgmt_addr);
1520 if (capable(CAP_SYS_ADMIN)) { 1556 seq_printf(m, " addr:%012llx", (unsigned long long) peer->status_addr);
1521 seq_printf(m, " mgmt:%012llx",
1522 (unsigned long long) peer->mgmt_addr);
1523 seq_printf(m, " addr:%012llx",
1524 (unsigned long long) peer->status_addr);
1525 }
1526 seq_putc(m, '\n'); 1557 seq_putc(m, '\n');
1527} 1558}
1528 1559
1529static int fwtty_proc_show(struct seq_file *m, void *v) 1560static int fwtty_proc_show(struct seq_file *m, void *v)
1530{ 1561{
1531 struct fwtty_port *port; 1562 struct fwtty_port *port;
1532 struct fw_serial *serial;
1533 struct fwtty_peer *peer;
1534 int i; 1563 int i;
1535 1564
1536 seq_puts(m, "fwserinfo: 1.0 driver: 1.0\n"); 1565 seq_puts(m, "fwserinfo: 1.0 driver: 1.0\n");
@@ -1541,16 +1570,39 @@ static int fwtty_proc_show(struct seq_file *m, void *v)
1541 fwtty_port_put(port); 1570 fwtty_port_put(port);
1542 seq_printf(m, "\n"); 1571 seq_printf(m, "\n");
1543 } 1572 }
1544 seq_putc(m, '\n'); 1573 return 0;
1574}
1545 1575
1546 rcu_read_lock(); 1576static int fwtty_debugfs_stats_show(struct seq_file *m, void *v)
1547 list_for_each_entry_rcu(serial, &fwserial_list, list) { 1577{
1548 seq_printf(m, "card: %s guid: %016llx\n", 1578 struct fw_serial *serial = m->private;
1549 dev_name(serial->card->device), 1579 struct fwtty_port *port;
1550 (unsigned long long) serial->card->guid); 1580 int i;
1551 list_for_each_entry_rcu(peer, &serial->peer_list, list) 1581
1552 fwtty_proc_show_peer(m, peer); 1582 for (i = 0; i < num_ports; ++i) {
1583 port = fwtty_port_get(serial->ports[i]->index);
1584 if (port) {
1585 seq_printf(m, "%2d:", port->index);
1586 fwtty_proc_show_port(m, port);
1587 fwtty_debugfs_show_port(m, port);
1588 fwtty_port_put(port);
1589 seq_printf(m, "\n");
1590 }
1553 } 1591 }
1592 return 0;
1593}
1594
1595static int fwtty_debugfs_peers_show(struct seq_file *m, void *v)
1596{
1597 struct fw_serial *serial = m->private;
1598 struct fwtty_peer *peer;
1599
1600 rcu_read_lock();
1601 seq_printf(m, "card: %s guid: %016llx\n",
1602 dev_name(serial->card->device),
1603 (unsigned long long) serial->card->guid);
1604 list_for_each_entry_rcu(peer, &serial->peer_list, list)
1605 fwtty_debugfs_show_peer(m, peer);
1554 rcu_read_unlock(); 1606 rcu_read_unlock();
1555 return 0; 1607 return 0;
1556} 1608}
@@ -1560,6 +1612,32 @@ static int fwtty_proc_open(struct inode *inode, struct file *fp)
1560 return single_open(fp, fwtty_proc_show, NULL); 1612 return single_open(fp, fwtty_proc_show, NULL);
1561} 1613}
1562 1614
1615static int fwtty_stats_open(struct inode *inode, struct file *fp)
1616{
1617 return single_open(fp, fwtty_debugfs_stats_show, inode->i_private);
1618}
1619
1620static int fwtty_peers_open(struct inode *inode, struct file *fp)
1621{
1622 return single_open(fp, fwtty_debugfs_peers_show, inode->i_private);
1623}
1624
1625static const struct file_operations fwtty_stats_fops = {
1626 .owner = THIS_MODULE,
1627 .open = fwtty_stats_open,
1628 .read = seq_read,
1629 .llseek = seq_lseek,
1630 .release = single_release,
1631};
1632
1633static const struct file_operations fwtty_peers_fops = {
1634 .owner = THIS_MODULE,
1635 .open = fwtty_peers_open,
1636 .read = seq_read,
1637 .llseek = seq_lseek,
1638 .release = single_release,
1639};
1640
1563static const struct file_operations fwtty_proc_fops = { 1641static const struct file_operations fwtty_proc_fops = {
1564 .owner = THIS_MODULE, 1642 .owner = THIS_MODULE,
1565 .open = fwtty_proc_open, 1643 .open = fwtty_proc_open,
@@ -1596,6 +1674,26 @@ static const struct tty_operations fwtty_ops = {
1596 .proc_fops = &fwtty_proc_fops, 1674 .proc_fops = &fwtty_proc_fops,
1597}; 1675};
1598 1676
1677static const struct tty_operations fwloop_ops = {
1678 .open = fwtty_open,
1679 .close = fwtty_close,
1680 .hangup = fwtty_hangup,
1681 .cleanup = fwtty_cleanup,
1682 .install = fwloop_install,
1683 .write = fwtty_write,
1684 .write_room = fwtty_write_room,
1685 .chars_in_buffer = fwtty_chars_in_buffer,
1686 .send_xchar = fwtty_send_xchar,
1687 .throttle = fwtty_throttle,
1688 .unthrottle = fwtty_unthrottle,
1689 .ioctl = fwtty_ioctl,
1690 .set_termios = fwtty_set_termios,
1691 .break_ctl = fwtty_break_ctl,
1692 .tiocmget = fwtty_tiocmget,
1693 .tiocmset = fwtty_tiocmset,
1694 .get_icount = fwtty_get_icount,
1695};
1696
1599static inline int mgmt_pkt_expected_len(__be16 code) 1697static inline int mgmt_pkt_expected_len(__be16 code)
1600{ 1698{
1601 static const struct fwserial_mgmt_pkt pkt; 1699 static const struct fwserial_mgmt_pkt pkt;
@@ -1685,8 +1783,7 @@ static void fwserial_virt_plug_complete(struct fwtty_peer *peer,
1685 1783
1686 /* reconfigure tx_fifo optimally for this peer */ 1784 /* reconfigure tx_fifo optimally for this peer */
1687 spin_lock_bh(&port->lock); 1785 spin_lock_bh(&port->lock);
1688 port->max_payload = min3(peer->max_payload, peer->fifo_len, 1786 port->max_payload = min(peer->max_payload, peer->fifo_len);
1689 MAX_ASYNC_PAYLOAD);
1690 dma_fifo_change_tx_limit(&port->tx_fifo, port->max_payload); 1787 dma_fifo_change_tx_limit(&port->tx_fifo, port->max_payload);
1691 spin_unlock_bh(&peer->port->lock); 1788 spin_unlock_bh(&peer->port->lock);
1692 1789
@@ -1781,10 +1878,11 @@ static struct fwtty_port *fwserial_find_port(struct fwtty_peer *peer)
1781 return NULL; 1878 return NULL;
1782} 1879}
1783 1880
1784static void fwserial_release_port(struct fwtty_port *port) 1881static void fwserial_release_port(struct fwtty_port *port, bool reset)
1785{ 1882{
1786 /* drop carrier (and all other line status) */ 1883 /* drop carrier (and all other line status) */
1787 fwtty_update_port_status(port, 0); 1884 if (reset)
1885 fwtty_update_port_status(port, 0);
1788 1886
1789 spin_lock_bh(&port->lock); 1887 spin_lock_bh(&port->lock);
1790 1888
@@ -1814,7 +1912,7 @@ static void fwserial_plug_timeout(unsigned long data)
1814 spin_unlock_bh(&peer->lock); 1912 spin_unlock_bh(&peer->lock);
1815 1913
1816 if (port) 1914 if (port)
1817 fwserial_release_port(port); 1915 fwserial_release_port(port, false);
1818} 1916}
1819 1917
1820/** 1918/**
@@ -1877,7 +1975,7 @@ cancel_timer:
1877 peer_revert_state(peer); 1975 peer_revert_state(peer);
1878release_port: 1976release_port:
1879 spin_unlock_bh(&peer->lock); 1977 spin_unlock_bh(&peer->lock);
1880 fwserial_release_port(port); 1978 fwserial_release_port(port, false);
1881free_pkt: 1979free_pkt:
1882 kfree(pkt); 1980 kfree(pkt);
1883 return err; 1981 return err;
@@ -1892,7 +1990,8 @@ free_pkt:
1892 * The port reference is put by fwtty_cleanup (if a reference was 1990 * The port reference is put by fwtty_cleanup (if a reference was
1893 * ever taken). 1991 * ever taken).
1894 */ 1992 */
1895static void fwserial_close_port(struct fwtty_port *port) 1993static void fwserial_close_port(struct tty_driver *driver,
1994 struct fwtty_port *port)
1896{ 1995{
1897 struct tty_struct *tty; 1996 struct tty_struct *tty;
1898 1997
@@ -1904,7 +2003,10 @@ static void fwserial_close_port(struct fwtty_port *port)
1904 } 2003 }
1905 mutex_unlock(&port->port.mutex); 2004 mutex_unlock(&port->port.mutex);
1906 2005
1907 tty_unregister_device(fwtty_driver, port->index); 2006 if (driver == fwloop_driver)
2007 tty_unregister_device(driver, loop_idx(port));
2008 else
2009 tty_unregister_device(driver, port->index);
1908} 2010}
1909 2011
1910/** 2012/**
@@ -2155,85 +2257,13 @@ static void fwserial_remove_peer(struct fwtty_peer *peer)
2155 spin_unlock_bh(&peer->lock); 2257 spin_unlock_bh(&peer->lock);
2156 2258
2157 if (port) 2259 if (port)
2158 fwserial_release_port(port); 2260 fwserial_release_port(port, true);
2159 2261
2160 synchronize_rcu(); 2262 synchronize_rcu();
2161 kfree(peer); 2263 kfree(peer);
2162} 2264}
2163 2265
2164/** 2266/**
2165 * create_loop_device - create a loopback tty device
2166 * @tty_driver: tty_driver to own loopback device
2167 * @prototype: ptr to already-assigned 'prototype' tty port
2168 * @index: index to associate this device with the tty port
2169 * @parent: device to child to
2170 *
2171 * HACK - this is basically tty_port_register_device() with an
2172 * alternate naming scheme. Suggest tty_port_register_named_device()
2173 * helper api.
2174 *
2175 * Creates a loopback tty device named 'fwloop<n>' which is attached to
2176 * the local unit in fwserial_add_peer(). Note that <n> in the device
2177 * name advances in increments of port allocation blocks, ie., for port
2178 * indices 0..3, the device name will be 'fwloop0'; for 4..7, 'fwloop1',
2179 * and so on.
2180 *
2181 * Only one loopback device should be created per fw_card.
2182 */
2183static void release_loop_device(struct device *dev)
2184{
2185 kfree(dev);
2186}
2187
2188static struct device *create_loop_device(struct tty_driver *driver,
2189 struct fwtty_port *prototype,
2190 struct fwtty_port *port,
2191 struct device *parent)
2192{
2193 char name[64];
2194 int index = port->index;
2195 dev_t devt = MKDEV(driver->major, driver->minor_start) + index;
2196 struct device *dev = NULL;
2197 int err;
2198
2199 if (index >= fwtty_driver->num)
2200 return ERR_PTR(-EINVAL);
2201
2202 snprintf(name, 64, "%s%d", loop_dev_name, index / num_ports);
2203
2204 tty_port_link_device(&port->port, driver, index);
2205
2206 cdev_init(&driver->cdevs[index], driver->cdevs[prototype->index].ops);
2207 driver->cdevs[index].owner = driver->owner;
2208 err = cdev_add(&driver->cdevs[index], devt, 1);
2209 if (err)
2210 return ERR_PTR(err);
2211
2212 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2213 if (!dev) {
2214 cdev_del(&driver->cdevs[index]);
2215 return ERR_PTR(-ENOMEM);
2216 }
2217
2218 dev->devt = devt;
2219 dev->class = prototype->device->class;
2220 dev->parent = parent;
2221 dev->release = release_loop_device;
2222 dev_set_name(dev, "%s", name);
2223 dev->groups = NULL;
2224 dev_set_drvdata(dev, NULL);
2225
2226 err = device_register(dev);
2227 if (err) {
2228 put_device(dev);
2229 cdev_del(&driver->cdevs[index]);
2230 return ERR_PTR(err);
2231 }
2232
2233 return dev;
2234}
2235
2236/**
2237 * fwserial_create - init everything to create TTYs for a specific fw_card 2267 * fwserial_create - init everything to create TTYs for a specific fw_card
2238 * @unit: fw_unit for first 'serial' unit device probed for this fw_card 2268 * @unit: fw_unit for first 'serial' unit device probed for this fw_card
2239 * 2269 *
@@ -2331,17 +2361,28 @@ static int fwserial_create(struct fw_unit *unit)
2331 if (create_loop_dev) { 2361 if (create_loop_dev) {
2332 struct device *loop_dev; 2362 struct device *loop_dev;
2333 2363
2334 loop_dev = create_loop_device(fwtty_driver, 2364 loop_dev = tty_port_register_device(&serial->ports[j]->port,
2335 serial->ports[0], 2365 fwloop_driver,
2336 serial->ports[num_ttys], 2366 loop_idx(serial->ports[j]),
2337 card->device); 2367 card->device);
2338 if (IS_ERR(loop_dev)) { 2368 if (IS_ERR(loop_dev)) {
2339 err = PTR_ERR(loop_dev); 2369 err = PTR_ERR(loop_dev);
2340 fwtty_err(&unit, "create loop device failed (%d)", err); 2370 fwtty_err(&unit, "create loop device failed (%d)", err);
2341 goto unregister_ttys; 2371 goto unregister_ttys;
2342 } 2372 }
2343 serial->ports[num_ttys]->device = loop_dev; 2373 serial->ports[j]->device = loop_dev;
2344 serial->ports[num_ttys]->loopback = true; 2374 serial->ports[j]->loopback = true;
2375 }
2376
2377 if (!IS_ERR_OR_NULL(fwserial_debugfs)) {
2378 serial->debugfs = debugfs_create_dir(dev_name(&unit->device),
2379 fwserial_debugfs);
2380 if (!IS_ERR_OR_NULL(serial->debugfs)) {
2381 debugfs_create_file("peers", 0444, serial->debugfs,
2382 serial, &fwtty_peers_fops);
2383 debugfs_create_file("stats", 0444, serial->debugfs,
2384 serial, &fwtty_stats_fops);
2385 }
2345 } 2386 }
2346 2387
2347 list_add_rcu(&serial->list, &fwserial_list); 2388 list_add_rcu(&serial->list, &fwserial_list);
@@ -2356,7 +2397,11 @@ static int fwserial_create(struct fw_unit *unit)
2356 fwtty_err(&unit, "unable to add peer unit device (%d)", err); 2397 fwtty_err(&unit, "unable to add peer unit device (%d)", err);
2357 2398
2358 /* fall-through to error processing */ 2399 /* fall-through to error processing */
2400 debugfs_remove_recursive(serial->debugfs);
2401
2359 list_del_rcu(&serial->list); 2402 list_del_rcu(&serial->list);
2403 if (create_loop_dev)
2404 tty_unregister_device(fwloop_driver, loop_idx(serial->ports[j]));
2360unregister_ttys: 2405unregister_ttys:
2361 for (--j; j >= 0; --j) 2406 for (--j; j >= 0; --j)
2362 tty_unregister_device(fwtty_driver, serial->ports[j]->index); 2407 tty_unregister_device(fwtty_driver, serial->ports[j]->index);
@@ -2445,8 +2490,12 @@ static int fwserial_remove(struct device *dev)
2445 /* unlink from the fwserial_list here */ 2490 /* unlink from the fwserial_list here */
2446 list_del_rcu(&serial->list); 2491 list_del_rcu(&serial->list);
2447 2492
2448 for (i = 0; i < num_ports; ++i) 2493 debugfs_remove_recursive(serial->debugfs);
2449 fwserial_close_port(serial->ports[i]); 2494
2495 for (i = 0; i < num_ttys; ++i)
2496 fwserial_close_port(fwtty_driver, serial->ports[i]);
2497 if (create_loop_dev)
2498 fwserial_close_port(fwloop_driver, serial->ports[i]);
2450 kref_put(&serial->kref, fwserial_destroy); 2499 kref_put(&serial->kref, fwserial_destroy);
2451 } 2500 }
2452 mutex_unlock(&fwserial_list_mutex); 2501 mutex_unlock(&fwserial_list_mutex);
@@ -2510,26 +2559,25 @@ static struct fw_driver fwserial_driver = {
2510/* XXX: config ROM definitons could be improved with semi-automated offset 2559/* XXX: config ROM definitons could be improved with semi-automated offset
2511 * and length calculation 2560 * and length calculation
2512 */ 2561 */
2562#define FW_ROM_LEN(quads) ((quads) << 16)
2513#define FW_ROM_DESCRIPTOR(ofs) (((CSR_LEAF | CSR_DESCRIPTOR) << 24) | (ofs)) 2563#define FW_ROM_DESCRIPTOR(ofs) (((CSR_LEAF | CSR_DESCRIPTOR) << 24) | (ofs))
2514 2564
2515struct fwserial_unit_directory_data { 2565struct fwserial_unit_directory_data {
2516 u16 crc; 2566 u32 len_crc;
2517 u16 len;
2518 u32 unit_specifier; 2567 u32 unit_specifier;
2519 u32 unit_sw_version; 2568 u32 unit_sw_version;
2520 u32 unit_addr_offset; 2569 u32 unit_addr_offset;
2521 u32 desc1_ofs; 2570 u32 desc1_ofs;
2522 u16 desc1_crc; 2571 u32 desc1_len_crc;
2523 u16 desc1_len;
2524 u32 desc1_data[5]; 2572 u32 desc1_data[5];
2525} __packed; 2573} __packed;
2526 2574
2527static struct fwserial_unit_directory_data fwserial_unit_directory_data = { 2575static struct fwserial_unit_directory_data fwserial_unit_directory_data = {
2528 .len = 4, 2576 .len_crc = FW_ROM_LEN(4),
2529 .unit_specifier = FW_UNIT_SPECIFIER(LINUX_VENDOR_ID), 2577 .unit_specifier = FW_UNIT_SPECIFIER(LINUX_VENDOR_ID),
2530 .unit_sw_version = FW_UNIT_VERSION(FWSERIAL_VERSION), 2578 .unit_sw_version = FW_UNIT_VERSION(FWSERIAL_VERSION),
2531 .desc1_ofs = FW_ROM_DESCRIPTOR(1), 2579 .desc1_ofs = FW_ROM_DESCRIPTOR(1),
2532 .desc1_len = 5, 2580 .desc1_len_crc = FW_ROM_LEN(5),
2533 .desc1_data = { 2581 .desc1_data = {
2534 0x00000000, /* type = text */ 2582 0x00000000, /* type = text */
2535 0x00000000, /* enc = ASCII, lang EN */ 2583 0x00000000, /* enc = ASCII, lang EN */
@@ -2549,7 +2597,7 @@ static struct fw_descriptor fwserial_unit_directory = {
2549 * The management address is in the unit space region but above other known 2597 * The management address is in the unit space region but above other known
2550 * address users (to keep wild writes from causing havoc) 2598 * address users (to keep wild writes from causing havoc)
2551 */ 2599 */
2552const struct fw_address_region fwserial_mgmt_addr_region = { 2600static const struct fw_address_region fwserial_mgmt_addr_region = {
2553 .start = CSR_REGISTER_BASE + 0x1e0000ULL, 2601 .start = CSR_REGISTER_BASE + 0x1e0000ULL,
2554 .end = 0x1000000000000ULL, 2602 .end = 0x1000000000000ULL,
2555}; 2603};
@@ -2615,7 +2663,7 @@ static void fwserial_handle_plug_req(struct work_struct *work)
2615 2663
2616 spin_unlock_bh(&peer->lock); 2664 spin_unlock_bh(&peer->lock);
2617 if (port) 2665 if (port)
2618 fwserial_release_port(port); 2666 fwserial_release_port(port, false);
2619 2667
2620 rcode = fwserial_send_mgmt_sync(peer, pkt); 2668 rcode = fwserial_send_mgmt_sync(peer, pkt);
2621 2669
@@ -2637,7 +2685,7 @@ static void fwserial_handle_plug_req(struct work_struct *work)
2637cleanup: 2685cleanup:
2638 spin_unlock_bh(&peer->lock); 2686 spin_unlock_bh(&peer->lock);
2639 if (port) 2687 if (port)
2640 fwserial_release_port(port); 2688 fwserial_release_port(port, false);
2641 kfree(pkt); 2689 kfree(pkt);
2642 return; 2690 return;
2643} 2691}
@@ -2681,15 +2729,14 @@ static void fwserial_handle_unplug_req(struct work_struct *work)
2681 2729
2682 spin_lock_bh(&peer->lock); 2730 spin_lock_bh(&peer->lock);
2683 if (peer->state == FWPS_UNPLUG_RESPONDING) { 2731 if (peer->state == FWPS_UNPLUG_RESPONDING) {
2684 if (rcode == RCODE_COMPLETE) 2732 if (rcode != RCODE_COMPLETE)
2685 port = peer_revert_state(peer);
2686 else
2687 fwtty_err(&peer->unit, "UNPLUG_RSP error (%d)", rcode); 2733 fwtty_err(&peer->unit, "UNPLUG_RSP error (%d)", rcode);
2734 port = peer_revert_state(peer);
2688 } 2735 }
2689cleanup: 2736cleanup:
2690 spin_unlock_bh(&peer->lock); 2737 spin_unlock_bh(&peer->lock);
2691 if (port) 2738 if (port)
2692 fwserial_release_port(port); 2739 fwserial_release_port(port, true);
2693 kfree(pkt); 2740 kfree(pkt);
2694 return; 2741 return;
2695} 2742}
@@ -2700,6 +2747,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer,
2700 size_t len) 2747 size_t len)
2701{ 2748{
2702 struct fwtty_port *port = NULL; 2749 struct fwtty_port *port = NULL;
2750 bool reset = false;
2703 int rcode; 2751 int rcode;
2704 2752
2705 if (addr != fwserial_mgmt_addr_handler.offset || len < sizeof(pkt->hdr)) 2753 if (addr != fwserial_mgmt_addr_handler.offset || len < sizeof(pkt->hdr))
@@ -2775,6 +2823,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer,
2775 if (be16_to_cpu(pkt->hdr.code) & FWSC_RSP_NACK) 2823 if (be16_to_cpu(pkt->hdr.code) & FWSC_RSP_NACK)
2776 fwtty_notice(&peer->unit, "NACK unplug?"); 2824 fwtty_notice(&peer->unit, "NACK unplug?");
2777 port = peer_revert_state(peer); 2825 port = peer_revert_state(peer);
2826 reset = true;
2778 } 2827 }
2779 break; 2828 break;
2780 2829
@@ -2786,7 +2835,7 @@ static int fwserial_parse_mgmt_write(struct fwtty_peer *peer,
2786 spin_unlock_bh(&peer->lock); 2835 spin_unlock_bh(&peer->lock);
2787 2836
2788 if (port) 2837 if (port)
2789 fwserial_release_port(port); 2838 fwserial_release_port(port, reset);
2790 2839
2791 return rcode; 2840 return rcode;
2792} 2841}
@@ -2836,14 +2885,18 @@ static int __init fwserial_init(void)
2836{ 2885{
2837 int err, num_loops = !!(create_loop_dev); 2886 int err, num_loops = !!(create_loop_dev);
2838 2887
2888 /* XXX: placeholder for a "firewire" debugfs node */
2889 fwserial_debugfs = debugfs_create_dir(KBUILD_MODNAME, NULL);
2890
2839 /* num_ttys/num_ports must not be set above the static alloc avail */ 2891 /* num_ttys/num_ports must not be set above the static alloc avail */
2840 if (num_ttys + num_loops > MAX_CARD_PORTS) 2892 if (num_ttys + num_loops > MAX_CARD_PORTS)
2841 num_ttys = MAX_CARD_PORTS - num_loops; 2893 num_ttys = MAX_CARD_PORTS - num_loops;
2842 num_ports = num_ttys + num_loops; 2894 num_ports = num_ttys + num_loops;
2843 2895
2844 fwtty_driver = alloc_tty_driver(MAX_TOTAL_PORTS); 2896 fwtty_driver = tty_alloc_driver(MAX_TOTAL_PORTS, TTY_DRIVER_REAL_RAW
2845 if (!fwtty_driver) { 2897 | TTY_DRIVER_DYNAMIC_DEV);
2846 err = -ENOMEM; 2898 if (IS_ERR(fwtty_driver)) {
2899 err = PTR_ERR(fwtty_driver);
2847 return err; 2900 return err;
2848 } 2901 }
2849 2902
@@ -2853,9 +2906,6 @@ static int __init fwserial_init(void)
2853 fwtty_driver->minor_start = 0; 2906 fwtty_driver->minor_start = 0;
2854 fwtty_driver->type = TTY_DRIVER_TYPE_SERIAL; 2907 fwtty_driver->type = TTY_DRIVER_TYPE_SERIAL;
2855 fwtty_driver->subtype = SERIAL_TYPE_NORMAL; 2908 fwtty_driver->subtype = SERIAL_TYPE_NORMAL;
2856 fwtty_driver->flags = TTY_DRIVER_REAL_RAW |
2857 TTY_DRIVER_DYNAMIC_DEV;
2858
2859 fwtty_driver->init_termios = tty_std_termios; 2909 fwtty_driver->init_termios = tty_std_termios;
2860 fwtty_driver->init_termios.c_cflag |= CLOCAL; 2910 fwtty_driver->init_termios.c_cflag |= CLOCAL;
2861 tty_set_operations(fwtty_driver, &fwtty_ops); 2911 tty_set_operations(fwtty_driver, &fwtty_ops);
@@ -2866,12 +2916,38 @@ static int __init fwserial_init(void)
2866 goto put_tty; 2916 goto put_tty;
2867 } 2917 }
2868 2918
2919 if (create_loop_dev) {
2920 fwloop_driver = tty_alloc_driver(MAX_TOTAL_PORTS / num_ports,
2921 TTY_DRIVER_REAL_RAW
2922 | TTY_DRIVER_DYNAMIC_DEV);
2923 if (IS_ERR(fwloop_driver)) {
2924 err = PTR_ERR(fwloop_driver);
2925 goto unregister_driver;
2926 }
2927
2928 fwloop_driver->driver_name = KBUILD_MODNAME "_loop";
2929 fwloop_driver->name = loop_dev_name;
2930 fwloop_driver->major = 0;
2931 fwloop_driver->minor_start = 0;
2932 fwloop_driver->type = TTY_DRIVER_TYPE_SERIAL;
2933 fwloop_driver->subtype = SERIAL_TYPE_NORMAL;
2934 fwloop_driver->init_termios = tty_std_termios;
2935 fwloop_driver->init_termios.c_cflag |= CLOCAL;
2936 tty_set_operations(fwloop_driver, &fwloop_ops);
2937
2938 err = tty_register_driver(fwloop_driver);
2939 if (err) {
2940 driver_err("register loop driver failed (%d)", err);
2941 goto put_loop;
2942 }
2943 }
2944
2869 fwtty_txn_cache = kmem_cache_create("fwtty_txn_cache", 2945 fwtty_txn_cache = kmem_cache_create("fwtty_txn_cache",
2870 sizeof(struct fwtty_transaction), 2946 sizeof(struct fwtty_transaction),
2871 0, 0, fwtty_txn_constructor); 2947 0, 0, fwtty_txn_constructor);
2872 if (!fwtty_txn_cache) { 2948 if (!fwtty_txn_cache) {
2873 err = -ENOMEM; 2949 err = -ENOMEM;
2874 goto unregister_driver; 2950 goto unregister_loop;
2875 } 2951 }
2876 2952
2877 /* 2953 /*
@@ -2913,10 +2989,17 @@ remove_handler:
2913 fw_core_remove_address_handler(&fwserial_mgmt_addr_handler); 2989 fw_core_remove_address_handler(&fwserial_mgmt_addr_handler);
2914destroy_cache: 2990destroy_cache:
2915 kmem_cache_destroy(fwtty_txn_cache); 2991 kmem_cache_destroy(fwtty_txn_cache);
2992unregister_loop:
2993 if (create_loop_dev)
2994 tty_unregister_driver(fwloop_driver);
2995put_loop:
2996 if (create_loop_dev)
2997 put_tty_driver(fwloop_driver);
2916unregister_driver: 2998unregister_driver:
2917 tty_unregister_driver(fwtty_driver); 2999 tty_unregister_driver(fwtty_driver);
2918put_tty: 3000put_tty:
2919 put_tty_driver(fwtty_driver); 3001 put_tty_driver(fwtty_driver);
3002 debugfs_remove_recursive(fwserial_debugfs);
2920 return err; 3003 return err;
2921} 3004}
2922 3005
@@ -2926,8 +3009,13 @@ static void __exit fwserial_exit(void)
2926 fw_core_remove_descriptor(&fwserial_unit_directory); 3009 fw_core_remove_descriptor(&fwserial_unit_directory);
2927 fw_core_remove_address_handler(&fwserial_mgmt_addr_handler); 3010 fw_core_remove_address_handler(&fwserial_mgmt_addr_handler);
2928 kmem_cache_destroy(fwtty_txn_cache); 3011 kmem_cache_destroy(fwtty_txn_cache);
3012 if (create_loop_dev) {
3013 tty_unregister_driver(fwloop_driver);
3014 put_tty_driver(fwloop_driver);
3015 }
2929 tty_unregister_driver(fwtty_driver); 3016 tty_unregister_driver(fwtty_driver);
2930 put_tty_driver(fwtty_driver); 3017 put_tty_driver(fwtty_driver);
3018 debugfs_remove_recursive(fwserial_debugfs);
2931} 3019}
2932 3020
2933module_init(fwserial_init); 3021module_init(fwserial_init);
@@ -2940,4 +3028,3 @@ MODULE_DEVICE_TABLE(ieee1394, fwserial_id_table);
2940MODULE_PARM_DESC(ttys, "Number of ttys to create for each local firewire node"); 3028MODULE_PARM_DESC(ttys, "Number of ttys to create for each local firewire node");
2941MODULE_PARM_DESC(auto, "Auto-connect a tty to each firewire node discovered"); 3029MODULE_PARM_DESC(auto, "Auto-connect a tty to each firewire node discovered");
2942MODULE_PARM_DESC(loop, "Create a loopback device, fwloop<n>, with ttys"); 3030MODULE_PARM_DESC(loop, "Create a loopback device, fwloop<n>, with ttys");
2943MODULE_PARM_DESC(limit_bw, "Limit bandwidth utilization to 20%.");
diff --git a/drivers/staging/fwserial/fwserial.h b/drivers/staging/fwserial/fwserial.h
index caa1c1ea82d5..514f57173259 100644
--- a/drivers/staging/fwserial/fwserial.h
+++ b/drivers/staging/fwserial/fwserial.h
@@ -15,6 +15,7 @@
15#include <linux/serial_reg.h> 15#include <linux/serial_reg.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/seq_file.h> 17#include <linux/seq_file.h>
18#include <linux/debugfs.h>
18 19
19#include "dma_fifo.h" 20#include "dma_fifo.h"
20 21
@@ -193,7 +194,7 @@ struct buffered_rx {
193 * @port: underlying tty_port 194 * @port: underlying tty_port
194 * @device: tty device 195 * @device: tty device
195 * @index: index into port_table for this particular port 196 * @index: index into port_table for this particular port
196 * note: minor = index + FWSERIAL_TTY_START_MINOR 197 * note: minor = index + minor_start assigned by tty_alloc_driver()
197 * @serial: back pointer to the containing fw_serial 198 * @serial: back pointer to the containing fw_serial
198 * @rx_handler: bus address handler for unique addr region used by remotes 199 * @rx_handler: bus address handler for unique addr region used by remotes
199 * to communicate with this port. Every port uses 200 * to communicate with this port. Every port uses
@@ -279,7 +280,7 @@ struct fwtty_port {
279 loopback:1; 280 loopback:1;
280 unsigned long flags; 281 unsigned long flags;
281 282
282 struct fwtty_peer *peer; 283 struct fwtty_peer __rcu *peer;
283 284
284 struct async_icount icount; 285 struct async_icount icount;
285 struct stats stats; 286 struct stats stats;
@@ -338,6 +339,7 @@ struct fw_serial {
338 struct fw_card *card; 339 struct fw_card *card;
339 struct kref kref; 340 struct kref kref;
340 341
342 struct dentry *debugfs;
341 struct fwtty_peer *self; 343 struct fwtty_peer *self;
342 344
343 struct list_head list; 345 struct list_head list;
@@ -351,9 +353,8 @@ struct fw_serial {
351#define TTY_DEV_NAME "fwtty" /* ttyFW was taken */ 353#define TTY_DEV_NAME "fwtty" /* ttyFW was taken */
352static const char tty_dev_name[] = TTY_DEV_NAME; 354static const char tty_dev_name[] = TTY_DEV_NAME;
353static const char loop_dev_name[] = "fwloop"; 355static const char loop_dev_name[] = "fwloop";
354extern bool limit_bw;
355 356
356struct tty_driver *fwtty_driver; 357extern struct tty_driver *fwtty_driver;
357 358
358#define driver_err(s, v...) pr_err(KBUILD_MODNAME ": " s, ##v) 359#define driver_err(s, v...) pr_err(KBUILD_MODNAME ": " s, ##v)
359 360
@@ -370,18 +371,16 @@ static inline void fwtty_bind_console(struct fwtty_port *port,
370 371
371/* 372/*
372 * Returns the max send async payload size in bytes based on the unit device 373 * Returns the max send async payload size in bytes based on the unit device
373 * link speed - if set to limit bandwidth to max 20%, use lookup table 374 * link speed. Self-limiting asynchronous bandwidth (via reducing the payload)
375 * is not necessary and does not work, because
376 * 1) asynchronous traffic will absorb all available bandwidth (less that
377 * being used for isochronous traffic)
378 * 2) isochronous arbitration always wins.
374 */ 379 */
375static inline int link_speed_to_max_payload(unsigned speed) 380static inline int link_speed_to_max_payload(unsigned speed)
376{ 381{
377 static const int max_async[] = { 307, 614, 1229, 2458, }; 382 /* Max async payload is 4096 - see IEEE 1394-2008 tables 6-4, 16-18 */
378 BUILD_BUG_ON(ARRAY_SIZE(max_async) - 1 != SCODE_800); 383 return min(512 << speed, 4096);
379
380 speed = clamp(speed, (unsigned) SCODE_100, (unsigned) SCODE_800);
381 if (limit_bw)
382 return max_async[speed];
383 else
384 return 1 << (speed + 9);
385} 384}
386 385
387#endif /* _FIREWIRE_FWSERIAL_H */ 386#endif /* _FIREWIRE_FWSERIAL_H */
diff --git a/drivers/staging/gdm72xx/gdm_sdio.c b/drivers/staging/gdm72xx/gdm_sdio.c
index 8b8ed981d102..695762b0e942 100644
--- a/drivers/staging/gdm72xx/gdm_sdio.c
+++ b/drivers/staging/gdm72xx/gdm_sdio.c
@@ -156,10 +156,8 @@ static int init_sdio(struct sdiowm_dev *sdev)
156 spin_lock_init(&tx->lock); 156 spin_lock_init(&tx->lock);
157 157
158 tx->sdu_buf = kmalloc(SDU_TX_BUF_SIZE, GFP_KERNEL); 158 tx->sdu_buf = kmalloc(SDU_TX_BUF_SIZE, GFP_KERNEL);
159 if (tx->sdu_buf == NULL) { 159 if (tx->sdu_buf == NULL)
160 dev_err(&sdev->func->dev, "Failed to allocate SDU tx buffer.\n");
161 goto fail; 160 goto fail;
162 }
163 161
164 for (i = 0; i < MAX_NR_SDU_BUF; i++) { 162 for (i = 0; i < MAX_NR_SDU_BUF; i++) {
165 t = alloc_tx_struct(tx); 163 t = alloc_tx_struct(tx);
@@ -185,10 +183,8 @@ static int init_sdio(struct sdiowm_dev *sdev)
185 } 183 }
186 184
187 rx->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL); 185 rx->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
188 if (rx->rx_buf == NULL) { 186 if (rx->rx_buf == NULL)
189 dev_err(&sdev->func->dev, "Failed to allocate rx buffer.\n");
190 goto fail; 187 goto fail;
191 }
192 188
193 return 0; 189 return 0;
194 190
diff --git a/drivers/staging/gdm72xx/sdio_boot.c b/drivers/staging/gdm72xx/sdio_boot.c
index 6291829dcdcc..93046dda78f0 100644
--- a/drivers/staging/gdm72xx/sdio_boot.c
+++ b/drivers/staging/gdm72xx/sdio_boot.c
@@ -72,10 +72,8 @@ static int download_image(struct sdio_func *func, const char *img_name)
72 } 72 }
73 73
74 buf = kmalloc(DOWNLOAD_SIZE + TYPE_A_HEADER_SIZE, GFP_KERNEL); 74 buf = kmalloc(DOWNLOAD_SIZE + TYPE_A_HEADER_SIZE, GFP_KERNEL);
75 if (buf == NULL) { 75 if (buf == NULL)
76 dev_err(&func->dev, "Error: kmalloc\n");
77 return -ENOMEM; 76 return -ENOMEM;
78 }
79 77
80 img_len = firm->size; 78 img_len = firm->size;
81 79
@@ -141,11 +139,8 @@ int sdio_boot(struct sdio_func *func)
141 const char *rfs_name = FW_DIR FW_RFS; 139 const char *rfs_name = FW_DIR FW_RFS;
142 140
143 tx_buf = kmalloc(YMEM0_SIZE, GFP_KERNEL); 141 tx_buf = kmalloc(YMEM0_SIZE, GFP_KERNEL);
144 if (tx_buf == NULL) { 142 if (tx_buf == NULL)
145 dev_err(&func->dev, "Error: kmalloc: %s %d\n",
146 __func__, __LINE__);
147 return -ENOMEM; 143 return -ENOMEM;
148 }
149 144
150 ret = download_image(func, krn_name); 145 ret = download_image(func, krn_name);
151 if (ret) 146 if (ret)
diff --git a/drivers/staging/gdm72xx/usb_boot.c b/drivers/staging/gdm72xx/usb_boot.c
index 3e2103ae4eae..0d45eb680be5 100644
--- a/drivers/staging/gdm72xx/usb_boot.c
+++ b/drivers/staging/gdm72xx/usb_boot.c
@@ -158,10 +158,8 @@ int usb_boot(struct usb_device *usbdev, u16 pid)
158 } 158 }
159 159
160 tx_buf = kmalloc(DOWNLOAD_SIZE, GFP_KERNEL); 160 tx_buf = kmalloc(DOWNLOAD_SIZE, GFP_KERNEL);
161 if (tx_buf == NULL) { 161 if (tx_buf == NULL)
162 dev_err(&usbdev->dev, "Error: kmalloc\n");
163 return -ENOMEM; 162 return -ENOMEM;
164 }
165 163
166 if (firm->size < sizeof(hdr)) { 164 if (firm->size < sizeof(hdr)) {
167 dev_err(&usbdev->dev, "Cannot read the image info.\n"); 165 dev_err(&usbdev->dev, "Cannot read the image info.\n");
@@ -301,10 +299,8 @@ static int em_download_image(struct usb_device *usbdev, const char *img_name,
301 } 299 }
302 300
303 buf = kmalloc(DOWNLOAD_CHUCK + pad_size, GFP_KERNEL); 301 buf = kmalloc(DOWNLOAD_CHUCK + pad_size, GFP_KERNEL);
304 if (buf == NULL) { 302 if (buf == NULL)
305 dev_err(&usbdev->dev, "Error: kmalloc\n");
306 return -ENOMEM; 303 return -ENOMEM;
307 }
308 304
309 strcpy(buf+pad_size, type_string); 305 strcpy(buf+pad_size, type_string);
310 ret = gdm_wibro_send(usbdev, buf, strlen(type_string)+pad_size); 306 ret = gdm_wibro_send(usbdev, buf, strlen(type_string)+pad_size);
diff --git a/drivers/staging/goldfish/Kconfig b/drivers/staging/goldfish/Kconfig
new file mode 100644
index 000000000000..4e094602437c
--- /dev/null
+++ b/drivers/staging/goldfish/Kconfig
@@ -0,0 +1,13 @@
1config GOLDFISH_AUDIO
2 tristate "Goldfish AVD Audio Device"
3 depends on GOLDFISH
4 ---help---
5 Emulated audio channel for the Goldfish Android Virtual Device
6
7config MTD_GOLDFISH_NAND
8 tristate "Goldfish NAND device"
9 depends on GOLDFISH
10 depends on MTD
11 help
12 Drives the emulated NAND flash device on the Google Goldfish
13 Android virtual device.
diff --git a/drivers/staging/goldfish/Makefile b/drivers/staging/goldfish/Makefile
new file mode 100644
index 000000000000..dec34ad58162
--- /dev/null
+++ b/drivers/staging/goldfish/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for the Goldfish audio driver
3#
4
5obj-$(CONFIG_GOLDFISH_AUDIO) += goldfish_audio.o
6obj-$(CONFIG_MTD_GOLDFISH_NAND) += goldfish_nand.o
diff --git a/drivers/staging/goldfish/README b/drivers/staging/goldfish/README
new file mode 100644
index 000000000000..93d65b0f0f83
--- /dev/null
+++ b/drivers/staging/goldfish/README
@@ -0,0 +1,12 @@
1Audio
2-----
3- Move to using the ALSA framework not faking it
4- Fix the wrong user page DMA (moving to ALSA may fix that too)
5
6NAND
7----
8- Switch from spinlock to mutex
9- Remove excess checking of parameters in calls
10- Use dma coherent memory not kmalloc/__pa for the memory (this is just
11 a cleanliness issue not a correctness one)
12
diff --git a/drivers/staging/goldfish/goldfish_audio.c b/drivers/staging/goldfish/goldfish_audio.c
new file mode 100644
index 000000000000..d3bed21f4072
--- /dev/null
+++ b/drivers/staging/goldfish/goldfish_audio.c
@@ -0,0 +1,363 @@
1/* drivers/misc/goldfish_audio.c
2 *
3 * Copyright (C) 2007 Google, Inc.
4 * Copyright (C) 2012 Intel, Inc.
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/miscdevice.h>
19#include <linux/fs.h>
20#include <linux/platform_device.h>
21#include <linux/types.h>
22#include <linux/pci.h>
23#include <linux/interrupt.h>
24#include <linux/io.h>
25#include <linux/sched.h>
26#include <linux/dma-mapping.h>
27#include <linux/uaccess.h>
28
29MODULE_AUTHOR("Google, Inc.");
30MODULE_DESCRIPTION("Android QEMU Audio Driver");
31MODULE_LICENSE("GPL");
32MODULE_VERSION("1.0");
33
34struct goldfish_audio {
35 char __iomem *reg_base;
36 int irq;
37 spinlock_t lock;
38 wait_queue_head_t wait;
39
40 char __iomem *buffer_virt; /* combined buffer virtual address */
41 unsigned long buffer_phys; /* combined buffer physical address */
42
43 char __iomem *write_buffer1; /* write buffer 1 virtual address */
44 char __iomem *write_buffer2; /* write buffer 2 virtual address */
45 char __iomem *read_buffer; /* read buffer virtual address */
46 int buffer_status;
47 int read_supported; /* true if we have audio input support */
48};
49
50/* We will allocate two read buffers and two write buffers.
51 Having two read buffers facilitate stereo -> mono conversion.
52 Having two write buffers facilitate interleaved IO.
53*/
54#define READ_BUFFER_SIZE 16384
55#define WRITE_BUFFER_SIZE 16384
56#define COMBINED_BUFFER_SIZE ((2 * READ_BUFFER_SIZE) + \
57 (2 * WRITE_BUFFER_SIZE))
58
59#define AUDIO_READ(data, addr) (readl(data->reg_base + addr))
60#define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr))
61
62/* temporary variable used between goldfish_audio_probe() and
63 goldfish_audio_open() */
64static struct goldfish_audio *audio_data;
65
66enum {
67 /* audio status register */
68 AUDIO_INT_STATUS = 0x00,
69 /* set this to enable IRQ */
70 AUDIO_INT_ENABLE = 0x04,
71 /* set these to specify buffer addresses */
72 AUDIO_SET_WRITE_BUFFER_1 = 0x08,
73 AUDIO_SET_WRITE_BUFFER_2 = 0x0C,
74 /* set number of bytes in buffer to write */
75 AUDIO_WRITE_BUFFER_1 = 0x10,
76 AUDIO_WRITE_BUFFER_2 = 0x14,
77
78 /* true if audio input is supported */
79 AUDIO_READ_SUPPORTED = 0x18,
80 /* buffer to use for audio input */
81 AUDIO_SET_READ_BUFFER = 0x1C,
82
83 /* driver writes number of bytes to read */
84 AUDIO_START_READ = 0x20,
85
86 /* number of bytes available in read buffer */
87 AUDIO_READ_BUFFER_AVAILABLE = 0x24,
88
89 /* AUDIO_INT_STATUS bits */
90
91 /* this bit set when it is safe to write more bytes to the buffer */
92 AUDIO_INT_WRITE_BUFFER_1_EMPTY = 1U << 0,
93 AUDIO_INT_WRITE_BUFFER_2_EMPTY = 1U << 1,
94 AUDIO_INT_READ_BUFFER_FULL = 1U << 2,
95
96 AUDIO_INT_MASK = AUDIO_INT_WRITE_BUFFER_1_EMPTY |
97 AUDIO_INT_WRITE_BUFFER_2_EMPTY |
98 AUDIO_INT_READ_BUFFER_FULL,
99};
100
101
102static atomic_t open_count = ATOMIC_INIT(0);
103
104
105static ssize_t goldfish_audio_read(struct file *fp, char __user *buf,
106 size_t count, loff_t *pos)
107{
108 struct goldfish_audio *data = fp->private_data;
109 int length;
110 int result = 0;
111
112 if (!data->read_supported)
113 return -ENODEV;
114
115 while (count > 0) {
116 length = (count > READ_BUFFER_SIZE ? READ_BUFFER_SIZE : count);
117 AUDIO_WRITE(data, AUDIO_START_READ, length);
118
119 wait_event_interruptible(data->wait,
120 (data->buffer_status & AUDIO_INT_READ_BUFFER_FULL));
121
122 length = AUDIO_READ(data,
123 AUDIO_READ_BUFFER_AVAILABLE);
124
125 /* copy data to user space */
126 if (copy_to_user(buf, data->read_buffer, length))
127 return -EFAULT;
128
129 result += length;
130 buf += length;
131 count -= length;
132 }
133 return result;
134}
135
136static ssize_t goldfish_audio_write(struct file *fp, const char __user *buf,
137 size_t count, loff_t *pos)
138{
139 struct goldfish_audio *data = fp->private_data;
140 unsigned long irq_flags;
141 ssize_t result = 0;
142 char __iomem *kbuf;
143
144 while (count > 0) {
145 ssize_t copy = count;
146 if (copy > WRITE_BUFFER_SIZE)
147 copy = WRITE_BUFFER_SIZE;
148 wait_event_interruptible(data->wait, (data->buffer_status &
149 (AUDIO_INT_WRITE_BUFFER_1_EMPTY |
150 AUDIO_INT_WRITE_BUFFER_2_EMPTY)));
151
152 if ((data->buffer_status & AUDIO_INT_WRITE_BUFFER_1_EMPTY) != 0)
153 kbuf = data->write_buffer1;
154 else
155 kbuf = data->write_buffer2;
156
157 /* copy from user space to the appropriate buffer */
158 if (copy_from_user(kbuf, buf, copy)) {
159 result = -EFAULT;
160 break;
161 }
162
163 spin_lock_irqsave(&data->lock, irq_flags);
164 /* clear the buffer empty flag, and signal the emulator
165 * to start writing the buffer */
166 if (kbuf == data->write_buffer1) {
167 data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_1_EMPTY;
168 AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_1, copy);
169 } else {
170 data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_2_EMPTY;
171 AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_2, copy);
172 }
173 spin_unlock_irqrestore(&data->lock, irq_flags);
174
175 buf += copy;
176 result += copy;
177 count -= copy;
178 }
179 return result;
180}
181
182static int goldfish_audio_open(struct inode *ip, struct file *fp)
183{
184 if (!audio_data)
185 return -ENODEV;
186
187 if (atomic_inc_return(&open_count) == 1) {
188 fp->private_data = audio_data;
189 audio_data->buffer_status = (AUDIO_INT_WRITE_BUFFER_1_EMPTY |
190 AUDIO_INT_WRITE_BUFFER_2_EMPTY);
191 AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, AUDIO_INT_MASK);
192 return 0;
193 } else {
194 atomic_dec(&open_count);
195 return -EBUSY;
196 }
197}
198
199static int goldfish_audio_release(struct inode *ip, struct file *fp)
200{
201 atomic_dec(&open_count);
202 /* FIXME: surely this is wrong for the multi-opened case */
203 AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, 0);
204 return 0;
205}
206
207static long goldfish_audio_ioctl(struct file *fp, unsigned int cmd,
208 unsigned long arg)
209{
210 /* temporary workaround, until we switch to the ALSA API */
211 if (cmd == 315)
212 return -1;
213 else
214 return 0;
215}
216
217static irqreturn_t goldfish_audio_interrupt(int irq, void *dev_id)
218{
219 unsigned long irq_flags;
220 struct goldfish_audio *data = dev_id;
221 u32 status;
222
223 spin_lock_irqsave(&data->lock, irq_flags);
224
225 /* read buffer status flags */
226 status = AUDIO_READ(data, AUDIO_INT_STATUS);
227 status &= AUDIO_INT_MASK;
228 /* if buffers are newly empty, wake up blocked
229 goldfish_audio_write() call */
230 if (status) {
231 data->buffer_status = status;
232 wake_up(&data->wait);
233 }
234
235 spin_unlock_irqrestore(&data->lock, irq_flags);
236 return status ? IRQ_HANDLED : IRQ_NONE;
237}
238
239/* file operations for /dev/eac */
240static const struct file_operations goldfish_audio_fops = {
241 .owner = THIS_MODULE,
242 .read = goldfish_audio_read,
243 .write = goldfish_audio_write,
244 .open = goldfish_audio_open,
245 .release = goldfish_audio_release,
246 .unlocked_ioctl = goldfish_audio_ioctl,
247};
248
249static struct miscdevice goldfish_audio_device = {
250 .minor = MISC_DYNAMIC_MINOR,
251 .name = "eac",
252 .fops = &goldfish_audio_fops,
253};
254
255static int goldfish_audio_probe(struct platform_device *pdev)
256{
257 int ret;
258 struct resource *r;
259 struct goldfish_audio *data;
260 dma_addr_t buf_addr;
261
262 data = kzalloc(sizeof(*data), GFP_KERNEL);
263 if (data == NULL) {
264 ret = -ENOMEM;
265 goto err_data_alloc_failed;
266 }
267 spin_lock_init(&data->lock);
268 init_waitqueue_head(&data->wait);
269 platform_set_drvdata(pdev, data);
270
271 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
272 if (r == NULL) {
273 dev_err(&pdev->dev, "platform_get_resource failed\n");
274 ret = -ENODEV;
275 goto err_no_io_base;
276 }
277 data->reg_base = ioremap(r->start, PAGE_SIZE);
278 if (data->reg_base == NULL) {
279 ret = -ENOMEM;
280 goto err_no_io_base;
281 }
282
283 data->irq = platform_get_irq(pdev, 0);
284 if (data->irq < 0) {
285 dev_err(&pdev->dev, "platform_get_irq failed\n");
286 ret = -ENODEV;
287 goto err_no_irq;
288 }
289 data->buffer_virt = dma_alloc_coherent(&pdev->dev,
290 COMBINED_BUFFER_SIZE, &buf_addr, GFP_KERNEL);
291 if (data->buffer_virt == 0) {
292 ret = -ENOMEM;
293 dev_err(&pdev->dev, "allocate buffer failed\n");
294 goto err_alloc_write_buffer_failed;
295 }
296 data->buffer_phys = buf_addr;
297 data->write_buffer1 = data->buffer_virt;
298 data->write_buffer2 = data->buffer_virt + WRITE_BUFFER_SIZE;
299 data->read_buffer = data->buffer_virt + 2 * WRITE_BUFFER_SIZE;
300
301 ret = request_irq(data->irq, goldfish_audio_interrupt,
302 IRQF_SHARED, pdev->name, data);
303 if (ret) {
304 dev_err(&pdev->dev, "request_irq failed\n");
305 goto err_request_irq_failed;
306 }
307
308 ret = misc_register(&goldfish_audio_device);
309 if (ret) {
310 dev_err(&pdev->dev,
311 "misc_register returned %d in goldfish_audio_init\n",
312 ret);
313 goto err_misc_register_failed;
314 }
315
316 AUDIO_WRITE(data, AUDIO_SET_WRITE_BUFFER_1, buf_addr);
317 AUDIO_WRITE(data, AUDIO_SET_WRITE_BUFFER_2,
318 buf_addr + WRITE_BUFFER_SIZE);
319
320 data->read_supported = AUDIO_READ(data, AUDIO_READ_SUPPORTED);
321 if (data->read_supported)
322 AUDIO_WRITE(data, AUDIO_SET_READ_BUFFER,
323 buf_addr + 2 * WRITE_BUFFER_SIZE);
324
325 audio_data = data;
326 return 0;
327
328err_misc_register_failed:
329err_request_irq_failed:
330 dma_free_coherent(&pdev->dev, COMBINED_BUFFER_SIZE,
331 data->buffer_virt, data->buffer_phys);
332err_alloc_write_buffer_failed:
333err_no_irq:
334 iounmap(data->reg_base);
335err_no_io_base:
336 kfree(data);
337err_data_alloc_failed:
338 return ret;
339}
340
341static int goldfish_audio_remove(struct platform_device *pdev)
342{
343 struct goldfish_audio *data = platform_get_drvdata(pdev);
344
345 misc_deregister(&goldfish_audio_device);
346 free_irq(data->irq, data);
347 dma_free_coherent(&pdev->dev, COMBINED_BUFFER_SIZE,
348 data->buffer_virt, data->buffer_phys);
349 iounmap(data->reg_base);
350 kfree(data);
351 audio_data = NULL;
352 return 0;
353}
354
355static struct platform_driver goldfish_audio_driver = {
356 .probe = goldfish_audio_probe,
357 .remove = goldfish_audio_remove,
358 .driver = {
359 .name = "goldfish_audio"
360 }
361};
362
363module_platform_driver(goldfish_audio_driver);
diff --git a/drivers/staging/goldfish/goldfish_nand.c b/drivers/staging/goldfish/goldfish_nand.c
new file mode 100644
index 000000000000..ab1f01952b48
--- /dev/null
+++ b/drivers/staging/goldfish/goldfish_nand.c
@@ -0,0 +1,444 @@
1/*
2 * drivers/mtd/devices/goldfish_nand.c
3 *
4 * Copyright (C) 2007 Google, Inc.
5 * Copyright (C) 2012 Intel, Inc.
6 * Copyright (C) 2013 Intel, Inc.
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/io.h>
20#include <linux/device.h>
21#include <linux/module.h>
22#include <linux/slab.h>
23#include <linux/ioport.h>
24#include <linux/vmalloc.h>
25#include <linux/init.h>
26#include <linux/mtd/mtd.h>
27#include <linux/platform_device.h>
28
29#include <asm/div64.h>
30
31#include "goldfish_nand_reg.h"
32
33struct goldfish_nand {
34 spinlock_t lock;
35 unsigned char __iomem *base;
36 struct cmd_params *cmd_params;
37 size_t mtd_count;
38 struct mtd_info mtd[0];
39};
40
41static u32 goldfish_nand_cmd_with_params(struct mtd_info *mtd,
42 enum nand_cmd cmd, u64 addr, u32 len,
43 void *ptr, u32 *rv)
44{
45 u32 cmdp;
46 struct goldfish_nand *nand = mtd->priv;
47 struct cmd_params *cps = nand->cmd_params;
48 unsigned char __iomem *base = nand->base;
49
50 if (cps == NULL)
51 return -1;
52
53 switch (cmd) {
54 case NAND_CMD_ERASE:
55 cmdp = NAND_CMD_ERASE_WITH_PARAMS;
56 break;
57 case NAND_CMD_READ:
58 cmdp = NAND_CMD_READ_WITH_PARAMS;
59 break;
60 case NAND_CMD_WRITE:
61 cmdp = NAND_CMD_WRITE_WITH_PARAMS;
62 break;
63 default:
64 return -1;
65 }
66 cps->dev = mtd - nand->mtd;
67 cps->addr_high = (u32)(addr >> 32);
68 cps->addr_low = (u32)addr;
69 cps->transfer_size = len;
70 cps->data = (u32)ptr;
71 writel(cmdp, base + NAND_COMMAND);
72 *rv = cps->result;
73 return 0;
74}
75
76static u32 goldfish_nand_cmd(struct mtd_info *mtd, enum nand_cmd cmd,
77 u64 addr, u32 len, void *ptr)
78{
79 struct goldfish_nand *nand = mtd->priv;
80 u32 rv;
81 unsigned long irq_flags;
82 unsigned char __iomem *base = nand->base;
83
84 spin_lock_irqsave(&nand->lock, irq_flags);
85 if (goldfish_nand_cmd_with_params(mtd, cmd, addr, len, ptr, &rv)) {
86 writel(mtd - nand->mtd, base + NAND_DEV);
87 writel((u32)(addr >> 32), base + NAND_ADDR_HIGH);
88 writel((u32)addr, base + NAND_ADDR_LOW);
89 writel(len, base + NAND_TRANSFER_SIZE);
90 writel((u32)ptr, base + NAND_DATA);
91 writel(cmd, base + NAND_COMMAND);
92 rv = readl(base + NAND_RESULT);
93 }
94 spin_unlock_irqrestore(&nand->lock, irq_flags);
95 return rv;
96}
97
98static int goldfish_nand_erase(struct mtd_info *mtd, struct erase_info *instr)
99{
100 loff_t ofs = instr->addr;
101 u32 len = instr->len;
102 u32 rem;
103
104 if (ofs + len > mtd->size)
105 goto invalid_arg;
106 rem = do_div(ofs, mtd->writesize);
107 if (rem)
108 goto invalid_arg;
109 ofs *= (mtd->writesize + mtd->oobsize);
110
111 if (len % mtd->writesize)
112 goto invalid_arg;
113 len = len / mtd->writesize * (mtd->writesize + mtd->oobsize);
114
115 if (goldfish_nand_cmd(mtd, NAND_CMD_ERASE, ofs, len, NULL) != len) {
116 pr_err("goldfish_nand_erase: erase failed, start %llx, len %x, dev_size %llx, erase_size %x\n",
117 ofs, len, mtd->size, mtd->erasesize);
118 return -EIO;
119 }
120
121 instr->state = MTD_ERASE_DONE;
122 mtd_erase_callback(instr);
123
124 return 0;
125
126invalid_arg:
127 pr_err("goldfish_nand_erase: invalid erase, start %llx, len %x, dev_size %llx, erase_size %x\n",
128 ofs, len, mtd->size, mtd->erasesize);
129 return -EINVAL;
130}
131
132static int goldfish_nand_read_oob(struct mtd_info *mtd, loff_t ofs,
133 struct mtd_oob_ops *ops)
134{
135 u32 rem;
136
137 if (ofs + ops->len > mtd->size)
138 goto invalid_arg;
139 if (ops->datbuf && ops->len && ops->len != mtd->writesize)
140 goto invalid_arg;
141 if (ops->ooblen + ops->ooboffs > mtd->oobsize)
142 goto invalid_arg;
143
144 rem = do_div(ofs, mtd->writesize);
145 if (rem)
146 goto invalid_arg;
147 ofs *= (mtd->writesize + mtd->oobsize);
148
149 if (ops->datbuf)
150 ops->retlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, ofs,
151 ops->len, ops->datbuf);
152 ofs += mtd->writesize + ops->ooboffs;
153 if (ops->oobbuf)
154 ops->oobretlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, ofs,
155 ops->ooblen, ops->oobbuf);
156 return 0;
157
158invalid_arg:
159 pr_err("goldfish_nand_read_oob: invalid read, start %llx, len %zx, ooblen %zx, dev_size %llx, write_size %x\n",
160 ofs, ops->len, ops->ooblen, mtd->size, mtd->writesize);
161 return -EINVAL;
162}
163
164static int goldfish_nand_write_oob(struct mtd_info *mtd, loff_t ofs,
165 struct mtd_oob_ops *ops)
166{
167 u32 rem;
168
169 if (ofs + ops->len > mtd->size)
170 goto invalid_arg;
171 if (ops->len && ops->len != mtd->writesize)
172 goto invalid_arg;
173 if (ops->ooblen + ops->ooboffs > mtd->oobsize)
174 goto invalid_arg;
175
176 rem = do_div(ofs, mtd->writesize);
177 if (rem)
178 goto invalid_arg;
179 ofs *= (mtd->writesize + mtd->oobsize);
180
181 if (ops->datbuf)
182 ops->retlen = goldfish_nand_cmd(mtd, NAND_CMD_WRITE, ofs,
183 ops->len, ops->datbuf);
184 ofs += mtd->writesize + ops->ooboffs;
185 if (ops->oobbuf)
186 ops->oobretlen = goldfish_nand_cmd(mtd, NAND_CMD_WRITE, ofs,
187 ops->ooblen, ops->oobbuf);
188 return 0;
189
190invalid_arg:
191 pr_err("goldfish_nand_write_oob: invalid write, start %llx, len %zx, ooblen %zx, dev_size %llx, write_size %x\n",
192 ofs, ops->len, ops->ooblen, mtd->size, mtd->writesize);
193 return -EINVAL;
194}
195
196static int goldfish_nand_read(struct mtd_info *mtd, loff_t from, size_t len,
197 size_t *retlen, u_char *buf)
198{
199 u32 rem;
200
201 if (from + len > mtd->size)
202 goto invalid_arg;
203 if (len != mtd->writesize)
204 goto invalid_arg;
205
206 rem = do_div(from, mtd->writesize);
207 if (rem)
208 goto invalid_arg;
209 from *= (mtd->writesize + mtd->oobsize);
210
211 *retlen = goldfish_nand_cmd(mtd, NAND_CMD_READ, from, len, buf);
212 return 0;
213
214invalid_arg:
215 pr_err("goldfish_nand_read: invalid read, start %llx, len %zx, dev_size %llx, write_size %x\n",
216 from, len, mtd->size, mtd->writesize);
217 return -EINVAL;
218}
219
220static int goldfish_nand_write(struct mtd_info *mtd, loff_t to, size_t len,
221 size_t *retlen, const u_char *buf)
222{
223 u32 rem;
224
225 if (to + len > mtd->size)
226 goto invalid_arg;
227 if (len != mtd->writesize)
228 goto invalid_arg;
229
230 rem = do_div(to, mtd->writesize);
231 if (rem)
232 goto invalid_arg;
233 to *= (mtd->writesize + mtd->oobsize);
234
235 *retlen = goldfish_nand_cmd(mtd, NAND_CMD_WRITE, to, len, (void *)buf);
236 return 0;
237
238invalid_arg:
239 pr_err("goldfish_nand_write: invalid write, start %llx, len %zx, dev_size %llx, write_size %x\n",
240 to, len, mtd->size, mtd->writesize);
241 return -EINVAL;
242}
243
244static int goldfish_nand_block_isbad(struct mtd_info *mtd, loff_t ofs)
245{
246 u32 rem;
247
248 if (ofs >= mtd->size)
249 goto invalid_arg;
250
251 rem = do_div(ofs, mtd->erasesize);
252 if (rem)
253 goto invalid_arg;
254 ofs *= mtd->erasesize / mtd->writesize;
255 ofs *= (mtd->writesize + mtd->oobsize);
256
257 return goldfish_nand_cmd(mtd, NAND_CMD_BLOCK_BAD_GET, ofs, 0, NULL);
258
259invalid_arg:
260 pr_err("goldfish_nand_block_isbad: invalid arg, ofs %llx, dev_size %llx, write_size %x\n",
261 ofs, mtd->size, mtd->writesize);
262 return -EINVAL;
263}
264
265static int goldfish_nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
266{
267 u32 rem;
268
269 if (ofs >= mtd->size)
270 goto invalid_arg;
271
272 rem = do_div(ofs, mtd->erasesize);
273 if (rem)
274 goto invalid_arg;
275 ofs *= mtd->erasesize / mtd->writesize;
276 ofs *= (mtd->writesize + mtd->oobsize);
277
278 if (goldfish_nand_cmd(mtd, NAND_CMD_BLOCK_BAD_SET, ofs, 0, NULL) != 1)
279 return -EIO;
280 return 0;
281
282invalid_arg:
283 pr_err("goldfish_nand_block_markbad: invalid arg, ofs %llx, dev_size %llx, write_size %x\n",
284 ofs, mtd->size, mtd->writesize);
285 return -EINVAL;
286}
287
288static int nand_setup_cmd_params(struct platform_device *pdev,
289 struct goldfish_nand *nand)
290{
291 u64 paddr;
292 unsigned char __iomem *base = nand->base;
293
294 nand->cmd_params = devm_kzalloc(&pdev->dev,
295 sizeof(struct cmd_params), GFP_KERNEL);
296 if (!nand->cmd_params)
297 return -1;
298
299 paddr = __pa(nand->cmd_params);
300 writel((u32)(paddr >> 32), base + NAND_CMD_PARAMS_ADDR_HIGH);
301 writel((u32)paddr, base + NAND_CMD_PARAMS_ADDR_LOW);
302 return 0;
303}
304
305static int goldfish_nand_init_device(struct platform_device *pdev,
306 struct goldfish_nand *nand, int id)
307{
308 u32 name_len;
309 u32 result;
310 u32 flags;
311 unsigned long irq_flags;
312 unsigned char __iomem *base = nand->base;
313 struct mtd_info *mtd = &nand->mtd[id];
314 char *name;
315
316 spin_lock_irqsave(&nand->lock, irq_flags);
317 writel(id, base + NAND_DEV);
318 flags = readl(base + NAND_DEV_FLAGS);
319 name_len = readl(base + NAND_DEV_NAME_LEN);
320 mtd->writesize = readl(base + NAND_DEV_PAGE_SIZE);
321 mtd->size = readl(base + NAND_DEV_SIZE_LOW);
322 mtd->size |= (u64)readl(base + NAND_DEV_SIZE_HIGH) << 32;
323 mtd->oobsize = readl(base + NAND_DEV_EXTRA_SIZE);
324 mtd->oobavail = mtd->oobsize;
325 mtd->erasesize = readl(base + NAND_DEV_ERASE_SIZE) /
326 (mtd->writesize + mtd->oobsize) * mtd->writesize;
327 do_div(mtd->size, mtd->writesize + mtd->oobsize);
328 mtd->size *= mtd->writesize;
329 dev_dbg(&pdev->dev,
330 "goldfish nand dev%d: size %llx, page %d, extra %d, erase %d\n",
331 id, mtd->size, mtd->writesize, mtd->oobsize, mtd->erasesize);
332 spin_unlock_irqrestore(&nand->lock, irq_flags);
333
334 mtd->priv = nand;
335
336 mtd->name = name = devm_kzalloc(&pdev->dev, name_len + 1, GFP_KERNEL);
337 if (name == NULL)
338 return -ENOMEM;
339
340 result = goldfish_nand_cmd(mtd, NAND_CMD_GET_DEV_NAME, 0, name_len,
341 name);
342 if (result != name_len) {
343 dev_err(&pdev->dev,
344 "goldfish_nand_init_device failed to get dev name %d != %d\n",
345 result, name_len);
346 return -ENODEV;
347 }
348 ((char *) mtd->name)[name_len] = '\0';
349
350 /* Setup the MTD structure */
351 mtd->type = MTD_NANDFLASH;
352 mtd->flags = MTD_CAP_NANDFLASH;
353 if (flags & NAND_DEV_FLAG_READ_ONLY)
354 mtd->flags &= ~MTD_WRITEABLE;
355 if (flags & NAND_DEV_FLAG_CMD_PARAMS_CAP)
356 nand_setup_cmd_params(pdev, nand);
357
358 mtd->owner = THIS_MODULE;
359 mtd->_erase = goldfish_nand_erase;
360 mtd->_read = goldfish_nand_read;
361 mtd->_write = goldfish_nand_write;
362 mtd->_read_oob = goldfish_nand_read_oob;
363 mtd->_write_oob = goldfish_nand_write_oob;
364 mtd->_block_isbad = goldfish_nand_block_isbad;
365 mtd->_block_markbad = goldfish_nand_block_markbad;
366
367 if (mtd_device_register(mtd, NULL, 0))
368 return -EIO;
369
370 return 0;
371}
372
373static int goldfish_nand_probe(struct platform_device *pdev)
374{
375 u32 num_dev;
376 int i;
377 int err;
378 u32 num_dev_working;
379 u32 version;
380 struct resource *r;
381 struct goldfish_nand *nand;
382 unsigned char __iomem *base;
383
384 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
385 if (r == NULL)
386 return -ENODEV;
387
388 base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE);
389 if (base == NULL)
390 return -ENOMEM;
391
392 version = readl(base + NAND_VERSION);
393 if (version != NAND_VERSION_CURRENT) {
394 dev_err(&pdev->dev,
395 "goldfish_nand_init: version mismatch, got %d, expected %d\n",
396 version, NAND_VERSION_CURRENT);
397 return -ENODEV;
398 }
399 num_dev = readl(base + NAND_NUM_DEV);
400 if (num_dev == 0)
401 return -ENODEV;
402
403 nand = devm_kzalloc(&pdev->dev, sizeof(*nand) +
404 sizeof(struct mtd_info) * num_dev, GFP_KERNEL);
405 if (nand == NULL)
406 return -ENOMEM;
407
408 spin_lock_init(&nand->lock);
409 nand->base = base;
410 nand->mtd_count = num_dev;
411 platform_set_drvdata(pdev, nand);
412
413 num_dev_working = 0;
414 for (i = 0; i < num_dev; i++) {
415 err = goldfish_nand_init_device(pdev, nand, i);
416 if (err == 0)
417 num_dev_working++;
418 }
419 if (num_dev_working == 0)
420 return -ENODEV;
421 return 0;
422}
423
424static int goldfish_nand_remove(struct platform_device *pdev)
425{
426 struct goldfish_nand *nand = platform_get_drvdata(pdev);
427 int i;
428 for (i = 0; i < nand->mtd_count; i++) {
429 if (nand->mtd[i].name)
430 mtd_device_unregister(&nand->mtd[i]);
431 }
432 return 0;
433}
434
435static struct platform_driver goldfish_nand_driver = {
436 .probe = goldfish_nand_probe,
437 .remove = goldfish_nand_remove,
438 .driver = {
439 .name = "goldfish_nand"
440 }
441};
442
443module_platform_driver(goldfish_nand_driver);
444MODULE_LICENSE("GPL");
diff --git a/drivers/staging/goldfish/goldfish_nand_reg.h b/drivers/staging/goldfish/goldfish_nand_reg.h
new file mode 100644
index 000000000000..956c6c304b6e
--- /dev/null
+++ b/drivers/staging/goldfish/goldfish_nand_reg.h
@@ -0,0 +1,72 @@
1/* drivers/mtd/devices/goldfish_nand_reg.h
2**
3** Copyright (C) 2007 Google, Inc.
4**
5** This software is licensed under the terms of the GNU General Public
6** License version 2, as published by the Free Software Foundation, and
7** may be copied, distributed, and modified under those terms.
8**
9** This program is distributed in the hope that it will be useful,
10** but WITHOUT ANY WARRANTY; without even the implied warranty of
11** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12** GNU General Public License for more details.
13**
14*/
15
16#ifndef GOLDFISH_NAND_REG_H
17#define GOLDFISH_NAND_REG_H
18
19enum nand_cmd {
20 NAND_CMD_GET_DEV_NAME, /* Write device name for NAND_DEV to NAND_DATA (vaddr) */
21 NAND_CMD_READ,
22 NAND_CMD_WRITE,
23 NAND_CMD_ERASE,
24 NAND_CMD_BLOCK_BAD_GET, /* NAND_RESULT is 1 if block is bad, 0 if it is not */
25 NAND_CMD_BLOCK_BAD_SET,
26 NAND_CMD_READ_WITH_PARAMS,
27 NAND_CMD_WRITE_WITH_PARAMS,
28 NAND_CMD_ERASE_WITH_PARAMS
29};
30
31enum nand_dev_flags {
32 NAND_DEV_FLAG_READ_ONLY = 0x00000001,
33 NAND_DEV_FLAG_CMD_PARAMS_CAP = 0x00000002,
34};
35
36#define NAND_VERSION_CURRENT (1)
37
38enum nand_reg {
39 /* Global */
40 NAND_VERSION = 0x000,
41 NAND_NUM_DEV = 0x004,
42 NAND_DEV = 0x008,
43
44 /* Dev info */
45 NAND_DEV_FLAGS = 0x010,
46 NAND_DEV_NAME_LEN = 0x014,
47 NAND_DEV_PAGE_SIZE = 0x018,
48 NAND_DEV_EXTRA_SIZE = 0x01c,
49 NAND_DEV_ERASE_SIZE = 0x020,
50 NAND_DEV_SIZE_LOW = 0x028,
51 NAND_DEV_SIZE_HIGH = 0x02c,
52
53 /* Command */
54 NAND_RESULT = 0x040,
55 NAND_COMMAND = 0x044,
56 NAND_DATA = 0x048,
57 NAND_TRANSFER_SIZE = 0x04c,
58 NAND_ADDR_LOW = 0x050,
59 NAND_ADDR_HIGH = 0x054,
60 NAND_CMD_PARAMS_ADDR_LOW = 0x058,
61 NAND_CMD_PARAMS_ADDR_HIGH = 0x05c,
62};
63
64struct cmd_params {
65 uint32_t dev;
66 uint32_t addr_low;
67 uint32_t addr_high;
68 uint32_t transfer_size;
69 uint32_t data;
70 uint32_t result;
71};
72#endif
diff --git a/drivers/staging/iio/Kconfig b/drivers/staging/iio/Kconfig
index ca56c75a35fc..dc267175a2b5 100644
--- a/drivers/staging/iio/Kconfig
+++ b/drivers/staging/iio/Kconfig
@@ -12,19 +12,6 @@ config IIO_ST_HWMON
12 map allows IIO devices to provide basic hwmon functionality 12 map allows IIO devices to provide basic hwmon functionality
13 for those channels specified in the map. 13 for those channels specified in the map.
14 14
15if IIO_BUFFER
16
17config IIO_SW_RING
18 select IIO_TRIGGER
19 tristate "Industrial I/O lock free software ring"
20 help
21 Example software ring buffer implementation. The design aim
22 of this particular realization was to minimize write locking
23 with the intention that some devices would be able to write
24 in interrupt context.
25
26endif # IIO_BUFFER
27
28source "drivers/staging/iio/accel/Kconfig" 15source "drivers/staging/iio/accel/Kconfig"
29source "drivers/staging/iio/adc/Kconfig" 16source "drivers/staging/iio/adc/Kconfig"
30source "drivers/staging/iio/addac/Kconfig" 17source "drivers/staging/iio/addac/Kconfig"
@@ -32,7 +19,6 @@ source "drivers/staging/iio/cdc/Kconfig"
32source "drivers/staging/iio/frequency/Kconfig" 19source "drivers/staging/iio/frequency/Kconfig"
33source "drivers/staging/iio/gyro/Kconfig" 20source "drivers/staging/iio/gyro/Kconfig"
34source "drivers/staging/iio/impedance-analyzer/Kconfig" 21source "drivers/staging/iio/impedance-analyzer/Kconfig"
35source "drivers/staging/iio/imu/Kconfig"
36source "drivers/staging/iio/light/Kconfig" 22source "drivers/staging/iio/light/Kconfig"
37source "drivers/staging/iio/magnetometer/Kconfig" 23source "drivers/staging/iio/magnetometer/Kconfig"
38source "drivers/staging/iio/meter/Kconfig" 24source "drivers/staging/iio/meter/Kconfig"
diff --git a/drivers/staging/iio/Makefile b/drivers/staging/iio/Makefile
index fa6937d92ee3..158e0a017e7b 100644
--- a/drivers/staging/iio/Makefile
+++ b/drivers/staging/iio/Makefile
@@ -2,8 +2,6 @@
2# Makefile for the industrial I/O core. 2# Makefile for the industrial I/O core.
3# 3#
4 4
5obj-$(CONFIG_IIO_SW_RING) += ring_sw.o
6
7obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o 5obj-$(CONFIG_IIO_SIMPLE_DUMMY) += iio_dummy.o
8iio_dummy-y := iio_simple_dummy.o 6iio_dummy-y := iio_simple_dummy.o
9iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_EVENTS) += iio_simple_dummy_events.o 7iio_dummy-$(CONFIG_IIO_SIMPLE_DUMMY_EVENTS) += iio_simple_dummy_events.o
@@ -20,7 +18,6 @@ obj-y += cdc/
20obj-y += frequency/ 18obj-y += frequency/
21obj-y += gyro/ 19obj-y += gyro/
22obj-y += impedance-analyzer/ 20obj-y += impedance-analyzer/
23obj-y += imu/
24obj-y += light/ 21obj-y += light/
25obj-y += magnetometer/ 22obj-y += magnetometer/
26obj-y += meter/ 23obj-y += meter/
diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig
index 2b54430f2d99..e2e786dc9c7b 100644
--- a/drivers/staging/iio/accel/Kconfig
+++ b/drivers/staging/iio/accel/Kconfig
@@ -56,45 +56,17 @@ config ADIS16240
56 Say yes here to build support for Analog Devices adis16240 programmable 56 Say yes here to build support for Analog Devices adis16240 programmable
57 impact Sensor and recorder. 57 impact Sensor and recorder.
58 58
59config KXSD9
60 tristate "Kionix KXSD9 Accelerometer Driver"
61 depends on SPI
62 help
63 Say yes here to build support for the Kionix KXSD9 accelerometer.
64 Currently this only supports the device via an SPI interface.
65
66config LIS3L02DQ 59config LIS3L02DQ
67 tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver" 60 tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver"
68 depends on SPI 61 depends on SPI
69 select IIO_TRIGGER if IIO_BUFFER 62 select IIO_TRIGGER if IIO_BUFFER
70 depends on !IIO_BUFFER || IIO_KFIFO_BUF || IIO_SW_RING 63 depends on !IIO_BUFFER || IIO_KFIFO_BUF
71 depends on GENERIC_GPIO 64 depends on GENERIC_GPIO
72 help 65 help
73 Say yes here to build SPI support for the ST microelectronics 66 Say yes here to build SPI support for the ST microelectronics
74 accelerometer. The driver supplies direct access via sysfs files 67 accelerometer. The driver supplies direct access via sysfs files
75 and an event interface via a character device. 68 and an event interface via a character device.
76 69
77choice
78 prompt "Buffer type"
79 depends on LIS3L02DQ && IIO_BUFFER
80
81config LIS3L02DQ_BUF_KFIFO
82 depends on IIO_KFIFO_BUF
83 bool "Simple FIFO"
84 help
85 Kfifo based FIFO. Does not provide any events so it is up
86 to userspace to ensure it reads often enough that data is not
87 lost.
88
89config LIS3L02DQ_BUF_RING_SW
90 depends on IIO_SW_RING
91 bool "IIO Software Ring"
92 help
93 Original IIO ring buffer implementation. Provides simple
94 buffer events, half full etc.
95
96endchoice
97
98config SCA3000 70config SCA3000
99 depends on IIO_BUFFER 71 depends on IIO_BUFFER
100 depends on SPI 72 depends on SPI
diff --git a/drivers/staging/iio/accel/Makefile b/drivers/staging/iio/accel/Makefile
index 8e7ee0368519..1ed137f1a506 100644
--- a/drivers/staging/iio/accel/Makefile
+++ b/drivers/staging/iio/accel/Makefile
@@ -20,8 +20,6 @@ obj-$(CONFIG_ADIS16220) += adis16220.o
20adis16240-y := adis16240_core.o 20adis16240-y := adis16240_core.o
21obj-$(CONFIG_ADIS16240) += adis16240.o 21obj-$(CONFIG_ADIS16240) += adis16240.o
22 22
23obj-$(CONFIG_KXSD9) += kxsd9.o
24
25lis3l02dq-y := lis3l02dq_core.o 23lis3l02dq-y := lis3l02dq_core.o
26lis3l02dq-$(CONFIG_IIO_BUFFER) += lis3l02dq_ring.o 24lis3l02dq-$(CONFIG_IIO_BUFFER) += lis3l02dq_ring.o
27obj-$(CONFIG_LIS3L02DQ) += lis3l02dq.o 25obj-$(CONFIG_LIS3L02DQ) += lis3l02dq.o
diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h
index 2bac7221837c..0a8ea8270866 100644
--- a/drivers/staging/iio/accel/lis3l02dq.h
+++ b/drivers/staging/iio/accel/lis3l02dq.h
@@ -185,14 +185,6 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev);
185int lis3l02dq_configure_buffer(struct iio_dev *indio_dev); 185int lis3l02dq_configure_buffer(struct iio_dev *indio_dev);
186void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev); 186void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev);
187 187
188#ifdef CONFIG_LIS3L02DQ_BUF_RING_SW
189#define lis3l02dq_free_buf iio_sw_rb_free
190#define lis3l02dq_alloc_buf iio_sw_rb_allocate
191#endif
192#ifdef CONFIG_LIS3L02DQ_BUF_KFIFO
193#define lis3l02dq_free_buf iio_kfifo_free
194#define lis3l02dq_alloc_buf iio_kfifo_allocate
195#endif
196irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private); 188irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private);
197#define lis3l02dq_th lis3l02dq_data_rdy_trig_poll 189#define lis3l02dq_th lis3l02dq_data_rdy_trig_poll
198 190
diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
index 37ed1b8ebb6f..0e019306439c 100644
--- a/drivers/staging/iio/accel/lis3l02dq_core.c
+++ b/drivers/staging/iio/accel/lis3l02dq_core.c
@@ -53,7 +53,6 @@ int lis3l02dq_spi_read_reg_8(struct iio_dev *indio_dev,
53 u8 reg_address, u8 *val) 53 u8 reg_address, u8 *val)
54{ 54{
55 struct lis3l02dq_state *st = iio_priv(indio_dev); 55 struct lis3l02dq_state *st = iio_priv(indio_dev);
56 struct spi_message msg;
57 int ret; 56 int ret;
58 struct spi_transfer xfer = { 57 struct spi_transfer xfer = {
59 .tx_buf = st->tx, 58 .tx_buf = st->tx,
@@ -66,9 +65,7 @@ int lis3l02dq_spi_read_reg_8(struct iio_dev *indio_dev,
66 st->tx[0] = LIS3L02DQ_READ_REG(reg_address); 65 st->tx[0] = LIS3L02DQ_READ_REG(reg_address);
67 st->tx[1] = 0; 66 st->tx[1] = 0;
68 67
69 spi_message_init(&msg); 68 ret = spi_sync_transfer(st->us, &xfer, 1);
70 spi_message_add_tail(&xfer, &msg);
71 ret = spi_sync(st->us, &msg);
72 *val = st->rx[1]; 69 *val = st->rx[1];
73 mutex_unlock(&st->buf_lock); 70 mutex_unlock(&st->buf_lock);
74 71
@@ -109,7 +106,6 @@ static int lis3l02dq_spi_write_reg_s16(struct iio_dev *indio_dev,
109 s16 value) 106 s16 value)
110{ 107{
111 int ret; 108 int ret;
112 struct spi_message msg;
113 struct lis3l02dq_state *st = iio_priv(indio_dev); 109 struct lis3l02dq_state *st = iio_priv(indio_dev);
114 struct spi_transfer xfers[] = { { 110 struct spi_transfer xfers[] = { {
115 .tx_buf = st->tx, 111 .tx_buf = st->tx,
@@ -129,10 +125,7 @@ static int lis3l02dq_spi_write_reg_s16(struct iio_dev *indio_dev,
129 st->tx[2] = LIS3L02DQ_WRITE_REG(lower_reg_address + 1); 125 st->tx[2] = LIS3L02DQ_WRITE_REG(lower_reg_address + 1);
130 st->tx[3] = (value >> 8) & 0xFF; 126 st->tx[3] = (value >> 8) & 0xFF;
131 127
132 spi_message_init(&msg); 128 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
133 spi_message_add_tail(&xfers[0], &msg);
134 spi_message_add_tail(&xfers[1], &msg);
135 ret = spi_sync(st->us, &msg);
136 mutex_unlock(&st->buf_lock); 129 mutex_unlock(&st->buf_lock);
137 130
138 return ret; 131 return ret;
@@ -143,8 +136,6 @@ static int lis3l02dq_read_reg_s16(struct iio_dev *indio_dev,
143 int *val) 136 int *val)
144{ 137{
145 struct lis3l02dq_state *st = iio_priv(indio_dev); 138 struct lis3l02dq_state *st = iio_priv(indio_dev);
146
147 struct spi_message msg;
148 int ret; 139 int ret;
149 s16 tempval; 140 s16 tempval;
150 struct spi_transfer xfers[] = { { 141 struct spi_transfer xfers[] = { {
@@ -167,10 +158,7 @@ static int lis3l02dq_read_reg_s16(struct iio_dev *indio_dev,
167 st->tx[2] = LIS3L02DQ_READ_REG(lower_reg_address + 1); 158 st->tx[2] = LIS3L02DQ_READ_REG(lower_reg_address + 1);
168 st->tx[3] = 0; 159 st->tx[3] = 0;
169 160
170 spi_message_init(&msg); 161 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
171 spi_message_add_tail(&xfers[0], &msg);
172 spi_message_add_tail(&xfers[1], &msg);
173 ret = spi_sync(st->us, &msg);
174 if (ret) { 162 if (ret) {
175 dev_err(&st->us->dev, "problem when reading 16 bit register"); 163 dev_err(&st->us->dev, "problem when reading 16 bit register");
176 goto error_ret; 164 goto error_ret;
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index bc38651c315e..e676403ea3ea 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -7,7 +7,6 @@
7#include <linux/export.h> 7#include <linux/export.h>
8 8
9#include <linux/iio/iio.h> 9#include <linux/iio/iio.h>
10#include "../ring_sw.h"
11#include <linux/iio/kfifo_buf.h> 10#include <linux/iio/kfifo_buf.h>
12#include <linux/iio/trigger.h> 11#include <linux/iio/trigger.h>
13#include <linux/iio/trigger_consumer.h> 12#include <linux/iio/trigger_consumer.h>
@@ -141,11 +140,8 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
141 char *data; 140 char *data;
142 141
143 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 142 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
144 if (data == NULL) { 143 if (data == NULL)
145 dev_err(indio_dev->dev.parent,
146 "memory alloc failed in buffer bh");
147 goto done; 144 goto done;
148 }
149 145
150 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 146 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
151 len = lis3l02dq_get_buffer_element(indio_dev, data); 147 len = lis3l02dq_get_buffer_element(indio_dev, data);
@@ -318,7 +314,7 @@ void lis3l02dq_remove_trigger(struct iio_dev *indio_dev)
318void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev) 314void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev)
319{ 315{
320 iio_dealloc_pollfunc(indio_dev->pollfunc); 316 iio_dealloc_pollfunc(indio_dev->pollfunc);
321 lis3l02dq_free_buf(indio_dev->buffer); 317 iio_kfifo_free(indio_dev->buffer);
322} 318}
323 319
324static int lis3l02dq_buffer_postenable(struct iio_dev *indio_dev) 320static int lis3l02dq_buffer_postenable(struct iio_dev *indio_dev)
@@ -401,7 +397,7 @@ int lis3l02dq_configure_buffer(struct iio_dev *indio_dev)
401 int ret; 397 int ret;
402 struct iio_buffer *buffer; 398 struct iio_buffer *buffer;
403 399
404 buffer = lis3l02dq_alloc_buf(indio_dev); 400 buffer = iio_kfifo_allocate(indio_dev);
405 if (!buffer) 401 if (!buffer)
406 return -ENOMEM; 402 return -ENOMEM;
407 403
@@ -427,6 +423,6 @@ int lis3l02dq_configure_buffer(struct iio_dev *indio_dev)
427 return 0; 423 return 0;
428 424
429error_iio_sw_rb_free: 425error_iio_sw_rb_free:
430 lis3l02dq_free_buf(indio_dev->buffer); 426 iio_kfifo_free(indio_dev->buffer);
431 return ret; 427 return ret;
432} 428}
diff --git a/drivers/staging/iio/accel/sca3000_core.c b/drivers/staging/iio/accel/sca3000_core.c
index 414d3cad55a7..14683f583ccf 100644
--- a/drivers/staging/iio/accel/sca3000_core.c
+++ b/drivers/staging/iio/accel/sca3000_core.c
@@ -90,7 +90,6 @@ int sca3000_read_data_short(struct sca3000_state *st,
90 uint8_t reg_address_high, 90 uint8_t reg_address_high,
91 int len) 91 int len)
92{ 92{
93 struct spi_message msg;
94 struct spi_transfer xfer[2] = { 93 struct spi_transfer xfer[2] = {
95 { 94 {
96 .len = 1, 95 .len = 1,
@@ -101,11 +100,8 @@ int sca3000_read_data_short(struct sca3000_state *st,
101 } 100 }
102 }; 101 };
103 st->tx[0] = SCA3000_READ_REG(reg_address_high); 102 st->tx[0] = SCA3000_READ_REG(reg_address_high);
104 spi_message_init(&msg);
105 spi_message_add_tail(&xfer[0], &msg);
106 spi_message_add_tail(&xfer[1], &msg);
107 103
108 return spi_sync(st->us, &msg); 104 return spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
109} 105}
110 106
111/** 107/**
@@ -133,7 +129,6 @@ static int sca3000_reg_lock_on(struct sca3000_state *st)
133 **/ 129 **/
134static int __sca3000_unlock_reg_lock(struct sca3000_state *st) 130static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
135{ 131{
136 struct spi_message msg;
137 struct spi_transfer xfer[3] = { 132 struct spi_transfer xfer[3] = {
138 { 133 {
139 .len = 2, 134 .len = 2,
@@ -154,12 +149,8 @@ static int __sca3000_unlock_reg_lock(struct sca3000_state *st)
154 st->tx[3] = 0x50; 149 st->tx[3] = 0x50;
155 st->tx[4] = SCA3000_WRITE_REG(SCA3000_REG_ADDR_UNLOCK); 150 st->tx[4] = SCA3000_WRITE_REG(SCA3000_REG_ADDR_UNLOCK);
156 st->tx[5] = 0xA0; 151 st->tx[5] = 0xA0;
157 spi_message_init(&msg);
158 spi_message_add_tail(&xfer[0], &msg);
159 spi_message_add_tail(&xfer[1], &msg);
160 spi_message_add_tail(&xfer[2], &msg);
161 152
162 return spi_sync(st->us, &msg); 153 return spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
163} 154}
164 155
165/** 156/**
diff --git a/drivers/staging/iio/accel/sca3000_ring.c b/drivers/staging/iio/accel/sca3000_ring.c
index cbec2f1665e5..3e5e860aa38e 100644
--- a/drivers/staging/iio/accel/sca3000_ring.c
+++ b/drivers/staging/iio/accel/sca3000_ring.c
@@ -39,7 +39,6 @@ static int sca3000_read_data(struct sca3000_state *st,
39 int len) 39 int len)
40{ 40{
41 int ret; 41 int ret;
42 struct spi_message msg;
43 struct spi_transfer xfer[2] = { 42 struct spi_transfer xfer[2] = {
44 { 43 {
45 .len = 1, 44 .len = 1,
@@ -55,10 +54,7 @@ static int sca3000_read_data(struct sca3000_state *st,
55 } 54 }
56 xfer[1].rx_buf = *rx_p; 55 xfer[1].rx_buf = *rx_p;
57 st->tx[0] = SCA3000_READ_REG(reg_address_high); 56 st->tx[0] = SCA3000_READ_REG(reg_address_high);
58 spi_message_init(&msg); 57 ret = spi_sync_transfer(st->us, xfer, ARRAY_SIZE(xfer));
59 spi_message_add_tail(&xfer[0], &msg);
60 spi_message_add_tail(&xfer[1], &msg);
61 ret = spi_sync(st->us, &msg);
62 if (ret) { 58 if (ret) {
63 dev_err(get_device(&st->us->dev), "problem reading register"); 59 dev_err(get_device(&st->us->dev), "problem reading register");
64 goto error_free_rx; 60 goto error_free_rx;
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index fb8c239b0c88..7b2a01d64f5e 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -119,12 +119,12 @@ config LPC32XX_ADC
119 via sysfs. 119 via sysfs.
120 120
121config MXS_LRADC 121config MXS_LRADC
122 tristate "Freescale i.MX28 LRADC" 122 tristate "Freescale i.MX23/i.MX28 LRADC"
123 depends on ARCH_MXS 123 depends on ARCH_MXS
124 select IIO_BUFFER 124 select IIO_BUFFER
125 select IIO_TRIGGERED_BUFFER 125 select IIO_TRIGGERED_BUFFER
126 help 126 help
127 Say yes here to build support for i.MX28 LRADC convertor 127 Say yes here to build support for i.MX23/i.MX28 LRADC convertor
128 built into these chips. 128 built into these chips.
129 129
130 To compile this driver as a module, choose M here: the 130 To compile this driver as a module, choose M here: the
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index fa81a491e790..1f190c1b12a6 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -199,12 +199,8 @@ static int __ad7280_read32(struct spi_device *spi, unsigned *val)
199 .rx_buf = &rx_buf, 199 .rx_buf = &rx_buf,
200 .len = 4, 200 .len = 4,
201 }; 201 };
202 struct spi_message m;
203 202
204 spi_message_init(&m); 203 ret = spi_sync_transfer(spi, &t, 1);
205 spi_message_add_tail(&t, &m);
206
207 ret = spi_sync(spi, &m);
208 if (ret) 204 if (ret)
209 return ret; 205 return ret;
210 206
diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index 3d562da039db..55a459b61907 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -33,6 +33,8 @@
33#include <linux/stmp_device.h> 33#include <linux/stmp_device.h>
34#include <linux/bitops.h> 34#include <linux/bitops.h>
35#include <linux/completion.h> 35#include <linux/completion.h>
36#include <linux/delay.h>
37#include <linux/input.h>
36 38
37#include <mach/mxs.h> 39#include <mach/mxs.h>
38#include <mach/common.h> 40#include <mach/common.h>
@@ -60,7 +62,39 @@
60#define LRADC_DELAY_TIMER_PER 200 62#define LRADC_DELAY_TIMER_PER 200
61#define LRADC_DELAY_TIMER_LOOP 5 63#define LRADC_DELAY_TIMER_LOOP 5
62 64
63static const char * const mxs_lradc_irq_name[] = { 65/*
66 * Once the pen touches the touchscreen, the touchscreen switches from
67 * IRQ-driven mode to polling mode to prevent interrupt storm. The polling
68 * is realized by worker thread, which is called every 20 or so milliseconds.
69 * This gives the touchscreen enough fluence and does not strain the system
70 * too much.
71 */
72#define LRADC_TS_SAMPLE_DELAY_MS 5
73
74/*
75 * The LRADC reads the following amount of samples from each touchscreen
76 * channel and the driver then computes avarage of these.
77 */
78#define LRADC_TS_SAMPLE_AMOUNT 4
79
80enum mxs_lradc_id {
81 IMX23_LRADC,
82 IMX28_LRADC,
83};
84
85static const char * const mx23_lradc_irq_names[] = {
86 "mxs-lradc-touchscreen",
87 "mxs-lradc-channel0",
88 "mxs-lradc-channel1",
89 "mxs-lradc-channel2",
90 "mxs-lradc-channel3",
91 "mxs-lradc-channel4",
92 "mxs-lradc-channel5",
93 "mxs-lradc-channel6",
94 "mxs-lradc-channel7",
95};
96
97static const char * const mx28_lradc_irq_names[] = {
64 "mxs-lradc-touchscreen", 98 "mxs-lradc-touchscreen",
65 "mxs-lradc-thresh0", 99 "mxs-lradc-thresh0",
66 "mxs-lradc-thresh1", 100 "mxs-lradc-thresh1",
@@ -76,9 +110,26 @@ static const char * const mxs_lradc_irq_name[] = {
76 "mxs-lradc-button1", 110 "mxs-lradc-button1",
77}; 111};
78 112
79struct mxs_lradc_chan { 113struct mxs_lradc_of_config {
80 uint8_t slot; 114 const int irq_count;
81 uint8_t flags; 115 const char * const *irq_name;
116};
117
118static const struct mxs_lradc_of_config mxs_lradc_of_config[] = {
119 [IMX23_LRADC] = {
120 .irq_count = ARRAY_SIZE(mx23_lradc_irq_names),
121 .irq_name = mx23_lradc_irq_names,
122 },
123 [IMX28_LRADC] = {
124 .irq_count = ARRAY_SIZE(mx28_lradc_irq_names),
125 .irq_name = mx28_lradc_irq_names,
126 },
127};
128
129enum mxs_lradc_ts {
130 MXS_LRADC_TOUCHSCREEN_NONE = 0,
131 MXS_LRADC_TOUCHSCREEN_4WIRE,
132 MXS_LRADC_TOUCHSCREEN_5WIRE,
82}; 133};
83 134
84struct mxs_lradc { 135struct mxs_lradc {
@@ -91,24 +142,70 @@ struct mxs_lradc {
91 142
92 struct mutex lock; 143 struct mutex lock;
93 144
94 uint8_t enable;
95
96 struct completion completion; 145 struct completion completion;
146
147 /*
148 * Touchscreen LRADC channels receives a private slot in the CTRL4
149 * register, the slot #7. Therefore only 7 slots instead of 8 in the
150 * CTRL4 register can be mapped to LRADC channels when using the
151 * touchscreen.
152 *
153 * Furthermore, certain LRADC channels are shared between touchscreen
154 * and/or touch-buttons and generic LRADC block. Therefore when using
155 * either of these, these channels are not available for the regular
156 * sampling. The shared channels are as follows:
157 *
158 * CH0 -- Touch button #0
159 * CH1 -- Touch button #1
160 * CH2 -- Touch screen XPUL
161 * CH3 -- Touch screen YPLL
162 * CH4 -- Touch screen XNUL
163 * CH5 -- Touch screen YNLR
164 * CH6 -- Touch screen WIPER (5-wire only)
165 *
166 * The bitfields below represents which parts of the LRADC block are
167 * switched into special mode of operation. These channels can not
168 * be sampled as regular LRADC channels. The driver will refuse any
169 * attempt to sample these channels.
170 */
171#define CHAN_MASK_TOUCHBUTTON (0x3 << 0)
172#define CHAN_MASK_TOUCHSCREEN_4WIRE (0xf << 2)
173#define CHAN_MASK_TOUCHSCREEN_5WIRE (0x1f << 2)
174 enum mxs_lradc_ts use_touchscreen;
175 bool stop_touchscreen;
176 bool use_touchbutton;
177
178 struct input_dev *ts_input;
179 struct work_struct ts_work;
97}; 180};
98 181
99#define LRADC_CTRL0 0x00 182#define LRADC_CTRL0 0x00
100#define LRADC_CTRL0_TOUCH_DETECT_ENABLE (1 << 23) 183#define LRADC_CTRL0_TOUCH_DETECT_ENABLE (1 << 23)
101#define LRADC_CTRL0_TOUCH_SCREEN_TYPE (1 << 22) 184#define LRADC_CTRL0_TOUCH_SCREEN_TYPE (1 << 22)
185#define LRADC_CTRL0_YNNSW /* YM */ (1 << 21)
186#define LRADC_CTRL0_YPNSW /* YP */ (1 << 20)
187#define LRADC_CTRL0_YPPSW /* YP */ (1 << 19)
188#define LRADC_CTRL0_XNNSW /* XM */ (1 << 18)
189#define LRADC_CTRL0_XNPSW /* XM */ (1 << 17)
190#define LRADC_CTRL0_XPPSW /* XP */ (1 << 16)
191#define LRADC_CTRL0_PLATE_MASK (0x3f << 16)
102 192
103#define LRADC_CTRL1 0x10 193#define LRADC_CTRL1 0x10
104#define LRADC_CTRL1_LRADC_IRQ(n) (1 << (n)) 194#define LRADC_CTRL1_TOUCH_DETECT_IRQ_EN (1 << 24)
105#define LRADC_CTRL1_LRADC_IRQ_MASK 0x1fff
106#define LRADC_CTRL1_LRADC_IRQ_EN(n) (1 << ((n) + 16)) 195#define LRADC_CTRL1_LRADC_IRQ_EN(n) (1 << ((n) + 16))
107#define LRADC_CTRL1_LRADC_IRQ_EN_MASK (0x1fff << 16) 196#define LRADC_CTRL1_LRADC_IRQ_EN_MASK (0x1fff << 16)
197#define LRADC_CTRL1_LRADC_IRQ_EN_OFFSET 16
198#define LRADC_CTRL1_TOUCH_DETECT_IRQ (1 << 8)
199#define LRADC_CTRL1_LRADC_IRQ(n) (1 << (n))
200#define LRADC_CTRL1_LRADC_IRQ_MASK 0x1fff
201#define LRADC_CTRL1_LRADC_IRQ_OFFSET 0
108 202
109#define LRADC_CTRL2 0x20 203#define LRADC_CTRL2 0x20
110#define LRADC_CTRL2_TEMPSENSE_PWD (1 << 15) 204#define LRADC_CTRL2_TEMPSENSE_PWD (1 << 15)
111 205
206#define LRADC_STATUS 0x40
207#define LRADC_STATUS_TOUCH_DETECT_RAW (1 << 0)
208
112#define LRADC_CH(n) (0x50 + (0x10 * (n))) 209#define LRADC_CH(n) (0x50 + (0x10 * (n)))
113#define LRADC_CH_ACCUMULATE (1 << 29) 210#define LRADC_CH_ACCUMULATE (1 << 29)
114#define LRADC_CH_NUM_SAMPLES_MASK (0x1f << 24) 211#define LRADC_CH_NUM_SAMPLES_MASK (0x1f << 24)
@@ -140,6 +237,7 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
140{ 237{
141 struct mxs_lradc *lradc = iio_priv(iio_dev); 238 struct mxs_lradc *lradc = iio_priv(iio_dev);
142 int ret; 239 int ret;
240 unsigned long mask;
143 241
144 if (m != IIO_CHAN_INFO_RAW) 242 if (m != IIO_CHAN_INFO_RAW)
145 return -EINVAL; 243 return -EINVAL;
@@ -148,6 +246,12 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
148 if (chan->channel > LRADC_MAX_TOTAL_CHANS) 246 if (chan->channel > LRADC_MAX_TOTAL_CHANS)
149 return -EINVAL; 247 return -EINVAL;
150 248
249 /* Validate the channel if it doesn't intersect with reserved chans. */
250 bitmap_set(&mask, chan->channel, 1);
251 ret = iio_validate_scan_mask_onehot(iio_dev, &mask);
252 if (ret)
253 return -EINVAL;
254
151 /* 255 /*
152 * See if there is no buffered operation in progess. If there is, simply 256 * See if there is no buffered operation in progess. If there is, simply
153 * bail out. This can be improved to support both buffered and raw IO at 257 * bail out. This can be improved to support both buffered and raw IO at
@@ -169,7 +273,11 @@ static int mxs_lradc_read_raw(struct iio_dev *iio_dev,
169 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR); 273 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR);
170 writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 274 writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
171 275
172 writel(chan->channel, lradc->base + LRADC_CTRL4); 276 /* Clean the slot's previous content, then set new one. */
277 writel(LRADC_CTRL4_LRADCSELECT_MASK(0),
278 lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR);
279 writel(chan->channel, lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET);
280
173 writel(0, lradc->base + LRADC_CH(0)); 281 writel(0, lradc->base + LRADC_CH(0));
174 282
175 /* Enable the IRQ and start sampling the channel. */ 283 /* Enable the IRQ and start sampling the channel. */
@@ -203,6 +311,269 @@ static const struct iio_info mxs_lradc_iio_info = {
203}; 311};
204 312
205/* 313/*
314 * Touchscreen handling
315 */
316enum lradc_ts_plate {
317 LRADC_SAMPLE_X,
318 LRADC_SAMPLE_Y,
319 LRADC_SAMPLE_PRESSURE,
320};
321
322static int mxs_lradc_ts_touched(struct mxs_lradc *lradc)
323{
324 uint32_t reg;
325
326 /* Enable touch detection. */
327 writel(LRADC_CTRL0_PLATE_MASK,
328 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
329 writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE,
330 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET);
331
332 msleep(LRADC_TS_SAMPLE_DELAY_MS);
333
334 reg = readl(lradc->base + LRADC_STATUS);
335
336 return reg & LRADC_STATUS_TOUCH_DETECT_RAW;
337}
338
339static int32_t mxs_lradc_ts_sample(struct mxs_lradc *lradc,
340 enum lradc_ts_plate plate, int change)
341{
342 unsigned long delay, jiff;
343 uint32_t reg, ctrl0 = 0, chan = 0;
344 /* The touchscreen always uses CTRL4 slot #7. */
345 const uint8_t slot = 7;
346 uint32_t val;
347
348 /*
349 * There are three correct configurations of the controller sampling
350 * the touchscreen, each of these configuration provides different
351 * information from the touchscreen.
352 *
353 * The following table describes the sampling configurations:
354 * +-------------+-------+-------+-------+
355 * | Wire \ Axis | X | Y | Z |
356 * +---------------------+-------+-------+
357 * | X+ (CH2) | HI | TS | TS |
358 * +-------------+-------+-------+-------+
359 * | X- (CH4) | LO | SH | HI |
360 * +-------------+-------+-------+-------+
361 * | Y+ (CH3) | SH | HI | HI |
362 * +-------------+-------+-------+-------+
363 * | Y- (CH5) | TS | LO | SH |
364 * +-------------+-------+-------+-------+
365 *
366 * HI ... strong '1' ; LO ... strong '0'
367 * SH ... sample here ; TS ... tri-state
368 *
369 * There are a few other ways of obtaining the Z coordinate
370 * (aka. pressure), but the one in the table seems to be the
371 * most reliable one.
372 */
373 switch (plate) {
374 case LRADC_SAMPLE_X:
375 ctrl0 = LRADC_CTRL0_XPPSW | LRADC_CTRL0_XNNSW;
376 chan = 3;
377 break;
378 case LRADC_SAMPLE_Y:
379 ctrl0 = LRADC_CTRL0_YPPSW | LRADC_CTRL0_YNNSW;
380 chan = 4;
381 break;
382 case LRADC_SAMPLE_PRESSURE:
383 ctrl0 = LRADC_CTRL0_YPPSW | LRADC_CTRL0_XNNSW;
384 chan = 5;
385 break;
386 }
387
388 if (change) {
389 writel(LRADC_CTRL0_PLATE_MASK,
390 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
391 writel(ctrl0, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET);
392
393 writel(LRADC_CTRL4_LRADCSELECT_MASK(slot),
394 lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR);
395 writel(chan << LRADC_CTRL4_LRADCSELECT_OFFSET(slot),
396 lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET);
397 }
398
399 writel(0xffffffff, lradc->base + LRADC_CH(slot) + STMP_OFFSET_REG_CLR);
400 writel(1 << slot, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET);
401
402 delay = jiffies + msecs_to_jiffies(LRADC_TS_SAMPLE_DELAY_MS);
403 do {
404 jiff = jiffies;
405 reg = readl_relaxed(lradc->base + LRADC_CTRL1);
406 if (reg & LRADC_CTRL1_LRADC_IRQ(slot))
407 break;
408 } while (time_before(jiff, delay));
409
410 writel(LRADC_CTRL1_LRADC_IRQ(slot),
411 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR);
412
413 if (time_after_eq(jiff, delay))
414 return -ETIMEDOUT;
415
416 val = readl(lradc->base + LRADC_CH(slot));
417 val &= LRADC_CH_VALUE_MASK;
418
419 return val;
420}
421
422static int32_t mxs_lradc_ts_sample_filter(struct mxs_lradc *lradc,
423 enum lradc_ts_plate plate)
424{
425 int32_t val, tot = 0;
426 int i;
427
428 val = mxs_lradc_ts_sample(lradc, plate, 1);
429
430 /* Delay a bit so the touchscreen is stable. */
431 mdelay(2);
432
433 for (i = 0; i < LRADC_TS_SAMPLE_AMOUNT; i++) {
434 val = mxs_lradc_ts_sample(lradc, plate, 0);
435 tot += val;
436 }
437
438 return tot / LRADC_TS_SAMPLE_AMOUNT;
439}
440
441static void mxs_lradc_ts_work(struct work_struct *ts_work)
442{
443 struct mxs_lradc *lradc = container_of(ts_work,
444 struct mxs_lradc, ts_work);
445 int val_x, val_y, val_p;
446 bool valid = false;
447
448 while (mxs_lradc_ts_touched(lradc)) {
449 /* Disable touch detector so we can sample the touchscreen. */
450 writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE,
451 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
452
453 if (likely(valid)) {
454 input_report_abs(lradc->ts_input, ABS_X, val_x);
455 input_report_abs(lradc->ts_input, ABS_Y, val_y);
456 input_report_abs(lradc->ts_input, ABS_PRESSURE, val_p);
457 input_report_key(lradc->ts_input, BTN_TOUCH, 1);
458 input_sync(lradc->ts_input);
459 }
460
461 valid = false;
462
463 val_x = mxs_lradc_ts_sample_filter(lradc, LRADC_SAMPLE_X);
464 if (val_x < 0)
465 continue;
466 val_y = mxs_lradc_ts_sample_filter(lradc, LRADC_SAMPLE_Y);
467 if (val_y < 0)
468 continue;
469 val_p = mxs_lradc_ts_sample_filter(lradc, LRADC_SAMPLE_PRESSURE);
470 if (val_p < 0)
471 continue;
472
473 valid = true;
474 }
475
476 input_report_abs(lradc->ts_input, ABS_PRESSURE, 0);
477 input_report_key(lradc->ts_input, BTN_TOUCH, 0);
478 input_sync(lradc->ts_input);
479
480 /* Do not restart the TS IRQ if the driver is shutting down. */
481 if (lradc->stop_touchscreen)
482 return;
483
484 /* Restart the touchscreen interrupts. */
485 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ,
486 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR);
487 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN,
488 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET);
489}
490
491static int mxs_lradc_ts_open(struct input_dev *dev)
492{
493 struct mxs_lradc *lradc = input_get_drvdata(dev);
494
495 /* The touchscreen is starting. */
496 lradc->stop_touchscreen = false;
497
498 /* Enable the touch-detect circuitry. */
499 writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE,
500 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET);
501
502 /* Enable the touch-detect IRQ. */
503 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN,
504 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET);
505
506 return 0;
507}
508
509static void mxs_lradc_ts_close(struct input_dev *dev)
510{
511 struct mxs_lradc *lradc = input_get_drvdata(dev);
512
513 /* Indicate the touchscreen is stopping. */
514 lradc->stop_touchscreen = true;
515 mb();
516
517 /* Wait until touchscreen thread finishes any possible remnants. */
518 cancel_work_sync(&lradc->ts_work);
519
520 /* Disable touchscreen touch-detect IRQ. */
521 writel(LRADC_CTRL1_TOUCH_DETECT_IRQ_EN,
522 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR);
523
524 /* Power-down touchscreen touch-detect circuitry. */
525 writel(LRADC_CTRL0_TOUCH_DETECT_ENABLE,
526 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
527}
528
529static int mxs_lradc_ts_register(struct mxs_lradc *lradc)
530{
531 struct input_dev *input;
532 struct device *dev = lradc->dev;
533 int ret;
534
535 if (!lradc->use_touchscreen)
536 return 0;
537
538 input = input_allocate_device();
539 if (!input) {
540 dev_err(dev, "Failed to allocate TS device!\n");
541 return -ENOMEM;
542 }
543
544 input->name = DRIVER_NAME;
545 input->id.bustype = BUS_HOST;
546 input->dev.parent = dev;
547 input->open = mxs_lradc_ts_open;
548 input->close = mxs_lradc_ts_close;
549
550 __set_bit(EV_ABS, input->evbit);
551 __set_bit(EV_KEY, input->evbit);
552 __set_bit(BTN_TOUCH, input->keybit);
553 input_set_abs_params(input, ABS_X, 0, LRADC_CH_VALUE_MASK, 0, 0);
554 input_set_abs_params(input, ABS_Y, 0, LRADC_CH_VALUE_MASK, 0, 0);
555 input_set_abs_params(input, ABS_PRESSURE, 0, LRADC_CH_VALUE_MASK, 0, 0);
556
557 lradc->ts_input = input;
558 input_set_drvdata(input, lradc);
559 ret = input_register_device(input);
560 if (ret)
561 input_free_device(lradc->ts_input);
562
563 return ret;
564}
565
566static void mxs_lradc_ts_unregister(struct mxs_lradc *lradc)
567{
568 if (!lradc->use_touchscreen)
569 return;
570
571 cancel_work_sync(&lradc->ts_work);
572
573 input_unregister_device(lradc->ts_input);
574}
575
576/*
206 * IRQ Handling 577 * IRQ Handling
207 */ 578 */
208static irqreturn_t mxs_lradc_handle_irq(int irq, void *data) 579static irqreturn_t mxs_lradc_handle_irq(int irq, void *data)
@@ -210,14 +581,24 @@ static irqreturn_t mxs_lradc_handle_irq(int irq, void *data)
210 struct iio_dev *iio = data; 581 struct iio_dev *iio = data;
211 struct mxs_lradc *lradc = iio_priv(iio); 582 struct mxs_lradc *lradc = iio_priv(iio);
212 unsigned long reg = readl(lradc->base + LRADC_CTRL1); 583 unsigned long reg = readl(lradc->base + LRADC_CTRL1);
584 const uint32_t ts_irq_mask =
585 LRADC_CTRL1_TOUCH_DETECT_IRQ_EN |
586 LRADC_CTRL1_TOUCH_DETECT_IRQ;
213 587
214 if (!(reg & LRADC_CTRL1_LRADC_IRQ_MASK)) 588 if (!(reg & LRADC_CTRL1_LRADC_IRQ_MASK))
215 return IRQ_NONE; 589 return IRQ_NONE;
216 590
217 /* 591 /*
218 * Touchscreen IRQ handling code shall probably have priority 592 * Touchscreen IRQ handling code has priority and therefore
219 * and therefore shall be placed here. 593 * is placed here. In case touchscreen IRQ arrives, disable
594 * it ASAP
220 */ 595 */
596 if (reg & LRADC_CTRL1_TOUCH_DETECT_IRQ) {
597 writel(ts_irq_mask,
598 lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_CLR);
599 if (!lradc->stop_touchscreen)
600 schedule_work(&lradc->ts_work);
601 }
221 602
222 if (iio_buffer_enabled(iio)) 603 if (iio_buffer_enabled(iio))
223 iio_trigger_poll(iio->trig, iio_get_time_ns()); 604 iio_trigger_poll(iio->trig, iio_get_time_ns());
@@ -313,8 +694,10 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio)
313{ 694{
314 struct mxs_lradc *lradc = iio_priv(iio); 695 struct mxs_lradc *lradc = iio_priv(iio);
315 struct iio_buffer *buffer = iio->buffer; 696 struct iio_buffer *buffer = iio->buffer;
316 int ret = 0, chan, ofs = 0, enable = 0; 697 int ret = 0, chan, ofs = 0;
317 uint32_t ctrl4 = 0; 698 unsigned long enable = 0;
699 uint32_t ctrl4_set = 0;
700 uint32_t ctrl4_clr = 0;
318 uint32_t ctrl1_irq = 0; 701 uint32_t ctrl1_irq = 0;
319 const uint32_t chan_value = LRADC_CH_ACCUMULATE | 702 const uint32_t chan_value = LRADC_CH_ACCUMULATE |
320 ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET); 703 ((LRADC_DELAY_TIMER_LOOP - 1) << LRADC_CH_NUM_SAMPLES_OFFSET);
@@ -346,17 +729,20 @@ static int mxs_lradc_buffer_preenable(struct iio_dev *iio)
346 writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR); 729 writel(0xff, lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
347 730
348 for_each_set_bit(chan, buffer->scan_mask, LRADC_MAX_TOTAL_CHANS) { 731 for_each_set_bit(chan, buffer->scan_mask, LRADC_MAX_TOTAL_CHANS) {
349 ctrl4 |= chan << LRADC_CTRL4_LRADCSELECT_OFFSET(ofs); 732 ctrl4_set |= chan << LRADC_CTRL4_LRADCSELECT_OFFSET(ofs);
733 ctrl4_clr |= LRADC_CTRL4_LRADCSELECT_MASK(ofs);
350 ctrl1_irq |= LRADC_CTRL1_LRADC_IRQ_EN(ofs); 734 ctrl1_irq |= LRADC_CTRL1_LRADC_IRQ_EN(ofs);
351 writel(chan_value, lradc->base + LRADC_CH(ofs)); 735 writel(chan_value, lradc->base + LRADC_CH(ofs));
352 enable |= 1 << ofs; 736 bitmap_set(&enable, ofs, 1);
353 ofs++; 737 ofs++;
354 } 738 }
355 739
356 writel(LRADC_DELAY_TRIGGER_LRADCS_MASK | LRADC_DELAY_KICK, 740 writel(LRADC_DELAY_TRIGGER_LRADCS_MASK | LRADC_DELAY_KICK,
357 lradc->base + LRADC_DELAY(0) + STMP_OFFSET_REG_CLR); 741 lradc->base + LRADC_DELAY(0) + STMP_OFFSET_REG_CLR);
358 742
359 writel(ctrl4, lradc->base + LRADC_CTRL4); 743 writel(ctrl4_clr, lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_CLR);
744 writel(ctrl4_set, lradc->base + LRADC_CTRL4 + STMP_OFFSET_REG_SET);
745
360 writel(ctrl1_irq, lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET); 746 writel(ctrl1_irq, lradc->base + LRADC_CTRL1 + STMP_OFFSET_REG_SET);
361 747
362 writel(enable << LRADC_DELAY_TRIGGER_LRADCS_OFFSET, 748 writel(enable << LRADC_DELAY_TRIGGER_LRADCS_OFFSET,
@@ -391,9 +777,33 @@ static int mxs_lradc_buffer_postdisable(struct iio_dev *iio)
391static bool mxs_lradc_validate_scan_mask(struct iio_dev *iio, 777static bool mxs_lradc_validate_scan_mask(struct iio_dev *iio,
392 const unsigned long *mask) 778 const unsigned long *mask)
393{ 779{
394 const int mw = bitmap_weight(mask, iio->masklength); 780 struct mxs_lradc *lradc = iio_priv(iio);
395 781 const int len = iio->masklength;
396 return mw <= LRADC_MAX_MAPPED_CHANS; 782 const int map_chans = bitmap_weight(mask, len);
783 int rsvd_chans = 0;
784 unsigned long rsvd_mask = 0;
785
786 if (lradc->use_touchbutton)
787 rsvd_mask |= CHAN_MASK_TOUCHBUTTON;
788 if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_4WIRE)
789 rsvd_mask |= CHAN_MASK_TOUCHSCREEN_4WIRE;
790 if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_5WIRE)
791 rsvd_mask |= CHAN_MASK_TOUCHSCREEN_5WIRE;
792
793 if (lradc->use_touchbutton)
794 rsvd_chans++;
795 if (lradc->use_touchscreen)
796 rsvd_chans++;
797
798 /* Test for attempts to map channels with special mode of operation. */
799 if (bitmap_intersects(mask, &rsvd_mask, len))
800 return false;
801
802 /* Test for attempts to map more channels then available slots. */
803 if (map_chans + rsvd_chans > LRADC_MAX_MAPPED_CHANS)
804 return false;
805
806 return true;
397} 807}
398 808
399static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = { 809static const struct iio_buffer_setup_ops mxs_lradc_buffer_ops = {
@@ -442,15 +852,29 @@ static const struct iio_chan_spec mxs_lradc_chan_spec[] = {
442 852
443static void mxs_lradc_hw_init(struct mxs_lradc *lradc) 853static void mxs_lradc_hw_init(struct mxs_lradc *lradc)
444{ 854{
445 int i; 855 /* The ADC always uses DELAY CHANNEL 0. */
446 const uint32_t cfg = 856 const uint32_t adc_cfg =
857 (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + 0)) |
447 (LRADC_DELAY_TIMER_PER << LRADC_DELAY_DELAY_OFFSET); 858 (LRADC_DELAY_TIMER_PER << LRADC_DELAY_DELAY_OFFSET);
448 859
449 stmp_reset_block(lradc->base); 860 stmp_reset_block(lradc->base);
450 861
451 for (i = 0; i < LRADC_MAX_DELAY_CHANS; i++) 862 /* Configure DELAY CHANNEL 0 for generic ADC sampling. */
452 writel(cfg | (1 << (LRADC_DELAY_TRIGGER_DELAYS_OFFSET + i)), 863 writel(adc_cfg, lradc->base + LRADC_DELAY(0));
453 lradc->base + LRADC_DELAY(i)); 864
865 /* Disable remaining DELAY CHANNELs */
866 writel(0, lradc->base + LRADC_DELAY(1));
867 writel(0, lradc->base + LRADC_DELAY(2));
868 writel(0, lradc->base + LRADC_DELAY(3));
869
870 /* Configure the touchscreen type */
871 writel(LRADC_CTRL0_TOUCH_SCREEN_TYPE,
872 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_CLR);
873
874 if (lradc->use_touchscreen == MXS_LRADC_TOUCHSCREEN_5WIRE) {
875 writel(LRADC_CTRL0_TOUCH_SCREEN_TYPE,
876 lradc->base + LRADC_CTRL0 + STMP_OFFSET_REG_SET);
877 }
454 878
455 /* Start internal temperature sensing. */ 879 /* Start internal temperature sensing. */
456 writel(0, lradc->base + LRADC_CTRL2); 880 writel(0, lradc->base + LRADC_CTRL2);
@@ -467,12 +891,25 @@ static void mxs_lradc_hw_stop(struct mxs_lradc *lradc)
467 writel(0, lradc->base + LRADC_DELAY(i)); 891 writel(0, lradc->base + LRADC_DELAY(i));
468} 892}
469 893
894static const struct of_device_id mxs_lradc_dt_ids[] = {
895 { .compatible = "fsl,imx23-lradc", .data = (void *)IMX23_LRADC, },
896 { .compatible = "fsl,imx28-lradc", .data = (void *)IMX28_LRADC, },
897 { /* sentinel */ }
898};
899MODULE_DEVICE_TABLE(of, mxs_lradc_dt_ids);
900
470static int mxs_lradc_probe(struct platform_device *pdev) 901static int mxs_lradc_probe(struct platform_device *pdev)
471{ 902{
903 const struct of_device_id *of_id =
904 of_match_device(mxs_lradc_dt_ids, &pdev->dev);
905 const struct mxs_lradc_of_config *of_cfg =
906 &mxs_lradc_of_config[(enum mxs_lradc_id)of_id->data];
472 struct device *dev = &pdev->dev; 907 struct device *dev = &pdev->dev;
908 struct device_node *node = dev->of_node;
473 struct mxs_lradc *lradc; 909 struct mxs_lradc *lradc;
474 struct iio_dev *iio; 910 struct iio_dev *iio;
475 struct resource *iores; 911 struct resource *iores;
912 uint32_t ts_wires = 0;
476 int ret = 0; 913 int ret = 0;
477 int i; 914 int i;
478 915
@@ -494,8 +931,23 @@ static int mxs_lradc_probe(struct platform_device *pdev)
494 goto err_addr; 931 goto err_addr;
495 } 932 }
496 933
934 INIT_WORK(&lradc->ts_work, mxs_lradc_ts_work);
935
936 /* Check if touchscreen is enabled in DT. */
937 ret = of_property_read_u32(node, "fsl,lradc-touchscreen-wires",
938 &ts_wires);
939 if (ret)
940 dev_info(dev, "Touchscreen not enabled.\n");
941 else if (ts_wires == 4)
942 lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_4WIRE;
943 else if (ts_wires == 5)
944 lradc->use_touchscreen = MXS_LRADC_TOUCHSCREEN_5WIRE;
945 else
946 dev_warn(dev, "Unsupported number of touchscreen wires (%d)\n",
947 ts_wires);
948
497 /* Grab all IRQ sources */ 949 /* Grab all IRQ sources */
498 for (i = 0; i < 13; i++) { 950 for (i = 0; i < of_cfg->irq_count; i++) {
499 lradc->irq[i] = platform_get_irq(pdev, i); 951 lradc->irq[i] = platform_get_irq(pdev, i);
500 if (lradc->irq[i] < 0) { 952 if (lradc->irq[i] < 0) {
501 ret = -EINVAL; 953 ret = -EINVAL;
@@ -504,7 +956,7 @@ static int mxs_lradc_probe(struct platform_device *pdev)
504 956
505 ret = devm_request_irq(dev, lradc->irq[i], 957 ret = devm_request_irq(dev, lradc->irq[i],
506 mxs_lradc_handle_irq, 0, 958 mxs_lradc_handle_irq, 0,
507 mxs_lradc_irq_name[i], iio); 959 of_cfg->irq_name[i], iio);
508 if (ret) 960 if (ret)
509 goto err_addr; 961 goto err_addr;
510 } 962 }
@@ -531,11 +983,16 @@ static int mxs_lradc_probe(struct platform_device *pdev)
531 if (ret) 983 if (ret)
532 goto err_trig; 984 goto err_trig;
533 985
986 /* Register the touchscreen input device. */
987 ret = mxs_lradc_ts_register(lradc);
988 if (ret)
989 goto err_dev;
990
534 /* Register IIO device. */ 991 /* Register IIO device. */
535 ret = iio_device_register(iio); 992 ret = iio_device_register(iio);
536 if (ret) { 993 if (ret) {
537 dev_err(dev, "Failed to register IIO device\n"); 994 dev_err(dev, "Failed to register IIO device\n");
538 goto err_dev; 995 goto err_ts;
539 } 996 }
540 997
541 /* Configure the hardware. */ 998 /* Configure the hardware. */
@@ -543,6 +1000,8 @@ static int mxs_lradc_probe(struct platform_device *pdev)
543 1000
544 return 0; 1001 return 0;
545 1002
1003err_ts:
1004 mxs_lradc_ts_unregister(lradc);
546err_dev: 1005err_dev:
547 mxs_lradc_trigger_remove(iio); 1006 mxs_lradc_trigger_remove(iio);
548err_trig: 1007err_trig:
@@ -557,6 +1016,8 @@ static int mxs_lradc_remove(struct platform_device *pdev)
557 struct iio_dev *iio = platform_get_drvdata(pdev); 1016 struct iio_dev *iio = platform_get_drvdata(pdev);
558 struct mxs_lradc *lradc = iio_priv(iio); 1017 struct mxs_lradc *lradc = iio_priv(iio);
559 1018
1019 mxs_lradc_ts_unregister(lradc);
1020
560 mxs_lradc_hw_stop(lradc); 1021 mxs_lradc_hw_stop(lradc);
561 1022
562 iio_device_unregister(iio); 1023 iio_device_unregister(iio);
@@ -567,12 +1028,6 @@ static int mxs_lradc_remove(struct platform_device *pdev)
567 return 0; 1028 return 0;
568} 1029}
569 1030
570static const struct of_device_id mxs_lradc_dt_ids[] = {
571 { .compatible = "fsl,imx28-lradc", },
572 { /* sentinel */ }
573};
574MODULE_DEVICE_TABLE(of, mxs_lradc_dt_ids);
575
576static struct platform_driver mxs_lradc_driver = { 1031static struct platform_driver mxs_lradc_driver = {
577 .driver = { 1032 .driver = {
578 .name = DRIVER_NAME, 1033 .name = DRIVER_NAME,
diff --git a/drivers/staging/iio/frequency/ad5930.c b/drivers/staging/iio/frequency/ad5930.c
index 23777be38b18..69e90e9e60ea 100644
--- a/drivers/staging/iio/frequency/ad5930.c
+++ b/drivers/staging/iio/frequency/ad5930.c
@@ -44,7 +44,6 @@ static ssize_t ad5930_set_parameter(struct device *dev,
44 const char *buf, 44 const char *buf,
45 size_t len) 45 size_t len)
46{ 46{
47 struct spi_message msg;
48 struct spi_transfer xfer; 47 struct spi_transfer xfer;
49 int ret; 48 int ret;
50 struct ad5903_config *config = (struct ad5903_config *)buf; 49 struct ad5903_config *config = (struct ad5903_config *)buf;
@@ -64,9 +63,7 @@ static ssize_t ad5930_set_parameter(struct device *dev,
64 xfer.tx_buf = config; 63 xfer.tx_buf = config;
65 mutex_lock(&st->lock); 64 mutex_lock(&st->lock);
66 65
67 spi_message_init(&msg); 66 ret = spi_sync_transfer(st->sdev, &xfer, 1);
68 spi_message_add_tail(&xfer, &msg);
69 ret = spi_sync(st->sdev, &msg);
70 if (ret) 67 if (ret)
71 goto error_ret; 68 goto error_ret;
72error_ret: 69error_ret:
diff --git a/drivers/staging/iio/frequency/ad9850.c b/drivers/staging/iio/frequency/ad9850.c
index 104f7a4905a3..01a8a93031f5 100644
--- a/drivers/staging/iio/frequency/ad9850.c
+++ b/drivers/staging/iio/frequency/ad9850.c
@@ -39,7 +39,6 @@ static ssize_t ad9850_set_parameter(struct device *dev,
39 const char *buf, 39 const char *buf,
40 size_t len) 40 size_t len)
41{ 41{
42 struct spi_message msg;
43 struct spi_transfer xfer; 42 struct spi_transfer xfer;
44 int ret; 43 int ret;
45 struct ad9850_config *config = (struct ad9850_config *)buf; 44 struct ad9850_config *config = (struct ad9850_config *)buf;
@@ -50,9 +49,7 @@ static ssize_t ad9850_set_parameter(struct device *dev,
50 xfer.tx_buf = config; 49 xfer.tx_buf = config;
51 mutex_lock(&st->lock); 50 mutex_lock(&st->lock);
52 51
53 spi_message_init(&msg); 52 ret = spi_sync_transfer(st->sdev, &xfer, 1);
54 spi_message_add_tail(&xfer, &msg);
55 ret = spi_sync(st->sdev, &msg);
56 if (ret) 53 if (ret)
57 goto error_ret; 54 goto error_ret;
58error_ret: 55error_ret:
diff --git a/drivers/staging/iio/frequency/ad9852.c b/drivers/staging/iio/frequency/ad9852.c
index 17ac825b3d26..1344031232bc 100644
--- a/drivers/staging/iio/frequency/ad9852.c
+++ b/drivers/staging/iio/frequency/ad9852.c
@@ -183,7 +183,6 @@ static IIO_DEVICE_ATTR(dds, S_IWUSR, NULL, ad9852_set_parameter, 0);
183 183
184static void ad9852_init(struct ad9852_state *st) 184static void ad9852_init(struct ad9852_state *st)
185{ 185{
186 struct spi_message msg;
187 struct spi_transfer xfer; 186 struct spi_transfer xfer;
188 int ret; 187 int ret;
189 u8 config[5]; 188 u8 config[5];
@@ -199,9 +198,7 @@ static void ad9852_init(struct ad9852_state *st)
199 xfer.len = 5; 198 xfer.len = 5;
200 xfer.tx_buf = &config; 199 xfer.tx_buf = &config;
201 200
202 spi_message_init(&msg); 201 ret = spi_sync_transfer(st->sdev, &xfer, 1);
203 spi_message_add_tail(&xfer, &msg);
204 ret = spi_sync(st->sdev, &msg);
205 if (ret) 202 if (ret)
206 goto error_ret; 203 goto error_ret;
207 204
diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig
index 87979a0d03a9..836066287192 100644
--- a/drivers/staging/iio/gyro/Kconfig
+++ b/drivers/staging/iio/gyro/Kconfig
@@ -10,13 +10,6 @@ config ADIS16060
10 Say yes here to build support for Analog Devices adis16060 wide bandwidth 10 Say yes here to build support for Analog Devices adis16060 wide bandwidth
11 yaw rate gyroscope with SPI. 11 yaw rate gyroscope with SPI.
12 12
13config ADIS16080
14 tristate "Analog Devices ADIS16080/100 Yaw Rate Gyroscope with SPI driver"
15 depends on SPI
16 help
17 Say yes here to build support for Analog Devices adis16080/100 Yaw Rate
18 Gyroscope with SPI.
19
20config ADIS16130 13config ADIS16130
21 tristate "Analog Devices ADIS16130 High Precision Angular Rate Sensor driver" 14 tristate "Analog Devices ADIS16130 High Precision Angular Rate Sensor driver"
22 depends on SPI 15 depends on SPI
@@ -36,14 +29,4 @@ config ADIS16260
36 This driver can also be built as a module. If so, the module 29 This driver can also be built as a module. If so, the module
37 will be called adis16260. 30 will be called adis16260.
38 31
39config ADXRS450
40 tristate "Analog Devices ADXRS450/3 Digital Output Gyroscope SPI driver"
41 depends on SPI
42 help
43 Say yes here to build support for Analog Devices ADXRS450 and ADXRS453
44 programmable digital output gyroscope.
45
46 This driver can also be built as a module. If so, the module
47 will be called adxrs450.
48
49endmenu 32endmenu
diff --git a/drivers/staging/iio/gyro/Makefile b/drivers/staging/iio/gyro/Makefile
index 1303569e5c8a..98e650061a3a 100644
--- a/drivers/staging/iio/gyro/Makefile
+++ b/drivers/staging/iio/gyro/Makefile
@@ -5,17 +5,8 @@
5adis16060-y := adis16060_core.o 5adis16060-y := adis16060_core.o
6obj-$(CONFIG_ADIS16060) += adis16060.o 6obj-$(CONFIG_ADIS16060) += adis16060.o
7 7
8adis16080-y := adis16080_core.o
9obj-$(CONFIG_ADIS16080) += adis16080.o
10
11adis16130-y := adis16130_core.o 8adis16130-y := adis16130_core.o
12obj-$(CONFIG_ADIS16130) += adis16130.o 9obj-$(CONFIG_ADIS16130) += adis16130.o
13 10
14adis16260-y := adis16260_core.o 11adis16260-y := adis16260_core.o
15obj-$(CONFIG_ADIS16260) += adis16260.o 12obj-$(CONFIG_ADIS16260) += adis16260.o
16
17adis16251-y := adis16251_core.o
18obj-$(CONFIG_ADIS16251) += adis16251.o
19
20adxrs450-y := adxrs450_core.o
21obj-$(CONFIG_ADXRS450) += adxrs450.o
diff --git a/drivers/staging/iio/gyro/adxrs450.h b/drivers/staging/iio/gyro/adxrs450.h
deleted file mode 100644
index f8cf21f02943..000000000000
--- a/drivers/staging/iio/gyro/adxrs450.h
+++ /dev/null
@@ -1,62 +0,0 @@
1#ifndef SPI_ADXRS450_H_
2#define SPI_ADXRS450_H_
3
4#define ADXRS450_STARTUP_DELAY 50 /* ms */
5
6/* The MSB for the spi commands */
7#define ADXRS450_SENSOR_DATA 0x20
8#define ADXRS450_WRITE_DATA 0x40
9#define ADXRS450_READ_DATA 0x80
10
11#define ADXRS450_RATE1 0x00 /* Rate Registers */
12#define ADXRS450_TEMP1 0x02 /* Temperature Registers */
13#define ADXRS450_LOCST1 0x04 /* Low CST Memory Registers */
14#define ADXRS450_HICST1 0x06 /* High CST Memory Registers */
15#define ADXRS450_QUAD1 0x08 /* Quad Memory Registers */
16#define ADXRS450_FAULT1 0x0A /* Fault Registers */
17#define ADXRS450_PID1 0x0C /* Part ID Register 1 */
18#define ADXRS450_SNH 0x0E /* Serial Number Registers, 4 bytes */
19#define ADXRS450_SNL 0x10
20#define ADXRS450_DNC1 0x12 /* Dynamic Null Correction Registers */
21/* Check bits */
22#define ADXRS450_P 0x01
23#define ADXRS450_CHK 0x02
24#define ADXRS450_CST 0x04
25#define ADXRS450_PWR 0x08
26#define ADXRS450_POR 0x10
27#define ADXRS450_NVM 0x20
28#define ADXRS450_Q 0x40
29#define ADXRS450_PLL 0x80
30#define ADXRS450_UV 0x100
31#define ADXRS450_OV 0x200
32#define ADXRS450_AMP 0x400
33#define ADXRS450_FAIL 0x800
34
35#define ADXRS450_WRERR_MASK (0x7 << 29)
36
37#define ADXRS450_MAX_RX 4
38#define ADXRS450_MAX_TX 4
39
40#define ADXRS450_GET_ST(a) ((a >> 26) & 0x3)
41
42enum {
43 ID_ADXRS450,
44 ID_ADXRS453,
45};
46
47/**
48 * struct adxrs450_state - device instance specific data
49 * @us: actual spi_device
50 * @buf_lock: mutex to protect tx and rx
51 * @tx: transmit buffer
52 * @rx: receive buffer
53 **/
54struct adxrs450_state {
55 struct spi_device *us;
56 struct mutex buf_lock;
57 u8 tx[ADXRS450_MAX_RX] ____cacheline_aligned;
58 u8 rx[ADXRS450_MAX_TX];
59
60};
61
62#endif /* SPI_ADXRS450_H_ */
diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
index c7a5f97576c7..93af756ba48c 100644
--- a/drivers/staging/iio/iio_hwmon.c
+++ b/drivers/staging/iio/iio_hwmon.c
@@ -55,63 +55,58 @@ static ssize_t iio_hwmon_read_val(struct device *dev,
55 return sprintf(buf, "%d\n", result); 55 return sprintf(buf, "%d\n", result);
56} 56}
57 57
58static void iio_hwmon_free_attrs(struct iio_hwmon_state *st) 58static ssize_t show_name(struct device *dev, struct device_attribute *attr,
59 char *buf)
59{ 60{
60 int i; 61 return sprintf(buf, "iio_hwmon\n");
61 struct sensor_device_attribute *a;
62 for (i = 0; i < st->num_channels; i++)
63 if (st->attrs[i]) {
64 a = to_sensor_dev_attr(
65 container_of(st->attrs[i],
66 struct device_attribute,
67 attr));
68 kfree(a);
69 }
70} 62}
71 63
64static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
65
72static int iio_hwmon_probe(struct platform_device *pdev) 66static int iio_hwmon_probe(struct platform_device *pdev)
73{ 67{
68 struct device *dev = &pdev->dev;
74 struct iio_hwmon_state *st; 69 struct iio_hwmon_state *st;
75 struct sensor_device_attribute *a; 70 struct sensor_device_attribute *a;
76 int ret, i; 71 int ret, i;
77 int in_i = 1, temp_i = 1, curr_i = 1; 72 int in_i = 1, temp_i = 1, curr_i = 1;
78 enum iio_chan_type type; 73 enum iio_chan_type type;
74 struct iio_channel *channels;
79 75
80 st = kzalloc(sizeof(*st), GFP_KERNEL); 76 channels = iio_channel_get_all(dev);
81 if (st == NULL) { 77 if (IS_ERR(channels))
82 ret = -ENOMEM; 78 return PTR_ERR(channels);
83 goto error_ret;
84 }
85 79
86 st->channels = iio_channel_get_all(dev_name(&pdev->dev)); 80 st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL);
87 if (IS_ERR(st->channels)) { 81 if (st == NULL)
88 ret = PTR_ERR(st->channels); 82 return -ENOMEM;
89 goto error_free_state; 83
90 } 84 st->channels = channels;
91 85
92 /* count how many attributes we have */ 86 /* count how many attributes we have */
93 while (st->channels[st->num_channels].indio_dev) 87 while (st->channels[st->num_channels].indio_dev)
94 st->num_channels++; 88 st->num_channels++;
95 89
96 st->attrs = kzalloc(sizeof(st->attrs) * (st->num_channels + 1), 90 st->attrs = devm_kzalloc(dev,
97 GFP_KERNEL); 91 sizeof(*st->attrs) * (st->num_channels + 2),
92 GFP_KERNEL);
98 if (st->attrs == NULL) { 93 if (st->attrs == NULL) {
99 ret = -ENOMEM; 94 ret = -ENOMEM;
100 goto error_release_channels; 95 goto error_release_channels;
101 } 96 }
97
102 for (i = 0; i < st->num_channels; i++) { 98 for (i = 0; i < st->num_channels; i++) {
103 a = kzalloc(sizeof(*a), GFP_KERNEL); 99 a = devm_kzalloc(dev, sizeof(*a), GFP_KERNEL);
104 if (a == NULL) { 100 if (a == NULL) {
105 ret = -ENOMEM; 101 ret = -ENOMEM;
106 goto error_free_attrs; 102 goto error_release_channels;
107 } 103 }
108 104
109 sysfs_attr_init(&a->dev_attr.attr); 105 sysfs_attr_init(&a->dev_attr.attr);
110 ret = iio_get_channel_type(&st->channels[i], &type); 106 ret = iio_get_channel_type(&st->channels[i], &type);
111 if (ret < 0) { 107 if (ret < 0)
112 kfree(a); 108 goto error_release_channels;
113 goto error_free_attrs; 109
114 }
115 switch (type) { 110 switch (type) {
116 case IIO_VOLTAGE: 111 case IIO_VOLTAGE:
117 a->dev_attr.attr.name = kasprintf(GFP_KERNEL, 112 a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
@@ -130,27 +125,25 @@ static int iio_hwmon_probe(struct platform_device *pdev)
130 break; 125 break;
131 default: 126 default:
132 ret = -EINVAL; 127 ret = -EINVAL;
133 kfree(a); 128 goto error_release_channels;
134 goto error_free_attrs;
135 } 129 }
136 if (a->dev_attr.attr.name == NULL) { 130 if (a->dev_attr.attr.name == NULL) {
137 kfree(a);
138 ret = -ENOMEM; 131 ret = -ENOMEM;
139 goto error_free_attrs; 132 goto error_release_channels;
140 } 133 }
141 a->dev_attr.show = iio_hwmon_read_val; 134 a->dev_attr.show = iio_hwmon_read_val;
142 a->dev_attr.attr.mode = S_IRUGO; 135 a->dev_attr.attr.mode = S_IRUGO;
143 a->index = i; 136 a->index = i;
144 st->attrs[i] = &a->dev_attr.attr; 137 st->attrs[i] = &a->dev_attr.attr;
145 } 138 }
146 139 st->attrs[st->num_channels] = &dev_attr_name.attr;
147 st->attr_group.attrs = st->attrs; 140 st->attr_group.attrs = st->attrs;
148 platform_set_drvdata(pdev, st); 141 platform_set_drvdata(pdev, st);
149 ret = sysfs_create_group(&pdev->dev.kobj, &st->attr_group); 142 ret = sysfs_create_group(&dev->kobj, &st->attr_group);
150 if (ret < 0) 143 if (ret < 0)
151 goto error_free_attrs; 144 goto error_release_channels;
152 145
153 st->hwmon_dev = hwmon_device_register(&pdev->dev); 146 st->hwmon_dev = hwmon_device_register(dev);
154 if (IS_ERR(st->hwmon_dev)) { 147 if (IS_ERR(st->hwmon_dev)) {
155 ret = PTR_ERR(st->hwmon_dev); 148 ret = PTR_ERR(st->hwmon_dev);
156 goto error_remove_group; 149 goto error_remove_group;
@@ -158,15 +151,9 @@ static int iio_hwmon_probe(struct platform_device *pdev)
158 return 0; 151 return 0;
159 152
160error_remove_group: 153error_remove_group:
161 sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); 154 sysfs_remove_group(&dev->kobj, &st->attr_group);
162error_free_attrs:
163 iio_hwmon_free_attrs(st);
164 kfree(st->attrs);
165error_release_channels: 155error_release_channels:
166 iio_channel_release_all(st->channels); 156 iio_channel_release_all(st->channels);
167error_free_state:
168 kfree(st);
169error_ret:
170 return ret; 157 return ret;
171} 158}
172 159
@@ -176,17 +163,21 @@ static int iio_hwmon_remove(struct platform_device *pdev)
176 163
177 hwmon_device_unregister(st->hwmon_dev); 164 hwmon_device_unregister(st->hwmon_dev);
178 sysfs_remove_group(&pdev->dev.kobj, &st->attr_group); 165 sysfs_remove_group(&pdev->dev.kobj, &st->attr_group);
179 iio_hwmon_free_attrs(st);
180 kfree(st->attrs);
181 iio_channel_release_all(st->channels); 166 iio_channel_release_all(st->channels);
182 167
183 return 0; 168 return 0;
184} 169}
185 170
171static struct of_device_id iio_hwmon_of_match[] = {
172 { .compatible = "iio-hwmon", },
173 { }
174};
175
186static struct platform_driver __refdata iio_hwmon_driver = { 176static struct platform_driver __refdata iio_hwmon_driver = {
187 .driver = { 177 .driver = {
188 .name = "iio_hwmon", 178 .name = "iio_hwmon",
189 .owner = THIS_MODULE, 179 .owner = THIS_MODULE,
180 .of_match_table = iio_hwmon_of_match,
190 }, 181 },
191 .probe = iio_hwmon_probe, 182 .probe = iio_hwmon_probe,
192 .remove = iio_hwmon_remove, 183 .remove = iio_hwmon_remove,
diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index a865adf81938..aee76c710a3b 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -54,7 +54,7 @@ struct iio_dummy_accel_calibscale {
54static const struct iio_dummy_accel_calibscale dummy_scales[] = { 54static const struct iio_dummy_accel_calibscale dummy_scales[] = {
55 { 0, 100, 0x8 }, /* 0.000100 */ 55 { 0, 100, 0x8 }, /* 0.000100 */
56 { 0, 133, 0x7 }, /* 0.000133 */ 56 { 0, 133, 0x7 }, /* 0.000133 */
57 { 733, 13, 0x9 }, /* 733.00013 */ 57 { 733, 13, 0x9 }, /* 733.000013 */
58}; 58};
59 59
60/* 60/*
@@ -284,7 +284,7 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
284/** 284/**
285 * iio_dummy_write_raw() - data write function. 285 * iio_dummy_write_raw() - data write function.
286 * @indio_dev: the struct iio_dev associated with this device instance 286 * @indio_dev: the struct iio_dev associated with this device instance
287 * @chan: the channel whose data is to be read 287 * @chan: the channel whose data is to be written
288 * @val: first element of value to set (typically INT) 288 * @val: first element of value to set (typically INT)
289 * @val2: second element of value to set (typically MICRO) 289 * @val2: second element of value to set (typically MICRO)
290 * @mask: what we actually want to write. 0 is the channel, everything else 290 * @mask: what we actually want to write. 0 is the channel, everything else
diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
index dee16f0e7570..72f400c3cbcb 100644
--- a/drivers/staging/iio/iio_simple_dummy_buffer.c
+++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
@@ -155,7 +155,7 @@ int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev,
155 * occurs, this function is run. Typically this grabs data 155 * occurs, this function is run. Typically this grabs data
156 * from the device. 156 * from the device.
157 * 157 *
158 * NULL for the top half. This is normally implemented only if we 158 * NULL for the bottom half. This is normally implemented only if we
159 * either want to ping a capture now pin (no sleeping) or grab 159 * either want to ping a capture now pin (no sleeping) or grab
160 * a timestamp as close as possible to a data ready trigger firing. 160 * a timestamp as close as possible to a data ready trigger firing.
161 * 161 *
diff --git a/drivers/staging/iio/impedance-analyzer/Kconfig b/drivers/staging/iio/impedance-analyzer/Kconfig
index ad0ff765e4b2..dd97b6bb3fd0 100644
--- a/drivers/staging/iio/impedance-analyzer/Kconfig
+++ b/drivers/staging/iio/impedance-analyzer/Kconfig
@@ -7,7 +7,7 @@ config AD5933
7 tristate "Analog Devices AD5933, AD5934 driver" 7 tristate "Analog Devices AD5933, AD5934 driver"
8 depends on I2C 8 depends on I2C
9 select IIO_BUFFER 9 select IIO_BUFFER
10 select IIO_SW_RING 10 select IIO_KFIFO_BUF
11 help 11 help
12 Say yes here to build support for Analog Devices Impedance Converter, 12 Say yes here to build support for Analog Devices Impedance Converter,
13 Network Analyzer, AD5933/4, provides direct access via sysfs. 13 Network Analyzer, AD5933/4, provides direct access via sysfs.
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 779243d24dec..440e2261e8cb 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -22,7 +22,7 @@
22#include <linux/iio/iio.h> 22#include <linux/iio/iio.h>
23#include <linux/iio/sysfs.h> 23#include <linux/iio/sysfs.h>
24#include <linux/iio/buffer.h> 24#include <linux/iio/buffer.h>
25#include "../ring_sw.h" 25#include <linux/iio/kfifo_buf.h>
26 26
27#include "ad5933.h" 27#include "ad5933.h"
28 28
@@ -630,7 +630,7 @@ static const struct iio_buffer_setup_ops ad5933_ring_setup_ops = {
630 630
631static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev) 631static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
632{ 632{
633 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 633 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
634 if (!indio_dev->buffer) 634 if (!indio_dev->buffer)
635 return -ENOMEM; 635 return -ENOMEM;
636 636
@@ -774,7 +774,7 @@ static int ad5933_probe(struct i2c_client *client,
774error_uninitialize_ring: 774error_uninitialize_ring:
775 iio_buffer_unregister(indio_dev); 775 iio_buffer_unregister(indio_dev);
776error_unreg_ring: 776error_unreg_ring:
777 iio_sw_rb_free(indio_dev->buffer); 777 iio_kfifo_free(indio_dev->buffer);
778error_disable_reg: 778error_disable_reg:
779 if (!IS_ERR(st->reg)) 779 if (!IS_ERR(st->reg))
780 regulator_disable(st->reg); 780 regulator_disable(st->reg);
@@ -794,7 +794,7 @@ static int ad5933_remove(struct i2c_client *client)
794 794
795 iio_device_unregister(indio_dev); 795 iio_device_unregister(indio_dev);
796 iio_buffer_unregister(indio_dev); 796 iio_buffer_unregister(indio_dev);
797 iio_sw_rb_free(indio_dev->buffer); 797 iio_kfifo_free(indio_dev->buffer);
798 if (!IS_ERR(st->reg)) { 798 if (!IS_ERR(st->reg)) {
799 regulator_disable(st->reg); 799 regulator_disable(st->reg);
800 regulator_put(st->reg); 800 regulator_put(st->reg);
diff --git a/drivers/staging/iio/imu/Kconfig b/drivers/staging/iio/imu/Kconfig
deleted file mode 100644
index 2c2f47de2630..000000000000
--- a/drivers/staging/iio/imu/Kconfig
+++ /dev/null
@@ -1,17 +0,0 @@
1#
2# IIO imu drivers configuration
3#
4menu "Inertial measurement units"
5
6config ADIS16400
7 tristate "Analog Devices ADIS16400 and similar IMU SPI driver"
8 depends on SPI
9 select IIO_SW_RING if IIO_BUFFER
10 select IIO_TRIGGER if IIO_BUFFER
11 help
12 Say yes here to build support for Analog Devices adis16300, adis16344,
13 adis16350, adis16354, adis16355, adis16360, adis16362, adis16364,
14 adis16365, adis16400 and adis16405 triaxial inertial sensors
15 (adis16400 series also have magnetometers).
16
17endmenu
diff --git a/drivers/staging/iio/imu/Makefile b/drivers/staging/iio/imu/Makefile
deleted file mode 100644
index 3400a13d1522..000000000000
--- a/drivers/staging/iio/imu/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
1#
2# Makefile for Inertial Measurement Units
3#
4
5adis16400-y := adis16400_core.o
6adis16400-$(CONFIG_IIO_BUFFER) += adis16400_ring.o adis16400_trigger.o
7obj-$(CONFIG_ADIS16400) += adis16400.o
diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
deleted file mode 100644
index 9c8f5ab7e13b..000000000000
--- a/drivers/staging/iio/imu/adis16400_core.c
+++ /dev/null
@@ -1,1320 +0,0 @@
1/*
2 * adis16400.c support Analog Devices ADIS16400/5
3 * 3d 2g Linear Accelerometers,
4 * 3d Gyroscopes,
5 * 3d Magnetometers via SPI
6 *
7 * Copyright (c) 2009 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
8 * Copyright (c) 2007 Jonathan Cameron <jic23@kernel.org>
9 * Copyright (c) 2011 Analog Devices Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 *
15 */
16
17#include <linux/interrupt.h>
18#include <linux/irq.h>
19#include <linux/delay.h>
20#include <linux/mutex.h>
21#include <linux/device.h>
22#include <linux/kernel.h>
23#include <linux/spi/spi.h>
24#include <linux/slab.h>
25#include <linux/sysfs.h>
26#include <linux/list.h>
27#include <linux/module.h>
28
29#include <linux/iio/iio.h>
30#include <linux/iio/sysfs.h>
31#include <linux/iio/buffer.h>
32#include "adis16400.h"
33
34enum adis16400_chip_variant {
35 ADIS16300,
36 ADIS16334,
37 ADIS16350,
38 ADIS16360,
39 ADIS16362,
40 ADIS16364,
41 ADIS16400,
42};
43
44/**
45 * adis16400_spi_write_reg_8() - write single byte to a register
46 * @dev: device associated with child of actual device (iio_dev or iio_trig)
47 * @reg_address: the address of the register to be written
48 * @val: the value to write
49 */
50static int adis16400_spi_write_reg_8(struct iio_dev *indio_dev,
51 u8 reg_address,
52 u8 val)
53{
54 int ret;
55 struct adis16400_state *st = iio_priv(indio_dev);
56
57 mutex_lock(&st->buf_lock);
58 st->tx[0] = ADIS16400_WRITE_REG(reg_address);
59 st->tx[1] = val;
60
61 ret = spi_write(st->us, st->tx, 2);
62 mutex_unlock(&st->buf_lock);
63
64 return ret;
65}
66
67/**
68 * adis16400_spi_write_reg_16() - write 2 bytes to a pair of registers
69 * @dev: device associated with child of actual device (iio_dev or iio_trig)
70 * @reg_address: the address of the lower of the two registers. Second register
71 * is assumed to have address one greater.
72 * @val: value to be written
73 *
74 * At the moment the spi framework doesn't allow global setting of cs_change.
75 * This means that use cannot be made of spi_write.
76 */
77static int adis16400_spi_write_reg_16(struct iio_dev *indio_dev,
78 u8 lower_reg_address,
79 u16 value)
80{
81 int ret;
82 struct spi_message msg;
83 struct adis16400_state *st = iio_priv(indio_dev);
84 struct spi_transfer xfers[] = {
85 {
86 .tx_buf = st->tx,
87 .bits_per_word = 8,
88 .len = 2,
89 .cs_change = 1,
90 }, {
91 .tx_buf = st->tx + 2,
92 .bits_per_word = 8,
93 .len = 2,
94 },
95 };
96
97 mutex_lock(&st->buf_lock);
98 st->tx[0] = ADIS16400_WRITE_REG(lower_reg_address);
99 st->tx[1] = value & 0xFF;
100 st->tx[2] = ADIS16400_WRITE_REG(lower_reg_address + 1);
101 st->tx[3] = (value >> 8) & 0xFF;
102
103 spi_message_init(&msg);
104 spi_message_add_tail(&xfers[0], &msg);
105 spi_message_add_tail(&xfers[1], &msg);
106 ret = spi_sync(st->us, &msg);
107 mutex_unlock(&st->buf_lock);
108
109 return ret;
110}
111
112/**
113 * adis16400_spi_read_reg_16() - read 2 bytes from a 16-bit register
114 * @indio_dev: iio device
115 * @reg_address: the address of the lower of the two registers. Second register
116 * is assumed to have address one greater.
117 * @val: somewhere to pass back the value read
118 *
119 * At the moment the spi framework doesn't allow global setting of cs_change.
120 * This means that use cannot be made of spi_read.
121 **/
122static int adis16400_spi_read_reg_16(struct iio_dev *indio_dev,
123 u8 lower_reg_address,
124 u16 *val)
125{
126 struct spi_message msg;
127 struct adis16400_state *st = iio_priv(indio_dev);
128 int ret;
129 struct spi_transfer xfers[] = {
130 {
131 .tx_buf = st->tx,
132 .bits_per_word = 8,
133 .len = 2,
134 .cs_change = 1,
135 }, {
136 .rx_buf = st->rx,
137 .bits_per_word = 8,
138 .len = 2,
139 },
140 };
141
142 mutex_lock(&st->buf_lock);
143 st->tx[0] = ADIS16400_READ_REG(lower_reg_address);
144 st->tx[1] = 0;
145
146 spi_message_init(&msg);
147 spi_message_add_tail(&xfers[0], &msg);
148 spi_message_add_tail(&xfers[1], &msg);
149 ret = spi_sync(st->us, &msg);
150 if (ret) {
151 dev_err(&st->us->dev,
152 "problem when reading 16 bit register 0x%02X",
153 lower_reg_address);
154 goto error_ret;
155 }
156 *val = (st->rx[0] << 8) | st->rx[1];
157
158error_ret:
159 mutex_unlock(&st->buf_lock);
160 return ret;
161}
162
163static int adis16334_get_freq(struct iio_dev *indio_dev)
164{
165 int ret;
166 u16 t;
167
168 ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SMPL_PRD, &t);
169 if (ret < 0)
170 return ret;
171
172 t >>= ADIS16334_RATE_DIV_SHIFT;
173
174 return (8192 >> t) / 10;
175}
176
177static int adis16334_set_freq(struct iio_dev *indio_dev, unsigned int freq)
178{
179 unsigned int t;
180
181 t = ilog2(8192 / (freq * 10));
182
183 if (t > 0x31)
184 t = 0x31;
185
186 t <<= ADIS16334_RATE_DIV_SHIFT;
187 t |= ADIS16334_RATE_INT_CLK;
188
189 return adis16400_spi_write_reg_16(indio_dev, ADIS16400_SMPL_PRD, t);
190}
191
192static int adis16400_get_freq(struct iio_dev *indio_dev)
193{
194 int sps, ret;
195 u16 t;
196
197 ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_SMPL_PRD, &t);
198 if (ret < 0)
199 return ret;
200 sps = (t & ADIS16400_SMPL_PRD_TIME_BASE) ? 53 : 1638;
201 sps /= (t & ADIS16400_SMPL_PRD_DIV_MASK) + 1;
202
203 return sps;
204}
205
206static int adis16400_set_freq(struct iio_dev *indio_dev, unsigned int freq)
207{
208 struct adis16400_state *st = iio_priv(indio_dev);
209 unsigned int t;
210
211 t = 1638 / freq;
212 if (t > 0)
213 t--;
214 t &= ADIS16400_SMPL_PRD_DIV_MASK;
215 if ((t & ADIS16400_SMPL_PRD_DIV_MASK) >= 0x0A)
216 st->us->max_speed_hz = ADIS16400_SPI_SLOW;
217 else
218 st->us->max_speed_hz = ADIS16400_SPI_FAST;
219
220 return adis16400_spi_write_reg_8(indio_dev,
221 ADIS16400_SMPL_PRD, t);
222}
223
224static ssize_t adis16400_read_frequency(struct device *dev,
225 struct device_attribute *attr,
226 char *buf)
227{
228 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
229 struct adis16400_state *st = iio_priv(indio_dev);
230 int ret, len = 0;
231
232 ret = st->variant->get_freq(indio_dev);
233 if (ret < 0)
234 return ret;
235 len = sprintf(buf, "%d SPS\n", ret);
236 return len;
237}
238
239static const unsigned adis16400_3db_divisors[] = {
240 [0] = 2, /* Special case */
241 [1] = 5,
242 [2] = 10,
243 [3] = 50,
244 [4] = 200,
245};
246
247static int adis16400_set_filter(struct iio_dev *indio_dev, int sps, int val)
248{
249 int i, ret;
250 u16 val16;
251 for (i = ARRAY_SIZE(adis16400_3db_divisors) - 1; i >= 0; i--)
252 if (sps/adis16400_3db_divisors[i] > val)
253 break;
254 if (i == -1)
255 ret = -EINVAL;
256 else {
257 ret = adis16400_spi_read_reg_16(indio_dev,
258 ADIS16400_SENS_AVG,
259 &val16);
260 if (ret < 0)
261 goto error_ret;
262
263 ret = adis16400_spi_write_reg_16(indio_dev,
264 ADIS16400_SENS_AVG,
265 (val16 & ~0x03) | i);
266 }
267error_ret:
268 return ret;
269}
270
271static ssize_t adis16400_write_frequency(struct device *dev,
272 struct device_attribute *attr,
273 const char *buf,
274 size_t len)
275{
276 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
277 struct adis16400_state *st = iio_priv(indio_dev);
278 long val;
279 int ret;
280
281 ret = strict_strtol(buf, 10, &val);
282 if (ret)
283 return ret;
284 if (val == 0)
285 return -EINVAL;
286
287 mutex_lock(&indio_dev->mlock);
288
289 st->variant->set_freq(indio_dev, val);
290
291 /* Also update the filter */
292 mutex_unlock(&indio_dev->mlock);
293
294 return ret ? ret : len;
295}
296
297static int adis16400_reset(struct iio_dev *indio_dev)
298{
299 int ret;
300 ret = adis16400_spi_write_reg_8(indio_dev,
301 ADIS16400_GLOB_CMD,
302 ADIS16400_GLOB_CMD_SW_RESET);
303 if (ret)
304 dev_err(&indio_dev->dev, "problem resetting device");
305
306 return ret;
307}
308
309int adis16400_set_irq(struct iio_dev *indio_dev, bool enable)
310{
311 int ret;
312 u16 msc;
313
314 ret = adis16400_spi_read_reg_16(indio_dev, ADIS16400_MSC_CTRL, &msc);
315 if (ret)
316 goto error_ret;
317
318 msc |= ADIS16400_MSC_CTRL_DATA_RDY_POL_HIGH;
319 if (enable)
320 msc |= ADIS16400_MSC_CTRL_DATA_RDY_EN;
321 else
322 msc &= ~ADIS16400_MSC_CTRL_DATA_RDY_EN;
323
324 ret = adis16400_spi_write_reg_16(indio_dev, ADIS16400_MSC_CTRL, msc);
325 if (ret)
326 goto error_ret;
327
328error_ret:
329 return ret;
330}
331
332/* Power down the device */
333static int adis16400_stop_device(struct iio_dev *indio_dev)
334{
335 int ret;
336 u16 val = ADIS16400_SLP_CNT_POWER_OFF;
337
338 ret = adis16400_spi_write_reg_16(indio_dev, ADIS16400_SLP_CNT, val);
339 if (ret)
340 dev_err(&indio_dev->dev,
341 "problem with turning device off: SLP_CNT");
342
343 return ret;
344}
345
346static int adis16400_check_status(struct iio_dev *indio_dev)
347{
348 u16 status;
349 int ret;
350 struct device *dev = &indio_dev->dev;
351
352 ret = adis16400_spi_read_reg_16(indio_dev,
353 ADIS16400_DIAG_STAT, &status);
354
355 if (ret < 0) {
356 dev_err(dev, "Reading status failed\n");
357 goto error_ret;
358 }
359 ret = status;
360 if (status & ADIS16400_DIAG_STAT_ZACCL_FAIL)
361 dev_err(dev, "Z-axis accelerometer self-test failure\n");
362 if (status & ADIS16400_DIAG_STAT_YACCL_FAIL)
363 dev_err(dev, "Y-axis accelerometer self-test failure\n");
364 if (status & ADIS16400_DIAG_STAT_XACCL_FAIL)
365 dev_err(dev, "X-axis accelerometer self-test failure\n");
366 if (status & ADIS16400_DIAG_STAT_XGYRO_FAIL)
367 dev_err(dev, "X-axis gyroscope self-test failure\n");
368 if (status & ADIS16400_DIAG_STAT_YGYRO_FAIL)
369 dev_err(dev, "Y-axis gyroscope self-test failure\n");
370 if (status & ADIS16400_DIAG_STAT_ZGYRO_FAIL)
371 dev_err(dev, "Z-axis gyroscope self-test failure\n");
372 if (status & ADIS16400_DIAG_STAT_ALARM2)
373 dev_err(dev, "Alarm 2 active\n");
374 if (status & ADIS16400_DIAG_STAT_ALARM1)
375 dev_err(dev, "Alarm 1 active\n");
376 if (status & ADIS16400_DIAG_STAT_FLASH_CHK)
377 dev_err(dev, "Flash checksum error\n");
378 if (status & ADIS16400_DIAG_STAT_SELF_TEST)
379 dev_err(dev, "Self test error\n");
380 if (status & ADIS16400_DIAG_STAT_OVERFLOW)
381 dev_err(dev, "Sensor overrange\n");
382 if (status & ADIS16400_DIAG_STAT_SPI_FAIL)
383 dev_err(dev, "SPI failure\n");
384 if (status & ADIS16400_DIAG_STAT_FLASH_UPT)
385 dev_err(dev, "Flash update failed\n");
386 if (status & ADIS16400_DIAG_STAT_POWER_HIGH)
387 dev_err(dev, "Power supply above 5.25V\n");
388 if (status & ADIS16400_DIAG_STAT_POWER_LOW)
389 dev_err(dev, "Power supply below 4.75V\n");
390
391error_ret:
392 return ret;
393}
394
395static int adis16400_self_test(struct iio_dev *indio_dev)
396{
397 int ret;
398 ret = adis16400_spi_write_reg_16(indio_dev,
399 ADIS16400_MSC_CTRL,
400 ADIS16400_MSC_CTRL_MEM_TEST);
401 if (ret) {
402 dev_err(&indio_dev->dev, "problem starting self test");
403 goto err_ret;
404 }
405
406 msleep(ADIS16400_MTEST_DELAY);
407 adis16400_check_status(indio_dev);
408
409err_ret:
410 return ret;
411}
412
413static int adis16400_initial_setup(struct iio_dev *indio_dev)
414{
415 int ret;
416 u16 prod_id, smp_prd;
417 unsigned int device_id;
418 struct adis16400_state *st = iio_priv(indio_dev);
419
420 /* use low spi speed for init if the device has a slow mode */
421 if (st->variant->flags & ADIS16400_HAS_SLOW_MODE)
422 st->us->max_speed_hz = ADIS16400_SPI_SLOW;
423 else
424 st->us->max_speed_hz = ADIS16400_SPI_FAST;
425 st->us->mode = SPI_MODE_3;
426 spi_setup(st->us);
427
428 ret = adis16400_set_irq(indio_dev, false);
429 if (ret) {
430 dev_err(&indio_dev->dev, "disable irq failed");
431 goto err_ret;
432 }
433
434 ret = adis16400_self_test(indio_dev);
435 if (ret) {
436 dev_err(&indio_dev->dev, "self test failure");
437 goto err_ret;
438 }
439
440 ret = adis16400_check_status(indio_dev);
441 if (ret) {
442 adis16400_reset(indio_dev);
443 dev_err(&indio_dev->dev, "device not playing ball -> reset");
444 msleep(ADIS16400_STARTUP_DELAY);
445 ret = adis16400_check_status(indio_dev);
446 if (ret) {
447 dev_err(&indio_dev->dev, "giving up");
448 goto err_ret;
449 }
450 }
451 if (st->variant->flags & ADIS16400_HAS_PROD_ID) {
452 ret = adis16400_spi_read_reg_16(indio_dev,
453 ADIS16400_PRODUCT_ID, &prod_id);
454 if (ret)
455 goto err_ret;
456
457 sscanf(indio_dev->name, "adis%u\n", &device_id);
458
459 if (prod_id != device_id)
460 dev_warn(&indio_dev->dev, "Device ID(%u) and product ID(%u) do not match.",
461 device_id, prod_id);
462
463 dev_info(&indio_dev->dev, "%s: prod_id 0x%04x at CS%d (irq %d)\n",
464 indio_dev->name, prod_id,
465 st->us->chip_select, st->us->irq);
466 }
467 /* use high spi speed if possible */
468 if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) {
469 ret = adis16400_spi_read_reg_16(indio_dev,
470 ADIS16400_SMPL_PRD, &smp_prd);
471 if (ret)
472 goto err_ret;
473
474 if ((smp_prd & ADIS16400_SMPL_PRD_DIV_MASK) < 0x0A) {
475 st->us->max_speed_hz = ADIS16400_SPI_FAST;
476 spi_setup(st->us);
477 }
478 }
479
480err_ret:
481 return ret;
482}
483
484static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
485 adis16400_read_frequency,
486 adis16400_write_frequency);
487
488static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("409 546 819 1638");
489
490enum adis16400_chan {
491 in_supply,
492 gyro_x,
493 gyro_y,
494 gyro_z,
495 accel_x,
496 accel_y,
497 accel_z,
498 magn_x,
499 magn_y,
500 magn_z,
501 temp,
502 temp0, temp1, temp2,
503 in1,
504 in2,
505 incli_x,
506 incli_y,
507};
508
509static u8 adis16400_addresses[18][2] = {
510 [in_supply] = { ADIS16400_SUPPLY_OUT },
511 [gyro_x] = { ADIS16400_XGYRO_OUT, ADIS16400_XGYRO_OFF },
512 [gyro_y] = { ADIS16400_YGYRO_OUT, ADIS16400_YGYRO_OFF },
513 [gyro_z] = { ADIS16400_ZGYRO_OUT, ADIS16400_ZGYRO_OFF },
514 [accel_x] = { ADIS16400_XACCL_OUT, ADIS16400_XACCL_OFF },
515 [accel_y] = { ADIS16400_YACCL_OUT, ADIS16400_YACCL_OFF },
516 [accel_z] = { ADIS16400_ZACCL_OUT, ADIS16400_ZACCL_OFF },
517 [magn_x] = { ADIS16400_XMAGN_OUT },
518 [magn_y] = { ADIS16400_YMAGN_OUT },
519 [magn_z] = { ADIS16400_ZMAGN_OUT },
520 [temp] = { ADIS16400_TEMP_OUT },
521 [temp0] = { ADIS16350_XTEMP_OUT },
522 [temp1] = { ADIS16350_YTEMP_OUT },
523 [temp2] = { ADIS16350_ZTEMP_OUT },
524 [in1] = { ADIS16300_AUX_ADC },
525 [in2] = { ADIS16400_AUX_ADC },
526 [incli_x] = { ADIS16300_PITCH_OUT },
527 [incli_y] = { ADIS16300_ROLL_OUT }
528};
529
530
531static int adis16400_write_raw(struct iio_dev *indio_dev,
532 struct iio_chan_spec const *chan,
533 int val,
534 int val2,
535 long mask)
536{
537 struct adis16400_state *st = iio_priv(indio_dev);
538 int ret, sps;
539
540 switch (mask) {
541 case IIO_CHAN_INFO_CALIBBIAS:
542 mutex_lock(&indio_dev->mlock);
543 ret = adis16400_spi_write_reg_16(indio_dev,
544 adis16400_addresses[chan->address][1],
545 val);
546 mutex_unlock(&indio_dev->mlock);
547 return ret;
548 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
549 /* Need to cache values so we can update if the frequency
550 changes */
551 mutex_lock(&indio_dev->mlock);
552 st->filt_int = val;
553 /* Work out update to current value */
554 sps = st->variant->get_freq(indio_dev);
555 if (sps < 0) {
556 mutex_unlock(&indio_dev->mlock);
557 return sps;
558 }
559
560 ret = adis16400_set_filter(indio_dev, sps, val);
561 mutex_unlock(&indio_dev->mlock);
562 return ret;
563 default:
564 return -EINVAL;
565 }
566}
567
568static int adis16400_read_raw(struct iio_dev *indio_dev,
569 struct iio_chan_spec const *chan,
570 int *val,
571 int *val2,
572 long mask)
573{
574 struct adis16400_state *st = iio_priv(indio_dev);
575 int ret, shift;
576 s16 val16;
577
578 switch (mask) {
579 case IIO_CHAN_INFO_RAW:
580 mutex_lock(&indio_dev->mlock);
581 ret = adis16400_spi_read_reg_16(indio_dev,
582 adis16400_addresses[chan->address][0],
583 &val16);
584 if (ret) {
585 mutex_unlock(&indio_dev->mlock);
586 return ret;
587 }
588 val16 &= (1 << chan->scan_type.realbits) - 1;
589 if (chan->scan_type.sign == 's') {
590 shift = 16 - chan->scan_type.realbits;
591 val16 = (s16)(val16 << shift) >> shift;
592 }
593 *val = val16;
594 mutex_unlock(&indio_dev->mlock);
595 return IIO_VAL_INT;
596 case IIO_CHAN_INFO_SCALE:
597 switch (chan->type) {
598 case IIO_ANGL_VEL:
599 *val = 0;
600 *val2 = st->variant->gyro_scale_micro;
601 return IIO_VAL_INT_PLUS_MICRO;
602 case IIO_VOLTAGE:
603 *val = 0;
604 if (chan->channel == 0) {
605 *val = 2;
606 *val2 = 418000; /* 2.418 mV */
607 } else {
608 *val = 0;
609 *val2 = 805800; /* 805.8 uV */
610 }
611 return IIO_VAL_INT_PLUS_MICRO;
612 case IIO_ACCEL:
613 *val = 0;
614 *val2 = st->variant->accel_scale_micro;
615 return IIO_VAL_INT_PLUS_MICRO;
616 case IIO_MAGN:
617 *val = 0;
618 *val2 = 500; /* 0.5 mgauss */
619 return IIO_VAL_INT_PLUS_MICRO;
620 case IIO_TEMP:
621 *val = st->variant->temp_scale_nano / 1000000;
622 *val2 = (st->variant->temp_scale_nano % 1000000);
623 return IIO_VAL_INT_PLUS_MICRO;
624 default:
625 return -EINVAL;
626 }
627 case IIO_CHAN_INFO_CALIBBIAS:
628 mutex_lock(&indio_dev->mlock);
629 ret = adis16400_spi_read_reg_16(indio_dev,
630 adis16400_addresses[chan->address][1],
631 &val16);
632 mutex_unlock(&indio_dev->mlock);
633 if (ret)
634 return ret;
635 val16 = ((val16 & 0xFFF) << 4) >> 4;
636 *val = val16;
637 return IIO_VAL_INT;
638 case IIO_CHAN_INFO_OFFSET:
639 /* currently only temperature */
640 *val = st->variant->temp_offset;
641 return IIO_VAL_INT;
642 case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
643 mutex_lock(&indio_dev->mlock);
644 /* Need both the number of taps and the sampling frequency */
645 ret = adis16400_spi_read_reg_16(indio_dev,
646 ADIS16400_SENS_AVG,
647 &val16);
648 if (ret < 0) {
649 mutex_unlock(&indio_dev->mlock);
650 return ret;
651 }
652 val16 = st->variant->get_freq(indio_dev);
653 if (ret > 0)
654 *val = ret/adis16400_3db_divisors[val16 & 0x03];
655 *val2 = 0;
656 mutex_unlock(&indio_dev->mlock);
657 if (ret < 0)
658 return ret;
659 return IIO_VAL_INT_PLUS_MICRO;
660 default:
661 return -EINVAL;
662 }
663}
664
665static const struct iio_chan_spec adis16400_channels[] = {
666 {
667 .type = IIO_VOLTAGE,
668 .indexed = 1,
669 .channel = 0,
670 .extend_name = "supply",
671 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
672 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
673 .address = in_supply,
674 .scan_index = ADIS16400_SCAN_SUPPLY,
675 .scan_type = IIO_ST('u', 14, 16, 0),
676 }, {
677 .type = IIO_ANGL_VEL,
678 .modified = 1,
679 .channel2 = IIO_MOD_X,
680 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
681 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
682 IIO_CHAN_INFO_SCALE_SHARED_BIT |
683 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
684 .address = gyro_x,
685 .scan_index = ADIS16400_SCAN_GYRO_X,
686 .scan_type = IIO_ST('s', 14, 16, 0),
687 }, {
688 .type = IIO_ANGL_VEL,
689 .modified = 1,
690 .channel2 = IIO_MOD_Y,
691 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
692 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
693 IIO_CHAN_INFO_SCALE_SHARED_BIT |
694 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
695 .address = gyro_y,
696 .scan_index = ADIS16400_SCAN_GYRO_Y,
697 .scan_type = IIO_ST('s', 14, 16, 0),
698 }, {
699 .type = IIO_ANGL_VEL,
700 .modified = 1,
701 .channel2 = IIO_MOD_Z,
702 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
703 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
704 IIO_CHAN_INFO_SCALE_SHARED_BIT |
705 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
706 .address = gyro_z,
707 .scan_index = ADIS16400_SCAN_GYRO_Z,
708 .scan_type = IIO_ST('s', 14, 16, 0),
709 }, {
710 .type = IIO_ACCEL,
711 .modified = 1,
712 .channel2 = IIO_MOD_X,
713 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
714 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
715 IIO_CHAN_INFO_SCALE_SHARED_BIT |
716 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
717 .address = accel_x,
718 .scan_index = ADIS16400_SCAN_ACC_X,
719 .scan_type = IIO_ST('s', 14, 16, 0),
720 }, {
721 .type = IIO_ACCEL,
722 .modified = 1,
723 .channel2 = IIO_MOD_Y,
724 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
725 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
726 IIO_CHAN_INFO_SCALE_SHARED_BIT |
727 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
728 .address = accel_y,
729 .scan_index = ADIS16400_SCAN_ACC_Y,
730 .scan_type = IIO_ST('s', 14, 16, 0),
731 }, {
732 .type = IIO_ACCEL,
733 .modified = 1,
734 .channel2 = IIO_MOD_Z,
735 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
736 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
737 IIO_CHAN_INFO_SCALE_SHARED_BIT |
738 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
739 .address = accel_z,
740 .scan_index = ADIS16400_SCAN_ACC_Z,
741 .scan_type = IIO_ST('s', 14, 16, 0),
742 }, {
743 .type = IIO_MAGN,
744 .modified = 1,
745 .channel2 = IIO_MOD_X,
746 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
747 IIO_CHAN_INFO_SCALE_SHARED_BIT |
748 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
749 .address = magn_x,
750 .scan_index = ADIS16400_SCAN_MAGN_X,
751 .scan_type = IIO_ST('s', 14, 16, 0),
752 }, {
753 .type = IIO_MAGN,
754 .modified = 1,
755 .channel2 = IIO_MOD_Y,
756 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
757 IIO_CHAN_INFO_SCALE_SHARED_BIT |
758 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
759 .address = magn_y,
760 .scan_index = ADIS16400_SCAN_MAGN_Y,
761 .scan_type = IIO_ST('s', 14, 16, 0),
762 }, {
763 .type = IIO_MAGN,
764 .modified = 1,
765 .channel2 = IIO_MOD_Z,
766 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
767 IIO_CHAN_INFO_SCALE_SHARED_BIT |
768 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
769 .address = magn_z,
770 .scan_index = ADIS16400_SCAN_MAGN_Z,
771 .scan_type = IIO_ST('s', 14, 16, 0),
772 }, {
773 .type = IIO_TEMP,
774 .indexed = 1,
775 .channel = 0,
776 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
777 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
778 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
779 .address = temp,
780 .scan_index = ADIS16400_SCAN_TEMP,
781 .scan_type = IIO_ST('s', 12, 16, 0),
782 }, {
783 .type = IIO_VOLTAGE,
784 .indexed = 1,
785 .channel = 1,
786 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
787 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
788 .address = in2,
789 .scan_index = ADIS16400_SCAN_ADC_0,
790 .scan_type = IIO_ST('s', 12, 16, 0),
791 },
792 IIO_CHAN_SOFT_TIMESTAMP(12)
793};
794
795static const struct iio_chan_spec adis16350_channels[] = {
796 {
797 .type = IIO_VOLTAGE,
798 .indexed = 1,
799 .channel = 0,
800 .extend_name = "supply",
801 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
802 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
803 .address = in_supply,
804 .scan_index = ADIS16400_SCAN_SUPPLY,
805 .scan_type = IIO_ST('u', 12, 16, 0),
806 }, {
807 .type = IIO_ANGL_VEL,
808 .modified = 1,
809 .channel2 = IIO_MOD_X,
810 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
811 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
812 IIO_CHAN_INFO_SCALE_SHARED_BIT |
813 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
814 .address = gyro_x,
815 .scan_index = ADIS16400_SCAN_GYRO_X,
816 .scan_type = IIO_ST('s', 14, 16, 0),
817 }, {
818 .type = IIO_ANGL_VEL,
819 .modified = 1,
820 .channel2 = IIO_MOD_Y,
821 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
822 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
823 IIO_CHAN_INFO_SCALE_SHARED_BIT |
824 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
825 .address = gyro_y,
826 .scan_index = ADIS16400_SCAN_GYRO_Y,
827 .scan_type = IIO_ST('s', 14, 16, 0),
828 }, {
829 .type = IIO_ANGL_VEL,
830 .modified = 1,
831 .channel2 = IIO_MOD_Z,
832 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
833 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
834 IIO_CHAN_INFO_SCALE_SHARED_BIT |
835 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
836 .address = gyro_z,
837 .scan_index = ADIS16400_SCAN_GYRO_Z,
838 .scan_type = IIO_ST('s', 14, 16, 0),
839 }, {
840 .type = IIO_ACCEL,
841 .modified = 1,
842 .channel2 = IIO_MOD_X,
843 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
844 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
845 IIO_CHAN_INFO_SCALE_SHARED_BIT |
846 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
847 .address = accel_x,
848 .scan_index = ADIS16400_SCAN_ACC_X,
849 .scan_type = IIO_ST('s', 14, 16, 0),
850 }, {
851 .type = IIO_ACCEL,
852 .modified = 1,
853 .channel2 = IIO_MOD_Y,
854 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
855 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
856 IIO_CHAN_INFO_SCALE_SHARED_BIT |
857 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
858 .address = accel_y,
859 .scan_index = ADIS16400_SCAN_ACC_Y,
860 .scan_type = IIO_ST('s', 14, 16, 0),
861 }, {
862 .type = IIO_ACCEL,
863 .modified = 1,
864 .channel2 = IIO_MOD_Z,
865 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
866 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
867 IIO_CHAN_INFO_SCALE_SHARED_BIT |
868 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
869 .address = accel_z,
870 .scan_index = ADIS16400_SCAN_ACC_Z,
871 .scan_type = IIO_ST('s', 14, 16, 0),
872 }, {
873 .type = IIO_TEMP,
874 .indexed = 1,
875 .channel = 0,
876 .extend_name = "x",
877 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
878 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
879 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
880 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
881 .address = temp0,
882 .scan_index = ADIS16350_SCAN_TEMP_X,
883 .scan_type = IIO_ST('s', 12, 16, 0),
884 }, {
885 .type = IIO_TEMP,
886 .indexed = 1,
887 .channel = 1,
888 .extend_name = "y",
889 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
890 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
891 IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
892 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
893 .address = temp1,
894 .scan_index = ADIS16350_SCAN_TEMP_Y,
895 .scan_type = IIO_ST('s', 12, 16, 0),
896 }, {
897 .type = IIO_TEMP,
898 .indexed = 1,
899 .channel = 2,
900 .extend_name = "z",
901 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
902 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
903 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
904 .address = temp2,
905 .scan_index = ADIS16350_SCAN_TEMP_Z,
906 .scan_type = IIO_ST('s', 12, 16, 0),
907 }, {
908 .type = IIO_VOLTAGE,
909 .indexed = 1,
910 .channel = 1,
911 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
912 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
913 .address = in1,
914 .scan_index = ADIS16350_SCAN_ADC_0,
915 .scan_type = IIO_ST('s', 12, 16, 0),
916 },
917 IIO_CHAN_SOFT_TIMESTAMP(11)
918};
919
920static const struct iio_chan_spec adis16300_channels[] = {
921 {
922 .type = IIO_VOLTAGE,
923 .indexed = 1,
924 .channel = 0,
925 .extend_name = "supply",
926 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
927 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
928 .address = in_supply,
929 .scan_index = ADIS16400_SCAN_SUPPLY,
930 .scan_type = IIO_ST('u', 12, 16, 0),
931 }, {
932 .type = IIO_ANGL_VEL,
933 .modified = 1,
934 .channel2 = IIO_MOD_X,
935 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
936 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
937 IIO_CHAN_INFO_SCALE_SHARED_BIT |
938 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
939 .address = gyro_x,
940 .scan_index = ADIS16400_SCAN_GYRO_X,
941 .scan_type = IIO_ST('s', 14, 16, 0),
942 }, {
943 .type = IIO_ACCEL,
944 .modified = 1,
945 .channel2 = IIO_MOD_X,
946 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
947 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
948 IIO_CHAN_INFO_SCALE_SHARED_BIT |
949 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
950 .address = accel_x,
951 .scan_index = ADIS16400_SCAN_ACC_X,
952 .scan_type = IIO_ST('s', 14, 16, 0),
953 }, {
954 .type = IIO_ACCEL,
955 .modified = 1,
956 .channel2 = IIO_MOD_Y,
957 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
958 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
959 IIO_CHAN_INFO_SCALE_SHARED_BIT |
960 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
961 .address = accel_y,
962 .scan_index = ADIS16400_SCAN_ACC_Y,
963 .scan_type = IIO_ST('s', 14, 16, 0),
964 }, {
965 .type = IIO_ACCEL,
966 .modified = 1,
967 .channel2 = IIO_MOD_Z,
968 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
969 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
970 IIO_CHAN_INFO_SCALE_SHARED_BIT |
971 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
972 .address = accel_z,
973 .scan_index = ADIS16400_SCAN_ACC_Z,
974 .scan_type = IIO_ST('s', 14, 16, 0),
975 }, {
976 .type = IIO_TEMP,
977 .indexed = 1,
978 .channel = 0,
979 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
980 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
981 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
982 .address = temp0,
983 .scan_index = ADIS16400_SCAN_TEMP,
984 .scan_type = IIO_ST('s', 12, 16, 0),
985 }, {
986 .type = IIO_VOLTAGE,
987 .indexed = 1,
988 .channel = 1,
989 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
990 IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
991 .address = in1,
992 .scan_index = ADIS16350_SCAN_ADC_0,
993 .scan_type = IIO_ST('s', 12, 16, 0),
994 }, {
995 .type = IIO_INCLI,
996 .modified = 1,
997 .channel2 = IIO_MOD_X,
998 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
999 IIO_CHAN_INFO_SCALE_SHARED_BIT,
1000 .address = incli_x,
1001 .scan_index = ADIS16300_SCAN_INCLI_X,
1002 .scan_type = IIO_ST('s', 13, 16, 0),
1003 }, {
1004 .type = IIO_INCLI,
1005 .modified = 1,
1006 .channel2 = IIO_MOD_Y,
1007 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1008 IIO_CHAN_INFO_SCALE_SHARED_BIT,
1009 .address = incli_y,
1010 .scan_index = ADIS16300_SCAN_INCLI_Y,
1011 .scan_type = IIO_ST('s', 13, 16, 0),
1012 },
1013 IIO_CHAN_SOFT_TIMESTAMP(14)
1014};
1015
1016static const struct iio_chan_spec adis16334_channels[] = {
1017 {
1018 .type = IIO_ANGL_VEL,
1019 .modified = 1,
1020 .channel2 = IIO_MOD_X,
1021 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1022 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1023 IIO_CHAN_INFO_SCALE_SHARED_BIT |
1024 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
1025 .address = gyro_x,
1026 .scan_index = ADIS16400_SCAN_GYRO_X,
1027 .scan_type = IIO_ST('s', 14, 16, 0),
1028 }, {
1029 .type = IIO_ANGL_VEL,
1030 .modified = 1,
1031 .channel2 = IIO_MOD_Y,
1032 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1033 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1034 IIO_CHAN_INFO_SCALE_SHARED_BIT |
1035 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
1036 .address = gyro_y,
1037 .scan_index = ADIS16400_SCAN_GYRO_Y,
1038 .scan_type = IIO_ST('s', 14, 16, 0),
1039 }, {
1040 .type = IIO_ANGL_VEL,
1041 .modified = 1,
1042 .channel2 = IIO_MOD_Z,
1043 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1044 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1045 IIO_CHAN_INFO_SCALE_SHARED_BIT |
1046 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
1047 .address = gyro_z,
1048 .scan_index = ADIS16400_SCAN_GYRO_Z,
1049 .scan_type = IIO_ST('s', 14, 16, 0),
1050 }, {
1051 .type = IIO_ACCEL,
1052 .modified = 1,
1053 .channel2 = IIO_MOD_X,
1054 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1055 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1056 IIO_CHAN_INFO_SCALE_SHARED_BIT |
1057 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
1058 .address = accel_x,
1059 .scan_index = ADIS16400_SCAN_ACC_X,
1060 .scan_type = IIO_ST('s', 14, 16, 0),
1061 }, {
1062 .type = IIO_ACCEL,
1063 .modified = 1,
1064 .channel2 = IIO_MOD_Y,
1065 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1066 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1067 IIO_CHAN_INFO_SCALE_SHARED_BIT |
1068 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
1069 .address = accel_y,
1070 .scan_index = ADIS16400_SCAN_ACC_Y,
1071 .scan_type = IIO_ST('s', 14, 16, 0),
1072 }, {
1073 .type = IIO_ACCEL,
1074 .modified = 1,
1075 .channel2 = IIO_MOD_Z,
1076 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1077 IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT |
1078 IIO_CHAN_INFO_SCALE_SHARED_BIT |
1079 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT,
1080 .address = accel_z,
1081 .scan_index = ADIS16400_SCAN_ACC_Z,
1082 .scan_type = IIO_ST('s', 14, 16, 0),
1083 }, {
1084 .type = IIO_TEMP,
1085 .indexed = 1,
1086 .channel = 0,
1087 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
1088 IIO_CHAN_INFO_OFFSET_SEPARATE_BIT |
1089 IIO_CHAN_INFO_SCALE_SHARED_BIT,
1090 .address = temp0,
1091 .scan_index = ADIS16400_SCAN_TEMP,
1092 .scan_type = IIO_ST('s', 14, 16, 0),
1093 },
1094 IIO_CHAN_SOFT_TIMESTAMP(12)
1095};
1096
1097static struct attribute *adis16400_attributes[] = {
1098 &iio_dev_attr_sampling_frequency.dev_attr.attr,
1099 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
1100 NULL
1101};
1102
1103static const struct attribute_group adis16400_attribute_group = {
1104 .attrs = adis16400_attributes,
1105};
1106
1107static struct adis16400_chip_info adis16400_chips[] = {
1108 [ADIS16300] = {
1109 .channels = adis16300_channels,
1110 .num_channels = ARRAY_SIZE(adis16300_channels),
1111 .flags = ADIS16400_HAS_SLOW_MODE,
1112 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1113 .accel_scale_micro = 5884,
1114 .temp_scale_nano = 140000000, /* 0.14 C */
1115 .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */
1116 .default_scan_mask = (1 << ADIS16400_SCAN_SUPPLY) |
1117 (1 << ADIS16400_SCAN_GYRO_X) | (1 << ADIS16400_SCAN_ACC_X) |
1118 (1 << ADIS16400_SCAN_ACC_Y) | (1 << ADIS16400_SCAN_ACC_Z) |
1119 (1 << ADIS16400_SCAN_TEMP) | (1 << ADIS16400_SCAN_ADC_0) |
1120 (1 << ADIS16300_SCAN_INCLI_X) | (1 << ADIS16300_SCAN_INCLI_Y) |
1121 (1 << 14),
1122 .set_freq = adis16400_set_freq,
1123 .get_freq = adis16400_get_freq,
1124 },
1125 [ADIS16334] = {
1126 .channels = adis16334_channels,
1127 .num_channels = ARRAY_SIZE(adis16334_channels),
1128 .flags = ADIS16400_HAS_PROD_ID,
1129 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1130 .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
1131 .temp_scale_nano = 67850000, /* 0.06785 C */
1132 .temp_offset = 25000000 / 67850, /* 25 C = 0x00 */
1133 .default_scan_mask = (1 << ADIS16400_SCAN_GYRO_X) |
1134 (1 << ADIS16400_SCAN_GYRO_Y) | (1 << ADIS16400_SCAN_GYRO_Z) |
1135 (1 << ADIS16400_SCAN_ACC_X) | (1 << ADIS16400_SCAN_ACC_Y) |
1136 (1 << ADIS16400_SCAN_ACC_Z),
1137 .set_freq = adis16334_set_freq,
1138 .get_freq = adis16334_get_freq,
1139 },
1140 [ADIS16350] = {
1141 .channels = adis16350_channels,
1142 .num_channels = ARRAY_SIZE(adis16350_channels),
1143 .gyro_scale_micro = IIO_DEGREE_TO_RAD(73260), /* 0.07326 deg/s */
1144 .accel_scale_micro = IIO_G_TO_M_S_2(2522), /* 0.002522 g */
1145 .temp_scale_nano = 145300000, /* 0.1453 C */
1146 .temp_offset = 25000000 / 145300, /* 25 C = 0x00 */
1147 .default_scan_mask = 0x7FF,
1148 .flags = ADIS16400_NO_BURST | ADIS16400_HAS_SLOW_MODE,
1149 .set_freq = adis16400_set_freq,
1150 .get_freq = adis16400_get_freq,
1151 },
1152 [ADIS16360] = {
1153 .channels = adis16350_channels,
1154 .num_channels = ARRAY_SIZE(adis16350_channels),
1155 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
1156 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1157 .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
1158 .temp_scale_nano = 136000000, /* 0.136 C */
1159 .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
1160 .default_scan_mask = 0x7FF,
1161 .set_freq = adis16400_set_freq,
1162 .get_freq = adis16400_get_freq,
1163 },
1164 [ADIS16362] = {
1165 .channels = adis16350_channels,
1166 .num_channels = ARRAY_SIZE(adis16350_channels),
1167 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
1168 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1169 .accel_scale_micro = IIO_G_TO_M_S_2(333), /* 0.333 mg */
1170 .temp_scale_nano = 136000000, /* 0.136 C */
1171 .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
1172 .default_scan_mask = 0x7FF,
1173 .set_freq = adis16400_set_freq,
1174 .get_freq = adis16400_get_freq,
1175 },
1176 [ADIS16364] = {
1177 .channels = adis16350_channels,
1178 .num_channels = ARRAY_SIZE(adis16350_channels),
1179 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
1180 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1181 .accel_scale_micro = IIO_G_TO_M_S_2(1000), /* 1 mg */
1182 .temp_scale_nano = 136000000, /* 0.136 C */
1183 .temp_offset = 25000000 / 136000, /* 25 C = 0x00 */
1184 .default_scan_mask = 0x7FF,
1185 .set_freq = adis16400_set_freq,
1186 .get_freq = adis16400_get_freq,
1187 },
1188 [ADIS16400] = {
1189 .channels = adis16400_channels,
1190 .num_channels = ARRAY_SIZE(adis16400_channels),
1191 .flags = ADIS16400_HAS_PROD_ID | ADIS16400_HAS_SLOW_MODE,
1192 .gyro_scale_micro = IIO_DEGREE_TO_RAD(50000), /* 0.05 deg/s */
1193 .accel_scale_micro = IIO_G_TO_M_S_2(3333), /* 3.333 mg */
1194 .default_scan_mask = 0xFFF,
1195 .temp_scale_nano = 140000000, /* 0.14 C */
1196 .temp_offset = 25000000 / 140000, /* 25 C = 0x00 */
1197 .set_freq = adis16400_set_freq,
1198 .get_freq = adis16400_get_freq,
1199 }
1200};
1201
1202static const struct iio_info adis16400_info = {
1203 .driver_module = THIS_MODULE,
1204 .read_raw = &adis16400_read_raw,
1205 .write_raw = &adis16400_write_raw,
1206 .attrs = &adis16400_attribute_group,
1207};
1208
1209static int adis16400_probe(struct spi_device *spi)
1210{
1211 int ret;
1212 struct adis16400_state *st;
1213 struct iio_dev *indio_dev = iio_device_alloc(sizeof(*st));
1214 if (indio_dev == NULL) {
1215 ret = -ENOMEM;
1216 goto error_ret;
1217 }
1218 st = iio_priv(indio_dev);
1219 /* this is only used for removal purposes */
1220 spi_set_drvdata(spi, indio_dev);
1221
1222 st->us = spi;
1223 mutex_init(&st->buf_lock);
1224
1225 /* setup the industrialio driver allocated elements */
1226 st->variant = &adis16400_chips[spi_get_device_id(spi)->driver_data];
1227 indio_dev->dev.parent = &spi->dev;
1228 indio_dev->name = spi_get_device_id(spi)->name;
1229 indio_dev->channels = st->variant->channels;
1230 indio_dev->num_channels = st->variant->num_channels;
1231 indio_dev->info = &adis16400_info;
1232 indio_dev->modes = INDIO_DIRECT_MODE;
1233
1234 ret = adis16400_configure_ring(indio_dev);
1235 if (ret)
1236 goto error_free_dev;
1237
1238 ret = iio_buffer_register(indio_dev,
1239 st->variant->channels,
1240 st->variant->num_channels);
1241 if (ret) {
1242 dev_err(&spi->dev, "failed to initialize the ring\n");
1243 goto error_unreg_ring_funcs;
1244 }
1245
1246 if (spi->irq) {
1247 ret = adis16400_probe_trigger(indio_dev);
1248 if (ret)
1249 goto error_uninitialize_ring;
1250 }
1251
1252 /* Get the device into a sane initial state */
1253 ret = adis16400_initial_setup(indio_dev);
1254 if (ret)
1255 goto error_remove_trigger;
1256 ret = iio_device_register(indio_dev);
1257 if (ret)
1258 goto error_remove_trigger;
1259
1260 return 0;
1261
1262error_remove_trigger:
1263 if (spi->irq)
1264 adis16400_remove_trigger(indio_dev);
1265error_uninitialize_ring:
1266 iio_buffer_unregister(indio_dev);
1267error_unreg_ring_funcs:
1268 adis16400_unconfigure_ring(indio_dev);
1269error_free_dev:
1270 iio_device_free(indio_dev);
1271error_ret:
1272 return ret;
1273}
1274
1275/* fixme, confirm ordering in this function */
1276static int adis16400_remove(struct spi_device *spi)
1277{
1278 struct iio_dev *indio_dev = spi_get_drvdata(spi);
1279
1280 iio_device_unregister(indio_dev);
1281 adis16400_stop_device(indio_dev);
1282
1283 adis16400_remove_trigger(indio_dev);
1284 iio_buffer_unregister(indio_dev);
1285 adis16400_unconfigure_ring(indio_dev);
1286 iio_device_free(indio_dev);
1287
1288 return 0;
1289}
1290
1291static const struct spi_device_id adis16400_id[] = {
1292 {"adis16300", ADIS16300},
1293 {"adis16334", ADIS16334},
1294 {"adis16350", ADIS16350},
1295 {"adis16354", ADIS16350},
1296 {"adis16355", ADIS16350},
1297 {"adis16360", ADIS16360},
1298 {"adis16362", ADIS16362},
1299 {"adis16364", ADIS16364},
1300 {"adis16365", ADIS16360},
1301 {"adis16400", ADIS16400},
1302 {"adis16405", ADIS16400},
1303 {}
1304};
1305MODULE_DEVICE_TABLE(spi, adis16400_id);
1306
1307static struct spi_driver adis16400_driver = {
1308 .driver = {
1309 .name = "adis16400",
1310 .owner = THIS_MODULE,
1311 },
1312 .id_table = adis16400_id,
1313 .probe = adis16400_probe,
1314 .remove = adis16400_remove,
1315};
1316module_spi_driver(adis16400_driver);
1317
1318MODULE_AUTHOR("Manuel Stahl <manuel.stahl@iis.fraunhofer.de>");
1319MODULE_DESCRIPTION("Analog Devices ADIS16400/5 IMU SPI driver");
1320MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
deleted file mode 100644
index d46c1e38cf7b..000000000000
--- a/drivers/staging/iio/imu/adis16400_ring.c
+++ /dev/null
@@ -1,204 +0,0 @@
1#include <linux/interrupt.h>
2#include <linux/mutex.h>
3#include <linux/kernel.h>
4#include <linux/spi/spi.h>
5#include <linux/slab.h>
6#include <linux/bitops.h>
7#include <linux/export.h>
8
9#include <linux/iio/iio.h>
10#include "../ring_sw.h"
11#include <linux/iio/trigger_consumer.h>
12#include "adis16400.h"
13
14/**
15 * adis16400_spi_read_burst() - read all data registers
16 * @indio_dev: the IIO device
17 * @rx: somewhere to pass back the value read (min size is 24 bytes)
18 **/
19static int adis16400_spi_read_burst(struct iio_dev *indio_dev, u8 *rx)
20{
21 struct spi_message msg;
22 struct adis16400_state *st = iio_priv(indio_dev);
23 u32 old_speed_hz = st->us->max_speed_hz;
24 int ret;
25
26 struct spi_transfer xfers[] = {
27 {
28 .tx_buf = st->tx,
29 .bits_per_word = 8,
30 .len = 2,
31 }, {
32 .rx_buf = rx,
33 .bits_per_word = 8,
34 .len = 24,
35 },
36 };
37
38 mutex_lock(&st->buf_lock);
39 st->tx[0] = ADIS16400_READ_REG(ADIS16400_GLOB_CMD);
40 st->tx[1] = 0;
41
42 spi_message_init(&msg);
43 spi_message_add_tail(&xfers[0], &msg);
44 spi_message_add_tail(&xfers[1], &msg);
45
46 st->us->max_speed_hz = min(ADIS16400_SPI_BURST, old_speed_hz);
47 spi_setup(st->us);
48
49 ret = spi_sync(st->us, &msg);
50 if (ret)
51 dev_err(&st->us->dev, "problem when burst reading");
52
53 st->us->max_speed_hz = old_speed_hz;
54 spi_setup(st->us);
55 mutex_unlock(&st->buf_lock);
56 return ret;
57}
58
59static const u16 read_all_tx_array[] = {
60 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_SUPPLY_OUT)),
61 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_XGYRO_OUT)),
62 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_YGYRO_OUT)),
63 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_ZGYRO_OUT)),
64 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_XACCL_OUT)),
65 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_YACCL_OUT)),
66 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_ZACCL_OUT)),
67 cpu_to_be16(ADIS16400_READ_REG(ADIS16350_XTEMP_OUT)),
68 cpu_to_be16(ADIS16400_READ_REG(ADIS16350_YTEMP_OUT)),
69 cpu_to_be16(ADIS16400_READ_REG(ADIS16350_ZTEMP_OUT)),
70 cpu_to_be16(ADIS16400_READ_REG(ADIS16400_AUX_ADC)),
71};
72
73static int adis16350_spi_read_all(struct iio_dev *indio_dev, u8 *rx)
74{
75 struct adis16400_state *st = iio_priv(indio_dev);
76
77 struct spi_message msg;
78 int i, j = 0, ret;
79 struct spi_transfer *xfers;
80 int scan_count = bitmap_weight(indio_dev->active_scan_mask,
81 indio_dev->masklength);
82
83 xfers = kzalloc(sizeof(*xfers)*(scan_count + 1),
84 GFP_KERNEL);
85 if (xfers == NULL)
86 return -ENOMEM;
87
88 for (i = 0; i < ARRAY_SIZE(read_all_tx_array); i++)
89 if (test_bit(i, indio_dev->active_scan_mask)) {
90 xfers[j].tx_buf = &read_all_tx_array[i];
91 xfers[j].bits_per_word = 16;
92 xfers[j].len = 2;
93 xfers[j + 1].rx_buf = rx + j*2;
94 j++;
95 }
96 xfers[j].bits_per_word = 16;
97 xfers[j].len = 2;
98
99 spi_message_init(&msg);
100 for (j = 0; j < scan_count + 1; j++)
101 spi_message_add_tail(&xfers[j], &msg);
102
103 ret = spi_sync(st->us, &msg);
104 kfree(xfers);
105
106 return ret;
107}
108
109/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
110 * specific to be rolled into the core.
111 */
112static irqreturn_t adis16400_trigger_handler(int irq, void *p)
113{
114 struct iio_poll_func *pf = p;
115 struct iio_dev *indio_dev = pf->indio_dev;
116 struct adis16400_state *st = iio_priv(indio_dev);
117 int i = 0, j, ret = 0;
118 s16 *data;
119
120 /* Asumption that long is enough for maximum channels */
121 unsigned long mask = *indio_dev->active_scan_mask;
122 int scan_count = bitmap_weight(indio_dev->active_scan_mask,
123 indio_dev->masklength);
124 data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
125 if (data == NULL) {
126 dev_err(&st->us->dev, "memory alloc failed in ring bh");
127 goto done;
128 }
129
130 if (scan_count) {
131 if (st->variant->flags & ADIS16400_NO_BURST) {
132 ret = adis16350_spi_read_all(indio_dev, st->rx);
133 if (ret < 0)
134 goto done;
135 for (; i < scan_count; i++)
136 data[i] = *(s16 *)(st->rx + i*2);
137 } else {
138 ret = adis16400_spi_read_burst(indio_dev, st->rx);
139 if (ret < 0)
140 goto done;
141 for (; i < scan_count; i++) {
142 j = __ffs(mask);
143 mask &= ~(1 << j);
144 data[i] = be16_to_cpup(
145 (__be16 *)&(st->rx[j*2]));
146 }
147 }
148 }
149 /* Guaranteed to be aligned with 8 byte boundary */
150 if (indio_dev->scan_timestamp)
151 *((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
152 iio_push_to_buffers(indio_dev, (u8 *) data);
153
154done:
155 kfree(data);
156 iio_trigger_notify_done(indio_dev->trig);
157
158 return IRQ_HANDLED;
159}
160
161void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
162{
163 iio_dealloc_pollfunc(indio_dev->pollfunc);
164 iio_sw_rb_free(indio_dev->buffer);
165}
166
167static const struct iio_buffer_setup_ops adis16400_ring_setup_ops = {
168 .preenable = &iio_sw_buffer_preenable,
169 .postenable = &iio_triggered_buffer_postenable,
170 .predisable = &iio_triggered_buffer_predisable,
171};
172
173int adis16400_configure_ring(struct iio_dev *indio_dev)
174{
175 int ret = 0;
176 struct iio_buffer *ring;
177
178 ring = iio_sw_rb_allocate(indio_dev);
179 if (!ring) {
180 ret = -ENOMEM;
181 return ret;
182 }
183 indio_dev->buffer = ring;
184 ring->scan_timestamp = true;
185 indio_dev->setup_ops = &adis16400_ring_setup_ops;
186
187 indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
188 &adis16400_trigger_handler,
189 IRQF_ONESHOT,
190 indio_dev,
191 "%s_consumer%d",
192 indio_dev->name,
193 indio_dev->id);
194 if (indio_dev->pollfunc == NULL) {
195 ret = -ENOMEM;
196 goto error_iio_sw_rb_free;
197 }
198
199 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
200 return 0;
201error_iio_sw_rb_free:
202 iio_sw_rb_free(indio_dev->buffer);
203 return ret;
204}
diff --git a/drivers/staging/iio/imu/adis16400_trigger.c b/drivers/staging/iio/imu/adis16400_trigger.c
deleted file mode 100644
index 42a678e92fc6..000000000000
--- a/drivers/staging/iio/imu/adis16400_trigger.c
+++ /dev/null
@@ -1,74 +0,0 @@
1#include <linux/interrupt.h>
2#include <linux/kernel.h>
3#include <linux/spi/spi.h>
4#include <linux/export.h>
5
6#include <linux/iio/iio.h>
7#include <linux/iio/trigger.h>
8#include "adis16400.h"
9
10/**
11 * adis16400_data_rdy_trigger_set_state() set datardy interrupt state
12 **/
13static int adis16400_data_rdy_trigger_set_state(struct iio_trigger *trig,
14 bool state)
15{
16 struct iio_dev *indio_dev = trig->private_data;
17
18 dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
19 return adis16400_set_irq(indio_dev, state);
20}
21
22static const struct iio_trigger_ops adis16400_trigger_ops = {
23 .owner = THIS_MODULE,
24 .set_trigger_state = &adis16400_data_rdy_trigger_set_state,
25};
26
27int adis16400_probe_trigger(struct iio_dev *indio_dev)
28{
29 int ret;
30 struct adis16400_state *st = iio_priv(indio_dev);
31
32 st->trig = iio_trigger_alloc("%s-dev%d",
33 indio_dev->name,
34 indio_dev->id);
35 if (st->trig == NULL) {
36 ret = -ENOMEM;
37 goto error_ret;
38 }
39
40 ret = request_irq(st->us->irq,
41 &iio_trigger_generic_data_rdy_poll,
42 IRQF_TRIGGER_RISING,
43 "adis16400",
44 st->trig);
45 if (ret)
46 goto error_free_trig;
47 st->trig->dev.parent = &st->us->dev;
48 st->trig->private_data = indio_dev;
49 st->trig->ops = &adis16400_trigger_ops;
50 ret = iio_trigger_register(st->trig);
51
52 /* select default trigger */
53 indio_dev->trig = st->trig;
54 if (ret)
55 goto error_free_irq;
56
57 return 0;
58
59error_free_irq:
60 free_irq(st->us->irq, st->trig);
61error_free_trig:
62 iio_trigger_free(st->trig);
63error_ret:
64 return ret;
65}
66
67void adis16400_remove_trigger(struct iio_dev *indio_dev)
68{
69 struct adis16400_state *st = iio_priv(indio_dev);
70
71 iio_trigger_unregister(st->trig);
72 free_irq(st->us->irq, st->trig);
73 iio_trigger_free(st->trig);
74}
diff --git a/drivers/staging/iio/light/Kconfig b/drivers/staging/iio/light/Kconfig
index 4bed30eac3ed..ca8d6e66c899 100644
--- a/drivers/staging/iio/light/Kconfig
+++ b/drivers/staging/iio/light/Kconfig
@@ -25,16 +25,6 @@ config SENSORS_ISL29028
25 Proximity value via iio. The ISL29028 provides the concurrent sensing 25 Proximity value via iio. The ISL29028 provides the concurrent sensing
26 of ambient light and proximity. 26 of ambient light and proximity.
27 27
28config SENSORS_TSL2563
29 tristate "TAOS TSL2560, TSL2561, TSL2562 and TSL2563 ambient light sensors"
30 depends on I2C
31 help
32 If you say yes here you get support for the Taos TSL2560,
33 TSL2561, TSL2562 and TSL2563 ambient light sensors.
34
35 This driver can also be built as a module. If so, the module
36 will be called tsl2563.
37
38config TSL2583 28config TSL2583
39 tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters" 29 tristate "TAOS TSL2580, TSL2581 and TSL2583 light-to-digital converters"
40 depends on I2C 30 depends on I2C
diff --git a/drivers/staging/iio/light/Makefile b/drivers/staging/iio/light/Makefile
index 141af1eb164c..9960fdf7c15b 100644
--- a/drivers/staging/iio/light/Makefile
+++ b/drivers/staging/iio/light/Makefile
@@ -2,7 +2,6 @@
2# Makefile for industrial I/O Light sensors 2# Makefile for industrial I/O Light sensors
3# 3#
4 4
5obj-$(CONFIG_SENSORS_TSL2563) += tsl2563.o
6obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o 5obj-$(CONFIG_SENSORS_ISL29018) += isl29018.o
7obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o 6obj-$(CONFIG_SENSORS_ISL29028) += isl29028.o
8obj-$(CONFIG_TSL2583) += tsl2583.o 7obj-$(CONFIG_TSL2583) += tsl2583.o
diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
index 9e50fbbadf9d..a58731e70bb9 100644
--- a/drivers/staging/iio/light/tsl2x7x_core.c
+++ b/drivers/staging/iio/light/tsl2x7x_core.c
@@ -292,59 +292,6 @@ static const u8 device_channel_config[] = {
292}; 292};
293 293
294/** 294/**
295 * tsl2x7x_parse_buffer() - parse a decimal result from a buffer.
296 * @*buf: pointer to char buffer to parse
297 * @*result: pointer to buffer to contain
298 * resulting interger / decimal as ints.
299 *
300 */
301static int
302tsl2x7x_parse_buffer(const char *buf, struct tsl2x7x_parse_result *result)
303{
304 int integer = 0, fract = 0, fract_mult = 100000;
305 bool integer_part = true, negative = false;
306
307 if (buf[0] == '-') {
308 negative = true;
309 buf++;
310 }
311
312 while (*buf) {
313 if ('0' <= *buf && *buf <= '9') {
314 if (integer_part)
315 integer = integer*10 + *buf - '0';
316 else {
317 fract += fract_mult*(*buf - '0');
318 if (fract_mult == 1)
319 break;
320 fract_mult /= 10;
321 }
322 } else if (*buf == '\n') {
323 if (*(buf + 1) == '\0')
324 break;
325 else
326 return -EINVAL;
327 } else if (*buf == '.') {
328 integer_part = false;
329 } else {
330 return -EINVAL;
331 }
332 buf++;
333 }
334 if (negative) {
335 if (integer)
336 integer = -integer;
337 else
338 fract = -fract;
339 }
340
341 result->integer = integer;
342 result->fract = fract;
343
344 return 0;
345}
346
347/**
348 * tsl2x7x_i2c_read() - Read a byte from a register. 295 * tsl2x7x_i2c_read() - Read a byte from a register.
349 * @client: i2c client 296 * @client: i2c client
350 * @reg: device register to read from 297 * @reg: device register to read from
@@ -1036,13 +983,12 @@ static ssize_t tsl2x7x_als_time_store(struct device *dev,
1036 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 983 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
1037 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 984 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1038 struct tsl2x7x_parse_result result; 985 struct tsl2x7x_parse_result result;
986 int ret;
1039 987
1040 result.integer = 0; 988 ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
1041 result.fract = 0; 989 if (ret)
1042 990 return ret;
1043 tsl2x7x_parse_buffer(buf, &result);
1044 991
1045 result.fract /= 1000;
1046 result.fract /= 3; 992 result.fract /= 3;
1047 chip->tsl2x7x_settings.als_time = 993 chip->tsl2x7x_settings.als_time =
1048 (TSL2X7X_MAX_TIMER_CNT - (u8)result.fract); 994 (TSL2X7X_MAX_TIMER_CNT - (u8)result.fract);
@@ -1109,12 +1055,12 @@ static ssize_t tsl2x7x_als_persistence_store(struct device *dev,
1109 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1055 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1110 struct tsl2x7x_parse_result result; 1056 struct tsl2x7x_parse_result result;
1111 int y, z, filter_delay; 1057 int y, z, filter_delay;
1058 int ret;
1112 1059
1113 result.integer = 0; 1060 ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
1114 result.fract = 0; 1061 if (ret)
1115 tsl2x7x_parse_buffer(buf, &result); 1062 return ret;
1116 1063
1117 result.fract /= 1000;
1118 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1; 1064 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
1119 z = y * TSL2X7X_MIN_ITIME; 1065 z = y * TSL2X7X_MIN_ITIME;
1120 1066
@@ -1155,12 +1101,12 @@ static ssize_t tsl2x7x_prox_persistence_store(struct device *dev,
1155 struct tsl2X7X_chip *chip = iio_priv(indio_dev); 1101 struct tsl2X7X_chip *chip = iio_priv(indio_dev);
1156 struct tsl2x7x_parse_result result; 1102 struct tsl2x7x_parse_result result;
1157 int y, z, filter_delay; 1103 int y, z, filter_delay;
1104 int ret;
1158 1105
1159 result.integer = 0; 1106 ret = iio_str_to_fixpoint(buf, 100, &result.integer, &result.fract);
1160 result.fract = 0; 1107 if (ret)
1161 tsl2x7x_parse_buffer(buf, &result); 1108 return ret;
1162 1109
1163 result.fract /= 1000;
1164 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1; 1110 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
1165 z = y * TSL2X7X_MIN_ITIME; 1111 z = y * TSL2X7X_MIN_ITIME;
1166 1112
diff --git a/drivers/staging/iio/meter/Kconfig b/drivers/staging/iio/meter/Kconfig
index d290d2738419..e53274b64ae1 100644
--- a/drivers/staging/iio/meter/Kconfig
+++ b/drivers/staging/iio/meter/Kconfig
@@ -21,7 +21,7 @@ config ADE7758
21 tristate "Analog Devices ADE7758 Poly Phase Multifunction Energy Metering IC Driver" 21 tristate "Analog Devices ADE7758 Poly Phase Multifunction Energy Metering IC Driver"
22 depends on SPI 22 depends on SPI
23 select IIO_TRIGGER if IIO_BUFFER 23 select IIO_TRIGGER if IIO_BUFFER
24 select IIO_SW_RING if IIO_BUFFER 24 select IIO_KFIFO_BUF if IIO_BUFFER
25 help 25 help
26 Say yes here to build support for Analog Devices ADE7758 Polyphase 26 Say yes here to build support for Analog Devices ADE7758 Polyphase
27 Multifunction Energy Metering IC with Per Phase Information Driver. 27 Multifunction Energy Metering IC with Per Phase Information Driver.
diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
index 51c3bdece785..e5943e2287cf 100644
--- a/drivers/staging/iio/meter/ade7753.c
+++ b/drivers/staging/iio/meter/ade7753.c
@@ -103,7 +103,6 @@ static int ade7753_spi_read_reg_24(struct device *dev,
103 u8 reg_address, 103 u8 reg_address,
104 u32 *val) 104 u32 *val)
105{ 105{
106 struct spi_message msg;
107 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 106 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
108 struct ade7753_state *st = iio_priv(indio_dev); 107 struct ade7753_state *st = iio_priv(indio_dev);
109 int ret; 108 int ret;
@@ -122,10 +121,7 @@ static int ade7753_spi_read_reg_24(struct device *dev,
122 mutex_lock(&st->buf_lock); 121 mutex_lock(&st->buf_lock);
123 st->tx[0] = ADE7753_READ_REG(reg_address); 122 st->tx[0] = ADE7753_READ_REG(reg_address);
124 123
125 spi_message_init(&msg); 124 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
126 spi_message_add_tail(&xfers[0], &msg);
127 spi_message_add_tail(&xfers[1], &msg);
128 ret = spi_sync(st->us, &msg);
129 if (ret) { 125 if (ret) {
130 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X", 126 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X",
131 reg_address); 127 reg_address);
diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c
index b50c89e93993..7b6503bf9a74 100644
--- a/drivers/staging/iio/meter/ade7754.c
+++ b/drivers/staging/iio/meter/ade7754.c
@@ -103,7 +103,6 @@ static int ade7754_spi_read_reg_24(struct device *dev,
103 u8 reg_address, 103 u8 reg_address,
104 u32 *val) 104 u32 *val)
105{ 105{
106 struct spi_message msg;
107 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 106 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
108 struct ade7754_state *st = iio_priv(indio_dev); 107 struct ade7754_state *st = iio_priv(indio_dev);
109 int ret; 108 int ret;
@@ -122,9 +121,7 @@ static int ade7754_spi_read_reg_24(struct device *dev,
122 st->tx[2] = 0; 121 st->tx[2] = 0;
123 st->tx[3] = 0; 122 st->tx[3] = 0;
124 123
125 spi_message_init(&msg); 124 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
126 spi_message_add_tail(xfers, &msg);
127 ret = spi_sync(st->us, &msg);
128 if (ret) { 125 if (ret) {
129 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X", 126 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X",
130 reg_address); 127 reg_address);
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index 3454e5154ed2..53c68dcc4544 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -47,7 +47,6 @@ static int ade7758_spi_write_reg_16(struct device *dev,
47 u16 value) 47 u16 value)
48{ 48{
49 int ret; 49 int ret;
50 struct spi_message msg;
51 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 50 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
52 struct ade7758_state *st = iio_priv(indio_dev); 51 struct ade7758_state *st = iio_priv(indio_dev);
53 struct spi_transfer xfers[] = { 52 struct spi_transfer xfers[] = {
@@ -63,9 +62,7 @@ static int ade7758_spi_write_reg_16(struct device *dev,
63 st->tx[1] = (value >> 8) & 0xFF; 62 st->tx[1] = (value >> 8) & 0xFF;
64 st->tx[2] = value & 0xFF; 63 st->tx[2] = value & 0xFF;
65 64
66 spi_message_init(&msg); 65 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
67 spi_message_add_tail(xfers, &msg);
68 ret = spi_sync(st->us, &msg);
69 mutex_unlock(&st->buf_lock); 66 mutex_unlock(&st->buf_lock);
70 67
71 return ret; 68 return ret;
@@ -76,7 +73,6 @@ static int ade7758_spi_write_reg_24(struct device *dev,
76 u32 value) 73 u32 value)
77{ 74{
78 int ret; 75 int ret;
79 struct spi_message msg;
80 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 76 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
81 struct ade7758_state *st = iio_priv(indio_dev); 77 struct ade7758_state *st = iio_priv(indio_dev);
82 struct spi_transfer xfers[] = { 78 struct spi_transfer xfers[] = {
@@ -93,9 +89,7 @@ static int ade7758_spi_write_reg_24(struct device *dev,
93 st->tx[2] = (value >> 8) & 0xFF; 89 st->tx[2] = (value >> 8) & 0xFF;
94 st->tx[3] = value & 0xFF; 90 st->tx[3] = value & 0xFF;
95 91
96 spi_message_init(&msg); 92 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
97 spi_message_add_tail(xfers, &msg);
98 ret = spi_sync(st->us, &msg);
99 mutex_unlock(&st->buf_lock); 93 mutex_unlock(&st->buf_lock);
100 94
101 return ret; 95 return ret;
@@ -105,7 +99,6 @@ int ade7758_spi_read_reg_8(struct device *dev,
105 u8 reg_address, 99 u8 reg_address,
106 u8 *val) 100 u8 *val)
107{ 101{
108 struct spi_message msg;
109 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 102 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
110 struct ade7758_state *st = iio_priv(indio_dev); 103 struct ade7758_state *st = iio_priv(indio_dev);
111 int ret; 104 int ret;
@@ -128,10 +121,7 @@ int ade7758_spi_read_reg_8(struct device *dev,
128 st->tx[0] = ADE7758_READ_REG(reg_address); 121 st->tx[0] = ADE7758_READ_REG(reg_address);
129 st->tx[1] = 0; 122 st->tx[1] = 0;
130 123
131 spi_message_init(&msg); 124 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
132 spi_message_add_tail(&xfers[0], &msg);
133 spi_message_add_tail(&xfers[1], &msg);
134 ret = spi_sync(st->us, &msg);
135 if (ret) { 125 if (ret) {
136 dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X", 126 dev_err(&st->us->dev, "problem when reading 8 bit register 0x%02X",
137 reg_address); 127 reg_address);
@@ -148,7 +138,6 @@ static int ade7758_spi_read_reg_16(struct device *dev,
148 u8 reg_address, 138 u8 reg_address,
149 u16 *val) 139 u16 *val)
150{ 140{
151 struct spi_message msg;
152 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 141 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
153 struct ade7758_state *st = iio_priv(indio_dev); 142 struct ade7758_state *st = iio_priv(indio_dev);
154 int ret; 143 int ret;
@@ -173,10 +162,7 @@ static int ade7758_spi_read_reg_16(struct device *dev,
173 st->tx[1] = 0; 162 st->tx[1] = 0;
174 st->tx[2] = 0; 163 st->tx[2] = 0;
175 164
176 spi_message_init(&msg); 165 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
177 spi_message_add_tail(&xfers[0], &msg);
178 spi_message_add_tail(&xfers[1], &msg);
179 ret = spi_sync(st->us, &msg);
180 if (ret) { 166 if (ret) {
181 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X", 167 dev_err(&st->us->dev, "problem when reading 16 bit register 0x%02X",
182 reg_address); 168 reg_address);
@@ -194,7 +180,6 @@ static int ade7758_spi_read_reg_24(struct device *dev,
194 u8 reg_address, 180 u8 reg_address,
195 u32 *val) 181 u32 *val)
196{ 182{
197 struct spi_message msg;
198 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 183 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
199 struct ade7758_state *st = iio_priv(indio_dev); 184 struct ade7758_state *st = iio_priv(indio_dev);
200 int ret; 185 int ret;
@@ -219,10 +204,7 @@ static int ade7758_spi_read_reg_24(struct device *dev,
219 st->tx[2] = 0; 204 st->tx[2] = 0;
220 st->tx[3] = 0; 205 st->tx[3] = 0;
221 206
222 spi_message_init(&msg); 207 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
223 spi_message_add_tail(&xfers[0], &msg);
224 spi_message_add_tail(&xfers[1], &msg);
225 ret = spi_sync(st->us, &msg);
226 if (ret) { 208 if (ret) {
227 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X", 209 dev_err(&st->us->dev, "problem when reading 24 bit register 0x%02X",
228 reg_address); 210 reg_address);
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index 4552a4c7fe33..b29e2d5d9937 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -13,7 +13,7 @@
13#include <asm/unaligned.h> 13#include <asm/unaligned.h>
14 14
15#include <linux/iio/iio.h> 15#include <linux/iio/iio.h>
16#include "../ring_sw.h" 16#include <linux/iio/kfifo_buf.h>
17#include <linux/iio/trigger_consumer.h> 17#include <linux/iio/trigger_consumer.h>
18#include "ade7758.h" 18#include "ade7758.h"
19 19
@@ -119,7 +119,7 @@ static const struct iio_buffer_setup_ops ade7758_ring_setup_ops = {
119void ade7758_unconfigure_ring(struct iio_dev *indio_dev) 119void ade7758_unconfigure_ring(struct iio_dev *indio_dev)
120{ 120{
121 iio_dealloc_pollfunc(indio_dev->pollfunc); 121 iio_dealloc_pollfunc(indio_dev->pollfunc);
122 iio_sw_rb_free(indio_dev->buffer); 122 iio_kfifo_free(indio_dev->buffer);
123} 123}
124 124
125int ade7758_configure_ring(struct iio_dev *indio_dev) 125int ade7758_configure_ring(struct iio_dev *indio_dev)
@@ -127,7 +127,7 @@ int ade7758_configure_ring(struct iio_dev *indio_dev)
127 struct ade7758_state *st = iio_priv(indio_dev); 127 struct ade7758_state *st = iio_priv(indio_dev);
128 int ret = 0; 128 int ret = 0;
129 129
130 indio_dev->buffer = iio_sw_rb_allocate(indio_dev); 130 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
131 if (!indio_dev->buffer) { 131 if (!indio_dev->buffer) {
132 ret = -ENOMEM; 132 ret = -ENOMEM;
133 return ret; 133 return ret;
@@ -143,7 +143,7 @@ int ade7758_configure_ring(struct iio_dev *indio_dev)
143 indio_dev->id); 143 indio_dev->id);
144 if (indio_dev->pollfunc == NULL) { 144 if (indio_dev->pollfunc == NULL) {
145 ret = -ENOMEM; 145 ret = -ENOMEM;
146 goto error_iio_sw_rb_free; 146 goto error_iio_kfifo_free;
147 } 147 }
148 148
149 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 149 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
@@ -183,8 +183,8 @@ int ade7758_configure_ring(struct iio_dev *indio_dev)
183 183
184 return 0; 184 return 0;
185 185
186error_iio_sw_rb_free: 186error_iio_kfifo_free:
187 iio_sw_rb_free(indio_dev->buffer); 187 iio_kfifo_free(indio_dev->buffer);
188 return ret; 188 return ret;
189} 189}
190 190
diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c
index 10b911bd3853..17dc373e1082 100644
--- a/drivers/staging/iio/meter/ade7759.c
+++ b/drivers/staging/iio/meter/ade7759.c
@@ -103,7 +103,6 @@ static int ade7759_spi_read_reg_40(struct device *dev,
103 u8 reg_address, 103 u8 reg_address,
104 u64 *val) 104 u64 *val)
105{ 105{
106 struct spi_message msg;
107 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 106 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
108 struct ade7759_state *st = iio_priv(indio_dev); 107 struct ade7759_state *st = iio_priv(indio_dev);
109 int ret; 108 int ret;
@@ -120,9 +119,7 @@ static int ade7759_spi_read_reg_40(struct device *dev,
120 st->tx[0] = ADE7759_READ_REG(reg_address); 119 st->tx[0] = ADE7759_READ_REG(reg_address);
121 memset(&st->tx[1], 0 , 5); 120 memset(&st->tx[1], 0 , 5);
122 121
123 spi_message_init(&msg); 122 ret = spi_sync_transfer(st->us, xfers, ARRAY_SIZE(xfers));
124 spi_message_add_tail(xfers, &msg);
125 ret = spi_sync(st->us, &msg);
126 if (ret) { 123 if (ret) {
127 dev_err(&st->us->dev, "problem when reading 40 bit register 0x%02X", 124 dev_err(&st->us->dev, "problem when reading 40 bit register 0x%02X",
128 reg_address); 125 reg_address);
diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c
index f0984fa1cbb9..a802cf2491d6 100644
--- a/drivers/staging/iio/meter/ade7854-spi.c
+++ b/drivers/staging/iio/meter/ade7854-spi.c
@@ -20,7 +20,6 @@ static int ade7854_spi_write_reg_8(struct device *dev,
20 u8 value) 20 u8 value)
21{ 21{
22 int ret; 22 int ret;
23 struct spi_message msg;
24 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 23 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
25 struct ade7854_state *st = iio_priv(indio_dev); 24 struct ade7854_state *st = iio_priv(indio_dev);
26 struct spi_transfer xfer = { 25 struct spi_transfer xfer = {
@@ -35,9 +34,7 @@ static int ade7854_spi_write_reg_8(struct device *dev,
35 st->tx[2] = reg_address & 0xFF; 34 st->tx[2] = reg_address & 0xFF;
36 st->tx[3] = value & 0xFF; 35 st->tx[3] = value & 0xFF;
37 36
38 spi_message_init(&msg); 37 ret = spi_sync_transfer(st->spi, &xfer, 1);
39 spi_message_add_tail(&xfer, &msg);
40 ret = spi_sync(st->spi, &msg);
41 mutex_unlock(&st->buf_lock); 38 mutex_unlock(&st->buf_lock);
42 39
43 return ret; 40 return ret;
@@ -48,7 +45,6 @@ static int ade7854_spi_write_reg_16(struct device *dev,
48 u16 value) 45 u16 value)
49{ 46{
50 int ret; 47 int ret;
51 struct spi_message msg;
52 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 48 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
53 struct ade7854_state *st = iio_priv(indio_dev); 49 struct ade7854_state *st = iio_priv(indio_dev);
54 struct spi_transfer xfer = { 50 struct spi_transfer xfer = {
@@ -64,9 +60,7 @@ static int ade7854_spi_write_reg_16(struct device *dev,
64 st->tx[3] = (value >> 8) & 0xFF; 60 st->tx[3] = (value >> 8) & 0xFF;
65 st->tx[4] = value & 0xFF; 61 st->tx[4] = value & 0xFF;
66 62
67 spi_message_init(&msg); 63 ret = spi_sync_transfer(st->spi, &xfer, 1);
68 spi_message_add_tail(&xfer, &msg);
69 ret = spi_sync(st->spi, &msg);
70 mutex_unlock(&st->buf_lock); 64 mutex_unlock(&st->buf_lock);
71 65
72 return ret; 66 return ret;
@@ -77,7 +71,6 @@ static int ade7854_spi_write_reg_24(struct device *dev,
77 u32 value) 71 u32 value)
78{ 72{
79 int ret; 73 int ret;
80 struct spi_message msg;
81 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 74 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
82 struct ade7854_state *st = iio_priv(indio_dev); 75 struct ade7854_state *st = iio_priv(indio_dev);
83 struct spi_transfer xfer = { 76 struct spi_transfer xfer = {
@@ -94,9 +87,7 @@ static int ade7854_spi_write_reg_24(struct device *dev,
94 st->tx[4] = (value >> 8) & 0xFF; 87 st->tx[4] = (value >> 8) & 0xFF;
95 st->tx[5] = value & 0xFF; 88 st->tx[5] = value & 0xFF;
96 89
97 spi_message_init(&msg); 90 ret = spi_sync_transfer(st->spi, &xfer, 1);
98 spi_message_add_tail(&xfer, &msg);
99 ret = spi_sync(st->spi, &msg);
100 mutex_unlock(&st->buf_lock); 91 mutex_unlock(&st->buf_lock);
101 92
102 return ret; 93 return ret;
@@ -107,7 +98,6 @@ static int ade7854_spi_write_reg_32(struct device *dev,
107 u32 value) 98 u32 value)
108{ 99{
109 int ret; 100 int ret;
110 struct spi_message msg;
111 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 101 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
112 struct ade7854_state *st = iio_priv(indio_dev); 102 struct ade7854_state *st = iio_priv(indio_dev);
113 struct spi_transfer xfer = { 103 struct spi_transfer xfer = {
@@ -125,9 +115,7 @@ static int ade7854_spi_write_reg_32(struct device *dev,
125 st->tx[5] = (value >> 8) & 0xFF; 115 st->tx[5] = (value >> 8) & 0xFF;
126 st->tx[6] = value & 0xFF; 116 st->tx[6] = value & 0xFF;
127 117
128 spi_message_init(&msg); 118 ret = spi_sync_transfer(st->spi, &xfer, 1);
129 spi_message_add_tail(&xfer, &msg);
130 ret = spi_sync(st->spi, &msg);
131 mutex_unlock(&st->buf_lock); 119 mutex_unlock(&st->buf_lock);
132 120
133 return ret; 121 return ret;
@@ -137,7 +125,6 @@ static int ade7854_spi_read_reg_8(struct device *dev,
137 u16 reg_address, 125 u16 reg_address,
138 u8 *val) 126 u8 *val)
139{ 127{
140 struct spi_message msg;
141 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 128 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
142 struct ade7854_state *st = iio_priv(indio_dev); 129 struct ade7854_state *st = iio_priv(indio_dev);
143 int ret; 130 int ret;
@@ -159,10 +146,7 @@ static int ade7854_spi_read_reg_8(struct device *dev,
159 st->tx[1] = (reg_address >> 8) & 0xFF; 146 st->tx[1] = (reg_address >> 8) & 0xFF;
160 st->tx[2] = reg_address & 0xFF; 147 st->tx[2] = reg_address & 0xFF;
161 148
162 spi_message_init(&msg); 149 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
163 spi_message_add_tail(&xfers[0], &msg);
164 spi_message_add_tail(&xfers[1], &msg);
165 ret = spi_sync(st->spi, &msg);
166 if (ret) { 150 if (ret) {
167 dev_err(&st->spi->dev, "problem when reading 8 bit register 0x%02X", 151 dev_err(&st->spi->dev, "problem when reading 8 bit register 0x%02X",
168 reg_address); 152 reg_address);
@@ -179,7 +163,6 @@ static int ade7854_spi_read_reg_16(struct device *dev,
179 u16 reg_address, 163 u16 reg_address,
180 u16 *val) 164 u16 *val)
181{ 165{
182 struct spi_message msg;
183 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 166 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
184 struct ade7854_state *st = iio_priv(indio_dev); 167 struct ade7854_state *st = iio_priv(indio_dev);
185 int ret; 168 int ret;
@@ -200,10 +183,7 @@ static int ade7854_spi_read_reg_16(struct device *dev,
200 st->tx[1] = (reg_address >> 8) & 0xFF; 183 st->tx[1] = (reg_address >> 8) & 0xFF;
201 st->tx[2] = reg_address & 0xFF; 184 st->tx[2] = reg_address & 0xFF;
202 185
203 spi_message_init(&msg); 186 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
204 spi_message_add_tail(&xfers[0], &msg);
205 spi_message_add_tail(&xfers[1], &msg);
206 ret = spi_sync(st->spi, &msg);
207 if (ret) { 187 if (ret) {
208 dev_err(&st->spi->dev, "problem when reading 16 bit register 0x%02X", 188 dev_err(&st->spi->dev, "problem when reading 16 bit register 0x%02X",
209 reg_address); 189 reg_address);
@@ -220,7 +200,6 @@ static int ade7854_spi_read_reg_24(struct device *dev,
220 u16 reg_address, 200 u16 reg_address,
221 u32 *val) 201 u32 *val)
222{ 202{
223 struct spi_message msg;
224 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 203 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
225 struct ade7854_state *st = iio_priv(indio_dev); 204 struct ade7854_state *st = iio_priv(indio_dev);
226 int ret; 205 int ret;
@@ -242,10 +221,7 @@ static int ade7854_spi_read_reg_24(struct device *dev,
242 st->tx[1] = (reg_address >> 8) & 0xFF; 221 st->tx[1] = (reg_address >> 8) & 0xFF;
243 st->tx[2] = reg_address & 0xFF; 222 st->tx[2] = reg_address & 0xFF;
244 223
245 spi_message_init(&msg); 224 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
246 spi_message_add_tail(&xfers[0], &msg);
247 spi_message_add_tail(&xfers[1], &msg);
248 ret = spi_sync(st->spi, &msg);
249 if (ret) { 225 if (ret) {
250 dev_err(&st->spi->dev, "problem when reading 24 bit register 0x%02X", 226 dev_err(&st->spi->dev, "problem when reading 24 bit register 0x%02X",
251 reg_address); 227 reg_address);
@@ -262,7 +238,6 @@ static int ade7854_spi_read_reg_32(struct device *dev,
262 u16 reg_address, 238 u16 reg_address,
263 u32 *val) 239 u32 *val)
264{ 240{
265 struct spi_message msg;
266 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 241 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
267 struct ade7854_state *st = iio_priv(indio_dev); 242 struct ade7854_state *st = iio_priv(indio_dev);
268 int ret; 243 int ret;
@@ -284,10 +259,7 @@ static int ade7854_spi_read_reg_32(struct device *dev,
284 st->tx[1] = (reg_address >> 8) & 0xFF; 259 st->tx[1] = (reg_address >> 8) & 0xFF;
285 st->tx[2] = reg_address & 0xFF; 260 st->tx[2] = reg_address & 0xFF;
286 261
287 spi_message_init(&msg); 262 ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers));
288 spi_message_add_tail(&xfers[0], &msg);
289 spi_message_add_tail(&xfers[1], &msg);
290 ret = spi_sync(st->spi, &msg);
291 if (ret) { 263 if (ret) {
292 dev_err(&st->spi->dev, "problem when reading 32 bit register 0x%02X", 264 dev_err(&st->spi->dev, "problem when reading 32 bit register 0x%02X",
293 reg_address); 265 reg_address);
diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c
index ed07a348eb55..53110b6a3c74 100644
--- a/drivers/staging/iio/resolver/ad2s1210.c
+++ b/drivers/staging/iio/resolver/ad2s1210.c
@@ -130,15 +130,12 @@ static int ad2s1210_config_read(struct ad2s1210_state *st,
130 .rx_buf = st->rx, 130 .rx_buf = st->rx,
131 .tx_buf = st->tx, 131 .tx_buf = st->tx,
132 }; 132 };
133 struct spi_message msg;
134 int ret = 0; 133 int ret = 0;
135 134
136 ad2s1210_set_mode(MOD_CONFIG, st); 135 ad2s1210_set_mode(MOD_CONFIG, st);
137 spi_message_init(&msg);
138 spi_message_add_tail(&xfer, &msg);
139 st->tx[0] = address | AD2S1210_MSB_IS_HIGH; 136 st->tx[0] = address | AD2S1210_MSB_IS_HIGH;
140 st->tx[1] = AD2S1210_REG_FAULT; 137 st->tx[1] = AD2S1210_REG_FAULT;
141 ret = spi_sync(st->sdev, &msg); 138 ret = spi_sync_transfer(st->sdev, &xfer, 1);
142 if (ret < 0) 139 if (ret < 0)
143 return ret; 140 return ret;
144 st->old_data = true; 141 st->old_data = true;
diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
deleted file mode 100644
index 3a45f9a52de8..000000000000
--- a/drivers/staging/iio/ring_sw.c
+++ /dev/null
@@ -1,366 +0,0 @@
1/* The industrial I/O simple minimally locked ring buffer.
2 *
3 * Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10#include <linux/slab.h>
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/device.h>
14#include <linux/workqueue.h>
15#include <linux/sched.h>
16#include <linux/poll.h>
17#include "ring_sw.h"
18#include <linux/iio/trigger.h>
19
20/**
21 * struct iio_sw_ring_buffer - software ring buffer
22 * @buf: generic ring buffer elements
23 * @data: the ring buffer memory
24 * @read_p: read pointer (oldest available)
25 * @write_p: write pointer
26 * @half_p: half buffer length behind write_p (event generation)
27 * @update_needed: flag to indicate change in size requested
28 *
29 * Note that the first element of all ring buffers must be a
30 * struct iio_buffer.
31**/
32struct iio_sw_ring_buffer {
33 struct iio_buffer buf;
34 unsigned char *data;
35 unsigned char *read_p;
36 unsigned char *write_p;
37 /* used to act as a point at which to signal an event */
38 unsigned char *half_p;
39 int update_needed;
40};
41
42#define iio_to_sw_ring(r) container_of(r, struct iio_sw_ring_buffer, buf)
43
44static inline int __iio_allocate_sw_ring_buffer(struct iio_sw_ring_buffer *ring,
45 int bytes_per_datum, int length)
46{
47 if ((length == 0) || (bytes_per_datum == 0))
48 return -EINVAL;
49 __iio_update_buffer(&ring->buf, bytes_per_datum, length);
50 ring->data = kmalloc(length*ring->buf.bytes_per_datum, GFP_ATOMIC);
51 ring->read_p = NULL;
52 ring->write_p = NULL;
53 ring->half_p = NULL;
54 return ring->data ? 0 : -ENOMEM;
55}
56
57static inline void __iio_free_sw_ring_buffer(struct iio_sw_ring_buffer *ring)
58{
59 kfree(ring->data);
60}
61
62/* Ring buffer related functionality */
63/* Store to ring is typically called in the bh of a data ready interrupt handler
64 * in the device driver */
65/* Lock always held if their is a chance this may be called */
66/* Only one of these per ring may run concurrently - enforced by drivers */
67static int iio_store_to_sw_ring(struct iio_sw_ring_buffer *ring,
68 unsigned char *data)
69{
70 int ret = 0;
71 unsigned char *temp_ptr, *change_test_ptr;
72
73 /* initial store */
74 if (unlikely(ring->write_p == NULL)) {
75 ring->write_p = ring->data;
76 /* Doesn't actually matter if this is out of the set
77 * as long as the read pointer is valid before this
78 * passes it - guaranteed as set later in this function.
79 */
80 ring->half_p = ring->data - ring->buf.length*ring->buf.bytes_per_datum/2;
81 }
82 /* Copy data to where ever the current write pointer says */
83 memcpy(ring->write_p, data, ring->buf.bytes_per_datum);
84 barrier();
85 /* Update the pointer used to get most recent value.
86 * Always valid as either points to latest or second latest value.
87 * Before this runs it is null and read attempts fail with -EAGAIN.
88 */
89 barrier();
90 /* temp_ptr used to ensure we never have an invalid pointer
91 * it may be slightly lagging, but never invalid
92 */
93 temp_ptr = ring->write_p + ring->buf.bytes_per_datum;
94 /* End of ring, back to the beginning */
95 if (temp_ptr == ring->data + ring->buf.length*ring->buf.bytes_per_datum)
96 temp_ptr = ring->data;
97 /* Update the write pointer
98 * always valid as long as this is the only function able to write.
99 * Care needed with smp systems to ensure more than one ring fill
100 * is never scheduled.
101 */
102 ring->write_p = temp_ptr;
103
104 if (ring->read_p == NULL)
105 ring->read_p = ring->data;
106 /* Buffer full - move the read pointer and create / escalate
107 * ring event */
108 /* Tricky case - if the read pointer moves before we adjust it.
109 * Handle by not pushing if it has moved - may result in occasional
110 * unnecessary buffer full events when it wasn't quite true.
111 */
112 else if (ring->write_p == ring->read_p) {
113 change_test_ptr = ring->read_p;
114 temp_ptr = change_test_ptr + ring->buf.bytes_per_datum;
115 if (temp_ptr
116 == ring->data + ring->buf.length*ring->buf.bytes_per_datum) {
117 temp_ptr = ring->data;
118 }
119 /* We are moving pointer on one because the ring is full. Any
120 * change to the read pointer will be this or greater.
121 */
122 if (change_test_ptr == ring->read_p)
123 ring->read_p = temp_ptr;
124 }
125 /* investigate if our event barrier has been passed */
126 /* There are definite 'issues' with this and chances of
127 * simultaneous read */
128 /* Also need to use loop count to ensure this only happens once */
129 ring->half_p += ring->buf.bytes_per_datum;
130 if (ring->half_p == ring->data + ring->buf.length*ring->buf.bytes_per_datum)
131 ring->half_p = ring->data;
132 if (ring->half_p == ring->read_p) {
133 ring->buf.stufftoread = true;
134 wake_up_interruptible(&ring->buf.pollq);
135 }
136 return ret;
137}
138
139static int iio_read_first_n_sw_rb(struct iio_buffer *r,
140 size_t n, char __user *buf)
141{
142 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
143
144 u8 *initial_read_p, *initial_write_p, *current_read_p, *end_read_p;
145 u8 *data;
146 int ret, max_copied, bytes_to_rip, dead_offset;
147 size_t data_available, buffer_size;
148
149 /* A userspace program has probably made an error if it tries to
150 * read something that is not a whole number of bpds.
151 * Return an error.
152 */
153 if (n % ring->buf.bytes_per_datum) {
154 ret = -EINVAL;
155 printk(KERN_INFO "Ring buffer read request not whole number of"
156 "samples: Request bytes %zd, Current bytes per datum %d\n",
157 n, ring->buf.bytes_per_datum);
158 goto error_ret;
159 }
160
161 buffer_size = ring->buf.bytes_per_datum*ring->buf.length;
162
163 /* Limit size to whole of ring buffer */
164 bytes_to_rip = min_t(size_t, buffer_size, n);
165
166 data = kmalloc(bytes_to_rip, GFP_KERNEL);
167 if (data == NULL) {
168 ret = -ENOMEM;
169 goto error_ret;
170 }
171
172 /* build local copy */
173 initial_read_p = ring->read_p;
174 if (unlikely(initial_read_p == NULL)) { /* No data here as yet */
175 ret = 0;
176 goto error_free_data_cpy;
177 }
178
179 initial_write_p = ring->write_p;
180
181 /* Need a consistent pair */
182 while ((initial_read_p != ring->read_p)
183 || (initial_write_p != ring->write_p)) {
184 initial_read_p = ring->read_p;
185 initial_write_p = ring->write_p;
186 }
187 if (initial_write_p == initial_read_p) {
188 /* No new data available.*/
189 ret = 0;
190 goto error_free_data_cpy;
191 }
192
193 if (initial_write_p >= initial_read_p)
194 data_available = initial_write_p - initial_read_p;
195 else
196 data_available = buffer_size - (initial_read_p - initial_write_p);
197
198 if (data_available < bytes_to_rip)
199 bytes_to_rip = data_available;
200
201 if (initial_read_p + bytes_to_rip >= ring->data + buffer_size) {
202 max_copied = ring->data + buffer_size - initial_read_p;
203 memcpy(data, initial_read_p, max_copied);
204 memcpy(data + max_copied, ring->data, bytes_to_rip - max_copied);
205 end_read_p = ring->data + bytes_to_rip - max_copied;
206 } else {
207 memcpy(data, initial_read_p, bytes_to_rip);
208 end_read_p = initial_read_p + bytes_to_rip;
209 }
210
211 /* Now to verify which section was cleanly copied - i.e. how far
212 * read pointer has been pushed */
213 current_read_p = ring->read_p;
214
215 if (initial_read_p <= current_read_p)
216 dead_offset = current_read_p - initial_read_p;
217 else
218 dead_offset = buffer_size - (initial_read_p - current_read_p);
219
220 /* possible issue if the initial write has been lapped or indeed
221 * the point we were reading to has been passed */
222 /* No valid data read.
223 * In this case the read pointer is already correct having been
224 * pushed further than we would look. */
225 if (bytes_to_rip - dead_offset < 0) {
226 ret = 0;
227 goto error_free_data_cpy;
228 }
229
230 /* setup the next read position */
231 /* Beware, this may fail due to concurrency fun and games.
232 * Possible that sufficient fill commands have run to push the read
233 * pointer past where we would be after the rip. If this occurs, leave
234 * it be.
235 */
236 /* Tricky - deal with loops */
237
238 while (ring->read_p != end_read_p)
239 ring->read_p = end_read_p;
240
241 ret = bytes_to_rip - dead_offset;
242
243 if (copy_to_user(buf, data + dead_offset, ret)) {
244 ret = -EFAULT;
245 goto error_free_data_cpy;
246 }
247
248 if (bytes_to_rip >= ring->buf.length*ring->buf.bytes_per_datum/2)
249 ring->buf.stufftoread = 0;
250
251error_free_data_cpy:
252 kfree(data);
253error_ret:
254
255 return ret;
256}
257
258static int iio_store_to_sw_rb(struct iio_buffer *r,
259 u8 *data)
260{
261 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
262 return iio_store_to_sw_ring(ring, data);
263}
264
265static int iio_request_update_sw_rb(struct iio_buffer *r)
266{
267 int ret = 0;
268 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
269
270 r->stufftoread = false;
271 if (!ring->update_needed)
272 goto error_ret;
273 __iio_free_sw_ring_buffer(ring);
274 ret = __iio_allocate_sw_ring_buffer(ring, ring->buf.bytes_per_datum,
275 ring->buf.length);
276error_ret:
277 return ret;
278}
279
280static int iio_get_bytes_per_datum_sw_rb(struct iio_buffer *r)
281{
282 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
283 return ring->buf.bytes_per_datum;
284}
285
286static int iio_mark_update_needed_sw_rb(struct iio_buffer *r)
287{
288 struct iio_sw_ring_buffer *ring = iio_to_sw_ring(r);
289 ring->update_needed = true;
290 return 0;
291}
292
293static int iio_set_bytes_per_datum_sw_rb(struct iio_buffer *r, size_t bpd)
294{
295 if (r->bytes_per_datum != bpd) {
296 r->bytes_per_datum = bpd;
297 iio_mark_update_needed_sw_rb(r);
298 }
299 return 0;
300}
301
302static int iio_get_length_sw_rb(struct iio_buffer *r)
303{
304 return r->length;
305}
306
307static int iio_set_length_sw_rb(struct iio_buffer *r, int length)
308{
309 if (r->length != length) {
310 r->length = length;
311 iio_mark_update_needed_sw_rb(r);
312 }
313 return 0;
314}
315
316static IIO_BUFFER_ENABLE_ATTR;
317static IIO_BUFFER_LENGTH_ATTR;
318
319/* Standard set of ring buffer attributes */
320static struct attribute *iio_ring_attributes[] = {
321 &dev_attr_length.attr,
322 &dev_attr_enable.attr,
323 NULL,
324};
325
326static struct attribute_group iio_ring_attribute_group = {
327 .attrs = iio_ring_attributes,
328 .name = "buffer",
329};
330
331static const struct iio_buffer_access_funcs ring_sw_access_funcs = {
332 .store_to = &iio_store_to_sw_rb,
333 .read_first_n = &iio_read_first_n_sw_rb,
334 .request_update = &iio_request_update_sw_rb,
335 .get_bytes_per_datum = &iio_get_bytes_per_datum_sw_rb,
336 .set_bytes_per_datum = &iio_set_bytes_per_datum_sw_rb,
337 .get_length = &iio_get_length_sw_rb,
338 .set_length = &iio_set_length_sw_rb,
339};
340
341struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev)
342{
343 struct iio_buffer *buf;
344 struct iio_sw_ring_buffer *ring;
345
346 ring = kzalloc(sizeof *ring, GFP_KERNEL);
347 if (!ring)
348 return NULL;
349 ring->update_needed = true;
350 buf = &ring->buf;
351 iio_buffer_init(buf);
352 buf->attrs = &iio_ring_attribute_group;
353 buf->access = &ring_sw_access_funcs;
354
355 return buf;
356}
357EXPORT_SYMBOL(iio_sw_rb_allocate);
358
359void iio_sw_rb_free(struct iio_buffer *r)
360{
361 kfree(iio_to_sw_ring(r));
362}
363EXPORT_SYMBOL(iio_sw_rb_free);
364
365MODULE_DESCRIPTION("Industrial I/O software ring buffer");
366MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/ring_sw.h b/drivers/staging/iio/ring_sw.h
deleted file mode 100644
index a5857aa7aefa..000000000000
--- a/drivers/staging/iio/ring_sw.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/* The industrial I/O simple minimally locked ring buffer.
2 *
3 * Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * This code is deliberately kept separate from the main industrialio I/O core
10 * as it is intended that in the future a number of different software ring
11 * buffer implementations will exist with different characteristics to suit
12 * different applications.
13 *
14 * This particular one was designed for a data capture application where it was
15 * particularly important that no userspace reads would interrupt the capture
16 * process. To this end the ring is not locked during a read.
17 *
18 * Comments on this buffer design welcomed. It's far from efficient and some of
19 * my understanding of the effects of scheduling on this are somewhat limited.
20 * Frankly, to my mind, this is the current weak point in the industrial I/O
21 * patch set.
22 */
23
24#ifndef _IIO_RING_SW_H_
25#define _IIO_RING_SW_H_
26#include <linux/iio/buffer.h>
27
28struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev);
29void iio_sw_rb_free(struct iio_buffer *ring);
30#endif /* _IIO_RING_SW_H_ */
diff --git a/drivers/staging/imx-drm/ipu-v3/ipu-common.c b/drivers/staging/imx-drm/ipu-v3/ipu-common.c
index f7059cddd7fd..366f259e3756 100644
--- a/drivers/staging/imx-drm/ipu-v3/ipu-common.c
+++ b/drivers/staging/imx-drm/ipu-v3/ipu-common.c
@@ -1142,9 +1142,6 @@ failed_ioremap:
1142static int ipu_remove(struct platform_device *pdev) 1142static int ipu_remove(struct platform_device *pdev)
1143{ 1143{
1144 struct ipu_soc *ipu = platform_get_drvdata(pdev); 1144 struct ipu_soc *ipu = platform_get_drvdata(pdev);
1145 struct resource *res;
1146
1147 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1148 1145
1149 platform_device_unregister_children(pdev); 1146 platform_device_unregister_children(pdev);
1150 ipu_submodules_exit(ipu); 1147 ipu_submodules_exit(ipu);
diff --git a/drivers/staging/imx-drm/ipu-v3/ipu-di.c b/drivers/staging/imx-drm/ipu-v3/ipu-di.c
index 67d974f7be36..ec340da968ac 100644
--- a/drivers/staging/imx-drm/ipu-v3/ipu-di.c
+++ b/drivers/staging/imx-drm/ipu-v3/ipu-di.c
@@ -677,7 +677,7 @@ int ipu_di_init(struct ipu_soc *ipu, struct device *dev, int id,
677 goto failed_clk_register; 677 goto failed_clk_register;
678 } 678 }
679 679
680 dev_info(dev, "DI%d base: 0x%08lx remapped to %p\n", 680 dev_dbg(dev, "DI%d base: 0x%08lx remapped to %p\n",
681 id, base, di->base); 681 id, base, di->base);
682 di->inuse = false; 682 di->inuse = false;
683 di->ipu = ipu; 683 di->ipu = ipu;
diff --git a/drivers/staging/keucr/usb.c b/drivers/staging/keucr/usb.c
index 55a0b82c6391..f656f8aeeda3 100644
--- a/drivers/staging/keucr/usb.c
+++ b/drivers/staging/keucr/usb.c
@@ -42,19 +42,12 @@ static int eucr_suspend(struct usb_interface *iface, pm_message_t message)
42 /* Wait until no command is running */ 42 /* Wait until no command is running */
43 mutex_lock(&us->dev_mutex); 43 mutex_lock(&us->dev_mutex);
44 44
45 //US_DEBUGP("%s\n", __func__);
46 if (us->suspend_resume_hook) 45 if (us->suspend_resume_hook)
47 (us->suspend_resume_hook)(us, US_SUSPEND); 46 (us->suspend_resume_hook)(us, US_SUSPEND);
48 47
49 /* When runtime PM is working, we'll set a flag to indicate
50 * whether we should autoresume when a SCSI request arrives. */
51 // us->Power_IsResum = true;
52 //us->SD_Status.Ready = 0;
53
54 mutex_unlock(&us->dev_mutex); 48 mutex_unlock(&us->dev_mutex);
55 return 0; 49 return 0;
56} 50}
57//EXPORT_SYMBOL_GPL(eucr_suspend);
58 51
59static int eucr_resume(struct usb_interface *iface) 52static int eucr_resume(struct usb_interface *iface)
60{ 53{
@@ -64,43 +57,40 @@ static int eucr_resume(struct usb_interface *iface)
64 pr_info("--- eucr_resume---\n"); 57 pr_info("--- eucr_resume---\n");
65 mutex_lock(&us->dev_mutex); 58 mutex_lock(&us->dev_mutex);
66 59
67 //US_DEBUGP("%s\n", __func__);
68 if (us->suspend_resume_hook) 60 if (us->suspend_resume_hook)
69 (us->suspend_resume_hook)(us, US_RESUME); 61 (us->suspend_resume_hook)(us, US_RESUME);
70 62
71 63
72 mutex_unlock(&us->dev_mutex); 64 mutex_unlock(&us->dev_mutex);
73 65
74 66 us->Power_IsResum = true;
75 us->Power_IsResum = true; 67
76 // 68 us->SM_Status = *(PSM_STATUS)&tmp;
77 //us->SD_Status.Ready = 0; //?? 69
78 us->SM_Status = *(PSM_STATUS)&tmp;
79
80 return 0; 70 return 0;
81} 71}
82//EXPORT_SYMBOL_GPL(eucr_resume); 72
83static int eucr_reset_resume(struct usb_interface *iface) 73static int eucr_reset_resume(struct usb_interface *iface)
84{ 74{
85 BYTE tmp = 0; 75 BYTE tmp = 0;
86 struct us_data *us = usb_get_intfdata(iface); 76 struct us_data *us = usb_get_intfdata(iface);
87 77
88 pr_info("--- eucr_reset_resume---\n"); 78 pr_info("--- eucr_reset_resume---\n");
89 //US_DEBUGP("%s\n", __func__);
90 79
91 /* Report the reset to the SCSI core */ 80 /* Report the reset to the SCSI core */
92 usb_stor_report_bus_reset(us); 81 usb_stor_report_bus_reset(us);
93 82
94 /* FIXME: Notify the subdrivers that they need to reinitialize 83 /*
95 * the device */ 84 * FIXME: Notify the subdrivers that they need to reinitialize
96 //ENE_InitMedia(us); 85 * the device
86 */
87
97 us->Power_IsResum = true; 88 us->Power_IsResum = true;
98 // 89
99 //us->SD_Status.Ready = 0; //?? 90 us->SM_Status = *(PSM_STATUS)&tmp;
100 us->SM_Status = *(PSM_STATUS)&tmp; 91
101 return 0; 92 return 0;
102} 93}
103//EXPORT_SYMBOL_GPL(usb_stor_reset_resume);
104 94
105#else 95#else
106 96
@@ -110,7 +100,6 @@ static int eucr_reset_resume(struct usb_interface *iface)
110 100
111#endif 101#endif
112 102
113//----- eucr_pre_reset() ---------------------
114static int eucr_pre_reset(struct usb_interface *iface) 103static int eucr_pre_reset(struct usb_interface *iface)
115{ 104{
116 struct us_data *us = usb_get_intfdata(iface); 105 struct us_data *us = usb_get_intfdata(iface);
@@ -122,7 +111,6 @@ static int eucr_pre_reset(struct usb_interface *iface)
122 return 0; 111 return 0;
123} 112}
124 113
125//----- eucr_post_reset() ---------------------
126static int eucr_post_reset(struct usb_interface *iface) 114static int eucr_post_reset(struct usb_interface *iface)
127{ 115{
128 struct us_data *us = usb_get_intfdata(iface); 116 struct us_data *us = usb_get_intfdata(iface);
@@ -136,19 +124,15 @@ static int eucr_post_reset(struct usb_interface *iface)
136 return 0; 124 return 0;
137} 125}
138 126
139//----- fill_inquiry_response() ---------------------
140void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int data_len) 127void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int data_len)
141{ 128{
142 pr_info("usb --- fill_inquiry_response\n"); 129 pr_info("usb --- fill_inquiry_response\n");
143 if (data_len<36) // You lose. 130 if (data_len < 36) /* You lose. */
144 return; 131 return;
145 132
146 if (data[0]&0x20) 133 if (data[0]&0x20) {
147 {
148 memset(data+8,0,28); 134 memset(data+8,0,28);
149 } 135 } else {
150 else
151 {
152 u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice); 136 u16 bcdDevice = le16_to_cpu(us->pusb_dev->descriptor.bcdDevice);
153 memcpy(data+8, us->unusual_dev->vendorName, 137 memcpy(data+8, us->unusual_dev->vendorName,
154 strlen(us->unusual_dev->vendorName) > 8 ? 8 : 138 strlen(us->unusual_dev->vendorName) > 8 ? 8 :
@@ -164,18 +148,16 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int
164 usb_stor_set_xfer_buf(us, data, data_len, us->srb, TO_XFER_BUF); 148 usb_stor_set_xfer_buf(us, data, data_len, us->srb, TO_XFER_BUF);
165} 149}
166 150
167//----- usb_stor_control_thread() ---------------------
168static int usb_stor_control_thread(void * __us) 151static int usb_stor_control_thread(void * __us)
169{ 152{
170 struct us_data *us = (struct us_data *)__us; 153 struct us_data *us = (struct us_data *)__us;
171 struct Scsi_Host *host = us_to_host(us); 154 struct Scsi_Host *host = us_to_host(us);
172 155
173 pr_info("usb --- usb_stor_control_thread\n"); 156 pr_info("usb --- usb_stor_control_thread\n");
174 for(;;) 157 for (;;) {
175 {
176 if (wait_for_completion_interruptible(&us->cmnd_ready)) 158 if (wait_for_completion_interruptible(&us->cmnd_ready))
177 break; 159 break;
178 160
179 /* lock the device pointers */ 161 /* lock the device pointers */
180 mutex_lock(&(us->dev_mutex)); 162 mutex_lock(&(us->dev_mutex));
181 163
@@ -189,44 +171,34 @@ static int usb_stor_control_thread(void * __us)
189 scsi_lock(host); 171 scsi_lock(host);
190 172
191 /* When we are called with no command pending, we're done */ 173 /* When we are called with no command pending, we're done */
192 if (us->srb == NULL) 174 if (us->srb == NULL) {
193 {
194 scsi_unlock(host); 175 scsi_unlock(host);
195 mutex_unlock(&us->dev_mutex); 176 mutex_unlock(&us->dev_mutex);
196 //US_DEBUGP("-- exiting\n");
197 break; 177 break;
198 } 178 }
199 179
200 /* has the command timed out *already* ? */ 180 /* has the command timed out *already* ? */
201 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) 181 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
202 {
203 us->srb->result = DID_ABORT << 16; 182 us->srb->result = DID_ABORT << 16;
204 goto SkipForAbort; 183 goto SkipForAbort;
205 } 184 }
206 185
207 scsi_unlock(host); 186 scsi_unlock(host);
208 187
209 if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) 188 if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) {
210 {
211 us->srb->result = DID_ERROR << 16; 189 us->srb->result = DID_ERROR << 16;
212 } 190 } else if (us->srb->device->id
213 else if (us->srb->device->id && !(us->fflags & US_FL_SCM_MULT_TARG)) 191 && !(us->fflags & US_FL_SCM_MULT_TARG)) {
214 {
215 us->srb->result = DID_BAD_TARGET << 16; 192 us->srb->result = DID_BAD_TARGET << 16;
216 } 193 } else if (us->srb->device->lun > us->max_lun) {
217 else if (us->srb->device->lun > us->max_lun)
218 {
219 us->srb->result = DID_BAD_TARGET << 16; 194 us->srb->result = DID_BAD_TARGET << 16;
220 } 195 } else if ((us->srb->cmnd[0] == INQUIRY)
221 else if ((us->srb->cmnd[0] == INQUIRY) && (us->fflags & US_FL_FIX_INQUIRY)) 196 && (us->fflags & US_FL_FIX_INQUIRY)) {
222 {
223 unsigned char data_ptr[36] = {0x00, 0x80, 0x02, 0x02, 0x1F, 0x00, 0x00, 0x00}; 197 unsigned char data_ptr[36] = {0x00, 0x80, 0x02, 0x02, 0x1F, 0x00, 0x00, 0x00};
224 198
225 fill_inquiry_response(us, data_ptr, 36); 199 fill_inquiry_response(us, data_ptr, 36);
226 us->srb->result = SAM_STAT_GOOD; 200 us->srb->result = SAM_STAT_GOOD;
227 } 201 } else {
228 else
229 {
230 us->proto_handler(us->srb, us); 202 us->proto_handler(us->srb, us);
231 } 203 }
232 204
@@ -234,18 +206,14 @@ static int usb_stor_control_thread(void * __us)
234 scsi_lock(host); 206 scsi_lock(host);
235 207
236 /* indicate that the command is done */ 208 /* indicate that the command is done */
237 if (us->srb->result != DID_ABORT << 16) 209 if (us->srb->result != DID_ABORT << 16) {
238 {
239 us->srb->scsi_done(us->srb); 210 us->srb->scsi_done(us->srb);
240 } 211 } else {
241 else
242 {
243SkipForAbort: 212SkipForAbort:
244 pr_info("scsi command aborted\n"); 213 pr_info("scsi command aborted\n");
245 } 214 }
246 215
247 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) 216 if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) {
248 {
249 complete(&(us->notify)); 217 complete(&(us->notify));
250 218
251 /* Allow USB transfers to resume */ 219 /* Allow USB transfers to resume */
@@ -262,8 +230,7 @@ SkipForAbort:
262 } /* for (;;) */ 230 } /* for (;;) */
263 231
264 /* Wait until we are told to stop */ 232 /* Wait until we are told to stop */
265 for (;;) 233 for (;;) {
266 {
267 set_current_state(TASK_INTERRUPTIBLE); 234 set_current_state(TASK_INTERRUPTIBLE);
268 if (kthread_should_stop()) 235 if (kthread_should_stop())
269 break; 236 break;
@@ -271,9 +238,8 @@ SkipForAbort:
271 } 238 }
272 __set_current_state(TASK_RUNNING); 239 __set_current_state(TASK_RUNNING);
273 return 0; 240 return 0;
274} 241}
275 242
276//----- associate_dev() ---------------------
277static int associate_dev(struct us_data *us, struct usb_interface *intf) 243static int associate_dev(struct us_data *us, struct usb_interface *intf)
278{ 244{
279 pr_info("usb --- associate_dev\n"); 245 pr_info("usb --- associate_dev\n");
@@ -288,29 +254,24 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf)
288 254
289 /* Allocate the device-related DMA-mapped buffers */ 255 /* Allocate the device-related DMA-mapped buffers */
290 us->cr = usb_alloc_coherent(us->pusb_dev, sizeof(*us->cr), GFP_KERNEL, &us->cr_dma); 256 us->cr = usb_alloc_coherent(us->pusb_dev, sizeof(*us->cr), GFP_KERNEL, &us->cr_dma);
291 if (!us->cr) 257 if (!us->cr) {
292 {
293 pr_info("usb_ctrlrequest allocation failed\n"); 258 pr_info("usb_ctrlrequest allocation failed\n");
294 return -ENOMEM; 259 return -ENOMEM;
295 } 260 }
296 261
297 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, GFP_KERNEL, &us->iobuf_dma); 262 us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, GFP_KERNEL, &us->iobuf_dma);
298 if (!us->iobuf) 263 if (!us->iobuf) {
299 {
300 pr_info("I/O buffer allocation failed\n"); 264 pr_info("I/O buffer allocation failed\n");
301 return -ENOMEM; 265 return -ENOMEM;
302 } 266 }
303 267
304 us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL); 268 us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL);
305 if (!us->sensebuf) 269 if (!us->sensebuf)
306 {
307 pr_info("Sense buffer allocation failed\n");
308 return -ENOMEM; 270 return -ENOMEM;
309 } 271
310 return 0; 272 return 0;
311} 273}
312 274
313//----- get_device_info() ---------------------
314static int get_device_info(struct us_data *us, const struct usb_device_id *id) 275static int get_device_info(struct us_data *us, const struct usb_device_id *id)
315{ 276{
316 struct usb_device *dev = us->pusb_dev; 277 struct usb_device *dev = us->pusb_dev;
@@ -323,8 +284,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
323 us->fflags = id->driver_info; 284 us->fflags = id->driver_info;
324 us->Power_IsResum = false; 285 us->Power_IsResum = false;
325 286
326 if (us->fflags & US_FL_IGNORE_DEVICE) 287 if (us->fflags & US_FL_IGNORE_DEVICE) {
327 {
328 pr_info("device ignored\n"); 288 pr_info("device ignored\n");
329 return -ENODEV; 289 return -ENODEV;
330 } 290 }
@@ -335,7 +295,6 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
335 return 0; 295 return 0;
336} 296}
337 297
338//----- get_transport() ---------------------
339static int get_transport(struct us_data *us) 298static int get_transport(struct us_data *us)
340{ 299{
341 pr_info("usb --- get_transport\n"); 300 pr_info("usb --- get_transport\n");
@@ -349,7 +308,6 @@ static int get_transport(struct us_data *us)
349 default: 308 default:
350 return -EIO; 309 return -EIO;
351 } 310 }
352 /* pr_info("Transport: %s\n", us->transport_name); */
353 311
354 /* fix for single-lun devices */ 312 /* fix for single-lun devices */
355 if (us->fflags & US_FL_SINGLE_LUN) 313 if (us->fflags & US_FL_SINGLE_LUN)
@@ -357,7 +315,6 @@ static int get_transport(struct us_data *us)
357 return 0; 315 return 0;
358} 316}
359 317
360//----- get_protocol() ---------------------
361static int get_protocol(struct us_data *us) 318static int get_protocol(struct us_data *us)
362{ 319{
363 pr_info("usb --- get_protocol\n"); 320 pr_info("usb --- get_protocol\n");
@@ -368,7 +325,8 @@ static int get_protocol(struct us_data *us)
368 switch (us->subclass) { 325 switch (us->subclass) {
369 case USB_SC_SCSI: 326 case USB_SC_SCSI:
370 us->protocol_name = "Transparent SCSI"; 327 us->protocol_name = "Transparent SCSI";
371 if( (us->pusb_dev->descriptor.idVendor == 0x0CF2) && (us->pusb_dev->descriptor.idProduct == 0x6250) ) 328 if ((us->pusb_dev->descriptor.idVendor == 0x0CF2)
329 && (us->pusb_dev->descriptor.idProduct == 0x6250))
372 us->proto_handler = ENE_stor_invoke_transport; 330 us->proto_handler = ENE_stor_invoke_transport;
373 else 331 else
374 us->proto_handler = usb_stor_invoke_transport; 332 us->proto_handler = usb_stor_invoke_transport;
@@ -377,11 +335,9 @@ static int get_protocol(struct us_data *us)
377 default: 335 default:
378 return -EIO; 336 return -EIO;
379 } 337 }
380 /* pr_info("Protocol: %s\n", us->protocol_name); */
381 return 0; 338 return 0;
382} 339}
383 340
384//----- get_pipes() ---------------------
385static int get_pipes(struct us_data *us) 341static int get_pipes(struct us_data *us)
386{ 342{
387 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; 343 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting;
@@ -393,32 +349,24 @@ static int get_pipes(struct us_data *us)
393 349
394 pr_info("usb --- get_pipes\n"); 350 pr_info("usb --- get_pipes\n");
395 351
396 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) 352 for (i = 0; i < altsetting->desc.bNumEndpoints; i++) {
397 {
398 ep = &altsetting->endpoint[i].desc; 353 ep = &altsetting->endpoint[i].desc;
399 354
400 if (usb_endpoint_xfer_bulk(ep)) 355 if (usb_endpoint_xfer_bulk(ep)) {
401 { 356 if (usb_endpoint_dir_in(ep)) {
402 if (usb_endpoint_dir_in(ep))
403 {
404 if (!ep_in) 357 if (!ep_in)
405 ep_in = ep; 358 ep_in = ep;
406 } 359 } else {
407 else
408 {
409 if (!ep_out) 360 if (!ep_out)
410 ep_out = ep; 361 ep_out = ep;
411 } 362 }
412 } 363 } else if (usb_endpoint_is_int_in(ep)) {
413 else if (usb_endpoint_is_int_in(ep))
414 {
415 if (!ep_int) 364 if (!ep_int)
416 ep_int = ep; 365 ep_int = ep;
417 } 366 }
418 } 367 }
419 368
420 if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) 369 if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) {
421 {
422 pr_info("Endpoint sanity check failed! Rejecting dev.\n"); 370 pr_info("Endpoint sanity check failed! Rejecting dev.\n");
423 return -EIO; 371 return -EIO;
424 } 372 }
@@ -428,31 +376,27 @@ static int get_pipes(struct us_data *us)
428 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0); 376 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0);
429 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 377 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
430 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 378 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
431 if (ep_int) 379 if (ep_int) {
432 {
433 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, ep_int->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 380 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, ep_int->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
434 us->ep_bInterval = ep_int->bInterval; 381 us->ep_bInterval = ep_int->bInterval;
435 } 382 }
436 return 0; 383 return 0;
437} 384}
438 385
439//----- usb_stor_acquire_resources() ---------------------
440static int usb_stor_acquire_resources(struct us_data *us) 386static int usb_stor_acquire_resources(struct us_data *us)
441{ 387{
442 struct task_struct *th; 388 struct task_struct *th;
443 389
444 pr_info("usb --- usb_stor_acquire_resources\n"); 390 pr_info("usb --- usb_stor_acquire_resources\n");
445 us->current_urb = usb_alloc_urb(0, GFP_KERNEL); 391 us->current_urb = usb_alloc_urb(0, GFP_KERNEL);
446 if (!us->current_urb) 392 if (!us->current_urb) {
447 {
448 pr_info("URB allocation failed\n"); 393 pr_info("URB allocation failed\n");
449 return -ENOMEM; 394 return -ENOMEM;
450 } 395 }
451 396
452 /* Start up our control thread */ 397 /* Start up our control thread */
453 th = kthread_run(usb_stor_control_thread, us, "eucr-storage"); 398 th = kthread_run(usb_stor_control_thread, us, "eucr-storage");
454 if (IS_ERR(th)) 399 if (IS_ERR(th)) {
455 {
456 pr_info("Unable to start control thread\n"); 400 pr_info("Unable to start control thread\n");
457 return PTR_ERR(th); 401 return PTR_ERR(th);
458 } 402 }
@@ -461,7 +405,6 @@ static int usb_stor_acquire_resources(struct us_data *us)
461 return 0; 405 return 0;
462} 406}
463 407
464//----- usb_stor_release_resources() ---------------------
465static void usb_stor_release_resources(struct us_data *us) 408static void usb_stor_release_resources(struct us_data *us)
466{ 409{
467 pr_info("usb --- usb_stor_release_resources\n"); 410 pr_info("usb --- usb_stor_release_resources\n");
@@ -473,8 +416,7 @@ static void usb_stor_release_resources(struct us_data *us)
473 kthread_stop(us->ctl_thread); 416 kthread_stop(us->ctl_thread);
474 417
475 /* Call the destructor routine, if it exists */ 418 /* Call the destructor routine, if it exists */
476 if (us->extra_destructor) 419 if (us->extra_destructor) {
477 {
478 pr_info("-- calling extra_destructor()\n"); 420 pr_info("-- calling extra_destructor()\n");
479 us->extra_destructor(us->extra); 421 us->extra_destructor(us->extra);
480 } 422 }
@@ -484,7 +426,6 @@ static void usb_stor_release_resources(struct us_data *us)
484 usb_free_urb(us->current_urb); 426 usb_free_urb(us->current_urb);
485} 427}
486 428
487//----- dissociate_dev() ---------------------
488static void dissociate_dev(struct us_data *us) 429static void dissociate_dev(struct us_data *us)
489{ 430{
490 pr_info("usb --- dissociate_dev\n"); 431 pr_info("usb --- dissociate_dev\n");
@@ -501,7 +442,6 @@ static void dissociate_dev(struct us_data *us)
501 usb_set_intfdata(us->pusb_intf, NULL); 442 usb_set_intfdata(us->pusb_intf, NULL);
502} 443}
503 444
504//----- quiesce_and_remove_host() ---------------------
505static void quiesce_and_remove_host(struct us_data *us) 445static void quiesce_and_remove_host(struct us_data *us)
506{ 446{
507 struct Scsi_Host *host = us_to_host(us); 447 struct Scsi_Host *host = us_to_host(us);
@@ -512,19 +452,22 @@ static void quiesce_and_remove_host(struct us_data *us)
512 if (us->pusb_dev->state == USB_STATE_NOTATTACHED) 452 if (us->pusb_dev->state == USB_STATE_NOTATTACHED)
513 set_bit(US_FLIDX_DISCONNECTING, &us->dflags); 453 set_bit(US_FLIDX_DISCONNECTING, &us->dflags);
514 454
515 /* Prevent SCSI-scanning (if it hasn't started yet) 455 /*
456 * Prevent SCSI-scanning (if it hasn't started yet)
516 * and wait for the SCSI-scanning thread to stop. 457 * and wait for the SCSI-scanning thread to stop.
517 */ 458 */
518 set_bit(US_FLIDX_DONT_SCAN, &us->dflags); 459 set_bit(US_FLIDX_DONT_SCAN, &us->dflags);
519 wake_up(&us->delay_wait); 460 wake_up(&us->delay_wait);
520 wait_for_completion(&us->scanning_done); 461 wait_for_completion(&us->scanning_done);
521 462
522 /* Removing the host will perform an orderly shutdown: caches 463 /*
464 * Removing the host will perform an orderly shutdown: caches
523 * synchronized, disks spun down, etc. 465 * synchronized, disks spun down, etc.
524 */ 466 */
525 scsi_remove_host(host); 467 scsi_remove_host(host);
526 468
527 /* Prevent any new commands from being accepted and cut short 469 /*
470 * Prevent any new commands from being accepted and cut short
528 * reset delays. 471 * reset delays.
529 */ 472 */
530 scsi_lock(host); 473 scsi_lock(host);
@@ -533,7 +476,6 @@ static void quiesce_and_remove_host(struct us_data *us)
533 wake_up(&us->delay_wait); 476 wake_up(&us->delay_wait);
534} 477}
535 478
536//----- release_everything() ---------------------
537static void release_everything(struct us_data *us) 479static void release_everything(struct us_data *us)
538{ 480{
539 pr_info("usb --- release_everything\n"); 481 pr_info("usb --- release_everything\n");
@@ -543,7 +485,6 @@ static void release_everything(struct us_data *us)
543 scsi_host_put(us_to_host(us)); 485 scsi_host_put(us_to_host(us));
544} 486}
545 487
546//----- usb_stor_scan_thread() ---------------------
547static int usb_stor_scan_thread(void * __us) 488static int usb_stor_scan_thread(void * __us)
548{ 489{
549 struct us_data *us = (struct us_data *)__us; 490 struct us_data *us = (struct us_data *)__us;
@@ -560,11 +501,10 @@ static int usb_stor_scan_thread(void * __us)
560 } 501 }
561 502
562 /* If the device is still connected, perform the scanning */ 503 /* If the device is still connected, perform the scanning */
563 if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) 504 if (!test_bit(US_FLIDX_DONT_SCAN, &us->dflags)) {
564 {
565 /* For bulk-only devices, determine the max LUN value */ 505 /* For bulk-only devices, determine the max LUN value */
566 if (us->protocol == USB_PR_BULK && !(us->fflags & US_FL_SINGLE_LUN)) 506 if (us->protocol == USB_PR_BULK
567 { 507 && !(us->fflags & US_FL_SINGLE_LUN)) {
568 mutex_lock(&us->dev_mutex); 508 mutex_lock(&us->dev_mutex);
569 us->max_lun = usb_stor_Bulk_max_lun(us); 509 us->max_lun = usb_stor_Bulk_max_lun(us);
570 mutex_unlock(&us->dev_mutex); 510 mutex_unlock(&us->dev_mutex);
@@ -575,7 +515,6 @@ static int usb_stor_scan_thread(void * __us)
575 complete_and_exit(&us->scanning_done, 0); 515 complete_and_exit(&us->scanning_done, 0);
576} 516}
577 517
578//----- eucr_probe() ---------------------
579static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id) 518static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id)
580{ 519{
581 struct Scsi_Host *host; 520 struct Scsi_Host *host;
@@ -587,8 +526,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id
587 pr_info("usb --- eucr_probe\n"); 526 pr_info("usb --- eucr_probe\n");
588 527
589 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); 528 host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us));
590 if (!host) 529 if (!host) {
591 {
592 pr_info("Unable to allocate the scsi host\n"); 530 pr_info("Unable to allocate the scsi host\n");
593 return -ENOMEM; 531 return -ENOMEM;
594 } 532 }
@@ -630,8 +568,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id
630 goto BadDevice; 568 goto BadDevice;
631 569
632 result = scsi_add_host(host, &intf->dev); 570 result = scsi_add_host(host, &intf->dev);
633 if (result) 571 if (result) {
634 {
635 pr_info("Unable to add the scsi host\n"); 572 pr_info("Unable to add the scsi host\n");
636 goto BadDevice; 573 goto BadDevice;
637 } 574 }
@@ -673,7 +610,6 @@ BadDevice:
673 return result; 610 return result;
674} 611}
675 612
676//----- eucr_disconnect() ---------------------
677static void eucr_disconnect(struct usb_interface *intf) 613static void eucr_disconnect(struct usb_interface *intf)
678{ 614{
679 struct us_data *us = usb_get_intfdata(intf); 615 struct us_data *us = usb_get_intfdata(intf);
@@ -683,11 +619,7 @@ static void eucr_disconnect(struct usb_interface *intf)
683 release_everything(us); 619 release_everything(us);
684} 620}
685 621
686/*********************************************************************** 622/* Initialization and registration */
687 * Initialization and registration
688 ***********************************************************************/
689
690//----- usb_storage_driver() ---------------------
691static struct usb_driver usb_storage_driver = { 623static struct usb_driver usb_storage_driver = {
692 .name = "eucr", 624 .name = "eucr",
693 .probe = eucr_probe, 625 .probe = eucr_probe,
diff --git a/drivers/staging/line6/Kconfig b/drivers/staging/line6/Kconfig
index b63543658b2e..4f1219b4c692 100644
--- a/drivers/staging/line6/Kconfig
+++ b/drivers/staging/line6/Kconfig
@@ -23,16 +23,6 @@ menuconfig LINE6_USB
23 23
24if LINE6_USB 24if LINE6_USB
25 25
26config LINE6_USB_DUMP_PCM
27 bool "dump PCM data"
28 default n
29 help
30 Say Y here to write PCM data sent to and received from Line6
31 devices to the syslog. This will produce a huge amount of
32 syslog data during playback and capture.
33
34 If unsure, say N.
35
36config LINE6_USB_IMPULSE_RESPONSE 26config LINE6_USB_IMPULSE_RESPONSE
37 bool "measure impulse response" 27 bool "measure impulse response"
38 default n 28 default n
diff --git a/drivers/staging/line6/capture.c b/drivers/staging/line6/capture.c
index 389c41fd1b74..f8316b71f13d 100644
--- a/drivers/staging/line6/capture.c
+++ b/drivers/staging/line6/capture.c
@@ -216,16 +216,6 @@ static void audio_in_callback(struct urb *urb)
216 if (urb == line6pcm->urb_audio_in[index]) 216 if (urb == line6pcm->urb_audio_in[index])
217 break; 217 break;
218 218
219#ifdef CONFIG_LINE6_USB_DUMP_PCM
220 for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
221 struct usb_iso_packet_descriptor *fout =
222 &urb->iso_frame_desc[i];
223 line6_write_hexdump(line6pcm->line6, 'C',
224 urb->transfer_buffer + fout->offset,
225 fout->length);
226 }
227#endif
228
229 spin_lock_irqsave(&line6pcm->lock_audio_in, flags); 219 spin_lock_irqsave(&line6pcm->lock_audio_in, flags);
230 220
231 for (i = 0; i < LINE6_ISO_PACKETS; ++i) { 221 for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
index 1e4ce50069a9..6252aca82866 100644
--- a/drivers/staging/line6/driver.c
+++ b/drivers/staging/line6/driver.c
@@ -135,47 +135,6 @@ static void line6_stop_listen(struct usb_line6 *line6)
135 usb_kill_urb(line6->urb_listen); 135 usb_kill_urb(line6->urb_listen);
136} 136}
137 137
138#ifdef CONFIG_LINE6_USB_DUMP_ANY
139/*
140 Write hexdump to syslog.
141*/
142void line6_write_hexdump(struct usb_line6 *line6, char dir,
143 const unsigned char *buffer, int size)
144{
145 static const int BYTES_PER_LINE = 8;
146 char hexdump[100];
147 char asc[BYTES_PER_LINE + 1];
148 int i, j;
149
150 for (i = 0; i < size; i += BYTES_PER_LINE) {
151 int hexdumpsize = sizeof(hexdump);
152 char *p = hexdump;
153 int n = min(size - i, BYTES_PER_LINE);
154 asc[n] = 0;
155
156 for (j = 0; j < BYTES_PER_LINE; ++j) {
157 int bytes;
158
159 if (j < n) {
160 unsigned char val = buffer[i + j];
161 bytes = snprintf(p, hexdumpsize, " %02X", val);
162 asc[j] = ((val >= 0x20)
163 && (val < 0x7f)) ? val : '.';
164 } else
165 bytes = snprintf(p, hexdumpsize, " ");
166
167 if (bytes > hexdumpsize)
168 break; /* buffer overflow */
169
170 p += bytes;
171 hexdumpsize -= bytes;
172 }
173
174 dev_info(line6->ifcdev, "%c%04X:%s %s\n", dir, i, hexdump, asc);
175 }
176}
177#endif
178
179/* 138/*
180 Send raw message in pieces of wMaxPacketSize bytes. 139 Send raw message in pieces of wMaxPacketSize bytes.
181*/ 140*/
@@ -274,11 +233,8 @@ int line6_send_raw_message_async(struct usb_line6 *line6, const char *buffer,
274 233
275 /* create message: */ 234 /* create message: */
276 msg = kmalloc(sizeof(struct message), GFP_ATOMIC); 235 msg = kmalloc(sizeof(struct message), GFP_ATOMIC);
277 236 if (msg == NULL)
278 if (msg == NULL) {
279 dev_err(line6->ifcdev, "Out of memory\n");
280 return -ENOMEM; 237 return -ENOMEM;
281 }
282 238
283 /* create URB: */ 239 /* create URB: */
284 urb = usb_alloc_urb(0, GFP_ATOMIC); 240 urb = usb_alloc_urb(0, GFP_ATOMIC);
@@ -307,14 +263,13 @@ int line6_version_request_async(struct usb_line6 *line6)
307 char *buffer; 263 char *buffer;
308 int retval; 264 int retval;
309 265
310 buffer = kmalloc(sizeof(line6_request_version), GFP_ATOMIC); 266 buffer = kmemdup(line6_request_version,
267 sizeof(line6_request_version), GFP_ATOMIC);
311 if (buffer == NULL) { 268 if (buffer == NULL) {
312 dev_err(line6->ifcdev, "Out of memory"); 269 dev_err(line6->ifcdev, "Out of memory");
313 return -ENOMEM; 270 return -ENOMEM;
314 } 271 }
315 272
316 memcpy(buffer, line6_request_version, sizeof(line6_request_version));
317
318 retval = line6_send_raw_message_async(line6, buffer, 273 retval = line6_send_raw_message_async(line6, buffer,
319 sizeof(line6_request_version)); 274 sizeof(line6_request_version));
320 kfree(buffer); 275 kfree(buffer);
@@ -333,17 +288,6 @@ int line6_send_sysex_message(struct usb_line6 *line6, const char *buffer,
333} 288}
334 289
335/* 290/*
336 Send sysex message in pieces of wMaxPacketSize bytes.
337*/
338int line6_send_sysex_message_async(struct usb_line6 *line6, const char *buffer,
339 int size)
340{
341 return line6_send_raw_message_async(line6, buffer,
342 size + SYSEX_EXTRA_SIZE) -
343 SYSEX_EXTRA_SIZE;
344}
345
346/*
347 Allocate buffer for sysex message and prepare header. 291 Allocate buffer for sysex message and prepare header.
348 @param code sysex message code 292 @param code sysex message code
349 @param size number of bytes between code and sysex end 293 @param size number of bytes between code and sysex end
@@ -353,10 +297,8 @@ char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
353{ 297{
354 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC); 298 char *buffer = kmalloc(size + SYSEX_EXTRA_SIZE, GFP_ATOMIC);
355 299
356 if (!buffer) { 300 if (!buffer)
357 dev_err(line6->ifcdev, "out of memory\n");
358 return NULL; 301 return NULL;
359 }
360 302
361 buffer[0] = LINE6_SYSEX_BEGIN; 303 buffer[0] = LINE6_SYSEX_BEGIN;
362 memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id)); 304 memcpy(buffer + 1, line6_midi_id, sizeof(line6_midi_id));
@@ -372,7 +314,7 @@ char *line6_alloc_sysex_buffer(struct usb_line6 *line6, int code1, int code2,
372static void line6_data_received(struct urb *urb) 314static void line6_data_received(struct urb *urb)
373{ 315{
374 struct usb_line6 *line6 = (struct usb_line6 *)urb->context; 316 struct usb_line6 *line6 = (struct usb_line6 *)urb->context;
375 struct MidiBuffer *mb = &line6->line6midi->midibuf_in; 317 struct midi_buffer *mb = &line6->line6midi->midibuf_in;
376 int done; 318 int done;
377 319
378 if (urb->status == -ESHUTDOWN) 320 if (urb->status == -ESHUTDOWN)
@@ -456,11 +398,8 @@ int line6_send_program(struct usb_line6 *line6, u8 value)
456 int partial; 398 int partial;
457 399
458 buffer = kmalloc(2, GFP_KERNEL); 400 buffer = kmalloc(2, GFP_KERNEL);
459 401 if (!buffer)
460 if (!buffer) {
461 dev_err(line6->ifcdev, "out of memory\n");
462 return -ENOMEM; 402 return -ENOMEM;
463 }
464 403
465 buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST; 404 buffer[0] = LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST;
466 buffer[1] = value; 405 buffer[1] = value;
@@ -488,11 +427,8 @@ int line6_transmit_parameter(struct usb_line6 *line6, int param, u8 value)
488 int partial; 427 int partial;
489 428
490 buffer = kmalloc(3, GFP_KERNEL); 429 buffer = kmalloc(3, GFP_KERNEL);
491 430 if (!buffer)
492 if (!buffer) {
493 dev_err(line6->ifcdev, "out of memory\n");
494 return -ENOMEM; 431 return -ENOMEM;
495 }
496 432
497 buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST; 433 buffer[0] = LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST;
498 buffer[1] = param; 434 buffer[1] = param;
@@ -532,7 +468,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
532 return ret; 468 return ret;
533 } 469 }
534 470
535 /* Wait for data length. We'll get a couple of 0xff until length arrives. */ 471 /* Wait for data length. We'll get 0xff until length arrives. */
536 do { 472 do {
537 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67, 473 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
538 USB_TYPE_VENDOR | USB_RECIP_DEVICE | 474 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
@@ -887,9 +823,7 @@ static int line6_probe(struct usb_interface *interface,
887 } 823 }
888 824
889 line6 = kzalloc(size, GFP_KERNEL); 825 line6 = kzalloc(size, GFP_KERNEL);
890
891 if (line6 == NULL) { 826 if (line6 == NULL) {
892 dev_err(&interface->dev, "Out of memory\n");
893 ret = -ENODEV; 827 ret = -ENODEV;
894 goto err_put; 828 goto err_put;
895 } 829 }
@@ -928,18 +862,14 @@ static int line6_probe(struct usb_interface *interface,
928 /* initialize USB buffers: */ 862 /* initialize USB buffers: */
929 line6->buffer_listen = 863 line6->buffer_listen =
930 kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL); 864 kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
931
932 if (line6->buffer_listen == NULL) { 865 if (line6->buffer_listen == NULL) {
933 dev_err(&interface->dev, "Out of memory\n");
934 ret = -ENOMEM; 866 ret = -ENOMEM;
935 goto err_destruct; 867 goto err_destruct;
936 } 868 }
937 869
938 line6->buffer_message = 870 line6->buffer_message =
939 kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL); 871 kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
940
941 if (line6->buffer_message == NULL) { 872 if (line6->buffer_message == NULL) {
942 dev_err(&interface->dev, "Out of memory\n");
943 ret = -ENOMEM; 873 ret = -ENOMEM;
944 goto err_destruct; 874 goto err_destruct;
945 } 875 }
diff --git a/drivers/staging/line6/driver.h b/drivers/staging/line6/driver.h
index f0be5a2adaba..a8341f9fdb98 100644
--- a/drivers/staging/line6/driver.h
+++ b/drivers/staging/line6/driver.h
@@ -20,10 +20,6 @@
20 20
21#define DRIVER_NAME "line6usb" 21#define DRIVER_NAME "line6usb"
22 22
23#if defined(CONFIG_LINE6_USB_DUMP_PCM)
24#define CONFIG_LINE6_USB_DUMP_ANY
25#endif
26
27#define LINE6_TIMEOUT 1 23#define LINE6_TIMEOUT 1
28#define LINE6_BUFSIZE_LISTEN 32 24#define LINE6_BUFSIZE_LISTEN 32
29#define LINE6_MESSAGE_MAXLEN 256 25#define LINE6_MESSAGE_MAXLEN 256
@@ -53,7 +49,7 @@
53#define LINE6_CHANNEL_MASK 0x0f 49#define LINE6_CHANNEL_MASK 0x0f
54 50
55#define MISSING_CASE \ 51#define MISSING_CASE \
56 printk(KERN_ERR "line6usb driver bug: missing case in %s:%d\n", \ 52 pr_err("line6usb driver bug: missing case in %s:%d\n", \
57 __FILE__, __LINE__) 53 __FILE__, __LINE__)
58 54
59#define CHECK_RETURN(x) \ 55#define CHECK_RETURN(x) \
@@ -208,8 +204,6 @@ extern int line6_send_raw_message_async(struct usb_line6 *line6,
208 const char *buffer, int size); 204 const char *buffer, int size);
209extern int line6_send_sysex_message(struct usb_line6 *line6, 205extern int line6_send_sysex_message(struct usb_line6 *line6,
210 const char *buffer, int size); 206 const char *buffer, int size);
211extern int line6_send_sysex_message_async(struct usb_line6 *line6,
212 const char *buffer, int size);
213extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr, 207extern ssize_t line6_set_raw(struct device *dev, struct device_attribute *attr,
214 const char *buf, size_t count); 208 const char *buf, size_t count);
215extern void line6_start_timer(struct timer_list *timer, unsigned int msecs, 209extern void line6_start_timer(struct timer_list *timer, unsigned int msecs,
@@ -221,9 +215,4 @@ extern int line6_version_request_async(struct usb_line6 *line6);
221extern int line6_write_data(struct usb_line6 *line6, int address, void *data, 215extern int line6_write_data(struct usb_line6 *line6, int address, void *data,
222 size_t datalen); 216 size_t datalen);
223 217
224#ifdef CONFIG_LINE6_USB_DUMP_ANY
225extern void line6_write_hexdump(struct usb_line6 *line6, char dir,
226 const unsigned char *buffer, int size);
227#endif
228
229#endif 218#endif
diff --git a/drivers/staging/line6/midi.c b/drivers/staging/line6/midi.c
index 6982eca661bd..e3f9a53dbd96 100644
--- a/drivers/staging/line6/midi.c
+++ b/drivers/staging/line6/midi.c
@@ -45,7 +45,7 @@ static void line6_midi_transmit(struct snd_rawmidi_substream *substream)
45 struct usb_line6 *line6 = 45 struct usb_line6 *line6 =
46 line6_rawmidi_substream_midi(substream)->line6; 46 line6_rawmidi_substream_midi(substream)->line6;
47 struct snd_line6_midi *line6midi = line6->line6midi; 47 struct snd_line6_midi *line6midi = line6->line6midi;
48 struct MidiBuffer *mb = &line6midi->midibuf_out; 48 struct midi_buffer *mb = &line6midi->midibuf_out;
49 unsigned long flags; 49 unsigned long flags;
50 unsigned char chunk[line6->max_packet_size]; 50 unsigned char chunk[line6->max_packet_size];
51 int req, done; 51 int req, done;
diff --git a/drivers/staging/line6/midi.h b/drivers/staging/line6/midi.h
index 19dabd54051a..78f903fb4d41 100644
--- a/drivers/staging/line6/midi.h
+++ b/drivers/staging/line6/midi.h
@@ -57,12 +57,12 @@ struct snd_line6_midi {
57 /** 57 /**
58 Buffer for incoming MIDI stream. 58 Buffer for incoming MIDI stream.
59 */ 59 */
60 struct MidiBuffer midibuf_in; 60 struct midi_buffer midibuf_in;
61 61
62 /** 62 /**
63 Buffer for outgoing MIDI stream. 63 Buffer for outgoing MIDI stream.
64 */ 64 */
65 struct MidiBuffer midibuf_out; 65 struct midi_buffer midibuf_out;
66}; 66};
67 67
68extern int line6_init_midi(struct usb_line6 *line6); 68extern int line6_init_midi(struct usb_line6 *line6);
diff --git a/drivers/staging/line6/midibuf.c b/drivers/staging/line6/midibuf.c
index 968e0de83dab..f0adb7baa603 100644
--- a/drivers/staging/line6/midibuf.c
+++ b/drivers/staging/line6/midibuf.c
@@ -33,23 +33,23 @@ static int midibuf_message_length(unsigned char code)
33 } 33 }
34} 34}
35 35
36static int midibuf_is_empty(struct MidiBuffer *this) 36static int midibuf_is_empty(struct midi_buffer *this)
37{ 37{
38 return (this->pos_read == this->pos_write) && !this->full; 38 return (this->pos_read == this->pos_write) && !this->full;
39} 39}
40 40
41static int midibuf_is_full(struct MidiBuffer *this) 41static int midibuf_is_full(struct midi_buffer *this)
42{ 42{
43 return this->full; 43 return this->full;
44} 44}
45 45
46void line6_midibuf_reset(struct MidiBuffer *this) 46void line6_midibuf_reset(struct midi_buffer *this)
47{ 47{
48 this->pos_read = this->pos_write = this->full = 0; 48 this->pos_read = this->pos_write = this->full = 0;
49 this->command_prev = -1; 49 this->command_prev = -1;
50} 50}
51 51
52int line6_midibuf_init(struct MidiBuffer *this, int size, int split) 52int line6_midibuf_init(struct midi_buffer *this, int size, int split)
53{ 53{
54 this->buf = kmalloc(size, GFP_KERNEL); 54 this->buf = kmalloc(size, GFP_KERNEL);
55 55
@@ -62,14 +62,14 @@ int line6_midibuf_init(struct MidiBuffer *this, int size, int split)
62 return 0; 62 return 0;
63} 63}
64 64
65void line6_midibuf_status(struct MidiBuffer *this) 65void line6_midibuf_status(struct midi_buffer *this)
66{ 66{
67 pr_debug("midibuf size=%d split=%d pos_read=%d pos_write=%d full=%d command_prev=%02x\n", 67 pr_debug("midibuf size=%d split=%d pos_read=%d pos_write=%d full=%d command_prev=%02x\n",
68 this->size, this->split, this->pos_read, this->pos_write, 68 this->size, this->split, this->pos_read, this->pos_write,
69 this->full, this->command_prev); 69 this->full, this->command_prev);
70} 70}
71 71
72int line6_midibuf_bytes_free(struct MidiBuffer *this) 72int line6_midibuf_bytes_free(struct midi_buffer *this)
73{ 73{
74 return 74 return
75 midibuf_is_full(this) ? 75 midibuf_is_full(this) ?
@@ -78,7 +78,7 @@ int line6_midibuf_bytes_free(struct MidiBuffer *this)
78 1; 78 1;
79} 79}
80 80
81int line6_midibuf_bytes_used(struct MidiBuffer *this) 81int line6_midibuf_bytes_used(struct midi_buffer *this)
82{ 82{
83 return 83 return
84 midibuf_is_empty(this) ? 84 midibuf_is_empty(this) ?
@@ -87,7 +87,7 @@ int line6_midibuf_bytes_used(struct MidiBuffer *this)
87 1; 87 1;
88} 88}
89 89
90int line6_midibuf_write(struct MidiBuffer *this, unsigned char *data, 90int line6_midibuf_write(struct midi_buffer *this, unsigned char *data,
91 int length) 91 int length)
92{ 92{
93 int bytes_free; 93 int bytes_free;
@@ -130,7 +130,8 @@ int line6_midibuf_write(struct MidiBuffer *this, unsigned char *data,
130 return length + skip_active_sense; 130 return length + skip_active_sense;
131} 131}
132 132
133int line6_midibuf_read(struct MidiBuffer *this, unsigned char *data, int length) 133int line6_midibuf_read(struct midi_buffer *this, unsigned char *data,
134 int length)
134{ 135{
135 int bytes_used; 136 int bytes_used;
136 int length1, length2; 137 int length1, length2;
@@ -234,7 +235,7 @@ int line6_midibuf_read(struct MidiBuffer *this, unsigned char *data, int length)
234 return length + repeat; 235 return length + repeat;
235} 236}
236 237
237int line6_midibuf_ignore(struct MidiBuffer *this, int length) 238int line6_midibuf_ignore(struct midi_buffer *this, int length)
238{ 239{
239 int bytes_used = line6_midibuf_bytes_used(this); 240 int bytes_used = line6_midibuf_bytes_used(this);
240 241
@@ -246,7 +247,7 @@ int line6_midibuf_ignore(struct MidiBuffer *this, int length)
246 return length; 247 return length;
247} 248}
248 249
249int line6_midibuf_skip_message(struct MidiBuffer *this, unsigned short mask) 250int line6_midibuf_skip_message(struct midi_buffer *this, unsigned short mask)
250{ 251{
251 int cmd = this->command_prev; 252 int cmd = this->command_prev;
252 253
@@ -257,7 +258,7 @@ int line6_midibuf_skip_message(struct MidiBuffer *this, unsigned short mask)
257 return 0; 258 return 0;
258} 259}
259 260
260void line6_midibuf_destroy(struct MidiBuffer *this) 261void line6_midibuf_destroy(struct midi_buffer *this)
261{ 262{
262 kfree(this->buf); 263 kfree(this->buf);
263 this->buf = NULL; 264 this->buf = NULL;
diff --git a/drivers/staging/line6/midibuf.h b/drivers/staging/line6/midibuf.h
index 444cb3a12d72..707482b940e4 100644
--- a/drivers/staging/line6/midibuf.h
+++ b/drivers/staging/line6/midibuf.h
@@ -12,7 +12,7 @@
12#ifndef MIDIBUF_H 12#ifndef MIDIBUF_H
13#define MIDIBUF_H 13#define MIDIBUF_H
14 14
15struct MidiBuffer { 15struct midi_buffer {
16 unsigned char *buf; 16 unsigned char *buf;
17 int size; 17 int size;
18 int split; 18 int split;
@@ -21,18 +21,18 @@ struct MidiBuffer {
21 int command_prev; 21 int command_prev;
22}; 22};
23 23
24extern int line6_midibuf_bytes_used(struct MidiBuffer *mb); 24extern int line6_midibuf_bytes_used(struct midi_buffer *mb);
25extern int line6_midibuf_bytes_free(struct MidiBuffer *mb); 25extern int line6_midibuf_bytes_free(struct midi_buffer *mb);
26extern void line6_midibuf_destroy(struct MidiBuffer *mb); 26extern void line6_midibuf_destroy(struct midi_buffer *mb);
27extern int line6_midibuf_ignore(struct MidiBuffer *mb, int length); 27extern int line6_midibuf_ignore(struct midi_buffer *mb, int length);
28extern int line6_midibuf_init(struct MidiBuffer *mb, int size, int split); 28extern int line6_midibuf_init(struct midi_buffer *mb, int size, int split);
29extern int line6_midibuf_read(struct MidiBuffer *mb, unsigned char *data, 29extern int line6_midibuf_read(struct midi_buffer *mb, unsigned char *data,
30 int length); 30 int length);
31extern void line6_midibuf_reset(struct MidiBuffer *mb); 31extern void line6_midibuf_reset(struct midi_buffer *mb);
32extern int line6_midibuf_skip_message(struct MidiBuffer *mb, 32extern int line6_midibuf_skip_message(struct midi_buffer *mb,
33 unsigned short mask); 33 unsigned short mask);
34extern void line6_midibuf_status(struct MidiBuffer *mb); 34extern void line6_midibuf_status(struct midi_buffer *mb);
35extern int line6_midibuf_write(struct MidiBuffer *mb, unsigned char *data, 35extern int line6_midibuf_write(struct midi_buffer *mb, unsigned char *data,
36 int length); 36 int length);
37 37
38#endif 38#endif
diff --git a/drivers/staging/line6/pcm.c b/drivers/staging/line6/pcm.c
index 6c1e31335d19..02f77d74809f 100644
--- a/drivers/staging/line6/pcm.c
+++ b/drivers/staging/line6/pcm.c
@@ -49,11 +49,11 @@ static ssize_t pcm_set_impulse_volume(struct device *dev,
49{ 49{
50 struct snd_line6_pcm *line6pcm = dev2pcm(dev); 50 struct snd_line6_pcm *line6pcm = dev2pcm(dev);
51 int value; 51 int value;
52 int rv; 52 int ret;
53 53
54 rv = kstrtoint(buf, 10, &value); 54 ret = kstrtoint(buf, 10, &value);
55 if (rv < 0) 55 if (ret < 0)
56 return rv; 56 return ret;
57 57
58 line6pcm->impulse_volume = value; 58 line6pcm->impulse_volume = value;
59 59
@@ -81,7 +81,14 @@ static ssize_t pcm_set_impulse_period(struct device *dev,
81 struct device_attribute *attr, 81 struct device_attribute *attr,
82 const char *buf, size_t count) 82 const char *buf, size_t count)
83{ 83{
84 dev2pcm(dev)->impulse_period = simple_strtoul(buf, NULL, 10); 84 int value;
85 int ret;
86
87 ret = kstrtoint(buf, 10, &value);
88 if (ret < 0)
89 return ret;
90
91 dev2pcm(dev)->impulse_period = value;
85 return count; 92 return count;
86} 93}
87 94
@@ -114,10 +121,7 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
114 line6pcm->buffer_in = 121 line6pcm->buffer_in =
115 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * 122 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
116 line6pcm->max_packet_size, GFP_KERNEL); 123 line6pcm->max_packet_size, GFP_KERNEL);
117
118 if (!line6pcm->buffer_in) { 124 if (!line6pcm->buffer_in) {
119 dev_err(line6pcm->line6->ifcdev,
120 "cannot malloc capture buffer\n");
121 err = -ENOMEM; 125 err = -ENOMEM;
122 goto pcm_acquire_error; 126 goto pcm_acquire_error;
123 } 127 }
@@ -153,10 +157,7 @@ int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels)
153 line6pcm->buffer_out = 157 line6pcm->buffer_out =
154 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS * 158 kmalloc(LINE6_ISO_BUFFERS * LINE6_ISO_PACKETS *
155 line6pcm->max_packet_size, GFP_KERNEL); 159 line6pcm->max_packet_size, GFP_KERNEL);
156
157 if (!line6pcm->buffer_out) { 160 if (!line6pcm->buffer_out) {
158 dev_err(line6pcm->line6->ifcdev,
159 "cannot malloc playback buffer\n");
160 err = -ENOMEM; 161 err = -ENOMEM;
161 goto pcm_acquire_error; 162 goto pcm_acquire_error;
162 } 163 }
@@ -455,13 +456,12 @@ int line6_init_pcm(struct usb_line6 *line6,
455 ep_write = 0x01; 456 ep_write = 0x01;
456 break; 457 break;
457 458
458 /* this is for interface_number == 1: 459 /* this is for interface_number == 1:
459 case LINE6_DEVID_TONEPORT_UX2: 460 case LINE6_DEVID_TONEPORT_UX2:
460 case LINE6_DEVID_PODSTUDIO_UX2: 461 case LINE6_DEVID_PODSTUDIO_UX2:
461 ep_read = 0x87; 462 ep_read = 0x87;
462 ep_write = 0x00; 463 ep_write = 0x00;
463 break; 464 break; */
464 */
465 465
466 default: 466 default:
467 MISSING_CASE; 467 MISSING_CASE;
diff --git a/drivers/staging/line6/playback.c b/drivers/staging/line6/playback.c
index 4cf23af9c627..f9135c7cb195 100644
--- a/drivers/staging/line6/playback.c
+++ b/drivers/staging/line6/playback.c
@@ -264,15 +264,6 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm)
264 } 264 }
265#endif 265#endif
266 } 266 }
267#ifdef CONFIG_LINE6_USB_DUMP_PCM
268 for (i = 0; i < LINE6_ISO_PACKETS; ++i) {
269 struct usb_iso_packet_descriptor *fout =
270 &urb_out->iso_frame_desc[i];
271 line6_write_hexdump(line6pcm->line6, 'P',
272 urb_out->transfer_buffer + fout->offset,
273 fout->length);
274 }
275#endif
276 267
277 ret = usb_submit_urb(urb_out, GFP_ATOMIC); 268 ret = usb_submit_urb(urb_out, GFP_ATOMIC);
278 269
diff --git a/drivers/staging/line6/pod.c b/drivers/staging/line6/pod.c
index e542540d0db3..74898c3c9f90 100644
--- a/drivers/staging/line6/pod.c
+++ b/drivers/staging/line6/pod.c
@@ -34,12 +34,14 @@ enum {
34 POD_SYSEX_DUMPMEM = 0x73, 34 POD_SYSEX_DUMPMEM = 0x73,
35 POD_SYSEX_DUMP = 0x74, 35 POD_SYSEX_DUMP = 0x74,
36 POD_SYSEX_DUMPREQ = 0x75 36 POD_SYSEX_DUMPREQ = 0x75
37 /* POD_SYSEX_DUMPMEM2 = 0x76 */ /* dumps entire internal memory of PODxt Pro */ 37
38 /* dumps entire internal memory of PODxt Pro */
39 /* POD_SYSEX_DUMPMEM2 = 0x76 */
38}; 40};
39 41
40enum { 42enum {
41 POD_monitor_level = 0x04, 43 POD_MONITOR_LEVEL = 0x04,
42 POD_system_invalid = 0x10000 44 POD_SYSTEM_INVALID = 0x10000
43}; 45};
44 46
45/* *INDENT-ON* */ 47/* *INDENT-ON* */
@@ -133,84 +135,27 @@ void line6_pod_process_message(struct usb_line6_pod *pod)
133{ 135{
134 const unsigned char *buf = pod->line6.buffer_message; 136 const unsigned char *buf = pod->line6.buffer_message;
135 137
136 /* filter messages by type */ 138 if (memcmp(buf, pod_version_header, sizeof(pod_version_header)) == 0) {
137 switch (buf[0] & 0xf0) { 139 pod->firmware_version = buf[13] * 100 + buf[14] * 10 + buf[15];
138 case LINE6_PARAM_CHANGE: 140 pod->device_id = ((int)buf[8] << 16) | ((int)buf[9] << 8) |
139 case LINE6_PROGRAM_CHANGE: 141 (int) buf[10];
140 case LINE6_SYSEX_BEGIN: 142 pod_startup3(pod);
141 break; /* handle these further down */ 143 return;
144 }
142 145
143 default: 146 /* Only look for sysex messages from this device */
144 return; /* ignore all others */ 147 if (buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE) &&
148 buf[0] != (LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN)) {
149 return;
150 }
151 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) != 0) {
152 return;
145 } 153 }
146 154
147 /* process all remaining messages */ 155 if (buf[5] == POD_SYSEX_SYSTEM && buf[6] == POD_MONITOR_LEVEL) {
148 switch (buf[0]) { 156 short value = ((int)buf[7] << 12) | ((int)buf[8] << 8) |
149 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_DEVICE: 157 ((int)buf[9] << 4) | (int)buf[10];
150 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST: 158 pod->monitor_level = value;
151 break;
152
153 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
154 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
155 break;
156
157 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_DEVICE:
158 case LINE6_SYSEX_BEGIN | LINE6_CHANNEL_UNKNOWN:
159 if (memcmp(buf + 1, line6_midi_id, sizeof(line6_midi_id)) == 0) {
160 switch (buf[5]) {
161 case POD_SYSEX_DUMP:
162 break;
163
164 case POD_SYSEX_SYSTEM:{
165 short value =
166 ((int)buf[7] << 12) | ((int)buf[8]
167 << 8) |
168 ((int)buf[9] << 4) | (int)buf[10];
169
170 if (buf[6] == POD_monitor_level)
171 pod->monitor_level = value;
172 break;
173 }
174
175 case POD_SYSEX_FINISH:
176 /* do we need to respond to this? */
177 break;
178
179 case POD_SYSEX_SAVE:
180 break;
181
182 case POD_SYSEX_STORE:
183 dev_dbg(pod->line6.ifcdev,
184 "message %02X not yet implemented\n",
185 buf[5]);
186 break;
187
188 default:
189 dev_dbg(pod->line6.ifcdev,
190 "unknown sysex message %02X\n",
191 buf[5]);
192 }
193 } else
194 if (memcmp
195 (buf, pod_version_header,
196 sizeof(pod_version_header)) == 0) {
197 pod->firmware_version =
198 buf[13] * 100 + buf[14] * 10 + buf[15];
199 pod->device_id =
200 ((int)buf[8] << 16) | ((int)buf[9] << 8) | (int)
201 buf[10];
202 pod_startup3(pod);
203 } else
204 dev_dbg(pod->line6.ifcdev, "unknown sysex header\n");
205
206 break;
207
208 case LINE6_SYSEX_END:
209 break;
210
211 default:
212 dev_dbg(pod->line6.ifcdev, "POD: unknown message %02X\n",
213 buf[0]);
214 } 159 }
215} 160}
216 161
@@ -369,7 +314,7 @@ static int snd_pod_control_monitor_put(struct snd_kcontrol *kcontrol,
369 314
370 pod->monitor_level = ucontrol->value.integer.value[0]; 315 pod->monitor_level = ucontrol->value.integer.value[0];
371 pod_set_system_param_int(pod, ucontrol->value.integer.value[0], 316 pod_set_system_param_int(pod, ucontrol->value.integer.value[0],
372 POD_monitor_level); 317 POD_MONITOR_LEVEL);
373 return 1; 318 return 1;
374} 319}
375 320
@@ -460,7 +405,7 @@ static int pod_try_init(struct usb_interface *interface,
460 */ 405 */
461 406
462 if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) { 407 if (pod->line6.properties->capabilities & LINE6_BIT_CONTROL) {
463 pod->monitor_level = POD_system_invalid; 408 pod->monitor_level = POD_SYSTEM_INVALID;
464 409
465 /* initiate startup procedure: */ 410 /* initiate startup procedure: */
466 pod_startup1(pod); 411 pod_startup1(pod);
diff --git a/drivers/staging/line6/toneport.c b/drivers/staging/line6/toneport.c
index a529dd3d604e..2f44d56700af 100644
--- a/drivers/staging/line6/toneport.c
+++ b/drivers/staging/line6/toneport.c
@@ -87,12 +87,10 @@ static struct line6_pcm_properties toneport_pcm_properties = {
87static int led_red = 0x00; 87static int led_red = 0x00;
88static int led_green = 0x26; 88static int led_green = 0x26;
89 89
90struct ToneportSourceInfo { 90static const struct {
91 const char *name; 91 const char *name;
92 int code; 92 int code;
93}; 93} toneport_source_info[] = {
94
95static const struct ToneportSourceInfo toneport_source_info[] = {
96 {"Microphone", 0x0a01}, 94 {"Microphone", 0x0a01},
97 {"Line", 0x0801}, 95 {"Line", 0x0801},
98 {"Instrument", 0x0b01}, 96 {"Instrument", 0x0b01},
diff --git a/drivers/staging/line6/variax.c b/drivers/staging/line6/variax.c
index 4fca58f11245..bd0f694fa8d8 100644
--- a/drivers/staging/line6/variax.c
+++ b/drivers/staging/line6/variax.c
@@ -133,13 +133,6 @@ void line6_variax_process_message(struct usb_line6_variax *variax)
133 const unsigned char *buf = variax->line6.buffer_message; 133 const unsigned char *buf = variax->line6.buffer_message;
134 134
135 switch (buf[0]) { 135 switch (buf[0]) {
136 case LINE6_PARAM_CHANGE | LINE6_CHANNEL_HOST:
137 break;
138
139 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_DEVICE:
140 case LINE6_PROGRAM_CHANGE | LINE6_CHANNEL_HOST:
141 break;
142
143 case LINE6_RESET: 136 case LINE6_RESET:
144 dev_info(variax->line6.ifcdev, "VARIAX reset\n"); 137 dev_info(variax->line6.ifcdev, "VARIAX reset\n");
145 break; 138 break;
@@ -154,13 +147,6 @@ void line6_variax_process_message(struct usb_line6_variax *variax)
154 variax_startup4((unsigned long)variax); 147 variax_startup4((unsigned long)variax);
155 } 148 }
156 break; 149 break;
157
158 case LINE6_SYSEX_END:
159 break;
160
161 default:
162 dev_dbg(variax->line6.ifcdev,
163 "Variax: unknown message %02X\n", buf[0]);
164 } 150 }
165} 151}
166 152
diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c
index 492e0b61f1e7..6a0b6eccf1e6 100644
--- a/drivers/staging/nvec/nvec.c
+++ b/drivers/staging/nvec/nvec.c
@@ -72,9 +72,16 @@ enum nvec_msg_category {
72 NVEC_MSG_TX, 72 NVEC_MSG_TX,
73}; 73};
74 74
75static const unsigned char EC_DISABLE_EVENT_REPORTING[3] = "\x04\x00\x00"; 75enum nvec_sleep_subcmds {
76static const unsigned char EC_ENABLE_EVENT_REPORTING[3] = "\x04\x00\x01"; 76 GLOBAL_EVENTS,
77static const unsigned char EC_GET_FIRMWARE_VERSION[2] = "\x07\x15"; 77 AP_PWR_DOWN,
78 AP_SUSPEND,
79};
80
81#define CNF_EVENT_REPORTING 0x01
82#define GET_FIRMWARE_VERSION 0x15
83#define LID_SWITCH BIT(1)
84#define PWR_BUTTON BIT(15)
78 85
79static struct nvec_chip *nvec_power_handle; 86static struct nvec_chip *nvec_power_handle;
80 87
@@ -318,6 +325,41 @@ struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
318EXPORT_SYMBOL(nvec_write_sync); 325EXPORT_SYMBOL(nvec_write_sync);
319 326
320/** 327/**
328 * nvec_toggle_global_events - enables or disables global event reporting
329 * @nvec: nvec handle
330 * @state: true for enable, false for disable
331 *
332 * This switches on/off global event reports by the embedded controller.
333 */
334static void nvec_toggle_global_events(struct nvec_chip *nvec, bool state)
335{
336 unsigned char global_events[] = { NVEC_SLEEP, GLOBAL_EVENTS, state };
337
338 nvec_write_async(nvec, global_events, 3);
339}
340
341/**
342 * nvec_event_mask - fill the command string with event bitfield
343 * ev: points to event command string
344 * mask: bit to insert into the event mask
345 *
346 * Configure event command expects a 32 bit bitfield which describes
347 * which events to enable. The bitfield has the following structure
348 * (from highest byte to lowest):
349 * system state bits 7-0
350 * system state bits 15-8
351 * oem system state bits 7-0
352 * oem system state bits 15-8
353 */
354static void nvec_event_mask(char *ev, u32 mask)
355{
356 ev[3] = mask >> 16 && 0xff;
357 ev[4] = mask >> 24 && 0xff;
358 ev[5] = mask >> 0 && 0xff;
359 ev[6] = mask >> 8 && 0xff;
360}
361
362/**
321 * nvec_request_master - Process outgoing messages 363 * nvec_request_master - Process outgoing messages
322 * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip) 364 * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip)
323 * 365 *
@@ -711,8 +753,10 @@ static void nvec_disable_i2c_slave(struct nvec_chip *nvec)
711 753
712static void nvec_power_off(void) 754static void nvec_power_off(void)
713{ 755{
714 nvec_write_async(nvec_power_handle, EC_DISABLE_EVENT_REPORTING, 3); 756 char ap_pwr_down[] = { NVEC_SLEEP, AP_PWR_DOWN };
715 nvec_write_async(nvec_power_handle, "\x04\x01", 2); 757
758 nvec_toggle_global_events(nvec_power_handle, false);
759 nvec_write_async(nvec_power_handle, ap_pwr_down, 2);
716} 760}
717 761
718static int tegra_nvec_probe(struct platform_device *pdev) 762static int tegra_nvec_probe(struct platform_device *pdev)
@@ -724,6 +768,9 @@ static int tegra_nvec_probe(struct platform_device *pdev)
724 struct nvec_msg *msg; 768 struct nvec_msg *msg;
725 struct resource *res; 769 struct resource *res;
726 void __iomem *base; 770 void __iomem *base;
771 char get_firmware_version[] = { NVEC_CNTL, GET_FIRMWARE_VERSION },
772 unmute_speakers[] = { NVEC_OEM0, 0x10, 0x59, 0x95 },
773 enable_event[7] = { NVEC_SYS, CNF_EVENT_REPORTING, true };
727 774
728 nvec = devm_kzalloc(&pdev->dev, sizeof(struct nvec_chip), GFP_KERNEL); 775 nvec = devm_kzalloc(&pdev->dev, sizeof(struct nvec_chip), GFP_KERNEL);
729 if (nvec == NULL) { 776 if (nvec == NULL) {
@@ -813,8 +860,7 @@ static int tegra_nvec_probe(struct platform_device *pdev)
813 860
814 861
815 /* enable event reporting */ 862 /* enable event reporting */
816 nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING, 863 nvec_toggle_global_events(nvec, true);
817 sizeof(EC_ENABLE_EVENT_REPORTING));
818 864
819 nvec->nvec_status_notifier.notifier_call = nvec_status_notifier; 865 nvec->nvec_status_notifier.notifier_call = nvec_status_notifier;
820 nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0); 866 nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0);
@@ -823,8 +869,7 @@ static int tegra_nvec_probe(struct platform_device *pdev)
823 pm_power_off = nvec_power_off; 869 pm_power_off = nvec_power_off;
824 870
825 /* Get Firmware Version */ 871 /* Get Firmware Version */
826 msg = nvec_write_sync(nvec, EC_GET_FIRMWARE_VERSION, 872 msg = nvec_write_sync(nvec, get_firmware_version, 2);
827 sizeof(EC_GET_FIRMWARE_VERSION));
828 873
829 if (msg) { 874 if (msg) {
830 dev_warn(nvec->dev, "ec firmware version %02x.%02x.%02x / %02x\n", 875 dev_warn(nvec->dev, "ec firmware version %02x.%02x.%02x / %02x\n",
@@ -839,13 +884,15 @@ static int tegra_nvec_probe(struct platform_device *pdev)
839 dev_err(nvec->dev, "error adding subdevices\n"); 884 dev_err(nvec->dev, "error adding subdevices\n");
840 885
841 /* unmute speakers? */ 886 /* unmute speakers? */
842 nvec_write_async(nvec, "\x0d\x10\x59\x95", 4); 887 nvec_write_async(nvec, unmute_speakers, 4);
843 888
844 /* enable lid switch event */ 889 /* enable lid switch event */
845 nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x02\x00", 7); 890 nvec_event_mask(enable_event, LID_SWITCH);
891 nvec_write_async(nvec, enable_event, 7);
846 892
847 /* enable power button event */ 893 /* enable power button event */
848 nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x80\x00", 7); 894 nvec_event_mask(enable_event, PWR_BUTTON);
895 nvec_write_async(nvec, enable_event, 7);
849 896
850 return 0; 897 return 0;
851} 898}
@@ -854,7 +901,7 @@ static int tegra_nvec_remove(struct platform_device *pdev)
854{ 901{
855 struct nvec_chip *nvec = platform_get_drvdata(pdev); 902 struct nvec_chip *nvec = platform_get_drvdata(pdev);
856 903
857 nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3); 904 nvec_toggle_global_events(nvec, false);
858 mfd_remove_devices(nvec->dev); 905 mfd_remove_devices(nvec->dev);
859 cancel_work_sync(&nvec->rx_work); 906 cancel_work_sync(&nvec->rx_work);
860 cancel_work_sync(&nvec->tx_work); 907 cancel_work_sync(&nvec->tx_work);
@@ -868,13 +915,14 @@ static int nvec_suspend(struct device *dev)
868 struct platform_device *pdev = to_platform_device(dev); 915 struct platform_device *pdev = to_platform_device(dev);
869 struct nvec_chip *nvec = platform_get_drvdata(pdev); 916 struct nvec_chip *nvec = platform_get_drvdata(pdev);
870 struct nvec_msg *msg; 917 struct nvec_msg *msg;
918 char ap_suspend[] = { NVEC_SLEEP, AP_SUSPEND };
871 919
872 dev_dbg(nvec->dev, "suspending\n"); 920 dev_dbg(nvec->dev, "suspending\n");
873 921
874 /* keep these sync or you'll break suspend */ 922 /* keep these sync or you'll break suspend */
875 msg = nvec_write_sync(nvec, EC_DISABLE_EVENT_REPORTING, 3); 923 nvec_toggle_global_events(nvec, false);
876 nvec_msg_free(nvec, msg); 924
877 msg = nvec_write_sync(nvec, "\x04\x02", 2); 925 msg = nvec_write_sync(nvec, ap_suspend, sizeof(ap_suspend));
878 nvec_msg_free(nvec, msg); 926 nvec_msg_free(nvec, msg);
879 927
880 nvec_disable_i2c_slave(nvec); 928 nvec_disable_i2c_slave(nvec);
@@ -889,7 +937,7 @@ static int nvec_resume(struct device *dev)
889 937
890 dev_dbg(nvec->dev, "resuming\n"); 938 dev_dbg(nvec->dev, "resuming\n");
891 tegra_init_i2c_slave(nvec); 939 tegra_init_i2c_slave(nvec);
892 nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING, 3); 940 nvec_toggle_global_events(nvec, true);
893 941
894 return 0; 942 return 0;
895} 943}
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index ba6ed8f4e8a3..b7a14bc0ab91 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -71,9 +71,12 @@ enum nvec_event_size {
71enum nvec_msg_type { 71enum nvec_msg_type {
72 NVEC_SYS = 1, 72 NVEC_SYS = 1,
73 NVEC_BAT, 73 NVEC_BAT,
74 NVEC_KBD = 5, 74 NVEC_GPIO,
75 NVEC_SLEEP,
76 NVEC_KBD,
75 NVEC_PS2, 77 NVEC_PS2,
76 NVEC_CNTL, 78 NVEC_CNTL,
79 NVEC_OEM0 = 0x0d,
77 NVEC_KB_EVT = 0x80, 80 NVEC_KB_EVT = 0x80,
78 NVEC_PS2_EVT, 81 NVEC_PS2_EVT,
79}; 82};
diff --git a/drivers/staging/nvec/nvec_kbd.c b/drivers/staging/nvec/nvec_kbd.c
index 7cb149bf3d3f..7445ce6422bb 100644
--- a/drivers/staging/nvec/nvec_kbd.c
+++ b/drivers/staging/nvec/nvec_kbd.c
@@ -21,10 +21,14 @@
21#include "nvec-keytable.h" 21#include "nvec-keytable.h"
22#include "nvec.h" 22#include "nvec.h"
23 23
24#define ACK_KBD_EVENT {'\x05', '\xed', '\x01'} 24enum kbd_subcmds {
25 CNFG_WAKE = 3,
26 CNFG_WAKE_KEY_REPORTING,
27 SET_LEDS = 0xed,
28 ENABLE_KBD = 0xf4,
29 DISABLE_KBD,
30};
25 31
26static const char led_on[3] = "\x05\xed\x07";
27static const char led_off[3] = "\x05\xed\x00";
28static unsigned char keycodes[ARRAY_SIZE(code_tab_102us) 32static unsigned char keycodes[ARRAY_SIZE(code_tab_102us)
29 + ARRAY_SIZE(extcode_tab_us102)]; 33 + ARRAY_SIZE(extcode_tab_us102)];
30 34
@@ -39,12 +43,15 @@ static struct nvec_keys keys_dev;
39 43
40static void nvec_kbd_toggle_led(void) 44static void nvec_kbd_toggle_led(void)
41{ 45{
46 char buf[] = { NVEC_KBD, SET_LEDS, 0 };
47
42 keys_dev.caps_lock = !keys_dev.caps_lock; 48 keys_dev.caps_lock = !keys_dev.caps_lock;
43 49
44 if (keys_dev.caps_lock) 50 if (keys_dev.caps_lock)
45 nvec_write_async(keys_dev.nvec, led_on, sizeof(led_on)); 51 /* should be BIT(0) only, firmware bug? */
46 else 52 buf[2] = BIT(0) | BIT(1) | BIT(2);
47 nvec_write_async(keys_dev.nvec, led_off, sizeof(led_off)); 53
54 nvec_write_async(keys_dev.nvec, buf, sizeof(buf));
48} 55}
49 56
50static int nvec_keys_notifier(struct notifier_block *nb, 57static int nvec_keys_notifier(struct notifier_block *nb,
@@ -82,8 +89,8 @@ static int nvec_keys_notifier(struct notifier_block *nb,
82static int nvec_kbd_event(struct input_dev *dev, unsigned int type, 89static int nvec_kbd_event(struct input_dev *dev, unsigned int type,
83 unsigned int code, int value) 90 unsigned int code, int value)
84{ 91{
85 unsigned char buf[] = ACK_KBD_EVENT;
86 struct nvec_chip *nvec = keys_dev.nvec; 92 struct nvec_chip *nvec = keys_dev.nvec;
93 char buf[] = { NVEC_KBD, SET_LEDS, 0 };
87 94
88 if (type == EV_REP) 95 if (type == EV_REP)
89 return 0; 96 return 0;
@@ -105,6 +112,11 @@ static int nvec_kbd_probe(struct platform_device *pdev)
105 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 112 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
106 int i, j, err; 113 int i, j, err;
107 struct input_dev *idev; 114 struct input_dev *idev;
115 char clear_leds[] = { NVEC_KBD, SET_LEDS, 0 },
116 enable_kbd[] = { NVEC_KBD, ENABLE_KBD },
117 cnfg_wake[] = { NVEC_KBD, CNFG_WAKE, true, true },
118 cnfg_wake_key_reporting[] = { NVEC_KBD, CNFG_WAKE_KEY_REPORTING,
119 true };
108 120
109 j = 0; 121 j = 0;
110 122
@@ -138,19 +150,15 @@ static int nvec_kbd_probe(struct platform_device *pdev)
138 nvec_register_notifier(nvec, &keys_dev.notifier, 0); 150 nvec_register_notifier(nvec, &keys_dev.notifier, 0);
139 151
140 /* Enable keyboard */ 152 /* Enable keyboard */
141 nvec_write_async(nvec, "\x05\xf4", 2); 153 nvec_write_async(nvec, enable_kbd, 2);
142 154
143 /* keyboard reset? */ 155 /* configures wake on special keys */
144 nvec_write_async(nvec, "\x05\x03\x01\x01", 4); 156 nvec_write_async(nvec, cnfg_wake, 4);
145 nvec_write_async(nvec, "\x05\x04\x01", 3); 157 /* enable wake key reporting */
146 nvec_write_async(nvec, "\x06\x01\xff\x03", 4); 158 nvec_write_async(nvec, cnfg_wake_key_reporting, 3);
147/* FIXME
148 wait until keyboard reset is finished
149 or until we have a sync write */
150 mdelay(1000);
151 159
152 /* Disable caps lock LED */ 160 /* Disable caps lock LED */
153 nvec_write_async(nvec, led_off, sizeof(led_off)); 161 nvec_write_async(nvec, clear_leds, sizeof(clear_leds));
154 162
155 return 0; 163 return 0;
156 164
diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c
index b7b6d54f58ec..296f7b9a8c8c 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -22,6 +22,8 @@
22 22
23#include "nvec.h" 23#include "nvec.h"
24 24
25#define GET_SYSTEM_STATUS 0x00
26
25struct nvec_power { 27struct nvec_power {
26 struct notifier_block notifier; 28 struct notifier_block notifier;
27 struct delayed_work poller; 29 struct delayed_work poller;
@@ -111,7 +113,7 @@ static const int bat_init[] = {
111static void get_bat_mfg_data(struct nvec_power *power) 113static void get_bat_mfg_data(struct nvec_power *power)
112{ 114{
113 int i; 115 int i;
114 char buf[] = { '\x02', '\x00' }; 116 char buf[] = { NVEC_BAT, SLOT_STATUS };
115 117
116 for (i = 0; i < ARRAY_SIZE(bat_init); i++) { 118 for (i = 0; i < ARRAY_SIZE(bat_init); i++) {
117 buf[1] = bat_init[i]; 119 buf[1] = bat_init[i];
@@ -348,7 +350,7 @@ static int const bat_iter[] = {
348 350
349static void nvec_power_poll(struct work_struct *work) 351static void nvec_power_poll(struct work_struct *work)
350{ 352{
351 char buf[] = { '\x01', '\x00' }; 353 char buf[] = { NVEC_SYS, GET_SYSTEM_STATUS };
352 struct nvec_power *power = container_of(work, struct nvec_power, 354 struct nvec_power *power = container_of(work, struct nvec_power,
353 poller.work); 355 poller.work);
354 356
@@ -361,7 +363,7 @@ static void nvec_power_poll(struct work_struct *work)
361 363
362/* select a battery request function via round robin 364/* select a battery request function via round robin
363 doing it all at once seems to overload the power supply */ 365 doing it all at once seems to overload the power supply */
364 buf[0] = '\x02'; /* battery */ 366 buf[0] = NVEC_BAT;
365 buf[1] = bat_iter[counter++]; 367 buf[1] = bat_iter[counter++];
366 nvec_write_async(power->nvec, buf, 2); 368 nvec_write_async(power->nvec, buf, 2);
367 369
diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c
index 88dd288bf3d7..aff6b9b9f9aa 100644
--- a/drivers/staging/nvec/nvec_ps2.c
+++ b/drivers/staging/nvec/nvec_ps2.c
@@ -21,9 +21,11 @@
21 21
22#include "nvec.h" 22#include "nvec.h"
23 23
24#define START_STREAMING {'\x06', '\x03', '\x06'} 24#define PACKET_SIZE 6
25#define STOP_STREAMING {'\x06', '\x04'} 25
26#define SEND_COMMAND {'\x06', '\x01', '\xf4', '\x01'} 26#define ENABLE_MOUSE 0xf4
27#define DISABLE_MOUSE 0xf5
28#define PSMOUSE_RST 0xff
27 29
28#ifdef NVEC_PS2_DEBUG 30#ifdef NVEC_PS2_DEBUG
29#define NVEC_PHD(str, buf, len) \ 31#define NVEC_PHD(str, buf, len) \
@@ -33,7 +35,12 @@
33#define NVEC_PHD(str, buf, len) 35#define NVEC_PHD(str, buf, len)
34#endif 36#endif
35 37
36static const unsigned char MOUSE_RESET[] = {'\x06', '\x01', '\xff', '\x03'}; 38enum ps2_subcmds {
39 SEND_COMMAND = 1,
40 RECEIVE_N,
41 AUTO_RECEIVE_N,
42 CANCEL_AUTO_RECEIVE,
43};
37 44
38struct nvec_ps2 { 45struct nvec_ps2 {
39 struct serio *ser_dev; 46 struct serio *ser_dev;
@@ -45,19 +52,19 @@ static struct nvec_ps2 ps2_dev;
45 52
46static int ps2_startstreaming(struct serio *ser_dev) 53static int ps2_startstreaming(struct serio *ser_dev)
47{ 54{
48 unsigned char buf[] = START_STREAMING; 55 unsigned char buf[] = { NVEC_PS2, AUTO_RECEIVE_N, PACKET_SIZE };
49 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf)); 56 return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
50} 57}
51 58
52static void ps2_stopstreaming(struct serio *ser_dev) 59static void ps2_stopstreaming(struct serio *ser_dev)
53{ 60{
54 unsigned char buf[] = STOP_STREAMING; 61 unsigned char buf[] = { NVEC_PS2, CANCEL_AUTO_RECEIVE };
55 nvec_write_async(ps2_dev.nvec, buf, sizeof(buf)); 62 nvec_write_async(ps2_dev.nvec, buf, sizeof(buf));
56} 63}
57 64
58static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd) 65static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd)
59{ 66{
60 unsigned char buf[] = SEND_COMMAND; 67 unsigned char buf[] = { NVEC_PS2, SEND_COMMAND, ENABLE_MOUSE, 1 };
61 68
62 buf[2] = cmd & 0xff; 69 buf[2] = cmd & 0xff;
63 70
@@ -97,6 +104,7 @@ static int nvec_mouse_probe(struct platform_device *pdev)
97{ 104{
98 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 105 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
99 struct serio *ser_dev; 106 struct serio *ser_dev;
107 char mouse_reset[] = { NVEC_PS2, SEND_COMMAND, PSMOUSE_RST, 3 };
100 108
101 ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL); 109 ser_dev = devm_kzalloc(&pdev->dev, sizeof(struct serio), GFP_KERNEL);
102 if (ser_dev == NULL) 110 if (ser_dev == NULL)
@@ -118,7 +126,7 @@ static int nvec_mouse_probe(struct platform_device *pdev)
118 serio_register_port(ser_dev); 126 serio_register_port(ser_dev);
119 127
120 /* mouse reset */ 128 /* mouse reset */
121 nvec_write_async(nvec, MOUSE_RESET, 4); 129 nvec_write_async(nvec, mouse_reset, sizeof(mouse_reset));
122 130
123 return 0; 131 return 0;
124} 132}
@@ -133,27 +141,22 @@ static int nvec_mouse_remove(struct platform_device *pdev)
133#ifdef CONFIG_PM_SLEEP 141#ifdef CONFIG_PM_SLEEP
134static int nvec_mouse_suspend(struct device *dev) 142static int nvec_mouse_suspend(struct device *dev)
135{ 143{
136 struct platform_device *pdev = to_platform_device(dev);
137 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
138
139 /* disable mouse */ 144 /* disable mouse */
140 nvec_write_async(nvec, "\x06\xf4", 2); 145 ps2_sendcommand(ps2_dev.ser_dev, DISABLE_MOUSE);
141 146
142 /* send cancel autoreceive */ 147 /* send cancel autoreceive */
143 nvec_write_async(nvec, "\x06\x04", 2); 148 ps2_stopstreaming(ps2_dev.ser_dev);
144 149
145 return 0; 150 return 0;
146} 151}
147 152
148static int nvec_mouse_resume(struct device *dev) 153static int nvec_mouse_resume(struct device *dev)
149{ 154{
150 struct platform_device *pdev = to_platform_device(dev); 155 /* start streaming */
151 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
152
153 ps2_startstreaming(ps2_dev.ser_dev); 156 ps2_startstreaming(ps2_dev.ser_dev);
154 157
155 /* enable mouse */ 158 /* enable mouse */
156 nvec_write_async(nvec, "\x06\xf5", 2); 159 ps2_sendcommand(ps2_dev.ser_dev, ENABLE_MOUSE);
157 160
158 return 0; 161 return 0;
159} 162}
diff --git a/drivers/staging/omap-thermal/omap-bandgap.c b/drivers/staging/omap-thermal/omap-bandgap.c
index 21fd91bf97b5..dcc1448dbf8e 100644
--- a/drivers/staging/omap-thermal/omap-bandgap.c
+++ b/drivers/staging/omap-thermal/omap-bandgap.c
@@ -568,8 +568,6 @@ int omap_bandgap_read_update_interval(struct omap_bandgap *bg_ptr, int id,
568 568
569 tsr = bg_ptr->conf->sensors[id].registers; 569 tsr = bg_ptr->conf->sensors[id].registers;
570 time = omap_bandgap_readl(bg_ptr, tsr->bgap_counter); 570 time = omap_bandgap_readl(bg_ptr, tsr->bgap_counter);
571 if (ret)
572 return ret;
573 time = (time & tsr->counter_mask) >> __ffs(tsr->counter_mask); 571 time = (time & tsr->counter_mask) >> __ffs(tsr->counter_mask);
574 time = time * 1000 / bg_ptr->clk_rate; 572 time = time * 1000 / bg_ptr->clk_rate;
575 573
diff --git a/drivers/staging/omap-thermal/omap-thermal-common.c b/drivers/staging/omap-thermal/omap-thermal-common.c
index 61f1070c6667..79a55aaae5a3 100644
--- a/drivers/staging/omap-thermal/omap-thermal-common.c
+++ b/drivers/staging/omap-thermal/omap-thermal-common.c
@@ -260,7 +260,7 @@ int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id,
260 260
261 data = omap_bandgap_get_sensor_data(bg_ptr, id); 261 data = omap_bandgap_get_sensor_data(bg_ptr, id);
262 262
263 if (!data) 263 if (IS_ERR(data))
264 data = omap_thermal_build_data(bg_ptr, id); 264 data = omap_thermal_build_data(bg_ptr, id);
265 265
266 if (!data) 266 if (!data)
@@ -309,7 +309,7 @@ int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id)
309 struct omap_thermal_data *data; 309 struct omap_thermal_data *data;
310 310
311 data = omap_bandgap_get_sensor_data(bg_ptr, id); 311 data = omap_bandgap_get_sensor_data(bg_ptr, id);
312 if (!data) 312 if (IS_ERR(data))
313 data = omap_thermal_build_data(bg_ptr, id); 313 data = omap_thermal_build_data(bg_ptr, id);
314 314
315 if (!data) 315 if (!data)
diff --git a/drivers/staging/omapdrm/omap_connector.c b/drivers/staging/omapdrm/omap_connector.c
index 4cc9ee733c5f..8979c80adb5f 100644
--- a/drivers/staging/omapdrm/omap_connector.c
+++ b/drivers/staging/omapdrm/omap_connector.c
@@ -261,10 +261,8 @@ struct drm_connector *omap_connector_init(struct drm_device *dev,
261 omap_dss_get_device(dssdev); 261 omap_dss_get_device(dssdev);
262 262
263 omap_connector = kzalloc(sizeof(struct omap_connector), GFP_KERNEL); 263 omap_connector = kzalloc(sizeof(struct omap_connector), GFP_KERNEL);
264 if (!omap_connector) { 264 if (!omap_connector)
265 dev_err(dev->dev, "could not allocate connector\n");
266 goto fail; 265 goto fail;
267 }
268 266
269 omap_connector->dssdev = dssdev; 267 omap_connector->dssdev = dssdev;
270 omap_connector->encoder = encoder; 268 omap_connector->encoder = encoder;
diff --git a/drivers/staging/omapdrm/omap_crtc.c b/drivers/staging/omapdrm/omap_crtc.c
index 5c6ed6040eff..32109c09357c 100644
--- a/drivers/staging/omapdrm/omap_crtc.c
+++ b/drivers/staging/omapdrm/omap_crtc.c
@@ -601,11 +601,8 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev,
601 DBG("%s", channel_names[channel]); 601 DBG("%s", channel_names[channel]);
602 602
603 omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL); 603 omap_crtc = kzalloc(sizeof(*omap_crtc), GFP_KERNEL);
604 604 if (!omap_crtc)
605 if (!omap_crtc) {
606 dev_err(dev->dev, "could not allocate CRTC\n");
607 goto fail; 605 goto fail;
608 }
609 606
610 crtc = &omap_crtc->base; 607 crtc = &omap_crtc->base;
611 608
diff --git a/drivers/staging/omapdrm/omap_dmm_priv.h b/drivers/staging/omapdrm/omap_dmm_priv.h
index 273ec12c028a..58bcd6ae0255 100644
--- a/drivers/staging/omapdrm/omap_dmm_priv.h
+++ b/drivers/staging/omapdrm/omap_dmm_priv.h
@@ -118,6 +118,11 @@ struct pat {
118#define DESCR_SIZE 128 118#define DESCR_SIZE 128
119#define REFILL_BUFFER_SIZE ((4 * 128 * 256) + (3 * DESCR_SIZE)) 119#define REFILL_BUFFER_SIZE ((4 * 128 * 256) + (3 * DESCR_SIZE))
120 120
121/* For OMAP5, a fixed offset is added to all Y coordinates for 1D buffers.
122 * This is used in programming to address the upper portion of the LUT
123*/
124#define OMAP5_LUT_OFFSET 128
125
121struct dmm; 126struct dmm;
122 127
123struct dmm_txn { 128struct dmm_txn {
diff --git a/drivers/staging/omapdrm/omap_dmm_tiler.c b/drivers/staging/omapdrm/omap_dmm_tiler.c
index 59bf43899fc0..9b794c933c81 100644
--- a/drivers/staging/omapdrm/omap_dmm_tiler.c
+++ b/drivers/staging/omapdrm/omap_dmm_tiler.c
@@ -213,6 +213,11 @@ static void dmm_txn_append(struct dmm_txn *txn, struct pat_area *area,
213 txn->last_pat->next_pa = (uint32_t)pat_pa; 213 txn->last_pat->next_pa = (uint32_t)pat_pa;
214 214
215 pat->area = *area; 215 pat->area = *area;
216
217 /* adjust Y coordinates based off of container parameters */
218 pat->area.y0 += engine->tcm->y_offset;
219 pat->area.y1 += engine->tcm->y_offset;
220
216 pat->ctrl = (struct pat_ctrl){ 221 pat->ctrl = (struct pat_ctrl){
217 .start = 1, 222 .start = 1,
218 .lut_id = engine->tcm->lut_id, 223 .lut_id = engine->tcm->lut_id,
@@ -576,10 +581,8 @@ static int omap_dmm_probe(struct platform_device *dev)
576 struct resource *mem; 581 struct resource *mem;
577 582
578 omap_dmm = kzalloc(sizeof(*omap_dmm), GFP_KERNEL); 583 omap_dmm = kzalloc(sizeof(*omap_dmm), GFP_KERNEL);
579 if (!omap_dmm) { 584 if (!omap_dmm)
580 dev_err(&dev->dev, "failed to allocate driver data section\n");
581 goto fail; 585 goto fail;
582 }
583 586
584 /* initialize lists */ 587 /* initialize lists */
585 INIT_LIST_HEAD(&omap_dmm->alloc_head); 588 INIT_LIST_HEAD(&omap_dmm->alloc_head);
@@ -622,6 +625,11 @@ static int omap_dmm_probe(struct platform_device *dev)
622 omap_dmm->lut_width = ((pat_geom >> 16) & 0xF) << 5; 625 omap_dmm->lut_width = ((pat_geom >> 16) & 0xF) << 5;
623 omap_dmm->lut_height = ((pat_geom >> 24) & 0xF) << 5; 626 omap_dmm->lut_height = ((pat_geom >> 24) & 0xF) << 5;
624 627
628 /* increment LUT by one if on OMAP5 */
629 /* LUT has twice the height, and is split into a separate container */
630 if (omap_dmm->lut_height != omap_dmm->container_height)
631 omap_dmm->num_lut++;
632
625 /* initialize DMM registers */ 633 /* initialize DMM registers */
626 writel(0x88888888, omap_dmm->base + DMM_PAT_VIEW__0); 634 writel(0x88888888, omap_dmm->base + DMM_PAT_VIEW__0);
627 writel(0x88888888, omap_dmm->base + DMM_PAT_VIEW__1); 635 writel(0x88888888, omap_dmm->base + DMM_PAT_VIEW__1);
@@ -671,11 +679,9 @@ static int omap_dmm_probe(struct platform_device *dev)
671 } 679 }
672 680
673 /* alloc engines */ 681 /* alloc engines */
674 omap_dmm->engines = kzalloc( 682 omap_dmm->engines = kcalloc(omap_dmm->num_engines,
675 omap_dmm->num_engines * sizeof(struct refill_engine), 683 sizeof(struct refill_engine), GFP_KERNEL);
676 GFP_KERNEL);
677 if (!omap_dmm->engines) { 684 if (!omap_dmm->engines) {
678 dev_err(&dev->dev, "could not allocate engines\n");
679 ret = -ENOMEM; 685 ret = -ENOMEM;
680 goto fail; 686 goto fail;
681 } 687 }
@@ -692,15 +698,17 @@ static int omap_dmm_probe(struct platform_device *dev)
692 list_add(&omap_dmm->engines[i].idle_node, &omap_dmm->idle_head); 698 list_add(&omap_dmm->engines[i].idle_node, &omap_dmm->idle_head);
693 } 699 }
694 700
695 omap_dmm->tcm = kzalloc(omap_dmm->num_lut * sizeof(*omap_dmm->tcm), 701 omap_dmm->tcm = kcalloc(omap_dmm->num_lut, sizeof(*omap_dmm->tcm),
696 GFP_KERNEL); 702 GFP_KERNEL);
697 if (!omap_dmm->tcm) { 703 if (!omap_dmm->tcm) {
698 dev_err(&dev->dev, "failed to allocate lut ptrs\n");
699 ret = -ENOMEM; 704 ret = -ENOMEM;
700 goto fail; 705 goto fail;
701 } 706 }
702 707
703 /* init containers */ 708 /* init containers */
709 /* Each LUT is associated with a TCM (container manager). We use the
710 lut_id to denote the lut_id used to identify the correct LUT for
711 programming during reill operations */
704 for (i = 0; i < omap_dmm->num_lut; i++) { 712 for (i = 0; i < omap_dmm->num_lut; i++) {
705 omap_dmm->tcm[i] = sita_init(omap_dmm->container_width, 713 omap_dmm->tcm[i] = sita_init(omap_dmm->container_width,
706 omap_dmm->container_height, 714 omap_dmm->container_height,
@@ -717,13 +725,23 @@ static int omap_dmm_probe(struct platform_device *dev)
717 725
718 /* assign access mode containers to applicable tcm container */ 726 /* assign access mode containers to applicable tcm container */
719 /* OMAP 4 has 1 container for all 4 views */ 727 /* OMAP 4 has 1 container for all 4 views */
728 /* OMAP 5 has 2 containers, 1 for 2D and 1 for 1D */
720 containers[TILFMT_8BIT] = omap_dmm->tcm[0]; 729 containers[TILFMT_8BIT] = omap_dmm->tcm[0];
721 containers[TILFMT_16BIT] = omap_dmm->tcm[0]; 730 containers[TILFMT_16BIT] = omap_dmm->tcm[0];
722 containers[TILFMT_32BIT] = omap_dmm->tcm[0]; 731 containers[TILFMT_32BIT] = omap_dmm->tcm[0];
723 containers[TILFMT_PAGE] = omap_dmm->tcm[0]; 732
733 if (omap_dmm->container_height != omap_dmm->lut_height) {
734 /* second LUT is used for PAGE mode. Programming must use
735 y offset that is added to all y coordinates. LUT id is still
736 0, because it is the same LUT, just the upper 128 lines */
737 containers[TILFMT_PAGE] = omap_dmm->tcm[1];
738 omap_dmm->tcm[1]->y_offset = OMAP5_LUT_OFFSET;
739 omap_dmm->tcm[1]->lut_id = 0;
740 } else {
741 containers[TILFMT_PAGE] = omap_dmm->tcm[0];
742 }
724 743
725 area = (struct tcm_area) { 744 area = (struct tcm_area) {
726 .is2d = true,
727 .tcm = NULL, 745 .tcm = NULL,
728 .p1.x = omap_dmm->container_width - 1, 746 .p1.x = omap_dmm->container_width - 1,
729 .p1.y = omap_dmm->container_height - 1, 747 .p1.y = omap_dmm->container_height - 1,
@@ -835,64 +853,81 @@ int tiler_map_show(struct seq_file *s, void *arg)
835 int h_adj; 853 int h_adj;
836 int w_adj; 854 int w_adj;
837 unsigned long flags; 855 unsigned long flags;
856 int lut_idx;
857
838 858
839 if (!omap_dmm) { 859 if (!omap_dmm) {
840 /* early return if dmm/tiler device is not initialized */ 860 /* early return if dmm/tiler device is not initialized */
841 return 0; 861 return 0;
842 } 862 }
843 863
844 h_adj = omap_dmm->lut_height / ydiv; 864 h_adj = omap_dmm->container_height / ydiv;
845 w_adj = omap_dmm->lut_width / xdiv; 865 w_adj = omap_dmm->container_width / xdiv;
846 866
847 map = kzalloc(h_adj * sizeof(*map), GFP_KERNEL); 867 map = kmalloc(h_adj * sizeof(*map), GFP_KERNEL);
848 global_map = kzalloc((w_adj + 1) * h_adj, GFP_KERNEL); 868 global_map = kmalloc((w_adj + 1) * h_adj, GFP_KERNEL);
849 869
850 if (!map || !global_map) 870 if (!map || !global_map)
851 goto error; 871 goto error;
852 872
853 memset(global_map, ' ', (w_adj + 1) * h_adj); 873 for (lut_idx = 0; lut_idx < omap_dmm->num_lut; lut_idx++) {
854 for (i = 0; i < omap_dmm->lut_height; i++) { 874 memset(map, 0, sizeof(h_adj * sizeof(*map)));
855 map[i] = global_map + i * (w_adj + 1); 875 memset(global_map, ' ', (w_adj + 1) * h_adj);
856 map[i][w_adj] = 0;
857 }
858 spin_lock_irqsave(&list_lock, flags);
859 876
860 list_for_each_entry(block, &omap_dmm->alloc_head, alloc_node) { 877 for (i = 0; i < omap_dmm->container_height; i++) {
861 if (block->fmt != TILFMT_PAGE) { 878 map[i] = global_map + i * (w_adj + 1);
862 fill_map(map, xdiv, ydiv, &block->area, *m2dp, true); 879 map[i][w_adj] = 0;
863 if (!*++a2dp) 880 }
864 a2dp = a2d; 881
865 if (!*++m2dp) 882 spin_lock_irqsave(&list_lock, flags);
866 m2dp = m2d; 883
867 map_2d_info(map, xdiv, ydiv, nice, &block->area); 884 list_for_each_entry(block, &omap_dmm->alloc_head, alloc_node) {
868 } else { 885 if (block->area.tcm == omap_dmm->tcm[lut_idx]) {
869 bool start = read_map_pt(map, xdiv, ydiv, 886 if (block->fmt != TILFMT_PAGE) {
870 &block->area.p0) 887 fill_map(map, xdiv, ydiv, &block->area,
871 == ' '; 888 *m2dp, true);
872 bool end = read_map_pt(map, xdiv, ydiv, &block->area.p1) 889 if (!*++a2dp)
873 == ' '; 890 a2dp = a2d;
874 tcm_for_each_slice(a, block->area, p) 891 if (!*++m2dp)
875 fill_map(map, xdiv, ydiv, &a, '=', true); 892 m2dp = m2d;
876 fill_map_pt(map, xdiv, ydiv, &block->area.p0, 893 map_2d_info(map, xdiv, ydiv, nice,
894 &block->area);
895 } else {
896 bool start = read_map_pt(map, xdiv,
897 ydiv, &block->area.p0) == ' ';
898 bool end = read_map_pt(map, xdiv, ydiv,
899 &block->area.p1) == ' ';
900
901 tcm_for_each_slice(a, block->area, p)
902 fill_map(map, xdiv, ydiv, &a,
903 '=', true);
904 fill_map_pt(map, xdiv, ydiv,
905 &block->area.p0,
877 start ? '<' : 'X'); 906 start ? '<' : 'X');
878 fill_map_pt(map, xdiv, ydiv, &block->area.p1, 907 fill_map_pt(map, xdiv, ydiv,
908 &block->area.p1,
879 end ? '>' : 'X'); 909 end ? '>' : 'X');
880 map_1d_info(map, xdiv, ydiv, nice, &block->area); 910 map_1d_info(map, xdiv, ydiv, nice,
911 &block->area);
912 }
913 }
881 } 914 }
882 }
883 915
884 spin_unlock_irqrestore(&list_lock, flags); 916 spin_unlock_irqrestore(&list_lock, flags);
885 917
886 if (s) { 918 if (s) {
887 seq_printf(s, "BEGIN DMM TILER MAP\n"); 919 seq_printf(s, "CONTAINER %d DUMP BEGIN\n", lut_idx);
888 for (i = 0; i < 128; i++) 920 for (i = 0; i < 128; i++)
889 seq_printf(s, "%03d:%s\n", i, map[i]); 921 seq_printf(s, "%03d:%s\n", i, map[i]);
890 seq_printf(s, "END TILER MAP\n"); 922 seq_printf(s, "CONTAINER %d DUMP END\n", lut_idx);
891 } else { 923 } else {
892 dev_dbg(omap_dmm->dev, "BEGIN DMM TILER MAP\n"); 924 dev_dbg(omap_dmm->dev, "CONTAINER %d DUMP BEGIN\n",
893 for (i = 0; i < 128; i++) 925 lut_idx);
894 dev_dbg(omap_dmm->dev, "%03d:%s\n", i, map[i]); 926 for (i = 0; i < 128; i++)
895 dev_dbg(omap_dmm->dev, "END TILER MAP\n"); 927 dev_dbg(omap_dmm->dev, "%03d:%s\n", i, map[i]);
928 dev_dbg(omap_dmm->dev, "CONTAINER %d DUMP END\n",
929 lut_idx);
930 }
896 } 931 }
897 932
898error: 933error:
@@ -903,12 +938,45 @@ error:
903} 938}
904#endif 939#endif
905 940
941#ifdef CONFIG_PM
942static int omap_dmm_resume(struct device *dev)
943{
944 struct tcm_area area;
945 int i;
946
947 if (!omap_dmm)
948 return -ENODEV;
949
950 area = (struct tcm_area) {
951 .tcm = NULL,
952 .p1.x = omap_dmm->container_width - 1,
953 .p1.y = omap_dmm->container_height - 1,
954 };
955
956 /* initialize all LUTs to dummy page entries */
957 for (i = 0; i < omap_dmm->num_lut; i++) {
958 area.tcm = omap_dmm->tcm[i];
959 if (fill(&area, NULL, 0, 0, true))
960 dev_err(dev, "refill failed");
961 }
962
963 return 0;
964}
965
966static const struct dev_pm_ops omap_dmm_pm_ops = {
967 .resume = omap_dmm_resume,
968};
969#endif
970
906struct platform_driver omap_dmm_driver = { 971struct platform_driver omap_dmm_driver = {
907 .probe = omap_dmm_probe, 972 .probe = omap_dmm_probe,
908 .remove = omap_dmm_remove, 973 .remove = omap_dmm_remove,
909 .driver = { 974 .driver = {
910 .owner = THIS_MODULE, 975 .owner = THIS_MODULE,
911 .name = DMM_DRIVER_NAME, 976 .name = DMM_DRIVER_NAME,
977#ifdef CONFIG_PM
978 .pm = &omap_dmm_pm_ops,
979#endif
912 }, 980 },
913}; 981};
914 982
diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c
index ae5ecc2efbc7..480dc343446c 100644
--- a/drivers/staging/omapdrm/omap_drv.c
+++ b/drivers/staging/omapdrm/omap_drv.c
@@ -335,10 +335,8 @@ static int dev_load(struct drm_device *dev, unsigned long flags)
335 DBG("load: dev=%p", dev); 335 DBG("load: dev=%p", dev);
336 336
337 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 337 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
338 if (!priv) { 338 if (!priv)
339 dev_err(dev->dev, "could not allocate priv\n");
340 return -ENOMEM; 339 return -ENOMEM;
341 }
342 340
343 priv->omaprev = pdata->omaprev; 341 priv->omaprev = pdata->omaprev;
344 342
@@ -368,6 +366,9 @@ static int dev_load(struct drm_device *dev, unsigned long flags)
368 /* well, limp along without an fbdev.. maybe X11 will work? */ 366 /* well, limp along without an fbdev.. maybe X11 will work? */
369 } 367 }
370 368
369 /* store off drm_device for use in pm ops */
370 dev_set_drvdata(dev->dev, dev);
371
371 drm_kms_helper_poll_init(dev); 372 drm_kms_helper_poll_init(dev);
372 373
373 return 0; 374 return 0;
@@ -393,6 +394,8 @@ static int dev_unload(struct drm_device *dev)
393 kfree(dev->dev_private); 394 kfree(dev->dev_private);
394 dev->dev_private = NULL; 395 dev->dev_private = NULL;
395 396
397 dev_set_drvdata(dev->dev, NULL);
398
396 return 0; 399 return 0;
397} 400}
398 401
@@ -558,10 +561,19 @@ static int pdev_remove(struct platform_device *device)
558 return 0; 561 return 0;
559} 562}
560 563
564#ifdef CONFIG_PM
565static const struct dev_pm_ops omapdrm_pm_ops = {
566 .resume = omap_gem_resume,
567};
568#endif
569
561struct platform_driver pdev = { 570struct platform_driver pdev = {
562 .driver = { 571 .driver = {
563 .name = DRIVER_NAME, 572 .name = DRIVER_NAME,
564 .owner = THIS_MODULE, 573 .owner = THIS_MODULE,
574#ifdef CONFIG_PM
575 .pm = &omapdrm_pm_ops,
576#endif
565 }, 577 },
566 .probe = pdev_probe, 578 .probe = pdev_probe,
567 .remove = pdev_remove, 579 .remove = pdev_remove,
diff --git a/drivers/staging/omapdrm/omap_drv.h b/drivers/staging/omapdrm/omap_drv.h
index cd1f22b0b124..f921027e7500 100644
--- a/drivers/staging/omapdrm/omap_drv.h
+++ b/drivers/staging/omapdrm/omap_drv.h
@@ -135,6 +135,10 @@ void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
135void omap_gem_describe_objects(struct list_head *list, struct seq_file *m); 135void omap_gem_describe_objects(struct list_head *list, struct seq_file *m);
136#endif 136#endif
137 137
138#ifdef CONFIG_PM
139int omap_gem_resume(struct device *dev);
140#endif
141
138int omap_irq_enable_vblank(struct drm_device *dev, int crtc); 142int omap_irq_enable_vblank(struct drm_device *dev, int crtc);
139void omap_irq_disable_vblank(struct drm_device *dev, int crtc); 143void omap_irq_disable_vblank(struct drm_device *dev, int crtc);
140irqreturn_t omap_irq_handler(DRM_IRQ_ARGS); 144irqreturn_t omap_irq_handler(DRM_IRQ_ARGS);
diff --git a/drivers/staging/omapdrm/omap_encoder.c b/drivers/staging/omapdrm/omap_encoder.c
index e053160d2db3..25fc0c7b4f6d 100644
--- a/drivers/staging/omapdrm/omap_encoder.c
+++ b/drivers/staging/omapdrm/omap_encoder.c
@@ -147,10 +147,8 @@ struct drm_encoder *omap_encoder_init(struct drm_device *dev,
147 struct omap_encoder *omap_encoder; 147 struct omap_encoder *omap_encoder;
148 148
149 omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL); 149 omap_encoder = kzalloc(sizeof(*omap_encoder), GFP_KERNEL);
150 if (!omap_encoder) { 150 if (!omap_encoder)
151 dev_err(dev->dev, "could not allocate encoder\n");
152 goto fail; 151 goto fail;
153 }
154 152
155 omap_encoder->dssdev = dssdev; 153 omap_encoder->dssdev = dssdev;
156 154
diff --git a/drivers/staging/omapdrm/omap_fb.c b/drivers/staging/omapdrm/omap_fb.c
index 09028e9c1093..bb4969942148 100644
--- a/drivers/staging/omapdrm/omap_fb.c
+++ b/drivers/staging/omapdrm/omap_fb.c
@@ -418,7 +418,6 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,
418 418
419 omap_fb = kzalloc(sizeof(*omap_fb), GFP_KERNEL); 419 omap_fb = kzalloc(sizeof(*omap_fb), GFP_KERNEL);
420 if (!omap_fb) { 420 if (!omap_fb) {
421 dev_err(dev->dev, "could not allocate fb\n");
422 ret = -ENOMEM; 421 ret = -ENOMEM;
423 goto fail; 422 goto fail;
424 } 423 }
diff --git a/drivers/staging/omapdrm/omap_fbdev.c b/drivers/staging/omapdrm/omap_fbdev.c
index 8a027bb77d97..70f2d6ed2ed3 100644
--- a/drivers/staging/omapdrm/omap_fbdev.c
+++ b/drivers/staging/omapdrm/omap_fbdev.c
@@ -348,10 +348,8 @@ struct drm_fb_helper *omap_fbdev_init(struct drm_device *dev)
348 int ret = 0; 348 int ret = 0;
349 349
350 fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); 350 fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL);
351 if (!fbdev) { 351 if (!fbdev)
352 dev_err(dev->dev, "could not allocate fbdev\n");
353 goto fail; 352 goto fail;
354 }
355 353
356 INIT_WORK(&fbdev->work, pan_worker); 354 INIT_WORK(&fbdev->work, pan_worker);
357 355
diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c
index c38992b76fc9..518d03d4d4f3 100644
--- a/drivers/staging/omapdrm/omap_gem.c
+++ b/drivers/staging/omapdrm/omap_gem.c
@@ -964,6 +964,34 @@ void *omap_gem_vaddr(struct drm_gem_object *obj)
964 return omap_obj->vaddr; 964 return omap_obj->vaddr;
965} 965}
966 966
967#ifdef CONFIG_PM
968/* re-pin objects in DMM in resume path: */
969int omap_gem_resume(struct device *dev)
970{
971 struct drm_device *drm_dev = dev_get_drvdata(dev);
972 struct omap_drm_private *priv = drm_dev->dev_private;
973 struct omap_gem_object *omap_obj;
974 int ret = 0;
975
976 list_for_each_entry(omap_obj, &priv->obj_list, mm_list) {
977 if (omap_obj->block) {
978 struct drm_gem_object *obj = &omap_obj->base;
979 uint32_t npages = obj->size >> PAGE_SHIFT;
980 WARN_ON(!omap_obj->pages); /* this can't happen */
981 ret = tiler_pin(omap_obj->block,
982 omap_obj->pages, npages,
983 omap_obj->roll, true);
984 if (ret) {
985 dev_err(dev, "could not repin: %d\n", ret);
986 return ret;
987 }
988 }
989 }
990
991 return 0;
992}
993#endif
994
967#ifdef CONFIG_DEBUG_FS 995#ifdef CONFIG_DEBUG_FS
968void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m) 996void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m)
969{ 997{
@@ -1239,12 +1267,12 @@ int omap_gem_set_sync_object(struct drm_gem_object *obj, void *syncobj)
1239 1267
1240 if ((omap_obj->flags & OMAP_BO_EXT_SYNC) && !syncobj) { 1268 if ((omap_obj->flags & OMAP_BO_EXT_SYNC) && !syncobj) {
1241 /* clearing a previously set syncobj */ 1269 /* clearing a previously set syncobj */
1242 syncobj = kzalloc(sizeof(*omap_obj->sync), GFP_ATOMIC); 1270 syncobj = kmemdup(omap_obj->sync, sizeof(*omap_obj->sync),
1271 GFP_ATOMIC);
1243 if (!syncobj) { 1272 if (!syncobj) {
1244 ret = -ENOMEM; 1273 ret = -ENOMEM;
1245 goto unlock; 1274 goto unlock;
1246 } 1275 }
1247 memcpy(syncobj, omap_obj->sync, sizeof(*omap_obj->sync));
1248 omap_obj->flags &= ~OMAP_BO_EXT_SYNC; 1276 omap_obj->flags &= ~OMAP_BO_EXT_SYNC;
1249 omap_obj->sync = syncobj; 1277 omap_obj->sync = syncobj;
1250 } else if (syncobj && !(omap_obj->flags & OMAP_BO_EXT_SYNC)) { 1278 } else if (syncobj && !(omap_obj->flags & OMAP_BO_EXT_SYNC)) {
@@ -1374,10 +1402,8 @@ struct drm_gem_object *omap_gem_new(struct drm_device *dev,
1374 } 1402 }
1375 1403
1376 omap_obj = kzalloc(sizeof(*omap_obj), GFP_KERNEL); 1404 omap_obj = kzalloc(sizeof(*omap_obj), GFP_KERNEL);
1377 if (!omap_obj) { 1405 if (!omap_obj)
1378 dev_err(dev->dev, "could not allocate GEM object\n");
1379 goto fail; 1406 goto fail;
1380 }
1381 1407
1382 list_add(&omap_obj->mm_list, &priv->obj_list); 1408 list_add(&omap_obj->mm_list, &priv->obj_list);
1383 1409
@@ -1433,11 +1459,9 @@ void omap_gem_init(struct drm_device *dev)
1433 return; 1459 return;
1434 } 1460 }
1435 1461
1436 usergart = kzalloc(3 * sizeof(*usergart), GFP_KERNEL); 1462 usergart = kcalloc(3, sizeof(*usergart), GFP_KERNEL);
1437 if (!usergart) { 1463 if (!usergart)
1438 dev_warn(dev->dev, "could not allocate usergart\n");
1439 return; 1464 return;
1440 }
1441 1465
1442 /* reserve 4k aligned/wide regions for userspace mappings: */ 1466 /* reserve 4k aligned/wide regions for userspace mappings: */
1443 for (i = 0; i < ARRAY_SIZE(fmts); i++) { 1467 for (i = 0; i < ARRAY_SIZE(fmts); i++) {
diff --git a/drivers/staging/omapdrm/omap_gem_dmabuf.c b/drivers/staging/omapdrm/omap_gem_dmabuf.c
index b6c5b5c6c8c5..a3236abfca3d 100644
--- a/drivers/staging/omapdrm/omap_gem_dmabuf.c
+++ b/drivers/staging/omapdrm/omap_gem_dmabuf.c
@@ -53,10 +53,10 @@ static struct sg_table *omap_gem_map_dma_buf(
53 /* this should be after _get_paddr() to ensure we have pages attached */ 53 /* this should be after _get_paddr() to ensure we have pages attached */
54 omap_gem_dma_sync(obj, dir); 54 omap_gem_dma_sync(obj, dir);
55 55
56out:
57 if (ret)
58 return ERR_PTR(ret);
59 return sg; 56 return sg;
57out:
58 kfree(sg);
59 return ERR_PTR(ret);
60} 60}
61 61
62static void omap_gem_unmap_dma_buf(struct dma_buf_attachment *attachment, 62static void omap_gem_unmap_dma_buf(struct dma_buf_attachment *attachment,
diff --git a/drivers/staging/omapdrm/omap_plane.c b/drivers/staging/omapdrm/omap_plane.c
index bb989d7f026d..c063476db3bb 100644
--- a/drivers/staging/omapdrm/omap_plane.c
+++ b/drivers/staging/omapdrm/omap_plane.c
@@ -390,10 +390,8 @@ struct drm_plane *omap_plane_init(struct drm_device *dev,
390 DBG("%s: priv=%d", plane_names[id], private_plane); 390 DBG("%s: priv=%d", plane_names[id], private_plane);
391 391
392 omap_plane = kzalloc(sizeof(*omap_plane), GFP_KERNEL); 392 omap_plane = kzalloc(sizeof(*omap_plane), GFP_KERNEL);
393 if (!omap_plane) { 393 if (!omap_plane)
394 dev_err(dev->dev, "could not allocate plane\n");
395 goto fail; 394 goto fail;
396 }
397 395
398 ret = kfifo_alloc(&omap_plane->unpin_fifo, 16, GFP_KERNEL); 396 ret = kfifo_alloc(&omap_plane->unpin_fifo, 16, GFP_KERNEL);
399 if (ret) { 397 if (ret) {
diff --git a/drivers/staging/omapdrm/tcm.h b/drivers/staging/omapdrm/tcm.h
index d273e3ee0b4c..a8d5ce47686f 100644
--- a/drivers/staging/omapdrm/tcm.h
+++ b/drivers/staging/omapdrm/tcm.h
@@ -59,6 +59,8 @@ struct tcm {
59 u16 width, height; /* container dimensions */ 59 u16 width, height; /* container dimensions */
60 int lut_id; /* Lookup table identifier */ 60 int lut_id; /* Lookup table identifier */
61 61
62 unsigned int y_offset; /* offset to use for y coordinates */
63
62 /* 'pvt' structure shall contain any tcm details (attr) along with 64 /* 'pvt' structure shall contain any tcm details (attr) along with
63 linked list of allocated areas and mutex for mutually exclusive access 65 linked list of allocated areas and mutex for mutually exclusive access
64 to the list. It may also contain copies of width and height to notice 66 to the list. It may also contain copies of width and height to notice
diff --git a/drivers/staging/ozwpan/TODO b/drivers/staging/ozwpan/TODO
index b5db2456bffa..b4febd79a68d 100644
--- a/drivers/staging/ozwpan/TODO
+++ b/drivers/staging/ozwpan/TODO
@@ -10,6 +10,5 @@ TODO:
10 - testing with as many devices as possible. 10 - testing with as many devices as possible.
11 11
12Please send any patches for this driver to 12Please send any patches for this driver to
13Rupesh Gujare <rgujare@ozmodevices.com> 13Rupesh Gujare <rupesh.gujare@atmel.com>
14Chris Kelly <ckelly@ozmodevices.com>
15and Greg Kroah-Hartman <gregkh@linuxfoundation.org>. 14and Greg Kroah-Hartman <gregkh@linuxfoundation.org>.
diff --git a/drivers/staging/ozwpan/ozcdev.c b/drivers/staging/ozwpan/ozcdev.c
index 64913aeb0bac..ba15aeb70672 100644
--- a/drivers/staging/ozwpan/ozcdev.c
+++ b/drivers/staging/ozwpan/ozcdev.c
@@ -19,6 +19,7 @@
19#include "ozpd.h" 19#include "ozpd.h"
20#include "ozproto.h" 20#include "ozproto.h"
21#include "ozevent.h" 21#include "ozevent.h"
22#include "ozcdev.h"
22/*------------------------------------------------------------------------------ 23/*------------------------------------------------------------------------------
23 */ 24 */
24#define OZ_RD_BUF_SZ 256 25#define OZ_RD_BUF_SZ 256
@@ -43,7 +44,7 @@ struct oz_serial_ctx {
43/*------------------------------------------------------------------------------ 44/*------------------------------------------------------------------------------
44 */ 45 */
45static struct oz_cdev g_cdev; 46static struct oz_cdev g_cdev;
46struct class *g_oz_class; 47static struct class *g_oz_class;
47/*------------------------------------------------------------------------------ 48/*------------------------------------------------------------------------------
48 * Context: process and softirq 49 * Context: process and softirq
49 */ 50 */
@@ -70,7 +71,7 @@ static void oz_cdev_release_ctx(struct oz_serial_ctx *ctx)
70/*------------------------------------------------------------------------------ 71/*------------------------------------------------------------------------------
71 * Context: process 72 * Context: process
72 */ 73 */
73int oz_cdev_open(struct inode *inode, struct file *filp) 74static int oz_cdev_open(struct inode *inode, struct file *filp)
74{ 75{
75 struct oz_cdev *dev; 76 struct oz_cdev *dev;
76 oz_trace("oz_cdev_open()\n"); 77 oz_trace("oz_cdev_open()\n");
@@ -82,7 +83,7 @@ int oz_cdev_open(struct inode *inode, struct file *filp)
82/*------------------------------------------------------------------------------ 83/*------------------------------------------------------------------------------
83 * Context: process 84 * Context: process
84 */ 85 */
85int oz_cdev_release(struct inode *inode, struct file *filp) 86static int oz_cdev_release(struct inode *inode, struct file *filp)
86{ 87{
87 oz_trace("oz_cdev_release()\n"); 88 oz_trace("oz_cdev_release()\n");
88 return 0; 89 return 0;
@@ -90,14 +91,14 @@ int oz_cdev_release(struct inode *inode, struct file *filp)
90/*------------------------------------------------------------------------------ 91/*------------------------------------------------------------------------------
91 * Context: process 92 * Context: process
92 */ 93 */
93ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count, 94static ssize_t oz_cdev_read(struct file *filp, char __user *buf, size_t count,
94 loff_t *fpos) 95 loff_t *fpos)
95{ 96{
96 int n; 97 int n;
97 int ix; 98 int ix;
98 99
99 struct oz_pd *pd; 100 struct oz_pd *pd;
100 struct oz_serial_ctx *ctx = 0; 101 struct oz_serial_ctx *ctx;
101 102
102 spin_lock_bh(&g_cdev.lock); 103 spin_lock_bh(&g_cdev.lock);
103 pd = g_cdev.active_pd; 104 pd = g_cdev.active_pd;
@@ -142,12 +143,12 @@ out2:
142/*------------------------------------------------------------------------------ 143/*------------------------------------------------------------------------------
143 * Context: process 144 * Context: process
144 */ 145 */
145ssize_t oz_cdev_write(struct file *filp, const char __user *buf, size_t count, 146static ssize_t oz_cdev_write(struct file *filp, const char __user *buf,
146 loff_t *fpos) 147 size_t count, loff_t *fpos)
147{ 148{
148 struct oz_pd *pd; 149 struct oz_pd *pd;
149 struct oz_elt_buf *eb; 150 struct oz_elt_buf *eb;
150 struct oz_elt_info *ei = 0; 151 struct oz_elt_info *ei;
151 struct oz_elt *elt; 152 struct oz_elt *elt;
152 struct oz_app_hdr *app_hdr; 153 struct oz_app_hdr *app_hdr;
153 struct oz_serial_ctx *ctx; 154 struct oz_serial_ctx *ctx;
@@ -182,7 +183,7 @@ ssize_t oz_cdev_write(struct file *filp, const char __user *buf, size_t count,
182 ctx->tx_seq_num = 1; 183 ctx->tx_seq_num = 1;
183 spin_lock(&eb->lock); 184 spin_lock(&eb->lock);
184 if (oz_queue_elt_info(eb, 0, 0, ei) == 0) 185 if (oz_queue_elt_info(eb, 0, 0, ei) == 0)
185 ei = 0; 186 ei = NULL;
186 spin_unlock(&eb->lock); 187 spin_unlock(&eb->lock);
187 } 188 }
188 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); 189 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
@@ -199,7 +200,7 @@ out:
199/*------------------------------------------------------------------------------ 200/*------------------------------------------------------------------------------
200 * Context: process 201 * Context: process
201 */ 202 */
202static int oz_set_active_pd(u8 *addr) 203static int oz_set_active_pd(const u8 *addr)
203{ 204{
204 int rc = 0; 205 int rc = 0;
205 struct oz_pd *pd; 206 struct oz_pd *pd;
@@ -217,7 +218,7 @@ static int oz_set_active_pd(u8 *addr)
217 if (is_zero_ether_addr(addr)) { 218 if (is_zero_ether_addr(addr)) {
218 spin_lock_bh(&g_cdev.lock); 219 spin_lock_bh(&g_cdev.lock);
219 pd = g_cdev.active_pd; 220 pd = g_cdev.active_pd;
220 g_cdev.active_pd = 0; 221 g_cdev.active_pd = NULL;
221 memset(g_cdev.active_addr, 0, 222 memset(g_cdev.active_addr, 0,
222 sizeof(g_cdev.active_addr)); 223 sizeof(g_cdev.active_addr));
223 spin_unlock_bh(&g_cdev.lock); 224 spin_unlock_bh(&g_cdev.lock);
@@ -232,7 +233,8 @@ static int oz_set_active_pd(u8 *addr)
232/*------------------------------------------------------------------------------ 233/*------------------------------------------------------------------------------
233 * Context: process 234 * Context: process
234 */ 235 */
235long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 236static long oz_cdev_ioctl(struct file *filp, unsigned int cmd,
237 unsigned long arg)
236{ 238{
237 int rc = 0; 239 int rc = 0;
238 if (_IOC_TYPE(cmd) != OZ_IOCTL_MAGIC) 240 if (_IOC_TYPE(cmd) != OZ_IOCTL_MAGIC)
@@ -296,7 +298,7 @@ long oz_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
296/*------------------------------------------------------------------------------ 298/*------------------------------------------------------------------------------
297 * Context: process 299 * Context: process
298 */ 300 */
299unsigned int oz_cdev_poll(struct file *filp, poll_table *wait) 301static unsigned int oz_cdev_poll(struct file *filp, poll_table *wait)
300{ 302{
301 unsigned int ret = 0; 303 unsigned int ret = 0;
302 struct oz_cdev *dev = filp->private_data; 304 struct oz_cdev *dev = filp->private_data;
@@ -317,7 +319,7 @@ unsigned int oz_cdev_poll(struct file *filp, poll_table *wait)
317} 319}
318/*------------------------------------------------------------------------------ 320/*------------------------------------------------------------------------------
319 */ 321 */
320const struct file_operations oz_fops = { 322static const struct file_operations oz_fops = {
321 .owner = THIS_MODULE, 323 .owner = THIS_MODULE,
322 .open = oz_cdev_open, 324 .open = oz_cdev_open,
323 .release = oz_cdev_release, 325 .release = oz_cdev_release,
@@ -385,7 +387,7 @@ int oz_cdev_deregister(void)
385 */ 387 */
386int oz_cdev_init(void) 388int oz_cdev_init(void)
387{ 389{
388 oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_SERIAL, 0, 0); 390 oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_SERIAL, NULL, 0);
389 oz_app_enable(OZ_APPID_SERIAL, 1); 391 oz_app_enable(OZ_APPID_SERIAL, 1);
390 return 0; 392 return 0;
391} 393}
@@ -394,7 +396,7 @@ int oz_cdev_init(void)
394 */ 396 */
395void oz_cdev_term(void) 397void oz_cdev_term(void)
396{ 398{
397 oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_SERIAL, 0, 0); 399 oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_SERIAL, NULL, 0);
398 oz_app_enable(OZ_APPID_SERIAL, 0); 400 oz_app_enable(OZ_APPID_SERIAL, 0);
399} 401}
400/*------------------------------------------------------------------------------ 402/*------------------------------------------------------------------------------
@@ -403,8 +405,8 @@ void oz_cdev_term(void)
403int oz_cdev_start(struct oz_pd *pd, int resume) 405int oz_cdev_start(struct oz_pd *pd, int resume)
404{ 406{
405 struct oz_serial_ctx *ctx; 407 struct oz_serial_ctx *ctx;
406 struct oz_serial_ctx *old_ctx = 0; 408 struct oz_serial_ctx *old_ctx;
407 oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_SERIAL, 0, resume); 409 oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_SERIAL, NULL, resume);
408 if (resume) { 410 if (resume) {
409 oz_trace("Serial service resumed.\n"); 411 oz_trace("Serial service resumed.\n");
410 return 0; 412 return 0;
@@ -440,22 +442,22 @@ int oz_cdev_start(struct oz_pd *pd, int resume)
440void oz_cdev_stop(struct oz_pd *pd, int pause) 442void oz_cdev_stop(struct oz_pd *pd, int pause)
441{ 443{
442 struct oz_serial_ctx *ctx; 444 struct oz_serial_ctx *ctx;
443 oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_SERIAL, 0, pause); 445 oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_SERIAL, NULL, pause);
444 if (pause) { 446 if (pause) {
445 oz_trace("Serial service paused.\n"); 447 oz_trace("Serial service paused.\n");
446 return; 448 return;
447 } 449 }
448 spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); 450 spin_lock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]);
449 ctx = (struct oz_serial_ctx *)pd->app_ctx[OZ_APPID_SERIAL-1]; 451 ctx = (struct oz_serial_ctx *)pd->app_ctx[OZ_APPID_SERIAL-1];
450 pd->app_ctx[OZ_APPID_SERIAL-1] = 0; 452 pd->app_ctx[OZ_APPID_SERIAL-1] = NULL;
451 spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]); 453 spin_unlock_bh(&pd->app_lock[OZ_APPID_SERIAL-1]);
452 if (ctx) 454 if (ctx)
453 oz_cdev_release_ctx(ctx); 455 oz_cdev_release_ctx(ctx);
454 spin_lock(&g_cdev.lock); 456 spin_lock(&g_cdev.lock);
455 if (pd == g_cdev.active_pd) 457 if (pd == g_cdev.active_pd)
456 g_cdev.active_pd = 0; 458 g_cdev.active_pd = NULL;
457 else 459 else
458 pd = 0; 460 pd = NULL;
459 spin_unlock(&g_cdev.lock); 461 spin_unlock(&g_cdev.lock);
460 if (pd) { 462 if (pd) {
461 oz_pd_put(pd); 463 oz_pd_put(pd);
@@ -523,9 +525,3 @@ void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt)
523out: 525out:
524 oz_cdev_release_ctx(ctx); 526 oz_cdev_release_ctx(ctx);
525} 527}
526/*------------------------------------------------------------------------------
527 * Context: softirq
528 */
529void oz_cdev_heartbeat(struct oz_pd *pd)
530{
531}
diff --git a/drivers/staging/ozwpan/ozcdev.h b/drivers/staging/ozwpan/ozcdev.h
index 698014bb8d72..dd11935a093f 100644
--- a/drivers/staging/ozwpan/ozcdev.h
+++ b/drivers/staging/ozwpan/ozcdev.h
@@ -13,6 +13,5 @@ void oz_cdev_term(void);
13int oz_cdev_start(struct oz_pd *pd, int resume); 13int oz_cdev_start(struct oz_pd *pd, int resume);
14void oz_cdev_stop(struct oz_pd *pd, int pause); 14void oz_cdev_stop(struct oz_pd *pd, int pause);
15void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt); 15void oz_cdev_rx(struct oz_pd *pd, struct oz_elt *elt);
16void oz_cdev_heartbeat(struct oz_pd *pd);
17 16
18#endif /* _OZCDEV_H */ 17#endif /* _OZCDEV_H */
diff --git a/drivers/staging/ozwpan/ozeltbuf.c b/drivers/staging/ozwpan/ozeltbuf.c
index 988f522475d9..ac90fc7f5441 100644
--- a/drivers/staging/ozwpan/ozeltbuf.c
+++ b/drivers/staging/ozwpan/ozeltbuf.c
@@ -64,7 +64,7 @@ void oz_elt_buf_term(struct oz_elt_buf *buf)
64 */ 64 */
65struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf) 65struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf)
66{ 66{
67 struct oz_elt_info *ei = 0; 67 struct oz_elt_info *ei = NULL;
68 spin_lock_bh(&buf->lock); 68 spin_lock_bh(&buf->lock);
69 if (buf->free_elts && buf->elt_pool) { 69 if (buf->free_elts && buf->elt_pool) {
70 ei = container_of(buf->elt_pool, struct oz_elt_info, link); 70 ei = container_of(buf->elt_pool, struct oz_elt_info, link);
@@ -82,9 +82,9 @@ struct oz_elt_info *oz_elt_info_alloc(struct oz_elt_buf *buf)
82 if (ei) { 82 if (ei) {
83 ei->flags = 0; 83 ei->flags = 0;
84 ei->app_id = 0; 84 ei->app_id = 0;
85 ei->callback = 0; 85 ei->callback = NULL;
86 ei->context = 0; 86 ei->context = 0;
87 ei->stream = 0; 87 ei->stream = NULL;
88 ei->magic = OZ_ELT_INFO_MAGIC_USED; 88 ei->magic = OZ_ELT_INFO_MAGIC_USED;
89 INIT_LIST_HEAD(&ei->link); 89 INIT_LIST_HEAD(&ei->link);
90 INIT_LIST_HEAD(&ei->link_order); 90 INIT_LIST_HEAD(&ei->link_order);
@@ -135,7 +135,7 @@ int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count)
135 oz_trace("oz_elt_stream_create(0x%x)\n", id); 135 oz_trace("oz_elt_stream_create(0x%x)\n", id);
136 136
137 st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC | __GFP_ZERO); 137 st = kzalloc(sizeof(struct oz_elt_stream), GFP_ATOMIC | __GFP_ZERO);
138 if (st == 0) 138 if (st == NULL)
139 return -ENOMEM; 139 return -ENOMEM;
140 atomic_set(&st->ref_count, 1); 140 atomic_set(&st->ref_count, 1);
141 st->id = id; 141 st->id = id;
@@ -151,7 +151,7 @@ int oz_elt_stream_create(struct oz_elt_buf *buf, u8 id, int max_buf_count)
151int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id) 151int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id)
152{ 152{
153 struct list_head *e; 153 struct list_head *e;
154 struct oz_elt_stream *st; 154 struct oz_elt_stream *st = NULL;
155 oz_trace("oz_elt_stream_delete(0x%x)\n", id); 155 oz_trace("oz_elt_stream_delete(0x%x)\n", id);
156 spin_lock_bh(&buf->lock); 156 spin_lock_bh(&buf->lock);
157 e = buf->stream_list.next; 157 e = buf->stream_list.next;
@@ -161,7 +161,7 @@ int oz_elt_stream_delete(struct oz_elt_buf *buf, u8 id)
161 list_del(e); 161 list_del(e);
162 break; 162 break;
163 } 163 }
164 st = 0; 164 st = NULL;
165 } 165 }
166 if (!st) { 166 if (!st) {
167 spin_unlock_bh(&buf->lock); 167 spin_unlock_bh(&buf->lock);
@@ -208,7 +208,7 @@ void oz_elt_stream_put(struct oz_elt_stream *st)
208int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id, 208int oz_queue_elt_info(struct oz_elt_buf *buf, u8 isoc, u8 id,
209 struct oz_elt_info *ei) 209 struct oz_elt_info *ei)
210{ 210{
211 struct oz_elt_stream *st = 0; 211 struct oz_elt_stream *st = NULL;
212 struct list_head *e; 212 struct list_head *e;
213 if (id) { 213 if (id) {
214 list_for_each(e, &buf->stream_list) { 214 list_for_each(e, &buf->stream_list) {
@@ -297,7 +297,7 @@ int oz_select_elts_for_tx(struct oz_elt_buf *buf, u8 isoc, unsigned *len,
297 "Stream down: %d %d\n", 297 "Stream down: %d %d\n",
298 ei->stream->buf_count, ei->length); 298 ei->stream->buf_count, ei->length);
299 oz_elt_stream_put(ei->stream); 299 oz_elt_stream_put(ei->stream);
300 ei->stream = 0; 300 ei->stream = NULL;
301 } 301 }
302 INIT_LIST_HEAD(&ei->link_order); 302 INIT_LIST_HEAD(&ei->link_order);
303 list_add_tail(&ei->link, list); 303 list_add_tail(&ei->link, list);
@@ -319,7 +319,7 @@ int oz_are_elts_available(struct oz_elt_buf *buf)
319 */ 319 */
320void oz_trim_elt_pool(struct oz_elt_buf *buf) 320void oz_trim_elt_pool(struct oz_elt_buf *buf)
321{ 321{
322 struct list_head *free = 0; 322 struct list_head *free = NULL;
323 struct list_head *e; 323 struct list_head *e;
324 spin_lock_bh(&buf->lock); 324 spin_lock_bh(&buf->lock);
325 while (buf->free_elts > buf->max_free_elts) { 325 while (buf->free_elts > buf->max_free_elts) {
diff --git a/drivers/staging/ozwpan/ozevent.c b/drivers/staging/ozwpan/ozevent.c
index 50578ba0061c..77e86753610d 100644
--- a/drivers/staging/ozwpan/ozevent.c
+++ b/drivers/staging/ozwpan/ozevent.c
@@ -92,7 +92,7 @@ static void oz_events_clear(struct oz_evtdev *dev)
92/*------------------------------------------------------------------------------ 92/*------------------------------------------------------------------------------
93 * Context: process 93 * Context: process
94 */ 94 */
95int oz_events_open(struct inode *inode, struct file *filp) 95static int oz_events_open(struct inode *inode, struct file *filp)
96{ 96{
97 oz_trace("oz_evt_open()\n"); 97 oz_trace("oz_evt_open()\n");
98 oz_trace("Open flags: 0x%x\n", filp->f_flags); 98 oz_trace("Open flags: 0x%x\n", filp->f_flags);
@@ -107,7 +107,7 @@ int oz_events_open(struct inode *inode, struct file *filp)
107/*------------------------------------------------------------------------------ 107/*------------------------------------------------------------------------------
108 * Context: process 108 * Context: process
109 */ 109 */
110int oz_events_release(struct inode *inode, struct file *filp) 110static int oz_events_release(struct inode *inode, struct file *filp)
111{ 111{
112 oz_events_clear(&g_evtdev); 112 oz_events_clear(&g_evtdev);
113 atomic_dec(&g_evtdev.users); 113 atomic_dec(&g_evtdev.users);
@@ -118,7 +118,7 @@ int oz_events_release(struct inode *inode, struct file *filp)
118/*------------------------------------------------------------------------------ 118/*------------------------------------------------------------------------------
119 * Context: process 119 * Context: process
120 */ 120 */
121ssize_t oz_events_read(struct file *filp, char __user *buf, size_t count, 121static ssize_t oz_events_read(struct file *filp, char __user *buf, size_t count,
122 loff_t *fpos) 122 loff_t *fpos)
123{ 123{
124 struct oz_evtdev *dev = &g_evtdev; 124 struct oz_evtdev *dev = &g_evtdev;
@@ -157,7 +157,7 @@ out:
157} 157}
158/*------------------------------------------------------------------------------ 158/*------------------------------------------------------------------------------
159 */ 159 */
160const struct file_operations oz_events_fops = { 160static const struct file_operations oz_events_fops = {
161 .owner = THIS_MODULE, 161 .owner = THIS_MODULE,
162 .open = oz_events_open, 162 .open = oz_events_open,
163 .release = oz_events_release, 163 .release = oz_events_release,
diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c
index b2d77df2a526..8ac26f584fd4 100644
--- a/drivers/staging/ozwpan/ozhcd.c
+++ b/drivers/staging/ozwpan/ozhcd.c
@@ -36,6 +36,7 @@
36#include "oztrace.h" 36#include "oztrace.h"
37#include "ozurbparanoia.h" 37#include "ozurbparanoia.h"
38#include "ozevent.h" 38#include "ozevent.h"
39#include "ozhcd.h"
39/*------------------------------------------------------------------------------ 40/*------------------------------------------------------------------------------
40 * Number of units of buffering to capture for an isochronous IN endpoint before 41 * Number of units of buffering to capture for an isochronous IN endpoint before
41 * allowing data to be indicated up. 42 * allowing data to be indicated up.
@@ -248,7 +249,7 @@ static int oz_get_port_from_addr(struct oz_hcd *ozhcd, u8 bus_addr)
248 */ 249 */
249static struct oz_urb_link *oz_alloc_urb_link(void) 250static struct oz_urb_link *oz_alloc_urb_link(void)
250{ 251{
251 struct oz_urb_link *urbl = 0; 252 struct oz_urb_link *urbl = NULL;
252 unsigned long irq_state; 253 unsigned long irq_state;
253 spin_lock_irqsave(&g_link_lock, irq_state); 254 spin_lock_irqsave(&g_link_lock, irq_state);
254 if (g_link_pool) { 255 if (g_link_pool) {
@@ -257,7 +258,7 @@ static struct oz_urb_link *oz_alloc_urb_link(void)
257 --g_link_pool_size; 258 --g_link_pool_size;
258 } 259 }
259 spin_unlock_irqrestore(&g_link_lock, irq_state); 260 spin_unlock_irqrestore(&g_link_lock, irq_state);
260 if (urbl == 0) 261 if (urbl == NULL)
261 urbl = kmalloc(sizeof(struct oz_urb_link), GFP_ATOMIC); 262 urbl = kmalloc(sizeof(struct oz_urb_link), GFP_ATOMIC);
262 return urbl; 263 return urbl;
263} 264}
@@ -274,7 +275,7 @@ static void oz_free_urb_link(struct oz_urb_link *urbl)
274 if (g_link_pool_size < OZ_MAX_LINK_POOL_SIZE) { 275 if (g_link_pool_size < OZ_MAX_LINK_POOL_SIZE) {
275 urbl->link.next = g_link_pool; 276 urbl->link.next = g_link_pool;
276 g_link_pool = &urbl->link; 277 g_link_pool = &urbl->link;
277 urbl = 0; 278 urbl = NULL;
278 g_link_pool_size++; 279 g_link_pool_size++;
279 } 280 }
280 spin_unlock_irqrestore(&g_link_lock, irq_state); 281 spin_unlock_irqrestore(&g_link_lock, irq_state);
@@ -291,7 +292,7 @@ static void oz_empty_link_pool(void)
291 unsigned long irq_state; 292 unsigned long irq_state;
292 spin_lock_irqsave(&g_link_lock, irq_state); 293 spin_lock_irqsave(&g_link_lock, irq_state);
293 e = g_link_pool; 294 e = g_link_pool;
294 g_link_pool = 0; 295 g_link_pool = NULL;
295 g_link_pool_size = 0; 296 g_link_pool_size = 0;
296 spin_unlock_irqrestore(&g_link_lock, irq_state); 297 spin_unlock_irqrestore(&g_link_lock, irq_state);
297 while (e) { 298 while (e) {
@@ -326,7 +327,7 @@ static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size)
326 * disabled. 327 * disabled.
327 * Context: softirq or process 328 * Context: softirq or process
328 */ 329 */
329struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb) 330static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb)
330{ 331{
331 struct oz_urb_link *urbl; 332 struct oz_urb_link *urbl;
332 struct list_head *e; 333 struct list_head *e;
@@ -337,7 +338,7 @@ struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb)
337 return urbl; 338 return urbl;
338 } 339 }
339 } 340 }
340 return 0; 341 return NULL;
341} 342}
342/*------------------------------------------------------------------------------ 343/*------------------------------------------------------------------------------
343 * This is called when we have finished processing an urb. It unlinks it from 344 * This is called when we have finished processing an urb. It unlinks it from
@@ -349,13 +350,13 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb,
349{ 350{
350 struct oz_hcd *ozhcd = oz_hcd_private(hcd); 351 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
351 unsigned long irq_state; 352 unsigned long irq_state;
352 struct oz_urb_link *cancel_urbl = 0; 353 struct oz_urb_link *cancel_urbl = NULL;
353 spin_lock_irqsave(&g_tasklet_lock, irq_state); 354 spin_lock_irqsave(&g_tasklet_lock, irq_state);
354 usb_hcd_unlink_urb_from_ep(hcd, urb); 355 usb_hcd_unlink_urb_from_ep(hcd, urb);
355 /* Clear hcpriv which will prevent it being put in the cancel list 356 /* Clear hcpriv which will prevent it being put in the cancel list
356 * in the event that an attempt is made to cancel it. 357 * in the event that an attempt is made to cancel it.
357 */ 358 */
358 urb->hcpriv = 0; 359 urb->hcpriv = NULL;
359 /* Walk the cancel list in case the urb is already sitting there. 360 /* Walk the cancel list in case the urb is already sitting there.
360 * Since we process the cancel list in a tasklet rather than in 361 * Since we process the cancel list in a tasklet rather than in
361 * the dequeue function this could happen. 362 * the dequeue function this could happen.
@@ -416,7 +417,8 @@ static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep)
416/*------------------------------------------------------------------------------ 417/*------------------------------------------------------------------------------
417 * Context: softirq 418 * Context: softirq
418 */ 419 */
419void oz_complete_buffered_urb(struct oz_port *port, struct oz_endpoint *ep, 420static void oz_complete_buffered_urb(struct oz_port *port,
421 struct oz_endpoint *ep,
420 struct urb *urb) 422 struct urb *urb)
421{ 423{
422 u8 data_len, available_space, copy_len; 424 u8 data_len, available_space, copy_len;
@@ -507,7 +509,7 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
507 ep->last_jiffies = jiffies; 509 ep->last_jiffies = jiffies;
508 ep->credit = 0; 510 ep->credit = 0;
509 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 511 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num,
510 0, 0, ep->credit); 512 0, NULL, ep->credit);
511 } 513 }
512 } else { 514 } else {
513 err = -EPIPE; 515 err = -EPIPE;
@@ -525,7 +527,7 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
525static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, 527static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
526 struct urb *urb) 528 struct urb *urb)
527{ 529{
528 struct oz_urb_link *urbl = 0; 530 struct oz_urb_link *urbl = NULL;
529 struct oz_endpoint *ep; 531 struct oz_endpoint *ep;
530 spin_lock_bh(&port->ozhcd->hcd_lock); 532 spin_lock_bh(&port->ozhcd->hcd_lock);
531 if (in_dir) 533 if (in_dir)
@@ -540,7 +542,7 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
540 list_del_init(e); 542 list_del_init(e);
541 break; 543 break;
542 } 544 }
543 urbl = 0; 545 urbl = NULL;
544 } 546 }
545 } 547 }
546 spin_unlock_bh(&port->ozhcd->hcd_lock); 548 spin_unlock_bh(&port->ozhcd->hcd_lock);
@@ -556,8 +558,8 @@ static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix,
556 u8 req_id) 558 u8 req_id)
557{ 559{
558 struct oz_hcd *ozhcd = port->ozhcd; 560 struct oz_hcd *ozhcd = port->ozhcd;
559 struct urb *urb = 0; 561 struct urb *urb = NULL;
560 struct oz_urb_link *urbl = 0; 562 struct oz_urb_link *urbl = NULL;
561 struct oz_endpoint *ep; 563 struct oz_endpoint *ep;
562 564
563 spin_lock_bh(&ozhcd->hcd_lock); 565 spin_lock_bh(&ozhcd->hcd_lock);
@@ -630,13 +632,13 @@ static inline void oz_hcd_put(struct oz_hcd *ozhcd)
630void *oz_hcd_pd_arrived(void *hpd) 632void *oz_hcd_pd_arrived(void *hpd)
631{ 633{
632 int i; 634 int i;
633 void *hport = 0; 635 void *hport = NULL;
634 struct oz_hcd *ozhcd = 0; 636 struct oz_hcd *ozhcd = NULL;
635 struct oz_endpoint *ep; 637 struct oz_endpoint *ep;
636 oz_trace("oz_hcd_pd_arrived()\n"); 638 oz_trace("oz_hcd_pd_arrived()\n");
637 ozhcd = oz_hcd_claim(); 639 ozhcd = oz_hcd_claim();
638 if (ozhcd == 0) 640 if (ozhcd == NULL)
639 return 0; 641 return NULL;
640 /* Allocate an endpoint object in advance (before holding hcd lock) to 642 /* Allocate an endpoint object in advance (before holding hcd lock) to
641 * use for out endpoint 0. 643 * use for out endpoint 0.
642 */ 644 */
@@ -663,7 +665,7 @@ void *oz_hcd_pd_arrived(void *hpd)
663 /* Attach out endpoint 0. 665 /* Attach out endpoint 0.
664 */ 666 */
665 ozhcd->ports[i].out_ep[0] = ep; 667 ozhcd->ports[i].out_ep[0] = ep;
666 ep = 0; 668 ep = NULL;
667 hport = &ozhcd->ports[i]; 669 hport = &ozhcd->ports[i];
668 spin_unlock_bh(&ozhcd->hcd_lock); 670 spin_unlock_bh(&ozhcd->hcd_lock);
669 if (ozhcd->flags & OZ_HDC_F_SUSPENDED) { 671 if (ozhcd->flags & OZ_HDC_F_SUSPENDED) {
@@ -676,7 +678,7 @@ void *oz_hcd_pd_arrived(void *hpd)
676 } 678 }
677out: 679out:
678 if (ep) /* ep is non-null if not used. */ 680 if (ep) /* ep is non-null if not used. */
679 oz_ep_free(0, ep); 681 oz_ep_free(NULL, ep);
680 oz_hcd_put(ozhcd); 682 oz_hcd_put(ozhcd);
681 return hport; 683 return hport;
682} 684}
@@ -691,15 +693,15 @@ void oz_hcd_pd_departed(void *hport)
691 struct oz_port *port = (struct oz_port *)hport; 693 struct oz_port *port = (struct oz_port *)hport;
692 struct oz_hcd *ozhcd; 694 struct oz_hcd *ozhcd;
693 void *hpd; 695 void *hpd;
694 struct oz_endpoint *ep = 0; 696 struct oz_endpoint *ep = NULL;
695 697
696 oz_trace("oz_hcd_pd_departed()\n"); 698 oz_trace("oz_hcd_pd_departed()\n");
697 if (port == 0) { 699 if (port == NULL) {
698 oz_trace("oz_hcd_pd_departed() port = 0\n"); 700 oz_trace("oz_hcd_pd_departed() port = 0\n");
699 return; 701 return;
700 } 702 }
701 ozhcd = port->ozhcd; 703 ozhcd = port->ozhcd;
702 if (ozhcd == 0) 704 if (ozhcd == NULL)
703 return; 705 return;
704 /* Check if this is the connection port - if so clear it. 706 /* Check if this is the connection port - if so clear it.
705 */ 707 */
@@ -717,7 +719,7 @@ void oz_hcd_pd_departed(void *hport)
717 oz_clean_endpoints_for_config(ozhcd->hcd, port); 719 oz_clean_endpoints_for_config(ozhcd->hcd, port);
718 spin_lock_bh(&port->port_lock); 720 spin_lock_bh(&port->port_lock);
719 hpd = port->hpd; 721 hpd = port->hpd;
720 port->hpd = 0; 722 port->hpd = NULL;
721 port->bus_addr = 0xff; 723 port->bus_addr = 0xff;
722 port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING); 724 port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING);
723 port->flags |= OZ_PORT_F_CHANGED; 725 port->flags |= OZ_PORT_F_CHANGED;
@@ -728,7 +730,7 @@ void oz_hcd_pd_departed(void *hport)
728 */ 730 */
729 if (port->out_ep[0]) { 731 if (port->out_ep[0]) {
730 ep = port->out_ep[0]; 732 ep = port->out_ep[0];
731 port->out_ep[0] = 0; 733 port->out_ep[0] = NULL;
732 } 734 }
733 spin_unlock_bh(&port->port_lock); 735 spin_unlock_bh(&port->port_lock);
734 if (ep) 736 if (ep)
@@ -757,14 +759,14 @@ void oz_hcd_pd_reset(void *hpd, void *hport)
757/*------------------------------------------------------------------------------ 759/*------------------------------------------------------------------------------
758 * Context: softirq 760 * Context: softirq
759 */ 761 */
760void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, u8 *desc, 762void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc,
761 int length, int offset, int total_size) 763 int length, int offset, int total_size)
762{ 764{
763 struct oz_port *port = (struct oz_port *)hport; 765 struct oz_port *port = (struct oz_port *)hport;
764 struct urb *urb; 766 struct urb *urb;
765 int err = 0; 767 int err = 0;
766 768
767 oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, 0, status); 769 oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, NULL, status);
768 oz_trace("oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n", 770 oz_trace("oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n",
769 length, offset, total_size); 771 length, offset, total_size);
770 urb = oz_find_urb_by_id(port, 0, req_id); 772 urb = oz_find_urb_by_id(port, 0, req_id);
@@ -893,7 +895,7 @@ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb,
893/*------------------------------------------------------------------------------ 895/*------------------------------------------------------------------------------
894 * Context: softirq 896 * Context: softirq
895 */ 897 */
896void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data, 898void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data,
897 int data_len) 899 int data_len)
898{ 900{
899 struct oz_port *port = (struct oz_port *)hport; 901 struct oz_port *port = (struct oz_port *)hport;
@@ -903,7 +905,7 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data,
903 unsigned windex; 905 unsigned windex;
904 unsigned wvalue; 906 unsigned wvalue;
905 907
906 oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, 0, rcode); 908 oz_event_log(OZ_EVT_CTRL_CNF, 0, req_id, NULL, rcode);
907 oz_trace("oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len); 909 oz_trace("oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len);
908 urb = oz_find_urb_by_id(port, 0, req_id); 910 urb = oz_find_urb_by_id(port, 0, req_id);
909 if (!urb) { 911 if (!urb) {
@@ -946,7 +948,8 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, u8 *data,
946/*------------------------------------------------------------------------------ 948/*------------------------------------------------------------------------------
947 * Context: softirq-serialized 949 * Context: softirq-serialized
948 */ 950 */
949static int oz_hcd_buffer_data(struct oz_endpoint *ep, u8 *data, int data_len) 951static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data,
952 int data_len)
950{ 953{
951 int space; 954 int space;
952 int copy_len; 955 int copy_len;
@@ -981,14 +984,14 @@ static int oz_hcd_buffer_data(struct oz_endpoint *ep, u8 *data, int data_len)
981/*------------------------------------------------------------------------------ 984/*------------------------------------------------------------------------------
982 * Context: softirq-serialized 985 * Context: softirq-serialized
983 */ 986 */
984void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len) 987void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len)
985{ 988{
986 struct oz_port *port = (struct oz_port *)hport; 989 struct oz_port *port = (struct oz_port *)hport;
987 struct oz_endpoint *ep; 990 struct oz_endpoint *ep;
988 struct oz_hcd *ozhcd = port->ozhcd; 991 struct oz_hcd *ozhcd = port->ozhcd;
989 spin_lock_bh(&ozhcd->hcd_lock); 992 spin_lock_bh(&ozhcd->hcd_lock);
990 ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK]; 993 ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK];
991 if (ep == 0) 994 if (ep == NULL)
992 goto done; 995 goto done;
993 switch (ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) { 996 switch (ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) {
994 case USB_ENDPOINT_XFER_INT: 997 case USB_ENDPOINT_XFER_INT:
@@ -1056,7 +1059,8 @@ int oz_hcd_heartbeat(void *hport)
1056 ep->credit += jiffies_to_msecs(now - ep->last_jiffies); 1059 ep->credit += jiffies_to_msecs(now - ep->last_jiffies);
1057 if (ep->credit > ep->credit_ceiling) 1060 if (ep->credit > ep->credit_ceiling)
1058 ep->credit = ep->credit_ceiling; 1061 ep->credit = ep->credit_ceiling;
1059 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, 0, ep->credit); 1062 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, NULL,
1063 ep->credit);
1060 ep->last_jiffies = now; 1064 ep->last_jiffies = now;
1061 while (ep->credit && !list_empty(&ep->urb_list)) { 1065 while (ep->credit && !list_empty(&ep->urb_list)) {
1062 urbl = list_first_entry(&ep->urb_list, 1066 urbl = list_first_entry(&ep->urb_list,
@@ -1065,8 +1069,8 @@ int oz_hcd_heartbeat(void *hport)
1065 if ((ep->credit + 1) < urb->number_of_packets) 1069 if ((ep->credit + 1) < urb->number_of_packets)
1066 break; 1070 break;
1067 ep->credit -= urb->number_of_packets; 1071 ep->credit -= urb->number_of_packets;
1068 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, 0, 1072 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num, 0, NULL,
1069 ep->credit); 1073 ep->credit);
1070 list_move_tail(&urbl->link, &xfr_list); 1074 list_move_tail(&urbl->link, &xfr_list);
1071 } 1075 }
1072 } 1076 }
@@ -1091,22 +1095,22 @@ int oz_hcd_heartbeat(void *hport)
1091 list_for_each(e, &port->isoc_in_ep) { 1095 list_for_each(e, &port->isoc_in_ep) {
1092 struct oz_endpoint *ep = ep_from_link(e); 1096 struct oz_endpoint *ep = ep_from_link(e);
1093 if (ep->flags & OZ_F_EP_BUFFERING) { 1097 if (ep->flags & OZ_F_EP_BUFFERING) {
1094 if (ep->buffered_units * OZ_IN_BUFFERING_UNITS) { 1098 if (ep->buffered_units >= OZ_IN_BUFFERING_UNITS) {
1095 ep->flags &= ~OZ_F_EP_BUFFERING; 1099 ep->flags &= ~OZ_F_EP_BUFFERING;
1096 ep->credit = 0; 1100 ep->credit = 0;
1097 oz_event_log(OZ_EVT_EP_CREDIT, 1101 oz_event_log(OZ_EVT_EP_CREDIT,
1098 ep->ep_num | USB_DIR_IN, 1102 ep->ep_num | USB_DIR_IN,
1099 0, 0, ep->credit); 1103 0, NULL, ep->credit);
1100 ep->last_jiffies = now; 1104 ep->last_jiffies = now;
1101 ep->start_frame = 0; 1105 ep->start_frame = 0;
1102 oz_event_log(OZ_EVT_EP_BUFFERING, 1106 oz_event_log(OZ_EVT_EP_BUFFERING,
1103 ep->ep_num | USB_DIR_IN, 0, 0, 0); 1107 ep->ep_num | USB_DIR_IN, 0, NULL, 0);
1104 } 1108 }
1105 continue; 1109 continue;
1106 } 1110 }
1107 ep->credit += jiffies_to_msecs(now - ep->last_jiffies); 1111 ep->credit += jiffies_to_msecs(now - ep->last_jiffies);
1108 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN, 1112 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN,
1109 0, 0, ep->credit); 1113 0, NULL, ep->credit);
1110 ep->last_jiffies = now; 1114 ep->last_jiffies = now;
1111 while (!list_empty(&ep->urb_list)) { 1115 while (!list_empty(&ep->urb_list)) {
1112 struct oz_urb_link *urbl = 1116 struct oz_urb_link *urbl =
@@ -1151,7 +1155,7 @@ int oz_hcd_heartbeat(void *hport)
1151 list_move_tail(&urbl->link, &xfr_list); 1155 list_move_tail(&urbl->link, &xfr_list);
1152 ep->credit -= urb->number_of_packets; 1156 ep->credit -= urb->number_of_packets;
1153 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN, 1157 oz_event_log(OZ_EVT_EP_CREDIT, ep->ep_num | USB_DIR_IN,
1154 0, 0, ep->credit); 1158 0, NULL, ep->credit);
1155 } 1159 }
1156 } 1160 }
1157 if (!list_empty(&port->isoc_out_ep) || !list_empty(&port->isoc_in_ep)) 1161 if (!list_empty(&port->isoc_out_ep) || !list_empty(&port->isoc_in_ep))
@@ -1244,7 +1248,7 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd,
1244 if (ep_addr & USB_ENDPOINT_DIR_MASK) { 1248 if (ep_addr & USB_ENDPOINT_DIR_MASK) {
1245 ep->flags |= OZ_F_EP_BUFFERING; 1249 ep->flags |= OZ_F_EP_BUFFERING;
1246 oz_event_log(OZ_EVT_EP_BUFFERING, 1250 oz_event_log(OZ_EVT_EP_BUFFERING,
1247 ep->ep_num | USB_DIR_IN, 1, 0, 0); 1251 ep->ep_num | USB_DIR_IN, 1, NULL, 0);
1248 } else { 1252 } else {
1249 ep->flags |= OZ_F_EP_HAVE_STREAM; 1253 ep->flags |= OZ_F_EP_HAVE_STREAM;
1250 if (oz_usb_stream_create(port->hpd, ep_num)) 1254 if (oz_usb_stream_create(port->hpd, ep_num))
@@ -1300,7 +1304,7 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd,
1300 */ 1304 */
1301 if ((mask & (1<<i)) && port->out_ep[i]) { 1305 if ((mask & (1<<i)) && port->out_ep[i]) {
1302 e = &port->out_ep[i]->link; 1306 e = &port->out_ep[i]->link;
1303 port->out_ep[i] = 0; 1307 port->out_ep[i] = NULL;
1304 /* Remove from isoc list if present. 1308 /* Remove from isoc list if present.
1305 */ 1309 */
1306 list_move_tail(e, &ep_list); 1310 list_move_tail(e, &ep_list);
@@ -1309,7 +1313,7 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd,
1309 */ 1313 */
1310 if ((mask & (1<<(i+OZ_NB_ENDPOINTS))) && port->in_ep[i]) { 1314 if ((mask & (1<<(i+OZ_NB_ENDPOINTS))) && port->in_ep[i]) {
1311 e = &port->in_ep[i]->link; 1315 e = &port->in_ep[i]->link;
1312 port->in_ep[i] = 0; 1316 port->in_ep[i] = NULL;
1313 list_move_tail(e, &ep_list); 1317 list_move_tail(e, &ep_list);
1314 } 1318 }
1315 } 1319 }
@@ -1370,7 +1374,7 @@ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd,
1370 if (port->iface) { 1374 if (port->iface) {
1371 oz_trace("Freeing interfaces object.\n"); 1375 oz_trace("Freeing interfaces object.\n");
1372 kfree(port->iface); 1376 kfree(port->iface);
1373 port->iface = 0; 1377 port->iface = NULL;
1374 } 1378 }
1375 port->num_iface = 0; 1379 port->num_iface = 0;
1376 spin_unlock_bh(&ozhcd->hcd_lock); 1380 spin_unlock_bh(&ozhcd->hcd_lock);
@@ -1380,7 +1384,7 @@ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd,
1380 */ 1384 */
1381static void *oz_claim_hpd(struct oz_port *port) 1385static void *oz_claim_hpd(struct oz_port *port)
1382{ 1386{
1383 void *hpd = 0; 1387 void *hpd = NULL;
1384 struct oz_hcd *ozhcd = port->ozhcd; 1388 struct oz_hcd *ozhcd = port->ozhcd;
1385 spin_lock_bh(&ozhcd->hcd_lock); 1389 spin_lock_bh(&ozhcd->hcd_lock);
1386 hpd = port->hpd; 1390 hpd = port->hpd;
@@ -1399,13 +1403,13 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1399 unsigned windex; 1403 unsigned windex;
1400 unsigned wvalue; 1404 unsigned wvalue;
1401 unsigned wlength; 1405 unsigned wlength;
1402 void *hpd = 0; 1406 void *hpd = NULL;
1403 u8 req_id; 1407 u8 req_id;
1404 int rc = 0; 1408 int rc = 0;
1405 unsigned complete = 0; 1409 unsigned complete = 0;
1406 1410
1407 int port_ix = -1; 1411 int port_ix = -1;
1408 struct oz_port *port = 0; 1412 struct oz_port *port = NULL;
1409 1413
1410 oz_trace2(OZ_TRACE_URB, "%lu: oz_process_ep0_urb(%p)\n", jiffies, urb); 1414 oz_trace2(OZ_TRACE_URB, "%lu: oz_process_ep0_urb(%p)\n", jiffies, urb);
1411 port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); 1415 port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum);
@@ -1437,7 +1441,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1437 1441
1438 req_id = port->next_req_id++; 1442 req_id = port->next_req_id++;
1439 hpd = oz_claim_hpd(port); 1443 hpd = oz_claim_hpd(port);
1440 if (hpd == 0) { 1444 if (hpd == NULL) {
1441 oz_trace("Cannot claim port\n"); 1445 oz_trace("Cannot claim port\n");
1442 rc = -EPIPE; 1446 rc = -EPIPE;
1443 goto out; 1447 goto out;
@@ -1452,7 +1456,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1452 break; 1456 break;
1453 case USB_REQ_SET_ADDRESS: 1457 case USB_REQ_SET_ADDRESS:
1454 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 1458 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest,
1455 0, 0, setup->bRequestType); 1459 0, NULL, setup->bRequestType);
1456 oz_trace("USB_REQ_SET_ADDRESS - req\n"); 1460 oz_trace("USB_REQ_SET_ADDRESS - req\n");
1457 oz_trace("Port %d address is 0x%x\n", ozhcd->conn_port, 1461 oz_trace("Port %d address is 0x%x\n", ozhcd->conn_port,
1458 (u8)le16_to_cpu(setup->wValue)); 1462 (u8)le16_to_cpu(setup->wValue));
@@ -1473,8 +1477,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1473 /* We short circuit this case and reply directly since 1477 /* We short circuit this case and reply directly since
1474 * we have the selected configuration number cached. 1478 * we have the selected configuration number cached.
1475 */ 1479 */
1476 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, 1480 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0,
1477 setup->bRequestType); 1481 NULL, setup->bRequestType);
1478 oz_trace("USB_REQ_GET_CONFIGURATION - reply now\n"); 1482 oz_trace("USB_REQ_GET_CONFIGURATION - reply now\n");
1479 if (urb->transfer_buffer_length >= 1) { 1483 if (urb->transfer_buffer_length >= 1) {
1480 urb->actual_length = 1; 1484 urb->actual_length = 1;
@@ -1489,8 +1493,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb,
1489 /* We short circuit this case and reply directly since 1493 /* We short circuit this case and reply directly since
1490 * we have the selected interface alternative cached. 1494 * we have the selected interface alternative cached.
1491 */ 1495 */
1492 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0, 0, 1496 oz_event_log(OZ_EVT_CTRL_LOCAL, setup->bRequest, 0,
1493 setup->bRequestType); 1497 NULL, setup->bRequestType);
1494 oz_trace("USB_REQ_GET_INTERFACE - reply now\n"); 1498 oz_trace("USB_REQ_GET_INTERFACE - reply now\n");
1495 if (urb->transfer_buffer_length >= 1) { 1499 if (urb->transfer_buffer_length >= 1) {
1496 urb->actual_length = 1; 1500 urb->actual_length = 1;
@@ -1583,7 +1587,7 @@ static void oz_urb_process_tasklet(unsigned long unused)
1583 struct urb *urb; 1587 struct urb *urb;
1584 struct oz_hcd *ozhcd = oz_hcd_claim(); 1588 struct oz_hcd *ozhcd = oz_hcd_claim();
1585 int rc = 0; 1589 int rc = 0;
1586 if (ozhcd == 0) 1590 if (ozhcd == NULL)
1587 return; 1591 return;
1588 /* This is called from a tasklet so is in softirq context but the urb 1592 /* This is called from a tasklet so is in softirq context but the urb
1589 * list is filled from any context so we need to lock 1593 * list is filled from any context so we need to lock
@@ -1617,17 +1621,17 @@ static void oz_urb_process_tasklet(unsigned long unused)
1617 */ 1621 */
1618static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) 1622static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb)
1619{ 1623{
1620 struct oz_urb_link *urbl = 0; 1624 struct oz_urb_link *urbl = NULL;
1621 struct list_head *e; 1625 struct list_head *e;
1622 struct oz_hcd *ozhcd; 1626 struct oz_hcd *ozhcd;
1623 unsigned long irq_state; 1627 unsigned long irq_state;
1624 u8 ix; 1628 u8 ix;
1625 if (port == 0) { 1629 if (port == NULL) {
1626 oz_trace("ERRORERROR: oz_urb_cancel(%p) port is null\n", urb); 1630 oz_trace("ERRORERROR: oz_urb_cancel(%p) port is null\n", urb);
1627 return; 1631 return;
1628 } 1632 }
1629 ozhcd = port->ozhcd; 1633 ozhcd = port->ozhcd;
1630 if (ozhcd == 0) { 1634 if (ozhcd == NULL) {
1631 oz_trace("ERRORERROR: oz_urb_cancel(%p) ozhcd is null\n", urb); 1635 oz_trace("ERRORERROR: oz_urb_cancel(%p) ozhcd is null\n", urb);
1632 return; 1636 return;
1633 } 1637 }
@@ -1644,7 +1648,7 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb)
1644 } 1648 }
1645 } 1649 }
1646 spin_unlock_irqrestore(&g_tasklet_lock, irq_state); 1650 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
1647 urbl = 0; 1651 urbl = NULL;
1648 1652
1649 /* Look in the orphanage. 1653 /* Look in the orphanage.
1650 */ 1654 */
@@ -1658,7 +1662,7 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb)
1658 } 1662 }
1659 } 1663 }
1660 ix = (ep_num & 0xf); 1664 ix = (ep_num & 0xf);
1661 urbl = 0; 1665 urbl = NULL;
1662 if ((ep_num & USB_DIR_IN) && ix) 1666 if ((ep_num & USB_DIR_IN) && ix)
1663 urbl = oz_remove_urb(port->in_ep[ix], urb); 1667 urbl = oz_remove_urb(port->in_ep[ix], urb);
1664 else 1668 else
@@ -1680,7 +1684,7 @@ static void oz_urb_cancel_tasklet(unsigned long unused)
1680 unsigned long irq_state; 1684 unsigned long irq_state;
1681 struct urb *urb; 1685 struct urb *urb;
1682 struct oz_hcd *ozhcd = oz_hcd_claim(); 1686 struct oz_hcd *ozhcd = oz_hcd_claim();
1683 if (ozhcd == 0) 1687 if (ozhcd == NULL)
1684 return; 1688 return;
1685 spin_lock_irqsave(&g_tasklet_lock, irq_state); 1689 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1686 while (!list_empty(&ozhcd->urb_cancel_list)) { 1690 while (!list_empty(&ozhcd->urb_cancel_list)) {
@@ -1772,7 +1776,7 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1772 jiffies, urb); 1776 jiffies, urb);
1773 oz_event_log(OZ_EVT_URB_SUBMIT, oz_get_irq_ctx(), 1777 oz_event_log(OZ_EVT_URB_SUBMIT, oz_get_irq_ctx(),
1774 (u16)urb->number_of_packets, urb, urb->pipe); 1778 (u16)urb->number_of_packets, urb, urb->pipe);
1775 if (unlikely(ozhcd == 0)) { 1779 if (unlikely(ozhcd == NULL)) {
1776 oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not ozhcd.\n", 1780 oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not ozhcd.\n",
1777 jiffies, urb); 1781 jiffies, urb);
1778 return -EPIPE; 1782 return -EPIPE;
@@ -1786,7 +1790,7 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1786 if (port_ix < 0) 1790 if (port_ix < 0)
1787 return -EPIPE; 1791 return -EPIPE;
1788 port = &ozhcd->ports[port_ix]; 1792 port = &ozhcd->ports[port_ix];
1789 if (port == 0) 1793 if (port == NULL)
1790 return -EPIPE; 1794 return -EPIPE;
1791 if ((port->flags & OZ_PORT_F_PRESENT) == 0) { 1795 if ((port->flags & OZ_PORT_F_PRESENT) == 0) {
1792 oz_trace("Refusing URB port_ix = %d devnum = %d\n", 1796 oz_trace("Refusing URB port_ix = %d devnum = %d\n",
@@ -1797,7 +1801,7 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1797 /* Put request in queue for processing by tasklet. 1801 /* Put request in queue for processing by tasklet.
1798 */ 1802 */
1799 urbl = oz_alloc_urb_link(); 1803 urbl = oz_alloc_urb_link();
1800 if (unlikely(urbl == 0)) 1804 if (unlikely(urbl == NULL))
1801 return -ENOMEM; 1805 return -ENOMEM;
1802 urbl->urb = urb; 1806 urbl->urb = urb;
1803 spin_lock_irqsave(&g_tasklet_lock, irq_state); 1807 spin_lock_irqsave(&g_tasklet_lock, irq_state);
@@ -1819,10 +1823,10 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1819static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, 1823static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep,
1820 struct urb *urb) 1824 struct urb *urb)
1821{ 1825{
1822 struct oz_urb_link *urbl = 0; 1826 struct oz_urb_link *urbl = NULL;
1823 struct list_head *e; 1827 struct list_head *e;
1824 if (unlikely(ep == 0)) 1828 if (unlikely(ep == NULL))
1825 return 0; 1829 return NULL;
1826 list_for_each(e, &ep->urb_list) { 1830 list_for_each(e, &ep->urb_list) {
1827 urbl = container_of(e, struct oz_urb_link, link); 1831 urbl = container_of(e, struct oz_urb_link, link);
1828 if (urbl->urb == urb) { 1832 if (urbl->urb == urb) {
@@ -1834,12 +1838,12 @@ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep,
1834 oz_event_log(OZ_EVT_EP_CREDIT, 1838 oz_event_log(OZ_EVT_EP_CREDIT,
1835 usb_pipein(urb->pipe) ? 1839 usb_pipein(urb->pipe) ?
1836 (ep->ep_num | USB_DIR_IN) : ep->ep_num, 1840 (ep->ep_num | USB_DIR_IN) : ep->ep_num,
1837 0, 0, ep->credit); 1841 0, NULL, ep->credit);
1838 } 1842 }
1839 return urbl; 1843 return urbl;
1840 } 1844 }
1841 } 1845 }
1842 return 0; 1846 return NULL;
1843} 1847}
1844/*------------------------------------------------------------------------------ 1848/*------------------------------------------------------------------------------
1845 * Called to dequeue a previously submitted urb for the device. 1849 * Called to dequeue a previously submitted urb for the device.
@@ -1848,12 +1852,12 @@ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep,
1848static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 1852static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1849{ 1853{
1850 struct oz_hcd *ozhcd = oz_hcd_private(hcd); 1854 struct oz_hcd *ozhcd = oz_hcd_private(hcd);
1851 struct oz_urb_link *urbl = 0; 1855 struct oz_urb_link *urbl = NULL;
1852 int rc; 1856 int rc;
1853 unsigned long irq_state; 1857 unsigned long irq_state;
1854 oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_dequeue(%p)\n", jiffies, urb); 1858 oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_dequeue(%p)\n", jiffies, urb);
1855 urbl = oz_alloc_urb_link(); 1859 urbl = oz_alloc_urb_link();
1856 if (unlikely(urbl == 0)) 1860 if (unlikely(urbl == NULL))
1857 return -ENOMEM; 1861 return -ENOMEM;
1858 spin_lock_irqsave(&g_tasklet_lock, irq_state); 1862 spin_lock_irqsave(&g_tasklet_lock, irq_state);
1859 /* The following function checks the urb is still in the queue 1863 /* The following function checks the urb is still in the queue
@@ -2193,7 +2197,7 @@ static int oz_plat_probe(struct platform_device *dev)
2193 struct oz_hcd *ozhcd; 2197 struct oz_hcd *ozhcd;
2194 oz_trace("oz_plat_probe()\n"); 2198 oz_trace("oz_plat_probe()\n");
2195 hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev)); 2199 hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev));
2196 if (hcd == 0) { 2200 if (hcd == NULL) {
2197 oz_trace("Failed to created hcd object OK\n"); 2201 oz_trace("Failed to created hcd object OK\n");
2198 return -ENOMEM; 2202 return -ENOMEM;
2199 } 2203 }
@@ -2232,12 +2236,12 @@ static int oz_plat_remove(struct platform_device *dev)
2232 struct usb_hcd *hcd = platform_get_drvdata(dev); 2236 struct usb_hcd *hcd = platform_get_drvdata(dev);
2233 struct oz_hcd *ozhcd; 2237 struct oz_hcd *ozhcd;
2234 oz_trace("oz_plat_remove()\n"); 2238 oz_trace("oz_plat_remove()\n");
2235 if (hcd == 0) 2239 if (hcd == NULL)
2236 return -1; 2240 return -1;
2237 ozhcd = oz_hcd_private(hcd); 2241 ozhcd = oz_hcd_private(hcd);
2238 spin_lock_bh(&g_hcdlock); 2242 spin_lock_bh(&g_hcdlock);
2239 if (ozhcd == g_ozhcd) 2243 if (ozhcd == g_ozhcd)
2240 g_ozhcd = 0; 2244 g_ozhcd = NULL;
2241 spin_unlock_bh(&g_hcdlock); 2245 spin_unlock_bh(&g_hcdlock);
2242 oz_trace("Clearing orphanage\n"); 2246 oz_trace("Clearing orphanage\n");
2243 oz_hcd_clear_orphanage(ozhcd, -EPIPE); 2247 oz_hcd_clear_orphanage(ozhcd, -EPIPE);
@@ -2278,7 +2282,7 @@ int oz_hcd_init(void)
2278 if (err) 2282 if (err)
2279 goto error; 2283 goto error;
2280 g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1); 2284 g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1);
2281 if (g_plat_dev == 0) { 2285 if (g_plat_dev == NULL) {
2282 err = -ENOMEM; 2286 err = -ENOMEM;
2283 goto error1; 2287 goto error1;
2284 } 2288 }
diff --git a/drivers/staging/ozwpan/ozmain.c b/drivers/staging/ozwpan/ozmain.c
index ef6c5ab753ee..57a0cbd58551 100644
--- a/drivers/staging/ozwpan/ozmain.c
+++ b/drivers/staging/ozwpan/ozmain.c
@@ -22,7 +22,7 @@
22 * bind to nothing. '*' means bind to all netcards - this includes non-802.11 22 * bind to nothing. '*' means bind to all netcards - this includes non-802.11
23 * netcards. Bindings can be added later using an IOCTL. 23 * netcards. Bindings can be added later using an IOCTL.
24 */ 24 */
25char *g_net_dev = ""; 25static char *g_net_dev = "";
26/*------------------------------------------------------------------------------ 26/*------------------------------------------------------------------------------
27 * Context: process 27 * Context: process
28 */ 28 */
diff --git a/drivers/staging/ozwpan/ozpd.c b/drivers/staging/ozwpan/ozpd.c
index 118a4db74dec..f8b9da080c4b 100644
--- a/drivers/staging/ozwpan/ozpd.c
+++ b/drivers/staging/ozwpan/ozpd.c
@@ -46,7 +46,7 @@ static void oz_def_app_rx(struct oz_pd *pd, struct oz_elt *elt);
46static atomic_t g_submitted_isoc = ATOMIC_INIT(0); 46static atomic_t g_submitted_isoc = ATOMIC_INIT(0);
47/* Application handler functions. 47/* Application handler functions.
48 */ 48 */
49static struct oz_app_if g_app_if[OZ_APPID_MAX] = { 49static const struct oz_app_if g_app_if[OZ_APPID_MAX] = {
50 {oz_usb_init, 50 {oz_usb_init,
51 oz_usb_term, 51 oz_usb_term,
52 oz_usb_start, 52 oz_usb_start,
@@ -61,8 +61,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = {
61 oz_def_app_start, 61 oz_def_app_start,
62 oz_def_app_stop, 62 oz_def_app_stop,
63 oz_def_app_rx, 63 oz_def_app_rx,
64 0, 64 NULL,
65 0, 65 NULL,
66 OZ_APPID_UNUSED1}, 66 OZ_APPID_UNUSED1},
67 67
68 {oz_def_app_init, 68 {oz_def_app_init,
@@ -70,8 +70,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = {
70 oz_def_app_start, 70 oz_def_app_start,
71 oz_def_app_stop, 71 oz_def_app_stop,
72 oz_def_app_rx, 72 oz_def_app_rx,
73 0, 73 NULL,
74 0, 74 NULL,
75 OZ_APPID_UNUSED2}, 75 OZ_APPID_UNUSED2},
76 76
77 {oz_cdev_init, 77 {oz_cdev_init,
@@ -79,8 +79,8 @@ static struct oz_app_if g_app_if[OZ_APPID_MAX] = {
79 oz_cdev_start, 79 oz_cdev_start,
80 oz_cdev_stop, 80 oz_cdev_stop,
81 oz_cdev_rx, 81 oz_cdev_rx,
82 0, 82 NULL,
83 0, 83 NULL,
84 OZ_APPID_SERIAL}, 84 OZ_APPID_SERIAL},
85}; 85};
86/*------------------------------------------------------------------------------ 86/*------------------------------------------------------------------------------
@@ -121,7 +121,7 @@ static void oz_def_app_rx(struct oz_pd *pd, struct oz_elt *elt)
121void oz_pd_set_state(struct oz_pd *pd, unsigned state) 121void oz_pd_set_state(struct oz_pd *pd, unsigned state)
122{ 122{
123 pd->state = state; 123 pd->state = state;
124 oz_event_log(OZ_EVT_PD_STATE, 0, 0, 0, state); 124 oz_event_log(OZ_EVT_PD_STATE, 0, 0, NULL, state);
125#ifdef WANT_TRACE 125#ifdef WANT_TRACE
126 switch (state) { 126 switch (state) {
127 case OZ_PD_S_IDLE: 127 case OZ_PD_S_IDLE:
@@ -157,7 +157,7 @@ void oz_pd_put(struct oz_pd *pd)
157/*------------------------------------------------------------------------------ 157/*------------------------------------------------------------------------------
158 * Context: softirq-serialized 158 * Context: softirq-serialized
159 */ 159 */
160struct oz_pd *oz_pd_alloc(u8 *mac_addr) 160struct oz_pd *oz_pd_alloc(const u8 *mac_addr)
161{ 161{
162 struct oz_pd *pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC); 162 struct oz_pd *pd = kzalloc(sizeof(struct oz_pd), GFP_ATOMIC);
163 if (pd) { 163 if (pd) {
@@ -171,7 +171,7 @@ struct oz_pd *oz_pd_alloc(u8 *mac_addr)
171 memcpy(pd->mac_addr, mac_addr, ETH_ALEN); 171 memcpy(pd->mac_addr, mac_addr, ETH_ALEN);
172 if (0 != oz_elt_buf_init(&pd->elt_buff)) { 172 if (0 != oz_elt_buf_init(&pd->elt_buff)) {
173 kfree(pd); 173 kfree(pd);
174 pd = 0; 174 pd = NULL;
175 } 175 }
176 spin_lock_init(&pd->tx_frame_lock); 176 spin_lock_init(&pd->tx_frame_lock);
177 INIT_LIST_HEAD(&pd->tx_queue); 177 INIT_LIST_HEAD(&pd->tx_queue);
@@ -235,7 +235,7 @@ void oz_pd_destroy(struct oz_pd *pd)
235 */ 235 */
236int oz_services_start(struct oz_pd *pd, u16 apps, int resume) 236int oz_services_start(struct oz_pd *pd, u16 apps, int resume)
237{ 237{
238 struct oz_app_if *ai; 238 const struct oz_app_if *ai;
239 int rc = 0; 239 int rc = 0;
240 oz_trace("oz_services_start(0x%x) resume(%d)\n", apps, resume); 240 oz_trace("oz_services_start(0x%x) resume(%d)\n", apps, resume);
241 for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { 241 for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) {
@@ -260,7 +260,7 @@ int oz_services_start(struct oz_pd *pd, u16 apps, int resume)
260 */ 260 */
261void oz_services_stop(struct oz_pd *pd, u16 apps, int pause) 261void oz_services_stop(struct oz_pd *pd, u16 apps, int pause)
262{ 262{
263 struct oz_app_if *ai; 263 const struct oz_app_if *ai;
264 oz_trace("oz_stop_services(0x%x) pause(%d)\n", apps, pause); 264 oz_trace("oz_stop_services(0x%x) pause(%d)\n", apps, pause);
265 for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { 265 for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) {
266 if (apps & (1<<ai->app_id)) { 266 if (apps & (1<<ai->app_id)) {
@@ -281,7 +281,7 @@ void oz_services_stop(struct oz_pd *pd, u16 apps, int pause)
281 */ 281 */
282void oz_pd_heartbeat(struct oz_pd *pd, u16 apps) 282void oz_pd_heartbeat(struct oz_pd *pd, u16 apps)
283{ 283{
284 struct oz_app_if *ai; 284 const struct oz_app_if *ai;
285 int more = 0; 285 int more = 0;
286 for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) { 286 for (ai = g_app_if; ai < &g_app_if[OZ_APPID_MAX]; ai++) {
287 if (ai->heartbeat && (apps & (1<<ai->app_id))) { 287 if (ai->heartbeat && (apps & (1<<ai->app_id))) {
@@ -355,7 +355,7 @@ int oz_pd_sleep(struct oz_pd *pd)
355 */ 355 */
356static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd) 356static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd)
357{ 357{
358 struct oz_tx_frame *f = 0; 358 struct oz_tx_frame *f = NULL;
359 spin_lock_bh(&pd->tx_frame_lock); 359 spin_lock_bh(&pd->tx_frame_lock);
360 if (pd->tx_pool) { 360 if (pd->tx_pool) {
361 f = container_of(pd->tx_pool, struct oz_tx_frame, link); 361 f = container_of(pd->tx_pool, struct oz_tx_frame, link);
@@ -363,7 +363,7 @@ static struct oz_tx_frame *oz_tx_frame_alloc(struct oz_pd *pd)
363 pd->tx_pool_count--; 363 pd->tx_pool_count--;
364 } 364 }
365 spin_unlock_bh(&pd->tx_frame_lock); 365 spin_unlock_bh(&pd->tx_frame_lock);
366 if (f == 0) 366 if (f == NULL)
367 f = kmalloc(sizeof(struct oz_tx_frame), GFP_ATOMIC); 367 f = kmalloc(sizeof(struct oz_tx_frame), GFP_ATOMIC);
368 if (f) { 368 if (f) {
369 f->total_size = sizeof(struct oz_hdr); 369 f->total_size = sizeof(struct oz_hdr);
@@ -399,7 +399,7 @@ static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f)
399 f->link.next = pd->tx_pool; 399 f->link.next = pd->tx_pool;
400 pd->tx_pool = &f->link; 400 pd->tx_pool = &f->link;
401 pd->tx_pool_count++; 401 pd->tx_pool_count++;
402 f = 0; 402 f = NULL;
403 } 403 }
404 spin_unlock_bh(&pd->tx_frame_lock); 404 spin_unlock_bh(&pd->tx_frame_lock);
405 kfree(f); 405 kfree(f);
@@ -407,7 +407,7 @@ static void oz_tx_frame_free(struct oz_pd *pd, struct oz_tx_frame *f)
407/*------------------------------------------------------------------------------ 407/*------------------------------------------------------------------------------
408 * Context: softirq-serialized 408 * Context: softirq-serialized
409 */ 409 */
410void oz_set_more_bit(struct sk_buff *skb) 410static void oz_set_more_bit(struct sk_buff *skb)
411{ 411{
412 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); 412 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb);
413 oz_hdr->control |= OZ_F_MORE_DATA; 413 oz_hdr->control |= OZ_F_MORE_DATA;
@@ -415,7 +415,7 @@ void oz_set_more_bit(struct sk_buff *skb)
415/*------------------------------------------------------------------------------ 415/*------------------------------------------------------------------------------
416 * Context: softirq-serialized 416 * Context: softirq-serialized
417 */ 417 */
418void oz_set_last_pkt_nb(struct oz_pd *pd, struct sk_buff *skb) 418static void oz_set_last_pkt_nb(struct oz_pd *pd, struct sk_buff *skb)
419{ 419{
420 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); 420 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb);
421 oz_hdr->last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK; 421 oz_hdr->last_pkt_num = pd->trigger_pkt_num & OZ_LAST_PN_MASK;
@@ -433,7 +433,7 @@ int oz_prepare_frame(struct oz_pd *pd, int empty)
433 if (!empty && !oz_are_elts_available(&pd->elt_buff)) 433 if (!empty && !oz_are_elts_available(&pd->elt_buff))
434 return -1; 434 return -1;
435 f = oz_tx_frame_alloc(pd); 435 f = oz_tx_frame_alloc(pd);
436 if (f == 0) 436 if (f == NULL)
437 return -1; 437 return -1;
438 f->skb = NULL; 438 f->skb = NULL;
439 f->hdr.control = 439 f->hdr.control =
@@ -455,7 +455,7 @@ int oz_prepare_frame(struct oz_pd *pd, int empty)
455 */ 455 */
456static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f) 456static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f)
457{ 457{
458 struct sk_buff *skb = 0; 458 struct sk_buff *skb;
459 struct net_device *dev = pd->net_dev; 459 struct net_device *dev = pd->net_dev;
460 struct oz_hdr *oz_hdr; 460 struct oz_hdr *oz_hdr;
461 struct oz_elt *elt; 461 struct oz_elt *elt;
@@ -464,8 +464,8 @@ static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f)
464 * as the space we need. 464 * as the space we need.
465 */ 465 */
466 skb = alloc_skb(f->total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); 466 skb = alloc_skb(f->total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC);
467 if (skb == 0) 467 if (skb == NULL)
468 return 0; 468 return NULL;
469 /* Reserve the head room for lower layers. 469 /* Reserve the head room for lower layers.
470 */ 470 */
471 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 471 skb_reserve(skb, LL_RESERVED_SPACE(dev));
@@ -492,7 +492,7 @@ static struct sk_buff *oz_build_frame(struct oz_pd *pd, struct oz_tx_frame *f)
492 return skb; 492 return skb;
493fail: 493fail:
494 kfree_skb(skb); 494 kfree_skb(skb);
495 return 0; 495 return NULL;
496} 496}
497/*------------------------------------------------------------------------------ 497/*------------------------------------------------------------------------------
498 * Context: softirq or process 498 * Context: softirq or process
@@ -544,7 +544,7 @@ static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data)
544 if (dev_queue_xmit(skb) < 0) { 544 if (dev_queue_xmit(skb) < 0) {
545 oz_trace2(OZ_TRACE_TX_FRAMES, 545 oz_trace2(OZ_TRACE_TX_FRAMES,
546 "Dropping ISOC Frame\n"); 546 "Dropping ISOC Frame\n");
547 oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); 547 oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0);
548 return -1; 548 return -1;
549 } 549 }
550 atomic_inc(&g_submitted_isoc); 550 atomic_inc(&g_submitted_isoc);
@@ -555,7 +555,7 @@ static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data)
555 } else { 555 } else {
556 kfree_skb(skb); 556 kfree_skb(skb);
557 oz_trace2(OZ_TRACE_TX_FRAMES, "Dropping ISOC Frame>\n"); 557 oz_trace2(OZ_TRACE_TX_FRAMES, "Dropping ISOC Frame>\n");
558 oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); 558 oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0);
559 return -1; 559 return -1;
560 } 560 }
561 } 561 }
@@ -570,7 +570,7 @@ static int oz_send_next_queued_frame(struct oz_pd *pd, int more_data)
570 oz_event_log(OZ_EVT_TX_FRAME, 570 oz_event_log(OZ_EVT_TX_FRAME,
571 0, 571 0,
572 (((u16)f->hdr.control)<<8)|f->hdr.last_pkt_num, 572 (((u16)f->hdr.control)<<8)|f->hdr.last_pkt_num,
573 0, f->hdr.pkt_num); 573 NULL, f->hdr.pkt_num);
574 if (dev_queue_xmit(skb) < 0) 574 if (dev_queue_xmit(skb) < 0)
575 return -1; 575 return -1;
576 576
@@ -620,7 +620,7 @@ out: oz_prepare_frame(pd, 1);
620 */ 620 */
621static int oz_send_isoc_frame(struct oz_pd *pd) 621static int oz_send_isoc_frame(struct oz_pd *pd)
622{ 622{
623 struct sk_buff *skb = 0; 623 struct sk_buff *skb;
624 struct net_device *dev = pd->net_dev; 624 struct net_device *dev = pd->net_dev;
625 struct oz_hdr *oz_hdr; 625 struct oz_hdr *oz_hdr;
626 struct oz_elt *elt; 626 struct oz_elt *elt;
@@ -634,7 +634,7 @@ static int oz_send_isoc_frame(struct oz_pd *pd)
634 if (list.next == &list) 634 if (list.next == &list)
635 return 0; 635 return 0;
636 skb = alloc_skb(total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); 636 skb = alloc_skb(total_size + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC);
637 if (skb == 0) { 637 if (skb == NULL) {
638 oz_trace("Cannot alloc skb\n"); 638 oz_trace("Cannot alloc skb\n");
639 oz_elt_info_free_chain(&pd->elt_buff, &list); 639 oz_elt_info_free_chain(&pd->elt_buff, &list);
640 return -1; 640 return -1;
@@ -659,7 +659,7 @@ static int oz_send_isoc_frame(struct oz_pd *pd)
659 memcpy(elt, ei->data, ei->length); 659 memcpy(elt, ei->data, ei->length);
660 elt = oz_next_elt(elt); 660 elt = oz_next_elt(elt);
661 } 661 }
662 oz_event_log(OZ_EVT_TX_ISOC, 0, 0, 0, 0); 662 oz_event_log(OZ_EVT_TX_ISOC, 0, 0, NULL, 0);
663 dev_queue_xmit(skb); 663 dev_queue_xmit(skb);
664 oz_elt_info_free_chain(&pd->elt_buff, &list); 664 oz_elt_info_free_chain(&pd->elt_buff, &list);
665 return 0; 665 return 0;
@@ -671,8 +671,8 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn)
671{ 671{
672 struct list_head *e; 672 struct list_head *e;
673 struct oz_tx_frame *f; 673 struct oz_tx_frame *f;
674 struct list_head *first = 0; 674 struct list_head *first = NULL;
675 struct list_head *last = 0; 675 struct list_head *last = NULL;
676 u8 diff; 676 u8 diff;
677 u32 pkt_num; 677 u32 pkt_num;
678 678
@@ -686,7 +686,7 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn)
686 break; 686 break;
687 oz_trace2(OZ_TRACE_TX_FRAMES, "Releasing pkt_num= %u, nb= %d\n", 687 oz_trace2(OZ_TRACE_TX_FRAMES, "Releasing pkt_num= %u, nb= %d\n",
688 pkt_num, pd->nb_queued_frames); 688 pkt_num, pd->nb_queued_frames);
689 if (first == 0) 689 if (first == NULL)
690 first = e; 690 first = e;
691 last = e; 691 last = e;
692 e = e->next; 692 e = e->next;
@@ -695,7 +695,7 @@ void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn)
695 if (first) { 695 if (first) {
696 last->next->prev = &pd->tx_queue; 696 last->next->prev = &pd->tx_queue;
697 pd->tx_queue.next = last->next; 697 pd->tx_queue.next = last->next;
698 last->next = 0; 698 last->next = NULL;
699 } 699 }
700 pd->last_sent_frame = &pd->tx_queue; 700 pd->last_sent_frame = &pd->tx_queue;
701 spin_unlock(&pd->tx_frame_lock); 701 spin_unlock(&pd->tx_frame_lock);
@@ -718,7 +718,7 @@ static struct oz_isoc_stream *pd_stream_find(struct oz_pd *pd, u8 ep_num)
718 if (st->ep_num == ep_num) 718 if (st->ep_num == ep_num)
719 return st; 719 return st;
720 } 720 }
721 return 0; 721 return NULL;
722} 722}
723/*------------------------------------------------------------------------------ 723/*------------------------------------------------------------------------------
724 * Context: softirq 724 * Context: softirq
@@ -733,7 +733,7 @@ int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num)
733 spin_lock_bh(&pd->stream_lock); 733 spin_lock_bh(&pd->stream_lock);
734 if (!pd_stream_find(pd, ep_num)) { 734 if (!pd_stream_find(pd, ep_num)) {
735 list_add(&st->link, &pd->stream_list); 735 list_add(&st->link, &pd->stream_list);
736 st = 0; 736 st = NULL;
737 } 737 }
738 spin_unlock_bh(&pd->stream_lock); 738 spin_unlock_bh(&pd->stream_lock);
739 kfree(st); 739 kfree(st);
@@ -774,19 +774,19 @@ static void oz_isoc_destructor(struct sk_buff *skb)
774/*------------------------------------------------------------------------------ 774/*------------------------------------------------------------------------------
775 * Context: softirq 775 * Context: softirq
776 */ 776 */
777int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len) 777int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len)
778{ 778{
779 struct net_device *dev = pd->net_dev; 779 struct net_device *dev = pd->net_dev;
780 struct oz_isoc_stream *st; 780 struct oz_isoc_stream *st;
781 u8 nb_units = 0; 781 u8 nb_units = 0;
782 struct sk_buff *skb = 0; 782 struct sk_buff *skb = NULL;
783 struct oz_hdr *oz_hdr = 0; 783 struct oz_hdr *oz_hdr = NULL;
784 int size = 0; 784 int size = 0;
785 spin_lock_bh(&pd->stream_lock); 785 spin_lock_bh(&pd->stream_lock);
786 st = pd_stream_find(pd, ep_num); 786 st = pd_stream_find(pd, ep_num);
787 if (st) { 787 if (st) {
788 skb = st->skb; 788 skb = st->skb;
789 st->skb = 0; 789 st->skb = NULL;
790 nb_units = st->nb_units; 790 nb_units = st->nb_units;
791 st->nb_units = 0; 791 st->nb_units = 0;
792 oz_hdr = st->oz_hdr; 792 oz_hdr = st->oz_hdr;
@@ -799,7 +799,7 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len)
799 /* Allocate enough space for max size frame. */ 799 /* Allocate enough space for max size frame. */
800 skb = alloc_skb(pd->max_tx_size + OZ_ALLOCATED_SPACE(dev), 800 skb = alloc_skb(pd->max_tx_size + OZ_ALLOCATED_SPACE(dev),
801 GFP_ATOMIC); 801 GFP_ATOMIC);
802 if (skb == 0) 802 if (skb == NULL)
803 return 0; 803 return 0;
804 /* Reserve the head room for lower layers. */ 804 /* Reserve the head room for lower layers. */
805 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 805 skb_reserve(skb, LL_RESERVED_SPACE(dev));
@@ -874,13 +874,13 @@ int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len)
874 oz_event_log(OZ_EVT_TX_ISOC, nb_units, iso.frame_number, 874 oz_event_log(OZ_EVT_TX_ISOC, nb_units, iso.frame_number,
875 skb, atomic_read(&g_submitted_isoc)); 875 skb, atomic_read(&g_submitted_isoc));
876 if (dev_queue_xmit(skb) < 0) { 876 if (dev_queue_xmit(skb) < 0) {
877 oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); 877 oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0);
878 return -1; 878 return -1;
879 } else 879 } else
880 return 0; 880 return 0;
881 } 881 }
882 882
883out: oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, 0, 0); 883out: oz_event_log(OZ_EVT_TX_ISOC_DROP, 0, 0, NULL, 0);
884 kfree_skb(skb); 884 kfree_skb(skb);
885 return -1; 885 return -1;
886 886
@@ -913,7 +913,7 @@ void oz_apps_term(void)
913 */ 913 */
914void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt) 914void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt)
915{ 915{
916 struct oz_app_if *ai; 916 const struct oz_app_if *ai;
917 if (app_id == 0 || app_id > OZ_APPID_MAX) 917 if (app_id == 0 || app_id > OZ_APPID_MAX)
918 return; 918 return;
919 ai = &g_app_if[app_id-1]; 919 ai = &g_app_if[app_id-1];
@@ -925,7 +925,7 @@ void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt)
925void oz_pd_indicate_farewells(struct oz_pd *pd) 925void oz_pd_indicate_farewells(struct oz_pd *pd)
926{ 926{
927 struct oz_farewell *f; 927 struct oz_farewell *f;
928 struct oz_app_if *ai = &g_app_if[OZ_APPID_USB-1]; 928 const struct oz_app_if *ai = &g_app_if[OZ_APPID_USB-1];
929 while (1) { 929 while (1) {
930 oz_polling_lock_bh(); 930 oz_polling_lock_bh();
931 if (list_empty(&pd->farewell_list)) { 931 if (list_empty(&pd->farewell_list)) {
diff --git a/drivers/staging/ozwpan/ozpd.h b/drivers/staging/ozwpan/ozpd.h
index d35b0ea44f67..fbf47cbab8a9 100644
--- a/drivers/staging/ozwpan/ozpd.h
+++ b/drivers/staging/ozwpan/ozpd.h
@@ -99,7 +99,7 @@ struct oz_pd {
99 99
100#define OZ_MAX_QUEUED_FRAMES 4 100#define OZ_MAX_QUEUED_FRAMES 4
101 101
102struct oz_pd *oz_pd_alloc(u8 *mac_addr); 102struct oz_pd *oz_pd_alloc(const u8 *mac_addr);
103void oz_pd_destroy(struct oz_pd *pd); 103void oz_pd_destroy(struct oz_pd *pd);
104void oz_pd_get(struct oz_pd *pd); 104void oz_pd_get(struct oz_pd *pd);
105void oz_pd_put(struct oz_pd *pd); 105void oz_pd_put(struct oz_pd *pd);
@@ -115,7 +115,7 @@ void oz_send_queued_frames(struct oz_pd *pd, int backlog);
115void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn); 115void oz_retire_tx_frames(struct oz_pd *pd, u8 lpn);
116int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num); 116int oz_isoc_stream_create(struct oz_pd *pd, u8 ep_num);
117int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num); 117int oz_isoc_stream_delete(struct oz_pd *pd, u8 ep_num);
118int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, u8 *data, int len); 118int oz_send_isoc_unit(struct oz_pd *pd, u8 ep_num, const u8 *data, int len);
119void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt); 119void oz_handle_app_elt(struct oz_pd *pd, u8 app_id, struct oz_elt *elt);
120void oz_apps_init(void); 120void oz_apps_init(void);
121void oz_apps_term(void); 121void oz_apps_term(void);
diff --git a/drivers/staging/ozwpan/ozproto.c b/drivers/staging/ozwpan/ozproto.c
index e00a53915daa..3badf1537adb 100644
--- a/drivers/staging/ozwpan/ozproto.c
+++ b/drivers/staging/ozwpan/ozproto.c
@@ -98,7 +98,7 @@ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status)
98 int sz = sizeof(struct oz_hdr) + sizeof(struct oz_elt) + 98 int sz = sizeof(struct oz_hdr) + sizeof(struct oz_elt) +
99 sizeof(struct oz_elt_connect_rsp); 99 sizeof(struct oz_elt_connect_rsp);
100 skb = alloc_skb(sz + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC); 100 skb = alloc_skb(sz + OZ_ALLOCATED_SPACE(dev), GFP_ATOMIC);
101 if (skb == 0) 101 if (skb == NULL)
102 return; 102 return;
103 skb_reserve(skb, LL_RESERVED_SPACE(dev)); 103 skb_reserve(skb, LL_RESERVED_SPACE(dev));
104 skb_reset_network_header(skb); 104 skb_reset_network_header(skb);
@@ -116,7 +116,7 @@ static void oz_send_conn_rsp(struct oz_pd *pd, u8 status)
116 oz_hdr->control = (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT); 116 oz_hdr->control = (OZ_PROTOCOL_VERSION<<OZ_VERSION_SHIFT);
117 oz_hdr->last_pkt_num = 0; 117 oz_hdr->last_pkt_num = 0;
118 put_unaligned(0, &oz_hdr->pkt_num); 118 put_unaligned(0, &oz_hdr->pkt_num);
119 oz_event_log(OZ_EVT_CONNECT_RSP, 0, 0, 0, 0); 119 oz_event_log(OZ_EVT_CONNECT_RSP, 0, 0, NULL, 0);
120 elt->type = OZ_ELT_CONNECT_RSP; 120 elt->type = OZ_ELT_CONNECT_RSP;
121 elt->length = sizeof(struct oz_elt_connect_rsp); 121 elt->length = sizeof(struct oz_elt_connect_rsp);
122 memset(body, 0, sizeof(struct oz_elt_connect_rsp)); 122 memset(body, 0, sizeof(struct oz_elt_connect_rsp));
@@ -171,7 +171,7 @@ static void pd_set_presleep(struct oz_pd *pd, u8 presleep)
171 * Context: softirq-serialized 171 * Context: softirq-serialized
172 */ 172 */
173static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt, 173static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt,
174 u8 *pd_addr, struct net_device *net_dev) 174 const u8 *pd_addr, struct net_device *net_dev)
175{ 175{
176 struct oz_pd *pd; 176 struct oz_pd *pd;
177 struct oz_elt_connect_req *body = 177 struct oz_elt_connect_req *body =
@@ -179,17 +179,17 @@ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt,
179 u8 rsp_status = OZ_STATUS_SUCCESS; 179 u8 rsp_status = OZ_STATUS_SUCCESS;
180 u8 stop_needed = 0; 180 u8 stop_needed = 0;
181 u16 new_apps = g_apps; 181 u16 new_apps = g_apps;
182 struct net_device *old_net_dev = 0; 182 struct net_device *old_net_dev = NULL;
183 struct oz_pd *free_pd = 0; 183 struct oz_pd *free_pd = NULL;
184 if (cur_pd) { 184 if (cur_pd) {
185 pd = cur_pd; 185 pd = cur_pd;
186 spin_lock_bh(&g_polling_lock); 186 spin_lock_bh(&g_polling_lock);
187 } else { 187 } else {
188 struct oz_pd *pd2 = 0; 188 struct oz_pd *pd2 = NULL;
189 struct list_head *e; 189 struct list_head *e;
190 pd = oz_pd_alloc(pd_addr); 190 pd = oz_pd_alloc(pd_addr);
191 if (pd == 0) 191 if (pd == NULL)
192 return 0; 192 return NULL;
193 pd->last_rx_time_j = jiffies; 193 pd->last_rx_time_j = jiffies;
194 spin_lock_bh(&g_polling_lock); 194 spin_lock_bh(&g_polling_lock);
195 list_for_each(e, &g_pd_list) { 195 list_for_each(e, &g_pd_list) {
@@ -203,9 +203,9 @@ static struct oz_pd *oz_connect_req(struct oz_pd *cur_pd, struct oz_elt *elt,
203 if (pd != pd2) 203 if (pd != pd2)
204 list_add_tail(&pd->link, &g_pd_list); 204 list_add_tail(&pd->link, &g_pd_list);
205 } 205 }
206 if (pd == 0) { 206 if (pd == NULL) {
207 spin_unlock_bh(&g_polling_lock); 207 spin_unlock_bh(&g_polling_lock);
208 return 0; 208 return NULL;
209 } 209 }
210 if (pd->net_dev != net_dev) { 210 if (pd->net_dev != net_dev) {
211 old_net_dev = pd->net_dev; 211 old_net_dev = pd->net_dev;
@@ -294,7 +294,7 @@ done:
294 if (stop_needed) 294 if (stop_needed)
295 oz_pd_stop(pd); 295 oz_pd_stop(pd);
296 oz_pd_put(pd); 296 oz_pd_put(pd);
297 pd = 0; 297 pd = NULL;
298 } 298 }
299 if (old_net_dev) 299 if (old_net_dev)
300 dev_put(old_net_dev); 300 dev_put(old_net_dev);
@@ -306,7 +306,7 @@ done:
306 * Context: softirq-serialized 306 * Context: softirq-serialized
307 */ 307 */
308static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index, 308static void oz_add_farewell(struct oz_pd *pd, u8 ep_num, u8 index,
309 u8 *report, u8 len) 309 const u8 *report, u8 len)
310{ 310{
311 struct oz_farewell *f; 311 struct oz_farewell *f;
312 struct oz_farewell *f2; 312 struct oz_farewell *f2;
@@ -340,14 +340,14 @@ static void oz_rx_frame(struct sk_buff *skb)
340 u8 *src_addr; 340 u8 *src_addr;
341 struct oz_elt *elt; 341 struct oz_elt *elt;
342 int length; 342 int length;
343 struct oz_pd *pd = 0; 343 struct oz_pd *pd = NULL;
344 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb); 344 struct oz_hdr *oz_hdr = (struct oz_hdr *)skb_network_header(skb);
345 int dup = 0; 345 int dup = 0;
346 u32 pkt_num; 346 u32 pkt_num;
347 347
348 oz_event_log(OZ_EVT_RX_PROCESS, 0, 348 oz_event_log(OZ_EVT_RX_PROCESS, 0,
349 (((u16)oz_hdr->control)<<8)|oz_hdr->last_pkt_num, 349 (((u16)oz_hdr->control)<<8)|oz_hdr->last_pkt_num,
350 0, oz_hdr->pkt_num); 350 NULL, oz_hdr->pkt_num);
351 oz_trace2(OZ_TRACE_RX_FRAMES, 351 oz_trace2(OZ_TRACE_RX_FRAMES,
352 "RX frame PN=0x%x LPN=0x%x control=0x%x\n", 352 "RX frame PN=0x%x LPN=0x%x control=0x%x\n",
353 oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control); 353 oz_hdr->pkt_num, oz_hdr->last_pkt_num, oz_hdr->control);
@@ -402,7 +402,7 @@ static void oz_rx_frame(struct sk_buff *skb)
402 break; 402 break;
403 switch (elt->type) { 403 switch (elt->type) {
404 case OZ_ELT_CONNECT_REQ: 404 case OZ_ELT_CONNECT_REQ:
405 oz_event_log(OZ_EVT_CONNECT_REQ, 0, 0, 0, 0); 405 oz_event_log(OZ_EVT_CONNECT_REQ, 0, 0, NULL, 0);
406 oz_trace("RX: OZ_ELT_CONNECT_REQ\n"); 406 oz_trace("RX: OZ_ELT_CONNECT_REQ\n");
407 pd = oz_connect_req(pd, elt, src_addr, skb->dev); 407 pd = oz_connect_req(pd, elt, src_addr, skb->dev);
408 break; 408 break;
@@ -456,7 +456,7 @@ done:
456 */ 456 */
457void oz_protocol_term(void) 457void oz_protocol_term(void)
458{ 458{
459 struct list_head *chain = 0; 459 struct list_head *chain;
460 del_timer_sync(&g_timer); 460 del_timer_sync(&g_timer);
461 /* Walk the list of bindings and remove each one. 461 /* Walk the list of bindings and remove each one.
462 */ 462 */
@@ -487,7 +487,7 @@ void oz_protocol_term(void)
487 spin_lock_bh(&g_polling_lock); 487 spin_lock_bh(&g_polling_lock);
488 } 488 }
489 chain = g_timer_pool; 489 chain = g_timer_pool;
490 g_timer_pool = 0; 490 g_timer_pool = NULL;
491 spin_unlock_bh(&g_polling_lock); 491 spin_unlock_bh(&g_polling_lock);
492 while (chain) { 492 while (chain) {
493 struct oz_timer *t = container_of(chain, struct oz_timer, link); 493 struct oz_timer *t = container_of(chain, struct oz_timer, link);
@@ -534,25 +534,25 @@ static void oz_protocol_timer(unsigned long arg)
534 /* This happens if we remove the current timer but can't stop 534 /* This happens if we remove the current timer but can't stop
535 * the timer from firing. In this case just get out. 535 * the timer from firing. In this case just get out.
536 */ 536 */
537 oz_event_log(OZ_EVT_TIMER, 0, 0, 0, 0); 537 oz_event_log(OZ_EVT_TIMER, 0, 0, NULL, 0);
538 spin_unlock_bh(&g_polling_lock); 538 spin_unlock_bh(&g_polling_lock);
539 return; 539 return;
540 } 540 }
541 g_timer_state = OZ_TIMER_IN_HANDLER; 541 g_timer_state = OZ_TIMER_IN_HANDLER;
542 t = g_cur_timer; 542 t = g_cur_timer;
543 g_cur_timer = 0; 543 g_cur_timer = NULL;
544 list_del(&t->link); 544 list_del(&t->link);
545 spin_unlock_bh(&g_polling_lock); 545 spin_unlock_bh(&g_polling_lock);
546 do { 546 do {
547 pd = t->pd; 547 pd = t->pd;
548 oz_event_log(OZ_EVT_TIMER, 0, t->type, 0, 0); 548 oz_event_log(OZ_EVT_TIMER, 0, t->type, NULL, 0);
549 oz_pd_handle_timer(pd, t->type); 549 oz_pd_handle_timer(pd, t->type);
550 spin_lock_bh(&g_polling_lock); 550 spin_lock_bh(&g_polling_lock);
551 if (g_timer_pool_count < OZ_MAX_TIMER_POOL_SIZE) { 551 if (g_timer_pool_count < OZ_MAX_TIMER_POOL_SIZE) {
552 t->link.next = g_timer_pool; 552 t->link.next = g_timer_pool;
553 g_timer_pool = &t->link; 553 g_timer_pool = &t->link;
554 g_timer_pool_count++; 554 g_timer_pool_count++;
555 t = 0; 555 t = NULL;
556 } 556 }
557 if (!list_empty(&g_timer_list)) { 557 if (!list_empty(&g_timer_list)) {
558 t2 = container_of(g_timer_list.next, 558 t2 = container_of(g_timer_list.next,
@@ -560,9 +560,9 @@ static void oz_protocol_timer(unsigned long arg)
560 if (time_before_eq(t2->due_time, jiffies)) 560 if (time_before_eq(t2->due_time, jiffies))
561 list_del(&t2->link); 561 list_del(&t2->link);
562 else 562 else
563 t2 = 0; 563 t2 = NULL;
564 } else { 564 } else {
565 t2 = 0; 565 t2 = NULL;
566 } 566 }
567 spin_unlock_bh(&g_polling_lock); 567 spin_unlock_bh(&g_polling_lock);
568 oz_pd_put(pd); 568 oz_pd_put(pd);
@@ -583,12 +583,12 @@ static void oz_protocol_timer_start(void)
583 container_of(g_timer_list.next, struct oz_timer, link); 583 container_of(g_timer_list.next, struct oz_timer, link);
584 if (g_timer_state == OZ_TIMER_SET) { 584 if (g_timer_state == OZ_TIMER_SET) {
585 oz_event_log(OZ_EVT_TIMER_CTRL, 3, 585 oz_event_log(OZ_EVT_TIMER_CTRL, 3,
586 (u16)g_cur_timer->type, 0, 586 (u16)g_cur_timer->type, NULL,
587 (unsigned)g_cur_timer->due_time); 587 (unsigned)g_cur_timer->due_time);
588 mod_timer(&g_timer, g_cur_timer->due_time); 588 mod_timer(&g_timer, g_cur_timer->due_time);
589 } else { 589 } else {
590 oz_event_log(OZ_EVT_TIMER_CTRL, 4, 590 oz_event_log(OZ_EVT_TIMER_CTRL, 4,
591 (u16)g_cur_timer->type, 0, 591 (u16)g_cur_timer->type, NULL,
592 (unsigned)g_cur_timer->due_time); 592 (unsigned)g_cur_timer->due_time);
593 g_timer.expires = g_cur_timer->due_time; 593 g_timer.expires = g_cur_timer->due_time;
594 g_timer.function = oz_protocol_timer; 594 g_timer.function = oz_protocol_timer;
@@ -608,9 +608,9 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time,
608 int remove) 608 int remove)
609{ 609{
610 struct list_head *e; 610 struct list_head *e;
611 struct oz_timer *t = 0; 611 struct oz_timer *t = NULL;
612 int restart_needed = 0; 612 int restart_needed = 0;
613 oz_event_log(OZ_EVT_TIMER_CTRL, 1, (u16)type, 0, (unsigned)due_time); 613 oz_event_log(OZ_EVT_TIMER_CTRL, 1, (u16)type, NULL, (unsigned)due_time);
614 spin_lock(&g_polling_lock); 614 spin_lock(&g_polling_lock);
615 if (remove) { 615 if (remove) {
616 list_for_each(e, &g_timer_list) { 616 list_for_each(e, &g_timer_list) {
@@ -618,12 +618,12 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time,
618 if ((t->pd == pd) && (t->type == type)) { 618 if ((t->pd == pd) && (t->type == type)) {
619 if (g_cur_timer == t) { 619 if (g_cur_timer == t) {
620 restart_needed = 1; 620 restart_needed = 1;
621 g_cur_timer = 0; 621 g_cur_timer = NULL;
622 } 622 }
623 list_del(e); 623 list_del(e);
624 break; 624 break;
625 } 625 }
626 t = 0; 626 t = NULL;
627 } 627 }
628 } 628 }
629 if (!t) { 629 if (!t) {
@@ -647,7 +647,7 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time,
647 t2 = container_of(e, struct oz_timer, link); 647 t2 = container_of(e, struct oz_timer, link);
648 if (time_before(due_time, t2->due_time)) { 648 if (time_before(due_time, t2->due_time)) {
649 if (t2 == g_cur_timer) { 649 if (t2 == g_cur_timer) {
650 g_cur_timer = 0; 650 g_cur_timer = NULL;
651 restart_needed = 1; 651 restart_needed = 1;
652 } 652 }
653 break; 653 break;
@@ -668,18 +668,18 @@ void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time,
668 */ 668 */
669void oz_timer_delete(struct oz_pd *pd, int type) 669void oz_timer_delete(struct oz_pd *pd, int type)
670{ 670{
671 struct list_head *chain = 0; 671 struct list_head *chain = NULL;
672 struct oz_timer *t; 672 struct oz_timer *t;
673 struct oz_timer *n; 673 struct oz_timer *n;
674 int restart_needed = 0; 674 int restart_needed = 0;
675 int release = 0; 675 int release = 0;
676 oz_event_log(OZ_EVT_TIMER_CTRL, 2, (u16)type, 0, 0); 676 oz_event_log(OZ_EVT_TIMER_CTRL, 2, (u16)type, NULL, 0);
677 spin_lock(&g_polling_lock); 677 spin_lock(&g_polling_lock);
678 list_for_each_entry_safe(t, n, &g_timer_list, link) { 678 list_for_each_entry_safe(t, n, &g_timer_list, link) {
679 if ((t->pd == pd) && ((type == 0) || (t->type == type))) { 679 if ((t->pd == pd) && ((type == 0) || (t->type == type))) {
680 if (g_cur_timer == t) { 680 if (g_cur_timer == t) {
681 restart_needed = 1; 681 restart_needed = 1;
682 g_cur_timer = 0; 682 g_cur_timer = NULL;
683 del_timer(&g_timer); 683 del_timer(&g_timer);
684 } 684 }
685 list_del(&t->link); 685 list_del(&t->link);
@@ -734,7 +734,7 @@ void oz_pd_request_heartbeat(struct oz_pd *pd)
734/*------------------------------------------------------------------------------ 734/*------------------------------------------------------------------------------
735 * Context: softirq or process 735 * Context: softirq or process
736 */ 736 */
737struct oz_pd *oz_pd_find(u8 *mac_addr) 737struct oz_pd *oz_pd_find(const u8 *mac_addr)
738{ 738{
739 struct oz_pd *pd; 739 struct oz_pd *pd;
740 struct list_head *e; 740 struct list_head *e;
@@ -748,7 +748,7 @@ struct oz_pd *oz_pd_find(u8 *mac_addr)
748 } 748 }
749 } 749 }
750 spin_unlock_bh(&g_polling_lock); 750 spin_unlock_bh(&g_polling_lock);
751 return 0; 751 return NULL;
752} 752}
753/*------------------------------------------------------------------------------ 753/*------------------------------------------------------------------------------
754 * Context: process 754 * Context: process
@@ -770,9 +770,9 @@ void oz_app_enable(int app_id, int enable)
770static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev, 770static int oz_pkt_recv(struct sk_buff *skb, struct net_device *dev,
771 struct packet_type *pt, struct net_device *orig_dev) 771 struct packet_type *pt, struct net_device *orig_dev)
772{ 772{
773 oz_event_log(OZ_EVT_RX_FRAME, 0, 0, 0, 0); 773 oz_event_log(OZ_EVT_RX_FRAME, 0, 0, NULL, 0);
774 skb = skb_share_check(skb, GFP_ATOMIC); 774 skb = skb_share_check(skb, GFP_ATOMIC);
775 if (skb == 0) 775 if (skb == NULL)
776 return 0; 776 return 0;
777 spin_lock_bh(&g_rx_queue.lock); 777 spin_lock_bh(&g_rx_queue.lock);
778 if (g_processing_rx) { 778 if (g_processing_rx) {
@@ -815,14 +815,14 @@ void oz_binding_add(char *net_dev)
815 oz_trace("Adding binding: %s\n", net_dev); 815 oz_trace("Adding binding: %s\n", net_dev);
816 binding->ptype.dev = 816 binding->ptype.dev =
817 dev_get_by_name(&init_net, net_dev); 817 dev_get_by_name(&init_net, net_dev);
818 if (binding->ptype.dev == 0) { 818 if (binding->ptype.dev == NULL) {
819 oz_trace("Netdev %s not found\n", net_dev); 819 oz_trace("Netdev %s not found\n", net_dev);
820 kfree(binding); 820 kfree(binding);
821 binding = 0; 821 binding = NULL;
822 } 822 }
823 } else { 823 } else {
824 oz_trace("Binding to all netcards\n"); 824 oz_trace("Binding to all netcards\n");
825 binding->ptype.dev = 0; 825 binding->ptype.dev = NULL;
826 } 826 }
827 if (binding) { 827 if (binding) {
828 dev_add_pack(&binding->ptype); 828 dev_add_pack(&binding->ptype);
@@ -876,7 +876,7 @@ static void pd_stop_all_for_device(struct net_device *net_dev)
876 */ 876 */
877void oz_binding_remove(char *net_dev) 877void oz_binding_remove(char *net_dev)
878{ 878{
879 struct oz_binding *binding = 0; 879 struct oz_binding *binding;
880 struct oz_binding **link; 880 struct oz_binding **link;
881 oz_trace("Removing binding: %s\n", net_dev); 881 oz_trace("Removing binding: %s\n", net_dev);
882 spin_lock_bh(&g_binding_lock); 882 spin_lock_bh(&g_binding_lock);
@@ -923,7 +923,7 @@ int oz_protocol_init(char *devs)
923{ 923{
924 skb_queue_head_init(&g_rx_queue); 924 skb_queue_head_init(&g_rx_queue);
925 if (devs && (devs[0] == '*')) { 925 if (devs && (devs[0] == '*')) {
926 oz_binding_add(0); 926 oz_binding_add(NULL);
927 } else { 927 } else {
928 char d[32]; 928 char d[32];
929 while (*devs) { 929 while (*devs) {
diff --git a/drivers/staging/ozwpan/ozproto.h b/drivers/staging/ozwpan/ozproto.h
index 755a08d0e1ca..93bb4c0172e0 100644
--- a/drivers/staging/ozwpan/ozproto.h
+++ b/drivers/staging/ozwpan/ozproto.h
@@ -62,7 +62,7 @@ int oz_protocol_init(char *devs);
62void oz_protocol_term(void); 62void oz_protocol_term(void);
63int oz_get_pd_list(struct oz_mac_addr *addr, int max_count); 63int oz_get_pd_list(struct oz_mac_addr *addr, int max_count);
64void oz_app_enable(int app_id, int enable); 64void oz_app_enable(int app_id, int enable);
65struct oz_pd *oz_pd_find(u8 *mac_addr); 65struct oz_pd *oz_pd_find(const u8 *mac_addr);
66void oz_binding_add(char *net_dev); 66void oz_binding_add(char *net_dev);
67void oz_binding_remove(char *net_dev); 67void oz_binding_remove(char *net_dev);
68void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time, 68void oz_timer_add(struct oz_pd *pd, int type, unsigned long due_time,
diff --git a/drivers/staging/ozwpan/ozusbif.h b/drivers/staging/ozwpan/ozusbif.h
index 3acf5980d7cc..8531438d7586 100644
--- a/drivers/staging/ozwpan/ozusbif.h
+++ b/drivers/staging/ozwpan/ozusbif.h
@@ -21,7 +21,7 @@ int oz_usb_stream_delete(void *hpd, u8 ep_num);
21/* Request functions. 21/* Request functions.
22 */ 22 */
23int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup, 23int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup,
24 u8 *data, int data_len); 24 const u8 *data, int data_len);
25int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, 25int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type,
26 u8 index, u16 windex, int offset, int len); 26 u8 index, u16 windex, int offset, int len);
27int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb); 27int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb);
@@ -30,13 +30,13 @@ void oz_usb_request_heartbeat(void *hpd);
30/* Confirmation functions. 30/* Confirmation functions.
31 */ 31 */
32void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, 32void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status,
33 u8 *desc, int length, int offset, int total_size); 33 const u8 *desc, int length, int offset, int total_size);
34void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, 34void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode,
35 u8 *data, int data_len); 35 const u8 *data, int data_len);
36 36
37/* Indication functions. 37/* Indication functions.
38 */ 38 */
39void oz_hcd_data_ind(void *hport, u8 endpoint, u8 *data, int data_len); 39void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len);
40 40
41int oz_hcd_heartbeat(void *hport); 41int oz_hcd_heartbeat(void *hport);
42 42
diff --git a/drivers/staging/ozwpan/ozusbsvc.c b/drivers/staging/ozwpan/ozusbsvc.c
index 8fa7f256ad8c..543a9415975c 100644
--- a/drivers/staging/ozwpan/ozusbsvc.c
+++ b/drivers/staging/ozwpan/ozusbsvc.c
@@ -34,7 +34,7 @@
34 */ 34 */
35int oz_usb_init(void) 35int oz_usb_init(void)
36{ 36{
37 oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_USB, 0, 0); 37 oz_event_log(OZ_EVT_SERVICE, 1, OZ_APPID_USB, NULL, 0);
38 return oz_hcd_init(); 38 return oz_hcd_init();
39} 39}
40/*------------------------------------------------------------------------------ 40/*------------------------------------------------------------------------------
@@ -43,7 +43,7 @@ int oz_usb_init(void)
43 */ 43 */
44void oz_usb_term(void) 44void oz_usb_term(void)
45{ 45{
46 oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_USB, 0, 0); 46 oz_event_log(OZ_EVT_SERVICE, 2, OZ_APPID_USB, NULL, 0);
47 oz_hcd_term(); 47 oz_hcd_term();
48} 48}
49/*------------------------------------------------------------------------------ 49/*------------------------------------------------------------------------------
@@ -54,8 +54,8 @@ int oz_usb_start(struct oz_pd *pd, int resume)
54{ 54{
55 int rc = 0; 55 int rc = 0;
56 struct oz_usb_ctx *usb_ctx; 56 struct oz_usb_ctx *usb_ctx;
57 struct oz_usb_ctx *old_ctx = 0; 57 struct oz_usb_ctx *old_ctx;
58 oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_USB, 0, resume); 58 oz_event_log(OZ_EVT_SERVICE, 3, OZ_APPID_USB, NULL, resume);
59 if (resume) { 59 if (resume) {
60 oz_trace("USB service resumed.\n"); 60 oz_trace("USB service resumed.\n");
61 return 0; 61 return 0;
@@ -65,7 +65,7 @@ int oz_usb_start(struct oz_pd *pd, int resume)
65 * has a USB context then we will destroy it. 65 * has a USB context then we will destroy it.
66 */ 66 */
67 usb_ctx = kzalloc(sizeof(struct oz_usb_ctx), GFP_ATOMIC); 67 usb_ctx = kzalloc(sizeof(struct oz_usb_ctx), GFP_ATOMIC);
68 if (usb_ctx == 0) 68 if (usb_ctx == NULL)
69 return -ENOMEM; 69 return -ENOMEM;
70 atomic_set(&usb_ctx->ref_count, 1); 70 atomic_set(&usb_ctx->ref_count, 1);
71 usb_ctx->pd = pd; 71 usb_ctx->pd = pd;
@@ -76,7 +76,7 @@ int oz_usb_start(struct oz_pd *pd, int resume)
76 */ 76 */
77 spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); 77 spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]);
78 old_ctx = pd->app_ctx[OZ_APPID_USB-1]; 78 old_ctx = pd->app_ctx[OZ_APPID_USB-1];
79 if (old_ctx == 0) 79 if (old_ctx == NULL)
80 pd->app_ctx[OZ_APPID_USB-1] = usb_ctx; 80 pd->app_ctx[OZ_APPID_USB-1] = usb_ctx;
81 oz_usb_get(pd->app_ctx[OZ_APPID_USB-1]); 81 oz_usb_get(pd->app_ctx[OZ_APPID_USB-1]);
82 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); 82 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
@@ -98,10 +98,10 @@ int oz_usb_start(struct oz_pd *pd, int resume)
98 oz_hcd_pd_reset(usb_ctx, usb_ctx->hport); 98 oz_hcd_pd_reset(usb_ctx, usb_ctx->hport);
99 } else { 99 } else {
100 usb_ctx->hport = oz_hcd_pd_arrived(usb_ctx); 100 usb_ctx->hport = oz_hcd_pd_arrived(usb_ctx);
101 if (usb_ctx->hport == 0) { 101 if (usb_ctx->hport == NULL) {
102 oz_trace("USB hub returned null port.\n"); 102 oz_trace("USB hub returned null port.\n");
103 spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); 103 spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]);
104 pd->app_ctx[OZ_APPID_USB-1] = 0; 104 pd->app_ctx[OZ_APPID_USB-1] = NULL;
105 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); 105 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
106 oz_usb_put(usb_ctx); 106 oz_usb_put(usb_ctx);
107 rc = -1; 107 rc = -1;
@@ -117,14 +117,14 @@ int oz_usb_start(struct oz_pd *pd, int resume)
117void oz_usb_stop(struct oz_pd *pd, int pause) 117void oz_usb_stop(struct oz_pd *pd, int pause)
118{ 118{
119 struct oz_usb_ctx *usb_ctx; 119 struct oz_usb_ctx *usb_ctx;
120 oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_USB, 0, pause); 120 oz_event_log(OZ_EVT_SERVICE, 4, OZ_APPID_USB, NULL, pause);
121 if (pause) { 121 if (pause) {
122 oz_trace("USB service paused.\n"); 122 oz_trace("USB service paused.\n");
123 return; 123 return;
124 } 124 }
125 spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]); 125 spin_lock_bh(&pd->app_lock[OZ_APPID_USB-1]);
126 usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB-1]; 126 usb_ctx = (struct oz_usb_ctx *)pd->app_ctx[OZ_APPID_USB-1];
127 pd->app_ctx[OZ_APPID_USB-1] = 0; 127 pd->app_ctx[OZ_APPID_USB-1] = NULL;
128 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); 128 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
129 if (usb_ctx) { 129 if (usb_ctx) {
130 unsigned long tout = jiffies + HZ; 130 unsigned long tout = jiffies + HZ;
@@ -182,7 +182,7 @@ int oz_usb_heartbeat(struct oz_pd *pd)
182 if (usb_ctx) 182 if (usb_ctx)
183 oz_usb_get(usb_ctx); 183 oz_usb_get(usb_ctx);
184 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); 184 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
185 if (usb_ctx == 0) 185 if (usb_ctx == NULL)
186 return rc; 186 return rc;
187 if (usb_ctx->stopped) 187 if (usb_ctx->stopped)
188 goto done; 188 goto done;
diff --git a/drivers/staging/ozwpan/ozusbsvc1.c b/drivers/staging/ozwpan/ozusbsvc1.c
index 66bd576bb5e9..4e4b650fee3f 100644
--- a/drivers/staging/ozwpan/ozusbsvc1.c
+++ b/drivers/staging/ozwpan/ozusbsvc1.c
@@ -71,7 +71,7 @@ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type,
71 oz_trace(" len = 0x%x\n", len); 71 oz_trace(" len = 0x%x\n", len);
72 if (len > 200) 72 if (len > 200)
73 len = 200; 73 len = 200;
74 if (ei == 0) 74 if (ei == NULL)
75 return -1; 75 return -1;
76 elt = (struct oz_elt *)ei->data; 76 elt = (struct oz_elt *)ei->data;
77 elt->length = sizeof(struct oz_get_desc_req); 77 elt->length = sizeof(struct oz_get_desc_req);
@@ -97,7 +97,7 @@ static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index)
97 struct oz_elt_buf *eb = &pd->elt_buff; 97 struct oz_elt_buf *eb = &pd->elt_buff;
98 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); 98 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
99 struct oz_set_config_req *body; 99 struct oz_set_config_req *body;
100 if (ei == 0) 100 if (ei == NULL)
101 return -1; 101 return -1;
102 elt = (struct oz_elt *)ei->data; 102 elt = (struct oz_elt *)ei->data;
103 elt->length = sizeof(struct oz_set_config_req); 103 elt->length = sizeof(struct oz_set_config_req);
@@ -118,7 +118,7 @@ static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt)
118 struct oz_elt_buf *eb = &pd->elt_buff; 118 struct oz_elt_buf *eb = &pd->elt_buff;
119 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); 119 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
120 struct oz_set_interface_req *body; 120 struct oz_set_interface_req *body;
121 if (ei == 0) 121 if (ei == NULL)
122 return -1; 122 return -1;
123 elt = (struct oz_elt *)ei->data; 123 elt = (struct oz_elt *)ei->data;
124 elt->length = sizeof(struct oz_set_interface_req); 124 elt->length = sizeof(struct oz_set_interface_req);
@@ -141,7 +141,7 @@ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type,
141 struct oz_elt_buf *eb = &pd->elt_buff; 141 struct oz_elt_buf *eb = &pd->elt_buff;
142 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); 142 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
143 struct oz_feature_req *body; 143 struct oz_feature_req *body;
144 if (ei == 0) 144 if (ei == NULL)
145 return -1; 145 return -1;
146 elt = (struct oz_elt *)ei->data; 146 elt = (struct oz_elt *)ei->data;
147 elt->length = sizeof(struct oz_feature_req); 147 elt->length = sizeof(struct oz_feature_req);
@@ -157,7 +157,7 @@ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type,
157 * Context: tasklet 157 * Context: tasklet
158 */ 158 */
159static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, 159static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type,
160 u8 request, __le16 value, __le16 index, u8 *data, int data_len) 160 u8 request, __le16 value, __le16 index, const u8 *data, int data_len)
161{ 161{
162 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; 162 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd;
163 struct oz_pd *pd = usb_ctx->pd; 163 struct oz_pd *pd = usb_ctx->pd;
@@ -165,7 +165,7 @@ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type,
165 struct oz_elt_buf *eb = &pd->elt_buff; 165 struct oz_elt_buf *eb = &pd->elt_buff;
166 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff); 166 struct oz_elt_info *ei = oz_elt_info_alloc(&pd->elt_buff);
167 struct oz_vendor_class_req *body; 167 struct oz_vendor_class_req *body;
168 if (ei == 0) 168 if (ei == NULL)
169 return -1; 169 return -1;
170 elt = (struct oz_elt *)ei->data; 170 elt = (struct oz_elt *)ei->data;
171 elt->length = sizeof(struct oz_vendor_class_req) - 1 + data_len; 171 elt->length = sizeof(struct oz_vendor_class_req) - 1 + data_len;
@@ -184,7 +184,7 @@ static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type,
184 * Context: tasklet 184 * Context: tasklet
185 */ 185 */
186int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup, 186int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup,
187 u8 *data, int data_len) 187 const u8 *data, int data_len)
188{ 188{
189 unsigned wvalue = le16_to_cpu(setup->wValue); 189 unsigned wvalue = le16_to_cpu(setup->wValue);
190 unsigned windex = le16_to_cpu(setup->wIndex); 190 unsigned windex = le16_to_cpu(setup->wIndex);
@@ -264,7 +264,7 @@ int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb)
264 int unit_count; 264 int unit_count;
265 int unit_size; 265 int unit_size;
266 int rem; 266 int rem;
267 if (ei == 0) 267 if (ei == NULL)
268 return -1; 268 return -1;
269 rem = MAX_ISOC_FIXED_DATA; 269 rem = MAX_ISOC_FIXED_DATA;
270 elt = (struct oz_elt *)ei->data; 270 elt = (struct oz_elt *)ei->data;
@@ -305,7 +305,7 @@ int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb)
305/*------------------------------------------------------------------------------ 305/*------------------------------------------------------------------------------
306 * Context: softirq-serialized 306 * Context: softirq-serialized
307 */ 307 */
308void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx, 308static void oz_usb_handle_ep_data(struct oz_usb_ctx *usb_ctx,
309 struct oz_usb_hdr *usb_hdr, int len) 309 struct oz_usb_hdr *usb_hdr, int len)
310{ 310{
311 struct oz_data *data_hdr = (struct oz_data *)usb_hdr; 311 struct oz_data *data_hdr = (struct oz_data *)usb_hdr;
@@ -359,7 +359,7 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt)
359 if (usb_ctx) 359 if (usb_ctx)
360 oz_usb_get(usb_ctx); 360 oz_usb_get(usb_ctx);
361 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); 361 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
362 if (usb_ctx == 0) 362 if (usb_ctx == NULL)
363 return; /* Context has gone so nothing to do. */ 363 return; /* Context has gone so nothing to do. */
364 if (usb_ctx->stopped) 364 if (usb_ctx->stopped)
365 goto done; 365 goto done;
@@ -391,14 +391,14 @@ void oz_usb_rx(struct oz_pd *pd, struct oz_elt *elt)
391 struct oz_set_config_rsp *body = 391 struct oz_set_config_rsp *body =
392 (struct oz_set_config_rsp *)usb_hdr; 392 (struct oz_set_config_rsp *)usb_hdr;
393 oz_hcd_control_cnf(usb_ctx->hport, body->req_id, 393 oz_hcd_control_cnf(usb_ctx->hport, body->req_id,
394 body->rcode, 0, 0); 394 body->rcode, NULL, 0);
395 } 395 }
396 break; 396 break;
397 case OZ_SET_INTERFACE_RSP: { 397 case OZ_SET_INTERFACE_RSP: {
398 struct oz_set_interface_rsp *body = 398 struct oz_set_interface_rsp *body =
399 (struct oz_set_interface_rsp *)usb_hdr; 399 (struct oz_set_interface_rsp *)usb_hdr;
400 oz_hcd_control_cnf(usb_ctx->hport, 400 oz_hcd_control_cnf(usb_ctx->hport,
401 body->req_id, body->rcode, 0, 0); 401 body->req_id, body->rcode, NULL, 0);
402 } 402 }
403 break; 403 break;
404 case OZ_VENDOR_CLASS_RSP: { 404 case OZ_VENDOR_CLASS_RSP: {
@@ -427,7 +427,7 @@ void oz_usb_farewell(struct oz_pd *pd, u8 ep_num, u8 *data, u8 len)
427 if (usb_ctx) 427 if (usb_ctx)
428 oz_usb_get(usb_ctx); 428 oz_usb_get(usb_ctx);
429 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]); 429 spin_unlock_bh(&pd->app_lock[OZ_APPID_USB-1]);
430 if (usb_ctx == 0) 430 if (usb_ctx == NULL)
431 return; /* Context has gone so nothing to do. */ 431 return; /* Context has gone so nothing to do. */
432 if (!usb_ctx->stopped) { 432 if (!usb_ctx->stopped) {
433 oz_trace("Farewell indicated ep = 0x%x\n", ep_num); 433 oz_trace("Farewell indicated ep = 0x%x\n", ep_num);
diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
index e3113ecefefd..c54df3948e20 100644
--- a/drivers/staging/panel/panel.c
+++ b/drivers/staging/panel/panel.c
@@ -185,7 +185,7 @@ struct logical_input {
185 } u; 185 } u;
186}; 186};
187 187
188LIST_HEAD(logical_inputs); /* list of all defined logical inputs */ 188static LIST_HEAD(logical_inputs); /* list of all defined logical inputs */
189 189
190/* physical contacts history 190/* physical contacts history
191 * Physical contacts are a 45 bits string of 9 groups of 5 bits each. 191 * Physical contacts are a 45 bits string of 9 groups of 5 bits each.
@@ -527,10 +527,10 @@ MODULE_PARM_DESC(lcd_cl_pin,
527 "# of the // port pin connected to serial LCD 'SCL' " 527 "# of the // port pin connected to serial LCD 'SCL' "
528 "signal, with polarity (-17..17)"); 528 "signal, with polarity (-17..17)");
529 529
530static unsigned char *lcd_char_conv; 530static const unsigned char *lcd_char_conv;
531 531
532/* for some LCD drivers (ks0074) we need a charset conversion table. */ 532/* for some LCD drivers (ks0074) we need a charset conversion table. */
533static unsigned char lcd_char_conv_ks0074[256] = { 533static const unsigned char lcd_char_conv_ks0074[256] = {
534 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */ 534 /* 0|8 1|9 2|A 3|B 4|C 5|D 6|E 7|F */
535 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 535 /* 0x00 */ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
536 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 536 /* 0x08 */ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -566,7 +566,7 @@ static unsigned char lcd_char_conv_ks0074[256] = {
566 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79, 566 /* 0xF8 */ 0xac, 0xa6, 0xea, 0xef, 0x7e, 0xeb, 0xb2, 0x79,
567}; 567};
568 568
569char old_keypad_profile[][4][9] = { 569static const char old_keypad_profile[][4][9] = {
570 {"S0", "Left\n", "Left\n", ""}, 570 {"S0", "Left\n", "Left\n", ""},
571 {"S1", "Down\n", "Down\n", ""}, 571 {"S1", "Down\n", "Down\n", ""},
572 {"S2", "Up\n", "Up\n", ""}, 572 {"S2", "Up\n", "Up\n", ""},
@@ -577,7 +577,7 @@ char old_keypad_profile[][4][9] = {
577}; 577};
578 578
579/* signals, press, repeat, release */ 579/* signals, press, repeat, release */
580char new_keypad_profile[][4][9] = { 580static const char new_keypad_profile[][4][9] = {
581 {"S0", "Left\n", "Left\n", ""}, 581 {"S0", "Left\n", "Left\n", ""},
582 {"S1", "Down\n", "Down\n", ""}, 582 {"S1", "Down\n", "Down\n", ""},
583 {"S2", "Up\n", "Up\n", ""}, 583 {"S2", "Up\n", "Up\n", ""},
@@ -590,7 +590,7 @@ char new_keypad_profile[][4][9] = {
590}; 590};
591 591
592/* signals, press, repeat, release */ 592/* signals, press, repeat, release */
593char nexcom_keypad_profile[][4][9] = { 593static const char nexcom_keypad_profile[][4][9] = {
594 {"a-p-e-", "Down\n", "Down\n", ""}, 594 {"a-p-e-", "Down\n", "Down\n", ""},
595 {"a-p-E-", "Ret\n", "Ret\n", ""}, 595 {"a-p-E-", "Ret\n", "Ret\n", ""},
596 {"a-P-E-", "Esc\n", "Esc\n", ""}, 596 {"a-P-E-", "Esc\n", "Esc\n", ""},
@@ -599,7 +599,7 @@ char nexcom_keypad_profile[][4][9] = {
599 {"", "", "", ""} 599 {"", "", "", ""}
600}; 600};
601 601
602static char (*keypad_profile)[4][9] = old_keypad_profile; 602static const char (*keypad_profile)[4][9] = old_keypad_profile;
603 603
604/* FIXME: this should be converted to a bit array containing signals states */ 604/* FIXME: this should be converted to a bit array containing signals states */
605static struct { 605static struct {
@@ -669,7 +669,7 @@ static void panel_set_bits(void)
669 * out(dport, in(dport) & d_val[2] | d_val[signal_state]) 669 * out(dport, in(dport) & d_val[2] | d_val[signal_state])
670 * out(cport, in(cport) & c_val[2] | c_val[signal_state]) 670 * out(cport, in(cport) & c_val[2] | c_val[signal_state])
671 */ 671 */
672void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val) 672static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
673{ 673{
674 int d_bit, c_bit, inv; 674 int d_bit, c_bit, inv;
675 675
@@ -1372,14 +1372,14 @@ static struct miscdevice lcd_dev = {
1372}; 1372};
1373 1373
1374/* public function usable from the kernel for any purpose */ 1374/* public function usable from the kernel for any purpose */
1375void panel_lcd_print(char *s) 1375static void panel_lcd_print(const char *s)
1376{ 1376{
1377 if (lcd_enabled && lcd_initialized) 1377 if (lcd_enabled && lcd_initialized)
1378 lcd_write(NULL, s, strlen(s), NULL); 1378 lcd_write(NULL, s, strlen(s), NULL);
1379} 1379}
1380 1380
1381/* initialize the LCD driver */ 1381/* initialize the LCD driver */
1382void lcd_init(void) 1382static void lcd_init(void)
1383{ 1383{
1384 switch (lcd_type) { 1384 switch (lcd_type) {
1385 case LCD_TYPE_OLD: 1385 case LCD_TYPE_OLD:
@@ -1638,7 +1638,7 @@ static struct miscdevice keypad_dev = {
1638 &keypad_fops 1638 &keypad_fops
1639}; 1639};
1640 1640
1641static void keypad_send_key(char *string, int max_len) 1641static void keypad_send_key(const char *string, int max_len)
1642{ 1642{
1643 if (init_in_progress) 1643 if (init_in_progress)
1644 return; 1644 return;
@@ -1929,7 +1929,7 @@ static void init_scan_timer(void)
1929 * corresponding to out and in bits respectively. 1929 * corresponding to out and in bits respectively.
1930 * returns 1 if ok, 0 if error (in which case, nothing is written). 1930 * returns 1 if ok, 0 if error (in which case, nothing is written).
1931 */ 1931 */
1932static int input_name2mask(char *name, pmask_t *mask, pmask_t *value, 1932static int input_name2mask(const char *name, pmask_t *mask, pmask_t *value,
1933 char *imask, char *omask) 1933 char *imask, char *omask)
1934{ 1934{
1935 static char sigtab[10] = "EeSsPpAaBb"; 1935 static char sigtab[10] = "EeSsPpAaBb";
@@ -1977,8 +1977,9 @@ static int input_name2mask(char *name, pmask_t *mask, pmask_t *value,
1977 * strings <press>, <repeat>, <release> for these respective events. 1977 * strings <press>, <repeat>, <release> for these respective events.
1978 * Returns the pointer to the new key if ok, NULL if the key could not be bound. 1978 * Returns the pointer to the new key if ok, NULL if the key could not be bound.
1979 */ 1979 */
1980static struct logical_input *panel_bind_key(char *name, char *press, 1980static struct logical_input *panel_bind_key(const char *name, const char *press,
1981 char *repeat, char *release) 1981 const char *repeat,
1982 const char *release)
1982{ 1983{
1983 struct logical_input *key; 1984 struct logical_input *key;
1984 1985
@@ -2178,7 +2179,7 @@ static struct parport_driver panel_driver = {
2178}; 2179};
2179 2180
2180/* init function */ 2181/* init function */
2181int panel_init(void) 2182static int panel_init(void)
2182{ 2183{
2183 /* for backwards compatibility */ 2184 /* for backwards compatibility */
2184 if (keypad_type < 0) 2185 if (keypad_type < 0)
diff --git a/drivers/staging/ramster/Kconfig b/drivers/staging/ramster/Kconfig
deleted file mode 100644
index 3abf6619dace..000000000000
--- a/drivers/staging/ramster/Kconfig
+++ /dev/null
@@ -1,31 +0,0 @@
1config ZCACHE2
2 bool "Dynamic compression of swap pages and clean pagecache pages"
3 depends on CRYPTO=y && SWAP=y && CLEANCACHE && FRONTSWAP && !ZCACHE
4 select CRYPTO_LZO
5 default n
6 help
7 Zcache2 doubles RAM efficiency while providing a significant
8 performance boosts on many workloads. Zcache2 uses
9 compression and an in-kernel implementation of transcendent
10 memory to store clean page cache pages and swap in RAM,
11 providing a noticeable reduction in disk I/O. Zcache2
12 is a complete rewrite of the older zcache; it was intended to
13 be a merge but that has been blocked due to political and
14 technical disagreements. It is intended that they will merge
15 again in the future. Until then, zcache2 is a single-node
16 version of ramster.
17
18config RAMSTER
19 bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem"
20 depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE2=y
21 depends on NET
22 # must ensure struct page is 8-byte aligned
23 select HAVE_ALIGNED_STRUCT_PAGE if !64_BIT
24 default n
25 help
26 RAMster allows RAM on other machines in a cluster to be utilized
27 dynamically and symmetrically instead of swapping to a local swap
28 disk, thus improving performance on memory-constrained workloads
29 while minimizing total RAM across the cluster. RAMster, like
30 zcache2, compresses swap pages into local RAM, but then remotifies
31 the compressed pages to another node in the RAMster cluster.
diff --git a/drivers/staging/ramster/Makefile b/drivers/staging/ramster/Makefile
deleted file mode 100644
index 2d8b9d0a6a8b..000000000000
--- a/drivers/staging/ramster/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
1zcache-y := zcache-main.o tmem.o zbud.o
2zcache-$(CONFIG_RAMSTER) += ramster/ramster.o ramster/r2net.o
3zcache-$(CONFIG_RAMSTER) += ramster/nodemanager.o ramster/tcp.o
4zcache-$(CONFIG_RAMSTER) += ramster/heartbeat.o ramster/masklog.o
5
6obj-$(CONFIG_ZCACHE2) += zcache.o
diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
deleted file mode 100644
index a2b7e03b6062..000000000000
--- a/drivers/staging/ramster/tmem.c
+++ /dev/null
@@ -1,894 +0,0 @@
1/*
2 * In-kernel transcendent memory (generic implementation)
3 *
4 * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp.
5 *
6 * The primary purpose of Transcedent Memory ("tmem") is to map object-oriented
7 * "handles" (triples containing a pool id, and object id, and an index), to
8 * pages in a page-accessible memory (PAM). Tmem references the PAM pages via
9 * an abstract "pampd" (PAM page-descriptor), which can be operated on by a
10 * set of functions (pamops). Each pampd contains some representation of
11 * PAGE_SIZE bytes worth of data. For those familiar with key-value stores,
12 * the tmem handle is a three-level hierarchical key, and the value is always
13 * reconstituted (but not necessarily stored) as PAGE_SIZE bytes and is
14 * referenced in the datastore by the pampd. The hierarchy is required
15 * to ensure that certain invalidation functions can be performed efficiently
16 * (i.e. flush all indexes associated with this object_id, or
17 * flush all objects associated with this pool).
18 *
19 * Tmem must support potentially millions of pages and must be able to insert,
20 * find, and delete these pages at a potential frequency of thousands per
21 * second concurrently across many CPUs, (and, if used with KVM, across many
22 * vcpus across many guests). Tmem is tracked with a hierarchy of data
23 * structures, organized by the elements in the handle-tuple: pool_id,
24 * object_id, and page index. One or more "clients" (e.g. guests) each
25 * provide one or more tmem_pools. Each pool, contains a hash table of
26 * rb_trees of tmem_objs. Each tmem_obj contains a radix-tree-like tree
27 * of pointers, with intermediate nodes called tmem_objnodes. Each leaf
28 * pointer in this tree points to a pampd, which is accessible only through
29 * a small set of callbacks registered by the PAM implementation (see
30 * tmem_register_pamops). Tmem only needs to memory allocation for objs
31 * and objnodes and this is done via a set of callbacks that must be
32 * registered by the tmem host implementation (e.g. see tmem_register_hostops).
33 */
34
35#include <linux/list.h>
36#include <linux/spinlock.h>
37#include <linux/atomic.h>
38#ifdef CONFIG_RAMSTER
39#include <linux/delay.h>
40#endif
41
42#include "tmem.h"
43
44/* data structure sentinels used for debugging... see tmem.h */
45#define POOL_SENTINEL 0x87658765
46#define OBJ_SENTINEL 0x12345678
47#define OBJNODE_SENTINEL 0xfedcba09
48
49/*
50 * A tmem host implementation must use this function to register callbacks
51 * for memory allocation.
52 */
53static struct tmem_hostops tmem_hostops;
54
55static void tmem_objnode_tree_init(void);
56
57void tmem_register_hostops(struct tmem_hostops *m)
58{
59 tmem_objnode_tree_init();
60 tmem_hostops = *m;
61}
62
63/*
64 * A tmem host implementation must use this function to register
65 * callbacks for a page-accessible memory (PAM) implementation.
66 */
67static struct tmem_pamops tmem_pamops;
68
69void tmem_register_pamops(struct tmem_pamops *m)
70{
71 tmem_pamops = *m;
72}
73
74/*
75 * Oid's are potentially very sparse and tmem_objs may have an indeterminately
76 * short life, being added and deleted at a relatively high frequency.
77 * So an rb_tree is an ideal data structure to manage tmem_objs. But because
78 * of the potentially huge number of tmem_objs, each pool manages a hashtable
79 * of rb_trees to reduce search, insert, delete, and rebalancing time.
80 * Each hashbucket also has a lock to manage concurrent access and no
81 * searches, inserts, or deletions can be performed unless the lock is held.
82 * As a result, care must be taken to ensure tmem routines are not called
83 * recursively; the vast majority of the time, a recursive call may work
84 * but a deadlock will occur a small fraction of the time due to the
85 * hashbucket lock.
86 *
87 * The following routines manage tmem_objs. In all of these routines,
88 * the hashbucket lock is already held.
89 */
90
91/* Search for object==oid in pool, returns object if found. */
92static struct tmem_obj *__tmem_obj_find(struct tmem_hashbucket *hb,
93 struct tmem_oid *oidp,
94 struct rb_node **parent,
95 struct rb_node ***link)
96{
97 struct rb_node *_parent = NULL, **rbnode;
98 struct tmem_obj *obj = NULL;
99
100 rbnode = &hb->obj_rb_root.rb_node;
101 while (*rbnode) {
102 BUG_ON(RB_EMPTY_NODE(*rbnode));
103 _parent = *rbnode;
104 obj = rb_entry(*rbnode, struct tmem_obj,
105 rb_tree_node);
106 switch (tmem_oid_compare(oidp, &obj->oid)) {
107 case 0: /* equal */
108 goto out;
109 case -1:
110 rbnode = &(*rbnode)->rb_left;
111 break;
112 case 1:
113 rbnode = &(*rbnode)->rb_right;
114 break;
115 }
116 }
117
118 if (parent)
119 *parent = _parent;
120 if (link)
121 *link = rbnode;
122 obj = NULL;
123out:
124 return obj;
125}
126
127static struct tmem_obj *tmem_obj_find(struct tmem_hashbucket *hb,
128 struct tmem_oid *oidp)
129{
130 return __tmem_obj_find(hb, oidp, NULL, NULL);
131}
132
133static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *, bool);
134
135/* Free an object that has no more pampds in it. */
136static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb)
137{
138 struct tmem_pool *pool;
139
140 BUG_ON(obj == NULL);
141 ASSERT_SENTINEL(obj, OBJ);
142 BUG_ON(obj->pampd_count > 0);
143 pool = obj->pool;
144 BUG_ON(pool == NULL);
145 if (obj->objnode_tree_root != NULL) /* may be "stump" with no leaves */
146 tmem_pampd_destroy_all_in_obj(obj, false);
147 BUG_ON(obj->objnode_tree_root != NULL);
148 BUG_ON((long)obj->objnode_count != 0);
149 atomic_dec(&pool->obj_count);
150 BUG_ON(atomic_read(&pool->obj_count) < 0);
151 INVERT_SENTINEL(obj, OBJ);
152 obj->pool = NULL;
153 tmem_oid_set_invalid(&obj->oid);
154 rb_erase(&obj->rb_tree_node, &hb->obj_rb_root);
155}
156
157/*
158 * Initialize, and insert an tmem_object_root (called only if find failed).
159 */
160static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
161 struct tmem_pool *pool,
162 struct tmem_oid *oidp)
163{
164 struct rb_root *root = &hb->obj_rb_root;
165 struct rb_node **new = NULL, *parent = NULL;
166
167 BUG_ON(pool == NULL);
168 atomic_inc(&pool->obj_count);
169 obj->objnode_tree_height = 0;
170 obj->objnode_tree_root = NULL;
171 obj->pool = pool;
172 obj->oid = *oidp;
173 obj->objnode_count = 0;
174 obj->pampd_count = 0;
175#ifdef CONFIG_RAMSTER
176 if (tmem_pamops.new_obj != NULL)
177 (*tmem_pamops.new_obj)(obj);
178#endif
179 SET_SENTINEL(obj, OBJ);
180
181 if (__tmem_obj_find(hb, oidp, &parent, &new))
182 BUG();
183
184 rb_link_node(&obj->rb_tree_node, parent, new);
185 rb_insert_color(&obj->rb_tree_node, root);
186}
187
188/*
189 * Tmem is managed as a set of tmem_pools with certain attributes, such as
190 * "ephemeral" vs "persistent". These attributes apply to all tmem_objs
191 * and all pampds that belong to a tmem_pool. A tmem_pool is created
192 * or deleted relatively rarely (for example, when a filesystem is
193 * mounted or unmounted).
194 */
195
196/* flush all data from a pool and, optionally, free it */
197static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
198{
199 struct rb_node *rbnode;
200 struct tmem_obj *obj;
201 struct tmem_hashbucket *hb = &pool->hashbucket[0];
202 int i;
203
204 BUG_ON(pool == NULL);
205 for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) {
206 spin_lock(&hb->lock);
207 rbnode = rb_first(&hb->obj_rb_root);
208 while (rbnode != NULL) {
209 obj = rb_entry(rbnode, struct tmem_obj, rb_tree_node);
210 rbnode = rb_next(rbnode);
211 tmem_pampd_destroy_all_in_obj(obj, true);
212 tmem_obj_free(obj, hb);
213 (*tmem_hostops.obj_free)(obj, pool);
214 }
215 spin_unlock(&hb->lock);
216 }
217 if (destroy)
218 list_del(&pool->pool_list);
219}
220
221/*
222 * A tmem_obj contains a radix-tree-like tree in which the intermediate
223 * nodes are called tmem_objnodes. (The kernel lib/radix-tree.c implementation
224 * is very specialized and tuned for specific uses and is not particularly
225 * suited for use from this code, though some code from the core algorithms has
226 * been reused, thus the copyright notices below). Each tmem_objnode contains
227 * a set of pointers which point to either a set of intermediate tmem_objnodes
228 * or a set of of pampds.
229 *
230 * Portions Copyright (C) 2001 Momchil Velikov
231 * Portions Copyright (C) 2001 Christoph Hellwig
232 * Portions Copyright (C) 2005 SGI, Christoph Lameter <clameter@sgi.com>
233 */
234
235struct tmem_objnode_tree_path {
236 struct tmem_objnode *objnode;
237 int offset;
238};
239
240/* objnode height_to_maxindex translation */
241static unsigned long tmem_objnode_tree_h2max[OBJNODE_TREE_MAX_PATH + 1];
242
243static void tmem_objnode_tree_init(void)
244{
245 unsigned int ht, tmp;
246
247 for (ht = 0; ht < ARRAY_SIZE(tmem_objnode_tree_h2max); ht++) {
248 tmp = ht * OBJNODE_TREE_MAP_SHIFT;
249 if (tmp >= OBJNODE_TREE_INDEX_BITS)
250 tmem_objnode_tree_h2max[ht] = ~0UL;
251 else
252 tmem_objnode_tree_h2max[ht] =
253 (~0UL >> (OBJNODE_TREE_INDEX_BITS - tmp - 1)) >> 1;
254 }
255}
256
257static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
258{
259 struct tmem_objnode *objnode;
260
261 ASSERT_SENTINEL(obj, OBJ);
262 BUG_ON(obj->pool == NULL);
263 ASSERT_SENTINEL(obj->pool, POOL);
264 objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
265 if (unlikely(objnode == NULL))
266 goto out;
267 objnode->obj = obj;
268 SET_SENTINEL(objnode, OBJNODE);
269 memset(&objnode->slots, 0, sizeof(objnode->slots));
270 objnode->slots_in_use = 0;
271 obj->objnode_count++;
272out:
273 return objnode;
274}
275
276static void tmem_objnode_free(struct tmem_objnode *objnode)
277{
278 struct tmem_pool *pool;
279 int i;
280
281 BUG_ON(objnode == NULL);
282 for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++)
283 BUG_ON(objnode->slots[i] != NULL);
284 ASSERT_SENTINEL(objnode, OBJNODE);
285 INVERT_SENTINEL(objnode, OBJNODE);
286 BUG_ON(objnode->obj == NULL);
287 ASSERT_SENTINEL(objnode->obj, OBJ);
288 pool = objnode->obj->pool;
289 BUG_ON(pool == NULL);
290 ASSERT_SENTINEL(pool, POOL);
291 objnode->obj->objnode_count--;
292 objnode->obj = NULL;
293 (*tmem_hostops.objnode_free)(objnode, pool);
294}
295
296/*
297 * Lookup index in object and return associated pampd (or NULL if not found).
298 */
299static void **__tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index)
300{
301 unsigned int height, shift;
302 struct tmem_objnode **slot = NULL;
303
304 BUG_ON(obj == NULL);
305 ASSERT_SENTINEL(obj, OBJ);
306 BUG_ON(obj->pool == NULL);
307 ASSERT_SENTINEL(obj->pool, POOL);
308
309 height = obj->objnode_tree_height;
310 if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height])
311 goto out;
312 if (height == 0 && obj->objnode_tree_root) {
313 slot = &obj->objnode_tree_root;
314 goto out;
315 }
316 shift = (height-1) * OBJNODE_TREE_MAP_SHIFT;
317 slot = &obj->objnode_tree_root;
318 while (height > 0) {
319 if (*slot == NULL)
320 goto out;
321 slot = (struct tmem_objnode **)
322 ((*slot)->slots +
323 ((index >> shift) & OBJNODE_TREE_MAP_MASK));
324 shift -= OBJNODE_TREE_MAP_SHIFT;
325 height--;
326 }
327out:
328 return slot != NULL ? (void **)slot : NULL;
329}
330
331static void *tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index)
332{
333 struct tmem_objnode **slot;
334
335 slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index);
336 return slot != NULL ? *slot : NULL;
337}
338
339#ifdef CONFIG_RAMSTER
340static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
341 void *new_pampd, bool no_free)
342{
343 struct tmem_objnode **slot;
344 void *ret = NULL;
345
346 slot = (struct tmem_objnode **)__tmem_pampd_lookup_in_obj(obj, index);
347 if ((slot != NULL) && (*slot != NULL)) {
348 void *old_pampd = *(void **)slot;
349 *(void **)slot = new_pampd;
350 if (!no_free)
351 (*tmem_pamops.free)(old_pampd, obj->pool,
352 NULL, 0, false);
353 ret = new_pampd;
354 }
355 return ret;
356}
357#endif
358
359static int tmem_pampd_add_to_obj(struct tmem_obj *obj, uint32_t index,
360 void *pampd)
361{
362 int ret = 0;
363 struct tmem_objnode *objnode = NULL, *newnode, *slot;
364 unsigned int height, shift;
365 int offset = 0;
366
367 /* if necessary, extend the tree to be higher */
368 if (index > tmem_objnode_tree_h2max[obj->objnode_tree_height]) {
369 height = obj->objnode_tree_height + 1;
370 if (index > tmem_objnode_tree_h2max[height])
371 while (index > tmem_objnode_tree_h2max[height])
372 height++;
373 if (obj->objnode_tree_root == NULL) {
374 obj->objnode_tree_height = height;
375 goto insert;
376 }
377 do {
378 newnode = tmem_objnode_alloc(obj);
379 if (!newnode) {
380 ret = -ENOMEM;
381 goto out;
382 }
383 newnode->slots[0] = obj->objnode_tree_root;
384 newnode->slots_in_use = 1;
385 obj->objnode_tree_root = newnode;
386 obj->objnode_tree_height++;
387 } while (height > obj->objnode_tree_height);
388 }
389insert:
390 slot = obj->objnode_tree_root;
391 height = obj->objnode_tree_height;
392 shift = (height-1) * OBJNODE_TREE_MAP_SHIFT;
393 while (height > 0) {
394 if (slot == NULL) {
395 /* add a child objnode. */
396 slot = tmem_objnode_alloc(obj);
397 if (!slot) {
398 ret = -ENOMEM;
399 goto out;
400 }
401 if (objnode) {
402
403 objnode->slots[offset] = slot;
404 objnode->slots_in_use++;
405 } else
406 obj->objnode_tree_root = slot;
407 }
408 /* go down a level */
409 offset = (index >> shift) & OBJNODE_TREE_MAP_MASK;
410 objnode = slot;
411 slot = objnode->slots[offset];
412 shift -= OBJNODE_TREE_MAP_SHIFT;
413 height--;
414 }
415 BUG_ON(slot != NULL);
416 if (objnode) {
417 objnode->slots_in_use++;
418 objnode->slots[offset] = pampd;
419 } else
420 obj->objnode_tree_root = pampd;
421 obj->pampd_count++;
422out:
423 return ret;
424}
425
426static void *tmem_pampd_delete_from_obj(struct tmem_obj *obj, uint32_t index)
427{
428 struct tmem_objnode_tree_path path[OBJNODE_TREE_MAX_PATH + 1];
429 struct tmem_objnode_tree_path *pathp = path;
430 struct tmem_objnode *slot = NULL;
431 unsigned int height, shift;
432 int offset;
433
434 BUG_ON(obj == NULL);
435 ASSERT_SENTINEL(obj, OBJ);
436 BUG_ON(obj->pool == NULL);
437 ASSERT_SENTINEL(obj->pool, POOL);
438 height = obj->objnode_tree_height;
439 if (index > tmem_objnode_tree_h2max[height])
440 goto out;
441 slot = obj->objnode_tree_root;
442 if (height == 0 && obj->objnode_tree_root) {
443 obj->objnode_tree_root = NULL;
444 goto out;
445 }
446 shift = (height - 1) * OBJNODE_TREE_MAP_SHIFT;
447 pathp->objnode = NULL;
448 do {
449 if (slot == NULL)
450 goto out;
451 pathp++;
452 offset = (index >> shift) & OBJNODE_TREE_MAP_MASK;
453 pathp->offset = offset;
454 pathp->objnode = slot;
455 slot = slot->slots[offset];
456 shift -= OBJNODE_TREE_MAP_SHIFT;
457 height--;
458 } while (height > 0);
459 if (slot == NULL)
460 goto out;
461 while (pathp->objnode) {
462 pathp->objnode->slots[pathp->offset] = NULL;
463 pathp->objnode->slots_in_use--;
464 if (pathp->objnode->slots_in_use) {
465 if (pathp->objnode == obj->objnode_tree_root) {
466 while (obj->objnode_tree_height > 0 &&
467 obj->objnode_tree_root->slots_in_use == 1 &&
468 obj->objnode_tree_root->slots[0]) {
469 struct tmem_objnode *to_free =
470 obj->objnode_tree_root;
471
472 obj->objnode_tree_root =
473 to_free->slots[0];
474 obj->objnode_tree_height--;
475 to_free->slots[0] = NULL;
476 to_free->slots_in_use = 0;
477 tmem_objnode_free(to_free);
478 }
479 }
480 goto out;
481 }
482 tmem_objnode_free(pathp->objnode); /* 0 slots used, free it */
483 pathp--;
484 }
485 obj->objnode_tree_height = 0;
486 obj->objnode_tree_root = NULL;
487
488out:
489 if (slot != NULL)
490 obj->pampd_count--;
491 BUG_ON(obj->pampd_count < 0);
492 return slot;
493}
494
495/* Recursively walk the objnode_tree destroying pampds and objnodes. */
496static void tmem_objnode_node_destroy(struct tmem_obj *obj,
497 struct tmem_objnode *objnode,
498 unsigned int ht)
499{
500 int i;
501
502 if (ht == 0)
503 return;
504 for (i = 0; i < OBJNODE_TREE_MAP_SIZE; i++) {
505 if (objnode->slots[i]) {
506 if (ht == 1) {
507 obj->pampd_count--;
508 (*tmem_pamops.free)(objnode->slots[i],
509 obj->pool, NULL, 0, true);
510 objnode->slots[i] = NULL;
511 continue;
512 }
513 tmem_objnode_node_destroy(obj, objnode->slots[i], ht-1);
514 tmem_objnode_free(objnode->slots[i]);
515 objnode->slots[i] = NULL;
516 }
517 }
518}
519
520static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
521 bool pool_destroy)
522{
523 if (obj->objnode_tree_root == NULL)
524 return;
525 if (obj->objnode_tree_height == 0) {
526 obj->pampd_count--;
527 (*tmem_pamops.free)(obj->objnode_tree_root,
528 obj->pool, NULL, 0, true);
529 } else {
530 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
531 obj->objnode_tree_height);
532 tmem_objnode_free(obj->objnode_tree_root);
533 obj->objnode_tree_height = 0;
534 }
535 obj->objnode_tree_root = NULL;
536#ifdef CONFIG_RAMSTER
537 if (tmem_pamops.free_obj != NULL)
538 (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
539#endif
540}
541
542/*
543 * Tmem is operated on by a set of well-defined actions:
544 * "put", "get", "flush", "flush_object", "new pool" and "destroy pool".
545 * (The tmem ABI allows for subpages and exchanges but these operations
546 * are not included in this implementation.)
547 *
548 * These "tmem core" operations are implemented in the following functions.
549 */
550
551/*
552 * "Put" a page, e.g. associate the passed pampd with the passed handle.
553 * Tmem_put is complicated by a corner case: What if a page with matching
554 * handle already exists in tmem? To guarantee coherency, one of two
555 * actions is necessary: Either the data for the page must be overwritten,
556 * or the page must be "flushed" so that the data is not accessible to a
557 * subsequent "get". Since these "duplicate puts" are relatively rare,
558 * this implementation always flushes for simplicity.
559 */
560int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
561 bool raw, void *pampd_to_use)
562{
563 struct tmem_obj *obj = NULL, *objfound = NULL, *objnew = NULL;
564 void *pampd = NULL, *pampd_del = NULL;
565 int ret = -ENOMEM;
566 struct tmem_hashbucket *hb;
567
568 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
569 spin_lock(&hb->lock);
570 obj = objfound = tmem_obj_find(hb, oidp);
571 if (obj != NULL) {
572 pampd = tmem_pampd_lookup_in_obj(objfound, index);
573 if (pampd != NULL) {
574 /* if found, is a dup put, flush the old one */
575 pampd_del = tmem_pampd_delete_from_obj(obj, index);
576 BUG_ON(pampd_del != pampd);
577 (*tmem_pamops.free)(pampd, pool, oidp, index, true);
578 if (obj->pampd_count == 0) {
579 objnew = obj;
580 objfound = NULL;
581 }
582 pampd = NULL;
583 }
584 } else {
585 obj = objnew = (*tmem_hostops.obj_alloc)(pool);
586 if (unlikely(obj == NULL)) {
587 ret = -ENOMEM;
588 goto out;
589 }
590 tmem_obj_init(obj, hb, pool, oidp);
591 }
592 BUG_ON(obj == NULL);
593 BUG_ON(((objnew != obj) && (objfound != obj)) || (objnew == objfound));
594 pampd = pampd_to_use;
595 BUG_ON(pampd_to_use == NULL);
596 ret = tmem_pampd_add_to_obj(obj, index, pampd);
597 if (unlikely(ret == -ENOMEM))
598 /* may have partially built objnode tree ("stump") */
599 goto delete_and_free;
600 (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
601 goto out;
602
603delete_and_free:
604 (void)tmem_pampd_delete_from_obj(obj, index);
605 if (pampd)
606 (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
607 if (objnew) {
608 tmem_obj_free(objnew, hb);
609 (*tmem_hostops.obj_free)(objnew, pool);
610 }
611out:
612 spin_unlock(&hb->lock);
613 return ret;
614}
615
616#ifdef CONFIG_RAMSTER
617/*
618 * For ramster only: The following routines provide a two-step sequence
619 * to allow the caller to replace a pampd in the tmem data structures with
620 * another pampd. Here, we lookup the passed handle and, if found, return the
621 * associated pampd and object, leaving the hashbucket locked and returning
622 * a reference to it. The caller is expected to immediately call the
623 * matching tmem_localify_finish routine which will handles the replacement
624 * and unlocks the hashbucket.
625 */
626void *tmem_localify_get_pampd(struct tmem_pool *pool, struct tmem_oid *oidp,
627 uint32_t index, struct tmem_obj **ret_obj,
628 void **saved_hb)
629{
630 struct tmem_hashbucket *hb;
631 struct tmem_obj *obj = NULL;
632 void *pampd = NULL;
633
634 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
635 spin_lock(&hb->lock);
636 obj = tmem_obj_find(hb, oidp);
637 if (likely(obj != NULL))
638 pampd = tmem_pampd_lookup_in_obj(obj, index);
639 *ret_obj = obj;
640 *saved_hb = (void *)hb;
641 /* note, hashbucket remains locked */
642 return pampd;
643}
644
645void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
646 void *pampd, void *saved_hb, bool delete)
647{
648 struct tmem_hashbucket *hb = (struct tmem_hashbucket *)saved_hb;
649
650 BUG_ON(!spin_is_locked(&hb->lock));
651 if (pampd != NULL) {
652 BUG_ON(obj == NULL);
653 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
654 (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
655 } else if (delete) {
656 BUG_ON(obj == NULL);
657 (void)tmem_pampd_delete_from_obj(obj, index);
658 }
659 spin_unlock(&hb->lock);
660}
661
662/*
663 * For ramster only. Helper function to support asynchronous tmem_get.
664 */
665static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
666 struct tmem_pool *pool, struct tmem_oid *oidp,
667 uint32_t index, bool free, char *data)
668{
669 void *old_pampd = *ppampd, *new_pampd = NULL;
670 bool intransit = false;
671 int ret = 0;
672
673 if (!is_ephemeral(pool))
674 new_pampd = (*tmem_pamops.repatriate_preload)(
675 old_pampd, pool, oidp, index, &intransit);
676 if (intransit)
677 ret = -EAGAIN;
678 else if (new_pampd != NULL)
679 *ppampd = new_pampd;
680 /* must release the hb->lock else repatriate can't sleep */
681 spin_unlock(&hb->lock);
682 if (!intransit)
683 ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
684 oidp, index, free, data);
685 if (ret == -EAGAIN) {
686 /* rare I think, but should cond_resched()??? */
687 usleep_range(10, 1000);
688 } else if (ret == -ENOTCONN || ret == -EHOSTDOWN) {
689 ret = -1;
690 } else if (ret != 0 && ret != -ENOENT) {
691 ret = -1;
692 }
693 /* note hb->lock has now been unlocked */
694 return ret;
695}
696
697/*
698 * For ramster only. If a page in tmem matches the handle, replace the
699 * page so that any subsequent "get" gets the new page. Returns 0 if
700 * there was a page to replace, else returns -1.
701 */
702int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
703 uint32_t index, void *new_pampd)
704{
705 struct tmem_obj *obj;
706 int ret = -1;
707 struct tmem_hashbucket *hb;
708
709 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
710 spin_lock(&hb->lock);
711 obj = tmem_obj_find(hb, oidp);
712 if (obj == NULL)
713 goto out;
714 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
715 /* if we bug here, pamops wasn't properly set up for ramster */
716 BUG_ON(tmem_pamops.replace_in_obj == NULL);
717 ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
718out:
719 spin_unlock(&hb->lock);
720 return ret;
721}
722#endif
723
724/*
725 * "Get" a page, e.g. if a pampd can be found matching the passed handle,
726 * use a pamops callback to recreated the page from the pampd with the
727 * matching handle. By tmem definition, when a "get" is successful on
728 * an ephemeral page, the page is "flushed", and when a "get" is successful
729 * on a persistent page, the page is retained in tmem. Note that to preserve
730 * coherency, "get" can never be skipped if tmem contains the data.
731 * That is, if a get is done with a certain handle and fails, any
732 * subsequent "get" must also fail (unless of course there is a
733 * "put" done with the same handle).
734 */
735int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
736 char *data, size_t *sizep, bool raw, int get_and_free)
737{
738 struct tmem_obj *obj;
739 void *pampd = NULL;
740 bool ephemeral = is_ephemeral(pool);
741 int ret = -1;
742 struct tmem_hashbucket *hb;
743 bool free = (get_and_free == 1) || ((get_and_free == 0) && ephemeral);
744 bool lock_held = false;
745 void **ppampd;
746
747 do {
748 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
749 spin_lock(&hb->lock);
750 lock_held = true;
751 obj = tmem_obj_find(hb, oidp);
752 if (obj == NULL)
753 goto out;
754 ppampd = __tmem_pampd_lookup_in_obj(obj, index);
755 if (ppampd == NULL)
756 goto out;
757#ifdef CONFIG_RAMSTER
758 if ((tmem_pamops.is_remote != NULL) &&
759 tmem_pamops.is_remote(*ppampd)) {
760 ret = tmem_repatriate(ppampd, hb, pool, oidp,
761 index, free, data);
762 /* tmem_repatriate releases hb->lock */
763 lock_held = false;
764 *sizep = PAGE_SIZE;
765 if (ret != -EAGAIN)
766 goto out;
767 }
768#endif
769 } while (ret == -EAGAIN);
770 if (free)
771 pampd = tmem_pampd_delete_from_obj(obj, index);
772 else
773 pampd = tmem_pampd_lookup_in_obj(obj, index);
774 if (pampd == NULL)
775 goto out;
776 if (free) {
777 if (obj->pampd_count == 0) {
778 tmem_obj_free(obj, hb);
779 (*tmem_hostops.obj_free)(obj, pool);
780 obj = NULL;
781 }
782 }
783 if (free)
784 ret = (*tmem_pamops.get_data_and_free)(
785 data, sizep, raw, pampd, pool, oidp, index);
786 else
787 ret = (*tmem_pamops.get_data)(
788 data, sizep, raw, pampd, pool, oidp, index);
789 if (ret < 0)
790 goto out;
791 ret = 0;
792out:
793 if (lock_held)
794 spin_unlock(&hb->lock);
795 return ret;
796}
797
798/*
799 * If a page in tmem matches the handle, "flush" this page from tmem such
800 * that any subsequent "get" does not succeed (unless, of course, there
801 * was another "put" with the same handle).
802 */
803int tmem_flush_page(struct tmem_pool *pool,
804 struct tmem_oid *oidp, uint32_t index)
805{
806 struct tmem_obj *obj;
807 void *pampd;
808 int ret = -1;
809 struct tmem_hashbucket *hb;
810
811 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
812 spin_lock(&hb->lock);
813 obj = tmem_obj_find(hb, oidp);
814 if (obj == NULL)
815 goto out;
816 pampd = tmem_pampd_delete_from_obj(obj, index);
817 if (pampd == NULL)
818 goto out;
819 (*tmem_pamops.free)(pampd, pool, oidp, index, true);
820 if (obj->pampd_count == 0) {
821 tmem_obj_free(obj, hb);
822 (*tmem_hostops.obj_free)(obj, pool);
823 }
824 ret = 0;
825
826out:
827 spin_unlock(&hb->lock);
828 return ret;
829}
830
831/*
832 * "Flush" all pages in tmem matching this oid.
833 */
834int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
835{
836 struct tmem_obj *obj;
837 struct tmem_hashbucket *hb;
838 int ret = -1;
839
840 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
841 spin_lock(&hb->lock);
842 obj = tmem_obj_find(hb, oidp);
843 if (obj == NULL)
844 goto out;
845 tmem_pampd_destroy_all_in_obj(obj, false);
846 tmem_obj_free(obj, hb);
847 (*tmem_hostops.obj_free)(obj, pool);
848 ret = 0;
849
850out:
851 spin_unlock(&hb->lock);
852 return ret;
853}
854
855/*
856 * "Flush" all pages (and tmem_objs) from this tmem_pool and disable
857 * all subsequent access to this tmem_pool.
858 */
859int tmem_destroy_pool(struct tmem_pool *pool)
860{
861 int ret = -1;
862
863 if (pool == NULL)
864 goto out;
865 tmem_pool_flush(pool, 1);
866 ret = 0;
867out:
868 return ret;
869}
870
871static LIST_HEAD(tmem_global_pool_list);
872
873/*
874 * Create a new tmem_pool with the provided flag and return
875 * a pool id provided by the tmem host implementation.
876 */
877void tmem_new_pool(struct tmem_pool *pool, uint32_t flags)
878{
879 int persistent = flags & TMEM_POOL_PERSIST;
880 int shared = flags & TMEM_POOL_SHARED;
881 struct tmem_hashbucket *hb = &pool->hashbucket[0];
882 int i;
883
884 for (i = 0; i < TMEM_HASH_BUCKETS; i++, hb++) {
885 hb->obj_rb_root = RB_ROOT;
886 spin_lock_init(&hb->lock);
887 }
888 INIT_LIST_HEAD(&pool->pool_list);
889 atomic_set(&pool->obj_count, 0);
890 SET_SENTINEL(pool, POOL);
891 list_add_tail(&pool->pool_list, &tmem_global_pool_list);
892 pool->persistent = persistent;
893 pool->shared = shared;
894}
diff --git a/drivers/staging/ramster/tmem.h b/drivers/staging/ramster/tmem.h
deleted file mode 100644
index adbe5a8f28aa..000000000000
--- a/drivers/staging/ramster/tmem.h
+++ /dev/null
@@ -1,259 +0,0 @@
1/*
2 * tmem.h
3 *
4 * Transcendent memory
5 *
6 * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp.
7 */
8
9#ifndef _TMEM_H_
10#define _TMEM_H_
11
12#include <linux/types.h>
13#include <linux/highmem.h>
14#include <linux/hash.h>
15#include <linux/atomic.h>
16
17/*
18 * These are defined by the Xen<->Linux ABI so should remain consistent
19 */
20#define TMEM_POOL_PERSIST 1
21#define TMEM_POOL_SHARED 2
22#define TMEM_POOL_PRECOMPRESSED 4
23#define TMEM_POOL_PAGESIZE_SHIFT 4
24#define TMEM_POOL_PAGESIZE_MASK 0xf
25#define TMEM_POOL_RESERVED_BITS 0x00ffff00
26
27/*
28 * sentinels have proven very useful for debugging but can be removed
29 * or disabled before final merge.
30 */
31#undef SENTINELS
32#ifdef SENTINELS
33#define DECL_SENTINEL uint32_t sentinel;
34#define SET_SENTINEL(_x, _y) (_x->sentinel = _y##_SENTINEL)
35#define INVERT_SENTINEL(_x, _y) (_x->sentinel = ~_y##_SENTINEL)
36#define ASSERT_SENTINEL(_x, _y) WARN_ON(_x->sentinel != _y##_SENTINEL)
37#define ASSERT_INVERTED_SENTINEL(_x, _y) WARN_ON(_x->sentinel != ~_y##_SENTINEL)
38#else
39#define DECL_SENTINEL
40#define SET_SENTINEL(_x, _y) do { } while (0)
41#define INVERT_SENTINEL(_x, _y) do { } while (0)
42#define ASSERT_SENTINEL(_x, _y) do { } while (0)
43#define ASSERT_INVERTED_SENTINEL(_x, _y) do { } while (0)
44#endif
45
46#define ASSERT_SPINLOCK(_l) lockdep_assert_held(_l)
47
48/*
49 * A pool is the highest-level data structure managed by tmem and
50 * usually corresponds to a large independent set of pages such as
51 * a filesystem. Each pool has an id, and certain attributes and counters.
52 * It also contains a set of hash buckets, each of which contains an rbtree
53 * of objects and a lock to manage concurrency within the pool.
54 */
55
56#define TMEM_HASH_BUCKET_BITS 8
57#define TMEM_HASH_BUCKETS (1<<TMEM_HASH_BUCKET_BITS)
58
59struct tmem_hashbucket {
60 struct rb_root obj_rb_root;
61 spinlock_t lock;
62};
63
64struct tmem_pool {
65 void *client; /* "up" for some clients, avoids table lookup */
66 struct list_head pool_list;
67 uint32_t pool_id;
68 bool persistent;
69 bool shared;
70 atomic_t obj_count;
71 atomic_t refcount;
72 struct tmem_hashbucket hashbucket[TMEM_HASH_BUCKETS];
73 DECL_SENTINEL
74};
75
76#define is_persistent(_p) (_p->persistent)
77#define is_ephemeral(_p) (!(_p->persistent))
78
79/*
80 * An object id ("oid") is large: 192-bits (to ensure, for example, files
81 * in a modern filesystem can be uniquely identified).
82 */
83
84struct tmem_oid {
85 uint64_t oid[3];
86};
87
88static inline void tmem_oid_set_invalid(struct tmem_oid *oidp)
89{
90 oidp->oid[0] = oidp->oid[1] = oidp->oid[2] = -1UL;
91}
92
93static inline bool tmem_oid_valid(struct tmem_oid *oidp)
94{
95 return oidp->oid[0] != -1UL || oidp->oid[1] != -1UL ||
96 oidp->oid[2] != -1UL;
97}
98
99static inline int tmem_oid_compare(struct tmem_oid *left,
100 struct tmem_oid *right)
101{
102 int ret;
103
104 if (left->oid[2] == right->oid[2]) {
105 if (left->oid[1] == right->oid[1]) {
106 if (left->oid[0] == right->oid[0])
107 ret = 0;
108 else if (left->oid[0] < right->oid[0])
109 ret = -1;
110 else
111 return 1;
112 } else if (left->oid[1] < right->oid[1])
113 ret = -1;
114 else
115 ret = 1;
116 } else if (left->oid[2] < right->oid[2])
117 ret = -1;
118 else
119 ret = 1;
120 return ret;
121}
122
123static inline unsigned tmem_oid_hash(struct tmem_oid *oidp)
124{
125 return hash_long(oidp->oid[0] ^ oidp->oid[1] ^ oidp->oid[2],
126 TMEM_HASH_BUCKET_BITS);
127}
128
129#ifdef CONFIG_RAMSTER
130struct tmem_xhandle {
131 uint8_t client_id;
132 uint8_t xh_data_cksum;
133 uint16_t xh_data_size;
134 uint16_t pool_id;
135 struct tmem_oid oid;
136 uint32_t index;
137 void *extra;
138};
139
140static inline struct tmem_xhandle tmem_xhandle_fill(uint16_t client_id,
141 struct tmem_pool *pool,
142 struct tmem_oid *oidp,
143 uint32_t index)
144{
145 struct tmem_xhandle xh;
146 xh.client_id = client_id;
147 xh.xh_data_cksum = (uint8_t)-1;
148 xh.xh_data_size = (uint16_t)-1;
149 xh.pool_id = pool->pool_id;
150 xh.oid = *oidp;
151 xh.index = index;
152 return xh;
153}
154#endif
155
156
157/*
158 * A tmem_obj contains an identifier (oid), pointers to the parent
159 * pool and the rb_tree to which it belongs, counters, and an ordered
160 * set of pampds, structured in a radix-tree-like tree. The intermediate
161 * nodes of the tree are called tmem_objnodes.
162 */
163
164struct tmem_objnode;
165
166struct tmem_obj {
167 struct tmem_oid oid;
168 struct tmem_pool *pool;
169 struct rb_node rb_tree_node;
170 struct tmem_objnode *objnode_tree_root;
171 unsigned int objnode_tree_height;
172 unsigned long objnode_count;
173 long pampd_count;
174#ifdef CONFIG_RAMSTER
175 /*
176 * for current design of ramster, all pages belonging to
177 * an object reside on the same remotenode and extra is
178 * used to record the number of the remotenode so a
179 * flush-object operation can specify it
180 */
181 void *extra; /* for private use by pampd implementation */
182#endif
183 DECL_SENTINEL
184};
185
186#define OBJNODE_TREE_MAP_SHIFT 6
187#define OBJNODE_TREE_MAP_SIZE (1UL << OBJNODE_TREE_MAP_SHIFT)
188#define OBJNODE_TREE_MAP_MASK (OBJNODE_TREE_MAP_SIZE-1)
189#define OBJNODE_TREE_INDEX_BITS (8 /* CHAR_BIT */ * sizeof(unsigned long))
190#define OBJNODE_TREE_MAX_PATH \
191 (OBJNODE_TREE_INDEX_BITS/OBJNODE_TREE_MAP_SHIFT + 2)
192
193struct tmem_objnode {
194 struct tmem_obj *obj;
195 DECL_SENTINEL
196 void *slots[OBJNODE_TREE_MAP_SIZE];
197 unsigned int slots_in_use;
198};
199
200struct tmem_handle {
201 struct tmem_oid oid; /* 24 bytes */
202 uint32_t index;
203 uint16_t pool_id;
204 uint16_t client_id;
205};
206
207
208/* pampd abstract datatype methods provided by the PAM implementation */
209struct tmem_pamops {
210 void (*create_finish)(void *, bool);
211 int (*get_data)(char *, size_t *, bool, void *, struct tmem_pool *,
212 struct tmem_oid *, uint32_t);
213 int (*get_data_and_free)(char *, size_t *, bool, void *,
214 struct tmem_pool *, struct tmem_oid *,
215 uint32_t);
216 void (*free)(void *, struct tmem_pool *,
217 struct tmem_oid *, uint32_t, bool);
218#ifdef CONFIG_RAMSTER
219 void (*new_obj)(struct tmem_obj *);
220 void (*free_obj)(struct tmem_pool *, struct tmem_obj *, bool);
221 void *(*repatriate_preload)(void *, struct tmem_pool *,
222 struct tmem_oid *, uint32_t, bool *);
223 int (*repatriate)(void *, void *, struct tmem_pool *,
224 struct tmem_oid *, uint32_t, bool, void *);
225 bool (*is_remote)(void *);
226 int (*replace_in_obj)(void *, struct tmem_obj *);
227#endif
228};
229extern void tmem_register_pamops(struct tmem_pamops *m);
230
231/* memory allocation methods provided by the host implementation */
232struct tmem_hostops {
233 struct tmem_obj *(*obj_alloc)(struct tmem_pool *);
234 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
235 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
236 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
237};
238extern void tmem_register_hostops(struct tmem_hostops *m);
239
240/* core tmem accessor functions */
241extern int tmem_put(struct tmem_pool *, struct tmem_oid *, uint32_t index,
242 bool, void *);
243extern int tmem_get(struct tmem_pool *, struct tmem_oid *, uint32_t index,
244 char *, size_t *, bool, int);
245extern int tmem_flush_page(struct tmem_pool *, struct tmem_oid *,
246 uint32_t index);
247extern int tmem_flush_object(struct tmem_pool *, struct tmem_oid *);
248extern int tmem_destroy_pool(struct tmem_pool *);
249extern void tmem_new_pool(struct tmem_pool *, uint32_t);
250#ifdef CONFIG_RAMSTER
251extern int tmem_replace(struct tmem_pool *, struct tmem_oid *, uint32_t index,
252 void *);
253extern void *tmem_localify_get_pampd(struct tmem_pool *, struct tmem_oid *,
254 uint32_t index, struct tmem_obj **,
255 void **);
256extern void tmem_localify_finish(struct tmem_obj *, uint32_t index,
257 void *, void *, bool);
258#endif
259#endif /* _TMEM_H */
diff --git a/drivers/staging/ramster/zcache-main.c b/drivers/staging/ramster/zcache-main.c
deleted file mode 100644
index a09dd5cc1cea..000000000000
--- a/drivers/staging/ramster/zcache-main.c
+++ /dev/null
@@ -1,1820 +0,0 @@
1/*
2 * zcache.c
3 *
4 * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp.
5 * Copyright (c) 2010,2011, Nitin Gupta
6 *
7 * Zcache provides an in-kernel "host implementation" for transcendent memory
8 * ("tmem") and, thus indirectly, for cleancache and frontswap. Zcache uses
9 * lzo1x compression to improve density and an embedded allocator called
10 * "zbud" which "buddies" two compressed pages semi-optimally in each physical
11 * pageframe. Zbud is integrally tied into tmem to allow pageframes to
12 * be "reclaimed" efficiently.
13 */
14
15#include <linux/module.h>
16#include <linux/cpu.h>
17#include <linux/highmem.h>
18#include <linux/list.h>
19#include <linux/slab.h>
20#include <linux/spinlock.h>
21#include <linux/types.h>
22#include <linux/atomic.h>
23#include <linux/math64.h>
24#include <linux/crypto.h>
25
26#include <linux/cleancache.h>
27#include <linux/frontswap.h>
28#include "tmem.h"
29#include "zcache.h"
30#include "zbud.h"
31#include "ramster.h"
32#ifdef CONFIG_RAMSTER
33static int ramster_enabled;
34#else
35#define ramster_enabled 0
36#endif
37
38#ifndef __PG_WAS_ACTIVE
39static inline bool PageWasActive(struct page *page)
40{
41 return true;
42}
43
44static inline void SetPageWasActive(struct page *page)
45{
46}
47#endif
48
49#ifdef FRONTSWAP_HAS_EXCLUSIVE_GETS
50static bool frontswap_has_exclusive_gets __read_mostly = true;
51#else
52static bool frontswap_has_exclusive_gets __read_mostly;
53static inline void frontswap_tmem_exclusive_gets(bool b)
54{
55}
56#endif
57
58static int zcache_enabled __read_mostly;
59static int disable_cleancache __read_mostly;
60static int disable_frontswap __read_mostly;
61static int disable_frontswap_ignore_nonactive __read_mostly;
62static int disable_cleancache_ignore_nonactive __read_mostly;
63static char *namestr __read_mostly = "zcache";
64
65#define ZCACHE_GFP_MASK \
66 (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC)
67
68MODULE_LICENSE("GPL");
69
70/* crypto API for zcache */
71#define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME
72static char zcache_comp_name[ZCACHE_COMP_NAME_SZ] __read_mostly;
73static struct crypto_comp * __percpu *zcache_comp_pcpu_tfms __read_mostly;
74
75enum comp_op {
76 ZCACHE_COMPOP_COMPRESS,
77 ZCACHE_COMPOP_DECOMPRESS
78};
79
80static inline int zcache_comp_op(enum comp_op op,
81 const u8 *src, unsigned int slen,
82 u8 *dst, unsigned int *dlen)
83{
84 struct crypto_comp *tfm;
85 int ret = -1;
86
87 BUG_ON(!zcache_comp_pcpu_tfms);
88 tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, get_cpu());
89 BUG_ON(!tfm);
90 switch (op) {
91 case ZCACHE_COMPOP_COMPRESS:
92 ret = crypto_comp_compress(tfm, src, slen, dst, dlen);
93 break;
94 case ZCACHE_COMPOP_DECOMPRESS:
95 ret = crypto_comp_decompress(tfm, src, slen, dst, dlen);
96 break;
97 default:
98 ret = -EINVAL;
99 }
100 put_cpu();
101 return ret;
102}
103
104/*
105 * policy parameters
106 */
107
108/*
109 * byte count defining poor compression; pages with greater zsize will be
110 * rejected
111 */
112static unsigned int zbud_max_zsize __read_mostly = (PAGE_SIZE / 8) * 7;
113/*
114 * byte count defining poor *mean* compression; pages with greater zsize
115 * will be rejected until sufficient better-compressed pages are accepted
116 * driving the mean below this threshold
117 */
118static unsigned int zbud_max_mean_zsize __read_mostly = (PAGE_SIZE / 8) * 5;
119
120/*
121 * for now, used named slabs so can easily track usage; later can
122 * either just use kmalloc, or perhaps add a slab-like allocator
123 * to more carefully manage total memory utilization
124 */
125static struct kmem_cache *zcache_objnode_cache;
126static struct kmem_cache *zcache_obj_cache;
127
128static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, };
129
130/* we try to keep these statistics SMP-consistent */
131static long zcache_obj_count;
132static atomic_t zcache_obj_atomic = ATOMIC_INIT(0);
133static long zcache_obj_count_max;
134static long zcache_objnode_count;
135static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0);
136static long zcache_objnode_count_max;
137static u64 zcache_eph_zbytes;
138static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0);
139static u64 zcache_eph_zbytes_max;
140static u64 zcache_pers_zbytes;
141static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0);
142static u64 zcache_pers_zbytes_max;
143static long zcache_eph_pageframes;
144static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0);
145static long zcache_eph_pageframes_max;
146static long zcache_pers_pageframes;
147static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0);
148static long zcache_pers_pageframes_max;
149static long zcache_pageframes_alloced;
150static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0);
151static long zcache_pageframes_freed;
152static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0);
153static long zcache_eph_zpages;
154static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0);
155static long zcache_eph_zpages_max;
156static long zcache_pers_zpages;
157static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0);
158static long zcache_pers_zpages_max;
159
160/* but for the rest of these, counting races are ok */
161static unsigned long zcache_flush_total;
162static unsigned long zcache_flush_found;
163static unsigned long zcache_flobj_total;
164static unsigned long zcache_flobj_found;
165static unsigned long zcache_failed_eph_puts;
166static unsigned long zcache_failed_pers_puts;
167static unsigned long zcache_failed_getfreepages;
168static unsigned long zcache_failed_alloc;
169static unsigned long zcache_put_to_flush;
170static unsigned long zcache_compress_poor;
171static unsigned long zcache_mean_compress_poor;
172static unsigned long zcache_eph_ate_tail;
173static unsigned long zcache_eph_ate_tail_failed;
174static unsigned long zcache_pers_ate_eph;
175static unsigned long zcache_pers_ate_eph_failed;
176static unsigned long zcache_evicted_eph_zpages;
177static unsigned long zcache_evicted_eph_pageframes;
178static unsigned long zcache_last_active_file_pageframes;
179static unsigned long zcache_last_inactive_file_pageframes;
180static unsigned long zcache_last_active_anon_pageframes;
181static unsigned long zcache_last_inactive_anon_pageframes;
182static unsigned long zcache_eph_nonactive_puts_ignored;
183static unsigned long zcache_pers_nonactive_puts_ignored;
184
185#ifdef CONFIG_DEBUG_FS
186#include <linux/debugfs.h>
187#define zdfs debugfs_create_size_t
188#define zdfs64 debugfs_create_u64
189static int zcache_debugfs_init(void)
190{
191 struct dentry *root = debugfs_create_dir("zcache", NULL);
192 if (root == NULL)
193 return -ENXIO;
194
195 zdfs("obj_count", S_IRUGO, root, &zcache_obj_count);
196 zdfs("obj_count_max", S_IRUGO, root, &zcache_obj_count_max);
197 zdfs("objnode_count", S_IRUGO, root, &zcache_objnode_count);
198 zdfs("objnode_count_max", S_IRUGO, root, &zcache_objnode_count_max);
199 zdfs("flush_total", S_IRUGO, root, &zcache_flush_total);
200 zdfs("flush_found", S_IRUGO, root, &zcache_flush_found);
201 zdfs("flobj_total", S_IRUGO, root, &zcache_flobj_total);
202 zdfs("flobj_found", S_IRUGO, root, &zcache_flobj_found);
203 zdfs("failed_eph_puts", S_IRUGO, root, &zcache_failed_eph_puts);
204 zdfs("failed_pers_puts", S_IRUGO, root, &zcache_failed_pers_puts);
205 zdfs("failed_get_free_pages", S_IRUGO, root,
206 &zcache_failed_getfreepages);
207 zdfs("failed_alloc", S_IRUGO, root, &zcache_failed_alloc);
208 zdfs("put_to_flush", S_IRUGO, root, &zcache_put_to_flush);
209 zdfs("compress_poor", S_IRUGO, root, &zcache_compress_poor);
210 zdfs("mean_compress_poor", S_IRUGO, root, &zcache_mean_compress_poor);
211 zdfs("eph_ate_tail", S_IRUGO, root, &zcache_eph_ate_tail);
212 zdfs("eph_ate_tail_failed", S_IRUGO, root, &zcache_eph_ate_tail_failed);
213 zdfs("pers_ate_eph", S_IRUGO, root, &zcache_pers_ate_eph);
214 zdfs("pers_ate_eph_failed", S_IRUGO, root, &zcache_pers_ate_eph_failed);
215 zdfs("evicted_eph_zpages", S_IRUGO, root, &zcache_evicted_eph_zpages);
216 zdfs("evicted_eph_pageframes", S_IRUGO, root,
217 &zcache_evicted_eph_pageframes);
218 zdfs("eph_pageframes", S_IRUGO, root, &zcache_eph_pageframes);
219 zdfs("eph_pageframes_max", S_IRUGO, root, &zcache_eph_pageframes_max);
220 zdfs("pers_pageframes", S_IRUGO, root, &zcache_pers_pageframes);
221 zdfs("pers_pageframes_max", S_IRUGO, root, &zcache_pers_pageframes_max);
222 zdfs("eph_zpages", S_IRUGO, root, &zcache_eph_zpages);
223 zdfs("eph_zpages_max", S_IRUGO, root, &zcache_eph_zpages_max);
224 zdfs("pers_zpages", S_IRUGO, root, &zcache_pers_zpages);
225 zdfs("pers_zpages_max", S_IRUGO, root, &zcache_pers_zpages_max);
226 zdfs("last_active_file_pageframes", S_IRUGO, root,
227 &zcache_last_active_file_pageframes);
228 zdfs("last_inactive_file_pageframes", S_IRUGO, root,
229 &zcache_last_inactive_file_pageframes);
230 zdfs("last_active_anon_pageframes", S_IRUGO, root,
231 &zcache_last_active_anon_pageframes);
232 zdfs("last_inactive_anon_pageframes", S_IRUGO, root,
233 &zcache_last_inactive_anon_pageframes);
234 zdfs("eph_nonactive_puts_ignored", S_IRUGO, root,
235 &zcache_eph_nonactive_puts_ignored);
236 zdfs("pers_nonactive_puts_ignored", S_IRUGO, root,
237 &zcache_pers_nonactive_puts_ignored);
238 zdfs64("eph_zbytes", S_IRUGO, root, &zcache_eph_zbytes);
239 zdfs64("eph_zbytes_max", S_IRUGO, root, &zcache_eph_zbytes_max);
240 zdfs64("pers_zbytes", S_IRUGO, root, &zcache_pers_zbytes);
241 zdfs64("pers_zbytes_max", S_IRUGO, root, &zcache_pers_zbytes_max);
242 return 0;
243}
244#undef zdebugfs
245#undef zdfs64
246#endif
247
248#define ZCACHE_DEBUG
249#ifdef ZCACHE_DEBUG
250/* developers can call this in case of ooms, e.g. to find memory leaks */
251void zcache_dump(void)
252{
253 pr_info("zcache: obj_count=%lu\n", zcache_obj_count);
254 pr_info("zcache: obj_count_max=%lu\n", zcache_obj_count_max);
255 pr_info("zcache: objnode_count=%lu\n", zcache_objnode_count);
256 pr_info("zcache: objnode_count_max=%lu\n", zcache_objnode_count_max);
257 pr_info("zcache: flush_total=%lu\n", zcache_flush_total);
258 pr_info("zcache: flush_found=%lu\n", zcache_flush_found);
259 pr_info("zcache: flobj_total=%lu\n", zcache_flobj_total);
260 pr_info("zcache: flobj_found=%lu\n", zcache_flobj_found);
261 pr_info("zcache: failed_eph_puts=%lu\n", zcache_failed_eph_puts);
262 pr_info("zcache: failed_pers_puts=%lu\n", zcache_failed_pers_puts);
263 pr_info("zcache: failed_get_free_pages=%lu\n",
264 zcache_failed_getfreepages);
265 pr_info("zcache: failed_alloc=%lu\n", zcache_failed_alloc);
266 pr_info("zcache: put_to_flush=%lu\n", zcache_put_to_flush);
267 pr_info("zcache: compress_poor=%lu\n", zcache_compress_poor);
268 pr_info("zcache: mean_compress_poor=%lu\n",
269 zcache_mean_compress_poor);
270 pr_info("zcache: eph_ate_tail=%lu\n", zcache_eph_ate_tail);
271 pr_info("zcache: eph_ate_tail_failed=%lu\n",
272 zcache_eph_ate_tail_failed);
273 pr_info("zcache: pers_ate_eph=%lu\n", zcache_pers_ate_eph);
274 pr_info("zcache: pers_ate_eph_failed=%lu\n",
275 zcache_pers_ate_eph_failed);
276 pr_info("zcache: evicted_eph_zpages=%lu\n", zcache_evicted_eph_zpages);
277 pr_info("zcache: evicted_eph_pageframes=%lu\n",
278 zcache_evicted_eph_pageframes);
279 pr_info("zcache: eph_pageframes=%lu\n", zcache_eph_pageframes);
280 pr_info("zcache: eph_pageframes_max=%lu\n", zcache_eph_pageframes_max);
281 pr_info("zcache: pers_pageframes=%lu\n", zcache_pers_pageframes);
282 pr_info("zcache: pers_pageframes_max=%lu\n",
283 zcache_pers_pageframes_max);
284 pr_info("zcache: eph_zpages=%lu\n", zcache_eph_zpages);
285 pr_info("zcache: eph_zpages_max=%lu\n", zcache_eph_zpages_max);
286 pr_info("zcache: pers_zpages=%lu\n", zcache_pers_zpages);
287 pr_info("zcache: pers_zpages_max=%lu\n", zcache_pers_zpages_max);
288 pr_info("zcache: eph_zbytes=%llu\n",
289 (unsigned long long)zcache_eph_zbytes);
290 pr_info("zcache: eph_zbytes_max=%llu\n",
291 (unsigned long long)zcache_eph_zbytes_max);
292 pr_info("zcache: pers_zbytes=%llu\n",
293 (unsigned long long)zcache_pers_zbytes);
294 pr_info("zcache: pers_zbytes_max=%llu\n",
295 (unsigned long long)zcache_pers_zbytes_max);
296}
297#endif
298
299/*
300 * zcache core code starts here
301 */
302
303static struct zcache_client zcache_host;
304static struct zcache_client zcache_clients[MAX_CLIENTS];
305
306static inline bool is_local_client(struct zcache_client *cli)
307{
308 return cli == &zcache_host;
309}
310
311static struct zcache_client *zcache_get_client_by_id(uint16_t cli_id)
312{
313 struct zcache_client *cli = &zcache_host;
314
315 if (cli_id != LOCAL_CLIENT) {
316 if (cli_id >= MAX_CLIENTS)
317 goto out;
318 cli = &zcache_clients[cli_id];
319 }
320out:
321 return cli;
322}
323
324/*
325 * Tmem operations assume the poolid implies the invoking client.
326 * Zcache only has one client (the kernel itself): LOCAL_CLIENT.
327 * RAMster has each client numbered by cluster node, and a KVM version
328 * of zcache would have one client per guest and each client might
329 * have a poolid==N.
330 */
331struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid)
332{
333 struct tmem_pool *pool = NULL;
334 struct zcache_client *cli = NULL;
335
336 cli = zcache_get_client_by_id(cli_id);
337 if (cli == NULL)
338 goto out;
339 if (!is_local_client(cli))
340 atomic_inc(&cli->refcount);
341 if (poolid < MAX_POOLS_PER_CLIENT) {
342 pool = cli->tmem_pools[poolid];
343 if (pool != NULL)
344 atomic_inc(&pool->refcount);
345 }
346out:
347 return pool;
348}
349
350void zcache_put_pool(struct tmem_pool *pool)
351{
352 struct zcache_client *cli = NULL;
353
354 if (pool == NULL)
355 BUG();
356 cli = pool->client;
357 atomic_dec(&pool->refcount);
358 if (!is_local_client(cli))
359 atomic_dec(&cli->refcount);
360}
361
362int zcache_new_client(uint16_t cli_id)
363{
364 struct zcache_client *cli;
365 int ret = -1;
366
367 cli = zcache_get_client_by_id(cli_id);
368 if (cli == NULL)
369 goto out;
370 if (cli->allocated)
371 goto out;
372 cli->allocated = 1;
373 ret = 0;
374out:
375 return ret;
376}
377
378/*
379 * zcache implementation for tmem host ops
380 */
381
382static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool)
383{
384 struct tmem_objnode *objnode = NULL;
385 struct zcache_preload *kp;
386 int i;
387
388 kp = &__get_cpu_var(zcache_preloads);
389 for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) {
390 objnode = kp->objnodes[i];
391 if (objnode != NULL) {
392 kp->objnodes[i] = NULL;
393 break;
394 }
395 }
396 BUG_ON(objnode == NULL);
397 zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic);
398 if (zcache_objnode_count > zcache_objnode_count_max)
399 zcache_objnode_count_max = zcache_objnode_count;
400 return objnode;
401}
402
403static void zcache_objnode_free(struct tmem_objnode *objnode,
404 struct tmem_pool *pool)
405{
406 zcache_objnode_count =
407 atomic_dec_return(&zcache_objnode_atomic);
408 BUG_ON(zcache_objnode_count < 0);
409 kmem_cache_free(zcache_objnode_cache, objnode);
410}
411
412static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool)
413{
414 struct tmem_obj *obj = NULL;
415 struct zcache_preload *kp;
416
417 kp = &__get_cpu_var(zcache_preloads);
418 obj = kp->obj;
419 BUG_ON(obj == NULL);
420 kp->obj = NULL;
421 zcache_obj_count = atomic_inc_return(&zcache_obj_atomic);
422 if (zcache_obj_count > zcache_obj_count_max)
423 zcache_obj_count_max = zcache_obj_count;
424 return obj;
425}
426
427static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool)
428{
429 zcache_obj_count =
430 atomic_dec_return(&zcache_obj_atomic);
431 BUG_ON(zcache_obj_count < 0);
432 kmem_cache_free(zcache_obj_cache, obj);
433}
434
435static struct tmem_hostops zcache_hostops = {
436 .obj_alloc = zcache_obj_alloc,
437 .obj_free = zcache_obj_free,
438 .objnode_alloc = zcache_objnode_alloc,
439 .objnode_free = zcache_objnode_free,
440};
441
442static struct page *zcache_alloc_page(void)
443{
444 struct page *page = alloc_page(ZCACHE_GFP_MASK);
445
446 if (page != NULL)
447 zcache_pageframes_alloced =
448 atomic_inc_return(&zcache_pageframes_alloced_atomic);
449 return page;
450}
451
452#ifdef FRONTSWAP_HAS_UNUSE
453static void zcache_unacct_page(void)
454{
455 zcache_pageframes_freed =
456 atomic_inc_return(&zcache_pageframes_freed_atomic);
457}
458#endif
459
460static void zcache_free_page(struct page *page)
461{
462 long curr_pageframes;
463 static long max_pageframes, min_pageframes;
464
465 if (page == NULL)
466 BUG();
467 __free_page(page);
468 zcache_pageframes_freed =
469 atomic_inc_return(&zcache_pageframes_freed_atomic);
470 curr_pageframes = zcache_pageframes_alloced -
471 atomic_read(&zcache_pageframes_freed_atomic) -
472 atomic_read(&zcache_eph_pageframes_atomic) -
473 atomic_read(&zcache_pers_pageframes_atomic);
474 if (curr_pageframes > max_pageframes)
475 max_pageframes = curr_pageframes;
476 if (curr_pageframes < min_pageframes)
477 min_pageframes = curr_pageframes;
478#ifdef ZCACHE_DEBUG
479 if (curr_pageframes > 2L || curr_pageframes < -2L) {
480 /* pr_info here */
481 }
482#endif
483}
484
485/*
486 * zcache implementations for PAM page descriptor ops
487 */
488
489/* forward reference */
490static void zcache_compress(struct page *from,
491 void **out_va, unsigned *out_len);
492
493static struct page *zcache_evict_eph_pageframe(void);
494
495static void *zcache_pampd_eph_create(char *data, size_t size, bool raw,
496 struct tmem_handle *th)
497{
498 void *pampd = NULL, *cdata = data;
499 unsigned clen = size;
500 struct page *page = (struct page *)(data), *newpage;
501
502 if (!raw) {
503 zcache_compress(page, &cdata, &clen);
504 if (clen > zbud_max_buddy_size()) {
505 zcache_compress_poor++;
506 goto out;
507 }
508 } else {
509 BUG_ON(clen > zbud_max_buddy_size());
510 }
511
512 /* look for space via an existing match first */
513 pampd = (void *)zbud_match_prep(th, true, cdata, clen);
514 if (pampd != NULL)
515 goto got_pampd;
516
517 /* no match, now we need to find (or free up) a full page */
518 newpage = zcache_alloc_page();
519 if (newpage != NULL)
520 goto create_in_new_page;
521
522 zcache_failed_getfreepages++;
523 /* can't allocate a page, evict an ephemeral page via LRU */
524 newpage = zcache_evict_eph_pageframe();
525 if (newpage == NULL) {
526 zcache_eph_ate_tail_failed++;
527 goto out;
528 }
529 zcache_eph_ate_tail++;
530
531create_in_new_page:
532 pampd = (void *)zbud_create_prep(th, true, cdata, clen, newpage);
533 BUG_ON(pampd == NULL);
534 zcache_eph_pageframes =
535 atomic_inc_return(&zcache_eph_pageframes_atomic);
536 if (zcache_eph_pageframes > zcache_eph_pageframes_max)
537 zcache_eph_pageframes_max = zcache_eph_pageframes;
538
539got_pampd:
540 zcache_eph_zbytes =
541 atomic_long_add_return(clen, &zcache_eph_zbytes_atomic);
542 if (zcache_eph_zbytes > zcache_eph_zbytes_max)
543 zcache_eph_zbytes_max = zcache_eph_zbytes;
544 zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic);
545 if (zcache_eph_zpages > zcache_eph_zpages_max)
546 zcache_eph_zpages_max = zcache_eph_zpages;
547 if (ramster_enabled && raw)
548 ramster_count_foreign_pages(true, 1);
549out:
550 return pampd;
551}
552
553static void *zcache_pampd_pers_create(char *data, size_t size, bool raw,
554 struct tmem_handle *th)
555{
556 void *pampd = NULL, *cdata = data;
557 unsigned clen = size;
558 struct page *page = (struct page *)(data), *newpage;
559 unsigned long zbud_mean_zsize;
560 unsigned long curr_pers_zpages, total_zsize;
561
562 if (data == NULL) {
563 BUG_ON(!ramster_enabled);
564 goto create_pampd;
565 }
566 curr_pers_zpages = zcache_pers_zpages;
567/* FIXME CONFIG_RAMSTER... subtract atomic remote_pers_pages here? */
568 if (!raw)
569 zcache_compress(page, &cdata, &clen);
570 /* reject if compression is too poor */
571 if (clen > zbud_max_zsize) {
572 zcache_compress_poor++;
573 goto out;
574 }
575 /* reject if mean compression is too poor */
576 if ((clen > zbud_max_mean_zsize) && (curr_pers_zpages > 0)) {
577 total_zsize = zcache_pers_zbytes;
578 if ((long)total_zsize < 0)
579 total_zsize = 0;
580 zbud_mean_zsize = div_u64(total_zsize,
581 curr_pers_zpages);
582 if (zbud_mean_zsize > zbud_max_mean_zsize) {
583 zcache_mean_compress_poor++;
584 goto out;
585 }
586 }
587
588create_pampd:
589 /* look for space via an existing match first */
590 pampd = (void *)zbud_match_prep(th, false, cdata, clen);
591 if (pampd != NULL)
592 goto got_pampd;
593
594 /* no match, now we need to find (or free up) a full page */
595 newpage = zcache_alloc_page();
596 if (newpage != NULL)
597 goto create_in_new_page;
598 /*
599 * FIXME do the following only if eph is oversized?
600 * if (zcache_eph_pageframes >
601 * (global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE) +
602 * global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE)))
603 */
604 zcache_failed_getfreepages++;
605 /* can't allocate a page, evict an ephemeral page via LRU */
606 newpage = zcache_evict_eph_pageframe();
607 if (newpage == NULL) {
608 zcache_pers_ate_eph_failed++;
609 goto out;
610 }
611 zcache_pers_ate_eph++;
612
613create_in_new_page:
614 pampd = (void *)zbud_create_prep(th, false, cdata, clen, newpage);
615 BUG_ON(pampd == NULL);
616 zcache_pers_pageframes =
617 atomic_inc_return(&zcache_pers_pageframes_atomic);
618 if (zcache_pers_pageframes > zcache_pers_pageframes_max)
619 zcache_pers_pageframes_max = zcache_pers_pageframes;
620
621got_pampd:
622 zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic);
623 if (zcache_pers_zpages > zcache_pers_zpages_max)
624 zcache_pers_zpages_max = zcache_pers_zpages;
625 zcache_pers_zbytes =
626 atomic_long_add_return(clen, &zcache_pers_zbytes_atomic);
627 if (zcache_pers_zbytes > zcache_pers_zbytes_max)
628 zcache_pers_zbytes_max = zcache_pers_zbytes;
629 if (ramster_enabled && raw)
630 ramster_count_foreign_pages(false, 1);
631out:
632 return pampd;
633}
634
635/*
636 * This is called directly from zcache_put_page to pre-allocate space
637 * to store a zpage.
638 */
639void *zcache_pampd_create(char *data, unsigned int size, bool raw,
640 int eph, struct tmem_handle *th)
641{
642 void *pampd = NULL;
643 struct zcache_preload *kp;
644 struct tmem_objnode *objnode;
645 struct tmem_obj *obj;
646 int i;
647
648 BUG_ON(!irqs_disabled());
649 /* pre-allocate per-cpu metadata */
650 BUG_ON(zcache_objnode_cache == NULL);
651 BUG_ON(zcache_obj_cache == NULL);
652 kp = &__get_cpu_var(zcache_preloads);
653 for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) {
654 objnode = kp->objnodes[i];
655 if (objnode == NULL) {
656 objnode = kmem_cache_alloc(zcache_objnode_cache,
657 ZCACHE_GFP_MASK);
658 if (unlikely(objnode == NULL)) {
659 zcache_failed_alloc++;
660 goto out;
661 }
662 kp->objnodes[i] = objnode;
663 }
664 }
665 if (kp->obj == NULL) {
666 obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK);
667 kp->obj = obj;
668 }
669 if (unlikely(kp->obj == NULL)) {
670 zcache_failed_alloc++;
671 goto out;
672 }
673 /*
674 * ok, have all the metadata pre-allocated, now do the data
675 * but since how we allocate the data is dependent on ephemeral
676 * or persistent, we split the call here to different sub-functions
677 */
678 if (eph)
679 pampd = zcache_pampd_eph_create(data, size, raw, th);
680 else
681 pampd = zcache_pampd_pers_create(data, size, raw, th);
682out:
683 return pampd;
684}
685
686/*
687 * This is a pamops called via tmem_put and is necessary to "finish"
688 * a pampd creation.
689 */
690void zcache_pampd_create_finish(void *pampd, bool eph)
691{
692 zbud_create_finish((struct zbudref *)pampd, eph);
693}
694
695/*
696 * This is passed as a function parameter to zbud_decompress so that
697 * zbud need not be familiar with the details of crypto. It assumes that
698 * the bytes from_va and to_va through from_va+size-1 and to_va+size-1 are
699 * kmapped. It must be successful, else there is a logic bug somewhere.
700 */
701static void zcache_decompress(char *from_va, unsigned int size, char *to_va)
702{
703 int ret;
704 unsigned int outlen = PAGE_SIZE;
705
706 ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, from_va, size,
707 to_va, &outlen);
708 BUG_ON(ret);
709 BUG_ON(outlen != PAGE_SIZE);
710}
711
712/*
713 * Decompress from the kernel va to a pageframe
714 */
715void zcache_decompress_to_page(char *from_va, unsigned int size,
716 struct page *to_page)
717{
718 char *to_va = kmap_atomic(to_page);
719 zcache_decompress(from_va, size, to_va);
720 kunmap_atomic(to_va);
721}
722
723/*
724 * fill the pageframe corresponding to the struct page with the data
725 * from the passed pampd
726 */
727static int zcache_pampd_get_data(char *data, size_t *sizep, bool raw,
728 void *pampd, struct tmem_pool *pool,
729 struct tmem_oid *oid, uint32_t index)
730{
731 int ret;
732 bool eph = !is_persistent(pool);
733
734 BUG_ON(preemptible());
735 BUG_ON(eph); /* fix later if shared pools get implemented */
736 BUG_ON(pampd_is_remote(pampd));
737 if (raw)
738 ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd,
739 sizep, eph);
740 else {
741 ret = zbud_decompress((struct page *)(data),
742 (struct zbudref *)pampd, false,
743 zcache_decompress);
744 *sizep = PAGE_SIZE;
745 }
746 return ret;
747}
748
749/*
750 * fill the pageframe corresponding to the struct page with the data
751 * from the passed pampd
752 */
753static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw,
754 void *pampd, struct tmem_pool *pool,
755 struct tmem_oid *oid, uint32_t index)
756{
757 int ret;
758 bool eph = !is_persistent(pool);
759 struct page *page = NULL;
760 unsigned int zsize, zpages;
761
762 BUG_ON(preemptible());
763 BUG_ON(pampd_is_remote(pampd));
764 if (raw)
765 ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd,
766 sizep, eph);
767 else {
768 ret = zbud_decompress((struct page *)(data),
769 (struct zbudref *)pampd, eph,
770 zcache_decompress);
771 *sizep = PAGE_SIZE;
772 }
773 page = zbud_free_and_delist((struct zbudref *)pampd, eph,
774 &zsize, &zpages);
775 if (eph) {
776 if (page)
777 zcache_eph_pageframes =
778 atomic_dec_return(&zcache_eph_pageframes_atomic);
779 zcache_eph_zpages =
780 atomic_sub_return(zpages, &zcache_eph_zpages_atomic);
781 zcache_eph_zbytes =
782 atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
783 } else {
784 if (page)
785 zcache_pers_pageframes =
786 atomic_dec_return(&zcache_pers_pageframes_atomic);
787 zcache_pers_zpages =
788 atomic_sub_return(zpages, &zcache_pers_zpages_atomic);
789 zcache_pers_zbytes =
790 atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
791 }
792 if (!is_local_client(pool->client))
793 ramster_count_foreign_pages(eph, -1);
794 if (page)
795 zcache_free_page(page);
796 return ret;
797}
798
799/*
800 * free the pampd and remove it from any zcache lists
801 * pampd must no longer be pointed to from any tmem data structures!
802 */
803static void zcache_pampd_free(void *pampd, struct tmem_pool *pool,
804 struct tmem_oid *oid, uint32_t index, bool acct)
805{
806 struct page *page = NULL;
807 unsigned int zsize, zpages;
808
809 BUG_ON(preemptible());
810 if (pampd_is_remote(pampd)) {
811 BUG_ON(!ramster_enabled);
812 pampd = ramster_pampd_free(pampd, pool, oid, index, acct);
813 if (pampd == NULL)
814 return;
815 }
816 if (is_ephemeral(pool)) {
817 page = zbud_free_and_delist((struct zbudref *)pampd,
818 true, &zsize, &zpages);
819 if (page)
820 zcache_eph_pageframes =
821 atomic_dec_return(&zcache_eph_pageframes_atomic);
822 zcache_eph_zpages =
823 atomic_sub_return(zpages, &zcache_eph_zpages_atomic);
824 zcache_eph_zbytes =
825 atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
826 /* FIXME CONFIG_RAMSTER... check acct parameter? */
827 } else {
828 page = zbud_free_and_delist((struct zbudref *)pampd,
829 false, &zsize, &zpages);
830 if (page)
831 zcache_pers_pageframes =
832 atomic_dec_return(&zcache_pers_pageframes_atomic);
833 zcache_pers_zpages =
834 atomic_sub_return(zpages, &zcache_pers_zpages_atomic);
835 zcache_pers_zbytes =
836 atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
837 }
838 if (!is_local_client(pool->client))
839 ramster_count_foreign_pages(is_ephemeral(pool), -1);
840 if (page)
841 zcache_free_page(page);
842}
843
844static struct tmem_pamops zcache_pamops = {
845 .create_finish = zcache_pampd_create_finish,
846 .get_data = zcache_pampd_get_data,
847 .get_data_and_free = zcache_pampd_get_data_and_free,
848 .free = zcache_pampd_free,
849};
850
851/*
852 * zcache compression/decompression and related per-cpu stuff
853 */
854
855static DEFINE_PER_CPU(unsigned char *, zcache_dstmem);
856#define ZCACHE_DSTMEM_ORDER 1
857
858static void zcache_compress(struct page *from, void **out_va, unsigned *out_len)
859{
860 int ret;
861 unsigned char *dmem = __get_cpu_var(zcache_dstmem);
862 char *from_va;
863
864 BUG_ON(!irqs_disabled());
865 /* no buffer or no compressor so can't compress */
866 BUG_ON(dmem == NULL);
867 *out_len = PAGE_SIZE << ZCACHE_DSTMEM_ORDER;
868 from_va = kmap_atomic(from);
869 mb();
870 ret = zcache_comp_op(ZCACHE_COMPOP_COMPRESS, from_va, PAGE_SIZE, dmem,
871 out_len);
872 BUG_ON(ret);
873 *out_va = dmem;
874 kunmap_atomic(from_va);
875}
876
877static int zcache_comp_cpu_up(int cpu)
878{
879 struct crypto_comp *tfm;
880
881 tfm = crypto_alloc_comp(zcache_comp_name, 0, 0);
882 if (IS_ERR(tfm))
883 return NOTIFY_BAD;
884 *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = tfm;
885 return NOTIFY_OK;
886}
887
888static void zcache_comp_cpu_down(int cpu)
889{
890 struct crypto_comp *tfm;
891
892 tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu);
893 crypto_free_comp(tfm);
894 *per_cpu_ptr(zcache_comp_pcpu_tfms, cpu) = NULL;
895}
896
897static int zcache_cpu_notifier(struct notifier_block *nb,
898 unsigned long action, void *pcpu)
899{
900 int ret, i, cpu = (long)pcpu;
901 struct zcache_preload *kp;
902
903 switch (action) {
904 case CPU_UP_PREPARE:
905 ret = zcache_comp_cpu_up(cpu);
906 if (ret != NOTIFY_OK) {
907 pr_err("%s: can't allocate compressor xform\n",
908 namestr);
909 return ret;
910 }
911 per_cpu(zcache_dstmem, cpu) = (void *)__get_free_pages(
912 GFP_KERNEL | __GFP_REPEAT, ZCACHE_DSTMEM_ORDER);
913 if (ramster_enabled)
914 ramster_cpu_up(cpu);
915 break;
916 case CPU_DEAD:
917 case CPU_UP_CANCELED:
918 zcache_comp_cpu_down(cpu);
919 free_pages((unsigned long)per_cpu(zcache_dstmem, cpu),
920 ZCACHE_DSTMEM_ORDER);
921 per_cpu(zcache_dstmem, cpu) = NULL;
922 kp = &per_cpu(zcache_preloads, cpu);
923 for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) {
924 if (kp->objnodes[i])
925 kmem_cache_free(zcache_objnode_cache,
926 kp->objnodes[i]);
927 }
928 if (kp->obj) {
929 kmem_cache_free(zcache_obj_cache, kp->obj);
930 kp->obj = NULL;
931 }
932 if (ramster_enabled)
933 ramster_cpu_down(cpu);
934 break;
935 default:
936 break;
937 }
938 return NOTIFY_OK;
939}
940
941static struct notifier_block zcache_cpu_notifier_block = {
942 .notifier_call = zcache_cpu_notifier
943};
944
945/*
946 * The following code interacts with the zbud eviction and zbud
947 * zombify code to access LRU pages
948 */
949
950static struct page *zcache_evict_eph_pageframe(void)
951{
952 struct page *page;
953 unsigned int zsize = 0, zpages = 0;
954
955 page = zbud_evict_pageframe_lru(&zsize, &zpages);
956 if (page == NULL)
957 goto out;
958 zcache_eph_zbytes = atomic_long_sub_return(zsize,
959 &zcache_eph_zbytes_atomic);
960 zcache_eph_zpages = atomic_sub_return(zpages,
961 &zcache_eph_zpages_atomic);
962 zcache_evicted_eph_zpages++;
963 zcache_eph_pageframes =
964 atomic_dec_return(&zcache_eph_pageframes_atomic);
965 zcache_evicted_eph_pageframes++;
966out:
967 return page;
968}
969
970#ifdef FRONTSWAP_HAS_UNUSE
971static void unswiz(struct tmem_oid oid, u32 index,
972 unsigned *type, pgoff_t *offset);
973
974/*
975 * Choose an LRU persistent pageframe and attempt to "unuse" it by
976 * calling frontswap_unuse on both zpages.
977 *
978 * This is work-in-progress.
979 */
980
981static int zcache_frontswap_unuse(void)
982{
983 struct tmem_handle th[2];
984 int ret = -ENOMEM;
985 int nzbuds, unuse_ret;
986 unsigned type;
987 struct page *newpage1 = NULL, *newpage2 = NULL;
988 struct page *evictpage1 = NULL, *evictpage2 = NULL;
989 pgoff_t offset;
990
991 newpage1 = alloc_page(ZCACHE_GFP_MASK);
992 newpage2 = alloc_page(ZCACHE_GFP_MASK);
993 if (newpage1 == NULL)
994 evictpage1 = zcache_evict_eph_pageframe();
995 if (newpage2 == NULL)
996 evictpage2 = zcache_evict_eph_pageframe();
997 if (evictpage1 == NULL || evictpage2 == NULL)
998 goto free_and_out;
999 /* ok, we have two pages pre-allocated */
1000 nzbuds = zbud_make_zombie_lru(&th[0], NULL, NULL, false);
1001 if (nzbuds == 0) {
1002 ret = -ENOENT;
1003 goto free_and_out;
1004 }
1005 unswiz(th[0].oid, th[0].index, &type, &offset);
1006 unuse_ret = frontswap_unuse(type, offset,
1007 newpage1 != NULL ? newpage1 : evictpage1,
1008 ZCACHE_GFP_MASK);
1009 if (unuse_ret != 0)
1010 goto free_and_out;
1011 else if (evictpage1 != NULL)
1012 zcache_unacct_page();
1013 newpage1 = NULL;
1014 evictpage1 = NULL;
1015 if (nzbuds == 2) {
1016 unswiz(th[1].oid, th[1].index, &type, &offset);
1017 unuse_ret = frontswap_unuse(type, offset,
1018 newpage2 != NULL ? newpage2 : evictpage2,
1019 ZCACHE_GFP_MASK);
1020 if (unuse_ret != 0) {
1021 goto free_and_out;
1022 } else if (evictpage2 != NULL) {
1023 zcache_unacct_page();
1024 }
1025 }
1026 ret = 0;
1027 goto out;
1028
1029free_and_out:
1030 if (newpage1 != NULL)
1031 __free_page(newpage1);
1032 if (newpage2 != NULL)
1033 __free_page(newpage2);
1034 if (evictpage1 != NULL)
1035 zcache_free_page(evictpage1);
1036 if (evictpage2 != NULL)
1037 zcache_free_page(evictpage2);
1038out:
1039 return ret;
1040}
1041#endif
1042
1043/*
1044 * When zcache is disabled ("frozen"), pools can be created and destroyed,
1045 * but all puts (and thus all other operations that require memory allocation)
1046 * must fail. If zcache is unfrozen, accepts puts, then frozen again,
1047 * data consistency requires all puts while frozen to be converted into
1048 * flushes.
1049 */
1050static bool zcache_freeze;
1051
1052/*
1053 * This zcache shrinker interface reduces the number of ephemeral pageframes
1054 * used by zcache to approximately the same as the total number of LRU_FILE
1055 * pageframes in use.
1056 */
1057static int shrink_zcache_memory(struct shrinker *shrink,
1058 struct shrink_control *sc)
1059{
1060 static bool in_progress;
1061 int ret = -1;
1062 int nr = sc->nr_to_scan;
1063 int nr_evict = 0;
1064 int nr_unuse = 0;
1065 struct page *page;
1066#ifdef FRONTSWAP_HAS_UNUSE
1067 int unuse_ret;
1068#endif
1069
1070 if (nr <= 0)
1071 goto skip_evict;
1072
1073 /* don't allow more than one eviction thread at a time */
1074 if (in_progress)
1075 goto skip_evict;
1076
1077 in_progress = true;
1078
1079 /* we are going to ignore nr, and target a different value */
1080 zcache_last_active_file_pageframes =
1081 global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE);
1082 zcache_last_inactive_file_pageframes =
1083 global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE);
1084 nr_evict = zcache_eph_pageframes - zcache_last_active_file_pageframes +
1085 zcache_last_inactive_file_pageframes;
1086 while (nr_evict-- > 0) {
1087 page = zcache_evict_eph_pageframe();
1088 if (page == NULL)
1089 break;
1090 zcache_free_page(page);
1091 }
1092
1093 zcache_last_active_anon_pageframes =
1094 global_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON);
1095 zcache_last_inactive_anon_pageframes =
1096 global_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON);
1097 nr_unuse = zcache_pers_pageframes - zcache_last_active_anon_pageframes +
1098 zcache_last_inactive_anon_pageframes;
1099#ifdef FRONTSWAP_HAS_UNUSE
1100 /* rate limit for testing */
1101 if (nr_unuse > 32)
1102 nr_unuse = 32;
1103 while (nr_unuse-- > 0) {
1104 unuse_ret = zcache_frontswap_unuse();
1105 if (unuse_ret == -ENOMEM)
1106 break;
1107 }
1108#endif
1109 in_progress = false;
1110
1111skip_evict:
1112 /* resample: has changed, but maybe not all the way yet */
1113 zcache_last_active_file_pageframes =
1114 global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE);
1115 zcache_last_inactive_file_pageframes =
1116 global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE);
1117 ret = zcache_eph_pageframes - zcache_last_active_file_pageframes +
1118 zcache_last_inactive_file_pageframes;
1119 if (ret < 0)
1120 ret = 0;
1121 return ret;
1122}
1123
1124static struct shrinker zcache_shrinker = {
1125 .shrink = shrink_zcache_memory,
1126 .seeks = DEFAULT_SEEKS,
1127};
1128
1129/*
1130 * zcache shims between cleancache/frontswap ops and tmem
1131 */
1132
1133/* FIXME rename these core routines to zcache_tmemput etc? */
1134int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp,
1135 uint32_t index, void *page,
1136 unsigned int size, bool raw, int ephemeral)
1137{
1138 struct tmem_pool *pool;
1139 struct tmem_handle th;
1140 int ret = -1;
1141 void *pampd = NULL;
1142
1143 BUG_ON(!irqs_disabled());
1144 pool = zcache_get_pool_by_id(cli_id, pool_id);
1145 if (unlikely(pool == NULL))
1146 goto out;
1147 if (!zcache_freeze) {
1148 ret = 0;
1149 th.client_id = cli_id;
1150 th.pool_id = pool_id;
1151 th.oid = *oidp;
1152 th.index = index;
1153 pampd = zcache_pampd_create((char *)page, size, raw,
1154 ephemeral, &th);
1155 if (pampd == NULL) {
1156 ret = -ENOMEM;
1157 if (ephemeral)
1158 zcache_failed_eph_puts++;
1159 else
1160 zcache_failed_pers_puts++;
1161 } else {
1162 if (ramster_enabled)
1163 ramster_do_preload_flnode(pool);
1164 ret = tmem_put(pool, oidp, index, 0, pampd);
1165 if (ret < 0)
1166 BUG();
1167 }
1168 zcache_put_pool(pool);
1169 } else {
1170 zcache_put_to_flush++;
1171 if (ramster_enabled)
1172 ramster_do_preload_flnode(pool);
1173 if (atomic_read(&pool->obj_count) > 0)
1174 /* the put fails whether the flush succeeds or not */
1175 (void)tmem_flush_page(pool, oidp, index);
1176 zcache_put_pool(pool);
1177 }
1178out:
1179 return ret;
1180}
1181
1182int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp,
1183 uint32_t index, void *page,
1184 size_t *sizep, bool raw, int get_and_free)
1185{
1186 struct tmem_pool *pool;
1187 int ret = -1;
1188 bool eph;
1189
1190 if (!raw) {
1191 BUG_ON(irqs_disabled());
1192 BUG_ON(in_softirq());
1193 }
1194 pool = zcache_get_pool_by_id(cli_id, pool_id);
1195 eph = is_ephemeral(pool);
1196 if (likely(pool != NULL)) {
1197 if (atomic_read(&pool->obj_count) > 0)
1198 ret = tmem_get(pool, oidp, index, (char *)(page),
1199 sizep, raw, get_and_free);
1200 zcache_put_pool(pool);
1201 }
1202 WARN_ONCE((!is_ephemeral(pool) && (ret != 0)),
1203 "zcache_get fails on persistent pool, "
1204 "bad things are very likely to happen soon\n");
1205#ifdef RAMSTER_TESTING
1206 if (ret != 0 && ret != -1 && !(ret == -EINVAL && is_ephemeral(pool)))
1207 pr_err("TESTING zcache_get tmem_get returns ret=%d\n", ret);
1208#endif
1209 return ret;
1210}
1211
1212int zcache_flush_page(int cli_id, int pool_id,
1213 struct tmem_oid *oidp, uint32_t index)
1214{
1215 struct tmem_pool *pool;
1216 int ret = -1;
1217 unsigned long flags;
1218
1219 local_irq_save(flags);
1220 zcache_flush_total++;
1221 pool = zcache_get_pool_by_id(cli_id, pool_id);
1222 if (ramster_enabled)
1223 ramster_do_preload_flnode(pool);
1224 if (likely(pool != NULL)) {
1225 if (atomic_read(&pool->obj_count) > 0)
1226 ret = tmem_flush_page(pool, oidp, index);
1227 zcache_put_pool(pool);
1228 }
1229 if (ret >= 0)
1230 zcache_flush_found++;
1231 local_irq_restore(flags);
1232 return ret;
1233}
1234
1235int zcache_flush_object(int cli_id, int pool_id,
1236 struct tmem_oid *oidp)
1237{
1238 struct tmem_pool *pool;
1239 int ret = -1;
1240 unsigned long flags;
1241
1242 local_irq_save(flags);
1243 zcache_flobj_total++;
1244 pool = zcache_get_pool_by_id(cli_id, pool_id);
1245 if (ramster_enabled)
1246 ramster_do_preload_flnode(pool);
1247 if (likely(pool != NULL)) {
1248 if (atomic_read(&pool->obj_count) > 0)
1249 ret = tmem_flush_object(pool, oidp);
1250 zcache_put_pool(pool);
1251 }
1252 if (ret >= 0)
1253 zcache_flobj_found++;
1254 local_irq_restore(flags);
1255 return ret;
1256}
1257
1258static int zcache_client_destroy_pool(int cli_id, int pool_id)
1259{
1260 struct tmem_pool *pool = NULL;
1261 struct zcache_client *cli = NULL;
1262 int ret = -1;
1263
1264 if (pool_id < 0)
1265 goto out;
1266 if (cli_id == LOCAL_CLIENT)
1267 cli = &zcache_host;
1268 else if ((unsigned int)cli_id < MAX_CLIENTS)
1269 cli = &zcache_clients[cli_id];
1270 if (cli == NULL)
1271 goto out;
1272 atomic_inc(&cli->refcount);
1273 pool = cli->tmem_pools[pool_id];
1274 if (pool == NULL)
1275 goto out;
1276 cli->tmem_pools[pool_id] = NULL;
1277 /* wait for pool activity on other cpus to quiesce */
1278 while (atomic_read(&pool->refcount) != 0)
1279 ;
1280 atomic_dec(&cli->refcount);
1281 local_bh_disable();
1282 ret = tmem_destroy_pool(pool);
1283 local_bh_enable();
1284 kfree(pool);
1285 if (cli_id == LOCAL_CLIENT)
1286 pr_info("%s: destroyed local pool id=%d\n", namestr, pool_id);
1287 else
1288 pr_info("%s: destroyed pool id=%d, client=%d\n",
1289 namestr, pool_id, cli_id);
1290out:
1291 return ret;
1292}
1293
1294int zcache_new_pool(uint16_t cli_id, uint32_t flags)
1295{
1296 int poolid = -1;
1297 struct tmem_pool *pool;
1298 struct zcache_client *cli = NULL;
1299
1300 if (cli_id == LOCAL_CLIENT)
1301 cli = &zcache_host;
1302 else if ((unsigned int)cli_id < MAX_CLIENTS)
1303 cli = &zcache_clients[cli_id];
1304 if (cli == NULL)
1305 goto out;
1306 atomic_inc(&cli->refcount);
1307 pool = kmalloc(sizeof(struct tmem_pool), GFP_ATOMIC);
1308 if (pool == NULL) {
1309 pr_info("%s: pool creation failed: out of memory\n", namestr);
1310 goto out;
1311 }
1312
1313 for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++)
1314 if (cli->tmem_pools[poolid] == NULL)
1315 break;
1316 if (poolid >= MAX_POOLS_PER_CLIENT) {
1317 pr_info("%s: pool creation failed: max exceeded\n", namestr);
1318 kfree(pool);
1319 poolid = -1;
1320 goto out;
1321 }
1322 atomic_set(&pool->refcount, 0);
1323 pool->client = cli;
1324 pool->pool_id = poolid;
1325 tmem_new_pool(pool, flags);
1326 cli->tmem_pools[poolid] = pool;
1327 if (cli_id == LOCAL_CLIENT)
1328 pr_info("%s: created %s local tmem pool, id=%d\n", namestr,
1329 flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
1330 poolid);
1331 else
1332 pr_info("%s: created %s tmem pool, id=%d, client=%d\n", namestr,
1333 flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
1334 poolid, cli_id);
1335out:
1336 if (cli != NULL)
1337 atomic_dec(&cli->refcount);
1338 return poolid;
1339}
1340
1341static int zcache_local_new_pool(uint32_t flags)
1342{
1343 return zcache_new_pool(LOCAL_CLIENT, flags);
1344}
1345
1346int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph)
1347{
1348 struct tmem_pool *pool;
1349 struct zcache_client *cli;
1350 uint32_t flags = eph ? 0 : TMEM_POOL_PERSIST;
1351 int ret = -1;
1352
1353 BUG_ON(!ramster_enabled);
1354 if (cli_id == LOCAL_CLIENT)
1355 goto out;
1356 if (pool_id >= MAX_POOLS_PER_CLIENT)
1357 goto out;
1358 if (cli_id >= MAX_CLIENTS)
1359 goto out;
1360
1361 cli = &zcache_clients[cli_id];
1362 if ((eph && disable_cleancache) || (!eph && disable_frontswap)) {
1363 pr_err("zcache_autocreate_pool: pool type disabled\n");
1364 goto out;
1365 }
1366 if (!cli->allocated) {
1367 if (zcache_new_client(cli_id)) {
1368 pr_err("zcache_autocreate_pool: can't create client\n");
1369 goto out;
1370 }
1371 cli = &zcache_clients[cli_id];
1372 }
1373 atomic_inc(&cli->refcount);
1374 pool = cli->tmem_pools[pool_id];
1375 if (pool != NULL) {
1376 if (pool->persistent && eph) {
1377 pr_err("zcache_autocreate_pool: type mismatch\n");
1378 goto out;
1379 }
1380 ret = 0;
1381 goto out;
1382 }
1383 pool = kmalloc(sizeof(struct tmem_pool), GFP_KERNEL);
1384 if (pool == NULL) {
1385 pr_info("%s: pool creation failed: out of memory\n", namestr);
1386 goto out;
1387 }
1388 atomic_set(&pool->refcount, 0);
1389 pool->client = cli;
1390 pool->pool_id = pool_id;
1391 tmem_new_pool(pool, flags);
1392 cli->tmem_pools[pool_id] = pool;
1393 pr_info("%s: AUTOcreated %s tmem poolid=%d, for remote client=%d\n",
1394 namestr, flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
1395 pool_id, cli_id);
1396 ret = 0;
1397out:
1398 if (cli != NULL)
1399 atomic_dec(&cli->refcount);
1400 return ret;
1401}
1402
1403/**********
1404 * Two kernel functionalities currently can be layered on top of tmem.
1405 * These are "cleancache" which is used as a second-chance cache for clean
1406 * page cache pages; and "frontswap" which is used for swap pages
1407 * to avoid writes to disk. A generic "shim" is provided here for each
1408 * to translate in-kernel semantics to zcache semantics.
1409 */
1410
1411static void zcache_cleancache_put_page(int pool_id,
1412 struct cleancache_filekey key,
1413 pgoff_t index, struct page *page)
1414{
1415 u32 ind = (u32) index;
1416 struct tmem_oid oid = *(struct tmem_oid *)&key;
1417
1418 if (!disable_cleancache_ignore_nonactive && !PageWasActive(page)) {
1419 zcache_eph_nonactive_puts_ignored++;
1420 return;
1421 }
1422 if (likely(ind == index))
1423 (void)zcache_put_page(LOCAL_CLIENT, pool_id, &oid, index,
1424 page, PAGE_SIZE, false, 1);
1425}
1426
1427static int zcache_cleancache_get_page(int pool_id,
1428 struct cleancache_filekey key,
1429 pgoff_t index, struct page *page)
1430{
1431 u32 ind = (u32) index;
1432 struct tmem_oid oid = *(struct tmem_oid *)&key;
1433 size_t size;
1434 int ret = -1;
1435
1436 if (likely(ind == index)) {
1437 ret = zcache_get_page(LOCAL_CLIENT, pool_id, &oid, index,
1438 page, &size, false, 0);
1439 BUG_ON(ret >= 0 && size != PAGE_SIZE);
1440 if (ret == 0)
1441 SetPageWasActive(page);
1442 }
1443 return ret;
1444}
1445
1446static void zcache_cleancache_flush_page(int pool_id,
1447 struct cleancache_filekey key,
1448 pgoff_t index)
1449{
1450 u32 ind = (u32) index;
1451 struct tmem_oid oid = *(struct tmem_oid *)&key;
1452
1453 if (likely(ind == index))
1454 (void)zcache_flush_page(LOCAL_CLIENT, pool_id, &oid, ind);
1455}
1456
1457static void zcache_cleancache_flush_inode(int pool_id,
1458 struct cleancache_filekey key)
1459{
1460 struct tmem_oid oid = *(struct tmem_oid *)&key;
1461
1462 (void)zcache_flush_object(LOCAL_CLIENT, pool_id, &oid);
1463}
1464
1465static void zcache_cleancache_flush_fs(int pool_id)
1466{
1467 if (pool_id >= 0)
1468 (void)zcache_client_destroy_pool(LOCAL_CLIENT, pool_id);
1469}
1470
1471static int zcache_cleancache_init_fs(size_t pagesize)
1472{
1473 BUG_ON(sizeof(struct cleancache_filekey) !=
1474 sizeof(struct tmem_oid));
1475 BUG_ON(pagesize != PAGE_SIZE);
1476 return zcache_local_new_pool(0);
1477}
1478
1479static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize)
1480{
1481 /* shared pools are unsupported and map to private */
1482 BUG_ON(sizeof(struct cleancache_filekey) !=
1483 sizeof(struct tmem_oid));
1484 BUG_ON(pagesize != PAGE_SIZE);
1485 return zcache_local_new_pool(0);
1486}
1487
1488static struct cleancache_ops zcache_cleancache_ops = {
1489 .put_page = zcache_cleancache_put_page,
1490 .get_page = zcache_cleancache_get_page,
1491 .invalidate_page = zcache_cleancache_flush_page,
1492 .invalidate_inode = zcache_cleancache_flush_inode,
1493 .invalidate_fs = zcache_cleancache_flush_fs,
1494 .init_shared_fs = zcache_cleancache_init_shared_fs,
1495 .init_fs = zcache_cleancache_init_fs
1496};
1497
1498struct cleancache_ops zcache_cleancache_register_ops(void)
1499{
1500 struct cleancache_ops old_ops =
1501 cleancache_register_ops(&zcache_cleancache_ops);
1502
1503 return old_ops;
1504}
1505
1506/* a single tmem poolid is used for all frontswap "types" (swapfiles) */
1507static int zcache_frontswap_poolid __read_mostly = -1;
1508
1509/*
1510 * Swizzling increases objects per swaptype, increasing tmem concurrency
1511 * for heavy swaploads. Later, larger nr_cpus -> larger SWIZ_BITS
1512 * Setting SWIZ_BITS to 27 basically reconstructs the swap entry from
1513 * frontswap_get_page(), but has side-effects. Hence using 8.
1514 */
1515#define SWIZ_BITS 8
1516#define SWIZ_MASK ((1 << SWIZ_BITS) - 1)
1517#define _oswiz(_type, _ind) ((_type << SWIZ_BITS) | (_ind & SWIZ_MASK))
1518#define iswiz(_ind) (_ind >> SWIZ_BITS)
1519
1520static inline struct tmem_oid oswiz(unsigned type, u32 ind)
1521{
1522 struct tmem_oid oid = { .oid = { 0 } };
1523 oid.oid[0] = _oswiz(type, ind);
1524 return oid;
1525}
1526
1527#ifdef FRONTSWAP_HAS_UNUSE
1528static void unswiz(struct tmem_oid oid, u32 index,
1529 unsigned *type, pgoff_t *offset)
1530{
1531 *type = (unsigned)(oid.oid[0] >> SWIZ_BITS);
1532 *offset = (pgoff_t)((index << SWIZ_BITS) |
1533 (oid.oid[0] & SWIZ_MASK));
1534}
1535#endif
1536
1537static int zcache_frontswap_put_page(unsigned type, pgoff_t offset,
1538 struct page *page)
1539{
1540 u64 ind64 = (u64)offset;
1541 u32 ind = (u32)offset;
1542 struct tmem_oid oid = oswiz(type, ind);
1543 int ret = -1;
1544 unsigned long flags;
1545
1546 BUG_ON(!PageLocked(page));
1547 if (!disable_frontswap_ignore_nonactive && !PageWasActive(page)) {
1548 zcache_pers_nonactive_puts_ignored++;
1549 ret = -ERANGE;
1550 goto out;
1551 }
1552 if (likely(ind64 == ind)) {
1553 local_irq_save(flags);
1554 ret = zcache_put_page(LOCAL_CLIENT, zcache_frontswap_poolid,
1555 &oid, iswiz(ind),
1556 page, PAGE_SIZE, false, 0);
1557 local_irq_restore(flags);
1558 }
1559out:
1560 return ret;
1561}
1562
1563/* returns 0 if the page was successfully gotten from frontswap, -1 if
1564 * was not present (should never happen!) */
1565static int zcache_frontswap_get_page(unsigned type, pgoff_t offset,
1566 struct page *page)
1567{
1568 u64 ind64 = (u64)offset;
1569 u32 ind = (u32)offset;
1570 struct tmem_oid oid = oswiz(type, ind);
1571 size_t size;
1572 int ret = -1, get_and_free;
1573
1574 if (frontswap_has_exclusive_gets)
1575 get_and_free = 1;
1576 else
1577 get_and_free = -1;
1578 BUG_ON(!PageLocked(page));
1579 if (likely(ind64 == ind)) {
1580 ret = zcache_get_page(LOCAL_CLIENT, zcache_frontswap_poolid,
1581 &oid, iswiz(ind),
1582 page, &size, false, get_and_free);
1583 BUG_ON(ret >= 0 && size != PAGE_SIZE);
1584 }
1585 return ret;
1586}
1587
1588/* flush a single page from frontswap */
1589static void zcache_frontswap_flush_page(unsigned type, pgoff_t offset)
1590{
1591 u64 ind64 = (u64)offset;
1592 u32 ind = (u32)offset;
1593 struct tmem_oid oid = oswiz(type, ind);
1594
1595 if (likely(ind64 == ind))
1596 (void)zcache_flush_page(LOCAL_CLIENT, zcache_frontswap_poolid,
1597 &oid, iswiz(ind));
1598}
1599
1600/* flush all pages from the passed swaptype */
1601static void zcache_frontswap_flush_area(unsigned type)
1602{
1603 struct tmem_oid oid;
1604 int ind;
1605
1606 for (ind = SWIZ_MASK; ind >= 0; ind--) {
1607 oid = oswiz(type, ind);
1608 (void)zcache_flush_object(LOCAL_CLIENT,
1609 zcache_frontswap_poolid, &oid);
1610 }
1611}
1612
1613static void zcache_frontswap_init(unsigned ignored)
1614{
1615 /* a single tmem poolid is used for all frontswap "types" (swapfiles) */
1616 if (zcache_frontswap_poolid < 0)
1617 zcache_frontswap_poolid =
1618 zcache_local_new_pool(TMEM_POOL_PERSIST);
1619}
1620
1621static struct frontswap_ops zcache_frontswap_ops = {
1622 .store = zcache_frontswap_put_page,
1623 .load = zcache_frontswap_get_page,
1624 .invalidate_page = zcache_frontswap_flush_page,
1625 .invalidate_area = zcache_frontswap_flush_area,
1626 .init = zcache_frontswap_init
1627};
1628
1629struct frontswap_ops zcache_frontswap_register_ops(void)
1630{
1631 struct frontswap_ops old_ops =
1632 frontswap_register_ops(&zcache_frontswap_ops);
1633
1634 return old_ops;
1635}
1636
1637/*
1638 * zcache initialization
1639 * NOTE FOR NOW zcache or ramster MUST BE PROVIDED AS A KERNEL BOOT PARAMETER
1640 * OR NOTHING HAPPENS!
1641 */
1642
1643static int __init enable_zcache(char *s)
1644{
1645 zcache_enabled = 1;
1646 return 1;
1647}
1648__setup("zcache", enable_zcache);
1649
1650static int __init enable_ramster(char *s)
1651{
1652 zcache_enabled = 1;
1653#ifdef CONFIG_RAMSTER
1654 ramster_enabled = 1;
1655#endif
1656 return 1;
1657}
1658__setup("ramster", enable_ramster);
1659
1660/* allow independent dynamic disabling of cleancache and frontswap */
1661
1662static int __init no_cleancache(char *s)
1663{
1664 disable_cleancache = 1;
1665 return 1;
1666}
1667
1668__setup("nocleancache", no_cleancache);
1669
1670static int __init no_frontswap(char *s)
1671{
1672 disable_frontswap = 1;
1673 return 1;
1674}
1675
1676__setup("nofrontswap", no_frontswap);
1677
1678static int __init no_frontswap_exclusive_gets(char *s)
1679{
1680 frontswap_has_exclusive_gets = false;
1681 return 1;
1682}
1683
1684__setup("nofrontswapexclusivegets", no_frontswap_exclusive_gets);
1685
1686static int __init no_frontswap_ignore_nonactive(char *s)
1687{
1688 disable_frontswap_ignore_nonactive = 1;
1689 return 1;
1690}
1691
1692__setup("nofrontswapignorenonactive", no_frontswap_ignore_nonactive);
1693
1694static int __init no_cleancache_ignore_nonactive(char *s)
1695{
1696 disable_cleancache_ignore_nonactive = 1;
1697 return 1;
1698}
1699
1700__setup("nocleancacheignorenonactive", no_cleancache_ignore_nonactive);
1701
1702static int __init enable_zcache_compressor(char *s)
1703{
1704 strncpy(zcache_comp_name, s, ZCACHE_COMP_NAME_SZ);
1705 zcache_enabled = 1;
1706 return 1;
1707}
1708__setup("zcache=", enable_zcache_compressor);
1709
1710
1711static int __init zcache_comp_init(void)
1712{
1713 int ret = 0;
1714
1715 /* check crypto algorithm */
1716 if (*zcache_comp_name != '\0') {
1717 ret = crypto_has_comp(zcache_comp_name, 0, 0);
1718 if (!ret)
1719 pr_info("zcache: %s not supported\n",
1720 zcache_comp_name);
1721 }
1722 if (!ret)
1723 strcpy(zcache_comp_name, "lzo");
1724 ret = crypto_has_comp(zcache_comp_name, 0, 0);
1725 if (!ret) {
1726 ret = 1;
1727 goto out;
1728 }
1729 pr_info("zcache: using %s compressor\n", zcache_comp_name);
1730
1731 /* alloc percpu transforms */
1732 ret = 0;
1733 zcache_comp_pcpu_tfms = alloc_percpu(struct crypto_comp *);
1734 if (!zcache_comp_pcpu_tfms)
1735 ret = 1;
1736out:
1737 return ret;
1738}
1739
1740static int __init zcache_init(void)
1741{
1742 int ret = 0;
1743
1744 if (ramster_enabled) {
1745 namestr = "ramster";
1746 ramster_register_pamops(&zcache_pamops);
1747 }
1748#ifdef CONFIG_DEBUG_FS
1749 zcache_debugfs_init();
1750#endif
1751 if (zcache_enabled) {
1752 unsigned int cpu;
1753
1754 tmem_register_hostops(&zcache_hostops);
1755 tmem_register_pamops(&zcache_pamops);
1756 ret = register_cpu_notifier(&zcache_cpu_notifier_block);
1757 if (ret) {
1758 pr_err("%s: can't register cpu notifier\n", namestr);
1759 goto out;
1760 }
1761 ret = zcache_comp_init();
1762 if (ret) {
1763 pr_err("%s: compressor initialization failed\n",
1764 namestr);
1765 goto out;
1766 }
1767 for_each_online_cpu(cpu) {
1768 void *pcpu = (void *)(long)cpu;
1769 zcache_cpu_notifier(&zcache_cpu_notifier_block,
1770 CPU_UP_PREPARE, pcpu);
1771 }
1772 }
1773 zcache_objnode_cache = kmem_cache_create("zcache_objnode",
1774 sizeof(struct tmem_objnode), 0, 0, NULL);
1775 zcache_obj_cache = kmem_cache_create("zcache_obj",
1776 sizeof(struct tmem_obj), 0, 0, NULL);
1777 ret = zcache_new_client(LOCAL_CLIENT);
1778 if (ret) {
1779 pr_err("%s: can't create client\n", namestr);
1780 goto out;
1781 }
1782 zbud_init();
1783 if (zcache_enabled && !disable_cleancache) {
1784 struct cleancache_ops old_ops;
1785
1786 register_shrinker(&zcache_shrinker);
1787 old_ops = zcache_cleancache_register_ops();
1788 pr_info("%s: cleancache enabled using kernel transcendent "
1789 "memory and compression buddies\n", namestr);
1790#ifdef ZCACHE_DEBUG
1791 pr_info("%s: cleancache: ignorenonactive = %d\n",
1792 namestr, !disable_cleancache_ignore_nonactive);
1793#endif
1794 if (old_ops.init_fs != NULL)
1795 pr_warn("%s: cleancache_ops overridden\n", namestr);
1796 }
1797 if (zcache_enabled && !disable_frontswap) {
1798 struct frontswap_ops old_ops;
1799
1800 old_ops = zcache_frontswap_register_ops();
1801 if (frontswap_has_exclusive_gets)
1802 frontswap_tmem_exclusive_gets(true);
1803 pr_info("%s: frontswap enabled using kernel transcendent "
1804 "memory and compression buddies\n", namestr);
1805#ifdef ZCACHE_DEBUG
1806 pr_info("%s: frontswap: excl gets = %d active only = %d\n",
1807 namestr, frontswap_has_exclusive_gets,
1808 !disable_frontswap_ignore_nonactive);
1809#endif
1810 if (old_ops.init != NULL)
1811 pr_warn("%s: frontswap_ops overridden\n", namestr);
1812 }
1813 if (ramster_enabled)
1814 ramster_init(!disable_cleancache, !disable_frontswap,
1815 frontswap_has_exclusive_gets);
1816out:
1817 return ret;
1818}
1819
1820late_initcall(zcache_init);
diff --git a/drivers/staging/rtl8187se/ieee80211/dot11d.c b/drivers/staging/rtl8187se/ieee80211/dot11d.c
index 0e93eb0735a7..9d2d5c58add2 100644
--- a/drivers/staging/rtl8187se/ieee80211/dot11d.c
+++ b/drivers/staging/rtl8187se/ieee80211/dot11d.c
@@ -39,12 +39,11 @@ Dot11d_Reset(struct ieee80211_device *ieee)
39 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1); 39 memset(pDot11dInfo->channel_map, 0, MAX_CHANNEL_NUMBER+1);
40 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1); 40 memset(pDot11dInfo->MaxTxPwrDbmList, 0xFF, MAX_CHANNEL_NUMBER+1);
41 // Set new channel map 41 // Set new channel map
42 for (i=1; i<=11; i++) { 42 for (i = 1; i <= 11; i++)
43 (pDot11dInfo->channel_map)[i] = 1; 43 (pDot11dInfo->channel_map)[i] = 1;
44 } 44
45 for (i=12; i<=14; i++) { 45 for (i = 12; i <= 14; i++)
46 (pDot11dInfo->channel_map)[i] = 2; 46 (pDot11dInfo->channel_map)[i] = 2;
47 }
48 47
49 pDot11dInfo->State = DOT11D_STATE_NONE; 48 pDot11dInfo->State = DOT11D_STATE_NONE;
50 pDot11dInfo->CountryIeLen = 0; 49 pDot11dInfo->CountryIeLen = 0;
@@ -68,17 +67,16 @@ Dot11d_Reset(struct ieee80211_device *ieee)
68void 67void
69Dot11d_UpdateCountryIe( 68Dot11d_UpdateCountryIe(
70 struct ieee80211_device *dev, 69 struct ieee80211_device *dev,
71 u8 * pTaddr, 70 u8 *pTaddr,
72 u16 CoutryIeLen, 71 u16 CoutryIeLen,
73 u8 * pCoutryIe 72 u8 *pCoutryIe
74 ) 73 )
75{ 74{
76 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 75 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
77 u8 i, j, NumTriples, MaxChnlNum; 76 u8 i, j, NumTriples, MaxChnlNum;
78 PCHNL_TXPOWER_TRIPLE pTriple; 77 PCHNL_TXPOWER_TRIPLE pTriple;
79 78
80 if((CoutryIeLen - 3)%3 != 0) 79 if ((CoutryIeLen - 3)%3 != 0) {
81 {
82 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); 80 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
83 Dot11d_Reset(dev); 81 Dot11d_Reset(dev);
84 return; 82 return;
@@ -89,35 +87,33 @@ Dot11d_UpdateCountryIe(
89 MaxChnlNum = 0; 87 MaxChnlNum = 0;
90 NumTriples = (CoutryIeLen - 3) / 3; // skip 3-byte country string. 88 NumTriples = (CoutryIeLen - 3) / 3; // skip 3-byte country string.
91 pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3); 89 pTriple = (PCHNL_TXPOWER_TRIPLE)(pCoutryIe + 3);
92 for(i = 0; i < NumTriples; i++) 90 for (i = 0; i < NumTriples; i++) {
93 { 91 if (MaxChnlNum >= pTriple->FirstChnl) {
94 if(MaxChnlNum >= pTriple->FirstChnl) 92 // It is not in a monotonically increasing order, so stop processing.
95 { // It is not in a monotonically increasing order, so stop processing.
96 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n"); 93 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........1\n");
97 Dot11d_Reset(dev); 94 Dot11d_Reset(dev);
98 return; 95 return;
99 } 96 }
100 if(MAX_CHANNEL_NUMBER < (pTriple->FirstChnl + pTriple->NumChnls)) 97 if (MAX_CHANNEL_NUMBER < (pTriple->FirstChnl + pTriple->NumChnls)) {
101 { // It is not a valid set of channel id, so stop processing. 98 // It is not a valid set of channel id, so stop processing.
102 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n"); 99 printk("Dot11d_UpdateCountryIe(): Invalid country IE, skip it........2\n");
103 Dot11d_Reset(dev); 100 Dot11d_Reset(dev);
104 return; 101 return;
105 } 102 }
106 103
107 for(j = 0 ; j < pTriple->NumChnls; j++) 104 for (j = 0 ; j < pTriple->NumChnls; j++) {
108 {
109 pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1; 105 pDot11dInfo->channel_map[pTriple->FirstChnl + j] = 1;
110 pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] = pTriple->MaxTxPowerInDbm; 106 pDot11dInfo->MaxTxPwrDbmList[pTriple->FirstChnl + j] = pTriple->MaxTxPowerInDbm;
111 MaxChnlNum = pTriple->FirstChnl + j; 107 MaxChnlNum = pTriple->FirstChnl + j;
112 } 108 }
113 109
114 pTriple = (PCHNL_TXPOWER_TRIPLE)((u8*)pTriple + 3); 110 pTriple = (PCHNL_TXPOWER_TRIPLE)((u8 *)pTriple + 3);
115 } 111 }
116#if 1 112#if 1
117 //printk("Dot11d_UpdateCountryIe(): Channel List:\n"); 113 //printk("Dot11d_UpdateCountryIe(): Channel List:\n");
118 printk("Channel List:"); 114 printk("Channel List:");
119 for(i=1; i<= MAX_CHANNEL_NUMBER; i++) 115 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++)
120 if(pDot11dInfo->channel_map[i] > 0) 116 if (pDot11dInfo->channel_map[i] > 0)
121 printk(" %d", i); 117 printk(" %d", i);
122 printk("\n"); 118 printk("\n");
123#endif 119#endif
@@ -125,7 +121,7 @@ Dot11d_UpdateCountryIe(
125 UPDATE_CIE_SRC(dev, pTaddr); 121 UPDATE_CIE_SRC(dev, pTaddr);
126 122
127 pDot11dInfo->CountryIeLen = CoutryIeLen; 123 pDot11dInfo->CountryIeLen = CoutryIeLen;
128 memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe,CoutryIeLen); 124 memcpy(pDot11dInfo->CountryIeBuf, pCoutryIe, CoutryIeLen);
129 pDot11dInfo->State = DOT11D_STATE_LEARNED; 125 pDot11dInfo->State = DOT11D_STATE_LEARNED;
130} 126}
131 127
@@ -138,13 +134,11 @@ DOT11D_GetMaxTxPwrInDbm(
138 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 134 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
139 u8 MaxTxPwrInDbm = 255; 135 u8 MaxTxPwrInDbm = 255;
140 136
141 if(MAX_CHANNEL_NUMBER < Channel) 137 if (MAX_CHANNEL_NUMBER < Channel) {
142 {
143 printk("DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n"); 138 printk("DOT11D_GetMaxTxPwrInDbm(): Invalid Channel\n");
144 return MaxTxPwrInDbm; 139 return MaxTxPwrInDbm;
145 } 140 }
146 if(pDot11dInfo->channel_map[Channel]) 141 if (pDot11dInfo->channel_map[Channel]) {
147 {
148 MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel]; 142 MaxTxPwrInDbm = pDot11dInfo->MaxTxPwrDbmList[Channel];
149 } 143 }
150 144
@@ -154,20 +148,19 @@ DOT11D_GetMaxTxPwrInDbm(
154 148
155void 149void
156DOT11D_ScanComplete( 150DOT11D_ScanComplete(
157 struct ieee80211_device * dev 151 struct ieee80211_device *dev
158 ) 152 )
159{ 153{
160 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 154 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
161 155
162 switch(pDot11dInfo->State) 156 switch (pDot11dInfo->State) {
163 {
164 case DOT11D_STATE_LEARNED: 157 case DOT11D_STATE_LEARNED:
165 pDot11dInfo->State = DOT11D_STATE_DONE; 158 pDot11dInfo->State = DOT11D_STATE_DONE;
166 break; 159 break;
167 160
168 case DOT11D_STATE_DONE: 161 case DOT11D_STATE_DONE:
169 if( GET_CIE_WATCHDOG(dev) == 0 ) 162 if (GET_CIE_WATCHDOG(dev) == 0) {
170 { // Reset country IE if previous one is gone. 163 // Reset country IE if previous one is gone.
171 Dot11d_Reset(dev); 164 Dot11d_Reset(dev);
172 } 165 }
173 break; 166 break;
@@ -177,24 +170,23 @@ DOT11D_ScanComplete(
177} 170}
178 171
179int IsLegalChannel( 172int IsLegalChannel(
180 struct ieee80211_device * dev, 173 struct ieee80211_device *dev,
181 u8 channel 174 u8 channel
182) 175)
183{ 176{
184 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev); 177 PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(dev);
185 178
186 if(MAX_CHANNEL_NUMBER < channel) 179 if (MAX_CHANNEL_NUMBER < channel) {
187 {
188 printk("IsLegalChannel(): Invalid Channel\n"); 180 printk("IsLegalChannel(): Invalid Channel\n");
189 return 0; 181 return 0;
190 } 182 }
191 if(pDot11dInfo->channel_map[channel] > 0) 183 if (pDot11dInfo->channel_map[channel] > 0)
192 return 1; 184 return 1;
193 return 0; 185 return 0;
194} 186}
195 187
196int ToLegalChannel( 188int ToLegalChannel(
197 struct ieee80211_device * dev, 189 struct ieee80211_device *dev,
198 u8 channel 190 u8 channel
199) 191)
200{ 192{
@@ -202,22 +194,19 @@ int ToLegalChannel(
202 u8 default_chn = 0; 194 u8 default_chn = 0;
203 u32 i = 0; 195 u32 i = 0;
204 196
205 for (i=1; i<= MAX_CHANNEL_NUMBER; i++) 197 for (i = 1; i <= MAX_CHANNEL_NUMBER; i++) {
206 { 198 if (pDot11dInfo->channel_map[i] > 0) {
207 if(pDot11dInfo->channel_map[i] > 0)
208 {
209 default_chn = i; 199 default_chn = i;
210 break; 200 break;
211 } 201 }
212 } 202 }
213 203
214 if(MAX_CHANNEL_NUMBER < channel) 204 if (MAX_CHANNEL_NUMBER < channel) {
215 {
216 printk("IsLegalChannel(): Invalid Channel\n"); 205 printk("IsLegalChannel(): Invalid Channel\n");
217 return default_chn; 206 return default_chn;
218 } 207 }
219 208
220 if(pDot11dInfo->channel_map[channel] > 0) 209 if (pDot11dInfo->channel_map[channel] > 0)
221 return channel; 210 return channel;
222 211
223 return default_chn; 212 return default_chn;
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c
index 4358c4b0ca60..07a1fbb6678e 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_module.c
@@ -68,10 +68,8 @@ static inline int ieee80211_networks_allocate(struct ieee80211_device *ieee)
68 ieee->networks = kcalloc( 68 ieee->networks = kcalloc(
69 MAX_NETWORK_COUNT, sizeof(struct ieee80211_network), 69 MAX_NETWORK_COUNT, sizeof(struct ieee80211_network),
70 GFP_KERNEL); 70 GFP_KERNEL);
71 if (!ieee->networks) { 71 if (!ieee->networks)
72 netdev_warn(ieee->dev, "Out of memory allocating beacons\n");
73 return -ENOMEM; 72 return -ENOMEM;
74 }
75 73
76 return 0; 74 return 0;
77} 75}
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c
index 446f15ec6396..e30315997bbe 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_rx.c
@@ -408,11 +408,9 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
408 // if (memcmp(entry->mac, mac, ETH_ALEN)){ 408 // if (memcmp(entry->mac, mac, ETH_ALEN)){
409 if (p == &ieee->ibss_mac_hash[index]) { 409 if (p == &ieee->ibss_mac_hash[index]) {
410 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC); 410 entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
411 if (!entry) { 411 if (!entry)
412 netdev_warn(ieee->dev,
413 "Cannot malloc new mac entry\n");
414 return 0; 412 return 0;
415 } 413
416 memcpy(entry->mac, mac, ETH_ALEN); 414 memcpy(entry->mac, mac, ETH_ALEN);
417 entry->seq_num[tid] = seq; 415 entry->seq_num[tid] = seq;
418 entry->frag_num[tid] = frag; 416 entry->frag_num[tid] = frag;
diff --git a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
index c7917b24425c..e014f7e74397 100644
--- a/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8187se/ieee80211/ieee80211_wx.c
@@ -41,9 +41,9 @@ static const char *ieee80211_modes[] = {
41 41
42#define MAX_CUSTOM_LEN 64 42#define MAX_CUSTOM_LEN 64
43static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee, 43static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee,
44 char *start, char *stop, 44 char *start, char *stop,
45 struct ieee80211_network *network, 45 struct ieee80211_network *network,
46 struct iw_request_info *info) 46 struct iw_request_info *info)
47{ 47{
48 char custom[MAX_CUSTOM_LEN]; 48 char custom[MAX_CUSTOM_LEN];
49 char *p; 49 char *p;
@@ -78,9 +78,9 @@ static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee,
78 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11%s", ieee80211_modes[network->mode]); 78 snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11%s", ieee80211_modes[network->mode]);
79 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN); 79 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_CHAR_LEN);
80 80
81 /* Add mode */ 81 /* Add mode */
82 iwe.cmd = SIOCGIWMODE; 82 iwe.cmd = SIOCGIWMODE;
83 if (network->capability & 83 if (network->capability &
84 (WLAN_CAPABILITY_BSS | WLAN_CAPABILITY_IBSS)) { 84 (WLAN_CAPABILITY_BSS | WLAN_CAPABILITY_IBSS)) {
85 if (network->capability & WLAN_CAPABILITY_BSS) 85 if (network->capability & WLAN_CAPABILITY_BSS)
86 iwe.u.mode = IW_MODE_MASTER; 86 iwe.u.mode = IW_MODE_MASTER;
@@ -90,7 +90,7 @@ static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee,
90 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN); 90 start = iwe_stream_add_event(info, start, stop, &iwe, IW_EV_UINT_LEN);
91 } 91 }
92 92
93 /* Add frequency/channel */ 93 /* Add frequency/channel */
94 iwe.cmd = SIOCGIWFREQ; 94 iwe.cmd = SIOCGIWFREQ;
95/* iwe.u.freq.m = ieee80211_frequency(network->channel, network->mode); 95/* iwe.u.freq.m = ieee80211_frequency(network->channel, network->mode);
96 iwe.u.freq.e = 3; */ 96 iwe.u.freq.e = 3; */
@@ -168,23 +168,23 @@ static inline char *rtl818x_translate_scan(struct ieee80211_device *ieee,
168 if (iwe.u.data.length) 168 if (iwe.u.data.length)
169 start = iwe_stream_add_point(info, start, stop, &iwe, custom); 169 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
170 170
171 memset(&iwe, 0, sizeof(iwe)); 171 memset(&iwe, 0, sizeof(iwe));
172 if (network->wpa_ie_len) { 172 if (network->wpa_ie_len) {
173 // printk("wpa_ie_len:%d\n", network->wpa_ie_len); 173 // printk("wpa_ie_len:%d\n", network->wpa_ie_len);
174 char buf[MAX_WPA_IE_LEN]; 174 char buf[MAX_WPA_IE_LEN];
175 memcpy(buf, network->wpa_ie, network->wpa_ie_len); 175 memcpy(buf, network->wpa_ie, network->wpa_ie_len);
176 iwe.cmd = IWEVGENIE; 176 iwe.cmd = IWEVGENIE;
177 iwe.u.data.length = network->wpa_ie_len; 177 iwe.u.data.length = network->wpa_ie_len;
178 start = iwe_stream_add_point(info, start, stop, &iwe, buf); 178 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
179 } 179 }
180 180
181 memset(&iwe, 0, sizeof(iwe)); 181 memset(&iwe, 0, sizeof(iwe));
182 if (network->rsn_ie_len) { 182 if (network->rsn_ie_len) {
183 // printk("=====>rsn_ie_len:\n", network->rsn_ie_len); 183 // printk("=====>rsn_ie_len:\n", network->rsn_ie_len);
184 char buf[MAX_WPA_IE_LEN]; 184 char buf[MAX_WPA_IE_LEN];
185 memcpy(buf, network->rsn_ie, network->rsn_ie_len); 185 memcpy(buf, network->rsn_ie, network->rsn_ie_len);
186 iwe.cmd = IWEVGENIE; 186 iwe.cmd = IWEVGENIE;
187 iwe.u.data.length = network->rsn_ie_len; 187 iwe.u.data.length = network->rsn_ie_len;
188 start = iwe_stream_add_point(info, start, stop, &iwe, buf); 188 start = iwe_stream_add_point(info, start, stop, &iwe, buf);
189 } 189 }
190 190
@@ -217,22 +217,18 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
217 down(&ieee->wx_sem); 217 down(&ieee->wx_sem);
218 spin_lock_irqsave(&ieee->lock, flags); 218 spin_lock_irqsave(&ieee->lock, flags);
219 219
220 if(!ieee->bHwRadioOff) 220 if (!ieee->bHwRadioOff) {
221 {
222 list_for_each_entry(network, &ieee->network_list, list) { 221 list_for_each_entry(network, &ieee->network_list, list) {
223 i++; 222 i++;
224 223
225 if((stop-ev)<200) 224 if ((stop-ev) < 200) {
226 {
227 err = -E2BIG; 225 err = -E2BIG;
228 break; 226 break;
229 } 227 }
230 if (ieee->scan_age == 0 || 228 if (ieee->scan_age == 0 ||
231 time_after(network->last_scanned + ieee->scan_age, jiffies)) 229 time_after(network->last_scanned + ieee->scan_age, jiffies)) {
232 {
233 ev = rtl818x_translate_scan(ieee, ev, stop, network, info); 230 ev = rtl818x_translate_scan(ieee, ev, stop, network, info);
234 } 231 } else
235 else
236 IEEE80211_DEBUG_SCAN( 232 IEEE80211_DEBUG_SCAN(
237 "Not showing network '%s (" 233 "Not showing network '%s ("
238 "%pM)' due to age (%lums).\n", 234 "%pM)' due to age (%lums).\n",
@@ -340,9 +336,8 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
340 kfree(new_crypt); 336 kfree(new_crypt);
341 new_crypt = NULL; 337 new_crypt = NULL;
342 338
343 printk(KERN_WARNING "%s: could not initialize WEP: " 339 netdev_warn(ieee->dev,
344 "load module ieee80211_crypt_wep\n", 340 "could not initialize WEP: load module ieee80211_crypt_wep\n");
345 dev->name);
346 return -EOPNOTSUPP; 341 return -EOPNOTSUPP;
347 } 342 }
348 *crypt = new_crypt; 343 *crypt = new_crypt;
@@ -359,7 +354,7 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
359 key, escape_essid(sec.keys[key], len), 354 key, escape_essid(sec.keys[key], len),
360 erq->length, len); 355 erq->length, len);
361 sec.key_sizes[key] = len; 356 sec.key_sizes[key] = len;
362 (*crypt)->ops->set_key(sec.keys[key], len, NULL, 357 (*crypt)->ops->set_key(sec.keys[key], len, NULL,
363 (*crypt)->priv); 358 (*crypt)->priv);
364 sec.flags |= (1 << key); 359 sec.flags |= (1 << key);
365 /* This ensures a key will be activated if no key is 360 /* This ensures a key will be activated if no key is
@@ -414,7 +409,7 @@ int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
414 if (ieee->reset_on_keychange && 409 if (ieee->reset_on_keychange &&
415 ieee->iw_mode != IW_MODE_INFRA && 410 ieee->iw_mode != IW_MODE_INFRA &&
416 ieee->reset_port && ieee->reset_port(dev)) { 411 ieee->reset_port && ieee->reset_port(dev)) {
417 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name); 412 netdev_dbg(ieee->dev, "reset_port failed\n");
418 return -EINVAL; 413 return -EINVAL;
419 } 414 }
420 return 0; 415 return 0;
@@ -430,7 +425,7 @@ int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
430 425
431 IEEE80211_DEBUG_WX("GET_ENCODE\n"); 426 IEEE80211_DEBUG_WX("GET_ENCODE\n");
432 427
433 if(ieee->iw_mode == IW_MODE_MONITOR) 428 if (ieee->iw_mode == IW_MODE_MONITOR)
434 return -1; 429 return -1;
435 430
436 key = erq->flags & IW_ENCODE_INDEX; 431 key = erq->flags & IW_ENCODE_INDEX;
@@ -472,240 +467,240 @@ int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
472} 467}
473 468
474int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee, 469int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
475 struct iw_request_info *info, 470 struct iw_request_info *info,
476 union iwreq_data *wrqu, char *extra) 471 union iwreq_data *wrqu, char *extra)
477{ 472{
478 struct net_device *dev = ieee->dev; 473 struct net_device *dev = ieee->dev;
479 struct iw_point *encoding = &wrqu->encoding; 474 struct iw_point *encoding = &wrqu->encoding;
480 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; 475 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
481 int i, idx, ret = 0; 476 int i, idx, ret = 0;
482 int group_key = 0; 477 int group_key = 0;
483 const char *alg; 478 const char *alg;
484 struct ieee80211_crypto_ops *ops; 479 struct ieee80211_crypto_ops *ops;
485 struct ieee80211_crypt_data **crypt; 480 struct ieee80211_crypt_data **crypt;
486 481
487 struct ieee80211_security sec = { 482 struct ieee80211_security sec = {
488 .flags = 0, 483 .flags = 0,
489 }; 484 };
490 //printk("======>encoding flag:%x,ext flag:%x, ext alg:%d\n", encoding->flags,ext->ext_flags, ext->alg); 485 //printk("======>encoding flag:%x,ext flag:%x, ext alg:%d\n", encoding->flags,ext->ext_flags, ext->alg);
491 idx = encoding->flags & IW_ENCODE_INDEX; 486 idx = encoding->flags & IW_ENCODE_INDEX;
492 if (idx) { 487 if (idx) {
493 if (idx < 1 || idx > WEP_KEYS) 488 if (idx < 1 || idx > WEP_KEYS)
494 return -EINVAL; 489 return -EINVAL;
495 idx--; 490 idx--;
496 } else 491 } else
497 idx = ieee->tx_keyidx; 492 idx = ieee->tx_keyidx;
498 493
499 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { 494 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
500 crypt = &ieee->crypt[idx]; 495 crypt = &ieee->crypt[idx];
501 group_key = 1; 496 group_key = 1;
502 } else { 497 } else {
503 /* some Cisco APs use idx>0 for unicast in dynamic WEP */ 498 /* some Cisco APs use idx>0 for unicast in dynamic WEP */
504 //printk("not group key, flags:%x, ext->alg:%d\n", ext->ext_flags, ext->alg); 499 //printk("not group key, flags:%x, ext->alg:%d\n", ext->ext_flags, ext->alg);
505 if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP) 500 if (idx != 0 && ext->alg != IW_ENCODE_ALG_WEP)
506 return -EINVAL; 501 return -EINVAL;
507 if (ieee->iw_mode == IW_MODE_INFRA) 502 if (ieee->iw_mode == IW_MODE_INFRA)
508 crypt = &ieee->crypt[idx]; 503 crypt = &ieee->crypt[idx];
509 else 504 else
510 return -EINVAL; 505 return -EINVAL;
511 } 506 }
512 507
513 sec.flags |= SEC_ENABLED;// | SEC_ENCRYPT; 508 sec.flags |= SEC_ENABLED;// | SEC_ENCRYPT;
514 if ((encoding->flags & IW_ENCODE_DISABLED) || 509 if ((encoding->flags & IW_ENCODE_DISABLED) ||
515 ext->alg == IW_ENCODE_ALG_NONE) { 510 ext->alg == IW_ENCODE_ALG_NONE) {
516 if (*crypt) 511 if (*crypt)
517 ieee80211_crypt_delayed_deinit(ieee, crypt); 512 ieee80211_crypt_delayed_deinit(ieee, crypt);
518 513
519 for (i = 0; i < WEP_KEYS; i++) 514 for (i = 0; i < WEP_KEYS; i++)
520 if (ieee->crypt[i] != NULL) 515 if (ieee->crypt[i] != NULL)
521 break; 516 break;
522 517
523 if (i == WEP_KEYS) { 518 if (i == WEP_KEYS) {
524 sec.enabled = 0; 519 sec.enabled = 0;
525 // sec.encrypt = 0; 520 // sec.encrypt = 0;
526 sec.level = SEC_LEVEL_0; 521 sec.level = SEC_LEVEL_0;
527 sec.flags |= SEC_LEVEL; 522 sec.flags |= SEC_LEVEL;
528 } 523 }
529 //printk("disabled: flag:%x\n", encoding->flags); 524 //printk("disabled: flag:%x\n", encoding->flags);
530 goto done; 525 goto done;
531 } 526 }
532 527
533 sec.enabled = 1; 528 sec.enabled = 1;
534 // sec.encrypt = 1; 529 // sec.encrypt = 1;
535 530
536 switch (ext->alg) { 531 switch (ext->alg) {
537 case IW_ENCODE_ALG_WEP: 532 case IW_ENCODE_ALG_WEP:
538 alg = "WEP"; 533 alg = "WEP";
539 break; 534 break;
540 case IW_ENCODE_ALG_TKIP: 535 case IW_ENCODE_ALG_TKIP:
541 alg = "TKIP"; 536 alg = "TKIP";
542 break; 537 break;
543 case IW_ENCODE_ALG_CCMP: 538 case IW_ENCODE_ALG_CCMP:
544 alg = "CCMP"; 539 alg = "CCMP";
545 break; 540 break;
546 default: 541 default:
547 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", 542 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
548 dev->name, ext->alg); 543 dev->name, ext->alg);
549 ret = -EINVAL; 544 ret = -EINVAL;
550 goto done; 545 goto done;
551 } 546 }
552// printk("8-09-08-9=====>%s, alg name:%s\n",__func__, alg); 547// printk("8-09-08-9=====>%s, alg name:%s\n",__func__, alg);
553 548
554 ops = ieee80211_get_crypto_ops(alg); 549 ops = ieee80211_get_crypto_ops(alg);
555 if (ops == NULL) 550 if (ops == NULL)
556 ops = ieee80211_get_crypto_ops(alg); 551 ops = ieee80211_get_crypto_ops(alg);
557 if (ops == NULL) { 552 if (ops == NULL) {
558 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n", 553 IEEE80211_DEBUG_WX("%s: unknown crypto alg %d\n",
559 dev->name, ext->alg); 554 dev->name, ext->alg);
560 printk("========>unknown crypto alg %d\n", ext->alg); 555 printk("========>unknown crypto alg %d\n", ext->alg);
561 ret = -EINVAL; 556 ret = -EINVAL;
562 goto done; 557 goto done;
563 } 558 }
564 559
565 if (*crypt == NULL || (*crypt)->ops != ops) { 560 if (*crypt == NULL || (*crypt)->ops != ops) {
566 struct ieee80211_crypt_data *new_crypt; 561 struct ieee80211_crypt_data *new_crypt;
567 562
568 ieee80211_crypt_delayed_deinit(ieee, crypt); 563 ieee80211_crypt_delayed_deinit(ieee, crypt);
569 564
570 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL); 565 new_crypt = kzalloc(sizeof(*new_crypt), GFP_KERNEL);
571 if (new_crypt == NULL) { 566 if (new_crypt == NULL) {
572 ret = -ENOMEM; 567 ret = -ENOMEM;
573 goto done; 568 goto done;
574 } 569 }
575 new_crypt->ops = ops; 570 new_crypt->ops = ops;
576 if (new_crypt->ops) 571 if (new_crypt->ops)
577 new_crypt->priv = new_crypt->ops->init(idx); 572 new_crypt->priv = new_crypt->ops->init(idx);
578 if (new_crypt->priv == NULL) { 573 if (new_crypt->priv == NULL) {
579 kfree(new_crypt); 574 kfree(new_crypt);
580 ret = -EINVAL; 575 ret = -EINVAL;
581 goto done; 576 goto done;
582 } 577 }
583 *crypt = new_crypt; 578 *crypt = new_crypt;
584 579
585 } 580 }
586 581
587 if (ext->key_len > 0 && (*crypt)->ops->set_key && 582 if (ext->key_len > 0 && (*crypt)->ops->set_key &&
588 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq, 583 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
589 (*crypt)->priv) < 0) { 584 (*crypt)->priv) < 0) {
590 IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name); 585 IEEE80211_DEBUG_WX("%s: key setting failed\n", dev->name);
591 printk("key setting failed\n"); 586 printk("key setting failed\n");
592 ret = -EINVAL; 587 ret = -EINVAL;
593 goto done; 588 goto done;
594 } 589 }
595#if 1 590#if 1
596 //skip_host_crypt: 591 //skip_host_crypt:
597 //printk("skip_host_crypt:ext_flags:%x\n", ext->ext_flags); 592 //printk("skip_host_crypt:ext_flags:%x\n", ext->ext_flags);
598 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { 593 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
599 ieee->tx_keyidx = idx; 594 ieee->tx_keyidx = idx;
600 sec.active_key = idx; 595 sec.active_key = idx;
601 sec.flags |= SEC_ACTIVE_KEY; 596 sec.flags |= SEC_ACTIVE_KEY;
602 } 597 }
603 598
604 if (ext->alg != IW_ENCODE_ALG_NONE) { 599 if (ext->alg != IW_ENCODE_ALG_NONE) {
605 memcpy(sec.keys[idx], ext->key, ext->key_len); 600 memcpy(sec.keys[idx], ext->key, ext->key_len);
606 sec.key_sizes[idx] = ext->key_len; 601 sec.key_sizes[idx] = ext->key_len;
607 sec.flags |= (1 << idx); 602 sec.flags |= (1 << idx);
608 if (ext->alg == IW_ENCODE_ALG_WEP) { 603 if (ext->alg == IW_ENCODE_ALG_WEP) {
609 // sec.encode_alg[idx] = SEC_ALG_WEP; 604 // sec.encode_alg[idx] = SEC_ALG_WEP;
610 sec.flags |= SEC_LEVEL; 605 sec.flags |= SEC_LEVEL;
611 sec.level = SEC_LEVEL_1; 606 sec.level = SEC_LEVEL_1;
612 } else if (ext->alg == IW_ENCODE_ALG_TKIP) { 607 } else if (ext->alg == IW_ENCODE_ALG_TKIP) {
613 // sec.encode_alg[idx] = SEC_ALG_TKIP; 608 // sec.encode_alg[idx] = SEC_ALG_TKIP;
614 sec.flags |= SEC_LEVEL; 609 sec.flags |= SEC_LEVEL;
615 sec.level = SEC_LEVEL_2; 610 sec.level = SEC_LEVEL_2;
616 } else if (ext->alg == IW_ENCODE_ALG_CCMP) { 611 } else if (ext->alg == IW_ENCODE_ALG_CCMP) {
617 // sec.encode_alg[idx] = SEC_ALG_CCMP; 612 // sec.encode_alg[idx] = SEC_ALG_CCMP;
618 sec.flags |= SEC_LEVEL; 613 sec.flags |= SEC_LEVEL;
619 sec.level = SEC_LEVEL_3; 614 sec.level = SEC_LEVEL_3;
620 } 615 }
621 /* Don't set sec level for group keys. */ 616 /* Don't set sec level for group keys. */
622 if (group_key) 617 if (group_key)
623 sec.flags &= ~SEC_LEVEL; 618 sec.flags &= ~SEC_LEVEL;
624 } 619 }
625#endif 620#endif
626done: 621done:
627 if (ieee->set_security) 622 if (ieee->set_security)
628 ieee->set_security(ieee->dev, &sec); 623 ieee->set_security(ieee->dev, &sec);
629 624
630 if (ieee->reset_on_keychange && 625 if (ieee->reset_on_keychange &&
631 ieee->iw_mode != IW_MODE_INFRA && 626 ieee->iw_mode != IW_MODE_INFRA &&
632 ieee->reset_port && ieee->reset_port(dev)) { 627 ieee->reset_port && ieee->reset_port(dev)) {
633 IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name); 628 IEEE80211_DEBUG_WX("%s: reset_port failed\n", dev->name);
634 return -EINVAL; 629 return -EINVAL;
635 } 630 }
636 631
637 return ret; 632 return ret;
638} 633}
639int ieee80211_wx_set_mlme(struct ieee80211_device *ieee, 634int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
640 struct iw_request_info *info, 635 struct iw_request_info *info,
641 union iwreq_data *wrqu, char *extra) 636 union iwreq_data *wrqu, char *extra)
642{ 637{
643 struct iw_mlme *mlme = (struct iw_mlme *) extra; 638 struct iw_mlme *mlme = (struct iw_mlme *) extra;
644// printk("\ndkgadfslkdjgalskdf===============>%s(), cmd:%x\n", __func__, mlme->cmd); 639// printk("\ndkgadfslkdjgalskdf===============>%s(), cmd:%x\n", __func__, mlme->cmd);
645#if 1 640#if 1
646 switch (mlme->cmd) { 641 switch (mlme->cmd) {
647 case IW_MLME_DEAUTH: 642 case IW_MLME_DEAUTH:
648 case IW_MLME_DISASSOC: 643 case IW_MLME_DISASSOC:
649 // printk("disassoc now\n"); 644 // printk("disassoc now\n");
650 ieee80211_disassociate(ieee); 645 ieee80211_disassociate(ieee);
651 break; 646 break;
652 default: 647 default:
653 return -EOPNOTSUPP; 648 return -EOPNOTSUPP;
654 } 649 }
655#endif 650#endif
656 return 0; 651 return 0;
657} 652}
658 653
659int ieee80211_wx_set_auth(struct ieee80211_device *ieee, 654int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
660 struct iw_request_info *info, 655 struct iw_request_info *info,
661 struct iw_param *data, char *extra) 656 struct iw_param *data, char *extra)
662{ 657{
663/* 658/*
664 struct ieee80211_security sec = { 659 struct ieee80211_security sec = {
665 .flags = SEC_AUTH_MODE, 660 .flags = SEC_AUTH_MODE,
666 } 661 }
667*/ 662*/
668 //printk("set auth:flag:%x, data value:%x\n", data->flags, data->value); 663 //printk("set auth:flag:%x, data value:%x\n", data->flags, data->value);
669 switch (data->flags & IW_AUTH_INDEX) { 664 switch (data->flags & IW_AUTH_INDEX) {
670 case IW_AUTH_WPA_VERSION: 665 case IW_AUTH_WPA_VERSION:
671 /*need to support wpa2 here*/ 666 /*need to support wpa2 here*/
672 //printk("wpa version:%x\n", data->value); 667 //printk("wpa version:%x\n", data->value);
673 break; 668 break;
674 case IW_AUTH_CIPHER_PAIRWISE: 669 case IW_AUTH_CIPHER_PAIRWISE:
675 case IW_AUTH_CIPHER_GROUP: 670 case IW_AUTH_CIPHER_GROUP:
676 case IW_AUTH_KEY_MGMT: 671 case IW_AUTH_KEY_MGMT:
677 /* 672 /*
678 * * Host AP driver does not use these parameters and allows 673 * * Host AP driver does not use these parameters and allows
679 * * wpa_supplicant to control them internally. 674 * * wpa_supplicant to control them internally.
680 * */ 675 * */
681 break; 676 break;
682 case IW_AUTH_TKIP_COUNTERMEASURES: 677 case IW_AUTH_TKIP_COUNTERMEASURES:
683 ieee->tkip_countermeasures = data->value; 678 ieee->tkip_countermeasures = data->value;
684 break; 679 break;
685 case IW_AUTH_DROP_UNENCRYPTED: 680 case IW_AUTH_DROP_UNENCRYPTED:
686 ieee->drop_unencrypted = data->value; 681 ieee->drop_unencrypted = data->value;
687 break; 682 break;
688 683
689 case IW_AUTH_80211_AUTH_ALG: 684 case IW_AUTH_80211_AUTH_ALG:
690 ieee->open_wep = (data->value&IW_AUTH_ALG_OPEN_SYSTEM)?1:0; 685 ieee->open_wep = (data->value&IW_AUTH_ALG_OPEN_SYSTEM) ? 1 : 0;
691 //printk("open_wep:%d\n", ieee->open_wep); 686 //printk("open_wep:%d\n", ieee->open_wep);
692 break; 687 break;
693 688
694#if 1 689#if 1
695 case IW_AUTH_WPA_ENABLED: 690 case IW_AUTH_WPA_ENABLED:
696 ieee->wpa_enabled = (data->value)?1:0; 691 ieee->wpa_enabled = (data->value) ? 1 : 0;
697 //printk("enable wpa:%d\n", ieee->wpa_enabled); 692 //printk("enable wpa:%d\n", ieee->wpa_enabled);
698 break; 693 break;
699 694
700#endif 695#endif
701 case IW_AUTH_RX_UNENCRYPTED_EAPOL: 696 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
702 ieee->ieee802_1x = data->value; 697 ieee->ieee802_1x = data->value;
703 break; 698 break;
704 case IW_AUTH_PRIVACY_INVOKED: 699 case IW_AUTH_PRIVACY_INVOKED:
705 ieee->privacy_invoked = data->value; 700 ieee->privacy_invoked = data->value;
706 break; 701 break;
707 default: 702 default:
708 return -EOPNOTSUPP; 703 return -EOPNOTSUPP;
709 } 704 }
710 return 0; 705 return 0;
711} 706}
@@ -715,15 +710,13 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
715{ 710{
716 u8 *buf = NULL; 711 u8 *buf = NULL;
717 712
718 if (len>MAX_WPA_IE_LEN || (len && ie == NULL)) 713 if (len > MAX_WPA_IE_LEN || (len && ie == NULL)) {
719 {
720 printk("return error out, len:%zu\n", len); 714 printk("return error out, len:%zu\n", len);
721 return -EINVAL; 715 return -EINVAL;
722 } 716 }
723 717
724 if (len) 718 if (len) {
725 { 719 if (len != ie[1]+2) {
726 if (len != ie[1]+2){
727 printk("len:%zu, ie:%d\n", len, ie[1]); 720 printk("len:%zu, ie:%d\n", len, ie[1]);
728 return -EINVAL; 721 return -EINVAL;
729 } 722 }
@@ -733,8 +726,7 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
733 kfree(ieee->wpa_ie); 726 kfree(ieee->wpa_ie);
734 ieee->wpa_ie = buf; 727 ieee->wpa_ie = buf;
735 ieee->wpa_ie_len = len; 728 ieee->wpa_ie_len = len;
736 } 729 } else {
737 else{
738 kfree(ieee->wpa_ie); 730 kfree(ieee->wpa_ie);
739 ieee->wpa_ie = NULL; 731 ieee->wpa_ie = NULL;
740 ieee->wpa_ie_len = 0; 732 ieee->wpa_ie_len = 0;
diff --git a/drivers/staging/rtl8187se/r8185b_init.c b/drivers/staging/rtl8187se/r8185b_init.c
index f1db9e401c87..978dc5f4f929 100644
--- a/drivers/staging/rtl8187se/r8185b_init.c
+++ b/drivers/staging/rtl8187se/r8185b_init.c
@@ -115,21 +115,24 @@ static u8 OFDM_CONFIG[] = {
115 *--------------------------------------------------------------- 115 *---------------------------------------------------------------
116 */ 116 */
117 117
118void PlatformIOWrite1Byte(struct net_device *dev, u32 offset, u8 data) 118static u8 PlatformIORead1Byte(struct net_device *dev, u32 offset)
119{
120 return read_nic_byte(dev, offset);
121}
122
123static void PlatformIOWrite1Byte(struct net_device *dev, u32 offset, u8 data)
119{ 124{
120 write_nic_byte(dev, offset, data); 125 write_nic_byte(dev, offset, data);
121 read_nic_byte(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ 126 read_nic_byte(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
122} 127}
123 128
124void PlatformIOWrite2Byte(struct net_device *dev, u32 offset, u16 data) 129static void PlatformIOWrite2Byte(struct net_device *dev, u32 offset, u16 data)
125{ 130{
126 write_nic_word(dev, offset, data); 131 write_nic_word(dev, offset, data);
127 read_nic_word(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */ 132 read_nic_word(dev, offset); /* To make sure write operation is completed, 2005.11.09, by rcnjko. */
128} 133}
129 134
130u8 PlatformIORead1Byte(struct net_device *dev, u32 offset); 135static void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data)
131
132void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data)
133{ 136{
134 if (offset == PhyAddr) { 137 if (offset == PhyAddr) {
135 /* For Base Band configuration. */ 138 /* For Base Band configuration. */
@@ -172,37 +175,7 @@ void PlatformIOWrite4Byte(struct net_device *dev, u32 offset, u32 data)
172 } 175 }
173} 176}
174 177
175u8 PlatformIORead1Byte(struct net_device *dev, u32 offset) 178static void SetOutputEnableOfRfPins(struct net_device *dev)
176{
177 u8 data = 0;
178
179 data = read_nic_byte(dev, offset);
180
181
182 return data;
183}
184
185u16 PlatformIORead2Byte(struct net_device *dev, u32 offset)
186{
187 u16 data = 0;
188
189 data = read_nic_word(dev, offset);
190
191
192 return data;
193}
194
195u32 PlatformIORead4Byte(struct net_device *dev, u32 offset)
196{
197 u32 data = 0;
198
199 data = read_nic_dword(dev, offset);
200
201
202 return data;
203}
204
205void SetOutputEnableOfRfPins(struct net_device *dev)
206{ 179{
207 write_nic_word(dev, RFPinsEnable, 0x1bff); 180 write_nic_word(dev, RFPinsEnable, 0x1bff);
208} 181}
@@ -287,35 +260,19 @@ u16 RF_ReadReg(struct net_device *dev, u8 offset)
287 return reg; 260 return reg;
288} 261}
289 262
263static u8 ReadBBPortUchar(struct net_device *dev, u32 addr)
264{
265 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
266 return PlatformIORead1Byte(dev, PhyDataR);
267}
290 268
291/* by Owen on 04/07/14 for writing BB register successfully */ 269/* by Owen on 04/07/14 for writing BB register successfully */
292void WriteBBPortUchar(struct net_device *dev, u32 Data) 270static void WriteBBPortUchar(struct net_device *dev, u32 Data)
293{ 271{
294 /* u8 TimeoutCounter; */
295 u8 RegisterContent;
296 u8 UCharData;
297
298 UCharData = (u8)((Data & 0x0000ff00) >> 8);
299 PlatformIOWrite4Byte(dev, PhyAddr, Data); 272 PlatformIOWrite4Byte(dev, PhyAddr, Data);
300 /* for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--) */ 273 ReadBBPortUchar(dev, Data);
301 {
302 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
303 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
304 /*if(UCharData == RegisterContent) */
305 /* break; */
306 }
307} 274}
308 275
309u8 ReadBBPortUchar(struct net_device *dev, u32 addr)
310{
311 /*u8 TimeoutCounter; */
312 u8 RegisterContent;
313
314 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
315 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
316
317 return RegisterContent;
318}
319/* 276/*
320 * Description: 277 * Description:
321 * Perform Antenna settings with antenna diversity on 87SE. 278 * Perform Antenna settings with antenna diversity on 87SE.
@@ -327,62 +284,38 @@ bool SetAntennaConfig87SE(struct net_device *dev,
327{ 284{
328 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 285 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
329 bool bAntennaSwitched = true; 286 bool bAntennaSwitched = true;
287 u8 ant_diversity_offset = 0x00; /* 0x00 = disabled, 0x80 = enabled */
330 288
331 /* printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity); */ 289 /* printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity); */
332 290
333 /* Threshold for antenna diversity. */ 291 /* Threshold for antenna diversity. */
334 write_phy_cck(dev, 0x0c, 0x09); /* Reg0c : 09 */ 292 write_phy_cck(dev, 0x0c, 0x09); /* Reg0c : 09 */
335 293
336 if (bAntDiversity) { /* Enable Antenna Diversity. */ 294 if (bAntDiversity) /* Enable Antenna Diversity. */
337 if (DefaultAnt == 1) { /* aux antenna */ 295 ant_diversity_offset = 0x80;
338 296
339 /* Mac register, aux antenna */ 297 if (DefaultAnt == 1) { /* aux Antenna */
340 write_nic_byte(dev, ANTSEL, 0x00); 298 /* Mac register, aux antenna */
341 299 write_nic_byte(dev, ANTSEL, 0x00);
342 /* Config CCK RX antenna. */ 300
343 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */ 301 /* Config CCK RX antenna. */
344 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */ 302 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */
345 303 write_phy_cck(dev, 0x01, 0x47|ant_diversity_offset); /* Reg01 : 47 | ant_diversity_offset */
346 /* Config OFDM RX antenna. */ 304
347 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */ 305 /* Config OFDM RX antenna. */
348 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */ 306 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */
349 } else { /* use main antenna */ 307 write_phy_ofdm(dev, 0x18, 0x32|ant_diversity_offset); /* Reg18 : 32 */
350 /* Mac register, main antenna */ 308 } else { /* main Antenna */
351 write_nic_byte(dev, ANTSEL, 0x03); 309 /* Mac register, main antenna */
352 /* base band */ 310 write_nic_byte(dev, ANTSEL, 0x03);
353 /* Config CCK RX antenna. */ 311
354 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */ 312 /* Config CCK RX antenna. */
355 write_phy_cck(dev, 0x01, 0xc7); /* Reg01 : c7 */ 313 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */
356 314 write_phy_cck(dev, 0x01, 0x47|ant_diversity_offset); /* Reg01 : 47 */
357 /* Config OFDM RX antenna. */ 315
358 write_phy_ofdm(dev, 0x0d, 0x5c); /* Reg0d : 5c */ 316 /* Config OFDM RX antenna. */
359 write_phy_ofdm(dev, 0x18, 0xb2); /* Reg18 : b2 */ 317 write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */
360 } 318 write_phy_ofdm(dev, 0x18, 0x32|ant_diversity_offset); /*Reg18 : 32 */
361 } else {
362 /* Disable Antenna Diversity. */
363 if (DefaultAnt == 1) { /* aux Antenna */
364 /* Mac register, aux antenna */
365 write_nic_byte(dev, ANTSEL, 0x00);
366
367 /* Config CCK RX antenna. */
368 write_phy_cck(dev, 0x11, 0xbb); /* Reg11 : bb */
369 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */
370
371 /* Config OFDM RX antenna. */
372 write_phy_ofdm(dev, 0x0D, 0x54); /* Reg0d : 54 */
373 write_phy_ofdm(dev, 0x18, 0x32); /* Reg18 : 32 */
374 } else { /* main Antenna */
375 /* Mac register, main antenna */
376 write_nic_byte(dev, ANTSEL, 0x03);
377
378 /* Config CCK RX antenna. */
379 write_phy_cck(dev, 0x11, 0x9b); /* Reg11 : 9b */
380 write_phy_cck(dev, 0x01, 0x47); /* Reg01 : 47 */
381
382 /* Config OFDM RX antenna. */
383 write_phy_ofdm(dev, 0x0D, 0x5c); /* Reg0d : 5c */
384 write_phy_ofdm(dev, 0x18, 0x32); /*Reg18 : 32 */
385 }
386 } 319 }
387 priv->CurrAntennaIndex = DefaultAnt; /* Update default settings. */ 320 priv->CurrAntennaIndex = DefaultAnt; /* Update default settings. */
388 return bAntennaSwitched; 321 return bAntennaSwitched;
@@ -394,7 +327,7 @@ bool SetAntennaConfig87SE(struct net_device *dev,
394 *-------------------------------------------------------------- 327 *--------------------------------------------------------------
395 */ 328 */
396 329
397void ZEBRA_Config_85BASIC_HardCode(struct net_device *dev) 330static void ZEBRA_Config_85BASIC_HardCode(struct net_device *dev)
398{ 331{
399 332
400 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 333 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
@@ -695,7 +628,7 @@ void UpdateInitialGain(struct net_device *dev)
695 * Tx Power tracking mechanism routine on 87SE. 628 * Tx Power tracking mechanism routine on 87SE.
696 * Created by Roger, 2007.12.11. 629 * Created by Roger, 2007.12.11.
697 */ 630 */
698void InitTxPwrTracking87SE(struct net_device *dev) 631static void InitTxPwrTracking87SE(struct net_device *dev)
699{ 632{
700 u32 u4bRfReg; 633 u32 u4bRfReg;
701 634
@@ -705,7 +638,7 @@ void InitTxPwrTracking87SE(struct net_device *dev)
705 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1); 638 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
706} 639}
707 640
708void PhyConfig8185(struct net_device *dev) 641static void PhyConfig8185(struct net_device *dev)
709{ 642{
710 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 643 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
711 write_nic_dword(dev, RCR, priv->ReceiveConfig); 644 write_nic_dword(dev, RCR, priv->ReceiveConfig);
@@ -732,7 +665,7 @@ void PhyConfig8185(struct net_device *dev)
732 return; 665 return;
733} 666}
734 667
735void HwConfigureRTL8185(struct net_device *dev) 668static void HwConfigureRTL8185(struct net_device *dev)
736{ 669{
737 /* RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control. */ 670 /* RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control. */
738 u8 bUNIVERSAL_CONTROL_RL = 0; 671 u8 bUNIVERSAL_CONTROL_RL = 0;
@@ -857,21 +790,16 @@ static void MacConfig_85BASIC(struct net_device *dev)
857 write_nic_byte(dev, 0x24E, 0x01); 790 write_nic_byte(dev, 0x24E, 0x01);
858} 791}
859 792
860u8 GetSupportedWirelessMode8185(struct net_device *dev) 793static u8 GetSupportedWirelessMode8185(struct net_device *dev)
861{ 794{
862 return WIRELESS_MODE_B | WIRELESS_MODE_G; 795 return WIRELESS_MODE_B | WIRELESS_MODE_G;
863} 796}
864 797
865void ActUpdateChannelAccessSetting(struct net_device *dev, 798static void ActUpdateChannelAccessSetting(struct net_device *dev,
866 WIRELESS_MODE WirelessMode, 799 WIRELESS_MODE WirelessMode,
867 PCHANNEL_ACCESS_SETTING ChnlAccessSetting) 800 PCHANNEL_ACCESS_SETTING ChnlAccessSetting)
868{ 801{
869 struct r8180_priv *priv = ieee80211_priv(dev);
870 struct ieee80211_device *ieee = priv->ieee80211;
871 AC_CODING eACI; 802 AC_CODING eACI;
872 AC_PARAM AcParam;
873 u8 bFollowLegacySetting = 0;
874 u8 u1bAIFS;
875 803
876 /* 804 /*
877 * <RJ_TODO_8185B> 805 * <RJ_TODO_8185B>
@@ -893,131 +821,16 @@ void ActUpdateChannelAccessSetting(struct net_device *dev,
893 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer); 821 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
894 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); /* Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29. */ 822 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); /* Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29. */
895 823
896 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer);
897
898 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer); 824 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
899 825
900 write_nic_byte(dev, AckTimeOutReg, 0x5B); /* <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */ 826 write_nic_byte(dev, AckTimeOutReg, 0x5B); /* <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08. */
901 827
902 { /* Legacy 802.11. */ 828 for (eACI = 0; eACI < AC_MAX; eACI++) {
903 bFollowLegacySetting = 1; 829 write_nic_byte(dev, ACM_CONTROL, 0);
904
905 }
906
907 /* this setting is copied from rtl8187B. xiong-2006-11-13 */
908 if (bFollowLegacySetting) {
909
910 /*
911 * Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
912 * 2005.12.01, by rcnjko.
913 */
914 AcParam.longData = 0;
915 AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */
916 AcParam.f.AciAifsn.f.ACM = 0;
917 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; /* Follow 802.11 CWmin. */
918 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; /* Follow 802.11 CWmax. */
919 AcParam.f.TXOPLimit = 0;
920
921 /* lzm reserved 080826 */
922 /* For turbo mode setting. port from 87B by Isaiah 2008-08-01 */
923 if (ieee->current_network.Turbo_Enable == 1)
924 AcParam.f.TXOPLimit = 0x01FF;
925 /* For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB) */
926 if (ieee->iw_mode == IW_MODE_ADHOC)
927 AcParam.f.TXOPLimit = 0x0020;
928
929 for (eACI = 0; eACI < AC_MAX; eACI++) {
930 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
931 {
932 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
933 AC_CODING eACI;
934 u8 u1bAIFS;
935 u32 u4bAcParam;
936
937 /* Retrieve parameters to update. */
938 eACI = pAcParam->f.AciAifsn.f.ACI;
939 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
940 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
941 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
942 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
943 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
944
945 switch (eACI) {
946 case AC1_BK:
947 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
948 break;
949
950 case AC0_BE:
951 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
952 break;
953
954 case AC2_VI:
955 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
956 break;
957
958 case AC3_VO:
959 /* write_nic_dword(dev, AC_BK_PARAM, u4bAcParam); */
960 break;
961
962 default:
963 DMESGW("SetHwReg8185(): invalid ACI: %d !\n", eACI);
964 break;
965 }
966
967 /* Cehck ACM bit. */
968 /* If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13. */
969 {
970 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
971 AC_CODING eACI = pAciAifsn->f.ACI;
972
973 /*for 8187B AsynIORead issue */
974 u8 AcmCtrl = 0;
975 if (pAciAifsn->f.ACM) {
976 /* ACM bit is 1. */
977 switch (eACI) {
978 case AC0_BE:
979 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); /* or 0x21 */
980 break;
981
982 case AC2_VI:
983 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); /* or 0x42 */
984 break;
985
986 case AC3_VO:
987 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); /* or 0x84 */
988 break;
989
990 default:
991 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI);
992 break;
993 }
994 } else {
995 /* ACM bit is 0. */
996 switch (eACI) {
997 case AC0_BE:
998 AcmCtrl &= ((~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xDE */
999 break;
1000
1001 case AC2_VI:
1002 AcmCtrl &= ((~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0xBD */
1003 break;
1004
1005 case AC3_VO:
1006 AcmCtrl &= ((~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN)); /* and 0x7B */
1007 break;
1008
1009 default:
1010 break;
1011 }
1012 }
1013 write_nic_byte(dev, ACM_CONTROL, 0);
1014 }
1015 }
1016 }
1017 } 830 }
1018} 831}
1019 832
1020void ActSetWirelessMode8185(struct net_device *dev, u8 btWirelessMode) 833static void ActSetWirelessMode8185(struct net_device *dev, u8 btWirelessMode)
1021{ 834{
1022 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 835 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1023 struct ieee80211_device *ieee = priv->ieee80211; 836 struct ieee80211_device *ieee = priv->ieee80211;
@@ -1074,7 +887,7 @@ void rtl8185b_irq_enable(struct net_device *dev)
1074 write_nic_dword(dev, IMR, priv->IntrMask); 887 write_nic_dword(dev, IMR, priv->IntrMask);
1075} 888}
1076 889
1077void MgntDisconnectIBSS(struct net_device *dev) 890static void MgntDisconnectIBSS(struct net_device *dev)
1078{ 891{
1079 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 892 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1080 u8 i; 893 u8 i;
@@ -1100,7 +913,7 @@ void MgntDisconnectIBSS(struct net_device *dev)
1100 notify_wx_assoc_event(priv->ieee80211); 913 notify_wx_assoc_event(priv->ieee80211);
1101} 914}
1102 915
1103void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn) 916static void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn)
1104{ 917{
1105 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 918 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1106 u8 i; 919 u8 i;
@@ -1117,7 +930,7 @@ void MlmeDisassociateRequest(struct net_device *dev, u8 *asSta, u8 asRsn)
1117 } 930 }
1118} 931}
1119 932
1120void MgntDisconnectAP(struct net_device *dev, u8 asRsn) 933static void MgntDisconnectAP(struct net_device *dev, u8 asRsn)
1121{ 934{
1122 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 935 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1123 936
@@ -1135,7 +948,7 @@ void MgntDisconnectAP(struct net_device *dev, u8 asRsn)
1135 priv->ieee80211->state = IEEE80211_NOLINK; 948 priv->ieee80211->state = IEEE80211_NOLINK;
1136} 949}
1137 950
1138bool MgntDisconnect(struct net_device *dev, u8 asRsn) 951static bool MgntDisconnect(struct net_device *dev, u8 asRsn)
1139{ 952{
1140 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 953 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1141 /* 954 /*
@@ -1171,7 +984,7 @@ bool MgntDisconnect(struct net_device *dev, u8 asRsn)
1171 * Assumption: 984 * Assumption:
1172 * PASSIVE LEVEL. 985 * PASSIVE LEVEL.
1173 */ 986 */
1174bool SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerState) 987static bool SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerState)
1175{ 988{
1176 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 989 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1177 bool bResult = false; 990 bool bResult = false;
@@ -1275,7 +1088,7 @@ bool MgntActSet_RF_State(struct net_device *dev, RT_RF_POWER_STATE StateToSet, u
1275 return bActionAllowed; 1088 return bActionAllowed;
1276} 1089}
1277 1090
1278void InactivePowerSave(struct net_device *dev) 1091static void InactivePowerSave(struct net_device *dev)
1279{ 1092{
1280 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev); 1093 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1281 /* 1094 /*
diff --git a/drivers/staging/rtl8192u/changes b/drivers/staging/rtl8192u/changes
index 87c33fdb9526..0485d6eec7b5 100644
--- a/drivers/staging/rtl8192u/changes
+++ b/drivers/staging/rtl8192u/changes
@@ -2,4 +2,3 @@ v 0.1
2 2
3First version. 3First version.
4This is based on the rtl8180-sa2400 pre-0.22-CVS code.. 4This is based on the rtl8180-sa2400 pre-0.22-CVS code..
5
diff --git a/drivers/staging/rtl8192u/ieee80211/Makefile b/drivers/staging/rtl8192u/ieee80211/Makefile
index 51effd6412ac..b5d0c2eb045b 100644
--- a/drivers/staging/rtl8192u/ieee80211/Makefile
+++ b/drivers/staging/rtl8192u/ieee80211/Makefile
@@ -25,4 +25,3 @@ obj-m +=ieee80211_crypt-rsl.o
25obj-m +=ieee80211_crypt_wep-rsl.o 25obj-m +=ieee80211_crypt_wep-rsl.o
26obj-m +=ieee80211_crypt_tkip-rsl.o 26obj-m +=ieee80211_crypt_tkip-rsl.o
27obj-m +=ieee80211_crypt_ccmp-rsl.o 27obj-m +=ieee80211_crypt_ccmp-rsl.o
28
diff --git a/drivers/staging/rtl8192u/ieee80211/aes.c b/drivers/staging/rtl8192u/ieee80211/aes.c
index a6bb6c9207d3..abc1023cef65 100644
--- a/drivers/staging/rtl8192u/ieee80211/aes.c
+++ b/drivers/staging/rtl8192u/ieee80211/aes.c
@@ -443,7 +443,7 @@ static struct crypto_alg aes_alg = {
443 .cipher = { 443 .cipher = {
444 .cia_min_keysize = AES_MIN_KEY_SIZE, 444 .cia_min_keysize = AES_MIN_KEY_SIZE,
445 .cia_max_keysize = AES_MAX_KEY_SIZE, 445 .cia_max_keysize = AES_MAX_KEY_SIZE,
446 .cia_setkey = aes_set_key, 446 .cia_setkey = aes_set_key,
447 .cia_encrypt = aes_encrypt, 447 .cia_encrypt = aes_encrypt,
448 .cia_decrypt = aes_decrypt 448 .cia_decrypt = aes_decrypt
449 } 449 }
@@ -466,4 +466,3 @@ module_exit(aes_fini);
466 466
467MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm"); 467MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm");
468MODULE_LICENSE("Dual BSD/GPL"); 468MODULE_LICENSE("Dual BSD/GPL");
469
diff --git a/drivers/staging/rtl8192u/ieee80211/arc4.c b/drivers/staging/rtl8192u/ieee80211/arc4.c
index e3ad8d2f415e..b790e9ad104c 100644
--- a/drivers/staging/rtl8192u/ieee80211/arc4.c
+++ b/drivers/staging/rtl8192u/ieee80211/arc4.c
@@ -79,7 +79,7 @@ static struct crypto_alg arc4_alg = {
79 .cra_u = { .cipher = { 79 .cra_u = { .cipher = {
80 .cia_min_keysize = ARC4_MIN_KEY_SIZE, 80 .cia_min_keysize = ARC4_MIN_KEY_SIZE,
81 .cia_max_keysize = ARC4_MAX_KEY_SIZE, 81 .cia_max_keysize = ARC4_MAX_KEY_SIZE,
82 .cia_setkey = arc4_set_key, 82 .cia_setkey = arc4_set_key,
83 .cia_encrypt = arc4_crypt, 83 .cia_encrypt = arc4_crypt,
84 .cia_decrypt = arc4_crypt } } 84 .cia_decrypt = arc4_crypt } }
85}; 85};
diff --git a/drivers/staging/rtl8192u/ieee80211/crypto_compat.h b/drivers/staging/rtl8192u/ieee80211/crypto_compat.h
index da486588f1c0..2ba374a64178 100644
--- a/drivers/staging/rtl8192u/ieee80211/crypto_compat.h
+++ b/drivers/staging/rtl8192u/ieee80211/crypto_compat.h
@@ -56,5 +56,3 @@ static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm,
56} 56}
57//EXPORT_SYMBOL_GPL(crypto_alloc_tfm); 57//EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
58//EXPORT_SYMBOL_GPL(crypto_free_tfm); 58//EXPORT_SYMBOL_GPL(crypto_free_tfm);
59
60
diff --git a/drivers/staging/rtl8192u/ieee80211/dot11d.c b/drivers/staging/rtl8192u/ieee80211/dot11d.c
index ce63fc341c6e..f10fd5a93c38 100644
--- a/drivers/staging/rtl8192u/ieee80211/dot11d.c
+++ b/drivers/staging/rtl8192u/ieee80211/dot11d.c
@@ -218,4 +218,3 @@ EXPORT_SYMBOL(DOT11D_GetMaxTxPwrInDbm);
218EXPORT_SYMBOL(DOT11D_ScanComplete); 218EXPORT_SYMBOL(DOT11D_ScanComplete);
219EXPORT_SYMBOL(IsLegalChannel); 219EXPORT_SYMBOL(IsLegalChannel);
220EXPORT_SYMBOL(ToLegalChannel); 220EXPORT_SYMBOL(ToLegalChannel);
221
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index 502bfdbcc84b..210898c8e66c 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -64,7 +64,7 @@
64#endif 64#endif
65 65
66#define KEY_TYPE_NA 0x0 66#define KEY_TYPE_NA 0x0
67#define KEY_TYPE_WEP40 0x1 67#define KEY_TYPE_WEP40 0x1
68#define KEY_TYPE_TKIP 0x2 68#define KEY_TYPE_TKIP 0x2
69#define KEY_TYPE_CCMP 0x4 69#define KEY_TYPE_CCMP 0x4
70#define KEY_TYPE_WEP104 0x5 70#define KEY_TYPE_WEP104 0x5
@@ -195,21 +195,21 @@ enum _ReasonCode{
195 auth_not_valid = 0x2, 195 auth_not_valid = 0x2,
196 deauth_lv_ss = 0x3, 196 deauth_lv_ss = 0x3,
197 inactivity = 0x4, 197 inactivity = 0x4,
198 ap_overload = 0x5, 198 ap_overload = 0x5,
199 class2_err = 0x6, 199 class2_err = 0x6,
200 class3_err = 0x7, 200 class3_err = 0x7,
201 disas_lv_ss = 0x8, 201 disas_lv_ss = 0x8,
202 asoc_not_auth = 0x9, 202 asoc_not_auth = 0x9,
203 203
204 //----MIC_CHECK 204 //----MIC_CHECK
205 mic_failure = 0xe, 205 mic_failure = 0xe,
206 //----END MIC_CHECK 206 //----END MIC_CHECK
207 207
208 // Reason code defined in 802.11i D10.0 p.28. 208 // Reason code defined in 802.11i D10.0 p.28.
209 invalid_IE = 0x0d, 209 invalid_IE = 0x0d,
210 four_way_tmout = 0x0f, 210 four_way_tmout = 0x0f,
211 two_way_tmout = 0x10, 211 two_way_tmout = 0x10,
212 IE_dismatch = 0x11, 212 IE_dismatch = 0x11,
213 invalid_Gcipher = 0x12, 213 invalid_Gcipher = 0x12,
214 invalid_Pcipher = 0x13, 214 invalid_Pcipher = 0x13,
215 invalid_AKMP = 0x14, 215 invalid_AKMP = 0x14,
@@ -222,7 +222,7 @@ enum _ReasonCode{
222 QoS_unspec = 0x20, // 32 222 QoS_unspec = 0x20, // 32
223 QAP_bandwidth = 0x21, // 33 223 QAP_bandwidth = 0x21, // 33
224 poor_condition = 0x22, // 34 224 poor_condition = 0x22, // 34
225 no_facility = 0x23, // 35 225 no_facility = 0x23, // 35
226 // Where is 36??? 226 // Where is 36???
227 req_declined = 0x25, // 37 227 req_declined = 0x25, // 37
228 invalid_param = 0x26, // 38 228 invalid_param = 0x26, // 38
@@ -265,7 +265,7 @@ enum _ReasonCode{
265#define IEEE_WPAX_USEGROUP 0 265#define IEEE_WPAX_USEGROUP 0
266#define IEEE_WPAX_WEP40 1 266#define IEEE_WPAX_WEP40 1
267#define IEEE_WPAX_TKIP 2 267#define IEEE_WPAX_TKIP 2
268#define IEEE_WPAX_WRAP 3 268#define IEEE_WPAX_WRAP 3
269#define IEEE_WPAX_CCMP 4 269#define IEEE_WPAX_CCMP 4
270#define IEEE_WPAX_WEP104 5 270#define IEEE_WPAX_WEP104 5
271 271
@@ -289,12 +289,12 @@ enum _ReasonCode{
289#define MAX_IE_LEN 0xff 289#define MAX_IE_LEN 0xff
290 290
291// added for kernel conflict 291// added for kernel conflict
292#define ieee80211_crypt_deinit_entries ieee80211_crypt_deinit_entries_rsl 292#define ieee80211_crypt_deinit_entries ieee80211_crypt_deinit_entries_rsl
293#define ieee80211_crypt_deinit_handler ieee80211_crypt_deinit_handler_rsl 293#define ieee80211_crypt_deinit_handler ieee80211_crypt_deinit_handler_rsl
294#define ieee80211_crypt_delayed_deinit ieee80211_crypt_delayed_deinit_rsl 294#define ieee80211_crypt_delayed_deinit ieee80211_crypt_delayed_deinit_rsl
295#define ieee80211_register_crypto_ops ieee80211_register_crypto_ops_rsl 295#define ieee80211_register_crypto_ops ieee80211_register_crypto_ops_rsl
296#define ieee80211_unregister_crypto_ops ieee80211_unregister_crypto_ops_rsl 296#define ieee80211_unregister_crypto_ops ieee80211_unregister_crypto_ops_rsl
297#define ieee80211_get_crypto_ops ieee80211_get_crypto_ops_rsl 297#define ieee80211_get_crypto_ops ieee80211_get_crypto_ops_rsl
298 298
299#define ieee80211_ccmp_null ieee80211_ccmp_null_rsl 299#define ieee80211_ccmp_null ieee80211_ccmp_null_rsl
300 300
@@ -302,10 +302,10 @@ enum _ReasonCode{
302 302
303#define ieee80211_wep_null ieee80211_wep_null_rsl 303#define ieee80211_wep_null ieee80211_wep_null_rsl
304 304
305#define free_ieee80211 free_ieee80211_rsl 305#define free_ieee80211 free_ieee80211_rsl
306#define alloc_ieee80211 alloc_ieee80211_rsl 306#define alloc_ieee80211 alloc_ieee80211_rsl
307 307
308#define ieee80211_rx ieee80211_rx_rsl 308#define ieee80211_rx ieee80211_rx_rsl
309#define ieee80211_rx_mgt ieee80211_rx_mgt_rsl 309#define ieee80211_rx_mgt ieee80211_rx_mgt_rsl
310 310
311#define ieee80211_get_beacon ieee80211_get_beacon_rsl 311#define ieee80211_get_beacon ieee80211_get_beacon_rsl
@@ -450,7 +450,7 @@ typedef struct ieee_param {
450 450
451/* management */ 451/* management */
452#define IEEE80211_STYPE_ASSOC_REQ 0x0000 452#define IEEE80211_STYPE_ASSOC_REQ 0x0000
453#define IEEE80211_STYPE_ASSOC_RESP 0x0010 453#define IEEE80211_STYPE_ASSOC_RESP 0x0010
454#define IEEE80211_STYPE_REASSOC_REQ 0x0020 454#define IEEE80211_STYPE_REASSOC_REQ 0x0020
455#define IEEE80211_STYPE_REASSOC_RESP 0x0030 455#define IEEE80211_STYPE_REASSOC_RESP 0x0030
456#define IEEE80211_STYPE_PROBE_REQ 0x0040 456#define IEEE80211_STYPE_PROBE_REQ 0x0040
@@ -536,7 +536,7 @@ do { if (ieee80211_debug_level & (level)) \
536//if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA 536//if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA
537#define IEEE80211_DEBUG_DATA(level, data, datalen) \ 537#define IEEE80211_DEBUG_DATA(level, data, datalen) \
538 do{ if ((ieee80211_debug_level & (level)) == (level)) \ 538 do{ if ((ieee80211_debug_level & (level)) == (level)) \
539 { \ 539 { \
540 int i; \ 540 int i; \
541 u8* pdata = (u8*) data; \ 541 u8* pdata = (u8*) data; \
542 printk(KERN_DEBUG "ieee80211: %s()\n", __FUNCTION__); \ 542 printk(KERN_DEBUG "ieee80211: %s()\n", __FUNCTION__); \
@@ -623,20 +623,20 @@ do { if (ieee80211_debug_level & (level)) \
623#define MAX_STR_LEN 64 623#define MAX_STR_LEN 64
624/* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. Annie, 2005-11-22.*/ 624/* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. Annie, 2005-11-22.*/
625#define PRINTABLE(_ch) (_ch>'!' && _ch<'~') 625#define PRINTABLE(_ch) (_ch>'!' && _ch<'~')
626#define IEEE80211_PRINT_STR(_Comp, _TitleString, _Ptr, _Len) \ 626#define IEEE80211_PRINT_STR(_Comp, _TitleString, _Ptr, _Len) \
627 if((_Comp) & level) \ 627 if((_Comp) & level) \
628 { \ 628 { \
629 int __i; \ 629 int __i; \
630 u8 buffer[MAX_STR_LEN]; \ 630 u8 buffer[MAX_STR_LEN]; \
631 int length = (_Len<MAX_STR_LEN)? _Len : (MAX_STR_LEN-1) ; \ 631 int length = (_Len<MAX_STR_LEN)? _Len : (MAX_STR_LEN-1) ; \
632 memset(buffer, 0, MAX_STR_LEN); \ 632 memset(buffer, 0, MAX_STR_LEN); \
633 memcpy(buffer, (u8 *)_Ptr, length ); \ 633 memcpy(buffer, (u8 *)_Ptr, length ); \
634 for( __i=0; __i<MAX_STR_LEN; __i++ ) \ 634 for( __i=0; __i<MAX_STR_LEN; __i++ ) \
635 { \ 635 { \
636 if( !PRINTABLE(buffer[__i]) ) buffer[__i] = '?'; \ 636 if( !PRINTABLE(buffer[__i]) ) buffer[__i] = '?'; \
637 } \ 637 } \
638 buffer[length] = '\0'; \ 638 buffer[length] = '\0'; \
639 printk("Rtl819x: "); \ 639 printk("Rtl819x: "); \
640 printk(_TitleString); \ 640 printk(_TitleString); \
641 printk(": %d, <%s>\n", _Len, buffer); \ 641 printk(": %d, <%s>\n", _Len, buffer); \
642 } 642 }
@@ -785,12 +785,12 @@ enum ieee80211_reasoncode {
785#define IEEE80211_24GHZ_BAND (1<<0) 785#define IEEE80211_24GHZ_BAND (1<<0)
786#define IEEE80211_52GHZ_BAND (1<<1) 786#define IEEE80211_52GHZ_BAND (1<<1)
787 787
788#define IEEE80211_CCK_RATE_LEN 4 788#define IEEE80211_CCK_RATE_LEN 4
789#define IEEE80211_CCK_RATE_1MB 0x02 789#define IEEE80211_CCK_RATE_1MB 0x02
790#define IEEE80211_CCK_RATE_2MB 0x04 790#define IEEE80211_CCK_RATE_2MB 0x04
791#define IEEE80211_CCK_RATE_5MB 0x0B 791#define IEEE80211_CCK_RATE_5MB 0x0B
792#define IEEE80211_CCK_RATE_11MB 0x16 792#define IEEE80211_CCK_RATE_11MB 0x16
793#define IEEE80211_OFDM_RATE_LEN 8 793#define IEEE80211_OFDM_RATE_LEN 8
794#define IEEE80211_OFDM_RATE_6MB 0x0C 794#define IEEE80211_OFDM_RATE_6MB 0x0C
795#define IEEE80211_OFDM_RATE_9MB 0x12 795#define IEEE80211_OFDM_RATE_9MB 0x12
796#define IEEE80211_OFDM_RATE_12MB 0x18 796#define IEEE80211_OFDM_RATE_12MB 0x18
@@ -919,10 +919,10 @@ struct ieee80211_rx_stats {
919 u16 fraglength; // FragLength should equal to PacketLength in non-fragment case 919 u16 fraglength; // FragLength should equal to PacketLength in non-fragment case
920 u16 fragoffset; // Data offset for this fragment 920 u16 fragoffset; // Data offset for this fragment
921 u16 ntotalfrag; 921 u16 ntotalfrag;
922 bool bisrxaggrsubframe; 922 bool bisrxaggrsubframe;
923 bool bPacketBeacon; //cosa add for rssi 923 bool bPacketBeacon; //cosa add for rssi
924 bool bToSelfBA; //cosa add for rssi 924 bool bToSelfBA; //cosa add for rssi
925 char cck_adc_pwdb[4]; //cosa add for rx path selection 925 char cck_adc_pwdb[4]; //cosa add for rx path selection
926 u16 Seq_Num; 926 u16 Seq_Num;
927 927
928}; 928};
@@ -992,7 +992,7 @@ struct ieee80211_device;
992#define SEC_ALG_TKIP 2 992#define SEC_ALG_TKIP 2
993#define SEC_ALG_CCMP 3 993#define SEC_ALG_CCMP 3
994 994
995#define WEP_KEYS 4 995#define WEP_KEYS 4
996#define WEP_KEY_LEN 13 996#define WEP_KEY_LEN 13
997#define SCM_KEY_LEN 32 997#define SCM_KEY_LEN 32
998#define SCM_TEMPORAL_KEY_LENGTH 16 998#define SCM_TEMPORAL_KEY_LENGTH 16
@@ -1205,7 +1205,7 @@ struct ieee80211_drv_agg_txb {
1205 struct sk_buff *tx_agg_frames[MAX_TX_AGG_COUNT]; 1205 struct sk_buff *tx_agg_frames[MAX_TX_AGG_COUNT];
1206}__attribute__((packed)); 1206}__attribute__((packed));
1207 1207
1208#define MAX_SUBFRAME_COUNT 64 1208#define MAX_SUBFRAME_COUNT 64
1209struct ieee80211_rxb { 1209struct ieee80211_rxb {
1210 u8 nr_subframes; 1210 u8 nr_subframes;
1211 struct sk_buff *subframes[MAX_SUBFRAME_COUNT]; 1211 struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
@@ -1534,7 +1534,7 @@ struct ieee80211_network {
1534 bool bWithAironetIE; 1534 bool bWithAironetIE;
1535 bool bCkipSupported; 1535 bool bCkipSupported;
1536 bool bCcxRmEnable; 1536 bool bCcxRmEnable;
1537 u16 CcxRmState[2]; 1537 u16 CcxRmState[2];
1538 // CCXv4 S59, MBSSID. 1538 // CCXv4 S59, MBSSID.
1539 bool bMBssidValid; 1539 bool bMBssidValid;
1540 u8 MBssidMask; 1540 u8 MBssidMask;
@@ -1655,8 +1655,7 @@ typedef struct tx_pending_t{
1655 struct ieee80211_txb *txb; 1655 struct ieee80211_txb *txb;
1656}tx_pending_t; 1656}tx_pending_t;
1657 1657
1658typedef struct _bandwidth_autoswitch 1658typedef struct _bandwidth_autoswitch {
1659{
1660 long threshold_20Mhzto40Mhz; 1659 long threshold_20Mhzto40Mhz;
1661 long threshold_40Mhzto20Mhz; 1660 long threshold_40Mhzto20Mhz;
1662 bool bforced_tx20Mhz; 1661 bool bforced_tx20Mhz;
@@ -1668,8 +1667,7 @@ typedef struct _bandwidth_autoswitch
1668 1667
1669#define REORDER_WIN_SIZE 128 1668#define REORDER_WIN_SIZE 128
1670#define REORDER_ENTRY_NUM 128 1669#define REORDER_ENTRY_NUM 128
1671typedef struct _RX_REORDER_ENTRY 1670typedef struct _RX_REORDER_ENTRY {
1672{
1673 struct list_head List; 1671 struct list_head List;
1674 u16 SeqNum; 1672 u16 SeqNum;
1675 struct ieee80211_rxb* prxb; 1673 struct ieee80211_rxb* prxb;
@@ -1709,15 +1707,13 @@ typedef struct _IbssParms{
1709#define MAX_NUM_RATES 264 // Max num of support rates element: 8, Max num of ext. support rate: 255. 061122, by rcnjko. 1707#define MAX_NUM_RATES 264 // Max num of support rates element: 8, Max num of ext. support rate: 255. 061122, by rcnjko.
1710 1708
1711// RF state. 1709// RF state.
1712typedef enum _RT_RF_POWER_STATE 1710typedef enum _RT_RF_POWER_STATE {
1713{
1714 eRfOn, 1711 eRfOn,
1715 eRfSleep, 1712 eRfSleep,
1716 eRfOff 1713 eRfOff
1717}RT_RF_POWER_STATE; 1714}RT_RF_POWER_STATE;
1718 1715
1719typedef struct _RT_POWER_SAVE_CONTROL 1716typedef struct _RT_POWER_SAVE_CONTROL {
1720{
1721 1717
1722 // 1718 //
1723 // Inactive Power Save(IPS) : Disable RF when disconnected 1719 // Inactive Power Save(IPS) : Disable RF when disconnected
@@ -1726,7 +1722,7 @@ typedef struct _RT_POWER_SAVE_CONTROL
1726 bool bIPSModeBackup; 1722 bool bIPSModeBackup;
1727 bool bSwRfProcessing; 1723 bool bSwRfProcessing;
1728 RT_RF_POWER_STATE eInactivePowerState; 1724 RT_RF_POWER_STATE eInactivePowerState;
1729 struct work_struct InactivePsWorkItem; 1725 struct work_struct InactivePsWorkItem;
1730 struct timer_list InactivePsTimer; 1726 struct timer_list InactivePsTimer;
1731 1727
1732 // Return point for join action 1728 // Return point for join action
@@ -1837,11 +1833,11 @@ struct ieee80211_device {
1837 u8 HTHighestOperaRate; 1833 u8 HTHighestOperaRate;
1838 //wb added for rate operation mode to firmware 1834 //wb added for rate operation mode to firmware
1839 u8 bTxDisableRateFallBack; 1835 u8 bTxDisableRateFallBack;
1840 u8 bTxUseDriverAssingedRate; 1836 u8 bTxUseDriverAssingedRate;
1841 atomic_t atm_chnlop; 1837 atomic_t atm_chnlop;
1842 atomic_t atm_swbw; 1838 atomic_t atm_swbw;
1843// u8 HTHighestOperaRate; 1839// u8 HTHighestOperaRate;
1844// u8 HTCurrentOperaRate; 1840// u8 HTCurrentOperaRate;
1845 1841
1846 // 802.11e and WMM Traffic Stream Info (TX) 1842 // 802.11e and WMM Traffic Stream Info (TX)
1847 struct list_head Tx_TS_Admit_List; 1843 struct list_head Tx_TS_Admit_List;
@@ -2055,9 +2051,9 @@ struct ieee80211_device {
2055 bool bdynamic_txpower_enable; 2051 bool bdynamic_txpower_enable;
2056 2052
2057 bool bCTSToSelfEnable; 2053 bool bCTSToSelfEnable;
2058 u8 CTSToSelfTH; 2054 u8 CTSToSelfTH;
2059 2055
2060 u32 fsync_time_interval; 2056 u32 fsync_time_interval;
2061 u32 fsync_rate_bitmap; 2057 u32 fsync_rate_bitmap;
2062 u8 fsync_rssi_threshold; 2058 u8 fsync_rssi_threshold;
2063 bool bfsync_enable; 2059 bool bfsync_enable;
@@ -2092,10 +2088,10 @@ struct ieee80211_device {
2092 struct delayed_work start_ibss_wq; 2088 struct delayed_work start_ibss_wq;
2093 struct work_struct wx_sync_scan_wq; 2089 struct work_struct wx_sync_scan_wq;
2094 struct workqueue_struct *wq; 2090 struct workqueue_struct *wq;
2095 // Qos related. Added by Annie, 2005-11-01. 2091 // Qos related. Added by Annie, 2005-11-01.
2096 //STA_QOS StaQos; 2092 //STA_QOS StaQos;
2097 2093
2098 //u32 STA_EDCA_PARAM[4]; 2094 //u32 STA_EDCA_PARAM[4];
2099 //CHANNEL_ACCESS_SETTING ChannelAccessSetting; 2095 //CHANNEL_ACCESS_SETTING ChannelAccessSetting;
2100 2096
2101 2097
@@ -2111,11 +2107,11 @@ struct ieee80211_device {
2111 struct net_device *dev); 2107 struct net_device *dev);
2112 2108
2113 int (*reset_port)(struct net_device *dev); 2109 int (*reset_port)(struct net_device *dev);
2114 int (*is_queue_full) (struct net_device * dev, int pri); 2110 int (*is_queue_full) (struct net_device * dev, int pri);
2115 2111
2116 int (*handle_management) (struct net_device * dev, 2112 int (*handle_management) (struct net_device * dev,
2117 struct ieee80211_network * network, u16 type); 2113 struct ieee80211_network * network, u16 type);
2118 int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb); 2114 int (*is_qos_active) (struct net_device *dev, struct sk_buff *skb);
2119 2115
2120 /* Softmac-generated frames (management) are TXed via this 2116 /* Softmac-generated frames (management) are TXed via this
2121 * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is 2117 * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
@@ -2214,7 +2210,7 @@ struct ieee80211_device {
2214#define IEEE_A (1<<0) 2210#define IEEE_A (1<<0)
2215#define IEEE_B (1<<1) 2211#define IEEE_B (1<<1)
2216#define IEEE_G (1<<2) 2212#define IEEE_G (1<<2)
2217#define IEEE_N_24G (1<<4) 2213#define IEEE_N_24G (1<<4)
2218#define IEEE_N_5G (1<<5) 2214#define IEEE_N_5G (1<<5)
2219#define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G) 2215#define IEEE_MODE_MASK (IEEE_A|IEEE_B|IEEE_G)
2220 2216
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
index 82d4bf6a86a5..76c56e5aed79 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
@@ -220,7 +220,7 @@ void free_ieee80211(struct net_device *dev)
220 220
221#ifdef CONFIG_IEEE80211_DEBUG 221#ifdef CONFIG_IEEE80211_DEBUG
222 222
223u32 ieee80211_debug_level = 0; 223u32 ieee80211_debug_level;
224static int debug = \ 224static int debug = \
225 // IEEE80211_DL_INFO | 225 // IEEE80211_DL_INFO |
226 // IEEE80211_DL_WX | 226 // IEEE80211_DL_WX |
@@ -233,15 +233,15 @@ static int debug = \
233 // IEEE80211_DL_TX | 233 // IEEE80211_DL_TX |
234 // IEEE80211_DL_RX | 234 // IEEE80211_DL_RX |
235 //IEEE80211_DL_QOS | 235 //IEEE80211_DL_QOS |
236 // IEEE80211_DL_HT | 236 // IEEE80211_DL_HT |
237 // IEEE80211_DL_TS | 237 // IEEE80211_DL_TS |
238// IEEE80211_DL_BA | 238// IEEE80211_DL_BA |
239 // IEEE80211_DL_REORDER| 239 // IEEE80211_DL_REORDER|
240// IEEE80211_DL_TRACE | 240// IEEE80211_DL_TRACE |
241 //IEEE80211_DL_DATA | 241 //IEEE80211_DL_DATA |
242 IEEE80211_DL_ERR //awayls open this flags to show error out 242 IEEE80211_DL_ERR //awayls open this flags to show error out
243 ; 243 ;
244struct proc_dir_entry *ieee80211_proc = NULL; 244struct proc_dir_entry *ieee80211_proc;
245 245
246static int show_debug_level(char *page, char **start, off_t offset, 246static int show_debug_level(char *page, char **start, off_t offset,
247 int count, int *eof, void *data) 247 int count, int *eof, void *data)
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index e3cf7a45b900..ee7ce5fca462 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -52,7 +52,7 @@ static inline void ieee80211_monitor_rx(struct ieee80211_device *ieee,
52 u16 fc = le16_to_cpu(hdr->frame_ctl); 52 u16 fc = le16_to_cpu(hdr->frame_ctl);
53 53
54 skb->dev = ieee->dev; 54 skb->dev = ieee->dev;
55 skb_reset_mac_header(skb); 55 skb_reset_mac_header(skb);
56 56
57 skb_pull(skb, ieee80211_get_hdrlen(fc)); 57 skb_pull(skb, ieee80211_get_hdrlen(fc));
58 skb->pkt_type = PACKET_OTHERHOST; 58 skb->pkt_type = PACKET_OTHERHOST;
@@ -218,16 +218,16 @@ ieee80211_rx_frame_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb,
218 * this is not mandatory.... but seems that the probe 218 * this is not mandatory.... but seems that the probe
219 * response parser uses it 219 * response parser uses it
220 */ 220 */
221 struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data; 221 struct ieee80211_hdr_3addr * hdr = (struct ieee80211_hdr_3addr *)skb->data;
222 222
223 rx_stats->len = skb->len; 223 rx_stats->len = skb->len;
224 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats); 224 ieee80211_rx_mgt(ieee,(struct ieee80211_hdr_4addr *)skb->data,rx_stats);
225 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN))) 225 //if ((ieee->state == IEEE80211_LINKED) && (memcmp(hdr->addr3, ieee->current_network.bssid, ETH_ALEN)))
226 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames 226 if ((memcmp(hdr->addr1, ieee->dev->dev_addr, ETH_ALEN)))//use ADDR1 to perform address matching for Management frames
227 { 227 {
228 dev_kfree_skb_any(skb); 228 dev_kfree_skb_any(skb);
229 return 0; 229 return 0;
230 } 230 }
231 231
232 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype); 232 ieee80211_rx_frame_softmac(ieee, skb, rx_stats, type, stype);
233 233
@@ -608,7 +608,7 @@ void RxReorderIndicatePacket( struct ieee80211_device *ieee,
608 u16 SeqNum) 608 u16 SeqNum)
609{ 609{
610 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 610 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
611 PRX_REORDER_ENTRY pReorderEntry = NULL; 611 PRX_REORDER_ENTRY pReorderEntry = NULL;
612 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE]; 612 struct ieee80211_rxb* prxbIndicateArray[REORDER_WIN_SIZE];
613 u8 WinSize = pHTInfo->RxReorderWinSize; 613 u8 WinSize = pHTInfo->RxReorderWinSize;
614 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096; 614 u16 WinEnd = (pTS->RxIndicateSeq + WinSize -1)%4096;
@@ -773,7 +773,7 @@ void RxReorderIndicatePacket( struct ieee80211_device *ieee,
773} 773}
774 774
775u8 parse_subframe(struct sk_buff *skb, 775u8 parse_subframe(struct sk_buff *skb,
776 struct ieee80211_rx_stats *rx_stats, 776 struct ieee80211_rx_stats *rx_stats,
777 struct ieee80211_rxb *rxb,u8* src,u8* dst) 777 struct ieee80211_rxb *rxb,u8* src,u8* dst)
778{ 778{
779 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data; 779 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr* )skb->data;
@@ -1043,7 +1043,7 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1043 { 1043 {
1044 1044
1045 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__FUNCTION__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc)); 1045 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__FUNCTION__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc));
1046 if( (fc & (1<<11)) && 1046 if( (fc & (1<<11)) &&
1047 (frag == pRxTS->RxLastFragNum) && 1047 (frag == pRxTS->RxLastFragNum) &&
1048 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) ) 1048 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) )
1049 { 1049 {
@@ -1154,8 +1154,8 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1154 type, stype, skb->len); 1154 type, stype, skb->len);
1155 goto rx_dropped; 1155 goto rx_dropped;
1156 } 1156 }
1157 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN)) 1157 if (memcmp(bssid, ieee->current_network.bssid, ETH_ALEN))
1158 goto rx_dropped; 1158 goto rx_dropped;
1159 1159
1160 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */ 1160 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
1161 1161
@@ -1402,19 +1402,19 @@ static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
1402* the right values 1402* the right values
1403*/ 1403*/
1404static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element 1404static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1405 *info_element, int sub_type) 1405 *info_element, int sub_type)
1406{ 1406{
1407 1407
1408 if (info_element->qui_subtype != sub_type) 1408 if (info_element->qui_subtype != sub_type)
1409 return -1; 1409 return -1;
1410 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN)) 1410 if (memcmp(info_element->qui, qos_oui, QOS_OUI_LEN))
1411 return -1; 1411 return -1;
1412 if (info_element->qui_type != QOS_OUI_TYPE) 1412 if (info_element->qui_type != QOS_OUI_TYPE)
1413 return -1; 1413 return -1;
1414 if (info_element->version != QOS_VERSION_1) 1414 if (info_element->version != QOS_VERSION_1)
1415 return -1; 1415 return -1;
1416 1416
1417 return 0; 1417 return 0;
1418} 1418}
1419 1419
1420 1420
@@ -1422,56 +1422,56 @@ static int ieee80211_verify_qos_info(struct ieee80211_qos_information_element
1422 * Parse a QoS parameter element 1422 * Parse a QoS parameter element
1423 */ 1423 */
1424static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info 1424static int ieee80211_read_qos_param_element(struct ieee80211_qos_parameter_info
1425 *element_param, struct ieee80211_info_element 1425 *element_param, struct ieee80211_info_element
1426 *info_element) 1426 *info_element)
1427{ 1427{
1428 int ret = 0; 1428 int ret = 0;
1429 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2; 1429 u16 size = sizeof(struct ieee80211_qos_parameter_info) - 2;
1430 1430
1431 if ((info_element == NULL) || (element_param == NULL)) 1431 if ((info_element == NULL) || (element_param == NULL))
1432 return -1; 1432 return -1;
1433 1433
1434 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) { 1434 if (info_element->id == QOS_ELEMENT_ID && info_element->len == size) {
1435 memcpy(element_param->info_element.qui, info_element->data, 1435 memcpy(element_param->info_element.qui, info_element->data,
1436 info_element->len); 1436 info_element->len);
1437 element_param->info_element.elementID = info_element->id; 1437 element_param->info_element.elementID = info_element->id;
1438 element_param->info_element.length = info_element->len; 1438 element_param->info_element.length = info_element->len;
1439 } else 1439 } else
1440 ret = -1; 1440 ret = -1;
1441 if (ret == 0) 1441 if (ret == 0)
1442 ret = ieee80211_verify_qos_info(&element_param->info_element, 1442 ret = ieee80211_verify_qos_info(&element_param->info_element,
1443 QOS_OUI_PARAM_SUB_TYPE); 1443 QOS_OUI_PARAM_SUB_TYPE);
1444 return ret; 1444 return ret;
1445} 1445}
1446 1446
1447/* 1447/*
1448 * Parse a QoS information element 1448 * Parse a QoS information element
1449 */ 1449 */
1450static int ieee80211_read_qos_info_element(struct 1450static int ieee80211_read_qos_info_element(struct
1451 ieee80211_qos_information_element 1451 ieee80211_qos_information_element
1452 *element_info, struct ieee80211_info_element 1452 *element_info, struct ieee80211_info_element
1453 *info_element) 1453 *info_element)
1454{ 1454{
1455 int ret = 0; 1455 int ret = 0;
1456 u16 size = sizeof(struct ieee80211_qos_information_element) - 2; 1456 u16 size = sizeof(struct ieee80211_qos_information_element) - 2;
1457 1457
1458 if (element_info == NULL) 1458 if (element_info == NULL)
1459 return -1; 1459 return -1;
1460 if (info_element == NULL) 1460 if (info_element == NULL)
1461 return -1; 1461 return -1;
1462 1462
1463 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) { 1463 if ((info_element->id == QOS_ELEMENT_ID) && (info_element->len == size)) {
1464 memcpy(element_info->qui, info_element->data, 1464 memcpy(element_info->qui, info_element->data,
1465 info_element->len); 1465 info_element->len);
1466 element_info->elementID = info_element->id; 1466 element_info->elementID = info_element->id;
1467 element_info->length = info_element->len; 1467 element_info->length = info_element->len;
1468 } else 1468 } else
1469 ret = -1; 1469 ret = -1;
1470 1470
1471 if (ret == 0) 1471 if (ret == 0)
1472 ret = ieee80211_verify_qos_info(element_info, 1472 ret = ieee80211_verify_qos_info(element_info,
1473 QOS_OUI_INFO_SUB_TYPE); 1473 QOS_OUI_INFO_SUB_TYPE);
1474 return ret; 1474 return ret;
1475} 1475}
1476 1476
1477 1477
@@ -1479,39 +1479,39 @@ static int ieee80211_read_qos_info_element(struct
1479 * Write QoS parameters from the ac parameters. 1479 * Write QoS parameters from the ac parameters.
1480 */ 1480 */
1481static int ieee80211_qos_convert_ac_to_parameters(struct 1481static int ieee80211_qos_convert_ac_to_parameters(struct
1482 ieee80211_qos_parameter_info 1482 ieee80211_qos_parameter_info
1483 *param_elm, struct 1483 *param_elm, struct
1484 ieee80211_qos_parameters 1484 ieee80211_qos_parameters
1485 *qos_param) 1485 *qos_param)
1486{ 1486{
1487 int rc = 0; 1487 int rc = 0;
1488 int i; 1488 int i;
1489 struct ieee80211_qos_ac_parameter *ac_params; 1489 struct ieee80211_qos_ac_parameter *ac_params;
1490 u8 aci; 1490 u8 aci;
1491 //u8 cw_min; 1491 //u8 cw_min;
1492 //u8 cw_max; 1492 //u8 cw_max;
1493 1493
1494 for (i = 0; i < QOS_QUEUE_NUM; i++) { 1494 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1495 ac_params = &(param_elm->ac_params_record[i]); 1495 ac_params = &(param_elm->ac_params_record[i]);
1496 1496
1497 aci = (ac_params->aci_aifsn & 0x60) >> 5; 1497 aci = (ac_params->aci_aifsn & 0x60) >> 5;
1498 1498
1499 if(aci >= QOS_QUEUE_NUM) 1499 if(aci >= QOS_QUEUE_NUM)
1500 continue; 1500 continue;
1501 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f; 1501 qos_param->aifs[aci] = (ac_params->aci_aifsn) & 0x0f;
1502 1502
1503 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */ 1503 /* WMM spec P.11: The minimum value for AIFSN shall be 2 */
1504 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci]; 1504 qos_param->aifs[aci] = (qos_param->aifs[aci] < 2) ? 2:qos_param->aifs[aci];
1505 1505
1506 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F; 1506 qos_param->cw_min[aci] = ac_params->ecw_min_max & 0x0F;
1507 1507
1508 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4; 1508 qos_param->cw_max[aci] = (ac_params->ecw_min_max & 0xF0) >> 4;
1509 1509
1510 qos_param->flag[aci] = 1510 qos_param->flag[aci] =
1511 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00; 1511 (ac_params->aci_aifsn & 0x10) ? 0x01 : 0x00;
1512 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit); 1512 qos_param->tx_op_limit[aci] = le16_to_cpu(ac_params->tx_op_limit);
1513 } 1513 }
1514 return rc; 1514 return rc;
1515} 1515}
1516 1516
1517/* 1517/*
@@ -1520,38 +1520,38 @@ static int ieee80211_qos_convert_ac_to_parameters(struct
1520 * which type to read 1520 * which type to read
1521 */ 1521 */
1522static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element 1522static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1523 *info_element, 1523 *info_element,
1524 struct ieee80211_network *network) 1524 struct ieee80211_network *network)
1525{ 1525{
1526 int rc = 0; 1526 int rc = 0;
1527 struct ieee80211_qos_parameters *qos_param = NULL; 1527 struct ieee80211_qos_parameters *qos_param = NULL;
1528 struct ieee80211_qos_information_element qos_info_element; 1528 struct ieee80211_qos_information_element qos_info_element;
1529 1529
1530 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element); 1530 rc = ieee80211_read_qos_info_element(&qos_info_element, info_element);
1531 1531
1532 if (rc == 0) { 1532 if (rc == 0) {
1533 network->qos_data.param_count = qos_info_element.ac_info & 0x0F; 1533 network->qos_data.param_count = qos_info_element.ac_info & 0x0F;
1534 network->flags |= NETWORK_HAS_QOS_INFORMATION; 1534 network->flags |= NETWORK_HAS_QOS_INFORMATION;
1535 } else { 1535 } else {
1536 struct ieee80211_qos_parameter_info param_element; 1536 struct ieee80211_qos_parameter_info param_element;
1537 1537
1538 rc = ieee80211_read_qos_param_element(&param_element, 1538 rc = ieee80211_read_qos_param_element(&param_element,
1539 info_element); 1539 info_element);
1540 if (rc == 0) { 1540 if (rc == 0) {
1541 qos_param = &(network->qos_data.parameters); 1541 qos_param = &(network->qos_data.parameters);
1542 ieee80211_qos_convert_ac_to_parameters(&param_element, 1542 ieee80211_qos_convert_ac_to_parameters(&param_element,
1543 qos_param); 1543 qos_param);
1544 network->flags |= NETWORK_HAS_QOS_PARAMETERS; 1544 network->flags |= NETWORK_HAS_QOS_PARAMETERS;
1545 network->qos_data.param_count = 1545 network->qos_data.param_count =
1546 param_element.info_element.ac_info & 0x0F; 1546 param_element.info_element.ac_info & 0x0F;
1547 } 1547 }
1548 } 1548 }
1549 1549
1550 if (rc == 0) { 1550 if (rc == 0) {
1551 IEEE80211_DEBUG_QOS("QoS is supported\n"); 1551 IEEE80211_DEBUG_QOS("QoS is supported\n");
1552 network->qos_data.supported = 1; 1552 network->qos_data.supported = 1;
1553 } 1553 }
1554 return rc; 1554 return rc;
1555} 1555}
1556 1556
1557#ifdef CONFIG_IEEE80211_DEBUG 1557#ifdef CONFIG_IEEE80211_DEBUG
@@ -1559,37 +1559,37 @@ static int ieee80211_parse_qos_info_param_IE(struct ieee80211_info_element
1559 1559
1560static const char *get_info_element_string(u16 id) 1560static const char *get_info_element_string(u16 id)
1561{ 1561{
1562 switch (id) { 1562 switch (id) {
1563 MFIE_STRING(SSID); 1563 MFIE_STRING(SSID);
1564 MFIE_STRING(RATES); 1564 MFIE_STRING(RATES);
1565 MFIE_STRING(FH_SET); 1565 MFIE_STRING(FH_SET);
1566 MFIE_STRING(DS_SET); 1566 MFIE_STRING(DS_SET);
1567 MFIE_STRING(CF_SET); 1567 MFIE_STRING(CF_SET);
1568 MFIE_STRING(TIM); 1568 MFIE_STRING(TIM);
1569 MFIE_STRING(IBSS_SET); 1569 MFIE_STRING(IBSS_SET);
1570 MFIE_STRING(COUNTRY); 1570 MFIE_STRING(COUNTRY);
1571 MFIE_STRING(HOP_PARAMS); 1571 MFIE_STRING(HOP_PARAMS);
1572 MFIE_STRING(HOP_TABLE); 1572 MFIE_STRING(HOP_TABLE);
1573 MFIE_STRING(REQUEST); 1573 MFIE_STRING(REQUEST);
1574 MFIE_STRING(CHALLENGE); 1574 MFIE_STRING(CHALLENGE);
1575 MFIE_STRING(POWER_CONSTRAINT); 1575 MFIE_STRING(POWER_CONSTRAINT);
1576 MFIE_STRING(POWER_CAPABILITY); 1576 MFIE_STRING(POWER_CAPABILITY);
1577 MFIE_STRING(TPC_REQUEST); 1577 MFIE_STRING(TPC_REQUEST);
1578 MFIE_STRING(TPC_REPORT); 1578 MFIE_STRING(TPC_REPORT);
1579 MFIE_STRING(SUPP_CHANNELS); 1579 MFIE_STRING(SUPP_CHANNELS);
1580 MFIE_STRING(CSA); 1580 MFIE_STRING(CSA);
1581 MFIE_STRING(MEASURE_REQUEST); 1581 MFIE_STRING(MEASURE_REQUEST);
1582 MFIE_STRING(MEASURE_REPORT); 1582 MFIE_STRING(MEASURE_REPORT);
1583 MFIE_STRING(QUIET); 1583 MFIE_STRING(QUIET);
1584 MFIE_STRING(IBSS_DFS); 1584 MFIE_STRING(IBSS_DFS);
1585 // MFIE_STRING(ERP_INFO); 1585 // MFIE_STRING(ERP_INFO);
1586 MFIE_STRING(RSN); 1586 MFIE_STRING(RSN);
1587 MFIE_STRING(RATES_EX); 1587 MFIE_STRING(RATES_EX);
1588 MFIE_STRING(GENERIC); 1588 MFIE_STRING(GENERIC);
1589 MFIE_STRING(QOS_PARAMETER); 1589 MFIE_STRING(QOS_PARAMETER);
1590 default: 1590 default:
1591 return "UNKNOWN"; 1591 return "UNKNOWN";
1592 } 1592 }
1593} 1593}
1594#endif 1594#endif
1595 1595
@@ -1634,7 +1634,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1634{ 1634{
1635 u8 i; 1635 u8 i;
1636 short offset; 1636 short offset;
1637 u16 tmp_htcap_len=0; 1637 u16 tmp_htcap_len=0;
1638 u16 tmp_htinfo_len=0; 1638 u16 tmp_htinfo_len=0;
1639 u16 ht_realtek_agg_len=0; 1639 u16 ht_realtek_agg_len=0;
1640 u8 ht_realtek_agg_buf[MAX_IE_LEN]; 1640 u8 ht_realtek_agg_buf[MAX_IE_LEN];
@@ -1752,34 +1752,34 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1752 network->tim.tim_count = info_element->data[0]; 1752 network->tim.tim_count = info_element->data[0];
1753 network->tim.tim_period = info_element->data[1]; 1753 network->tim.tim_period = info_element->data[1];
1754 1754
1755 network->dtim_period = info_element->data[1]; 1755 network->dtim_period = info_element->data[1];
1756 if(ieee->state != IEEE80211_LINKED) 1756 if(ieee->state != IEEE80211_LINKED)
1757 break; 1757 break;
1758 1758
1759 network->last_dtim_sta_time[0] = stats->mac_time[0]; 1759 network->last_dtim_sta_time[0] = stats->mac_time[0];
1760 network->last_dtim_sta_time[1] = stats->mac_time[1]; 1760 network->last_dtim_sta_time[1] = stats->mac_time[1];
1761 1761
1762 network->dtim_data = IEEE80211_DTIM_VALID; 1762 network->dtim_data = IEEE80211_DTIM_VALID;
1763 1763
1764 if(info_element->data[0] != 0) 1764 if(info_element->data[0] != 0)
1765 break; 1765 break;
1766 1766
1767 if(info_element->data[2] & 1) 1767 if(info_element->data[2] & 1)
1768 network->dtim_data |= IEEE80211_DTIM_MBCAST; 1768 network->dtim_data |= IEEE80211_DTIM_MBCAST;
1769 1769
1770 offset = (info_element->data[2] >> 1)*2; 1770 offset = (info_element->data[2] >> 1)*2;
1771 1771
1772 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id); 1772 //printk("offset1:%x aid:%x\n",offset, ieee->assoc_id);
1773 1773
1774 if(ieee->assoc_id < 8*offset || 1774 if(ieee->assoc_id < 8*offset ||
1775 ieee->assoc_id > 8*(offset + info_element->len -3)) 1775 ieee->assoc_id > 8*(offset + info_element->len -3))
1776 1776
1777 break; 1777 break;
1778 1778
1779 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ; 1779 offset = (ieee->assoc_id / 8) - offset;// + ((aid % 8)? 0 : 1) ;
1780 1780
1781 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8))) 1781 if(info_element->data[3+offset] & (1<<(ieee->assoc_id%8)))
1782 network->dtim_data |= IEEE80211_DTIM_UCAST; 1782 network->dtim_data |= IEEE80211_DTIM_UCAST;
1783 1783
1784 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n"); 1784 //IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
1785 break; 1785 break;
@@ -1820,17 +1820,17 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1820 } 1820 }
1821 1821
1822#ifdef THOMAS_TURBO 1822#ifdef THOMAS_TURBO
1823 if (info_element->len == 7 && 1823 if (info_element->len == 7 &&
1824 info_element->data[0] == 0x00 && 1824 info_element->data[0] == 0x00 &&
1825 info_element->data[1] == 0xe0 && 1825 info_element->data[1] == 0xe0 &&
1826 info_element->data[2] == 0x4c && 1826 info_element->data[2] == 0x4c &&
1827 info_element->data[3] == 0x01 && 1827 info_element->data[3] == 0x01 &&
1828 info_element->data[4] == 0x02) { 1828 info_element->data[4] == 0x02) {
1829 network->Turbo_Enable = 1; 1829 network->Turbo_Enable = 1;
1830 } 1830 }
1831#endif 1831#endif
1832 1832
1833 //for HTcap and HTinfo parameters 1833 //for HTcap and HTinfo parameters
1834 if(tmp_htcap_len == 0){ 1834 if(tmp_htcap_len == 0){
1835 if(info_element->len >= 4 && 1835 if(info_element->len >= 4 &&
1836 info_element->data[0] == 0x00 && 1836 info_element->data[0] == 0x00 &&
@@ -1839,12 +1839,12 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1839 info_element->data[3] == 0x033){ 1839 info_element->data[3] == 0x033){
1840 1840
1841 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN); 1841 tmp_htcap_len = min(info_element->len,(u8)MAX_IE_LEN);
1842 if(tmp_htcap_len != 0){ 1842 if(tmp_htcap_len != 0){
1843 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC; 1843 network->bssht.bdHTSpecVer = HT_SPEC_VER_EWC;
1844 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\ 1844 network->bssht.bdHTCapLen = tmp_htcap_len > sizeof(network->bssht.bdHTCapBuf)?\
1845 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len; 1845 sizeof(network->bssht.bdHTCapBuf):tmp_htcap_len;
1846 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen); 1846 memcpy(network->bssht.bdHTCapBuf,info_element->data,network->bssht.bdHTCapLen);
1847 } 1847 }
1848 } 1848 }
1849 if(tmp_htcap_len != 0) 1849 if(tmp_htcap_len != 0)
1850 network->bssht.bdSupportHT = true; 1850 network->bssht.bdSupportHT = true;
@@ -1856,9 +1856,9 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
1856 if(tmp_htinfo_len == 0){ 1856 if(tmp_htinfo_len == 0){
1857 if(info_element->len >= 4 && 1857 if(info_element->len >= 4 &&
1858 info_element->data[0] == 0x00 && 1858 info_element->data[0] == 0x00 &&
1859 info_element->data[1] == 0x90 && 1859 info_element->data[1] == 0x90 &&
1860 info_element->data[2] == 0x4c && 1860 info_element->data[2] == 0x4c &&
1861 info_element->data[3] == 0x034){ 1861 info_element->data[3] == 0x034){
1862 1862
1863 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN); 1863 tmp_htinfo_len = min(info_element->len,(u8)MAX_IE_LEN);
1864 if(tmp_htinfo_len != 0){ 1864 if(tmp_htinfo_len != 0){
@@ -2014,7 +2014,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2014 network->rsn_ie_len); 2014 network->rsn_ie_len);
2015 break; 2015 break;
2016 2016
2017 //HT related element. 2017 //HT related element.
2018 case MFIE_TYPE_HT_CAP: 2018 case MFIE_TYPE_HT_CAP:
2019 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n", 2019 IEEE80211_DEBUG_SCAN("MFIE_TYPE_HT_CAP: %d bytes\n",
2020 info_element->len); 2020 info_element->len);
@@ -2027,7 +2027,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2027 2027
2028 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT() 2028 //If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
2029 // windows driver will update WMM parameters each beacon received once connected 2029 // windows driver will update WMM parameters each beacon received once connected
2030 // Linux driver is a bit different. 2030 // Linux driver is a bit different.
2031 network->bssht.bdSupportHT = true; 2031 network->bssht.bdSupportHT = true;
2032 } 2032 }
2033 else 2033 else
@@ -2060,7 +2060,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2060 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) || 2060 if( (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_MIC) ||
2061 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) ) 2061 (info_element->data[IE_CISCO_FLAG_POSITION]&SUPPORT_CKIP_PK) )
2062 { 2062 {
2063 network->bCkipSupported = true; 2063 network->bCkipSupported = true;
2064 } 2064 }
2065 else 2065 else
2066 { 2066 {
@@ -2070,7 +2070,7 @@ int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2070 else 2070 else
2071 { 2071 {
2072 network->bWithAironetIE = false; 2072 network->bWithAironetIE = false;
2073 network->bCkipSupported = false; 2073 network->bCkipSupported = false;
2074 } 2074 }
2075 break; 2075 break;
2076 case MFIE_TYPE_QOS_PARAMETER: 2076 case MFIE_TYPE_QOS_PARAMETER:
@@ -2189,10 +2189,10 @@ static inline int ieee80211_network_init(
2189 //char *p; 2189 //char *p;
2190#endif 2190#endif
2191 2191
2192 network->qos_data.active = 0; 2192 network->qos_data.active = 0;
2193 network->qos_data.supported = 0; 2193 network->qos_data.supported = 0;
2194 network->qos_data.param_count = 0; 2194 network->qos_data.param_count = 0;
2195 network->qos_data.old_param_count = 0; 2195 network->qos_data.old_param_count = 0;
2196 2196
2197 /* Pull out fixed field data */ 2197 /* Pull out fixed field data */
2198 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN); 2198 memcpy(network->bssid, beacon->header.addr3, ETH_ALEN);
@@ -2209,9 +2209,9 @@ static inline int ieee80211_network_init(
2209 network->flags = 0; 2209 network->flags = 0;
2210 network->atim_window = 0; 2210 network->atim_window = 0;
2211 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ? 2211 network->erp_value = (network->capability & WLAN_CAPABILITY_IBSS) ?
2212 0x3 : 0x0; 2212 0x3 : 0x0;
2213 network->berp_info_valid = false; 2213 network->berp_info_valid = false;
2214 network->broadcom_cap_exist = false; 2214 network->broadcom_cap_exist = false;
2215 network->ralink_cap_exist = false; 2215 network->ralink_cap_exist = false;
2216 network->atheros_cap_exist = false; 2216 network->atheros_cap_exist = false;
2217 network->cisco_cap_exist = false; 2217 network->cisco_cap_exist = false;
@@ -2230,12 +2230,12 @@ static inline int ieee80211_network_init(
2230 } else 2230 } else
2231 network->flags |= NETWORK_HAS_CCK; 2231 network->flags |= NETWORK_HAS_CCK;
2232 2232
2233 network->wpa_ie_len = 0; 2233 network->wpa_ie_len = 0;
2234 network->rsn_ie_len = 0; 2234 network->rsn_ie_len = 0;
2235 2235
2236 if (ieee80211_parse_info_param 2236 if (ieee80211_parse_info_param
2237 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats)) 2237 (ieee,beacon->info_element, stats->len - sizeof(*beacon), network, stats))
2238 return 1; 2238 return 1;
2239 2239
2240 network->mode = 0; 2240 network->mode = 0;
2241 if (stats->freq == IEEE80211_52GHZ_BAND) 2241 if (stats->freq == IEEE80211_52GHZ_BAND)
@@ -2329,7 +2329,7 @@ static inline void update_network(struct ieee80211_network *dst,
2329 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1]; 2329 dst->last_dtim_sta_time[1] = src->last_dtim_sta_time[1];
2330 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters)); 2330 memcpy(&dst->tim, &src->tim, sizeof(struct ieee80211_tim_parameters));
2331 2331
2332 dst->bssht.bdSupportHT = src->bssht.bdSupportHT; 2332 dst->bssht.bdSupportHT = src->bssht.bdSupportHT;
2333 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation; 2333 dst->bssht.bdRT2RTAggregation = src->bssht.bdRT2RTAggregation;
2334 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen; 2334 dst->bssht.bdHTCapLen= src->bssht.bdHTCapLen;
2335 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen); 2335 memcpy(dst->bssht.bdHTCapBuf,src->bssht.bdHTCapBuf,src->bssht.bdHTCapLen);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index 7a0707810fd0..454f8895d211 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -498,7 +498,7 @@ void ieee80211_softmac_scan_wq(struct work_struct *work)
498{ 498{
499 struct delayed_work *dwork = container_of(work, struct delayed_work, work); 499 struct delayed_work *dwork = container_of(work, struct delayed_work, work);
500 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq); 500 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
501 static short watchdog = 0; 501 static short watchdog;
502 u8 channel_map[MAX_CHANNEL_NUMBER+1]; 502 u8 channel_map[MAX_CHANNEL_NUMBER+1];
503 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 503 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
504 if(!ieee->ieee_up) 504 if(!ieee->ieee_up)
@@ -1948,166 +1948,166 @@ ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1948 1948
1949 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) { 1949 switch (WLAN_FC_GET_STYPE(header->frame_ctl)) {
1950 1950
1951 case IEEE80211_STYPE_ASSOC_RESP: 1951 case IEEE80211_STYPE_ASSOC_RESP:
1952 case IEEE80211_STYPE_REASSOC_RESP: 1952 case IEEE80211_STYPE_REASSOC_RESP:
1953 1953
1954 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n", 1954 IEEE80211_DEBUG_MGMT("received [RE]ASSOCIATION RESPONSE (%d)\n",
1955 WLAN_FC_GET_STYPE(header->frame_ctl)); 1955 WLAN_FC_GET_STYPE(header->frame_ctl));
1956 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && 1956 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
1957 ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED && 1957 ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATED &&
1958 ieee->iw_mode == IW_MODE_INFRA){ 1958 ieee->iw_mode == IW_MODE_INFRA){
1959 struct ieee80211_network network_resp; 1959 struct ieee80211_network network_resp;
1960 struct ieee80211_network *network = &network_resp; 1960 struct ieee80211_network *network = &network_resp;
1961 1961
1962 if (0 == (errcode=assoc_parse(ieee,skb, &aid))){ 1962 if (0 == (errcode=assoc_parse(ieee,skb, &aid))){
1963 ieee->state=IEEE80211_LINKED; 1963 ieee->state=IEEE80211_LINKED;
1964 ieee->assoc_id = aid; 1964 ieee->assoc_id = aid;
1965 ieee->softmac_stats.rx_ass_ok++; 1965 ieee->softmac_stats.rx_ass_ok++;
1966 /* station support qos */ 1966 /* station support qos */
1967 /* Let the register setting defaultly with Legacy station */ 1967 /* Let the register setting defaultly with Legacy station */
1968 if(ieee->qos_support) { 1968 if(ieee->qos_support) {
1969 assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data; 1969 assoc_resp = (struct ieee80211_assoc_response_frame*)skb->data;
1970 memset(network, 0, sizeof(*network)); 1970 memset(network, 0, sizeof(*network));
1971 if (ieee80211_parse_info_param(ieee,assoc_resp->info_element,\ 1971 if (ieee80211_parse_info_param(ieee,assoc_resp->info_element,\
1972 rx_stats->len - sizeof(*assoc_resp),\ 1972 rx_stats->len - sizeof(*assoc_resp),\
1973 network,rx_stats)){ 1973 network,rx_stats)){
1974 return 1; 1974 return 1;
1975 }
1976 else
1977 { //filling the PeerHTCap. //maybe not necessary as we can get its info from current_network.
1978 memcpy(ieee->pHTInfo->PeerHTCapBuf, network->bssht.bdHTCapBuf, network->bssht.bdHTCapLen);
1979 memcpy(ieee->pHTInfo->PeerHTInfoBuf, network->bssht.bdHTInfoBuf, network->bssht.bdHTInfoLen);
1980 }
1981 if (ieee->handle_assoc_response != NULL)
1982 ieee->handle_assoc_response(ieee->dev, (struct ieee80211_assoc_response_frame*)header, network);
1983 } 1975 }
1984 ieee80211_associate_complete(ieee); 1976 else
1985 } else { 1977 { //filling the PeerHTCap. //maybe not necessary as we can get its info from current_network.
1986 /* aid could not been allocated */ 1978 memcpy(ieee->pHTInfo->PeerHTCapBuf, network->bssht.bdHTCapBuf, network->bssht.bdHTCapLen);
1987 ieee->softmac_stats.rx_ass_err++; 1979 memcpy(ieee->pHTInfo->PeerHTInfoBuf, network->bssht.bdHTInfoBuf, network->bssht.bdHTInfoLen);
1988 printk(
1989 "Association response status code 0x%x\n",
1990 errcode);
1991 IEEE80211_DEBUG_MGMT(
1992 "Association response status code 0x%x\n",
1993 errcode);
1994 if(ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT) {
1995 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1996 } else {
1997 ieee80211_associate_abort(ieee);
1998 } 1980 }
1981 if (ieee->handle_assoc_response != NULL)
1982 ieee->handle_assoc_response(ieee->dev, (struct ieee80211_assoc_response_frame*)header, network);
1983 }
1984 ieee80211_associate_complete(ieee);
1985 } else {
1986 /* aid could not been allocated */
1987 ieee->softmac_stats.rx_ass_err++;
1988 printk(
1989 "Association response status code 0x%x\n",
1990 errcode);
1991 IEEE80211_DEBUG_MGMT(
1992 "Association response status code 0x%x\n",
1993 errcode);
1994 if(ieee->AsocRetryCount < RT_ASOC_RETRY_LIMIT) {
1995 queue_work(ieee->wq, &ieee->associate_procedure_wq);
1996 } else {
1997 ieee80211_associate_abort(ieee);
1999 } 1998 }
2000 } 1999 }
2001 break; 2000 }
2001 break;
2002 2002
2003 case IEEE80211_STYPE_ASSOC_REQ: 2003 case IEEE80211_STYPE_ASSOC_REQ:
2004 case IEEE80211_STYPE_REASSOC_REQ: 2004 case IEEE80211_STYPE_REASSOC_REQ:
2005 2005
2006 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && 2006 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2007 ieee->iw_mode == IW_MODE_MASTER) 2007 ieee->iw_mode == IW_MODE_MASTER)
2008 2008
2009 ieee80211_rx_assoc_rq(ieee, skb); 2009 ieee80211_rx_assoc_rq(ieee, skb);
2010 break; 2010 break;
2011 2011
2012 case IEEE80211_STYPE_AUTH: 2012 case IEEE80211_STYPE_AUTH:
2013 2013
2014 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){ 2014 if (ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE){
2015 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING && 2015 if (ieee->state == IEEE80211_ASSOCIATING_AUTHENTICATING &&
2016 ieee->iw_mode == IW_MODE_INFRA){ 2016 ieee->iw_mode == IW_MODE_INFRA){
2017 2017
2018 IEEE80211_DEBUG_MGMT("Received authentication response"); 2018 IEEE80211_DEBUG_MGMT("Received authentication response");
2019 2019
2020 if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){ 2020 if (0 == (errcode=auth_parse(skb, &challenge, &chlen))){
2021 if(ieee->open_wep || !challenge){ 2021 if(ieee->open_wep || !challenge){
2022 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED; 2022 ieee->state = IEEE80211_ASSOCIATING_AUTHENTICATED;
2023 ieee->softmac_stats.rx_auth_rs_ok++; 2023 ieee->softmac_stats.rx_auth_rs_ok++;
2024 if(!(ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE)) 2024 if(!(ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE))
2025 {
2026 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev))
2025 { 2027 {
2026 if (!ieee->GetNmodeSupportBySecCfg(ieee->dev)) 2028 // WEP or TKIP encryption
2029 if(IsHTHalfNmodeAPs(ieee))
2027 { 2030 {
2028 // WEP or TKIP encryption 2031 bSupportNmode = true;
2029 if(IsHTHalfNmodeAPs(ieee)) 2032 bHalfSupportNmode = true;
2030 {
2031 bSupportNmode = true;
2032 bHalfSupportNmode = true;
2033 }
2034 else
2035 {
2036 bSupportNmode = false;
2037 bHalfSupportNmode = false;
2038 }
2039 printk("==========>to link with AP using SEC(%d, %d)", bSupportNmode, bHalfSupportNmode);
2040 } 2033 }
2034 else
2035 {
2036 bSupportNmode = false;
2037 bHalfSupportNmode = false;
2038 }
2039 printk("==========>to link with AP using SEC(%d, %d)", bSupportNmode, bHalfSupportNmode);
2041 } 2040 }
2042 /* Dummy wirless mode setting to avoid encryption issue */ 2041 }
2043 if(bSupportNmode) { 2042 /* Dummy wirless mode setting to avoid encryption issue */
2044 //N mode setting 2043 if(bSupportNmode) {
2045 ieee->SetWirelessMode(ieee->dev, \ 2044 //N mode setting
2046 ieee->current_network.mode); 2045 ieee->SetWirelessMode(ieee->dev, \
2047 }else{ 2046 ieee->current_network.mode);
2048 //b/g mode setting
2049 /*TODO*/
2050 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2051 }
2052
2053 if (ieee->current_network.mode == IEEE_N_24G && bHalfSupportNmode == true)
2054 {
2055 printk("===============>entern half N mode\n");
2056 ieee->bHalfWirelessN24GMode = true;
2057 }
2058 else
2059 ieee->bHalfWirelessN24GMode = false;
2060
2061 ieee80211_associate_step2(ieee);
2062 }else{ 2047 }else{
2063 ieee80211_auth_challenge(ieee, challenge, chlen); 2048 //b/g mode setting
2049 /*TODO*/
2050 ieee->SetWirelessMode(ieee->dev, IEEE_G);
2064 } 2051 }
2052
2053 if (ieee->current_network.mode == IEEE_N_24G && bHalfSupportNmode == true)
2054 {
2055 printk("===============>entern half N mode\n");
2056 ieee->bHalfWirelessN24GMode = true;
2057 }
2058 else
2059 ieee->bHalfWirelessN24GMode = false;
2060
2061 ieee80211_associate_step2(ieee);
2065 }else{ 2062 }else{
2066 ieee->softmac_stats.rx_auth_rs_err++; 2063 ieee80211_auth_challenge(ieee, challenge, chlen);
2067 IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x",errcode);
2068 ieee80211_associate_abort(ieee);
2069 } 2064 }
2070 2065 }else{
2071 }else if (ieee->iw_mode == IW_MODE_MASTER){ 2066 ieee->softmac_stats.rx_auth_rs_err++;
2072 ieee80211_rx_auth_rq(ieee, skb); 2067 IEEE80211_DEBUG_MGMT("Authentication response status code 0x%x",errcode);
2068 ieee80211_associate_abort(ieee);
2073 } 2069 }
2070
2071 }else if (ieee->iw_mode == IW_MODE_MASTER){
2072 ieee80211_rx_auth_rq(ieee, skb);
2074 } 2073 }
2075 break; 2074 }
2075 break;
2076 2076
2077 case IEEE80211_STYPE_PROBE_REQ: 2077 case IEEE80211_STYPE_PROBE_REQ:
2078 2078
2079 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) && 2079 if ((ieee->softmac_features & IEEE_SOFTMAC_PROBERS) &&
2080 ((ieee->iw_mode == IW_MODE_ADHOC || 2080 ((ieee->iw_mode == IW_MODE_ADHOC ||
2081 ieee->iw_mode == IW_MODE_MASTER) && 2081 ieee->iw_mode == IW_MODE_MASTER) &&
2082 ieee->state == IEEE80211_LINKED)){ 2082 ieee->state == IEEE80211_LINKED)){
2083 ieee80211_rx_probe_rq(ieee, skb); 2083 ieee80211_rx_probe_rq(ieee, skb);
2084 } 2084 }
2085 break; 2085 break;
2086 2086
2087 case IEEE80211_STYPE_DISASSOC: 2087 case IEEE80211_STYPE_DISASSOC:
2088 case IEEE80211_STYPE_DEAUTH: 2088 case IEEE80211_STYPE_DEAUTH:
2089 /* FIXME for now repeat all the association procedure 2089 /* FIXME for now repeat all the association procedure
2090 * both for disassociation and deauthentication 2090 * both for disassociation and deauthentication
2091 */ 2091 */
2092 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) && 2092 if ((ieee->softmac_features & IEEE_SOFTMAC_ASSOCIATE) &&
2093 ieee->state == IEEE80211_LINKED && 2093 ieee->state == IEEE80211_LINKED &&
2094 ieee->iw_mode == IW_MODE_INFRA){ 2094 ieee->iw_mode == IW_MODE_INFRA){
2095 2095
2096 ieee->state = IEEE80211_ASSOCIATING; 2096 ieee->state = IEEE80211_ASSOCIATING;
2097 ieee->softmac_stats.reassoc++; 2097 ieee->softmac_stats.reassoc++;
2098 2098
2099 notify_wx_assoc_event(ieee); 2099 notify_wx_assoc_event(ieee);
2100 //HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT); 2100 //HTSetConnectBwMode(ieee, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
2101 RemovePeerTS(ieee, header->addr2); 2101 RemovePeerTS(ieee, header->addr2);
2102 queue_work(ieee->wq, &ieee->associate_procedure_wq); 2102 queue_work(ieee->wq, &ieee->associate_procedure_wq);
2103 } 2103 }
2104 break; 2104 break;
2105 case IEEE80211_STYPE_MANAGE_ACT: 2105 case IEEE80211_STYPE_MANAGE_ACT:
2106 ieee80211_process_action(ieee,skb); 2106 ieee80211_process_action(ieee,skb);
2107 break; 2107 break;
2108 default: 2108 default:
2109 return -1; 2109 return -1;
2110 break; 2110 break;
2111 } 2111 }
2112 2112
2113 //dev_kfree_skb_any(skb); 2113 //dev_kfree_skb_any(skb);
@@ -2503,8 +2503,8 @@ void ieee80211_disassociate(struct ieee80211_device *ieee)
2503} 2503}
2504void ieee80211_associate_retry_wq(struct work_struct *work) 2504void ieee80211_associate_retry_wq(struct work_struct *work)
2505{ 2505{
2506 struct delayed_work *dwork = container_of(work, struct delayed_work, work); 2506 struct delayed_work *dwork = container_of(work, struct delayed_work, work);
2507 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq); 2507 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
2508 unsigned long flags; 2508 unsigned long flags;
2509 2509
2510 down(&ieee->wx_sem); 2510 down(&ieee->wx_sem);
@@ -3124,7 +3124,7 @@ inline struct sk_buff *ieee80211_disassociate_skb(
3124void 3124void
3125SendDisassociation( 3125SendDisassociation(
3126 struct ieee80211_device *ieee, 3126 struct ieee80211_device *ieee,
3127 u8* asSta, 3127 u8* asSta,
3128 u8 asRsn 3128 u8 asRsn
3129) 3129)
3130{ 3130{
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
index 421da8a07697..60746b8b1eb0 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
@@ -302,7 +302,7 @@ void ieee80211_wx_sync_scan_wq(struct work_struct *work)
302 HT_EXTCHNL_OFFSET chan_offset=0; 302 HT_EXTCHNL_OFFSET chan_offset=0;
303 HT_CHANNEL_WIDTH bandwidth=0; 303 HT_CHANNEL_WIDTH bandwidth=0;
304 int b40M = 0; 304 int b40M = 0;
305 static int count = 0; 305 static int count;
306 chan = ieee->current_network.channel; 306 chan = ieee->current_network.channel;
307 netif_carrier_off(ieee->dev); 307 netif_carrier_off(ieee->dev);
308 308
@@ -482,22 +482,23 @@ int ieee80211_wx_get_name(struct ieee80211_device *ieee,
482 struct iw_request_info *info, 482 struct iw_request_info *info,
483 union iwreq_data *wrqu, char *extra) 483 union iwreq_data *wrqu, char *extra)
484{ 484{
485 strcpy(wrqu->name, "802.11"); 485 strlcpy(wrqu->name, "802.11", IFNAMSIZ);
486 if(ieee->modulation & IEEE80211_CCK_MODULATION){ 486 if (ieee->modulation & IEEE80211_CCK_MODULATION) {
487 strcat(wrqu->name, "b"); 487 strlcat(wrqu->name, "b", IFNAMSIZ);
488 if(ieee->modulation & IEEE80211_OFDM_MODULATION) 488 if (ieee->modulation & IEEE80211_OFDM_MODULATION)
489 strcat(wrqu->name, "/g"); 489 strlcat(wrqu->name, "/g", IFNAMSIZ);
490 }else if(ieee->modulation & IEEE80211_OFDM_MODULATION) 490 } else if (ieee->modulation & IEEE80211_OFDM_MODULATION) {
491 strcat(wrqu->name, "g"); 491 strlcat(wrqu->name, "g", IFNAMSIZ);
492 if (ieee->mode & (IEEE_N_24G | IEEE_N_5G)) 492 }
493 strcat(wrqu->name, "/n");
494 493
495 if((ieee->state == IEEE80211_LINKED) || 494 if (ieee->mode & (IEEE_N_24G | IEEE_N_5G))
496 (ieee->state == IEEE80211_LINKED_SCANNING)) 495 strlcat(wrqu->name, "/n", IFNAMSIZ);
497 strcat(wrqu->name," linked");
498 else if(ieee->state != IEEE80211_NOLINK)
499 strcat(wrqu->name," link..");
500 496
497 if ((ieee->state == IEEE80211_LINKED) ||
498 (ieee->state == IEEE80211_LINKED_SCANNING))
499 strlcat(wrqu->name, " linked", IFNAMSIZ);
500 else if (ieee->state != IEEE80211_NOLINK)
501 strlcat(wrqu->name, " link..", IFNAMSIZ);
501 502
502 return 0; 503 return 0;
503} 504}
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 3f5ceeb88b6c..c39e680bb0ac 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -70,7 +70,7 @@ val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x
70desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep | 70desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep |
71 | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | | 71 | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | |
72 '-----------------------------------------------------------------------------------------' 72 '-----------------------------------------------------------------------------------------'
73 /\ 73 /\
74 | 74 |
75802.11 Data Frame | 75802.11 Data Frame |
76 ,--------- 'ctrl' expands to >-----------' 76 ,--------- 'ctrl' expands to >-----------'
@@ -283,22 +283,22 @@ ieee80211_classify(struct sk_buff *skb, struct ieee80211_network *network)
283// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len); 283// IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, skb->data, skb->len);
284 ip = ip_hdr(skb); 284 ip = ip_hdr(skb);
285 switch (ip->tos & 0xfc) { 285 switch (ip->tos & 0xfc) {
286 case 0x20: 286 case 0x20:
287 return 2; 287 return 2;
288 case 0x40: 288 case 0x40:
289 return 1; 289 return 1;
290 case 0x60: 290 case 0x60:
291 return 3; 291 return 3;
292 case 0x80: 292 case 0x80:
293 return 4; 293 return 4;
294 case 0xa0: 294 case 0xa0:
295 return 5; 295 return 5;
296 case 0xc0: 296 case 0xc0:
297 return 6; 297 return 6;
298 case 0xe0: 298 case 0xe0:
299 return 7; 299 return 7;
300 default: 300 default:
301 return 0; 301 return 0;
302 } 302 }
303} 303}
304 304
@@ -395,7 +395,7 @@ ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, cb_desc *tcb_desc)
395{ 395{
396 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 396 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
397 397
398 tcb_desc->bUseShortGI = false; 398 tcb_desc->bUseShortGI = false;
399 399
400 if(!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT) 400 if(!pHTInfo->bCurrentHTSupport||!pHTInfo->bEnableHT)
401 return; 401 return;
@@ -514,7 +514,7 @@ void ieee80211_query_protectionmode(struct ieee80211_device* ieee, cb_desc* tcb_
514 if(pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF) 514 if(pHTInfo->IOTAction & HT_IOT_ACT_FORCED_CTS2SELF)
515 { 515 {
516 tcb_desc->bCTSEnable = true; 516 tcb_desc->bCTSEnable = true;
517 tcb_desc->rts_rate = MGN_24M; 517 tcb_desc->rts_rate = MGN_24M;
518 tcb_desc->bRTSEnable = true; 518 tcb_desc->bRTSEnable = true;
519 break; 519 break;
520 } 520 }
@@ -527,7 +527,7 @@ void ieee80211_query_protectionmode(struct ieee80211_device* ieee, cb_desc* tcb_
527 { 527 {
528 tcb_desc->bCTSEnable = true; 528 tcb_desc->bCTSEnable = true;
529 tcb_desc->rts_rate = MGN_24M; 529 tcb_desc->rts_rate = MGN_24M;
530 tcb_desc->bRTSEnable = true; 530 tcb_desc->bRTSEnable = true;
531 } 531 }
532 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE) 532 if (ieee->current_network.capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
533 tcb_desc->bUseShortPreamble = true; 533 tcb_desc->bUseShortPreamble = true;
@@ -656,17 +656,17 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
656 memcpy(&dest, skb->data, ETH_ALEN); 656 memcpy(&dest, skb->data, ETH_ALEN);
657 memcpy(&src, skb->data+ETH_ALEN, ETH_ALEN); 657 memcpy(&src, skb->data+ETH_ALEN, ETH_ALEN);
658 658
659 /* Advance the SKB to the start of the payload */ 659 /* Advance the SKB to the start of the payload */
660 skb_pull(skb, sizeof(struct ethhdr)); 660 skb_pull(skb, sizeof(struct ethhdr));
661 661
662 /* Determine total amount of storage required for TXB packets */ 662 /* Determine total amount of storage required for TXB packets */
663 bytes = skb->len + SNAP_SIZE + sizeof(u16); 663 bytes = skb->len + SNAP_SIZE + sizeof(u16);
664 664
665 if (encrypt) 665 if (encrypt)
666 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_WEP; 666 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_WEP;
667 else 667 else
668 668
669 fc = IEEE80211_FTYPE_DATA; 669 fc = IEEE80211_FTYPE_DATA;
670 670
671 //if(ieee->current_network.QoS_Enable) 671 //if(ieee->current_network.QoS_Enable)
672 if(qos_actived) 672 if(qos_actived)
@@ -689,7 +689,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
689 memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN); 689 memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN);
690 } 690 }
691 691
692 header.frame_ctl = cpu_to_le16(fc); 692 header.frame_ctl = cpu_to_le16(fc);
693 693
694 /* Determine fragmentation size based on destination (multicast 694 /* Determine fragmentation size based on destination (multicast
695 * and broadcast are not fragmented) */ 695 * and broadcast are not fragmented) */
@@ -833,7 +833,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
833 else 833 else
834 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++; 834 ieee->seq_ctrl[UP2AC(skb->priority) + 1]++;
835 } else { 835 } else {
836 if (ieee->seq_ctrl[0] == 0xFFF) 836 if (ieee->seq_ctrl[0] == 0xFFF)
837 ieee->seq_ctrl[0] = 0; 837 ieee->seq_ctrl[0] = 0;
838 else 838 else
839 ieee->seq_ctrl[0]++; 839 ieee->seq_ctrl[0]++;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
index f0ba7f467493..e1fe54acb4b8 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
@@ -761,7 +761,7 @@ int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
761 case IW_MLME_DISASSOC: 761 case IW_MLME_DISASSOC:
762 ieee80211_disassociate(ieee); 762 ieee80211_disassociate(ieee);
763 break; 763 break;
764 default: 764 default:
765 return -EOPNOTSUPP; 765 return -EOPNOTSUPP;
766 } 766 }
767 return 0; 767 return 0;
diff --git a/drivers/staging/rtl8192u/ieee80211/internal.h b/drivers/staging/rtl8192u/ieee80211/internal.h
index bebe13ac53b7..6f54cfe8a467 100644
--- a/drivers/staging/rtl8192u/ieee80211/internal.h
+++ b/drivers/staging/rtl8192u/ieee80211/internal.h
@@ -79,4 +79,3 @@ void crypto_exit_cipher_ops(struct crypto_tfm *tfm);
79void crypto_exit_compress_ops(struct crypto_tfm *tfm); 79void crypto_exit_compress_ops(struct crypto_tfm *tfm);
80 80
81#endif /* _CRYPTO_INTERNAL_H */ 81#endif /* _CRYPTO_INTERNAL_H */
82
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h
index 8ddc8bf9dc26..2c398ca9a8ac 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BA.h
@@ -1,7 +1,7 @@
1#ifndef _BATYPE_H_ 1#ifndef _BATYPE_H_
2#define _BATYPE_H_ 2#define _BATYPE_H_
3 3
4#define TOTAL_TXBA_NUM 16 4#define TOTAL_TXBA_NUM 16
5#define TOTAL_RXBA_NUM 16 5#define TOTAL_RXBA_NUM 16
6 6
7#define BA_SETUP_TIMEOUT 200 7#define BA_SETUP_TIMEOUT 200
@@ -28,8 +28,7 @@ struct ieee80211_ADDBA_Req{
28//Is this need?I put here just to make it easier to define structure BA_RECORD //WB 28//Is this need?I put here just to make it easier to define structure BA_RECORD //WB
29typedef union _SEQUENCE_CONTROL{ 29typedef union _SEQUENCE_CONTROL{
30 u16 ShortData; 30 u16 ShortData;
31 struct 31 struct {
32 {
33 u16 FragNum:4; 32 u16 FragNum:4;
34 u16 SeqNum:12; 33 u16 SeqNum:12;
35 }field; 34 }field;
@@ -66,4 +65,3 @@ typedef struct _BA_RECORD {
66} BA_RECORD, *PBA_RECORD; 65} BA_RECORD, *PBA_RECORD;
67 66
68#endif //end _BATYPE_H_ 67#endif //end _BATYPE_H_
69
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
index 1ebea3daea2d..69735d320315 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
@@ -9,8 +9,8 @@
9 9
10/******************************************************************************************************************** 10/********************************************************************************************************************
11 *function: Activate BA entry. And if Time is nozero, start timer. 11 *function: Activate BA entry. And if Time is nozero, start timer.
12 * input: PBA_RECORD pBA //BA entry to be enabled 12 * input: PBA_RECORD pBA //BA entry to be enabled
13 * u16 Time //indicate time delay. 13 * u16 Time //indicate time delay.
14 * output: none 14 * output: none
15********************************************************************************************************************/ 15********************************************************************************************************************/
16void ActivateBAEntry(struct ieee80211_device* ieee, PBA_RECORD pBA, u16 Time) 16void ActivateBAEntry(struct ieee80211_device* ieee, PBA_RECORD pBA, u16 Time)
@@ -22,7 +22,7 @@ void ActivateBAEntry(struct ieee80211_device* ieee, PBA_RECORD pBA, u16 Time)
22 22
23/******************************************************************************************************************** 23/********************************************************************************************************************
24 *function: deactivate BA entry, including its timer. 24 *function: deactivate BA entry, including its timer.
25 * input: PBA_RECORD pBA //BA entry to be disabled 25 * input: PBA_RECORD pBA //BA entry to be disabled
26 * output: none 26 * output: none
27********************************************************************************************************************/ 27********************************************************************************************************************/
28void DeActivateBAEntry( struct ieee80211_device* ieee, PBA_RECORD pBA) 28void DeActivateBAEntry( struct ieee80211_device* ieee, PBA_RECORD pBA)
@@ -33,7 +33,7 @@ void DeActivateBAEntry( struct ieee80211_device* ieee, PBA_RECORD pBA)
33/******************************************************************************************************************** 33/********************************************************************************************************************
34 *function: deactivete BA entry in Tx Ts, and send DELBA. 34 *function: deactivete BA entry in Tx Ts, and send DELBA.
35 * input: 35 * input:
36 * PTX_TS_RECORD pTxTs //Tx Ts which is to deactivate BA entry. 36 * PTX_TS_RECORD pTxTs //Tx Ts which is to deactivate BA entry.
37 * output: none 37 * output: none
38 * notice: As PTX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME 38 * notice: As PTX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME
39********************************************************************************************************************/ 39********************************************************************************************************************/
@@ -63,7 +63,7 @@ u8 TxTsDeleteBA( struct ieee80211_device* ieee, PTX_TS_RECORD pTxTs)
63/******************************************************************************************************************** 63/********************************************************************************************************************
64 *function: deactivete BA entry in Tx Ts, and send DELBA. 64 *function: deactivete BA entry in Tx Ts, and send DELBA.
65 * input: 65 * input:
66 * PRX_TS_RECORD pRxTs //Rx Ts which is to deactivate BA entry. 66 * PRX_TS_RECORD pRxTs //Rx Ts which is to deactivate BA entry.
67 * output: none 67 * output: none
68 * notice: As PRX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME, same with above 68 * notice: As PRX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME, same with above
69********************************************************************************************************************/ 69********************************************************************************************************************/
@@ -84,7 +84,7 @@ u8 RxTsDeleteBA( struct ieee80211_device* ieee, PRX_TS_RECORD pRxTs)
84/******************************************************************************************************************** 84/********************************************************************************************************************
85 *function: reset BA entry 85 *function: reset BA entry
86 * input: 86 * input:
87 * PBA_RECORD pBA //entry to be reset 87 * PBA_RECORD pBA //entry to be reset
88 * output: none 88 * output: none
89********************************************************************************************************************/ 89********************************************************************************************************************/
90void ResetBaEntry( PBA_RECORD pBA) 90void ResetBaEntry( PBA_RECORD pBA)
@@ -98,12 +98,12 @@ void ResetBaEntry( PBA_RECORD pBA)
98//These functions need porting here or not? 98//These functions need porting here or not?
99/******************************************************************************************************************************* 99/*******************************************************************************************************************************
100 *function: construct ADDBAREQ and ADDBARSP frame here together. 100 *function: construct ADDBAREQ and ADDBARSP frame here together.
101 * input: u8* Dst //ADDBA frame's destination 101 * input: u8* Dst //ADDBA frame's destination
102 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA. 102 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA.
103 * u16 StatusCode //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?) 103 * u16 StatusCode //status code in RSP and I will use it to indicate whether it's RSP or REQ(will I?)
104 * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ) 104 * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ)
105 * output: none 105 * output: none
106 * return: sk_buff* skb //return constructed skb to xmit 106 * return: sk_buff* skb //return constructed skb to xmit
107*******************************************************************************************************************************/ 107*******************************************************************************************************************************/
108static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, PBA_RECORD pBA, u16 StatusCode, u8 type) 108static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, PBA_RECORD pBA, u16 StatusCode, u8 type)
109{ 109{
@@ -126,7 +126,7 @@ static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, P
126 return NULL; 126 return NULL;
127 } 127 }
128 128
129 memset(skb->data, 0, sizeof( struct ieee80211_hdr_3addr)); //I wonder whether it's necessary. Apparently kernel will not do it when alloc a skb. 129 memset(skb->data, 0, sizeof( struct ieee80211_hdr_3addr)); //I wonder whether it's necessary. Apparently kernel will not do it when alloc a skb.
130 skb_reserve(skb, ieee->tx_headroom); 130 skb_reserve(skb, ieee->tx_headroom);
131 131
132 BAReq = ( struct ieee80211_hdr_3addr *) skb_put(skb,sizeof( struct ieee80211_hdr_3addr)); 132 BAReq = ( struct ieee80211_hdr_3addr *) skb_put(skb,sizeof( struct ieee80211_hdr_3addr));
@@ -177,12 +177,12 @@ static struct sk_buff* ieee80211_ADDBA(struct ieee80211_device* ieee, u8* Dst, P
177 177
178/******************************************************************************************************************** 178/********************************************************************************************************************
179 *function: construct DELBA frame 179 *function: construct DELBA frame
180 * input: u8* dst //DELBA frame's destination 180 * input: u8* dst //DELBA frame's destination
181 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 181 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA
182 * TR_SELECT TxRxSelect //TX RX direction 182 * TR_SELECT TxRxSelect //TX RX direction
183 * u16 ReasonCode //status code. 183 * u16 ReasonCode //status code.
184 * output: none 184 * output: none
185 * return: sk_buff* skb //return constructed skb to xmit 185 * return: sk_buff* skb //return constructed skb to xmit
186********************************************************************************************************************/ 186********************************************************************************************************************/
187static struct sk_buff* ieee80211_DELBA( 187static struct sk_buff* ieee80211_DELBA(
188 struct ieee80211_device* ieee, 188 struct ieee80211_device* ieee,
@@ -246,8 +246,8 @@ static struct sk_buff* ieee80211_DELBA(
246 246
247/******************************************************************************************************************** 247/********************************************************************************************************************
248 *function: send ADDBAReq frame out 248 *function: send ADDBAReq frame out
249 * input: u8* dst //ADDBAReq frame's destination 249 * input: u8* dst //ADDBAReq frame's destination
250 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 250 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA
251 * output: none 251 * output: none
252 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 252 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
253********************************************************************************************************************/ 253********************************************************************************************************************/
@@ -272,9 +272,9 @@ void ieee80211_send_ADDBAReq(struct ieee80211_device* ieee, u8* dst, PBA_RECORD
272 272
273/******************************************************************************************************************** 273/********************************************************************************************************************
274 *function: send ADDBARSP frame out 274 *function: send ADDBARSP frame out
275 * input: u8* dst //DELBA frame's destination 275 * input: u8* dst //DELBA frame's destination
276 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 276 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA
277 * u16 StatusCode //RSP StatusCode 277 * u16 StatusCode //RSP StatusCode
278 * output: none 278 * output: none
279 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 279 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
280********************************************************************************************************************/ 280********************************************************************************************************************/
@@ -297,10 +297,10 @@ void ieee80211_send_ADDBARsp(struct ieee80211_device* ieee, u8* dst, PBA_RECORD
297} 297}
298/******************************************************************************************************************** 298/********************************************************************************************************************
299 *function: send ADDBARSP frame out 299 *function: send ADDBARSP frame out
300 * input: u8* dst //DELBA frame's destination 300 * input: u8* dst //DELBA frame's destination
301 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 301 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA
302 * TR_SELECT TxRxSelect //TX or RX 302 * TR_SELECT TxRxSelect //TX or RX
303 * u16 ReasonCode //DEL ReasonCode 303 * u16 ReasonCode //DEL ReasonCode
304 * output: none 304 * output: none
305 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 305 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
306********************************************************************************************************************/ 306********************************************************************************************************************/
@@ -340,7 +340,7 @@ int ieee80211_rx_ADDBAReq( struct ieee80211_device* ieee, struct sk_buff *skb)
340 340
341 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9) 341 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9)
342 { 342 {
343 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BAREQ(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9)); 343 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BAREQ(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9));
344 return -1; 344 return -1;
345 } 345 }
346 346
@@ -439,7 +439,7 @@ int ieee80211_rx_ADDBARsp( struct ieee80211_device* ieee, struct sk_buff *skb)
439 439
440 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9) 440 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9)
441 { 441 {
442 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BARSP(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9)); 442 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in BARSP(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 9));
443 return -1; 443 return -1;
444 } 444 }
445 rsp = ( struct ieee80211_hdr_3addr*)skb->data; 445 rsp = ( struct ieee80211_hdr_3addr*)skb->data;
@@ -569,7 +569,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device* ieee,struct sk_buff *skb)
569 569
570 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 6) 570 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 6)
571 { 571 {
572 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in DELBA(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 6)); 572 IEEE80211_DEBUG(IEEE80211_DL_ERR, " Invalid skb len in DELBA(%d / %zu)\n", skb->len, (sizeof( struct ieee80211_hdr_3addr) + 6));
573 return -1; 573 return -1;
574 } 574 }
575 575
@@ -589,7 +589,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device* ieee,struct sk_buff *skb)
589 589
590 if(pDelBaParamSet->field.Initiator == 1) 590 if(pDelBaParamSet->field.Initiator == 1)
591 { 591 {
592 PRX_TS_RECORD pRxTs; 592 PRX_TS_RECORD pRxTs;
593 593
594 if( !GetTs( 594 if( !GetTs(
595 ieee, 595 ieee,
@@ -657,7 +657,7 @@ TsInitAddBA(
657 // BufferSize: This need to be set according to A-MPDU vector 657 // BufferSize: This need to be set according to A-MPDU vector
658 pBA->BaParamSet.field.BufferSize = 32; // BufferSize: This need to be set according to A-MPDU vector 658 pBA->BaParamSet.field.BufferSize = 32; // BufferSize: This need to be set according to A-MPDU vector
659 pBA->BaTimeoutValue = 0; // Timeout value: Set 0 to disable Timer 659 pBA->BaTimeoutValue = 0; // Timeout value: Set 0 to disable Timer
660 pBA->BaStartSeqCtrl.field.SeqNum = (pTS->TxCurSeq + 3) % 4096; // Block Ack will start after 3 packets later. 660 pBA->BaStartSeqCtrl.field.SeqNum = (pTS->TxCurSeq + 3) % 4096; // Block Ack will start after 3 packets later.
661 661
662 ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT); 662 ActivateBAEntry(ieee, pBA, BA_SETUP_TIMEOUT);
663 663
@@ -734,4 +734,3 @@ void RxBaInactTimeout(unsigned long data)
734 DELBA_REASON_TIMEOUT); 734 DELBA_REASON_TIMEOUT);
735 return ; 735 return ;
736} 736}
737
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
index a60b39cdb472..2b8283534be4 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
@@ -121,7 +121,7 @@ typedef union _HT_CAPABILITY_MACPARA{
121 121
122typedef enum _HT_ACTION{ 122typedef enum _HT_ACTION{
123 ACT_RECOMMAND_WIDTH = 0, 123 ACT_RECOMMAND_WIDTH = 0,
124 ACT_MIMO_PWR_SAVE = 1, 124 ACT_MIMO_PWR_SAVE = 1,
125 ACT_PSMP = 2, 125 ACT_PSMP = 2,
126 ACT_SET_PCO_PHASE = 3, 126 ACT_SET_PCO_PHASE = 3,
127 ACT_MIMO_CHL_MEASURE = 4, 127 ACT_MIMO_CHL_MEASURE = 4,
@@ -398,9 +398,9 @@ typedef struct _BSS_HT{
398typedef struct _MIMO_RSSI{ 398typedef struct _MIMO_RSSI{
399 u32 EnableAntenna; 399 u32 EnableAntenna;
400 u32 AntennaA; 400 u32 AntennaA;
401 u32 AntennaB; 401 u32 AntennaB;
402 u32 AntennaC; 402 u32 AntennaC;
403 u32 AntennaD; 403 u32 AntennaD;
404 u32 Average; 404 u32 Average;
405}MIMO_RSSI, *PMIMO_RSSI; 405}MIMO_RSSI, *PMIMO_RSSI;
406 406
@@ -436,11 +436,11 @@ extern u8 MCS_FILTER_1SS[16];
436 436
437 437
438// MCS Bw 40 {1~7, 12~15,32} 438// MCS Bw 40 {1~7, 12~15,32}
439#define RATE_ADPT_1SS_MASK 0xFF 439#define RATE_ADPT_1SS_MASK 0xFF
440#define RATE_ADPT_2SS_MASK 0xF0 //Skip MCS8~11 because mcs7 > mcs6, 9, 10, 11. 2007.01.16 by Emily 440#define RATE_ADPT_2SS_MASK 0xF0 //Skip MCS8~11 because mcs7 > mcs6, 9, 10, 11. 2007.01.16 by Emily
441#define RATE_ADPT_MCS32_MASK 0x01 441#define RATE_ADPT_MCS32_MASK 0x01
442 442
443#define IS_11N_MCS_RATE(rate) (rate&0x80) 443#define IS_11N_MCS_RATE(rate) (rate&0x80)
444 444
445typedef enum _HT_AGGRE_SIZE{ 445typedef enum _HT_AGGRE_SIZE{
446 HT_AGG_SIZE_8K = 0, 446 HT_AGG_SIZE_8K = 0,
@@ -478,4 +478,3 @@ typedef enum _HT_IOT_ACTION{
478}HT_IOT_ACTION_E, *PHT_IOT_ACTION_E; 478}HT_IOT_ACTION_E, *PHT_IOT_ACTION_E;
479 479
480#endif //_RTL819XU_HTTYPE_H_ 480#endif //_RTL819XU_HTTYPE_H_
481
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
index ebb523904edc..268b270e9495 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
@@ -21,7 +21,7 @@ u16 MCS_DATA_RATE[2][2][77] =
21 81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648, 864, 972, 1080, 21 81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648, 864, 972, 1080,
22 12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324, 378, 378, 432, 324, 405, 22 12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324, 378, 378, 432, 324, 405,
23 405, 486, 567, 567, 648, 270, 324, 378, 324, 378, 432, 486, 432, 486, 540, 540, 23 405, 486, 567, 567, 648, 270, 324, 378, 324, 378, 432, 486, 432, 486, 540, 540,
24 594, 405, 486, 567, 486, 567, 648, 729, 648, 729, 810, 810, 891}, // Long GI, 40MHz 24 594, 405, 486, 567, 486, 567, 648, 729, 648, 729, 810, 810, 891}, // Long GI, 40MHz
25 {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, 25 {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600,
26 90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720, 960, 1080, 1200, 26 90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720, 960, 1080, 1200,
27 13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360, 420, 420, 480, 360, 450, 27 13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360, 420, 420, 480, 360, 450,
@@ -88,7 +88,7 @@ void HTUpdateDefaultSetting(struct ieee80211_device* ieee)
88 ieee->bTxDisableRateFallBack = 0; 88 ieee->bTxDisableRateFallBack = 0;
89 ieee->bTxUseDriverAssingedRate = 0; 89 ieee->bTxUseDriverAssingedRate = 0;
90 90
91#ifdef TO_DO_LIST 91#ifdef TO_DO_LIST
92 // 8190 only. Assign duration operation mode to firmware 92 // 8190 only. Assign duration operation mode to firmware
93 pMgntInfo->bTxEnableFwCalcDur = (BOOLEAN)pNdisCommon->bRegTxEnableFwCalcDur; 93 pMgntInfo->bTxEnableFwCalcDur = (BOOLEAN)pNdisCommon->bRegTxEnableFwCalcDur;
94#endif 94#endif
@@ -116,7 +116,7 @@ void HTUpdateDefaultSetting(struct ieee80211_device* ieee)
116/******************************************************************************************************************** 116/********************************************************************************************************************
117 *function: This function print out each field on HT capability IE mainly from (Beacon/ProbeRsp/AssocReq) 117 *function: This function print out each field on HT capability IE mainly from (Beacon/ProbeRsp/AssocReq)
118 * input: u8* CapIE //Capability IE to be printed out 118 * input: u8* CapIE //Capability IE to be printed out
119 * u8* TitleString //mainly print out caller function 119 * u8* TitleString //mainly print out caller function
120 * output: none 120 * output: none
121 * return: none 121 * return: none
122 * notice: Driver should not print out this message by default. 122 * notice: Driver should not print out this message by default.
@@ -125,7 +125,7 @@ void HTDebugHTCapability(u8* CapIE, u8* TitleString )
125{ 125{
126 126
127 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily 127 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily
128 PHT_CAPABILITY_ELE pCapELE; 128 PHT_CAPABILITY_ELE pCapELE;
129 129
130 if(!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap))) 130 if(!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap)))
131 { 131 {
@@ -153,7 +153,7 @@ void HTDebugHTCapability(u8* CapIE, u8* TitleString )
153/******************************************************************************************************************** 153/********************************************************************************************************************
154 *function: This function print out each field on HT Information IE mainly from (Beacon/ProbeRsp) 154 *function: This function print out each field on HT Information IE mainly from (Beacon/ProbeRsp)
155 * input: u8* InfoIE //Capability IE to be printed out 155 * input: u8* InfoIE //Capability IE to be printed out
156 * u8* TitleString //mainly print out caller function 156 * u8* TitleString //mainly print out caller function
157 * output: none 157 * output: none
158 * return: none 158 * return: none
159 * notice: Driver should not print out this message by default. 159 * notice: Driver should not print out this message by default.
@@ -217,7 +217,7 @@ void HTDebugHTInfo(u8* InfoIE, u8* TitleString)
217} 217}
218 218
219/* 219/*
220* Return: true if station in half n mode and AP supports 40 bw 220* Return: true if station in half n mode and AP supports 40 bw
221*/ 221*/
222bool IsHTHalfNmode40Bandwidth(struct ieee80211_device* ieee) 222bool IsHTHalfNmode40Bandwidth(struct ieee80211_device* ieee)
223{ 223{
@@ -228,7 +228,7 @@ bool IsHTHalfNmode40Bandwidth(struct ieee80211_device* ieee)
228 retValue = false; 228 retValue = false;
229 else if(pHTInfo->bRegBW40MHz == false) // station supports 40 bw 229 else if(pHTInfo->bRegBW40MHz == false) // station supports 40 bw
230 retValue = false; 230 retValue = false;
231 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode 231 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode
232 retValue = false; 232 retValue = false;
233 else if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw 233 else if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw
234 retValue = true; 234 retValue = true;
@@ -245,7 +245,7 @@ bool IsHTHalfNmodeSGI(struct ieee80211_device* ieee, bool is40MHz)
245 245
246 if(pHTInfo->bCurrentHTSupport == false ) // wireless is n mode 246 if(pHTInfo->bCurrentHTSupport == false ) // wireless is n mode
247 retValue = false; 247 retValue = false;
248 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode 248 else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) // station in half n mode
249 retValue = false; 249 retValue = false;
250 else if(is40MHz) // ap support 40 bw 250 else if(is40MHz) // ap support 40 bw
251 { 251 {
@@ -265,7 +265,7 @@ bool IsHTHalfNmodeSGI(struct ieee80211_device* ieee, bool is40MHz)
265 return retValue; 265 return retValue;
266} 266}
267 267
268u16 HTHalfMcsToDataRate(struct ieee80211_device* ieee, u8 nMcsRate) 268u16 HTHalfMcsToDataRate(struct ieee80211_device* ieee, u8 nMcsRate)
269{ 269{
270 270
271 u8 is40MHz; 271 u8 is40MHz;
@@ -291,8 +291,8 @@ u16 HTMcsToDataRate( struct ieee80211_device* ieee, u8 nMcsRate)
291 291
292/******************************************************************************************************************** 292/********************************************************************************************************************
293 *function: This function returns current datarate. 293 *function: This function returns current datarate.
294 * input: struct ieee80211_device* ieee 294 * input: struct ieee80211_device* ieee
295 * u8 nDataRate 295 * u8 nDataRate
296 * output: none 296 * output: none
297 * return: tx rate 297 * return: tx rate
298 * notice: quite unsure about how to use this function //wb 298 * notice: quite unsure about how to use this function //wb
@@ -371,7 +371,7 @@ bool IsHTHalfNmodeAPs(struct ieee80211_device* ieee)
371 371
372/******************************************************************************************************************** 372/********************************************************************************************************************
373 *function: This function returns peer IOT. 373 *function: This function returns peer IOT.
374 * input: struct ieee80211_device* ieee 374 * input: struct ieee80211_device* ieee
375 * output: none 375 * output: none
376 * return: 376 * return:
377 * notice: 377 * notice:
@@ -408,8 +408,8 @@ void HTIOTPeerDetermine(struct ieee80211_device* ieee)
408/******************************************************************************************************************** 408/********************************************************************************************************************
409 *function: Check whether driver should declare received rate up to MCS13 only since some chipset is not good 409 *function: Check whether driver should declare received rate up to MCS13 only since some chipset is not good
410 * at receiving MCS14~15 frame from some AP. 410 * at receiving MCS14~15 frame from some AP.
411 * input: struct ieee80211_device* ieee 411 * input: struct ieee80211_device* ieee
412 * u8 * PeerMacAddr 412 * u8 * PeerMacAddr
413 * output: none 413 * output: none
414 * return: return 1 if driver should declare MCS13 only(otherwise return 0) 414 * return: return 1 if driver should declare MCS13 only(otherwise return 0)
415 * *****************************************************************************************************************/ 415 * *****************************************************************************************************************/
@@ -429,7 +429,7 @@ u8 HTIOTActIsDisableMCS14(struct ieee80211_device* ieee, u8* PeerMacAddr)
429* PADAPTER Adapter, 429* PADAPTER Adapter,
430* 430*
431* Output: None 431* Output: None
432* Return: true if driver should disable MCS15 432* Return: true if driver should disable MCS15
433* 2008.04.15 Emily 433* 2008.04.15 Emily
434*/ 434*/
435bool HTIOTActIsDisableMCS15(struct ieee80211_device* ieee) 435bool HTIOTActIsDisableMCS15(struct ieee80211_device* ieee)
@@ -466,7 +466,7 @@ bool HTIOTActIsDisableMCS15(struct ieee80211_device* ieee)
466* PADAPTER Adapter, 466* PADAPTER Adapter,
467* 467*
468* Output: None 468* Output: None
469* Return: true if driver should disable all two spatial stream packet 469* Return: true if driver should disable all two spatial stream packet
470* 2008.04.21 Emily 470* 2008.04.21 Emily
471*/ 471*/
472bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee, u8 *PeerMacAddr) 472bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee, u8 *PeerMacAddr)
@@ -481,12 +481,12 @@ bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee, u8 *Pee
481 481
482/******************************************************************************************************************** 482/********************************************************************************************************************
483 *function: Check whether driver should disable EDCA turbo mode 483 *function: Check whether driver should disable EDCA turbo mode
484 * input: struct ieee80211_device* ieee 484 * input: struct ieee80211_device* ieee
485 * u8* PeerMacAddr 485 * u8* PeerMacAddr
486 * output: none 486 * output: none
487 * return: return 1 if driver should disable EDCA turbo mode(otherwise return 0) 487 * return: return 1 if driver should disable EDCA turbo mode(otherwise return 0)
488 * *****************************************************************************************************************/ 488 * *****************************************************************************************************************/
489u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device* ieee, u8* PeerMacAddr) 489u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device* ieee, u8* PeerMacAddr)
490{ 490{
491 u8 retValue = false; // default enable EDCA Turbo mode. 491 u8 retValue = false; // default enable EDCA Turbo mode.
492 // Set specific EDCA parameter for different AP in DM handler. 492 // Set specific EDCA parameter for different AP in DM handler.
@@ -539,10 +539,10 @@ void HTResetIOTSetting(
539 539
540/******************************************************************************************************************** 540/********************************************************************************************************************
541 *function: Construct Capablility Element in Beacon... if HTEnable is turned on 541 *function: Construct Capablility Element in Beacon... if HTEnable is turned on
542 * input: struct ieee80211_device* ieee 542 * input: struct ieee80211_device* ieee
543 * u8* posHTCap //pointer to store Capability Ele 543 * u8* posHTCap //pointer to store Capability Ele
544 * u8* len //store length of CE 544 * u8* len //store length of CE
545 * u8 IsEncrypt //whether encrypt, needed further 545 * u8 IsEncrypt //whether encrypt, needed further
546 * output: none 546 * output: none
547 * return: none 547 * return: none
548 * notice: posHTCap can't be null and should be initialized before. 548 * notice: posHTCap can't be null and should be initialized before.
@@ -550,7 +550,7 @@ void HTResetIOTSetting(
550void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u8* len, u8 IsEncrypt) 550void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u8* len, u8 IsEncrypt)
551{ 551{
552 PRT_HIGH_THROUGHPUT pHT = ieee->pHTInfo; 552 PRT_HIGH_THROUGHPUT pHT = ieee->pHTInfo;
553 PHT_CAPABILITY_ELE pCapELE = NULL; 553 PHT_CAPABILITY_ELE pCapELE = NULL;
554 //u8 bIsDeclareMCS13; 554 //u8 bIsDeclareMCS13;
555 555
556 if ((posHTCap == NULL) || (pHT == NULL)) 556 if ((posHTCap == NULL) || (pHT == NULL))
@@ -571,7 +571,7 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u
571 571
572 572
573 //HT capability info 573 //HT capability info
574 pCapELE->AdvCoding = 0; // This feature is not supported now!! 574 pCapELE->AdvCoding = 0; // This feature is not supported now!!
575 if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)) 575 if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
576 { 576 {
577 pCapELE->ChlWidth = 0; 577 pCapELE->ChlWidth = 0;
@@ -581,18 +581,18 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u
581 pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0); 581 pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0);
582 } 582 }
583 583
584// pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0); 584// pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0);
585 pCapELE->MimoPwrSave = pHT->SelfMimoPs; 585 pCapELE->MimoPwrSave = pHT->SelfMimoPs;
586 pCapELE->GreenField = 0; // This feature is not supported now!! 586 pCapELE->GreenField = 0; // This feature is not supported now!!
587 pCapELE->ShortGI20Mhz = 1; // We can receive Short GI!! 587 pCapELE->ShortGI20Mhz = 1; // We can receive Short GI!!
588 pCapELE->ShortGI40Mhz = 1; // We can receive Short GI!! 588 pCapELE->ShortGI40Mhz = 1; // We can receive Short GI!!
589 //DbgPrint("TX HT cap/info ele BW=%d SG20=%d SG40=%d\n\r", 589 //DbgPrint("TX HT cap/info ele BW=%d SG20=%d SG40=%d\n\r",
590 //pCapELE->ChlWidth, pCapELE->ShortGI20Mhz, pCapELE->ShortGI40Mhz); 590 //pCapELE->ChlWidth, pCapELE->ShortGI20Mhz, pCapELE->ShortGI40Mhz);
591 pCapELE->TxSTBC = 1; 591 pCapELE->TxSTBC = 1;
592 pCapELE->RxSTBC = 0; 592 pCapELE->RxSTBC = 0;
593 pCapELE->DelayBA = 0; // Do not support now!! 593 pCapELE->DelayBA = 0; // Do not support now!!
594 pCapELE->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE>=7935)?1:0; 594 pCapELE->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE>=7935)?1:0;
595 pCapELE->DssCCk = ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0); 595 pCapELE->DssCCk = ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0);
596 pCapELE->PSMP = 0; // Do not support now!! 596 pCapELE->PSMP = 0; // Do not support now!!
597 pCapELE->LSigTxopProtect = 0; // Do not support now!! 597 pCapELE->LSigTxopProtect = 0; // Do not support now!!
598 598
@@ -603,13 +603,13 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u
603 603
604 if( IsEncrypt) 604 if( IsEncrypt)
605 { 605 {
606 pCapELE->MPDUDensity = 7; // 8us 606 pCapELE->MPDUDensity = 7; // 8us
607 pCapELE->MaxRxAMPDUFactor = 2; // 2 is for 32 K and 3 is 64K 607 pCapELE->MaxRxAMPDUFactor = 2; // 2 is for 32 K and 3 is 64K
608 } 608 }
609 else 609 else
610 { 610 {
611 pCapELE->MaxRxAMPDUFactor = 3; // 2 is for 32 K and 3 is 64K 611 pCapELE->MaxRxAMPDUFactor = 3; // 2 is for 32 K and 3 is 64K
612 pCapELE->MPDUDensity = 0; // no density 612 pCapELE->MPDUDensity = 0; // no density
613 } 613 }
614 614
615 //Supported MCS set 615 //Supported MCS set
@@ -658,10 +658,10 @@ void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u
658} 658}
659/******************************************************************************************************************** 659/********************************************************************************************************************
660 *function: Construct Information Element in Beacon... if HTEnable is turned on 660 *function: Construct Information Element in Beacon... if HTEnable is turned on
661 * input: struct ieee80211_device* ieee 661 * input: struct ieee80211_device* ieee
662 * u8* posHTCap //pointer to store Information Ele 662 * u8* posHTCap //pointer to store Information Ele
663 * u8* len //store len of 663 * u8* len //store len of
664 * u8 IsEncrypt //whether encrypt, needed further 664 * u8 IsEncrypt //whether encrypt, needed further
665 * output: none 665 * output: none
666 * return: none 666 * return: none
667 * notice: posHTCap can't be null and be initialized before. only AP and IBSS sta should do this 667 * notice: posHTCap can't be null and be initialized before. only AP and IBSS sta should do this
@@ -679,12 +679,12 @@ void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* le
679 memset(posHTInfo, 0, *len); 679 memset(posHTInfo, 0, *len);
680 if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported 680 if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported
681 { 681 {
682 pHTInfoEle->ControlChl = ieee->current_network.channel; 682 pHTInfoEle->ControlChl = ieee->current_network.channel;
683 pHTInfoEle->ExtChlOffset = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT: 683 pHTInfoEle->ExtChlOffset = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT:
684 (ieee->current_network.channel<=6)? 684 (ieee->current_network.channel<=6)?
685 HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER); 685 HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER);
686 pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz; 686 pHTInfoEle->RecommemdedTxWidth = pHT->bRegBW40MHz;
687 pHTInfoEle->RIFS = 0; 687 pHTInfoEle->RIFS = 0;
688 pHTInfoEle->PSMPAccessOnly = 0; 688 pHTInfoEle->PSMPAccessOnly = 0;
689 pHTInfoEle->SrvIntGranularity = 0; 689 pHTInfoEle->SrvIntGranularity = 0;
690 pHTInfoEle->OptMode = pHT->CurrentOpMode; 690 pHTInfoEle->OptMode = pHT->CurrentOpMode;
@@ -723,17 +723,17 @@ void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* le
723 * Element ID Length OUI Type1 Reserved 723 * Element ID Length OUI Type1 Reserved
724 * 1 byte 1 byte 3 bytes 1 byte 1 byte 724 * 1 byte 1 byte 3 bytes 1 byte 1 byte
725 * 725 *
726 * OUI = 0x00, 0xe0, 0x4c, 726 * OUI = 0x00, 0xe0, 0x4c,
727 * Type = 0x02 727 * Type = 0x02
728 * Reserved = 0x00 728 * Reserved = 0x00
729 * 729 *
730 * 2007.8.21 by Emily 730 * 2007.8.21 by Emily
731*/ 731*/
732/******************************************************************************************************************** 732/********************************************************************************************************************
733 *function: Construct Information Element in Beacon... in RT2RT condition 733 *function: Construct Information Element in Beacon... in RT2RT condition
734 * input: struct ieee80211_device* ieee 734 * input: struct ieee80211_device* ieee
735 * u8* posRT2RTAgg //pointer to store Information Ele 735 * u8* posRT2RTAgg //pointer to store Information Ele
736 * u8* len //store len 736 * u8* len //store len
737 * output: none 737 * output: none
738 * return: none 738 * return: none
739 * notice: 739 * notice:
@@ -787,8 +787,8 @@ void HTConstructRT2RTAggElement(struct ieee80211_device* ieee, u8* posRT2RTAgg,
787 787
788/******************************************************************************************************************** 788/********************************************************************************************************************
789 *function: Pick the right Rate Adaptive table to use 789 *function: Pick the right Rate Adaptive table to use
790 * input: struct ieee80211_device* ieee 790 * input: struct ieee80211_device* ieee
791 * u8* pOperateMCS //A pointer to MCS rate bitmap 791 * u8* pOperateMCS //A pointer to MCS rate bitmap
792 * return: always we return true 792 * return: always we return true
793 * notice: 793 * notice:
794 * *****************************************************************************************************************/ 794 * *****************************************************************************************************************/
@@ -840,7 +840,7 @@ u8 HT_PickMCSRate(struct ieee80211_device* ieee, u8* pOperateMCS)
840* Description: 840* Description:
841* This function will get the highest speed rate in input MCS set. 841* This function will get the highest speed rate in input MCS set.
842* 842*
843* /param Adapter Pionter to Adapter entity 843* /param Adapter Pionter to Adapter entity
844* pMCSRateSet Pointer to MCS rate bitmap 844* pMCSRateSet Pointer to MCS rate bitmap
845* pMCSFilter Pointer to MCS rate filter 845* pMCSFilter Pointer to MCS rate filter
846* 846*
@@ -849,9 +849,9 @@ u8 HT_PickMCSRate(struct ieee80211_device* ieee, u8* pOperateMCS)
849*/ 849*/
850/******************************************************************************************************************** 850/********************************************************************************************************************
851 *function: This function will get the highest speed rate in input MCS set. 851 *function: This function will get the highest speed rate in input MCS set.
852 * input: struct ieee80211_device* ieee 852 * input: struct ieee80211_device* ieee
853 * u8* pMCSRateSet //Pointer to MCS rate bitmap 853 * u8* pMCSRateSet //Pointer to MCS rate bitmap
854 * u8* pMCSFilter //Pointer to MCS rate filter 854 * u8* pMCSFilter //Pointer to MCS rate filter
855 * return: Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter 855 * return: Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter
856 * notice: 856 * notice:
857 * *****************************************************************************************************************/ 857 * *****************************************************************************************************************/
@@ -1062,7 +1062,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
1062 else 1062 else
1063 pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity; 1063 pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
1064 if(ieee->pairwise_key_type != KEY_TYPE_NA ) 1064 if(ieee->pairwise_key_type != KEY_TYPE_NA )
1065 pHTInfo->CurrentMPDUDensity = 7; // 8us 1065 pHTInfo->CurrentMPDUDensity = 7; // 8us
1066 // Force TX AMSDU 1066 // Force TX AMSDU
1067 1067
1068 // Lanhsin: mark for tmp to avoid deauth by ap from s3 1068 // Lanhsin: mark for tmp to avoid deauth by ap from s3
@@ -1118,7 +1118,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
1118void HTSetConnectBwModeCallback(struct ieee80211_device* ieee); 1118void HTSetConnectBwModeCallback(struct ieee80211_device* ieee);
1119/******************************************************************************************************************** 1119/********************************************************************************************************************
1120 *function: initialize HT info(struct PRT_HIGH_THROUGHPUT) 1120 *function: initialize HT info(struct PRT_HIGH_THROUGHPUT)
1121 * input: struct ieee80211_device* ieee 1121 * input: struct ieee80211_device* ieee
1122 * output: none 1122 * output: none
1123 * return: none 1123 * return: none
1124 * notice: This function is called when * (1) MPInitialization Phase * (2) Receiving of Deauthentication from AP 1124 * notice: This function is called when * (1) MPInitialization Phase * (2) Receiving of Deauthentication from AP
@@ -1208,13 +1208,13 @@ void HTInitializeBssDesc(PBSS_HT pBssHT)
1208} 1208}
1209/******************************************************************************************************************** 1209/********************************************************************************************************************
1210 *function: initialize Bss HT structure(struct PBSS_HT) 1210 *function: initialize Bss HT structure(struct PBSS_HT)
1211 * input: struct ieee80211_device *ieee 1211 * input: struct ieee80211_device *ieee
1212 * struct ieee80211_network *pNetwork //usually current network we are live in 1212 * struct ieee80211_network *pNetwork //usually current network we are live in
1213 * output: none 1213 * output: none
1214 * return: none 1214 * return: none
1215 * notice: This function should ONLY be called before association 1215 * notice: This function should ONLY be called before association
1216********************************************************************************************************************/ 1216********************************************************************************************************************/
1217void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork) 1217void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork)
1218{ 1218{
1219 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 1219 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1220// u16 nMaxAMSDUSize; 1220// u16 nMaxAMSDUSize;
@@ -1235,7 +1235,7 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80
1235 pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer; 1235 pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer;
1236 1236
1237 // Save HTCap and HTInfo information Element 1237 // Save HTCap and HTInfo information Element
1238 if(pNetwork->bssht.bdHTCapLen > 0 && pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf)) 1238 if(pNetwork->bssht.bdHTCapLen > 0 && pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf))
1239 memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen); 1239 memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen);
1240 1240
1241 if(pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf)) 1241 if(pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf))
@@ -1297,7 +1297,7 @@ void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee, struct ieee80
1297 1297
1298} 1298}
1299 1299
1300void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork) 1300void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee, struct ieee80211_network * pNetwork)
1301{ 1301{
1302 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 1302 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1303// PHT_CAPABILITY_ELE pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf; 1303// PHT_CAPABILITY_ELE pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
@@ -1364,8 +1364,8 @@ void HTUseDefaultSetting(struct ieee80211_device* ieee)
1364} 1364}
1365/******************************************************************************************************************** 1365/********************************************************************************************************************
1366 *function: check whether HT control field exists 1366 *function: check whether HT control field exists
1367 * input: struct ieee80211_device *ieee 1367 * input: struct ieee80211_device *ieee
1368 * u8* pFrame //coming skb->data 1368 * u8* pFrame //coming skb->data
1369 * output: none 1369 * output: none
1370 * return: return true if HT control field exists(false otherwise) 1370 * return: return true if HT control field exists(false otherwise)
1371 * notice: 1371 * notice:
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
index 9e4ced15edf5..2348ccd70be0 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_Qos.h
@@ -81,8 +81,7 @@ typedef union _QOS_CTRL_FIELD{
81 u16 shortData; 81 u16 shortData;
82 82
83 // WMM spec 83 // WMM spec
84 struct 84 struct {
85 {
86 u8 UP:3; 85 u8 UP:3;
87 u8 usRsvd1:1; 86 u8 usRsvd1:1;
88 u8 EOSP:1; 87 u8 EOSP:1;
@@ -92,8 +91,7 @@ typedef union _QOS_CTRL_FIELD{
92 }WMM; 91 }WMM;
93 92
94 // 802.11e: QoS data type frame sent by non-AP QSTAs. 93 // 802.11e: QoS data type frame sent by non-AP QSTAs.
95 struct 94 struct {
96 {
97 u8 TID:4; 95 u8 TID:4;
98 u8 bIsQsize:1;// 0: BIT[8:15] is TXOP Duration Requested, 1: BIT[8:15] is Queue Size. 96 u8 bIsQsize:1;// 0: BIT[8:15] is TXOP Duration Requested, 1: BIT[8:15] is Queue Size.
99 u8 AckPolicy:2; 97 u8 AckPolicy:2;
@@ -102,8 +100,7 @@ typedef union _QOS_CTRL_FIELD{
102 }BySta; 100 }BySta;
103 101
104 // 802.11e: QoS data, QoS Null, and QoS Data+CF-Ack frames sent by HC. 102 // 802.11e: QoS data, QoS Null, and QoS Data+CF-Ack frames sent by HC.
105 struct 103 struct {
106 {
107 u8 TID:4; 104 u8 TID:4;
108 u8 EOSP:1; 105 u8 EOSP:1;
109 u8 AckPolicy:2; 106 u8 AckPolicy:2;
@@ -112,8 +109,7 @@ typedef union _QOS_CTRL_FIELD{
112 }ByHc_Data; 109 }ByHc_Data;
113 110
114 // 802.11e: QoS (+) CF-Poll frames sent by HC. 111 // 802.11e: QoS (+) CF-Poll frames sent by HC.
115 struct 112 struct {
116 {
117 u8 TID:4; 113 u8 TID:4;
118 u8 EOSP:1; 114 u8 EOSP:1;
119 u8 AckPolicy:2; 115 u8 AckPolicy:2;
@@ -133,14 +129,12 @@ typedef union _QOS_CTRL_FIELD{
133typedef union _QOS_INFO_FIELD{ 129typedef union _QOS_INFO_FIELD{
134 u8 charData; 130 u8 charData;
135 131
136 struct 132 struct {
137 {
138 u8 ucParameterSetCount:4; 133 u8 ucParameterSetCount:4;
139 u8 ucReserved:4; 134 u8 ucReserved:4;
140 }WMM; 135 }WMM;
141 136
142 struct 137 struct {
143 {
144 //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah 138 //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah
145 u8 ucAC_VO_UAPSD:1; 139 u8 ucAC_VO_UAPSD:1;
146 u8 ucAC_VI_UAPSD:1; 140 u8 ucAC_VI_UAPSD:1;
@@ -152,16 +146,14 @@ typedef union _QOS_INFO_FIELD{
152 146
153 }ByWmmPsSta; 147 }ByWmmPsSta;
154 148
155 struct 149 struct {
156 {
157 //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah 150 //Ref WMM_Specification_1-1.pdf, 2006-06-13 Isaiah
158 u8 ucParameterSetCount:4; 151 u8 ucParameterSetCount:4;
159 u8 ucReserved:3; 152 u8 ucReserved:3;
160 u8 ucApUapsd:1; 153 u8 ucApUapsd:1;
161 }ByWmmPsAp; 154 }ByWmmPsAp;
162 155
163 struct 156 struct {
164 {
165 u8 ucAC3_UAPSD:1; 157 u8 ucAC3_UAPSD:1;
166 u8 ucAC2_UAPSD:1; 158 u8 ucAC2_UAPSD:1;
167 u8 ucAC1_UAPSD:1; 159 u8 ucAC1_UAPSD:1;
@@ -171,8 +163,7 @@ typedef union _QOS_INFO_FIELD{
171 u8 ucMoreDataAck:1; 163 u8 ucMoreDataAck:1;
172 } By11eSta; 164 } By11eSta;
173 165
174 struct 166 struct {
175 {
176 u8 ucParameterSetCount:4; 167 u8 ucParameterSetCount:4;
177 u8 ucQAck:1; 168 u8 ucQAck:1;
178 u8 ucQueueReq:1; 169 u8 ucQueueReq:1;
@@ -180,16 +171,14 @@ typedef union _QOS_INFO_FIELD{
180 u8 ucReserved:1; 171 u8 ucReserved:1;
181 } By11eAp; 172 } By11eAp;
182 173
183 struct 174 struct {
184 {
185 u8 ucReserved1:4; 175 u8 ucReserved1:4;
186 u8 ucQAck:1; 176 u8 ucQAck:1;
187 u8 ucReserved2:2; 177 u8 ucReserved2:2;
188 u8 ucMoreDataAck:1; 178 u8 ucMoreDataAck:1;
189 } ByWmmsaSta; 179 } ByWmmsaSta;
190 180
191 struct 181 struct {
192 {
193 u8 ucReserved1:4; 182 u8 ucReserved1:4;
194 u8 ucQAck:1; 183 u8 ucQAck:1;
195 u8 ucQueueReq:1; 184 u8 ucQueueReq:1;
@@ -197,8 +186,7 @@ typedef union _QOS_INFO_FIELD{
197 u8 ucReserved2:1; 186 u8 ucReserved2:1;
198 } ByWmmsaAp; 187 } ByWmmsaAp;
199 188
200 struct 189 struct {
201 {
202 u8 ucAC3_UAPSD:1; 190 u8 ucAC3_UAPSD:1;
203 u8 ucAC2_UAPSD:1; 191 u8 ucAC2_UAPSD:1;
204 u8 ucAC1_UAPSD:1; 192 u8 ucAC1_UAPSD:1;
@@ -208,8 +196,7 @@ typedef union _QOS_INFO_FIELD{
208 u8 ucMoreDataAck:1; 196 u8 ucMoreDataAck:1;
209 } ByAllSta; 197 } ByAllSta;
210 198
211 struct 199 struct {
212 {
213 u8 ucParameterSetCount:4; 200 u8 ucParameterSetCount:4;
214 u8 ucQAck:1; 201 u8 ucQAck:1;
215 u8 ucQueueReq:1; 202 u8 ucQueueReq:1;
@@ -246,8 +233,7 @@ typedef u32 AC_CODING;
246typedef union _ACI_AIFSN{ 233typedef union _ACI_AIFSN{
247 u8 charData; 234 u8 charData;
248 235
249 struct 236 struct {
250 {
251 u8 AIFSN:4; 237 u8 AIFSN:4;
252 u8 ACM:1; 238 u8 ACM:1;
253 u8 ACI:2; 239 u8 ACI:2;
@@ -261,8 +247,7 @@ typedef union _ACI_AIFSN{
261// 247//
262typedef union _ECW{ 248typedef union _ECW{
263 u8 charData; 249 u8 charData;
264 struct 250 struct {
265 {
266 u8 ECWmin:4; 251 u8 ECWmin:4;
267 u8 ECWmax:4; 252 u8 ECWmax:4;
268 }f; // Field 253 }f; // Field
@@ -276,8 +261,7 @@ typedef union _AC_PARAM{
276 u32 longData; 261 u32 longData;
277 u8 charData[4]; 262 u8 charData[4];
278 263
279 struct 264 struct {
280 {
281 ACI_AIFSN AciAifsn; 265 ACI_AIFSN AciAifsn;
282 ECW Ecw; 266 ECW Ecw;
283 u16 TXOPLimit; 267 u16 TXOPLimit;
@@ -336,8 +320,7 @@ typedef union _QOS_TSINFO{
336typedef union _TSPEC_BODY{ 320typedef union _TSPEC_BODY{
337 u8 charData[55]; 321 u8 charData[55];
338 322
339 struct 323 struct {
340 {
341 QOS_TSINFO TSInfo; //u8 TSInfo[3]; 324 QOS_TSINFO TSInfo; //u8 TSInfo[3];
342 u16 NominalMSDUsize; 325 u16 NominalMSDUsize;
343 u16 MaxMSDUsize; 326 u16 MaxMSDUsize;
@@ -412,14 +395,14 @@ typedef union _QOS_TCLAS{
412 395
413 struct _TYPE_GENERAL{ 396 struct _TYPE_GENERAL{
414 u8 Priority; 397 u8 Priority;
415 u8 ClassifierType; 398 u8 ClassifierType;
416 u8 Mask; 399 u8 Mask;
417 } TYPE_GENERAL; 400 } TYPE_GENERAL;
418 401
419 struct _TYPE0_ETH{ 402 struct _TYPE0_ETH{
420 u8 Priority; 403 u8 Priority;
421 u8 ClassifierType; 404 u8 ClassifierType;
422 u8 Mask; 405 u8 Mask;
423 u8 SrcAddr[6]; 406 u8 SrcAddr[6];
424 u8 DstAddr[6]; 407 u8 DstAddr[6];
425 u16 Type; 408 u16 Type;
@@ -427,9 +410,9 @@ typedef union _QOS_TCLAS{
427 410
428 struct _TYPE1_IPV4{ 411 struct _TYPE1_IPV4{
429 u8 Priority; 412 u8 Priority;
430 u8 ClassifierType; 413 u8 ClassifierType;
431 u8 Mask; 414 u8 Mask;
432 u8 Version; 415 u8 Version;
433 u8 SrcIP[4]; 416 u8 SrcIP[4];
434 u8 DstIP[4]; 417 u8 DstIP[4];
435 u16 SrcPort; 418 u16 SrcPort;
@@ -441,9 +424,9 @@ typedef union _QOS_TCLAS{
441 424
442 struct _TYPE1_IPV6{ 425 struct _TYPE1_IPV6{
443 u8 Priority; 426 u8 Priority;
444 u8 ClassifierType; 427 u8 ClassifierType;
445 u8 Mask; 428 u8 Mask;
446 u8 Version; 429 u8 Version;
447 u8 SrcIP[16]; 430 u8 SrcIP[16];
448 u8 DstIP[16]; 431 u8 DstIP[16];
449 u16 SrcPort; 432 u16 SrcPort;
@@ -453,8 +436,8 @@ typedef union _QOS_TCLAS{
453 436
454 struct _TYPE2_8021Q{ 437 struct _TYPE2_8021Q{
455 u8 Priority; 438 u8 Priority;
456 u8 ClassifierType; 439 u8 ClassifierType;
457 u8 Mask; 440 u8 Mask;
458 u16 TagType; 441 u16 TagType;
459 } TYPE2_8021Q; 442 } TYPE2_8021Q;
460} QOS_TCLAS, *PQOS_TCLAS; 443} QOS_TCLAS, *PQOS_TCLAS;
@@ -481,7 +464,7 @@ typedef struct _QOS_TSTREAM{
481// "Qos control field" and "Qos info field" 464// "Qos control field" and "Qos info field"
482//typedef struct _QOS_UAPSD{ 465//typedef struct _QOS_UAPSD{
483// u8 bTriggerEnable[4]; 466// u8 bTriggerEnable[4];
484// u8 MaxSPLength; 467// u8 MaxSPLength;
485// u8 HighestBufAC; 468// u8 HighestBufAC;
486//} QOS_UAPSD, *PQOS_APSD; 469//} QOS_UAPSD, *PQOS_APSD;
487 470
@@ -489,7 +472,7 @@ typedef struct _QOS_TSTREAM{
489// 802.11 Management frame Status Code field 472// 802.11 Management frame Status Code field
490//---------------------------------------------------------------------------- 473//----------------------------------------------------------------------------
491typedef struct _OCTET_STRING{ 474typedef struct _OCTET_STRING{
492 u8 *Octet; 475 u8 *Octet;
493 u16 Length; 476 u16 Length;
494}OCTET_STRING, *POCTET_STRING; 477}OCTET_STRING, *POCTET_STRING;
495 478
@@ -512,7 +495,7 @@ typedef struct _STA_QOS{
512 AC_UAPSD Curr4acUapsd; 495 AC_UAPSD Curr4acUapsd;
513 u8 bInServicePeriod; 496 u8 bInServicePeriod;
514 u8 MaxSPLength; 497 u8 MaxSPLength;
515 int NumBcnBeforeTrigger; 498 int NumBcnBeforeTrigger;
516 499
517 // Part 2. EDCA Parameter (perAC) 500 // Part 2. EDCA Parameter (perAC)
518 u8 * pWMMInfoEle; 501 u8 * pWMMInfoEle;
@@ -523,7 +506,7 @@ typedef struct _STA_QOS{
523 //2 ToDo: remove the Qos Info Field and replace it by the above WMM Info element. 506 //2 ToDo: remove the Qos Info Field and replace it by the above WMM Info element.
524 // By Bruce, 2008-01-30. 507 // By Bruce, 2008-01-30.
525 // Part 2. EDCA Parameter (perAC) 508 // Part 2. EDCA Parameter (perAC)
526 QOS_INFO_FIELD QosInfoField_STA; // Maintained by STA 509 QOS_INFO_FIELD QosInfoField_STA; // Maintained by STA
527 QOS_INFO_FIELD QosInfoField_AP; // Retrieved from AP 510 QOS_INFO_FIELD QosInfoField_AP; // Retrieved from AP
528 511
529 AC_PARAM CurAcParameters[4]; 512 AC_PARAM CurAcParameters[4];
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
index e7e26fd96395..7ed7243b1fb0 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
@@ -28,7 +28,7 @@ typedef struct _TS_COMMON_INFO{
28typedef struct _TX_TS_RECORD{ 28typedef struct _TX_TS_RECORD{
29 TS_COMMON_INFO TsCommonInfo; 29 TS_COMMON_INFO TsCommonInfo;
30 u16 TxCurSeq; 30 u16 TxCurSeq;
31 BA_RECORD TxPendingBARecord; // For BA Originator 31 BA_RECORD TxPendingBARecord; // For BA Originator
32 BA_RECORD TxAdmittedBARecord; // For BA Originator 32 BA_RECORD TxAdmittedBARecord; // For BA Originator
33// QOS_DL_RECORD DLRecord; 33// QOS_DL_RECORD DLRecord;
34 u8 bAddBaReqInProgress; 34 u8 bAddBaReqInProgress;
@@ -53,4 +53,3 @@ typedef struct _RX_TS_RECORD {
53 53
54 54
55#endif 55#endif
56
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 06a9824bbff1..0310d07287a1 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -27,7 +27,7 @@ void RxPktPendingTimeout(unsigned long data)
27 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data; 27 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data;
28 struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]); 28 struct ieee80211_device *ieee = container_of(pRxTs, struct ieee80211_device, RxTsRecord[pRxTs->num]);
29 29
30 PRX_REORDER_ENTRY pReorderEntry = NULL; 30 PRX_REORDER_ENTRY pReorderEntry = NULL;
31 31
32 //u32 flags = 0; 32 //u32 flags = 0;
33 unsigned long flags = 0; 33 unsigned long flags = 0;
@@ -236,8 +236,8 @@ void AdmitTS(struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, u32 I
236 236
237PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect) 237PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8 TID, TR_SELECT TxRxSelect)
238{ 238{
239 //DIRECTION_VALUE dir; 239 //DIRECTION_VALUE dir;
240 u8 dir; 240 u8 dir;
241 bool search_dir[4] = {0, 0, 0, 0}; 241 bool search_dir[4] = {0, 0, 0, 0};
242 struct list_head* psearch_list; //FIXME 242 struct list_head* psearch_list; //FIXME
243 PTS_COMMON_INFO pRet = NULL; 243 PTS_COMMON_INFO pRet = NULL;
@@ -250,14 +250,14 @@ PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8
250 } 250 }
251 else 251 else
252 { 252 {
253 search_dir[DIR_UP] = true; 253 search_dir[DIR_UP] = true;
254 search_dir[DIR_BI_DIR]= true; 254 search_dir[DIR_BI_DIR]= true;
255 } 255 }
256 } 256 }
257 else if(ieee->iw_mode == IW_MODE_ADHOC) 257 else if(ieee->iw_mode == IW_MODE_ADHOC)
258 { 258 {
259 if(TxRxSelect == TX_DIR) 259 if(TxRxSelect == TX_DIR)
260 search_dir[DIR_UP] = true; 260 search_dir[DIR_UP] = true;
261 else 261 else
262 search_dir[DIR_DOWN] = true; 262 search_dir[DIR_DOWN] = true;
263 } 263 }
@@ -265,7 +265,7 @@ PTS_COMMON_INFO SearchAdmitTRStream(struct ieee80211_device *ieee, u8* Addr, u8
265 { 265 {
266 if(TxRxSelect == TX_DIR) 266 if(TxRxSelect == TX_DIR)
267 { 267 {
268 search_dir[DIR_UP] = true; 268 search_dir[DIR_UP] = true;
269 search_dir[DIR_BI_DIR]= true; 269 search_dir[DIR_BI_DIR]= true;
270 search_dir[DIR_DIRECT]= true; 270 search_dir[DIR_DIRECT]= true;
271 } 271 }
@@ -450,8 +450,8 @@ bool GetTs(
450 pTSInfo->field.ucTSID = UP; // TSID 450 pTSInfo->field.ucTSID = UP; // TSID
451 pTSInfo->field.ucDirection = Dir; // Direction: if there is DirectLink, this need additional consideration. 451 pTSInfo->field.ucDirection = Dir; // Direction: if there is DirectLink, this need additional consideration.
452 pTSInfo->field.ucAccessPolicy = 1; // Access policy 452 pTSInfo->field.ucAccessPolicy = 1; // Access policy
453 pTSInfo->field.ucAggregation = 0; // Aggregation 453 pTSInfo->field.ucAggregation = 0; // Aggregation
454 pTSInfo->field.ucPSB = 0; // Aggregation 454 pTSInfo->field.ucPSB = 0; // Aggregation
455 pTSInfo->field.ucUP = UP; // User priority 455 pTSInfo->field.ucUP = UP; // User priority
456 pTSInfo->field.ucTSInfoAckPolicy = 0; // Ack policy 456 pTSInfo->field.ucTSInfoAckPolicy = 0; // Ack policy
457 pTSInfo->field.ucSchedule = 0; // Schedule 457 pTSInfo->field.ucSchedule = 0; // Schedule
@@ -488,7 +488,7 @@ void RemoveTsEntry(
488 { 488 {
489//#ifdef TO_DO_LIST 489//#ifdef TO_DO_LIST
490 PRX_REORDER_ENTRY pRxReorderEntry; 490 PRX_REORDER_ENTRY pRxReorderEntry;
491 PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs; 491 PRX_TS_RECORD pRxTS = (PRX_TS_RECORD)pTs;
492 if(timer_pending(&pRxTS->RxPktPendingTimer)) 492 if(timer_pending(&pRxTS->RxPktPendingTimer))
493 del_timer_sync(&pRxTS->RxPktPendingTimer); 493 del_timer_sync(&pRxTS->RxPktPendingTimer);
494 494
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h b/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h
index ccf6ae763572..c3c87108ee9e 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl_crypto.h
@@ -52,10 +52,10 @@
52 52
53#define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100 53#define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
54#define CRYPTO_TFM_RES_WEAK_KEY 0x00100000 54#define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
55#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000 55#define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
56#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000 56#define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
57#define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000 57#define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000
58#define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000 58#define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000
59 59
60/* 60/*
61 * Miscellaneous stuff. 61 * Miscellaneous stuff.
@@ -73,7 +73,7 @@ struct cipher_alg {
73 unsigned int cia_min_keysize; 73 unsigned int cia_min_keysize;
74 unsigned int cia_max_keysize; 74 unsigned int cia_max_keysize;
75 int (*cia_setkey)(void *ctx, const u8 *key, 75 int (*cia_setkey)(void *ctx, const u8 *key,
76 unsigned int keylen, u32 *flags); 76 unsigned int keylen, u32 *flags);
77 void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src); 77 void (*cia_encrypt)(void *ctx, u8 *dst, const u8 *src);
78 void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src); 78 void (*cia_decrypt)(void *ctx, u8 *dst, const u8 *src);
79}; 79};
@@ -84,16 +84,16 @@ struct digest_alg {
84 void (*dia_update)(void *ctx, const u8 *data, unsigned int len); 84 void (*dia_update)(void *ctx, const u8 *data, unsigned int len);
85 void (*dia_final)(void *ctx, u8 *out); 85 void (*dia_final)(void *ctx, u8 *out);
86 int (*dia_setkey)(void *ctx, const u8 *key, 86 int (*dia_setkey)(void *ctx, const u8 *key,
87 unsigned int keylen, u32 *flags); 87 unsigned int keylen, u32 *flags);
88}; 88};
89 89
90struct compress_alg { 90struct compress_alg {
91 int (*coa_init)(void *ctx); 91 int (*coa_init)(void *ctx);
92 void (*coa_exit)(void *ctx); 92 void (*coa_exit)(void *ctx);
93 int (*coa_compress)(void *ctx, const u8 *src, unsigned int slen, 93 int (*coa_compress)(void *ctx, const u8 *src, unsigned int slen,
94 u8 *dst, unsigned int *dlen); 94 u8 *dst, unsigned int *dlen);
95 int (*coa_decompress)(void *ctx, const u8 *src, unsigned int slen, 95 int (*coa_decompress)(void *ctx, const u8 *src, unsigned int slen,
96 u8 *dst, unsigned int *dlen); 96 u8 *dst, unsigned int *dlen);
97}; 97};
98 98
99#define cra_cipher cra_u.cipher 99#define cra_cipher cra_u.cipher
@@ -139,15 +139,15 @@ struct cipher_tfm {
139 unsigned int cit_ivsize; 139 unsigned int cit_ivsize;
140 u32 cit_mode; 140 u32 cit_mode;
141 int (*cit_setkey)(struct crypto_tfm *tfm, 141 int (*cit_setkey)(struct crypto_tfm *tfm,
142 const u8 *key, unsigned int keylen); 142 const u8 *key, unsigned int keylen);
143 int (*cit_encrypt)(struct crypto_tfm *tfm, 143 int (*cit_encrypt)(struct crypto_tfm *tfm,
144 struct scatterlist *dst, 144 struct scatterlist *dst,
145 struct scatterlist *src, 145 struct scatterlist *src,
146 unsigned int nbytes); 146 unsigned int nbytes);
147 int (*cit_encrypt_iv)(struct crypto_tfm *tfm, 147 int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
148 struct scatterlist *dst, 148 struct scatterlist *dst,
149 struct scatterlist *src, 149 struct scatterlist *src,
150 unsigned int nbytes, u8 *iv); 150 unsigned int nbytes, u8 *iv);
151 int (*cit_decrypt)(struct crypto_tfm *tfm, 151 int (*cit_decrypt)(struct crypto_tfm *tfm,
152 struct scatterlist *dst, 152 struct scatterlist *dst,
153 struct scatterlist *src, 153 struct scatterlist *src,
@@ -162,12 +162,12 @@ struct cipher_tfm {
162struct digest_tfm { 162struct digest_tfm {
163 void (*dit_init)(struct crypto_tfm *tfm); 163 void (*dit_init)(struct crypto_tfm *tfm);
164 void (*dit_update)(struct crypto_tfm *tfm, 164 void (*dit_update)(struct crypto_tfm *tfm,
165 struct scatterlist *sg, unsigned int nsg); 165 struct scatterlist *sg, unsigned int nsg);
166 void (*dit_final)(struct crypto_tfm *tfm, u8 *out); 166 void (*dit_final)(struct crypto_tfm *tfm, u8 *out);
167 void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg, 167 void (*dit_digest)(struct crypto_tfm *tfm, struct scatterlist *sg,
168 unsigned int nsg, u8 *out); 168 unsigned int nsg, u8 *out);
169 int (*dit_setkey)(struct crypto_tfm *tfm, 169 int (*dit_setkey)(struct crypto_tfm *tfm,
170 const u8 *key, unsigned int keylen); 170 const u8 *key, unsigned int keylen);
171#ifdef CONFIG_CRYPTO_HMAC 171#ifdef CONFIG_CRYPTO_HMAC
172 void *dit_hmac_block; 172 void *dit_hmac_block;
173#endif 173#endif
@@ -175,11 +175,11 @@ struct digest_tfm {
175 175
176struct compress_tfm { 176struct compress_tfm {
177 int (*cot_compress)(struct crypto_tfm *tfm, 177 int (*cot_compress)(struct crypto_tfm *tfm,
178 const u8 *src, unsigned int slen, 178 const u8 *src, unsigned int slen,
179 u8 *dst, unsigned int *dlen); 179 u8 *dst, unsigned int *dlen);
180 int (*cot_decompress)(struct crypto_tfm *tfm, 180 int (*cot_decompress)(struct crypto_tfm *tfm,
181 const u8 *src, unsigned int slen, 181 const u8 *src, unsigned int slen,
182 u8 *dst, unsigned int *dlen); 182 u8 *dst, unsigned int *dlen);
183}; 183};
184 184
185#define crt_cipher crt_u.cipher 185#define crt_cipher crt_u.cipher
@@ -277,8 +277,8 @@ static inline void crypto_digest_init(struct crypto_tfm *tfm)
277} 277}
278 278
279static inline void crypto_digest_update(struct crypto_tfm *tfm, 279static inline void crypto_digest_update(struct crypto_tfm *tfm,
280 struct scatterlist *sg, 280 struct scatterlist *sg,
281 unsigned int nsg) 281 unsigned int nsg)
282{ 282{
283 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); 283 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
284 tfm->crt_digest.dit_update(tfm, sg, nsg); 284 tfm->crt_digest.dit_update(tfm, sg, nsg);
@@ -291,15 +291,15 @@ static inline void crypto_digest_final(struct crypto_tfm *tfm, u8 *out)
291} 291}
292 292
293static inline void crypto_digest_digest(struct crypto_tfm *tfm, 293static inline void crypto_digest_digest(struct crypto_tfm *tfm,
294 struct scatterlist *sg, 294 struct scatterlist *sg,
295 unsigned int nsg, u8 *out) 295 unsigned int nsg, u8 *out)
296{ 296{
297 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); 297 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
298 tfm->crt_digest.dit_digest(tfm, sg, nsg, out); 298 tfm->crt_digest.dit_digest(tfm, sg, nsg, out);
299} 299}
300 300
301static inline int crypto_digest_setkey(struct crypto_tfm *tfm, 301static inline int crypto_digest_setkey(struct crypto_tfm *tfm,
302 const u8 *key, unsigned int keylen) 302 const u8 *key, unsigned int keylen)
303{ 303{
304 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST); 304 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_DIGEST);
305 if (tfm->crt_digest.dit_setkey == NULL) 305 if (tfm->crt_digest.dit_setkey == NULL)
@@ -308,25 +308,25 @@ static inline int crypto_digest_setkey(struct crypto_tfm *tfm,
308} 308}
309 309
310static inline int crypto_cipher_setkey(struct crypto_tfm *tfm, 310static inline int crypto_cipher_setkey(struct crypto_tfm *tfm,
311 const u8 *key, unsigned int keylen) 311 const u8 *key, unsigned int keylen)
312{ 312{
313 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); 313 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
314 return tfm->crt_cipher.cit_setkey(tfm, key, keylen); 314 return tfm->crt_cipher.cit_setkey(tfm, key, keylen);
315} 315}
316 316
317static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm, 317static inline int crypto_cipher_encrypt(struct crypto_tfm *tfm,
318 struct scatterlist *dst, 318 struct scatterlist *dst,
319 struct scatterlist *src, 319 struct scatterlist *src,
320 unsigned int nbytes) 320 unsigned int nbytes)
321{ 321{
322 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); 322 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
323 return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes); 323 return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes);
324} 324}
325 325
326static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm, 326static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm,
327 struct scatterlist *dst, 327 struct scatterlist *dst,
328 struct scatterlist *src, 328 struct scatterlist *src,
329 unsigned int nbytes, u8 *iv) 329 unsigned int nbytes, u8 *iv)
330{ 330{
331 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); 331 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
332 BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); 332 BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB);
@@ -334,18 +334,18 @@ static inline int crypto_cipher_encrypt_iv(struct crypto_tfm *tfm,
334} 334}
335 335
336static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm, 336static inline int crypto_cipher_decrypt(struct crypto_tfm *tfm,
337 struct scatterlist *dst, 337 struct scatterlist *dst,
338 struct scatterlist *src, 338 struct scatterlist *src,
339 unsigned int nbytes) 339 unsigned int nbytes)
340{ 340{
341 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); 341 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
342 return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes); 342 return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes);
343} 343}
344 344
345static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm, 345static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm,
346 struct scatterlist *dst, 346 struct scatterlist *dst,
347 struct scatterlist *src, 347 struct scatterlist *src,
348 unsigned int nbytes, u8 *iv) 348 unsigned int nbytes, u8 *iv)
349{ 349{
350 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); 350 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
351 BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB); 351 BUG_ON(tfm->crt_cipher.cit_mode == CRYPTO_TFM_MODE_ECB);
@@ -353,30 +353,30 @@ static inline int crypto_cipher_decrypt_iv(struct crypto_tfm *tfm,
353} 353}
354 354
355static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm, 355static inline void crypto_cipher_set_iv(struct crypto_tfm *tfm,
356 const u8 *src, unsigned int len) 356 const u8 *src, unsigned int len)
357{ 357{
358 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); 358 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
359 memcpy(tfm->crt_cipher.cit_iv, src, len); 359 memcpy(tfm->crt_cipher.cit_iv, src, len);
360} 360}
361 361
362static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm, 362static inline void crypto_cipher_get_iv(struct crypto_tfm *tfm,
363 u8 *dst, unsigned int len) 363 u8 *dst, unsigned int len)
364{ 364{
365 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER); 365 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_CIPHER);
366 memcpy(dst, tfm->crt_cipher.cit_iv, len); 366 memcpy(dst, tfm->crt_cipher.cit_iv, len);
367} 367}
368 368
369static inline int crypto_comp_compress(struct crypto_tfm *tfm, 369static inline int crypto_comp_compress(struct crypto_tfm *tfm,
370 const u8 *src, unsigned int slen, 370 const u8 *src, unsigned int slen,
371 u8 *dst, unsigned int *dlen) 371 u8 *dst, unsigned int *dlen)
372{ 372{
373 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); 373 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
374 return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen); 374 return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen);
375} 375}
376 376
377static inline int crypto_comp_decompress(struct crypto_tfm *tfm, 377static inline int crypto_comp_decompress(struct crypto_tfm *tfm,
378 const u8 *src, unsigned int slen, 378 const u8 *src, unsigned int slen,
379 u8 *dst, unsigned int *dlen) 379 u8 *dst, unsigned int *dlen)
380{ 380{
381 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS); 381 BUG_ON(crypto_tfm_alg_type(tfm) != CRYPTO_ALG_TYPE_COMPRESS);
382 return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen); 382 return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen);
@@ -388,12 +388,11 @@ static inline int crypto_comp_decompress(struct crypto_tfm *tfm,
388#ifdef CONFIG_CRYPTO_HMAC 388#ifdef CONFIG_CRYPTO_HMAC
389void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen); 389void crypto_hmac_init(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen);
390void crypto_hmac_update(struct crypto_tfm *tfm, 390void crypto_hmac_update(struct crypto_tfm *tfm,
391 struct scatterlist *sg, unsigned int nsg); 391 struct scatterlist *sg, unsigned int nsg);
392void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key, 392void crypto_hmac_final(struct crypto_tfm *tfm, u8 *key,
393 unsigned int *keylen, u8 *out); 393 unsigned int *keylen, u8 *out);
394void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen, 394void crypto_hmac(struct crypto_tfm *tfm, u8 *key, unsigned int *keylen,
395 struct scatterlist *sg, unsigned int nsg, u8 *out); 395 struct scatterlist *sg, unsigned int nsg, u8 *out);
396#endif /* CONFIG_CRYPTO_HMAC */ 396#endif /* CONFIG_CRYPTO_HMAC */
397 397
398#endif /* _LINUX_CRYPTO_H */ 398#endif /* _LINUX_CRYPTO_H */
399
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c
index 3c515b7bc542..7e49ad8f48f6 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -95,7 +95,7 @@ u32 eprom_read(struct net_device *dev, u32 addr)
95 u32 ret; 95 u32 ret;
96 96
97 ret=0; 97 ret=0;
98 //enable EPROM programming 98 //enable EPROM programming
99 write_nic_byte_E(dev, EPROM_CMD, 99 write_nic_byte_E(dev, EPROM_CMD,
100 (EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT)); 100 (EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT));
101 force_pci_posting(dev); 101 force_pci_posting(dev);
diff --git a/drivers/staging/rtl8192u/r8180_pm.h b/drivers/staging/rtl8192u/r8180_pm.h
index c7d18a8b79a1..52d6fba99deb 100644
--- a/drivers/staging/rtl8192u/r8180_pm.h
+++ b/drivers/staging/rtl8192u/r8180_pm.h
@@ -1,5 +1,5 @@
1/* 1/*
2 Power management interface routines. 2 Power management interface routines.
3 Written by Mariusz Matuszek. 3 Written by Mariusz Matuszek.
4 This code is currently just a placeholder for later work and 4 This code is currently just a placeholder for later work and
5 does not do anything useful. 5 does not do anything useful.
diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c b/drivers/staging/rtl8192u/r8190_rtl8256.c
index 74ff337b0583..cf9713fa8b9d 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.c
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.c
@@ -16,9 +16,9 @@
16#include "r8190_rtl8256.h" 16#include "r8190_rtl8256.h"
17 17
18/*-------------------------------------------------------------------------- 18/*--------------------------------------------------------------------------
19 * Overview: set RF band width (20M or 40M) 19 * Overview: set RF band width (20M or 40M)
20 * Input: struct net_device* dev 20 * Input: struct net_device* dev
21 * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M 21 * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M
22 * Output: NONE 22 * Output: NONE
23 * Return: NONE 23 * Return: NONE
24 * Note: 8226 support both 20M and 40 MHz 24 * Note: 8226 support both 20M and 40 MHz
@@ -106,16 +106,16 @@ void PHY_RF8256_Config(struct net_device* dev)
106 *---------------------------------------------------------------------------*/ 106 *---------------------------------------------------------------------------*/
107void phy_RF8256_Config_ParaFile(struct net_device* dev) 107void phy_RF8256_Config_ParaFile(struct net_device* dev)
108{ 108{
109 u32 u4RegValue = 0; 109 u32 u4RegValue = 0;
110 //static s1Byte szRadioAFile[] = RTL819X_PHY_RADIO_A; 110 //static s1Byte szRadioAFile[] = RTL819X_PHY_RADIO_A;
111 //static s1Byte szRadioBFile[] = RTL819X_PHY_RADIO_B; 111 //static s1Byte szRadioBFile[] = RTL819X_PHY_RADIO_B;
112 //static s1Byte szRadioCFile[] = RTL819X_PHY_RADIO_C; 112 //static s1Byte szRadioCFile[] = RTL819X_PHY_RADIO_C;
113 //static s1Byte szRadioDFile[] = RTL819X_PHY_RADIO_D; 113 //static s1Byte szRadioDFile[] = RTL819X_PHY_RADIO_D;
114 u8 eRFPath; 114 u8 eRFPath;
115 BB_REGISTER_DEFINITION_T *pPhyReg; 115 BB_REGISTER_DEFINITION_T *pPhyReg;
116 struct r8192_priv *priv = ieee80211_priv(dev); 116 struct r8192_priv *priv = ieee80211_priv(dev);
117 u32 RegOffSetToBeCheck = 0x3; 117 u32 RegOffSetToBeCheck = 0x3;
118 u32 RegValueToBeCheck = 0x7f1; 118 u32 RegValueToBeCheck = 0x7f1;
119 u32 RF3_Final_Value = 0; 119 u32 RF3_Final_Value = 0;
120 u8 ConstRetryTimes = 5, RetryTimes = 5; 120 u8 ConstRetryTimes = 5, RetryTimes = 5;
121 u8 ret = 0; 121 u8 ret = 0;
@@ -152,7 +152,7 @@ void phy_RF8256_Config_ParaFile(struct net_device* dev)
152 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1); 152 rtl8192_setBBreg(dev, pPhyReg->rfintfo, bRFSI_RFENV, 0x1);
153 153
154 /* Set bit number of Address and Data for RF register */ 154 /* Set bit number of Address and Data for RF register */
155 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); // Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258 155 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); // Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258
156 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); // Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ??? 156 rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); // Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ???
157 157
158 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf); 158 rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E) eRFPath, 0x0, bMask12Bits, 0xbf);
@@ -309,4 +309,3 @@ void PHY_SetRF8256OFDMTxPower(struct net_device* dev, u8 powerlevel)
309 return; 309 return;
310 310
311} 311}
312
diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
index 57e3383cc935..e538e026b512 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -110,7 +110,7 @@ do { if(rt_global_debug_component & component) \
110#define COMP_RATE BIT12 // For Rate Adaptive mechanism, 2006.07.02, by rcnjko. 110#define COMP_RATE BIT12 // For Rate Adaptive mechanism, 2006.07.02, by rcnjko.
111#define COMP_RM BIT13 // For Radio Measurement. 111#define COMP_RM BIT13 // For Radio Measurement.
112#define COMP_DIG BIT14 // For DIG, 2006.09.25, by rcnjko. 112#define COMP_DIG BIT14 // For DIG, 2006.09.25, by rcnjko.
113#define COMP_PHY BIT15 113#define COMP_PHY BIT15
114#define COMP_CH BIT16 //channel setting debug 114#define COMP_CH BIT16 //channel setting debug
115#define COMP_TXAGC BIT17 // For Tx power, 060928, by rcnjko. 115#define COMP_TXAGC BIT17 // For Tx power, 060928, by rcnjko.
116#define COMP_HIPWR BIT18 // For High Power Mechanism, 060928, by rcnjko. 116#define COMP_HIPWR BIT18 // For High Power Mechanism, 060928, by rcnjko.
@@ -136,26 +136,26 @@ do { if(rt_global_debug_component & component) \
136#define RTL819x_DEBUG 136#define RTL819x_DEBUG
137#ifdef RTL819x_DEBUG 137#ifdef RTL819x_DEBUG
138#define assert(expr) \ 138#define assert(expr) \
139 if (!(expr)) { \ 139 if (!(expr)) { \
140 printk( "Assertion failed! %s,%s,%s,line=%d\n", \ 140 printk( "Assertion failed! %s,%s,%s,line=%d\n", \
141 #expr,__FILE__,__FUNCTION__,__LINE__); \ 141 #expr,__FILE__,__FUNCTION__,__LINE__); \
142 } 142 }
143//wb added to debug out data buf 143//wb added to debug out data buf
144//if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA 144//if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA
145#define RT_DEBUG_DATA(level, data, datalen) \ 145#define RT_DEBUG_DATA(level, data, datalen) \
146 do{ if ((rt_global_debug_component & (level)) == (level)) \ 146 do{ if ((rt_global_debug_component & (level)) == (level)) \
147 { \ 147 { \
148 int i; \ 148 int i; \
149 u8* pdata = (u8*) data; \ 149 u8* pdata = (u8*) data; \
150 printk(KERN_DEBUG RTL819xU_MODULE_NAME ": %s()\n", __FUNCTION__); \ 150 printk(KERN_DEBUG RTL819xU_MODULE_NAME ": %s()\n", __FUNCTION__); \
151 for(i=0; i<(int)(datalen); i++) \ 151 for(i=0; i<(int)(datalen); i++) \
152 { \ 152 { \
153 printk("%2x ", pdata[i]); \ 153 printk("%2x ", pdata[i]); \
154 if ((i+1)%16 == 0) printk("\n"); \ 154 if ((i+1)%16 == 0) printk("\n"); \
155 } \ 155 } \
156 printk("\n"); \ 156 printk("\n"); \
157 } \ 157 } \
158 } while (0) 158 } while (0)
159#else 159#else
160#define assert(expr) do {} while (0) 160#define assert(expr) do {} while (0)
161#define RT_DEBUG_DATA(level, data, datalen) do {} while(0) 161#define RT_DEBUG_DATA(level, data, datalen) do {} while(0)
@@ -209,47 +209,47 @@ do { if(rt_global_debug_component & component) \
209#define IEEE80211_WATCH_DOG_TIME 2000 209#define IEEE80211_WATCH_DOG_TIME 2000
210#define PHY_Beacon_RSSI_SLID_WIN_MAX 10 210#define PHY_Beacon_RSSI_SLID_WIN_MAX 10
211//for txpowertracking by amy 211//for txpowertracking by amy
212#define OFDM_Table_Length 19 212#define OFDM_Table_Length 19
213#define CCK_Table_length 12 213#define CCK_Table_length 12
214 214
215/* for rtl819x */ 215/* for rtl819x */
216typedef struct _tx_desc_819x_usb { 216typedef struct _tx_desc_819x_usb {
217 //DWORD 0 217 //DWORD 0
218 u16 PktSize; 218 u16 PktSize;
219 u8 Offset; 219 u8 Offset;
220 u8 Reserved0:3; 220 u8 Reserved0:3;
221 u8 CmdInit:1; 221 u8 CmdInit:1;
222 u8 LastSeg:1; 222 u8 LastSeg:1;
223 u8 FirstSeg:1; 223 u8 FirstSeg:1;
224 u8 LINIP:1; 224 u8 LINIP:1;
225 u8 OWN:1; 225 u8 OWN:1;
226 226
227 //DWORD 1 227 //DWORD 1
228 u8 TxFWInfoSize; 228 u8 TxFWInfoSize;
229 u8 RATid:3; 229 u8 RATid:3;
230 u8 DISFB:1; 230 u8 DISFB:1;
231 u8 USERATE:1; 231 u8 USERATE:1;
232 u8 MOREFRAG:1; 232 u8 MOREFRAG:1;
233 u8 NoEnc:1; 233 u8 NoEnc:1;
234 u8 PIFS:1; 234 u8 PIFS:1;
235 u8 QueueSelect:5; 235 u8 QueueSelect:5;
236 u8 NoACM:1; 236 u8 NoACM:1;
237 u8 Reserved1:2; 237 u8 Reserved1:2;
238 u8 SecCAMID:5; 238 u8 SecCAMID:5;
239 u8 SecDescAssign:1; 239 u8 SecDescAssign:1;
240 u8 SecType:2; 240 u8 SecType:2;
241 241
242 //DWORD 2 242 //DWORD 2
243 u16 TxBufferSize; 243 u16 TxBufferSize;
244 //u16 Reserved2; 244 //u16 Reserved2;
245 u8 ResvForPaddingLen:7; 245 u8 ResvForPaddingLen:7;
246 u8 Reserved3:1; 246 u8 Reserved3:1;
247 u8 Reserved4; 247 u8 Reserved4;
248 248
249 //DWORD 3, 4, 5 249 //DWORD 3, 4, 5
250 u32 Reserved5; 250 u32 Reserved5;
251 u32 Reserved6; 251 u32 Reserved6;
252 u32 Reserved7; 252 u32 Reserved7;
253}tx_desc_819x_usb, *ptx_desc_819x_usb; 253}tx_desc_819x_usb, *ptx_desc_819x_usb;
254 254
255#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE 255#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
@@ -280,7 +280,7 @@ typedef struct _tx_desc_819x_usb_aggr_subframe {
280 280
281 281
282typedef struct _tx_desc_cmd_819x_usb { 282typedef struct _tx_desc_cmd_819x_usb {
283 //DWORD 0 283 //DWORD 0
284 u16 Reserved0; 284 u16 Reserved0;
285 u8 Reserved1; 285 u8 Reserved1;
286 u8 Reserved2:3; 286 u8 Reserved2:3;
@@ -290,15 +290,15 @@ typedef struct _tx_desc_cmd_819x_usb {
290 u8 LINIP:1; 290 u8 LINIP:1;
291 u8 OWN:1; 291 u8 OWN:1;
292 292
293 //DOWRD 1 293 //DOWRD 1
294 //u32 Reserved3; 294 //u32 Reserved3;
295 u8 TxFWInfoSize; 295 u8 TxFWInfoSize;
296 u8 Reserved3; 296 u8 Reserved3;
297 u8 QueueSelect; 297 u8 QueueSelect;
298 u8 Reserved4; 298 u8 Reserved4;
299 299
300 //DOWRD 2 300 //DOWRD 2
301 u16 TxBufferSize; 301 u16 TxBufferSize;
302 u16 Reserved5; 302 u16 Reserved5;
303 303
304 //DWORD 3,4,5 304 //DWORD 3,4,5
@@ -311,34 +311,34 @@ typedef struct _tx_desc_cmd_819x_usb {
311 311
312 312
313typedef struct _tx_fwinfo_819x_usb { 313typedef struct _tx_fwinfo_819x_usb {
314 //DOWRD 0 314 //DOWRD 0
315 u8 TxRate:7; 315 u8 TxRate:7;
316 u8 CtsEnable:1; 316 u8 CtsEnable:1;
317 u8 RtsRate:7; 317 u8 RtsRate:7;
318 u8 RtsEnable:1; 318 u8 RtsEnable:1;
319 u8 TxHT:1; 319 u8 TxHT:1;
320 u8 Short:1; //Short PLCP for CCK, or short GI for 11n MCS 320 u8 Short:1; //Short PLCP for CCK, or short GI for 11n MCS
321 u8 TxBandwidth:1; // This is used for HT MCS rate only. 321 u8 TxBandwidth:1; // This is used for HT MCS rate only.
322 u8 TxSubCarrier:2; // This is used for legacy OFDM rate only. 322 u8 TxSubCarrier:2; // This is used for legacy OFDM rate only.
323 u8 STBC:2; 323 u8 STBC:2;
324 u8 AllowAggregation:1; 324 u8 AllowAggregation:1;
325 u8 RtsHT:1; //Interpret RtsRate field as high throughput data rate 325 u8 RtsHT:1; //Interpret RtsRate field as high throughput data rate
326 u8 RtsShort:1; //Short PLCP for CCK, or short GI for 11n MCS 326 u8 RtsShort:1; //Short PLCP for CCK, or short GI for 11n MCS
327 u8 RtsBandwidth:1; // This is used for HT MCS rate only. 327 u8 RtsBandwidth:1; // This is used for HT MCS rate only.
328 u8 RtsSubcarrier:2; // This is used for legacy OFDM rate only. 328 u8 RtsSubcarrier:2; // This is used for legacy OFDM rate only.
329 u8 RtsSTBC:2; 329 u8 RtsSTBC:2;
330 u8 EnableCPUDur:1; //Enable firmware to recalculate and assign packet duration 330 u8 EnableCPUDur:1; //Enable firmware to recalculate and assign packet duration
331 331
332 //DWORD 1 332 //DWORD 1
333 u32 RxMF:2; 333 u32 RxMF:2;
334 u32 RxAMD:3; 334 u32 RxAMD:3;
335 u32 TxPerPktInfoFeedback:1;//1 indicate Tx info gathtered by firmware and returned by Rx Cmd 335 u32 TxPerPktInfoFeedback:1;//1 indicate Tx info gathtered by firmware and returned by Rx Cmd
336 u32 Reserved1:2; 336 u32 Reserved1:2;
337 u32 TxAGCOffSet:4; 337 u32 TxAGCOffSet:4;
338 u32 TxAGCSign:1; 338 u32 TxAGCSign:1;
339 u32 Tx_INFO_RSVD:6; 339 u32 Tx_INFO_RSVD:6;
340 u32 PacketID:13; 340 u32 PacketID:13;
341 //u32 Reserved; 341 //u32 Reserved;
342}tx_fwinfo_819x_usb, *ptx_fwinfo_819x_usb; 342}tx_fwinfo_819x_usb, *ptx_fwinfo_819x_usb;
343 343
344typedef struct rtl8192_rx_info { 344typedef struct rtl8192_rx_info {
@@ -391,7 +391,7 @@ typedef struct _rx_desc_819x_usb_aggr_subframe{
391 //DWORD 2 391 //DWORD 2
392 //u4Byte Reserved3; 392 //u4Byte Reserved3;
393 //DWORD 3 393 //DWORD 3
394 //u4Byte BufferAddress; 394 //u4Byte BufferAddress;
395}rx_desc_819x_usb_aggr_subframe, *prx_desc_819x_usb_aggr_subframe; 395}rx_desc_819x_usb_aggr_subframe, *prx_desc_819x_usb_aggr_subframe;
396#endif 396#endif
397 397
@@ -424,7 +424,7 @@ typedef struct rx_drvinfo_819x_usb{
424#define MAX_802_11_HEADER_LENGTH (40 + MAX_FIRMWARE_INFORMATION_SIZE) 424#define MAX_802_11_HEADER_LENGTH (40 + MAX_FIRMWARE_INFORMATION_SIZE)
425#define ENCRYPTION_MAX_OVERHEAD 128 425#define ENCRYPTION_MAX_OVERHEAD 128
426#define USB_HWDESC_HEADER_LEN sizeof(tx_desc_819x_usb) 426#define USB_HWDESC_HEADER_LEN sizeof(tx_desc_819x_usb)
427#define TX_PACKET_SHIFT_BYTES (USB_HWDESC_HEADER_LEN + sizeof(tx_fwinfo_819x_usb)) 427#define TX_PACKET_SHIFT_BYTES (USB_HWDESC_HEADER_LEN + sizeof(tx_fwinfo_819x_usb))
428#define MAX_FRAGMENT_COUNT 8 428#define MAX_FRAGMENT_COUNT 8
429#ifdef RTL8192U 429#ifdef RTL8192U
430#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE 430#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
@@ -433,7 +433,7 @@ typedef struct rx_drvinfo_819x_usb{
433#define MAX_TRANSMIT_BUFFER_SIZE 8000 433#define MAX_TRANSMIT_BUFFER_SIZE 8000
434#endif 434#endif
435#else 435#else
436#define MAX_TRANSMIT_BUFFER_SIZE (1600+(MAX_802_11_HEADER_LENGTH+ENCRYPTION_MAX_OVERHEAD)*MAX_FRAGMENT_COUNT) 436#define MAX_TRANSMIT_BUFFER_SIZE (1600+(MAX_802_11_HEADER_LENGTH+ENCRYPTION_MAX_OVERHEAD)*MAX_FRAGMENT_COUNT)
437#endif 437#endif
438#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE 438#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
439#define TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES (sizeof(tx_desc_819x_usb_aggr_subframe) + sizeof(tx_fwinfo_819x_usb)) 439#define TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES (sizeof(tx_desc_819x_usb_aggr_subframe) + sizeof(tx_fwinfo_819x_usb))
@@ -559,22 +559,21 @@ typedef enum _WIRELESS_MODE {
559 559
560#define RTL_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30 560#define RTL_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
561 561
562typedef struct buffer 562typedef struct buffer {
563{
564 struct buffer *next; 563 struct buffer *next;
565 u32 *buf; 564 u32 *buf;
566 565
567} buffer; 566} buffer;
568 567
569typedef struct rtl_reg_debug{ 568typedef struct rtl_reg_debug{
570 unsigned int cmd; 569 unsigned int cmd;
571 struct { 570 struct {
572 unsigned char type; 571 unsigned char type;
573 unsigned char addr; 572 unsigned char addr;
574 unsigned char page; 573 unsigned char page;
575 unsigned char length; 574 unsigned char length;
576 } head; 575 } head;
577 unsigned char buf[0xff]; 576 unsigned char buf[0xff];
578}rtl_reg_debug; 577}rtl_reg_debug;
579 578
580 579
@@ -600,8 +599,7 @@ typedef struct _RT_SMOOTH_DATA_4RF {
600 599
601#define MAX_8192U_RX_SIZE 8192 // This maybe changed for D-cut larger aggregation size 600#define MAX_8192U_RX_SIZE 8192 // This maybe changed for D-cut larger aggregation size
602//stats seems messed up, clean it ASAP 601//stats seems messed up, clean it ASAP
603typedef struct Stats 602typedef struct Stats {
604{
605 unsigned long txrdu; 603 unsigned long txrdu;
606// unsigned long rxrdu; 604// unsigned long rxrdu;
607 //unsigned long rxnolast; 605 //unsigned long rxnolast;
@@ -711,7 +709,7 @@ typedef struct Stats
711 709
712//+by amy 080507 710//+by amy 080507
713 711
714typedef struct ChnlAccessSetting { 712typedef struct ChnlAccessSetting {
715 u16 SIFS_Timer; 713 u16 SIFS_Timer;
716 u16 DIFS_Timer; 714 u16 DIFS_Timer;
717 u16 SlotTimeTimer; 715 u16 SlotTimeTimer;
@@ -721,35 +719,34 @@ typedef struct ChnlAccessSetting {
721}*PCHANNEL_ACCESS_SETTING,CHANNEL_ACCESS_SETTING; 719}*PCHANNEL_ACCESS_SETTING,CHANNEL_ACCESS_SETTING;
722 720
723typedef struct _BB_REGISTER_DEFINITION{ 721typedef struct _BB_REGISTER_DEFINITION{
724 u32 rfintfs; // set software control: // 0x870~0x877[8 bytes] 722 u32 rfintfs; // set software control: // 0x870~0x877[8 bytes]
725 u32 rfintfi; // readback data: // 0x8e0~0x8e7[8 bytes] 723 u32 rfintfi; // readback data: // 0x8e0~0x8e7[8 bytes]
726 u32 rfintfo; // output data: // 0x860~0x86f [16 bytes] 724 u32 rfintfo; // output data: // 0x860~0x86f [16 bytes]
727 u32 rfintfe; // output enable: // 0x860~0x86f [16 bytes] 725 u32 rfintfe; // output enable: // 0x860~0x86f [16 bytes]
728 u32 rf3wireOffset; // LSSI data: // 0x840~0x84f [16 bytes] 726 u32 rf3wireOffset; // LSSI data: // 0x840~0x84f [16 bytes]
729 u32 rfLSSI_Select; // BB Band Select: // 0x878~0x87f [8 bytes] 727 u32 rfLSSI_Select; // BB Band Select: // 0x878~0x87f [8 bytes]
730 u32 rfTxGainStage; // Tx gain stage: // 0x80c~0x80f [4 bytes] 728 u32 rfTxGainStage; // Tx gain stage: // 0x80c~0x80f [4 bytes]
731 u32 rfHSSIPara1; // wire parameter control1 : // 0x820~0x823,0x828~0x82b, 0x830~0x833, 0x838~0x83b [16 bytes] 729 u32 rfHSSIPara1; // wire parameter control1 : // 0x820~0x823,0x828~0x82b, 0x830~0x833, 0x838~0x83b [16 bytes]
732 u32 rfHSSIPara2; // wire parameter control2 : // 0x824~0x827,0x82c~0x82f, 0x834~0x837, 0x83c~0x83f [16 bytes] 730 u32 rfHSSIPara2; // wire parameter control2 : // 0x824~0x827,0x82c~0x82f, 0x834~0x837, 0x83c~0x83f [16 bytes]
733 u32 rfSwitchControl; //Tx Rx antenna control : // 0x858~0x85f [16 bytes] 731 u32 rfSwitchControl; //Tx Rx antenna control : // 0x858~0x85f [16 bytes]
734 u32 rfAGCControl1; //AGC parameter control1 : // 0xc50~0xc53,0xc58~0xc5b, 0xc60~0xc63, 0xc68~0xc6b [16 bytes] 732 u32 rfAGCControl1; //AGC parameter control1 : // 0xc50~0xc53,0xc58~0xc5b, 0xc60~0xc63, 0xc68~0xc6b [16 bytes]
735 u32 rfAGCControl2; //AGC parameter control2 : // 0xc54~0xc57,0xc5c~0xc5f, 0xc64~0xc67, 0xc6c~0xc6f [16 bytes] 733 u32 rfAGCControl2; //AGC parameter control2 : // 0xc54~0xc57,0xc5c~0xc5f, 0xc64~0xc67, 0xc6c~0xc6f [16 bytes]
736 u32 rfRxIQImbalance; //OFDM Rx IQ imbalance matrix : // 0xc14~0xc17,0xc1c~0xc1f, 0xc24~0xc27, 0xc2c~0xc2f [16 bytes] 734 u32 rfRxIQImbalance; //OFDM Rx IQ imbalance matrix : // 0xc14~0xc17,0xc1c~0xc1f, 0xc24~0xc27, 0xc2c~0xc2f [16 bytes]
737 u32 rfRxAFE; //Rx IQ DC ofset and Rx digital filter, Rx DC notch filter : // 0xc10~0xc13,0xc18~0xc1b, 0xc20~0xc23, 0xc28~0xc2b [16 bytes] 735 u32 rfRxAFE; //Rx IQ DC ofset and Rx digital filter, Rx DC notch filter : // 0xc10~0xc13,0xc18~0xc1b, 0xc20~0xc23, 0xc28~0xc2b [16 bytes]
738 u32 rfTxIQImbalance; //OFDM Tx IQ imbalance matrix // 0xc80~0xc83,0xc88~0xc8b, 0xc90~0xc93, 0xc98~0xc9b [16 bytes] 736 u32 rfTxIQImbalance; //OFDM Tx IQ imbalance matrix // 0xc80~0xc83,0xc88~0xc8b, 0xc90~0xc93, 0xc98~0xc9b [16 bytes]
739 u32 rfTxAFE; //Tx IQ DC Offset and Tx DFIR type // 0xc84~0xc87,0xc8c~0xc8f, 0xc94~0xc97, 0xc9c~0xc9f [16 bytes] 737 u32 rfTxAFE; //Tx IQ DC Offset and Tx DFIR type // 0xc84~0xc87,0xc8c~0xc8f, 0xc94~0xc97, 0xc9c~0xc9f [16 bytes]
740 u32 rfLSSIReadBack; //LSSI RF readback data // 0x8a0~0x8af [16 bytes] 738 u32 rfLSSIReadBack; //LSSI RF readback data // 0x8a0~0x8af [16 bytes]
741}BB_REGISTER_DEFINITION_T, *PBB_REGISTER_DEFINITION_T; 739}BB_REGISTER_DEFINITION_T, *PBB_REGISTER_DEFINITION_T;
742 740
743typedef enum _RT_RF_TYPE_819xU{ 741typedef enum _RT_RF_TYPE_819xU{
744 RF_TYPE_MIN = 0, 742 RF_TYPE_MIN = 0,
745 RF_8225, 743 RF_8225,
746 RF_8256, 744 RF_8256,
747 RF_8258, 745 RF_8258,
748 RF_PSEUDO_11N = 4, 746 RF_PSEUDO_11N = 4,
749}RT_RF_TYPE_819xU, *PRT_RF_TYPE_819xU; 747}RT_RF_TYPE_819xU, *PRT_RF_TYPE_819xU;
750 748
751typedef struct _rate_adaptive 749typedef struct _rate_adaptive {
752{
753 u8 rate_adaptive_disabled; 750 u8 rate_adaptive_disabled;
754 u8 ratr_state; 751 u8 ratr_state;
755 u16 reserve; 752 u16 reserve;
@@ -775,21 +772,18 @@ typedef struct _rate_adaptive
775#define TxBBGainTableLength 37 772#define TxBBGainTableLength 37
776#define CCKTxBBGainTableLength 23 773#define CCKTxBBGainTableLength 23
777 774
778typedef struct _txbbgain_struct 775typedef struct _txbbgain_struct {
779{
780 long txbb_iq_amplifygain; 776 long txbb_iq_amplifygain;
781 u32 txbbgain_value; 777 u32 txbbgain_value;
782} txbbgain_struct, *ptxbbgain_struct; 778} txbbgain_struct, *ptxbbgain_struct;
783 779
784typedef struct _ccktxbbgain_struct 780typedef struct _ccktxbbgain_struct {
785{
786 //The Value is from a22 to a29 one Byte one time is much Safer 781 //The Value is from a22 to a29 one Byte one time is much Safer
787 u8 ccktxbb_valuearray[8]; 782 u8 ccktxbb_valuearray[8];
788} ccktxbbgain_struct,*pccktxbbgain_struct; 783} ccktxbbgain_struct,*pccktxbbgain_struct;
789 784
790 785
791typedef struct _init_gain 786typedef struct _init_gain {
792{
793 u8 xaagccore1; 787 u8 xaagccore1;
794 u8 xbagccore1; 788 u8 xbagccore1;
795 u8 xcagccore1; 789 u8 xcagccore1;
@@ -799,8 +793,7 @@ typedef struct _init_gain
799} init_gain, *pinit_gain; 793} init_gain, *pinit_gain;
800//by amy 0606 794//by amy 0606
801 795
802typedef struct _phy_ofdm_rx_status_report_819xusb 796typedef struct _phy_ofdm_rx_status_report_819xusb {
803{
804 u8 trsw_gain_X[4]; 797 u8 trsw_gain_X[4];
805 u8 pwdb_all; 798 u8 pwdb_all;
806 u8 cfosho_X[4]; 799 u8 cfosho_X[4];
@@ -816,8 +809,7 @@ typedef struct _phy_ofdm_rx_status_report_819xusb
816 u8 rxsc_sgien_exflg; 809 u8 rxsc_sgien_exflg;
817}phy_sts_ofdm_819xusb_t; 810}phy_sts_ofdm_819xusb_t;
818 811
819typedef struct _phy_cck_rx_status_report_819xusb 812typedef struct _phy_cck_rx_status_report_819xusb {
820{
821 /* For CCK rate descriptor. This is a unsigned 8:1 variable. LSB bit presend 813 /* For CCK rate descriptor. This is a unsigned 8:1 variable. LSB bit presend
822 0.5. And MSB 7 bts presend a signed value. Range from -64~+63.5. */ 814 0.5. And MSB 7 bts presend a signed value. Range from -64~+63.5. */
823 u8 adc_pwdb_X[4]; 815 u8 adc_pwdb_X[4];
@@ -881,8 +873,7 @@ typedef enum _tag_TxCmd_Config_Index{
881 TXCMD_XXXX_CTRL, 873 TXCMD_XXXX_CTRL,
882}DCMD_TXCMD_OP; 874}DCMD_TXCMD_OP;
883 875
884typedef struct r8192_priv 876typedef struct r8192_priv {
885{
886 struct usb_device *udev; 877 struct usb_device *udev;
887 //added for maintain info from eeprom 878 //added for maintain info from eeprom
888 short epromtype; 879 short epromtype;
@@ -907,7 +898,7 @@ typedef struct r8192_priv
907 spinlock_t irq_lock; 898 spinlock_t irq_lock;
908// spinlock_t irq_th_lock; 899// spinlock_t irq_th_lock;
909 spinlock_t tx_lock; 900 spinlock_t tx_lock;
910 struct mutex mutex; 901 struct mutex mutex;
911 //spinlock_t rf_lock; //used to lock rf write operation added by wb 902 //spinlock_t rf_lock; //used to lock rf write operation added by wb
912 903
913 u16 irq_mask; 904 u16 irq_mask;
@@ -970,8 +961,8 @@ typedef struct r8192_priv
970 atomic_t irt_counter;//count for irq_rx_tasklet 961 atomic_t irt_counter;//count for irq_rx_tasklet
971#endif 962#endif
972#ifdef JACKSON_NEW_RX 963#ifdef JACKSON_NEW_RX
973 struct sk_buff **pp_rxskb; 964 struct sk_buff **pp_rxskb;
974 int rx_inx; 965 int rx_inx;
975#endif 966#endif
976 967
977/* modified by davad for Rx process */ 968/* modified by davad for Rx process */
@@ -1006,7 +997,7 @@ typedef struct r8192_priv
1006 u8 retry_rts; 997 u8 retry_rts;
1007 u16 rts; 998 u16 rts;
1008 999
1009 struct ChnlAccessSetting ChannelAccessSetting; 1000 struct ChnlAccessSetting ChannelAccessSetting;
1010 struct work_struct reset_wq; 1001 struct work_struct reset_wq;
1011 1002
1012/**********************************************************/ 1003/**********************************************************/
@@ -1014,7 +1005,7 @@ typedef struct r8192_priv
1014 u16 basic_rate; 1005 u16 basic_rate;
1015 u8 short_preamble; 1006 u8 short_preamble;
1016 u8 slot_time; 1007 u8 slot_time;
1017 bool bDcut; 1008 bool bDcut;
1018 bool bCurrentRxAggrEnable; 1009 bool bCurrentRxAggrEnable;
1019 u8 Rf_Mode; //add for Firmware RF -R/W switch 1010 u8 Rf_Mode; //add for Firmware RF -R/W switch
1020 prt_firmware pFirmware; 1011 prt_firmware pFirmware;
@@ -1050,7 +1041,7 @@ typedef struct r8192_priv
1050 1041
1051 //for set channel 1042 //for set channel
1052 u8 SwChnlInProgress; 1043 u8 SwChnlInProgress;
1053 u8 SwChnlStage; 1044 u8 SwChnlStage;
1054 u8 SwChnlStep; 1045 u8 SwChnlStep;
1055 u8 SetBWModeInProgress; 1046 u8 SetBWModeInProgress;
1056 HT_CHANNEL_WIDTH CurrentChannelBW; 1047 HT_CHANNEL_WIDTH CurrentChannelBW;
@@ -1062,8 +1053,8 @@ typedef struct r8192_priv
1062 // We save RF reg0 in this variable to reduce RF reading. 1053 // We save RF reg0 in this variable to reduce RF reading.
1063 // 1054 //
1064 u32 RfReg0Value[4]; 1055 u32 RfReg0Value[4];
1065 u8 NumTotalRFPath; 1056 u8 NumTotalRFPath;
1066 bool brfpath_rxenable[4]; 1057 bool brfpath_rxenable[4];
1067 //RF set related 1058 //RF set related
1068 bool SetRFPowerStateInProgress; 1059 bool SetRFPowerStateInProgress;
1069//+by amy 080507 1060//+by amy 080507
@@ -1104,7 +1095,7 @@ typedef struct r8192_priv
1104 bool btxpower_tracking; 1095 bool btxpower_tracking;
1105 bool bcck_in_ch14; 1096 bool bcck_in_ch14;
1106 bool btxpowerdata_readfromEEPORM; 1097 bool btxpowerdata_readfromEEPORM;
1107 u16 TSSI_13dBm; 1098 u16 TSSI_13dBm;
1108 //For Backup Initial Gain 1099 //For Backup Initial Gain
1109 init_gain initgain_backup; 1100 init_gain initgain_backup;
1110 u8 DefaultInitialGain[4]; 1101 u8 DefaultInitialGain[4];
@@ -1114,17 +1105,17 @@ typedef struct r8192_priv
1114 bool bis_cur_rdlstate; 1105 bool bis_cur_rdlstate;
1115 struct timer_list fsync_timer; 1106 struct timer_list fsync_timer;
1116 bool bfsync_processing; // 500ms Fsync timer is active or not 1107 bool bfsync_processing; // 500ms Fsync timer is active or not
1117 u32 rate_record; 1108 u32 rate_record;
1118 u32 rateCountDiffRecord; 1109 u32 rateCountDiffRecord;
1119 u32 ContinueDiffCount; 1110 u32 ContinueDiffCount;
1120 bool bswitch_fsync; 1111 bool bswitch_fsync;
1121 1112
1122 u8 framesync; 1113 u8 framesync;
1123 u32 framesyncC34; 1114 u32 framesyncC34;
1124 u8 framesyncMonitor; 1115 u8 framesyncMonitor;
1125 //Added by amy 080516 for RX related 1116 //Added by amy 080516 for RX related
1126 u16 nrxAMPDU_size; 1117 u16 nrxAMPDU_size;
1127 u8 nrxAMPDU_aggr_num; 1118 u8 nrxAMPDU_aggr_num;
1128 1119
1129 //by amy for gpio 1120 //by amy for gpio
1130 bool bHwRadioOff; 1121 bool bHwRadioOff;
@@ -1204,7 +1195,7 @@ typedef enum{
1204#ifdef JOHN_HWSEC 1195#ifdef JOHN_HWSEC
1205struct ssid_thread { 1196struct ssid_thread {
1206 struct net_device *dev; 1197 struct net_device *dev;
1207 u8 name[IW_ESSID_MAX_SIZE + 1]; 1198 u8 name[IW_ESSID_MAX_SIZE + 1];
1208}; 1199};
1209#endif 1200#endif
1210 1201
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 56367f23112f..f7de2f6d49a5 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -80,9 +80,9 @@ double __extendsfdf2(float a) {return a;}
80#include "dot11d.h" 80#include "dot11d.h"
81//set here to open your trace code. //WB 81//set here to open your trace code. //WB
82u32 rt_global_debug_component = \ 82u32 rt_global_debug_component = \
83 // COMP_INIT | 83 // COMP_INIT |
84// COMP_DBG | 84// COMP_DBG |
85 // COMP_EPROM | 85 // COMP_EPROM |
86// COMP_PHY | 86// COMP_PHY |
87 // COMP_RF | 87 // COMP_RF |
88// COMP_FIRMWARE | 88// COMP_FIRMWARE |
@@ -159,23 +159,22 @@ static struct usb_driver rtl8192_usb_driver = {
159 .resume = rtl8192_resume, /* PM resume fn */ 159 .resume = rtl8192_resume, /* PM resume fn */
160#else 160#else
161 .suspend = NULL, /* PM suspend fn */ 161 .suspend = NULL, /* PM suspend fn */
162 .resume = NULL, /* PM resume fn */ 162 .resume = NULL, /* PM resume fn */
163#endif 163#endif
164}; 164};
165 165
166 166
167typedef struct _CHANNEL_LIST 167typedef struct _CHANNEL_LIST {
168{
169 u8 Channel[32]; 168 u8 Channel[32];
170 u8 Len; 169 u8 Len;
171}CHANNEL_LIST, *PCHANNEL_LIST; 170}CHANNEL_LIST, *PCHANNEL_LIST;
172 171
173static CHANNEL_LIST ChannelPlan[] = { 172static CHANNEL_LIST ChannelPlan[] = {
174 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, //FCC 173 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, //FCC
175 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC 174 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
176 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI 175 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
177 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI. 176 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
178 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI. 177 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
179 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, //MKK //MKK 178 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, //MKK //MKK
180 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1 179 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
181 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel. 180 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
@@ -190,57 +189,51 @@ static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
190 struct ieee80211_device* ieee = priv->ieee80211; 189 struct ieee80211_device* ieee = priv->ieee80211;
191 switch (channel_plan) 190 switch (channel_plan)
192 { 191 {
193 case COUNTRY_CODE_FCC: 192 case COUNTRY_CODE_FCC:
194 case COUNTRY_CODE_IC: 193 case COUNTRY_CODE_IC:
195 case COUNTRY_CODE_ETSI: 194 case COUNTRY_CODE_ETSI:
196 case COUNTRY_CODE_SPAIN: 195 case COUNTRY_CODE_SPAIN:
197 case COUNTRY_CODE_FRANCE: 196 case COUNTRY_CODE_FRANCE:
198 case COUNTRY_CODE_MKK: 197 case COUNTRY_CODE_MKK:
199 case COUNTRY_CODE_MKK1: 198 case COUNTRY_CODE_MKK1:
200 case COUNTRY_CODE_ISRAEL: 199 case COUNTRY_CODE_ISRAEL:
201 case COUNTRY_CODE_TELEC: 200 case COUNTRY_CODE_TELEC:
202 case COUNTRY_CODE_MIC: 201 case COUNTRY_CODE_MIC:
203 { 202 Dot11d_Init(ieee);
204 Dot11d_Init(ieee); 203 ieee->bGlobalDomain = false;
205 ieee->bGlobalDomain = false; 204 //actually 8225 & 8256 rf chips only support B,G,24N mode
206 //actually 8225 & 8256 rf chips only support B,G,24N mode 205 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) {
207 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) 206 min_chan = 1;
208 { 207 max_chan = 14;
209 min_chan = 1; 208 }
210 max_chan = 14; 209 else {
211 } 210 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__);
212 else 211 }
213 { 212 if (ChannelPlan[channel_plan].Len != 0) {
214 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__); 213 // Clear old channel map
215 } 214 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
216 if (ChannelPlan[channel_plan].Len != 0){ 215 // Set new channel map
217 // Clear old channel map 216 for (i=0;i<ChannelPlan[channel_plan].Len;i++) {
218 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map)); 217 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
219 // Set new channel map
220 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
221 {
222 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
223 break; 218 break;
224 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1; 219 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
225 }
226 } 220 }
227 break;
228 } 221 }
229 case COUNTRY_CODE_GLOBAL_DOMAIN: 222 break;
230 { 223
231 GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings. 224 case COUNTRY_CODE_GLOBAL_DOMAIN:
232 Dot11d_Reset(ieee); 225 GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings.
233 ieee->bGlobalDomain = true; 226 Dot11d_Reset(ieee);
234 break; 227 ieee->bGlobalDomain = true;
235 } 228 break;
236 default: 229
237 break; 230 default:
231 break;
238 } 232 }
239 return;
240} 233}
241 234
242 235
243#define rx_hal_is_cck_rate(_pdrvinfo)\ 236#define rx_hal_is_cck_rate(_pdrvinfo)\
244 (_pdrvinfo->RxRate == DESC90_RATE1M ||\ 237 (_pdrvinfo->RxRate == DESC90_RATE1M ||\
245 _pdrvinfo->RxRate == DESC90_RATE2M ||\ 238 _pdrvinfo->RxRate == DESC90_RATE2M ||\
246 _pdrvinfo->RxRate == DESC90_RATE5_5M ||\ 239 _pdrvinfo->RxRate == DESC90_RATE5_5M ||\
@@ -516,55 +509,50 @@ static int proc_get_registers(char *page, char **start,
516 int max=0xff; 509 int max=0xff;
517 510
518 /* This dump the current register page */ 511 /* This dump the current register page */
519len += snprintf(page + len, count - len, 512 len += snprintf(page + len, count - len,
520 "\n####################page 0##################\n "); 513 "\n####################page 0##################\n ");
521 514
522 for(n=0;n<=max;) 515 for (n=0;n<=max;) {
523 {
524 //printk( "\nD: %2x> ", n); 516 //printk( "\nD: %2x> ", n);
525 len += snprintf(page + len, count - len, 517 len += snprintf(page + len, count - len,
526 "\nD: %2x > ",n); 518 "\nD: %2x > ",n);
527 519
528 for(i=0;i<16 && n<=max;i++,n++) 520 for (i=0;i<16 && n<=max;i++,n++)
529 len += snprintf(page + len, count - len, 521 len += snprintf(page + len, count - len,
530 "%2x ",read_nic_byte(dev,0x000|n)); 522 "%2x ",read_nic_byte(dev,0x000|n));
531 523
532 // printk("%2x ",read_nic_byte(dev,n)); 524 // printk("%2x ",read_nic_byte(dev,n));
533 } 525 }
534len += snprintf(page + len, count - len, 526 len += snprintf(page + len, count - len,
535 "\n####################page 1##################\n "); 527 "\n####################page 1##################\n ");
536 for(n=0;n<=max;) 528 for (n=0;n<=max;) {
537 {
538 //printk( "\nD: %2x> ", n); 529 //printk( "\nD: %2x> ", n);
539 len += snprintf(page + len, count - len, 530 len += snprintf(page + len, count - len,
540 "\nD: %2x > ",n); 531 "\nD: %2x > ",n);
541 532
542 for(i=0;i<16 && n<=max;i++,n++) 533 for (i=0;i<16 && n<=max;i++,n++)
543 len += snprintf(page + len, count - len, 534 len += snprintf(page + len, count - len,
544 "%2x ",read_nic_byte(dev,0x100|n)); 535 "%2x ",read_nic_byte(dev,0x100|n));
545 536
546 // printk("%2x ",read_nic_byte(dev,n)); 537 // printk("%2x ",read_nic_byte(dev,n));
547 } 538 }
548len += snprintf(page + len, count - len, 539 len += snprintf(page + len, count - len,
549 "\n####################page 3##################\n "); 540 "\n####################page 3##################\n ");
550 for(n=0;n<=max;) 541 for (n=0;n<=max;) {
551 {
552 //printk( "\nD: %2x> ", n); 542 //printk( "\nD: %2x> ", n);
553 len += snprintf(page + len, count - len, 543 len += snprintf(page + len, count - len,
554 "\nD: %2x > ",n); 544 "\nD: %2x > ",n);
555 545
556 for(i=0;i<16 && n<=max;i++,n++) 546 for(i=0;i<16 && n<=max;i++,n++)
557 len += snprintf(page + len, count - len, 547 len += snprintf(page + len, count - len,
558 "%2x ",read_nic_byte(dev,0x300|n)); 548 "%2x ",read_nic_byte(dev,0x300|n));
559 549
560 // printk("%2x ",read_nic_byte(dev,n)); 550 // printk("%2x ",read_nic_byte(dev,n));
561 } 551 }
562 552
563
564 len += snprintf(page + len, count - len,"\n"); 553 len += snprintf(page + len, count - len,"\n");
565 *eof = 1; 554 *eof = 1;
566 return len; 555 return len;
567
568} 556}
569 557
570 558
@@ -1272,8 +1260,8 @@ struct sk_buff *DrvAggr_Aggregation(struct net_device *dev, struct ieee80211_drv
1272{ 1260{
1273 struct ieee80211_device *ieee = netdev_priv(dev); 1261 struct ieee80211_device *ieee = netdev_priv(dev);
1274 struct r8192_priv *priv = ieee80211_priv(dev); 1262 struct r8192_priv *priv = ieee80211_priv(dev);
1275 cb_desc *tcb_desc = NULL; 1263 cb_desc *tcb_desc = NULL;
1276 u8 i; 1264 u8 i;
1277 u32 TotalLength; 1265 u32 TotalLength;
1278 struct sk_buff *skb; 1266 struct sk_buff *skb;
1279 struct sk_buff *agg_skb; 1267 struct sk_buff *agg_skb;
@@ -1444,7 +1432,7 @@ u8 DrvAggr_GetAggregatibleList(struct net_device *dev, struct sk_buff *skb,
1444 struct ieee80211_device *ieee = netdev_priv(dev); 1432 struct ieee80211_device *ieee = netdev_priv(dev);
1445 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 1433 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1446 u16 nMaxAggrNum = pHTInfo->UsbTxAggrNum; 1434 u16 nMaxAggrNum = pHTInfo->UsbTxAggrNum;
1447 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 1435 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1448 u8 QueueID = tcb_desc->queue_index; 1436 u8 QueueID = tcb_desc->queue_index;
1449 1437
1450 do { 1438 do {
@@ -1812,7 +1800,7 @@ short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1812 int status; 1800 int status;
1813 struct urb *tx_urb; 1801 struct urb *tx_urb;
1814 //int urb_buf_len; 1802 //int urb_buf_len;
1815 unsigned int idx_pipe; 1803 unsigned int idx_pipe;
1816 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data; 1804 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
1817 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 1805 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1818 u8 queue_index = tcb_desc->queue_index; 1806 u8 queue_index = tcb_desc->queue_index;
@@ -1876,43 +1864,43 @@ u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1876 u8 QueueSelect = 0x0; //defualt set to 1864 u8 QueueSelect = 0x0; //defualt set to
1877 1865
1878 switch(QueueID) { 1866 switch(QueueID) {
1879 case BE_QUEUE: 1867 case BE_QUEUE:
1880 QueueSelect = QSLT_BE; //or QSelect = pTcb->priority; 1868 QueueSelect = QSLT_BE; //or QSelect = pTcb->priority;
1881 break; 1869 break;
1882 1870
1883 case BK_QUEUE: 1871 case BK_QUEUE:
1884 QueueSelect = QSLT_BK; //or QSelect = pTcb->priority; 1872 QueueSelect = QSLT_BK; //or QSelect = pTcb->priority;
1885 break; 1873 break;
1886 1874
1887 case VO_QUEUE: 1875 case VO_QUEUE:
1888 QueueSelect = QSLT_VO; //or QSelect = pTcb->priority; 1876 QueueSelect = QSLT_VO; //or QSelect = pTcb->priority;
1889 break; 1877 break;
1890 1878
1891 case VI_QUEUE: 1879 case VI_QUEUE:
1892 QueueSelect = QSLT_VI; //or QSelect = pTcb->priority; 1880 QueueSelect = QSLT_VI; //or QSelect = pTcb->priority;
1893 break; 1881 break;
1894 case MGNT_QUEUE: 1882 case MGNT_QUEUE:
1895 QueueSelect = QSLT_MGNT; 1883 QueueSelect = QSLT_MGNT;
1896 break; 1884 break;
1897 1885
1898 case BEACON_QUEUE: 1886 case BEACON_QUEUE:
1899 QueueSelect = QSLT_BEACON; 1887 QueueSelect = QSLT_BEACON;
1900 break; 1888 break;
1901 1889
1902 // TODO: 2006.10.30 mark other queue selection until we verify it is OK 1890 // TODO: 2006.10.30 mark other queue selection until we verify it is OK
1903 // TODO: Remove Assertions 1891 // TODO: Remove Assertions
1904//#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502) 1892//#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502)
1905 case TXCMD_QUEUE: 1893 case TXCMD_QUEUE:
1906 QueueSelect = QSLT_CMD; 1894 QueueSelect = QSLT_CMD;
1907 break; 1895 break;
1908//#endif 1896//#endif
1909 case HIGH_QUEUE: 1897 case HIGH_QUEUE:
1910 QueueSelect = QSLT_HIGH; 1898 QueueSelect = QSLT_HIGH;
1911 break; 1899 break;
1912 1900
1913 default: 1901 default:
1914 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID); 1902 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
1915 break; 1903 break;
1916 } 1904 }
1917 return QueueSelect; 1905 return QueueSelect;
1918} 1906}
@@ -1922,39 +1910,39 @@ u8 MRateToHwRate8190Pci(u8 rate)
1922 u8 ret = DESC90_RATE1M; 1910 u8 ret = DESC90_RATE1M;
1923 1911
1924 switch(rate) { 1912 switch(rate) {
1925 case MGN_1M: ret = DESC90_RATE1M; break; 1913 case MGN_1M: ret = DESC90_RATE1M; break;
1926 case MGN_2M: ret = DESC90_RATE2M; break; 1914 case MGN_2M: ret = DESC90_RATE2M; break;
1927 case MGN_5_5M: ret = DESC90_RATE5_5M; break; 1915 case MGN_5_5M: ret = DESC90_RATE5_5M; break;
1928 case MGN_11M: ret = DESC90_RATE11M; break; 1916 case MGN_11M: ret = DESC90_RATE11M; break;
1929 case MGN_6M: ret = DESC90_RATE6M; break; 1917 case MGN_6M: ret = DESC90_RATE6M; break;
1930 case MGN_9M: ret = DESC90_RATE9M; break; 1918 case MGN_9M: ret = DESC90_RATE9M; break;
1931 case MGN_12M: ret = DESC90_RATE12M; break; 1919 case MGN_12M: ret = DESC90_RATE12M; break;
1932 case MGN_18M: ret = DESC90_RATE18M; break; 1920 case MGN_18M: ret = DESC90_RATE18M; break;
1933 case MGN_24M: ret = DESC90_RATE24M; break; 1921 case MGN_24M: ret = DESC90_RATE24M; break;
1934 case MGN_36M: ret = DESC90_RATE36M; break; 1922 case MGN_36M: ret = DESC90_RATE36M; break;
1935 case MGN_48M: ret = DESC90_RATE48M; break; 1923 case MGN_48M: ret = DESC90_RATE48M; break;
1936 case MGN_54M: ret = DESC90_RATE54M; break; 1924 case MGN_54M: ret = DESC90_RATE54M; break;
1937 1925
1938 // HT rate since here 1926 // HT rate since here
1939 case MGN_MCS0: ret = DESC90_RATEMCS0; break; 1927 case MGN_MCS0: ret = DESC90_RATEMCS0; break;
1940 case MGN_MCS1: ret = DESC90_RATEMCS1; break; 1928 case MGN_MCS1: ret = DESC90_RATEMCS1; break;
1941 case MGN_MCS2: ret = DESC90_RATEMCS2; break; 1929 case MGN_MCS2: ret = DESC90_RATEMCS2; break;
1942 case MGN_MCS3: ret = DESC90_RATEMCS3; break; 1930 case MGN_MCS3: ret = DESC90_RATEMCS3; break;
1943 case MGN_MCS4: ret = DESC90_RATEMCS4; break; 1931 case MGN_MCS4: ret = DESC90_RATEMCS4; break;
1944 case MGN_MCS5: ret = DESC90_RATEMCS5; break; 1932 case MGN_MCS5: ret = DESC90_RATEMCS5; break;
1945 case MGN_MCS6: ret = DESC90_RATEMCS6; break; 1933 case MGN_MCS6: ret = DESC90_RATEMCS6; break;
1946 case MGN_MCS7: ret = DESC90_RATEMCS7; break; 1934 case MGN_MCS7: ret = DESC90_RATEMCS7; break;
1947 case MGN_MCS8: ret = DESC90_RATEMCS8; break; 1935 case MGN_MCS8: ret = DESC90_RATEMCS8; break;
1948 case MGN_MCS9: ret = DESC90_RATEMCS9; break; 1936 case MGN_MCS9: ret = DESC90_RATEMCS9; break;
1949 case MGN_MCS10: ret = DESC90_RATEMCS10; break; 1937 case MGN_MCS10: ret = DESC90_RATEMCS10; break;
1950 case MGN_MCS11: ret = DESC90_RATEMCS11; break; 1938 case MGN_MCS11: ret = DESC90_RATEMCS11; break;
1951 case MGN_MCS12: ret = DESC90_RATEMCS12; break; 1939 case MGN_MCS12: ret = DESC90_RATEMCS12; break;
1952 case MGN_MCS13: ret = DESC90_RATEMCS13; break; 1940 case MGN_MCS13: ret = DESC90_RATEMCS13; break;
1953 case MGN_MCS14: ret = DESC90_RATEMCS14; break; 1941 case MGN_MCS14: ret = DESC90_RATEMCS14; break;
1954 case MGN_MCS15: ret = DESC90_RATEMCS15; break; 1942 case MGN_MCS15: ret = DESC90_RATEMCS15; break;
1955 case (0x80|0x20): ret = DESC90_RATEMCS32; break; 1943 case (0x80|0x20): ret = DESC90_RATEMCS32; break;
1956 1944
1957 default: break; 1945 default: break;
1958 } 1946 }
1959 return ret; 1947 return ret;
1960} 1948}
@@ -2182,7 +2170,7 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
2182 dev->trans_start = jiffies; 2170 dev->trans_start = jiffies;
2183 atomic_inc(&priv->tx_pending[tcb_desc->queue_index]); 2171 atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
2184 return 0; 2172 return 0;
2185 }else{ 2173 } else {
2186 RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), 2174 RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
2187 status); 2175 status);
2188 return -1; 2176 return -1;
@@ -2320,33 +2308,33 @@ void rtl8192_link_change(struct net_device *dev)
2320// RT_TRACE(COMP_CH, "========>%s(), chan:%d\n", __FUNCTION__, priv->chan); 2308// RT_TRACE(COMP_CH, "========>%s(), chan:%d\n", __FUNCTION__, priv->chan);
2321// rtl8192_set_chan(dev, priv->chan); 2309// rtl8192_set_chan(dev, priv->chan);
2322 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) 2310 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
2323 { 2311 {
2324 u32 reg = 0; 2312 u32 reg = 0;
2325 reg = read_nic_dword(dev, RCR); 2313 reg = read_nic_dword(dev, RCR);
2326 if (priv->ieee80211->state == IEEE80211_LINKED) 2314 if (priv->ieee80211->state == IEEE80211_LINKED)
2327 priv->ReceiveConfig = reg |= RCR_CBSSID; 2315 priv->ReceiveConfig = reg |= RCR_CBSSID;
2328 else 2316 else
2329 priv->ReceiveConfig = reg &= ~RCR_CBSSID; 2317 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
2330 write_nic_dword(dev, RCR, reg); 2318 write_nic_dword(dev, RCR, reg);
2331 } 2319 }
2332 2320
2333// rtl8192_set_rxconf(dev); 2321// rtl8192_set_rxconf(dev);
2334} 2322}
2335 2323
2336static struct ieee80211_qos_parameters def_qos_parameters = { 2324static struct ieee80211_qos_parameters def_qos_parameters = {
2337 {3,3,3,3},/* cw_min */ 2325 {3,3,3,3},/* cw_min */
2338 {7,7,7,7},/* cw_max */ 2326 {7,7,7,7},/* cw_max */
2339 {2,2,2,2},/* aifs */ 2327 {2,2,2,2},/* aifs */
2340 {0,0,0,0},/* flags */ 2328 {0,0,0,0},/* flags */
2341 {0,0,0,0} /* tx_op_limit */ 2329 {0,0,0,0} /* tx_op_limit */
2342}; 2330};
2343 2331
2344 2332
2345void rtl8192_update_beacon(struct work_struct * work) 2333void rtl8192_update_beacon(struct work_struct * work)
2346{ 2334{
2347 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work); 2335 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
2348 struct net_device *dev = priv->ieee80211->dev; 2336 struct net_device *dev = priv->ieee80211->dev;
2349 struct ieee80211_device* ieee = priv->ieee80211; 2337 struct ieee80211_device* ieee = priv->ieee80211;
2350 struct ieee80211_network* net = &ieee->current_network; 2338 struct ieee80211_network* net = &ieee->current_network;
2351 2339
2352 if (ieee->pHTInfo->bCurrentHTSupport) 2340 if (ieee->pHTInfo->bCurrentHTSupport)
@@ -2717,7 +2705,7 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
2717 priv->bDisableNormalResetCheck = false; 2705 priv->bDisableNormalResetCheck = false;
2718 priv->force_reset = false; 2706 priv->force_reset = false;
2719 2707
2720 priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available. 2708 priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available.
2721 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL; 2709 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2722 priv->ieee80211->iw_mode = IW_MODE_INFRA; 2710 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2723 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN | 2711 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
@@ -2778,11 +2766,11 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
2778#ifdef TO_DO_LIST 2766#ifdef TO_DO_LIST
2779 if(Adapter->bInHctTest) 2767 if(Adapter->bInHctTest)
2780 pHalData->ReceiveConfig = pHalData->CSMethod | 2768 pHalData->ReceiveConfig = pHalData->CSMethod |
2781 RCR_AMF | RCR_ADF | //RCR_AAP | //accept management/data 2769 RCR_AMF | RCR_ADF | //RCR_AAP | //accept management/data
2782 //guangan200710 2770 //guangan200710
2783 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko. 2771 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2784 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC 2772 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2785 RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet 2773 RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
2786 ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited. 2774 ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
2787 (pHalData->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold. 2775 (pHalData->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
2788 (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt:0); 2776 (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt:0);
@@ -2793,7 +2781,7 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
2793 RCR_AMF | RCR_ADF | //accept management/data 2781 RCR_AMF | RCR_ADF | //accept management/data
2794 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko. 2782 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
2795 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC 2783 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
2796 //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet 2784 //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
2797 ((u32)7<<RCR_MXDMA_OFFSET)| // Max DMA Burst Size per Rx DMA Burst, 7: unlimited. 2785 ((u32)7<<RCR_MXDMA_OFFSET)| // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
2798 (priv->EarlyRxThreshold<<RX_FIFO_THRESHOLD_SHIFT) | // Rx FIFO Threshold, 7: No Rx threshold. 2786 (priv->EarlyRxThreshold<<RX_FIFO_THRESHOLD_SHIFT) | // Rx FIFO Threshold, 7: No Rx threshold.
2799 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0); 2787 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0);
@@ -3549,7 +3537,7 @@ HalTxCheckStuck819xUsb(
3549 ) 3537 )
3550{ 3538{
3551 struct r8192_priv *priv = ieee80211_priv(dev); 3539 struct r8192_priv *priv = ieee80211_priv(dev);
3552 u16 RegTxCounter = read_nic_word(dev, 0x128); 3540 u16 RegTxCounter = read_nic_word(dev, 0x128);
3553 bool bStuck = FALSE; 3541 bool bStuck = FALSE;
3554 RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter); 3542 RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
3555 if(priv->TxCounter==RegTxCounter) 3543 if(priv->TxCounter==RegTxCounter)
@@ -3583,16 +3571,16 @@ TxCheckStuck(struct net_device *dev)
3583// spin_lock_irqsave(&priv->ieee80211->lock,flags); 3571// spin_lock_irqsave(&priv->ieee80211->lock,flags);
3584 for (QueueID = 0; QueueID<=BEACON_QUEUE;QueueID ++) 3572 for (QueueID = 0; QueueID<=BEACON_QUEUE;QueueID ++)
3585 { 3573 {
3586 if(QueueID == TXCMD_QUEUE) 3574 if(QueueID == TXCMD_QUEUE)
3587 continue; 3575 continue;
3588#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE 3576#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
3589 if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0)) 3577 if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0))
3590#else 3578#else
3591 if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0)) 3579 if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
3592#endif 3580#endif
3593 continue; 3581 continue;
3594 3582
3595 bCheckFwTxCnt = true; 3583 bCheckFwTxCnt = true;
3596 } 3584 }
3597// PlatformReleaseSpinLock(Adapter, RT_TX_SPINLOCK); 3585// PlatformReleaseSpinLock(Adapter, RT_TX_SPINLOCK);
3598// spin_unlock_irqrestore(&priv->ieee80211->lock,flags); 3586// spin_unlock_irqrestore(&priv->ieee80211->lock,flags);
@@ -3611,10 +3599,10 @@ TxCheckStuck(struct net_device *dev)
3611bool 3599bool
3612HalRxCheckStuck819xUsb(struct net_device *dev) 3600HalRxCheckStuck819xUsb(struct net_device *dev)
3613{ 3601{
3614 u16 RegRxCounter = read_nic_word(dev, 0x130); 3602 u16 RegRxCounter = read_nic_word(dev, 0x130);
3615 struct r8192_priv *priv = ieee80211_priv(dev); 3603 struct r8192_priv *priv = ieee80211_priv(dev);
3616 bool bStuck = FALSE; 3604 bool bStuck = FALSE;
3617 static u8 rx_chk_cnt = 0; 3605 static u8 rx_chk_cnt;
3618 RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter); 3606 RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter);
3619 // If rssi is small, we should check rx for long time because of bad rx. 3607 // If rssi is small, we should check rx for long time because of bad rx.
3620 // or maybe it will continuous silent reset every 2 seconds. 3608 // or maybe it will continuous silent reset every 2 seconds.
@@ -3718,7 +3706,7 @@ rtl819x_ifcheck_resetornot(struct net_device *dev)
3718 struct r8192_priv *priv = ieee80211_priv(dev); 3706 struct r8192_priv *priv = ieee80211_priv(dev);
3719 RESET_TYPE TxResetType = RESET_TYPE_NORESET; 3707 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
3720 RESET_TYPE RxResetType = RESET_TYPE_NORESET; 3708 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
3721 RT_RF_POWER_STATE rfState; 3709 RT_RF_POWER_STATE rfState;
3722 3710
3723 rfState = priv->ieee80211->eRFPowerState; 3711 rfState = priv->ieee80211->eRFPowerState;
3724 3712
@@ -4006,18 +3994,18 @@ RESET_START:
4006 3994
4007void CAM_read_entry( 3995void CAM_read_entry(
4008 struct net_device *dev, 3996 struct net_device *dev,
4009 u32 iIndex 3997 u32 iIndex
4010) 3998)
4011{ 3999{
4012 u32 target_command=0; 4000 u32 target_command=0;
4013 u32 target_content=0; 4001 u32 target_content=0;
4014 u8 entry_i=0; 4002 u8 entry_i=0;
4015 u32 ulStatus; 4003 u32 ulStatus;
4016 s32 i=100; 4004 s32 i=100;
4017// printk("=======>start read CAM\n"); 4005// printk("=======>start read CAM\n");
4018 for(entry_i=0;entry_i<CAM_CONTENT_COUNT;entry_i++) 4006 for(entry_i=0;entry_i<CAM_CONTENT_COUNT;entry_i++)
4019 { 4007 {
4020 // polling bit, and No Write enable, and address 4008 // polling bit, and No Write enable, and address
4021 target_command= entry_i+CAM_CONTENT_COUNT*iIndex; 4009 target_command= entry_i+CAM_CONTENT_COUNT*iIndex;
4022 target_command= target_command | BIT31; 4010 target_command= target_command | BIT31;
4023 4011
@@ -4049,7 +4037,7 @@ void rtl819x_update_rxcounts(
4049 u32* TotalRxDataNum 4037 u32* TotalRxDataNum
4050) 4038)
4051{ 4039{
4052 u16 SlotIndex; 4040 u16 SlotIndex;
4053 u8 i; 4041 u8 i;
4054 4042
4055 *TotalRxBcnNum = 0; 4043 *TotalRxBcnNum = 0;
@@ -4072,7 +4060,7 @@ extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
4072 struct net_device *dev = priv->ieee80211->dev; 4060 struct net_device *dev = priv->ieee80211->dev;
4073 struct ieee80211_device* ieee = priv->ieee80211; 4061 struct ieee80211_device* ieee = priv->ieee80211;
4074 RESET_TYPE ResetType = RESET_TYPE_NORESET; 4062 RESET_TYPE ResetType = RESET_TYPE_NORESET;
4075 static u8 check_reset_cnt=0; 4063 static u8 check_reset_cnt;
4076 bool bBusyTraffic = false; 4064 bool bBusyTraffic = false;
4077 4065
4078 if(!priv->up) 4066 if(!priv->up)
@@ -4111,7 +4099,7 @@ extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
4111 notify_wx_assoc_event(priv->ieee80211); 4099 notify_wx_assoc_event(priv->ieee80211);
4112 RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid); 4100 RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid);
4113 priv->ieee80211->link_change(dev); 4101 priv->ieee80211->link_change(dev);
4114 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq); 4102 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
4115 4103
4116 } 4104 }
4117 } 4105 }
@@ -4122,7 +4110,7 @@ extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
4122 //check if reset the driver 4110 //check if reset the driver
4123 if(check_reset_cnt++ >= 3) 4111 if(check_reset_cnt++ >= 3)
4124 { 4112 {
4125 ResetType = rtl819x_ifcheck_resetornot(dev); 4113 ResetType = rtl819x_ifcheck_resetornot(dev);
4126 check_reset_cnt = 3; 4114 check_reset_cnt = 3;
4127 //DbgPrint("Start to check silent reset\n"); 4115 //DbgPrint("Start to check silent reset\n");
4128 } 4116 }
@@ -4365,66 +4353,66 @@ int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
4365 } 4353 }
4366 4354
4367 switch (cmd) { 4355 switch (cmd) {
4368 case RTL_IOCTL_WPA_SUPPLICANT: 4356 case RTL_IOCTL_WPA_SUPPLICANT:
4369 //parse here for HW security 4357 //parse here for HW security
4370 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) 4358 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
4359 {
4360 if (ipw->u.crypt.set_tx)
4371 { 4361 {
4372 if (ipw->u.crypt.set_tx) 4362 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
4363 ieee->pairwise_key_type = KEY_TYPE_CCMP;
4364 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
4365 ieee->pairwise_key_type = KEY_TYPE_TKIP;
4366 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
4373 { 4367 {
4374 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) 4368 if (ipw->u.crypt.key_len == 13)
4375 ieee->pairwise_key_type = KEY_TYPE_CCMP; 4369 ieee->pairwise_key_type = KEY_TYPE_WEP104;
4376 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) 4370 else if (ipw->u.crypt.key_len == 5)
4377 ieee->pairwise_key_type = KEY_TYPE_TKIP; 4371 ieee->pairwise_key_type = KEY_TYPE_WEP40;
4378 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
4379 {
4380 if (ipw->u.crypt.key_len == 13)
4381 ieee->pairwise_key_type = KEY_TYPE_WEP104;
4382 else if (ipw->u.crypt.key_len == 5)
4383 ieee->pairwise_key_type = KEY_TYPE_WEP40;
4384 }
4385 else
4386 ieee->pairwise_key_type = KEY_TYPE_NA;
4387
4388 if (ieee->pairwise_key_type)
4389 {
4390 memcpy((u8*)key, ipw->u.crypt.key, 16);
4391 EnableHWSecurityConfig8192(dev);
4392 //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
4393 //added by WB.
4394 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4395 if (ieee->auth_mode != 2)
4396 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4397 }
4398 } 4372 }
4399 else //if (ipw->u.crypt.idx) //group key use idx > 0 4373 else
4374 ieee->pairwise_key_type = KEY_TYPE_NA;
4375
4376 if (ieee->pairwise_key_type)
4400 { 4377 {
4401 memcpy((u8*)key, ipw->u.crypt.key, 16); 4378 memcpy((u8*)key, ipw->u.crypt.key, 16);
4402 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) 4379 EnableHWSecurityConfig8192(dev);
4403 ieee->group_key_type= KEY_TYPE_CCMP; 4380 //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
4404 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) 4381 //added by WB.
4405 ieee->group_key_type = KEY_TYPE_TKIP; 4382 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4406 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) 4383 if (ieee->auth_mode != 2)
4407 { 4384 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
4408 if (ipw->u.crypt.key_len == 13) 4385 }
4409 ieee->group_key_type = KEY_TYPE_WEP104; 4386 }
4410 else if (ipw->u.crypt.key_len == 5) 4387 else //if (ipw->u.crypt.idx) //group key use idx > 0
4411 ieee->group_key_type = KEY_TYPE_WEP40; 4388 {
4412 } 4389 memcpy((u8*)key, ipw->u.crypt.key, 16);
4413 else 4390 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
4414 ieee->group_key_type = KEY_TYPE_NA; 4391 ieee->group_key_type= KEY_TYPE_CCMP;
4392 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
4393 ieee->group_key_type = KEY_TYPE_TKIP;
4394 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
4395 {
4396 if (ipw->u.crypt.key_len == 13)
4397 ieee->group_key_type = KEY_TYPE_WEP104;
4398 else if (ipw->u.crypt.key_len == 5)
4399 ieee->group_key_type = KEY_TYPE_WEP40;
4400 }
4401 else
4402 ieee->group_key_type = KEY_TYPE_NA;
4415 4403
4416 if (ieee->group_key_type) 4404 if (ieee->group_key_type)
4417 { 4405 {
4418 setKey( dev, 4406 setKey( dev,
4419 ipw->u.crypt.idx, 4407 ipw->u.crypt.idx,
4420 ipw->u.crypt.idx, //KeyIndex 4408 ipw->u.crypt.idx, //KeyIndex
4421 ieee->group_key_type, //KeyType 4409 ieee->group_key_type, //KeyType
4422 broadcast_addr, //MacAddr 4410 broadcast_addr, //MacAddr
4423 0, //DefaultKey 4411 0, //DefaultKey
4424 key); //KeyContent 4412 key); //KeyContent
4425 }
4426 } 4413 }
4427 } 4414 }
4415 }
4428#ifdef JOHN_HWSEC_DEBUG 4416#ifdef JOHN_HWSEC_DEBUG
4429 //john's test 0711 4417 //john's test 0711
4430 printk("@@ wrq->u pointer = "); 4418 printk("@@ wrq->u pointer = ");
@@ -4437,7 +4425,7 @@ int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
4437 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data); 4425 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
4438 break; 4426 break;
4439 4427
4440 default: 4428 default:
4441 ret = -EOPNOTSUPP; 4429 ret = -EOPNOTSUPP;
4442 break; 4430 break;
4443 } 4431 }
@@ -4454,49 +4442,49 @@ u8 HwRateToMRate90(bool bIsHT, u8 rate)
4454 4442
4455 if(!bIsHT) { 4443 if(!bIsHT) {
4456 switch(rate) { 4444 switch(rate) {
4457 case DESC90_RATE1M: ret_rate = MGN_1M; break; 4445 case DESC90_RATE1M: ret_rate = MGN_1M; break;
4458 case DESC90_RATE2M: ret_rate = MGN_2M; break; 4446 case DESC90_RATE2M: ret_rate = MGN_2M; break;
4459 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break; 4447 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
4460 case DESC90_RATE11M: ret_rate = MGN_11M; break; 4448 case DESC90_RATE11M: ret_rate = MGN_11M; break;
4461 case DESC90_RATE6M: ret_rate = MGN_6M; break; 4449 case DESC90_RATE6M: ret_rate = MGN_6M; break;
4462 case DESC90_RATE9M: ret_rate = MGN_9M; break; 4450 case DESC90_RATE9M: ret_rate = MGN_9M; break;
4463 case DESC90_RATE12M: ret_rate = MGN_12M; break; 4451 case DESC90_RATE12M: ret_rate = MGN_12M; break;
4464 case DESC90_RATE18M: ret_rate = MGN_18M; break; 4452 case DESC90_RATE18M: ret_rate = MGN_18M; break;
4465 case DESC90_RATE24M: ret_rate = MGN_24M; break; 4453 case DESC90_RATE24M: ret_rate = MGN_24M; break;
4466 case DESC90_RATE36M: ret_rate = MGN_36M; break; 4454 case DESC90_RATE36M: ret_rate = MGN_36M; break;
4467 case DESC90_RATE48M: ret_rate = MGN_48M; break; 4455 case DESC90_RATE48M: ret_rate = MGN_48M; break;
4468 case DESC90_RATE54M: ret_rate = MGN_54M; break; 4456 case DESC90_RATE54M: ret_rate = MGN_54M; break;
4469 4457
4470 default: 4458 default:
4471 ret_rate = 0xff; 4459 ret_rate = 0xff;
4472 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT); 4460 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
4473 break; 4461 break;
4474 } 4462 }
4475 4463
4476 } else { 4464 } else {
4477 switch(rate) { 4465 switch(rate) {
4478 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break; 4466 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
4479 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break; 4467 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
4480 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break; 4468 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
4481 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break; 4469 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
4482 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break; 4470 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
4483 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break; 4471 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
4484 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break; 4472 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
4485 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break; 4473 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
4486 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break; 4474 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
4487 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break; 4475 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
4488 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break; 4476 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
4489 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break; 4477 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
4490 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break; 4478 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
4491 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break; 4479 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
4492 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break; 4480 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
4493 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break; 4481 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
4494 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break; 4482 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
4495 4483
4496 default: 4484 default:
4497 ret_rate = 0xff; 4485 ret_rate = 0xff;
4498 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT); 4486 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT);
4499 break; 4487 break;
4500 } 4488 }
4501 } 4489 }
4502 4490
@@ -4555,12 +4543,12 @@ void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee802
4555 u8 rfpath; 4543 u8 rfpath;
4556 u32 nspatial_stream, tmp_val; 4544 u32 nspatial_stream, tmp_val;
4557 //u8 i; 4545 //u8 i;
4558 static u32 slide_rssi_index=0, slide_rssi_statistics=0; 4546 static u32 slide_rssi_index, slide_rssi_statistics;
4559 static u32 slide_evm_index=0, slide_evm_statistics=0; 4547 static u32 slide_evm_index, slide_evm_statistics;
4560 static u32 last_rssi=0, last_evm=0; 4548 static u32 last_rssi, last_evm;
4561 4549
4562 static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0; 4550 static u32 slide_beacon_adc_pwdb_index, slide_beacon_adc_pwdb_statistics;
4563 static u32 last_beacon_adc_pwdb=0; 4551 static u32 last_beacon_adc_pwdb;
4564 4552
4565 struct ieee80211_hdr_3addr *hdr; 4553 struct ieee80211_hdr_3addr *hdr;
4566 u16 sc ; 4554 u16 sc ;
@@ -4578,11 +4566,8 @@ void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee802
4578 { 4566 {
4579 // if previous packet is not aggregated packet 4567 // if previous packet is not aggregated packet
4580 bcheck = true; 4568 bcheck = true;
4581 }else
4582 {
4583 } 4569 }
4584 4570
4585
4586 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) 4571 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
4587 { 4572 {
4588 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX; 4573 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
@@ -4808,9 +4793,9 @@ rtl819x_evm_dbtopercentage(
4808 ret_val = value; 4793 ret_val = value;
4809 4794
4810 if(ret_val >= 0) 4795 if(ret_val >= 0)
4811 ret_val = 0; 4796 ret_val = 0;
4812 if(ret_val <= -33) 4797 if(ret_val <= -33)
4813 ret_val = -33; 4798 ret_val = -33;
4814 ret_val = 0 - ret_val; 4799 ret_val = 0 - ret_val;
4815 ret_val*=3; 4800 ret_val*=3;
4816 if(ret_val == 99) 4801 if(ret_val == 99)
@@ -4819,7 +4804,7 @@ rtl819x_evm_dbtopercentage(
4819} 4804}
4820// 4805//
4821// Description: 4806// Description:
4822// We want good-looking for signal strength/quality 4807// We want good-looking for signal strength/quality
4823// 2007/7/19 01:09, by cosa. 4808// 2007/7/19 01:09, by cosa.
4824// 4809//
4825long 4810long
@@ -5203,7 +5188,7 @@ void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
5203* Overview: Record the received data rate 5188* Overview: Record the received data rate
5204* 5189*
5205* Input: 5190* Input:
5206* struct net_device *dev 5191* struct net_device *dev
5207* struct ieee80211_rx_stats *stats 5192* struct ieee80211_rx_stats *stats
5208* 5193*
5209* Output: 5194* Output:
@@ -5581,7 +5566,7 @@ rtl819xusb_process_received_packet(
5581 ) 5566 )
5582{ 5567{
5583// bool bfreerfd=false, bqueued=false; 5568// bool bfreerfd=false, bqueued=false;
5584 u8* frame; 5569 u8* frame;
5585 u16 frame_len=0; 5570 u16 frame_len=0;
5586 struct r8192_priv *priv = ieee80211_priv(dev); 5571 struct r8192_priv *priv = ieee80211_priv(dev);
5587// u8 index = 0; 5572// u8 index = 0;
@@ -5682,10 +5667,6 @@ void rtl8192_rx_cmd(struct sk_buff *skb)
5682 5667
5683 dev_kfree_skb_any(skb); 5668 dev_kfree_skb_any(skb);
5684 } 5669 }
5685 else
5686 ;
5687
5688
5689} 5670}
5690 5671
5691void rtl8192_irq_rx_tasklet(struct r8192_priv *priv) 5672void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
@@ -5697,25 +5678,25 @@ void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
5697 info = (struct rtl8192_rx_info *)skb->cb; 5678 info = (struct rtl8192_rx_info *)skb->cb;
5698 switch (info->out_pipe) { 5679 switch (info->out_pipe) {
5699 /* Nomal packet pipe */ 5680 /* Nomal packet pipe */
5700 case 3: 5681 case 3:
5701 //RT_TRACE(COMP_RECV, "normal in-pipe index(%d)\n",info->out_pipe); 5682 //RT_TRACE(COMP_RECV, "normal in-pipe index(%d)\n",info->out_pipe);
5702 priv->IrpPendingCount--; 5683 priv->IrpPendingCount--;
5703 rtl8192_rx_nomal(skb); 5684 rtl8192_rx_nomal(skb);
5704 break; 5685 break;
5705 5686
5706 /* Command packet pipe */ 5687 /* Command packet pipe */
5707 case 9: 5688 case 9:
5708 RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",\ 5689 RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",\
5709 info->out_pipe); 5690 info->out_pipe);
5710 5691
5711 rtl8192_rx_cmd(skb); 5692 rtl8192_rx_cmd(skb);
5712 break; 5693 break;
5713 5694
5714 default: /* should never get here! */ 5695 default: /* should never get here! */
5715 RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",\ 5696 RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",\
5716 info->out_pipe); 5697 info->out_pipe);
5717 dev_kfree_skb(skb); 5698 dev_kfree_skb(skb);
5718 break; 5699 break;
5719 5700
5720 } 5701 }
5721 } 5702 }
@@ -6007,7 +5988,7 @@ void setKey( struct net_device *dev,
6007 // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo)); 5988 // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo));
6008 } 5989 }
6009 else if(i==1){//MAC 5990 else if(i==1){//MAC
6010 TargetContent = (u32)(*(MacAddr+2)) | 5991 TargetContent = (u32)(*(MacAddr+2)) |
6011 (u32)(*(MacAddr+3)) << 8| 5992 (u32)(*(MacAddr+3)) << 8|
6012 (u32)(*(MacAddr+4)) << 16| 5993 (u32)(*(MacAddr+4)) << 16|
6013 (u32)(*(MacAddr+5)) << 24; 5994 (u32)(*(MacAddr+5)) << 24;
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index cd8dc85e9c0f..ea46717f1fad 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -8,7 +8,7 @@ Abstract:
8 HW dynamic mechanism. 8 HW dynamic mechanism.
9 9
10Major Change History: 10Major Change History:
11 When Who What 11 When Who What
12 ---------- --------------- ------------------------------- 12 ---------- --------------- -------------------------------
13 2008-05-14 amy create version 0 porting from windows code. 13 2008-05-14 amy create version 0 porting from windows code.
14 14
@@ -25,9 +25,9 @@ Major Change History:
25// Indicate different AP vendor for IOT issue. 25// Indicate different AP vendor for IOT issue.
26// 26//
27static u32 edca_setting_DL[HT_IOT_PEER_MAX] = 27static u32 edca_setting_DL[HT_IOT_PEER_MAX] =
28 { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5ea44f}; 28 { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5ea44f};
29static u32 edca_setting_UL[HT_IOT_PEER_MAX] = 29static u32 edca_setting_UL[HT_IOT_PEER_MAX] =
30 { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5ea44f, 0x5ea44f}; 30 { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5ea44f, 0x5ea44f};
31 31
32 32
33#define RTK_UL_EDCA 0xa44f 33#define RTK_UL_EDCA 0xa44f
@@ -134,7 +134,7 @@ static void dm_check_pbc_gpio(struct net_device *dev);
134 134
135// DM --> Check current RX RF path state 135// DM --> Check current RX RF path state
136static void dm_check_rx_path_selection(struct net_device *dev); 136static void dm_check_rx_path_selection(struct net_device *dev);
137static void dm_init_rxpath_selection(struct net_device *dev); 137static void dm_init_rxpath_selection(struct net_device *dev);
138static void dm_rxpath_sel_byrssi(struct net_device *dev); 138static void dm_rxpath_sel_byrssi(struct net_device *dev);
139 139
140 140
@@ -201,8 +201,8 @@ extern void deinit_hal_dm(struct net_device *dev)
201void dm_CheckRxAggregation(struct net_device *dev) { 201void dm_CheckRxAggregation(struct net_device *dev) {
202 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev); 202 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
203 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo; 203 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
204 static unsigned long lastTxOkCnt = 0; 204 static unsigned long lastTxOkCnt;
205 static unsigned long lastRxOkCnt = 0; 205 static unsigned long lastRxOkCnt;
206 unsigned long curTxOkCnt = 0; 206 unsigned long curTxOkCnt = 0;
207 unsigned long curRxOkCnt = 0; 207 unsigned long curRxOkCnt = 0;
208 208
@@ -259,7 +259,7 @@ extern void hal_dm_watchdog(struct net_device *dev)
259{ 259{
260 //struct r8192_priv *priv = ieee80211_priv(dev); 260 //struct r8192_priv *priv = ieee80211_priv(dev);
261 261
262 //static u8 previous_bssid[6] ={0}; 262 //static u8 previous_bssid[6] ={0};
263 263
264 /*Add by amy 2008/05/15 ,porting from windows code.*/ 264 /*Add by amy 2008/05/15 ,porting from windows code.*/
265 dm_check_rate_adaptive(dev); 265 dm_check_rate_adaptive(dev);
@@ -315,21 +315,21 @@ extern void init_rate_adaptive(struct net_device * dev)
315 { 315 {
316 // 07/10/08 MH Modify for RA smooth scheme. 316 // 07/10/08 MH Modify for RA smooth scheme.
317 /* 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.*/ 317 /* 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.*/
318 pra->upper_rssi_threshold_ratr = 0x8f0f0000; 318 pra->upper_rssi_threshold_ratr = 0x8f0f0000;
319 pra->middle_rssi_threshold_ratr = 0x8f0ff000; 319 pra->middle_rssi_threshold_ratr = 0x8f0ff000;
320 pra->low_rssi_threshold_ratr = 0x8f0ff001; 320 pra->low_rssi_threshold_ratr = 0x8f0ff001;
321 pra->low_rssi_threshold_ratr_40M = 0x8f0ff005; 321 pra->low_rssi_threshold_ratr_40M = 0x8f0ff005;
322 pra->low_rssi_threshold_ratr_20M = 0x8f0ff001; 322 pra->low_rssi_threshold_ratr_20M = 0x8f0ff001;
323 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test 323 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test
324 } 324 }
325 else if (priv->rf_type == RF_1T2R) 325 else if (priv->rf_type == RF_1T2R)
326 { 326 {
327 pra->upper_rssi_threshold_ratr = 0x000f0000; 327 pra->upper_rssi_threshold_ratr = 0x000f0000;
328 pra->middle_rssi_threshold_ratr = 0x000ff000; 328 pra->middle_rssi_threshold_ratr = 0x000ff000;
329 pra->low_rssi_threshold_ratr = 0x000ff001; 329 pra->low_rssi_threshold_ratr = 0x000ff001;
330 pra->low_rssi_threshold_ratr_40M = 0x000ff005; 330 pra->low_rssi_threshold_ratr_40M = 0x000ff005;
331 pra->low_rssi_threshold_ratr_20M = 0x000ff001; 331 pra->low_rssi_threshold_ratr_20M = 0x000ff001;
332 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test 332 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test
333 } 333 }
334 334
335} // InitRateAdaptive 335} // InitRateAdaptive
@@ -348,7 +348,7 @@ extern void init_rate_adaptive(struct net_device * dev)
348 * 348 *
349 * Revised History: 349 * Revised History:
350 * When Who Remark 350 * When Who Remark
351 * 05/26/08 amy Create version 0 porting from windows code. 351 * 05/26/08 amy Create version 0 porting from windows code.
352 * 352 *
353 *---------------------------------------------------------------------------*/ 353 *---------------------------------------------------------------------------*/
354static void dm_check_rate_adaptive(struct net_device * dev) 354static void dm_check_rate_adaptive(struct net_device * dev)
@@ -359,7 +359,7 @@ static void dm_check_rate_adaptive(struct net_device * dev)
359 u32 currentRATR, targetRATR = 0; 359 u32 currentRATR, targetRATR = 0;
360 u32 LowRSSIThreshForRA = 0, HighRSSIThreshForRA = 0; 360 u32 LowRSSIThreshForRA = 0, HighRSSIThreshForRA = 0;
361 bool bshort_gi_enabled = false; 361 bool bshort_gi_enabled = false;
362 static u8 ping_rssi_state=0; 362 static u8 ping_rssi_state;
363 363
364 364
365 if(!priv->up) 365 if(!priv->up)
@@ -413,14 +413,14 @@ static void dm_check_rate_adaptive(struct net_device * dev)
413 to prevent jumping frequently. */ 413 to prevent jumping frequently. */
414 if (pra->ratr_state == DM_RATR_STA_HIGH) 414 if (pra->ratr_state == DM_RATR_STA_HIGH)
415 { 415 {
416 HighRSSIThreshForRA = pra->high2low_rssi_thresh_for_ra; 416 HighRSSIThreshForRA = pra->high2low_rssi_thresh_for_ra;
417 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)? 417 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
418 (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M); 418 (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M);
419 } 419 }
420 else if (pra->ratr_state == DM_RATR_STA_LOW) 420 else if (pra->ratr_state == DM_RATR_STA_LOW)
421 { 421 {
422 HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra; 422 HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra;
423 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)? 423 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
424 (pra->low2high_rssi_thresh_for_ra40M):(pra->low2high_rssi_thresh_for_ra20M); 424 (pra->low2high_rssi_thresh_for_ra40M):(pra->low2high_rssi_thresh_for_ra20M);
425 } 425 }
426 else 426 else
@@ -599,7 +599,7 @@ static void dm_TXPowerTrackingCallback_TSSI(struct net_device * dev)
599 u32 Value; 599 u32 Value;
600 u8 Pwr_Flag; 600 u8 Pwr_Flag;
601 u16 Avg_TSSI_Meas, TSSI_13dBm, Avg_TSSI_Meas_from_driver=0; 601 u16 Avg_TSSI_Meas, TSSI_13dBm, Avg_TSSI_Meas_from_driver=0;
602 //RT_STATUS rtStatus = RT_STATUS_SUCCESS; 602 //RT_STATUS rtStatus = RT_STATUS_SUCCESS;
603 bool rtStatus = true; 603 bool rtStatus = true;
604 u32 delta=0; 604 u32 delta=0;
605 605
@@ -954,79 +954,79 @@ static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev)
954 struct r8192_priv *priv = ieee80211_priv(dev); 954 struct r8192_priv *priv = ieee80211_priv(dev);
955 955
956 //Initial the Tx BB index and mapping value 956 //Initial the Tx BB index and mapping value
957 priv->txbbgain_table[0].txbb_iq_amplifygain = 12; 957 priv->txbbgain_table[0].txbb_iq_amplifygain = 12;
958 priv->txbbgain_table[0].txbbgain_value=0x7f8001fe; 958 priv->txbbgain_table[0].txbbgain_value=0x7f8001fe;
959 priv->txbbgain_table[1].txbb_iq_amplifygain = 11; 959 priv->txbbgain_table[1].txbb_iq_amplifygain = 11;
960 priv->txbbgain_table[1].txbbgain_value=0x788001e2; 960 priv->txbbgain_table[1].txbbgain_value=0x788001e2;
961 priv->txbbgain_table[2].txbb_iq_amplifygain = 10; 961 priv->txbbgain_table[2].txbb_iq_amplifygain = 10;
962 priv->txbbgain_table[2].txbbgain_value=0x71c001c7; 962 priv->txbbgain_table[2].txbbgain_value=0x71c001c7;
963 priv->txbbgain_table[3].txbb_iq_amplifygain = 9; 963 priv->txbbgain_table[3].txbb_iq_amplifygain = 9;
964 priv->txbbgain_table[3].txbbgain_value=0x6b8001ae; 964 priv->txbbgain_table[3].txbbgain_value=0x6b8001ae;
965 priv->txbbgain_table[4].txbb_iq_amplifygain = 8; 965 priv->txbbgain_table[4].txbb_iq_amplifygain = 8;
966 priv->txbbgain_table[4].txbbgain_value=0x65400195; 966 priv->txbbgain_table[4].txbbgain_value=0x65400195;
967 priv->txbbgain_table[5].txbb_iq_amplifygain = 7; 967 priv->txbbgain_table[5].txbb_iq_amplifygain = 7;
968 priv->txbbgain_table[5].txbbgain_value=0x5fc0017f; 968 priv->txbbgain_table[5].txbbgain_value=0x5fc0017f;
969 priv->txbbgain_table[6].txbb_iq_amplifygain = 6; 969 priv->txbbgain_table[6].txbb_iq_amplifygain = 6;
970 priv->txbbgain_table[6].txbbgain_value=0x5a400169; 970 priv->txbbgain_table[6].txbbgain_value=0x5a400169;
971 priv->txbbgain_table[7].txbb_iq_amplifygain = 5; 971 priv->txbbgain_table[7].txbb_iq_amplifygain = 5;
972 priv->txbbgain_table[7].txbbgain_value=0x55400155; 972 priv->txbbgain_table[7].txbbgain_value=0x55400155;
973 priv->txbbgain_table[8].txbb_iq_amplifygain = 4; 973 priv->txbbgain_table[8].txbb_iq_amplifygain = 4;
974 priv->txbbgain_table[8].txbbgain_value=0x50800142; 974 priv->txbbgain_table[8].txbbgain_value=0x50800142;
975 priv->txbbgain_table[9].txbb_iq_amplifygain = 3; 975 priv->txbbgain_table[9].txbb_iq_amplifygain = 3;
976 priv->txbbgain_table[9].txbbgain_value=0x4c000130; 976 priv->txbbgain_table[9].txbbgain_value=0x4c000130;
977 priv->txbbgain_table[10].txbb_iq_amplifygain = 2; 977 priv->txbbgain_table[10].txbb_iq_amplifygain = 2;
978 priv->txbbgain_table[10].txbbgain_value=0x47c0011f; 978 priv->txbbgain_table[10].txbbgain_value=0x47c0011f;
979 priv->txbbgain_table[11].txbb_iq_amplifygain = 1; 979 priv->txbbgain_table[11].txbb_iq_amplifygain = 1;
980 priv->txbbgain_table[11].txbbgain_value=0x43c0010f; 980 priv->txbbgain_table[11].txbbgain_value=0x43c0010f;
981 priv->txbbgain_table[12].txbb_iq_amplifygain = 0; 981 priv->txbbgain_table[12].txbb_iq_amplifygain = 0;
982 priv->txbbgain_table[12].txbbgain_value=0x40000100; 982 priv->txbbgain_table[12].txbbgain_value=0x40000100;
983 priv->txbbgain_table[13].txbb_iq_amplifygain = -1; 983 priv->txbbgain_table[13].txbb_iq_amplifygain = -1;
984 priv->txbbgain_table[13].txbbgain_value=0x3c8000f2; 984 priv->txbbgain_table[13].txbbgain_value=0x3c8000f2;
985 priv->txbbgain_table[14].txbb_iq_amplifygain = -2; 985 priv->txbbgain_table[14].txbb_iq_amplifygain = -2;
986 priv->txbbgain_table[14].txbbgain_value=0x390000e4; 986 priv->txbbgain_table[14].txbbgain_value=0x390000e4;
987 priv->txbbgain_table[15].txbb_iq_amplifygain = -3; 987 priv->txbbgain_table[15].txbb_iq_amplifygain = -3;
988 priv->txbbgain_table[15].txbbgain_value=0x35c000d7; 988 priv->txbbgain_table[15].txbbgain_value=0x35c000d7;
989 priv->txbbgain_table[16].txbb_iq_amplifygain = -4; 989 priv->txbbgain_table[16].txbb_iq_amplifygain = -4;
990 priv->txbbgain_table[16].txbbgain_value=0x32c000cb; 990 priv->txbbgain_table[16].txbbgain_value=0x32c000cb;
991 priv->txbbgain_table[17].txbb_iq_amplifygain = -5; 991 priv->txbbgain_table[17].txbb_iq_amplifygain = -5;
992 priv->txbbgain_table[17].txbbgain_value=0x300000c0; 992 priv->txbbgain_table[17].txbbgain_value=0x300000c0;
993 priv->txbbgain_table[18].txbb_iq_amplifygain = -6; 993 priv->txbbgain_table[18].txbb_iq_amplifygain = -6;
994 priv->txbbgain_table[18].txbbgain_value=0x2d4000b5; 994 priv->txbbgain_table[18].txbbgain_value=0x2d4000b5;
995 priv->txbbgain_table[19].txbb_iq_amplifygain = -7; 995 priv->txbbgain_table[19].txbb_iq_amplifygain = -7;
996 priv->txbbgain_table[19].txbbgain_value=0x2ac000ab; 996 priv->txbbgain_table[19].txbbgain_value=0x2ac000ab;
997 priv->txbbgain_table[20].txbb_iq_amplifygain = -8; 997 priv->txbbgain_table[20].txbb_iq_amplifygain = -8;
998 priv->txbbgain_table[20].txbbgain_value=0x288000a2; 998 priv->txbbgain_table[20].txbbgain_value=0x288000a2;
999 priv->txbbgain_table[21].txbb_iq_amplifygain = -9; 999 priv->txbbgain_table[21].txbb_iq_amplifygain = -9;
1000 priv->txbbgain_table[21].txbbgain_value=0x26000098; 1000 priv->txbbgain_table[21].txbbgain_value=0x26000098;
1001 priv->txbbgain_table[22].txbb_iq_amplifygain = -10; 1001 priv->txbbgain_table[22].txbb_iq_amplifygain = -10;
1002 priv->txbbgain_table[22].txbbgain_value=0x24000090; 1002 priv->txbbgain_table[22].txbbgain_value=0x24000090;
1003 priv->txbbgain_table[23].txbb_iq_amplifygain = -11; 1003 priv->txbbgain_table[23].txbb_iq_amplifygain = -11;
1004 priv->txbbgain_table[23].txbbgain_value=0x22000088; 1004 priv->txbbgain_table[23].txbbgain_value=0x22000088;
1005 priv->txbbgain_table[24].txbb_iq_amplifygain = -12; 1005 priv->txbbgain_table[24].txbb_iq_amplifygain = -12;
1006 priv->txbbgain_table[24].txbbgain_value=0x20000080; 1006 priv->txbbgain_table[24].txbbgain_value=0x20000080;
1007 priv->txbbgain_table[25].txbb_iq_amplifygain = -13; 1007 priv->txbbgain_table[25].txbb_iq_amplifygain = -13;
1008 priv->txbbgain_table[25].txbbgain_value=0x1a00006c; 1008 priv->txbbgain_table[25].txbbgain_value=0x1a00006c;
1009 priv->txbbgain_table[26].txbb_iq_amplifygain = -14; 1009 priv->txbbgain_table[26].txbb_iq_amplifygain = -14;
1010 priv->txbbgain_table[26].txbbgain_value=0x1c800072; 1010 priv->txbbgain_table[26].txbbgain_value=0x1c800072;
1011 priv->txbbgain_table[27].txbb_iq_amplifygain = -15; 1011 priv->txbbgain_table[27].txbb_iq_amplifygain = -15;
1012 priv->txbbgain_table[27].txbbgain_value=0x18000060; 1012 priv->txbbgain_table[27].txbbgain_value=0x18000060;
1013 priv->txbbgain_table[28].txbb_iq_amplifygain = -16; 1013 priv->txbbgain_table[28].txbb_iq_amplifygain = -16;
1014 priv->txbbgain_table[28].txbbgain_value=0x19800066; 1014 priv->txbbgain_table[28].txbbgain_value=0x19800066;
1015 priv->txbbgain_table[29].txbb_iq_amplifygain = -17; 1015 priv->txbbgain_table[29].txbb_iq_amplifygain = -17;
1016 priv->txbbgain_table[29].txbbgain_value=0x15800056; 1016 priv->txbbgain_table[29].txbbgain_value=0x15800056;
1017 priv->txbbgain_table[30].txbb_iq_amplifygain = -18; 1017 priv->txbbgain_table[30].txbb_iq_amplifygain = -18;
1018 priv->txbbgain_table[30].txbbgain_value=0x26c0005b; 1018 priv->txbbgain_table[30].txbbgain_value=0x26c0005b;
1019 priv->txbbgain_table[31].txbb_iq_amplifygain = -19; 1019 priv->txbbgain_table[31].txbb_iq_amplifygain = -19;
1020 priv->txbbgain_table[31].txbbgain_value=0x14400051; 1020 priv->txbbgain_table[31].txbbgain_value=0x14400051;
1021 priv->txbbgain_table[32].txbb_iq_amplifygain = -20; 1021 priv->txbbgain_table[32].txbb_iq_amplifygain = -20;
1022 priv->txbbgain_table[32].txbbgain_value=0x24400051; 1022 priv->txbbgain_table[32].txbbgain_value=0x24400051;
1023 priv->txbbgain_table[33].txbb_iq_amplifygain = -21; 1023 priv->txbbgain_table[33].txbb_iq_amplifygain = -21;
1024 priv->txbbgain_table[33].txbbgain_value=0x1300004c; 1024 priv->txbbgain_table[33].txbbgain_value=0x1300004c;
1025 priv->txbbgain_table[34].txbb_iq_amplifygain = -22; 1025 priv->txbbgain_table[34].txbb_iq_amplifygain = -22;
1026 priv->txbbgain_table[34].txbbgain_value=0x12000048; 1026 priv->txbbgain_table[34].txbbgain_value=0x12000048;
1027 priv->txbbgain_table[35].txbb_iq_amplifygain = -23; 1027 priv->txbbgain_table[35].txbb_iq_amplifygain = -23;
1028 priv->txbbgain_table[35].txbbgain_value=0x11000044; 1028 priv->txbbgain_table[35].txbbgain_value=0x11000044;
1029 priv->txbbgain_table[36].txbb_iq_amplifygain = -24; 1029 priv->txbbgain_table[36].txbb_iq_amplifygain = -24;
1030 priv->txbbgain_table[36].txbbgain_value=0x10000040; 1030 priv->txbbgain_table[36].txbbgain_value=0x10000040;
1031 1031
1032 //ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29 1032 //ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
@@ -1486,7 +1486,7 @@ void dm_initialize_txpower_tracking(struct net_device *dev)
1486static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev) 1486static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev)
1487{ 1487{
1488 struct r8192_priv *priv = ieee80211_priv(dev); 1488 struct r8192_priv *priv = ieee80211_priv(dev);
1489 static u32 tx_power_track_counter = 0; 1489 static u32 tx_power_track_counter;
1490 1490
1491 if(!priv->btxpower_tracking) 1491 if(!priv->btxpower_tracking)
1492 return; 1492 return;
@@ -1505,7 +1505,7 @@ static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev)
1505static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev) 1505static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
1506{ 1506{
1507 struct r8192_priv *priv = ieee80211_priv(dev); 1507 struct r8192_priv *priv = ieee80211_priv(dev);
1508 static u8 TM_Trigger=0; 1508 static u8 TM_Trigger;
1509 //DbgPrint("dm_CheckTXPowerTracking() \n"); 1509 //DbgPrint("dm_CheckTXPowerTracking() \n");
1510 if(!priv->btxpower_tracking) 1510 if(!priv->btxpower_tracking)
1511 return; 1511 return;
@@ -1564,40 +1564,40 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
1564 TempVal = 0; 1564 TempVal = 0;
1565 if(!bInCH14){ 1565 if(!bInCH14){
1566 //Write 0xa22 0xa23 1566 //Write 0xa22 0xa23
1567 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] + 1567 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
1568 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ; 1568 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
1569 1569
1570 rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal); 1570 rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal);
1571 //Write 0xa24 ~ 0xa27 1571 //Write 0xa24 ~ 0xa27
1572 TempVal = 0; 1572 TempVal = 0;
1573 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + 1573 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
1574 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) + 1574 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
1575 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+ 1575 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+
1576 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24); 1576 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
1577 rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal); 1577 rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal);
1578 //Write 0xa28 0xa29 1578 //Write 0xa28 0xa29
1579 TempVal = 0; 1579 TempVal = 0;
1580 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + 1580 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
1581 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ; 1581 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
1582 1582
1583 rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal); 1583 rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal);
1584 } 1584 }
1585 else 1585 else
1586 { 1586 {
1587 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] + 1587 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
1588 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ; 1588 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
1589 1589
1590 rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal); 1590 rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal);
1591 //Write 0xa24 ~ 0xa27 1591 //Write 0xa24 ~ 0xa27
1592 TempVal = 0; 1592 TempVal = 0;
1593 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + 1593 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
1594 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) + 1594 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
1595 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+ 1595 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+
1596 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24); 1596 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
1597 rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal); 1597 rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal);
1598 //Write 0xa28 0xa29 1598 //Write 0xa28 0xa29
1599 TempVal = 0; 1599 TempVal = 0;
1600 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + 1600 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
1601 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ; 1601 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
1602 1602
1603 rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal); 1603 rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal);
@@ -1615,14 +1615,14 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1615 if(!bInCH14) 1615 if(!bInCH14)
1616 { 1616 {
1617 //Write 0xa22 0xa23 1617 //Write 0xa22 0xa23
1618 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] + 1618 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] +
1619 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1]<<8) ; 1619 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1]<<8) ;
1620 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1620 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1621 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n", 1621 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1622 rCCK0_TxFilter1, TempVal); 1622 rCCK0_TxFilter1, TempVal);
1623 //Write 0xa24 ~ 0xa27 1623 //Write 0xa24 ~ 0xa27
1624 TempVal = 0; 1624 TempVal = 0;
1625 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] + 1625 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] +
1626 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) + 1626 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) +
1627 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16 )+ 1627 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16 )+
1628 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5]<<24); 1628 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5]<<24);
@@ -1631,7 +1631,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1631 rCCK0_TxFilter2, TempVal); 1631 rCCK0_TxFilter2, TempVal);
1632 //Write 0xa28 0xa29 1632 //Write 0xa28 0xa29
1633 TempVal = 0; 1633 TempVal = 0;
1634 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] + 1634 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] +
1635 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ; 1635 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ;
1636 1636
1637 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); 1637 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
@@ -1642,7 +1642,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1642 { 1642 {
1643// priv->CCKTxPowerAdjustCntNotCh14++; //cosa add for debug. 1643// priv->CCKTxPowerAdjustCntNotCh14++; //cosa add for debug.
1644 //Write 0xa22 0xa23 1644 //Write 0xa22 0xa23
1645 TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] + 1645 TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] +
1646 (CCKSwingTable_Ch14[priv->CCK_index][1]<<8) ; 1646 (CCKSwingTable_Ch14[priv->CCK_index][1]<<8) ;
1647 1647
1648 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1648 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
@@ -1650,7 +1650,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1650 rCCK0_TxFilter1, TempVal); 1650 rCCK0_TxFilter1, TempVal);
1651 //Write 0xa24 ~ 0xa27 1651 //Write 0xa24 ~ 0xa27
1652 TempVal = 0; 1652 TempVal = 0;
1653 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] + 1653 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] +
1654 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) + 1654 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) +
1655 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16 )+ 1655 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16 )+
1656 (CCKSwingTable_Ch14[priv->CCK_index][5]<<24); 1656 (CCKSwingTable_Ch14[priv->CCK_index][5]<<24);
@@ -1659,7 +1659,7 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1659 rCCK0_TxFilter2, TempVal); 1659 rCCK0_TxFilter2, TempVal);
1660 //Write 0xa28 0xa29 1660 //Write 0xa28 0xa29
1661 TempVal = 0; 1661 TempVal = 0;
1662 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] + 1662 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] +
1663 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ; 1663 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ;
1664 1664
1665 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal); 1665 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
@@ -1713,7 +1713,7 @@ static void dm_txpower_reset_recovery(
1713extern void dm_restore_dynamic_mechanism_state(struct net_device *dev) 1713extern void dm_restore_dynamic_mechanism_state(struct net_device *dev)
1714{ 1714{
1715 struct r8192_priv *priv = ieee80211_priv(dev); 1715 struct r8192_priv *priv = ieee80211_priv(dev);
1716 u32 reg_ratr = priv->rate_adaptive.last_ratr; 1716 u32 reg_ratr = priv->rate_adaptive.last_ratr;
1717 1717
1718 if(!priv->up) 1718 if(!priv->up)
1719 { 1719 {
@@ -1934,7 +1934,7 @@ dm_change_rxpath_selection_setting(
1934 s32 DM_Value) 1934 s32 DM_Value)
1935{ 1935{
1936 struct r8192_priv *priv = ieee80211_priv(dev); 1936 struct r8192_priv *priv = ieee80211_priv(dev);
1937 prate_adaptive pRA = (prate_adaptive)&(priv->rate_adaptive); 1937 prate_adaptive pRA = (prate_adaptive)&(priv->rate_adaptive);
1938 1938
1939 1939
1940 if(DM_Type == 0) 1940 if(DM_Type == 0)
@@ -2036,8 +2036,8 @@ static void dm_dig_init(struct net_device *dev)
2036 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX; 2036 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
2037 dm_digtable.initialgain_lowerbound_state = false; 2037 dm_digtable.initialgain_lowerbound_state = false;
2038 2038
2039 dm_digtable.rssi_low_thresh = DM_DIG_THRESH_LOW; 2039 dm_digtable.rssi_low_thresh = DM_DIG_THRESH_LOW;
2040 dm_digtable.rssi_high_thresh = DM_DIG_THRESH_HIGH; 2040 dm_digtable.rssi_high_thresh = DM_DIG_THRESH_HIGH;
2041 2041
2042 dm_digtable.rssi_high_power_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW; 2042 dm_digtable.rssi_high_power_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW;
2043 dm_digtable.rssi_high_power_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH; 2043 dm_digtable.rssi_high_power_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH;
@@ -2091,7 +2091,7 @@ static void dm_ctrl_initgain_byrssi_by_driverrssi(
2091{ 2091{
2092 struct r8192_priv *priv = ieee80211_priv(dev); 2092 struct r8192_priv *priv = ieee80211_priv(dev);
2093 u8 i; 2093 u8 i;
2094 static u8 fw_dig=0; 2094 static u8 fw_dig;
2095 2095
2096 if (dm_digtable.dig_enable_flag == false) 2096 if (dm_digtable.dig_enable_flag == false)
2097 return; 2097 return;
@@ -2131,7 +2131,7 @@ static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
2131 struct net_device *dev) 2131 struct net_device *dev)
2132{ 2132{
2133 struct r8192_priv *priv = ieee80211_priv(dev); 2133 struct r8192_priv *priv = ieee80211_priv(dev);
2134 static u32 reset_cnt = 0; 2134 static u32 reset_cnt;
2135 u8 i; 2135 u8 i;
2136 2136
2137 if (dm_digtable.dig_enable_flag == false) 2137 if (dm_digtable.dig_enable_flag == false)
@@ -2319,7 +2319,7 @@ static void dm_ctrl_initgain_byrssi_highpwr(
2319 struct net_device * dev) 2319 struct net_device * dev)
2320{ 2320{
2321 struct r8192_priv *priv = ieee80211_priv(dev); 2321 struct r8192_priv *priv = ieee80211_priv(dev);
2322 static u32 reset_cnt_highpwr = 0; 2322 static u32 reset_cnt_highpwr;
2323 2323
2324 // For smooth, we can not change high power DIG state in the range. 2324 // For smooth, we can not change high power DIG state in the range.
2325 if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_high_power_lowthresh) && 2325 if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_high_power_lowthresh) &&
@@ -2395,8 +2395,8 @@ static void dm_initial_gain(
2395{ 2395{
2396 struct r8192_priv *priv = ieee80211_priv(dev); 2396 struct r8192_priv *priv = ieee80211_priv(dev);
2397 u8 initial_gain=0; 2397 u8 initial_gain=0;
2398 static u8 initialized=0, force_write=0; 2398 static u8 initialized, force_write;
2399 static u32 reset_cnt=0; 2399 static u32 reset_cnt;
2400 2400
2401 if(dm_digtable.dig_algorithm_switch) 2401 if(dm_digtable.dig_algorithm_switch)
2402 { 2402 {
@@ -2462,8 +2462,8 @@ static void dm_pd_th(
2462 struct net_device * dev) 2462 struct net_device * dev)
2463{ 2463{
2464 struct r8192_priv *priv = ieee80211_priv(dev); 2464 struct r8192_priv *priv = ieee80211_priv(dev);
2465 static u8 initialized=0, force_write=0; 2465 static u8 initialized, force_write;
2466 static u32 reset_cnt = 0; 2466 static u32 reset_cnt;
2467 2467
2468 if(dm_digtable.dig_algorithm_switch) 2468 if(dm_digtable.dig_algorithm_switch)
2469 { 2469 {
@@ -2574,8 +2574,8 @@ static void dm_cs_ratio(
2574 struct net_device * dev) 2574 struct net_device * dev)
2575{ 2575{
2576 struct r8192_priv *priv = ieee80211_priv(dev); 2576 struct r8192_priv *priv = ieee80211_priv(dev);
2577 static u8 initialized=0,force_write=0; 2577 static u8 initialized,force_write;
2578 static u32 reset_cnt = 0; 2578 static u32 reset_cnt;
2579 2579
2580 if(dm_digtable.dig_algorithm_switch) 2580 if(dm_digtable.dig_algorithm_switch)
2581 { 2581 {
@@ -2651,8 +2651,8 @@ static void dm_check_edca_turbo(
2651 //PSTA_QOS pStaQos = pMgntInfo->pStaQos; 2651 //PSTA_QOS pStaQos = pMgntInfo->pStaQos;
2652 2652
2653 // Keep past Tx/Rx packet count for RT-to-RT EDCA turbo. 2653 // Keep past Tx/Rx packet count for RT-to-RT EDCA turbo.
2654 static unsigned long lastTxOkCnt = 0; 2654 static unsigned long lastTxOkCnt;
2655 static unsigned long lastRxOkCnt = 0; 2655 static unsigned long lastRxOkCnt;
2656 unsigned long curTxOkCnt = 0; 2656 unsigned long curTxOkCnt = 0;
2657 unsigned long curRxOkCnt = 0; 2657 unsigned long curRxOkCnt = 0;
2658 2658
@@ -2785,8 +2785,8 @@ static void dm_ctstoself(struct net_device *dev)
2785{ 2785{
2786 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev); 2786 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
2787 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo; 2787 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
2788 static unsigned long lastTxOkCnt = 0; 2788 static unsigned long lastTxOkCnt;
2789 static unsigned long lastRxOkCnt = 0; 2789 static unsigned long lastRxOkCnt;
2790 unsigned long curTxOkCnt = 0; 2790 unsigned long curTxOkCnt = 0;
2791 unsigned long curRxOkCnt = 0; 2791 unsigned long curRxOkCnt = 0;
2792 2792
@@ -2871,7 +2871,7 @@ static void dm_check_rfctrl_gpio(struct net_device * dev)
2871 * 2871 *
2872 * Revised History: 2872 * Revised History:
2873 * When Who Remark 2873 * When Who Remark
2874 * 05/28/2008 amy Create Version 0 porting from windows code. 2874 * 05/28/2008 amy Create Version 0 porting from windows code.
2875 * 2875 *
2876 *---------------------------------------------------------------------------*/ 2876 *---------------------------------------------------------------------------*/
2877static void dm_check_pbc_gpio(struct net_device *dev) 2877static void dm_check_pbc_gpio(struct net_device *dev)
@@ -3044,7 +3044,7 @@ static void dm_rxpath_sel_byrssi(struct net_device * dev)
3044 u8 cck_rx_ver2_max_index=0, cck_rx_ver2_min_index=0, cck_rx_ver2_sec_index=0; 3044 u8 cck_rx_ver2_max_index=0, cck_rx_ver2_min_index=0, cck_rx_ver2_sec_index=0;
3045 u8 cur_rf_rssi; 3045 u8 cur_rf_rssi;
3046 long cur_cck_pwdb; 3046 long cur_cck_pwdb;
3047 static u8 disabled_rf_cnt=0, cck_Rx_Path_initialized=0; 3047 static u8 disabled_rf_cnt, cck_Rx_Path_initialized;
3048 u8 update_cck_rx_path; 3048 u8 update_cck_rx_path;
3049 3049
3050 if(priv->rf_type != RF_2T4R) 3050 if(priv->rf_type != RF_2T4R)
@@ -3517,8 +3517,8 @@ static void dm_EndSWFsync(struct net_device *dev)
3517static void dm_StartSWFsync(struct net_device *dev) 3517static void dm_StartSWFsync(struct net_device *dev)
3518{ 3518{
3519 struct r8192_priv *priv = ieee80211_priv(dev); 3519 struct r8192_priv *priv = ieee80211_priv(dev);
3520 u32 rateIndex; 3520 u32 rateIndex;
3521 u32 rateBitmap; 3521 u32 rateBitmap;
3522 3522
3523 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__); 3523 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__);
3524 // Initial rate record to zero, start to record. 3524 // Initial rate record to zero, start to record.
@@ -3569,9 +3569,9 @@ void dm_check_fsync(struct net_device *dev)
3569#define RegC38_NonFsync_Other_AP 1 3569#define RegC38_NonFsync_Other_AP 1
3570#define RegC38_Fsync_AP_BCM 2 3570#define RegC38_Fsync_AP_BCM 2
3571 struct r8192_priv *priv = ieee80211_priv(dev); 3571 struct r8192_priv *priv = ieee80211_priv(dev);
3572 //u32 framesyncC34; 3572 //u32 framesyncC34;
3573 static u8 reg_c38_State=RegC38_Default; 3573 static u8 reg_c38_State=RegC38_Default;
3574 static u32 reset_cnt=0; 3574 static u32 reset_cnt;
3575 3575
3576 RT_TRACE(COMP_HALDM, "RSSI %d TimeInterval %d MultipleTimeInterval %d\n", priv->ieee80211->fsync_rssi_threshold, priv->ieee80211->fsync_time_interval, priv->ieee80211->fsync_multiple_timeinterval); 3576 RT_TRACE(COMP_HALDM, "RSSI %d TimeInterval %d MultipleTimeInterval %d\n", priv->ieee80211->fsync_rssi_threshold, priv->ieee80211->fsync_time_interval, priv->ieee80211->fsync_multiple_timeinterval);
3577 RT_TRACE(COMP_HALDM, "RateBitmap 0x%x FirstDiffRateThreshold %d SecondDiffRateThreshold %d\n", priv->ieee80211->fsync_rate_bitmap, priv->ieee80211->fsync_firstdiff_ratethreshold, priv->ieee80211->fsync_seconddiff_ratethreshold); 3577 RT_TRACE(COMP_HALDM, "RateBitmap 0x%x FirstDiffRateThreshold %d SecondDiffRateThreshold %d\n", priv->ieee80211->fsync_rate_bitmap, priv->ieee80211->fsync_firstdiff_ratethreshold, priv->ieee80211->fsync_seconddiff_ratethreshold);
@@ -3887,4 +3887,3 @@ static void dm_send_rssi_tofw(struct net_device *dev)
3887} 3887}
3888 3888
3889/*---------------------------Define function prototype------------------------*/ 3889/*---------------------------Define function prototype------------------------*/
3890
diff --git a/drivers/staging/rtl8192u/r8192U_dm.h b/drivers/staging/rtl8192u/r8192U_dm.h
index 3ceb59b9eca7..ffb083c958ad 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.h
+++ b/drivers/staging/rtl8192u/r8192U_dm.h
@@ -13,7 +13,7 @@
13 * 13 *
14 * History: 14 * History:
15 * Data Who Remark 15 * Data Who Remark
16 * 10/04/2007 MHC Create initial version. 16 * 10/04/2007 MHC Create initial version.
17 * 17 *
18 *****************************************************************************/ 18 *****************************************************************************/
19 /* Check to see if the file has been included already. */ 19 /* Check to see if the file has been included already. */
@@ -55,20 +55,19 @@
55#define TX_POWER_NEAR_FIELD_THRESH_LOW 62 55#define TX_POWER_NEAR_FIELD_THRESH_LOW 62
56//added by amy for atheros AP 56//added by amy for atheros AP
57#define TX_POWER_ATHEROAP_THRESH_HIGH 78 57#define TX_POWER_ATHEROAP_THRESH_HIGH 78
58#define TX_POWER_ATHEROAP_THRESH_LOW 72 58#define TX_POWER_ATHEROAP_THRESH_LOW 72
59 59
60//defined by vivi, for showing on UI 60//defined by vivi, for showing on UI
61#define Current_Tx_Rate_Reg 0x1b8 61#define Current_Tx_Rate_Reg 0x1b8
62#define Initial_Tx_Rate_Reg 0x1b9 62#define Initial_Tx_Rate_Reg 0x1b9
63#define Tx_Retry_Count_Reg 0x1ac 63#define Tx_Retry_Count_Reg 0x1ac
64#define RegC38_TH 20 64#define RegC38_TH 20
65/*--------------------------Define Parameters-------------------------------*/ 65/*--------------------------Define Parameters-------------------------------*/
66 66
67 67
68/*------------------------------Define structure----------------------------*/ 68/*------------------------------Define structure----------------------------*/
69/* 2007/10/04 MH Define upper and lower threshold of DIG enable or disable. */ 69/* 2007/10/04 MH Define upper and lower threshold of DIG enable or disable. */
70typedef struct _dynamic_initial_gain_threshold_ 70typedef struct _dynamic_initial_gain_threshold_ {
71{
72 u8 dig_enable_flag; 71 u8 dig_enable_flag;
73 u8 dig_algorithm; 72 u8 dig_algorithm;
74 u8 dbg_mode; 73 u8 dbg_mode;
@@ -132,8 +131,8 @@ typedef enum tag_dynamic_init_gain_operation_type_definition
132 DIG_TYPE_PWDB_FACTOR = 8, 131 DIG_TYPE_PWDB_FACTOR = 8,
133 DIG_TYPE_RX_GAIN_MIN = 9, 132 DIG_TYPE_RX_GAIN_MIN = 9,
134 DIG_TYPE_RX_GAIN_MAX = 10, 133 DIG_TYPE_RX_GAIN_MAX = 10,
135 DIG_TYPE_ENABLE = 20, 134 DIG_TYPE_ENABLE = 20,
136 DIG_TYPE_DISABLE = 30, 135 DIG_TYPE_DISABLE = 30,
137 DIG_OP_TYPE_MAX 136 DIG_OP_TYPE_MAX
138}dm_dig_op_e; 137}dm_dig_op_e;
139 138
@@ -172,8 +171,7 @@ typedef enum tag_dig_cck_cs_ratio_state_definition
172 DIG_CS_RATIO_HIGHER = 1, 171 DIG_CS_RATIO_HIGHER = 1,
173 DIG_CS_MAX 172 DIG_CS_MAX
174}dm_dig_cs_ratio_e; 173}dm_dig_cs_ratio_e;
175typedef struct _Dynamic_Rx_Path_Selection_ 174typedef struct _Dynamic_Rx_Path_Selection_ {
176{
177 u8 Enable; 175 u8 Enable;
178 u8 DbgMode; 176 u8 DbgMode;
179 u8 cck_method; 177 u8 cck_method;
@@ -203,8 +201,7 @@ typedef enum tag_DM_DbgMode_Definition
203 DM_DBG_MAX 201 DM_DBG_MAX
204}DM_DBG_E; 202}DM_DBG_E;
205 203
206typedef struct tag_Tx_Config_Cmd_Format 204typedef struct tag_Tx_Config_Cmd_Format {
207{
208 u32 Op; /* Command packet type. */ 205 u32 Op; /* Command packet type. */
209 u32 Length; /* Command packet length. */ 206 u32 Length; /* Command packet length. */
210 u32 Value; 207 u32 Value;
@@ -251,4 +248,3 @@ extern void dm_initialize_txpower_tracking(struct net_device *dev);
251 248
252 249
253/* End of r8192U_dm.h */ 250/* End of r8192U_dm.h */
254
diff --git a/drivers/staging/rtl8192u/r8192U_hw.h b/drivers/staging/rtl8192u/r8192U_hw.h
index 1bfe871dcfb2..15b0423356f8 100644
--- a/drivers/staging/rtl8192u/r8192U_hw.h
+++ b/drivers/staging/rtl8192u/r8192U_hw.h
@@ -122,7 +122,7 @@ enum _RTL8192Usb_HW {
122 SIFS = 0x03E, // SIFS register 122 SIFS = 0x03E, // SIFS register
123 TCR = 0x040, // Transmit Configuration Register 123 TCR = 0x040, // Transmit Configuration Register
124 124
125#define TCR_MXDMA_2048 7 125#define TCR_MXDMA_2048 7
126#define TCR_LRL_OFFSET 0 126#define TCR_LRL_OFFSET 0
127#define TCR_SRL_OFFSET 8 127#define TCR_SRL_OFFSET 8
128#define TCR_MXDMA_OFFSET 21 128#define TCR_MXDMA_OFFSET 21
@@ -379,7 +379,7 @@ enum _RTL8192Usb_HW {
379// IMR_POLL = 0x360, 379// IMR_POLL = 0x360,
380 MacBlkCtrl = 0x403, // Mac block on/off control register 380 MacBlkCtrl = 0x403, // Mac block on/off control register
381 381
382 EPROM_CMD = 0xfe58, 382 EPROM_CMD = 0xfe58,
383#define Cmd9346CR_9356SEL (1<<4) 383#define Cmd9346CR_9356SEL (1<<4)
384#define EPROM_CMD_RESERVED_MASK (1<<5) 384#define EPROM_CMD_RESERVED_MASK (1<<5)
385#define EPROM_CMD_OPERATING_MODE_SHIFT 6 385#define EPROM_CMD_OPERATING_MODE_SHIFT 6
@@ -392,12 +392,12 @@ enum _RTL8192Usb_HW {
392#define EPROM_CK_SHIFT 2 392#define EPROM_CK_SHIFT 2
393#define EPROM_W_SHIFT 1 393#define EPROM_W_SHIFT 1
394#define EPROM_R_SHIFT 0 394#define EPROM_R_SHIFT 0
395 MAC0 = 0x000, 395 MAC0 = 0x000,
396 MAC1 = 0x001, 396 MAC1 = 0x001,
397 MAC2 = 0x002, 397 MAC2 = 0x002,
398 MAC3 = 0x003, 398 MAC3 = 0x003,
399 MAC4 = 0x004, 399 MAC4 = 0x004,
400 MAC5 = 0x005, 400 MAC5 = 0x005,
401 401
402}; 402};
403//---------------------------------------------------------------------------- 403//----------------------------------------------------------------------------
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c
index 71f2d2349c38..c904aa8cc0a6 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.c
+++ b/drivers/staging/rtl8192u/r8192U_wx.c
@@ -354,8 +354,7 @@ static int r8192_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
354 return ret; 354 return ret;
355} 355}
356 356
357struct iw_range_with_scan_capa 357struct iw_range_with_scan_capa {
358{
359 /* Informative stuff (to choose between different interface) */ 358 /* Informative stuff (to choose between different interface) */
360 __u32 throughput; /* To give an idea... */ 359 __u32 throughput; /* To give an idea... */
361 /* In theory this value should be the maximum benchmarked 360 /* In theory this value should be the maximum benchmarked
@@ -711,12 +710,12 @@ static int r8192_wx_set_enc(struct net_device *dev,
711 #define CONF_WEP104 0x14 710 #define CONF_WEP104 0x14
712 711
713 switch(wrqu->encoding.flags & IW_ENCODE_INDEX){ 712 switch(wrqu->encoding.flags & IW_ENCODE_INDEX){
714 case 0: key_idx = ieee->tx_keyidx; break; 713 case 0: key_idx = ieee->tx_keyidx; break;
715 case 1: key_idx = 0; break; 714 case 1: key_idx = 0; break;
716 case 2: key_idx = 1; break; 715 case 2: key_idx = 1; break;
717 case 3: key_idx = 2; break; 716 case 3: key_idx = 2; break;
718 case 4: key_idx = 3; break; 717 case 4: key_idx = 3; break;
719 default: break; 718 default: break;
720 } 719 }
721 720
722 if(wrqu->encoding.length==0x5){ 721 if(wrqu->encoding.length==0x5){
@@ -1021,7 +1020,7 @@ static int dummy(struct net_device *dev, struct iw_request_info *a,
1021static iw_handler r8192_wx_handlers[] = 1020static iw_handler r8192_wx_handlers[] =
1022{ 1021{
1023 NULL, /* SIOCSIWCOMMIT */ 1022 NULL, /* SIOCSIWCOMMIT */
1024 r8192_wx_get_name, /* SIOCGIWNAME */ 1023 r8192_wx_get_name, /* SIOCGIWNAME */
1025 dummy, /* SIOCSIWNWID */ 1024 dummy, /* SIOCSIWNWID */
1026 dummy, /* SIOCGIWNWID */ 1025 dummy, /* SIOCGIWNWID */
1027 r8192_wx_set_freq, /* SIOCSIWFREQ */ 1026 r8192_wx_set_freq, /* SIOCSIWFREQ */
@@ -1040,7 +1039,7 @@ static iw_handler r8192_wx_handlers[] =
1040 dummy, /* SIOCGIWSPY */ 1039 dummy, /* SIOCGIWSPY */
1041 NULL, /* SIOCGIWTHRSPY */ 1040 NULL, /* SIOCGIWTHRSPY */
1042 NULL, /* SIOCWIWTHRSPY */ 1041 NULL, /* SIOCWIWTHRSPY */
1043 r8192_wx_set_wap, /* SIOCSIWAP */ 1042 r8192_wx_set_wap, /* SIOCSIWAP */
1044 r8192_wx_get_wap, /* SIOCGIWAP */ 1043 r8192_wx_get_wap, /* SIOCGIWAP */
1045#if (WIRELESS_EXT >= 18) 1044#if (WIRELESS_EXT >= 18)
1046 r8192_wx_set_mlme, /* MLME-- */ 1045 r8192_wx_set_mlme, /* MLME-- */
@@ -1071,23 +1070,23 @@ static iw_handler r8192_wx_handlers[] =
1071 r8192_wx_set_power, /* SIOCSIWPOWER */ 1070 r8192_wx_set_power, /* SIOCSIWPOWER */
1072 r8192_wx_get_power, /* SIOCGIWPOWER */ 1071 r8192_wx_get_power, /* SIOCGIWPOWER */
1073 NULL, /*---hole---*/ 1072 NULL, /*---hole---*/
1074 NULL, /*---hole---*/ 1073 NULL, /*---hole---*/
1075 r8192_wx_set_gen_ie,//NULL, /* SIOCSIWGENIE */ 1074 r8192_wx_set_gen_ie,//NULL, /* SIOCSIWGENIE */
1076 NULL, /* SIOCSIWGENIE */ 1075 NULL, /* SIOCSIWGENIE */
1077 1076
1078#if (WIRELESS_EXT >= 18) 1077#if (WIRELESS_EXT >= 18)
1079 r8192_wx_set_auth,//NULL, /* SIOCSIWAUTH */ 1078 r8192_wx_set_auth,//NULL, /* SIOCSIWAUTH */
1080 NULL,//r8192_wx_get_auth,//NULL, /* SIOCSIWAUTH */ 1079 NULL,//r8192_wx_get_auth,//NULL, /* SIOCSIWAUTH */
1081 r8192_wx_set_enc_ext, /* SIOCSIWENCODEEXT */ 1080 r8192_wx_set_enc_ext, /* SIOCSIWENCODEEXT */
1082 NULL,//r8192_wx_get_enc_ext,//NULL, /* SIOCSIWENCODEEXT */ 1081 NULL,//r8192_wx_get_enc_ext,//NULL, /* SIOCSIWENCODEEXT */
1083#else 1082#else
1084 NULL, 1083 NULL,
1085 NULL, 1084 NULL,
1086 NULL, 1085 NULL,
1087 NULL, 1086 NULL,
1088#endif 1087#endif
1089 NULL, /* SIOCSIWPMKSA */ 1088 NULL, /* SIOCSIWPMKSA */
1090 NULL, /*---hole---*/ 1089 NULL, /*---hole---*/
1091 1090
1092}; 1091};
1093 1092
diff --git a/drivers/staging/rtl8192u/r819xU_HTGen.h b/drivers/staging/rtl8192u/r819xU_HTGen.h
index f37b6d69b404..6a4678f7da5f 100644
--- a/drivers/staging/rtl8192u/r819xU_HTGen.h
+++ b/drivers/staging/rtl8192u/r819xU_HTGen.h
@@ -10,4 +10,3 @@ typedef enum _HT_IOT_ACTION{
10 HT_IOT_ACT_CDD_FSYNC = 0x00000020, 10 HT_IOT_ACT_CDD_FSYNC = 0x00000020,
11 HT_IOT_ACT_PURE_N_MODE = 0x00000040, 11 HT_IOT_ACT_PURE_N_MODE = 0x00000040,
12}HT_IOT_ACTION_E, *PHT_IOT_ACTION_E; 12}HT_IOT_ACTION_E, *PHT_IOT_ACTION_E;
13
diff --git a/drivers/staging/rtl8192u/r819xU_HTType.h b/drivers/staging/rtl8192u/r819xU_HTType.h
index 6c1d05e1e820..19a7bdd1973a 100644
--- a/drivers/staging/rtl8192u/r819xU_HTType.h
+++ b/drivers/staging/rtl8192u/r819xU_HTType.h
@@ -89,7 +89,7 @@ typedef enum _CHNLOP{
89 89
90typedef enum _HT_ACTION{ 90typedef enum _HT_ACTION{
91 ACT_RECOMMAND_WIDTH = 0, 91 ACT_RECOMMAND_WIDTH = 0,
92 ACT_MIMO_PWR_SAVE = 1, 92 ACT_MIMO_PWR_SAVE = 1,
93 ACT_PSMP = 2, 93 ACT_PSMP = 2,
94 ACT_SET_PCO_PHASE = 3, 94 ACT_SET_PCO_PHASE = 3,
95 ACT_MIMO_CHL_MEASURE = 4, 95 ACT_MIMO_CHL_MEASURE = 4,
@@ -367,9 +367,9 @@ typedef struct _BSS_HT{
367typedef struct _MIMO_RSSI{ 367typedef struct _MIMO_RSSI{
368 u32 EnableAntenna; 368 u32 EnableAntenna;
369 u32 AntennaA; 369 u32 AntennaA;
370 u32 AntennaB; 370 u32 AntennaB;
371 u32 AntennaC; 371 u32 AntennaC;
372 u32 AntennaD; 372 u32 AntennaD;
373 u32 Average; 373 u32 Average;
374}MIMO_RSSI, *PMIMO_RSSI; 374}MIMO_RSSI, *PMIMO_RSSI;
375 375
@@ -388,4 +388,3 @@ typedef struct _FALSE_ALARM_STATISTICS{
388 388
389 389
390#endif //__INC_HTTYPE_H 390#endif //__INC_HTTYPE_H
391
diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.c b/drivers/staging/rtl8192u/r819xU_cmdpkt.c
index a8a6dc2c365f..b755eb46341f 100644
--- a/drivers/staging/rtl8192u/r819xU_cmdpkt.c
+++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.c
@@ -18,7 +18,7 @@
18 History: 18 History:
19 Data Who Remark 19 Data Who Remark
20 20
21 05/06/2008 amy Create initial version porting from windows driver. 21 05/06/2008 amy Create initial version porting from windows driver.
22 22
23******************************************************************************/ 23******************************************************************************/
24#include "r8192U.h" 24#include "r8192U.h"
@@ -41,7 +41,7 @@
41rt_status 41rt_status
42SendTxCommandPacket( 42SendTxCommandPacket(
43 struct net_device *dev, 43 struct net_device *dev,
44 void* pData, 44 void* pData,
45 u32 DataLen 45 u32 DataLen
46 ) 46 )
47{ 47{
@@ -106,7 +106,7 @@ SendTxCommandPacket(
106 u32 buffer_len) 106 u32 buffer_len)
107{ 107{
108 108
109 bool rt_status = true; 109 bool rt_status = true;
110#ifdef RTL8192U 110#ifdef RTL8192U
111 return rt_status; 111 return rt_status;
112#else 112#else
@@ -188,7 +188,7 @@ SendTxCommandPacket(
188 * 188 *
189 * Overview: 189 * Overview:
190 * 190 *
191 * Input: PADAPTER pAdapter - . 191 * Input: PADAPTER pAdapter - .
192 * CMPK_TXFB_T *psTx_FB - . 192 * CMPK_TXFB_T *psTx_FB - .
193 * 193 *
194 * Output: NONE 194 * Output: NONE
@@ -197,7 +197,7 @@ SendTxCommandPacket(
197 * 197 *
198 * Revised History: 198 * Revised History:
199 * When Who Remark 199 * When Who Remark
200 * 05/12/2008 amy Create Version 0 porting from windows code. 200 * 05/12/2008 amy Create Version 0 porting from windows code.
201 * 201 *
202 *---------------------------------------------------------------------------*/ 202 *---------------------------------------------------------------------------*/
203static void 203static void
@@ -289,7 +289,7 @@ cmpk_count_txstatistic(
289 * in the command packet. 289 * in the command packet.
290 * 290 *
291 * Input: struct net_device * dev 291 * Input: struct net_device * dev
292 * u8 * pmsg - Msg Ptr of the command packet. 292 * u8 * pmsg - Msg Ptr of the command packet.
293 * 293 *
294 * Output: NONE 294 * Output: NONE
295 * 295 *
@@ -369,7 +369,7 @@ cmdpkt_beacontimerinterrupt_819xusb(
369 * Overview: The function is responsible for extract the message from 369 * Overview: The function is responsible for extract the message from
370 * firmware. It will contain dedicated info in 370 * firmware. It will contain dedicated info in
371 * ws-07-0063-v06-rtl819x-command-packet-specification-070315.doc. 371 * ws-07-0063-v06-rtl819x-command-packet-specification-070315.doc.
372 * Please refer to chapter "Interrupt Status Element". 372 * Please refer to chapter "Interrupt Status Element".
373 * 373 *
374 * Input: struct net_device *dev, 374 * Input: struct net_device *dev,
375 * u8* pmsg - Message Pointer of the command packet. 375 * u8* pmsg - Message Pointer of the command packet.
@@ -400,8 +400,8 @@ cmpk_handle_interrupt_status(
400 /* It seems that FW use big endian(MIPS) and DRV use little endian in 400 /* It seems that FW use big endian(MIPS) and DRV use little endian in
401 windows OS. So we have to read the content byte by byte or transfer 401 windows OS. So we have to read the content byte by byte or transfer
402 endian type before copy the message copy. */ 402 endian type before copy the message copy. */
403 //rx_bcn_state.Element_ID = pMsg[0]; 403 //rx_bcn_state.Element_ID = pMsg[0];
404 //rx_bcn_state.Length = pMsg[1]; 404 //rx_bcn_state.Length = pMsg[1];
405 rx_intr_status.length = pmsg[1]; 405 rx_intr_status.length = pmsg[1];
406 if (rx_intr_status.length != (sizeof(cmpk_intr_sta_t) - 2)) 406 if (rx_intr_status.length != (sizeof(cmpk_intr_sta_t) - 2))
407 { 407 {
@@ -478,16 +478,16 @@ cmpk_handle_query_config_rx(
478 /* It seems that FW use big endian(MIPS) and DRV use little endian in 478 /* It seems that FW use big endian(MIPS) and DRV use little endian in
479 windows OS. So we have to read the content byte by byte or transfer 479 windows OS. So we have to read the content byte by byte or transfer
480 endian type before copy the message copy. */ 480 endian type before copy the message copy. */
481 //rx_query_cfg.Element_ID = pMsg[0]; 481 //rx_query_cfg.Element_ID = pMsg[0];
482 //rx_query_cfg.Length = pMsg[1]; 482 //rx_query_cfg.Length = pMsg[1];
483 rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000)>>31; 483 rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000)>>31;
484 rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5; 484 rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5;
485 rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3; 485 rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3;
486 rx_query_cfg.cfg_page = (pmsg[6] & 0x0F) >> 0; 486 rx_query_cfg.cfg_page = (pmsg[6] & 0x0F) >> 0;
487 rx_query_cfg.cfg_offset = pmsg[7]; 487 rx_query_cfg.cfg_offset = pmsg[7];
488 rx_query_cfg.value = (pmsg[8] << 24) | (pmsg[9] << 16) | 488 rx_query_cfg.value = (pmsg[8] << 24) | (pmsg[9] << 16) |
489 (pmsg[10] << 8) | (pmsg[11] << 0); 489 (pmsg[10] << 8) | (pmsg[11] << 0);
490 rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) | 490 rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) |
491 (pmsg[14] << 8) | (pmsg[15] << 0); 491 (pmsg[14] << 8) | (pmsg[15] << 0);
492 492
493} /* cmpk_Handle_Query_Config_Rx */ 493} /* cmpk_Handle_Query_Config_Rx */
@@ -511,7 +511,7 @@ cmpk_handle_query_config_rx(
511 * 511 *
512 *---------------------------------------------------------------------------*/ 512 *---------------------------------------------------------------------------*/
513static void cmpk_count_tx_status( struct net_device *dev, 513static void cmpk_count_tx_status( struct net_device *dev,
514 cmpk_tx_status_t *pstx_status) 514 cmpk_tx_status_t *pstx_status)
515{ 515{
516 struct r8192_priv *priv = ieee80211_priv(dev); 516 struct r8192_priv *priv = ieee80211_priv(dev);
517 517
diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.h b/drivers/staging/rtl8192u/r819xU_cmdpkt.h
index a8855e61b0e5..59caa4e05323 100644
--- a/drivers/staging/rtl8192u/r819xU_cmdpkt.h
+++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.h
@@ -19,8 +19,7 @@
19/*------------------------------Define structure----------------------------*/ 19/*------------------------------Define structure----------------------------*/
20/* Define different command packet structure. */ 20/* Define different command packet structure. */
21/* 1. RX side: TX feedback packet. */ 21/* 1. RX side: TX feedback packet. */
22typedef struct tag_cmd_pkt_tx_feedback 22typedef struct tag_cmd_pkt_tx_feedback {
23{
24 // DWORD 0 23 // DWORD 0
25 u8 element_id; /* Command packet type. */ 24 u8 element_id; /* Command packet type. */
26 u8 length; /* Command packet length. */ 25 u8 length; /* Command packet length. */
@@ -57,8 +56,7 @@ typedef struct tag_cmd_pkt_tx_feedback
57 56
58/* 2. RX side: Interrupt status packet. It includes Beacon State, 57/* 2. RX side: Interrupt status packet. It includes Beacon State,
59 Beacon Timer Interrupt and other useful informations in MAC ISR Reg. */ 58 Beacon Timer Interrupt and other useful informations in MAC ISR Reg. */
60typedef struct tag_cmd_pkt_interrupt_status 59typedef struct tag_cmd_pkt_interrupt_status {
61{
62 u8 element_id; /* Command packet type. */ 60 u8 element_id; /* Command packet type. */
63 u8 length; /* Command packet length. */ 61 u8 length; /* Command packet length. */
64 u16 reserve; 62 u16 reserve;
@@ -67,12 +65,11 @@ typedef struct tag_cmd_pkt_interrupt_status
67 65
68 66
69/* 3. TX side: Set configuration packet. */ 67/* 3. TX side: Set configuration packet. */
70typedef struct tag_cmd_pkt_set_configuration 68typedef struct tag_cmd_pkt_set_configuration {
71{
72 u8 element_id; /* Command packet type. */ 69 u8 element_id; /* Command packet type. */
73 u8 length; /* Command packet length. */ 70 u8 length; /* Command packet length. */
74 u16 reserve1; /* */ 71 u16 reserve1; /* */
75 u8 cfg_reserve1:3; 72 u8 cfg_reserve1:3;
76 u8 cfg_size:2; /* Configuration info. */ 73 u8 cfg_size:2; /* Configuration info. */
77 u8 cfg_type:2; /* Configuration info. */ 74 u8 cfg_type:2; /* Configuration info. */
78 u8 cfg_action:1; /* Configuration info. */ 75 u8 cfg_action:1; /* Configuration info. */
@@ -89,25 +86,24 @@ typedef struct tag_cmd_pkt_set_configuration
89#define cmpk_query_cfg_t cmpk_set_cfg_t 86#define cmpk_query_cfg_t cmpk_set_cfg_t
90 87
91/* 5. Multi packet feedback status. */ 88/* 5. Multi packet feedback status. */
92typedef struct tag_tx_stats_feedback // PJ quick rxcmd 09042007 89typedef struct tag_tx_stats_feedback { // PJ quick rxcmd 09042007
93{
94 // For endian transfer --> Driver will not the same as firmware structure. 90 // For endian transfer --> Driver will not the same as firmware structure.
95 // DW 0 91 // DW 0
96 u16 reserve1; 92 u16 reserve1;
97 u8 length; // Command packet length 93 u8 length; // Command packet length
98 u8 element_id; // Command packet type 94 u8 element_id; // Command packet type
99 95
100 // DW 1 96 // DW 1
101 u16 txfail; // Tx Fail count 97 u16 txfail; // Tx Fail count
102 u16 txok; // Tx ok count 98 u16 txok; // Tx ok count
103 99
104 // DW 2 100 // DW 2
105 u16 txmcok; // tx multicast 101 u16 txmcok; // tx multicast
106 u16 txretry; // Tx Retry count 102 u16 txretry; // Tx Retry count
107 103
108 // DW 3 104 // DW 3
109 u16 txucok; // tx unicast 105 u16 txucok; // tx unicast
110 u16 txbcok; // tx broadcast 106 u16 txbcok; // tx broadcast
111 107
112 // DW 4 108 // DW 4
113 u16 txbcfail; // 109 u16 txbcfail; //
@@ -130,13 +126,12 @@ typedef struct tag_tx_stats_feedback // PJ quick rxcmd 09042007
130 126
131/* 6. Debug feedback message. */ 127/* 6. Debug feedback message. */
132/* 2007/10/23 MH Define RX debug message */ 128/* 2007/10/23 MH Define RX debug message */
133typedef struct tag_rx_debug_message_feedback 129typedef struct tag_rx_debug_message_feedback {
134{
135 // For endian transfer --> for driver 130 // For endian transfer --> for driver
136 // DW 0 131 // DW 0
137 u16 reserve1; 132 u16 reserve1;
138 u8 length; // Command packet length 133 u8 length; // Command packet length
139 u8 element_id; // Command packet type 134 u8 element_id; // Command packet type
140 135
141 // DW 1-?? 136 // DW 1-??
142 // Variable debug message. 137 // Variable debug message.
@@ -144,19 +139,18 @@ typedef struct tag_rx_debug_message_feedback
144}cmpk_rx_dbginfo_t; 139}cmpk_rx_dbginfo_t;
145 140
146/* 2008/03/20 MH Define transmit rate history. For big endian format. */ 141/* 2008/03/20 MH Define transmit rate history. For big endian format. */
147typedef struct tag_tx_rate_history 142typedef struct tag_tx_rate_history {
148{
149 // For endian transfer --> for driver 143 // For endian transfer --> for driver
150 // DW 0 144 // DW 0
151 u8 element_id; // Command packet type 145 u8 element_id; // Command packet type
152 u8 length; // Command packet length 146 u8 length; // Command packet length
153 u16 reserved1; 147 u16 reserved1;
154 148
155 // DW 1-2 CCK rate counter 149 // DW 1-2 CCK rate counter
156 u16 cck[4]; 150 u16 cck[4];
157 151
158 // DW 3-6 152 // DW 3-6
159 u16 ofdm[8]; 153 u16 ofdm[8];
160 154
161 // DW 7-14 155 // DW 7-14
162 //UINT16 MCS_BW0_SG0[16]; 156 //UINT16 MCS_BW0_SG0[16];
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
index b12d19079798..573e9cd68509 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.c
+++ b/drivers/staging/rtl8192u/r819xU_firmware.c
@@ -2,7 +2,7 @@
2 * Procedure: Init boot code/firmware code/data session 2 * Procedure: Init boot code/firmware code/data session
3 * 3 *
4 * Description: This routine will initialize firmware. If any error occurs during the initialization 4 * Description: This routine will initialize firmware. If any error occurs during the initialization
5 * process, the routine shall terminate immediately and return fail. 5 * process, the routine shall terminate immediately and return fail.
6 * NIC driver should call NdisOpenFile only from MiniportInitialize. 6 * NIC driver should call NdisOpenFile only from MiniportInitialize.
7 * 7 *
8 * Arguments: The pointer of the adapter 8 * Arguments: The pointer of the adapter
@@ -19,7 +19,7 @@
19#include <linux/firmware.h> 19#include <linux/firmware.h>
20void firmware_init_param(struct net_device *dev) 20void firmware_init_param(struct net_device *dev)
21{ 21{
22 struct r8192_priv *priv = ieee80211_priv(dev); 22 struct r8192_priv *priv = ieee80211_priv(dev);
23 rt_firmware *pfirmware = priv->pFirmware; 23 rt_firmware *pfirmware = priv->pFirmware;
24 24
25 pfirmware->cmdpacket_frag_thresold = GET_COMMAND_PACKET_FRAG_THRESHOLD(MAX_TRANSMIT_BUFFER_SIZE); 25 pfirmware->cmdpacket_frag_thresold = GET_COMMAND_PACKET_FRAG_THRESHOLD(MAX_TRANSMIT_BUFFER_SIZE);
@@ -32,7 +32,7 @@ void firmware_init_param(struct net_device *dev)
32bool fw_download_code(struct net_device *dev, u8 *code_virtual_address, u32 buffer_len) 32bool fw_download_code(struct net_device *dev, u8 *code_virtual_address, u32 buffer_len)
33{ 33{
34 struct r8192_priv *priv = ieee80211_priv(dev); 34 struct r8192_priv *priv = ieee80211_priv(dev);
35 bool rt_status = true; 35 bool rt_status = true;
36 u16 frag_threshold; 36 u16 frag_threshold;
37 u16 frag_length, frag_offset = 0; 37 u16 frag_length, frag_offset = 0;
38 //u16 total_size; 38 //u16 total_size;
@@ -241,17 +241,17 @@ CPUCheckFirmwareReady_Fail:
241 241
242bool init_firmware(struct net_device *dev) 242bool init_firmware(struct net_device *dev)
243{ 243{
244 struct r8192_priv *priv = ieee80211_priv(dev); 244 struct r8192_priv *priv = ieee80211_priv(dev);
245 bool rt_status = TRUE; 245 bool rt_status = TRUE;
246 246
247 u32 file_length = 0; 247 u32 file_length = 0;
248 u8 *mapped_file = NULL; 248 u8 *mapped_file = NULL;
249 u32 init_step = 0; 249 u32 init_step = 0;
250 opt_rst_type_e rst_opt = OPT_SYSTEM_RESET; 250 opt_rst_type_e rst_opt = OPT_SYSTEM_RESET;
251 firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT; 251 firmware_init_step_e starting_state = FW_INIT_STEP0_BOOT;
252 252
253 rt_firmware *pfirmware = priv->pFirmware; 253 rt_firmware *pfirmware = priv->pFirmware;
254 const struct firmware *fw_entry; 254 const struct firmware *fw_entry;
255 const char *fw_name[3] = { "RTL8192U/boot.img", 255 const char *fw_name[3] = { "RTL8192U/boot.img",
256 "RTL8192U/main.img", 256 "RTL8192U/main.img",
257 "RTL8192U/data.img"}; 257 "RTL8192U/data.img"};
@@ -334,56 +334,56 @@ bool init_firmware(struct net_device *dev)
334 } 334 }
335 335
336 switch(init_step) { 336 switch(init_step) {
337 case FW_INIT_STEP0_BOOT: 337 case FW_INIT_STEP0_BOOT:
338 /* Download boot 338 /* Download boot
339 * initialize command descriptor. 339 * initialize command descriptor.
340 * will set polling bit when firmware code is also configured 340 * will set polling bit when firmware code is also configured
341 */ 341 */
342 pfirmware->firmware_status = FW_STATUS_1_MOVE_BOOT_CODE; 342 pfirmware->firmware_status = FW_STATUS_1_MOVE_BOOT_CODE;
343#ifdef RTL8190P 343#ifdef RTL8190P
344 // To initialize IMEM, CPU move code from 0x80000080, hence, we send 0x80 byte packet 344 // To initialize IMEM, CPU move code from 0x80000080, hence, we send 0x80 byte packet
345 rt_status = fwSendNullPacket(dev, RTL8190_CPU_START_OFFSET); 345 rt_status = fwSendNullPacket(dev, RTL8190_CPU_START_OFFSET);
346 if(rt_status != true) 346 if(rt_status != true)
347 { 347 {
348 RT_TRACE(COMP_INIT, "fwSendNullPacket() fail ! \n"); 348 RT_TRACE(COMP_INIT, "fwSendNullPacket() fail ! \n");
349 goto download_firmware_fail; 349 goto download_firmware_fail;
350 } 350 }
351#endif 351#endif
352 //mdelay(1000); 352 //mdelay(1000);
353 /* 353 /*
354 * To initialize IMEM, CPU move code from 0x80000080, 354 * To initialize IMEM, CPU move code from 0x80000080,
355 * hence, we send 0x80 byte packet 355 * hence, we send 0x80 byte packet
356 */ 356 */
357 break; 357 break;
358 358
359 case FW_INIT_STEP1_MAIN: 359 case FW_INIT_STEP1_MAIN:
360 /* Download firmware code. Wait until Boot Ready and Turn on CPU */ 360 /* Download firmware code. Wait until Boot Ready and Turn on CPU */
361 pfirmware->firmware_status = FW_STATUS_2_MOVE_MAIN_CODE; 361 pfirmware->firmware_status = FW_STATUS_2_MOVE_MAIN_CODE;
362 362
363 /* Check Put Code OK and Turn On CPU */ 363 /* Check Put Code OK and Turn On CPU */
364 rt_status = CPUcheck_maincodeok_turnonCPU(dev); 364 rt_status = CPUcheck_maincodeok_turnonCPU(dev);
365 if(rt_status != TRUE) { 365 if(rt_status != TRUE) {
366 RT_TRACE(COMP_ERR, "CPUcheck_maincodeok_turnonCPU fail!\n"); 366 RT_TRACE(COMP_ERR, "CPUcheck_maincodeok_turnonCPU fail!\n");
367 goto download_firmware_fail; 367 goto download_firmware_fail;
368 } 368 }
369 369
370 pfirmware->firmware_status = FW_STATUS_3_TURNON_CPU; 370 pfirmware->firmware_status = FW_STATUS_3_TURNON_CPU;
371 break; 371 break;
372 372
373 case FW_INIT_STEP2_DATA: 373 case FW_INIT_STEP2_DATA:
374 /* download initial data code */ 374 /* download initial data code */
375 pfirmware->firmware_status = FW_STATUS_4_MOVE_DATA_CODE; 375 pfirmware->firmware_status = FW_STATUS_4_MOVE_DATA_CODE;
376 mdelay(1); 376 mdelay(1);
377 377
378 rt_status = CPUcheck_firmware_ready(dev); 378 rt_status = CPUcheck_firmware_ready(dev);
379 if(rt_status != TRUE) { 379 if(rt_status != TRUE) {
380 RT_TRACE(COMP_ERR, "CPUcheck_firmware_ready fail(%d)!\n",rt_status); 380 RT_TRACE(COMP_ERR, "CPUcheck_firmware_ready fail(%d)!\n",rt_status);
381 goto download_firmware_fail; 381 goto download_firmware_fail;
382 } 382 }
383 383
384 /* wait until data code is initialized ready.*/ 384 /* wait until data code is initialized ready.*/
385 pfirmware->firmware_status = FW_STATUS_5_READY; 385 pfirmware->firmware_status = FW_STATUS_5_READY;
386 break; 386 break;
387 } 387 }
388 } 388 }
389 389
@@ -402,4 +402,3 @@ download_firmware_fail:
402MODULE_FIRMWARE("RTL8192U/boot.img"); 402MODULE_FIRMWARE("RTL8192U/boot.img");
403MODULE_FIRMWARE("RTL8192U/main.img"); 403MODULE_FIRMWARE("RTL8192U/main.img");
404MODULE_FIRMWARE("RTL8192U/data.img"); 404MODULE_FIRMWARE("RTL8192U/data.img");
405
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.h b/drivers/staging/rtl8192u/r819xU_firmware.h
index a4bceeef33d3..c48c884aa1af 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.h
+++ b/drivers/staging/rtl8192u/r819xU_firmware.h
@@ -24,4 +24,3 @@ typedef enum _opt_rst_type{
24}opt_rst_type_e; 24}opt_rst_type_e;
25 25
26#endif 26#endif
27
diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c
index dd1954daea2d..17fac41c12d9 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -124,10 +124,10 @@ static void phy_FwRFSerialWrite( struct net_device* dev, RF90_RADIO_PATH_E
124/****************************************************************************** 124/******************************************************************************
125 *function: This function read register from RF chip 125 *function: This function read register from RF chip
126 * input: net_device dev 126 * input: net_device dev
127 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D 127 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
128 * u32 Offset //target address to be read 128 * u32 Offset //target address to be read
129 * output: none 129 * output: none
130 * return: u32 readback value 130 * return: u32 readback value
131 * notice: There are three types of serial operations:(1) Software serial write.(2)Hardware LSSI-Low Speed Serial Interface.(3)Hardware HSSI-High speed serial write. Driver here need to implement (1) and (2)---need more spec for this information. 131 * notice: There are three types of serial operations:(1) Software serial write.(2)Hardware LSSI-Low Speed Serial Interface.(3)Hardware HSSI-High speed serial write. Driver here need to implement (1) and (2)---need more spec for this information.
132 * ****************************************************************************/ 132 * ****************************************************************************/
133u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset) 133u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath, u32 Offset)
@@ -201,7 +201,7 @@ u32 rtl8192_phy_RFSerialRead(struct net_device* dev, RF90_RADIO_PATH_E eRFPath,
201/****************************************************************************** 201/******************************************************************************
202 *function: This function write data to RF register 202 *function: This function write data to RF register
203 * input: net_device dev 203 * input: net_device dev
204 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D 204 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
205 * u32 Offset //target address to be written 205 * u32 Offset //target address to be written
206 * u32 Data //The new register data to be written 206 * u32 Data //The new register data to be written
207 * output: none 207 * output: none
@@ -283,7 +283,7 @@ void rtl8192_phy_RFSerialWrite(struct net_device* dev, RF90_RADIO_PATH_E eRFPath
283/****************************************************************************** 283/******************************************************************************
284 *function: This function set specific bits to RF register 284 *function: This function set specific bits to RF register
285 * input: net_device dev 285 * input: net_device dev
286 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D 286 * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
287 * u32 RegAddr //target addr to be modified 287 * u32 RegAddr //target addr to be modified
288 * u32 BitMask //taget bit pos in the addr to be modified 288 * u32 BitMask //taget bit pos in the addr to be modified
289 * u32 Data //value to be write 289 * u32 Data //value to be write
@@ -684,8 +684,8 @@ void rtl8192_InitBBRFRegDef(struct net_device* dev)
684/****************************************************************************** 684/******************************************************************************
685 *function: This function is to write register and then readback to make sure whether BB and RF is OK 685 *function: This function is to write register and then readback to make sure whether BB and RF is OK
686 * input: net_device dev 686 * input: net_device dev
687 * HW90_BLOCK_E CheckBlock 687 * HW90_BLOCK_E CheckBlock
688 * RF90_RADIO_PATH_E eRFPath //only used when checkblock is HW90_BLOCK_RF 688 * RF90_RADIO_PATH_E eRFPath //only used when checkblock is HW90_BLOCK_RF
689 * output: none 689 * output: none
690 * return: return whether BB and RF is ok(0:OK; 1:Fail) 690 * return: return whether BB and RF is ok(0:OK; 1:Fail)
691 * notice: This function may be removed in the ASIC 691 * notice: This function may be removed in the ASIC
@@ -957,56 +957,56 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E
957 u8 ret = 0; 957 u8 ret = 0;
958 958
959 switch(eRFPath){ 959 switch(eRFPath){
960 case RF90_PATH_A: 960 case RF90_PATH_A:
961 for(i = 0;i<RadioA_ArrayLength; i=i+2){ 961 for(i = 0;i<RadioA_ArrayLength; i=i+2){
962
963 if(rtl819XRadioA_Array[i] == 0xfe){
964 mdelay(100);
965 continue;
966 }
967 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioA_Array[i], bMask12Bits, rtl819XRadioA_Array[i+1]);
968 mdelay(1);
969 962
963 if(rtl819XRadioA_Array[i] == 0xfe){
964 mdelay(100);
965 continue;
970 } 966 }
971 break; 967 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioA_Array[i], bMask12Bits, rtl819XRadioA_Array[i+1]);
972 case RF90_PATH_B: 968 mdelay(1);
973 for(i = 0;i<RadioB_ArrayLength; i=i+2){
974 969
975 if(rtl819XRadioB_Array[i] == 0xfe){ 970 }
976 mdelay(100); 971 break;
977 continue; 972 case RF90_PATH_B:
978 } 973 for(i = 0;i<RadioB_ArrayLength; i=i+2){
979 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioB_Array[i], bMask12Bits, rtl819XRadioB_Array[i+1]);
980 mdelay(1);
981 974
975 if(rtl819XRadioB_Array[i] == 0xfe){
976 mdelay(100);
977 continue;
982 } 978 }
983 break; 979 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioB_Array[i], bMask12Bits, rtl819XRadioB_Array[i+1]);
984 case RF90_PATH_C: 980 mdelay(1);
985 for(i = 0;i<RadioC_ArrayLength; i=i+2){
986 981
987 if(rtl819XRadioC_Array[i] == 0xfe){ 982 }
988 mdelay(100); 983 break;
989 continue; 984 case RF90_PATH_C:
990 } 985 for(i = 0;i<RadioC_ArrayLength; i=i+2){
991 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioC_Array[i], bMask12Bits, rtl819XRadioC_Array[i+1]);
992 mdelay(1);
993 986
987 if(rtl819XRadioC_Array[i] == 0xfe){
988 mdelay(100);
989 continue;
994 } 990 }
995 break; 991 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioC_Array[i], bMask12Bits, rtl819XRadioC_Array[i+1]);
996 case RF90_PATH_D: 992 mdelay(1);
997 for(i = 0;i<RadioD_ArrayLength; i=i+2){
998 993
999 if(rtl819XRadioD_Array[i] == 0xfe){ 994 }
1000 mdelay(100); 995 break;
1001 continue; 996 case RF90_PATH_D:
1002 } 997 for(i = 0;i<RadioD_ArrayLength; i=i+2){
1003 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioD_Array[i], bMask12Bits, rtl819XRadioD_Array[i+1]);
1004 mdelay(1);
1005 998
999 if(rtl819XRadioD_Array[i] == 0xfe){
1000 mdelay(100);
1001 continue;
1006 } 1002 }
1007 break; 1003 rtl8192_phy_SetRFReg(dev, eRFPath, rtl819XRadioD_Array[i], bMask12Bits, rtl819XRadioD_Array[i+1]);
1008 default: 1004 mdelay(1);
1009 break; 1005
1006 }
1007 break;
1008 default:
1009 break;
1010 } 1010 }
1011 1011
1012 return ret; 1012 return ret;
@@ -1015,7 +1015,7 @@ u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device* dev, RF90_RADIO_PATH_E
1015/****************************************************************************** 1015/******************************************************************************
1016 *function: This function set Tx Power of the channel 1016 *function: This function set Tx Power of the channel
1017 * input: struct net_device *dev 1017 * input: struct net_device *dev
1018 * u8 channel 1018 * u8 channel
1019 * output: none 1019 * output: none
1020 * return: none 1020 * return: none
1021 * Note: 1021 * Note:
@@ -1052,7 +1052,7 @@ void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
1052/****************************************************************************** 1052/******************************************************************************
1053 *function: This function set RF state on or off 1053 *function: This function set RF state on or off
1054 * input: struct net_device *dev 1054 * input: struct net_device *dev
1055 * RT_RF_POWER_STATE eRFPowerState //Power State to set 1055 * RT_RF_POWER_STATE eRFPowerState //Power State to set
1056 * output: none 1056 * output: none
1057 * return: none 1057 * return: none
1058 * Note: 1058 * Note:
@@ -1183,10 +1183,10 @@ bool rtl8192_SetRFPowerState(struct net_device *dev, RT_RF_POWER_STATE eRFPowerS
1183 1183
1184/**************************************************************************************** 1184/****************************************************************************************
1185 *function: This function set command table variable(struct SwChnlCmd). 1185 *function: This function set command table variable(struct SwChnlCmd).
1186 * input: SwChnlCmd* CmdTable //table to be set. 1186 * input: SwChnlCmd* CmdTable //table to be set.
1187 * u32 CmdTableIdx //variable index in table to be set 1187 * u32 CmdTableIdx //variable index in table to be set
1188 * u32 CmdTableSz //table size. 1188 * u32 CmdTableSz //table size.
1189 * SwChnlCmdID CmdID //command ID to set. 1189 * SwChnlCmdID CmdID //command ID to set.
1190 * u32 Para1 1190 * u32 Para1
1191 * u32 Para2 1191 * u32 Para2
1192 * u32 msDelay 1192 * u32 msDelay
@@ -1229,10 +1229,10 @@ u8 rtl8192_phy_SetSwChnlCmdArray(
1229/****************************************************************************** 1229/******************************************************************************
1230 *function: This function set channel step by step 1230 *function: This function set channel step by step
1231 * input: struct net_device *dev 1231 * input: struct net_device *dev
1232 * u8 channel 1232 * u8 channel
1233 * u8* stage //3 stages 1233 * u8* stage //3 stages
1234 * u8* step // 1234 * u8* step //
1235 * u32* delay //whether need to delay 1235 * u32* delay //whether need to delay
1236 * output: store new stage, step and delay for next step(combine with function above) 1236 * output: store new stage, step and delay for next step(combine with function above)
1237 * return: true if finished, false otherwise 1237 * return: true if finished, false otherwise
1238 * Note: Wait for simpler function to replace it //wb 1238 * Note: Wait for simpler function to replace it //wb
@@ -1386,7 +1386,7 @@ u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel, u8* stage, u
1386/****************************************************************************** 1386/******************************************************************************
1387 *function: This function does actually set channel work 1387 *function: This function does actually set channel work
1388 * input: struct net_device *dev 1388 * input: struct net_device *dev
1389 * u8 channel 1389 * u8 channel
1390 * output: none 1390 * output: none
1391 * return: noin 1391 * return: noin
1392 * Note: We should not call this function directly 1392 * Note: We should not call this function directly
@@ -1427,7 +1427,7 @@ void rtl8192_SwChnl_WorkItem(struct net_device *dev)
1427/****************************************************************************** 1427/******************************************************************************
1428 *function: This function scheduled actual work item to set channel 1428 *function: This function scheduled actual work item to set channel
1429 * input: net_device dev 1429 * input: net_device dev
1430 * u8 channel //channel to set 1430 * u8 channel //channel to set
1431 * output: none 1431 * output: none
1432 * return: return code show if workitem is scheduled(1:pass, 0:fail) 1432 * return: return code show if workitem is scheduled(1:pass, 0:fail)
1433 * Note: Delay may be required for RF configuration 1433 * Note: Delay may be required for RF configuration
@@ -1501,12 +1501,12 @@ if (0) //to test current channel from RF reg 0x7.
1501/****************************************************************************** 1501/******************************************************************************
1502 *function: Callback routine of the work item for set bandwidth mode. 1502 *function: Callback routine of the work item for set bandwidth mode.
1503 * input: struct net_device *dev 1503 * input: struct net_device *dev
1504 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M 1504 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
1505 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care 1505 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
1506 * output: none 1506 * output: none
1507 * return: none 1507 * return: none
1508 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can 1508 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
1509 * test whether current work in the queue or not.//do I? 1509 * test whether current work in the queue or not.//do I?
1510 * ***************************************************************************/ 1510 * ***************************************************************************/
1511void rtl8192_SetBWModeWorkItem(struct net_device *dev) 1511void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1512{ 1512{
@@ -1649,12 +1649,12 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1649/****************************************************************************** 1649/******************************************************************************
1650 *function: This function schedules bandwidth switch work. 1650 *function: This function schedules bandwidth switch work.
1651 * input: struct net_device *dev 1651 * input: struct net_device *dev
1652 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M 1652 * HT_CHANNEL_WIDTH Bandwidth //20M or 40M
1653 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care 1653 * HT_EXTCHNL_OFFSET Offset //Upper, Lower, or Don't care
1654 * output: none 1654 * output: none
1655 * return: none 1655 * return: none
1656 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can 1656 * Note: I doubt whether SetBWModeInProgress flag is necessary as we can
1657 * test whether current work in the queue or not.//do I? 1657 * test whether current work in the queue or not.//do I?
1658 * ***************************************************************************/ 1658 * ***************************************************************************/
1659void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset) 1659void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET Offset)
1660{ 1660{
@@ -1770,4 +1770,3 @@ extern void InitialGainOperateWorkItemCallBack(struct work_struct *work)
1770 break; 1770 break;
1771 } 1771 }
1772} 1772}
1773
diff --git a/drivers/staging/rtl8192u/r819xU_phyreg.h b/drivers/staging/rtl8192u/r819xU_phyreg.h
index cca34c05f6a5..64285d6a33f8 100644
--- a/drivers/staging/rtl8192u/r819xU_phyreg.h
+++ b/drivers/staging/rtl8192u/r819xU_phyreg.h
@@ -6,185 +6,185 @@
6 6
7//Register //duplicate register due to connection: RF_Mode, TRxRN, NumOf L-STF 7//Register //duplicate register due to connection: RF_Mode, TRxRN, NumOf L-STF
8//page 1 8//page 1
9#define rPMAC_Reset 0x100 9#define rPMAC_Reset 0x100
10#define rPMAC_TxStart 0x104 10#define rPMAC_TxStart 0x104
11#define rPMAC_TxLegacySIG 0x108 11#define rPMAC_TxLegacySIG 0x108
12#define rPMAC_TxHTSIG1 0x10c 12#define rPMAC_TxHTSIG1 0x10c
13#define rPMAC_TxHTSIG2 0x110 13#define rPMAC_TxHTSIG2 0x110
14#define rPMAC_PHYDebug 0x114 14#define rPMAC_PHYDebug 0x114
15#define rPMAC_TxPacketNum 0x118 15#define rPMAC_TxPacketNum 0x118
16#define rPMAC_TxIdle 0x11c 16#define rPMAC_TxIdle 0x11c
17#define rPMAC_TxMACHeader0 0x120 17#define rPMAC_TxMACHeader0 0x120
18#define rPMAC_TxMACHeader1 0x124 18#define rPMAC_TxMACHeader1 0x124
19#define rPMAC_TxMACHeader2 0x128 19#define rPMAC_TxMACHeader2 0x128
20#define rPMAC_TxMACHeader3 0x12c 20#define rPMAC_TxMACHeader3 0x12c
21#define rPMAC_TxMACHeader4 0x130 21#define rPMAC_TxMACHeader4 0x130
22#define rPMAC_TxMACHeader5 0x134 22#define rPMAC_TxMACHeader5 0x134
23#define rPMAC_TxDataType 0x138 23#define rPMAC_TxDataType 0x138
24#define rPMAC_TxRandomSeed 0x13c 24#define rPMAC_TxRandomSeed 0x13c
25#define rPMAC_CCKPLCPPreamble 0x140 25#define rPMAC_CCKPLCPPreamble 0x140
26#define rPMAC_CCKPLCPHeader 0x144 26#define rPMAC_CCKPLCPHeader 0x144
27#define rPMAC_CCKCRC16 0x148 27#define rPMAC_CCKCRC16 0x148
28#define rPMAC_OFDMRxCRC32OK 0x170 28#define rPMAC_OFDMRxCRC32OK 0x170
29#define rPMAC_OFDMRxCRC32Er 0x174 29#define rPMAC_OFDMRxCRC32Er 0x174
30#define rPMAC_OFDMRxParityEr 0x178 30#define rPMAC_OFDMRxParityEr 0x178
31#define rPMAC_OFDMRxCRC8Er 0x17c 31#define rPMAC_OFDMRxCRC8Er 0x17c
32#define rPMAC_CCKCRxRC16Er 0x180 32#define rPMAC_CCKCRxRC16Er 0x180
33#define rPMAC_CCKCRxRC32Er 0x184 33#define rPMAC_CCKCRxRC32Er 0x184
34#define rPMAC_CCKCRxRC32OK 0x188 34#define rPMAC_CCKCRxRC32OK 0x188
35#define rPMAC_TxStatus 0x18c 35#define rPMAC_TxStatus 0x18c
36 36
37//page8 37//page8
38#define rFPGA0_RFMOD 0x800 //RF mode & CCK TxSC 38#define rFPGA0_RFMOD 0x800 //RF mode & CCK TxSC
39#define rFPGA0_TxInfo 0x804 39#define rFPGA0_TxInfo 0x804
40#define rFPGA0_PSDFunction 0x808 40#define rFPGA0_PSDFunction 0x808
41#define rFPGA0_TxGainStage 0x80c 41#define rFPGA0_TxGainStage 0x80c
42#define rFPGA0_RFTiming1 0x810 42#define rFPGA0_RFTiming1 0x810
43#define rFPGA0_RFTiming2 0x814 43#define rFPGA0_RFTiming2 0x814
44//#define rFPGA0_XC_RFTiming 0x818 44//#define rFPGA0_XC_RFTiming 0x818
45//#define rFPGA0_XD_RFTiming 0x81c 45//#define rFPGA0_XD_RFTiming 0x81c
46#define rFPGA0_XA_HSSIParameter1 0x820 46#define rFPGA0_XA_HSSIParameter1 0x820
47#define rFPGA0_XA_HSSIParameter2 0x824 47#define rFPGA0_XA_HSSIParameter2 0x824
48#define rFPGA0_XB_HSSIParameter1 0x828 48#define rFPGA0_XB_HSSIParameter1 0x828
49#define rFPGA0_XB_HSSIParameter2 0x82c 49#define rFPGA0_XB_HSSIParameter2 0x82c
50#define rFPGA0_XC_HSSIParameter1 0x830 50#define rFPGA0_XC_HSSIParameter1 0x830
51#define rFPGA0_XC_HSSIParameter2 0x834 51#define rFPGA0_XC_HSSIParameter2 0x834
52#define rFPGA0_XD_HSSIParameter1 0x838 52#define rFPGA0_XD_HSSIParameter1 0x838
53#define rFPGA0_XD_HSSIParameter2 0x83c 53#define rFPGA0_XD_HSSIParameter2 0x83c
54#define rFPGA0_XA_LSSIParameter 0x840 54#define rFPGA0_XA_LSSIParameter 0x840
55#define rFPGA0_XB_LSSIParameter 0x844 55#define rFPGA0_XB_LSSIParameter 0x844
56#define rFPGA0_XC_LSSIParameter 0x848 56#define rFPGA0_XC_LSSIParameter 0x848
57#define rFPGA0_XD_LSSIParameter 0x84c 57#define rFPGA0_XD_LSSIParameter 0x84c
58#define rFPGA0_RFWakeUpParameter 0x850 58#define rFPGA0_RFWakeUpParameter 0x850
59#define rFPGA0_RFSleepUpParameter 0x854 59#define rFPGA0_RFSleepUpParameter 0x854
60#define rFPGA0_XAB_SwitchControl 0x858 60#define rFPGA0_XAB_SwitchControl 0x858
61#define rFPGA0_XCD_SwitchControl 0x85c 61#define rFPGA0_XCD_SwitchControl 0x85c
62#define rFPGA0_XA_RFInterfaceOE 0x860 62#define rFPGA0_XA_RFInterfaceOE 0x860
63#define rFPGA0_XB_RFInterfaceOE 0x864 63#define rFPGA0_XB_RFInterfaceOE 0x864
64#define rFPGA0_XC_RFInterfaceOE 0x868 64#define rFPGA0_XC_RFInterfaceOE 0x868
65#define rFPGA0_XD_RFInterfaceOE 0x86c 65#define rFPGA0_XD_RFInterfaceOE 0x86c
66#define rFPGA0_XAB_RFInterfaceSW 0x870 66#define rFPGA0_XAB_RFInterfaceSW 0x870
67#define rFPGA0_XCD_RFInterfaceSW 0x874 67#define rFPGA0_XCD_RFInterfaceSW 0x874
68#define rFPGA0_XAB_RFParameter 0x878 68#define rFPGA0_XAB_RFParameter 0x878
69#define rFPGA0_XCD_RFParameter 0x87c 69#define rFPGA0_XCD_RFParameter 0x87c
70#define rFPGA0_AnalogParameter1 0x880 70#define rFPGA0_AnalogParameter1 0x880
71#define rFPGA0_AnalogParameter2 0x884 71#define rFPGA0_AnalogParameter2 0x884
72#define rFPGA0_AnalogParameter3 0x888 72#define rFPGA0_AnalogParameter3 0x888
73#define rFPGA0_AnalogParameter4 0x88c 73#define rFPGA0_AnalogParameter4 0x88c
74#define rFPGA0_XA_LSSIReadBack 0x8a0 74#define rFPGA0_XA_LSSIReadBack 0x8a0
75#define rFPGA0_XB_LSSIReadBack 0x8a4 75#define rFPGA0_XB_LSSIReadBack 0x8a4
76#define rFPGA0_XC_LSSIReadBack 0x8a8 76#define rFPGA0_XC_LSSIReadBack 0x8a8
77#define rFPGA0_XD_LSSIReadBack 0x8ac 77#define rFPGA0_XD_LSSIReadBack 0x8ac
78#define rFPGA0_PSDReport 0x8b4 78#define rFPGA0_PSDReport 0x8b4
79#define rFPGA0_XAB_RFInterfaceRB 0x8e0 79#define rFPGA0_XAB_RFInterfaceRB 0x8e0
80#define rFPGA0_XCD_RFInterfaceRB 0x8e4 80#define rFPGA0_XCD_RFInterfaceRB 0x8e4
81 81
82//page 9 82//page 9
83#define rFPGA1_RFMOD 0x900 //RF mode & OFDM TxSC 83#define rFPGA1_RFMOD 0x900 //RF mode & OFDM TxSC
84#define rFPGA1_TxBlock 0x904 84#define rFPGA1_TxBlock 0x904
85#define rFPGA1_DebugSelect 0x908 85#define rFPGA1_DebugSelect 0x908
86#define rFPGA1_TxInfo 0x90c 86#define rFPGA1_TxInfo 0x90c
87 87
88//page a 88//page a
89#define rCCK0_System 0xa00 89#define rCCK0_System 0xa00
90#define rCCK0_AFESetting 0xa04 90#define rCCK0_AFESetting 0xa04
91#define rCCK0_CCA 0xa08 91#define rCCK0_CCA 0xa08
92#define rCCK0_RxAGC1 0xa0c //AGC default value, saturation level 92#define rCCK0_RxAGC1 0xa0c //AGC default value, saturation level
93#define rCCK0_RxAGC2 0xa10 //AGC & DAGC 93#define rCCK0_RxAGC2 0xa10 //AGC & DAGC
94#define rCCK0_RxHP 0xa14 94#define rCCK0_RxHP 0xa14
95#define rCCK0_DSPParameter1 0xa18 //Timing recovery & Channel estimation threshold 95#define rCCK0_DSPParameter1 0xa18 //Timing recovery & Channel estimation threshold
96#define rCCK0_DSPParameter2 0xa1c //SQ threshold 96#define rCCK0_DSPParameter2 0xa1c //SQ threshold
97#define rCCK0_TxFilter1 0xa20 97#define rCCK0_TxFilter1 0xa20
98#define rCCK0_TxFilter2 0xa24 98#define rCCK0_TxFilter2 0xa24
99#define rCCK0_DebugPort 0xa28 //debug port and Tx filter3 99#define rCCK0_DebugPort 0xa28 //debug port and Tx filter3
100#define rCCK0_FalseAlarmReport 0xa2c //0xa2d 100#define rCCK0_FalseAlarmReport 0xa2c //0xa2d
101#define rCCK0_TRSSIReport 0xa50 101#define rCCK0_TRSSIReport 0xa50
102#define rCCK0_RxReport 0xa54 //0xa57 102#define rCCK0_RxReport 0xa54 //0xa57
103#define rCCK0_FACounterLower 0xa5c //0xa5b 103#define rCCK0_FACounterLower 0xa5c //0xa5b
104#define rCCK0_FACounterUpper 0xa58 //0xa5c 104#define rCCK0_FACounterUpper 0xa58 //0xa5c
105 105
106//page c 106//page c
107#define rOFDM0_LSTF 0xc00 107#define rOFDM0_LSTF 0xc00
108#define rOFDM0_TRxPathEnable 0xc04 108#define rOFDM0_TRxPathEnable 0xc04
109#define rOFDM0_TRMuxPar 0xc08 109#define rOFDM0_TRMuxPar 0xc08
110#define rOFDM0_TRSWIsolation 0xc0c 110#define rOFDM0_TRSWIsolation 0xc0c
111#define rOFDM0_XARxAFE 0xc10 //RxIQ DC offset, Rx digital filter, DC notch filter 111#define rOFDM0_XARxAFE 0xc10 //RxIQ DC offset, Rx digital filter, DC notch filter
112#define rOFDM0_XARxIQImbalance 0xc14 //RxIQ imblance matrix 112#define rOFDM0_XARxIQImbalance 0xc14 //RxIQ imblance matrix
113#define rOFDM0_XBRxAFE 0xc18 113#define rOFDM0_XBRxAFE 0xc18
114#define rOFDM0_XBRxIQImbalance 0xc1c 114#define rOFDM0_XBRxIQImbalance 0xc1c
115#define rOFDM0_XCRxAFE 0xc20 115#define rOFDM0_XCRxAFE 0xc20
116#define rOFDM0_XCRxIQImbalance 0xc24 116#define rOFDM0_XCRxIQImbalance 0xc24
117#define rOFDM0_XDRxAFE 0xc28 117#define rOFDM0_XDRxAFE 0xc28
118#define rOFDM0_XDRxIQImbalance 0xc2c 118#define rOFDM0_XDRxIQImbalance 0xc2c
119#define rOFDM0_RxDetector1 0xc30 //PD,BW & SBD 119#define rOFDM0_RxDetector1 0xc30 //PD,BW & SBD
120#define rOFDM0_RxDetector2 0xc34 //SBD & Fame Sync. 120#define rOFDM0_RxDetector2 0xc34 //SBD & Fame Sync.
121#define rOFDM0_RxDetector3 0xc38 //Frame Sync. 121#define rOFDM0_RxDetector3 0xc38 //Frame Sync.
122#define rOFDM0_RxDetector4 0xc3c //PD, SBD, Frame Sync & Short-GI 122#define rOFDM0_RxDetector4 0xc3c //PD, SBD, Frame Sync & Short-GI
123#define rOFDM0_RxDSP 0xc40 //Rx Sync Path 123#define rOFDM0_RxDSP 0xc40 //Rx Sync Path
124#define rOFDM0_CFOandDAGC 0xc44 //CFO & DAGC 124#define rOFDM0_CFOandDAGC 0xc44 //CFO & DAGC
125#define rOFDM0_CCADropThreshold 0xc48 //CCA Drop threshold 125#define rOFDM0_CCADropThreshold 0xc48 //CCA Drop threshold
126#define rOFDM0_ECCAThreshold 0xc4c // energy CCA 126#define rOFDM0_ECCAThreshold 0xc4c // energy CCA
127#define rOFDM0_XAAGCCore1 0xc50 127#define rOFDM0_XAAGCCore1 0xc50
128#define rOFDM0_XAAGCCore2 0xc54 128#define rOFDM0_XAAGCCore2 0xc54
129#define rOFDM0_XBAGCCore1 0xc58 129#define rOFDM0_XBAGCCore1 0xc58
130#define rOFDM0_XBAGCCore2 0xc5c 130#define rOFDM0_XBAGCCore2 0xc5c
131#define rOFDM0_XCAGCCore1 0xc60 131#define rOFDM0_XCAGCCore1 0xc60
132#define rOFDM0_XCAGCCore2 0xc64 132#define rOFDM0_XCAGCCore2 0xc64
133#define rOFDM0_XDAGCCore1 0xc68 133#define rOFDM0_XDAGCCore1 0xc68
134#define rOFDM0_XDAGCCore2 0xc6c 134#define rOFDM0_XDAGCCore2 0xc6c
135#define rOFDM0_AGCParameter1 0xc70 135#define rOFDM0_AGCParameter1 0xc70
136#define rOFDM0_AGCParameter2 0xc74 136#define rOFDM0_AGCParameter2 0xc74
137#define rOFDM0_AGCRSSITable 0xc78 137#define rOFDM0_AGCRSSITable 0xc78
138#define rOFDM0_HTSTFAGC 0xc7c 138#define rOFDM0_HTSTFAGC 0xc7c
139#define rOFDM0_XATxIQImbalance 0xc80 139#define rOFDM0_XATxIQImbalance 0xc80
140#define rOFDM0_XATxAFE 0xc84 140#define rOFDM0_XATxAFE 0xc84
141#define rOFDM0_XBTxIQImbalance 0xc88 141#define rOFDM0_XBTxIQImbalance 0xc88
142#define rOFDM0_XBTxAFE 0xc8c 142#define rOFDM0_XBTxAFE 0xc8c
143#define rOFDM0_XCTxIQImbalance 0xc90 143#define rOFDM0_XCTxIQImbalance 0xc90
144#define rOFDM0_XCTxAFE 0xc94 144#define rOFDM0_XCTxAFE 0xc94
145#define rOFDM0_XDTxIQImbalance 0xc98 145#define rOFDM0_XDTxIQImbalance 0xc98
146#define rOFDM0_XDTxAFE 0xc9c 146#define rOFDM0_XDTxAFE 0xc9c
147#define rOFDM0_RxHPParameter 0xce0 147#define rOFDM0_RxHPParameter 0xce0
148#define rOFDM0_TxPseudoNoiseWgt 0xce4 148#define rOFDM0_TxPseudoNoiseWgt 0xce4
149#define rOFDM0_FrameSync 0xcf0 149#define rOFDM0_FrameSync 0xcf0
150#define rOFDM0_DFSReport 0xcf4 150#define rOFDM0_DFSReport 0xcf4
151#define rOFDM0_TxCoeff1 0xca4 151#define rOFDM0_TxCoeff1 0xca4
152#define rOFDM0_TxCoeff2 0xca8 152#define rOFDM0_TxCoeff2 0xca8
153#define rOFDM0_TxCoeff3 0xcac 153#define rOFDM0_TxCoeff3 0xcac
154#define rOFDM0_TxCoeff4 0xcb0 154#define rOFDM0_TxCoeff4 0xcb0
155#define rOFDM0_TxCoeff5 0xcb4 155#define rOFDM0_TxCoeff5 0xcb4
156#define rOFDM0_TxCoeff6 0xcb8 156#define rOFDM0_TxCoeff6 0xcb8
157 157
158 158
159//page d 159//page d
160#define rOFDM1_LSTF 0xd00 160#define rOFDM1_LSTF 0xd00
161#define rOFDM1_TRxPathEnable 0xd04 161#define rOFDM1_TRxPathEnable 0xd04
162#define rOFDM1_CFO 0xd08 162#define rOFDM1_CFO 0xd08
163#define rOFDM1_CSI1 0xd10 163#define rOFDM1_CSI1 0xd10
164#define rOFDM1_SBD 0xd14 164#define rOFDM1_SBD 0xd14
165#define rOFDM1_CSI2 0xd18 165#define rOFDM1_CSI2 0xd18
166#define rOFDM1_CFOTracking 0xd2c 166#define rOFDM1_CFOTracking 0xd2c
167#define rOFDM1_TRxMesaure1 0xd34 167#define rOFDM1_TRxMesaure1 0xd34
168#define rOFDM1_IntfDet 0xd3c 168#define rOFDM1_IntfDet 0xd3c
169#define rOFDM1_PseudoNoiseStateAB 0xd50 169#define rOFDM1_PseudoNoiseStateAB 0xd50
170#define rOFDM1_PseudoNoiseStateCD 0xd54 170#define rOFDM1_PseudoNoiseStateCD 0xd54
171#define rOFDM1_RxPseudoNoiseWgt 0xd58 171#define rOFDM1_RxPseudoNoiseWgt 0xd58
172#define rOFDM_PHYCounter1 0xda0 //cca, parity fail 172#define rOFDM_PHYCounter1 0xda0 //cca, parity fail
173#define rOFDM_PHYCounter2 0xda4 //rate illegal, crc8 fail 173#define rOFDM_PHYCounter2 0xda4 //rate illegal, crc8 fail
174#define rOFDM_PHYCounter3 0xda8 //MCS not support 174#define rOFDM_PHYCounter3 0xda8 //MCS not support
175#define rOFDM_ShortCFOAB 0xdac 175#define rOFDM_ShortCFOAB 0xdac
176#define rOFDM_ShortCFOCD 0xdb0 176#define rOFDM_ShortCFOCD 0xdb0
177#define rOFDM_LongCFOAB 0xdb4 177#define rOFDM_LongCFOAB 0xdb4
178#define rOFDM_LongCFOCD 0xdb8 178#define rOFDM_LongCFOCD 0xdb8
179#define rOFDM_TailCFOAB 0xdbc 179#define rOFDM_TailCFOAB 0xdbc
180#define rOFDM_TailCFOCD 0xdc0 180#define rOFDM_TailCFOCD 0xdc0
181#define rOFDM_PWMeasure1 0xdc4 181#define rOFDM_PWMeasure1 0xdc4
182#define rOFDM_PWMeasure2 0xdc8 182#define rOFDM_PWMeasure2 0xdc8
183#define rOFDM_BWReport 0xdcc 183#define rOFDM_BWReport 0xdcc
184#define rOFDM_AGCReport 0xdd0 184#define rOFDM_AGCReport 0xdd0
185#define rOFDM_RxSNR 0xdd4 185#define rOFDM_RxSNR 0xdd4
186#define rOFDM_RxEVMCSI 0xdd8 186#define rOFDM_RxEVMCSI 0xdd8
187#define rOFDM_SIGReport 0xddc 187#define rOFDM_SIGReport 0xddc
188 188
189//page e 189//page e
190#define rTxAGC_Rate18_06 0xe00 190#define rTxAGC_Rate18_06 0xe00
@@ -198,373 +198,373 @@
198 198
199//RF 199//RF
200//Zebra1 200//Zebra1
201#define rZebra1_HSSIEnable 0x0 201#define rZebra1_HSSIEnable 0x0
202#define rZebra1_TRxEnable1 0x1 202#define rZebra1_TRxEnable1 0x1
203#define rZebra1_TRxEnable2 0x2 203#define rZebra1_TRxEnable2 0x2
204#define rZebra1_AGC 0x4 204#define rZebra1_AGC 0x4
205#define rZebra1_ChargePump 0x5 205#define rZebra1_ChargePump 0x5
206#define rZebra1_Channel 0x7 206#define rZebra1_Channel 0x7
207#define rZebra1_TxGain 0x8 207#define rZebra1_TxGain 0x8
208#define rZebra1_TxLPF 0x9 208#define rZebra1_TxLPF 0x9
209#define rZebra1_RxLPF 0xb 209#define rZebra1_RxLPF 0xb
210#define rZebra1_RxHPFCorner 0xc 210#define rZebra1_RxHPFCorner 0xc
211 211
212//Zebra4 212//Zebra4
213#define rGlobalCtrl 0 213#define rGlobalCtrl 0
214#define rRTL8256_TxLPF 19 214#define rRTL8256_TxLPF 19
215#define rRTL8256_RxLPF 11 215#define rRTL8256_RxLPF 11
216 216
217//RTL8258 217//RTL8258
218#define rRTL8258_TxLPF 0x11 218#define rRTL8258_TxLPF 0x11
219#define rRTL8258_RxLPF 0x13 219#define rRTL8258_RxLPF 0x13
220#define rRTL8258_RSSILPF 0xa 220#define rRTL8258_RSSILPF 0xa
221 221
222//Bit Mask 222//Bit Mask
223//page-1 223//page-1
224#define bBBResetB 0x100 224#define bBBResetB 0x100
225#define bGlobalResetB 0x200 225#define bGlobalResetB 0x200
226#define bOFDMTxStart 0x4 226#define bOFDMTxStart 0x4
227#define bCCKTxStart 0x8 227#define bCCKTxStart 0x8
228#define bCRC32Debug 0x100 228#define bCRC32Debug 0x100
229#define bPMACLoopback 0x10 229#define bPMACLoopback 0x10
230#define bTxLSIG 0xffffff 230#define bTxLSIG 0xffffff
231#define bOFDMTxRate 0xf 231#define bOFDMTxRate 0xf
232#define bOFDMTxReserved 0x10 232#define bOFDMTxReserved 0x10
233#define bOFDMTxLength 0x1ffe0 233#define bOFDMTxLength 0x1ffe0
234#define bOFDMTxParity 0x20000 234#define bOFDMTxParity 0x20000
235#define bTxHTSIG1 0xffffff 235#define bTxHTSIG1 0xffffff
236#define bTxHTMCSRate 0x7f 236#define bTxHTMCSRate 0x7f
237#define bTxHTBW 0x80 237#define bTxHTBW 0x80
238#define bTxHTLength 0xffff00 238#define bTxHTLength 0xffff00
239#define bTxHTSIG2 0xffffff 239#define bTxHTSIG2 0xffffff
240#define bTxHTSmoothing 0x1 240#define bTxHTSmoothing 0x1
241#define bTxHTSounding 0x2 241#define bTxHTSounding 0x2
242#define bTxHTReserved 0x4 242#define bTxHTReserved 0x4
243#define bTxHTAggreation 0x8 243#define bTxHTAggreation 0x8
244#define bTxHTSTBC 0x30 244#define bTxHTSTBC 0x30
245#define bTxHTAdvanceCoding 0x40 245#define bTxHTAdvanceCoding 0x40
246#define bTxHTShortGI 0x80 246#define bTxHTShortGI 0x80
247#define bTxHTNumberHT_LTF 0x300 247#define bTxHTNumberHT_LTF 0x300
248#define bTxHTCRC8 0x3fc00 248#define bTxHTCRC8 0x3fc00
249#define bCounterReset 0x10000 249#define bCounterReset 0x10000
250#define bNumOfOFDMTx 0xffff 250#define bNumOfOFDMTx 0xffff
251#define bNumOfCCKTx 0xffff0000 251#define bNumOfCCKTx 0xffff0000
252#define bTxIdleInterval 0xffff 252#define bTxIdleInterval 0xffff
253#define bOFDMService 0xffff0000 253#define bOFDMService 0xffff0000
254#define bTxMACHeader 0xffffffff 254#define bTxMACHeader 0xffffffff
255#define bTxDataInit 0xff 255#define bTxDataInit 0xff
256#define bTxHTMode 0x100 256#define bTxHTMode 0x100
257#define bTxDataType 0x30000 257#define bTxDataType 0x30000
258#define bTxRandomSeed 0xffffffff 258#define bTxRandomSeed 0xffffffff
259#define bCCKTxPreamble 0x1 259#define bCCKTxPreamble 0x1
260#define bCCKTxSFD 0xffff0000 260#define bCCKTxSFD 0xffff0000
261#define bCCKTxSIG 0xff 261#define bCCKTxSIG 0xff
262#define bCCKTxService 0xff00 262#define bCCKTxService 0xff00
263#define bCCKLengthExt 0x8000 263#define bCCKLengthExt 0x8000
264#define bCCKTxLength 0xffff0000 264#define bCCKTxLength 0xffff0000
265#define bCCKTxCRC16 0xffff 265#define bCCKTxCRC16 0xffff
266#define bCCKTxStatus 0x1 266#define bCCKTxStatus 0x1
267#define bOFDMTxStatus 0x2 267#define bOFDMTxStatus 0x2
268 268
269//page-8 269//page-8
270#define bRFMOD 0x1 270#define bRFMOD 0x1
271#define bJapanMode 0x2 271#define bJapanMode 0x2
272#define bCCKTxSC 0x30 272#define bCCKTxSC 0x30
273#define bCCKEn 0x1000000 273#define bCCKEn 0x1000000
274#define bOFDMEn 0x2000000 274#define bOFDMEn 0x2000000
275#define bOFDMRxADCPhase 0x10000 275#define bOFDMRxADCPhase 0x10000
276#define bOFDMTxDACPhase 0x40000 276#define bOFDMTxDACPhase 0x40000
277#define bXATxAGC 0x3f 277#define bXATxAGC 0x3f
278#define bXBTxAGC 0xf00 278#define bXBTxAGC 0xf00
279#define bXCTxAGC 0xf000 279#define bXCTxAGC 0xf000
280#define bXDTxAGC 0xf0000 280#define bXDTxAGC 0xf0000
281#define bPAStart 0xf0000000 281#define bPAStart 0xf0000000
282#define bTRStart 0x00f00000 282#define bTRStart 0x00f00000
283#define bRFStart 0x0000f000 283#define bRFStart 0x0000f000
284#define bBBStart 0x000000f0 284#define bBBStart 0x000000f0
285#define bBBCCKStart 0x0000000f 285#define bBBCCKStart 0x0000000f
286#define bPAEnd 0xf //Reg0x814 286#define bPAEnd 0xf //Reg0x814
287#define bTREnd 0x0f000000 287#define bTREnd 0x0f000000
288#define bRFEnd 0x000f0000 288#define bRFEnd 0x000f0000
289#define bCCAMask 0x000000f0 //T2R 289#define bCCAMask 0x000000f0 //T2R
290#define bR2RCCAMask 0x00000f00 290#define bR2RCCAMask 0x00000f00
291#define bHSSI_R2TDelay 0xf8000000 291#define bHSSI_R2TDelay 0xf8000000
292#define bHSSI_T2RDelay 0xf80000 292#define bHSSI_T2RDelay 0xf80000
293#define bContTxHSSI 0x400 //chane gain at continue Tx 293#define bContTxHSSI 0x400 //chane gain at continue Tx
294#define bIGFromCCK 0x200 294#define bIGFromCCK 0x200
295#define bAGCAddress 0x3f 295#define bAGCAddress 0x3f
296#define bRxHPTx 0x7000 296#define bRxHPTx 0x7000
297#define bRxHPT2R 0x38000 297#define bRxHPT2R 0x38000
298#define bRxHPCCKIni 0xc0000 298#define bRxHPCCKIni 0xc0000
299#define bAGCTxCode 0xc00000 299#define bAGCTxCode 0xc00000
300#define bAGCRxCode 0x300000 300#define bAGCRxCode 0x300000
301#define b3WireDataLength 0x800 301#define b3WireDataLength 0x800
302#define b3WireAddressLength 0x400 302#define b3WireAddressLength 0x400
303#define b3WireRFPowerDown 0x1 303#define b3WireRFPowerDown 0x1
304//#define bHWSISelect 0x8 304//#define bHWSISelect 0x8
305#define b5GPAPEPolarity 0x40000000 305#define b5GPAPEPolarity 0x40000000
306#define b2GPAPEPolarity 0x80000000 306#define b2GPAPEPolarity 0x80000000
307#define bRFSW_TxDefaultAnt 0x3 307#define bRFSW_TxDefaultAnt 0x3
308#define bRFSW_TxOptionAnt 0x30 308#define bRFSW_TxOptionAnt 0x30
309#define bRFSW_RxDefaultAnt 0x300 309#define bRFSW_RxDefaultAnt 0x300
310#define bRFSW_RxOptionAnt 0x3000 310#define bRFSW_RxOptionAnt 0x3000
311#define bRFSI_3WireData 0x1 311#define bRFSI_3WireData 0x1
312#define bRFSI_3WireClock 0x2 312#define bRFSI_3WireClock 0x2
313#define bRFSI_3WireLoad 0x4 313#define bRFSI_3WireLoad 0x4
314#define bRFSI_3WireRW 0x8 314#define bRFSI_3WireRW 0x8
315#define bRFSI_3Wire 0xf //3-wire total control 315#define bRFSI_3Wire 0xf //3-wire total control
316#define bRFSI_RFENV 0x10 316#define bRFSI_RFENV 0x10
317#define bRFSI_TRSW 0x20 317#define bRFSI_TRSW 0x20
318#define bRFSI_TRSWB 0x40 318#define bRFSI_TRSWB 0x40
319#define bRFSI_ANTSW 0x100 319#define bRFSI_ANTSW 0x100
320#define bRFSI_ANTSWB 0x200 320#define bRFSI_ANTSWB 0x200
321#define bRFSI_PAPE 0x400 321#define bRFSI_PAPE 0x400
322#define bRFSI_PAPE5G 0x800 322#define bRFSI_PAPE5G 0x800
323#define bBandSelect 0x1 323#define bBandSelect 0x1
324#define bHTSIG2_GI 0x80 324#define bHTSIG2_GI 0x80
325#define bHTSIG2_Smoothing 0x01 325#define bHTSIG2_Smoothing 0x01
326#define bHTSIG2_Sounding 0x02 326#define bHTSIG2_Sounding 0x02
327#define bHTSIG2_Aggreaton 0x08 327#define bHTSIG2_Aggreaton 0x08
328#define bHTSIG2_STBC 0x30 328#define bHTSIG2_STBC 0x30
329#define bHTSIG2_AdvCoding 0x40 329#define bHTSIG2_AdvCoding 0x40
330#define bHTSIG2_NumOfHTLTF 0x300 330#define bHTSIG2_NumOfHTLTF 0x300
331#define bHTSIG2_CRC8 0x3fc 331#define bHTSIG2_CRC8 0x3fc
332#define bHTSIG1_MCS 0x7f 332#define bHTSIG1_MCS 0x7f
333#define bHTSIG1_BandWidth 0x80 333#define bHTSIG1_BandWidth 0x80
334#define bHTSIG1_HTLength 0xffff 334#define bHTSIG1_HTLength 0xffff
335#define bLSIG_Rate 0xf 335#define bLSIG_Rate 0xf
336#define bLSIG_Reserved 0x10 336#define bLSIG_Reserved 0x10
337#define bLSIG_Length 0x1fffe 337#define bLSIG_Length 0x1fffe
338#define bLSIG_Parity 0x20 338#define bLSIG_Parity 0x20
339#define bCCKRxPhase 0x4 339#define bCCKRxPhase 0x4
340#define bLSSIReadAddress 0x3f000000 //LSSI "Read" Address 340#define bLSSIReadAddress 0x3f000000 //LSSI "Read" Address
341#define bLSSIReadEdge 0x80000000 //LSSI "Read" edge signal 341#define bLSSIReadEdge 0x80000000 //LSSI "Read" edge signal
342#define bLSSIReadBackData 0xfff 342#define bLSSIReadBackData 0xfff
343#define bLSSIReadOKFlag 0x1000 343#define bLSSIReadOKFlag 0x1000
344#define bCCKSampleRate 0x8 //0: 44MHz, 1:88MHz 344#define bCCKSampleRate 0x8 //0: 44MHz, 1:88MHz
345 345
346#define bRegulator0Standby 0x1 346#define bRegulator0Standby 0x1
347#define bRegulatorPLLStandby 0x2 347#define bRegulatorPLLStandby 0x2
348#define bRegulator1Standby 0x4 348#define bRegulator1Standby 0x4
349#define bPLLPowerUp 0x8 349#define bPLLPowerUp 0x8
350#define bDPLLPowerUp 0x10 350#define bDPLLPowerUp 0x10
351#define bDA10PowerUp 0x20 351#define bDA10PowerUp 0x20
352#define bAD7PowerUp 0x200 352#define bAD7PowerUp 0x200
353#define bDA6PowerUp 0x2000 353#define bDA6PowerUp 0x2000
354#define bXtalPowerUp 0x4000 354#define bXtalPowerUp 0x4000
355#define b40MDClkPowerUP 0x8000 355#define b40MDClkPowerUP 0x8000
356#define bDA6DebugMode 0x20000 356#define bDA6DebugMode 0x20000
357#define bDA6Swing 0x380000 357#define bDA6Swing 0x380000
358#define bADClkPhase 0x4000000 358#define bADClkPhase 0x4000000
359#define b80MClkDelay 0x18000000 359#define b80MClkDelay 0x18000000
360#define bAFEWatchDogEnable 0x20000000 360#define bAFEWatchDogEnable 0x20000000
361#define bXtalCap 0x0f000000 361#define bXtalCap 0x0f000000
362#define bIntDifClkEnable 0x400 362#define bIntDifClkEnable 0x400
363#define bExtSigClkEnable 0x800 363#define bExtSigClkEnable 0x800
364#define bBandgapMbiasPowerUp 0x10000 364#define bBandgapMbiasPowerUp 0x10000
365#define bAD11SHGain 0xc0000 365#define bAD11SHGain 0xc0000
366#define bAD11InputRange 0x700000 366#define bAD11InputRange 0x700000
367#define bAD11OPCurrent 0x3800000 367#define bAD11OPCurrent 0x3800000
368#define bIPathLoopback 0x4000000 368#define bIPathLoopback 0x4000000
369#define bQPathLoopback 0x8000000 369#define bQPathLoopback 0x8000000
370#define bAFELoopback 0x10000000 370#define bAFELoopback 0x10000000
371#define bDA10Swing 0x7e0 371#define bDA10Swing 0x7e0
372#define bDA10Reverse 0x800 372#define bDA10Reverse 0x800
373#define bDAClkSource 0x1000 373#define bDAClkSource 0x1000
374#define bAD7InputRange 0x6000 374#define bAD7InputRange 0x6000
375#define bAD7Gain 0x38000 375#define bAD7Gain 0x38000
376#define bAD7OutputCMMode 0x40000 376#define bAD7OutputCMMode 0x40000
377#define bAD7InputCMMode 0x380000 377#define bAD7InputCMMode 0x380000
378#define bAD7Current 0xc00000 378#define bAD7Current 0xc00000
379#define bRegulatorAdjust 0x7000000 379#define bRegulatorAdjust 0x7000000
380#define bAD11PowerUpAtTx 0x1 380#define bAD11PowerUpAtTx 0x1
381#define bDA10PSAtTx 0x10 381#define bDA10PSAtTx 0x10
382#define bAD11PowerUpAtRx 0x100 382#define bAD11PowerUpAtRx 0x100
383#define bDA10PSAtRx 0x1000 383#define bDA10PSAtRx 0x1000
384 384
385#define bCCKRxAGCFormat 0x200 385#define bCCKRxAGCFormat 0x200
386 386
387#define bPSDFFTSamplepPoint 0xc000 387#define bPSDFFTSamplepPoint 0xc000
388#define bPSDAverageNum 0x3000 388#define bPSDAverageNum 0x3000
389#define bIQPathControl 0xc00 389#define bIQPathControl 0xc00
390#define bPSDFreq 0x3ff 390#define bPSDFreq 0x3ff
391#define bPSDAntennaPath 0x30 391#define bPSDAntennaPath 0x30
392#define bPSDIQSwitch 0x40 392#define bPSDIQSwitch 0x40
393#define bPSDRxTrigger 0x400000 393#define bPSDRxTrigger 0x400000
394#define bPSDTxTrigger 0x80000000 394#define bPSDTxTrigger 0x80000000
395#define bPSDSineToneScale 0x7f000000 395#define bPSDSineToneScale 0x7f000000
396#define bPSDReport 0xffff 396#define bPSDReport 0xffff
397 397
398//page-9 398//page-9
399#define bOFDMTxSC 0x30000000 399#define bOFDMTxSC 0x30000000
400#define bCCKTxOn 0x1 400#define bCCKTxOn 0x1
401#define bOFDMTxOn 0x2 401#define bOFDMTxOn 0x2
402#define bDebugPage 0xfff //reset debug page and also HWord, LWord 402#define bDebugPage 0xfff //reset debug page and also HWord, LWord
403#define bDebugItem 0xff //reset debug page and LWord 403#define bDebugItem 0xff //reset debug page and LWord
404#define bAntL 0x10 404#define bAntL 0x10
405#define bAntNonHT 0x100 405#define bAntNonHT 0x100
406#define bAntHT1 0x1000 406#define bAntHT1 0x1000
407#define bAntHT2 0x10000 407#define bAntHT2 0x10000
408#define bAntHT1S1 0x100000 408#define bAntHT1S1 0x100000
409#define bAntNonHTS1 0x1000000 409#define bAntNonHTS1 0x1000000
410 410
411//page-a 411//page-a
412#define bCCKBBMode 0x3 412#define bCCKBBMode 0x3
413#define bCCKTxPowerSaving 0x80 413#define bCCKTxPowerSaving 0x80
414#define bCCKRxPowerSaving 0x40 414#define bCCKRxPowerSaving 0x40
415#define bCCKSideBand 0x10 415#define bCCKSideBand 0x10
416#define bCCKScramble 0x8 416#define bCCKScramble 0x8
417#define bCCKAntDiversity 0x8000 417#define bCCKAntDiversity 0x8000
418#define bCCKCarrierRecovery 0x4000 418#define bCCKCarrierRecovery 0x4000
419#define bCCKTxRate 0x3000 419#define bCCKTxRate 0x3000
420#define bCCKDCCancel 0x0800 420#define bCCKDCCancel 0x0800
421#define bCCKISICancel 0x0400 421#define bCCKISICancel 0x0400
422#define bCCKMatchFilter 0x0200 422#define bCCKMatchFilter 0x0200
423#define bCCKEqualizer 0x0100 423#define bCCKEqualizer 0x0100
424#define bCCKPreambleDetect 0x800000 424#define bCCKPreambleDetect 0x800000
425#define bCCKFastFalseCCA 0x400000 425#define bCCKFastFalseCCA 0x400000
426#define bCCKChEstStart 0x300000 426#define bCCKChEstStart 0x300000
427#define bCCKCCACount 0x080000 427#define bCCKCCACount 0x080000
428#define bCCKcs_lim 0x070000 428#define bCCKcs_lim 0x070000
429#define bCCKBistMode 0x80000000 429#define bCCKBistMode 0x80000000
430#define bCCKCCAMask 0x40000000 430#define bCCKCCAMask 0x40000000
431#define bCCKTxDACPhase 0x4 431#define bCCKTxDACPhase 0x4
432#define bCCKRxADCPhase 0x20000000 //r_rx_clk 432#define bCCKRxADCPhase 0x20000000 //r_rx_clk
433#define bCCKr_cp_mode0 0x0100 433#define bCCKr_cp_mode0 0x0100
434#define bCCKTxDCOffset 0xf0 434#define bCCKTxDCOffset 0xf0
435#define bCCKRxDCOffset 0xf 435#define bCCKRxDCOffset 0xf
436#define bCCKCCAMode 0xc000 436#define bCCKCCAMode 0xc000
437#define bCCKFalseCS_lim 0x3f00 437#define bCCKFalseCS_lim 0x3f00
438#define bCCKCS_ratio 0xc00000 438#define bCCKCS_ratio 0xc00000
439#define bCCKCorgBit_sel 0x300000 439#define bCCKCorgBit_sel 0x300000
440#define bCCKPD_lim 0x0f0000 440#define bCCKPD_lim 0x0f0000
441#define bCCKNewCCA 0x80000000 441#define bCCKNewCCA 0x80000000
442#define bCCKRxHPofIG 0x8000 442#define bCCKRxHPofIG 0x8000
443#define bCCKRxIG 0x7f00 443#define bCCKRxIG 0x7f00
444#define bCCKLNAPolarity 0x800000 444#define bCCKLNAPolarity 0x800000
445#define bCCKRx1stGain 0x7f0000 445#define bCCKRx1stGain 0x7f0000
446#define bCCKRFExtend 0x20000000 //CCK Rx initial gain polarity 446#define bCCKRFExtend 0x20000000 //CCK Rx initial gain polarity
447#define bCCKRxAGCSatLevel 0x1f000000 447#define bCCKRxAGCSatLevel 0x1f000000
448#define bCCKRxAGCSatCount 0xe0 448#define bCCKRxAGCSatCount 0xe0
449#define bCCKRxRFSettle 0x1f //AGCsamp_dly 449#define bCCKRxRFSettle 0x1f //AGCsamp_dly
450#define bCCKFixedRxAGC 0x8000 450#define bCCKFixedRxAGC 0x8000
451//#define bCCKRxAGCFormat 0x4000 //remove to HSSI register 0x824 451//#define bCCKRxAGCFormat 0x4000 //remove to HSSI register 0x824
452#define bCCKAntennaPolarity 0x2000 452#define bCCKAntennaPolarity 0x2000
453#define bCCKTxFilterType 0x0c00 453#define bCCKTxFilterType 0x0c00
454#define bCCKRxAGCReportType 0x0300 454#define bCCKRxAGCReportType 0x0300
455#define bCCKRxDAGCEn 0x80000000 455#define bCCKRxDAGCEn 0x80000000
456#define bCCKRxDAGCPeriod 0x20000000 456#define bCCKRxDAGCPeriod 0x20000000
457#define bCCKRxDAGCSatLevel 0x1f000000 457#define bCCKRxDAGCSatLevel 0x1f000000
458#define bCCKTimingRecovery 0x800000 458#define bCCKTimingRecovery 0x800000
459#define bCCKTxC0 0x3f0000 459#define bCCKTxC0 0x3f0000
460#define bCCKTxC1 0x3f000000 460#define bCCKTxC1 0x3f000000
461#define bCCKTxC2 0x3f 461#define bCCKTxC2 0x3f
462#define bCCKTxC3 0x3f00 462#define bCCKTxC3 0x3f00
463#define bCCKTxC4 0x3f0000 463#define bCCKTxC4 0x3f0000
464#define bCCKTxC5 0x3f000000 464#define bCCKTxC5 0x3f000000
465#define bCCKTxC6 0x3f 465#define bCCKTxC6 0x3f
466#define bCCKTxC7 0x3f00 466#define bCCKTxC7 0x3f00
467#define bCCKDebugPort 0xff0000 467#define bCCKDebugPort 0xff0000
468#define bCCKDACDebug 0x0f000000 468#define bCCKDACDebug 0x0f000000
469#define bCCKFalseAlarmEnable 0x8000 469#define bCCKFalseAlarmEnable 0x8000
470#define bCCKFalseAlarmRead 0x4000 470#define bCCKFalseAlarmRead 0x4000
471#define bCCKTRSSI 0x7f 471#define bCCKTRSSI 0x7f
472#define bCCKRxAGCReport 0xfe 472#define bCCKRxAGCReport 0xfe
473#define bCCKRxReport_AntSel 0x80000000 473#define bCCKRxReport_AntSel 0x80000000
474#define bCCKRxReport_MFOff 0x40000000 474#define bCCKRxReport_MFOff 0x40000000
475#define bCCKRxRxReport_SQLoss 0x20000000 475#define bCCKRxRxReport_SQLoss 0x20000000
476#define bCCKRxReport_Pktloss 0x10000000 476#define bCCKRxReport_Pktloss 0x10000000
477#define bCCKRxReport_Lockedbit 0x08000000 477#define bCCKRxReport_Lockedbit 0x08000000
478#define bCCKRxReport_RateError 0x04000000 478#define bCCKRxReport_RateError 0x04000000
479#define bCCKRxReport_RxRate 0x03000000 479#define bCCKRxReport_RxRate 0x03000000
480#define bCCKRxFACounterLower 0xff 480#define bCCKRxFACounterLower 0xff
481#define bCCKRxFACounterUpper 0xff000000 481#define bCCKRxFACounterUpper 0xff000000
482#define bCCKRxHPAGCStart 0xe000 482#define bCCKRxHPAGCStart 0xe000
483#define bCCKRxHPAGCFinal 0x1c00 483#define bCCKRxHPAGCFinal 0x1c00
484 484
485#define bCCKRxFalseAlarmEnable 0x8000 485#define bCCKRxFalseAlarmEnable 0x8000
486#define bCCKFACounterFreeze 0x4000 486#define bCCKFACounterFreeze 0x4000
487 487
488#define bCCKTxPathSel 0x10000000 488#define bCCKTxPathSel 0x10000000
489#define bCCKDefaultRxPath 0xc000000 489#define bCCKDefaultRxPath 0xc000000
490#define bCCKOptionRxPath 0x3000000 490#define bCCKOptionRxPath 0x3000000
491 491
492//page c 492//page c
493#define bNumOfSTF 0x3 493#define bNumOfSTF 0x3
494#define bShift_L 0xc0 494#define bShift_L 0xc0
495#define bGI_TH 0xc 495#define bGI_TH 0xc
496#define bRxPathA 0x1 496#define bRxPathA 0x1
497#define bRxPathB 0x2 497#define bRxPathB 0x2
498#define bRxPathC 0x4 498#define bRxPathC 0x4
499#define bRxPathD 0x8 499#define bRxPathD 0x8
500#define bTxPathA 0x1 500#define bTxPathA 0x1
501#define bTxPathB 0x2 501#define bTxPathB 0x2
502#define bTxPathC 0x4 502#define bTxPathC 0x4
503#define bTxPathD 0x8 503#define bTxPathD 0x8
504#define bTRSSIFreq 0x200 504#define bTRSSIFreq 0x200
505#define bADCBackoff 0x3000 505#define bADCBackoff 0x3000
506#define bDFIRBackoff 0xc000 506#define bDFIRBackoff 0xc000
507#define bTRSSILatchPhase 0x10000 507#define bTRSSILatchPhase 0x10000
508#define bRxIDCOffset 0xff 508#define bRxIDCOffset 0xff
509#define bRxQDCOffset 0xff00 509#define bRxQDCOffset 0xff00
510#define bRxDFIRMode 0x1800000 510#define bRxDFIRMode 0x1800000
511#define bRxDCNFType 0xe000000 511#define bRxDCNFType 0xe000000
512#define bRXIQImb_A 0x3ff 512#define bRXIQImb_A 0x3ff
513#define bRXIQImb_B 0xfc00 513#define bRXIQImb_B 0xfc00
514#define bRXIQImb_C 0x3f0000 514#define bRXIQImb_C 0x3f0000
515#define bRXIQImb_D 0xffc00000 515#define bRXIQImb_D 0xffc00000
516#define bDC_dc_Notch 0x60000 516#define bDC_dc_Notch 0x60000
517#define bRxNBINotch 0x1f000000 517#define bRxNBINotch 0x1f000000
518#define bPD_TH 0xf 518#define bPD_TH 0xf
519#define bPD_TH_Opt2 0xc000 519#define bPD_TH_Opt2 0xc000
520#define bPWED_TH 0x700 520#define bPWED_TH 0x700
521#define bIfMF_Win_L 0x800 521#define bIfMF_Win_L 0x800
522#define bPD_Option 0x1000 522#define bPD_Option 0x1000
523#define bMF_Win_L 0xe000 523#define bMF_Win_L 0xe000
524#define bBW_Search_L 0x30000 524#define bBW_Search_L 0x30000
525#define bwin_enh_L 0xc0000 525#define bwin_enh_L 0xc0000
526#define bBW_TH 0x700000 526#define bBW_TH 0x700000
527#define bED_TH2 0x3800000 527#define bED_TH2 0x3800000
528#define bBW_option 0x4000000 528#define bBW_option 0x4000000
529#define bRatio_TH 0x18000000 529#define bRatio_TH 0x18000000
530#define bWindow_L 0xe0000000 530#define bWindow_L 0xe0000000
531#define bSBD_Option 0x1 531#define bSBD_Option 0x1
532#define bFrame_TH 0x1c 532#define bFrame_TH 0x1c
533#define bFS_Option 0x60 533#define bFS_Option 0x60
534#define bDC_Slope_check 0x80 534#define bDC_Slope_check 0x80
535#define bFGuard_Counter_DC_L 0xe00 535#define bFGuard_Counter_DC_L 0xe00
536#define bFrame_Weight_Short 0x7000 536#define bFrame_Weight_Short 0x7000
537#define bSub_Tune 0xe00000 537#define bSub_Tune 0xe00000
538#define bFrame_DC_Length 0xe000000 538#define bFrame_DC_Length 0xe000000
539#define bSBD_start_offset 0x30000000 539#define bSBD_start_offset 0x30000000
540#define bFrame_TH_2 0x7 540#define bFrame_TH_2 0x7
541#define bFrame_GI2_TH 0x38 541#define bFrame_GI2_TH 0x38
542#define bGI2_Sync_en 0x40 542#define bGI2_Sync_en 0x40
543#define bSarch_Short_Early 0x300 543#define bSarch_Short_Early 0x300
544#define bSarch_Short_Late 0xc00 544#define bSarch_Short_Late 0xc00
545#define bSarch_GI2_Late 0x70000 545#define bSarch_GI2_Late 0x70000
546#define bCFOAntSum 0x1 546#define bCFOAntSum 0x1
547#define bCFOAcc 0x2 547#define bCFOAcc 0x2
548#define bCFOStartOffset 0xc 548#define bCFOStartOffset 0xc
549#define bCFOLookBack 0x70 549#define bCFOLookBack 0x70
550#define bCFOSumWeight 0x80 550#define bCFOSumWeight 0x80
551#define bDAGCEnable 0x10000 551#define bDAGCEnable 0x10000
552#define bTXIQImb_A 0x3ff 552#define bTXIQImb_A 0x3ff
553#define bTXIQImb_B 0xfc00 553#define bTXIQImb_B 0xfc00
554#define bTXIQImb_C 0x3f0000 554#define bTXIQImb_C 0x3f0000
555#define bTXIQImb_D 0xffc00000 555#define bTXIQImb_D 0xffc00000
556#define bTxIDCOffset 0xff 556#define bTxIDCOffset 0xff
557#define bTxQDCOffset 0xff00 557#define bTxQDCOffset 0xff00
558#define bTxDFIRMode 0x10000 558#define bTxDFIRMode 0x10000
559#define bTxPesudoNoiseOn 0x4000000 559#define bTxPesudoNoiseOn 0x4000000
560#define bTxPesudoNoise_A 0xff 560#define bTxPesudoNoise_A 0xff
561#define bTxPesudoNoise_B 0xff00 561#define bTxPesudoNoise_B 0xff00
562#define bTxPesudoNoise_C 0xff0000 562#define bTxPesudoNoise_C 0xff0000
563#define bTxPesudoNoise_D 0xff000000 563#define bTxPesudoNoise_D 0xff000000
564#define bCCADropOption 0x20000 564#define bCCADropOption 0x20000
565#define bCCADropThres 0xfff00000 565#define bCCADropThres 0xfff00000
566#define bEDCCA_H 0xf 566#define bEDCCA_H 0xf
567#define bEDCCA_L 0xf0 567#define bEDCCA_L 0xf0
568#define bLambda_ED 0x300 568#define bLambda_ED 0x300
569#define bRxInitialGain 0x7f 569#define bRxInitialGain 0x7f
570#define bRxAntDivEn 0x80 570#define bRxAntDivEn 0x80
@@ -862,10 +862,10 @@
862#define PathD 0x3 862#define PathD 0x3
863 863
864#define rRTL8256RxMixerPole 0xb 864#define rRTL8256RxMixerPole 0xb
865#define bZebraRxMixerPole 0x6 865#define bZebraRxMixerPole 0x6
866#define rRTL8256TxBBOPBias 0x9 866#define rRTL8256TxBBOPBias 0x9
867#define bRTL8256TxBBOPBias 0x400 867#define bRTL8256TxBBOPBias 0x400
868#define rRTL8256TxBBBW 19 868#define rRTL8256TxBBBW 19
869#define bRTL8256TxBBBW 0x18 869#define bRTL8256TxBBBW 0x18
870 870
871#endif //__INC_HAL8190PCIPHYREG_H 871#endif //__INC_HAL8190PCIPHYREG_H
diff --git a/drivers/staging/rtl8712/ethernet.h b/drivers/staging/rtl8712/ethernet.h
index 90954203776d..fad173f4097e 100644
--- a/drivers/staging/rtl8712/ethernet.h
+++ b/drivers/staging/rtl8712/ethernet.h
@@ -26,15 +26,8 @@
26#ifndef __INC_ETHERNET_H 26#ifndef __INC_ETHERNET_H
27#define __INC_ETHERNET_H 27#define __INC_ETHERNET_H
28 28
29#define ETHERNET_ADDRESS_LENGTH 6 /*!< Ethernet Address Length*/
30#define ETHERNET_HEADER_SIZE 14 /*!< Ethernet Header Length*/ 29#define ETHERNET_HEADER_SIZE 14 /*!< Ethernet Header Length*/
31#define LLC_HEADER_SIZE 6 /*!< LLC Header Length*/ 30#define LLC_HEADER_SIZE 6 /*!< LLC Header Length*/
32#define TYPE_LENGTH_FIELD_SIZE 2 /*!< Type/Length Size*/
33#define MINIMUM_ETHERNET_PACKET_SIZE 60 /*!< Min Ethernet Packet Size*/
34#define MAXIMUM_ETHERNET_PACKET_SIZE 1514 /*!< Max Ethernet Packet Size*/
35
36/*!< Is Multicast Address? */
37#define RT_ETH_IS_MULTICAST(_pAddr) ((((u8 *)(_pAddr))[0]&0x01) != 0)
38 31
39#endif /* #ifndef __INC_ETHERNET_H */ 32#endif /* #ifndef __INC_ETHERNET_H */
40 33
diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c
index cb9d4cfe8fe4..d801c5af006a 100644
--- a/drivers/staging/rtl8712/hal_init.c
+++ b/drivers/staging/rtl8712/hal_init.c
@@ -49,7 +49,7 @@ static void rtl871x_load_fw_cb(const struct firmware *firmware, void *context)
49 if (!firmware) { 49 if (!firmware) {
50 struct usb_device *udev = padapter->dvobjpriv.pusbdev; 50 struct usb_device *udev = padapter->dvobjpriv.pusbdev;
51 struct usb_interface *pusb_intf = padapter->pusb_intf; 51 struct usb_interface *pusb_intf = padapter->pusb_intf;
52 printk(KERN_ERR "r8712u: Firmware request failed\n"); 52 dev_err(&udev->dev, "r8712u: Firmware request failed\n");
53 padapter->fw_found = false; 53 padapter->fw_found = false;
54 usb_put_dev(udev); 54 usb_put_dev(udev);
55 usb_set_intfdata(pusb_intf, NULL); 55 usb_set_intfdata(pusb_intf, NULL);
@@ -69,12 +69,11 @@ int rtl871x_load_fw(struct _adapter *padapter)
69 int rc; 69 int rc;
70 70
71 init_completion(&padapter->rtl8712_fw_ready); 71 init_completion(&padapter->rtl8712_fw_ready);
72 printk(KERN_INFO "r8712u: Loading firmware from \"%s\"\n", 72 dev_info(dev, "r8712u: Loading firmware from \"%s\"\n", firmware_file);
73 firmware_file);
74 rc = request_firmware_nowait(THIS_MODULE, 1, firmware_file, dev, 73 rc = request_firmware_nowait(THIS_MODULE, 1, firmware_file, dev,
75 GFP_KERNEL, padapter, rtl871x_load_fw_cb); 74 GFP_KERNEL, padapter, rtl871x_load_fw_cb);
76 if (rc) 75 if (rc)
77 printk(KERN_ERR "r8712u: Firmware request error %d\n", rc); 76 dev_err(dev, "r8712u: Firmware request error %d\n", rc);
78 return rc; 77 return rc;
79} 78}
80MODULE_FIRMWARE("rtlwifi/rtl8712u.bin"); 79MODULE_FIRMWARE("rtlwifi/rtl8712u.bin");
@@ -84,8 +83,8 @@ static u32 rtl871x_open_fw(struct _adapter *padapter, const u8 **ppmappedfw)
84 const struct firmware **praw = &padapter->fw; 83 const struct firmware **praw = &padapter->fw;
85 84
86 if (padapter->fw->size > 200000) { 85 if (padapter->fw->size > 200000) {
87 printk(KERN_ERR "r8172u: Badfw->size of %d\n", 86 dev_err(&padapter->pnetdev->dev, "r8172u: Badfw->size of %d\n",
88 (int)padapter->fw->size); 87 (int)padapter->fw->size);
89 return 0; 88 return 0;
90 } 89 }
91 *ppmappedfw = (u8 *)((*praw)->data); 90 *ppmappedfw = (u8 *)((*praw)->data);
@@ -334,11 +333,13 @@ uint rtl8712_hal_init(struct _adapter *padapter)
334 if (rtl8712_dl_fw(padapter) != _SUCCESS) 333 if (rtl8712_dl_fw(padapter) != _SUCCESS)
335 return _FAIL; 334 return _FAIL;
336 335
337 printk(KERN_INFO "r8712u: 1 RCR=0x%x\n", r8712_read32(padapter, RCR)); 336 netdev_info(padapter->pnetdev, "1 RCR=0x%x\n",
337 r8712_read32(padapter, RCR));
338 val32 = r8712_read32(padapter, RCR); 338 val32 = r8712_read32(padapter, RCR);
339 r8712_write32(padapter, RCR, (val32 | BIT(26))); /* Enable RX TCP 339 r8712_write32(padapter, RCR, (val32 | BIT(26))); /* Enable RX TCP
340 Checksum offload */ 340 Checksum offload */
341 printk(KERN_INFO "r8712u: 2 RCR=0x%x\n", r8712_read32(padapter, RCR)); 341 netdev_info(padapter->pnetdev, "2 RCR=0x%x\n",
342 r8712_read32(padapter, RCR));
342 val32 = r8712_read32(padapter, RCR); 343 val32 = r8712_read32(padapter, RCR);
343 r8712_write32(padapter, RCR, (val32|BIT(25))); /* Append PHY status */ 344 r8712_write32(padapter, RCR, (val32|BIT(25))); /* Append PHY status */
344 val32 = 0; 345 val32 = 0;
diff --git a/drivers/staging/rtl8712/ieee80211.h b/drivers/staging/rtl8712/ieee80211.h
index 21515c31b373..da4000e49da6 100644
--- a/drivers/staging/rtl8712/ieee80211.h
+++ b/drivers/staging/rtl8712/ieee80211.h
@@ -777,7 +777,7 @@ extern inline int ieee80211_get_hdrlen(u16 fc)
777struct registry_priv; 777struct registry_priv;
778 778
779u8 *r8712_set_ie(u8 *pbuf, sint index, uint len, u8 *source, uint *frlen); 779u8 *r8712_set_ie(u8 *pbuf, sint index, uint len, u8 *source, uint *frlen);
780u8 *r8712_get_ie(u8*pbuf, sint index, sint *len, sint limit); 780u8 *r8712_get_ie(u8 *pbuf, sint index, sint *len, sint limit);
781unsigned char *r8712_get_wpa_ie(unsigned char *pie, int *rsn_ie_len, int limit); 781unsigned char *r8712_get_wpa_ie(unsigned char *pie, int *rsn_ie_len, int limit);
782unsigned char *r8712_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, 782unsigned char *r8712_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len,
783 int limit); 783 int limit);
diff --git a/drivers/staging/rtl8712/mlme_linux.c b/drivers/staging/rtl8712/mlme_linux.c
index 7279854c86aa..f569a7081be5 100644
--- a/drivers/staging/rtl8712/mlme_linux.c
+++ b/drivers/staging/rtl8712/mlme_linux.c
@@ -106,8 +106,6 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
106 * disconnect with AP for 60 seconds. 106 * disconnect with AP for 60 seconds.
107 */ 107 */
108 108
109 memset(&backupPMKIDList[0], 0x00, sizeof(
110 struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
111 memcpy(&backupPMKIDList[0], &adapter->securitypriv. 109 memcpy(&backupPMKIDList[0], &adapter->securitypriv.
112 PMKIDList[0], sizeof(struct RT_PMKID_LIST) * 110 PMKIDList[0], sizeof(struct RT_PMKID_LIST) *
113 NUM_PMKID_CACHE); 111 NUM_PMKID_CACHE);
diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index e00f7918d261..b65bf5e177a8 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -224,8 +224,7 @@ struct net_device *r8712_init_netdev(void)
224 } 224 }
225 padapter = (struct _adapter *) netdev_priv(pnetdev); 225 padapter = (struct _adapter *) netdev_priv(pnetdev);
226 padapter->pnetdev = pnetdev; 226 padapter->pnetdev = pnetdev;
227 printk(KERN_INFO "r8712u: register rtl8712_netdev_ops to" 227 pr_info("r8712u: register rtl8712_netdev_ops to netdev_ops\n");
228 " netdev_ops\n");
229 pnetdev->netdev_ops = &rtl8712_netdev_ops; 228 pnetdev->netdev_ops = &rtl8712_netdev_ops;
230 pnetdev->watchdog_timeo = HZ; /* 1 second timeout */ 229 pnetdev->watchdog_timeo = HZ; /* 1 second timeout */
231 pnetdev->wireless_handlers = (struct iw_handler_def *) 230 pnetdev->wireless_handlers = (struct iw_handler_def *)
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index c76732cdb183..d59a74aa3048 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -115,11 +115,11 @@ void r8712_free_recv_priv(struct recv_priv *precvpriv)
115 kfree(precvpriv->pallocated_recv_buf); 115 kfree(precvpriv->pallocated_recv_buf);
116 skb_queue_purge(&precvpriv->rx_skb_queue); 116 skb_queue_purge(&precvpriv->rx_skb_queue);
117 if (skb_queue_len(&precvpriv->rx_skb_queue)) 117 if (skb_queue_len(&precvpriv->rx_skb_queue))
118 printk(KERN_WARNING "r8712u: rx_skb_queue not empty\n"); 118 netdev_warn(padapter->pnetdev, "r8712u: rx_skb_queue not empty\n");
119 skb_queue_purge(&precvpriv->free_recv_skb_queue); 119 skb_queue_purge(&precvpriv->free_recv_skb_queue);
120 if (skb_queue_len(&precvpriv->free_recv_skb_queue)) 120 if (skb_queue_len(&precvpriv->free_recv_skb_queue))
121 printk(KERN_WARNING "r8712u: free_recv_skb_queue not empty " 121 netdev_warn(padapter->pnetdev, "r8712u: free_recv_skb_queue not empty %d\n",
122 "%d\n", skb_queue_len(&precvpriv->free_recv_skb_queue)); 122 skb_queue_len(&precvpriv->free_recv_skb_queue));
123} 123}
124 124
125int r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf) 125int r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf)
@@ -364,9 +364,8 @@ static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe)
364 nSubframe_Length = (nSubframe_Length >> 8) + 364 nSubframe_Length = (nSubframe_Length >> 8) +
365 (nSubframe_Length << 8); 365 (nSubframe_Length << 8);
366 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) { 366 if (a_len < (ETHERNET_HEADER_SIZE + nSubframe_Length)) {
367 printk(KERN_WARNING "r8712u: nRemain_Length is %d and" 367 netdev_warn(padapter->pnetdev, "r8712u: nRemain_Length is %d and nSubframe_Length is: %d\n",
368 " nSubframe_Length is: %d\n", 368 a_len, nSubframe_Length);
369 a_len, nSubframe_Length);
370 goto exit; 369 goto exit;
371 } 370 }
372 /* move the data point to data content */ 371 /* move the data point to data content */
@@ -381,8 +380,7 @@ static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe)
381 memcpy(data_ptr, pdata, nSubframe_Length); 380 memcpy(data_ptr, pdata, nSubframe_Length);
382 subframes[nr_subframes++] = sub_skb; 381 subframes[nr_subframes++] = sub_skb;
383 if (nr_subframes >= MAX_SUBFRAME_COUNT) { 382 if (nr_subframes >= MAX_SUBFRAME_COUNT) {
384 printk(KERN_WARNING "r8712u: ParseSubframe(): Too" 383 netdev_warn(padapter->pnetdev, "r8712u: ParseSubframe(): Too many Subframes! Packets dropped!\n");
385 " many Subframes! Packets dropped!\n");
386 break; 384 break;
387 } 385 }
388 pdata += nSubframe_Length; 386 pdata += nSubframe_Length;
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index 31f31dbf7f31..f16307f5d827 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -525,7 +525,6 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
525 kfree(pcmd); 525 kfree(pcmd);
526 return _FAIL; 526 return _FAIL;
527 } 527 }
528 memset(psecnetwork, 0, t_len);
529 memcpy(psecnetwork, &pnetwork->network, t_len); 528 memcpy(psecnetwork, &pnetwork->network, t_len);
530 auth = &psecuritypriv->authenticator_ie[0]; 529 auth = &psecuritypriv->authenticator_ie[0];
531 psecuritypriv->authenticator_ie[0] = (unsigned char) 530 psecuritypriv->authenticator_ie[0] = (unsigned char)
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h
index 9d93189d8700..0ce79b1c4ee2 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -749,7 +749,7 @@ u8 r8712_setopmode_cmd(struct _adapter *padapter,
749u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset); 749u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset);
750u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan); 750u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan);
751u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset); 751u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset);
752u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 * pval); 752u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval);
753u8 r8712_setrfintfs_cmd(struct _adapter *padapter, u8 mode); 753u8 r8712_setrfintfs_cmd(struct _adapter *padapter, u8 mode);
754u8 r8712_setrfreg_cmd(struct _adapter *padapter, u8 offset, u32 val); 754u8 r8712_setrfreg_cmd(struct _adapter *padapter, u8 offset, u32 val);
755u8 r8712_setrttbl_cmd(struct _adapter *padapter, 755u8 r8712_setrttbl_cmd(struct _adapter *padapter,
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 3a6479064519..f034567122d9 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -188,8 +188,7 @@ static inline char *translate_scan(struct _adapter *padapter,
188 /* Add the ESSID */ 188 /* Add the ESSID */
189 iwe.cmd = SIOCGIWESSID; 189 iwe.cmd = SIOCGIWESSID;
190 iwe.u.data.flags = 1; 190 iwe.u.data.flags = 1;
191 iwe.u.data.length = (u16)min((u16)pnetwork->network.Ssid.SsidLength, 191 iwe.u.data.length = min_t(u32, pnetwork->network.Ssid.SsidLength, 32);
192 (u16)32);
193 start = iwe_stream_add_point(info, start, stop, &iwe, 192 start = iwe_stream_add_point(info, start, stop, &iwe,
194 pnetwork->network.Ssid.Ssid); 193 pnetwork->network.Ssid.Ssid);
195 /* parsing HT_CAP_IE */ 194 /* parsing HT_CAP_IE */
@@ -415,8 +414,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
415 } else 414 } else
416 return -EINVAL; 415 return -EINVAL;
417 if (strcmp(param->u.crypt.alg, "WEP") == 0) { 416 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
418 printk(KERN_INFO "r8712u: wpa_set_encryption, crypt.alg =" 417 netdev_info(dev, "r8712u: %s: crypt.alg = WEP\n", __func__);
419 " WEP\n");
420 padapter->securitypriv.ndisencryptstatus = 418 padapter->securitypriv.ndisencryptstatus =
421 Ndis802_11Encryption1Enabled; 419 Ndis802_11Encryption1Enabled;
422 padapter->securitypriv.PrivacyAlgrthm = _WEP40_; 420 padapter->securitypriv.PrivacyAlgrthm = _WEP40_;
@@ -608,8 +606,7 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
608 606
609 if ((eid == _VENDOR_SPECIFIC_IE_) && 607 if ((eid == _VENDOR_SPECIFIC_IE_) &&
610 (!memcmp(&buf[cnt+2], wps_oui, 4))) { 608 (!memcmp(&buf[cnt+2], wps_oui, 4))) {
611 printk(KERN_INFO "r8712u: " 609 netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE\n");
612 "SET WPS_IE\n");
613 padapter->securitypriv.wps_ie_len = 610 padapter->securitypriv.wps_ie_len =
614 ((buf[cnt+1] + 2) < 611 ((buf[cnt+1] + 2) <
615 (MAX_WPA_IE_LEN << 2)) ? 612 (MAX_WPA_IE_LEN << 2)) ?
@@ -620,8 +617,7 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
620 padapter->securitypriv.wps_ie_len); 617 padapter->securitypriv.wps_ie_len);
621 padapter->securitypriv.wps_phase = 618 padapter->securitypriv.wps_phase =
622 true; 619 true;
623 printk(KERN_INFO "r8712u: SET WPS_IE," 620 netdev_info(padapter->pnetdev, "r8712u: SET WPS_IE, wps_phase==true\n");
624 " wps_phase==true\n");
625 cnt += buf[cnt+1]+2; 621 cnt += buf[cnt+1]+2;
626 break; 622 break;
627 } else 623 } else
@@ -829,8 +825,8 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
829 strIssueBssid, ETH_ALEN)) { 825 strIssueBssid, ETH_ALEN)) {
830 /* BSSID is matched, the same AP => rewrite 826 /* BSSID is matched, the same AP => rewrite
831 * with new PMKID. */ 827 * with new PMKID. */
832 printk(KERN_INFO "r8712u: r871x_wx_set_pmkid:" 828 netdev_info(dev, "r8712u: %s: BSSID exists in the PMKList.\n",
833 " BSSID exists in the PMKList.\n"); 829 __func__);
834 memcpy(psecuritypriv->PMKIDList[j].PMKID, 830 memcpy(psecuritypriv->PMKIDList[j].PMKID,
835 pPMK->pmkid, IW_PMKID_LEN); 831 pPMK->pmkid, IW_PMKID_LEN);
836 psecuritypriv->PMKIDList[j].bUsed = true; 832 psecuritypriv->PMKIDList[j].bUsed = true;
@@ -841,9 +837,8 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
841 } 837 }
842 if (!blInserted) { 838 if (!blInserted) {
843 /* Find a new entry */ 839 /* Find a new entry */
844 printk(KERN_INFO "r8712u: r871x_wx_set_pmkid: Use the" 840 netdev_info(dev, "r8712u: %s: Use the new entry index = %d for this PMKID.\n",
845 " new entry index = %d for this PMKID.\n", 841 __func__, psecuritypriv->PMKIDIndex);
846 psecuritypriv->PMKIDIndex);
847 memcpy(psecuritypriv->PMKIDList[psecuritypriv-> 842 memcpy(psecuritypriv->PMKIDList[psecuritypriv->
848 PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN); 843 PMKIDIndex].Bssid, strIssueBssid, ETH_ALEN);
849 memcpy(psecuritypriv->PMKIDList[psecuritypriv-> 844 memcpy(psecuritypriv->PMKIDList[psecuritypriv->
@@ -876,8 +871,7 @@ static int r871x_wx_set_pmkid(struct net_device *dev,
876 intReturn = true; 871 intReturn = true;
877 break; 872 break;
878 default: 873 default:
879 printk(KERN_INFO "r8712u: r871x_wx_set_pmkid: " 874 netdev_info(dev, "r8712u: %s: unknown Command\n", __func__);
880 "unknown Command\n");
881 intReturn = false; 875 intReturn = false;
882 break; 876 break;
883 } 877 }
@@ -1045,8 +1039,8 @@ static int r871x_wx_set_priv(struct net_device *dev,
1045 ); 1039 );
1046 sprintf(ext, "OK"); 1040 sprintf(ext, "OK");
1047 } else { 1041 } else {
1048 printk(KERN_INFO "r8712u: r871x_wx_set_priv: unknown Command" 1042 netdev_info(dev, "r8712u: %s: unknown Command %s.\n",
1049 " %s.\n", ext); 1043 __func__, ext);
1050 goto FREE_EXT; 1044 goto FREE_EXT;
1051 } 1045 }
1052 if (copy_to_user(dwrq->pointer, ext, 1046 if (copy_to_user(dwrq->pointer, ext,
@@ -1131,11 +1125,11 @@ static int r8711_wx_get_wap(struct net_device *dev,
1131 struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network; 1125 struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
1132 1126
1133 wrqu->ap_addr.sa_family = ARPHRD_ETHER; 1127 wrqu->ap_addr.sa_family = ARPHRD_ETHER;
1134 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN); 1128 if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE |
1135 if (check_fwstate(pmlmepriv, _FW_LINKED | 1129 WIFI_AP_STATE))
1136 WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE)) {
1137 memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN); 1130 memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
1138 } 1131 else
1132 memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
1139 return 0; 1133 return 0;
1140} 1134}
1141 1135
@@ -1183,8 +1177,8 @@ static int r8711_wx_set_scan(struct net_device *dev,
1183 u8 status = true; 1177 u8 status = true;
1184 1178
1185 if (padapter->bDriverStopped == true) { 1179 if (padapter->bDriverStopped == true) {
1186 printk(KERN_WARNING "r8712u: in r8711_wx_set_scan: " 1180 netdev_info(dev, "In %s: bDriverStopped=%d\n",
1187 "bDriverStopped=%d\n", padapter->bDriverStopped); 1181 __func__, padapter->bDriverStopped);
1188 return -1; 1182 return -1;
1189 } 1183 }
1190 if (padapter->bup == false) 1184 if (padapter->bup == false)
@@ -1199,8 +1193,7 @@ static int r8711_wx_set_scan(struct net_device *dev,
1199 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { 1193 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1200 struct ndis_802_11_ssid ssid; 1194 struct ndis_802_11_ssid ssid;
1201 unsigned long irqL; 1195 unsigned long irqL;
1202 u32 len = (u32) min((u8)req->essid_len, 1196 u32 len = min_t(u8, req->essid_len, IW_ESSID_MAX_SIZE);
1203 (u8)IW_ESSID_MAX_SIZE);
1204 memset((unsigned char *)&ssid, 0, 1197 memset((unsigned char *)&ssid, 0,
1205 sizeof(struct ndis_802_11_ssid)); 1198 sizeof(struct ndis_802_11_ssid));
1206 memcpy(ssid.Ssid, req->essid, len); 1199 memcpy(ssid.Ssid, req->essid, len);
@@ -1556,8 +1549,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
1556 key = erq->flags & IW_ENCODE_INDEX; 1549 key = erq->flags & IW_ENCODE_INDEX;
1557 memset(&wep, 0, sizeof(struct NDIS_802_11_WEP)); 1550 memset(&wep, 0, sizeof(struct NDIS_802_11_WEP));
1558 if (erq->flags & IW_ENCODE_DISABLED) { 1551 if (erq->flags & IW_ENCODE_DISABLED) {
1559 printk(KERN_INFO "r8712u: r8711_wx_set_enc: " 1552 netdev_info(dev, "r8712u: %s: EncryptionDisabled\n", __func__);
1560 "EncryptionDisabled\n");
1561 padapter->securitypriv.ndisencryptstatus = 1553 padapter->securitypriv.ndisencryptstatus =
1562 Ndis802_11EncryptionDisabled; 1554 Ndis802_11EncryptionDisabled;
1563 padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_; 1555 padapter->securitypriv.PrivacyAlgrthm = _NO_PRIVACY_;
@@ -1578,8 +1570,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
1578 } 1570 }
1579 /* set authentication mode */ 1571 /* set authentication mode */
1580 if (erq->flags & IW_ENCODE_OPEN) { 1572 if (erq->flags & IW_ENCODE_OPEN) {
1581 printk(KERN_INFO "r8712u: r8711_wx_set_enc: " 1573 netdev_info(dev, "r8712u: %s: IW_ENCODE_OPEN\n", __func__);
1582 "IW_ENCODE_OPEN\n");
1583 padapter->securitypriv.ndisencryptstatus = 1574 padapter->securitypriv.ndisencryptstatus =
1584 Ndis802_11Encryption1Enabled; 1575 Ndis802_11Encryption1Enabled;
1585 padapter->securitypriv.AuthAlgrthm = 0; /* open system */ 1576 padapter->securitypriv.AuthAlgrthm = 0; /* open system */
@@ -1588,8 +1579,7 @@ static int r8711_wx_set_enc(struct net_device *dev,
1588 authmode = Ndis802_11AuthModeOpen; 1579 authmode = Ndis802_11AuthModeOpen;
1589 padapter->securitypriv.ndisauthtype = authmode; 1580 padapter->securitypriv.ndisauthtype = authmode;
1590 } else if (erq->flags & IW_ENCODE_RESTRICTED) { 1581 } else if (erq->flags & IW_ENCODE_RESTRICTED) {
1591 printk(KERN_INFO "r8712u: r8711_wx_set_enc: " 1582 netdev_info(dev, "r8712u: %s: IW_ENCODE_RESTRICTED\n", __func__);
1592 "IW_ENCODE_RESTRICTED\n");
1593 padapter->securitypriv.ndisencryptstatus = 1583 padapter->securitypriv.ndisencryptstatus =
1594 Ndis802_11Encryption1Enabled; 1584 Ndis802_11Encryption1Enabled;
1595 padapter->securitypriv.AuthAlgrthm = 1; /* shared system */ 1585 padapter->securitypriv.AuthAlgrthm = 1; /* shared system */
@@ -1977,9 +1967,9 @@ static int r871x_mp_ioctl_hdl(struct net_device *dev,
1977 status = phandler->handler(&oid_par); 1967 status = phandler->handler(&oid_par);
1978 /* todo:check status, BytesNeeded, etc. */ 1968 /* todo:check status, BytesNeeded, etc. */
1979 } else { 1969 } else {
1980 printk(KERN_INFO "r8712u: r871x_mp_ioctl_hdl(): err!," 1970 netdev_info(dev, "r8712u: %s: err!, subcode=%d, oid=%d, handler=%p\n",
1981 " subcode=%d, oid=%d, handler=%p\n", 1971 __func__, poidparam->subcode, phandler->oid,
1982 poidparam->subcode, phandler->oid, phandler->handler); 1972 phandler->handler);
1983 ret = -EFAULT; 1973 ret = -EFAULT;
1984 goto _r871x_mp_ioctl_hdl_exit; 1974 goto _r871x_mp_ioctl_hdl_exit;
1985 } 1975 }
@@ -2034,13 +2024,13 @@ static int r871x_get_ap_info(struct net_device *dev,
2034 break; 2024 break;
2035 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list); 2025 pnetwork = LIST_CONTAINOR(plist, struct wlan_network, list);
2036 if (hwaddr_aton_i(data, bssid)) { 2026 if (hwaddr_aton_i(data, bssid)) {
2037 printk(KERN_INFO "r8712u: Invalid BSSID '%s'.\n", 2027 netdev_info(dev, "r8712u: Invalid BSSID '%s'.\n",
2038 (u8 *)data); 2028 (u8 *)data);
2039 spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock), 2029 spin_unlock_irqrestore(&(pmlmepriv->scanned_queue.lock),
2040 irqL); 2030 irqL);
2041 return -EINVAL; 2031 return -EINVAL;
2042 } 2032 }
2043 printk(KERN_INFO "r8712u: BSSID:%pM\n", bssid); 2033 netdev_info(dev, "r8712u: BSSID:%pM\n", bssid);
2044 if (!memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN)) { 2034 if (!memcmp(bssid, pnetwork->network.MacAddress, ETH_ALEN)) {
2045 /* BSSID match, then check if supporting wpa/wpa2 */ 2035 /* BSSID match, then check if supporting wpa/wpa2 */
2046 pbuf = r8712_get_wpa_ie(&pnetwork->network.IEs[12], 2036 pbuf = r8712_get_wpa_ie(&pnetwork->network.IEs[12],
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
index 9a33eaee879b..5d6d55e7b389 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c
@@ -28,6 +28,7 @@
28 28
29#define _RTL871X_IOCTL_RTL_C_ 29#define _RTL871X_IOCTL_RTL_C_
30 30
31#include <linux/rndis.h>
31#include "osdep_service.h" 32#include "osdep_service.h"
32#include "drv_types.h" 33#include "drv_types.h"
33#include "wlan_bssdef.h" 34#include "wlan_bssdef.h"
@@ -42,8 +43,8 @@
42uint oid_rt_get_signal_quality_hdl(struct oid_par_priv *poid_par_priv) 43uint oid_rt_get_signal_quality_hdl(struct oid_par_priv *poid_par_priv)
43{ 44{
44 if (poid_par_priv->type_of_oid != QUERY_OID) 45 if (poid_par_priv->type_of_oid != QUERY_OID)
45 return NDIS_STATUS_NOT_ACCEPTED; 46 return RNDIS_STATUS_NOT_ACCEPTED;
46 return NDIS_STATUS_SUCCESS; 47 return RNDIS_STATUS_SUCCESS;
47} 48}
48 49
49uint oid_rt_get_small_packet_crc_hdl(struct oid_par_priv *poid_par_priv) 50uint oid_rt_get_small_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
@@ -52,14 +53,14 @@ uint oid_rt_get_small_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
52 (poid_par_priv->adapter_context); 53 (poid_par_priv->adapter_context);
53 54
54 if (poid_par_priv->type_of_oid != QUERY_OID) 55 if (poid_par_priv->type_of_oid != QUERY_OID)
55 return NDIS_STATUS_NOT_ACCEPTED; 56 return RNDIS_STATUS_NOT_ACCEPTED;
56 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 57 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
57 *(u32 *)poid_par_priv->information_buf = 58 *(u32 *)poid_par_priv->information_buf =
58 padapter->recvpriv.rx_smallpacket_crcerr; 59 padapter->recvpriv.rx_smallpacket_crcerr;
59 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 60 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
60 } else 61 } else
61 return NDIS_STATUS_INVALID_LENGTH; 62 return RNDIS_STATUS_INVALID_LENGTH;
62 return NDIS_STATUS_SUCCESS; 63 return RNDIS_STATUS_SUCCESS;
63} 64}
64 65
65uint oid_rt_get_middle_packet_crc_hdl(struct oid_par_priv *poid_par_priv) 66uint oid_rt_get_middle_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
@@ -68,14 +69,14 @@ uint oid_rt_get_middle_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
68 (poid_par_priv->adapter_context); 69 (poid_par_priv->adapter_context);
69 70
70 if (poid_par_priv->type_of_oid != QUERY_OID) 71 if (poid_par_priv->type_of_oid != QUERY_OID)
71 return NDIS_STATUS_NOT_ACCEPTED; 72 return RNDIS_STATUS_NOT_ACCEPTED;
72 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 73 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
73 *(u32 *)poid_par_priv->information_buf = 74 *(u32 *)poid_par_priv->information_buf =
74 padapter->recvpriv.rx_middlepacket_crcerr; 75 padapter->recvpriv.rx_middlepacket_crcerr;
75 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 76 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
76 } else 77 } else
77 return NDIS_STATUS_INVALID_LENGTH; 78 return RNDIS_STATUS_INVALID_LENGTH;
78 return NDIS_STATUS_SUCCESS; 79 return RNDIS_STATUS_SUCCESS;
79} 80}
80 81
81uint oid_rt_get_large_packet_crc_hdl(struct oid_par_priv *poid_par_priv) 82uint oid_rt_get_large_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
@@ -84,29 +85,29 @@ uint oid_rt_get_large_packet_crc_hdl(struct oid_par_priv *poid_par_priv)
84 (poid_par_priv->adapter_context); 85 (poid_par_priv->adapter_context);
85 86
86 if (poid_par_priv->type_of_oid != QUERY_OID) 87 if (poid_par_priv->type_of_oid != QUERY_OID)
87 return NDIS_STATUS_NOT_ACCEPTED; 88 return RNDIS_STATUS_NOT_ACCEPTED;
88 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 89 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
89 *(u32 *)poid_par_priv->information_buf = 90 *(u32 *)poid_par_priv->information_buf =
90 padapter->recvpriv.rx_largepacket_crcerr; 91 padapter->recvpriv.rx_largepacket_crcerr;
91 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 92 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
92 } else 93 } else
93 return NDIS_STATUS_INVALID_LENGTH; 94 return RNDIS_STATUS_INVALID_LENGTH;
94 return NDIS_STATUS_SUCCESS; 95 return RNDIS_STATUS_SUCCESS;
95} 96}
96 97
97uint oid_rt_get_tx_retry_hdl(struct oid_par_priv *poid_par_priv) 98uint oid_rt_get_tx_retry_hdl(struct oid_par_priv *poid_par_priv)
98{ 99{
99 if (poid_par_priv->type_of_oid != QUERY_OID) 100 if (poid_par_priv->type_of_oid != QUERY_OID)
100 return NDIS_STATUS_NOT_ACCEPTED; 101 return RNDIS_STATUS_NOT_ACCEPTED;
101 return NDIS_STATUS_SUCCESS; 102 return RNDIS_STATUS_SUCCESS;
102} 103}
103 104
104uint oid_rt_get_rx_retry_hdl(struct oid_par_priv *poid_par_priv) 105uint oid_rt_get_rx_retry_hdl(struct oid_par_priv *poid_par_priv)
105{ 106{
106 if (poid_par_priv->type_of_oid != QUERY_OID) 107 if (poid_par_priv->type_of_oid != QUERY_OID)
107 return NDIS_STATUS_NOT_ACCEPTED; 108 return RNDIS_STATUS_NOT_ACCEPTED;
108 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 109 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
109 return NDIS_STATUS_SUCCESS; 110 return RNDIS_STATUS_SUCCESS;
110} 111}
111 112
112uint oid_rt_get_rx_total_packet_hdl(struct oid_par_priv *poid_par_priv) 113uint oid_rt_get_rx_total_packet_hdl(struct oid_par_priv *poid_par_priv)
@@ -115,29 +116,29 @@ uint oid_rt_get_rx_total_packet_hdl(struct oid_par_priv *poid_par_priv)
115 (poid_par_priv->adapter_context); 116 (poid_par_priv->adapter_context);
116 117
117 if (poid_par_priv->type_of_oid != QUERY_OID) 118 if (poid_par_priv->type_of_oid != QUERY_OID)
118 return NDIS_STATUS_NOT_ACCEPTED; 119 return RNDIS_STATUS_NOT_ACCEPTED;
119 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 120 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
120 *(u32 *)poid_par_priv->information_buf = 121 *(u32 *)poid_par_priv->information_buf =
121 padapter->recvpriv.rx_pkts + 122 padapter->recvpriv.rx_pkts +
122 padapter->recvpriv.rx_drop; 123 padapter->recvpriv.rx_drop;
123 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 124 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
124 } else 125 } else
125 return NDIS_STATUS_INVALID_LENGTH; 126 return RNDIS_STATUS_INVALID_LENGTH;
126 return NDIS_STATUS_SUCCESS; 127 return RNDIS_STATUS_SUCCESS;
127} 128}
128 129
129uint oid_rt_get_tx_beacon_ok_hdl(struct oid_par_priv *poid_par_priv) 130uint oid_rt_get_tx_beacon_ok_hdl(struct oid_par_priv *poid_par_priv)
130{ 131{
131 if (poid_par_priv->type_of_oid != QUERY_OID) 132 if (poid_par_priv->type_of_oid != QUERY_OID)
132 return NDIS_STATUS_NOT_ACCEPTED; 133 return RNDIS_STATUS_NOT_ACCEPTED;
133 return NDIS_STATUS_SUCCESS; 134 return RNDIS_STATUS_SUCCESS;
134} 135}
135 136
136uint oid_rt_get_tx_beacon_err_hdl(struct oid_par_priv *poid_par_priv) 137uint oid_rt_get_tx_beacon_err_hdl(struct oid_par_priv *poid_par_priv)
137{ 138{
138 if (poid_par_priv->type_of_oid != QUERY_OID) 139 if (poid_par_priv->type_of_oid != QUERY_OID)
139 return NDIS_STATUS_NOT_ACCEPTED; 140 return RNDIS_STATUS_NOT_ACCEPTED;
140 return NDIS_STATUS_SUCCESS; 141 return RNDIS_STATUS_SUCCESS;
141} 142}
142 143
143uint oid_rt_get_rx_icv_err_hdl(struct oid_par_priv *poid_par_priv) 144uint oid_rt_get_rx_icv_err_hdl(struct oid_par_priv *poid_par_priv)
@@ -146,22 +147,22 @@ uint oid_rt_get_rx_icv_err_hdl(struct oid_par_priv *poid_par_priv)
146 (poid_par_priv->adapter_context); 147 (poid_par_priv->adapter_context);
147 148
148 if (poid_par_priv->type_of_oid != QUERY_OID) 149 if (poid_par_priv->type_of_oid != QUERY_OID)
149 return NDIS_STATUS_NOT_ACCEPTED; 150 return RNDIS_STATUS_NOT_ACCEPTED;
150 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 151 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
151 *(uint *)poid_par_priv->information_buf = 152 *(uint *)poid_par_priv->information_buf =
152 padapter->recvpriv.rx_icv_err; 153 padapter->recvpriv.rx_icv_err;
153 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 154 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
154 } else 155 } else
155 return NDIS_STATUS_INVALID_LENGTH ; 156 return RNDIS_STATUS_INVALID_LENGTH ;
156 return NDIS_STATUS_SUCCESS; 157 return RNDIS_STATUS_SUCCESS;
157} 158}
158 159
159uint oid_rt_set_encryption_algorithm_hdl(struct oid_par_priv 160uint oid_rt_set_encryption_algorithm_hdl(struct oid_par_priv
160 *poid_par_priv) 161 *poid_par_priv)
161{ 162{
162 if (poid_par_priv->type_of_oid != SET_OID) 163 if (poid_par_priv->type_of_oid != SET_OID)
163 return NDIS_STATUS_NOT_ACCEPTED; 164 return RNDIS_STATUS_NOT_ACCEPTED;
164 return NDIS_STATUS_SUCCESS; 165 return RNDIS_STATUS_SUCCESS;
165} 166}
166 167
167uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv) 168uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv)
@@ -171,7 +172,7 @@ uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv)
171 u32 preamblemode = 0 ; 172 u32 preamblemode = 0 ;
172 173
173 if (poid_par_priv->type_of_oid != QUERY_OID) 174 if (poid_par_priv->type_of_oid != QUERY_OID)
174 return NDIS_STATUS_NOT_ACCEPTED; 175 return RNDIS_STATUS_NOT_ACCEPTED;
175 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 176 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
176 if (padapter->registrypriv.preamble == PREAMBLE_LONG) 177 if (padapter->registrypriv.preamble == PREAMBLE_LONG)
177 preamblemode = 0; 178 preamblemode = 0;
@@ -182,15 +183,15 @@ uint oid_rt_get_preamble_mode_hdl(struct oid_par_priv *poid_par_priv)
182 *(u32 *)poid_par_priv->information_buf = preamblemode; 183 *(u32 *)poid_par_priv->information_buf = preamblemode;
183 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 184 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
184 } else 185 } else
185 return NDIS_STATUS_INVALID_LENGTH; 186 return RNDIS_STATUS_INVALID_LENGTH;
186 return NDIS_STATUS_SUCCESS; 187 return RNDIS_STATUS_SUCCESS;
187} 188}
188 189
189uint oid_rt_get_ap_ip_hdl(struct oid_par_priv *poid_par_priv) 190uint oid_rt_get_ap_ip_hdl(struct oid_par_priv *poid_par_priv)
190{ 191{
191 if (poid_par_priv->type_of_oid != QUERY_OID) 192 if (poid_par_priv->type_of_oid != QUERY_OID)
192 return NDIS_STATUS_NOT_ACCEPTED; 193 return RNDIS_STATUS_NOT_ACCEPTED;
193 return NDIS_STATUS_SUCCESS; 194 return RNDIS_STATUS_SUCCESS;
194} 195}
195 196
196uint oid_rt_get_channelplan_hdl(struct oid_par_priv *poid_par_priv) 197uint oid_rt_get_channelplan_hdl(struct oid_par_priv *poid_par_priv)
@@ -200,10 +201,10 @@ uint oid_rt_get_channelplan_hdl(struct oid_par_priv *poid_par_priv)
200 struct eeprom_priv *peeprompriv = &padapter->eeprompriv; 201 struct eeprom_priv *peeprompriv = &padapter->eeprompriv;
201 202
202 if (poid_par_priv->type_of_oid != QUERY_OID) 203 if (poid_par_priv->type_of_oid != QUERY_OID)
203 return NDIS_STATUS_NOT_ACCEPTED; 204 return RNDIS_STATUS_NOT_ACCEPTED;
204 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 205 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
205 *(u16 *)poid_par_priv->information_buf = peeprompriv->channel_plan; 206 *(u16 *)poid_par_priv->information_buf = peeprompriv->channel_plan;
206 return NDIS_STATUS_SUCCESS; 207 return RNDIS_STATUS_SUCCESS;
207} 208}
208 209
209uint oid_rt_set_channelplan_hdl(struct oid_par_priv 210uint oid_rt_set_channelplan_hdl(struct oid_par_priv
@@ -214,9 +215,9 @@ uint oid_rt_set_channelplan_hdl(struct oid_par_priv
214 struct eeprom_priv *peeprompriv = &padapter->eeprompriv; 215 struct eeprom_priv *peeprompriv = &padapter->eeprompriv;
215 216
216 if (poid_par_priv->type_of_oid != SET_OID) 217 if (poid_par_priv->type_of_oid != SET_OID)
217 return NDIS_STATUS_NOT_ACCEPTED; 218 return RNDIS_STATUS_NOT_ACCEPTED;
218 peeprompriv->channel_plan = *(u16 *)poid_par_priv->information_buf; 219 peeprompriv->channel_plan = *(u16 *)poid_par_priv->information_buf;
219 return NDIS_STATUS_SUCCESS; 220 return RNDIS_STATUS_SUCCESS;
220} 221}
221 222
222uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv 223uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv
@@ -227,7 +228,7 @@ uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv
227 u32 preamblemode = 0; 228 u32 preamblemode = 0;
228 229
229 if (poid_par_priv->type_of_oid != SET_OID) 230 if (poid_par_priv->type_of_oid != SET_OID)
230 return NDIS_STATUS_NOT_ACCEPTED; 231 return RNDIS_STATUS_NOT_ACCEPTED;
231 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 232 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
232 preamblemode = *(u32 *)poid_par_priv->information_buf; 233 preamblemode = *(u32 *)poid_par_priv->information_buf;
233 if (preamblemode == 0) 234 if (preamblemode == 0)
@@ -239,21 +240,21 @@ uint oid_rt_set_preamble_mode_hdl(struct oid_par_priv
239 *(u32 *)poid_par_priv->information_buf = preamblemode; 240 *(u32 *)poid_par_priv->information_buf = preamblemode;
240 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 241 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
241 } else 242 } else
242 return NDIS_STATUS_INVALID_LENGTH; 243 return RNDIS_STATUS_INVALID_LENGTH;
243 return NDIS_STATUS_SUCCESS; 244 return RNDIS_STATUS_SUCCESS;
244} 245}
245 246
246uint oid_rt_set_bcn_intvl_hdl(struct oid_par_priv *poid_par_priv) 247uint oid_rt_set_bcn_intvl_hdl(struct oid_par_priv *poid_par_priv)
247{ 248{
248 if (poid_par_priv->type_of_oid != SET_OID) 249 if (poid_par_priv->type_of_oid != SET_OID)
249 return NDIS_STATUS_NOT_ACCEPTED; 250 return RNDIS_STATUS_NOT_ACCEPTED;
250 return NDIS_STATUS_SUCCESS; 251 return RNDIS_STATUS_SUCCESS;
251} 252}
252 253
253uint oid_rt_dedicate_probe_hdl(struct oid_par_priv 254uint oid_rt_dedicate_probe_hdl(struct oid_par_priv
254 *poid_par_priv) 255 *poid_par_priv)
255{ 256{
256 return NDIS_STATUS_SUCCESS; 257 return RNDIS_STATUS_SUCCESS;
257} 258}
258 259
259uint oid_rt_get_total_tx_bytes_hdl(struct oid_par_priv 260uint oid_rt_get_total_tx_bytes_hdl(struct oid_par_priv
@@ -263,14 +264,14 @@ uint oid_rt_get_total_tx_bytes_hdl(struct oid_par_priv
263 (poid_par_priv->adapter_context); 264 (poid_par_priv->adapter_context);
264 265
265 if (poid_par_priv->type_of_oid != QUERY_OID) 266 if (poid_par_priv->type_of_oid != QUERY_OID)
266 return NDIS_STATUS_NOT_ACCEPTED; 267 return RNDIS_STATUS_NOT_ACCEPTED;
267 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 268 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
268 *(u32 *)poid_par_priv->information_buf = 269 *(u32 *)poid_par_priv->information_buf =
269 padapter->xmitpriv.tx_bytes; 270 padapter->xmitpriv.tx_bytes;
270 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 271 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
271 } else 272 } else
272 return NDIS_STATUS_INVALID_LENGTH; 273 return RNDIS_STATUS_INVALID_LENGTH;
273 return NDIS_STATUS_SUCCESS; 274 return RNDIS_STATUS_SUCCESS;
274} 275}
275 276
276uint oid_rt_get_total_rx_bytes_hdl(struct oid_par_priv 277uint oid_rt_get_total_rx_bytes_hdl(struct oid_par_priv
@@ -280,37 +281,37 @@ uint oid_rt_get_total_rx_bytes_hdl(struct oid_par_priv
280 (poid_par_priv->adapter_context); 281 (poid_par_priv->adapter_context);
281 282
282 if (poid_par_priv->type_of_oid != QUERY_OID) 283 if (poid_par_priv->type_of_oid != QUERY_OID)
283 return NDIS_STATUS_NOT_ACCEPTED; 284 return RNDIS_STATUS_NOT_ACCEPTED;
284 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 285 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
285 *(u32 *)poid_par_priv->information_buf = 286 *(u32 *)poid_par_priv->information_buf =
286 padapter->recvpriv.rx_bytes; 287 padapter->recvpriv.rx_bytes;
287 *poid_par_priv->bytes_rw = poid_par_priv-> 288 *poid_par_priv->bytes_rw = poid_par_priv->
288 information_buf_len; 289 information_buf_len;
289 } else 290 } else
290 return NDIS_STATUS_INVALID_LENGTH; 291 return RNDIS_STATUS_INVALID_LENGTH;
291 return NDIS_STATUS_SUCCESS; 292 return RNDIS_STATUS_SUCCESS;
292} 293}
293 294
294uint oid_rt_current_tx_power_level_hdl(struct oid_par_priv 295uint oid_rt_current_tx_power_level_hdl(struct oid_par_priv
295 *poid_par_priv) 296 *poid_par_priv)
296{ 297{
297 return NDIS_STATUS_SUCCESS; 298 return RNDIS_STATUS_SUCCESS;
298} 299}
299 300
300uint oid_rt_get_enc_key_mismatch_count_hdl(struct oid_par_priv 301uint oid_rt_get_enc_key_mismatch_count_hdl(struct oid_par_priv
301 *poid_par_priv) 302 *poid_par_priv)
302{ 303{
303 if (poid_par_priv->type_of_oid != QUERY_OID) 304 if (poid_par_priv->type_of_oid != QUERY_OID)
304 return NDIS_STATUS_NOT_ACCEPTED; 305 return RNDIS_STATUS_NOT_ACCEPTED;
305 return NDIS_STATUS_SUCCESS; 306 return RNDIS_STATUS_SUCCESS;
306} 307}
307 308
308uint oid_rt_get_enc_key_match_count_hdl(struct oid_par_priv 309uint oid_rt_get_enc_key_match_count_hdl(struct oid_par_priv
309 *poid_par_priv) 310 *poid_par_priv)
310{ 311{
311 if (poid_par_priv->type_of_oid != QUERY_OID) 312 if (poid_par_priv->type_of_oid != QUERY_OID)
312 return NDIS_STATUS_NOT_ACCEPTED; 313 return RNDIS_STATUS_NOT_ACCEPTED;
313 return NDIS_STATUS_SUCCESS; 314 return RNDIS_STATUS_SUCCESS;
314} 315}
315 316
316uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv) 317uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv)
@@ -322,7 +323,7 @@ uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv)
322 u32 channelnum; 323 u32 channelnum;
323 324
324 if (poid_par_priv->type_of_oid != QUERY_OID) 325 if (poid_par_priv->type_of_oid != QUERY_OID)
325 return NDIS_STATUS_NOT_ACCEPTED; 326 return RNDIS_STATUS_NOT_ACCEPTED;
326 if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) || 327 if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) ||
327 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true)) 328 (check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) == true))
328 pnic_Config = &pmlmepriv->cur_network.network.Configuration; 329 pnic_Config = &pmlmepriv->cur_network.network.Configuration;
@@ -332,22 +333,22 @@ uint oid_rt_get_channel_hdl(struct oid_par_priv *poid_par_priv)
332 channelnum = pnic_Config->DSConfig; 333 channelnum = pnic_Config->DSConfig;
333 *(u32 *)poid_par_priv->information_buf = channelnum; 334 *(u32 *)poid_par_priv->information_buf = channelnum;
334 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 335 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
335 return NDIS_STATUS_SUCCESS; 336 return RNDIS_STATUS_SUCCESS;
336} 337}
337 338
338uint oid_rt_get_hardware_radio_off_hdl(struct oid_par_priv 339uint oid_rt_get_hardware_radio_off_hdl(struct oid_par_priv
339 *poid_par_priv) 340 *poid_par_priv)
340{ 341{
341 if (poid_par_priv->type_of_oid != QUERY_OID) 342 if (poid_par_priv->type_of_oid != QUERY_OID)
342 return NDIS_STATUS_NOT_ACCEPTED; 343 return RNDIS_STATUS_NOT_ACCEPTED;
343 return NDIS_STATUS_SUCCESS; 344 return RNDIS_STATUS_SUCCESS;
344} 345}
345 346
346uint oid_rt_get_key_mismatch_hdl(struct oid_par_priv *poid_par_priv) 347uint oid_rt_get_key_mismatch_hdl(struct oid_par_priv *poid_par_priv)
347{ 348{
348 if (poid_par_priv->type_of_oid != QUERY_OID) 349 if (poid_par_priv->type_of_oid != QUERY_OID)
349 return NDIS_STATUS_NOT_ACCEPTED; 350 return RNDIS_STATUS_NOT_ACCEPTED;
350 return NDIS_STATUS_SUCCESS; 351 return RNDIS_STATUS_SUCCESS;
351} 352}
352 353
353uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv 354uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv
@@ -356,7 +357,7 @@ uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv
356 u32 ulInfo = 0; 357 u32 ulInfo = 0;
357 358
358 if (poid_par_priv->type_of_oid != QUERY_OID) 359 if (poid_par_priv->type_of_oid != QUERY_OID)
359 return NDIS_STATUS_NOT_ACCEPTED; 360 return RNDIS_STATUS_NOT_ACCEPTED;
360 if (poid_par_priv->information_buf_len >= sizeof(u32)) { 361 if (poid_par_priv->information_buf_len >= sizeof(u32)) {
361 ulInfo |= 0x0100; /* WIRELESS_MODE_B */ 362 ulInfo |= 0x0100; /* WIRELESS_MODE_B */
362 ulInfo |= 0x0200; /* WIRELESS_MODE_G */ 363 ulInfo |= 0x0200; /* WIRELESS_MODE_G */
@@ -364,108 +365,108 @@ uint oid_rt_supported_wireless_mode_hdl(struct oid_par_priv
364 *(u32 *) poid_par_priv->information_buf = ulInfo; 365 *(u32 *) poid_par_priv->information_buf = ulInfo;
365 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 366 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
366 } else 367 } else
367 return NDIS_STATUS_INVALID_LENGTH; 368 return RNDIS_STATUS_INVALID_LENGTH;
368 return NDIS_STATUS_SUCCESS; 369 return RNDIS_STATUS_SUCCESS;
369} 370}
370 371
371uint oid_rt_get_channel_list_hdl(struct oid_par_priv *poid_par_priv) 372uint oid_rt_get_channel_list_hdl(struct oid_par_priv *poid_par_priv)
372{ 373{
373 if (poid_par_priv->type_of_oid != QUERY_OID) 374 if (poid_par_priv->type_of_oid != QUERY_OID)
374 return NDIS_STATUS_NOT_ACCEPTED; 375 return RNDIS_STATUS_NOT_ACCEPTED;
375 return NDIS_STATUS_SUCCESS; 376 return RNDIS_STATUS_SUCCESS;
376} 377}
377 378
378uint oid_rt_get_scan_in_progress_hdl(struct oid_par_priv *poid_par_priv) 379uint oid_rt_get_scan_in_progress_hdl(struct oid_par_priv *poid_par_priv)
379{ 380{
380 if (poid_par_priv->type_of_oid != QUERY_OID) 381 if (poid_par_priv->type_of_oid != QUERY_OID)
381 return NDIS_STATUS_NOT_ACCEPTED; 382 return RNDIS_STATUS_NOT_ACCEPTED;
382 return NDIS_STATUS_SUCCESS; 383 return RNDIS_STATUS_SUCCESS;
383} 384}
384 385
385 386
386uint oid_rt_forced_data_rate_hdl(struct oid_par_priv *poid_par_priv) 387uint oid_rt_forced_data_rate_hdl(struct oid_par_priv *poid_par_priv)
387{ 388{
388 return NDIS_STATUS_SUCCESS; 389 return RNDIS_STATUS_SUCCESS;
389} 390}
390 391
391uint oid_rt_wireless_mode_for_scan_list_hdl(struct oid_par_priv 392uint oid_rt_wireless_mode_for_scan_list_hdl(struct oid_par_priv
392 *poid_par_priv) 393 *poid_par_priv)
393{ 394{
394 return NDIS_STATUS_SUCCESS; 395 return RNDIS_STATUS_SUCCESS;
395} 396}
396 397
397uint oid_rt_get_bss_wireless_mode_hdl(struct oid_par_priv 398uint oid_rt_get_bss_wireless_mode_hdl(struct oid_par_priv
398 *poid_par_priv) 399 *poid_par_priv)
399{ 400{
400 if (poid_par_priv->type_of_oid != QUERY_OID) 401 if (poid_par_priv->type_of_oid != QUERY_OID)
401 return NDIS_STATUS_NOT_ACCEPTED; 402 return RNDIS_STATUS_NOT_ACCEPTED;
402 return NDIS_STATUS_SUCCESS; 403 return RNDIS_STATUS_SUCCESS;
403} 404}
404 405
405uint oid_rt_scan_with_magic_packet_hdl(struct oid_par_priv 406uint oid_rt_scan_with_magic_packet_hdl(struct oid_par_priv
406 *poid_par_priv) 407 *poid_par_priv)
407{ 408{
408 return NDIS_STATUS_SUCCESS; 409 return RNDIS_STATUS_SUCCESS;
409} 410}
410 411
411uint oid_rt_ap_get_associated_station_list_hdl(struct oid_par_priv 412uint oid_rt_ap_get_associated_station_list_hdl(struct oid_par_priv
412 *poid_par_priv) 413 *poid_par_priv)
413{ 414{
414 if (poid_par_priv->type_of_oid != QUERY_OID) 415 if (poid_par_priv->type_of_oid != QUERY_OID)
415 return NDIS_STATUS_NOT_ACCEPTED; 416 return RNDIS_STATUS_NOT_ACCEPTED;
416 return NDIS_STATUS_SUCCESS; 417 return RNDIS_STATUS_SUCCESS;
417} 418}
418 419
419uint oid_rt_ap_switch_into_ap_mode_hdl(struct oid_par_priv* 420uint oid_rt_ap_switch_into_ap_mode_hdl(struct oid_par_priv*
420 poid_par_priv) 421 poid_par_priv)
421{ 422{
422 return NDIS_STATUS_SUCCESS; 423 return RNDIS_STATUS_SUCCESS;
423} 424}
424 425
425uint oid_rt_ap_supported_hdl(struct oid_par_priv *poid_par_priv) 426uint oid_rt_ap_supported_hdl(struct oid_par_priv *poid_par_priv)
426{ 427{
427 return NDIS_STATUS_SUCCESS; 428 return RNDIS_STATUS_SUCCESS;
428} 429}
429 430
430uint oid_rt_ap_set_passphrase_hdl(struct oid_par_priv *poid_par_priv) 431uint oid_rt_ap_set_passphrase_hdl(struct oid_par_priv *poid_par_priv)
431{ 432{
432 if (poid_par_priv->type_of_oid != SET_OID) 433 if (poid_par_priv->type_of_oid != SET_OID)
433 return NDIS_STATUS_NOT_ACCEPTED; 434 return RNDIS_STATUS_NOT_ACCEPTED;
434 return NDIS_STATUS_SUCCESS; 435 return RNDIS_STATUS_SUCCESS;
435} 436}
436 437
437uint oid_rt_pro_rf_write_registry_hdl(struct oid_par_priv* 438uint oid_rt_pro_rf_write_registry_hdl(struct oid_par_priv*
438 poid_par_priv) 439 poid_par_priv)
439{ 440{
440 uint status = NDIS_STATUS_SUCCESS; 441 uint status = RNDIS_STATUS_SUCCESS;
441 struct _adapter *Adapter = (struct _adapter *) 442 struct _adapter *Adapter = (struct _adapter *)
442 (poid_par_priv->adapter_context); 443 (poid_par_priv->adapter_context);
443 444
444 if (poid_par_priv->type_of_oid != SET_OID) /* QUERY_OID */ 445 if (poid_par_priv->type_of_oid != SET_OID) /* QUERY_OID */
445 return NDIS_STATUS_NOT_ACCEPTED; 446 return RNDIS_STATUS_NOT_ACCEPTED;
446 if (poid_par_priv->information_buf_len == 447 if (poid_par_priv->information_buf_len ==
447 (sizeof(unsigned long) * 3)) { 448 (sizeof(unsigned long) * 3)) {
448 if (!r8712_setrfreg_cmd(Adapter, 449 if (!r8712_setrfreg_cmd(Adapter,
449 *(unsigned char *)poid_par_priv->information_buf, 450 *(unsigned char *)poid_par_priv->information_buf,
450 (unsigned long)(*((unsigned long *) 451 (unsigned long)(*((unsigned long *)
451 poid_par_priv->information_buf + 2)))) 452 poid_par_priv->information_buf + 2))))
452 status = NDIS_STATUS_NOT_ACCEPTED; 453 status = RNDIS_STATUS_NOT_ACCEPTED;
453 } else 454 } else
454 status = NDIS_STATUS_INVALID_LENGTH; 455 status = RNDIS_STATUS_INVALID_LENGTH;
455 return status; 456 return status;
456} 457}
457 458
458uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv) 459uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv)
459{ 460{
460 uint status = NDIS_STATUS_SUCCESS; 461 uint status = RNDIS_STATUS_SUCCESS;
461 struct _adapter *Adapter = (struct _adapter *) 462 struct _adapter *Adapter = (struct _adapter *)
462 (poid_par_priv->adapter_context); 463 (poid_par_priv->adapter_context);
463 464
464 if (poid_par_priv->type_of_oid != SET_OID) /* QUERY_OID */ 465 if (poid_par_priv->type_of_oid != SET_OID) /* QUERY_OID */
465 return NDIS_STATUS_NOT_ACCEPTED; 466 return RNDIS_STATUS_NOT_ACCEPTED;
466 if (poid_par_priv->information_buf_len == (sizeof(unsigned long)*3)) { 467 if (poid_par_priv->information_buf_len == (sizeof(unsigned long)*3)) {
467 if (Adapter->mppriv.act_in_progress == true) 468 if (Adapter->mppriv.act_in_progress == true)
468 status = NDIS_STATUS_NOT_ACCEPTED; 469 status = RNDIS_STATUS_NOT_ACCEPTED;
469 else { 470 else {
470 /* init workparam */ 471 /* init workparam */
471 Adapter->mppriv.act_in_progress = true; 472 Adapter->mppriv.act_in_progress = true;
@@ -486,10 +487,10 @@ uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv)
486 *(unsigned char *)poid_par_priv->information_buf, 487 *(unsigned char *)poid_par_priv->information_buf,
487 (unsigned char *)&Adapter->mppriv.workparam. 488 (unsigned char *)&Adapter->mppriv.workparam.
488 io_value)) 489 io_value))
489 status = NDIS_STATUS_NOT_ACCEPTED; 490 status = RNDIS_STATUS_NOT_ACCEPTED;
490 } 491 }
491 } else 492 } else
492 status = NDIS_STATUS_INVALID_LENGTH; 493 status = RNDIS_STATUS_INVALID_LENGTH;
493 return status; 494 return status;
494} 495}
495 496
@@ -508,7 +509,7 @@ uint oid_rt_get_connect_state_hdl(struct oid_par_priv *poid_par_priv)
508 u32 ulInfo; 509 u32 ulInfo;
509 510
510 if (poid_par_priv->type_of_oid != QUERY_OID) 511 if (poid_par_priv->type_of_oid != QUERY_OID)
511 return NDIS_STATUS_NOT_ACCEPTED; 512 return RNDIS_STATUS_NOT_ACCEPTED;
512 /* nStatus==0 CheckingStatus 513 /* nStatus==0 CheckingStatus
513 * nStatus==1 Associated 514 * nStatus==1 Associated
514 * nStatus==2 AdHocMode 515 * nStatus==2 AdHocMode
@@ -524,12 +525,12 @@ uint oid_rt_get_connect_state_hdl(struct oid_par_priv *poid_par_priv)
524 ulInfo = NOTASSOCIATED ; 525 ulInfo = NOTASSOCIATED ;
525 *(u32 *)poid_par_priv->information_buf = ulInfo; 526 *(u32 *)poid_par_priv->information_buf = ulInfo;
526 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 527 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
527 return NDIS_STATUS_SUCCESS; 528 return RNDIS_STATUS_SUCCESS;
528} 529}
529 530
530uint oid_rt_set_default_key_id_hdl(struct oid_par_priv *poid_par_priv) 531uint oid_rt_set_default_key_id_hdl(struct oid_par_priv *poid_par_priv)
531{ 532{
532 if (poid_par_priv->type_of_oid != SET_OID) 533 if (poid_par_priv->type_of_oid != SET_OID)
533 return NDIS_STATUS_NOT_ACCEPTED; 534 return RNDIS_STATUS_NOT_ACCEPTED;
534 return NDIS_STATUS_SUCCESS; 535 return RNDIS_STATUS_SUCCESS;
535} 536}
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
index d3ab24e34e3d..53a7c8c1bb40 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
@@ -97,8 +97,6 @@ static u8 do_join(struct _adapter *padapter)
97 pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE; 97 pmlmepriv->fw_state = WIFI_ADHOC_MASTER_STATE;
98 pibss = padapter->registrypriv.dev_network. 98 pibss = padapter->registrypriv.dev_network.
99 MacAddress; 99 MacAddress;
100 memset(&pdev_network->Ssid, 0,
101 sizeof(struct ndis_802_11_ssid));
102 memcpy(&pdev_network->Ssid, 100 memcpy(&pdev_network->Ssid,
103 &pmlmepriv->assoc_ssid, 101 &pmlmepriv->assoc_ssid,
104 sizeof(struct ndis_802_11_ssid)); 102 sizeof(struct ndis_802_11_ssid));
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index c51ad9ed4b52..659615481f6f 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -604,9 +604,6 @@ void r8712_surveydone_event_callback(struct _adapter *adapter, u8 *pbuf)
604 adapter->registrypriv. 604 adapter->registrypriv.
605 dev_network.MacAddress; 605 dev_network.MacAddress;
606 pmlmepriv->fw_state ^= _FW_UNDER_SURVEY; 606 pmlmepriv->fw_state ^= _FW_UNDER_SURVEY;
607 memset(&pdev_network->Ssid, 0,
608 sizeof(struct
609 ndis_802_11_ssid));
610 memcpy(&pdev_network->Ssid, 607 memcpy(&pdev_network->Ssid,
611 &pmlmepriv->assoc_ssid, 608 &pmlmepriv->assoc_ssid,
612 sizeof(struct 609 sizeof(struct
@@ -1006,8 +1003,6 @@ void r8712_stadel_event_callback(struct _adapter *adapter, u8 *pbuf)
1006 memcpy(pdev_network, &tgt_network->network, 1003 memcpy(pdev_network, &tgt_network->network,
1007 r8712_get_ndis_wlan_bssid_ex_sz(&tgt_network-> 1004 r8712_get_ndis_wlan_bssid_ex_sz(&tgt_network->
1008 network)); 1005 network));
1009 memset(&pdev_network->Ssid, 0,
1010 sizeof(struct ndis_802_11_ssid));
1011 memcpy(&pdev_network->Ssid, 1006 memcpy(&pdev_network->Ssid,
1012 &pmlmepriv->assoc_ssid, 1007 &pmlmepriv->assoc_ssid,
1013 sizeof(struct ndis_802_11_ssid)); 1008 sizeof(struct ndis_802_11_ssid));
@@ -1048,8 +1043,8 @@ void r8712_got_addbareq_event_callback(struct _adapter *adapter, u8 *pbuf)
1048 struct sta_priv *pstapriv = &adapter->stapriv; 1043 struct sta_priv *pstapriv = &adapter->stapriv;
1049 struct recv_reorder_ctrl *precvreorder_ctrl = NULL; 1044 struct recv_reorder_ctrl *precvreorder_ctrl = NULL;
1050 1045
1051 printk(KERN_INFO "r8712u: [%s] mac = %pM, seq = %d, tid = %d\n", 1046 netdev_info(adapter->pnetdev, "%s: mac = %pM, seq = %d, tid = %d\n",
1052 __func__, pAddbareq_pram->MacAddress, 1047 __func__, pAddbareq_pram->MacAddress,
1053 pAddbareq_pram->StartSeqNum, pAddbareq_pram->tid); 1048 pAddbareq_pram->StartSeqNum, pAddbareq_pram->tid);
1054 psta = r8712_get_stainfo(pstapriv, pAddbareq_pram->MacAddress); 1049 psta = r8712_get_stainfo(pstapriv, pAddbareq_pram->MacAddress);
1055 if (psta) { 1050 if (psta) {
diff --git a/drivers/staging/rtl8712/rtl871x_mp.h b/drivers/staging/rtl8712/rtl871x_mp.h
index 255dc94f0901..51395d1a3c7e 100644
--- a/drivers/staging/rtl8712/rtl871x_mp.h
+++ b/drivers/staging/rtl8712/rtl871x_mp.h
@@ -26,62 +26,6 @@
26#ifndef __RTL871X_MP_H_ 26#ifndef __RTL871X_MP_H_
27#define __RTL871X_MP_H_ 27#define __RTL871X_MP_H_
28 28
29/* 00 - Success */
30/* 11 - Error */
31#define STATUS_SUCCESS (0x00000000L)
32#define STATUS_PENDING (0x00000103L)
33#define STATUS_UNSUCCESSFUL (0xC0000001L)
34#define STATUS_INSUFFICIENT_RESOURCES (0xC000009AL)
35#define STATUS_NOT_SUPPORTED (0xC00000BBL)
36#define NDIS_STATUS_SUCCESS ((uint)STATUS_SUCCESS)
37#define NDIS_STATUS_PENDING ((uint) STATUS_PENDING)
38#define NDIS_STATUS_NOT_RECOGNIZED ((uint)0x00010001L)
39#define NDIS_STATUS_NOT_COPIED ((uint)0x00010002L)
40#define NDIS_STATUS_NOT_ACCEPTED ((uint)0x00010003L)
41#define NDIS_STATUS_CALL_ACTIVE ((uint)0x00010007L)
42#define NDIS_STATUS_FAILURE ((uint) STATUS_UNSUCCESSFUL)
43#define NDIS_STATUS_RESOURCES ((uint)\
44 STATUS_INSUFFICIENT_RESOURCES)
45#define NDIS_STATUS_CLOSING ((uint)0xC0010002L)
46#define NDIS_STATUS_BAD_VERSION ((uint)0xC0010004L)
47#define NDIS_STATUS_BAD_CHARACTERISTICS ((uint)0xC0010005L)
48#define NDIS_STATUS_ADAPTER_NOT_FOUND ((uint)0xC0010006L)
49#define NDIS_STATUS_OPEN_FAILED ((uint)0xC0010007L)
50#define NDIS_STATUS_DEVICE_FAILED ((uint)0xC0010008L)
51#define NDIS_STATUS_MULTICAST_FULL ((uint)0xC0010009L)
52#define NDIS_STATUS_MULTICAST_EXISTS ((uint)0xC001000AL)
53#define NDIS_STATUS_MULTICAST_NOT_FOUND ((uint)0xC001000BL)
54#define NDIS_STATUS_REQUEST_ABORTED ((uint)0xC001000CL)
55#define NDIS_STATUS_RESET_IN_PROGRESS ((uint)0xC001000DL)
56#define NDIS_STATUS_CLOSING_INDICATING ((uint)0xC001000EL)
57#define NDIS_STATUS_NOT_SUPPORTED ((uint)STATUS_NOT_SUPPORTED)
58#define NDIS_STATUS_INVALID_PACKET ((uint)0xC001000FL)
59#define NDIS_STATUS_OPEN_LIST_FULL ((uint)0xC0010010L)
60#define NDIS_STATUS_ADAPTER_NOT_READY ((uint)0xC0010011L)
61#define NDIS_STATUS_ADAPTER_NOT_OPEN ((uint)0xC0010012L)
62#define NDIS_STATUS_NOT_INDICATING ((uint)0xC0010013L)
63#define NDIS_STATUS_INVALID_LENGTH ((uint)0xC0010014L)
64#define NDIS_STATUS_INVALID_DATA ((uint)0xC0010015L)
65#define NDIS_STATUS_BUFFER_TOO_SHORT ((uint)0xC0010016L)
66#define NDIS_STATUS_INVALID_OID ((uint)0xC0010017L)
67#define NDIS_STATUS_ADAPTER_REMOVED ((uint)0xC0010018L)
68#define NDIS_STATUS_UNSUPPORTED_MEDIA ((uint)0xC0010019L)
69#define NDIS_STATUS_GROUP_ADDRESS_IN_USE ((uint)0xC001001AL)
70#define NDIS_STATUS_FILE_NOT_FOUND ((uint)0xC001001BL)
71#define NDIS_STATUS_ERROR_READING_FILE ((uint)0xC001001CL)
72#define NDIS_STATUS_ALREADY_MAPPED ((uint)0xC001001DL)
73#define NDIS_STATUS_RESOURCE_CONFLICT ((uint)0xC001001EL)
74#define NDIS_STATUS_NO_CABLE ((uint)0xC001001FL)
75#define NDIS_STATUS_INVALID_SAP ((uint)0xC0010020L)
76#define NDIS_STATUS_SAP_IN_USE ((uint)0xC0010021L)
77#define NDIS_STATUS_INVALID_ADDRESS ((uint)0xC0010022L)
78#define NDIS_STATUS_VC_NOT_ACTIVATED ((uint)0xC0010023L)
79#define NDIS_STATUS_DEST_OUT_OF_ORDER ((uint)0xC0010024L) /* cause 27*/
80#define NDIS_STATUS_VC_NOT_AVAILABLE ((uint)0xC0010025L) /* 35,45*/
81#define NDIS_STATUS_CELLRATE_NOT_AVAILABLE ((uint)0xC0010026L) /* 37*/
82#define NDIS_STATUS_INCOMPATABLE_QOS ((uint)0xC0010027L) /* 49*/
83#define NDIS_STATUS_AAL_PARAMS_UNSUPPORTED ((uint)0xC0010028L) /* 93*/
84#define NDIS_STATUS_NO_ROUTE_TO_DESTINATION ((uint)0xC0010029L) /* 3*/
85#define MPT_NOOP 0 29#define MPT_NOOP 0
86#define MPT_READ_MAC_1BYTE 1 30#define MPT_READ_MAC_1BYTE 1
87#define MPT_READ_MAC_2BYTE 2 31#define MPT_READ_MAC_2BYTE 2
diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
index 5eb461b4a491..5bd42966fd5c 100644
--- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
+++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
@@ -26,6 +26,7 @@
26 * 26 *
27 ******************************************************************************/ 27 ******************************************************************************/
28 28
29#include <linux/rndis.h>
29#include "osdep_service.h" 30#include "osdep_service.h"
30#include "drv_types.h" 31#include "drv_types.h"
31#include "mlme_osdep.h" 32#include "mlme_osdep.h"
@@ -34,12 +35,12 @@
34 35
35uint oid_null_function(struct oid_par_priv *poid_par_priv) 36uint oid_null_function(struct oid_par_priv *poid_par_priv)
36{ 37{
37 return NDIS_STATUS_SUCCESS; 38 return RNDIS_STATUS_SUCCESS;
38} 39}
39 40
40uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv) 41uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv)
41{ 42{
42 uint status = NDIS_STATUS_SUCCESS; 43 uint status = RNDIS_STATUS_SUCCESS;
43 struct _adapter *Adapter = (struct _adapter *) 44 struct _adapter *Adapter = (struct _adapter *)
44 (poid_par_priv->adapter_context); 45 (poid_par_priv->adapter_context);
45 46
@@ -48,7 +49,7 @@ uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv)
48 Adapter->registrypriv.wireless_mode = 49 Adapter->registrypriv.wireless_mode =
49 *(u8 *)poid_par_priv->information_buf; 50 *(u8 *)poid_par_priv->information_buf;
50 else 51 else
51 status = NDIS_STATUS_INVALID_LENGTH; 52 status = RNDIS_STATUS_INVALID_LENGTH;
52 } else if (poid_par_priv->type_of_oid == QUERY_OID) { 53 } else if (poid_par_priv->type_of_oid == QUERY_OID) {
53 if (poid_par_priv->information_buf_len >= sizeof(u8)) { 54 if (poid_par_priv->information_buf_len >= sizeof(u8)) {
54 *(u8 *)poid_par_priv->information_buf = 55 *(u8 *)poid_par_priv->information_buf =
@@ -56,16 +57,16 @@ uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv)
56 *poid_par_priv->bytes_rw = 57 *poid_par_priv->bytes_rw =
57 poid_par_priv->information_buf_len; 58 poid_par_priv->information_buf_len;
58 } else 59 } else
59 status = NDIS_STATUS_INVALID_LENGTH; 60 status = RNDIS_STATUS_INVALID_LENGTH;
60 } else { 61 } else {
61 status = NDIS_STATUS_NOT_ACCEPTED; 62 status = RNDIS_STATUS_NOT_ACCEPTED;
62 } 63 }
63 return status; 64 return status;
64} 65}
65 66
66uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv) 67uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
67{ 68{
68 uint status = NDIS_STATUS_SUCCESS; 69 uint status = RNDIS_STATUS_SUCCESS;
69 struct _adapter *Adapter = (struct _adapter *) 70 struct _adapter *Adapter = (struct _adapter *)
70 (poid_par_priv->adapter_context); 71 (poid_par_priv->adapter_context);
71 struct bb_reg_param *pbbreg; 72 struct bb_reg_param *pbbreg;
@@ -73,9 +74,9 @@ uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
73 u32 value; 74 u32 value;
74 75
75 if (poid_par_priv->type_of_oid != SET_OID) 76 if (poid_par_priv->type_of_oid != SET_OID)
76 return NDIS_STATUS_NOT_ACCEPTED; 77 return RNDIS_STATUS_NOT_ACCEPTED;
77 if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) 78 if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param))
78 return NDIS_STATUS_INVALID_LENGTH; 79 return RNDIS_STATUS_INVALID_LENGTH;
79 pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); 80 pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf);
80 offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/ 81 offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/
81 if (offset < BB_REG_BASE_ADDR) 82 if (offset < BB_REG_BASE_ADDR)
@@ -87,7 +88,7 @@ uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
87 88
88uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv) 89uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
89{ 90{
90 uint status = NDIS_STATUS_SUCCESS; 91 uint status = RNDIS_STATUS_SUCCESS;
91 struct _adapter *Adapter = (struct _adapter *) 92 struct _adapter *Adapter = (struct _adapter *)
92 (poid_par_priv->adapter_context); 93 (poid_par_priv->adapter_context);
93 struct bb_reg_param *pbbreg; 94 struct bb_reg_param *pbbreg;
@@ -95,9 +96,9 @@ uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
95 u32 value; 96 u32 value;
96 97
97 if (poid_par_priv->type_of_oid != QUERY_OID) 98 if (poid_par_priv->type_of_oid != QUERY_OID)
98 return NDIS_STATUS_NOT_ACCEPTED; 99 return RNDIS_STATUS_NOT_ACCEPTED;
99 if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param)) 100 if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param))
100 return NDIS_STATUS_INVALID_LENGTH; 101 return RNDIS_STATUS_INVALID_LENGTH;
101 pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf); 102 pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf);
102 offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/ 103 offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/
103 if (offset < BB_REG_BASE_ADDR) 104 if (offset < BB_REG_BASE_ADDR)
@@ -110,7 +111,7 @@ uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
110 111
111uint oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv) 112uint oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv)
112{ 113{
113 uint status = NDIS_STATUS_SUCCESS; 114 uint status = RNDIS_STATUS_SUCCESS;
114 struct _adapter *Adapter = (struct _adapter *) 115 struct _adapter *Adapter = (struct _adapter *)
115 (poid_par_priv->adapter_context); 116 (poid_par_priv->adapter_context);
116 struct rf_reg_param *pbbreg; 117 struct rf_reg_param *pbbreg;
@@ -119,13 +120,13 @@ uint oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv)
119 u32 value; 120 u32 value;
120 121
121 if (poid_par_priv->type_of_oid != SET_OID) 122 if (poid_par_priv->type_of_oid != SET_OID)
122 return NDIS_STATUS_NOT_ACCEPTED; 123 return RNDIS_STATUS_NOT_ACCEPTED;
123 if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) 124 if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param))
124 return NDIS_STATUS_INVALID_LENGTH; 125 return RNDIS_STATUS_INVALID_LENGTH;
125 pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); 126 pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf);
126 path = (u8)pbbreg->path; 127 path = (u8)pbbreg->path;
127 if (path > RF_PATH_B) 128 if (path > RF_PATH_B)
128 return NDIS_STATUS_NOT_ACCEPTED; 129 return RNDIS_STATUS_NOT_ACCEPTED;
129 offset = (u8)pbbreg->offset; 130 offset = (u8)pbbreg->offset;
130 value = pbbreg->value; 131 value = pbbreg->value;
131 r8712_rf_reg_write(Adapter, path, offset, value); 132 r8712_rf_reg_write(Adapter, path, offset, value);
@@ -136,20 +137,20 @@ uint oid_rt_pro_read_rf_reg_hdl(struct oid_par_priv *poid_par_priv)
136{ 137{
137 struct _adapter *Adapter = (struct _adapter *) 138 struct _adapter *Adapter = (struct _adapter *)
138 (poid_par_priv->adapter_context); 139 (poid_par_priv->adapter_context);
139 uint status = NDIS_STATUS_SUCCESS; 140 uint status = RNDIS_STATUS_SUCCESS;
140 struct rf_reg_param *pbbreg; 141 struct rf_reg_param *pbbreg;
141 u8 path; 142 u8 path;
142 u8 offset; 143 u8 offset;
143 u32 value; 144 u32 value;
144 145
145 if (poid_par_priv->type_of_oid != QUERY_OID) 146 if (poid_par_priv->type_of_oid != QUERY_OID)
146 return NDIS_STATUS_NOT_ACCEPTED; 147 return RNDIS_STATUS_NOT_ACCEPTED;
147 if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param)) 148 if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param))
148 return NDIS_STATUS_INVALID_LENGTH; 149 return RNDIS_STATUS_INVALID_LENGTH;
149 pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf); 150 pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf);
150 path = (u8)pbbreg->path; 151 path = (u8)pbbreg->path;
151 if (path > RF_PATH_B) /* 1T2R path_a /path_b */ 152 if (path > RF_PATH_B) /* 1T2R path_a /path_b */
152 return NDIS_STATUS_NOT_ACCEPTED; 153 return RNDIS_STATUS_NOT_ACCEPTED;
153 offset = (u8)pbbreg->offset; 154 offset = (u8)pbbreg->offset;
154 value = r8712_rf_reg_read(Adapter, path, offset); 155 value = r8712_rf_reg_read(Adapter, path, offset);
155 pbbreg->value = value; 156 pbbreg->value = value;
@@ -265,16 +266,16 @@ uint oid_rt_pro_set_data_rate_hdl(struct oid_par_priv
265{ 266{
266 struct _adapter *Adapter = (struct _adapter *) 267 struct _adapter *Adapter = (struct _adapter *)
267 (poid_par_priv->adapter_context); 268 (poid_par_priv->adapter_context);
268 uint status = NDIS_STATUS_SUCCESS; 269 uint status = RNDIS_STATUS_SUCCESS;
269 u32 ratevalue; 270 u32 ratevalue;
270 271
271 if (poid_par_priv->type_of_oid != SET_OID) 272 if (poid_par_priv->type_of_oid != SET_OID)
272 return NDIS_STATUS_NOT_ACCEPTED; 273 return RNDIS_STATUS_NOT_ACCEPTED;
273 if (poid_par_priv->information_buf_len != sizeof(u32)) 274 if (poid_par_priv->information_buf_len != sizeof(u32))
274 return NDIS_STATUS_INVALID_LENGTH; 275 return RNDIS_STATUS_INVALID_LENGTH;
275 ratevalue = *((u32 *)poid_par_priv->information_buf); 276 ratevalue = *((u32 *)poid_par_priv->information_buf);
276 if (ratevalue >= MPT_RATE_LAST) 277 if (ratevalue >= MPT_RATE_LAST)
277 return NDIS_STATUS_INVALID_DATA; 278 return RNDIS_STATUS_INVALID_DATA;
278 Adapter->mppriv.curr_rateidx = ratevalue; 279 Adapter->mppriv.curr_rateidx = ratevalue;
279 r8712_SetDataRate(Adapter); 280 r8712_SetDataRate(Adapter);
280 return status; 281 return status;
@@ -284,16 +285,16 @@ uint oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv)
284{ 285{
285 struct _adapter *Adapter = (struct _adapter *) 286 struct _adapter *Adapter = (struct _adapter *)
286 (poid_par_priv->adapter_context); 287 (poid_par_priv->adapter_context);
287 uint status = NDIS_STATUS_SUCCESS; 288 uint status = RNDIS_STATUS_SUCCESS;
288 u32 mode; 289 u32 mode;
289 u8 val8; 290 u8 val8;
290 291
291 if (poid_par_priv->type_of_oid != SET_OID) 292 if (poid_par_priv->type_of_oid != SET_OID)
292 return NDIS_STATUS_NOT_ACCEPTED; 293 return RNDIS_STATUS_NOT_ACCEPTED;
293 mode = *((u32 *)poid_par_priv->information_buf); 294 mode = *((u32 *)poid_par_priv->information_buf);
294 Adapter->mppriv.mode = mode;/* 1 for loopback*/ 295 Adapter->mppriv.mode = mode;/* 1 for loopback*/
295 if (mp_start_test(Adapter) == _FAIL) 296 if (mp_start_test(Adapter) == _FAIL)
296 status = NDIS_STATUS_NOT_ACCEPTED; 297 status = RNDIS_STATUS_NOT_ACCEPTED;
297 r8712_write8(Adapter, MSR, 1); /* Link in ad hoc network, 0x1025004C */ 298 r8712_write8(Adapter, MSR, 1); /* Link in ad hoc network, 0x1025004C */
298 r8712_write8(Adapter, RCR, 0); /* RCR : disable all pkt, 0x10250048 */ 299 r8712_write8(Adapter, RCR, 0); /* RCR : disable all pkt, 0x10250048 */
299 /* RCR disable Check BSSID, 0x1025004a */ 300 /* RCR disable Check BSSID, 0x1025004a */
@@ -313,12 +314,12 @@ uint oid_rt_pro_stop_test_hdl(struct oid_par_priv *poid_par_priv)
313{ 314{
314 struct _adapter *Adapter = (struct _adapter *) 315 struct _adapter *Adapter = (struct _adapter *)
315 (poid_par_priv->adapter_context); 316 (poid_par_priv->adapter_context);
316 uint status = NDIS_STATUS_SUCCESS; 317 uint status = RNDIS_STATUS_SUCCESS;
317 318
318 if (poid_par_priv->type_of_oid != SET_OID) 319 if (poid_par_priv->type_of_oid != SET_OID)
319 return NDIS_STATUS_NOT_ACCEPTED; 320 return RNDIS_STATUS_NOT_ACCEPTED;
320 if (mp_stop_test(Adapter) == _FAIL) 321 if (mp_stop_test(Adapter) == _FAIL)
321 status = NDIS_STATUS_NOT_ACCEPTED; 322 status = RNDIS_STATUS_NOT_ACCEPTED;
322 return status; 323 return status;
323} 324}
324 325
@@ -327,16 +328,16 @@ uint oid_rt_pro_set_channel_direct_call_hdl(struct oid_par_priv
327{ 328{
328 struct _adapter *Adapter = (struct _adapter *) 329 struct _adapter *Adapter = (struct _adapter *)
329 (poid_par_priv->adapter_context); 330 (poid_par_priv->adapter_context);
330 uint status = NDIS_STATUS_SUCCESS; 331 uint status = RNDIS_STATUS_SUCCESS;
331 u32 Channel; 332 u32 Channel;
332 333
333 if (poid_par_priv->type_of_oid != SET_OID) 334 if (poid_par_priv->type_of_oid != SET_OID)
334 return NDIS_STATUS_NOT_ACCEPTED; 335 return RNDIS_STATUS_NOT_ACCEPTED;
335 if (poid_par_priv->information_buf_len != sizeof(u32)) 336 if (poid_par_priv->information_buf_len != sizeof(u32))
336 return NDIS_STATUS_INVALID_LENGTH; 337 return RNDIS_STATUS_INVALID_LENGTH;
337 Channel = *((u32 *)poid_par_priv->information_buf); 338 Channel = *((u32 *)poid_par_priv->information_buf);
338 if (Channel > 14) 339 if (Channel > 14)
339 return NDIS_STATUS_NOT_ACCEPTED; 340 return RNDIS_STATUS_NOT_ACCEPTED;
340 Adapter->mppriv.curr_ch = Channel; 341 Adapter->mppriv.curr_ch = Channel;
341 r8712_SetChannel(Adapter); 342 r8712_SetChannel(Adapter);
342 return status; 343 return status;
@@ -346,13 +347,13 @@ uint oid_rt_pro_set_antenna_bb_hdl(struct oid_par_priv *poid_par_priv)
346{ 347{
347 struct _adapter *Adapter = (struct _adapter *) 348 struct _adapter *Adapter = (struct _adapter *)
348 (poid_par_priv->adapter_context); 349 (poid_par_priv->adapter_context);
349 uint status = NDIS_STATUS_SUCCESS; 350 uint status = RNDIS_STATUS_SUCCESS;
350 u32 antenna; 351 u32 antenna;
351 352
352 if (poid_par_priv->type_of_oid != SET_OID) 353 if (poid_par_priv->type_of_oid != SET_OID)
353 return NDIS_STATUS_NOT_ACCEPTED; 354 return RNDIS_STATUS_NOT_ACCEPTED;
354 if (poid_par_priv->information_buf_len != sizeof(u32)) 355 if (poid_par_priv->information_buf_len != sizeof(u32))
355 return NDIS_STATUS_INVALID_LENGTH; 356 return RNDIS_STATUS_INVALID_LENGTH;
356 antenna = *((u32 *)poid_par_priv->information_buf); 357 antenna = *((u32 *)poid_par_priv->information_buf);
357 Adapter->mppriv.antenna_tx = (u16)((antenna & 0xFFFF0000) >> 16); 358 Adapter->mppriv.antenna_tx = (u16)((antenna & 0xFFFF0000) >> 16);
358 Adapter->mppriv.antenna_rx = (u16)(antenna & 0x0000FFFF); 359 Adapter->mppriv.antenna_rx = (u16)(antenna & 0x0000FFFF);
@@ -365,16 +366,16 @@ uint oid_rt_pro_set_tx_power_control_hdl(
365{ 366{
366 struct _adapter *Adapter = (struct _adapter *) 367 struct _adapter *Adapter = (struct _adapter *)
367 (poid_par_priv->adapter_context); 368 (poid_par_priv->adapter_context);
368 uint status = NDIS_STATUS_SUCCESS; 369 uint status = RNDIS_STATUS_SUCCESS;
369 u32 tx_pwr_idx; 370 u32 tx_pwr_idx;
370 371
371 if (poid_par_priv->type_of_oid != SET_OID) 372 if (poid_par_priv->type_of_oid != SET_OID)
372 return NDIS_STATUS_NOT_ACCEPTED; 373 return RNDIS_STATUS_NOT_ACCEPTED;
373 if (poid_par_priv->information_buf_len != sizeof(u32)) 374 if (poid_par_priv->information_buf_len != sizeof(u32))
374 return NDIS_STATUS_INVALID_LENGTH; 375 return RNDIS_STATUS_INVALID_LENGTH;
375 tx_pwr_idx = *((u32 *)poid_par_priv->information_buf); 376 tx_pwr_idx = *((u32 *)poid_par_priv->information_buf);
376 if (tx_pwr_idx > MAX_TX_PWR_INDEX_N_MODE) 377 if (tx_pwr_idx > MAX_TX_PWR_INDEX_N_MODE)
377 return NDIS_STATUS_NOT_ACCEPTED; 378 return RNDIS_STATUS_NOT_ACCEPTED;
378 Adapter->mppriv.curr_txpoweridx = (u8)tx_pwr_idx; 379 Adapter->mppriv.curr_txpoweridx = (u8)tx_pwr_idx;
379 r8712_SetTxPower(Adapter); 380 r8712_SetTxPower(Adapter);
380 return status; 381 return status;
@@ -383,12 +384,12 @@ uint oid_rt_pro_set_tx_power_control_hdl(
383uint oid_rt_pro_query_tx_packet_sent_hdl( 384uint oid_rt_pro_query_tx_packet_sent_hdl(
384 struct oid_par_priv *poid_par_priv) 385 struct oid_par_priv *poid_par_priv)
385{ 386{
386 uint status = NDIS_STATUS_SUCCESS; 387 uint status = RNDIS_STATUS_SUCCESS;
387 struct _adapter *Adapter = (struct _adapter *) 388 struct _adapter *Adapter = (struct _adapter *)
388 (poid_par_priv->adapter_context); 389 (poid_par_priv->adapter_context);
389 390
390 if (poid_par_priv->type_of_oid != QUERY_OID) { 391 if (poid_par_priv->type_of_oid != QUERY_OID) {
391 status = NDIS_STATUS_NOT_ACCEPTED; 392 status = RNDIS_STATUS_NOT_ACCEPTED;
392 return status; 393 return status;
393 } 394 }
394 if (poid_par_priv->information_buf_len == sizeof(u32)) { 395 if (poid_par_priv->information_buf_len == sizeof(u32)) {
@@ -396,19 +397,19 @@ uint oid_rt_pro_query_tx_packet_sent_hdl(
396 Adapter->mppriv.tx_pktcount; 397 Adapter->mppriv.tx_pktcount;
397 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 398 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
398 } else 399 } else
399 status = NDIS_STATUS_INVALID_LENGTH; 400 status = RNDIS_STATUS_INVALID_LENGTH;
400 return status; 401 return status;
401} 402}
402 403
403uint oid_rt_pro_query_rx_packet_received_hdl( 404uint oid_rt_pro_query_rx_packet_received_hdl(
404 struct oid_par_priv *poid_par_priv) 405 struct oid_par_priv *poid_par_priv)
405{ 406{
406 uint status = NDIS_STATUS_SUCCESS; 407 uint status = RNDIS_STATUS_SUCCESS;
407 struct _adapter *Adapter = (struct _adapter *) 408 struct _adapter *Adapter = (struct _adapter *)
408 (poid_par_priv->adapter_context); 409 (poid_par_priv->adapter_context);
409 410
410 if (poid_par_priv->type_of_oid != QUERY_OID) { 411 if (poid_par_priv->type_of_oid != QUERY_OID) {
411 status = NDIS_STATUS_NOT_ACCEPTED; 412 status = RNDIS_STATUS_NOT_ACCEPTED;
412 return status; 413 return status;
413 } 414 }
414 if (poid_par_priv->information_buf_len == sizeof(u32)) { 415 if (poid_par_priv->information_buf_len == sizeof(u32)) {
@@ -416,19 +417,19 @@ uint oid_rt_pro_query_rx_packet_received_hdl(
416 Adapter->mppriv.rx_pktcount; 417 Adapter->mppriv.rx_pktcount;
417 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 418 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
418 } else 419 } else
419 status = NDIS_STATUS_INVALID_LENGTH; 420 status = RNDIS_STATUS_INVALID_LENGTH;
420 return status; 421 return status;
421} 422}
422 423
423uint oid_rt_pro_query_rx_packet_crc32_error_hdl( 424uint oid_rt_pro_query_rx_packet_crc32_error_hdl(
424 struct oid_par_priv *poid_par_priv) 425 struct oid_par_priv *poid_par_priv)
425{ 426{
426 uint status = NDIS_STATUS_SUCCESS; 427 uint status = RNDIS_STATUS_SUCCESS;
427 struct _adapter *Adapter = (struct _adapter *) 428 struct _adapter *Adapter = (struct _adapter *)
428 (poid_par_priv->adapter_context); 429 (poid_par_priv->adapter_context);
429 430
430 if (poid_par_priv->type_of_oid != QUERY_OID) { 431 if (poid_par_priv->type_of_oid != QUERY_OID) {
431 status = NDIS_STATUS_NOT_ACCEPTED; 432 status = RNDIS_STATUS_NOT_ACCEPTED;
432 return status; 433 return status;
433 } 434 }
434 if (poid_par_priv->information_buf_len == sizeof(u32)) { 435 if (poid_par_priv->information_buf_len == sizeof(u32)) {
@@ -436,7 +437,7 @@ uint oid_rt_pro_query_rx_packet_crc32_error_hdl(
436 Adapter->mppriv.rx_crcerrpktcount; 437 Adapter->mppriv.rx_crcerrpktcount;
437 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 438 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
438 } else 439 } else
439 status = NDIS_STATUS_INVALID_LENGTH; 440 status = RNDIS_STATUS_INVALID_LENGTH;
440 return status; 441 return status;
441} 442}
442 443
@@ -447,25 +448,25 @@ uint oid_rt_pro_reset_tx_packet_sent_hdl(struct oid_par_priv
447 (poid_par_priv->adapter_context); 448 (poid_par_priv->adapter_context);
448 449
449 if (poid_par_priv->type_of_oid != SET_OID) 450 if (poid_par_priv->type_of_oid != SET_OID)
450 return NDIS_STATUS_NOT_ACCEPTED; 451 return RNDIS_STATUS_NOT_ACCEPTED;
451 Adapter->mppriv.tx_pktcount = 0; 452 Adapter->mppriv.tx_pktcount = 0;
452 return NDIS_STATUS_SUCCESS; 453 return RNDIS_STATUS_SUCCESS;
453} 454}
454 455
455uint oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv 456uint oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv
456 *poid_par_priv) 457 *poid_par_priv)
457{ 458{
458 uint status = NDIS_STATUS_SUCCESS; 459 uint status = RNDIS_STATUS_SUCCESS;
459 struct _adapter *Adapter = (struct _adapter *) 460 struct _adapter *Adapter = (struct _adapter *)
460 (poid_par_priv->adapter_context); 461 (poid_par_priv->adapter_context);
461 462
462 if (poid_par_priv->type_of_oid != SET_OID) 463 if (poid_par_priv->type_of_oid != SET_OID)
463 return NDIS_STATUS_NOT_ACCEPTED; 464 return RNDIS_STATUS_NOT_ACCEPTED;
464 if (poid_par_priv->information_buf_len == sizeof(u32)) { 465 if (poid_par_priv->information_buf_len == sizeof(u32)) {
465 Adapter->mppriv.rx_pktcount = 0; 466 Adapter->mppriv.rx_pktcount = 0;
466 Adapter->mppriv.rx_crcerrpktcount = 0; 467 Adapter->mppriv.rx_crcerrpktcount = 0;
467 } else 468 } else
468 status = NDIS_STATUS_INVALID_LENGTH; 469 status = RNDIS_STATUS_INVALID_LENGTH;
469 return status; 470 return status;
470} 471}
471 472
@@ -476,9 +477,9 @@ uint oid_rt_reset_phy_rx_packet_count_hdl(struct oid_par_priv
476 (poid_par_priv->adapter_context); 477 (poid_par_priv->adapter_context);
477 478
478 if (poid_par_priv->type_of_oid != SET_OID) 479 if (poid_par_priv->type_of_oid != SET_OID)
479 return NDIS_STATUS_NOT_ACCEPTED; 480 return RNDIS_STATUS_NOT_ACCEPTED;
480 r8712_ResetPhyRxPktCount(Adapter); 481 r8712_ResetPhyRxPktCount(Adapter);
481 return NDIS_STATUS_SUCCESS; 482 return RNDIS_STATUS_SUCCESS;
482} 483}
483 484
484uint oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv 485uint oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv
@@ -488,13 +489,13 @@ uint oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv
488 (poid_par_priv->adapter_context); 489 (poid_par_priv->adapter_context);
489 490
490 if (poid_par_priv->type_of_oid != QUERY_OID) 491 if (poid_par_priv->type_of_oid != QUERY_OID)
491 return NDIS_STATUS_NOT_ACCEPTED; 492 return RNDIS_STATUS_NOT_ACCEPTED;
492 if (poid_par_priv->information_buf_len != sizeof(u32)) 493 if (poid_par_priv->information_buf_len != sizeof(u32))
493 return NDIS_STATUS_INVALID_LENGTH; 494 return RNDIS_STATUS_INVALID_LENGTH;
494 *(u32 *)poid_par_priv->information_buf = 495 *(u32 *)poid_par_priv->information_buf =
495 r8712_GetPhyRxPktReceived(Adapter); 496 r8712_GetPhyRxPktReceived(Adapter);
496 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 497 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
497 return NDIS_STATUS_SUCCESS; 498 return RNDIS_STATUS_SUCCESS;
498} 499}
499 500
500uint oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv 501uint oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv
@@ -504,13 +505,13 @@ uint oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv
504 (poid_par_priv->adapter_context); 505 (poid_par_priv->adapter_context);
505 506
506 if (poid_par_priv->type_of_oid != QUERY_OID) 507 if (poid_par_priv->type_of_oid != QUERY_OID)
507 return NDIS_STATUS_NOT_ACCEPTED; 508 return RNDIS_STATUS_NOT_ACCEPTED;
508 if (poid_par_priv->information_buf_len != sizeof(u32)) 509 if (poid_par_priv->information_buf_len != sizeof(u32))
509 return NDIS_STATUS_INVALID_LENGTH; 510 return RNDIS_STATUS_INVALID_LENGTH;
510 *(u32 *)poid_par_priv->information_buf = 511 *(u32 *)poid_par_priv->information_buf =
511 r8712_GetPhyRxPktCRC32Error(Adapter); 512 r8712_GetPhyRxPktCRC32Error(Adapter);
512 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 513 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
513 return NDIS_STATUS_SUCCESS; 514 return RNDIS_STATUS_SUCCESS;
514} 515}
515 516
516uint oid_rt_pro_set_modulation_hdl(struct oid_par_priv 517uint oid_rt_pro_set_modulation_hdl(struct oid_par_priv
@@ -520,10 +521,10 @@ uint oid_rt_pro_set_modulation_hdl(struct oid_par_priv
520 (poid_par_priv->adapter_context); 521 (poid_par_priv->adapter_context);
521 522
522 if (poid_par_priv->type_of_oid != SET_OID) 523 if (poid_par_priv->type_of_oid != SET_OID)
523 return NDIS_STATUS_NOT_ACCEPTED; 524 return RNDIS_STATUS_NOT_ACCEPTED;
524 525
525 Adapter->mppriv.curr_modem = *((u8 *)poid_par_priv->information_buf); 526 Adapter->mppriv.curr_modem = *((u8 *)poid_par_priv->information_buf);
526 return NDIS_STATUS_SUCCESS; 527 return RNDIS_STATUS_SUCCESS;
527} 528}
528 529
529uint oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv 530uint oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv
@@ -534,10 +535,10 @@ uint oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv
534 u32 bStartTest; 535 u32 bStartTest;
535 536
536 if (poid_par_priv->type_of_oid != SET_OID) 537 if (poid_par_priv->type_of_oid != SET_OID)
537 return NDIS_STATUS_NOT_ACCEPTED; 538 return RNDIS_STATUS_NOT_ACCEPTED;
538 bStartTest = *((u32 *)poid_par_priv->information_buf); 539 bStartTest = *((u32 *)poid_par_priv->information_buf);
539 r8712_SetContinuousTx(Adapter, (u8)bStartTest); 540 r8712_SetContinuousTx(Adapter, (u8)bStartTest);
540 return NDIS_STATUS_SUCCESS; 541 return RNDIS_STATUS_SUCCESS;
541} 542}
542 543
543uint oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv 544uint oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv
@@ -548,10 +549,10 @@ uint oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv
548 u32 bStartTest; 549 u32 bStartTest;
549 550
550 if (poid_par_priv->type_of_oid != SET_OID) 551 if (poid_par_priv->type_of_oid != SET_OID)
551 return NDIS_STATUS_NOT_ACCEPTED; 552 return RNDIS_STATUS_NOT_ACCEPTED;
552 bStartTest = *((u32 *)poid_par_priv->information_buf); 553 bStartTest = *((u32 *)poid_par_priv->information_buf);
553 r8712_SetSingleCarrierTx(Adapter, (u8)bStartTest); 554 r8712_SetSingleCarrierTx(Adapter, (u8)bStartTest);
554 return NDIS_STATUS_SUCCESS; 555 return RNDIS_STATUS_SUCCESS;
555} 556}
556 557
557uint oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv 558uint oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv
@@ -562,10 +563,10 @@ uint oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv
562 u32 bStartTest; 563 u32 bStartTest;
563 564
564 if (poid_par_priv->type_of_oid != SET_OID) 565 if (poid_par_priv->type_of_oid != SET_OID)
565 return NDIS_STATUS_NOT_ACCEPTED; 566 return RNDIS_STATUS_NOT_ACCEPTED;
566 bStartTest = *((u32 *)poid_par_priv->information_buf); 567 bStartTest = *((u32 *)poid_par_priv->information_buf);
567 r8712_SetCarrierSuppressionTx(Adapter, (u8)bStartTest); 568 r8712_SetCarrierSuppressionTx(Adapter, (u8)bStartTest);
568 return NDIS_STATUS_SUCCESS; 569 return RNDIS_STATUS_SUCCESS;
569} 570}
570 571
571uint oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv 572uint oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv
@@ -576,28 +577,28 @@ uint oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv
576 u32 bStartTest; 577 u32 bStartTest;
577 578
578 if (poid_par_priv->type_of_oid != SET_OID) 579 if (poid_par_priv->type_of_oid != SET_OID)
579 return NDIS_STATUS_NOT_ACCEPTED; 580 return RNDIS_STATUS_NOT_ACCEPTED;
580 bStartTest = *((u32 *)poid_par_priv->information_buf); 581 bStartTest = *((u32 *)poid_par_priv->information_buf);
581 r8712_SetSingleToneTx(Adapter, (u8)bStartTest); 582 r8712_SetSingleToneTx(Adapter, (u8)bStartTest);
582 return NDIS_STATUS_SUCCESS; 583 return RNDIS_STATUS_SUCCESS;
583} 584}
584 585
585uint oid_rt_pro8711_join_bss_hdl(struct oid_par_priv *poid_par_priv) 586uint oid_rt_pro8711_join_bss_hdl(struct oid_par_priv *poid_par_priv)
586{ 587{
587 struct _adapter *Adapter = (struct _adapter *) 588 struct _adapter *Adapter = (struct _adapter *)
588 (poid_par_priv->adapter_context); 589 (poid_par_priv->adapter_context);
589 uint status = NDIS_STATUS_SUCCESS; 590 uint status = RNDIS_STATUS_SUCCESS;
590 struct ndis_802_11_ssid *pssid; 591 struct ndis_802_11_ssid *pssid;
591 592
592 if (poid_par_priv->type_of_oid != SET_OID) 593 if (poid_par_priv->type_of_oid != SET_OID)
593 return NDIS_STATUS_NOT_ACCEPTED; 594 return RNDIS_STATUS_NOT_ACCEPTED;
594 *poid_par_priv->bytes_needed = (u32)sizeof(struct ndis_802_11_ssid); 595 *poid_par_priv->bytes_needed = (u32)sizeof(struct ndis_802_11_ssid);
595 *poid_par_priv->bytes_rw = 0; 596 *poid_par_priv->bytes_rw = 0;
596 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) 597 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed)
597 return NDIS_STATUS_INVALID_LENGTH; 598 return RNDIS_STATUS_INVALID_LENGTH;
598 pssid = (struct ndis_802_11_ssid *)poid_par_priv->information_buf; 599 pssid = (struct ndis_802_11_ssid *)poid_par_priv->information_buf;
599 if (mp_start_joinbss(Adapter, pssid) == _FAIL) 600 if (mp_start_joinbss(Adapter, pssid) == _FAIL)
600 status = NDIS_STATUS_NOT_ACCEPTED; 601 status = RNDIS_STATUS_NOT_ACCEPTED;
601 *poid_par_priv->bytes_rw = sizeof(struct ndis_802_11_ssid); 602 *poid_par_priv->bytes_rw = sizeof(struct ndis_802_11_ssid);
602 return status; 603 return status;
603} 604}
@@ -607,12 +608,12 @@ uint oid_rt_pro_read_register_hdl(struct oid_par_priv
607{ 608{
608 struct _adapter *Adapter = (struct _adapter *) 609 struct _adapter *Adapter = (struct _adapter *)
609 (poid_par_priv->adapter_context); 610 (poid_par_priv->adapter_context);
610 uint status = NDIS_STATUS_SUCCESS; 611 uint status = RNDIS_STATUS_SUCCESS;
611 struct mp_rw_reg *RegRWStruct; 612 struct mp_rw_reg *RegRWStruct;
612 u16 offset; 613 u16 offset;
613 614
614 if (poid_par_priv->type_of_oid != QUERY_OID) 615 if (poid_par_priv->type_of_oid != QUERY_OID)
615 return NDIS_STATUS_NOT_ACCEPTED; 616 return RNDIS_STATUS_NOT_ACCEPTED;
616 RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf; 617 RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf;
617 if ((RegRWStruct->offset >= 0x10250800) && 618 if ((RegRWStruct->offset >= 0x10250800) &&
618 (RegRWStruct->offset <= 0x10250FFF)) { 619 (RegRWStruct->offset <= 0x10250FFF)) {
@@ -635,7 +636,7 @@ uint oid_rt_pro_read_register_hdl(struct oid_par_priv
635 RegRWStruct->offset); 636 RegRWStruct->offset);
636 break; 637 break;
637 default: 638 default:
638 status = NDIS_STATUS_NOT_ACCEPTED; 639 status = RNDIS_STATUS_NOT_ACCEPTED;
639 break; 640 break;
640 } 641 }
641 } 642 }
@@ -647,14 +648,14 @@ uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv)
647{ 648{
648 struct _adapter *Adapter = (struct _adapter *) 649 struct _adapter *Adapter = (struct _adapter *)
649 (poid_par_priv->adapter_context); 650 (poid_par_priv->adapter_context);
650 uint status = NDIS_STATUS_SUCCESS; 651 uint status = RNDIS_STATUS_SUCCESS;
651 struct mp_rw_reg *RegRWStruct; 652 struct mp_rw_reg *RegRWStruct;
652 u16 offset; 653 u16 offset;
653 u32 value; 654 u32 value;
654 u32 oldValue = 0; 655 u32 oldValue = 0;
655 656
656 if (poid_par_priv->type_of_oid != SET_OID) 657 if (poid_par_priv->type_of_oid != SET_OID)
657 return NDIS_STATUS_NOT_ACCEPTED; 658 return RNDIS_STATUS_NOT_ACCEPTED;
658 RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf; 659 RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf;
659 if ((RegRWStruct->offset >= 0x10250800) && 660 if ((RegRWStruct->offset >= 0x10250800) &&
660 (RegRWStruct->offset <= 0x10250FFF)) { 661 (RegRWStruct->offset <= 0x10250FFF)) {
@@ -691,11 +692,11 @@ uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv)
691 (unsigned int)RegRWStruct->value); 692 (unsigned int)RegRWStruct->value);
692 break; 693 break;
693 default: 694 default:
694 status = NDIS_STATUS_NOT_ACCEPTED; 695 status = RNDIS_STATUS_NOT_ACCEPTED;
695 break; 696 break;
696 } 697 }
697 698
698 if ((status == NDIS_STATUS_SUCCESS) && 699 if ((status == RNDIS_STATUS_SUCCESS) &&
699 (RegRWStruct->offset == HIMR) && 700 (RegRWStruct->offset == HIMR) &&
700 (RegRWStruct->width == 4)) 701 (RegRWStruct->width == 4))
701 Adapter->ImrContent = RegRWStruct->value; 702 Adapter->ImrContent = RegRWStruct->value;
@@ -711,12 +712,12 @@ uint oid_rt_pro_burst_read_register_hdl(struct oid_par_priv
711 struct burst_rw_reg *pBstRwReg; 712 struct burst_rw_reg *pBstRwReg;
712 713
713 if (poid_par_priv->type_of_oid != QUERY_OID) 714 if (poid_par_priv->type_of_oid != QUERY_OID)
714 return NDIS_STATUS_NOT_ACCEPTED; 715 return RNDIS_STATUS_NOT_ACCEPTED;
715 pBstRwReg = (struct burst_rw_reg *)poid_par_priv->information_buf; 716 pBstRwReg = (struct burst_rw_reg *)poid_par_priv->information_buf;
716 r8712_read_mem(Adapter, pBstRwReg->offset, (u32)pBstRwReg->len, 717 r8712_read_mem(Adapter, pBstRwReg->offset, (u32)pBstRwReg->len,
717 pBstRwReg->Data); 718 pBstRwReg->Data);
718 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 719 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
719 return NDIS_STATUS_SUCCESS; 720 return RNDIS_STATUS_SUCCESS;
720} 721}
721 722
722uint oid_rt_pro_burst_write_register_hdl(struct oid_par_priv 723uint oid_rt_pro_burst_write_register_hdl(struct oid_par_priv
@@ -727,16 +728,16 @@ uint oid_rt_pro_burst_write_register_hdl(struct oid_par_priv
727 struct burst_rw_reg *pBstRwReg; 728 struct burst_rw_reg *pBstRwReg;
728 729
729 if (poid_par_priv->type_of_oid != SET_OID) 730 if (poid_par_priv->type_of_oid != SET_OID)
730 return NDIS_STATUS_NOT_ACCEPTED; 731 return RNDIS_STATUS_NOT_ACCEPTED;
731 pBstRwReg = (struct burst_rw_reg *)poid_par_priv->information_buf; 732 pBstRwReg = (struct burst_rw_reg *)poid_par_priv->information_buf;
732 r8712_write_mem(Adapter, pBstRwReg->offset, (u32)pBstRwReg->len, 733 r8712_write_mem(Adapter, pBstRwReg->offset, (u32)pBstRwReg->len,
733 pBstRwReg->Data); 734 pBstRwReg->Data);
734 return NDIS_STATUS_SUCCESS; 735 return RNDIS_STATUS_SUCCESS;
735} 736}
736 737
737uint oid_rt_pro_write_txcmd_hdl(struct oid_par_priv *poid_par_priv) 738uint oid_rt_pro_write_txcmd_hdl(struct oid_par_priv *poid_par_priv)
738{ 739{
739 return NDIS_STATUS_SUCCESS; 740 return RNDIS_STATUS_SUCCESS;
740} 741}
741 742
742uint oid_rt_pro_read16_eeprom_hdl(struct oid_par_priv *poid_par_priv) 743uint oid_rt_pro_read16_eeprom_hdl(struct oid_par_priv *poid_par_priv)
@@ -746,12 +747,12 @@ uint oid_rt_pro_read16_eeprom_hdl(struct oid_par_priv *poid_par_priv)
746 struct eeprom_rw_param *pEEPROM; 747 struct eeprom_rw_param *pEEPROM;
747 748
748 if (poid_par_priv->type_of_oid != QUERY_OID) 749 if (poid_par_priv->type_of_oid != QUERY_OID)
749 return NDIS_STATUS_NOT_ACCEPTED; 750 return RNDIS_STATUS_NOT_ACCEPTED;
750 pEEPROM = (struct eeprom_rw_param *)poid_par_priv->information_buf; 751 pEEPROM = (struct eeprom_rw_param *)poid_par_priv->information_buf;
751 pEEPROM->value = r8712_eeprom_read16(Adapter, 752 pEEPROM->value = r8712_eeprom_read16(Adapter,
752 (u16)(pEEPROM->offset >> 1)); 753 (u16)(pEEPROM->offset >> 1));
753 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 754 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
754 return NDIS_STATUS_SUCCESS; 755 return RNDIS_STATUS_SUCCESS;
755} 756}
756 757
757uint oid_rt_pro_write16_eeprom_hdl(struct oid_par_priv *poid_par_priv) 758uint oid_rt_pro_write16_eeprom_hdl(struct oid_par_priv *poid_par_priv)
@@ -761,12 +762,12 @@ uint oid_rt_pro_write16_eeprom_hdl(struct oid_par_priv *poid_par_priv)
761 struct eeprom_rw_param *pEEPROM; 762 struct eeprom_rw_param *pEEPROM;
762 763
763 if (poid_par_priv->type_of_oid != SET_OID) 764 if (poid_par_priv->type_of_oid != SET_OID)
764 return NDIS_STATUS_NOT_ACCEPTED; 765 return RNDIS_STATUS_NOT_ACCEPTED;
765 pEEPROM = (struct eeprom_rw_param *)poid_par_priv->information_buf; 766 pEEPROM = (struct eeprom_rw_param *)poid_par_priv->information_buf;
766 r8712_eeprom_write16(Adapter, (u16)(pEEPROM->offset >> 1), 767 r8712_eeprom_write16(Adapter, (u16)(pEEPROM->offset >> 1),
767 pEEPROM->value); 768 pEEPROM->value);
768 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 769 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
769 return NDIS_STATUS_SUCCESS; 770 return RNDIS_STATUS_SUCCESS;
770} 771}
771 772
772uint oid_rt_pro8711_wi_poll_hdl(struct oid_par_priv *poid_par_priv) 773uint oid_rt_pro8711_wi_poll_hdl(struct oid_par_priv *poid_par_priv)
@@ -776,17 +777,17 @@ uint oid_rt_pro8711_wi_poll_hdl(struct oid_par_priv *poid_par_priv)
776 struct mp_wiparam *pwi_param; 777 struct mp_wiparam *pwi_param;
777 778
778 if (poid_par_priv->type_of_oid != QUERY_OID) 779 if (poid_par_priv->type_of_oid != QUERY_OID)
779 return NDIS_STATUS_NOT_ACCEPTED; 780 return RNDIS_STATUS_NOT_ACCEPTED;
780 if (poid_par_priv->information_buf_len < sizeof(struct mp_wiparam)) 781 if (poid_par_priv->information_buf_len < sizeof(struct mp_wiparam))
781 return NDIS_STATUS_INVALID_LENGTH; 782 return RNDIS_STATUS_INVALID_LENGTH;
782 if (Adapter->mppriv.workparam.bcompleted == false) 783 if (Adapter->mppriv.workparam.bcompleted == false)
783 return NDIS_STATUS_NOT_ACCEPTED; 784 return RNDIS_STATUS_NOT_ACCEPTED;
784 pwi_param = (struct mp_wiparam *)poid_par_priv->information_buf; 785 pwi_param = (struct mp_wiparam *)poid_par_priv->information_buf;
785 memcpy(pwi_param, &Adapter->mppriv.workparam, 786 memcpy(pwi_param, &Adapter->mppriv.workparam,
786 sizeof(struct mp_wiparam)); 787 sizeof(struct mp_wiparam));
787 Adapter->mppriv.act_in_progress = false; 788 Adapter->mppriv.act_in_progress = false;
788 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 789 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
789 return NDIS_STATUS_SUCCESS; 790 return RNDIS_STATUS_SUCCESS;
790} 791}
791 792
792uint oid_rt_pro8711_pkt_loss_hdl(struct oid_par_priv *poid_par_priv) 793uint oid_rt_pro8711_pkt_loss_hdl(struct oid_par_priv *poid_par_priv)
@@ -795,42 +796,42 @@ uint oid_rt_pro8711_pkt_loss_hdl(struct oid_par_priv *poid_par_priv)
795 (poid_par_priv->adapter_context); 796 (poid_par_priv->adapter_context);
796 797
797 if (poid_par_priv->type_of_oid != QUERY_OID) 798 if (poid_par_priv->type_of_oid != QUERY_OID)
798 return NDIS_STATUS_NOT_ACCEPTED; 799 return RNDIS_STATUS_NOT_ACCEPTED;
799 if (poid_par_priv->information_buf_len < sizeof(uint) * 2) 800 if (poid_par_priv->information_buf_len < sizeof(uint) * 2)
800 return NDIS_STATUS_INVALID_LENGTH; 801 return RNDIS_STATUS_INVALID_LENGTH;
801 if (*(uint *)poid_par_priv->information_buf == 1) 802 if (*(uint *)poid_par_priv->information_buf == 1)
802 Adapter->mppriv.rx_pktloss = 0; 803 Adapter->mppriv.rx_pktloss = 0;
803 *((uint *)poid_par_priv->information_buf+1) = 804 *((uint *)poid_par_priv->information_buf+1) =
804 Adapter->mppriv.rx_pktloss; 805 Adapter->mppriv.rx_pktloss;
805 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 806 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
806 return NDIS_STATUS_SUCCESS; 807 return RNDIS_STATUS_SUCCESS;
807} 808}
808 809
809uint oid_rt_rd_attrib_mem_hdl(struct oid_par_priv *poid_par_priv) 810uint oid_rt_rd_attrib_mem_hdl(struct oid_par_priv *poid_par_priv)
810{ 811{
811 if (poid_par_priv->type_of_oid != QUERY_OID) 812 if (poid_par_priv->type_of_oid != QUERY_OID)
812 return NDIS_STATUS_NOT_ACCEPTED; 813 return RNDIS_STATUS_NOT_ACCEPTED;
813 return NDIS_STATUS_SUCCESS; 814 return RNDIS_STATUS_SUCCESS;
814} 815}
815 816
816uint oid_rt_wr_attrib_mem_hdl(struct oid_par_priv *poid_par_priv) 817uint oid_rt_wr_attrib_mem_hdl(struct oid_par_priv *poid_par_priv)
817{ 818{
818 if (poid_par_priv->type_of_oid != SET_OID) 819 if (poid_par_priv->type_of_oid != SET_OID)
819 return NDIS_STATUS_NOT_ACCEPTED; 820 return RNDIS_STATUS_NOT_ACCEPTED;
820 return NDIS_STATUS_SUCCESS; 821 return RNDIS_STATUS_SUCCESS;
821} 822}
822 823
823uint oid_rt_pro_set_rf_intfs_hdl(struct oid_par_priv *poid_par_priv) 824uint oid_rt_pro_set_rf_intfs_hdl(struct oid_par_priv *poid_par_priv)
824{ 825{
825 struct _adapter *Adapter = (struct _adapter *) 826 struct _adapter *Adapter = (struct _adapter *)
826 (poid_par_priv->adapter_context); 827 (poid_par_priv->adapter_context);
827 uint status = NDIS_STATUS_SUCCESS; 828 uint status = RNDIS_STATUS_SUCCESS;
828 829
829 if (poid_par_priv->type_of_oid != SET_OID) 830 if (poid_par_priv->type_of_oid != SET_OID)
830 return NDIS_STATUS_NOT_ACCEPTED; 831 return RNDIS_STATUS_NOT_ACCEPTED;
831 if (r8712_setrfintfs_cmd(Adapter, *(unsigned char *) 832 if (r8712_setrfintfs_cmd(Adapter, *(unsigned char *)
832 poid_par_priv->information_buf) == _FAIL) 833 poid_par_priv->information_buf) == _FAIL)
833 status = NDIS_STATUS_NOT_ACCEPTED; 834 status = RNDIS_STATUS_NOT_ACCEPTED;
834 return status; 835 return status;
835} 836}
836 837
@@ -838,10 +839,10 @@ uint oid_rt_poll_rx_status_hdl(struct oid_par_priv *poid_par_priv)
838{ 839{
839 struct _adapter *Adapter = (struct _adapter *) 840 struct _adapter *Adapter = (struct _adapter *)
840 (poid_par_priv->adapter_context); 841 (poid_par_priv->adapter_context);
841 uint status = NDIS_STATUS_SUCCESS; 842 uint status = RNDIS_STATUS_SUCCESS;
842 843
843 if (poid_par_priv->type_of_oid != QUERY_OID) 844 if (poid_par_priv->type_of_oid != QUERY_OID)
844 return NDIS_STATUS_NOT_ACCEPTED; 845 return RNDIS_STATUS_NOT_ACCEPTED;
845 memcpy(poid_par_priv->information_buf, 846 memcpy(poid_par_priv->information_buf,
846 (unsigned char *)&Adapter->mppriv.rxstat, 847 (unsigned char *)&Adapter->mppriv.rxstat,
847 sizeof(struct recv_stat)); 848 sizeof(struct recv_stat));
@@ -852,7 +853,7 @@ uint oid_rt_poll_rx_status_hdl(struct oid_par_priv *poid_par_priv)
852uint oid_rt_pro_cfg_debug_message_hdl(struct oid_par_priv 853uint oid_rt_pro_cfg_debug_message_hdl(struct oid_par_priv
853 *poid_par_priv) 854 *poid_par_priv)
854{ 855{
855 return NDIS_STATUS_SUCCESS; 856 return RNDIS_STATUS_SUCCESS;
856} 857}
857 858
858uint oid_rt_pro_set_data_rate_ex_hdl(struct oid_par_priv 859uint oid_rt_pro_set_data_rate_ex_hdl(struct oid_par_priv
@@ -860,13 +861,13 @@ uint oid_rt_pro_set_data_rate_ex_hdl(struct oid_par_priv
860{ 861{
861 struct _adapter *Adapter = (struct _adapter *) 862 struct _adapter *Adapter = (struct _adapter *)
862 (poid_par_priv->adapter_context); 863 (poid_par_priv->adapter_context);
863 uint status = NDIS_STATUS_SUCCESS; 864 uint status = RNDIS_STATUS_SUCCESS;
864 865
865 if (poid_par_priv->type_of_oid != SET_OID) 866 if (poid_par_priv->type_of_oid != SET_OID)
866 return NDIS_STATUS_NOT_ACCEPTED; 867 return RNDIS_STATUS_NOT_ACCEPTED;
867 if (r8712_setdatarate_cmd(Adapter, 868 if (r8712_setdatarate_cmd(Adapter,
868 poid_par_priv->information_buf) != _SUCCESS) 869 poid_par_priv->information_buf) != _SUCCESS)
869 status = NDIS_STATUS_NOT_ACCEPTED; 870 status = RNDIS_STATUS_NOT_ACCEPTED;
870 return status; 871 return status;
871} 872}
872 873
@@ -874,16 +875,16 @@ uint oid_rt_get_thermal_meter_hdl(struct oid_par_priv *poid_par_priv)
874{ 875{
875 struct _adapter *Adapter = (struct _adapter *) 876 struct _adapter *Adapter = (struct _adapter *)
876 (poid_par_priv->adapter_context); 877 (poid_par_priv->adapter_context);
877 uint status = NDIS_STATUS_SUCCESS; 878 uint status = RNDIS_STATUS_SUCCESS;
878 879
879 if (poid_par_priv->type_of_oid != QUERY_OID) 880 if (poid_par_priv->type_of_oid != QUERY_OID)
880 return NDIS_STATUS_NOT_ACCEPTED; 881 return RNDIS_STATUS_NOT_ACCEPTED;
881 882
882 if (Adapter->mppriv.act_in_progress == true) 883 if (Adapter->mppriv.act_in_progress == true)
883 return NDIS_STATUS_NOT_ACCEPTED; 884 return RNDIS_STATUS_NOT_ACCEPTED;
884 885
885 if (poid_par_priv->information_buf_len < sizeof(u8)) 886 if (poid_par_priv->information_buf_len < sizeof(u8))
886 return NDIS_STATUS_INVALID_LENGTH; 887 return RNDIS_STATUS_INVALID_LENGTH;
887 /*init workparam*/ 888 /*init workparam*/
888 Adapter->mppriv.act_in_progress = true; 889 Adapter->mppriv.act_in_progress = true;
889 Adapter->mppriv.workparam.bcompleted = false; 890 Adapter->mppriv.workparam.bcompleted = false;
@@ -904,14 +905,14 @@ uint oid_rt_pro_set_power_tracking_hdl(struct oid_par_priv
904{ 905{
905 struct _adapter *Adapter = (struct _adapter *) 906 struct _adapter *Adapter = (struct _adapter *)
906 (poid_par_priv->adapter_context); 907 (poid_par_priv->adapter_context);
907 uint status = NDIS_STATUS_SUCCESS; 908 uint status = RNDIS_STATUS_SUCCESS;
908 909
909 if (poid_par_priv->type_of_oid != SET_OID) 910 if (poid_par_priv->type_of_oid != SET_OID)
910 return NDIS_STATUS_NOT_ACCEPTED; 911 return RNDIS_STATUS_NOT_ACCEPTED;
911 if (poid_par_priv->information_buf_len < sizeof(u8)) 912 if (poid_par_priv->information_buf_len < sizeof(u8))
912 return NDIS_STATUS_INVALID_LENGTH; 913 return RNDIS_STATUS_INVALID_LENGTH;
913 if (!r8712_setptm_cmd(Adapter, *((u8 *)poid_par_priv->information_buf))) 914 if (!r8712_setptm_cmd(Adapter, *((u8 *)poid_par_priv->information_buf)))
914 status = NDIS_STATUS_NOT_ACCEPTED; 915 status = RNDIS_STATUS_NOT_ACCEPTED;
915 return status; 916 return status;
916} 917}
917 918
@@ -920,13 +921,13 @@ uint oid_rt_pro_set_basic_rate_hdl(struct oid_par_priv *poid_par_priv)
920 struct _adapter *Adapter = (struct _adapter *) 921 struct _adapter *Adapter = (struct _adapter *)
921 (poid_par_priv->adapter_context); 922 (poid_par_priv->adapter_context);
922 u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff}; 923 u8 mpdatarate[NumRates] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0xff};
923 uint status = NDIS_STATUS_SUCCESS; 924 uint status = RNDIS_STATUS_SUCCESS;
924 u32 ratevalue; 925 u32 ratevalue;
925 u8 datarates[NumRates]; 926 u8 datarates[NumRates];
926 int i; 927 int i;
927 928
928 if (poid_par_priv->type_of_oid != SET_OID) 929 if (poid_par_priv->type_of_oid != SET_OID)
929 return NDIS_STATUS_NOT_ACCEPTED; 930 return RNDIS_STATUS_NOT_ACCEPTED;
930 ratevalue = *((u32 *)poid_par_priv->information_buf); 931 ratevalue = *((u32 *)poid_par_priv->information_buf);
931 for (i = 0; i < NumRates; i++) { 932 for (i = 0; i < NumRates; i++) {
932 if (ratevalue == mpdatarate[i]) 933 if (ratevalue == mpdatarate[i])
@@ -935,7 +936,7 @@ uint oid_rt_pro_set_basic_rate_hdl(struct oid_par_priv *poid_par_priv)
935 datarates[i] = 0xff; 936 datarates[i] = 0xff;
936 } 937 }
937 if (r8712_setbasicrate_cmd(Adapter, datarates) != _SUCCESS) 938 if (r8712_setbasicrate_cmd(Adapter, datarates) != _SUCCESS)
938 status = NDIS_STATUS_NOT_ACCEPTED; 939 status = RNDIS_STATUS_NOT_ACCEPTED;
939 return status; 940 return status;
940} 941}
941 942
@@ -945,14 +946,14 @@ uint oid_rt_pro_qry_pwrstate_hdl(struct oid_par_priv *poid_par_priv)
945 (poid_par_priv->adapter_context); 946 (poid_par_priv->adapter_context);
946 947
947 if (poid_par_priv->type_of_oid != QUERY_OID) 948 if (poid_par_priv->type_of_oid != QUERY_OID)
948 return NDIS_STATUS_NOT_ACCEPTED; 949 return RNDIS_STATUS_NOT_ACCEPTED;
949 if (poid_par_priv->information_buf_len < 8) 950 if (poid_par_priv->information_buf_len < 8)
950 return NDIS_STATUS_INVALID_LENGTH; 951 return RNDIS_STATUS_INVALID_LENGTH;
951 *poid_par_priv->bytes_rw = 8; 952 *poid_par_priv->bytes_rw = 8;
952 memcpy(poid_par_priv->information_buf, 953 memcpy(poid_par_priv->information_buf,
953 &(Adapter->pwrctrlpriv.pwr_mode), 8); 954 &(Adapter->pwrctrlpriv.pwr_mode), 8);
954 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 955 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
955 return NDIS_STATUS_SUCCESS; 956 return RNDIS_STATUS_SUCCESS;
956} 957}
957 958
958uint oid_rt_pro_set_pwrstate_hdl(struct oid_par_priv *poid_par_priv) 959uint oid_rt_pro_set_pwrstate_hdl(struct oid_par_priv *poid_par_priv)
@@ -962,18 +963,18 @@ uint oid_rt_pro_set_pwrstate_hdl(struct oid_par_priv *poid_par_priv)
962 uint pwr_mode, smart_ps; 963 uint pwr_mode, smart_ps;
963 964
964 if (poid_par_priv->type_of_oid != SET_OID) 965 if (poid_par_priv->type_of_oid != SET_OID)
965 return NDIS_STATUS_NOT_ACCEPTED; 966 return RNDIS_STATUS_NOT_ACCEPTED;
966 *poid_par_priv->bytes_rw = 0; 967 *poid_par_priv->bytes_rw = 0;
967 *poid_par_priv->bytes_needed = 8; 968 *poid_par_priv->bytes_needed = 8;
968 if (poid_par_priv->information_buf_len < 8) 969 if (poid_par_priv->information_buf_len < 8)
969 return NDIS_STATUS_INVALID_LENGTH; 970 return RNDIS_STATUS_INVALID_LENGTH;
970 pwr_mode = *(uint *)(poid_par_priv->information_buf); 971 pwr_mode = *(uint *)(poid_par_priv->information_buf);
971 smart_ps = *(uint *)((addr_t)poid_par_priv->information_buf + 4); 972 smart_ps = *(uint *)((addr_t)poid_par_priv->information_buf + 4);
972 if (pwr_mode != Adapter->pwrctrlpriv.pwr_mode || smart_ps != 973 if (pwr_mode != Adapter->pwrctrlpriv.pwr_mode || smart_ps !=
973 Adapter->pwrctrlpriv.smart_ps) 974 Adapter->pwrctrlpriv.smart_ps)
974 r8712_set_ps_mode(Adapter, pwr_mode, smart_ps); 975 r8712_set_ps_mode(Adapter, pwr_mode, smart_ps);
975 *poid_par_priv->bytes_rw = 8; 976 *poid_par_priv->bytes_rw = 8;
976 return NDIS_STATUS_SUCCESS; 977 return RNDIS_STATUS_SUCCESS;
977} 978}
978 979
979uint oid_rt_pro_h2c_set_rate_table_hdl(struct oid_par_priv 980uint oid_rt_pro_h2c_set_rate_table_hdl(struct oid_par_priv
@@ -981,20 +982,20 @@ uint oid_rt_pro_h2c_set_rate_table_hdl(struct oid_par_priv
981{ 982{
982 struct _adapter *Adapter = (struct _adapter *) 983 struct _adapter *Adapter = (struct _adapter *)
983 (poid_par_priv->adapter_context); 984 (poid_par_priv->adapter_context);
984 uint status = NDIS_STATUS_SUCCESS; 985 uint status = RNDIS_STATUS_SUCCESS;
985 struct setratable_parm *prate_table; 986 struct setratable_parm *prate_table;
986 u8 res; 987 u8 res;
987 988
988 if (poid_par_priv->type_of_oid != SET_OID) 989 if (poid_par_priv->type_of_oid != SET_OID)
989 return NDIS_STATUS_NOT_ACCEPTED; 990 return RNDIS_STATUS_NOT_ACCEPTED;
990 *poid_par_priv->bytes_needed = sizeof(struct setratable_parm); 991 *poid_par_priv->bytes_needed = sizeof(struct setratable_parm);
991 if (poid_par_priv->information_buf_len < 992 if (poid_par_priv->information_buf_len <
992 sizeof(struct setratable_parm)) 993 sizeof(struct setratable_parm))
993 return NDIS_STATUS_INVALID_LENGTH; 994 return RNDIS_STATUS_INVALID_LENGTH;
994 prate_table = (struct setratable_parm *)poid_par_priv->information_buf; 995 prate_table = (struct setratable_parm *)poid_par_priv->information_buf;
995 res = r8712_setrttbl_cmd(Adapter, prate_table); 996 res = r8712_setrttbl_cmd(Adapter, prate_table);
996 if (res == _FAIL) 997 if (res == _FAIL)
997 status = NDIS_STATUS_FAILURE; 998 status = RNDIS_STATUS_FAILURE;
998 return status; 999 return status;
999} 1000}
1000 1001
@@ -1002,8 +1003,8 @@ uint oid_rt_pro_h2c_get_rate_table_hdl(struct oid_par_priv
1002 *poid_par_priv) 1003 *poid_par_priv)
1003{ 1004{
1004 if (poid_par_priv->type_of_oid != QUERY_OID) 1005 if (poid_par_priv->type_of_oid != QUERY_OID)
1005 return NDIS_STATUS_NOT_ACCEPTED; 1006 return RNDIS_STATUS_NOT_ACCEPTED;
1006 return NDIS_STATUS_SUCCESS; 1007 return RNDIS_STATUS_SUCCESS;
1007} 1008}
1008 1009
1009uint oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv 1010uint oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv
@@ -1016,7 +1017,7 @@ uint oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv
1016 1017
1017 *poid_par_priv->bytes_needed = sizeof(u8); 1018 *poid_par_priv->bytes_needed = sizeof(u8);
1018 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) 1019 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed)
1019 return NDIS_STATUS_INVALID_LENGTH; 1020 return RNDIS_STATUS_INVALID_LENGTH;
1020 1021
1021 if (poid_par_priv->type_of_oid == SET_OID) { 1022 if (poid_par_priv->type_of_oid == SET_OID) {
1022 encry_mode = *((u8 *)poid_par_priv->information_buf); 1023 encry_mode = *((u8 *)poid_par_priv->information_buf);
@@ -1054,7 +1055,7 @@ uint oid_rt_pro_encryption_ctrl_hdl(struct oid_par_priv
1054 *(u8 *)poid_par_priv->information_buf = encry_mode; 1055 *(u8 *)poid_par_priv->information_buf = encry_mode;
1055 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 1056 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
1056 } 1057 }
1057 return NDIS_STATUS_SUCCESS; 1058 return RNDIS_STATUS_SUCCESS;
1058} 1059}
1059/*----------------------------------------------------------------------*/ 1060/*----------------------------------------------------------------------*/
1060uint oid_rt_pro_add_sta_info_hdl(struct oid_par_priv *poid_par_priv) 1061uint oid_rt_pro_add_sta_info_hdl(struct oid_par_priv *poid_par_priv)
@@ -1062,24 +1063,24 @@ uint oid_rt_pro_add_sta_info_hdl(struct oid_par_priv *poid_par_priv)
1062 struct _adapter *Adapter = (struct _adapter *) 1063 struct _adapter *Adapter = (struct _adapter *)
1063 (poid_par_priv->adapter_context); 1064 (poid_par_priv->adapter_context);
1064 1065
1065 uint status = NDIS_STATUS_SUCCESS; 1066 uint status = RNDIS_STATUS_SUCCESS;
1066 1067
1067 struct sta_info *psta = NULL; 1068 struct sta_info *psta = NULL;
1068 u8 *macaddr; 1069 u8 *macaddr;
1069 1070
1070 1071
1071 if (poid_par_priv->type_of_oid != SET_OID) 1072 if (poid_par_priv->type_of_oid != SET_OID)
1072 return NDIS_STATUS_NOT_ACCEPTED; 1073 return RNDIS_STATUS_NOT_ACCEPTED;
1073 1074
1074 *poid_par_priv->bytes_needed = ETH_ALEN; 1075 *poid_par_priv->bytes_needed = ETH_ALEN;
1075 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) 1076 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed)
1076 return NDIS_STATUS_INVALID_LENGTH; 1077 return RNDIS_STATUS_INVALID_LENGTH;
1077 macaddr = (u8 *) poid_par_priv->information_buf; 1078 macaddr = (u8 *) poid_par_priv->information_buf;
1078 psta = r8712_get_stainfo(&Adapter->stapriv, macaddr); 1079 psta = r8712_get_stainfo(&Adapter->stapriv, macaddr);
1079 if (psta == NULL) { /* the sta in sta_info_queue => do nothing*/ 1080 if (psta == NULL) { /* the sta in sta_info_queue => do nothing*/
1080 psta = r8712_alloc_stainfo(&Adapter->stapriv, macaddr); 1081 psta = r8712_alloc_stainfo(&Adapter->stapriv, macaddr);
1081 if (psta == NULL) 1082 if (psta == NULL)
1082 status = NDIS_STATUS_FAILURE; 1083 status = RNDIS_STATUS_FAILURE;
1083 } 1084 }
1084 return status; 1085 return status;
1085} 1086}
@@ -1090,18 +1091,18 @@ uint oid_rt_pro_dele_sta_info_hdl(struct oid_par_priv *poid_par_priv)
1090 (poid_par_priv->adapter_context); 1091 (poid_par_priv->adapter_context);
1091 1092
1092 unsigned long irqL; 1093 unsigned long irqL;
1093 uint status = NDIS_STATUS_SUCCESS; 1094 uint status = RNDIS_STATUS_SUCCESS;
1094 1095
1095 struct sta_info *psta = NULL; 1096 struct sta_info *psta = NULL;
1096 u8 *macaddr; 1097 u8 *macaddr;
1097 1098
1098 1099
1099 if (poid_par_priv->type_of_oid != SET_OID) 1100 if (poid_par_priv->type_of_oid != SET_OID)
1100 return NDIS_STATUS_NOT_ACCEPTED; 1101 return RNDIS_STATUS_NOT_ACCEPTED;
1101 1102
1102 *poid_par_priv->bytes_needed = ETH_ALEN; 1103 *poid_par_priv->bytes_needed = ETH_ALEN;
1103 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) 1104 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed)
1104 return NDIS_STATUS_INVALID_LENGTH; 1105 return RNDIS_STATUS_INVALID_LENGTH;
1105 1106
1106 macaddr = (u8 *)poid_par_priv->information_buf; 1107 macaddr = (u8 *)poid_par_priv->information_buf;
1107 1108
@@ -1125,15 +1126,15 @@ uint oid_rt_pro_query_dr_variable_hdl(struct oid_par_priv *poid_par_priv)
1125 struct _adapter *Adapter = (struct _adapter *) 1126 struct _adapter *Adapter = (struct _adapter *)
1126 (poid_par_priv->adapter_context); 1127 (poid_par_priv->adapter_context);
1127 1128
1128 uint status = NDIS_STATUS_SUCCESS; 1129 uint status = RNDIS_STATUS_SUCCESS;
1129 1130
1130 struct DR_VARIABLE_STRUCT *pdrv_var; 1131 struct DR_VARIABLE_STRUCT *pdrv_var;
1131 1132
1132 if (poid_par_priv->type_of_oid != QUERY_OID) 1133 if (poid_par_priv->type_of_oid != QUERY_OID)
1133 return NDIS_STATUS_NOT_ACCEPTED; 1134 return RNDIS_STATUS_NOT_ACCEPTED;
1134 *poid_par_priv->bytes_needed = sizeof(struct DR_VARIABLE_STRUCT); 1135 *poid_par_priv->bytes_needed = sizeof(struct DR_VARIABLE_STRUCT);
1135 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed) 1136 if (poid_par_priv->information_buf_len < *poid_par_priv->bytes_needed)
1136 return NDIS_STATUS_INVALID_LENGTH; 1137 return RNDIS_STATUS_INVALID_LENGTH;
1137 pdrv_var = (struct DR_VARIABLE_STRUCT *)poid_par_priv->information_buf; 1138 pdrv_var = (struct DR_VARIABLE_STRUCT *)poid_par_priv->information_buf;
1138 pdrv_var->variable = mp_query_drv_var(Adapter, pdrv_var->offset, 1139 pdrv_var->variable = mp_query_drv_var(Adapter, pdrv_var->offset,
1139 pdrv_var->variable); 1140 pdrv_var->variable);
@@ -1144,7 +1145,7 @@ uint oid_rt_pro_query_dr_variable_hdl(struct oid_par_priv *poid_par_priv)
1144/*--------------------------------------------------------------------------*/ 1145/*--------------------------------------------------------------------------*/
1145uint oid_rt_pro_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv) 1146uint oid_rt_pro_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv)
1146{ 1147{
1147 return NDIS_STATUS_SUCCESS; 1148 return RNDIS_STATUS_SUCCESS;
1148} 1149}
1149/*------------------------------------------------------------------------*/ 1150/*------------------------------------------------------------------------*/
1150uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv) 1151uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv)
@@ -1152,17 +1153,17 @@ uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv)
1152 struct _adapter *Adapter = (struct _adapter *) 1153 struct _adapter *Adapter = (struct _adapter *)
1153 (poid_par_priv->adapter_context); 1154 (poid_par_priv->adapter_context);
1154 1155
1155 uint status = NDIS_STATUS_SUCCESS; 1156 uint status = RNDIS_STATUS_SUCCESS;
1156 1157
1157 struct EFUSE_ACCESS_STRUCT *pefuse; 1158 struct EFUSE_ACCESS_STRUCT *pefuse;
1158 u8 *data; 1159 u8 *data;
1159 u16 addr = 0, cnts = 0; 1160 u16 addr = 0, cnts = 0;
1160 1161
1161 if (poid_par_priv->type_of_oid != QUERY_OID) 1162 if (poid_par_priv->type_of_oid != QUERY_OID)
1162 return NDIS_STATUS_NOT_ACCEPTED; 1163 return RNDIS_STATUS_NOT_ACCEPTED;
1163 if (poid_par_priv->information_buf_len < 1164 if (poid_par_priv->information_buf_len <
1164 sizeof(struct EFUSE_ACCESS_STRUCT)) 1165 sizeof(struct EFUSE_ACCESS_STRUCT))
1165 return NDIS_STATUS_INVALID_LENGTH; 1166 return RNDIS_STATUS_INVALID_LENGTH;
1166 pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf; 1167 pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf;
1167 addr = pefuse->start_addr; 1168 addr = pefuse->start_addr;
1168 cnts = pefuse->cnts; 1169 cnts = pefuse->cnts;
@@ -1170,9 +1171,9 @@ uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv)
1170 memset(data, 0xFF, cnts); 1171 memset(data, 0xFF, cnts);
1171 if ((addr > 511) || (cnts < 1) || (cnts > 512) || (addr + cnts) > 1172 if ((addr > 511) || (cnts < 1) || (cnts > 512) || (addr + cnts) >
1172 EFUSE_MAX_SIZE) 1173 EFUSE_MAX_SIZE)
1173 return NDIS_STATUS_NOT_ACCEPTED; 1174 return RNDIS_STATUS_NOT_ACCEPTED;
1174 if (r8712_efuse_access(Adapter, true, addr, cnts, data) == false) 1175 if (r8712_efuse_access(Adapter, true, addr, cnts, data) == false)
1175 status = NDIS_STATUS_FAILURE; 1176 status = RNDIS_STATUS_FAILURE;
1176 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 1177 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
1177 return status; 1178 return status;
1178} 1179}
@@ -1182,14 +1183,14 @@ uint oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv)
1182 struct _adapter *Adapter = (struct _adapter *) 1183 struct _adapter *Adapter = (struct _adapter *)
1183 (poid_par_priv->adapter_context); 1184 (poid_par_priv->adapter_context);
1184 1185
1185 uint status = NDIS_STATUS_SUCCESS; 1186 uint status = RNDIS_STATUS_SUCCESS;
1186 1187
1187 struct EFUSE_ACCESS_STRUCT *pefuse; 1188 struct EFUSE_ACCESS_STRUCT *pefuse;
1188 u8 *data; 1189 u8 *data;
1189 u16 addr = 0, cnts = 0; 1190 u16 addr = 0, cnts = 0;
1190 1191
1191 if (poid_par_priv->type_of_oid != SET_OID) 1192 if (poid_par_priv->type_of_oid != SET_OID)
1192 return NDIS_STATUS_NOT_ACCEPTED; 1193 return RNDIS_STATUS_NOT_ACCEPTED;
1193 1194
1194 pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf; 1195 pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf;
1195 addr = pefuse->start_addr; 1196 addr = pefuse->start_addr;
@@ -1198,9 +1199,9 @@ uint oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv)
1198 1199
1199 if ((addr > 511) || (cnts < 1) || (cnts > 512) || 1200 if ((addr > 511) || (cnts < 1) || (cnts > 512) ||
1200 (addr + cnts) > r8712_efuse_get_max_size(Adapter)) 1201 (addr + cnts) > r8712_efuse_get_max_size(Adapter))
1201 return NDIS_STATUS_NOT_ACCEPTED; 1202 return RNDIS_STATUS_NOT_ACCEPTED;
1202 if (r8712_efuse_access(Adapter, false, addr, cnts, data) == false) 1203 if (r8712_efuse_access(Adapter, false, addr, cnts, data) == false)
1203 status = NDIS_STATUS_FAILURE; 1204 status = RNDIS_STATUS_FAILURE;
1204 return status; 1205 return status;
1205} 1206}
1206/*----------------------------------------------------------------------*/ 1207/*----------------------------------------------------------------------*/
@@ -1208,12 +1209,12 @@ uint oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv)
1208{ 1209{
1209 struct _adapter *Adapter = (struct _adapter *) 1210 struct _adapter *Adapter = (struct _adapter *)
1210 (poid_par_priv->adapter_context); 1211 (poid_par_priv->adapter_context);
1211 uint status = NDIS_STATUS_SUCCESS; 1212 uint status = RNDIS_STATUS_SUCCESS;
1212 struct PGPKT_STRUCT *ppgpkt; 1213 struct PGPKT_STRUCT *ppgpkt;
1213 1214
1214 *poid_par_priv->bytes_rw = 0; 1215 *poid_par_priv->bytes_rw = 0;
1215 if (poid_par_priv->information_buf_len < sizeof(struct PGPKT_STRUCT)) 1216 if (poid_par_priv->information_buf_len < sizeof(struct PGPKT_STRUCT))
1216 return NDIS_STATUS_INVALID_LENGTH; 1217 return RNDIS_STATUS_INVALID_LENGTH;
1217 ppgpkt = (struct PGPKT_STRUCT *)poid_par_priv->information_buf; 1218 ppgpkt = (struct PGPKT_STRUCT *)poid_par_priv->information_buf;
1218 if (poid_par_priv->type_of_oid == QUERY_OID) { 1219 if (poid_par_priv->type_of_oid == QUERY_OID) {
1219 if (r8712_efuse_pg_packet_read(Adapter, ppgpkt->offset, 1220 if (r8712_efuse_pg_packet_read(Adapter, ppgpkt->offset,
@@ -1221,7 +1222,7 @@ uint oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv)
1221 *poid_par_priv->bytes_rw = 1222 *poid_par_priv->bytes_rw =
1222 poid_par_priv->information_buf_len; 1223 poid_par_priv->information_buf_len;
1223 else 1224 else
1224 status = NDIS_STATUS_FAILURE; 1225 status = RNDIS_STATUS_FAILURE;
1225 } else { 1226 } else {
1226 if (r8712_efuse_reg_init(Adapter) == true) { 1227 if (r8712_efuse_reg_init(Adapter) == true) {
1227 if (r8712_efuse_pg_packet_write(Adapter, ppgpkt->offset, 1228 if (r8712_efuse_pg_packet_write(Adapter, ppgpkt->offset,
@@ -1229,10 +1230,10 @@ uint oid_rt_pro_rw_efuse_pgpkt_hdl(struct oid_par_priv *poid_par_priv)
1229 *poid_par_priv->bytes_rw = 1230 *poid_par_priv->bytes_rw =
1230 poid_par_priv->information_buf_len; 1231 poid_par_priv->information_buf_len;
1231 else 1232 else
1232 status = NDIS_STATUS_FAILURE; 1233 status = RNDIS_STATUS_FAILURE;
1233 r8712_efuse_reg_uninit(Adapter); 1234 r8712_efuse_reg_uninit(Adapter);
1234 } else 1235 } else
1235 status = NDIS_STATUS_FAILURE; 1236 status = RNDIS_STATUS_FAILURE;
1236 } 1237 }
1237 return status; 1238 return status;
1238} 1239}
@@ -1242,12 +1243,12 @@ uint oid_rt_get_efuse_current_size_hdl(struct oid_par_priv
1242{ 1243{
1243 struct _adapter *Adapter = (struct _adapter *) 1244 struct _adapter *Adapter = (struct _adapter *)
1244 (poid_par_priv->adapter_context); 1245 (poid_par_priv->adapter_context);
1245 uint status = NDIS_STATUS_SUCCESS; 1246 uint status = RNDIS_STATUS_SUCCESS;
1246 1247
1247 if (poid_par_priv->type_of_oid != QUERY_OID) 1248 if (poid_par_priv->type_of_oid != QUERY_OID)
1248 return NDIS_STATUS_NOT_ACCEPTED; 1249 return RNDIS_STATUS_NOT_ACCEPTED;
1249 if (poid_par_priv->information_buf_len < sizeof(int)) 1250 if (poid_par_priv->information_buf_len < sizeof(int))
1250 return NDIS_STATUS_INVALID_LENGTH; 1251 return RNDIS_STATUS_INVALID_LENGTH;
1251 r8712_efuse_reg_init(Adapter); 1252 r8712_efuse_reg_init(Adapter);
1252 *(int *)poid_par_priv->information_buf = 1253 *(int *)poid_par_priv->information_buf =
1253 r8712_efuse_get_current_size(Adapter); 1254 r8712_efuse_get_current_size(Adapter);
@@ -1260,12 +1261,12 @@ uint oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv)
1260{ 1261{
1261 struct _adapter *Adapter = (struct _adapter *) 1262 struct _adapter *Adapter = (struct _adapter *)
1262 (poid_par_priv->adapter_context); 1263 (poid_par_priv->adapter_context);
1263 uint status = NDIS_STATUS_SUCCESS; 1264 uint status = RNDIS_STATUS_SUCCESS;
1264 1265
1265 if (poid_par_priv->type_of_oid != QUERY_OID) 1266 if (poid_par_priv->type_of_oid != QUERY_OID)
1266 return NDIS_STATUS_NOT_ACCEPTED; 1267 return RNDIS_STATUS_NOT_ACCEPTED;
1267 if (poid_par_priv->information_buf_len < sizeof(u32)) 1268 if (poid_par_priv->information_buf_len < sizeof(u32))
1268 return NDIS_STATUS_INVALID_LENGTH; 1269 return RNDIS_STATUS_INVALID_LENGTH;
1269 *(int *)poid_par_priv->information_buf = 1270 *(int *)poid_par_priv->information_buf =
1270 r8712_efuse_get_max_size(Adapter); 1271 r8712_efuse_get_max_size(Adapter);
1271 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 1272 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
@@ -1274,7 +1275,7 @@ uint oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv)
1274 1275
1275uint oid_rt_pro_efuse_hdl(struct oid_par_priv *poid_par_priv) 1276uint oid_rt_pro_efuse_hdl(struct oid_par_priv *poid_par_priv)
1276{ 1277{
1277 uint status = NDIS_STATUS_SUCCESS; 1278 uint status = RNDIS_STATUS_SUCCESS;
1278 1279
1279 if (poid_par_priv->type_of_oid == QUERY_OID) 1280 if (poid_par_priv->type_of_oid == QUERY_OID)
1280 status = oid_rt_pro_read_efuse_hdl(poid_par_priv); 1281 status = oid_rt_pro_read_efuse_hdl(poid_par_priv);
@@ -1287,18 +1288,18 @@ uint oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv)
1287{ 1288{
1288 struct _adapter *Adapter = (struct _adapter *) 1289 struct _adapter *Adapter = (struct _adapter *)
1289 (poid_par_priv->adapter_context); 1290 (poid_par_priv->adapter_context);
1290 uint status = NDIS_STATUS_SUCCESS; 1291 uint status = RNDIS_STATUS_SUCCESS;
1291 u8 *data; 1292 u8 *data;
1292 1293
1293 *poid_par_priv->bytes_rw = 0; 1294 *poid_par_priv->bytes_rw = 0;
1294 if (poid_par_priv->information_buf_len < EFUSE_MAP_MAX_SIZE) 1295 if (poid_par_priv->information_buf_len < EFUSE_MAP_MAX_SIZE)
1295 return NDIS_STATUS_INVALID_LENGTH; 1296 return RNDIS_STATUS_INVALID_LENGTH;
1296 data = (u8 *)poid_par_priv->information_buf; 1297 data = (u8 *)poid_par_priv->information_buf;
1297 if (poid_par_priv->type_of_oid == QUERY_OID) { 1298 if (poid_par_priv->type_of_oid == QUERY_OID) {
1298 if (r8712_efuse_map_read(Adapter, 0, EFUSE_MAP_MAX_SIZE, data)) 1299 if (r8712_efuse_map_read(Adapter, 0, EFUSE_MAP_MAX_SIZE, data))
1299 *poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE; 1300 *poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE;
1300 else 1301 else
1301 status = NDIS_STATUS_FAILURE; 1302 status = RNDIS_STATUS_FAILURE;
1302 } else { 1303 } else {
1303 /* SET_OID */ 1304 /* SET_OID */
1304 if (r8712_efuse_reg_init(Adapter) == true) { 1305 if (r8712_efuse_reg_init(Adapter) == true) {
@@ -1306,10 +1307,10 @@ uint oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv)
1306 EFUSE_MAP_MAX_SIZE, data)) 1307 EFUSE_MAP_MAX_SIZE, data))
1307 *poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE; 1308 *poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE;
1308 else 1309 else
1309 status = NDIS_STATUS_FAILURE; 1310 status = RNDIS_STATUS_FAILURE;
1310 r8712_efuse_reg_uninit(Adapter); 1311 r8712_efuse_reg_uninit(Adapter);
1311 } else { 1312 } else {
1312 status = NDIS_STATUS_FAILURE; 1313 status = RNDIS_STATUS_FAILURE;
1313 } 1314 }
1314 } 1315 }
1315 return status; 1316 return status;
@@ -1319,13 +1320,13 @@ uint oid_rt_set_bandwidth_hdl(struct oid_par_priv *poid_par_priv)
1319{ 1320{
1320 struct _adapter *Adapter = (struct _adapter *) 1321 struct _adapter *Adapter = (struct _adapter *)
1321 (poid_par_priv->adapter_context); 1322 (poid_par_priv->adapter_context);
1322 uint status = NDIS_STATUS_SUCCESS; 1323 uint status = RNDIS_STATUS_SUCCESS;
1323 u32 bandwidth; 1324 u32 bandwidth;
1324 1325
1325 if (poid_par_priv->type_of_oid != SET_OID) 1326 if (poid_par_priv->type_of_oid != SET_OID)
1326 return NDIS_STATUS_NOT_ACCEPTED; 1327 return RNDIS_STATUS_NOT_ACCEPTED;
1327 if (poid_par_priv->information_buf_len < sizeof(u32)) 1328 if (poid_par_priv->information_buf_len < sizeof(u32))
1328 return NDIS_STATUS_INVALID_LENGTH; 1329 return RNDIS_STATUS_INVALID_LENGTH;
1329 bandwidth = *((u32 *)poid_par_priv->information_buf);/*4*/ 1330 bandwidth = *((u32 *)poid_par_priv->information_buf);/*4*/
1330 if (bandwidth != HT_CHANNEL_WIDTH_20) 1331 if (bandwidth != HT_CHANNEL_WIDTH_20)
1331 bandwidth = HT_CHANNEL_WIDTH_40; 1332 bandwidth = HT_CHANNEL_WIDTH_40;
@@ -1338,16 +1339,16 @@ uint oid_rt_set_crystal_cap_hdl(struct oid_par_priv *poid_par_priv)
1338{ 1339{
1339 struct _adapter *Adapter = (struct _adapter *) 1340 struct _adapter *Adapter = (struct _adapter *)
1340 (poid_par_priv->adapter_context); 1341 (poid_par_priv->adapter_context);
1341 uint status = NDIS_STATUS_SUCCESS; 1342 uint status = RNDIS_STATUS_SUCCESS;
1342 u32 crystal_cap = 0; 1343 u32 crystal_cap = 0;
1343 1344
1344 if (poid_par_priv->type_of_oid != SET_OID) 1345 if (poid_par_priv->type_of_oid != SET_OID)
1345 return NDIS_STATUS_NOT_ACCEPTED; 1346 return RNDIS_STATUS_NOT_ACCEPTED;
1346 if (poid_par_priv->information_buf_len < sizeof(u32)) 1347 if (poid_par_priv->information_buf_len < sizeof(u32))
1347 return NDIS_STATUS_INVALID_LENGTH; 1348 return RNDIS_STATUS_INVALID_LENGTH;
1348 crystal_cap = *((u32 *)poid_par_priv->information_buf);/*4*/ 1349 crystal_cap = *((u32 *)poid_par_priv->information_buf);/*4*/
1349 if (crystal_cap > 0xf) 1350 if (crystal_cap > 0xf)
1350 return NDIS_STATUS_NOT_ACCEPTED; 1351 return RNDIS_STATUS_NOT_ACCEPTED;
1351 Adapter->mppriv.curr_crystalcap = crystal_cap; 1352 Adapter->mppriv.curr_crystalcap = crystal_cap;
1352 r8712_SetCrystalCap(Adapter); 1353 r8712_SetCrystalCap(Adapter);
1353 return status; 1354 return status;
@@ -1362,9 +1363,9 @@ uint oid_rt_set_rx_packet_type_hdl(struct oid_par_priv
1362 u32 rcr_val32; 1363 u32 rcr_val32;
1363 1364
1364 if (poid_par_priv->type_of_oid != SET_OID) 1365 if (poid_par_priv->type_of_oid != SET_OID)
1365 return NDIS_STATUS_NOT_ACCEPTED; 1366 return RNDIS_STATUS_NOT_ACCEPTED;
1366 if (poid_par_priv->information_buf_len < sizeof(u8)) 1367 if (poid_par_priv->information_buf_len < sizeof(u8))
1367 return NDIS_STATUS_INVALID_LENGTH; 1368 return RNDIS_STATUS_INVALID_LENGTH;
1368 rx_pkt_type = *((u8 *)poid_par_priv->information_buf);/*4*/ 1369 rx_pkt_type = *((u8 *)poid_par_priv->information_buf);/*4*/
1369 rcr_val32 = r8712_read32(Adapter, RCR);/*RCR = 0x10250048*/ 1370 rcr_val32 = r8712_read32(Adapter, RCR);/*RCR = 0x10250048*/
1370 rcr_val32 &= ~(RCR_CBSSID | RCR_AB | RCR_AM | RCR_APM | RCR_AAP); 1371 rcr_val32 &= ~(RCR_CBSSID | RCR_AB | RCR_AM | RCR_APM | RCR_AAP);
@@ -1391,7 +1392,7 @@ uint oid_rt_set_rx_packet_type_hdl(struct oid_par_priv
1391 else 1392 else
1392 Adapter->mppriv.check_mp_pkt = 0; 1393 Adapter->mppriv.check_mp_pkt = 0;
1393 r8712_write32(Adapter, RCR, rcr_val32); 1394 r8712_write32(Adapter, RCR, rcr_val32);
1394 return NDIS_STATUS_SUCCESS; 1395 return RNDIS_STATUS_SUCCESS;
1395} 1396}
1396 1397
1397uint oid_rt_pro_set_tx_agc_offset_hdl(struct oid_par_priv 1398uint oid_rt_pro_set_tx_agc_offset_hdl(struct oid_par_priv
@@ -1402,12 +1403,12 @@ uint oid_rt_pro_set_tx_agc_offset_hdl(struct oid_par_priv
1402 u32 txagc; 1403 u32 txagc;
1403 1404
1404 if (poid_par_priv->type_of_oid != SET_OID) 1405 if (poid_par_priv->type_of_oid != SET_OID)
1405 return NDIS_STATUS_NOT_ACCEPTED; 1406 return RNDIS_STATUS_NOT_ACCEPTED;
1406 if (poid_par_priv->information_buf_len < sizeof(u32)) 1407 if (poid_par_priv->information_buf_len < sizeof(u32))
1407 return NDIS_STATUS_INVALID_LENGTH; 1408 return RNDIS_STATUS_INVALID_LENGTH;
1408 txagc = *(u32 *)poid_par_priv->information_buf; 1409 txagc = *(u32 *)poid_par_priv->information_buf;
1409 r8712_SetTxAGCOffset(Adapter, txagc); 1410 r8712_SetTxAGCOffset(Adapter, txagc);
1410 return NDIS_STATUS_SUCCESS; 1411 return RNDIS_STATUS_SUCCESS;
1411} 1412}
1412 1413
1413uint oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv 1414uint oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv
@@ -1415,16 +1416,16 @@ uint oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv
1415{ 1416{
1416 struct _adapter *Adapter = (struct _adapter *) 1417 struct _adapter *Adapter = (struct _adapter *)
1417 (poid_par_priv->adapter_context); 1418 (poid_par_priv->adapter_context);
1418 uint status = NDIS_STATUS_SUCCESS; 1419 uint status = RNDIS_STATUS_SUCCESS;
1419 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; 1420 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
1420 struct mp_priv *pmppriv = &Adapter->mppriv; 1421 struct mp_priv *pmppriv = &Adapter->mppriv;
1421 u32 type; 1422 u32 type;
1422 1423
1423 if (poid_par_priv->type_of_oid != SET_OID) 1424 if (poid_par_priv->type_of_oid != SET_OID)
1424 return NDIS_STATUS_NOT_ACCEPTED; 1425 return RNDIS_STATUS_NOT_ACCEPTED;
1425 1426
1426 if (poid_par_priv->information_buf_len < sizeof(u32)) 1427 if (poid_par_priv->information_buf_len < sizeof(u32))
1427 return NDIS_STATUS_INVALID_LENGTH; 1428 return RNDIS_STATUS_INVALID_LENGTH;
1428 1429
1429 type = *(u32 *)poid_par_priv->information_buf; 1430 type = *(u32 *)poid_par_priv->information_buf;
1430 1431
@@ -1435,7 +1436,7 @@ uint oid_rt_pro_set_pkt_test_mode_hdl(struct oid_par_priv
1435 pmppriv->mode = type; 1436 pmppriv->mode = type;
1436 _clr_fwstate_(pmlmepriv, WIFI_MP_LPBK_STATE); 1437 _clr_fwstate_(pmlmepriv, WIFI_MP_LPBK_STATE);
1437 } else 1438 } else
1438 status = NDIS_STATUS_NOT_ACCEPTED; 1439 status = RNDIS_STATUS_NOT_ACCEPTED;
1439 return status; 1440 return status;
1440} 1441}
1441/*--------------------------------------------------------------------------*/ 1442/*--------------------------------------------------------------------------*/
@@ -1450,10 +1451,10 @@ uint oid_rt_set_power_down_hdl(struct oid_par_priv *poid_par_priv)
1450 u8 bpwrup; 1451 u8 bpwrup;
1451 1452
1452 if (poid_par_priv->type_of_oid != SET_OID) 1453 if (poid_par_priv->type_of_oid != SET_OID)
1453 return NDIS_STATUS_NOT_ACCEPTED; 1454 return RNDIS_STATUS_NOT_ACCEPTED;
1454 bpwrup = *(u8 *)poid_par_priv->information_buf; 1455 bpwrup = *(u8 *)poid_par_priv->information_buf;
1455 /*CALL the power_down function*/ 1456 /*CALL the power_down function*/
1456 return NDIS_STATUS_SUCCESS; 1457 return RNDIS_STATUS_SUCCESS;
1457} 1458}
1458 1459
1459/*-------------------------------------------------------------------------- */ 1460/*-------------------------------------------------------------------------- */
@@ -1463,11 +1464,11 @@ uint oid_rt_get_power_mode_hdl(struct oid_par_priv *poid_par_priv)
1463 (poid_par_priv->adapter_context); 1464 (poid_par_priv->adapter_context);
1464 1465
1465 if (poid_par_priv->type_of_oid != QUERY_OID) 1466 if (poid_par_priv->type_of_oid != QUERY_OID)
1466 return NDIS_STATUS_NOT_ACCEPTED; 1467 return RNDIS_STATUS_NOT_ACCEPTED;
1467 if (poid_par_priv->information_buf_len < sizeof(u32)) 1468 if (poid_par_priv->information_buf_len < sizeof(u32))
1468 return NDIS_STATUS_INVALID_LENGTH; 1469 return RNDIS_STATUS_INVALID_LENGTH;
1469 *(int *)poid_par_priv->information_buf = 1470 *(int *)poid_par_priv->information_buf =
1470 Adapter->registrypriv.low_power ? POWER_LOW : POWER_NORMAL; 1471 Adapter->registrypriv.low_power ? POWER_LOW : POWER_NORMAL;
1471 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len; 1472 *poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
1472 return NDIS_STATUS_SUCCESS; 1473 return RNDIS_STATUS_SUCCESS;
1473} 1474}
diff --git a/drivers/staging/rtl8712/rtl871x_security.h b/drivers/staging/rtl8712/rtl871x_security.h
index a13395fe21d7..c732aeab8d2c 100644
--- a/drivers/staging/rtl8712/rtl871x_security.h
+++ b/drivers/staging/rtl8712/rtl871x_security.h
@@ -207,9 +207,9 @@ void seccalctkipmic(
207 u8 *Miccode, 207 u8 *Miccode,
208 u8 priority); 208 u8 priority);
209 209
210void r8712_secmicsetkey(struct mic_data *pmicdata, u8 * key); 210void r8712_secmicsetkey(struct mic_data *pmicdata, u8 *key);
211void r8712_secmicappend(struct mic_data *pmicdata, u8 * src, u32 nBytes); 211void r8712_secmicappend(struct mic_data *pmicdata, u8 *src, u32 nBytes);
212void r8712_secgetmic(struct mic_data *pmicdata, u8 * dst); 212void r8712_secgetmic(struct mic_data *pmicdata, u8 *dst);
213u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe); 213u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe);
214u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe); 214u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe);
215void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe); 215void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe);
diff --git a/drivers/staging/rtl8712/sta_info.h b/drivers/staging/rtl8712/sta_info.h
index f8016e9abffd..c4e0ef2f52c6 100644
--- a/drivers/staging/rtl8712/sta_info.h
+++ b/drivers/staging/rtl8712/sta_info.h
@@ -140,7 +140,7 @@ void r8712_free_all_stainfo(struct _adapter *padapter);
140struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr); 140struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr);
141void r8712_init_bcmc_stainfo(struct _adapter *padapter); 141void r8712_init_bcmc_stainfo(struct _adapter *padapter);
142struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter); 142struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter);
143u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 * mac_addr); 143u8 r8712_access_ctrl(struct wlan_acl_pool *pacl_list, u8 *mac_addr);
144 144
145#endif /* _STA_INFO_H_ */ 145#endif /* _STA_INFO_H_ */
146 146
diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c
index a96cd06d69dd..c812d6c7dc31 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -205,9 +205,9 @@ static int r871x_suspend(struct usb_interface *pusb_intf, pm_message_t state)
205{ 205{
206 struct net_device *pnetdev = usb_get_intfdata(pusb_intf); 206 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
207 207
208 printk(KERN_INFO "r8712: suspending...\n"); 208 netdev_info(pnetdev, "Suspending...\n");
209 if (!pnetdev || !netif_running(pnetdev)) { 209 if (!pnetdev || !netif_running(pnetdev)) {
210 printk(KERN_INFO "r8712: unable to suspend\n"); 210 netdev_info(pnetdev, "Unable to suspend\n");
211 return 0; 211 return 0;
212 } 212 }
213 if (pnetdev->netdev_ops->ndo_stop) 213 if (pnetdev->netdev_ops->ndo_stop)
@@ -221,9 +221,9 @@ static int r871x_resume(struct usb_interface *pusb_intf)
221{ 221{
222 struct net_device *pnetdev = usb_get_intfdata(pusb_intf); 222 struct net_device *pnetdev = usb_get_intfdata(pusb_intf);
223 223
224 printk(KERN_INFO "r8712: resuming...\n"); 224 netdev_info(pnetdev, "Resuming...\n");
225 if (!pnetdev || !netif_running(pnetdev)) { 225 if (!pnetdev || !netif_running(pnetdev)) {
226 printk(KERN_INFO "r8712: unable to resume\n"); 226 netdev_info(pnetdev, "Unable to resume\n");
227 return 0; 227 return 0;
228 } 228 }
229 netif_device_attach(pnetdev); 229 netif_device_attach(pnetdev);
@@ -273,12 +273,12 @@ static uint r8712_usb_dvobj_init(struct _adapter *padapter)
273 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints; 273 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
274 if (pusbd->speed == USB_SPEED_HIGH) { 274 if (pusbd->speed == USB_SPEED_HIGH) {
275 pdvobjpriv->ishighspeed = true; 275 pdvobjpriv->ishighspeed = true;
276 printk(KERN_INFO "r8712u: USB_SPEED_HIGH with %d endpoints\n", 276 dev_info(&pusbd->dev, "r8712u: USB_SPEED_HIGH with %d endpoints\n",
277 pdvobjpriv->nr_endpoint); 277 pdvobjpriv->nr_endpoint);
278 } else { 278 } else {
279 pdvobjpriv->ishighspeed = false; 279 pdvobjpriv->ishighspeed = false;
280 printk(KERN_INFO "r8712u: USB_SPEED_LOW with %d endpoints\n", 280 dev_info(&pusbd->dev, "r8712u: USB_SPEED_LOW with %d endpoints\n",
281 pdvobjpriv->nr_endpoint); 281 pdvobjpriv->nr_endpoint);
282 } 282 }
283 if ((r8712_alloc_io_queue(padapter)) == _FAIL) 283 if ((r8712_alloc_io_queue(padapter)) == _FAIL)
284 status = _FAIL; 284 status = _FAIL;
@@ -423,9 +423,9 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
423 tmpU1b = r8712_read8(padapter, EE_9346CR);/*CR9346*/ 423 tmpU1b = r8712_read8(padapter, EE_9346CR);/*CR9346*/
424 424
425 /* To check system boot selection.*/ 425 /* To check system boot selection.*/
426 printk(KERN_INFO "r8712u: Boot from %s: Autoload %s\n", 426 dev_info(&udev->dev, "r8712u: Boot from %s: Autoload %s\n",
427 (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE", 427 (tmpU1b & _9356SEL) ? "EEPROM" : "EFUSE",
428 (tmpU1b & _EEPROM_EN) ? "OK" : "Failed"); 428 (tmpU1b & _EEPROM_EN) ? "OK" : "Failed");
429 429
430 /* To check autoload success or not.*/ 430 /* To check autoload success or not.*/
431 if (tmpU1b & _EEPROM_EN) { 431 if (tmpU1b & _EEPROM_EN) {
@@ -533,8 +533,8 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
533 RT_CID_DEFAULT; 533 RT_CID_DEFAULT;
534 break; 534 break;
535 } 535 }
536 printk(KERN_INFO "r8712u: CustomerID = 0x%.4x\n", 536 dev_info(&udev->dev, "r8712u: CustomerID = 0x%.4x\n",
537 padapter->eeprompriv.CustomerID); 537 padapter->eeprompriv.CustomerID);
538 /* Led mode */ 538 /* Led mode */
539 switch (padapter->eeprompriv.CustomerID) { 539 switch (padapter->eeprompriv.CustomerID) {
540 case RT_CID_DEFAULT: 540 case RT_CID_DEFAULT:
@@ -590,11 +590,9 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
590 * address by setting bit 1 of first octet. 590 * address by setting bit 1 of first octet.
591 */ 591 */
592 mac[0] &= 0xFE; 592 mac[0] &= 0xFE;
593 printk(KERN_INFO "r8712u: MAC Address from user = " 593 dev_info(&udev->dev, "r8712u: MAC Address from user = %pM\n", mac);
594 "%pM\n", mac);
595 } else 594 } else
596 printk(KERN_INFO "r8712u: MAC Address from efuse = " 595 dev_info(&udev->dev, "r8712u: MAC Address from efuse = %pM\n", mac);
597 "%pM\n", mac);
598 memcpy(pnetdev->dev_addr, mac, ETH_ALEN); 596 memcpy(pnetdev->dev_addr, mac, ETH_ALEN);
599 } 597 }
600 /* step 6. Load the firmware asynchronously */ 598 /* step 6. Load the firmware asynchronously */
@@ -661,7 +659,6 @@ static void __exit r8712u_drv_halt(void)
661{ 659{
662 drvpriv.drv_registered = false; 660 drvpriv.drv_registered = false;
663 usb_deregister(&drvpriv.r871xu_drv); 661 usb_deregister(&drvpriv.r871xu_drv);
664 printk(KERN_INFO "r8712u: Driver unloaded\n");
665} 662}
666 663
667module_init(r8712u_drv_entry); 664module_init(r8712u_drv_entry);
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c
index 24e1ec5f0060..dca398a0656b 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -45,9 +45,6 @@ struct zero_bulkout_context {
45 void *padapter; 45 void *padapter;
46}; 46};
47 47
48#define usb_write_cmd r8712_usb_write_mem
49#define usb_write_cmd_complete usb_write_mem_complete
50
51uint r8712_usb_init_intf_priv(struct intf_priv *pintfpriv) 48uint r8712_usb_init_intf_priv(struct intf_priv *pintfpriv)
52{ 49{
53 pintfpriv->piorw_urb = usb_alloc_urb(0, GFP_ATOMIC); 50 pintfpriv->piorw_urb = usb_alloc_urb(0, GFP_ATOMIC);
@@ -243,8 +240,7 @@ static void r8712_usb_read_port_complete(struct urb *purb)
243 (unsigned char *)precvbuf); 240 (unsigned char *)precvbuf);
244 break; 241 break;
245 case -EINPROGRESS: 242 case -EINPROGRESS:
246 printk(KERN_ERR "r8712u: ERROR: URB IS IN" 243 netdev_err(padapter->pnetdev, "ERROR: URB IS IN PROGRESS!\n");
247 " PROGRESS!/n");
248 break; 244 break;
249 default: 245 default:
250 break; 246 break;
@@ -336,8 +332,7 @@ void r8712_xmit_bh(void *priv)
336 332
337 if ((padapter->bDriverStopped == true) || 333 if ((padapter->bDriverStopped == true) ||
338 (padapter->bSurpriseRemoved == true)) { 334 (padapter->bSurpriseRemoved == true)) {
339 printk(KERN_ERR "r8712u: xmit_bh => bDriverStopped" 335 netdev_err(padapter->pnetdev, "xmit_bh => bDriverStopped or bSurpriseRemoved\n");
340 " or bSurpriseRemoved\n");
341 return; 336 return;
342 } 337 }
343 ret = r8712_xmitframe_complete(padapter, pxmitpriv, NULL); 338 ret = r8712_xmitframe_complete(padapter, pxmitpriv, NULL);
@@ -387,7 +382,7 @@ static void usb_write_port_complete(struct urb *purb)
387 case 0: 382 case 0:
388 break; 383 break;
389 default: 384 default:
390 printk(KERN_WARNING "r8712u: pipe error: (%d)\n", purb->status); 385 netdev_warn(padapter->pnetdev, "r8712u: pipe error: (%d)\n", purb->status);
391 break; 386 break;
392 } 387 }
393 /* not to consider tx fragment */ 388 /* not to consider tx fragment */
@@ -502,8 +497,8 @@ int r8712_usbctrl_vendorreq(struct intf_priv *pintfpriv, u8 request, u16 value,
502 497
503 palloc_buf = _malloc((u32) len + 16); 498 palloc_buf = _malloc((u32) len + 16);
504 if (palloc_buf == NULL) { 499 if (palloc_buf == NULL) {
505 printk(KERN_ERR "r8712u: [%s] Can't alloc memory for vendor" 500 dev_err(&udev->dev, "%s: Can't alloc memory for vendor request\n",
506 " request\n", __func__); 501 __func__);
507 return -1; 502 return -1;
508 } 503 }
509 pIo_buf = palloc_buf + 16 - ((addr_t)(palloc_buf) & 0x0f); 504 pIo_buf = palloc_buf + 16 - ((addr_t)(palloc_buf) & 0x0f);
diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index 793443e758ac..73d7cd280607 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -159,99 +159,85 @@ enum WIFI_REG_DOMAIN {
159#define _PRIVACY_ BIT(14) 159#define _PRIVACY_ BIT(14)
160#define _ORDER_ BIT(15) 160#define _ORDER_ BIT(15)
161 161
162#define SetToDs(pbuf) \ 162#define SetToDs(pbuf) ({ \
163 do { \ 163 *(unsigned short *)(pbuf) |= cpu_to_le16(_TO_DS_); \
164 *(unsigned short *)(pbuf) |= cpu_to_le16(_TO_DS_); \ 164})
165 } while (0)
166 165
167#define GetToDs(pbuf) (((*(unsigned short *)(pbuf)) & \ 166#define GetToDs(pbuf) (((*(unsigned short *)(pbuf)) & \
168 le16_to_cpu(_TO_DS_)) != 0) 167 le16_to_cpu(_TO_DS_)) != 0)
169 168
170#define ClearToDs(pbuf) \ 169#define ClearToDs(pbuf) ({ \
171 do { \ 170 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \
172 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \ 171})
173 } while (0)
174 172
175#define SetFrDs(pbuf) \ 173#define SetFrDs(pbuf) ({ \
176 do { \ 174 *(unsigned short *)(pbuf) |= cpu_to_le16(_FROM_DS_); \
177 *(unsigned short *)(pbuf) |= cpu_to_le16(_FROM_DS_); \ 175})
178 } while (0)
179 176
180#define GetFrDs(pbuf) (((*(unsigned short *)(pbuf)) & \ 177#define GetFrDs(pbuf) (((*(unsigned short *)(pbuf)) & \
181 le16_to_cpu(_FROM_DS_)) != 0) 178 le16_to_cpu(_FROM_DS_)) != 0)
182 179
183#define ClearFrDs(pbuf) \ 180#define ClearFrDs(pbuf) ({ \
184 do { \ 181 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \
185 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \ 182})
186 } while (0)
187 183
188#define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe)) 184#define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe))
189 185
190 186
191#define SetMFrag(pbuf) \ 187#define SetMFrag(pbuf) ({ \
192 do { \ 188 *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \
193 *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \ 189})
194 } while (0)
195 190
196#define GetMFrag(pbuf) (((*(unsigned short *)(pbuf)) & \ 191#define GetMFrag(pbuf) (((*(unsigned short *)(pbuf)) & \
197 le16_to_cpu(_MORE_FRAG_)) != 0) 192 le16_to_cpu(_MORE_FRAG_)) != 0)
198 193
199#define ClearMFrag(pbuf) \ 194#define ClearMFrag(pbuf) ({ \
200 do { \ 195 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \
201 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \ 196})
202 } while (0)
203 197
204#define SetRetry(pbuf) \ 198#define SetRetry(pbuf) ({ \
205 do { \ 199 *(unsigned short *)(pbuf) |= cpu_to_le16(_RETRY_); \
206 *(unsigned short *)(pbuf) |= cpu_to_le16(_RETRY_); \ 200})
207 } while (0)
208 201
209#define GetRetry(pbuf) (((*(unsigned short *)(pbuf)) & \ 202#define GetRetry(pbuf) (((*(unsigned short *)(pbuf)) & \
210 le16_to_cpu(_RETRY_)) != 0) 203 le16_to_cpu(_RETRY_)) != 0)
211 204
212#define ClearRetry(pbuf) \ 205#define ClearRetry(pbuf) ({ \
213 do { \ 206 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \
214 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \ 207})
215 } while (0)
216 208
217#define SetPwrMgt(pbuf) \ 209#define SetPwrMgt(pbuf) ({ \
218 do { \ 210 *(unsigned short *)(pbuf) |= cpu_to_le16(_PWRMGT_); \
219 *(unsigned short *)(pbuf) |= cpu_to_le16(_PWRMGT_); \ 211})
220 } while (0)
221 212
222#define GetPwrMgt(pbuf) (((*(unsigned short *)(pbuf)) & \ 213#define GetPwrMgt(pbuf) (((*(unsigned short *)(pbuf)) & \
223 le16_to_cpu(_PWRMGT_)) != 0) 214 le16_to_cpu(_PWRMGT_)) != 0)
224 215
225#define ClearPwrMgt(pbuf) \ 216#define ClearPwrMgt(pbuf) ({ \
226 do { \ 217 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \
227 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \ 218})
228 } while (0)
229 219
230#define SetMData(pbuf) \ 220#define SetMData(pbuf) ({ \
231 do { \ 221 *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \
232 *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \ 222})
233 } while (0)
234 223
235#define GetMData(pbuf) (((*(unsigned short *)(pbuf)) & \ 224#define GetMData(pbuf) (((*(unsigned short *)(pbuf)) & \
236 le16_to_cpu(_MORE_DATA_)) != 0) 225 le16_to_cpu(_MORE_DATA_)) != 0)
237 226
238#define ClearMData(pbuf) \ 227#define ClearMData(pbuf) ({ \
239 do { \ 228 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \
240 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \ 229})
241 } while (0)
242 230
243#define SetPrivacy(pbuf) \ 231#define SetPrivacy(pbuf) ({ \
244 do { \ 232 *(unsigned short *)(pbuf) |= cpu_to_le16(_PRIVACY_); \
245 *(unsigned short *)(pbuf) |= cpu_to_le16(_PRIVACY_); \ 233})
246 } while (0)
247 234
248#define GetPrivacy(pbuf) (((*(unsigned short *)(pbuf)) & \ 235#define GetPrivacy(pbuf) (((*(unsigned short *)(pbuf)) & \
249 le16_to_cpu(_PRIVACY_)) != 0) 236 le16_to_cpu(_PRIVACY_)) != 0)
250 237
251#define ClearPrivacy(pbuf) \ 238#define ClearPrivacy(pbuf) ({ \
252 do { \ 239 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PRIVACY_)); \
253 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PRIVACY_)); \ 240})
254 } while (0)
255 241
256 242
257#define GetOrder(pbuf) (((*(unsigned short *)(pbuf)) & \ 243#define GetOrder(pbuf) (((*(unsigned short *)(pbuf)) & \
@@ -287,48 +273,42 @@ enum WIFI_REG_DOMAIN {
287#define GetTupleCache(pbuf) (cpu_to_le16(*(unsigned short *)\ 273#define GetTupleCache(pbuf) (cpu_to_le16(*(unsigned short *)\
288 ((addr_t)(pbuf) + 22))) 274 ((addr_t)(pbuf) + 22)))
289 275
290#define SetFragNum(pbuf, num) \ 276#define SetFragNum(pbuf, num) ({ \
291 do { \ 277 *(unsigned short *)((addr_t)(pbuf) + 22) = \
292 *(unsigned short *)((addr_t)(pbuf) + 22) = \ 278 ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \
293 ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \ 279 le16_to_cpu(~(0x000f))) | \
294 le16_to_cpu(~(0x000f))) | \ 280 cpu_to_le16(0x0f & (num)); \
295 cpu_to_le16(0x0f & (num)); \ 281})
296 } while (0) 282
297 283#define SetSeqNum(pbuf, num) ({ \
298#define SetSeqNum(pbuf, num) \ 284 *(unsigned short *)((addr_t)(pbuf) + 22) = \
299 do { \ 285 ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \
300 *(unsigned short *)((addr_t)(pbuf) + 22) = \ 286 le16_to_cpu((unsigned short)0x000f)) | \
301 ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \ 287 le16_to_cpu((unsigned short)(0xfff0 & (num << 4))); \
302 le16_to_cpu((unsigned short)0x000f)) | \ 288})
303 le16_to_cpu((unsigned short)(0xfff0 & (num << 4))); \ 289
304 } while (0) 290#define SetDuration(pbuf, dur) ({ \
305 291 *(unsigned short *)((addr_t)(pbuf) + 2) |= \
306#define SetDuration(pbuf, dur) \ 292 cpu_to_le16(0xffff & (dur)); \
307 do { \ 293})
308 *(unsigned short *)((addr_t)(pbuf) + 2) |= \ 294
309 cpu_to_le16(0xffff & (dur)); \ 295#define SetPriority(pbuf, tid) ({ \
310 } while (0) 296 *(unsigned short *)(pbuf) |= cpu_to_le16(tid & 0xf); \
311 297})
312#define SetPriority(pbuf, tid) \
313 do { \
314 *(unsigned short *)(pbuf) |= cpu_to_le16(tid & 0xf); \
315 } while (0)
316 298
317#define GetPriority(pbuf) ((le16_to_cpu(*(unsigned short *)(pbuf))) & 0xf) 299#define GetPriority(pbuf) ((le16_to_cpu(*(unsigned short *)(pbuf))) & 0xf)
318 300
319#define SetAckpolicy(pbuf, ack) \ 301#define SetAckpolicy(pbuf, ack) ({ \
320 do { \ 302 *(unsigned short *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
321 *(unsigned short *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \ 303})
322 } while (0)
323 304
324#define GetAckpolicy(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 5) & 0x3) 305#define GetAckpolicy(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 5) & 0x3)
325 306
326#define GetAMsdu(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 7) & 0x1) 307#define GetAMsdu(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 7) & 0x1)
327 308
328#define SetAMsdu(pbuf, amsdu) \ 309#define SetAMsdu(pbuf, amsdu) ({ \
329 do { \ 310 *(unsigned short *)(pbuf) |= cpu_to_le16((amsdu & 1) << 7); \
330 *(unsigned short *)(pbuf) |= cpu_to_le16((amsdu & 1) << 7); \ 311})
331 } while (0)
332 312
333#define GetAid(pbuf) (cpu_to_le16(*(unsigned short *)((addr_t)(pbuf) + 2)) \ 313#define GetAid(pbuf) (cpu_to_le16(*(unsigned short *)((addr_t)(pbuf) + 2)) \
334 & 0x3fff) 314 & 0x3fff)
@@ -457,11 +437,7 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
457#define _SSID_IE_ 0 437#define _SSID_IE_ 0
458#define _SUPPORTEDRATES_IE_ 1 438#define _SUPPORTEDRATES_IE_ 1
459#define _DSSET_IE_ 3 439#define _DSSET_IE_ 3
460#define _TIM_IE_ 5
461#define _IBSS_PARA_IE_ 6 440#define _IBSS_PARA_IE_ 6
462#define _CHLGETXT_IE_ 16
463#define _RSN_IE_2_ 48`
464#define _SSN_IE_1_ 221
465#define _ERPINFO_IE_ 42 441#define _ERPINFO_IE_ 42
466#define _EXT_SUPPORTEDRATES_IE_ 50 442#define _EXT_SUPPORTEDRATES_IE_ 50
467 443
@@ -526,10 +502,9 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
526#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000 502#define IEEE80211_DELBA_PARAM_TID_MASK 0xF000
527#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800 503#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
528 504
529#define SetOrderBit(pbuf) \ 505#define SetOrderBit(pbuf) ({ \
530 do { \ 506 *(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \
531 *(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \ 507})
532 } while (0)
533 508
534#define GetOrderBit(pbuf) (((*(unsigned short *)(pbuf)) & \ 509#define GetOrderBit(pbuf) (((*(unsigned short *)(pbuf)) & \
535 le16_to_cpu(_ORDER_)) != 0) 510 le16_to_cpu(_ORDER_)) != 0)
diff --git a/drivers/staging/rtl8712/xmit_linux.c b/drivers/staging/rtl8712/xmit_linux.c
index 65542cb7168f..4d22bb7008f8 100644
--- a/drivers/staging/rtl8712/xmit_linux.c
+++ b/drivers/staging/rtl8712/xmit_linux.c
@@ -134,8 +134,7 @@ int r8712_xmit_resource_alloc(struct _adapter *padapter,
134 for (i = 0; i < 8; i++) { 134 for (i = 0; i < 8; i++) {
135 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL); 135 pxmitbuf->pxmit_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
136 if (pxmitbuf->pxmit_urb[i] == NULL) { 136 if (pxmitbuf->pxmit_urb[i] == NULL) {
137 printk(KERN_ERR "r8712u: pxmitbuf->pxmit_urb[i]" 137 netdev_err(padapter->pnetdev, "pxmitbuf->pxmit_urb[i] == NULL\n");
138 " == NULL");
139 return _FAIL; 138 return _FAIL;
140 } 139 }
141 } 140 }
diff --git a/drivers/staging/sb105x/sb_mp_register.h b/drivers/staging/sb105x/sb_mp_register.h
index 5480ae11368f..a2087f5b0d1a 100644
--- a/drivers/staging/sb105x/sb_mp_register.h
+++ b/drivers/staging/sb105x/sb_mp_register.h
@@ -45,7 +45,7 @@
45#define IIR_RS232 0x00 /* RS232 type */ 45#define IIR_RS232 0x00 /* RS232 type */
46#define IIR_RS422 0x10 /* RS422 type */ 46#define IIR_RS422 0x10 /* RS422 type */
47#define IIR_RS485 0x20 /* RS485 type */ 47#define IIR_RS485 0x20 /* RS485 type */
48#define IIR_UNKNOWN 0x30 /* unknown type */ 48#define IIR_TYPE_MASK 0x30
49 49
50/* Interrrupt Mask Register */ 50/* Interrrupt Mask Register */
51#define MP_OPTR_IMR0 0x0C /* port0 ~ port8 */ 51#define MP_OPTR_IMR0 0x0C /* port0 ~ port8 */
diff --git a/drivers/staging/sb105x/sb_pci_mp.c b/drivers/staging/sb105x/sb_pci_mp.c
index 9464f3874346..f75ee1dd475c 100644
--- a/drivers/staging/sb105x/sb_pci_mp.c
+++ b/drivers/staging/sb105x/sb_pci_mp.c
@@ -1563,13 +1563,13 @@ static int mp_open(struct tty_struct *tty, struct file *filp)
1563 1563
1564 state = uart_get(drv, line); 1564 state = uart_get(drv, line);
1565 1565
1566 mtpt = (struct mp_port *)state->port;
1567
1568 if (IS_ERR(state)) { 1566 if (IS_ERR(state)) {
1569 retval = PTR_ERR(state); 1567 retval = PTR_ERR(state);
1570 goto fail; 1568 goto fail;
1571 } 1569 }
1572 1570
1571 mtpt = (struct mp_port *)state->port;
1572
1573 tty->driver_data = state; 1573 tty->driver_data = state;
1574 tty->low_latency = (state->port->flags & UPF_LOW_LATENCY) ? 1 : 0; 1574 tty->low_latency = (state->port->flags & UPF_LOW_LATENCY) ? 1 : 0;
1575 tty->alt_speed = 0; 1575 tty->alt_speed = 0;
@@ -2851,18 +2851,12 @@ static void __init multi_init_ports(void)
2851 printk("IIR_RET = %x\n",b_ret); 2851 printk("IIR_RET = %x\n",b_ret);
2852 } 2852 }
2853 2853
2854 if(IIR_RS232 == (b_ret & IIR_RS232)) 2854 /* default to RS232 */
2855 { 2855 mtpt->interface = RS232;
2856 mtpt->interface = RS232; 2856 if (IIR_RS422 == (b_ret & IIR_TYPE_MASK))
2857 }
2858 if(IIR_RS422 == (b_ret & IIR_RS422))
2859 {
2860 mtpt->interface = RS422PTP; 2857 mtpt->interface = RS422PTP;
2861 } 2858 if (IIR_RS485 == (b_ret & IIR_TYPE_MASK))
2862 if(IIR_RS485 == (b_ret & IIR_RS485))
2863 {
2864 mtpt->interface = RS485NE; 2859 mtpt->interface = RS485NE;
2865 }
2866 } 2860 }
2867 } 2861 }
2868} 2862}
diff --git a/drivers/staging/sbe-2t3e3/dc.c b/drivers/staging/sbe-2t3e3/dc.c
index daadd6ea4978..f207b9e015ce 100644
--- a/drivers/staging/sbe-2t3e3/dc.c
+++ b/drivers/staging/sbe-2t3e3/dc.c
@@ -315,20 +315,17 @@ static int dc_init_descriptor_list(struct channel *sc)
315 struct sk_buff *m; 315 struct sk_buff *m;
316 316
317 if (sc->ether.rx_ring == NULL) 317 if (sc->ether.rx_ring == NULL)
318 sc->ether.rx_ring = kzalloc(SBE_2T3E3_RX_DESC_RING_SIZE * 318 sc->ether.rx_ring = kcalloc(SBE_2T3E3_RX_DESC_RING_SIZE,
319 sizeof(t3e3_rx_desc_t), GFP_KERNEL); 319 sizeof(t3e3_rx_desc_t), GFP_KERNEL);
320 if (sc->ether.rx_ring == NULL) { 320 if (sc->ether.rx_ring == NULL)
321 dev_err(&sc->pdev->dev, "SBE 2T3E3: no buffer space for RX ring\n");
322 return -ENOMEM; 321 return -ENOMEM;
323 }
324 322
325 if (sc->ether.tx_ring == NULL) 323 if (sc->ether.tx_ring == NULL)
326 sc->ether.tx_ring = kzalloc(SBE_2T3E3_TX_DESC_RING_SIZE * 324 sc->ether.tx_ring = kcalloc(SBE_2T3E3_TX_DESC_RING_SIZE,
327 sizeof(t3e3_tx_desc_t), GFP_KERNEL); 325 sizeof(t3e3_tx_desc_t), GFP_KERNEL);
328 if (sc->ether.tx_ring == NULL) { 326 if (sc->ether.tx_ring == NULL) {
329 kfree(sc->ether.rx_ring); 327 kfree(sc->ether.rx_ring);
330 sc->ether.rx_ring = NULL; 328 sc->ether.rx_ring = NULL;
331 dev_err(&sc->pdev->dev, "SBE 2T3E3: no buffer space for RX ring\n");
332 return -ENOMEM; 329 return -ENOMEM;
333 } 330 }
334 331
diff --git a/drivers/staging/sbe-2t3e3/module.c b/drivers/staging/sbe-2t3e3/module.c
index ae7af397a992..0e32be5c2471 100644
--- a/drivers/staging/sbe-2t3e3/module.c
+++ b/drivers/staging/sbe-2t3e3/module.c
@@ -154,11 +154,10 @@ static int t3e3_init_card(struct pci_dev *pdev, const struct pci_device_id *ent)
154 /* holds the reference for pdev1 */ 154 /* holds the reference for pdev1 */
155 } 155 }
156 156
157 card = kzalloc(sizeof(struct card) + channels * sizeof(struct channel), GFP_KERNEL); 157 card = kzalloc(sizeof(struct card) + channels * sizeof(struct channel),
158 if (!card) { 158 GFP_KERNEL);
159 dev_err(&pdev->dev, "Out of memory\n"); 159 if (!card)
160 return -ENOBUFS; 160 return -ENOBUFS;
161 }
162 161
163 spin_lock_init(&card->bootrom_lock); 162 spin_lock_init(&card->bootrom_lock);
164 card->bootrom_addr = pci_resource_start(pdev, 0); 163 card->bootrom_addr = pci_resource_start(pdev, 0);
diff --git a/drivers/staging/sep/sep_crypto.c b/drivers/staging/sep/sep_crypto.c
index 34710ce56004..cd3bb39e4255 100644
--- a/drivers/staging/sep/sep_crypto.c
+++ b/drivers/staging/sep/sep_crypto.c
@@ -178,11 +178,9 @@ static struct scatterlist *sep_alloc_sg_buf(
178 nbr_pages += 1; 178 nbr_pages += 1;
179 } 179 }
180 180
181 sg = kmalloc((sizeof(struct scatterlist) * nbr_pages), GFP_ATOMIC); 181 sg = kmalloc_array(nbr_pages, sizeof(struct scatterlist), GFP_ATOMIC);
182 if (!sg) { 182 if (!sg)
183 dev_warn(&sep->pdev->dev, "Cannot allocate page for new sg\n");
184 return NULL; 183 return NULL;
185 }
186 184
187 sg_init_table(sg, nbr_pages); 185 sg_init_table(sg, nbr_pages);
188 186
@@ -3908,13 +3906,9 @@ int sep_crypto_setup(void)
3908 return -ENOMEM; 3906 return -ENOMEM;
3909 } 3907 }
3910 3908
3911 i = 0;
3912 j = 0;
3913
3914 spin_lock_init(&queue_lock); 3909 spin_lock_init(&queue_lock);
3915 3910
3916 err = 0; 3911 err = 0;
3917
3918 for (i = 0; i < ARRAY_SIZE(hash_algs); i++) { 3912 for (i = 0; i < ARRAY_SIZE(hash_algs); i++) {
3919 err = crypto_register_ahash(&hash_algs[i]); 3913 err = crypto_register_ahash(&hash_algs[i]);
3920 if (err) 3914 if (err)
diff --git a/drivers/staging/sep/sep_main.c b/drivers/staging/sep/sep_main.c
index 15c6e3d9437c..30e8d25113e4 100644
--- a/drivers/staging/sep/sep_main.c
+++ b/drivers/staging/sep/sep_main.c
@@ -219,12 +219,8 @@ static int sep_allocate_dmatables_region(struct sep_device *sep,
219 dev_dbg(&sep->pdev->dev, "[PID%d] oldlen = 0x%08X\n", current->pid, 219 dev_dbg(&sep->pdev->dev, "[PID%d] oldlen = 0x%08X\n", current->pid,
220 dma_ctx->dmatables_len); 220 dma_ctx->dmatables_len);
221 tmp_region = kzalloc(new_len + dma_ctx->dmatables_len, GFP_KERNEL); 221 tmp_region = kzalloc(new_len + dma_ctx->dmatables_len, GFP_KERNEL);
222 if (!tmp_region) { 222 if (!tmp_region)
223 dev_warn(&sep->pdev->dev,
224 "[PID%d] no mem for dma tables region\n",
225 current->pid);
226 return -ENOMEM; 223 return -ENOMEM;
227 }
228 224
229 /* Were there any previous tables that need to be preserved ? */ 225 /* Were there any previous tables that need to be preserved ? */
230 if (*dmatables_region) { 226 if (*dmatables_region) {
@@ -1245,27 +1241,23 @@ static int sep_lock_user_pages(struct sep_device *sep,
1245 current->pid, num_pages); 1241 current->pid, num_pages);
1246 1242
1247 /* Allocate array of pages structure pointers */ 1243 /* Allocate array of pages structure pointers */
1248 page_array = kmalloc(sizeof(struct page *) * num_pages, GFP_ATOMIC); 1244 page_array = kmalloc_array(num_pages, sizeof(struct page *),
1245 GFP_ATOMIC);
1249 if (!page_array) { 1246 if (!page_array) {
1250 error = -ENOMEM; 1247 error = -ENOMEM;
1251 goto end_function; 1248 goto end_function;
1252 } 1249 }
1253 map_array = kmalloc(sizeof(struct sep_dma_map) * num_pages, GFP_ATOMIC); 1250
1251 map_array = kmalloc_array(num_pages, sizeof(struct sep_dma_map),
1252 GFP_ATOMIC);
1254 if (!map_array) { 1253 if (!map_array) {
1255 dev_warn(&sep->pdev->dev,
1256 "[PID%d] kmalloc for map_array failed\n",
1257 current->pid);
1258 error = -ENOMEM; 1254 error = -ENOMEM;
1259 goto end_function_with_error1; 1255 goto end_function_with_error1;
1260 } 1256 }
1261 1257
1262 lli_array = kmalloc(sizeof(struct sep_lli_entry) * num_pages, 1258 lli_array = kmalloc_array(num_pages, sizeof(struct sep_lli_entry),
1263 GFP_ATOMIC); 1259 GFP_ATOMIC);
1264
1265 if (!lli_array) { 1260 if (!lli_array) {
1266 dev_warn(&sep->pdev->dev,
1267 "[PID%d] kmalloc for lli_array failed\n",
1268 current->pid);
1269 error = -ENOMEM; 1261 error = -ENOMEM;
1270 goto end_function_with_error2; 1262 goto end_function_with_error2;
1271 } 1263 }
@@ -1448,15 +1440,10 @@ static int sep_lli_table_secure_dma(struct sep_device *sep,
1448 dev_dbg(&sep->pdev->dev, "[PID%d] num_pages is (hex) %x\n", 1440 dev_dbg(&sep->pdev->dev, "[PID%d] num_pages is (hex) %x\n",
1449 current->pid, num_pages); 1441 current->pid, num_pages);
1450 1442
1451 lli_array = kmalloc(sizeof(struct sep_lli_entry) * num_pages, 1443 lli_array = kmalloc_array(num_pages, sizeof(struct sep_lli_entry),
1452 GFP_ATOMIC); 1444 GFP_ATOMIC);
1453 1445 if (!lli_array)
1454 if (!lli_array) {
1455 dev_warn(&sep->pdev->dev,
1456 "[PID%d] kmalloc for lli_array failed\n",
1457 current->pid);
1458 return -ENOMEM; 1446 return -ENOMEM;
1459 }
1460 1447
1461 /* 1448 /*
1462 * Fill the lli_array 1449 * Fill the lli_array
@@ -3419,11 +3406,9 @@ static ssize_t sep_create_dcb_dmatables_context(struct sep_device *sep,
3419 goto end_function; 3406 goto end_function;
3420 } 3407 }
3421 3408
3422 dcb_args = kzalloc(num_dcbs * sizeof(struct build_dcb_struct), 3409 dcb_args = kcalloc(num_dcbs, sizeof(struct build_dcb_struct),
3423 GFP_KERNEL); 3410 GFP_KERNEL);
3424 if (!dcb_args) { 3411 if (!dcb_args) {
3425 dev_warn(&sep->pdev->dev, "[PID%d] no memory for dcb args\n",
3426 current->pid);
3427 error = -ENOMEM; 3412 error = -ENOMEM;
3428 goto end_function; 3413 goto end_function;
3429 } 3414 }
@@ -3610,9 +3595,6 @@ static ssize_t sep_create_msgarea_context(struct sep_device *sep,
3610 /* Allocate thread-specific memory for message buffer */ 3595 /* Allocate thread-specific memory for message buffer */
3611 *msg_region = kzalloc(msg_len, GFP_KERNEL); 3596 *msg_region = kzalloc(msg_len, GFP_KERNEL);
3612 if (!(*msg_region)) { 3597 if (!(*msg_region)) {
3613 dev_warn(&sep->pdev->dev,
3614 "[PID%d] no mem for msgarea context\n",
3615 current->pid);
3616 error = -ENOMEM; 3598 error = -ENOMEM;
3617 goto end_function; 3599 goto end_function;
3618 } 3600 }
@@ -4133,8 +4115,6 @@ static int sep_probe(struct pci_dev *pdev,
4133 /* Allocate the sep_device structure for this device */ 4115 /* Allocate the sep_device structure for this device */
4134 sep_dev = kzalloc(sizeof(struct sep_device), GFP_ATOMIC); 4116 sep_dev = kzalloc(sizeof(struct sep_device), GFP_ATOMIC);
4135 if (sep_dev == NULL) { 4117 if (sep_dev == NULL) {
4136 dev_warn(&pdev->dev,
4137 "can't kmalloc the sep_device structure\n");
4138 error = -ENOMEM; 4118 error = -ENOMEM;
4139 goto end_function_disable_device; 4119 goto end_function_disable_device;
4140 } 4120 }
diff --git a/drivers/staging/slicoss/slic.h b/drivers/staging/slicoss/slic.h
index ebdcc6f91fdc..4c7822bd5358 100644
--- a/drivers/staging/slicoss/slic.h
+++ b/drivers/staging/slicoss/slic.h
@@ -43,15 +43,15 @@
43 43
44/* firmware stuff */ 44/* firmware stuff */
45#define OASIS_UCODE_VERS_STRING "1.2" 45#define OASIS_UCODE_VERS_STRING "1.2"
46#define OASIS_UCODE_VERS_DATE "2006/03/27 15:10:37" 46#define OASIS_UCODE_VERS_DATE "2006/03/27 15:10:37"
47#define OASIS_UCODE_HOSTIF_ID 3 47#define OASIS_UCODE_HOSTIF_ID 3
48 48
49#define MOJAVE_UCODE_VERS_STRING "1.2" 49#define MOJAVE_UCODE_VERS_STRING "1.2"
50#define MOJAVE_UCODE_VERS_DATE "2006/03/27 15:12:22" 50#define MOJAVE_UCODE_VERS_DATE "2006/03/27 15:12:22"
51#define MOJAVE_UCODE_HOSTIF_ID 3 51#define MOJAVE_UCODE_HOSTIF_ID 3
52 52
53#define GB_RCVUCODE_VERS_STRING "1.2" 53#define GB_RCVUCODE_VERS_STRING "1.2"
54#define GB_RCVUCODE_VERS_DATE "2006/03/27 15:12:15" 54#define GB_RCVUCODE_VERS_DATE "2006/03/27 15:12:15"
55static u32 OasisRcvUCodeLen = 512; 55static u32 OasisRcvUCodeLen = 512;
56static u32 GBRcvUCodeLen = 512; 56static u32 GBRcvUCodeLen = 512;
57#define SECTION_SIZE 65536 57#define SECTION_SIZE 65536
@@ -65,12 +65,12 @@ struct slic_spinlock {
65#define SLIC_RSPQ_BUFSINPAGE (PAGE_SIZE / SLIC_RSPBUF_SIZE) 65#define SLIC_RSPQ_BUFSINPAGE (PAGE_SIZE / SLIC_RSPBUF_SIZE)
66 66
67struct slic_rspqueue { 67struct slic_rspqueue {
68 u32 offset; 68 u32 offset;
69 u32 pageindex; 69 u32 pageindex;
70 u32 num_pages; 70 u32 num_pages;
71 struct slic_rspbuf *rspbuf; 71 struct slic_rspbuf *rspbuf;
72 u32 *vaddr[SLIC_RSPQ_PAGES_GB]; 72 u32 *vaddr[SLIC_RSPQ_PAGES_GB];
73 dma_addr_t paddr[SLIC_RSPQ_PAGES_GB]; 73 dma_addr_t paddr[SLIC_RSPQ_PAGES_GB];
74}; 74};
75 75
76#define SLIC_RCVQ_EXPANSION 1 76#define SLIC_RCVQ_EXPANSION 1
@@ -82,20 +82,20 @@ struct slic_rspqueue {
82#define SLIC_RCVQ_FILLTHRESH (SLIC_RCVQ_ENTRIES - SLIC_RCVQ_FILLENTRIES) 82#define SLIC_RCVQ_FILLTHRESH (SLIC_RCVQ_ENTRIES - SLIC_RCVQ_FILLENTRIES)
83 83
84struct slic_rcvqueue { 84struct slic_rcvqueue {
85 struct sk_buff *head; 85 struct sk_buff *head;
86 struct sk_buff *tail; 86 struct sk_buff *tail;
87 u32 count; 87 u32 count;
88 u32 size; 88 u32 size;
89 u32 errors; 89 u32 errors;
90}; 90};
91 91
92struct slic_rcvbuf_info { 92struct slic_rcvbuf_info {
93 u32 id; 93 u32 id;
94 u32 starttime; 94 u32 starttime;
95 u32 stoptime; 95 u32 stoptime;
96 u32 slicworld; 96 u32 slicworld;
97 u32 lasttime; 97 u32 lasttime;
98 u32 lastid; 98 u32 lastid;
99}; 99};
100/* 100/*
101 SLIC Handle structure. Used to restrict handle values to 101 SLIC Handle structure. Used to restrict handle values to
@@ -113,12 +113,12 @@ struct slic_handle_word {
113}; 113};
114 114
115struct slic_handle { 115struct slic_handle {
116 struct slic_handle_word token; /* token passed between host and card*/ 116 struct slic_handle_word token; /* token passed between host and card*/
117 ushort type; 117 ushort type;
118 void *address; /* actual address of the object*/ 118 void *address; /* actual address of the object*/
119 ushort offset; 119 ushort offset;
120 struct slic_handle *other_handle; 120 struct slic_handle *other_handle;
121 struct slic_handle *next; 121 struct slic_handle *next;
122}; 122};
123 123
124#define SLIC_HANDLE_FREE 0x0000 124#define SLIC_HANDLE_FREE 0x0000
@@ -134,17 +134,17 @@ struct slic_handle {
134#define SLIC_HOSTCMD_SIZE 512 134#define SLIC_HOSTCMD_SIZE 512
135 135
136struct slic_hostcmd { 136struct slic_hostcmd {
137 struct slic_host64_cmd cmd64; 137 struct slic_host64_cmd cmd64;
138 u32 type; 138 u32 type;
139 struct sk_buff *skb; 139 struct sk_buff *skb;
140 u32 paddrl; 140 u32 paddrl;
141 u32 paddrh; 141 u32 paddrh;
142 u32 busy; 142 u32 busy;
143 u32 cmdsize; 143 u32 cmdsize;
144 ushort numbufs; 144 ushort numbufs;
145 struct slic_handle *pslic_handle;/* handle associated with command */ 145 struct slic_handle *pslic_handle;/* handle associated with command */
146 struct slic_hostcmd *next; 146 struct slic_hostcmd *next;
147 struct slic_hostcmd *next_all; 147 struct slic_hostcmd *next_all;
148}; 148};
149 149
150#define SLIC_CMDQ_CMDSINPAGE (PAGE_SIZE / SLIC_HOSTCMD_SIZE) 150#define SLIC_CMDQ_CMDSINPAGE (PAGE_SIZE / SLIC_HOSTCMD_SIZE)
@@ -228,35 +228,35 @@ struct mcast_address {
228#define SLIC_CARD_STATE(x) ((x == CARD_UP) ? "UP" : "Down") 228#define SLIC_CARD_STATE(x) ((x == CARD_UP) ? "UP" : "Down")
229 229
230struct slic_iface_stats { 230struct slic_iface_stats {
231 /* 231 /*
232 * Stats 232 * Stats
233 */ 233 */
234 u64 xmt_bytes; 234 u64 xmt_bytes;
235 u64 xmt_ucast; 235 u64 xmt_ucast;
236 u64 xmt_mcast; 236 u64 xmt_mcast;
237 u64 xmt_bcast; 237 u64 xmt_bcast;
238 u64 xmt_errors; 238 u64 xmt_errors;
239 u64 xmt_discards; 239 u64 xmt_discards;
240 u64 xmit_collisions; 240 u64 xmit_collisions;
241 u64 xmit_excess_xmit_collisions; 241 u64 xmit_excess_xmit_collisions;
242 u64 rcv_bytes; 242 u64 rcv_bytes;
243 u64 rcv_ucast; 243 u64 rcv_ucast;
244 u64 rcv_mcast; 244 u64 rcv_mcast;
245 u64 rcv_bcast; 245 u64 rcv_bcast;
246 u64 rcv_errors; 246 u64 rcv_errors;
247 u64 rcv_discards; 247 u64 rcv_discards;
248}; 248};
249 249
250struct sliccp_stats { 250struct sliccp_stats {
251 u64 xmit_tcp_segs; 251 u64 xmit_tcp_segs;
252 u64 xmit_tcp_bytes; 252 u64 xmit_tcp_bytes;
253 u64 rcv_tcp_segs; 253 u64 rcv_tcp_segs;
254 u64 rcv_tcp_bytes; 254 u64 rcv_tcp_bytes;
255}; 255};
256 256
257struct slicnet_stats { 257struct slicnet_stats {
258 struct sliccp_stats tcp; 258 struct sliccp_stats tcp;
259 struct slic_iface_stats iface; 259 struct slic_iface_stats iface;
260}; 260};
261 261
262#define SLIC_LOADTIMER_PERIOD 1 262#define SLIC_LOADTIMER_PERIOD 1
@@ -285,51 +285,51 @@ struct slicnet_stats {
285#define SLIC_INTAGG_5GB 100 285#define SLIC_INTAGG_5GB 100
286 286
287struct ether_header { 287struct ether_header {
288 unsigned char ether_dhost[6]; 288 unsigned char ether_dhost[6];
289 unsigned char ether_shost[6]; 289 unsigned char ether_shost[6];
290 ushort ether_type; 290 ushort ether_type;
291}; 291};
292 292
293struct sliccard { 293struct sliccard {
294 uint busnumber; 294 uint busnumber;
295 uint slotnumber; 295 uint slotnumber;
296 uint state; 296 uint state;
297 uint cardnum; 297 uint cardnum;
298 uint card_size; 298 uint card_size;
299 uint adapters_activated; 299 uint adapters_activated;
300 uint adapters_allocated; 300 uint adapters_allocated;
301 uint adapters_sleeping; 301 uint adapters_sleeping;
302 uint gennumber; 302 uint gennumber;
303 u32 events; 303 u32 events;
304 u32 loadlevel_current; 304 u32 loadlevel_current;
305 u32 load; 305 u32 load;
306 uint reset_in_progress; 306 uint reset_in_progress;
307 u32 pingstatus; 307 u32 pingstatus;
308 u32 bad_pingstatus; 308 u32 bad_pingstatus;
309 struct timer_list loadtimer; 309 struct timer_list loadtimer;
310 u32 loadtimerset; 310 u32 loadtimerset;
311 uint config_set; 311 uint config_set;
312 struct slic_config config; 312 struct slic_config config;
313 struct dentry *debugfs_dir; 313 struct dentry *debugfs_dir;
314 struct dentry *debugfs_cardinfo; 314 struct dentry *debugfs_cardinfo;
315 struct adapter *master; 315 struct adapter *master;
316 struct adapter *adapter[SLIC_MAX_PORTS]; 316 struct adapter *adapter[SLIC_MAX_PORTS];
317 struct sliccard *next; 317 struct sliccard *next;
318 u32 error_interrupts; 318 u32 error_interrupts;
319 u32 error_rmiss_interrupts; 319 u32 error_rmiss_interrupts;
320 u32 rcv_interrupts; 320 u32 rcv_interrupts;
321 u32 xmit_interrupts; 321 u32 xmit_interrupts;
322 u32 num_isrs; 322 u32 num_isrs;
323 u32 false_interrupts; 323 u32 false_interrupts;
324 u32 max_isr_rcvs; 324 u32 max_isr_rcvs;
325 u32 max_isr_xmits; 325 u32 max_isr_xmits;
326 u32 rcv_interrupt_yields; 326 u32 rcv_interrupt_yields;
327 u32 tx_packets; 327 u32 tx_packets;
328 u32 debug_ix; 328 u32 debug_ix;
329 ushort reg_type[32]; 329 ushort reg_type[32];
330 ushort reg_offset[32]; 330 ushort reg_offset[32];
331 u32 reg_value[32]; 331 u32 reg_value[32];
332 u32 reg_valueh[32]; 332 u32 reg_valueh[32];
333}; 333};
334 334
335#define NUM_CFG_SPACES 2 335#define NUM_CFG_SPACES 2
@@ -337,182 +337,182 @@ struct sliccard {
337#define NUM_CFG_REG_ULONGS (NUM_CFG_REGS / sizeof(u32)) 337#define NUM_CFG_REG_ULONGS (NUM_CFG_REGS / sizeof(u32))
338 338
339struct physcard { 339struct physcard {
340 struct adapter *adapter[SLIC_MAX_PORTS]; 340 struct adapter *adapter[SLIC_MAX_PORTS];
341 struct physcard *next; 341 struct physcard *next;
342 uint adapters_allocd; 342 uint adapters_allocd;
343 343
344 /* the following is not currently needed 344/* the following is not currently needed
345 u32 bridge_busnum; 345 u32 bridge_busnum;
346 u32 bridge_cfg[NUM_CFG_SPACES][NUM_CFG_REG_ULONGS]; 346 u32 bridge_cfg[NUM_CFG_SPACES][NUM_CFG_REG_ULONGS];
347 */ 347*/
348}; 348};
349 349
350struct base_driver { 350struct base_driver {
351 struct slic_spinlock driver_lock; 351 struct slic_spinlock driver_lock;
352 u32 num_slic_cards; 352 u32 num_slic_cards;
353 u32 num_slic_ports; 353 u32 num_slic_ports;
354 u32 num_slic_ports_active; 354 u32 num_slic_ports_active;
355 u32 dynamic_intagg; 355 u32 dynamic_intagg;
356 struct sliccard *slic_card; 356 struct sliccard *slic_card;
357 struct physcard *phys_card; 357 struct physcard *phys_card;
358 uint cardnuminuse[SLIC_MAX_CARDS]; 358 uint cardnuminuse[SLIC_MAX_CARDS];
359}; 359};
360 360
361struct slic_shmem { 361struct slic_shmem {
362 volatile u32 isr; 362 volatile u32 isr;
363 volatile u32 linkstatus; 363 volatile u32 linkstatus;
364 volatile struct slic_stats inicstats; 364 volatile struct slic_stats inicstats;
365}; 365};
366 366
367struct slic_reg_params { 367struct slic_reg_params {
368 u32 linkspeed; 368 u32 linkspeed;
369 u32 linkduplex; 369 u32 linkduplex;
370 u32 fail_on_bad_eeprom; 370 u32 fail_on_bad_eeprom;
371}; 371};
372 372
373struct slic_upr { 373struct slic_upr {
374 uint adapter; 374 uint adapter;
375 u32 upr_request; 375 u32 upr_request;
376 u32 upr_data; 376 u32 upr_data;
377 u32 upr_data_h; 377 u32 upr_data_h;
378 u32 upr_buffer; 378 u32 upr_buffer;
379 u32 upr_buffer_h; 379 u32 upr_buffer_h;
380 struct slic_upr *next; 380 struct slic_upr *next;
381}; 381};
382 382
383struct slic_ifevents { 383struct slic_ifevents {
384 uint oflow802; 384 uint oflow802;
385 uint uflow802; 385 uint uflow802;
386 uint Tprtoflow; 386 uint Tprtoflow;
387 uint rcvearly; 387 uint rcvearly;
388 uint Bufov; 388 uint Bufov;
389 uint Carre; 389 uint Carre;
390 uint Longe; 390 uint Longe;
391 uint Invp; 391 uint Invp;
392 uint Crc; 392 uint Crc;
393 uint Drbl; 393 uint Drbl;
394 uint Code; 394 uint Code;
395 uint IpHlen; 395 uint IpHlen;
396 uint IpLen; 396 uint IpLen;
397 uint IpCsum; 397 uint IpCsum;
398 uint TpCsum; 398 uint TpCsum;
399 uint TpHlen; 399 uint TpHlen;
400}; 400};
401 401
402struct adapter { 402struct adapter {
403 void *ifp; 403 void *ifp;
404 struct sliccard *card; 404 struct sliccard *card;
405 uint port; 405 uint port;
406 struct physcard *physcard; 406 struct physcard *physcard;
407 uint physport; 407 uint physport;
408 uint cardindex; 408 uint cardindex;
409 uint card_size; 409 uint card_size;
410 uint chipid; 410 uint chipid;
411 struct net_device *netdev; 411 struct net_device *netdev;
412 struct net_device *next_netdevice; 412 struct net_device *next_netdevice;
413 struct slic_spinlock adapter_lock; 413 struct slic_spinlock adapter_lock;
414 struct slic_spinlock reset_lock; 414 struct slic_spinlock reset_lock;
415 struct pci_dev *pcidev; 415 struct pci_dev *pcidev;
416 uint busnumber; 416 uint busnumber;
417 uint slotnumber; 417 uint slotnumber;
418 uint functionnumber; 418 uint functionnumber;
419 ushort vendid; 419 ushort vendid;
420 ushort devid; 420 ushort devid;
421 ushort subsysid; 421 ushort subsysid;
422 u32 irq; 422 u32 irq;
423 void __iomem *memorybase; 423 void __iomem *memorybase;
424 u32 memorylength; 424 u32 memorylength;
425 u32 drambase; 425 u32 drambase;
426 u32 dramlength; 426 u32 dramlength;
427 uint queues_initialized; 427 uint queues_initialized;
428 uint allocated; 428 uint allocated;
429 uint activated; 429 uint activated;
430 u32 intrregistered; 430 u32 intrregistered;
431 uint isp_initialized; 431 uint isp_initialized;
432 uint gennumber; 432 uint gennumber;
433 u32 curaddrupper; 433 u32 curaddrupper;
434 struct slic_shmem *pshmem; 434 struct slic_shmem *pshmem;
435 dma_addr_t phys_shmem; 435 dma_addr_t phys_shmem;
436 u32 isrcopy; 436 u32 isrcopy;
437 __iomem struct slic_regs *slic_regs; 437 __iomem struct slic_regs *slic_regs;
438 unsigned char state; 438 unsigned char state;
439 unsigned char linkstate; 439 unsigned char linkstate;
440 unsigned char linkspeed; 440 unsigned char linkspeed;
441 unsigned char linkduplex; 441 unsigned char linkduplex;
442 uint flags; 442 uint flags;
443 unsigned char macaddr[6]; 443 unsigned char macaddr[6];
444 unsigned char currmacaddr[6]; 444 unsigned char currmacaddr[6];
445 u32 macopts; 445 u32 macopts;
446 ushort devflags_prev; 446 ushort devflags_prev;
447 u64 mcastmask; 447 u64 mcastmask;
448 struct mcast_address *mcastaddrs; 448 struct mcast_address *mcastaddrs;
449 struct slic_upr *upr_list; 449 struct slic_upr *upr_list;
450 uint upr_busy; 450 uint upr_busy;
451 struct timer_list pingtimer; 451 struct timer_list pingtimer;
452 u32 pingtimerset; 452 u32 pingtimerset;
453 struct timer_list loadtimer; 453 struct timer_list loadtimer;
454 u32 loadtimerset; 454 u32 loadtimerset;
455 struct dentry *debugfs_entry; 455 struct dentry *debugfs_entry;
456 struct slic_spinlock upr_lock; 456 struct slic_spinlock upr_lock;
457 struct slic_spinlock bit64reglock; 457 struct slic_spinlock bit64reglock;
458 struct slic_rspqueue rspqueue; 458 struct slic_rspqueue rspqueue;
459 struct slic_rcvqueue rcvqueue; 459 struct slic_rcvqueue rcvqueue;
460 struct slic_cmdqueue cmdq_free; 460 struct slic_cmdqueue cmdq_free;
461 struct slic_cmdqueue cmdq_done; 461 struct slic_cmdqueue cmdq_done;
462 struct slic_cmdqueue cmdq_all; 462 struct slic_cmdqueue cmdq_all;
463 struct slic_cmdqmem cmdqmem; 463 struct slic_cmdqmem cmdqmem;
464 /* 464 /*
465 * SLIC Handles 465 * SLIC Handles
466 */ 466 */
467 struct slic_handle slic_handles[SLIC_CMDQ_MAXCMDS+1]; /* Object handles*/ 467 struct slic_handle slic_handles[SLIC_CMDQ_MAXCMDS+1]; /* Object handles*/
468 struct slic_handle *pfree_slic_handles; /* Free object handles*/ 468 struct slic_handle *pfree_slic_handles; /* Free object handles*/
469 struct slic_spinlock handle_lock; /* Object handle list lock*/ 469 struct slic_spinlock handle_lock; /* Object handle list lock*/
470 ushort slic_handle_ix; 470 ushort slic_handle_ix;
471 471
472 u32 xmitq_full; 472 u32 xmitq_full;
473 u32 all_reg_writes; 473 u32 all_reg_writes;
474 u32 icr_reg_writes; 474 u32 icr_reg_writes;
475 u32 isr_reg_writes; 475 u32 isr_reg_writes;
476 u32 error_interrupts; 476 u32 error_interrupts;
477 u32 error_rmiss_interrupts; 477 u32 error_rmiss_interrupts;
478 u32 rx_errors; 478 u32 rx_errors;
479 u32 rcv_drops; 479 u32 rcv_drops;
480 u32 rcv_interrupts; 480 u32 rcv_interrupts;
481 u32 xmit_interrupts; 481 u32 xmit_interrupts;
482 u32 linkevent_interrupts; 482 u32 linkevent_interrupts;
483 u32 upr_interrupts; 483 u32 upr_interrupts;
484 u32 num_isrs; 484 u32 num_isrs;
485 u32 false_interrupts; 485 u32 false_interrupts;
486 u32 tx_packets; 486 u32 tx_packets;
487 u32 xmit_completes; 487 u32 xmit_completes;
488 u32 tx_drops; 488 u32 tx_drops;
489 u32 rcv_broadcasts; 489 u32 rcv_broadcasts;
490 u32 rcv_multicasts; 490 u32 rcv_multicasts;
491 u32 rcv_unicasts; 491 u32 rcv_unicasts;
492 u32 max_isr_rcvs; 492 u32 max_isr_rcvs;
493 u32 max_isr_xmits; 493 u32 max_isr_xmits;
494 u32 rcv_interrupt_yields; 494 u32 rcv_interrupt_yields;
495 u32 intagg_period; 495 u32 intagg_period;
496 struct inicpm_state *inicpm_info; 496 struct inicpm_state *inicpm_info;
497 void *pinicpm_info; 497 void *pinicpm_info;
498 struct slic_reg_params reg_params; 498 struct slic_reg_params reg_params;
499 struct slic_ifevents if_events; 499 struct slic_ifevents if_events;
500 struct slic_stats inicstats_prev; 500 struct slic_stats inicstats_prev;
501 struct slicnet_stats slic_stats; 501 struct slicnet_stats slic_stats;
502}; 502};
503 503
504 504
505#define UPDATE_STATS(largestat, newstat, oldstat) \ 505#define UPDATE_STATS(largestat, newstat, oldstat) \
506{ \ 506{ \
507 if ((newstat) < (oldstat)) \ 507 if ((newstat) < (oldstat)) \
508 (largestat) += ((newstat) + (0xFFFFFFFF - oldstat + 1)); \ 508 (largestat) += ((newstat) + (0xFFFFFFFF - oldstat + 1)); \
509 else \ 509 else \
510 (largestat) += ((newstat) - (oldstat)); \ 510 (largestat) += ((newstat) - (oldstat)); \
511} 511}
512 512
513#define UPDATE_STATS_GB(largestat, newstat, oldstat) \ 513#define UPDATE_STATS_GB(largestat, newstat, oldstat) \
514{ \ 514{ \
515 (largestat) += ((newstat) - (oldstat)); \ 515 (largestat) += ((newstat) - (oldstat)); \
516} 516}
517 517
518#if BITS_PER_LONG == 64 518#if BITS_PER_LONG == 64
diff --git a/drivers/staging/slicoss/slichw.h b/drivers/staging/slicoss/slichw.h
index 6275d4529676..21cd02b8b7eb 100644
--- a/drivers/staging/slicoss/slichw.h
+++ b/drivers/staging/slicoss/slichw.h
@@ -450,7 +450,7 @@ struct slic_regs {
450 u32 pad34; 450 u32 pad34;
451#define SLIC_DBAR64 0x0108 451#define SLIC_DBAR64 0x0108
452 452
453 u32 slic_cbar64; /* 64 bit Xmt Cmd buf addr regs. */ 453 u32 slic_cbar64; /* 64 bit Xmt Cmd buf addr regs. */
454 u32 pad35; 454 u32 pad35;
455#define SLIC_CBAR64 0x0110 455#define SLIC_CBAR64 0x0110
456 456
@@ -478,11 +478,11 @@ struct slic_regs {
478 478
479 u32 slic_read_xf_info; /* Read Transformer info */ 479 u32 slic_read_xf_info; /* Read Transformer info */
480 u32 pad41; 480 u32 pad41;
481#define SLIC_READ_XF_INFO 0x0140 481#define SLIC_READ_XF_INFO 0x0140
482 482
483 u32 slic_write_xf_info; /* Write Transformer info */ 483 u32 slic_write_xf_info; /* Write Transformer info */
484 u32 pad42; 484 u32 pad42;
485#define SLIC_WRITE_XF_INFO 0x0148 485#define SLIC_WRITE_XF_INFO 0x0148
486 486
487 u32 RSVD1; /* TOE Only */ 487 u32 RSVD1; /* TOE Only */
488 u32 pad43; 488 u32 pad43;
diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c
index 78578ee59557..76fc2e554f35 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -144,24 +144,24 @@ MODULE_DEVICE_TABLE(pci, slic_pci_tbl);
144 144
145#define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \ 145#define SLIC_GET_SLIC_HANDLE(_adapter, _pslic_handle) \
146{ \ 146{ \
147 spin_lock_irqsave(&_adapter->handle_lock.lock, \ 147 spin_lock_irqsave(&_adapter->handle_lock.lock, \
148 _adapter->handle_lock.flags); \ 148 _adapter->handle_lock.flags); \
149 _pslic_handle = _adapter->pfree_slic_handles; \ 149 _pslic_handle = _adapter->pfree_slic_handles; \
150 if (_pslic_handle) { \ 150 if (_pslic_handle) { \
151 _adapter->pfree_slic_handles = _pslic_handle->next; \ 151 _adapter->pfree_slic_handles = _pslic_handle->next; \
152 } \ 152 } \
153 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \ 153 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
154 _adapter->handle_lock.flags); \ 154 _adapter->handle_lock.flags); \
155} 155}
156 156
157#define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \ 157#define SLIC_FREE_SLIC_HANDLE(_adapter, _pslic_handle) \
158{ \ 158{ \
159 _pslic_handle->type = SLIC_HANDLE_FREE; \ 159 _pslic_handle->type = SLIC_HANDLE_FREE; \
160 spin_lock_irqsave(&_adapter->handle_lock.lock, \ 160 spin_lock_irqsave(&_adapter->handle_lock.lock, \
161 _adapter->handle_lock.flags); \ 161 _adapter->handle_lock.flags); \
162 _pslic_handle->next = _adapter->pfree_slic_handles; \ 162 _pslic_handle->next = _adapter->pfree_slic_handles; \
163 _adapter->pfree_slic_handles = _pslic_handle; \ 163 _adapter->pfree_slic_handles = _pslic_handle; \
164 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \ 164 spin_unlock_irqrestore(&_adapter->handle_lock.lock, \
165 _adapter->handle_lock.flags); \ 165 _adapter->handle_lock.flags); \
166} 166}
167 167
@@ -209,7 +209,7 @@ static u32 slic_crc_init; /* Is table initialized */
209 */ 209 */
210static void slic_mcast_init_crc32(void) 210static void slic_mcast_init_crc32(void)
211{ 211{
212 u32 c; /* CRC shit reg */ 212 u32 c; /* CRC reg */
213 u32 e = 0; /* Poly X-or pattern */ 213 u32 e = 0; /* Poly X-or pattern */
214 int i; /* counter */ 214 int i; /* counter */
215 int k; /* byte being shifted into crc */ 215 int k; /* byte being shifted into crc */
@@ -2930,11 +2930,14 @@ static int slic_if_init(struct adapter *adapter)
2930 } 2930 }
2931 2931
2932 if (!adapter->queues_initialized) { 2932 if (!adapter->queues_initialized) {
2933 if ((rc = slic_rspqueue_init(adapter))) 2933 rc = slic_rspqueue_init(adapter);
2934 if (rc)
2934 goto err; 2935 goto err;
2935 if ((rc = slic_cmdq_init(adapter))) 2936 rc = slic_cmdq_init(adapter);
2937 if (rc)
2936 goto err; 2938 goto err;
2937 if ((rc = slic_rcvqueue_init(adapter))) 2939 rc = slic_rcvqueue_init(adapter);
2940 if (rc)
2938 goto err; 2941 goto err;
2939 adapter->queues_initialized = 1; 2942 adapter->queues_initialized = 1;
2940 } 2943 }
@@ -3437,7 +3440,7 @@ static int slic_card_init(struct sliccard *card, struct adapter *adapter)
3437 (eecodesize - 2)); 3440 (eecodesize - 2));
3438 /* 3441 /*
3439 if the ucdoe chksum flag bit worked, 3442 if the ucdoe chksum flag bit worked,
3440 we wouldn't need this shit 3443 we wouldn't need this
3441 */ 3444 */
3442 if (ee_chksum == calc_chksum) 3445 if (ee_chksum == calc_chksum)
3443 card->config.EepromValid = true; 3446 card->config.EepromValid = true;
diff --git a/drivers/staging/speakup/Kconfig b/drivers/staging/speakup/Kconfig
index d288cf03e14b..b416aceb13f2 100644
--- a/drivers/staging/speakup/Kconfig
+++ b/drivers/staging/speakup/Kconfig
@@ -8,7 +8,7 @@ config SPEAKUP
8 video console for blind people. If built in to the 8 video console for blind people. If built in to the
9 kernel, it can speak everything on the text console from 9 kernel, it can speak everything on the text console from
10 boot up to shutdown. For more information on Speakup, 10 boot up to shutdown. For more information on Speakup,
11 point your browser at http://www.linux-speakup.org/. 11 point your browser at <http://www.linux-speakup.org/>.
12 There is also a mailing list at the above url that you 12 There is also a mailing list at the above url that you
13 can subscribe to. 13 can subscribe to.
14 14
diff --git a/drivers/staging/speakup/buffers.c b/drivers/staging/speakup/buffers.c
index a2db956edd54..382973e8b80f 100644
--- a/drivers/staging/speakup/buffers.c
+++ b/drivers/staging/speakup/buffers.c
@@ -5,12 +5,12 @@
5#include "speakup.h" 5#include "speakup.h"
6#include "spk_priv.h" 6#include "spk_priv.h"
7 7
8#define synthBufferSize 8192 /* currently 8K bytes */ 8#define SYNTH_BUF_SIZE 8192 /* currently 8K bytes */
9 9
10static u_char synth_buffer[synthBufferSize]; /* guess what this is for! */ 10static u_char synth_buffer[SYNTH_BUF_SIZE]; /* guess what this is for! */
11static u_char *buff_in = synth_buffer; 11static u_char *buff_in = synth_buffer;
12static u_char *buff_out = synth_buffer; 12static u_char *buff_out = synth_buffer;
13static u_char *buffer_end = synth_buffer+synthBufferSize-1; 13static u_char *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
14 14
15/* These try to throttle applications by stopping the TTYs 15/* These try to throttle applications by stopping the TTYs
16 * Note: we need to make sure that we will restart them eventually, which is 16 * Note: we need to make sure that we will restart them eventually, which is
@@ -44,13 +44,13 @@ static void speakup_stop_ttys(void)
44 44
45static int synth_buffer_free(void) 45static int synth_buffer_free(void)
46{ 46{
47 int bytesFree; 47 int bytes_free;
48 48
49 if (buff_in >= buff_out) 49 if (buff_in >= buff_out)
50 bytesFree = synthBufferSize - (buff_in - buff_out); 50 bytes_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
51 else 51 else
52 bytesFree = buff_out - buff_in; 52 bytes_free = buff_out - buff_in;
53 return bytesFree; 53 return bytes_free;
54} 54}
55 55
56int synth_buffer_empty(void) 56int synth_buffer_empty(void)
diff --git a/drivers/staging/speakup/fakekey.c b/drivers/staging/speakup/fakekey.c
index 1b34a8771641..4299cf45f947 100644
--- a/drivers/staging/speakup/fakekey.c
+++ b/drivers/staging/speakup/fakekey.c
@@ -28,7 +28,7 @@
28#define PRESSED 1 28#define PRESSED 1
29#define RELEASED 0 29#define RELEASED 0
30 30
31DEFINE_PER_CPU(bool, reporting_keystroke); 31static DEFINE_PER_CPU(bool, reporting_keystroke);
32 32
33static struct input_dev *virt_keyboard; 33static struct input_dev *virt_keyboard;
34 34
diff --git a/drivers/staging/speakup/i18n.c b/drivers/staging/speakup/i18n.c
index 7c1658b971dc..2add1fcfd122 100644
--- a/drivers/staging/speakup/i18n.c
+++ b/drivers/staging/speakup/i18n.c
@@ -390,7 +390,7 @@ static struct msg_group_t all_groups[] = {
390 390
391static const int num_groups = sizeof(all_groups) / sizeof(struct msg_group_t); 391static const int num_groups = sizeof(all_groups) / sizeof(struct msg_group_t);
392 392
393char *msg_get(enum msg_index_t index) 393char *spk_msg_get(enum msg_index_t index)
394{ 394{
395 char *ch; 395 char *ch;
396 396
@@ -540,7 +540,7 @@ static int fmt_validate(char *template, char *user)
540 * -EINVAL - Invalid format specifiers in formatted message or illegal index. 540 * -EINVAL - Invalid format specifiers in formatted message or illegal index.
541 * -ENOMEM - Unable to allocate memory. 541 * -ENOMEM - Unable to allocate memory.
542*/ 542*/
543ssize_t msg_set(enum msg_index_t index, char *text, size_t length) 543ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
544{ 544{
545 int rc = 0; 545 int rc = 0;
546 char *newstr = NULL; 546 char *newstr = NULL;
@@ -576,7 +576,7 @@ ssize_t msg_set(enum msg_index_t index, char *text, size_t length)
576 * Find a message group, given its name. Return a pointer to the structure 576 * Find a message group, given its name. Return a pointer to the structure
577 * if found, or NULL otherwise. 577 * if found, or NULL otherwise.
578*/ 578*/
579struct msg_group_t *find_msg_group(const char *group_name) 579struct msg_group_t *spk_find_msg_group(const char *group_name)
580{ 580{
581 struct msg_group_t *group = NULL; 581 struct msg_group_t *group = NULL;
582 int i; 582 int i;
@@ -590,7 +590,7 @@ struct msg_group_t *find_msg_group(const char *group_name)
590 return group; 590 return group;
591} 591}
592 592
593void reset_msg_group(struct msg_group_t *group) 593void spk_reset_msg_group(struct msg_group_t *group)
594{ 594{
595 unsigned long flags; 595 unsigned long flags;
596 enum msg_index_t i; 596 enum msg_index_t i;
@@ -606,14 +606,14 @@ void reset_msg_group(struct msg_group_t *group)
606} 606}
607 607
608/* Called at initialization time, to establish default messages. */ 608/* Called at initialization time, to establish default messages. */
609void initialize_msgs(void) 609void spk_initialize_msgs(void)
610{ 610{
611 memcpy(speakup_msgs, speakup_default_msgs, 611 memcpy(speakup_msgs, speakup_default_msgs,
612 sizeof(speakup_default_msgs)); 612 sizeof(speakup_default_msgs));
613} 613}
614 614
615/* Free user-supplied strings when module is unloaded: */ 615/* Free user-supplied strings when module is unloaded: */
616void free_user_msgs(void) 616void spk_free_user_msgs(void)
617{ 617{
618 enum msg_index_t index; 618 enum msg_index_t index;
619 unsigned long flags; 619 unsigned long flags;
diff --git a/drivers/staging/speakup/i18n.h b/drivers/staging/speakup/i18n.h
index 65caa8010776..dd338f4218de 100644
--- a/drivers/staging/speakup/i18n.h
+++ b/drivers/staging/speakup/i18n.h
@@ -218,11 +218,11 @@ struct msg_group_t {
218 enum msg_index_t end; 218 enum msg_index_t end;
219}; 219};
220 220
221extern char *msg_get(enum msg_index_t index); 221extern char *spk_msg_get(enum msg_index_t index);
222extern ssize_t msg_set(enum msg_index_t index, char *text, size_t length); 222extern ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length);
223extern struct msg_group_t *find_msg_group(const char *group_name); 223extern struct msg_group_t *spk_find_msg_group(const char *group_name);
224extern void reset_msg_group(struct msg_group_t *group); 224extern void spk_reset_msg_group(struct msg_group_t *group);
225extern void initialize_msgs(void); 225extern void spk_initialize_msgs(void);
226extern void free_user_msgs(void); 226extern void spk_free_user_msgs(void);
227 227
228#endif 228#endif
diff --git a/drivers/staging/speakup/keyhelp.c b/drivers/staging/speakup/keyhelp.c
index 170f38815ffd..5091625a4901 100644
--- a/drivers/staging/speakup/keyhelp.c
+++ b/drivers/staging/speakup/keyhelp.c
@@ -115,10 +115,11 @@ static void say_key(int key)
115 key &= 0xff; 115 key &= 0xff;
116 for (i = 0; i < 6; i++) { 116 for (i = 0; i < 6; i++) {
117 if (state & masks[i]) 117 if (state & masks[i])
118 synth_printf(" %s", msg_get(MSG_STATES_START + i)); 118 synth_printf(" %s", spk_msg_get(MSG_STATES_START + i));
119 } 119 }
120 if ((key > 0) && (key <= num_key_names)) 120 if ((key > 0) && (key <= num_key_names))
121 synth_printf(" %s\n", msg_get(MSG_KEYNAMES_START + (key - 1))); 121 synth_printf(" %s\n",
122 spk_msg_get(MSG_KEYNAMES_START + (key - 1)));
122} 123}
123 124
124static int help_init(void) 125static int help_init(void)
@@ -126,9 +127,9 @@ static int help_init(void)
126 char start = SPACE; 127 char start = SPACE;
127 int i; 128 int i;
128 int num_funcs = MSG_FUNCNAMES_END - MSG_FUNCNAMES_START + 1; 129 int num_funcs = MSG_FUNCNAMES_END - MSG_FUNCNAMES_START + 1;
129state_tbl = our_keys[0]+SHIFT_TBL_SIZE+2; 130state_tbl = spk_our_keys[0]+SHIFT_TBL_SIZE+2;
130 for (i = 0; i < num_funcs; i++) { 131 for (i = 0; i < num_funcs; i++) {
131 char *cur_funcname = msg_get(MSG_FUNCNAMES_START + i); 132 char *cur_funcname = spk_msg_get(MSG_FUNCNAMES_START + i);
132 if (start == *cur_funcname) 133 if (start == *cur_funcname)
133 continue; 134 continue;
134 start = *cur_funcname; 135 start = *cur_funcname;
@@ -137,7 +138,7 @@ state_tbl = our_keys[0]+SHIFT_TBL_SIZE+2;
137 return 0; 138 return 0;
138} 139}
139 140
140int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key) 141int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
141{ 142{
142 int i, n; 143 int i, n;
143 char *name; 144 char *name;
@@ -147,15 +148,15 @@ int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
147 help_init(); 148 help_init();
148 if (type == KT_LATIN) { 149 if (type == KT_LATIN) {
149 if (ch == SPACE) { 150 if (ch == SPACE) {
150 special_handler = NULL; 151 spk_special_handler = NULL;
151 synth_printf("%s\n", msg_get(MSG_LEAVING_HELP)); 152 synth_printf("%s\n", spk_msg_get(MSG_LEAVING_HELP));
152 return 1; 153 return 1;
153 } 154 }
154 ch |= 32; /* lower case */ 155 ch |= 32; /* lower case */
155 if (ch < 'a' || ch > 'z') 156 if (ch < 'a' || ch > 'z')
156 return -1; 157 return -1;
157 if (letter_offsets[ch-'a'] == -1) { 158 if (letter_offsets[ch-'a'] == -1) {
158 synth_printf(msg_get(MSG_NO_COMMAND), ch); 159 synth_printf(spk_msg_get(MSG_NO_COMMAND), ch);
159 synth_printf("\n"); 160 synth_printf("\n");
160 return 1; 161 return 1;
161 } 162 }
@@ -169,47 +170,49 @@ int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key)
169 cur_item--; 170 cur_item--;
170 else 171 else
171 return -1; 172 return -1;
172 } else if (type == KT_SPKUP && ch == SPEAKUP_HELP && !special_handler) { 173 } else if (type == KT_SPKUP
173 special_handler = handle_help; 174 && ch == SPEAKUP_HELP
174 synth_printf("%s\n", msg_get(MSG_HELP_INFO)); 175 && !spk_special_handler) {
176 spk_special_handler = spk_handle_help;
177 synth_printf("%s\n", spk_msg_get(MSG_HELP_INFO));
175 build_key_data(); /* rebuild each time in case new mapping */ 178 build_key_data(); /* rebuild each time in case new mapping */
176 return 1; 179 return 1;
177 } else { 180 } else {
178 name = NULL; 181 name = NULL;
179 if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) { 182 if ((type != KT_SPKUP) && (key > 0) && (key <= num_key_names)) {
180 synth_printf("%s\n", 183 synth_printf("%s\n",
181 msg_get(MSG_KEYNAMES_START + key-1)); 184 spk_msg_get(MSG_KEYNAMES_START + key-1));
182 return 1; 185 return 1;
183 } 186 }
184 for (i = 0; funcvals[i] != 0 && !name; i++) { 187 for (i = 0; funcvals[i] != 0 && !name; i++) {
185 if (ch == funcvals[i]) 188 if (ch == funcvals[i])
186 name = msg_get(MSG_FUNCNAMES_START + i); 189 name = spk_msg_get(MSG_FUNCNAMES_START + i);
187 } 190 }
188 if (!name) 191 if (!name)
189 return -1; 192 return -1;
190 kp = our_keys[key]+1; 193 kp = spk_our_keys[key]+1;
191 for (i = 0; i < nstates; i++) { 194 for (i = 0; i < nstates; i++) {
192 if (ch == kp[i]) 195 if (ch == kp[i])
193 break; 196 break;
194 } 197 }
195 key += (state_tbl[i] << 8); 198 key += (state_tbl[i] << 8);
196 say_key(key); 199 say_key(key);
197 synth_printf(msg_get(MSG_KEYDESC), name); 200 synth_printf(spk_msg_get(MSG_KEYDESC), name);
198 synth_printf("\n"); 201 synth_printf("\n");
199 return 1; 202 return 1;
200 } 203 }
201 name = msg_get(MSG_FUNCNAMES_START + cur_item); 204 name = spk_msg_get(MSG_FUNCNAMES_START + cur_item);
202 func = funcvals[cur_item]; 205 func = funcvals[cur_item];
203 synth_printf("%s", name); 206 synth_printf("%s", name);
204 if (key_offsets[func] == 0) { 207 if (key_offsets[func] == 0) {
205 synth_printf(" %s\n", msg_get(MSG_IS_UNASSIGNED)); 208 synth_printf(" %s\n", spk_msg_get(MSG_IS_UNASSIGNED));
206 return 1; 209 return 1;
207 } 210 }
208 p_keys = key_data + key_offsets[func]; 211 p_keys = key_data + key_offsets[func];
209 for (n = 0; p_keys[n]; n++) { 212 for (n = 0; p_keys[n]; n++) {
210 val = p_keys[n]; 213 val = p_keys[n];
211 if (n > 0) 214 if (n > 0)
212 synth_printf("%s ", msg_get(MSG_DISJUNCTION)); 215 synth_printf("%s ", spk_msg_get(MSG_DISJUNCTION));
213 say_key(val); 216 say_key(val);
214 } 217 }
215 return 1; 218 return 1;
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index 2093896c546b..35f647ce1f1e 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -41,7 +41,7 @@ static ssize_t chars_chartab_show(struct kobject *kobj,
41 break; 41 break;
42 if (strcmp("characters", attr->attr.name) == 0) { 42 if (strcmp("characters", attr->attr.name) == 0) {
43 len = scnprintf(buf_pointer, bufsize, "%d\t%s\n", 43 len = scnprintf(buf_pointer, bufsize, "%d\t%s\n",
44 i, characters[i]); 44 i, spk_characters[i]);
45 } else { /* show chartab entry */ 45 } else { /* show chartab entry */
46 if (IS_TYPE(i, B_CTL)) 46 if (IS_TYPE(i, B_CTL))
47 cp = "B_CTL"; 47 cp = "B_CTL";
@@ -185,12 +185,12 @@ static ssize_t chars_chartab_store(struct kobject *kobj,
185 outptr[desc_length] = '\0'; 185 outptr[desc_length] = '\0';
186 186
187 if (do_characters) { 187 if (do_characters) {
188 if (characters[index] != default_chars[index]) 188 if (spk_characters[index] != spk_default_chars[index])
189 kfree(characters[index]); 189 kfree(spk_characters[index]);
190 characters[index] = desc; 190 spk_characters[index] = desc;
191 used++; 191 used++;
192 } else { 192 } else {
193 charclass = chartab_get_value(keyword); 193 charclass = spk_chartab_get_value(keyword);
194 if (charclass == 0) { 194 if (charclass == 0) {
195 rejected++; 195 rejected++;
196 cp = linefeed + 1; 196 cp = linefeed + 1;
@@ -206,9 +206,9 @@ static ssize_t chars_chartab_store(struct kobject *kobj,
206 206
207 if (reset) { 207 if (reset) {
208 if (do_characters) 208 if (do_characters)
209 reset_default_chars(); 209 spk_reset_default_chars();
210 else 210 else
211 reset_default_chartab(); 211 spk_reset_default_chartab();
212 } 212 }
213 213
214 spk_unlock(flags); 214 spk_unlock(flags);
@@ -232,7 +232,7 @@ static ssize_t keymap_show(struct kobject *kobj, struct kobj_attribute *attr,
232 u_char ch; 232 u_char ch;
233 unsigned long flags; 233 unsigned long flags;
234 spk_lock(flags); 234 spk_lock(flags);
235 cp1 = key_buf + SHIFT_TBL_SIZE; 235 cp1 = spk_key_buf + SHIFT_TBL_SIZE;
236 num_keys = (int)(*cp1); 236 num_keys = (int)(*cp1);
237 nstates = (int)cp1[1]; 237 nstates = (int)cp1[1];
238 cp += sprintf(cp, "%d, %d, %d,\n", KEY_MAP_VER, num_keys, nstates); 238 cp += sprintf(cp, "%d, %d, %d,\n", KEY_MAP_VER, num_keys, nstates);
@@ -271,7 +271,7 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr,
271 return -ENOMEM; 271 return -ENOMEM;
272 } 272 }
273 if (strchr("dDrR", *in_buff)) { 273 if (strchr("dDrR", *in_buff)) {
274 set_key_info(key_defaults, key_buf); 274 spk_set_key_info(spk_key_defaults, spk_key_buf);
275 pr_info("keymap set to default values\n"); 275 pr_info("keymap set to default values\n");
276 kfree(in_buff); 276 kfree(in_buff);
277 spk_unlock(flags); 277 spk_unlock(flags);
@@ -282,14 +282,14 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr,
282 cp = in_buff; 282 cp = in_buff;
283 cp1 = (u_char *)in_buff; 283 cp1 = (u_char *)in_buff;
284 for (i = 0; i < 3; i++) { 284 for (i = 0; i < 3; i++) {
285 cp = s2uchar(cp, cp1); 285 cp = spk_s2uchar(cp, cp1);
286 cp1++; 286 cp1++;
287 } 287 }
288 i = (int)cp1[-2]+1; 288 i = (int)cp1[-2]+1;
289 i *= (int)cp1[-1]+1; 289 i *= (int)cp1[-1]+1;
290 i += 2; /* 0 and last map ver */ 290 i += 2; /* 0 and last map ver */
291 if (cp1[-3] != KEY_MAP_VER || cp1[-1] > 10 || 291 if (cp1[-3] != KEY_MAP_VER || cp1[-1] > 10 ||
292 i+SHIFT_TBL_SIZE+4 >= sizeof(key_buf)) { 292 i+SHIFT_TBL_SIZE+4 >= sizeof(spk_key_buf)) {
293 pr_warn("i %d %d %d %d\n", i, 293 pr_warn("i %d %d %d %d\n", i,
294 (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]); 294 (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]);
295 kfree(in_buff); 295 kfree(in_buff);
@@ -297,7 +297,7 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr,
297 return -EINVAL; 297 return -EINVAL;
298 } 298 }
299 while (--i >= 0) { 299 while (--i >= 0) {
300 cp = s2uchar(cp, cp1); 300 cp = spk_s2uchar(cp, cp1);
301 cp1++; 301 cp1++;
302 if (!(*cp)) 302 if (!(*cp))
303 break; 303 break;
@@ -307,8 +307,8 @@ static ssize_t keymap_store(struct kobject *kobj, struct kobj_attribute *attr,
307 pr_warn("end %d %d %d %d\n", i, 307 pr_warn("end %d %d %d %d\n", i,
308 (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]); 308 (int)cp1[-3], (int)cp1[-2], (int)cp1[-1]);
309 } else { 309 } else {
310 if (set_key_info(in_buff, key_buf)) { 310 if (spk_set_key_info(in_buff, spk_key_buf)) {
311 set_key_info(key_defaults, key_buf); 311 spk_set_key_info(spk_key_defaults, spk_key_buf);
312 ret = -EINVAL; 312 ret = -EINVAL;
313 pr_warn("set key failed\n"); 313 pr_warn("set key failed\n");
314 } 314 }
@@ -343,7 +343,7 @@ static ssize_t silent_store(struct kobject *kobj, struct kobj_attribute *attr,
343 spk_lock(flags); 343 spk_lock(flags);
344 if (ch&2) { 344 if (ch&2) {
345 shut = 1; 345 shut = 1;
346 do_flush(); 346 spk_do_flush();
347 } else { 347 } else {
348 shut = 0; 348 shut = 0;
349 } 349 }
@@ -388,7 +388,7 @@ static ssize_t synth_store(struct kobject *kobj, struct kobj_attribute *attr,
388 if (new_synth_name[len - 1] == '\n') 388 if (new_synth_name[len - 1] == '\n')
389 len--; 389 len--;
390 new_synth_name[len] = '\0'; 390 new_synth_name[len] = '\0';
391 strlwr(new_synth_name); 391 spk_strlwr(new_synth_name);
392 if ((synth != NULL) && (!strcmp(new_synth_name, synth->name))) { 392 if ((synth != NULL) && (!strcmp(new_synth_name, synth->name))) {
393 pr_warn("%s already in use\n", new_synth_name); 393 pr_warn("%s already in use\n", new_synth_name);
394 } else if (synth_init(new_synth_name) != 0) { 394 } else if (synth_init(new_synth_name) != 0) {
@@ -417,7 +417,7 @@ static ssize_t synth_direct_store(struct kobject *kobj,
417 bytes = min_t(size_t, len, 250); 417 bytes = min_t(size_t, len, 250);
418 strncpy(tmp, ptr, bytes); 418 strncpy(tmp, ptr, bytes);
419 tmp[bytes] = '\0'; 419 tmp[bytes] = '\0';
420 xlate(tmp); 420 spk_xlate(tmp);
421 synth_printf("%s", tmp); 421 synth_printf("%s", tmp);
422 ptr += bytes; 422 ptr += bytes;
423 len -= bytes; 423 len -= bytes;
@@ -455,14 +455,14 @@ static ssize_t punc_show(struct kobject *kobj, struct kobj_attribute *attr,
455 short mask; 455 short mask;
456 unsigned long flags; 456 unsigned long flags;
457 457
458 p_header = var_header_by_name(attr->attr.name); 458 p_header = spk_var_header_by_name(attr->attr.name);
459 if (p_header == NULL) { 459 if (p_header == NULL) {
460 pr_warn("p_header is null, attr->attr.name is %s\n", 460 pr_warn("p_header is null, attr->attr.name is %s\n",
461 attr->attr.name); 461 attr->attr.name);
462 return -EINVAL; 462 return -EINVAL;
463 } 463 }
464 464
465 var = get_punc_var(p_header->var_id); 465 var = spk_get_punc_var(p_header->var_id);
466 if (var == NULL) { 466 if (var == NULL) {
467 pr_warn("var is null, p_header->var_id is %i\n", 467 pr_warn("var is null, p_header->var_id is %i\n",
468 p_header->var_id); 468 p_header->var_id);
@@ -470,7 +470,7 @@ static ssize_t punc_show(struct kobject *kobj, struct kobj_attribute *attr,
470 } 470 }
471 471
472 spk_lock(flags); 472 spk_lock(flags);
473 pb = (struct st_bits_data *) &punc_info[var->value]; 473 pb = (struct st_bits_data *) &spk_punc_info[var->value];
474 mask = pb->mask; 474 mask = pb->mask;
475 for (i = 33; i < 128; i++) { 475 for (i = 33; i < 128; i++) {
476 if (!(spk_chartab[i]&mask)) 476 if (!(spk_chartab[i]&mask))
@@ -497,14 +497,14 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr,
497 if (x < 1 || x > 99) 497 if (x < 1 || x > 99)
498 return -EINVAL; 498 return -EINVAL;
499 499
500 p_header = var_header_by_name(attr->attr.name); 500 p_header = spk_var_header_by_name(attr->attr.name);
501 if (p_header == NULL) { 501 if (p_header == NULL) {
502 pr_warn("p_header is null, attr->attr.name is %s\n", 502 pr_warn("p_header is null, attr->attr.name is %s\n",
503 attr->attr.name); 503 attr->attr.name);
504 return -EINVAL; 504 return -EINVAL;
505 } 505 }
506 506
507 var = get_punc_var(p_header->var_id); 507 var = spk_get_punc_var(p_header->var_id);
508 if (var == NULL) { 508 if (var == NULL) {
509 pr_warn("var is null, p_header->var_id is %i\n", 509 pr_warn("var is null, p_header->var_id is %i\n",
510 p_header->var_id); 510 p_header->var_id);
@@ -520,9 +520,9 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr,
520 spk_lock(flags); 520 spk_lock(flags);
521 521
522 if (*punc_buf == 'd' || *punc_buf == 'r') 522 if (*punc_buf == 'd' || *punc_buf == 'r')
523 x = set_mask_bits(0, var->value, 3); 523 x = spk_set_mask_bits(0, var->value, 3);
524 else 524 else
525 x = set_mask_bits(punc_buf, var->value, 3); 525 x = spk_set_mask_bits(punc_buf, var->value, 3);
526 526
527 spk_unlock(flags); 527 spk_unlock(flags);
528 return count; 528 return count;
@@ -542,7 +542,7 @@ ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
542 char ch; 542 char ch;
543 unsigned long flags; 543 unsigned long flags;
544 544
545 param = var_header_by_name(attr->attr.name); 545 param = spk_var_header_by_name(attr->attr.name);
546 if (param == NULL) 546 if (param == NULL)
547 return -EINVAL; 547 return -EINVAL;
548 548
@@ -599,13 +599,13 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
599 int value; 599 int value;
600 unsigned long flags; 600 unsigned long flags;
601 601
602 param = var_header_by_name(attr->attr.name); 602 param = spk_var_header_by_name(attr->attr.name);
603 if (param == NULL) 603 if (param == NULL)
604 return -EINVAL; 604 return -EINVAL;
605 if (param->data == NULL) 605 if (param->data == NULL)
606 return 0; 606 return 0;
607 ret = 0; 607 ret = 0;
608 cp = xlate((char *) buf); 608 cp = spk_xlate((char *) buf);
609 609
610 spk_lock(flags); 610 spk_lock(flags);
611 switch (param->var_type) { 611 switch (param->var_type) {
@@ -618,7 +618,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
618 else 618 else
619 len = E_SET; 619 len = E_SET;
620 speakup_s2i(cp, &value); 620 speakup_s2i(cp, &value);
621 ret = set_num_var(value, param, len); 621 ret = spk_set_num_var(value, param, len);
622 if (ret == E_RANGE) { 622 if (ret == E_RANGE) {
623 var_data = param->data; 623 var_data = param->data;
624 pr_warn("value for %s out of range, expect %d to %d\n", 624 pr_warn("value for %s out of range, expect %d to %d\n",
@@ -636,7 +636,7 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
636 } 636 }
637 cp = (char *) buf; 637 cp = (char *) buf;
638 cp[len] = '\0'; 638 cp[len] = '\0';
639 ret = set_string_var(buf, param, len); 639 ret = spk_set_string_var(buf, param, len);
640 if (ret == E_TOOLONG) 640 if (ret == E_TOOLONG)
641 pr_warn("value too long for %s\n", 641 pr_warn("value too long for %s\n",
642 attr->attr.name); 642 attr->attr.name);
@@ -652,19 +652,19 @@ ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
652 */ 652 */
653 if (strcmp(attr->attr.name, "voice") == 0) { 653 if (strcmp(attr->attr.name, "voice") == 0) {
654 if (synth && synth->default_pitch) { 654 if (synth && synth->default_pitch) {
655 param = var_header_by_name("pitch"); 655 param = spk_var_header_by_name("pitch");
656 if (param) { 656 if (param) {
657 set_num_var(synth->default_pitch[value], param, 657 spk_set_num_var(synth->default_pitch[value],
658 E_NEW_DEFAULT); 658 param, E_NEW_DEFAULT);
659 set_num_var(0, param, E_DEFAULT); 659 spk_set_num_var(0, param, E_DEFAULT);
660 } 660 }
661 } 661 }
662 if (synth && synth->default_vol) { 662 if (synth && synth->default_vol) {
663 param = var_header_by_name("vol"); 663 param = spk_var_header_by_name("vol");
664 if (param) { 664 if (param) {
665 set_num_var(synth->default_vol[value], param, 665 spk_set_num_var(synth->default_vol[value],
666 E_NEW_DEFAULT); 666 param, E_NEW_DEFAULT);
667 set_num_var(0, param, E_DEFAULT); 667 spk_set_num_var(0, param, E_DEFAULT);
668 } 668 }
669 } 669 }
670 } 670 }
@@ -694,7 +694,7 @@ static ssize_t message_show_helper(char *buf, enum msg_index_t first,
694 if (bufsize <= 1) 694 if (bufsize <= 1)
695 break; 695 break;
696 printed = scnprintf(buf_pointer, bufsize, "%d\t%s\n", 696 printed = scnprintf(buf_pointer, bufsize, "%d\t%s\n",
697 index, msg_get(cursor)); 697 index, spk_msg_get(cursor));
698 buf_pointer += printed; 698 buf_pointer += printed;
699 bufsize -= printed; 699 bufsize -= printed;
700 } 700 }
@@ -788,7 +788,7 @@ static ssize_t message_store_helper(const char *buf, size_t count,
788 continue; 788 continue;
789 } 789 }
790 790
791 msg_stored = msg_set(curmessage, temp, desc_length); 791 msg_stored = spk_msg_set(curmessage, temp, desc_length);
792 if (msg_stored < 0) { 792 if (msg_stored < 0) {
793 retval = msg_stored; 793 retval = msg_stored;
794 if (msg_stored == -ENOMEM) 794 if (msg_stored == -ENOMEM)
@@ -802,7 +802,7 @@ static ssize_t message_store_helper(const char *buf, size_t count,
802 } 802 }
803 803
804 if (reset) 804 if (reset)
805 reset_msg_group(group); 805 spk_reset_msg_group(group);
806 806
807 report_msg_status(reset, received, used, rejected, group->name); 807 report_msg_status(reset, received, used, rejected, group->name);
808 return retval; 808 return retval;
@@ -812,7 +812,7 @@ static ssize_t message_show(struct kobject *kobj,
812 struct kobj_attribute *attr, char *buf) 812 struct kobj_attribute *attr, char *buf)
813{ 813{
814 ssize_t retval = 0; 814 ssize_t retval = 0;
815 struct msg_group_t *group = find_msg_group(attr->attr.name); 815 struct msg_group_t *group = spk_find_msg_group(attr->attr.name);
816 unsigned long flags; 816 unsigned long flags;
817 817
818 BUG_ON(!group); 818 BUG_ON(!group);
@@ -826,7 +826,7 @@ static ssize_t message_store(struct kobject *kobj, struct kobj_attribute *attr,
826 const char *buf, size_t count) 826 const char *buf, size_t count)
827{ 827{
828 ssize_t retval = 0; 828 ssize_t retval = 0;
829 struct msg_group_t *group = find_msg_group(attr->attr.name); 829 struct msg_group_t *group = spk_find_msg_group(attr->attr.name);
830 830
831 BUG_ON(!group); 831 BUG_ON(!group);
832 retval = message_store_helper(buf, count, group); 832 retval = message_store_helper(buf, count, group);
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index 40e2488b9679..9916e94aa361 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -65,23 +65,23 @@ MODULE_VERSION(SPEAKUP_VERSION);
65 65
66char *synth_name; 66char *synth_name;
67module_param_named(synth, synth_name, charp, S_IRUGO); 67module_param_named(synth, synth_name, charp, S_IRUGO);
68module_param_named(quiet, quiet_boot, bool, S_IRUGO); 68module_param_named(quiet, spk_quiet_boot, bool, S_IRUGO);
69 69
70MODULE_PARM_DESC(synth, "Synth to start if speakup is built in."); 70MODULE_PARM_DESC(synth, "Synth to start if speakup is built in.");
71MODULE_PARM_DESC(quiet, "Do not announce when the synthesizer is found."); 71MODULE_PARM_DESC(quiet, "Do not announce when the synthesizer is found.");
72 72
73special_func special_handler; 73special_func spk_special_handler;
74 74
75short pitch_shift, synth_flags; 75short spk_pitch_shift, synth_flags;
76static char buf[256]; 76static char buf[256];
77int attrib_bleep, bleeps, bleep_time = 10; 77int spk_attrib_bleep, spk_bleeps, spk_bleep_time = 10;
78int no_intr, spell_delay; 78int spk_no_intr, spk_spell_delay;
79int key_echo, say_word_ctl; 79int spk_key_echo, spk_say_word_ctl;
80int say_ctrl, bell_pos; 80int spk_say_ctrl, spk_bell_pos;
81short punc_mask; 81short spk_punc_mask;
82int punc_level, reading_punc; 82int spk_punc_level, spk_reading_punc;
83char str_caps_start[MAXVARLEN + 1] = "\0", str_caps_stop[MAXVARLEN + 1] = "\0"; 83char spk_str_caps_start[MAXVARLEN + 1] = "\0", spk_str_caps_stop[MAXVARLEN + 1] = "\0";
84const struct st_bits_data punc_info[] = { 84const struct st_bits_data spk_punc_info[] = {
85 {"none", "", 0}, 85 {"none", "", 0},
86 {"some", "/$%&@", SOME}, 86 {"some", "/$%&@", SOME},
87 {"most", "$%&#()=+*/@^<>|\\", MOST}, 87 {"most", "$%&#()=+*/@^<>|\\", MOST},
@@ -95,9 +95,9 @@ const struct st_bits_data punc_info[] = {
95 95
96static char mark_cut_flag; 96static char mark_cut_flag;
97#define MAX_KEY 160 97#define MAX_KEY 160
98u_char *our_keys[MAX_KEY], *shift_table; 98u_char *spk_our_keys[MAX_KEY], *spk_shift_table;
99u_char key_buf[600]; 99u_char spk_key_buf[600];
100const u_char key_defaults[] = { 100const u_char spk_key_defaults[] = {
101#include "speakupmap.h" 101#include "speakupmap.h"
102}; 102};
103 103
@@ -129,9 +129,9 @@ static char *phonetic[] = {
129/* array of 256 char pointers (one for each character description) 129/* array of 256 char pointers (one for each character description)
130 * initialized to default_chars and user selectable via 130 * initialized to default_chars and user selectable via
131 * /proc/speakup/characters */ 131 * /proc/speakup/characters */
132char *characters[256]; 132char *spk_characters[256];
133 133
134char *default_chars[256] = { 134char *spk_default_chars[256] = {
135/*000*/ "null", "^a", "^b", "^c", "^d", "^e", "^f", "^g", 135/*000*/ "null", "^a", "^b", "^c", "^d", "^e", "^f", "^g",
136/*008*/ "^h", "^i", "^j", "^k", "^l", "^m", "^n", "^o", 136/*008*/ "^h", "^i", "^j", "^k", "^l", "^m", "^n", "^o",
137/*016*/ "^p", "^q", "^r", "^s", "^t", "^u", "^v", "^w", 137/*016*/ "^p", "^q", "^r", "^s", "^t", "^u", "^v", "^w",
@@ -238,7 +238,7 @@ static u_short default_chartab[256] = {
238}; 238};
239 239
240struct task_struct *speakup_task; 240struct task_struct *speakup_task;
241struct bleep unprocessed_sound; 241struct bleep spk_unprocessed_sound;
242static int spk_keydown; 242static int spk_keydown;
243static u_char spk_lastkey, spk_close_press, keymap_flags; 243static u_char spk_lastkey, spk_close_press, keymap_flags;
244static u_char last_keycode, this_speakup_key; 244static u_char last_keycode, this_speakup_key;
@@ -251,14 +251,14 @@ DEFINE_MUTEX(spk_mutex);
251static int keyboard_notifier_call(struct notifier_block *, 251static int keyboard_notifier_call(struct notifier_block *,
252 unsigned long code, void *param); 252 unsigned long code, void *param);
253 253
254struct notifier_block keyboard_notifier_block = { 254static struct notifier_block keyboard_notifier_block = {
255 .notifier_call = keyboard_notifier_call, 255 .notifier_call = keyboard_notifier_call,
256}; 256};
257 257
258static int vt_notifier_call(struct notifier_block *, 258static int vt_notifier_call(struct notifier_block *,
259 unsigned long code, void *param); 259 unsigned long code, void *param);
260 260
261struct notifier_block vt_notifier_block = { 261static struct notifier_block vt_notifier_block = {
262 .notifier_call = vt_notifier_call, 262 .notifier_call = vt_notifier_call,
263}; 263};
264 264
@@ -282,13 +282,13 @@ static void bleep(u_short val)
282 350, 370, 392, 414, 440, 466, 491, 523, 554, 587, 619, 659 282 350, 370, 392, 414, 440, 466, 491, 523, 554, 587, 619, 659
283 }; 283 };
284 short freq; 284 short freq;
285 int time = bleep_time; 285 int time = spk_bleep_time;
286 freq = vals[val % 12]; 286 freq = vals[val % 12];
287 if (val > 11) 287 if (val > 11)
288 freq *= (1 << (val / 12)); 288 freq *= (1 << (val / 12));
289 unprocessed_sound.freq = freq; 289 spk_unprocessed_sound.freq = freq;
290 unprocessed_sound.jiffies = msecs_to_jiffies(time); 290 spk_unprocessed_sound.jiffies = msecs_to_jiffies(time);
291 unprocessed_sound.active = 1; 291 spk_unprocessed_sound.active = 1;
292 /* We can only have 1 active sound at a time. */ 292 /* We can only have 1 active sound at a time. */
293} 293}
294 294
@@ -300,7 +300,7 @@ static void speakup_shut_up(struct vc_data *vc)
300 spk_parked &= 0xfe; 300 spk_parked &= 0xfe;
301 speakup_date(vc); 301 speakup_date(vc);
302 if (synth != NULL) 302 if (synth != NULL)
303 do_flush(); 303 spk_do_flush();
304} 304}
305 305
306static void speech_kill(struct vc_data *vc) 306static void speech_kill(struct vc_data *vc)
@@ -313,9 +313,9 @@ static void speech_kill(struct vc_data *vc)
313 if (val == 2 || spk_killed) { 313 if (val == 2 || spk_killed) {
314 /* dead */ 314 /* dead */
315 spk_shut_up &= ~0x40; 315 spk_shut_up &= ~0x40;
316 synth_printf("%s\n", msg_get(MSG_IAM_ALIVE)); 316 synth_printf("%s\n", spk_msg_get(MSG_IAM_ALIVE));
317 } else { 317 } else {
318 synth_printf("%s\n", msg_get(MSG_YOU_KILLED_SPEAKUP)); 318 synth_printf("%s\n", spk_msg_get(MSG_YOU_KILLED_SPEAKUP));
319 spk_shut_up |= 0x40; 319 spk_shut_up |= 0x40;
320 } 320 }
321} 321}
@@ -324,10 +324,10 @@ static void speakup_off(struct vc_data *vc)
324{ 324{
325 if (spk_shut_up & 0x80) { 325 if (spk_shut_up & 0x80) {
326 spk_shut_up &= 0x7f; 326 spk_shut_up &= 0x7f;
327 synth_printf("%s\n", msg_get(MSG_HEY_THATS_BETTER)); 327 synth_printf("%s\n", spk_msg_get(MSG_HEY_THATS_BETTER));
328 } else { 328 } else {
329 spk_shut_up |= 0x80; 329 spk_shut_up |= 0x80;
330 synth_printf("%s\n", msg_get(MSG_YOU_TURNED_ME_OFF)); 330 synth_printf("%s\n", spk_msg_get(MSG_YOU_TURNED_ME_OFF));
331 } 331 }
332 speakup_date(vc); 332 speakup_date(vc);
333} 333}
@@ -336,10 +336,10 @@ static void speakup_parked(struct vc_data *vc)
336{ 336{
337 if (spk_parked & 0x80) { 337 if (spk_parked & 0x80) {
338 spk_parked = 0; 338 spk_parked = 0;
339 synth_printf("%s\n", msg_get(MSG_UNPARKED)); 339 synth_printf("%s\n", spk_msg_get(MSG_UNPARKED));
340 } else { 340 } else {
341 spk_parked |= 0x80; 341 spk_parked |= 0x80;
342 synth_printf("%s\n", msg_get(MSG_PARKED)); 342 synth_printf("%s\n", spk_msg_get(MSG_PARKED));
343 } 343 }
344} 344}
345 345
@@ -350,16 +350,16 @@ static void speakup_cut(struct vc_data *vc)
350 350
351 if (!mark_cut_flag) { 351 if (!mark_cut_flag) {
352 mark_cut_flag = 1; 352 mark_cut_flag = 1;
353 xs = (u_short) spk_x; 353 spk_xs = (u_short) spk_x;
354 ys = (u_short) spk_y; 354 spk_ys = (u_short) spk_y;
355 spk_sel_cons = vc; 355 spk_sel_cons = vc;
356 synth_printf("%s\n", msg_get(MSG_MARK)); 356 synth_printf("%s\n", spk_msg_get(MSG_MARK));
357 return; 357 return;
358 } 358 }
359 xe = (u_short) spk_x; 359 spk_xe = (u_short) spk_x;
360 ye = (u_short) spk_y; 360 spk_ye = (u_short) spk_y;
361 mark_cut_flag = 0; 361 mark_cut_flag = 0;
362 synth_printf("%s\n", msg_get(MSG_CUT)); 362 synth_printf("%s\n", spk_msg_get(MSG_CUT));
363 363
364 speakup_clear_selection(); 364 speakup_clear_selection();
365 ret = speakup_set_selection(tty); 365 ret = speakup_set_selection(tty);
@@ -383,9 +383,9 @@ static void speakup_paste(struct vc_data *vc)
383{ 383{
384 if (mark_cut_flag) { 384 if (mark_cut_flag) {
385 mark_cut_flag = 0; 385 mark_cut_flag = 0;
386 synth_printf("%s\n", msg_get(MSG_MARK_CLEARED)); 386 synth_printf("%s\n", spk_msg_get(MSG_MARK_CLEARED));
387 } else { 387 } else {
388 synth_printf("%s\n", msg_get(MSG_PASTE)); 388 synth_printf("%s\n", spk_msg_get(MSG_PASTE));
389 speakup_paste_selection(tty); 389 speakup_paste_selection(tty);
390 } 390 }
391} 391}
@@ -395,16 +395,16 @@ static void say_attributes(struct vc_data *vc)
395 int fg = spk_attr & 0x0f; 395 int fg = spk_attr & 0x0f;
396 int bg = spk_attr >> 4; 396 int bg = spk_attr >> 4;
397 if (fg > 8) { 397 if (fg > 8) {
398 synth_printf("%s ", msg_get(MSG_BRIGHT)); 398 synth_printf("%s ", spk_msg_get(MSG_BRIGHT));
399 fg -= 8; 399 fg -= 8;
400 } 400 }
401 synth_printf("%s", msg_get(MSG_COLORS_START + fg)); 401 synth_printf("%s", spk_msg_get(MSG_COLORS_START + fg));
402 if (bg > 7) { 402 if (bg > 7) {
403 synth_printf(" %s ", msg_get(MSG_ON_BLINKING)); 403 synth_printf(" %s ", spk_msg_get(MSG_ON_BLINKING));
404 bg -= 8; 404 bg -= 8;
405 } else 405 } else
406 synth_printf(" %s ", msg_get(MSG_ON)); 406 synth_printf(" %s ", spk_msg_get(MSG_ON));
407 synth_printf("%s\n", msg_get(MSG_COLORS_START + bg)); 407 synth_printf("%s\n", spk_msg_get(MSG_COLORS_START + bg));
408} 408}
409 409
410enum { 410enum {
@@ -417,24 +417,24 @@ enum {
417 417
418static void announce_edge(struct vc_data *vc, int msg_id) 418static void announce_edge(struct vc_data *vc, int msg_id)
419{ 419{
420 if (bleeps & 1) 420 if (spk_bleeps & 1)
421 bleep(spk_y); 421 bleep(spk_y);
422 if ((bleeps & 2) && (msg_id < edge_quiet)) 422 if ((spk_bleeps & 2) && (msg_id < edge_quiet))
423 synth_printf("%s\n", msg_get(MSG_EDGE_MSGS_START + msg_id - 1)); 423 synth_printf("%s\n", spk_msg_get(MSG_EDGE_MSGS_START + msg_id - 1));
424} 424}
425 425
426static void speak_char(u_char ch) 426static void speak_char(u_char ch)
427{ 427{
428 char *cp = characters[ch]; 428 char *cp = spk_characters[ch];
429 struct var_t *direct = get_var(DIRECT); 429 struct var_t *direct = spk_get_var(DIRECT);
430 if (direct && direct->u.n.value) { 430 if (direct && direct->u.n.value) {
431 if (IS_CHAR(ch, B_CAP)) { 431 if (IS_CHAR(ch, B_CAP)) {
432 pitch_shift++; 432 spk_pitch_shift++;
433 synth_printf("%s", str_caps_start); 433 synth_printf("%s", spk_str_caps_start);
434 } 434 }
435 synth_printf("%c", ch); 435 synth_printf("%c", ch);
436 if (IS_CHAR(ch, B_CAP)) 436 if (IS_CHAR(ch, B_CAP))
437 synth_printf("%s", str_caps_stop); 437 synth_printf("%s", spk_str_caps_stop);
438 return; 438 return;
439 } 439 }
440 if (cp == NULL) { 440 if (cp == NULL) {
@@ -443,13 +443,13 @@ static void speak_char(u_char ch)
443 } 443 }
444 synth_buffer_add(SPACE); 444 synth_buffer_add(SPACE);
445 if (IS_CHAR(ch, B_CAP)) { 445 if (IS_CHAR(ch, B_CAP)) {
446 pitch_shift++; 446 spk_pitch_shift++;
447 synth_printf("%s", str_caps_start); 447 synth_printf("%s", spk_str_caps_start);
448 synth_printf("%s", cp); 448 synth_printf("%s", cp);
449 synth_printf("%s", str_caps_stop); 449 synth_printf("%s", spk_str_caps_stop);
450 } else { 450 } else {
451 if (*cp == '^') { 451 if (*cp == '^') {
452 synth_printf("%s", msg_get(MSG_CTRL)); 452 synth_printf("%s", spk_msg_get(MSG_CTRL));
453 cp++; 453 cp++;
454 } 454 }
455 synth_printf("%s", cp); 455 synth_printf("%s", cp);
@@ -479,9 +479,9 @@ static void say_char(struct vc_data *vc)
479 spk_old_attr = spk_attr; 479 spk_old_attr = spk_attr;
480 ch = get_char(vc, (u_short *) spk_pos, &spk_attr); 480 ch = get_char(vc, (u_short *) spk_pos, &spk_attr);
481 if (spk_attr != spk_old_attr) { 481 if (spk_attr != spk_old_attr) {
482 if (attrib_bleep & 1) 482 if (spk_attrib_bleep & 1)
483 bleep(spk_y); 483 bleep(spk_y);
484 if (attrib_bleep & 2) 484 if (spk_attrib_bleep & 2)
485 say_attributes(vc); 485 say_attributes(vc);
486 } 486 }
487 speak_char(ch & 0xff); 487 speak_char(ch & 0xff);
@@ -497,7 +497,7 @@ static void say_phonetic_char(struct vc_data *vc)
497 synth_printf("%s\n", phonetic[--ch]); 497 synth_printf("%s\n", phonetic[--ch]);
498 } else { 498 } else {
499 if (IS_CHAR(ch, B_NUM)) 499 if (IS_CHAR(ch, B_NUM))
500 synth_printf("%s ", msg_get(MSG_NUMBER)); 500 synth_printf("%s ", spk_msg_get(MSG_NUMBER));
501 speak_char(ch); 501 speak_char(ch);
502 } 502 }
503} 503}
@@ -527,8 +527,8 @@ static void say_next_char(struct vc_data *vc)
527} 527}
528 528
529/* get_word - will first check to see if the character under the 529/* get_word - will first check to see if the character under the
530 * reading cursor is a space and if say_word_ctl is true it will 530 * reading cursor is a space and if spk_say_word_ctl is true it will
531 * return the word space. If say_word_ctl is not set it will check to 531 * return the word space. If spk_say_word_ctl is not set it will check to
532 * see if there is a word starting on the next position to the right 532 * see if there is a word starting on the next position to the right
533 * and return that word if it exists. If it does not exist it will 533 * and return that word if it exists. If it does not exist it will
534 * move left to the beginning of any previous word on the line or the 534 * move left to the beginning of any previous word on the line or the
@@ -544,9 +544,9 @@ static u_long get_word(struct vc_data *vc)
544 ch = (char)get_char(vc, (u_short *) tmp_pos, &temp); 544 ch = (char)get_char(vc, (u_short *) tmp_pos, &temp);
545 545
546/* decided to take out the sayword if on a space (mis-information */ 546/* decided to take out the sayword if on a space (mis-information */
547 if (say_word_ctl && ch == SPACE) { 547 if (spk_say_word_ctl && ch == SPACE) {
548 *buf = '\0'; 548 *buf = '\0';
549 synth_printf("%s\n", msg_get(MSG_SPACE)); 549 synth_printf("%s\n", spk_msg_get(MSG_SPACE));
550 return 0; 550 return 0;
551 } else if ((tmpx < vc->vc_cols - 2) 551 } else if ((tmpx < vc->vc_cols - 2)
552 && (ch == SPACE || ch == 0 || IS_WDLM(ch)) 552 && (ch == SPACE || ch == 0 || IS_WDLM(ch))
@@ -582,13 +582,13 @@ static u_long get_word(struct vc_data *vc)
582static void say_word(struct vc_data *vc) 582static void say_word(struct vc_data *vc)
583{ 583{
584 u_long cnt = get_word(vc); 584 u_long cnt = get_word(vc);
585 u_short saved_punc_mask = punc_mask; 585 u_short saved_punc_mask = spk_punc_mask;
586 if (cnt == 0) 586 if (cnt == 0)
587 return; 587 return;
588 punc_mask = PUNC; 588 spk_punc_mask = PUNC;
589 buf[cnt++] = SPACE; 589 buf[cnt++] = SPACE;
590 spkup_write(buf, cnt); 590 spkup_write(buf, cnt);
591 punc_mask = saved_punc_mask; 591 spk_punc_mask = saved_punc_mask;
592} 592}
593 593
594static void say_prev_word(struct vc_data *vc) 594static void say_prev_word(struct vc_data *vc)
@@ -686,22 +686,22 @@ static void say_next_word(struct vc_data *vc)
686static void spell_word(struct vc_data *vc) 686static void spell_word(struct vc_data *vc)
687{ 687{
688 static char *delay_str[] = { "", ",", ".", ". .", ". . ." }; 688 static char *delay_str[] = { "", ",", ".", ". .", ". . ." };
689 char *cp = buf, *str_cap = str_caps_stop; 689 char *cp = buf, *str_cap = spk_str_caps_stop;
690 char *cp1, *last_cap = str_caps_stop; 690 char *cp1, *last_cap = spk_str_caps_stop;
691 u_char ch; 691 u_char ch;
692 if (!get_word(vc)) 692 if (!get_word(vc))
693 return; 693 return;
694 while ((ch = (u_char) *cp)) { 694 while ((ch = (u_char) *cp)) {
695 if (cp != buf) 695 if (cp != buf)
696 synth_printf(" %s ", delay_str[spell_delay]); 696 synth_printf(" %s ", delay_str[spk_spell_delay]);
697 if (IS_CHAR(ch, B_CAP)) { 697 if (IS_CHAR(ch, B_CAP)) {
698 str_cap = str_caps_start; 698 str_cap = spk_str_caps_start;
699 if (*str_caps_stop) 699 if (*spk_str_caps_stop)
700 pitch_shift++; 700 spk_pitch_shift++;
701 else /* synth has no pitch */ 701 else /* synth has no pitch */
702 last_cap = str_caps_stop; 702 last_cap = spk_str_caps_stop;
703 } else 703 } else
704 str_cap = str_caps_stop; 704 str_cap = spk_str_caps_stop;
705 if (str_cap != last_cap) { 705 if (str_cap != last_cap) {
706 synth_printf("%s", str_cap); 706 synth_printf("%s", str_cap);
707 last_cap = str_cap; 707 last_cap = str_cap;
@@ -711,17 +711,17 @@ static void spell_word(struct vc_data *vc)
711 ch &= 31; 711 ch &= 31;
712 cp1 = phonetic[--ch]; 712 cp1 = phonetic[--ch];
713 } else { 713 } else {
714 cp1 = characters[ch]; 714 cp1 = spk_characters[ch];
715 if (*cp1 == '^') { 715 if (*cp1 == '^') {
716 synth_printf("%s", msg_get(MSG_CTRL)); 716 synth_printf("%s", spk_msg_get(MSG_CTRL));
717 cp1++; 717 cp1++;
718 } 718 }
719 } 719 }
720 synth_printf("%s", cp1); 720 synth_printf("%s", cp1);
721 cp++; 721 cp++;
722 } 722 }
723 if (str_cap != str_caps_stop) 723 if (str_cap != spk_str_caps_stop)
724 synth_printf("%s", str_caps_stop); 724 synth_printf("%s", spk_str_caps_stop);
725} 725}
726 726
727static int get_line(struct vc_data *vc) 727static int get_line(struct vc_data *vc)
@@ -746,9 +746,9 @@ static void say_line(struct vc_data *vc)
746{ 746{
747 int i = get_line(vc); 747 int i = get_line(vc);
748 char *cp; 748 char *cp;
749 u_short saved_punc_mask = punc_mask; 749 u_short saved_punc_mask = spk_punc_mask;
750 if (i == 0) { 750 if (i == 0) {
751 synth_printf("%s\n", msg_get(MSG_BLANK)); 751 synth_printf("%s\n", spk_msg_get(MSG_BLANK));
752 return; 752 return;
753 } 753 }
754 buf[i++] = '\n'; 754 buf[i++] = '\n';
@@ -758,9 +758,9 @@ static void say_line(struct vc_data *vc)
758 cp++; 758 cp++;
759 synth_printf("%d, ", (cp - buf) + 1); 759 synth_printf("%d, ", (cp - buf) + 1);
760 } 760 }
761 punc_mask = punc_masks[reading_punc]; 761 spk_punc_mask = spk_punc_masks[spk_reading_punc];
762 spkup_write(buf, i); 762 spkup_write(buf, i);
763 punc_mask = saved_punc_mask; 763 spk_punc_mask = saved_punc_mask;
764} 764}
765 765
766static void say_prev_line(struct vc_data *vc) 766static void say_prev_line(struct vc_data *vc)
@@ -792,7 +792,7 @@ static int say_from_to(struct vc_data *vc, u_long from, u_long to,
792{ 792{
793 int i = 0; 793 int i = 0;
794 u_char tmp; 794 u_char tmp;
795 u_short saved_punc_mask = punc_mask; 795 u_short saved_punc_mask = spk_punc_mask;
796 spk_old_attr = spk_attr; 796 spk_old_attr = spk_attr;
797 spk_attr = get_attributes((u_short *) from); 797 spk_attr = get_attributes((u_short *) from);
798 while (from < to) { 798 while (from < to) {
@@ -809,10 +809,10 @@ static int say_from_to(struct vc_data *vc, u_long from, u_long to,
809 if (i < 1) 809 if (i < 1)
810 return i; 810 return i;
811 if (read_punc) 811 if (read_punc)
812 punc_mask = punc_info[reading_punc].mask; 812 spk_punc_mask = spk_punc_info[spk_reading_punc].mask;
813 spkup_write(buf, i); 813 spkup_write(buf, i);
814 if (read_punc) 814 if (read_punc)
815 punc_mask = saved_punc_mask; 815 spk_punc_mask = saved_punc_mask;
816 return i - 1; 816 return i - 1;
817} 817}
818 818
@@ -824,7 +824,7 @@ static void say_line_from_to(struct vc_data *vc, u_long from, u_long to,
824 start += from * 2; 824 start += from * 2;
825 if (say_from_to(vc, start, end, read_punc) <= 0) 825 if (say_from_to(vc, start, end, read_punc) <= 0)
826 if (cursor_track != read_all_mode) 826 if (cursor_track != read_all_mode)
827 synth_printf("%s\n", msg_get(MSG_BLANK)); 827 synth_printf("%s\n", spk_msg_get(MSG_BLANK));
828} 828}
829 829
830/* Sentence Reading Commands */ 830/* Sentence Reading Commands */
@@ -924,7 +924,7 @@ static void speakup_win_say(struct vc_data *vc)
924{ 924{
925 u_long start, end, from, to; 925 u_long start, end, from, to;
926 if (win_start < 2) { 926 if (win_start < 2) {
927 synth_printf("%s\n", msg_get(MSG_NO_WINDOW)); 927 synth_printf("%s\n", spk_msg_get(MSG_NO_WINDOW));
928 return; 928 return;
929 } 929 }
930 start = vc->vc_origin + (win_top * vc->vc_size_row); 930 start = vc->vc_origin + (win_top * vc->vc_size_row);
@@ -975,7 +975,7 @@ static void say_first_char(struct vc_data *vc)
975 u_char ch; 975 u_char ch;
976 spk_parked |= 0x01; 976 spk_parked |= 0x01;
977 if (len == 0) { 977 if (len == 0) {
978 synth_printf("%s\n", msg_get(MSG_BLANK)); 978 synth_printf("%s\n", spk_msg_get(MSG_BLANK));
979 return; 979 return;
980 } 980 }
981 for (i = 0; i < len; i++) 981 for (i = 0; i < len; i++)
@@ -994,7 +994,7 @@ static void say_last_char(struct vc_data *vc)
994 u_char ch; 994 u_char ch;
995 spk_parked |= 0x01; 995 spk_parked |= 0x01;
996 if (len == 0) { 996 if (len == 0) {
997 synth_printf("%s\n", msg_get(MSG_BLANK)); 997 synth_printf("%s\n", spk_msg_get(MSG_BLANK));
998 return; 998 return;
999 } 999 }
1000 ch = buf[--len]; 1000 ch = buf[--len];
@@ -1006,7 +1006,7 @@ static void say_last_char(struct vc_data *vc)
1006 1006
1007static void say_position(struct vc_data *vc) 1007static void say_position(struct vc_data *vc)
1008{ 1008{
1009 synth_printf(msg_get(MSG_POS_INFO), spk_y + 1, spk_x + 1, 1009 synth_printf(spk_msg_get(MSG_POS_INFO), spk_y + 1, spk_x + 1,
1010 vc->vc_num + 1); 1010 vc->vc_num + 1);
1011 synth_printf("\n"); 1011 synth_printf("\n");
1012} 1012}
@@ -1017,7 +1017,7 @@ static void say_char_num(struct vc_data *vc)
1017 u_char tmp; 1017 u_char tmp;
1018 u_short ch = get_char(vc, (u_short *) spk_pos, &tmp); 1018 u_short ch = get_char(vc, (u_short *) spk_pos, &tmp);
1019 ch &= 0xff; 1019 ch &= 0xff;
1020 synth_printf(msg_get(MSG_CHAR_INFO), ch, ch); 1020 synth_printf(spk_msg_get(MSG_CHAR_INFO), ch, ch);
1021} 1021}
1022 1022
1023/* these are stub functions to keep keyboard.c happy. */ 1023/* these are stub functions to keep keyboard.c happy. */
@@ -1066,7 +1066,7 @@ static void spkup_write(const char *in_buf, int count)
1066 } else { 1066 } else {
1067 if ((last_type & CH_RPT) && rep_count > 2) { 1067 if ((last_type & CH_RPT) && rep_count > 2) {
1068 synth_printf(" "); 1068 synth_printf(" ");
1069 synth_printf(msg_get(MSG_REPEAT_DESC), 1069 synth_printf(spk_msg_get(MSG_REPEAT_DESC),
1070 ++rep_count); 1070 ++rep_count);
1071 synth_printf(" "); 1071 synth_printf(" ");
1072 } 1072 }
@@ -1074,7 +1074,7 @@ static void spkup_write(const char *in_buf, int count)
1074 } 1074 }
1075 if (ch == spk_lastkey) { 1075 if (ch == spk_lastkey) {
1076 rep_count = 0; 1076 rep_count = 0;
1077 if (key_echo == 1 && ch >= MINECHOCHAR) 1077 if (spk_key_echo == 1 && ch >= MINECHOCHAR)
1078 speak_char(ch); 1078 speak_char(ch);
1079 } else if (char_type & B_ALPHA) { 1079 } else if (char_type & B_ALPHA) {
1080 if ((synth_flags & SF_DEC) && (last_type & PUNC)) 1080 if ((synth_flags & SF_DEC) && (last_type & PUNC))
@@ -1083,7 +1083,7 @@ static void spkup_write(const char *in_buf, int count)
1083 } else if (char_type & B_NUM) { 1083 } else if (char_type & B_NUM) {
1084 rep_count = 0; 1084 rep_count = 0;
1085 synth_printf("%c", ch); 1085 synth_printf("%c", ch);
1086 } else if (char_type & punc_mask) { 1086 } else if (char_type & spk_punc_mask) {
1087 speak_char(ch); 1087 speak_char(ch);
1088 char_type &= ~PUNC; /* for dec nospell processing */ 1088 char_type &= ~PUNC; /* for dec nospell processing */
1089 } else if (char_type & SYNTH_OK) { 1089 } else if (char_type & SYNTH_OK) {
@@ -1111,7 +1111,7 @@ static void spkup_write(const char *in_buf, int count)
1111 if (in_count > 2 && rep_count > 2) { 1111 if (in_count > 2 && rep_count > 2) {
1112 if (last_type & CH_RPT) { 1112 if (last_type & CH_RPT) {
1113 synth_printf(" "); 1113 synth_printf(" ");
1114 synth_printf(msg_get(MSG_REPEAT_DESC2), ++rep_count); 1114 synth_printf(spk_msg_get(MSG_REPEAT_DESC2), ++rep_count);
1115 synth_printf(" "); 1115 synth_printf(" ");
1116 } 1116 }
1117 rep_count = 0; 1117 rep_count = 0;
@@ -1135,22 +1135,22 @@ static void do_handle_shift(struct vc_data *vc, u_char value, char up_flag)
1135 case KVAL(K_SHIFT): 1135 case KVAL(K_SHIFT):
1136 del_timer(&cursor_timer); 1136 del_timer(&cursor_timer);
1137 spk_shut_up &= 0xfe; 1137 spk_shut_up &= 0xfe;
1138 do_flush(); 1138 spk_do_flush();
1139 read_all_doc(vc); 1139 read_all_doc(vc);
1140 break; 1140 break;
1141 case KVAL(K_CTRL): 1141 case KVAL(K_CTRL):
1142 del_timer(&cursor_timer); 1142 del_timer(&cursor_timer);
1143 cursor_track = prev_cursor_track; 1143 cursor_track = prev_cursor_track;
1144 spk_shut_up &= 0xfe; 1144 spk_shut_up &= 0xfe;
1145 do_flush(); 1145 spk_do_flush();
1146 break; 1146 break;
1147 } 1147 }
1148 } else { 1148 } else {
1149 spk_shut_up &= 0xfe; 1149 spk_shut_up &= 0xfe;
1150 do_flush(); 1150 spk_do_flush();
1151 } 1151 }
1152 if (say_ctrl && value < NUM_CTL_LABELS) 1152 if (spk_say_ctrl && value < NUM_CTL_LABELS)
1153 synth_printf("%s", msg_get(MSG_CTL_START + value)); 1153 synth_printf("%s", spk_msg_get(MSG_CTL_START + value));
1154 spk_unlock(flags); 1154 spk_unlock(flags);
1155} 1155}
1156 1156
@@ -1171,12 +1171,12 @@ static void do_handle_latin(struct vc_data *vc, u_char value, char up_flag)
1171 spk_lastkey = value; 1171 spk_lastkey = value;
1172 spk_keydown++; 1172 spk_keydown++;
1173 spk_parked &= 0xfe; 1173 spk_parked &= 0xfe;
1174 if (key_echo == 2 && value >= MINECHOCHAR) 1174 if (spk_key_echo == 2 && value >= MINECHOCHAR)
1175 speak_char(value); 1175 speak_char(value);
1176 spk_unlock(flags); 1176 spk_unlock(flags);
1177} 1177}
1178 1178
1179int set_key_info(const u_char *key_info, u_char *k_buffer) 1179int spk_set_key_info(const u_char *key_info, u_char *k_buffer)
1180{ 1180{
1181 int i = 0, states, key_data_len; 1181 int i = 0, states, key_data_len;
1182 const u_char *cp = key_info; 1182 const u_char *cp = key_info;
@@ -1188,12 +1188,12 @@ int set_key_info(const u_char *key_info, u_char *k_buffer)
1188 num_keys = *cp; 1188 num_keys = *cp;
1189 states = (int)cp[1]; 1189 states = (int)cp[1];
1190 key_data_len = (states + 1) * (num_keys + 1); 1190 key_data_len = (states + 1) * (num_keys + 1);
1191 if (key_data_len + SHIFT_TBL_SIZE + 4 >= sizeof(key_buf)) 1191 if (key_data_len + SHIFT_TBL_SIZE + 4 >= sizeof(spk_key_buf))
1192 return -2; 1192 return -2;
1193 memset(k_buffer, 0, SHIFT_TBL_SIZE); 1193 memset(k_buffer, 0, SHIFT_TBL_SIZE);
1194 memset(our_keys, 0, sizeof(our_keys)); 1194 memset(spk_our_keys, 0, sizeof(spk_our_keys));
1195 shift_table = k_buffer; 1195 spk_shift_table = k_buffer;
1196 our_keys[0] = shift_table; 1196 spk_our_keys[0] = spk_shift_table;
1197 cp1 += SHIFT_TBL_SIZE; 1197 cp1 += SHIFT_TBL_SIZE;
1198 memcpy(cp1, cp, key_data_len + 3); 1198 memcpy(cp1, cp, key_data_len + 3);
1199 /* get num_keys, states and data */ 1199 /* get num_keys, states and data */
@@ -1202,13 +1202,13 @@ int set_key_info(const u_char *key_info, u_char *k_buffer)
1202 ch = *cp1++; 1202 ch = *cp1++;
1203 if (ch >= SHIFT_TBL_SIZE) 1203 if (ch >= SHIFT_TBL_SIZE)
1204 return -3; 1204 return -3;
1205 shift_table[ch] = i; 1205 spk_shift_table[ch] = i;
1206 } 1206 }
1207 keymap_flags = *cp1++; 1207 keymap_flags = *cp1++;
1208 while ((ch = *cp1)) { 1208 while ((ch = *cp1)) {
1209 if (ch >= MAX_KEY) 1209 if (ch >= MAX_KEY)
1210 return -4; 1210 return -4;
1211 our_keys[ch] = cp1; 1211 spk_our_keys[ch] = cp1;
1212 cp1 += states + 1; 1212 cp1 += states + 1;
1213 } 1213 }
1214 return 0; 1214 return 0;
@@ -1237,24 +1237,24 @@ static void toggle_cursoring(struct vc_data *vc)
1237 cursor_track = prev_cursor_track; 1237 cursor_track = prev_cursor_track;
1238 if (++cursor_track >= CT_Max) 1238 if (++cursor_track >= CT_Max)
1239 cursor_track = 0; 1239 cursor_track = 0;
1240 synth_printf("%s\n", msg_get(MSG_CURSOR_MSGS_START + cursor_track)); 1240 synth_printf("%s\n", spk_msg_get(MSG_CURSOR_MSGS_START + cursor_track));
1241} 1241}
1242 1242
1243void reset_default_chars(void) 1243void spk_reset_default_chars(void)
1244{ 1244{
1245 int i; 1245 int i;
1246 1246
1247 /* First, free any non-default */ 1247 /* First, free any non-default */
1248 for (i = 0; i < 256; i++) { 1248 for (i = 0; i < 256; i++) {
1249 if ((characters[i] != NULL) 1249 if ((spk_characters[i] != NULL)
1250 && (characters[i] != default_chars[i])) 1250 && (spk_characters[i] != spk_default_chars[i]))
1251 kfree(characters[i]); 1251 kfree(spk_characters[i]);
1252 } 1252 }
1253 1253
1254 memcpy(characters, default_chars, sizeof(default_chars)); 1254 memcpy(spk_characters, spk_default_chars, sizeof(spk_default_chars));
1255} 1255}
1256 1256
1257void reset_default_chartab(void) 1257void spk_reset_default_chartab(void)
1258{ 1258{
1259 memcpy(spk_chartab, default_chartab, sizeof(default_chartab)); 1259 memcpy(spk_chartab, default_chartab, sizeof(default_chartab));
1260} 1260}
@@ -1267,8 +1267,8 @@ static int edit_bits(struct vc_data *vc, u_char type, u_char ch, u_short key)
1267 if (type != KT_LATIN || (ch_type & B_NUM) || ch < SPACE) 1267 if (type != KT_LATIN || (ch_type & B_NUM) || ch < SPACE)
1268 return -1; 1268 return -1;
1269 if (ch == SPACE) { 1269 if (ch == SPACE) {
1270 synth_printf("%s\n", msg_get(MSG_EDIT_DONE)); 1270 synth_printf("%s\n", spk_msg_get(MSG_EDIT_DONE));
1271 special_handler = NULL; 1271 spk_special_handler = NULL;
1272 return 1; 1272 return 1;
1273 } 1273 }
1274 if (mask < PUNC && !(ch_type & PUNC)) 1274 if (mask < PUNC && !(ch_type & PUNC))
@@ -1276,8 +1276,8 @@ static int edit_bits(struct vc_data *vc, u_char type, u_char ch, u_short key)
1276 spk_chartab[ch] ^= mask; 1276 spk_chartab[ch] ^= mask;
1277 speak_char(ch); 1277 speak_char(ch);
1278 synth_printf(" %s\n", 1278 synth_printf(" %s\n",
1279 (spk_chartab[ch] & mask) ? msg_get(MSG_ON) : 1279 (spk_chartab[ch] & mask) ? spk_msg_get(MSG_ON) :
1280 msg_get(MSG_OFF)); 1280 spk_msg_get(MSG_OFF));
1281 return 1; 1281 return 1;
1282} 1282}
1283 1283
@@ -1346,7 +1346,7 @@ static void read_all_doc(struct vc_data *vc)
1346 if (cursor_track != read_all_mode) 1346 if (cursor_track != read_all_mode)
1347 prev_cursor_track = cursor_track; 1347 prev_cursor_track = cursor_track;
1348 cursor_track = read_all_mode; 1348 cursor_track = read_all_mode;
1349 reset_index_count(0); 1349 spk_reset_index_count(0);
1350 if (get_sentence_buf(vc, 0) == -1) 1350 if (get_sentence_buf(vc, 0) == -1)
1351 kbd_fakekey2(vc, RA_DOWN_ARROW); 1351 kbd_fakekey2(vc, RA_DOWN_ARROW);
1352 else { 1352 else {
@@ -1361,7 +1361,7 @@ static void stop_read_all(struct vc_data *vc)
1361 del_timer(&cursor_timer); 1361 del_timer(&cursor_timer);
1362 cursor_track = prev_cursor_track; 1362 cursor_track = prev_cursor_track;
1363 spk_shut_up &= 0xfe; 1363 spk_shut_up &= 0xfe;
1364 do_flush(); 1364 spk_do_flush();
1365} 1365}
1366 1366
1367static void start_read_all_timer(struct vc_data *vc, int command) 1367static void start_read_all_timer(struct vc_data *vc, int command)
@@ -1370,7 +1370,7 @@ static void start_read_all_timer(struct vc_data *vc, int command)
1370 1370
1371 cursor_con = vc->vc_num; 1371 cursor_con = vc->vc_num;
1372 read_all_key = command; 1372 read_all_key = command;
1373 cursor_timeout = get_var(CURSOR_TIME); 1373 cursor_timeout = spk_get_var(CURSOR_TIME);
1374 mod_timer(&cursor_timer, 1374 mod_timer(&cursor_timer,
1375 jiffies + msecs_to_jiffies(cursor_timeout->u.n.value)); 1375 jiffies + msecs_to_jiffies(cursor_timeout->u.n.value));
1376} 1376}
@@ -1382,9 +1382,9 @@ static void handle_cursor_read_all(struct vc_data *vc, int command)
1382 switch (command) { 1382 switch (command) {
1383 case RA_NEXT_SENT: 1383 case RA_NEXT_SENT:
1384 /* Get Current Sentence */ 1384 /* Get Current Sentence */
1385 get_index_count(&indcount, &sentcount); 1385 spk_get_index_count(&indcount, &sentcount);
1386 /*printk("%d %d ", indcount, sentcount); */ 1386 /*printk("%d %d ", indcount, sentcount); */
1387 reset_index_count(sentcount + 1); 1387 spk_reset_index_count(sentcount + 1);
1388 if (indcount == 1) { 1388 if (indcount == 1) {
1389 if (!say_sentence_num(sentcount + 1, 0)) { 1389 if (!say_sentence_num(sentcount + 1, 0)) {
1390 kbd_fakekey2(vc, RA_FIND_NEXT_SENT); 1390 kbd_fakekey2(vc, RA_FIND_NEXT_SENT);
@@ -1395,7 +1395,7 @@ static void handle_cursor_read_all(struct vc_data *vc, int command)
1395 sn = 0; 1395 sn = 0;
1396 if (!say_sentence_num(sentcount + 1, 1)) { 1396 if (!say_sentence_num(sentcount + 1, 1)) {
1397 sn = 1; 1397 sn = 1;
1398 reset_index_count(sn); 1398 spk_reset_index_count(sn);
1399 } else 1399 } else
1400 synth_insert_next_index(0); 1400 synth_insert_next_index(0);
1401 if (!say_sentence_num(sn, 0)) { 1401 if (!say_sentence_num(sn, 0)) {
@@ -1437,7 +1437,7 @@ static void handle_cursor_read_all(struct vc_data *vc, int command)
1437 case RA_FIND_PREV_SENT: 1437 case RA_FIND_PREV_SENT:
1438 break; 1438 break;
1439 case RA_TIMER: 1439 case RA_TIMER:
1440 get_index_count(&indcount, &sentcount); 1440 spk_get_index_count(&indcount, &sentcount);
1441 if (indcount < 2) 1441 if (indcount < 2)
1442 kbd_fakekey2(vc, RA_DOWN_ARROW); 1442 kbd_fakekey2(vc, RA_DOWN_ARROW);
1443 else 1443 else
@@ -1458,7 +1458,7 @@ static int pre_handle_cursor(struct vc_data *vc, u_char value, char up_flag)
1458 } 1458 }
1459 del_timer(&cursor_timer); 1459 del_timer(&cursor_timer);
1460 spk_shut_up &= 0xfe; 1460 spk_shut_up &= 0xfe;
1461 do_flush(); 1461 spk_do_flush();
1462 start_read_all_timer(vc, value + 1); 1462 start_read_all_timer(vc, value + 1);
1463 spk_unlock(flags); 1463 spk_unlock(flags);
1464 return NOTIFY_STOP; 1464 return NOTIFY_STOP;
@@ -1479,8 +1479,8 @@ static void do_handle_cursor(struct vc_data *vc, u_char value, char up_flag)
1479 return; 1479 return;
1480 } 1480 }
1481 spk_shut_up &= 0xfe; 1481 spk_shut_up &= 0xfe;
1482 if (no_intr) 1482 if (spk_no_intr)
1483 do_flush(); 1483 spk_do_flush();
1484/* the key press flushes if !no_inter but we want to flush on cursor 1484/* the key press flushes if !no_inter but we want to flush on cursor
1485 * moves regardless of no_inter state */ 1485 * moves regardless of no_inter state */
1486 is_cursor = value + 1; 1486 is_cursor = value + 1;
@@ -1491,7 +1491,7 @@ static void do_handle_cursor(struct vc_data *vc, u_char value, char up_flag)
1491 cursor_con = vc->vc_num; 1491 cursor_con = vc->vc_num;
1492 if (cursor_track == CT_Highlight) 1492 if (cursor_track == CT_Highlight)
1493 reset_highlight_buffers(vc); 1493 reset_highlight_buffers(vc);
1494 cursor_timeout = get_var(CURSOR_TIME); 1494 cursor_timeout = spk_get_var(CURSOR_TIME);
1495 mod_timer(&cursor_timer, 1495 mod_timer(&cursor_timer,
1496 jiffies + msecs_to_jiffies(cursor_timeout->u.n.value)); 1496 jiffies + msecs_to_jiffies(cursor_timeout->u.n.value));
1497 spk_unlock(flags); 1497 spk_unlock(flags);
@@ -1603,7 +1603,7 @@ static int speak_highlight(struct vc_data *vc)
1603 if (speakup_console[vc_num]->ht.ry[hc] != vc->vc_y) 1603 if (speakup_console[vc_num]->ht.ry[hc] != vc->vc_y)
1604 return 0; 1604 return 0;
1605 spk_parked |= 0x01; 1605 spk_parked |= 0x01;
1606 do_flush(); 1606 spk_do_flush();
1607 spkup_write(speakup_console[vc_num]->ht.highbuf[hc], 1607 spkup_write(speakup_console[vc_num]->ht.highbuf[hc],
1608 speakup_console[vc_num]->ht.highsize[hc]); 1608 speakup_console[vc_num]->ht.highsize[hc]);
1609 spk_pos = spk_cp = speakup_console[vc_num]->ht.rpos[hc]; 1609 spk_pos = spk_cp = speakup_console[vc_num]->ht.rpos[hc];
@@ -1685,7 +1685,7 @@ static void speakup_con_write(struct vc_data *vc, const char *str, int len)
1685 if (!spk_trylock(flags)) 1685 if (!spk_trylock(flags))
1686 /* Speakup output, discard */ 1686 /* Speakup output, discard */
1687 return; 1687 return;
1688 if (bell_pos && spk_keydown && (vc->vc_x == bell_pos - 1)) 1688 if (spk_bell_pos && spk_keydown && (vc->vc_x == spk_bell_pos - 1))
1689 bleep(3); 1689 bleep(3);
1690 if ((is_cursor) || (cursor_track == read_all_mode)) { 1690 if ((is_cursor) || (cursor_track == read_all_mode)) {
1691 if (cursor_track == CT_Highlight) 1691 if (cursor_track == CT_Highlight)
@@ -1726,19 +1726,19 @@ static void do_handle_spec(struct vc_data *vc, u_char value, char up_flag)
1726 return; 1726 return;
1727 spk_lock(flags); 1727 spk_lock(flags);
1728 spk_shut_up &= 0xfe; 1728 spk_shut_up &= 0xfe;
1729 if (no_intr) 1729 if (spk_no_intr)
1730 do_flush(); 1730 spk_do_flush();
1731 switch (value) { 1731 switch (value) {
1732 case KVAL(K_CAPS): 1732 case KVAL(K_CAPS):
1733 label = msg_get(MSG_KEYNAME_CAPSLOCK); 1733 label = spk_msg_get(MSG_KEYNAME_CAPSLOCK);
1734 on_off = vt_get_leds(fg_console, VC_CAPSLOCK); 1734 on_off = vt_get_leds(fg_console, VC_CAPSLOCK);
1735 break; 1735 break;
1736 case KVAL(K_NUM): 1736 case KVAL(K_NUM):
1737 label = msg_get(MSG_KEYNAME_NUMLOCK); 1737 label = spk_msg_get(MSG_KEYNAME_NUMLOCK);
1738 on_off = vt_get_leds(fg_console, VC_NUMLOCK); 1738 on_off = vt_get_leds(fg_console, VC_NUMLOCK);
1739 break; 1739 break;
1740 case KVAL(K_HOLD): 1740 case KVAL(K_HOLD):
1741 label = msg_get(MSG_KEYNAME_SCROLLLOCK); 1741 label = spk_msg_get(MSG_KEYNAME_SCROLLLOCK);
1742 on_off = vt_get_leds(fg_console, VC_SCROLLOCK); 1742 on_off = vt_get_leds(fg_console, VC_SCROLLOCK);
1743 if (speakup_console[vc->vc_num]) 1743 if (speakup_console[vc->vc_num])
1744 speakup_console[vc->vc_num]->tty_stopped = on_off; 1744 speakup_console[vc->vc_num]->tty_stopped = on_off;
@@ -1750,7 +1750,7 @@ static void do_handle_spec(struct vc_data *vc, u_char value, char up_flag)
1750 } 1750 }
1751 if (on_off < 2) 1751 if (on_off < 2)
1752 synth_printf("%s %s\n", 1752 synth_printf("%s %s\n",
1753 label, msg_get(MSG_STATUS_START + on_off)); 1753 label, spk_msg_get(MSG_STATUS_START + on_off));
1754 spk_unlock(flags); 1754 spk_unlock(flags);
1755} 1755}
1756 1756
@@ -1764,13 +1764,13 @@ static int inc_dec_var(u_char value)
1764 int var_id = (int)value - VAR_START; 1764 int var_id = (int)value - VAR_START;
1765 int how = (var_id & 1) ? E_INC : E_DEC; 1765 int how = (var_id & 1) ? E_INC : E_DEC;
1766 var_id = var_id / 2 + FIRST_SET_VAR; 1766 var_id = var_id / 2 + FIRST_SET_VAR;
1767 p_header = get_var_header(var_id); 1767 p_header = spk_get_var_header(var_id);
1768 if (p_header == NULL) 1768 if (p_header == NULL)
1769 return -1; 1769 return -1;
1770 if (p_header->var_type != VAR_NUM) 1770 if (p_header->var_type != VAR_NUM)
1771 return -1; 1771 return -1;
1772 var_data = p_header->data; 1772 var_data = p_header->data;
1773 if (set_num_var(1, p_header, how) != 0) 1773 if (spk_set_num_var(1, p_header, how) != 0)
1774 return -1; 1774 return -1;
1775 if (!spk_close_press) { 1775 if (!spk_close_press) {
1776 for (pn = p_header->name; *pn; pn++) { 1776 for (pn = p_header->name; *pn; pn++) {
@@ -1790,18 +1790,18 @@ static void speakup_win_set(struct vc_data *vc)
1790{ 1790{
1791 char info[40]; 1791 char info[40];
1792 if (win_start > 1) { 1792 if (win_start > 1) {
1793 synth_printf("%s\n", msg_get(MSG_WINDOW_ALREADY_SET)); 1793 synth_printf("%s\n", spk_msg_get(MSG_WINDOW_ALREADY_SET));
1794 return; 1794 return;
1795 } 1795 }
1796 if (spk_x < win_left || spk_y < win_top) { 1796 if (spk_x < win_left || spk_y < win_top) {
1797 synth_printf("%s\n", msg_get(MSG_END_BEFORE_START)); 1797 synth_printf("%s\n", spk_msg_get(MSG_END_BEFORE_START));
1798 return; 1798 return;
1799 } 1799 }
1800 if (win_start && spk_x == win_left && spk_y == win_top) { 1800 if (win_start && spk_x == win_left && spk_y == win_top) {
1801 win_left = 0; 1801 win_left = 0;
1802 win_right = vc->vc_cols - 1; 1802 win_right = vc->vc_cols - 1;
1803 win_bottom = spk_y; 1803 win_bottom = spk_y;
1804 snprintf(info, sizeof(info), msg_get(MSG_WINDOW_LINE), 1804 snprintf(info, sizeof(info), spk_msg_get(MSG_WINDOW_LINE),
1805 (int)win_top + 1); 1805 (int)win_top + 1);
1806 } else { 1806 } else {
1807 if (!win_start) { 1807 if (!win_start) {
@@ -1811,8 +1811,8 @@ static void speakup_win_set(struct vc_data *vc)
1811 win_bottom = spk_y; 1811 win_bottom = spk_y;
1812 win_right = spk_x; 1812 win_right = spk_x;
1813 } 1813 }
1814 snprintf(info, sizeof(info), msg_get(MSG_WINDOW_BOUNDARY), 1814 snprintf(info, sizeof(info), spk_msg_get(MSG_WINDOW_BOUNDARY),
1815 (win_start) ? msg_get(MSG_END) : msg_get(MSG_START), 1815 (win_start) ? spk_msg_get(MSG_END) : spk_msg_get(MSG_START),
1816 (int)spk_y + 1, (int)spk_x + 1); 1816 (int)spk_y + 1, (int)spk_x + 1);
1817 } 1817 }
1818 synth_printf("%s\n", info); 1818 synth_printf("%s\n", info);
@@ -1824,32 +1824,32 @@ static void speakup_win_clear(struct vc_data *vc)
1824 win_top = win_bottom = 0; 1824 win_top = win_bottom = 0;
1825 win_left = win_right = 0; 1825 win_left = win_right = 0;
1826 win_start = 0; 1826 win_start = 0;
1827 synth_printf("%s\n", msg_get(MSG_WINDOW_CLEARED)); 1827 synth_printf("%s\n", spk_msg_get(MSG_WINDOW_CLEARED));
1828} 1828}
1829 1829
1830static void speakup_win_enable(struct vc_data *vc) 1830static void speakup_win_enable(struct vc_data *vc)
1831{ 1831{
1832 if (win_start < 2) { 1832 if (win_start < 2) {
1833 synth_printf("%s\n", msg_get(MSG_NO_WINDOW)); 1833 synth_printf("%s\n", spk_msg_get(MSG_NO_WINDOW));
1834 return; 1834 return;
1835 } 1835 }
1836 win_enabled ^= 1; 1836 win_enabled ^= 1;
1837 if (win_enabled) 1837 if (win_enabled)
1838 synth_printf("%s\n", msg_get(MSG_WINDOW_SILENCED)); 1838 synth_printf("%s\n", spk_msg_get(MSG_WINDOW_SILENCED));
1839 else 1839 else
1840 synth_printf("%s\n", msg_get(MSG_WINDOW_SILENCE_DISABLED)); 1840 synth_printf("%s\n", spk_msg_get(MSG_WINDOW_SILENCE_DISABLED));
1841} 1841}
1842 1842
1843static void speakup_bits(struct vc_data *vc) 1843static void speakup_bits(struct vc_data *vc)
1844{ 1844{
1845 int val = this_speakup_key - (FIRST_EDIT_BITS - 1); 1845 int val = this_speakup_key - (FIRST_EDIT_BITS - 1);
1846 if (special_handler != NULL || val < 1 || val > 6) { 1846 if (spk_special_handler != NULL || val < 1 || val > 6) {
1847 synth_printf("%s\n", msg_get(MSG_ERROR)); 1847 synth_printf("%s\n", spk_msg_get(MSG_ERROR));
1848 return; 1848 return;
1849 } 1849 }
1850 pb_edit = &punc_info[val]; 1850 pb_edit = &spk_punc_info[val];
1851 synth_printf(msg_get(MSG_EDIT_PROMPT), pb_edit->name); 1851 synth_printf(spk_msg_get(MSG_EDIT_PROMPT), pb_edit->name);
1852 special_handler = edit_bits; 1852 spk_special_handler = edit_bits;
1853} 1853}
1854 1854
1855static int handle_goto(struct vc_data *vc, u_char type, u_char ch, u_short key) 1855static int handle_goto(struct vc_data *vc, u_char type, u_char ch, u_short key)
@@ -1887,9 +1887,9 @@ static int handle_goto(struct vc_data *vc, u_char type, u_char ch, u_short key)
1887 if (ch < 'x' || ch > 'y') { 1887 if (ch < 'x' || ch > 'y') {
1888oops: 1888oops:
1889 if (!spk_killed) 1889 if (!spk_killed)
1890 synth_printf(" %s\n", msg_get(MSG_GOTO_CANCELED)); 1890 synth_printf(" %s\n", spk_msg_get(MSG_GOTO_CANCELED));
1891 goto_buf[num = 0] = '\0'; 1891 goto_buf[num = 0] = '\0';
1892 special_handler = NULL; 1892 spk_special_handler = NULL;
1893 return 1; 1893 return 1;
1894 } 1894 }
1895 cp = speakup_s2i(goto_buf, &go_pos); 1895 cp = speakup_s2i(goto_buf, &go_pos);
@@ -1917,7 +1917,7 @@ oops:
1917 } 1917 }
1918 goto_buf[num = 0] = '\0'; 1918 goto_buf[num = 0] = '\0';
1919do_goto: 1919do_goto:
1920 special_handler = NULL; 1920 spk_special_handler = NULL;
1921 spk_parked |= 0x01; 1921 spk_parked |= 0x01;
1922 if (goto_x) { 1922 if (goto_x) {
1923 spk_pos -= spk_x * 2; 1923 spk_pos -= spk_x * 2;
@@ -1934,18 +1934,18 @@ do_goto:
1934 1934
1935static void speakup_goto(struct vc_data *vc) 1935static void speakup_goto(struct vc_data *vc)
1936{ 1936{
1937 if (special_handler != NULL) { 1937 if (spk_special_handler != NULL) {
1938 synth_printf("%s\n", msg_get(MSG_ERROR)); 1938 synth_printf("%s\n", spk_msg_get(MSG_ERROR));
1939 return; 1939 return;
1940 } 1940 }
1941 synth_printf("%s\n", msg_get(MSG_GOTO)); 1941 synth_printf("%s\n", spk_msg_get(MSG_GOTO));
1942 special_handler = handle_goto; 1942 spk_special_handler = handle_goto;
1943 return; 1943 return;
1944} 1944}
1945 1945
1946static void speakup_help(struct vc_data *vc) 1946static void speakup_help(struct vc_data *vc)
1947{ 1947{
1948 handle_help(vc, KT_SPKUP, SPEAKUP_HELP, 0); 1948 spk_handle_help(vc, KT_SPKUP, SPEAKUP_HELP, 0);
1949} 1949}
1950 1950
1951static void do_nothing(struct vc_data *vc) 1951static void do_nothing(struct vc_data *vc)
@@ -1992,7 +1992,7 @@ static void do_spkup(struct vc_data *vc, u_char value)
1992 spk_shut_up &= 0xfe; 1992 spk_shut_up &= 0xfe;
1993 this_speakup_key = value; 1993 this_speakup_key = value;
1994 if (value < SPKUP_MAX_FUNC && spkup_handler[value]) { 1994 if (value < SPKUP_MAX_FUNC && spkup_handler[value]) {
1995 do_flush(); 1995 spk_do_flush();
1996 (*spkup_handler[value]) (vc); 1996 (*spkup_handler[value]) (vc);
1997 } else { 1997 } else {
1998 if (inc_dec_var(value) < 0) 1998 if (inc_dec_var(value) < 0)
@@ -2032,7 +2032,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym,
2032 } 2032 }
2033 if (keycode >= MAX_KEY) 2033 if (keycode >= MAX_KEY)
2034 goto no_map; 2034 goto no_map;
2035 key_info = our_keys[keycode]; 2035 key_info = spk_our_keys[keycode];
2036 if (key_info == 0) 2036 if (key_info == 0)
2037 goto no_map; 2037 goto no_map;
2038 /* Check valid read all mode keys */ 2038 /* Check valid read all mode keys */
@@ -2051,7 +2051,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym,
2051 } 2051 }
2052 } 2052 }
2053 shift_info = (shift_state & 0x0f) + key_speakup; 2053 shift_info = (shift_state & 0x0f) + key_speakup;
2054 offset = shift_table[shift_info]; 2054 offset = spk_shift_table[shift_info];
2055 if (offset) { 2055 if (offset) {
2056 new_key = key_info[offset]; 2056 new_key = key_info[offset];
2057 if (new_key) { 2057 if (new_key) {
@@ -2062,7 +2062,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym,
2062 if (up_flag || spk_killed) 2062 if (up_flag || spk_killed)
2063 goto out; 2063 goto out;
2064 spk_shut_up &= 0xfe; 2064 spk_shut_up &= 0xfe;
2065 do_flush(); 2065 spk_do_flush();
2066 goto out; 2066 goto out;
2067 } 2067 }
2068 if (up_flag) 2068 if (up_flag)
@@ -2070,7 +2070,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym,
2070 if (last_keycode == keycode && 2070 if (last_keycode == keycode &&
2071 last_spk_jiffy + MAX_DELAY > jiffies) { 2071 last_spk_jiffy + MAX_DELAY > jiffies) {
2072 spk_close_press = 1; 2072 spk_close_press = 1;
2073 offset = shift_table[shift_info + 32]; 2073 offset = spk_shift_table[shift_info + 32];
2074 /* double press? */ 2074 /* double press? */
2075 if (offset && key_info[offset]) 2075 if (offset && key_info[offset])
2076 new_key = key_info[offset]; 2076 new_key = key_info[offset];
@@ -2082,7 +2082,7 @@ speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym,
2082 } 2082 }
2083 } 2083 }
2084no_map: 2084no_map:
2085 if (type == KT_SPKUP && special_handler == NULL) { 2085 if (type == KT_SPKUP && spk_special_handler == NULL) {
2086 do_spkup(vc, new_key); 2086 do_spkup(vc, new_key);
2087 spk_close_press = 0; 2087 spk_close_press = 0;
2088 ret = 1; 2088 ret = 1;
@@ -2096,9 +2096,9 @@ no_map:
2096 || (value == KVAL(K_LEFT)) 2096 || (value == KVAL(K_LEFT))
2097 || (value == KVAL(K_RIGHT)); 2097 || (value == KVAL(K_RIGHT));
2098 if ((cursor_track != read_all_mode) || !kh) 2098 if ((cursor_track != read_all_mode) || !kh)
2099 if (!no_intr) 2099 if (!spk_no_intr)
2100 do_flush(); 2100 spk_do_flush();
2101 if (special_handler) { 2101 if (spk_special_handler) {
2102 if (type == KT_SPEC && value == 1) { 2102 if (type == KT_SPEC && value == 1) {
2103 value = '\n'; 2103 value = '\n';
2104 type = KT_LATIN; 2104 type = KT_LATIN;
@@ -2106,7 +2106,7 @@ no_map:
2106 type = KT_LATIN; 2106 type = KT_LATIN;
2107 else if (value == 0x7f) 2107 else if (value == 0x7f)
2108 value = 8; /* make del = backspace */ 2108 value = 8; /* make del = backspace */
2109 ret = (*special_handler) (vc, type, value, keycode); 2109 ret = (*spk_special_handler) (vc, type, value, keycode);
2110 spk_close_press = 0; 2110 spk_close_press = 0;
2111 if (ret < 0) 2111 if (ret < 0)
2112 bleep(9); 2112 bleep(9);
@@ -2237,11 +2237,11 @@ static void __exit speakup_exit(void)
2237 speakup_unregister_var(i); 2237 speakup_unregister_var(i);
2238 2238
2239 for (i = 0; i < 256; i++) { 2239 for (i = 0; i < 256; i++) {
2240 if (characters[i] != default_chars[i]) 2240 if (spk_characters[i] != spk_default_chars[i])
2241 kfree(characters[i]); 2241 kfree(spk_characters[i]);
2242 } 2242 }
2243 2243
2244 free_user_msgs(); 2244 spk_free_user_msgs();
2245} 2245}
2246 2246
2247/* call by: module_init() */ 2247/* call by: module_init() */
@@ -2254,20 +2254,20 @@ static int __init speakup_init(void)
2254 struct var_t *var; 2254 struct var_t *var;
2255 2255
2256 /* These first few initializations cannot fail. */ 2256 /* These first few initializations cannot fail. */
2257 initialize_msgs(); /* Initialize arrays for i18n. */ 2257 spk_initialize_msgs(); /* Initialize arrays for i18n. */
2258 reset_default_chars(); 2258 spk_reset_default_chars();
2259 reset_default_chartab(); 2259 spk_reset_default_chartab();
2260 strlwr(synth_name); 2260 spk_strlwr(synth_name);
2261 spk_vars[0].u.n.high = vc->vc_cols; 2261 spk_vars[0].u.n.high = vc->vc_cols;
2262 for (var = spk_vars; var->var_id != MAXVARS; var++) 2262 for (var = spk_vars; var->var_id != MAXVARS; var++)
2263 speakup_register_var(var); 2263 speakup_register_var(var);
2264 for (var = synth_time_vars; 2264 for (var = synth_time_vars;
2265 (var->var_id >= 0) && (var->var_id < MAXVARS); var++) 2265 (var->var_id >= 0) && (var->var_id < MAXVARS); var++)
2266 speakup_register_var(var); 2266 speakup_register_var(var);
2267 for (i = 1; punc_info[i].mask != 0; i++) 2267 for (i = 1; spk_punc_info[i].mask != 0; i++)
2268 set_mask_bits(0, i, 2); 2268 spk_set_mask_bits(0, i, 2);
2269 2269
2270 set_key_info(key_defaults, key_buf); 2270 spk_set_key_info(spk_key_defaults, spk_key_buf);
2271 2271
2272 /* From here on out, initializations can fail. */ 2272 /* From here on out, initializations can fail. */
2273 err = speakup_add_virtual_keyboard(); 2273 err = speakup_add_virtual_keyboard();
@@ -2290,7 +2290,7 @@ static int __init speakup_init(void)
2290 goto error_kobjects; 2290 goto error_kobjects;
2291 } 2291 }
2292 2292
2293 if (quiet_boot) 2293 if (spk_quiet_boot)
2294 spk_shut_up |= 0x01; 2294 spk_shut_up |= 0x01;
2295 2295
2296 err = speakup_kobj_init(); 2296 err = speakup_kobj_init();
@@ -2352,11 +2352,11 @@ error_virtkeyboard:
2352 speakup_unregister_var(i); 2352 speakup_unregister_var(i);
2353 2353
2354 for (i = 0; i < 256; i++) { 2354 for (i = 0; i < 256; i++) {
2355 if (characters[i] != default_chars[i]) 2355 if (spk_characters[i] != spk_default_chars[i])
2356 kfree(characters[i]); 2356 kfree(spk_characters[i]);
2357 } 2357 }
2358 2358
2359 free_user_msgs(); 2359 spk_free_user_msgs();
2360 2360
2361out: 2361out:
2362 return err; 2362 return err;
diff --git a/drivers/staging/speakup/selection.c b/drivers/staging/speakup/selection.c
index 0612df06a4bf..822ac3d24788 100644
--- a/drivers/staging/speakup/selection.c
+++ b/drivers/staging/speakup/selection.c
@@ -10,7 +10,7 @@
10/* Don't take this from <ctype.h>: 011-015 on the screen aren't spaces */ 10/* Don't take this from <ctype.h>: 011-015 on the screen aren't spaces */
11#define ishardspace(c) ((c) == ' ') 11#define ishardspace(c) ((c) == ' ')
12 12
13unsigned short xs, ys, xe, ye; /* our region points */ 13unsigned short spk_xs, spk_ys, spk_xe, spk_ye; /* our region points */
14 14
15/* Variables for selection control. */ 15/* Variables for selection control. */
16/* must not be disallocated */ 16/* must not be disallocated */
@@ -51,12 +51,12 @@ int speakup_set_selection(struct tty_struct *tty)
51 int i, ps, pe; 51 int i, ps, pe;
52 struct vc_data *vc = vc_cons[fg_console].d; 52 struct vc_data *vc = vc_cons[fg_console].d;
53 53
54 xs = limit(xs, vc->vc_cols - 1); 54 spk_xs = limit(spk_xs, vc->vc_cols - 1);
55 ys = limit(ys, vc->vc_rows - 1); 55 spk_ys = limit(spk_ys, vc->vc_rows - 1);
56 xe = limit(xe, vc->vc_cols - 1); 56 spk_xe = limit(spk_xe, vc->vc_cols - 1);
57 ye = limit(ye, vc->vc_rows - 1); 57 spk_ye = limit(spk_ye, vc->vc_rows - 1);
58 ps = ys * vc->vc_size_row + (xs << 1); 58 ps = spk_ys * vc->vc_size_row + (spk_xs << 1);
59 pe = ye * vc->vc_size_row + (xe << 1); 59 pe = spk_ye * vc->vc_size_row + (spk_xe << 1);
60 60
61 if (ps > pe) { 61 if (ps > pe) {
62 /* make sel_start <= sel_end */ 62 /* make sel_start <= sel_end */
@@ -95,7 +95,6 @@ int speakup_set_selection(struct tty_struct *tty)
95 /* Allocate a new buffer before freeing the old one ... */ 95 /* Allocate a new buffer before freeing the old one ... */
96 bp = kmalloc((sel_end-sel_start)/2+1, GFP_ATOMIC); 96 bp = kmalloc((sel_end-sel_start)/2+1, GFP_ATOMIC);
97 if (!bp) { 97 if (!bp) {
98 dev_warn(tty->dev, "selection: kmalloc() failed\n");
99 speakup_clear_selection(); 98 speakup_clear_selection();
100 return -ENOMEM; 99 return -ENOMEM;
101 } 100 }
diff --git a/drivers/staging/speakup/serialio.c b/drivers/staging/speakup/serialio.c
index a97d3d5b58a4..e4d27aa2898f 100644
--- a/drivers/staging/speakup/serialio.c
+++ b/drivers/staging/speakup/serialio.c
@@ -116,7 +116,7 @@ static void start_serial_interrupt(int irq)
116 outb(1, speakup_info.port_tts + UART_FCR); /* Turn FIFO On */ 116 outb(1, speakup_info.port_tts + UART_FCR); /* Turn FIFO On */
117} 117}
118 118
119void stop_serial_interrupt(void) 119void spk_stop_serial_interrupt(void)
120{ 120{
121 if (speakup_info.port_tts == 0) 121 if (speakup_info.port_tts == 0)
122 return; 122 return;
@@ -130,7 +130,7 @@ void stop_serial_interrupt(void)
130 free_irq(serstate->irq, (void *) synth_readbuf_handler); 130 free_irq(serstate->irq, (void *) synth_readbuf_handler);
131} 131}
132 132
133int wait_for_xmitr(void) 133int spk_wait_for_xmitr(void)
134{ 134{
135 int tmout = SPK_XMITR_TIMEOUT; 135 int tmout = SPK_XMITR_TIMEOUT;
136 if ((synth->alive) && (timeouts >= NUM_DISABLE_TIMEOUTS)) { 136 if ((synth->alive) && (timeouts >= NUM_DISABLE_TIMEOUTS)) {
@@ -195,7 +195,7 @@ EXPORT_SYMBOL_GPL(spk_serial_in_nowait);
195 195
196int spk_serial_out(const char ch) 196int spk_serial_out(const char ch)
197{ 197{
198 if (synth->alive && wait_for_xmitr()) { 198 if (synth->alive && spk_wait_for_xmitr()) {
199 outb_p(ch, speakup_info.port_tts); 199 outb_p(ch, speakup_info.port_tts);
200 return 1; 200 return 1;
201 } 201 }
diff --git a/drivers/staging/speakup/speakup.h b/drivers/staging/speakup/speakup.h
index e66579e6147a..22f0fbb85f42 100644
--- a/drivers/staging/speakup/speakup.h
+++ b/drivers/staging/speakup/speakup.h
@@ -50,34 +50,34 @@
50#define E_UNDEF -1 50#define E_UNDEF -1
51 51
52extern int speakup_thread(void *data); 52extern int speakup_thread(void *data);
53extern void reset_default_chars(void); 53extern void spk_reset_default_chars(void);
54extern void reset_default_chartab(void); 54extern void spk_reset_default_chartab(void);
55extern void synth_start(void); 55extern void synth_start(void);
56void synth_insert_next_index(int sent_num); 56void synth_insert_next_index(int sent_num);
57void reset_index_count(int sc); 57void spk_reset_index_count(int sc);
58void get_index_count(int *linecount, int *sentcount); 58void spk_get_index_count(int *linecount, int *sentcount);
59extern int set_key_info(const u_char *key_info, u_char *k_buffer); 59extern int spk_set_key_info(const u_char *key_info, u_char *k_buffer);
60extern char *strlwr(char *s); 60extern char *spk_strlwr(char *s);
61extern char *speakup_s2i(char *start, int *dest); 61extern char *speakup_s2i(char *start, int *dest);
62extern char *s2uchar(char *start, char *dest); 62extern char *spk_s2uchar(char *start, char *dest);
63extern char *xlate(char *s); 63extern char *spk_xlate(char *s);
64extern int speakup_kobj_init(void); 64extern int speakup_kobj_init(void);
65extern void speakup_kobj_exit(void); 65extern void speakup_kobj_exit(void);
66extern int chartab_get_value(char *keyword); 66extern int spk_chartab_get_value(char *keyword);
67extern void speakup_register_var(struct var_t *var); 67extern void speakup_register_var(struct var_t *var);
68extern void speakup_unregister_var(enum var_id_t var_id); 68extern void speakup_unregister_var(enum var_id_t var_id);
69extern struct st_var_header *get_var_header(enum var_id_t var_id); 69extern struct st_var_header *spk_get_var_header(enum var_id_t var_id);
70extern struct st_var_header *var_header_by_name(const char *name); 70extern struct st_var_header *spk_var_header_by_name(const char *name);
71extern struct punc_var_t *get_punc_var(enum var_id_t var_id); 71extern struct punc_var_t *spk_get_punc_var(enum var_id_t var_id);
72extern int set_num_var(int val, struct st_var_header *var, int how); 72extern int spk_set_num_var(int val, struct st_var_header *var, int how);
73extern int set_string_var(const char *page, struct st_var_header *var, int len); 73extern int spk_set_string_var(const char *page, struct st_var_header *var, int len);
74extern int set_mask_bits(const char *input, const int which, const int how); 74extern int spk_set_mask_bits(const char *input, const int which, const int how);
75extern special_func special_handler; 75extern special_func spk_special_handler;
76extern int handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key); 76extern int spk_handle_help(struct vc_data *vc, u_char type, u_char ch, u_short key);
77extern int synth_init(char *name); 77extern int synth_init(char *name);
78extern void synth_release(void); 78extern void synth_release(void);
79 79
80extern void do_flush(void); 80extern void spk_do_flush(void);
81extern void speakup_start_ttys(void); 81extern void speakup_start_ttys(void);
82extern void synth_buffer_add(char ch); 82extern void synth_buffer_add(char ch);
83extern void synth_buffer_clear(void); 83extern void synth_buffer_clear(void);
@@ -90,35 +90,35 @@ extern void synth_write(const char *buf, size_t count);
90extern int synth_supports_indexing(void); 90extern int synth_supports_indexing(void);
91 91
92extern struct vc_data *spk_sel_cons; 92extern struct vc_data *spk_sel_cons;
93extern unsigned short xs, ys, xe, ye; /* our region points */ 93extern unsigned short spk_xs, spk_ys, spk_xe, spk_ye; /* our region points */
94 94
95extern wait_queue_head_t speakup_event; 95extern wait_queue_head_t speakup_event;
96extern struct kobject *speakup_kobj; 96extern struct kobject *speakup_kobj;
97extern struct task_struct *speakup_task; 97extern struct task_struct *speakup_task;
98extern const u_char key_defaults[]; 98extern const u_char spk_key_defaults[];
99 99
100/* Protect speakup synthesizer list */ 100/* Protect speakup synthesizer list */
101extern struct mutex spk_mutex; 101extern struct mutex spk_mutex;
102extern struct st_spk_t *speakup_console[]; 102extern struct st_spk_t *speakup_console[];
103extern struct spk_synth *synth; 103extern struct spk_synth *synth;
104extern char pitch_buff[]; 104extern char spk_pitch_buff[];
105extern u_char *our_keys[]; 105extern u_char *spk_our_keys[];
106extern short punc_masks[]; 106extern short spk_punc_masks[];
107extern char str_caps_start[], str_caps_stop[]; 107extern char spk_str_caps_start[], spk_str_caps_stop[];
108extern const struct st_bits_data punc_info[]; 108extern const struct st_bits_data spk_punc_info[];
109extern u_char key_buf[600]; 109extern u_char spk_key_buf[600];
110extern char *characters[]; 110extern char *spk_characters[];
111extern char *default_chars[]; 111extern char *spk_default_chars[];
112extern u_short spk_chartab[]; 112extern u_short spk_chartab[];
113extern int no_intr, say_ctrl, say_word_ctl, punc_level; 113extern int spk_no_intr, spk_say_ctrl, spk_say_word_ctl, spk_punc_level;
114extern int reading_punc, attrib_bleep, bleeps; 114extern int spk_reading_punc, spk_attrib_bleep, spk_bleeps;
115extern int bleep_time, bell_pos; 115extern int spk_bleep_time, spk_bell_pos;
116extern int spell_delay, key_echo; 116extern int spk_spell_delay, spk_key_echo;
117extern short punc_mask; 117extern short spk_punc_mask;
118extern short pitch_shift, synth_flags; 118extern short spk_pitch_shift, synth_flags;
119extern bool quiet_boot; 119extern bool spk_quiet_boot;
120extern char *synth_name; 120extern char *synth_name;
121extern struct bleep unprocessed_sound; 121extern struct bleep spk_unprocessed_sound;
122 122
123/* Prototypes from fakekey.c. */ 123/* Prototypes from fakekey.c. */
124int speakup_add_virtual_keyboard(void); 124int speakup_add_virtual_keyboard(void);
diff --git a/drivers/staging/speakup/speakup_acntpc.c b/drivers/staging/speakup/speakup_acntpc.c
index bbe28b6809e0..1c1f0d560449 100644
--- a/drivers/staging/speakup/speakup_acntpc.c
+++ b/drivers/staging/speakup/speakup_acntpc.c
@@ -182,9 +182,9 @@ static void do_catch_up(struct spk_synth *synth)
182 struct var_t *full_time; 182 struct var_t *full_time;
183 struct var_t *jiffy_delta; 183 struct var_t *jiffy_delta;
184 184
185 jiffy_delta = get_var(JIFFY); 185 jiffy_delta = spk_get_var(JIFFY);
186 delay_time = get_var(DELAY); 186 delay_time = spk_get_var(DELAY);
187 full_time = get_var(FULL); 187 full_time = spk_get_var(FULL);
188 188
189 spk_lock(flags); 189 spk_lock(flags);
190 jiffy_delta_val = jiffy_delta->u.n.value; 190 jiffy_delta_val = jiffy_delta->u.n.value;
diff --git a/drivers/staging/speakup/speakup_acntsa.c b/drivers/staging/speakup/speakup_acntsa.c
index 590fa6bb0ed4..22a8b7291098 100644
--- a/drivers/staging/speakup/speakup_acntsa.c
+++ b/drivers/staging/speakup/speakup_acntsa.c
@@ -128,7 +128,7 @@ static int synth_probe(struct spk_synth *synth)
128{ 128{
129 int failed; 129 int failed;
130 130
131 failed = serial_synth_probe(synth); 131 failed = spk_serial_synth_probe(synth);
132 if (failed == 0) { 132 if (failed == 0) {
133 spk_synth_immediate(synth, "\033=R\r"); 133 spk_synth_immediate(synth, "\033=R\r");
134 mdelay(100); 134 mdelay(100);
diff --git a/drivers/staging/speakup/speakup_apollo.c b/drivers/staging/speakup/speakup_apollo.c
index 00d5cedd00ab..3e450ccbda66 100644
--- a/drivers/staging/speakup/speakup_apollo.c
+++ b/drivers/staging/speakup/speakup_apollo.c
@@ -112,7 +112,7 @@ static struct spk_synth synth_apollo = {
112 .startup = SYNTH_START, 112 .startup = SYNTH_START,
113 .checkval = SYNTH_CHECK, 113 .checkval = SYNTH_CHECK,
114 .vars = vars, 114 .vars = vars,
115 .probe = serial_synth_probe, 115 .probe = spk_serial_synth_probe,
116 .release = spk_serial_release, 116 .release = spk_serial_release,
117 .synth_immediate = spk_synth_immediate, 117 .synth_immediate = spk_synth_immediate,
118 .catch_up = do_catch_up, 118 .catch_up = do_catch_up,
@@ -145,9 +145,9 @@ static void do_catch_up(struct spk_synth *synth)
145 int delay_time_val = 0; 145 int delay_time_val = 0;
146 int jiffy_delta_val = 0; 146 int jiffy_delta_val = 0;
147 147
148 jiffy_delta = get_var(JIFFY); 148 jiffy_delta = spk_get_var(JIFFY);
149 delay_time = get_var(DELAY); 149 delay_time = spk_get_var(DELAY);
150 full_time = get_var(FULL); 150 full_time = spk_get_var(FULL);
151 spk_lock(flags); 151 spk_lock(flags);
152 jiffy_delta_val = jiffy_delta->u.n.value; 152 jiffy_delta_val = jiffy_delta->u.n.value;
153 spk_unlock(flags); 153 spk_unlock(flags);
diff --git a/drivers/staging/speakup/speakup_audptr.c b/drivers/staging/speakup/speakup_audptr.c
index 94e509992c8b..3508aee98ab0 100644
--- a/drivers/staging/speakup/speakup_audptr.c
+++ b/drivers/staging/speakup/speakup_audptr.c
@@ -162,7 +162,7 @@ static int synth_probe(struct spk_synth *synth)
162{ 162{
163 int failed = 0; 163 int failed = 0;
164 164
165 failed = serial_synth_probe(synth); 165 failed = spk_serial_synth_probe(synth);
166 if (failed == 0) 166 if (failed == 0)
167 synth_version(synth); 167 synth_version(synth);
168 synth->alive = !failed; 168 synth->alive = !failed;
diff --git a/drivers/staging/speakup/speakup_bns.c b/drivers/staging/speakup/speakup_bns.c
index 43e5b54f344c..4bfe3d458dc0 100644
--- a/drivers/staging/speakup/speakup_bns.c
+++ b/drivers/staging/speakup/speakup_bns.c
@@ -100,7 +100,7 @@ static struct spk_synth synth_bns = {
100 .startup = SYNTH_START, 100 .startup = SYNTH_START,
101 .checkval = SYNTH_CHECK, 101 .checkval = SYNTH_CHECK,
102 .vars = vars, 102 .vars = vars,
103 .probe = serial_synth_probe, 103 .probe = spk_serial_synth_probe,
104 .release = spk_serial_release, 104 .release = spk_serial_release,
105 .synth_immediate = spk_synth_immediate, 105 .synth_immediate = spk_synth_immediate,
106 .catch_up = spk_do_catch_up, 106 .catch_up = spk_do_catch_up,
diff --git a/drivers/staging/speakup/speakup_decext.c b/drivers/staging/speakup/speakup_decext.c
index b4ef9153f42e..d39a0de286fb 100644
--- a/drivers/staging/speakup/speakup_decext.c
+++ b/drivers/staging/speakup/speakup_decext.c
@@ -130,7 +130,7 @@ static struct spk_synth synth_decext = {
130 .startup = SYNTH_START, 130 .startup = SYNTH_START,
131 .checkval = SYNTH_CHECK, 131 .checkval = SYNTH_CHECK,
132 .vars = vars, 132 .vars = vars,
133 .probe = serial_synth_probe, 133 .probe = spk_serial_synth_probe,
134 .release = spk_serial_release, 134 .release = spk_serial_release,
135 .synth_immediate = spk_synth_immediate, 135 .synth_immediate = spk_synth_immediate,
136 .catch_up = do_catch_up, 136 .catch_up = do_catch_up,
@@ -162,8 +162,8 @@ static void do_catch_up(struct spk_synth *synth)
162 int jiffy_delta_val = 0; 162 int jiffy_delta_val = 0;
163 int delay_time_val = 0; 163 int delay_time_val = 0;
164 164
165 jiffy_delta = get_var(JIFFY); 165 jiffy_delta = spk_get_var(JIFFY);
166 delay_time = get_var(DELAY); 166 delay_time = spk_get_var(DELAY);
167 167
168 spk_lock(flags); 168 spk_lock(flags);
169 jiffy_delta_val = jiffy_delta->u.n.value; 169 jiffy_delta_val = jiffy_delta->u.n.value;
diff --git a/drivers/staging/speakup/speakup_decpc.c b/drivers/staging/speakup/speakup_decpc.c
index a09a0c9975df..6c88b55bdac8 100644
--- a/drivers/staging/speakup/speakup_decpc.c
+++ b/drivers/staging/speakup/speakup_decpc.c
@@ -375,8 +375,8 @@ static void do_catch_up(struct spk_synth *synth)
375 int jiffy_delta_val; 375 int jiffy_delta_val;
376 int delay_time_val; 376 int delay_time_val;
377 377
378 jiffy_delta = get_var(JIFFY); 378 jiffy_delta = spk_get_var(JIFFY);
379 delay_time = get_var(DELAY); 379 delay_time = spk_get_var(DELAY);
380 spk_lock(flags); 380 spk_lock(flags);
381 jiffy_delta_val = jiffy_delta->u.n.value; 381 jiffy_delta_val = jiffy_delta->u.n.value;
382 spk_unlock(flags); 382 spk_unlock(flags);
diff --git a/drivers/staging/speakup/speakup_dectlk.c b/drivers/staging/speakup/speakup_dectlk.c
index daff3b9a4a6d..0dd2eb96cb28 100644
--- a/drivers/staging/speakup/speakup_dectlk.c
+++ b/drivers/staging/speakup/speakup_dectlk.c
@@ -134,7 +134,7 @@ static struct spk_synth synth_dectlk = {
134 .vars = vars, 134 .vars = vars,
135 .default_pitch = ap_defaults, 135 .default_pitch = ap_defaults,
136 .default_vol = g5_defaults, 136 .default_vol = g5_defaults,
137 .probe = serial_synth_probe, 137 .probe = spk_serial_synth_probe,
138 .release = spk_serial_release, 138 .release = spk_serial_release,
139 .synth_immediate = spk_synth_immediate, 139 .synth_immediate = spk_synth_immediate,
140 .catch_up = do_catch_up, 140 .catch_up = do_catch_up,
@@ -214,8 +214,8 @@ static void do_catch_up(struct spk_synth *synth)
214 int jiffy_delta_val; 214 int jiffy_delta_val;
215 int delay_time_val; 215 int delay_time_val;
216 216
217 jiffy_delta = get_var(JIFFY); 217 jiffy_delta = spk_get_var(JIFFY);
218 delay_time = get_var(DELAY); 218 delay_time = spk_get_var(DELAY);
219 spk_lock(flags); 219 spk_lock(flags);
220 jiffy_delta_val = jiffy_delta->u.n.value; 220 jiffy_delta_val = jiffy_delta->u.n.value;
221 spk_unlock(flags); 221 spk_unlock(flags);
diff --git a/drivers/staging/speakup/speakup_dtlk.c b/drivers/staging/speakup/speakup_dtlk.c
index 97bc476746cd..a9cefbd3ea93 100644
--- a/drivers/staging/speakup/speakup_dtlk.c
+++ b/drivers/staging/speakup/speakup_dtlk.c
@@ -198,8 +198,8 @@ static void do_catch_up(struct spk_synth *synth)
198 int jiffy_delta_val; 198 int jiffy_delta_val;
199 int delay_time_val; 199 int delay_time_val;
200 200
201 jiffy_delta = get_var(JIFFY); 201 jiffy_delta = spk_get_var(JIFFY);
202 delay_time = get_var(DELAY); 202 delay_time = spk_get_var(DELAY);
203 spk_lock(flags); 203 spk_lock(flags);
204 jiffy_delta_val = jiffy_delta->u.n.value; 204 jiffy_delta_val = jiffy_delta->u.n.value;
205 spk_unlock(flags); 205 spk_unlock(flags);
diff --git a/drivers/staging/speakup/speakup_dummy.c b/drivers/staging/speakup/speakup_dummy.c
index c20f41188be1..4a24b9c1e8e3 100644
--- a/drivers/staging/speakup/speakup_dummy.c
+++ b/drivers/staging/speakup/speakup_dummy.c
@@ -102,7 +102,7 @@ static struct spk_synth synth_dummy = {
102 .startup = SYNTH_START, 102 .startup = SYNTH_START,
103 .checkval = SYNTH_CHECK, 103 .checkval = SYNTH_CHECK,
104 .vars = vars, 104 .vars = vars,
105 .probe = serial_synth_probe, 105 .probe = spk_serial_synth_probe,
106 .release = spk_serial_release, 106 .release = spk_serial_release,
107 .synth_immediate = spk_synth_immediate, 107 .synth_immediate = spk_synth_immediate,
108 .catch_up = spk_do_catch_up, 108 .catch_up = spk_do_catch_up,
diff --git a/drivers/staging/speakup/speakup_keypc.c b/drivers/staging/speakup/speakup_keypc.c
index 496e01481f9e..feb5f22cc169 100644
--- a/drivers/staging/speakup/speakup_keypc.c
+++ b/drivers/staging/speakup/speakup_keypc.c
@@ -184,9 +184,9 @@ static void do_catch_up(struct spk_synth *synth)
184 int full_time_val; 184 int full_time_val;
185 int jiffy_delta_val; 185 int jiffy_delta_val;
186 186
187 jiffy_delta = get_var(JIFFY); 187 jiffy_delta = spk_get_var(JIFFY);
188 delay_time = get_var(DELAY); 188 delay_time = spk_get_var(DELAY);
189 full_time = get_var(FULL); 189 full_time = spk_get_var(FULL);
190spk_lock(flags); 190spk_lock(flags);
191 jiffy_delta_val = jiffy_delta->u.n.value; 191 jiffy_delta_val = jiffy_delta->u.n.value;
192 spk_unlock(flags); 192 spk_unlock(flags);
diff --git a/drivers/staging/speakup/speakup_ltlk.c b/drivers/staging/speakup/speakup_ltlk.c
index 971de1a13712..326f94d6b079 100644
--- a/drivers/staging/speakup/speakup_ltlk.c
+++ b/drivers/staging/speakup/speakup_ltlk.c
@@ -161,7 +161,7 @@ static int synth_probe(struct spk_synth *synth)
161{ 161{
162 int failed = 0; 162 int failed = 0;
163 163
164 failed = serial_synth_probe(synth); 164 failed = spk_serial_synth_probe(synth);
165 if (failed == 0) 165 if (failed == 0)
166 synth_interrogate(synth); 166 synth_interrogate(synth);
167 synth->alive = !failed; 167 synth->alive = !failed;
diff --git a/drivers/staging/speakup/speakup_spkout.c b/drivers/staging/speakup/speakup_spkout.c
index 9a3a80d9701e..e74f85620c68 100644
--- a/drivers/staging/speakup/speakup_spkout.c
+++ b/drivers/staging/speakup/speakup_spkout.c
@@ -107,7 +107,7 @@ static struct spk_synth synth_spkout = {
107 .startup = SYNTH_START, 107 .startup = SYNTH_START,
108 .checkval = SYNTH_CHECK, 108 .checkval = SYNTH_CHECK,
109 .vars = vars, 109 .vars = vars,
110 .probe = serial_synth_probe, 110 .probe = spk_serial_synth_probe,
111 .release = spk_serial_release, 111 .release = spk_serial_release,
112 .synth_immediate = spk_synth_immediate, 112 .synth_immediate = spk_synth_immediate,
113 .catch_up = spk_do_catch_up, 113 .catch_up = spk_do_catch_up,
diff --git a/drivers/staging/speakup/speakup_txprt.c b/drivers/staging/speakup/speakup_txprt.c
index 5d5bf7c3d0b1..5a29b9fcc930 100644
--- a/drivers/staging/speakup/speakup_txprt.c
+++ b/drivers/staging/speakup/speakup_txprt.c
@@ -100,7 +100,7 @@ static struct spk_synth synth_txprt = {
100 .startup = SYNTH_START, 100 .startup = SYNTH_START,
101 .checkval = SYNTH_CHECK, 101 .checkval = SYNTH_CHECK,
102 .vars = vars, 102 .vars = vars,
103 .probe = serial_synth_probe, 103 .probe = spk_serial_synth_probe,
104 .release = spk_serial_release, 104 .release = spk_serial_release,
105 .synth_immediate = spk_synth_immediate, 105 .synth_immediate = spk_synth_immediate,
106 .catch_up = spk_do_catch_up, 106 .catch_up = spk_do_catch_up,
diff --git a/drivers/staging/speakup/spk_priv.h b/drivers/staging/speakup/spk_priv.h
index a47c5b78d57d..303105b46013 100644
--- a/drivers/staging/speakup/spk_priv.h
+++ b/drivers/staging/speakup/spk_priv.h
@@ -45,8 +45,8 @@
45#define KT_SPKUP 15 45#define KT_SPKUP 15
46 46
47extern const struct old_serial_port *spk_serial_init(int index); 47extern const struct old_serial_port *spk_serial_init(int index);
48extern void stop_serial_interrupt(void); 48extern void spk_stop_serial_interrupt(void);
49extern int wait_for_xmitr(void); 49extern int spk_wait_for_xmitr(void);
50extern unsigned char spk_serial_in(void); 50extern unsigned char spk_serial_in(void);
51extern unsigned char spk_serial_in_nowait(void); 51extern unsigned char spk_serial_in_nowait(void);
52extern int spk_serial_out(const char ch); 52extern int spk_serial_out(const char ch);
@@ -55,13 +55,13 @@ extern void spk_serial_release(void);
55extern char synth_buffer_getc(void); 55extern char synth_buffer_getc(void);
56extern char synth_buffer_peek(void); 56extern char synth_buffer_peek(void);
57extern int synth_buffer_empty(void); 57extern int synth_buffer_empty(void);
58extern struct var_t *get_var(enum var_id_t var_id); 58extern struct var_t *spk_get_var(enum var_id_t var_id);
59extern ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr, 59extern ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
60 char *buf); 60 char *buf);
61extern ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr, 61extern ssize_t spk_var_store(struct kobject *kobj, struct kobj_attribute *attr,
62 const char *buf, size_t count); 62 const char *buf, size_t count);
63 63
64extern int serial_synth_probe(struct spk_synth *synth); 64extern int spk_serial_synth_probe(struct spk_synth *synth);
65extern const char *spk_synth_immediate(struct spk_synth *synth, const char *buff); 65extern const char *spk_synth_immediate(struct spk_synth *synth, const char *buff);
66extern void spk_do_catch_up(struct spk_synth *synth); 66extern void spk_do_catch_up(struct spk_synth *synth);
67extern void spk_synth_flush(struct spk_synth *synth); 67extern void spk_synth_flush(struct spk_synth *synth);
diff --git a/drivers/staging/speakup/synth.c b/drivers/staging/speakup/synth.c
index 7616f058a00b..d867dd9109ed 100644
--- a/drivers/staging/speakup/synth.c
+++ b/drivers/staging/speakup/synth.c
@@ -20,9 +20,9 @@
20#define MAXSYNTHS 16 /* Max number of synths in array. */ 20#define MAXSYNTHS 16 /* Max number of synths in array. */
21static struct spk_synth *synths[MAXSYNTHS]; 21static struct spk_synth *synths[MAXSYNTHS];
22struct spk_synth *synth; 22struct spk_synth *synth;
23char pitch_buff[32] = ""; 23char spk_pitch_buff[32] = "";
24static int module_status; 24static int module_status;
25bool quiet_boot; 25bool spk_quiet_boot;
26 26
27struct speakup_info_t speakup_info = { 27struct speakup_info_t speakup_info = {
28 .spinlock = __SPIN_LOCK_UNLOCKED(speakup_info.spinlock), 28 .spinlock = __SPIN_LOCK_UNLOCKED(speakup_info.spinlock),
@@ -32,7 +32,7 @@ EXPORT_SYMBOL_GPL(speakup_info);
32 32
33static int do_synth_init(struct spk_synth *in_synth); 33static int do_synth_init(struct spk_synth *in_synth);
34 34
35int serial_synth_probe(struct spk_synth *synth) 35int spk_serial_synth_probe(struct spk_synth *synth)
36{ 36{
37 const struct old_serial_port *ser; 37 const struct old_serial_port *ser;
38 int failed = 0; 38 int failed = 0;
@@ -59,7 +59,7 @@ int serial_synth_probe(struct spk_synth *synth)
59 synth->alive = 1; 59 synth->alive = 1;
60 return 0; 60 return 0;
61} 61}
62EXPORT_SYMBOL_GPL(serial_synth_probe); 62EXPORT_SYMBOL_GPL(spk_serial_synth_probe);
63 63
64/* Main loop of the progression thread: keep eating from the buffer 64/* Main loop of the progression thread: keep eating from the buffer
65 * and push to the serial port, waiting as needed 65 * and push to the serial port, waiting as needed
@@ -79,9 +79,9 @@ void spk_do_catch_up(struct spk_synth *synth)
79 int delay_time_val; 79 int delay_time_val;
80 int full_time_val; 80 int full_time_val;
81 81
82 jiffy_delta = get_var(JIFFY); 82 jiffy_delta = spk_get_var(JIFFY);
83 full_time = get_var(FULL); 83 full_time = spk_get_var(FULL);
84 delay_time = get_var(DELAY); 84 delay_time = spk_get_var(DELAY);
85 85
86 spk_lock(flags); 86 spk_lock(flags);
87 jiffy_delta_val = jiffy_delta->u.n.value; 87 jiffy_delta_val = jiffy_delta->u.n.value;
@@ -139,7 +139,7 @@ const char *spk_synth_immediate(struct spk_synth *synth, const char *buff)
139 while ((ch = *buff)) { 139 while ((ch = *buff)) {
140 if (ch == '\n') 140 if (ch == '\n')
141 ch = synth->procspeech; 141 ch = synth->procspeech;
142 if (wait_for_xmitr()) 142 if (spk_wait_for_xmitr())
143 outb(ch, speakup_info.port_tts); 143 outb(ch, speakup_info.port_tts);
144 else 144 else
145 return buff; 145 return buff;
@@ -166,7 +166,7 @@ int spk_synth_is_alive_restart(struct spk_synth *synth)
166{ 166{
167 if (synth->alive) 167 if (synth->alive)
168 return 1; 168 return 1;
169 if (!synth->alive && wait_for_xmitr() > 0) { 169 if (!synth->alive && spk_wait_for_xmitr() > 0) {
170 /* restart */ 170 /* restart */
171 synth->alive = 1; 171 synth->alive = 1;
172 synth_printf("%s", synth->init); 172 synth_printf("%s", synth->init);
@@ -192,20 +192,20 @@ void synth_start(void)
192 synth_buffer_clear(); 192 synth_buffer_clear();
193 return; 193 return;
194 } 194 }
195 trigger_time = get_var(TRIGGER); 195 trigger_time = spk_get_var(TRIGGER);
196 if (!timer_pending(&thread_timer)) 196 if (!timer_pending(&thread_timer))
197 mod_timer(&thread_timer, jiffies + 197 mod_timer(&thread_timer, jiffies +
198 msecs_to_jiffies(trigger_time->u.n.value)); 198 msecs_to_jiffies(trigger_time->u.n.value));
199} 199}
200 200
201void do_flush(void) 201void spk_do_flush(void)
202{ 202{
203 speakup_info.flushing = 1; 203 speakup_info.flushing = 1;
204 synth_buffer_clear(); 204 synth_buffer_clear();
205 if (synth->alive) { 205 if (synth->alive) {
206 if (pitch_shift) { 206 if (spk_pitch_shift) {
207 synth_printf("%s", pitch_buff); 207 synth_printf("%s", spk_pitch_buff);
208 pitch_shift = 0; 208 spk_pitch_shift = 0;
209 } 209 }
210 } 210 }
211 wake_up_interruptible_all(&speakup_event); 211 wake_up_interruptible_all(&speakup_event);
@@ -241,7 +241,7 @@ EXPORT_SYMBOL_GPL(synth_printf);
241static int index_count; 241static int index_count;
242static int sentence_count; 242static int sentence_count;
243 243
244void reset_index_count(int sc) 244void spk_reset_index_count(int sc)
245{ 245{
246 static int first = 1; 246 static int first = 1;
247 if (first) 247 if (first)
@@ -277,7 +277,7 @@ void synth_insert_next_index(int sent_num)
277 } 277 }
278} 278}
279 279
280void get_index_count(int *linecount, int *sentcount) 280void spk_get_index_count(int *linecount, int *sentcount)
281{ 281{
282 int ind = synth->get_index(); 282 int ind = synth->get_index();
283 if (ind) { 283 if (ind) {
@@ -384,7 +384,7 @@ static int do_synth_init(struct spk_synth *in_synth)
384 for (var = synth->vars; 384 for (var = synth->vars;
385 (var->var_id >= 0) && (var->var_id < MAXVARS); var++) 385 (var->var_id >= 0) && (var->var_id < MAXVARS); var++)
386 speakup_register_var(var); 386 speakup_register_var(var);
387 if (!quiet_boot) 387 if (!spk_quiet_boot)
388 synth_printf("%s found\n", synth->long_name); 388 synth_printf("%s found\n", synth->long_name);
389 if (synth->attributes.name 389 if (synth->attributes.name
390 && sysfs_create_group(speakup_kobj, &(synth->attributes)) < 0) 390 && sysfs_create_group(speakup_kobj, &(synth->attributes)) < 0)
@@ -412,7 +412,7 @@ void synth_release(void)
412 sysfs_remove_group(speakup_kobj, &(synth->attributes)); 412 sysfs_remove_group(speakup_kobj, &(synth->attributes));
413 for (var = synth->vars; var->var_id != MAXVARS; var++) 413 for (var = synth->vars; var->var_id != MAXVARS; var++)
414 speakup_unregister_var(var->var_id); 414 speakup_unregister_var(var->var_id);
415 stop_serial_interrupt(); 415 spk_stop_serial_interrupt();
416 synth->release(); 416 synth->release();
417 synth = NULL; 417 synth = NULL;
418} 418}
@@ -460,4 +460,4 @@ void synth_remove(struct spk_synth *in_synth)
460} 460}
461EXPORT_SYMBOL_GPL(synth_remove); 461EXPORT_SYMBOL_GPL(synth_remove);
462 462
463short punc_masks[] = { 0, SOME, MOST, PUNC, PUNC|B_SYM }; 463short spk_punc_masks[] = { 0, SOME, MOST, PUNC, PUNC|B_SYM };
diff --git a/drivers/staging/speakup/thread.c b/drivers/staging/speakup/thread.c
index 103c5c81ee85..42fa660a7e0d 100644
--- a/drivers/staging/speakup/thread.c
+++ b/drivers/staging/speakup/thread.c
@@ -23,8 +23,8 @@ int speakup_thread(void *data)
23 DEFINE_WAIT(wait); 23 DEFINE_WAIT(wait);
24 while (1) { 24 while (1) {
25 spk_lock(flags); 25 spk_lock(flags);
26 our_sound = unprocessed_sound; 26 our_sound = spk_unprocessed_sound;
27 unprocessed_sound.active = 0; 27 spk_unprocessed_sound.active = 0;
28 prepare_to_wait(&speakup_event, &wait, 28 prepare_to_wait(&speakup_event, &wait,
29 TASK_INTERRUPTIBLE); 29 TASK_INTERRUPTIBLE);
30 should_break = kthread_should_stop() || 30 should_break = kthread_should_stop() ||
diff --git a/drivers/staging/speakup/varhandlers.c b/drivers/staging/speakup/varhandlers.c
index ab7de9389dd6..f8c1e457d389 100644
--- a/drivers/staging/speakup/varhandlers.c
+++ b/drivers/staging/speakup/varhandlers.c
@@ -16,24 +16,24 @@ static struct st_var_header var_headers[] = {
16 { "ex_num", EXNUMBER, VAR_PROC, NULL, NULL }, 16 { "ex_num", EXNUMBER, VAR_PROC, NULL, NULL },
17 { "characters", CHARS, VAR_PROC, NULL, NULL }, 17 { "characters", CHARS, VAR_PROC, NULL, NULL },
18 { "synth_direct", SYNTH_DIRECT, VAR_PROC, NULL, NULL }, 18 { "synth_direct", SYNTH_DIRECT, VAR_PROC, NULL, NULL },
19 { "caps_start", CAPS_START, VAR_STRING, str_caps_start, NULL }, 19 { "caps_start", CAPS_START, VAR_STRING, spk_str_caps_start, NULL },
20 { "caps_stop", CAPS_STOP, VAR_STRING, str_caps_stop, NULL }, 20 { "caps_stop", CAPS_STOP, VAR_STRING, spk_str_caps_stop, NULL },
21 { "delay_time", DELAY, VAR_TIME, NULL, NULL }, 21 { "delay_time", DELAY, VAR_TIME, NULL, NULL },
22 { "trigger_time", TRIGGER, VAR_TIME, NULL, NULL }, 22 { "trigger_time", TRIGGER, VAR_TIME, NULL, NULL },
23 { "jiffy_delta", JIFFY, VAR_TIME, NULL, NULL }, 23 { "jiffy_delta", JIFFY, VAR_TIME, NULL, NULL },
24 { "full_time", FULL, VAR_TIME, NULL, NULL }, 24 { "full_time", FULL, VAR_TIME, NULL, NULL },
25 { "spell_delay", SPELL_DELAY, VAR_NUM, &spell_delay, NULL }, 25 { "spell_delay", SPELL_DELAY, VAR_NUM, &spk_spell_delay, NULL },
26 { "bleeps", BLEEPS, VAR_NUM, &bleeps, NULL }, 26 { "bleeps", BLEEPS, VAR_NUM, &spk_bleeps, NULL },
27 { "attrib_bleep", ATTRIB_BLEEP, VAR_NUM, &attrib_bleep, NULL }, 27 { "attrib_bleep", ATTRIB_BLEEP, VAR_NUM, &spk_attrib_bleep, NULL },
28 { "bleep_time", BLEEP_TIME, VAR_TIME, &bleep_time, NULL }, 28 { "bleep_time", BLEEP_TIME, VAR_TIME, &spk_bleep_time, NULL },
29 { "cursor_time", CURSOR_TIME, VAR_TIME, NULL, NULL }, 29 { "cursor_time", CURSOR_TIME, VAR_TIME, NULL, NULL },
30 { "punc_level", PUNC_LEVEL, VAR_NUM, &punc_level, NULL }, 30 { "punc_level", PUNC_LEVEL, VAR_NUM, &spk_punc_level, NULL },
31 { "reading_punc", READING_PUNC, VAR_NUM, &reading_punc, NULL }, 31 { "reading_punc", READING_PUNC, VAR_NUM, &spk_reading_punc, NULL },
32 { "say_control", SAY_CONTROL, VAR_NUM, &say_ctrl, NULL }, 32 { "say_control", SAY_CONTROL, VAR_NUM, &spk_say_ctrl, NULL },
33 { "say_word_ctl", SAY_WORD_CTL, VAR_NUM, &say_word_ctl, NULL }, 33 { "say_word_ctl", SAY_WORD_CTL, VAR_NUM, &spk_say_word_ctl, NULL },
34 { "no_interrupt", NO_INTERRUPT, VAR_NUM, &no_intr, NULL }, 34 { "no_interrupt", NO_INTERRUPT, VAR_NUM, &spk_no_intr, NULL },
35 { "key_echo", KEY_ECHO, VAR_NUM, &key_echo, NULL }, 35 { "key_echo", KEY_ECHO, VAR_NUM, &spk_key_echo, NULL },
36 { "bell_pos", BELL_POS, VAR_NUM, &bell_pos, NULL }, 36 { "bell_pos", BELL_POS, VAR_NUM, &spk_bell_pos, NULL },
37 { "rate", RATE, VAR_NUM, NULL, NULL }, 37 { "rate", RATE, VAR_NUM, NULL, NULL },
38 { "pitch", PITCH, VAR_NUM, NULL, NULL }, 38 { "pitch", PITCH, VAR_NUM, NULL, NULL },
39 { "vol", VOL, VAR_NUM, NULL, NULL }, 39 { "vol", VOL, VAR_NUM, NULL, NULL },
@@ -58,7 +58,7 @@ static struct punc_var_t punc_vars[] = {
58 { -1, -1 }, 58 { -1, -1 },
59}; 59};
60 60
61int chartab_get_value(char *keyword) 61int spk_chartab_get_value(char *keyword)
62{ 62{
63 int value = 0; 63 int value = 0;
64 64
@@ -103,11 +103,11 @@ void speakup_register_var(struct var_t *var)
103 p_header->data = var; 103 p_header->data = var;
104 switch (p_header->var_type) { 104 switch (p_header->var_type) {
105 case VAR_STRING: 105 case VAR_STRING:
106 set_string_var(nothing, p_header, 0); 106 spk_set_string_var(nothing, p_header, 0);
107 break; 107 break;
108 case VAR_NUM: 108 case VAR_NUM:
109 case VAR_TIME: 109 case VAR_TIME:
110 set_num_var(0, p_header, E_DEFAULT); 110 spk_set_num_var(0, p_header, E_DEFAULT);
111 break; 111 break;
112 default: 112 default:
113 break; 113 break;
@@ -123,7 +123,7 @@ void speakup_unregister_var(enum var_id_t var_id)
123 p_header->data = NULL; 123 p_header->data = NULL;
124} 124}
125 125
126struct st_var_header *get_var_header(enum var_id_t var_id) 126struct st_var_header *spk_get_var_header(enum var_id_t var_id)
127{ 127{
128 struct st_var_header *p_header; 128 struct st_var_header *p_header;
129 if (var_id < 0 || var_id >= MAXVARS) 129 if (var_id < 0 || var_id >= MAXVARS)
@@ -134,7 +134,7 @@ struct st_var_header *get_var_header(enum var_id_t var_id)
134 return p_header; 134 return p_header;
135} 135}
136 136
137struct st_var_header *var_header_by_name(const char *name) 137struct st_var_header *spk_var_header_by_name(const char *name)
138{ 138{
139 int i; 139 int i;
140 struct st_var_header *where = NULL; 140 struct st_var_header *where = NULL;
@@ -151,15 +151,15 @@ struct st_var_header *var_header_by_name(const char *name)
151 return where; 151 return where;
152} 152}
153 153
154struct var_t *get_var(enum var_id_t var_id) 154struct var_t *spk_get_var(enum var_id_t var_id)
155{ 155{
156 BUG_ON(var_id < 0 || var_id >= MAXVARS); 156 BUG_ON(var_id < 0 || var_id >= MAXVARS);
157 BUG_ON(!var_ptrs[var_id]); 157 BUG_ON(!var_ptrs[var_id]);
158 return var_ptrs[var_id]->data; 158 return var_ptrs[var_id]->data;
159} 159}
160EXPORT_SYMBOL_GPL(get_var); 160EXPORT_SYMBOL_GPL(spk_get_var);
161 161
162struct punc_var_t *get_punc_var(enum var_id_t var_id) 162struct punc_var_t *spk_get_punc_var(enum var_id_t var_id)
163{ 163{
164 struct punc_var_t *rv = NULL; 164 struct punc_var_t *rv = NULL;
165 struct punc_var_t *where; 165 struct punc_var_t *where;
@@ -175,7 +175,7 @@ struct punc_var_t *get_punc_var(enum var_id_t var_id)
175} 175}
176 176
177/* handlers for setting vars */ 177/* handlers for setting vars */
178int set_num_var(int input, struct st_var_header *var, int how) 178int spk_set_num_var(int input, struct st_var_header *var, int how)
179{ 179{
180 int val; 180 int val;
181 short ret = 0; 181 short ret = 0;
@@ -217,7 +217,7 @@ int set_num_var(int input, struct st_var_header *var, int how)
217 if (p_val != NULL) 217 if (p_val != NULL)
218 *p_val = val; 218 *p_val = val;
219 if (var->var_id == PUNC_LEVEL) { 219 if (var->var_id == PUNC_LEVEL) {
220 punc_mask = punc_masks[val]; 220 spk_punc_mask = spk_punc_masks[val];
221 return ret; 221 return ret;
222 } 222 }
223 if (var_data->u.n.multiplier != 0) 223 if (var_data->u.n.multiplier != 0)
@@ -232,7 +232,7 @@ int set_num_var(int input, struct st_var_header *var, int how)
232 if (!var_data->u.n.synth_fmt) 232 if (!var_data->u.n.synth_fmt)
233 return ret; 233 return ret;
234 if (var->var_id == PITCH) 234 if (var->var_id == PITCH)
235 cp = pitch_buff; 235 cp = spk_pitch_buff;
236 else 236 else
237 cp = buf; 237 cp = buf;
238 if (!var_data->u.n.out_str) 238 if (!var_data->u.n.out_str)
@@ -244,7 +244,7 @@ int set_num_var(int input, struct st_var_header *var, int how)
244 return ret; 244 return ret;
245} 245}
246 246
247int set_string_var(const char *page, struct st_var_header *var, int len) 247int spk_set_string_var(const char *page, struct st_var_header *var, int len)
248{ 248{
249 int ret = 0; 249 int ret = 0;
250 struct var_t *var_data = var->data; 250 struct var_t *var_data = var->data;
@@ -267,21 +267,21 @@ int set_string_var(const char *page, struct st_var_header *var, int len)
267 return ret; 267 return ret;
268} 268}
269 269
270/* set_mask_bits sets or clears the punc/delim/repeat bits, 270/* spk_set_mask_bits sets or clears the punc/delim/repeat bits,
271 * if input is null uses the defaults. 271 * if input is null uses the defaults.
272 * values for how: 0 clears bits of chars supplied, 272 * values for how: 0 clears bits of chars supplied,
273 * 1 clears allk, 2 sets bits for chars */ 273 * 1 clears allk, 2 sets bits for chars */
274int set_mask_bits(const char *input, const int which, const int how) 274int spk_set_mask_bits(const char *input, const int which, const int how)
275{ 275{
276 u_char *cp; 276 u_char *cp;
277 short mask = punc_info[which].mask; 277 short mask = spk_punc_info[which].mask;
278 if (how&1) { 278 if (how&1) {
279 for (cp = (u_char *)punc_info[3].value; *cp; cp++) 279 for (cp = (u_char *)spk_punc_info[3].value; *cp; cp++)
280 spk_chartab[*cp] &= ~mask; 280 spk_chartab[*cp] &= ~mask;
281 } 281 }
282 cp = (u_char *)input; 282 cp = (u_char *)input;
283 if (cp == 0) 283 if (cp == 0)
284 cp = punc_info[which].value; 284 cp = spk_punc_info[which].value;
285 else { 285 else {
286 for ( ; *cp; cp++) { 286 for ( ; *cp; cp++) {
287 if (*cp < SPACE) 287 if (*cp < SPACE)
@@ -308,7 +308,7 @@ int set_mask_bits(const char *input, const int which, const int how)
308 return 0; 308 return 0;
309} 309}
310 310
311char *strlwr(char *s) 311char *spk_strlwr(char *s)
312{ 312{
313 char *p; 313 char *p;
314 if (s == NULL) 314 if (s == NULL)
@@ -341,7 +341,7 @@ char *speakup_s2i(char *start, int *dest)
341 return start; 341 return start;
342} 342}
343 343
344char *s2uchar(char *start, char *dest) 344char *spk_s2uchar(char *start, char *dest)
345{ 345{
346 int val = 0; 346 int val = 0;
347 while (*start && *start <= SPACE) 347 while (*start && *start <= SPACE)
@@ -357,7 +357,7 @@ char *s2uchar(char *start, char *dest)
357 return start; 357 return start;
358} 358}
359 359
360char *xlate(char *s) 360char *spk_xlate(char *s)
361{ 361{
362 static const char finds[] = "nrtvafe"; 362 static const char finds[] = "nrtvafe";
363 static const char subs[] = "\n\r\t\013\001\014\033"; 363 static const char subs[] = "\n\r\t\013\001\014\033";
diff --git a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
index 299f51810199..6a21f67af086 100644
--- a/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
+++ b/drivers/staging/ste_rmi4/synaptics_i2c_rmi4.c
@@ -742,13 +742,9 @@ static int synaptics_rmi4_i2c_query_device(struct synaptics_rmi4_data *pdata)
742 case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM: 742 case SYNAPTICS_RMI4_TOUCHPAD_FUNC_NUM:
743 if (rmi_fd.intr_src_count) { 743 if (rmi_fd.intr_src_count) {
744 rfi = kmalloc(sizeof(*rfi), 744 rfi = kmalloc(sizeof(*rfi),
745 GFP_KERNEL); 745 GFP_KERNEL);
746 if (!rfi) { 746 if (!rfi)
747 dev_err(&client->dev, 747 return -ENOMEM;
748 "%s:kmalloc failed\n",
749 __func__);
750 return -ENOMEM;
751 }
752 retval = synpatics_rmi4_touchpad_detect 748 retval = synpatics_rmi4_touchpad_detect
753 (pdata, rfi, 749 (pdata, rfi,
754 &rmi_fd, 750 &rmi_fd,
@@ -900,12 +896,10 @@ static int synaptics_rmi4_probe
900 } 896 }
901 897
902 /* Allocate and initialize the instance data for this client */ 898 /* Allocate and initialize the instance data for this client */
903 rmi4_data = kzalloc(sizeof(struct synaptics_rmi4_data) * 2, 899 rmi4_data = kcalloc(2, sizeof(struct synaptics_rmi4_data),
904 GFP_KERNEL); 900 GFP_KERNEL);
905 if (!rmi4_data) { 901 if (!rmi4_data)
906 dev_err(&client->dev, "%s: no memory allocated\n", __func__);
907 return -ENOMEM; 902 return -ENOMEM;
908 }
909 903
910 rmi4_data->input_dev = input_allocate_device(); 904 rmi4_data->input_dev = input_allocate_device();
911 if (rmi4_data->input_dev == NULL) { 905 if (rmi4_data->input_dev == NULL) {
diff --git a/drivers/staging/tidspbridge/core/msg_sm.c b/drivers/staging/tidspbridge/core/msg_sm.c
index ce9557e16eb0..7b517eb827fe 100644
--- a/drivers/staging/tidspbridge/core/msg_sm.c
+++ b/drivers/staging/tidspbridge/core/msg_sm.c
@@ -198,8 +198,7 @@ out_err:
198 */ 198 */
199void bridge_msg_delete(struct msg_mgr *hmsg_mgr) 199void bridge_msg_delete(struct msg_mgr *hmsg_mgr)
200{ 200{
201 if (hmsg_mgr) 201 delete_msg_mgr(hmsg_mgr);
202 delete_msg_mgr(hmsg_mgr);
203} 202}
204 203
205/* 204/*
diff --git a/drivers/staging/tidspbridge/core/tiomap3430.c b/drivers/staging/tidspbridge/core/tiomap3430.c
index f619fb3c56d2..b770b2281ce8 100644
--- a/drivers/staging/tidspbridge/core/tiomap3430.c
+++ b/drivers/staging/tidspbridge/core/tiomap3430.c
@@ -70,14 +70,9 @@
70#define PAGES_II_LVL_TABLE 512 70#define PAGES_II_LVL_TABLE 512
71#define PHYS_TO_PAGE(phys) pfn_to_page((phys) >> PAGE_SHIFT) 71#define PHYS_TO_PAGE(phys) pfn_to_page((phys) >> PAGE_SHIFT)
72 72
73/* 73/* IVA Boot modes */
74 * This is a totally ugly layer violation, but needed until 74#define DIRECT 0
75 * omap_ctrl_set_dsp_boot*() are provided. 75#define IDLE 1
76 */
77#define OMAP3_IVA2_BOOTMOD_IDLE 1
78#define OMAP2_CONTROL_GENERAL 0x270
79#define OMAP343X_CONTROL_IVA2_BOOTADDR (OMAP2_CONTROL_GENERAL + 0x0190)
80#define OMAP343X_CONTROL_IVA2_BOOTMOD (OMAP2_CONTROL_GENERAL + 0x0194)
81 76
82/* Forward Declarations: */ 77/* Forward Declarations: */
83static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt); 78static int bridge_brd_monitor(struct bridge_dev_context *dev_ctxt);
@@ -423,29 +418,14 @@ static int bridge_brd_start(struct bridge_dev_context *dev_ctxt,
423 418
424 /* Assert RST1 i.e only the RST only for DSP megacell */ 419 /* Assert RST1 i.e only the RST only for DSP megacell */
425 if (!status) { 420 if (!status) {
426 /*
427 * XXX: OMAP343X_CTRL_BASE ioremapping MUST be removed once ctrl
428 * function is made available.
429 */
430 void __iomem *ctrl = ioremap(0x48002000, SZ_4K);
431 if (!ctrl) {
432 iounmap(sync_addr);
433 return -ENOMEM;
434 }
435
436 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK, 421 (*pdata->dsp_prm_rmw_bits)(OMAP3430_RST1_IVA2_MASK,
437 OMAP3430_RST1_IVA2_MASK, OMAP3430_IVA2_MOD, 422 OMAP3430_RST1_IVA2_MASK, OMAP3430_IVA2_MOD,
438 OMAP2_RM_RSTCTRL); 423 OMAP2_RM_RSTCTRL);
439 /* Mask address with 1K for compatibility */
440 __raw_writel(dsp_addr & OMAP3_IVA2_BOOTADDR_MASK,
441 ctrl + OMAP343X_CONTROL_IVA2_BOOTADDR);
442 /*
443 * Set bootmode to self loop if dsp_debug flag is true
444 */
445 __raw_writel((dsp_debug) ? OMAP3_IVA2_BOOTMOD_IDLE : 0,
446 ctrl + OMAP343X_CONTROL_IVA2_BOOTMOD);
447 424
448 iounmap(ctrl); 425 /* Mask address with 1K for compatibility */
426 pdata->set_bootaddr(dsp_addr &
427 OMAP3_IVA2_BOOTADDR_MASK);
428 pdata->set_bootmode(dsp_debug ? IDLE : DIRECT);
449 } 429 }
450 } 430 }
451 if (!status) { 431 if (!status) {
diff --git a/drivers/staging/tidspbridge/include/dspbridge/proc.h b/drivers/staging/tidspbridge/include/dspbridge/proc.h
index 851b356d7a51..774a3f6ff201 100644
--- a/drivers/staging/tidspbridge/include/dspbridge/proc.h
+++ b/drivers/staging/tidspbridge/include/dspbridge/proc.h
@@ -23,8 +23,6 @@
23#include <dspbridge/devdefs.h> 23#include <dspbridge/devdefs.h>
24#include <dspbridge/drv.h> 24#include <dspbridge/drv.h>
25 25
26extern char *iva_img;
27
28/* 26/*
29 * ======== proc_attach ======== 27 * ======== proc_attach ========
30 * Purpose: 28 * Purpose:
diff --git a/drivers/staging/tidspbridge/pmgr/cod.c b/drivers/staging/tidspbridge/pmgr/cod.c
index 4007826f7abc..6c29379baf60 100644
--- a/drivers/staging/tidspbridge/pmgr/cod.c
+++ b/drivers/staging/tidspbridge/pmgr/cod.c
@@ -289,7 +289,7 @@ int cod_get_base_name(struct cod_manager *cod_mgr_obj, char *sz_name,
289 int status = 0; 289 int status = 0;
290 290
291 if (usize <= COD_MAXPATHLENGTH) 291 if (usize <= COD_MAXPATHLENGTH)
292 strncpy(sz_name, cod_mgr_obj->sz_zl_file, usize); 292 strlcpy(sz_name, cod_mgr_obj->sz_zl_file, usize);
293 else 293 else
294 status = -EPERM; 294 status = -EPERM;
295 295
diff --git a/drivers/staging/tidspbridge/pmgr/dbll.c b/drivers/staging/tidspbridge/pmgr/dbll.c
index 9f07036cd411..c191ae203565 100644
--- a/drivers/staging/tidspbridge/pmgr/dbll.c
+++ b/drivers/staging/tidspbridge/pmgr/dbll.c
@@ -1382,7 +1382,7 @@ void find_symbol_callback(void *elem, void *user_data)
1382 offset < context->cur_best_offset) { 1382 offset < context->cur_best_offset) {
1383 context->cur_best_offset = offset; 1383 context->cur_best_offset = offset;
1384 context->sym_addr = symbol_addr; 1384 context->sym_addr = symbol_addr;
1385 strncpy(context->name, symbol->name, sizeof(context->name)); 1385 strlcpy(context->name, symbol->name, sizeof(context->name));
1386 } 1386 }
1387 1387
1388 return; 1388 return;
diff --git a/drivers/staging/tidspbridge/pmgr/dspapi.c b/drivers/staging/tidspbridge/pmgr/dspapi.c
index 9ef1ad9527af..70db4ff99ec6 100644
--- a/drivers/staging/tidspbridge/pmgr/dspapi.c
+++ b/drivers/staging/tidspbridge/pmgr/dspapi.c
@@ -414,10 +414,13 @@ u32 mgrwrap_register_object(union trapped_args *args, void *pr_ctxt)
414 CP_FM_USR(&uuid_obj, args->args_mgr_registerobject.uuid_obj, status, 1); 414 CP_FM_USR(&uuid_obj, args->args_mgr_registerobject.uuid_obj, status, 1);
415 if (status) 415 if (status)
416 goto func_end; 416 goto func_end;
417 /* path_size is increased by 1 to accommodate NULL */
418 path_size = strlen_user((char *) 417 path_size = strlen_user((char *)
419 args->args_mgr_registerobject.sz_path_name) + 418 args->args_mgr_registerobject.sz_path_name);
420 1; 419 if (!path_size) {
420 status = -EINVAL;
421 goto func_end;
422 }
423
421 psz_path_name = kmalloc(path_size, GFP_KERNEL); 424 psz_path_name = kmalloc(path_size, GFP_KERNEL);
422 if (!psz_path_name) { 425 if (!psz_path_name) {
423 status = -ENOMEM; 426 status = -ENOMEM;
@@ -1540,7 +1543,7 @@ u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt)
1540 if (num_bufs > MAX_BUFS) 1543 if (num_bufs > MAX_BUFS)
1541 return -EINVAL; 1544 return -EINVAL;
1542 1545
1543 ap_buffer = kmalloc((num_bufs * sizeof(u8 *)), GFP_KERNEL); 1546 ap_buffer = kmalloc_array(num_bufs, sizeof(u8 *), GFP_KERNEL);
1544 if (ap_buffer == NULL) 1547 if (ap_buffer == NULL)
1545 return -ENOMEM; 1548 return -ENOMEM;
1546 1549
diff --git a/drivers/staging/tidspbridge/rmgr/dbdcd.c b/drivers/staging/tidspbridge/rmgr/dbdcd.c
index 9d52c3cb92f0..3d2a26f1efe5 100644
--- a/drivers/staging/tidspbridge/rmgr/dbdcd.c
+++ b/drivers/staging/tidspbridge/rmgr/dbdcd.c
@@ -852,8 +852,7 @@ int dcd_register_object(struct dsp_uuid *uuid_obj,
852 goto func_end; 852 goto func_end;
853 } 853 }
854 854
855 dcd_key->path = kmalloc(strlen(sz_reg_key) + 1, 855 dcd_key->path = kmalloc(dw_path_size, GFP_KERNEL);
856 GFP_KERNEL);
857 856
858 if (!dcd_key->path) { 857 if (!dcd_key->path) {
859 kfree(dcd_key); 858 kfree(dcd_key);
diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index e6f31d817d6b..df0f37ea1ee5 100644
--- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
+++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
@@ -65,7 +65,6 @@ static struct class *bridge_class;
65static u32 driver_context; 65static u32 driver_context;
66static s32 driver_major; 66static s32 driver_major;
67static char *base_img; 67static char *base_img;
68char *iva_img;
69static s32 shm_size = 0x500000; /* 5 MB */ 68static s32 shm_size = 0x500000; /* 5 MB */
70static int tc_wordswapon; /* Default value is always false */ 69static int tc_wordswapon; /* Default value is always false */
71#ifdef CONFIG_TIDSPBRIDGE_RECOVERY 70#ifdef CONFIG_TIDSPBRIDGE_RECOVERY
diff --git a/drivers/staging/tidspbridge/rmgr/nldr.c b/drivers/staging/tidspbridge/rmgr/nldr.c
index 6309221b64a5..ca3805046a73 100644
--- a/drivers/staging/tidspbridge/rmgr/nldr.c
+++ b/drivers/staging/tidspbridge/rmgr/nldr.c
@@ -1802,8 +1802,6 @@ int nldr_find_addr(struct nldr_nodeobject *nldr_node, u32 sym_addr,
1802 bool status1 = false; 1802 bool status1 = false;
1803 s32 i = 0; 1803 s32 i = 0;
1804 struct lib_node root = { NULL, 0, NULL }; 1804 struct lib_node root = { NULL, 0, NULL };
1805 pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", __func__, (u32) nldr_node,
1806 sym_addr, offset_range, (u32) offset_output, sym_name);
1807 1805
1808 if (nldr_node->dynamic && *nldr_node->phase_split) { 1806 if (nldr_node->dynamic && *nldr_node->phase_split) {
1809 switch (nldr_node->phase) { 1807 switch (nldr_node->phase) {
@@ -1852,6 +1850,10 @@ int nldr_find_addr(struct nldr_nodeobject *nldr_node, u32 sym_addr,
1852 pr_debug("%s: Address 0x%x not found in range %d.\n", 1850 pr_debug("%s: Address 0x%x not found in range %d.\n",
1853 __func__, sym_addr, offset_range); 1851 __func__, sym_addr, offset_range);
1854 status = -ESPIPE; 1852 status = -ESPIPE;
1853 } else {
1854 pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n",
1855 __func__, (u32) nldr_node, sym_addr, offset_range,
1856 (u32) offset_output, sym_name);
1855 } 1857 }
1856 1858
1857 return status; 1859 return status;
diff --git a/drivers/staging/tidspbridge/rmgr/node.c b/drivers/staging/tidspbridge/rmgr/node.c
index 737f4a9d86a3..87dfa92ab45b 100644
--- a/drivers/staging/tidspbridge/rmgr/node.c
+++ b/drivers/staging/tidspbridge/rmgr/node.c
@@ -3012,16 +3012,16 @@ int node_find_addr(struct node_mgr *node_mgr, u32 sym_addr,
3012 struct node_object *node_obj; 3012 struct node_object *node_obj;
3013 int status = -ENOENT; 3013 int status = -ENOENT;
3014 3014
3015 pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", __func__,
3016 (unsigned int) node_mgr,
3017 sym_addr, offset_range,
3018 (unsigned int) sym_addr_output, sym_name);
3019
3020 list_for_each_entry(node_obj, &node_mgr->node_list, list_elem) { 3015 list_for_each_entry(node_obj, &node_mgr->node_list, list_elem) {
3021 status = nldr_find_addr(node_obj->nldr_node_obj, sym_addr, 3016 status = nldr_find_addr(node_obj->nldr_node_obj, sym_addr,
3022 offset_range, sym_addr_output, sym_name); 3017 offset_range, sym_addr_output, sym_name);
3023 if (!status) 3018 if (!status) {
3019 pr_debug("%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", __func__,
3020 (unsigned int) node_mgr,
3021 sym_addr, offset_range,
3022 (unsigned int) sym_addr_output, sym_name);
3024 break; 3023 break;
3024 }
3025 } 3025 }
3026 3026
3027 return status; 3027 return status;
diff --git a/drivers/staging/tidspbridge/rmgr/proc.c b/drivers/staging/tidspbridge/rmgr/proc.c
index 5e43938ab7fa..0df55bd5bde4 100644
--- a/drivers/staging/tidspbridge/rmgr/proc.c
+++ b/drivers/staging/tidspbridge/rmgr/proc.c
@@ -119,16 +119,14 @@ static struct dmm_map_object *add_mapping_info(struct process_context *pr_ctxt,
119 dsp_addr, size); 119 dsp_addr, size);
120 120
121 map_obj = kzalloc(sizeof(struct dmm_map_object), GFP_KERNEL); 121 map_obj = kzalloc(sizeof(struct dmm_map_object), GFP_KERNEL);
122 if (!map_obj) { 122 if (!map_obj)
123 pr_err("%s: kzalloc failed\n", __func__);
124 return NULL; 123 return NULL;
125 } 124
126 INIT_LIST_HEAD(&map_obj->link); 125 INIT_LIST_HEAD(&map_obj->link);
127 126
128 map_obj->pages = kcalloc(num_usr_pgs, sizeof(struct page *), 127 map_obj->pages = kcalloc(num_usr_pgs, sizeof(struct page *),
129 GFP_KERNEL); 128 GFP_KERNEL);
130 if (!map_obj->pages) { 129 if (!map_obj->pages) {
131 pr_err("%s: kzalloc failed\n", __func__);
132 kfree(map_obj); 130 kfree(map_obj);
133 return NULL; 131 return NULL;
134 } 132 }
@@ -382,7 +380,6 @@ static int get_exec_file(struct cfg_devnode *dev_node_obj,
382 u32 size, char *exec_file) 380 u32 size, char *exec_file)
383{ 381{
384 u8 dev_type; 382 u8 dev_type;
385 s32 len;
386 struct drv_data *drv_datap = dev_get_drvdata(bridge); 383 struct drv_data *drv_datap = dev_get_drvdata(bridge);
387 384
388 dev_get_dev_type(hdev_obj, (u8 *) &dev_type); 385 dev_get_dev_type(hdev_obj, (u8 *) &dev_type);
@@ -394,13 +391,10 @@ static int get_exec_file(struct cfg_devnode *dev_node_obj,
394 if (!drv_datap || !drv_datap->base_img) 391 if (!drv_datap || !drv_datap->base_img)
395 return -EFAULT; 392 return -EFAULT;
396 393
397 if (strlen(drv_datap->base_img) > size) 394 if (strlen(drv_datap->base_img) >= size)
398 return -EINVAL; 395 return -EINVAL;
399 396
400 strcpy(exec_file, drv_datap->base_img); 397 strcpy(exec_file, drv_datap->base_img);
401 } else if (dev_type == IVA_UNIT && iva_img) {
402 len = strlen(iva_img);
403 strncpy(exec_file, iva_img, len + 1);
404 } else { 398 } else {
405 return -ENOENT; 399 return -ENOENT;
406 } 400 }
@@ -697,7 +691,6 @@ static int memory_give_ownership(struct dmm_map_object *map_obj,
697 691
698 sg = kcalloc(num_pages, sizeof(*sg), GFP_KERNEL); 692 sg = kcalloc(num_pages, sizeof(*sg), GFP_KERNEL);
699 if (!sg) { 693 if (!sg) {
700 pr_err("%s: kcalloc failed\n", __func__);
701 ret = -ENOMEM; 694 ret = -ENOMEM;
702 goto out; 695 goto out;
703 } 696 }
@@ -1231,12 +1224,8 @@ int proc_load(void *hprocessor, const s32 argc_index,
1231 (p_proc_object->bridge_context, &brd_state))) { 1224 (p_proc_object->bridge_context, &brd_state))) {
1232 pr_info("%s: Processor Loaded %s\n", __func__, pargv0); 1225 pr_info("%s: Processor Loaded %s\n", __func__, pargv0);
1233 kfree(drv_datap->base_img); 1226 kfree(drv_datap->base_img);
1234 drv_datap->base_img = kmalloc(strlen(pargv0) + 1, 1227 drv_datap->base_img = kstrdup(pargv0, GFP_KERNEL);
1235 GFP_KERNEL); 1228 if (!drv_datap->base_img)
1236 if (drv_datap->base_img)
1237 strncpy(drv_datap->base_img, pargv0,
1238 strlen(pargv0) + 1);
1239 else
1240 status = -ENOMEM; 1229 status = -ENOMEM;
1241 } 1230 }
1242 } 1231 }
diff --git a/drivers/staging/usbip/Kconfig b/drivers/staging/usbip/Kconfig
index 199b1d4c0b85..886000980474 100644
--- a/drivers/staging/usbip/Kconfig
+++ b/drivers/staging/usbip/Kconfig
@@ -8,7 +8,7 @@ config USBIP_CORE
8 USB/IP core that is required by both drivers. 8 USB/IP core that is required by both drivers.
9 9
10 For more details, and to get the userspace utility 10 For more details, and to get the userspace utility
11 programs, please see http://usbip.sourceforge.net/. 11 programs, please see <http://usbip.sourceforge.net/>.
12 12
13 To compile this as a module, choose M here: the module will 13 To compile this as a module, choose M here: the module will
14 be called usbip-core. 14 be called usbip-core.
diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index ee36415eb26d..67556acd1514 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -67,9 +67,9 @@ static ssize_t show_status(struct device *dev, struct device_attribute *attr,
67 return -ENODEV; 67 return -ENODEV;
68 } 68 }
69 69
70 spin_lock(&sdev->ud.lock); 70 spin_lock_irq(&sdev->ud.lock);
71 status = sdev->ud.status; 71 status = sdev->ud.status;
72 spin_unlock(&sdev->ud.lock); 72 spin_unlock_irq(&sdev->ud.lock);
73 73
74 return snprintf(buf, PAGE_SIZE, "%d\n", status); 74 return snprintf(buf, PAGE_SIZE, "%d\n", status);
75} 75}
@@ -97,39 +97,39 @@ static ssize_t store_sockfd(struct device *dev, struct device_attribute *attr,
97 if (sockfd != -1) { 97 if (sockfd != -1) {
98 dev_info(dev, "stub up\n"); 98 dev_info(dev, "stub up\n");
99 99
100 spin_lock(&sdev->ud.lock); 100 spin_lock_irq(&sdev->ud.lock);
101 101
102 if (sdev->ud.status != SDEV_ST_AVAILABLE) { 102 if (sdev->ud.status != SDEV_ST_AVAILABLE) {
103 dev_err(dev, "not ready\n"); 103 dev_err(dev, "not ready\n");
104 spin_unlock(&sdev->ud.lock); 104 spin_unlock_irq(&sdev->ud.lock);
105 return -EINVAL; 105 return -EINVAL;
106 } 106 }
107 107
108 socket = sockfd_to_socket(sockfd); 108 socket = sockfd_to_socket(sockfd);
109 if (!socket) { 109 if (!socket) {
110 spin_unlock(&sdev->ud.lock); 110 spin_unlock_irq(&sdev->ud.lock);
111 return -EINVAL; 111 return -EINVAL;
112 } 112 }
113 sdev->ud.tcp_socket = socket; 113 sdev->ud.tcp_socket = socket;
114 114
115 spin_unlock(&sdev->ud.lock); 115 spin_unlock_irq(&sdev->ud.lock);
116 116
117 sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud, "stub_rx"); 117 sdev->ud.tcp_rx = kthread_get_run(stub_rx_loop, &sdev->ud, "stub_rx");
118 sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud, "stub_tx"); 118 sdev->ud.tcp_tx = kthread_get_run(stub_tx_loop, &sdev->ud, "stub_tx");
119 119
120 spin_lock(&sdev->ud.lock); 120 spin_lock_irq(&sdev->ud.lock);
121 sdev->ud.status = SDEV_ST_USED; 121 sdev->ud.status = SDEV_ST_USED;
122 spin_unlock(&sdev->ud.lock); 122 spin_unlock_irq(&sdev->ud.lock);
123 123
124 } else { 124 } else {
125 dev_info(dev, "stub down\n"); 125 dev_info(dev, "stub down\n");
126 126
127 spin_lock(&sdev->ud.lock); 127 spin_lock_irq(&sdev->ud.lock);
128 if (sdev->ud.status != SDEV_ST_USED) { 128 if (sdev->ud.status != SDEV_ST_USED) {
129 spin_unlock(&sdev->ud.lock); 129 spin_unlock_irq(&sdev->ud.lock);
130 return -EINVAL; 130 return -EINVAL;
131 } 131 }
132 spin_unlock(&sdev->ud.lock); 132 spin_unlock_irq(&sdev->ud.lock);
133 133
134 usbip_event_add(&sdev->ud, SDEV_EVENT_DOWN); 134 usbip_event_add(&sdev->ud, SDEV_EVENT_DOWN);
135 } 135 }
@@ -241,9 +241,9 @@ static void stub_device_reset(struct usbip_device *ud)
241 ret = usb_lock_device_for_reset(udev, sdev->interface); 241 ret = usb_lock_device_for_reset(udev, sdev->interface);
242 if (ret < 0) { 242 if (ret < 0) {
243 dev_err(&udev->dev, "lock for reset\n"); 243 dev_err(&udev->dev, "lock for reset\n");
244 spin_lock(&ud->lock); 244 spin_lock_irq(&ud->lock);
245 ud->status = SDEV_ST_ERROR; 245 ud->status = SDEV_ST_ERROR;
246 spin_unlock(&ud->lock); 246 spin_unlock_irq(&ud->lock);
247 return; 247 return;
248 } 248 }
249 249
@@ -251,7 +251,7 @@ static void stub_device_reset(struct usbip_device *ud)
251 ret = usb_reset_device(udev); 251 ret = usb_reset_device(udev);
252 usb_unlock_device(udev); 252 usb_unlock_device(udev);
253 253
254 spin_lock(&ud->lock); 254 spin_lock_irq(&ud->lock);
255 if (ret) { 255 if (ret) {
256 dev_err(&udev->dev, "device reset\n"); 256 dev_err(&udev->dev, "device reset\n");
257 ud->status = SDEV_ST_ERROR; 257 ud->status = SDEV_ST_ERROR;
@@ -259,14 +259,14 @@ static void stub_device_reset(struct usbip_device *ud)
259 dev_info(&udev->dev, "device reset\n"); 259 dev_info(&udev->dev, "device reset\n");
260 ud->status = SDEV_ST_AVAILABLE; 260 ud->status = SDEV_ST_AVAILABLE;
261 } 261 }
262 spin_unlock(&ud->lock); 262 spin_unlock_irq(&ud->lock);
263} 263}
264 264
265static void stub_device_unusable(struct usbip_device *ud) 265static void stub_device_unusable(struct usbip_device *ud)
266{ 266{
267 spin_lock(&ud->lock); 267 spin_lock_irq(&ud->lock);
268 ud->status = SDEV_ST_ERROR; 268 ud->status = SDEV_ST_ERROR;
269 spin_unlock(&ud->lock); 269 spin_unlock_irq(&ud->lock);
270} 270}
271 271
272/** 272/**
@@ -286,10 +286,8 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev,
286 286
287 /* yes, it's a new device */ 287 /* yes, it's a new device */
288 sdev = kzalloc(sizeof(struct stub_device), GFP_KERNEL); 288 sdev = kzalloc(sizeof(struct stub_device), GFP_KERNEL);
289 if (!sdev) { 289 if (!sdev)
290 dev_err(&interface->dev, "no memory for stub_device\n");
291 return NULL; 290 return NULL;
292 }
293 291
294 sdev->interface = usb_get_intf(interface); 292 sdev->interface = usb_get_intf(interface);
295 sdev->udev = usb_get_dev(udev); 293 sdev->udev = usb_get_dev(udev);
@@ -528,13 +526,13 @@ static void stub_disconnect(struct usb_interface *interface)
528 * when the device is being reset 526 * when the device is being reset
529 */ 527 */
530 528
531int stub_pre_reset(struct usb_interface *interface) 529static int stub_pre_reset(struct usb_interface *interface)
532{ 530{
533 dev_dbg(&interface->dev, "pre_reset\n"); 531 dev_dbg(&interface->dev, "pre_reset\n");
534 return 0; 532 return 0;
535} 533}
536 534
537int stub_post_reset(struct usb_interface *interface) 535static int stub_post_reset(struct usb_interface *interface)
538{ 536{
539 dev_dbg(&interface->dev, "post_reset\n"); 537 dev_dbg(&interface->dev, "post_reset\n");
540 return 0; 538 return 0;
diff --git a/drivers/staging/usbip/stub_rx.c b/drivers/staging/usbip/stub_rx.c
index 0572a15242b5..715e8a79fb4e 100644
--- a/drivers/staging/usbip/stub_rx.c
+++ b/drivers/staging/usbip/stub_rx.c
@@ -307,12 +307,12 @@ static int valid_request(struct stub_device *sdev, struct usbip_header *pdu)
307 int valid = 0; 307 int valid = 0;
308 308
309 if (pdu->base.devid == sdev->devid) { 309 if (pdu->base.devid == sdev->devid) {
310 spin_lock(&ud->lock); 310 spin_lock_irq(&ud->lock);
311 if (ud->status == SDEV_ST_USED) { 311 if (ud->status == SDEV_ST_USED) {
312 /* A request is valid. */ 312 /* A request is valid. */
313 valid = 1; 313 valid = 1;
314 } 314 }
315 spin_unlock(&ud->lock); 315 spin_unlock_irq(&ud->lock);
316 } 316 }
317 317
318 return valid; 318 return valid;
@@ -485,7 +485,6 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
485 kzalloc(pdu->u.cmd_submit.transfer_buffer_length, 485 kzalloc(pdu->u.cmd_submit.transfer_buffer_length,
486 GFP_KERNEL); 486 GFP_KERNEL);
487 if (!priv->urb->transfer_buffer) { 487 if (!priv->urb->transfer_buffer) {
488 dev_err(&sdev->interface->dev, "malloc x_buff\n");
489 usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC); 488 usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
490 return; 489 return;
491 } 490 }
diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c
index 513961fef055..cd5326ae38cc 100644
--- a/drivers/staging/usbip/stub_tx.c
+++ b/drivers/staging/usbip/stub_tx.c
@@ -42,7 +42,6 @@ void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum,
42 42
43 unlink = kzalloc(sizeof(struct stub_unlink), GFP_ATOMIC); 43 unlink = kzalloc(sizeof(struct stub_unlink), GFP_ATOMIC);
44 if (!unlink) { 44 if (!unlink) {
45 dev_err(&sdev->interface->dev, "alloc stub_unlink\n");
46 usbip_event_add(&sdev->ud, VDEV_EVENT_ERROR_MALLOC); 45 usbip_event_add(&sdev->ud, VDEV_EVENT_ERROR_MALLOC);
47 return; 46 return;
48 } 47 }
diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c
index 75189feac380..75aa5bfcb8dd 100644
--- a/drivers/staging/usbip/usbip_common.c
+++ b/drivers/staging/usbip/usbip_common.c
@@ -672,9 +672,8 @@ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb)
672 return 0; 672 return 0;
673 673
674 /* my Bluetooth dongle gets ISO URBs which are np = 0 */ 674 /* my Bluetooth dongle gets ISO URBs which are np = 0 */
675 if (np == 0) { 675 if (np == 0)
676 return 0; 676 return 0;
677 }
678 677
679 buff = kzalloc(size, GFP_KERNEL); 678 buff = kzalloc(size, GFP_KERNEL);
680 if (!buff) 679 if (!buff)
diff --git a/drivers/staging/usbip/usbip_event.c b/drivers/staging/usbip/usbip_event.c
index d332a34ddb6d..82123be8732d 100644
--- a/drivers/staging/usbip/usbip_event.c
+++ b/drivers/staging/usbip/usbip_event.c
@@ -105,10 +105,12 @@ EXPORT_SYMBOL_GPL(usbip_stop_eh);
105 105
106void usbip_event_add(struct usbip_device *ud, unsigned long event) 106void usbip_event_add(struct usbip_device *ud, unsigned long event)
107{ 107{
108 spin_lock(&ud->lock); 108 unsigned long flags;
109
110 spin_lock_irqsave(&ud->lock, flags);
109 ud->event |= event; 111 ud->event |= event;
110 wake_up(&ud->eh_waitq); 112 wake_up(&ud->eh_waitq);
111 spin_unlock(&ud->lock); 113 spin_unlock_irqrestore(&ud->lock, flags);
112} 114}
113EXPORT_SYMBOL_GPL(usbip_event_add); 115EXPORT_SYMBOL_GPL(usbip_event_add);
114 116
diff --git a/drivers/staging/usbip/userspace/.gitignore b/drivers/staging/usbip/userspace/.gitignore
new file mode 100644
index 000000000000..9aad9e30a8ba
--- /dev/null
+++ b/drivers/staging/usbip/userspace/.gitignore
@@ -0,0 +1,28 @@
1Makefile
2Makefile.in
3aclocal.m4
4autom4te.cache/
5config.guess
6config.h
7config.h.in
8config.log
9config.status
10config.sub
11configure
12depcomp
13install-sh
14libsrc/Makefile
15libsrc/Makefile.in
16libtool
17ltmain.sh
18missing
19src/Makefile
20src/Makefile.in
21stamp-h1
22libsrc/libusbip.la
23libsrc/libusbip_la-names.lo
24libsrc/libusbip_la-usbip_common.lo
25libsrc/libusbip_la-usbip_host_driver.lo
26libsrc/libusbip_la-vhci_driver.lo
27src/usbip
28src/usbipd
diff --git a/drivers/staging/usbip/userspace/Makefile.am b/drivers/staging/usbip/userspace/Makefile.am
index 9ab19499fe00..66f8bf038c9f 100644
--- a/drivers/staging/usbip/userspace/Makefile.am
+++ b/drivers/staging/usbip/userspace/Makefile.am
@@ -3,4 +3,4 @@ includedir = @includedir@/usbip
3include_HEADERS := $(addprefix libsrc/, \ 3include_HEADERS := $(addprefix libsrc/, \
4 usbip_common.h vhci_driver.h usbip_host_driver.h) 4 usbip_common.h vhci_driver.h usbip_host_driver.h)
5 5
6dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbip_bind_driver.8) 6dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8)
diff --git a/drivers/staging/usbip/userspace/README b/drivers/staging/usbip/userspace/README
index 63cd10719059..233d1d7aef92 100644
--- a/drivers/staging/usbip/userspace/README
+++ b/drivers/staging/usbip/userspace/README
@@ -17,8 +17,6 @@
17 17
18 - gcc >= 4.0 18 - gcc >= 4.0
19 19
20 - libglib2.0-dev >= 2.6.0
21
22 - libtool, automake >= 1.9, autoconf >= 2.5.0, pkg-config 20 - libtool, automake >= 1.9, autoconf >= 2.5.0, pkg-config
23 21
24 22
diff --git a/drivers/staging/usbip/userspace/configure.ac b/drivers/staging/usbip/userspace/configure.ac
index 43e641e5ac06..2be4060f9036 100644
--- a/drivers/staging/usbip/userspace/configure.ac
+++ b/drivers/staging/usbip/userspace/configure.ac
@@ -91,10 +91,22 @@ AC_ARG_WITH([usbids-dir],
91 [USBIDS_DIR=$withval], [USBIDS_DIR="/usr/share/hwdata/"]) 91 [USBIDS_DIR=$withval], [USBIDS_DIR="/usr/share/hwdata/"])
92AC_SUBST([USBIDS_DIR]) 92AC_SUBST([USBIDS_DIR])
93 93
94GLIB2_REQUIRED=2.6.0 94# use _FORTIFY_SOURCE
95PKG_CHECK_MODULES([PACKAGE], [glib-2.0 >= $GLIB2_REQUIRED]) 95AC_MSG_CHECKING([whether to use fortify])
96AC_SUBST([PACKAGE_CFLAGS]) 96AC_ARG_WITH([fortify],
97AC_SUBST([PACKAGE_LIBS]) 97 [AS_HELP_STRING([--with-fortify],
98 [use _FORTIFY_SROUCE option when compiling)])],
99 dnl [ACTION-IF-GIVEN]
100 [if test "$withval" = "yes"; then
101 AC_MSG_RESULT([yes])
102 CFLAGS="$CFLAGS -D_FORTIFY_SOURCE -O"
103 else
104 AC_MSG_RESULT([no])
105 CFLAGS="$CFLAGS -U_FORTIFY_SOURCE"
106 fi
107 ],
108 dnl [ACTION-IF-NOT-GIVEN]
109 [AC_MSG_RESULT([default])])
98 110
99AC_CONFIG_FILES([Makefile libsrc/Makefile src/Makefile]) 111AC_CONFIG_FILES([Makefile libsrc/Makefile src/Makefile])
100AC_OUTPUT 112AC_OUTPUT
diff --git a/drivers/staging/usbip/userspace/src/Makefile.am b/drivers/staging/usbip/userspace/src/Makefile.am
index c365a3fada90..a11300361392 100644
--- a/drivers/staging/usbip/userspace/src/Makefile.am
+++ b/drivers/staging/usbip/userspace/src/Makefile.am
@@ -1,6 +1,6 @@
1AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' 1AM_CPPFLAGS = -I$(top_srcdir)/libsrc -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
2AM_CFLAGS = @EXTRA_CFLAGS@ @PACKAGE_CFLAGS@ 2AM_CFLAGS = @EXTRA_CFLAGS@
3LDADD = $(top_builddir)/libsrc/libusbip.la @PACKAGE_LIBS@ 3LDADD = $(top_builddir)/libsrc/libusbip.la
4 4
5sbin_PROGRAMS := usbip usbipd 5sbin_PROGRAMS := usbip usbipd
6 6
diff --git a/drivers/staging/usbip/userspace/src/usbip_attach.c b/drivers/staging/usbip/userspace/src/usbip_attach.c
index bdf61c0fe699..2da4e44e1633 100644
--- a/drivers/staging/usbip/userspace/src/usbip_attach.c
+++ b/drivers/staging/usbip/userspace/src/usbip_attach.c
@@ -27,6 +27,7 @@
27#include <fcntl.h> 27#include <fcntl.h>
28#include <getopt.h> 28#include <getopt.h>
29#include <unistd.h> 29#include <unistd.h>
30#include <errno.h>
30 31
31#include "vhci_driver.h" 32#include "vhci_driver.h"
32#include "usbip_common.h" 33#include "usbip_common.h"
@@ -52,8 +53,18 @@ static int record_connection(char *host, char *port, char *busid, int rhport)
52 int ret; 53 int ret;
53 54
54 ret = mkdir(VHCI_STATE_PATH, 0700); 55 ret = mkdir(VHCI_STATE_PATH, 0700);
55 if (ret < 0) 56 if (ret < 0) {
56 return -1; 57 /* if VHCI_STATE_PATH exists, then it better be a directory */
58 if (errno == EEXIST) {
59 struct stat s;
60 ret = stat(VHCI_STATE_PATH, &s);
61 if (ret < 0)
62 return -1;
63 if (!(s.st_mode & S_IFDIR))
64 return -1;
65 } else
66 return -1;
67 }
57 68
58 snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport); 69 snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport);
59 70
diff --git a/drivers/staging/usbip/userspace/src/usbipd.c b/drivers/staging/usbip/userspace/src/usbipd.c
index 8668a8092d4d..34760cc1d10e 100644
--- a/drivers/staging/usbip/userspace/src/usbipd.c
+++ b/drivers/staging/usbip/userspace/src/usbipd.c
@@ -20,6 +20,7 @@
20#include "../config.h" 20#include "../config.h"
21#endif 21#endif
22 22
23#define _GNU_SOURCE
23#include <errno.h> 24#include <errno.h>
24#include <unistd.h> 25#include <unistd.h>
25#include <netdb.h> 26#include <netdb.h>
@@ -35,10 +36,9 @@
35#include <tcpd.h> 36#include <tcpd.h>
36#endif 37#endif
37 38
38#define _GNU_SOURCE
39#include <getopt.h> 39#include <getopt.h>
40#include <glib.h>
41#include <signal.h> 40#include <signal.h>
41#include <poll.h>
42 42
43#include "usbip_host_driver.h" 43#include "usbip_host_driver.h"
44#include "usbip_common.h" 44#include "usbip_common.h"
@@ -48,7 +48,7 @@
48#define PROGNAME "usbipd" 48#define PROGNAME "usbipd"
49#define MAXSOCKFD 20 49#define MAXSOCKFD 20
50 50
51GMainLoop *main_loop; 51#define MAIN_LOOP_TIMEOUT 10
52 52
53static const char usbip_version_string[] = PACKAGE_STRING; 53static const char usbip_version_string[] = PACKAGE_STRING;
54 54
@@ -310,30 +310,22 @@ static int do_accept(int listenfd)
310 return connfd; 310 return connfd;
311} 311}
312 312
313gboolean process_request(GIOChannel *gio, GIOCondition condition, 313int process_request(int listenfd)
314 gpointer unused_data)
315{ 314{
316 int listenfd; 315 pid_t childpid;
317 int connfd; 316 int connfd;
318 317
319 (void) unused_data; 318 connfd = do_accept(listenfd);
320 319 if (connfd < 0)
321 if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL)) { 320 return -1;
322 err("unknown condition"); 321 childpid = fork();
323 BUG(); 322 if (childpid == 0) {
324 } 323 close(listenfd);
325
326 if (condition & G_IO_IN) {
327 listenfd = g_io_channel_unix_get_fd(gio);
328 connfd = do_accept(listenfd);
329 if (connfd < 0)
330 return TRUE;
331
332 recv_pdu(connfd); 324 recv_pdu(connfd);
333 close(connfd); 325 exit(0);
334 } 326 }
335 327 close(connfd);
336 return TRUE; 328 return 0;
337} 329}
338 330
339static void log_addrinfo(struct addrinfo *ai) 331static void log_addrinfo(struct addrinfo *ai)
@@ -418,10 +410,7 @@ static struct addrinfo *do_getaddrinfo(char *host, int ai_family)
418 410
419static void signal_handler(int i) 411static void signal_handler(int i)
420{ 412{
421 dbg("received signal: code %d", i); 413 dbg("received '%s' signal", strsignal(i));
422
423 if (main_loop)
424 g_main_loop_quit(main_loop);
425} 414}
426 415
427static void set_signal(void) 416static void set_signal(void)
@@ -433,14 +422,19 @@ static void set_signal(void)
433 sigemptyset(&act.sa_mask); 422 sigemptyset(&act.sa_mask);
434 sigaction(SIGTERM, &act, NULL); 423 sigaction(SIGTERM, &act, NULL);
435 sigaction(SIGINT, &act, NULL); 424 sigaction(SIGINT, &act, NULL);
425 act.sa_handler = SIG_IGN;
426 sigaction(SIGCLD, &act, NULL);
436} 427}
437 428
438static int do_standalone_mode(gboolean daemonize) 429static int do_standalone_mode(int daemonize)
439{ 430{
440 struct addrinfo *ai_head; 431 struct addrinfo *ai_head;
441 int sockfdlist[MAXSOCKFD]; 432 int sockfdlist[MAXSOCKFD];
442 int nsockfd; 433 int nsockfd;
443 int i; 434 int i, terminate;
435 struct pollfd *fds;
436 struct timespec timeout;
437 sigset_t sigmask;
444 438
445 if (usbip_names_init(USBIDS_FILE)) 439 if (usbip_names_init(USBIDS_FILE))
446 err("failed to open %s", USBIDS_FILE); 440 err("failed to open %s", USBIDS_FILE);
@@ -456,7 +450,7 @@ static int do_standalone_mode(gboolean daemonize)
456 err("daemonizing failed: %s", strerror(errno)); 450 err("daemonizing failed: %s", strerror(errno));
457 return -1; 451 return -1;
458 } 452 }
459 453 umask(0);
460 usbip_use_syslog = 1; 454 usbip_use_syslog = 1;
461 } 455 }
462 set_signal(); 456 set_signal();
@@ -472,20 +466,40 @@ static int do_standalone_mode(gboolean daemonize)
472 err("failed to open a listening socket"); 466 err("failed to open a listening socket");
473 return -1; 467 return -1;
474 } 468 }
475 469 fds = calloc(nsockfd, sizeof(struct pollfd));
476 for (i = 0; i < nsockfd; i++) { 470 for (i = 0; i < nsockfd; i++) {
477 GIOChannel *gio; 471 fds[i].fd = sockfdlist[i];
478 472 fds[i].events = POLLIN;
479 gio = g_io_channel_unix_new(sockfdlist[i]); 473 }
480 g_io_add_watch(gio, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL), 474 timeout.tv_sec = MAIN_LOOP_TIMEOUT;
481 process_request, NULL); 475 timeout.tv_nsec = 0;
476
477 sigfillset(&sigmask);
478 sigdelset(&sigmask, SIGTERM);
479 sigdelset(&sigmask, SIGINT);
480
481 terminate = 0;
482 while (!terminate) {
483 int r;
484
485 r = ppoll(fds, nsockfd, &timeout, &sigmask);
486 if (r < 0) {
487 dbg("%s", strerror(errno));
488 terminate = 1;
489 } else if (r) {
490 for (i = 0; i < nsockfd; i++) {
491 if (fds[i].revents & POLLIN) {
492 dbg("read event on fd[%d]=%d",
493 i, sockfdlist[i]);
494 process_request(sockfdlist[i]);
495 }
496 }
497 } else
498 dbg("heartbeat timeout on ppoll()");
482 } 499 }
483
484 main_loop = g_main_loop_new(FALSE, FALSE);
485 g_main_loop_run(main_loop);
486 500
487 info("shutting down " PROGNAME); 501 info("shutting down " PROGNAME);
488 502 free(fds);
489 freeaddrinfo(ai_head); 503 freeaddrinfo(ai_head);
490 usbip_host_driver_close(); 504 usbip_host_driver_close();
491 usbip_names_free(); 505 usbip_names_free();
@@ -509,7 +523,7 @@ int main(int argc, char *argv[])
509 cmd_version 523 cmd_version
510 } cmd; 524 } cmd;
511 525
512 gboolean daemonize = FALSE; 526 int daemonize = 0;
513 int opt, rc = -1; 527 int opt, rc = -1;
514 528
515 usbip_use_stderr = 1; 529 usbip_use_stderr = 1;
@@ -527,7 +541,7 @@ int main(int argc, char *argv[])
527 541
528 switch (opt) { 542 switch (opt) {
529 case 'D': 543 case 'D':
530 daemonize = TRUE; 544 daemonize = 1;
531 break; 545 break;
532 case 'd': 546 case 'd':
533 usbip_use_debug = 1; 547 usbip_use_debug = 1;
diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index c3aa2195f1a8..f1ca08478da8 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -121,11 +121,9 @@ static void dump_port_status_diff(u32 prev_status, u32 new_status)
121 121
122void rh_port_connect(int rhport, enum usb_device_speed speed) 122void rh_port_connect(int rhport, enum usb_device_speed speed)
123{ 123{
124 unsigned long flags;
125
126 usbip_dbg_vhci_rh("rh_port_connect %d\n", rhport); 124 usbip_dbg_vhci_rh("rh_port_connect %d\n", rhport);
127 125
128 spin_lock_irqsave(&the_controller->lock, flags); 126 spin_lock(&the_controller->lock);
129 127
130 the_controller->port_status[rhport] |= USB_PORT_STAT_CONNECTION 128 the_controller->port_status[rhport] |= USB_PORT_STAT_CONNECTION
131 | (1 << USB_PORT_FEAT_C_CONNECTION); 129 | (1 << USB_PORT_FEAT_C_CONNECTION);
@@ -141,24 +139,22 @@ void rh_port_connect(int rhport, enum usb_device_speed speed)
141 break; 139 break;
142 } 140 }
143 141
144 spin_unlock_irqrestore(&the_controller->lock, flags); 142 spin_unlock(&the_controller->lock);
145 143
146 usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); 144 usb_hcd_poll_rh_status(vhci_to_hcd(the_controller));
147} 145}
148 146
149static void rh_port_disconnect(int rhport) 147static void rh_port_disconnect(int rhport)
150{ 148{
151 unsigned long flags;
152
153 usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport); 149 usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport);
154 150
155 spin_lock_irqsave(&the_controller->lock, flags); 151 spin_lock(&the_controller->lock);
156 152
157 the_controller->port_status[rhport] &= ~USB_PORT_STAT_CONNECTION; 153 the_controller->port_status[rhport] &= ~USB_PORT_STAT_CONNECTION;
158 the_controller->port_status[rhport] |= 154 the_controller->port_status[rhport] |=
159 (1 << USB_PORT_FEAT_C_CONNECTION); 155 (1 << USB_PORT_FEAT_C_CONNECTION);
160 156
161 spin_unlock_irqrestore(&the_controller->lock, flags); 157 spin_unlock(&the_controller->lock);
162 usb_hcd_poll_rh_status(vhci_to_hcd(the_controller)); 158 usb_hcd_poll_rh_status(vhci_to_hcd(the_controller));
163} 159}
164 160
@@ -183,7 +179,6 @@ static void rh_port_disconnect(int rhport)
183static int vhci_hub_status(struct usb_hcd *hcd, char *buf) 179static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
184{ 180{
185 struct vhci_hcd *vhci; 181 struct vhci_hcd *vhci;
186 unsigned long flags;
187 int retval; 182 int retval;
188 int rhport; 183 int rhport;
189 int changed = 0; 184 int changed = 0;
@@ -193,7 +188,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
193 188
194 vhci = hcd_to_vhci(hcd); 189 vhci = hcd_to_vhci(hcd);
195 190
196 spin_lock_irqsave(&vhci->lock, flags); 191 spin_lock(&vhci->lock);
197 if (!HCD_HW_ACCESSIBLE(hcd)) { 192 if (!HCD_HW_ACCESSIBLE(hcd)) {
198 usbip_dbg_vhci_rh("hw accessible flag not on?\n"); 193 usbip_dbg_vhci_rh("hw accessible flag not on?\n");
199 goto done; 194 goto done;
@@ -216,7 +211,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
216 usb_hcd_resume_root_hub(hcd); 211 usb_hcd_resume_root_hub(hcd);
217 212
218done: 213done:
219 spin_unlock_irqrestore(&vhci->lock, flags); 214 spin_unlock(&vhci->lock);
220 return changed ? retval : 0; 215 return changed ? retval : 0;
221} 216}
222 217
@@ -237,7 +232,6 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
237{ 232{
238 struct vhci_hcd *dum; 233 struct vhci_hcd *dum;
239 int retval = 0; 234 int retval = 0;
240 unsigned long flags;
241 int rhport; 235 int rhport;
242 236
243 u32 prev_port_status[VHCI_NPORTS]; 237 u32 prev_port_status[VHCI_NPORTS];
@@ -257,7 +251,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
257 251
258 dum = hcd_to_vhci(hcd); 252 dum = hcd_to_vhci(hcd);
259 253
260 spin_lock_irqsave(&dum->lock, flags); 254 spin_lock(&dum->lock);
261 255
262 /* store old status and compare now and old later */ 256 /* store old status and compare now and old later */
263 if (usbip_dbg_flag_vhci_rh) { 257 if (usbip_dbg_flag_vhci_rh) {
@@ -410,7 +404,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
410 } 404 }
411 usbip_dbg_vhci_rh(" bye\n"); 405 usbip_dbg_vhci_rh(" bye\n");
412 406
413 spin_unlock_irqrestore(&dum->lock, flags); 407 spin_unlock(&dum->lock);
414 408
415 return retval; 409 return retval;
416} 410}
@@ -433,7 +427,6 @@ static void vhci_tx_urb(struct urb *urb)
433{ 427{
434 struct vhci_device *vdev = get_vdev(urb->dev); 428 struct vhci_device *vdev = get_vdev(urb->dev);
435 struct vhci_priv *priv; 429 struct vhci_priv *priv;
436 unsigned long flag;
437 430
438 if (!vdev) { 431 if (!vdev) {
439 pr_err("could not get virtual device"); 432 pr_err("could not get virtual device");
@@ -441,16 +434,13 @@ static void vhci_tx_urb(struct urb *urb)
441 } 434 }
442 435
443 priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC); 436 priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC);
444
445 spin_lock_irqsave(&vdev->priv_lock, flag);
446
447 if (!priv) { 437 if (!priv) {
448 dev_err(&urb->dev->dev, "malloc vhci_priv\n");
449 spin_unlock_irqrestore(&vdev->priv_lock, flag);
450 usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); 438 usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);
451 return; 439 return;
452 } 440 }
453 441
442 spin_lock(&vdev->priv_lock);
443
454 priv->seqnum = atomic_inc_return(&the_controller->seqnum); 444 priv->seqnum = atomic_inc_return(&the_controller->seqnum);
455 if (priv->seqnum == 0xffff) 445 if (priv->seqnum == 0xffff)
456 dev_info(&urb->dev->dev, "seqnum max\n"); 446 dev_info(&urb->dev->dev, "seqnum max\n");
@@ -463,7 +453,7 @@ static void vhci_tx_urb(struct urb *urb)
463 list_add_tail(&priv->list, &vdev->priv_tx); 453 list_add_tail(&priv->list, &vdev->priv_tx);
464 454
465 wake_up(&vdev->waitq_tx); 455 wake_up(&vdev->waitq_tx);
466 spin_unlock_irqrestore(&vdev->priv_lock, flag); 456 spin_unlock(&vdev->priv_lock);
467} 457}
468 458
469static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, 459static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
@@ -471,7 +461,6 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
471{ 461{
472 struct device *dev = &urb->dev->dev; 462 struct device *dev = &urb->dev->dev;
473 int ret = 0; 463 int ret = 0;
474 unsigned long flags;
475 struct vhci_device *vdev; 464 struct vhci_device *vdev;
476 465
477 usbip_dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n", 466 usbip_dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n",
@@ -480,11 +469,11 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
480 /* patch to usb_sg_init() is in 2.5.60 */ 469 /* patch to usb_sg_init() is in 2.5.60 */
481 BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length); 470 BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length);
482 471
483 spin_lock_irqsave(&the_controller->lock, flags); 472 spin_lock(&the_controller->lock);
484 473
485 if (urb->status != -EINPROGRESS) { 474 if (urb->status != -EINPROGRESS) {
486 dev_err(dev, "URB already unlinked!, status %d\n", urb->status); 475 dev_err(dev, "URB already unlinked!, status %d\n", urb->status);
487 spin_unlock_irqrestore(&the_controller->lock, flags); 476 spin_unlock(&the_controller->lock);
488 return urb->status; 477 return urb->status;
489 } 478 }
490 479
@@ -496,7 +485,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
496 vdev->ud.status == VDEV_ST_ERROR) { 485 vdev->ud.status == VDEV_ST_ERROR) {
497 dev_err(dev, "enqueue for inactive port %d\n", vdev->rhport); 486 dev_err(dev, "enqueue for inactive port %d\n", vdev->rhport);
498 spin_unlock(&vdev->ud.lock); 487 spin_unlock(&vdev->ud.lock);
499 spin_unlock_irqrestore(&the_controller->lock, flags); 488 spin_unlock(&the_controller->lock);
500 return -ENODEV; 489 return -ENODEV;
501 } 490 }
502 spin_unlock(&vdev->ud.lock); 491 spin_unlock(&vdev->ud.lock);
@@ -571,14 +560,14 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
571 560
572out: 561out:
573 vhci_tx_urb(urb); 562 vhci_tx_urb(urb);
574 spin_unlock_irqrestore(&the_controller->lock, flags); 563 spin_unlock(&the_controller->lock);
575 564
576 return 0; 565 return 0;
577 566
578no_need_xmit: 567no_need_xmit:
579 usb_hcd_unlink_urb_from_ep(hcd, urb); 568 usb_hcd_unlink_urb_from_ep(hcd, urb);
580no_need_unlink: 569no_need_unlink:
581 spin_unlock_irqrestore(&the_controller->lock, flags); 570 spin_unlock(&the_controller->lock);
582 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); 571 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status);
583 return ret; 572 return ret;
584} 573}
@@ -631,19 +620,18 @@ no_need_unlink:
631 */ 620 */
632static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 621static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
633{ 622{
634 unsigned long flags;
635 struct vhci_priv *priv; 623 struct vhci_priv *priv;
636 struct vhci_device *vdev; 624 struct vhci_device *vdev;
637 625
638 pr_info("dequeue a urb %p\n", urb); 626 pr_info("dequeue a urb %p\n", urb);
639 627
640 spin_lock_irqsave(&the_controller->lock, flags); 628 spin_lock(&the_controller->lock);
641 629
642 priv = urb->hcpriv; 630 priv = urb->hcpriv;
643 if (!priv) { 631 if (!priv) {
644 /* URB was never linked! or will be soon given back by 632 /* URB was never linked! or will be soon given back by
645 * vhci_rx. */ 633 * vhci_rx. */
646 spin_unlock_irqrestore(&the_controller->lock, flags); 634 spin_unlock(&the_controller->lock);
647 return 0; 635 return 0;
648 } 636 }
649 637
@@ -651,7 +639,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
651 int ret = 0; 639 int ret = 0;
652 ret = usb_hcd_check_unlink_urb(hcd, urb, status); 640 ret = usb_hcd_check_unlink_urb(hcd, urb, status);
653 if (ret) { 641 if (ret) {
654 spin_unlock_irqrestore(&the_controller->lock, flags); 642 spin_unlock(&the_controller->lock);
655 return ret; 643 return ret;
656 } 644 }
657 } 645 }
@@ -661,16 +649,14 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
661 649
662 if (!vdev->ud.tcp_socket) { 650 if (!vdev->ud.tcp_socket) {
663 /* tcp connection is closed */ 651 /* tcp connection is closed */
664 unsigned long flags2; 652 spin_lock(&vdev->priv_lock);
665
666 spin_lock_irqsave(&vdev->priv_lock, flags2);
667 653
668 pr_info("device %p seems to be disconnected\n", vdev); 654 pr_info("device %p seems to be disconnected\n", vdev);
669 list_del(&priv->list); 655 list_del(&priv->list);
670 kfree(priv); 656 kfree(priv);
671 urb->hcpriv = NULL; 657 urb->hcpriv = NULL;
672 658
673 spin_unlock_irqrestore(&vdev->priv_lock, flags2); 659 spin_unlock(&vdev->priv_lock);
674 660
675 /* 661 /*
676 * If tcp connection is alive, we have sent CMD_UNLINK. 662 * If tcp connection is alive, we have sent CMD_UNLINK.
@@ -681,24 +667,22 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
681 667
682 usb_hcd_unlink_urb_from_ep(hcd, urb); 668 usb_hcd_unlink_urb_from_ep(hcd, urb);
683 669
684 spin_unlock_irqrestore(&the_controller->lock, flags); 670 spin_unlock(&the_controller->lock);
685 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, 671 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
686 urb->status); 672 urb->status);
687 spin_lock_irqsave(&the_controller->lock, flags); 673 spin_lock(&the_controller->lock);
688 674
689 } else { 675 } else {
690 /* tcp connection is alive */ 676 /* tcp connection is alive */
691 unsigned long flags2;
692 struct vhci_unlink *unlink; 677 struct vhci_unlink *unlink;
693 678
694 spin_lock_irqsave(&vdev->priv_lock, flags2); 679 spin_lock(&vdev->priv_lock);
695 680
696 /* setup CMD_UNLINK pdu */ 681 /* setup CMD_UNLINK pdu */
697 unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC); 682 unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC);
698 if (!unlink) { 683 if (!unlink) {
699 pr_err("malloc vhci_unlink\n"); 684 spin_unlock(&vdev->priv_lock);
700 spin_unlock_irqrestore(&vdev->priv_lock, flags2); 685 spin_unlock(&the_controller->lock);
701 spin_unlock_irqrestore(&the_controller->lock, flags);
702 usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); 686 usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);
703 return -ENOMEM; 687 return -ENOMEM;
704 } 688 }
@@ -716,10 +700,10 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
716 list_add_tail(&unlink->list, &vdev->unlink_tx); 700 list_add_tail(&unlink->list, &vdev->unlink_tx);
717 wake_up(&vdev->waitq_tx); 701 wake_up(&vdev->waitq_tx);
718 702
719 spin_unlock_irqrestore(&vdev->priv_lock, flags2); 703 spin_unlock(&vdev->priv_lock);
720 } 704 }
721 705
722 spin_unlock_irqrestore(&the_controller->lock, flags); 706 spin_unlock(&the_controller->lock);
723 707
724 usbip_dbg_vhci_hc("leave\n"); 708 usbip_dbg_vhci_hc("leave\n");
725 return 0; 709 return 0;
@@ -957,9 +941,9 @@ static int vhci_bus_suspend(struct usb_hcd *hcd)
957 941
958 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); 942 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
959 943
960 spin_lock_irq(&vhci->lock); 944 spin_lock(&vhci->lock);
961 hcd->state = HC_STATE_SUSPENDED; 945 hcd->state = HC_STATE_SUSPENDED;
962 spin_unlock_irq(&vhci->lock); 946 spin_unlock(&vhci->lock);
963 947
964 return 0; 948 return 0;
965} 949}
@@ -971,13 +955,13 @@ static int vhci_bus_resume(struct usb_hcd *hcd)
971 955
972 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); 956 dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
973 957
974 spin_lock_irq(&vhci->lock); 958 spin_lock(&vhci->lock);
975 if (!HCD_HW_ACCESSIBLE(hcd)) { 959 if (!HCD_HW_ACCESSIBLE(hcd)) {
976 rc = -ESHUTDOWN; 960 rc = -ESHUTDOWN;
977 } else { 961 } else {
978 hcd->state = HC_STATE_RUNNING; 962 hcd->state = HC_STATE_RUNNING;
979 } 963 }
980 spin_unlock_irq(&vhci->lock); 964 spin_unlock(&vhci->lock);
981 965
982 return rc; 966 return rc;
983} 967}
diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
index ba5f1c079b69..faf8e607c5c6 100644
--- a/drivers/staging/usbip/vhci_rx.c
+++ b/drivers/staging/usbip/vhci_rx.c
@@ -68,7 +68,6 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
68{ 68{
69 struct usbip_device *ud = &vdev->ud; 69 struct usbip_device *ud = &vdev->ud;
70 struct urb *urb; 70 struct urb *urb;
71 unsigned long flags;
72 71
73 spin_lock(&vdev->priv_lock); 72 spin_lock(&vdev->priv_lock);
74 urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum); 73 urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum);
@@ -101,9 +100,9 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
101 100
102 usbip_dbg_vhci_rx("now giveback urb %p\n", urb); 101 usbip_dbg_vhci_rx("now giveback urb %p\n", urb);
103 102
104 spin_lock_irqsave(&the_controller->lock, flags); 103 spin_lock(&the_controller->lock);
105 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 104 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
106 spin_unlock_irqrestore(&the_controller->lock, flags); 105 spin_unlock(&the_controller->lock);
107 106
108 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); 107 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status);
109 108
@@ -141,7 +140,6 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
141{ 140{
142 struct vhci_unlink *unlink; 141 struct vhci_unlink *unlink;
143 struct urb *urb; 142 struct urb *urb;
144 unsigned long flags;
145 143
146 usbip_dump_header(pdu); 144 usbip_dump_header(pdu);
147 145
@@ -171,9 +169,9 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
171 urb->status = pdu->u.ret_unlink.status; 169 urb->status = pdu->u.ret_unlink.status;
172 pr_info("urb->status %d\n", urb->status); 170 pr_info("urb->status %d\n", urb->status);
173 171
174 spin_lock_irqsave(&the_controller->lock, flags); 172 spin_lock(&the_controller->lock);
175 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 173 usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
176 spin_unlock_irqrestore(&the_controller->lock, flags); 174 spin_unlock(&the_controller->lock);
177 175
178 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, 176 usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
179 urb->status); 177 urb->status);
diff --git a/drivers/staging/usbip/vhci_tx.c b/drivers/staging/usbip/vhci_tx.c
index b1f0dcd68f55..409fd99f3257 100644
--- a/drivers/staging/usbip/vhci_tx.c
+++ b/drivers/staging/usbip/vhci_tx.c
@@ -46,18 +46,17 @@ static void setup_cmd_submit_pdu(struct usbip_header *pdup, struct urb *urb)
46 46
47static struct vhci_priv *dequeue_from_priv_tx(struct vhci_device *vdev) 47static struct vhci_priv *dequeue_from_priv_tx(struct vhci_device *vdev)
48{ 48{
49 unsigned long flags;
50 struct vhci_priv *priv, *tmp; 49 struct vhci_priv *priv, *tmp;
51 50
52 spin_lock_irqsave(&vdev->priv_lock, flags); 51 spin_lock(&vdev->priv_lock);
53 52
54 list_for_each_entry_safe(priv, tmp, &vdev->priv_tx, list) { 53 list_for_each_entry_safe(priv, tmp, &vdev->priv_tx, list) {
55 list_move_tail(&priv->list, &vdev->priv_rx); 54 list_move_tail(&priv->list, &vdev->priv_rx);
56 spin_unlock_irqrestore(&vdev->priv_lock, flags); 55 spin_unlock(&vdev->priv_lock);
57 return priv; 56 return priv;
58 } 57 }
59 58
60 spin_unlock_irqrestore(&vdev->priv_lock, flags); 59 spin_unlock(&vdev->priv_lock);
61 60
62 return NULL; 61 return NULL;
63} 62}
@@ -136,18 +135,17 @@ static int vhci_send_cmd_submit(struct vhci_device *vdev)
136 135
137static struct vhci_unlink *dequeue_from_unlink_tx(struct vhci_device *vdev) 136static struct vhci_unlink *dequeue_from_unlink_tx(struct vhci_device *vdev)
138{ 137{
139 unsigned long flags;
140 struct vhci_unlink *unlink, *tmp; 138 struct vhci_unlink *unlink, *tmp;
141 139
142 spin_lock_irqsave(&vdev->priv_lock, flags); 140 spin_lock(&vdev->priv_lock);
143 141
144 list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { 142 list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) {
145 list_move_tail(&unlink->list, &vdev->unlink_rx); 143 list_move_tail(&unlink->list, &vdev->unlink_rx);
146 spin_unlock_irqrestore(&vdev->priv_lock, flags); 144 spin_unlock(&vdev->priv_lock);
147 return unlink; 145 return unlink;
148 } 146 }
149 147
150 spin_unlock_irqrestore(&vdev->priv_lock, flags); 148 spin_unlock(&vdev->priv_lock);
151 149
152 return NULL; 150 return NULL;
153} 151}
diff --git a/drivers/staging/vme/devices/Kconfig b/drivers/staging/vme/devices/Kconfig
index d0cab1766190..8e8bbb1dcd9b 100644
--- a/drivers/staging/vme/devices/Kconfig
+++ b/drivers/staging/vme/devices/Kconfig
@@ -6,7 +6,7 @@ config VME_USER
6 help 6 help
7 If you say Y here you want to be able to access a limited number of 7 If you say Y here you want to be able to access a limited number of
8 VME windows in a manner at least semi-compatible with the interface 8 VME windows in a manner at least semi-compatible with the interface
9 provided with the original driver at http://vmelinux.org/. 9 provided with the original driver at <http://www.vmelinux.org/>.
10 10
11config VME_PIO2 11config VME_PIO2
12 tristate "GE PIO2 VME" 12 tristate "GE PIO2 VME"
diff --git a/drivers/staging/vme/devices/vme_pio2_core.c b/drivers/staging/vme/devices/vme_pio2_core.c
index bf73ba26e88a..fd19c257f533 100644
--- a/drivers/staging/vme/devices/vme_pio2_core.c
+++ b/drivers/staging/vme/devices/vme_pio2_core.c
@@ -222,7 +222,6 @@ static int pio2_probe(struct vme_dev *vdev)
222 222
223 card = kzalloc(sizeof(struct pio2_card), GFP_KERNEL); 223 card = kzalloc(sizeof(struct pio2_card), GFP_KERNEL);
224 if (card == NULL) { 224 if (card == NULL) {
225 dev_err(&vdev->dev, "Unable to allocate card structure\n");
226 retval = -ENOMEM; 225 retval = -ENOMEM;
227 goto err_struct; 226 goto err_struct;
228 } 227 }
diff --git a/drivers/staging/vme/devices/vme_pio2_gpio.c b/drivers/staging/vme/devices/vme_pio2_gpio.c
index 69d880517e07..2a2d920d980b 100644
--- a/drivers/staging/vme/devices/vme_pio2_gpio.c
+++ b/drivers/staging/vme/devices/vme_pio2_gpio.c
@@ -192,10 +192,8 @@ int pio2_gpio_init(struct pio2_card *card)
192 char *label; 192 char *label;
193 193
194 label = kmalloc(PIO2_NUM_CHANNELS, GFP_KERNEL); 194 label = kmalloc(PIO2_NUM_CHANNELS, GFP_KERNEL);
195 if (label == NULL) { 195 if (label == NULL)
196 dev_err(&card->vdev->dev, "Unable to allocate GPIO label\n");
197 return -ENOMEM; 196 return -ENOMEM;
198 }
199 197
200 sprintf(label, "%s@%s", driver_name, dev_name(&card->vdev->dev)); 198 sprintf(label, "%s@%s", driver_name, dev_name(&card->vdev->dev));
201 card->gc.label = label; 199 card->gc.label = label;
diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
index 4ef852c4c4e1..57474cff51f0 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -761,8 +761,6 @@ static int vme_user_probe(struct vme_dev *vdev)
761 image[i].size_buf = PCI_BUF_SIZE; 761 image[i].size_buf = PCI_BUF_SIZE;
762 image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL); 762 image[i].kern_buf = kmalloc(image[i].size_buf, GFP_KERNEL);
763 if (image[i].kern_buf == NULL) { 763 if (image[i].kern_buf == NULL) {
764 dev_warn(&vdev->dev,
765 "Unable to allocate memory for master window buffers\n");
766 err = -ENOMEM; 764 err = -ENOMEM;
767 goto err_master_buf; 765 goto err_master_buf;
768 } 766 }
diff --git a/drivers/staging/vt6655/channel.c b/drivers/staging/vt6655/channel.c
index 47c156bb70a9..aa76e39a46f4 100644
--- a/drivers/staging/vt6655/channel.c
+++ b/drivers/staging/vt6655/channel.c
@@ -749,9 +749,9 @@ bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
749 unsigned char *pbyChannelNumber, unsigned char *pbyMap) 749 unsigned char *pbyChannelNumber, unsigned char *pbyMap)
750{ 750{
751 751
752 if (uChannelIndex > CB_MAX_CHANNEL) { 752 if (uChannelIndex > CB_MAX_CHANNEL)
753 return false; 753 return false;
754 } 754
755 *pbyChannelNumber = sChannelTbl[uChannelIndex].byChannelNumber; 755 *pbyChannelNumber = sChannelTbl[uChannelIndex].byChannelNumber;
756 *pbyMap = sChannelTbl[uChannelIndex].byMAP; 756 *pbyMap = sChannelTbl[uChannelIndex].byMAP;
757 return sChannelTbl[uChannelIndex].bValid; 757 return sChannelTbl[uChannelIndex].bValid;
@@ -761,9 +761,9 @@ void set_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
761 unsigned char byMap) 761 unsigned char byMap)
762{ 762{
763 763
764 if (uChannelIndex > CB_MAX_CHANNEL) { 764 if (uChannelIndex > CB_MAX_CHANNEL)
765 return; 765 return;
766 } 766
767 sChannelTbl[uChannelIndex].byMAP |= byMap; 767 sChannelTbl[uChannelIndex].byMAP |= byMap;
768} 768}
769 769
@@ -771,9 +771,8 @@ void clear_channel_map_info(void *pDeviceHandler)
771{ 771{
772 unsigned int ii = 0; 772 unsigned int ii = 0;
773 773
774 for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) { 774 for (ii = 1; ii <= CB_MAX_CHANNEL; ii++)
775 sChannelTbl[ii].byMAP = 0; 775 sChannelTbl[ii].byMAP = 0;
776 }
777} 776}
778 777
779unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType) 778unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h
index e54e00bc5665..e27244ce383e 100644
--- a/drivers/staging/vt6655/device.h
+++ b/drivers/staging/vt6655/device.h
@@ -881,26 +881,14 @@ inline static bool device_get_ip(PSDevice pInfo) {
881 881
882 882
883 883
884static inline PDEVICE_RD_INFO alloc_rd_info(void) { 884static inline PDEVICE_RD_INFO alloc_rd_info(void)
885 PDEVICE_RD_INFO ptr; 885{
886 ptr = (PDEVICE_RD_INFO)kmalloc((int)sizeof(DEVICE_RD_INFO), (int)GFP_ATOMIC); 886 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
887 if (ptr == NULL)
888 return NULL;
889 else {
890 memset(ptr,0,sizeof(DEVICE_RD_INFO));
891 return ptr;
892 }
893} 887}
894 888
895static inline PDEVICE_TD_INFO alloc_td_info(void) { 889static inline PDEVICE_TD_INFO alloc_td_info(void)
896 PDEVICE_TD_INFO ptr; 890{
897 ptr = (PDEVICE_TD_INFO)kmalloc((int)sizeof(DEVICE_TD_INFO), (int)GFP_ATOMIC); 891 return kzalloc(sizeof(DEVICE_TD_INFO), GFP_ATOMIC);
898 if (ptr == NULL)
899 return NULL;
900 else {
901 memset(ptr,0,sizeof(DEVICE_TD_INFO));
902 return ptr;
903 }
904} 892}
905 893
906/*--------------------- Export Functions --------------------------*/ 894/*--------------------- Export Functions --------------------------*/
diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 875ee4442386..d66854f5b304 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -2421,7 +2421,7 @@ CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2421 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10)); 2421 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
2422 2422
2423 // Notes: 2423 // Notes:
2424 // Although spec says MMPDU can be fragmented; In most case, 2424 // Although spec says MMPDU can be fragmented; In most cases,
2425 // no one will send a MMPDU under fragmentation. With RTS may occur. 2425 // no one will send a MMPDU under fragmentation. With RTS may occur.
2426 pDevice->bAES = false; //Set FRAGCTL_WEPTYP 2426 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2427 2427
@@ -2510,7 +2510,7 @@ CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2510 pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen); 2510 pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2511 2511
2512 //Fill TXKEY 2512 //Fill TXKEY
2513 //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet. 2513 //Kyle: Need fix: TKIP and AES did't encrypt Mnt Packet.
2514 //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL); 2514 //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL);
2515 2515
2516 //Fill IV(ExtIV,RSNHDR) 2516 //Fill IV(ExtIV,RSNHDR)
@@ -2957,7 +2957,7 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, unsigned char *pbMPDU, un
2957 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10); 2957 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10);
2958 2958
2959 // Notes: 2959 // Notes:
2960 // Although spec says MMPDU can be fragmented; In most casses, 2960 // Although spec says MMPDU can be fragmented; In most cases,
2961 // no one will send a MMPDU under fragmentation. With RTS may occur. 2961 // no one will send a MMPDU under fragmentation. With RTS may occur.
2962 pDevice->bAES = false; //Set FRAGCTL_WEPTYP 2962 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2963 2963
diff --git a/drivers/staging/vt6655/wcmd.c b/drivers/staging/vt6655/wcmd.c
index 6d0b87a14267..101c7359f414 100644
--- a/drivers/staging/vt6655/wcmd.c
+++ b/drivers/staging/vt6655/wcmd.c
@@ -720,7 +720,7 @@ printk("chester-abyDesireSSID=%s\n",((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySS
720 pDevice->nTxDataTimeCout = 0; 720 pDevice->nTxDataTimeCout = 0;
721 } 721 }
722 else { 722 else {
723 // printk("mike:-->First time triger TimerTxData InSleep\n"); 723 // printk("mike:-->First time trigger TimerTxData InSleep\n");
724 } 724 }
725 pDevice->IsTxDataTrigger = true; 725 pDevice->IsTxDataTrigger = true;
726 add_timer(&pDevice->sTimerTxData); 726 add_timer(&pDevice->sTimerTxData);
diff --git a/drivers/staging/vt6655/wmgr.c b/drivers/staging/vt6655/wmgr.c
index b6f99ecbbeb5..b08a611a184a 100644
--- a/drivers/staging/vt6655/wmgr.c
+++ b/drivers/staging/vt6655/wmgr.c
@@ -2068,7 +2068,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
2068 2068
2069 if (pBSSList != NULL) { 2069 if (pBSSList != NULL) {
2070 2070
2071 // Compare PHY paramater setting 2071 // Compare PHY parameter setting
2072 if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) { 2072 if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) {
2073 bUpdatePhyParameter = true; 2073 bUpdatePhyParameter = true;
2074 pMgmt->wCurrCapInfo = pBSSList->wCapInfo; 2074 pMgmt->wCurrCapInfo = pBSSList->wCapInfo;
diff --git a/drivers/staging/vt6656/80211mgr.c b/drivers/staging/vt6656/80211mgr.c
index e6ced95e6fa7..534d490539b6 100644
--- a/drivers/staging/vt6656/80211mgr.c
+++ b/drivers/staging/vt6656/80211mgr.c
@@ -96,9 +96,10 @@ vMgrEncodeBeacon(
96{ 96{
97 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; 97 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
98 98
99 /* Fixed Fields */ 99 /* Fixed Fields */
100 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 100 pFrame->pqwTimestamp =
101 + WLAN_BEACON_OFF_TS); 101 (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
102 WLAN_BEACON_OFF_TS);
102 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 103 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
103 + WLAN_BEACON_OFF_BCN_INT); 104 + WLAN_BEACON_OFF_BCN_INT);
104 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 105 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
@@ -130,9 +131,10 @@ vMgrDecodeBeacon(
130 131
131 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; 132 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
132 133
133 /* Fixed Fields */ 134 /* Fixed Fields */
134 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 135 pFrame->pqwTimestamp =
135 + WLAN_BEACON_OFF_TS); 136 (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
137 WLAN_BEACON_OFF_TS);
136 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 138 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
137 + WLAN_BEACON_OFF_BCN_INT); 139 + WLAN_BEACON_OFF_BCN_INT);
138 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 140 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
@@ -178,7 +180,7 @@ vMgrDecodeBeacon(
178 break; 180 break;
179 case WLAN_EID_RSN_WPA: 181 case WLAN_EID_RSN_WPA:
180 if (pFrame->pRSNWPA == NULL) { 182 if (pFrame->pRSNWPA == NULL) {
181 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) 183 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
182 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; 184 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
183 } 185 }
184 break; 186 break;
@@ -391,7 +393,7 @@ vMgrDecodeAssocRequest(
391 break; 393 break;
392 case WLAN_EID_RSN_WPA: 394 case WLAN_EID_RSN_WPA:
393 if (pFrame->pRSNWPA == NULL) { 395 if (pFrame->pRSNWPA == NULL) {
394 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) 396 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
395 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; 397 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
396 } 398 }
397 break; 399 break;
@@ -561,7 +563,7 @@ vMgrDecodeReassocRequest(
561 break; 563 break;
562 case WLAN_EID_RSN_WPA: 564 case WLAN_EID_RSN_WPA:
563 if (pFrame->pRSNWPA == NULL) 565 if (pFrame->pRSNWPA == NULL)
564 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) 566 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
565 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; 567 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
566 break; 568 break;
567 569
@@ -671,9 +673,10 @@ vMgrEncodeProbeResponse(
671{ 673{
672 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; 674 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
673 675
674 /* Fixed Fields */ 676 /* Fixed Fields */
675 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 677 pFrame->pqwTimestamp =
676 + WLAN_PROBERESP_OFF_TS); 678 (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
679 WLAN_PROBERESP_OFF_TS);
677 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 680 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
678 + WLAN_PROBERESP_OFF_BCN_INT); 681 + WLAN_PROBERESP_OFF_BCN_INT);
679 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 682 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
@@ -706,9 +709,10 @@ vMgrDecodeProbeResponse(
706 709
707 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf; 710 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
708 711
709 /* Fixed Fields */ 712 /* Fixed Fields */
710 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 713 pFrame->pqwTimestamp =
711 + WLAN_PROBERESP_OFF_TS); 714 (u64 *)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
715 WLAN_PROBERESP_OFF_TS);
712 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 716 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
713 + WLAN_PROBERESP_OFF_BCN_INT); 717 + WLAN_PROBERESP_OFF_BCN_INT);
714 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) 718 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
@@ -749,7 +753,7 @@ vMgrDecodeProbeResponse(
749 break; 753 break;
750 case WLAN_EID_RSN_WPA: 754 case WLAN_EID_RSN_WPA:
751 if (pFrame->pRSNWPA == NULL) { 755 if (pFrame->pRSNWPA == NULL) {
752 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE) 756 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
753 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem; 757 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
754 } 758 }
755 break; 759 break;
diff --git a/drivers/staging/vt6656/80211mgr.h b/drivers/staging/vt6656/80211mgr.h
index e5db73be0e71..f8e16d8989ea 100644
--- a/drivers/staging/vt6656/80211mgr.h
+++ b/drivers/staging/vt6656/80211mgr.h
@@ -38,7 +38,7 @@
38 38
39#define WLAN_MIN_ARRAY 1 39#define WLAN_MIN_ARRAY 1
40 40
41// Information Element ID value 41/* Information Element ID value */
42#define WLAN_EID_SSID 0 42#define WLAN_EID_SSID 0
43#define WLAN_EID_SUPP_RATES 1 43#define WLAN_EID_SUPP_RATES 1
44#define WLAN_EID_FH_PARMS 2 44#define WLAN_EID_FH_PARMS 2
@@ -59,10 +59,10 @@
59#define WLAN_EID_QUIET 40 59#define WLAN_EID_QUIET 40
60#define WLAN_EID_IBSS_DFS 41 60#define WLAN_EID_IBSS_DFS 41
61#define WLAN_EID_ERP 42 61#define WLAN_EID_ERP 42
62// reference 802.11i 7.3.2 table 20 62/* reference 802.11i 7.3.2 table 20 */
63#define WLAN_EID_RSN 48 63#define WLAN_EID_RSN 48
64#define WLAN_EID_EXTSUPP_RATES 50 64#define WLAN_EID_EXTSUPP_RATES 50
65// reference WiFi WPA spec. 65/* reference WiFi WPA spec */
66#define WLAN_EID_RSN_WPA 221 66#define WLAN_EID_RSN_WPA 221
67 67
68#ifdef Cisco_ccx 68#ifdef Cisco_ccx
@@ -75,7 +75,7 @@
75#define WLAN_EID_ERP_USE_PROTECTION 0x02 75#define WLAN_EID_ERP_USE_PROTECTION 0x02
76#define WLAN_EID_ERP_BARKER_MODE 0x04 76#define WLAN_EID_ERP_BARKER_MODE 0x04
77 77
78// Reason Codes 78/* reason codes */
79#define WLAN_MGMT_REASON_RSVD 0 79#define WLAN_MGMT_REASON_RSVD 0
80#define WLAN_MGMT_REASON_UNSPEC 1 80#define WLAN_MGMT_REASON_UNSPEC 1
81#define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2 81#define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2
@@ -100,7 +100,7 @@
100#define WLAN_MGMT_REASON_RSNE_CAP_INVALID 22 100#define WLAN_MGMT_REASON_RSNE_CAP_INVALID 22
101#define WLAN_MGMT_REASON_80211X_AUTH_FAILED 23 101#define WLAN_MGMT_REASON_80211X_AUTH_FAILED 23
102 102
103// Status Codes 103/* status codes */
104#define WLAN_MGMT_STATUS_SUCCESS 0 104#define WLAN_MGMT_STATUS_SUCCESS 0
105#define WLAN_MGMT_STATUS_UNSPEC_FAILURE 1 105#define WLAN_MGMT_STATUS_UNSPEC_FAILURE 1
106#define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED 10 106#define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED 10
@@ -116,19 +116,16 @@
116#define WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC 20 116#define WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC 20
117#define WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY 21 117#define WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY 21
118 118
119// reference 802.11h 7.3.1.9 119/* reference 802.11h 7.3.1.9 */
120//
121#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SPECTRUM_MNG 22 120#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SPECTRUM_MNG 22
122#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_PWR_CAP 23 121#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_PWR_CAP 23
123#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SUPP_CH 24 122#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SUPP_CH 24
124// 123
125// reference 802.11g 7.3.1.9 124/* reference 802.11g 7.3.1.9 */
126//
127#define WLAN_MGMT_STATUS_SHORTSLOTTIME_UNSUPPORTED 25 125#define WLAN_MGMT_STATUS_SHORTSLOTTIME_UNSUPPORTED 25
128#define WLAN_MGMT_STATUS_DSSSOFDM_UNSUPPORTED 26 126#define WLAN_MGMT_STATUS_DSSSOFDM_UNSUPPORTED 26
129// 127
130// reference 802.11i 7.3.1.9 table 19 128/* reference 802.11i 7.3.1.9 table 19 */
131//
132#define WLAN_MGMT_STATUS_INVALID_IE 40 129#define WLAN_MGMT_STATUS_INVALID_IE 40
133#define WLAN_MGMT_STATUS_GROUP_CIPHER_INVALID 41 130#define WLAN_MGMT_STATUS_GROUP_CIPHER_INVALID 41
134#define WLAN_MGMT_STATUS_PAIRWISE_CIPHER_INVALID 42 131#define WLAN_MGMT_STATUS_PAIRWISE_CIPHER_INVALID 42
@@ -137,17 +134,16 @@
137#define WLAN_MGMT_STATUS_INVALID_RSN_IE_CAP 45 134#define WLAN_MGMT_STATUS_INVALID_RSN_IE_CAP 45
138#define WLAN_MGMT_STATUS_CIPHER_REJECT 46 135#define WLAN_MGMT_STATUS_CIPHER_REJECT 46
139 136
140 137/* auth algorithm */
141
142// Auth Algorithm
143#define WLAN_AUTH_ALG_OPENSYSTEM 0 138#define WLAN_AUTH_ALG_OPENSYSTEM 0
144#define WLAN_AUTH_ALG_SHAREDKEY 1 139#define WLAN_AUTH_ALG_SHAREDKEY 1
145 140
141/* management frame field offsets */
146 142
147 143/*
148// Management Frame Field Offsets 144 * Note: Not all fields are listed because of variable lengths
149// Note: Not all fields are listed because of variable lengths. 145 * Note: These offsets are from the start of the frame data
150// Note: These offsets are from the start of the frame data 146 */
151 147
152#define WLAN_BEACON_OFF_TS 0 148#define WLAN_BEACON_OFF_TS 0
153#define WLAN_BEACON_OFF_BCN_INT 8 149#define WLAN_BEACON_OFF_BCN_INT 8
@@ -189,10 +185,7 @@
189 185
190#define WLAN_DEAUTHEN_OFF_REASON 0 186#define WLAN_DEAUTHEN_OFF_REASON 0
191 187
192 188/* cipher suite selectors defined in 802.11i */
193//
194// Cipher Suite Selectors defined in 802.11i
195//
196#define WLAN_11i_CSS_USE_GROUP 0 189#define WLAN_11i_CSS_USE_GROUP 0
197#define WLAN_11i_CSS_WEP40 1 190#define WLAN_11i_CSS_WEP40 1
198#define WLAN_11i_CSS_TKIP 2 191#define WLAN_11i_CSS_TKIP 2
@@ -200,24 +193,22 @@
200#define WLAN_11i_CSS_WEP104 5 193#define WLAN_11i_CSS_WEP104 5
201#define WLAN_11i_CSS_UNKNOWN 255 194#define WLAN_11i_CSS_UNKNOWN 255
202 195
203// 196/* authentication and key management suite selectors defined in 802.11i */
204// Authentication and Key Management Suite Selectors defined in 802.11i
205//
206#define WLAN_11i_AKMSS_802_1X 1 197#define WLAN_11i_AKMSS_802_1X 1
207#define WLAN_11i_AKMSS_PSK 2 198#define WLAN_11i_AKMSS_PSK 2
208#define WLAN_11i_AKMSS_UNKNOWN 255 199#define WLAN_11i_AKMSS_UNKNOWN 255
209 200
210// Measurement type definitions reference ieee 802.11h Table 20b 201/* measurement type definitions reference IEEE 802.11h table 20b */
211#define MEASURE_TYPE_BASIC 0 202#define MEASURE_TYPE_BASIC 0
212#define MEASURE_TYPE_CCA 1 203#define MEASURE_TYPE_CCA 1
213#define MEASURE_TYPE_RPI 2 204#define MEASURE_TYPE_RPI 2
214 205
215// Measurement request mode definitions reference ieee 802.11h Figure 46h 206/* measurement request mode definitions reference IEEE 802.11h figure 46h */
216#define MEASURE_MODE_ENABLE 0x02 207#define MEASURE_MODE_ENABLE 0x02
217#define MEASURE_MODE_REQ 0x04 208#define MEASURE_MODE_REQ 0x04
218#define MEASURE_MODE_REP 0x08 209#define MEASURE_MODE_REP 0x08
219 210
220// Measurement report mode definitions reference ieee 802.11h Figure 46m 211/* measurement report mode definitions reference IEEE 802.11h figure 46m */
221#define MEASURE_MODE_LATE 0x01 212#define MEASURE_MODE_LATE 0x01
222#define MEASURE_MODE_INCAPABLE 0x02 213#define MEASURE_MODE_INCAPABLE 0x02
223#define MEASURE_MODE_REFUSED 0x04 214#define MEASURE_MODE_REFUSED 0x04
@@ -228,7 +219,7 @@
228 219
229/*--------------------- Export Types ------------------------------*/ 220/*--------------------- Export Types ------------------------------*/
230 221
231// Information Element Types 222/* Information Element types */
232 223
233#pragma pack(1) 224#pragma pack(1)
234typedef struct tagWLAN_IE { 225typedef struct tagWLAN_IE {
@@ -237,7 +228,7 @@ typedef struct tagWLAN_IE {
237} __attribute__ ((__packed__)) 228} __attribute__ ((__packed__))
238WLAN_IE, *PWLAN_IE; 229WLAN_IE, *PWLAN_IE;
239 230
240// Service Set Identity (SSID) 231/* Service Set IDentity (SSID) */
241#pragma pack(1) 232#pragma pack(1)
242typedef struct tagWLAN_IE_SSID { 233typedef struct tagWLAN_IE_SSID {
243 BYTE byElementID; 234 BYTE byElementID;
@@ -246,7 +237,7 @@ typedef struct tagWLAN_IE_SSID {
246} __attribute__ ((__packed__)) 237} __attribute__ ((__packed__))
247WLAN_IE_SSID, *PWLAN_IE_SSID; 238WLAN_IE_SSID, *PWLAN_IE_SSID;
248 239
249// Supported Rates 240/* Supported Rates */
250#pragma pack(1) 241#pragma pack(1)
251typedef struct tagWLAN_IE_SUPP_RATES { 242typedef struct tagWLAN_IE_SUPP_RATES {
252 BYTE byElementID; 243 BYTE byElementID;
@@ -255,7 +246,7 @@ typedef struct tagWLAN_IE_SUPP_RATES {
255} __attribute__ ((__packed__)) 246} __attribute__ ((__packed__))
256WLAN_IE_SUPP_RATES, *PWLAN_IE_SUPP_RATES; 247WLAN_IE_SUPP_RATES, *PWLAN_IE_SUPP_RATES;
257 248
258// FH Parameter Set 249/* FH Parameter Set */
259#pragma pack(1) 250#pragma pack(1)
260typedef struct _WLAN_IE_FH_PARMS { 251typedef struct _WLAN_IE_FH_PARMS {
261 BYTE byElementID; 252 BYTE byElementID;
@@ -266,7 +257,7 @@ typedef struct _WLAN_IE_FH_PARMS {
266 BYTE byHopIndex; 257 BYTE byHopIndex;
267} WLAN_IE_FH_PARMS, *PWLAN_IE_FH_PARMS; 258} WLAN_IE_FH_PARMS, *PWLAN_IE_FH_PARMS;
268 259
269// DS Parameter Set 260/* DS Parameter Set */
270#pragma pack(1) 261#pragma pack(1)
271typedef struct tagWLAN_IE_DS_PARMS { 262typedef struct tagWLAN_IE_DS_PARMS {
272 BYTE byElementID; 263 BYTE byElementID;
@@ -275,7 +266,7 @@ typedef struct tagWLAN_IE_DS_PARMS {
275} __attribute__ ((__packed__)) 266} __attribute__ ((__packed__))
276WLAN_IE_DS_PARMS, *PWLAN_IE_DS_PARMS; 267WLAN_IE_DS_PARMS, *PWLAN_IE_DS_PARMS;
277 268
278// CF Parameter Set 269/* CF Parameter Set */
279#pragma pack(1) 270#pragma pack(1)
280typedef struct tagWLAN_IE_CF_PARMS { 271typedef struct tagWLAN_IE_CF_PARMS {
281 BYTE byElementID; 272 BYTE byElementID;
@@ -287,7 +278,7 @@ typedef struct tagWLAN_IE_CF_PARMS {
287} __attribute__ ((__packed__)) 278} __attribute__ ((__packed__))
288WLAN_IE_CF_PARMS, *PWLAN_IE_CF_PARMS; 279WLAN_IE_CF_PARMS, *PWLAN_IE_CF_PARMS;
289 280
290// TIM 281/* TIM */
291#pragma pack(1) 282#pragma pack(1)
292typedef struct tagWLAN_IE_TIM { 283typedef struct tagWLAN_IE_TIM {
293 BYTE byElementID; 284 BYTE byElementID;
@@ -299,7 +290,7 @@ typedef struct tagWLAN_IE_TIM {
299} __attribute__ ((__packed__)) 290} __attribute__ ((__packed__))
300WLAN_IE_TIM, *PWLAN_IE_TIM; 291WLAN_IE_TIM, *PWLAN_IE_TIM;
301 292
302// IBSS Parameter Set 293/* IBSS Parameter Set */
303#pragma pack(1) 294#pragma pack(1)
304typedef struct tagWLAN_IE_IBSS_PARMS { 295typedef struct tagWLAN_IE_IBSS_PARMS {
305 BYTE byElementID; 296 BYTE byElementID;
@@ -308,7 +299,7 @@ typedef struct tagWLAN_IE_IBSS_PARMS {
308} __attribute__ ((__packed__)) 299} __attribute__ ((__packed__))
309WLAN_IE_IBSS_PARMS, *PWLAN_IE_IBSS_PARMS; 300WLAN_IE_IBSS_PARMS, *PWLAN_IE_IBSS_PARMS;
310 301
311// Challenge Text 302/* Challenge Text */
312#pragma pack(1) 303#pragma pack(1)
313typedef struct tagWLAN_IE_CHALLENGE { 304typedef struct tagWLAN_IE_CHALLENGE {
314 BYTE byElementID; 305 BYTE byElementID;
@@ -325,10 +316,10 @@ typedef struct tagWLAN_IE_RSN_EXT {
325 WORD wVersion; 316 WORD wVersion;
326 BYTE abyMulticast[4]; 317 BYTE abyMulticast[4];
327 WORD wPKCount; 318 WORD wPKCount;
328 struct { 319 struct {
329 BYTE abyOUI[4]; 320 BYTE abyOUI[4];
330 } PKSList[1]; // the rest is variable so need to 321 } PKSList[1];
331 // overlay ieauth structure 322 /* the rest is variable so need to overlay ieauth structure */
332} WLAN_IE_RSN_EXT, *PWLAN_IE_RSN_EXT; 323} WLAN_IE_RSN_EXT, *PWLAN_IE_RSN_EXT;
333 324
334#pragma pack(1) 325#pragma pack(1)
@@ -339,7 +330,7 @@ typedef struct tagWLAN_IE_RSN_AUTH {
339 } AuthKSList[1]; 330 } AuthKSList[1];
340} WLAN_IE_RSN_AUTH, *PWLAN_IE_RSN_AUTH; 331} WLAN_IE_RSN_AUTH, *PWLAN_IE_RSN_AUTH;
341 332
342// RSN Identity 333/* RSN Identity */
343#pragma pack(1) 334#pragma pack(1)
344typedef struct tagWLAN_IE_RSN { 335typedef struct tagWLAN_IE_RSN {
345 BYTE byElementID; 336 BYTE byElementID;
@@ -348,8 +339,7 @@ typedef struct tagWLAN_IE_RSN {
348 BYTE abyRSN[WLAN_MIN_ARRAY]; 339 BYTE abyRSN[WLAN_MIN_ARRAY];
349} WLAN_IE_RSN, *PWLAN_IE_RSN; 340} WLAN_IE_RSN, *PWLAN_IE_RSN;
350 341
351 342/* CCX Identity DavidWang */
352// CCX Identity DavidWang
353#pragma pack(1) 343#pragma pack(1)
354typedef struct tagWLAN_IE_CCX { 344typedef struct tagWLAN_IE_CCX {
355BYTE byElementID; 345BYTE byElementID;
@@ -371,9 +361,7 @@ BYTE len;
371BYTE abyCCXVer[5]; 361BYTE abyCCXVer[5];
372} WLAN_IE_CCX_Ver, *PWLAN_IE_CCX_Ver; 362} WLAN_IE_CCX_Ver, *PWLAN_IE_CCX_Ver;
373 363
374 364/* ERP */
375
376// ERP
377#pragma pack(1) 365#pragma pack(1)
378typedef struct tagWLAN_IE_ERP { 366typedef struct tagWLAN_IE_ERP {
379 BYTE byElementID; 367 BYTE byElementID;
@@ -505,10 +493,9 @@ typedef struct _WLAN_IE_IBSS_DFS {
505 493
506#pragma pack() 494#pragma pack()
507 495
496/* frame types */
508 497
509 498/* prototype structure, all mgmt frame types will start with these members */
510// Frame Types
511// prototype structure, all mgmt frame types will start with these members
512typedef struct tagWLAN_FR_MGMT { 499typedef struct tagWLAN_FR_MGMT {
513 500
514 unsigned int uType; 501 unsigned int uType;
@@ -518,21 +505,21 @@ typedef struct tagWLAN_FR_MGMT {
518 505
519} WLAN_FR_MGMT, *PWLAN_FR_MGMT; 506} WLAN_FR_MGMT, *PWLAN_FR_MGMT;
520 507
521// Beacon frame 508/* beacon frame */
522typedef struct tagWLAN_FR_BEACON { 509typedef struct tagWLAN_FR_BEACON {
523 510
524 unsigned int uType; 511 unsigned int uType;
525 unsigned int len; 512 unsigned int len;
526 PBYTE pBuf; 513 PBYTE pBuf;
527 PUWLAN_80211HDR pHdr; 514 PUWLAN_80211HDR pHdr;
528 // fixed fields 515 /* fixed fields */
529 PQWORD pqwTimestamp; 516 u64 *pqwTimestamp;
530 PWORD pwBeaconInterval; 517 PWORD pwBeaconInterval;
531 PWORD pwCapInfo; 518 PWORD pwCapInfo;
532 /*-- info elements ----------*/ 519 /* info elements */
533 PWLAN_IE_SSID pSSID; 520 PWLAN_IE_SSID pSSID;
534 PWLAN_IE_SUPP_RATES pSuppRates; 521 PWLAN_IE_SUPP_RATES pSuppRates;
535// PWLAN_IE_FH_PARMS pFHParms; 522/* PWLAN_IE_FH_PARMS pFHParms; */
536 PWLAN_IE_DS_PARMS pDSParms; 523 PWLAN_IE_DS_PARMS pDSParms;
537 PWLAN_IE_CF_PARMS pCFParms; 524 PWLAN_IE_CF_PARMS pCFParms;
538 PWLAN_IE_TIM pTIM; 525 PWLAN_IE_TIM pTIM;
@@ -549,8 +536,7 @@ typedef struct tagWLAN_FR_BEACON {
549 536
550} WLAN_FR_BEACON, *PWLAN_FR_BEACON; 537} WLAN_FR_BEACON, *PWLAN_FR_BEACON;
551 538
552 539/* IBSS ATIM frame */
553// IBSS ATIM frame
554typedef struct tagWLAN_FR_IBSSATIM { 540typedef struct tagWLAN_FR_IBSSATIM {
555 541
556 unsigned int uType; 542 unsigned int uType;
@@ -558,36 +544,36 @@ typedef struct tagWLAN_FR_IBSSATIM {
558 PBYTE pBuf; 544 PBYTE pBuf;
559 PUWLAN_80211HDR pHdr; 545 PUWLAN_80211HDR pHdr;
560 546
561 // fixed fields 547 /* fixed fields */
562 // info elements 548 /* info elements */
563 // this frame type has a null body 549 /* this frame type has a null body */
564 550
565} WLAN_FR_IBSSATIM, *PWLAN_FR_IBSSATIM; 551} WLAN_FR_IBSSATIM, *PWLAN_FR_IBSSATIM;
566 552
567// Disassociation 553/* disassociation */
568typedef struct tagWLAN_FR_DISASSOC { 554typedef struct tagWLAN_FR_DISASSOC {
569 555
570 unsigned int uType; 556 unsigned int uType;
571 unsigned int len; 557 unsigned int len;
572 PBYTE pBuf; 558 PBYTE pBuf;
573 PUWLAN_80211HDR pHdr; 559 PUWLAN_80211HDR pHdr;
574 /*-- fixed fields -----------*/ 560 /* fixed fields */
575 PWORD pwReason; 561 PWORD pwReason;
576 /*-- info elements ----------*/ 562 /* info elements */
577 563
578} WLAN_FR_DISASSOC, *PWLAN_FR_DISASSOC; 564} WLAN_FR_DISASSOC, *PWLAN_FR_DISASSOC;
579 565
580// Association Request 566/* association request */
581typedef struct tagWLAN_FR_ASSOCREQ { 567typedef struct tagWLAN_FR_ASSOCREQ {
582 568
583 unsigned int uType; 569 unsigned int uType;
584 unsigned int len; 570 unsigned int len;
585 PBYTE pBuf; 571 PBYTE pBuf;
586 PUWLAN_80211HDR pHdr; 572 PUWLAN_80211HDR pHdr;
587 /*-- fixed fields -----------*/ 573 /* fixed fields */
588 PWORD pwCapInfo; 574 PWORD pwCapInfo;
589 PWORD pwListenInterval; 575 PWORD pwListenInterval;
590 /*-- info elements ----------*/ 576 /* info elements */
591 PWLAN_IE_SSID pSSID; 577 PWLAN_IE_SSID pSSID;
592 PWLAN_IE_SUPP_RATES pSuppRates; 578 PWLAN_IE_SUPP_RATES pSuppRates;
593 PWLAN_IE_RSN pRSN; 579 PWLAN_IE_RSN pRSN;
@@ -601,24 +587,24 @@ typedef struct tagWLAN_FR_ASSOCREQ {
601 587
602} WLAN_FR_ASSOCREQ, *PWLAN_FR_ASSOCREQ; 588} WLAN_FR_ASSOCREQ, *PWLAN_FR_ASSOCREQ;
603 589
604// Association Response 590/* association response */
605typedef struct tagWLAN_FR_ASSOCRESP { 591typedef struct tagWLAN_FR_ASSOCRESP {
606 592
607 unsigned int uType; 593 unsigned int uType;
608 unsigned int len; 594 unsigned int len;
609 PBYTE pBuf; 595 PBYTE pBuf;
610 PUWLAN_80211HDR pHdr; 596 PUWLAN_80211HDR pHdr;
611 /*-- fixed fields -----------*/ 597 /* fixed fields */
612 PWORD pwCapInfo; 598 PWORD pwCapInfo;
613 PWORD pwStatus; 599 PWORD pwStatus;
614 PWORD pwAid; 600 PWORD pwAid;
615 /*-- info elements ----------*/ 601 /* info elements */
616 PWLAN_IE_SUPP_RATES pSuppRates; 602 PWLAN_IE_SUPP_RATES pSuppRates;
617 PWLAN_IE_SUPP_RATES pExtSuppRates; 603 PWLAN_IE_SUPP_RATES pExtSuppRates;
618 604
619} WLAN_FR_ASSOCRESP, *PWLAN_FR_ASSOCRESP; 605} WLAN_FR_ASSOCRESP, *PWLAN_FR_ASSOCRESP;
620 606
621// Reassociation Request 607/* reassociation request */
622typedef struct tagWLAN_FR_REASSOCREQ { 608typedef struct tagWLAN_FR_REASSOCREQ {
623 609
624 unsigned int uType; 610 unsigned int uType;
@@ -626,12 +612,12 @@ typedef struct tagWLAN_FR_REASSOCREQ {
626 PBYTE pBuf; 612 PBYTE pBuf;
627 PUWLAN_80211HDR pHdr; 613 PUWLAN_80211HDR pHdr;
628 614
629 /*-- fixed fields -----------*/ 615 /* fixed fields */
630 PWORD pwCapInfo; 616 PWORD pwCapInfo;
631 PWORD pwListenInterval; 617 PWORD pwListenInterval;
632 PIEEE_ADDR pAddrCurrAP; 618 PIEEE_ADDR pAddrCurrAP;
633 619
634 /*-- info elements ----------*/ 620 /* info elements */
635 PWLAN_IE_SSID pSSID; 621 PWLAN_IE_SSID pSSID;
636 PWLAN_IE_SUPP_RATES pSuppRates; 622 PWLAN_IE_SUPP_RATES pSuppRates;
637 PWLAN_IE_RSN pRSN; 623 PWLAN_IE_RSN pRSN;
@@ -643,50 +629,50 @@ typedef struct tagWLAN_FR_REASSOCREQ {
643 629
644} WLAN_FR_REASSOCREQ, *PWLAN_FR_REASSOCREQ; 630} WLAN_FR_REASSOCREQ, *PWLAN_FR_REASSOCREQ;
645 631
646// Reassociation Response 632/* reassociation response */
647typedef struct tagWLAN_FR_REASSOCRESP { 633typedef struct tagWLAN_FR_REASSOCRESP {
648 634
649 unsigned int uType; 635 unsigned int uType;
650 unsigned int len; 636 unsigned int len;
651 PBYTE pBuf; 637 PBYTE pBuf;
652 PUWLAN_80211HDR pHdr; 638 PUWLAN_80211HDR pHdr;
653 /*-- fixed fields -----------*/ 639 /* fixed fields */
654 PWORD pwCapInfo; 640 PWORD pwCapInfo;
655 PWORD pwStatus; 641 PWORD pwStatus;
656 PWORD pwAid; 642 PWORD pwAid;
657 /*-- info elements ----------*/ 643 /* info elements */
658 PWLAN_IE_SUPP_RATES pSuppRates; 644 PWLAN_IE_SUPP_RATES pSuppRates;
659 PWLAN_IE_SUPP_RATES pExtSuppRates; 645 PWLAN_IE_SUPP_RATES pExtSuppRates;
660 646
661} WLAN_FR_REASSOCRESP, *PWLAN_FR_REASSOCRESP; 647} WLAN_FR_REASSOCRESP, *PWLAN_FR_REASSOCRESP;
662 648
663// Probe Request 649/* probe request */
664typedef struct tagWLAN_FR_PROBEREQ { 650typedef struct tagWLAN_FR_PROBEREQ {
665 651
666 unsigned int uType; 652 unsigned int uType;
667 unsigned int len; 653 unsigned int len;
668 PBYTE pBuf; 654 PBYTE pBuf;
669 PUWLAN_80211HDR pHdr; 655 PUWLAN_80211HDR pHdr;
670 /*-- fixed fields -----------*/ 656 /* fixed fields */
671 /*-- info elements ----------*/ 657 /* info elements */
672 PWLAN_IE_SSID pSSID; 658 PWLAN_IE_SSID pSSID;
673 PWLAN_IE_SUPP_RATES pSuppRates; 659 PWLAN_IE_SUPP_RATES pSuppRates;
674 PWLAN_IE_SUPP_RATES pExtSuppRates; 660 PWLAN_IE_SUPP_RATES pExtSuppRates;
675 661
676} WLAN_FR_PROBEREQ, *PWLAN_FR_PROBEREQ; 662} WLAN_FR_PROBEREQ, *PWLAN_FR_PROBEREQ;
677 663
678// Probe Response 664/* probe response */
679typedef struct tagWLAN_FR_PROBERESP { 665typedef struct tagWLAN_FR_PROBERESP {
680 666
681 unsigned int uType; 667 unsigned int uType;
682 unsigned int len; 668 unsigned int len;
683 PBYTE pBuf; 669 PBYTE pBuf;
684 PUWLAN_80211HDR pHdr; 670 PUWLAN_80211HDR pHdr;
685 /*-- fixed fields -----------*/ 671 /* fixed fields */
686 PQWORD pqwTimestamp; 672 u64 *pqwTimestamp;
687 PWORD pwBeaconInterval; 673 PWORD pwBeaconInterval;
688 PWORD pwCapInfo; 674 PWORD pwCapInfo;
689 /*-- info elements ----------*/ 675 /* info elements */
690 PWLAN_IE_SSID pSSID; 676 PWLAN_IE_SSID pSSID;
691 PWLAN_IE_SUPP_RATES pSuppRates; 677 PWLAN_IE_SUPP_RATES pSuppRates;
692 PWLAN_IE_DS_PARMS pDSParms; 678 PWLAN_IE_DS_PARMS pDSParms;
@@ -704,37 +690,38 @@ typedef struct tagWLAN_FR_PROBERESP {
704 690
705} WLAN_FR_PROBERESP, *PWLAN_FR_PROBERESP; 691} WLAN_FR_PROBERESP, *PWLAN_FR_PROBERESP;
706 692
707// Authentication 693/* authentication */
708typedef struct tagWLAN_FR_AUTHEN { 694typedef struct tagWLAN_FR_AUTHEN {
709 695
710 unsigned int uType; 696 unsigned int uType;
711 unsigned int len; 697 unsigned int len;
712 PBYTE pBuf; 698 PBYTE pBuf;
713 PUWLAN_80211HDR pHdr; 699 PUWLAN_80211HDR pHdr;
714 /*-- fixed fields -----------*/ 700 /* fixed fields */
715 PWORD pwAuthAlgorithm; 701 PWORD pwAuthAlgorithm;
716 PWORD pwAuthSequence; 702 PWORD pwAuthSequence;
717 PWORD pwStatus; 703 PWORD pwStatus;
718 /*-- info elements ----------*/ 704 /* info elements */
719 PWLAN_IE_CHALLENGE pChallenge; 705 PWLAN_IE_CHALLENGE pChallenge;
720 706
721} WLAN_FR_AUTHEN, *PWLAN_FR_AUTHEN; 707} WLAN_FR_AUTHEN, *PWLAN_FR_AUTHEN;
722 708
723// Deauthentication 709/* deauthentication */
724typedef struct tagWLAN_FR_DEAUTHEN { 710typedef struct tagWLAN_FR_DEAUTHEN {
725 711
726 unsigned int uType; 712 unsigned int uType;
727 unsigned int len; 713 unsigned int len;
728 PBYTE pBuf; 714 PBYTE pBuf;
729 PUWLAN_80211HDR pHdr; 715 PUWLAN_80211HDR pHdr;
730 /*-- fixed fields -----------*/ 716 /* fixed fields */
731 PWORD pwReason; 717 PWORD pwReason;
732 718
733 /*-- info elements ----------*/ 719 /* info elements */
734 720
735} WLAN_FR_DEAUTHEN, *PWLAN_FR_DEAUTHEN; 721} WLAN_FR_DEAUTHEN, *PWLAN_FR_DEAUTHEN;
736 722
737/*--------------------- Export Functions --------------------------*/ 723/*--------------------- Export Functions --------------------------*/
724
738void 725void
739vMgrEncodeBeacon( 726vMgrEncodeBeacon(
740 PWLAN_FR_BEACON pFrame 727 PWLAN_FR_BEACON pFrame
@@ -845,4 +832,4 @@ vMgrDecodeReassocResponse(
845 PWLAN_FR_REASSOCRESP pFrame 832 PWLAN_FR_REASSOCRESP pFrame
846 ); 833 );
847 834
848#endif// __80211MGR_H__ 835#endif /* __80211MGR_H__ */
diff --git a/drivers/staging/vt6656/aes_ccmp.c b/drivers/staging/vt6656/aes_ccmp.c
index f7a3b8f8da70..fb6124d9082a 100644
--- a/drivers/staging/vt6656/aes_ccmp.c
+++ b/drivers/staging/vt6656/aes_ccmp.c
@@ -231,7 +231,7 @@ void AESv128(BYTE *key, BYTE *data, BYTE *ciphertext)
231 * 231 *
232 */ 232 */
233 233
234BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize) 234bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
235{ 235{
236 BYTE abyNonce[13]; 236 BYTE abyNonce[13];
237 BYTE MIC_IV[16]; 237 BYTE MIC_IV[16];
@@ -249,7 +249,7 @@ BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
249 WORD wHLen = 22; 249 WORD wHLen = 22;
250 /* 8 is IV, 8 is MIC, 4 is CRC */ 250 /* 8 is IV, 8 is MIC, 4 is CRC */
251 WORD wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN; 251 WORD wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN;
252 BOOL bA4 = FALSE; 252 bool bA4 = false;
253 BYTE byTmp; 253 BYTE byTmp;
254 WORD wCnt; 254 WORD wCnt;
255 int ii, jj, kk; 255 int ii, jj, kk;
@@ -257,7 +257,7 @@ BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
257 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN; 257 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
258 if (WLAN_GET_FC_TODS(*(PWORD) pbyFrame) && 258 if (WLAN_GET_FC_TODS(*(PWORD) pbyFrame) &&
259 WLAN_GET_FC_FROMDS(*(PWORD) pbyFrame)) { 259 WLAN_GET_FC_FROMDS(*(PWORD) pbyFrame)) {
260 bA4 = TRUE; 260 bA4 = true;
261 pbyIV += 6; /* 6 is 802.11 address4 */ 261 pbyIV += 6; /* 6 is 802.11 address4 */
262 wHLen += 6; 262 wHLen += 6;
263 wPayloadSize -= 6; 263 wPayloadSize -= 6;
@@ -380,7 +380,7 @@ BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
380 /* => above is the packet dec-MIC */ 380 /* => above is the packet dec-MIC */
381 381
382 if (!memcmp(abyMIC, abyTmp, 8)) 382 if (!memcmp(abyMIC, abyTmp, 8))
383 return TRUE; 383 return true;
384 else 384 else
385 return FALSE; 385 return false;
386} 386}
diff --git a/drivers/staging/vt6656/aes_ccmp.h b/drivers/staging/vt6656/aes_ccmp.h
index 353bd210a502..a2e2c4e9a5c9 100644
--- a/drivers/staging/vt6656/aes_ccmp.h
+++ b/drivers/staging/vt6656/aes_ccmp.h
@@ -41,6 +41,6 @@
41/*--------------------- Export Variables --------------------------*/ 41/*--------------------- Export Variables --------------------------*/
42 42
43/*--------------------- Export Functions --------------------------*/ 43/*--------------------- Export Functions --------------------------*/
44BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize); 44bool AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize);
45 45
46#endif /* __AES_CCMP_H__ */ 46#endif /* __AES_CCMP_H__ */
diff --git a/drivers/staging/vt6656/baseband.c b/drivers/staging/vt6656/baseband.c
index 385501595b4d..a9f525e9d16e 100644
--- a/drivers/staging/vt6656/baseband.c
+++ b/drivers/staging/vt6656/baseband.c
@@ -690,7 +690,7 @@ s_vClearSQ3Value(PSDevice pDevice);
690 * 690 *
691 */ 691 */
692unsigned int 692unsigned int
693BBuGetFrameTime ( 693BBuGetFrameTime(
694 BYTE byPreambleType, 694 BYTE byPreambleType,
695 BYTE byPktType, 695 BYTE byPktType,
696 unsigned int cbFrameLength, 696 unsigned int cbFrameLength,
@@ -756,26 +756,19 @@ BBuGetFrameTime (
756 * Return Value: none 756 * Return Value: none
757 * 757 *
758 */ 758 */
759void 759void BBvCalculateParameter(struct vnt_private *pDevice, u32 cbFrameLength,
760BBvCalculateParameter ( 760 u16 wRate, u8 byPacketType, u16 *pwPhyLen, u8 *pbyPhySrv,
761 PSDevice pDevice, 761 u8 *pbyPhySgn)
762 unsigned int cbFrameLength,
763 WORD wRate,
764 BYTE byPacketType,
765 PWORD pwPhyLen,
766 PBYTE pbyPhySrv,
767 PBYTE pbyPhySgn
768 )
769{ 762{
770 unsigned int cbBitCount; 763 u32 cbBitCount;
771 unsigned int cbUsCount = 0; 764 u32 cbUsCount = 0;
772 unsigned int cbTmp; 765 u32 cbTmp;
773 BOOL bExtBit; 766 int bExtBit;
774 BYTE byPreambleType = pDevice->byPreambleType; 767 u8 byPreambleType = pDevice->byPreambleType;
775 BOOL bCCK = pDevice->bCCK; 768 int bCCK = pDevice->bCCK;
776 769
777 cbBitCount = cbFrameLength * 8; 770 cbBitCount = cbFrameLength * 8;
778 bExtBit = FALSE; 771 bExtBit = false;
779 772
780 switch (wRate) { 773 switch (wRate) {
781 case RATE_1M : 774 case RATE_1M :
@@ -792,7 +785,7 @@ BBvCalculateParameter (
792 break; 785 break;
793 786
794 case RATE_5M : 787 case RATE_5M :
795 if (bCCK == FALSE) 788 if (bCCK == false)
796 cbBitCount ++; 789 cbBitCount ++;
797 cbUsCount = (cbBitCount * 10) / 55; 790 cbUsCount = (cbBitCount * 10) / 55;
798 cbTmp = (cbUsCount * 55) / 10; 791 cbTmp = (cbUsCount * 55) / 10;
@@ -806,14 +799,14 @@ BBvCalculateParameter (
806 799
807 case RATE_11M : 800 case RATE_11M :
808 801
809 if (bCCK == FALSE) 802 if (bCCK == false)
810 cbBitCount ++; 803 cbBitCount ++;
811 cbUsCount = cbBitCount / 11; 804 cbUsCount = cbBitCount / 11;
812 cbTmp = cbUsCount * 11; 805 cbTmp = cbUsCount * 11;
813 if (cbTmp != cbBitCount) { 806 if (cbTmp != cbBitCount) {
814 cbUsCount ++; 807 cbUsCount ++;
815 if ((cbBitCount - cbTmp) <= 3) 808 if ((cbBitCount - cbTmp) <= 3)
816 bExtBit = TRUE; 809 bExtBit = true;
817 } 810 }
818 if (byPreambleType == 1) 811 if (byPreambleType == 1)
819 *pbyPhySgn = 0x0b; 812 *pbyPhySgn = 0x0b;
@@ -929,8 +922,7 @@ BBvCalculateParameter (
929 * Return Value: none 922 * Return Value: none
930 * 923 *
931 */ 924 */
932void 925void BBvSetAntennaMode(struct vnt_private *pDevice, u8 byAntennaMode)
933BBvSetAntennaMode (PSDevice pDevice, BYTE byAntennaMode)
934{ 926{
935 switch (byAntennaMode) { 927 switch (byAntennaMode) {
936 case ANT_TXA: 928 case ANT_TXA:
@@ -968,7 +960,7 @@ BBvSetAntennaMode (PSDevice pDevice, BYTE byAntennaMode)
968 * 960 *
969 */ 961 */
970 962
971BOOL BBbVT3184Init(PSDevice pDevice) 963int BBbVT3184Init(struct vnt_private *pDevice)
972{ 964{
973 int ntStatus; 965 int ntStatus;
974 WORD wLength; 966 WORD wLength;
@@ -984,12 +976,12 @@ BOOL BBbVT3184Init(PSDevice pDevice)
984 EEP_MAX_CONTEXT_SIZE, 976 EEP_MAX_CONTEXT_SIZE,
985 pDevice->abyEEPROM); 977 pDevice->abyEEPROM);
986 if (ntStatus != STATUS_SUCCESS) { 978 if (ntStatus != STATUS_SUCCESS) {
987 return FALSE; 979 return false;
988 } 980 }
989 981
990 982
991// if ((pDevice->abyEEPROM[EEP_OFS_RADIOCTL]&0x06)==0x04) 983// if ((pDevice->abyEEPROM[EEP_OFS_RADIOCTL]&0x06)==0x04)
992// return FALSE; 984// return false;
993 985
994//zonetype initial 986//zonetype initial
995 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE]; 987 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
@@ -1105,7 +1097,7 @@ else {
1105 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL2, SOFTPWRCTL_RFLEOPT); 1097 MACvRegBitsOn(pDevice, MAC_REG_SOFTPWRCTL2, SOFTPWRCTL_RFLEOPT);
1106 //}} 1098 //}}
1107 } else { 1099 } else {
1108 return TRUE; 1100 return true;
1109 } 1101 }
1110 1102
1111 memcpy(abyArray, pbyAddr, wLength); 1103 memcpy(abyArray, pbyAddr, wLength);
@@ -1144,7 +1136,7 @@ else {
1144 ControlvWriteByte(pDevice,MESSAGE_REQUEST_BBREG,0x0D,0x01); 1136 ControlvWriteByte(pDevice,MESSAGE_REQUEST_BBREG,0x0D,0x01);
1145 1137
1146 RFbRFTableDownload(pDevice); 1138 RFbRFTableDownload(pDevice);
1147 return TRUE;//ntStatus; 1139 return true;//ntStatus;
1148} 1140}
1149 1141
1150 1142
@@ -1161,7 +1153,7 @@ else {
1161 * Return Value: none 1153 * Return Value: none
1162 * 1154 *
1163 */ 1155 */
1164void BBvLoopbackOn (PSDevice pDevice) 1156void BBvLoopbackOn(struct vnt_private *pDevice)
1165{ 1157{
1166 BYTE byData; 1158 BYTE byData;
1167 1159
@@ -1214,9 +1206,9 @@ void BBvLoopbackOn (PSDevice pDevice)
1214 * Return Value: none 1206 * Return Value: none
1215 * 1207 *
1216 */ 1208 */
1217void BBvLoopbackOff (PSDevice pDevice) 1209void BBvLoopbackOff(struct vnt_private *pDevice)
1218{ 1210{
1219 BYTE byData; 1211 u8 byData;
1220 1212
1221 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, pDevice->byBBCRc9);//CR201 1213 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xC9, pDevice->byBBCRc9);//CR201
1222 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, pDevice->byBBCR88);//CR136 1214 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x88, pDevice->byBBCR88);//CR136
@@ -1249,8 +1241,7 @@ void BBvLoopbackOff (PSDevice pDevice)
1249 * Return Value: none 1241 * Return Value: none
1250 * 1242 *
1251 */ 1243 */
1252void 1244void BBvSetShortSlotTime(struct vnt_private *pDevice)
1253BBvSetShortSlotTime (PSDevice pDevice)
1254{ 1245{
1255 BYTE byBBVGA=0; 1246 BYTE byBBVGA=0;
1256 1247
@@ -1267,7 +1258,7 @@ BBvSetShortSlotTime (PSDevice pDevice)
1267} 1258}
1268 1259
1269 1260
1270void BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData) 1261void BBvSetVGAGainOffset(struct vnt_private *pDevice, BYTE byData)
1271{ 1262{
1272 1263
1273 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, byData); 1264 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xE7, byData);
@@ -1294,8 +1285,7 @@ void BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData)
1294 * Return Value: none 1285 * Return Value: none
1295 * 1286 *
1296 */ 1287 */
1297void 1288void BBvSoftwareReset(struct vnt_private *pDevice)
1298BBvSoftwareReset (PSDevice pDevice)
1299{ 1289{
1300 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0x40); 1290 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0x40);
1301 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0); 1291 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x50, 0);
@@ -1315,22 +1305,20 @@ BBvSoftwareReset (PSDevice pDevice)
1315 * Return Value: none 1305 * Return Value: none
1316 * 1306 *
1317 */ 1307 */
1318void 1308void BBvSetDeepSleep(struct vnt_private *pDevice)
1319BBvSetDeepSleep (PSDevice pDevice)
1320{ 1309{
1321 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);//CR12 1310 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);//CR12
1322 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0D, 0xB9);//CR13 1311 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0D, 0xB9);//CR13
1323} 1312}
1324 1313
1325void 1314void BBvExitDeepSleep(struct vnt_private *pDevice)
1326BBvExitDeepSleep (PSDevice pDevice)
1327{ 1315{
1328 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0C, 0x00);//CR12 1316 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0C, 0x00);//CR12
1329 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0D, 0x01);//CR13 1317 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0x0D, 0x01);//CR13
1330} 1318}
1331 1319
1332 1320
1333static unsigned long s_ulGetLowSQ3(PSDevice pDevice) 1321static unsigned long s_ulGetLowSQ3(struct vnt_private *pDevice)
1334{ 1322{
1335 int ii; 1323 int ii;
1336 unsigned long ulSQ3 = 0; 1324 unsigned long ulSQ3 = 0;
@@ -1349,7 +1337,7 @@ static unsigned long s_ulGetLowSQ3(PSDevice pDevice)
1349 return ulSQ3; 1337 return ulSQ3;
1350} 1338}
1351 1339
1352static unsigned long s_ulGetRatio(PSDevice pDevice) 1340static unsigned long s_ulGetRatio(struct vnt_private *pDevice)
1353{ 1341{
1354 int ii, jj; 1342 int ii, jj;
1355 unsigned long ulRatio = 0; 1343 unsigned long ulRatio = 0;
@@ -1377,9 +1365,7 @@ static unsigned long s_ulGetRatio(PSDevice pDevice)
1377} 1365}
1378 1366
1379 1367
1380static 1368static void s_vClearSQ3Value(struct vnt_private *pDevice)
1381void
1382s_vClearSQ3Value (PSDevice pDevice)
1383{ 1369{
1384 int ii; 1370 int ii;
1385 pDevice->uDiversityCnt = 0; 1371 pDevice->uDiversityCnt = 0;
@@ -1406,8 +1392,8 @@ s_vClearSQ3Value (PSDevice pDevice)
1406 * 1392 *
1407 */ 1393 */
1408 1394
1409void 1395void BBvAntennaDiversity(struct vnt_private *pDevice,
1410BBvAntennaDiversity (PSDevice pDevice, BYTE byRxRate, BYTE bySQ3) 1396 u8 byRxRate, u8 bySQ3)
1411{ 1397{
1412 1398
1413 pDevice->uDiversityCnt++; 1399 pDevice->uDiversityCnt++;
@@ -1541,9 +1527,8 @@ BBvAntennaDiversity (PSDevice pDevice, BYTE byRxRate, BYTE bySQ3)
1541 * 1527 *
1542-*/ 1528-*/
1543 1529
1544void TimerSQ3CallBack(void *hDeviceContext) 1530void TimerSQ3CallBack(struct vnt_private *pDevice)
1545{ 1531{
1546 PSDevice pDevice = (PSDevice)hDeviceContext;
1547 1532
1548 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3CallBack..."); 1533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3CallBack...");
1549 spin_lock_irq(&pDevice->lock); 1534 spin_lock_irq(&pDevice->lock);
@@ -1579,9 +1564,8 @@ void TimerSQ3CallBack(void *hDeviceContext)
1579 * 1564 *
1580-*/ 1565-*/
1581 1566
1582void TimerSQ3Tmax3CallBack(void *hDeviceContext) 1567void TimerSQ3Tmax3CallBack(struct vnt_private *pDevice)
1583{ 1568{
1584 PSDevice pDevice = (PSDevice)hDeviceContext;
1585 1569
1586 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3Tmax3CallBack..."); 1570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3Tmax3CallBack...");
1587 spin_lock_irq(&pDevice->lock); 1571 spin_lock_irq(&pDevice->lock);
@@ -1607,10 +1591,7 @@ void TimerSQ3Tmax3CallBack(void *hDeviceContext)
1607 spin_unlock_irq(&pDevice->lock); 1591 spin_unlock_irq(&pDevice->lock);
1608} 1592}
1609 1593
1610void 1594void BBvUpdatePreEDThreshold(struct vnt_private *pDevice, int bScanning)
1611BBvUpdatePreEDThreshold(
1612 PSDevice pDevice,
1613 BOOL bScanning)
1614{ 1595{
1615 1596
1616 1597
diff --git a/drivers/staging/vt6656/baseband.h b/drivers/staging/vt6656/baseband.h
index 844d5a8b13e5..fba61605a692 100644
--- a/drivers/staging/vt6656/baseband.h
+++ b/drivers/staging/vt6656/baseband.h
@@ -42,31 +42,30 @@
42#define PREAMBLE_LONG 0 42#define PREAMBLE_LONG 0
43#define PREAMBLE_SHORT 1 43#define PREAMBLE_SHORT 1
44 44
45// 45/*
46// Registers in the BASEBAND 46 * Registers in the BASEBAND
47// 47 */
48#define BB_MAX_CONTEXT_SIZE 256 48#define BB_MAX_CONTEXT_SIZE 256
49 49
50#define C_SIFS_A 16 // micro sec. 50#define C_SIFS_A 16 /* usec */
51#define C_SIFS_BG 10 51#define C_SIFS_BG 10
52 52
53#define C_EIFS 80 // micro sec. 53#define C_EIFS 80 /* usec */
54 54
55 55#define C_SLOT_SHORT 9 /* usec */
56#define C_SLOT_SHORT 9 // micro sec.
57#define C_SLOT_LONG 20 56#define C_SLOT_LONG 20
58 57
59#define C_CWMIN_A 15 // slot time 58#define C_CWMIN_A 15 /* slot time */
60#define C_CWMIN_B 31 59#define C_CWMIN_B 31
61 60
62#define C_CWMAX 1023 // slot time 61#define C_CWMAX 1023 /* slot time */
63 62
64//0:11A 1:11B 2:11G 63/* 0:11A 1:11B 2:11G */
65#define BB_TYPE_11A 0 64#define BB_TYPE_11A 0
66#define BB_TYPE_11B 1 65#define BB_TYPE_11B 1
67#define BB_TYPE_11G 2 66#define BB_TYPE_11G 2
68 67
69//0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) 68/* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga (OFDM in BasicRate) */
70#define PK_TYPE_11A 0 69#define PK_TYPE_11A 0
71#define PK_TYPE_11B 1 70#define PK_TYPE_11B 1
72#define PK_TYPE_11GB 2 71#define PK_TYPE_11GB 2
@@ -104,33 +103,26 @@ BBuGetFrameTime(
104 WORD wRate 103 WORD wRate
105 ); 104 );
106 105
107void BBvCalculateParameter(PSDevice pDevice, 106void BBvCalculateParameter(struct vnt_private *, u32 cbFrameLength,
108 unsigned int cbFrameLength, 107 u16 wRate, u8 byPacketType, u16 *pwPhyLen, u8 *pbyPhySrv,
109 WORD wRate, 108 u8 *pbyPhySgn);
110 BYTE byPacketType, 109
111 PWORD pwPhyLen, 110/* timer for antenna diversity */
112 PBYTE pbyPhySrv, 111
113 PBYTE pbyPhySgn); 112void TimerSQ3CallBack(struct vnt_private *);
114 113void TimerSQ3Tmax3CallBack(struct vnt_private *);
115// timer for antenna diversity 114
116 115void BBvAntennaDiversity(struct vnt_private *, u8 byRxRate, u8 bySQ3);
117void TimerSQ3CallBack(void *hDeviceContext); 116void BBvLoopbackOn(struct vnt_private *);
118void TimerSQ3Tmax3CallBack(void *hDeviceContext); 117void BBvLoopbackOff(struct vnt_private *);
119 118void BBvSoftwareReset(struct vnt_private *);
120void BBvAntennaDiversity(PSDevice pDevice, BYTE byRxRate, BYTE bySQ3); 119
121void BBvLoopbackOn(PSDevice pDevice); 120void BBvSetShortSlotTime(struct vnt_private *);
122void BBvLoopbackOff(PSDevice pDevice); 121void BBvSetVGAGainOffset(struct vnt_private *, u8 byData);
123void BBvSoftwareReset(PSDevice pDevice); 122void BBvSetAntennaMode(struct vnt_private *, u8 byAntennaMode);
124 123int BBbVT3184Init(struct vnt_private *);
125void BBvSetShortSlotTime(PSDevice pDevice); 124void BBvSetDeepSleep(struct vnt_private *);
126void BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData); 125void BBvExitDeepSleep(struct vnt_private *);
127void BBvSetAntennaMode(PSDevice pDevice, BYTE byAntennaMode); 126void BBvUpdatePreEDThreshold(struct vnt_private *, int bScanning);
128BOOL BBbVT3184Init(PSDevice pDevice);
129void BBvSetDeepSleep(PSDevice pDevice);
130void BBvExitDeepSleep(PSDevice pDevice);
131void BBvUpdatePreEDThreshold(
132 PSDevice pDevice,
133 BOOL bScanning
134 );
135 127
136#endif /* __BASEBAND_H__ */ 128#endif /* __BASEBAND_H__ */
diff --git a/drivers/staging/vt6656/bssdb.c b/drivers/staging/vt6656/bssdb.c
index 6a1394192248..e214fcf83868 100644
--- a/drivers/staging/vt6656/bssdb.c
+++ b/drivers/staging/vt6656/bssdb.c
@@ -91,9 +91,9 @@ const WORD awHWRetry1[5][5] = {
91 91
92/*--------------------- Static Functions --------------------------*/ 92/*--------------------- Static Functions --------------------------*/
93 93
94void s_vCheckSensitivity(void *hDeviceContext); 94static void s_vCheckSensitivity(struct vnt_private *pDevice);
95void s_vCheckPreEDThreshold(void *hDeviceContext); 95static void s_vCheckPreEDThreshold(struct vnt_private *pDevice);
96void s_uCalculateLinkQual(void *hDeviceContext); 96static void s_uCalculateLinkQual(struct vnt_private *pDevice);
97 97
98/*--------------------- Export Variables --------------------------*/ 98/*--------------------- Export Variables --------------------------*/
99 99
@@ -114,20 +114,19 @@ void s_uCalculateLinkQual(void *hDeviceContext);
114 * 114 *
115-*/ 115-*/
116 116
117PKnownBSS BSSpSearchBSSList(void *hDeviceContext, 117PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice,
118 PBYTE pbyDesireBSSID, 118 u8 *pbyDesireBSSID, u8 *pbyDesireSSID,
119 PBYTE pbyDesireSSID, 119 CARD_PHY_TYPE ePhyType)
120 CARD_PHY_TYPE ePhyType)
121{ 120{
122 PSDevice pDevice = (PSDevice)hDeviceContext; 121 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
123 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 122 u8 *pbyBSSID = NULL;
124 PBYTE pbyBSSID = NULL; 123 PWLAN_IE_SSID pSSID = NULL;
125 PWLAN_IE_SSID pSSID = NULL; 124 PKnownBSS pCurrBSS = NULL;
126 PKnownBSS pCurrBSS = NULL; 125 PKnownBSS pSelect = NULL;
127 PKnownBSS pSelect = NULL; 126 u8 ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
128 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00}; 127 int ii = 0;
129 unsigned int ii = 0; 128 int jj = 0;
130 unsigned int jj = 0; 129
131 if (pbyDesireBSSID != NULL) { 130 if (pbyDesireBSSID != NULL) {
132 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO 131 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
133 "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID); 132 "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID);
@@ -142,15 +141,15 @@ PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
142 } 141 }
143 } 142 }
144 143
145 if ((pbyBSSID != NULL)&&(pDevice->bRoaming == FALSE)) { 144 if ((pbyBSSID != NULL)&&(pDevice->bRoaming == false)) {
146 // match BSSID first 145 // match BSSID first
147 for (ii = 0; ii <MAX_BSS_NUM; ii++) { 146 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
148 pCurrBSS = &(pMgmt->sBSSList[ii]); 147 pCurrBSS = &(pMgmt->sBSSList[ii]);
149 148
150 pCurrBSS->bSelected = FALSE; 149 pCurrBSS->bSelected = false;
151 150
152 if ((pCurrBSS->bActive) && 151 if ((pCurrBSS->bActive) &&
153 (pCurrBSS->bSelected == FALSE)) { 152 (pCurrBSS->bSelected == false)) {
154 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) { 153 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
155 if (pSSID != NULL) { 154 if (pSSID != NULL) {
156 // compare ssid 155 // compare ssid
@@ -161,7 +160,7 @@ PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
161 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) || 160 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
162 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) 161 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
163 ) { 162 ) {
164 pCurrBSS->bSelected = TRUE; 163 pCurrBSS->bSelected = true;
165 return(pCurrBSS); 164 return(pCurrBSS);
166 } 165 }
167 } 166 }
@@ -170,7 +169,7 @@ PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
170 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) || 169 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
171 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) 170 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
172 ) { 171 ) {
173 pCurrBSS->bSelected = TRUE; 172 pCurrBSS->bSelected = true;
174 return(pCurrBSS); 173 return(pCurrBSS);
175 } 174 }
176 } 175 }
@@ -184,9 +183,9 @@ PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
184 183
185 //2007-0721-01<Mark>by MikeLiu 184 //2007-0721-01<Mark>by MikeLiu
186 // if ((pCurrBSS->bActive) && 185 // if ((pCurrBSS->bActive) &&
187 // (pCurrBSS->bSelected == FALSE)) { 186 // (pCurrBSS->bSelected == false)) {
188 187
189 pCurrBSS->bSelected = FALSE; 188 pCurrBSS->bSelected = false;
190 if (pCurrBSS->bActive) { 189 if (pCurrBSS->bActive) {
191 190
192 if (pSSID != NULL) { 191 if (pSSID != NULL) {
@@ -237,10 +236,9 @@ PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
237pDevice->bSameBSSMaxNum = jj; 236pDevice->bSameBSSMaxNum = jj;
238 237
239 if (pSelect != NULL) { 238 if (pSelect != NULL) {
240 pSelect->bSelected = TRUE; 239 pSelect->bSelected = true;
241 if (pDevice->bRoaming == FALSE) { 240 if (pDevice->bRoaming == false) {
242 // Einsn Add @20070907 241 // Einsn Add @20070907
243 memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
244 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ; 242 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
245 } 243 }
246 244
@@ -263,11 +261,10 @@ pDevice->bSameBSSMaxNum = jj;
263-*/ 261-*/
264 262
265 263
266void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID) 264void BSSvClearBSSList(struct vnt_private *pDevice, int bKeepCurrBSSID)
267{ 265{
268 PSDevice pDevice = (PSDevice)hDeviceContext; 266 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
269 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 267 int ii;
270 unsigned int ii;
271 268
272 for (ii = 0; ii < MAX_BSS_NUM; ii++) { 269 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
273 if (bKeepCurrBSSID) { 270 if (bKeepCurrBSSID) {
@@ -277,12 +274,12 @@ void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID)
277 //mike mark: there are two BSSID's in list. If that AP is in hidden ssid mode, one SSID is null, 274 //mike mark: there are two BSSID's in list. If that AP is in hidden ssid mode, one SSID is null,
278 // but other's might not be obvious, so if it associate's with your STA, 275 // but other's might not be obvious, so if it associate's with your STA,
279 // you must keep the two of them!! 276 // you must keep the two of them!!
280 // bKeepCurrBSSID = FALSE; 277 // bKeepCurrBSSID = false;
281 continue; 278 continue;
282 } 279 }
283 } 280 }
284 281
285 pMgmt->sBSSList[ii].bActive = FALSE; 282 pMgmt->sBSSList[ii].bActive = false;
286 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS)); 283 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
287 } 284 }
288 BSSvClearAnyBSSJoinRecord(pDevice); 285 BSSvClearAnyBSSJoinRecord(pDevice);
@@ -296,17 +293,15 @@ void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID)
296 * search BSS list by BSSID & SSID if matched 293 * search BSS list by BSSID & SSID if matched
297 * 294 *
298 * Return Value: 295 * Return Value:
299 * TRUE if found. 296 * true if found.
300 * 297 *
301-*/ 298-*/
302PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext, 299PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *pDevice,
303 PBYTE abyBSSID, 300 u8 *abyBSSID, PWLAN_IE_SSID pSSID)
304 PWLAN_IE_SSID pSSID)
305{ 301{
306 PSDevice pDevice = (PSDevice)hDeviceContext; 302 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
307 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 303 PKnownBSS pBSSList = NULL;
308 PKnownBSS pBSSList = NULL; 304 int ii;
309 unsigned int ii;
310 305
311 for (ii = 0; ii < MAX_BSS_NUM; ii++) { 306 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
312 pBSSList = &(pMgmt->sBSSList[ii]); 307 pBSSList = &(pMgmt->sBSSList[ii]);
@@ -333,36 +328,34 @@ PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext,
333 * Insert a BSS set into known BSS list 328 * Insert a BSS set into known BSS list
334 * 329 *
335 * Return Value: 330 * Return Value:
336 * TRUE if success. 331 * true if success.
337 * 332 *
338-*/ 333-*/
339 334
340BOOL BSSbInsertToBSSList(void *hDeviceContext, 335int BSSbInsertToBSSList(struct vnt_private *pDevice,
341 PBYTE abyBSSIDAddr, 336 u8 *abyBSSIDAddr,
342 QWORD qwTimestamp, 337 u64 qwTimestamp,
343 WORD wBeaconInterval, 338 u16 wBeaconInterval,
344 WORD wCapInfo, 339 u16 wCapInfo,
345 BYTE byCurrChannel, 340 u8 byCurrChannel,
346 PWLAN_IE_SSID pSSID, 341 PWLAN_IE_SSID pSSID,
347 PWLAN_IE_SUPP_RATES pSuppRates, 342 PWLAN_IE_SUPP_RATES pSuppRates,
348 PWLAN_IE_SUPP_RATES pExtSuppRates, 343 PWLAN_IE_SUPP_RATES pExtSuppRates,
349 PERPObject psERP, 344 PERPObject psERP,
350 PWLAN_IE_RSN pRSN, 345 PWLAN_IE_RSN pRSN,
351 PWLAN_IE_RSN_EXT pRSNWPA, 346 PWLAN_IE_RSN_EXT pRSNWPA,
352 PWLAN_IE_COUNTRY pIE_Country, 347 PWLAN_IE_COUNTRY pIE_Country,
353 PWLAN_IE_QUIET pIE_Quiet, 348 PWLAN_IE_QUIET pIE_Quiet,
354 unsigned int uIELength, 349 u32 uIELength,
355 PBYTE pbyIEs, 350 u8 *pbyIEs,
356 void *pRxPacketContext) 351 void *pRxPacketContext)
357{ 352{
358 353 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
359 PSDevice pDevice = (PSDevice)hDeviceContext; 354 struct vnt_rx_mgmt *pRxPacket =
360 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 355 (struct vnt_rx_mgmt *)pRxPacketContext;
361 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext; 356 PKnownBSS pBSSList = NULL;
362 PKnownBSS pBSSList = NULL; 357 unsigned int ii;
363 unsigned int ii; 358 bool bParsingQuiet = false;
364 BOOL bParsingQuiet = FALSE;
365
366 359
367 360
368 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]); 361 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
@@ -375,13 +368,12 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext,
375 368
376 if (ii == MAX_BSS_NUM){ 369 if (ii == MAX_BSS_NUM){
377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n"); 370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
378 return FALSE; 371 return false;
379 } 372 }
380 // save the BSS info 373 // save the BSS info
381 pBSSList->bActive = TRUE; 374 pBSSList->bActive = true;
382 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN); 375 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
383 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp)); 376 pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp);
384 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
385 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval); 377 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
386 pBSSList->wCapInfo = cpu_to_le16(wCapInfo); 378 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
387 pBSSList->uClearCount = 0; 379 pBSSList->uClearCount = 0;
@@ -412,7 +404,7 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext,
412 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) { 404 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
413 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A; 405 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
414 } else { 406 } else {
415 if (pBSSList->sERP.bERPExist == TRUE) { 407 if (pBSSList->sERP.bERPExist == true) {
416 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G; 408 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
417 } else { 409 } else {
418 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B; 410 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
@@ -428,7 +420,7 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext,
428 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { 420 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
429 // assoc with BSS 421 // assoc with BSS
430 if (pBSSList == pMgmt->pCurrBSS) { 422 if (pBSSList == pMgmt->pCurrBSS) {
431 bParsingQuiet = TRUE; 423 bParsingQuiet = true;
432 } 424 }
433 } 425 }
434 426
@@ -458,27 +450,27 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext,
458 } 450 }
459 } 451 }
460 452
461 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) { 453 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) {
462 454
463 PSKeyItem pTransmitKey = NULL; 455 PSKeyItem pTransmitKey = NULL;
464 BOOL bIs802_1x = FALSE; 456 bool bIs802_1x = false;
465 457
466 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) { 458 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
467 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) { 459 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
468 bIs802_1x = TRUE; 460 bIs802_1x = true;
469 break; 461 break;
470 } 462 }
471 } 463 }
472 if ((bIs802_1x == TRUE) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) && 464 if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
473 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) { 465 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
474 466
475 bAdd_PMKID_Candidate((void *) pDevice, 467 bAdd_PMKID_Candidate((void *) pDevice,
476 pBSSList->abyBSSID, 468 pBSSList->abyBSSID,
477 &pBSSList->sRSNCapObj); 469 &pBSSList->sRSNCapObj);
478 470
479 if ((pDevice->bLinkPass == TRUE) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { 471 if ((pDevice->bLinkPass == true) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
480 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) || 472 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) ||
481 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == TRUE)) { 473 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == true)) {
482 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList; 474 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
483 pDevice->gsPMKIDCandidate.Version = 1; 475 pDevice->gsPMKIDCandidate.Version = 1;
484 476
@@ -503,7 +495,7 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext,
503 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN; 495 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
504 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength); 496 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
505 497
506 return TRUE; 498 return true;
507} 499}
508 500
509 501
@@ -513,43 +505,43 @@ BOOL BSSbInsertToBSSList(void *hDeviceContext,
513 * Update BSS set in known BSS list 505 * Update BSS set in known BSS list
514 * 506 *
515 * Return Value: 507 * Return Value:
516 * TRUE if success. 508 * true if success.
517 * 509 *
518-*/ 510-*/
519// TODO: input structure modify 511// TODO: input structure modify
520 512
521BOOL BSSbUpdateToBSSList(void *hDeviceContext, 513int BSSbUpdateToBSSList(struct vnt_private *pDevice,
522 QWORD qwTimestamp, 514 u64 qwTimestamp,
523 WORD wBeaconInterval, 515 u16 wBeaconInterval,
524 WORD wCapInfo, 516 u16 wCapInfo,
525 BYTE byCurrChannel, 517 u8 byCurrChannel,
526 BOOL bChannelHit, 518 int bChannelHit,
527 PWLAN_IE_SSID pSSID, 519 PWLAN_IE_SSID pSSID,
528 PWLAN_IE_SUPP_RATES pSuppRates, 520 PWLAN_IE_SUPP_RATES pSuppRates,
529 PWLAN_IE_SUPP_RATES pExtSuppRates, 521 PWLAN_IE_SUPP_RATES pExtSuppRates,
530 PERPObject psERP, 522 PERPObject psERP,
531 PWLAN_IE_RSN pRSN, 523 PWLAN_IE_RSN pRSN,
532 PWLAN_IE_RSN_EXT pRSNWPA, 524 PWLAN_IE_RSN_EXT pRSNWPA,
533 PWLAN_IE_COUNTRY pIE_Country, 525 PWLAN_IE_COUNTRY pIE_Country,
534 PWLAN_IE_QUIET pIE_Quiet, 526 PWLAN_IE_QUIET pIE_Quiet,
535 PKnownBSS pBSSList, 527 PKnownBSS pBSSList,
536 unsigned int uIELength, 528 u32 uIELength,
537 PBYTE pbyIEs, 529 u8 *pbyIEs,
538 void *pRxPacketContext) 530 void *pRxPacketContext)
539{ 531{
540 int ii, jj; 532 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
541 PSDevice pDevice = (PSDevice)hDeviceContext; 533 struct vnt_rx_mgmt *pRxPacket =
542 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 534 (struct vnt_rx_mgmt *)pRxPacketContext;
543 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext; 535 int ii, jj;
544 signed long ldBm, ldBmSum; 536 signed long ldBm, ldBmSum;
545 BOOL bParsingQuiet = FALSE; 537 bool bParsingQuiet = false;
546 538
547 if (pBSSList == NULL) 539 if (pBSSList == NULL)
548 return FALSE; 540 return false;
549 541
550 542
551 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp)); 543 pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp);
552 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp)); 544
553 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval); 545 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
554 pBSSList->wCapInfo = cpu_to_le16(wCapInfo); 546 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
555 pBSSList->uClearCount = 0; 547 pBSSList->uClearCount = 0;
@@ -574,7 +566,7 @@ BOOL BSSbUpdateToBSSList(void *hDeviceContext,
574 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) { 566 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
575 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A; 567 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
576 } else { 568 } else {
577 if (pBSSList->sERP.bERPExist == TRUE) { 569 if (pBSSList->sERP.bERPExist == true) {
578 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G; 570 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
579 } else { 571 } else {
580 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B; 572 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
@@ -591,7 +583,7 @@ BOOL BSSbUpdateToBSSList(void *hDeviceContext,
591 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { 583 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
592 // assoc with BSS 584 // assoc with BSS
593 if (pBSSList == pMgmt->pCurrBSS) { 585 if (pBSSList == pMgmt->pCurrBSS) {
594 bParsingQuiet = TRUE; 586 bParsingQuiet = true;
595 } 587 }
596 } 588 }
597 589
@@ -643,7 +635,7 @@ BOOL BSSbUpdateToBSSList(void *hDeviceContext,
643 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN; 635 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
644 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength); 636 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
645 637
646 return TRUE; 638 return true;
647} 639}
648 640
649 641
@@ -660,13 +652,11 @@ BOOL BSSbUpdateToBSSList(void *hDeviceContext,
660 * 652 *
661-*/ 653-*/
662 654
663BOOL BSSbIsSTAInNodeDB(void *hDeviceContext, 655int BSSbIsSTAInNodeDB(struct vnt_private *pDevice,
664 PBYTE abyDstAddr, 656 u8 *abyDstAddr, u32 *puNodeIndex)
665 unsigned int *puNodeIndex)
666{ 657{
667 PSDevice pDevice = (PSDevice)hDeviceContext; 658 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
668 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 659 unsigned int ii;
669 unsigned int ii;
670 660
671 // Index = 0 reserved for AP Node 661 // Index = 0 reserved for AP Node
672 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) { 662 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
@@ -674,12 +664,12 @@ BOOL BSSbIsSTAInNodeDB(void *hDeviceContext,
674 if (!compare_ether_addr(abyDstAddr, 664 if (!compare_ether_addr(abyDstAddr,
675 pMgmt->sNodeDBTable[ii].abyMACAddr)) { 665 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
676 *puNodeIndex = ii; 666 *puNodeIndex = ii;
677 return TRUE; 667 return true;
678 } 668 }
679 } 669 }
680 } 670 }
681 671
682 return FALSE; 672 return false;
683}; 673};
684 674
685 675
@@ -694,15 +684,14 @@ BOOL BSSbIsSTAInNodeDB(void *hDeviceContext,
694 * None 684 * None
695 * 685 *
696-*/ 686-*/
697void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex) 687void BSSvCreateOneNode(struct vnt_private *pDevice, u32 *puNodeIndex)
698{ 688{
689 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
690 int ii;
691 u32 BigestCount = 0;
692 u32 SelectIndex;
693 struct sk_buff *skb;
699 694
700 PSDevice pDevice = (PSDevice)hDeviceContext;
701 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
702 unsigned int ii;
703 unsigned int BigestCount = 0;
704 unsigned int SelectIndex;
705 struct sk_buff *skb;
706 // Index = 0 reserved for AP Node (In STA mode) 695 // Index = 0 reserved for AP Node (In STA mode)
707 // Index = 0 reserved for Broadcast/MultiCast (In AP mode) 696 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
708 SelectIndex = 1; 697 SelectIndex = 1;
@@ -733,7 +722,7 @@ void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
733 } 722 }
734 723
735 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB)); 724 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
736 pMgmt->sNodeDBTable[*puNodeIndex].bActive = TRUE; 725 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
737 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND; 726 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
738 // for AP mode PS queue 727 // for AP mode PS queue
739 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue); 728 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
@@ -755,13 +744,11 @@ void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
755 * 744 *
756-*/ 745-*/
757 746
758void BSSvRemoveOneNode(void *hDeviceContext, unsigned int uNodeIndex) 747void BSSvRemoveOneNode(struct vnt_private *pDevice, u32 uNodeIndex)
759{ 748{
760 749 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
761 PSDevice pDevice = (PSDevice)hDeviceContext; 750 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
762 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 751 struct sk_buff *skb;
763 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
764 struct sk_buff *skb;
765 752
766 753
767 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL) 754 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
@@ -782,18 +769,15 @@ void BSSvRemoveOneNode(void *hDeviceContext, unsigned int uNodeIndex)
782 * 769 *
783-*/ 770-*/
784 771
785void BSSvUpdateAPNode(void *hDeviceContext, 772void BSSvUpdateAPNode(struct vnt_private *pDevice, u16 *pwCapInfo,
786 PWORD pwCapInfo, 773 PWLAN_IE_SUPP_RATES pSuppRates, PWLAN_IE_SUPP_RATES pExtSuppRates)
787 PWLAN_IE_SUPP_RATES pSuppRates,
788 PWLAN_IE_SUPP_RATES pExtSuppRates)
789{ 774{
790 PSDevice pDevice = (PSDevice)hDeviceContext; 775 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
791 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 776 u32 uRateLen = WLAN_RATES_MAXLEN;
792 unsigned int uRateLen = WLAN_RATES_MAXLEN;
793 777
794 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); 778 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
795 779
796 pMgmt->sNodeDBTable[0].bActive = TRUE; 780 pMgmt->sNodeDBTable[0].bActive = true;
797 if (pDevice->byBBType == BB_TYPE_11B) { 781 if (pDevice->byBBType == BB_TYPE_11B) {
798 uRateLen = WLAN_RATES_MAXLEN_11B; 782 uRateLen = WLAN_RATES_MAXLEN_11B;
799 } 783 }
@@ -806,7 +790,7 @@ void BSSvUpdateAPNode(void *hDeviceContext,
806 RATEvParseMaxRate((void *) pDevice, 790 RATEvParseMaxRate((void *) pDevice,
807 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 791 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
808 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, 792 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
809 TRUE, 793 true,
810 &(pMgmt->sNodeDBTable[0].wMaxBasicRate), 794 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
811 &(pMgmt->sNodeDBTable[0].wMaxSuppRate), 795 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
812 &(pMgmt->sNodeDBTable[0].wSuppRate), 796 &(pMgmt->sNodeDBTable[0].wSuppRate),
@@ -834,21 +818,20 @@ void BSSvUpdateAPNode(void *hDeviceContext,
834 * 818 *
835-*/ 819-*/
836 820
837void BSSvAddMulticastNode(void *hDeviceContext) 821void BSSvAddMulticastNode(struct vnt_private *pDevice)
838{ 822{
839 PSDevice pDevice = (PSDevice)hDeviceContext; 823 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
840 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
841 824
842 if (!pDevice->bEnableHostWEP) 825 if (!pDevice->bEnableHostWEP)
843 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB)); 826 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
844 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN); 827 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
845 pMgmt->sNodeDBTable[0].bActive = TRUE; 828 pMgmt->sNodeDBTable[0].bActive = true;
846 pMgmt->sNodeDBTable[0].bPSEnable = FALSE; 829 pMgmt->sNodeDBTable[0].bPSEnable = false;
847 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue); 830 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
848 RATEvParseMaxRate((void *) pDevice, 831 RATEvParseMaxRate((void *) pDevice,
849 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 832 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
850 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, 833 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
851 TRUE, 834 true,
852 &(pMgmt->sNodeDBTable[0].wMaxBasicRate), 835 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
853 &(pMgmt->sNodeDBTable[0].wMaxSuppRate), 836 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
854 &(pMgmt->sNodeDBTable[0].wSuppRate), 837 &(pMgmt->sNodeDBTable[0].wSuppRate),
@@ -873,26 +856,25 @@ void BSSvAddMulticastNode(void *hDeviceContext)
873 * 856 *
874-*/ 857-*/
875 858
876void BSSvSecondCallBack(void *hDeviceContext) 859void BSSvSecondCallBack(struct vnt_private *pDevice)
877{ 860{
878 PSDevice pDevice = (PSDevice)hDeviceContext; 861 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
879 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 862 int ii;
880 unsigned int ii; 863 PWLAN_IE_SSID pItemSSID, pCurrSSID;
881 PWLAN_IE_SSID pItemSSID, pCurrSSID; 864 u32 uSleepySTACnt = 0;
882 unsigned int uSleepySTACnt = 0; 865 u32 uNonShortSlotSTACnt = 0;
883 unsigned int uNonShortSlotSTACnt = 0; 866 u32 uLongPreambleSTACnt = 0;
884 unsigned int uLongPreambleSTACnt = 0;
885 867
886 spin_lock_irq(&pDevice->lock); 868 spin_lock_irq(&pDevice->lock);
887 869
888 pDevice->uAssocCount = 0; 870 pDevice->uAssocCount = 0;
889 871
890 //Power Saving Mode Tx Burst 872 //Power Saving Mode Tx Burst
891 if ( pDevice->bEnablePSMode == TRUE ) { 873 if ( pDevice->bEnablePSMode == true ) {
892 pDevice->ulPSModeWaitTx++; 874 pDevice->ulPSModeWaitTx++;
893 if ( pDevice->ulPSModeWaitTx >= 2 ) { 875 if ( pDevice->ulPSModeWaitTx >= 2 ) {
894 pDevice->ulPSModeWaitTx = 0; 876 pDevice->ulPSModeWaitTx = 0;
895 pDevice->bPSModeTxBurst = FALSE; 877 pDevice->bPSModeTxBurst = false;
896 } 878 }
897 } 879 }
898 880
@@ -909,10 +891,10 @@ void BSSvSecondCallBack(void *hDeviceContext)
909 891
910if(pDevice->byReAssocCount > 0) { 892if(pDevice->byReAssocCount > 0) {
911 pDevice->byReAssocCount++; 893 pDevice->byReAssocCount++;
912 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != TRUE)) { //10 sec timeout 894 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) { //10 sec timeout
913 printk("Re-association timeout!!!\n"); 895 printk("Re-association timeout!!!\n");
914 pDevice->byReAssocCount = 0; 896 pDevice->byReAssocCount = 0;
915 // if(pDevice->bWPASuppWextEnabled == TRUE) 897 // if(pDevice->bWPASuppWextEnabled == true)
916 { 898 {
917 union iwreq_data wrqu; 899 union iwreq_data wrqu;
918 memset(&wrqu, 0, sizeof (wrqu)); 900 memset(&wrqu, 0, sizeof (wrqu));
@@ -921,13 +903,13 @@ if(pDevice->byReAssocCount > 0) {
921 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL); 903 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
922 } 904 }
923 } 905 }
924 else if(pDevice->bLinkPass == TRUE) 906 else if(pDevice->bLinkPass == true)
925 pDevice->byReAssocCount = 0; 907 pDevice->byReAssocCount = 0;
926} 908}
927 909
928 pMgmt->eLastState = pMgmt->eCurrState ; 910 pMgmt->eLastState = pMgmt->eCurrState ;
929 911
930 s_uCalculateLinkQual((void *)pDevice); 912 s_uCalculateLinkQual(pDevice);
931 913
932 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) { 914 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
933 915
@@ -1006,27 +988,27 @@ if(pDevice->byReAssocCount > 0) {
1006 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) { 988 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1007 if (!pDevice->bProtectMode) { 989 if (!pDevice->bProtectMode) {
1008 MACvEnableProtectMD(pDevice); 990 MACvEnableProtectMD(pDevice);
1009 pDevice->bProtectMode = TRUE; 991 pDevice->bProtectMode = true;
1010 } 992 }
1011 } 993 }
1012 else { 994 else {
1013 if (pDevice->bProtectMode) { 995 if (pDevice->bProtectMode) {
1014 MACvDisableProtectMD(pDevice); 996 MACvDisableProtectMD(pDevice);
1015 pDevice->bProtectMode = FALSE; 997 pDevice->bProtectMode = false;
1016 } 998 }
1017 } 999 }
1018 // on/off short slot time 1000 // on/off short slot time
1019 1001
1020 if (uNonShortSlotSTACnt > 0) { 1002 if (uNonShortSlotSTACnt > 0) {
1021 if (pDevice->bShortSlotTime) { 1003 if (pDevice->bShortSlotTime) {
1022 pDevice->bShortSlotTime = FALSE; 1004 pDevice->bShortSlotTime = false;
1023 BBvSetShortSlotTime(pDevice); 1005 BBvSetShortSlotTime(pDevice);
1024 vUpdateIFS((void *)pDevice); 1006 vUpdateIFS((void *)pDevice);
1025 } 1007 }
1026 } 1008 }
1027 else { 1009 else {
1028 if (!pDevice->bShortSlotTime) { 1010 if (!pDevice->bShortSlotTime) {
1029 pDevice->bShortSlotTime = TRUE; 1011 pDevice->bShortSlotTime = true;
1030 BBvSetShortSlotTime(pDevice); 1012 BBvSetShortSlotTime(pDevice);
1031 vUpdateIFS((void *)pDevice); 1013 vUpdateIFS((void *)pDevice);
1032 } 1014 }
@@ -1037,13 +1019,13 @@ if(pDevice->byReAssocCount > 0) {
1037 if (uLongPreambleSTACnt > 0) { 1019 if (uLongPreambleSTACnt > 0) {
1038 if (!pDevice->bBarkerPreambleMd) { 1020 if (!pDevice->bBarkerPreambleMd) {
1039 MACvEnableBarkerPreambleMd(pDevice); 1021 MACvEnableBarkerPreambleMd(pDevice);
1040 pDevice->bBarkerPreambleMd = TRUE; 1022 pDevice->bBarkerPreambleMd = true;
1041 } 1023 }
1042 } 1024 }
1043 else { 1025 else {
1044 if (pDevice->bBarkerPreambleMd) { 1026 if (pDevice->bBarkerPreambleMd) {
1045 MACvDisableBarkerPreambleMd(pDevice); 1027 MACvDisableBarkerPreambleMd(pDevice);
1046 pDevice->bBarkerPreambleMd = FALSE; 1028 pDevice->bBarkerPreambleMd = false;
1047 } 1029 }
1048 } 1030 }
1049 1031
@@ -1053,9 +1035,9 @@ if(pDevice->byReAssocCount > 0) {
1053 // Check if any STA in PS mode, enable DTIM multicast deliver 1035 // Check if any STA in PS mode, enable DTIM multicast deliver
1054 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { 1036 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1055 if (uSleepySTACnt > 0) 1037 if (uSleepySTACnt > 0)
1056 pMgmt->sNodeDBTable[0].bPSEnable = TRUE; 1038 pMgmt->sNodeDBTable[0].bPSEnable = true;
1057 else 1039 else
1058 pMgmt->sNodeDBTable[0].bPSEnable = FALSE; 1040 pMgmt->sNodeDBTable[0].bPSEnable = false;
1059 } 1041 }
1060 1042
1061 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID; 1043 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
@@ -1067,8 +1049,8 @@ if(pDevice->byReAssocCount > 0) {
1067 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS 1049 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1068 1050
1069 if (pDevice->bUpdateBBVGA) { 1051 if (pDevice->bUpdateBBVGA) {
1070 /* s_vCheckSensitivity((void *) pDevice); */ 1052 s_vCheckSensitivity(pDevice);
1071 s_vCheckPreEDThreshold((void *) pDevice); 1053 s_vCheckPreEDThreshold(pDevice);
1072 } 1054 }
1073 1055
1074 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) && 1056 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
@@ -1080,14 +1062,14 @@ if(pDevice->byReAssocCount > 0) {
1080 } 1062 }
1081 1063
1082 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) { 1064 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1083 pMgmt->sNodeDBTable[0].bActive = FALSE; 1065 pMgmt->sNodeDBTable[0].bActive = false;
1084 pMgmt->eCurrMode = WMAC_MODE_STANDBY; 1066 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1085 pMgmt->eCurrState = WMAC_STATE_IDLE; 1067 pMgmt->eCurrState = WMAC_STATE_IDLE;
1086 netif_stop_queue(pDevice->dev); 1068 netif_stop_queue(pDevice->dev);
1087 pDevice->bLinkPass = FALSE; 1069 pDevice->bLinkPass = false;
1088 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 1070 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1089 pDevice->bRoaming = TRUE; 1071 pDevice->bRoaming = true;
1090 pDevice->bIsRoaming = FALSE; 1072 pDevice->bIsRoaming = false;
1091 1073
1092 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount); 1074 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1093 /* let wpa supplicant know AP may disconnect */ 1075 /* let wpa supplicant know AP may disconnect */
@@ -1102,10 +1084,10 @@ if(pDevice->byReAssocCount > 0) {
1102 } 1084 }
1103 else if (pItemSSID->len != 0) { 1085 else if (pItemSSID->len != 0) {
1104//Davidwang 1086//Davidwang
1105 if ((pDevice->bEnableRoaming == TRUE)&&(!(pMgmt->Cisco_cckm))) { 1087 if ((pDevice->bEnableRoaming == true)&&(!(pMgmt->Cisco_cckm))) {
1106DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bRoaming %d, !\n", pDevice->bRoaming ); 1088DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bRoaming %d, !\n", pDevice->bRoaming );
1107DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming ); 1089DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming );
1108 if ((pDevice->bRoaming == TRUE)&&(pDevice->bIsRoaming == TRUE)){ 1090 if ((pDevice->bRoaming == true)&&(pDevice->bIsRoaming == true)){
1109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fast Roaming ...\n"); 1091 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fast Roaming ...\n");
1110 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass); 1092 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1111 bScheduleCommand((void *) pDevice, 1093 bScheduleCommand((void *) pDevice,
@@ -1116,12 +1098,12 @@ DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming );
1116 pMgmt->abyDesireSSID); 1098 pMgmt->abyDesireSSID);
1117 pDevice->uAutoReConnectTime = 0; 1099 pDevice->uAutoReConnectTime = 0;
1118 pDevice->uIsroamingTime = 0; 1100 pDevice->uIsroamingTime = 0;
1119 pDevice->bRoaming = FALSE; 1101 pDevice->bRoaming = false;
1120 } 1102 }
1121 else if ((pDevice->bRoaming == FALSE)&&(pDevice->bIsRoaming == TRUE)) { 1103 else if ((pDevice->bRoaming == false)&&(pDevice->bIsRoaming == true)) {
1122 pDevice->uIsroamingTime++; 1104 pDevice->uIsroamingTime++;
1123 if (pDevice->uIsroamingTime >= 20) 1105 if (pDevice->uIsroamingTime >= 20)
1124 pDevice->bIsRoaming = FALSE; 1106 pDevice->bIsRoaming = false;
1125 } 1107 }
1126 1108
1127 } 1109 }
@@ -1129,7 +1111,7 @@ else {
1129 if (pDevice->uAutoReConnectTime < 10) { 1111 if (pDevice->uAutoReConnectTime < 10) {
1130 pDevice->uAutoReConnectTime++; 1112 pDevice->uAutoReConnectTime++;
1131 //network manager support need not do Roaming scan??? 1113 //network manager support need not do Roaming scan???
1132 if(pDevice->bWPASuppWextEnabled ==TRUE) 1114 if(pDevice->bWPASuppWextEnabled ==true)
1133 pDevice->uAutoReConnectTime = 0; 1115 pDevice->uAutoReConnectTime = 0;
1134 } 1116 }
1135 else { 1117 else {
@@ -1169,21 +1151,21 @@ else {
1169 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) { 1151 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1170 1152
1171 if (pDevice->bUpdateBBVGA) { 1153 if (pDevice->bUpdateBBVGA) {
1172 /* s_vCheckSensitivity((void *) pDevice); */ 1154 s_vCheckSensitivity(pDevice);
1173 s_vCheckPreEDThreshold((void *) pDevice); 1155 s_vCheckPreEDThreshold(pDevice);
1174 } 1156 }
1175 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) { 1157 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
1176 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount); 1158 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1177 pMgmt->sNodeDBTable[0].uInActiveCount = 0; 1159 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1178 pMgmt->eCurrState = WMAC_STATE_STARTED; 1160 pMgmt->eCurrState = WMAC_STATE_STARTED;
1179 netif_stop_queue(pDevice->dev); 1161 netif_stop_queue(pDevice->dev);
1180 pDevice->bLinkPass = FALSE; 1162 pDevice->bLinkPass = false;
1181 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 1163 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1182 } 1164 }
1183 } 1165 }
1184 } 1166 }
1185 1167
1186 if (pDevice->bLinkPass == TRUE) { 1168 if (pDevice->bLinkPass == true) {
1187 if (netif_queue_stopped(pDevice->dev)) 1169 if (netif_queue_stopped(pDevice->dev))
1188 netif_wake_queue(pDevice->dev); 1170 netif_wake_queue(pDevice->dev);
1189 } 1171 }
@@ -1207,22 +1189,19 @@ else {
1207 * 1189 *
1208-*/ 1190-*/
1209 1191
1210void BSSvUpdateNodeTxCounter(void *hDeviceContext, 1192void BSSvUpdateNodeTxCounter(struct vnt_private *pDevice,
1211 PSStatCounter pStatistic, 1193 PSStatCounter pStatistic, u8 byTSR, u8 byPktNO)
1212 BYTE byTSR,
1213 BYTE byPktNO)
1214{ 1194{
1215 PSDevice pDevice = (PSDevice)hDeviceContext; 1195 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1216 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1196 u32 uNodeIndex = 0;
1217 unsigned int uNodeIndex = 0; 1197 u8 byTxRetry;
1218 BYTE byTxRetry; 1198 u16 wRate;
1219 WORD wRate; 1199 u16 wFallBackRate = RATE_1M;
1220 WORD wFallBackRate = RATE_1M; 1200 u8 byFallBack;
1221 BYTE byFallBack; 1201 int ii;
1222 unsigned int ii; 1202 u8 *pbyDestAddr;
1223 PBYTE pbyDestAddr; 1203 u8 byPktNum;
1224 BYTE byPktNum; 1204 u16 wFIFOCtl;
1225 WORD wFIFOCtl;
1226 1205
1227 byPktNum = (byPktNO & 0x0F) >> 4; 1206 byPktNum = (byPktNO & 0x0F) >> 4;
1228 byTxRetry = (byTSR & 0xF0) >> 4; 1207 byTxRetry = (byTSR & 0xF0) >> 4;
@@ -1370,13 +1349,11 @@ void BSSvUpdateNodeTxCounter(void *hDeviceContext,
1370 * 1349 *
1371-*/ 1350-*/
1372 1351
1373void BSSvClearNodeDBTable(void *hDeviceContext, 1352void BSSvClearNodeDBTable(struct vnt_private *pDevice, u32 uStartIndex)
1374 unsigned int uStartIndex)
1375{ 1353{
1376 PSDevice pDevice = (PSDevice)hDeviceContext; 1354 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1377 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1355 struct sk_buff *skb;
1378 struct sk_buff *skb; 1356 int ii;
1379 unsigned int ii;
1380 1357
1381 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) { 1358 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1382 if (pMgmt->sNodeDBTable[ii].bActive) { 1359 if (pMgmt->sNodeDBTable[ii].bActive) {
@@ -1392,12 +1369,11 @@ void BSSvClearNodeDBTable(void *hDeviceContext,
1392 } 1369 }
1393}; 1370};
1394 1371
1395void s_vCheckSensitivity(void *hDeviceContext) 1372static void s_vCheckSensitivity(struct vnt_private *pDevice)
1396{ 1373{
1397 PSDevice pDevice = (PSDevice)hDeviceContext; 1374 PKnownBSS pBSSList = NULL;
1398 PKnownBSS pBSSList = NULL; 1375 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1399 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1376 int ii;
1400 int ii;
1401 1377
1402 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) || 1378 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1403 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) { 1379 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
@@ -1424,7 +1400,7 @@ void s_vCheckSensitivity(void *hDeviceContext)
1424 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) { 1400 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1425 pDevice->uBBVGADiffCount++; 1401 pDevice->uBBVGADiffCount++;
1426 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) 1402 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1427 bScheduleCommand((void *) pDevice, 1403 bScheduleCommand(pDevice,
1428 WLAN_CMD_CHANGE_BBSENSITIVITY, 1404 WLAN_CMD_CHANGE_BBSENSITIVITY,
1429 NULL); 1405 NULL);
1430 } else { 1406 } else {
@@ -1435,13 +1411,12 @@ void s_vCheckSensitivity(void *hDeviceContext)
1435 } 1411 }
1436} 1412}
1437 1413
1438void s_uCalculateLinkQual(void *hDeviceContext) 1414static void s_uCalculateLinkQual(struct vnt_private *pDevice)
1439{ 1415{
1440 PSDevice pDevice = (PSDevice)hDeviceContext; 1416 unsigned long TxOkRatio, TxCnt;
1441 unsigned long TxOkRatio, TxCnt; 1417 unsigned long RxOkRatio, RxCnt;
1442 unsigned long RxOkRatio, RxCnt; 1418 unsigned long RssiRatio;
1443 unsigned long RssiRatio; 1419 long ldBm;
1444 long ldBm;
1445 1420
1446TxCnt = pDevice->scStatistic.TxNoRetryOkCount + 1421TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1447 pDevice->scStatistic.TxRetryOkCount + 1422 pDevice->scStatistic.TxRetryOkCount +
@@ -1451,7 +1426,7 @@ RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1451TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt); 1426TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1452RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt); 1427RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1453//decide link quality 1428//decide link quality
1454if(pDevice->bLinkPass !=TRUE) 1429if(pDevice->bLinkPass !=true)
1455{ 1430{
1456 pDevice->scStatistic.LinkQuality = 0; 1431 pDevice->scStatistic.LinkQuality = 0;
1457 pDevice->scStatistic.SignalStren = 0; 1432 pDevice->scStatistic.SignalStren = 0;
@@ -1478,28 +1453,28 @@ else
1478 pDevice->scStatistic.TxRetryOkCount = 0; 1453 pDevice->scStatistic.TxRetryOkCount = 0;
1479} 1454}
1480 1455
1481void BSSvClearAnyBSSJoinRecord(void *hDeviceContext) 1456void BSSvClearAnyBSSJoinRecord(struct vnt_private *pDevice)
1482{ 1457{
1483 PSDevice pDevice = (PSDevice)hDeviceContext; 1458 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1484 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1459 int ii;
1485 unsigned int ii;
1486 1460
1487 for (ii = 0; ii < MAX_BSS_NUM; ii++) 1461 for (ii = 0; ii < MAX_BSS_NUM; ii++)
1488 pMgmt->sBSSList[ii].bSelected = FALSE; 1462 pMgmt->sBSSList[ii].bSelected = false;
1463
1464 return;
1489} 1465}
1490 1466
1491void s_vCheckPreEDThreshold(void *hDeviceContext) 1467static void s_vCheckPreEDThreshold(struct vnt_private *pDevice)
1492{ 1468{
1493 PSDevice pDevice = (PSDevice)hDeviceContext; 1469 PKnownBSS pBSSList = NULL;
1494 PKnownBSS pBSSList = NULL; 1470 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1495 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1496 1471
1497 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) || 1472 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1498 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) { 1473 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1499 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID); 1474 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1500 if (pBSSList != NULL) { 1475 if (pBSSList != NULL) {
1501 pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1); 1476 pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1);
1502 BBvUpdatePreEDThreshold(pDevice, FALSE); 1477 BBvUpdatePreEDThreshold(pDevice, false);
1503 } 1478 }
1504 } 1479 }
1505} 1480}
diff --git a/drivers/staging/vt6656/bssdb.h b/drivers/staging/vt6656/bssdb.h
index 806cbf72fb59..08091a0a7c40 100644
--- a/drivers/staging/vt6656/bssdb.h
+++ b/drivers/staging/vt6656/bssdb.h
@@ -79,20 +79,20 @@
79// 79//
80 80
81typedef struct tagSERPObject { 81typedef struct tagSERPObject {
82 BOOL bERPExist; 82 bool bERPExist;
83 BYTE byERP; 83 BYTE byERP;
84} ERPObject, *PERPObject; 84} ERPObject, *PERPObject;
85 85
86 86
87typedef struct tagSRSNCapObject { 87typedef struct tagSRSNCapObject {
88 BOOL bRSNCapExist; 88 bool bRSNCapExist;
89 WORD wRSNCap; 89 WORD wRSNCap;
90} SRSNCapObject, *PSRSNCapObject; 90} SRSNCapObject, *PSRSNCapObject;
91 91
92// BSS info(AP) 92// BSS info(AP)
93typedef struct tagKnownBSS { 93typedef struct tagKnownBSS {
94 // BSS info 94 // BSS info
95 BOOL bActive; 95 bool bActive;
96 BYTE abyBSSID[WLAN_BSSID_LEN]; 96 BYTE abyBSSID[WLAN_BSSID_LEN];
97 unsigned int uChannel; 97 unsigned int uChannel;
98 BYTE abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; 98 BYTE abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
@@ -110,10 +110,10 @@ typedef struct tagKnownBSS {
110 signed long ldBmAverage[RSSI_STAT_COUNT]; 110 signed long ldBmAverage[RSSI_STAT_COUNT];
111 signed long ldBmAverRange; 111 signed long ldBmAverRange;
112 //For any BSSID selection improvment 112 //For any BSSID selection improvment
113 BOOL bSelected; 113 bool bSelected;
114 114
115 //++ WPA informations 115 //++ WPA informations
116 BOOL bWPAValid; 116 bool bWPAValid;
117 BYTE byGKType; 117 BYTE byGKType;
118 BYTE abyPKType[4]; 118 BYTE abyPKType[4];
119 WORD wPKCount; 119 WORD wPKCount;
@@ -124,7 +124,7 @@ typedef struct tagKnownBSS {
124 //-- 124 //--
125 125
126 //++ WPA2 informations 126 //++ WPA2 informations
127 BOOL bWPA2Valid; 127 bool bWPA2Valid;
128 BYTE byCSSGK; 128 BYTE byCSSGK;
129 WORD wCSSPKCount; 129 WORD wCSSPKCount;
130 BYTE abyCSSPK[4]; 130 BYTE abyCSSPK[4];
@@ -141,8 +141,8 @@ typedef struct tagKnownBSS {
141 unsigned int uClearCount; 141 unsigned int uClearCount;
142// BYTE abyIEs[WLAN_BEACON_FR_MAXLEN]; 142// BYTE abyIEs[WLAN_BEACON_FR_MAXLEN];
143 unsigned int uIELength; 143 unsigned int uIELength;
144 QWORD qwBSSTimestamp; 144 u64 qwBSSTimestamp;
145 QWORD qwLocalTSF; // local TSF timer 145 u64 qwLocalTSF;/* local TSF timer */
146 146
147 CARD_PHY_TYPE eNetworkTypeInUse; 147 CARD_PHY_TYPE eNetworkTypeInUse;
148 148
@@ -167,14 +167,14 @@ typedef enum tagNODE_STATE {
167// STA node info 167// STA node info
168typedef struct tagKnownNodeDB { 168typedef struct tagKnownNodeDB {
169 // STA info 169 // STA info
170 BOOL bActive; 170 bool bActive;
171 BYTE abyMACAddr[WLAN_ADDR_LEN]; 171 BYTE abyMACAddr[WLAN_ADDR_LEN];
172 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN]; 172 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
173 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN]; 173 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
174 WORD wTxDataRate; 174 WORD wTxDataRate;
175 BOOL bShortPreamble; 175 bool bShortPreamble;
176 BOOL bERPExist; 176 bool bERPExist;
177 BOOL bShortSlotTime; 177 bool bShortSlotTime;
178 unsigned int uInActiveCount; 178 unsigned int uInActiveCount;
179 WORD wMaxBasicRate; //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp. 179 WORD wMaxBasicRate; //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
180 WORD wMaxSuppRate; //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon. 180 WORD wMaxSuppRate; //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
@@ -188,15 +188,15 @@ typedef struct tagKnownNodeDB {
188 WORD wListenInterval; 188 WORD wListenInterval;
189 WORD wAID; 189 WORD wAID;
190 NODE_STATE eNodeState; 190 NODE_STATE eNodeState;
191 BOOL bPSEnable; 191 bool bPSEnable;
192 BOOL bRxPSPoll; 192 bool bRxPSPoll;
193 BYTE byAuthSequence; 193 BYTE byAuthSequence;
194 unsigned long ulLastRxJiffer; 194 unsigned long ulLastRxJiffer;
195 BYTE bySuppRate; 195 BYTE bySuppRate;
196 DWORD dwFlags; 196 DWORD dwFlags;
197 WORD wEnQueueCnt; 197 WORD wEnQueueCnt;
198 198
199 BOOL bOnFly; 199 bool bOnFly;
200 unsigned long long KeyRSC; 200 unsigned long long KeyRSC;
201 BYTE byKeyIndex; 201 BYTE byKeyIndex;
202 DWORD dwKeyIndex; 202 DWORD dwKeyIndex;
@@ -207,7 +207,7 @@ typedef struct tagKnownNodeDB {
207 BYTE abyWepKey[WLAN_WEPMAX_KEYLEN]; 207 BYTE abyWepKey[WLAN_WEPMAX_KEYLEN];
208 // 208 //
209 // Auto rate fallback vars 209 // Auto rate fallback vars
210 BOOL bIsInFallback; 210 bool bIsInFallback;
211 unsigned int uAverageRSSI; 211 unsigned int uAverageRSSI;
212 unsigned int uRateRecoveryTimeout; 212 unsigned int uRateRecoveryTimeout;
213 unsigned int uRatePollTimeout; 213 unsigned int uRatePollTimeout;
@@ -225,80 +225,70 @@ typedef struct tagKnownNodeDB {
225 225
226/*--------------------- Export Functions --------------------------*/ 226/*--------------------- Export Functions --------------------------*/
227 227
228PKnownBSS BSSpSearchBSSList(void *hDeviceContext, 228PKnownBSS BSSpSearchBSSList(struct vnt_private *, u8 *pbyDesireBSSID,
229 PBYTE pbyDesireBSSID, 229 u8 *pbyDesireSSID, CARD_PHY_TYPE ePhyType);
230 PBYTE pbyDesireSSID, 230
231 CARD_PHY_TYPE ePhyType); 231PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *, u8 *abyBSSID,
232 232 PWLAN_IE_SSID pSSID);
233PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext, 233
234 PBYTE abyBSSID, 234void BSSvClearBSSList(struct vnt_private *, int bKeepCurrBSSID);
235 PWLAN_IE_SSID pSSID); 235
236 236int BSSbInsertToBSSList(struct vnt_private *,
237void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID); 237 u8 *abyBSSIDAddr,
238 238 u64 qwTimestamp,
239BOOL BSSbInsertToBSSList(void *hDeviceContext, 239 u16 wBeaconInterval,
240 PBYTE abyBSSIDAddr, 240 u16 wCapInfo,
241 QWORD qwTimestamp, 241 u8 byCurrChannel,
242 WORD wBeaconInterval, 242 PWLAN_IE_SSID pSSID,
243 WORD wCapInfo, 243 PWLAN_IE_SUPP_RATES pSuppRates,
244 BYTE byCurrChannel, 244 PWLAN_IE_SUPP_RATES pExtSuppRates,
245 PWLAN_IE_SSID pSSID, 245 PERPObject psERP,
246 PWLAN_IE_SUPP_RATES pSuppRates, 246 PWLAN_IE_RSN pRSN,
247 PWLAN_IE_SUPP_RATES pExtSuppRates, 247 PWLAN_IE_RSN_EXT pRSNWPA,
248 PERPObject psERP, 248 PWLAN_IE_COUNTRY pIE_Country,
249 PWLAN_IE_RSN pRSN, 249 PWLAN_IE_QUIET pIE_Quiet,
250 PWLAN_IE_RSN_EXT pRSNWPA, 250 u32 uIELength,
251 PWLAN_IE_COUNTRY pIE_Country, 251 u8 *pbyIEs,
252 PWLAN_IE_QUIET pIE_Quiet, 252 void *pRxPacketContext);
253 unsigned int uIELength, 253
254 PBYTE pbyIEs, 254int BSSbUpdateToBSSList(struct vnt_private *,
255 void *pRxPacketContext); 255 u64 qwTimestamp,
256 256 u16 wBeaconInterval,
257BOOL BSSbUpdateToBSSList(void *hDeviceContext, 257 u16 wCapInfo,
258 QWORD qwTimestamp, 258 u8 byCurrChannel,
259 WORD wBeaconInterval, 259 int bChannelHit,
260 WORD wCapInfo, 260 PWLAN_IE_SSID pSSID,
261 BYTE byCurrChannel, 261 PWLAN_IE_SUPP_RATES pSuppRates,
262 BOOL bChannelHit, 262 PWLAN_IE_SUPP_RATES pExtSuppRates,
263 PWLAN_IE_SSID pSSID, 263 PERPObject psERP,
264 PWLAN_IE_SUPP_RATES pSuppRates, 264 PWLAN_IE_RSN pRSN,
265 PWLAN_IE_SUPP_RATES pExtSuppRates, 265 PWLAN_IE_RSN_EXT pRSNWPA,
266 PERPObject psERP, 266 PWLAN_IE_COUNTRY pIE_Country,
267 PWLAN_IE_RSN pRSN, 267 PWLAN_IE_QUIET pIE_Quiet,
268 PWLAN_IE_RSN_EXT pRSNWPA, 268 PKnownBSS pBSSList,
269 PWLAN_IE_COUNTRY pIE_Country, 269 u32 uIELength,
270 PWLAN_IE_QUIET pIE_Quiet, 270 u8 *pbyIEs,
271 PKnownBSS pBSSList, 271 void *pRxPacketContext);
272 unsigned int uIELength, 272
273 PBYTE pbyIEs, 273int BSSbIsSTAInNodeDB(struct vnt_private *, PBYTE abyDstAddr,
274 void *pRxPacketContext); 274 u32 *puNodeIndex);
275 275
276BOOL BSSbIsSTAInNodeDB(void *hDeviceContext, 276void BSSvCreateOneNode(struct vnt_private *, u32 *puNodeIndex);
277 PBYTE abyDstAddr, 277
278 unsigned int *puNodeIndex); 278void BSSvUpdateAPNode(struct vnt_private *, u16 *pwCapInfo,
279 279 PWLAN_IE_SUPP_RATES pItemRates, PWLAN_IE_SUPP_RATES pExtSuppRates);
280void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex); 280
281 281void BSSvSecondCallBack(struct vnt_private *);
282void BSSvUpdateAPNode(void *hDeviceContext, 282
283 PWORD pwCapInfo, 283void BSSvUpdateNodeTxCounter(struct vnt_private *, PSStatCounter pStatistic,
284 PWLAN_IE_SUPP_RATES pItemRates, 284 u8 byTSR, u8 byPktNO);
285 PWLAN_IE_SUPP_RATES pExtSuppRates); 285
286 286void BSSvRemoveOneNode(struct vnt_private *, u32 uNodeIndex);
287void BSSvSecondCallBack(void *hDeviceContext); 287
288 288void BSSvAddMulticastNode(struct vnt_private *);
289void BSSvUpdateNodeTxCounter(void *hDeviceContext, 289
290 PSStatCounter pStatistic, 290void BSSvClearNodeDBTable(struct vnt_private *, u32 uStartIndex);
291 BYTE byTSR, 291
292 BYTE byPktNO); 292void BSSvClearAnyBSSJoinRecord(struct vnt_private *);
293
294void BSSvRemoveOneNode(void *hDeviceContext,
295 unsigned int uNodeIndex);
296
297void BSSvAddMulticastNode(void *hDeviceContext);
298
299void BSSvClearNodeDBTable(void *hDeviceContext,
300 unsigned int uStartIndex);
301
302void BSSvClearAnyBSSJoinRecord(void *hDeviceContext);
303 293
304#endif /* __BSSDB_H__ */ 294#endif /* __BSSDB_H__ */
diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index 826520b03383..22918a106d73 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -45,6 +45,7 @@
45 * 45 *
46 */ 46 */
47 47
48#include "device.h"
48#include "tmacro.h" 49#include "tmacro.h"
49#include "card.h" 50#include "card.h"
50#include "baseband.h" 51#include "baseband.h"
@@ -91,9 +92,8 @@ const WORD cwRXBCNTSFOff[MAX_RATE] =
91 * Out: 92 * Out:
92 * none 93 * none
93 */ 94 */
94void CARDbSetMediaChannel(void *pDeviceHandler, unsigned int uConnectionChannel) 95void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel)
95{ 96{
96PSDevice pDevice = (PSDevice) pDeviceHandler;
97 97
98 if (pDevice->byBBType == BB_TYPE_11A) { // 15 ~ 38 98 if (pDevice->byBBType == BB_TYPE_11A) { // 15 ~ 38
99 if ((uConnectionChannel < (CB_MAX_CHANNEL_24G+1)) || (uConnectionChannel > CB_MAX_CHANNEL)) 99 if ((uConnectionChannel < (CB_MAX_CHANNEL_24G+1)) || (uConnectionChannel > CB_MAX_CHANNEL))
@@ -149,17 +149,17 @@ PSDevice pDevice = (PSDevice) pDeviceHandler;
149 * Return Value: response Control frame rate 149 * Return Value: response Control frame rate
150 * 150 *
151 */ 151 */
152static WORD swGetCCKControlRate(void *pDeviceHandler, WORD wRateIdx) 152static u16 swGetCCKControlRate(struct vnt_private *pDevice, u16 wRateIdx)
153{ 153{
154 PSDevice pDevice = (PSDevice) pDeviceHandler; 154 u16 ui = wRateIdx;
155 unsigned int ui = (unsigned int)wRateIdx; 155
156 while (ui > RATE_1M) { 156 while (ui > RATE_1M) {
157 if (pDevice->wBasicRate & ((WORD)1 << ui)) { 157 if (pDevice->wBasicRate & (1 << ui))
158 return (WORD)ui; 158 return ui;
159 } 159 ui--;
160 ui --; 160 }
161 } 161
162 return (WORD)RATE_1M; 162 return RATE_1M;
163} 163}
164 164
165/* 165/*
@@ -175,28 +175,33 @@ static WORD swGetCCKControlRate(void *pDeviceHandler, WORD wRateIdx)
175 * Return Value: response Control frame rate 175 * Return Value: response Control frame rate
176 * 176 *
177 */ 177 */
178static WORD swGetOFDMControlRate(void *pDeviceHandler, WORD wRateIdx) 178static u16 swGetOFDMControlRate(struct vnt_private *pDevice, u16 wRateIdx)
179{ 179{
180 PSDevice pDevice = (PSDevice) pDeviceHandler; 180 u16 ui = wRateIdx;
181 unsigned int ui = (unsigned int)wRateIdx; 181
182 182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n",
183 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate); 183 pDevice->wBasicRate);
184 184
185 if (!CARDbIsOFDMinBasicRate(pDevice)) { 185 if (!CARDbIsOFDMinBasicRate(pDevice)) {
186 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx); 186 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
187 if (wRateIdx > RATE_24M) 187 "swGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
188 wRateIdx = RATE_24M; 188 if (wRateIdx > RATE_24M)
189 return wRateIdx; 189 wRateIdx = RATE_24M;
190 } 190 return wRateIdx;
191 while (ui > RATE_11M) { 191 }
192 if (pDevice->wBasicRate & ((WORD)1 << ui)) { 192
193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate : %d\n", ui); 193 while (ui > RATE_11M) {
194 return (WORD)ui; 194 if (pDevice->wBasicRate & (1 << ui)) {
195 } 195 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
196 ui --; 196 "swGetOFDMControlRate: %d\n", ui);
197 } 197 return ui;
198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n"); 198 }
199 return (WORD)RATE_24M; 199 ui--;
200 }
201
202 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"swGetOFDMControlRate: 6M\n");
203
204 return RATE_24M;
200} 205}
201 206
202/* 207/*
@@ -325,16 +330,15 @@ CARDvCalculateOFDMRParameter (
325 * Return Value: None. 330 * Return Value: None.
326 * 331 *
327 */ 332 */
328void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType) 333void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType)
329{ 334{
330 PSDevice pDevice = (PSDevice) pDeviceHandler; 335 u8 abyServ[4] = {0, 0, 0, 0}; /* For CCK */
331 BYTE abyServ[4] = {0,0,0,0}; // For CCK 336 u8 abySignal[4] = {0, 0, 0, 0};
332 BYTE abySignal[4] = {0,0,0,0}; 337 u16 awLen[4] = {0, 0, 0, 0};
333 WORD awLen[4] = {0,0,0,0}; 338 u8 abyTxRate[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; /* For OFDM */
334 BYTE abyTxRate[9] = {0,0,0,0,0,0,0,0,0}; // For OFDM 339 u8 abyRsvTime[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
335 BYTE abyRsvTime[9] = {0,0,0,0,0,0,0,0,0}; 340 u8 abyData[34];
336 BYTE abyData[34]; 341 int i;
337 int i;
338 342
339 //RSPINF_b_1 343 //RSPINF_b_1
340 BBvCalculateParameter(pDevice, 344 BBvCalculateParameter(pDevice,
@@ -476,12 +480,10 @@ void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType)
476 * Return Value: None. 480 * Return Value: None.
477 * 481 *
478 */ 482 */
479void vUpdateIFS(void *pDeviceHandler) 483void vUpdateIFS(struct vnt_private *pDevice)
480{ 484{
481 PSDevice pDevice = (PSDevice) pDeviceHandler; 485 u8 byMaxMin = 0;
482 //Set SIFS, DIFS, EIFS, SlotTime, CwMin 486 u8 byData[4];
483 BYTE byMaxMin = 0;
484 BYTE byData[4];
485 487
486 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a 488 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
487 pDevice->uSlot = C_SLOT_SHORT; 489 pDevice->uSlot = C_SLOT_SHORT;
@@ -499,7 +501,7 @@ void vUpdateIFS(void *pDeviceHandler)
499 } 501 }
500 else {// PK_TYPE_11GA & PK_TYPE_11GB 502 else {// PK_TYPE_11GA & PK_TYPE_11GB
501 BYTE byRate = 0; 503 BYTE byRate = 0;
502 BOOL bOFDMRate = FALSE; 504 bool bOFDMRate = false;
503 unsigned int ii = 0; 505 unsigned int ii = 0;
504 PWLAN_IE_SUPP_RATES pItemRates = NULL; 506 PWLAN_IE_SUPP_RATES pItemRates = NULL;
505 507
@@ -511,25 +513,26 @@ void vUpdateIFS(void *pDeviceHandler)
511 } 513 }
512 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot; 514 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
513 515
514 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrSuppRates; 516 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt.abyCurrSuppRates;
515 for (ii = 0; ii < pItemRates->len; ii++) { 517 for (ii = 0; ii < pItemRates->len; ii++) {
516 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); 518 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
517 if (RATEwGetRateIdx(byRate) > RATE_11M) { 519 if (RATEwGetRateIdx(byRate) > RATE_11M) {
518 bOFDMRate = TRUE; 520 bOFDMRate = true;
519 break; 521 break;
520 } 522 }
521 } 523 }
522 if (bOFDMRate == FALSE) { 524 if (bOFDMRate == false) {
523 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->sMgmtObj.abyCurrExtSuppRates; 525 pItemRates = (PWLAN_IE_SUPP_RATES)pDevice->vnt_mgmt
526 .abyCurrExtSuppRates;
524 for (ii = 0; ii < pItemRates->len; ii++) { 527 for (ii = 0; ii < pItemRates->len; ii++) {
525 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F); 528 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
526 if (RATEwGetRateIdx(byRate) > RATE_11M) { 529 if (RATEwGetRateIdx(byRate) > RATE_11M) {
527 bOFDMRate = TRUE; 530 bOFDMRate = true;
528 break; 531 break;
529 } 532 }
530 } 533 }
531 } 534 }
532 if (bOFDMRate == TRUE) { 535 if (bOFDMRate == true) {
533 pDevice->uCwMin = C_CWMIN_A; 536 pDevice->uCwMin = C_CWMIN_A;
534 byMaxMin = 4; 537 byMaxMin = 4;
535 } else { 538 } else {
@@ -561,11 +564,10 @@ void vUpdateIFS(void *pDeviceHandler)
561 &byMaxMin); 564 &byMaxMin);
562} 565}
563 566
564void CARDvUpdateBasicTopRate(void *pDeviceHandler) 567void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
565{ 568{
566PSDevice pDevice = (PSDevice) pDeviceHandler; 569 u8 byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
567BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M; 570 u8 ii;
568BYTE ii;
569 571
570 //Determines the highest basic rate. 572 //Determines the highest basic rate.
571 for (ii = RATE_54M; ii >= RATE_6M; ii --) { 573 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
@@ -597,13 +599,12 @@ BYTE ii;
597 * Out: 599 * Out:
598 * none 600 * none
599 * 601 *
600 * Return Value: TRUE if succeeded; FALSE if failed. 602 * Return Value: true if succeeded; false if failed.
601 * 603 *
602 */ 604 */
603void CARDbAddBasicRate(void *pDeviceHandler, WORD wRateIdx) 605void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx)
604{ 606{
605PSDevice pDevice = (PSDevice) pDeviceHandler; 607 u16 wRate = (1 << wRateIdx);
606WORD wRate = (WORD)(1<<wRateIdx);
607 608
608 pDevice->wBasicRate |= wRate; 609 pDevice->wBasicRate |= wRate;
609 610
@@ -611,21 +612,19 @@ WORD wRate = (WORD)(1<<wRateIdx);
611 CARDvUpdateBasicTopRate(pDevice); 612 CARDvUpdateBasicTopRate(pDevice);
612} 613}
613 614
614BOOL CARDbIsOFDMinBasicRate(void *pDeviceHandler) 615int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
615{ 616{
616PSDevice pDevice = (PSDevice) pDeviceHandler; 617 int ii;
617int ii;
618 618
619 for (ii = RATE_54M; ii >= RATE_6M; ii --) { 619 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
620 if ((pDevice->wBasicRate) & ((WORD)(1<<ii))) 620 if ((pDevice->wBasicRate) & ((WORD)(1<<ii)))
621 return TRUE; 621 return true;
622 } 622 }
623 return FALSE; 623 return false;
624} 624}
625 625
626BYTE CARDbyGetPktType(void *pDeviceHandler) 626u8 CARDbyGetPktType(struct vnt_private *pDevice)
627{ 627{
628 PSDevice pDevice = (PSDevice) pDeviceHandler;
629 628
630 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) { 629 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
631 return (BYTE)pDevice->byBBType; 630 return (BYTE)pDevice->byBBType;
@@ -654,28 +653,18 @@ BYTE CARDbyGetPktType(void *pDeviceHandler)
654 * Return Value: TSF Offset value 653 * Return Value: TSF Offset value
655 * 654 *
656 */ 655 */
657QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2) 656u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2)
658{ 657{
659 QWORD qwTSFOffset; 658 u64 qwTSFOffset = 0;
660 WORD wRxBcnTSFOffst = 0; 659 WORD wRxBcnTSFOffst = 0;
661 660
662 HIDWORD(qwTSFOffset) = 0; 661 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate % MAX_RATE];
663 LODWORD(qwTSFOffset) = 0;
664 662
665 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE]; 663 qwTSF2 += (u64)wRxBcnTSFOffst;
666 (qwTSF2).u.dwLowDword += (DWORD)(wRxBcnTSFOffst); 664
667 if ((qwTSF2).u.dwLowDword < (DWORD)(wRxBcnTSFOffst)) { 665 qwTSFOffset = qwTSF1 - qwTSF2;
668 (qwTSF2).u.dwHighDword++; 666
669 } 667 return qwTSFOffset;
670 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
671 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
672 // if borrow needed
673 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
674 }
675 else {
676 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
677 };
678 return (qwTSFOffset);
679} 668}
680 669
681 670
@@ -695,33 +684,25 @@ QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2)
695 * Return Value: none 684 * Return Value: none
696 * 685 *
697 */ 686 */
698void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, 687void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
699 QWORD qwBSSTimestamp, QWORD qwLocalTSF) 688 u64 qwBSSTimestamp, u64 qwLocalTSF)
700{ 689{
690 u64 qwTSFOffset = 0;
691 u8 pbyData[8];
701 692
702 PSDevice pDevice = (PSDevice) pDeviceHandler;
703 QWORD qwTSFOffset;
704 DWORD dwTSFOffset1,dwTSFOffset2;
705 BYTE pbyData[8];
706
707 HIDWORD(qwTSFOffset) = 0;
708 LODWORD(qwTSFOffset) = 0;
709 693
710 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF); 694 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
711 // adjust TSF 695 // adjust TSF
712 // HW's TSF add TSF Offset reg 696 // HW's TSF add TSF Offset reg
713 dwTSFOffset1 = LODWORD(qwTSFOffset);
714 dwTSFOffset2 = HIDWORD(qwTSFOffset);
715 697
716 698 pbyData[0] = (u8)qwTSFOffset;
717 pbyData[0] = (BYTE)dwTSFOffset1; 699 pbyData[1] = (u8)(qwTSFOffset >> 8);
718 pbyData[1] = (BYTE)(dwTSFOffset1>>8); 700 pbyData[2] = (u8)(qwTSFOffset >> 16);
719 pbyData[2] = (BYTE)(dwTSFOffset1>>16); 701 pbyData[3] = (u8)(qwTSFOffset >> 24);
720 pbyData[3] = (BYTE)(dwTSFOffset1>>24); 702 pbyData[4] = (u8)(qwTSFOffset >> 32);
721 pbyData[4] = (BYTE)dwTSFOffset2; 703 pbyData[5] = (u8)(qwTSFOffset >> 40);
722 pbyData[5] = (BYTE)(dwTSFOffset2>>8); 704 pbyData[6] = (u8)(qwTSFOffset >> 48);
723 pbyData[6] = (BYTE)(dwTSFOffset2>>16); 705 pbyData[7] = (u8)(qwTSFOffset >> 56);
724 pbyData[7] = (BYTE)(dwTSFOffset2>>24);
725 706
726 CONTROLnsRequestOut(pDevice, 707 CONTROLnsRequestOut(pDevice,
727 MESSAGE_TYPE_SET_TSFTBTT, 708 MESSAGE_TYPE_SET_TSFTBTT,
@@ -742,17 +723,15 @@ void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate,
742 * Out: 723 * Out:
743 * qwCurrTSF - Current TSF counter 724 * qwCurrTSF - Current TSF counter
744 * 725 *
745 * Return Value: TRUE if success; otherwise FALSE 726 * Return Value: true if success; otherwise false
746 * 727 *
747 */ 728 */
748BOOL CARDbGetCurrentTSF(void *pDeviceHandler, PQWORD pqwCurrTSF) 729bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF)
749{ 730{
750 PSDevice pDevice = (PSDevice) pDeviceHandler;
751 731
752 LODWORD(*pqwCurrTSF) = LODWORD(pDevice->qwCurrTSF); 732 *pqwCurrTSF = pDevice->qwCurrTSF;
753 HIDWORD(*pqwCurrTSF) = HIDWORD(pDevice->qwCurrTSF);
754 733
755 return(TRUE); 734 return true;
756} 735}
757 736
758 737
@@ -764,19 +743,17 @@ BOOL CARDbGetCurrentTSF(void *pDeviceHandler, PQWORD pqwCurrTSF)
764 * In: 743 * In:
765 * pDevice - The adapter to be read 744 * pDevice - The adapter to be read
766 * 745 *
767 * Return Value: TRUE if success; otherwise FALSE 746 * Return Value: true if success; otherwise false
768 * 747 *
769 */ 748 */
770BOOL CARDbClearCurrentTSF(void *pDeviceHandler) 749bool CARDbClearCurrentTSF(struct vnt_private *pDevice)
771{ 750{
772 PSDevice pDevice = (PSDevice) pDeviceHandler;
773 751
774 MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTRST); 752 MACvRegBitsOn(pDevice, MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
775 753
776 LODWORD(pDevice->qwCurrTSF) = 0; 754 pDevice->qwCurrTSF = 0;
777 HIDWORD(pDevice->qwCurrTSF) = 0;
778 755
779 return(TRUE); 756 return true;
780} 757}
781 758
782/* 759/*
@@ -793,7 +770,7 @@ BOOL CARDbClearCurrentTSF(void *pDeviceHandler)
793 * Return Value: TSF value of next Beacon 770 * Return Value: TSF value of next Beacon
794 * 771 *
795 */ 772 */
796QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval) 773u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval)
797{ 774{
798 775
799 unsigned int uLowNextTBTT; 776 unsigned int uLowNextTBTT;
@@ -802,18 +779,19 @@ QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval)
802 779
803 uBeaconInterval = wBeaconInterval * 1024; 780 uBeaconInterval = wBeaconInterval * 1024;
804 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval 781 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
805 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10; 782 uLowNextTBTT = ((qwTSF & 0xffffffffU) >> 10) << 10;
806 uLowRemain = (uLowNextTBTT) % uBeaconInterval; 783 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
807 uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF)) 784 uHighRemain = ((0x80000000 % uBeaconInterval) * 2 * (u32)(qwTSF >> 32))
808 % uBeaconInterval; 785 % uBeaconInterval;
809 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval; 786 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
810 uLowRemain = uBeaconInterval - uLowRemain; 787 uLowRemain = uBeaconInterval - uLowRemain;
811 788
812 // check if carry when add one beacon interval 789 // check if carry when add one beacon interval
813 if ((~uLowNextTBTT) < uLowRemain) 790 if ((~uLowNextTBTT) < uLowRemain)
814 HIDWORD(qwTSF) ++ ; 791 qwTSF = ((qwTSF >> 32) + 1) << 32;
815 792
816 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain; 793 qwTSF = (qwTSF & 0xffffffff00000000UL) |
794 (u64)(uLowNextTBTT + uLowRemain);
817 795
818 return (qwTSF); 796 return (qwTSF);
819} 797}
@@ -833,32 +811,24 @@ QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval)
833 * Return Value: none 811 * Return Value: none
834 * 812 *
835 */ 813 */
836void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval) 814void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval)
837{ 815{
816 u64 qwNextTBTT = 0;
817 u8 pbyData[8];
838 818
839 PSDevice pDevice = (PSDevice) pDeviceHandler; 819 CARDbClearCurrentTSF(pDevice);
840 QWORD qwNextTBTT;
841 DWORD dwLoTBTT,dwHiTBTT;
842 BYTE pbyData[8];
843
844 HIDWORD(qwNextTBTT) = 0;
845 LODWORD(qwNextTBTT) = 0;
846 CARDbClearCurrentTSF(pDevice);
847 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter 820 //CARDbGetCurrentTSF(pDevice, &qwNextTBTT); //Get Local TSF counter
848 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); 821 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
849 // Set NextTBTT 822 // Set NextTBTT
850 823
851 dwLoTBTT = LODWORD(qwNextTBTT); 824 pbyData[0] = (u8)qwNextTBTT;
852 dwHiTBTT = HIDWORD(qwNextTBTT); 825 pbyData[1] = (u8)(qwNextTBTT >> 8);
853 826 pbyData[2] = (u8)(qwNextTBTT >> 16);
854 pbyData[0] = (BYTE)dwLoTBTT; 827 pbyData[3] = (u8)(qwNextTBTT >> 24);
855 pbyData[1] = (BYTE)(dwLoTBTT>>8); 828 pbyData[4] = (u8)(qwNextTBTT >> 32);
856 pbyData[2] = (BYTE)(dwLoTBTT>>16); 829 pbyData[5] = (u8)(qwNextTBTT >> 40);
857 pbyData[3] = (BYTE)(dwLoTBTT>>24); 830 pbyData[6] = (u8)(qwNextTBTT >> 48);
858 pbyData[4] = (BYTE)dwHiTBTT; 831 pbyData[7] = (u8)(qwNextTBTT >> 56);
859 pbyData[5] = (BYTE)(dwHiTBTT>>8);
860 pbyData[6] = (BYTE)(dwHiTBTT>>16);
861 pbyData[7] = (BYTE)(dwHiTBTT>>24);
862 832
863 CONTROLnsRequestOut(pDevice, 833 CONTROLnsRequestOut(pDevice,
864 MESSAGE_TYPE_SET_TSFTBTT, 834 MESSAGE_TYPE_SET_TSFTBTT,
@@ -887,27 +857,23 @@ void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval)
887 * Return Value: none 857 * Return Value: none
888 * 858 *
889 */ 859 */
890void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF, 860void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
891 WORD wBeaconInterval) 861 u16 wBeaconInterval)
892{ 862{
893 PSDevice pDevice = (PSDevice) pDeviceHandler; 863 u8 pbyData[8];
894 DWORD dwLoTBTT,dwHiTBTT;
895 BYTE pbyData[8];
896 864
897 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval); 865 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
898 866
899 // Set NextTBTT 867 // Set NextTBTT
900 dwLoTBTT = LODWORD(qwTSF); 868
901 dwHiTBTT = HIDWORD(qwTSF); 869 pbyData[0] = (u8)qwTSF;
902 870 pbyData[1] = (u8)(qwTSF >> 8);
903 pbyData[0] = (BYTE)dwLoTBTT; 871 pbyData[2] = (u8)(qwTSF >> 16);
904 pbyData[1] = (BYTE)(dwLoTBTT>>8); 872 pbyData[3] = (u8)(qwTSF >> 24);
905 pbyData[2] = (BYTE)(dwLoTBTT>>16); 873 pbyData[4] = (u8)(qwTSF >> 32);
906 pbyData[3] = (BYTE)(dwLoTBTT>>24); 874 pbyData[5] = (u8)(qwTSF >> 40);
907 pbyData[4] = (BYTE)dwHiTBTT; 875 pbyData[6] = (u8)(qwTSF >> 48);
908 pbyData[5] = (BYTE)(dwHiTBTT>>8); 876 pbyData[7] = (u8)(qwTSF >> 56);
909 pbyData[6] = (BYTE)(dwHiTBTT>>16);
910 pbyData[7] = (BYTE)(dwHiTBTT>>24);
911 877
912 CONTROLnsRequestOut(pDevice, 878 CONTROLnsRequestOut(pDevice,
913 MESSAGE_TYPE_SET_TSFTBTT, 879 MESSAGE_TYPE_SET_TSFTBTT,
@@ -918,7 +884,8 @@ void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF,
918 ); 884 );
919 885
920 886
921 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",(int)HIDWORD(qwTSF), (int)LODWORD(qwTSF)); 887 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
888 "Card:Update Next TBTT[%8lx]\n", (unsigned long)qwTSF);
922 889
923 return; 890 return;
924} 891}
@@ -932,18 +899,17 @@ void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF,
932 * Out: 899 * Out:
933 * none 900 * none
934 * 901 *
935 * Return Value: TRUE if success; otherwise FALSE 902 * Return Value: true if success; otherwise false
936 * 903 *
937 */ 904 */
938BOOL CARDbRadioPowerOff(void *pDeviceHandler) 905int CARDbRadioPowerOff(struct vnt_private *pDevice)
939{ 906{
940PSDevice pDevice = (PSDevice) pDeviceHandler; 907 int bResult = true;
941BOOL bResult = TRUE;
942 908
943 //if (pDevice->bRadioOff == TRUE) 909 //if (pDevice->bRadioOff == true)
944 // return TRUE; 910 // return true;
945 911
946 pDevice->bRadioOff = TRUE; 912 pDevice->bRadioOff = true;
947 913
948 switch (pDevice->byRFType) { 914 switch (pDevice->byRFType) {
949 case RF_AL2230: 915 case RF_AL2230:
@@ -973,23 +939,21 @@ BOOL bResult = TRUE;
973 * Out: 939 * Out:
974 * none 940 * none
975 * 941 *
976 * Return Value: TRUE if success; otherwise FALSE 942 * Return Value: true if success; otherwise false
977 * 943 *
978 */ 944 */
979BOOL CARDbRadioPowerOn(void *pDeviceHandler) 945int CARDbRadioPowerOn(struct vnt_private *pDevice)
980{ 946{
981PSDevice pDevice = (PSDevice) pDeviceHandler; 947 int bResult = true;
982BOOL bResult = TRUE;
983
984 948
985 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) { 949 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
986 return FALSE; 950 return false;
987 } 951 }
988 952
989 //if (pDevice->bRadioOff == FALSE) 953 //if (pDevice->bRadioOff == false)
990 // return TRUE; 954 // return true;
991 955
992 pDevice->bRadioOff = FALSE; 956 pDevice->bRadioOff = false;
993 957
994 BBvExitDeepSleep(pDevice); 958 BBvExitDeepSleep(pDevice);
995 959
@@ -1009,9 +973,8 @@ BOOL bResult = TRUE;
1009 return bResult; 973 return bResult;
1010} 974}
1011 975
1012void CARDvSetBSSMode(void *pDeviceHandler) 976void CARDvSetBSSMode(struct vnt_private *pDevice)
1013{ 977{
1014 PSDevice pDevice = (PSDevice) pDeviceHandler;
1015 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now 978 // Set BB and packet type at the same time.//{{RobertYu:20050222, AL7230 have two TX PA output, only connet to b/g now
1016 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA 979 // so in 11a mode need to set the MAC Reg0x4C to 11b/g mode to turn on PA
1017 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) ) 980 if( (pDevice->byRFType == RF_AIROHA7230 ) && (pDevice->byBBType == BB_TYPE_11A) )
@@ -1068,30 +1031,23 @@ void CARDvSetBSSMode(void *pDeviceHandler)
1068 * Return Value: none. 1031 * Return Value: none.
1069 * 1032 *
1070-*/ 1033-*/
1071BOOL 1034int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode,
1072CARDbChannelSwitch ( 1035 u8 byNewChannel, u8 byCount)
1073 void *pDeviceHandler,
1074 BYTE byMode,
1075 BYTE byNewChannel,
1076 BYTE byCount
1077 )
1078{ 1036{
1079 PSDevice pDevice = (PSDevice) pDeviceHandler; 1037 int bResult = true;
1080 BOOL bResult = TRUE;
1081 1038
1082 if (byCount == 0) { 1039 if (byCount == 0) {
1083 pDevice->sMgmtObj.uCurrChannel = byNewChannel; 1040 pDevice->vnt_mgmt.uCurrChannel = byNewChannel;
1084 CARDbSetMediaChannel(pDevice, byNewChannel); 1041 CARDbSetMediaChannel(pDevice, byNewChannel);
1085 1042 return bResult;
1086 return bResult; 1043 }
1087 }
1088 pDevice->byChannelSwitchCount = byCount; 1044 pDevice->byChannelSwitchCount = byCount;
1089 pDevice->byNewChannel = byNewChannel; 1045 pDevice->byNewChannel = byNewChannel;
1090 pDevice->bChannelSwitch = TRUE; 1046 pDevice->bChannelSwitch = true;
1091 1047
1092 if (byMode == 1) { 1048 if (byMode == 1) {
1093 //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL); 1049 //bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1094 pDevice->bStopDataPkt = TRUE; 1050 pDevice->bStopDataPkt = true;
1095 } 1051 }
1096 return bResult; 1052 return bResult;
1097} 1053}
diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h
index 55962b198831..5123bc7d0dcd 100644
--- a/drivers/staging/vt6656/card.h
+++ b/drivers/staging/vt6656/card.h
@@ -28,7 +28,7 @@
28 28
29#ifndef __CARD_H__ 29#ifndef __CARD_H__
30#define __CARD_H__ 30#define __CARD_H__
31 31#include "device.h"
32#include "ttype.h" 32#include "ttype.h"
33 33
34/*--------------------- Export Definitions -------------------------*/ 34/*--------------------- Export Definitions -------------------------*/
@@ -58,31 +58,28 @@ typedef enum _CARD_OP_MODE {
58/*--------------------- Export Variables --------------------------*/ 58/*--------------------- Export Variables --------------------------*/
59 59
60/*--------------------- Export Functions --------------------------*/ 60/*--------------------- Export Functions --------------------------*/
61struct vnt_private;
61 62
62void CARDbSetMediaChannel(void *pDeviceHandler, 63void CARDbSetMediaChannel(struct vnt_private *pDevice, u32 uConnectionChannel);
63 unsigned int uConnectionChannel); 64void CARDvSetRSPINF(struct vnt_private *pDevice, u8 byBBType);
64void CARDvSetRSPINF(void *pDeviceHandler, BYTE byBBType); 65void vUpdateIFS(struct vnt_private *pDevice);
65void vUpdateIFS(void *pDeviceHandler); 66void CARDvUpdateBasicTopRate(struct vnt_private *pDevice);
66void CARDvUpdateBasicTopRate(void *pDeviceHandler); 67void CARDbAddBasicRate(struct vnt_private *pDevice, u16 wRateIdx);
67void CARDbAddBasicRate(void *pDeviceHandler, WORD wRateIdx); 68int CARDbIsOFDMinBasicRate(struct vnt_private *pDevice);
68BOOL CARDbIsOFDMinBasicRate(void *pDeviceHandler); 69void CARDvAdjustTSF(struct vnt_private *pDevice, u8 byRxRate,
69void CARDvAdjustTSF(void *pDeviceHandler, BYTE byRxRate, 70 u64 qwBSSTimestamp, u64 qwLocalTSF);
70 QWORD qwBSSTimestamp, QWORD qwLocalTSF); 71bool CARDbGetCurrentTSF(struct vnt_private *pDevice, u64 *pqwCurrTSF);
71BOOL CARDbGetCurrentTSF(void *pDeviceHandler, PQWORD pqwCurrTSF); 72bool CARDbClearCurrentTSF(struct vnt_private *pDevice);
72BOOL CARDbClearCurrentTSF(void *pDeviceHandler); 73void CARDvSetFirstNextTBTT(struct vnt_private *pDevice, WORD wBeaconInterval);
73void CARDvSetFirstNextTBTT(void *pDeviceHandler, WORD wBeaconInterval); 74void CARDvUpdateNextTBTT(struct vnt_private *pDevice, u64 qwTSF,
74void CARDvUpdateNextTBTT(void *pDeviceHandler, QWORD qwTSF,
75 WORD wBeaconInterval); 75 WORD wBeaconInterval);
76QWORD CARDqGetNextTBTT(QWORD qwTSF, WORD wBeaconInterval); 76u64 CARDqGetNextTBTT(u64 qwTSF, WORD wBeaconInterval);
77QWORD CARDqGetTSFOffset(BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2); 77u64 CARDqGetTSFOffset(BYTE byRxRate, u64 qwTSF1, u64 qwTSF2);
78BOOL CARDbRadioPowerOff(void *pDeviceHandler); 78int CARDbRadioPowerOff(struct vnt_private *pDevice);
79BOOL CARDbRadioPowerOn(void *pDeviceHandler); 79int CARDbRadioPowerOn(struct vnt_private *pDevice);
80BYTE CARDbyGetPktType(void *pDeviceHandler); 80u8 CARDbyGetPktType(struct vnt_private *pDevice);
81void CARDvSetBSSMode(void *pDeviceHandler); 81void CARDvSetBSSMode(struct vnt_private *pDevice);
82 82int CARDbChannelSwitch(struct vnt_private *pDevice, u8 byMode,
83BOOL CARDbChannelSwitch(void *pDeviceHandler, 83 u8 byNewChannel, u8 byCount);
84 BYTE byMode,
85 BYTE byNewChannel,
86 BYTE byCount);
87 84
88#endif /* __CARD_H__ */ 85#endif /* __CARD_H__ */
diff --git a/drivers/staging/vt6656/channel.c b/drivers/staging/vt6656/channel.c
index 650217607858..4181e3e12ea9 100644
--- a/drivers/staging/vt6656/channel.c
+++ b/drivers/staging/vt6656/channel.c
@@ -50,63 +50,63 @@ static int msglevel = MSG_LEVEL_INFO;
50 50
51static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] = 51static SChannelTblElement sChannelTbl[CB_MAX_CHANNEL+1] =
52{ 52{
53 {0, 0, FALSE}, 53 {0, 0, false},
54 {1, 2412, TRUE}, 54 {1, 2412, true},
55 {2, 2417, TRUE}, 55 {2, 2417, true},
56 {3, 2422, TRUE}, 56 {3, 2422, true},
57 {4, 2427, TRUE}, 57 {4, 2427, true},
58 {5, 2432, TRUE}, 58 {5, 2432, true},
59 {6, 2437, TRUE}, 59 {6, 2437, true},
60 {7, 2442, TRUE}, 60 {7, 2442, true},
61 {8, 2447, TRUE}, 61 {8, 2447, true},
62 {9, 2452, TRUE}, 62 {9, 2452, true},
63 {10, 2457, TRUE}, 63 {10, 2457, true},
64 {11, 2462, TRUE}, 64 {11, 2462, true},
65 {12, 2467, TRUE}, 65 {12, 2467, true},
66 {13, 2472, TRUE}, 66 {13, 2472, true},
67 {14, 2484, TRUE}, 67 {14, 2484, true},
68 {183, 4915, TRUE}, //15 68 {183, 4915, true}, //15
69 {184, 4920, TRUE}, //16 69 {184, 4920, true}, //16
70 {185, 4925, TRUE}, //17 70 {185, 4925, true}, //17
71 {187, 4935, TRUE}, //18 71 {187, 4935, true}, //18
72 {188, 4940, TRUE}, //19 72 {188, 4940, true}, //19
73 {189, 4945, TRUE}, //20 73 {189, 4945, true}, //20
74 {192, 4960, TRUE}, //21 74 {192, 4960, true}, //21
75 {196, 4980, TRUE}, //22 75 {196, 4980, true}, //22
76 {7, 5035, TRUE}, //23 76 {7, 5035, true}, //23
77 {8, 5040, TRUE}, //24 77 {8, 5040, true}, //24
78 {9, 5045, TRUE}, //25 78 {9, 5045, true}, //25
79 {11, 5055, TRUE}, //26 79 {11, 5055, true}, //26
80 {12, 5060, TRUE}, //27 80 {12, 5060, true}, //27
81 {16, 5080, TRUE}, //28 81 {16, 5080, true}, //28
82 {34, 5170, TRUE}, //29 82 {34, 5170, true}, //29
83 {36, 5180, TRUE}, //30 83 {36, 5180, true}, //30
84 {38, 5190, TRUE}, //31 84 {38, 5190, true}, //31
85 {40, 5200, TRUE}, //32 85 {40, 5200, true}, //32
86 {42, 5210, TRUE}, //33 86 {42, 5210, true}, //33
87 {44, 5220, TRUE}, //34 87 {44, 5220, true}, //34
88 {46, 5230, TRUE}, //35 88 {46, 5230, true}, //35
89 {48, 5240, TRUE}, //36 89 {48, 5240, true}, //36
90 {52, 5260, TRUE}, //37 90 {52, 5260, true}, //37
91 {56, 5280, TRUE}, //38 91 {56, 5280, true}, //38
92 {60, 5300, TRUE}, //39 92 {60, 5300, true}, //39
93 {64, 5320, TRUE}, //40 93 {64, 5320, true}, //40
94 {100, 5500, TRUE}, //41 94 {100, 5500, true}, //41
95 {104, 5520, TRUE}, //42 95 {104, 5520, true}, //42
96 {108, 5540, TRUE}, //43 96 {108, 5540, true}, //43
97 {112, 5560, TRUE}, //44 97 {112, 5560, true}, //44
98 {116, 5580, TRUE}, //45 98 {116, 5580, true}, //45
99 {120, 5600, TRUE}, //46 99 {120, 5600, true}, //46
100 {124, 5620, TRUE}, //47 100 {124, 5620, true}, //47
101 {128, 5640, TRUE}, //48 101 {128, 5640, true}, //48
102 {132, 5660, TRUE}, //49 102 {132, 5660, true}, //49
103 {136, 5680, TRUE}, //50 103 {136, 5680, true}, //50
104 {140, 5700, TRUE}, //51 104 {140, 5700, true}, //51
105 {149, 5745, TRUE}, //52 105 {149, 5745, true}, //52
106 {153, 5765, TRUE}, //53 106 {153, 5765, true}, //53
107 {157, 5785, TRUE}, //54 107 {157, 5785, true}, //54
108 {161, 5805, TRUE}, //55 108 {161, 5805, true}, //55
109 {165, 5825, TRUE} //56 109 {165, 5825, true} //56
110}; 110};
111 111
112 112
@@ -380,26 +380,26 @@ static struct
380 * 15 = 4.9G channel 183 380 * 15 = 4.9G channel 183
381 * 16 = 4.9G channel 184 381 * 16 = 4.9G channel 184
382 * ..... 382 * .....
383 * Output: TRUE if the specified 5GHz band is allowed to be used. 383 * Output: true if the specified 5GHz band is allowed to be used.
384 False otherwise. 384 False otherwise.
385// 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) 385// 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
386 386
387// 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, 387// 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
388// 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) 388// 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
389 ************************************************************************/ 389 ************************************************************************/
390BOOL 390bool
391ChannelValid(unsigned int CountryCode, unsigned int ChannelIndex) 391ChannelValid(unsigned int CountryCode, unsigned int ChannelIndex)
392{ 392{
393 BOOL bValid; 393 bool bValid;
394 394
395 bValid = FALSE; 395 bValid = false;
396 /* 396 /*
397 * If Channel Index is invalid, return invalid 397 * If Channel Index is invalid, return invalid
398 */ 398 */
399 if ((ChannelIndex > CB_MAX_CHANNEL) || 399 if ((ChannelIndex > CB_MAX_CHANNEL) ||
400 (ChannelIndex == 0)) 400 (ChannelIndex == 0))
401 { 401 {
402 bValid = FALSE; 402 bValid = false;
403 goto exit; 403 goto exit;
404 } 404 }
405 405
@@ -422,48 +422,47 @@ exit:
422 * 0x0000000000000003 means channel 1,2 are supported 422 * 0x0000000000000003 means channel 1,2 are supported
423 * 0x000000000000000F means channel 1,2,..15 are supported 423 * 0x000000000000000F means channel 1,2,..15 are supported
424 ************************************************************************/ 424 ************************************************************************/
425BOOL 425bool
426CHvChannelGetList ( 426CHvChannelGetList (
427 unsigned int uCountryCodeIdx, 427 unsigned int uCountryCodeIdx,
428 PBYTE pbyChannelTable 428 PBYTE pbyChannelTable
429 ) 429 )
430{ 430{
431 if (uCountryCodeIdx >= CCODE_MAX) { 431 if (uCountryCodeIdx >= CCODE_MAX) {
432 return (FALSE); 432 return (false);
433 } 433 }
434 memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL); 434 memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL);
435 return (TRUE); 435 return (true);
436} 436}
437 437
438 438
439void CHvInitChannelTable(void *pDeviceHandler) 439void CHvInitChannelTable(struct vnt_private *pDevice)
440{ 440{
441 PSDevice pDevice = (PSDevice) pDeviceHandler; 441 int bMultiBand = false;
442 BOOL bMultiBand = FALSE; 442 int ii;
443 unsigned int ii;
444 443
445 for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) 444 for (ii = 1; ii <= CB_MAX_CHANNEL; ii++)
446 sChannelTbl[ii].bValid = FALSE; 445 sChannelTbl[ii].bValid = false;
447 446
448 switch (pDevice->byRFType) { 447 switch (pDevice->byRFType) {
449 case RF_AL2230: 448 case RF_AL2230:
450 case RF_AL2230S: 449 case RF_AL2230S:
451 case RF_VT3226: 450 case RF_VT3226:
452 case RF_VT3226D0: 451 case RF_VT3226D0:
453 bMultiBand = FALSE; 452 bMultiBand = false;
454 break; 453 break;
455 case RF_AIROHA7230: 454 case RF_AIROHA7230:
456 case RF_VT3342A0: 455 case RF_VT3342A0:
457 default : 456 default :
458 bMultiBand = TRUE; 457 bMultiBand = true;
459 break; 458 break;
460 } 459 }
461 460
462 if ((pDevice->dwDiagRefCount != 0) || 461 if ((pDevice->dwDiagRefCount != 0) ||
463 (pDevice->b11hEable == TRUE)) { 462 (pDevice->b11hEable == true)) {
464 if (bMultiBand == TRUE) { 463 if (bMultiBand == true) {
465 for (ii = 0; ii < CB_MAX_CHANNEL; ii++) { 464 for (ii = 0; ii < CB_MAX_CHANNEL; ii++) {
466 sChannelTbl[ii+1].bValid = TRUE; 465 sChannelTbl[ii+1].bValid = true;
467 //pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1]; 466 //pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
468 //pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1]; 467 //pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
469 } 468 }
@@ -473,16 +472,16 @@ void CHvInitChannelTable(void *pDeviceHandler)
473 } 472 }
474 } else { 473 } else {
475 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) { 474 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
476 sChannelTbl[ii+1].bValid = TRUE; 475 sChannelTbl[ii+1].bValid = true;
477 //pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1]; 476 //pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
478 //pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1]; 477 //pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
479 } 478 }
480 } 479 }
481 } else if (pDevice->byZoneType <= CCODE_MAX) { 480 } else if (pDevice->byZoneType <= CCODE_MAX) {
482 if (bMultiBand == TRUE) { 481 if (bMultiBand == true) {
483 for (ii = 0; ii < CB_MAX_CHANNEL; ii++) { 482 for (ii = 0; ii < CB_MAX_CHANNEL; ii++) {
484 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) { 483 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
485 sChannelTbl[ii+1].bValid = TRUE; 484 sChannelTbl[ii+1].bValid = true;
486 //pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; 485 //pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
487 //pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; 486 //pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
488 } 487 }
@@ -490,7 +489,7 @@ void CHvInitChannelTable(void *pDeviceHandler)
490 } else { 489 } else {
491 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) { 490 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
492 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) { 491 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
493 sChannelTbl[ii+1].bValid = TRUE; 492 sChannelTbl[ii+1].bValid = true;
494 //pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; 493 //pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
495 //pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii]; 494 //pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
496 } 495 }
diff --git a/drivers/staging/vt6656/channel.h b/drivers/staging/vt6656/channel.h
index e7b3c1231825..9914dba0ba0c 100644
--- a/drivers/staging/vt6656/channel.h
+++ b/drivers/staging/vt6656/channel.h
@@ -30,6 +30,7 @@
30#ifndef _CHANNEL_H_ 30#ifndef _CHANNEL_H_
31#define _CHANNEL_H_ 31#define _CHANNEL_H_
32 32
33#include "device.h"
33#include "ttype.h" 34#include "ttype.h"
34 35
35/*--------------------- Export Definitions -------------------------*/ 36/*--------------------- Export Definitions -------------------------*/
@@ -39,17 +40,17 @@
39typedef struct tagSChannelTblElement { 40typedef struct tagSChannelTblElement {
40 BYTE byChannelNumber; 41 BYTE byChannelNumber;
41 unsigned int uFrequency; 42 unsigned int uFrequency;
42 BOOL bValid; 43 bool bValid;
43} SChannelTblElement, *PSChannelTblElement; 44} SChannelTblElement, *PSChannelTblElement;
44 45
45/*--------------------- Export Variables --------------------------*/ 46/*--------------------- Export Variables --------------------------*/
46 47
47/*--------------------- Export Functions --------------------------*/ 48/*--------------------- Export Functions --------------------------*/
48 49
49BOOL ChannelValid(unsigned int CountryCode, unsigned int ChannelNum); 50bool ChannelValid(unsigned int CountryCode, unsigned int ChannelNum);
50void CHvInitChannelTable(void *pDeviceHandler); 51void CHvInitChannelTable(struct vnt_private *pDevice);
51BYTE CHbyGetChannelMapping(BYTE byChannelNumber); 52BYTE CHbyGetChannelMapping(BYTE byChannelNumber);
52 53
53BOOL CHvChannelGetList(unsigned int uCountryCodeIdx, PBYTE pbyChannelTable); 54bool CHvChannelGetList(unsigned int uCountryCodeIdx, PBYTE pbyChannelTable);
54 55
55#endif /* _CHANNEL_H_ */ 56#endif /* _CHANNEL_H_ */
diff --git a/drivers/staging/vt6656/control.c b/drivers/staging/vt6656/control.c
index 5d8c5719419b..743ef5fb7fe7 100644
--- a/drivers/staging/vt6656/control.c
+++ b/drivers/staging/vt6656/control.c
@@ -56,43 +56,34 @@
56 56
57/*--------------------- Export Functions --------------------------*/ 57/*--------------------- Export Functions --------------------------*/
58 58
59void ControlvWriteByte(PSDevice pDevice, BYTE byRegType, BYTE byRegOfs, 59void ControlvWriteByte(struct vnt_private *pDevice, u8 reg, u8 reg_off,
60 BYTE byData) 60 u8 data)
61{ 61{
62 BYTE byData1; 62
63 byData1 = byData; 63 CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_WRITE, reg_off, reg,
64 CONTROLnsRequestOut(pDevice, 64 sizeof(u8), &data);
65 MESSAGE_TYPE_WRITE, 65
66 byRegOfs, 66 return;
67 byRegType,
68 1,
69 &byData1);
70} 67}
71 68
72void ControlvReadByte(PSDevice pDevice, BYTE byRegType, BYTE byRegOfs, 69void ControlvReadByte(struct vnt_private *pDevice, u8 reg, u8 reg_off,
73 PBYTE pbyData) 70 u8 *data)
74{ 71{
75 int ntStatus; 72 CONTROLnsRequestIn(pDevice, MESSAGE_TYPE_READ,
76 BYTE byData1; 73 reg_off, reg, sizeof(u8), data);
77 ntStatus = CONTROLnsRequestIn(pDevice, 74 return;
78 MESSAGE_TYPE_READ,
79 byRegOfs,
80 byRegType,
81 1,
82 &byData1);
83 *pbyData = byData1;
84} 75}
85 76
86void ControlvMaskByte(PSDevice pDevice, BYTE byRegType, BYTE byRegOfs, 77void ControlvMaskByte(struct vnt_private *pDevice, u8 reg_type, u8 reg_off,
87 BYTE byMask, BYTE byData) 78 u8 reg_mask, u8 data)
88{ 79{
89 BYTE pbyData[2]; 80 u8 reg_data[2];
90 pbyData[0] = byData; 81
91 pbyData[1] = byMask; 82 reg_data[0] = data;
92 CONTROLnsRequestOut(pDevice, 83 reg_data[1] = reg_mask;
93 MESSAGE_TYPE_WRITE_MASK, 84
94 byRegOfs, 85 CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_WRITE_MASK, reg_off,
95 byRegType, 86 reg_type, ARRAY_SIZE(reg_data), reg_data);
96 2, 87
97 pbyData); 88 return;
98} 89}
diff --git a/drivers/staging/vt6656/control.h b/drivers/staging/vt6656/control.h
index bbe610fd8b5a..76ce0244e100 100644
--- a/drivers/staging/vt6656/control.h
+++ b/drivers/staging/vt6656/control.h
@@ -51,28 +51,14 @@
51 51
52/*--------------------- Export Functions --------------------------*/ 52/*--------------------- Export Functions --------------------------*/
53 53
54void ControlvWriteByte( 54void ControlvWriteByte(struct vnt_private *pDevice, u8 reg, u8 reg_off,
55 PSDevice pDevice, 55 u8 data);
56 BYTE byRegType,
57 BYTE byRegOfs,
58 BYTE byData
59 );
60 56
57void ControlvReadByte(struct vnt_private *pDevice, u8 reg, u8 reg_off,
58 u8 *data);
61 59
62void ControlvReadByte( 60void ControlvMaskByte(struct vnt_private *pDevice, u8 reg_type, u8 reg_off,
63 PSDevice pDevice, 61 u8 reg_mask, u8 data);
64 BYTE byRegType,
65 BYTE byRegOfs,
66 PBYTE pbyData
67 );
68 62
69 63
70void ControlvMaskByte(
71 PSDevice pDevice,
72 BYTE byRegType,
73 BYTE byRegOfs,
74 BYTE byMask,
75 BYTE byData
76 );
77
78#endif /* __CONTROL_H__ */ 64#endif /* __CONTROL_H__ */
diff --git a/drivers/staging/vt6656/datarate.c b/drivers/staging/vt6656/datarate.c
index 5c2719fa72f7..77464e819f6d 100644
--- a/drivers/staging/vt6656/datarate.c
+++ b/drivers/staging/vt6656/datarate.c
@@ -54,7 +54,8 @@
54 54
55 55
56/*--------------------- Static Variables --------------------------*/ 56/*--------------------- Static Variables --------------------------*/
57//static int msglevel =MSG_LEVEL_DEBUG; 57
58/* static int msglevel = MSG_LEVEL_DEBUG; */
58static int msglevel =MSG_LEVEL_INFO; 59static int msglevel =MSG_LEVEL_INFO;
59const BYTE acbyIERate[MAX_RATE] = 60const BYTE acbyIERate[MAX_RATE] =
60{0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; 61{0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
@@ -71,7 +72,7 @@ void s_vResetCounter(PKnownNodeDB psNodeDBTable)
71{ 72{
72 BYTE ii; 73 BYTE ii;
73 74
74 // clear statistic counter for auto_rate 75 /* clear statistics counter for auto_rate */
75 for (ii = 0; ii <= MAX_RATE; ii++) { 76 for (ii = 0; ii <= MAX_RATE; ii++) {
76 psNodeDBTable->uTxOk[ii] = 0; 77 psNodeDBTable->uTxOk[ii] = 0;
77 psNodeDBTable->uTxFail[ii] = 0; 78 psNodeDBTable->uTxFail[ii] = 0;
@@ -105,8 +106,8 @@ DATARATEbyGetRateIdx (
105{ 106{
106 BYTE ii; 107 BYTE ii;
107 108
108 //Erase basicRate flag. 109 /* erase BasicRate flag */
109 byRate = byRate & 0x7F;//0111 1111 110 byRate = byRate & 0x7F;
110 111
111 for (ii = 0; ii < MAX_RATE; ii ++) { 112 for (ii = 0; ii < MAX_RATE; ii ++) {
112 if (acbyIERate[ii] == byRate) 113 if (acbyIERate[ii] == byRate)
@@ -159,8 +160,8 @@ RATEwGetRateIdx(
159{ 160{
160 WORD ii; 161 WORD ii;
161 162
162 //Erase basicRate flag. 163 /* erase BasicRate flag */
163 byRate = byRate & 0x7F;//0111 1111 164 byRate = byRate & 0x7F;
164 165
165 for (ii = 0; ii < MAX_RATE; ii ++) { 166 for (ii = 0; ii < MAX_RATE; ii ++) {
166 if (acbyIERate[ii] == byRate) 167 if (acbyIERate[ii] == byRate)
@@ -188,28 +189,19 @@ RATEwGetRateIdx(
188 * Return Value: none 189 * Return Value: none
189 * 190 *
190-*/ 191-*/
191void RATEvParseMaxRate(
192 void *pDeviceHandler,
193 PWLAN_IE_SUPP_RATES pItemRates,
194 PWLAN_IE_SUPP_RATES pItemExtRates,
195 BOOL bUpdateBasicRate,
196 PWORD pwMaxBasicRate,
197 PWORD pwMaxSuppRate,
198 PWORD pwSuppRate,
199 PBYTE pbyTopCCKRate,
200 PBYTE pbyTopOFDMRate
201 )
202{
203PSDevice pDevice = (PSDevice) pDeviceHandler;
204unsigned int ii;
205BYTE byHighSuppRate = 0;
206BYTE byRate = 0;
207WORD wOldBasicRate = pDevice->wBasicRate;
208unsigned int uRateLen;
209 192
193void RATEvParseMaxRate(struct vnt_private *pDevice,
194 PWLAN_IE_SUPP_RATES pItemRates, PWLAN_IE_SUPP_RATES pItemExtRates,
195 int bUpdateBasicRate, u16 *pwMaxBasicRate, u16 *pwMaxSuppRate,
196 u16 *pwSuppRate, u8 *pbyTopCCKRate, u8 *pbyTopOFDMRate)
197{
198 int ii;
199 u8 byHighSuppRate = 0, byRate = 0;
200 u16 wOldBasicRate = pDevice->wBasicRate;
201 u32 uRateLen;
210 202
211 if (pItemRates == NULL) 203 if (pItemRates == NULL)
212 return; 204 return;
213 205
214 *pwSuppRate = 0; 206 *pwSuppRate = 0;
215 uRateLen = pItemRates->len; 207 uRateLen = pItemRates->len;
@@ -226,8 +218,11 @@ unsigned int uRateLen;
226 for (ii = 0; ii < uRateLen; ii++) { 218 for (ii = 0; ii < uRateLen; ii++) {
227 byRate = (BYTE)(pItemRates->abyRates[ii]); 219 byRate = (BYTE)(pItemRates->abyRates[ii]);
228 if (WLAN_MGMT_IS_BASICRATE(byRate) && 220 if (WLAN_MGMT_IS_BASICRATE(byRate) &&
229 (bUpdateBasicRate == TRUE)) { 221 (bUpdateBasicRate == true)) {
230 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate 222 /*
223 * add to basic rate set, update pDevice->byTopCCKBasicRate and
224 * pDevice->byTopOFDMBasicRate
225 */
231 CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate)); 226 CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate));
232 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate)); 227 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate));
233 } 228 }
@@ -248,9 +243,12 @@ unsigned int uRateLen;
248 243
249 for (ii = 0; ii < uExtRateLen ; ii++) { 244 for (ii = 0; ii < uExtRateLen ; ii++) {
250 byRate = (BYTE)(pItemExtRates->abyRates[ii]); 245 byRate = (BYTE)(pItemExtRates->abyRates[ii]);
251 // select highest basic rate 246 /* select highest basic rate */
252 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) { 247 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
253 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate 248 /*
249 * add to basic rate set, update pDevice->byTopCCKBasicRate and
250 * pDevice->byTopOFDMBasicRate
251 */
254 CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate)); 252 CARDbAddBasicRate((void *)pDevice, RATEwGetRateIdx(byRate));
255 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate)); 253 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate));
256 } 254 }
@@ -260,9 +258,11 @@ unsigned int uRateLen;
260 if (byRate > byHighSuppRate) 258 if (byRate > byHighSuppRate)
261 byHighSuppRate = byRate; 259 byHighSuppRate = byRate;
262 *pwSuppRate |= (1<<RATEwGetRateIdx(byRate)); 260 *pwSuppRate |= (1<<RATEwGetRateIdx(byRate));
263 //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", RATEwGetRateIdx(byRate), byRate)); 261
262 /* DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n",
263 RATEwGetRateIdx(byRate), byRate)); */
264 } 264 }
265 } //if(pItemExtRates != NULL) 265 }
266 266
267 if ((pDevice->byPacketType == PK_TYPE_11GB) 267 if ((pDevice->byPacketType == PK_TYPE_11GB)
268 && CARDbIsOFDMinBasicRate((void *)pDevice)) { 268 && CARDbIsOFDMinBasicRate((void *)pDevice)) {
@@ -301,27 +301,24 @@ unsigned int uRateLen;
301#define AUTORATE_TXCNT_THRESHOLD 20 301#define AUTORATE_TXCNT_THRESHOLD 20
302#define AUTORATE_INC_THRESHOLD 30 302#define AUTORATE_INC_THRESHOLD 30
303 303
304void 304void RATEvTxRateFallBack(struct vnt_private *pDevice,
305RATEvTxRateFallBack( 305 PKnownNodeDB psNodeDBTable)
306 void *pDeviceHandler,
307 PKnownNodeDB psNodeDBTable
308 )
309{ 306{
310PSDevice pDevice = (PSDevice) pDeviceHandler; 307 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
311PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 308 u16 wIdxDownRate = 0;
312WORD wIdxDownRate = 0; 309 int ii;
313unsigned int ii; 310 int bAutoRate[MAX_RATE] = {true, true, true, true, false, false, true,
314BOOL bAutoRate[MAX_RATE] = {TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE}; 311 true, true, true, true, true};
315DWORD dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540}; 312 u32 dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180,
316DWORD dwThroughput = 0; 313 240, 360, 480, 540};
317WORD wIdxUpRate = 0; 314 u32 dwThroughput = 0;
318DWORD dwTxDiff = 0; 315 u16 wIdxUpRate = 0;
319 316 u32 dwTxDiff = 0;
320 if (pMgmt->eScanState != WMAC_NO_SCANNING) { 317
321 // Don't do Fallback when scanning Channel 318 if (pMgmt->eScanState != WMAC_NO_SCANNING)
322 return; 319 return; /* Don't do Fallback when scanning Channel */
323 } 320
324 psNodeDBTable->uTimeCount ++; 321 psNodeDBTable->uTimeCount++;
325 322
326 if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE]) 323 if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
327 dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE]; 324 dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
@@ -338,11 +335,11 @@ DWORD dwTxDiff = 0;
338 335
339 for (ii = 0; ii < MAX_RATE; ii++) { 336 for (ii = 0; ii < MAX_RATE; ii++) {
340 if (psNodeDBTable->wSuppRate & (0x0001<<ii)) { 337 if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
341 if (bAutoRate[ii] == TRUE) { 338 if (bAutoRate[ii] == true) {
342 wIdxUpRate = (WORD) ii; 339 wIdxUpRate = (WORD) ii;
343 } 340 }
344 } else { 341 } else {
345 bAutoRate[ii] = FALSE; 342 bAutoRate[ii] = false;
346 } 343 }
347 } 344 }
348 345
@@ -364,7 +361,7 @@ DWORD dwTxDiff = 0;
364 for (ii = psNodeDBTable->wTxDataRate; ii > 0;) { 361 for (ii = psNodeDBTable->wTxDataRate; ii > 0;) {
365 ii--; 362 ii--;
366 if ( (dwThroughputTbl[ii] > dwThroughput) && 363 if ( (dwThroughputTbl[ii] > dwThroughput) &&
367 (bAutoRate[ii]==TRUE) ) { 364 (bAutoRate[ii]==true) ) {
368 dwThroughput = dwThroughputTbl[ii]; 365 dwThroughput = dwThroughputTbl[ii];
369 wIdxDownRate = (WORD) ii; 366 wIdxDownRate = (WORD) ii;
370 } 367 }
@@ -375,7 +372,7 @@ DWORD dwTxDiff = 0;
375 (psNodeDBTable->uTxFail[MAX_RATE] * 4) ) { 372 (psNodeDBTable->uTxFail[MAX_RATE] * 4) ) {
376 psNodeDBTable->wTxDataRate = wIdxUpRate; 373 psNodeDBTable->wTxDataRate = wIdxUpRate;
377 } 374 }
378 }else { // adhoc, if uTxOk(total) =0 & uTxFail(total) = 0 375 } else { /* adhoc, if uTxOk(total) == 0 & uTxFail(total) == 0 */
379 if (psNodeDBTable->uTxFail[MAX_RATE] == 0) 376 if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
380 psNodeDBTable->wTxDataRate = wIdxUpRate; 377 psNodeDBTable->wTxDataRate = wIdxUpRate;
381 } 378 }
diff --git a/drivers/staging/vt6656/datarate.h b/drivers/staging/vt6656/datarate.h
index c6f5163ff9b8..8dc55bd61669 100644
--- a/drivers/staging/vt6656/datarate.h
+++ b/drivers/staging/vt6656/datarate.h
@@ -29,18 +29,18 @@
29#ifndef __DATARATE_H__ 29#ifndef __DATARATE_H__
30#define __DATARATE_H__ 30#define __DATARATE_H__
31 31
32/*--------------------- Export Definitions -------------------------*/
33 32
34#define FALLBACK_PKT_COLLECT_TR_H 50 // pkts 33/*--------------------- Export Definitions -------------------------*/
35#define FALLBACK_PKT_COLLECT_TR_L 10 // pkts
36#define FALLBACK_POLL_SECOND 5 // 5 sec
37#define FALLBACK_RECOVER_SECOND 30 // 30 sec
38#define FALLBACK_THRESHOLD 15 // percent
39#define UPGRADE_THRESHOLD 5 // percent
40#define UPGRADE_CNT_THRD 3 // times
41#define RETRY_TIMES_THRD_H 2 // times
42#define RETRY_TIMES_THRD_L 1 // times
43 34
35#define FALLBACK_PKT_COLLECT_TR_H 50 /* pkts */
36#define FALLBACK_PKT_COLLECT_TR_L 10 /* pkts */
37#define FALLBACK_POLL_SECOND 5 /* 5 sec */
38#define FALLBACK_RECOVER_SECOND 30 /* 30 sec */
39#define FALLBACK_THRESHOLD 15 /* percent */
40#define UPGRADE_THRESHOLD 5 /* percent */
41#define UPGRADE_CNT_THRD 3 /* times */
42#define RETRY_TIMES_THRD_H 2 /* times */
43#define RETRY_TIMES_THRD_L 1 /* times */
44 44
45#define RATE_1M 0 45#define RATE_1M 0
46#define RATE_2M 1 46#define RATE_2M 1
@@ -69,24 +69,13 @@
69 69
70 70
71 71
72void 72void RATEvParseMaxRate(struct vnt_private *, PWLAN_IE_SUPP_RATES pItemRates,
73RATEvParseMaxRate( 73 PWLAN_IE_SUPP_RATES pItemExtRates, int bUpdateBasicRate,
74 void *pDeviceHandler, 74 u16 *pwMaxBasicRate, u16 *pwMaxSuppRate, u16 *pwSuppRate,
75 PWLAN_IE_SUPP_RATES pItemRates, 75 u8 *pbyTopCCKRate, u8 *pbyTopOFDMRate);
76 PWLAN_IE_SUPP_RATES pItemExtRates,
77 BOOL bUpdateBasicRate,
78 PWORD pwMaxBasicRate,
79 PWORD pwMaxSuppRate,
80 PWORD pwSuppRate,
81 PBYTE pbyTopCCKRate,
82 PBYTE pbyTopOFDMRate
83 );
84 76
85void 77void RATEvTxRateFallBack(struct vnt_private *pDevice,
86RATEvTxRateFallBack( 78 PKnownNodeDB psNodeDBTable);
87 void *pDeviceHandler,
88 PKnownNodeDB psNodeDBTable
89 );
90 79
91BYTE 80BYTE
92RATEuSetIE( 81RATEuSetIE(
diff --git a/drivers/staging/vt6656/desc.h b/drivers/staging/vt6656/desc.h
index 5007e98d1b0e..0c0b614aaa11 100644
--- a/drivers/staging/vt6656/desc.h
+++ b/drivers/staging/vt6656/desc.h
@@ -36,92 +36,95 @@
36#include "ttype.h" 36#include "ttype.h"
37#include "tether.h" 37#include "tether.h"
38 38
39// max transmit or receive buffer size 39/* max transmit or receive buffer size */
40#define CB_MAX_BUF_SIZE 2900U // max buffer size 40#define CB_MAX_BUF_SIZE 2900U /* NOTE: must be multiple of 4 */
41 // NOTE: must be multiple of 4
42 41
43#define CB_MAX_TX_BUF_SIZE CB_MAX_BUF_SIZE // max Tx buffer size 42/* max TX buffer size */
44#define CB_MAX_RX_BUF_SIZE_NORMAL CB_MAX_BUF_SIZE // max Rx buffer size when not use Multi-RD 43#define CB_MAX_TX_BUF_SIZE CB_MAX_BUF_SIZE
44/* max RX buffer size when not use Multi-RD */
45#define CB_MAX_RX_BUF_SIZE_NORMAL CB_MAX_BUF_SIZE
45 46
46#define CB_BEACON_BUF_SIZE 512U // default beacon buffer size 47#define CB_BEACON_BUF_SIZE 512U /* default beacon buffer size */
47 48
48#define MAX_TOTAL_SIZE_WITH_ALL_HEADERS CB_MAX_BUF_SIZE 49#define MAX_TOTAL_SIZE_WITH_ALL_HEADERS CB_MAX_BUF_SIZE
49 50
50#define MAX_INTERRUPT_SIZE 32 51#define MAX_INTERRUPT_SIZE 32
51 52
52#define RX_BLOCKS 64 // form 0x60 to 0xA0 53#define RX_BLOCKS 64 /* from 0x60 to 0xA0 */
53#define TX_BLOCKS 32 // from 0xA0 to 0xC0 54#define TX_BLOCKS 32 /* from 0xA0 to 0xC0 */
54 55
55#define CB_MAX_RX_DESC 128 // max # of descriptor 56#define CB_MAX_RX_DESC 128 /* max # of descriptors */
56#define CB_MIN_RX_DESC 16 // min # of rx descriptor 57#define CB_MIN_RX_DESC 16 /* min # of RX descriptors */
57#define CB_MAX_TX_DESC 128 // max # of descriptor 58#define CB_MAX_TX_DESC 128 /* max # of descriptors */
58#define CB_MIN_TX_DESC 16 // min # of tx descriptor 59#define CB_MIN_TX_DESC 16 /* min # of TX descriptors */
59 60
60#define CB_RD_NUM 64 // default # of RD 61#define CB_RD_NUM 64 /* default # of RD */
61#define CB_TD_NUM 64 // default # of TD 62#define CB_TD_NUM 64 /* default # of TD */
62 63
63// 64/*
64// Bits in the RSR register 65 * bits in the RSR register
65// 66 */
66#define RSR_ADDRBROAD 0x80 // 1000 0000 67#define RSR_ADDRBROAD 0x80
67#define RSR_ADDRMULTI 0x40 // 0100 0000 68#define RSR_ADDRMULTI 0x40
68#define RSR_ADDRUNI 0x00 // 0000 0000 69#define RSR_ADDRUNI 0x00
69#define RSR_IVLDTYP 0x20 // 0010 0000 , invalid packet type 70#define RSR_IVLDTYP 0x20 /* invalid packet type */
70#define RSR_IVLDLEN 0x10 // 0001 0000 , invalid len (> 2312 byte) 71#define RSR_IVLDLEN 0x10 /* invalid len (> 2312 byte) */
71#define RSR_BSSIDOK 0x08 // 0000 1000 72#define RSR_BSSIDOK 0x08
72#define RSR_CRCOK 0x04 // 0000 0100 73#define RSR_CRCOK 0x04
73#define RSR_BCNSSIDOK 0x02 // 0000 0010 74#define RSR_BCNSSIDOK 0x02
74#define RSR_ADDROK 0x01 // 0000 0001 75#define RSR_ADDROK 0x01
75 76
76// 77/*
77// Bits in the new RSR register 78 * bits in the new RSR register
78// 79 */
79#define NEWRSR_DECRYPTOK 0x10 // 0001 0000 80#define NEWRSR_DECRYPTOK 0x10
80#define NEWRSR_CFPIND 0x08 // 0000 1000 81#define NEWRSR_CFPIND 0x08
81#define NEWRSR_HWUTSF 0x04 // 0000 0100 82#define NEWRSR_HWUTSF 0x04
82#define NEWRSR_BCNHITAID 0x02 // 0000 0010 83#define NEWRSR_BCNHITAID 0x02
83#define NEWRSR_BCNHITAID0 0x01 // 0000 0001 84#define NEWRSR_BCNHITAID0 0x01
84 85
85// 86/*
86// Bits in the TSR register 87 * bits in the TSR register
87// 88 */
88#define TSR_RETRYTMO 0x08 // 0000 1000 89#define TSR_RETRYTMO 0x08
89#define TSR_TMO 0x04 // 0000 0100 90#define TSR_TMO 0x04
90#define TSR_ACKDATA 0x02 // 0000 0010 91#define TSR_ACKDATA 0x02
91#define TSR_VALID 0x01 // 0000 0001 92#define TSR_VALID 0x01
92 93
93#define CB_PROTOCOL_RESERVED_SECTION 16 94#define CB_PROTOCOL_RESERVED_SECTION 16
94 95
95// if retrys excess 15 times , tx will abort, and 96/*
96// if tx fifo underflow, tx will fail 97 * if retries exceed 15 times, TX will abort, and
97// we should try to resend it 98 * if TX fifo underflow, TX will fail
99 * we should try to resend it
100 */
98#define CB_MAX_TX_ABORT_RETRY 3 101#define CB_MAX_TX_ABORT_RETRY 3
99 102
100#define FIFOCTL_AUTO_FB_1 0x1000 // 0001 0000 0000 0000 103#define FIFOCTL_AUTO_FB_1 0x1000
101#define FIFOCTL_AUTO_FB_0 0x0800 // 0000 1000 0000 0000 104#define FIFOCTL_AUTO_FB_0 0x0800
102#define FIFOCTL_GRPACK 0x0400 // 0000 0100 0000 0000 105#define FIFOCTL_GRPACK 0x0400
103#define FIFOCTL_11GA 0x0300 // 0000 0011 0000 0000 106#define FIFOCTL_11GA 0x0300
104#define FIFOCTL_11GB 0x0200 // 0000 0010 0000 0000 107#define FIFOCTL_11GB 0x0200
105#define FIFOCTL_11B 0x0100 // 0000 0001 0000 0000 108#define FIFOCTL_11B 0x0100
106#define FIFOCTL_11A 0x0000 // 0000 0000 0000 0000 109#define FIFOCTL_11A 0x0000
107#define FIFOCTL_RTS 0x0080 // 0000 0000 1000 0000 110#define FIFOCTL_RTS 0x0080
108#define FIFOCTL_ISDMA0 0x0040 // 0000 0000 0100 0000 111#define FIFOCTL_ISDMA0 0x0040
109#define FIFOCTL_GENINT 0x0020 // 0000 0000 0010 0000 112#define FIFOCTL_GENINT 0x0020
110#define FIFOCTL_TMOEN 0x0010 // 0000 0000 0001 0000 113#define FIFOCTL_TMOEN 0x0010
111#define FIFOCTL_LRETRY 0x0008 // 0000 0000 0000 1000 114#define FIFOCTL_LRETRY 0x0008
112#define FIFOCTL_CRCDIS 0x0004 // 0000 0000 0000 0100 115#define FIFOCTL_CRCDIS 0x0004
113#define FIFOCTL_NEEDACK 0x0002 // 0000 0000 0000 0010 116#define FIFOCTL_NEEDACK 0x0002
114#define FIFOCTL_LHEAD 0x0001 // 0000 0000 0000 0001 117#define FIFOCTL_LHEAD 0x0001
115 118
116//WMAC definition Frag Control 119/* WMAC definition Frag Control */
117#define FRAGCTL_AES 0x0300 // 0000 0011 0000 0000 120#define FRAGCTL_AES 0x0300
118#define FRAGCTL_TKIP 0x0200 // 0000 0010 0000 0000 121#define FRAGCTL_TKIP 0x0200
119#define FRAGCTL_LEGACY 0x0100 // 0000 0001 0000 0000 122#define FRAGCTL_LEGACY 0x0100
120#define FRAGCTL_NONENCRYPT 0x0000 // 0000 0000 0000 0000 123#define FRAGCTL_NONENCRYPT 0x0000
121#define FRAGCTL_ENDFRAG 0x0003 // 0000 0000 0000 0011 124#define FRAGCTL_ENDFRAG 0x0003
122#define FRAGCTL_MIDFRAG 0x0002 // 0000 0000 0000 0010 125#define FRAGCTL_MIDFRAG 0x0002
123#define FRAGCTL_STAFRAG 0x0001 // 0000 0000 0000 0001 126#define FRAGCTL_STAFRAG 0x0001
124#define FRAGCTL_NONFRAG 0x0000 // 0000 0000 0000 0000 127#define FRAGCTL_NONFRAG 0x0000
125 128
126#define TYPE_TXDMA0 0 129#define TYPE_TXDMA0 0
127#define TYPE_AC0DMA 1 130#define TYPE_AC0DMA 1
@@ -135,14 +138,14 @@
135#define TYPE_RXDMA1 1 138#define TYPE_RXDMA1 1
136#define TYPE_MAXRD 2 139#define TYPE_MAXRD 2
137 140
138// TD_INFO flags control bit 141/* TD_INFO flags control bit */
139#define TD_FLAGS_NETIF_SKB 0x01 // check if need release skb 142#define TD_FLAGS_NETIF_SKB 0x01 /* check if need release skb */
140#define TD_FLAGS_PRIV_SKB 0x02 // check if called from private skb(hostap) 143#define TD_FLAGS_PRIV_SKB 0x02 /* check if called from private skb(hostap) */
141#define TD_FLAGS_PS_RETRY 0x04 // check if PS STA frame re-transmit 144#define TD_FLAGS_PS_RETRY 0x04 /* check if PS STA frame re-transmit */
142 145
143// 146/*
144// RsvTime buffer header 147 * RsvTime buffer header
145// 148 */
146typedef struct tagSRrvTime_gRTS { 149typedef struct tagSRrvTime_gRTS {
147 WORD wRTSTxRrvTime_ba; 150 WORD wRTSTxRrvTime_ba;
148 WORD wRTSTxRrvTime_aa; 151 WORD wRTSTxRrvTime_aa;
@@ -181,9 +184,9 @@ SRrvTime_atim, *PSRrvTime_atim;
181 184
182typedef const SRrvTime_atim *PCSRrvTime_atim; 185typedef const SRrvTime_atim *PCSRrvTime_atim;
183 186
184// 187/*
185// RTS buffer header 188 * RTS buffer header
186// 189 */
187typedef struct tagSRTSData { 190typedef struct tagSRTSData {
188 WORD wFrameControl; 191 WORD wFrameControl;
189 WORD wDurationID; 192 WORD wDurationID;
@@ -257,9 +260,9 @@ SRTS_a_FB, *PSRTS_a_FB;
257 260
258typedef const SRTS_a_FB *PCSRTS_a_FB; 261typedef const SRTS_a_FB *PCSRTS_a_FB;
259 262
260// 263/*
261// CTS buffer header 264 * CTS buffer header
262// 265 */
263typedef struct tagSCTSData { 266typedef struct tagSCTSData {
264 WORD wFrameControl; 267 WORD wFrameControl;
265 WORD wDurationID; 268 WORD wDurationID;
@@ -294,9 +297,9 @@ SCTS_FB, *PSCTS_FB;
294 297
295typedef const SCTS_FB *PCSCTS_FB; 298typedef const SCTS_FB *PCSCTS_FB;
296 299
297// 300/*
298// Tx FIFO header 301 * TX FIFO header
299// 302 */
300typedef struct tagSTxBufHead { 303typedef struct tagSTxBufHead {
301 u32 adwTxKey[4]; 304 u32 adwTxKey[4];
302 WORD wFIFOCtl; 305 WORD wFIFOCtl;
@@ -314,9 +317,9 @@ typedef struct tagSTxShortBufHead {
314STxShortBufHead, *PSTxShortBufHead; 317STxShortBufHead, *PSTxShortBufHead;
315typedef const STxShortBufHead *PCSTxShortBufHead; 318typedef const STxShortBufHead *PCSTxShortBufHead;
316 319
317// 320/*
318// Tx data header 321 * TX data header
319// 322 */
320typedef struct tagSTxDataHead_g { 323typedef struct tagSTxDataHead_g {
321 BYTE bySignalField_b; 324 BYTE bySignalField_b;
322 BYTE byServiceField_b; 325 BYTE byServiceField_b;
@@ -372,9 +375,9 @@ typedef struct tagSTxDataHead_a_FB {
372STxDataHead_a_FB, *PSTxDataHead_a_FB; 375STxDataHead_a_FB, *PSTxDataHead_a_FB;
373typedef const STxDataHead_a_FB *PCSTxDataHead_a_FB; 376typedef const STxDataHead_a_FB *PCSTxDataHead_a_FB;
374 377
375// 378/*
376// MICHDR data header 379 * MICHDR data header
377// 380 */
378typedef struct tagSMICHDRHead { 381typedef struct tagSMICHDRHead {
379 u32 adwHDR0[4]; 382 u32 adwHDR0[4];
380 u32 adwHDR1[4]; 383 u32 adwHDR1[4];
diff --git a/drivers/staging/vt6656/device.h b/drivers/staging/vt6656/device.h
index 25bf03af7733..6bba2e06fa64 100644
--- a/drivers/staging/vt6656/device.h
+++ b/drivers/staging/vt6656/device.h
@@ -53,7 +53,7 @@
53#undef DEVICE_ETHTOOL_IOCTL_SUPPORT 53#undef DEVICE_ETHTOOL_IOCTL_SUPPORT
54#endif 54#endif
55 55
56//please copy below macro to driver_event.c for API 56/* please copy below macro to driver_event.c for API */
57#define RT_INSMOD_EVENT_FLAG 0x0101 57#define RT_INSMOD_EVENT_FLAG 0x0101
58#define RT_UPDEV_EVENT_FLAG 0x0102 58#define RT_UPDEV_EVENT_FLAG 0x0102
59#define RT_DISCONNECTED_EVENT_FLAG 0x0103 59#define RT_DISCONNECTED_EVENT_FLAG 0x0103
@@ -61,9 +61,9 @@
61#define RT_DOWNDEV_EVENT_FLAG 0x0105 61#define RT_DOWNDEV_EVENT_FLAG 0x0105
62#define RT_RMMOD_EVENT_FLAG 0x0106 62#define RT_RMMOD_EVENT_FLAG 0x0106
63 63
64// 64/*
65// device specific 65 * device specific
66// 66 */
67 67
68#include "device_cfg.h" 68#include "device_cfg.h"
69#include "ttype.h" 69#include "ttype.h"
@@ -110,7 +110,7 @@
110#define FB_RATE0 0 110#define FB_RATE0 0
111#define FB_RATE1 1 111#define FB_RATE1 1
112 112
113// Antenna Mode 113/* Antenna Mode */
114#define ANT_A 0 114#define ANT_A 0
115#define ANT_B 1 115#define ANT_B 1
116#define ANT_DIVERSITY 2 116#define ANT_DIVERSITY 2
@@ -125,7 +125,7 @@
125 125
126#define MAXCHECKHANGCNT 4 126#define MAXCHECKHANGCNT 4
127 127
128//Packet type 128/* Packet type */
129#define TX_PKT_UNI 0x00 129#define TX_PKT_UNI 0x00
130#define TX_PKT_MULTI 0x01 130#define TX_PKT_MULTI 0x01
131#define TX_PKT_BROAD 0x02 131#define TX_PKT_BROAD 0x02
@@ -137,7 +137,7 @@
137#define RUN_AT(x) (jiffies+(x)) 137#define RUN_AT(x) (jiffies+(x))
138#endif 138#endif
139 139
140// DMA related 140/* DMA related */
141#define RESERV_AC0DMA 4 141#define RESERV_AC0DMA 4
142 142
143#define PRIVATE_Message 0 143#define PRIVATE_Message 0
@@ -161,30 +161,30 @@ typedef enum __device_init_type {
161 DEVICE_INIT_DXPL /* Dx to D0 power lost init */ 161 DEVICE_INIT_DXPL /* Dx to D0 power lost init */
162} DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE; 162} DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE;
163 163
164//USB 164/* USB */
165 165
166// 166/*
167// Enum of context types for SendPacket 167 * Enum of context types for SendPacket
168// 168 */
169typedef enum _CONTEXT_TYPE { 169typedef enum _CONTEXT_TYPE {
170 CONTEXT_DATA_PACKET = 1, 170 CONTEXT_DATA_PACKET = 1,
171 CONTEXT_MGMT_PACKET 171 CONTEXT_MGMT_PACKET
172} CONTEXT_TYPE; 172} CONTEXT_TYPE;
173 173
174// RCB (Receive Control Block) 174/* RCB (Receive Control Block) */
175typedef struct _RCB 175typedef struct _RCB
176{ 176{
177 void *Next; 177 void *Next;
178 signed long Ref; 178 signed long Ref;
179 void *pDevice; 179 void *pDevice;
180 struct urb *pUrb; 180 struct urb *pUrb;
181 SRxMgmtPacket sMngPacket; 181 struct vnt_rx_mgmt sMngPacket;
182 struct sk_buff* skb; 182 struct sk_buff *skb;
183 BOOL bBoolInUse; 183 int bBoolInUse;
184 184
185} RCB, *PRCB; 185} RCB, *PRCB;
186 186
187// used to track bulk out irps 187/* used to track bulk out irps */
188typedef struct _USB_SEND_CONTEXT { 188typedef struct _USB_SEND_CONTEXT {
189 void *pDevice; 189 void *pDevice;
190 struct sk_buff *pPacket; 190 struct sk_buff *pPacket;
@@ -193,7 +193,7 @@ typedef struct _USB_SEND_CONTEXT {
193 CONTEXT_TYPE Type; 193 CONTEXT_TYPE Type;
194 SEthernetHeader sEthHeader; 194 SEthernetHeader sEthHeader;
195 void *Next; 195 void *Next;
196 BOOL bBoolInUse; 196 bool bBoolInUse;
197 unsigned char Data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS]; 197 unsigned char Data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
198} USB_SEND_CONTEXT, *PUSB_SEND_CONTEXT; 198} USB_SEND_CONTEXT, *PUSB_SEND_CONTEXT;
199 199
@@ -207,17 +207,17 @@ typedef struct _DEFAULT_CONFIG {
207 signed int eEncryptionStatus; 207 signed int eEncryptionStatus;
208} DEFAULT_CONFIG, *PDEFAULT_CONFIG; 208} DEFAULT_CONFIG, *PDEFAULT_CONFIG;
209 209
210// 210/*
211// Structure to keep track of usb interrupt packets 211 * Structure to keep track of USB interrupt packets
212// 212 */
213typedef struct { 213typedef struct {
214 unsigned int uDataLen; 214 unsigned int uDataLen;
215 PBYTE pDataBuf; 215 PBYTE pDataBuf;
216// struct urb *pUrb; 216 /* struct urb *pUrb; */
217 BOOL bInUse; 217 bool bInUse;
218} INT_BUFFER, *PINT_BUFFER; 218} INT_BUFFER, *PINT_BUFFER;
219 219
220//0:11A 1:11B 2:11G 220/* 0:11A 1:11B 2:11G */
221typedef enum _VIA_BB_TYPE 221typedef enum _VIA_BB_TYPE
222{ 222{
223 BB_TYPE_11A = 0, 223 BB_TYPE_11A = 0,
@@ -225,7 +225,7 @@ typedef enum _VIA_BB_TYPE
225 BB_TYPE_11G 225 BB_TYPE_11G
226} VIA_BB_TYPE, *PVIA_BB_TYPE; 226} VIA_BB_TYPE, *PVIA_BB_TYPE;
227 227
228//0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) 228/* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga(OFDM in BasicRate) */
229typedef enum _VIA_PKT_TYPE 229typedef enum _VIA_PKT_TYPE
230{ 230{
231 PK_TYPE_11A = 0, 231 PK_TYPE_11A = 0,
@@ -234,7 +234,7 @@ typedef enum _VIA_PKT_TYPE
234 PK_TYPE_11GA 234 PK_TYPE_11GA
235} VIA_PKT_TYPE, *PVIA_PKT_TYPE; 235} VIA_PKT_TYPE, *PVIA_PKT_TYPE;
236 236
237//++ NDIS related 237/*++ NDIS related */
238 238
239typedef enum __DEVICE_NDIS_STATUS { 239typedef enum __DEVICE_NDIS_STATUS {
240 STATUS_SUCCESS = 0, 240 STATUS_SUCCESS = 0,
@@ -245,10 +245,10 @@ typedef enum __DEVICE_NDIS_STATUS {
245 245
246#define MAX_BSSIDINFO_4_PMKID 16 246#define MAX_BSSIDINFO_4_PMKID 16
247#define MAX_PMKIDLIST 5 247#define MAX_PMKIDLIST 5
248//Flags for PMKID Candidate list structure 248/* flags for PMKID Candidate list structure */
249#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01 249#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
250 250
251// PMKID Structures 251/* PMKID Structures */
252typedef unsigned char NDIS_802_11_PMKID_VALUE[16]; 252typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
253 253
254 254
@@ -272,13 +272,13 @@ typedef enum _NDIS_802_11_WEP_STATUS
272 272
273typedef enum _NDIS_802_11_STATUS_TYPE 273typedef enum _NDIS_802_11_STATUS_TYPE
274{ 274{
275 Ndis802_11StatusType_Authentication, 275 Ndis802_11StatusType_Authentication,
276 Ndis802_11StatusType_MediaStreamMode, 276 Ndis802_11StatusType_MediaStreamMode,
277 Ndis802_11StatusType_PMKID_CandidateList, 277 Ndis802_11StatusType_PMKID_CandidateList,
278 Ndis802_11StatusTypeMax // not a real type, defined as an upper bound 278 Ndis802_11StatusTypeMax, /* not a real type, defined as upper bound */
279} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE; 279} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
280 280
281//Added new types for PMKID Candidate lists. 281/* added new types for PMKID Candidate lists */
282typedef struct _PMKID_CANDIDATE { 282typedef struct _PMKID_CANDIDATE {
283 NDIS_802_11_MAC_ADDRESS BSSID; 283 NDIS_802_11_MAC_ADDRESS BSSID;
284 unsigned long Flags; 284 unsigned long Flags;
@@ -304,22 +304,17 @@ typedef struct tagSPMKIDCandidateEvent {
304 PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST]; 304 PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
305} SPMKIDCandidateEvent, *PSPMKIDCandidateEvent; 305} SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
306 306
307//-- 307/*++ 802.11h related */
308
309//++ 802.11h related
310#define MAX_QUIET_COUNT 8 308#define MAX_QUIET_COUNT 8
311 309
312typedef struct tagSQuietControl { 310typedef struct tagSQuietControl {
313 BOOL bEnable; 311 bool bEnable;
314 DWORD dwStartTime; 312 DWORD dwStartTime;
315 BYTE byPeriod; 313 BYTE byPeriod;
316 WORD wDuration; 314 WORD wDuration;
317} SQuietControl, *PSQuietControl; 315} SQuietControl, *PSQuietControl;
318 316
319//-- 317/* The receive duplicate detection cache entry */
320
321
322// The receive duplicate detection cache entry
323typedef struct tagSCacheEntry{ 318typedef struct tagSCacheEntry{
324 WORD wFmSequence; 319 WORD wFmSequence;
325 BYTE abyAddr2[ETH_ALEN]; 320 BYTE abyAddr2[ETH_ALEN];
@@ -329,13 +324,15 @@ typedef struct tagSCacheEntry{
329typedef struct tagSCache{ 324typedef struct tagSCache{
330/* The receive cache is updated circularly. The next entry to be written is 325/* The receive cache is updated circularly. The next entry to be written is
331 * indexed by the "InPtr". 326 * indexed by the "InPtr".
332*/ 327 */
333 unsigned int uInPtr; /* Place to use next */ 328 unsigned int uInPtr; /* Place to use next */
334 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH]; 329 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
335} SCache, *PSCache; 330} SCache, *PSCache;
336 331
337#define CB_MAX_RX_FRAG 64 332#define CB_MAX_RX_FRAG 64
338// DeFragment Control Block, used for collecting fragments prior to reassembly 333/*
334 * DeFragment Control Block, used for collecting fragments prior to reassembly
335 */
339typedef struct tagSDeFragControlBlock 336typedef struct tagSDeFragControlBlock
340{ 337{
341 WORD wSequence; 338 WORD wSequence;
@@ -345,27 +342,25 @@ typedef struct tagSDeFragControlBlock
345 struct sk_buff* skb; 342 struct sk_buff* skb;
346 PBYTE pbyRxBuffer; 343 PBYTE pbyRxBuffer;
347 unsigned int cbFrameLength; 344 unsigned int cbFrameLength;
348 BOOL bInUse; 345 bool bInUse;
349} SDeFragControlBlock, *PSDeFragControlBlock; 346} SDeFragControlBlock, *PSDeFragControlBlock;
350 347
351 348/* flags for options */
352
353//flags for options
354#define DEVICE_FLAGS_UNPLUG 0x00000001UL 349#define DEVICE_FLAGS_UNPLUG 0x00000001UL
355#define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL 350#define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
356#define DEVICE_FLAGS_OP_MODE 0x00000004UL 351#define DEVICE_FLAGS_OP_MODE 0x00000004UL
357#define DEVICE_FLAGS_PS_MODE 0x00000008UL 352#define DEVICE_FLAGS_PS_MODE 0x00000008UL
358#define DEVICE_FLAGS_80211h_MODE 0x00000010UL 353#define DEVICE_FLAGS_80211h_MODE 0x00000010UL
359 354
360//flags for driver status 355/* flags for driver status */
361#define DEVICE_FLAGS_OPENED 0x00010000UL 356#define DEVICE_FLAGS_OPENED 0x00010000UL
362#define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL 357#define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
363//flags for capbilities 358/* flags for capabilities */
364#define DEVICE_FLAGS_TX_ALIGN 0x01000000UL 359#define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
365#define DEVICE_FLAGS_HAVE_CAM 0x02000000UL 360#define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
366#define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL 361#define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
367 362
368//flags for MII status 363/* flags for MII status */
369#define DEVICE_LINK_FAIL 0x00000001UL 364#define DEVICE_LINK_FAIL 0x00000001UL
370#define DEVICE_SPEED_10 0x00000002UL 365#define DEVICE_SPEED_10 0x00000002UL
371#define DEVICE_SPEED_100 0x00000004UL 366#define DEVICE_SPEED_100 0x00000004UL
@@ -373,14 +368,14 @@ typedef struct tagSDeFragControlBlock
373#define DEVICE_DUPLEX_FULL 0x00000010UL 368#define DEVICE_DUPLEX_FULL 0x00000010UL
374#define DEVICE_AUTONEG_ENABLE 0x00000020UL 369#define DEVICE_AUTONEG_ENABLE 0x00000020UL
375#define DEVICE_FORCED_BY_EEPROM 0x00000040UL 370#define DEVICE_FORCED_BY_EEPROM 0x00000040UL
376//for device_set_media_duplex 371/* for device_set_media_duplex */
377#define DEVICE_LINK_CHANGE 0x00000001UL 372#define DEVICE_LINK_CHANGE 0x00000001UL
378 373
379 374
380typedef struct __device_opt { 375typedef struct __device_opt {
381 int nRxDescs0; //Number of RX descriptors0 376 int nRxDescs0; /* number of RX descriptors 0 */
382 int nTxDescs0; //Number of TX descriptors 0, 1, 2, 3 377 int nTxDescs0; /* number of TX descriptors 0, 1, 2, 3 */
383 int rts_thresh; //rts threshold 378 int rts_thresh; /* RTS threshold */
384 int frag_thresh; 379 int frag_thresh;
385 int OpMode; 380 int OpMode;
386 int data_rate; 381 int data_rate;
@@ -392,429 +387,406 @@ typedef struct __device_opt {
392} OPTIONS, *POPTIONS; 387} OPTIONS, *POPTIONS;
393 388
394 389
395typedef struct __device_info { 390struct vnt_private {
391 /* netdev */
392 struct usb_device *usb;
393 struct net_device *dev;
394 struct net_device_stats stats;
396 395
397// netdev 396 OPTIONS sOpts;
398 struct usb_device* usb;
399 struct net_device* dev;
400 struct net_device_stats stats;
401 397
398 struct tasklet_struct CmdWorkItem;
399 struct tasklet_struct EventWorkItem;
400 struct tasklet_struct ReadWorkItem;
401 struct tasklet_struct RxMngWorkItem;
402 402
403 OPTIONS sOpts; 403 u32 rx_buf_sz;
404 int multicast_limit;
405 u8 byRxMode;
404 406
405 struct tasklet_struct CmdWorkItem; 407 spinlock_t lock;
406 struct tasklet_struct EventWorkItem;
407 struct tasklet_struct ReadWorkItem;
408 struct tasklet_struct RxMngWorkItem;
409 408
410 u32 rx_buf_sz; 409 u32 rx_bytes;
411 int multicast_limit;
412 BYTE byRxMode;
413 410
414 spinlock_t lock; 411 u8 byRevId;
415 412
416 u32 rx_bytes; 413 u32 flags;
414 unsigned long Flags;
417 415
418 BYTE byRevId; 416 SCache sDupRxCache;
419 417
420 u32 flags; 418 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
421 unsigned long Flags; 419 u32 cbDFCB;
420 u32 cbFreeDFCB;
421 u32 uCurrentDFCBIdx;
422 422
423 SCache sDupRxCache;
424 423
425 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG]; 424 /* USB */
426 unsigned int cbDFCB; 425 struct urb *pControlURB;
427 unsigned int cbFreeDFCB; 426 struct urb *pInterruptURB;
428 unsigned int uCurrentDFCBIdx; 427 struct usb_ctrlrequest sUsbCtlRequest;
428 u32 int_interval;
429 429
430 // +++USB 430 /* Variables to track resources for the BULK In Pipe */
431 431 PRCB pRCBMem;
432 struct urb *pControlURB; 432 PRCB apRCB[CB_MAX_RX_DESC];
433 struct urb *pInterruptURB; 433 u32 cbRD;
434 struct usb_ctrlrequest sUsbCtlRequest; 434 PRCB FirstRecvFreeList;
435 435 PRCB LastRecvFreeList;
436 unsigned int int_interval; 436 u32 NumRecvFreeList;
437 // 437 PRCB FirstRecvMngList;
438 // Variables to track resources for the BULK In Pipe 438 PRCB LastRecvMngList;
439 // 439 u32 NumRecvMngList;
440 PRCB pRCBMem; 440 int bIsRxWorkItemQueued;
441 PRCB apRCB[CB_MAX_RX_DESC]; 441 int bIsRxMngWorkItemQueued;
442 unsigned int cbRD;
443 PRCB FirstRecvFreeList;
444 PRCB LastRecvFreeList;
445 unsigned int NumRecvFreeList;
446 PRCB FirstRecvMngList;
447 PRCB LastRecvMngList;
448 unsigned int NumRecvMngList;
449 BOOL bIsRxWorkItemQueued;
450 BOOL bIsRxMngWorkItemQueued;
451 unsigned long ulRcvRefCount; /* packets that have not returned back */ 442 unsigned long ulRcvRefCount; /* packets that have not returned back */
452 443
453 // 444 /* Variables to track resources for the BULK Out Pipe */
454 // Variables to track resources for the BULK Out Pipe 445 PUSB_SEND_CONTEXT apTD[CB_MAX_TX_DESC];
455 // 446 u32 cbTD;
456 447
457 PUSB_SEND_CONTEXT apTD[CB_MAX_TX_DESC]; 448 /* Variables to track resources for the Interrupt In Pipe */
458 unsigned int cbTD; 449 INT_BUFFER intBuf;
459 450 int fKillEventPollingThread;
460 // 451 int bEventAvailable;
461 // Variables to track resources for the Interrupt In Pipe 452
462 // 453 /* default config from file by user setting */
463 INT_BUFFER intBuf; 454 DEFAULT_CONFIG config_file;
464 BOOL fKillEventPollingThread; 455
465 BOOL bEventAvailable; 456
466 457 /* Statistic for USB */
467 458 unsigned long ulBulkInPosted;
468 //default config from file by user setting 459 unsigned long ulBulkInError;
469 DEFAULT_CONFIG config_file; 460 unsigned long ulBulkInContCRCError;
470 461 unsigned long ulBulkInBytesRead;
471 462
472 // 463 unsigned long ulBulkOutPosted;
473 // Statistic for USB 464 unsigned long ulBulkOutError;
474 // protect with spinlock 465 unsigned long ulBulkOutContCRCError;
475 unsigned long ulBulkInPosted; 466 unsigned long ulBulkOutBytesWrite;
476 unsigned long ulBulkInError; 467
477 unsigned long ulBulkInContCRCError; 468 unsigned long ulIntInPosted;
478 unsigned long ulBulkInBytesRead; 469 unsigned long ulIntInError;
479 470 unsigned long ulIntInContCRCError;
480 unsigned long ulBulkOutPosted; 471 unsigned long ulIntInBytesRead;
481 unsigned long ulBulkOutError; 472
482 unsigned long ulBulkOutContCRCError; 473
483 unsigned long ulBulkOutBytesWrite; 474 /* Version control */
484 475 u16 wFirmwareVersion;
485 unsigned long ulIntInPosted; 476 u8 byLocalID;
486 unsigned long ulIntInError; 477 u8 byRFType;
487 unsigned long ulIntInContCRCError; 478 u8 byBBRxConf;
488 unsigned long ulIntInBytesRead; 479
489 480
490 481 u8 byZoneType;
491 // Version control 482 int bZoneRegExist;
492 WORD wFirmwareVersion; 483
493 BYTE byLocalID; 484 u8 byOriginalZonetype;
494 BYTE byRFType; 485
495 BYTE byBBRxConf; 486 int bLinkPass; /* link status: OK or fail */
496 487 u8 abyCurrentNetAddr[ETH_ALEN];
497 488 u8 abyPermanentNetAddr[ETH_ALEN];
498 BYTE byZoneType; 489
499 BOOL bZoneRegExist; 490 int bExistSWNetAddr;
500 491
501 BYTE byOriginalZonetype; 492 /* Adapter statistics */
502 493 SStatCounter scStatistic;
503 BOOL bLinkPass; // link status: OK or fail 494 /* 802.11 counter */
504 BYTE abyCurrentNetAddr[ETH_ALEN]; 495 SDot11Counters s802_11Counter;
505 BYTE abyPermanentNetAddr[ETH_ALEN]; 496
506 // SW network address 497 /* Maintain statistical debug info. */
507 /* u8 abySoftwareNetAddr[ETH_ALEN]; */ 498 unsigned long packetsReceived;
508 BOOL bExistSWNetAddr; 499 unsigned long packetsReceivedDropped;
509 500 unsigned long packetsReceivedOverflow;
510 // Adapter statistics 501 unsigned long packetsSent;
511 SStatCounter scStatistic; 502 unsigned long packetsSentDropped;
512 // 802.11 counter 503 unsigned long SendContextsInUse;
513 SDot11Counters s802_11Counter; 504 unsigned long RcvBuffersInUse;
514 505
515 // 506 /* 802.11 management */
516 // Maintain statistical debug info. 507 struct vnt_manager vnt_mgmt;
517 // 508
518 unsigned long packetsReceived; 509 u64 qwCurrTSF;
519 unsigned long packetsReceivedDropped; 510 u32 cbBulkInMax;
520 unsigned long packetsReceivedOverflow; 511 int bPSRxBeacon;
521 unsigned long packetsSent; 512
522 unsigned long packetsSentDropped; 513 /* 802.11 MAC specific */
523 unsigned long SendContextsInUse; 514 u32 uCurrRSSI;
524 unsigned long RcvBuffersInUse; 515 u8 byCurrSQ;
525 516
526 517 /* Antenna Diversity */
527 // 802.11 management 518 int bTxRxAntInv;
528 SMgmtObject sMgmtObj; 519 u32 dwRxAntennaSel;
529 520 u32 dwTxAntennaSel;
530 QWORD qwCurrTSF; 521 u8 byAntennaCount;
531 unsigned int cbBulkInMax; 522 u8 byRxAntennaMode;
532 BOOL bPSRxBeacon; 523 u8 byTxAntennaMode;
533 524 u8 byRadioCtl;
534 // 802.11 MAC specific 525 u8 bHWRadioOff;
535 unsigned int uCurrRSSI; 526
536 BYTE byCurrSQ; 527 /* SQ3 functions for antenna diversity */
537 528 struct timer_list TimerSQ3Tmax1;
538 529 struct timer_list TimerSQ3Tmax2;
539 //Antenna Diversity 530 struct timer_list TimerSQ3Tmax3;
540 BOOL bTxRxAntInv; 531
541 DWORD dwRxAntennaSel; 532 int bDiversityRegCtlON;
542 DWORD dwTxAntennaSel; 533 int bDiversityEnable;
543 BYTE byAntennaCount; 534 unsigned long ulDiversityNValue;
544 BYTE byRxAntennaMode; 535 unsigned long ulDiversityMValue;
545 BYTE byTxAntennaMode; 536 u8 byTMax;
546 BYTE byRadioCtl; 537 u8 byTMax2;
547 BYTE bHWRadioOff; 538 u8 byTMax3;
548 539 unsigned long ulSQ3TH;
549 //SQ3 functions for antenna diversity 540
550 struct timer_list TimerSQ3Tmax1; 541 unsigned long uDiversityCnt;
551 struct timer_list TimerSQ3Tmax2; 542 u8 byAntennaState;
552 struct timer_list TimerSQ3Tmax3; 543 unsigned long ulRatio_State0;
553 544 unsigned long ulRatio_State1;
554 BOOL bDiversityRegCtlON; 545 unsigned long ulSQ3_State0;
555 BOOL bDiversityEnable; 546 unsigned long ulSQ3_State1;
556 unsigned long ulDiversityNValue; 547
557 unsigned long ulDiversityMValue; 548 unsigned long aulSQ3Val[MAX_RATE];
558 BYTE byTMax; 549 unsigned long aulPktNum[MAX_RATE];
559 BYTE byTMax2;
560 BYTE byTMax3;
561 unsigned long ulSQ3TH;
562
563 unsigned long uDiversityCnt;
564 BYTE byAntennaState;
565 unsigned long ulRatio_State0;
566 unsigned long ulRatio_State1;
567 unsigned long ulSQ3_State0;
568 unsigned long ulSQ3_State1;
569
570 unsigned long aulSQ3Val[MAX_RATE];
571 unsigned long aulPktNum[MAX_RATE];
572 550
573 /* IFS & Cw */ 551 /* IFS & Cw */
574 unsigned int uSIFS; /* Current SIFS */ 552 u32 uSIFS; /* Current SIFS */
575 unsigned int uDIFS; /* Current DIFS */ 553 u32 uDIFS; /* Current DIFS */
576 unsigned int uEIFS; /* Current EIFS */ 554 u32 uEIFS; /* Current EIFS */
577 unsigned int uSlot; /* Current SlotTime */ 555 u32 uSlot; /* Current SlotTime */
578 unsigned int uCwMin; /* Current CwMin */ 556 u32 uCwMin; /* Current CwMin */
579 unsigned int uCwMax; /* CwMax is fixed on 1023 */ 557 u32 uCwMax; /* CwMax is fixed on 1023 */
580 558
581 // PHY parameter 559 /* PHY parameter */
582 BYTE bySIFS; 560 u8 bySIFS;
583 BYTE byDIFS; 561 u8 byDIFS;
584 BYTE byEIFS; 562 u8 byEIFS;
585 BYTE bySlot; 563 u8 bySlot;
586 BYTE byCWMaxMin; 564 u8 byCWMaxMin;
587 565
588 // Rate 566 /* Rate */
589 VIA_BB_TYPE byBBType; //0: 11A, 1:11B, 2:11G 567 VIA_BB_TYPE byBBType; /* 0: 11A, 1:11B, 2:11G */
590 VIA_PKT_TYPE byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) 568 VIA_PKT_TYPE byPacketType; /* 0:11a 1:11b 2:11gb 3:11ga */
591 WORD wBasicRate; 569 u16 wBasicRate;
592 BYTE byACKRate; 570 u8 byACKRate;
593 BYTE byTopOFDMBasicRate; 571 u8 byTopOFDMBasicRate;
594 BYTE byTopCCKBasicRate; 572 u8 byTopCCKBasicRate;
595 573
596 574
597 DWORD dwAotoRateTxOkCnt; 575 u32 dwAotoRateTxOkCnt;
598 DWORD dwAotoRateTxFailCnt; 576 u32 dwAotoRateTxFailCnt;
599 DWORD dwErrorRateThreshold[13]; 577 u32 dwErrorRateThreshold[13];
600 DWORD dwTPTable[MAX_RATE]; 578 u32 dwTPTable[MAX_RATE];
601 BYTE abyEEPROM[EEP_MAX_CONTEXT_SIZE]; //DWORD alignment 579 u8 abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */
602 580
603 BYTE byMinChannel; 581 u8 byMinChannel;
604 BYTE byMaxChannel; 582 u8 byMaxChannel;
605 unsigned int uConnectionRate; 583 u32 uConnectionRate;
606 584
607 BYTE byPreambleType; 585 u8 byPreambleType;
608 BYTE byShortPreamble; 586 u8 byShortPreamble;
609 // CARD_PHY_TYPE 587 /* CARD_PHY_TYPE */
610 BYTE eConfigPHYMode; 588 u8 eConfigPHYMode;
611 589
612 // For RF Power table 590 /* For RF Power table */
613 BYTE byCCKPwr; 591 u8 byCCKPwr;
614 BYTE byOFDMPwrG; 592 u8 byOFDMPwrG;
615 BYTE byOFDMPwrA; 593 u8 byOFDMPwrA;
616 BYTE byCurPwr; 594 u8 byCurPwr;
617 BYTE abyCCKPwrTbl[14]; 595 u8 abyCCKPwrTbl[14];
618 BYTE abyOFDMPwrTbl[14]; 596 u8 abyOFDMPwrTbl[14];
619 BYTE abyOFDMAPwrTbl[42]; 597 u8 abyOFDMAPwrTbl[42];
620 598
621 WORD wCurrentRate; 599 u16 wCurrentRate;
622 WORD wRTSThreshold; 600 u16 wRTSThreshold;
623 WORD wFragmentationThreshold; 601 u16 wFragmentationThreshold;
624 BYTE byShortRetryLimit; 602 u8 byShortRetryLimit;
625 BYTE byLongRetryLimit; 603 u8 byLongRetryLimit;
626 CARD_OP_MODE eOPMode; 604 CARD_OP_MODE eOPMode;
627 BOOL bBSSIDFilter; 605 int bBSSIDFilter;
628 WORD wMaxTransmitMSDULifetime; 606 u16 wMaxTransmitMSDULifetime;
629 BYTE abyBSSID[ETH_ALEN]; 607 u8 abyBSSID[ETH_ALEN];
630 BYTE abyDesireBSSID[ETH_ALEN]; 608 u8 abyDesireBSSID[ETH_ALEN];
631 WORD wCTSDuration; // update while speed change 609
632 WORD wACKDuration; // update while speed change 610 u16 wCTSDuration; /* update while speed change */
633 WORD wRTSTransmitLen; // update while speed change 611 u16 wACKDuration;
634 BYTE byRTSServiceField; // update while speed change 612 u16 wRTSTransmitLen;
635 BYTE byRTSSignalField; // update while speed change 613 u8 byRTSServiceField;
636 614 u8 byRTSSignalField;
637 DWORD dwMaxReceiveLifetime; // dot11MaxReceiveLifetime 615
638 616 u32 dwMaxReceiveLifetime; /* dot11MaxReceiveLifetime */
639 BOOL bCCK; 617
640 BOOL bEncryptionEnable; 618 int bCCK;
641 BOOL bLongHeader; 619 int bEncryptionEnable;
642 BOOL bSoftwareGenCrcErr; 620 int bLongHeader;
643 BOOL bShortSlotTime; 621 int bSoftwareGenCrcErr;
644 BOOL bProtectMode; 622 int bShortSlotTime;
645 BOOL bNonERPPresent; 623 int bProtectMode;
646 BOOL bBarkerPreambleMd; 624 int bNonERPPresent;
647 625 int bBarkerPreambleMd;
648 BYTE byERPFlag; 626
649 WORD wUseProtectCntDown; 627 u8 byERPFlag;
650 628 u16 wUseProtectCntDown;
651 BOOL bRadioControlOff; 629
652 BOOL bRadioOff; 630 int bRadioControlOff;
653 631 int bRadioOff;
654 // Power save 632
655 BOOL bEnablePSMode; 633 /* Power save */
656 WORD wListenInterval; 634 int bEnablePSMode;
657 BOOL bPWBitOn; 635 u16 wListenInterval;
658 WMAC_POWER_MODE ePSMode; 636 int bPWBitOn;
659 unsigned long ulPSModeWaitTx; 637 WMAC_POWER_MODE ePSMode;
660 BOOL bPSModeTxBurst; 638 unsigned long ulPSModeWaitTx;
661 639 int bPSModeTxBurst;
662 // Beacon releated 640
663 WORD wSeqCounter; 641 /* Beacon releated */
664 BOOL bBeaconBufReady; 642 u16 wSeqCounter;
665 BOOL bBeaconSent; 643 int bBeaconBufReady;
666 BOOL bFixRate; 644 int bBeaconSent;
667 BYTE byCurrentCh; 645 int bFixRate;
668 unsigned int uScanTime; 646 u8 byCurrentCh;
669 647 u32 uScanTime;
670 CMD_STATE eCommandState; 648
671 649 CMD_STATE eCommandState;
672 CMD_CODE eCommand; 650
673 BOOL bBeaconTx; 651 CMD_CODE eCommand;
674 BYTE byScanBBType; 652 int bBeaconTx;
675 653 u8 byScanBBType;
676 BOOL bStopBeacon; 654
677 BOOL bStopDataPkt; 655 int bStopBeacon;
678 BOOL bStopTx0Pkt; 656 int bStopDataPkt;
679 unsigned int uAutoReConnectTime; 657 int bStopTx0Pkt;
680 unsigned int uIsroamingTime; 658 u32 uAutoReConnectTime;
681 659 u32 uIsroamingTime;
682 // 802.11 counter 660
683 661 /* 802.11 counter */
684 CMD_ITEM eCmdQueue[CMD_Q_SIZE]; 662
685 unsigned int uCmdDequeueIdx; 663 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
686 unsigned int uCmdEnqueueIdx; 664 u32 uCmdDequeueIdx;
687 unsigned int cbFreeCmdQueue; 665 u32 uCmdEnqueueIdx;
688 BOOL bCmdRunning; 666 u32 cbFreeCmdQueue;
689 BOOL bCmdClear; 667 int bCmdRunning;
690 BOOL bNeedRadioOFF; 668 int bCmdClear;
691 669 int bNeedRadioOFF;
692 BOOL bEnableRoaming; 670
693 BOOL bIsRoaming; 671 int bEnableRoaming;
694 BOOL bFastRoaming; 672 int bIsRoaming;
695 BYTE bSameBSSMaxNum; 673 int bFastRoaming;
696 BYTE bSameBSSCurNum; 674 u8 bSameBSSMaxNum;
697 BOOL bRoaming; 675 u8 bSameBSSCurNum;
698 BOOL b11hEable; 676 int bRoaming;
699 unsigned long ulTxPower; 677 int b11hEable;
700 678 unsigned long ulTxPower;
701 // Encryption 679
702 NDIS_802_11_WEP_STATUS eEncryptionStatus; 680 /* Encryption */
703 BOOL bTransmitKey; 681 NDIS_802_11_WEP_STATUS eEncryptionStatus;
704 682 int bTransmitKey;
705//mike add :save old Encryption 683 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
706 NDIS_802_11_WEP_STATUS eOldEncryptionStatus; 684 SKeyManagement sKey;
707 685 u32 dwIVCounter;
708 SKeyManagement sKey; 686
709 DWORD dwIVCounter; 687
710 688 RC4Ext SBox;
711 689 u8 abyPRNG[WLAN_WEPMAX_KEYLEN+3];
712 RC4Ext SBox; 690 u8 byKeyIndex;
713 BYTE abyPRNG[WLAN_WEPMAX_KEYLEN+3]; 691
714 BYTE byKeyIndex; 692 int bAES;
715 693
716 BOOL bAES; 694 u32 uKeyLength;
717 695 u8 abyKey[WLAN_WEP232_KEYLEN];
718 unsigned int uKeyLength; 696
719 BYTE abyKey[WLAN_WEP232_KEYLEN]; 697 /* for AP mode */
720 698 u32 uAssocCount;
721 // for AP mode 699 int bMoreData;
722 unsigned int uAssocCount; 700
723 BOOL bMoreData; 701 /* QoS */
724 702 int bGrpAckPolicy;
725 // QoS 703
726 BOOL bGrpAckPolicy; 704
727 705 u8 byAutoFBCtrl;
728 706
729 BYTE byAutoFBCtrl; 707 int bTxMICFail;
730 708 int bRxMICFail;
731 BOOL bTxMICFail; 709
732 BOOL bRxMICFail; 710
733 711 /* For Update BaseBand VGA Gain Offset */
734 712 int bUpdateBBVGA;
735 // For Update BaseBand VGA Gain Offset 713 u32 uBBVGADiffCount;
736 BOOL bUpdateBBVGA; 714 u8 byBBVGANew;
737 unsigned int uBBVGADiffCount; 715 u8 byBBVGACurrent;
738 BYTE byBBVGANew; 716 u8 abyBBVGA[BB_VGA_LEVEL];
739 BYTE byBBVGACurrent; 717 signed long ldBmThreshold[BB_VGA_LEVEL];
740 BYTE abyBBVGA[BB_VGA_LEVEL]; 718
741 signed long ldBmThreshold[BB_VGA_LEVEL]; 719 u8 byBBPreEDRSSI;
742 720 u8 byBBPreEDIndex;
743 BYTE byBBPreEDRSSI; 721
744 BYTE byBBPreEDIndex; 722
745 723 int bRadioCmd;
746 724 u32 dwDiagRefCount;
747 BOOL bRadioCmd; 725
748 DWORD dwDiagRefCount; 726 /* For FOE Tuning */
749 727 u8 byFOETuning;
750 // For FOE Tuning 728
751 BYTE byFOETuning; 729 /* For Auto Power Tunning */
730 u8 byAutoPwrTunning;
731
732 /* BaseBand Loopback Use */
733 u8 byBBCR4d;
734 u8 byBBCRc9;
735 u8 byBBCR88;
736 u8 byBBCR09;
737
738 /* command timer */
739 struct timer_list sTimerCommand;
752 740
753 // For Auto Power Tunning 741 struct timer_list sTimerTxData;
742 unsigned long nTxDataTimeCout;
743 int fTxDataInSleep;
744 int IsTxDataTrigger;
754 745
755 BYTE byAutoPwrTunning; 746 int fWPA_Authened; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
747 u8 byReAssocCount;
748 u8 byLinkWaitCount;
756 749
757 // BaseBand Loopback Use 750 SEthernetHeader sTxEthHeader;
758 BYTE byBBCR4d; 751 SEthernetHeader sRxEthHeader;
759 BYTE byBBCRc9; 752 u8 abyBroadcastAddr[ETH_ALEN];
760 BYTE byBBCR88; 753 u8 abySNAP_RFC1042[ETH_ALEN];
761 BYTE byBBCR09; 754 u8 abySNAP_Bridgetunnel[ETH_ALEN];
762 755
763 // command timer 756 /* Pre-Authentication & PMK cache */
764 struct timer_list sTimerCommand; 757 SPMKID gsPMKID;
758 SPMKIDCandidateEvent gsPMKIDCandidate;
765 759
766 struct timer_list sTimerTxData;
767 unsigned long nTxDataTimeCout;
768 BOOL fTxDataInSleep;
769 BOOL IsTxDataTrigger;
770 760
771 BOOL fWPA_Authened; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? 761 /* for 802.11h */
772 BYTE byReAssocCount; //mike add:re-association retry times! 762 int b11hEnable;
773 BYTE byLinkWaitCount;
774 763
775 SEthernetHeader sTxEthHeader; 764 int bChannelSwitch;
776 SEthernetHeader sRxEthHeader; 765 u8 byNewChannel;
777 BYTE abyBroadcastAddr[ETH_ALEN]; 766 u8 byChannelSwitchCount;
778 BYTE abySNAP_RFC1042[ETH_ALEN];
779 BYTE abySNAP_Bridgetunnel[ETH_ALEN];
780 767
781 // Pre-Authentication & PMK cache 768 /* WPA supplicant daemon */
782 SPMKID gsPMKID; 769 int bWPADEVUp;
783 SPMKIDCandidateEvent gsPMKIDCandidate; 770 int bwextstep0;
771 int bwextstep1;
772 int bwextstep2;
773 int bwextstep3;
774 int bWPASuppWextEnabled;
784 775
776 /* user space daemon: hostapd, is used for HOSTAP */
777 int bEnableHostapd;
778 int bEnable8021x;
779 int bEnableHostWEP;
780 struct net_device *apdev;
781 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
785 782
786 // for 802.11h 783 u32 uChannel;
787 BOOL b11hEnable;
788
789 BOOL bChannelSwitch;
790 BYTE byNewChannel;
791 BYTE byChannelSwitchCount;
792 784
793 //WPA supplicant daemon 785 struct iw_statistics wstats; /* wireless stats */
794 struct net_device *wpadev;
795 BOOL bWPADEVUp;
796 //--
797 786
798 BOOL bwextstep0; 787 int bCommit;
799 BOOL bwextstep1;
800 BOOL bwextstep2;
801 BOOL bwextstep3;
802 BOOL bWPASuppWextEnabled;
803 788
804#ifdef HOSTAP 789};
805 // user space daemon: hostapd, is used for HOSTAP
806 BOOL bEnableHostapd;
807 BOOL bEnable8021x;
808 BOOL bEnableHostWEP;
809 struct net_device *apdev;
810 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
811#endif
812 unsigned int uChannel;
813
814 struct iw_statistics wstats; // wireless stats
815 BOOL bCommit;
816
817} DEVICE_INFO, *PSDevice;
818 790
819 791
820 792
@@ -871,9 +843,6 @@ typedef struct __device_info {
871 843
872/*--------------------- Export Functions --------------------------*/ 844/*--------------------- Export Functions --------------------------*/
873 845
874/* BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, 846int device_alloc_frag_buf(struct vnt_private *, PSDeFragControlBlock pDeF);
875 * unsigned int uNodeIndex);
876 */
877BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF);
878 847
879#endif 848#endif
diff --git a/drivers/staging/vt6656/device_cfg.h b/drivers/staging/vt6656/device_cfg.h
index a0b82169dad3..62290d0ac195 100644
--- a/drivers/staging/vt6656/device_cfg.h
+++ b/drivers/staging/vt6656/device_cfg.h
@@ -38,12 +38,12 @@ struct _version {
38 unsigned char build; 38 unsigned char build;
39} version_t, *pversion_t; 39} version_t, *pversion_t;
40 40
41#ifndef FALSE 41#ifndef false
42#define FALSE (0) 42#define false (0)
43#endif 43#endif
44 44
45#ifndef TRUE 45#ifndef true
46#define TRUE (!(FALSE)) 46#define true (!(false))
47#endif 47#endif
48 48
49#define VID_TABLE_SIZE 64 49#define VID_TABLE_SIZE 64
@@ -67,14 +67,14 @@ struct _version {
67#define DEVICE_VERSION "1.19_12" 67#define DEVICE_VERSION "1.19_12"
68#endif 68#endif
69 69
70//config file 70/* config file */
71#include <linux/fs.h> 71#include <linux/fs.h>
72#include <linux/fcntl.h> 72#include <linux/fcntl.h>
73#ifndef CONFIG_PATH 73#ifndef CONFIG_PATH
74#define CONFIG_PATH "/etc/vntconfiguration.dat" 74#define CONFIG_PATH "/etc/vntconfiguration.dat"
75#endif 75#endif
76 76
77//Max: 2378=2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR 77/* Max: 2378 = 2312 Payload + 30HD + 4CRC + 2Padding + 4Len + 8TSF + 4RSR */
78#define PKT_BUF_SZ 2390 78#define PKT_BUF_SZ 2390
79 79
80#define MAX_UINTS 8 80#define MAX_UINTS 8
diff --git a/drivers/staging/vt6656/dpc.c b/drivers/staging/vt6656/dpc.c
index e94f6a1647a3..e83f95e1d9a8 100644
--- a/drivers/staging/vt6656/dpc.c
+++ b/drivers/staging/vt6656/dpc.c
@@ -84,61 +84,23 @@ s_vGetDASA(
84 PSEthernetHeader psEthHeader 84 PSEthernetHeader psEthHeader
85 ); 85 );
86 86
87static 87static void s_vProcessRxMACHeader(struct vnt_private *pDevice,
88void 88 u8 *pbyRxBufferAddr, u32 cbPacketSize, int bIsWEP, int bExtIV,
89s_vProcessRxMACHeader ( 89 u32 *pcbHeadSize);
90 PSDevice pDevice,
91 PBYTE pbyRxBufferAddr,
92 unsigned int cbPacketSize,
93 BOOL bIsWEP,
94 BOOL bExtIV,
95 unsigned int *pcbHeadSize
96 );
97
98static BOOL s_bAPModeRxCtl(
99 PSDevice pDevice,
100 PBYTE pbyFrame,
101 signed int iSANodeIndex
102 );
103
104
105
106static BOOL s_bAPModeRxData (
107 PSDevice pDevice,
108 struct sk_buff *skb,
109 unsigned int FrameSize,
110 unsigned int cbHeaderOffset,
111 signed int iSANodeIndex,
112 signed int iDANodeIndex
113 );
114 90
91static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame,
92 s32 iSANodeIndex);
115 93
116static BOOL s_bHandleRxEncryption( 94static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb,
117 PSDevice pDevice, 95 u32 FrameSize, u32 cbHeaderOffset, s32 iSANodeIndex, s32 iDANodeIndex);
118 PBYTE pbyFrame,
119 unsigned int FrameSize,
120 PBYTE pbyRsr,
121 PBYTE pbyNewRsr,
122 PSKeyItem * pKeyOut,
123 int * pbExtIV,
124 PWORD pwRxTSC15_0,
125 PDWORD pdwRxTSC47_16
126 );
127
128static BOOL s_bHostWepRxEncryption(
129 96
130 PSDevice pDevice, 97static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
131 PBYTE pbyFrame, 98 u32 FrameSize, u8 *pbyRsr, u8 *pbyNewRsr, PSKeyItem *pKeyOut,
132 unsigned int FrameSize, 99 s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16);
133 PBYTE pbyRsr,
134 BOOL bOnFly,
135 PSKeyItem pKey,
136 PBYTE pbyNewRsr,
137 int * pbExtIV,
138 PWORD pwRxTSC15_0,
139 PDWORD pdwRxTSC47_16
140 100
141 ); 101static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
102 u32 FrameSize, u8 *pbyRsr, int bOnFly, PSKeyItem pKey, u8 *pbyNewRsr,
103 s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16);
142 104
143/*--------------------- Export Variables --------------------------*/ 105/*--------------------- Export Variables --------------------------*/
144 106
@@ -159,22 +121,16 @@ static BOOL s_bHostWepRxEncryption(
159 * Return Value: None 121 * Return Value: None
160 * 122 *
161-*/ 123-*/
162static 124
163void 125static void s_vProcessRxMACHeader(struct vnt_private *pDevice,
164s_vProcessRxMACHeader ( 126 u8 *pbyRxBufferAddr, u32 cbPacketSize, int bIsWEP, int bExtIV,
165 PSDevice pDevice, 127 u32 *pcbHeadSize)
166 PBYTE pbyRxBufferAddr,
167 unsigned int cbPacketSize,
168 BOOL bIsWEP,
169 BOOL bExtIV,
170 unsigned int *pcbHeadSize
171 )
172{ 128{
173 PBYTE pbyRxBuffer; 129 u8 *pbyRxBuffer;
174 unsigned int cbHeaderSize = 0; 130 u32 cbHeaderSize = 0;
175 PWORD pwType; 131 u16 *pwType;
176 PS802_11Header pMACHeader; 132 PS802_11Header pMACHeader;
177 int ii; 133 int ii;
178 134
179 135
180 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize); 136 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
@@ -310,56 +266,39 @@ s_vGetDASA (
310} 266}
311 267
312 268
313 269int RXbBulkInProcessData(struct vnt_private *pDevice, PRCB pRCB,
314 270 unsigned long BytesToIndicate)
315BOOL
316RXbBulkInProcessData (
317 PSDevice pDevice,
318 PRCB pRCB,
319 unsigned long BytesToIndicate
320 )
321{ 271{
322 272 struct net_device_stats *pStats = &pDevice->stats;
323 struct net_device_stats* pStats=&pDevice->stats; 273 struct sk_buff *skb;
324 struct sk_buff* skb; 274 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
325 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 275 struct vnt_rx_mgmt *pRxPacket = &pMgmt->sRxPacket;
326 PSRxMgmtPacket pRxPacket = &(pMgmt->sRxPacket); 276 PS802_11Header p802_11Header;
327 PS802_11Header p802_11Header; 277 u8 *pbyRsr, *pbyNewRsr, *pbyRSSI, *pbyFrame;
328 PBYTE pbyRsr; 278 u64 *pqwTSFTime;
329 PBYTE pbyNewRsr; 279 u32 bDeFragRx = false;
330 PBYTE pbyRSSI; 280 u32 cbHeaderOffset, cbIVOffset;
331 PQWORD pqwTSFTime;
332 PBYTE pbyFrame;
333 BOOL bDeFragRx = FALSE;
334 unsigned int cbHeaderOffset;
335 u32 FrameSize; 281 u32 FrameSize;
336 WORD wEtherType = 0; 282 u16 wEtherType = 0;
337 signed int iSANodeIndex = -1; 283 s32 iSANodeIndex = -1, iDANodeIndex = -1;
338 signed int iDANodeIndex = -1; 284 int ii;
339 unsigned int ii; 285 u8 *pbyRxSts, *pbyRxRate, *pbySQ, *pby3SQ;
340 unsigned int cbIVOffset; 286 u32 cbHeaderSize;
341 PBYTE pbyRxSts; 287 PSKeyItem pKey = NULL;
342 PBYTE pbyRxRate; 288 u16 wRxTSC15_0 = 0;
343 PBYTE pbySQ; 289 u32 dwRxTSC47_16 = 0;
344 PBYTE pby3SQ; 290 SKeyItem STempKey;
345 unsigned int cbHeaderSize; 291 /* signed long ldBm = 0; */
346 PSKeyItem pKey = NULL; 292 int bIsWEP = false; int bExtIV = false;
347 WORD wRxTSC15_0 = 0;
348 DWORD dwRxTSC47_16 = 0;
349 SKeyItem STempKey;
350 // 802.11h RPI
351 /* signed long ldBm = 0; */
352 BOOL bIsWEP = FALSE;
353 BOOL bExtIV = FALSE;
354 u32 dwWbkStatus; 293 u32 dwWbkStatus;
355 PRCB pRCBIndicate = pRCB; 294 PRCB pRCBIndicate = pRCB;
356 PBYTE pbyDAddress; 295 u8 *pbyDAddress;
357 PWORD pwPLCP_Length; 296 u16 *pwPLCP_Length;
358 BYTE abyVaildRate[MAX_RATE] = {2,4,11,22,12,18,24,36,48,72,96,108}; 297 u8 abyVaildRate[MAX_RATE]
359 WORD wPLCPwithPadding; 298 = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
360 PS802_11Header pMACHeader; 299 u16 wPLCPwithPadding;
361 BOOL bRxeapol_key = FALSE; 300 PS802_11Header pMACHeader;
362 301 int bRxeapol_key = false;
363 302
364 303
365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n"); 304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n");
@@ -373,13 +312,13 @@ RXbBulkInProcessData (
373 312
374 if (BytesToIndicate != FrameSize) { 313 if (BytesToIndicate != FrameSize) {
375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"------- WRONG Length 1\n"); 314 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"------- WRONG Length 1\n");
376 return FALSE; 315 return false;
377 } 316 }
378 317
379 if ((BytesToIndicate > 2372) || (BytesToIndicate <= 40)) { 318 if ((BytesToIndicate > 2372) || (BytesToIndicate <= 40)) {
380 // Frame Size error drop this packet. 319 // Frame Size error drop this packet.
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n"); 320 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n");
382 return FALSE; 321 return false;
383 } 322 }
384 323
385 pbyDAddress = (PBYTE)(skb->data); 324 pbyDAddress = (PBYTE)(skb->data);
@@ -397,7 +336,7 @@ RXbBulkInProcessData (
397 336
398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong PLCP Length %x\n", (int) *pwPLCP_Length); 337 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong PLCP Length %x\n", (int) *pwPLCP_Length);
399 ASSERT(0); 338 ASSERT(0);
400 return FALSE; 339 return false;
401 } 340 }
402 for ( ii=RATE_1M;ii<MAX_RATE;ii++) { 341 for ( ii=RATE_1M;ii<MAX_RATE;ii++) {
403 if ( *pbyRxRate == abyVaildRate[ii] ) { 342 if ( *pbyRxRate == abyVaildRate[ii] ) {
@@ -406,12 +345,12 @@ RXbBulkInProcessData (
406 } 345 }
407 if ( ii==MAX_RATE ) { 346 if ( ii==MAX_RATE ) {
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong RxRate %x\n",(int) *pbyRxRate); 347 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong RxRate %x\n",(int) *pbyRxRate);
409 return FALSE; 348 return false;
410 } 349 }
411 350
412 wPLCPwithPadding = ( (*pwPLCP_Length / 4) + ( (*pwPLCP_Length % 4) ? 1:0 ) ) *4; 351 wPLCPwithPadding = ( (*pwPLCP_Length / 4) + ( (*pwPLCP_Length % 4) ? 1:0 ) ) *4;
413 352
414 pqwTSFTime = (PQWORD) (pbyDAddress + 8 + wPLCPwithPadding); 353 pqwTSFTime = (u64 *)(pbyDAddress + 8 + wPLCPwithPadding);
415 if(pDevice->byBBType == BB_TYPE_11G) { 354 if(pDevice->byBBType == BB_TYPE_11G) {
416 pby3SQ = pbyDAddress + 8 + wPLCPwithPadding + 12; 355 pby3SQ = pbyDAddress + 8 + wPLCPwithPadding + 12;
417 pbySQ = pby3SQ; 356 pbySQ = pby3SQ;
@@ -455,12 +394,12 @@ RXbBulkInProcessData (
455 if (!is_multicast_ether_addr(pMACHeader->abyAddr1)) { 394 if (!is_multicast_ether_addr(pMACHeader->abyAddr1)) {
456 if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) { 395 if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) {
457 pDevice->s802_11Counter.FrameDuplicateCount++; 396 pDevice->s802_11Counter.FrameDuplicateCount++;
458 return FALSE; 397 return false;
459 } 398 }
460 399
461 if (compare_ether_addr(pDevice->abyCurrentNetAddr, 400 if (compare_ether_addr(pDevice->abyCurrentNetAddr,
462 pMACHeader->abyAddr1)) { 401 pMACHeader->abyAddr1)) {
463 return FALSE; 402 return false;
464 } 403 }
465 } 404 }
466 405
@@ -470,7 +409,7 @@ RXbBulkInProcessData (
470 409
471 if (!compare_ether_addr((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]), 410 if (!compare_ether_addr((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]),
472 pDevice->abyCurrentNetAddr)) 411 pDevice->abyCurrentNetAddr))
473 return FALSE; 412 return false;
474 413
475 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) { 414 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
476 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) { 415 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
@@ -484,17 +423,17 @@ RXbBulkInProcessData (
484 } 423 }
485 424
486 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { 425 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
487 if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == TRUE) { 426 if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == true) {
488 return FALSE; 427 return false;
489 } 428 }
490 } 429 }
491 430
492 431
493 if (IS_FC_WEP(pbyFrame)) { 432 if (IS_FC_WEP(pbyFrame)) {
494 BOOL bRxDecryOK = FALSE; 433 bool bRxDecryOK = false;
495 434
496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n"); 435 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n");
497 bIsWEP = TRUE; 436 bIsWEP = true;
498 if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) { 437 if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
499 pKey = &STempKey; 438 pKey = &STempKey;
500 pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite; 439 pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
@@ -546,11 +485,11 @@ RXbBulkInProcessData (
546// pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++; 485// pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
547 } 486 }
548 } 487 }
549 return FALSE; 488 return false;
550 } 489 }
551 } else { 490 } else {
552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n"); 491 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n");
553 return FALSE; 492 return false;
554 } 493 }
555 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) 494 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
556 FrameSize -= 8; // Message Integrity Code 495 FrameSize -= 8; // Message Integrity Code
@@ -579,14 +518,14 @@ RXbBulkInProcessData (
579 pbyFrame = skb->data + 8; 518 pbyFrame = skb->data + 8;
580 } 519 }
581 else { 520 else {
582 return FALSE; 521 return false;
583 } 522 }
584 } 523 }
585 524
586 // 525 //
587 // Management & Control frame Handle 526 // Management & Control frame Handle
588 // 527 //
589 if ((IS_TYPE_DATA((pbyFrame))) == FALSE) { 528 if ((IS_TYPE_DATA((pbyFrame))) == false) {
590 // Handle Control & Manage Frame 529 // Handle Control & Manage Frame
591 530
592 if (IS_TYPE_MGMT((pbyFrame))) { 531 if (IS_TYPE_MGMT((pbyFrame))) {
@@ -598,8 +537,7 @@ RXbBulkInProcessData (
598 pRxPacket->cbMPDULen = FrameSize; 537 pRxPacket->cbMPDULen = FrameSize;
599 pRxPacket->uRSSI = *pbyRSSI; 538 pRxPacket->uRSSI = *pbyRSSI;
600 pRxPacket->bySQ = *pbySQ; 539 pRxPacket->bySQ = *pbySQ;
601 HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime)); 540 pRxPacket->qwLocalTSF = cpu_to_le64(*pqwTSFTime);
602 LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
603 if (bIsWEP) { 541 if (bIsWEP) {
604 // strip IV 542 // strip IV
605 pbyData1 = WLAN_HDR_A3_DATA_PTR(pbyFrame); 543 pbyData1 = WLAN_HDR_A3_DATA_PTR(pbyFrame);
@@ -617,7 +555,7 @@ RXbBulkInProcessData (
617 //Discard beacon packet which channel is 0 555 //Discard beacon packet which channel is 0
618 if ( (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_BEACON) || 556 if ( (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_BEACON) ||
619 (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_PROBERESP) ) { 557 (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_PROBERESP) ) {
620 return FALSE; 558 return false;
621 } 559 }
622 } 560 }
623 pRxPacket->byRxChannel = (*pbyRxSts) >> 2; 561 pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
@@ -635,7 +573,7 @@ RXbBulkInProcessData (
635 skb->protocol = htons(ETH_P_802_2); 573 skb->protocol = htons(ETH_P_802_2);
636 memset(skb->cb, 0, sizeof(skb->cb)); 574 memset(skb->cb, 0, sizeof(skb->cb));
637 netif_rx(skb); 575 netif_rx(skb);
638 return TRUE; 576 return true;
639 } 577 }
640 578
641 // 579 //
@@ -643,11 +581,11 @@ RXbBulkInProcessData (
643 // 581 //
644 EnqueueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList, pRCBIndicate); 582 EnqueueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList, pRCBIndicate);
645 pDevice->NumRecvMngList++; 583 pDevice->NumRecvMngList++;
646 if ( bDeFragRx == FALSE) { 584 if ( bDeFragRx == false) {
647 pRCB->Ref++; 585 pRCB->Ref++;
648 } 586 }
649 if (pDevice->bIsRxMngWorkItemQueued == FALSE) { 587 if (pDevice->bIsRxMngWorkItemQueued == false) {
650 pDevice->bIsRxMngWorkItemQueued = TRUE; 588 pDevice->bIsRxMngWorkItemQueued = true;
651 tasklet_schedule(&pDevice->RxMngWorkItem); 589 tasklet_schedule(&pDevice->RxMngWorkItem);
652 } 590 }
653 591
@@ -655,7 +593,7 @@ RXbBulkInProcessData (
655 else { 593 else {
656 // Control Frame 594 // Control Frame
657 }; 595 };
658 return FALSE; 596 return false;
659 } 597 }
660 else { 598 else {
661 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { 599 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
@@ -667,12 +605,12 @@ RXbBulkInProcessData (
667 pDevice->dev->name); 605 pDevice->dev->name);
668 } 606 }
669 } 607 }
670 return FALSE; 608 return false;
671 } 609 }
672 } 610 }
673 else { 611 else {
674 // discard DATA packet while not associate || BSSID error 612 // discard DATA packet while not associate || BSSID error
675 if ((pDevice->bLinkPass == FALSE) || 613 if ((pDevice->bLinkPass == false) ||
676 !(*pbyRsr & RSR_BSSIDOK)) { 614 !(*pbyRsr & RSR_BSSIDOK)) {
677 if (bDeFragRx) { 615 if (bDeFragRx) {
678 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) { 616 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
@@ -680,7 +618,7 @@ RXbBulkInProcessData (
680 pDevice->dev->name); 618 pDevice->dev->name);
681 } 619 }
682 } 620 }
683 return FALSE; 621 return false;
684 } 622 }
685 //mike add:station mode check eapol-key challenge---> 623 //mike add:station mode check eapol-key challenge--->
686 { 624 {
@@ -699,7 +637,7 @@ RXbBulkInProcessData (
699 if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header 637 if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header
700 if(((Protocol_Version==1) ||(Protocol_Version==2)) && 638 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
701 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame receive 639 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame receive
702 bRxeapol_key = TRUE; 640 bRxeapol_key = true;
703 Descriptor_type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2]; 641 Descriptor_type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2];
704 Key_info = (skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+1]<<8) |skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+2] ; 642 Key_info = (skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+1]<<8) |skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+2] ;
705 if(Descriptor_type==2) { //RSN 643 if(Descriptor_type==2) { //RSN
@@ -726,8 +664,8 @@ RXbBulkInProcessData (
726 } 664 }
727 } 665 }
728 else { 666 else {
729 if (pMgmt->bInTIMWake == TRUE) { 667 if (pMgmt->bInTIMWake == true) {
730 pMgmt->bInTIMWake = FALSE; 668 pMgmt->bInTIMWake = false;
731 } 669 }
732 } 670 }
733 } 671 }
@@ -735,7 +673,7 @@ RXbBulkInProcessData (
735 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps 673 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
736 if (pDevice->bDiversityEnable && (FrameSize>50) && 674 if (pDevice->bDiversityEnable && (FrameSize>50) &&
737 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) && 675 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
738 (pDevice->bLinkPass == TRUE)) { 676 (pDevice->bLinkPass == true)) {
739 BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0); 677 BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
740 } 678 }
741 679
@@ -764,7 +702,7 @@ RXbBulkInProcessData (
764 702
765 // ----------------------------------------------- 703 // -----------------------------------------------
766 704
767 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == TRUE)){ 705 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == true)){
768 BYTE abyMacHdr[24]; 706 BYTE abyMacHdr[24];
769 707
770 // Only 802.1x packet incoming allowed 708 // Only 802.1x packet incoming allowed
@@ -779,7 +717,7 @@ RXbBulkInProcessData (
779 if (wEtherType == ETH_P_PAE) { 717 if (wEtherType == ETH_P_PAE) {
780 skb->dev = pDevice->apdev; 718 skb->dev = pDevice->apdev;
781 719
782 if (bIsWEP == TRUE) { 720 if (bIsWEP == true) {
783 // strip IV header(8) 721 // strip IV header(8)
784 memcpy(&abyMacHdr[0], (skb->data + 8), 24); 722 memcpy(&abyMacHdr[0], (skb->data + 8), 24);
785 memcpy((skb->data + 8 + cbIVOffset), &abyMacHdr[0], 24); 723 memcpy((skb->data + 8 + cbIVOffset), &abyMacHdr[0], 24);
@@ -793,12 +731,12 @@ RXbBulkInProcessData (
793 skb->protocol = htons(ETH_P_802_2); 731 skb->protocol = htons(ETH_P_802_2);
794 memset(skb->cb, 0, sizeof(skb->cb)); 732 memset(skb->cb, 0, sizeof(skb->cb));
795 netif_rx(skb); 733 netif_rx(skb);
796 return TRUE; 734 return true;
797 735
798 } 736 }
799 // check if 802.1x authorized 737 // check if 802.1x authorized
800 if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED)) 738 if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
801 return FALSE; 739 return false;
802 } 740 }
803 741
804 742
@@ -852,9 +790,9 @@ RXbBulkInProcessData (
852 790
853 791
854 if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) || 792 if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
855 (pDevice->bRxMICFail == TRUE)) { 793 (pDevice->bRxMICFail == true)) {
856 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n"); 794 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n");
857 pDevice->bRxMICFail = FALSE; 795 pDevice->bRxMICFail = false;
858 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++; 796 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
859 pDevice->s802_11Counter.TKIPLocalMICFailures++; 797 pDevice->s802_11Counter.TKIPLocalMICFailures++;
860 if (bDeFragRx) { 798 if (bDeFragRx) {
@@ -864,7 +802,7 @@ RXbBulkInProcessData (
864 } 802 }
865 } 803 }
866 //send event to wpa_supplicant 804 //send event to wpa_supplicant
867 //if(pDevice->bWPASuppWextEnabled == TRUE) 805 //if(pDevice->bWPASuppWextEnabled == true)
868 { 806 {
869 union iwreq_data wrqu; 807 union iwreq_data wrqu;
870 struct iw_michaelmicfailure ev; 808 struct iw_michaelmicfailure ev;
@@ -888,7 +826,7 @@ RXbBulkInProcessData (
888 826
889 } 827 }
890 828
891 return FALSE; 829 return false;
892 830
893 } 831 }
894 } 832 }
@@ -910,11 +848,11 @@ RXbBulkInProcessData (
910 RSC = dwRxTSC47_16; 848 RSC = dwRxTSC47_16;
911 RSC <<= 16; 849 RSC <<= 16;
912 RSC += wRxTSC15_0; 850 RSC += wRxTSC15_0;
913 memcpy(&(pKey->KeyRSC), &RSC, sizeof(QWORD)); 851 memcpy(&(pKey->KeyRSC), &RSC, sizeof(u64));
914 852
915 if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) && 853 if (pDevice->vnt_mgmt.eCurrMode == WMAC_MODE_ESS_STA &&
916 (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) { 854 pDevice->vnt_mgmt.eCurrState == WMAC_STATE_ASSOC) {
917 // check RSC 855 /* check RSC */
918 if ( (wRxTSC15_0 < wLocalTSC15_0) && 856 if ( (wRxTSC15_0 < wLocalTSC15_0) &&
919 (dwRxTSC47_16 <= dwLocalTSC47_16) && 857 (dwRxTSC47_16 <= dwLocalTSC47_16) &&
920 !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) { 858 !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
@@ -932,7 +870,7 @@ RXbBulkInProcessData (
932 pDevice->dev->name); 870 pDevice->dev->name);
933 } 871 }
934 } 872 }
935 return FALSE; 873 return false;
936 } 874 }
937 } 875 }
938 } 876 }
@@ -945,7 +883,7 @@ RXbBulkInProcessData (
945 883
946 // Null data, framesize = 12 884 // Null data, framesize = 12
947 if (FrameSize < 12) 885 if (FrameSize < 12)
948 return FALSE; 886 return false;
949 887
950 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { 888 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
951 if (s_bAPModeRxData(pDevice, 889 if (s_bAPModeRxData(pDevice,
@@ -954,7 +892,7 @@ RXbBulkInProcessData (
954 cbHeaderOffset, 892 cbHeaderOffset,
955 iSANodeIndex, 893 iSANodeIndex,
956 iDANodeIndex 894 iDANodeIndex
957 ) == FALSE) { 895 ) == false) {
958 896
959 if (bDeFragRx) { 897 if (bDeFragRx) {
960 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) { 898 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
@@ -962,7 +900,7 @@ RXbBulkInProcessData (
962 pDevice->dev->name); 900 pDevice->dev->name);
963 } 901 }
964 } 902 }
965 return FALSE; 903 return false;
966 } 904 }
967 905
968 } 906 }
@@ -980,22 +918,18 @@ RXbBulkInProcessData (
980 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n", 918 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
981 pDevice->dev->name); 919 pDevice->dev->name);
982 } 920 }
983 return FALSE; 921 return false;
984 } 922 }
985 923
986 return TRUE; 924 return true;
987} 925}
988 926
989 927static int s_bAPModeRxCtl(struct vnt_private *pDevice, u8 *pbyFrame,
990static BOOL s_bAPModeRxCtl ( 928 s32 iSANodeIndex)
991 PSDevice pDevice,
992 PBYTE pbyFrame,
993 signed int iSANodeIndex
994 )
995{ 929{
996 PS802_11Header p802_11Header; 930 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
997 CMD_STATUS Status; 931 PS802_11Header p802_11Header;
998 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 932 CMD_STATUS Status;
999 933
1000 934
1001 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) { 935 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
@@ -1017,7 +951,7 @@ static BOOL s_bAPModeRxCtl (
1017 &Status 951 &Status
1018 ); 952 );
1019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n"); 953 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
1020 return TRUE; 954 return true;
1021 } 955 }
1022 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) { 956 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
1023 // send deassoc notification 957 // send deassoc notification
@@ -1029,13 +963,13 @@ static BOOL s_bAPModeRxCtl (
1029 &Status 963 &Status
1030 ); 964 );
1031 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n"); 965 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
1032 return TRUE; 966 return true;
1033 } 967 }
1034 968
1035 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) { 969 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
1036 // delcare received ps-poll event 970 // delcare received ps-poll event
1037 if (IS_CTL_PSPOLL(pbyFrame)) { 971 if (IS_CTL_PSPOLL(pbyFrame)) {
1038 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; 972 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
1039 bScheduleCommand((void *) pDevice, 973 bScheduleCommand((void *) pDevice,
1040 WLAN_CMD_RX_PSPOLL, 974 WLAN_CMD_RX_PSPOLL,
1041 NULL); 975 NULL);
@@ -1045,8 +979,8 @@ static BOOL s_bAPModeRxCtl (
1045 // check Data PS state 979 // check Data PS state
1046 // if PW bit off, send out all PS bufferring packets. 980 // if PW bit off, send out all PS bufferring packets.
1047 if (!IS_FC_POWERMGT(pbyFrame)) { 981 if (!IS_FC_POWERMGT(pbyFrame)) {
1048 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE; 982 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
1049 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; 983 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
1050 bScheduleCommand((void *) pDevice, 984 bScheduleCommand((void *) pDevice,
1051 WLAN_CMD_RX_PSPOLL, 985 WLAN_CMD_RX_PSPOLL,
1052 NULL); 986 NULL);
@@ -1056,15 +990,15 @@ static BOOL s_bAPModeRxCtl (
1056 } 990 }
1057 else { 991 else {
1058 if (IS_FC_POWERMGT(pbyFrame)) { 992 if (IS_FC_POWERMGT(pbyFrame)) {
1059 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = TRUE; 993 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = true;
1060 // Once if STA in PS state, enable multicast bufferring 994 // Once if STA in PS state, enable multicast bufferring
1061 pMgmt->sNodeDBTable[0].bPSEnable = TRUE; 995 pMgmt->sNodeDBTable[0].bPSEnable = true;
1062 } 996 }
1063 else { 997 else {
1064 // clear all pending PS frame. 998 // clear all pending PS frame.
1065 if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) { 999 if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
1066 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE; 1000 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
1067 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE; 1001 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
1068 bScheduleCommand((void *) pDevice, 1002 bScheduleCommand((void *) pDevice,
1069 WLAN_CMD_RX_PSPOLL, 1003 WLAN_CMD_RX_PSPOLL,
1070 NULL); 1004 NULL);
@@ -1089,32 +1023,24 @@ static BOOL s_bAPModeRxCtl (
1089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n", 1023 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
1090 p802_11Header->abyAddr1); 1024 p802_11Header->abyAddr1);
1091 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl ); 1025 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
1092 return TRUE; 1026 return true;
1093 } 1027 }
1094 } 1028 }
1095 } 1029 }
1096 return FALSE; 1030 return false;
1097 1031
1098} 1032}
1099 1033
1100static BOOL s_bHandleRxEncryption ( 1034static int s_bHandleRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
1101 PSDevice pDevice, 1035 u32 FrameSize, u8 *pbyRsr, u8 *pbyNewRsr, PSKeyItem *pKeyOut,
1102 PBYTE pbyFrame, 1036 s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16)
1103 unsigned int FrameSize,
1104 PBYTE pbyRsr,
1105 PBYTE pbyNewRsr,
1106 PSKeyItem * pKeyOut,
1107 int * pbExtIV,
1108 PWORD pwRxTSC15_0,
1109 PDWORD pdwRxTSC47_16
1110 )
1111{ 1037{
1112 unsigned int PayloadLen = FrameSize; 1038 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1113 PBYTE pbyIV; 1039 u32 PayloadLen = FrameSize;
1114 BYTE byKeyIdx; 1040 u8 *pbyIV;
1115 PSKeyItem pKey = NULL; 1041 u8 byKeyIdx;
1116 BYTE byDecMode = KEY_CTL_WEP; 1042 PSKeyItem pKey = NULL;
1117 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1043 u8 byDecMode = KEY_CTL_WEP;
1118 1044
1119 1045
1120 *pwRxTSC15_0 = 0; 1046 *pwRxTSC15_0 = 0;
@@ -1139,7 +1065,7 @@ static BOOL s_bHandleRxEncryption (
1139 (pMgmt->byCSSPK != KEY_CTL_NONE)) { 1065 (pMgmt->byCSSPK != KEY_CTL_NONE)) {
1140 // unicast pkt use pairwise key 1066 // unicast pkt use pairwise key
1141 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n"); 1067 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n");
1142 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == TRUE) { 1068 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == true) {
1143 if (pMgmt->byCSSPK == KEY_CTL_TKIP) 1069 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
1144 byDecMode = KEY_CTL_TKIP; 1070 byDecMode = KEY_CTL_TKIP;
1145 else if (pMgmt->byCSSPK == KEY_CTL_CCMP) 1071 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
@@ -1173,24 +1099,24 @@ static BOOL s_bHandleRxEncryption (
1173 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n"); 1099 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n");
1174 if (byDecMode == KEY_CTL_WEP) { 1100 if (byDecMode == KEY_CTL_WEP) {
1175// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++; 1101// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1176 } else if (pDevice->bLinkPass == TRUE) { 1102 } else if (pDevice->bLinkPass == true) {
1177// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; 1103// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1178 } 1104 }
1179 return FALSE; 1105 return false;
1180 } 1106 }
1181 if (byDecMode != pKey->byCipherSuite) { 1107 if (byDecMode != pKey->byCipherSuite) {
1182 if (byDecMode == KEY_CTL_WEP) { 1108 if (byDecMode == KEY_CTL_WEP) {
1183// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++; 1109// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1184 } else if (pDevice->bLinkPass == TRUE) { 1110 } else if (pDevice->bLinkPass == true) {
1185// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; 1111// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1186 } 1112 }
1187 *pKeyOut = NULL; 1113 *pKeyOut = NULL;
1188 return FALSE; 1114 return false;
1189 } 1115 }
1190 if (byDecMode == KEY_CTL_WEP) { 1116 if (byDecMode == KEY_CTL_WEP) {
1191 // handle WEP 1117 // handle WEP
1192 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || 1118 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1193 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE)) { 1119 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true)) {
1194 // Software WEP 1120 // Software WEP
1195 // 1. 3253A 1121 // 1. 3253A
1196 // 2. WEP 256 1122 // 2. WEP 256
@@ -1238,35 +1164,23 @@ static BOOL s_bHandleRxEncryption (
1238 }// end of TKIP/AES 1164 }// end of TKIP/AES
1239 1165
1240 if ((*(pbyIV+3) & 0x20) != 0) 1166 if ((*(pbyIV+3) & 0x20) != 0)
1241 *pbExtIV = TRUE; 1167 *pbExtIV = true;
1242 return TRUE; 1168 return true;
1243} 1169}
1244 1170
1245 1171static int s_bHostWepRxEncryption(struct vnt_private *pDevice, u8 *pbyFrame,
1246static BOOL s_bHostWepRxEncryption ( 1172 u32 FrameSize, u8 *pbyRsr, int bOnFly, PSKeyItem pKey, u8 *pbyNewRsr,
1247 PSDevice pDevice, 1173 s32 *pbExtIV, u16 *pwRxTSC15_0, u32 *pdwRxTSC47_16)
1248 PBYTE pbyFrame,
1249 unsigned int FrameSize,
1250 PBYTE pbyRsr,
1251 BOOL bOnFly,
1252 PSKeyItem pKey,
1253 PBYTE pbyNewRsr,
1254 int * pbExtIV,
1255 PWORD pwRxTSC15_0,
1256 PDWORD pdwRxTSC47_16
1257 )
1258{ 1174{
1259 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1175 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1260 unsigned int PayloadLen = FrameSize; 1176 PS802_11Header pMACHeader;
1261 PBYTE pbyIV; 1177 u32 PayloadLen = FrameSize;
1262 BYTE byKeyIdx; 1178 u8 *pbyIV;
1263 BYTE byDecMode = KEY_CTL_WEP; 1179 u8 byKeyIdx;
1264 PS802_11Header pMACHeader; 1180 u8 byDecMode = KEY_CTL_WEP;
1265
1266
1267 1181
1268 *pwRxTSC15_0 = 0; 1182 *pwRxTSC15_0 = 0;
1269 *pdwRxTSC47_16 = 0; 1183 *pdwRxTSC47_16 = 0;
1270 1184
1271 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN; 1185 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1272 if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) && 1186 if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
@@ -1289,18 +1203,18 @@ static BOOL s_bHostWepRxEncryption (
1289 if (byDecMode != pKey->byCipherSuite) { 1203 if (byDecMode != pKey->byCipherSuite) {
1290 if (byDecMode == KEY_CTL_WEP) { 1204 if (byDecMode == KEY_CTL_WEP) {
1291// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++; 1205// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1292 } else if (pDevice->bLinkPass == TRUE) { 1206 } else if (pDevice->bLinkPass == true) {
1293// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++; 1207// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1294 } 1208 }
1295 return FALSE; 1209 return false;
1296 } 1210 }
1297 1211
1298 if (byDecMode == KEY_CTL_WEP) { 1212 if (byDecMode == KEY_CTL_WEP) {
1299 // handle WEP 1213 // handle WEP
1300 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n"); 1214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n");
1301 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || 1215 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1302 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE) || 1216 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true) ||
1303 (bOnFly == FALSE)) { 1217 (bOnFly == false)) {
1304 // Software WEP 1218 // Software WEP
1305 // 1. 3253A 1219 // 1. 3253A
1306 // 2. WEP 256 1220 // 2. WEP 256
@@ -1333,7 +1247,7 @@ static BOOL s_bHostWepRxEncryption (
1333 1247
1334 if (byDecMode == KEY_CTL_TKIP) { 1248 if (byDecMode == KEY_CTL_TKIP) {
1335 1249
1336 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == FALSE)) { 1250 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == false)) {
1337 // Software TKIP 1251 // Software TKIP
1338 // 1. 3253 A 1252 // 1. 3253 A
1339 // 2. NotOnFly 1253 // 2. NotOnFly
@@ -1353,7 +1267,7 @@ static BOOL s_bHostWepRxEncryption (
1353 } 1267 }
1354 1268
1355 if (byDecMode == KEY_CTL_CCMP) { 1269 if (byDecMode == KEY_CTL_CCMP) {
1356 if (bOnFly == FALSE) { 1270 if (bOnFly == false) {
1357 // Software CCMP 1271 // Software CCMP
1358 // NotOnFly 1272 // NotOnFly
1359 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n"); 1273 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n");
@@ -1369,33 +1283,23 @@ static BOOL s_bHostWepRxEncryption (
1369 }// end of TKIP/AES 1283 }// end of TKIP/AES
1370 1284
1371 if ((*(pbyIV+3) & 0x20) != 0) 1285 if ((*(pbyIV+3) & 0x20) != 0)
1372 *pbExtIV = TRUE; 1286 *pbExtIV = true;
1373 return TRUE; 1287 return true;
1374} 1288}
1375 1289
1376 1290static int s_bAPModeRxData(struct vnt_private *pDevice, struct sk_buff *skb,
1377 1291 u32 FrameSize, u32 cbHeaderOffset, s32 iSANodeIndex, s32 iDANodeIndex)
1378static BOOL s_bAPModeRxData (
1379 PSDevice pDevice,
1380 struct sk_buff *skb,
1381 unsigned int FrameSize,
1382 unsigned int cbHeaderOffset,
1383 signed int iSANodeIndex,
1384 signed int iDANodeIndex
1385 )
1386
1387{ 1292{
1388 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1293 struct sk_buff *skbcpy;
1389 BOOL bRelayAndForward = FALSE; 1294 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1390 BOOL bRelayOnly = FALSE; 1295 int bRelayAndForward = false;
1391 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; 1296 int bRelayOnly = false;
1392 WORD wAID; 1297 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1393 1298 u16 wAID;
1394 1299
1395 struct sk_buff* skbcpy = NULL;
1396 1300
1397 if (FrameSize > CB_MAX_BUF_SIZE) 1301 if (FrameSize > CB_MAX_BUF_SIZE)
1398 return FALSE; 1302 return false;
1399 // check DA 1303 // check DA
1400 if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) { 1304 if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) {
1401 if (pMgmt->sNodeDBTable[0].bPSEnable) { 1305 if (pMgmt->sNodeDBTable[0].bPSEnable) {
@@ -1417,7 +1321,7 @@ static BOOL s_bAPModeRxData (
1417 } 1321 }
1418 } 1322 }
1419 else { 1323 else {
1420 bRelayAndForward = TRUE; 1324 bRelayAndForward = true;
1421 } 1325 }
1422 } 1326 }
1423 else { 1327 else {
@@ -1437,10 +1341,10 @@ static BOOL s_bAPModeRxData (
1437 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7]; 1341 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n", 1342 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1439 iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]); 1343 iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1440 return TRUE; 1344 return true;
1441 } 1345 }
1442 else { 1346 else {
1443 bRelayOnly = TRUE; 1347 bRelayOnly = true;
1444 } 1348 }
1445 } 1349 }
1446 } 1350 }
@@ -1457,23 +1361,22 @@ static BOOL s_bAPModeRxData (
1457 } 1361 }
1458 1362
1459 if (bRelayOnly) 1363 if (bRelayOnly)
1460 return FALSE; 1364 return false;
1461 } 1365 }
1462 // none associate, don't forward 1366 // none associate, don't forward
1463 if (pDevice->uAssocCount == 0) 1367 if (pDevice->uAssocCount == 0)
1464 return FALSE; 1368 return false;
1465 1369
1466 return TRUE; 1370 return true;
1467} 1371}
1468 1372
1469 1373
1470 1374
1471 1375
1472void RXvWorkItem(void *Context) 1376void RXvWorkItem(struct vnt_private *pDevice)
1473{ 1377{
1474 PSDevice pDevice = (PSDevice) Context; 1378 int ntStatus;
1475 int ntStatus; 1379 PRCB pRCB = NULL;
1476 PRCB pRCB=NULL;
1477 1380
1478 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Polling Thread\n"); 1381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Polling Thread\n");
1479 spin_lock_irq(&pDevice->lock); 1382 spin_lock_irq(&pDevice->lock);
@@ -1487,19 +1390,15 @@ void RXvWorkItem(void *Context)
1487 DequeueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList); 1390 DequeueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList);
1488 ntStatus = PIPEnsBulkInUsbRead(pDevice, pRCB); 1391 ntStatus = PIPEnsBulkInUsbRead(pDevice, pRCB);
1489 } 1392 }
1490 pDevice->bIsRxWorkItemQueued = FALSE; 1393 pDevice->bIsRxWorkItemQueued = false;
1491 spin_unlock_irq(&pDevice->lock); 1394 spin_unlock_irq(&pDevice->lock);
1492 1395
1493} 1396}
1494 1397
1495 1398
1496void 1399void RXvFreeRCB(PRCB pRCB, int bReAllocSkb)
1497RXvFreeRCB(
1498 PRCB pRCB,
1499 BOOL bReAllocSkb
1500 )
1501{ 1400{
1502 PSDevice pDevice = (PSDevice)pRCB->pDevice; 1401 struct vnt_private *pDevice = pRCB->pDevice;
1503 1402
1504 1403
1505 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n"); 1404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n");
@@ -1507,12 +1406,12 @@ RXvFreeRCB(
1507 ASSERT(!pRCB->Ref); // should be 0 1406 ASSERT(!pRCB->Ref); // should be 0
1508 ASSERT(pRCB->pDevice); // shouldn't be NULL 1407 ASSERT(pRCB->pDevice); // shouldn't be NULL
1509 1408
1510 if (bReAllocSkb == FALSE) { 1409 if (bReAllocSkb == false) {
1511 kfree_skb(pRCB->skb); 1410 kfree_skb(pRCB->skb);
1512 bReAllocSkb = TRUE; 1411 bReAllocSkb = true;
1513 } 1412 }
1514 1413
1515 if (bReAllocSkb == TRUE) { 1414 if (bReAllocSkb == true) {
1516 pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); 1415 pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1517 // todo error handling 1416 // todo error handling
1518 if (pRCB->skb == NULL) { 1417 if (pRCB->skb == NULL) {
@@ -1529,21 +1428,20 @@ RXvFreeRCB(
1529 1428
1530 1429
1531 if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) && 1430 if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) &&
1532 (pDevice->bIsRxWorkItemQueued == FALSE) ) { 1431 (pDevice->bIsRxWorkItemQueued == false) ) {
1533 1432
1534 pDevice->bIsRxWorkItemQueued = TRUE; 1433 pDevice->bIsRxWorkItemQueued = true;
1535 tasklet_schedule(&pDevice->ReadWorkItem); 1434 tasklet_schedule(&pDevice->ReadWorkItem);
1536 } 1435 }
1537 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList); 1436 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
1538} 1437}
1539 1438
1540 1439
1541void RXvMngWorkItem(void *Context) 1440void RXvMngWorkItem(struct vnt_private *pDevice)
1542{ 1441{
1543 PSDevice pDevice = (PSDevice) Context; 1442 PRCB pRCB = NULL;
1544 PRCB pRCB=NULL; 1443 struct vnt_rx_mgmt *pRxPacket;
1545 PSRxMgmtPacket pRxPacket; 1444 int bReAllocSkb = false;
1546 BOOL bReAllocSkb = FALSE;
1547 1445
1548 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n"); 1446 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n");
1549 1447
@@ -1558,7 +1456,7 @@ void RXvMngWorkItem(void *Context)
1558 } 1456 }
1559 ASSERT(pRCB);// cannot be NULL 1457 ASSERT(pRCB);// cannot be NULL
1560 pRxPacket = &(pRCB->sMngPacket); 1458 pRxPacket = &(pRCB->sMngPacket);
1561 vMgrRxManagePacket((void *) pDevice, &(pDevice->sMgmtObj), pRxPacket); 1459 vMgrRxManagePacket(pDevice, &pDevice->vnt_mgmt, pRxPacket);
1562 pRCB->Ref--; 1460 pRCB->Ref--;
1563 if(pRCB->Ref == 0) { 1461 if(pRCB->Ref == 0) {
1564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeMng %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList); 1462 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeMng %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
@@ -1568,7 +1466,7 @@ void RXvMngWorkItem(void *Context)
1568 } 1466 }
1569 } 1467 }
1570 1468
1571 pDevice->bIsRxMngWorkItemQueued = FALSE; 1469 pDevice->bIsRxMngWorkItemQueued = false;
1572 spin_unlock_irq(&pDevice->lock); 1470 spin_unlock_irq(&pDevice->lock);
1573 1471
1574} 1472}
diff --git a/drivers/staging/vt6656/dpc.h b/drivers/staging/vt6656/dpc.h
index d4fca43af4fe..786c523f5479 100644
--- a/drivers/staging/vt6656/dpc.h
+++ b/drivers/staging/vt6656/dpc.h
@@ -45,17 +45,9 @@ void RXvWorkItem(void *Context);
45 45
46void RXvMngWorkItem(void *Context); 46void RXvMngWorkItem(void *Context);
47 47
48void 48void RXvFreeRCB(PRCB pRCB, int bReAllocSkb);
49RXvFreeRCB( 49
50 PRCB pRCB, 50int RXbBulkInProcessData(struct vnt_private *, PRCB pRCB,
51 BOOL bReAllocSkb 51 unsigned long BytesToIndicate);
52 );
53
54BOOL
55RXbBulkInProcessData(
56 PSDevice pDevice,
57 PRCB pRCB,
58 unsigned long BytesToIndicate
59 );
60 52
61#endif /* __RXTX_H__ */ 53#endif /* __RXTX_H__ */
diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c
index 8831ea03c001..4371a77e9adc 100644
--- a/drivers/staging/vt6656/firmware.c
+++ b/drivers/staging/vt6656/firmware.c
@@ -56,16 +56,13 @@ static int msglevel =MSG_LEVEL_INFO;
56/*--------------------- Export Functions --------------------------*/ 56/*--------------------- Export Functions --------------------------*/
57 57
58 58
59BOOL 59int FIRMWAREbDownload(struct vnt_private *pDevice)
60FIRMWAREbDownload(
61 PSDevice pDevice
62 )
63{ 60{
64 struct device *dev = &pDevice->usb->dev; 61 struct device *dev = &pDevice->usb->dev;
65 const struct firmware *fw; 62 const struct firmware *fw;
66 int NdisStatus; 63 int NdisStatus;
67 void *pBuffer = NULL; 64 void *pBuffer = NULL;
68 BOOL result = FALSE; 65 bool result = false;
69 u16 wLength; 66 u16 wLength;
70 int ii, rc; 67 int ii, rc;
71 68
@@ -102,7 +99,7 @@ FIRMWAREbDownload(
102 goto free_fw; 99 goto free_fw;
103 } 100 }
104 101
105 result = TRUE; 102 result = true;
106free_fw: 103free_fw:
107 release_firmware(fw); 104 release_firmware(fw);
108 105
@@ -114,12 +111,9 @@ out:
114} 111}
115MODULE_FIRMWARE(FIRMWARE_NAME); 112MODULE_FIRMWARE(FIRMWARE_NAME);
116 113
117BOOL 114int FIRMWAREbBrach2Sram(struct vnt_private *pDevice)
118FIRMWAREbBrach2Sram(
119 PSDevice pDevice
120 )
121{ 115{
122 int NdisStatus; 116 int NdisStatus;
123 117
124 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n"); 118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Branch to Sram\n");
125 119
@@ -132,17 +126,14 @@ FIRMWAREbBrach2Sram(
132 ); 126 );
133 127
134 if (NdisStatus != STATUS_SUCCESS) { 128 if (NdisStatus != STATUS_SUCCESS) {
135 return (FALSE); 129 return (false);
136 } else { 130 } else {
137 return (TRUE); 131 return (true);
138 } 132 }
139} 133}
140 134
141 135
142BOOL 136int FIRMWAREbCheckVersion(struct vnt_private *pDevice)
143FIRMWAREbCheckVersion(
144 PSDevice pDevice
145 )
146{ 137{
147 int ntStatus; 138 int ntStatus;
148 139
@@ -156,17 +147,17 @@ FIRMWAREbCheckVersion(
156 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion); 147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
157 if (ntStatus != STATUS_SUCCESS) { 148 if (ntStatus != STATUS_SUCCESS) {
158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n"); 149 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Invalid.\n");
159 return FALSE; 150 return false;
160 } 151 }
161 if (pDevice->wFirmwareVersion == 0xFFFF) { 152 if (pDevice->wFirmwareVersion == 0xFFFF) {
162 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n"); 153 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"In Loader.\n");
163 return FALSE; 154 return false;
164 } 155 }
165 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion); 156 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Firmware Version [%04x]\n", pDevice->wFirmwareVersion);
166 if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) { 157 if (pDevice->wFirmwareVersion < FIRMWARE_VERSION) {
167 // branch to loader for download new firmware 158 // branch to loader for download new firmware
168 FIRMWAREbBrach2Sram(pDevice); 159 FIRMWAREbBrach2Sram(pDevice);
169 return FALSE; 160 return false;
170 } 161 }
171 return TRUE; 162 return true;
172} 163}
diff --git a/drivers/staging/vt6656/firmware.h b/drivers/staging/vt6656/firmware.h
index b2f5b5818a93..ebab3a6351b3 100644
--- a/drivers/staging/vt6656/firmware.h
+++ b/drivers/staging/vt6656/firmware.h
@@ -41,19 +41,8 @@
41 41
42/*--------------------- Export Functions --------------------------*/ 42/*--------------------- Export Functions --------------------------*/
43 43
44BOOL 44int FIRMWAREbDownload(struct vnt_private *);
45FIRMWAREbDownload( 45int FIRMWAREbBrach2Sram(struct vnt_private *);
46 PSDevice pDevice 46int FIRMWAREbCheckVersion(struct vnt_private *);
47 );
48
49BOOL
50FIRMWAREbBrach2Sram(
51 PSDevice pDevice
52 );
53
54BOOL
55FIRMWAREbCheckVersion(
56 PSDevice pDevice
57 );
58 47
59#endif /* __FIRMWARE_H__ */ 48#endif /* __FIRMWARE_H__ */
diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
index 26a7d0e4b048..bc5e9da47586 100644
--- a/drivers/staging/vt6656/hostap.c
+++ b/drivers/staging/vt6656/hostap.c
@@ -60,13 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
60 * 60 *
61 */ 61 */
62 62
63static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked) 63static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
64{ 64{
65 PSDevice apdev_priv; 65 struct vnt_private *apdev_priv;
66 struct net_device *dev = pDevice->dev; 66 struct net_device *dev = pDevice->dev;
67 int ret; 67 int ret;
68 const struct net_device_ops apdev_netdev_ops = { 68 const struct net_device_ops apdev_netdev_ops = {
69 .ndo_start_xmit = pDevice->tx_80211, 69 .ndo_start_xmit = pDevice->tx_80211,
70 }; 70 };
71 71
72 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name); 72 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
@@ -120,7 +120,7 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
120 * 120 *
121 */ 121 */
122 122
123static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked) 123static int hostap_disable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
124{ 124{
125 125
126 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name); 126 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
@@ -135,9 +135,9 @@ static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
135 } 135 }
136 kfree(pDevice->apdev); 136 kfree(pDevice->apdev);
137 pDevice->apdev = NULL; 137 pDevice->apdev = NULL;
138 pDevice->bEnable8021x = FALSE; 138 pDevice->bEnable8021x = false;
139 pDevice->bEnableHostWEP = FALSE; 139 pDevice->bEnableHostWEP = false;
140 pDevice->bEncryptionEnable = FALSE; 140 pDevice->bEncryptionEnable = false;
141 141
142 return 0; 142 return 0;
143} 143}
@@ -157,7 +157,8 @@ static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
157 * 157 *
158 */ 158 */
159 159
160int vt6656_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked) 160int vt6656_hostap_set_hostapd(struct vnt_private *pDevice,
161 int val, int rtnl_locked)
161{ 162{
162 if (val < 0 || val > 1) 163 if (val < 0 || val > 1)
163 return -EINVAL; 164 return -EINVAL;
@@ -187,8 +188,8 @@ int vt6656_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
187 * Return Value: 188 * Return Value:
188 * 189 *
189 */ 190 */
190static int hostap_remove_sta(PSDevice pDevice, 191static int hostap_remove_sta(struct vnt_private *pDevice,
191 struct viawget_hostapd_param *param) 192 struct viawget_hostapd_param *param)
192{ 193{
193 unsigned int uNodeIndex; 194 unsigned int uNodeIndex;
194 195
@@ -215,22 +216,21 @@ static int hostap_remove_sta(PSDevice pDevice,
215 * Return Value: 216 * Return Value:
216 * 217 *
217 */ 218 */
218static int hostap_add_sta(PSDevice pDevice, 219static int hostap_add_sta(struct vnt_private *pDevice,
219 struct viawget_hostapd_param *param) 220 struct viawget_hostapd_param *param)
220{ 221{
221 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 222 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
222 unsigned int uNodeIndex; 223 unsigned int uNodeIndex;
223 224
225 if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex))
226 BSSvCreateOneNode(pDevice, &uNodeIndex);
224 227
225 if (!BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
226 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
227 }
228 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN); 228 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
229 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC; 229 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
230 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability; 230 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
231// TODO listenInterval 231// TODO listenInterval
232// pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1; 232// pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
233 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = FALSE; 233 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false;
234 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates; 234 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
235 235
236 // set max tx rate 236 // set max tx rate
@@ -275,10 +275,10 @@ static int hostap_add_sta(PSDevice pDevice,
275 * 275 *
276 */ 276 */
277 277
278static int hostap_get_info_sta(PSDevice pDevice, 278static int hostap_get_info_sta(struct vnt_private *pDevice,
279 struct viawget_hostapd_param *param) 279 struct viawget_hostapd_param *param)
280{ 280{
281 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 281 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
282 unsigned int uNodeIndex; 282 unsigned int uNodeIndex;
283 283
284 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { 284 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
@@ -308,10 +308,10 @@ static int hostap_get_info_sta(PSDevice pDevice,
308 * Return Value: 308 * Return Value:
309 * 309 *
310 */ 310 */
311static int hostap_set_flags_sta(PSDevice pDevice, 311static int hostap_set_flags_sta(struct vnt_private *pDevice,
312 struct viawget_hostapd_param *param) 312 struct viawget_hostapd_param *param)
313{ 313{
314 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 314 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
315 unsigned int uNodeIndex; 315 unsigned int uNodeIndex;
316 316
317 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) { 317 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &uNodeIndex)) {
@@ -342,10 +342,10 @@ static int hostap_set_flags_sta(PSDevice pDevice,
342 * Return Value: 342 * Return Value:
343 * 343 *
344 */ 344 */
345static int hostap_set_generic_element(PSDevice pDevice, 345static int hostap_set_generic_element(struct vnt_private *pDevice,
346 struct viawget_hostapd_param *param) 346 struct viawget_hostapd_param *param)
347{ 347{
348 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 348 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
349 349
350 350
351 351
@@ -388,7 +388,7 @@ static int hostap_set_generic_element(PSDevice pDevice,
388 * 388 *
389 */ 389 */
390 390
391static void hostap_flush_sta(PSDevice pDevice) 391static void hostap_flush_sta(struct vnt_private *pDevice)
392{ 392{
393 // reserved node index =0 for multicast node. 393 // reserved node index =0 for multicast node.
394 BSSvClearNodeDBTable(pDevice, 1); 394 BSSvClearNodeDBTable(pDevice, 1);
@@ -410,21 +410,20 @@ static void hostap_flush_sta(PSDevice pDevice)
410 * Return Value: 410 * Return Value:
411 * 411 *
412 */ 412 */
413static int hostap_set_encryption(PSDevice pDevice, 413static int hostap_set_encryption(struct vnt_private *pDevice,
414 struct viawget_hostapd_param *param, 414 struct viawget_hostapd_param *param, int param_len)
415 int param_len)
416{ 415{
417 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 416 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
418 DWORD dwKeyIndex = 0; 417 u32 dwKeyIndex = 0;
419 BYTE abyKey[MAX_KEY_LEN]; 418 u8 abyKey[MAX_KEY_LEN];
420 BYTE abySeq[MAX_KEY_LEN]; 419 u8 abySeq[MAX_KEY_LEN];
421 NDIS_802_11_KEY_RSC KeyRSC; 420 NDIS_802_11_KEY_RSC KeyRSC;
422 BYTE byKeyDecMode = KEY_CTL_WEP; 421 u8 byKeyDecMode = KEY_CTL_WEP;
423 int ret = 0; 422 int ret = 0;
424 int iNodeIndex = -1; 423 s32 iNodeIndex = -1;
425 int ii; 424 int ii;
426 BOOL bKeyTableFull = FALSE; 425 int bKeyTableFull = false;
427 WORD wKeyCtl = 0; 426 u16 wKeyCtl = 0;
428 427
429 428
430 param->u.crypt.err = 0; 429 param->u.crypt.err = 0;
@@ -445,7 +444,7 @@ static int hostap_set_encryption(PSDevice pDevice,
445 iNodeIndex = 0; 444 iNodeIndex = 0;
446 445
447 } else { 446 } else {
448 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) { 447 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) {
449 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; 448 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
450 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); 449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
451 return -EINVAL; 450 return -EINVAL;
@@ -456,15 +455,15 @@ static int hostap_set_encryption(PSDevice pDevice,
456 455
457 if (param->u.crypt.alg == WPA_ALG_NONE) { 456 if (param->u.crypt.alg == WPA_ALG_NONE) {
458 457
459 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == TRUE) { 458 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == true) {
460 if (KeybRemoveKey( pDevice, 459 if (KeybRemoveKey( pDevice,
461 &(pDevice->sKey), 460 &(pDevice->sKey),
462 param->sta_addr, 461 param->sta_addr,
463 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex 462 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex
464 ) == FALSE) { 463 ) == false) {
465 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n"); 464 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
466 } 465 }
467 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; 466 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
468 } 467 }
469 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0; 468 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
470 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0; 469 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
@@ -493,13 +492,13 @@ static int hostap_set_encryption(PSDevice pDevice,
493 dwKeyIndex = (DWORD)(param->u.crypt.idx); 492 dwKeyIndex = (DWORD)(param->u.crypt.idx);
494 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) { 493 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
495 pDevice->byKeyIndex = (BYTE)dwKeyIndex; 494 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
496 pDevice->bTransmitKey = TRUE; 495 pDevice->bTransmitKey = true;
497 dwKeyIndex |= (1 << 31); 496 dwKeyIndex |= (1 << 31);
498 } 497 }
499 498
500 if (param->u.crypt.alg == WPA_ALG_WEP) { 499 if (param->u.crypt.alg == WPA_ALG_WEP) {
501 500
502 if ((pDevice->bEnable8021x == FALSE) || (iNodeIndex == 0)) { 501 if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) {
503 KeybSetDefaultKey( pDevice, 502 KeybSetDefaultKey( pDevice,
504 &(pDevice->sKey), 503 &(pDevice->sKey),
505 dwKeyIndex & ~(BIT30 | USE_KEYRSC), 504 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
@@ -512,27 +511,25 @@ static int hostap_set_encryption(PSDevice pDevice,
512 } else { 511 } else {
513 // 8021x enable, individual key 512 // 8021x enable, individual key
514 dwKeyIndex |= (1 << 30); // set pairwise key 513 dwKeyIndex |= (1 << 30); // set pairwise key
515 if (KeybSetKey(pDevice, 514 if (KeybSetKey(pDevice, &(pDevice->sKey),
516 &(pDevice->sKey), 515 &param->sta_addr[0],
517 &param->sta_addr[0], 516 dwKeyIndex & ~(USE_KEYRSC),
518 dwKeyIndex & ~(USE_KEYRSC), 517 param->u.crypt.key_len,
519 param->u.crypt.key_len, 518 &KeyRSC, (PBYTE)abyKey,
520 (PQWORD) &(KeyRSC), 519 KEY_CTL_WEP
521 (PBYTE)abyKey, 520 ) == true) {
522 KEY_CTL_WEP
523 ) == TRUE) {
524 521
525 522
526 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; 523 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
527 524
528 } else { 525 } else {
529 // Key Table Full 526 // Key Table Full
530 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; 527 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
531 bKeyTableFull = TRUE; 528 bKeyTableFull = true;
532 } 529 }
533 } 530 }
534 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; 531 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
535 pDevice->bEncryptionEnable = TRUE; 532 pDevice->bEncryptionEnable = true;
536 pMgmt->byCSSPK = KEY_CTL_WEP; 533 pMgmt->byCSSPK = KEY_CTL_WEP;
537 pMgmt->byCSSGK = KEY_CTL_WEP; 534 pMgmt->byCSSGK = KEY_CTL_WEP;
538 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP; 535 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
@@ -574,11 +571,11 @@ static int hostap_set_encryption(PSDevice pDevice,
574 &(pDevice->sKey), 571 &(pDevice->sKey),
575 dwKeyIndex, 572 dwKeyIndex,
576 param->u.crypt.key_len, 573 param->u.crypt.key_len,
577 (PQWORD) &(KeyRSC), 574 &KeyRSC,
578 abyKey, 575 abyKey,
579 byKeyDecMode 576 byKeyDecMode
580 ); 577 );
581 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; 578 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
582 579
583 } else { 580 } else {
584 dwKeyIndex |= (1 << 30); // set pairwise key 581 dwKeyIndex |= (1 << 30); // set pairwise key
@@ -587,23 +584,23 @@ static int hostap_set_encryption(PSDevice pDevice,
587 &param->sta_addr[0], 584 &param->sta_addr[0],
588 dwKeyIndex, 585 dwKeyIndex,
589 param->u.crypt.key_len, 586 param->u.crypt.key_len,
590 (PQWORD) &(KeyRSC), 587 &KeyRSC,
591 (PBYTE)abyKey, 588 (PBYTE)abyKey,
592 byKeyDecMode 589 byKeyDecMode
593 ) == TRUE) { 590 ) == true) {
594 591
595 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE; 592 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
596 593
597 } else { 594 } else {
598 // Key Table Full 595 // Key Table Full
599 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE; 596 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
600 bKeyTableFull = TRUE; 597 bKeyTableFull = true;
601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n"); 598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
602 } 599 }
603 600
604 } 601 }
605 602
606 if (bKeyTableFull == TRUE) { 603 if (bKeyTableFull == true) {
607 wKeyCtl &= 0x7F00; // clear all key control filed 604 wKeyCtl &= 0x7F00; // clear all key control filed
608 wKeyCtl |= (byKeyDecMode << 4); 605 wKeyCtl |= (byKeyDecMode << 4);
609 wKeyCtl |= (byKeyDecMode); 606 wKeyCtl |= (byKeyDecMode);
@@ -625,7 +622,7 @@ static int hostap_set_encryption(PSDevice pDevice,
625 ); 622 );
626 623
627 // set wep key 624 // set wep key
628 pDevice->bEncryptionEnable = TRUE; 625 pDevice->bEncryptionEnable = true;
629 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode; 626 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
630 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex; 627 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
631 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0; 628 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
@@ -649,14 +646,14 @@ static int hostap_set_encryption(PSDevice pDevice,
649 * Return Value: 646 * Return Value:
650 * 647 *
651 */ 648 */
652static int hostap_get_encryption(PSDevice pDevice, 649static int hostap_get_encryption(struct vnt_private *pDevice,
653 struct viawget_hostapd_param *param, 650 struct viawget_hostapd_param *param,
654 int param_len) 651 int param_len)
655{ 652{
656 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 653 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
657 int ret = 0; 654 int ret = 0;
658 int ii; 655 int ii;
659 int iNodeIndex =0; 656 s32 iNodeIndex = 0;
660 657
661 658
662 param->u.crypt.err = 0; 659 param->u.crypt.err = 0;
@@ -664,7 +661,7 @@ static int hostap_get_encryption(PSDevice pDevice,
664 if (is_broadcast_ether_addr(param->sta_addr)) { 661 if (is_broadcast_ether_addr(param->sta_addr)) {
665 iNodeIndex = 0; 662 iNodeIndex = 0;
666 } else { 663 } else {
667 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == FALSE) { 664 if (BSSbIsSTAInNodeDB(pDevice, param->sta_addr, &iNodeIndex) == false) {
668 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR; 665 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
669 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n"); 666 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
670 return -EINVAL; 667 return -EINVAL;
@@ -694,7 +691,7 @@ static int hostap_get_encryption(PSDevice pDevice,
694 * 691 *
695 */ 692 */
696 693
697int vt6656_hostap_ioctl(PSDevice pDevice, struct iw_point *p) 694int vt6656_hostap_ioctl(struct vnt_private *pDevice, struct iw_point *p)
698{ 695{
699 struct viawget_hostapd_param *param; 696 struct viawget_hostapd_param *param;
700 int ret = 0; 697 int ret = 0;
diff --git a/drivers/staging/vt6656/hostap.h b/drivers/staging/vt6656/hostap.h
index b660aee1ca0e..f5656cd96a8f 100644
--- a/drivers/staging/vt6656/hostap.h
+++ b/drivers/staging/vt6656/hostap.h
@@ -61,7 +61,7 @@
61#define ARPHRD_IEEE80211 801 61#define ARPHRD_IEEE80211 801
62#endif 62#endif
63 63
64int vt6656_hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked); 64int vt6656_hostap_set_hostapd(struct vnt_private *, int val, int rtnl_locked);
65int vt6656_hostap_ioctl(PSDevice pDevice, struct iw_point *p); 65int vt6656_hostap_ioctl(struct vnt_private *, struct iw_point *p);
66 66
67#endif /* __HOSTAP_H__ */ 67#endif /* __HOSTAP_H__ */
diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c
index bba31caae036..51990bd3dd45 100644
--- a/drivers/staging/vt6656/int.c
+++ b/drivers/staging/vt6656/int.c
@@ -75,23 +75,22 @@ static int msglevel = MSG_LEVEL_INFO; /* MSG_LEVEL_DEBUG */
75 * if we've gotten no data 75 * if we've gotten no data
76 * 76 *
77-*/ 77-*/
78void INTvWorkItem(void *Context) 78void INTvWorkItem(struct vnt_private *pDevice)
79{ 79{
80 PSDevice pDevice = Context;
81 int ntStatus; 80 int ntStatus;
82 81
83 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Interrupt Polling Thread\n"); 82 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Interrupt Polling Thread\n");
84 83
85 spin_lock_irq(&pDevice->lock); 84 spin_lock_irq(&pDevice->lock);
86 if (pDevice->fKillEventPollingThread != TRUE) 85 if (pDevice->fKillEventPollingThread != true)
87 ntStatus = PIPEnsInterruptRead(pDevice); 86 ntStatus = PIPEnsInterruptRead(pDevice);
88 spin_unlock_irq(&pDevice->lock); 87 spin_unlock_irq(&pDevice->lock);
89} 88}
90 89
91void INTnsProcessData(PSDevice pDevice) 90void INTnsProcessData(struct vnt_private *pDevice)
92{ 91{
93 PSINTData pINTData; 92 PSINTData pINTData;
94 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 93 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
95 struct net_device_stats *pStats = &pDevice->stats; 94 struct net_device_stats *pStats = &pDevice->stats;
96 95
97 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptProcessData\n"); 96 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptProcessData\n");
@@ -147,12 +146,12 @@ void INTnsProcessData(PSDevice pDevice)
147 if (pMgmt->byDTIMCount > 0) { 146 if (pMgmt->byDTIMCount > 0) {
148 pMgmt->byDTIMCount--; 147 pMgmt->byDTIMCount--;
149 pMgmt->sNodeDBTable[0].bRxPSPoll = 148 pMgmt->sNodeDBTable[0].bRxPSPoll =
150 FALSE; 149 false;
151 } else if (pMgmt->byDTIMCount == 0) { 150 } else if (pMgmt->byDTIMCount == 0) {
152 /* check if multicast tx buffering */ 151 /* check if multicast tx buffering */
153 pMgmt->byDTIMCount = 152 pMgmt->byDTIMCount =
154 pMgmt->byDTIMPeriod-1; 153 pMgmt->byDTIMPeriod-1;
155 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE; 154 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
156 if (pMgmt->sNodeDBTable[0].bPSEnable) 155 if (pMgmt->sNodeDBTable[0].bPSEnable)
157 bScheduleCommand((void *) pDevice, 156 bScheduleCommand((void *) pDevice,
158 WLAN_CMD_RX_PSPOLL, 157 WLAN_CMD_RX_PSPOLL,
@@ -162,9 +161,9 @@ void INTnsProcessData(PSDevice pDevice)
162 WLAN_CMD_BECON_SEND, 161 WLAN_CMD_BECON_SEND,
163 NULL); 162 NULL);
164 } /* if (pDevice->eOPMode == OP_MODE_AP) */ 163 } /* if (pDevice->eOPMode == OP_MODE_AP) */
165 pDevice->bBeaconSent = TRUE; 164 pDevice->bBeaconSent = true;
166 } else { 165 } else {
167 pDevice->bBeaconSent = FALSE; 166 pDevice->bBeaconSent = false;
168 } 167 }
169 if (pINTData->byISR0 & ISR_TBTT) { 168 if (pINTData->byISR0 & ISR_TBTT) {
170 if (pDevice->bEnablePSMode) 169 if (pDevice->bEnablePSMode)
@@ -179,8 +178,7 @@ void INTnsProcessData(PSDevice pDevice)
179 NULL); 178 NULL);
180 } 179 }
181 } 180 }
182 LODWORD(pDevice->qwCurrTSF) = pINTData->dwLoTSF; 181 pDevice->qwCurrTSF = cpu_to_le64(pINTData->qwTSF);
183 HIDWORD(pDevice->qwCurrTSF) = pINTData->dwHiTSF;
184 /*DBG_PRN_GRP01(("ISR0 = %02x , 182 /*DBG_PRN_GRP01(("ISR0 = %02x ,
185 LoTsf = %08x, 183 LoTsf = %08x,
186 HiTsf = %08x\n", 184 HiTsf = %08x\n",
@@ -204,7 +202,7 @@ void INTnsProcessData(PSDevice pDevice)
204 WLAN_CMD_RADIO, 202 WLAN_CMD_RADIO,
205 NULL); 203 NULL);
206 pDevice->intBuf.uDataLen = 0; 204 pDevice->intBuf.uDataLen = 0;
207 pDevice->intBuf.bInUse = FALSE; 205 pDevice->intBuf.bInUse = false;
208 206
209 pStats->tx_packets = pDevice->scStatistic.ullTsrOK; 207 pStats->tx_packets = pDevice->scStatistic.ullTsrOK;
210 pStats->tx_bytes = pDevice->scStatistic.ullTxDirectedBytes + 208 pStats->tx_bytes = pDevice->scStatistic.ullTxDirectedBytes +
diff --git a/drivers/staging/vt6656/int.h b/drivers/staging/vt6656/int.h
index e0d2b07ba608..27c725f1ce11 100644
--- a/drivers/staging/vt6656/int.h
+++ b/drivers/staging/vt6656/int.h
@@ -47,8 +47,7 @@ typedef struct tagSINTData {
47 BYTE byTSR3; 47 BYTE byTSR3;
48 BYTE byPkt3; 48 BYTE byPkt3;
49 WORD wTime3; 49 WORD wTime3;
50 u32 dwLoTSF; 50 u64 qwTSF;
51 u32 dwHiTSF;
52 BYTE byISR0; 51 BYTE byISR0;
53 BYTE byISR1; 52 BYTE byISR1;
54 BYTE byRTSSuccess; 53 BYTE byRTSSuccess;
@@ -65,7 +64,7 @@ SINTData, *PSINTData;
65 64
66/*--------------------- Export Functions --------------------------*/ 65/*--------------------- Export Functions --------------------------*/
67 66
68void INTvWorkItem(void *Context); 67void INTvWorkItem(struct vnt_private *);
69void INTnsProcessData(PSDevice pDevice); 68void INTnsProcessData(struct vnt_private *);
70 69
71#endif /* __INT_H__ */ 70#endif /* __INT_H__ */
diff --git a/drivers/staging/vt6656/iocmd.h b/drivers/staging/vt6656/iocmd.h
index ae6e2d237b20..c354a77964d8 100644
--- a/drivers/staging/vt6656/iocmd.h
+++ b/drivers/staging/vt6656/iocmd.h
@@ -122,8 +122,8 @@ typedef struct tagSCmdBSSJoin {
122 u16 wBBPType; 122 u16 wBBPType;
123 u8 ssid[SSID_MAXLEN + 2]; 123 u8 ssid[SSID_MAXLEN + 2];
124 u32 uChannel; 124 u32 uChannel;
125 BOOL bPSEnable; 125 bool bPSEnable;
126 BOOL bShareKeyAuth; 126 bool bShareKeyAuth;
127 127
128} __packed SCmdBSSJoin, *PSCmdBSSJoin; 128} __packed SCmdBSSJoin, *PSCmdBSSJoin;
129 129
@@ -133,7 +133,7 @@ typedef struct tagSCmdBSSJoin {
133 133
134typedef struct tagSCmdZoneTypeSet { 134typedef struct tagSCmdZoneTypeSet {
135 135
136 BOOL bWrite; 136 bool bWrite;
137 WZONETYPE ZoneType; 137 WZONETYPE ZoneType;
138 138
139} __packed SCmdZoneTypeSet, *PSCmdZoneTypeSet; 139} __packed SCmdZoneTypeSet, *PSCmdZoneTypeSet;
@@ -143,7 +143,7 @@ typedef struct tagSWPAResult {
143 u8 proto; 143 u8 proto;
144 u8 key_mgmt; 144 u8 key_mgmt;
145 u8 eap_type; 145 u8 eap_type;
146 BOOL authenticated; 146 bool authenticated;
147} __packed SWPAResult, *PSWPAResult; 147} __packed SWPAResult, *PSWPAResult;
148 148
149typedef struct tagSCmdStartAP { 149typedef struct tagSCmdStartAP {
@@ -153,17 +153,17 @@ typedef struct tagSCmdStartAP {
153 u8 ssid[SSID_MAXLEN + 2]; 153 u8 ssid[SSID_MAXLEN + 2];
154 u32 uChannel; 154 u32 uChannel;
155 u32 uBeaconInt; 155 u32 uBeaconInt;
156 BOOL bShareKeyAuth; 156 bool bShareKeyAuth;
157 u8 byBasicRate; 157 u8 byBasicRate;
158 158
159} __packed SCmdStartAP, *PSCmdStartAP; 159} __packed SCmdStartAP, *PSCmdStartAP;
160 160
161typedef struct tagSCmdSetWEP { 161typedef struct tagSCmdSetWEP {
162 162
163 BOOL bEnableWep; 163 bool bEnableWep;
164 u8 byKeyIndex; 164 u8 byKeyIndex;
165 u8 abyWepKey[WEP_NKEYS][WEP_KEYMAXLEN]; 165 u8 abyWepKey[WEP_NKEYS][WEP_KEYMAXLEN];
166 BOOL bWepKeyAvailable[WEP_NKEYS]; 166 bool bWepKeyAvailable[WEP_NKEYS];
167 u32 auWepKeyLength[WEP_NKEYS]; 167 u32 auWepKeyLength[WEP_NKEYS];
168 168
169} __packed SCmdSetWEP, *PSCmdSetWEP; 169} __packed SCmdSetWEP, *PSCmdSetWEP;
@@ -176,7 +176,7 @@ typedef struct tagSBSSIDItem {
176 u16 wBeaconInterval; 176 u16 wBeaconInterval;
177 u16 wCapInfo; 177 u16 wCapInfo;
178 u8 byNetType; 178 u8 byNetType;
179 BOOL bWEPOn; 179 bool bWEPOn;
180 u32 uRSSI; 180 u32 uRSSI;
181 181
182} __packed SBSSIDItem; 182} __packed SBSSIDItem;
@@ -197,12 +197,12 @@ typedef struct tagSNodeItem {
197 u16 wInActiveCount; 197 u16 wInActiveCount;
198 u16 wEnQueueCnt; 198 u16 wEnQueueCnt;
199 u16 wFlags; 199 u16 wFlags;
200 BOOL bPWBitOn; 200 bool bPWBitOn;
201 u8 byKeyIndex; 201 u8 byKeyIndex;
202 u16 wWepKeyLength; 202 u16 wWepKeyLength;
203 u8 abyWepKey[WEP_KEYMAXLEN]; 203 u8 abyWepKey[WEP_KEYMAXLEN];
204 // Auto rate fallback vars 204 // Auto rate fallback vars
205 BOOL bIsInFallback; 205 bool bIsInFallback;
206 u32 uTxFailures; 206 u32 uTxFailures;
207 u32 uTxAttempts; 207 u32 uTxAttempts;
208 u16 wFailureRatio; 208 u16 wFailureRatio;
@@ -220,7 +220,7 @@ typedef struct tagSNodeList {
220 220
221typedef struct tagSCmdLinkStatus { 221typedef struct tagSCmdLinkStatus {
222 222
223 BOOL bLink; 223 bool bLink;
224 u16 wBSSType; 224 u16 wBSSType;
225 u8 byState; 225 u8 byState;
226 u8 abyBSSID[BSSID_LEN]; 226 u8 abyBSSID[BSSID_LEN];
diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c
index 52fce6902508..69971f35e490 100644
--- a/drivers/staging/vt6656/iwctl.c
+++ b/drivers/staging/vt6656/iwctl.c
@@ -55,7 +55,7 @@ static int msglevel = MSG_LEVEL_INFO;
55 55
56struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev) 56struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
57{ 57{
58 PSDevice pDevice = netdev_priv(dev); 58 struct vnt_private *pDevice = netdev_priv(dev);
59 long ldBm; 59 long ldBm;
60 60
61 pDevice->wstats.status = pDevice->eOPMode; 61 pDevice->wstats.status = pDevice->eOPMode;
@@ -91,9 +91,9 @@ int iwctl_giwname(struct net_device *dev, struct iw_request_info *info,
91int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info, 91int iwctl_siwscan(struct net_device *dev, struct iw_request_info *info,
92 union iwreq_data *wrqu, char *extra) 92 union iwreq_data *wrqu, char *extra)
93{ 93{
94 PSDevice pDevice = netdev_priv(dev); 94 struct vnt_private *pDevice = netdev_priv(dev);
95 struct iw_point *wrq = &wrqu->data; 95 struct iw_point *wrq = &wrqu->data;
96 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 96 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
97 struct iw_scan_req *req = (struct iw_scan_req *)extra; 97 struct iw_scan_req *req = (struct iw_scan_req *)extra;
98 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; 98 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
99 PWLAN_IE_SSID pItemSSID = NULL; 99 PWLAN_IE_SSID pItemSSID = NULL;
@@ -169,8 +169,8 @@ int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info,
169 int ii; 169 int ii;
170 int jj; 170 int jj;
171 int kk; 171 int kk;
172 PSDevice pDevice = netdev_priv(dev); 172 struct vnt_private *pDevice = netdev_priv(dev);
173 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 173 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
174 PKnownBSS pBSS; 174 PKnownBSS pBSS;
175 PWLAN_IE_SSID pItemSSID; 175 PWLAN_IE_SSID pItemSSID;
176 PWLAN_IE_SUPP_RATES pSuppRates; 176 PWLAN_IE_SUPP_RATES pSuppRates;
@@ -309,7 +309,7 @@ int iwctl_giwscan(struct net_device *dev, struct iw_request_info *info,
309int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info, 309int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info,
310 union iwreq_data *wrqu, char *extra) 310 union iwreq_data *wrqu, char *extra)
311{ 311{
312 PSDevice pDevice = netdev_priv(dev); 312 struct vnt_private *pDevice = netdev_priv(dev);
313 struct iw_freq *wrq = &wrqu->freq; 313 struct iw_freq *wrq = &wrqu->freq;
314 int rc = 0; 314 int rc = 0;
315 315
@@ -348,9 +348,9 @@ int iwctl_siwfreq(struct net_device *dev, struct iw_request_info *info,
348int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info, 348int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info,
349 union iwreq_data *wrqu, char *extra) 349 union iwreq_data *wrqu, char *extra)
350{ 350{
351 PSDevice pDevice = netdev_priv(dev); 351 struct vnt_private *pDevice = netdev_priv(dev);
352 struct iw_freq *wrq = &wrqu->freq; 352 struct iw_freq *wrq = &wrqu->freq;
353 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 353 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
354 354
355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ\n"); 355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ\n");
356 356
@@ -379,9 +379,9 @@ int iwctl_giwfreq(struct net_device *dev, struct iw_request_info *info,
379int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info, 379int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
380 union iwreq_data *wrqu, char *extra) 380 union iwreq_data *wrqu, char *extra)
381{ 381{
382 PSDevice pDevice = netdev_priv(dev); 382 struct vnt_private *pDevice = netdev_priv(dev);
383 __u32 *wmode = &wrqu->mode; 383 __u32 *wmode = &wrqu->mode;
384 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 384 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
385 int rc = 0; 385 int rc = 0;
386 386
387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE\n"); 387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE\n");
@@ -400,7 +400,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
400 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) { 400 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
401 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA; 401 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
402 if (pDevice->flags & DEVICE_FLAGS_OPENED) 402 if (pDevice->flags & DEVICE_FLAGS_OPENED)
403 pDevice->bCommit = TRUE; 403 pDevice->bCommit = true;
404 } 404 }
405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n"); 405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
406 break; 406 break;
@@ -409,7 +409,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
409 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) { 409 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
410 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA; 410 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
411 if (pDevice->flags & DEVICE_FLAGS_OPENED) 411 if (pDevice->flags & DEVICE_FLAGS_OPENED)
412 pDevice->bCommit = TRUE; 412 pDevice->bCommit = true;
413 } 413 }
414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n"); 414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
415 break; 415 break;
@@ -422,7 +422,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
422 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) { 422 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
423 pMgmt->eConfigMode = WMAC_CONFIG_AP; 423 pMgmt->eConfigMode = WMAC_CONFIG_AP;
424 if (pDevice->flags & DEVICE_FLAGS_OPENED) 424 if (pDevice->flags & DEVICE_FLAGS_OPENED)
425 pDevice->bCommit = TRUE; 425 pDevice->bCommit = true;
426 } 426 }
427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n"); 427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
428 break; 428 break;
@@ -455,7 +455,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
455 bScheduleCommand((void *) pDevice, 455 bScheduleCommand((void *) pDevice,
456 WLAN_CMD_DISASSOCIATE, NULL); 456 WLAN_CMD_DISASSOCIATE, NULL);
457 } else { 457 } else {
458 pDevice->bLinkPass = FALSE; 458 pDevice->bLinkPass = false;
459 pMgmt->eCurrState = WMAC_STATE_IDLE; 459 pMgmt->eCurrState = WMAC_STATE_IDLE;
460 memset(pMgmt->abyCurrBSSID, 0, 6); 460 memset(pMgmt->abyCurrBSSID, 0, 6);
461 } 461 }
@@ -479,7 +479,7 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
479 479
480 spin_unlock_irq(&pDevice->lock); 480 spin_unlock_irq(&pDevice->lock);
481 } 481 }
482 pDevice->bCommit = FALSE; 482 pDevice->bCommit = false;
483 } 483 }
484 484
485 485
@@ -492,9 +492,9 @@ int iwctl_siwmode(struct net_device *dev, struct iw_request_info *info,
492int iwctl_giwmode(struct net_device *dev, struct iw_request_info *info, 492int iwctl_giwmode(struct net_device *dev, struct iw_request_info *info,
493 union iwreq_data *wrqu, char *extra) 493 union iwreq_data *wrqu, char *extra)
494{ 494{
495 PSDevice pDevice = netdev_priv(dev); 495 struct vnt_private *pDevice = netdev_priv(dev);
496 __u32 *wmode = &wrqu->mode; 496 __u32 *wmode = &wrqu->mode;
497 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 497 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
498 498
499 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE\n"); 499 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE\n");
500 500
@@ -631,9 +631,9 @@ int iwctl_giwrange(struct net_device *dev, struct iw_request_info *info,
631int iwctl_siwap(struct net_device *dev, struct iw_request_info *info, 631int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
632 union iwreq_data *wrqu, char *extra) 632 union iwreq_data *wrqu, char *extra)
633{ 633{
634 PSDevice pDevice = netdev_priv(dev); 634 struct vnt_private *pDevice = netdev_priv(dev);
635 struct sockaddr *wrq = &wrqu->ap_addr; 635 struct sockaddr *wrq = &wrqu->ap_addr;
636 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 636 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
637 int rc = 0; 637 int rc = 0;
638 BYTE ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 638 BYTE ZeroBSSID[WLAN_BSSID_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
639 639
@@ -672,7 +672,7 @@ int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
672 } 672 }
673 673
674 if (pDevice->flags & DEVICE_FLAGS_OPENED) 674 if (pDevice->flags & DEVICE_FLAGS_OPENED)
675 pDevice->bCommit = TRUE; 675 pDevice->bCommit = true;
676 } 676 }
677 return rc; 677 return rc;
678} 678}
@@ -683,9 +683,9 @@ int iwctl_siwap(struct net_device *dev, struct iw_request_info *info,
683int iwctl_giwap(struct net_device *dev, struct iw_request_info *info, 683int iwctl_giwap(struct net_device *dev, struct iw_request_info *info,
684 union iwreq_data *wrqu, char *extra) 684 union iwreq_data *wrqu, char *extra)
685{ 685{
686 PSDevice pDevice = netdev_priv(dev); 686 struct vnt_private *pDevice = netdev_priv(dev);
687 struct sockaddr *wrq = &wrqu->ap_addr; 687 struct sockaddr *wrq = &wrqu->ap_addr;
688 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 688 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
689 689
690 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP\n"); 690 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP\n");
691 691
@@ -694,7 +694,7 @@ int iwctl_giwap(struct net_device *dev, struct iw_request_info *info,
694 694
695 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6); 695 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
696 696
697 if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)) 697 if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
698 memset(wrq->sa_data, 0, 6); 698 memset(wrq->sa_data, 0, 6);
699 699
700 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) 700 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
@@ -713,8 +713,8 @@ int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info,
713 struct iw_point *wrq = &wrqu->data; 713 struct iw_point *wrq = &wrqu->data;
714 struct sockaddr *sock; 714 struct sockaddr *sock;
715 struct iw_quality *qual; 715 struct iw_quality *qual;
716 PSDevice pDevice = netdev_priv(dev); 716 struct vnt_private *pDevice = netdev_priv(dev);
717 PSMgmtObject pMgmt = &pDevice->sMgmtObj; 717 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
718 PKnownBSS pBSS = &pMgmt->sBSSList[0]; 718 PKnownBSS pBSS = &pMgmt->sBSSList[0];
719 int ii; 719 int ii;
720 int jj; 720 int jj;
@@ -771,9 +771,9 @@ int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info,
771int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info, 771int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
772 union iwreq_data *wrqu, char *extra) 772 union iwreq_data *wrqu, char *extra)
773{ 773{
774 PSDevice pDevice = netdev_priv(dev); 774 struct vnt_private *pDevice = netdev_priv(dev);
775 struct iw_point *wrq = &wrqu->essid; 775 struct iw_point *wrq = &wrqu->essid;
776 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 776 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
777 PWLAN_IE_SSID pItemSSID; 777 PWLAN_IE_SSID pItemSSID;
778 778
779 if (pMgmt == NULL) 779 if (pMgmt == NULL)
@@ -784,7 +784,7 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
784 784
785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n"); 785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID :\n");
786 786
787 pDevice->fWPA_Authened = FALSE; 787 pDevice->fWPA_Authened = false;
788 // Check if we asked for `any' 788 // Check if we asked for `any'
789 if (wrq->flags == 0) { 789 if (wrq->flags == 0) {
790 // Just send an empty SSID list 790 // Just send an empty SSID list
@@ -816,7 +816,7 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
816 816
817 // Wext wil order another command of siwap to link 817 // Wext wil order another command of siwap to link
818 // with desired AP, so here need not associate?? 818 // with desired AP, so here need not associate??
819 if (pDevice->bWPASuppWextEnabled == TRUE) { 819 if (pDevice->bWPASuppWextEnabled == true) {
820 /*******search if in hidden ssid mode ****/ 820 /*******search if in hidden ssid mode ****/
821 PKnownBSS pCurr = NULL; 821 PKnownBSS pCurr = NULL;
822 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; 822 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
@@ -867,7 +867,7 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
867 } 867 }
868 868
869 if (pDevice->flags & DEVICE_FLAGS_OPENED) 869 if (pDevice->flags & DEVICE_FLAGS_OPENED)
870 pDevice->bCommit = TRUE; 870 pDevice->bCommit = true;
871 871
872 return 0; 872 return 0;
873} 873}
@@ -878,9 +878,9 @@ int iwctl_siwessid(struct net_device *dev, struct iw_request_info *info,
878int iwctl_giwessid(struct net_device *dev, struct iw_request_info *info, 878int iwctl_giwessid(struct net_device *dev, struct iw_request_info *info,
879 union iwreq_data *wrqu, char *extra) 879 union iwreq_data *wrqu, char *extra)
880{ 880{
881 PSDevice pDevice = netdev_priv(dev); 881 struct vnt_private *pDevice = netdev_priv(dev);
882 struct iw_point *wrq = &wrqu->essid; 882 struct iw_point *wrq = &wrqu->essid;
883 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 883 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
884 PWLAN_IE_SSID pItemSSID; 884 PWLAN_IE_SSID pItemSSID;
885 885
886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID\n"); 886 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID\n");
@@ -908,7 +908,7 @@ int iwctl_giwessid(struct net_device *dev, struct iw_request_info *info,
908int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info, 908int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
909 union iwreq_data *wrqu, char *extra) 909 union iwreq_data *wrqu, char *extra)
910{ 910{
911 PSDevice pDevice = netdev_priv(dev); 911 struct vnt_private *pDevice = netdev_priv(dev);
912 struct iw_param *wrq = &wrqu->bitrate; 912 struct iw_param *wrq = &wrqu->bitrate;
913 int rc = 0; 913 int rc = 0;
914 u8 brate = 0; 914 u8 brate = 0;
@@ -965,7 +965,7 @@ int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
965 if (wrq->fixed != 0) { 965 if (wrq->fixed != 0) {
966 // Fixed mode 966 // Fixed mode
967 // One rate, fixed 967 // One rate, fixed
968 pDevice->bFixRate = TRUE; 968 pDevice->bFixRate = true;
969 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) { 969 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
970 pDevice->uConnectionRate = 3; 970 pDevice->uConnectionRate = 3;
971 } else { 971 } else {
@@ -973,7 +973,7 @@ int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate); 973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
974 } 974 }
975 } else { 975 } else {
976 pDevice->bFixRate = FALSE; 976 pDevice->bFixRate = false;
977 pDevice->uConnectionRate = 13; 977 pDevice->uConnectionRate = 13;
978 } 978 }
979 979
@@ -986,9 +986,9 @@ int iwctl_siwrate(struct net_device *dev, struct iw_request_info *info,
986int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info, 986int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
987 union iwreq_data *wrqu, char *extra) 987 union iwreq_data *wrqu, char *extra)
988{ 988{
989 PSDevice pDevice = netdev_priv(dev); 989 struct vnt_private *pDevice = netdev_priv(dev);
990 struct iw_param *wrq = &wrqu->bitrate; 990 struct iw_param *wrq = &wrqu->bitrate;
991 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 991 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
992 992
993 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE\n"); 993 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE\n");
994 994
@@ -1024,8 +1024,8 @@ int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
1024 brate = abySupportedRates[pDevice->wCurrentRate]; 1024 brate = abySupportedRates[pDevice->wCurrentRate];
1025 wrq->value = brate * 500000; 1025 wrq->value = brate * 500000;
1026 // If more than one rate, set auto 1026 // If more than one rate, set auto
1027 if (pDevice->bFixRate == TRUE) 1027 if (pDevice->bFixRate == true)
1028 wrq->fixed = TRUE; 1028 wrq->fixed = true;
1029 } 1029 }
1030 1030
1031 return 0; 1031 return 0;
@@ -1037,7 +1037,7 @@ int iwctl_giwrate(struct net_device *dev, struct iw_request_info *info,
1037int iwctl_siwrts(struct net_device *dev, struct iw_request_info *info, 1037int iwctl_siwrts(struct net_device *dev, struct iw_request_info *info,
1038 union iwreq_data *wrqu, char *extra) 1038 union iwreq_data *wrqu, char *extra)
1039{ 1039{
1040 PSDevice pDevice = netdev_priv(dev); 1040 struct vnt_private *pDevice = netdev_priv(dev);
1041 struct iw_param *wrq = &wrqu->rts; 1041 struct iw_param *wrq = &wrqu->rts;
1042 1042
1043 if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled) 1043 if ((wrq->value < 0 || wrq->value > 2312) && !wrq->disabled)
@@ -1057,7 +1057,7 @@ int iwctl_siwrts(struct net_device *dev, struct iw_request_info *info,
1057int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info, 1057int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info,
1058 union iwreq_data *wrqu, char *extra) 1058 union iwreq_data *wrqu, char *extra)
1059{ 1059{
1060 PSDevice pDevice = netdev_priv(dev); 1060 struct vnt_private *pDevice = netdev_priv(dev);
1061 struct iw_param *wrq = &wrqu->rts; 1061 struct iw_param *wrq = &wrqu->rts;
1062 1062
1063 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS\n"); 1063 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS\n");
@@ -1073,7 +1073,7 @@ int iwctl_giwrts(struct net_device *dev, struct iw_request_info *info,
1073int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info, 1073int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info,
1074 union iwreq_data *wrqu, char *extra) 1074 union iwreq_data *wrqu, char *extra)
1075{ 1075{
1076 PSDevice pDevice = netdev_priv(dev); 1076 struct vnt_private *pDevice = netdev_priv(dev);
1077 struct iw_param *wrq = &wrqu->frag; 1077 struct iw_param *wrq = &wrqu->frag;
1078 int rc = 0; 1078 int rc = 0;
1079 int fthr = wrq->value; 1079 int fthr = wrq->value;
@@ -1097,7 +1097,7 @@ int iwctl_siwfrag(struct net_device *dev, struct iw_request_info *info,
1097int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info, 1097int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info,
1098 union iwreq_data *wrqu, char *extra) 1098 union iwreq_data *wrqu, char *extra)
1099{ 1099{
1100 PSDevice pDevice = netdev_priv(dev); 1100 struct vnt_private *pDevice = netdev_priv(dev);
1101 struct iw_param *wrq = &wrqu->frag; 1101 struct iw_param *wrq = &wrqu->frag;
1102 1102
1103 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG\n"); 1103 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG\n");
@@ -1113,7 +1113,7 @@ int iwctl_giwfrag(struct net_device *dev, struct iw_request_info *info,
1113int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info, 1113int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info,
1114 union iwreq_data *wrqu, char *extra) 1114 union iwreq_data *wrqu, char *extra)
1115{ 1115{
1116 PSDevice pDevice = netdev_priv(dev); 1116 struct vnt_private *pDevice = netdev_priv(dev);
1117 struct iw_param *wrq = &wrqu->retry; 1117 struct iw_param *wrq = &wrqu->retry;
1118 int rc = 0; 1118 int rc = 0;
1119 1119
@@ -1146,7 +1146,7 @@ int iwctl_siwretry(struct net_device *dev, struct iw_request_info *info,
1146int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info, 1146int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info,
1147 union iwreq_data *wrqu, char *extra) 1147 union iwreq_data *wrqu, char *extra)
1148{ 1148{
1149 PSDevice pDevice = netdev_priv(dev); 1149 struct vnt_private *pDevice = netdev_priv(dev);
1150 struct iw_param *wrq = &wrqu->retry; 1150 struct iw_param *wrq = &wrqu->retry;
1151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY\n"); 1151 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY\n");
1152 wrq->disabled = 0; // Can't be disabled 1152 wrq->disabled = 0; // Can't be disabled
@@ -1173,8 +1173,8 @@ int iwctl_giwretry(struct net_device *dev, struct iw_request_info *info,
1173int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info, 1173int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1174 union iwreq_data *wrqu, char *extra) 1174 union iwreq_data *wrqu, char *extra)
1175{ 1175{
1176 PSDevice pDevice = netdev_priv(dev); 1176 struct vnt_private *pDevice = netdev_priv(dev);
1177 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1177 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1178 struct iw_point *wrq = &wrqu->encoding; 1178 struct iw_point *wrq = &wrqu->encoding;
1179 u32 dwKeyIndex = (u32)(wrq->flags & IW_ENCODE_INDEX); 1179 u32 dwKeyIndex = (u32)(wrq->flags & IW_ENCODE_INDEX);
1180 int ii; 1180 int ii;
@@ -1229,8 +1229,8 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1229 } 1229 }
1230 pDevice->byKeyIndex = (BYTE)dwKeyIndex; 1230 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1231 pDevice->uKeyLength = wrq->length; 1231 pDevice->uKeyLength = wrq->length;
1232 pDevice->bTransmitKey = TRUE; 1232 pDevice->bTransmitKey = true;
1233 pDevice->bEncryptionEnable = TRUE; 1233 pDevice->bEncryptionEnable = true;
1234 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; 1234 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1235 1235
1236 // Do we want to just set the transmit key index? 1236 // Do we want to just set the transmit key index?
@@ -1244,8 +1244,8 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1244 // Read the flags 1244 // Read the flags
1245 if (wrq->flags & IW_ENCODE_DISABLED) { 1245 if (wrq->flags & IW_ENCODE_DISABLED) {
1246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n"); 1246 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1247 pMgmt->bShareKeyAlgorithm = FALSE; 1247 pMgmt->bShareKeyAlgorithm = false;
1248 pDevice->bEncryptionEnable = FALSE; 1248 pDevice->bEncryptionEnable = false;
1249 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; 1249 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1250 if (pDevice->flags & DEVICE_FLAGS_OPENED) { 1250 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1251 spin_lock_irq(&pDevice->lock); 1251 spin_lock_irq(&pDevice->lock);
@@ -1256,11 +1256,11 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1256 } 1256 }
1257 if (wrq->flags & IW_ENCODE_RESTRICTED) { 1257 if (wrq->flags & IW_ENCODE_RESTRICTED) {
1258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n"); 1258 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1259 pMgmt->bShareKeyAlgorithm = TRUE; 1259 pMgmt->bShareKeyAlgorithm = true;
1260 } 1260 }
1261 if (wrq->flags & IW_ENCODE_OPEN) { 1261 if (wrq->flags & IW_ENCODE_OPEN) {
1262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n"); 1262 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1263 pMgmt->bShareKeyAlgorithm = FALSE; 1263 pMgmt->bShareKeyAlgorithm = false;
1264 } 1264 }
1265 1265
1266 memset(pMgmt->abyDesireBSSID, 0xFF, 6); 1266 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
@@ -1271,8 +1271,8 @@ int iwctl_siwencode(struct net_device *dev, struct iw_request_info *info,
1271int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info, 1271int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
1272 union iwreq_data *wrqu, char *extra) 1272 union iwreq_data *wrqu, char *extra)
1273{ 1273{
1274 PSDevice pDevice = netdev_priv(dev); 1274 struct vnt_private *pDevice = netdev_priv(dev);
1275 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1275 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1276 struct iw_point *wrq = &wrqu->encoding; 1276 struct iw_point *wrq = &wrqu->encoding;
1277 char abyKey[WLAN_WEP232_KEYLEN]; 1277 char abyKey[WLAN_WEP232_KEYLEN];
1278 1278
@@ -1333,8 +1333,8 @@ int iwctl_giwencode(struct net_device *dev, struct iw_request_info *info,
1333int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info, 1333int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info,
1334 union iwreq_data *wrqu, char *extra) 1334 union iwreq_data *wrqu, char *extra)
1335{ 1335{
1336 PSDevice pDevice = netdev_priv(dev); 1336 struct vnt_private *pDevice = netdev_priv(dev);
1337 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1337 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1338 struct iw_param *wrq = &wrqu->power; 1338 struct iw_param *wrq = &wrqu->power;
1339 int rc = 0; 1339 int rc = 0;
1340 1340
@@ -1385,8 +1385,8 @@ int iwctl_siwpower(struct net_device *dev, struct iw_request_info *info,
1385int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info, 1385int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info,
1386 union iwreq_data *wrqu, char *extra) 1386 union iwreq_data *wrqu, char *extra)
1387{ 1387{
1388 PSDevice pDevice = netdev_priv(dev); 1388 struct vnt_private *pDevice = netdev_priv(dev);
1389 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1389 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1390 struct iw_param *wrq = &wrqu->power; 1390 struct iw_param *wrq = &wrqu->power;
1391 int mode = pDevice->ePSMode; 1391 int mode = pDevice->ePSMode;
1392 1392
@@ -1418,12 +1418,12 @@ int iwctl_giwpower(struct net_device *dev, struct iw_request_info *info,
1418int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info, 1418int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
1419 union iwreq_data *wrqu, char *extra) 1419 union iwreq_data *wrqu, char *extra)
1420{ 1420{
1421 PSDevice pDevice = netdev_priv(dev); 1421 struct vnt_private *pDevice = netdev_priv(dev);
1422 struct iw_param *wrq = &wrqu->sens; 1422 struct iw_param *wrq = &wrqu->sens;
1423 long ldBm; 1423 long ldBm;
1424 1424
1425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS\n"); 1425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS\n");
1426 if (pDevice->bLinkPass == TRUE) { 1426 if (pDevice->bLinkPass == true) {
1427 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm); 1427 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1428 wrq->value = ldBm; 1428 wrq->value = ldBm;
1429 } else { 1429 } else {
@@ -1437,8 +1437,8 @@ int iwctl_giwsens(struct net_device *dev, struct iw_request_info *info,
1437int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info, 1437int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1438 union iwreq_data *wrqu, char *extra) 1438 union iwreq_data *wrqu, char *extra)
1439{ 1439{
1440 PSDevice pDevice = netdev_priv(dev); 1440 struct vnt_private *pDevice = netdev_priv(dev);
1441 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1441 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1442 struct iw_param *wrq = &wrqu->param; 1442 struct iw_param *wrq = &wrqu->param;
1443 int ret = 0; 1443 int ret = 0;
1444 static int wpa_version = 0; // must be static to save the last value, einsn liu 1444 static int wpa_version = 0; // must be static to save the last value, einsn liu
@@ -1508,9 +1508,9 @@ int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1508 case IW_AUTH_80211_AUTH_ALG: 1508 case IW_AUTH_80211_AUTH_ALG:
1509 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value); 1509 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq->value);
1510 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM) 1510 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1511 pMgmt->bShareKeyAlgorithm = FALSE; 1511 pMgmt->bShareKeyAlgorithm = false;
1512 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY) 1512 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1513 pMgmt->bShareKeyAlgorithm = TRUE; 1513 pMgmt->bShareKeyAlgorithm = true;
1514 break; 1514 break;
1515 case IW_AUTH_WPA_ENABLED: 1515 case IW_AUTH_WPA_ENABLED:
1516 break; 1516 break;
@@ -1521,11 +1521,11 @@ int iwctl_siwauth(struct net_device *dev, struct iw_request_info *info,
1521 break; 1521 break;
1522 case IW_AUTH_PRIVACY_INVOKED: 1522 case IW_AUTH_PRIVACY_INVOKED:
1523 pDevice->bEncryptionEnable = !!wrq->value; 1523 pDevice->bEncryptionEnable = !!wrq->value;
1524 if (pDevice->bEncryptionEnable == FALSE) { 1524 if (pDevice->bEncryptionEnable == false) {
1525 wpa_version = 0; 1525 wpa_version = 0;
1526 pairwise = 0; 1526 pairwise = 0;
1527 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; 1527 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1528 pMgmt->bShareKeyAlgorithm = FALSE; 1528 pMgmt->bShareKeyAlgorithm = false;
1529 pMgmt->eAuthenMode = WMAC_AUTH_OPEN; 1529 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
1530 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n"); 1530 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1531 } 1531 }
@@ -1547,8 +1547,8 @@ int iwctl_giwauth(struct net_device *dev, struct iw_request_info *info,
1547int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info, 1547int iwctl_siwgenie(struct net_device *dev, struct iw_request_info *info,
1548 union iwreq_data *wrqu, char *extra) 1548 union iwreq_data *wrqu, char *extra)
1549{ 1549{
1550 PSDevice pDevice = netdev_priv(dev); 1550 struct vnt_private *pDevice = netdev_priv(dev);
1551 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1551 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1552 struct iw_point *wrq = &wrqu->data; 1552 struct iw_point *wrq = &wrqu->data;
1553 int ret = 0; 1553 int ret = 0;
1554 1554
@@ -1582,8 +1582,8 @@ out: // not completely ...not necessary in wpa_supplicant 0.5.8
1582int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info, 1582int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info,
1583 union iwreq_data *wrqu, char *extra) 1583 union iwreq_data *wrqu, char *extra)
1584{ 1584{
1585 PSDevice pDevice = netdev_priv(dev); 1585 struct vnt_private *pDevice = netdev_priv(dev);
1586 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1586 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1587 struct iw_point *wrq = &wrqu->data; 1587 struct iw_point *wrq = &wrqu->data;
1588 int ret = 0; 1588 int ret = 0;
1589 int space = wrq->length; 1589 int space = wrq->length;
@@ -1608,8 +1608,8 @@ int iwctl_giwgenie(struct net_device *dev, struct iw_request_info *info,
1608int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info, 1608int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1609 union iwreq_data *wrqu, char *extra) 1609 union iwreq_data *wrqu, char *extra)
1610{ 1610{
1611 PSDevice pDevice = netdev_priv(dev); 1611 struct vnt_private *pDevice = netdev_priv(dev);
1612 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1612 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1613 struct iw_point *wrq = &wrqu->encoding; 1613 struct iw_point *wrq = &wrqu->encoding;
1614 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra; 1614 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
1615 struct viawget_wpa_param *param=NULL; 1615 struct viawget_wpa_param *param=NULL;
@@ -1697,28 +1697,28 @@ int iwctl_siwencodeext(struct net_device *dev, struct iw_request_info *info,
1697/****this method is so foolish,but there is no other way??? */ 1697/****this method is so foolish,but there is no other way??? */
1698 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) { 1698 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1699 if (param->u.wpa_key.key_index ==0) { 1699 if (param->u.wpa_key.key_index ==0) {
1700 pDevice->bwextstep0 = TRUE; 1700 pDevice->bwextstep0 = true;
1701 } 1701 }
1702 if ((pDevice->bwextstep0 == TRUE) && (param->u.wpa_key.key_index == 1)) { 1702 if ((pDevice->bwextstep0 == true) && (param->u.wpa_key.key_index == 1)) {
1703 pDevice->bwextstep0 = FALSE; 1703 pDevice->bwextstep0 = false;
1704 pDevice->bwextstep1 = TRUE; 1704 pDevice->bwextstep1 = true;
1705 } 1705 }
1706 if ((pDevice->bwextstep1 == TRUE) && (param->u.wpa_key.key_index == 2)) { 1706 if ((pDevice->bwextstep1 == true) && (param->u.wpa_key.key_index == 2)) {
1707 pDevice->bwextstep1 = FALSE; 1707 pDevice->bwextstep1 = false;
1708 pDevice->bwextstep2 = TRUE; 1708 pDevice->bwextstep2 = true;
1709 } 1709 }
1710 if ((pDevice->bwextstep2 == TRUE) && (param->u.wpa_key.key_index == 3)) { 1710 if ((pDevice->bwextstep2 == true) && (param->u.wpa_key.key_index == 3)) {
1711 pDevice->bwextstep2 = FALSE; 1711 pDevice->bwextstep2 = false;
1712 pDevice->bwextstep3 = TRUE; 1712 pDevice->bwextstep3 = true;
1713 } 1713 }
1714 } 1714 }
1715 if (pDevice->bwextstep3 == TRUE) { 1715 if (pDevice->bwextstep3 == true) {
1716 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n"); 1716 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1717 pDevice->bwextstep0 = FALSE; 1717 pDevice->bwextstep0 = false;
1718 pDevice->bwextstep1 = FALSE; 1718 pDevice->bwextstep1 = false;
1719 pDevice->bwextstep2 = FALSE; 1719 pDevice->bwextstep2 = false;
1720 pDevice->bwextstep3 = FALSE; 1720 pDevice->bwextstep3 = false;
1721 pDevice->bWPASuppWextEnabled = TRUE; 1721 pDevice->bWPASuppWextEnabled = true;
1722 memset(pMgmt->abyDesireBSSID, 0xFF, 6); 1722 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1723 KeyvInitTable(pDevice, &pDevice->sKey); 1723 KeyvInitTable(pDevice, &pDevice->sKey);
1724 } 1724 }
@@ -1741,8 +1741,8 @@ int iwctl_giwencodeext(struct net_device *dev, struct iw_request_info *info,
1741int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info, 1741int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info,
1742 union iwreq_data *wrqu, char *extra) 1742 union iwreq_data *wrqu, char *extra)
1743{ 1743{
1744 PSDevice pDevice = netdev_priv(dev); 1744 struct vnt_private *pDevice = netdev_priv(dev);
1745 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1745 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1746 struct iw_mlme *mlme = (struct iw_mlme *)extra; 1746 struct iw_mlme *mlme = (struct iw_mlme *)extra;
1747 int ret = 0; 1747 int ret = 0;
1748 1748
@@ -1758,7 +1758,7 @@ int iwctl_siwmlme(struct net_device *dev, struct iw_request_info *info,
1758 switch (mlme->cmd){ 1758 switch (mlme->cmd){
1759 case IW_MLME_DEAUTH: 1759 case IW_MLME_DEAUTH:
1760 case IW_MLME_DISASSOC: 1760 case IW_MLME_DISASSOC:
1761 if (pDevice->bLinkPass == TRUE) { 1761 if (pDevice->bLinkPass == true) {
1762 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n"); 1762 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1763 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, 1763 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE,
1764 NULL); 1764 NULL);
diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c
index 8c78b86b5c80..416175e8ba53 100644
--- a/drivers/staging/vt6656/key.c
+++ b/drivers/staging/vt6656/key.c
@@ -60,26 +60,25 @@ static int msglevel =MSG_LEVEL_INFO;
60/*--------------------- Static Variables --------------------------*/ 60/*--------------------- Static Variables --------------------------*/
61 61
62/*--------------------- Static Functions --------------------------*/ 62/*--------------------- Static Functions --------------------------*/
63static void s_vCheckKeyTableValid(void *pDeviceHandler, 63static void s_vCheckKeyTableValid(struct vnt_private *pDevice,
64 PSKeyManagement pTable) 64 PSKeyManagement pTable)
65{ 65{
66 PSDevice pDevice = (PSDevice) pDeviceHandler; 66 int i;
67 int i; 67 u16 wLength = 0;
68 WORD wLength = 0; 68 u8 pbyData[MAX_KEY_TABLE];
69 BYTE pbyData[MAX_KEY_TABLE];
70 69
71 for (i=0;i<MAX_KEY_TABLE;i++) { 70 for (i=0;i<MAX_KEY_TABLE;i++) {
72 if ((pTable->KeyTable[i].bInUse == TRUE) && 71 if ((pTable->KeyTable[i].bInUse == true) &&
73 (pTable->KeyTable[i].PairwiseKey.bKeyValid == FALSE) && 72 (pTable->KeyTable[i].PairwiseKey.bKeyValid == false) &&
74 (pTable->KeyTable[i].GroupKey[0].bKeyValid == FALSE) && 73 (pTable->KeyTable[i].GroupKey[0].bKeyValid == false) &&
75 (pTable->KeyTable[i].GroupKey[1].bKeyValid == FALSE) && 74 (pTable->KeyTable[i].GroupKey[1].bKeyValid == false) &&
76 (pTable->KeyTable[i].GroupKey[2].bKeyValid == FALSE) && 75 (pTable->KeyTable[i].GroupKey[2].bKeyValid == false) &&
77 (pTable->KeyTable[i].GroupKey[3].bKeyValid == FALSE) 76 (pTable->KeyTable[i].GroupKey[3].bKeyValid == false)
78 ) { 77 ) {
79 78
80 pTable->KeyTable[i].bInUse = FALSE; 79 pTable->KeyTable[i].bInUse = false;
81 pTable->KeyTable[i].wKeyCtl = 0; 80 pTable->KeyTable[i].wKeyCtl = 0;
82 pTable->KeyTable[i].bSoftWEP = FALSE; 81 pTable->KeyTable[i].bSoftWEP = false;
83 pbyData[wLength++] = (BYTE) i; 82 pbyData[wLength++] = (BYTE) i;
84 //MACvDisableKeyEntry(pDevice, i); 83 //MACvDisableKeyEntry(pDevice, i);
85 } 84 }
@@ -112,27 +111,25 @@ static void s_vCheckKeyTableValid(void *pDeviceHandler,
112 * Return Value: none 111 * Return Value: none
113 * 112 *
114 */ 113 */
115void KeyvInitTable(void *pDeviceHandler, PSKeyManagement pTable) 114void KeyvInitTable(struct vnt_private *pDevice, PSKeyManagement pTable)
116{ 115{
117 PSDevice pDevice = (PSDevice) pDeviceHandler; 116 int i, jj;
118 int i; 117 u8 pbyData[MAX_KEY_TABLE+1];
119 int jj;
120 BYTE pbyData[MAX_KEY_TABLE+1];
121 118
122 spin_lock_irq(&pDevice->lock); 119 spin_lock_irq(&pDevice->lock);
123 for (i=0;i<MAX_KEY_TABLE;i++) { 120 for (i=0;i<MAX_KEY_TABLE;i++) {
124 pTable->KeyTable[i].bInUse = FALSE; 121 pTable->KeyTable[i].bInUse = false;
125 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; 122 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
126 pTable->KeyTable[i].PairwiseKey.pvKeyTable = 123 pTable->KeyTable[i].PairwiseKey.pvKeyTable =
127 (void *)&pTable->KeyTable[i]; 124 (void *)&pTable->KeyTable[i];
128 for (jj=0; jj < MAX_GROUP_KEY; jj++) { 125 for (jj=0; jj < MAX_GROUP_KEY; jj++) {
129 pTable->KeyTable[i].GroupKey[jj].bKeyValid = FALSE; 126 pTable->KeyTable[i].GroupKey[jj].bKeyValid = false;
130 pTable->KeyTable[i].GroupKey[jj].pvKeyTable = 127 pTable->KeyTable[i].GroupKey[jj].pvKeyTable =
131 (void *) &(pTable->KeyTable[i]); 128 (void *) &(pTable->KeyTable[i]);
132 } 129 }
133 pTable->KeyTable[i].wKeyCtl = 0; 130 pTable->KeyTable[i].wKeyCtl = 0;
134 pTable->KeyTable[i].dwGTKeyIndex = 0; 131 pTable->KeyTable[i].dwGTKeyIndex = 0;
135 pTable->KeyTable[i].bSoftWEP = FALSE; 132 pTable->KeyTable[i].bSoftWEP = false;
136 pbyData[i] = (BYTE) i; 133 pbyData[i] = (BYTE) i;
137 } 134 }
138 pbyData[i] = (BYTE) i; 135 pbyData[i] = (BYTE) i;
@@ -161,43 +158,43 @@ void KeyvInitTable(void *pDeviceHandler, PSKeyManagement pTable)
161 * Out: 158 * Out:
162 * pKey - Key return 159 * pKey - Key return
163 * 160 *
164 * Return Value: TRUE if found otherwise FALSE 161 * Return Value: true if found otherwise false
165 * 162 *
166 */ 163 */
167BOOL KeybGetKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyIndex, 164int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex,
168 PSKeyItem *pKey) 165 PSKeyItem *pKey)
169{ 166{
170 int i; 167 int i;
171 168
172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n"); 169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey()\n");
173 170
174 *pKey = NULL; 171 *pKey = NULL;
175 for (i=0;i<MAX_KEY_TABLE;i++) { 172 for (i=0;i<MAX_KEY_TABLE;i++) {
176 if ((pTable->KeyTable[i].bInUse == TRUE) && 173 if ((pTable->KeyTable[i].bInUse == true) &&
177 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { 174 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
178 if (dwKeyIndex == 0xFFFFFFFF) { 175 if (dwKeyIndex == 0xFFFFFFFF) {
179 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) { 176 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
180 *pKey = &(pTable->KeyTable[i].PairwiseKey); 177 *pKey = &(pTable->KeyTable[i].PairwiseKey);
181 return (TRUE); 178 return (true);
182 } 179 }
183 else { 180 else {
184 return (FALSE); 181 return (false);
185 } 182 }
186 } else if (dwKeyIndex < MAX_GROUP_KEY) { 183 } else if (dwKeyIndex < MAX_GROUP_KEY) {
187 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) { 184 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == true) {
188 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]); 185 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
189 return (TRUE); 186 return (true);
190 } 187 }
191 else { 188 else {
192 return (FALSE); 189 return (false);
193 } 190 }
194 } 191 }
195 else { 192 else {
196 return (FALSE); 193 return (false);
197 } 194 }
198 } 195 }
199 } 196 }
200 return (FALSE); 197 return (false);
201} 198}
202 199
203 200
@@ -215,37 +212,28 @@ BOOL KeybGetKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyIndex,
215 * Out: 212 * Out:
216 * none 213 * none
217 * 214 *
218 * Return Value: TRUE if success otherwise FALSE 215 * Return Value: true if success otherwise false
219 * 216 *
220 */ 217 */
221BOOL KeybSetKey( 218int KeybSetKey(struct vnt_private *pDevice, PSKeyManagement pTable,
222 void *pDeviceHandler, 219 u8 *pbyBSSID, u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey,
223 PSKeyManagement pTable, 220 u8 byKeyDecMode)
224 PBYTE pbyBSSID,
225 DWORD dwKeyIndex,
226 u32 uKeyLength,
227 PQWORD pKeyRSC,
228 PBYTE pbyKey,
229 BYTE byKeyDecMode
230 )
231{ 221{
232 PSDevice pDevice = (PSDevice) pDeviceHandler; 222 PSKeyItem pKey;
233 int i,j; 223 int i, j, ii;
234 unsigned int ii; 224 u32 uKeyIdx;
235 PSKeyItem pKey;
236 unsigned int uKeyIdx;
237 225
238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO 226 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
239 "Enter KeybSetKey: %X\n", dwKeyIndex); 227 "Enter KeybSetKey: %X\n", dwKeyIndex);
240 228
241 j = (MAX_KEY_TABLE-1); 229 j = (MAX_KEY_TABLE-1);
242 for (i=0;i<(MAX_KEY_TABLE-1);i++) { 230 for (i=0;i<(MAX_KEY_TABLE-1);i++) {
243 if ((pTable->KeyTable[i].bInUse == FALSE) && 231 if ((pTable->KeyTable[i].bInUse == false) &&
244 (j == (MAX_KEY_TABLE-1))) { 232 (j == (MAX_KEY_TABLE-1))) {
245 // found empty table 233 // found empty table
246 j = i; 234 j = i;
247 } 235 }
248 if ((pTable->KeyTable[i].bInUse == TRUE) && 236 if ((pTable->KeyTable[i].bInUse == true) &&
249 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { 237 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
250 // found table already exist 238 // found table already exist
251 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { 239 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
@@ -257,7 +245,7 @@ BOOL KeybSetKey(
257 } else { 245 } else {
258 // Group key 246 // Group key
259 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) 247 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
260 return (FALSE); 248 return (false);
261 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]); 249 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
262 if ((dwKeyIndex & TRANSMIT_KEY) != 0) { 250 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
263 // Group transmit key 251 // Group transmit key
@@ -273,7 +261,7 @@ BOOL KeybSetKey(
273 } 261 }
274 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly 262 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
275 263
276 pKey->bKeyValid = TRUE; 264 pKey->bKeyValid = true;
277 pKey->uKeyLength = uKeyLength; 265 pKey->uKeyLength = uKeyLength;
278 pKey->dwKeyIndex = dwKeyIndex; 266 pKey->dwKeyIndex = dwKeyIndex;
279 pKey->byCipherSuite = byKeyDecMode; 267 pKey->byCipherSuite = byKeyDecMode;
@@ -286,13 +274,11 @@ BOOL KeybSetKey(
286 } 274 }
287 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey); 275 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
288 276
289 if ((dwKeyIndex & USE_KEYRSC) == 0) { 277 if ((dwKeyIndex & USE_KEYRSC) == 0)
290 // RSC set by NIC 278 pKey->KeyRSC = 0; /* RSC set by NIC */
291 memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); 279 else
292 } 280 pKey->KeyRSC = *KeyRSC;
293 else { 281
294 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
295 }
296 pKey->dwTSC47_16 = 0; 282 pKey->dwTSC47_16 = 0;
297 pKey->wTSC15_0 = 0; 283 pKey->wTSC15_0 = 0;
298 284
@@ -312,12 +298,12 @@ BOOL KeybSetKey(
312 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ", 298 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ",
313 pKey->dwKeyIndex); 299 pKey->dwKeyIndex);
314 300
315 return (TRUE); 301 return (true);
316 } 302 }
317 } 303 }
318 if (j < (MAX_KEY_TABLE-1)) { 304 if (j < (MAX_KEY_TABLE-1)) {
319 memcpy(pTable->KeyTable[j].abyBSSID, pbyBSSID, ETH_ALEN); 305 memcpy(pTable->KeyTable[j].abyBSSID, pbyBSSID, ETH_ALEN);
320 pTable->KeyTable[j].bInUse = TRUE; 306 pTable->KeyTable[j].bInUse = true;
321 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { 307 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
322 // Pairwise key 308 // Pairwise key
323 pKey = &(pTable->KeyTable[j].PairwiseKey); 309 pKey = &(pTable->KeyTable[j].PairwiseKey);
@@ -327,7 +313,7 @@ BOOL KeybSetKey(
327 } else { 313 } else {
328 // Group key 314 // Group key
329 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) 315 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
330 return (FALSE); 316 return (false);
331 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]); 317 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
332 if ((dwKeyIndex & TRANSMIT_KEY) != 0) { 318 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
333 // Group transmit key 319 // Group transmit key
@@ -343,7 +329,7 @@ BOOL KeybSetKey(
343 } 329 }
344 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly 330 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
345 331
346 pKey->bKeyValid = TRUE; 332 pKey->bKeyValid = true;
347 pKey->uKeyLength = uKeyLength; 333 pKey->uKeyLength = uKeyLength;
348 pKey->dwKeyIndex = dwKeyIndex; 334 pKey->dwKeyIndex = dwKeyIndex;
349 pKey->byCipherSuite = byKeyDecMode; 335 pKey->byCipherSuite = byKeyDecMode;
@@ -356,13 +342,11 @@ BOOL KeybSetKey(
356 } 342 }
357 MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey); 343 MACvSetKeyEntry(pDevice, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey);
358 344
359 if ((dwKeyIndex & USE_KEYRSC) == 0) { 345 if ((dwKeyIndex & USE_KEYRSC) == 0)
360 // RSC set by NIC 346 pKey->KeyRSC = 0; /* RSC set by NIC */
361 memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); 347 else
362 } 348 pKey->KeyRSC = *KeyRSC;
363 else { 349
364 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
365 }
366 pKey->dwTSC47_16 = 0; 350 pKey->dwTSC47_16 = 0;
367 pKey->wTSC15_0 = 0; 351 pKey->wTSC15_0 = 0;
368 352
@@ -381,9 +365,9 @@ BOOL KeybSetKey(
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ", 365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n ",
382 pKey->dwKeyIndex); 366 pKey->dwKeyIndex);
383 367
384 return (TRUE); 368 return (true);
385 } 369 }
386 return (FALSE); 370 return (false);
387} 371}
388 372
389 373
@@ -398,68 +382,64 @@ BOOL KeybSetKey(
398 * Out: 382 * Out:
399 * none 383 * none
400 * 384 *
401 * Return Value: TRUE if success otherwise FALSE 385 * Return Value: true if success otherwise false
402 * 386 *
403 */ 387 */
404BOOL KeybRemoveKey( 388
405 void *pDeviceHandler, 389int KeybRemoveKey(struct vnt_private *pDevice, PSKeyManagement pTable,
406 PSKeyManagement pTable, 390 u8 *pbyBSSID, u32 dwKeyIndex)
407 PBYTE pbyBSSID,
408 DWORD dwKeyIndex
409 )
410{ 391{
411 PSDevice pDevice = (PSDevice) pDeviceHandler; 392 int i;
412 int i; 393 int bReturnValue = false;
413 BOOL bReturnValue = FALSE;
414 394
415 if (is_broadcast_ether_addr(pbyBSSID)) { 395 if (is_broadcast_ether_addr(pbyBSSID)) {
416 // delete all keys 396 // delete all keys
417 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { 397 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
418 for (i=0;i<MAX_KEY_TABLE;i++) { 398 for (i=0;i<MAX_KEY_TABLE;i++) {
419 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; 399 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
420 } 400 }
421 bReturnValue = TRUE; 401 bReturnValue = true;
422 } 402 }
423 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { 403 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
424 for (i=0;i<MAX_KEY_TABLE;i++) { 404 for (i=0;i<MAX_KEY_TABLE;i++) {
425 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; 405 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
426 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) { 406 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
427 // remove Group transmit key 407 // remove Group transmit key
428 pTable->KeyTable[i].dwGTKeyIndex = 0; 408 pTable->KeyTable[i].dwGTKeyIndex = 0;
429 } 409 }
430 } 410 }
431 bReturnValue = TRUE; 411 bReturnValue = true;
432 } 412 }
433 else { 413 else {
434 bReturnValue = FALSE; 414 bReturnValue = false;
435 } 415 }
436 416
437 } else { 417 } else {
438 for (i=0;i<MAX_KEY_TABLE;i++) { 418 for (i=0;i<MAX_KEY_TABLE;i++) {
439 if ( (pTable->KeyTable[i].bInUse == TRUE) && 419 if ( (pTable->KeyTable[i].bInUse == true) &&
440 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { 420 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
441 421
442 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { 422 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
443 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; 423 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
444 bReturnValue = TRUE; 424 bReturnValue = true;
445 break; 425 break;
446 } 426 }
447 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { 427 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
448 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; 428 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
449 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) { 429 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
450 // remove Group transmit key 430 // remove Group transmit key
451 pTable->KeyTable[i].dwGTKeyIndex = 0; 431 pTable->KeyTable[i].dwGTKeyIndex = 0;
452 } 432 }
453 bReturnValue = TRUE; 433 bReturnValue = true;
454 break; 434 break;
455 } 435 }
456 else { 436 else {
457 bReturnValue = FALSE; 437 bReturnValue = false;
458 break; 438 break;
459 } 439 }
460 } //pTable->KeyTable[i].bInUse == TRUE 440 } //pTable->KeyTable[i].bInUse == true
461 } //for 441 } //for
462 bReturnValue = TRUE; 442 bReturnValue = true;
463 } 443 }
464 444
465 s_vCheckKeyTableValid(pDevice,pTable); 445 s_vCheckKeyTableValid(pDevice,pTable);
@@ -479,31 +459,27 @@ BOOL KeybRemoveKey(
479 * Out: 459 * Out:
480 * none 460 * none
481 * 461 *
482 * Return Value: TRUE if success otherwise FALSE 462 * Return Value: true if success otherwise false
483 * 463 *
484 */ 464 */
485BOOL KeybRemoveAllKey( 465int KeybRemoveAllKey(struct vnt_private *pDevice, PSKeyManagement pTable,
486 void *pDeviceHandler, 466 u8 *pbyBSSID)
487 PSKeyManagement pTable,
488 PBYTE pbyBSSID
489 )
490{ 467{
491 PSDevice pDevice = (PSDevice) pDeviceHandler; 468 int i, u;
492 int i,u;
493 469
494 for (i=0;i<MAX_KEY_TABLE;i++) { 470 for (i=0;i<MAX_KEY_TABLE;i++) {
495 if ((pTable->KeyTable[i].bInUse == TRUE) && 471 if ((pTable->KeyTable[i].bInUse == true) &&
496 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { 472 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
497 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE; 473 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
498 for (u = 0; u < MAX_GROUP_KEY; u++) 474 for (u = 0; u < MAX_GROUP_KEY; u++)
499 pTable->KeyTable[i].GroupKey[u].bKeyValid = FALSE; 475 pTable->KeyTable[i].GroupKey[u].bKeyValid = false;
500 476
501 pTable->KeyTable[i].dwGTKeyIndex = 0; 477 pTable->KeyTable[i].dwGTKeyIndex = 0;
502 s_vCheckKeyTableValid(pDevice, pTable); 478 s_vCheckKeyTableValid(pDevice, pTable);
503 return (TRUE); 479 return (true);
504 } 480 }
505 } 481 }
506 return (FALSE); 482 return (false);
507} 483}
508 484
509/* 485/*
@@ -515,21 +491,17 @@ BOOL KeybRemoveAllKey(
515 * Out: 491 * Out:
516 * none 492 * none
517 * 493 *
518 * Return Value: TRUE if success otherwise FALSE 494 * Return Value: true if success otherwise false
519 * 495 *
520 */ 496 */
521void KeyvRemoveWEPKey( 497void KeyvRemoveWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable,
522 void *pDeviceHandler, 498 u32 dwKeyIndex)
523 PSKeyManagement pTable,
524 DWORD dwKeyIndex
525 )
526{ 499{
527 PSDevice pDevice = (PSDevice) pDeviceHandler;
528 500
529 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { 501 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
530 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) { 502 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == true) {
531 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) { 503 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
532 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE; 504 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
533 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) { 505 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
534 // remove Group transmit key 506 // remove Group transmit key
535 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0; 507 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
@@ -541,9 +513,8 @@ void KeyvRemoveWEPKey(
541 return; 513 return;
542} 514}
543 515
544void KeyvRemoveAllWEPKey(void *pDeviceHandler, PSKeyManagement pTable) 516void KeyvRemoveAllWEPKey(struct vnt_private *pDevice, PSKeyManagement pTable)
545{ 517{
546 PSDevice pDevice = (PSDevice) pDeviceHandler;
547 int i; 518 int i;
548 519
549 for (i = 0; i < MAX_GROUP_KEY; i++) 520 for (i = 0; i < MAX_GROUP_KEY; i++)
@@ -560,22 +531,23 @@ void KeyvRemoveAllWEPKey(void *pDeviceHandler, PSKeyManagement pTable)
560 * Out: 531 * Out:
561 * pKey - Key return 532 * pKey - Key return
562 * 533 *
563 * Return Value: TRUE if found otherwise FALSE 534 * Return Value: true if found otherwise false
564 * 535 *
565 */ 536 */
566BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType, 537int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType,
567 PSKeyItem *pKey) 538 PSKeyItem *pKey)
568{ 539{
569 int i, ii; 540 int i, ii;
541
542 *pKey = NULL;
570 543
571 *pKey = NULL;
572 for (i = 0; i < MAX_KEY_TABLE; i++) { 544 for (i = 0; i < MAX_KEY_TABLE; i++) {
573 if ((pTable->KeyTable[i].bInUse == TRUE) && 545 if ((pTable->KeyTable[i].bInUse == true) &&
574 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { 546 !compare_ether_addr(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
575 547
576 if (dwKeyType == PAIRWISE_KEY) { 548 if (dwKeyType == PAIRWISE_KEY) {
577 549
578 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) { 550 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == true) {
579 *pKey = &(pTable->KeyTable[i].PairwiseKey); 551 *pKey = &(pTable->KeyTable[i].PairwiseKey);
580 552
581 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:"); 553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
@@ -586,19 +558,19 @@ BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType,
586 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); 558 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
587 559
588 560
589 return (TRUE); 561 return (true);
590 } 562 }
591 else { 563 else {
592 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n"); 564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == false\n");
593 return (FALSE); 565 return (false);
594 } 566 }
595 } // End of Type == PAIRWISE 567 } // End of Type == PAIRWISE
596 else { 568 else {
597 if (pTable->KeyTable[i].dwGTKeyIndex == 0) { 569 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n"); 570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
599 return FALSE; 571 return false;
600 } 572 }
601 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) { 573 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == true) {
602 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]); 574 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
603 575
604 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:"); 576 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
@@ -610,11 +582,11 @@ BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType,
610 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %X\n", 582 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %X\n",
611 pTable->KeyTable[i].dwGTKeyIndex); 583 pTable->KeyTable[i].dwGTKeyIndex);
612 584
613 return (TRUE); 585 return (true);
614 } 586 }
615 else { 587 else {
616 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n"); 588 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == false\n");
617 return (FALSE); 589 return (false);
618 } 590 }
619 } // End of Type = GROUP 591 } // End of Type = GROUP
620 } // BSSID match 592 } // BSSID match
@@ -624,7 +596,7 @@ BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType,
624 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii)); 596 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii));
625 } 597 }
626 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n"); 598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
627 return (FALSE); 599 return (false);
628} 600}
629 601
630 602
@@ -637,22 +609,23 @@ BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType,
637 * Out: 609 * Out:
638 * none 610 * none
639 * 611 *
640 * Return Value: TRUE if found otherwise FALSE 612 * Return Value: true if found otherwise false
641 * 613 *
642 */ 614 */
643BOOL KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey) 615int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey)
644{ 616{
645 int i; 617 int i;
618
619 *pKey = NULL;
646 620
647 *pKey = NULL;
648 for (i=0;i<MAX_KEY_TABLE;i++) { 621 for (i=0;i<MAX_KEY_TABLE;i++) {
649 if ((pTable->KeyTable[i].bInUse == TRUE) && 622 if ((pTable->KeyTable[i].bInUse == true) &&
650 (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) { 623 (pTable->KeyTable[i].PairwiseKey.bKeyValid == true)) {
651 *pKey = &(pTable->KeyTable[i].PairwiseKey); 624 *pKey = &(pTable->KeyTable[i].PairwiseKey);
652 return (TRUE); 625 return (true);
653 } 626 }
654 } 627 }
655 return (FALSE); 628 return (false);
656} 629}
657 630
658/* 631/*
@@ -668,37 +641,31 @@ BOOL KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey)
668 * Out: 641 * Out:
669 * none 642 * none
670 * 643 *
671 * Return Value: TRUE if success otherwise FALSE 644 * Return Value: true if success otherwise false
672 * 645 *
673 */ 646 */
674BOOL KeybSetDefaultKey( 647
675 void *pDeviceHandler, 648int KeybSetDefaultKey(struct vnt_private *pDevice, PSKeyManagement pTable,
676 PSKeyManagement pTable, 649 u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey,
677 DWORD dwKeyIndex, 650 u8 byKeyDecMode)
678 u32 uKeyLength,
679 PQWORD pKeyRSC,
680 PBYTE pbyKey,
681 BYTE byKeyDecMode
682 )
683{ 651{
684 PSDevice pDevice = (PSDevice) pDeviceHandler; 652 int ii;
685 unsigned int ii; 653 PSKeyItem pKey;
686 PSKeyItem pKey; 654 u32 uKeyIdx;
687 unsigned int uKeyIdx;
688 655
689 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetDefaultKey: %1x, %d\n", 656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enter KeybSetDefaultKey: %1x, %d\n",
690 (int) dwKeyIndex, (int) uKeyLength); 657 (int) dwKeyIndex, (int) uKeyLength);
691 658
692 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key 659 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
693 return (FALSE); 660 return (false);
694 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { 661 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
695 return (FALSE); 662 return (false);
696 } 663 }
697 664
698 if (uKeyLength > MAX_KEY_LEN) 665 if (uKeyLength > MAX_KEY_LEN)
699 return false; 666 return false;
700 667
701 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE; 668 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = true;
702 for (ii = 0; ii < ETH_ALEN; ii++) 669 for (ii = 0; ii < ETH_ALEN; ii++)
703 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF; 670 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
704 671
@@ -722,13 +689,13 @@ BOOL KeybSetDefaultKey(
722 if ((uKeyLength == WLAN_WEP232_KEYLEN) && 689 if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
723 (byKeyDecMode == KEY_CTL_WEP)) { 690 (byKeyDecMode == KEY_CTL_WEP)) {
724 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match 691 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match
725 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE; 692 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true;
726 } else { 693 } else {
727 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == FALSE) 694 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == false)
728 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match 695 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match
729 } 696 }
730 697
731 pKey->bKeyValid = TRUE; 698 pKey->bKeyValid = true;
732 pKey->uKeyLength = uKeyLength; 699 pKey->uKeyLength = uKeyLength;
733 pKey->dwKeyIndex = dwKeyIndex; 700 pKey->dwKeyIndex = dwKeyIndex;
734 pKey->byCipherSuite = byKeyDecMode; 701 pKey->byCipherSuite = byKeyDecMode;
@@ -742,12 +709,12 @@ BOOL KeybSetDefaultKey(
742 709
743 MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD) pKey->abyKey); 710 MACvSetKeyEntry(pDevice, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD) pKey->abyKey);
744 711
745 if ((dwKeyIndex & USE_KEYRSC) == 0) { 712 if ((dwKeyIndex & USE_KEYRSC) == 0)
746 // RSC set by NIC 713 pKey->KeyRSC = 0; /* RSC set by NIC */
747 memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); 714 else
748 } else { 715 pKey->KeyRSC = *KeyRSC;
749 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD)); 716
750 } 717
751 pKey->dwTSC47_16 = 0; 718 pKey->dwTSC47_16 = 0;
752 pKey->wTSC15_0 = 0; 719 pKey->wTSC15_0 = 0;
753 720
@@ -767,7 +734,7 @@ BOOL KeybSetDefaultKey(
767 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n", 734 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %x\n",
768 pKey->dwKeyIndex); 735 pKey->dwKeyIndex);
769 736
770 return (TRUE); 737 return (true);
771} 738}
772 739
773 740
@@ -784,37 +751,30 @@ BOOL KeybSetDefaultKey(
784 * Out: 751 * Out:
785 * none 752 * none
786 * 753 *
787 * Return Value: TRUE if success otherwise FALSE 754 * Return Value: true if success otherwise false
788 * 755 *
789 */ 756 */
790BOOL KeybSetAllGroupKey( 757
791 void *pDeviceHandler, 758int KeybSetAllGroupKey(struct vnt_private *pDevice, PSKeyManagement pTable,
792 PSKeyManagement pTable, 759 u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey,
793 DWORD dwKeyIndex, 760 u8 byKeyDecMode)
794 u32 uKeyLength,
795 PQWORD pKeyRSC,
796 PBYTE pbyKey,
797 BYTE byKeyDecMode
798 )
799{ 761{
800 PSDevice pDevice = (PSDevice) pDeviceHandler; 762 int i, ii;
801 int i; 763 PSKeyItem pKey;
802 unsigned int ii; 764 u32 uKeyIdx;
803 PSKeyItem pKey;
804 unsigned int uKeyIdx;
805 765
806 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %X\n", 766 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %X\n",
807 dwKeyIndex); 767 dwKeyIndex);
808 768
809 769
810 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key 770 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
811 return (FALSE); 771 return (false);
812 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) { 772 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
813 return (FALSE); 773 return (false);
814 } 774 }
815 775
816 for (i=0; i < MAX_KEY_TABLE-1; i++) { 776 for (i=0; i < MAX_KEY_TABLE-1; i++) {
817 if (pTable->KeyTable[i].bInUse == TRUE) { 777 if (pTable->KeyTable[i].bInUse == true) {
818 // found table already exist 778 // found table already exist
819 // Group key 779 // Group key
820 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]); 780 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
@@ -833,7 +793,7 @@ BOOL KeybSetAllGroupKey(
833 793
834 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly 794 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
835 795
836 pKey->bKeyValid = TRUE; 796 pKey->bKeyValid = true;
837 pKey->uKeyLength = uKeyLength; 797 pKey->uKeyLength = uKeyLength;
838 pKey->dwKeyIndex = dwKeyIndex; 798 pKey->dwKeyIndex = dwKeyIndex;
839 pKey->byCipherSuite = byKeyDecMode; 799 pKey->byCipherSuite = byKeyDecMode;
@@ -847,13 +807,11 @@ BOOL KeybSetAllGroupKey(
847 807
848 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD) pKey->abyKey); 808 MACvSetKeyEntry(pDevice, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD) pKey->abyKey);
849 809
850 if ((dwKeyIndex & USE_KEYRSC) == 0) { 810 if ((dwKeyIndex & USE_KEYRSC) == 0)
851 // RSC set by NIC 811 pKey->KeyRSC = 0; /* RSC set by NIC */
852 memset(&(pKey->KeyRSC), 0, sizeof(QWORD)); 812 else
853 } 813 pKey->KeyRSC = *KeyRSC;
854 else { 814
855 memcpy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
856 }
857 pKey->dwTSC47_16 = 0; 815 pKey->dwTSC47_16 = 0;
858 pKey->wTSC15_0 = 0; 816 pKey->wTSC15_0 = 0;
859 817
@@ -870,7 +828,7 @@ BOOL KeybSetAllGroupKey(
870 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0)); 828 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
871 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex)); 829 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
872 830
873 } // (pTable->KeyTable[i].bInUse == TRUE) 831 } // (pTable->KeyTable[i].bInUse == true)
874 } 832 }
875 return (TRUE); 833 return (true);
876} 834}
diff --git a/drivers/staging/vt6656/key.h b/drivers/staging/vt6656/key.h
index bd35d39621ae..7ecddcd6bcfa 100644
--- a/drivers/staging/vt6656/key.h
+++ b/drivers/staging/vt6656/key.h
@@ -57,10 +57,10 @@
57 57
58typedef struct tagSKeyItem 58typedef struct tagSKeyItem
59{ 59{
60 BOOL bKeyValid; 60 bool bKeyValid;
61 u32 uKeyLength; 61 u32 uKeyLength;
62 BYTE abyKey[MAX_KEY_LEN]; 62 BYTE abyKey[MAX_KEY_LEN];
63 QWORD KeyRSC; 63 u64 KeyRSC;
64 DWORD dwTSC47_16; 64 DWORD dwTSC47_16;
65 WORD wTSC15_0; 65 WORD wTSC15_0;
66 BYTE byCipherSuite; 66 BYTE byCipherSuite;
@@ -76,9 +76,9 @@ typedef struct tagSKeyTable
76 SKeyItem PairwiseKey; 76 SKeyItem PairwiseKey;
77 SKeyItem GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328 77 SKeyItem GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328
78 DWORD dwGTKeyIndex; // GroupTransmitKey Index 78 DWORD dwGTKeyIndex; // GroupTransmitKey Index
79 BOOL bInUse; 79 bool bInUse;
80 WORD wKeyCtl; 80 WORD wKeyCtl;
81 BOOL bSoftWEP; 81 bool bSoftWEP;
82 BYTE byReserved1[6]; 82 BYTE byReserved1[6];
83} SKeyTable, *PSKeyTable; //352 83} SKeyTable, *PSKeyTable; //352
84 84
@@ -97,69 +97,37 @@ typedef struct tagSKeyManagement
97 97
98/*--------------------- Export Functions --------------------------*/ 98/*--------------------- Export Functions --------------------------*/
99 99
100void KeyvInitTable(void *pDeviceHandler, PSKeyManagement pTable); 100void KeyvInitTable(struct vnt_private *, PSKeyManagement pTable);
101 101
102BOOL KeybGetKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyIndex, 102int KeybGetKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyIndex,
103 PSKeyItem *pKey); 103 PSKeyItem *pKey);
104 104
105BOOL KeybSetKey( 105int KeybSetKey(struct vnt_private *, PSKeyManagement pTable, u8 *pbyBSSID,
106 void *pDeviceHandler, 106 u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey,
107 PSKeyManagement pTable, 107 u8 byKeyDecMode);
108 PBYTE pbyBSSID, 108
109 DWORD dwKeyIndex, 109int KeybRemoveKey(struct vnt_private *, PSKeyManagement pTable,
110 u32 uKeyLength, 110 u8 *pbyBSSID, u32 dwKeyIndex);
111 PQWORD pKeyRSC, 111
112 PBYTE pbyKey, 112int KeybRemoveAllKey(struct vnt_private *, PSKeyManagement pTable,
113 BYTE byKeyDecMode 113 u8 *pbyBSSID);
114 ); 114
115 115void KeyvRemoveWEPKey(struct vnt_private *, PSKeyManagement pTable,
116BOOL KeybRemoveKey( 116 u32 dwKeyIndex);
117 void *pDeviceHandler, 117
118 PSKeyManagement pTable, 118void KeyvRemoveAllWEPKey(struct vnt_private *, PSKeyManagement pTable);
119 PBYTE pbyBSSID, 119
120 DWORD dwKeyIndex 120int KeybGetTransmitKey(PSKeyManagement pTable, u8 *pbyBSSID, u32 dwKeyType,
121 ); 121 PSKeyItem *pKey);
122 122
123BOOL KeybRemoveAllKey( 123int KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey);
124 void *pDeviceHandler, 124
125 PSKeyManagement pTable, 125int KeybSetDefaultKey(struct vnt_private *, PSKeyManagement pTable,
126 PBYTE pbyBSSID 126 u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey,
127 ); 127 u8 byKeyDecMode);
128 128
129void KeyvRemoveWEPKey( 129int KeybSetAllGroupKey(struct vnt_private *, PSKeyManagement pTable,
130 void *pDeviceHandler, 130 u32 dwKeyIndex, u32 uKeyLength, u64 *KeyRSC, u8 *pbyKey,
131 PSKeyManagement pTable, 131 u8 byKeyDecMode);
132 DWORD dwKeyIndex
133 );
134
135void KeyvRemoveAllWEPKey(
136 void *pDeviceHandler,
137 PSKeyManagement pTable
138 );
139
140BOOL KeybGetTransmitKey(PSKeyManagement pTable, PBYTE pbyBSSID, DWORD dwKeyType,
141 PSKeyItem *pKey);
142
143BOOL KeybCheckPairewiseKey(PSKeyManagement pTable, PSKeyItem *pKey);
144
145BOOL KeybSetDefaultKey(
146 void *pDeviceHandler,
147 PSKeyManagement pTable,
148 DWORD dwKeyIndex,
149 u32 uKeyLength,
150 PQWORD pKeyRSC,
151 PBYTE pbyKey,
152 BYTE byKeyDecMode
153 );
154
155BOOL KeybSetAllGroupKey(
156 void *pDeviceHandler,
157 PSKeyManagement pTable,
158 DWORD dwKeyIndex,
159 u32 uKeyLength,
160 PQWORD pKeyRSC,
161 PBYTE pbyKey,
162 BYTE byKeyDecMode
163 );
164 132
165#endif /* __KEY_H__ */ 133#endif /* __KEY_H__ */
diff --git a/drivers/staging/vt6656/mac.c b/drivers/staging/vt6656/mac.c
index 8fddc7b3930b..76d307b58d52 100644
--- a/drivers/staging/vt6656/mac.c
+++ b/drivers/staging/vt6656/mac.c
@@ -68,11 +68,11 @@ static int msglevel =MSG_LEVEL_INFO;
68 * Return Value: none 68 * Return Value: none
69 * 69 *
70 */ 70 */
71void MACvSetMultiAddrByHash (PSDevice pDevice, BYTE byHashIdx) 71void MACvSetMultiAddrByHash(struct vnt_private *pDevice, u8 byHashIdx)
72{ 72{
73 unsigned int uByteIdx; 73 u8 uByteIdx;
74 BYTE byBitMask; 74 u8 byBitMask;
75 BYTE pbyData[2]; 75 u8 pbyData[2];
76 76
77 77
78 // calculate byte position 78 // calculate byte position
@@ -110,9 +110,9 @@ void MACvSetMultiAddrByHash (PSDevice pDevice, BYTE byHashIdx)
110 * Return Value: none 110 * Return Value: none
111 * 111 *
112 */ 112 */
113void MACvWriteMultiAddr(PSDevice pDevice, unsigned int uByteIdx, BYTE byData) 113void MACvWriteMultiAddr(struct vnt_private *pDevice, u32 uByteIdx, u8 byData)
114{ 114{
115 BYTE byData1; 115 u8 byData1;
116 116
117 byData1 = byData; 117 byData1 = byData;
118 CONTROLnsRequestOut(pDevice, 118 CONTROLnsRequestOut(pDevice,
@@ -135,7 +135,7 @@ void MACvWriteMultiAddr(PSDevice pDevice, unsigned int uByteIdx, BYTE byData)
135 * 135 *
136 * 136 *
137 */ 137 */
138void MACbShutdown(PSDevice pDevice) 138void MACbShutdown(struct vnt_private *pDevice)
139{ 139{
140 CONTROLnsRequestOutAsyn(pDevice, 140 CONTROLnsRequestOutAsyn(pDevice,
141 MESSAGE_TYPE_MACSHUTDOWN, 141 MESSAGE_TYPE_MACSHUTDOWN,
@@ -146,9 +146,9 @@ void MACbShutdown(PSDevice pDevice)
146 ); 146 );
147} 147}
148 148
149void MACvSetBBType(PSDevice pDevice,BYTE byType) 149void MACvSetBBType(struct vnt_private *pDevice, u8 byType)
150{ 150{
151BYTE pbyData[2]; 151 u8 pbyData[2];
152 152
153 153
154 pbyData[0] = byType; 154 pbyData[0] = byType;
@@ -163,9 +163,9 @@ BYTE pbyData[2];
163 ); 163 );
164} 164}
165 165
166void MACvSetMISCFifo (PSDevice pDevice, WORD wOffset, DWORD dwData) 166void MACvSetMISCFifo(struct vnt_private *pDevice, u16 wOffset, u32 dwData)
167{ 167{
168BYTE pbyData[4]; 168 u8 pbyData[4];
169 169
170 if (wOffset > 273) 170 if (wOffset > 273)
171 return; 171 return;
@@ -197,10 +197,10 @@ BYTE pbyData[4];
197 * Return Value: none 197 * Return Value: none
198 * 198 *
199 */ 199 */
200void MACvDisableKeyEntry(PSDevice pDevice, unsigned int uEntryIdx) 200void MACvDisableKeyEntry(struct vnt_private *pDevice, u32 uEntryIdx)
201{ 201{
202WORD wOffset; 202 u16 wOffset;
203BYTE byData; 203 u8 byData;
204 204
205 205
206 byData = (BYTE) uEntryIdx; 206 byData = (BYTE) uEntryIdx;
@@ -237,20 +237,18 @@ BYTE byData;
237 * Return Value: none 237 * Return Value: none
238 * 238 *
239 */ 239 */
240void MACvSetKeyEntry(PSDevice pDevice, WORD wKeyCtl, 240void MACvSetKeyEntry(struct vnt_private *pDevice, u16 wKeyCtl, u32 uEntryIdx,
241 unsigned int uEntryIdx, unsigned int uKeyIdx, 241 u32 uKeyIdx, u8 *pbyAddr, u32 *pdwKey)
242 PBYTE pbyAddr, PDWORD pdwKey)
243{ 242{
244PBYTE pbyKey; 243 u8 *pbyKey;
245WORD wOffset; 244 u16 wOffset;
246DWORD dwData1,dwData2; 245 u32 dwData1, dwData2;
247int ii; 246 int ii;
248BYTE pbyData[24]; 247 u8 pbyData[24];
249 248
250 if ( pDevice->byLocalID <= MAC_REVISION_A1 ) { 249 if (pDevice->byLocalID <= MAC_REVISION_A1)
251 if ( pDevice->sMgmtObj.byCSSPK == KEY_CTL_CCMP ) 250 if (pDevice->vnt_mgmt.byCSSPK == KEY_CTL_CCMP)
252 return; 251 return;
253 }
254 252
255 wOffset = MISCFIFO_KEYETRY0; 253 wOffset = MISCFIFO_KEYETRY0;
256 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE); 254 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
@@ -321,9 +319,9 @@ BYTE pbyData[24];
321} 319}
322 320
323 321
324void MACvRegBitsOff(PSDevice pDevice, BYTE byRegOfs, BYTE byBits) 322void MACvRegBitsOff(struct vnt_private *pDevice, u8 byRegOfs, u8 byBits)
325{ 323{
326BYTE pbyData[2]; 324 u8 pbyData[2];
327 325
328 pbyData[0] = 0; 326 pbyData[0] = 0;
329 pbyData[1] = byBits; 327 pbyData[1] = byBits;
@@ -338,9 +336,9 @@ BYTE pbyData[2];
338} 336}
339 337
340 338
341void MACvRegBitsOn(PSDevice pDevice, BYTE byRegOfs, BYTE byBits) 339void MACvRegBitsOn(struct vnt_private *pDevice, u8 byRegOfs, u8 byBits)
342{ 340{
343BYTE pbyData[2]; 341 u8 pbyData[2];
344 342
345 343
346 pbyData[0] = byBits; 344 pbyData[0] = byBits;
@@ -355,9 +353,9 @@ BYTE pbyData[2];
355 ); 353 );
356} 354}
357 355
358void MACvWriteWord(PSDevice pDevice, BYTE byRegOfs, WORD wData) 356void MACvWriteWord(struct vnt_private *pDevice, u8 byRegOfs, u16 wData)
359{ 357{
360BYTE pbyData[2]; 358 u8 pbyData[2];
361 359
362 360
363 pbyData[0] = (BYTE)(wData & 0xff); 361 pbyData[0] = (BYTE)(wData & 0xff);
@@ -373,9 +371,9 @@ BYTE pbyData[2];
373 371
374} 372}
375 373
376void MACvWriteBSSIDAddress(PSDevice pDevice, PBYTE pbyEtherAddr) 374void MACvWriteBSSIDAddress(struct vnt_private *pDevice, u8 *pbyEtherAddr)
377{ 375{
378BYTE pbyData[6]; 376 u8 pbyData[6];
379 377
380 378
381 pbyData[0] = *((PBYTE)pbyEtherAddr); 379 pbyData[0] = *((PBYTE)pbyEtherAddr);
@@ -394,9 +392,9 @@ BYTE pbyData[6];
394 ); 392 );
395} 393}
396 394
397void MACvEnableProtectMD(PSDevice pDevice) 395void MACvEnableProtectMD(struct vnt_private *pDevice)
398{ 396{
399BYTE pbyData[2]; 397 u8 pbyData[2];
400 398
401 399
402 pbyData[0] = EnCFG_ProtectMd; 400 pbyData[0] = EnCFG_ProtectMd;
@@ -411,9 +409,9 @@ BYTE pbyData[2];
411 ); 409 );
412} 410}
413 411
414void MACvDisableProtectMD(PSDevice pDevice) 412void MACvDisableProtectMD(struct vnt_private *pDevice)
415{ 413{
416BYTE pbyData[2]; 414 u8 pbyData[2];
417 415
418 416
419 pbyData[0] = 0; 417 pbyData[0] = 0;
@@ -428,9 +426,9 @@ BYTE pbyData[2];
428 ); 426 );
429} 427}
430 428
431void MACvEnableBarkerPreambleMd(PSDevice pDevice) 429void MACvEnableBarkerPreambleMd(struct vnt_private *pDevice)
432{ 430{
433BYTE pbyData[2]; 431 u8 pbyData[2];
434 432
435 433
436 pbyData[0] = EnCFG_BarkerPream; 434 pbyData[0] = EnCFG_BarkerPream;
@@ -445,9 +443,9 @@ BYTE pbyData[2];
445 ); 443 );
446} 444}
447 445
448void MACvDisableBarkerPreambleMd(PSDevice pDevice) 446void MACvDisableBarkerPreambleMd(struct vnt_private *pDevice)
449{ 447{
450BYTE pbyData[2]; 448 u8 pbyData[2];
451 449
452 450
453 pbyData[0] = 0; 451 pbyData[0] = 0;
@@ -463,12 +461,12 @@ BYTE pbyData[2];
463} 461}
464 462
465 463
466void MACvWriteBeaconInterval(PSDevice pDevice, WORD wInterval) 464void MACvWriteBeaconInterval(struct vnt_private *pDevice, u16 wInterval)
467{ 465{
468BYTE pbyData[2]; 466 u8 pbyData[2];
469 467
470 pbyData[0] = (BYTE) (wInterval & 0xff); 468 pbyData[0] = (u8)(wInterval & 0xff);
471 pbyData[1] = (BYTE) (wInterval >> 8); 469 pbyData[1] = (u8)(wInterval >> 8);
472 470
473 CONTROLnsRequestOut(pDevice, 471 CONTROLnsRequestOut(pDevice,
474 MESSAGE_TYPE_WRITE, 472 MESSAGE_TYPE_WRITE,
diff --git a/drivers/staging/vt6656/mac.h b/drivers/staging/vt6656/mac.h
index 147ac50218d3..6e28500ae5f8 100644
--- a/drivers/staging/vt6656/mac.h
+++ b/drivers/staging/vt6656/mac.h
@@ -420,24 +420,21 @@
420 420
421/*--------------------- Export Functions --------------------------*/ 421/*--------------------- Export Functions --------------------------*/
422 422
423void MACvSetMultiAddrByHash(PSDevice pDevice, BYTE byHashIdx); 423void MACvSetMultiAddrByHash(struct vnt_private *, u8);
424void MACvWriteMultiAddr(PSDevice pDevice, unsigned int uByteIdx, BYTE byData); 424void MACvWriteMultiAddr(struct vnt_private *, u32, u8);
425void MACbShutdown(PSDevice pDevice); 425void MACbShutdown(struct vnt_private *);
426void MACvSetBBType(PSDevice pDevice, BYTE byType); 426void MACvSetBBType(struct vnt_private *, u8);
427void MACvSetMISCFifo(PSDevice pDevice, WORD wOffset, DWORD dwData); 427void MACvSetMISCFifo(struct vnt_private *pDevice, u16, u32);
428void MACvDisableKeyEntry(PSDevice pDevice, unsigned int uEntryIdx); 428void MACvDisableKeyEntry(struct vnt_private *, u32);
429void MACvSetKeyEntry(PSDevice pDevice, WORD wKeyCtl, unsigned int uEntryIdx, 429void MACvSetKeyEntry(struct vnt_private *, u16, u32, u32, u8 *, u32 *);
430 unsigned int uKeyIdx, PBYTE pbyAddr, PDWORD pdwKey); 430void MACvRegBitsOff(struct vnt_private *, u8, u8);
431 431void MACvRegBitsOn(struct vnt_private *, u8, u8);
432void MACvRegBitsOff(PSDevice pDevice, BYTE byRegOfs, BYTE byBits); 432void MACvWriteWord(struct vnt_private *, u8, u16);
433void MACvRegBitsOn(PSDevice pDevice, BYTE byRegOfs, BYTE byBits); 433void MACvWriteBSSIDAddress(struct vnt_private *, u8 *);
434void MACvWriteWord(PSDevice pDevice, BYTE byRegOfs, WORD wData); 434void MACvEnableProtectMD(struct vnt_private *);
435 435void MACvDisableProtectMD(struct vnt_private *);
436void MACvWriteBSSIDAddress(PSDevice pDevice, PBYTE pbyEtherAddr); 436void MACvEnableBarkerPreambleMd(struct vnt_private *);
437void MACvEnableProtectMD(PSDevice pDevice); 437void MACvDisableBarkerPreambleMd(struct vnt_private *);
438void MACvDisableProtectMD(PSDevice pDevice); 438void MACvWriteBeaconInterval(struct vnt_private *, u16);
439void MACvEnableBarkerPreambleMd(PSDevice pDevice);
440void MACvDisableBarkerPreambleMd(PSDevice pDevice);
441void MACvWriteBeaconInterval(PSDevice pDevice, WORD wInterval);
442 439
443#endif /* __MAC_H__ */ 440#endif /* __MAC_H__ */
diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index f33086d66496..d5f53e1a74a2 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -73,15 +73,16 @@
73#include "iowpa.h" 73#include "iowpa.h"
74 74
75/*--------------------- Static Definitions -------------------------*/ 75/*--------------------- Static Definitions -------------------------*/
76//static int msglevel =MSG_LEVEL_DEBUG; 76/* static int msglevel = MSG_LEVEL_DEBUG; */
77static int msglevel =MSG_LEVEL_INFO; 77static int msglevel =MSG_LEVEL_INFO;
78 78
79// 79/*
80// Define module options 80 * define module options
81// 81 */
82 82
83// Version Information 83/* version information */
84#define DRIVER_AUTHOR "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>" 84#define DRIVER_AUTHOR \
85 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
85MODULE_AUTHOR(DRIVER_AUTHOR); 86MODULE_AUTHOR(DRIVER_AUTHOR);
86MODULE_LICENSE("GPL"); 87MODULE_LICENSE("GPL");
87MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM); 88MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
@@ -184,16 +185,16 @@ DEVICE_PARAM(BasebandType, "baseband type");
184DEVICE_PARAM(b80211hEnable, "802.11h mode"); 185DEVICE_PARAM(b80211hEnable, "802.11h mode");
185 186
186 187
187// 188/*
188// Static vars definitions 189 * Static vars definitions
189// 190 */
190 191
191static struct usb_device_id vt6656_table[] = { 192static struct usb_device_id vt6656_table[] = {
192 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)}, 193 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
193 {} 194 {}
194}; 195};
195 196
196// Frequency list (map channels to frequencies) 197/* frequency list (map channels to frequencies) */
197/* 198/*
198static const long frequency_list[] = { 199static const long frequency_list[] = {
199 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484, 200 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
@@ -225,26 +226,27 @@ static void device_set_multi(struct net_device *dev);
225static int device_close(struct net_device *dev); 226static int device_close(struct net_device *dev);
226static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 227static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
227 228
228static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType); 229static int device_init_registers(struct vnt_private *pDevice,
229static BOOL device_init_defrag_cb(PSDevice pDevice); 230 DEVICE_INIT_TYPE InitType);
230static void device_init_diversity_timer(PSDevice pDevice); 231static bool device_init_defrag_cb(struct vnt_private *pDevice);
232static void device_init_diversity_timer(struct vnt_private *pDevice);
231static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev); 233static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
232 234
233static int ethtool_ioctl(struct net_device *dev, void *useraddr); 235static int ethtool_ioctl(struct net_device *dev, void *useraddr);
234static void device_free_tx_bufs(PSDevice pDevice); 236static void device_free_tx_bufs(struct vnt_private *pDevice);
235static void device_free_rx_bufs(PSDevice pDevice); 237static void device_free_rx_bufs(struct vnt_private *pDevice);
236static void device_free_int_bufs(PSDevice pDevice); 238static void device_free_int_bufs(struct vnt_private *pDevice);
237static void device_free_frag_bufs(PSDevice pDevice); 239static void device_free_frag_bufs(struct vnt_private *pDevice);
238static BOOL device_alloc_bufs(PSDevice pDevice); 240static bool device_alloc_bufs(struct vnt_private *pDevice);
239 241
240static int Read_config_file(PSDevice pDevice); 242static int Read_config_file(struct vnt_private *pDevice);
241static unsigned char *Config_FileOperation(PSDevice pDevice); 243static unsigned char *Config_FileOperation(struct vnt_private *pDevice);
242static int Config_FileGetParameter(unsigned char *string, 244static int Config_FileGetParameter(unsigned char *string,
243 unsigned char *dest, 245 unsigned char *dest,
244 unsigned char *source); 246 unsigned char *source);
245 247
246 248
247static void usb_device_reset(PSDevice pDevice); 249static void usb_device_reset(struct vnt_private *pDevice);
248 250
249 251
250 252
@@ -254,7 +256,7 @@ static void usb_device_reset(PSDevice pDevice);
254 256
255 257
256static void 258static void
257device_set_options(PSDevice pDevice) { 259device_set_options(struct vnt_private *pDevice) {
258 260
259 BYTE abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 261 BYTE abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
260 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; 262 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
@@ -277,22 +279,22 @@ device_set_options(PSDevice pDevice) {
277 pDevice->b11hEnable = X80211h_MODE_DEF; 279 pDevice->b11hEnable = X80211h_MODE_DEF;
278 pDevice->eOPMode = OP_MODE_DEF; 280 pDevice->eOPMode = OP_MODE_DEF;
279 pDevice->uConnectionRate = DATA_RATE_DEF; 281 pDevice->uConnectionRate = DATA_RATE_DEF;
280 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE; 282 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
281 pDevice->byBBType = BBP_TYPE_DEF; 283 pDevice->byBBType = BBP_TYPE_DEF;
282 pDevice->byPacketType = pDevice->byBBType; 284 pDevice->byPacketType = pDevice->byBBType;
283 pDevice->byAutoFBCtrl = AUTO_FB_0; 285 pDevice->byAutoFBCtrl = AUTO_FB_0;
284 pDevice->bUpdateBBVGA = TRUE; 286 pDevice->bUpdateBBVGA = true;
285 pDevice->byFOETuning = 0; 287 pDevice->byFOETuning = 0;
286 pDevice->byAutoPwrTunning = 0; 288 pDevice->byAutoPwrTunning = 0;
287 pDevice->wCTSDuration = 0; 289 pDevice->wCTSDuration = 0;
288 pDevice->byPreambleType = 0; 290 pDevice->byPreambleType = 0;
289 pDevice->bExistSWNetAddr = FALSE; 291 pDevice->bExistSWNetAddr = false;
290// pDevice->bDiversityRegCtlON = TRUE; 292 /* pDevice->bDiversityRegCtlON = true; */
291 pDevice->bDiversityRegCtlON = FALSE; 293 pDevice->bDiversityRegCtlON = false;
292} 294}
293 295
294 296
295static void device_init_diversity_timer(PSDevice pDevice) 297static void device_init_diversity_timer(struct vnt_private *pDevice)
296{ 298{
297 init_timer(&pDevice->TimerSQ3Tmax1); 299 init_timer(&pDevice->TimerSQ3Tmax1);
298 pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice; 300 pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice;
@@ -313,25 +315,25 @@ static void device_init_diversity_timer(PSDevice pDevice)
313} 315}
314 316
315 317
316// 318/*
317// Initialization of MAC & BBP registers 319 * initialization of MAC & BBP registers
318// 320 */
319 321
320static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType) 322static int device_init_registers(struct vnt_private *pDevice,
323 DEVICE_INIT_TYPE InitType)
321{ 324{
322 u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 325 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
323 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; 326 u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
324 u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; 327 u8 abySNAP_RFC1042[ETH_ALEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
325 BYTE byAntenna; 328 u8 abySNAP_Bridgetunnel[ETH_ALEN]
326 unsigned int ii; 329 = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
327 CMD_CARD_INIT sInitCmd; 330 u8 byAntenna;
328 int ntStatus = STATUS_SUCCESS; 331 int ii;
329 RSP_CARD_INIT sInitRsp; 332 CMD_CARD_INIT sInitCmd;
330 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 333 int ntStatus = STATUS_SUCCESS;
331 BYTE byTmp; 334 RSP_CARD_INIT sInitRsp;
332 BYTE byCalibTXIQ = 0; 335 u8 byTmp;
333 BYTE byCalibTXDC = 0; 336 u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0;
334 BYTE byCalibRXIQ = 0;
335 337
336 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType); 338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType);
337 spin_lock_irq(&pDevice->lock); 339 spin_lock_irq(&pDevice->lock);
@@ -343,24 +345,24 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
343 ETH_ALEN); 345 ETH_ALEN);
344 346
345 if ( !FIRMWAREbCheckVersion(pDevice) ) { 347 if ( !FIRMWAREbCheckVersion(pDevice) ) {
346 if (FIRMWAREbDownload(pDevice) == TRUE) { 348 if (FIRMWAREbDownload(pDevice) == true) {
347 if (FIRMWAREbBrach2Sram(pDevice) == FALSE) { 349 if (FIRMWAREbBrach2Sram(pDevice) == false) {
348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n"); 350 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n");
349 spin_unlock_irq(&pDevice->lock); 351 spin_unlock_irq(&pDevice->lock);
350 return FALSE; 352 return false;
351 } 353 }
352 } else { 354 } else {
353 355
354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n"); 356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n");
355 spin_unlock_irq(&pDevice->lock); 357 spin_unlock_irq(&pDevice->lock);
356 return FALSE; 358 return false;
357 } 359 }
358 } 360 }
359 361
360 if ( !BBbVT3184Init(pDevice) ) { 362 if ( !BBbVT3184Init(pDevice) ) {
361 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n"); 363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n");
362 spin_unlock_irq(&pDevice->lock); 364 spin_unlock_irq(&pDevice->lock);
363 return FALSE; 365 return false;
364 } 366 }
365 } 367 }
366 368
@@ -371,7 +373,7 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
371 sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit; 373 sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;
372 sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit; 374 sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit;
373 375
374 //issue Card_init command to device 376 /* issue card_init command to device */
375 ntStatus = CONTROLnsRequestOut(pDevice, 377 ntStatus = CONTROLnsRequestOut(pDevice,
376 MESSAGE_TYPE_CARDINIT, 378 MESSAGE_TYPE_CARDINIT,
377 0, 379 0,
@@ -382,7 +384,7 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
382 if ( ntStatus != STATUS_SUCCESS ) { 384 if ( ntStatus != STATUS_SUCCESS ) {
383 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n"); 385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n");
384 spin_unlock_irq(&pDevice->lock); 386 spin_unlock_irq(&pDevice->lock);
385 return FALSE; 387 return false;
386 } 388 }
387 if (InitType == DEVICE_INIT_COLD) { 389 if (InitType == DEVICE_INIT_COLD) {
388 390
@@ -391,10 +393,10 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
391 if (ntStatus != STATUS_SUCCESS) { 393 if (ntStatus != STATUS_SUCCESS) {
392 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n"); 394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n");
393 spin_unlock_irq(&pDevice->lock); 395 spin_unlock_irq(&pDevice->lock);
394 return FALSE; 396 return false;
395 } 397 }
396 398
397 //Local ID for AES functions 399 /* local ID for AES functions */
398 ntStatus = CONTROLnsRequestIn(pDevice, 400 ntStatus = CONTROLnsRequestIn(pDevice,
399 MESSAGE_TYPE_READ, 401 MESSAGE_TYPE_READ,
400 MAC_REG_LOCALID, 402 MAC_REG_LOCALID,
@@ -404,15 +406,17 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
404 406
405 if ( ntStatus != STATUS_SUCCESS ) { 407 if ( ntStatus != STATUS_SUCCESS ) {
406 spin_unlock_irq(&pDevice->lock); 408 spin_unlock_irq(&pDevice->lock);
407 return FALSE; 409 return false;
408 } 410 }
409 411
410 // Do MACbSoftwareReset in MACvInitialize 412 /* do MACbSoftwareReset in MACvInitialize */
411 // force CCK 413
412 pDevice->bCCK = TRUE; 414 /* force CCK */
413 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE 415 pDevice->bCCK = true;
414 pDevice->bNonERPPresent = FALSE; 416 pDevice->bProtectMode = false;
415 pDevice->bBarkerPreambleMd = FALSE; 417 /* only used in 11g type, sync with ERP IE */
418 pDevice->bNonERPPresent = false;
419 pDevice->bBarkerPreambleMd = false;
416 if ( pDevice->bFixRate ) { 420 if ( pDevice->bFixRate ) {
417 pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate; 421 pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate;
418 } else { 422 } else {
@@ -426,13 +430,14 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
426 430
427 pDevice->byTopOFDMBasicRate = RATE_24M; 431 pDevice->byTopOFDMBasicRate = RATE_24M;
428 pDevice->byTopCCKBasicRate = RATE_1M; 432 pDevice->byTopCCKBasicRate = RATE_1M;
429 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip. 433 pDevice->byRevId = 0;
434 /* target to IF pin while programming to RF chip */
430 pDevice->byCurPwr = 0xFF; 435 pDevice->byCurPwr = 0xFF;
431 436
432 pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK]; 437 pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];
433 pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG]; 438 pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];
434 // Load power Table 439 /* load power table */
435 for (ii=0;ii<14;ii++) { 440 for (ii = 0; ii < 14; ii++) {
436 pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL]; 441 pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL];
437 if (pDevice->abyCCKPwrTbl[ii] == 0) 442 if (pDevice->abyCCKPwrTbl[ii] == 0)
438 pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr; 443 pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr;
@@ -441,8 +446,10 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
441 pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG; 446 pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;
442 } 447 }
443 448
444 //original zonetype is USA,but customize zonetype is europe, 449 /*
445 // then need recover 12,13 ,14 channel with 11 channel 450 * original zonetype is USA, but custom zonetype is Europe,
451 * then need to recover 12, 13, 14 channels with 11 channel
452 */
446 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) || 453 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
447 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&& 454 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
448 (pDevice->byOriginalZonetype == ZoneType_USA)) { 455 (pDevice->byOriginalZonetype == ZoneType_USA)) {
@@ -452,25 +459,24 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
452 } 459 }
453 } 460 }
454 461
455 //{{ RobertYu: 20041124 462 pDevice->byOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */
456 pDevice->byOFDMPwrA = 0x34; // same as RFbMA2829SelectChannel 463
457 // Load OFDM A Power Table 464 /* load OFDM A power table */
458 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL 465 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
459 pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL]; 466 pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL];
460 if (pDevice->abyOFDMAPwrTbl[ii] == 0) 467 if (pDevice->abyOFDMAPwrTbl[ii] == 0)
461 pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA; 468 pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;
462 } 469 }
463 //}} RobertYu
464 470
465 byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA]; 471 byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
466 if (byAntenna & EEP_ANTINV) 472 if (byAntenna & EEP_ANTINV)
467 pDevice->bTxRxAntInv = TRUE; 473 pDevice->bTxRxAntInv = true;
468 else 474 else
469 pDevice->bTxRxAntInv = FALSE; 475 pDevice->bTxRxAntInv = false;
470 476
471 byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); 477 byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
472 478
473 if (byAntenna == 0) // if not set default is All 479 if (byAntenna == 0) /* if not set default is both */
474 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN); 480 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
475 481
476 if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) { 482 if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
@@ -478,29 +484,29 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
478 pDevice->byTxAntennaMode = ANT_B; 484 pDevice->byTxAntennaMode = ANT_B;
479 pDevice->dwTxAntennaSel = 1; 485 pDevice->dwTxAntennaSel = 1;
480 pDevice->dwRxAntennaSel = 1; 486 pDevice->dwRxAntennaSel = 1;
481 if (pDevice->bTxRxAntInv == TRUE) 487 if (pDevice->bTxRxAntInv == true)
482 pDevice->byRxAntennaMode = ANT_A; 488 pDevice->byRxAntennaMode = ANT_A;
483 else 489 else
484 pDevice->byRxAntennaMode = ANT_B; 490 pDevice->byRxAntennaMode = ANT_B;
485 491
486 if (pDevice->bDiversityRegCtlON) 492 if (pDevice->bDiversityRegCtlON)
487 pDevice->bDiversityEnable = TRUE; 493 pDevice->bDiversityEnable = true;
488 else 494 else
489 pDevice->bDiversityEnable = FALSE; 495 pDevice->bDiversityEnable = false;
490 } else { 496 } else {
491 pDevice->bDiversityEnable = FALSE; 497 pDevice->bDiversityEnable = false;
492 pDevice->byAntennaCount = 1; 498 pDevice->byAntennaCount = 1;
493 pDevice->dwTxAntennaSel = 0; 499 pDevice->dwTxAntennaSel = 0;
494 pDevice->dwRxAntennaSel = 0; 500 pDevice->dwRxAntennaSel = 0;
495 if (byAntenna & EEP_ANTENNA_AUX) { 501 if (byAntenna & EEP_ANTENNA_AUX) {
496 pDevice->byTxAntennaMode = ANT_A; 502 pDevice->byTxAntennaMode = ANT_A;
497 if (pDevice->bTxRxAntInv == TRUE) 503 if (pDevice->bTxRxAntInv == true)
498 pDevice->byRxAntennaMode = ANT_B; 504 pDevice->byRxAntennaMode = ANT_B;
499 else 505 else
500 pDevice->byRxAntennaMode = ANT_A; 506 pDevice->byRxAntennaMode = ANT_A;
501 } else { 507 } else {
502 pDevice->byTxAntennaMode = ANT_B; 508 pDevice->byTxAntennaMode = ANT_B;
503 if (pDevice->bTxRxAntInv == TRUE) 509 if (pDevice->bTxRxAntInv == true)
504 pDevice->byRxAntennaMode = ANT_A; 510 pDevice->byRxAntennaMode = ANT_A;
505 else 511 else
506 pDevice->byRxAntennaMode = ANT_B; 512 pDevice->byRxAntennaMode = ANT_B;
@@ -512,35 +518,34 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
512 pDevice->byTMax2 = 4; 518 pDevice->byTMax2 = 4;
513 pDevice->ulSQ3TH = 0; 519 pDevice->ulSQ3TH = 0;
514 pDevice->byTMax3 = 64; 520 pDevice->byTMax3 = 64;
515 // -----------------------------------------------------------------
516 521
517 //Get Auto Fall Back Type 522 /* get Auto Fall Back type */
518 pDevice->byAutoFBCtrl = AUTO_FB_0; 523 pDevice->byAutoFBCtrl = AUTO_FB_0;
519 524
520 // Set SCAN Time 525 /* set SCAN Time */
521 pDevice->uScanTime = WLAN_SCAN_MINITIME; 526 pDevice->uScanTime = WLAN_SCAN_MINITIME;
522 527
523 // default Auto Mode 528 /* default Auto Mode */
524 //pDevice->NetworkType = Ndis802_11Automode; 529 /* pDevice->NetworkType = Ndis802_11Automode; */
525 pDevice->eConfigPHYMode = PHY_TYPE_AUTO; 530 pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
526 pDevice->byBBType = BB_TYPE_11G; 531 pDevice->byBBType = BB_TYPE_11G;
527 532
528 // initialize BBP registers 533 /* initialize BBP registers */
529 pDevice->ulTxPower = 25; 534 pDevice->ulTxPower = 25;
530 535
531 // Get Channel range 536 /* get channel range */
532 pDevice->byMinChannel = 1; 537 pDevice->byMinChannel = 1;
533 pDevice->byMaxChannel = CB_MAX_CHANNEL; 538 pDevice->byMaxChannel = CB_MAX_CHANNEL;
534 539
535 // Get RFType 540 /* get RFType */
536 pDevice->byRFType = sInitRsp.byRFType; 541 pDevice->byRFType = sInitRsp.byRFType;
537 542
538 if ((pDevice->byRFType & RF_EMU) != 0) { 543 if ((pDevice->byRFType & RF_EMU) != 0) {
539 // force change RevID for VT3253 emu 544 /* force change RevID for VT3253 emu */
540 pDevice->byRevId = 0x80; 545 pDevice->byRevId = 0x80;
541 } 546 }
542 547
543 // Load EEPROM calibrated vt3266 parameters 548 /* load vt3266 calibration parameters in EEPROM */
544 if (pDevice->byRFType == RF_VT3226D0) { 549 if (pDevice->byRFType == RF_VT3226D0) {
545 if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) && 550 if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&
546 (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) { 551 (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
@@ -548,13 +553,32 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
548 byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC]; 553 byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];
549 byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ]; 554 byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];
550 if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) { 555 if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) {
551 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x03); // CR255, Set BB to support TX/RX IQ and DC compensation Mode 556 /* CR255, enable TX/RX IQ and DC compensation mode */
552 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFB, byCalibTXIQ); // CR251, TX I/Q Imbalance Calibration 557 ControlvWriteByte(pDevice,
553 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFC, byCalibTXDC); // CR252, TX DC-Offset Calibration 558 MESSAGE_REQUEST_BBREG,
554 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFD, byCalibRXIQ); // CR253, RX I/Q Imbalance Calibration 559 0xFF,
560 0x03);
561 /* CR251, TX I/Q Imbalance Calibration */
562 ControlvWriteByte(pDevice,
563 MESSAGE_REQUEST_BBREG,
564 0xFB,
565 byCalibTXIQ);
566 /* CR252, TX DC-Offset Calibration */
567 ControlvWriteByte(pDevice,
568 MESSAGE_REQUEST_BBREG,
569 0xFC,
570 byCalibTXDC);
571 /* CR253, RX I/Q Imbalance Calibration */
572 ControlvWriteByte(pDevice,
573 MESSAGE_REQUEST_BBREG,
574 0xFD,
575 byCalibRXIQ);
555 } else { 576 } else {
556 // turn off BB Calibration compensation 577 /* CR255, turn off BB Calibration compensation */
557 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x0); // CR255 578 ControlvWriteByte(pDevice,
579 MESSAGE_REQUEST_BBREG,
580 0xFF,
581 0x0);
558 } 582 }
559 } 583 }
560 } 584 }
@@ -563,26 +587,27 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
563 pMgmt->uIBSSChannel = pDevice->uChannel; 587 pMgmt->uIBSSChannel = pDevice->uChannel;
564 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel); 588 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
565 589
566 // get Permanent network address 590 /* get permanent network address */
567 memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6); 591 memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6);
568 memcpy(pDevice->abyCurrentNetAddr, 592 memcpy(pDevice->abyCurrentNetAddr,
569 pDevice->abyPermanentNetAddr, 593 pDevice->abyPermanentNetAddr,
570 ETH_ALEN); 594 ETH_ALEN);
571 595
572 // if exist SW network address, use SW network address. 596 /* if exist SW network address, use it */
573
574 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n", 597 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
575 pDevice->abyCurrentNetAddr); 598 pDevice->abyCurrentNetAddr);
576 } 599 }
577 600
578 // Set BB and packet type at the same time. 601 /*
579 // Set Short Slot Time, xIFS, and RSPINF. 602 * set BB and packet type at the same time
603 * set Short Slot Time, xIFS, and RSPINF
604 */
580 if (pDevice->byBBType == BB_TYPE_11A) { 605 if (pDevice->byBBType == BB_TYPE_11A) {
581 CARDbAddBasicRate(pDevice, RATE_6M); 606 CARDbAddBasicRate(pDevice, RATE_6M);
582 pDevice->bShortSlotTime = TRUE; 607 pDevice->bShortSlotTime = true;
583 } else { 608 } else {
584 CARDbAddBasicRate(pDevice, RATE_1M); 609 CARDbAddBasicRate(pDevice, RATE_1M);
585 pDevice->bShortSlotTime = FALSE; 610 pDevice->bShortSlotTime = false;
586 } 611 }
587 BBvSetShortSlotTime(pDevice); 612 BBvSetShortSlotTime(pDevice);
588 CARDvSetBSSMode(pDevice); 613 CARDvSetBSSMode(pDevice);
@@ -594,7 +619,7 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
594 } 619 }
595 620
596 pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL]; 621 pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];
597 pDevice->bHWRadioOff = FALSE; 622 pDevice->bHWRadioOff = false;
598 if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) { 623 if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) {
599 ntStatus = CONTROLnsRequestIn(pDevice, 624 ntStatus = CONTROLnsRequestIn(pDevice,
600 MESSAGE_TYPE_READ, 625 MESSAGE_TYPE_READ,
@@ -605,23 +630,23 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
605 630
606 if ( ntStatus != STATUS_SUCCESS ) { 631 if ( ntStatus != STATUS_SUCCESS ) {
607 spin_unlock_irq(&pDevice->lock); 632 spin_unlock_irq(&pDevice->lock);
608 return FALSE; 633 return false;
609 } 634 }
610 if ( (byTmp & GPIO3_DATA) == 0 ) { 635 if ( (byTmp & GPIO3_DATA) == 0 ) {
611 pDevice->bHWRadioOff = TRUE; 636 pDevice->bHWRadioOff = true;
612 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); 637 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
613 } else { 638 } else {
614 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); 639 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
615 pDevice->bHWRadioOff = FALSE; 640 pDevice->bHWRadioOff = false;
616 } 641 }
617 642
618 } //EEP_RADIOCTL_ENABLE 643 }
619 644
620 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38); 645 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38);
621 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 646 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
622 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01); 647 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01);
623 648
624 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) { 649 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
625 CARDbRadioPowerOff(pDevice); 650 CARDbRadioPowerOff(pDevice);
626 } else { 651 } else {
627 CARDbRadioPowerOn(pDevice); 652 CARDbRadioPowerOn(pDevice);
@@ -629,14 +654,14 @@ static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
629 654
630 spin_unlock_irq(&pDevice->lock); 655 spin_unlock_irq(&pDevice->lock);
631 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n"); 656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");
632 return TRUE; 657 return true;
633} 658}
634 659
635#ifdef CONFIG_PM /* Minimal support for suspend and resume */ 660#ifdef CONFIG_PM /* Minimal support for suspend and resume */
636 661
637static int vt6656_suspend(struct usb_interface *intf, pm_message_t message) 662static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
638{ 663{
639 PSDevice device = usb_get_intfdata(intf); 664 struct vnt_private *device = usb_get_intfdata(intf);
640 665
641 if (!device || !device->dev) 666 if (!device || !device->dev)
642 return -ENODEV; 667 return -ENODEV;
@@ -651,7 +676,7 @@ static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
651 676
652static int vt6656_resume(struct usb_interface *intf) 677static int vt6656_resume(struct usb_interface *intf)
653{ 678{
654 PSDevice device = usb_get_intfdata(intf); 679 struct vnt_private *device = usb_get_intfdata(intf);
655 680
656 if (!device || !device->dev) 681 if (!device || !device->dev)
657 return -ENODEV; 682 return -ENODEV;
@@ -682,13 +707,13 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
682 struct usb_device *udev = interface_to_usbdev(intf); 707 struct usb_device *udev = interface_to_usbdev(intf);
683 int rc = 0; 708 int rc = 0;
684 struct net_device *netdev = NULL; 709 struct net_device *netdev = NULL;
685 PSDevice pDevice = NULL; 710 struct vnt_private *pDevice;
686 711
687 printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION); 712 printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
688 printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n"); 713 printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
689 714
690 udev = usb_get_dev(udev); 715 udev = usb_get_dev(udev);
691 netdev = alloc_etherdev(sizeof(DEVICE_INFO)); 716 netdev = alloc_etherdev(sizeof(struct vnt_private));
692 if (!netdev) { 717 if (!netdev) {
693 printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n"); 718 printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
694 rc = -ENOMEM; 719 rc = -ENOMEM;
@@ -696,7 +721,7 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
696 } 721 }
697 722
698 pDevice = netdev_priv(netdev); 723 pDevice = netdev_priv(netdev);
699 memset(pDevice, 0, sizeof(DEVICE_INFO)); 724 memset(pDevice, 0, sizeof(struct vnt_private));
700 725
701 pDevice->dev = netdev; 726 pDevice->dev = netdev;
702 pDevice->usb = udev; 727 pDevice->usb = udev;
@@ -705,7 +730,7 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
705 spin_lock_init(&pDevice->lock); 730 spin_lock_init(&pDevice->lock);
706 731
707 pDevice->tx_80211 = device_dma0_tx_80211; 732 pDevice->tx_80211 = device_dma0_tx_80211;
708 pDevice->sMgmtObj.pAdapter = (void *) pDevice; 733 pDevice->vnt_mgmt.pAdapter = (void *) pDevice;
709 734
710 netdev->netdev_ops = &device_netdev_ops; 735 netdev->netdev_ops = &device_netdev_ops;
711 netdev->wireless_handlers = 736 netdev->wireless_handlers =
@@ -732,7 +757,7 @@ err_nomem:
732 return rc; 757 return rc;
733} 758}
734 759
735static void device_free_tx_bufs(PSDevice pDevice) 760static void device_free_tx_bufs(struct vnt_private *pDevice)
736{ 761{
737 PUSB_SEND_CONTEXT pTxContext; 762 PUSB_SEND_CONTEXT pTxContext;
738 int ii; 763 int ii;
@@ -740,7 +765,7 @@ static void device_free_tx_bufs(PSDevice pDevice)
740 for (ii = 0; ii < pDevice->cbTD; ii++) { 765 for (ii = 0; ii < pDevice->cbTD; ii++) {
741 766
742 pTxContext = pDevice->apTD[ii]; 767 pTxContext = pDevice->apTD[ii];
743 //de-allocate URBs 768 /* deallocate URBs */
744 if (pTxContext->pUrb) { 769 if (pTxContext->pUrb) {
745 usb_kill_urb(pTxContext->pUrb); 770 usb_kill_urb(pTxContext->pUrb);
746 usb_free_urb(pTxContext->pUrb); 771 usb_free_urb(pTxContext->pUrb);
@@ -751,7 +776,7 @@ static void device_free_tx_bufs(PSDevice pDevice)
751} 776}
752 777
753 778
754static void device_free_rx_bufs(PSDevice pDevice) 779static void device_free_rx_bufs(struct vnt_private *pDevice)
755{ 780{
756 PRCB pRCB; 781 PRCB pRCB;
757 int ii; 782 int ii;
@@ -759,12 +784,12 @@ static void device_free_rx_bufs(PSDevice pDevice)
759 for (ii = 0; ii < pDevice->cbRD; ii++) { 784 for (ii = 0; ii < pDevice->cbRD; ii++) {
760 785
761 pRCB = pDevice->apRCB[ii]; 786 pRCB = pDevice->apRCB[ii];
762 //de-allocate URBs 787 /* deallocate URBs */
763 if (pRCB->pUrb) { 788 if (pRCB->pUrb) {
764 usb_kill_urb(pRCB->pUrb); 789 usb_kill_urb(pRCB->pUrb);
765 usb_free_urb(pRCB->pUrb); 790 usb_free_urb(pRCB->pUrb);
766 } 791 }
767 //de-allocate skb 792 /* deallocate skb */
768 if (pRCB->skb) 793 if (pRCB->skb)
769 dev_kfree_skb(pRCB->skb); 794 dev_kfree_skb(pRCB->skb);
770 } 795 }
@@ -773,7 +798,7 @@ static void device_free_rx_bufs(PSDevice pDevice)
773 return; 798 return;
774} 799}
775 800
776static void usb_device_reset(PSDevice pDevice) 801static void usb_device_reset(struct vnt_private *pDevice)
777{ 802{
778 int status; 803 int status;
779 status = usb_reset_device(pDevice->usb); 804 status = usb_reset_device(pDevice->usb);
@@ -782,14 +807,15 @@ static void usb_device_reset(PSDevice pDevice)
782 return ; 807 return ;
783} 808}
784 809
785static void device_free_int_bufs(PSDevice pDevice) 810static void device_free_int_bufs(struct vnt_private *pDevice)
786{ 811{
787 kfree(pDevice->intBuf.pDataBuf); 812 kfree(pDevice->intBuf.pDataBuf);
788 return; 813 return;
789} 814}
790 815
791 816
792static BOOL device_alloc_bufs(PSDevice pDevice) { 817static bool device_alloc_bufs(struct vnt_private *pDevice)
818{
793 819
794 PUSB_SEND_CONTEXT pTxContext; 820 PUSB_SEND_CONTEXT pTxContext;
795 PRCB pRCB; 821 PRCB pRCB;
@@ -805,16 +831,16 @@ static BOOL device_alloc_bufs(PSDevice pDevice) {
805 } 831 }
806 pDevice->apTD[ii] = pTxContext; 832 pDevice->apTD[ii] = pTxContext;
807 pTxContext->pDevice = (void *) pDevice; 833 pTxContext->pDevice = (void *) pDevice;
808 //allocate URBs 834 /* allocate URBs */
809 pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC); 835 pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
810 if (pTxContext->pUrb == NULL) { 836 if (pTxContext->pUrb == NULL) {
811 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n"); 837 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n");
812 goto free_tx; 838 goto free_tx;
813 } 839 }
814 pTxContext->bBoolInUse = FALSE; 840 pTxContext->bBoolInUse = false;
815 } 841 }
816 842
817 // allocate rcb mem 843 /* allocate RCB mem */
818 pDevice->pRCBMem = kzalloc((sizeof(RCB) * pDevice->cbRD), GFP_KERNEL); 844 pDevice->pRCBMem = kzalloc((sizeof(RCB) * pDevice->cbRD), GFP_KERNEL);
819 if (pDevice->pRCBMem == NULL) { 845 if (pDevice->pRCBMem == NULL) {
820 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name); 846 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name);
@@ -833,7 +859,7 @@ static BOOL device_alloc_bufs(PSDevice pDevice) {
833 859
834 pDevice->apRCB[ii] = pRCB; 860 pDevice->apRCB[ii] = pRCB;
835 pRCB->pDevice = (void *) pDevice; 861 pRCB->pDevice = (void *) pDevice;
836 //allocate URBs 862 /* allocate URBs */
837 pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC); 863 pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
838 864
839 if (pRCB->pUrb == NULL) { 865 if (pRCB->pUrb == NULL) {
@@ -846,7 +872,7 @@ static BOOL device_alloc_bufs(PSDevice pDevice) {
846 goto free_rx_tx; 872 goto free_rx_tx;
847 } 873 }
848 pRCB->skb->dev = pDevice->dev; 874 pRCB->skb->dev = pDevice->dev;
849 pRCB->bBoolInUse = FALSE; 875 pRCB->bBoolInUse = false;
850 EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB); 876 EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
851 pDevice->NumRecvFreeList++; 877 pDevice->NumRecvFreeList++;
852 pRCB++; 878 pRCB++;
@@ -874,7 +900,7 @@ static BOOL device_alloc_bufs(PSDevice pDevice) {
874 goto free_rx_tx; 900 goto free_rx_tx;
875 } 901 }
876 902
877 return TRUE; 903 return true;
878 904
879free_rx_tx: 905free_rx_tx:
880 device_free_rx_bufs(pDevice); 906 device_free_rx_bufs(pDevice);
@@ -882,15 +908,16 @@ free_rx_tx:
882free_tx: 908free_tx:
883 device_free_tx_bufs(pDevice); 909 device_free_tx_bufs(pDevice);
884 910
885 return FALSE; 911 return false;
886} 912}
887 913
888 914
889 915
890 916
891static BOOL device_init_defrag_cb(PSDevice pDevice) { 917static bool device_init_defrag_cb(struct vnt_private *pDevice)
892 int i; 918{
893 PSDeFragControlBlock pDeF; 919 int i;
920 PSDeFragControlBlock pDeF;
894 921
895 /* Init the fragment ctl entries */ 922 /* Init the fragment ctl entries */
896 for (i = 0; i < CB_MAX_RX_FRAG; i++) { 923 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
@@ -903,18 +930,19 @@ static BOOL device_init_defrag_cb(PSDevice pDevice) {
903 } 930 }
904 pDevice->cbDFCB = CB_MAX_RX_FRAG; 931 pDevice->cbDFCB = CB_MAX_RX_FRAG;
905 pDevice->cbFreeDFCB = pDevice->cbDFCB; 932 pDevice->cbFreeDFCB = pDevice->cbDFCB;
906 return TRUE; 933 return true;
907 934
908free_frag: 935free_frag:
909 device_free_frag_bufs(pDevice); 936 device_free_frag_bufs(pDevice);
910 return FALSE; 937 return false;
911} 938}
912 939
913 940
914 941
915static void device_free_frag_bufs(PSDevice pDevice) { 942static void device_free_frag_bufs(struct vnt_private *pDevice)
916 PSDeFragControlBlock pDeF; 943{
917 int i; 944 PSDeFragControlBlock pDeF;
945 int i;
918 946
919 for (i = 0; i < CB_MAX_RX_FRAG; i++) { 947 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
920 948
@@ -927,36 +955,39 @@ static void device_free_frag_bufs(PSDevice pDevice) {
927 955
928 956
929 957
930BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) { 958int device_alloc_frag_buf(struct vnt_private *pDevice,
959 PSDeFragControlBlock pDeF)
960{
931 961
932 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); 962 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
933 if (pDeF->skb == NULL) 963 if (pDeF->skb == NULL)
934 return FALSE; 964 return false;
935 ASSERT(pDeF->skb); 965 ASSERT(pDeF->skb);
936 pDeF->skb->dev = pDevice->dev; 966 pDeF->skb->dev = pDevice->dev;
937 967
938 return TRUE; 968 return true;
939} 969}
940 970
941 971
942/*-----------------------------------------------------------------*/ 972/*-----------------------------------------------------------------*/
943 973
944static int device_open(struct net_device *dev) { 974static int device_open(struct net_device *dev)
945 PSDevice pDevice=(PSDevice) netdev_priv(dev); 975{
976 struct vnt_private *pDevice = netdev_priv(dev);
946 977
947 pDevice->fWPA_Authened = FALSE; 978 pDevice->fWPA_Authened = false;
948 979
949 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n"); 980 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
950 981
951 982
952 pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS; 983 pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
953 984
954 if (device_alloc_bufs(pDevice) == FALSE) { 985 if (device_alloc_bufs(pDevice) == false) {
955 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n"); 986 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
956 return -ENOMEM; 987 return -ENOMEM;
957 } 988 }
958 989
959 if (device_init_defrag_cb(pDevice)== FALSE) { 990 if (device_init_defrag_cb(pDevice)== false) {
960 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n"); 991 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
961 goto free_rx_tx; 992 goto free_rx_tx;
962 } 993 }
@@ -967,25 +998,26 @@ static int device_open(struct net_device *dev) {
967 MP_SET_FLAG(pDevice, fMP_POST_READS); 998 MP_SET_FLAG(pDevice, fMP_POST_READS);
968 MP_SET_FLAG(pDevice, fMP_POST_WRITES); 999 MP_SET_FLAG(pDevice, fMP_POST_WRITES);
969 1000
970 //read config file 1001 /* read config file */
971 Read_config_file(pDevice); 1002 Read_config_file(pDevice);
972 1003
973 if (device_init_registers(pDevice, DEVICE_INIT_COLD) == FALSE) { 1004 if (device_init_registers(pDevice, DEVICE_INIT_COLD) == false) {
974 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n"); 1005 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
975 goto free_all; 1006 goto free_all;
976 } 1007 }
977 1008
978 device_set_multi(pDevice->dev); 1009 device_set_multi(pDevice->dev);
979 // Init for Key Management
980 1010
1011 /* init for key management */
981 KeyvInitTable(pDevice,&pDevice->sKey); 1012 KeyvInitTable(pDevice,&pDevice->sKey);
982 memcpy(pDevice->sMgmtObj.abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN); 1013 memcpy(pDevice->vnt_mgmt.abyMACAddr,
1014 pDevice->abyCurrentNetAddr, ETH_ALEN);
983 memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN); 1015 memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
984 pDevice->bStopTx0Pkt = FALSE; 1016 pDevice->bStopTx0Pkt = false;
985 pDevice->bStopDataPkt = FALSE; 1017 pDevice->bStopDataPkt = false;
986 pDevice->bRoaming = FALSE; 1018 pDevice->bRoaming = false;
987 pDevice->bIsRoaming = FALSE; 1019 pDevice->bIsRoaming = false;
988 pDevice->bEnableRoaming = FALSE; 1020 pDevice->bEnableRoaming = false;
989 if (pDevice->bDiversityRegCtlON) { 1021 if (pDevice->bDiversityRegCtlON) {
990 device_init_diversity_timer(pDevice); 1022 device_init_diversity_timer(pDevice);
991 } 1023 }
@@ -994,27 +1026,27 @@ static int device_open(struct net_device *dev) {
994 tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice); 1026 tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice);
995 tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice); 1027 tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice);
996 tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice); 1028 tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice);
997 add_timer(&(pDevice->sMgmtObj.sTimerSecondCallback)); 1029 add_timer(&pDevice->vnt_mgmt.sTimerSecondCallback);
998 pDevice->int_interval = 100; //Max 100 microframes. 1030 pDevice->int_interval = 100; /* max 100 microframes */
999 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; 1031 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1000 1032
1001 pDevice->bIsRxWorkItemQueued = TRUE; 1033 pDevice->bIsRxWorkItemQueued = true;
1002 pDevice->fKillEventPollingThread = FALSE; 1034 pDevice->fKillEventPollingThread = false;
1003 pDevice->bEventAvailable = FALSE; 1035 pDevice->bEventAvailable = false;
1004 1036
1005 pDevice->bWPADEVUp = FALSE; 1037 pDevice->bWPADEVUp = false;
1006 pDevice->bwextstep0 = FALSE; 1038 pDevice->bwextstep0 = false;
1007 pDevice->bwextstep1 = FALSE; 1039 pDevice->bwextstep1 = false;
1008 pDevice->bwextstep2 = FALSE; 1040 pDevice->bwextstep2 = false;
1009 pDevice->bwextstep3 = FALSE; 1041 pDevice->bwextstep3 = false;
1010 pDevice->bWPASuppWextEnabled = FALSE; 1042 pDevice->bWPASuppWextEnabled = false;
1011 pDevice->byReAssocCount = 0; 1043 pDevice->byReAssocCount = 0;
1012 1044
1013 RXvWorkItem(pDevice); 1045 RXvWorkItem(pDevice);
1014 INTvWorkItem(pDevice); 1046 INTvWorkItem(pDevice);
1015 1047
1016 // Patch: if WEP key already set by iwconfig but device not yet open 1048 /* if WEP key already set by iwconfig but device not yet open */
1017 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) { 1049 if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
1018 spin_lock_irq(&pDevice->lock); 1050 spin_lock_irq(&pDevice->lock);
1019 KeybSetDefaultKey( pDevice, 1051 KeybSetDefaultKey( pDevice,
1020 &(pDevice->sKey), 1052 &(pDevice->sKey),
@@ -1028,14 +1060,10 @@ static int device_open(struct net_device *dev) {
1028 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; 1060 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1029 } 1061 }
1030 1062
1031 if (pDevice->sMgmtObj.eConfigMode == WMAC_CONFIG_AP) { 1063 if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP)
1032 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL); 1064 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
1033 } 1065 else
1034 else { 1066 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1035 //mike:mark@2008-11-10
1036 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1037 /* bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL); */
1038 }
1039 1067
1040 1068
1041 netif_stop_queue(pDevice->dev); 1069 netif_stop_queue(pDevice->dev);
@@ -1061,13 +1089,13 @@ free_rx_tx:
1061 1089
1062 1090
1063 1091
1064static int device_close(struct net_device *dev) { 1092static int device_close(struct net_device *dev)
1065 PSDevice pDevice=(PSDevice) netdev_priv(dev); 1093{
1066 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1094 struct vnt_private *pDevice = netdev_priv(dev);
1067 1095 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1068 int uu; 1096 int uu;
1069 1097
1070 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1 \n"); 1098 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n");
1071 if (pDevice == NULL) 1099 if (pDevice == NULL)
1072 return -ENODEV; 1100 return -ENODEV;
1073 1101
@@ -1078,22 +1106,22 @@ static int device_close(struct net_device *dev) {
1078 1106
1079 1107
1080 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); 1108 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1081 pMgmt->bShareKeyAlgorithm = FALSE; 1109 pMgmt->bShareKeyAlgorithm = false;
1082 pDevice->bEncryptionEnable = FALSE; 1110 pDevice->bEncryptionEnable = false;
1083 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; 1111 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1084 spin_lock_irq(&pDevice->lock); 1112 spin_lock_irq(&pDevice->lock);
1085 for (uu = 0; uu < MAX_KEY_TABLE; uu++) 1113 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1086 MACvDisableKeyEntry(pDevice,uu); 1114 MACvDisableKeyEntry(pDevice,uu);
1087 spin_unlock_irq(&pDevice->lock); 1115 spin_unlock_irq(&pDevice->lock);
1088 1116
1089 if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == FALSE) { 1117 if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) {
1090 MACbShutdown(pDevice); 1118 MACbShutdown(pDevice);
1091 } 1119 }
1092 netif_stop_queue(pDevice->dev); 1120 netif_stop_queue(pDevice->dev);
1093 MP_SET_FLAG(pDevice, fMP_DISCONNECTED); 1121 MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
1094 MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES); 1122 MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
1095 MP_CLEAR_FLAG(pDevice, fMP_POST_READS); 1123 MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
1096 pDevice->fKillEventPollingThread = TRUE; 1124 pDevice->fKillEventPollingThread = true;
1097 del_timer(&pDevice->sTimerCommand); 1125 del_timer(&pDevice->sTimerCommand);
1098 del_timer(&pMgmt->sTimerSecondCallback); 1126 del_timer(&pMgmt->sTimerSecondCallback);
1099 1127
@@ -1108,11 +1136,11 @@ static int device_close(struct net_device *dev) {
1108 tasklet_kill(&pDevice->ReadWorkItem); 1136 tasklet_kill(&pDevice->ReadWorkItem);
1109 tasklet_kill(&pDevice->EventWorkItem); 1137 tasklet_kill(&pDevice->EventWorkItem);
1110 1138
1111 pDevice->bRoaming = FALSE; 1139 pDevice->bRoaming = false;
1112 pDevice->bIsRoaming = FALSE; 1140 pDevice->bIsRoaming = false;
1113 pDevice->bEnableRoaming = FALSE; 1141 pDevice->bEnableRoaming = false;
1114 pDevice->bCmdRunning = FALSE; 1142 pDevice->bCmdRunning = false;
1115 pDevice->bLinkPass = FALSE; 1143 pDevice->bLinkPass = false;
1116 memset(pMgmt->abyCurrBSSID, 0, 6); 1144 memset(pMgmt->abyCurrBSSID, 0, 6);
1117 pMgmt->eCurrState = WMAC_STATE_IDLE; 1145 pMgmt->eCurrState = WMAC_STATE_IDLE;
1118 1146
@@ -1136,7 +1164,7 @@ static int device_close(struct net_device *dev) {
1136 1164
1137static void vt6656_disconnect(struct usb_interface *intf) 1165static void vt6656_disconnect(struct usb_interface *intf)
1138{ 1166{
1139 PSDevice device = usb_get_intfdata(intf); 1167 struct vnt_private *device = usb_get_intfdata(intf);
1140 1168
1141 if (!device) 1169 if (!device)
1142 return; 1170 return;
@@ -1156,7 +1184,7 @@ static void vt6656_disconnect(struct usb_interface *intf)
1156 1184
1157static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) 1185static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1158{ 1186{
1159 PSDevice pDevice = netdev_priv(dev); 1187 struct vnt_private *pDevice = netdev_priv(dev);
1160 1188
1161 spin_lock_irq(&pDevice->lock); 1189 spin_lock_irq(&pDevice->lock);
1162 1190
@@ -1172,7 +1200,7 @@ static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1172 1200
1173static int device_xmit(struct sk_buff *skb, struct net_device *dev) 1201static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1174{ 1202{
1175 PSDevice pDevice = netdev_priv(dev); 1203 struct vnt_private *pDevice = netdev_priv(dev);
1176 struct net_device_stats *stats = &pDevice->stats; 1204 struct net_device_stats *stats = &pDevice->stats;
1177 1205
1178 spin_lock_irq(&pDevice->lock); 1206 spin_lock_irq(&pDevice->lock);
@@ -1217,7 +1245,7 @@ static inline u32 ether_crc(int length, unsigned char *data)
1217 return crc; 1245 return crc;
1218} 1246}
1219 1247
1220//find out the start position of str2 from str1 1248/* find out the start position of str2 from str1 */
1221static unsigned char *kstrstr(const unsigned char *str1, 1249static unsigned char *kstrstr(const unsigned char *str1,
1222 const unsigned char *str2) { 1250 const unsigned char *str2) {
1223 int str1_len = strlen(str1); 1251 int str1_len = strlen(str1);
@@ -1246,37 +1274,37 @@ static int Config_FileGetParameter(unsigned char *string,
1246 strcat(buf1, "="); 1274 strcat(buf1, "=");
1247 source+=strlen(buf1); 1275 source+=strlen(buf1);
1248 1276
1249//find target string start point 1277 /* find target string start point */
1250 start_p = kstrstr(source,buf1); 1278 start_p = kstrstr(source,buf1);
1251 if (start_p == NULL) 1279 if (start_p == NULL)
1252 return FALSE; 1280 return false;
1253 1281
1254//check if current config line is marked by "#" ?? 1282 /* check if current config line is marked by "#" */
1255 for (ii = 1; ; ii++) { 1283 for (ii = 1; ; ii++) {
1256 if (memcmp(start_p - ii, "\n", 1) == 0) 1284 if (memcmp(start_p - ii, "\n", 1) == 0)
1257 break; 1285 break;
1258 if (memcmp(start_p - ii, "#", 1) == 0) 1286 if (memcmp(start_p - ii, "#", 1) == 0)
1259 return FALSE; 1287 return false;
1260 } 1288 }
1261 1289
1262//find target string end point 1290 /* find target string end point */
1263 end_p = kstrstr(start_p,"\n"); 1291 end_p = kstrstr(start_p,"\n");
1264 if (end_p == NULL) { //can't find "\n",but don't care 1292 if (end_p == NULL) { /* can't find "\n", but don't care */
1265 end_p=start_p+strlen(start_p); //no include "\n" 1293 end_p = start_p + strlen(start_p); /* no include "\n" */
1266 } 1294 }
1267 1295
1268 memset(buf2,0,100); 1296 memset(buf2,0,100);
1269 memcpy(buf2,start_p,end_p-start_p); //get the target line 1297 memcpy(buf2, start_p, end_p-start_p); /* get the target line */
1270 buf2[end_p-start_p]='\0'; 1298 buf2[end_p-start_p]='\0';
1271 1299
1272 //find value 1300 /* find value */
1273 start_p = kstrstr(buf2,"="); 1301 start_p = kstrstr(buf2,"=");
1274 if (start_p == NULL) 1302 if (start_p == NULL)
1275 return FALSE; 1303 return false;
1276 memset(buf1,0,100); 1304 memset(buf1,0,100);
1277 strcpy(buf1,start_p+1); 1305 strcpy(buf1,start_p+1);
1278 1306
1279 //except space 1307 /* except space */
1280 tmp_p = buf1; 1308 tmp_p = buf1;
1281 while(*tmp_p != 0x00) { 1309 while(*tmp_p != 0x00) {
1282 if(*tmp_p==' ') 1310 if(*tmp_p==' ')
@@ -1286,29 +1314,22 @@ static int Config_FileGetParameter(unsigned char *string,
1286 } 1314 }
1287 1315
1288 memcpy(dest,tmp_p,strlen(tmp_p)); 1316 memcpy(dest,tmp_p,strlen(tmp_p));
1289 return TRUE; 1317 return true;
1290} 1318}
1291 1319
1292//if read fail,return NULL,or return data pointer; 1320/* if read fails, return NULL, or return data pointer */
1293static unsigned char *Config_FileOperation(PSDevice pDevice) 1321static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
1294{ 1322{
1295 unsigned char *config_path = CONFIG_PATH; 1323 unsigned char *config_path = CONFIG_PATH;
1296 unsigned char *buffer = NULL; 1324 unsigned char *buffer = NULL;
1297 struct file *filp=NULL; 1325 struct file *filp=NULL;
1298 mm_segment_t old_fs = get_fs(); 1326 mm_segment_t old_fs = get_fs();
1299 //int oldfsuid=0,oldfsgid=0; 1327
1300 int result = 0; 1328 int result = 0;
1301 1329
1302 set_fs (KERNEL_DS); 1330 set_fs (KERNEL_DS);
1303 /* Can't do this anymore, so we rely on correct filesystem permissions: 1331
1304 //Make sure a caller can read or write power as root 1332 /* open file */
1305 oldfsuid=current->fsuid;
1306 oldfsgid=current->fsgid;
1307 current->fsuid = 0;
1308 current->fsgid = 0;
1309 */
1310
1311 //open file
1312 filp = filp_open(config_path, O_RDWR, 0); 1333 filp = filp_open(config_path, O_RDWR, 0);
1313 if (IS_ERR(filp)) { 1334 if (IS_ERR(filp)) {
1314 printk("Config_FileOperation file Not exist\n"); 1335 printk("Config_FileOperation file Not exist\n");
@@ -1341,11 +1362,6 @@ error1:
1341error2: 1362error2:
1342 set_fs (old_fs); 1363 set_fs (old_fs);
1343 1364
1344 /*
1345 current->fsuid=oldfsuid;
1346 current->fsgid=oldfsgid;
1347 */
1348
1349if(result!=0) { 1365if(result!=0) {
1350 kfree(buffer); 1366 kfree(buffer);
1351 buffer=NULL; 1367 buffer=NULL;
@@ -1353,13 +1369,14 @@ if(result!=0) {
1353 return buffer; 1369 return buffer;
1354} 1370}
1355 1371
1356//return --->-1:fail; >=0:successful 1372/* return --->-1:fail; >=0:successful */
1357static int Read_config_file(PSDevice pDevice) { 1373static int Read_config_file(struct vnt_private *pDevice)
1358 int result = 0; 1374{
1359 unsigned char tmpbuffer[100]; 1375 int result = 0;
1360 unsigned char *buffer = NULL; 1376 unsigned char tmpbuffer[100];
1377 unsigned char *buffer = NULL;
1361 1378
1362 //init config setting 1379 /* init config setting */
1363 pDevice->config_file.ZoneType = -1; 1380 pDevice->config_file.ZoneType = -1;
1364 pDevice->config_file.eAuthenMode = -1; 1381 pDevice->config_file.eAuthenMode = -1;
1365 pDevice->config_file.eEncryptionStatus = -1; 1382 pDevice->config_file.eEncryptionStatus = -1;
@@ -1370,10 +1387,10 @@ static int Read_config_file(PSDevice pDevice) {
1370 return result; 1387 return result;
1371 } 1388 }
1372 1389
1373//get zonetype 1390/* get zonetype */
1374{ 1391{
1375 memset(tmpbuffer,0,sizeof(tmpbuffer)); 1392 memset(tmpbuffer,0,sizeof(tmpbuffer));
1376 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==TRUE) { 1393 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) {
1377 if(memcmp(tmpbuffer,"USA",3)==0) { 1394 if(memcmp(tmpbuffer,"USA",3)==0) {
1378 pDevice->config_file.ZoneType=ZoneType_USA; 1395 pDevice->config_file.ZoneType=ZoneType_USA;
1379 } 1396 }
@@ -1389,15 +1406,15 @@ static int Read_config_file(PSDevice pDevice) {
1389 } 1406 }
1390} 1407}
1391 1408
1392//get other parameter 1409/* get other parameter */
1393 { 1410 {
1394 memset(tmpbuffer,0,sizeof(tmpbuffer)); 1411 memset(tmpbuffer,0,sizeof(tmpbuffer));
1395 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==TRUE) { 1412 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) {
1396 pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10); 1413 pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1397 } 1414 }
1398 1415
1399 memset(tmpbuffer,0,sizeof(tmpbuffer)); 1416 memset(tmpbuffer,0,sizeof(tmpbuffer));
1400 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==TRUE) { 1417 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) {
1401 pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10); 1418 pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1402 } 1419 }
1403 } 1420 }
@@ -1406,15 +1423,16 @@ static int Read_config_file(PSDevice pDevice) {
1406 return result; 1423 return result;
1407} 1424}
1408 1425
1409static void device_set_multi(struct net_device *dev) { 1426static void device_set_multi(struct net_device *dev)
1410 PSDevice pDevice = (PSDevice) netdev_priv(dev); 1427{
1411 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1428 struct vnt_private *pDevice = netdev_priv(dev);
1412 u32 mc_filter[2]; 1429 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1413 int ii; 1430 struct netdev_hw_addr *ha;
1414 struct netdev_hw_addr *ha; 1431 u32 mc_filter[2];
1415 BYTE pbyData[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; 1432 int ii;
1416 BYTE byTmpMode = 0; 1433 u8 pbyData[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1417 int rc; 1434 u8 byTmpMode = 0;
1435 int rc;
1418 1436
1419 1437
1420 spin_lock_irq(&pDevice->lock); 1438 spin_lock_irq(&pDevice->lock);
@@ -1429,9 +1447,9 @@ static void device_set_multi(struct net_device *dev) {
1429 1447
1430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode); 1448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode);
1431 1449
1432 if (dev->flags & IFF_PROMISC) { // Set promiscuous. 1450 if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
1433 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name); 1451 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1434 // Unconditionally log net taps. 1452 /* unconditionally log net taps */
1435 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST); 1453 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1436 } 1454 }
1437 else if ((netdev_mc_count(dev) > pDevice->multicast_limit) || 1455 else if ((netdev_mc_count(dev) > pDevice->multicast_limit) ||
@@ -1460,7 +1478,10 @@ static void device_set_multi(struct net_device *dev) {
1460 } 1478 }
1461 1479
1462 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) { 1480 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1463 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac. 1481 /*
1482 * If AP mode, don't enable RCR_UNICAST since HW only compares
1483 * addr1 with local MAC
1484 */
1464 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); 1485 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1465 pDevice->byRxMode &= ~(RCR_UNICAST); 1486 pDevice->byRxMode &= ~(RCR_UNICAST);
1466 } 1487 }
@@ -1472,14 +1493,14 @@ static void device_set_multi(struct net_device *dev) {
1472 1493
1473static struct net_device_stats *device_get_stats(struct net_device *dev) 1494static struct net_device_stats *device_get_stats(struct net_device *dev)
1474{ 1495{
1475 PSDevice pDevice=(PSDevice) netdev_priv(dev); 1496 struct vnt_private *pDevice = netdev_priv(dev);
1476 1497
1477 return &pDevice->stats; 1498 return &pDevice->stats;
1478} 1499}
1479 1500
1480static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1501static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1481{ 1502{
1482 PSDevice pDevice = (PSDevice)netdev_priv(dev); 1503 struct vnt_private *pDevice = netdev_priv(dev);
1483 struct iwreq *wrq = (struct iwreq *) rq; 1504 struct iwreq *wrq = (struct iwreq *) rq;
1484 int rc = 0; 1505 int rc = 0;
1485 1506
@@ -1524,9 +1545,6 @@ static int ethtool_ioctl(struct net_device *dev, void *useraddr)
1524 return -EOPNOTSUPP; 1545 return -EOPNOTSUPP;
1525} 1546}
1526 1547
1527
1528/*------------------------------------------------------------------*/
1529
1530MODULE_DEVICE_TABLE(usb, vt6656_table); 1548MODULE_DEVICE_TABLE(usb, vt6656_table);
1531 1549
1532static struct usb_driver vt6656_driver = { 1550static struct usb_driver vt6656_driver = {
diff --git a/drivers/staging/vt6656/power.c b/drivers/staging/vt6656/power.c
index ab3a55462056..527c259f6758 100644
--- a/drivers/staging/vt6656/power.c
+++ b/drivers/staging/vt6656/power.c
@@ -70,12 +70,10 @@ static int msglevel = MSG_LEVEL_INFO;
70 * 70 *
71 */ 71 */
72 72
73void PSvEnablePowerSaving(void *hDeviceContext, 73void PSvEnablePowerSaving(struct vnt_private *pDevice, u16 wListenInterval)
74 WORD wListenInterval)
75{ 74{
76 PSDevice pDevice = (PSDevice)hDeviceContext; 75 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
77 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 76 u16 wAID = pMgmt->wCurrAID | BIT14 | BIT15;
78 WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15;
79 77
80 /* set period of power up before TBTT */ 78 /* set period of power up before TBTT */
81 MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT); 79 MACvWriteWord(pDevice, MAC_REG_PWBT, C_PWBT);
@@ -116,13 +114,13 @@ void PSvEnablePowerSaving(void *hDeviceContext,
116 pMgmt->wCountToWakeUp = 0; 114 pMgmt->wCountToWakeUp = 0;
117 } 115 }
118 116
119 pDevice->bEnablePSMode = TRUE; 117 pDevice->bEnablePSMode = true;
120 118
121 /* We don't send null pkt in ad hoc mode since beacon will handle this. */ 119 /* We don't send null pkt in ad hoc mode since beacon will handle this. */
122 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) 120 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)
123 PSbSendNullPacket(pDevice); 121 PSbSendNullPacket(pDevice);
124 122
125 pDevice->bPWBitOn = TRUE; 123 pDevice->bPWBitOn = true;
126 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable...\n"); 124 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable...\n");
127} 125}
128 126
@@ -136,10 +134,8 @@ void PSvEnablePowerSaving(void *hDeviceContext,
136 * 134 *
137 */ 135 */
138 136
139void PSvDisablePowerSaving(void *hDeviceContext) 137void PSvDisablePowerSaving(struct vnt_private *pDevice)
140{ 138{
141 PSDevice pDevice = (PSDevice)hDeviceContext;
142 /* PSMgmtObject pMgmt = &(pDevice->sMgmtObj); */
143 139
144 /* disable power saving hw function */ 140 /* disable power saving hw function */
145 CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_DISABLE_PS, 0, 141 CONTROLnsRequestOut(pDevice, MESSAGE_TYPE_DISABLE_PS, 0,
@@ -150,12 +146,12 @@ void PSvDisablePowerSaving(void *hDeviceContext)
150 146
151 /* set always listen beacon */ 147 /* set always listen beacon */
152 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN); 148 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_ALBCN);
153 pDevice->bEnablePSMode = FALSE; 149 pDevice->bEnablePSMode = false;
154 150
155 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) 151 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)
156 PSbSendNullPacket(pDevice); 152 PSbSendNullPacket(pDevice);
157 153
158 pDevice->bPWBitOn = FALSE; 154 pDevice->bPWBitOn = false;
159} 155}
160 156
161/* 157/*
@@ -164,38 +160,36 @@ void PSvDisablePowerSaving(void *hDeviceContext)
164 * Consider to power down when no more packets to tx or rx. 160 * Consider to power down when no more packets to tx or rx.
165 * 161 *
166 * Return Value: 162 * Return Value:
167 * TRUE, if power down success 163 * true, if power down success
168 * FALSE, if fail 164 * false, if fail
169 */ 165 */
170 166
171BOOL PSbConsiderPowerDown(void *hDeviceContext, 167int PSbConsiderPowerDown(struct vnt_private *pDevice, int bCheckRxDMA,
172 BOOL bCheckRxDMA, 168 int bCheckCountToWakeUp)
173 BOOL bCheckCountToWakeUp)
174{ 169{
175 PSDevice pDevice = (PSDevice)hDeviceContext; 170 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
176 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 171 u8 byData;
177 BYTE byData;
178 172
179 /* check if already in Doze mode */ 173 /* check if already in Doze mode */
180 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG, 174 ControlvReadByte(pDevice, MESSAGE_REQUEST_MACREG,
181 MAC_REG_PSCTL, &byData); 175 MAC_REG_PSCTL, &byData);
182 176
183 if ((byData & PSCTL_PS) != 0) 177 if ((byData & PSCTL_PS) != 0)
184 return TRUE; 178 return true;
185 179
186 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { 180 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
187 /* check if in TIM wake period */ 181 /* check if in TIM wake period */
188 if (pMgmt->bInTIMWake) 182 if (pMgmt->bInTIMWake)
189 return FALSE; 183 return false;
190 } 184 }
191 185
192 /* check scan state */ 186 /* check scan state */
193 if (pDevice->bCmdRunning) 187 if (pDevice->bCmdRunning)
194 return FALSE; 188 return false;
195 189
196 /* Tx Burst */ 190 /* Tx Burst */
197 if (pDevice->bPSModeTxBurst) 191 if (pDevice->bPSModeTxBurst)
198 return FALSE; 192 return false;
199 193
200 /* Froce PSEN on */ 194 /* Froce PSEN on */
201 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN); 195 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_PSEN);
@@ -203,16 +197,16 @@ BOOL PSbConsiderPowerDown(void *hDeviceContext,
203 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) { 197 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
204 if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0 198 if (bCheckCountToWakeUp && (pMgmt->wCountToWakeUp == 0
205 || pMgmt->wCountToWakeUp == 1)) { 199 || pMgmt->wCountToWakeUp == 1)) {
206 return FALSE; 200 return false;
207 } 201 }
208 } 202 }
209 203
210 pDevice->bPSRxBeacon = TRUE; 204 pDevice->bPSRxBeacon = true;
211 205
212 /* no Tx, no Rx isr, now go to Doze */ 206 /* no Tx, no Rx isr, now go to Doze */
213 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE); 207 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_GO2DOZE);
214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n"); 208 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
215 return TRUE; 209 return true;
216} 210}
217 211
218/* 212/*
@@ -225,15 +219,17 @@ BOOL PSbConsiderPowerDown(void *hDeviceContext,
225 * 219 *
226 */ 220 */
227 221
228void PSvSendPSPOLL(void *hDeviceContext) 222void PSvSendPSPOLL(struct vnt_private *pDevice)
229{ 223{
230 PSDevice pDevice = (PSDevice)hDeviceContext; 224 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
231 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 225 struct vnt_tx_mgmt *pTxPacket = NULL;
232 PSTxMgmtPacket pTxPacket = NULL; 226
227 memset(pMgmt->pbyPSPacketPool, 0, sizeof(struct vnt_tx_mgmt)
228 + WLAN_HDR_ADDR2_LEN);
229 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyPSPacketPool;
230 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
231 + sizeof(struct vnt_tx_mgmt));
233 232
234 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
235 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
236 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
237 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16( 233 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
238 ( 234 (
239 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) | 235 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
@@ -263,24 +259,25 @@ void PSvSendPSPOLL(void *hDeviceContext)
263 * 259 *
264 */ 260 */
265 261
266BOOL PSbSendNullPacket(void *hDeviceContext) 262int PSbSendNullPacket(struct vnt_private *pDevice)
267{ 263{
268 PSDevice pDevice = (PSDevice)hDeviceContext; 264 struct vnt_tx_mgmt *pTxPacket = NULL;
269 PSTxMgmtPacket pTxPacket = NULL; 265 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
270 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
271 u16 flags = 0; 266 u16 flags = 0;
272 267
273 if (pDevice->bLinkPass == FALSE) 268 if (pDevice->bLinkPass == false)
274 return FALSE; 269 return false;
275 270
276 if ((pDevice->bEnablePSMode == FALSE) && 271 if ((pDevice->bEnablePSMode == false) &&
277 (pDevice->fTxDataInSleep == FALSE)) { 272 (pDevice->fTxDataInSleep == false)) {
278 return FALSE; 273 return false;
279 } 274 }
280 275
281 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN); 276 memset(pMgmt->pbyPSPacketPool, 0, sizeof(struct vnt_tx_mgmt)
282 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool; 277 + WLAN_NULLDATA_FR_MAXLEN);
283 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 278 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyPSPacketPool;
279 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
280 + sizeof(struct vnt_tx_mgmt));
284 281
285 flags = WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) | 282 flags = WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
286 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL); 283 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL);
@@ -303,9 +300,9 @@ BOOL PSbSendNullPacket(void *hDeviceContext)
303 /* log error if sending failed */ 300 /* log error if sending failed */
304 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) { 301 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
305 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n"); 302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
306 return FALSE; 303 return false;
307 } 304 }
308 return TRUE; 305 return true;
309} 306}
310 307
311/* 308/*
@@ -318,11 +315,10 @@ BOOL PSbSendNullPacket(void *hDeviceContext)
318 * 315 *
319 */ 316 */
320 317
321BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext) 318int PSbIsNextTBTTWakeUp(struct vnt_private *pDevice)
322{ 319{
323 PSDevice pDevice = (PSDevice)hDeviceContext; 320 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
324 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 321 int bWakeUp = false;
325 BOOL bWakeUp = FALSE;
326 322
327 if (pMgmt->wListenInterval >= 2) { 323 if (pMgmt->wListenInterval >= 2) {
328 if (pMgmt->wCountToWakeUp == 0) 324 if (pMgmt->wCountToWakeUp == 0)
@@ -333,8 +329,8 @@ BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext)
333 if (pMgmt->wCountToWakeUp == 1) { 329 if (pMgmt->wCountToWakeUp == 1) {
334 /* Turn on wake up to listen next beacon */ 330 /* Turn on wake up to listen next beacon */
335 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); 331 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
336 pDevice->bPSRxBeacon = FALSE; 332 pDevice->bPSRxBeacon = false;
337 bWakeUp = TRUE; 333 bWakeUp = true;
338 } else if (!pDevice->bPSRxBeacon) { 334 } else if (!pDevice->bPSRxBeacon) {
339 /* Listen until RxBeacon */ 335 /* Listen until RxBeacon */
340 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN); 336 MACvRegBitsOn(pDevice, MAC_REG_PSCTL, PSCTL_LNBCN);
diff --git a/drivers/staging/vt6656/power.h b/drivers/staging/vt6656/power.h
index 41bffe528b44..879b10c0d42e 100644
--- a/drivers/staging/vt6656/power.h
+++ b/drivers/staging/vt6656/power.h
@@ -48,14 +48,12 @@
48/* PSDevice pDevice */ 48/* PSDevice pDevice */
49/* PSDevice hDeviceContext */ 49/* PSDevice hDeviceContext */
50 50
51BOOL PSbConsiderPowerDown(void *hDeviceContext, 51int PSbConsiderPowerDown(struct vnt_private *, int bCheckRxDMA,
52 BOOL bCheckRxDMA, 52 int bCheckCountToWakeUp);
53 BOOL bCheckCountToWakeUp); 53void PSvDisablePowerSaving(struct vnt_private *);
54 54void PSvEnablePowerSaving(struct vnt_private *, u16 wListenInterval);
55void PSvDisablePowerSaving(void *hDeviceContext); 55void PSvSendPSPOLL(struct vnt_private *);
56void PSvEnablePowerSaving(void *hDeviceContext, WORD wListenInterval); 56int PSbSendNullPacket(struct vnt_private *);
57void PSvSendPSPOLL(void *hDeviceContext); 57int PSbIsNextTBTTWakeUp(struct vnt_private *);
58BOOL PSbSendNullPacket(void *hDeviceContext);
59BOOL PSbIsNextTBTTWakeUp(void *hDeviceContext);
60 58
61#endif /* __POWER_H__ */ 59#endif /* __POWER_H__ */
diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c
index 74c0598e37b7..a415705297b2 100644
--- a/drivers/staging/vt6656/rf.c
+++ b/drivers/staging/vt6656/rf.c
@@ -69,7 +69,7 @@ static int msglevel =MSG_LEVEL_INFO;
69 69
70 70
71 71
72BYTE abyAL2230InitTable[CB_AL2230_INIT_SEQ][3] = { 72u8 abyAL2230InitTable[CB_AL2230_INIT_SEQ][3] = {
73 {0x03, 0xF7, 0x90}, 73 {0x03, 0xF7, 0x90},
74 {0x03, 0x33, 0x31}, 74 {0x03, 0x33, 0x31},
75 {0x01, 0xB8, 0x02}, 75 {0x01, 0xB8, 0x02},
@@ -87,7 +87,7 @@ BYTE abyAL2230InitTable[CB_AL2230_INIT_SEQ][3] = {
87 {0x00, 0x58, 0x0F} 87 {0x00, 0x58, 0x0F}
88 }; 88 };
89 89
90BYTE abyAL2230ChannelTable0[CB_MAX_CHANNEL_24G][3] = { 90u8 abyAL2230ChannelTable0[CB_MAX_CHANNEL_24G][3] = {
91 {0x03, 0xF7, 0x90}, // channel = 1, Tf = 2412MHz 91 {0x03, 0xF7, 0x90}, // channel = 1, Tf = 2412MHz
92 {0x03, 0xF7, 0x90}, // channel = 2, Tf = 2417MHz 92 {0x03, 0xF7, 0x90}, // channel = 2, Tf = 2417MHz
93 {0x03, 0xE7, 0x90}, // channel = 3, Tf = 2422MHz 93 {0x03, 0xE7, 0x90}, // channel = 3, Tf = 2422MHz
@@ -104,7 +104,7 @@ BYTE abyAL2230ChannelTable0[CB_MAX_CHANNEL_24G][3] = {
104 {0x03, 0xE7, 0xC0} // channel = 14, Tf = 2412M 104 {0x03, 0xE7, 0xC0} // channel = 14, Tf = 2412M
105 }; 105 };
106 106
107BYTE abyAL2230ChannelTable1[CB_MAX_CHANNEL_24G][3] = { 107u8 abyAL2230ChannelTable1[CB_MAX_CHANNEL_24G][3] = {
108 {0x03, 0x33, 0x31}, // channel = 1, Tf = 2412MHz 108 {0x03, 0x33, 0x31}, // channel = 1, Tf = 2412MHz
109 {0x0B, 0x33, 0x31}, // channel = 2, Tf = 2417MHz 109 {0x0B, 0x33, 0x31}, // channel = 2, Tf = 2417MHz
110 {0x03, 0x33, 0x31}, // channel = 3, Tf = 2422MHz 110 {0x03, 0x33, 0x31}, // channel = 3, Tf = 2422MHz
@@ -123,7 +123,7 @@ BYTE abyAL2230ChannelTable1[CB_MAX_CHANNEL_24G][3] = {
123 123
124// 40MHz reference frequency 124// 40MHz reference frequency
125// Need to Pull PLLON(PE3) low when writing channel registers through 3-wire. 125// Need to Pull PLLON(PE3) low when writing channel registers through 3-wire.
126BYTE abyAL7230InitTable[CB_AL7230_INIT_SEQ][3] = { 126u8 abyAL7230InitTable[CB_AL7230_INIT_SEQ][3] = {
127 {0x20, 0x37, 0x90}, // Channel1 // Need modify for 11a 127 {0x20, 0x37, 0x90}, // Channel1 // Need modify for 11a
128 {0x13, 0x33, 0x31}, // Channel1 // Need modify for 11a 128 {0x13, 0x33, 0x31}, // Channel1 // Need modify for 11a
129 {0x84, 0x1F, 0xF2}, // Need modify for 11a: 451FE2 129 {0x84, 0x1F, 0xF2}, // Need modify for 11a: 451FE2
@@ -146,7 +146,7 @@ BYTE abyAL7230InitTable[CB_AL7230_INIT_SEQ][3] = {
146 {0x1A, 0xBA, 0x8F} // Need modify for 11a: 12BACF 146 {0x1A, 0xBA, 0x8F} // Need modify for 11a: 12BACF
147 }; 147 };
148 148
149BYTE abyAL7230InitTableAMode[CB_AL7230_INIT_SEQ][3] = { 149u8 abyAL7230InitTableAMode[CB_AL7230_INIT_SEQ][3] = {
150 {0x2F, 0xF5, 0x20}, // Channel184 // Need modify for 11b/g 150 {0x2F, 0xF5, 0x20}, // Channel184 // Need modify for 11b/g
151 {0x00, 0x00, 0x01}, // Channel184 // Need modify for 11b/g 151 {0x00, 0x00, 0x01}, // Channel184 // Need modify for 11b/g
152 {0x45, 0x1F, 0xE2}, // Need modify for 11b/g 152 {0x45, 0x1F, 0xE2}, // Need modify for 11b/g
@@ -165,7 +165,7 @@ BYTE abyAL7230InitTableAMode[CB_AL7230_INIT_SEQ][3] = {
165 {0x12, 0xBA, 0xCF} // Need modify for 11b/g 165 {0x12, 0xBA, 0xCF} // Need modify for 11b/g
166 }; 166 };
167 167
168BYTE abyAL7230ChannelTable0[CB_MAX_CHANNEL][3] = { 168u8 abyAL7230ChannelTable0[CB_MAX_CHANNEL][3] = {
169 {0x20, 0x37, 0x90}, // channel = 1, Tf = 2412MHz 169 {0x20, 0x37, 0x90}, // channel = 1, Tf = 2412MHz
170 {0x20, 0x37, 0x90}, // channel = 2, Tf = 2417MHz 170 {0x20, 0x37, 0x90}, // channel = 2, Tf = 2417MHz
171 {0x20, 0x37, 0x90}, // channel = 3, Tf = 2422MHz 171 {0x20, 0x37, 0x90}, // channel = 3, Tf = 2422MHz
@@ -231,7 +231,7 @@ BYTE abyAL7230ChannelTable0[CB_MAX_CHANNEL][3] = {
231 {0x2F, 0xF6, 0x10} // channel = 165, Tf = 5825MHz (56) 231 {0x2F, 0xF6, 0x10} // channel = 165, Tf = 5825MHz (56)
232 }; 232 };
233 233
234BYTE abyAL7230ChannelTable1[CB_MAX_CHANNEL][3] = { 234u8 abyAL7230ChannelTable1[CB_MAX_CHANNEL][3] = {
235 {0x13, 0x33, 0x31}, // channel = 1, Tf = 2412MHz 235 {0x13, 0x33, 0x31}, // channel = 1, Tf = 2412MHz
236 {0x1B, 0x33, 0x31}, // channel = 2, Tf = 2417MHz 236 {0x1B, 0x33, 0x31}, // channel = 2, Tf = 2417MHz
237 {0x03, 0x33, 0x31}, // channel = 3, Tf = 2422MHz 237 {0x03, 0x33, 0x31}, // channel = 3, Tf = 2422MHz
@@ -295,7 +295,7 @@ BYTE abyAL7230ChannelTable1[CB_MAX_CHANNEL][3] = {
295 {0x02, 0xAA, 0xB1} // channel = 165, Tf = 5825MHz (56) 295 {0x02, 0xAA, 0xB1} // channel = 165, Tf = 5825MHz (56)
296 }; 296 };
297 297
298BYTE abyAL7230ChannelTable2[CB_MAX_CHANNEL][3] = { 298u8 abyAL7230ChannelTable2[CB_MAX_CHANNEL][3] = {
299 {0x7F, 0xD7, 0x84}, // channel = 1, Tf = 2412MHz 299 {0x7F, 0xD7, 0x84}, // channel = 1, Tf = 2412MHz
300 {0x7F, 0xD7, 0x84}, // channel = 2, Tf = 2417MHz 300 {0x7F, 0xD7, 0x84}, // channel = 2, Tf = 2417MHz
301 {0x7F, 0xD7, 0x84}, // channel = 3, Tf = 2422MHz 301 {0x7F, 0xD7, 0x84}, // channel = 3, Tf = 2422MHz
@@ -360,7 +360,7 @@ BYTE abyAL7230ChannelTable2[CB_MAX_CHANNEL][3] = {
360 }; 360 };
361 361
362///{{RobertYu:20051111 362///{{RobertYu:20051111
363BYTE abyVT3226_InitTable[CB_VT3226_INIT_SEQ][3] = { 363u8 abyVT3226_InitTable[CB_VT3226_INIT_SEQ][3] = {
364 {0x03, 0xFF, 0x80}, 364 {0x03, 0xFF, 0x80},
365 {0x02, 0x82, 0xA1}, 365 {0x02, 0x82, 0xA1},
366 {0x03, 0xC6, 0xA2}, 366 {0x03, 0xC6, 0xA2},
@@ -374,7 +374,7 @@ BYTE abyVT3226_InitTable[CB_VT3226_INIT_SEQ][3] = {
374 {0x02, 0x00, 0x2A} 374 {0x02, 0x00, 0x2A}
375 }; 375 };
376 376
377BYTE abyVT3226D0_InitTable[CB_VT3226_INIT_SEQ][3] = { 377u8 abyVT3226D0_InitTable[CB_VT3226_INIT_SEQ][3] = {
378 {0x03, 0xFF, 0x80}, 378 {0x03, 0xFF, 0x80},
379 {0x03, 0x02, 0x21}, //RobertYu:20060327 379 {0x03, 0x02, 0x21}, //RobertYu:20060327
380 {0x03, 0xC6, 0xA2}, 380 {0x03, 0xC6, 0xA2},
@@ -389,7 +389,7 @@ BYTE abyVT3226D0_InitTable[CB_VT3226_INIT_SEQ][3] = {
389 }; 389 };
390 390
391 391
392BYTE abyVT3226_ChannelTable0[CB_MAX_CHANNEL_24G][3] = { 392u8 abyVT3226_ChannelTable0[CB_MAX_CHANNEL_24G][3] = {
393 {0x01, 0x97, 0x83}, // channel = 1, Tf = 2412MHz 393 {0x01, 0x97, 0x83}, // channel = 1, Tf = 2412MHz
394 {0x01, 0x97, 0x83}, // channel = 2, Tf = 2417MHz 394 {0x01, 0x97, 0x83}, // channel = 2, Tf = 2417MHz
395 {0x01, 0x97, 0x93}, // channel = 3, Tf = 2422MHz 395 {0x01, 0x97, 0x93}, // channel = 3, Tf = 2422MHz
@@ -406,7 +406,7 @@ BYTE abyVT3226_ChannelTable0[CB_MAX_CHANNEL_24G][3] = {
406 {0x03, 0x37, 0xC3} // channel = 14, Tf = 2484MHz 406 {0x03, 0x37, 0xC3} // channel = 14, Tf = 2484MHz
407 }; 407 };
408 408
409BYTE abyVT3226_ChannelTable1[CB_MAX_CHANNEL_24G][3] = { 409u8 abyVT3226_ChannelTable1[CB_MAX_CHANNEL_24G][3] = {
410 {0x02, 0x66, 0x64}, // channel = 1, Tf = 2412MHz 410 {0x02, 0x66, 0x64}, // channel = 1, Tf = 2412MHz
411 {0x03, 0x66, 0x64}, // channel = 2, Tf = 2417MHz 411 {0x03, 0x66, 0x64}, // channel = 2, Tf = 2417MHz
412 {0x00, 0x66, 0x64}, // channel = 3, Tf = 2422MHz 412 {0x00, 0x66, 0x64}, // channel = 3, Tf = 2422MHz
@@ -426,7 +426,7 @@ BYTE abyVT3226_ChannelTable1[CB_MAX_CHANNEL_24G][3] = {
426 426
427 427
428//{{RobertYu:20060502, TWIF 1.14, LO Current for 11b mode 428//{{RobertYu:20060502, TWIF 1.14, LO Current for 11b mode
429DWORD dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = { 429u32 dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = {
430 0x0135C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz 430 0x0135C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
431 0x0135C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz 431 0x0135C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
432 0x0235C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz 432 0x0235C600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
@@ -446,7 +446,7 @@ DWORD dwVT3226D0LoCurrentTable[CB_MAX_CHANNEL_24G] = {
446 446
447 447
448//{{RobertYu:20060609 448//{{RobertYu:20060609
449BYTE abyVT3342A0_InitTable[CB_VT3342_INIT_SEQ][3] = { // 11b/g mode 449u8 abyVT3342A0_InitTable[CB_VT3342_INIT_SEQ][3] = { /* 11b/g mode */
450 {0x03, 0xFF, 0x80}, //update for mode// 450 {0x03, 0xFF, 0x80}, //update for mode//
451 {0x02, 0x08, 0x81}, 451 {0x02, 0x08, 0x81},
452 {0x00, 0xC6, 0x02}, 452 {0x00, 0xC6, 0x02},
@@ -469,7 +469,7 @@ BYTE abyVT3342A0_InitTable[CB_VT3342_INIT_SEQ][3] = { // 11b/g mode
469 // channel56, 5280MHz 0x00C402 for disable Frac 469 // channel56, 5280MHz 0x00C402 for disable Frac
470 // other channels 0x00C602 470 // other channels 0x00C602
471 471
472BYTE abyVT3342_ChannelTable0[CB_MAX_CHANNEL][3] = { 472u8 abyVT3342_ChannelTable0[CB_MAX_CHANNEL][3] = {
473 {0x02, 0x05, 0x03}, // channel = 1, Tf = 2412MHz 473 {0x02, 0x05, 0x03}, // channel = 1, Tf = 2412MHz
474 {0x01, 0x15, 0x03}, // channel = 2, Tf = 2417MHz 474 {0x01, 0x15, 0x03}, // channel = 2, Tf = 2417MHz
475 {0x03, 0xC5, 0x03}, // channel = 3, Tf = 2422MHz 475 {0x03, 0xC5, 0x03}, // channel = 3, Tf = 2422MHz
@@ -535,7 +535,7 @@ BYTE abyVT3342_ChannelTable0[CB_MAX_CHANNEL][3] = {
535 {0x00, 0x06, 0x03} // channel = 165, Tf = 5825MHz (56), TBD 535 {0x00, 0x06, 0x03} // channel = 165, Tf = 5825MHz (56), TBD
536 }; 536 };
537 537
538BYTE abyVT3342_ChannelTable1[CB_MAX_CHANNEL][3] = { 538u8 abyVT3342_ChannelTable1[CB_MAX_CHANNEL][3] = {
539 {0x01, 0x99, 0x94}, // channel = 1, Tf = 2412MHz 539 {0x01, 0x99, 0x94}, // channel = 1, Tf = 2412MHz
540 {0x02, 0x44, 0x44}, // channel = 2, Tf = 2417MHz 540 {0x02, 0x44, 0x44}, // channel = 2, Tf = 2417MHz
541 {0x02, 0xEE, 0xE4}, // channel = 3, Tf = 2422MHz 541 {0x02, 0xEE, 0xE4}, // channel = 3, Tf = 2422MHz
@@ -606,7 +606,7 @@ BYTE abyVT3342_ChannelTable1[CB_MAX_CHANNEL][3] = {
606 * 606 *
607-*/ 607-*/
608 608
609const DWORD dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = { 609const u32 dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
610 0x04040900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, 610 0x04040900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
611 0x04041900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, 611 0x04041900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
612 0x04042900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, 612 0x04042900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
@@ -682,7 +682,7 @@ const DWORD dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
682// 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64, 682// 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
683// 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56) 683// 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
684 684
685const BYTE RFaby11aChannelIndex[200] = { 685const u8 RFaby11aChannelIndex[200] = {
686 // 1 2 3 4 5 6 7 8 9 10 686 // 1 2 3 4 5 6 7 8 9 10
687 00, 00, 00, 00, 00, 00, 23, 24, 25, 00, // 10 687 00, 00, 00, 00, 00, 00, 23, 24, 25, 00, // 10
688 26, 27, 00, 00, 00, 28, 00, 00, 00, 00, // 20 688 26, 27, 00, 00, 00, 28, 00, 00, 00, 00, // 20
@@ -719,27 +719,23 @@ const BYTE RFaby11aChannelIndex[200] = {
719 * Out: 719 * Out:
720 * none 720 * none
721 * 721 *
722 * Return Value: TRUE if succeeded; FALSE if failed. 722 * Return Value: true if succeeded; false if failed.
723 * 723 *
724 */ 724 */
725BOOL IFRFbWriteEmbedded (PSDevice pDevice, DWORD dwData) 725int IFRFbWriteEmbedded(struct vnt_private *pDevice, u32 dwData)
726{ 726{
727 BYTE pbyData[4]; 727 u8 pbyData[4];
728 728
729 pbyData[0] = (BYTE)dwData; 729 pbyData[0] = (u8)dwData;
730 pbyData[1] = (BYTE)(dwData>>8); 730 pbyData[1] = (u8)(dwData >> 8);
731 pbyData[2] = (BYTE)(dwData>>16); 731 pbyData[2] = (u8)(dwData >> 16);
732 pbyData[3] = (BYTE)(dwData>>24); 732 pbyData[3] = (u8)(dwData >> 24);
733 CONTROLnsRequestOut(pDevice, 733
734 MESSAGE_TYPE_WRITE_IFRF, 734 CONTROLnsRequestOut(pDevice,
735 0, 735 MESSAGE_TYPE_WRITE_IFRF, 0, 0, 4, pbyData);
736 0,
737 4,
738 pbyData
739 );
740 736
741 737
742 return TRUE; 738 return true;
743} 739}
744 740
745 741
@@ -753,21 +749,16 @@ BOOL IFRFbWriteEmbedded (PSDevice pDevice, DWORD dwData)
753 * Out: 749 * Out:
754 * none 750 * none
755 * 751 *
756 * Return Value: TRUE if succeeded; FALSE if failed. 752 * Return Value: true if succeeded; false if failed.
757 * 753 *
758 */ 754 */
759BOOL RFbSetPower ( 755int RFbSetPower(struct vnt_private *pDevice, u32 uRATE, u32 uCH)
760 PSDevice pDevice,
761 unsigned int uRATE,
762 unsigned int uCH
763 )
764{ 756{
765BOOL bResult = TRUE; 757 int bResult = true;
766BYTE byPwr = pDevice->byCCKPwr; 758 u8 byPwr = pDevice->byCCKPwr;
767 759
768 if (pDevice->dwDiagRefCount != 0) { 760 if (pDevice->dwDiagRefCount)
769 return TRUE; 761 return true;
770 }
771 762
772 if (uCH == 0) 763 if (uCH == 0)
773 return -EINVAL; 764 return -EINVAL;
@@ -810,19 +801,16 @@ BYTE byPwr = pDevice->byCCKPwr;
810 * Out: 801 * Out:
811 * none 802 * none
812 * 803 *
813 * Return Value: TRUE if succeeded; FALSE if failed. 804 * Return Value: true if succeeded; false if failed.
814 * 805 *
815 */ 806 */
816BOOL RFbRawSetPower ( 807
817 PSDevice pDevice, 808int RFbRawSetPower(struct vnt_private *pDevice, u8 byPwr, u32 uRATE)
818 BYTE byPwr,
819 unsigned int uRATE
820 )
821{ 809{
822BOOL bResult = TRUE; 810 int bResult = true;
823 811
824 if (pDevice->byCurPwr == byPwr) 812 if (pDevice->byCurPwr == byPwr)
825 return TRUE; 813 return true;
826 814
827 pDevice->byCurPwr = byPwr; 815 pDevice->byCurPwr = byPwr;
828 816
@@ -830,7 +818,7 @@ BOOL bResult = TRUE;
830 818
831 case RF_AL2230 : 819 case RF_AL2230 :
832 if (pDevice->byCurPwr >= AL2230_PWR_IDX_LEN) 820 if (pDevice->byCurPwr >= AL2230_PWR_IDX_LEN)
833 return FALSE; 821 return false;
834 bResult &= IFRFbWriteEmbedded(pDevice, dwAL2230PowerTable[pDevice->byCurPwr]); 822 bResult &= IFRFbWriteEmbedded(pDevice, dwAL2230PowerTable[pDevice->byCurPwr]);
835 if (uRATE <= RATE_11M) 823 if (uRATE <= RATE_11M)
836 bResult &= IFRFbWriteEmbedded(pDevice, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 824 bResult &= IFRFbWriteEmbedded(pDevice, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
@@ -840,7 +828,7 @@ BOOL bResult = TRUE;
840 828
841 case RF_AL2230S : 829 case RF_AL2230S :
842 if (pDevice->byCurPwr >= AL2230_PWR_IDX_LEN) 830 if (pDevice->byCurPwr >= AL2230_PWR_IDX_LEN)
843 return FALSE; 831 return false;
844 bResult &= IFRFbWriteEmbedded(pDevice, dwAL2230PowerTable[pDevice->byCurPwr]); 832 bResult &= IFRFbWriteEmbedded(pDevice, dwAL2230PowerTable[pDevice->byCurPwr]);
845 if (uRATE <= RATE_11M) { 833 if (uRATE <= RATE_11M) {
846 bResult &= IFRFbWriteEmbedded(pDevice, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 834 bResult &= IFRFbWriteEmbedded(pDevice, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
@@ -863,7 +851,7 @@ BOOL bResult = TRUE;
863 bResult &= IFRFbWriteEmbedded(pDevice, 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW); 851 bResult &= IFRFbWriteEmbedded(pDevice, 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW);
864 } 852 }
865 853
866 if (pDevice->byCurPwr > AL7230_PWR_IDX_LEN) return FALSE; 854 if (pDevice->byCurPwr > AL7230_PWR_IDX_LEN) return false;
867 855
868 // 0x080F1B00 for 3 wire control TxGain(D10) and 0x31 as TX Gain value 856 // 0x080F1B00 for 3 wire control TxGain(D10) and 0x31 as TX Gain value
869 dwMax7230Pwr = 0x080C0B00 | ( (pDevice->byCurPwr) << 12 ) | 857 dwMax7230Pwr = 0x080C0B00 | ( (pDevice->byCurPwr) << 12 ) |
@@ -879,7 +867,7 @@ BOOL bResult = TRUE;
879 DWORD dwVT3226Pwr; 867 DWORD dwVT3226Pwr;
880 868
881 if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN) 869 if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN)
882 return FALSE; 870 return false;
883 dwVT3226Pwr = ((0x3F-pDevice->byCurPwr) << 20 ) | ( 0x17 << 8 ) /* Reg7 */ | 871 dwVT3226Pwr = ((0x3F-pDevice->byCurPwr) << 20 ) | ( 0x17 << 8 ) /* Reg7 */ |
884 (BY_VT3226_REG_LEN << 3 ) | IFREGCTL_REGW; 872 (BY_VT3226_REG_LEN << 3 ) | IFREGCTL_REGW;
885 bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226Pwr); 873 bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226Pwr);
@@ -891,7 +879,7 @@ BOOL bResult = TRUE;
891 DWORD dwVT3226Pwr; 879 DWORD dwVT3226Pwr;
892 880
893 if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN) 881 if (pDevice->byCurPwr >= VT3226_PWR_IDX_LEN)
894 return FALSE; 882 return false;
895 883
896 if (uRATE <= RATE_11M) { 884 if (uRATE <= RATE_11M) {
897 885
@@ -900,14 +888,22 @@ BOOL bResult = TRUE;
900 bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226Pwr); 888 bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226Pwr);
901 889
902 bResult &= IFRFbWriteEmbedded(pDevice, 0x03C6A200+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW); 890 bResult &= IFRFbWriteEmbedded(pDevice, 0x03C6A200+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW);
903 if (pDevice->sMgmtObj.eScanState != WMAC_NO_SCANNING) { 891 if (pDevice->vnt_mgmt.eScanState != WMAC_NO_SCANNING) {
904 // scanning, the channel number is pDevice->uScanChannel 892 /* scanning, channel number is pDevice->uScanChannel */
905 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"@@@@ RFbRawSetPower> 11B mode uCurrChannel[%d]\n", pDevice->sMgmtObj.uScanChannel); 893 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
906 bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226D0LoCurrentTable[pDevice->sMgmtObj.uScanChannel-1]); //RobertYu:20060420, sometimes didn't change channel just set power with different rate 894 "RFbRawSetPower> 11B mode uCurrChannel[%d]\n",
907 } else { 895 pDevice->vnt_mgmt.uScanChannel);
908 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"@@@@ RFbRawSetPower> 11B mode uCurrChannel[%d]\n", pDevice->sMgmtObj.uCurrChannel); 896 bResult &= IFRFbWriteEmbedded(pDevice,
909 bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226D0LoCurrentTable[pDevice->sMgmtObj.uCurrChannel-1]); //RobertYu:20060420, sometimes didn't change channel just set power with different rate 897 dwVT3226D0LoCurrentTable[pDevice->
910 } 898 vnt_mgmt.uScanChannel - 1]);
899 } else {
900 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
901 "RFbRawSetPower> 11B mode uCurrChannel[%d]\n",
902 pDevice->vnt_mgmt.uCurrChannel);
903 bResult &= IFRFbWriteEmbedded(pDevice,
904 dwVT3226D0LoCurrentTable[pDevice->
905 vnt_mgmt.uCurrChannel - 1]);
906 }
911 907
912 bResult &= IFRFbWriteEmbedded(pDevice, 0x015C0800+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW); //RobertYu:20060420, ok now, new switching power (mini-pci can have bigger power consumption) 908 bResult &= IFRFbWriteEmbedded(pDevice, 0x015C0800+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW); //RobertYu:20060420, ok now, new switching power (mini-pci can have bigger power consumption)
913 } else { 909 } else {
@@ -928,7 +924,7 @@ BOOL bResult = TRUE;
928 DWORD dwVT3342Pwr; 924 DWORD dwVT3342Pwr;
929 925
930 if (pDevice->byCurPwr >= VT3342_PWR_IDX_LEN) 926 if (pDevice->byCurPwr >= VT3342_PWR_IDX_LEN)
931 return FALSE; 927 return false;
932 928
933 dwVT3342Pwr = ((0x3F-pDevice->byCurPwr) << 20 ) | ( 0x27 << 8 ) /* Reg7 */ | 929 dwVT3342Pwr = ((0x3F-pDevice->byCurPwr) << 20 ) | ( 0x27 << 8 ) /* Reg7 */ |
934 (BY_VT3342_REG_LEN << 3 ) | IFREGCTL_REGW; 930 (BY_VT3342_REG_LEN << 3 ) | IFREGCTL_REGW;
@@ -957,17 +953,12 @@ BOOL bResult = TRUE;
957 * Return Value: none 953 * Return Value: none
958 * 954 *
959-*/ 955-*/
960void 956void RFvRSSITodBm(struct vnt_private *pDevice, u8 byCurrRSSI, long *pldBm)
961RFvRSSITodBm (
962 PSDevice pDevice,
963 BYTE byCurrRSSI,
964 long * pldBm
965 )
966{ 957{
967 BYTE byIdx = (((byCurrRSSI & 0xC0) >> 6) & 0x03); 958 u8 byIdx = (((byCurrRSSI & 0xC0) >> 6) & 0x03);
968 signed long b = (byCurrRSSI & 0x3F); 959 signed long b = (byCurrRSSI & 0x3F);
969 signed long a = 0; 960 signed long a = 0;
970 BYTE abyAIROHARF[4] = {0, 18, 0, 40}; 961 u8 abyAIROHARF[4] = {0, 18, 0, 40};
971 962
972 switch (pDevice->byRFType) { 963 switch (pDevice->byRFType) {
973 case RF_AL2230: 964 case RF_AL2230:
@@ -987,15 +978,12 @@ RFvRSSITodBm (
987 978
988 979
989 980
990void 981void RFbRFTableDownload(struct vnt_private *pDevice)
991RFbRFTableDownload (
992 PSDevice pDevice
993 )
994{ 982{
995WORD wLength1 = 0,wLength2 = 0 ,wLength3 = 0; 983 u16 wLength1 = 0, wLength2 = 0, wLength3 = 0;
996PBYTE pbyAddr1 = NULL,pbyAddr2 = NULL,pbyAddr3 = NULL; 984 u8 *pbyAddr1 = NULL, *pbyAddr2 = NULL, *pbyAddr3 = NULL;
997WORD wLength,wValue; 985 u16 wLength, wValue;
998BYTE abyArray[256]; 986 u8 abyArray[256];
999 987
1000 switch ( pDevice->byRFType ) { 988 switch ( pDevice->byRFType ) {
1001 case RF_AL2230: 989 case RF_AL2230:
@@ -1134,21 +1122,19 @@ BYTE abyArray[256];
1134 1122
1135} 1123}
1136 1124
1137// RobertYu:20060412, TWIF1.11 adjust LO Current for 11b mode 1125int s_bVT3226D0_11bLoCurrentAdjust(struct vnt_private *pDevice, u8 byChannel,
1138BOOL s_bVT3226D0_11bLoCurrentAdjust( 1126 int b11bMode)
1139 PSDevice pDevice,
1140 BYTE byChannel,
1141 BOOL b11bMode)
1142{ 1127{
1143 BOOL bResult; 1128 int bResult = true;
1144 1129
1145 bResult = TRUE; 1130 if (b11bMode)
1146 if( b11bMode ) 1131 bResult &= IFRFbWriteEmbedded(pDevice,
1147 bResult &= IFRFbWriteEmbedded(pDevice, dwVT3226D0LoCurrentTable[byChannel-1]); 1132 dwVT3226D0LoCurrentTable[byChannel-1]);
1148 else 1133 else
1149 bResult &= IFRFbWriteEmbedded(pDevice, 0x016BC600+(BY_VT3226_REG_LEN<<3)+IFREGCTL_REGW); //RobertYu:20060412 1134 bResult &= IFRFbWriteEmbedded(pDevice, 0x016bc600 +
1135 (BY_VT3226_REG_LEN << 3) + IFREGCTL_REGW);
1150 1136
1151 return bResult; 1137 return bResult;
1152} 1138}
1153 1139
1154 1140
diff --git a/drivers/staging/vt6656/rf.h b/drivers/staging/vt6656/rf.h
index 72eb27ac436b..9f70cf740bae 100644
--- a/drivers/staging/vt6656/rf.h
+++ b/drivers/staging/vt6656/rf.h
@@ -60,25 +60,15 @@
60/*--------------------- Export Classes ----------------------------*/ 60/*--------------------- Export Classes ----------------------------*/
61 61
62/*--------------------- Export Variables --------------------------*/ 62/*--------------------- Export Variables --------------------------*/
63extern const BYTE RFaby11aChannelIndex[200]; 63extern const u8 RFaby11aChannelIndex[200];
64/*--------------------- Export Functions --------------------------*/ 64/*--------------------- Export Functions --------------------------*/
65 65
66BOOL IFRFbWriteEmbedded(PSDevice pDevice, DWORD dwData); 66int IFRFbWriteEmbedded(struct vnt_private *, u32 dwData);
67BOOL RFbSetPower(PSDevice pDevice, unsigned int uRATE, unsigned int uCH); 67int RFbSetPower(struct vnt_private *, u32 uRATE, u32 uCH);
68 68int RFbRawSetPower(struct vnt_private *, u8 byPwr, u32 uRATE);
69BOOL RFbRawSetPower( 69void RFvRSSITodBm(struct vnt_private *, u8 byCurrRSSI, long *pldBm);
70 PSDevice pDevice, 70void RFbRFTableDownload(struct vnt_private *pDevice);
71 BYTE byPwr, 71int s_bVT3226D0_11bLoCurrentAdjust(struct vnt_private *, u8 byChannel,
72 unsigned int uRATE 72 int b11bMode);
73 );
74
75void RFvRSSITodBm(PSDevice pDevice, BYTE byCurrRSSI, long *pldBm);
76void RFbRFTableDownload(PSDevice pDevice);
77
78BOOL s_bVT3226D0_11bLoCurrentAdjust(
79 PSDevice pDevice,
80 BYTE byChannel,
81 BOOL b11bMode
82 );
83 73
84#endif /* __RF_H__ */ 74#endif /* __RF_H__ */
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index 83c04e120935..b939dcf689d6 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -106,181 +106,71 @@ const WORD wFB_Opt1[2][5] = {
106 106
107/*--------------------- Static Functions --------------------------*/ 107/*--------------------- Static Functions --------------------------*/
108 108
109static 109static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
110void 110 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl);
111s_vSaveTxPktInfo( 111
112 PSDevice pDevice, 112static void *s_vGetFreeContext(struct vnt_private *pDevice);
113 BYTE byPktNum, 113
114 PBYTE pbyDestAddr, 114static void s_vGenerateTxParameter(struct vnt_private *pDevice,
115 WORD wPktLength, 115 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
116 WORD wFIFOCtl 116 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
117); 117 PSEthernetHeader psEthHeader);
118 118
119static 119static u32 s_uFillDataHead(struct vnt_private *pDevice,
120void * 120 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
121s_vGetFreeContext( 121 u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize,
122 PSDevice pDevice 122 u32 uMACfragNum, u8 byFBOption);
123 ); 123
124 124
125 125static void s_vGenerateMACHeader(struct vnt_private *pDevice,
126static 126 u8 *pbyBufferAddr, u16 wDuration, PSEthernetHeader psEthHeader,
127void 127 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx);
128s_vGenerateTxParameter( 128
129 PSDevice pDevice, 129static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
130 BYTE byPktType, 130 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf, u16 wPayloadLen,
131 WORD wCurrentRate, 131 u8 *pMICHDR);
132 void *pTxBufHead, 132
133 void *pvRrvTime, 133static void s_vSWencryption(struct vnt_private *pDevice,
134 void *pvRTS, 134 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize);
135 void *pvCTS, 135
136 unsigned int cbFrameSize, 136static unsigned int s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
137 BOOL bNeedACK, 137 u32 cbFrameLength, u16 wRate, int bNeedAck);
138 unsigned int uDMAIdx, 138
139 PSEthernetHeader psEthHeader 139static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice, u8 byRTSRsvType,
140 ); 140 u8 byPktType, u32 cbFrameLength, u16 wCurrentRate);
141 141
142 142static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
143static unsigned int s_uFillDataHead( 143 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
144 PSDevice pDevice, 144 int bDisCRC, u16 wCurrentRate, u8 byFBOption);
145 BYTE byPktType, 145
146 WORD wCurrentRate, 146static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
147 void *pTxDataHead, 147 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
148 unsigned int cbFrameLength, 148 PSEthernetHeader psEthHeader, u16 wCurrentRate, u8 byFBOption);
149 unsigned int uDMAIdx, 149
150 BOOL bNeedAck, 150static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
151 unsigned int uFragIdx, 151 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
152 unsigned int cbLastFragmentSize, 152 u32 uFragIdx, u32 cbLastFragmentSize, u32 uMACfragNum,
153 unsigned int uMACfragNum, 153 u8 byFBOption);
154 BYTE byFBOption 154
155 ); 155static unsigned int s_uGetRTSCTSDuration(struct vnt_private *pDevice,
156 156 u8 byDurType, u32 cbFrameLength, u8 byPktType, u16 wRate,
157 157 int bNeedAck, u8 byFBOption);
158
159
160static
161void
162s_vGenerateMACHeader (
163 PSDevice pDevice,
164 PBYTE pbyBufferAddr,
165 WORD wDuration,
166 PSEthernetHeader psEthHeader,
167 BOOL bNeedEncrypt,
168 WORD wFragType,
169 unsigned int uDMAIdx,
170 unsigned int uFragIdx
171 );
172
173static
174void
175s_vFillTxKey(
176 PSDevice pDevice,
177 PBYTE pbyBuf,
178 PBYTE pbyIVHead,
179 PSKeyItem pTransmitKey,
180 PBYTE pbyHdrBuf,
181 WORD wPayloadLen,
182 PBYTE pMICHDR
183 );
184
185static
186void
187s_vSWencryption (
188 PSDevice pDevice,
189 PSKeyItem pTransmitKey,
190 PBYTE pbyPayloadHead,
191 WORD wPayloadSize
192 );
193
194static unsigned int s_uGetTxRsvTime(
195 PSDevice pDevice,
196 BYTE byPktType,
197 unsigned int cbFrameLength,
198 WORD wRate,
199 BOOL bNeedAck
200 );
201
202
203static unsigned int s_uGetRTSCTSRsvTime(
204 PSDevice pDevice,
205 BYTE byRTSRsvType,
206 BYTE byPktType,
207 unsigned int cbFrameLength,
208 WORD wCurrentRate
209 );
210
211static
212void
213s_vFillCTSHead (
214 PSDevice pDevice,
215 unsigned int uDMAIdx,
216 BYTE byPktType,
217 void *pvCTS,
218 unsigned int cbFrameLength,
219 BOOL bNeedAck,
220 BOOL bDisCRC,
221 WORD wCurrentRate,
222 BYTE byFBOption
223 );
224
225static
226void
227s_vFillRTSHead(
228 PSDevice pDevice,
229 BYTE byPktType,
230 void *pvRTS,
231 unsigned int cbFrameLength,
232 BOOL bNeedAck,
233 BOOL bDisCRC,
234 PSEthernetHeader psEthHeader,
235 WORD wCurrentRate,
236 BYTE byFBOption
237 );
238
239static unsigned int s_uGetDataDuration(
240 PSDevice pDevice,
241 BYTE byDurType,
242 unsigned int cbFrameLength,
243 BYTE byPktType,
244 WORD wRate,
245 BOOL bNeedAck,
246 unsigned int uFragIdx,
247 unsigned int cbLastFragmentSize,
248 unsigned int uMACfragNum,
249 BYTE byFBOption
250 );
251
252
253static
254unsigned int
255s_uGetRTSCTSDuration (
256 PSDevice pDevice,
257 BYTE byDurType,
258 unsigned int cbFrameLength,
259 BYTE byPktType,
260 WORD wRate,
261 BOOL bNeedAck,
262 BYTE byFBOption
263 );
264 158
265 159
266/*--------------------- Export Variables --------------------------*/ 160/*--------------------- Export Variables --------------------------*/
267 161
268static 162static void *s_vGetFreeContext(struct vnt_private *pDevice)
269void *
270s_vGetFreeContext(
271 PSDevice pDevice
272 )
273{ 163{
274 PUSB_SEND_CONTEXT pContext = NULL; 164 PUSB_SEND_CONTEXT pContext = NULL;
275 PUSB_SEND_CONTEXT pReturnContext = NULL; 165 PUSB_SEND_CONTEXT pReturnContext = NULL;
276 unsigned int ii; 166 int ii;
277 167
278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n"); 168 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GetFreeContext()\n");
279 169
280 for (ii = 0; ii < pDevice->cbTD; ii++) { 170 for (ii = 0; ii < pDevice->cbTD; ii++) {
281 pContext = pDevice->apTD[ii]; 171 pContext = pDevice->apTD[ii];
282 if (pContext->bBoolInUse == FALSE) { 172 if (pContext->bBoolInUse == false) {
283 pContext->bBoolInUse = TRUE; 173 pContext->bBoolInUse = true;
284 pReturnContext = pContext; 174 pReturnContext = pContext;
285 break; 175 break;
286 } 176 }
@@ -292,11 +182,10 @@ s_vGetFreeContext(
292} 182}
293 183
294 184
295static 185static void s_vSaveTxPktInfo(struct vnt_private *pDevice, u8 byPktNum,
296void 186 u8 *pbyDestAddr, u16 wPktLength, u16 wFIFOCtl)
297s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLength, WORD wFIFOCtl)
298{ 187{
299 PSStatCounter pStatistic=&(pDevice->scStatistic); 188 PSStatCounter pStatistic = &pDevice->scStatistic;
300 189
301 if (is_broadcast_ether_addr(pbyDestAddr)) 190 if (is_broadcast_ether_addr(pbyDestAddr))
302 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD; 191 pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni = TX_PKT_BROAD;
@@ -312,24 +201,15 @@ s_vSaveTxPktInfo(PSDevice pDevice, BYTE byPktNum, PBYTE pbyDestAddr, WORD wPktLe
312 ETH_ALEN); 201 ETH_ALEN);
313} 202}
314 203
315static 204static void s_vFillTxKey(struct vnt_private *pDevice, u8 *pbyBuf,
316void 205 u8 *pbyIVHead, PSKeyItem pTransmitKey, u8 *pbyHdrBuf,
317s_vFillTxKey ( 206 u16 wPayloadLen, u8 *pMICHDR)
318 PSDevice pDevice,
319 PBYTE pbyBuf,
320 PBYTE pbyIVHead,
321 PSKeyItem pTransmitKey,
322 PBYTE pbyHdrBuf,
323 WORD wPayloadLen,
324 PBYTE pMICHDR
325 )
326{ 207{
327 PDWORD pdwIV = (PDWORD) pbyIVHead; 208 u32 *pdwIV = (u32 *)pbyIVHead;
328 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4); 209 u32 *pdwExtIV = (u32 *)((u8 *)pbyIVHead + 4);
329 WORD wValue; 210 u16 wValue;
330 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf; 211 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
331 DWORD dwRevIVCounter; 212 u32 dwRevIVCounter;
332
333 213
334 214
335 //Fill TXKEY 215 //Fill TXKEY
@@ -430,18 +310,12 @@ s_vFillTxKey (
430} 310}
431 311
432 312
433static 313static void s_vSWencryption(struct vnt_private *pDevice,
434void 314 PSKeyItem pTransmitKey, u8 *pbyPayloadHead, u16 wPayloadSize)
435s_vSWencryption (
436 PSDevice pDevice,
437 PSKeyItem pTransmitKey,
438 PBYTE pbyPayloadHead,
439 WORD wPayloadSize
440 )
441{ 315{
442 unsigned int cbICVlen = 4; 316 u32 cbICVlen = 4;
443 DWORD dwICV = 0xFFFFFFFFL; 317 u32 dwICV = 0xffffffff;
444 PDWORD pdwICV; 318 u32 *pdwICV;
445 319
446 if (pTransmitKey == NULL) 320 if (pTransmitKey == NULL)
447 return; 321 return;
@@ -479,17 +353,10 @@ s_vSWencryption (
479 PK_TYPE_11GB 2 353 PK_TYPE_11GB 2
480 PK_TYPE_11GA 3 354 PK_TYPE_11GA 3
481*/ 355*/
482static 356static u32 s_uGetTxRsvTime(struct vnt_private *pDevice, u8 byPktType,
483unsigned int 357 u32 cbFrameLength, u16 wRate, int bNeedAck)
484s_uGetTxRsvTime (
485 PSDevice pDevice,
486 BYTE byPktType,
487 unsigned int cbFrameLength,
488 WORD wRate,
489 BOOL bNeedAck
490 )
491{ 358{
492 unsigned int uDataTime, uAckTime; 359 u32 uDataTime, uAckTime;
493 360
494 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate); 361 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
495 if (byPktType == PK_TYPE_11B) {//llb,CCK mode 362 if (byPktType == PK_TYPE_11B) {//llb,CCK mode
@@ -507,17 +374,10 @@ s_uGetTxRsvTime (
507} 374}
508 375
509//byFreqType: 0=>5GHZ 1=>2.4GHZ 376//byFreqType: 0=>5GHZ 1=>2.4GHZ
510static 377static u32 s_uGetRTSCTSRsvTime(struct vnt_private *pDevice,
511unsigned int 378 u8 byRTSRsvType, u8 byPktType, u32 cbFrameLength, u16 wCurrentRate)
512s_uGetRTSCTSRsvTime (
513 PSDevice pDevice,
514 BYTE byRTSRsvType,
515 BYTE byPktType,
516 unsigned int cbFrameLength,
517 WORD wCurrentRate
518 )
519{ 379{
520 unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime; 380 u32 uRrvTime, uRTSTime, uCTSTime, uAckTime, uDataTime;
521 381
522 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0; 382 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
523 383
@@ -549,23 +409,13 @@ s_uGetRTSCTSRsvTime (
549} 409}
550 410
551//byFreqType 0: 5GHz, 1:2.4Ghz 411//byFreqType 0: 5GHz, 1:2.4Ghz
552static 412static u32 s_uGetDataDuration(struct vnt_private *pDevice, u8 byDurType,
553unsigned int 413 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
554s_uGetDataDuration ( 414 u32 uFragIdx, u32 cbLastFragmentSize, u32 uMACfragNum,
555 PSDevice pDevice, 415 u8 byFBOption)
556 BYTE byDurType,
557 unsigned int cbFrameLength,
558 BYTE byPktType,
559 WORD wRate,
560 BOOL bNeedAck,
561 unsigned int uFragIdx,
562 unsigned int cbLastFragmentSize,
563 unsigned int uMACfragNum,
564 BYTE byFBOption
565 )
566{ 416{
567 BOOL bLastFrag = 0; 417 int bLastFrag = 0;
568 unsigned int uAckTime = 0, uNextPktTime = 0; 418 u32 uAckTime = 0, uNextPktTime = 0;
569 419
570 if (uFragIdx == (uMACfragNum-1)) { 420 if (uFragIdx == (uMACfragNum-1)) {
571 bLastFrag = 1; 421 bLastFrag = 1;
@@ -712,25 +562,17 @@ s_uGetDataDuration (
712 break; 562 break;
713 } 563 }
714 564
715 ASSERT(FALSE); 565 ASSERT(false);
716 return 0; 566 return 0;
717} 567}
718 568
719 569
720//byFreqType: 0=>5GHZ 1=>2.4GHZ 570//byFreqType: 0=>5GHZ 1=>2.4GHZ
721static 571static u32 s_uGetRTSCTSDuration(struct vnt_private *pDevice, u8 byDurType,
722unsigned int 572 u32 cbFrameLength, u8 byPktType, u16 wRate, int bNeedAck,
723s_uGetRTSCTSDuration ( 573 u8 byFBOption)
724 PSDevice pDevice,
725 BYTE byDurType,
726 unsigned int cbFrameLength,
727 BYTE byPktType,
728 WORD wRate,
729 BOOL bNeedAck,
730 BYTE byFBOption
731 )
732{ 574{
733 unsigned int uCTSTime = 0, uDurTime = 0; 575 u32 uCTSTime = 0, uDurTime = 0;
734 576
735 577
736 switch (byDurType) { 578 switch (byDurType) {
@@ -814,24 +656,10 @@ s_uGetRTSCTSDuration (
814 656
815} 657}
816 658
817 659static u32 s_uFillDataHead(struct vnt_private *pDevice,
818 660 u8 byPktType, u16 wCurrentRate, void *pTxDataHead, u32 cbFrameLength,
819 661 u32 uDMAIdx, int bNeedAck, u32 uFragIdx, u32 cbLastFragmentSize,
820static 662 u32 uMACfragNum, u8 byFBOption)
821unsigned int
822s_uFillDataHead (
823 PSDevice pDevice,
824 BYTE byPktType,
825 WORD wCurrentRate,
826 void *pTxDataHead,
827 unsigned int cbFrameLength,
828 unsigned int uDMAIdx,
829 BOOL bNeedAck,
830 unsigned int uFragIdx,
831 unsigned int cbLastFragmentSize,
832 unsigned int uMACfragNum,
833 BYTE byFBOption
834 )
835{ 663{
836 664
837 if (pTxDataHead == NULL) { 665 if (pTxDataHead == NULL) {
@@ -959,25 +787,12 @@ s_uFillDataHead (
959 return 0; 787 return 0;
960} 788}
961 789
962 790static void s_vFillRTSHead(struct vnt_private *pDevice, u8 byPktType,
963 791 void *pvRTS, u32 cbFrameLength, int bNeedAck, int bDisCRC,
964 792 PSEthernetHeader psEthHeader, u16 wCurrentRate, u8 byFBOption)
965static
966void
967s_vFillRTSHead (
968 PSDevice pDevice,
969 BYTE byPktType,
970 void *pvRTS,
971 unsigned int cbFrameLength,
972 BOOL bNeedAck,
973 BOOL bDisCRC,
974 PSEthernetHeader psEthHeader,
975 WORD wCurrentRate,
976 BYTE byFBOption
977 )
978{ 793{
979 unsigned int uRTSFrameLen = 20; 794 u32 uRTSFrameLen = 20;
980 WORD wLen = 0x0000; 795 u16 wLen = 0;
981 796
982 if (pvRTS == NULL) 797 if (pvRTS == NULL)
983 return; 798 return;
@@ -1190,22 +1005,12 @@ s_vFillRTSHead (
1190 } 1005 }
1191} 1006}
1192 1007
1193static 1008static void s_vFillCTSHead(struct vnt_private *pDevice, u32 uDMAIdx,
1194void 1009 u8 byPktType, void *pvCTS, u32 cbFrameLength, int bNeedAck,
1195s_vFillCTSHead ( 1010 int bDisCRC, u16 wCurrentRate, u8 byFBOption)
1196 PSDevice pDevice,
1197 unsigned int uDMAIdx,
1198 BYTE byPktType,
1199 void *pvCTS,
1200 unsigned int cbFrameLength,
1201 BOOL bNeedAck,
1202 BOOL bDisCRC,
1203 WORD wCurrentRate,
1204 BYTE byFBOption
1205 )
1206{ 1011{
1207 unsigned int uCTSFrameLen = 14; 1012 u32 uCTSFrameLen = 14;
1208 WORD wLen = 0x0000; 1013 u16 wLen = 0;
1209 1014
1210 if (pvCTS == NULL) { 1015 if (pvCTS == NULL) {
1211 return; 1016 return;
@@ -1290,27 +1095,15 @@ s_vFillCTSHead (
1290 * 1095 *
1291-*/ 1096-*/
1292 1097
1293static 1098static void s_vGenerateTxParameter(struct vnt_private *pDevice,
1294void 1099 u8 byPktType, u16 wCurrentRate, void *pTxBufHead, void *pvRrvTime,
1295s_vGenerateTxParameter ( 1100 void *pvRTS, void *pvCTS, u32 cbFrameSize, int bNeedACK, u32 uDMAIdx,
1296 PSDevice pDevice, 1101 PSEthernetHeader psEthHeader)
1297 BYTE byPktType,
1298 WORD wCurrentRate,
1299 void *pTxBufHead,
1300 void *pvRrvTime,
1301 void *pvRTS,
1302 void *pvCTS,
1303 unsigned int cbFrameSize,
1304 BOOL bNeedACK,
1305 unsigned int uDMAIdx,
1306 PSEthernetHeader psEthHeader
1307 )
1308{ 1102{
1309 unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */ 1103 u32 cbMACHdLen = WLAN_HDR_ADDR3_LEN; /* 24 */
1310 WORD wFifoCtl; 1104 u16 wFifoCtl;
1311 BOOL bDisCRC = FALSE; 1105 int bDisCRC = false;
1312 BYTE byFBOption = AUTO_FB_NONE; 1106 u8 byFBOption = AUTO_FB_NONE;
1313// WORD wCurrentRate = pDevice->wCurrentRate;
1314 1107
1315 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n"); 1108 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1316 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead; 1109 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
@@ -1318,7 +1111,7 @@ s_vGenerateTxParameter (
1318 wFifoCtl = pFifoHead->wFIFOCtl; 1111 wFifoCtl = pFifoHead->wFIFOCtl;
1319 1112
1320 if (wFifoCtl & FIFOCTL_CRCDIS) { 1113 if (wFifoCtl & FIFOCTL_CRCDIS) {
1321 bDisCRC = TRUE; 1114 bDisCRC = true;
1322 } 1115 }
1323 1116
1324 if (wFifoCtl & FIFOCTL_AUTO_FB_0) { 1117 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
@@ -1407,55 +1200,40 @@ s_vGenerateTxParameter (
1407 unsigned int cbFragmentSize,//Hdr+payoad+FCS 1200 unsigned int cbFragmentSize,//Hdr+payoad+FCS
1408*/ 1201*/
1409 1202
1410 1203static int s_bPacketToWirelessUsb(struct vnt_private *pDevice, u8 byPktType,
1411BOOL 1204 u8 *usbPacketBuf, int bNeedEncryption, u32 uSkbPacketLen, u32 uDMAIdx,
1412s_bPacketToWirelessUsb( 1205 PSEthernetHeader psEthHeader, u8 *pPacket, PSKeyItem pTransmitKey,
1413 PSDevice pDevice, 1206 u32 uNodeIndex, u16 wCurrentRate, u32 *pcbHeaderLen, u32 *pcbTotalLen)
1414 BYTE byPktType,
1415 PBYTE usbPacketBuf,
1416 BOOL bNeedEncryption,
1417 unsigned int uSkbPacketLen,
1418 unsigned int uDMAIdx,
1419 PSEthernetHeader psEthHeader,
1420 PBYTE pPacket,
1421 PSKeyItem pTransmitKey,
1422 unsigned int uNodeIndex,
1423 WORD wCurrentRate,
1424 unsigned int *pcbHeaderLen,
1425 unsigned int *pcbTotalLen
1426 )
1427{ 1207{
1428 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 1208 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1429 unsigned int cbFrameSize, cbFrameBodySize; 1209 u32 cbFrameSize, cbFrameBodySize;
1430 PTX_BUFFER pTxBufHead; 1210 PTX_BUFFER pTxBufHead;
1431 unsigned int cb802_1_H_len; 1211 u32 cb802_1_H_len;
1432 unsigned int cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, 1212 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbMACHdLen = 0;
1433 cbMACHdLen = 0, cbFCSlen = 4; 1213 u32 cbFCSlen = 4, cbMICHDR = 0;
1434 unsigned int cbMICHDR = 0; 1214 int bNeedACK, bRTS;
1435 BOOL bNeedACK,bRTS; 1215 u8 *pbyType, *pbyMacHdr, *pbyIVHead, *pbyPayloadHead, *pbyTxBufferAddr;
1436 PBYTE pbyType,pbyMacHdr,pbyIVHead,pbyPayloadHead,pbyTxBufferAddr; 1216 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
1437 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00}; 1217 u8 abySNAP_Bridgetunnel[ETH_ALEN]
1438 BYTE abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8}; 1218 = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
1439 unsigned int uDuration; 1219 u32 uDuration;
1440 unsigned int cbHeaderLength = 0, uPadding = 0; 1220 u32 cbHeaderLength = 0, uPadding = 0;
1441 void *pvRrvTime; 1221 void *pvRrvTime;
1442 PSMICHDRHead pMICHDR; 1222 PSMICHDRHead pMICHDR;
1443 void *pvRTS; 1223 void *pvRTS;
1444 void *pvCTS; 1224 void *pvCTS;
1445 void *pvTxDataHd; 1225 void *pvTxDataHd;
1446 BYTE byFBOption = AUTO_FB_NONE,byFragType; 1226 u8 byFBOption = AUTO_FB_NONE, byFragType;
1447 WORD wTxBufSize; 1227 u16 wTxBufSize;
1448 DWORD dwMICKey0,dwMICKey1,dwMIC_Priority,dwCRC; 1228 u32 dwMICKey0, dwMICKey1, dwMIC_Priority, dwCRC;
1449 PDWORD pdwMIC_L,pdwMIC_R; 1229 u32 *pdwMIC_L, *pdwMIC_R;
1450 BOOL bSoftWEP = FALSE; 1230 int bSoftWEP = false;
1451 1231
1452 1232 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1453 1233
1454
1455 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1456 if (bNeedEncryption && pTransmitKey->pvKeyTable) { 1234 if (bNeedEncryption && pTransmitKey->pvKeyTable) {
1457 if (((PSKeyTable)&pTransmitKey->pvKeyTable)->bSoftWEP == TRUE) 1235 if (((PSKeyTable)pTransmitKey->pvKeyTable)->bSoftWEP == true)
1458 bSoftWEP = TRUE; /* WEP 256 */ 1236 bSoftWEP = true; /* WEP 256 */
1459 } 1237 }
1460 1238
1461 pTxBufHead = (PTX_BUFFER) usbPacketBuf; 1239 pTxBufHead = (PTX_BUFFER) usbPacketBuf;
@@ -1478,23 +1256,23 @@ s_bPacketToWirelessUsb(
1478 pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8); 1256 pTxBufHead->wFIFOCtl |= (WORD)(byPktType<<8);
1479 1257
1480 if (pDevice->dwDiagRefCount != 0) { 1258 if (pDevice->dwDiagRefCount != 0) {
1481 bNeedACK = FALSE; 1259 bNeedACK = false;
1482 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); 1260 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1483 } else { //if (pDevice->dwDiagRefCount != 0) { 1261 } else { //if (pDevice->dwDiagRefCount != 0) {
1484 if ((pDevice->eOPMode == OP_MODE_ADHOC) || 1262 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1485 (pDevice->eOPMode == OP_MODE_AP)) { 1263 (pDevice->eOPMode == OP_MODE_AP)) {
1486 if (is_multicast_ether_addr(psEthHeader->abyDstAddr)) { 1264 if (is_multicast_ether_addr(psEthHeader->abyDstAddr)) {
1487 bNeedACK = FALSE; 1265 bNeedACK = false;
1488 pTxBufHead->wFIFOCtl = 1266 pTxBufHead->wFIFOCtl =
1489 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); 1267 pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
1490 } else { 1268 } else {
1491 bNeedACK = TRUE; 1269 bNeedACK = true;
1492 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; 1270 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1493 } 1271 }
1494 } 1272 }
1495 else { 1273 else {
1496 // MSDUs in Infra mode always need ACK 1274 // MSDUs in Infra mode always need ACK
1497 bNeedACK = TRUE; 1275 bNeedACK = true;
1498 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; 1276 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1499 } 1277 }
1500 } //if (pDevice->dwDiagRefCount != 0) { 1278 } //if (pDevice->dwDiagRefCount != 0) {
@@ -1518,7 +1296,7 @@ s_bPacketToWirelessUsb(
1518 pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10); 1296 pTxBufHead->wFragCtl |= (WORD)(cbMACHdLen << 10);
1519 1297
1520 //Set FIFOCTL_GrpAckPolicy 1298 //Set FIFOCTL_GrpAckPolicy
1521 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000 1299 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
1522 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; 1300 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
1523 } 1301 }
1524 1302
@@ -1533,7 +1311,7 @@ s_bPacketToWirelessUsb(
1533 } 1311 }
1534 } 1312 }
1535 1313
1536 if (bSoftWEP != TRUE) { 1314 if (bSoftWEP != true) {
1537 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled 1315 if ((bNeedEncryption) && (pTransmitKey != NULL)) { //WEP enabled
1538 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104 1316 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
1539 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; 1317 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
@@ -1564,7 +1342,7 @@ s_bPacketToWirelessUsb(
1564 cbICVlen = 8;//MIC 1342 cbICVlen = 8;//MIC
1565 cbMICHDR = sizeof(SMICHDRHead); 1343 cbMICHDR = sizeof(SMICHDRHead);
1566 } 1344 }
1567 if (bSoftWEP == FALSE) { 1345 if (bSoftWEP == false) {
1568 //MAC Header should be padding 0 to DW alignment. 1346 //MAC Header should be padding 0 to DW alignment.
1569 uPadding = 4 - (cbMACHdLen%4); 1347 uPadding = 4 - (cbMACHdLen%4);
1570 uPadding %= 4; 1348 uPadding %= 4;
@@ -1573,10 +1351,10 @@ s_bPacketToWirelessUsb(
1573 1351
1574 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen; 1352 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1575 1353
1576 if ( (bNeedACK == FALSE) ||(cbFrameSize < pDevice->wRTSThreshold) ) { 1354 if ( (bNeedACK == false) ||(cbFrameSize < pDevice->wRTSThreshold) ) {
1577 bRTS = FALSE; 1355 bRTS = false;
1578 } else { 1356 } else {
1579 bRTS = TRUE; 1357 bRTS = true;
1580 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY); 1358 pTxBufHead->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1581 } 1359 }
1582 1360
@@ -1584,7 +1362,7 @@ s_bPacketToWirelessUsb(
1584 wTxBufSize = sizeof(STxBufHead); 1362 wTxBufSize = sizeof(STxBufHead);
1585 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet 1363 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
1586 if (byFBOption == AUTO_FB_NONE) { 1364 if (byFBOption == AUTO_FB_NONE) {
1587 if (bRTS == TRUE) {//RTS_need 1365 if (bRTS == true) {//RTS_need
1588 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize); 1366 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1589 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS)); 1367 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1590 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR); 1368 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
@@ -1602,7 +1380,7 @@ s_bPacketToWirelessUsb(
1602 } 1380 }
1603 } else { 1381 } else {
1604 // Auto Fall Back 1382 // Auto Fall Back
1605 if (bRTS == TRUE) {//RTS_need 1383 if (bRTS == true) {//RTS_need
1606 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize); 1384 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1607 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS)); 1385 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1608 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR); 1386 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
@@ -1610,7 +1388,7 @@ s_bPacketToWirelessUsb(
1610 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB)); 1388 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1611 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB); 1389 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1612 } 1390 }
1613 else if (bRTS == FALSE) { //RTS_needless 1391 else if (bRTS == false) { //RTS_needless
1614 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize); 1392 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1615 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS)); 1393 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1616 pvRTS = NULL; 1394 pvRTS = NULL;
@@ -1622,7 +1400,7 @@ s_bPacketToWirelessUsb(
1622 } 1400 }
1623 else {//802.11a/b packet 1401 else {//802.11a/b packet
1624 if (byFBOption == AUTO_FB_NONE) { 1402 if (byFBOption == AUTO_FB_NONE) {
1625 if (bRTS == TRUE) {//RTS_need 1403 if (bRTS == true) {//RTS_need
1626 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); 1404 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1627 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); 1405 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1628 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR); 1406 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
@@ -1630,7 +1408,7 @@ s_bPacketToWirelessUsb(
1630 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab)); 1408 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1631 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab); 1409 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1632 } 1410 }
1633 else if (bRTS == FALSE) { //RTS_needless, no MICHDR 1411 else if (bRTS == false) { //RTS_needless, no MICHDR
1634 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); 1412 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1635 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); 1413 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1636 pvRTS = NULL; 1414 pvRTS = NULL;
@@ -1640,7 +1418,7 @@ s_bPacketToWirelessUsb(
1640 } 1418 }
1641 } else { 1419 } else {
1642 // Auto Fall Back 1420 // Auto Fall Back
1643 if (bRTS == TRUE) {//RTS_need 1421 if (bRTS == true) {//RTS_need
1644 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); 1422 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1645 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); 1423 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1646 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR); 1424 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
@@ -1648,7 +1426,7 @@ s_bPacketToWirelessUsb(
1648 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB)); 1426 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1649 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB); 1427 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1650 } 1428 }
1651 else if (bRTS == FALSE) { //RTS_needless 1429 else if (bRTS == false) { //RTS_needless
1652 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize); 1430 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1653 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab)); 1431 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1654 pvRTS = NULL; 1432 pvRTS = NULL;
@@ -1684,7 +1462,7 @@ s_bPacketToWirelessUsb(
1684 s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption, 1462 s_vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncryption,
1685 byFragType, uDMAIdx, 0); 1463 byFragType, uDMAIdx, 0);
1686 1464
1687 if (bNeedEncryption == TRUE) { 1465 if (bNeedEncryption == true) {
1688 //Fill TXKEY 1466 //Fill TXKEY
1689 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey, 1467 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
1690 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR); 1468 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
@@ -1729,14 +1507,14 @@ s_bPacketToWirelessUsb(
1729 1507
1730 ASSERT(uLength == cbNdisBodySize); 1508 ASSERT(uLength == cbNdisBodySize);
1731 1509
1732 if ((bNeedEncryption == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) { 1510 if ((bNeedEncryption == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1733 1511
1734 /////////////////////////////////////////////////////////////////// 1512 ///////////////////////////////////////////////////////////////////
1735 1513
1736 if (pDevice->sMgmtObj.eAuthenMode == WMAC_AUTH_WPANONE) { 1514 if (pDevice->vnt_mgmt.eAuthenMode == WMAC_AUTH_WPANONE) {
1737 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]); 1515 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1738 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]); 1516 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1739 } 1517 }
1740 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) { 1518 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1741 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]); 1519 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1742 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]); 1520 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
@@ -1769,10 +1547,10 @@ s_bPacketToWirelessUsb(
1769 MIC_vGetMIC(pdwMIC_L, pdwMIC_R); 1547 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1770 MIC_vUnInit(); 1548 MIC_vUnInit();
1771 1549
1772 if (pDevice->bTxMICFail == TRUE) { 1550 if (pDevice->bTxMICFail == true) {
1773 *pdwMIC_L = 0; 1551 *pdwMIC_L = 0;
1774 *pdwMIC_R = 0; 1552 *pdwMIC_R = 0;
1775 pDevice->bTxMICFail = FALSE; 1553 pDevice->bTxMICFail = false;
1776 } 1554 }
1777 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); 1555 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
1778 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen); 1556 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
@@ -1780,17 +1558,17 @@ s_bPacketToWirelessUsb(
1780 } 1558 }
1781 1559
1782 1560
1783 if (bSoftWEP == TRUE) { 1561 if (bSoftWEP == true) {
1784 1562
1785 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen)); 1563 s_vSWencryption(pDevice, pTransmitKey, (pbyPayloadHead), (WORD)(cbFrameBodySize + cbMIClen));
1786 1564
1787 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == TRUE)) || 1565 } else if ( ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) && (bNeedEncryption == true)) ||
1788 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == TRUE)) || 1566 ((pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) && (bNeedEncryption == true)) ||
1789 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == TRUE)) ) { 1567 ((pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) && (bNeedEncryption == true)) ) {
1790 cbFrameSize -= cbICVlen; 1568 cbFrameSize -= cbICVlen;
1791 } 1569 }
1792 1570
1793 if (pDevice->bSoftwareGenCrcErr == TRUE) { 1571 if (pDevice->bSoftwareGenCrcErr == true) {
1794 unsigned int cbLen; 1572 unsigned int cbLen;
1795 PDWORD pdwCRC; 1573 PDWORD pdwCRC;
1796 1574
@@ -1815,7 +1593,7 @@ s_bPacketToWirelessUsb(
1815 pTxBufHead->wFragCtl |= (WORD)byFragType; 1593 pTxBufHead->wFragCtl |= (WORD)byFragType;
1816 1594
1817 1595
1818 return TRUE; 1596 return true;
1819 1597
1820} 1598}
1821 1599
@@ -1839,19 +1617,11 @@ s_bPacketToWirelessUsb(
1839 * 1617 *
1840-*/ 1618-*/
1841 1619
1842void 1620static void s_vGenerateMACHeader(struct vnt_private *pDevice,
1843s_vGenerateMACHeader ( 1621 u8 *pbyBufferAddr, u16 wDuration, PSEthernetHeader psEthHeader,
1844 PSDevice pDevice, 1622 int bNeedEncrypt, u16 wFragType, u32 uDMAIdx, u32 uFragIdx)
1845 PBYTE pbyBufferAddr,
1846 WORD wDuration,
1847 PSEthernetHeader psEthHeader,
1848 BOOL bNeedEncrypt,
1849 WORD wFragType,
1850 unsigned int uDMAIdx,
1851 unsigned int uFragIdx
1852 )
1853{ 1623{
1854 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr; 1624 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
1855 1625
1856 memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV))); 1626 memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
1857 1627
@@ -1936,43 +1706,29 @@ s_vGenerateMACHeader (
1936 * Out: 1706 * Out:
1937 * none 1707 * none
1938 * 1708 *
1939 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise FALSE 1709 * Return Value: CMD_STATUS_PENDING if MAC Tx resource available; otherwise false
1940 * 1710 *
1941-*/ 1711-*/
1942 1712
1943CMD_STATUS csMgmt_xmit( 1713CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice,
1944 PSDevice pDevice, 1714 struct vnt_tx_mgmt *pPacket)
1945 PSTxMgmtPacket pPacket
1946 )
1947{ 1715{
1948 BYTE byPktType; 1716 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1949 PBYTE pbyTxBufferAddr; 1717 PTX_BUFFER pTX_Buffer;
1950 void *pvRTS; 1718 PSTxBufHead pTxBufHead;
1951 PSCTS pCTS; 1719 PUSB_SEND_CONTEXT pContext;
1952 void *pvTxDataHd; 1720 PS802_11Header pMACHeader;
1953 unsigned int uDuration; 1721 PSCTS pCTS;
1954 unsigned int cbReqCount; 1722 SEthernetHeader sEthHeader;
1955 PS802_11Header pMACHeader; 1723 u8 byPktType, *pbyTxBufferAddr;
1956 unsigned int cbHeaderSize; 1724 void *pvRTS, *pvTxDataHd, *pvRrvTime, *pMICHDR;
1957 unsigned int cbFrameBodySize; 1725 u32 uDuration, cbReqCount, cbHeaderSize, cbFrameBodySize, cbFrameSize;
1958 BOOL bNeedACK; 1726 int bNeedACK, bIsPSPOLL = false;
1959 BOOL bIsPSPOLL = FALSE; 1727 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
1960 PSTxBufHead pTxBufHead; 1728 u32 uPadding = 0;
1961 unsigned int cbFrameSize; 1729 u16 wTxBufSize;
1962 unsigned int cbIVlen = 0; 1730 u32 cbMacHdLen;
1963 unsigned int cbICVlen = 0; 1731 u16 wCurrentRate = RATE_1M;
1964 unsigned int cbMIClen = 0;
1965 unsigned int cbFCSlen = 4;
1966 unsigned int uPadding = 0;
1967 WORD wTxBufSize;
1968 unsigned int cbMacHdLen;
1969 SEthernetHeader sEthHeader;
1970 void *pvRrvTime;
1971 void *pMICHDR;
1972 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1973 WORD wCurrentRate = RATE_1M;
1974 PTX_BUFFER pTX_Buffer;
1975 PUSB_SEND_CONTEXT pContext;
1976 1732
1977 1733
1978 1734
@@ -2028,10 +1784,10 @@ CMD_STATUS csMgmt_xmit(
2028 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); 1784 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2029 1785
2030 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) { 1786 if (is_multicast_ether_addr(pPacket->p80211Header->sA3.abyAddr1)) {
2031 bNeedACK = FALSE; 1787 bNeedACK = false;
2032 } 1788 }
2033 else { 1789 else {
2034 bNeedACK = TRUE; 1790 bNeedACK = true;
2035 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; 1791 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2036 }; 1792 };
2037 1793
@@ -2043,7 +1799,7 @@ CMD_STATUS csMgmt_xmit(
2043 //pDevice->byPreambleType = PREAMBLE_LONG; 1799 //pDevice->byPreambleType = PREAMBLE_LONG;
2044 // probe-response don't retry 1800 // probe-response don't retry
2045 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { 1801 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2046 // bNeedACK = FALSE; 1802 // bNeedACK = false;
2047 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); 1803 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2048 //} 1804 //}
2049 } 1805 }
@@ -2051,7 +1807,7 @@ CMD_STATUS csMgmt_xmit(
2051 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); 1807 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2052 1808
2053 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { 1809 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2054 bIsPSPOLL = TRUE; 1810 bIsPSPOLL = true;
2055 cbMacHdLen = WLAN_HDR_ADDR2_LEN; 1811 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2056 } else { 1812 } else {
2057 cbMacHdLen = WLAN_HDR_ADDR3_LEN; 1813 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
@@ -2063,7 +1819,7 @@ CMD_STATUS csMgmt_xmit(
2063 // Notes: 1819 // Notes:
2064 // Although spec says MMPDU can be fragmented; In most case, 1820 // Although spec says MMPDU can be fragmented; In most case,
2065 // no one will send a MMPDU under fragmentation. With RTS may occur. 1821 // no one will send a MMPDU under fragmentation. With RTS may occur.
2066 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP 1822 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2067 1823
2068 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { 1824 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2069 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) { 1825 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
@@ -2084,7 +1840,7 @@ CMD_STATUS csMgmt_xmit(
2084 cbIVlen = 8;//RSN Header 1840 cbIVlen = 8;//RSN Header
2085 cbICVlen = 8;//MIC 1841 cbICVlen = 8;//MIC
2086 pTxBufHead->wFragCtl |= FRAGCTL_AES; 1842 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2087 pDevice->bAES = TRUE; 1843 pDevice->bAES = true;
2088 } 1844 }
2089 //MAC Header should be padding 0 to DW alignment. 1845 //MAC Header should be padding 0 to DW alignment.
2090 uPadding = 4 - (cbMacHdLen%4); 1846 uPadding = 4 - (cbMacHdLen%4);
@@ -2094,7 +1850,7 @@ CMD_STATUS csMgmt_xmit(
2094 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen; 1850 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2095 1851
2096 //Set FIFOCTL_GrpAckPolicy 1852 //Set FIFOCTL_GrpAckPolicy
2097 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000 1853 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
2098 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; 1854 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2099 } 1855 }
2100 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() 1856 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
@@ -2155,12 +1911,12 @@ CMD_STATUS csMgmt_xmit(
2155 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen); 1911 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2156 do { 1912 do {
2157 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) && 1913 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2158 (pDevice->bLinkPass == TRUE)) { 1914 (pDevice->bLinkPass == true)) {
2159 pbyBSSID = pDevice->abyBSSID; 1915 pbyBSSID = pDevice->abyBSSID;
2160 // get pairwise key 1916 // get pairwise key
2161 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) { 1917 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2162 // get group key 1918 // get group key
2163 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) { 1919 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2164 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); 1920 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2165 break; 1921 break;
2166 } 1922 }
@@ -2171,13 +1927,13 @@ CMD_STATUS csMgmt_xmit(
2171 } 1927 }
2172 // get group key 1928 // get group key
2173 pbyBSSID = pDevice->abyBroadcastAddr; 1929 pbyBSSID = pDevice->abyBroadcastAddr;
2174 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) { 1930 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2175 pTransmitKey = NULL; 1931 pTransmitKey = NULL;
2176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode); 1932 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2177 } else { 1933 } else {
2178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n"); 1934 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2179 } 1935 }
2180 } while(FALSE); 1936 } while(false);
2181 //Fill TXKEY 1937 //Fill TXKEY
2182 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey, 1938 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2183 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL); 1939 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
@@ -2231,26 +1987,22 @@ CMD_STATUS csMgmt_xmit(
2231} 1987}
2232 1988
2233 1989
2234CMD_STATUS 1990CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice,
2235csBeacon_xmit( 1991 struct vnt_tx_mgmt *pPacket)
2236 PSDevice pDevice,
2237 PSTxMgmtPacket pPacket
2238 )
2239{ 1992{
2240 1993 u32 cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2241 unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN; 1994 u32 cbHeaderSize = 0;
2242 unsigned int cbHeaderSize = 0; 1995 u16 wTxBufSize = sizeof(STxShortBufHead);
2243 WORD wTxBufSize = sizeof(STxShortBufHead); 1996 PSTxShortBufHead pTxBufHead;
2244 PSTxShortBufHead pTxBufHead; 1997 PS802_11Header pMACHeader;
2245 PS802_11Header pMACHeader; 1998 PSTxDataHead_ab pTxDataHead;
2246 PSTxDataHead_ab pTxDataHead; 1999 u16 wCurrentRate;
2247 WORD wCurrentRate; 2000 u32 cbFrameBodySize;
2248 unsigned int cbFrameBodySize; 2001 u32 cbReqCount;
2249 unsigned int cbReqCount; 2002 PBEACON_BUFFER pTX_Buffer;
2250 PBEACON_BUFFER pTX_Buffer; 2003 u8 *pbyTxBufferAddr;
2251 PBYTE pbyTxBufferAddr; 2004 PUSB_SEND_CONTEXT pContext;
2252 PUSB_SEND_CONTEXT pContext; 2005 CMD_STATUS status;
2253 CMD_STATUS status;
2254 2006
2255 2007
2256 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice); 2008 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
@@ -2277,7 +2029,7 @@ csBeacon_xmit(
2277 ); 2029 );
2278 //Get Duration and TimeStampOff 2030 //Get Duration and TimeStampOff
2279 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A, 2031 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, PK_TYPE_11A,
2280 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE)); 2032 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
2281 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]; 2033 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2282 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab); 2034 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2283 } else { 2035 } else {
@@ -2290,7 +2042,7 @@ csBeacon_xmit(
2290 ); 2042 );
2291 //Get Duration and TimeStampOff 2043 //Get Duration and TimeStampOff
2292 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B, 2044 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, PK_TYPE_11B,
2293 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE)); 2045 wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
2294 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]; 2046 pTxDataHead->wTimeStampOff = wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE];
2295 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab); 2047 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2296 } 2048 }
@@ -2321,56 +2073,38 @@ csBeacon_xmit(
2321} 2073}
2322 2074
2323 2075
2324 2076void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb)
2325 2077{
2326 2078 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2327void 2079 u8 byPktType;
2328vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) { 2080 u8 *pbyTxBufferAddr;
2329 2081 void *pvRTS, *pvCTS, *pvTxDataHd;
2330 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 2082 u32 uDuration, cbReqCount;
2331 BYTE byPktType; 2083 PS802_11Header pMACHeader;
2332 PBYTE pbyTxBufferAddr; 2084 u32 cbHeaderSize, cbFrameBodySize;
2333 void *pvRTS; 2085 int bNeedACK, bIsPSPOLL = false;
2334 void *pvCTS; 2086 PSTxBufHead pTxBufHead;
2335 void *pvTxDataHd; 2087 u32 cbFrameSize;
2336 unsigned int uDuration; 2088 u32 cbIVlen = 0, cbICVlen = 0, cbMIClen = 0, cbFCSlen = 4;
2337 unsigned int cbReqCount; 2089 u32 uPadding = 0;
2338 PS802_11Header pMACHeader; 2090 u32 cbMICHDR = 0, uLength = 0;
2339 unsigned int cbHeaderSize; 2091 u32 dwMICKey0, dwMICKey1;
2340 unsigned int cbFrameBodySize; 2092 u32 dwMIC_Priority;
2341 BOOL bNeedACK; 2093 u32 *pdwMIC_L, *pdwMIC_R;
2342 BOOL bIsPSPOLL = FALSE; 2094 u16 wTxBufSize;
2343 PSTxBufHead pTxBufHead; 2095 u32 cbMacHdLen;
2344 unsigned int cbFrameSize; 2096 SEthernetHeader sEthHeader;
2345 unsigned int cbIVlen = 0; 2097 void *pvRrvTime, *pMICHDR;
2346 unsigned int cbICVlen = 0; 2098 u32 wCurrentRate = RATE_1M;
2347 unsigned int cbMIClen = 0; 2099 PUWLAN_80211HDR p80211Header;
2348 unsigned int cbFCSlen = 4; 2100 u32 uNodeIndex = 0;
2349 unsigned int uPadding = 0; 2101 int bNodeExist = false;
2350 unsigned int cbMICHDR = 0; 2102 SKeyItem STempKey;
2351 unsigned int uLength = 0; 2103 PSKeyItem pTransmitKey = NULL;
2352 DWORD dwMICKey0, dwMICKey1; 2104 u8 *pbyIVHead, *pbyPayloadHead, *pbyMacHdr;
2353 DWORD dwMIC_Priority; 2105 u32 cbExtSuppRate = 0;
2354 PDWORD pdwMIC_L; 2106 PTX_BUFFER pTX_Buffer;
2355 PDWORD pdwMIC_R; 2107 PUSB_SEND_CONTEXT pContext;
2356 WORD wTxBufSize;
2357 unsigned int cbMacHdLen;
2358 SEthernetHeader sEthHeader;
2359 void *pvRrvTime;
2360 void *pMICHDR;
2361 WORD wCurrentRate = RATE_1M;
2362 PUWLAN_80211HDR p80211Header;
2363 unsigned int uNodeIndex = 0;
2364 BOOL bNodeExist = FALSE;
2365 SKeyItem STempKey;
2366 PSKeyItem pTransmitKey = NULL;
2367 PBYTE pbyIVHead;
2368 PBYTE pbyPayloadHead;
2369 PBYTE pbyMacHdr;
2370 unsigned int cbExtSuppRate = 0;
2371 PTX_BUFFER pTX_Buffer;
2372 PUSB_SEND_CONTEXT pContext;
2373// PWLAN_IE pItem;
2374 2108
2375 2109
2376 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; 2110 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
@@ -2435,18 +2169,18 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2435 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); 2169 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2436 2170
2437 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) { 2171 if (is_multicast_ether_addr(p80211Header->sA3.abyAddr1)) {
2438 bNeedACK = FALSE; 2172 bNeedACK = false;
2439 if (pDevice->bEnableHostWEP) { 2173 if (pDevice->bEnableHostWEP) {
2440 uNodeIndex = 0; 2174 uNodeIndex = 0;
2441 bNodeExist = TRUE; 2175 bNodeExist = true;
2442 } 2176 }
2443 } 2177 }
2444 else { 2178 else {
2445 if (pDevice->bEnableHostWEP) { 2179 if (pDevice->bEnableHostWEP) {
2446 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex)) 2180 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2447 bNodeExist = TRUE; 2181 bNodeExist = true;
2448 } 2182 }
2449 bNeedACK = TRUE; 2183 bNeedACK = true;
2450 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK; 2184 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2451 }; 2185 };
2452 2186
@@ -2459,7 +2193,7 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2459 2193
2460 // probe-response don't retry 2194 // probe-response don't retry
2461 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) { 2195 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2462 // bNeedACK = FALSE; 2196 // bNeedACK = false;
2463 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK); 2197 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2464 //} 2198 //}
2465 } 2199 }
@@ -2467,7 +2201,7 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2467 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); 2201 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2468 2202
2469 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { 2203 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2470 bIsPSPOLL = TRUE; 2204 bIsPSPOLL = true;
2471 cbMacHdLen = WLAN_HDR_ADDR2_LEN; 2205 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2472 } else { 2206 } else {
2473 cbMacHdLen = WLAN_HDR_ADDR3_LEN; 2207 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
@@ -2496,7 +2230,7 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2496 // Notes: 2230 // Notes:
2497 // Although spec says MMPDU can be fragmented; In most case, 2231 // Although spec says MMPDU can be fragmented; In most case,
2498 // no one will send a MMPDU under fragmentation. With RTS may occur. 2232 // no one will send a MMPDU under fragmentation. With RTS may occur.
2499 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP 2233 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2500 2234
2501 2235
2502 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) { 2236 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
@@ -2519,7 +2253,7 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2519 cbICVlen = 8;//MIC 2253 cbICVlen = 8;//MIC
2520 cbMICHDR = sizeof(SMICHDRHead); 2254 cbMICHDR = sizeof(SMICHDRHead);
2521 pTxBufHead->wFragCtl |= FRAGCTL_AES; 2255 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2522 pDevice->bAES = TRUE; 2256 pDevice->bAES = true;
2523 } 2257 }
2524 //MAC Header should be padding 0 to DW alignment. 2258 //MAC Header should be padding 0 to DW alignment.
2525 uPadding = 4 - (cbMacHdLen%4); 2259 uPadding = 4 - (cbMacHdLen%4);
@@ -2529,7 +2263,7 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2529 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate; 2263 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
2530 2264
2531 //Set FIFOCTL_GrpAckPolicy 2265 //Set FIFOCTL_GrpAckPolicy
2532 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000 2266 if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
2533 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK; 2267 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2534 } 2268 }
2535 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() 2269 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
@@ -2646,10 +2380,10 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2646 MIC_vGetMIC(pdwMIC_L, pdwMIC_R); 2380 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2647 MIC_vUnInit(); 2381 MIC_vUnInit();
2648 2382
2649 if (pDevice->bTxMICFail == TRUE) { 2383 if (pDevice->bTxMICFail == true) {
2650 *pdwMIC_L = 0; 2384 *pdwMIC_L = 0;
2651 *pdwMIC_R = 0; 2385 *pdwMIC_R = 0;
2652 pDevice->bTxMICFail = FALSE; 2386 pDevice->bTxMICFail = false;
2653 } 2387 }
2654 2388
2655 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize); 2389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
@@ -2729,29 +2463,30 @@ vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb) {
2729 * Return Value: NULL 2463 * Return Value: NULL
2730 */ 2464 */
2731 2465
2732int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb) 2466int nsDMA_tx_packet(struct vnt_private *pDevice,
2467 u32 uDMAIdx, struct sk_buff *skb)
2733{ 2468{
2734 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 2469 struct net_device_stats *pStats = &pDevice->stats;
2735 unsigned int BytesToWrite = 0, uHeaderLen = 0; 2470 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2736 unsigned int uNodeIndex = 0; 2471 u32 BytesToWrite = 0, uHeaderLen = 0;
2737 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; 2472 u32 uNodeIndex = 0;
2738 WORD wAID; 2473 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2739 BYTE byPktType; 2474 u16 wAID;
2740 BOOL bNeedEncryption = FALSE; 2475 u8 byPktType;
2741 PSKeyItem pTransmitKey = NULL; 2476 int bNeedEncryption = false;
2742 SKeyItem STempKey; 2477 PSKeyItem pTransmitKey = NULL;
2743 unsigned int ii; 2478 SKeyItem STempKey;
2744 BOOL bTKIP_UseGTK = FALSE; 2479 int ii;
2745 BOOL bNeedDeAuth = FALSE; 2480 int bTKIP_UseGTK = false;
2746 PBYTE pbyBSSID; 2481 int bNeedDeAuth = false;
2747 BOOL bNodeExist = FALSE; 2482 u8 *pbyBSSID;
2748 PUSB_SEND_CONTEXT pContext; 2483 int bNodeExist = false;
2749 BOOL fConvertedPacket; 2484 PUSB_SEND_CONTEXT pContext;
2750 PTX_BUFFER pTX_Buffer; 2485 bool fConvertedPacket;
2751 unsigned int status; 2486 PTX_BUFFER pTX_Buffer;
2752 WORD wKeepRate = pDevice->wCurrentRate; 2487 u32 status;
2753 struct net_device_stats* pStats = &pDevice->stats; 2488 u16 wKeepRate = pDevice->wCurrentRate;
2754 BOOL bTxeapol_key = FALSE; 2489 int bTxeapol_key = false;
2755 2490
2756 2491
2757 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { 2492 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
@@ -2763,7 +2498,7 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2763 2498
2764 if (is_multicast_ether_addr((PBYTE)(skb->data))) { 2499 if (is_multicast_ether_addr((PBYTE)(skb->data))) {
2765 uNodeIndex = 0; 2500 uNodeIndex = 0;
2766 bNodeExist = TRUE; 2501 bNodeExist = true;
2767 if (pMgmt->sNodeDBTable[0].bPSEnable) { 2502 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2768 2503
2769 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb); 2504 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
@@ -2808,11 +2543,11 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2808 }else { 2543 }else {
2809 pDevice->byPreambleType = PREAMBLE_LONG; 2544 pDevice->byPreambleType = PREAMBLE_LONG;
2810 } 2545 }
2811 bNodeExist = TRUE; 2546 bNodeExist = true;
2812 } 2547 }
2813 } 2548 }
2814 2549
2815 if (bNodeExist == FALSE) { 2550 if (bNodeExist == false) {
2816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n"); 2551 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2817 dev_kfree_skb_irq(skb); 2552 dev_kfree_skb_irq(skb);
2818 return 0; 2553 return 0;
@@ -2844,22 +2579,22 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2844 /* 802.1x OR eapol-key challenge frame transfer */ 2579 /* 802.1x OR eapol-key challenge frame transfer */
2845 if (((Protocol_Version == 1) || (Protocol_Version == 2)) && 2580 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2846 (Packet_Type == 3)) { 2581 (Packet_Type == 3)) {
2847 bTxeapol_key = TRUE; 2582 bTxeapol_key = true;
2848 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge 2583 if(!(Key_info & BIT3) && //WPA or RSN group-key challenge
2849 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key 2584 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2850 if(Descriptor_type==254) { 2585 if(Descriptor_type==254) {
2851 pDevice->fWPA_Authened = TRUE; 2586 pDevice->fWPA_Authened = true;
2852 PRINT_K("WPA "); 2587 PRINT_K("WPA ");
2853 } 2588 }
2854 else { 2589 else {
2855 pDevice->fWPA_Authened = TRUE; 2590 pDevice->fWPA_Authened = true;
2856 PRINT_K("WPA2(re-keying) "); 2591 PRINT_K("WPA2(re-keying) ");
2857 } 2592 }
2858 PRINT_K("Authentication completed!!\n"); 2593 PRINT_K("Authentication completed!!\n");
2859 } 2594 }
2860 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge 2595 else if((Key_info & BIT3) && (Descriptor_type==2) && //RSN pairwise-key challenge
2861 (Key_info & BIT8) && (Key_info & BIT9)) { 2596 (Key_info & BIT8) && (Key_info & BIT9)) {
2862 pDevice->fWPA_Authened = TRUE; 2597 pDevice->fWPA_Authened = true;
2863 PRINT_K("WPA2 Authentication completed!!\n"); 2598 PRINT_K("WPA2 Authentication completed!!\n");
2864 } 2599 }
2865 } 2600 }
@@ -2867,18 +2602,18 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2867} 2602}
2868//mike add:station mode check eapol-key challenge<--- 2603//mike add:station mode check eapol-key challenge<---
2869 2604
2870 if (pDevice->bEncryptionEnable == TRUE) { 2605 if (pDevice->bEncryptionEnable == true) {
2871 bNeedEncryption = TRUE; 2606 bNeedEncryption = true;
2872 // get Transmit key 2607 // get Transmit key
2873 do { 2608 do {
2874 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && 2609 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2875 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { 2610 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2876 pbyBSSID = pDevice->abyBSSID; 2611 pbyBSSID = pDevice->abyBSSID;
2877 // get pairwise key 2612 // get pairwise key
2878 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) { 2613 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2879 // get group key 2614 // get group key
2880 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) { 2615 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2881 bTKIP_UseGTK = TRUE; 2616 bTKIP_UseGTK = true;
2882 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); 2617 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2883 break; 2618 break;
2884 } 2619 }
@@ -2895,12 +2630,12 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n"); 2630 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2896 2631
2897 // get pairwise key 2632 // get pairwise key
2898 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) 2633 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
2899 break; 2634 break;
2900 } 2635 }
2901 // get group key 2636 // get group key
2902 pbyBSSID = pDevice->abyBroadcastAddr; 2637 pbyBSSID = pDevice->abyBroadcastAddr;
2903 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) { 2638 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2904 pTransmitKey = NULL; 2639 pTransmitKey = NULL;
2905 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { 2640 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2906 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); 2641 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
@@ -2908,15 +2643,15 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
2908 else 2643 else
2909 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode); 2644 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pMgmt->eCurrMode);
2910 } else { 2645 } else {
2911 bTKIP_UseGTK = TRUE; 2646 bTKIP_UseGTK = true;
2912 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n"); 2647 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2913 } 2648 }
2914 } while(FALSE); 2649 } while(false);
2915 } 2650 }
2916 2651
2917 if (pDevice->bEnableHostWEP) { 2652 if (pDevice->bEnableHostWEP) {
2918 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex); 2653 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2919 if (pDevice->bEncryptionEnable == TRUE) { 2654 if (pDevice->bEncryptionEnable == true) {
2920 pTransmitKey = &STempKey; 2655 pTransmitKey = &STempKey;
2921 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite; 2656 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2922 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex; 2657 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
@@ -3015,23 +2750,23 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
3015 byPktType = PK_TYPE_11B; 2750 byPktType = PK_TYPE_11B;
3016 } 2751 }
3017 2752
3018 if (bNeedEncryption == TRUE) { 2753 if (bNeedEncryption == true) {
3019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType)); 2754 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
3020 if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) { 2755 if ((pDevice->sTxEthHeader.wType) == cpu_to_be16(ETH_P_PAE)) {
3021 bNeedEncryption = FALSE; 2756 bNeedEncryption = false;
3022 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType)); 2757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
3023 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { 2758 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
3024 if (pTransmitKey == NULL) { 2759 if (pTransmitKey == NULL) {
3025 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n"); 2760 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
3026 } 2761 }
3027 else { 2762 else {
3028 if (bTKIP_UseGTK == TRUE) { 2763 if (bTKIP_UseGTK == true) {
3029 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n"); 2764 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
3030 } 2765 }
3031 else { 2766 else {
3032 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", 2767 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
3033 pTransmitKey->dwKeyIndex); 2768 pTransmitKey->dwKeyIndex);
3034 bNeedEncryption = TRUE; 2769 bNeedEncryption = true;
3035 } 2770 }
3036 } 2771 }
3037 } 2772 }
@@ -3041,7 +2776,7 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
3041 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) { 2776 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
3042 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n", 2777 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%X]\n",
3043 pTransmitKey->dwKeyIndex); 2778 pTransmitKey->dwKeyIndex);
3044 bNeedEncryption = TRUE; 2779 bNeedEncryption = true;
3045 } 2780 }
3046 } 2781 }
3047 } 2782 }
@@ -3049,7 +2784,7 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
3049 2784
3050 if (pTransmitKey == NULL) { 2785 if (pTransmitKey == NULL) {
3051 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n"); 2786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
3052 pContext->bBoolInUse = FALSE; 2787 pContext->bBoolInUse = false;
3053 dev_kfree_skb_irq(skb); 2788 dev_kfree_skb_irq(skb);
3054 pStats->tx_dropped++; 2789 pStats->tx_dropped++;
3055 return STATUS_FAILURE; 2790 return STATUS_FAILURE;
@@ -3065,18 +2800,18 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
3065 &uHeaderLen, &BytesToWrite 2800 &uHeaderLen, &BytesToWrite
3066 ); 2801 );
3067 2802
3068 if (fConvertedPacket == FALSE) { 2803 if (fConvertedPacket == false) {
3069 pContext->bBoolInUse = FALSE; 2804 pContext->bBoolInUse = false;
3070 dev_kfree_skb_irq(skb); 2805 dev_kfree_skb_irq(skb);
3071 return STATUS_FAILURE; 2806 return STATUS_FAILURE;
3072 } 2807 }
3073 2808
3074 if ( pDevice->bEnablePSMode == TRUE ) { 2809 if ( pDevice->bEnablePSMode == true ) {
3075 if ( !pDevice->bPSModeTxBurst ) { 2810 if ( !pDevice->bPSModeTxBurst ) {
3076 bScheduleCommand((void *) pDevice, 2811 bScheduleCommand((void *) pDevice,
3077 WLAN_CMD_MAC_DISPOWERSAVING, 2812 WLAN_CMD_MAC_DISPOWERSAVING,
3078 NULL); 2813 NULL);
3079 pDevice->bPSModeTxBurst = TRUE; 2814 pDevice->bPSModeTxBurst = true;
3080 } 2815 }
3081 } 2816 }
3082 2817
@@ -3092,14 +2827,14 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
3092 2827
3093 status = PIPEnsSendBulkOut(pDevice,pContext); 2828 status = PIPEnsSendBulkOut(pDevice,pContext);
3094 2829
3095 if (bNeedDeAuth == TRUE) { 2830 if (bNeedDeAuth == true) {
3096 WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE; 2831 WORD wReason = WLAN_MGMT_REASON_MIC_FAILURE;
3097 2832
3098 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (PBYTE) &wReason); 2833 bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (PBYTE) &wReason);
3099 } 2834 }
3100 2835
3101 if(status!=STATUS_PENDING) { 2836 if(status!=STATUS_PENDING) {
3102 pContext->bBoolInUse = FALSE; 2837 pContext->bBoolInUse = false;
3103 dev_kfree_skb_irq(skb); 2838 dev_kfree_skb_irq(skb);
3104 return STATUS_FAILURE; 2839 return STATUS_FAILURE;
3105 } 2840 }
@@ -3120,49 +2855,43 @@ int nsDMA_tx_packet(PSDevice pDevice, unsigned int uDMAIdx, struct sk_buff *skb)
3120 * pPacket - Pointer to rx packet 2855 * pPacket - Pointer to rx packet
3121 * cbPacketSize - rx ethernet frame size 2856 * cbPacketSize - rx ethernet frame size
3122 * Out: 2857 * Out:
3123 * TURE, FALSE 2858 * TURE, false
3124 * 2859 *
3125 * Return Value: Return TRUE if packet is copy to dma1; otherwise FALSE 2860 * Return Value: Return true if packet is copy to dma1; otherwise false
3126 */ 2861 */
3127 2862
3128 2863int bRelayPacketSend(struct vnt_private *pDevice, u8 *pbySkbData, u32 uDataLen,
3129BOOL 2864 u32 uNodeIndex)
3130bRelayPacketSend (
3131 PSDevice pDevice,
3132 PBYTE pbySkbData,
3133 unsigned int uDataLen,
3134 unsigned int uNodeIndex
3135 )
3136{ 2865{
3137 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 2866 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
3138 unsigned int BytesToWrite = 0, uHeaderLen = 0; 2867 u32 BytesToWrite = 0, uHeaderLen = 0;
3139 BYTE byPktType = PK_TYPE_11B; 2868 u8 byPktType = PK_TYPE_11B;
3140 BOOL bNeedEncryption = FALSE; 2869 int bNeedEncryption = false;
3141 SKeyItem STempKey; 2870 SKeyItem STempKey;
3142 PSKeyItem pTransmitKey = NULL; 2871 PSKeyItem pTransmitKey = NULL;
3143 PBYTE pbyBSSID; 2872 u8 *pbyBSSID;
3144 PUSB_SEND_CONTEXT pContext; 2873 PUSB_SEND_CONTEXT pContext;
3145 BYTE byPktTyp; 2874 u8 byPktTyp;
3146 BOOL fConvertedPacket; 2875 int fConvertedPacket;
3147 PTX_BUFFER pTX_Buffer; 2876 PTX_BUFFER pTX_Buffer;
3148 unsigned int status; 2877 u32 status;
3149 WORD wKeepRate = pDevice->wCurrentRate; 2878 u16 wKeepRate = pDevice->wCurrentRate;
3150 2879
3151 2880
3152 2881
3153 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice); 2882 pContext = (PUSB_SEND_CONTEXT)s_vGetFreeContext(pDevice);
3154 2883
3155 if (NULL == pContext) { 2884 if (NULL == pContext) {
3156 return FALSE; 2885 return false;
3157 } 2886 }
3158 2887
3159 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN); 2888 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, ETH_HLEN);
3160 2889
3161 if (pDevice->bEncryptionEnable == TRUE) { 2890 if (pDevice->bEncryptionEnable == true) {
3162 bNeedEncryption = TRUE; 2891 bNeedEncryption = true;
3163 // get group key 2892 // get group key
3164 pbyBSSID = pDevice->abyBroadcastAddr; 2893 pbyBSSID = pDevice->abyBroadcastAddr;
3165 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) { 2894 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
3166 pTransmitKey = NULL; 2895 pTransmitKey = NULL;
3167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode); 2896 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pMgmt->eCurrMode);
3168 } else { 2897 } else {
@@ -3186,8 +2915,8 @@ bRelayPacketSend (
3186 } 2915 }
3187 2916
3188 if ( bNeedEncryption && (pTransmitKey == NULL) ) { 2917 if ( bNeedEncryption && (pTransmitKey == NULL) ) {
3189 pContext->bBoolInUse = FALSE; 2918 pContext->bBoolInUse = false;
3190 return FALSE; 2919 return false;
3191 } 2920 }
3192 2921
3193 byPktTyp = (BYTE)pDevice->byPacketType; 2922 byPktTyp = (BYTE)pDevice->byPacketType;
@@ -3235,9 +2964,9 @@ bRelayPacketSend (
3235 &uHeaderLen, &BytesToWrite 2964 &uHeaderLen, &BytesToWrite
3236 ); 2965 );
3237 2966
3238 if (fConvertedPacket == FALSE) { 2967 if (fConvertedPacket == false) {
3239 pContext->bBoolInUse = FALSE; 2968 pContext->bBoolInUse = false;
3240 return FALSE; 2969 return false;
3241 } 2970 }
3242 2971
3243 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]); 2972 pTX_Buffer = (PTX_BUFFER)&(pContext->Data[0]);
@@ -3252,6 +2981,6 @@ bRelayPacketSend (
3252 2981
3253 status = PIPEnsSendBulkOut(pDevice,pContext); 2982 status = PIPEnsSendBulkOut(pDevice,pContext);
3254 2983
3255 return TRUE; 2984 return true;
3256} 2985}
3257 2986
diff --git a/drivers/staging/vt6656/rxtx.h b/drivers/staging/vt6656/rxtx.h
index dd2198acc636..9f537022cdd1 100644
--- a/drivers/staging/vt6656/rxtx.h
+++ b/drivers/staging/vt6656/rxtx.h
@@ -665,30 +665,11 @@ typedef struct tagSBEACON_BUFFER
665 665
666/*--------------------- Export Functions --------------------------*/ 666/*--------------------- Export Functions --------------------------*/
667 667
668BOOL 668void vDMA0_tx_80211(struct vnt_private *, struct sk_buff *skb);
669bPacketToWirelessUsb( 669int nsDMA_tx_packet(struct vnt_private *, u32 uDMAIdx, struct sk_buff *skb);
670 PSDevice pDevice, 670CMD_STATUS csMgmt_xmit(struct vnt_private *, struct vnt_tx_mgmt *);
671 BYTE byPktType, 671CMD_STATUS csBeacon_xmit(struct vnt_private *, struct vnt_tx_mgmt *);
672 PBYTE usbPacketBuf, 672int bRelayPacketSend(struct vnt_private *, u8 *pbySkbData, u32 uDataLen,
673 BOOL bNeedEncrypt, 673 u32 uNodeIndex);
674 unsigned int cbPayloadSize,
675 unsigned int uDMAIdx,
676 PSEthernetHeader psEthHeader,
677 PBYTE pPacket,
678 PSKeyItem pTransmitKey,
679 unsigned int uNodeIndex,
680 WORD wCurrentRate,
681 unsigned int *pcbHeaderLen,
682 unsigned int *pcbTotalLen
683 );
684
685void vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb);
686int nsDMA_tx_packet(PSDevice pDevice,
687 unsigned int uDMAIdx,
688 struct sk_buff *skb);
689CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket);
690CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket);
691BOOL bRelayPacketSend(PSDevice pDevice, PBYTE pbySkbData,
692 unsigned int uDataLen, unsigned int uNodeIndex);
693 674
694#endif /* __RXTX_H__ */ 675#endif /* __RXTX_H__ */
diff --git a/drivers/staging/vt6656/tether.c b/drivers/staging/vt6656/tether.c
index 083b2153a271..95286c4d5572 100644
--- a/drivers/staging/vt6656/tether.c
+++ b/drivers/staging/vt6656/tether.c
@@ -93,16 +93,16 @@ BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr)
93 * Out: 93 * Out:
94 * none 94 * none
95 * 95 *
96 * Return Value: TRUE if ok; FALSE if error. 96 * Return Value: true if ok; false if error.
97 * 97 *
98 */ 98 */
99BOOL ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength) 99bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength)
100{ 100{
101 DWORD dwCRC; 101 DWORD dwCRC;
102 102
103 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4); 103 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
104 if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) 104 if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC)
105 return FALSE; 105 return false;
106 return TRUE; 106 return true;
107} 107}
108 108
diff --git a/drivers/staging/vt6656/tether.h b/drivers/staging/vt6656/tether.h
index 8c1f5d253f88..2f8f4853fd9d 100644
--- a/drivers/staging/vt6656/tether.h
+++ b/drivers/staging/vt6656/tether.h
@@ -161,6 +161,6 @@ S802_11Header, *PS802_11Header;
161 161
162BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr); 162BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr);
163//BYTE ETHbyGetHashIndexByCrc(PBYTE pbyMultiAddr); 163//BYTE ETHbyGetHashIndexByCrc(PBYTE pbyMultiAddr);
164BOOL ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength); 164bool ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, unsigned int cbFrameLength);
165 165
166#endif /* __TETHER_H__ */ 166#endif /* __TETHER_H__ */
diff --git a/drivers/staging/vt6656/ttype.h b/drivers/staging/vt6656/ttype.h
index dfbf74713a80..d7b648945316 100644
--- a/drivers/staging/vt6656/ttype.h
+++ b/drivers/staging/vt6656/ttype.h
@@ -33,33 +33,12 @@
33 33
34/******* Common definitions and typedefs ***********************************/ 34/******* Common definitions and typedefs ***********************************/
35 35
36typedef int BOOL;
37
38#if !defined(TRUE)
39#define TRUE 1
40#endif
41#if !defined(FALSE)
42#define FALSE 0
43#endif
44
45/****** Simple typedefs ***************************************************/ 36/****** Simple typedefs ***************************************************/
46 37
47typedef u8 BYTE; 38typedef u8 BYTE;
48typedef u16 WORD; 39typedef u16 WORD;
49typedef u32 DWORD; 40typedef u32 DWORD;
50 41
51// QWORD is for those situation that we want
52// an 8-byte-aligned 8 byte long structure
53// which is NOT really a floating point number.
54typedef union tagUQuadWord {
55 struct {
56 u32 dwLowDword;
57 u32 dwHighDword;
58 } u;
59 double DoNotUseThisField;
60} UQuadWord;
61typedef UQuadWord QWORD; // 64-bit
62
63/****** Common pointer types ***********************************************/ 42/****** Common pointer types ***********************************************/
64 43
65typedef u32 ULONG_PTR; 44typedef u32 ULONG_PTR;
@@ -73,6 +52,4 @@ typedef WORD * PWORD;
73 52
74typedef DWORD * PDWORD; 53typedef DWORD * PDWORD;
75 54
76typedef QWORD * PQWORD;
77
78#endif /* __TTYPE_H__ */ 55#endif /* __TTYPE_H__ */
diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
index fc68518526e0..00fd0f8a58c2 100644
--- a/drivers/staging/vt6656/usbpipe.c
+++ b/drivers/staging/vt6656/usbpipe.c
@@ -67,51 +67,18 @@ static int msglevel =MSG_LEVEL_INFO;
67/*--------------------- Static Variables --------------------------*/ 67/*--------------------- Static Variables --------------------------*/
68 68
69/*--------------------- Static Functions --------------------------*/ 69/*--------------------- Static Functions --------------------------*/
70static 70static void s_nsInterruptUsbIoCompleteRead(struct urb *urb);
71void 71static void s_nsBulkInUsbIoCompleteRead(struct urb *urb);
72s_nsInterruptUsbIoCompleteRead( 72static void s_nsBulkOutIoCompleteWrite(struct urb *urb);
73 struct urb *urb 73static void s_nsControlInUsbIoCompleteRead(struct urb *urb);
74 ); 74static void s_nsControlInUsbIoCompleteWrite(struct urb *urb);
75
76
77static
78void
79s_nsBulkInUsbIoCompleteRead(
80 struct urb *urb
81 );
82
83
84static
85void
86s_nsBulkOutIoCompleteWrite(
87 struct urb *urb
88 );
89
90
91static
92void
93s_nsControlInUsbIoCompleteRead(
94 struct urb *urb
95 );
96
97static
98void
99s_nsControlInUsbIoCompleteWrite(
100 struct urb *urb
101 );
102 75
103/*--------------------- Export Variables --------------------------*/ 76/*--------------------- Export Variables --------------------------*/
104 77
105/*--------------------- Export Functions --------------------------*/ 78/*--------------------- Export Functions --------------------------*/
106 79
107int PIPEnsControlOutAsyn( 80int PIPEnsControlOutAsyn(struct vnt_private *pDevice, u8 byRequest,
108 PSDevice pDevice, 81 u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer)
109 BYTE byRequest,
110 WORD wValue,
111 WORD wIndex,
112 WORD wLength,
113 PBYTE pbyBuffer
114 )
115{ 82{
116 int ntStatus; 83 int ntStatus;
117 84
@@ -147,17 +114,11 @@ int PIPEnsControlOutAsyn(
147 return ntStatus; 114 return ntStatus;
148} 115}
149 116
150int PIPEnsControlOut( 117int PIPEnsControlOut(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
151 PSDevice pDevice, 118 u16 wIndex, u16 wLength, u8 *pbyBuffer)
152 BYTE byRequest,
153 WORD wValue,
154 WORD wIndex,
155 WORD wLength,
156 PBYTE pbyBuffer
157 )
158{ 119{
159 int ntStatus = 0; 120 int ntStatus = 0;
160 int ii; 121 int ii;
161 122
162 if (pDevice->Flags & fMP_DISCONNECTED) 123 if (pDevice->Flags & fMP_DISCONNECTED)
163 return STATUS_FAILURE; 124 return STATUS_FAILURE;
@@ -165,6 +126,11 @@ int PIPEnsControlOut(
165 if (pDevice->Flags & fMP_CONTROL_WRITES) 126 if (pDevice->Flags & fMP_CONTROL_WRITES)
166 return STATUS_FAILURE; 127 return STATUS_FAILURE;
167 128
129 if (pDevice->Flags & fMP_CONTROL_READS)
130 return STATUS_FAILURE;
131
132 MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES);
133
168 pDevice->sUsbCtlRequest.bRequestType = 0x40; 134 pDevice->sUsbCtlRequest.bRequestType = 0x40;
169 pDevice->sUsbCtlRequest.bRequest = byRequest; 135 pDevice->sUsbCtlRequest.bRequest = byRequest;
170 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue); 136 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
@@ -179,12 +145,13 @@ int PIPEnsControlOut(
179 145
180 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC); 146 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
181 if (ntStatus != 0) { 147 if (ntStatus != 0) {
182 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control send request submission failed: %d\n", ntStatus); 148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
149 "control send request submission failed: %d\n",
150 ntStatus);
151 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
183 return STATUS_FAILURE; 152 return STATUS_FAILURE;
184 } 153 }
185 else { 154
186 MP_SET_FLAG(pDevice, fMP_CONTROL_WRITES);
187 }
188 spin_unlock_irq(&pDevice->lock); 155 spin_unlock_irq(&pDevice->lock);
189 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) { 156 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
190 157
@@ -206,17 +173,11 @@ int PIPEnsControlOut(
206 return STATUS_SUCCESS; 173 return STATUS_SUCCESS;
207} 174}
208 175
209int PIPEnsControlIn( 176int PIPEnsControlIn(struct vnt_private *pDevice, u8 byRequest, u16 wValue,
210 PSDevice pDevice, 177 u16 wIndex, u16 wLength, u8 *pbyBuffer)
211 BYTE byRequest,
212 WORD wValue,
213 WORD wIndex,
214 WORD wLength,
215 PBYTE pbyBuffer
216 )
217{ 178{
218 int ntStatus = 0; 179 int ntStatus = 0;
219 int ii; 180 int ii;
220 181
221 if (pDevice->Flags & fMP_DISCONNECTED) 182 if (pDevice->Flags & fMP_DISCONNECTED)
222 return STATUS_FAILURE; 183 return STATUS_FAILURE;
@@ -224,6 +185,11 @@ int PIPEnsControlIn(
224 if (pDevice->Flags & fMP_CONTROL_READS) 185 if (pDevice->Flags & fMP_CONTROL_READS)
225 return STATUS_FAILURE; 186 return STATUS_FAILURE;
226 187
188 if (pDevice->Flags & fMP_CONTROL_WRITES)
189 return STATUS_FAILURE;
190
191 MP_SET_FLAG(pDevice, fMP_CONTROL_READS);
192
227 pDevice->sUsbCtlRequest.bRequestType = 0xC0; 193 pDevice->sUsbCtlRequest.bRequestType = 0xC0;
228 pDevice->sUsbCtlRequest.bRequest = byRequest; 194 pDevice->sUsbCtlRequest.bRequest = byRequest;
229 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue); 195 pDevice->sUsbCtlRequest.wValue = cpu_to_le16p(&wValue);
@@ -237,10 +203,11 @@ int PIPEnsControlIn(
237 203
238 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC); 204 ntStatus = usb_submit_urb(pDevice->pControlURB, GFP_ATOMIC);
239 if (ntStatus != 0) { 205 if (ntStatus != 0) {
240 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"control request submission failed: %d\n", ntStatus); 206 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
241 }else { 207 "control request submission failed: %d\n", ntStatus);
242 MP_SET_FLAG(pDevice, fMP_CONTROL_READS); 208 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
243 } 209 return STATUS_FAILURE;
210 }
244 211
245 spin_unlock_irq(&pDevice->lock); 212 spin_unlock_irq(&pDevice->lock);
246 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) { 213 for (ii = 0; ii <= USB_CTL_WAIT; ii ++) {
@@ -263,13 +230,9 @@ int PIPEnsControlIn(
263 return ntStatus; 230 return ntStatus;
264} 231}
265 232
266static 233static void s_nsControlInUsbIoCompleteWrite(struct urb *urb)
267void
268s_nsControlInUsbIoCompleteWrite(
269 struct urb *urb
270 )
271{ 234{
272 PSDevice pDevice; 235 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
273 236
274 pDevice = urb->context; 237 pDevice = urb->context;
275 switch (urb->status) { 238 switch (urb->status) {
@@ -304,15 +267,11 @@ s_nsControlInUsbIoCompleteWrite(
304 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver 267 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
305 * 268 *
306 */ 269 */
307static 270
308void 271static void s_nsControlInUsbIoCompleteRead(struct urb *urb)
309s_nsControlInUsbIoCompleteRead(
310 struct urb *urb
311 )
312{ 272{
313 PSDevice pDevice; 273 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
314 274
315 pDevice = urb->context;
316 switch (urb->status) { 275 switch (urb->status) {
317 case 0: 276 case 0:
318 break; 277 break;
@@ -345,17 +304,18 @@ s_nsControlInUsbIoCompleteRead(
345 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver 304 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
346 * 305 *
347 */ 306 */
348int PIPEnsInterruptRead(PSDevice pDevice) 307
308int PIPEnsInterruptRead(struct vnt_private *pDevice)
349{ 309{
350 int ntStatus = STATUS_FAILURE; 310 int ntStatus = STATUS_FAILURE;
351 311
352 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n"); 312 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartInterruptUsbRead()\n");
353 313
354 if(pDevice->intBuf.bInUse == TRUE){ 314 if(pDevice->intBuf.bInUse == true){
355 return (STATUS_FAILURE); 315 return (STATUS_FAILURE);
356 } 316 }
357 pDevice->intBuf.bInUse = TRUE; 317 pDevice->intBuf.bInUse = true;
358// pDevice->bEventAvailable = FALSE; 318// pDevice->bEventAvailable = false;
359 pDevice->ulIntInPosted++; 319 pDevice->ulIntInPosted++;
360 320
361 // 321 //
@@ -396,21 +356,16 @@ usb_fill_bulk_urb(pDevice->pInterruptURB,
396 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver 356 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
397 * 357 *
398 */ 358 */
399static
400void
401s_nsInterruptUsbIoCompleteRead(
402 struct urb *urb
403 )
404 359
360static void s_nsInterruptUsbIoCompleteRead(struct urb *urb)
405{ 361{
406 PSDevice pDevice; 362 struct vnt_private *pDevice = (struct vnt_private *)urb->context;
407 int ntStatus; 363 int ntStatus;
408 364
409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptUsbIoCompleteRead\n"); 365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsInterruptUsbIoCompleteRead\n");
410 // 366 //
411 // The context given to IoSetCompletionRoutine is the receive buffer object 367 // The context given to IoSetCompletionRoutine is the receive buffer object
412 // 368 //
413 pDevice = (PSDevice)urb->context;
414 369
415 // 370 //
416 // We have a number of cases: 371 // We have a number of cases:
@@ -428,7 +383,7 @@ s_nsInterruptUsbIoCompleteRead(
428 // otherwise interrupt data handler will free int buffer after it handle it. 383 // otherwise interrupt data handler will free int buffer after it handle it.
429 if (( ntStatus != STATUS_SUCCESS )) { 384 if (( ntStatus != STATUS_SUCCESS )) {
430 pDevice->ulBulkInError++; 385 pDevice->ulBulkInError++;
431 pDevice->intBuf.bInUse = FALSE; 386 pDevice->intBuf.bInUse = false;
432 387
433// if (ntStatus == USBD_STATUS_CRC) { 388// if (ntStatus == USBD_STATUS_CRC) {
434// pDevice->ulIntInContCRCError++; 389// pDevice->ulIntInContCRCError++;
@@ -436,20 +391,20 @@ s_nsInterruptUsbIoCompleteRead(
436 391
437// if (ntStatus == STATUS_NOT_CONNECTED ) 392// if (ntStatus == STATUS_NOT_CONNECTED )
438// { 393// {
439 pDevice->fKillEventPollingThread = TRUE; 394 pDevice->fKillEventPollingThread = true;
440// } 395// }
441 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"IntUSBIoCompleteControl STATUS = %d\n", ntStatus ); 396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"IntUSBIoCompleteControl STATUS = %d\n", ntStatus );
442 } else { 397 } else {
443 pDevice->ulIntInBytesRead += (unsigned long) urb->actual_length; 398 pDevice->ulIntInBytesRead += (unsigned long) urb->actual_length;
444 pDevice->ulIntInContCRCError = 0; 399 pDevice->ulIntInContCRCError = 0;
445 pDevice->bEventAvailable = TRUE; 400 pDevice->bEventAvailable = true;
446 INTnsProcessData(pDevice); 401 INTnsProcessData(pDevice);
447 } 402 }
448 403
449 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_InterruptStat, ntStatus); 404 STAvUpdateUSBCounter(&pDevice->scStatistic.USB_InterruptStat, ntStatus);
450 405
451 406
452 if (pDevice->fKillEventPollingThread != TRUE) { 407 if (pDevice->fKillEventPollingThread != true) {
453 usb_fill_bulk_urb(pDevice->pInterruptURB, 408 usb_fill_bulk_urb(pDevice->pInterruptURB,
454 pDevice->usb, 409 pDevice->usb,
455 usb_rcvbulkpipe(pDevice->usb, 1), 410 usb_rcvbulkpipe(pDevice->usb, 1),
@@ -483,10 +438,11 @@ s_nsInterruptUsbIoCompleteRead(
483 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver 438 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
484 * 439 *
485 */ 440 */
486int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB) 441
442int PIPEnsBulkInUsbRead(struct vnt_private *pDevice, PRCB pRCB)
487{ 443{
488 int ntStatus = 0; 444 int ntStatus = 0;
489 struct urb *pUrb; 445 struct urb *pUrb;
490 446
491 447
492 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n"); 448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsStartBulkInUsbRead\n");
@@ -521,7 +477,7 @@ int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB)
521 return STATUS_FAILURE ; 477 return STATUS_FAILURE ;
522 } 478 }
523 pRCB->Ref = 1; 479 pRCB->Ref = 1;
524 pRCB->bBoolInUse= TRUE; 480 pRCB->bBoolInUse= true;
525 481
526 return ntStatus; 482 return ntStatus;
527} 483}
@@ -543,19 +499,15 @@ int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB)
543 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver 499 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
544 * 500 *
545 */ 501 */
546static
547void
548s_nsBulkInUsbIoCompleteRead(
549 struct urb *urb
550 )
551 502
503static void s_nsBulkInUsbIoCompleteRead(struct urb *urb)
552{ 504{
553 PRCB pRCB = (PRCB)urb->context; 505 PRCB pRCB = (PRCB)urb->context;
554 PSDevice pDevice = (PSDevice)pRCB->pDevice; 506 struct vnt_private *pDevice = pRCB->pDevice;
555 unsigned long bytesRead; 507 unsigned long bytesRead;
556 BOOL bIndicateReceive = FALSE; 508 int bIndicateReceive = false;
557 BOOL bReAllocSkb = FALSE; 509 int bReAllocSkb = false;
558 int status; 510 int status;
559 511
560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n"); 512 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkInUsbIoCompleteRead\n");
561 status = urb->status; 513 status = urb->status;
@@ -576,7 +528,7 @@ s_nsBulkInUsbIoCompleteRead(
576// } 528// }
577 } else { 529 } else {
578 if (bytesRead) 530 if (bytesRead)
579 bIndicateReceive = TRUE; 531 bIndicateReceive = true;
580 pDevice->ulBulkInContCRCError = 0; 532 pDevice->ulBulkInContCRCError = 0;
581 pDevice->ulBulkInBytesRead += bytesRead; 533 pDevice->ulBulkInBytesRead += bytesRead;
582 534
@@ -588,8 +540,8 @@ s_nsBulkInUsbIoCompleteRead(
588 540
589 if (bIndicateReceive) { 541 if (bIndicateReceive) {
590 spin_lock(&pDevice->lock); 542 spin_lock(&pDevice->lock);
591 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == TRUE) 543 if (RXbBulkInProcessData(pDevice, pRCB, bytesRead) == true)
592 bReAllocSkb = TRUE; 544 bReAllocSkb = true;
593 spin_unlock(&pDevice->lock); 545 spin_unlock(&pDevice->lock);
594 } 546 }
595 pRCB->Ref--; 547 pRCB->Ref--;
@@ -618,18 +570,15 @@ s_nsBulkInUsbIoCompleteRead(
618 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver 570 * Return Value: STATUS_INSUFFICIENT_RESOURCES or result of IoCallDriver
619 * 571 *
620 */ 572 */
621int 573
622PIPEnsSendBulkOut( 574int PIPEnsSendBulkOut(struct vnt_private *pDevice, PUSB_SEND_CONTEXT pContext)
623 PSDevice pDevice,
624 PUSB_SEND_CONTEXT pContext
625 )
626{ 575{
627 int status; 576 int status;
628 struct urb *pUrb; 577 struct urb *pUrb;
629 578
630 579
631 580
632 pDevice->bPWBitOn = FALSE; 581 pDevice->bPWBitOn = false;
633 582
634/* 583/*
635 if (pDevice->pPendingBulkOutContext != NULL) { 584 if (pDevice->pPendingBulkOutContext != NULL) {
@@ -661,13 +610,13 @@ PIPEnsSendBulkOut(
661 if (status != 0) 610 if (status != 0)
662 { 611 {
663 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status); 612 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Submit Tx URB failed %d\n", status);
664 pContext->bBoolInUse = FALSE; 613 pContext->bBoolInUse = false;
665 return STATUS_FAILURE; 614 return STATUS_FAILURE;
666 } 615 }
667 return STATUS_PENDING; 616 return STATUS_PENDING;
668 } 617 }
669 else { 618 else {
670 pContext->bBoolInUse = FALSE; 619 pContext->bBoolInUse = false;
671 return STATUS_RESOURCES; 620 return STATUS_RESOURCES;
672 } 621 }
673} 622}
@@ -699,17 +648,14 @@ PIPEnsSendBulkOut(
699 * (IofCompleteRequest) to stop working on the irp. 648 * (IofCompleteRequest) to stop working on the irp.
700 * 649 *
701 */ 650 */
702static 651
703void 652static void s_nsBulkOutIoCompleteWrite(struct urb *urb)
704s_nsBulkOutIoCompleteWrite(
705 struct urb *urb
706 )
707{ 653{
708 PSDevice pDevice; 654 struct vnt_private *pDevice;
709 int status; 655 int status;
710 CONTEXT_TYPE ContextType; 656 CONTEXT_TYPE ContextType;
711 unsigned long ulBufLen; 657 unsigned long ulBufLen;
712 PUSB_SEND_CONTEXT pContext; 658 PUSB_SEND_CONTEXT pContext;
713 659
714 660
715 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n"); 661 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->s_nsBulkOutIoCompleteWrite\n");
@@ -769,11 +715,11 @@ s_nsBulkOutIoCompleteWrite(
769 } 715 }
770 716
771 } 717 }
772 if (pDevice->bLinkPass == TRUE) { 718 if (pDevice->bLinkPass == true) {
773 if (netif_queue_stopped(pDevice->dev)) 719 if (netif_queue_stopped(pDevice->dev))
774 netif_wake_queue(pDevice->dev); 720 netif_wake_queue(pDevice->dev);
775 } 721 }
776 pContext->bBoolInUse = FALSE; 722 pContext->bBoolInUse = false;
777 723
778 return; 724 return;
779} 725}
diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h
index b3673474a9e1..b3023559c15b 100644
--- a/drivers/staging/vt6656/usbpipe.h
+++ b/drivers/staging/vt6656/usbpipe.h
@@ -41,35 +41,15 @@
41 41
42/*--------------------- Export Functions --------------------------*/ 42/*--------------------- Export Functions --------------------------*/
43 43
44int PIPEnsControlOut( 44int PIPEnsControlOut(struct vnt_private *, u8 byRequest, u16 wValue,
45 PSDevice pDevice, 45 u16 wIndex, u16 wLength, u8 *pbyBuffer);
46 BYTE byRequest, 46int PIPEnsControlOutAsyn(struct vnt_private *, u8 byRequest,
47 WORD wValue, 47 u16 wValue, u16 wIndex, u16 wLength, u8 *pbyBuffer);
48 WORD wIndex, 48int PIPEnsControlIn(struct vnt_private *, u8 byRequest, u16 wValue,
49 WORD wLength, 49 u16 wIndex, u16 wLength, u8 *pbyBuffer);
50 PBYTE pbyBuffer 50
51 ); 51int PIPEnsInterruptRead(struct vnt_private *);
52 52int PIPEnsBulkInUsbRead(struct vnt_private *, PRCB pRCB);
53int PIPEnsControlOutAsyn( 53int PIPEnsSendBulkOut(struct vnt_private *, PUSB_SEND_CONTEXT pContext);
54 PSDevice pDevice,
55 BYTE byRequest,
56 WORD wValue,
57 WORD wIndex,
58 WORD wLength,
59 PBYTE pbyBuffer
60 );
61
62int PIPEnsControlIn(
63 PSDevice pDevice,
64 BYTE byRequest,
65 WORD wValue,
66 WORD wIndex,
67 WORD wLength,
68 PBYTE pbyBuffer
69 );
70
71int PIPEnsInterruptRead(PSDevice pDevice);
72int PIPEnsBulkInUsbRead(PSDevice pDevice, PRCB pRCB);
73int PIPEnsSendBulkOut(PSDevice pDevice, PUSB_SEND_CONTEXT pContext);
74 54
75#endif /* __USBPIPE_H__ */ 55#endif /* __USBPIPE_H__ */
diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c
index 22f6b41cfd19..4bb652bf7cf6 100644
--- a/drivers/staging/vt6656/wcmd.c
+++ b/drivers/staging/vt6656/wcmd.c
@@ -68,33 +68,17 @@ static int msglevel =MSG_LEVEL_INFO;
68//static int msglevel =MSG_LEVEL_DEBUG; 68//static int msglevel =MSG_LEVEL_DEBUG;
69/*--------------------- Static Functions --------------------------*/ 69/*--------------------- Static Functions --------------------------*/
70 70
71static 71static void s_vProbeChannel(struct vnt_private *);
72void
73s_vProbeChannel(
74 PSDevice pDevice
75 );
76 72
73static struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *,
74 struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
75 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
77 76
78static
79PSTxMgmtPacket
80s_MgrMakeProbeRequest(
81 PSDevice pDevice,
82 PSMgmtObject pMgmt,
83 PBYTE pScanBSSID,
84 PWLAN_IE_SSID pSSID,
85 PWLAN_IE_SUPP_RATES pCurrRates,
86 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
87 );
88 77
78static int s_bCommandComplete(struct vnt_private *);
89 79
90static
91BOOL
92s_bCommandComplete (
93 PSDevice pDevice
94 );
95 80
96 81static int s_bClearBSSID_SCAN(struct vnt_private *);
97static BOOL s_bClearBSSID_SCAN(void *hDeviceContext);
98 82
99/*--------------------- Export Variables --------------------------*/ 83/*--------------------- Export Variables --------------------------*/
100 84
@@ -114,13 +98,10 @@ static BOOL s_bClearBSSID_SCAN(void *hDeviceContext);
114 * 98 *
115 */ 99 */
116 100
117static 101static void vAdHocBeaconStop(struct vnt_private *pDevice)
118void
119vAdHocBeaconStop(PSDevice pDevice)
120{ 102{
121 103 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
122 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 104 int bStop;
123 BOOL bStop;
124 105
125 /* 106 /*
126 * temporarily stop Beacon packet for AdHoc Server 107 * temporarily stop Beacon packet for AdHoc Server
@@ -133,18 +114,18 @@ vAdHocBeaconStop(PSDevice pDevice)
133 * or 114 * or
134 * (3.2) AdHoc channel is in A mode 115 * (3.2) AdHoc channel is in A mode
135 */ 116 */
136 bStop = FALSE; 117 bStop = false;
137 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && 118 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
138 (pMgmt->eCurrState >= WMAC_STATE_STARTED)) 119 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
139 { 120 {
140 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) && 121 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
141 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) 122 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
142 { 123 {
143 bStop = TRUE; 124 bStop = true;
144 } 125 }
145 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G) 126 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
146 { 127 {
147 bStop = TRUE; 128 bStop = true;
148 } 129 }
149 } 130 }
150 131
@@ -171,11 +152,9 @@ vAdHocBeaconStop(PSDevice pDevice)
171 * Return Value: none 152 * Return Value: none
172 * 153 *
173 */ 154 */
174static 155static void vAdHocBeaconRestart(struct vnt_private *pDevice)
175void
176vAdHocBeaconRestart(PSDevice pDevice)
177{ 156{
178 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 157 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
179 158
180 /* 159 /*
181 * Restart Beacon packet for AdHoc Server 160 * Restart Beacon packet for AdHoc Server
@@ -204,22 +183,22 @@ vAdHocBeaconRestart(PSDevice pDevice)
204 * 183 *
205-*/ 184-*/
206 185
207static 186static void s_vProbeChannel(struct vnt_private *pDevice)
208void
209s_vProbeChannel(
210 PSDevice pDevice
211 )
212{ 187{
213 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M 188 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
214 BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C}; 189 struct vnt_tx_mgmt *pTxPacket;
215 BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60}; 190 u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
216 //6M, 9M, 12M, 48M 191 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
217 BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; 192 /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
218 BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16}; 193 u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
219 PBYTE pbyRate; 194 4, 0x0C, 0x12, 0x18, 0x60};
220 PSTxMgmtPacket pTxPacket; 195 /* 6M, 9M, 12M, 48M*/
221 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 196 u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
222 unsigned int ii; 197 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
198 u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
199 4, 0x02, 0x04, 0x0B, 0x16};
200 u8 *pbyRate;
201 int ii;
223 202
224 203
225 if (pDevice->byBBType == BB_TYPE_11A) { 204 if (pDevice->byBBType == BB_TYPE_11A) {
@@ -268,24 +247,19 @@ s_vProbeChannel(
268-*/ 247-*/
269 248
270 249
271PSTxMgmtPacket 250struct vnt_tx_mgmt *s_MgrMakeProbeRequest(struct vnt_private *pDevice,
272s_MgrMakeProbeRequest( 251 struct vnt_manager *pMgmt, u8 *pScanBSSID, PWLAN_IE_SSID pSSID,
273 PSDevice pDevice, 252 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
274 PSMgmtObject pMgmt,
275 PBYTE pScanBSSID,
276 PWLAN_IE_SSID pSSID,
277 PWLAN_IE_SUPP_RATES pCurrRates,
278 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
279
280 )
281{ 253{
282 PSTxMgmtPacket pTxPacket = NULL; 254 struct vnt_tx_mgmt *pTxPacket = NULL;
283 WLAN_FR_PROBEREQ sFrame; 255 WLAN_FR_PROBEREQ sFrame;
284 256
285 257
286 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 258 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
287 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN); 259 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
288 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 260 + WLAN_PROBEREQ_FR_MAXLEN);
261 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
262 + sizeof(struct vnt_tx_mgmt));
289 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 263 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
290 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN; 264 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
291 vMgrEncodeProbeRequest(&sFrame); 265 vMgrEncodeProbeRequest(&sFrame);
@@ -316,9 +290,8 @@ s_MgrMakeProbeRequest(
316 return pTxPacket; 290 return pTxPacket;
317} 291}
318 292
319void vCommandTimerWait(void *hDeviceContext, unsigned long MSecond) 293void vCommandTimerWait(struct vnt_private *pDevice, unsigned long MSecond)
320{ 294{
321 PSDevice pDevice = (PSDevice)hDeviceContext;
322 295
323 init_timer(&pDevice->sTimerCommand); 296 init_timer(&pDevice->sTimerCommand);
324 297
@@ -331,23 +304,22 @@ void vCommandTimerWait(void *hDeviceContext, unsigned long MSecond)
331 return; 304 return;
332} 305}
333 306
334void vRunCommand(void *hDeviceContext) 307void vRunCommand(struct vnt_private *pDevice)
335{ 308{
336 PSDevice pDevice = (PSDevice)hDeviceContext; 309 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
337 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 310 PWLAN_IE_SSID pItemSSID;
338 PWLAN_IE_SSID pItemSSID; 311 PWLAN_IE_SSID pItemSSIDCurr;
339 PWLAN_IE_SSID pItemSSIDCurr; 312 CMD_STATUS Status;
340 CMD_STATUS Status; 313 struct sk_buff *skb;
341 unsigned int ii;
342 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
343 struct sk_buff *skb;
344 BYTE byData;
345 union iwreq_data wrqu; 314 union iwreq_data wrqu;
315 int ii;
316 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
317 u8 byData;
346 318
347 319
348 if (pDevice->dwDiagRefCount != 0) 320 if (pDevice->dwDiagRefCount != 0)
349 return; 321 return;
350 if (pDevice->bCmdRunning != TRUE) 322 if (pDevice->bCmdRunning != true)
351 return; 323 return;
352 324
353 spin_lock_irq(&pDevice->lock); 325 spin_lock_irq(&pDevice->lock);
@@ -357,7 +329,7 @@ void vRunCommand(void *hDeviceContext)
357 case WLAN_CMD_SCAN_START: 329 case WLAN_CMD_SCAN_START:
358 330
359 pDevice->byReAssocCount = 0; 331 pDevice->byReAssocCount = 0;
360 if (pDevice->bRadioOff == TRUE) { 332 if (pDevice->bRadioOff == true) {
361 s_bCommandComplete(pDevice); 333 s_bCommandComplete(pDevice);
362 spin_unlock_irq(&pDevice->lock); 334 spin_unlock_irq(&pDevice->lock);
363 return; 335 return;
@@ -385,7 +357,7 @@ void vRunCommand(void *hDeviceContext)
385 if (pDevice->bUpdateBBVGA) { 357 if (pDevice->bUpdateBBVGA) {
386 BBvSetShortSlotTime(pDevice); 358 BBvSetShortSlotTime(pDevice);
387 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent); 359 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
388 BBvUpdatePreEDThreshold(pDevice, FALSE); 360 BBvUpdatePreEDThreshold(pDevice, false);
389 } 361 }
390 // Set channel back 362 // Set channel back
391 vAdHocBeaconRestart(pDevice); 363 vAdHocBeaconRestart(pDevice);
@@ -397,7 +369,7 @@ void vRunCommand(void *hDeviceContext)
397 pDevice->byRxMode |= RCR_BSSID; 369 pDevice->byRxMode |= RCR_BSSID;
398 } 370 }
399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel); 371 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
400 pDevice->bStopDataPkt = FALSE; 372 pDevice->bStopDataPkt = false;
401 s_bCommandComplete(pDevice); 373 s_bCommandComplete(pDevice);
402 spin_unlock_irq(&pDevice->lock); 374 spin_unlock_irq(&pDevice->lock);
403 return; 375 return;
@@ -423,7 +395,7 @@ void vRunCommand(void *hDeviceContext)
423 pDevice->bLinkPass); */ 395 pDevice->bLinkPass); */
424 pMgmt->eScanState = WMAC_IS_SCANNING; 396 pMgmt->eScanState = WMAC_IS_SCANNING;
425 pDevice->byScanBBType = pDevice->byBBType; //lucas 397 pDevice->byScanBBType = pDevice->byBBType; //lucas
426 pDevice->bStopDataPkt = TRUE; 398 pDevice->bStopDataPkt = true;
427 // Turn off RCR_BSSID filter every time 399 // Turn off RCR_BSSID filter every time
428 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID); 400 MACvRegBitsOff(pDevice, MAC_REG_RCR, RCR_BSSID);
429 pDevice->byRxMode &= ~RCR_BSSID; 401 pDevice->byRxMode &= ~RCR_BSSID;
@@ -447,7 +419,7 @@ void vRunCommand(void *hDeviceContext)
447 if (pDevice->bUpdateBBVGA) { 419 if (pDevice->bUpdateBBVGA) {
448 BBvSetShortSlotTime(pDevice); 420 BBvSetShortSlotTime(pDevice);
449 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]); 421 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
450 BBvUpdatePreEDThreshold(pDevice, TRUE); 422 BBvUpdatePreEDThreshold(pDevice, true);
451 } 423 }
452 pMgmt->uScanChannel++; 424 pMgmt->uScanChannel++;
453 425
@@ -461,7 +433,7 @@ void vRunCommand(void *hDeviceContext)
461 pDevice->eCommandState = WLAN_CMD_SCAN_END; 433 pDevice->eCommandState = WLAN_CMD_SCAN_END;
462 434
463 } 435 }
464 if ((pMgmt->b11hEnable == FALSE) || 436 if ((pMgmt->b11hEnable == false) ||
465 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) { 437 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
466 s_vProbeChannel(pDevice); 438 s_vProbeChannel(pDevice);
467 spin_unlock_irq(&pDevice->lock); 439 spin_unlock_irq(&pDevice->lock);
@@ -488,7 +460,7 @@ void vRunCommand(void *hDeviceContext)
488 if (pDevice->bUpdateBBVGA) { 460 if (pDevice->bUpdateBBVGA) {
489 BBvSetShortSlotTime(pDevice); 461 BBvSetShortSlotTime(pDevice);
490 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent); 462 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
491 BBvUpdatePreEDThreshold(pDevice, FALSE); 463 BBvUpdatePreEDThreshold(pDevice, false);
492 } 464 }
493 465
494 // Set channel back 466 // Set channel back
@@ -502,7 +474,7 @@ void vRunCommand(void *hDeviceContext)
502 } 474 }
503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel); 475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
504 pMgmt->eScanState = WMAC_NO_SCANNING; 476 pMgmt->eScanState = WMAC_NO_SCANNING;
505 pDevice->bStopDataPkt = FALSE; 477 pDevice->bStopDataPkt = false;
506 478
507 /*send scan event to wpa_Supplicant*/ 479 /*send scan event to wpa_Supplicant*/
508 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n"); 480 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
@@ -521,12 +493,12 @@ void vRunCommand(void *hDeviceContext)
521 return; 493 return;
522 } else { 494 } else {
523 495
524 pDevice->bwextstep0 = FALSE; 496 pDevice->bwextstep0 = false;
525 pDevice->bwextstep1 = FALSE; 497 pDevice->bwextstep1 = false;
526 pDevice->bwextstep2 = FALSE; 498 pDevice->bwextstep2 = false;
527 pDevice->bwextstep3 = FALSE; 499 pDevice->bwextstep3 = false;
528 pDevice->bWPASuppWextEnabled = FALSE; 500 pDevice->bWPASuppWextEnabled = false;
529 pDevice->fWPA_Authened = FALSE; 501 pDevice->fWPA_Authened = false;
530 502
531 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n"); 503 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
532 // reason = 8 : disassoc because sta has left 504 // reason = 8 : disassoc because sta has left
@@ -535,18 +507,18 @@ void vRunCommand(void *hDeviceContext)
535 pMgmt->abyCurrBSSID, 507 pMgmt->abyCurrBSSID,
536 (8), 508 (8),
537 &Status); 509 &Status);
538 pDevice->bLinkPass = FALSE; 510 pDevice->bLinkPass = false;
539 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 511 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
540 // unlock command busy 512 // unlock command busy
541 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; 513 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
542 pItemSSID->len = 0; 514 pItemSSID->len = 0;
543 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN); 515 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
544 pMgmt->eCurrState = WMAC_STATE_IDLE; 516 pMgmt->eCurrState = WMAC_STATE_IDLE;
545 pMgmt->sNodeDBTable[0].bActive = FALSE; 517 pMgmt->sNodeDBTable[0].bActive = false;
546// pDevice->bBeaconBufReady = FALSE; 518// pDevice->bBeaconBufReady = false;
547 } 519 }
548 netif_stop_queue(pDevice->dev); 520 netif_stop_queue(pDevice->dev);
549 if (pDevice->bNeedRadioOFF == TRUE) 521 if (pDevice->bNeedRadioOFF == true)
550 CARDbRadioPowerOff(pDevice); 522 CARDbRadioPowerOff(pDevice);
551 s_bCommandComplete(pDevice); 523 s_bCommandComplete(pDevice);
552 break; 524 break;
@@ -555,7 +527,7 @@ void vRunCommand(void *hDeviceContext)
555 case WLAN_CMD_SSID_START: 527 case WLAN_CMD_SSID_START:
556 528
557 pDevice->byReAssocCount = 0; 529 pDevice->byReAssocCount = 0;
558 if (pDevice->bRadioOff == TRUE) { 530 if (pDevice->bRadioOff == true) {
559 s_bCommandComplete(pDevice); 531 s_bCommandComplete(pDevice);
560 spin_unlock_irq(&pDevice->lock); 532 spin_unlock_irq(&pDevice->lock);
561 return; 533 return;
@@ -588,7 +560,7 @@ void vRunCommand(void *hDeviceContext)
588 } 560 }
589 } 561 }
590 netif_stop_queue(pDevice->dev); 562 netif_stop_queue(pDevice->dev);
591 pDevice->bLinkPass = FALSE; 563 pDevice->bLinkPass = false;
592 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 564 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
593 } 565 }
594 // set initial state 566 // set initial state
@@ -625,9 +597,9 @@ void vRunCommand(void *hDeviceContext)
625 if (netif_queue_stopped(pDevice->dev)){ 597 if (netif_queue_stopped(pDevice->dev)){
626 netif_wake_queue(pDevice->dev); 598 netif_wake_queue(pDevice->dev);
627 } 599 }
628 pDevice->bLinkPass = TRUE; 600 pDevice->bLinkPass = true;
629 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); 601 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
630 pMgmt->sNodeDBTable[0].bActive = TRUE; 602 pMgmt->sNodeDBTable[0].bActive = true;
631 pMgmt->sNodeDBTable[0].uInActiveCount = 0; 603 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
632 } 604 }
633 else { 605 else {
@@ -658,7 +630,7 @@ void vRunCommand(void *hDeviceContext)
658 BSSvAddMulticastNode(pDevice); 630 BSSvAddMulticastNode(pDevice);
659 s_bClearBSSID_SCAN(pDevice); 631 s_bClearBSSID_SCAN(pDevice);
660/* 632/*
661 pDevice->bLinkPass = TRUE; 633 pDevice->bLinkPass = true;
662 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); 634 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
663 if (netif_queue_stopped(pDevice->dev)){ 635 if (netif_queue_stopped(pDevice->dev)){
664 netif_wake_queue(pDevice->dev); 636 netif_wake_queue(pDevice->dev);
@@ -668,7 +640,7 @@ void vRunCommand(void *hDeviceContext)
668 } 640 }
669 else { 641 else {
670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n"); 642 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
671 // if(pDevice->bWPASuppWextEnabled == TRUE) 643 // if(pDevice->bWPASuppWextEnabled == true)
672 { 644 {
673 union iwreq_data wrqu; 645 union iwreq_data wrqu;
674 memset(&wrqu, 0, sizeof (wrqu)); 646 memset(&wrqu, 0, sizeof (wrqu));
@@ -726,7 +698,7 @@ void vRunCommand(void *hDeviceContext)
726*/ 698*/
727 pDevice->byLinkWaitCount = 0; 699 pDevice->byLinkWaitCount = 0;
728 pDevice->byReAssocCount = 0; 700 pDevice->byReAssocCount = 0;
729 pDevice->bLinkPass = TRUE; 701 pDevice->bLinkPass = true;
730 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); 702 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
731 s_bClearBSSID_SCAN(pDevice); 703 s_bClearBSSID_SCAN(pDevice);
732 704
@@ -734,20 +706,20 @@ void vRunCommand(void *hDeviceContext)
734 netif_wake_queue(pDevice->dev); 706 netif_wake_queue(pDevice->dev);
735 } 707 }
736 708
737 if(pDevice->IsTxDataTrigger != FALSE) { //TxDataTimer is not triggered at the first time 709 if(pDevice->IsTxDataTrigger != false) { //TxDataTimer is not triggered at the first time
738 // printk("Re-initial TxDataTimer****\n"); 710 // printk("Re-initial TxDataTimer****\n");
739 del_timer(&pDevice->sTimerTxData); 711 del_timer(&pDevice->sTimerTxData);
740 init_timer(&pDevice->sTimerTxData); 712 init_timer(&pDevice->sTimerTxData);
741 pDevice->sTimerTxData.data = (unsigned long) pDevice; 713 pDevice->sTimerTxData.data = (unsigned long) pDevice;
742 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData; 714 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
743 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback 715 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
744 pDevice->fTxDataInSleep = FALSE; 716 pDevice->fTxDataInSleep = false;
745 pDevice->nTxDataTimeCout = 0; 717 pDevice->nTxDataTimeCout = 0;
746 } 718 }
747 else { 719 else {
748 // printk("mike:-->First time trigger TimerTxData InSleep\n"); 720 // printk("mike:-->First time trigger TimerTxData InSleep\n");
749 } 721 }
750 pDevice->IsTxDataTrigger = TRUE; 722 pDevice->IsTxDataTrigger = true;
751 add_timer(&pDevice->sTimerTxData); 723 add_timer(&pDevice->sTimerTxData);
752 724
753 } 725 }
@@ -773,15 +745,15 @@ void vRunCommand(void *hDeviceContext)
773 del_timer(&pMgmt->sTimerSecondCallback); 745 del_timer(&pMgmt->sTimerSecondCallback);
774 pMgmt->eCurrState = WMAC_STATE_IDLE; 746 pMgmt->eCurrState = WMAC_STATE_IDLE;
775 pMgmt->eCurrMode = WMAC_MODE_STANDBY; 747 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
776 pDevice->bLinkPass = FALSE; 748 pDevice->bLinkPass = false;
777 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 749 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
778 if (pDevice->bEnableHostWEP == TRUE) 750 if (pDevice->bEnableHostWEP == true)
779 BSSvClearNodeDBTable(pDevice, 1); 751 BSSvClearNodeDBTable(pDevice, 1);
780 else 752 else
781 BSSvClearNodeDBTable(pDevice, 0); 753 BSSvClearNodeDBTable(pDevice, 0);
782 pDevice->uAssocCount = 0; 754 pDevice->uAssocCount = 0;
783 pMgmt->eCurrState = WMAC_STATE_IDLE; 755 pMgmt->eCurrState = WMAC_STATE_IDLE;
784 pDevice->bFixRate = FALSE; 756 pDevice->bFixRate = false;
785 757
786 vMgrCreateOwnIBSS((void *) pDevice, &Status); 758 vMgrCreateOwnIBSS((void *) pDevice, &Status);
787 if (Status != CMD_STATUS_SUCCESS) { 759 if (Status != CMD_STATUS_SUCCESS) {
@@ -796,7 +768,7 @@ void vRunCommand(void *hDeviceContext)
796 if (netif_queue_stopped(pDevice->dev)){ 768 if (netif_queue_stopped(pDevice->dev)){
797 netif_wake_queue(pDevice->dev); 769 netif_wake_queue(pDevice->dev);
798 } 770 }
799 pDevice->bLinkPass = TRUE; 771 pDevice->bLinkPass = true;
800 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); 772 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
801 add_timer(&pMgmt->sTimerSecondCallback); 773 add_timer(&pMgmt->sTimerSecondCallback);
802 } 774 }
@@ -809,10 +781,10 @@ void vRunCommand(void *hDeviceContext)
809 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) { 781 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
810 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) { 782 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
811 pMgmt->abyPSTxMap[0] &= ~byMask[0]; 783 pMgmt->abyPSTxMap[0] &= ~byMask[0];
812 pDevice->bMoreData = FALSE; 784 pDevice->bMoreData = false;
813 } 785 }
814 else { 786 else {
815 pDevice->bMoreData = TRUE; 787 pDevice->bMoreData = true;
816 } 788 }
817 789
818 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) { 790 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
@@ -834,10 +806,10 @@ void vRunCommand(void *hDeviceContext)
834 // clear tx map 806 // clear tx map
835 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &= 807 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
836 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7]; 808 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
837 pDevice->bMoreData = FALSE; 809 pDevice->bMoreData = false;
838 } 810 }
839 else { 811 else {
840 pDevice->bMoreData = TRUE; 812 pDevice->bMoreData = true;
841 } 813 }
842 814
843 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) { 815 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) != 0) {
@@ -856,7 +828,7 @@ void vRunCommand(void *hDeviceContext)
856 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7]; 828 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
857 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii); 829 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
858 } 830 }
859 pMgmt->sNodeDBTable[ii].bRxPSPoll = FALSE; 831 pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
860 } 832 }
861 } 833 }
862 834
@@ -866,7 +838,7 @@ void vRunCommand(void *hDeviceContext)
866 case WLAN_CMD_RADIO_START: 838 case WLAN_CMD_RADIO_START:
867 839
868 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n"); 840 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
869 // if (pDevice->bRadioCmd == TRUE) 841 // if (pDevice->bRadioCmd == true)
870 // CARDbRadioPowerOn(pDevice); 842 // CARDbRadioPowerOn(pDevice);
871 // else 843 // else
872 // CARDbRadioPowerOff(pDevice); 844 // CARDbRadioPowerOff(pDevice);
@@ -894,31 +866,31 @@ void vRunCommand(void *hDeviceContext)
894 pDevice->cbFreeCmdQueue = CMD_Q_SIZE; 866 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
895 pDevice->uCmdDequeueIdx = 0; 867 pDevice->uCmdDequeueIdx = 0;
896 pDevice->uCmdEnqueueIdx = 0; 868 pDevice->uCmdEnqueueIdx = 0;
897 //0415pDevice->bCmdRunning = FALSE; 869 //0415pDevice->bCmdRunning = false;
898 pDevice->bCmdClear = TRUE; 870 pDevice->bCmdClear = true;
899 pDevice->bStopTx0Pkt = FALSE; 871 pDevice->bStopTx0Pkt = false;
900 pDevice->bStopDataPkt = TRUE; 872 pDevice->bStopDataPkt = true;
901 873
902 pDevice->byKeyIndex = 0; 874 pDevice->byKeyIndex = 0;
903 pDevice->bTransmitKey = FALSE; 875 pDevice->bTransmitKey = false;
904 spin_unlock_irq(&pDevice->lock); 876 spin_unlock_irq(&pDevice->lock);
905 KeyvInitTable(pDevice,&pDevice->sKey); 877 KeyvInitTable(pDevice,&pDevice->sKey);
906 spin_lock_irq(&pDevice->lock); 878 spin_lock_irq(&pDevice->lock);
907 pMgmt->byCSSPK = KEY_CTL_NONE; 879 pMgmt->byCSSPK = KEY_CTL_NONE;
908 pMgmt->byCSSGK = KEY_CTL_NONE; 880 pMgmt->byCSSGK = KEY_CTL_NONE;
909 881
910 if (pDevice->bLinkPass == TRUE) { 882 if (pDevice->bLinkPass == true) {
911 // reason = 8 : disassoc because sta has left 883 // reason = 8 : disassoc because sta has left
912 vMgrDisassocBeginSta((void *) pDevice, 884 vMgrDisassocBeginSta((void *) pDevice,
913 pMgmt, 885 pMgmt,
914 pMgmt->abyCurrBSSID, 886 pMgmt->abyCurrBSSID,
915 (8), 887 (8),
916 &Status); 888 &Status);
917 pDevice->bLinkPass = FALSE; 889 pDevice->bLinkPass = false;
918 // unlock command busy 890 // unlock command busy
919 pMgmt->eCurrState = WMAC_STATE_IDLE; 891 pMgmt->eCurrState = WMAC_STATE_IDLE;
920 pMgmt->sNodeDBTable[0].bActive = FALSE; 892 pMgmt->sNodeDBTable[0].bActive = false;
921 // if(pDevice->bWPASuppWextEnabled == TRUE) 893 // if(pDevice->bWPASuppWextEnabled == true)
922 { 894 {
923 union iwreq_data wrqu; 895 union iwreq_data wrqu;
924 memset(&wrqu, 0, sizeof (wrqu)); 896 memset(&wrqu, 0, sizeof (wrqu));
@@ -927,11 +899,11 @@ void vRunCommand(void *hDeviceContext)
927 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL); 899 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
928 } 900 }
929 } 901 }
930 pDevice->bwextstep0 = FALSE; 902 pDevice->bwextstep0 = false;
931 pDevice->bwextstep1 = FALSE; 903 pDevice->bwextstep1 = false;
932 pDevice->bwextstep2 = FALSE; 904 pDevice->bwextstep2 = false;
933 pDevice->bwextstep3 = FALSE; 905 pDevice->bwextstep3 = false;
934 pDevice->bWPASuppWextEnabled = FALSE; 906 pDevice->bWPASuppWextEnabled = false;
935 //clear current SSID 907 //clear current SSID
936 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; 908 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
937 pItemSSID->len = 0; 909 pItemSSID->len = 0;
@@ -945,10 +917,10 @@ void vRunCommand(void *hDeviceContext)
945 CARDbRadioPowerOff(pDevice); 917 CARDbRadioPowerOff(pDevice);
946 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); 918 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
947 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF); 919 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_OFF);
948 pDevice->bHWRadioOff = TRUE; 920 pDevice->bHWRadioOff = true;
949 } else { 921 } else {
950 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n"); 922 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_RADIO_START_ON........................\n");
951 pDevice->bHWRadioOff = FALSE; 923 pDevice->bHWRadioOff = false;
952 CARDbRadioPowerOn(pDevice); 924 CARDbRadioPowerOn(pDevice);
953 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD); 925 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
954 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON); 926 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_ON);
@@ -961,11 +933,11 @@ void vRunCommand(void *hDeviceContext)
961 933
962 case WLAN_CMD_CHANGE_BBSENSITIVITY_START: 934 case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
963 935
964 pDevice->bStopDataPkt = TRUE; 936 pDevice->bStopDataPkt = true;
965 pDevice->byBBVGACurrent = pDevice->byBBVGANew; 937 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
966 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent); 938 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
967 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent); 939 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
968 pDevice->bStopDataPkt = FALSE; 940 pDevice->bStopDataPkt = false;
969 s_bCommandComplete(pDevice); 941 s_bCommandComplete(pDevice);
970 break; 942 break;
971 943
@@ -990,13 +962,13 @@ void vRunCommand(void *hDeviceContext)
990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel); 962 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
991 if ( pDevice->dwRxAntennaSel == 0) { 963 if ( pDevice->dwRxAntennaSel == 0) {
992 pDevice->dwRxAntennaSel=1; 964 pDevice->dwRxAntennaSel=1;
993 if (pDevice->bTxRxAntInv == TRUE) 965 if (pDevice->bTxRxAntInv == true)
994 BBvSetAntennaMode(pDevice, ANT_RXA); 966 BBvSetAntennaMode(pDevice, ANT_RXA);
995 else 967 else
996 BBvSetAntennaMode(pDevice, ANT_RXB); 968 BBvSetAntennaMode(pDevice, ANT_RXB);
997 } else { 969 } else {
998 pDevice->dwRxAntennaSel=0; 970 pDevice->dwRxAntennaSel=0;
999 if (pDevice->bTxRxAntInv == TRUE) 971 if (pDevice->bTxRxAntInv == true)
1000 BBvSetAntennaMode(pDevice, ANT_RXB); 972 BBvSetAntennaMode(pDevice, ANT_RXB);
1001 else 973 else
1002 BBvSetAntennaMode(pDevice, ANT_RXA); 974 BBvSetAntennaMode(pDevice, ANT_RXA);
@@ -1027,9 +999,9 @@ void vRunCommand(void *hDeviceContext)
1027 999
1028 case WLAN_CMD_11H_CHSW_START: 1000 case WLAN_CMD_11H_CHSW_START:
1029 CARDbSetMediaChannel(pDevice, pDevice->byNewChannel); 1001 CARDbSetMediaChannel(pDevice, pDevice->byNewChannel);
1030 pDevice->bChannelSwitch = FALSE; 1002 pDevice->bChannelSwitch = false;
1031 pMgmt->uCurrChannel = pDevice->byNewChannel; 1003 pMgmt->uCurrChannel = pDevice->byNewChannel;
1032 pDevice->bStopDataPkt = FALSE; 1004 pDevice->bStopDataPkt = false;
1033 s_bCommandComplete(pDevice); 1005 s_bCommandComplete(pDevice);
1034 break; 1006 break;
1035 1007
@@ -1043,24 +1015,19 @@ void vRunCommand(void *hDeviceContext)
1043} 1015}
1044 1016
1045 1017
1046static 1018static int s_bCommandComplete(struct vnt_private *pDevice)
1047BOOL
1048s_bCommandComplete (
1049 PSDevice pDevice
1050 )
1051{ 1019{
1052 PWLAN_IE_SSID pSSID; 1020 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1053 BOOL bRadioCmd = FALSE; 1021 PWLAN_IE_SSID pSSID;
1054 //WORD wDeAuthenReason = 0; 1022 int bRadioCmd = false;
1055 BOOL bForceSCAN = TRUE; 1023 int bForceSCAN = true;
1056 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1057 1024
1058 1025
1059 pDevice->eCommandState = WLAN_CMD_IDLE; 1026 pDevice->eCommandState = WLAN_CMD_IDLE;
1060 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) { 1027 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
1061 //Command Queue Empty 1028 //Command Queue Empty
1062 pDevice->bCmdRunning = FALSE; 1029 pDevice->bCmdRunning = false;
1063 return TRUE; 1030 return true;
1064 } 1031 }
1065 else { 1032 else {
1066 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd; 1033 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
@@ -1069,7 +1036,7 @@ s_bCommandComplete (
1069 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN; 1036 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
1070 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE); 1037 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
1071 pDevice->cbFreeCmdQueue++; 1038 pDevice->cbFreeCmdQueue++;
1072 pDevice->bCmdRunning = TRUE; 1039 pDevice->bCmdRunning = true;
1073 switch ( pDevice->eCommand ) { 1040 switch ( pDevice->eCommand ) {
1074 case WLAN_CMD_BSSID_SCAN: 1041 case WLAN_CMD_BSSID_SCAN:
1075 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n"); 1042 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
@@ -1081,7 +1048,7 @@ s_bCommandComplete (
1081 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); 1048 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1082 } 1049 }
1083/* 1050/*
1084 if ((bForceSCAN == FALSE) && (pDevice->bLinkPass == TRUE)) { 1051 if ((bForceSCAN == false) && (pDevice->bLinkPass == true)) {
1085 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) && 1052 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
1086 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) { 1053 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
1087 pDevice->eCommandState = WLAN_CMD_IDLE; 1054 pDevice->eCommandState = WLAN_CMD_IDLE;
@@ -1146,29 +1113,26 @@ s_bCommandComplete (
1146 break; 1113 break;
1147 1114
1148 } 1115 }
1149 vCommandTimerWait((void *) pDevice, 0); 1116 vCommandTimerWait(pDevice, 0);
1150 } 1117 }
1151 1118
1152 return TRUE; 1119 return true;
1153} 1120}
1154 1121
1155BOOL bScheduleCommand(void *hDeviceContext, 1122int bScheduleCommand(struct vnt_private *pDevice,
1156 CMD_CODE eCommand, 1123 CMD_CODE eCommand, u8 *pbyItem0)
1157 PBYTE pbyItem0)
1158{ 1124{
1159 PSDevice pDevice = (PSDevice)hDeviceContext;
1160
1161 1125
1162 if (pDevice->cbFreeCmdQueue == 0) { 1126 if (pDevice->cbFreeCmdQueue == 0) {
1163 return (FALSE); 1127 return (false);
1164 } 1128 }
1165 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand; 1129 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1166 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = TRUE; 1130 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
1167 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); 1131 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1168 if (pbyItem0 != NULL) { 1132 if (pbyItem0 != NULL) {
1169 switch (eCommand) { 1133 switch (eCommand) {
1170 case WLAN_CMD_BSSID_SCAN: 1134 case WLAN_CMD_BSSID_SCAN:
1171 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = FALSE; 1135 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
1172 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 1136 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1173 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1); 1137 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1174 break; 1138 break;
@@ -1199,12 +1163,12 @@ BOOL bScheduleCommand(void *hDeviceContext,
1199 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE); 1163 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1200 pDevice->cbFreeCmdQueue--; 1164 pDevice->cbFreeCmdQueue--;
1201 1165
1202 if (pDevice->bCmdRunning == FALSE) { 1166 if (pDevice->bCmdRunning == false) {
1203 s_bCommandComplete(pDevice); 1167 s_bCommandComplete(pDevice);
1204 } 1168 }
1205 else { 1169 else {
1206 } 1170 }
1207 return (TRUE); 1171 return (true);
1208 1172
1209} 1173}
1210 1174
@@ -1219,14 +1183,13 @@ BOOL bScheduleCommand(void *hDeviceContext,
1219 * Out: 1183 * Out:
1220 * none 1184 * none
1221 * 1185 *
1222 * Return Value: TRUE if success; otherwise FALSE 1186 * Return Value: true if success; otherwise false
1223 * 1187 *
1224 */ 1188 */
1225static BOOL s_bClearBSSID_SCAN(void *hDeviceContext) 1189static int s_bClearBSSID_SCAN(struct vnt_private *pDevice)
1226{ 1190{
1227 PSDevice pDevice = (PSDevice)hDeviceContext; 1191 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1228 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx; 1192 unsigned int ii;
1229 unsigned int ii;
1230 1193
1231 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) { 1194 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1232 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) { 1195 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
@@ -1237,14 +1200,13 @@ static BOOL s_bClearBSSID_SCAN(void *hDeviceContext)
1237 break; 1200 break;
1238 } 1201 }
1239 } 1202 }
1240 return TRUE; 1203 return true;
1241} 1204}
1242 1205
1243 1206
1244//mike add:reset command timer 1207//mike add:reset command timer
1245void vResetCommandTimer(void *hDeviceContext) 1208void vResetCommandTimer(struct vnt_private *pDevice)
1246{ 1209{
1247 PSDevice pDevice = (PSDevice)hDeviceContext;
1248 1210
1249 //delete timer 1211 //delete timer
1250 del_timer(&pDevice->sTimerCommand); 1212 del_timer(&pDevice->sTimerCommand);
@@ -1257,14 +1219,13 @@ void vResetCommandTimer(void *hDeviceContext)
1257 pDevice->uCmdDequeueIdx = 0; 1219 pDevice->uCmdDequeueIdx = 0;
1258 pDevice->uCmdEnqueueIdx = 0; 1220 pDevice->uCmdEnqueueIdx = 0;
1259 pDevice->eCommandState = WLAN_CMD_IDLE; 1221 pDevice->eCommandState = WLAN_CMD_IDLE;
1260 pDevice->bCmdRunning = FALSE; 1222 pDevice->bCmdRunning = false;
1261 pDevice->bCmdClear = FALSE; 1223 pDevice->bCmdClear = false;
1262} 1224}
1263 1225
1264void BSSvSecondTxData(void *hDeviceContext) 1226void BSSvSecondTxData(struct vnt_private *pDevice)
1265{ 1227{
1266 PSDevice pDevice = (PSDevice)hDeviceContext; 1228 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1267 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1268 1229
1269 pDevice->nTxDataTimeCout++; 1230 pDevice->nTxDataTimeCout++;
1270 1231
@@ -1278,13 +1239,13 @@ void BSSvSecondTxData(void *hDeviceContext)
1278 1239
1279 spin_lock_irq(&pDevice->lock); 1240 spin_lock_irq(&pDevice->lock);
1280 //is wap_supplicant running successful OR only open && sharekey mode! 1241 //is wap_supplicant running successful OR only open && sharekey mode!
1281 if (((pDevice->bLinkPass == TRUE) && 1242 if (((pDevice->bLinkPass == true) &&
1282 (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking 1243 (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
1283 (pDevice->fWPA_Authened == TRUE)) { //wpa linking 1244 (pDevice->fWPA_Authened == true)) { //wpa linking
1284 // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__); 1245 // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
1285 pDevice->fTxDataInSleep = TRUE; 1246 pDevice->fTxDataInSleep = true;
1286 PSbSendNullPacket(pDevice); //send null packet 1247 PSbSendNullPacket(pDevice); //send null packet
1287 pDevice->fTxDataInSleep = FALSE; 1248 pDevice->fTxDataInSleep = false;
1288 } 1249 }
1289 spin_unlock_irq(&pDevice->lock); 1250 spin_unlock_irq(&pDevice->lock);
1290 1251
diff --git a/drivers/staging/vt6656/wcmd.h b/drivers/staging/vt6656/wcmd.h
index d24a79dce61a..c40e6baa0b5d 100644
--- a/drivers/staging/vt6656/wcmd.h
+++ b/drivers/staging/vt6656/wcmd.h
@@ -28,7 +28,6 @@
28 28
29#ifndef __WCMD_H__ 29#ifndef __WCMD_H__
30#define __WCMD_H__ 30#define __WCMD_H__
31
32#include "ttype.h" 31#include "ttype.h"
33#include "80211hdr.h" 32#include "80211hdr.h"
34#include "80211mgr.h" 33#include "80211mgr.h"
@@ -75,9 +74,9 @@ typedef enum tagCMD_STATUS {
75typedef struct tagCMD_ITEM { 74typedef struct tagCMD_ITEM {
76 CMD_CODE eCmd; 75 CMD_CODE eCmd;
77 BYTE abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1]; 76 BYTE abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
78 BOOL bNeedRadioOFF; 77 bool bNeedRadioOFF;
79 BOOL bRadioCmd; 78 bool bRadioCmd;
80 BOOL bForceSCAN; 79 bool bForceSCAN;
81 WORD wDeAuthenReason; 80 WORD wDeAuthenReason;
82} CMD_ITEM, *PCMD_ITEM; 81} CMD_ITEM, *PCMD_ITEM;
83 82
@@ -112,14 +111,13 @@ typedef enum tagCMD_STATE {
112/*--------------------- Export Types ------------------------------*/ 111/*--------------------- Export Types ------------------------------*/
113 112
114/*--------------------- Export Functions --------------------------*/ 113/*--------------------- Export Functions --------------------------*/
114struct vnt_private;
115 115
116void vResetCommandTimer(void *hDeviceContext); 116void vResetCommandTimer(struct vnt_private *);
117 117
118BOOL bScheduleCommand(void *hDeviceContext, 118int bScheduleCommand(struct vnt_private *, CMD_CODE eCommand, u8 *pbyItem0);
119 CMD_CODE eCommand,
120 PBYTE pbyItem0);
121 119
122void vRunCommand(void *hDeviceContext); 120void vRunCommand(struct vnt_private *);
123 121
124/* 122/*
125void 123void
@@ -128,6 +126,6 @@ WCMDvCommandThread(
128 ); 126 );
129*/ 127*/
130 128
131void BSSvSecondTxData(void *hDeviceContext); 129void BSSvSecondTxData(struct vnt_private *);
132 130
133#endif /* __WCMD_H__ */ 131#endif /* __WCMD_H__ */
diff --git a/drivers/staging/vt6656/wctl.c b/drivers/staging/vt6656/wctl.c
index 9249263b2da8..baa48a1f0d36 100644
--- a/drivers/staging/vt6656/wctl.c
+++ b/drivers/staging/vt6656/wctl.c
@@ -53,8 +53,8 @@
53 53
54/* 54/*
55 * Description: 55 * Description:
56 * Scan Rx cache. Return TRUE if packet is duplicate, else 56 * Scan Rx cache. Return true if packet is duplicate, else
57 * inserts in receive cache and returns FALSE. 57 * inserts in receive cache and returns false.
58 * 58 *
59 * Parameters: 59 * Parameters:
60 * In: 60 * In:
@@ -63,11 +63,11 @@
63 * Out: 63 * Out:
64 * none 64 * none
65 * 65 *
66 * Return Value: TRUE if packet duplicate; otherwise FALSE 66 * Return Value: true if packet duplicate; otherwise false
67 * 67 *
68 */ 68 */
69 69
70BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader) 70bool WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
71{ 71{
72 unsigned int uIndex; 72 unsigned int uIndex;
73 unsigned int ii; 73 unsigned int ii;
@@ -84,7 +84,7 @@ BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
84 (LOBYTE(pCacheEntry->wFrameCtl) == LOBYTE(pMACHeader->wFrameCtl)) 84 (LOBYTE(pCacheEntry->wFrameCtl) == LOBYTE(pMACHeader->wFrameCtl))
85 ) { 85 ) {
86 /* Duplicate match */ 86 /* Duplicate match */
87 return TRUE; 87 return true;
88 } 88 }
89 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH); 89 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
90 } 90 }
@@ -95,7 +95,7 @@ BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
95 memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN); 95 memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
96 pCacheEntry->wFrameCtl = pMACHeader->wFrameCtl; 96 pCacheEntry->wFrameCtl = pMACHeader->wFrameCtl;
97 ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH); 97 ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
98 return FALSE; 98 return false;
99} 99}
100 100
101/* 101/*
@@ -113,12 +113,13 @@ BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
113 * 113 *
114 */ 114 */
115 115
116unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader) 116unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice,
117 PS802_11Header pMACHeader)
117{ 118{
118 unsigned int ii; 119 unsigned int ii;
119 120
120 for (ii = 0; ii < pDevice->cbDFCB; ii++) { 121 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
121 if ((pDevice->sRxDFCB[ii].bInUse == TRUE) && 122 if ((pDevice->sRxDFCB[ii].bInUse == true) &&
122 (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]), 123 (!compare_ether_addr(&(pDevice->sRxDFCB[ii].abyAddr2[0]),
123 &(pMACHeader->abyAddr2[0])))) { 124 &(pMACHeader->abyAddr2[0])))) {
124 return ii; 125 return ii;
@@ -141,17 +142,18 @@ unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader)
141 * Return Value: index number in Defragment Database 142 * Return Value: index number in Defragment Database
142 * 143 *
143 */ 144 */
144unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader) 145unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice,
146 PS802_11Header pMACHeader)
145{ 147{
146 unsigned int ii; 148 unsigned int ii;
147 149
148 if (pDevice->cbFreeDFCB == 0) 150 if (pDevice->cbFreeDFCB == 0)
149 return(pDevice->cbDFCB); 151 return(pDevice->cbDFCB);
150 for (ii = 0; ii < pDevice->cbDFCB; ii++) { 152 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
151 if (pDevice->sRxDFCB[ii].bInUse == FALSE) { 153 if (pDevice->sRxDFCB[ii].bInUse == false) {
152 pDevice->cbFreeDFCB--; 154 pDevice->cbFreeDFCB--;
153 pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime; 155 pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
154 pDevice->sRxDFCB[ii].bInUse = TRUE; 156 pDevice->sRxDFCB[ii].bInUse = true;
155 pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4); 157 pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
156 pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F); 158 pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
157 memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), 159 memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]),
@@ -177,16 +179,16 @@ unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader)
177 * Out: 179 * Out:
178 * none 180 * none
179 * 181 *
180 * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE 182 * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false
181 * 183 *
182 */ 184 */
183BOOL WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, 185bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader,
184 unsigned int cbFrameLength, BOOL bWEP, BOOL bExtIV) 186 unsigned int cbFrameLength, bool bWEP, bool bExtIV)
185{ 187{
186unsigned int uHeaderSize; 188 unsigned int uHeaderSize;
187 189
188 190
189 if (bWEP == TRUE) { 191 if (bWEP == true) {
190 uHeaderSize = 28; 192 uHeaderSize = 28;
191 if (bExtIV) 193 if (bExtIV)
192 // ExtIV 194 // ExtIV
@@ -207,7 +209,7 @@ unsigned int uHeaderSize;
207 else { 209 else {
208 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader); 210 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
209 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) { 211 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
210 return(FALSE); 212 return(false);
211 } 213 }
212 } 214 }
213 // reserve 8 byte to match MAC RX Buffer 215 // reserve 8 byte to match MAC RX Buffer
@@ -218,7 +220,7 @@ unsigned int uHeaderSize;
218 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength; 220 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
219 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++; 221 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
220 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); 222 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
221 return(FALSE); 223 return(false);
222 } 224 }
223 else { 225 else {
224 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader); 226 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
@@ -236,21 +238,21 @@ unsigned int uHeaderSize;
236 else { 238 else {
237 // seq error or frag # error flush DFCB 239 // seq error or frag # error flush DFCB
238 pDevice->cbFreeDFCB++; 240 pDevice->cbFreeDFCB++;
239 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE; 241 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
240 return(FALSE); 242 return(false);
241 } 243 }
242 } 244 }
243 else { 245 else {
244 return(FALSE); 246 return(false);
245 } 247 }
246 if (IS_LAST_FRAGMENT_PKT(pMACHeader)) { 248 if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
247 //enq defragcontrolblock 249 //enq defragcontrolblock
248 pDevice->cbFreeDFCB++; 250 pDevice->cbFreeDFCB++;
249 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE; 251 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
250 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx); 252 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
251 return(TRUE); 253 return(true);
252 } 254 }
253 return(FALSE); 255 return(false);
254 } 256 }
255} 257}
256 258
diff --git a/drivers/staging/vt6656/wctl.h b/drivers/staging/vt6656/wctl.h
index 7270af68c89d..1b21e32e99e5 100644
--- a/drivers/staging/vt6656/wctl.h
+++ b/drivers/staging/vt6656/wctl.h
@@ -96,10 +96,10 @@
96 96
97/*--------------------- Export Functions --------------------------*/ 97/*--------------------- Export Functions --------------------------*/
98 98
99BOOL WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader); 99bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader);
100BOOL WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, 100bool WCTLbHandleFragment(struct vnt_private *, PS802_11Header pMACHeader,
101 unsigned int cbFrameLength, BOOL bWEP, BOOL bExtIV); 101 unsigned int cbFrameLength, bool bWEP, bool bExtIV);
102unsigned int WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader); 102unsigned int WCTLuSearchDFCB(struct vnt_private *, PS802_11Header pMACHeader);
103unsigned int WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader); 103unsigned int WCTLuInsertDFCB(struct vnt_private *, PS802_11Header pMACHeader);
104 104
105#endif /* __WCTL_H__ */ 105#endif /* __WCTL_H__ */
diff --git a/drivers/staging/vt6656/wmgr.c b/drivers/staging/vt6656/wmgr.c
index 95ddc8303bb3..5dced0a43797 100644
--- a/drivers/staging/vt6656/wmgr.c
+++ b/drivers/staging/vt6656/wmgr.c
@@ -93,230 +93,101 @@ static int msglevel =MSG_LEVEL_INFO;
93 93
94/*--------------------- Static Functions --------------------------*/ 94/*--------------------- Static Functions --------------------------*/
95 95
96static BOOL ChannelExceedZoneType( 96static int ChannelExceedZoneType(struct vnt_private *, u8 byCurrChannel);
97 PSDevice pDevice,
98 BYTE byCurrChannel
99 );
100 97
101// Association/diassociation functions 98/* Association/diassociation functions */
102static 99static struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *,
103PSTxMgmtPacket 100 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
104s_MgrMakeAssocRequest( 101 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
105 PSDevice pDevice, 102 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
106 PSMgmtObject pMgmt,
107 PBYTE pDAddr,
108 WORD wCurrCapInfo,
109 WORD wListenInterval,
110 PWLAN_IE_SSID pCurrSSID,
111 PWLAN_IE_SUPP_RATES pCurrRates,
112 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
113 );
114 103
115static 104static void s_vMgrRxAssocRequest(struct vnt_private *,
116void 105 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
117s_vMgrRxAssocRequest( 106 u32 uNodeIndex);
118 PSDevice pDevice,
119 PSMgmtObject pMgmt,
120 PSRxMgmtPacket pRxPacket,
121 unsigned int uNodeIndex
122 );
123 107
124static 108static struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *,
125PSTxMgmtPacket 109 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
126s_MgrMakeReAssocRequest( 110 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
127 PSDevice pDevice, 111 PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
128 PSMgmtObject pMgmt,
129 PBYTE pDAddr,
130 WORD wCurrCapInfo,
131 WORD wListenInterval,
132 PWLAN_IE_SSID pCurrSSID,
133 PWLAN_IE_SUPP_RATES pCurrRates,
134 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
135 );
136 112
137static 113static void s_vMgrRxAssocResponse(struct vnt_private *,
138void 114 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
139s_vMgrRxAssocResponse( 115 int bReAssocType);
140 PSDevice pDevice,
141 PSMgmtObject pMgmt,
142 PSRxMgmtPacket pRxPacket,
143 BOOL bReAssocType
144 );
145 116
146static 117static void s_vMgrRxDisassociation(struct vnt_private *,
147void 118 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
148s_vMgrRxDisassociation(
149 PSDevice pDevice,
150 PSMgmtObject pMgmt,
151 PSRxMgmtPacket pRxPacket
152 );
153 119
154// Authentication/deauthen functions 120/* Authentication/deauthen functions */
155static 121static void s_vMgrRxAuthenSequence_1(struct vnt_private *,
156void 122 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
157s_vMgrRxAuthenSequence_1(
158 PSDevice pDevice,
159 PSMgmtObject pMgmt,
160 PWLAN_FR_AUTHEN pFrame
161 );
162 123
163static 124static void s_vMgrRxAuthenSequence_2(struct vnt_private *,
164void 125 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
165s_vMgrRxAuthenSequence_2(
166 PSDevice pDevice,
167 PSMgmtObject pMgmt,
168 PWLAN_FR_AUTHEN pFrame
169 );
170 126
171static 127static void s_vMgrRxAuthenSequence_3(struct vnt_private *,
172void 128 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
173s_vMgrRxAuthenSequence_3(
174 PSDevice pDevice,
175 PSMgmtObject pMgmt,
176 PWLAN_FR_AUTHEN pFrame
177 );
178 129
179static 130static void s_vMgrRxAuthenSequence_4(struct vnt_private *,
180void 131 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
181s_vMgrRxAuthenSequence_4(
182 PSDevice pDevice,
183 PSMgmtObject pMgmt,
184 PWLAN_FR_AUTHEN pFrame
185 );
186 132
187static 133static void s_vMgrRxAuthentication(struct vnt_private *,
188void 134 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
189s_vMgrRxAuthentication(
190 PSDevice pDevice,
191 PSMgmtObject pMgmt,
192 PSRxMgmtPacket pRxPacket
193 );
194 135
195static 136static void s_vMgrRxDeauthentication(struct vnt_private *,
196void 137 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
197s_vMgrRxDeauthentication(
198 PSDevice pDevice,
199 PSMgmtObject pMgmt,
200 PSRxMgmtPacket pRxPacket
201 );
202 138
203// Scan functions 139/* Scan functions
204// probe request/response functions 140* probe request/response functions */
205static
206void
207s_vMgrRxProbeRequest(
208 PSDevice pDevice,
209 PSMgmtObject pMgmt,
210 PSRxMgmtPacket pRxPacket
211 );
212 141
213static 142static void s_vMgrRxProbeRequest(struct vnt_private *,
214void 143 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
215s_vMgrRxProbeResponse(
216 PSDevice pDevice,
217 PSMgmtObject pMgmt,
218 PSRxMgmtPacket pRxPacket
219 );
220 144
221// beacon functions 145static void s_vMgrRxProbeResponse(struct vnt_private *,
222static 146 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
223void
224s_vMgrRxBeacon(
225 PSDevice pDevice,
226 PSMgmtObject pMgmt,
227 PSRxMgmtPacket pRxPacket,
228 BOOL bInScan
229 );
230 147
231static 148/* beacon functions */
232void 149static void s_vMgrRxBeacon(struct vnt_private *pDevice,
233s_vMgrFormatTIM( 150 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
234 PSMgmtObject pMgmt, 151 int bInScan);
235 PWLAN_IE_TIM pTIM
236 );
237 152
238static 153static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM);
239PSTxMgmtPacket
240s_MgrMakeBeacon(
241 PSDevice pDevice,
242 PSMgmtObject pMgmt,
243 WORD wCurrCapInfo,
244 WORD wCurrBeaconPeriod,
245 unsigned int uCurrChannel,
246 WORD wCurrATIMWinodw,
247 PWLAN_IE_SSID pCurrSSID,
248 PBYTE pCurrBSSID,
249 PWLAN_IE_SUPP_RATES pCurrSuppRates,
250 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
251 );
252 154
155static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
156 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
157 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
158 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
159 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
253 160
254// Association response
255static
256PSTxMgmtPacket
257s_MgrMakeAssocResponse(
258 PSDevice pDevice,
259 PSMgmtObject pMgmt,
260 WORD wCurrCapInfo,
261 WORD wAssocStatus,
262 WORD wAssocAID,
263 PBYTE pDstAddr,
264 PWLAN_IE_SUPP_RATES pCurrSuppRates,
265 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
266 );
267 161
268// ReAssociation response 162/* Association response */
269static 163static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *,
270PSTxMgmtPacket 164 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
271s_MgrMakeReAssocResponse( 165 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
272 PSDevice pDevice, 166 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
273 PSMgmtObject pMgmt,
274 WORD wCurrCapInfo,
275 WORD wAssocStatus,
276 WORD wAssocAID,
277 PBYTE pDstAddr,
278 PWLAN_IE_SUPP_RATES pCurrSuppRates,
279 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
280 );
281 167
282// Probe response 168/* ReAssociation response */
283static 169static struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *,
284PSTxMgmtPacket 170 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
285s_MgrMakeProbeResponse( 171 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
286 PSDevice pDevice, 172 PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
287 PSMgmtObject pMgmt,
288 WORD wCurrCapInfo,
289 WORD wCurrBeaconPeriod,
290 unsigned int uCurrChannel,
291 WORD wCurrATIMWinodw,
292 PBYTE pDstAddr,
293 PWLAN_IE_SSID pCurrSSID,
294 PBYTE pCurrBSSID,
295 PWLAN_IE_SUPP_RATES pCurrSuppRates,
296 PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
297 BYTE byPHYType
298 );
299 173
300// received status 174/* Probe response */
301static 175static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *,
302void 176 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
303s_vMgrLogStatus( 177 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
304 PSMgmtObject pMgmt, 178 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
305 WORD wStatus 179 PWLAN_IE_SUPP_RATES pCurrSuppRates,
306 ); 180 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType);
307 181
182/* received status */
183static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus);
308 184
309static
310void
311s_vMgrSynchBSS (
312 PSDevice pDevice,
313 unsigned int uBSSMode,
314 PKnownBSS pCurr,
315 PCMD_STATUS pStatus
316 );
317 185
186static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode,
187 PKnownBSS pCurr, PCMD_STATUS pStatus);
318 188
319static BOOL 189
190static bool
320s_bCipherMatch ( 191s_bCipherMatch (
321 PKnownBSS pBSSNode, 192 PKnownBSS pBSSNode,
322 NDIS_802_11_ENCRYPTION_STATUS EncStatus, 193 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
@@ -324,10 +195,7 @@ s_bCipherMatch (
324 PBYTE pbyCCSGK 195 PBYTE pbyCCSGK
325 ); 196 );
326 197
327 static void Encyption_Rebuild( 198static void Encyption_Rebuild(struct vnt_private *, PKnownBSS pCurr);
328 PSDevice pDevice,
329 PKnownBSS pCurr
330 );
331 199
332/*--------------------- Export Variables --------------------------*/ 200/*--------------------- Export Variables --------------------------*/
333 201
@@ -343,11 +211,10 @@ s_bCipherMatch (
343 * 211 *
344-*/ 212-*/
345 213
346void vMgrObjectInit(void *hDeviceContext) 214void vMgrObjectInit(struct vnt_private *pDevice)
347{ 215{
348 PSDevice pDevice = (PSDevice)hDeviceContext; 216 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
349 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 217 int ii;
350 int ii;
351 218
352 219
353 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0]; 220 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
@@ -361,7 +228,7 @@ void vMgrObjectInit(void *hDeviceContext)
361 pMgmt->byCSSPK = KEY_CTL_NONE; 228 pMgmt->byCSSPK = KEY_CTL_NONE;
362 pMgmt->byCSSGK = KEY_CTL_NONE; 229 pMgmt->byCSSGK = KEY_CTL_NONE;
363 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI; 230 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
364 BSSvClearBSSList((void *) pDevice, FALSE); 231 BSSvClearBSSList((void *) pDevice, false);
365 232
366 init_timer(&pMgmt->sTimerSecondCallback); 233 init_timer(&pMgmt->sTimerSecondCallback);
367 pMgmt->sTimerSecondCallback.data = (unsigned long)pDevice; 234 pMgmt->sTimerSecondCallback.data = (unsigned long)pDevice;
@@ -377,16 +244,16 @@ void vMgrObjectInit(void *hDeviceContext)
377 pDevice->sTimerTxData.data = (unsigned long)pDevice; 244 pDevice->sTimerTxData.data = (unsigned long)pDevice;
378 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData; 245 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
379 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback 246 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
380 pDevice->fTxDataInSleep = FALSE; 247 pDevice->fTxDataInSleep = false;
381 pDevice->IsTxDataTrigger = FALSE; 248 pDevice->IsTxDataTrigger = false;
382 pDevice->nTxDataTimeCout = 0; 249 pDevice->nTxDataTimeCout = 0;
383 250
384 pDevice->cbFreeCmdQueue = CMD_Q_SIZE; 251 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
385 pDevice->uCmdDequeueIdx = 0; 252 pDevice->uCmdDequeueIdx = 0;
386 pDevice->uCmdEnqueueIdx = 0; 253 pDevice->uCmdEnqueueIdx = 0;
387 pDevice->eCommandState = WLAN_CMD_IDLE; 254 pDevice->eCommandState = WLAN_CMD_IDLE;
388 pDevice->bCmdRunning = FALSE; 255 pDevice->bCmdRunning = false;
389 pDevice->bCmdClear = FALSE; 256 pDevice->bCmdClear = false;
390 257
391 return; 258 return;
392} 259}
@@ -402,12 +269,10 @@ void vMgrObjectInit(void *hDeviceContext)
402 * 269 *
403-*/ 270-*/
404 271
405void vMgrAssocBeginSta(void *hDeviceContext, 272void vMgrAssocBeginSta(struct vnt_private *pDevice,
406 PSMgmtObject pMgmt, 273 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
407 PCMD_STATUS pStatus)
408{ 274{
409 PSDevice pDevice = (PSDevice)hDeviceContext; 275 struct vnt_tx_mgmt *pTxPacket;
410 PSTxMgmtPacket pTxPacket;
411 276
412 277
413 pMgmt->wCurrCapInfo = 0; 278 pMgmt->wCurrCapInfo = 0;
@@ -426,7 +291,7 @@ void vMgrAssocBeginSta(void *hDeviceContext,
426 // ERP Phy (802.11g) should support short preamble. 291 // ERP Phy (802.11g) should support short preamble.
427 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) { 292 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
428 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); 293 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
429 if (pDevice->bShortSlotTime == TRUE) 294 if (pDevice->bShortSlotTime == true)
430 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1); 295 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
431 296
432 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) { 297 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
@@ -434,7 +299,7 @@ void vMgrAssocBeginSta(void *hDeviceContext,
434 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); 299 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
435 } 300 }
436 } 301 }
437 if (pMgmt->b11hEnable == TRUE) 302 if (pMgmt->b11hEnable == true)
438 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1); 303 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
439 304
440 // build an assocreq frame and send it 305 // build an assocreq frame and send it
@@ -475,14 +340,10 @@ void vMgrAssocBeginSta(void *hDeviceContext,
475 * 340 *
476-*/ 341-*/
477 342
478void vMgrReAssocBeginSta(void *hDeviceContext, 343void vMgrReAssocBeginSta(struct vnt_private *pDevice,
479 PSMgmtObject pMgmt, 344 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
480 PCMD_STATUS pStatus)
481{ 345{
482 PSDevice pDevice = (PSDevice)hDeviceContext; 346 struct vnt_tx_mgmt *pTxPacket;
483 PSTxMgmtPacket pTxPacket;
484
485
486 347
487 pMgmt->wCurrCapInfo = 0; 348 pMgmt->wCurrCapInfo = 0;
488 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1); 349 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
@@ -502,7 +363,7 @@ void vMgrReAssocBeginSta(void *hDeviceContext,
502 // ERP Phy (802.11g) should support short preamble. 363 // ERP Phy (802.11g) should support short preamble.
503 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) { 364 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
504 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); 365 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
505 if (pDevice->bShortSlotTime == TRUE) 366 if (pDevice->bShortSlotTime == true)
506 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1); 367 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
507 368
508 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) { 369 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
@@ -510,7 +371,7 @@ void vMgrReAssocBeginSta(void *hDeviceContext,
510 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1); 371 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
511 } 372 }
512 } 373 }
513 if (pMgmt->b11hEnable == TRUE) 374 if (pMgmt->b11hEnable == true)
514 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1); 375 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
515 376
516 377
@@ -551,19 +412,18 @@ void vMgrReAssocBeginSta(void *hDeviceContext,
551 * 412 *
552-*/ 413-*/
553 414
554void vMgrDisassocBeginSta(void *hDeviceContext, 415void vMgrDisassocBeginSta(struct vnt_private *pDevice,
555 PSMgmtObject pMgmt, 416 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
556 PBYTE abyDestAddress, 417 PCMD_STATUS pStatus)
557 WORD wReason,
558 PCMD_STATUS pStatus)
559{ 418{
560 PSDevice pDevice = (PSDevice)hDeviceContext; 419 struct vnt_tx_mgmt *pTxPacket = NULL;
561 PSTxMgmtPacket pTxPacket = NULL; 420 WLAN_FR_DISASSOC sFrame;
562 WLAN_FR_DISASSOC sFrame;
563 421
564 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 422 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
565 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN); 423 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
566 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 424 + WLAN_DISASSOC_FR_MAXLEN);
425 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
426 + sizeof(struct vnt_tx_mgmt));
567 427
568 // Setup the sFrame structure 428 // Setup the sFrame structure
569 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 429 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
@@ -610,23 +470,18 @@ void vMgrDisassocBeginSta(void *hDeviceContext,
610 * 470 *
611-*/ 471-*/
612 472
613static 473static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
614void 474 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
615s_vMgrRxAssocRequest( 475 u32 uNodeIndex)
616 PSDevice pDevice,
617 PSMgmtObject pMgmt,
618 PSRxMgmtPacket pRxPacket,
619 unsigned int uNodeIndex
620 )
621{ 476{
622 WLAN_FR_ASSOCREQ sFrame; 477 WLAN_FR_ASSOCREQ sFrame;
623 CMD_STATUS Status; 478 CMD_STATUS Status;
624 PSTxMgmtPacket pTxPacket; 479 struct vnt_tx_mgmt *pTxPacket;
625 WORD wAssocStatus = 0; 480 u16 wAssocStatus = 0;
626 WORD wAssocAID = 0; 481 u16 wAssocAID = 0;
627 unsigned int uRateLen = WLAN_RATES_MAXLEN; 482 u32 uRateLen = WLAN_RATES_MAXLEN;
628 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; 483 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
629 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; 484 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
630 485
631 486
632 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) 487 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
@@ -650,7 +505,7 @@ s_vMgrRxAssocRequest(
650 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo); 505 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
651 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval); 506 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
652 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = 507 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
653 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : FALSE; 508 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
654 // Todo: check sta basic rate, if ap can't support, set status code 509 // Todo: check sta basic rate, if ap can't support, set status code
655 if (pDevice->byBBType == BB_TYPE_11B) { 510 if (pDevice->byBBType == BB_TYPE_11B) {
656 uRateLen = WLAN_RATES_MAXLEN_11B; 511 uRateLen = WLAN_RATES_MAXLEN_11B;
@@ -672,7 +527,7 @@ s_vMgrRxAssocRequest(
672 RATEvParseMaxRate((void *)pDevice, 527 RATEvParseMaxRate((void *)pDevice,
673 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates, 528 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
674 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates, 529 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
675 FALSE, // do not change our basic rate 530 false, // do not change our basic rate
676 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), 531 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
677 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), 532 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
678 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), 533 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
@@ -693,15 +548,15 @@ s_vMgrRxAssocRequest(
693 wAssocAID = (WORD)uNodeIndex; 548 wAssocAID = (WORD)uNodeIndex;
694 // check if ERP support 549 // check if ERP support
695 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M) 550 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
696 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE; 551 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
697 552
698 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) { 553 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
699 // B only STA join 554 // B only STA join
700 pDevice->bProtectMode = TRUE; 555 pDevice->bProtectMode = true;
701 pDevice->bNonERPPresent = TRUE; 556 pDevice->bNonERPPresent = true;
702 } 557 }
703 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == FALSE) { 558 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
704 pDevice->bBarkerPreambleMd = TRUE; 559 pDevice->bBarkerPreambleMd = true;
705 } 560 }
706 561
707 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID); 562 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
@@ -766,23 +621,18 @@ s_vMgrRxAssocRequest(
766 * 621 *
767-*/ 622-*/
768 623
769static 624static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
770void 625 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
771s_vMgrRxReAssocRequest( 626 u32 uNodeIndex)
772 PSDevice pDevice,
773 PSMgmtObject pMgmt,
774 PSRxMgmtPacket pRxPacket,
775 unsigned int uNodeIndex
776 )
777{ 627{
778 WLAN_FR_REASSOCREQ sFrame; 628 WLAN_FR_REASSOCREQ sFrame;
779 CMD_STATUS Status; 629 CMD_STATUS Status;
780 PSTxMgmtPacket pTxPacket; 630 struct vnt_tx_mgmt *pTxPacket;
781 WORD wAssocStatus = 0; 631 u16 wAssocStatus = 0;
782 WORD wAssocAID = 0; 632 u16 wAssocAID = 0;
783 unsigned int uRateLen = WLAN_RATES_MAXLEN; 633 u32 uRateLen = WLAN_RATES_MAXLEN;
784 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; 634 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
785 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1]; 635 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
786 636
787 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) 637 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
788 return; 638 return;
@@ -801,7 +651,7 @@ s_vMgrRxReAssocRequest(
801 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo); 651 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
802 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval); 652 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
803 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = 653 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
804 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : FALSE; 654 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
805 // Todo: check sta basic rate, if ap can't support, set status code 655 // Todo: check sta basic rate, if ap can't support, set status code
806 656
807 if (pDevice->byBBType == BB_TYPE_11B) { 657 if (pDevice->byBBType == BB_TYPE_11B) {
@@ -825,7 +675,7 @@ s_vMgrRxReAssocRequest(
825 RATEvParseMaxRate((void *)pDevice, 675 RATEvParseMaxRate((void *)pDevice,
826 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates, 676 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
827 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates, 677 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
828 FALSE, // do not change our basic rate 678 false, // do not change our basic rate
829 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), 679 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
830 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), 680 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
831 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), 681 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
@@ -847,15 +697,15 @@ s_vMgrRxReAssocRequest(
847 697
848 // if suppurt ERP 698 // if suppurt ERP
849 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M) 699 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
850 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE; 700 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
851 701
852 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) { 702 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
853 // B only STA join 703 // B only STA join
854 pDevice->bProtectMode = TRUE; 704 pDevice->bProtectMode = true;
855 pDevice->bNonERPPresent = TRUE; 705 pDevice->bNonERPPresent = true;
856 } 706 }
857 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == FALSE) { 707 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
858 pDevice->bBarkerPreambleMd = TRUE; 708 pDevice->bBarkerPreambleMd = true;
859 } 709 }
860 710
861 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID); 711 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
@@ -913,18 +763,13 @@ s_vMgrRxReAssocRequest(
913 * 763 *
914-*/ 764-*/
915 765
916static 766static void s_vMgrRxAssocResponse(struct vnt_private *pDevice,
917void 767 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
918s_vMgrRxAssocResponse( 768 int bReAssocType)
919 PSDevice pDevice,
920 PSMgmtObject pMgmt,
921 PSRxMgmtPacket pRxPacket,
922 BOOL bReAssocType
923 )
924{ 769{
925 WLAN_FR_ASSOCRESP sFrame; 770 WLAN_FR_ASSOCRESP sFrame;
926 PWLAN_IE_SSID pItemSSID; 771 PWLAN_IE_SSID pItemSSID;
927 PBYTE pbyIEs; 772 u8 *pbyIEs;
928 773
929 774
930 775
@@ -970,10 +815,10 @@ s_vMgrRxAssocResponse(
970 sFrame.pExtSuppRates); 815 sFrame.pExtSuppRates);
971 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID; 816 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
972 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID); 817 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
973 pDevice->bLinkPass = TRUE; 818 pDevice->bLinkPass = true;
974 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); 819 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
975 820
976 //if(pDevice->bWPASuppWextEnabled == TRUE) 821 //if(pDevice->bWPASuppWextEnabled == true)
977 { 822 {
978 BYTE buf[512]; 823 BYTE buf[512];
979 size_t len; 824 size_t len;
@@ -1027,11 +872,11 @@ s_vMgrRxAssocResponse(
1027 } 872 }
1028 873
1029//need clear flags related to Networkmanager 874//need clear flags related to Networkmanager
1030 pDevice->bwextstep0 = FALSE; 875 pDevice->bwextstep0 = false;
1031 pDevice->bwextstep1 = FALSE; 876 pDevice->bwextstep1 = false;
1032 pDevice->bwextstep2 = FALSE; 877 pDevice->bwextstep2 = false;
1033 pDevice->bwextstep3 = FALSE; 878 pDevice->bwextstep3 = false;
1034 pDevice->bWPASuppWextEnabled = FALSE; 879 pDevice->bWPASuppWextEnabled = false;
1035 880
1036if(pMgmt->eCurrState == WMAC_STATE_ASSOC) 881if(pMgmt->eCurrState == WMAC_STATE_ASSOC)
1037 timer_expire(pDevice->sTimerCommand, 0); 882 timer_expire(pDevice->sTimerCommand, 0);
@@ -1050,17 +895,17 @@ if(pMgmt->eCurrState == WMAC_STATE_ASSOC)
1050 * 895 *
1051-*/ 896-*/
1052 897
1053void vMgrAuthenBeginSta(void *hDeviceContext, 898void vMgrAuthenBeginSta(struct vnt_private *pDevice,
1054 PSMgmtObject pMgmt, 899 struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
1055 PCMD_STATUS pStatus)
1056{ 900{
1057 PSDevice pDevice = (PSDevice)hDeviceContext; 901 WLAN_FR_AUTHEN sFrame;
1058 WLAN_FR_AUTHEN sFrame; 902 struct vnt_tx_mgmt *pTxPacket =
1059 PSTxMgmtPacket pTxPacket = NULL; 903 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1060 904
1061 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 905 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1062 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); 906 + WLAN_AUTHEN_FR_MAXLEN);
1063 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 907 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
908 + sizeof(struct vnt_tx_mgmt));
1064 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 909 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1065 sFrame.len = WLAN_AUTHEN_FR_MAXLEN; 910 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1066 vMgrEncodeAuthen(&sFrame); 911 vMgrEncodeAuthen(&sFrame);
@@ -1103,20 +948,18 @@ void vMgrAuthenBeginSta(void *hDeviceContext,
1103 * 948 *
1104-*/ 949-*/
1105 950
1106void vMgrDeAuthenBeginSta(void *hDeviceContext, 951void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
1107 PSMgmtObject pMgmt, 952 struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
1108 PBYTE abyDestAddress, 953 PCMD_STATUS pStatus)
1109 WORD wReason,
1110 PCMD_STATUS pStatus)
1111{ 954{
1112 PSDevice pDevice = (PSDevice)hDeviceContext; 955 WLAN_FR_DEAUTHEN sFrame;
1113 WLAN_FR_DEAUTHEN sFrame; 956 struct vnt_tx_mgmt *pTxPacket =
1114 PSTxMgmtPacket pTxPacket = NULL; 957 (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1115 958
1116 959 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1117 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 960 + WLAN_DEAUTHEN_FR_MAXLEN);
1118 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN); 961 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1119 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 962 + sizeof(struct vnt_tx_mgmt));
1120 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 963 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1121 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN; 964 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
1122 vMgrEncodeDeauthen(&sFrame); 965 vMgrEncodeDeauthen(&sFrame);
@@ -1156,15 +999,10 @@ void vMgrDeAuthenBeginSta(void *hDeviceContext,
1156 * 999 *
1157-*/ 1000-*/
1158 1001
1159static 1002static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
1160void 1003 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
1161s_vMgrRxAuthentication(
1162 PSDevice pDevice,
1163 PSMgmtObject pMgmt,
1164 PSRxMgmtPacket pRxPacket
1165 )
1166{ 1004{
1167 WLAN_FR_AUTHEN sFrame; 1005 WLAN_FR_AUTHEN sFrame;
1168 1006
1169 // we better be an AP or a STA in AUTHPENDING otherwise ignore 1007 // we better be an AP or a STA in AUTHPENDING otherwise ignore
1170 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP || 1008 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
@@ -1214,25 +1052,21 @@ s_vMgrRxAuthentication(
1214-*/ 1052-*/
1215 1053
1216 1054
1217static 1055static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
1218void 1056 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1219s_vMgrRxAuthenSequence_1(
1220 PSDevice pDevice,
1221 PSMgmtObject pMgmt,
1222 PWLAN_FR_AUTHEN pFrame
1223 )
1224{ 1057{
1225 PSTxMgmtPacket pTxPacket = NULL; 1058 struct vnt_tx_mgmt *pTxPacket = NULL;
1226 unsigned int uNodeIndex; 1059 u32 uNodeIndex;
1227 WLAN_FR_AUTHEN sFrame; 1060 WLAN_FR_AUTHEN sFrame;
1228 PSKeyItem pTransmitKey; 1061 PSKeyItem pTransmitKey;
1229 1062
1230 // Insert a Node entry 1063 /* Insert a Node entry */
1231 if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) { 1064 if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2,
1232 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex); 1065 &uNodeIndex)) {
1233 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2, 1066 BSSvCreateOneNode(pDevice, &uNodeIndex);
1234 WLAN_ADDR_LEN); 1067 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr,
1235 } 1068 pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1069 }
1236 1070
1237 if (pMgmt->bShareKeyAlgorithm) { 1071 if (pMgmt->bShareKeyAlgorithm) {
1238 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN; 1072 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
@@ -1243,9 +1077,11 @@ s_vMgrRxAuthenSequence_1(
1243 } 1077 }
1244 1078
1245 // send auth reply 1079 // send auth reply
1246 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 1080 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1247 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); 1081 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1248 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 1082 + WLAN_AUTHEN_FR_MAXLEN);
1083 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1084 + sizeof(struct vnt_tx_mgmt));
1249 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 1085 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1250 sFrame.len = WLAN_AUTHEN_FR_MAXLEN; 1086 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1251 // format buffer structure 1087 // format buffer structure
@@ -1285,7 +1121,7 @@ s_vMgrRxAuthenSequence_1(
1285 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN; 1121 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1286 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN); 1122 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
1287 // get group key 1123 // get group key
1288 if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == TRUE) { 1124 if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
1289 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3); 1125 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
1290 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN); 1126 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
1291 } 1127 }
@@ -1320,16 +1156,11 @@ s_vMgrRxAuthenSequence_1(
1320 * 1156 *
1321-*/ 1157-*/
1322 1158
1323static 1159static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
1324void 1160 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1325s_vMgrRxAuthenSequence_2(
1326 PSDevice pDevice,
1327 PSMgmtObject pMgmt,
1328 PWLAN_FR_AUTHEN pFrame
1329 )
1330{ 1161{
1331 WLAN_FR_AUTHEN sFrame; 1162 WLAN_FR_AUTHEN sFrame;
1332 PSTxMgmtPacket pTxPacket = NULL; 1163 struct vnt_tx_mgmt *pTxPacket = NULL;
1333 1164
1334 1165
1335 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm)))) 1166 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
@@ -1355,9 +1186,13 @@ s_vMgrRxAuthenSequence_2(
1355 case WLAN_AUTH_ALG_SHAREDKEY: 1186 case WLAN_AUTH_ALG_SHAREDKEY:
1356 1187
1357 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) { 1188 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
1358 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 1189 pTxPacket = (struct vnt_tx_mgmt *)
1359 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); 1190 pMgmt->pbyMgmtPacketPool;
1360 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 1191 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1192 + WLAN_AUTHEN_FR_MAXLEN);
1193 pTxPacket->p80211Header
1194 = (PUWLAN_80211HDR)((u8 *)pTxPacket
1195 + sizeof(struct vnt_tx_mgmt));
1361 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 1196 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1362 sFrame.len = WLAN_AUTHEN_FR_MAXLEN; 1197 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1363 // format buffer structure 1198 // format buffer structure
@@ -1421,18 +1256,13 @@ s_vMgrRxAuthenSequence_2(
1421 * 1256 *
1422-*/ 1257-*/
1423 1258
1424static 1259static void s_vMgrRxAuthenSequence_3(struct vnt_private *pDevice,
1425void 1260 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1426s_vMgrRxAuthenSequence_3(
1427 PSDevice pDevice,
1428 PSMgmtObject pMgmt,
1429 PWLAN_FR_AUTHEN pFrame
1430 )
1431{ 1261{
1432 PSTxMgmtPacket pTxPacket = NULL; 1262 struct vnt_tx_mgmt *pTxPacket = NULL;
1433 unsigned int uStatusCode = 0 ; 1263 u32 uStatusCode = 0 ;
1434 unsigned int uNodeIndex = 0; 1264 u32 uNodeIndex = 0;
1435 WLAN_FR_AUTHEN sFrame; 1265 WLAN_FR_AUTHEN sFrame;
1436 1266
1437 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) { 1267 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
1438 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL; 1268 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
@@ -1462,9 +1292,11 @@ s_vMgrRxAuthenSequence_3(
1462 1292
1463reply: 1293reply:
1464 // send auth reply 1294 // send auth reply
1465 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 1295 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
1466 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN); 1296 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
1467 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 1297 + WLAN_AUTHEN_FR_MAXLEN);
1298 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
1299 + sizeof(struct vnt_tx_mgmt));
1468 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 1300 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1469 sFrame.len = WLAN_AUTHEN_FR_MAXLEN; 1301 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1470 // format buffer structure 1302 // format buffer structure
@@ -1509,13 +1341,8 @@ reply:
1509 * None. 1341 * None.
1510 * 1342 *
1511-*/ 1343-*/
1512static 1344static void s_vMgrRxAuthenSequence_4(struct vnt_private *pDevice,
1513void 1345 struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
1514s_vMgrRxAuthenSequence_4(
1515 PSDevice pDevice,
1516 PSMgmtObject pMgmt,
1517 PWLAN_FR_AUTHEN pFrame
1518 )
1519{ 1346{
1520 1347
1521 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){ 1348 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
@@ -1547,17 +1374,12 @@ s_vMgrRxAuthenSequence_4(
1547 * 1374 *
1548-*/ 1375-*/
1549 1376
1550static 1377static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
1551void 1378 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
1552s_vMgrRxDisassociation(
1553 PSDevice pDevice,
1554 PSMgmtObject pMgmt,
1555 PSRxMgmtPacket pRxPacket
1556 )
1557{ 1379{
1558 WLAN_FR_DISASSOC sFrame; 1380 WLAN_FR_DISASSOC sFrame;
1559 unsigned int uNodeIndex = 0; 1381 u32 uNodeIndex = 0;
1560 CMD_STATUS CmdStatus; 1382 CMD_STATUS CmdStatus;
1561 1383
1562 if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){ 1384 if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1563 // if is acting an AP.. 1385 // if is acting an AP..
@@ -1577,24 +1399,24 @@ s_vMgrRxDisassociation(
1577 vMgrDecodeDisassociation(&sFrame); 1399 vMgrDecodeDisassociation(&sFrame);
1578 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason))); 1400 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
1579 1401
1580 pDevice->fWPA_Authened = FALSE; 1402 pDevice->fWPA_Authened = false;
1581 1403
1582 //TODO: do something let upper layer know or 1404 //TODO: do something let upper layer know or
1583 //try to send associate packet again because of inactivity timeout 1405 //try to send associate packet again because of inactivity timeout
1584 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) { 1406 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
1585 pDevice->bLinkPass = FALSE; 1407 pDevice->bLinkPass = false;
1586 pMgmt->sNodeDBTable[0].bActive = FALSE; 1408 pMgmt->sNodeDBTable[0].bActive = false;
1587 pDevice->byReAssocCount = 0; 1409 pDevice->byReAssocCount = 0;
1588 pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state! 1410 pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state!
1589 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT; 1411 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
1590 vMgrReAssocBeginSta((PSDevice)pDevice, pMgmt, &CmdStatus); 1412 vMgrReAssocBeginSta(pDevice, pMgmt, &CmdStatus);
1591 if(CmdStatus == CMD_STATUS_PENDING) { 1413 if(CmdStatus == CMD_STATUS_PENDING) {
1592 pDevice->byReAssocCount ++; 1414 pDevice->byReAssocCount ++;
1593 return; //mike add: you'll retry for many times, so it cann't be regarded as disconnected! 1415 return; //mike add: you'll retry for many times, so it cann't be regarded as disconnected!
1594 } 1416 }
1595 } 1417 }
1596 1418
1597 // if(pDevice->bWPASuppWextEnabled == TRUE) 1419 // if(pDevice->bWPASuppWextEnabled == true)
1598 { 1420 {
1599 union iwreq_data wrqu; 1421 union iwreq_data wrqu;
1600 memset(&wrqu, 0, sizeof (wrqu)); 1422 memset(&wrqu, 0, sizeof (wrqu));
@@ -1620,16 +1442,11 @@ s_vMgrRxDisassociation(
1620 * 1442 *
1621-*/ 1443-*/
1622 1444
1623static 1445static void s_vMgrRxDeauthentication(struct vnt_private *pDevice,
1624void 1446 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
1625s_vMgrRxDeauthentication(
1626 PSDevice pDevice,
1627 PSMgmtObject pMgmt,
1628 PSRxMgmtPacket pRxPacket
1629 )
1630{ 1447{
1631 WLAN_FR_DEAUTHEN sFrame; 1448 WLAN_FR_DEAUTHEN sFrame;
1632 unsigned int uNodeIndex = 0; 1449 u32 uNodeIndex = 0;
1633 1450
1634 1451
1635 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){ 1452 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
@@ -1650,22 +1467,22 @@ s_vMgrRxDeauthentication(
1650 sFrame.len = pRxPacket->cbMPDULen; 1467 sFrame.len = pRxPacket->cbMPDULen;
1651 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header; 1468 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1652 vMgrDecodeDeauthen(&sFrame); 1469 vMgrDecodeDeauthen(&sFrame);
1653 pDevice->fWPA_Authened = FALSE; 1470 pDevice->fWPA_Authened = false;
1654 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason)))); 1471 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
1655 // TODO: update BSS list for specific BSSID if pre-authentication case 1472 // TODO: update BSS list for specific BSSID if pre-authentication case
1656 if (!compare_ether_addr(sFrame.pHdr->sA3.abyAddr3, 1473 if (!compare_ether_addr(sFrame.pHdr->sA3.abyAddr3,
1657 pMgmt->abyCurrBSSID)) { 1474 pMgmt->abyCurrBSSID)) {
1658 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) { 1475 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
1659 pMgmt->sNodeDBTable[0].bActive = FALSE; 1476 pMgmt->sNodeDBTable[0].bActive = false;
1660 pMgmt->eCurrMode = WMAC_MODE_STANDBY; 1477 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1661 pMgmt->eCurrState = WMAC_STATE_IDLE; 1478 pMgmt->eCurrState = WMAC_STATE_IDLE;
1662 netif_stop_queue(pDevice->dev); 1479 netif_stop_queue(pDevice->dev);
1663 pDevice->bLinkPass = FALSE; 1480 pDevice->bLinkPass = false;
1664 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW); 1481 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1665 } 1482 }
1666 } 1483 }
1667 1484
1668 // if(pDevice->bWPASuppWextEnabled == TRUE) 1485 // if(pDevice->bWPASuppWextEnabled == true)
1669 { 1486 {
1670 union iwreq_data wrqu; 1487 union iwreq_data wrqu;
1671 memset(&wrqu, 0, sizeof (wrqu)); 1488 memset(&wrqu, 0, sizeof (wrqu));
@@ -1692,23 +1509,19 @@ s_vMgrRxDeauthentication(
1692 * True:exceed; 1509 * True:exceed;
1693 * False:normal case 1510 * False:normal case
1694-*/ 1511-*/
1695static BOOL 1512static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel)
1696ChannelExceedZoneType(
1697 PSDevice pDevice,
1698 BYTE byCurrChannel
1699 )
1700{ 1513{
1701 BOOL exceed=FALSE; 1514 int exceed = false;
1702 1515
1703 switch(pDevice->byZoneType) { 1516 switch(pDevice->byZoneType) {
1704 case 0x00: //USA:1~11 1517 case 0x00: //USA:1~11
1705 if((byCurrChannel<1) ||(byCurrChannel>11)) 1518 if((byCurrChannel<1) ||(byCurrChannel>11))
1706 exceed = TRUE; 1519 exceed = true;
1707 break; 1520 break;
1708 case 0x01: //Japan:1~13 1521 case 0x01: //Japan:1~13
1709 case 0x02: //Europe:1~13 1522 case 0x02: //Europe:1~13
1710 if((byCurrChannel<1) ||(byCurrChannel>13)) 1523 if((byCurrChannel<1) ||(byCurrChannel>13))
1711 exceed = TRUE; 1524 exceed = true;
1712 break; 1525 break;
1713 default: //reserve for other zonetype 1526 default: //reserve for other zonetype
1714 break; 1527 break;
@@ -1728,39 +1541,33 @@ ChannelExceedZoneType(
1728 * 1541 *
1729-*/ 1542-*/
1730 1543
1731static 1544static void s_vMgrRxBeacon(struct vnt_private *pDevice,
1732void 1545 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
1733s_vMgrRxBeacon( 1546 int bInScan)
1734 PSDevice pDevice,
1735 PSMgmtObject pMgmt,
1736 PSRxMgmtPacket pRxPacket,
1737 BOOL bInScan
1738 )
1739{ 1547{
1740 1548 PKnownBSS pBSSList;
1741 PKnownBSS pBSSList; 1549 WLAN_FR_BEACON sFrame;
1742 WLAN_FR_BEACON sFrame; 1550 u64 qwTSFOffset;
1743 QWORD qwTSFOffset; 1551 int bIsBSSIDEqual = false;
1744 BOOL bIsBSSIDEqual = FALSE; 1552 int bIsSSIDEqual = false;
1745 BOOL bIsSSIDEqual = FALSE; 1553 int bTSFLargeDiff = false;
1746 BOOL bTSFLargeDiff = FALSE; 1554 int bTSFOffsetPostive = false;
1747 BOOL bTSFOffsetPostive = FALSE; 1555 int bUpdateTSF = false;
1748 BOOL bUpdateTSF = FALSE; 1556 int bIsAPBeacon = false;
1749 BOOL bIsAPBeacon = FALSE; 1557 int bIsChannelEqual = false;
1750 BOOL bIsChannelEqual = FALSE; 1558 u32 uLocateByteIndex;
1751 unsigned int uLocateByteIndex; 1559 u8 byTIMBitOn = 0;
1752 BYTE byTIMBitOn = 0; 1560 u16 wAIDNumber = 0;
1753 WORD wAIDNumber = 0; 1561 u32 uNodeIndex;
1754 unsigned int uNodeIndex; 1562 u64 qwTimestamp, qwLocalTSF;
1755 QWORD qwTimestamp, qwLocalTSF; 1563 u64 qwCurrTSF;
1756 QWORD qwCurrTSF; 1564 u16 wStartIndex = 0;
1757 WORD wStartIndex = 0; 1565 u16 wAIDIndex = 0;
1758 WORD wAIDIndex = 0; 1566 u8 byCurrChannel = pRxPacket->byRxChannel;
1759 BYTE byCurrChannel = pRxPacket->byRxChannel; 1567 ERPObject sERP;
1760 ERPObject sERP; 1568 u32 uRateLen = WLAN_RATES_MAXLEN;
1761 unsigned int uRateLen = WLAN_RATES_MAXLEN; 1569 int bChannelHit = false;
1762 BOOL bChannelHit = FALSE; 1570 u8 byOldPreambleType;
1763 BYTE byOldPreambleType;
1764 1571
1765 1572
1766 1573
@@ -1787,31 +1594,31 @@ s_vMgrRxBeacon(
1787 { 1594 {
1788 if (sFrame.pDSParms != NULL) { 1595 if (sFrame.pDSParms != NULL) {
1789 if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]) 1596 if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
1790 bChannelHit = TRUE; 1597 bChannelHit = true;
1791 byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]; 1598 byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
1792 } else { 1599 } else {
1793 bChannelHit = TRUE; 1600 bChannelHit = true;
1794 } 1601 }
1795 1602
1796 } else { 1603 } else {
1797 if (sFrame.pDSParms != NULL) { 1604 if (sFrame.pDSParms != NULL) {
1798 if (byCurrChannel == sFrame.pDSParms->byCurrChannel) 1605 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
1799 bChannelHit = TRUE; 1606 bChannelHit = true;
1800 byCurrChannel = sFrame.pDSParms->byCurrChannel; 1607 byCurrChannel = sFrame.pDSParms->byCurrChannel;
1801 } else { 1608 } else {
1802 bChannelHit = TRUE; 1609 bChannelHit = true;
1803 } 1610 }
1804 } 1611 }
1805 1612
1806if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) 1613if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
1807 return; 1614 return;
1808 1615
1809 if (sFrame.pERP != NULL) { 1616 if (sFrame.pERP != NULL) {
1810 sERP.byERP = sFrame.pERP->byContext; 1617 sERP.byERP = sFrame.pERP->byContext;
1811 sERP.bERPExist = TRUE; 1618 sERP.bERPExist = true;
1812 1619
1813 } else { 1620 } else {
1814 sERP.bERPExist = FALSE; 1621 sERP.bERPExist = false;
1815 sERP.byERP = 0; 1622 sERP.byERP = 0;
1816 } 1623 }
1817 1624
@@ -1866,7 +1673,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
1866 } 1673 }
1867 1674
1868 if(byCurrChannel == (BYTE)pMgmt->uCurrChannel) 1675 if(byCurrChannel == (BYTE)pMgmt->uCurrChannel)
1869 bIsChannelEqual = TRUE; 1676 bIsChannelEqual = true;
1870 1677
1871 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) { 1678 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1872 1679
@@ -1895,7 +1702,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
1895 pMgmt->abyCurrBSSID, 1702 pMgmt->abyCurrBSSID,
1896 WLAN_BSSID_LEN) == 0) { 1703 WLAN_BSSID_LEN) == 0) {
1897 1704
1898 bIsBSSIDEqual = TRUE; 1705 bIsBSSIDEqual = true;
1899 pDevice->uCurrRSSI = pRxPacket->uRSSI; 1706 pDevice->uCurrRSSI = pRxPacket->uRSSI;
1900 pDevice->byCurrSQ = pRxPacket->bySQ; 1707 pDevice->byCurrSQ = pRxPacket->bySQ;
1901 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) { 1708 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
@@ -1909,22 +1716,22 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
1909 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, 1716 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
1910 sFrame.pSSID->len 1717 sFrame.pSSID->len
1911 ) == 0) { 1718 ) == 0) {
1912 bIsSSIDEqual = TRUE; 1719 bIsSSIDEqual = true;
1913 } 1720 }
1914 } 1721 }
1915 1722
1916 if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== TRUE) && 1723 if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) &&
1917 (bIsBSSIDEqual == TRUE) && 1724 (bIsBSSIDEqual == true) &&
1918 (bIsSSIDEqual == TRUE) && 1725 (bIsSSIDEqual == true) &&
1919 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && 1726 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1920 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) { 1727 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1921 // add state check to prevent reconnect fail since we'll receive Beacon 1728 // add state check to prevent reconnect fail since we'll receive Beacon
1922 1729
1923 bIsAPBeacon = TRUE; 1730 bIsAPBeacon = true;
1924 if (pBSSList != NULL) { 1731 if (pBSSList != NULL) {
1925 1732
1926 // Sync ERP field 1733 // Sync ERP field
1927 if ((pBSSList->sERP.bERPExist == TRUE) && (pDevice->byBBType == BB_TYPE_11G)) { 1734 if ((pBSSList->sERP.bERPExist == true) && (pDevice->byBBType == BB_TYPE_11G)) {
1928 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010 1735 if ((pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
1929 pDevice->bProtectMode = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION); 1736 pDevice->bProtectMode = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
1930 if (pDevice->bProtectMode) { 1737 if (pDevice->bProtectMode) {
@@ -1949,16 +1756,16 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
1949 } 1756 }
1950 // Sync Short Slot Time 1757 // Sync Short Slot Time
1951 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo) != pDevice->bShortSlotTime) { 1758 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo) != pDevice->bShortSlotTime) {
1952 BOOL bShortSlotTime; 1759 bool bShortSlotTime;
1953 1760
1954 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo); 1761 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo);
1955 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime)); 1762 //DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
1956 //Kyle check if it is OK to set G. 1763 //Kyle check if it is OK to set G.
1957 if (pDevice->byBBType == BB_TYPE_11A) { 1764 if (pDevice->byBBType == BB_TYPE_11A) {
1958 bShortSlotTime = TRUE; 1765 bShortSlotTime = true;
1959 } 1766 }
1960 else if (pDevice->byBBType == BB_TYPE_11B) { 1767 else if (pDevice->byBBType == BB_TYPE_11B) {
1961 bShortSlotTime = FALSE; 1768 bShortSlotTime = false;
1962 } 1769 }
1963 if (bShortSlotTime != pDevice->bShortSlotTime) { 1770 if (bShortSlotTime != pDevice->bShortSlotTime) {
1964 pDevice->bShortSlotTime = bShortSlotTime; 1771 pDevice->bShortSlotTime = bShortSlotTime;
@@ -1994,7 +1801,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
1994 RATEvParseMaxRate((void *)pDevice, 1801 RATEvParseMaxRate((void *)pDevice,
1995 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 1802 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1996 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, 1803 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1997 TRUE, 1804 true,
1998 &(pMgmt->sNodeDBTable[0].wMaxBasicRate), 1805 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
1999 &(pMgmt->sNodeDBTable[0].wMaxSuppRate), 1806 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
2000 &(pMgmt->sNodeDBTable[0].wSuppRate), 1807 &(pMgmt->sNodeDBTable[0].wSuppRate),
@@ -2013,26 +1820,14 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2013 } 1820 }
2014 } 1821 }
2015 1822
2016 HIDWORD(qwTimestamp) = cpu_to_le32(HIDWORD(*sFrame.pqwTimestamp)); 1823 qwTimestamp = cpu_to_le64(*sFrame.pqwTimestamp);
2017 LODWORD(qwTimestamp) = cpu_to_le32(LODWORD(*sFrame.pqwTimestamp)); 1824 qwLocalTSF = pRxPacket->qwLocalTSF;
2018 HIDWORD(qwLocalTSF) = HIDWORD(pRxPacket->qwLocalTSF);
2019 LODWORD(qwLocalTSF) = LODWORD(pRxPacket->qwLocalTSF);
2020 1825
2021 // check if beacon TSF larger or small than our local TSF 1826 // check if beacon TSF larger or small than our local TSF
2022 if (HIDWORD(qwTimestamp) == HIDWORD(qwLocalTSF)) { 1827 if (qwTimestamp >= qwLocalTSF)
2023 if (LODWORD(qwTimestamp) >= LODWORD(qwLocalTSF)) { 1828 bTSFOffsetPostive = true;
2024 bTSFOffsetPostive = TRUE; 1829 else
2025 } 1830 bTSFOffsetPostive = false;
2026 else {
2027 bTSFOffsetPostive = FALSE;
2028 }
2029 }
2030 else if (HIDWORD(qwTimestamp) > HIDWORD(qwLocalTSF)) {
2031 bTSFOffsetPostive = TRUE;
2032 }
2033 else if (HIDWORD(qwTimestamp) < HIDWORD(qwLocalTSF)) {
2034 bTSFOffsetPostive = FALSE;
2035 }
2036 1831
2037 if (bTSFOffsetPostive) { 1832 if (bTSFOffsetPostive) {
2038 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF)); 1833 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
@@ -2041,23 +1836,21 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2041 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp)); 1836 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
2042 } 1837 }
2043 1838
2044 if (HIDWORD(qwTSFOffset) != 0 || 1839 if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
2045 (LODWORD(qwTSFOffset) > TRIVIAL_SYNC_DIFFERENCE )) { 1840 bTSFLargeDiff = true;
2046 bTSFLargeDiff = TRUE;
2047 }
2048 1841
2049 1842
2050 // if infra mode 1843 // if infra mode
2051 if (bIsAPBeacon == TRUE) { 1844 if (bIsAPBeacon == true) {
2052 1845
2053 // Infra mode: Local TSF always follow AP's TSF if Difference huge. 1846 // Infra mode: Local TSF always follow AP's TSF if Difference huge.
2054 if (bTSFLargeDiff) 1847 if (bTSFLargeDiff)
2055 bUpdateTSF = TRUE; 1848 bUpdateTSF = true;
2056 1849
2057 if ((pDevice->bEnablePSMode == TRUE) && (sFrame.pTIM)) { 1850 if ((pDevice->bEnablePSMode == true) && (sFrame.pTIM)) {
2058 1851
2059 /* deal with DTIM, analysis TIM */ 1852 /* deal with DTIM, analysis TIM */
2060 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? TRUE : FALSE ; 1853 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ;
2061 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount; 1854 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
2062 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod; 1855 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
2063 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15); 1856 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
@@ -2072,36 +1865,33 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2072 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250] 1865 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
2073 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) { 1866 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
2074 byTIMBitOn = (0x01) << ((wAIDNumber) % 8); 1867 byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
2075 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? TRUE : FALSE; 1868 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
2076 } 1869 }
2077 else { 1870 else {
2078 pMgmt->bInTIM = FALSE; 1871 pMgmt->bInTIM = false;
2079 }; 1872 };
2080 } 1873 }
2081 else { 1874 else {
2082 pMgmt->bInTIM = FALSE; 1875 pMgmt->bInTIM = false;
2083 }; 1876 };
2084 1877
2085 if (pMgmt->bInTIM || 1878 if (pMgmt->bInTIM ||
2086 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) { 1879 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
2087 pMgmt->bInTIMWake = TRUE; 1880 pMgmt->bInTIMWake = true;
2088 // send out ps-poll packet 1881 /* send out ps-poll packet */
2089// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:In TIM\n"); 1882 if (pMgmt->bInTIM)
2090 if (pMgmt->bInTIM) { 1883 PSvSendPSPOLL(pDevice);
2091 PSvSendPSPOLL((PSDevice)pDevice);
2092// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:PS-POLL sent..\n");
2093 }
2094 1884
2095 } 1885 }
2096 else { 1886 else {
2097 pMgmt->bInTIMWake = FALSE; 1887 pMgmt->bInTIMWake = false;
2098 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n"); 1888 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
2099 if (pDevice->bPWBitOn == FALSE) { 1889 if (pDevice->bPWBitOn == false) {
2100 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n"); 1890 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
2101 if (PSbSendNullPacket(pDevice)) 1891 if (PSbSendNullPacket(pDevice))
2102 pDevice->bPWBitOn = TRUE; 1892 pDevice->bPWBitOn = true;
2103 } 1893 }
2104 if(PSbConsiderPowerDown(pDevice, FALSE, FALSE)) { 1894 if(PSbConsiderPowerDown(pDevice, false, false)) {
2105 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n"); 1895 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
2106 } 1896 }
2107 } 1897 }
@@ -2119,7 +1909,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2119 // adhoc mode:TSF updated only when beacon larger then local TSF 1909 // adhoc mode:TSF updated only when beacon larger then local TSF
2120 if (bTSFLargeDiff && bTSFOffsetPostive && 1910 if (bTSFLargeDiff && bTSFOffsetPostive &&
2121 (pMgmt->eCurrState == WMAC_STATE_JOINTED)) 1911 (pMgmt->eCurrState == WMAC_STATE_JOINTED))
2122 bUpdateTSF = TRUE; 1912 bUpdateTSF = true;
2123 1913
2124 // During dpc, already in spinlocked. 1914 // During dpc, already in spinlocked.
2125 if (BSSbIsSTAInNodeDB(pDevice, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) { 1915 if (BSSbIsSTAInNodeDB(pDevice, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
@@ -2132,7 +1922,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2132 RATEvParseMaxRate((void *)pDevice, 1922 RATEvParseMaxRate((void *)pDevice,
2133 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 1923 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2134 NULL, 1924 NULL,
2135 TRUE, 1925 true,
2136 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), 1926 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2137 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), 1927 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2138 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), 1928 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
@@ -2144,8 +1934,8 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2144 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0; 1934 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
2145 } 1935 }
2146 else { 1936 else {
2147 // Todo, initial Node content 1937 /* Todo, initial Node content */
2148 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex); 1938 BSSvCreateOneNode(pDevice, &uNodeIndex);
2149 1939
2150 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates, 1940 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2151 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 1941 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
@@ -2153,7 +1943,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2153 RATEvParseMaxRate((void *)pDevice, 1943 RATEvParseMaxRate((void *)pDevice,
2154 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 1944 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2155 NULL, 1945 NULL,
2156 TRUE, 1946 true,
2157 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate), 1947 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2158 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate), 1948 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2159 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate), 1949 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
@@ -2167,7 +1957,7 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2167/* 1957/*
2168 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo); 1958 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
2169 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M) 1959 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
2170 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE; 1960 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
2171*/ 1961*/
2172 } 1962 }
2173 1963
@@ -2175,12 +1965,12 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2175 if (pMgmt->eCurrState == WMAC_STATE_STARTED) { 1965 if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
2176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n"); 1966 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
2177 pMgmt->eCurrState = WMAC_STATE_JOINTED; 1967 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2178 pDevice->bLinkPass = TRUE; 1968 pDevice->bLinkPass = true;
2179 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); 1969 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
2180 if (netif_queue_stopped(pDevice->dev)){ 1970 if (netif_queue_stopped(pDevice->dev)){
2181 netif_wake_queue(pDevice->dev); 1971 netif_wake_queue(pDevice->dev);
2182 } 1972 }
2183 pMgmt->sNodeDBTable[0].bActive = TRUE; 1973 pMgmt->sNodeDBTable[0].bActive = true;
2184 pMgmt->sNodeDBTable[0].uInActiveCount = 0; 1974 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2185 1975
2186 } 1976 }
@@ -2256,26 +2046,22 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2256 * 2046 *
2257-*/ 2047-*/
2258 2048
2259void vMgrCreateOwnIBSS(void *hDeviceContext, 2049void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
2260 PCMD_STATUS pStatus)
2261{ 2050{
2262 PSDevice pDevice = (PSDevice)hDeviceContext; 2051 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2263 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 2052 u16 wMaxBasicRate;
2264 WORD wMaxBasicRate; 2053 u16 wMaxSuppRate;
2265 WORD wMaxSuppRate; 2054 u8 byTopCCKBasicRate;
2266 BYTE byTopCCKBasicRate; 2055 u8 byTopOFDMBasicRate;
2267 BYTE byTopOFDMBasicRate; 2056 u64 qwCurrTSF = 0;
2268 QWORD qwCurrTSF; 2057 int ii;
2269 unsigned int ii; 2058 u8 abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C,
2270 BYTE abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60}; 2059 0x12, 0x18, 0x60};
2271 BYTE abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96}; 2060 u8 abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
2272 BYTE abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; 2061 u8 abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2273 WORD wSuppRate; 2062 u16 wSuppRate;
2274
2275 2063
2276 2064
2277 HIDWORD(qwCurrTSF) = 0;
2278 LODWORD(qwCurrTSF) = 0;
2279 2065
2280 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n"); 2066 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
2281 2067
@@ -2366,16 +2152,16 @@ void vMgrCreateOwnIBSS(void *hDeviceContext,
2366 2152
2367 RATEvParseMaxRate((void *)pDevice, 2153 RATEvParseMaxRate((void *)pDevice,
2368 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 2154 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2369 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, TRUE, 2155 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
2370 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate, 2156 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2371 &byTopCCKBasicRate, &byTopOFDMBasicRate); 2157 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2372 2158
2373 2159
2374 2160
2375 if (pDevice->byBBType == BB_TYPE_11A) { 2161 if (pDevice->byBBType == BB_TYPE_11A) {
2376 pDevice->bShortSlotTime = TRUE; 2162 pDevice->bShortSlotTime = true;
2377 } else { 2163 } else {
2378 pDevice->bShortSlotTime = FALSE; 2164 pDevice->bShortSlotTime = false;
2379 } 2165 }
2380 BBvSetShortSlotTime(pDevice); 2166 BBvSetShortSlotTime(pDevice);
2381 // vUpdateIFS() use pDevice->bShortSlotTime as parameter so it must be called 2167 // vUpdateIFS() use pDevice->bShortSlotTime as parameter so it must be called
@@ -2420,12 +2206,12 @@ void vMgrCreateOwnIBSS(void *hDeviceContext,
2420 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) { 2206 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2421 2207
2422 // BSSID selected must be randomized as spec 11.1.3 2208 // BSSID selected must be randomized as spec 11.1.3
2423 pMgmt->abyCurrBSSID[5] = (BYTE) (LODWORD(qwCurrTSF)& 0x000000ff); 2209 pMgmt->abyCurrBSSID[5] = (u8)(qwCurrTSF & 0x000000ff);
2424 pMgmt->abyCurrBSSID[4] = (BYTE)((LODWORD(qwCurrTSF)& 0x0000ff00) >> 8); 2210 pMgmt->abyCurrBSSID[4] = (u8)((qwCurrTSF & 0x0000ff00) >> 8);
2425 pMgmt->abyCurrBSSID[3] = (BYTE)((LODWORD(qwCurrTSF)& 0x00ff0000) >> 16); 2211 pMgmt->abyCurrBSSID[3] = (u8)((qwCurrTSF & 0x00ff0000) >> 16);
2426 pMgmt->abyCurrBSSID[2] = (BYTE)((LODWORD(qwCurrTSF)& 0x00000ff0) >> 4); 2212 pMgmt->abyCurrBSSID[2] = (u8)((qwCurrTSF & 0x00000ff0) >> 4);
2427 pMgmt->abyCurrBSSID[1] = (BYTE)((LODWORD(qwCurrTSF)& 0x000ff000) >> 12); 2213 pMgmt->abyCurrBSSID[1] = (u8)((qwCurrTSF & 0x000ff000) >> 12);
2428 pMgmt->abyCurrBSSID[0] = (BYTE)((LODWORD(qwCurrTSF)& 0x0ff00000) >> 20); 2214 pMgmt->abyCurrBSSID[0] = (u8)((qwCurrTSF & 0x0ff00000) >> 20);
2429 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0]; 2215 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
2430 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1]; 2216 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
2431 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2]; 2217 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
@@ -2446,7 +2232,7 @@ void vMgrCreateOwnIBSS(void *hDeviceContext,
2446 2232
2447 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID); 2233 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2448 pDevice->byRxMode |= RCR_BSSID; 2234 pDevice->byRxMode |= RCR_BSSID;
2449 pMgmt->bCurrBSSIDFilterOn = TRUE; 2235 pMgmt->bCurrBSSIDFilterOn = true;
2450 2236
2451 // Set Capability Info 2237 // Set Capability Info
2452 pMgmt->wCurrCapInfo = 0; 2238 pMgmt->wCurrCapInfo = 0;
@@ -2511,26 +2297,25 @@ void vMgrCreateOwnIBSS(void *hDeviceContext,
2511 * 2297 *
2512-*/ 2298-*/
2513 2299
2514void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus) 2300void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
2515{ 2301{
2516 PSDevice pDevice = (PSDevice)hDeviceContext; 2302 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2517 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 2303 PKnownBSS pCurr = NULL;
2518 PKnownBSS pCurr = NULL; 2304 int ii, uu;
2519 unsigned int ii, uu; 2305 PWLAN_IE_SUPP_RATES pItemRates = NULL;
2520 PWLAN_IE_SUPP_RATES pItemRates = NULL; 2306 PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
2521 PWLAN_IE_SUPP_RATES pItemExtRates = NULL; 2307 PWLAN_IE_SSID pItemSSID;
2522 PWLAN_IE_SSID pItemSSID; 2308 u32 uRateLen = WLAN_RATES_MAXLEN;
2523 unsigned int uRateLen = WLAN_RATES_MAXLEN; 2309 u16 wMaxBasicRate = RATE_1M;
2524 WORD wMaxBasicRate = RATE_1M; 2310 u16 wMaxSuppRate = RATE_1M;
2525 WORD wMaxSuppRate = RATE_1M; 2311 u16 wSuppRate;
2526 WORD wSuppRate; 2312 u8 byTopCCKBasicRate = RATE_1M;
2527 BYTE byTopCCKBasicRate = RATE_1M; 2313 u8 byTopOFDMBasicRate = RATE_1M;
2528 BYTE byTopOFDMBasicRate = RATE_1M; 2314 u8 bShortSlotTime = false;
2529 BOOL bShortSlotTime = FALSE;
2530 2315
2531 2316
2532 for (ii = 0; ii < MAX_BSS_NUM; ii++) { 2317 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
2533 if (pMgmt->sBSSList[ii].bActive == TRUE) 2318 if (pMgmt->sBSSList[ii].bActive == true)
2534 break; 2319 break;
2535 } 2320 }
2536 2321
@@ -2564,14 +2349,14 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2564 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) { 2349 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
2565 /* 2350 /*
2566 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { 2351 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2567 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == FALSE) { 2352 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
2568 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); 2353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2569 // encryption mode error 2354 // encryption mode error
2570 pMgmt->eCurrState = WMAC_STATE_IDLE; 2355 pMgmt->eCurrState = WMAC_STATE_IDLE;
2571 return; 2356 return;
2572 } 2357 }
2573 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { 2358 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2574 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == FALSE) { 2359 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
2575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); 2360 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2576 // encryption mode error 2361 // encryption mode error
2577 pMgmt->eCurrState = WMAC_STATE_IDLE; 2362 pMgmt->eCurrState = WMAC_STATE_IDLE;
@@ -2581,7 +2366,7 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2581*/ 2366*/
2582 } 2367 }
2583 2368
2584 //if(pDevice->bWPASuppWextEnabled == TRUE) 2369 //if(pDevice->bWPASuppWextEnabled == true)
2585 Encyption_Rebuild(pDevice, pCurr); 2370 Encyption_Rebuild(pDevice, pCurr);
2586 2371
2587 // Infrastructure BSS 2372 // Infrastructure BSS
@@ -2637,7 +2422,7 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2637 } 2422 }
2638 } 2423 }
2639 2424
2640 RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, TRUE, 2425 RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
2641 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate, 2426 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2642 &byTopCCKBasicRate, &byTopOFDMBasicRate); 2427 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2643 vUpdateIFS(pDevice); 2428 vUpdateIFS(pDevice);
@@ -2658,11 +2443,11 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2658 // Add current BSS to Candidate list 2443 // Add current BSS to Candidate list
2659 // This should only work for WPA2 BSS, and WPA2 BSS check must be done before. 2444 // This should only work for WPA2 BSS, and WPA2 BSS check must be done before.
2660 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) { 2445 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
2661 BOOL bResult = bAdd_PMKID_Candidate((void *) pDevice, 2446 bool bResult = bAdd_PMKID_Candidate((void *) pDevice,
2662 pMgmt->abyCurrBSSID, 2447 pMgmt->abyCurrBSSID,
2663 &pCurr->sRSNCapObj); 2448 &pCurr->sRSNCapObj);
2664 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult); 2449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
2665 if (bResult == FALSE) { 2450 if (bResult == false) {
2666 vFlush_PMKID_Candidate((void *) pDevice); 2451 vFlush_PMKID_Candidate((void *) pDevice);
2667 DBG_PRT(MSG_LEVEL_DEBUG, 2452 DBG_PRT(MSG_LEVEL_DEBUG,
2668 KERN_INFO "vFlush_PMKID_Candidate: 4\n"); 2453 KERN_INFO "vFlush_PMKID_Candidate: 4\n");
@@ -2712,10 +2497,10 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2712 //DBG_PRN_WLAN05(("wCapInfo: %X\n", pCurr->wCapInfo)); 2497 //DBG_PRN_WLAN05(("wCapInfo: %X\n", pCurr->wCapInfo));
2713 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo) != pDevice->bShortSlotTime) { 2498 if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo) != pDevice->bShortSlotTime) {
2714 if (pDevice->byBBType == BB_TYPE_11A) { 2499 if (pDevice->byBBType == BB_TYPE_11A) {
2715 bShortSlotTime = TRUE; 2500 bShortSlotTime = true;
2716 } 2501 }
2717 else if (pDevice->byBBType == BB_TYPE_11B) { 2502 else if (pDevice->byBBType == BB_TYPE_11B) {
2718 bShortSlotTime = FALSE; 2503 bShortSlotTime = false;
2719 } 2504 }
2720 else { 2505 else {
2721 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo); 2506 bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo);
@@ -2742,7 +2527,7 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2742 2527
2743 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { 2528 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2744/* 2529/*
2745 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == FALSE) { 2530 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
2746 // encryption mode error 2531 // encryption mode error
2747 pMgmt->eCurrState = WMAC_STATE_IDLE; 2532 pMgmt->eCurrState = WMAC_STATE_IDLE;
2748 return; 2533 return;
@@ -2750,7 +2535,7 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2750*/ 2535*/
2751 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { 2536 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2752/* 2537/*
2753 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == FALSE) { 2538 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
2754 // encryption mode error 2539 // encryption mode error
2755 pMgmt->eCurrState = WMAC_STATE_IDLE; 2540 pMgmt->eCurrState = WMAC_STATE_IDLE;
2756 return; 2541 return;
@@ -2783,7 +2568,7 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2783 // set basic rate 2568 // set basic rate
2784 RATEvParseMaxRate((void *)pDevice, 2569 RATEvParseMaxRate((void *)pDevice,
2785 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates, 2570 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2786 NULL, TRUE, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate, 2571 NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2787 &byTopCCKBasicRate, &byTopOFDMBasicRate); 2572 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2788 vUpdateIFS(pDevice); 2573 vUpdateIFS(pDevice);
2789 pMgmt->wCurrCapInfo = pCurr->wCapInfo; 2574 pMgmt->wCurrCapInfo = pCurr->wCapInfo;
@@ -2796,7 +2581,7 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2796 pMgmt->eCurrState = WMAC_STATE_STARTED; 2581 pMgmt->eCurrState = WMAC_STATE_STARTED;
2797 // Adopt BSS state in Adapter Device Object 2582 // Adopt BSS state in Adapter Device Object
2798 pDevice->eOPMode = OP_MODE_ADHOC; 2583 pDevice->eOPMode = OP_MODE_ADHOC;
2799 pDevice->bLinkPass = TRUE; 2584 pDevice->bLinkPass = true;
2800 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER); 2585 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_INTER);
2801 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN); 2586 memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2802 2587
@@ -2836,30 +2621,27 @@ void vMgrJoinBSSBegin(void *hDeviceContext, PCMD_STATUS pStatus)
2836 * PCM_STATUS 2621 * PCM_STATUS
2837 * 2622 *
2838-*/ 2623-*/
2839static 2624static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode,
2840void 2625 PKnownBSS pCurr, PCMD_STATUS pStatus)
2841s_vMgrSynchBSS (
2842 PSDevice pDevice,
2843 unsigned int uBSSMode,
2844 PKnownBSS pCurr,
2845 PCMD_STATUS pStatus
2846 )
2847{ 2626{
2848 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 2627 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
2849 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M 2628 u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
2850 BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C}; 2629 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
2851 BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60}; 2630 /* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
2852 //6M, 9M, 12M, 48M 2631 u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
2853 BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; 2632 4, 0x0C, 0x12, 0x18, 0x60};
2854 BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16}; 2633 /* 6M, 9M, 12M, 48M*/
2855 2634 u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
2635 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2636 u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
2637 4, 0x02, 0x04, 0x0B, 0x16};
2856 2638
2857 *pStatus = CMD_STATUS_FAILURE; 2639 *pStatus = CMD_STATUS_FAILURE;
2858 2640
2859 if (s_bCipherMatch(pCurr, 2641 if (s_bCipherMatch(pCurr,
2860 pDevice->eEncryptionStatus, 2642 pDevice->eEncryptionStatus,
2861 &(pMgmt->byCSSPK), 2643 &(pMgmt->byCSSPK),
2862 &(pMgmt->byCSSGK)) == FALSE) { 2644 &(pMgmt->byCSSGK)) == false) {
2863 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "s_bCipherMatch Fail .......\n"); 2645 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "s_bCipherMatch Fail .......\n");
2864 return; 2646 return;
2865 } 2647 }
@@ -2872,12 +2654,12 @@ s_vMgrSynchBSS (
2872 } 2654 }
2873 2655
2874 // Init the BSS informations 2656 // Init the BSS informations
2875 pDevice->bCCK = TRUE; 2657 pDevice->bCCK = true;
2876 pDevice->bProtectMode = FALSE; 2658 pDevice->bProtectMode = false;
2877 MACvDisableProtectMD(pDevice); 2659 MACvDisableProtectMD(pDevice);
2878 pDevice->bBarkerPreambleMd = FALSE; 2660 pDevice->bBarkerPreambleMd = false;
2879 MACvDisableBarkerPreambleMd(pDevice); 2661 MACvDisableBarkerPreambleMd(pDevice);
2880 pDevice->bNonERPPresent = FALSE; 2662 pDevice->bNonERPPresent = false;
2881 pDevice->byPreambleType = 0; 2663 pDevice->byPreambleType = 0;
2882 pDevice->wBasicRate = 0; 2664 pDevice->wBasicRate = 0;
2883 // Set Basic Rate 2665 // Set Basic Rate
@@ -2907,7 +2689,7 @@ s_vMgrSynchBSS (
2907 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) { 2689 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2908 pDevice->byBBType = BB_TYPE_11A; 2690 pDevice->byBBType = BB_TYPE_11A;
2909 pMgmt->eCurrentPHYMode = PHY_TYPE_11A; 2691 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2910 pDevice->bShortSlotTime = TRUE; 2692 pDevice->bShortSlotTime = true;
2911 BBvSetShortSlotTime(pDevice); 2693 BBvSetShortSlotTime(pDevice);
2912 CARDvSetBSSMode(pDevice); 2694 CARDvSetBSSMode(pDevice);
2913 } else { 2695 } else {
@@ -2919,7 +2701,7 @@ s_vMgrSynchBSS (
2919 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) { 2701 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2920 pDevice->byBBType = BB_TYPE_11B; 2702 pDevice->byBBType = BB_TYPE_11B;
2921 pMgmt->eCurrentPHYMode = PHY_TYPE_11B; 2703 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2922 pDevice->bShortSlotTime = FALSE; 2704 pDevice->bShortSlotTime = false;
2923 BBvSetShortSlotTime(pDevice); 2705 BBvSetShortSlotTime(pDevice);
2924 CARDvSetBSSMode(pDevice); 2706 CARDvSetBSSMode(pDevice);
2925 } else { 2707 } else {
@@ -2930,12 +2712,12 @@ s_vMgrSynchBSS (
2930 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) { 2712 (pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
2931 pDevice->byBBType = BB_TYPE_11G; 2713 pDevice->byBBType = BB_TYPE_11G;
2932 pMgmt->eCurrentPHYMode = PHY_TYPE_11G; 2714 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2933 pDevice->bShortSlotTime = TRUE; 2715 pDevice->bShortSlotTime = true;
2934 BBvSetShortSlotTime(pDevice); 2716 BBvSetShortSlotTime(pDevice);
2935 CARDvSetBSSMode(pDevice); 2717 CARDvSetBSSMode(pDevice);
2936 } else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) { 2718 } else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) {
2937 pDevice->byBBType = BB_TYPE_11B; 2719 pDevice->byBBType = BB_TYPE_11B;
2938 pDevice->bShortSlotTime = FALSE; 2720 pDevice->bShortSlotTime = false;
2939 BBvSetShortSlotTime(pDevice); 2721 BBvSetShortSlotTime(pDevice);
2940 CARDvSetBSSMode(pDevice); 2722 CARDvSetBSSMode(pDevice);
2941 } else { 2723 } else {
@@ -2947,7 +2729,7 @@ s_vMgrSynchBSS (
2947 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC); 2729 MACvRegBitsOff(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2948 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID); 2730 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2949 pDevice->byRxMode |= RCR_BSSID; 2731 pDevice->byRxMode |= RCR_BSSID;
2950 pMgmt->bCurrBSSIDFilterOn = TRUE; 2732 pMgmt->bCurrBSSIDFilterOn = true;
2951 } 2733 }
2952 2734
2953 // set channel and clear NAV 2735 // set channel and clear NAV
@@ -2971,7 +2753,7 @@ s_vMgrSynchBSS (
2971 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC); 2753 MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2972 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID); 2754 MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
2973 pDevice->byRxMode |= RCR_BSSID; 2755 pDevice->byRxMode |= RCR_BSSID;
2974 pMgmt->bCurrBSSIDFilterOn = TRUE; 2756 pMgmt->bCurrBSSIDFilterOn = true;
2975 } 2757 }
2976 2758
2977 if (pDevice->byBBType == BB_TYPE_11A) { 2759 if (pDevice->byBBType == BB_TYPE_11A) {
@@ -2991,21 +2773,13 @@ s_vMgrSynchBSS (
2991 return; 2773 return;
2992}; 2774};
2993 2775
2994 2776static void Encyption_Rebuild(struct vnt_private *pDevice, PKnownBSS pCurr)
2995//mike add: fix NetworkManager 0.7.0 hidden ssid mode in WPA encryption
2996// ,need reset eAuthenMode and eEncryptionStatus
2997 static void Encyption_Rebuild(
2998 PSDevice pDevice,
2999 PKnownBSS pCurr
3000 )
3001 { 2777 {
3002 PSMgmtObject pMgmt = &(pDevice->sMgmtObj); 2778 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
3003 /* unsigned int ii, uSameBssidNum=0; */
3004 2779
3005 // if( uSameBssidNum>=2) { //we only check AP in hidden sssid mode 2780 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3006 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || //networkmanager 0.7.0 does not give the pairwise-key selsection, 2781 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
3007 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { // so we need re-selsect it according to real pairwise-key info. 2782 if (pCurr->bWPAValid == true) { /*WPA-PSK */
3008 if(pCurr->bWPAValid == TRUE) { //WPA-PSK
3009 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK; 2783 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
3010 if(pCurr->abyPKType[0] == WPA_TKIP) { 2784 if(pCurr->abyPKType[0] == WPA_TKIP) {
3011 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP 2785 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
@@ -3016,7 +2790,7 @@ s_vMgrSynchBSS (
3016 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n"); 2790 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
3017 } 2791 }
3018 } 2792 }
3019 else if(pCurr->bWPA2Valid == TRUE) { //WPA2-PSK 2793 else if(pCurr->bWPA2Valid == true) { //WPA2-PSK
3020 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK; 2794 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
3021 if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) { 2795 if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
3022 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP 2796 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
@@ -3044,20 +2818,15 @@ s_vMgrSynchBSS (
3044 * 2818 *
3045-*/ 2819-*/
3046 2820
3047static 2821static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM)
3048void
3049s_vMgrFormatTIM(
3050 PSMgmtObject pMgmt,
3051 PWLAN_IE_TIM pTIM
3052 )
3053{ 2822{
3054 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80}; 2823 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
3055 BYTE byMap; 2824 u8 byMap;
3056 unsigned int ii, jj; 2825 int ii, jj;
3057 BOOL bStartFound = FALSE; 2826 int bStartFound = false;
3058 BOOL bMulticast = FALSE; 2827 int bMulticast = false;
3059 WORD wStartIndex = 0; 2828 u16 wStartIndex = 0;
3060 WORD wEndIndex = 0; 2829 u16 wEndIndex = 0;
3061 2830
3062 2831
3063 // Find size of partial virtual bitmap 2832 // Find size of partial virtual bitmap
@@ -3067,13 +2836,13 @@ s_vMgrFormatTIM(
3067 // Mask out the broadcast bit which is indicated separately. 2836 // Mask out the broadcast bit which is indicated separately.
3068 bMulticast = (byMap & byMask[0]) != 0; 2837 bMulticast = (byMap & byMask[0]) != 0;
3069 if(bMulticast) { 2838 if(bMulticast) {
3070 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE; 2839 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
3071 } 2840 }
3072 byMap = 0; 2841 byMap = 0;
3073 } 2842 }
3074 if (byMap) { 2843 if (byMap) {
3075 if (!bStartFound) { 2844 if (!bStartFound) {
3076 bStartFound = TRUE; 2845 bStartFound = true;
3077 wStartIndex = (WORD)ii; 2846 wStartIndex = (WORD)ii;
3078 } 2847 }
3079 wEndIndex = (WORD)ii; 2848 wEndIndex = (WORD)ii;
@@ -3119,30 +2888,23 @@ s_vMgrFormatTIM(
3119 * 2888 *
3120-*/ 2889-*/
3121 2890
3122static 2891static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
3123PSTxMgmtPacket 2892 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
3124s_MgrMakeBeacon( 2893 u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
3125 PSDevice pDevice, 2894 u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3126 PSMgmtObject pMgmt, 2895 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3127 WORD wCurrCapInfo,
3128 WORD wCurrBeaconPeriod,
3129 unsigned int uCurrChannel,
3130 WORD wCurrATIMWinodw,
3131 PWLAN_IE_SSID pCurrSSID,
3132 PBYTE pCurrBSSID,
3133 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3134 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3135 )
3136{ 2896{
3137 PSTxMgmtPacket pTxPacket = NULL; 2897 struct vnt_tx_mgmt *pTxPacket = NULL;
3138 WLAN_FR_BEACON sFrame; 2898 WLAN_FR_BEACON sFrame;
3139 BYTE abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 2899 u8 abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3140 2900
3141 2901
3142 // prepare beacon frame 2902 /* prepare beacon frame */
3143 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 2903 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3144 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN); 2904 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3145 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 2905 + WLAN_BEACON_FR_MAXLEN);
2906 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
2907 + sizeof(struct vnt_tx_mgmt));
3146 // Setup the sFrame structure. 2908 // Setup the sFrame structure.
3147 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 2909 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3148 sFrame.len = WLAN_BEACON_FR_MAXLEN; 2910 sFrame.len = WLAN_BEACON_FR_MAXLEN;
@@ -3243,11 +3005,11 @@ s_MgrMakeBeacon(
3243 sFrame.pERP->byElementID = WLAN_EID_ERP; 3005 sFrame.pERP->byElementID = WLAN_EID_ERP;
3244 sFrame.pERP->len = 1; 3006 sFrame.pERP->len = 1;
3245 sFrame.pERP->byContext = 0; 3007 sFrame.pERP->byContext = 0;
3246 if (pDevice->bProtectMode == TRUE) 3008 if (pDevice->bProtectMode == true)
3247 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION; 3009 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3248 if (pDevice->bNonERPPresent == TRUE) 3010 if (pDevice->bNonERPPresent == true)
3249 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT; 3011 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3250 if (pDevice->bBarkerPreambleMd == TRUE) 3012 if (pDevice->bBarkerPreambleMd == true)
3251 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE; 3013 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3252 } 3014 }
3253 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) { 3015 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
@@ -3259,7 +3021,7 @@ s_MgrMakeBeacon(
3259 ); 3021 );
3260 } 3022 }
3261 // hostapd wpa/wpa2 IE 3023 // hostapd wpa/wpa2 IE
3262 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == TRUE)) { 3024 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
3263 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) { 3025 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3264 if (pMgmt->wWPAIELen != 0) { 3026 if (pMgmt->wWPAIELen != 0) {
3265 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len); 3027 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
@@ -3294,30 +3056,22 @@ s_MgrMakeBeacon(
3294 3056
3295 3057
3296 3058
3297PSTxMgmtPacket 3059struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *pDevice,
3298s_MgrMakeProbeResponse( 3060 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
3299 PSDevice pDevice, 3061 u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
3300 PSMgmtObject pMgmt, 3062 PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
3301 WORD wCurrCapInfo, 3063 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3302 WORD wCurrBeaconPeriod, 3064 PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType)
3303 unsigned int uCurrChannel,
3304 WORD wCurrATIMWinodw,
3305 PBYTE pDstAddr,
3306 PWLAN_IE_SSID pCurrSSID,
3307 PBYTE pCurrBSSID,
3308 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3309 PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
3310 BYTE byPHYType
3311 )
3312{ 3065{
3313 PSTxMgmtPacket pTxPacket = NULL; 3066 struct vnt_tx_mgmt *pTxPacket = NULL;
3314 WLAN_FR_PROBERESP sFrame; 3067 WLAN_FR_PROBERESP sFrame;
3315
3316 3068
3317 3069
3318 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 3070 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3319 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN); 3071 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3320 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 3072 + WLAN_PROBERESP_FR_MAXLEN);
3073 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3074 + sizeof(struct vnt_tx_mgmt));
3321 // Setup the sFrame structure. 3075 // Setup the sFrame structure.
3322 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 3076 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3323 sFrame.len = WLAN_PROBERESP_FR_MAXLEN; 3077 sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
@@ -3377,11 +3131,11 @@ s_MgrMakeProbeResponse(
3377 sFrame.pERP->byElementID = WLAN_EID_ERP; 3131 sFrame.pERP->byElementID = WLAN_EID_ERP;
3378 sFrame.pERP->len = 1; 3132 sFrame.pERP->len = 1;
3379 sFrame.pERP->byContext = 0; 3133 sFrame.pERP->byContext = 0;
3380 if (pDevice->bProtectMode == TRUE) 3134 if (pDevice->bProtectMode == true)
3381 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION; 3135 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3382 if (pDevice->bNonERPPresent == TRUE) 3136 if (pDevice->bNonERPPresent == true)
3383 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT; 3137 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3384 if (pDevice->bBarkerPreambleMd == TRUE) 3138 if (pDevice->bBarkerPreambleMd == true)
3385 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE; 3139 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3386 } 3140 }
3387 3141
@@ -3395,7 +3149,7 @@ s_MgrMakeProbeResponse(
3395 } 3149 }
3396 3150
3397 // hostapd wpa/wpa2 IE 3151 // hostapd wpa/wpa2 IE
3398 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == TRUE)) { 3152 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == true)) {
3399 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) { 3153 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3400 if (pMgmt->wWPAIELen != 0) { 3154 if (pMgmt->wWPAIELen != 0) {
3401 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len); 3155 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
@@ -3426,27 +3180,24 @@ s_MgrMakeProbeResponse(
3426-*/ 3180-*/
3427 3181
3428 3182
3429PSTxMgmtPacket 3183struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *pDevice,
3430s_MgrMakeAssocRequest( 3184 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3431 PSDevice pDevice, 3185 u16 wListenInterval,
3432 PSMgmtObject pMgmt, 3186 PWLAN_IE_SSID pCurrSSID,
3433 PBYTE pDAddr, 3187 PWLAN_IE_SUPP_RATES pCurrRates,
3434 WORD wCurrCapInfo, 3188 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3435 WORD wListenInterval,
3436 PWLAN_IE_SSID pCurrSSID,
3437 PWLAN_IE_SUPP_RATES pCurrRates,
3438 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3439 )
3440{ 3189{
3441 PSTxMgmtPacket pTxPacket = NULL; 3190 struct vnt_tx_mgmt *pTxPacket = NULL;
3442 WLAN_FR_ASSOCREQ sFrame; 3191 WLAN_FR_ASSOCREQ sFrame;
3443 PBYTE pbyIEs; 3192 u8 *pbyIEs;
3444 PBYTE pbyRSN; 3193 u8 *pbyRSN;
3445 3194
3446 3195
3447 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 3196 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3448 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN); 3197 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3449 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 3198 + WLAN_ASSOCREQ_FR_MAXLEN);
3199 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3200 + sizeof(struct vnt_tx_mgmt));
3450 // Setup the sFrame structure. 3201 // Setup the sFrame structure.
3451 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 3202 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3452 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN; 3203 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
@@ -3625,7 +3376,7 @@ s_MgrMakeAssocRequest(
3625 sFrame.pRSN->len +=6; 3376 sFrame.pRSN->len +=6;
3626 3377
3627 // RSN Capabilites 3378 // RSN Capabilites
3628 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) { 3379 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
3629 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2); 3380 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3630 } else { 3381 } else {
3631 sFrame.pRSN->abyRSN[16] = 0; 3382 sFrame.pRSN->abyRSN[16] = 0;
@@ -3633,7 +3384,7 @@ s_MgrMakeAssocRequest(
3633 } 3384 }
3634 sFrame.pRSN->len +=2; 3385 sFrame.pRSN->len +=2;
3635 3386
3636 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == TRUE) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { 3387 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3637 // RSN PMKID 3388 // RSN PMKID
3638 pbyRSN = &sFrame.pRSN->abyRSN[18]; 3389 pbyRSN = &sFrame.pRSN->abyRSN[18];
3639 pwPMKID = (PWORD)pbyRSN; // Point to PMKID count 3390 pwPMKID = (PWORD)pbyRSN; // Point to PMKID count
@@ -3688,27 +3439,23 @@ s_MgrMakeAssocRequest(
3688-*/ 3439-*/
3689 3440
3690 3441
3691PSTxMgmtPacket 3442struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *pDevice,
3692s_MgrMakeReAssocRequest( 3443 struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
3693 PSDevice pDevice, 3444 u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
3694 PSMgmtObject pMgmt, 3445 PWLAN_IE_SUPP_RATES pCurrRates,
3695 PBYTE pDAddr, 3446 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3696 WORD wCurrCapInfo,
3697 WORD wListenInterval,
3698 PWLAN_IE_SSID pCurrSSID,
3699 PWLAN_IE_SUPP_RATES pCurrRates,
3700 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3701 )
3702{ 3447{
3703 PSTxMgmtPacket pTxPacket = NULL; 3448 struct vnt_tx_mgmt *pTxPacket = NULL;
3704 WLAN_FR_REASSOCREQ sFrame; 3449 WLAN_FR_REASSOCREQ sFrame;
3705 PBYTE pbyIEs; 3450 u8 *pbyIEs;
3706 PBYTE pbyRSN; 3451 u8 *pbyRSN;
3707 3452
3708 3453
3709 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 3454 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3710 memset( pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN); 3455 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3711 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 3456 + WLAN_REASSOCREQ_FR_MAXLEN);
3457 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3458 + sizeof(struct vnt_tx_mgmt));
3712 /* Setup the sFrame structure. */ 3459 /* Setup the sFrame structure. */
3713 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 3460 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3714 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN; 3461 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
@@ -3885,7 +3632,7 @@ s_MgrMakeReAssocRequest(
3885 sFrame.pRSN->len +=6; 3632 sFrame.pRSN->len +=6;
3886 3633
3887 // RSN Capabilites 3634 // RSN Capabilites
3888 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) { 3635 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
3889 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2); 3636 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3890 } else { 3637 } else {
3891 sFrame.pRSN->abyRSN[16] = 0; 3638 sFrame.pRSN->abyRSN[16] = 0;
@@ -3893,7 +3640,7 @@ s_MgrMakeReAssocRequest(
3893 } 3640 }
3894 sFrame.pRSN->len +=2; 3641 sFrame.pRSN->len +=2;
3895 3642
3896 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == TRUE) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { 3643 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == true) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3897 // RSN PMKID 3644 // RSN PMKID
3898 pbyRSN = &sFrame.pRSN->abyRSN[18]; 3645 pbyRSN = &sFrame.pRSN->abyRSN[18];
3899 pwPMKID = (PWORD)pbyRSN; // Point to PMKID count 3646 pwPMKID = (PWORD)pbyRSN; // Point to PMKID count
@@ -3942,25 +3689,20 @@ s_MgrMakeReAssocRequest(
3942 * 3689 *
3943-*/ 3690-*/
3944 3691
3945PSTxMgmtPacket 3692struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *pDevice,
3946s_MgrMakeAssocResponse( 3693 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
3947 PSDevice pDevice, 3694 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
3948 PSMgmtObject pMgmt, 3695 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
3949 WORD wCurrCapInfo,
3950 WORD wAssocStatus,
3951 WORD wAssocAID,
3952 PBYTE pDstAddr,
3953 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3954 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3955 )
3956{ 3696{
3957 PSTxMgmtPacket pTxPacket = NULL; 3697 struct vnt_tx_mgmt *pTxPacket = NULL;
3958 WLAN_FR_ASSOCRESP sFrame; 3698 WLAN_FR_ASSOCRESP sFrame;
3959 3699
3960 3700
3961 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 3701 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
3962 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN); 3702 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
3963 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 3703 + WLAN_ASSOCREQ_FR_MAXLEN);
3704 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3705 + sizeof(struct vnt_tx_mgmt));
3964 // Setup the sFrame structure 3706 // Setup the sFrame structure
3965 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 3707 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3966 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN; 3708 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
@@ -4016,25 +3758,20 @@ s_MgrMakeAssocResponse(
4016-*/ 3758-*/
4017 3759
4018 3760
4019PSTxMgmtPacket 3761struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *pDevice,
4020s_MgrMakeReAssocResponse( 3762 struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
4021 PSDevice pDevice, 3763 u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
4022 PSMgmtObject pMgmt, 3764 PWLAN_IE_SUPP_RATES pCurrExtSuppRates)
4023 WORD wCurrCapInfo,
4024 WORD wAssocStatus,
4025 WORD wAssocAID,
4026 PBYTE pDstAddr,
4027 PWLAN_IE_SUPP_RATES pCurrSuppRates,
4028 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
4029 )
4030{ 3765{
4031 PSTxMgmtPacket pTxPacket = NULL; 3766 struct vnt_tx_mgmt *pTxPacket = NULL;
4032 WLAN_FR_REASSOCRESP sFrame; 3767 WLAN_FR_REASSOCRESP sFrame;
4033 3768
4034 3769
4035 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool; 3770 pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
4036 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN); 3771 memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
4037 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket)); 3772 + WLAN_ASSOCREQ_FR_MAXLEN);
3773 pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
3774 + sizeof(struct vnt_tx_mgmt));
4038 // Setup the sFrame structure 3775 // Setup the sFrame structure
4039 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header; 3776 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
4040 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN; 3777 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
@@ -4089,19 +3826,14 @@ s_MgrMakeReAssocResponse(
4089 * 3826 *
4090-*/ 3827-*/
4091 3828
4092static 3829static void s_vMgrRxProbeResponse(struct vnt_private *pDevice,
4093void 3830 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
4094s_vMgrRxProbeResponse(
4095 PSDevice pDevice,
4096 PSMgmtObject pMgmt,
4097 PSRxMgmtPacket pRxPacket
4098 )
4099{ 3831{
4100 PKnownBSS pBSSList = NULL; 3832 PKnownBSS pBSSList = NULL;
4101 WLAN_FR_PROBERESP sFrame; 3833 WLAN_FR_PROBERESP sFrame;
4102 BYTE byCurrChannel = pRxPacket->byRxChannel; 3834 u8 byCurrChannel = pRxPacket->byRxChannel;
4103 ERPObject sERP; 3835 ERPObject sERP;
4104 BOOL bChannelHit = TRUE; 3836 int bChannelHit = true;
4105 3837
4106 3838
4107 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP)); 3839 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
@@ -4132,31 +3864,31 @@ s_vMgrRxProbeResponse(
4132 if (sFrame.pDSParms) { 3864 if (sFrame.pDSParms) {
4133 if (byCurrChannel == 3865 if (byCurrChannel ==
4134 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]) 3866 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
4135 bChannelHit = TRUE; 3867 bChannelHit = true;
4136 byCurrChannel = 3868 byCurrChannel =
4137 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1]; 3869 RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
4138 } else { 3870 } else {
4139 bChannelHit = TRUE; 3871 bChannelHit = true;
4140 } 3872 }
4141 } else { 3873 } else {
4142 if (sFrame.pDSParms) { 3874 if (sFrame.pDSParms) {
4143 if (byCurrChannel == sFrame.pDSParms->byCurrChannel) 3875 if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
4144 bChannelHit = TRUE; 3876 bChannelHit = true;
4145 byCurrChannel = sFrame.pDSParms->byCurrChannel; 3877 byCurrChannel = sFrame.pDSParms->byCurrChannel;
4146 } else { 3878 } else {
4147 bChannelHit = TRUE; 3879 bChannelHit = true;
4148 } 3880 }
4149 } 3881 }
4150 //RobertYu:20050201 3882 //RobertYu:20050201
4151 3883
4152if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE) 3884if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
4153 return; 3885 return;
4154 3886
4155 if (sFrame.pERP) { 3887 if (sFrame.pERP) {
4156 sERP.byERP = sFrame.pERP->byContext; 3888 sERP.byERP = sFrame.pERP->byContext;
4157 sERP.bERPExist = TRUE; 3889 sERP.bERPExist = true;
4158 } else { 3890 } else {
4159 sERP.bERPExist = FALSE; 3891 sERP.bERPExist = false;
4160 sERP.byERP = 0; 3892 sERP.byERP = 0;
4161 } 3893 }
4162 3894
@@ -4221,18 +3953,13 @@ if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
4221-*/ 3953-*/
4222 3954
4223 3955
4224static 3956static void s_vMgrRxProbeRequest(struct vnt_private *pDevice,
4225void 3957 struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
4226s_vMgrRxProbeRequest(
4227 PSDevice pDevice,
4228 PSMgmtObject pMgmt,
4229 PSRxMgmtPacket pRxPacket
4230 )
4231{ 3958{
4232 WLAN_FR_PROBEREQ sFrame; 3959 WLAN_FR_PROBEREQ sFrame;
4233 CMD_STATUS Status; 3960 CMD_STATUS Status;
4234 PSTxMgmtPacket pTxPacket; 3961 struct vnt_tx_mgmt *pTxPacket;
4235 BYTE byPHYType = BB_TYPE_11B; 3962 u8 byPHYType = BB_TYPE_11B;
4236 3963
4237 // STA in Ad-hoc mode: when latest TBTT beacon transmit success, 3964 // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
4238 // STA have to response this request. 3965 // STA have to response this request.
@@ -4307,15 +4034,13 @@ s_vMgrRxProbeRequest(
4307 * 4034 *
4308-*/ 4035-*/
4309 4036
4310void vMgrRxManagePacket(void *hDeviceContext, 4037void vMgrRxManagePacket(struct vnt_private *pDevice, struct vnt_manager *pMgmt,
4311 PSMgmtObject pMgmt, 4038 struct vnt_rx_mgmt *pRxPacket)
4312 PSRxMgmtPacket pRxPacket)
4313{ 4039{
4314 PSDevice pDevice = (PSDevice)hDeviceContext; 4040 int bInScan = false;
4315 BOOL bInScan = FALSE; 4041 u32 uNodeIndex = 0;
4316 unsigned int uNodeIndex = 0; 4042 NODE_STATE eNodeState = 0;
4317 NODE_STATE eNodeState = 0; 4043 CMD_STATUS Status;
4318 CMD_STATUS Status;
4319 4044
4320 4045
4321 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) { 4046 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
@@ -4348,7 +4073,7 @@ void vMgrRxManagePacket(void *hDeviceContext,
4348 case WLAN_FSTYPE_ASSOCRESP: 4073 case WLAN_FSTYPE_ASSOCRESP:
4349 // Frame Clase = 2 4074 // Frame Clase = 2
4350 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n"); 4075 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
4351 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, FALSE); 4076 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
4352 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n"); 4077 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
4353 break; 4078 break;
4354 4079
@@ -4375,7 +4100,7 @@ void vMgrRxManagePacket(void *hDeviceContext,
4375 case WLAN_FSTYPE_REASSOCRESP: 4100 case WLAN_FSTYPE_REASSOCRESP:
4376 // Frame Clase = 2 4101 // Frame Clase = 2
4377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n"); 4102 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
4378 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, TRUE); 4103 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
4379 break; 4104 break;
4380 4105
4381 case WLAN_FSTYPE_PROBEREQ: 4106 case WLAN_FSTYPE_PROBEREQ:
@@ -4395,7 +4120,7 @@ void vMgrRxManagePacket(void *hDeviceContext,
4395 // Frame Clase = 0 4120 // Frame Clase = 0
4396 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n"); 4121 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
4397 if (pMgmt->eScanState != WMAC_NO_SCANNING) { 4122 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
4398 bInScan = TRUE; 4123 bInScan = true;
4399 } 4124 }
4400 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan); 4125 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
4401 break; 4126 break;
@@ -4450,15 +4175,15 @@ void vMgrRxManagePacket(void *hDeviceContext,
4450 * Prepare beacon to send 4175 * Prepare beacon to send
4451 * 4176 *
4452 * Return Value: 4177 * Return Value:
4453 * TRUE if success; FALSE if failed. 4178 * true if success; false if failed.
4454 * 4179 *
4455-*/ 4180-*/
4456BOOL bMgrPrepareBeaconToSend(void *hDeviceContext, PSMgmtObject pMgmt) 4181int bMgrPrepareBeaconToSend(struct vnt_private *pDevice,
4182 struct vnt_manager *pMgmt)
4457{ 4183{
4458 PSDevice pDevice = (PSDevice)hDeviceContext; 4184 struct vnt_tx_mgmt *pTxPacket;
4459 PSTxMgmtPacket pTxPacket;
4460 4185
4461// pDevice->bBeaconBufReady = FALSE; 4186// pDevice->bBeaconBufReady = false;
4462 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){ 4187 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){
4463 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1); 4188 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
4464 } 4189 }
@@ -4481,12 +4206,12 @@ BOOL bMgrPrepareBeaconToSend(void *hDeviceContext, PSMgmtObject pMgmt)
4481 4206
4482 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && 4207 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
4483 (pMgmt->abyCurrBSSID[0] == 0)) 4208 (pMgmt->abyCurrBSSID[0] == 0))
4484 return FALSE; 4209 return false;
4485 4210
4486 csBeacon_xmit(pDevice, pTxPacket); 4211 csBeacon_xmit(pDevice, pTxPacket);
4487 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX); 4212 MACvRegBitsOn(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
4488 4213
4489 return TRUE; 4214 return true;
4490} 4215}
4491 4216
4492 4217
@@ -4504,12 +4229,7 @@ BOOL bMgrPrepareBeaconToSend(void *hDeviceContext, PSMgmtObject pMgmt)
4504 * none. 4229 * none.
4505 * 4230 *
4506-*/ 4231-*/
4507static 4232static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus)
4508void
4509s_vMgrLogStatus(
4510 PSMgmtObject pMgmt,
4511 WORD wStatus
4512 )
4513{ 4233{
4514 switch( wStatus ){ 4234 switch( wStatus ){
4515 case WLAN_MGMT_STATUS_UNSPEC_FAILURE: 4235 case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
@@ -4574,21 +4294,19 @@ s_vMgrLogStatus(
4574 * 4294 *
4575-*/ 4295-*/
4576 4296
4577BOOL bAdd_PMKID_Candidate(void *hDeviceContext, 4297int bAdd_PMKID_Candidate(struct vnt_private *pDevice, u8 *pbyBSSID,
4578 PBYTE pbyBSSID, 4298 PSRSNCapObject psRSNCapObj)
4579 PSRSNCapObject psRSNCapObj)
4580{ 4299{
4581 PSDevice pDevice = (PSDevice)hDeviceContext; 4300 PPMKID_CANDIDATE pCandidateList;
4582 PPMKID_CANDIDATE pCandidateList; 4301 int ii = 0;
4583 unsigned int ii = 0;
4584 4302
4585 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates); 4303 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4586 4304
4587 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL)) 4305 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
4588 return FALSE; 4306 return false;
4589 4307
4590 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) 4308 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
4591 return FALSE; 4309 return false;
4592 4310
4593 4311
4594 4312
@@ -4596,7 +4314,7 @@ BOOL bAdd_PMKID_Candidate(void *hDeviceContext,
4596 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) { 4314 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
4597 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii]; 4315 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
4598 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) { 4316 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
4599 if ((psRSNCapObj->bRSNCapExist == TRUE) 4317 if ((psRSNCapObj->bRSNCapExist == true)
4600 && (psRSNCapObj->wRSNCap & BIT0)) { 4318 && (psRSNCapObj->wRSNCap & BIT0)) {
4601 pCandidateList->Flags |= 4319 pCandidateList->Flags |=
4602 NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED; 4320 NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
@@ -4604,13 +4322,13 @@ BOOL bAdd_PMKID_Candidate(void *hDeviceContext,
4604 pCandidateList->Flags &= 4322 pCandidateList->Flags &=
4605 ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED); 4323 ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4606 } 4324 }
4607 return TRUE; 4325 return true;
4608 } 4326 }
4609 } 4327 }
4610 4328
4611 // New Candidate 4329 // New Candidate
4612 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates]; 4330 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
4613 if ((psRSNCapObj->bRSNCapExist == TRUE) && (psRSNCapObj->wRSNCap & BIT0)) { 4331 if ((psRSNCapObj->bRSNCapExist == true) && (psRSNCapObj->wRSNCap & BIT0)) {
4614 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED; 4332 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4615 } else { 4333 } else {
4616 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED); 4334 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
@@ -4618,7 +4336,7 @@ BOOL bAdd_PMKID_Candidate(void *hDeviceContext,
4618 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN); 4336 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
4619 pDevice->gsPMKIDCandidate.NumCandidates++; 4337 pDevice->gsPMKIDCandidate.NumCandidates++;
4620 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates); 4338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4621 return TRUE; 4339 return true;
4622} 4340}
4623 4341
4624/* 4342/*
@@ -4636,17 +4354,17 @@ BOOL bAdd_PMKID_Candidate(void *hDeviceContext,
4636 * 4354 *
4637-*/ 4355-*/
4638 4356
4639void vFlush_PMKID_Candidate(void *hDeviceContext) 4357void vFlush_PMKID_Candidate(struct vnt_private *pDevice)
4640{ 4358{
4641 PSDevice pDevice = (PSDevice)hDeviceContext; 4359 if (pDevice == NULL)
4360 return;
4642 4361
4643 if (pDevice == NULL) 4362 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
4644 return;
4645 4363
4646 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent)); 4364 return;
4647} 4365}
4648 4366
4649static BOOL 4367static bool
4650s_bCipherMatch ( 4368s_bCipherMatch (
4651 PKnownBSS pBSSNode, 4369 PKnownBSS pBSSNode,
4652 NDIS_802_11_ENCRYPTION_STATUS EncStatus, 4370 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
@@ -4659,7 +4377,7 @@ s_bCipherMatch (
4659 int i; 4377 int i;
4660 4378
4661 if (pBSSNode == NULL) 4379 if (pBSSNode == NULL)
4662 return FALSE; 4380 return false;
4663 4381
4664 // check cap. of BSS 4382 // check cap. of BSS
4665 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) && 4383 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
@@ -4669,7 +4387,7 @@ s_bCipherMatch (
4669 } 4387 }
4670 4388
4671 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) && 4389 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4672 (pBSSNode->bWPA2Valid == TRUE) && 4390 (pBSSNode->bWPA2Valid == true) &&
4673 4391
4674 ((EncStatus == Ndis802_11Encryption3Enabled) || 4392 ((EncStatus == Ndis802_11Encryption3Enabled) ||
4675 (EncStatus == Ndis802_11Encryption2Enabled))) { 4393 (EncStatus == Ndis802_11Encryption2Enabled))) {
@@ -4704,7 +4422,7 @@ s_bCipherMatch (
4704 } 4422 }
4705 4423
4706 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) && 4424 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4707 (pBSSNode->bWPAValid == TRUE) && 4425 (pBSSNode->bWPAValid == true) &&
4708 ((EncStatus == Ndis802_11Encryption2Enabled) || (EncStatus == Ndis802_11Encryption3Enabled))) { 4426 ((EncStatus == Ndis802_11Encryption2Enabled) || (EncStatus == Ndis802_11Encryption3Enabled))) {
4709 //WPA 4427 //WPA
4710 // check Group Key Cipher 4428 // check Group Key Cipher
@@ -4746,9 +4464,9 @@ s_bCipherMatch (
4746 (byCipherMask == 0)) { 4464 (byCipherMask == 0)) {
4747 *pbyCCSGK = KEY_CTL_WEP; 4465 *pbyCCSGK = KEY_CTL_WEP;
4748 *pbyCCSPK = KEY_CTL_NONE; 4466 *pbyCCSPK = KEY_CTL_NONE;
4749 return TRUE; 4467 return true;
4750 } else { 4468 } else {
4751 return FALSE; 4469 return false;
4752 } 4470 }
4753 4471
4754 } else if (EncStatus == Ndis802_11Encryption2Enabled) { 4472 } else if (EncStatus == Ndis802_11Encryption2Enabled) {
@@ -4756,45 +4474,45 @@ s_bCipherMatch (
4756 (byCipherMask == 0)) { 4474 (byCipherMask == 0)) {
4757 *pbyCCSGK = KEY_CTL_TKIP; 4475 *pbyCCSGK = KEY_CTL_TKIP;
4758 *pbyCCSPK = KEY_CTL_NONE; 4476 *pbyCCSPK = KEY_CTL_NONE;
4759 return TRUE; 4477 return true;
4760 } else if ((byMulticastCipher == KEY_CTL_WEP) && 4478 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4761 ((byCipherMask & 0x02) != 0)) { 4479 ((byCipherMask & 0x02) != 0)) {
4762 *pbyCCSGK = KEY_CTL_WEP; 4480 *pbyCCSGK = KEY_CTL_WEP;
4763 *pbyCCSPK = KEY_CTL_TKIP; 4481 *pbyCCSPK = KEY_CTL_TKIP;
4764 return TRUE; 4482 return true;
4765 } else if ((byMulticastCipher == KEY_CTL_TKIP) && 4483 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4766 ((byCipherMask & 0x02) != 0)) { 4484 ((byCipherMask & 0x02) != 0)) {
4767 *pbyCCSGK = KEY_CTL_TKIP; 4485 *pbyCCSGK = KEY_CTL_TKIP;
4768 *pbyCCSPK = KEY_CTL_TKIP; 4486 *pbyCCSPK = KEY_CTL_TKIP;
4769 return TRUE; 4487 return true;
4770 } else { 4488 } else {
4771 return FALSE; 4489 return false;
4772 } 4490 }
4773 } else if (EncStatus == Ndis802_11Encryption3Enabled) { 4491 } else if (EncStatus == Ndis802_11Encryption3Enabled) {
4774 if ((byMulticastCipher == KEY_CTL_CCMP) && 4492 if ((byMulticastCipher == KEY_CTL_CCMP) &&
4775 (byCipherMask == 0)) { 4493 (byCipherMask == 0)) {
4776 // When CCMP is enable, "Use group cipher suite" shall not be a valid option. 4494 // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
4777 return FALSE; 4495 return false;
4778 } else if ((byMulticastCipher == KEY_CTL_WEP) && 4496 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4779 ((byCipherMask & 0x04) != 0)) { 4497 ((byCipherMask & 0x04) != 0)) {
4780 *pbyCCSGK = KEY_CTL_WEP; 4498 *pbyCCSGK = KEY_CTL_WEP;
4781 *pbyCCSPK = KEY_CTL_CCMP; 4499 *pbyCCSPK = KEY_CTL_CCMP;
4782 return TRUE; 4500 return true;
4783 } else if ((byMulticastCipher == KEY_CTL_TKIP) && 4501 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4784 ((byCipherMask & 0x04) != 0)) { 4502 ((byCipherMask & 0x04) != 0)) {
4785 *pbyCCSGK = KEY_CTL_TKIP; 4503 *pbyCCSGK = KEY_CTL_TKIP;
4786 *pbyCCSPK = KEY_CTL_CCMP; 4504 *pbyCCSPK = KEY_CTL_CCMP;
4787 return TRUE; 4505 return true;
4788 } else if ((byMulticastCipher == KEY_CTL_CCMP) && 4506 } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
4789 ((byCipherMask & 0x04) != 0)) { 4507 ((byCipherMask & 0x04) != 0)) {
4790 *pbyCCSGK = KEY_CTL_CCMP; 4508 *pbyCCSGK = KEY_CTL_CCMP;
4791 *pbyCCSPK = KEY_CTL_CCMP; 4509 *pbyCCSPK = KEY_CTL_CCMP;
4792 return TRUE; 4510 return true;
4793 } else { 4511 } else {
4794 return FALSE; 4512 return false;
4795 } 4513 }
4796 } 4514 }
4797 return TRUE; 4515 return true;
4798} 4516}
4799 4517
4800 4518
diff --git a/drivers/staging/vt6656/wmgr.h b/drivers/staging/vt6656/wmgr.h
index 52b1b562b141..83aed45f68a3 100644
--- a/drivers/staging/vt6656/wmgr.h
+++ b/drivers/staging/vt6656/wmgr.h
@@ -218,216 +218,199 @@ typedef enum tagWMAC_POWER_MODE {
218 218
219 219
220 220
221// Tx Management Packet descriptor 221/* Tx Management Packet descriptor */
222typedef struct tagSTxMgmtPacket { 222struct vnt_tx_mgmt {
223 223 PUWLAN_80211HDR p80211Header;
224 PUWLAN_80211HDR p80211Header; 224 u32 cbMPDULen;
225 unsigned int cbMPDULen; 225 u32 cbPayloadLen;
226 unsigned int cbPayloadLen; 226};
227 227
228} STxMgmtPacket, *PSTxMgmtPacket; 228
229 229/* Rx Management Packet descriptor */
230 230struct vnt_rx_mgmt {
231// Rx Management Packet descriptor 231 PUWLAN_80211HDR p80211Header;
232typedef struct tagSRxMgmtPacket { 232 u64 qwLocalTSF;
233 233 u32 cbMPDULen;
234 PUWLAN_80211HDR p80211Header; 234 u32 cbPayloadLen;
235 QWORD qwLocalTSF; 235 u32 uRSSI;
236 unsigned int cbMPDULen; 236 u8 bySQ;
237 unsigned int cbPayloadLen; 237 u8 byRxRate;
238 unsigned int uRSSI; 238 u8 byRxChannel;
239 BYTE bySQ; 239};
240 BYTE byRxRate; 240
241 BYTE byRxChannel; 241
242 242struct vnt_manager {
243} SRxMgmtPacket, *PSRxMgmtPacket;
244
245
246
247typedef struct tagSMgmtObject
248{
249 void *pAdapter; 243 void *pAdapter;
250 // MAC address
251 BYTE abyMACAddr[WLAN_ADDR_LEN];
252
253 // Configuration Mode
254 WMAC_CONFIG_MODE eConfigMode; // MAC pre-configed mode
255
256 CARD_PHY_TYPE eCurrentPHYMode;
257
258
259 // Operation state variables
260 WMAC_CURRENT_MODE eCurrMode; // MAC current connection mode
261 WMAC_BSS_STATE eCurrState; // MAC current BSS state
262 WMAC_BSS_STATE eLastState; // MAC last BSS state
263
264 PKnownBSS pCurrBSS;
265 BYTE byCSSGK;
266 BYTE byCSSPK;
267
268// BYTE abyNewSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
269// BYTE abyNewExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
270 BOOL bCurrBSSIDFilterOn;
271
272 // Current state vars
273 unsigned int uCurrChannel;
274 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
275 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
276 BYTE abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
277 BYTE abyCurrBSSID[WLAN_BSSID_LEN];
278 WORD wCurrCapInfo;
279 WORD wCurrAID;
280 unsigned int uRSSITrigger;
281 WORD wCurrATIMWindow;
282 WORD wCurrBeaconPeriod;
283 BOOL bIsDS;
284 BYTE byERPContext;
285
286 CMD_STATE eCommandState;
287 unsigned int uScanChannel;
288
289 // Desire joinning BSS vars
290 BYTE abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
291 BYTE abyDesireBSSID[WLAN_BSSID_LEN];
292
293//restore BSS info for Ad-Hoc mode
294 BYTE abyAdHocSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
295
296 // Adhoc or AP configuration vars
297 WORD wIBSSBeaconPeriod;
298 WORD wIBSSATIMWindow;
299 unsigned int uIBSSChannel;
300 BYTE abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
301 BYTE byAPBBType;
302 BYTE abyWPAIE[MAX_WPA_IE_LEN];
303 WORD wWPAIELen;
304
305 unsigned int uAssocCount;
306 BOOL bMoreData;
307
308 // Scan state vars
309 WMAC_SCAN_STATE eScanState;
310 WMAC_SCAN_TYPE eScanType;
311 unsigned int uScanStartCh;
312 unsigned int uScanEndCh;
313 WORD wScanSteps;
314 unsigned int uScanBSSType;
315 // Desire scannig vars
316 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
317 BYTE abyScanBSSID[WLAN_BSSID_LEN];
318
319 // Privacy
320 WMAC_AUTHENTICATION_MODE eAuthenMode;
321 BOOL bShareKeyAlgorithm;
322 BYTE abyChallenge[WLAN_CHALLENGE_LEN];
323 BOOL bPrivacyInvoked;
324
325 // Received beacon state vars
326 BOOL bInTIM;
327 BOOL bMulticastTIM;
328 BYTE byDTIMCount;
329 BYTE byDTIMPeriod;
330
331 // Power saving state vars
332 WMAC_POWER_MODE ePSMode;
333 WORD wListenInterval;
334 WORD wCountToWakeUp;
335 BOOL bInTIMWake;
336 PBYTE pbyPSPacketPool;
337 BYTE byPSPacketPool[sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN];
338 BOOL bRxBeaconInTBTTWake;
339 BYTE abyPSTxMap[MAX_NODE_NUM + 1];
340
341 // management command related
342 unsigned int uCmdBusy;
343 unsigned int uCmdHostAPBusy;
344
345 // management packet pool
346 PBYTE pbyMgmtPacketPool;
347 BYTE byMgmtPacketPool[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
348
349
350 // One second callback timer
351 struct timer_list sTimerSecondCallback;
352
353 // Temporarily Rx Mgmt Packet Descriptor
354 SRxMgmtPacket sRxPacket;
355
356 // link list of known bss's (scan results)
357 KnownBSS sBSSList[MAX_BSS_NUM];
358 /* link list of same bss's */
359 KnownBSS pSameBSS[6] ;
360 BOOL Cisco_cckm ;
361 BYTE Roam_dbm;
362
363 // table list of known node
364 // sNodeDBList[0] is reserved for AP under Infra mode
365 // sNodeDBList[0] is reserved for Multicast under adhoc/AP mode
366 KnownNodeDB sNodeDBTable[MAX_NODE_NUM + 1];
367 244
368 245 /* MAC address */
369 246 u8 abyMACAddr[WLAN_ADDR_LEN];
370 // WPA2 PMKID Cache 247
371 SPMKIDCache gsPMKIDCache; 248 /* Configuration Mode */
372 BOOL bRoaming; 249 WMAC_CONFIG_MODE eConfigMode; /* MAC pre-configed mode */
373 250
374 // rate fall back vars 251 CARD_PHY_TYPE eCurrentPHYMode;
375 252
376 253 /* Operation state variables */
377 254 WMAC_CURRENT_MODE eCurrMode; /* MAC current connection mode */
378 // associate info 255 WMAC_BSS_STATE eCurrState; /* MAC current BSS state */
379 SAssocInfo sAssocInfo; 256 WMAC_BSS_STATE eLastState; /* MAC last BSS state */
380 257
381 258 PKnownBSS pCurrBSS;
382 // for 802.11h 259 u8 byCSSGK;
383 BOOL b11hEnable; 260 u8 byCSSPK;
384 BOOL bSwitchChannel; 261
385 BYTE byNewChannel; 262 int bCurrBSSIDFilterOn;
386 PWLAN_IE_MEASURE_REP pCurrMeasureEIDRep; 263
387 unsigned int uLengthOfRepEIDs; 264 /* Current state vars */
388 BYTE abyCurrentMSRReq[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN]; 265 u32 uCurrChannel;
389 BYTE abyCurrentMSRRep[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN]; 266 u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
390 BYTE abyIECountry[WLAN_A3FR_MAXLEN]; 267 u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
391 BYTE abyIBSSDFSOwner[6]; 268 u8 abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
392 BYTE byIBSSDFSRecovery; 269 u8 abyCurrBSSID[WLAN_BSSID_LEN];
393 270 u16 wCurrCapInfo;
394 struct sk_buff skb; 271 u16 wCurrAID;
395 272 u32 uRSSITrigger;
396} SMgmtObject, *PSMgmtObject; 273 u16 wCurrATIMWindow;
274 u16 wCurrBeaconPeriod;
275 int bIsDS;
276 u8 byERPContext;
277
278 CMD_STATE eCommandState;
279 u32 uScanChannel;
280
281 /* Desire joinning BSS vars */
282 u8 abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
283 u8 abyDesireBSSID[WLAN_BSSID_LEN];
284
285 /*restore BSS info for Ad-Hoc mode */
286 u8 abyAdHocSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
287
288 /* Adhoc or AP configuration vars */
289 u16 wIBSSBeaconPeriod;
290 u16 wIBSSATIMWindow;
291 u32 uIBSSChannel;
292 u8 abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
293 u8 byAPBBType;
294 u8 abyWPAIE[MAX_WPA_IE_LEN];
295 u16 wWPAIELen;
296
297 u32 uAssocCount;
298 int bMoreData;
299
300 /* Scan state vars */
301 WMAC_SCAN_STATE eScanState;
302 WMAC_SCAN_TYPE eScanType;
303 u32 uScanStartCh;
304 u32 uScanEndCh;
305 u16 wScanSteps;
306 u32 uScanBSSType;
307 /* Desire scannig vars */
308 u8 abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
309 u8 abyScanBSSID[WLAN_BSSID_LEN];
310
311 /* Privacy */
312 WMAC_AUTHENTICATION_MODE eAuthenMode;
313 int bShareKeyAlgorithm;
314 u8 abyChallenge[WLAN_CHALLENGE_LEN];
315 int bPrivacyInvoked;
316
317 /* Received beacon state vars */
318 int bInTIM;
319 int bMulticastTIM;
320 u8 byDTIMCount;
321 u8 byDTIMPeriod;
322
323 /* Power saving state vars */
324 WMAC_POWER_MODE ePSMode;
325 u16 wListenInterval;
326 u16 wCountToWakeUp;
327 int bInTIMWake;
328 u8 *pbyPSPacketPool;
329 u8 byPSPacketPool[sizeof(struct vnt_tx_mgmt)
330 + WLAN_NULLDATA_FR_MAXLEN];
331 int bRxBeaconInTBTTWake;
332 u8 abyPSTxMap[MAX_NODE_NUM + 1];
333
334 /* management command related */
335 u32 uCmdBusy;
336 u32 uCmdHostAPBusy;
337
338 /* management packet pool */
339 u8 *pbyMgmtPacketPool;
340 u8 byMgmtPacketPool[sizeof(struct vnt_tx_mgmt)
341 + WLAN_A3FR_MAXLEN];
342
343
344 /* One second callback timer */
345 struct timer_list sTimerSecondCallback;
346
347 /* Temporarily Rx Mgmt Packet Descriptor */
348 struct vnt_rx_mgmt sRxPacket;
349
350 /* link list of known bss's (scan results) */
351 KnownBSS sBSSList[MAX_BSS_NUM];
352 /* link list of same bss's */
353 KnownBSS pSameBSS[6];
354 int Cisco_cckm;
355 u8 Roam_dbm;
356
357 /* table list of known node */
358 /* sNodeDBList[0] is reserved for AP under Infra mode */
359 /* sNodeDBList[0] is reserved for Multicast under adhoc/AP mode */
360 KnownNodeDB sNodeDBTable[MAX_NODE_NUM + 1];
361
362 /* WPA2 PMKID Cache */
363 SPMKIDCache gsPMKIDCache;
364 int bRoaming;
365
366 /* associate info */
367 SAssocInfo sAssocInfo;
368
369 /* for 802.11h */
370 int b11hEnable;
371 int bSwitchChannel;
372 u8 byNewChannel;
373 PWLAN_IE_MEASURE_REP pCurrMeasureEIDRep;
374 u32 uLengthOfRepEIDs;
375 u8 abyCurrentMSRReq[sizeof(struct vnt_tx_mgmt)
376 + WLAN_A3FR_MAXLEN];
377 u8 abyCurrentMSRRep[sizeof(struct vnt_tx_mgmt)
378 + WLAN_A3FR_MAXLEN];
379 u8 abyIECountry[WLAN_A3FR_MAXLEN];
380 u8 abyIBSSDFSOwner[6];
381 u8 byIBSSDFSRecovery;
382
383 struct sk_buff skb;
384
385};
397 386
398/*--------------------- Export Macros ------------------------------*/ 387/*--------------------- Export Macros ------------------------------*/
399 388
400/*--------------------- Export Functions --------------------------*/ 389/*--------------------- Export Functions --------------------------*/
401 390
402void vMgrObjectInit(void *hDeviceContext); 391void vMgrObjectInit(struct vnt_private *pDevice);
403 392
404void vMgrAssocBeginSta(void *hDeviceContext, 393void vMgrAssocBeginSta(struct vnt_private *pDevice,
405 PSMgmtObject pMgmt, 394 struct vnt_manager *, PCMD_STATUS pStatus);
406 PCMD_STATUS pStatus);
407 395
408void vMgrReAssocBeginSta(void *hDeviceContext, 396void vMgrReAssocBeginSta(struct vnt_private *pDevice,
409 PSMgmtObject pMgmt, 397 struct vnt_manager *, PCMD_STATUS pStatus);
410 PCMD_STATUS pStatus);
411 398
412void vMgrDisassocBeginSta(void *hDeviceContext, 399void vMgrDisassocBeginSta(struct vnt_private *pDevice,
413 PSMgmtObject pMgmt, 400 struct vnt_manager *, u8 *abyDestAddress, u16 wReason,
414 PBYTE abyDestAddress, 401 PCMD_STATUS pStatus);
415 WORD wReason,
416 PCMD_STATUS pStatus);
417 402
418void vMgrAuthenBeginSta(void *hDeviceContext, 403void vMgrAuthenBeginSta(struct vnt_private *pDevice,
419 PSMgmtObject pMgmt, 404 struct vnt_manager *, PCMD_STATUS pStatus);
420 PCMD_STATUS pStatus);
421 405
422void vMgrCreateOwnIBSS(void *hDeviceContext, 406void vMgrCreateOwnIBSS(struct vnt_private *pDevice,
423 PCMD_STATUS pStatus); 407 PCMD_STATUS pStatus);
424 408
425void vMgrJoinBSSBegin(void *hDeviceContext, 409void vMgrJoinBSSBegin(struct vnt_private *pDevice,
426 PCMD_STATUS pStatus); 410 PCMD_STATUS pStatus);
427 411
428void vMgrRxManagePacket(void *hDeviceContext, 412void vMgrRxManagePacket(struct vnt_private *pDevice,
429 PSMgmtObject pMgmt, 413 struct vnt_manager *, struct vnt_rx_mgmt *);
430 PSRxMgmtPacket pRxPacket);
431 414
432/* 415/*
433void 416void
@@ -437,19 +420,16 @@ vMgrScanBegin(
437 ); 420 );
438*/ 421*/
439 422
440void vMgrDeAuthenBeginSta(void *hDeviceContext, 423void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
441 PSMgmtObject pMgmt, 424 struct vnt_manager *, u8 *abyDestAddress, u16 wReason,
442 PBYTE abyDestAddress, 425 PCMD_STATUS pStatus);
443 WORD wReason,
444 PCMD_STATUS pStatus);
445 426
446BOOL bMgrPrepareBeaconToSend(void *hDeviceContext, 427int bMgrPrepareBeaconToSend(struct vnt_private *pDevice,
447 PSMgmtObject pMgmt); 428 struct vnt_manager *);
448 429
449BOOL bAdd_PMKID_Candidate(void *hDeviceContext, 430int bAdd_PMKID_Candidate(struct vnt_private *pDevice,
450 PBYTE pbyBSSID, 431 u8 *pbyBSSID, PSRSNCapObject psRSNCapObj);
451 PSRSNCapObject psRSNCapObj);
452 432
453void vFlush_PMKID_Candidate(void *hDeviceContext); 433void vFlush_PMKID_Candidate(struct vnt_private *pDevice);
454 434
455#endif /* __WMGR_H__ */ 435#endif /* __WMGR_H__ */
diff --git a/drivers/staging/vt6656/wpa.c b/drivers/staging/vt6656/wpa.c
index f6429a26ae0f..f037be3aa164 100644
--- a/drivers/staging/vt6656/wpa.c
+++ b/drivers/staging/vt6656/wpa.c
@@ -83,9 +83,9 @@ WPA_ClearRSN(
83 pBSSList->wAuthCount = 0; 83 pBSSList->wAuthCount = 0;
84 pBSSList->byDefaultK_as_PK = 0; 84 pBSSList->byDefaultK_as_PK = 0;
85 pBSSList->byReplayIdx = 0; 85 pBSSList->byReplayIdx = 0;
86 pBSSList->sRSNCapObj.bRSNCapExist = FALSE; 86 pBSSList->sRSNCapObj.bRSNCapExist = false;
87 pBSSList->sRSNCapObj.wRSNCap = 0; 87 pBSSList->sRSNCapObj.wRSNCap = 0;
88 pBSSList->bWPAValid = FALSE; 88 pBSSList->bWPAValid = false;
89} 89}
90 90
91 91
@@ -212,14 +212,14 @@ WPA_ParseRSN(
212 pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI; 212 pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI;
213 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG; 213 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
214 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS); 214 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
215 pBSSList->sRSNCapObj.bRSNCapExist = TRUE; 215 pBSSList->sRSNCapObj.bRSNCapExist = true;
216 pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps; 216 pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps;
217 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps)); 217 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
218 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK)); 218 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
219 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx)); 219 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
220 } 220 }
221 } 221 }
222 pBSSList->bWPAValid = TRUE; 222 pBSSList->bWPAValid = true;
223 } 223 }
224} 224}
225 225
@@ -239,7 +239,7 @@ WPA_ParseRSN(
239 * Return Value: none. 239 * Return Value: none.
240 * 240 *
241-*/ 241-*/
242BOOL 242bool
243WPA_SearchRSN( 243WPA_SearchRSN(
244 BYTE byCmd, 244 BYTE byCmd,
245 BYTE byEncrypt, 245 BYTE byEncrypt,
@@ -249,14 +249,14 @@ WPA_SearchRSN(
249 int ii; 249 int ii;
250 BYTE byPKType = WPA_NONE; 250 BYTE byPKType = WPA_NONE;
251 251
252 if (pBSSList->bWPAValid == FALSE) 252 if (pBSSList->bWPAValid == false)
253 return FALSE; 253 return false;
254 254
255 switch(byCmd) { 255 switch(byCmd) {
256 case 0: 256 case 0:
257 257
258 if (byEncrypt != pBSSList->byGKType) 258 if (byEncrypt != pBSSList->byGKType)
259 return FALSE; 259 return false;
260 260
261 if (pBSSList->wPKCount > 0) { 261 if (pBSSList->wPKCount > 0) {
262 for (ii = 0; ii < pBSSList->wPKCount; ii ++) { 262 for (ii = 0; ii < pBSSList->wPKCount; ii ++) {
@@ -270,9 +270,9 @@ WPA_SearchRSN(
270 byPKType = WPA_WEP104; 270 byPKType = WPA_WEP104;
271 } 271 }
272 if (byEncrypt != byPKType) 272 if (byEncrypt != byPKType)
273 return FALSE; 273 return false;
274 } 274 }
275 return TRUE; 275 return true;
276// if (pBSSList->wAuthCount > 0) 276// if (pBSSList->wAuthCount > 0)
277// for (ii=0; ii < pBSSList->wAuthCount; ii ++) 277// for (ii=0; ii < pBSSList->wAuthCount; ii ++)
278// if (byAuth == pBSSList->abyAuthType[ii]) 278// if (byAuth == pBSSList->abyAuthType[ii])
@@ -282,7 +282,7 @@ WPA_SearchRSN(
282 default: 282 default:
283 break; 283 break;
284 } 284 }
285 return FALSE; 285 return false;
286} 286}
287 287
288/*+ 288/*+
@@ -299,20 +299,20 @@ WPA_SearchRSN(
299 * Return Value: none. 299 * Return Value: none.
300 * 300 *
301-*/ 301-*/
302BOOL 302bool
303WPAb_Is_RSN( 303WPAb_Is_RSN(
304 PWLAN_IE_RSN_EXT pRSN 304 PWLAN_IE_RSN_EXT pRSN
305 ) 305 )
306{ 306{
307 if (pRSN == NULL) 307 if (pRSN == NULL)
308 return FALSE; 308 return false;
309 309
310 if ((pRSN->len >= 6) && // oui1(4)+ver(2) 310 if ((pRSN->len >= 6) && // oui1(4)+ver(2)
311 (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) && 311 (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
312 (pRSN->wVersion == 1)) { 312 (pRSN->wVersion == 1)) {
313 return TRUE; 313 return true;
314 } 314 }
315 else 315 else
316 return FALSE; 316 return false;
317} 317}
318 318
diff --git a/drivers/staging/vt6656/wpa.h b/drivers/staging/vt6656/wpa.h
index 889489adbb81..0369cbf32c49 100644
--- a/drivers/staging/vt6656/wpa.h
+++ b/drivers/staging/vt6656/wpa.h
@@ -69,14 +69,14 @@ WPA_ParseRSN(
69 PWLAN_IE_RSN_EXT pRSN 69 PWLAN_IE_RSN_EXT pRSN
70 ); 70 );
71 71
72BOOL 72bool
73WPA_SearchRSN( 73WPA_SearchRSN(
74 BYTE byCmd, 74 BYTE byCmd,
75 BYTE byEncrypt, 75 BYTE byEncrypt,
76 PKnownBSS pBSSList 76 PKnownBSS pBSSList
77 ); 77 );
78 78
79BOOL 79bool
80WPAb_Is_RSN( 80WPAb_Is_RSN(
81 PWLAN_IE_RSN_EXT pRSN 81 PWLAN_IE_RSN_EXT pRSN
82 ); 82 );
diff --git a/drivers/staging/vt6656/wpa2.c b/drivers/staging/vt6656/wpa2.c
index 616e24dcf42b..a89456a9137a 100644
--- a/drivers/staging/vt6656/wpa2.c
+++ b/drivers/staging/vt6656/wpa2.c
@@ -78,7 +78,7 @@ WPA2_ClearRSN (
78{ 78{
79 int ii; 79 int ii;
80 80
81 pBSSNode->bWPA2Valid = FALSE; 81 pBSSNode->bWPA2Valid = false;
82 82
83 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP; 83 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
84 for (ii=0; ii < 4; ii ++) 84 for (ii=0; ii < 4; ii ++)
@@ -87,7 +87,7 @@ WPA2_ClearRSN (
87 for (ii=0; ii < 4; ii ++) 87 for (ii=0; ii < 4; ii ++)
88 pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X; 88 pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
89 pBSSNode->wAKMSSAuthCount = 1; 89 pBSSNode->wAKMSSAuthCount = 1;
90 pBSSNode->sRSNCapObj.bRSNCapExist = FALSE; 90 pBSSNode->sRSNCapObj.bRSNCapExist = false;
91 pBSSNode->sRSNCapObj.wRSNCap = 0; 91 pBSSNode->sRSNCapObj.wRSNCap = 0;
92} 92}
93 93
@@ -115,7 +115,7 @@ WPA2vParseRSN (
115 int i, j; 115 int i, j;
116 WORD m = 0, n = 0; 116 WORD m = 0, n = 0;
117 PBYTE pbyOUI; 117 PBYTE pbyOUI;
118 BOOL bUseGK = FALSE; 118 bool bUseGK = false;
119 119
120 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len); 120 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len);
121 121
@@ -123,7 +123,7 @@ WPA2vParseRSN (
123 123
124 if (pRSN->len == 2) { // ver(2) 124 if (pRSN->len == 2) { // ver(2)
125 if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) { 125 if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) {
126 pBSSNode->bWPA2Valid = TRUE; 126 pBSSNode->bWPA2Valid = true;
127 } 127 }
128 return; 128 return;
129 } 129 }
@@ -158,7 +158,7 @@ WPA2vParseRSN (
158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK); 158 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK);
159 159
160 if (pRSN->len == 6) { 160 if (pRSN->len == 6) {
161 pBSSNode->bWPA2Valid = TRUE; 161 pBSSNode->bWPA2Valid = true;
162 return; 162 return;
163 } 163 }
164 164
@@ -172,7 +172,7 @@ WPA2vParseRSN (
172 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i) 172 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
173 if ( !memcmp(pbyOUI, abyOUIGK, 4)) { 173 if ( !memcmp(pbyOUI, abyOUIGK, 4)) {
174 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP; 174 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
175 bUseGK = TRUE; 175 bUseGK = true;
176 } else if ( !memcmp(pbyOUI, abyOUIWEP40, 4)) { 176 } else if ( !memcmp(pbyOUI, abyOUIWEP40, 4)) {
177 // Invalid CSS, continue parsing 177 // Invalid CSS, continue parsing
178 } else if ( !memcmp(pbyOUI, abyOUITKIP, 4)) { 178 } else if ( !memcmp(pbyOUI, abyOUITKIP, 4)) {
@@ -194,7 +194,7 @@ WPA2vParseRSN (
194 break; 194 break;
195 } //for 195 } //for
196 196
197 if (bUseGK == TRUE) { 197 if (bUseGK == true) {
198 if (j != 1) { 198 if (j != 1) {
199 // invalid CSS, This should be only PK CSS. 199 // invalid CSS, This should be only PK CSS.
200 return; 200 return;
@@ -236,12 +236,12 @@ WPA2vParseRSN (
236 236
237 n = *((PWORD) &(pRSN->abyRSN[6+4*m])); 237 n = *((PWORD) &(pRSN->abyRSN[6+4*m]));
238 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2) 238 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
239 pBSSNode->sRSNCapObj.bRSNCapExist = TRUE; 239 pBSSNode->sRSNCapObj.bRSNCapExist = true;
240 pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n])); 240 pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n]));
241 } 241 }
242 } 242 }
243 //ignore PMKID lists bcs only (Re)Assocrequest has this field 243 //ignore PMKID lists bcs only (Re)Assocrequest has this field
244 pBSSNode->bWPA2Valid = TRUE; 244 pBSSNode->bWPA2Valid = true;
245 } 245 }
246} 246}
247 247
@@ -260,19 +260,16 @@ WPA2vParseRSN (
260 * Return Value: length of IEs. 260 * Return Value: length of IEs.
261 * 261 *
262-*/ 262-*/
263unsigned int 263unsigned int WPA2uSetIEs(void *pMgmtHandle, PWLAN_IE_RSN pRSNIEs)
264WPA2uSetIEs(void *pMgmtHandle,
265 PWLAN_IE_RSN pRSNIEs
266 )
267{ 264{
268 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle; 265 struct vnt_manager *pMgmt = (struct vnt_manager *)pMgmtHandle;
269 PBYTE pbyBuffer = NULL; 266 u8 *pbyBuffer = NULL;
270 unsigned int ii = 0; 267 int ii = 0;
271 PWORD pwPMKID = NULL; 268 u16 *pwPMKID = NULL;
269
270 if (pRSNIEs == NULL)
271 return 0;
272 272
273 if (pRSNIEs == NULL) {
274 return(0);
275 }
276 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || 273 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
277 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) && 274 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
278 (pMgmt->pCurrBSS != NULL)) { 275 (pMgmt->pCurrBSS != NULL)) {
@@ -328,7 +325,7 @@ WPA2uSetIEs(void *pMgmtHandle,
328 pRSNIEs->len +=6; 325 pRSNIEs->len +=6;
329 326
330 // RSN Capabilites 327 // RSN Capabilites
331 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) { 328 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
332 memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2); 329 memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
333 } else { 330 } else {
334 pRSNIEs->abyRSN[16] = 0; 331 pRSNIEs->abyRSN[16] = 0;
@@ -337,7 +334,7 @@ WPA2uSetIEs(void *pMgmtHandle,
337 pRSNIEs->len +=2; 334 pRSNIEs->len +=2;
338 335
339 if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) && 336 if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
340 (pMgmt->bRoaming == TRUE) && 337 (pMgmt->bRoaming == true) &&
341 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) { 338 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
342 /* RSN PMKID, pointer to PMKID count */ 339 /* RSN PMKID, pointer to PMKID count */
343 pwPMKID = (PWORD)(&pRSNIEs->abyRSN[18]); 340 pwPMKID = (PWORD)(&pRSNIEs->abyRSN[18]);
diff --git a/drivers/staging/vt6656/wpactl.c b/drivers/staging/vt6656/wpactl.c
index cc1d48bced2d..53629b26f24d 100644
--- a/drivers/staging/vt6656/wpactl.c
+++ b/drivers/staging/vt6656/wpactl.c
@@ -67,14 +67,14 @@ static int msglevel = MSG_LEVEL_INFO;
67 * Return Value: 67 * Return Value:
68 * 68 *
69 */ 69 */
70int wpa_set_keys(PSDevice pDevice, void *ctx) 70int wpa_set_keys(struct vnt_private *pDevice, void *ctx)
71{ 71{
72 struct viawget_wpa_param *param = ctx; 72 struct viawget_wpa_param *param = ctx;
73 PSMgmtObject pMgmt = &pDevice->sMgmtObj; 73 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
74 DWORD dwKeyIndex = 0; 74 DWORD dwKeyIndex = 0;
75 BYTE abyKey[MAX_KEY_LEN]; 75 BYTE abyKey[MAX_KEY_LEN];
76 BYTE abySeq[MAX_KEY_LEN]; 76 BYTE abySeq[MAX_KEY_LEN];
77 QWORD KeyRSC; 77 u64 KeyRSC;
78 BYTE byKeyDecMode = KEY_CTL_WEP; 78 BYTE byKeyDecMode = KEY_CTL_WEP;
79 int ret = 0; 79 int ret = 0;
80 int uu; 80 int uu;
@@ -87,9 +87,9 @@ int wpa_set_keys(PSDevice pDevice, void *ctx)
87 param->u.wpa_key.alg_name); 87 param->u.wpa_key.alg_name);
88 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) { 88 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
89 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled; 89 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
90 pDevice->bEncryptionEnable = FALSE; 90 pDevice->bEncryptionEnable = false;
91 pDevice->byKeyIndex = 0; 91 pDevice->byKeyIndex = 0;
92 pDevice->bTransmitKey = FALSE; 92 pDevice->bTransmitKey = false;
93 for (uu=0; uu<MAX_KEY_TABLE; uu++) { 93 for (uu=0; uu<MAX_KEY_TABLE; uu++) {
94 MACvDisableKeyEntry(pDevice, uu); 94 MACvDisableKeyEntry(pDevice, uu);
95 } 95 }
@@ -109,7 +109,7 @@ int wpa_set_keys(PSDevice pDevice, void *ctx)
109 } else { 109 } else {
110 if (param->u.wpa_key.set_tx) { 110 if (param->u.wpa_key.set_tx) {
111 pDevice->byKeyIndex = (BYTE)dwKeyIndex; 111 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
112 pDevice->bTransmitKey = TRUE; 112 pDevice->bTransmitKey = true;
113 dwKeyIndex |= (1 << 31); 113 dwKeyIndex |= (1 << 31);
114 } 114 }
115 KeybSetDefaultKey( pDevice, 115 KeybSetDefaultKey( pDevice,
@@ -123,7 +123,7 @@ int wpa_set_keys(PSDevice pDevice, void *ctx)
123 123
124 } 124 }
125 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled; 125 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
126 pDevice->bEncryptionEnable = TRUE; 126 pDevice->bEncryptionEnable = true;
127 return ret; 127 return ret;
128 } 128 }
129 129
@@ -136,9 +136,9 @@ int wpa_set_keys(PSDevice pDevice, void *ctx)
136 if (param->u.wpa_key.seq_len > 0) { 136 if (param->u.wpa_key.seq_len > 0) {
137 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) { 137 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
138 if (ii < 4) 138 if (ii < 4)
139 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8)); 139 KeyRSC |= (abySeq[ii] << (ii * 8));
140 else 140 else
141 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8)); 141 KeyRSC |= (abySeq[ii] << ((ii-4) * 8));
142 } 142 }
143 dwKeyIndex |= 1 << 29; 143 dwKeyIndex |= 1 << 29;
144 } 144 }
@@ -203,18 +203,18 @@ int wpa_set_keys(PSDevice pDevice, void *ctx)
203 203
204 if ((KeybSetAllGroupKey(pDevice, &(pDevice->sKey), dwKeyIndex, 204 if ((KeybSetAllGroupKey(pDevice, &(pDevice->sKey), dwKeyIndex,
205 param->u.wpa_key.key_len, 205 param->u.wpa_key.key_len,
206 (PQWORD) &(KeyRSC), 206 &KeyRSC,
207 (PBYTE)abyKey, 207 (PBYTE)abyKey,
208 byKeyDecMode 208 byKeyDecMode
209 ) == TRUE) && 209 ) == true) &&
210 (KeybSetDefaultKey(pDevice, 210 (KeybSetDefaultKey(pDevice,
211 &(pDevice->sKey), 211 &(pDevice->sKey),
212 dwKeyIndex, 212 dwKeyIndex,
213 param->u.wpa_key.key_len, 213 param->u.wpa_key.key_len,
214 (PQWORD) &(KeyRSC), 214 &KeyRSC,
215 (PBYTE)abyKey, 215 (PBYTE)abyKey,
216 byKeyDecMode 216 byKeyDecMode
217 ) == TRUE) ) { 217 ) == true) ) {
218 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n"); 218 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
219 } else { 219 } else {
220 return -EINVAL; 220 return -EINVAL;
@@ -234,8 +234,8 @@ int wpa_set_keys(PSDevice pDevice, void *ctx)
234 } 234 }
235 if (KeybSetKey(pDevice, &(pDevice->sKey), &param->addr[0], 235 if (KeybSetKey(pDevice, &(pDevice->sKey), &param->addr[0],
236 dwKeyIndex, param->u.wpa_key.key_len, 236 dwKeyIndex, param->u.wpa_key.key_len,
237 (PQWORD) &(KeyRSC), (PBYTE)abyKey, byKeyDecMode 237 &KeyRSC, (PBYTE)abyKey, byKeyDecMode
238 ) == TRUE) { 238 ) == true) {
239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n"); 239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
240 } else { 240 } else {
241 // Key Table Full 241 // Key Table Full
@@ -251,9 +251,9 @@ int wpa_set_keys(PSDevice pDevice, void *ctx)
251 } // BSSID not 0xffffffffffff 251 } // BSSID not 0xffffffffffff
252 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) { 252 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
253 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index; 253 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
254 pDevice->bTransmitKey = TRUE; 254 pDevice->bTransmitKey = true;
255 } 255 }
256 pDevice->bEncryptionEnable = TRUE; 256 pDevice->bEncryptionEnable = true;
257 257
258 return ret; 258 return ret;
259} 259}
diff --git a/drivers/staging/vt6656/wpactl.h b/drivers/staging/vt6656/wpactl.h
index b4ec6b0e1c67..2235ee97012e 100644
--- a/drivers/staging/vt6656/wpactl.h
+++ b/drivers/staging/vt6656/wpactl.h
@@ -52,6 +52,6 @@ typedef unsigned long long NDIS_802_11_KEY_RSC;
52 52
53/*--------------------- Export Functions --------------------------*/ 53/*--------------------- Export Functions --------------------------*/
54 54
55int wpa_set_keys(PSDevice pDevice, void *ctx); 55int wpa_set_keys(struct vnt_private *, void *ctx);
56 56
57#endif /* __WPACL_H__ */ 57#endif /* __WPACL_H__ */
diff --git a/drivers/staging/winbond/Kconfig b/drivers/staging/winbond/Kconfig
index a29f60836b77..db5b053d9bc2 100644
--- a/drivers/staging/winbond/Kconfig
+++ b/drivers/staging/winbond/Kconfig
@@ -8,4 +8,4 @@ config W35UND
8 Hardware is present in some Kohjinsha subnotebooks, and in some 8 Hardware is present in some Kohjinsha subnotebooks, and in some
9 stand-alone USB modules. Chipset name seems to be w89c35d. 9 stand-alone USB modules. Chipset name seems to be w89c35d.
10 10
11 Check http://code.google.com/p/winbondport/ for new version. 11 Check <http://code.google.com/p/winbondport/> for new version.
diff --git a/drivers/staging/wlags49_h2/ap_h2.c b/drivers/staging/wlags49_h2/ap_h2.c
index e524153e925d..3a08d421c735 100644
--- a/drivers/staging/wlags49_h2/ap_h2.c
+++ b/drivers/staging/wlags49_h2/ap_h2.c
@@ -3256,7 +3256,7 @@ static const CFG_PROG_STRCT fw_image_code[] = {
3256 0x0146, /* sizeof(fw_image_1_data), */ 3256 0x0146, /* sizeof(fw_image_1_data), */
3257 0x00000060, /* Target address in NIC Memory */ 3257 0x00000060, /* Target address in NIC Memory */
3258 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ 3258 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
3259 (hcf_8 FAR *) fw_image_1_data 3259 (hcf_8 *)fw_image_1_data
3260 }, 3260 },
3261 { 3261 {
3262 8, 3262 8,
@@ -3265,7 +3265,7 @@ static const CFG_PROG_STRCT fw_image_code[] = {
3265 0x1918, /* sizeof(fw_image_2_data), */ 3265 0x1918, /* sizeof(fw_image_2_data), */
3266 0x00000C16, /* Target address in NIC Memory */ 3266 0x00000C16, /* Target address in NIC Memory */
3267 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ 3267 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
3268 (hcf_8 FAR *) fw_image_2_data 3268 (hcf_8 *)fw_image_2_data
3269 }, 3269 },
3270 { 3270 {
3271 8, 3271 8,
@@ -3274,7 +3274,7 @@ static const CFG_PROG_STRCT fw_image_code[] = {
3274 0x01bc, /* sizeof(fw_image_3_data), */ 3274 0x01bc, /* sizeof(fw_image_3_data), */
3275 0x001E252E, /* Target address in NIC Memory */ 3275 0x001E252E, /* Target address in NIC Memory */
3276 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ 3276 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
3277 (hcf_8 FAR *) fw_image_3_data 3277 (hcf_8 *)fw_image_3_data
3278 }, 3278 },
3279 { 3279 {
3280 8, 3280 8,
@@ -3283,7 +3283,7 @@ static const CFG_PROG_STRCT fw_image_code[] = {
3283 0xab28, /* sizeof(fw_image_4_data), */ 3283 0xab28, /* sizeof(fw_image_4_data), */
3284 0x001F4000, /* Target address in NIC Memory */ 3284 0x001F4000, /* Target address in NIC Memory */
3285 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */ 3285 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
3286 (hcf_8 FAR *) fw_image_4_data 3286 (hcf_8 *)fw_image_4_data
3287 }, 3287 },
3288 { 3288 {
3289 5, 3289 5,
diff --git a/drivers/staging/wlags49_h2/ap_h25.c b/drivers/staging/wlags49_h2/ap_h25.c
index f4491cbd08d3..d3a0faa3ab97 100644
--- a/drivers/staging/wlags49_h2/ap_h25.c
+++ b/drivers/staging/wlags49_h2/ap_h25.c
@@ -24,10 +24,10 @@
24 */ 24 */
25 25
26 26
27#include "hcfcfg.h" // to get hcf_16 etc defined as well as 27#include "hcfcfg.h" /* to get hcf_16 etc defined as well as */
28 // possible settings which inluence mdd.h or dhf.h 28 /* possible settings which inluence mdd.h or dhf.h */
29#include "mdd.h" //to get COMP_ID_STA etc defined 29#include "mdd.h" /* to get COMP_ID_STA etc defined */
30#include "dhf.h" //used to be "fhfmem.h", to get memblock,plugrecord, 30#include "dhf.h" /* used to be fhfmem.h, to get memblock,plugrecord, */
31 31
32static const hcf_8 fw_image_1_data[] = { 32static const hcf_8 fw_image_1_data[] = {
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -3996,59 +3996,59 @@ static const hcf_8 fw_image_4_data[] = {
3996 3996
3997static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = { 3997static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = {
3998 { 3998 {
3999 sizeof( CFG_IDENTITY_STRCT ) / sizeof(hcf_16) - 1, 3999 sizeof(CFG_IDENTITY_STRCT) / sizeof(hcf_16) - 1,
4000 CFG_FW_IDENTITY, 4000 CFG_FW_IDENTITY,
4001 COMP_ID_FW_AP, 4001 COMP_ID_FW_AP,
4002 3, //Variant 4002 3, /* Variant */
4003 1, //Major 4003 1, /* Major */
4004 24 //Minor 4004 24 /* Minor */
4005 }, 4005 },
4006 { 0000, 0000, 0000, 0000, 0000, 0000 } //endsentinel 4006 { 0000, 0000, 0000, 0000, 0000, 0000 } /* endsentinel */
4007}; 4007};
4008 4008
4009static const CFG_PROG_STRCT fw_image_code[] = { 4009static const CFG_PROG_STRCT fw_image_code[] = {
4010 { 4010 {
4011 8, 4011 8,
4012 CFG_PROG, 4012 CFG_PROG,
4013 CFG_PROG_VOLATILE, // mode 4013 CFG_PROG_VOLATILE, /* mode */
4014 0x0148, // sizeof(fw_image_1_data), 4014 0x0148, /* sizeof(fw_image_1_data), */
4015 0x00000060, // Target address in NIC Memory 4015 0x00000060, /* Target address in NIC Memory */
4016 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4016 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
4017 (hcf_8 FAR *) fw_image_1_data 4017 (hcf_8 *)fw_image_1_data
4018 }, 4018 },
4019 { 4019 {
4020 8, 4020 8,
4021 CFG_PROG, 4021 CFG_PROG,
4022 CFG_PROG_VOLATILE, // mode 4022 CFG_PROG_VOLATILE, /* mode */
4023 0x2432, // sizeof(fw_image_2_data), 4023 0x2432, /* sizeof(fw_image_2_data), */
4024 0x00000C16, // Target address in NIC Memory 4024 0x00000C16, /* Target address in NIC Memory */
4025 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4025 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
4026 (hcf_8 FAR *) fw_image_2_data 4026 (hcf_8 *)fw_image_2_data
4027 }, 4027 },
4028 { 4028 {
4029 8, 4029 8,
4030 CFG_PROG, 4030 CFG_PROG,
4031 CFG_PROG_VOLATILE, // mode 4031 CFG_PROG_VOLATILE, /* mode */
4032 0x194c, // sizeof(fw_image_3_data), 4032 0x194c, /* sizeof(fw_image_3_data), */
4033 0x001E3048, // Target address in NIC Memory 4033 0x001E3048, /* Target address in NIC Memory */
4034 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4034 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
4035 (hcf_8 FAR *) fw_image_3_data 4035 (hcf_8 *)fw_image_3_data
4036 }, 4036 },
4037 { 4037 {
4038 8, 4038 8,
4039 CFG_PROG, 4039 CFG_PROG,
4040 CFG_PROG_VOLATILE, // mode 4040 CFG_PROG_VOLATILE, /* mode*/
4041 0xb7e4, // sizeof(fw_image_4_data), 4041 0xb7e4, /* sizeof(fw_image_4_data),*/
4042 0x001F4000, // Target address in NIC Memory 4042 0x001F4000, /* Target address in NIC Memory*/
4043 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4043 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary*/
4044 (hcf_8 FAR *) fw_image_4_data 4044 (hcf_8 *)fw_image_4_data
4045 }, 4045 },
4046 { 4046 {
4047 5, 4047 5,
4048 CFG_PROG, 4048 CFG_PROG,
4049 CFG_PROG_STOP, // mode 4049 CFG_PROG_STOP, /* mode*/
4050 0000, 4050 0000,
4051 0x000F2101, // Start execution address 4051 0x000F2101, /* Start execution address*/
4052 }, 4052 },
4053 { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000} 4053 { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000}
4054}; 4054};
@@ -4059,7 +4059,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = {
4059 COMP_ROLE_SUPL, 4059 COMP_ROLE_SUPL,
4060 COMP_ID_APF, 4060 COMP_ID_APF,
4061 { 4061 {
4062 { 4, 1, 1 } //variant, bottom, top 4062 { 4, 1, 1 } /* variant, bottom, top*/
4063 } 4063 }
4064 }, 4064 },
4065 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), 4065 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)),
@@ -4067,8 +4067,8 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = {
4067 COMP_ROLE_ACT, 4067 COMP_ROLE_ACT,
4068 COMP_ID_MFI, 4068 COMP_ID_MFI,
4069 { 4069 {
4070 { 7, 3, 3 }, //variant, bottom, top 4070 { 7, 3, 3 }, /* variant, bottom, top */
4071 { 8, 1, 1 } //variant, bottom, top 4071 { 8, 1, 1 } /* variant, bottom, top */
4072 } 4072 }
4073 }, 4073 },
4074 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), 4074 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)),
@@ -4076,18 +4076,18 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = {
4076 COMP_ROLE_ACT, 4076 COMP_ROLE_ACT,
4077 COMP_ID_CFI, 4077 COMP_ID_CFI,
4078 { 4078 {
4079 { 4, 1, 2 } //variant, bottom, top 4079 { 4, 1, 2 } /* variant, bottom, top */
4080 } 4080 }
4081 }, 4081 },
4082 { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } //endsentinel 4082 { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } /* endsentinel */
4083}; 4083};
4084 4084
4085memimage fw_image = { 4085memimage fw_image = {
4086 "FUPU7D37dhfwci\001C", //signature, <format number>, C/Bin type 4086 "FUPU7D37dhfwci\001C", /* signature, <format number>, C/Bin type */
4087 (CFG_PROG_STRCT *) fw_image_code, 4087 (CFG_PROG_STRCT *) fw_image_code,
4088 0x000F2101, 4088 0x000F2101,
4089 00000000, //(dummy) pdaplug 4089 00000000, /* (dummy) pdaplug */
4090 00000000, //(dummy) priplug 4090 00000000, /* (dummy) priplug */
4091 (CFG_RANGE20_STRCT *) fw_image_infocompat, 4091 (CFG_RANGE20_STRCT *) fw_image_infocompat,
4092 (CFG_IDENTITY_STRCT *) fw_image_infoidentity, 4092 (CFG_IDENTITY_STRCT *) fw_image_infoidentity,
4093}; 4093};
diff --git a/drivers/staging/wlags49_h2/sta_h2.c b/drivers/staging/wlags49_h2/sta_h2.c
index 00dffe2ed8f1..19bed819df1e 100644
--- a/drivers/staging/wlags49_h2/sta_h2.c
+++ b/drivers/staging/wlags49_h2/sta_h2.c
@@ -25,10 +25,10 @@
25 */ 25 */
26 26
27 27
28#include "hcfcfg.h" // to get hcf_16 etc defined as well as 28#include "hcfcfg.h" /* to get hcf_16 etc defined as well as */
29 // possible settings which influence mdd.h or dhf.h 29 /* possible settings which influence mdd.h or dhf.h */
30#include "mdd.h" //to get COMP_ID_STA etc defined 30#include "mdd.h" /* to get COMP_ID_STA etc defined */
31#include "dhf.h" //used to be "fhfmem.h", to get memblock,plugrecord, 31#include "dhf.h" /* used to be fhfmem.h, to get memblock,plugrecord, */
32 32
33static const hcf_8 fw_image_1_data[] = { 33static const hcf_8 fw_image_1_data[] = {
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -4381,59 +4381,59 @@ static const hcf_8 fw_image_4_data[] = {
4381 4381
4382static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = { 4382static const CFG_IDENTITY_STRCT fw_image_infoidentity[] = {
4383 { 4383 {
4384 sizeof( CFG_IDENTITY_STRCT ) / sizeof(hcf_16) - 1, 4384 sizeof(CFG_IDENTITY_STRCT) / sizeof(hcf_16) - 1,
4385 CFG_FW_IDENTITY, 4385 CFG_FW_IDENTITY,
4386 COMP_ID_FW_STA, 4386 COMP_ID_FW_STA,
4387 3, //Variant 4387 3, /* Variant */
4388 2, //Major 4388 2, /* Major */
4389 36 //Minor 4389 36 /* Minor */
4390 }, 4390 },
4391 { 0000, 0000, 0000, 0000, 0000, 0000 } //endsentinel 4391 { 0000, 0000, 0000, 0000, 0000, 0000 } /* endsentinel */
4392}; 4392};
4393 4393
4394static const CFG_PROG_STRCT fw_image_code[] = { 4394static const CFG_PROG_STRCT fw_image_code[] = {
4395 { 4395 {
4396 8, 4396 8,
4397 CFG_PROG, 4397 CFG_PROG,
4398 CFG_PROG_VOLATILE, // mode 4398 CFG_PROG_VOLATILE, /* mode */
4399 0x0186, // sizeof(fw_image_1_data), 4399 0x0186, /* sizeof(fw_image_1_data), */
4400 0x00000060, // Target address in NIC Memory 4400 0x00000060, /* Target address in NIC Memory */
4401 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4401 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
4402 (hcf_8 FAR *) fw_image_1_data 4402 (hcf_8 *)fw_image_1_data
4403 }, 4403 },
4404 { 4404 {
4405 8, 4405 8,
4406 CFG_PROG, 4406 CFG_PROG,
4407 CFG_PROG_VOLATILE, // mode 4407 CFG_PROG_VOLATILE, /* mode */
4408 0x2518, // sizeof(fw_image_2_data), 4408 0x2518, /* sizeof(fw_image_2_data), */
4409 0x00000C16, // Target address in NIC Memory 4409 0x00000C16, /* Target address in NIC Memory */
4410 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4410 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
4411 (hcf_8 FAR *) fw_image_2_data 4411 (hcf_8 *)fw_image_2_data
4412 }, 4412 },
4413 { 4413 {
4414 8, 4414 8,
4415 CFG_PROG, 4415 CFG_PROG,
4416 CFG_PROG_VOLATILE, // mode 4416 CFG_PROG_VOLATILE, /* mode */
4417 0x3daa, // sizeof(fw_image_3_data), 4417 0x3daa, /* sizeof(fw_image_3_data), */
4418 0x001E312E, // Target address in NIC Memory 4418 0x001E312E, /* Target address in NIC Memory */
4419 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4419 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
4420 (hcf_8 FAR *) fw_image_3_data 4420 (hcf_8 *)fw_image_3_data
4421 }, 4421 },
4422 { 4422 {
4423 8, 4423 8,
4424 CFG_PROG, 4424 CFG_PROG,
4425 CFG_PROG_VOLATILE, // mode 4425 CFG_PROG_VOLATILE, /* mode */
4426 0xaa66, // sizeof(fw_image_4_data), 4426 0xaa66, /* sizeof(fw_image_4_data), */
4427 0x001F4000, // Target address in NIC Memory 4427 0x001F4000, /* Target address in NIC Memory */
4428 0x0000, // CRC: yes/no TYPE: primary/station/tertiary 4428 0x0000, /* CRC: yes/no TYPE: primary/station/tertiary */
4429 (hcf_8 FAR *) fw_image_4_data 4429 (hcf_8 *)fw_image_4_data
4430 }, 4430 },
4431 { 4431 {
4432 5, 4432 5,
4433 CFG_PROG, 4433 CFG_PROG,
4434 CFG_PROG_STOP, // mode 4434 CFG_PROG_STOP, /* mode */
4435 0000, 4435 0000,
4436 0x000F368E, // Start execution address 4436 0x000F368E, /* Start execution address */
4437 }, 4437 },
4438 { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000} 4438 { 0000, 0000, 0000, 0000, 00000000, 0000, 00000000}
4439}; 4439};
@@ -4444,7 +4444,7 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = {
4444 COMP_ROLE_SUPL, 4444 COMP_ROLE_SUPL,
4445 COMP_ID_STA, 4445 COMP_ID_STA,
4446 { 4446 {
4447 { 2, 2, 5 } //variant, bottom, top 4447 { 2, 2, 5 } /* variant, bottom, top */
4448 } 4448 }
4449 }, 4449 },
4450 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), 4450 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)),
@@ -4452,9 +4452,9 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = {
4452 COMP_ROLE_ACT, 4452 COMP_ROLE_ACT,
4453 COMP_ID_MFI, 4453 COMP_ID_MFI,
4454 { 4454 {
4455 { 4, 6, 7 }, //variant, bottom, top 4455 { 4, 6, 7 }, /* variant, bottom, top */
4456 { 5, 6, 7 }, //variant, bottom, top 4456 { 5, 6, 7 }, /* variant, bottom, top */
4457 { 6, 6, 7 } //variant, bottom, top 4457 { 6, 6, 7 } /* variant, bottom, top */
4458 } 4458 }
4459 }, 4459 },
4460 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)), 4460 { 3 + ((20 * sizeof(CFG_RANGE_SPEC_STRCT)) / sizeof(hcf_16)),
@@ -4462,18 +4462,18 @@ static const CFG_RANGE20_STRCT fw_image_infocompat[] = {
4462 COMP_ROLE_ACT, 4462 COMP_ROLE_ACT,
4463 COMP_ID_CFI, 4463 COMP_ID_CFI,
4464 { 4464 {
4465 { 2, 1, 2 } //variant, bottom, top 4465 { 2, 1, 2 } /* variant, bottom, top */
4466 } 4466 }
4467 }, 4467 },
4468 { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } //endsentinel 4468 { 0000, 0000, 0000, 0000, { { 0000, 0000, 0000 } } } /* endsentinel */
4469}; 4469};
4470 4470
4471memimage fw_image = { 4471memimage fw_image = {
4472 "FUPU7D37dhfwci\001C", //signature, <format number>, C/Bin type 4472 "FUPU7D37dhfwci\001C", /* signature, <format number>, C/Bin type */
4473 (CFG_PROG_STRCT *) fw_image_code, 4473 (CFG_PROG_STRCT *) fw_image_code,
4474 0x000F368E, 4474 0x000F368E,
4475 00000000, //(dummy) pdaplug 4475 00000000, /* (dummy) pdaplug */
4476 00000000, //(dummy) priplug 4476 00000000, /* (dummy) priplug */
4477 (CFG_RANGE20_STRCT *) fw_image_infocompat, 4477 (CFG_RANGE20_STRCT *) fw_image_infocompat,
4478 (CFG_IDENTITY_STRCT *) fw_image_infoidentity, 4478 (CFG_IDENTITY_STRCT *) fw_image_infoidentity,
4479}; 4479};
diff --git a/drivers/staging/wlags49_h2/wl_enc.c b/drivers/staging/wlags49_h2/wl_enc.c
index 4c6f776cc4da..51293d9f2be9 100644
--- a/drivers/staging/wlags49_h2/wl_enc.c
+++ b/drivers/staging/wlags49_h2/wl_enc.c
@@ -105,57 +105,57 @@ extern dbg_info_t *DbgInfo;
105 * OK 105 * OK
106 * 106 *
107 ******************************************************************************/ 107 ******************************************************************************/
108int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen ) 108int wl_wep_code(char *szCrypt, char *szDest, void *Data, int nLen)
109{ 109{
110 int i; 110 int i;
111 int t; 111 int t;
112 int k ; 112 int k ;
113 char bits; 113 char bits;
114 char *szData = (char *) Data; 114 char *szData = (char *) Data;
115 /*------------------------------------------------------------------------*/ 115 /*------------------------------------------------------------------------*/
116 116
117 117
118 for( i = bits = 0 ; i < MACADDRESS_STR_LEN; i++ ) { 118 for (i = bits = 0; i < MACADDRESS_STR_LEN; i++) {
119 bits ^= szCrypt[i]; 119 bits ^= szCrypt[i];
120 bits += szCrypt[i]; 120 bits += szCrypt[i];
121 } 121 }
122 122
123 for( i = t = *szDest = 0; i < nLen; i++, t++ ) { 123 for (i = t = *szDest = 0; i < nLen; i++, t++) {
124 k = szData[i] ^ ( bits + i ); 124 k = szData[i] ^ (bits + i);
125 125
126 126
127 switch( i % 3 ) { 127 switch (i % 3) {
128 128
129 case 0 : 129 case 0:
130 130
131 szDest[t] = ((k & 0xFC) >> 2) + CH_START ; 131 szDest[t] = ((k & 0xFC) >> 2) + CH_START ;
132 szDest[t+1] = ((k & 0x03) << 4) + CH_START ; 132 szDest[t+1] = ((k & 0x03) << 4) + CH_START ;
133 szDest[t+2] = '\0'; 133 szDest[t+2] = '\0';
134 134
135 break; 135 break;
136 136
137 137
138 case 1 : 138 case 1:
139 139
140 szDest[t] += (( k & 0xF0 ) >> 4 ); 140 szDest[t] += ((k & 0xF0) >> 4);
141 szDest[t+1] = (( k & 0x0F ) << 2 ) + CH_START ; 141 szDest[t+1] = ((k & 0x0F) << 2) + CH_START ;
142 szDest[t+2] = '\0'; 142 szDest[t+2] = '\0';
143 143
144 break; 144 break;
145 145
146 146
147 case 2 : 147 case 2:
148 148
149 szDest[t] += (( k & 0xC0 ) >> 6 ); 149 szDest[t] += ((k & 0xC0) >> 6);
150 szDest[t+1] = ( k & 0x3F ) + CH_START ; 150 szDest[t+1] = (k & 0x3F) + CH_START ;
151 szDest[t+2] = '\0'; 151 szDest[t+2] = '\0';
152 t++; 152 t++;
153 153
154 break; 154 break;
155 } 155 }
156 } 156 }
157 157
158 return( strlen( szDest )) ; 158 return strlen(szDest);
159 159
160} 160}
161/*============================================================================*/ 161/*============================================================================*/
@@ -182,50 +182,50 @@ int wl_wep_code( char *szCrypt, char *szDest, void *Data, int nLen )
182 * OK 182 * OK
183 * 183 *
184 ******************************************************************************/ 184 ******************************************************************************/
185int wl_wep_decode( char *szCrypt, void *Dest, char *szData ) 185int wl_wep_decode(char *szCrypt, void *Dest, char *szData)
186{ 186{
187 int i; 187 int i;
188 int t; 188 int t;
189 int nLen; 189 int nLen;
190 char bits; 190 char bits;
191 char *szDest = Dest; 191 char *szDest = Dest;
192 /*------------------------------------------------------------------------*/ 192 /*------------------------------------------------------------------------*/
193 193
194 194
195 for( i = bits = 0 ; i < 12; i++ ) { 195 for (i = bits = 0; i < 12; i++) {
196 bits ^= szCrypt[i] ; 196 bits ^= szCrypt[i] ;
197 bits += szCrypt[i] ; 197 bits += szCrypt[i] ;
198 } 198 }
199 199
200 nLen = ( strlen( szData ) * 3) / 4 ; 200 nLen = (strlen(szData) * 3) / 4 ;
201 201
202 for( i = t = 0; i < nLen; i++, t++ ) { 202 for (i = t = 0; i < nLen; i++, t++) {
203 switch( i % 3 ) { 203 switch (i % 3) {
204 case 0 : 204 case 0:
205 205
206 szDest[i] = ((( szData[t]-CH_START ) & 0x3f ) << 2 ) + 206 szDest[i] = (((szData[t] - CH_START) & 0x3f) << 2) +
207 ((( szData[t+1]-CH_START ) & 0x30 ) >> 4 ); 207 (((szData[t+1] - CH_START) & 0x30) >> 4);
208 break; 208 break;
209 209
210 210
211 case 1 : 211 case 1:
212 szDest[i] = ((( szData[t]-CH_START ) & 0x0f ) << 4 ) + 212 szDest[i] = (((szData[t] - CH_START) & 0x0f) << 4) +
213 ((( szData[t+1]-CH_START ) & 0x3c ) >> 2 ); 213 (((szData[t+1] - CH_START) & 0x3c) >> 2);
214 break; 214 break;
215 215
216 216
217 case 2 : 217 case 2:
218 szDest[i] = ((( szData[t]-CH_START ) & 0x03 ) << 6 ) + 218 szDest[i] = (((szData[t] - CH_START) & 0x03) << 6) +
219 (( szData[t+1]-CH_START ) & 0x3f ); 219 ((szData[t+1] - CH_START) & 0x3f);
220 t++; 220 t++;
221 break; 221 break;
222 } 222 }
223 223
224 szDest[i] ^= ( bits + i ) ; 224 szDest[i] ^= (bits + i);
225 225
226 } 226 }
227 227
228 return( i ) ; 228 return i;
229 229
230} 230}
231/*============================================================================*/ 231/*============================================================================*/
diff --git a/drivers/staging/wlags49_h2/wl_netdev.h b/drivers/staging/wlags49_h2/wl_netdev.h
index 61f040f26d97..95bfbebf35d6 100644
--- a/drivers/staging/wlags49_h2/wl_netdev.h
+++ b/drivers/staging/wlags49_h2/wl_netdev.h
@@ -68,87 +68,87 @@
68/******************************************************************************* 68/*******************************************************************************
69 * function prototypes 69 * function prototypes
70 ******************************************************************************/ 70 ******************************************************************************/
71int wl_init( struct net_device *dev ); 71int wl_init(struct net_device *dev);
72 72
73int wl_config( struct net_device *dev, struct ifmap *map ); 73int wl_config(struct net_device *dev, struct ifmap *map);
74 74
75struct net_device *wl_device_alloc( void ); 75struct net_device *wl_device_alloc(void);
76 76
77void wl_device_dealloc( struct net_device *dev ); 77void wl_device_dealloc(struct net_device *dev);
78 78
79int wl_open( struct net_device *dev ); 79int wl_open(struct net_device *dev);
80 80
81int wl_close( struct net_device *dev ); 81int wl_close(struct net_device *dev);
82 82
83int wl_ioctl( struct net_device *dev, struct ifreq *rq, int cmd ); 83int wl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
84 84
85int wl_tx( struct sk_buff *skb, struct net_device *dev, int port ); 85int wl_tx(struct sk_buff *skb, struct net_device *dev, int port);
86 86
87int wl_send( struct wl_private *lp ); 87int wl_send(struct wl_private *lp);
88 88
89int wl_rx( struct net_device *dev ); 89int wl_rx(struct net_device *dev);
90 90
91void wl_tx_timeout( struct net_device *dev ); 91void wl_tx_timeout(struct net_device *dev);
92 92
93struct net_device_stats *wl_stats( struct net_device *dev ); 93struct net_device_stats *wl_stats(struct net_device *dev);
94 94
95 95
96#ifdef ENABLE_DMA 96#ifdef ENABLE_DMA
97int wl_send_dma( struct wl_private *lp, struct sk_buff *skb, int port ); 97int wl_send_dma(struct wl_private *lp, struct sk_buff *skb, int port);
98int wl_rx_dma( struct net_device *dev ); 98int wl_rx_dma(struct net_device *dev);
99#endif 99#endif
100 100
101#ifdef NEW_MULTICAST 101#ifdef NEW_MULTICAST
102void wl_multicast( struct net_device *dev ); 102void wl_multicast(struct net_device *dev);
103#else 103#else
104void wl_multicast( struct net_device *dev, int num_addrs, void *addrs ); 104void wl_multicast(struct net_device *dev, int num_addrs, void *addrs);
105#endif // NEW_MULTICAST 105#endif /* NEW_MULTICAST */
106 106
107 107
108int wl_tx_port0( struct sk_buff *skb, struct net_device *dev ); 108int wl_tx_port0(struct sk_buff *skb, struct net_device *dev);
109 109
110 110
111#ifdef USE_WDS 111#ifdef USE_WDS
112 112
113int wl_tx_port1( struct sk_buff *skb, struct net_device *dev ); 113int wl_tx_port1(struct sk_buff *skb, struct net_device *dev);
114int wl_tx_port2( struct sk_buff *skb, struct net_device *dev ); 114int wl_tx_port2(struct sk_buff *skb, struct net_device *dev);
115int wl_tx_port3( struct sk_buff *skb, struct net_device *dev ); 115int wl_tx_port3(struct sk_buff *skb, struct net_device *dev);
116int wl_tx_port4( struct sk_buff *skb, struct net_device *dev ); 116int wl_tx_port4(struct sk_buff *skb, struct net_device *dev);
117int wl_tx_port5( struct sk_buff *skb, struct net_device *dev ); 117int wl_tx_port5(struct sk_buff *skb, struct net_device *dev);
118int wl_tx_port6( struct sk_buff *skb, struct net_device *dev ); 118int wl_tx_port6(struct sk_buff *skb, struct net_device *dev);
119 119
120void wl_wds_device_alloc( struct wl_private *lp ); 120void wl_wds_device_alloc(struct wl_private *lp);
121void wl_wds_device_dealloc( struct wl_private *lp ); 121void wl_wds_device_dealloc(struct wl_private *lp);
122void wl_wds_netif_start_queue( struct wl_private *lp ); 122void wl_wds_netif_start_queue(struct wl_private *lp);
123void wl_wds_netif_stop_queue( struct wl_private *lp ); 123void wl_wds_netif_stop_queue(struct wl_private *lp);
124void wl_wds_netif_wake_queue( struct wl_private *lp ); 124void wl_wds_netif_wake_queue(struct wl_private *lp);
125void wl_wds_netif_carrier_on( struct wl_private *lp ); 125void wl_wds_netif_carrier_on(struct wl_private *lp);
126void wl_wds_netif_carrier_off( struct wl_private *lp ); 126void wl_wds_netif_carrier_off(struct wl_private *lp);
127 127
128#endif /* USE_WDS */ 128#endif /* USE_WDS */
129 129
130 130
131#ifdef USE_WDS 131#ifdef USE_WDS
132 132
133#define WL_WDS_DEVICE_ALLOC( ARG ) wl_wds_device_alloc( ARG ) 133#define WL_WDS_DEVICE_ALLOC(ARG) wl_wds_device_alloc(ARG)
134#define WL_WDS_DEVICE_DEALLOC( ARG ) wl_wds_device_dealloc( ARG ) 134#define WL_WDS_DEVICE_DEALLOC(ARG) wl_wds_device_dealloc(ARG)
135#define WL_WDS_NETIF_START_QUEUE( ARG ) wl_wds_netif_start_queue( ARG ) 135#define WL_WDS_NETIF_START_QUEUE(ARG) wl_wds_netif_start_queue(ARG)
136#define WL_WDS_NETIF_STOP_QUEUE( ARG ) wl_wds_netif_stop_queue( ARG ) 136#define WL_WDS_NETIF_STOP_QUEUE(ARG) wl_wds_netif_stop_queue(ARG)
137#define WL_WDS_NETIF_WAKE_QUEUE( ARG ) wl_wds_netif_wake_queue( ARG ) 137#define WL_WDS_NETIF_WAKE_QUEUE(ARG) wl_wds_netif_wake_queue(ARG)
138#define WL_WDS_NETIF_CARRIER_ON( ARG ) wl_wds_netif_carrier_on( ARG ) 138#define WL_WDS_NETIF_CARRIER_ON(ARG) wl_wds_netif_carrier_on(ARG)
139#define WL_WDS_NETIF_CARRIER_OFF( ARG ) wl_wds_netif_carrier_off( ARG ) 139#define WL_WDS_NETIF_CARRIER_OFF(ARG) wl_wds_netif_carrier_off(ARG)
140 140
141#else 141#else
142 142
143#define WL_WDS_DEVICE_ALLOC( ARG ) 143#define WL_WDS_DEVICE_ALLOC(ARG)
144#define WL_WDS_DEVICE_DEALLOC( ARG ) 144#define WL_WDS_DEVICE_DEALLOC(ARG)
145#define WL_WDS_NETIF_START_QUEUE( ARG ) 145#define WL_WDS_NETIF_START_QUEUE(ARG)
146#define WL_WDS_NETIF_STOP_QUEUE( ARG ) 146#define WL_WDS_NETIF_STOP_QUEUE(ARG)
147#define WL_WDS_NETIF_WAKE_QUEUE( ARG ) 147#define WL_WDS_NETIF_WAKE_QUEUE(ARG)
148#define WL_WDS_NETIF_CARRIER_ON( ARG ) 148#define WL_WDS_NETIF_CARRIER_ON(ARG)
149#define WL_WDS_NETIF_CARRIER_OFF( ARG ) 149#define WL_WDS_NETIF_CARRIER_OFF(ARG)
150 150
151#endif /* USE_WDS */ 151#endif /* USE_WDS */
152 152
153 153
154#endif // __WL_NETDEV_H__ 154#endif /* __WL_NETDEV_H__ */
diff --git a/drivers/staging/wlags49_h2/wl_priv.c b/drivers/staging/wlags49_h2/wl_priv.c
index 87e1e4123126..c97e0e154d28 100644
--- a/drivers/staging/wlags49_h2/wl_priv.c
+++ b/drivers/staging/wlags49_h2/wl_priv.c
@@ -67,7 +67,7 @@
67#include <linux/ioport.h> 67#include <linux/ioport.h>
68#include <linux/slab.h> 68#include <linux/slab.h>
69#include <linux/delay.h> 69#include <linux/delay.h>
70#include <asm/uaccess.h> 70#include <linux/uaccess.h>
71 71
72#include <debug.h> 72#include <debug.h>
73#include <hcf.h> 73#include <hcf.h>
@@ -81,17 +81,17 @@
81#include <wl_util.h> 81#include <wl_util.h>
82#include <wl_netdev.h> 82#include <wl_netdev.h>
83 83
84int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ); 84int wvlan_uil_connect(struct uilreq *urq, struct wl_private *lp);
85int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ); 85int wvlan_uil_disconnect(struct uilreq *urq, struct wl_private *lp);
86int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ); 86int wvlan_uil_action(struct uilreq *urq, struct wl_private *lp);
87int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ); 87int wvlan_uil_block(struct uilreq *urq, struct wl_private *lp);
88int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ); 88int wvlan_uil_unblock(struct uilreq *urq, struct wl_private *lp);
89int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ); 89int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp);
90int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ); 90int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp);
91int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ); 91int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp);
92 92
93int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ); 93int cfg_driver_info(struct uilreq *urq, struct wl_private *lp);
94int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ); 94int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp);
95 95
96 96
97/******************************************************************************* 97/*******************************************************************************
@@ -99,7 +99,7 @@ int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp );
99 ******************************************************************************/ 99 ******************************************************************************/
100#if DBG 100#if DBG
101extern dbg_info_t *DbgInfo; 101extern dbg_info_t *DbgInfo;
102#endif // DBG 102#endif /* DBG */
103 103
104 104
105 105
@@ -127,47 +127,47 @@ extern dbg_info_t *DbgInfo;
127 * errno value otherwise 127 * errno value otherwise
128 * 128 *
129 ******************************************************************************/ 129 ******************************************************************************/
130int wvlan_uil( struct uilreq *urq, struct wl_private *lp ) 130int wvlan_uil(struct uilreq *urq, struct wl_private *lp)
131{ 131{
132 int ioctl_ret = 0; 132 int ioctl_ret = 0;
133 /*------------------------------------------------------------------------*/ 133 /*------------------------------------------------------------------------*/
134 134
135 DBG_FUNC( "wvlan_uil" ); 135 DBG_FUNC("wvlan_uil");
136 DBG_ENTER( DbgInfo ); 136 DBG_ENTER(DbgInfo);
137 137
138 switch( urq->command ) { 138 switch (urq->command) {
139 case UIL_FUN_CONNECT: 139 case UIL_FUN_CONNECT:
140 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_CONNECT\n"); 140 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_CONNECT\n");
141 ioctl_ret = wvlan_uil_connect( urq, lp ); 141 ioctl_ret = wvlan_uil_connect(urq, lp);
142 break; 142 break;
143 case UIL_FUN_DISCONNECT: 143 case UIL_FUN_DISCONNECT:
144 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_DISCONNECT\n"); 144 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_DISCONNECT\n");
145 ioctl_ret = wvlan_uil_disconnect( urq, lp ); 145 ioctl_ret = wvlan_uil_disconnect(urq, lp);
146 break; 146 break;
147 case UIL_FUN_ACTION: 147 case UIL_FUN_ACTION:
148 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_ACTION\n" ); 148 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_ACTION\n");
149 ioctl_ret = wvlan_uil_action( urq, lp ); 149 ioctl_ret = wvlan_uil_action(urq, lp);
150 break; 150 break;
151 case UIL_FUN_SEND_DIAG_MSG: 151 case UIL_FUN_SEND_DIAG_MSG:
152 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_SEND_DIAG_MSG\n"); 152 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_SEND_DIAG_MSG\n");
153 ioctl_ret = wvlan_uil_send_diag_msg( urq, lp ); 153 ioctl_ret = wvlan_uil_send_diag_msg(urq, lp);
154 break; 154 break;
155 case UIL_FUN_GET_INFO: 155 case UIL_FUN_GET_INFO:
156 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_GET_INFO\n"); 156 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_GET_INFO\n");
157 ioctl_ret = wvlan_uil_get_info( urq, lp ); 157 ioctl_ret = wvlan_uil_get_info(urq, lp);
158 break; 158 break;
159 case UIL_FUN_PUT_INFO: 159 case UIL_FUN_PUT_INFO:
160 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_PUT_INFO\n"); 160 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- WVLAN2_UIL_PUT_INFO\n");
161 ioctl_ret = wvlan_uil_put_info( urq, lp ); 161 ioctl_ret = wvlan_uil_put_info(urq, lp);
162 break; 162 break;
163 default: 163 default:
164 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- UNSUPPORTED UIL CODE: 0x%X", urq->command ); 164 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_UIL -- UNSUPPORTED UIL CODE: 0x%X", urq->command);
165 ioctl_ret = -EOPNOTSUPP; 165 ioctl_ret = -EOPNOTSUPP;
166 break; 166 break;
167 } 167 }
168 DBG_LEAVE( DbgInfo ); 168 DBG_LEAVE(DbgInfo);
169 return ioctl_ret; 169 return ioctl_ret;
170} // wvlan_uil 170} /* wvlan_uil */
171/*============================================================================*/ 171/*============================================================================*/
172 172
173 173
@@ -192,28 +192,28 @@ int wvlan_uil( struct uilreq *urq, struct wl_private *lp )
192 * UIL_ERR_xxx value otherwise 192 * UIL_ERR_xxx value otherwise
193 * 193 *
194 ******************************************************************************/ 194 ******************************************************************************/
195int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ) 195int wvlan_uil_connect(struct uilreq *urq, struct wl_private *lp)
196{ 196{
197 int result = 0; 197 int result = 0;
198 /*------------------------------------------------------------------------*/ 198 /*------------------------------------------------------------------------*/
199 199
200 200
201 DBG_FUNC( "wvlan_uil_connect" ); 201 DBG_FUNC("wvlan_uil_connect");
202 DBG_ENTER( DbgInfo ); 202 DBG_ENTER(DbgInfo);
203 203
204 204
205 if( !( lp->flags & WVLAN2_UIL_CONNECTED )) { 205 if (!(lp->flags & WVLAN2_UIL_CONNECTED)) {
206 lp->flags |= WVLAN2_UIL_CONNECTED; 206 lp->flags |= WVLAN2_UIL_CONNECTED;
207 urq->hcfCtx = &( lp->hcfCtx ); 207 urq->hcfCtx = &(lp->hcfCtx);
208 urq->result = UIL_SUCCESS; 208 urq->result = UIL_SUCCESS;
209 } else { 209 } else {
210 DBG_WARNING( DbgInfo, "UIL_ERR_IN_USE\n" ); 210 DBG_WARNING(DbgInfo, "UIL_ERR_IN_USE\n");
211 urq->result = UIL_ERR_IN_USE; 211 urq->result = UIL_ERR_IN_USE;
212 } 212 }
213 213
214 DBG_LEAVE( DbgInfo ); 214 DBG_LEAVE(DbgInfo);
215 return result; 215 return result;
216} // wvlan_uil_connect 216} /* wvlan_uil_connect */
217/*============================================================================*/ 217/*============================================================================*/
218 218
219 219
@@ -238,17 +238,17 @@ int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp )
238 * UIL_ERR_xxx value otherwise 238 * UIL_ERR_xxx value otherwise
239 * 239 *
240 ******************************************************************************/ 240 ******************************************************************************/
241int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ) 241int wvlan_uil_disconnect(struct uilreq *urq, struct wl_private *lp)
242{ 242{
243 int result = 0; 243 int result = 0;
244 /*------------------------------------------------------------------------*/ 244 /*------------------------------------------------------------------------*/
245 245
246 246
247 DBG_FUNC( "wvlan_uil_disconnect" ); 247 DBG_FUNC("wvlan_uil_disconnect");
248 DBG_ENTER( DbgInfo ); 248 DBG_ENTER(DbgInfo);
249 249
250 250
251 if( urq->hcfCtx == &( lp->hcfCtx )) { 251 if (urq->hcfCtx == &(lp->hcfCtx)) {
252 if (lp->flags & WVLAN2_UIL_CONNECTED) { 252 if (lp->flags & WVLAN2_UIL_CONNECTED) {
253 lp->flags &= ~WVLAN2_UIL_CONNECTED; 253 lp->flags &= ~WVLAN2_UIL_CONNECTED;
254 /* 254 /*
@@ -262,13 +262,13 @@ int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp )
262 urq->hcfCtx = NULL; 262 urq->hcfCtx = NULL;
263 urq->result = UIL_SUCCESS; 263 urq->result = UIL_SUCCESS;
264 } else { 264 } else {
265 DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); 265 DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n");
266 urq->result = UIL_ERR_WRONG_IFB; 266 urq->result = UIL_ERR_WRONG_IFB;
267 } 267 }
268 268
269 DBG_LEAVE( DbgInfo ); 269 DBG_LEAVE(DbgInfo);
270 return result; 270 return result;
271} // wvlan_uil_disconnect 271} /* wvlan_uil_disconnect */
272/*============================================================================*/ 272/*============================================================================*/
273 273
274 274
@@ -293,60 +293,60 @@ int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp )
293 * UIL_ERR_xxx value otherwise 293 * UIL_ERR_xxx value otherwise
294 * 294 *
295 ******************************************************************************/ 295 ******************************************************************************/
296int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ) 296int wvlan_uil_action(struct uilreq *urq, struct wl_private *lp)
297{ 297{
298 int result = 0; 298 int result = 0;
299 ltv_t *ltv; 299 ltv_t *ltv;
300 /*------------------------------------------------------------------------*/ 300 /*------------------------------------------------------------------------*/
301 301
302 302
303 DBG_FUNC( "wvlan_uil_action" ); 303 DBG_FUNC("wvlan_uil_action");
304 DBG_ENTER( DbgInfo ); 304 DBG_ENTER(DbgInfo);
305 305
306 306
307 if( urq->hcfCtx == &( lp->hcfCtx )) { 307 if (urq->hcfCtx == &(lp->hcfCtx)) {
308 /* Make sure there's an LTV in the request buffer */ 308 /* Make sure there's an LTV in the request buffer */
309 ltv = (ltv_t *)urq->data; 309 ltv = (ltv_t *)urq->data;
310 if( ltv != NULL ) { 310 if (ltv != NULL) {
311 /* Switch on the Type field of the LTV contained in the request 311 /* Switch on the Type field of the LTV contained in the request
312 buffer */ 312 buffer */
313 switch( ltv->typ ) { 313 switch (ltv->typ) {
314 case UIL_ACT_BLOCK: 314 case UIL_ACT_BLOCK:
315 DBG_TRACE( DbgInfo, "UIL_ACT_BLOCK\n" ); 315 DBG_TRACE(DbgInfo, "UIL_ACT_BLOCK\n");
316 result = wvlan_uil_block( urq, lp ); 316 result = wvlan_uil_block(urq, lp);
317 break; 317 break;
318 case UIL_ACT_UNBLOCK: 318 case UIL_ACT_UNBLOCK:
319 DBG_TRACE( DbgInfo, "UIL_ACT_UNBLOCK\n" ); 319 DBG_TRACE(DbgInfo, "UIL_ACT_UNBLOCK\n");
320 result = wvlan_uil_unblock( urq, lp ); 320 result = wvlan_uil_unblock(urq, lp);
321 break; 321 break;
322 case UIL_ACT_SCAN: 322 case UIL_ACT_SCAN:
323 DBG_TRACE( DbgInfo, "UIL_ACT_SCAN\n" ); 323 DBG_TRACE(DbgInfo, "UIL_ACT_SCAN\n");
324 urq->result = hcf_action( &( lp->hcfCtx ), MDD_ACT_SCAN ); 324 urq->result = hcf_action(&(lp->hcfCtx), MDD_ACT_SCAN);
325 break; 325 break;
326 case UIL_ACT_APPLY: 326 case UIL_ACT_APPLY:
327 DBG_TRACE( DbgInfo, "UIL_ACT_APPLY\n" ); 327 DBG_TRACE(DbgInfo, "UIL_ACT_APPLY\n");
328 urq->result = wl_apply( lp ); 328 urq->result = wl_apply(lp);
329 break; 329 break;
330 case UIL_ACT_RESET: 330 case UIL_ACT_RESET:
331 DBG_TRACE( DbgInfo, "UIL_ACT_RESET\n" ); 331 DBG_TRACE(DbgInfo, "UIL_ACT_RESET\n");
332 urq->result = wl_go( lp ); 332 urq->result = wl_go(lp);
333 break; 333 break;
334 default: 334 default:
335 DBG_WARNING( DbgInfo, "Unknown action code: 0x%x\n", ltv->typ ); 335 DBG_WARNING(DbgInfo, "Unknown action code: 0x%x\n", ltv->typ);
336 break; 336 break;
337 } 337 }
338 } else { 338 } else {
339 DBG_ERROR( DbgInfo, "Bad LTV for this action\n" ); 339 DBG_ERROR(DbgInfo, "Bad LTV for this action\n");
340 urq->result = UIL_ERR_LEN; 340 urq->result = UIL_ERR_LEN;
341 } 341 }
342 } else { 342 } else {
343 DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); 343 DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n");
344 urq->result = UIL_ERR_WRONG_IFB; 344 urq->result = UIL_ERR_WRONG_IFB;
345 } 345 }
346 346
347 DBG_LEAVE( DbgInfo ); 347 DBG_LEAVE(DbgInfo);
348 return result; 348 return result;
349} // wvlan_uil_action 349} /* wvlan_uil_action */
350/*============================================================================*/ 350/*============================================================================*/
351 351
352 352
@@ -373,34 +373,34 @@ int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp )
373 * 373 *
374 ******************************************************************************/ 374 ******************************************************************************/
375 375
376int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ) 376int wvlan_uil_block(struct uilreq *urq, struct wl_private *lp)
377{ 377{
378 int result = 0; 378 int result = 0;
379 /*------------------------------------------------------------------------*/ 379 /*------------------------------------------------------------------------*/
380 380
381 381
382 DBG_FUNC( "wvlan_uil_block" ); 382 DBG_FUNC("wvlan_uil_block");
383 DBG_ENTER( DbgInfo ); 383 DBG_ENTER(DbgInfo);
384 384
385 if( urq->hcfCtx == &( lp->hcfCtx )) { 385 if (urq->hcfCtx == &(lp->hcfCtx)) {
386 if( capable( CAP_NET_ADMIN )) { 386 if (capable(CAP_NET_ADMIN)) {
387 lp->flags |= WVLAN2_UIL_BUSY; 387 lp->flags |= WVLAN2_UIL_BUSY;
388 netif_stop_queue(lp->dev); 388 netif_stop_queue(lp->dev);
389 WL_WDS_NETIF_STOP_QUEUE( lp ); 389 WL_WDS_NETIF_STOP_QUEUE(lp);
390 urq->result = UIL_SUCCESS; 390 urq->result = UIL_SUCCESS;
391 } else { 391 } else {
392 DBG_ERROR( DbgInfo, "EPERM\n" ); 392 DBG_ERROR(DbgInfo, "EPERM\n");
393 urq->result = UIL_FAILURE; 393 urq->result = UIL_FAILURE;
394 result = -EPERM; 394 result = -EPERM;
395 } 395 }
396 } else { 396 } else {
397 DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); 397 DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n");
398 urq->result = UIL_ERR_WRONG_IFB; 398 urq->result = UIL_ERR_WRONG_IFB;
399 } 399 }
400 400
401 DBG_LEAVE( DbgInfo ); 401 DBG_LEAVE(DbgInfo);
402 return result; 402 return result;
403} // wvlan_uil_block 403} /* wvlan_uil_block */
404/*============================================================================*/ 404/*============================================================================*/
405 405
406 406
@@ -425,35 +425,35 @@ int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp )
425 * UIL_ERR_xxx value otherwise 425 * UIL_ERR_xxx value otherwise
426 * 426 *
427 ******************************************************************************/ 427 ******************************************************************************/
428int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ) 428int wvlan_uil_unblock(struct uilreq *urq, struct wl_private *lp)
429{ 429{
430 int result = 0; 430 int result = 0;
431 /*------------------------------------------------------------------------*/ 431 /*------------------------------------------------------------------------*/
432 432
433 433
434 DBG_FUNC( "wvlan_uil_unblock" ); 434 DBG_FUNC("wvlan_uil_unblock");
435 DBG_ENTER( DbgInfo ); 435 DBG_ENTER(DbgInfo);
436 436
437 if( urq->hcfCtx == &( lp->hcfCtx )) { 437 if (urq->hcfCtx == &(lp->hcfCtx)) {
438 if( capable( CAP_NET_ADMIN )) { 438 if (capable(CAP_NET_ADMIN)) {
439 if (lp->flags & WVLAN2_UIL_BUSY) { 439 if (lp->flags & WVLAN2_UIL_BUSY) {
440 lp->flags &= ~WVLAN2_UIL_BUSY; 440 lp->flags &= ~WVLAN2_UIL_BUSY;
441 netif_wake_queue(lp->dev); 441 netif_wake_queue(lp->dev);
442 WL_WDS_NETIF_WAKE_QUEUE( lp ); 442 WL_WDS_NETIF_WAKE_QUEUE(lp);
443 } 443 }
444 } else { 444 } else {
445 DBG_ERROR( DbgInfo, "EPERM\n" ); 445 DBG_ERROR(DbgInfo, "EPERM\n");
446 urq->result = UIL_FAILURE; 446 urq->result = UIL_FAILURE;
447 result = -EPERM; 447 result = -EPERM;
448 } 448 }
449 } else { 449 } else {
450 DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); 450 DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n");
451 urq->result = UIL_ERR_WRONG_IFB; 451 urq->result = UIL_ERR_WRONG_IFB;
452 } 452 }
453 453
454 DBG_LEAVE( DbgInfo ); 454 DBG_LEAVE(DbgInfo);
455 return result; 455 return result;
456} // wvlan_uil_unblock 456} /* wvlan_uil_unblock */
457/*============================================================================*/ 457/*============================================================================*/
458 458
459 459
@@ -478,47 +478,47 @@ int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp )
478 * UIL_ERR_xxx value otherwise 478 * UIL_ERR_xxx value otherwise
479 * 479 *
480 ******************************************************************************/ 480 ******************************************************************************/
481int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ) 481int wvlan_uil_send_diag_msg(struct uilreq *urq, struct wl_private *lp)
482{ 482{
483 int result = 0; 483 int result = 0;
484 DESC_STRCT Descp[1]; 484 DESC_STRCT Descp[1];
485 /*------------------------------------------------------------------------*/ 485 /*------------------------------------------------------------------------*/
486 486
487 487
488 DBG_FUNC( "wvlan_uil_send_diag_msg" ); 488 DBG_FUNC("wvlan_uil_send_diag_msg");
489 DBG_ENTER( DbgInfo ); 489 DBG_ENTER(DbgInfo);
490 490
491 if( urq->hcfCtx == &( lp->hcfCtx )) { 491 if (urq->hcfCtx == &(lp->hcfCtx)) {
492 if( capable( CAP_NET_ADMIN )) { 492 if (capable(CAP_NET_ADMIN)) {
493 if ((urq->data != NULL) && (urq->len != 0)) { 493 if ((urq->data != NULL) && (urq->len != 0)) {
494 if (lp->hcfCtx.IFB_RscInd != 0) { 494 if (lp->hcfCtx.IFB_RscInd != 0) {
495 u_char *data; 495 u_char *data;
496 496
497 // Verify the user buffer 497 /* Verify the user buffer */
498 result = verify_area(VERIFY_READ, urq->data, urq->len); 498 result = verify_area(VERIFY_READ, urq->data, urq->len);
499 if (result != 0) { 499 if (result != 0) {
500 DBG_ERROR( DbgInfo, "verify_area failed, result: %d\n", result ); 500 DBG_ERROR(DbgInfo, "verify_area failed, result: %d\n", result);
501 urq->result = UIL_FAILURE; 501 urq->result = UIL_FAILURE;
502 DBG_LEAVE( DbgInfo ); 502 DBG_LEAVE(DbgInfo);
503 return result; 503 return result;
504 } 504 }
505 505
506 data = kmalloc(urq->len, GFP_KERNEL); 506 data = kmalloc(urq->len, GFP_KERNEL);
507 if (data != NULL) { 507 if (data != NULL) {
508 memset( Descp, 0, sizeof( DESC_STRCT )); 508 memset(Descp, 0, sizeof(DESC_STRCT));
509 memcpy( data, urq->data, urq->len ); 509 memcpy(data, urq->data, urq->len);
510 510
511 Descp[0].buf_addr = (wci_bufp)data; 511 Descp[0].buf_addr = (wci_bufp)data;
512 Descp[0].BUF_CNT = urq->len; 512 Descp[0].BUF_CNT = urq->len;
513 Descp[0].next_desc_addr = 0; // terminate list 513 Descp[0].next_desc_addr = 0; /* terminate list */
514 514
515 hcf_send_msg( &(lp->hcfCtx), &Descp[0], HCF_PORT_0 ); 515 hcf_send_msg(&(lp->hcfCtx), &Descp[0], HCF_PORT_0);
516 kfree( data ); 516 kfree(data);
517 } else { 517 } else {
518 DBG_ERROR( DbgInfo, "ENOMEM\n" ); 518 DBG_ERROR(DbgInfo, "ENOMEM\n");
519 urq->result = UIL_FAILURE; 519 urq->result = UIL_FAILURE;
520 result = -ENOMEM; 520 result = -ENOMEM;
521 DBG_LEAVE( DbgInfo ); 521 DBG_LEAVE(DbgInfo);
522 return result; 522 return result;
523 } 523 }
524 524
@@ -530,18 +530,18 @@ int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp )
530 urq->result = UIL_FAILURE; 530 urq->result = UIL_FAILURE;
531 } 531 }
532 } else { 532 } else {
533 DBG_ERROR( DbgInfo, "EPERM\n" ); 533 DBG_ERROR(DbgInfo, "EPERM\n");
534 urq->result = UIL_FAILURE; 534 urq->result = UIL_FAILURE;
535 result = -EPERM; 535 result = -EPERM;
536 } 536 }
537 } else { 537 } else {
538 DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); 538 DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n");
539 urq->result = UIL_ERR_WRONG_IFB; 539 urq->result = UIL_ERR_WRONG_IFB;
540 } 540 }
541 541
542 DBG_LEAVE( DbgInfo ); 542 DBG_LEAVE(DbgInfo);
543 return result; 543 return result;
544} // wvlan_uil_send_diag_msg 544} /* wvlan_uil_send_diag_msg */
545/*============================================================================*/ 545/*============================================================================*/
546 546
547 547
@@ -564,7 +564,7 @@ int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp )
564 * UIL_ERR_xxx value otherwise 564 * UIL_ERR_xxx value otherwise
565 * 565 *
566 ******************************************************************************/ 566 ******************************************************************************/
567int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ) 567int wvlan_uil_put_info(struct uilreq *urq, struct wl_private *lp)
568{ 568{
569 int result = 0; 569 int result = 0;
570 ltv_t *pLtv; 570 ltv_t *pLtv;
@@ -575,94 +575,94 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
575 hcf_16 hcfPort = HCF_PORT_0; 575 hcf_16 hcfPort = HCF_PORT_0;
576#endif /* USE_WDS */ 576#endif /* USE_WDS */
577 /*------------------------------------------------------------------------*/ 577 /*------------------------------------------------------------------------*/
578 DBG_FUNC( "wvlan_uil_put_info" ); 578 DBG_FUNC("wvlan_uil_put_info");
579 DBG_ENTER( DbgInfo ); 579 DBG_ENTER(DbgInfo);
580 580
581 581
582 if( urq->hcfCtx == &( lp->hcfCtx )) { 582 if (urq->hcfCtx == &(lp->hcfCtx)) {
583 if( capable( CAP_NET_ADMIN )) { 583 if (capable(CAP_NET_ADMIN)) {
584 if(( urq->data != NULL ) && ( urq->len != 0 )) { 584 if ((urq->data != NULL) && (urq->len != 0)) {
585 /* Make sure that we have at least a command and length to send. */ 585 /* Make sure that we have at least a command and length to send. */
586 if( urq->len < ( sizeof( hcf_16 ) * 2 )) { 586 if (urq->len < (sizeof(hcf_16) * 2)) {
587 urq->len = sizeof( lp->ltvRecord ); 587 urq->len = sizeof(lp->ltvRecord);
588 urq->result = UIL_ERR_LEN; 588 urq->result = UIL_ERR_LEN;
589 DBG_ERROR( DbgInfo, "No Length/Type in LTV!!!\n" ); 589 DBG_ERROR(DbgInfo, "No Length/Type in LTV!!!\n");
590 DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); 590 DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n");
591 DBG_LEAVE( DbgInfo ); 591 DBG_LEAVE(DbgInfo);
592 return result; 592 return result;
593 } 593 }
594 594
595 /* Verify the user buffer */ 595 /* Verify the user buffer */
596 result = verify_area( VERIFY_READ, urq->data, urq->len ); 596 result = verify_area(VERIFY_READ, urq->data, urq->len);
597 if( result != 0 ) { 597 if (result != 0) {
598 urq->result = UIL_FAILURE; 598 urq->result = UIL_FAILURE;
599 DBG_ERROR( DbgInfo, "verify_area(), VERIFY_READ FAILED\n" ); 599 DBG_ERROR(DbgInfo, "verify_area(), VERIFY_READ FAILED\n");
600 DBG_LEAVE( DbgInfo ); 600 DBG_LEAVE(DbgInfo);
601 return result; 601 return result;
602 } 602 }
603 603
604 /* Get only the command and length information. */ 604 /* Get only the command and length information. */
605 copy_from_user( &( lp->ltvRecord ), urq->data, sizeof( hcf_16 ) * 2 ); 605 copy_from_user(&(lp->ltvRecord), urq->data, sizeof(hcf_16) * 2);
606 606
607 /* Make sure the incoming LTV record length is within the bounds of the 607 /* Make sure the incoming LTV record length is within the bounds of the
608 IOCTL length */ 608 IOCTL length */
609 if((( lp->ltvRecord.len + 1 ) * sizeof( hcf_16 )) > urq->len ) { 609 if (((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) {
610 urq->len = sizeof( lp->ltvRecord ); 610 urq->len = sizeof(lp->ltvRecord);
611 urq->result = UIL_ERR_LEN; 611 urq->result = UIL_ERR_LEN;
612 DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); 612 DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n");
613 DBG_LEAVE( DbgInfo ); 613 DBG_LEAVE(DbgInfo);
614 return result; 614 return result;
615 } 615 }
616 616
617 /* If the requested length is greater than the size of our local 617 /* If the requested length is greater than the size of our local
618 LTV record, try to allocate it from the kernel stack. 618 LTV record, try to allocate it from the kernel stack.
619 Otherwise, we just use our local LTV record. */ 619 Otherwise, we just use our local LTV record. */
620 if( urq->len > sizeof( lp->ltvRecord )) { 620 if (urq->len > sizeof(lp->ltvRecord)) {
621 pLtv = kmalloc(urq->len, GFP_KERNEL); 621 pLtv = kmalloc(urq->len, GFP_KERNEL);
622 if (pLtv != NULL) { 622 if (pLtv != NULL) {
623 ltvAllocated = TRUE; 623 ltvAllocated = TRUE;
624 } else { 624 } else {
625 DBG_ERROR( DbgInfo, "Alloc FAILED\n" ); 625 DBG_ERROR(DbgInfo, "Alloc FAILED\n");
626 urq->len = sizeof( lp->ltvRecord ); 626 urq->len = sizeof(lp->ltvRecord);
627 urq->result = UIL_ERR_LEN; 627 urq->result = UIL_ERR_LEN;
628 result = -ENOMEM; 628 result = -ENOMEM;
629 DBG_LEAVE( DbgInfo ); 629 DBG_LEAVE(DbgInfo);
630 return result; 630 return result;
631 } 631 }
632 } else { 632 } else {
633 pLtv = &( lp->ltvRecord ); 633 pLtv = &(lp->ltvRecord);
634 } 634 }
635 635
636 /* Copy the data from the user's buffer into the local LTV 636 /* Copy the data from the user's buffer into the local LTV
637 record data area. */ 637 record data area. */
638 copy_from_user( pLtv, urq->data, urq->len ); 638 copy_from_user(pLtv, urq->data, urq->len);
639 639
640 640
641 /* We need to snoop the commands to see if there is anything we 641 /* We need to snoop the commands to see if there is anything we
642 need to store for the purposes of a reset or start/stop 642 need to store for the purposes of a reset or start/stop
643 sequence. Perform endian translation as needed */ 643 sequence. Perform endian translation as needed */
644 switch( pLtv->typ ) { 644 switch (pLtv->typ) {
645 case CFG_CNF_PORT_TYPE: 645 case CFG_CNF_PORT_TYPE:
646 lp->PortType = pLtv->u.u16[0]; 646 lp->PortType = pLtv->u.u16[0];
647 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 647 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
648 break; 648 break;
649 case CFG_CNF_OWN_MAC_ADDR: 649 case CFG_CNF_OWN_MAC_ADDR:
650 /* TODO: determine if we are going to store anything based on this */ 650 /* TODO: determine if we are going to store anything based on this */
651 break; 651 break;
652 case CFG_CNF_OWN_CHANNEL: 652 case CFG_CNF_OWN_CHANNEL:
653 lp->Channel = pLtv->u.u16[0]; 653 lp->Channel = pLtv->u.u16[0];
654 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 654 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
655 break; 655 break;
656 /* CFG_CNF_OWN_SSID currently same as CNF_DESIRED_SSID. Do we 656 /* CFG_CNF_OWN_SSID currently same as CNF_DESIRED_SSID. Do we
657 need separate storage for this? */ 657 need separate storage for this? */
658 //case CFG_CNF_OWN_SSID: 658 /* case CFG_CNF_OWN_SSID: */
659 case CFG_CNF_OWN_ATIM_WINDOW: 659 case CFG_CNF_OWN_ATIM_WINDOW:
660 lp->atimWindow = pLtv->u.u16[0]; 660 lp->atimWindow = pLtv->u.u16[0];
661 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 661 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
662 break; 662 break;
663 case CFG_CNF_SYSTEM_SCALE: 663 case CFG_CNF_SYSTEM_SCALE:
664 lp->DistanceBetweenAPs = pLtv->u.u16[0]; 664 lp->DistanceBetweenAPs = pLtv->u.u16[0];
665 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 665 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
666 666
667 case CFG_CNF_MAX_DATA_LEN: 667 case CFG_CNF_MAX_DATA_LEN:
668 /* TODO: determine if we are going to store anything based 668 /* TODO: determine if we are going to store anything based
@@ -670,163 +670,163 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
670 break; 670 break;
671 case CFG_CNF_PM_ENABLED: 671 case CFG_CNF_PM_ENABLED:
672 lp->PMEnabled = pLtv->u.u16[0]; 672 lp->PMEnabled = pLtv->u.u16[0];
673 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 673 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
674 break; 674 break;
675 case CFG_CNF_MCAST_RX: 675 case CFG_CNF_MCAST_RX:
676 lp->MulticastReceive = pLtv->u.u16[0]; 676 lp->MulticastReceive = pLtv->u.u16[0];
677 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 677 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
678 break; 678 break;
679 case CFG_CNF_MAX_SLEEP_DURATION: 679 case CFG_CNF_MAX_SLEEP_DURATION:
680 lp->MaxSleepDuration = pLtv->u.u16[0]; 680 lp->MaxSleepDuration = pLtv->u.u16[0];
681 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 681 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
682 break; 682 break;
683 case CFG_CNF_HOLDOVER_DURATION: 683 case CFG_CNF_HOLDOVER_DURATION:
684 lp->holdoverDuration = pLtv->u.u16[0]; 684 lp->holdoverDuration = pLtv->u.u16[0];
685 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 685 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
686 break; 686 break;
687 case CFG_CNF_OWN_NAME: 687 case CFG_CNF_OWN_NAME:
688 memset( lp->StationName, 0, sizeof( lp->StationName )); 688 memset(lp->StationName, 0, sizeof(lp->StationName));
689 memcpy( (void *)lp->StationName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); 689 memcpy((void *)lp->StationName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]);
690 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 690 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
691 break; 691 break;
692 case CFG_CNF_LOAD_BALANCING: 692 case CFG_CNF_LOAD_BALANCING:
693 lp->loadBalancing = pLtv->u.u16[0]; 693 lp->loadBalancing = pLtv->u.u16[0];
694 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 694 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
695 break; 695 break;
696 case CFG_CNF_MEDIUM_DISTRIBUTION: 696 case CFG_CNF_MEDIUM_DISTRIBUTION:
697 lp->mediumDistribution = pLtv->u.u16[0]; 697 lp->mediumDistribution = pLtv->u.u16[0];
698 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 698 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
699 break; 699 break;
700#ifdef WARP 700#ifdef WARP
701 case CFG_CNF_TX_POW_LVL: 701 case CFG_CNF_TX_POW_LVL:
702 lp->txPowLevel = pLtv->u.u16[0]; 702 lp->txPowLevel = pLtv->u.u16[0];
703 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 703 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
704 break; 704 break;
705 //case CFG_CNF_SHORT_RETRY_LIMIT: // Short Retry Limit 705 /* case CFG_CNF_SHORT_RETRY_LIMIT: */ /* Short Retry Limit */
706 //case 0xFC33: // Long Retry Limit 706 /* case 0xFC33: */ /* Long Retry Limit */
707 case CFG_SUPPORTED_RATE_SET_CNTL: // Supported Rate Set Control 707 case CFG_SUPPORTED_RATE_SET_CNTL: /* Supported Rate Set Control */
708 lp->srsc[0] = pLtv->u.u16[0]; 708 lp->srsc[0] = pLtv->u.u16[0];
709 lp->srsc[1] = pLtv->u.u16[1]; 709 lp->srsc[1] = pLtv->u.u16[1];
710 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 710 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
711 pLtv->u.u16[1] = CNV_INT_TO_LITTLE( pLtv->u.u16[1] ); 711 pLtv->u.u16[1] = CNV_INT_TO_LITTLE(pLtv->u.u16[1]);
712 break; 712 break;
713 case CFG_BASIC_RATE_SET_CNTL: // Basic Rate Set Control 713 case CFG_BASIC_RATE_SET_CNTL: /* Basic Rate Set Control */
714 lp->brsc[0] = pLtv->u.u16[0]; 714 lp->brsc[0] = pLtv->u.u16[0];
715 lp->brsc[1] = pLtv->u.u16[1]; 715 lp->brsc[1] = pLtv->u.u16[1];
716 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 716 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
717 pLtv->u.u16[1] = CNV_INT_TO_LITTLE( pLtv->u.u16[1] ); 717 pLtv->u.u16[1] = CNV_INT_TO_LITTLE(pLtv->u.u16[1]);
718 break; 718 break;
719 case CFG_CNF_CONNECTION_CNTL: 719 case CFG_CNF_CONNECTION_CNTL:
720 lp->connectionControl = pLtv->u.u16[0]; 720 lp->connectionControl = pLtv->u.u16[0];
721 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 721 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
722 break; 722 break;
723 //case CFG_PROBE_DATA_RATE: 723 /* case CFG_PROBE_DATA_RATE: */
724#endif // HERMES25 724#endif /* HERMES25 */
725 725
726#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP 726#if 1 /* ;? (HCF_TYPE) & HCF_TYPE_AP */
727 //;?should we restore this to allow smaller memory footprint 727 /* ;?should we restore this to allow smaller memory footprint */
728 728
729 case CFG_CNF_OWN_DTIM_PERIOD: 729 case CFG_CNF_OWN_DTIM_PERIOD:
730 lp->DTIMPeriod = pLtv->u.u16[0]; 730 lp->DTIMPeriod = pLtv->u.u16[0];
731 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 731 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
732 break; 732 break;
733#ifdef WARP 733#ifdef WARP
734 case CFG_CNF_OWN_BEACON_INTERVAL: // Own Beacon Interval 734 case CFG_CNF_OWN_BEACON_INTERVAL: /* Own Beacon Interval */
735 lp->ownBeaconInterval = pLtv->u.u16[0]; 735 lp->ownBeaconInterval = pLtv->u.u16[0];
736 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 736 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
737 break; 737 break;
738#endif // WARP 738#endif /* WARP */
739 case CFG_COEXISTENSE_BEHAVIOUR: // Coexistence behavior 739 case CFG_COEXISTENSE_BEHAVIOUR: /* Coexistence behavior */
740 lp->coexistence = pLtv->u.u16[0]; 740 lp->coexistence = pLtv->u.u16[0];
741 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 741 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
742 break; 742 break;
743#ifdef USE_WDS 743#ifdef USE_WDS
744 case CFG_CNF_WDS_ADDR1: 744 case CFG_CNF_WDS_ADDR1:
745 memcpy( &lp->wds_port[0].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); 745 memcpy(&lp->wds_port[0].wdsAddress, &pLtv->u.u8[0], ETH_ALEN);
746 hcfPort = HCF_PORT_1; 746 hcfPort = HCF_PORT_1;
747 break; 747 break;
748 case CFG_CNF_WDS_ADDR2: 748 case CFG_CNF_WDS_ADDR2:
749 memcpy( &lp->wds_port[1].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); 749 memcpy(&lp->wds_port[1].wdsAddress, &pLtv->u.u8[0], ETH_ALEN);
750 hcfPort = HCF_PORT_2; 750 hcfPort = HCF_PORT_2;
751 break; 751 break;
752 case CFG_CNF_WDS_ADDR3: 752 case CFG_CNF_WDS_ADDR3:
753 memcpy( &lp->wds_port[2].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); 753 memcpy(&lp->wds_port[2].wdsAddress, &pLtv->u.u8[0], ETH_ALEN);
754 hcfPort = HCF_PORT_3; 754 hcfPort = HCF_PORT_3;
755 break; 755 break;
756 case CFG_CNF_WDS_ADDR4: 756 case CFG_CNF_WDS_ADDR4:
757 memcpy( &lp->wds_port[3].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); 757 memcpy(&lp->wds_port[3].wdsAddress, &pLtv->u.u8[0], ETH_ALEN);
758 hcfPort = HCF_PORT_4; 758 hcfPort = HCF_PORT_4;
759 break; 759 break;
760 case CFG_CNF_WDS_ADDR5: 760 case CFG_CNF_WDS_ADDR5:
761 memcpy( &lp->wds_port[4].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); 761 memcpy(&lp->wds_port[4].wdsAddress, &pLtv->u.u8[0], ETH_ALEN);
762 hcfPort = HCF_PORT_5; 762 hcfPort = HCF_PORT_5;
763 break; 763 break;
764 case CFG_CNF_WDS_ADDR6: 764 case CFG_CNF_WDS_ADDR6:
765 memcpy( &lp->wds_port[5].wdsAddress, &pLtv->u.u8[0], ETH_ALEN ); 765 memcpy(&lp->wds_port[5].wdsAddress, &pLtv->u.u8[0], ETH_ALEN);
766 hcfPort = HCF_PORT_6; 766 hcfPort = HCF_PORT_6;
767 break; 767 break;
768#endif /* USE_WDS */ 768#endif /* USE_WDS */
769 769
770 case CFG_CNF_MCAST_PM_BUF: 770 case CFG_CNF_MCAST_PM_BUF:
771 lp->multicastPMBuffering = pLtv->u.u16[0]; 771 lp->multicastPMBuffering = pLtv->u.u16[0];
772 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 772 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
773 break; 773 break;
774 case CFG_CNF_REJECT_ANY: 774 case CFG_CNF_REJECT_ANY:
775 lp->RejectAny = pLtv->u.u16[0]; 775 lp->RejectAny = pLtv->u.u16[0];
776 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 776 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
777 break; 777 break;
778#endif 778#endif
779 779
780 case CFG_CNF_ENCRYPTION: 780 case CFG_CNF_ENCRYPTION:
781 lp->EnableEncryption = pLtv->u.u16[0]; 781 lp->EnableEncryption = pLtv->u.u16[0];
782 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 782 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
783 break; 783 break;
784 case CFG_CNF_AUTHENTICATION: 784 case CFG_CNF_AUTHENTICATION:
785 lp->authentication = pLtv->u.u16[0]; 785 lp->authentication = pLtv->u.u16[0];
786 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 786 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
787 break; 787 break;
788#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP 788#if 1 /* ;? (HCF_TYPE) & HCF_TYPE_AP */
789 //;?should we restore this to allow smaller memory footprint 789 /* ;?should we restore this to allow smaller memory footprint */
790 790
791 //case CFG_CNF_EXCL_UNENCRYPTED: 791 /* case CFG_CNF_EXCL_UNENCRYPTED:
792 //lp->ExcludeUnencrypted = pLtv->u.u16[0]; 792 lp->ExcludeUnencrypted = pLtv->u.u16[0];
793 //pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 793 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
794 //break; 794 break; */
795 case CFG_CNF_MCAST_RATE: 795 case CFG_CNF_MCAST_RATE:
796 /* TODO: determine if we are going to store anything based on this */ 796 /* TODO: determine if we are going to store anything based on this */
797 break; 797 break;
798 case CFG_CNF_INTRA_BSS_RELAY: 798 case CFG_CNF_INTRA_BSS_RELAY:
799 lp->intraBSSRelay = pLtv->u.u16[0]; 799 lp->intraBSSRelay = pLtv->u.u16[0];
800 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 800 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
801 break; 801 break;
802#endif 802#endif
803 803
804 case CFG_CNF_MICRO_WAVE: 804 case CFG_CNF_MICRO_WAVE:
805 /* TODO: determine if we are going to store anything based on this */ 805 /* TODO: determine if we are going to store anything based on this */
806 break; 806 break;
807 //case CFG_CNF_LOAD_BALANCING: 807 /*case CFG_CNF_LOAD_BALANCING:*/
808 /* TODO: determine if we are going to store anything based on this */ 808 /* TODO: determine if we are going to store anything based on this */
809 //break; 809 /* break; */
810 //case CFG_CNF_MEDIUM_DISTRIBUTION: 810 /* case CFG_CNF_MEDIUM_DISTRIBUTION: */
811 /* TODO: determine if we are going to store anything based on this */ 811 /* TODO: determine if we are going to store anything based on this */
812 //break; 812 /* break; */
813 //case CFG_CNF_RX_ALL_GROUP_ADDRESS: 813 /* case CFG_CNF_RX_ALL_GROUP_ADDRESS: */
814 // TODO: determine if we are going to store anything based on this 814 /* TODO: determine if we are going to store anything based on this */
815 //break; 815 /* break; */
816 //case CFG_CNF_COUNTRY_INFO: 816 /* case CFG_CNF_COUNTRY_INFO: */
817 /* TODO: determine if we are going to store anything based on this */ 817 /* TODO: determine if we are going to store anything based on this */
818 //break; 818 /* break; */
819 case CFG_CNF_OWN_SSID: 819 case CFG_CNF_OWN_SSID:
820 //case CNF_DESIRED_SSID: 820 /* case CNF_DESIRED_SSID: */
821 case CFG_DESIRED_SSID: 821 case CFG_DESIRED_SSID:
822 memset( lp->NetworkName, 0, sizeof( lp->NetworkName )); 822 memset(lp->NetworkName, 0, sizeof(lp->NetworkName));
823 memcpy( (void *)lp->NetworkName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0] ); 823 memcpy((void *)lp->NetworkName, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]);
824 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 824 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
825 825
826 /* take care of the special network name "ANY" case */ 826 /* take care of the special network name "ANY" case */
827 if(( strlen( &pLtv->u.u8[2] ) == 0 ) || 827 if ((strlen(&pLtv->u.u8[2]) == 0) ||
828 ( strcmp( &pLtv->u.u8[2], "ANY" ) == 0 ) || 828 (strcmp(&pLtv->u.u8[2], "ANY") == 0) ||
829 ( strcmp( &pLtv->u.u8[2], "any" ) == 0 )) { 829 (strcmp(&pLtv->u.u8[2], "any") == 0)) {
830 /* set the SSID_STRCT llen field (u16[0]) to zero, and the 830 /* set the SSID_STRCT llen field (u16[0]) to zero, and the
831 effectually null the string u8[2] */ 831 effectually null the string u8[2] */
832 pLtv->u.u16[0] = 0; 832 pLtv->u.u16[0] = 0;
@@ -838,93 +838,93 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
838 break; 838 break;
839 case CFG_CREATE_IBSS: 839 case CFG_CREATE_IBSS:
840 lp->CreateIBSS = pLtv->u.u16[0]; 840 lp->CreateIBSS = pLtv->u.u16[0];
841 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 841 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
842 break; 842 break;
843 case CFG_RTS_THRH: 843 case CFG_RTS_THRH:
844 lp->RTSThreshold = pLtv->u.u16[0]; 844 lp->RTSThreshold = pLtv->u.u16[0];
845 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 845 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
846 break; 846 break;
847 case CFG_TX_RATE_CNTL: 847 case CFG_TX_RATE_CNTL:
848 lp->TxRateControl[0] = pLtv->u.u16[0]; 848 lp->TxRateControl[0] = pLtv->u.u16[0];
849 lp->TxRateControl[1] = pLtv->u.u16[1]; 849 lp->TxRateControl[1] = pLtv->u.u16[1];
850 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 850 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
851 pLtv->u.u16[1] = CNV_INT_TO_LITTLE( pLtv->u.u16[1] ); 851 pLtv->u.u16[1] = CNV_INT_TO_LITTLE(pLtv->u.u16[1]);
852 break; 852 break;
853 case CFG_PROMISCUOUS_MODE: 853 case CFG_PROMISCUOUS_MODE:
854 /* TODO: determine if we are going to store anything based on this */ 854 /* TODO: determine if we are going to store anything based on this */
855 break; 855 break;
856 //case CFG_WAKE_ON_LAN: 856 /* case CFG_WAKE_ON_LAN: */
857 /* TODO: determine if we are going to store anything based on this */ 857 /* TODO: determine if we are going to store anything based on this */
858 //break; 858 /* break; */
859#if 1 //;? #if (HCF_TYPE) & HCF_TYPE_AP 859#if 1 /* ;? #if (HCF_TYPE) & HCF_TYPE_AP */
860 //;?should we restore this to allow smaller memory footprint 860 /* ;?should we restore this to allow smaller memory footprint */
861 case CFG_RTS_THRH0: 861 case CFG_RTS_THRH0:
862 lp->RTSThreshold = pLtv->u.u16[0]; 862 lp->RTSThreshold = pLtv->u.u16[0];
863 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 863 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
864 break; 864 break;
865 case CFG_TX_RATE_CNTL0: 865 case CFG_TX_RATE_CNTL0:
866//;?no idea what this should be, get going so comment it out lp->TxRateControl = pLtv->u.u16[0]; 866/*;?no idea what this should be, get going so comment it out lp->TxRateControl = pLtv->u.u16[0];*/
867 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 867 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
868 break; 868 break;
869#ifdef USE_WDS 869#ifdef USE_WDS
870 case CFG_RTS_THRH1: 870 case CFG_RTS_THRH1:
871 lp->wds_port[0].rtsThreshold = pLtv->u.u16[0]; 871 lp->wds_port[0].rtsThreshold = pLtv->u.u16[0];
872 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 872 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
873 hcfPort = HCF_PORT_1; 873 hcfPort = HCF_PORT_1;
874 break; 874 break;
875 case CFG_RTS_THRH2: 875 case CFG_RTS_THRH2:
876 lp->wds_port[1].rtsThreshold = pLtv->u.u16[0]; 876 lp->wds_port[1].rtsThreshold = pLtv->u.u16[0];
877 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 877 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
878 hcfPort = HCF_PORT_2; 878 hcfPort = HCF_PORT_2;
879 break; 879 break;
880 case CFG_RTS_THRH3: 880 case CFG_RTS_THRH3:
881 lp->wds_port[2].rtsThreshold = pLtv->u.u16[0]; 881 lp->wds_port[2].rtsThreshold = pLtv->u.u16[0];
882 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 882 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
883 hcfPort = HCF_PORT_3; 883 hcfPort = HCF_PORT_3;
884 break; 884 break;
885 case CFG_RTS_THRH4: 885 case CFG_RTS_THRH4:
886 lp->wds_port[3].rtsThreshold = pLtv->u.u16[0]; 886 lp->wds_port[3].rtsThreshold = pLtv->u.u16[0];
887 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 887 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
888 hcfPort = HCF_PORT_4; 888 hcfPort = HCF_PORT_4;
889 break; 889 break;
890 case CFG_RTS_THRH5: 890 case CFG_RTS_THRH5:
891 lp->wds_port[4].rtsThreshold = pLtv->u.u16[0]; 891 lp->wds_port[4].rtsThreshold = pLtv->u.u16[0];
892 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 892 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
893 hcfPort = HCF_PORT_5; 893 hcfPort = HCF_PORT_5;
894 break; 894 break;
895 case CFG_RTS_THRH6: 895 case CFG_RTS_THRH6:
896 lp->wds_port[5].rtsThreshold = pLtv->u.u16[0]; 896 lp->wds_port[5].rtsThreshold = pLtv->u.u16[0];
897 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 897 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
898 hcfPort = HCF_PORT_6; 898 hcfPort = HCF_PORT_6;
899 break; 899 break;
900 case CFG_TX_RATE_CNTL1: 900 case CFG_TX_RATE_CNTL1:
901 lp->wds_port[0].txRateCntl = pLtv->u.u16[0]; 901 lp->wds_port[0].txRateCntl = pLtv->u.u16[0];
902 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 902 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
903 hcfPort = HCF_PORT_1; 903 hcfPort = HCF_PORT_1;
904 break; 904 break;
905 case CFG_TX_RATE_CNTL2: 905 case CFG_TX_RATE_CNTL2:
906 lp->wds_port[1].txRateCntl = pLtv->u.u16[0]; 906 lp->wds_port[1].txRateCntl = pLtv->u.u16[0];
907 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 907 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
908 hcfPort = HCF_PORT_2; 908 hcfPort = HCF_PORT_2;
909 break; 909 break;
910 case CFG_TX_RATE_CNTL3: 910 case CFG_TX_RATE_CNTL3:
911 lp->wds_port[2].txRateCntl = pLtv->u.u16[0]; 911 lp->wds_port[2].txRateCntl = pLtv->u.u16[0];
912 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 912 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
913 hcfPort = HCF_PORT_3; 913 hcfPort = HCF_PORT_3;
914 break; 914 break;
915 case CFG_TX_RATE_CNTL4: 915 case CFG_TX_RATE_CNTL4:
916 lp->wds_port[3].txRateCntl = pLtv->u.u16[0]; 916 lp->wds_port[3].txRateCntl = pLtv->u.u16[0];
917 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 917 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
918 hcfPort = HCF_PORT_4; 918 hcfPort = HCF_PORT_4;
919 break; 919 break;
920 case CFG_TX_RATE_CNTL5: 920 case CFG_TX_RATE_CNTL5:
921 lp->wds_port[4].txRateCntl = pLtv->u.u16[0]; 921 lp->wds_port[4].txRateCntl = pLtv->u.u16[0];
922 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 922 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
923 hcfPort = HCF_PORT_5; 923 hcfPort = HCF_PORT_5;
924 break; 924 break;
925 case CFG_TX_RATE_CNTL6: 925 case CFG_TX_RATE_CNTL6:
926 lp->wds_port[5].txRateCntl = pLtv->u.u16[0]; 926 lp->wds_port[5].txRateCntl = pLtv->u.u16[0];
927 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 927 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
928 hcfPort = HCF_PORT_6; 928 hcfPort = HCF_PORT_6;
929 break; 929 break;
930#endif /* USE_WDS */ 930#endif /* USE_WDS */
@@ -934,18 +934,18 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
934 { 934 {
935 CFG_DEFAULT_KEYS_STRCT *pKeys = (CFG_DEFAULT_KEYS_STRCT *)pLtv; 935 CFG_DEFAULT_KEYS_STRCT *pKeys = (CFG_DEFAULT_KEYS_STRCT *)pLtv;
936 936
937 pKeys->key[0].len = CNV_INT_TO_LITTLE( pKeys->key[0].len ); 937 pKeys->key[0].len = CNV_INT_TO_LITTLE(pKeys->key[0].len);
938 pKeys->key[1].len = CNV_INT_TO_LITTLE( pKeys->key[1].len ); 938 pKeys->key[1].len = CNV_INT_TO_LITTLE(pKeys->key[1].len);
939 pKeys->key[2].len = CNV_INT_TO_LITTLE( pKeys->key[2].len ); 939 pKeys->key[2].len = CNV_INT_TO_LITTLE(pKeys->key[2].len);
940 pKeys->key[3].len = CNV_INT_TO_LITTLE( pKeys->key[3].len ); 940 pKeys->key[3].len = CNV_INT_TO_LITTLE(pKeys->key[3].len);
941 941
942 memcpy( (void *)&(lp->DefaultKeys), (void *)pKeys, 942 memcpy((void *)&(lp->DefaultKeys), (void *)pKeys,
943 sizeof( CFG_DEFAULT_KEYS_STRCT )); 943 sizeof(CFG_DEFAULT_KEYS_STRCT));
944 } 944 }
945 break; 945 break;
946 case CFG_TX_KEY_ID: 946 case CFG_TX_KEY_ID:
947 lp->TransmitKeyID = pLtv->u.u16[0]; 947 lp->TransmitKeyID = pLtv->u.u16[0];
948 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 948 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
949 break; 949 break;
950 case CFG_SCAN_SSID: 950 case CFG_SCAN_SSID:
951 /* TODO: determine if we are going to store anything based on this */ 951 /* TODO: determine if we are going to store anything based on this */
@@ -956,7 +956,7 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
956 /* these RIDS are Info RIDs, and should they be allowed for puts??? */ 956 /* these RIDS are Info RIDs, and should they be allowed for puts??? */
957 case CFG_MAX_LOAD_TIME: 957 case CFG_MAX_LOAD_TIME:
958 case CFG_DL_BUF: 958 case CFG_DL_BUF:
959 //case CFG_HSI_SUP_RANGE: 959 /* case CFG_HSI_SUP_RANGE: */
960 case CFG_NIC_SERIAL_NUMBER: 960 case CFG_NIC_SERIAL_NUMBER:
961 case CFG_NIC_IDENTITY: 961 case CFG_NIC_IDENTITY:
962 case CFG_NIC_MFI_SUP_RANGE: 962 case CFG_NIC_MFI_SUP_RANGE:
@@ -982,35 +982,35 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
982 case CFG_CF_POLLABLE: 982 case CFG_CF_POLLABLE:
983 case CFG_AUTHENTICATION_ALGORITHMS: 983 case CFG_AUTHENTICATION_ALGORITHMS:
984 case CFG_PRIVACY_OPT_IMPLEMENTED: 984 case CFG_PRIVACY_OPT_IMPLEMENTED:
985 //case CFG_CURRENT_REMOTE_RATES: 985 /* case CFG_CURRENT_REMOTE_RATES: */
986 //case CFG_CURRENT_USED_RATES: 986 /* case CFG_CURRENT_USED_RATES: */
987 //case CFG_CURRENT_SYSTEM_SCALE: 987 /* case CFG_CURRENT_SYSTEM_SCALE: */
988 //case CFG_CURRENT_TX_RATE1: 988 /* case CFG_CURRENT_TX_RATE1: */
989 //case CFG_CURRENT_TX_RATE2: 989 /* case CFG_CURRENT_TX_RATE2: */
990 //case CFG_CURRENT_TX_RATE3: 990 /* case CFG_CURRENT_TX_RATE3: */
991 //case CFG_CURRENT_TX_RATE4: 991 /* case CFG_CURRENT_TX_RATE4: */
992 //case CFG_CURRENT_TX_RATE5: 992 /* case CFG_CURRENT_TX_RATE5: */
993 //case CFG_CURRENT_TX_RATE6: 993 /* case CFG_CURRENT_TX_RATE6: */
994 case CFG_NIC_MAC_ADDR: 994 case CFG_NIC_MAC_ADDR:
995 case CFG_PCF_INFO: 995 case CFG_PCF_INFO:
996 //case CFG_CURRENT_COUNTRY_INFO: 996 /* case CFG_CURRENT_COUNTRY_INFO: */
997 case CFG_PHY_TYPE: 997 case CFG_PHY_TYPE:
998 case CFG_CUR_CHANNEL: 998 case CFG_CUR_CHANNEL:
999 //case CFG_CURRENT_POWER_STATE: 999 /* case CFG_CURRENT_POWER_STATE: */
1000 //case CFG_CCAMODE: 1000 /* case CFG_CCAMODE: */
1001 case CFG_SUPPORTED_DATA_RATES: 1001 case CFG_SUPPORTED_DATA_RATES:
1002 break; 1002 break;
1003 case CFG_AP_MODE: 1003 case CFG_AP_MODE:
1004//;? lp->DownloadFirmware = ( pLtv->u.u16[0] ) + 1; 1004/*;? lp->DownloadFirmware = (pLtv->u.u16[0]) + 1; */
1005 DBG_ERROR( DbgInfo, "set CFG_AP_MODE no longer supported\n" ); 1005 DBG_ERROR(DbgInfo, "set CFG_AP_MODE no longer supported\n");
1006 break; 1006 break;
1007 case CFG_ENCRYPT_STRING: 1007 case CFG_ENCRYPT_STRING:
1008 /* TODO: ENDIAN TRANSLATION HERE??? */ 1008 /* TODO: ENDIAN TRANSLATION HERE??? */
1009 memset( lp->szEncryption, 0, sizeof( lp->szEncryption )); 1009 memset(lp->szEncryption, 0, sizeof(lp->szEncryption));
1010 memcpy( (void *)lp->szEncryption, (void *)&pLtv->u.u8[0], 1010 memcpy((void *)lp->szEncryption, (void *)&pLtv->u.u8[0],
1011 ( pLtv->len * sizeof( hcf_16 )) ); 1011 (pLtv->len * sizeof(hcf_16)));
1012 wl_wep_decode( CRYPT_CODE, &sEncryption, 1012 wl_wep_decode(CRYPT_CODE, &sEncryption,
1013 lp->szEncryption ); 1013 lp->szEncryption);
1014 1014
1015 /* the Linux driver likes to use 1-4 for the key IDs, and then 1015 /* the Linux driver likes to use 1-4 for the key IDs, and then
1016 convert to 0-3 when sending to the card. The Windows code 1016 convert to 0-3 when sending to the card. The Windows code
@@ -1022,34 +1022,34 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
1022 lp->TransmitKeyID = sEncryption.wTxKeyID + 1; 1022 lp->TransmitKeyID = sEncryption.wTxKeyID + 1;
1023 lp->EnableEncryption = sEncryption.wEnabled; 1023 lp->EnableEncryption = sEncryption.wEnabled;
1024 1024
1025 memcpy( &lp->DefaultKeys, &sEncryption.EncStr, 1025 memcpy(&lp->DefaultKeys, &sEncryption.EncStr,
1026 sizeof( CFG_DEFAULT_KEYS_STRCT )); 1026 sizeof(CFG_DEFAULT_KEYS_STRCT));
1027 break; 1027 break;
1028 /*case CFG_COUNTRY_STRING: 1028 /*case CFG_COUNTRY_STRING:
1029 memset( lp->countryString, 0, sizeof( lp->countryString )); 1029 memset(lp->countryString, 0, sizeof(lp->countryString));
1030 memcpy( (void *)lp->countryString, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]); 1030 memcpy((void *)lp->countryString, (void *)&pLtv->u.u8[2], (size_t)pLtv->u.u16[0]);
1031 break; 1031 break;
1032 */ 1032 */
1033 1033
1034 case CFG_DRIVER_ENABLE: 1034 case CFG_DRIVER_ENABLE:
1035 lp->driverEnable = pLtv->u.u16[0]; 1035 lp->driverEnable = pLtv->u.u16[0];
1036 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 1036 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
1037 break; 1037 break;
1038 case CFG_WOLAS_ENABLE: 1038 case CFG_WOLAS_ENABLE:
1039 lp->wolasEnable = pLtv->u.u16[0]; 1039 lp->wolasEnable = pLtv->u.u16[0];
1040 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 1040 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
1041 break; 1041 break;
1042 case CFG_SET_WPA_AUTH_KEY_MGMT_SUITE: 1042 case CFG_SET_WPA_AUTH_KEY_MGMT_SUITE:
1043 lp->AuthKeyMgmtSuite = pLtv->u.u16[0]; 1043 lp->AuthKeyMgmtSuite = pLtv->u.u16[0];
1044 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 1044 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
1045 break; 1045 break;
1046 case CFG_DISASSOCIATE_ADDR: 1046 case CFG_DISASSOCIATE_ADDR:
1047 pLtv->u.u16[ETH_ALEN / 2] = CNV_INT_TO_LITTLE( pLtv->u.u16[ETH_ALEN / 2] ); 1047 pLtv->u.u16[ETH_ALEN / 2] = CNV_INT_TO_LITTLE(pLtv->u.u16[ETH_ALEN / 2]);
1048 break; 1048 break;
1049 case CFG_ADD_TKIP_DEFAULT_KEY: 1049 case CFG_ADD_TKIP_DEFAULT_KEY:
1050 case CFG_REMOVE_TKIP_DEFAULT_KEY: 1050 case CFG_REMOVE_TKIP_DEFAULT_KEY:
1051 /* Endian convert the Tx Key Information */ 1051 /* Endian convert the Tx Key Information */
1052 pLtv->u.u16[0] = CNV_INT_TO_LITTLE( pLtv->u.u16[0] ); 1052 pLtv->u.u16[0] = CNV_INT_TO_LITTLE(pLtv->u.u16[0]);
1053 break; 1053 break;
1054 case CFG_ADD_TKIP_MAPPED_KEY: 1054 case CFG_ADD_TKIP_MAPPED_KEY:
1055 break; 1055 break;
@@ -1066,7 +1066,7 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
1066 being sent to the card, as they require a call to 1066 being sent to the card, as they require a call to
1067 UIL_ACT_APPLY to take effect. Dynamic Entities will be sent 1067 UIL_ACT_APPLY to take effect. Dynamic Entities will be sent
1068 immediately */ 1068 immediately */
1069 switch( pLtv->typ ) { 1069 switch (pLtv->typ) {
1070 case CFG_CNF_PORT_TYPE: 1070 case CFG_CNF_PORT_TYPE:
1071 case CFG_CNF_OWN_MAC_ADDR: 1071 case CFG_CNF_OWN_MAC_ADDR:
1072 case CFG_CNF_OWN_CHANNEL: 1072 case CFG_CNF_OWN_CHANNEL:
@@ -1084,14 +1084,14 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
1084#ifdef WARP 1084#ifdef WARP
1085 case CFG_CNF_TX_POW_LVL: 1085 case CFG_CNF_TX_POW_LVL:
1086 case CFG_CNF_CONNECTION_CNTL: 1086 case CFG_CNF_CONNECTION_CNTL:
1087 //case CFG_PROBE_DATA_RATE: 1087 /*case CFG_PROBE_DATA_RATE: */
1088#endif // HERMES25 1088#endif /* HERMES25 */
1089#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP 1089#if 1 /*;? (HCF_TYPE) & HCF_TYPE_AP */
1090 //;?should we restore this to allow smaller memory footprint 1090 /*;?should we restore this to allow smaller memory footprint */
1091 case CFG_CNF_OWN_DTIM_PERIOD: 1091 case CFG_CNF_OWN_DTIM_PERIOD:
1092#ifdef WARP 1092#ifdef WARP
1093 case CFG_CNF_OWN_BEACON_INTERVAL: // Own Beacon Interval 1093 case CFG_CNF_OWN_BEACON_INTERVAL: /* Own Beacon Interval */
1094#endif // WARP 1094#endif /* WARP */
1095#ifdef USE_WDS 1095#ifdef USE_WDS
1096 case CFG_CNF_WDS_ADDR1: 1096 case CFG_CNF_WDS_ADDR1:
1097 case CFG_CNF_WDS_ADDR2: 1097 case CFG_CNF_WDS_ADDR2:
@@ -1106,8 +1106,8 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
1106 1106
1107 case CFG_CNF_ENCRYPTION: 1107 case CFG_CNF_ENCRYPTION:
1108 case CFG_CNF_AUTHENTICATION: 1108 case CFG_CNF_AUTHENTICATION:
1109#if 1 //;? (HCF_TYPE) & HCF_TYPE_AP 1109#if 1 /* ;? (HCF_TYPE) & HCF_TYPE_AP */
1110 //;?should we restore this to allow smaller memory footprint 1110 /* ;?should we restore this to allow smaller memory footprint */
1111 1111
1112 case CFG_CNF_EXCL_UNENCRYPTED: 1112 case CFG_CNF_EXCL_UNENCRYPTED:
1113 case CFG_CNF_MCAST_RATE: 1113 case CFG_CNF_MCAST_RATE:
@@ -1115,68 +1115,54 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
1115#endif 1115#endif
1116 1116
1117 case CFG_CNF_MICRO_WAVE: 1117 case CFG_CNF_MICRO_WAVE:
1118 //case CFG_CNF_LOAD_BALANCING: 1118 /* case CFG_CNF_LOAD_BALANCING: */
1119 //case CFG_CNF_MEDIUM_DISTRIBUTION: 1119 /* case CFG_CNF_MEDIUM_DISTRIBUTION: */
1120 //case CFG_CNF_RX_ALL_GROUP_ADDRESS: 1120 /* case CFG_CNF_RX_ALL_GROUP_ADDRESS: */
1121 //case CFG_CNF_COUNTRY_INFO: 1121 /* case CFG_CNF_COUNTRY_INFO: */
1122 //case CFG_COUNTRY_STRING: 1122 /* case CFG_COUNTRY_STRING: */
1123 case CFG_AP_MODE: 1123 case CFG_AP_MODE:
1124 case CFG_ENCRYPT_STRING: 1124 case CFG_ENCRYPT_STRING:
1125 //case CFG_DRIVER_ENABLE: 1125 /* case CFG_DRIVER_ENABLE: */
1126 case CFG_WOLAS_ENABLE: 1126 case CFG_WOLAS_ENABLE:
1127 case CFG_MB_INFO: 1127 case CFG_MB_INFO:
1128 case CFG_IFB: 1128 case CFG_IFB:
1129 break; 1129 break;
1130 /* Deal with this dynamic MSF RID, as it's required for WPA */ 1130 /* Deal with this dynamic MSF RID, as it's required for WPA */
1131 case CFG_DRIVER_ENABLE: 1131 case CFG_DRIVER_ENABLE:
1132 if( lp->driverEnable ) { 1132 if (lp->driverEnable) {
1133 //hcf_cntl_port( &( lp->hcfCtx ), 1133 hcf_cntl(&(lp->hcfCtx), HCF_CNTL_ENABLE | HCF_PORT_0);
1134 // HCF_PORT_ENABLE | HCF_PORT_0 ); 1134 hcf_cntl(&(lp->hcfCtx), HCF_CNTL_CONNECT);
1135 // //hcf_cntl( &( lp->hcfCtx ),
1136 // // HCF_PORT_ENABLE | HCF_PORT_0 );
1137 //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_ENABLE );
1138 // //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_CONNECT );
1139
1140 hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_ENABLE | HCF_PORT_0 );
1141 hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_CONNECT );
1142 } else { 1135 } else {
1143 //hcf_cntl_port( &( lp->hcfCtx ), 1136 hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISABLE | HCF_PORT_0);
1144 // HCF_PORT_DISABLE | HCF_PORT_0 ); 1137 hcf_cntl(&(lp->hcfCtx), HCF_CNTL_DISCONNECT);
1145 // //hcf_cntl( &( lp->hcfCtx ),
1146 // // HCF_PORT_DISABLE | HCF_PORT_0 );
1147 //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISABLE );
1148 // //hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISCONNECT );
1149
1150 hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISABLE | HCF_PORT_0 );
1151 hcf_cntl( &( lp->hcfCtx ), HCF_CNTL_DISCONNECT );
1152 } 1138 }
1153 break; 1139 break;
1154 default: 1140 default:
1155 wl_act_int_off( lp ); 1141 wl_act_int_off(lp);
1156 urq->result = hcf_put_info(&(lp->hcfCtx), (LTVP) pLtv); 1142 urq->result = hcf_put_info(&(lp->hcfCtx), (LTVP) pLtv);
1157 wl_act_int_on( lp ); 1143 wl_act_int_on(lp);
1158 break; 1144 break;
1159 } 1145 }
1160 1146
1161 if( ltvAllocated ) { 1147 if (ltvAllocated)
1162 kfree( pLtv ); 1148 kfree(pLtv);
1163 }
1164 } else { 1149 } else {
1165 urq->result = UIL_FAILURE; 1150 urq->result = UIL_FAILURE;
1166 } 1151 }
1167 } else { 1152 } else {
1168 DBG_ERROR( DbgInfo, "EPERM\n" ); 1153 DBG_ERROR(DbgInfo, "EPERM\n");
1169 urq->result = UIL_FAILURE; 1154 urq->result = UIL_FAILURE;
1170 result = -EPERM; 1155 result = -EPERM;
1171 } 1156 }
1172 } else { 1157 } else {
1173 DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); 1158 DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n");
1174 urq->result = UIL_ERR_WRONG_IFB; 1159 urq->result = UIL_ERR_WRONG_IFB;
1175 } 1160 }
1176 1161
1177 DBG_LEAVE( DbgInfo ); 1162 DBG_LEAVE(DbgInfo);
1178 return result; 1163 return result;
1179} // wvlan_uil_put_info 1164} /* wvlan_uil_put_info */
1165
1180/*============================================================================*/ 1166/*============================================================================*/
1181 1167
1182/******************************************************************************* 1168/*******************************************************************************
@@ -1199,97 +1185,97 @@ int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp )
1199 * UIL_ERR_xxx value otherwise 1185 * UIL_ERR_xxx value otherwise
1200 * 1186 *
1201 ******************************************************************************/ 1187 ******************************************************************************/
1202int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ) 1188int wvlan_uil_get_info(struct uilreq *urq, struct wl_private *lp)
1203{ 1189{
1204 int result = 0; 1190 int result = 0;
1205 int i; 1191 int i;
1206 /*------------------------------------------------------------------------*/ 1192 /*------------------------------------------------------------------------*/
1207 1193
1208 DBG_FUNC( "wvlan_uil_get_info" ); 1194 DBG_FUNC("wvlan_uil_get_info");
1209 DBG_ENTER( DbgInfo ); 1195 DBG_ENTER(DbgInfo);
1210 1196
1211 if( urq->hcfCtx == &( lp->hcfCtx )) { 1197 if (urq->hcfCtx == &(lp->hcfCtx)) {
1212 if(( urq->data != NULL ) && ( urq->len != 0 )) { 1198 if ((urq->data != NULL) && (urq->len != 0)) {
1213 ltv_t *pLtv; 1199 ltv_t *pLtv;
1214 bool_t ltvAllocated = FALSE; 1200 bool_t ltvAllocated = FALSE;
1215 1201
1216 /* Make sure that we have at least a command and length */ 1202 /* Make sure that we have at least a command and length */
1217 if( urq->len < ( sizeof( hcf_16 ) * 2 )) { 1203 if (urq->len < (sizeof(hcf_16) * 2)) {
1218 urq->len = sizeof( lp->ltvRecord ); 1204 urq->len = sizeof(lp->ltvRecord);
1219 DBG_ERROR( DbgInfo, "No Length/Type in LTV!!!\n" ); 1205 DBG_ERROR(DbgInfo, "No Length/Type in LTV!!!\n");
1220 DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); 1206 DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n");
1221 urq->result = UIL_ERR_LEN; 1207 urq->result = UIL_ERR_LEN;
1222 DBG_LEAVE( DbgInfo ); 1208 DBG_LEAVE(DbgInfo);
1223 return result; 1209 return result;
1224 } 1210 }
1225 1211
1226 /* Verify the user's LTV record header. */ 1212 /* Verify the user's LTV record header. */
1227 result = verify_area( VERIFY_READ, urq->data, sizeof( hcf_16 ) * 2 ); 1213 result = verify_area(VERIFY_READ, urq->data, sizeof(hcf_16) * 2);
1228 if( result != 0 ) { 1214 if (result != 0) {
1229 DBG_ERROR( DbgInfo, "verify_area(), VERIFY_READ FAILED\n" ); 1215 DBG_ERROR(DbgInfo, "verify_area(), VERIFY_READ FAILED\n");
1230 urq->result = UIL_FAILURE; 1216 urq->result = UIL_FAILURE;
1231 DBG_LEAVE( DbgInfo ); 1217 DBG_LEAVE(DbgInfo);
1232 return result; 1218 return result;
1233 } 1219 }
1234 1220
1235 /* Get only the command and length information. */ 1221 /* Get only the command and length information. */
1236 result = copy_from_user( &( lp->ltvRecord ), urq->data, sizeof( hcf_16 ) * 2 ); 1222 result = copy_from_user(&(lp->ltvRecord), urq->data, sizeof(hcf_16) * 2);
1237 1223
1238 /* Make sure the incoming LTV record length is within the bounds of 1224 /* Make sure the incoming LTV record length is within the bounds of
1239 the IOCTL length. */ 1225 the IOCTL length. */
1240 if((( lp->ltvRecord.len + 1 ) * sizeof( hcf_16 )) > urq->len ) { 1226 if (((lp->ltvRecord.len + 1) * sizeof(hcf_16)) > urq->len) {
1241 DBG_ERROR( DbgInfo, "Incoming LTV too big\n" ); 1227 DBG_ERROR(DbgInfo, "Incoming LTV too big\n");
1242 urq->len = sizeof( lp->ltvRecord ); 1228 urq->len = sizeof(lp->ltvRecord);
1243 urq->result = UIL_ERR_LEN; 1229 urq->result = UIL_ERR_LEN;
1244 DBG_LEAVE( DbgInfo ); 1230 DBG_LEAVE(DbgInfo);
1245 return result; 1231 return result;
1246 } 1232 }
1247 1233
1248 /* Determine if hcf_get_info() is needed or not */ 1234 /* Determine if hcf_get_info() is needed or not */
1249 switch ( lp->ltvRecord.typ ) { 1235 switch (lp->ltvRecord.typ) {
1250 case CFG_NIC_IDENTITY: 1236 case CFG_NIC_IDENTITY:
1251 memcpy( &lp->ltvRecord.u.u8[0], &lp->NICIdentity, sizeof( lp->NICIdentity )); 1237 memcpy(&lp->ltvRecord.u.u8[0], &lp->NICIdentity, sizeof(lp->NICIdentity));
1252 break; 1238 break;
1253 case CFG_PRI_IDENTITY: 1239 case CFG_PRI_IDENTITY:
1254 memcpy( &lp->ltvRecord.u.u8[0], &lp->PrimaryIdentity, sizeof( lp->PrimaryIdentity )); 1240 memcpy(&lp->ltvRecord.u.u8[0], &lp->PrimaryIdentity, sizeof(lp->PrimaryIdentity));
1255 break; 1241 break;
1256 case CFG_AP_MODE: 1242 case CFG_AP_MODE:
1257 DBG_ERROR( DbgInfo, "set CFG_AP_MODE no longer supported, so is get useful ????\n" ); 1243 DBG_ERROR(DbgInfo, "set CFG_AP_MODE no longer supported, so is get useful ????\n");
1258 lp->ltvRecord.u.u16[0] = 1244 lp->ltvRecord.u.u16[0] =
1259 CNV_INT_TO_LITTLE( lp->hcfCtx.IFB_FWIdentity.comp_id ) == COMP_ID_FW_AP; 1245 CNV_INT_TO_LITTLE(lp->hcfCtx.IFB_FWIdentity.comp_id) == COMP_ID_FW_AP;
1260 break; 1246 break;
1261 //case CFG_DRV_INFO: 1247 /* case CFG_DRV_INFO: */
1262 case CFG_ENCRYPT_STRING: 1248 case CFG_ENCRYPT_STRING:
1263 case CFG_COUNTRY_STRING: 1249 case CFG_COUNTRY_STRING:
1264 case CFG_DRIVER_ENABLE: 1250 case CFG_DRIVER_ENABLE:
1265 case CFG_WOLAS_ENABLE: 1251 case CFG_WOLAS_ENABLE:
1266 // TODO: determine if we're going to support these 1252 /* TODO: determine if we're going to support these */
1267 urq->result = UIL_FAILURE; 1253 urq->result = UIL_FAILURE;
1268 break; 1254 break;
1269 case CFG_DRV_INFO: 1255 case CFG_DRV_INFO:
1270 DBG_TRACE( DbgInfo, "Intercept CFG_DRV_INFO\n" ); 1256 DBG_TRACE(DbgInfo, "Intercept CFG_DRV_INFO\n");
1271 result = cfg_driver_info( urq, lp ); 1257 result = cfg_driver_info(urq, lp);
1272 break; 1258 break;
1273 case CFG_DRV_IDENTITY: 1259 case CFG_DRV_IDENTITY:
1274 DBG_TRACE( DbgInfo, "Intercept CFG_DRV_IDENTITY\n" ); 1260 DBG_TRACE(DbgInfo, "Intercept CFG_DRV_IDENTITY\n");
1275 result = cfg_driver_identity( urq, lp ); 1261 result = cfg_driver_identity(urq, lp);
1276 break; 1262 break;
1277 case CFG_IFB: 1263 case CFG_IFB:
1278 /* IFB can be a security hole */ 1264 /* IFB can be a security hole */
1279 if( !capable( CAP_NET_ADMIN )) { 1265 if (!capable(CAP_NET_ADMIN)) {
1280 result = -EPERM; 1266 result = -EPERM;
1281 break; 1267 break;
1282 } 1268 }
1283 1269
1284 /* Else fall through to the default */ 1270 /* Else fall through to the default */
1285 1271
1286 case CFG_FW_IDENTITY: // For Hermes-1, this is cached 1272 case CFG_FW_IDENTITY: /* For Hermes-1, this is cached */
1287 default: 1273 default:
1288 1274
1289 /* Verify the user buffer */ 1275 /* Verify the user buffer */
1290 result = verify_area( VERIFY_WRITE, urq->data, urq->len ); 1276 result = verify_area(VERIFY_WRITE, urq->data, urq->len);
1291 if( result != 0 ) { 1277 if (result != 0) {
1292 DBG_ERROR( DbgInfo, "verify_area(), VERIFY_WRITE FAILED\n" ); 1278 DBG_ERROR(DbgInfo, "verify_area(), VERIFY_WRITE FAILED\n");
1293 urq->result = UIL_FAILURE; 1279 urq->result = UIL_FAILURE;
1294 break; 1280 break;
1295 } 1281 }
@@ -1297,43 +1283,43 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp )
1297 /* If the requested length is greater than the size of our local 1283 /* If the requested length is greater than the size of our local
1298 LTV record, try to allocate it from the kernel stack. 1284 LTV record, try to allocate it from the kernel stack.
1299 Otherwise, we just use our local LTV record. */ 1285 Otherwise, we just use our local LTV record. */
1300 if( urq->len > sizeof( lp->ltvRecord )) { 1286 if (urq->len > sizeof(lp->ltvRecord)) {
1301 pLtv = kmalloc(urq->len, GFP_KERNEL); 1287 pLtv = kmalloc(urq->len, GFP_KERNEL);
1302 if (pLtv != NULL) { 1288 if (pLtv != NULL) {
1303 ltvAllocated = TRUE; 1289 ltvAllocated = TRUE;
1304 1290
1305 /* Copy the command/length information into the new buffer. */ 1291 /* Copy the command/length information into the new buffer. */
1306 memcpy( pLtv, &( lp->ltvRecord ), sizeof( hcf_16 ) * 2 ); 1292 memcpy(pLtv, &(lp->ltvRecord), sizeof(hcf_16) * 2);
1307 } else { 1293 } else {
1308 urq->len = sizeof( lp->ltvRecord ); 1294 urq->len = sizeof(lp->ltvRecord);
1309 urq->result = UIL_ERR_LEN; 1295 urq->result = UIL_ERR_LEN;
1310 DBG_ERROR( DbgInfo, "kmalloc FAILED\n" ); 1296 DBG_ERROR(DbgInfo, "kmalloc FAILED\n");
1311 DBG_ERROR( DbgInfo, "UIL_ERR_LEN\n" ); 1297 DBG_ERROR(DbgInfo, "UIL_ERR_LEN\n");
1312 result = -ENOMEM; 1298 result = -ENOMEM;
1313 break; 1299 break;
1314 } 1300 }
1315 } else { 1301 } else {
1316 pLtv = &( lp->ltvRecord ); 1302 pLtv = &(lp->ltvRecord);
1317 } 1303 }
1318 1304
1319 wl_act_int_off( lp ); 1305 wl_act_int_off(lp);
1320 urq->result = hcf_get_info( &( lp->hcfCtx ), (LTVP) pLtv ); 1306 urq->result = hcf_get_info(&(lp->hcfCtx), (LTVP) pLtv);
1321 wl_act_int_on( lp ); 1307 wl_act_int_on(lp);
1322 1308
1323 // Copy the LTV into the user's buffer. 1309 /* Copy the LTV into the user's buffer. */
1324 //copy_to_user( urq->data, pLtv, urq->len ); 1310 /*copy_to_user(urq->data, pLtv, urq->len); */
1325 1311
1326 //if( ltvAllocated ) 1312 /*if(ltvAllocated)
1327 //{ 1313 {
1328 // kfree( pLtv ); 1314 kfree(pLtv);
1329 //} 1315 }*/
1330 1316
1331 //urq->result = UIL_SUCCESS; 1317 /* urq->result = UIL_SUCCESS; */
1332 break; 1318 break;
1333 } 1319 }
1334 1320
1335 /* Handle endian conversion of special fields */ 1321 /* Handle endian conversion of special fields */
1336 switch( lp->ltvRecord.typ ) { 1322 switch (lp->ltvRecord.typ) {
1337 /* simple int gets just need the first hcf_16 byte flipped */ 1323 /* simple int gets just need the first hcf_16 byte flipped */
1338 case CFG_CNF_PORT_TYPE: 1324 case CFG_CNF_PORT_TYPE:
1339 case CFG_CNF_OWN_CHANNEL: 1325 case CFG_CNF_OWN_CHANNEL:
@@ -1357,14 +1343,14 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp )
1357#ifdef WARP 1343#ifdef WARP
1358 case CFG_CNF_TX_POW_LVL: 1344 case CFG_CNF_TX_POW_LVL:
1359 case CFG_CNF_CONNECTION_CNTL: 1345 case CFG_CNF_CONNECTION_CNTL:
1360 case CFG_CNF_OWN_BEACON_INTERVAL: // Own Beacon Interval 1346 case CFG_CNF_OWN_BEACON_INTERVAL: /* Own Beacon Interval */
1361 case CFG_COEXISTENSE_BEHAVIOUR: // Coexistence Behavior 1347 case CFG_COEXISTENSE_BEHAVIOUR: /* Coexistence Behavior */
1362 //case CFG_CNF_RX_ALL_GROUP_ADDRESS: 1348 /*case CFG_CNF_RX_ALL_GROUP_ADDRESS: */
1363#endif // HERMES25 1349#endif /* HERMES25 */
1364 case CFG_CREATE_IBSS: 1350 case CFG_CREATE_IBSS:
1365 case CFG_RTS_THRH: 1351 case CFG_RTS_THRH:
1366 case CFG_PROMISCUOUS_MODE: 1352 case CFG_PROMISCUOUS_MODE:
1367 //case CFG_WAKE_ON_LAN: 1353 /*case CFG_WAKE_ON_LAN: */
1368 case CFG_RTS_THRH0: 1354 case CFG_RTS_THRH0:
1369 case CFG_RTS_THRH1: 1355 case CFG_RTS_THRH1:
1370 case CFG_RTS_THRH2: 1356 case CFG_RTS_THRH2:
@@ -1393,29 +1379,29 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp )
1393 case CFG_MAX_RX_LIFETIME: 1379 case CFG_MAX_RX_LIFETIME:
1394 case CFG_CF_POLLABLE: 1380 case CFG_CF_POLLABLE:
1395 case CFG_PRIVACY_OPT_IMPLEMENTED: 1381 case CFG_PRIVACY_OPT_IMPLEMENTED:
1396 //case CFG_CURRENT_REMOTE_RATES: 1382 /* case CFG_CURRENT_REMOTE_RATES: */
1397 //case CFG_CURRENT_USED_RATES: 1383 /* case CFG_CURRENT_USED_RATES: */
1398 //case CFG_CURRENT_SYSTEM_SCALE: 1384 /* case CFG_CURRENT_SYSTEM_SCALE: */
1399 //case CFG_CURRENT_TX_RATE1: 1385 /* case CFG_CURRENT_TX_RATE1: */
1400 //case CFG_CURRENT_TX_RATE2: 1386 /* case CFG_CURRENT_TX_RATE2: */
1401 //case CFG_CURRENT_TX_RATE3: 1387 /* case CFG_CURRENT_TX_RATE3: */
1402 //case CFG_CURRENT_TX_RATE4: 1388 /* case CFG_CURRENT_TX_RATE4: */
1403 //case CFG_CURRENT_TX_RATE5: 1389 /* case CFG_CURRENT_TX_RATE5: */
1404 //case CFG_CURRENT_TX_RATE6: 1390 /* case CFG_CURRENT_TX_RATE6: */
1405 case CFG_PHY_TYPE: 1391 case CFG_PHY_TYPE:
1406 case CFG_CUR_CHANNEL: 1392 case CFG_CUR_CHANNEL:
1407 //case CFG_CURRENT_POWER_STATE: 1393 /* case CFG_CURRENT_POWER_STATE: */
1408 //case CFG_CCAMODE: 1394 /* case CFG_CCAMODE: */
1409 // lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); 1395 /* lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]); */
1410 // break; 1396 /* break; */
1411 /* name string gets just need the first hcf_16 byte flipped (length of string) */ 1397 /* name string gets just need the first hcf_16 byte flipped (length of string) */
1412 case CFG_CNF_OWN_SSID: 1398 case CFG_CNF_OWN_SSID:
1413 case CFG_CNF_OWN_NAME: 1399 case CFG_CNF_OWN_NAME:
1414 //case CNF_DESIRED_SSID: 1400 /* case CNF_DESIRED_SSID: */
1415 case CFG_DESIRED_SSID: 1401 case CFG_DESIRED_SSID:
1416 case CFG_SCAN_SSID: 1402 case CFG_SCAN_SSID:
1417 case CFG_CUR_SSID: 1403 case CFG_CUR_SSID:
1418 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); 1404 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]);
1419 break; 1405 break;
1420 /* non-length counted strings need no byte flipping */ 1406 /* non-length counted strings need no byte flipping */
1421 case CFG_CNF_OWN_MAC_ADDR: 1407 case CFG_CNF_OWN_MAC_ADDR:
@@ -1432,14 +1418,14 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp )
1432 case CFG_NIC_MAC_ADDR: 1418 case CFG_NIC_MAC_ADDR:
1433 case CFG_SUPPORTED_DATA_RATES: /* need to ensure we can treat this as a string */ 1419 case CFG_SUPPORTED_DATA_RATES: /* need to ensure we can treat this as a string */
1434 break; 1420 break;
1435 //case CFG_CNF_COUNTRY_INFO: /* special case, see page 75 of 022486, Rev C. */ 1421 /* case CFG_CNF_COUNTRY_INFO: */ /* special case, see page 75 of 022486, Rev C. */
1436 //case CFG_CURRENT_COUNTRY_INFO: /* special case, see page 101 of 022486, Rev C. */ 1422 /* case CFG_CURRENT_COUNTRY_INFO: */ /* special case, see page 101 of 022486, Rev C. */
1437 /* 1423 /*
1438 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); 1424 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]);
1439 lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[3] ); 1425 lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]);
1440 1426
1441 for( i = 4; i < lp->ltvRecord.len; i++ ) { 1427 for(i = 4; i < lp->ltvRecord.len; i++) {
1442 lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[i] ); 1428 lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[i]);
1443 } 1429 }
1444 break; 1430 break;
1445 */ 1431 */
@@ -1448,57 +1434,56 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp )
1448 { 1434 {
1449 CFG_DEFAULT_KEYS_STRCT *pKeys = (CFG_DEFAULT_KEYS_STRCT *)&lp->ltvRecord.u.u8[0]; 1435 CFG_DEFAULT_KEYS_STRCT *pKeys = (CFG_DEFAULT_KEYS_STRCT *)&lp->ltvRecord.u.u8[0];
1450 1436
1451 pKeys[0].len = CNV_INT_TO_LITTLE( pKeys[0].len ); 1437 pKeys[0].len = CNV_INT_TO_LITTLE(pKeys[0].len);
1452 pKeys[1].len = CNV_INT_TO_LITTLE( pKeys[1].len ); 1438 pKeys[1].len = CNV_INT_TO_LITTLE(pKeys[1].len);
1453 pKeys[2].len = CNV_INT_TO_LITTLE( pKeys[2].len ); 1439 pKeys[2].len = CNV_INT_TO_LITTLE(pKeys[2].len);
1454 pKeys[3].len = CNV_INT_TO_LITTLE( pKeys[3].len ); 1440 pKeys[3].len = CNV_INT_TO_LITTLE(pKeys[3].len);
1455 } 1441 }
1456 break; 1442 break;
1457 case CFG_CNF_MCAST_RATE: 1443 case CFG_CNF_MCAST_RATE:
1458 case CFG_TX_RATE_CNTL: 1444 case CFG_TX_RATE_CNTL:
1459 case CFG_SUPPORTED_RATE_SET_CNTL: // Supported Rate Set Control 1445 case CFG_SUPPORTED_RATE_SET_CNTL: /* Supported Rate Set Control */
1460 case CFG_BASIC_RATE_SET_CNTL: // Basic Rate Set Control 1446 case CFG_BASIC_RATE_SET_CNTL: /* Basic Rate Set Control */
1461 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); 1447 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]);
1462 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); 1448 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]);
1463 break; 1449 break;
1464 case CFG_DL_BUF: 1450 case CFG_DL_BUF:
1465 case CFG_NIC_IDENTITY: 1451 case CFG_NIC_IDENTITY:
1466 case CFG_COMMS_QUALITY: 1452 case CFG_COMMS_QUALITY:
1467 case CFG_PCF_INFO: 1453 case CFG_PCF_INFO:
1468 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); 1454 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]);
1469 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); 1455 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]);
1470 lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[2] ); 1456 lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[2]);
1471 break; 1457 break;
1472 case CFG_FW_IDENTITY: 1458 case CFG_FW_IDENTITY:
1473 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); 1459 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]);
1474 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); 1460 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]);
1475 lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[2] ); 1461 lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[2]);
1476 lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[3] ); 1462 lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]);
1477 break; 1463 break;
1478 //case CFG_HSI_SUP_RANGE: 1464 /* case CFG_HSI_SUP_RANGE: */
1479 case CFG_NIC_MFI_SUP_RANGE: 1465 case CFG_NIC_MFI_SUP_RANGE:
1480 case CFG_NIC_CFI_SUP_RANGE: 1466 case CFG_NIC_CFI_SUP_RANGE:
1481 case CFG_NIC_PROFILE: 1467 case CFG_NIC_PROFILE:
1482 case CFG_FW_SUP_RANGE: 1468 case CFG_FW_SUP_RANGE:
1483 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[0] ); 1469 lp->ltvRecord.u.u16[0] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[0]);
1484 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[1] ); 1470 lp->ltvRecord.u.u16[1] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[1]);
1485 lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[2] ); 1471 lp->ltvRecord.u.u16[2] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[2]);
1486 lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[3] ); 1472 lp->ltvRecord.u.u16[3] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[3]);
1487 lp->ltvRecord.u.u16[4] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[4] ); 1473 lp->ltvRecord.u.u16[4] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[4]);
1488 break; 1474 break;
1489 case CFG_MFI_ACT_RANGES_STA: 1475 case CFG_MFI_ACT_RANGES_STA:
1490 case CFG_CFI_ACT_RANGES_STA: 1476 case CFG_CFI_ACT_RANGES_STA:
1491 case CFG_CUR_SCALE_THRH: 1477 case CFG_CUR_SCALE_THRH:
1492 case CFG_AUTHENTICATION_ALGORITHMS: 1478 case CFG_AUTHENTICATION_ALGORITHMS:
1493 for( i = 0; i < ( lp->ltvRecord.len - 1 ); i++ ) { 1479 for (i = 0; i < (lp->ltvRecord.len - 1); i++)
1494 lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE( lp->ltvRecord.u.u16[i] ); 1480 lp->ltvRecord.u.u16[i] = CNV_INT_TO_LITTLE(lp->ltvRecord.u.u16[i]);
1495 }
1496 break; 1481 break;
1497 /* done at init time, and endian handled then */ 1482 /* done at init time, and endian handled then */
1498 case CFG_PRI_IDENTITY: 1483 case CFG_PRI_IDENTITY:
1499 break; 1484 break;
1500 case CFG_MB_INFO: 1485 case CFG_MB_INFO:
1501 //wvlanEndianTranslateMailbox( pLtv ); 1486 /* wvlanEndianTranslateMailbox(pLtv); */
1502 break; 1487 break;
1503 /* MSF and HCF RIDS */ 1488 /* MSF and HCF RIDS */
1504 case CFG_IFB: 1489 case CFG_IFB:
@@ -1512,25 +1497,23 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp )
1512 break; 1497 break;
1513 } 1498 }
1514 1499
1515 // Copy the LTV into the user's buffer. 1500 /* Copy the LTV into the user's buffer. */
1516 copy_to_user( urq->data, &( lp->ltvRecord ), urq->len ); 1501 copy_to_user(urq->data, &(lp->ltvRecord), urq->len);
1517
1518 if( ltvAllocated ) {
1519 kfree( &( lp->ltvRecord ));
1520 }
1521 1502
1503 if (ltvAllocated)
1504 kfree(&(lp->ltvRecord));
1522 urq->result = UIL_SUCCESS; 1505 urq->result = UIL_SUCCESS;
1523 } else { 1506 } else {
1524 urq->result = UIL_FAILURE; 1507 urq->result = UIL_FAILURE;
1525 } 1508 }
1526 } else { 1509 } else {
1527 DBG_ERROR( DbgInfo, "UIL_ERR_WRONG_IFB\n" ); 1510 DBG_ERROR(DbgInfo, "UIL_ERR_WRONG_IFB\n");
1528 urq->result = UIL_ERR_WRONG_IFB; 1511 urq->result = UIL_ERR_WRONG_IFB;
1529 } 1512 }
1530 1513
1531 DBG_LEAVE( DbgInfo ); 1514 DBG_LEAVE(DbgInfo);
1532 return result; 1515 return result;
1533} // wvlan_uil_get_info 1516} /* wvlan_uil_get_info */
1534/*============================================================================*/ 1517/*============================================================================*/
1535 1518
1536 1519
@@ -1556,41 +1539,41 @@ int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp )
1556 * UIL_ERR_xxx value otherwise 1539 * UIL_ERR_xxx value otherwise
1557 * 1540 *
1558 ******************************************************************************/ 1541 ******************************************************************************/
1559int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ) 1542int cfg_driver_info(struct uilreq *urq, struct wl_private *lp)
1560{ 1543{
1561 int result = 0; 1544 int result = 0;
1562 /*------------------------------------------------------------------------*/ 1545 /*------------------------------------------------------------------------*/
1563 1546
1564 1547
1565 DBG_FUNC( "cfg_driver_info" ); 1548 DBG_FUNC("cfg_driver_info");
1566 DBG_ENTER( DbgInfo ); 1549 DBG_ENTER(DbgInfo);
1567 1550
1568 1551
1569 /* Make sure that user buffer can handle the driver information buffer */ 1552 /* Make sure that user buffer can handle the driver information buffer */
1570 if( urq->len < sizeof( lp->driverInfo )) { 1553 if (urq->len < sizeof(lp->driverInfo)) {
1571 urq->len = sizeof( lp->driverInfo ); 1554 urq->len = sizeof(lp->driverInfo);
1572 urq->result = UIL_ERR_LEN; 1555 urq->result = UIL_ERR_LEN;
1573 DBG_LEAVE( DbgInfo ); 1556 DBG_LEAVE(DbgInfo);
1574 return result; 1557 return result;
1575 } 1558 }
1576 1559
1577 /* Verify the user buffer. */ 1560 /* Verify the user buffer. */
1578 result = verify_area( VERIFY_WRITE, urq->data, sizeof( lp->driverInfo )); 1561 result = verify_area(VERIFY_WRITE, urq->data, sizeof(lp->driverInfo));
1579 if( result != 0 ) { 1562 if (result != 0) {
1580 urq->result = UIL_FAILURE; 1563 urq->result = UIL_FAILURE;
1581 DBG_LEAVE( DbgInfo ); 1564 DBG_LEAVE(DbgInfo);
1582 return result; 1565 return result;
1583 } 1566 }
1584 1567
1585 lp->driverInfo.card_stat = lp->hcfCtx.IFB_CardStat; 1568 lp->driverInfo.card_stat = lp->hcfCtx.IFB_CardStat;
1586 1569
1587 // Copy the driver information into the user's buffer. 1570 /* Copy the driver information into the user's buffer. */
1588 urq->result = UIL_SUCCESS; 1571 urq->result = UIL_SUCCESS;
1589 copy_to_user( urq->data, &( lp->driverInfo ), sizeof( lp->driverInfo )); 1572 copy_to_user(urq->data, &(lp->driverInfo), sizeof(lp->driverInfo));
1590 1573
1591 DBG_LEAVE( DbgInfo ); 1574 DBG_LEAVE(DbgInfo);
1592 return result; 1575 return result;
1593} // cfg_driver_info 1576} /* cfg_driver_info */
1594/*============================================================================*/ 1577/*============================================================================*/
1595 1578
1596 1579
@@ -1615,39 +1598,39 @@ int cfg_driver_info( struct uilreq *urq, struct wl_private *lp )
1615 * UIL_ERR_xxx value otherwise 1598 * UIL_ERR_xxx value otherwise
1616 * 1599 *
1617 ******************************************************************************/ 1600 ******************************************************************************/
1618int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ) 1601int cfg_driver_identity(struct uilreq *urq, struct wl_private *lp)
1619{ 1602{
1620 int result = 0; 1603 int result = 0;
1621 /*------------------------------------------------------------------------*/ 1604 /*------------------------------------------------------------------------*/
1622 1605
1623 1606
1624 DBG_FUNC( "wvlan_driver_identity" ); 1607 DBG_FUNC("wvlan_driver_identity");
1625 DBG_ENTER( DbgInfo ); 1608 DBG_ENTER(DbgInfo);
1626 1609
1627 1610
1628 /* Make sure that user buffer can handle the driver identity structure. */ 1611 /* Make sure that user buffer can handle the driver identity structure. */
1629 if( urq->len < sizeof( lp->driverIdentity )) { 1612 if (urq->len < sizeof(lp->driverIdentity)) {
1630 urq->len = sizeof( lp->driverIdentity ); 1613 urq->len = sizeof(lp->driverIdentity);
1631 urq->result = UIL_ERR_LEN; 1614 urq->result = UIL_ERR_LEN;
1632 DBG_LEAVE( DbgInfo ); 1615 DBG_LEAVE(DbgInfo);
1633 return result; 1616 return result;
1634 } 1617 }
1635 1618
1636 /* Verify the user buffer. */ 1619 /* Verify the user buffer. */
1637 result = verify_area( VERIFY_WRITE, urq->data, sizeof( lp->driverIdentity )); 1620 result = verify_area(VERIFY_WRITE, urq->data, sizeof(lp->driverIdentity));
1638 if( result != 0 ) { 1621 if (result != 0) {
1639 urq->result = UIL_FAILURE; 1622 urq->result = UIL_FAILURE;
1640 DBG_LEAVE( DbgInfo ); 1623 DBG_LEAVE(DbgInfo);
1641 return result; 1624 return result;
1642 } 1625 }
1643 1626
1644 /* Copy the driver identity into the user's buffer. */ 1627 /* Copy the driver identity into the user's buffer. */
1645 urq->result = UIL_SUCCESS; 1628 urq->result = UIL_SUCCESS;
1646 copy_to_user( urq->data, &( lp->driverIdentity ), sizeof( lp->driverIdentity )); 1629 copy_to_user(urq->data, &(lp->driverIdentity), sizeof(lp->driverIdentity));
1647 1630
1648 DBG_LEAVE( DbgInfo ); 1631 DBG_LEAVE(DbgInfo);
1649 return result; 1632 return result;
1650} // cfg_driver_identity 1633} /* cfg_driver_identity */
1651/*============================================================================*/ 1634/*============================================================================*/
1652 1635
1653 1636
@@ -1684,27 +1667,27 @@ int wvlan_set_netname(struct net_device *dev,
1684 union iwreq_data *wrqu, 1667 union iwreq_data *wrqu,
1685 char *extra) 1668 char *extra)
1686{ 1669{
1687 struct wl_private *lp = wl_priv(dev); 1670 struct wl_private *lp = wl_priv(dev);
1688 unsigned long flags; 1671 unsigned long flags;
1689 int ret = 0; 1672 int ret = 0;
1690 /*------------------------------------------------------------------------*/ 1673 /*------------------------------------------------------------------------*/
1691 1674
1692 1675
1693 DBG_FUNC( "wvlan_set_netname" ); 1676 DBG_FUNC("wvlan_set_netname");
1694 DBG_ENTER( DbgInfo ); 1677 DBG_ENTER(DbgInfo);
1695 1678
1696 wl_lock(lp, &flags); 1679 wl_lock(lp, &flags);
1697 1680
1698 memset( lp->NetworkName, 0, sizeof( lp->NetworkName )); 1681 memset(lp->NetworkName, 0, sizeof(lp->NetworkName));
1699 memcpy( lp->NetworkName, extra, wrqu->data.length); 1682 memcpy(lp->NetworkName, extra, wrqu->data.length);
1700 1683
1701 /* Commit the adapter parameters */ 1684 /* Commit the adapter parameters */
1702 wl_apply(lp); 1685 wl_apply(lp);
1703 wl_unlock(lp, &flags); 1686 wl_unlock(lp, &flags);
1704 1687
1705 DBG_LEAVE( DbgInfo ); 1688 DBG_LEAVE(DbgInfo);
1706 return ret; 1689 return ret;
1707} // wvlan_set_netname 1690} /* wvlan_set_netname */
1708/*============================================================================*/ 1691/*============================================================================*/
1709 1692
1710 1693
@@ -1734,41 +1717,41 @@ int wvlan_get_netname(struct net_device *dev,
1734 union iwreq_data *wrqu, 1717 union iwreq_data *wrqu,
1735 char *extra) 1718 char *extra)
1736{ 1719{
1737 struct wl_private *lp = wl_priv(dev); 1720 struct wl_private *lp = wl_priv(dev);
1738 unsigned long flags; 1721 unsigned long flags;
1739 int ret = 0; 1722 int ret = 0;
1740 int status = -1; 1723 int status = -1;
1741 wvName_t *pName; 1724 wvName_t *pName;
1742 /*------------------------------------------------------------------------*/ 1725 /*------------------------------------------------------------------------*/
1743 1726
1744 1727
1745 DBG_FUNC( "wvlan_get_netname" ); 1728 DBG_FUNC("wvlan_get_netname");
1746 DBG_ENTER( DbgInfo ); 1729 DBG_ENTER(DbgInfo);
1747 1730
1748 wl_lock(lp, &flags); 1731 wl_lock(lp, &flags);
1749 1732
1750 /* Get the current network name */ 1733 /* Get the current network name */
1751 lp->ltvRecord.len = 1 + ( sizeof( *pName ) / sizeof( hcf_16 )); 1734 lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16));
1752 lp->ltvRecord.typ = CFG_CUR_SSID; 1735 lp->ltvRecord.typ = CFG_CUR_SSID;
1753 1736
1754 status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord )); 1737 status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord));
1755 1738
1756 if( status == HCF_SUCCESS ) { 1739 if (status == HCF_SUCCESS) {
1757 pName = (wvName_t *)&( lp->ltvRecord.u.u32 ); 1740 pName = (wvName_t *)&(lp->ltvRecord.u.u32);
1758 1741
1759 memset(extra, '\0', HCF_MAX_NAME_LEN); 1742 memset(extra, '\0', HCF_MAX_NAME_LEN);
1760 wrqu->data.length = pName->length; 1743 wrqu->data.length = pName->length;
1761 1744
1762 memcpy(extra, pName->name, pName->length); 1745 memcpy(extra, pName->name, pName->length);
1763 } else { 1746 } else {
1764 ret = -EFAULT; 1747 ret = -EFAULT;
1765 } 1748 }
1766 1749
1767 wl_unlock(lp, &flags); 1750 wl_unlock(lp, &flags);
1768 1751
1769 DBG_LEAVE( DbgInfo ); 1752 DBG_LEAVE(DbgInfo);
1770 return ret; 1753 return ret;
1771} // wvlan_get_netname 1754} /* wvlan_get_netname */
1772/*============================================================================*/ 1755/*============================================================================*/
1773 1756
1774 1757
@@ -1798,28 +1781,28 @@ int wvlan_set_station_nickname(struct net_device *dev,
1798 union iwreq_data *wrqu, 1781 union iwreq_data *wrqu,
1799 char *extra) 1782 char *extra)
1800{ 1783{
1801 struct wl_private *lp = wl_priv(dev); 1784 struct wl_private *lp = wl_priv(dev);
1802 unsigned long flags; 1785 unsigned long flags;
1803 int ret = 0; 1786 int ret = 0;
1804 /*------------------------------------------------------------------------*/ 1787 /*------------------------------------------------------------------------*/
1805 1788
1806 1789
1807 DBG_FUNC( "wvlan_set_station_nickname" ); 1790 DBG_FUNC("wvlan_set_station_nickname");
1808 DBG_ENTER( DbgInfo ); 1791 DBG_ENTER(DbgInfo);
1809 1792
1810 wl_lock(lp, &flags); 1793 wl_lock(lp, &flags);
1811 1794
1812 memset( lp->StationName, 0, sizeof( lp->StationName )); 1795 memset(lp->StationName, 0, sizeof(lp->StationName));
1813 1796
1814 memcpy( lp->StationName, extra, wrqu->data.length); 1797 memcpy(lp->StationName, extra, wrqu->data.length);
1815 1798
1816 /* Commit the adapter parameters */ 1799 /* Commit the adapter parameters */
1817 wl_apply( lp ); 1800 wl_apply(lp);
1818 wl_unlock(lp, &flags); 1801 wl_unlock(lp, &flags);
1819 1802
1820 DBG_LEAVE( DbgInfo ); 1803 DBG_LEAVE(DbgInfo);
1821 return ret; 1804 return ret;
1822} // wvlan_set_station_nickname 1805} /* wvlan_set_station_nickname */
1823/*============================================================================*/ 1806/*============================================================================*/
1824 1807
1825 1808
@@ -1849,41 +1832,41 @@ int wvlan_get_station_nickname(struct net_device *dev,
1849 union iwreq_data *wrqu, 1832 union iwreq_data *wrqu,
1850 char *extra) 1833 char *extra)
1851{ 1834{
1852 struct wl_private *lp = wl_priv(dev); 1835 struct wl_private *lp = wl_priv(dev);
1853 unsigned long flags; 1836 unsigned long flags;
1854 int ret = 0; 1837 int ret = 0;
1855 int status = -1; 1838 int status = -1;
1856 wvName_t *pName; 1839 wvName_t *pName;
1857 /*------------------------------------------------------------------------*/ 1840 /*------------------------------------------------------------------------*/
1858 1841
1859 1842
1860 DBG_FUNC( "wvlan_get_station_nickname" ); 1843 DBG_FUNC("wvlan_get_station_nickname");
1861 DBG_ENTER( DbgInfo ); 1844 DBG_ENTER(DbgInfo);
1862 1845
1863 wl_lock( lp, &flags ); 1846 wl_lock(lp, &flags);
1864 1847
1865 /* Get the current station name */ 1848 /* Get the current station name */
1866 lp->ltvRecord.len = 1 + ( sizeof( *pName ) / sizeof( hcf_16 )); 1849 lp->ltvRecord.len = 1 + (sizeof(*pName) / sizeof(hcf_16));
1867 lp->ltvRecord.typ = CFG_CNF_OWN_NAME; 1850 lp->ltvRecord.typ = CFG_CNF_OWN_NAME;
1868 1851
1869 status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord )); 1852 status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord));
1870 1853
1871 if( status == HCF_SUCCESS ) { 1854 if (status == HCF_SUCCESS) {
1872 pName = (wvName_t *)&( lp->ltvRecord.u.u32 ); 1855 pName = (wvName_t *)&(lp->ltvRecord.u.u32);
1873 1856
1874 memset(extra, '\0', HCF_MAX_NAME_LEN); 1857 memset(extra, '\0', HCF_MAX_NAME_LEN);
1875 wrqu->data.length = pName->length; 1858 wrqu->data.length = pName->length;
1876 memcpy(extra, pName->name, pName->length); 1859 memcpy(extra, pName->name, pName->length);
1877 } else { 1860 } else {
1878 ret = -EFAULT; 1861 ret = -EFAULT;
1879 } 1862 }
1880 1863
1881 wl_unlock(lp, &flags); 1864 wl_unlock(lp, &flags);
1882 1865
1883//out: 1866/* out: */
1884 DBG_LEAVE( DbgInfo ); 1867 DBG_LEAVE(DbgInfo);
1885 return ret; 1868 return ret;
1886} // wvlan_get_station_nickname 1869} /* wvlan_get_station_nickname */
1887/*============================================================================*/ 1870/*============================================================================*/
1888 1871
1889 1872
@@ -1913,37 +1896,37 @@ int wvlan_set_porttype(struct net_device *dev,
1913 union iwreq_data *wrqu, 1896 union iwreq_data *wrqu,
1914 char *extra) 1897 char *extra)
1915{ 1898{
1916 struct wl_private *lp = wl_priv(dev); 1899 struct wl_private *lp = wl_priv(dev);
1917 unsigned long flags; 1900 unsigned long flags;
1918 int ret = 0; 1901 int ret = 0;
1919 hcf_16 portType; 1902 hcf_16 portType;
1920 /*------------------------------------------------------------------------*/ 1903 /*------------------------------------------------------------------------*/
1921 1904
1922 1905
1923 DBG_FUNC( "wvlan_set_porttype" ); 1906 DBG_FUNC("wvlan_set_porttype");
1924 DBG_ENTER( DbgInfo ); 1907 DBG_ENTER(DbgInfo);
1925 1908
1926 wl_lock(lp, &flags); 1909 wl_lock(lp, &flags);
1927 1910
1928 /* Validate the new value */ 1911 /* Validate the new value */
1929 portType = *((__u32 *)extra); 1912 portType = *((__u32 *)extra);
1930 1913
1931 if( !(( portType == 1 ) || ( portType == 3 ))) { 1914 if (!((portType == 1) || (portType == 3))) {
1932 ret = -EINVAL; 1915 ret = -EINVAL;
1933 goto out_unlock; 1916 goto out_unlock;
1934 } 1917 }
1935 1918
1936 lp->PortType = portType; 1919 lp->PortType = portType;
1937 1920
1938 /* Commit the adapter parameters */ 1921 /* Commit the adapter parameters */
1939 wl_apply( lp ); 1922 wl_apply(lp);
1940 1923
1941out_unlock: 1924out_unlock:
1942 wl_unlock(lp, &flags); 1925 wl_unlock(lp, &flags);
1943 1926
1944//out: 1927/* out: */
1945 DBG_LEAVE( DbgInfo ); 1928 DBG_LEAVE(DbgInfo);
1946 return ret; 1929 return ret;
1947} 1930}
1948 1931
1949/*============================================================================*/ 1932/*============================================================================*/
@@ -1973,43 +1956,43 @@ int wvlan_get_porttype(struct net_device *dev,
1973 union iwreq_data *wrqu, 1956 union iwreq_data *wrqu,
1974 char *extra) 1957 char *extra)
1975{ 1958{
1976 struct wl_private *lp = wl_priv(dev); 1959 struct wl_private *lp = wl_priv(dev);
1977 unsigned long flags; 1960 unsigned long flags;
1978 int ret = 0; 1961 int ret = 0;
1979 int status = -1; 1962 int status = -1;
1980 hcf_16 *pPortType; 1963 hcf_16 *pPortType;
1981 __u32 *pData = (__u32 *)extra; 1964 __u32 *pData = (__u32 *)extra;
1982 /*------------------------------------------------------------------------*/ 1965 /*------------------------------------------------------------------------*/
1983 1966
1984 1967
1985 DBG_FUNC( "wvlan_get_porttype" ); 1968 DBG_FUNC("wvlan_get_porttype");
1986 DBG_ENTER( DbgInfo ); 1969 DBG_ENTER(DbgInfo);
1987 1970
1988 wl_lock( lp, &flags ); 1971 wl_lock(lp, &flags);
1989 1972
1990 /* Get the current port type */ 1973 /* Get the current port type */
1991 lp->ltvRecord.len = 1 + ( sizeof( *pPortType ) / sizeof( hcf_16 )); 1974 lp->ltvRecord.len = 1 + (sizeof(*pPortType) / sizeof(hcf_16));
1992 lp->ltvRecord.typ = CFG_CNF_PORT_TYPE; 1975 lp->ltvRecord.typ = CFG_CNF_PORT_TYPE;
1993 1976
1994 status = hcf_get_info( &( lp->hcfCtx ), (LTVP)&( lp->ltvRecord )); 1977 status = hcf_get_info(&(lp->hcfCtx), (LTVP)&(lp->ltvRecord));
1995 1978
1996 if( status == HCF_SUCCESS ) { 1979 if (status == HCF_SUCCESS) {
1997 pPortType = (hcf_16 *)&( lp->ltvRecord.u.u32 ); 1980 pPortType = (hcf_16 *)&(lp->ltvRecord.u.u32);
1998 1981
1999 *pData = CNV_LITTLE_TO_INT( *pPortType ); 1982 *pData = CNV_LITTLE_TO_INT(*pPortType);
2000 } else { 1983 } else {
2001 ret = -EFAULT; 1984 ret = -EFAULT;
2002 } 1985 }
2003 1986
2004 wl_unlock(lp, &flags); 1987 wl_unlock(lp, &flags);
2005 1988
2006//out: 1989/* out: */
2007 DBG_LEAVE( DbgInfo ); 1990 DBG_LEAVE(DbgInfo);
2008 return ret; 1991 return ret;
2009} // wvlan_get_porttype 1992} /* wvlan_get_porttype */
2010/*============================================================================*/ 1993/*============================================================================*/
2011 1994
2012#endif // WIRELESS_EXT 1995#endif /* WIRELESS_EXT */
2013 1996
2014 1997
2015 1998
@@ -2034,49 +2017,49 @@ int wvlan_get_porttype(struct net_device *dev,
2034 * errno value otherwise 2017 * errno value otherwise
2035 * 2018 *
2036 ******************************************************************************/ 2019 ******************************************************************************/
2037int wvlan_rts( struct rtsreq *rrq, __u32 io_base ) 2020int wvlan_rts(struct rtsreq *rrq, __u32 io_base)
2038{ 2021{
2039 int ioctl_ret = 0; 2022 int ioctl_ret = 0;
2040 /*------------------------------------------------------------------------*/ 2023 /*------------------------------------------------------------------------*/
2041 2024
2042 2025
2043 DBG_FUNC( "wvlan_rts" ); 2026 DBG_FUNC("wvlan_rts");
2044 DBG_ENTER( DbgInfo ); 2027 DBG_ENTER(DbgInfo);
2045 2028
2046 2029
2047 DBG_PRINT( "io_base: 0x%08x\n", io_base ); 2030 DBG_PRINT("io_base: 0x%08x\n", io_base);
2048 2031
2049 switch( rrq->typ ) { 2032 switch (rrq->typ) {
2050 case WL_IOCTL_RTS_READ: 2033 case WL_IOCTL_RTS_READ:
2051 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_READ\n"); 2034 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_READ\n");
2052 rrq->data[0] = IN_PORT_WORD( io_base + rrq->reg ); 2035 rrq->data[0] = IN_PORT_WORD(io_base + rrq->reg);
2053 DBG_TRACE( DbgInfo, " reg 0x%04x ==> 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT( rrq->data[0] ) ); 2036 DBG_TRACE(DbgInfo, " reg 0x%04x ==> 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT(rrq->data[0]));
2054 break; 2037 break;
2055 case WL_IOCTL_RTS_WRITE: 2038 case WL_IOCTL_RTS_WRITE:
2056 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_WRITE\n"); 2039 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_WRITE\n");
2057 OUT_PORT_WORD( io_base + rrq->reg, rrq->data[0] ); 2040 OUT_PORT_WORD(io_base + rrq->reg, rrq->data[0]);
2058 DBG_TRACE( DbgInfo, " reg 0x%04x <== 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT( rrq->data[0] ) ); 2041 DBG_TRACE(DbgInfo, " reg 0x%04x <== 0x%04x\n", rrq->reg, CNV_LITTLE_TO_SHORT(rrq->data[0]));
2059 break; 2042 break;
2060 case WL_IOCTL_RTS_BATCH_READ: 2043 case WL_IOCTL_RTS_BATCH_READ:
2061 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_READ\n"); 2044 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_READ\n");
2062 IN_PORT_STRING_16( io_base + rrq->reg, rrq->data, rrq->len ); 2045 IN_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len);
2063 DBG_TRACE( DbgInfo, " reg 0x%04x ==> %d bytes\n", rrq->reg, rrq->len * sizeof (__u16 ) ); 2046 DBG_TRACE(DbgInfo, " reg 0x%04x ==> %d bytes\n", rrq->reg, rrq->len * sizeof(__u16));
2064 break; 2047 break;
2065 case WL_IOCTL_RTS_BATCH_WRITE: 2048 case WL_IOCTL_RTS_BATCH_WRITE:
2066 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_WRITE\n"); 2049 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- WL_IOCTL_RTS_BATCH_WRITE\n");
2067 OUT_PORT_STRING_16( io_base + rrq->reg, rrq->data, rrq->len ); 2050 OUT_PORT_STRING_16(io_base + rrq->reg, rrq->data, rrq->len);
2068 DBG_TRACE( DbgInfo, " reg 0x%04x <== %d bytes\n", rrq->reg, rrq->len * sizeof (__u16) ); 2051 DBG_TRACE(DbgInfo, " reg 0x%04x <== %d bytes\n", rrq->reg, rrq->len * sizeof(__u16));
2069 break; 2052 break;
2070 default: 2053 default:
2071 2054
2072 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- UNSUPPORTED RTS CODE: 0x%X", rrq->typ ); 2055 DBG_TRACE(DbgInfo, "IOCTL: WVLAN2_IOCTL_RTS -- UNSUPPORTED RTS CODE: 0x%X", rrq->typ);
2073 ioctl_ret = -EOPNOTSUPP; 2056 ioctl_ret = -EOPNOTSUPP;
2074 break; 2057 break;
2075 } 2058 }
2076 2059
2077 DBG_LEAVE( DbgInfo ); 2060 DBG_LEAVE(DbgInfo);
2078 return ioctl_ret; 2061 return ioctl_ret;
2079} // wvlan_rts 2062} /* wvlan_rts */
2080/*============================================================================*/ 2063/*============================================================================*/
2081 2064
2082#endif /* USE_RTS */ 2065#endif /* USE_RTS */
diff --git a/drivers/staging/wlags49_h2/wl_priv.h b/drivers/staging/wlags49_h2/wl_priv.h
index b647bfd90098..f35e79486428 100644
--- a/drivers/staging/wlags49_h2/wl_priv.h
+++ b/drivers/staging/wlags49_h2/wl_priv.h
@@ -70,52 +70,58 @@
70#ifdef WIRELESS_EXT 70#ifdef WIRELESS_EXT
71 71
72 72
73int wvlan_set_netname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); 73int wvlan_set_netname(struct net_device *, struct iw_request_info *,
74 union iwreq_data *, char *extra);
74 75
75int wvlan_get_netname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); 76int wvlan_get_netname(struct net_device *, struct iw_request_info *,
77 union iwreq_data *, char *extra);
76 78
77int wvlan_set_station_nickname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); 79int wvlan_set_station_nickname(struct net_device *, struct iw_request_info *,
80 union iwreq_data *, char *extra);
78 81
79int wvlan_get_station_nickname( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); 82int wvlan_get_station_nickname(struct net_device *, struct iw_request_info *,
83 union iwreq_data *, char *extra);
80 84
81int wvlan_set_porttype( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); 85int wvlan_set_porttype(struct net_device *, struct iw_request_info *,
86 union iwreq_data *, char *extra);
82 87
83int wvlan_get_porttype( struct net_device *, struct iw_request_info *, union iwreq_data *, char *extra ); 88int wvlan_get_porttype(struct net_device *, struct iw_request_info *,
89 union iwreq_data *, char *extra);
84 90
85 91
86#endif // WIRELESS_EXT 92#endif /* WIRELESS_EXT */
87 93
88 94
89 95
90 96
91#ifdef USE_UIL 97#ifdef USE_UIL
92 98
93int wvlan_uil( struct uilreq *urq, struct wl_private *lp ); 99int wvlan_uil(struct uilreq *urq, struct wl_private *lp);
94 100
95// int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ); 101/* int wvlan_uil_connect( struct uilreq *urq, struct wl_private *lp ); */
96// int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ); 102/* int wvlan_uil_disconnect( struct uilreq *urq, struct wl_private *lp ); */
97// int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ); 103/* int wvlan_uil_action( struct uilreq *urq, struct wl_private *lp ); */
98// int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ); 104/* int wvlan_uil_block( struct uilreq *urq, struct wl_private *lp ); */
99// int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ); 105/* int wvlan_uil_unblock( struct uilreq *urq, struct wl_private *lp ); */
100// int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ); 106/* int wvlan_uil_send_diag_msg( struct uilreq *urq, struct wl_private *lp ); */
101// int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ); 107/* int wvlan_uil_put_info( struct uilreq *urq, struct wl_private *lp ); */
102// int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ); 108/* int wvlan_uil_get_info( struct uilreq *urq, struct wl_private *lp ); */
103 109
104//int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ); 110/* int cfg_driver_info( struct uilreq *urq, struct wl_private *lp ); */
105//int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ); 111/* int cfg_driver_identity( struct uilreq *urq, struct wl_private *lp ); */
106 112
107#endif // USE_UIL 113#endif /* USE_UIL */
108 114
109 115
110#ifdef USE_RTS 116#ifdef USE_RTS
111 117
112int wvlan_rts( struct rtsreq *rrq, __u32 io_base ); 118int wvlan_rts(struct rtsreq *rrq, __u32 io_base);
113int wvlan_rts_read( __u16 reg, __u16 *val, __u32 io_base ); 119int wvlan_rts_read(__u16 reg, __u16 *val, __u32 io_base);
114int wvlan_rts_write( __u16 reg, __u16 val, __u32 io_base ); 120int wvlan_rts_write(__u16 reg, __u16 val, __u32 io_base);
115int wvlan_rts_batch_read( struct rtsreq *rrq, __u32 io_base ); 121int wvlan_rts_batch_read(struct rtsreq *rrq, __u32 io_base);
116int wvlan_rts_batch_write( struct rtsreq *rrq, __u32 io_base ); 122int wvlan_rts_batch_write(struct rtsreq *rrq, __u32 io_base);
117 123
118#endif // USE_RTS 124#endif /* USE_RTS */
119 125
120 126
121#endif // __WL_PRIV_H__ 127#endif /* __WL_PRIV_H__ */
diff --git a/drivers/staging/wlags49_h2/wl_profile.h b/drivers/staging/wlags49_h2/wl_profile.h
index f81df51d2216..d615c836f950 100644
--- a/drivers/staging/wlags49_h2/wl_profile.h
+++ b/drivers/staging/wlags49_h2/wl_profile.h
@@ -73,15 +73,15 @@
73/******************************************************************************* 73/*******************************************************************************
74 * function prototypes 74 * function prototypes
75 ******************************************************************************/ 75 ******************************************************************************/
76void parse_config( struct net_device *dev ); 76void parse_config(struct net_device *dev);
77 77
78int readline( int filedesc, char *buffer ); 78int readline(int filedesc, char *buffer);
79 79
80void translate_option( char *buffer, struct wl_private *lp ); 80void translate_option(char *buffer, struct wl_private *lp);
81 81
82int parse_mac_address( char *value, u_char *byte_array ); 82int parse_mac_address(char *value, u_char *byte_array);
83 83
84void ParseConfigLine( char *pszLine, char **ppszLVal, char **ppszRVal ); 84void ParseConfigLine(char *pszLine, char **ppszLVal, char **ppszRVal);
85 85
86 86
87#endif // __WL_PROFILE_H__ 87#endif /* __WL_PROFILE_H__ */
diff --git a/drivers/staging/wlags49_h2/wl_util.h b/drivers/staging/wlags49_h2/wl_util.h
index 946b1b64c46f..57bfd7fac6fa 100644
--- a/drivers/staging/wlags49_h2/wl_util.h
+++ b/drivers/staging/wlags49_h2/wl_util.h
@@ -65,32 +65,32 @@
65/******************************************************************************* 65/*******************************************************************************
66 * function prototypes 66 * function prototypes
67 ******************************************************************************/ 67 ******************************************************************************/
68int dbm( int value ); 68int dbm(int value);
69 69
70int is_valid_key_string( char *s ); 70int is_valid_key_string(char *s);
71 71
72void key_string2key( char *ks, KEY_STRCT *key ); 72void key_string2key(char *ks, KEY_STRCT *key);
73 73
74void wl_hcf_error( struct net_device *dev, int hcfStatus ); 74void wl_hcf_error(struct net_device *dev, int hcfStatus);
75 75
76void wl_endian_translate_event( ltv_t *pLtv ); 76void wl_endian_translate_event(ltv_t *pLtv);
77 77
78int wl_has_wep( IFBP ifbp ); 78int wl_has_wep(IFBP ifbp);
79 79
80hcf_8 wl_parse_ds_ie( PROBE_RESP *probe_rsp ); 80hcf_8 wl_parse_ds_ie(PROBE_RESP *probe_rsp);
81hcf_8 * wl_parse_wpa_ie( PROBE_RESP *probe_rsp, hcf_16 *length ); 81hcf_8 *wl_parse_wpa_ie(PROBE_RESP *probe_rsp, hcf_16 *length);
82hcf_8 * wl_print_wpa_ie( hcf_8 *buffer, int length ); 82hcf_8 *wl_print_wpa_ie(hcf_8 *buffer, int length);
83 83
84int wl_get_tallies(struct wl_private *, CFG_HERMES_TALLIES_STRCT *); 84int wl_get_tallies(struct wl_private *, CFG_HERMES_TALLIES_STRCT *);
85int wl_is_a_valid_chan( int channel ); 85int wl_is_a_valid_chan(int channel);
86int wl_is_a_valid_freq( long frequency ); 86int wl_is_a_valid_freq(long frequency);
87long wl_get_freq_from_chan( int channel ); 87long wl_get_freq_from_chan(int channel);
88int wl_get_chan_from_freq( long frequency ); 88int wl_get_chan_from_freq(long frequency);
89 89
90void wl_process_link_status( struct wl_private *lp ); 90void wl_process_link_status(struct wl_private *lp);
91void wl_process_probe_response( struct wl_private *lp ); 91void wl_process_probe_response(struct wl_private *lp);
92void wl_process_updated_record( struct wl_private *lp ); 92void wl_process_updated_record(struct wl_private *lp);
93void wl_process_assoc_status( struct wl_private *lp ); 93void wl_process_assoc_status(struct wl_private *lp);
94void wl_process_security_status( struct wl_private *lp ); 94void wl_process_security_status(struct wl_private *lp);
95 95
96#endif // __WL_UTIL_H__ 96#endif /* __WL_UTIL_H__ */
diff --git a/drivers/staging/wlags49_h2/wl_wext.c b/drivers/staging/wlags49_h2/wl_wext.c
index f553366cccc5..c731ff2a6aa1 100644
--- a/drivers/staging/wlags49_h2/wl_wext.c
+++ b/drivers/staging/wlags49_h2/wl_wext.c
@@ -796,8 +796,6 @@ static int wireless_get_bssid(struct net_device *dev, struct iw_request_info *in
796 796
797 wl_act_int_off( lp ); 797 wl_act_int_off( lp );
798 798
799 memset( &ap_addr->sa_data, 0, ETH_ALEN );
800
801 ap_addr->sa_family = ARPHRD_ETHER; 799 ap_addr->sa_family = ARPHRD_ETHER;
802 800
803 /* Assume AP mode here, which means the BSSID is our own MAC address. In 801 /* Assume AP mode here, which means the BSSID is our own MAC address. In
diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h
index 5631ad0a7237..3dfa85ccc504 100644
--- a/drivers/staging/wlan-ng/hfa384x.h
+++ b/drivers/staging/wlan-ng/hfa384x.h
@@ -59,6 +59,7 @@
59#define HFA384x_FIRMWARE_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) 59#define HFA384x_FIRMWARE_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
60 60
61#include <linux/if_ether.h> 61#include <linux/if_ether.h>
62#include <linux/usb.h>
62 63
63/*--- Mins & Maxs -----------------------------------*/ 64/*--- Mins & Maxs -----------------------------------*/
64#define HFA384x_PORTID_MAX ((u16)7) 65#define HFA384x_PORTID_MAX ((u16)7)
@@ -81,8 +82,8 @@
81#define HFA384x_WEPFLAGS_EXCLUDE ((u16)BIT(1)) 82#define HFA384x_WEPFLAGS_EXCLUDE ((u16)BIT(1))
82#define HFA384x_WEPFLAGS_DISABLE_TXCRYPT ((u16)BIT(4)) 83#define HFA384x_WEPFLAGS_DISABLE_TXCRYPT ((u16)BIT(4))
83#define HFA384x_WEPFLAGS_DISABLE_RXCRYPT ((u16)BIT(7)) 84#define HFA384x_WEPFLAGS_DISABLE_RXCRYPT ((u16)BIT(7))
84#define HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM ((u16)3) 85#define HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM ((u16)3)
85#define HFA384x_PORTSTATUS_DISABLED ((u16)1) 86#define HFA384x_PORTSTATUS_DISABLED ((u16)1)
86#define HFA384x_RATEBIT_1 ((u16)1) 87#define HFA384x_RATEBIT_1 ((u16)1)
87#define HFA384x_RATEBIT_2 ((u16)2) 88#define HFA384x_RATEBIT_2 ((u16)2)
88#define HFA384x_RATEBIT_5dot5 ((u16)4) 89#define HFA384x_RATEBIT_5dot5 ((u16)4)
@@ -164,7 +165,7 @@
164#define HFA384x_CMDCODE_DOWNLD ((u16)0x22) 165#define HFA384x_CMDCODE_DOWNLD ((u16)0x22)
165 166
166/*--- Debugging Commands -----------------------------*/ 167/*--- Debugging Commands -----------------------------*/
167#define HFA384x_CMDCODE_MONITOR ((u16)(0x38)) 168#define HFA384x_CMDCODE_MONITOR ((u16)(0x38))
168#define HFA384x_MONITOR_ENABLE ((u16)(0x0b)) 169#define HFA384x_MONITOR_ENABLE ((u16)(0x0b))
169#define HFA384x_MONITOR_DISABLE ((u16)(0x0f)) 170#define HFA384x_MONITOR_DISABLE ((u16)(0x0f))
170 171
@@ -275,15 +276,15 @@ API ENHANCEMENTS (NOT ALREADY IMPLEMENTED)
275#define HFA384x_RID_CNFAUTHENTICATION ((u16)0xFC2A) 276#define HFA384x_RID_CNFAUTHENTICATION ((u16)0xFC2A)
276#define HFA384x_RID_CNFROAMINGMODE ((u16)0xFC2D) 277#define HFA384x_RID_CNFROAMINGMODE ((u16)0xFC2D)
277#define HFA384x_RID_CNFAPBCNint ((u16)0xFC33) 278#define HFA384x_RID_CNFAPBCNint ((u16)0xFC33)
278#define HFA384x_RID_CNFDBMADJUST ((u16)0xFC46) 279#define HFA384x_RID_CNFDBMADJUST ((u16)0xFC46)
279#define HFA384x_RID_CNFWPADATA ((u16)0xFC48) 280#define HFA384x_RID_CNFWPADATA ((u16)0xFC48)
280#define HFA384x_RID_CNFBASICRATES ((u16)0xFCB3) 281#define HFA384x_RID_CNFBASICRATES ((u16)0xFCB3)
281#define HFA384x_RID_CNFSUPPRATES ((u16)0xFCB4) 282#define HFA384x_RID_CNFSUPPRATES ((u16)0xFCB4)
282#define HFA384x_RID_CNFPASSIVESCANCTRL ((u16)0xFCBA) 283#define HFA384x_RID_CNFPASSIVESCANCTRL ((u16)0xFCBA)
283#define HFA384x_RID_TXPOWERMAX ((u16)0xFCBE) 284#define HFA384x_RID_TXPOWERMAX ((u16)0xFCBE)
284#define HFA384x_RID_JOINREQUEST ((u16)0xFCE2) 285#define HFA384x_RID_JOINREQUEST ((u16)0xFCE2)
285#define HFA384x_RID_AUTHENTICATESTA ((u16)0xFCE3) 286#define HFA384x_RID_AUTHENTICATESTA ((u16)0xFCE3)
286#define HFA384x_RID_HOSTSCAN ((u16)0xFCE5) 287#define HFA384x_RID_HOSTSCAN ((u16)0xFCE5)
287 288
288#define HFA384x_RID_CNFWEPDEFAULTKEY_LEN ((u16)6) 289#define HFA384x_RID_CNFWEPDEFAULTKEY_LEN ((u16)6)
289#define HFA384x_RID_CNFWEP128DEFAULTKEY_LEN ((u16)14) 290#define HFA384x_RID_CNFWEP128DEFAULTKEY_LEN ((u16)14)
@@ -311,7 +312,7 @@ PD Record codes
311#define HFA384x_PDR_HFA3861_IFRF ((u16)0x0204) 312#define HFA384x_PDR_HFA3861_IFRF ((u16)0x0204)
312#define HFA384x_PDR_HFA3861_CHCALSP ((u16)0x0300) 313#define HFA384x_PDR_HFA3861_CHCALSP ((u16)0x0300)
313#define HFA384x_PDR_HFA3861_CHCALI ((u16)0x0301) 314#define HFA384x_PDR_HFA3861_CHCALI ((u16)0x0301)
314#define HFA384x_PDR_MAX_TX_POWER ((u16)0x0302) 315#define HFA384x_PDR_MAX_TX_POWER ((u16)0x0302)
315#define HFA384x_PDR_MASTER_CHAN_LIST ((u16)0x0303) 316#define HFA384x_PDR_MASTER_CHAN_LIST ((u16)0x0303)
316#define HFA384x_PDR_3842_NIC_CONFIG ((u16)0x0400) 317#define HFA384x_PDR_3842_NIC_CONFIG ((u16)0x0400)
317#define HFA384x_PDR_USB_ID ((u16)0x0401) 318#define HFA384x_PDR_USB_ID ((u16)0x0401)
@@ -322,10 +323,10 @@ PD Record codes
322#define HFA384x_PDR_USB_POWER_TYPE ((u16)0x0407) 323#define HFA384x_PDR_USB_POWER_TYPE ((u16)0x0407)
323#define HFA384x_PDR_USB_MAX_POWER ((u16)0x0409) 324#define HFA384x_PDR_USB_MAX_POWER ((u16)0x0409)
324#define HFA384x_PDR_USB_MANUFACTURER ((u16)0x0410) 325#define HFA384x_PDR_USB_MANUFACTURER ((u16)0x0410)
325#define HFA384x_PDR_USB_PRODUCT ((u16)0x0411) 326#define HFA384x_PDR_USB_PRODUCT ((u16)0x0411)
326#define HFA384x_PDR_ANT_DIVERSITY ((u16)0x0412) 327#define HFA384x_PDR_ANT_DIVERSITY ((u16)0x0412)
327#define HFA384x_PDR_HFO_DELAY ((u16)0x0413) 328#define HFA384x_PDR_HFO_DELAY ((u16)0x0413)
328#define HFA384x_PDR_SCALE_THRESH ((u16)0x0414) 329#define HFA384x_PDR_SCALE_THRESH ((u16)0x0414)
329 330
330#define HFA384x_PDR_HFA3861_MANF_TESTSP ((u16)0x0900) 331#define HFA384x_PDR_HFA3861_MANF_TESTSP ((u16)0x0900)
331#define HFA384x_PDR_HFA3861_MANF_TESTI ((u16)0x0901) 332#define HFA384x_PDR_HFA3861_MANF_TESTI ((u16)0x0901)
@@ -383,7 +384,7 @@ typedef struct hfa384x_caplevel {
383/*-- Configuration Record: cnfAuthentication --*/ 384/*-- Configuration Record: cnfAuthentication --*/
384#define HFA384x_CNFAUTHENTICATION_OPENSYSTEM 0x0001 385#define HFA384x_CNFAUTHENTICATION_OPENSYSTEM 0x0001
385#define HFA384x_CNFAUTHENTICATION_SHAREDKEY 0x0002 386#define HFA384x_CNFAUTHENTICATION_SHAREDKEY 0x0002
386#define HFA384x_CNFAUTHENTICATION_LEAP 0x0004 387#define HFA384x_CNFAUTHENTICATION_LEAP 0x0004
387 388
388/*-------------------------------------------------------------------- 389/*--------------------------------------------------------------------
389Configuration Record Structures: 390Configuration Record Structures:
@@ -575,8 +576,8 @@ Information Types
575#define HFA384x_IT_AUTHREQ ((u16)0xF202UL) 576#define HFA384x_IT_AUTHREQ ((u16)0xF202UL)
576#define HFA384x_IT_PSUSERCNT ((u16)0xF203UL) 577#define HFA384x_IT_PSUSERCNT ((u16)0xF203UL)
577#define HFA384x_IT_KEYIDCHANGED ((u16)0xF204UL) 578#define HFA384x_IT_KEYIDCHANGED ((u16)0xF204UL)
578#define HFA384x_IT_ASSOCREQ ((u16)0xF205UL) 579#define HFA384x_IT_ASSOCREQ ((u16)0xF205UL)
579#define HFA384x_IT_MICFAILURE ((u16)0xF206UL) 580#define HFA384x_IT_MICFAILURE ((u16)0xF206UL)
580 581
581/*-------------------------------------------------------------------- 582/*--------------------------------------------------------------------
582Information Frames Structures 583Information Frames Structures
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index 750330f064f9..0039e082507d 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -351,6 +351,8 @@ static int p80211knetdev_hard_start_xmit(struct sk_buff *skb,
351 union p80211_hdr p80211_hdr; 351 union p80211_hdr p80211_hdr;
352 struct p80211_metawep p80211_wep; 352 struct p80211_metawep p80211_wep;
353 353
354 p80211_wep.data = NULL;
355
354 if (skb == NULL) 356 if (skb == NULL)
355 return NETDEV_TX_OK; 357 return NETDEV_TX_OK;
356 358
diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c
index 89bfd858bb28..d22db43e8031 100644
--- a/drivers/staging/wlan-ng/prism2mgmt.c
+++ b/drivers/staging/wlan-ng/prism2mgmt.c
@@ -415,11 +415,14 @@ int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
415 break; 415 break;
416 416
417#define REQBASICRATE(N) \ 417#define REQBASICRATE(N) \
418 if ((count >= N) && DOT11_RATE5_ISBASIC_GET(item->supprates[(N)-1])) { \ 418 do { \
419 req->basicrate ## N .data = item->supprates[(N)-1]; \ 419 if ((count >= N) && DOT11_RATE5_ISBASIC_GET( \
420 req->basicrate ## N .status = \ 420 item->supprates[(N)-1])) { \
421 P80211ENUM_msgitem_status_data_ok; \ 421 req->basicrate ## N .data = item->supprates[(N)-1]; \
422 } 422 req->basicrate ## N .status = \
423 P80211ENUM_msgitem_status_data_ok; \
424 } \
425 } while (0)
423 426
424 REQBASICRATE(1); 427 REQBASICRATE(1);
425 REQBASICRATE(2); 428 REQBASICRATE(2);
@@ -431,11 +434,13 @@ int prism2mgmt_scan_results(wlandevice_t *wlandev, void *msgp)
431 REQBASICRATE(8); 434 REQBASICRATE(8);
432 435
433#define REQSUPPRATE(N) \ 436#define REQSUPPRATE(N) \
434 if (count >= N) { \ 437 do { \
435 req->supprate ## N .data = item->supprates[(N)-1]; \ 438 if (count >= N) { \
436 req->supprate ## N .status = \ 439 req->supprate ## N .data = item->supprates[(N)-1]; \
437 P80211ENUM_msgitem_status_data_ok; \ 440 req->supprate ## N .status = \
438 } 441 P80211ENUM_msgitem_status_data_ok; \
442 } \
443 } while (0)
439 444
440 REQSUPPRATE(1); 445 REQSUPPRATE(1);
441 REQSUPPRATE(2); 446 REQSUPPRATE(2);
@@ -1139,9 +1144,8 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1139 /* Enable the port */ 1144 /* Enable the port */
1140 result = hfa384x_drvr_enable(hw, 0); 1145 result = hfa384x_drvr_enable(hw, 0);
1141 if (result) { 1146 if (result) {
1142 pr_debug 1147 pr_debug("failed to enable port to presniff setting, result=%d\n",
1143 ("failed to enable port to presniff setting, result=%d\n", 1148 result);
1144 result);
1145 goto failed; 1149 goto failed;
1146 } 1150 }
1147 } else { 1151 } else {
@@ -1181,18 +1185,16 @@ int prism2mgmt_wlansniff(wlandevice_t *wlandev, void *msgp)
1181 hfa384x_drvr_stop(hw); 1185 hfa384x_drvr_stop(hw);
1182 result = hfa384x_drvr_start(hw); 1186 result = hfa384x_drvr_start(hw);
1183 if (result) { 1187 if (result) {
1184 pr_debug 1188 pr_debug("failed to restart the card for sniffing, result=%d\n",
1185 ("failed to restart the card for sniffing, result=%d\n", 1189 result);
1186 result);
1187 goto failed; 1190 goto failed;
1188 } 1191 }
1189 } else { 1192 } else {
1190 /* Disable the port */ 1193 /* Disable the port */
1191 result = hfa384x_drvr_disable(hw, 0); 1194 result = hfa384x_drvr_disable(hw, 0);
1192 if (result) { 1195 if (result) {
1193 pr_debug 1196 pr_debug("failed to enable port for sniffing, result=%d\n",
1194 ("failed to enable port for sniffing, result=%d\n", 1197 result);
1195 result);
1196 goto failed; 1198 goto failed;
1197 } 1199 }
1198 } 1200 }
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index e0f745de7e7a..801ac4053a7a 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -91,11 +91,10 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
91 unsigned short ModeIdIndex, index = 0; 91 unsigned short ModeIdIndex, index = 0;
92 unsigned short RefreshRateTableIndex = 0; 92 unsigned short RefreshRateTableIndex = 0;
93 93
94 unsigned short VRE, VBE, VRS, VBS, VDE, VT; 94 unsigned short VRE, VBE, VRS, VDE;
95 unsigned short HRE, HBE, HRS, HBS, HDE, HT; 95 unsigned short HRE, HBE, HRS, HDE;
96 unsigned char sr_data, cr_data, cr_data2; 96 unsigned char sr_data, cr_data, cr_data2;
97 unsigned long cr_data3; 97 int B, C, D, F, temp, j;
98 int A, B, C, D, E, F, temp, j;
99 InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr); 98 InitTo330Pointer(HwDeviceExtension->jChipType, XGI_Pr);
100 if (!XGI_SearchModeID(ModeNo, &ModeIdIndex, XGI_Pr)) 99 if (!XGI_SearchModeID(ModeNo, &ModeIdIndex, XGI_Pr))
101 return 0; 100 return 0;
@@ -105,25 +104,13 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
105 104
106 sr_data = XGI_CRT1Table[index].CR[5]; 105 sr_data = XGI_CRT1Table[index].CR[5];
107 106
108 cr_data = XGI_CRT1Table[index].CR[0]; 107 HDE = (XGI330_RefIndex[RefreshRateTableIndex].XRes >> 3);
109
110 /* Horizontal total */
111 HT = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x03) << 8);
112 A = HT + 5;
113
114 HDE = (XGI330_RefIndex[RefreshRateTableIndex].XRes >> 3) - 1;
115 E = HDE + 1;
116 108
117 cr_data = XGI_CRT1Table[index].CR[3]; 109 cr_data = XGI_CRT1Table[index].CR[3];
118 110
119 /* Horizontal retrace (=sync) start */ 111 /* Horizontal retrace (=sync) start */
120 HRS = (cr_data & 0xff) | ((unsigned short) (sr_data & 0xC0) << 2); 112 HRS = (cr_data & 0xff) | ((unsigned short) (sr_data & 0xC0) << 2);
121 F = HRS - E - 3; 113 F = HRS - HDE - 3;
122
123 cr_data = XGI_CRT1Table[index].CR[1];
124
125 /* Horizontal blank start */
126 HBS = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x30) << 4);
127 114
128 sr_data = XGI_CRT1Table[index].CR[6]; 115 sr_data = XGI_CRT1Table[index].CR[6];
129 116
@@ -138,10 +125,10 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
138 /* Horizontal retrace (=sync) end */ 125 /* Horizontal retrace (=sync) end */
139 HRE = (cr_data2 & 0x1f) | ((sr_data & 0x04) << 3); 126 HRE = (cr_data2 & 0x1f) | ((sr_data & 0x04) << 3);
140 127
141 temp = HBE - ((E - 1) & 255); 128 temp = HBE - ((HDE - 1) & 255);
142 B = (temp > 0) ? temp : (temp + 256); 129 B = (temp > 0) ? temp : (temp + 256);
143 130
144 temp = HRE - ((E + F + 3) & 63); 131 temp = HRE - ((HDE + F + 3) & 63);
145 C = (temp > 0) ? temp : (temp + 64); 132 C = (temp > 0) ? temp : (temp + 64);
146 133
147 D = B - F - C; 134 D = B - F - C;
@@ -152,18 +139,9 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
152 139
153 sr_data = XGI_CRT1Table[index].CR[14]; 140 sr_data = XGI_CRT1Table[index].CR[14];
154 141
155 cr_data = XGI_CRT1Table[index].CR[8];
156
157 cr_data2 = XGI_CRT1Table[index].CR[9]; 142 cr_data2 = XGI_CRT1Table[index].CR[9];
158 143
159 /* Vertical total */ 144 VDE = XGI330_RefIndex[RefreshRateTableIndex].YRes;
160 VT = (cr_data & 0xFF) | ((unsigned short) (cr_data2 & 0x01) << 8)
161 | ((unsigned short) (cr_data2 & 0x20) << 4)
162 | ((unsigned short) (sr_data & 0x01) << 10);
163 A = VT + 2;
164
165 VDE = XGI330_RefIndex[RefreshRateTableIndex].YRes - 1;
166 E = VDE + 1;
167 145
168 cr_data = XGI_CRT1Table[index].CR[10]; 146 cr_data = XGI_CRT1Table[index].CR[10];
169 147
@@ -171,29 +149,20 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
171 VRS = (cr_data & 0xff) | ((unsigned short) (cr_data2 & 0x04) << 6) 149 VRS = (cr_data & 0xff) | ((unsigned short) (cr_data2 & 0x04) << 6)
172 | ((unsigned short) (cr_data2 & 0x80) << 2) 150 | ((unsigned short) (cr_data2 & 0x80) << 2)
173 | ((unsigned short) (sr_data & 0x08) << 7); 151 | ((unsigned short) (sr_data & 0x08) << 7);
174 F = VRS + 1 - E; 152 F = VRS + 1 - VDE;
175
176 cr_data = XGI_CRT1Table[index].CR[12];
177
178 cr_data3 = (XGI_CRT1Table[index].CR[14] & 0x80) << 5;
179
180 /* Vertical blank start */
181 VBS = (cr_data & 0xff) | ((unsigned short) (cr_data2 & 0x08) << 5)
182 | ((unsigned short) (cr_data3 & 0x20) << 4)
183 | ((unsigned short) (sr_data & 0x04) << 8);
184 153
185 cr_data = XGI_CRT1Table[index].CR[13]; 154 cr_data = XGI_CRT1Table[index].CR[13];
186 155
187 /* Vertical blank end */ 156 /* Vertical blank end */
188 VBE = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x10) << 4); 157 VBE = (cr_data & 0xff) | ((unsigned short) (sr_data & 0x10) << 4);
189 temp = VBE - ((E - 1) & 511); 158 temp = VBE - ((VDE - 1) & 511);
190 B = (temp > 0) ? temp : (temp + 512); 159 B = (temp > 0) ? temp : (temp + 512);
191 160
192 cr_data = XGI_CRT1Table[index].CR[11]; 161 cr_data = XGI_CRT1Table[index].CR[11];
193 162
194 /* Vertical retrace (=sync) end */ 163 /* Vertical retrace (=sync) end */
195 VRE = (cr_data & 0x0f) | ((sr_data & 0x20) >> 1); 164 VRE = (cr_data & 0x0f) | ((sr_data & 0x20) >> 1);
196 temp = VRE - ((E + F - 1) & 31); 165 temp = VRE - ((VDE + F - 1) & 31);
197 C = (temp > 0) ? temp : (temp + 32); 166 C = (temp > 0) ? temp : (temp + 32);
198 167
199 D = B - F - C; 168 D = B - F - C;
@@ -233,13 +202,14 @@ static int XGIfb_mode_rate_to_ddata(struct vb_device_info *XGI_Pr,
233 return 1; 202 return 1;
234} 203}
235 204
236static void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned long BaseAddr) 205void XGIRegInit(struct vb_device_info *XGI_Pr, unsigned long BaseAddr)
237{ 206{
238 XGI_Pr->P3c4 = BaseAddr + 0x14; 207 XGI_Pr->P3c4 = BaseAddr + 0x14;
239 XGI_Pr->P3d4 = BaseAddr + 0x24; 208 XGI_Pr->P3d4 = BaseAddr + 0x24;
240 XGI_Pr->P3c0 = BaseAddr + 0x10; 209 XGI_Pr->P3c0 = BaseAddr + 0x10;
241 XGI_Pr->P3ce = BaseAddr + 0x1e; 210 XGI_Pr->P3ce = BaseAddr + 0x1e;
242 XGI_Pr->P3c2 = BaseAddr + 0x12; 211 XGI_Pr->P3c2 = BaseAddr + 0x12;
212 XGI_Pr->P3cc = BaseAddr + 0x1c;
243 XGI_Pr->P3ca = BaseAddr + 0x1a; 213 XGI_Pr->P3ca = BaseAddr + 0x1a;
244 XGI_Pr->P3c6 = BaseAddr + 0x16; 214 XGI_Pr->P3c6 = BaseAddr + 0x16;
245 XGI_Pr->P3c7 = BaseAddr + 0x17; 215 XGI_Pr->P3c7 = BaseAddr + 0x17;
@@ -1160,22 +1130,10 @@ static int XGIfb_release(struct fb_info *info, int user)
1160 return 0; 1130 return 0;
1161} 1131}
1162 1132
1133/* similar to sisfb_get_cmap_len */
1163static int XGIfb_get_cmap_len(const struct fb_var_screeninfo *var) 1134static int XGIfb_get_cmap_len(const struct fb_var_screeninfo *var)
1164{ 1135{
1165 int rc = 16; 1136 return (var->bits_per_pixel == 8) ? 256 : 16;
1166
1167 switch (var->bits_per_pixel) {
1168 case 8:
1169 rc = 256;
1170 break;
1171 case 16:
1172 rc = 16;
1173 break;
1174 case 32:
1175 rc = 16;
1176 break;
1177 }
1178 return rc;
1179} 1137}
1180 1138
1181static int XGIfb_setcolreg(unsigned regno, unsigned red, unsigned green, 1139static int XGIfb_setcolreg(unsigned regno, unsigned red, unsigned green,
@@ -1362,12 +1320,6 @@ static int XGIfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1362 /* Adapt RGB settings */ 1320 /* Adapt RGB settings */
1363 XGIfb_bpp_to_var(xgifb_info, var); 1321 XGIfb_bpp_to_var(xgifb_info, var);
1364 1322
1365 /* Sanity check for offsets */
1366 if (var->xoffset < 0)
1367 var->xoffset = 0;
1368 if (var->yoffset < 0)
1369 var->yoffset = 0;
1370
1371 if (!XGIfb_ypan) { 1323 if (!XGIfb_ypan) {
1372 if (var->xres != var->xres_virtual) 1324 if (var->xres != var->xres_virtual)
1373 var->xres_virtual = var->xres; 1325 var->xres_virtual = var->xres;
@@ -1402,8 +1354,7 @@ static int XGIfb_pan_display(struct fb_var_screeninfo *var,
1402 return -EINVAL; 1354 return -EINVAL;
1403 1355
1404 if (var->vmode & FB_VMODE_YWRAP) { 1356 if (var->vmode & FB_VMODE_YWRAP) {
1405 if (var->yoffset < 0 || var->yoffset >= info->var.yres_virtual 1357 if (var->yoffset >= info->var.yres_virtual || var->xoffset)
1406 || var->xoffset)
1407 return -EINVAL; 1358 return -EINVAL;
1408 } else if (var->xoffset + info->var.xres > info->var.xres_virtual 1359 } else if (var->xoffset + info->var.xres > info->var.xres_virtual
1409 || var->yoffset + info->var.yres 1360 || var->yoffset + info->var.yres
@@ -1838,7 +1789,7 @@ static int xgifb_probe(struct pci_dev *pdev,
1838 if (!XGIInitNew(pdev)) 1789 if (!XGIInitNew(pdev))
1839 dev_err(&pdev->dev, "XGIInitNew() failed!\n"); 1790 dev_err(&pdev->dev, "XGIInitNew() failed!\n");
1840 1791
1841 xgifb_info->mtrr = (unsigned int) 0; 1792 xgifb_info->mtrr = -1;
1842 1793
1843 xgifb_info->hasVB = HASVB_NONE; 1794 xgifb_info->hasVB = HASVB_NONE;
1844 if ((xgifb_info->chip == XG20) || 1795 if ((xgifb_info->chip == XG20) ||
@@ -1957,6 +1908,7 @@ static int xgifb_probe(struct pci_dev *pdev,
1957 1908
1958 if (xgifb_info->mode_idx < 0) { 1909 if (xgifb_info->mode_idx < 0) {
1959 dev_err(&pdev->dev, "No supported video mode found\n"); 1910 dev_err(&pdev->dev, "No supported video mode found\n");
1911 ret = -EINVAL;
1960 goto error_1; 1912 goto error_1;
1961 } 1913 }
1962 1914
diff --git a/drivers/staging/xgifb/XGIfb.h b/drivers/staging/xgifb/XGIfb.h
index 80547983759b..af50362395d5 100644
--- a/drivers/staging/xgifb/XGIfb.h
+++ b/drivers/staging/xgifb/XGIfb.h
@@ -67,7 +67,7 @@ struct xgifb_video_info {
67 unsigned long mmio_size; 67 unsigned long mmio_size;
68 void __iomem *mmio_vbase; 68 void __iomem *mmio_vbase;
69 unsigned long vga_base; 69 unsigned long vga_base;
70 unsigned long mtrr; 70 int mtrr;
71 71
72 int video_bpp; 72 int video_bpp;
73 int video_cmap_len; 73 int video_cmap_len;
diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index 2b791c10eb15..df127e406952 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -131,22 +131,6 @@ static void XGINew_SetMemoryClock(struct xgi_hw_device_info *HwDeviceExtension,
131 xgifb_reg_set(pVBInfo->P3c4, 131 xgifb_reg_set(pVBInfo->P3c4,
132 0x30, 132 0x30,
133 XGI340_ECLKData[pVBInfo->ram_type].SR30); 133 XGI340_ECLKData[pVBInfo->ram_type].SR30);
134
135 /* When XG42 ECLK = MCLK = 207MHz, Set SR32 D[1:0] = 10b */
136 /* Modify SR32 value, when MCLK=207MHZ, ELCK=250MHz,
137 * Set SR32 D[1:0] = 10b */
138 if (HwDeviceExtension->jChipType == XG42) {
139 if ((pVBInfo->MCLKData[pVBInfo->ram_type].SR28 == 0x1C) &&
140 (pVBInfo->MCLKData[pVBInfo->ram_type].SR29 == 0x01) &&
141 (((XGI340_ECLKData[pVBInfo->ram_type].SR2E == 0x1C) &&
142 (XGI340_ECLKData[pVBInfo->ram_type].SR2F == 0x01)) ||
143 ((XGI340_ECLKData[pVBInfo->ram_type].SR2E == 0x22) &&
144 (XGI340_ECLKData[pVBInfo->ram_type].SR2F == 0x01))))
145 xgifb_reg_set(pVBInfo->P3c4,
146 0x32,
147 ((unsigned char) xgifb_reg_get(
148 pVBInfo->P3c4, 0x32) & 0xFC) | 0x02);
149 }
150} 134}
151 135
152static void XGINew_DDRII_Bootup_XG27( 136static void XGINew_DDRII_Bootup_XG27(
@@ -413,11 +397,24 @@ static void XGINew_DDR2_DefaultRegister(
413 XGINew_DDR2_MRS_XG20(HwDeviceExtension, P3c4, pVBInfo); 397 XGINew_DDR2_MRS_XG20(HwDeviceExtension, P3c4, pVBInfo);
414} 398}
415 399
400static void XGI_SetDRAM_Helper(unsigned long P3d4, u8 seed, u8 temp2, u8 reg,
401 u8 shift_factor, u8 mask1, u8 mask2)
402{
403 u8 j;
404 for (j = 0; j < 4; j++) {
405 temp2 |= (((seed >> (2 * j)) & 0x03) << shift_factor);
406 xgifb_reg_set(P3d4, reg, temp2);
407 xgifb_reg_get(P3d4, reg);
408 temp2 &= mask1;
409 temp2 += mask2;
410 }
411}
412
416static void XGINew_SetDRAMDefaultRegister340( 413static void XGINew_SetDRAMDefaultRegister340(
417 struct xgi_hw_device_info *HwDeviceExtension, 414 struct xgi_hw_device_info *HwDeviceExtension,
418 unsigned long Port, struct vb_device_info *pVBInfo) 415 unsigned long Port, struct vb_device_info *pVBInfo)
419{ 416{
420 unsigned char temp, temp1, temp2, temp3, i, j, k; 417 unsigned char temp, temp1, temp2, temp3, j, k;
421 418
422 unsigned long P3d4 = Port, P3c4 = Port - 0x10; 419 unsigned long P3d4 = Port, P3c4 = Port - 0x10;
423 420
@@ -426,54 +423,18 @@ static void XGINew_SetDRAMDefaultRegister340(
426 xgifb_reg_set(P3d4, 0x69, pVBInfo->CR40[6][pVBInfo->ram_type]); 423 xgifb_reg_set(P3d4, 0x69, pVBInfo->CR40[6][pVBInfo->ram_type]);
427 xgifb_reg_set(P3d4, 0x6A, pVBInfo->CR40[7][pVBInfo->ram_type]); 424 xgifb_reg_set(P3d4, 0x6A, pVBInfo->CR40[7][pVBInfo->ram_type]);
428 425
429 temp2 = 0; 426 /* CR6B DQS fine tune delay */
430 for (i = 0; i < 4; i++) { 427 temp = 0xaa;
431 /* CR6B DQS fine tune delay */ 428 XGI_SetDRAM_Helper(P3d4, temp, 0, 0x6B, 2, 0xF0, 0x10);
432 temp = XGI340_CR6B[pVBInfo->ram_type][i];
433 for (j = 0; j < 4; j++) {
434 temp1 = ((temp >> (2 * j)) & 0x03) << 2;
435 temp2 |= temp1;
436 xgifb_reg_set(P3d4, 0x6B, temp2);
437 /* Insert read command for delay */
438 xgifb_reg_get(P3d4, 0x6B);
439 temp2 &= 0xF0;
440 temp2 += 0x10;
441 }
442 }
443 429
444 temp2 = 0; 430 /* CR6E DQM fine tune delay */
445 for (i = 0; i < 4; i++) { 431 XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6E, 2, 0xF0, 0x10);
446 /* CR6E DQM fine tune delay */
447 temp = 0;
448 for (j = 0; j < 4; j++) {
449 temp1 = ((temp >> (2 * j)) & 0x03) << 2;
450 temp2 |= temp1;
451 xgifb_reg_set(P3d4, 0x6E, temp2);
452 /* Insert read command for delay */
453 xgifb_reg_get(P3d4, 0x6E);
454 temp2 &= 0xF0;
455 temp2 += 0x10;
456 }
457 }
458 432
459 temp3 = 0; 433 temp3 = 0;
460 for (k = 0; k < 4; k++) { 434 for (k = 0; k < 4; k++) {
461 /* CR6E_D[1:0] select channel */ 435 /* CR6E_D[1:0] select channel */
462 xgifb_reg_and_or(P3d4, 0x6E, 0xFC, temp3); 436 xgifb_reg_and_or(P3d4, 0x6E, 0xFC, temp3);
463 temp2 = 0; 437 XGI_SetDRAM_Helper(P3d4, 0, 0, 0x6F, 0, 0xF8, 0x08);
464 for (i = 0; i < 8; i++) {
465 /* CR6F DQ fine tune delay */
466 temp = 0;
467 for (j = 0; j < 4; j++) {
468 temp1 = (temp >> (2 * j)) & 0x03;
469 temp2 |= temp1;
470 xgifb_reg_set(P3d4, 0x6F, temp2);
471 /* Insert read command for delay */
472 xgifb_reg_get(P3d4, 0x6F);
473 temp2 &= 0xF8;
474 temp2 += 0x08;
475 }
476 }
477 temp3 += 0x01; 438 temp3 += 0x01;
478 } 439 }
479 440
@@ -486,15 +447,7 @@ static void XGINew_SetDRAMDefaultRegister340(
486 447
487 temp2 = 0x80; 448 temp2 = 0x80;
488 /* CR89 terminator type select */ 449 /* CR89 terminator type select */
489 temp = 0; 450 XGI_SetDRAM_Helper(P3d4, 0, temp2, 0x89, 0, 0xF0, 0x10);
490 for (j = 0; j < 4; j++) {
491 temp1 = (temp >> (2 * j)) & 0x03;
492 temp2 |= temp1;
493 xgifb_reg_set(P3d4, 0x89, temp2);
494 xgifb_reg_get(P3d4, 0x89); /* Insert read command for delay */
495 temp2 &= 0xF0;
496 temp2 += 0x10;
497 }
498 451
499 temp = 0; 452 temp = 0;
500 temp1 = temp & 0x03; 453 temp1 = temp & 0x03;
@@ -1286,36 +1239,14 @@ unsigned char XGIInitNew(struct pci_dev *pdev)
1286 1239
1287 pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress; 1240 pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress;
1288 1241
1289 pVBInfo->BaseAddr = xgifb_info->vga_base;
1290
1291 if (pVBInfo->FBAddr == NULL) { 1242 if (pVBInfo->FBAddr == NULL) {
1292 dev_dbg(&pdev->dev, "pVBInfo->FBAddr == 0\n"); 1243 dev_dbg(&pdev->dev, "pVBInfo->FBAddr == 0\n");
1293 return 0; 1244 return 0;
1294 } 1245 }
1295 if (pVBInfo->BaseAddr == 0) {
1296 dev_dbg(&pdev->dev, "pVBInfo->BaseAddr == 0\n");
1297 return 0;
1298 }
1299 1246
1300 outb(0x67, (pVBInfo->BaseAddr + 0x12)); /* 3c2 <- 67 ,ynlai */ 1247 XGIRegInit(pVBInfo, xgifb_info->vga_base);
1301 1248
1302 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14; 1249 outb(0x67, pVBInfo->P3c2);
1303 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
1304 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
1305 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
1306 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
1307 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
1308 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
1309 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
1310 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
1311 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
1312 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
1313 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
1314 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
1315 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
1316 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
1317 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
1318 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
1319 1250
1320 if (HwDeviceExtension->jChipType < XG20) 1251 if (HwDeviceExtension->jChipType < XG20)
1321 /* Run XGI_GetVBType before InitTo330Pointer */ 1252 /* Run XGI_GetVBType before InitTo330Pointer */
@@ -1410,7 +1341,7 @@ unsigned char XGIInitNew(struct pci_dev *pdev)
1410 xgifb_reg_and_or(pVBInfo->Part0Port, 0x3F, 0xEF, 0x00); 1341 xgifb_reg_and_or(pVBInfo->Part0Port, 0x3F, 0xEF, 0x00);
1411 xgifb_reg_set(pVBInfo->Part1Port, 0x00, 0x00); 1342 xgifb_reg_set(pVBInfo->Part1Port, 0x00, 0x00);
1412 /* chk if BCLK>=100MHz */ 1343 /* chk if BCLK>=100MHz */
1413 temp1 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x7B); 1344 temp1 = xgifb_reg_get(pVBInfo->P3d4, 0x7B);
1414 temp = (unsigned char) ((temp1 >> 4) & 0x0F); 1345 temp = (unsigned char) ((temp1 >> 4) & 0x0F);
1415 1346
1416 xgifb_reg_set(pVBInfo->Part1Port, 1347 xgifb_reg_set(pVBInfo->Part1Port,
diff --git a/drivers/staging/xgifb/vb_init.h b/drivers/staging/xgifb/vb_init.h
index d54898322548..24573026a7c0 100644
--- a/drivers/staging/xgifb/vb_init.h
+++ b/drivers/staging/xgifb/vb_init.h
@@ -1,5 +1,6 @@
1#ifndef _VBINIT_ 1#ifndef _VBINIT_
2#define _VBINIT_ 2#define _VBINIT_
3extern unsigned char XGIInitNew(struct pci_dev *pdev); 3extern unsigned char XGIInitNew(struct pci_dev *pdev);
4extern void XGIRegInit(struct vb_device_info *, unsigned long);
4#endif 5#endif
5 6
diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c
index d723a2571995..dfa5303379e9 100644
--- a/drivers/staging/xgifb/vb_setmode.c
+++ b/drivers/staging/xgifb/vb_setmode.c
@@ -2,6 +2,7 @@
2#include "XGIfb.h" 2#include "XGIfb.h"
3 3
4#include "vb_def.h" 4#include "vb_def.h"
5#include "vb_init.h"
5#include "vb_util.h" 6#include "vb_util.h"
6#include "vb_table.h" 7#include "vb_table.h"
7#include "vb_setmode.h" 8#include "vb_setmode.h"
@@ -63,29 +64,15 @@ static void XGI_SetSeqRegs(unsigned short ModeNo,
63 unsigned short ModeIdIndex, 64 unsigned short ModeIdIndex,
64 struct vb_device_info *pVBInfo) 65 struct vb_device_info *pVBInfo)
65{ 66{
66 unsigned char tempah, SRdata; 67 unsigned char SRdata, i;
67 unsigned short i, modeflag;
68
69 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
70 68
71 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */ 69 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
72 tempah = XGI330_StandTable.SR[0];
73
74 i = XGI_SetCRT2ToLCDA;
75 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
76 tempah |= 0x01;
77 } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
78 if (pVBInfo->VBInfo & SetInSlaveMode)
79 tempah |= 0x01;
80 }
81 70
82 tempah |= 0x20; /* screen off */ 71 for (i = 0; i < 4; i++) {
83 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */ 72 /* Get SR1,2,3,4 from file */
84 73 /* SR1 is with screen off 0x20 */
85 for (i = 02; i <= 04; i++) { 74 SRdata = XGI330_StandTable.SR[i];
86 /* Get SR2,3,4 from file */ 75 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
87 SRdata = XGI330_StandTable.SR[i - 1];
88 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
89 } 76 }
90} 77}
91 78
@@ -95,7 +82,7 @@ static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
95 unsigned char CRTCdata; 82 unsigned char CRTCdata;
96 unsigned short i; 83 unsigned short i;
97 84
98 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); 85 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
99 CRTCdata &= 0x7f; 86 CRTCdata &= 0x7f;
100 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */ 87 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
101 88
@@ -152,7 +139,7 @@ static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
152 } 139 }
153 140
154 if (pVBInfo->ModeType > ModeVGA) { 141 if (pVBInfo->ModeType > ModeVGA) {
155 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05); 142 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
156 GRdata &= 0xBF; /* 256 color disable */ 143 GRdata &= 0xBF; /* 256 color disable */
157 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata); 144 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
158 } 145 }
@@ -300,7 +287,7 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
300 unsigned short i, j; 287 unsigned short i, j;
301 288
302 /* unlock cr0-7 */ 289 /* unlock cr0-7 */
303 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); 290 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
304 data &= 0x7F; 291 data &= 0x7F;
305 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); 292 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
306 293
@@ -317,7 +304,7 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
317 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data); 304 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
318 } 305 }
319 306
320 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e); 307 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
321 j &= 0x1F; 308 j &= 0x1F;
322 data = pVBInfo->TimingH.data[7]; 309 data = pVBInfo->TimingH.data[7];
323 data &= 0xE0; 310 data &= 0xE0;
@@ -325,17 +312,16 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
325 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data); 312 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
326 313
327 if (HwDeviceExtension->jChipType >= XG20) { 314 if (HwDeviceExtension->jChipType >= XG20) {
328 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04); 315 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
329 data = data - 1; 316 data = data - 1;
330 xgifb_reg_set(pVBInfo->P3d4, 0x04, data); 317 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
331 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05); 318 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
332 data1 = data; 319 data1 = data;
333 data1 &= 0xE0; 320 data1 &= 0xE0;
334 data &= 0x1F; 321 data &= 0x1F;
335 if (data == 0) { 322 if (data == 0) {
336 pushax = data; 323 pushax = data;
337 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 324 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
338 0x0c);
339 data &= 0xFB; 325 data &= 0xFB;
340 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data); 326 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
341 data = pushax; 327 data = pushax;
@@ -343,7 +329,7 @@ static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
343 data = data - 1; 329 data = data - 1;
344 data |= data1; 330 data |= data1;
345 xgifb_reg_set(pVBInfo->P3d4, 0x05, data); 331 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
346 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e); 332 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
347 data = data >> 5; 333 data = data >> 5;
348 data = data + 3; 334 data = data + 3;
349 if (data > 7) 335 if (data > 7)
@@ -375,7 +361,7 @@ static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
375 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data); 361 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
376 } 362 }
377 363
378 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a); 364 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
379 j &= 0xC0; 365 j &= 0xC0;
380 data = pVBInfo->TimingV.data[6]; 366 data = pVBInfo->TimingV.data[6];
381 data &= 0x3F; 367 data &= 0x3F;
@@ -391,7 +377,7 @@ static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
391 if (i) 377 if (i)
392 data |= 0x80; 378 data |= 0x80;
393 379
394 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09); 380 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
395 j &= 0x5F; 381 j &= 0x5F;
396 data |= j; 382 data |= j;
397 xgifb_reg_set(pVBInfo->P3d4, 0x09, data); 383 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
@@ -409,7 +395,7 @@ static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
409 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 395 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
410 index = index & IndexMask; 396 index = index & IndexMask;
411 397
412 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); 398 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
413 data &= 0x7F; 399 data &= 0x7F;
414 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */ 400 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
415 401
@@ -640,10 +626,7 @@ static void xgifb_set_lcd(int chip_id,
640 unsigned short RefreshRateTableIndex, 626 unsigned short RefreshRateTableIndex,
641 unsigned short ModeNo) 627 unsigned short ModeNo)
642{ 628{
643 unsigned short Data, Temp; 629 unsigned short temp;
644 unsigned short XGI_P3cc;
645
646 XGI_P3cc = pVBInfo->P3cc;
647 630
648 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00); 631 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
649 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00); 632 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
@@ -651,8 +634,8 @@ static void xgifb_set_lcd(int chip_id,
651 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00); 634 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
652 635
653 if (chip_id == XG27) { 636 if (chip_id == XG27) {
654 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); 637 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
655 if ((Temp & 0x03) == 0) { /* dual 12 */ 638 if ((temp & 0x03) == 0) { /* dual 12 */
656 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13); 639 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
657 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13); 640 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
658 } 641 }
@@ -661,8 +644,8 @@ static void xgifb_set_lcd(int chip_id,
661 if (chip_id == XG27) { 644 if (chip_id == XG27) {
662 XGI_SetXG27FPBits(pVBInfo); 645 XGI_SetXG27FPBits(pVBInfo);
663 } else { 646 } else {
664 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); 647 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
665 if (Temp & 0x01) { 648 if (temp & 0x01) {
666 /* 18 bits FP */ 649 /* 18 bits FP */
667 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40); 650 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
668 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40); 651 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
@@ -674,11 +657,11 @@ static void xgifb_set_lcd(int chip_id,
674 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */ 657 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
675 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */ 658 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
676 659
677 Data = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag; 660 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
678 if (Data & 0x4000) 661 if (temp & 0x4000)
679 /* Hsync polarity */ 662 /* Hsync polarity */
680 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20); 663 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
681 if (Data & 0x8000) 664 if (temp & 0x8000)
682 /* Vsync polarity */ 665 /* Vsync polarity */
683 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80); 666 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
684} 667}
@@ -757,8 +740,8 @@ static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
757 tempax -= 1; 740 tempax -= 1;
758 tempbx -= 1; 741 tempbx -= 1;
759 tempcx = tempax; 742 tempcx = tempax;
760 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); 743 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
761 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); 744 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
762 data &= 0x7F; 745 data &= 0x7F;
763 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */ 746 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
764 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff)); 747 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
@@ -775,7 +758,7 @@ static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
775 tempax |= 0x40; 758 tempax |= 0x40;
776 759
777 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax); 760 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
778 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07); 761 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
779 data &= 0xFF; 762 data &= 0xFF;
780 tempax = 0; 763 tempax = 0;
781 764
@@ -876,62 +859,47 @@ static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
876 struct xgi_hw_device_info *HwDeviceExtension, 859 struct xgi_hw_device_info *HwDeviceExtension,
877 struct vb_device_info *pVBInfo) 860 struct vb_device_info *pVBInfo)
878{ 861{
879 unsigned short CRT2Index, VCLKIndex; 862 unsigned short VCLKIndex, modeflag;
880 unsigned short modeflag, resinfo;
881 863
882 /* si+Ext_ResInfo */ 864 /* si+Ext_ResInfo */
883 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 865 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
884 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
885 CRT2Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
886 866
887 if (pVBInfo->IF_DEF_LVDS == 0) { 867 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
888 CRT2Index = CRT2Index >> 6; /* for LCD */ 868 if (pVBInfo->LCDResInfo != Panel_1024x768)
889 if (pVBInfo->VBInfo & 869 /* LCDXlat2VCLK */
890 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/ 870 VCLKIndex = VCLK108_2_315 + 5;
891 if (pVBInfo->LCDResInfo != Panel_1024x768) 871 else
892 /* LCDXlat2VCLK */ 872 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
893 VCLKIndex = VCLK108_2_315 + 5; 873 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
894 else 874 if (pVBInfo->SetFlag & RPLLDIV2XO)
895 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */ 875 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
896 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) { 876 else
897 if (pVBInfo->SetFlag & RPLLDIV2XO) 877 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
898 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
899 else
900 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
901 878
902 if (pVBInfo->SetFlag & TVSimuMode) { 879 if (pVBInfo->SetFlag & TVSimuMode) {
903 if (modeflag & Charx8Dot) { 880 if (modeflag & Charx8Dot) {
904 VCLKIndex = TVCLKBASE_315_25 + 881 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
905 HiTVSimuVCLK; 882 } else {
906 } else { 883 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
907 VCLKIndex = TVCLKBASE_315_25 +
908 HiTVTextVCLK;
909 }
910 } 884 }
885 }
911 886
912 /* 301lv */ 887 /* 301lv */
913 if (pVBInfo->VBType & VB_SIS301LV) { 888 if (pVBInfo->VBType & VB_SIS301LV) {
914 if (pVBInfo->SetFlag & RPLLDIV2XO)
915 VCLKIndex = YPbPr525iVCLK_2;
916 else
917 VCLKIndex = YPbPr525iVCLK;
918 }
919 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
920 if (pVBInfo->SetFlag & RPLLDIV2XO) 889 if (pVBInfo->SetFlag & RPLLDIV2XO)
921 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2; 890 VCLKIndex = YPbPr525iVCLK_2;
922 else 891 else
923 VCLKIndex = TVCLKBASE_315_25 + TVVCLK; 892 VCLKIndex = YPbPr525iVCLK;
924 } else { /* for CRT2 */
925 /* di+Ext_CRTVCLK */
926 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].
927 Ext_CRTVCLK;
928 VCLKIndex &= IndexMask;
929 } 893 }
930 } else if ((pVBInfo->LCDResInfo == Panel_800x600) || 894 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
931 (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */ 895 if (pVBInfo->SetFlag & RPLLDIV2XO)
932 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */ 896 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
933 } else { 897 else
934 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */ 898 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
899 } else { /* for CRT2 */
900 /* di+Ext_CRTVCLK */
901 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
902 VCLKIndex &= IndexMask;
935 } 903 }
936 904
937 return VCLKIndex; 905 return VCLKIndex;
@@ -1103,10 +1071,8 @@ static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1103 data = 0x0048; 1071 data = 0x0048;
1104 } 1072 }
1105 1073
1106 data2 = data & 0x00FF; 1074 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1107 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2); 1075 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
1108 data2 = (data & 0xFF00) >> 8;
1109 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
1110 1076
1111 if (modeflag & HalfDCLK) 1077 if (modeflag & HalfDCLK)
1112 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08); 1078 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
@@ -1389,14 +1355,10 @@ static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
1389 struct xgi_hw_device_info *HwDeviceExtension, 1355 struct xgi_hw_device_info *HwDeviceExtension,
1390 struct vb_device_info *pVBInfo) 1356 struct vb_device_info *pVBInfo)
1391{ 1357{
1392 unsigned char index;
1393 unsigned short i; 1358 unsigned short i;
1394 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL; 1359 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1395 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL; 1360 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
1396 1361
1397 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1398 index = index & IndexMask;
1399
1400 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { 1362 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
1401 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex, 1363 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
1402 RefreshRateTableIndex, pVBInfo); 1364 RefreshRateTableIndex, pVBInfo);
@@ -1496,18 +1458,11 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
1496{ 1458{
1497 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag; 1459 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1498 unsigned long temp, temp1, temp2, temp3, push3; 1460 unsigned long temp, temp1, temp2, temp3, push3;
1499 struct XGI_LCDDesStruct const *LCDPtr = NULL;
1500 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL; 1461 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
1501 1462
1502 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 1463 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1503 if (pVBInfo->LCDInfo & EnableScalingLCD) 1464 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, ModeIdIndex,
1504 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo, 1465 RefreshRateTableIndex, pVBInfo);
1505 ModeIdIndex, RefreshRateTableIndex,
1506 pVBInfo);
1507 else
1508 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1509 ModeIdIndex, RefreshRateTableIndex,
1510 pVBInfo);
1511 1466
1512 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo); 1467 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1513 push1 = tempbx; 1468 push1 = tempbx;
@@ -1539,10 +1494,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
1539 1494
1540 tempax = pVBInfo->HT; 1495 tempax = pVBInfo->HT;
1541 1496
1542 if (pVBInfo->LCDInfo & EnableScalingLCD) 1497 tempbx = LCDPtr1->LCDHDES;
1543 tempbx = LCDPtr1->LCDHDES;
1544 else
1545 tempbx = LCDPtr->LCDHDES;
1546 1498
1547 tempcx = pVBInfo->HDE; 1499 tempcx = pVBInfo->HDE;
1548 tempbx = tempbx & 0x0fff; 1500 tempbx = tempbx & 0x0fff;
@@ -1563,10 +1515,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
1563 1515
1564 tempax = pVBInfo->HT; 1516 tempax = pVBInfo->HT;
1565 1517
1566 if (pVBInfo->LCDInfo & EnableScalingLCD) 1518 tempbx = LCDPtr1->LCDHRS;
1567 tempbx = LCDPtr1->LCDHRS;
1568 else
1569 tempbx = LCDPtr->LCDHRS;
1570 1519
1571 tempcx = push2; 1520 tempcx = push2;
1572 1521
@@ -1591,10 +1540,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
1591 (unsigned short) (tempbx & 0xff)); 1540 (unsigned short) (tempbx & 0xff));
1592 1541
1593 tempax = pVBInfo->VT; 1542 tempax = pVBInfo->VT;
1594 if (pVBInfo->LCDInfo & EnableScalingLCD) 1543 tempbx = LCDPtr1->LCDVDES;
1595 tempbx = LCDPtr1->LCDVDES;
1596 else
1597 tempbx = LCDPtr->LCDVDES;
1598 tempcx = pVBInfo->VDE; 1544 tempcx = pVBInfo->VDE;
1599 1545
1600 tempbx = tempbx & 0x0fff; 1546 tempbx = tempbx & 0x0fff;
@@ -1615,10 +1561,7 @@ static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
1615 | tempbx)); 1561 | tempbx));
1616 1562
1617 tempax = pVBInfo->VT; 1563 tempax = pVBInfo->VT;
1618 if (pVBInfo->LCDInfo & EnableScalingLCD) 1564 tempbx = LCDPtr1->LCDVRS;
1619 tempbx = LCDPtr1->LCDVRS;
1620 else
1621 tempbx = LCDPtr->LCDVRS;
1622 1565
1623 tempcx = push1; 1566 tempcx = push1;
1624 1567
@@ -1835,14 +1778,7 @@ static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1835 } 1778 }
1836 } /* {End of VB} */ 1779 } /* {End of VB} */
1837 1780
1838 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02)); 1781 inb((pVBInfo->P3ca + 0x02));
1839 tempal = tempal >> 2;
1840 tempal &= 0x03;
1841
1842 /* for Dot8 Scaling LCD */
1843 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
1844 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1845
1846 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK; 1782 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1847 return tempal; 1783 return tempal;
1848} 1784}
@@ -2050,40 +1986,28 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2050 1986
2051 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38); 1987 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
2052 1988
2053 if (pVBInfo->IF_DEF_LVDS == 0) { 1989 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
2054 if (pVBInfo->VBType & 1990 VB_XGI301C)) {
2055 (VB_SIS302B | 1991 if (temp & EnableDualEdge) {
2056 VB_SIS301LV | 1992 tempbx |= SetCRT2ToDualEdge;
2057 VB_SIS302LV | 1993 if (temp & SetToLCDA)
2058 VB_XGI301C)) { 1994 tempbx |= XGI_SetCRT2ToLCDA;
2059 if (temp & EnableDualEdge) {
2060 tempbx |= SetCRT2ToDualEdge;
2061 if (temp & SetToLCDA)
2062 tempbx |= XGI_SetCRT2ToLCDA;
2063 }
2064 } 1995 }
2065 } 1996 }
2066 1997
2067 if (pVBInfo->IF_DEF_YPbPr == 1) { 1998 if (pVBInfo->IF_DEF_YPbPr == 1) {
2068 if (((pVBInfo->IF_DEF_LVDS == 0) && 1999 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
2069 ((pVBInfo->VBType & VB_SIS301LV) ||
2070 (pVBInfo->VBType & VB_SIS302LV) ||
2071 (pVBInfo->VBType & VB_XGI301C)))) {
2072 if (temp & SetYPbPr) { 2000 if (temp & SetYPbPr) {
2073 if (pVBInfo->IF_DEF_HiVision == 1) { 2001 if (pVBInfo->IF_DEF_HiVision == 1) {
2074 /* shampoo add for new 2002 /* shampoo add for new scratch */
2075 * scratch */ 2003 temp = xgifb_reg_get(pVBInfo->P3d4,
2076 temp = xgifb_reg_get( 2004 0x35);
2077 pVBInfo->P3d4,
2078 0x35);
2079 temp &= YPbPrMode; 2005 temp &= YPbPrMode;
2080 tempbx |= SetCRT2ToHiVision; 2006 tempbx |= SetCRT2ToHiVision;
2081 2007
2082 if (temp != YPbPrMode1080i) { 2008 if (temp != YPbPrMode1080i) {
2083 tempbx &= 2009 tempbx &= (~SetCRT2ToHiVision);
2084 (~SetCRT2ToHiVision); 2010 tempbx |= SetCRT2ToYPbPr525750;
2085 tempbx |=
2086 SetCRT2ToYPbPr525750;
2087 } 2011 }
2088 } 2012 }
2089 } 2013 }
@@ -2092,19 +2016,15 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2092 2016
2093 tempax = push; /* restore CR31 */ 2017 tempax = push; /* restore CR31 */
2094 2018
2095 if (pVBInfo->IF_DEF_LVDS == 0) { 2019 if (pVBInfo->IF_DEF_YPbPr == 1) {
2096 if (pVBInfo->IF_DEF_YPbPr == 1) { 2020 if (pVBInfo->IF_DEF_HiVision == 1)
2097 if (pVBInfo->IF_DEF_HiVision == 1) 2021 temp = 0x09FC;
2098 temp = 0x09FC; 2022 else
2099 else 2023 temp = 0x097C;
2100 temp = 0x097C; 2024 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2101 } else if (pVBInfo->IF_DEF_HiVision == 1) { 2025 temp = 0x01FC;
2102 temp = 0x01FC; 2026 } else {
2103 } else { 2027 temp = 0x017C;
2104 temp = 0x017C;
2105 }
2106 } else { /* 3rd party chip */
2107 temp = SetCRT2ToLCD;
2108 } 2028 }
2109 2029
2110 if (!(tempbx & temp)) { 2030 if (!(tempbx & temp)) {
@@ -2115,14 +2035,11 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2115 if (!(pVBInfo->VBType & VB_NoLCD)) { 2035 if (!(pVBInfo->VBType & VB_NoLCD)) {
2116 if (tempbx & XGI_SetCRT2ToLCDA) { 2036 if (tempbx & XGI_SetCRT2ToLCDA) {
2117 if (tempbx & SetSimuScanMode) 2037 if (tempbx & SetSimuScanMode)
2118 tempbx &= (~(SetCRT2ToLCD | 2038 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2119 SetCRT2ToRAMDAC |
2120 SwitchCRT2)); 2039 SwitchCRT2));
2121 else 2040 else
2122 tempbx &= (~(SetCRT2ToLCD | 2041 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
2123 SetCRT2ToRAMDAC | 2042 SetCRT2ToTV | SwitchCRT2));
2124 SetCRT2ToTV |
2125 SwitchCRT2));
2126 } 2043 }
2127 } 2044 }
2128 2045
@@ -2131,49 +2048,38 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2131 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) { 2048 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2132 if (pVBInfo->IF_DEF_CRT2Monitor == 1) { 2049 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2133 if (tempbx & SetCRT2ToRAMDAC) { 2050 if (tempbx & SetCRT2ToRAMDAC) {
2134 tempbx &= (0xFF00 | 2051 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
2135 SetCRT2ToRAMDAC | 2052 SwitchCRT2 | SetSimuScanMode);
2136 SwitchCRT2 |
2137 SetSimuScanMode);
2138 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750)); 2053 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2139 } 2054 }
2140 } else { 2055 } else {
2141 tempbx &= (~(SetCRT2ToRAMDAC | 2056 tempbx &= (~(SetCRT2ToRAMDAC | SetCRT2ToLCD |
2142 SetCRT2ToLCD |
2143 SetCRT2ToTV)); 2057 SetCRT2ToTV));
2144 } 2058 }
2145 } 2059 }
2146 2060
2147 if (!(pVBInfo->VBType & VB_NoLCD)) { 2061 if (!(pVBInfo->VBType & VB_NoLCD)) {
2148 if (tempbx & SetCRT2ToLCD) { 2062 if (tempbx & SetCRT2ToLCD) {
2149 tempbx &= (0xFF00 | 2063 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
2150 SetCRT2ToLCD |
2151 SwitchCRT2 |
2152 SetSimuScanMode); 2064 SetSimuScanMode);
2153 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750)); 2065 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2154 } 2066 }
2155 } 2067 }
2156 2068
2157 if (tempbx & SetCRT2ToSCART) { 2069 if (tempbx & SetCRT2ToSCART) {
2158 tempbx &= (0xFF00 | 2070 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
2159 SetCRT2ToSCART |
2160 SwitchCRT2 |
2161 SetSimuScanMode); 2071 SetSimuScanMode);
2162 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750)); 2072 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2163 } 2073 }
2164 2074
2165 if (pVBInfo->IF_DEF_YPbPr == 1) { 2075 if (pVBInfo->IF_DEF_YPbPr == 1) {
2166 if (tempbx & SetCRT2ToYPbPr525750) 2076 if (tempbx & SetCRT2ToYPbPr525750)
2167 tempbx &= (0xFF00 | 2077 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
2168 SwitchCRT2 |
2169 SetSimuScanMode);
2170 } 2078 }
2171 2079
2172 if (pVBInfo->IF_DEF_HiVision == 1) { 2080 if (pVBInfo->IF_DEF_HiVision == 1) {
2173 if (tempbx & SetCRT2ToHiVision) 2081 if (tempbx & SetCRT2ToHiVision)
2174 tempbx &= (0xFF00 | 2082 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
2175 SetCRT2ToHiVision |
2176 SwitchCRT2 |
2177 SetSimuScanMode); 2083 SetSimuScanMode);
2178 } 2084 }
2179 2085
@@ -2183,19 +2089,15 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2183 } 2089 }
2184 2090
2185 if (!(tempbx & DisableCRT2Display)) { 2091 if (!(tempbx & DisableCRT2Display)) {
2186 if ((!(tempbx & DriverMode)) || 2092 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
2187 (!(modeflag & CRT2Mode))) {
2188 if (!(tempbx & XGI_SetCRT2ToLCDA)) 2093 if (!(tempbx & XGI_SetCRT2ToLCDA))
2189 tempbx |= (SetInSlaveMode | 2094 tempbx |= (SetInSlaveMode | SetSimuScanMode);
2190 SetSimuScanMode);
2191 } 2095 }
2192 2096
2193 /* LCD+TV can't support in slave mode 2097 /* LCD+TV can't support in slave mode
2194 * (Force LCDA+TV->LCDB) */ 2098 * (Force LCDA+TV->LCDB) */
2195 if ((tempbx & SetInSlaveMode) && 2099 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2196 (tempbx & XGI_SetCRT2ToLCDA)) { 2100 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
2197 tempbx ^= (SetCRT2ToLCD |
2198 XGI_SetCRT2ToLCDA |
2199 SetCRT2ToDualEdge); 2101 SetCRT2ToDualEdge);
2200 pVBInfo->SetFlag |= ReserveTVOption; 2102 pVBInfo->SetFlag |= ReserveTVOption;
2201 } 2103 }
@@ -2207,36 +2109,28 @@ static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2207static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex, 2109static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2208 struct vb_device_info *pVBInfo) 2110 struct vb_device_info *pVBInfo)
2209{ 2111{
2210 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1; 2112 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
2211
2212 tempbx = 0;
2213 resinfo = 0;
2214 2113
2215 if (pVBInfo->VBInfo & SetCRT2ToTV) { 2114 if (pVBInfo->VBInfo & SetCRT2ToTV) {
2216 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 2115 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2217 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; 2116 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2218 2117
2219 if (pVBInfo->VBInfo & SetCRT2ToTV) { 2118 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2220 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35); 2119 if (tempbx & TVSetPAL) {
2221 tempbx = temp; 2120 tempbx &= (SetCHTVOverScan |
2222 if (tempbx & TVSetPAL) { 2121 TVSetPALM |
2223 tempbx &= (SetCHTVOverScan | 2122 TVSetPALN |
2224 TVSetPALM | 2123 TVSetPAL);
2225 TVSetPALN | 2124 if (tempbx & TVSetPALM)
2226 TVSetPAL); 2125 /* set to NTSC if PAL-M */
2227 if (tempbx & TVSetPALM) 2126 tempbx &= ~TVSetPAL;
2228 /* set to NTSC if PAL-M */ 2127 } else
2229 tempbx &= ~TVSetPAL; 2128 tempbx &= (SetCHTVOverScan |
2230 } else 2129 TVSetNTSCJ |
2231 tempbx &= (SetCHTVOverScan | 2130 TVSetPAL);
2232 TVSetNTSCJ |
2233 TVSetPAL);
2234 }
2235 2131
2236 if (pVBInfo->IF_DEF_LVDS == 0) { 2132 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2237 if (pVBInfo->VBInfo & SetCRT2ToSCART) 2133 tempbx |= TVSetPAL;
2238 tempbx |= TVSetPAL;
2239 }
2240 2134
2241 if (pVBInfo->IF_DEF_YPbPr == 1) { 2135 if (pVBInfo->IF_DEF_YPbPr == 1) {
2242 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) { 2136 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
@@ -2258,33 +2152,26 @@ static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2258 tempbx = tempbx | TVSetHiVision | TVSetPAL; 2152 tempbx = tempbx | TVSetHiVision | TVSetPAL;
2259 } 2153 }
2260 2154
2261 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */ 2155 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2262 if ((pVBInfo->VBInfo & SetInSlaveMode) && 2156 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2263 (!(pVBInfo->VBInfo & SetNotSimuMode))) 2157 tempbx |= TVSimuMode;
2264 tempbx |= TVSimuMode;
2265 2158
2266 if (!(tempbx & TVSetPAL) && 2159 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2267 (modeflag > 13) && 2160 /* NTSC 1024x768, */
2268 (resinfo == 8)) /* NTSC 1024x768, */ 2161 tempbx |= NTSC1024x768;
2269 tempbx |= NTSC1024x768;
2270 2162
2271 tempbx |= RPLLDIV2XO; 2163 tempbx |= RPLLDIV2XO;
2272 2164
2273 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { 2165 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2274 if (pVBInfo->VBInfo & SetInSlaveMode) 2166 if (pVBInfo->VBInfo & SetInSlaveMode)
2275 tempbx &= (~RPLLDIV2XO); 2167 tempbx &= (~RPLLDIV2XO);
2276 } else if (tempbx & 2168 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2277 (TVSetYPbPr525p | TVSetYPbPr750p)) { 2169 tempbx &= (~RPLLDIV2XO);
2278 tempbx &= (~RPLLDIV2XO); 2170 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2279 } else if (!(pVBInfo->VBType & 2171 VB_SIS301LV | VB_SIS302LV |
2280 (VB_SIS301B | 2172 VB_XGI301C))) {
2281 VB_SIS302B | 2173 if (tempbx & TVSimuMode)
2282 VB_SIS301LV | 2174 tempbx &= (~RPLLDIV2XO);
2283 VB_SIS302LV |
2284 VB_XGI301C))) {
2285 if (tempbx & TVSimuMode)
2286 tempbx &= (~RPLLDIV2XO);
2287 }
2288 } 2175 }
2289 } 2176 }
2290 pVBInfo->TVInfo = tempbx; 2177 pVBInfo->TVInfo = tempbx;
@@ -2293,13 +2180,12 @@ static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
2293static unsigned char XGI_GetLCDInfo(unsigned short ModeNo, 2180static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2294 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo) 2181 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
2295{ 2182{
2296 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex; 2183 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
2297 2184
2298 pVBInfo->LCDResInfo = 0; 2185 pVBInfo->LCDResInfo = 0;
2299 pVBInfo->LCDTypeInfo = 0; 2186 pVBInfo->LCDTypeInfo = 0;
2300 pVBInfo->LCDInfo = 0; 2187 pVBInfo->LCDInfo = 0;
2301 2188
2302 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2303 /* si+Ext_ResInfo // */ 2189 /* si+Ext_ResInfo // */
2304 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; 2190 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
2305 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */ 2191 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
@@ -2346,23 +2232,18 @@ static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2346 2232
2347 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability; 2233 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
2348 2234
2349 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */ 2235 if (((pVBInfo->VBType & VB_SIS302LV) ||
2350 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType 2236 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2351 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) { 2237 tempbx |= SetLCDDualLink;
2352 tempbx |= SetLCDDualLink;
2353 }
2354 }
2355 2238
2356 if (pVBInfo->IF_DEF_LVDS == 0) { 2239 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2357 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo 2240 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2358 & SetCRT2ToLCD) && (resinfo == 9) && 2241 (!(tempbx & EnableScalingLCD)))
2359 (!(tempbx & EnableScalingLCD))) 2242 /*
2360 /* 2243 * set to center in 1280x1024 LCDB
2361 * set to center in 1280x1024 LCDB 2244 * for Panel_1400x1050
2362 * for Panel_1400x1050 2245 */
2363 */ 2246 tempbx |= SetLCDtoNonExpanding;
2364 tempbx |= SetLCDtoNonExpanding;
2365 }
2366 2247
2367 if (pVBInfo->VBInfo & SetInSlaveMode) { 2248 if (pVBInfo->VBInfo & SetInSlaveMode) {
2368 if (pVBInfo->VBInfo & SetNotSimuMode) 2249 if (pVBInfo->VBInfo & SetNotSimuMode)
@@ -2637,36 +2518,34 @@ static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2637 if (!(pVBInfo->VBInfo & SetCRT2ToLCD)) 2518 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2638 goto exit; 2519 goto exit;
2639 2520
2640 if (pVBInfo->IF_DEF_LVDS == 0) { 2521 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2641 if (pVBInfo->LCDResInfo == Panel_1600x1200) { 2522 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2642 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) { 2523 if (yres == 1024)
2643 if (yres == 1024) 2524 yres = 1056;
2644 yres = 1056;
2645 }
2646 } 2525 }
2526 }
2647 2527
2648 if (pVBInfo->LCDResInfo == Panel_1280x1024) { 2528 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2649 if (yres == 400) 2529 if (yres == 400)
2650 yres = 405; 2530 yres = 405;
2651 else if (yres == 350) 2531 else if (yres == 350)
2652 yres = 360; 2532 yres = 360;
2653 2533
2654 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) { 2534 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2655 if (yres == 360) 2535 if (yres == 360)
2656 yres = 375; 2536 yres = 375;
2657 }
2658 } 2537 }
2538 }
2659 2539
2660 if (pVBInfo->LCDResInfo == Panel_1024x768) { 2540 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2661 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) { 2541 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2662 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) { 2542 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2663 if (yres == 350) 2543 if (yres == 350)
2664 yres = 357; 2544 yres = 357;
2665 else if (yres == 400) 2545 else if (yres == 400)
2666 yres = 420; 2546 yres = 420;
2667 else if (yres == 480) 2547 else if (yres == 480)
2668 yres = 525; 2548 yres = 525;
2669 }
2670 } 2549 }
2671 } 2550 }
2672 } 2551 }
@@ -2981,10 +2860,8 @@ static unsigned short XGI_GetOffset(unsigned short ModeNo,
2981 temp = 0x6B; 2860 temp = 0x6B;
2982 if (infoflag & InterlaceMode) 2861 if (infoflag & InterlaceMode)
2983 temp = temp << 1; 2862 temp = temp << 1;
2984 return temp * colordepth;
2985 } else {
2986 return temp * colordepth;
2987 } 2863 }
2864 return temp * colordepth;
2988} 2865}
2989 2866
2990static void XGI_SetCRT2Offset(unsigned short ModeNo, 2867static void XGI_SetCRT2Offset(unsigned short ModeNo,
@@ -3022,11 +2899,7 @@ static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
3022 unsigned short RefreshRateTableIndex, 2899 unsigned short RefreshRateTableIndex,
3023 struct vb_device_info *pVBInfo) 2900 struct vb_device_info *pVBInfo)
3024{ 2901{
3025 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0; 2902 u8 tempcx;
3026
3027 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3028 CRT1Index &= IndexMask;
3029 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3030 2903
3031 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, 2904 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3032 HwDeviceExtension, pVBInfo); 2905 HwDeviceExtension, pVBInfo);
@@ -3045,11 +2918,10 @@ static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
3045 struct vb_device_info *pVBInfo) 2918 struct vb_device_info *pVBInfo)
3046{ 2919{
3047 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0, 2920 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3048 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0; 2921 pushbx = 0, CRT1Index, modeflag;
3049 2922
3050 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; 2923 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3051 CRT1Index &= IndexMask; 2924 CRT1Index &= IndexMask;
3052 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3053 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 2925 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3054 2926
3055 /* bainy change table name */ 2927 /* bainy change table name */
@@ -3204,13 +3076,11 @@ static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
3204 struct vb_device_info *pVBInfo) 3076 struct vb_device_info *pVBInfo)
3205{ 3077{
3206 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo, 3078 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3207 modeflag, CRT1Index; 3079 modeflag;
3208 3080
3209 /* si+Ext_ResInfo */ 3081 /* si+Ext_ResInfo */
3210 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 3082 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3211 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO; 3083 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3212 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3213 CRT1Index &= IndexMask;
3214 3084
3215 if (!(pVBInfo->VBInfo & SetInSlaveMode)) 3085 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3216 return; 3086 return;
@@ -3501,15 +3371,13 @@ static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
3501 struct vb_device_info *pVBInfo) 3371 struct vb_device_info *pVBInfo)
3502{ 3372{
3503 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2, 3373 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3504 modeflag, resinfo, crt2crtc; 3374 modeflag;
3505 unsigned char const *TimingPoint; 3375 unsigned char const *TimingPoint;
3506 3376
3507 unsigned long longtemp, tempeax, tempebx, temp2, tempecx; 3377 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3508 3378
3509 /* si+Ext_ResInfo */ 3379 /* si+Ext_ResInfo */
3510 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag; 3380 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3511 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3512 crt2crtc = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
3513 3381
3514 tempax = 0; 3382 tempax = 0;
3515 3383
@@ -3918,8 +3786,7 @@ static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
3918 } 3786 }
3919 3787
3920 if (pVBInfo->TVInfo & TVSetPALM) { 3788 if (pVBInfo->TVInfo & TVSetPALM) {
3921 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port, 3789 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
3922 0x01);
3923 tempax--; 3790 tempax--;
3924 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax); 3791 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
3925 3792
@@ -3940,17 +3807,12 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
3940 unsigned short RefreshRateTableIndex, 3807 unsigned short RefreshRateTableIndex,
3941 struct vb_device_info *pVBInfo) 3808 struct vb_device_info *pVBInfo)
3942{ 3809{
3943 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp, 3810 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3944 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index; 3811 tempbh, tempch;
3945 3812
3946 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL; 3813 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
3947 3814
3948 /* si+Ext_ResInfo */ 3815 /* si+Ext_ResInfo */
3949 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3950 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3951 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3952 CRT1Index &= IndexMask;
3953
3954 if (!(pVBInfo->VBInfo & SetCRT2ToLCD)) 3816 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3955 return; 3817 return;
3956 3818
@@ -3969,7 +3831,6 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
3969 3831
3970 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp); 3832 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
3971 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */ 3833 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3972 push1 = tempbx;
3973 tempbx--; 3834 tempbx--;
3974 temp = tempbx & 0x00FF; 3835 temp = tempbx & 0x00FF;
3975 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp); 3836 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
@@ -3977,7 +3838,6 @@ static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
3977 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp); 3838 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
3978 3839
3979 tempcx = pVBInfo->VT - 1; 3840 tempcx = pVBInfo->VT - 1;
3980 push2 = tempcx + 1;
3981 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */ 3841 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
3982 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp); 3842 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
3983 temp = (tempcx & 0xFF00) >> 8; 3843 temp = (tempcx & 0xFF00) >> 8;
@@ -4459,10 +4319,6 @@ static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4459static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex, 4319static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
4460 struct vb_device_info *pVBInfo) 4320 struct vb_device_info *pVBInfo)
4461{ 4321{
4462 unsigned short Pindex, Pdata;
4463
4464 Pindex = pVBInfo->Part5Port;
4465 Pdata = pVBInfo->Part5Port + 1;
4466 if (pVBInfo->ModeType == ModeVGA) { 4322 if (pVBInfo->ModeType == ModeVGA) {
4467 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag 4323 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
4468 | DisableCRT2Display))) { 4324 | DisableCRT2Display))) {
@@ -4538,7 +4394,7 @@ static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4538 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability & 4394 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
4539 (LCDPolarity << 8)) >> 8); 4395 (LCDPolarity << 8)) >> 8);
4540 temp &= LCDPolarity; 4396 temp &= LCDPolarity;
4541 Miscdata = (unsigned char) inb(pVBInfo->P3cc); 4397 Miscdata = inb(pVBInfo->P3cc);
4542 4398
4543 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2); 4399 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
4544 4400
@@ -4598,7 +4454,7 @@ static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4598 4454
4599 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE; 4455 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
4600 4456
4601 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11); 4457 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
4602 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */ 4458 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
4603 4459
4604 if (!(modeflag & Charx8Dot)) 4460 if (!(modeflag & Charx8Dot))
@@ -4737,43 +4593,21 @@ static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
4737} 4593}
4738 4594
4739/* --------------------------------------------------------------------- */ 4595/* --------------------------------------------------------------------- */
4740/* Function : XGI_DisableChISLCD */
4741/* Input : */
4742/* Output : 0 -> Not LCD Mode */
4743/* Description : */
4744/* --------------------------------------------------------------------- */
4745static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
4746{
4747 unsigned short tempbx, tempah;
4748
4749 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4750 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
4751
4752 if (tempbx & (EnableChA | DisableChA)) {
4753 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4754 return 0;
4755 }
4756
4757 if (!(tempbx & (EnableChB | DisableChB)))
4758 return 0;
4759
4760 if (tempah & 0x01) /* Chk LCDB Mode */
4761 return 1;
4762
4763 return 0;
4764}
4765
4766/* --------------------------------------------------------------------- */
4767/* Function : XGI_EnableChISLCD */ 4596/* Function : XGI_EnableChISLCD */
4768/* Input : */ 4597/* Input : */
4769/* Output : 0 -> Not LCD mode */ 4598/* Output : 0 -> Not LCD mode */
4770/* Description : */ 4599/* Description : if bool enable = true -> enable, else disable */
4771/* --------------------------------------------------------------------- */ 4600/* --------------------------------------------------------------------- */
4772static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo) 4601static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo,
4602 bool enable)
4773{ 4603{
4774 unsigned short tempbx, tempah; 4604 unsigned short tempbx, tempah;
4775 4605
4776 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB); 4606 if (enable)
4607 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
4608 else
4609 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
4610
4777 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E)); 4611 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
4778 4612
4779 if (tempbx & (EnableChA | DisableChA)) { 4613 if (tempbx & (EnableChA | DisableChA)) {
@@ -4825,9 +4659,9 @@ static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4825 4659
4826 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) { 4660 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
4827 if (((pVBInfo->VBInfo & 4661 if (((pVBInfo->VBInfo &
4828 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) 4662 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
4829 || (XGI_DisableChISLCD(pVBInfo)) 4663 (XGI_EnableChISLCD(pVBInfo, false)) ||
4830 || (XGI_IsLCDON(pVBInfo))) 4664 (XGI_IsLCDON(pVBInfo)))
4831 /* LVDS Driver power down */ 4665 /* LVDS Driver power down */
4832 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80); 4666 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
4833 } 4667 }
@@ -5018,16 +4852,6 @@ static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
5018 } 4852 }
5019 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah); 4853 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
5020 } 4854 }
5021 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5022 tempbl = 0;
5023 tempbh = 0;
5024 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5025 tempah = XGI301LCDDelay;
5026 tempah &= 0x0f;
5027 tempah = tempah << 4;
5028 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
5029 tempah);
5030 }
5031 } 4855 }
5032} 4856}
5033 4857
@@ -5118,12 +4942,8 @@ static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5118 4942
5119 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability; 4943 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5120 4944
5121 if (pVBInfo->VBType & 4945 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
5122 (VB_SIS301B | 4946 VB_SIS302LV | VB_XGI301C)) {
5123 VB_SIS302B |
5124 VB_SIS301LV |
5125 VB_SIS302LV |
5126 VB_XGI301C)) { /* 301LV/302LV only */
5127 if (pVBInfo->VBType & 4947 if (pVBInfo->VBType &
5128 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) { 4948 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
5129 /* Set 301LV Capability */ 4949 /* Set 301LV Capability */
@@ -5135,10 +4955,7 @@ static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5135 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8), 4955 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5136 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW 4956 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5137 | EnablePLLSPLOW)) >> 8)); 4957 | EnablePLLSPLOW)) >> 8));
5138 }
5139 4958
5140 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5141 | VB_SIS302LV | VB_XGI301C)) {
5142 if (pVBInfo->VBInfo & SetCRT2ToLCD) 4959 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5143 XGI_SetLCDCap_B(tempcx, pVBInfo); 4960 XGI_SetLCDCap_B(tempcx, pVBInfo);
5144 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) 4961 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
@@ -5510,13 +5327,10 @@ unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5510 unsigned short ModeNo, unsigned short ModeIdIndex, 5327 unsigned short ModeNo, unsigned short ModeIdIndex,
5511 struct vb_device_info *pVBInfo) 5328 struct vb_device_info *pVBInfo)
5512{ 5329{
5513 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 }, 5330 const u8 LCDARefreshIndex[] = {
5514 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01, 5331 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
5515 0x01, 0x01 };
5516 5332
5517 unsigned short RefreshRateTableIndex, i, modeflag, index, temp; 5333 unsigned short RefreshRateTableIndex, i, index, temp;
5518
5519 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
5520 5334
5521 index = xgifb_reg_get(pVBInfo->P3d4, 0x33); 5335 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
5522 index = index >> pVBInfo->SelectCRT2Rate; 5336 index = index >> pVBInfo->SelectCRT2Rate;
@@ -5531,15 +5345,8 @@ unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5531 if (pVBInfo->SetFlag & ProgrammingCRT2) { 5345 if (pVBInfo->SetFlag & ProgrammingCRT2) {
5532 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { 5346 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
5533 if (pVBInfo->IF_DEF_LVDS == 0) { 5347 if (pVBInfo->IF_DEF_LVDS == 0) {
5534 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B 5348 temp = LCDARefreshIndex[
5535 | VB_SIS301LV | VB_SIS302LV 5349 pVBInfo->LCDResInfo & 0x07];
5536 | VB_XGI301C))
5537 /* 301b */
5538 temp = LCDARefreshIndex[
5539 pVBInfo->LCDResInfo & 0x0F];
5540 else
5541 temp = LCDRefreshIndex[
5542 pVBInfo->LCDResInfo & 0x0F];
5543 5350
5544 if (index > temp) 5351 if (index > temp)
5545 index = temp; 5352 index = temp;
@@ -5617,9 +5424,8 @@ static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
5617 struct xgi_hw_device_info *HwDeviceExtension, 5424 struct xgi_hw_device_info *HwDeviceExtension,
5618 struct vb_device_info *pVBInfo) 5425 struct vb_device_info *pVBInfo)
5619{ 5426{
5620 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex; 5427 unsigned short ModeIdIndex, RefreshRateTableIndex;
5621 5428
5622 tempbx = pVBInfo->VBInfo;
5623 pVBInfo->SetFlag |= ProgrammingCRT2; 5429 pVBInfo->SetFlag |= ProgrammingCRT2;
5624 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo); 5430 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5625 pVBInfo->SelectCRT2Rate = 4; 5431 pVBInfo->SelectCRT2Rate = 4;
@@ -5658,32 +5464,31 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5658 5464
5659 unsigned char CR17, CR63, SR31; 5465 unsigned char CR17, CR63, SR31;
5660 unsigned short temp; 5466 unsigned short temp;
5661 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5662 5467
5663 int i; 5468 int i;
5664 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86); 5469 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
5665 5470
5666 /* to fix XG42 single LCD sense to CRT+LCD */ 5471 /* to fix XG42 single LCD sense to CRT+LCD */
5667 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A); 5472 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
5668 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get( 5473 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
5669 pVBInfo->P3d4, 0x53) | 0x02)); 5474 pVBInfo->P3d4, 0x53) | 0x02));
5670 5475
5671 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31); 5476 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5672 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63); 5477 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5673 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01); 5478 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
5674 5479
5675 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF)); 5480 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5676 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF)); 5481 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
5677 5482
5678 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17); 5483 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
5679 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80)); 5484 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
5680 5485
5681 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F); 5486 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5682 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04)); 5487 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
5683 5488
5684 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07); 5489 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
5685 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB)); 5490 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
5686 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06); 5491 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
5687 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3)); 5492 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
5688 5493
5689 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00); 5494 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
@@ -5712,10 +5517,8 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5712 5517
5713 outb(0x00, pVBInfo->P3c8); 5518 outb(0x00, pVBInfo->P3c8);
5714 5519
5715 for (i = 0; i < 256; i++) { 5520 for (i = 0; i < 256 * 3; i++) {
5716 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1)); 5521 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
5717 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5718 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
5719 } 5522 }
5720 5523
5721 mdelay(1); 5524 mdelay(1);
@@ -5731,9 +5534,7 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5731 /* avoid display something, set BLACK DAC if not restore DAC */ 5534 /* avoid display something, set BLACK DAC if not restore DAC */
5732 outb(0x00, pVBInfo->P3c8); 5535 outb(0x00, pVBInfo->P3c8);
5733 5536
5734 for (i = 0; i < 256; i++) { 5537 for (i = 0; i < 256 * 3; i++) {
5735 outb(0, (pVBInfo->P3c8 + 1));
5736 outb(0, (pVBInfo->P3c8 + 1));
5737 outb(0, (pVBInfo->P3c8 + 1)); 5538 outb(0, (pVBInfo->P3c8 + 1));
5738 } 5539 }
5739 5540
@@ -5741,7 +5542,7 @@ void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5741 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63); 5542 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5742 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31); 5543 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
5743 5544
5744 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get( 5545 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
5745 pVBInfo->P3d4, 0x53) & 0xFD)); 5546 pVBInfo->P3d4, 0x53) & 0xFD));
5746 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F); 5547 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
5747} 5548}
@@ -5755,13 +5556,10 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5755 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV 5556 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5756 | VB_SIS302LV | VB_XGI301C)) { 5557 | VB_SIS302LV | VB_XGI301C)) {
5757 if (!(pVBInfo->SetFlag & DisableChA)) { 5558 if (!(pVBInfo->SetFlag & DisableChA)) {
5758 if (pVBInfo->SetFlag & EnableChA) { 5559 if ((pVBInfo->SetFlag & EnableChA) ||
5560 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5759 /* Power on */ 5561 /* Power on */
5760 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20); 5562 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
5761 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5762 /* Power on */
5763 xgifb_reg_set(pVBInfo->Part1Port,
5764 0x1E, 0x20);
5765 } 5563 }
5766 } 5564 }
5767 5565
@@ -5769,8 +5567,7 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5769 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo 5567 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5770 & (SetCRT2ToLCD | SetCRT2ToTV 5568 & (SetCRT2ToLCD | SetCRT2ToTV
5771 | SetCRT2ToRAMDAC))) { 5569 | SetCRT2ToRAMDAC))) {
5772 tempah = (unsigned char) xgifb_reg_get( 5570 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5773 pVBInfo->P3c4, 0x32);
5774 tempah &= 0xDF; 5571 tempah &= 0xDF;
5775 if (pVBInfo->VBInfo & SetInSlaveMode) { 5572 if (pVBInfo->VBInfo & SetInSlaveMode) {
5776 if (!(pVBInfo->VBInfo & 5573 if (!(pVBInfo->VBInfo &
@@ -5780,8 +5577,8 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5780 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah); 5577 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5781 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20); 5578 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5782 5579
5783 tempah = (unsigned char) xgifb_reg_get( 5580 tempah = xgifb_reg_get(pVBInfo->Part1Port,
5784 pVBInfo->Part1Port, 0x2E); 5581 0x2E);
5785 5582
5786 if (!(tempah & 0x80)) 5583 if (!(tempah & 0x80))
5787 xgifb_reg_or(pVBInfo->Part1Port, 5584 xgifb_reg_or(pVBInfo->Part1Port,
@@ -5795,8 +5592,8 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5795 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0, 5592 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
5796 0x20); /* shampoo 0129 */ 5593 0x20); /* shampoo 0129 */
5797 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) { 5594 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
5798 if (!XGI_DisableChISLCD(pVBInfo)) { 5595 if (!XGI_EnableChISLCD(pVBInfo, false)) {
5799 if (XGI_EnableChISLCD(pVBInfo) || 5596 if (XGI_EnableChISLCD(pVBInfo, true) ||
5800 (pVBInfo->VBInfo & 5597 (pVBInfo->VBInfo &
5801 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) 5598 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5802 /* LVDS PLL power on */ 5599 /* LVDS PLL power on */
@@ -5854,8 +5651,7 @@ static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5854 /* enable CRT2 */ 5651 /* enable CRT2 */
5855 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20); 5652 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
5856 5653
5857 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port, 5654 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5858 0x2E);
5859 if (!(tempah & 0x80)) 5655 if (!(tempah & 0x80))
5860 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80); 5656 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5861 5657
@@ -5947,7 +5743,6 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5947 unsigned short ModeIdIndex; 5743 unsigned short ModeIdIndex;
5948 struct vb_device_info VBINF; 5744 struct vb_device_info VBINF;
5949 struct vb_device_info *pVBInfo = &VBINF; 5745 struct vb_device_info *pVBInfo = &VBINF;
5950 pVBInfo->BaseAddr = xgifb_info->vga_base;
5951 pVBInfo->IF_DEF_LVDS = 0; 5746 pVBInfo->IF_DEF_LVDS = 0;
5952 5747
5953 if (HwDeviceExtension->jChipType >= XG20) { 5748 if (HwDeviceExtension->jChipType >= XG20) {
@@ -5961,24 +5756,7 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5961 pVBInfo->IF_DEF_CRT2Monitor = 1; 5756 pVBInfo->IF_DEF_CRT2Monitor = 1;
5962 } 5757 }
5963 5758
5964 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14; 5759 XGIRegInit(pVBInfo, xgifb_info->vga_base);
5965 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
5966 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
5967 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
5968 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
5969 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
5970 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
5971 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
5972 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
5973 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
5974 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
5975 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
5976 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
5977 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
5978 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
5979 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
5980 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
5981 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
5982 5760
5983 /* for x86 Linux, XG21 LVDS */ 5761 /* for x86 Linux, XG21 LVDS */
5984 if (HwDeviceExtension->jChipType == XG21) { 5762 if (HwDeviceExtension->jChipType == XG21) {
@@ -6011,7 +5789,8 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
6011 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo); 5789 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
6012 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo); 5790 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
6013 5791
6014 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) { 5792 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5793 (!(pVBInfo->VBInfo & SwitchCRT2))) {
6015 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo, 5794 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6016 ModeIdIndex, pVBInfo); 5795 ModeIdIndex, pVBInfo);
6017 5796
@@ -6019,24 +5798,11 @@ unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
6019 XGI_SetLCDAGroup(ModeNo, ModeIdIndex, 5798 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6020 HwDeviceExtension, pVBInfo); 5799 HwDeviceExtension, pVBInfo);
6021 } 5800 }
6022 } else if (!(pVBInfo->VBInfo & SwitchCRT2)) {
6023 XGI_SetCRT1Group(xgifb_info,
6024 HwDeviceExtension, ModeNo,
6025 ModeIdIndex, pVBInfo);
6026 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6027 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6028 HwDeviceExtension,
6029 pVBInfo);
6030 }
6031 } 5801 }
6032 5802
6033 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) { 5803 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
6034 switch (HwDeviceExtension->ujVBChipID) { 5804 switch (HwDeviceExtension->ujVBChipID) {
6035 case VB_CHIP_301: 5805 case VB_CHIP_301: /* fall through */
6036 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6037 pVBInfo); /*add for CRT2 */
6038 break;
6039
6040 case VB_CHIP_302: 5806 case VB_CHIP_302:
6041 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension, 5807 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6042 pVBInfo); /*add for CRT2 */ 5808 pVBInfo); /*add for CRT2 */
diff --git a/drivers/staging/xgifb/vb_struct.h b/drivers/staging/xgifb/vb_struct.h
index acf6e7fbbaed..ae0c18b320a4 100644
--- a/drivers/staging/xgifb/vb_struct.h
+++ b/drivers/staging/xgifb/vb_struct.h
@@ -156,10 +156,9 @@ struct vb_device_info {
156 unsigned short SelectCRT2Rate; 156 unsigned short SelectCRT2Rate;
157 157
158 void __iomem *FBAddr; 158 void __iomem *FBAddr;
159 unsigned long BaseAddr;
160 159
161 unsigned char const (*SR15)[8]; 160 unsigned char const (*SR15)[3];
162 unsigned char const (*CR40)[8]; 161 unsigned char const (*CR40)[3];
163 162
164 struct SiS_MCLKData const *MCLKData; 163 struct SiS_MCLKData const *MCLKData;
165 164
diff --git a/drivers/staging/xgifb/vb_table.h b/drivers/staging/xgifb/vb_table.h
index 39f528b14f01..b4c05c80b937 100644
--- a/drivers/staging/xgifb/vb_table.h
+++ b/drivers/staging/xgifb/vb_table.h
@@ -4,114 +4,88 @@ static const struct SiS_MCLKData XGI340New_MCLKData[] = {
4 {0x16, 0x01, 0x01, 166}, 4 {0x16, 0x01, 0x01, 166},
5 {0x19, 0x02, 0x01, 124}, 5 {0x19, 0x02, 0x01, 124},
6 {0x7C, 0x08, 0x01, 200}, 6 {0x7C, 0x08, 0x01, 200},
7 {0x79, 0x06, 0x01, 250},
8 {0x29, 0x01, 0x81, 301},
9 {0x5c, 0x23, 0x01, 166},
10 {0x5c, 0x23, 0x01, 166},
11 {0x5c, 0x23, 0x01, 166}
12}; 7};
13 8
14static const struct SiS_MCLKData XGI27New_MCLKData[] = { 9static const struct SiS_MCLKData XGI27New_MCLKData[] = {
15 {0x5c, 0x23, 0x01, 166}, 10 {0x5c, 0x23, 0x01, 166},
16 {0x19, 0x02, 0x01, 124}, 11 {0x19, 0x02, 0x01, 124},
17 {0x7C, 0x08, 0x80, 200}, 12 {0x7C, 0x08, 0x80, 200},
18 {0x79, 0x06, 0x80, 250},
19 {0x29, 0x01, 0x81, 300},
20 {0x5c, 0x23, 0x01, 166},
21 {0x5c, 0x23, 0x01, 166},
22 {0x5c, 0x23, 0x01, 166}
23}; 13};
24 14
25const struct XGI_ECLKDataStruct XGI340_ECLKData[] = { 15const struct XGI_ECLKDataStruct XGI340_ECLKData[] = {
26 {0x5c, 0x23, 0x01, 166}, 16 {0x5c, 0x23, 0x01, 166},
27 {0x55, 0x84, 0x01, 123}, 17 {0x55, 0x84, 0x01, 123},
28 {0x7C, 0x08, 0x01, 200}, 18 {0x7C, 0x08, 0x01, 200},
29 {0x79, 0x06, 0x01, 250}, 19};
30 {0x29, 0x01, 0x81, 301}, 20
31 {0x5c, 0x23, 0x01, 166}, 21static const unsigned char XG27_SR13[4][3] = {
32 {0x5c, 0x23, 0x01, 166}, 22 {0x35, 0x45, 0xb1}, /* SR13 */
33 {0x5c, 0x23, 0x01, 166} 23 {0x41, 0x51, 0x5c}, /* SR14 */
34}; 24 {0x32, 0x32, 0x42}, /* SR18 */
35 25 {0x03, 0x03, 0x03} /* SR1B */
36static const unsigned char XG27_SR13[4][8] = { 26};
37 {0x35, 0x45, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR13 */ 27
38 {0x41, 0x51, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR14 */ 28static const unsigned char XGI340_SR13[4][3] = {
39 {0x32, 0x32, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR18 */ 29 {0x35, 0x45, 0xb1}, /* SR13 */
40 {0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00} /* SR1B */ 30 {0x41, 0x51, 0x5c}, /* SR14 */
41}; 31 {0x31, 0x42, 0x42}, /* SR18 */
42 32 {0x03, 0x03, 0x03} /* SR1B */
43static const unsigned char XGI340_SR13[4][8] = { 33};
44 {0x35, 0x45, 0xb1, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR13 */ 34
45 {0x41, 0x51, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR14 */ 35static const unsigned char XGI340_cr41[24][3] = {
46 {0x31, 0x42, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00}, /* SR18 */ 36 {0x20, 0x50, 0x60}, /* 0 CR41 */
47 {0x03, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00} /* SR1B */ 37 {0xc4, 0x40, 0x84}, /* 1 CR8A */
48}; 38 {0xc4, 0x40, 0x84}, /* 2 CR8B */
49 39 {0xb5, 0xa4, 0xa4},
50static const unsigned char XGI340_cr41[24][8] = { 40 {0xf0, 0xf0, 0xf0},
51 {0x20, 0x50, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0 CR41 */ 41 {0x90, 0x90, 0x24}, /* 5 CR68 */
52 {0xc4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1 CR8A */ 42 {0x77, 0x77, 0x44}, /* 6 CR69 */
53 {0xc4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2 CR8B */ 43 {0x77, 0x77, 0x44}, /* 7 CR6A */
54 {0xb5, 0xa4, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00}, 44 {0xff, 0xff, 0xff}, /* 8 CR6D */
55 {0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, 45 {0x55, 0x55, 0x55}, /* 9 CR80 */
56 {0x90, 0x90, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 5 CR68 */ 46 {0x00, 0x00, 0x00}, /* 10 CR81 */
57 {0x77, 0x77, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 6 CR69 */ 47 {0x88, 0xa8, 0x48}, /* 11 CR82 */
58 {0x77, 0x77, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 7 CR6A */ 48 {0x44, 0x44, 0x77}, /* 12 CR85 */
59 {0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 8 CR6D */ 49 {0x48, 0x48, 0x88}, /* 13 CR86 */
60 {0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 9 CR80 */ 50 {0x54, 0x54, 0x44}, /* 14 CR90 */
61 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 10 CR81 */ 51 {0x54, 0x54, 0x44}, /* 15 CR91 */
62 {0x88, 0xa8, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 11 CR82 */ 52 {0x0a, 0x0a, 0x07}, /* 16 CR92 */
63 {0x44, 0x44, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 12 CR85 */ 53 {0x44, 0x44, 0x44}, /* 17 CR93 */
64 {0x48, 0x48, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 13 CR86 */ 54 {0x10, 0x10, 0x0A}, /* 18 CR94 */
65 {0x54, 0x54, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 14 CR90 */ 55 {0x11, 0x11, 0x0a}, /* 19 CR95 */
66 {0x54, 0x54, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 15 CR91 */ 56 {0x05, 0x05, 0x05}, /* 20 CR96 */
67 {0x0a, 0x0a, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 16 CR92 */ 57 {0xf0, 0xf0, 0xf0}, /* 21 CRC3 */
68 {0x44, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 17 CR93 */ 58 {0x05, 0x00, 0x02}, /* 22 CRC4 */
69 {0x10, 0x10, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 18 CR94 */ 59 {0x00, 0x00, 0x00} /* 23 CRC5 */
70 {0x11, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 19 CR95 */ 60};
71 {0x05, 0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 20 CR96 */ 61
72 {0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 21 CRC3 */ 62static const unsigned char XGI27_cr41[24][3] = {
73 {0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 22 CRC4 */ 63 {0x20, 0x40, 0x60}, /* 0 CR41 */
74 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 23 CRC5 */ 64 {0xC4, 0x40, 0x84}, /* 1 CR8A */
75}; 65 {0xC4, 0x40, 0x84}, /* 2 CR8B */
76 66 {0xB3, 0x13, 0xa4}, /* 3 CR40[7],
77static const unsigned char XGI27_cr41[24][8] = { 67 CR99[2:0],
78 {0x20, 0x40, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 0 CR41 */ 68 CR45[3:0]*/
79 {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 1 CR8A */ 69 {0xf0, 0xf5, 0xf0}, /* 4 CR59 */
80 {0xC4, 0x40, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 2 CR8B */ 70 {0x90, 0x90, 0x24}, /* 5 CR68 */
81 {0xB3, 0x13, 0xa4, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 3 CR40[7], 71 {0x77, 0x67, 0x44}, /* 6 CR69 */
82 CR99[2:0], 72 {0x77, 0x77, 0x44}, /* 7 CR6A */
83 CR45[3:0]*/ 73 {0xff, 0xff, 0xff}, /* 8 CR6D */
84 {0xf0, 0xf5, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 4 CR59 */ 74 {0x55, 0x55, 0x55}, /* 9 CR80 */
85 {0x90, 0x90, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 5 CR68 */ 75 {0x00, 0x00, 0x00}, /* 10 CR81 */
86 {0x77, 0x67, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 6 CR69 */ 76 {0x88, 0xcc, 0x48}, /* 11 CR82 */
87 {0x77, 0x77, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 7 CR6A */ 77 {0x44, 0x88, 0x77}, /* 12 CR85 */
88 {0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 8 CR6D */ 78 {0x48, 0x88, 0x88}, /* 13 CR86 */
89 {0x55, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 9 CR80 */ 79 {0x54, 0x32, 0x44}, /* 14 CR90 */
90 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 10 CR81 */ 80 {0x54, 0x33, 0x44}, /* 15 CR91 */
91 {0x88, 0xcc, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 11 CR82 */ 81 {0x0a, 0x07, 0x07}, /* 16 CR92 */
92 {0x44, 0x88, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 12 CR85 */ 82 {0x44, 0x63, 0x44}, /* 17 CR93 */
93 {0x48, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 13 CR86 */ 83 {0x10, 0x14, 0x0A}, /* 18 CR94 */
94 {0x54, 0x32, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 14 CR90 */ 84 {0x11, 0x0B, 0x0C}, /* 19 CR95 */
95 {0x54, 0x33, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 15 CR91 */ 85 {0x05, 0x22, 0x05}, /* 20 CR96 */
96 {0x0a, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 16 CR92 */ 86 {0xf0, 0xf0, 0x00}, /* 21 CRC3 */
97 {0x44, 0x63, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 17 CR93 */ 87 {0x05, 0x00, 0x02}, /* 22 CRC4 */
98 {0x10, 0x14, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 18 CR94 */ 88 {0x00, 0x00, 0x00} /* 23 CRC5 */
99 {0x11, 0x0B, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 19 CR95 */
100 {0x05, 0x22, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 20 CR96 */
101 {0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 21 CRC3 */
102 {0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00}, /* 22 CRC4 */
103 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} /* 23 CRC5 */
104};
105
106const unsigned char XGI340_CR6B[8][4] = {
107 {0xaa, 0xaa, 0xaa, 0xaa},
108 {0xaa, 0xaa, 0xaa, 0xaa},
109 {0xaa, 0xaa, 0xaa, 0xaa},
110 {0x00, 0x00, 0x00, 0x00},
111 {0x00, 0x00, 0x00, 0x00},
112 {0x00, 0x00, 0x00, 0x00},
113 {0x00, 0x00, 0x00, 0x00},
114 {0x00, 0x00, 0x00, 0x00}
115}; 89};
116 90
117/* CR47,CR48,CR49,CR4A,CR4B,CR4C,CR70,CR71,CR74,CR75,CR76,CR77 */ 91/* CR47,CR48,CR49,CR4A,CR4B,CR4C,CR70,CR71,CR74,CR75,CR76,CR77 */
@@ -195,7 +169,7 @@ const struct XGI_ExtStruct XGI330_EModeIDTable[] = {
195static const struct SiS_StandTable_S XGI330_StandTable = { 169static const struct SiS_StandTable_S XGI330_StandTable = {
196/* ExtVGATable */ 170/* ExtVGATable */
197 0x00, 0x00, 0x00, 0x0000, 171 0x00, 0x00, 0x00, 0x0000,
198 {0x01, 0x0f, 0x00, 0x0e}, 172 {0x21, 0x0f, 0x00, 0x0e}, /* 0x21 = 0x01 | (0x20 = screen off) */
199 0x23, 173 0x23,
200 {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 174 {0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e,
201 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 175 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
diff --git a/drivers/staging/zcache/Kconfig b/drivers/staging/zcache/Kconfig
index 4881839be625..73582705e8c5 100644
--- a/drivers/staging/zcache/Kconfig
+++ b/drivers/staging/zcache/Kconfig
@@ -1,6 +1,6 @@
1config ZCACHE 1config ZCACHE
2 bool "Dynamic compression of swap pages and clean pagecache pages" 2 bool "Dynamic compression of swap pages and clean pagecache pages"
3 depends on (CLEANCACHE || FRONTSWAP) && CRYPTO=y && ZSMALLOC=y 3 depends on CRYPTO=y && SWAP=y && CLEANCACHE && FRONTSWAP
4 select CRYPTO_LZO 4 select CRYPTO_LZO
5 default n 5 default n
6 help 6 help
@@ -9,3 +9,35 @@ config ZCACHE
9 compression and an in-kernel implementation of transcendent 9 compression and an in-kernel implementation of transcendent
10 memory to store clean page cache pages and swap in RAM, 10 memory to store clean page cache pages and swap in RAM,
11 providing a noticeable reduction in disk I/O. 11 providing a noticeable reduction in disk I/O.
12
13config RAMSTER
14 bool "Cross-machine RAM capacity sharing, aka peer-to-peer tmem"
15 depends on CONFIGFS_FS=y && SYSFS=y && !HIGHMEM && ZCACHE=y
16 depends on NET
17 # must ensure struct page is 8-byte aligned
18 select HAVE_ALIGNED_STRUCT_PAGE if !64_BIT
19 default n
20 help
21 RAMster allows RAM on other machines in a cluster to be utilized
22 dynamically and symmetrically instead of swapping to a local swap
23 disk, thus improving performance on memory-constrained workloads
24 while minimizing total RAM across the cluster. RAMster, like
25 zcache2, compresses swap pages into local RAM, but then remotifies
26 the compressed pages to another node in the RAMster cluster.
27
28# Depends on not-yet-upstreamed mm patches to export end_swap_bio_write and
29# __add_to_swap_cache, and implement __swap_writepage (which is swap_writepage
30# without the frontswap call. When these are in-tree, the dependency on
31# BROKEN can be removed
32config ZCACHE_WRITEBACK
33 bool "Allow compressed swap pages to be writtenback to swap disk"
34 depends on ZCACHE=y && BROKEN
35 default n
36 help
37 Zcache caches compressed swap pages (and other data) in RAM which
38 often improves performance by avoiding I/O's due to swapping.
39 In some workloads with very long-lived large processes, it can
40 instead reduce performance. Writeback decompresses zcache-compressed
41 pages (in LRU order) when under memory pressure and writes them to
42 the backing swap disk to ameliorate this problem. Policy driving
43 writeback is still under development.
diff --git a/drivers/staging/zcache/Makefile b/drivers/staging/zcache/Makefile
index 60daa272c204..471104957dad 100644
--- a/drivers/staging/zcache/Makefile
+++ b/drivers/staging/zcache/Makefile
@@ -1,3 +1,6 @@
1zcache-y := zcache-main.o tmem.o 1zcache-y := zcache-main.o tmem.o zbud.o
2zcache-$(CONFIG_RAMSTER) += ramster/ramster.o ramster/r2net.o
3zcache-$(CONFIG_RAMSTER) += ramster/nodemanager.o ramster/tcp.o
4zcache-$(CONFIG_RAMSTER) += ramster/heartbeat.o ramster/masklog.o
2 5
3obj-$(CONFIG_ZCACHE) += zcache.o 6obj-$(CONFIG_ZCACHE) += zcache.o
diff --git a/drivers/staging/zcache/TODO b/drivers/staging/zcache/TODO
new file mode 100644
index 000000000000..c1e26d4973dc
--- /dev/null
+++ b/drivers/staging/zcache/TODO
@@ -0,0 +1,69 @@
1
2** ZCACHE PLAN FOR PROMOTION FROM STAGING **
3
4Last updated: Feb 13, 2013
5
6PLAN STEPS
7
81. merge zcache and ramster to eliminate horrible code duplication
92. converge on a predictable, writeback-capable allocator
103. use debugfs instead of sysfs (per akpm feedback in 2011)
114. zcache side of cleancache/mm WasActive patch
125. zcache side of frontswap exclusive gets
136. zcache must be able to writeback to physical swap disk
14 (per Andrea Arcangeli feedback in 2011)
157. implement adequate policy for writeback
168. frontswap/cleancache work to allow zcache to be loaded
17 as a module
189. get core mm developer to review
1910. incorporate feedback from review
2011. get review/acks from 1-2 additional mm developers
2112. incorporate any feedback from additional mm reviews
2213. propose location/file-naming in mm tree
2314. repeat 9-13 as necessary until akpm is happy and merges
24
25STATUS/OWNERSHIP
26
271. DONE as part of "new" zcache; in staging/zcache for 3.9
282. DONE as part of "new" zcache (cf zbud.[ch]); in staging/zcache for 3.9
29 (this was the core of the zcache1 vs zcache2 flail)
303. DONE as part of "new" zcache; in staging/zcache for 3.9
314. DONE (w/caveats) as part of "new" zcache; per cleancache performance
32 feedback see https://lkml.org/lkml/2011/8/17/351, in
33 staging/zcache for 3.9; dependent on proposed mm patch, see
34 https://lkml.org/lkml/2012/1/25/300
355. DONE as part of "new" zcache; performance tuning only,
36 in staging/zcache for 3.9; dependent on frontswap patch
37 merged in 3.7 (33c2a174)
386. DONE (w/caveats), prototyped as part of "new" zcache, had
39 bad memory leak; reimplemented to use sjennings clever tricks
40 and proposed mm patches with new version in staging/zcache
41 for 3.9, see https://lkml.org/lkml/2013/2/6/437;
427. PROTOTYPED as part of "new" zcache; in staging/zcache for 3.9;
43 needs more review (plan to discuss at LSF/MM 2013)
448. IN PROGRESS; owned by Konrad Wilk; v2 recently posted
45 http://lkml.org/lkml/2013/2/1/542
469. IN PROGRESS; owned by Konrad Wilk; Mel Gorman provided
47 great feedback in August 2012 (unfortunately of "old"
48 zcache)
4910. Konrad posted series of fixes (that now need rebasing)
50 https://lkml.org/lkml/2013/2/1/566
5111. NOT DONE; owned by Konrad Wilk
5212. TBD (depends on quantity of feedback)
5313. PROPOSED; one suggestion proposed by Dan; needs more ideas/feedback
5414. TBD (depends on feedback)
55
56WHO NEEDS TO AGREE
57
58Not sure. Seth Jennings is now pursuing a separate but semi-parallel
59track. Akpm clearly has to approve for any mm merge to happen. Minchan
60Kim has interest but may be happy if/when zram is merged into mm. Konrad
61Wilk may be maintainer if akpm decides compression is maintainable
62separately from the rest of mm. (More LSF/MM 2013 discussion.)
63
64ZCACHE FUTURE NEW FUNCTIONALITY
65
66A. Support zsmalloc as an alternative high-density allocator
67 (See https://lkml.org/lkml/2013/1/23/511)
68B. Support zero-filled pages more efficiently
69C. Possibly support three zbuds per pageframe when space allows
diff --git a/drivers/staging/ramster/ramster.h b/drivers/staging/zcache/ramster.h
index 1b71aea2ff62..1b71aea2ff62 100644
--- a/drivers/staging/ramster/ramster.h
+++ b/drivers/staging/zcache/ramster.h
diff --git a/drivers/staging/ramster/ramster/heartbeat.c b/drivers/staging/zcache/ramster/heartbeat.c
index 75d3fe80b055..75d3fe80b055 100644
--- a/drivers/staging/ramster/ramster/heartbeat.c
+++ b/drivers/staging/zcache/ramster/heartbeat.c
diff --git a/drivers/staging/ramster/ramster/heartbeat.h b/drivers/staging/zcache/ramster/heartbeat.h
index 6cbc775bd63b..6cbc775bd63b 100644
--- a/drivers/staging/ramster/ramster/heartbeat.h
+++ b/drivers/staging/zcache/ramster/heartbeat.h
diff --git a/drivers/staging/ramster/ramster/masklog.c b/drivers/staging/zcache/ramster/masklog.c
index 1261d8579aae..1261d8579aae 100644
--- a/drivers/staging/ramster/ramster/masklog.c
+++ b/drivers/staging/zcache/ramster/masklog.c
diff --git a/drivers/staging/ramster/ramster/masklog.h b/drivers/staging/zcache/ramster/masklog.h
index 918ae110b699..918ae110b699 100644
--- a/drivers/staging/ramster/ramster/masklog.h
+++ b/drivers/staging/zcache/ramster/masklog.h
diff --git a/drivers/staging/ramster/ramster/nodemanager.c b/drivers/staging/zcache/ramster/nodemanager.c
index c0f48158735d..c0f48158735d 100644
--- a/drivers/staging/ramster/ramster/nodemanager.c
+++ b/drivers/staging/zcache/ramster/nodemanager.c
diff --git a/drivers/staging/ramster/ramster/nodemanager.h b/drivers/staging/zcache/ramster/nodemanager.h
index 41a04df5842c..41a04df5842c 100644
--- a/drivers/staging/ramster/ramster/nodemanager.h
+++ b/drivers/staging/zcache/ramster/nodemanager.h
diff --git a/drivers/staging/ramster/ramster/r2net.c b/drivers/staging/zcache/ramster/r2net.c
index 34818dc65612..34818dc65612 100644
--- a/drivers/staging/ramster/ramster/r2net.c
+++ b/drivers/staging/zcache/ramster/r2net.c
diff --git a/drivers/staging/ramster/ramster/ramster.c b/drivers/staging/zcache/ramster/ramster.c
index c06709f39682..bf96a1cbf7c1 100644
--- a/drivers/staging/ramster/ramster/ramster.c
+++ b/drivers/staging/zcache/ramster/ramster.c
@@ -67,25 +67,25 @@ static int ramster_remote_target_nodenum __read_mostly = -1;
67static long ramster_flnodes; 67static long ramster_flnodes;
68static atomic_t ramster_flnodes_atomic = ATOMIC_INIT(0); 68static atomic_t ramster_flnodes_atomic = ATOMIC_INIT(0);
69static unsigned long ramster_flnodes_max; 69static unsigned long ramster_flnodes_max;
70static long ramster_foreign_eph_pages; 70static ssize_t ramster_foreign_eph_pages;
71static atomic_t ramster_foreign_eph_pages_atomic = ATOMIC_INIT(0); 71static atomic_t ramster_foreign_eph_pages_atomic = ATOMIC_INIT(0);
72static unsigned long ramster_foreign_eph_pages_max; 72static ssize_t ramster_foreign_eph_pages_max;
73static long ramster_foreign_pers_pages; 73static ssize_t ramster_foreign_pers_pages;
74static atomic_t ramster_foreign_pers_pages_atomic = ATOMIC_INIT(0); 74static atomic_t ramster_foreign_pers_pages_atomic = ATOMIC_INIT(0);
75static unsigned long ramster_foreign_pers_pages_max; 75static ssize_t ramster_foreign_pers_pages_max;
76static unsigned long ramster_eph_pages_remoted; 76static ssize_t ramster_eph_pages_remoted;
77static unsigned long ramster_pers_pages_remoted; 77static ssize_t ramster_pers_pages_remoted;
78static unsigned long ramster_eph_pages_remote_failed; 78static ssize_t ramster_eph_pages_remote_failed;
79static unsigned long ramster_pers_pages_remote_failed; 79static ssize_t ramster_pers_pages_remote_failed;
80static unsigned long ramster_remote_eph_pages_succ_get; 80static ssize_t ramster_remote_eph_pages_succ_get;
81static unsigned long ramster_remote_pers_pages_succ_get; 81static ssize_t ramster_remote_pers_pages_succ_get;
82static unsigned long ramster_remote_eph_pages_unsucc_get; 82static ssize_t ramster_remote_eph_pages_unsucc_get;
83static unsigned long ramster_remote_pers_pages_unsucc_get; 83static ssize_t ramster_remote_pers_pages_unsucc_get;
84static unsigned long ramster_pers_pages_remote_nomem; 84static ssize_t ramster_pers_pages_remote_nomem;
85static unsigned long ramster_remote_objects_flushed; 85static ssize_t ramster_remote_objects_flushed;
86static unsigned long ramster_remote_object_flushes_failed; 86static ssize_t ramster_remote_object_flushes_failed;
87static unsigned long ramster_remote_pages_flushed; 87static ssize_t ramster_remote_pages_flushed;
88static unsigned long ramster_remote_page_flushes_failed; 88static ssize_t ramster_remote_page_flushes_failed;
89/* FIXME frontswap selfshrinking knobs in debugfs? */ 89/* FIXME frontswap selfshrinking knobs in debugfs? */
90 90
91#ifdef CONFIG_DEBUG_FS 91#ifdef CONFIG_DEBUG_FS
diff --git a/drivers/staging/ramster/ramster/ramster.h b/drivers/staging/zcache/ramster/ramster.h
index 12ae56f09ca4..12ae56f09ca4 100644
--- a/drivers/staging/ramster/ramster/ramster.h
+++ b/drivers/staging/zcache/ramster/ramster.h
diff --git a/drivers/staging/ramster/ramster/ramster_nodemanager.h b/drivers/staging/zcache/ramster/ramster_nodemanager.h
index 49f879d943ab..49f879d943ab 100644
--- a/drivers/staging/ramster/ramster/ramster_nodemanager.h
+++ b/drivers/staging/zcache/ramster/ramster_nodemanager.h
diff --git a/drivers/staging/ramster/ramster/tcp.c b/drivers/staging/zcache/ramster/tcp.c
index aa2a1a763aa4..aa2a1a763aa4 100644
--- a/drivers/staging/ramster/ramster/tcp.c
+++ b/drivers/staging/zcache/ramster/tcp.c
diff --git a/drivers/staging/ramster/ramster/tcp.h b/drivers/staging/zcache/ramster/tcp.h
index 9d05833452b5..9d05833452b5 100644
--- a/drivers/staging/ramster/ramster/tcp.h
+++ b/drivers/staging/zcache/ramster/tcp.h
diff --git a/drivers/staging/ramster/ramster/tcp_internal.h b/drivers/staging/zcache/ramster/tcp_internal.h
index 4d8cc9f96fd2..4d8cc9f96fd2 100644
--- a/drivers/staging/ramster/ramster/tcp_internal.h
+++ b/drivers/staging/zcache/ramster/tcp_internal.h
diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
index 56c8e606ad1c..a2b7e03b6062 100644
--- a/drivers/staging/zcache/tmem.c
+++ b/drivers/staging/zcache/tmem.c
@@ -1,32 +1,43 @@
1/* 1/*
2 * In-kernel transcendent memory (generic implementation) 2 * In-kernel transcendent memory (generic implementation)
3 * 3 *
4 * Copyright (c) 2009-2011, Dan Magenheimer, Oracle Corp. 4 * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp.
5 * 5 *
6 * The primary purpose of Transcendent Memory ("tmem") is to map object-oriented 6 * The primary purpose of Transcedent Memory ("tmem") is to map object-oriented
7 * "handles" (triples containing a pool id, and object id, and an index), to 7 * "handles" (triples containing a pool id, and object id, and an index), to
8 * pages in a page-accessible memory (PAM). Tmem references the PAM pages via 8 * pages in a page-accessible memory (PAM). Tmem references the PAM pages via
9 * an abstract "pampd" (PAM page-descriptor), which can be operated on by a 9 * an abstract "pampd" (PAM page-descriptor), which can be operated on by a
10 * set of functions (pamops). Each pampd contains some representation of 10 * set of functions (pamops). Each pampd contains some representation of
11 * PAGE_SIZE bytes worth of data. Tmem must support potentially millions of 11 * PAGE_SIZE bytes worth of data. For those familiar with key-value stores,
12 * pages and must be able to insert, find, and delete these pages at a 12 * the tmem handle is a three-level hierarchical key, and the value is always
13 * potential frequency of thousands per second concurrently across many CPUs, 13 * reconstituted (but not necessarily stored) as PAGE_SIZE bytes and is
14 * (and, if used with KVM, across many vcpus across many guests). 14 * referenced in the datastore by the pampd. The hierarchy is required
15 * Tmem is tracked with a hierarchy of data structures, organized by 15 * to ensure that certain invalidation functions can be performed efficiently
16 * the elements in a handle-tuple: pool_id, object_id, and page index. 16 * (i.e. flush all indexes associated with this object_id, or
17 * One or more "clients" (e.g. guests) each provide one or more tmem_pools. 17 * flush all objects associated with this pool).
18 * Each pool, contains a hash table of rb_trees of tmem_objs. Each 18 *
19 * tmem_obj contains a radix-tree-like tree of pointers, with intermediate 19 * Tmem must support potentially millions of pages and must be able to insert,
20 * nodes called tmem_objnodes. Each leaf pointer in this tree points to 20 * find, and delete these pages at a potential frequency of thousands per
21 * a pampd, which is accessible only through a small set of callbacks 21 * second concurrently across many CPUs, (and, if used with KVM, across many
22 * registered by the PAM implementation (see tmem_register_pamops). Tmem 22 * vcpus across many guests). Tmem is tracked with a hierarchy of data
23 * does all memory allocation via a set of callbacks registered by the tmem 23 * structures, organized by the elements in the handle-tuple: pool_id,
24 * host implementation (e.g. see tmem_register_hostops). 24 * object_id, and page index. One or more "clients" (e.g. guests) each
25 * provide one or more tmem_pools. Each pool, contains a hash table of
26 * rb_trees of tmem_objs. Each tmem_obj contains a radix-tree-like tree
27 * of pointers, with intermediate nodes called tmem_objnodes. Each leaf
28 * pointer in this tree points to a pampd, which is accessible only through
29 * a small set of callbacks registered by the PAM implementation (see
30 * tmem_register_pamops). Tmem only needs to memory allocation for objs
31 * and objnodes and this is done via a set of callbacks that must be
32 * registered by the tmem host implementation (e.g. see tmem_register_hostops).
25 */ 33 */
26 34
27#include <linux/list.h> 35#include <linux/list.h>
28#include <linux/spinlock.h> 36#include <linux/spinlock.h>
29#include <linux/atomic.h> 37#include <linux/atomic.h>
38#ifdef CONFIG_RAMSTER
39#include <linux/delay.h>
40#endif
30 41
31#include "tmem.h" 42#include "tmem.h"
32 43
@@ -51,7 +62,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
51 62
52/* 63/*
53 * A tmem host implementation must use this function to register 64 * A tmem host implementation must use this function to register
54 * callbacks for a page-accessible memory (PAM) implementation 65 * callbacks for a page-accessible memory (PAM) implementation.
55 */ 66 */
56static struct tmem_pamops tmem_pamops; 67static struct tmem_pamops tmem_pamops;
57 68
@@ -66,15 +77,22 @@ void tmem_register_pamops(struct tmem_pamops *m)
66 * So an rb_tree is an ideal data structure to manage tmem_objs. But because 77 * So an rb_tree is an ideal data structure to manage tmem_objs. But because
67 * of the potentially huge number of tmem_objs, each pool manages a hashtable 78 * of the potentially huge number of tmem_objs, each pool manages a hashtable
68 * of rb_trees to reduce search, insert, delete, and rebalancing time. 79 * of rb_trees to reduce search, insert, delete, and rebalancing time.
69 * Each hashbucket also has a lock to manage concurrent access. 80 * Each hashbucket also has a lock to manage concurrent access and no
81 * searches, inserts, or deletions can be performed unless the lock is held.
82 * As a result, care must be taken to ensure tmem routines are not called
83 * recursively; the vast majority of the time, a recursive call may work
84 * but a deadlock will occur a small fraction of the time due to the
85 * hashbucket lock.
70 * 86 *
71 * The following routines manage tmem_objs. When any tmem_obj is accessed, 87 * The following routines manage tmem_objs. In all of these routines,
72 * the hashbucket lock must be held. 88 * the hashbucket lock is already held.
73 */ 89 */
74 90
75static struct tmem_obj 91/* Search for object==oid in pool, returns object if found. */
76*__tmem_obj_find(struct tmem_hashbucket*hb, struct tmem_oid *oidp, 92static struct tmem_obj *__tmem_obj_find(struct tmem_hashbucket *hb,
77 struct rb_node **parent, struct rb_node ***link) 93 struct tmem_oid *oidp,
94 struct rb_node **parent,
95 struct rb_node ***link)
78{ 96{
79 struct rb_node *_parent = NULL, **rbnode; 97 struct rb_node *_parent = NULL, **rbnode;
80 struct tmem_obj *obj = NULL; 98 struct tmem_obj *obj = NULL;
@@ -101,23 +119,20 @@ static struct tmem_obj
101 *parent = _parent; 119 *parent = _parent;
102 if (link) 120 if (link)
103 *link = rbnode; 121 *link = rbnode;
104
105 obj = NULL; 122 obj = NULL;
106out: 123out:
107 return obj; 124 return obj;
108} 125}
109 126
110
111/* searches for object==oid in pool, returns locked object if found */
112static struct tmem_obj *tmem_obj_find(struct tmem_hashbucket *hb, 127static struct tmem_obj *tmem_obj_find(struct tmem_hashbucket *hb,
113 struct tmem_oid *oidp) 128 struct tmem_oid *oidp)
114{ 129{
115 return __tmem_obj_find(hb, oidp, NULL, NULL); 130 return __tmem_obj_find(hb, oidp, NULL, NULL);
116} 131}
117 132
118static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *); 133static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *, bool);
119 134
120/* free an object that has no more pampds in it */ 135/* Free an object that has no more pampds in it. */
121static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb) 136static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb)
122{ 137{
123 struct tmem_pool *pool; 138 struct tmem_pool *pool;
@@ -128,7 +143,7 @@ static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb)
128 pool = obj->pool; 143 pool = obj->pool;
129 BUG_ON(pool == NULL); 144 BUG_ON(pool == NULL);
130 if (obj->objnode_tree_root != NULL) /* may be "stump" with no leaves */ 145 if (obj->objnode_tree_root != NULL) /* may be "stump" with no leaves */
131 tmem_pampd_destroy_all_in_obj(obj); 146 tmem_pampd_destroy_all_in_obj(obj, false);
132 BUG_ON(obj->objnode_tree_root != NULL); 147 BUG_ON(obj->objnode_tree_root != NULL);
133 BUG_ON((long)obj->objnode_count != 0); 148 BUG_ON((long)obj->objnode_count != 0);
134 atomic_dec(&pool->obj_count); 149 atomic_dec(&pool->obj_count);
@@ -140,7 +155,7 @@ static void tmem_obj_free(struct tmem_obj *obj, struct tmem_hashbucket *hb)
140} 155}
141 156
142/* 157/*
143 * initialize, and insert an tmem_object_root (called only if find failed) 158 * Initialize, and insert an tmem_object_root (called only if find failed).
144 */ 159 */
145static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb, 160static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
146 struct tmem_pool *pool, 161 struct tmem_pool *pool,
@@ -157,7 +172,10 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
157 obj->oid = *oidp; 172 obj->oid = *oidp;
158 obj->objnode_count = 0; 173 obj->objnode_count = 0;
159 obj->pampd_count = 0; 174 obj->pampd_count = 0;
160 (*tmem_pamops.new_obj)(obj); 175#ifdef CONFIG_RAMSTER
176 if (tmem_pamops.new_obj != NULL)
177 (*tmem_pamops.new_obj)(obj);
178#endif
161 SET_SENTINEL(obj, OBJ); 179 SET_SENTINEL(obj, OBJ);
162 180
163 if (__tmem_obj_find(hb, oidp, &parent, &new)) 181 if (__tmem_obj_find(hb, oidp, &parent, &new))
@@ -172,7 +190,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
172 * "ephemeral" vs "persistent". These attributes apply to all tmem_objs 190 * "ephemeral" vs "persistent". These attributes apply to all tmem_objs
173 * and all pampds that belong to a tmem_pool. A tmem_pool is created 191 * and all pampds that belong to a tmem_pool. A tmem_pool is created
174 * or deleted relatively rarely (for example, when a filesystem is 192 * or deleted relatively rarely (for example, when a filesystem is
175 * mounted or unmounted. 193 * mounted or unmounted).
176 */ 194 */
177 195
178/* flush all data from a pool and, optionally, free it */ 196/* flush all data from a pool and, optionally, free it */
@@ -190,7 +208,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
190 while (rbnode != NULL) { 208 while (rbnode != NULL) {
191 obj = rb_entry(rbnode, struct tmem_obj, rb_tree_node); 209 obj = rb_entry(rbnode, struct tmem_obj, rb_tree_node);
192 rbnode = rb_next(rbnode); 210 rbnode = rb_next(rbnode);
193 tmem_pampd_destroy_all_in_obj(obj); 211 tmem_pampd_destroy_all_in_obj(obj, true);
194 tmem_obj_free(obj, hb); 212 tmem_obj_free(obj, hb);
195 (*tmem_hostops.obj_free)(obj, pool); 213 (*tmem_hostops.obj_free)(obj, pool);
196 } 214 }
@@ -276,7 +294,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
276} 294}
277 295
278/* 296/*
279 * lookup index in object and return associated pampd (or NULL if not found) 297 * Lookup index in object and return associated pampd (or NULL if not found).
280 */ 298 */
281static void **__tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index) 299static void **__tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index)
282{ 300{
@@ -318,8 +336,9 @@ static void *tmem_pampd_lookup_in_obj(struct tmem_obj *obj, uint32_t index)
318 return slot != NULL ? *slot : NULL; 336 return slot != NULL ? *slot : NULL;
319} 337}
320 338
339#ifdef CONFIG_RAMSTER
321static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index, 340static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
322 void *new_pampd) 341 void *new_pampd, bool no_free)
323{ 342{
324 struct tmem_objnode **slot; 343 struct tmem_objnode **slot;
325 void *ret = NULL; 344 void *ret = NULL;
@@ -328,11 +347,14 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
328 if ((slot != NULL) && (*slot != NULL)) { 347 if ((slot != NULL) && (*slot != NULL)) {
329 void *old_pampd = *(void **)slot; 348 void *old_pampd = *(void **)slot;
330 *(void **)slot = new_pampd; 349 *(void **)slot = new_pampd;
331 (*tmem_pamops.free)(old_pampd, obj->pool, NULL, 0); 350 if (!no_free)
351 (*tmem_pamops.free)(old_pampd, obj->pool,
352 NULL, 0, false);
332 ret = new_pampd; 353 ret = new_pampd;
333 } 354 }
334 return ret; 355 return ret;
335} 356}
357#endif
336 358
337static int tmem_pampd_add_to_obj(struct tmem_obj *obj, uint32_t index, 359static int tmem_pampd_add_to_obj(struct tmem_obj *obj, uint32_t index,
338 void *pampd) 360 void *pampd)
@@ -470,7 +492,7 @@ out:
470 return slot; 492 return slot;
471} 493}
472 494
473/* recursively walk the objnode_tree destroying pampds and objnodes */ 495/* Recursively walk the objnode_tree destroying pampds and objnodes. */
474static void tmem_objnode_node_destroy(struct tmem_obj *obj, 496static void tmem_objnode_node_destroy(struct tmem_obj *obj,
475 struct tmem_objnode *objnode, 497 struct tmem_objnode *objnode,
476 unsigned int ht) 498 unsigned int ht)
@@ -484,7 +506,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
484 if (ht == 1) { 506 if (ht == 1) {
485 obj->pampd_count--; 507 obj->pampd_count--;
486 (*tmem_pamops.free)(objnode->slots[i], 508 (*tmem_pamops.free)(objnode->slots[i],
487 obj->pool, NULL, 0); 509 obj->pool, NULL, 0, true);
488 objnode->slots[i] = NULL; 510 objnode->slots[i] = NULL;
489 continue; 511 continue;
490 } 512 }
@@ -495,13 +517,15 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
495 } 517 }
496} 518}
497 519
498static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj) 520static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
521 bool pool_destroy)
499{ 522{
500 if (obj->objnode_tree_root == NULL) 523 if (obj->objnode_tree_root == NULL)
501 return; 524 return;
502 if (obj->objnode_tree_height == 0) { 525 if (obj->objnode_tree_height == 0) {
503 obj->pampd_count--; 526 obj->pampd_count--;
504 (*tmem_pamops.free)(obj->objnode_tree_root, obj->pool, NULL, 0); 527 (*tmem_pamops.free)(obj->objnode_tree_root,
528 obj->pool, NULL, 0, true);
505 } else { 529 } else {
506 tmem_objnode_node_destroy(obj, obj->objnode_tree_root, 530 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
507 obj->objnode_tree_height); 531 obj->objnode_tree_height);
@@ -509,7 +533,10 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj)
509 obj->objnode_tree_height = 0; 533 obj->objnode_tree_height = 0;
510 } 534 }
511 obj->objnode_tree_root = NULL; 535 obj->objnode_tree_root = NULL;
512 (*tmem_pamops.free_obj)(obj->pool, obj); 536#ifdef CONFIG_RAMSTER
537 if (tmem_pamops.free_obj != NULL)
538 (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
539#endif
513} 540}
514 541
515/* 542/*
@@ -522,17 +549,16 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj)
522 */ 549 */
523 550
524/* 551/*
525 * "Put" a page, e.g. copy a page from the kernel into newly allocated 552 * "Put" a page, e.g. associate the passed pampd with the passed handle.
526 * PAM space (if such space is available). Tmem_put is complicated by 553 * Tmem_put is complicated by a corner case: What if a page with matching
527 * a corner case: What if a page with matching handle already exists in 554 * handle already exists in tmem? To guarantee coherency, one of two
528 * tmem? To guarantee coherency, one of two actions is necessary: Either 555 * actions is necessary: Either the data for the page must be overwritten,
529 * the data for the page must be overwritten, or the page must be 556 * or the page must be "flushed" so that the data is not accessible to a
530 * "flushed" so that the data is not accessible to a subsequent "get". 557 * subsequent "get". Since these "duplicate puts" are relatively rare,
531 * Since these "duplicate puts" are relatively rare, this implementation 558 * this implementation always flushes for simplicity.
532 * always flushes for simplicity.
533 */ 559 */
534int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, 560int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
535 char *data, size_t size, bool raw, bool ephemeral) 561 bool raw, void *pampd_to_use)
536{ 562{
537 struct tmem_obj *obj = NULL, *objfound = NULL, *objnew = NULL; 563 struct tmem_obj *obj = NULL, *objfound = NULL, *objnew = NULL;
538 void *pampd = NULL, *pampd_del = NULL; 564 void *pampd = NULL, *pampd_del = NULL;
@@ -548,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
548 /* if found, is a dup put, flush the old one */ 574 /* if found, is a dup put, flush the old one */
549 pampd_del = tmem_pampd_delete_from_obj(obj, index); 575 pampd_del = tmem_pampd_delete_from_obj(obj, index);
550 BUG_ON(pampd_del != pampd); 576 BUG_ON(pampd_del != pampd);
551 (*tmem_pamops.free)(pampd, pool, oidp, index); 577 (*tmem_pamops.free)(pampd, pool, oidp, index, true);
552 if (obj->pampd_count == 0) { 578 if (obj->pampd_count == 0) {
553 objnew = obj; 579 objnew = obj;
554 objfound = NULL; 580 objfound = NULL;
@@ -565,21 +591,19 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
565 } 591 }
566 BUG_ON(obj == NULL); 592 BUG_ON(obj == NULL);
567 BUG_ON(((objnew != obj) && (objfound != obj)) || (objnew == objfound)); 593 BUG_ON(((objnew != obj) && (objfound != obj)) || (objnew == objfound));
568 pampd = (*tmem_pamops.create)(data, size, raw, ephemeral, 594 pampd = pampd_to_use;
569 obj->pool, &obj->oid, index); 595 BUG_ON(pampd_to_use == NULL);
570 if (unlikely(pampd == NULL))
571 goto free;
572 ret = tmem_pampd_add_to_obj(obj, index, pampd); 596 ret = tmem_pampd_add_to_obj(obj, index, pampd);
573 if (unlikely(ret == -ENOMEM)) 597 if (unlikely(ret == -ENOMEM))
574 /* may have partially built objnode tree ("stump") */ 598 /* may have partially built objnode tree ("stump") */
575 goto delete_and_free; 599 goto delete_and_free;
600 (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
576 goto out; 601 goto out;
577 602
578delete_and_free: 603delete_and_free:
579 (void)tmem_pampd_delete_from_obj(obj, index); 604 (void)tmem_pampd_delete_from_obj(obj, index);
580free:
581 if (pampd) 605 if (pampd)
582 (*tmem_pamops.free)(pampd, pool, NULL, 0); 606 (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
583 if (objnew) { 607 if (objnew) {
584 tmem_obj_free(objnew, hb); 608 tmem_obj_free(objnew, hb);
585 (*tmem_hostops.obj_free)(objnew, pool); 609 (*tmem_hostops.obj_free)(objnew, pool);
@@ -589,35 +613,160 @@ out:
589 return ret; 613 return ret;
590} 614}
591 615
616#ifdef CONFIG_RAMSTER
617/*
618 * For ramster only: The following routines provide a two-step sequence
619 * to allow the caller to replace a pampd in the tmem data structures with
620 * another pampd. Here, we lookup the passed handle and, if found, return the
621 * associated pampd and object, leaving the hashbucket locked and returning
622 * a reference to it. The caller is expected to immediately call the
623 * matching tmem_localify_finish routine which will handles the replacement
624 * and unlocks the hashbucket.
625 */
626void *tmem_localify_get_pampd(struct tmem_pool *pool, struct tmem_oid *oidp,
627 uint32_t index, struct tmem_obj **ret_obj,
628 void **saved_hb)
629{
630 struct tmem_hashbucket *hb;
631 struct tmem_obj *obj = NULL;
632 void *pampd = NULL;
633
634 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
635 spin_lock(&hb->lock);
636 obj = tmem_obj_find(hb, oidp);
637 if (likely(obj != NULL))
638 pampd = tmem_pampd_lookup_in_obj(obj, index);
639 *ret_obj = obj;
640 *saved_hb = (void *)hb;
641 /* note, hashbucket remains locked */
642 return pampd;
643}
644
645void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
646 void *pampd, void *saved_hb, bool delete)
647{
648 struct tmem_hashbucket *hb = (struct tmem_hashbucket *)saved_hb;
649
650 BUG_ON(!spin_is_locked(&hb->lock));
651 if (pampd != NULL) {
652 BUG_ON(obj == NULL);
653 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
654 (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
655 } else if (delete) {
656 BUG_ON(obj == NULL);
657 (void)tmem_pampd_delete_from_obj(obj, index);
658 }
659 spin_unlock(&hb->lock);
660}
661
662/*
663 * For ramster only. Helper function to support asynchronous tmem_get.
664 */
665static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
666 struct tmem_pool *pool, struct tmem_oid *oidp,
667 uint32_t index, bool free, char *data)
668{
669 void *old_pampd = *ppampd, *new_pampd = NULL;
670 bool intransit = false;
671 int ret = 0;
672
673 if (!is_ephemeral(pool))
674 new_pampd = (*tmem_pamops.repatriate_preload)(
675 old_pampd, pool, oidp, index, &intransit);
676 if (intransit)
677 ret = -EAGAIN;
678 else if (new_pampd != NULL)
679 *ppampd = new_pampd;
680 /* must release the hb->lock else repatriate can't sleep */
681 spin_unlock(&hb->lock);
682 if (!intransit)
683 ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
684 oidp, index, free, data);
685 if (ret == -EAGAIN) {
686 /* rare I think, but should cond_resched()??? */
687 usleep_range(10, 1000);
688 } else if (ret == -ENOTCONN || ret == -EHOSTDOWN) {
689 ret = -1;
690 } else if (ret != 0 && ret != -ENOENT) {
691 ret = -1;
692 }
693 /* note hb->lock has now been unlocked */
694 return ret;
695}
696
592/* 697/*
593 * "Get" a page, e.g. if one can be found, copy the tmem page with the 698 * For ramster only. If a page in tmem matches the handle, replace the
594 * matching handle from PAM space to the kernel. By tmem definition, 699 * page so that any subsequent "get" gets the new page. Returns 0 if
595 * when a "get" is successful on an ephemeral page, the page is "flushed", 700 * there was a page to replace, else returns -1.
596 * and when a "get" is successful on a persistent page, the page is retained 701 */
597 * in tmem. Note that to preserve 702int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
703 uint32_t index, void *new_pampd)
704{
705 struct tmem_obj *obj;
706 int ret = -1;
707 struct tmem_hashbucket *hb;
708
709 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
710 spin_lock(&hb->lock);
711 obj = tmem_obj_find(hb, oidp);
712 if (obj == NULL)
713 goto out;
714 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
715 /* if we bug here, pamops wasn't properly set up for ramster */
716 BUG_ON(tmem_pamops.replace_in_obj == NULL);
717 ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
718out:
719 spin_unlock(&hb->lock);
720 return ret;
721}
722#endif
723
724/*
725 * "Get" a page, e.g. if a pampd can be found matching the passed handle,
726 * use a pamops callback to recreated the page from the pampd with the
727 * matching handle. By tmem definition, when a "get" is successful on
728 * an ephemeral page, the page is "flushed", and when a "get" is successful
729 * on a persistent page, the page is retained in tmem. Note that to preserve
598 * coherency, "get" can never be skipped if tmem contains the data. 730 * coherency, "get" can never be skipped if tmem contains the data.
599 * That is, if a get is done with a certain handle and fails, any 731 * That is, if a get is done with a certain handle and fails, any
600 * subsequent "get" must also fail (unless of course there is a 732 * subsequent "get" must also fail (unless of course there is a
601 * "put" done with the same handle). 733 * "put" done with the same handle).
602
603 */ 734 */
604int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index, 735int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
605 char *data, size_t *size, bool raw, int get_and_free) 736 char *data, size_t *sizep, bool raw, int get_and_free)
606{ 737{
607 struct tmem_obj *obj; 738 struct tmem_obj *obj;
608 void *pampd; 739 void *pampd = NULL;
609 bool ephemeral = is_ephemeral(pool); 740 bool ephemeral = is_ephemeral(pool);
610 int ret = -1; 741 int ret = -1;
611 struct tmem_hashbucket *hb; 742 struct tmem_hashbucket *hb;
612 bool free = (get_and_free == 1) || ((get_and_free == 0) && ephemeral); 743 bool free = (get_and_free == 1) || ((get_and_free == 0) && ephemeral);
613 bool lock_held = false; 744 bool lock_held = false;
745 void **ppampd;
614 746
615 hb = &pool->hashbucket[tmem_oid_hash(oidp)]; 747 do {
616 spin_lock(&hb->lock); 748 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
617 lock_held = true; 749 spin_lock(&hb->lock);
618 obj = tmem_obj_find(hb, oidp); 750 lock_held = true;
619 if (obj == NULL) 751 obj = tmem_obj_find(hb, oidp);
620 goto out; 752 if (obj == NULL)
753 goto out;
754 ppampd = __tmem_pampd_lookup_in_obj(obj, index);
755 if (ppampd == NULL)
756 goto out;
757#ifdef CONFIG_RAMSTER
758 if ((tmem_pamops.is_remote != NULL) &&
759 tmem_pamops.is_remote(*ppampd)) {
760 ret = tmem_repatriate(ppampd, hb, pool, oidp,
761 index, free, data);
762 /* tmem_repatriate releases hb->lock */
763 lock_held = false;
764 *sizep = PAGE_SIZE;
765 if (ret != -EAGAIN)
766 goto out;
767 }
768#endif
769 } while (ret == -EAGAIN);
621 if (free) 770 if (free)
622 pampd = tmem_pampd_delete_from_obj(obj, index); 771 pampd = tmem_pampd_delete_from_obj(obj, index);
623 else 772 else
@@ -631,16 +780,12 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
631 obj = NULL; 780 obj = NULL;
632 } 781 }
633 } 782 }
634 if (tmem_pamops.is_remote(pampd)) {
635 lock_held = false;
636 spin_unlock(&hb->lock);
637 }
638 if (free) 783 if (free)
639 ret = (*tmem_pamops.get_data_and_free)( 784 ret = (*tmem_pamops.get_data_and_free)(
640 data, size, raw, pampd, pool, oidp, index); 785 data, sizep, raw, pampd, pool, oidp, index);
641 else 786 else
642 ret = (*tmem_pamops.get_data)( 787 ret = (*tmem_pamops.get_data)(
643 data, size, raw, pampd, pool, oidp, index); 788 data, sizep, raw, pampd, pool, oidp, index);
644 if (ret < 0) 789 if (ret < 0)
645 goto out; 790 goto out;
646 ret = 0; 791 ret = 0;
@@ -671,7 +816,7 @@ int tmem_flush_page(struct tmem_pool *pool,
671 pampd = tmem_pampd_delete_from_obj(obj, index); 816 pampd = tmem_pampd_delete_from_obj(obj, index);
672 if (pampd == NULL) 817 if (pampd == NULL)
673 goto out; 818 goto out;
674 (*tmem_pamops.free)(pampd, pool, oidp, index); 819 (*tmem_pamops.free)(pampd, pool, oidp, index, true);
675 if (obj->pampd_count == 0) { 820 if (obj->pampd_count == 0) {
676 tmem_obj_free(obj, hb); 821 tmem_obj_free(obj, hb);
677 (*tmem_hostops.obj_free)(obj, pool); 822 (*tmem_hostops.obj_free)(obj, pool);
@@ -684,30 +829,6 @@ out:
684} 829}
685 830
686/* 831/*
687 * If a page in tmem matches the handle, replace the page so that any
688 * subsequent "get" gets the new page. Returns 0 if
689 * there was a page to replace, else returns -1.
690 */
691int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
692 uint32_t index, void *new_pampd)
693{
694 struct tmem_obj *obj;
695 int ret = -1;
696 struct tmem_hashbucket *hb;
697
698 hb = &pool->hashbucket[tmem_oid_hash(oidp)];
699 spin_lock(&hb->lock);
700 obj = tmem_obj_find(hb, oidp);
701 if (obj == NULL)
702 goto out;
703 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd);
704 ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
705out:
706 spin_unlock(&hb->lock);
707 return ret;
708}
709
710/*
711 * "Flush" all pages in tmem matching this oid. 832 * "Flush" all pages in tmem matching this oid.
712 */ 833 */
713int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp) 834int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
@@ -721,7 +842,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
721 obj = tmem_obj_find(hb, oidp); 842 obj = tmem_obj_find(hb, oidp);
722 if (obj == NULL) 843 if (obj == NULL)
723 goto out; 844 goto out;
724 tmem_pampd_destroy_all_in_obj(obj); 845 tmem_pampd_destroy_all_in_obj(obj, false);
725 tmem_obj_free(obj, hb); 846 tmem_obj_free(obj, hb);
726 (*tmem_hostops.obj_free)(obj, pool); 847 (*tmem_hostops.obj_free)(obj, pool);
727 ret = 0; 848 ret = 0;
diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
index 0d4aa82706b3..adbe5a8f28aa 100644
--- a/drivers/staging/zcache/tmem.h
+++ b/drivers/staging/zcache/tmem.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Transcendent memory 4 * Transcendent memory
5 * 5 *
6 * Copyright (c) 2009-2011, Dan Magenheimer, Oracle Corp. 6 * Copyright (c) 2009-2012, Dan Magenheimer, Oracle Corp.
7 */ 7 */
8 8
9#ifndef _TMEM_H_ 9#ifndef _TMEM_H_
@@ -15,12 +15,8 @@
15#include <linux/atomic.h> 15#include <linux/atomic.h>
16 16
17/* 17/*
18 * These are pre-defined by the Xen<->Linux ABI 18 * These are defined by the Xen<->Linux ABI so should remain consistent
19 */ 19 */
20#define TMEM_PUT_PAGE 4
21#define TMEM_GET_PAGE 5
22#define TMEM_FLUSH_PAGE 6
23#define TMEM_FLUSH_OBJECT 7
24#define TMEM_POOL_PERSIST 1 20#define TMEM_POOL_PERSIST 1
25#define TMEM_POOL_SHARED 2 21#define TMEM_POOL_SHARED 2
26#define TMEM_POOL_PRECOMPRESSED 4 22#define TMEM_POOL_PRECOMPRESSED 4
@@ -32,7 +28,7 @@
32 * sentinels have proven very useful for debugging but can be removed 28 * sentinels have proven very useful for debugging but can be removed
33 * or disabled before final merge. 29 * or disabled before final merge.
34 */ 30 */
35#define SENTINELS 31#undef SENTINELS
36#ifdef SENTINELS 32#ifdef SENTINELS
37#define DECL_SENTINEL uint32_t sentinel; 33#define DECL_SENTINEL uint32_t sentinel;
38#define SET_SENTINEL(_x, _y) (_x->sentinel = _y##_SENTINEL) 34#define SET_SENTINEL(_x, _y) (_x->sentinel = _y##_SENTINEL)
@@ -130,6 +126,34 @@ static inline unsigned tmem_oid_hash(struct tmem_oid *oidp)
130 TMEM_HASH_BUCKET_BITS); 126 TMEM_HASH_BUCKET_BITS);
131} 127}
132 128
129#ifdef CONFIG_RAMSTER
130struct tmem_xhandle {
131 uint8_t client_id;
132 uint8_t xh_data_cksum;
133 uint16_t xh_data_size;
134 uint16_t pool_id;
135 struct tmem_oid oid;
136 uint32_t index;
137 void *extra;
138};
139
140static inline struct tmem_xhandle tmem_xhandle_fill(uint16_t client_id,
141 struct tmem_pool *pool,
142 struct tmem_oid *oidp,
143 uint32_t index)
144{
145 struct tmem_xhandle xh;
146 xh.client_id = client_id;
147 xh.xh_data_cksum = (uint8_t)-1;
148 xh.xh_data_size = (uint16_t)-1;
149 xh.pool_id = pool->pool_id;
150 xh.oid = *oidp;
151 xh.index = index;
152 return xh;
153}
154#endif
155
156
133/* 157/*
134 * A tmem_obj contains an identifier (oid), pointers to the parent 158 * A tmem_obj contains an identifier (oid), pointers to the parent
135 * pool and the rb_tree to which it belongs, counters, and an ordered 159 * pool and the rb_tree to which it belongs, counters, and an ordered
@@ -147,7 +171,15 @@ struct tmem_obj {
147 unsigned int objnode_tree_height; 171 unsigned int objnode_tree_height;
148 unsigned long objnode_count; 172 unsigned long objnode_count;
149 long pampd_count; 173 long pampd_count;
174#ifdef CONFIG_RAMSTER
175 /*
176 * for current design of ramster, all pages belonging to
177 * an object reside on the same remotenode and extra is
178 * used to record the number of the remotenode so a
179 * flush-object operation can specify it
180 */
150 void *extra; /* for private use by pampd implementation */ 181 void *extra; /* for private use by pampd implementation */
182#endif
151 DECL_SENTINEL 183 DECL_SENTINEL
152}; 184};
153 185
@@ -165,20 +197,34 @@ struct tmem_objnode {
165 unsigned int slots_in_use; 197 unsigned int slots_in_use;
166}; 198};
167 199
200struct tmem_handle {
201 struct tmem_oid oid; /* 24 bytes */
202 uint32_t index;
203 uint16_t pool_id;
204 uint16_t client_id;
205};
206
207
168/* pampd abstract datatype methods provided by the PAM implementation */ 208/* pampd abstract datatype methods provided by the PAM implementation */
169struct tmem_pamops { 209struct tmem_pamops {
170 void *(*create)(char *, size_t, bool, int, 210 void (*create_finish)(void *, bool);
171 struct tmem_pool *, struct tmem_oid *, uint32_t);
172 int (*get_data)(char *, size_t *, bool, void *, struct tmem_pool *, 211 int (*get_data)(char *, size_t *, bool, void *, struct tmem_pool *,
173 struct tmem_oid *, uint32_t); 212 struct tmem_oid *, uint32_t);
174 int (*get_data_and_free)(char *, size_t *, bool, void *, 213 int (*get_data_and_free)(char *, size_t *, bool, void *,
175 struct tmem_pool *, struct tmem_oid *, 214 struct tmem_pool *, struct tmem_oid *,
176 uint32_t); 215 uint32_t);
177 void (*free)(void *, struct tmem_pool *, struct tmem_oid *, uint32_t); 216 void (*free)(void *, struct tmem_pool *,
178 void (*free_obj)(struct tmem_pool *, struct tmem_obj *); 217 struct tmem_oid *, uint32_t, bool);
179 bool (*is_remote)(void *); 218#ifdef CONFIG_RAMSTER
180 void (*new_obj)(struct tmem_obj *); 219 void (*new_obj)(struct tmem_obj *);
220 void (*free_obj)(struct tmem_pool *, struct tmem_obj *, bool);
221 void *(*repatriate_preload)(void *, struct tmem_pool *,
222 struct tmem_oid *, uint32_t, bool *);
223 int (*repatriate)(void *, void *, struct tmem_pool *,
224 struct tmem_oid *, uint32_t, bool, void *);
225 bool (*is_remote)(void *);
181 int (*replace_in_obj)(void *, struct tmem_obj *); 226 int (*replace_in_obj)(void *, struct tmem_obj *);
227#endif
182}; 228};
183extern void tmem_register_pamops(struct tmem_pamops *m); 229extern void tmem_register_pamops(struct tmem_pamops *m);
184 230
@@ -193,14 +239,21 @@ extern void tmem_register_hostops(struct tmem_hostops *m);
193 239
194/* core tmem accessor functions */ 240/* core tmem accessor functions */
195extern int tmem_put(struct tmem_pool *, struct tmem_oid *, uint32_t index, 241extern int tmem_put(struct tmem_pool *, struct tmem_oid *, uint32_t index,
196 char *, size_t, bool, bool); 242 bool, void *);
197extern int tmem_get(struct tmem_pool *, struct tmem_oid *, uint32_t index, 243extern int tmem_get(struct tmem_pool *, struct tmem_oid *, uint32_t index,
198 char *, size_t *, bool, int); 244 char *, size_t *, bool, int);
199extern int tmem_replace(struct tmem_pool *, struct tmem_oid *, uint32_t index,
200 void *);
201extern int tmem_flush_page(struct tmem_pool *, struct tmem_oid *, 245extern int tmem_flush_page(struct tmem_pool *, struct tmem_oid *,
202 uint32_t index); 246 uint32_t index);
203extern int tmem_flush_object(struct tmem_pool *, struct tmem_oid *); 247extern int tmem_flush_object(struct tmem_pool *, struct tmem_oid *);
204extern int tmem_destroy_pool(struct tmem_pool *); 248extern int tmem_destroy_pool(struct tmem_pool *);
205extern void tmem_new_pool(struct tmem_pool *, uint32_t); 249extern void tmem_new_pool(struct tmem_pool *, uint32_t);
250#ifdef CONFIG_RAMSTER
251extern int tmem_replace(struct tmem_pool *, struct tmem_oid *, uint32_t index,
252 void *);
253extern void *tmem_localify_get_pampd(struct tmem_pool *, struct tmem_oid *,
254 uint32_t index, struct tmem_obj **,
255 void **);
256extern void tmem_localify_finish(struct tmem_obj *, uint32_t index,
257 void *, void *, bool);
258#endif
206#endif /* _TMEM_H */ 259#endif /* _TMEM_H */
diff --git a/drivers/staging/ramster/zbud.c b/drivers/staging/zcache/zbud.c
index a7c436127aa1..328c397ea5dc 100644
--- a/drivers/staging/ramster/zbud.c
+++ b/drivers/staging/zcache/zbud.c
@@ -103,8 +103,8 @@ struct zbudpage {
103 struct { 103 struct {
104 unsigned long space_for_flags; 104 unsigned long space_for_flags;
105 struct { 105 struct {
106 unsigned zbud0_size:12; 106 unsigned zbud0_size:PAGE_SHIFT;
107 unsigned zbud1_size:12; 107 unsigned zbud1_size:PAGE_SHIFT;
108 unsigned unevictable:2; 108 unsigned unevictable:2;
109 }; 109 };
110 struct list_head budlist; 110 struct list_head budlist;
@@ -112,6 +112,9 @@ struct zbudpage {
112 }; 112 };
113 }; 113 };
114}; 114};
115#if (PAGE_SHIFT * 2) + 2 > BITS_PER_LONG
116#error "zbud won't work for this arch, PAGE_SIZE is too large"
117#endif
115 118
116struct zbudref { 119struct zbudref {
117 union { 120 union {
@@ -278,26 +281,26 @@ static inline char *zbud_data(void *zbpg,
278 * debugfs viewers, some of these should also be atomic_long_t, but 281 * debugfs viewers, some of these should also be atomic_long_t, but
279 * I don't know how to expose atomics via debugfs either... 282 * I don't know how to expose atomics via debugfs either...
280 */ 283 */
281static unsigned long zbud_eph_pageframes; 284static ssize_t zbud_eph_pageframes;
282static unsigned long zbud_pers_pageframes; 285static ssize_t zbud_pers_pageframes;
283static unsigned long zbud_eph_zpages; 286static ssize_t zbud_eph_zpages;
284static unsigned long zbud_pers_zpages; 287static ssize_t zbud_pers_zpages;
285static u64 zbud_eph_zbytes; 288static u64 zbud_eph_zbytes;
286static u64 zbud_pers_zbytes; 289static u64 zbud_pers_zbytes;
287static unsigned long zbud_eph_evicted_pageframes; 290static ssize_t zbud_eph_evicted_pageframes;
288static unsigned long zbud_pers_evicted_pageframes; 291static ssize_t zbud_pers_evicted_pageframes;
289static unsigned long zbud_eph_cumul_zpages; 292static ssize_t zbud_eph_cumul_zpages;
290static unsigned long zbud_pers_cumul_zpages; 293static ssize_t zbud_pers_cumul_zpages;
291static u64 zbud_eph_cumul_zbytes; 294static u64 zbud_eph_cumul_zbytes;
292static u64 zbud_pers_cumul_zbytes; 295static u64 zbud_pers_cumul_zbytes;
293static unsigned long zbud_eph_cumul_chunk_counts[NCHUNKS]; 296static ssize_t zbud_eph_cumul_chunk_counts[NCHUNKS];
294static unsigned long zbud_pers_cumul_chunk_counts[NCHUNKS]; 297static ssize_t zbud_pers_cumul_chunk_counts[NCHUNKS];
295static unsigned long zbud_eph_buddied_count; 298static ssize_t zbud_eph_buddied_count;
296static unsigned long zbud_pers_buddied_count; 299static ssize_t zbud_pers_buddied_count;
297static unsigned long zbud_eph_unbuddied_count; 300static ssize_t zbud_eph_unbuddied_count;
298static unsigned long zbud_pers_unbuddied_count; 301static ssize_t zbud_pers_unbuddied_count;
299static unsigned long zbud_eph_zombie_count; 302static ssize_t zbud_eph_zombie_count;
300static unsigned long zbud_pers_zombie_count; 303static ssize_t zbud_pers_zombie_count;
301static atomic_t zbud_eph_zombie_atomic; 304static atomic_t zbud_eph_zombie_atomic;
302static atomic_t zbud_pers_zombie_atomic; 305static atomic_t zbud_pers_zombie_atomic;
303 306
@@ -1044,7 +1047,7 @@ out:
1044 return ret; 1047 return ret;
1045} 1048}
1046 1049
1047void __init zbud_init(void) 1050void zbud_init(void)
1048{ 1051{
1049 int i; 1052 int i;
1050 1053
diff --git a/drivers/staging/ramster/zbud.h b/drivers/staging/zcache/zbud.h
index 891e8a7d5aa5..891e8a7d5aa5 100644
--- a/drivers/staging/ramster/zbud.h
+++ b/drivers/staging/zcache/zbud.h
diff --git a/drivers/staging/zcache/zcache-main.c b/drivers/staging/zcache/zcache-main.c
index 52b43b7b83d7..328898ea76c3 100644
--- a/drivers/staging/zcache/zcache-main.c
+++ b/drivers/staging/zcache/zcache-main.c
@@ -1,23 +1,15 @@
1/* 1/*
2 * zcache.c 2 * zcache.c
3 * 3 *
4 * Copyright (c) 2010,2011, Dan Magenheimer, Oracle Corp. 4 * Copyright (c) 2010-2012, Dan Magenheimer, Oracle Corp.
5 * Copyright (c) 2010,2011, Nitin Gupta 5 * Copyright (c) 2010,2011, Nitin Gupta
6 * 6 *
7 * Zcache provides an in-kernel "host implementation" for transcendent memory 7 * Zcache provides an in-kernel "host implementation" for transcendent memory
8 * and, thus indirectly, for cleancache and frontswap. Zcache includes two 8 * ("tmem") and, thus indirectly, for cleancache and frontswap. Zcache uses
9 * page-accessible memory [1] interfaces, both utilizing the crypto compression 9 * lzo1x compression to improve density and an embedded allocator called
10 * API: 10 * "zbud" which "buddies" two compressed pages semi-optimally in each physical
11 * 1) "compression buddies" ("zbud") is used for ephemeral pages 11 * pageframe. Zbud is integrally tied into tmem to allow pageframes to
12 * 2) zsmalloc is used for persistent pages. 12 * be "reclaimed" efficiently.
13 * Xvmalloc (based on the TLSF allocator) has very low fragmentation
14 * so maximizes space efficiency, while zbud allows pairs (and potentially,
15 * in the future, more than a pair of) compressed pages to be closely linked
16 * so that reclaiming can be done via the kernel's physical-page-oriented
17 * "shrinker" interface.
18 *
19 * [1] For a definition of page-accessible memory (aka PAM), see:
20 * http://marc.info/?l=linux-mm&m=127811271605009
21 */ 13 */
22 14
23#include <linux/module.h> 15#include <linux/module.h>
@@ -30,70 +22,62 @@
30#include <linux/atomic.h> 22#include <linux/atomic.h>
31#include <linux/math64.h> 23#include <linux/math64.h>
32#include <linux/crypto.h> 24#include <linux/crypto.h>
33#include <linux/string.h> 25#include <linux/swap.h>
34#include <linux/idr.h> 26#include <linux/swapops.h>
35#include "tmem.h" 27#include <linux/pagemap.h>
36 28#include <linux/writeback.h>
37#include "../zsmalloc/zsmalloc.h"
38 29
39#ifdef CONFIG_CLEANCACHE
40#include <linux/cleancache.h> 30#include <linux/cleancache.h>
41#endif
42#ifdef CONFIG_FRONTSWAP
43#include <linux/frontswap.h> 31#include <linux/frontswap.h>
44#endif 32#include "tmem.h"
45 33#include "zcache.h"
46#if 0 34#include "zbud.h"
47/* this is more aggressive but may cause other problems? */ 35#include "ramster.h"
48#define ZCACHE_GFP_MASK (GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN) 36#ifdef CONFIG_RAMSTER
37static int ramster_enabled;
49#else 38#else
50#define ZCACHE_GFP_MASK \ 39#define ramster_enabled 0
51 (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC)
52#endif 40#endif
53 41
54#define MAX_CLIENTS 16 42#ifndef __PG_WAS_ACTIVE
55#define LOCAL_CLIENT ((uint16_t)-1) 43static inline bool PageWasActive(struct page *page)
56
57MODULE_LICENSE("GPL");
58
59struct zcache_client {
60 struct idr tmem_pools;
61 struct zs_pool *zspool;
62 bool allocated;
63 atomic_t refcount;
64};
65
66static struct zcache_client zcache_host;
67static struct zcache_client zcache_clients[MAX_CLIENTS];
68
69static inline uint16_t get_client_id_from_client(struct zcache_client *cli)
70{ 44{
71 BUG_ON(cli == NULL); 45 return true;
72 if (cli == &zcache_host)
73 return LOCAL_CLIENT;
74 return cli - &zcache_clients[0];
75} 46}
76 47
77static struct zcache_client *get_zcache_client(uint16_t cli_id) 48static inline void SetPageWasActive(struct page *page)
78{ 49{
79 if (cli_id == LOCAL_CLIENT)
80 return &zcache_host;
81
82 if ((unsigned int)cli_id < MAX_CLIENTS)
83 return &zcache_clients[cli_id];
84
85 return NULL;
86} 50}
51#endif
87 52
88static inline bool is_local_client(struct zcache_client *cli) 53#ifdef FRONTSWAP_HAS_EXCLUSIVE_GETS
54static bool frontswap_has_exclusive_gets __read_mostly = true;
55#else
56static bool frontswap_has_exclusive_gets __read_mostly;
57static inline void frontswap_tmem_exclusive_gets(bool b)
89{ 58{
90 return cli == &zcache_host;
91} 59}
60#endif
61
62/* enable (or fix code) when Seth's patches are accepted upstream */
63#define zcache_writeback_enabled 0
64
65static int zcache_enabled __read_mostly;
66static int disable_cleancache __read_mostly;
67static int disable_frontswap __read_mostly;
68static int disable_frontswap_ignore_nonactive __read_mostly;
69static int disable_cleancache_ignore_nonactive __read_mostly;
70static char *namestr __read_mostly = "zcache";
71
72#define ZCACHE_GFP_MASK \
73 (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC)
74
75MODULE_LICENSE("GPL");
92 76
93/* crypto API for zcache */ 77/* crypto API for zcache */
94#define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME 78#define ZCACHE_COMP_NAME_SZ CRYPTO_MAX_ALG_NAME
95static char zcache_comp_name[ZCACHE_COMP_NAME_SZ]; 79static char zcache_comp_name[ZCACHE_COMP_NAME_SZ] __read_mostly;
96static struct crypto_comp * __percpu *zcache_comp_pcpu_tfms; 80static struct crypto_comp * __percpu *zcache_comp_pcpu_tfms __read_mostly;
97 81
98enum comp_op { 82enum comp_op {
99 ZCACHE_COMPOP_COMPRESS, 83 ZCACHE_COMPOP_COMPRESS,
@@ -105,7 +89,7 @@ static inline int zcache_comp_op(enum comp_op op,
105 u8 *dst, unsigned int *dlen) 89 u8 *dst, unsigned int *dlen)
106{ 90{
107 struct crypto_comp *tfm; 91 struct crypto_comp *tfm;
108 int ret; 92 int ret = -1;
109 93
110 BUG_ON(!zcache_comp_pcpu_tfms); 94 BUG_ON(!zcache_comp_pcpu_tfms);
111 tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, get_cpu()); 95 tfm = *per_cpu_ptr(zcache_comp_pcpu_tfms, get_cpu());
@@ -124,816 +108,247 @@ static inline int zcache_comp_op(enum comp_op op,
124 return ret; 108 return ret;
125} 109}
126 110
127/**********
128 * Compression buddies ("zbud") provides for packing two (or, possibly
129 * in the future, more) compressed ephemeral pages into a single "raw"
130 * (physical) page and tracking them with data structures so that
131 * the raw pages can be easily reclaimed.
132 *
133 * A zbud page ("zbpg") is an aligned page containing a list_head,
134 * a lock, and two "zbud headers". The remainder of the physical
135 * page is divided up into aligned 64-byte "chunks" which contain
136 * the compressed data for zero, one, or two zbuds. Each zbpg
137 * resides on: (1) an "unused list" if it has no zbuds; (2) a
138 * "buddied" list if it is fully populated with two zbuds; or
139 * (3) one of PAGE_SIZE/64 "unbuddied" lists indexed by how many chunks
140 * the one unbuddied zbud uses. The data inside a zbpg cannot be
141 * read or written unless the zbpg's lock is held.
142 */
143
144#define ZBH_SENTINEL 0x43214321
145#define ZBPG_SENTINEL 0xdeadbeef
146
147#define ZBUD_MAX_BUDS 2
148
149struct zbud_hdr {
150 uint16_t client_id;
151 uint16_t pool_id;
152 struct tmem_oid oid;
153 uint32_t index;
154 uint16_t size; /* compressed size in bytes, zero means unused */
155 DECL_SENTINEL
156};
157
158struct zbud_page {
159 struct list_head bud_list;
160 spinlock_t lock;
161 struct zbud_hdr buddy[ZBUD_MAX_BUDS];
162 DECL_SENTINEL
163 /* followed by NUM_CHUNK aligned CHUNK_SIZE-byte chunks */
164};
165
166#define CHUNK_SHIFT 6
167#define CHUNK_SIZE (1 << CHUNK_SHIFT)
168#define CHUNK_MASK (~(CHUNK_SIZE-1))
169#define NCHUNKS (((PAGE_SIZE - sizeof(struct zbud_page)) & \
170 CHUNK_MASK) >> CHUNK_SHIFT)
171#define MAX_CHUNK (NCHUNKS-1)
172
173static struct {
174 struct list_head list;
175 unsigned count;
176} zbud_unbuddied[NCHUNKS];
177/* list N contains pages with N chunks USED and NCHUNKS-N unused */
178/* element 0 is never used but optimizing that isn't worth it */
179static unsigned long zbud_cumul_chunk_counts[NCHUNKS];
180
181struct list_head zbud_buddied_list;
182static unsigned long zcache_zbud_buddied_count;
183
184/* protects the buddied list and all unbuddied lists */
185static DEFINE_SPINLOCK(zbud_budlists_spinlock);
186
187static LIST_HEAD(zbpg_unused_list);
188static unsigned long zcache_zbpg_unused_list_count;
189
190/* protects the unused page list */
191static DEFINE_SPINLOCK(zbpg_unused_list_spinlock);
192
193static atomic_t zcache_zbud_curr_raw_pages;
194static atomic_t zcache_zbud_curr_zpages;
195static unsigned long zcache_zbud_curr_zbytes;
196static unsigned long zcache_zbud_cumul_zpages;
197static unsigned long zcache_zbud_cumul_zbytes;
198static unsigned long zcache_compress_poor;
199static unsigned long zcache_mean_compress_poor;
200
201/* forward references */
202static void *zcache_get_free_page(void);
203static void zcache_free_page(void *p);
204
205/*
206 * zbud helper functions
207 */
208
209static inline unsigned zbud_max_buddy_size(void)
210{
211 return MAX_CHUNK << CHUNK_SHIFT;
212}
213
214static inline unsigned zbud_size_to_chunks(unsigned size)
215{
216 BUG_ON(size == 0 || size > zbud_max_buddy_size());
217 return (size + CHUNK_SIZE - 1) >> CHUNK_SHIFT;
218}
219
220static inline int zbud_budnum(struct zbud_hdr *zh)
221{
222 unsigned offset = (unsigned long)zh & (PAGE_SIZE - 1);
223 struct zbud_page *zbpg = NULL;
224 unsigned budnum = -1U;
225 int i;
226
227 for (i = 0; i < ZBUD_MAX_BUDS; i++)
228 if (offset == offsetof(typeof(*zbpg), buddy[i])) {
229 budnum = i;
230 break;
231 }
232 BUG_ON(budnum == -1U);
233 return budnum;
234}
235
236static char *zbud_data(struct zbud_hdr *zh, unsigned size)
237{
238 struct zbud_page *zbpg;
239 char *p;
240 unsigned budnum;
241
242 ASSERT_SENTINEL(zh, ZBH);
243 budnum = zbud_budnum(zh);
244 BUG_ON(size == 0 || size > zbud_max_buddy_size());
245 zbpg = container_of(zh, struct zbud_page, buddy[budnum]);
246 ASSERT_SPINLOCK(&zbpg->lock);
247 p = (char *)zbpg;
248 if (budnum == 0)
249 p += ((sizeof(struct zbud_page) + CHUNK_SIZE - 1) &
250 CHUNK_MASK);
251 else if (budnum == 1)
252 p += PAGE_SIZE - ((size + CHUNK_SIZE - 1) & CHUNK_MASK);
253 return p;
254}
255
256/*
257 * zbud raw page management
258 */
259
260static struct zbud_page *zbud_alloc_raw_page(void)
261{
262 struct zbud_page *zbpg = NULL;
263 struct zbud_hdr *zh0, *zh1;
264 bool recycled = 0;
265
266 /* if any pages on the zbpg list, use one */
267 spin_lock(&zbpg_unused_list_spinlock);
268 if (!list_empty(&zbpg_unused_list)) {
269 zbpg = list_first_entry(&zbpg_unused_list,
270 struct zbud_page, bud_list);
271 list_del_init(&zbpg->bud_list);
272 zcache_zbpg_unused_list_count--;
273 recycled = 1;
274 }
275 spin_unlock(&zbpg_unused_list_spinlock);
276 if (zbpg == NULL)
277 /* none on zbpg list, try to get a kernel page */
278 zbpg = zcache_get_free_page();
279 if (likely(zbpg != NULL)) {
280 INIT_LIST_HEAD(&zbpg->bud_list);
281 zh0 = &zbpg->buddy[0]; zh1 = &zbpg->buddy[1];
282 spin_lock_init(&zbpg->lock);
283 if (recycled) {
284 ASSERT_INVERTED_SENTINEL(zbpg, ZBPG);
285 SET_SENTINEL(zbpg, ZBPG);
286 BUG_ON(zh0->size != 0 || tmem_oid_valid(&zh0->oid));
287 BUG_ON(zh1->size != 0 || tmem_oid_valid(&zh1->oid));
288 } else {
289 atomic_inc(&zcache_zbud_curr_raw_pages);
290 INIT_LIST_HEAD(&zbpg->bud_list);
291 SET_SENTINEL(zbpg, ZBPG);
292 zh0->size = 0; zh1->size = 0;
293 tmem_oid_set_invalid(&zh0->oid);
294 tmem_oid_set_invalid(&zh1->oid);
295 }
296 }
297 return zbpg;
298}
299
300static void zbud_free_raw_page(struct zbud_page *zbpg)
301{
302 struct zbud_hdr *zh0 = &zbpg->buddy[0], *zh1 = &zbpg->buddy[1];
303
304 ASSERT_SENTINEL(zbpg, ZBPG);
305 BUG_ON(!list_empty(&zbpg->bud_list));
306 ASSERT_SPINLOCK(&zbpg->lock);
307 BUG_ON(zh0->size != 0 || tmem_oid_valid(&zh0->oid));
308 BUG_ON(zh1->size != 0 || tmem_oid_valid(&zh1->oid));
309 INVERT_SENTINEL(zbpg, ZBPG);
310 spin_unlock(&zbpg->lock);
311 spin_lock(&zbpg_unused_list_spinlock);
312 list_add(&zbpg->bud_list, &zbpg_unused_list);
313 zcache_zbpg_unused_list_count++;
314 spin_unlock(&zbpg_unused_list_spinlock);
315}
316
317/*
318 * core zbud handling routines
319 */
320
321static unsigned zbud_free(struct zbud_hdr *zh)
322{
323 unsigned size;
324
325 ASSERT_SENTINEL(zh, ZBH);
326 BUG_ON(!tmem_oid_valid(&zh->oid));
327 size = zh->size;
328 BUG_ON(zh->size == 0 || zh->size > zbud_max_buddy_size());
329 zh->size = 0;
330 tmem_oid_set_invalid(&zh->oid);
331 INVERT_SENTINEL(zh, ZBH);
332 zcache_zbud_curr_zbytes -= size;
333 atomic_dec(&zcache_zbud_curr_zpages);
334 return size;
335}
336
337static void zbud_free_and_delist(struct zbud_hdr *zh)
338{
339 unsigned chunks;
340 struct zbud_hdr *zh_other;
341 unsigned budnum = zbud_budnum(zh), size;
342 struct zbud_page *zbpg =
343 container_of(zh, struct zbud_page, buddy[budnum]);
344
345 spin_lock(&zbud_budlists_spinlock);
346 spin_lock(&zbpg->lock);
347 if (list_empty(&zbpg->bud_list)) {
348 /* ignore zombie page... see zbud_evict_pages() */
349 spin_unlock(&zbpg->lock);
350 spin_unlock(&zbud_budlists_spinlock);
351 return;
352 }
353 size = zbud_free(zh);
354 ASSERT_SPINLOCK(&zbpg->lock);
355 zh_other = &zbpg->buddy[(budnum == 0) ? 1 : 0];
356 if (zh_other->size == 0) { /* was unbuddied: unlist and free */
357 chunks = zbud_size_to_chunks(size) ;
358 BUG_ON(list_empty(&zbud_unbuddied[chunks].list));
359 list_del_init(&zbpg->bud_list);
360 zbud_unbuddied[chunks].count--;
361 spin_unlock(&zbud_budlists_spinlock);
362 zbud_free_raw_page(zbpg);
363 } else { /* was buddied: move remaining buddy to unbuddied list */
364 chunks = zbud_size_to_chunks(zh_other->size) ;
365 list_del_init(&zbpg->bud_list);
366 zcache_zbud_buddied_count--;
367 list_add_tail(&zbpg->bud_list, &zbud_unbuddied[chunks].list);
368 zbud_unbuddied[chunks].count++;
369 spin_unlock(&zbud_budlists_spinlock);
370 spin_unlock(&zbpg->lock);
371 }
372}
373
374static struct zbud_hdr *zbud_create(uint16_t client_id, uint16_t pool_id,
375 struct tmem_oid *oid,
376 uint32_t index, struct page *page,
377 void *cdata, unsigned size)
378{
379 struct zbud_hdr *zh0, *zh1, *zh = NULL;
380 struct zbud_page *zbpg = NULL, *ztmp;
381 unsigned nchunks;
382 char *to;
383 int i, found_good_buddy = 0;
384
385 nchunks = zbud_size_to_chunks(size) ;
386 for (i = MAX_CHUNK - nchunks + 1; i > 0; i--) {
387 spin_lock(&zbud_budlists_spinlock);
388 if (!list_empty(&zbud_unbuddied[i].list)) {
389 list_for_each_entry_safe(zbpg, ztmp,
390 &zbud_unbuddied[i].list, bud_list) {
391 if (spin_trylock(&zbpg->lock)) {
392 found_good_buddy = i;
393 goto found_unbuddied;
394 }
395 }
396 }
397 spin_unlock(&zbud_budlists_spinlock);
398 }
399 /* didn't find a good buddy, try allocating a new page */
400 zbpg = zbud_alloc_raw_page();
401 if (unlikely(zbpg == NULL))
402 goto out;
403 /* ok, have a page, now compress the data before taking locks */
404 spin_lock(&zbud_budlists_spinlock);
405 spin_lock(&zbpg->lock);
406 list_add_tail(&zbpg->bud_list, &zbud_unbuddied[nchunks].list);
407 zbud_unbuddied[nchunks].count++;
408 zh = &zbpg->buddy[0];
409 goto init_zh;
410
411found_unbuddied:
412 ASSERT_SPINLOCK(&zbpg->lock);
413 zh0 = &zbpg->buddy[0]; zh1 = &zbpg->buddy[1];
414 BUG_ON(!((zh0->size == 0) ^ (zh1->size == 0)));
415 if (zh0->size != 0) { /* buddy0 in use, buddy1 is vacant */
416 ASSERT_SENTINEL(zh0, ZBH);
417 zh = zh1;
418 } else if (zh1->size != 0) { /* buddy1 in use, buddy0 is vacant */
419 ASSERT_SENTINEL(zh1, ZBH);
420 zh = zh0;
421 } else
422 BUG();
423 list_del_init(&zbpg->bud_list);
424 zbud_unbuddied[found_good_buddy].count--;
425 list_add_tail(&zbpg->bud_list, &zbud_buddied_list);
426 zcache_zbud_buddied_count++;
427
428init_zh:
429 SET_SENTINEL(zh, ZBH);
430 zh->size = size;
431 zh->index = index;
432 zh->oid = *oid;
433 zh->pool_id = pool_id;
434 zh->client_id = client_id;
435 to = zbud_data(zh, size);
436 memcpy(to, cdata, size);
437 spin_unlock(&zbpg->lock);
438 spin_unlock(&zbud_budlists_spinlock);
439
440 zbud_cumul_chunk_counts[nchunks]++;
441 atomic_inc(&zcache_zbud_curr_zpages);
442 zcache_zbud_cumul_zpages++;
443 zcache_zbud_curr_zbytes += size;
444 zcache_zbud_cumul_zbytes += size;
445out:
446 return zh;
447}
448
449static int zbud_decompress(struct page *page, struct zbud_hdr *zh)
450{
451 struct zbud_page *zbpg;
452 unsigned budnum = zbud_budnum(zh);
453 unsigned int out_len = PAGE_SIZE;
454 char *to_va, *from_va;
455 unsigned size;
456 int ret = 0;
457
458 zbpg = container_of(zh, struct zbud_page, buddy[budnum]);
459 spin_lock(&zbpg->lock);
460 if (list_empty(&zbpg->bud_list)) {
461 /* ignore zombie page... see zbud_evict_pages() */
462 ret = -EINVAL;
463 goto out;
464 }
465 ASSERT_SENTINEL(zh, ZBH);
466 BUG_ON(zh->size == 0 || zh->size > zbud_max_buddy_size());
467 to_va = kmap_atomic(page);
468 size = zh->size;
469 from_va = zbud_data(zh, size);
470 ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, from_va, size,
471 to_va, &out_len);
472 BUG_ON(ret);
473 BUG_ON(out_len != PAGE_SIZE);
474 kunmap_atomic(to_va);
475out:
476 spin_unlock(&zbpg->lock);
477 return ret;
478}
479
480/* 111/*
481 * The following routines handle shrinking of ephemeral pages by evicting 112 * policy parameters
482 * pages "least valuable" first.
483 */ 113 */
484 114
485static unsigned long zcache_evicted_raw_pages;
486static unsigned long zcache_evicted_buddied_pages;
487static unsigned long zcache_evicted_unbuddied_pages;
488
489static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id,
490 uint16_t poolid);
491static void zcache_put_pool(struct tmem_pool *pool);
492
493/*
494 * Flush and free all zbuds in a zbpg, then free the pageframe
495 */
496static void zbud_evict_zbpg(struct zbud_page *zbpg)
497{
498 struct zbud_hdr *zh;
499 int i, j;
500 uint32_t pool_id[ZBUD_MAX_BUDS], client_id[ZBUD_MAX_BUDS];
501 uint32_t index[ZBUD_MAX_BUDS];
502 struct tmem_oid oid[ZBUD_MAX_BUDS];
503 struct tmem_pool *pool;
504
505 ASSERT_SPINLOCK(&zbpg->lock);
506 BUG_ON(!list_empty(&zbpg->bud_list));
507 for (i = 0, j = 0; i < ZBUD_MAX_BUDS; i++) {
508 zh = &zbpg->buddy[i];
509 if (zh->size) {
510 client_id[j] = zh->client_id;
511 pool_id[j] = zh->pool_id;
512 oid[j] = zh->oid;
513 index[j] = zh->index;
514 j++;
515 zbud_free(zh);
516 }
517 }
518 spin_unlock(&zbpg->lock);
519 for (i = 0; i < j; i++) {
520 pool = zcache_get_pool_by_id(client_id[i], pool_id[i]);
521 if (pool != NULL) {
522 tmem_flush_page(pool, &oid[i], index[i]);
523 zcache_put_pool(pool);
524 }
525 }
526 ASSERT_SENTINEL(zbpg, ZBPG);
527 spin_lock(&zbpg->lock);
528 zbud_free_raw_page(zbpg);
529}
530
531/*
532 * Free nr pages. This code is funky because we want to hold the locks
533 * protecting various lists for as short a time as possible, and in some
534 * circumstances the list may change asynchronously when the list lock is
535 * not held. In some cases we also trylock not only to avoid waiting on a
536 * page in use by another cpu, but also to avoid potential deadlock due to
537 * lock inversion.
538 */
539static void zbud_evict_pages(int nr)
540{
541 struct zbud_page *zbpg;
542 int i;
543
544 /* first try freeing any pages on unused list */
545retry_unused_list:
546 spin_lock_bh(&zbpg_unused_list_spinlock);
547 if (!list_empty(&zbpg_unused_list)) {
548 /* can't walk list here, since it may change when unlocked */
549 zbpg = list_first_entry(&zbpg_unused_list,
550 struct zbud_page, bud_list);
551 list_del_init(&zbpg->bud_list);
552 zcache_zbpg_unused_list_count--;
553 atomic_dec(&zcache_zbud_curr_raw_pages);
554 spin_unlock_bh(&zbpg_unused_list_spinlock);
555 zcache_free_page(zbpg);
556 zcache_evicted_raw_pages++;
557 if (--nr <= 0)
558 goto out;
559 goto retry_unused_list;
560 }
561 spin_unlock_bh(&zbpg_unused_list_spinlock);
562
563 /* now try freeing unbuddied pages, starting with least space avail */
564 for (i = 0; i < MAX_CHUNK; i++) {
565retry_unbud_list_i:
566 spin_lock_bh(&zbud_budlists_spinlock);
567 if (list_empty(&zbud_unbuddied[i].list)) {
568 spin_unlock_bh(&zbud_budlists_spinlock);
569 continue;
570 }
571 list_for_each_entry(zbpg, &zbud_unbuddied[i].list, bud_list) {
572 if (unlikely(!spin_trylock(&zbpg->lock)))
573 continue;
574 list_del_init(&zbpg->bud_list);
575 zbud_unbuddied[i].count--;
576 spin_unlock(&zbud_budlists_spinlock);
577 zcache_evicted_unbuddied_pages++;
578 /* want budlists unlocked when doing zbpg eviction */
579 zbud_evict_zbpg(zbpg);
580 local_bh_enable();
581 if (--nr <= 0)
582 goto out;
583 goto retry_unbud_list_i;
584 }
585 spin_unlock_bh(&zbud_budlists_spinlock);
586 }
587
588 /* as a last resort, free buddied pages */
589retry_bud_list:
590 spin_lock_bh(&zbud_budlists_spinlock);
591 if (list_empty(&zbud_buddied_list)) {
592 spin_unlock_bh(&zbud_budlists_spinlock);
593 goto out;
594 }
595 list_for_each_entry(zbpg, &zbud_buddied_list, bud_list) {
596 if (unlikely(!spin_trylock(&zbpg->lock)))
597 continue;
598 list_del_init(&zbpg->bud_list);
599 zcache_zbud_buddied_count--;
600 spin_unlock(&zbud_budlists_spinlock);
601 zcache_evicted_buddied_pages++;
602 /* want budlists unlocked when doing zbpg eviction */
603 zbud_evict_zbpg(zbpg);
604 local_bh_enable();
605 if (--nr <= 0)
606 goto out;
607 goto retry_bud_list;
608 }
609 spin_unlock_bh(&zbud_budlists_spinlock);
610out:
611 return;
612}
613
614static void __init zbud_init(void)
615{
616 int i;
617
618 INIT_LIST_HEAD(&zbud_buddied_list);
619
620 for (i = 0; i < NCHUNKS; i++)
621 INIT_LIST_HEAD(&zbud_unbuddied[i].list);
622}
623
624#ifdef CONFIG_SYSFS
625/*
626 * These sysfs routines show a nice distribution of how many zbpg's are
627 * currently (and have ever been placed) in each unbuddied list. It's fun
628 * to watch but can probably go away before final merge.
629 */
630static int zbud_show_unbuddied_list_counts(char *buf)
631{
632 int i;
633 char *p = buf;
634
635 for (i = 0; i < NCHUNKS; i++)
636 p += sprintf(p, "%u ", zbud_unbuddied[i].count);
637 return p - buf;
638}
639
640static int zbud_show_cumul_chunk_counts(char *buf)
641{
642 unsigned long i, chunks = 0, total_chunks = 0, sum_total_chunks = 0;
643 unsigned long total_chunks_lte_21 = 0, total_chunks_lte_32 = 0;
644 unsigned long total_chunks_lte_42 = 0;
645 char *p = buf;
646
647 for (i = 0; i < NCHUNKS; i++) {
648 p += sprintf(p, "%lu ", zbud_cumul_chunk_counts[i]);
649 chunks += zbud_cumul_chunk_counts[i];
650 total_chunks += zbud_cumul_chunk_counts[i];
651 sum_total_chunks += i * zbud_cumul_chunk_counts[i];
652 if (i == 21)
653 total_chunks_lte_21 = total_chunks;
654 if (i == 32)
655 total_chunks_lte_32 = total_chunks;
656 if (i == 42)
657 total_chunks_lte_42 = total_chunks;
658 }
659 p += sprintf(p, "<=21:%lu <=32:%lu <=42:%lu, mean:%lu\n",
660 total_chunks_lte_21, total_chunks_lte_32, total_chunks_lte_42,
661 chunks == 0 ? 0 : sum_total_chunks / chunks);
662 return p - buf;
663}
664#endif
665
666/**********
667 * This "zv" PAM implementation combines the slab-based zsmalloc
668 * with the crypto compression API to maximize the amount of data that can
669 * be packed into a physical page.
670 *
671 * Zv represents a PAM page with the index and object (plus a "size" value
672 * necessary for decompression) immediately preceding the compressed data.
673 */
674
675#define ZVH_SENTINEL 0x43214321
676
677struct zv_hdr {
678 uint32_t pool_id;
679 struct tmem_oid oid;
680 uint32_t index;
681 size_t size;
682 DECL_SENTINEL
683};
684
685/* rudimentary policy limits */
686/* total number of persistent pages may not exceed this percentage */
687static unsigned int zv_page_count_policy_percent = 75;
688/* 115/*
689 * byte count defining poor compression; pages with greater zsize will be 116 * byte count defining poor compression; pages with greater zsize will be
690 * rejected 117 * rejected
691 */ 118 */
692static unsigned int zv_max_zsize = (PAGE_SIZE / 8) * 7; 119static unsigned int zbud_max_zsize __read_mostly = (PAGE_SIZE / 8) * 7;
693/* 120/*
694 * byte count defining poor *mean* compression; pages with greater zsize 121 * byte count defining poor *mean* compression; pages with greater zsize
695 * will be rejected until sufficient better-compressed pages are accepted 122 * will be rejected until sufficient better-compressed pages are accepted
696 * driving the mean below this threshold 123 * driving the mean below this threshold
697 */ 124 */
698static unsigned int zv_max_mean_zsize = (PAGE_SIZE / 8) * 5; 125static unsigned int zbud_max_mean_zsize __read_mostly = (PAGE_SIZE / 8) * 5;
699
700static atomic_t zv_curr_dist_counts[NCHUNKS];
701static atomic_t zv_cumul_dist_counts[NCHUNKS];
702 126
703static unsigned long zv_create(struct zs_pool *pool, uint32_t pool_id,
704 struct tmem_oid *oid, uint32_t index,
705 void *cdata, unsigned clen)
706{
707 struct zv_hdr *zv;
708 u32 size = clen + sizeof(struct zv_hdr);
709 int chunks = (size + (CHUNK_SIZE - 1)) >> CHUNK_SHIFT;
710 unsigned long handle = 0;
711
712 BUG_ON(!irqs_disabled());
713 BUG_ON(chunks >= NCHUNKS);
714 handle = zs_malloc(pool, size);
715 if (!handle)
716 goto out;
717 atomic_inc(&zv_curr_dist_counts[chunks]);
718 atomic_inc(&zv_cumul_dist_counts[chunks]);
719 zv = zs_map_object(pool, handle, ZS_MM_WO);
720 zv->index = index;
721 zv->oid = *oid;
722 zv->pool_id = pool_id;
723 zv->size = clen;
724 SET_SENTINEL(zv, ZVH);
725 memcpy((char *)zv + sizeof(struct zv_hdr), cdata, clen);
726 zs_unmap_object(pool, handle);
727out:
728 return handle;
729}
730
731static void zv_free(struct zs_pool *pool, unsigned long handle)
732{
733 unsigned long flags;
734 struct zv_hdr *zv;
735 uint16_t size;
736 int chunks;
737
738 zv = zs_map_object(pool, handle, ZS_MM_RW);
739 ASSERT_SENTINEL(zv, ZVH);
740 size = zv->size + sizeof(struct zv_hdr);
741 INVERT_SENTINEL(zv, ZVH);
742 zs_unmap_object(pool, handle);
743
744 chunks = (size + (CHUNK_SIZE - 1)) >> CHUNK_SHIFT;
745 BUG_ON(chunks >= NCHUNKS);
746 atomic_dec(&zv_curr_dist_counts[chunks]);
747
748 local_irq_save(flags);
749 zs_free(pool, handle);
750 local_irq_restore(flags);
751}
752
753static void zv_decompress(struct page *page, unsigned long handle)
754{
755 unsigned int clen = PAGE_SIZE;
756 char *to_va;
757 int ret;
758 struct zv_hdr *zv;
759
760 zv = zs_map_object(zcache_host.zspool, handle, ZS_MM_RO);
761 BUG_ON(zv->size == 0);
762 ASSERT_SENTINEL(zv, ZVH);
763 to_va = kmap_atomic(page);
764 ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, (char *)zv + sizeof(*zv),
765 zv->size, to_va, &clen);
766 kunmap_atomic(to_va);
767 zs_unmap_object(zcache_host.zspool, handle);
768 BUG_ON(ret);
769 BUG_ON(clen != PAGE_SIZE);
770}
771
772#ifdef CONFIG_SYSFS
773/* 127/*
774 * show a distribution of compression stats for zv pages. 128 * for now, used named slabs so can easily track usage; later can
129 * either just use kmalloc, or perhaps add a slab-like allocator
130 * to more carefully manage total memory utilization
775 */ 131 */
132static struct kmem_cache *zcache_objnode_cache;
133static struct kmem_cache *zcache_obj_cache;
776 134
777static int zv_curr_dist_counts_show(char *buf) 135static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, };
778{
779 unsigned long i, n, chunks = 0, sum_total_chunks = 0;
780 char *p = buf;
781
782 for (i = 0; i < NCHUNKS; i++) {
783 n = atomic_read(&zv_curr_dist_counts[i]);
784 p += sprintf(p, "%lu ", n);
785 chunks += n;
786 sum_total_chunks += i * n;
787 }
788 p += sprintf(p, "mean:%lu\n",
789 chunks == 0 ? 0 : sum_total_chunks / chunks);
790 return p - buf;
791}
792
793static int zv_cumul_dist_counts_show(char *buf)
794{
795 unsigned long i, n, chunks = 0, sum_total_chunks = 0;
796 char *p = buf;
797
798 for (i = 0; i < NCHUNKS; i++) {
799 n = atomic_read(&zv_cumul_dist_counts[i]);
800 p += sprintf(p, "%lu ", n);
801 chunks += n;
802 sum_total_chunks += i * n;
803 }
804 p += sprintf(p, "mean:%lu\n",
805 chunks == 0 ? 0 : sum_total_chunks / chunks);
806 return p - buf;
807}
808 136
809/* 137/* we try to keep these statistics SMP-consistent */
810 * setting zv_max_zsize via sysfs causes all persistent (e.g. swap) 138static ssize_t zcache_obj_count;
811 * pages that don't compress to less than this value (including metadata 139static atomic_t zcache_obj_atomic = ATOMIC_INIT(0);
812 * overhead) to be rejected. We don't allow the value to get too close 140static ssize_t zcache_obj_count_max;
813 * to PAGE_SIZE. 141static ssize_t zcache_objnode_count;
814 */ 142static atomic_t zcache_objnode_atomic = ATOMIC_INIT(0);
815static ssize_t zv_max_zsize_show(struct kobject *kobj, 143static ssize_t zcache_objnode_count_max;
816 struct kobj_attribute *attr, 144static u64 zcache_eph_zbytes;
817 char *buf) 145static atomic_long_t zcache_eph_zbytes_atomic = ATOMIC_INIT(0);
818{ 146static u64 zcache_eph_zbytes_max;
819 return sprintf(buf, "%u\n", zv_max_zsize); 147static u64 zcache_pers_zbytes;
148static atomic_long_t zcache_pers_zbytes_atomic = ATOMIC_INIT(0);
149static u64 zcache_pers_zbytes_max;
150static ssize_t zcache_eph_pageframes;
151static atomic_t zcache_eph_pageframes_atomic = ATOMIC_INIT(0);
152static ssize_t zcache_eph_pageframes_max;
153static ssize_t zcache_pers_pageframes;
154static atomic_t zcache_pers_pageframes_atomic = ATOMIC_INIT(0);
155static ssize_t zcache_pers_pageframes_max;
156static ssize_t zcache_pageframes_alloced;
157static atomic_t zcache_pageframes_alloced_atomic = ATOMIC_INIT(0);
158static ssize_t zcache_pageframes_freed;
159static atomic_t zcache_pageframes_freed_atomic = ATOMIC_INIT(0);
160static ssize_t zcache_eph_zpages;
161static ssize_t zcache_eph_zpages;
162static atomic_t zcache_eph_zpages_atomic = ATOMIC_INIT(0);
163static ssize_t zcache_eph_zpages_max;
164static ssize_t zcache_pers_zpages;
165static atomic_t zcache_pers_zpages_atomic = ATOMIC_INIT(0);
166static ssize_t zcache_pers_zpages_max;
167
168/* but for the rest of these, counting races are ok */
169static ssize_t zcache_flush_total;
170static ssize_t zcache_flush_found;
171static ssize_t zcache_flobj_total;
172static ssize_t zcache_flobj_found;
173static ssize_t zcache_failed_eph_puts;
174static ssize_t zcache_failed_pers_puts;
175static ssize_t zcache_failed_getfreepages;
176static ssize_t zcache_failed_alloc;
177static ssize_t zcache_put_to_flush;
178static ssize_t zcache_compress_poor;
179static ssize_t zcache_mean_compress_poor;
180static ssize_t zcache_eph_ate_tail;
181static ssize_t zcache_eph_ate_tail_failed;
182static ssize_t zcache_pers_ate_eph;
183static ssize_t zcache_pers_ate_eph_failed;
184static ssize_t zcache_evicted_eph_zpages;
185static ssize_t zcache_evicted_eph_pageframes;
186static ssize_t zcache_last_active_file_pageframes;
187static ssize_t zcache_last_inactive_file_pageframes;
188static ssize_t zcache_last_active_anon_pageframes;
189static ssize_t zcache_last_inactive_anon_pageframes;
190static ssize_t zcache_eph_nonactive_puts_ignored;
191static ssize_t zcache_pers_nonactive_puts_ignored;
192static ssize_t zcache_writtenback_pages;
193static ssize_t zcache_outstanding_writeback_pages;
194
195#ifdef CONFIG_DEBUG_FS
196#include <linux/debugfs.h>
197#define zdfs debugfs_create_size_t
198#define zdfs64 debugfs_create_u64
199static int zcache_debugfs_init(void)
200{
201 struct dentry *root = debugfs_create_dir("zcache", NULL);
202 if (root == NULL)
203 return -ENXIO;
204
205 zdfs("obj_count", S_IRUGO, root, &zcache_obj_count);
206 zdfs("obj_count_max", S_IRUGO, root, &zcache_obj_count_max);
207 zdfs("objnode_count", S_IRUGO, root, &zcache_objnode_count);
208 zdfs("objnode_count_max", S_IRUGO, root, &zcache_objnode_count_max);
209 zdfs("flush_total", S_IRUGO, root, &zcache_flush_total);
210 zdfs("flush_found", S_IRUGO, root, &zcache_flush_found);
211 zdfs("flobj_total", S_IRUGO, root, &zcache_flobj_total);
212 zdfs("flobj_found", S_IRUGO, root, &zcache_flobj_found);
213 zdfs("failed_eph_puts", S_IRUGO, root, &zcache_failed_eph_puts);
214 zdfs("failed_pers_puts", S_IRUGO, root, &zcache_failed_pers_puts);
215 zdfs("failed_get_free_pages", S_IRUGO, root,
216 &zcache_failed_getfreepages);
217 zdfs("failed_alloc", S_IRUGO, root, &zcache_failed_alloc);
218 zdfs("put_to_flush", S_IRUGO, root, &zcache_put_to_flush);
219 zdfs("compress_poor", S_IRUGO, root, &zcache_compress_poor);
220 zdfs("mean_compress_poor", S_IRUGO, root, &zcache_mean_compress_poor);
221 zdfs("eph_ate_tail", S_IRUGO, root, &zcache_eph_ate_tail);
222 zdfs("eph_ate_tail_failed", S_IRUGO, root, &zcache_eph_ate_tail_failed);
223 zdfs("pers_ate_eph", S_IRUGO, root, &zcache_pers_ate_eph);
224 zdfs("pers_ate_eph_failed", S_IRUGO, root, &zcache_pers_ate_eph_failed);
225 zdfs("evicted_eph_zpages", S_IRUGO, root, &zcache_evicted_eph_zpages);
226 zdfs("evicted_eph_pageframes", S_IRUGO, root,
227 &zcache_evicted_eph_pageframes);
228 zdfs("eph_pageframes", S_IRUGO, root, &zcache_eph_pageframes);
229 zdfs("eph_pageframes_max", S_IRUGO, root, &zcache_eph_pageframes_max);
230 zdfs("pers_pageframes", S_IRUGO, root, &zcache_pers_pageframes);
231 zdfs("pers_pageframes_max", S_IRUGO, root, &zcache_pers_pageframes_max);
232 zdfs("eph_zpages", S_IRUGO, root, &zcache_eph_zpages);
233 zdfs("eph_zpages_max", S_IRUGO, root, &zcache_eph_zpages_max);
234 zdfs("pers_zpages", S_IRUGO, root, &zcache_pers_zpages);
235 zdfs("pers_zpages_max", S_IRUGO, root, &zcache_pers_zpages_max);
236 zdfs("last_active_file_pageframes", S_IRUGO, root,
237 &zcache_last_active_file_pageframes);
238 zdfs("last_inactive_file_pageframes", S_IRUGO, root,
239 &zcache_last_inactive_file_pageframes);
240 zdfs("last_active_anon_pageframes", S_IRUGO, root,
241 &zcache_last_active_anon_pageframes);
242 zdfs("last_inactive_anon_pageframes", S_IRUGO, root,
243 &zcache_last_inactive_anon_pageframes);
244 zdfs("eph_nonactive_puts_ignored", S_IRUGO, root,
245 &zcache_eph_nonactive_puts_ignored);
246 zdfs("pers_nonactive_puts_ignored", S_IRUGO, root,
247 &zcache_pers_nonactive_puts_ignored);
248 zdfs64("eph_zbytes", S_IRUGO, root, &zcache_eph_zbytes);
249 zdfs64("eph_zbytes_max", S_IRUGO, root, &zcache_eph_zbytes_max);
250 zdfs64("pers_zbytes", S_IRUGO, root, &zcache_pers_zbytes);
251 zdfs64("pers_zbytes_max", S_IRUGO, root, &zcache_pers_zbytes_max);
252 zdfs("outstanding_writeback_pages", S_IRUGO, root,
253 &zcache_outstanding_writeback_pages);
254 zdfs("writtenback_pages", S_IRUGO, root, &zcache_writtenback_pages);
255 return 0;
820} 256}
257#undef zdebugfs
258#undef zdfs64
259#endif
821 260
822static ssize_t zv_max_zsize_store(struct kobject *kobj, 261#define ZCACHE_DEBUG
823 struct kobj_attribute *attr, 262#ifdef ZCACHE_DEBUG
824 const char *buf, size_t count) 263/* developers can call this in case of ooms, e.g. to find memory leaks */
825{ 264void zcache_dump(void)
826 unsigned long val; 265{
827 int err; 266 pr_info("zcache: obj_count=%zd\n", zcache_obj_count);
828 267 pr_info("zcache: obj_count_max=%zd\n", zcache_obj_count_max);
829 if (!capable(CAP_SYS_ADMIN)) 268 pr_info("zcache: objnode_count=%zd\n", zcache_objnode_count);
830 return -EPERM; 269 pr_info("zcache: objnode_count_max=%zd\n", zcache_objnode_count_max);
831 270 pr_info("zcache: flush_total=%zd\n", zcache_flush_total);
832 err = kstrtoul(buf, 10, &val); 271 pr_info("zcache: flush_found=%zd\n", zcache_flush_found);
833 if (err || (val == 0) || (val > (PAGE_SIZE / 8) * 7)) 272 pr_info("zcache: flobj_total=%zd\n", zcache_flobj_total);
834 return -EINVAL; 273 pr_info("zcache: flobj_found=%zd\n", zcache_flobj_found);
835 zv_max_zsize = val; 274 pr_info("zcache: failed_eph_puts=%zd\n", zcache_failed_eph_puts);
836 return count; 275 pr_info("zcache: failed_pers_puts=%zd\n", zcache_failed_pers_puts);
276 pr_info("zcache: failed_get_free_pages=%zd\n",
277 zcache_failed_getfreepages);
278 pr_info("zcache: failed_alloc=%zd\n", zcache_failed_alloc);
279 pr_info("zcache: put_to_flush=%zd\n", zcache_put_to_flush);
280 pr_info("zcache: compress_poor=%zd\n", zcache_compress_poor);
281 pr_info("zcache: mean_compress_poor=%zd\n",
282 zcache_mean_compress_poor);
283 pr_info("zcache: eph_ate_tail=%zd\n", zcache_eph_ate_tail);
284 pr_info("zcache: eph_ate_tail_failed=%zd\n",
285 zcache_eph_ate_tail_failed);
286 pr_info("zcache: pers_ate_eph=%zd\n", zcache_pers_ate_eph);
287 pr_info("zcache: pers_ate_eph_failed=%zd\n",
288 zcache_pers_ate_eph_failed);
289 pr_info("zcache: evicted_eph_zpages=%zd\n", zcache_evicted_eph_zpages);
290 pr_info("zcache: evicted_eph_pageframes=%zd\n",
291 zcache_evicted_eph_pageframes);
292 pr_info("zcache: eph_pageframes=%zd\n", zcache_eph_pageframes);
293 pr_info("zcache: eph_pageframes_max=%zd\n", zcache_eph_pageframes_max);
294 pr_info("zcache: pers_pageframes=%zd\n", zcache_pers_pageframes);
295 pr_info("zcache: pers_pageframes_max=%zd\n",
296 zcache_pers_pageframes_max);
297 pr_info("zcache: eph_zpages=%zd\n", zcache_eph_zpages);
298 pr_info("zcache: eph_zpages_max=%zd\n", zcache_eph_zpages_max);
299 pr_info("zcache: pers_zpages=%zd\n", zcache_pers_zpages);
300 pr_info("zcache: pers_zpages_max=%zd\n", zcache_pers_zpages_max);
301 pr_info("zcache: last_active_file_pageframes=%zd\n",
302 zcache_last_active_file_pageframes);
303 pr_info("zcache: last_inactive_file_pageframes=%zd\n",
304 zcache_last_inactive_file_pageframes);
305 pr_info("zcache: last_active_anon_pageframes=%zd\n",
306 zcache_last_active_anon_pageframes);
307 pr_info("zcache: last_inactive_anon_pageframes=%zd\n",
308 zcache_last_inactive_anon_pageframes);
309 pr_info("zcache: eph_nonactive_puts_ignored=%zd\n",
310 zcache_eph_nonactive_puts_ignored);
311 pr_info("zcache: pers_nonactive_puts_ignored=%zd\n",
312 zcache_pers_nonactive_puts_ignored);
313 pr_info("zcache: eph_zbytes=%llu\n",
314 zcache_eph_zbytes);
315 pr_info("zcache: eph_zbytes_max=%llu\n",
316 zcache_eph_zbytes_max);
317 pr_info("zcache: pers_zbytes=%llu\n",
318 zcache_pers_zbytes);
319 pr_info("zcache: pers_zbytes_max=%llu\n",
320 zcache_pers_zbytes_max);
321 pr_info("zcache: outstanding_writeback_pages=%zd\n",
322 zcache_outstanding_writeback_pages);
323 pr_info("zcache: writtenback_pages=%zd\n", zcache_writtenback_pages);
837} 324}
325#endif
838 326
839/* 327/*
840 * setting zv_max_mean_zsize via sysfs causes all persistent (e.g. swap) 328 * zcache core code starts here
841 * pages that don't compress to less than this value (including metadata
842 * overhead) to be rejected UNLESS the mean compression is also smaller
843 * than this value. In other words, we are load-balancing-by-zsize the
844 * accepted pages. Again, we don't allow the value to get too close
845 * to PAGE_SIZE.
846 */ 329 */
847static ssize_t zv_max_mean_zsize_show(struct kobject *kobj,
848 struct kobj_attribute *attr,
849 char *buf)
850{
851 return sprintf(buf, "%u\n", zv_max_mean_zsize);
852}
853
854static ssize_t zv_max_mean_zsize_store(struct kobject *kobj,
855 struct kobj_attribute *attr,
856 const char *buf, size_t count)
857{
858 unsigned long val;
859 int err;
860 330
861 if (!capable(CAP_SYS_ADMIN)) 331static struct zcache_client zcache_host;
862 return -EPERM; 332static struct zcache_client zcache_clients[MAX_CLIENTS];
863
864 err = kstrtoul(buf, 10, &val);
865 if (err || (val == 0) || (val > (PAGE_SIZE / 8) * 7))
866 return -EINVAL;
867 zv_max_mean_zsize = val;
868 return count;
869}
870 333
871/* 334static inline bool is_local_client(struct zcache_client *cli)
872 * setting zv_page_count_policy_percent via sysfs sets an upper bound of
873 * persistent (e.g. swap) pages that will be retained according to:
874 * (zv_page_count_policy_percent * totalram_pages) / 100)
875 * when that limit is reached, further puts will be rejected (until
876 * some pages have been flushed). Note that, due to compression,
877 * this number may exceed 100; it defaults to 75 and we set an
878 * arbitary limit of 150. A poor choice will almost certainly result
879 * in OOM's, so this value should only be changed prudently.
880 */
881static ssize_t zv_page_count_policy_percent_show(struct kobject *kobj,
882 struct kobj_attribute *attr,
883 char *buf)
884{ 335{
885 return sprintf(buf, "%u\n", zv_page_count_policy_percent); 336 return cli == &zcache_host;
886} 337}
887 338
888static ssize_t zv_page_count_policy_percent_store(struct kobject *kobj, 339static struct zcache_client *zcache_get_client_by_id(uint16_t cli_id)
889 struct kobj_attribute *attr,
890 const char *buf, size_t count)
891{ 340{
892 unsigned long val; 341 struct zcache_client *cli = &zcache_host;
893 int err;
894 342
895 if (!capable(CAP_SYS_ADMIN)) 343 if (cli_id != LOCAL_CLIENT) {
896 return -EPERM; 344 if (cli_id >= MAX_CLIENTS)
897 345 goto out;
898 err = kstrtoul(buf, 10, &val); 346 cli = &zcache_clients[cli_id];
899 if (err || (val == 0) || (val > 150)) 347 }
900 return -EINVAL; 348out:
901 zv_page_count_policy_percent = val; 349 return cli;
902 return count;
903} 350}
904 351
905static struct kobj_attribute zcache_zv_max_zsize_attr = {
906 .attr = { .name = "zv_max_zsize", .mode = 0644 },
907 .show = zv_max_zsize_show,
908 .store = zv_max_zsize_store,
909};
910
911static struct kobj_attribute zcache_zv_max_mean_zsize_attr = {
912 .attr = { .name = "zv_max_mean_zsize", .mode = 0644 },
913 .show = zv_max_mean_zsize_show,
914 .store = zv_max_mean_zsize_store,
915};
916
917static struct kobj_attribute zcache_zv_page_count_policy_percent_attr = {
918 .attr = { .name = "zv_page_count_policy_percent",
919 .mode = 0644 },
920 .show = zv_page_count_policy_percent_show,
921 .store = zv_page_count_policy_percent_store,
922};
923#endif
924
925/*
926 * zcache core code starts here
927 */
928
929/* useful stats not collected by cleancache or frontswap */
930static unsigned long zcache_flush_total;
931static unsigned long zcache_flush_found;
932static unsigned long zcache_flobj_total;
933static unsigned long zcache_flobj_found;
934static unsigned long zcache_failed_eph_puts;
935static unsigned long zcache_failed_pers_puts;
936
937/* 352/*
938 * Tmem operations assume the poolid implies the invoking client. 353 * Tmem operations assume the poolid implies the invoking client.
939 * Zcache only has one client (the kernel itself): LOCAL_CLIENT. 354 * Zcache only has one client (the kernel itself): LOCAL_CLIENT.
@@ -941,24 +356,26 @@ static unsigned long zcache_failed_pers_puts;
941 * of zcache would have one client per guest and each client might 356 * of zcache would have one client per guest and each client might
942 * have a poolid==N. 357 * have a poolid==N.
943 */ 358 */
944static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid) 359struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid)
945{ 360{
946 struct tmem_pool *pool = NULL; 361 struct tmem_pool *pool = NULL;
947 struct zcache_client *cli = NULL; 362 struct zcache_client *cli = NULL;
948 363
949 cli = get_zcache_client(cli_id); 364 cli = zcache_get_client_by_id(cli_id);
950 if (!cli) 365 if (cli == NULL)
951 goto out; 366 goto out;
952 367 if (!is_local_client(cli))
953 atomic_inc(&cli->refcount); 368 atomic_inc(&cli->refcount);
954 pool = idr_find(&cli->tmem_pools, poolid); 369 if (poolid < MAX_POOLS_PER_CLIENT) {
955 if (pool != NULL) 370 pool = cli->tmem_pools[poolid];
956 atomic_inc(&pool->refcount); 371 if (pool != NULL)
372 atomic_inc(&pool->refcount);
373 }
957out: 374out:
958 return pool; 375 return pool;
959} 376}
960 377
961static void zcache_put_pool(struct tmem_pool *pool) 378void zcache_put_pool(struct tmem_pool *pool)
962{ 379{
963 struct zcache_client *cli = NULL; 380 struct zcache_client *cli = NULL;
964 381
@@ -966,7 +383,8 @@ static void zcache_put_pool(struct tmem_pool *pool)
966 BUG(); 383 BUG();
967 cli = pool->client; 384 cli = pool->client;
968 atomic_dec(&pool->refcount); 385 atomic_dec(&pool->refcount);
969 atomic_dec(&cli->refcount); 386 if (!is_local_client(cli))
387 atomic_dec(&cli->refcount);
970} 388}
971 389
972int zcache_new_client(uint16_t cli_id) 390int zcache_new_client(uint16_t cli_id)
@@ -974,120 +392,17 @@ int zcache_new_client(uint16_t cli_id)
974 struct zcache_client *cli; 392 struct zcache_client *cli;
975 int ret = -1; 393 int ret = -1;
976 394
977 cli = get_zcache_client(cli_id); 395 cli = zcache_get_client_by_id(cli_id);
978
979 if (cli == NULL) 396 if (cli == NULL)
980 goto out; 397 goto out;
981 if (cli->allocated) 398 if (cli->allocated)
982 goto out; 399 goto out;
983 cli->allocated = 1; 400 cli->allocated = 1;
984#ifdef CONFIG_FRONTSWAP
985 cli->zspool = zs_create_pool("zcache", ZCACHE_GFP_MASK);
986 if (cli->zspool == NULL)
987 goto out;
988 idr_init(&cli->tmem_pools);
989#endif
990 ret = 0;
991out:
992 return ret;
993}
994
995/* counters for debugging */
996static unsigned long zcache_failed_get_free_pages;
997static unsigned long zcache_failed_alloc;
998static unsigned long zcache_put_to_flush;
999
1000/*
1001 * for now, used named slabs so can easily track usage; later can
1002 * either just use kmalloc, or perhaps add a slab-like allocator
1003 * to more carefully manage total memory utilization
1004 */
1005static struct kmem_cache *zcache_objnode_cache;
1006static struct kmem_cache *zcache_obj_cache;
1007static atomic_t zcache_curr_obj_count = ATOMIC_INIT(0);
1008static unsigned long zcache_curr_obj_count_max;
1009static atomic_t zcache_curr_objnode_count = ATOMIC_INIT(0);
1010static unsigned long zcache_curr_objnode_count_max;
1011
1012/*
1013 * to avoid memory allocation recursion (e.g. due to direct reclaim), we
1014 * preload all necessary data structures so the hostops callbacks never
1015 * actually do a malloc
1016 */
1017struct zcache_preload {
1018 void *page;
1019 struct tmem_obj *obj;
1020 int nr;
1021 struct tmem_objnode *objnodes[OBJNODE_TREE_MAX_PATH];
1022};
1023static DEFINE_PER_CPU(struct zcache_preload, zcache_preloads) = { 0, };
1024
1025static int zcache_do_preload(struct tmem_pool *pool)
1026{
1027 struct zcache_preload *kp;
1028 struct tmem_objnode *objnode;
1029 struct tmem_obj *obj;
1030 void *page;
1031 int ret = -ENOMEM;
1032
1033 if (unlikely(zcache_objnode_cache == NULL))
1034 goto out;
1035 if (unlikely(zcache_obj_cache == NULL))
1036 goto out;
1037
1038 /* IRQ has already been disabled. */
1039 kp = &__get_cpu_var(zcache_preloads);
1040 while (kp->nr < ARRAY_SIZE(kp->objnodes)) {
1041 objnode = kmem_cache_alloc(zcache_objnode_cache,
1042 ZCACHE_GFP_MASK);
1043 if (unlikely(objnode == NULL)) {
1044 zcache_failed_alloc++;
1045 goto out;
1046 }
1047
1048 kp->objnodes[kp->nr++] = objnode;
1049 }
1050
1051 if (!kp->obj) {
1052 obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK);
1053 if (unlikely(obj == NULL)) {
1054 zcache_failed_alloc++;
1055 goto out;
1056 }
1057 kp->obj = obj;
1058 }
1059
1060 if (!kp->page) {
1061 page = (void *)__get_free_page(ZCACHE_GFP_MASK);
1062 if (unlikely(page == NULL)) {
1063 zcache_failed_get_free_pages++;
1064 goto out;
1065 }
1066 kp->page = page;
1067 }
1068
1069 ret = 0; 401 ret = 0;
1070out: 402out:
1071 return ret; 403 return ret;
1072} 404}
1073 405
1074static void *zcache_get_free_page(void)
1075{
1076 struct zcache_preload *kp;
1077 void *page;
1078
1079 kp = &__get_cpu_var(zcache_preloads);
1080 page = kp->page;
1081 BUG_ON(page == NULL);
1082 kp->page = NULL;
1083 return page;
1084}
1085
1086static void zcache_free_page(void *p)
1087{
1088 free_page((unsigned long)p);
1089}
1090
1091/* 406/*
1092 * zcache implementation for tmem host ops 407 * zcache implementation for tmem host ops
1093 */ 408 */
@@ -1095,51 +410,53 @@ static void zcache_free_page(void *p)
1095static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool) 410static struct tmem_objnode *zcache_objnode_alloc(struct tmem_pool *pool)
1096{ 411{
1097 struct tmem_objnode *objnode = NULL; 412 struct tmem_objnode *objnode = NULL;
1098 unsigned long count;
1099 struct zcache_preload *kp; 413 struct zcache_preload *kp;
414 int i;
1100 415
1101 kp = &__get_cpu_var(zcache_preloads); 416 kp = &__get_cpu_var(zcache_preloads);
1102 if (kp->nr <= 0) 417 for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) {
1103 goto out; 418 objnode = kp->objnodes[i];
1104 objnode = kp->objnodes[kp->nr - 1]; 419 if (objnode != NULL) {
420 kp->objnodes[i] = NULL;
421 break;
422 }
423 }
1105 BUG_ON(objnode == NULL); 424 BUG_ON(objnode == NULL);
1106 kp->objnodes[kp->nr - 1] = NULL; 425 zcache_objnode_count = atomic_inc_return(&zcache_objnode_atomic);
1107 kp->nr--; 426 if (zcache_objnode_count > zcache_objnode_count_max)
1108 count = atomic_inc_return(&zcache_curr_objnode_count); 427 zcache_objnode_count_max = zcache_objnode_count;
1109 if (count > zcache_curr_objnode_count_max)
1110 zcache_curr_objnode_count_max = count;
1111out:
1112 return objnode; 428 return objnode;
1113} 429}
1114 430
1115static void zcache_objnode_free(struct tmem_objnode *objnode, 431static void zcache_objnode_free(struct tmem_objnode *objnode,
1116 struct tmem_pool *pool) 432 struct tmem_pool *pool)
1117{ 433{
1118 atomic_dec(&zcache_curr_objnode_count); 434 zcache_objnode_count =
1119 BUG_ON(atomic_read(&zcache_curr_objnode_count) < 0); 435 atomic_dec_return(&zcache_objnode_atomic);
436 BUG_ON(zcache_objnode_count < 0);
1120 kmem_cache_free(zcache_objnode_cache, objnode); 437 kmem_cache_free(zcache_objnode_cache, objnode);
1121} 438}
1122 439
1123static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool) 440static struct tmem_obj *zcache_obj_alloc(struct tmem_pool *pool)
1124{ 441{
1125 struct tmem_obj *obj = NULL; 442 struct tmem_obj *obj = NULL;
1126 unsigned long count;
1127 struct zcache_preload *kp; 443 struct zcache_preload *kp;
1128 444
1129 kp = &__get_cpu_var(zcache_preloads); 445 kp = &__get_cpu_var(zcache_preloads);
1130 obj = kp->obj; 446 obj = kp->obj;
1131 BUG_ON(obj == NULL); 447 BUG_ON(obj == NULL);
1132 kp->obj = NULL; 448 kp->obj = NULL;
1133 count = atomic_inc_return(&zcache_curr_obj_count); 449 zcache_obj_count = atomic_inc_return(&zcache_obj_atomic);
1134 if (count > zcache_curr_obj_count_max) 450 if (zcache_obj_count > zcache_obj_count_max)
1135 zcache_curr_obj_count_max = count; 451 zcache_obj_count_max = zcache_obj_count;
1136 return obj; 452 return obj;
1137} 453}
1138 454
1139static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool) 455static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool)
1140{ 456{
1141 atomic_dec(&zcache_curr_obj_count); 457 zcache_obj_count =
1142 BUG_ON(atomic_read(&zcache_curr_obj_count) < 0); 458 atomic_dec_return(&zcache_obj_atomic);
459 BUG_ON(zcache_obj_count < 0);
1143 kmem_cache_free(zcache_obj_cache, obj); 460 kmem_cache_free(zcache_obj_cache, obj);
1144} 461}
1145 462
@@ -1150,96 +467,302 @@ static struct tmem_hostops zcache_hostops = {
1150 .objnode_free = zcache_objnode_free, 467 .objnode_free = zcache_objnode_free,
1151}; 468};
1152 469
470static struct page *zcache_alloc_page(void)
471{
472 struct page *page = alloc_page(ZCACHE_GFP_MASK);
473
474 if (page != NULL)
475 zcache_pageframes_alloced =
476 atomic_inc_return(&zcache_pageframes_alloced_atomic);
477 return page;
478}
479
480static void zcache_free_page(struct page *page)
481{
482 long curr_pageframes;
483 static long max_pageframes, min_pageframes;
484
485 if (page == NULL)
486 BUG();
487 __free_page(page);
488 zcache_pageframes_freed =
489 atomic_inc_return(&zcache_pageframes_freed_atomic);
490 curr_pageframes = zcache_pageframes_alloced -
491 atomic_read(&zcache_pageframes_freed_atomic) -
492 atomic_read(&zcache_eph_pageframes_atomic) -
493 atomic_read(&zcache_pers_pageframes_atomic);
494 if (curr_pageframes > max_pageframes)
495 max_pageframes = curr_pageframes;
496 if (curr_pageframes < min_pageframes)
497 min_pageframes = curr_pageframes;
498#ifdef ZCACHE_DEBUG
499 if (curr_pageframes > 2L || curr_pageframes < -2L) {
500 /* pr_info here */
501 }
502#endif
503}
504
1153/* 505/*
1154 * zcache implementations for PAM page descriptor ops 506 * zcache implementations for PAM page descriptor ops
1155 */ 507 */
1156 508
1157static atomic_t zcache_curr_eph_pampd_count = ATOMIC_INIT(0);
1158static unsigned long zcache_curr_eph_pampd_count_max;
1159static atomic_t zcache_curr_pers_pampd_count = ATOMIC_INIT(0);
1160static unsigned long zcache_curr_pers_pampd_count_max;
1161
1162/* forward reference */ 509/* forward reference */
1163static int zcache_compress(struct page *from, void **out_va, unsigned *out_len); 510static void zcache_compress(struct page *from,
511 void **out_va, unsigned *out_len);
512
513static struct page *zcache_evict_eph_pageframe(void);
1164 514
1165static void *zcache_pampd_create(char *data, size_t size, bool raw, int eph, 515static void *zcache_pampd_eph_create(char *data, size_t size, bool raw,
1166 struct tmem_pool *pool, struct tmem_oid *oid, 516 struct tmem_handle *th)
1167 uint32_t index)
1168{ 517{
1169 void *pampd = NULL, *cdata; 518 void *pampd = NULL, *cdata = data;
1170 unsigned clen; 519 unsigned clen = size;
1171 int ret; 520 struct page *page = (struct page *)(data), *newpage;
1172 unsigned long count;
1173 struct page *page = (struct page *)(data);
1174 struct zcache_client *cli = pool->client;
1175 uint16_t client_id = get_client_id_from_client(cli);
1176 unsigned long zv_mean_zsize;
1177 unsigned long curr_pers_pampd_count;
1178 u64 total_zsize;
1179 521
1180 if (eph) { 522 if (!raw) {
1181 ret = zcache_compress(page, &cdata, &clen); 523 zcache_compress(page, &cdata, &clen);
1182 if (ret == 0) 524 if (clen > zbud_max_buddy_size()) {
1183 goto out;
1184 if (clen == 0 || clen > zbud_max_buddy_size()) {
1185 zcache_compress_poor++; 525 zcache_compress_poor++;
1186 goto out; 526 goto out;
1187 } 527 }
1188 pampd = (void *)zbud_create(client_id, pool->pool_id, oid,
1189 index, page, cdata, clen);
1190 if (pampd != NULL) {
1191 count = atomic_inc_return(&zcache_curr_eph_pampd_count);
1192 if (count > zcache_curr_eph_pampd_count_max)
1193 zcache_curr_eph_pampd_count_max = count;
1194 }
1195 } else { 528 } else {
1196 curr_pers_pampd_count = 529 BUG_ON(clen > zbud_max_buddy_size());
1197 atomic_read(&zcache_curr_pers_pampd_count); 530 }
1198 if (curr_pers_pampd_count > 531
1199 (zv_page_count_policy_percent * totalram_pages) / 100) 532 /* look for space via an existing match first */
1200 goto out; 533 pampd = (void *)zbud_match_prep(th, true, cdata, clen);
1201 ret = zcache_compress(page, &cdata, &clen); 534 if (pampd != NULL)
1202 if (ret == 0) 535 goto got_pampd;
1203 goto out; 536
1204 /* reject if compression is too poor */ 537 /* no match, now we need to find (or free up) a full page */
1205 if (clen > zv_max_zsize) { 538 newpage = zcache_alloc_page();
1206 zcache_compress_poor++; 539 if (newpage != NULL)
540 goto create_in_new_page;
541
542 zcache_failed_getfreepages++;
543 /* can't allocate a page, evict an ephemeral page via LRU */
544 newpage = zcache_evict_eph_pageframe();
545 if (newpage == NULL) {
546 zcache_eph_ate_tail_failed++;
547 goto out;
548 }
549 zcache_eph_ate_tail++;
550
551create_in_new_page:
552 pampd = (void *)zbud_create_prep(th, true, cdata, clen, newpage);
553 BUG_ON(pampd == NULL);
554 zcache_eph_pageframes =
555 atomic_inc_return(&zcache_eph_pageframes_atomic);
556 if (zcache_eph_pageframes > zcache_eph_pageframes_max)
557 zcache_eph_pageframes_max = zcache_eph_pageframes;
558
559got_pampd:
560 zcache_eph_zbytes =
561 atomic_long_add_return(clen, &zcache_eph_zbytes_atomic);
562 if (zcache_eph_zbytes > zcache_eph_zbytes_max)
563 zcache_eph_zbytes_max = zcache_eph_zbytes;
564 zcache_eph_zpages = atomic_inc_return(&zcache_eph_zpages_atomic);
565 if (zcache_eph_zpages > zcache_eph_zpages_max)
566 zcache_eph_zpages_max = zcache_eph_zpages;
567 if (ramster_enabled && raw)
568 ramster_count_foreign_pages(true, 1);
569out:
570 return pampd;
571}
572
573static void *zcache_pampd_pers_create(char *data, size_t size, bool raw,
574 struct tmem_handle *th)
575{
576 void *pampd = NULL, *cdata = data;
577 unsigned clen = size;
578 struct page *page = (struct page *)(data), *newpage;
579 unsigned long zbud_mean_zsize;
580 unsigned long curr_pers_zpages, total_zsize;
581
582 if (data == NULL) {
583 BUG_ON(!ramster_enabled);
584 goto create_pampd;
585 }
586 curr_pers_zpages = zcache_pers_zpages;
587/* FIXME CONFIG_RAMSTER... subtract atomic remote_pers_pages here? */
588 if (!raw)
589 zcache_compress(page, &cdata, &clen);
590 /* reject if compression is too poor */
591 if (clen > zbud_max_zsize) {
592 zcache_compress_poor++;
593 goto out;
594 }
595 /* reject if mean compression is too poor */
596 if ((clen > zbud_max_mean_zsize) && (curr_pers_zpages > 0)) {
597 total_zsize = zcache_pers_zbytes;
598 if ((long)total_zsize < 0)
599 total_zsize = 0;
600 zbud_mean_zsize = div_u64(total_zsize,
601 curr_pers_zpages);
602 if (zbud_mean_zsize > zbud_max_mean_zsize) {
603 zcache_mean_compress_poor++;
1207 goto out; 604 goto out;
1208 } 605 }
1209 /* reject if mean compression is too poor */ 606 }
1210 if ((clen > zv_max_mean_zsize) && (curr_pers_pampd_count > 0)) { 607
1211 total_zsize = zs_get_total_size_bytes(cli->zspool); 608create_pampd:
1212 zv_mean_zsize = div_u64(total_zsize, 609 /* look for space via an existing match first */
1213 curr_pers_pampd_count); 610 pampd = (void *)zbud_match_prep(th, false, cdata, clen);
1214 if (zv_mean_zsize > zv_max_mean_zsize) { 611 if (pampd != NULL)
1215 zcache_mean_compress_poor++; 612 goto got_pampd;
613
614 /* no match, now we need to find (or free up) a full page */
615 newpage = zcache_alloc_page();
616 if (newpage != NULL)
617 goto create_in_new_page;
618 /*
619 * FIXME do the following only if eph is oversized?
620 * if (zcache_eph_pageframes >
621 * (global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE) +
622 * global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE)))
623 */
624 zcache_failed_getfreepages++;
625 /* can't allocate a page, evict an ephemeral page via LRU */
626 newpage = zcache_evict_eph_pageframe();
627 if (newpage == NULL) {
628 zcache_pers_ate_eph_failed++;
629 goto out;
630 }
631 zcache_pers_ate_eph++;
632
633create_in_new_page:
634 pampd = (void *)zbud_create_prep(th, false, cdata, clen, newpage);
635 BUG_ON(pampd == NULL);
636 zcache_pers_pageframes =
637 atomic_inc_return(&zcache_pers_pageframes_atomic);
638 if (zcache_pers_pageframes > zcache_pers_pageframes_max)
639 zcache_pers_pageframes_max = zcache_pers_pageframes;
640
641got_pampd:
642 zcache_pers_zpages = atomic_inc_return(&zcache_pers_zpages_atomic);
643 if (zcache_pers_zpages > zcache_pers_zpages_max)
644 zcache_pers_zpages_max = zcache_pers_zpages;
645 zcache_pers_zbytes =
646 atomic_long_add_return(clen, &zcache_pers_zbytes_atomic);
647 if (zcache_pers_zbytes > zcache_pers_zbytes_max)
648 zcache_pers_zbytes_max = zcache_pers_zbytes;
649 if (ramster_enabled && raw)
650 ramster_count_foreign_pages(false, 1);
651out:
652 return pampd;
653}
654
655/*
656 * This is called directly from zcache_put_page to pre-allocate space
657 * to store a zpage.
658 */
659void *zcache_pampd_create(char *data, unsigned int size, bool raw,
660 int eph, struct tmem_handle *th)
661{
662 void *pampd = NULL;
663 struct zcache_preload *kp;
664 struct tmem_objnode *objnode;
665 struct tmem_obj *obj;
666 int i;
667
668 BUG_ON(!irqs_disabled());
669 /* pre-allocate per-cpu metadata */
670 BUG_ON(zcache_objnode_cache == NULL);
671 BUG_ON(zcache_obj_cache == NULL);
672 kp = &__get_cpu_var(zcache_preloads);
673 for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) {
674 objnode = kp->objnodes[i];
675 if (objnode == NULL) {
676 objnode = kmem_cache_alloc(zcache_objnode_cache,
677 ZCACHE_GFP_MASK);
678 if (unlikely(objnode == NULL)) {
679 zcache_failed_alloc++;
1216 goto out; 680 goto out;
1217 } 681 }
682 kp->objnodes[i] = objnode;
1218 } 683 }
1219 pampd = (void *)zv_create(cli->zspool, pool->pool_id,
1220 oid, index, cdata, clen);
1221 if (pampd == NULL)
1222 goto out;
1223 count = atomic_inc_return(&zcache_curr_pers_pampd_count);
1224 if (count > zcache_curr_pers_pampd_count_max)
1225 zcache_curr_pers_pampd_count_max = count;
1226 } 684 }
685 if (kp->obj == NULL) {
686 obj = kmem_cache_alloc(zcache_obj_cache, ZCACHE_GFP_MASK);
687 kp->obj = obj;
688 }
689 if (unlikely(kp->obj == NULL)) {
690 zcache_failed_alloc++;
691 goto out;
692 }
693 /*
694 * ok, have all the metadata pre-allocated, now do the data
695 * but since how we allocate the data is dependent on ephemeral
696 * or persistent, we split the call here to different sub-functions
697 */
698 if (eph)
699 pampd = zcache_pampd_eph_create(data, size, raw, th);
700 else
701 pampd = zcache_pampd_pers_create(data, size, raw, th);
1227out: 702out:
1228 return pampd; 703 return pampd;
1229} 704}
1230 705
1231/* 706/*
707 * This is a pamops called via tmem_put and is necessary to "finish"
708 * a pampd creation.
709 */
710void zcache_pampd_create_finish(void *pampd, bool eph)
711{
712 zbud_create_finish((struct zbudref *)pampd, eph);
713}
714
715/*
716 * This is passed as a function parameter to zbud_decompress so that
717 * zbud need not be familiar with the details of crypto. It assumes that
718 * the bytes from_va and to_va through from_va+size-1 and to_va+size-1 are
719 * kmapped. It must be successful, else there is a logic bug somewhere.
720 */
721static void zcache_decompress(char *from_va, unsigned int size, char *to_va)
722{
723 int ret;
724 unsigned int outlen = PAGE_SIZE;
725
726 ret = zcache_comp_op(ZCACHE_COMPOP_DECOMPRESS, from_va, size,
727 to_va, &outlen);
728 BUG_ON(ret);
729 BUG_ON(outlen != PAGE_SIZE);
730}
731
732/*
733 * Decompress from the kernel va to a pageframe
734 */
735void zcache_decompress_to_page(char *from_va, unsigned int size,
736 struct page *to_page)
737{
738 char *to_va = kmap_atomic(to_page);
739 zcache_decompress(from_va, size, to_va);
740 kunmap_atomic(to_va);
741}
742
743/*
1232 * fill the pageframe corresponding to the struct page with the data 744 * fill the pageframe corresponding to the struct page with the data
1233 * from the passed pampd 745 * from the passed pampd
1234 */ 746 */
1235static int zcache_pampd_get_data(char *data, size_t *bufsize, bool raw, 747static int zcache_pampd_get_data(char *data, size_t *sizep, bool raw,
1236 void *pampd, struct tmem_pool *pool, 748 void *pampd, struct tmem_pool *pool,
1237 struct tmem_oid *oid, uint32_t index) 749 struct tmem_oid *oid, uint32_t index)
1238{ 750{
1239 int ret = 0; 751 int ret;
1240 752 bool eph = !is_persistent(pool);
1241 BUG_ON(is_ephemeral(pool)); 753
1242 zv_decompress((struct page *)(data), (unsigned long)pampd); 754 BUG_ON(preemptible());
755 BUG_ON(eph); /* fix later if shared pools get implemented */
756 BUG_ON(pampd_is_remote(pampd));
757 if (raw)
758 ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd,
759 sizep, eph);
760 else {
761 ret = zbud_decompress((struct page *)(data),
762 (struct zbudref *)pampd, false,
763 zcache_decompress);
764 *sizep = PAGE_SIZE;
765 }
1243 return ret; 766 return ret;
1244} 767}
1245 768
@@ -1247,16 +770,50 @@ static int zcache_pampd_get_data(char *data, size_t *bufsize, bool raw,
1247 * fill the pageframe corresponding to the struct page with the data 770 * fill the pageframe corresponding to the struct page with the data
1248 * from the passed pampd 771 * from the passed pampd
1249 */ 772 */
1250static int zcache_pampd_get_data_and_free(char *data, size_t *bufsize, bool raw, 773static int zcache_pampd_get_data_and_free(char *data, size_t *sizep, bool raw,
1251 void *pampd, struct tmem_pool *pool, 774 void *pampd, struct tmem_pool *pool,
1252 struct tmem_oid *oid, uint32_t index) 775 struct tmem_oid *oid, uint32_t index)
1253{ 776{
1254 BUG_ON(!is_ephemeral(pool)); 777 int ret;
1255 if (zbud_decompress((struct page *)(data), pampd) < 0) 778 bool eph = !is_persistent(pool);
1256 return -EINVAL; 779 struct page *page = NULL;
1257 zbud_free_and_delist((struct zbud_hdr *)pampd); 780 unsigned int zsize, zpages;
1258 atomic_dec(&zcache_curr_eph_pampd_count); 781
1259 return 0; 782 BUG_ON(preemptible());
783 BUG_ON(pampd_is_remote(pampd));
784 if (raw)
785 ret = zbud_copy_from_zbud(data, (struct zbudref *)pampd,
786 sizep, eph);
787 else {
788 ret = zbud_decompress((struct page *)(data),
789 (struct zbudref *)pampd, eph,
790 zcache_decompress);
791 *sizep = PAGE_SIZE;
792 }
793 page = zbud_free_and_delist((struct zbudref *)pampd, eph,
794 &zsize, &zpages);
795 if (eph) {
796 if (page)
797 zcache_eph_pageframes =
798 atomic_dec_return(&zcache_eph_pageframes_atomic);
799 zcache_eph_zpages =
800 atomic_sub_return(zpages, &zcache_eph_zpages_atomic);
801 zcache_eph_zbytes =
802 atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
803 } else {
804 if (page)
805 zcache_pers_pageframes =
806 atomic_dec_return(&zcache_pers_pageframes_atomic);
807 zcache_pers_zpages =
808 atomic_sub_return(zpages, &zcache_pers_zpages_atomic);
809 zcache_pers_zbytes =
810 atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
811 }
812 if (!is_local_client(pool->client))
813 ramster_count_foreign_pages(eph, -1);
814 if (page)
815 zcache_free_page(page);
816 return ret;
1260} 817}
1261 818
1262/* 819/*
@@ -1264,48 +821,51 @@ static int zcache_pampd_get_data_and_free(char *data, size_t *bufsize, bool raw,
1264 * pampd must no longer be pointed to from any tmem data structures! 821 * pampd must no longer be pointed to from any tmem data structures!
1265 */ 822 */
1266static void zcache_pampd_free(void *pampd, struct tmem_pool *pool, 823static void zcache_pampd_free(void *pampd, struct tmem_pool *pool,
1267 struct tmem_oid *oid, uint32_t index) 824 struct tmem_oid *oid, uint32_t index, bool acct)
1268{ 825{
1269 struct zcache_client *cli = pool->client; 826 struct page *page = NULL;
827 unsigned int zsize, zpages;
1270 828
829 BUG_ON(preemptible());
830 if (pampd_is_remote(pampd)) {
831 BUG_ON(!ramster_enabled);
832 pampd = ramster_pampd_free(pampd, pool, oid, index, acct);
833 if (pampd == NULL)
834 return;
835 }
1271 if (is_ephemeral(pool)) { 836 if (is_ephemeral(pool)) {
1272 zbud_free_and_delist((struct zbud_hdr *)pampd); 837 page = zbud_free_and_delist((struct zbudref *)pampd,
1273 atomic_dec(&zcache_curr_eph_pampd_count); 838 true, &zsize, &zpages);
1274 BUG_ON(atomic_read(&zcache_curr_eph_pampd_count) < 0); 839 if (page)
840 zcache_eph_pageframes =
841 atomic_dec_return(&zcache_eph_pageframes_atomic);
842 zcache_eph_zpages =
843 atomic_sub_return(zpages, &zcache_eph_zpages_atomic);
844 zcache_eph_zbytes =
845 atomic_long_sub_return(zsize, &zcache_eph_zbytes_atomic);
846 /* FIXME CONFIG_RAMSTER... check acct parameter? */
1275 } else { 847 } else {
1276 zv_free(cli->zspool, (unsigned long)pampd); 848 page = zbud_free_and_delist((struct zbudref *)pampd,
1277 atomic_dec(&zcache_curr_pers_pampd_count); 849 false, &zsize, &zpages);
1278 BUG_ON(atomic_read(&zcache_curr_pers_pampd_count) < 0); 850 if (page)
851 zcache_pers_pageframes =
852 atomic_dec_return(&zcache_pers_pageframes_atomic);
853 zcache_pers_zpages =
854 atomic_sub_return(zpages, &zcache_pers_zpages_atomic);
855 zcache_pers_zbytes =
856 atomic_long_sub_return(zsize, &zcache_pers_zbytes_atomic);
1279 } 857 }
1280} 858 if (!is_local_client(pool->client))
1281 859 ramster_count_foreign_pages(is_ephemeral(pool), -1);
1282static void zcache_pampd_free_obj(struct tmem_pool *pool, struct tmem_obj *obj) 860 if (page)
1283{ 861 zcache_free_page(page);
1284}
1285
1286static void zcache_pampd_new_obj(struct tmem_obj *obj)
1287{
1288}
1289
1290static int zcache_pampd_replace_in_obj(void *pampd, struct tmem_obj *obj)
1291{
1292 return -1;
1293}
1294
1295static bool zcache_pampd_is_remote(void *pampd)
1296{
1297 return 0;
1298} 862}
1299 863
1300static struct tmem_pamops zcache_pamops = { 864static struct tmem_pamops zcache_pamops = {
1301 .create = zcache_pampd_create, 865 .create_finish = zcache_pampd_create_finish,
1302 .get_data = zcache_pampd_get_data, 866 .get_data = zcache_pampd_get_data,
1303 .get_data_and_free = zcache_pampd_get_data_and_free, 867 .get_data_and_free = zcache_pampd_get_data_and_free,
1304 .free = zcache_pampd_free, 868 .free = zcache_pampd_free,
1305 .free_obj = zcache_pampd_free_obj,
1306 .new_obj = zcache_pampd_new_obj,
1307 .replace_in_obj = zcache_pampd_replace_in_obj,
1308 .is_remote = zcache_pampd_is_remote,
1309}; 869};
1310 870
1311/* 871/*
@@ -1315,15 +875,15 @@ static struct tmem_pamops zcache_pamops = {
1315static DEFINE_PER_CPU(unsigned char *, zcache_dstmem); 875static DEFINE_PER_CPU(unsigned char *, zcache_dstmem);
1316#define ZCACHE_DSTMEM_ORDER 1 876#define ZCACHE_DSTMEM_ORDER 1
1317 877
1318static int zcache_compress(struct page *from, void **out_va, unsigned *out_len) 878static void zcache_compress(struct page *from, void **out_va, unsigned *out_len)
1319{ 879{
1320 int ret = 0; 880 int ret;
1321 unsigned char *dmem = __get_cpu_var(zcache_dstmem); 881 unsigned char *dmem = __get_cpu_var(zcache_dstmem);
1322 char *from_va; 882 char *from_va;
1323 883
1324 BUG_ON(!irqs_disabled()); 884 BUG_ON(!irqs_disabled());
1325 if (unlikely(dmem == NULL)) 885 /* no buffer or no compressor so can't compress */
1326 goto out; /* no buffer or no compressor so can't compress */ 886 BUG_ON(dmem == NULL);
1327 *out_len = PAGE_SIZE << ZCACHE_DSTMEM_ORDER; 887 *out_len = PAGE_SIZE << ZCACHE_DSTMEM_ORDER;
1328 from_va = kmap_atomic(from); 888 from_va = kmap_atomic(from);
1329 mb(); 889 mb();
@@ -1332,9 +892,6 @@ static int zcache_compress(struct page *from, void **out_va, unsigned *out_len)
1332 BUG_ON(ret); 892 BUG_ON(ret);
1333 *out_va = dmem; 893 *out_va = dmem;
1334 kunmap_atomic(from_va); 894 kunmap_atomic(from_va);
1335 ret = 1;
1336out:
1337 return ret;
1338} 895}
1339 896
1340static int zcache_comp_cpu_up(int cpu) 897static int zcache_comp_cpu_up(int cpu)
@@ -1360,18 +917,21 @@ static void zcache_comp_cpu_down(int cpu)
1360static int zcache_cpu_notifier(struct notifier_block *nb, 917static int zcache_cpu_notifier(struct notifier_block *nb,
1361 unsigned long action, void *pcpu) 918 unsigned long action, void *pcpu)
1362{ 919{
1363 int ret, cpu = (long)pcpu; 920 int ret, i, cpu = (long)pcpu;
1364 struct zcache_preload *kp; 921 struct zcache_preload *kp;
1365 922
1366 switch (action) { 923 switch (action) {
1367 case CPU_UP_PREPARE: 924 case CPU_UP_PREPARE:
1368 ret = zcache_comp_cpu_up(cpu); 925 ret = zcache_comp_cpu_up(cpu);
1369 if (ret != NOTIFY_OK) { 926 if (ret != NOTIFY_OK) {
1370 pr_err("zcache: can't allocate compressor transform\n"); 927 pr_err("%s: can't allocate compressor xform\n",
928 namestr);
1371 return ret; 929 return ret;
1372 } 930 }
1373 per_cpu(zcache_dstmem, cpu) = (void *)__get_free_pages( 931 per_cpu(zcache_dstmem, cpu) = (void *)__get_free_pages(
1374 GFP_KERNEL | __GFP_REPEAT, ZCACHE_DSTMEM_ORDER); 932 GFP_KERNEL | __GFP_REPEAT, ZCACHE_DSTMEM_ORDER);
933 if (ramster_enabled)
934 ramster_cpu_up(cpu);
1375 break; 935 break;
1376 case CPU_DEAD: 936 case CPU_DEAD:
1377 case CPU_UP_CANCELED: 937 case CPU_UP_CANCELED:
@@ -1380,20 +940,17 @@ static int zcache_cpu_notifier(struct notifier_block *nb,
1380 ZCACHE_DSTMEM_ORDER); 940 ZCACHE_DSTMEM_ORDER);
1381 per_cpu(zcache_dstmem, cpu) = NULL; 941 per_cpu(zcache_dstmem, cpu) = NULL;
1382 kp = &per_cpu(zcache_preloads, cpu); 942 kp = &per_cpu(zcache_preloads, cpu);
1383 while (kp->nr) { 943 for (i = 0; i < ARRAY_SIZE(kp->objnodes); i++) {
1384 kmem_cache_free(zcache_objnode_cache, 944 if (kp->objnodes[i])
1385 kp->objnodes[kp->nr - 1]); 945 kmem_cache_free(zcache_objnode_cache,
1386 kp->objnodes[kp->nr - 1] = NULL; 946 kp->objnodes[i]);
1387 kp->nr--;
1388 } 947 }
1389 if (kp->obj) { 948 if (kp->obj) {
1390 kmem_cache_free(zcache_obj_cache, kp->obj); 949 kmem_cache_free(zcache_obj_cache, kp->obj);
1391 kp->obj = NULL; 950 kp->obj = NULL;
1392 } 951 }
1393 if (kp->page) { 952 if (ramster_enabled)
1394 free_page((unsigned long)kp->page); 953 ramster_cpu_down(cpu);
1395 kp->page = NULL;
1396 }
1397 break; 954 break;
1398 default: 955 default:
1399 break; 956 break;
@@ -1405,116 +962,279 @@ static struct notifier_block zcache_cpu_notifier_block = {
1405 .notifier_call = zcache_cpu_notifier 962 .notifier_call = zcache_cpu_notifier
1406}; 963};
1407 964
1408#ifdef CONFIG_SYSFS 965/*
1409#define ZCACHE_SYSFS_RO(_name) \ 966 * The following code interacts with the zbud eviction and zbud
1410 static ssize_t zcache_##_name##_show(struct kobject *kobj, \ 967 * zombify code to access LRU pages
1411 struct kobj_attribute *attr, char *buf) \ 968 */
1412 { \ 969
1413 return sprintf(buf, "%lu\n", zcache_##_name); \ 970static struct page *zcache_evict_eph_pageframe(void)
1414 } \ 971{
1415 static struct kobj_attribute zcache_##_name##_attr = { \ 972 struct page *page;
1416 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 973 unsigned int zsize = 0, zpages = 0;
1417 .show = zcache_##_name##_show, \ 974
1418 } 975 page = zbud_evict_pageframe_lru(&zsize, &zpages);
976 if (page == NULL)
977 goto out;
978 zcache_eph_zbytes = atomic_long_sub_return(zsize,
979 &zcache_eph_zbytes_atomic);
980 zcache_eph_zpages = atomic_sub_return(zpages,
981 &zcache_eph_zpages_atomic);
982 zcache_evicted_eph_zpages += zpages;
983 zcache_eph_pageframes =
984 atomic_dec_return(&zcache_eph_pageframes_atomic);
985 zcache_evicted_eph_pageframes++;
986out:
987 return page;
988}
989
990#ifdef CONFIG_ZCACHE_WRITEBACK
991
992static atomic_t zcache_outstanding_writeback_pages_atomic = ATOMIC_INIT(0);
993
994static void unswiz(struct tmem_oid oid, u32 index,
995 unsigned *type, pgoff_t *offset);
996
997/*
998 * Choose an LRU persistent pageframe and attempt to write it back to
999 * the backing swap disk by calling frontswap_writeback on both zpages.
1000 *
1001 * This is work-in-progress.
1002 */
1419 1003
1420#define ZCACHE_SYSFS_RO_ATOMIC(_name) \ 1004static void zcache_end_swap_write(struct bio *bio, int err)
1421 static ssize_t zcache_##_name##_show(struct kobject *kobj, \ 1005{
1422 struct kobj_attribute *attr, char *buf) \ 1006 end_swap_bio_write(bio, err);
1423 { \ 1007 zcache_outstanding_writeback_pages =
1424 return sprintf(buf, "%d\n", atomic_read(&zcache_##_name)); \ 1008 atomic_dec_return(&zcache_outstanding_writeback_pages_atomic);
1425 } \ 1009 zcache_writtenback_pages++;
1426 static struct kobj_attribute zcache_##_name##_attr = { \ 1010}
1427 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 1011
1428 .show = zcache_##_name##_show, \ 1012/*
1013 * zcache_get_swap_cache_page
1014 *
1015 * This is an adaption of read_swap_cache_async()
1016 *
1017 * If success, page is returned in retpage
1018 * Returns 0 if page was already in the swap cache, page is not locked
1019 * Returns 1 if the new page needs to be populated, page is locked
1020 */
1021static int zcache_get_swap_cache_page(int type, pgoff_t offset,
1022 struct page *new_page)
1023{
1024 struct page *found_page;
1025 swp_entry_t entry = swp_entry(type, offset);
1026 int err;
1027
1028 BUG_ON(new_page == NULL);
1029 do {
1030 /*
1031 * First check the swap cache. Since this is normally
1032 * called after lookup_swap_cache() failed, re-calling
1033 * that would confuse statistics.
1034 */
1035 found_page = find_get_page(&swapper_space, entry.val);
1036 if (found_page)
1037 return 0;
1038
1039 /*
1040 * call radix_tree_preload() while we can wait.
1041 */
1042 err = radix_tree_preload(GFP_KERNEL);
1043 if (err)
1044 break;
1045
1046 /*
1047 * Swap entry may have been freed since our caller observed it.
1048 */
1049 err = swapcache_prepare(entry);
1050 if (err == -EEXIST) { /* seems racy */
1051 radix_tree_preload_end();
1052 continue;
1053 }
1054 if (err) { /* swp entry is obsolete ? */
1055 radix_tree_preload_end();
1056 break;
1057 }
1058
1059 /* May fail (-ENOMEM) if radix-tree node allocation failed. */
1060 __set_page_locked(new_page);
1061 SetPageSwapBacked(new_page);
1062 err = __add_to_swap_cache(new_page, entry);
1063 if (likely(!err)) {
1064 radix_tree_preload_end();
1065 lru_cache_add_anon(new_page);
1066 return 1;
1067 }
1068 radix_tree_preload_end();
1069 ClearPageSwapBacked(new_page);
1070 __clear_page_locked(new_page);
1071 /*
1072 * add_to_swap_cache() doesn't return -EEXIST, so we can safely
1073 * clear SWAP_HAS_CACHE flag.
1074 */
1075 swapcache_free(entry, NULL);
1076 /* FIXME: is it possible to get here without err==-ENOMEM?
1077 * If not, we can dispense with the do loop, use goto retry */
1078 } while (err != -ENOMEM);
1079
1080 return -ENOMEM;
1081}
1082
1083/*
1084 * Given a frontswap zpage in zcache (identified by type/offset) and
1085 * an empty page, put the page into the swap cache, use frontswap
1086 * to get the page from zcache into the empty page, then give it
1087 * to the swap subsystem to send to disk (carefully avoiding the
1088 * possibility that frontswap might snatch it back).
1089 * Returns < 0 if error, 0 if successful, and 1 if successful but
1090 * the newpage passed in not needed and should be freed.
1091 */
1092static int zcache_frontswap_writeback_zpage(int type, pgoff_t offset,
1093 struct page *newpage)
1094{
1095 struct page *page = newpage;
1096 int ret;
1097 struct writeback_control wbc = {
1098 .sync_mode = WB_SYNC_NONE,
1099 };
1100
1101 ret = zcache_get_swap_cache_page(type, offset, page);
1102 if (ret < 0)
1103 return ret;
1104 else if (ret == 0) {
1105 /* more uptodate page is already in swapcache */
1106 __frontswap_invalidate_page(type, offset);
1107 return 1;
1429 } 1108 }
1430 1109
1431#define ZCACHE_SYSFS_RO_CUSTOM(_name, _func) \ 1110 BUG_ON(!frontswap_has_exclusive_gets); /* load must also invalidate */
1432 static ssize_t zcache_##_name##_show(struct kobject *kobj, \ 1111 /* FIXME: how is it possible to get here when page is unlocked? */
1433 struct kobj_attribute *attr, char *buf) \ 1112 __frontswap_load(page);
1434 { \ 1113 SetPageUptodate(page); /* above does SetPageDirty, is that enough? */
1435 return _func(buf); \ 1114
1436 } \ 1115 /* start writeback */
1437 static struct kobj_attribute zcache_##_name##_attr = { \ 1116 SetPageReclaim(page);
1438 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 1117 /*
1439 .show = zcache_##_name##_show, \ 1118 * Return value is ignored here because it doesn't change anything
1119 * for us. Page is returned unlocked.
1120 */
1121 (void)__swap_writepage(page, &wbc, zcache_end_swap_write);
1122 page_cache_release(page);
1123 zcache_outstanding_writeback_pages =
1124 atomic_inc_return(&zcache_outstanding_writeback_pages_atomic);
1125
1126 return 0;
1127}
1128
1129/*
1130 * The following is still a magic number... we want to allow forward progress
1131 * for writeback because it clears out needed RAM when under pressure, but
1132 * we don't want to allow writeback to absorb and queue too many GFP_KERNEL
1133 * pages if the swap device is very slow.
1134 */
1135#define ZCACHE_MAX_OUTSTANDING_WRITEBACK_PAGES 6400
1136
1137/*
1138 * Try to allocate two free pages, first using a non-aggressive alloc,
1139 * then by evicting zcache ephemeral (clean pagecache) pages, and last
1140 * by aggressive GFP_KERNEL alloc. We allow zbud to choose a pageframe
1141 * consisting of 1-2 zbuds/zpages, then call the writeback_zpage helper
1142 * function above for each.
1143 */
1144static int zcache_frontswap_writeback(void)
1145{
1146 struct tmem_handle th[2];
1147 int ret = 0;
1148 int nzbuds, writeback_ret;
1149 unsigned type;
1150 struct page *znewpage1 = NULL, *znewpage2 = NULL;
1151 struct page *evictpage1 = NULL, *evictpage2 = NULL;
1152 struct page *newpage1 = NULL, *newpage2 = NULL;
1153 struct page *page1 = NULL, *page2 = NULL;
1154 pgoff_t offset;
1155
1156 znewpage1 = alloc_page(ZCACHE_GFP_MASK);
1157 znewpage2 = alloc_page(ZCACHE_GFP_MASK);
1158 if (znewpage1 == NULL)
1159 evictpage1 = zcache_evict_eph_pageframe();
1160 if (znewpage2 == NULL)
1161 evictpage2 = zcache_evict_eph_pageframe();
1162
1163 if ((evictpage1 == NULL || evictpage2 == NULL) &&
1164 atomic_read(&zcache_outstanding_writeback_pages_atomic) >
1165 ZCACHE_MAX_OUTSTANDING_WRITEBACK_PAGES) {
1166 goto free_and_out;
1167 }
1168 if (znewpage1 == NULL && evictpage1 == NULL)
1169 newpage1 = alloc_page(GFP_KERNEL);
1170 if (znewpage2 == NULL && evictpage2 == NULL)
1171 newpage2 = alloc_page(GFP_KERNEL);
1172 if (newpage1 == NULL || newpage2 == NULL)
1173 goto free_and_out;
1174
1175 /* ok, we have two pageframes pre-allocated, get a pair of zbuds */
1176 nzbuds = zbud_make_zombie_lru(&th[0], NULL, NULL, false);
1177 if (nzbuds == 0) {
1178 ret = -ENOENT;
1179 goto free_and_out;
1440 } 1180 }
1441 1181
1442ZCACHE_SYSFS_RO(curr_obj_count_max); 1182 /* process the first zbud */
1443ZCACHE_SYSFS_RO(curr_objnode_count_max); 1183 unswiz(th[0].oid, th[0].index, &type, &offset);
1444ZCACHE_SYSFS_RO(flush_total); 1184 page1 = (znewpage1 != NULL) ? znewpage1 :
1445ZCACHE_SYSFS_RO(flush_found); 1185 ((newpage1 != NULL) ? newpage1 : evictpage1);
1446ZCACHE_SYSFS_RO(flobj_total); 1186 writeback_ret = zcache_frontswap_writeback_zpage(type, offset, page1);
1447ZCACHE_SYSFS_RO(flobj_found); 1187 if (writeback_ret < 0) {
1448ZCACHE_SYSFS_RO(failed_eph_puts); 1188 ret = -ENOMEM;
1449ZCACHE_SYSFS_RO(failed_pers_puts); 1189 goto free_and_out;
1450ZCACHE_SYSFS_RO(zbud_curr_zbytes); 1190 }
1451ZCACHE_SYSFS_RO(zbud_cumul_zpages); 1191 if (evictpage1 != NULL)
1452ZCACHE_SYSFS_RO(zbud_cumul_zbytes); 1192 zcache_pageframes_freed =
1453ZCACHE_SYSFS_RO(zbud_buddied_count); 1193 atomic_inc_return(&zcache_pageframes_freed_atomic);
1454ZCACHE_SYSFS_RO(zbpg_unused_list_count); 1194 if (writeback_ret == 0) {
1455ZCACHE_SYSFS_RO(evicted_raw_pages); 1195 /* zcache_get_swap_cache_page will free, don't double free */
1456ZCACHE_SYSFS_RO(evicted_unbuddied_pages); 1196 znewpage1 = NULL;
1457ZCACHE_SYSFS_RO(evicted_buddied_pages); 1197 newpage1 = NULL;
1458ZCACHE_SYSFS_RO(failed_get_free_pages); 1198 evictpage1 = NULL;
1459ZCACHE_SYSFS_RO(failed_alloc); 1199 }
1460ZCACHE_SYSFS_RO(put_to_flush); 1200 if (nzbuds < 2)
1461ZCACHE_SYSFS_RO(compress_poor); 1201 goto free_and_out;
1462ZCACHE_SYSFS_RO(mean_compress_poor); 1202
1463ZCACHE_SYSFS_RO_ATOMIC(zbud_curr_raw_pages); 1203 /* if there is a second zbud, process it */
1464ZCACHE_SYSFS_RO_ATOMIC(zbud_curr_zpages); 1204 unswiz(th[1].oid, th[1].index, &type, &offset);
1465ZCACHE_SYSFS_RO_ATOMIC(curr_obj_count); 1205 page2 = (znewpage2 != NULL) ? znewpage2 :
1466ZCACHE_SYSFS_RO_ATOMIC(curr_objnode_count); 1206 ((newpage2 != NULL) ? newpage2 : evictpage2);
1467ZCACHE_SYSFS_RO_CUSTOM(zbud_unbuddied_list_counts, 1207 writeback_ret = zcache_frontswap_writeback_zpage(type, offset, page2);
1468 zbud_show_unbuddied_list_counts); 1208 if (writeback_ret < 0) {
1469ZCACHE_SYSFS_RO_CUSTOM(zbud_cumul_chunk_counts, 1209 ret = -ENOMEM;
1470 zbud_show_cumul_chunk_counts); 1210 goto free_and_out;
1471ZCACHE_SYSFS_RO_CUSTOM(zv_curr_dist_counts, 1211 }
1472 zv_curr_dist_counts_show); 1212 if (evictpage2 != NULL)
1473ZCACHE_SYSFS_RO_CUSTOM(zv_cumul_dist_counts, 1213 zcache_pageframes_freed =
1474 zv_cumul_dist_counts_show); 1214 atomic_inc_return(&zcache_pageframes_freed_atomic);
1475 1215 if (writeback_ret == 0) {
1476static struct attribute *zcache_attrs[] = { 1216 znewpage2 = NULL;
1477 &zcache_curr_obj_count_attr.attr, 1217 newpage2 = NULL;
1478 &zcache_curr_obj_count_max_attr.attr, 1218 evictpage2 = NULL;
1479 &zcache_curr_objnode_count_attr.attr, 1219 }
1480 &zcache_curr_objnode_count_max_attr.attr,
1481 &zcache_flush_total_attr.attr,
1482 &zcache_flobj_total_attr.attr,
1483 &zcache_flush_found_attr.attr,
1484 &zcache_flobj_found_attr.attr,
1485 &zcache_failed_eph_puts_attr.attr,
1486 &zcache_failed_pers_puts_attr.attr,
1487 &zcache_compress_poor_attr.attr,
1488 &zcache_mean_compress_poor_attr.attr,
1489 &zcache_zbud_curr_raw_pages_attr.attr,
1490 &zcache_zbud_curr_zpages_attr.attr,
1491 &zcache_zbud_curr_zbytes_attr.attr,
1492 &zcache_zbud_cumul_zpages_attr.attr,
1493 &zcache_zbud_cumul_zbytes_attr.attr,
1494 &zcache_zbud_buddied_count_attr.attr,
1495 &zcache_zbpg_unused_list_count_attr.attr,
1496 &zcache_evicted_raw_pages_attr.attr,
1497 &zcache_evicted_unbuddied_pages_attr.attr,
1498 &zcache_evicted_buddied_pages_attr.attr,
1499 &zcache_failed_get_free_pages_attr.attr,
1500 &zcache_failed_alloc_attr.attr,
1501 &zcache_put_to_flush_attr.attr,
1502 &zcache_zbud_unbuddied_list_counts_attr.attr,
1503 &zcache_zbud_cumul_chunk_counts_attr.attr,
1504 &zcache_zv_curr_dist_counts_attr.attr,
1505 &zcache_zv_cumul_dist_counts_attr.attr,
1506 &zcache_zv_max_zsize_attr.attr,
1507 &zcache_zv_max_mean_zsize_attr.attr,
1508 &zcache_zv_page_count_policy_percent_attr.attr,
1509 NULL,
1510};
1511 1220
1512static struct attribute_group zcache_attr_group = { 1221free_and_out:
1513 .attrs = zcache_attrs, 1222 if (znewpage1 != NULL)
1514 .name = "zcache", 1223 page_cache_release(znewpage1);
1515}; 1224 if (znewpage2 != NULL)
1225 page_cache_release(znewpage2);
1226 if (newpage1 != NULL)
1227 page_cache_release(newpage1);
1228 if (newpage2 != NULL)
1229 page_cache_release(newpage2);
1230 if (evictpage1 != NULL)
1231 zcache_free_page(evictpage1);
1232 if (evictpage2 != NULL)
1233 zcache_free_page(evictpage2);
1234 return ret;
1235}
1236#endif /* CONFIG_ZCACHE_WRITEBACK */
1516 1237
1517#endif /* CONFIG_SYSFS */
1518/* 1238/*
1519 * When zcache is disabled ("frozen"), pools can be created and destroyed, 1239 * When zcache is disabled ("frozen"), pools can be created and destroyed,
1520 * but all puts (and thus all other operations that require memory allocation) 1240 * but all puts (and thus all other operations that require memory allocation)
@@ -1525,23 +1245,81 @@ static struct attribute_group zcache_attr_group = {
1525static bool zcache_freeze; 1245static bool zcache_freeze;
1526 1246
1527/* 1247/*
1528 * zcache shrinker interface (only useful for ephemeral pages, so zbud only) 1248 * This zcache shrinker interface reduces the number of ephemeral pageframes
1249 * used by zcache to approximately the same as the total number of LRU_FILE
1250 * pageframes in use, and now also reduces the number of persistent pageframes
1251 * used by zcache to approximately the same as the total number of LRU_ANON
1252 * pageframes in use. FIXME POLICY: Probably the writeback should only occur
1253 * if the eviction doesn't free enough pages.
1529 */ 1254 */
1530static int shrink_zcache_memory(struct shrinker *shrink, 1255static int shrink_zcache_memory(struct shrinker *shrink,
1531 struct shrink_control *sc) 1256 struct shrink_control *sc)
1532{ 1257{
1258 static bool in_progress;
1533 int ret = -1; 1259 int ret = -1;
1534 int nr = sc->nr_to_scan; 1260 int nr = sc->nr_to_scan;
1535 gfp_t gfp_mask = sc->gfp_mask; 1261 int nr_evict = 0;
1262 int nr_writeback = 0;
1263 struct page *page;
1264 int file_pageframes_inuse, anon_pageframes_inuse;
1265
1266 if (nr <= 0)
1267 goto skip_evict;
1268
1269 /* don't allow more than one eviction thread at a time */
1270 if (in_progress)
1271 goto skip_evict;
1272
1273 in_progress = true;
1274
1275 /* we are going to ignore nr, and target a different value */
1276 zcache_last_active_file_pageframes =
1277 global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE);
1278 zcache_last_inactive_file_pageframes =
1279 global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE);
1280 file_pageframes_inuse = zcache_last_active_file_pageframes +
1281 zcache_last_inactive_file_pageframes;
1282 if (zcache_eph_pageframes > file_pageframes_inuse)
1283 nr_evict = zcache_eph_pageframes - file_pageframes_inuse;
1284 else
1285 nr_evict = 0;
1286 while (nr_evict-- > 0) {
1287 page = zcache_evict_eph_pageframe();
1288 if (page == NULL)
1289 break;
1290 zcache_free_page(page);
1291 }
1536 1292
1537 if (nr >= 0) { 1293 zcache_last_active_anon_pageframes =
1538 if (!(gfp_mask & __GFP_FS)) 1294 global_page_state(NR_LRU_BASE + LRU_ACTIVE_ANON);
1539 /* does this case really need to be skipped? */ 1295 zcache_last_inactive_anon_pageframes =
1540 goto out; 1296 global_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON);
1541 zbud_evict_pages(nr); 1297 anon_pageframes_inuse = zcache_last_active_anon_pageframes +
1298 zcache_last_inactive_anon_pageframes;
1299 if (zcache_pers_pageframes > anon_pageframes_inuse)
1300 nr_writeback = zcache_pers_pageframes - anon_pageframes_inuse;
1301 else
1302 nr_writeback = 0;
1303 while (nr_writeback-- > 0) {
1304#ifdef CONFIG_ZCACHE_WRITEBACK
1305 int writeback_ret;
1306 writeback_ret = zcache_frontswap_writeback();
1307 if (writeback_ret == -ENOMEM)
1308#endif
1309 break;
1542 } 1310 }
1543 ret = (int)atomic_read(&zcache_zbud_curr_raw_pages); 1311 in_progress = false;
1544out: 1312
1313skip_evict:
1314 /* resample: has changed, but maybe not all the way yet */
1315 zcache_last_active_file_pageframes =
1316 global_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE);
1317 zcache_last_inactive_file_pageframes =
1318 global_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE);
1319 ret = zcache_eph_pageframes - zcache_last_active_file_pageframes +
1320 zcache_last_inactive_file_pageframes;
1321 if (ret < 0)
1322 ret = 0;
1545 return ret; 1323 return ret;
1546} 1324}
1547 1325
@@ -1554,59 +1332,86 @@ static struct shrinker zcache_shrinker = {
1554 * zcache shims between cleancache/frontswap ops and tmem 1332 * zcache shims between cleancache/frontswap ops and tmem
1555 */ 1333 */
1556 1334
1557static int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp, 1335/* FIXME rename these core routines to zcache_tmemput etc? */
1558 uint32_t index, struct page *page) 1336int zcache_put_page(int cli_id, int pool_id, struct tmem_oid *oidp,
1337 uint32_t index, void *page,
1338 unsigned int size, bool raw, int ephemeral)
1559{ 1339{
1560 struct tmem_pool *pool; 1340 struct tmem_pool *pool;
1341 struct tmem_handle th;
1561 int ret = -1; 1342 int ret = -1;
1343 void *pampd = NULL;
1562 1344
1563 BUG_ON(!irqs_disabled()); 1345 BUG_ON(!irqs_disabled());
1564 pool = zcache_get_pool_by_id(cli_id, pool_id); 1346 pool = zcache_get_pool_by_id(cli_id, pool_id);
1565 if (unlikely(pool == NULL)) 1347 if (unlikely(pool == NULL))
1566 goto out; 1348 goto out;
1567 if (!zcache_freeze && zcache_do_preload(pool) == 0) { 1349 if (!zcache_freeze) {
1568 /* preload does preempt_disable on success */ 1350 ret = 0;
1569 ret = tmem_put(pool, oidp, index, (char *)(page), 1351 th.client_id = cli_id;
1570 PAGE_SIZE, 0, is_ephemeral(pool)); 1352 th.pool_id = pool_id;
1571 if (ret < 0) { 1353 th.oid = *oidp;
1572 if (is_ephemeral(pool)) 1354 th.index = index;
1355 pampd = zcache_pampd_create((char *)page, size, raw,
1356 ephemeral, &th);
1357 if (pampd == NULL) {
1358 ret = -ENOMEM;
1359 if (ephemeral)
1573 zcache_failed_eph_puts++; 1360 zcache_failed_eph_puts++;
1574 else 1361 else
1575 zcache_failed_pers_puts++; 1362 zcache_failed_pers_puts++;
1363 } else {
1364 if (ramster_enabled)
1365 ramster_do_preload_flnode(pool);
1366 ret = tmem_put(pool, oidp, index, 0, pampd);
1367 if (ret < 0)
1368 BUG();
1576 } 1369 }
1370 zcache_put_pool(pool);
1577 } else { 1371 } else {
1578 zcache_put_to_flush++; 1372 zcache_put_to_flush++;
1373 if (ramster_enabled)
1374 ramster_do_preload_flnode(pool);
1579 if (atomic_read(&pool->obj_count) > 0) 1375 if (atomic_read(&pool->obj_count) > 0)
1580 /* the put fails whether the flush succeeds or not */ 1376 /* the put fails whether the flush succeeds or not */
1581 (void)tmem_flush_page(pool, oidp, index); 1377 (void)tmem_flush_page(pool, oidp, index);
1378 zcache_put_pool(pool);
1582 } 1379 }
1583
1584 zcache_put_pool(pool);
1585out: 1380out:
1586 return ret; 1381 return ret;
1587} 1382}
1588 1383
1589static int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp, 1384int zcache_get_page(int cli_id, int pool_id, struct tmem_oid *oidp,
1590 uint32_t index, struct page *page) 1385 uint32_t index, void *page,
1386 size_t *sizep, bool raw, int get_and_free)
1591{ 1387{
1592 struct tmem_pool *pool; 1388 struct tmem_pool *pool;
1593 int ret = -1; 1389 int ret = -1;
1594 unsigned long flags; 1390 bool eph;
1595 size_t size = PAGE_SIZE;
1596 1391
1597 local_irq_save(flags); 1392 if (!raw) {
1393 BUG_ON(irqs_disabled());
1394 BUG_ON(in_softirq());
1395 }
1598 pool = zcache_get_pool_by_id(cli_id, pool_id); 1396 pool = zcache_get_pool_by_id(cli_id, pool_id);
1397 eph = is_ephemeral(pool);
1599 if (likely(pool != NULL)) { 1398 if (likely(pool != NULL)) {
1600 if (atomic_read(&pool->obj_count) > 0) 1399 if (atomic_read(&pool->obj_count) > 0)
1601 ret = tmem_get(pool, oidp, index, (char *)(page), 1400 ret = tmem_get(pool, oidp, index, (char *)(page),
1602 &size, 0, is_ephemeral(pool)); 1401 sizep, raw, get_and_free);
1603 zcache_put_pool(pool); 1402 zcache_put_pool(pool);
1604 } 1403 }
1605 local_irq_restore(flags); 1404 WARN_ONCE((!is_ephemeral(pool) && (ret != 0)),
1405 "zcache_get fails on persistent pool, "
1406 "bad things are very likely to happen soon\n");
1407#ifdef RAMSTER_TESTING
1408 if (ret != 0 && ret != -1 && !(ret == -EINVAL && is_ephemeral(pool)))
1409 pr_err("TESTING zcache_get tmem_get returns ret=%d\n", ret);
1410#endif
1606 return ret; 1411 return ret;
1607} 1412}
1608 1413
1609static int zcache_flush_page(int cli_id, int pool_id, 1414int zcache_flush_page(int cli_id, int pool_id,
1610 struct tmem_oid *oidp, uint32_t index) 1415 struct tmem_oid *oidp, uint32_t index)
1611{ 1416{
1612 struct tmem_pool *pool; 1417 struct tmem_pool *pool;
@@ -1616,6 +1421,8 @@ static int zcache_flush_page(int cli_id, int pool_id,
1616 local_irq_save(flags); 1421 local_irq_save(flags);
1617 zcache_flush_total++; 1422 zcache_flush_total++;
1618 pool = zcache_get_pool_by_id(cli_id, pool_id); 1423 pool = zcache_get_pool_by_id(cli_id, pool_id);
1424 if (ramster_enabled)
1425 ramster_do_preload_flnode(pool);
1619 if (likely(pool != NULL)) { 1426 if (likely(pool != NULL)) {
1620 if (atomic_read(&pool->obj_count) > 0) 1427 if (atomic_read(&pool->obj_count) > 0)
1621 ret = tmem_flush_page(pool, oidp, index); 1428 ret = tmem_flush_page(pool, oidp, index);
@@ -1627,7 +1434,7 @@ static int zcache_flush_page(int cli_id, int pool_id,
1627 return ret; 1434 return ret;
1628} 1435}
1629 1436
1630static int zcache_flush_object(int cli_id, int pool_id, 1437int zcache_flush_object(int cli_id, int pool_id,
1631 struct tmem_oid *oidp) 1438 struct tmem_oid *oidp)
1632{ 1439{
1633 struct tmem_pool *pool; 1440 struct tmem_pool *pool;
@@ -1637,6 +1444,8 @@ static int zcache_flush_object(int cli_id, int pool_id,
1637 local_irq_save(flags); 1444 local_irq_save(flags);
1638 zcache_flobj_total++; 1445 zcache_flobj_total++;
1639 pool = zcache_get_pool_by_id(cli_id, pool_id); 1446 pool = zcache_get_pool_by_id(cli_id, pool_id);
1447 if (ramster_enabled)
1448 ramster_do_preload_flnode(pool);
1640 if (likely(pool != NULL)) { 1449 if (likely(pool != NULL)) {
1641 if (atomic_read(&pool->obj_count) > 0) 1450 if (atomic_read(&pool->obj_count) > 0)
1642 ret = tmem_flush_object(pool, oidp); 1451 ret = tmem_flush_object(pool, oidp);
@@ -1648,24 +1457,25 @@ static int zcache_flush_object(int cli_id, int pool_id,
1648 return ret; 1457 return ret;
1649} 1458}
1650 1459
1651static int zcache_destroy_pool(int cli_id, int pool_id) 1460static int zcache_client_destroy_pool(int cli_id, int pool_id)
1652{ 1461{
1653 struct tmem_pool *pool = NULL; 1462 struct tmem_pool *pool = NULL;
1654 struct zcache_client *cli; 1463 struct zcache_client *cli = NULL;
1655 int ret = -1; 1464 int ret = -1;
1656 1465
1657 if (pool_id < 0) 1466 if (pool_id < 0)
1658 goto out; 1467 goto out;
1659 1468 if (cli_id == LOCAL_CLIENT)
1660 cli = get_zcache_client(cli_id); 1469 cli = &zcache_host;
1470 else if ((unsigned int)cli_id < MAX_CLIENTS)
1471 cli = &zcache_clients[cli_id];
1661 if (cli == NULL) 1472 if (cli == NULL)
1662 goto out; 1473 goto out;
1663
1664 atomic_inc(&cli->refcount); 1474 atomic_inc(&cli->refcount);
1665 pool = idr_find(&cli->tmem_pools, pool_id); 1475 pool = cli->tmem_pools[pool_id];
1666 if (pool == NULL) 1476 if (pool == NULL)
1667 goto out; 1477 goto out;
1668 idr_remove(&cli->tmem_pools, pool_id); 1478 cli->tmem_pools[pool_id] = NULL;
1669 /* wait for pool activity on other cpus to quiesce */ 1479 /* wait for pool activity on other cpus to quiesce */
1670 while (atomic_read(&pool->refcount) != 0) 1480 while (atomic_read(&pool->refcount) != 0)
1671 ; 1481 ;
@@ -1674,56 +1484,119 @@ static int zcache_destroy_pool(int cli_id, int pool_id)
1674 ret = tmem_destroy_pool(pool); 1484 ret = tmem_destroy_pool(pool);
1675 local_bh_enable(); 1485 local_bh_enable();
1676 kfree(pool); 1486 kfree(pool);
1677 pr_info("zcache: destroyed pool id=%d, cli_id=%d\n", 1487 if (cli_id == LOCAL_CLIENT)
1678 pool_id, cli_id); 1488 pr_info("%s: destroyed local pool id=%d\n", namestr, pool_id);
1489 else
1490 pr_info("%s: destroyed pool id=%d, client=%d\n",
1491 namestr, pool_id, cli_id);
1679out: 1492out:
1680 return ret; 1493 return ret;
1681} 1494}
1682 1495
1683static int zcache_new_pool(uint16_t cli_id, uint32_t flags) 1496int zcache_new_pool(uint16_t cli_id, uint32_t flags)
1684{ 1497{
1685 int poolid = -1; 1498 int poolid = -1;
1686 struct tmem_pool *pool; 1499 struct tmem_pool *pool;
1687 struct zcache_client *cli = NULL; 1500 struct zcache_client *cli = NULL;
1688 int r;
1689 1501
1690 cli = get_zcache_client(cli_id); 1502 if (cli_id == LOCAL_CLIENT)
1503 cli = &zcache_host;
1504 else if ((unsigned int)cli_id < MAX_CLIENTS)
1505 cli = &zcache_clients[cli_id];
1691 if (cli == NULL) 1506 if (cli == NULL)
1692 goto out; 1507 goto out;
1693
1694 atomic_inc(&cli->refcount); 1508 atomic_inc(&cli->refcount);
1695 pool = kmalloc(sizeof(struct tmem_pool), GFP_ATOMIC); 1509 pool = kmalloc(sizeof(struct tmem_pool), GFP_ATOMIC);
1696 if (pool == NULL) { 1510 if (pool == NULL)
1697 pr_info("zcache: pool creation failed: out of memory\n"); 1511 goto out;
1512
1513 for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++)
1514 if (cli->tmem_pools[poolid] == NULL)
1515 break;
1516 if (poolid >= MAX_POOLS_PER_CLIENT) {
1517 pr_info("%s: pool creation failed: max exceeded\n", namestr);
1518 kfree(pool);
1519 poolid = -1;
1698 goto out; 1520 goto out;
1699 } 1521 }
1522 atomic_set(&pool->refcount, 0);
1523 pool->client = cli;
1524 pool->pool_id = poolid;
1525 tmem_new_pool(pool, flags);
1526 cli->tmem_pools[poolid] = pool;
1527 if (cli_id == LOCAL_CLIENT)
1528 pr_info("%s: created %s local tmem pool, id=%d\n", namestr,
1529 flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
1530 poolid);
1531 else
1532 pr_info("%s: created %s tmem pool, id=%d, client=%d\n", namestr,
1533 flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
1534 poolid, cli_id);
1535out:
1536 if (cli != NULL)
1537 atomic_dec(&cli->refcount);
1538 return poolid;
1539}
1700 1540
1701 do { 1541static int zcache_local_new_pool(uint32_t flags)
1702 r = idr_pre_get(&cli->tmem_pools, GFP_ATOMIC); 1542{
1703 if (r != 1) { 1543 return zcache_new_pool(LOCAL_CLIENT, flags);
1704 kfree(pool); 1544}
1705 pr_info("zcache: pool creation failed: out of memory\n"); 1545
1546int zcache_autocreate_pool(unsigned int cli_id, unsigned int pool_id, bool eph)
1547{
1548 struct tmem_pool *pool;
1549 struct zcache_client *cli;
1550 uint32_t flags = eph ? 0 : TMEM_POOL_PERSIST;
1551 int ret = -1;
1552
1553 BUG_ON(!ramster_enabled);
1554 if (cli_id == LOCAL_CLIENT)
1555 goto out;
1556 if (pool_id >= MAX_POOLS_PER_CLIENT)
1557 goto out;
1558 if (cli_id >= MAX_CLIENTS)
1559 goto out;
1560
1561 cli = &zcache_clients[cli_id];
1562 if ((eph && disable_cleancache) || (!eph && disable_frontswap)) {
1563 pr_err("zcache_autocreate_pool: pool type disabled\n");
1564 goto out;
1565 }
1566 if (!cli->allocated) {
1567 if (zcache_new_client(cli_id)) {
1568 pr_err("zcache_autocreate_pool: can't create client\n");
1706 goto out; 1569 goto out;
1707 } 1570 }
1708 r = idr_get_new(&cli->tmem_pools, pool, &poolid); 1571 cli = &zcache_clients[cli_id];
1709 } while (r == -EAGAIN); 1572 }
1710 if (r) { 1573 atomic_inc(&cli->refcount);
1711 pr_info("zcache: pool creation failed: error %d\n", r); 1574 pool = cli->tmem_pools[pool_id];
1712 kfree(pool); 1575 if (pool != NULL) {
1576 if (pool->persistent && eph) {
1577 pr_err("zcache_autocreate_pool: type mismatch\n");
1578 goto out;
1579 }
1580 ret = 0;
1713 goto out; 1581 goto out;
1714 } 1582 }
1583 pool = kmalloc(sizeof(struct tmem_pool), GFP_KERNEL);
1584 if (pool == NULL)
1585 goto out;
1715 1586
1716 atomic_set(&pool->refcount, 0); 1587 atomic_set(&pool->refcount, 0);
1717 pool->client = cli; 1588 pool->client = cli;
1718 pool->pool_id = poolid; 1589 pool->pool_id = pool_id;
1719 tmem_new_pool(pool, flags); 1590 tmem_new_pool(pool, flags);
1720 pr_info("zcache: created %s tmem pool, id=%d, client=%d\n", 1591 cli->tmem_pools[pool_id] = pool;
1721 flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", 1592 pr_info("%s: AUTOcreated %s tmem poolid=%d, for remote client=%d\n",
1722 poolid, cli_id); 1593 namestr, flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
1594 pool_id, cli_id);
1595 ret = 0;
1723out: 1596out:
1724 if (cli != NULL) 1597 if (cli != NULL)
1725 atomic_dec(&cli->refcount); 1598 atomic_dec(&cli->refcount);
1726 return poolid; 1599 return ret;
1727} 1600}
1728 1601
1729/********** 1602/**********
@@ -1734,7 +1607,6 @@ out:
1734 * to translate in-kernel semantics to zcache semantics. 1607 * to translate in-kernel semantics to zcache semantics.
1735 */ 1608 */
1736 1609
1737#ifdef CONFIG_CLEANCACHE
1738static void zcache_cleancache_put_page(int pool_id, 1610static void zcache_cleancache_put_page(int pool_id,
1739 struct cleancache_filekey key, 1611 struct cleancache_filekey key,
1740 pgoff_t index, struct page *page) 1612 pgoff_t index, struct page *page)
@@ -1742,8 +1614,13 @@ static void zcache_cleancache_put_page(int pool_id,
1742 u32 ind = (u32) index; 1614 u32 ind = (u32) index;
1743 struct tmem_oid oid = *(struct tmem_oid *)&key; 1615 struct tmem_oid oid = *(struct tmem_oid *)&key;
1744 1616
1617 if (!disable_cleancache_ignore_nonactive && !PageWasActive(page)) {
1618 zcache_eph_nonactive_puts_ignored++;
1619 return;
1620 }
1745 if (likely(ind == index)) 1621 if (likely(ind == index))
1746 (void)zcache_put_page(LOCAL_CLIENT, pool_id, &oid, index, page); 1622 (void)zcache_put_page(LOCAL_CLIENT, pool_id, &oid, index,
1623 page, PAGE_SIZE, false, 1);
1747} 1624}
1748 1625
1749static int zcache_cleancache_get_page(int pool_id, 1626static int zcache_cleancache_get_page(int pool_id,
@@ -1752,10 +1629,16 @@ static int zcache_cleancache_get_page(int pool_id,
1752{ 1629{
1753 u32 ind = (u32) index; 1630 u32 ind = (u32) index;
1754 struct tmem_oid oid = *(struct tmem_oid *)&key; 1631 struct tmem_oid oid = *(struct tmem_oid *)&key;
1632 size_t size;
1755 int ret = -1; 1633 int ret = -1;
1756 1634
1757 if (likely(ind == index)) 1635 if (likely(ind == index)) {
1758 ret = zcache_get_page(LOCAL_CLIENT, pool_id, &oid, index, page); 1636 ret = zcache_get_page(LOCAL_CLIENT, pool_id, &oid, index,
1637 page, &size, false, 0);
1638 BUG_ON(ret >= 0 && size != PAGE_SIZE);
1639 if (ret == 0)
1640 SetPageWasActive(page);
1641 }
1759 return ret; 1642 return ret;
1760} 1643}
1761 1644
@@ -1781,7 +1664,7 @@ static void zcache_cleancache_flush_inode(int pool_id,
1781static void zcache_cleancache_flush_fs(int pool_id) 1664static void zcache_cleancache_flush_fs(int pool_id)
1782{ 1665{
1783 if (pool_id >= 0) 1666 if (pool_id >= 0)
1784 (void)zcache_destroy_pool(LOCAL_CLIENT, pool_id); 1667 (void)zcache_client_destroy_pool(LOCAL_CLIENT, pool_id);
1785} 1668}
1786 1669
1787static int zcache_cleancache_init_fs(size_t pagesize) 1670static int zcache_cleancache_init_fs(size_t pagesize)
@@ -1789,7 +1672,7 @@ static int zcache_cleancache_init_fs(size_t pagesize)
1789 BUG_ON(sizeof(struct cleancache_filekey) != 1672 BUG_ON(sizeof(struct cleancache_filekey) !=
1790 sizeof(struct tmem_oid)); 1673 sizeof(struct tmem_oid));
1791 BUG_ON(pagesize != PAGE_SIZE); 1674 BUG_ON(pagesize != PAGE_SIZE);
1792 return zcache_new_pool(LOCAL_CLIENT, 0); 1675 return zcache_local_new_pool(0);
1793} 1676}
1794 1677
1795static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize) 1678static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize)
@@ -1798,7 +1681,7 @@ static int zcache_cleancache_init_shared_fs(char *uuid, size_t pagesize)
1798 BUG_ON(sizeof(struct cleancache_filekey) != 1681 BUG_ON(sizeof(struct cleancache_filekey) !=
1799 sizeof(struct tmem_oid)); 1682 sizeof(struct tmem_oid));
1800 BUG_ON(pagesize != PAGE_SIZE); 1683 BUG_ON(pagesize != PAGE_SIZE);
1801 return zcache_new_pool(LOCAL_CLIENT, 0); 1684 return zcache_local_new_pool(0);
1802} 1685}
1803 1686
1804static struct cleancache_ops zcache_cleancache_ops = { 1687static struct cleancache_ops zcache_cleancache_ops = {
@@ -1818,17 +1701,15 @@ struct cleancache_ops zcache_cleancache_register_ops(void)
1818 1701
1819 return old_ops; 1702 return old_ops;
1820} 1703}
1821#endif
1822 1704
1823#ifdef CONFIG_FRONTSWAP
1824/* a single tmem poolid is used for all frontswap "types" (swapfiles) */ 1705/* a single tmem poolid is used for all frontswap "types" (swapfiles) */
1825static int zcache_frontswap_poolid = -1; 1706static int zcache_frontswap_poolid __read_mostly = -1;
1826 1707
1827/* 1708/*
1828 * Swizzling increases objects per swaptype, increasing tmem concurrency 1709 * Swizzling increases objects per swaptype, increasing tmem concurrency
1829 * for heavy swaploads. Later, larger nr_cpus -> larger SWIZ_BITS 1710 * for heavy swaploads. Later, larger nr_cpus -> larger SWIZ_BITS
1830 * Setting SWIZ_BITS to 27 basically reconstructs the swap entry from 1711 * Setting SWIZ_BITS to 27 basically reconstructs the swap entry from
1831 * frontswap_load(), but has side-effects. Hence using 8. 1712 * frontswap_get_page(), but has side-effects. Hence using 8.
1832 */ 1713 */
1833#define SWIZ_BITS 8 1714#define SWIZ_BITS 8
1834#define SWIZ_MASK ((1 << SWIZ_BITS) - 1) 1715#define SWIZ_MASK ((1 << SWIZ_BITS) - 1)
@@ -1842,8 +1723,18 @@ static inline struct tmem_oid oswiz(unsigned type, u32 ind)
1842 return oid; 1723 return oid;
1843} 1724}
1844 1725
1845static int zcache_frontswap_store(unsigned type, pgoff_t offset, 1726#ifdef CONFIG_ZCACHE_WRITEBACK
1846 struct page *page) 1727static void unswiz(struct tmem_oid oid, u32 index,
1728 unsigned *type, pgoff_t *offset)
1729{
1730 *type = (unsigned)(oid.oid[0] >> SWIZ_BITS);
1731 *offset = (pgoff_t)((index << SWIZ_BITS) |
1732 (oid.oid[0] & SWIZ_MASK));
1733}
1734#endif
1735
1736static int zcache_frontswap_put_page(unsigned type, pgoff_t offset,
1737 struct page *page)
1847{ 1738{
1848 u64 ind64 = (u64)offset; 1739 u64 ind64 = (u64)offset;
1849 u32 ind = (u32)offset; 1740 u32 ind = (u32)offset;
@@ -1852,29 +1743,44 @@ static int zcache_frontswap_store(unsigned type, pgoff_t offset,
1852 unsigned long flags; 1743 unsigned long flags;
1853 1744
1854 BUG_ON(!PageLocked(page)); 1745 BUG_ON(!PageLocked(page));
1746 if (!disable_frontswap_ignore_nonactive && !PageWasActive(page)) {
1747 zcache_pers_nonactive_puts_ignored++;
1748 ret = -ERANGE;
1749 goto out;
1750 }
1855 if (likely(ind64 == ind)) { 1751 if (likely(ind64 == ind)) {
1856 local_irq_save(flags); 1752 local_irq_save(flags);
1857 ret = zcache_put_page(LOCAL_CLIENT, zcache_frontswap_poolid, 1753 ret = zcache_put_page(LOCAL_CLIENT, zcache_frontswap_poolid,
1858 &oid, iswiz(ind), page); 1754 &oid, iswiz(ind),
1755 page, PAGE_SIZE, false, 0);
1859 local_irq_restore(flags); 1756 local_irq_restore(flags);
1860 } 1757 }
1758out:
1861 return ret; 1759 return ret;
1862} 1760}
1863 1761
1864/* returns 0 if the page was successfully gotten from frontswap, -1 if 1762/* returns 0 if the page was successfully gotten from frontswap, -1 if
1865 * was not present (should never happen!) */ 1763 * was not present (should never happen!) */
1866static int zcache_frontswap_load(unsigned type, pgoff_t offset, 1764static int zcache_frontswap_get_page(unsigned type, pgoff_t offset,
1867 struct page *page) 1765 struct page *page)
1868{ 1766{
1869 u64 ind64 = (u64)offset; 1767 u64 ind64 = (u64)offset;
1870 u32 ind = (u32)offset; 1768 u32 ind = (u32)offset;
1871 struct tmem_oid oid = oswiz(type, ind); 1769 struct tmem_oid oid = oswiz(type, ind);
1872 int ret = -1; 1770 size_t size;
1771 int ret = -1, get_and_free;
1873 1772
1773 if (frontswap_has_exclusive_gets)
1774 get_and_free = 1;
1775 else
1776 get_and_free = -1;
1874 BUG_ON(!PageLocked(page)); 1777 BUG_ON(!PageLocked(page));
1875 if (likely(ind64 == ind)) 1778 if (likely(ind64 == ind)) {
1876 ret = zcache_get_page(LOCAL_CLIENT, zcache_frontswap_poolid, 1779 ret = zcache_get_page(LOCAL_CLIENT, zcache_frontswap_poolid,
1877 &oid, iswiz(ind), page); 1780 &oid, iswiz(ind),
1781 page, &size, false, get_and_free);
1782 BUG_ON(ret >= 0 && size != PAGE_SIZE);
1783 }
1878 return ret; 1784 return ret;
1879} 1785}
1880 1786
@@ -1908,12 +1814,12 @@ static void zcache_frontswap_init(unsigned ignored)
1908 /* a single tmem poolid is used for all frontswap "types" (swapfiles) */ 1814 /* a single tmem poolid is used for all frontswap "types" (swapfiles) */
1909 if (zcache_frontswap_poolid < 0) 1815 if (zcache_frontswap_poolid < 0)
1910 zcache_frontswap_poolid = 1816 zcache_frontswap_poolid =
1911 zcache_new_pool(LOCAL_CLIENT, TMEM_POOL_PERSIST); 1817 zcache_local_new_pool(TMEM_POOL_PERSIST);
1912} 1818}
1913 1819
1914static struct frontswap_ops zcache_frontswap_ops = { 1820static struct frontswap_ops zcache_frontswap_ops = {
1915 .store = zcache_frontswap_store, 1821 .store = zcache_frontswap_put_page,
1916 .load = zcache_frontswap_load, 1822 .load = zcache_frontswap_get_page,
1917 .invalidate_page = zcache_frontswap_flush_page, 1823 .invalidate_page = zcache_frontswap_flush_page,
1918 .invalidate_area = zcache_frontswap_flush_area, 1824 .invalidate_area = zcache_frontswap_flush_area,
1919 .init = zcache_frontswap_init 1825 .init = zcache_frontswap_init
@@ -1926,16 +1832,13 @@ struct frontswap_ops zcache_frontswap_register_ops(void)
1926 1832
1927 return old_ops; 1833 return old_ops;
1928} 1834}
1929#endif
1930 1835
1931/* 1836/*
1932 * zcache initialization 1837 * zcache initialization
1933 * NOTE FOR NOW zcache MUST BE PROVIDED AS A KERNEL BOOT PARAMETER OR 1838 * NOTE FOR NOW zcache or ramster MUST BE PROVIDED AS A KERNEL BOOT PARAMETER
1934 * NOTHING HAPPENS! 1839 * OR NOTHING HAPPENS!
1935 */ 1840 */
1936 1841
1937static int zcache_enabled;
1938
1939static int __init enable_zcache(char *s) 1842static int __init enable_zcache(char *s)
1940{ 1843{
1941 zcache_enabled = 1; 1844 zcache_enabled = 1;
@@ -1943,28 +1846,58 @@ static int __init enable_zcache(char *s)
1943} 1846}
1944__setup("zcache", enable_zcache); 1847__setup("zcache", enable_zcache);
1945 1848
1946/* allow independent dynamic disabling of cleancache and frontswap */ 1849static int __init enable_ramster(char *s)
1850{
1851 zcache_enabled = 1;
1852#ifdef CONFIG_RAMSTER
1853 ramster_enabled = 1;
1854#endif
1855 return 1;
1856}
1857__setup("ramster", enable_ramster);
1947 1858
1948static int use_cleancache = 1; 1859/* allow independent dynamic disabling of cleancache and frontswap */
1949 1860
1950static int __init no_cleancache(char *s) 1861static int __init no_cleancache(char *s)
1951{ 1862{
1952 use_cleancache = 0; 1863 disable_cleancache = 1;
1953 return 1; 1864 return 1;
1954} 1865}
1955 1866
1956__setup("nocleancache", no_cleancache); 1867__setup("nocleancache", no_cleancache);
1957 1868
1958static int use_frontswap = 1;
1959
1960static int __init no_frontswap(char *s) 1869static int __init no_frontswap(char *s)
1961{ 1870{
1962 use_frontswap = 0; 1871 disable_frontswap = 1;
1963 return 1; 1872 return 1;
1964} 1873}
1965 1874
1966__setup("nofrontswap", no_frontswap); 1875__setup("nofrontswap", no_frontswap);
1967 1876
1877static int __init no_frontswap_exclusive_gets(char *s)
1878{
1879 frontswap_has_exclusive_gets = false;
1880 return 1;
1881}
1882
1883__setup("nofrontswapexclusivegets", no_frontswap_exclusive_gets);
1884
1885static int __init no_frontswap_ignore_nonactive(char *s)
1886{
1887 disable_frontswap_ignore_nonactive = 1;
1888 return 1;
1889}
1890
1891__setup("nofrontswapignorenonactive", no_frontswap_ignore_nonactive);
1892
1893static int __init no_cleancache_ignore_nonactive(char *s)
1894{
1895 disable_cleancache_ignore_nonactive = 1;
1896 return 1;
1897}
1898
1899__setup("nocleancacheignorenonactive", no_cleancache_ignore_nonactive);
1900
1968static int __init enable_zcache_compressor(char *s) 1901static int __init enable_zcache_compressor(char *s)
1969{ 1902{
1970 strncpy(zcache_comp_name, s, ZCACHE_COMP_NAME_SZ); 1903 strncpy(zcache_comp_name, s, ZCACHE_COMP_NAME_SZ);
@@ -2007,14 +1940,13 @@ static int __init zcache_init(void)
2007{ 1940{
2008 int ret = 0; 1941 int ret = 0;
2009 1942
2010#ifdef CONFIG_SYSFS 1943 if (ramster_enabled) {
2011 ret = sysfs_create_group(mm_kobj, &zcache_attr_group); 1944 namestr = "ramster";
2012 if (ret) { 1945 ramster_register_pamops(&zcache_pamops);
2013 pr_err("zcache: can't create sysfs\n");
2014 goto out;
2015 } 1946 }
2016#endif /* CONFIG_SYSFS */ 1947#ifdef CONFIG_DEBUG_FS
2017 1948 zcache_debugfs_init();
1949#endif
2018 if (zcache_enabled) { 1950 if (zcache_enabled) {
2019 unsigned int cpu; 1951 unsigned int cpu;
2020 1952
@@ -2022,12 +1954,13 @@ static int __init zcache_init(void)
2022 tmem_register_pamops(&zcache_pamops); 1954 tmem_register_pamops(&zcache_pamops);
2023 ret = register_cpu_notifier(&zcache_cpu_notifier_block); 1955 ret = register_cpu_notifier(&zcache_cpu_notifier_block);
2024 if (ret) { 1956 if (ret) {
2025 pr_err("zcache: can't register cpu notifier\n"); 1957 pr_err("%s: can't register cpu notifier\n", namestr);
2026 goto out; 1958 goto out;
2027 } 1959 }
2028 ret = zcache_comp_init(); 1960 ret = zcache_comp_init();
2029 if (ret) { 1961 if (ret) {
2030 pr_err("zcache: compressor initialization failed\n"); 1962 pr_err("%s: compressor initialization failed\n",
1963 namestr);
2031 goto out; 1964 goto out;
2032 } 1965 }
2033 for_each_online_cpu(cpu) { 1966 for_each_online_cpu(cpu) {
@@ -2042,36 +1975,45 @@ static int __init zcache_init(void)
2042 sizeof(struct tmem_obj), 0, 0, NULL); 1975 sizeof(struct tmem_obj), 0, 0, NULL);
2043 ret = zcache_new_client(LOCAL_CLIENT); 1976 ret = zcache_new_client(LOCAL_CLIENT);
2044 if (ret) { 1977 if (ret) {
2045 pr_err("zcache: can't create client\n"); 1978 pr_err("%s: can't create client\n", namestr);
2046 goto out; 1979 goto out;
2047 } 1980 }
2048 1981 zbud_init();
2049#ifdef CONFIG_CLEANCACHE 1982 if (zcache_enabled && !disable_cleancache) {
2050 if (zcache_enabled && use_cleancache) {
2051 struct cleancache_ops old_ops; 1983 struct cleancache_ops old_ops;
2052 1984
2053 zbud_init();
2054 register_shrinker(&zcache_shrinker); 1985 register_shrinker(&zcache_shrinker);
2055 old_ops = zcache_cleancache_register_ops(); 1986 old_ops = zcache_cleancache_register_ops();
2056 pr_info("zcache: cleancache enabled using kernel " 1987 pr_info("%s: cleancache enabled using kernel transcendent "
2057 "transcendent memory and compression buddies\n"); 1988 "memory and compression buddies\n", namestr);
1989#ifdef ZCACHE_DEBUG
1990 pr_info("%s: cleancache: ignorenonactive = %d\n",
1991 namestr, !disable_cleancache_ignore_nonactive);
1992#endif
2058 if (old_ops.init_fs != NULL) 1993 if (old_ops.init_fs != NULL)
2059 pr_warning("zcache: cleancache_ops overridden"); 1994 pr_warn("%s: cleancache_ops overridden\n", namestr);
2060 } 1995 }
2061#endif 1996 if (zcache_enabled && !disable_frontswap) {
2062#ifdef CONFIG_FRONTSWAP
2063 if (zcache_enabled && use_frontswap) {
2064 struct frontswap_ops old_ops; 1997 struct frontswap_ops old_ops;
2065 1998
2066 old_ops = zcache_frontswap_register_ops(); 1999 old_ops = zcache_frontswap_register_ops();
2067 pr_info("zcache: frontswap enabled using kernel " 2000 if (frontswap_has_exclusive_gets)
2068 "transcendent memory and zsmalloc\n"); 2001 frontswap_tmem_exclusive_gets(true);
2002 pr_info("%s: frontswap enabled using kernel transcendent "
2003 "memory and compression buddies\n", namestr);
2004#ifdef ZCACHE_DEBUG
2005 pr_info("%s: frontswap: excl gets = %d active only = %d\n",
2006 namestr, frontswap_has_exclusive_gets,
2007 !disable_frontswap_ignore_nonactive);
2008#endif
2069 if (old_ops.init != NULL) 2009 if (old_ops.init != NULL)
2070 pr_warning("zcache: frontswap_ops overridden"); 2010 pr_warn("%s: frontswap_ops overridden\n", namestr);
2071 } 2011 }
2072#endif 2012 if (ramster_enabled)
2013 ramster_init(!disable_cleancache, !disable_frontswap,
2014 frontswap_has_exclusive_gets);
2073out: 2015out:
2074 return ret; 2016 return ret;
2075} 2017}
2076 2018
2077module_init(zcache_init) 2019late_initcall(zcache_init);
diff --git a/drivers/staging/ramster/zcache.h b/drivers/staging/zcache/zcache.h
index 81722b33b087..81722b33b087 100644
--- a/drivers/staging/ramster/zcache.h
+++ b/drivers/staging/zcache/zcache.h
diff --git a/drivers/staging/zram/Kconfig b/drivers/staging/zram/Kconfig
index be5abe8e7943..983314c41349 100644
--- a/drivers/staging/zram/Kconfig
+++ b/drivers/staging/zram/Kconfig
@@ -14,7 +14,7 @@ config ZRAM
14 disks and maybe many more. 14 disks and maybe many more.
15 15
16 See zram.txt for more information. 16 See zram.txt for more information.
17 Project home: http://compcache.googlecode.com/ 17 Project home: <https://compcache.googlecode.com/>
18 18
19config ZRAM_DEBUG 19config ZRAM_DEBUG
20 bool "Compressed RAM block device debug support" 20 bool "Compressed RAM block device debug support"
diff --git a/drivers/staging/zram/zram.txt b/drivers/staging/zram/zram.txt
index 5f75d2987564..765d790ae831 100644
--- a/drivers/staging/zram/zram.txt
+++ b/drivers/staging/zram/zram.txt
@@ -23,17 +23,17 @@ Following shows a typical sequence of steps for using zram.
23 This creates 4 devices: /dev/zram{0,1,2,3} 23 This creates 4 devices: /dev/zram{0,1,2,3}
24 (num_devices parameter is optional. Default: 1) 24 (num_devices parameter is optional. Default: 1)
25 25
262) Set Disksize (Optional): 262) Set Disksize
27 Set disk size by writing the value to sysfs node 'disksize' 27 Set disk size by writing the value to sysfs node 'disksize'.
28 (in bytes). If disksize is not given, default value of 25% 28 The value can be either in bytes or you can use mem suffixes.
29 of RAM is used. 29 Examples:
30 30 # Initialize /dev/zram0 with 50MB disksize
31 # Initialize /dev/zram0 with 50MB disksize 31 echo $((50*1024*1024)) > /sys/block/zram0/disksize
32 echo $((50*1024*1024)) > /sys/block/zram0/disksize 32
33 33 # Using mem suffixes
34 NOTE: disksize cannot be changed if the disk contains any 34 echo 256K > /sys/block/zram0/disksize
35 data. So, for such a disk, you need to issue 'reset' (see below) 35 echo 512M > /sys/block/zram0/disksize
36 before you can change its disksize. 36 echo 1G > /sys/block/zram0/disksize
37 37
383) Activate: 383) Activate:
39 mkswap /dev/zram0 39 mkswap /dev/zram0
@@ -65,8 +65,9 @@ Following shows a typical sequence of steps for using zram.
65 echo 1 > /sys/block/zram0/reset 65 echo 1 > /sys/block/zram0/reset
66 echo 1 > /sys/block/zram1/reset 66 echo 1 > /sys/block/zram1/reset
67 67
68 (This frees all the memory allocated for the given device). 68 This frees all the memory allocated for the given device and
69 69 resets the disksize to zero. You must set the disksize again
70 before reusing the device.
70 71
71Please report any problems at: 72Please report any problems at:
72 - Mailing list: linux-mm-cc at laptop dot org 73 - Mailing list: linux-mm-cc at laptop dot org
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index f2a73bd739fb..5918fd7d7e36 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -40,17 +40,7 @@ static int zram_major;
40struct zram *zram_devices; 40struct zram *zram_devices;
41 41
42/* Module params (documentation at end) */ 42/* Module params (documentation at end) */
43static unsigned int num_devices; 43static unsigned int num_devices = 1;
44
45static void zram_stat_inc(u32 *v)
46{
47 *v = *v + 1;
48}
49
50static void zram_stat_dec(u32 *v)
51{
52 *v = *v - 1;
53}
54 44
55static void zram_stat64_add(struct zram *zram, u64 *v, u64 inc) 45static void zram_stat64_add(struct zram *zram, u64 *v, u64 inc)
56{ 46{
@@ -71,22 +61,22 @@ static void zram_stat64_inc(struct zram *zram, u64 *v)
71 zram_stat64_add(zram, v, 1); 61 zram_stat64_add(zram, v, 1);
72} 62}
73 63
74static int zram_test_flag(struct zram *zram, u32 index, 64static int zram_test_flag(struct zram_meta *meta, u32 index,
75 enum zram_pageflags flag) 65 enum zram_pageflags flag)
76{ 66{
77 return zram->table[index].flags & BIT(flag); 67 return meta->table[index].flags & BIT(flag);
78} 68}
79 69
80static void zram_set_flag(struct zram *zram, u32 index, 70static void zram_set_flag(struct zram_meta *meta, u32 index,
81 enum zram_pageflags flag) 71 enum zram_pageflags flag)
82{ 72{
83 zram->table[index].flags |= BIT(flag); 73 meta->table[index].flags |= BIT(flag);
84} 74}
85 75
86static void zram_clear_flag(struct zram *zram, u32 index, 76static void zram_clear_flag(struct zram_meta *meta, u32 index,
87 enum zram_pageflags flag) 77 enum zram_pageflags flag)
88{ 78{
89 zram->table[index].flags &= ~BIT(flag); 79 meta->table[index].flags &= ~BIT(flag);
90} 80}
91 81
92static int page_zero_filled(void *ptr) 82static int page_zero_filled(void *ptr)
@@ -104,66 +94,38 @@ static int page_zero_filled(void *ptr)
104 return 1; 94 return 1;
105} 95}
106 96
107static void zram_set_disksize(struct zram *zram, size_t totalram_bytes)
108{
109 if (!zram->disksize) {
110 pr_info(
111 "disk size not provided. You can use disksize_kb module "
112 "param to specify size.\nUsing default: (%u%% of RAM).\n",
113 default_disksize_perc_ram
114 );
115 zram->disksize = default_disksize_perc_ram *
116 (totalram_bytes / 100);
117 }
118
119 if (zram->disksize > 2 * (totalram_bytes)) {
120 pr_info(
121 "There is little point creating a zram of greater than "
122 "twice the size of memory since we expect a 2:1 compression "
123 "ratio. Note that zram uses about 0.1%% of the size of "
124 "the disk when not in use so a huge zram is "
125 "wasteful.\n"
126 "\tMemory Size: %zu kB\n"
127 "\tSize you selected: %llu kB\n"
128 "Continuing anyway ...\n",
129 totalram_bytes >> 10, zram->disksize
130 );
131 }
132
133 zram->disksize &= PAGE_MASK;
134}
135
136static void zram_free_page(struct zram *zram, size_t index) 97static void zram_free_page(struct zram *zram, size_t index)
137{ 98{
138 unsigned long handle = zram->table[index].handle; 99 struct zram_meta *meta = zram->meta;
139 u16 size = zram->table[index].size; 100 unsigned long handle = meta->table[index].handle;
101 u16 size = meta->table[index].size;
140 102
141 if (unlikely(!handle)) { 103 if (unlikely(!handle)) {
142 /* 104 /*
143 * No memory is allocated for zero filled pages. 105 * No memory is allocated for zero filled pages.
144 * Simply clear zero page flag. 106 * Simply clear zero page flag.
145 */ 107 */
146 if (zram_test_flag(zram, index, ZRAM_ZERO)) { 108 if (zram_test_flag(meta, index, ZRAM_ZERO)) {
147 zram_clear_flag(zram, index, ZRAM_ZERO); 109 zram_clear_flag(meta, index, ZRAM_ZERO);
148 zram_stat_dec(&zram->stats.pages_zero); 110 zram->stats.pages_zero--;
149 } 111 }
150 return; 112 return;
151 } 113 }
152 114
153 if (unlikely(size > max_zpage_size)) 115 if (unlikely(size > max_zpage_size))
154 zram_stat_dec(&zram->stats.bad_compress); 116 zram->stats.bad_compress--;
155 117
156 zs_free(zram->mem_pool, handle); 118 zs_free(meta->mem_pool, handle);
157 119
158 if (size <= PAGE_SIZE / 2) 120 if (size <= PAGE_SIZE / 2)
159 zram_stat_dec(&zram->stats.good_compress); 121 zram->stats.good_compress--;
160 122
161 zram_stat64_sub(zram, &zram->stats.compr_size, 123 zram_stat64_sub(zram, &zram->stats.compr_size,
162 zram->table[index].size); 124 meta->table[index].size);
163 zram_stat_dec(&zram->stats.pages_stored); 125 zram->stats.pages_stored--;
164 126
165 zram->table[index].handle = 0; 127 meta->table[index].handle = 0;
166 zram->table[index].size = 0; 128 meta->table[index].size = 0;
167} 129}
168 130
169static void handle_zero_page(struct bio_vec *bvec) 131static void handle_zero_page(struct bio_vec *bvec)
@@ -188,20 +150,21 @@ static int zram_decompress_page(struct zram *zram, char *mem, u32 index)
188 int ret = LZO_E_OK; 150 int ret = LZO_E_OK;
189 size_t clen = PAGE_SIZE; 151 size_t clen = PAGE_SIZE;
190 unsigned char *cmem; 152 unsigned char *cmem;
191 unsigned long handle = zram->table[index].handle; 153 struct zram_meta *meta = zram->meta;
154 unsigned long handle = meta->table[index].handle;
192 155
193 if (!handle || zram_test_flag(zram, index, ZRAM_ZERO)) { 156 if (!handle || zram_test_flag(meta, index, ZRAM_ZERO)) {
194 memset(mem, 0, PAGE_SIZE); 157 memset(mem, 0, PAGE_SIZE);
195 return 0; 158 return 0;
196 } 159 }
197 160
198 cmem = zs_map_object(zram->mem_pool, handle, ZS_MM_RO); 161 cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_RO);
199 if (zram->table[index].size == PAGE_SIZE) 162 if (meta->table[index].size == PAGE_SIZE)
200 memcpy(mem, cmem, PAGE_SIZE); 163 memcpy(mem, cmem, PAGE_SIZE);
201 else 164 else
202 ret = lzo1x_decompress_safe(cmem, zram->table[index].size, 165 ret = lzo1x_decompress_safe(cmem, meta->table[index].size,
203 mem, &clen); 166 mem, &clen);
204 zs_unmap_object(zram->mem_pool, handle); 167 zs_unmap_object(meta->mem_pool, handle);
205 168
206 /* Should NEVER happen. Return bio error if it does. */ 169 /* Should NEVER happen. Return bio error if it does. */
207 if (unlikely(ret != LZO_E_OK)) { 170 if (unlikely(ret != LZO_E_OK)) {
@@ -219,20 +182,21 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
219 int ret; 182 int ret;
220 struct page *page; 183 struct page *page;
221 unsigned char *user_mem, *uncmem = NULL; 184 unsigned char *user_mem, *uncmem = NULL;
222 185 struct zram_meta *meta = zram->meta;
223 page = bvec->bv_page; 186 page = bvec->bv_page;
224 187
225 if (unlikely(!zram->table[index].handle) || 188 if (unlikely(!meta->table[index].handle) ||
226 zram_test_flag(zram, index, ZRAM_ZERO)) { 189 zram_test_flag(meta, index, ZRAM_ZERO)) {
227 handle_zero_page(bvec); 190 handle_zero_page(bvec);
228 return 0; 191 return 0;
229 } 192 }
230 193
231 user_mem = kmap_atomic(page);
232 if (is_partial_io(bvec)) 194 if (is_partial_io(bvec))
233 /* Use a temporary buffer to decompress the page */ 195 /* Use a temporary buffer to decompress the page */
234 uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL); 196 uncmem = kmalloc(PAGE_SIZE, GFP_NOIO);
235 else 197
198 user_mem = kmap_atomic(page);
199 if (!is_partial_io(bvec))
236 uncmem = user_mem; 200 uncmem = user_mem;
237 201
238 if (!uncmem) { 202 if (!uncmem) {
@@ -270,18 +234,18 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
270 unsigned long handle; 234 unsigned long handle;
271 struct page *page; 235 struct page *page;
272 unsigned char *user_mem, *cmem, *src, *uncmem = NULL; 236 unsigned char *user_mem, *cmem, *src, *uncmem = NULL;
237 struct zram_meta *meta = zram->meta;
273 238
274 page = bvec->bv_page; 239 page = bvec->bv_page;
275 src = zram->compress_buffer; 240 src = meta->compress_buffer;
276 241
277 if (is_partial_io(bvec)) { 242 if (is_partial_io(bvec)) {
278 /* 243 /*
279 * This is a partial IO. We need to read the full page 244 * This is a partial IO. We need to read the full page
280 * before to write the changes. 245 * before to write the changes.
281 */ 246 */
282 uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL); 247 uncmem = kmalloc(PAGE_SIZE, GFP_NOIO);
283 if (!uncmem) { 248 if (!uncmem) {
284 pr_info("Error allocating temp memory!\n");
285 ret = -ENOMEM; 249 ret = -ENOMEM;
286 goto out; 250 goto out;
287 } 251 }
@@ -294,8 +258,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
294 * System overwrites unused sectors. Free memory associated 258 * System overwrites unused sectors. Free memory associated
295 * with this sector now. 259 * with this sector now.
296 */ 260 */
297 if (zram->table[index].handle || 261 if (meta->table[index].handle ||
298 zram_test_flag(zram, index, ZRAM_ZERO)) 262 zram_test_flag(meta, index, ZRAM_ZERO))
299 zram_free_page(zram, index); 263 zram_free_page(zram, index);
300 264
301 user_mem = kmap_atomic(page); 265 user_mem = kmap_atomic(page);
@@ -310,16 +274,17 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
310 } 274 }
311 275
312 if (page_zero_filled(uncmem)) { 276 if (page_zero_filled(uncmem)) {
313 if (!is_partial_io(bvec)) 277 kunmap_atomic(user_mem);
314 kunmap_atomic(user_mem); 278 if (is_partial_io(bvec))
315 zram_stat_inc(&zram->stats.pages_zero); 279 kfree(uncmem);
316 zram_set_flag(zram, index, ZRAM_ZERO); 280 zram->stats.pages_zero++;
281 zram_set_flag(meta, index, ZRAM_ZERO);
317 ret = 0; 282 ret = 0;
318 goto out; 283 goto out;
319 } 284 }
320 285
321 ret = lzo1x_1_compress(uncmem, PAGE_SIZE, src, &clen, 286 ret = lzo1x_1_compress(uncmem, PAGE_SIZE, src, &clen,
322 zram->compress_workmem); 287 meta->compress_workmem);
323 288
324 if (!is_partial_io(bvec)) { 289 if (!is_partial_io(bvec)) {
325 kunmap_atomic(user_mem); 290 kunmap_atomic(user_mem);
@@ -333,21 +298,21 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
333 } 298 }
334 299
335 if (unlikely(clen > max_zpage_size)) { 300 if (unlikely(clen > max_zpage_size)) {
336 zram_stat_inc(&zram->stats.bad_compress); 301 zram->stats.bad_compress++;
337 clen = PAGE_SIZE; 302 clen = PAGE_SIZE;
338 src = NULL; 303 src = NULL;
339 if (is_partial_io(bvec)) 304 if (is_partial_io(bvec))
340 src = uncmem; 305 src = uncmem;
341 } 306 }
342 307
343 handle = zs_malloc(zram->mem_pool, clen); 308 handle = zs_malloc(meta->mem_pool, clen);
344 if (!handle) { 309 if (!handle) {
345 pr_info("Error allocating memory for compressed " 310 pr_info("Error allocating memory for compressed "
346 "page: %u, size=%zu\n", index, clen); 311 "page: %u, size=%zu\n", index, clen);
347 ret = -ENOMEM; 312 ret = -ENOMEM;
348 goto out; 313 goto out;
349 } 314 }
350 cmem = zs_map_object(zram->mem_pool, handle, ZS_MM_WO); 315 cmem = zs_map_object(meta->mem_pool, handle, ZS_MM_WO);
351 316
352 if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) 317 if ((clen == PAGE_SIZE) && !is_partial_io(bvec))
353 src = kmap_atomic(page); 318 src = kmap_atomic(page);
@@ -355,16 +320,16 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
355 if ((clen == PAGE_SIZE) && !is_partial_io(bvec)) 320 if ((clen == PAGE_SIZE) && !is_partial_io(bvec))
356 kunmap_atomic(src); 321 kunmap_atomic(src);
357 322
358 zs_unmap_object(zram->mem_pool, handle); 323 zs_unmap_object(meta->mem_pool, handle);
359 324
360 zram->table[index].handle = handle; 325 meta->table[index].handle = handle;
361 zram->table[index].size = clen; 326 meta->table[index].size = clen;
362 327
363 /* Update stats */ 328 /* Update stats */
364 zram_stat64_add(zram, &zram->stats.compr_size, clen); 329 zram_stat64_add(zram, &zram->stats.compr_size, clen);
365 zram_stat_inc(&zram->stats.pages_stored); 330 zram->stats.pages_stored++;
366 if (clen <= PAGE_SIZE / 2) 331 if (clen <= PAGE_SIZE / 2)
367 zram_stat_inc(&zram->stats.good_compress); 332 zram->stats.good_compress++;
368 333
369out: 334out:
370 if (is_partial_io(bvec)) 335 if (is_partial_io(bvec))
@@ -479,16 +444,13 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
479{ 444{
480 struct zram *zram = queue->queuedata; 445 struct zram *zram = queue->queuedata;
481 446
482 if (unlikely(!zram->init_done) && zram_init_device(zram))
483 goto error;
484
485 down_read(&zram->init_lock); 447 down_read(&zram->init_lock);
486 if (unlikely(!zram->init_done)) 448 if (unlikely(!zram->init_done))
487 goto error_unlock; 449 goto error;
488 450
489 if (!valid_io_request(zram, bio)) { 451 if (!valid_io_request(zram, bio)) {
490 zram_stat64_inc(zram, &zram->stats.invalid_io); 452 zram_stat64_inc(zram, &zram->stats.invalid_io);
491 goto error_unlock; 453 goto error;
492 } 454 }
493 455
494 __zram_make_request(zram, bio, bio_data_dir(bio)); 456 __zram_make_request(zram, bio, bio_data_dir(bio));
@@ -496,44 +458,38 @@ static void zram_make_request(struct request_queue *queue, struct bio *bio)
496 458
497 return; 459 return;
498 460
499error_unlock:
500 up_read(&zram->init_lock);
501error: 461error:
462 up_read(&zram->init_lock);
502 bio_io_error(bio); 463 bio_io_error(bio);
503} 464}
504 465
505void __zram_reset_device(struct zram *zram) 466static void __zram_reset_device(struct zram *zram)
506{ 467{
507 size_t index; 468 size_t index;
469 struct zram_meta *meta;
508 470
509 zram->init_done = 0; 471 if (!zram->init_done)
510 472 return;
511 /* Free various per-device buffers */
512 kfree(zram->compress_workmem);
513 free_pages((unsigned long)zram->compress_buffer, 1);
514 473
515 zram->compress_workmem = NULL; 474 meta = zram->meta;
516 zram->compress_buffer = NULL; 475 zram->init_done = 0;
517 476
518 /* Free all pages that are still in this zram device */ 477 /* Free all pages that are still in this zram device */
519 for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) { 478 for (index = 0; index < zram->disksize >> PAGE_SHIFT; index++) {
520 unsigned long handle = zram->table[index].handle; 479 unsigned long handle = meta->table[index].handle;
521 if (!handle) 480 if (!handle)
522 continue; 481 continue;
523 482
524 zs_free(zram->mem_pool, handle); 483 zs_free(meta->mem_pool, handle);
525 } 484 }
526 485
527 vfree(zram->table); 486 zram_meta_free(zram->meta);
528 zram->table = NULL; 487 zram->meta = NULL;
529
530 zs_destroy_pool(zram->mem_pool);
531 zram->mem_pool = NULL;
532
533 /* Reset stats */ 488 /* Reset stats */
534 memset(&zram->stats, 0, sizeof(zram->stats)); 489 memset(&zram->stats, 0, sizeof(zram->stats));
535 490
536 zram->disksize = 0; 491 zram->disksize = 0;
492 set_capacity(zram->disk, 0);
537} 493}
538 494
539void zram_reset_device(struct zram *zram) 495void zram_reset_device(struct zram *zram)
@@ -543,69 +499,84 @@ void zram_reset_device(struct zram *zram)
543 up_write(&zram->init_lock); 499 up_write(&zram->init_lock);
544} 500}
545 501
546int zram_init_device(struct zram *zram) 502void zram_meta_free(struct zram_meta *meta)
547{ 503{
548 int ret; 504 zs_destroy_pool(meta->mem_pool);
549 size_t num_pages; 505 kfree(meta->compress_workmem);
550 506 free_pages((unsigned long)meta->compress_buffer, 1);
551 down_write(&zram->init_lock); 507 vfree(meta->table);
552 508 kfree(meta);
553 if (zram->init_done) { 509}
554 up_write(&zram->init_lock);
555 return 0;
556 }
557 510
558 zram_set_disksize(zram, totalram_pages << PAGE_SHIFT); 511struct zram_meta *zram_meta_alloc(u64 disksize)
512{
513 size_t num_pages;
514 struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
515 if (!meta)
516 goto out;
559 517
560 zram->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL); 518 meta->compress_workmem = kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
561 if (!zram->compress_workmem) { 519 if (!meta->compress_workmem)
562 pr_err("Error allocating compressor working memory!\n"); 520 goto free_meta;
563 ret = -ENOMEM;
564 goto fail_no_table;
565 }
566 521
567 zram->compress_buffer = 522 meta->compress_buffer =
568 (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1); 523 (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, 1);
569 if (!zram->compress_buffer) { 524 if (!meta->compress_buffer) {
570 pr_err("Error allocating compressor buffer space\n"); 525 pr_err("Error allocating compressor buffer space\n");
571 ret = -ENOMEM; 526 goto free_workmem;
572 goto fail_no_table;
573 } 527 }
574 528
575 num_pages = zram->disksize >> PAGE_SHIFT; 529 num_pages = disksize >> PAGE_SHIFT;
576 zram->table = vzalloc(num_pages * sizeof(*zram->table)); 530 meta->table = vzalloc(num_pages * sizeof(*meta->table));
577 if (!zram->table) { 531 if (!meta->table) {
578 pr_err("Error allocating zram address table\n"); 532 pr_err("Error allocating zram address table\n");
579 ret = -ENOMEM; 533 goto free_buffer;
580 goto fail_no_table;
581 } 534 }
582 535
583 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); 536 meta->mem_pool = zs_create_pool(GFP_NOIO | __GFP_HIGHMEM);
537 if (!meta->mem_pool) {
538 pr_err("Error creating memory pool\n");
539 goto free_table;
540 }
584 541
585 /* zram devices sort of resembles non-rotational disks */ 542 return meta;
586 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
587 543
588 zram->mem_pool = zs_create_pool("zram", GFP_NOIO | __GFP_HIGHMEM); 544free_table:
589 if (!zram->mem_pool) { 545 vfree(meta->table);
590 pr_err("Error creating memory pool\n"); 546free_buffer:
591 ret = -ENOMEM; 547 free_pages((unsigned long)meta->compress_buffer, 1);
592 goto fail; 548free_workmem:
549 kfree(meta->compress_workmem);
550free_meta:
551 kfree(meta);
552 meta = NULL;
553out:
554 return meta;
555}
556
557void zram_init_device(struct zram *zram, struct zram_meta *meta)
558{
559 if (zram->disksize > 2 * (totalram_pages << PAGE_SHIFT)) {
560 pr_info(
561 "There is little point creating a zram of greater than "
562 "twice the size of memory since we expect a 2:1 compression "
563 "ratio. Note that zram uses about 0.1%% of the size of "
564 "the disk when not in use so a huge zram is "
565 "wasteful.\n"
566 "\tMemory Size: %lu kB\n"
567 "\tSize you selected: %llu kB\n"
568 "Continuing anyway ...\n",
569 (totalram_pages << PAGE_SHIFT) >> 10, zram->disksize >> 10
570 );
593 } 571 }
594 572
573 /* zram devices sort of resembles non-rotational disks */
574 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, zram->disk->queue);
575
576 zram->meta = meta;
595 zram->init_done = 1; 577 zram->init_done = 1;
596 up_write(&zram->init_lock);
597 578
598 pr_debug("Initialization done!\n"); 579 pr_debug("Initialization done!\n");
599 return 0;
600
601fail_no_table:
602 /* To prevent accessing table entries during cleanup */
603 zram->disksize = 0;
604fail:
605 __zram_reset_device(zram);
606 up_write(&zram->init_lock);
607 pr_err("Initialization failed: err=%d\n", ret);
608 return ret;
609} 580}
610 581
611static void zram_slot_free_notify(struct block_device *bdev, 582static void zram_slot_free_notify(struct block_device *bdev,
@@ -724,13 +695,7 @@ static int __init zram_init(void)
724 goto out; 695 goto out;
725 } 696 }
726 697
727 if (!num_devices) {
728 pr_info("num_devices not specified. Using default: 1\n");
729 num_devices = 1;
730 }
731
732 /* Allocate the device array and initialize each one */ 698 /* Allocate the device array and initialize each one */
733 pr_info("Creating %u devices ...\n", num_devices);
734 zram_devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL); 699 zram_devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL);
735 if (!zram_devices) { 700 if (!zram_devices) {
736 ret = -ENOMEM; 701 ret = -ENOMEM;
@@ -743,6 +708,8 @@ static int __init zram_init(void)
743 goto free_devices; 708 goto free_devices;
744 } 709 }
745 710
711 pr_info("Created %u device(s) ...\n", num_devices);
712
746 return 0; 713 return 0;
747 714
748free_devices: 715free_devices:
@@ -764,8 +731,7 @@ static void __exit zram_exit(void)
764 zram = &zram_devices[i]; 731 zram = &zram_devices[i];
765 732
766 destroy_device(zram); 733 destroy_device(zram);
767 if (zram->init_done) 734 zram_reset_device(zram);
768 zram_reset_device(zram);
769 } 735 }
770 736
771 unregister_blkdev(zram_major, "zram"); 737 unregister_blkdev(zram_major, "zram");
diff --git a/drivers/staging/zram/zram_drv.h b/drivers/staging/zram/zram_drv.h
index df2eec407db6..2d1a3f1e8edb 100644
--- a/drivers/staging/zram/zram_drv.h
+++ b/drivers/staging/zram/zram_drv.h
@@ -28,9 +28,6 @@ static const unsigned max_num_devices = 32;
28 28
29/*-- Configurable parameters */ 29/*-- Configurable parameters */
30 30
31/* Default zram disk size: 25% of total RAM */
32static const unsigned default_disksize_perc_ram = 25;
33
34/* 31/*
35 * Pages that compress to size greater than this are stored 32 * Pages that compress to size greater than this are stored
36 * uncompressed in memory. 33 * uncompressed in memory.
@@ -86,11 +83,15 @@ struct zram_stats {
86 u32 bad_compress; /* % of pages with compression ratio>=75% */ 83 u32 bad_compress; /* % of pages with compression ratio>=75% */
87}; 84};
88 85
89struct zram { 86struct zram_meta {
90 struct zs_pool *mem_pool;
91 void *compress_workmem; 87 void *compress_workmem;
92 void *compress_buffer; 88 void *compress_buffer;
93 struct table *table; 89 struct table *table;
90 struct zs_pool *mem_pool;
91};
92
93struct zram {
94 struct zram_meta *meta;
94 spinlock_t stat64_lock; /* protect 64-bit stats */ 95 spinlock_t stat64_lock; /* protect 64-bit stats */
95 struct rw_semaphore lock; /* protect compression buffers and table 96 struct rw_semaphore lock; /* protect compression buffers and table
96 * against concurrent read and writes */ 97 * against concurrent read and writes */
@@ -114,7 +115,9 @@ unsigned int zram_get_num_devices(void);
114extern struct attribute_group zram_disk_attr_group; 115extern struct attribute_group zram_disk_attr_group;
115#endif 116#endif
116 117
117extern int zram_init_device(struct zram *zram); 118extern void zram_reset_device(struct zram *zram);
118extern void __zram_reset_device(struct zram *zram); 119extern struct zram_meta *zram_meta_alloc(u64 disksize);
120extern void zram_meta_free(struct zram_meta *meta);
121extern void zram_init_device(struct zram *zram, struct zram_meta *meta);
119 122
120#endif 123#endif
diff --git a/drivers/staging/zram/zram_sysfs.c b/drivers/staging/zram/zram_sysfs.c
index de1eacf65dbd..e6a929d452f7 100644
--- a/drivers/staging/zram/zram_sysfs.c
+++ b/drivers/staging/zram/zram_sysfs.c
@@ -56,21 +56,26 @@ static ssize_t disksize_store(struct device *dev,
56 struct device_attribute *attr, const char *buf, size_t len) 56 struct device_attribute *attr, const char *buf, size_t len)
57{ 57{
58 u64 disksize; 58 u64 disksize;
59 struct zram_meta *meta;
59 struct zram *zram = dev_to_zram(dev); 60 struct zram *zram = dev_to_zram(dev);
60 61
61 disksize = memparse(buf, NULL); 62 disksize = memparse(buf, NULL);
62 if (!disksize) 63 if (!disksize)
63 return -EINVAL; 64 return -EINVAL;
64 65
66 disksize = PAGE_ALIGN(disksize);
67 meta = zram_meta_alloc(disksize);
65 down_write(&zram->init_lock); 68 down_write(&zram->init_lock);
66 if (zram->init_done) { 69 if (zram->init_done) {
67 up_write(&zram->init_lock); 70 up_write(&zram->init_lock);
71 zram_meta_free(meta);
68 pr_info("Cannot change disksize for initialized device\n"); 72 pr_info("Cannot change disksize for initialized device\n");
69 return -EBUSY; 73 return -EBUSY;
70 } 74 }
71 75
72 zram->disksize = PAGE_ALIGN(disksize); 76 zram->disksize = disksize;
73 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); 77 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
78 zram_init_device(zram, meta);
74 up_write(&zram->init_lock); 79 up_write(&zram->init_lock);
75 80
76 return len; 81 return len;
@@ -110,11 +115,7 @@ static ssize_t reset_store(struct device *dev,
110 if (bdev) 115 if (bdev)
111 fsync_bdev(bdev); 116 fsync_bdev(bdev);
112 117
113 down_write(&zram->init_lock); 118 zram_reset_device(zram);
114 if (zram->init_done)
115 __zram_reset_device(zram);
116 up_write(&zram->init_lock);
117
118 return len; 119 return len;
119} 120}
120 121
@@ -185,9 +186,10 @@ static ssize_t mem_used_total_show(struct device *dev,
185{ 186{
186 u64 val = 0; 187 u64 val = 0;
187 struct zram *zram = dev_to_zram(dev); 188 struct zram *zram = dev_to_zram(dev);
189 struct zram_meta *meta = zram->meta;
188 190
189 if (zram->init_done) 191 if (zram->init_done)
190 val = zs_get_total_size_bytes(zram->mem_pool); 192 val = zs_get_total_size_bytes(meta->mem_pool);
191 193
192 return sprintf(buf, "%llu\n", val); 194 return sprintf(buf, "%llu\n", val);
193} 195}
diff --git a/drivers/staging/zsmalloc/zsmalloc-main.c b/drivers/staging/zsmalloc/zsmalloc-main.c
index 09a9d35d436f..06f73a93a44d 100644
--- a/drivers/staging/zsmalloc/zsmalloc-main.c
+++ b/drivers/staging/zsmalloc/zsmalloc-main.c
@@ -141,7 +141,7 @@
141 * ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN 141 * ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN
142 * (reason above) 142 * (reason above)
143 */ 143 */
144#define ZS_SIZE_CLASS_DELTA 16 144#define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> 8)
145#define ZS_SIZE_CLASSES ((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / \ 145#define ZS_SIZE_CLASSES ((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / \
146 ZS_SIZE_CLASS_DELTA + 1) 146 ZS_SIZE_CLASS_DELTA + 1)
147 147
@@ -207,7 +207,6 @@ struct zs_pool {
207 struct size_class size_class[ZS_SIZE_CLASSES]; 207 struct size_class size_class[ZS_SIZE_CLASSES];
208 208
209 gfp_t flags; /* allocation flags used when growing pool */ 209 gfp_t flags; /* allocation flags used when growing pool */
210 const char *name;
211}; 210};
212 211
213/* 212/*
@@ -222,11 +221,9 @@ struct zs_pool {
222/* 221/*
223 * By default, zsmalloc uses a copy-based object mapping method to access 222 * By default, zsmalloc uses a copy-based object mapping method to access
224 * allocations that span two pages. However, if a particular architecture 223 * allocations that span two pages. However, if a particular architecture
225 * 1) Implements local_flush_tlb_kernel_range() and 2) Performs VM mapping 224 * performs VM mapping faster than copying, then it should be added here
226 * faster than copying, then it should be added here so that 225 * so that USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use
227 * USE_PGTABLE_MAPPING is defined. This causes zsmalloc to use page table 226 * page table mapping rather than copying for object mapping.
228 * mapping rather than copying
229 * for object mapping.
230*/ 227*/
231#if defined(CONFIG_ARM) 228#if defined(CONFIG_ARM)
232#define USE_PGTABLE_MAPPING 229#define USE_PGTABLE_MAPPING
@@ -663,7 +660,7 @@ static inline void __zs_unmap_object(struct mapping_area *area,
663 660
664 flush_cache_vunmap(addr, end); 661 flush_cache_vunmap(addr, end);
665 unmap_kernel_range_noflush(addr, PAGE_SIZE * 2); 662 unmap_kernel_range_noflush(addr, PAGE_SIZE * 2);
666 local_flush_tlb_kernel_range(addr, end); 663 flush_tlb_kernel_range(addr, end);
667} 664}
668 665
669#else /* USE_PGTABLE_MAPPING */ 666#else /* USE_PGTABLE_MAPPING */
@@ -798,14 +795,21 @@ fail:
798 return notifier_to_errno(ret); 795 return notifier_to_errno(ret);
799} 796}
800 797
801struct zs_pool *zs_create_pool(const char *name, gfp_t flags) 798/**
799 * zs_create_pool - Creates an allocation pool to work from.
800 * @flags: allocation flags used to allocate pool metadata
801 *
802 * This function must be called before anything when using
803 * the zsmalloc allocator.
804 *
805 * On success, a pointer to the newly created pool is returned,
806 * otherwise NULL.
807 */
808struct zs_pool *zs_create_pool(gfp_t flags)
802{ 809{
803 int i, ovhd_size; 810 int i, ovhd_size;
804 struct zs_pool *pool; 811 struct zs_pool *pool;
805 812
806 if (!name)
807 return NULL;
808
809 ovhd_size = roundup(sizeof(*pool), PAGE_SIZE); 813 ovhd_size = roundup(sizeof(*pool), PAGE_SIZE);
810 pool = kzalloc(ovhd_size, GFP_KERNEL); 814 pool = kzalloc(ovhd_size, GFP_KERNEL);
811 if (!pool) 815 if (!pool)
@@ -828,7 +832,6 @@ struct zs_pool *zs_create_pool(const char *name, gfp_t flags)
828 } 832 }
829 833
830 pool->flags = flags; 834 pool->flags = flags;
831 pool->name = name;
832 835
833 return pool; 836 return pool;
834} 837}
diff --git a/drivers/staging/zsmalloc/zsmalloc.h b/drivers/staging/zsmalloc/zsmalloc.h
index de2e8bfbcc06..46dbd0558d86 100644
--- a/drivers/staging/zsmalloc/zsmalloc.h
+++ b/drivers/staging/zsmalloc/zsmalloc.h
@@ -28,7 +28,7 @@ enum zs_mapmode {
28 28
29struct zs_pool; 29struct zs_pool;
30 30
31struct zs_pool *zs_create_pool(const char *name, gfp_t flags); 31struct zs_pool *zs_create_pool(gfp_t flags);
32void zs_destroy_pool(struct zs_pool *pool); 32void zs_destroy_pool(struct zs_pool *pool);
33 33
34unsigned long zs_malloc(struct zs_pool *pool, size_t size); 34unsigned long zs_malloc(struct zs_pool *pool, size_t size);
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index 0aa5f4c42ae6..ecefb7311dd6 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -157,4 +157,42 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
157*/ 157*/
158int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, 158int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
159 u32 field_index, s32 *value); 159 u32 field_index, s32 *value);
160
161/* hid-sensor-attributes */
162
163/* Common hid sensor iio structure */
164struct hid_sensor_common {
165 struct hid_sensor_hub_device *hsdev;
166 struct platform_device *pdev;
167 unsigned usage_id;
168 bool data_ready;
169 struct hid_sensor_hub_attribute_info poll;
170 struct hid_sensor_hub_attribute_info report_state;
171 struct hid_sensor_hub_attribute_info power_state;
172 struct hid_sensor_hub_attribute_info sensitivity;
173};
174
175/*Convert from hid unit expo to regular exponent*/
176static inline int hid_sensor_convert_exponent(int unit_expo)
177{
178 if (unit_expo < 0x08)
179 return unit_expo;
180 else if (unit_expo <= 0x0f)
181 return -(0x0f-unit_expo+1);
182 else
183 return 0;
184}
185
186int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
187 u32 usage_id,
188 struct hid_sensor_common *st);
189int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
190 int val1, int val2);
191int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st,
192 int *val1, int *val2);
193int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
194 int val1, int val2);
195int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st,
196 int *val1, int *val2);
197
160#endif 198#endif
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 55f277372fed..6f24446e7669 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -66,6 +66,15 @@
66#define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS 0x200486 66#define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Y_AXIS 0x200486
67#define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS 0x200487 67#define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX_Z_AXIS 0x200487
68 68
69/* Time (2000a0) */
70#define HID_USAGE_SENSOR_TIME 0x2000a0
71#define HID_USAGE_SENSOR_TIME_YEAR 0x200521
72#define HID_USAGE_SENSOR_TIME_MONTH 0x200522
73#define HID_USAGE_SENSOR_TIME_DAY 0x200523
74#define HID_USAGE_SENSOR_TIME_HOUR 0x200525
75#define HID_USAGE_SENSOR_TIME_MINUTE 0x200526
76#define HID_USAGE_SENSOR_TIME_SECOND 0x200527
77
69/* Units */ 78/* Units */
70#define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED 0x00 79#define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED 0x00
71#define HID_USAGE_SENSOR_UNITS_LUX 0x01 80#define HID_USAGE_SENSOR_UNITS_LUX 0x01
diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h
index f3eea18fdf46..2bac0eb8948d 100644
--- a/include/linux/iio/buffer.h
+++ b/include/linux/iio/buffer.h
@@ -103,19 +103,6 @@ int iio_update_buffers(struct iio_dev *indio_dev,
103 **/ 103 **/
104void iio_buffer_init(struct iio_buffer *buffer); 104void iio_buffer_init(struct iio_buffer *buffer);
105 105
106/**
107 * __iio_update_buffer() - update common elements of buffers
108 * @buffer: buffer that is the event source
109 * @bytes_per_datum: size of individual datum including timestamp
110 * @length: number of datums in buffer
111 **/
112static inline void __iio_update_buffer(struct iio_buffer *buffer,
113 int bytes_per_datum, int length)
114{
115 buffer->bytes_per_datum = bytes_per_datum;
116 buffer->length = length;
117}
118
119int iio_scan_mask_query(struct iio_dev *indio_dev, 106int iio_scan_mask_query(struct iio_dev *indio_dev,
120 struct iio_buffer *buffer, int bit); 107 struct iio_buffer *buffer, int bit);
121 108
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
new file mode 100644
index 000000000000..1f86a97ab2e2
--- /dev/null
+++ b/include/linux/iio/common/st_sensors.h
@@ -0,0 +1,280 @@
1/*
2 * STMicroelectronics sensors library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_SENSORS_H
12#define ST_SENSORS_H
13
14#include <linux/i2c.h>
15#include <linux/spi/spi.h>
16#include <linux/irqreturn.h>
17#include <linux/iio/trigger.h>
18
19#define ST_SENSORS_TX_MAX_LENGTH 2
20#define ST_SENSORS_RX_MAX_LENGTH 6
21
22#define ST_SENSORS_ODR_LIST_MAX 10
23#define ST_SENSORS_FULLSCALE_AVL_MAX 10
24
25#define ST_SENSORS_NUMBER_ALL_CHANNELS 4
26#define ST_SENSORS_NUMBER_DATA_CHANNELS 3
27#define ST_SENSORS_ENABLE_ALL_AXIS 0x07
28#define ST_SENSORS_BYTE_FOR_CHANNEL 2
29#define ST_SENSORS_SCAN_X 0
30#define ST_SENSORS_SCAN_Y 1
31#define ST_SENSORS_SCAN_Z 2
32#define ST_SENSORS_DEFAULT_12_REALBITS 12
33#define ST_SENSORS_DEFAULT_16_REALBITS 16
34#define ST_SENSORS_DEFAULT_POWER_ON_VALUE 0x01
35#define ST_SENSORS_DEFAULT_POWER_OFF_VALUE 0x00
36#define ST_SENSORS_DEFAULT_WAI_ADDRESS 0x0f
37#define ST_SENSORS_DEFAULT_AXIS_ADDR 0x20
38#define ST_SENSORS_DEFAULT_AXIS_MASK 0x07
39#define ST_SENSORS_DEFAULT_AXIS_N_BIT 3
40
41#define ST_SENSORS_MAX_NAME 17
42#define ST_SENSORS_MAX_4WAI 7
43
44#define ST_SENSORS_LSM_CHANNELS(device_type, index, mod, endian, bits, addr) \
45{ \
46 .type = device_type, \
47 .modified = 1, \
48 .info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT | \
49 IIO_CHAN_INFO_SCALE_SEPARATE_BIT, \
50 .scan_index = index, \
51 .channel2 = mod, \
52 .address = addr, \
53 .scan_type = { \
54 .sign = 's', \
55 .realbits = bits, \
56 .shift = 16 - bits, \
57 .storagebits = 16, \
58 .endianness = endian, \
59 }, \
60}
61
62#define ST_SENSOR_DEV_ATTR_SAMP_FREQ() \
63 IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, \
64 st_sensors_sysfs_get_sampling_frequency, \
65 st_sensors_sysfs_set_sampling_frequency)
66
67#define ST_SENSORS_DEV_ATTR_SAMP_FREQ_AVAIL() \
68 IIO_DEV_ATTR_SAMP_FREQ_AVAIL( \
69 st_sensors_sysfs_sampling_frequency_avail)
70
71#define ST_SENSORS_DEV_ATTR_SCALE_AVAIL(name) \
72 IIO_DEVICE_ATTR(name, S_IRUGO, \
73 st_sensors_sysfs_scale_avail, NULL , 0);
74
75struct st_sensor_odr_avl {
76 unsigned int hz;
77 u8 value;
78};
79
80struct st_sensor_odr {
81 u8 addr;
82 u8 mask;
83 struct st_sensor_odr_avl odr_avl[ST_SENSORS_ODR_LIST_MAX];
84};
85
86struct st_sensor_power {
87 u8 addr;
88 u8 mask;
89 u8 value_off;
90 u8 value_on;
91};
92
93struct st_sensor_axis {
94 u8 addr;
95 u8 mask;
96};
97
98struct st_sensor_fullscale_avl {
99 unsigned int num;
100 u8 value;
101 unsigned int gain;
102 unsigned int gain2;
103};
104
105struct st_sensor_fullscale {
106 u8 addr;
107 u8 mask;
108 struct st_sensor_fullscale_avl fs_avl[ST_SENSORS_FULLSCALE_AVL_MAX];
109};
110
111/**
112 * struct st_sensor_bdu - ST sensor device block data update
113 * @addr: address of the register.
114 * @mask: mask to write the block data update flag.
115 */
116struct st_sensor_bdu {
117 u8 addr;
118 u8 mask;
119};
120
121/**
122 * struct st_sensor_data_ready_irq - ST sensor device data-ready interrupt
123 * @addr: address of the register.
124 * @mask: mask to write the on/off value.
125 * struct ig1 - represents the Interrupt Generator 1 of sensors.
126 * @en_addr: address of the enable ig1 register.
127 * @en_mask: mask to write the on/off value for enable.
128 */
129struct st_sensor_data_ready_irq {
130 u8 addr;
131 u8 mask;
132 struct {
133 u8 en_addr;
134 u8 en_mask;
135 } ig1;
136};
137
138/**
139 * struct st_sensor_transfer_buffer - ST sensor device I/O buffer
140 * @buf_lock: Mutex to protect rx and tx buffers.
141 * @tx_buf: Buffer used by SPI transfer function to send data to the sensors.
142 * This buffer is used to avoid DMA not-aligned issue.
143 * @rx_buf: Buffer used by SPI transfer to receive data from sensors.
144 * This buffer is used to avoid DMA not-aligned issue.
145 */
146struct st_sensor_transfer_buffer {
147 struct mutex buf_lock;
148 u8 rx_buf[ST_SENSORS_RX_MAX_LENGTH];
149 u8 tx_buf[ST_SENSORS_TX_MAX_LENGTH] ____cacheline_aligned;
150};
151
152/**
153 * struct st_sensor_transfer_function - ST sensor device I/O function
154 * @read_byte: Function used to read one byte.
155 * @write_byte: Function used to write one byte.
156 * @read_multiple_byte: Function used to read multiple byte.
157 */
158struct st_sensor_transfer_function {
159 int (*read_byte) (struct st_sensor_transfer_buffer *tb,
160 struct device *dev, u8 reg_addr, u8 *res_byte);
161 int (*write_byte) (struct st_sensor_transfer_buffer *tb,
162 struct device *dev, u8 reg_addr, u8 data);
163 int (*read_multiple_byte) (struct st_sensor_transfer_buffer *tb,
164 struct device *dev, u8 reg_addr, int len, u8 *data,
165 bool multiread_bit);
166};
167
168/**
169 * struct st_sensors - ST sensors list
170 * @wai: Contents of WhoAmI register.
171 * @sensors_supported: List of supported sensors by struct itself.
172 * @ch: IIO channels for the sensor.
173 * @odr: Output data rate register and ODR list available.
174 * @pw: Power register of the sensor.
175 * @enable_axis: Enable one or more axis of the sensor.
176 * @fs: Full scale register and full scale list available.
177 * @bdu: Block data update register.
178 * @drdy_irq: Data ready register of the sensor.
179 * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
180 * @bootime: samples to discard when sensor passing from power-down to power-up.
181 */
182struct st_sensors {
183 u8 wai;
184 char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
185 struct iio_chan_spec *ch;
186 struct st_sensor_odr odr;
187 struct st_sensor_power pw;
188 struct st_sensor_axis enable_axis;
189 struct st_sensor_fullscale fs;
190 struct st_sensor_bdu bdu;
191 struct st_sensor_data_ready_irq drdy_irq;
192 bool multi_read_bit;
193 unsigned int bootime;
194};
195
196/**
197 * struct st_sensor_data - ST sensor device status
198 * @dev: Pointer to instance of struct device (I2C or SPI).
199 * @trig: The trigger in use by the core driver.
200 * @sensor: Pointer to the current sensor struct in use.
201 * @current_fullscale: Maximum range of measure by the sensor.
202 * @enabled: Status of the sensor (false->off, true->on).
203 * @multiread_bit: Use or not particular bit for [I2C/SPI] multiread.
204 * @buffer_data: Data used by buffer part.
205 * @odr: Output data rate of the sensor [Hz].
206 * @get_irq_data_ready: Function to get the IRQ used for data ready signal.
207 * @tf: Transfer function structure used by I/O operations.
208 * @tb: Transfer buffers and mutex used by I/O operations.
209 */
210struct st_sensor_data {
211 struct device *dev;
212 struct iio_trigger *trig;
213 struct st_sensors *sensor;
214 struct st_sensor_fullscale_avl *current_fullscale;
215
216 bool enabled;
217 bool multiread_bit;
218
219 char *buffer_data;
220
221 unsigned int odr;
222
223 unsigned int (*get_irq_data_ready) (struct iio_dev *indio_dev);
224
225 const struct st_sensor_transfer_function *tf;
226 struct st_sensor_transfer_buffer tb;
227};
228
229#ifdef CONFIG_IIO_BUFFER
230int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
231 const struct iio_trigger_ops *trigger_ops);
232
233void st_sensors_deallocate_trigger(struct iio_dev *indio_dev);
234
235irqreturn_t st_sensors_trigger_handler(int irq, void *p);
236
237int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf);
238#else
239static inline int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
240 const struct iio_trigger_ops *trigger_ops)
241{
242 return 0;
243}
244static inline void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
245{
246 return;
247}
248#endif
249
250int st_sensors_init_sensor(struct iio_dev *indio_dev);
251
252int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable);
253
254int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable);
255
256int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr);
257
258int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable);
259
260int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale);
261
262int st_sensors_read_info_raw(struct iio_dev *indio_dev,
263 struct iio_chan_spec const *ch, int *val);
264
265int st_sensors_check_device_support(struct iio_dev *indio_dev,
266 int num_sensors_list, const struct st_sensors *sensors);
267
268ssize_t st_sensors_sysfs_get_sampling_frequency(struct device *dev,
269 struct device_attribute *attr, char *buf);
270
271ssize_t st_sensors_sysfs_set_sampling_frequency(struct device *dev,
272 struct device_attribute *attr, const char *buf, size_t size);
273
274ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
275 struct device_attribute *attr, char *buf);
276
277ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
278 struct device_attribute *attr, char *buf);
279
280#endif /* ST_SENSORS_H */
diff --git a/include/linux/iio/common/st_sensors_i2c.h b/include/linux/iio/common/st_sensors_i2c.h
new file mode 100644
index 000000000000..67d845385ae2
--- /dev/null
+++ b/include/linux/iio/common/st_sensors_i2c.h
@@ -0,0 +1,20 @@
1/*
2 * STMicroelectronics sensors i2c library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_SENSORS_I2C_H
12#define ST_SENSORS_I2C_H
13
14#include <linux/i2c.h>
15#include <linux/iio/common/st_sensors.h>
16
17void st_sensors_i2c_configure(struct iio_dev *indio_dev,
18 struct i2c_client *client, struct st_sensor_data *sdata);
19
20#endif /* ST_SENSORS_I2C_H */
diff --git a/include/linux/iio/common/st_sensors_spi.h b/include/linux/iio/common/st_sensors_spi.h
new file mode 100644
index 000000000000..d964a3563dc6
--- /dev/null
+++ b/include/linux/iio/common/st_sensors_spi.h
@@ -0,0 +1,20 @@
1/*
2 * STMicroelectronics sensors spi library driver
3 *
4 * Copyright 2012-2013 STMicroelectronics Inc.
5 *
6 * Denis Ciocca <denis.ciocca@st.com>
7 *
8 * Licensed under the GPL-2.
9 */
10
11#ifndef ST_SENSORS_SPI_H
12#define ST_SENSORS_SPI_H
13
14#include <linux/spi/spi.h>
15#include <linux/iio/common/st_sensors.h>
16
17void st_sensors_spi_configure(struct iio_dev *indio_dev,
18 struct spi_device *spi, struct st_sensor_data *sdata);
19
20#endif /* ST_SENSORS_SPI_H */
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
index 16c35ac045bd..833926c91aa8 100644
--- a/include/linux/iio/consumer.h
+++ b/include/linux/iio/consumer.h
@@ -15,6 +15,7 @@
15 15
16struct iio_dev; 16struct iio_dev;
17struct iio_chan_spec; 17struct iio_chan_spec;
18struct device;
18 19
19/** 20/**
20 * struct iio_channel - everything needed for a consumer to use a channel 21 * struct iio_channel - everything needed for a consumer to use a channel
@@ -30,14 +31,15 @@ struct iio_channel {
30 31
31/** 32/**
32 * iio_channel_get() - get description of all that is needed to access channel. 33 * iio_channel_get() - get description of all that is needed to access channel.
33 * @name: Unique name of the device as provided in the iio_map 34 * @dev: Pointer to consumer device. Device name must match
35 * the name of the device as provided in the iio_map
34 * with which the desired provider to consumer mapping 36 * with which the desired provider to consumer mapping
35 * was registered. 37 * was registered.
36 * @consumer_channel: Unique name to identify the channel on the consumer 38 * @consumer_channel: Unique name to identify the channel on the consumer
37 * side. This typically describes the channels use within 39 * side. This typically describes the channels use within
38 * the consumer. E.g. 'battery_voltage' 40 * the consumer. E.g. 'battery_voltage'
39 */ 41 */
40struct iio_channel *iio_channel_get(const char *name, 42struct iio_channel *iio_channel_get(struct device *dev,
41 const char *consumer_channel); 43 const char *consumer_channel);
42 44
43/** 45/**
@@ -48,14 +50,14 @@ void iio_channel_release(struct iio_channel *chan);
48 50
49/** 51/**
50 * iio_channel_get_all() - get all channels associated with a client 52 * iio_channel_get_all() - get all channels associated with a client
51 * @name: name of consumer device. 53 * @dev: Pointer to consumer device.
52 * 54 *
53 * Returns an array of iio_channel structures terminated with one with 55 * Returns an array of iio_channel structures terminated with one with
54 * null iio_dev pointer. 56 * null iio_dev pointer.
55 * This function is used by fairly generic consumers to get all the 57 * This function is used by fairly generic consumers to get all the
56 * channels registered as having this consumer. 58 * channels registered as having this consumer.
57 */ 59 */
58struct iio_channel *iio_channel_get_all(const char *name); 60struct iio_channel *iio_channel_get_all(struct device *dev);
59 61
60/** 62/**
61 * iio_channel_release_all() - reverse iio_channel_get_all 63 * iio_channel_release_all() - reverse iio_channel_get_all
@@ -66,7 +68,7 @@ void iio_channel_release_all(struct iio_channel *chan);
66struct iio_cb_buffer; 68struct iio_cb_buffer;
67/** 69/**
68 * iio_channel_get_all_cb() - register callback for triggered capture 70 * iio_channel_get_all_cb() - register callback for triggered capture
69 * @name: Name of client device. 71 * @dev: Pointer to client device.
70 * @cb: Callback function. 72 * @cb: Callback function.
71 * @private: Private data passed to callback. 73 * @private: Private data passed to callback.
72 * 74 *
@@ -74,7 +76,7 @@ struct iio_cb_buffer;
74 * So if the channels requested come from different devices this will 76 * So if the channels requested come from different devices this will
75 * fail. 77 * fail.
76 */ 78 */
77struct iio_cb_buffer *iio_channel_get_all_cb(const char *name, 79struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
78 int (*cb)(u8 *data, 80 int (*cb)(u8 *data,
79 void *private), 81 void *private),
80 void *private); 82 void *private);
diff --git a/include/linux/iio/driver.h b/include/linux/iio/driver.h
index a4f8b2e05af5..7dfb10ee2669 100644
--- a/include/linux/iio/driver.h
+++ b/include/linux/iio/driver.h
@@ -22,13 +22,10 @@ int iio_map_array_register(struct iio_dev *indio_dev,
22 struct iio_map *map); 22 struct iio_map *map);
23 23
24/** 24/**
25 * iio_map_array_unregister() - tell the core to remove consumer mappings 25 * iio_map_array_unregister() - tell the core to remove consumer mappings for
26 * the given provider device
26 * @indio_dev: provider device 27 * @indio_dev: provider device
27 * @map: array of mappings to remove. Note these must have same memory
28 * addresses as those originally added not just equal parameter
29 * values.
30 */ 28 */
31int iio_map_array_unregister(struct iio_dev *indio_dev, 29int iio_map_array_unregister(struct iio_dev *indio_dev);
32 struct iio_map *map);
33 30
34#endif 31#endif
diff --git a/include/linux/iio/gyro/itg3200.h b/include/linux/iio/gyro/itg3200.h
new file mode 100644
index 000000000000..c53f16914b77
--- /dev/null
+++ b/include/linux/iio/gyro/itg3200.h
@@ -0,0 +1,154 @@
1/*
2 * itg3200.h -- support InvenSense ITG3200
3 * Digital 3-Axis Gyroscope driver
4 *
5 * Copyright (c) 2011 Christian Strobel <christian.strobel@iis.fraunhofer.de>
6 * Copyright (c) 2011 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
7 * Copyright (c) 2012 Thorsten Nowak <thorsten.nowak@iis.fraunhofer.de>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#ifndef I2C_ITG3200_H_
15#define I2C_ITG3200_H_
16
17#include <linux/iio/iio.h>
18
19/* Register with I2C address (34h) */
20#define ITG3200_REG_ADDRESS 0x00
21
22/* Sample rate divider
23 * Range: 0 to 255
24 * Default value: 0x00 */
25#define ITG3200_REG_SAMPLE_RATE_DIV 0x15
26
27/* Digital low pass filter settings */
28#define ITG3200_REG_DLPF 0x16
29/* DLPF full scale range */
30#define ITG3200_DLPF_FS_SEL_2000 0x18
31/* Bandwidth (Hz) and internal sample rate
32 * (kHz) of DLPF */
33#define ITG3200_DLPF_256_8 0x00
34#define ITG3200_DLPF_188_1 0x01
35#define ITG3200_DLPF_98_1 0x02
36#define ITG3200_DLPF_42_1 0x03
37#define ITG3200_DLPF_20_1 0x04
38#define ITG3200_DLPF_10_1 0x05
39#define ITG3200_DLPF_5_1 0x06
40
41#define ITG3200_DLPF_CFG_MASK 0x07
42
43/* Configuration for interrupt operations */
44#define ITG3200_REG_IRQ_CONFIG 0x17
45/* Logic level */
46#define ITG3200_IRQ_ACTIVE_LOW 0x80
47#define ITG3200_IRQ_ACTIVE_HIGH 0x00
48/* Drive type */
49#define ITG3200_IRQ_OPEN_DRAIN 0x40
50#define ITG3200_IRQ_PUSH_PULL 0x00
51/* Latch mode */
52#define ITG3200_IRQ_LATCH_UNTIL_CLEARED 0x20
53#define ITG3200_IRQ_LATCH_50US_PULSE 0x00
54/* Latch clear method */
55#define ITG3200_IRQ_LATCH_CLEAR_ANY 0x10
56#define ITG3200_IRQ_LATCH_CLEAR_STATUS 0x00
57/* Enable interrupt when device is ready */
58#define ITG3200_IRQ_DEVICE_RDY_ENABLE 0x04
59/* Enable interrupt when data is available */
60#define ITG3200_IRQ_DATA_RDY_ENABLE 0x01
61
62/* Determine the status of ITG-3200 interrupts */
63#define ITG3200_REG_IRQ_STATUS 0x1A
64/* Status of 'device is ready'-interrupt */
65#define ITG3200_IRQ_DEVICE_RDY_STATUS 0x04
66/* Status of 'data is available'-interrupt */
67#define ITG3200_IRQ_DATA_RDY_STATUS 0x01
68
69/* Sensor registers */
70#define ITG3200_REG_TEMP_OUT_H 0x1B
71#define ITG3200_REG_TEMP_OUT_L 0x1C
72#define ITG3200_REG_GYRO_XOUT_H 0x1D
73#define ITG3200_REG_GYRO_XOUT_L 0x1E
74#define ITG3200_REG_GYRO_YOUT_H 0x1F
75#define ITG3200_REG_GYRO_YOUT_L 0x20
76#define ITG3200_REG_GYRO_ZOUT_H 0x21
77#define ITG3200_REG_GYRO_ZOUT_L 0x22
78
79/* Power management */
80#define ITG3200_REG_POWER_MANAGEMENT 0x3E
81/* Reset device and internal registers to the
82 * power-up-default settings */
83#define ITG3200_RESET 0x80
84/* Enable low power sleep mode */
85#define ITG3200_SLEEP 0x40
86/* Put according gyroscope in standby mode */
87#define ITG3200_STANDBY_GYRO_X 0x20
88#define ITG3200_STANDBY_GYRO_Y 0x10
89#define ITG3200_STANDBY_GYRO_Z 0x08
90/* Determine the device clock source */
91#define ITG3200_CLK_INTERNAL 0x00
92#define ITG3200_CLK_GYRO_X 0x01
93#define ITG3200_CLK_GYRO_Y 0x02
94#define ITG3200_CLK_GYRO_Z 0x03
95#define ITG3200_CLK_EXT_32K 0x04
96#define ITG3200_CLK_EXT_19M 0x05
97
98
99/**
100 * struct itg3200 - device instance specific data
101 * @i2c: actual i2c_client
102 * @trig: data ready trigger from itg3200 pin
103 **/
104struct itg3200 {
105 struct i2c_client *i2c;
106 struct iio_trigger *trig;
107};
108
109enum ITG3200_SCAN_INDEX {
110 ITG3200_SCAN_TEMP,
111 ITG3200_SCAN_GYRO_X,
112 ITG3200_SCAN_GYRO_Y,
113 ITG3200_SCAN_GYRO_Z,
114 ITG3200_SCAN_ELEMENTS,
115};
116
117int itg3200_write_reg_8(struct iio_dev *indio_dev,
118 u8 reg_address, u8 val);
119
120int itg3200_read_reg_8(struct iio_dev *indio_dev,
121 u8 reg_address, u8 *val);
122
123
124#ifdef CONFIG_IIO_BUFFER
125
126void itg3200_remove_trigger(struct iio_dev *indio_dev);
127int itg3200_probe_trigger(struct iio_dev *indio_dev);
128
129int itg3200_buffer_configure(struct iio_dev *indio_dev);
130void itg3200_buffer_unconfigure(struct iio_dev *indio_dev);
131
132#else /* CONFIG_IIO_BUFFER */
133
134static inline void itg3200_remove_trigger(struct iio_dev *indio_dev)
135{
136}
137
138static inline int itg3200_probe_trigger(struct iio_dev *indio_dev)
139{
140 return 0;
141}
142
143static inline int itg3200_buffer_configure(struct iio_dev *indio_dev)
144{
145 return 0;
146}
147
148static inline void itg3200_buffer_unconfigure(struct iio_dev *indio_dev)
149{
150}
151
152#endif /* CONFIG_IIO_RING_BUFFER */
153
154#endif /* ITG3200_H_ */
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h
index 20239da1d0f7..c66e0a96f6e8 100644
--- a/include/linux/iio/trigger.h
+++ b/include/linux/iio/trigger.h
@@ -12,6 +12,7 @@
12#ifndef _IIO_TRIGGER_H_ 12#ifndef _IIO_TRIGGER_H_
13#define _IIO_TRIGGER_H_ 13#define _IIO_TRIGGER_H_
14 14
15#ifdef CONFIG_IIO_TRIGGER
15struct iio_subirq { 16struct iio_subirq {
16 bool enabled; 17 bool enabled;
17}; 18};
@@ -117,4 +118,8 @@ irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
117__printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...); 118__printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...);
118void iio_trigger_free(struct iio_trigger *trig); 119void iio_trigger_free(struct iio_trigger *trig);
119 120
121#else
122struct iio_trigger;
123struct iio_trigger_ops;
124#endif
120#endif /* _IIO_TRIGGER_H_ */ 125#endif /* _IIO_TRIGGER_H_ */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 907e7e56fa4b..6938ccfa42d5 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1807,6 +1807,8 @@
1807#define PCI_VENDOR_ID_ESDGMBH 0x12fe 1807#define PCI_VENDOR_ID_ESDGMBH 0x12fe
1808#define PCI_DEVICE_ID_ESDGMBH_CPCIASIO4 0x0111 1808#define PCI_DEVICE_ID_ESDGMBH_CPCIASIO4 0x0111
1809 1809
1810#define PCI_VENDOR_ID_CB 0x1307 /* Measurement Computing */
1811
1810#define PCI_VENDOR_ID_SIIG 0x131f 1812#define PCI_VENDOR_ID_SIIG 0x131f
1811#define PCI_SUBVENDOR_ID_SIIG 0x131f 1813#define PCI_SUBVENDOR_ID_SIIG 0x131f
1812#define PCI_DEVICE_ID_SIIG_1S_10x_550 0x1000 1814#define PCI_DEVICE_ID_SIIG_1S_10x_550 0x1000
@@ -2013,6 +2015,10 @@
2013#define PCI_DEVICE_ID_CMEDIA_CM8738 0x0111 2015#define PCI_DEVICE_ID_CMEDIA_CM8738 0x0111
2014#define PCI_DEVICE_ID_CMEDIA_CM8738B 0x0112 2016#define PCI_DEVICE_ID_CMEDIA_CM8738B 0x0112
2015 2017
2018#define PCI_VENDOR_ID_ADVANTECH 0x13fe
2019
2020#define PCI_VENDOR_ID_MEILHAUS 0x1402
2021
2016#define PCI_VENDOR_ID_LAVA 0x1407 2022#define PCI_VENDOR_ID_LAVA 0x1407
2017#define PCI_DEVICE_ID_LAVA_DSERIAL 0x0100 /* 2x 16550 */ 2023#define PCI_DEVICE_ID_LAVA_DSERIAL 0x0100 /* 2x 16550 */
2018#define PCI_DEVICE_ID_LAVA_QUATRO_A 0x0101 /* 2x 16550, half of 4 port */ 2024#define PCI_DEVICE_ID_LAVA_QUATRO_A 0x0101 /* 2x 16550, half of 4 port */
@@ -2058,6 +2064,8 @@
2058 2064
2059#define PCI_VENDOR_ID_CHELSIO 0x1425 2065#define PCI_VENDOR_ID_CHELSIO 0x1425
2060 2066
2067#define PCI_VENDOR_ID_ADLINK 0x144a
2068
2061#define PCI_VENDOR_ID_SAMSUNG 0x144d 2069#define PCI_VENDOR_ID_SAMSUNG 0x144d
2062 2070
2063#define PCI_VENDOR_ID_GIGABYTE 0x1458 2071#define PCI_VENDOR_ID_GIGABYTE 0x1458
@@ -2091,6 +2099,8 @@
2091#define PCI_DEVICE_ID_AFAVLAB_P030 0x2182 2099#define PCI_DEVICE_ID_AFAVLAB_P030 0x2182
2092#define PCI_SUBDEVICE_ID_AFAVLAB_P061 0x2150 2100#define PCI_SUBDEVICE_ID_AFAVLAB_P061 0x2150
2093 2101
2102#define PCI_VENDOR_ID_AMPLICON 0x14dc
2103
2094#define PCI_VENDOR_ID_BCM_GVC 0x14a4 2104#define PCI_VENDOR_ID_BCM_GVC 0x14a4
2095#define PCI_VENDOR_ID_BROADCOM 0x14e4 2105#define PCI_VENDOR_ID_BROADCOM 0x14e4
2096#define PCI_DEVICE_ID_TIGON3_5752 0x1600 2106#define PCI_DEVICE_ID_TIGON3_5752 0x1600
diff --git a/include/linux/platform_data/invensense_mpu6050.h b/include/linux/platform_data/invensense_mpu6050.h
new file mode 100644
index 000000000000..ad3aa7b95f35
--- /dev/null
+++ b/include/linux/platform_data/invensense_mpu6050.h
@@ -0,0 +1,31 @@
1/*
2* Copyright (C) 2012 Invensense, Inc.
3*
4* This software is licensed under the terms of the GNU General Public
5* License version 2, as published by the Free Software Foundation, and
6* may be copied, distributed, and modified under those terms.
7*
8* This program is distributed in the hope that it will be useful,
9* but WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*/
13
14#ifndef __INV_MPU6050_PLATFORM_H_
15#define __INV_MPU6050_PLATFORM_H_
16
17/**
18 * struct inv_mpu6050_platform_data - Platform data for the mpu driver
19 * @orientation: Orientation matrix of the chip
20 *
21 * Contains platform specific information on how to configure the MPU6050 to
22 * work on this platform. The orientation matricies are 3x3 rotation matricies
23 * that are applied to the data to rotate from the mounting orientation to the
24 * platform orientation. The values must be one of 0, 1, or -1 and each row and
25 * column should have exactly 1 non-zero value.
26 */
27struct inv_mpu6050_platform_data {
28 __s8 orientation[9];
29};
30
31#endif
diff --git a/drivers/staging/iio/light/tsl2563.h b/include/linux/platform_data/tsl2563.h
index b97368bd7fff..c90d7a09dda7 100644
--- a/drivers/staging/iio/light/tsl2563.h
+++ b/include/linux/platform_data/tsl2563.h
@@ -6,4 +6,3 @@ struct tsl2563_platform_data {
6}; 6};
7 7
8#endif /* __LINUX_TSL2563_H */ 8#endif /* __LINUX_TSL2563_H */
9
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 30e9c50a5e20..38c2b925923d 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -596,6 +596,26 @@ spi_transfer_del(struct spi_transfer *t)
596 list_del(&t->transfer_list); 596 list_del(&t->transfer_list);
597} 597}
598 598
599/**
600 * spi_message_init_with_transfers - Initialize spi_message and append transfers
601 * @m: spi_message to be initialized
602 * @xfers: An array of spi transfers
603 * @num_xfers: Number of items in the xfer array
604 *
605 * This function initializes the given spi_message and adds each spi_transfer in
606 * the given array to the message.
607 */
608static inline void
609spi_message_init_with_transfers(struct spi_message *m,
610struct spi_transfer *xfers, unsigned int num_xfers)
611{
612 unsigned int i;
613
614 spi_message_init(m);
615 for (i = 0; i < num_xfers; ++i)
616 spi_message_add_tail(&xfers[i], m);
617}
618
599/* It's fine to embed message and transaction structures in other data 619/* It's fine to embed message and transaction structures in other data
600 * structures so long as you don't free them while they're in use. 620 * structures so long as you don't free them while they're in use.
601 */ 621 */
@@ -688,6 +708,30 @@ spi_read(struct spi_device *spi, void *buf, size_t len)
688 return spi_sync(spi, &m); 708 return spi_sync(spi, &m);
689} 709}
690 710
711/**
712 * spi_sync_transfer - synchronous SPI data transfer
713 * @spi: device with which data will be exchanged
714 * @xfers: An array of spi_transfers
715 * @num_xfers: Number of items in the xfer array
716 * Context: can sleep
717 *
718 * Does a synchronous SPI data transfer of the given spi_transfer array.
719 *
720 * For more specific semantics see spi_sync().
721 *
722 * It returns zero on success, else a negative error code.
723 */
724static inline int
725spi_sync_transfer(struct spi_device *spi, struct spi_transfer *xfers,
726 unsigned int num_xfers)
727{
728 struct spi_message msg;
729
730 spi_message_init_with_transfers(&msg, xfers, num_xfers);
731
732 return spi_sync(spi, &msg);
733}
734
691/* this copies txbuf and rxbuf data; for small transfers only! */ 735/* this copies txbuf and rxbuf data; for small transfers only! */
692extern int spi_write_then_read(struct spi_device *spi, 736extern int spi_write_then_read(struct spi_device *spi,
693 const void *txbuf, unsigned n_tx, 737 const void *txbuf, unsigned n_tx,