aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-02-22 15:14:01 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-02-22 15:14:01 -0500
commitcaa59428971d5ad81d19512365c9ba580d83268c (patch)
treecd9615719bad9a97f02bb5bc1021396a1b484762 /drivers
parentb2064617c74f301dab1448f1f9c8dbb3c8021058 (diff)
parent0a441275018b69deffd35bc22a84fd51c54d7d85 (diff)
Merge tag 'staging-4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging/iio driver updates from Greg KH: "Here is the big staging and iio driver patchsets for 4.11-rc1. We almost broke even this time around, with only a few thousand lines added overall, as we removed the old and obsolete i4l code, but added some new drivers for the RPi platform, as well as adding some new IIO drivers. All of these have been in linux-next for a while with no reported issues" * tag 'staging-4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (669 commits) Staging: vc04_services: Fix the "space prohibited" code style errors Staging: vc04_services: Fix the "wrong indent" code style errors staging: octeon: Use net_device_stats from struct net_device Staging: rtl8192u: ieee80211: ieee80211.h - style fix Staging: rtl8192u: ieee80211: ieee80211_tx.c - style fix Staging: rtl8192u: ieee80211: rtl819x_BAProc.c - style fix Staging: rtl8192u: ieee80211: ieee80211_module.c - style fix Staging: rtl8192u: ieee80211: rtl819x_TSProc.c - style fix Staging: rtl8192u: r8192U.h - style fix Staging: rtl8192u: r8192U_core.c - style fix Staging: rtl8192u: r819xU_cmdpkt.c - style fix staging: rtl8192u: blank lines aren't necessary before a close brace '}' staging: rtl8192u: Adding space after enum and struct definition staging: rtl8192u: Adding space after struct definition Staging: ks7010: Add required and preferred spaces around operators Staging: ks7010: ks*: Remove redundant blank lines Staging: ks7010: ks*: Add missing blank lines after declarations staging: visorbus, replace init_timer with setup_timer staging: vt6656: rxtx.c Removed multiple dereferencing staging: vt6656: Alignment match open parenthesis ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/iio/accel/Kconfig2
-rw-r--r--drivers/iio/accel/bmc150-accel-core.c3
-rw-r--r--drivers/iio/accel/hid-sensor-accel-3d.c104
-rw-r--r--drivers/iio/accel/mma8452.c4
-rw-r--r--drivers/iio/accel/ssp_accel_sensor.c13
-rw-r--r--drivers/iio/accel/st_accel.h18
-rw-r--r--drivers/iio/accel/st_accel_i2c.c78
-rw-r--r--drivers/iio/accel/st_accel_spi.c9
-rw-r--r--drivers/iio/adc/Kconfig83
-rw-r--r--drivers/iio/adc/Makefile6
-rw-r--r--drivers/iio/adc/axp288_adc.c32
-rw-r--r--drivers/iio/adc/exynos_adc.c2
-rw-r--r--drivers/iio/adc/fsl-imx25-gcq.c1
-rw-r--r--drivers/iio/adc/hx711.c532
-rw-r--r--drivers/iio/adc/ina2xx-adc.c2
-rw-r--r--drivers/iio/adc/max11100.c181
-rw-r--r--drivers/iio/adc/max1363.c1
-rw-r--r--drivers/iio/adc/meson_saradc.c922
-rw-r--r--drivers/iio/adc/qcom-spmi-vadc.c481
-rw-r--r--drivers/iio/adc/rcar-gyroadc.c631
-rw-r--r--drivers/iio/adc/stm32-adc-core.c1
-rw-r--r--drivers/iio/adc/stm32-adc-core.h2
-rw-r--r--drivers/iio/adc/stm32-adc.c633
-rw-r--r--drivers/iio/adc/stx104.c72
-rw-r--r--drivers/iio/adc/ti-ads1015.c4
-rw-r--r--drivers/iio/adc/ti-ads7950.c490
-rw-r--r--drivers/iio/adc/ti-tlc4541.c271
-rw-r--r--drivers/iio/buffer/industrialio-buffer-cb.c3
-rw-r--r--drivers/iio/buffer/kfifo_buf.c3
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-attributes.c36
-rw-r--r--drivers/iio/common/ssp_sensors/ssp_iio.c1
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_i2c.c20
-rw-r--r--drivers/iio/dac/ad5592r.c8
-rw-r--r--drivers/iio/dac/ad5593r.c8
-rw-r--r--drivers/iio/dummy/iio_simple_dummy.h8
-rw-r--r--drivers/iio/dummy/iio_simple_dummy_buffer.c4
-rw-r--r--drivers/iio/gyro/ssp_gyro_sensor.c13
-rw-r--r--drivers/iio/health/max30100.c2
-rw-r--r--drivers/iio/humidity/hts221_i2c.c8
-rw-r--r--drivers/iio/imu/Kconfig1
-rw-r--r--drivers/iio/imu/Makefile2
-rw-r--r--drivers/iio/imu/bmi160/bmi160_core.c8
-rw-r--r--drivers/iio/imu/bmi160/bmi160_i2c.c14
-rw-r--r--drivers/iio/imu/bmi160/bmi160_spi.c18
-rw-r--r--drivers/iio/imu/st_lsm6dsx/Kconfig22
-rw-r--r--drivers/iio/imu/st_lsm6dsx/Makefile5
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h141
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c454
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c720
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c101
-rw-r--r--drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c118
-rw-r--r--drivers/iio/industrialio-buffer.c321
-rw-r--r--drivers/iio/industrialio-core.c2
-rw-r--r--drivers/iio/industrialio-trigger.c92
-rw-r--r--drivers/iio/inkern.c10
-rw-r--r--drivers/iio/light/Kconfig10
-rw-r--r--drivers/iio/light/Makefile1
-rw-r--r--drivers/iio/light/cm3232.c2
-rw-r--r--drivers/iio/light/cm3605.c330
-rw-r--r--drivers/iio/light/hid-sensor-als.c24
-rw-r--r--drivers/iio/light/opt3001.c1
-rw-r--r--drivers/iio/magnetometer/ak8974.c8
-rw-r--r--drivers/iio/magnetometer/mag3110.c30
-rw-r--r--drivers/iio/potentiometer/Kconfig11
-rw-r--r--drivers/iio/potentiometer/Makefile1
-rw-r--r--drivers/iio/potentiometer/max5481.c223
-rw-r--r--drivers/iio/potentiometer/mcp4531.c1
-rw-r--r--drivers/iio/pressure/Kconfig10
-rw-r--r--drivers/iio/pressure/Makefile1
-rw-r--r--drivers/iio/pressure/bmp280-core.c14
-rw-r--r--drivers/iio/pressure/cros_ec_baro.c220
-rw-r--r--drivers/iio/pressure/mpl115.c1
-rw-r--r--drivers/iio/pressure/mpl3115.c4
-rw-r--r--drivers/iio/pressure/ms5611_core.c12
-rw-r--r--drivers/iio/pressure/st_pressure.h8
-rw-r--r--drivers/iio/pressure/st_pressure_core.c12
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c51
-rw-r--r--drivers/iio/proximity/Kconfig13
-rw-r--r--drivers/iio/proximity/Makefile1
-rw-r--r--drivers/iio/proximity/pulsedlight-lidar-lite-v2.c2
-rw-r--r--drivers/iio/proximity/srf08.c398
-rw-r--r--drivers/iio/proximity/sx9500.c10
-rw-r--r--drivers/iio/temperature/Kconfig10
-rw-r--r--drivers/iio/temperature/Makefile1
-rw-r--r--drivers/iio/temperature/tmp007.c345
-rw-r--r--drivers/iio/trigger/Kconfig9
-rw-r--r--drivers/iio/trigger/Makefile1
-rw-r--r--drivers/iio/trigger/iio-trig-interrupt.c8
-rw-r--r--drivers/iio/trigger/iio-trig-sysfs.c2
-rw-r--r--drivers/iio/trigger/stm32-timer-trigger.c342
-rw-r--r--drivers/mfd/Kconfig11
-rw-r--r--drivers/mfd/Makefile2
-rw-r--r--drivers/mfd/stm32-timers.c80
-rw-r--r--drivers/platform/chrome/cros_ec_dev.c3
-rw-r--r--drivers/pwm/Kconfig9
-rw-r--r--drivers/pwm/Makefile1
-rw-r--r--drivers/pwm/pwm-stm32.c397
-rw-r--r--drivers/staging/Kconfig4
-rw-r--r--drivers/staging/Makefile3
-rw-r--r--drivers/staging/android/ion/ion-ioctl.c3
-rw-r--r--drivers/staging/android/ion/ion_cma_heap.c12
-rw-r--r--drivers/staging/android/ion/ion_of.c1
-rw-r--r--drivers/staging/android/ion/ion_priv.h40
-rw-r--r--drivers/staging/bcm2835-audio/Kconfig7
-rw-r--r--drivers/staging/bcm2835-audio/Makefile5
-rw-r--r--drivers/staging/bcm2835-audio/TODO29
-rw-r--r--drivers/staging/bcm2835-audio/bcm2835-ctl.c345
-rw-r--r--drivers/staging/bcm2835-audio/bcm2835-pcm.c554
-rw-r--r--drivers/staging/bcm2835-audio/bcm2835-vchiq.c912
-rw-r--r--drivers/staging/bcm2835-audio/bcm2835.c250
-rw-r--r--drivers/staging/bcm2835-audio/bcm2835.h167
-rw-r--r--drivers/staging/bcm2835-audio/vc_vchi_audioserv_defs.h108
-rw-r--r--drivers/staging/comedi/Kconfig10
-rw-r--r--drivers/staging/comedi/comedi_compat32.h3
-rw-r--r--drivers/staging/comedi/comedi_fops.c10
-rw-r--r--drivers/staging/comedi/comedi_internal.h9
-rw-r--r--drivers/staging/comedi/comedi_pci.h18
-rw-r--r--drivers/staging/comedi/comedi_pcmcia.c3
-rw-r--r--drivers/staging/comedi/comedi_pcmcia.h22
-rw-r--r--drivers/staging/comedi/comedi_usb.h16
-rw-r--r--drivers/staging/comedi/comedidev.h55
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3501.c2
-rw-r--r--drivers/staging/comedi/drivers/addi_watchdog.h2
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9118.c5
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas64.c140
-rw-r--r--drivers/staging/comedi/drivers/comedi_8254.h30
-rw-r--r--drivers/staging/comedi/drivers/comedi_isadma.h10
-rw-r--r--drivers/staging/comedi/drivers/comedi_test.c135
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c401
-rw-r--r--drivers/staging/comedi/drivers/dmm32at.c4
-rw-r--r--drivers/staging/comedi/drivers/dt2801.c4
-rw-r--r--drivers/staging/comedi/drivers/dt2814.c2
-rw-r--r--drivers/staging/comedi/drivers/dt2815.c2
-rw-r--r--drivers/staging/comedi/drivers/dyna_pci10xx.c8
-rw-r--r--drivers/staging/comedi/drivers/mite.h37
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c10
-rw-r--r--drivers/staging/comedi/drivers/ni_670x.c2
-rw-r--r--drivers/staging/comedi/drivers/ni_at_a2150.c2
-rw-r--r--drivers/staging/comedi/drivers/ni_at_ao.c62
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc.h4
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c42
-rw-r--r--drivers/staging/comedi/drivers/ni_pcimio.c182
-rw-r--r--drivers/staging/comedi/drivers/ni_stc.h1
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.h42
-rw-r--r--drivers/staging/comedi/drivers/ni_tio_internal.h14
-rw-r--r--drivers/staging/comedi/drivers/s626.c2
-rw-r--r--drivers/staging/comedi/proc.c6
-rw-r--r--drivers/staging/dgnc/TODO3
-rw-r--r--drivers/staging/dgnc/dgnc_tty.c10
-rw-r--r--drivers/staging/emxx_udc/emxx_udc.c30
-rw-r--r--drivers/staging/fbtft/fb_agm1264k-fl.c18
-rw-r--r--drivers/staging/fbtft/fb_hx8340bn.c4
-rw-r--r--drivers/staging/fbtft/fb_hx8347d.c2
-rw-r--r--drivers/staging/fbtft/fb_hx8353d.c2
-rw-r--r--drivers/staging/fbtft/fb_ili9163.c2
-rw-r--r--drivers/staging/fbtft/fb_ili9320.c2
-rw-r--r--drivers/staging/fbtft/fb_ili9325.c2
-rw-r--r--drivers/staging/fbtft/fb_ili9341.c2
-rw-r--r--drivers/staging/fbtft/fb_pcd8544.c6
-rw-r--r--drivers/staging/fbtft/fb_ra8875.c14
-rw-r--r--drivers/staging/fbtft/fb_s6d1121.c2
-rw-r--r--drivers/staging/fbtft/fb_ssd1289.c4
-rw-r--r--drivers/staging/fbtft/fb_ssd1305.c2
-rw-r--r--drivers/staging/fbtft/fb_ssd1306.c41
-rw-r--r--drivers/staging/fbtft/fb_ssd1325.c2
-rw-r--r--drivers/staging/fbtft/fb_ssd1331.c22
-rw-r--r--drivers/staging/fbtft/fb_ssd1351.c6
-rw-r--r--drivers/staging/fbtft/fb_st7735r.c2
-rw-r--r--drivers/staging/fbtft/fb_st7789v.c2
-rw-r--r--drivers/staging/fbtft/fb_tls8204.c4
-rw-r--r--drivers/staging/fbtft/fb_uc1611.c12
-rw-r--r--drivers/staging/fbtft/fb_watterott.c2
-rw-r--r--drivers/staging/fbtft/fbtft-core.c34
-rw-r--r--drivers/staging/fbtft/fbtft-io.c4
-rw-r--r--drivers/staging/fbtft/fbtft-sysfs.c15
-rw-r--r--drivers/staging/fbtft/fbtft.h5
-rw-r--r--drivers/staging/fbtft/fbtft_device.c38
-rw-r--r--drivers/staging/fbtft/flexfb.c34
-rw-r--r--drivers/staging/fbtft/internal.h2
-rw-r--r--drivers/staging/fsl-mc/bus/dpbp-cmd.h116
-rw-r--r--drivers/staging/fsl-mc/bus/dpbp.c452
-rw-r--r--drivers/staging/fsl-mc/bus/dpmcp-cmd.h95
-rw-r--r--drivers/staging/fsl-mc/bus/dpmcp.c382
-rw-r--r--drivers/staging/fsl-mc/bus/dpmcp.h100
-rw-r--r--drivers/staging/fsl-mc/bus/dprc-cmd.h18
-rw-r--r--drivers/staging/fsl-mc/bus/dprc-driver.c1
-rw-r--r--drivers/staging/fsl-mc/bus/dprc.c666
-rw-r--r--drivers/staging/fsl-mc/bus/fsl-mc-bus.c75
-rw-r--r--drivers/staging/fsl-mc/bus/fsl-mc-msi.c1
-rw-r--r--drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c3
-rw-r--r--drivers/staging/fsl-mc/include/dpbp.h129
-rw-r--r--drivers/staging/fsl-mc/include/dpmng.h4
-rw-r--r--drivers/staging/fsl-mc/include/dprc.h243
-rw-r--r--drivers/staging/gdm724x/gdm_endian.c24
-rw-r--r--drivers/staging/gdm724x/gdm_endian.h15
-rw-r--r--drivers/staging/gdm724x/gdm_lte.c53
-rw-r--r--drivers/staging/gdm724x/hci_packet.h46
-rw-r--r--drivers/staging/greybus/Makefile4
-rw-r--r--drivers/staging/greybus/arche-apb-ctrl.c9
-rw-r--r--drivers/staging/greybus/arche-platform.c43
-rw-r--r--drivers/staging/greybus/arche_platform.h2
-rw-r--r--drivers/staging/greybus/arpc.h1
-rw-r--r--drivers/staging/greybus/audio_codec.c51
-rw-r--r--drivers/staging/greybus/audio_codec.h46
-rw-r--r--drivers/staging/greybus/audio_gb.c4
-rw-r--r--drivers/staging/greybus/audio_module.c2
-rw-r--r--drivers/staging/greybus/audio_topology.c104
-rw-r--r--drivers/staging/greybus/authentication.c1
-rw-r--r--drivers/staging/greybus/bootrom.c13
-rw-r--r--drivers/staging/greybus/camera.c10
-rw-r--r--drivers/staging/greybus/connection.c6
-rw-r--r--drivers/staging/greybus/control.c50
-rw-r--r--drivers/staging/greybus/control.h7
-rw-r--r--drivers/staging/greybus/core.c11
-rw-r--r--drivers/staging/greybus/es2.c139
-rw-r--r--drivers/staging/greybus/fw-download.c6
-rw-r--r--drivers/staging/greybus/gbphy.c3
-rw-r--r--drivers/staging/greybus/gpio.c25
-rw-r--r--drivers/staging/greybus/greybus.h1
-rw-r--r--drivers/staging/greybus/greybus_protocols.h47
-rw-r--r--drivers/staging/greybus/greybus_trace.h28
-rw-r--r--drivers/staging/greybus/hd.h7
-rw-r--r--drivers/staging/greybus/interface.c56
-rw-r--r--drivers/staging/greybus/interface.h5
-rw-r--r--drivers/staging/greybus/log.c6
-rw-r--r--drivers/staging/greybus/loopback.c32
-rw-r--r--drivers/staging/greybus/operation.c50
-rw-r--r--drivers/staging/greybus/operation.h2
-rw-r--r--drivers/staging/greybus/sdio.c2
-rw-r--r--drivers/staging/greybus/svc.c119
-rw-r--r--drivers/staging/greybus/svc.h7
-rw-r--r--drivers/staging/greybus/svc_watchdog.c4
-rw-r--r--drivers/staging/greybus/timesync.c1357
-rw-r--r--drivers/staging/greybus/timesync.h45
-rw-r--r--drivers/staging/greybus/timesync_platform.c88
-rw-r--r--drivers/staging/greybus/tools/loopback_test.c5
-rw-r--r--drivers/staging/greybus/uart.c9
-rw-r--r--drivers/staging/greybus/vibrator.c4
-rw-r--r--drivers/staging/i4l/Documentation/README.act2000104
-rw-r--r--drivers/staging/i4l/Documentation/README.icn148
-rw-r--r--drivers/staging/i4l/Documentation/README.pcbit40
-rw-r--r--drivers/staging/i4l/Documentation/README.sc281
-rw-r--r--drivers/staging/i4l/Kconfig13
-rw-r--r--drivers/staging/i4l/Makefile5
-rw-r--r--drivers/staging/i4l/TODO3
-rw-r--r--drivers/staging/i4l/act2000/Kconfig9
-rw-r--r--drivers/staging/i4l/act2000/Makefile9
-rw-r--r--drivers/staging/i4l/act2000/act2000.h202
-rw-r--r--drivers/staging/i4l/act2000/act2000_isa.c444
-rw-r--r--drivers/staging/i4l/act2000/act2000_isa.h136
-rw-r--r--drivers/staging/i4l/act2000/capi.c1187
-rw-r--r--drivers/staging/i4l/act2000/capi.h357
-rw-r--r--drivers/staging/i4l/act2000/module.c816
-rw-r--r--drivers/staging/i4l/icn/Kconfig12
-rw-r--r--drivers/staging/i4l/icn/Makefile5
-rw-r--r--drivers/staging/i4l/icn/icn.c1696
-rw-r--r--drivers/staging/i4l/icn/icn.h252
-rw-r--r--drivers/staging/i4l/pcbit/Kconfig10
-rw-r--r--drivers/staging/i4l/pcbit/Makefile9
-rw-r--r--drivers/staging/i4l/pcbit/callbacks.c345
-rw-r--r--drivers/staging/i4l/pcbit/callbacks.h44
-rw-r--r--drivers/staging/i4l/pcbit/capi.c646
-rw-r--r--drivers/staging/i4l/pcbit/capi.h81
-rw-r--r--drivers/staging/i4l/pcbit/drv.c1070
-rw-r--r--drivers/staging/i4l/pcbit/edss1.c310
-rw-r--r--drivers/staging/i4l/pcbit/edss1.h99
-rw-r--r--drivers/staging/i4l/pcbit/layer2.c710
-rw-r--r--drivers/staging/i4l/pcbit/layer2.h281
-rw-r--r--drivers/staging/i4l/pcbit/module.c125
-rw-r--r--drivers/staging/i4l/pcbit/pcbit.h177
-rw-r--r--drivers/staging/iio/accel/adis16201_core.c4
-rw-r--r--drivers/staging/iio/accel/adis16203_core.c6
-rw-r--r--drivers/staging/iio/accel/adis16209_core.c4
-rw-r--r--drivers/staging/iio/adc/ad7606.c79
-rw-r--r--drivers/staging/iio/adc/ad7816.c10
-rw-r--r--drivers/staging/iio/addac/adt7316-i2c.c2
-rw-r--r--drivers/staging/iio/addac/adt7316.c3
-rw-r--r--drivers/staging/iio/cdc/ad7150.c34
-rw-r--r--drivers/staging/iio/impedance-analyzer/ad5933.c4
-rw-r--r--drivers/staging/iio/light/isl29028.c415
-rw-r--r--drivers/staging/iio/meter/ade7753.c2
-rw-r--r--drivers/staging/iio/meter/ade7753.h2
-rw-r--r--drivers/staging/iio/meter/ade7754.c2
-rw-r--r--drivers/staging/iio/meter/ade7754.h2
-rw-r--r--drivers/staging/iio/meter/ade7758.h2
-rw-r--r--drivers/staging/iio/meter/ade7758_core.c2
-rw-r--r--drivers/staging/iio/meter/ade7758_ring.c1
-rw-r--r--drivers/staging/iio/meter/ade7759.c2
-rw-r--r--drivers/staging/iio/meter/ade7759.h2
-rw-r--r--drivers/staging/iio/meter/ade7854.c2
-rw-r--r--drivers/staging/iio/meter/ade7854.h2
-rw-r--r--drivers/staging/iio/trigger/iio-trig-bfin-timer.c6
-rw-r--r--drivers/staging/ks7010/ks7010_sdio.c1
-rw-r--r--drivers/staging/ks7010/ks7010_sdio.h5
-rw-r--r--drivers/staging/ks7010/ks_hostif.c13
-rw-r--r--drivers/staging/ks7010/ks_hostif.h64
-rw-r--r--drivers/staging/ks7010/ks_wlan.h6
-rw-r--r--drivers/staging/ks7010/ks_wlan_ioctl.h64
-rw-r--r--drivers/staging/ks7010/ks_wlan_net.c16
-rw-r--r--drivers/staging/ks7010/michael_mic.c8
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h60
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_private.h16
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h4
-rw-r--r--drivers/staging/lustre/include/linux/lnet/lib-lnet.h14
-rw-r--r--drivers/staging/lustre/include/linux/lnet/lib-types.h10
-rw-r--r--drivers/staging/lustre/include/linux/lnet/lnetst.h198
-rw-r--r--drivers/staging/lustre/include/linux/lnet/socklnd.h11
-rw-r--r--drivers/staging/lustre/include/linux/lnet/types.h70
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c16
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h6
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c4
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c16
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h2
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c43
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c26
-rw-r--r--drivers/staging/lustre/lnet/libcfs/debug.c2
-rw-r--r--drivers/staging/lustre/lnet/libcfs/hash.c2
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c17
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-module.c15
-rw-r--r--drivers/staging/lustre/lnet/libcfs/module.c4
-rw-r--r--drivers/staging/lustre/lnet/libcfs/workitem.c2
-rw-r--r--drivers/staging/lustre/lnet/lnet/acceptor.c14
-rw-r--r--drivers/staging/lustre/lnet/lnet/api-ni.c186
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-move.c20
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-msg.c4
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-ptl.c2
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-socket.c8
-rw-r--r--drivers/staging/lustre/lnet/lnet/net_fault.c12
-rw-r--r--drivers/staging/lustre/lnet/lnet/router.c10
-rw-r--r--drivers/staging/lustre/lnet/lnet/router_proc.c4
-rw-r--r--drivers/staging/lustre/lnet/selftest/brw_test.c2
-rw-r--r--drivers/staging/lustre/lnet/selftest/conctl.c76
-rw-r--r--drivers/staging/lustre/lnet/selftest/conrpc.c36
-rw-r--r--drivers/staging/lustre/lnet/selftest/conrpc.h4
-rw-r--r--drivers/staging/lustre/lnet/selftest/console.c56
-rw-r--r--drivers/staging/lustre/lnet/selftest/console.h24
-rw-r--r--drivers/staging/lustre/lnet/selftest/framework.c18
-rw-r--r--drivers/staging/lustre/lnet/selftest/module.c3
-rw-r--r--drivers/staging/lustre/lnet/selftest/rpc.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/rpc.h38
-rw-r--r--drivers/staging/lustre/lnet/selftest/selftest.h10
-rw-r--r--drivers/staging/lustre/lustre/fid/fid_lib.c7
-rw-r--r--drivers/staging/lustre/lustre/fid/lproc_fid.c12
-rw-r--r--drivers/staging/lustre/lustre/include/cl_object.h12
-rw-r--r--drivers/staging/lustre/lustre/include/interval_tree.h12
-rw-r--r--drivers/staging/lustre/lustre/include/lu_object.h19
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_idl.h46
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_user.h18
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_net.h8
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_obdo.h54
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_req_layout.h10
-rw-r--r--drivers/staging/lustre/lustre/include/obd.h23
-rw-r--r--drivers/staging/lustre/lustre/include/obd_class.h5
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_extent.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_flock.c3
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c1
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lib.c13
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lock.c12
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_request.c2
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_resource.c2
-rw-r--r--drivers/staging/lustre/lustre/llite/dcache.c13
-rw-r--r--drivers/staging/lustre/lustre/llite/dir.c16
-rw-r--r--drivers/staging/lustre/lustre/llite/file.c109
-rw-r--r--drivers/staging/lustre/lustre/llite/lcommon_cl.c9
-rw-r--r--drivers/staging/lustre/lustre/llite/lcommon_misc.c2
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_internal.h16
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_lib.c126
-rw-r--r--drivers/staging/lustre/lustre/llite/lproc_llite.c27
-rw-r--r--drivers/staging/lustre/lustre/llite/namei.c9
-rw-r--r--drivers/staging/lustre/lustre/llite/range_lock.c10
-rw-r--r--drivers/staging/lustre/lustre/llite/range_lock.h2
-rw-r--r--drivers/staging/lustre/lustre/llite/rw.c199
-rw-r--r--drivers/staging/lustre/lustre/llite/rw26.c4
-rw-r--r--drivers/staging/lustre/lustre/llite/statahead.c94
-rw-r--r--drivers/staging/lustre/lustre/llite/super25.c2
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_dev.c2
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_internal.h2
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_io.c17
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_page.c3
-rw-r--r--drivers/staging/lustre/lustre/llite/xattr.c9
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_intent.c16
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_obd.c121
-rw-r--r--drivers/staging/lustre/lustre/lmv/lproc_lmv.c85
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_io.c7
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_lock.c5
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_obd.c2
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_object.c33
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_pack.c9
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_request.c6
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_internal.h3
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_lib.c12
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_locks.c20
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_request.c11
-rw-r--r--drivers/staging/lustre/lustre/mgc/mgc_request.c183
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_io.c4
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_object.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lu_object.c106
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_mount.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obdo.c54
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_cache.c155
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_cl_internal.h11
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_internal.h19
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_io.c79
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_object.c19
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_page.c98
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_request.c86
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/client.c28
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/events.c5
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/import.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/layout.c26
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/niobuf.c5
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/nrs.c3
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pack_generic.c103
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pers.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h3
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c18
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/recover.c24
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/service.c21
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/wiretest.c194
-rw-r--r--drivers/staging/media/Kconfig2
-rw-r--r--drivers/staging/media/Makefile1
-rw-r--r--drivers/staging/media/bcm2048/radio-bcm2048.c2
-rw-r--r--drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c2
-rw-r--r--drivers/staging/media/platform/bcm2835/Kconfig10
-rw-r--r--drivers/staging/media/platform/bcm2835/Makefile10
-rw-r--r--drivers/staging/media/platform/bcm2835/TODO39
-rw-r--r--drivers/staging/media/platform/bcm2835/bcm2835-camera.c2024
-rw-r--r--drivers/staging/media/platform/bcm2835/bcm2835-camera.h145
-rw-r--r--drivers/staging/media/platform/bcm2835/controls.c1335
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-common.h53
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-encodings.h127
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-msg-common.h50
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-msg-format.h81
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-msg-port.h107
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-msg.h404
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-parameters.h689
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-vchiq.c1913
-rw-r--r--drivers/staging/media/platform/bcm2835/mmal-vchiq.h178
-rw-r--r--drivers/staging/most/hdm-dim2/dim2_hdm.c4
-rw-r--r--drivers/staging/most/hdm-i2c/hdm_i2c.c2
-rw-r--r--drivers/staging/most/hdm-usb/hdm_usb.c10
-rw-r--r--drivers/staging/nvec/nvec.h2
-rw-r--r--drivers/staging/nvec/nvec_power.c2
-rw-r--r--drivers/staging/nvec/nvec_ps2.c2
-rw-r--r--drivers/staging/octeon/ethernet-rx.c6
-rw-r--r--drivers/staging/octeon/ethernet-tx.c10
-rw-r--r--drivers/staging/octeon/ethernet.c21
-rw-r--r--drivers/staging/octeon/octeon-ethernet.h2
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c14
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c4
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ap.c144
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_cmd.c3
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_efuse.c8
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ieee80211.c9
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ioctl_set.c5
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_led.c4
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme.c3
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c95
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_pwrctrl.c5
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_recv.c227
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_security.c158
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_sta_mgt.c1
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c3
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_xmit.c8
-rw-r--r--drivers/staging/rtl8188eu/hal/bb_cfg.c3
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c2
-rw-r--r--drivers/staging/rtl8188eu/include/drv_types.h1
-rw-r--r--drivers/staging/rtl8188eu/include/osdep_service.h7
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_debug.h2
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme.h185
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_recv.h73
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_security.h36
-rw-r--r--drivers/staging/rtl8188eu/include/wifi.h116
-rw-r--r--drivers/staging/rtl8188eu/os_dep/ioctl_linux.c15
-rw-r--r--drivers/staging/rtl8188eu/os_dep/mon.c4
-rw-r--r--drivers/staging/rtl8188eu/os_dep/os_intfs.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/osdep_service.c14
-rw-r--r--drivers/staging/rtl8188eu/os_dep/recv_linux.c21
-rw-r--r--drivers/staging/rtl8188eu/os_dep/rtw_android.c1
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c1
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c35
-rw-r--r--drivers/staging/rtl8192e/dot11d.h2
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_core.c12
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac.c32
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211.h67
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c21
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.h12
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c42
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c7
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_module.c65
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c64
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c316
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c3
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c127
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h38
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c9
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.c36
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.h27
-rw-r--r--drivers/staging/rtl8192u/r8190_rtl8256.c16
-rw-r--r--drivers/staging/rtl8192u/r8190_rtl8256.h20
-rw-r--r--drivers/staging/rtl8192u/r8192U.h39
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c84
-rw-r--r--drivers/staging/rtl8192u/r8192U_hw.h28
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.c6
-rw-r--r--drivers/staging/rtl8192u/r819xU_cmdpkt.c117
-rw-r--r--drivers/staging/rtl8192u/r819xU_cmdpkt.h9
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.c10
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.c41
-rw-r--r--drivers/staging/rtl8712/hal_init.c12
-rw-r--r--drivers/staging/rtl8712/ieee80211.c18
-rw-r--r--drivers/staging/rtl8712/ieee80211.h84
-rw-r--r--drivers/staging/rtl8712/mlme_linux.c6
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.c7
-rw-r--r--drivers/staging/rtl8712/rtl8712_event.h2
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c14
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.h28
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.c10
-rw-r--r--drivers/staging/rtl8712/rtl8712_xmit.h16
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.h6
-rw-r--r--drivers/staging/rtl8712/rtl871x_event.h2
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c8
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c24
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp_ioctl.c4
-rw-r--r--drivers/staging/rtl8712/rtl871x_recv.c14
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.c28
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.c7
-rw-r--r--drivers/staging/rtl8712/usb_ops.c18
-rw-r--r--drivers/staging/rtl8712/usb_ops_linux.c5
-rw-r--r--drivers/staging/rtl8712/wifi.h113
-rw-r--r--drivers/staging/rtl8712/wlan_bssdef.h2
-rw-r--r--drivers/staging/rts5208/ms.c6
-rw-r--r--drivers/staging/rts5208/rtsx.c6
-rw-r--r--drivers/staging/rts5208/rtsx_transport.c4
-rw-r--r--drivers/staging/skein/skein_base.c16
-rw-r--r--drivers/staging/skein/skein_base.h112
-rw-r--r--drivers/staging/skein/skein_block.c32
-rw-r--r--drivers/staging/skein/skein_block.h20
-rw-r--r--drivers/staging/skein/skein_iv.h24
-rw-r--r--drivers/staging/sm750fb/ddk750_chip.c48
-rw-r--r--drivers/staging/sm750fb/ddk750_chip.h13
-rw-r--r--drivers/staging/sm750fb/ddk750_display.c44
-rw-r--r--drivers/staging/sm750fb/ddk750_hwi2c.c38
-rw-r--r--drivers/staging/sm750fb/ddk750_mode.c38
-rw-r--r--drivers/staging/sm750fb/ddk750_power.c26
-rw-r--r--drivers/staging/sm750fb/ddk750_power.h4
-rw-r--r--drivers/staging/sm750fb/ddk750_swi2c.c34
-rw-r--r--drivers/staging/sm750fb/sm750.c9
-rw-r--r--drivers/staging/sm750fb/sm750_cursor.c12
-rw-r--r--drivers/staging/sm750fb/sm750_hw.c102
-rw-r--r--drivers/staging/speakup/fakekey.c10
-rw-r--r--drivers/staging/speakup/i18n.c14
-rw-r--r--drivers/staging/speakup/kobjects.c54
-rw-r--r--drivers/staging/speakup/main.c6
-rw-r--r--drivers/staging/speakup/speakup.h4
-rw-r--r--drivers/staging/speakup/speakup_acntpc.c26
-rw-r--r--drivers/staging/speakup/speakup_acntsa.c28
-rw-r--r--drivers/staging/speakup/speakup_apollo.c30
-rw-r--r--drivers/staging/speakup/speakup_audptr.c28
-rw-r--r--drivers/staging/speakup/speakup_bns.c28
-rw-r--r--drivers/staging/speakup/speakup_decext.c30
-rw-r--r--drivers/staging/speakup/speakup_decpc.c30
-rw-r--r--drivers/staging/speakup/speakup_dectlk.c28
-rw-r--r--drivers/staging/speakup/speakup_dtlk.c34
-rw-r--r--drivers/staging/speakup/speakup_dtlk.h10
-rw-r--r--drivers/staging/speakup/speakup_dummy.c26
-rw-r--r--drivers/staging/speakup/speakup_keypc.c22
-rw-r--r--drivers/staging/speakup/speakup_ltlk.c34
-rw-r--r--drivers/staging/speakup/speakup_soft.c32
-rw-r--r--drivers/staging/speakup/speakup_spkout.c28
-rw-r--r--drivers/staging/speakup/speakup_txprt.c26
-rw-r--r--drivers/staging/speakup/spk_priv.h4
-rw-r--r--drivers/staging/unisys/include/channel.h134
-rw-r--r--drivers/staging/unisys/visorbus/controlvmchannel.h87
-rw-r--r--drivers/staging/unisys/visorbus/visorbus_main.c52
-rw-r--r--drivers/staging/unisys/visorbus/visorchannel.c6
-rw-r--r--drivers/staging/unisys/visorbus/visorchipset.c465
-rw-r--r--drivers/staging/unisys/visorbus/vmcallinterface.h8
-rw-r--r--drivers/staging/unisys/visorhba/visorhba_main.c4
-rw-r--r--drivers/staging/unisys/visornic/visornic_main.c38
-rw-r--r--drivers/staging/vc04_services/interface/vchi/connections/connection.h3
-rw-r--r--drivers/staging/vc04_services/interface/vchi/message_drivers/message.h9
-rw-r--r--drivers/staging/vc04_services/interface/vchi/vchi.h36
-rw-r--r--drivers/staging/vc04_services/interface/vchi/vchi_common.h15
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835.h42
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c49
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c132
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h2
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c102
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.h3
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c14
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c84
-rw-r--r--drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c9
-rw-r--r--drivers/staging/vme/devices/vme_user.c3
-rw-r--r--drivers/staging/vt6655/baseband.h16
-rw-r--r--drivers/staging/vt6656/card.h34
-rw-r--r--drivers/staging/vt6656/channel.h2
-rw-r--r--drivers/staging/vt6656/dpc.h2
-rw-r--r--drivers/staging/vt6656/firmware.c34
-rw-r--r--drivers/staging/vt6656/firmware.h6
-rw-r--r--drivers/staging/vt6656/int.c2
-rw-r--r--drivers/staging/vt6656/int.h4
-rw-r--r--drivers/staging/vt6656/key.c14
-rw-r--r--drivers/staging/vt6656/key.h4
-rw-r--r--drivers/staging/vt6656/mac.c46
-rw-r--r--drivers/staging/vt6656/mac.h31
-rw-r--r--drivers/staging/vt6656/main_usb.c63
-rw-r--r--drivers/staging/vt6656/power.h6
-rw-r--r--drivers/staging/vt6656/rf.c12
-rw-r--r--drivers/staging/vt6656/rf.h10
-rw-r--r--drivers/staging/vt6656/rxtx.c58
-rw-r--r--drivers/staging/vt6656/rxtx.h8
-rw-r--r--drivers/staging/vt6656/usbpipe.c12
-rw-r--r--drivers/staging/vt6656/usbpipe.h17
-rw-r--r--drivers/staging/vt6656/wcmd.c2
-rw-r--r--drivers/staging/vt6656/wcmd.h4
-rw-r--r--drivers/staging/wilc1000/host_interface.c3
-rw-r--r--drivers/staging/wilc1000/linux_wlan.c4
-rw-r--r--drivers/staging/wilc1000/wilc_debugfs.c4
-rw-r--r--drivers/staging/wilc1000/wilc_sdio.c5
-rw-r--r--drivers/staging/wilc1000/wilc_wfi_cfgoperations.c26
-rw-r--r--drivers/staging/wlan-ng/cfg80211.c6
-rw-r--r--drivers/staging/wlan-ng/hfa384x.h4
-rw-r--r--drivers/staging/wlan-ng/p80211conv.c2
-rw-r--r--drivers/staging/wlan-ng/p80211conv.h4
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c2
-rw-r--r--drivers/staging/wlan-ng/prism2mgmt.c11
-rw-r--r--drivers/staging/wlan-ng/prism2mib.c4
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c31
-rw-r--r--drivers/staging/xgifb/vb_init.c3
-rw-r--r--drivers/staging/xgifb/vb_setmode.h18
634 files changed, 24633 insertions, 20656 deletions
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index c68bdb649005..ef8401ac1141 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -120,6 +120,8 @@ config HID_SENSOR_ACCEL_3D
120config IIO_ST_ACCEL_3AXIS 120config IIO_ST_ACCEL_3AXIS
121 tristate "STMicroelectronics accelerometers 3-Axis Driver" 121 tristate "STMicroelectronics accelerometers 3-Axis Driver"
122 depends on (I2C || SPI_MASTER) && SYSFS 122 depends on (I2C || SPI_MASTER) && SYSFS
123 depends on !SENSORS_LIS3_I2C
124 depends on !SENSORS_LIS3_SPI
123 select IIO_ST_SENSORS_CORE 125 select IIO_ST_SENSORS_CORE
124 select IIO_ST_ACCEL_I2C_3AXIS if (I2C) 126 select IIO_ST_ACCEL_I2C_3AXIS if (I2C)
125 select IIO_ST_ACCEL_SPI_3AXIS if (SPI_MASTER) 127 select IIO_ST_ACCEL_SPI_3AXIS if (SPI_MASTER)
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 59b380dbf27f..6b5d3be283c4 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -1638,7 +1638,8 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
1638 if (block_supported) { 1638 if (block_supported) {
1639 indio_dev->modes |= INDIO_BUFFER_SOFTWARE; 1639 indio_dev->modes |= INDIO_BUFFER_SOFTWARE;
1640 indio_dev->info = &bmc150_accel_info_fifo; 1640 indio_dev->info = &bmc150_accel_info_fifo;
1641 indio_dev->buffer->attrs = bmc150_accel_fifo_attributes; 1641 iio_buffer_set_attrs(indio_dev->buffer,
1642 bmc150_accel_fifo_attributes);
1642 } 1643 }
1643 } 1644 }
1644 1645
diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index ab1e238d5c75..ca5759c0c318 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -42,11 +42,13 @@ struct accel_3d_state {
42 struct hid_sensor_hub_callbacks callbacks; 42 struct hid_sensor_hub_callbacks callbacks;
43 struct hid_sensor_common common_attributes; 43 struct hid_sensor_common common_attributes;
44 struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX]; 44 struct hid_sensor_hub_attribute_info accel[ACCEL_3D_CHANNEL_MAX];
45 u32 accel_val[ACCEL_3D_CHANNEL_MAX]; 45 /* Reserve for 3 channels + padding + timestamp */
46 u32 accel_val[ACCEL_3D_CHANNEL_MAX + 3];
46 int scale_pre_decml; 47 int scale_pre_decml;
47 int scale_post_decml; 48 int scale_post_decml;
48 int scale_precision; 49 int scale_precision;
49 int value_offset; 50 int value_offset;
51 int64_t timestamp;
50}; 52};
51 53
52static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = { 54static const u32 accel_3d_addresses[ACCEL_3D_CHANNEL_MAX] = {
@@ -87,6 +89,42 @@ static const struct iio_chan_spec accel_3d_channels[] = {
87 BIT(IIO_CHAN_INFO_SAMP_FREQ) | 89 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
88 BIT(IIO_CHAN_INFO_HYSTERESIS), 90 BIT(IIO_CHAN_INFO_HYSTERESIS),
89 .scan_index = CHANNEL_SCAN_INDEX_Z, 91 .scan_index = CHANNEL_SCAN_INDEX_Z,
92 },
93 IIO_CHAN_SOFT_TIMESTAMP(3)
94};
95
96/* Channel definitions */
97static const struct iio_chan_spec gravity_channels[] = {
98 {
99 .type = IIO_GRAVITY,
100 .modified = 1,
101 .channel2 = IIO_MOD_X,
102 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
103 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
104 BIT(IIO_CHAN_INFO_SCALE) |
105 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
106 BIT(IIO_CHAN_INFO_HYSTERESIS),
107 .scan_index = CHANNEL_SCAN_INDEX_X,
108 }, {
109 .type = IIO_GRAVITY,
110 .modified = 1,
111 .channel2 = IIO_MOD_Y,
112 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
113 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
114 BIT(IIO_CHAN_INFO_SCALE) |
115 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
116 BIT(IIO_CHAN_INFO_HYSTERESIS),
117 .scan_index = CHANNEL_SCAN_INDEX_Y,
118 }, {
119 .type = IIO_GRAVITY,
120 .modified = 1,
121 .channel2 = IIO_MOD_Z,
122 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
123 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
124 BIT(IIO_CHAN_INFO_SCALE) |
125 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
126 BIT(IIO_CHAN_INFO_HYSTERESIS),
127 .scan_index = CHANNEL_SCAN_INDEX_Z,
90 } 128 }
91}; 129};
92 130
@@ -111,6 +149,8 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
111 int report_id = -1; 149 int report_id = -1;
112 u32 address; 150 u32 address;
113 int ret_type; 151 int ret_type;
152 struct hid_sensor_hub_device *hsdev =
153 accel_state->common_attributes.hsdev;
114 154
115 *val = 0; 155 *val = 0;
116 *val2 = 0; 156 *val2 = 0;
@@ -122,8 +162,7 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
122 if (report_id >= 0) 162 if (report_id >= 0)
123 *val = sensor_hub_input_attr_get_raw_value( 163 *val = sensor_hub_input_attr_get_raw_value(
124 accel_state->common_attributes.hsdev, 164 accel_state->common_attributes.hsdev,
125 HID_USAGE_SENSOR_ACCEL_3D, address, 165 hsdev->usage, address, report_id,
126 report_id,
127 SENSOR_HUB_SYNC); 166 SENSOR_HUB_SYNC);
128 else { 167 else {
129 *val = 0; 168 *val = 0;
@@ -192,11 +231,11 @@ static const struct iio_info accel_3d_info = {
192}; 231};
193 232
194/* Function to push data to buffer */ 233/* Function to push data to buffer */
195static void hid_sensor_push_data(struct iio_dev *indio_dev, const void *data, 234static void hid_sensor_push_data(struct iio_dev *indio_dev, void *data,
196 int len) 235 int len, int64_t timestamp)
197{ 236{
198 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n"); 237 dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
199 iio_push_to_buffers(indio_dev, data); 238 iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp);
200} 239}
201 240
202/* Callback handler to send event after all samples are received and captured */ 241/* Callback handler to send event after all samples are received and captured */
@@ -208,10 +247,17 @@ static int accel_3d_proc_event(struct hid_sensor_hub_device *hsdev,
208 struct accel_3d_state *accel_state = iio_priv(indio_dev); 247 struct accel_3d_state *accel_state = iio_priv(indio_dev);
209 248
210 dev_dbg(&indio_dev->dev, "accel_3d_proc_event\n"); 249 dev_dbg(&indio_dev->dev, "accel_3d_proc_event\n");
211 if (atomic_read(&accel_state->common_attributes.data_ready)) 250 if (atomic_read(&accel_state->common_attributes.data_ready)) {
251 if (!accel_state->timestamp)
252 accel_state->timestamp = iio_get_time_ns(indio_dev);
253
212 hid_sensor_push_data(indio_dev, 254 hid_sensor_push_data(indio_dev,
213 accel_state->accel_val, 255 accel_state->accel_val,
214 sizeof(accel_state->accel_val)); 256 sizeof(accel_state->accel_val),
257 accel_state->timestamp);
258
259 accel_state->timestamp = 0;
260 }
215 261
216 return 0; 262 return 0;
217} 263}
@@ -236,6 +282,12 @@ static int accel_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
236 *(u32 *)raw_data; 282 *(u32 *)raw_data;
237 ret = 0; 283 ret = 0;
238 break; 284 break;
285 case HID_USAGE_SENSOR_TIME_TIMESTAMP:
286 accel_state->timestamp =
287 hid_sensor_convert_timestamp(
288 &accel_state->common_attributes,
289 *(int64_t *)raw_data);
290 break;
239 default: 291 default:
240 break; 292 break;
241 } 293 }
@@ -272,7 +324,7 @@ static int accel_3d_parse_report(struct platform_device *pdev,
272 st->accel[2].index, st->accel[2].report_id); 324 st->accel[2].index, st->accel[2].report_id);
273 325
274 st->scale_precision = hid_sensor_format_scale( 326 st->scale_precision = hid_sensor_format_scale(
275 HID_USAGE_SENSOR_ACCEL_3D, 327 hsdev->usage,
276 &st->accel[CHANNEL_SCAN_INDEX_X], 328 &st->accel[CHANNEL_SCAN_INDEX_X],
277 &st->scale_pre_decml, &st->scale_post_decml); 329 &st->scale_pre_decml, &st->scale_post_decml);
278 330
@@ -295,9 +347,12 @@ static int accel_3d_parse_report(struct platform_device *pdev,
295static int hid_accel_3d_probe(struct platform_device *pdev) 347static int hid_accel_3d_probe(struct platform_device *pdev)
296{ 348{
297 int ret = 0; 349 int ret = 0;
298 static const char *name = "accel_3d"; 350 static const char *name;
299 struct iio_dev *indio_dev; 351 struct iio_dev *indio_dev;
300 struct accel_3d_state *accel_state; 352 struct accel_3d_state *accel_state;
353 const struct iio_chan_spec *channel_spec;
354 int channel_size;
355
301 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 356 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
302 357
303 indio_dev = devm_iio_device_alloc(&pdev->dev, 358 indio_dev = devm_iio_device_alloc(&pdev->dev,
@@ -311,24 +366,30 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
311 accel_state->common_attributes.hsdev = hsdev; 366 accel_state->common_attributes.hsdev = hsdev;
312 accel_state->common_attributes.pdev = pdev; 367 accel_state->common_attributes.pdev = pdev;
313 368
314 ret = hid_sensor_parse_common_attributes(hsdev, 369 if (hsdev->usage == HID_USAGE_SENSOR_ACCEL_3D) {
315 HID_USAGE_SENSOR_ACCEL_3D, 370 name = "accel_3d";
371 channel_spec = accel_3d_channels;
372 channel_size = sizeof(accel_3d_channels);
373 } else {
374 name = "gravity";
375 channel_spec = gravity_channels;
376 channel_size = sizeof(gravity_channels);
377 }
378 ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
316 &accel_state->common_attributes); 379 &accel_state->common_attributes);
317 if (ret) { 380 if (ret) {
318 dev_err(&pdev->dev, "failed to setup common attributes\n"); 381 dev_err(&pdev->dev, "failed to setup common attributes\n");
319 return ret; 382 return ret;
320 } 383 }
384 indio_dev->channels = kmemdup(channel_spec, channel_size, GFP_KERNEL);
321 385
322 indio_dev->channels = kmemdup(accel_3d_channels,
323 sizeof(accel_3d_channels), GFP_KERNEL);
324 if (!indio_dev->channels) { 386 if (!indio_dev->channels) {
325 dev_err(&pdev->dev, "failed to duplicate channels\n"); 387 dev_err(&pdev->dev, "failed to duplicate channels\n");
326 return -ENOMEM; 388 return -ENOMEM;
327 } 389 }
328
329 ret = accel_3d_parse_report(pdev, hsdev, 390 ret = accel_3d_parse_report(pdev, hsdev,
330 (struct iio_chan_spec *)indio_dev->channels, 391 (struct iio_chan_spec *)indio_dev->channels,
331 HID_USAGE_SENSOR_ACCEL_3D, accel_state); 392 hsdev->usage, accel_state);
332 if (ret) { 393 if (ret) {
333 dev_err(&pdev->dev, "failed to setup attributes\n"); 394 dev_err(&pdev->dev, "failed to setup attributes\n");
334 goto error_free_dev_mem; 395 goto error_free_dev_mem;
@@ -363,7 +424,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
363 accel_state->callbacks.send_event = accel_3d_proc_event; 424 accel_state->callbacks.send_event = accel_3d_proc_event;
364 accel_state->callbacks.capture_sample = accel_3d_capture_sample; 425 accel_state->callbacks.capture_sample = accel_3d_capture_sample;
365 accel_state->callbacks.pdev = pdev; 426 accel_state->callbacks.pdev = pdev;
366 ret = sensor_hub_register_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D, 427 ret = sensor_hub_register_callback(hsdev, hsdev->usage,
367 &accel_state->callbacks); 428 &accel_state->callbacks);
368 if (ret < 0) { 429 if (ret < 0) {
369 dev_err(&pdev->dev, "callback reg failed\n"); 430 dev_err(&pdev->dev, "callback reg failed\n");
@@ -390,7 +451,7 @@ static int hid_accel_3d_remove(struct platform_device *pdev)
390 struct iio_dev *indio_dev = platform_get_drvdata(pdev); 451 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
391 struct accel_3d_state *accel_state = iio_priv(indio_dev); 452 struct accel_3d_state *accel_state = iio_priv(indio_dev);
392 453
393 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D); 454 sensor_hub_remove_callback(hsdev, hsdev->usage);
394 iio_device_unregister(indio_dev); 455 iio_device_unregister(indio_dev);
395 hid_sensor_remove_trigger(&accel_state->common_attributes); 456 hid_sensor_remove_trigger(&accel_state->common_attributes);
396 iio_triggered_buffer_cleanup(indio_dev); 457 iio_triggered_buffer_cleanup(indio_dev);
@@ -404,6 +465,9 @@ static const struct platform_device_id hid_accel_3d_ids[] = {
404 /* Format: HID-SENSOR-usage_id_in_hex_lowercase */ 465 /* Format: HID-SENSOR-usage_id_in_hex_lowercase */
405 .name = "HID-SENSOR-200073", 466 .name = "HID-SENSOR-200073",
406 }, 467 },
468 { /* gravity sensor */
469 .name = "HID-SENSOR-20007b",
470 },
407 { /* sentinel */ } 471 { /* sentinel */ }
408}; 472};
409MODULE_DEVICE_TABLE(platform, hid_accel_3d_ids); 473MODULE_DEVICE_TABLE(platform, hid_accel_3d_ids);
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index f418c588af6a..eb6e3dc789b2 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -248,7 +248,7 @@ static int mma8452_get_int_plus_micros_index(const int (*vals)[2], int n,
248 return -EINVAL; 248 return -EINVAL;
249} 249}
250 250
251static int mma8452_get_odr_index(struct mma8452_data *data) 251static unsigned int mma8452_get_odr_index(struct mma8452_data *data)
252{ 252{
253 return (data->ctrl_reg1 & MMA8452_CTRL_DR_MASK) >> 253 return (data->ctrl_reg1 & MMA8452_CTRL_DR_MASK) >>
254 MMA8452_CTRL_DR_SHIFT; 254 MMA8452_CTRL_DR_SHIFT;
@@ -260,7 +260,7 @@ static const int mma8452_samp_freq[8][2] = {
260}; 260};
261 261
262/* Datasheet table: step time "Relationship with the ODR" (sample frequency) */ 262/* Datasheet table: step time "Relationship with the ODR" (sample frequency) */
263static const int mma8452_transient_time_step_us[4][8] = { 263static const unsigned int mma8452_transient_time_step_us[4][8] = {
264 { 1250, 2500, 5000, 10000, 20000, 20000, 20000, 20000 }, /* normal */ 264 { 1250, 2500, 5000, 10000, 20000, 20000, 20000, 20000 }, /* normal */
265 { 1250, 2500, 5000, 10000, 20000, 80000, 80000, 80000 }, /* l p l n */ 265 { 1250, 2500, 5000, 10000, 20000, 80000, 80000, 80000 }, /* l p l n */
266 { 1250, 2500, 2500, 2500, 2500, 2500, 2500, 2500 }, /* high res*/ 266 { 1250, 2500, 2500, 2500, 2500, 2500, 2500, 2500 }, /* high res*/
diff --git a/drivers/iio/accel/ssp_accel_sensor.c b/drivers/iio/accel/ssp_accel_sensor.c
index 31db00970fa0..dd6ece8f9239 100644
--- a/drivers/iio/accel/ssp_accel_sensor.c
+++ b/drivers/iio/accel/ssp_accel_sensor.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/iio/common/ssp_sensors.h> 16#include <linux/iio/common/ssp_sensors.h>
17#include <linux/iio/iio.h> 17#include <linux/iio/iio.h>
18#include <linux/iio/buffer.h>
18#include <linux/iio/kfifo_buf.h> 19#include <linux/iio/kfifo_buf.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
@@ -135,7 +136,7 @@ static int ssp_accel_probe(struct platform_device *pdev)
135 136
136 platform_set_drvdata(pdev, indio_dev); 137 platform_set_drvdata(pdev, indio_dev);
137 138
138 ret = iio_device_register(indio_dev); 139 ret = devm_iio_device_register(&pdev->dev, indio_dev);
139 if (ret < 0) 140 if (ret < 0)
140 return ret; 141 return ret;
141 142
@@ -145,21 +146,11 @@ static int ssp_accel_probe(struct platform_device *pdev)
145 return 0; 146 return 0;
146} 147}
147 148
148static int ssp_accel_remove(struct platform_device *pdev)
149{
150 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
151
152 iio_device_unregister(indio_dev);
153
154 return 0;
155}
156
157static struct platform_driver ssp_accel_driver = { 149static struct platform_driver ssp_accel_driver = {
158 .driver = { 150 .driver = {
159 .name = SSP_ACCEL_NAME, 151 .name = SSP_ACCEL_NAME,
160 }, 152 },
161 .probe = ssp_accel_probe, 153 .probe = ssp_accel_probe,
162 .remove = ssp_accel_remove,
163}; 154};
164 155
165module_platform_driver(ssp_accel_driver); 156module_platform_driver(ssp_accel_driver);
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index 7c231687109a..3ad44ce7ae82 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -14,6 +14,24 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/iio/common/st_sensors.h> 15#include <linux/iio/common/st_sensors.h>
16 16
17enum st_accel_type {
18 LSM303DLH,
19 LSM303DLHC,
20 LIS3DH,
21 LSM330D,
22 LSM330DL,
23 LSM330DLC,
24 LIS331DLH,
25 LSM303DL,
26 LSM303DLM,
27 LSM330,
28 LSM303AGR,
29 LIS2DH12,
30 LIS3L02DQ,
31 LNG2DM,
32 ST_ACCEL_MAX,
33};
34
17#define H3LIS331DL_DRIVER_NAME "h3lis331dl_accel" 35#define H3LIS331DL_DRIVER_NAME "h3lis331dl_accel"
18#define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel" 36#define LIS3LV02DL_ACCEL_DEV_NAME "lis3lv02dl_accel"
19#define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel" 37#define LSM303DLHC_ACCEL_DEV_NAME "lsm303dlhc_accel"
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index c0f8867aa1ea..543f0ad7fd7e 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/acpi.h>
14#include <linux/i2c.h> 15#include <linux/i2c.h>
15#include <linux/iio/iio.h> 16#include <linux/iio/iio.h>
16 17
@@ -21,6 +22,11 @@
21#ifdef CONFIG_OF 22#ifdef CONFIG_OF
22static const struct of_device_id st_accel_of_match[] = { 23static const struct of_device_id st_accel_of_match[] = {
23 { 24 {
25 /* An older compatible */
26 .compatible = "st,lis3lv02d",
27 .data = LIS3LV02DL_ACCEL_DEV_NAME,
28 },
29 {
24 .compatible = "st,lis3lv02dl-accel", 30 .compatible = "st,lis3lv02dl-accel",
25 .data = LIS3LV02DL_ACCEL_DEV_NAME, 31 .data = LIS3LV02DL_ACCEL_DEV_NAME,
26 }, 32 },
@@ -95,25 +101,67 @@ MODULE_DEVICE_TABLE(of, st_accel_of_match);
95#define st_accel_of_match NULL 101#define st_accel_of_match NULL
96#endif 102#endif
97 103
104#ifdef CONFIG_ACPI
105static const struct acpi_device_id st_accel_acpi_match[] = {
106 {"SMO8A90", LNG2DM},
107 { },
108};
109MODULE_DEVICE_TABLE(acpi, st_accel_acpi_match);
110#else
111#define st_accel_acpi_match NULL
112#endif
113
114static const struct i2c_device_id st_accel_id_table[] = {
115 { LSM303DLH_ACCEL_DEV_NAME, LSM303DLH },
116 { LSM303DLHC_ACCEL_DEV_NAME, LSM303DLHC },
117 { LIS3DH_ACCEL_DEV_NAME, LIS3DH },
118 { LSM330D_ACCEL_DEV_NAME, LSM330D },
119 { LSM330DL_ACCEL_DEV_NAME, LSM330DL },
120 { LSM330DLC_ACCEL_DEV_NAME, LSM330DLC },
121 { LIS331DLH_ACCEL_DEV_NAME, LIS331DLH },
122 { LSM303DL_ACCEL_DEV_NAME, LSM303DL },
123 { LSM303DLM_ACCEL_DEV_NAME, LSM303DLM },
124 { LSM330_ACCEL_DEV_NAME, LSM330 },
125 { LSM303AGR_ACCEL_DEV_NAME, LSM303AGR },
126 { LIS2DH12_ACCEL_DEV_NAME, LIS2DH12 },
127 { LIS3L02DQ_ACCEL_DEV_NAME, LIS3L02DQ },
128 { LNG2DM_ACCEL_DEV_NAME, LNG2DM },
129 {},
130};
131MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
132
98static int st_accel_i2c_probe(struct i2c_client *client, 133static int st_accel_i2c_probe(struct i2c_client *client,
99 const struct i2c_device_id *id) 134 const struct i2c_device_id *id)
100{ 135{
101 struct iio_dev *indio_dev; 136 struct iio_dev *indio_dev;
102 struct st_sensor_data *adata; 137 struct st_sensor_data *adata;
103 int err; 138 int ret;
104 139
105 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata)); 140 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*adata));
106 if (!indio_dev) 141 if (!indio_dev)
107 return -ENOMEM; 142 return -ENOMEM;
108 143
109 adata = iio_priv(indio_dev); 144 adata = iio_priv(indio_dev);
110 st_sensors_of_i2c_probe(client, st_accel_of_match); 145
146 if (client->dev.of_node) {
147 st_sensors_of_i2c_probe(client, st_accel_of_match);
148 } else if (ACPI_HANDLE(&client->dev)) {
149 ret = st_sensors_match_acpi_device(&client->dev);
150 if ((ret < 0) || (ret >= ST_ACCEL_MAX))
151 return -ENODEV;
152
153 strncpy(client->name, st_accel_id_table[ret].name,
154 sizeof(client->name));
155 client->name[sizeof(client->name) - 1] = '\0';
156 } else if (!id)
157 return -ENODEV;
158
111 159
112 st_sensors_i2c_configure(indio_dev, client, adata); 160 st_sensors_i2c_configure(indio_dev, client, adata);
113 161
114 err = st_accel_common_probe(indio_dev); 162 ret = st_accel_common_probe(indio_dev);
115 if (err < 0) 163 if (ret < 0)
116 return err; 164 return ret;
117 165
118 return 0; 166 return 0;
119} 167}
@@ -125,29 +173,11 @@ static int st_accel_i2c_remove(struct i2c_client *client)
125 return 0; 173 return 0;
126} 174}
127 175
128static const struct i2c_device_id st_accel_id_table[] = {
129 { LSM303DLH_ACCEL_DEV_NAME },
130 { LSM303DLHC_ACCEL_DEV_NAME },
131 { LIS3DH_ACCEL_DEV_NAME },
132 { LSM330D_ACCEL_DEV_NAME },
133 { LSM330DL_ACCEL_DEV_NAME },
134 { LSM330DLC_ACCEL_DEV_NAME },
135 { LIS331DLH_ACCEL_DEV_NAME },
136 { LSM303DL_ACCEL_DEV_NAME },
137 { LSM303DLM_ACCEL_DEV_NAME },
138 { LSM330_ACCEL_DEV_NAME },
139 { LSM303AGR_ACCEL_DEV_NAME },
140 { LIS2DH12_ACCEL_DEV_NAME },
141 { LIS3L02DQ_ACCEL_DEV_NAME },
142 { LNG2DM_ACCEL_DEV_NAME },
143 {},
144};
145MODULE_DEVICE_TABLE(i2c, st_accel_id_table);
146
147static struct i2c_driver st_accel_driver = { 176static struct i2c_driver st_accel_driver = {
148 .driver = { 177 .driver = {
149 .name = "st-accel-i2c", 178 .name = "st-accel-i2c",
150 .of_match_table = of_match_ptr(st_accel_of_match), 179 .of_match_table = of_match_ptr(st_accel_of_match),
180 .acpi_match_table = ACPI_PTR(st_accel_acpi_match),
151 }, 181 },
152 .probe = st_accel_i2c_probe, 182 .probe = st_accel_i2c_probe,
153 .remove = st_accel_i2c_remove, 183 .remove = st_accel_i2c_remove,
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index c25ac50d4600..29a15f27a51b 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -65,9 +65,18 @@ static const struct spi_device_id st_accel_id_table[] = {
65}; 65};
66MODULE_DEVICE_TABLE(spi, st_accel_id_table); 66MODULE_DEVICE_TABLE(spi, st_accel_id_table);
67 67
68#ifdef CONFIG_OF
69static const struct of_device_id lis302dl_spi_dt_ids[] = {
70 { .compatible = "st,lis302dl-spi" },
71 {}
72};
73MODULE_DEVICE_TABLE(of, lis302dl_spi_dt_ids);
74#endif
75
68static struct spi_driver st_accel_driver = { 76static struct spi_driver st_accel_driver = {
69 .driver = { 77 .driver = {
70 .name = "st-accel-spi", 78 .name = "st-accel-spi",
79 .of_match_table = of_match_ptr(lis302dl_spi_dt_ids),
71 }, 80 },
72 .probe = st_accel_spi_probe, 81 .probe = st_accel_spi_probe,
73 .remove = st_accel_spi_remove, 82 .remove = st_accel_spi_remove,
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 9c8b558ba19e..dedae7adbce9 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -247,6 +247,25 @@ config HI8435
247 This driver can also be built as a module. If so, the module will be 247 This driver can also be built as a module. If so, the module will be
248 called hi8435. 248 called hi8435.
249 249
250config HX711
251 tristate "AVIA HX711 ADC for weight cells"
252 depends on GPIOLIB
253 help
254 If you say yes here you get support for AVIA HX711 ADC which is used
255 for weigh cells
256
257 This driver uses two GPIOs, one acts as the clock and controls the
258 channel selection and gain, the other one is used for the measurement
259 data
260
261 Currently the raw value is read from the chip and delivered.
262 To get an actual weight one needs to subtract the
263 zero offset and multiply by a scale factor.
264 This should be done in userspace.
265
266 This driver can also be built as a module. If so, the module will be
267 called hx711.
268
250config INA2XX_ADC 269config INA2XX_ADC
251 tristate "Texas Instruments INA2xx Power Monitors IIO driver" 270 tristate "Texas Instruments INA2xx Power Monitors IIO driver"
252 depends on I2C && !SENSORS_INA2XX 271 depends on I2C && !SENSORS_INA2XX
@@ -307,6 +326,15 @@ config MAX1027
307 To compile this driver as a module, choose M here: the module will be 326 To compile this driver as a module, choose M here: the module will be
308 called max1027. 327 called max1027.
309 328
329config MAX11100
330 tristate "Maxim max11100 ADC driver"
331 depends on SPI_MASTER
332 help
333 Say yes here to build support for Maxim max11100 SPI ADC
334
335 To compile this driver as a module, choose M here: the module will be
336 called max11100.
337
310config MAX1363 338config MAX1363
311 tristate "Maxim max1363 ADC driver" 339 tristate "Maxim max1363 ADC driver"
312 depends on I2C 340 depends on I2C
@@ -371,6 +399,18 @@ config MEN_Z188_ADC
371 This driver can also be built as a module. If so, the module will be 399 This driver can also be built as a module. If so, the module will be
372 called men_z188_adc. 400 called men_z188_adc.
373 401
402config MESON_SARADC
403 tristate "Amlogic Meson SAR ADC driver"
404 default ARCH_MESON
405 depends on OF && COMMON_CLK && (ARCH_MESON || COMPILE_TEST)
406 select REGMAP_MMIO
407 help
408 Say yes here to build support for the SAR ADC found in Amlogic Meson
409 SoCs.
410
411 To compile this driver as a module, choose M here: the
412 module will be called meson_saradc.
413
374config MXS_LRADC 414config MXS_LRADC
375 tristate "Freescale i.MX23/i.MX28 LRADC" 415 tristate "Freescale i.MX23/i.MX28 LRADC"
376 depends on (ARCH_MXS || COMPILE_TEST) && HAS_IOMEM 416 depends on (ARCH_MXS || COMPILE_TEST) && HAS_IOMEM
@@ -430,6 +470,19 @@ config QCOM_SPMI_VADC
430 To compile this driver as a module, choose M here: the module will 470 To compile this driver as a module, choose M here: the module will
431 be called qcom-spmi-vadc. 471 be called qcom-spmi-vadc.
432 472
473config RCAR_GYRO_ADC
474 tristate "Renesas R-Car GyroADC driver"
475 depends on ARCH_RCAR_GEN2 || (ARM && COMPILE_TEST)
476 help
477 Say yes here to build support for the GyroADC found in Renesas
478 R-Car Gen2 SoCs. This block is a simple SPI offload engine for
479 reading data out of attached compatible ADCs in a round-robin
480 fashion. Up to 4 or 8 ADC channels are supported by this block,
481 depending on which ADCs are attached.
482
483 To compile this driver as a module, choose M here: the
484 module will be called rcar-gyroadc.
485
433config ROCKCHIP_SARADC 486config ROCKCHIP_SARADC
434 tristate "Rockchip SARADC driver" 487 tristate "Rockchip SARADC driver"
435 depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST) 488 depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST)
@@ -444,8 +497,13 @@ config ROCKCHIP_SARADC
444config STM32_ADC_CORE 497config STM32_ADC_CORE
445 tristate "STMicroelectronics STM32 adc core" 498 tristate "STMicroelectronics STM32 adc core"
446 depends on ARCH_STM32 || COMPILE_TEST 499 depends on ARCH_STM32 || COMPILE_TEST
500 depends on HAS_DMA
447 depends on OF 501 depends on OF
448 depends on REGULATOR 502 depends on REGULATOR
503 select IIO_BUFFER
504 select MFD_STM32_TIMERS
505 select IIO_STM32_TIMER_TRIGGER
506 select IIO_TRIGGERED_BUFFER
449 help 507 help
450 Select this option to enable the core driver for STMicroelectronics 508 Select this option to enable the core driver for STMicroelectronics
451 STM32 analog-to-digital converter (ADC). 509 STM32 analog-to-digital converter (ADC).
@@ -549,6 +607,19 @@ config TI_ADS1015
549 This driver can also be built as a module. If so, the module will be 607 This driver can also be built as a module. If so, the module will be
550 called ti-ads1015. 608 called ti-ads1015.
551 609
610config TI_ADS7950
611 tristate "Texas Instruments ADS7950 ADC driver"
612 depends on SPI
613 select IIO_BUFFER
614 select IIO_TRIGGERED_BUFFER
615 help
616 Say yes here to build support for Texas Instruments ADS7950, ADS7951,
617 ADS7952, ADS7953, ADS7954, ADS7955, ADS7956, ADS7957, ADS7958, ADS7959.
618 ADS7960, ADS7961.
619
620 To compile this driver as a module, choose M here: the
621 module will be called ti-ads7950.
622
552config TI_ADS8688 623config TI_ADS8688
553 tristate "Texas Instruments ADS8688" 624 tristate "Texas Instruments ADS8688"
554 depends on SPI && OF 625 depends on SPI && OF
@@ -571,6 +642,18 @@ config TI_AM335X_ADC
571 To compile this driver as a module, choose M here: the module will be 642 To compile this driver as a module, choose M here: the module will be
572 called ti_am335x_adc. 643 called ti_am335x_adc.
573 644
645config TI_TLC4541
646 tristate "Texas Instruments TLC4541 ADC driver"
647 depends on SPI
648 select IIO_BUFFER
649 select IIO_TRIGGERED_BUFFER
650 help
651 Say yes here to build support for Texas Instruments TLC4541 / TLC3541
652 ADC chips.
653
654 This driver can also be built as a module. If so, the module will be
655 called ti-tlc4541.
656
574config TWL4030_MADC 657config TWL4030_MADC
575 tristate "TWL4030 MADC (Monitoring A/D Converter)" 658 tristate "TWL4030 MADC (Monitoring A/D Converter)"
576 depends on TWL4030_CORE 659 depends on TWL4030_CORE
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index d36c4be8d1fc..d0012620cd1c 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -25,22 +25,26 @@ obj-$(CONFIG_ENVELOPE_DETECTOR) += envelope-detector.o
25obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o 25obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
26obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o 26obj-$(CONFIG_FSL_MX25_ADC) += fsl-imx25-gcq.o
27obj-$(CONFIG_HI8435) += hi8435.o 27obj-$(CONFIG_HI8435) += hi8435.o
28obj-$(CONFIG_HX711) += hx711.o
28obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o 29obj-$(CONFIG_IMX7D_ADC) += imx7d_adc.o
29obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o 30obj-$(CONFIG_INA2XX_ADC) += ina2xx-adc.o
30obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o 31obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
31obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o 32obj-$(CONFIG_LPC18XX_ADC) += lpc18xx_adc.o
32obj-$(CONFIG_LTC2485) += ltc2485.o 33obj-$(CONFIG_LTC2485) += ltc2485.o
33obj-$(CONFIG_MAX1027) += max1027.o 34obj-$(CONFIG_MAX1027) += max1027.o
35obj-$(CONFIG_MAX11100) += max11100.o
34obj-$(CONFIG_MAX1363) += max1363.o 36obj-$(CONFIG_MAX1363) += max1363.o
35obj-$(CONFIG_MCP320X) += mcp320x.o 37obj-$(CONFIG_MCP320X) += mcp320x.o
36obj-$(CONFIG_MCP3422) += mcp3422.o 38obj-$(CONFIG_MCP3422) += mcp3422.o
37obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o 39obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
38obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o 40obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
41obj-$(CONFIG_MESON_SARADC) += meson_saradc.o
39obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o 42obj-$(CONFIG_MXS_LRADC) += mxs-lradc.o
40obj-$(CONFIG_NAU7802) += nau7802.o 43obj-$(CONFIG_NAU7802) += nau7802.o
41obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o 44obj-$(CONFIG_PALMAS_GPADC) += palmas_gpadc.o
42obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o 45obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
43obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o 46obj-$(CONFIG_QCOM_SPMI_VADC) += qcom-spmi-vadc.o
47obj-$(CONFIG_RCAR_GYRO_ADC) += rcar-gyroadc.o
44obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o 48obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
45obj-$(CONFIG_STX104) += stx104.o 49obj-$(CONFIG_STX104) += stx104.o
46obj-$(CONFIG_STM32_ADC_CORE) += stm32-adc-core.o 50obj-$(CONFIG_STM32_ADC_CORE) += stm32-adc-core.o
@@ -51,8 +55,10 @@ obj-$(CONFIG_TI_ADC12138) += ti-adc12138.o
51obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o 55obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
52obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o 56obj-$(CONFIG_TI_ADC161S626) += ti-adc161s626.o
53obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o 57obj-$(CONFIG_TI_ADS1015) += ti-ads1015.o
58obj-$(CONFIG_TI_ADS7950) += ti-ads7950.o
54obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o 59obj-$(CONFIG_TI_ADS8688) += ti-ads8688.o
55obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o 60obj-$(CONFIG_TI_AM335X_ADC) += ti_am335x_adc.o
61obj-$(CONFIG_TI_TLC4541) += ti-tlc4541.o
56obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o 62obj-$(CONFIG_TWL4030_MADC) += twl4030-madc.o
57obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o 63obj-$(CONFIG_TWL6030_GPADC) += twl6030-gpadc.o
58obj-$(CONFIG_VF610_ADC) += vf610_adc.o 64obj-$(CONFIG_VF610_ADC) += vf610_adc.o
diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c
index 7fd24949c0c1..64799ad7ebad 100644
--- a/drivers/iio/adc/axp288_adc.c
+++ b/drivers/iio/adc/axp288_adc.c
@@ -28,8 +28,6 @@
28#include <linux/iio/driver.h> 28#include <linux/iio/driver.h>
29 29
30#define AXP288_ADC_EN_MASK 0xF1 30#define AXP288_ADC_EN_MASK 0xF1
31#define AXP288_ADC_TS_PIN_GPADC 0xF2
32#define AXP288_ADC_TS_PIN_ON 0xF3
33 31
34enum axp288_adc_id { 32enum axp288_adc_id {
35 AXP288_ADC_TS, 33 AXP288_ADC_TS,
@@ -123,16 +121,6 @@ static int axp288_adc_read_channel(int *val, unsigned long address,
123 return IIO_VAL_INT; 121 return IIO_VAL_INT;
124} 122}
125 123
126static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode,
127 unsigned long address)
128{
129 /* channels other than GPADC do not need to switch TS pin */
130 if (address != AXP288_GP_ADC_H)
131 return 0;
132
133 return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
134}
135
136static int axp288_adc_read_raw(struct iio_dev *indio_dev, 124static int axp288_adc_read_raw(struct iio_dev *indio_dev,
137 struct iio_chan_spec const *chan, 125 struct iio_chan_spec const *chan,
138 int *val, int *val2, long mask) 126 int *val, int *val2, long mask)
@@ -143,16 +131,7 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
143 mutex_lock(&indio_dev->mlock); 131 mutex_lock(&indio_dev->mlock);
144 switch (mask) { 132 switch (mask) {
145 case IIO_CHAN_INFO_RAW: 133 case IIO_CHAN_INFO_RAW:
146 if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC,
147 chan->address)) {
148 dev_err(&indio_dev->dev, "GPADC mode\n");
149 ret = -EINVAL;
150 break;
151 }
152 ret = axp288_adc_read_channel(val, chan->address, info->regmap); 134 ret = axp288_adc_read_channel(val, chan->address, info->regmap);
153 if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON,
154 chan->address))
155 dev_err(&indio_dev->dev, "TS pin restore\n");
156 break; 135 break;
157 default: 136 default:
158 ret = -EINVAL; 137 ret = -EINVAL;
@@ -162,15 +141,6 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
162 return ret; 141 return ret;
163} 142}
164 143
165static int axp288_adc_set_state(struct regmap *regmap)
166{
167 /* ADC should be always enabled for internal FG to function */
168 if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON))
169 return -EIO;
170
171 return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
172}
173
174static const struct iio_info axp288_adc_iio_info = { 144static const struct iio_info axp288_adc_iio_info = {
175 .read_raw = &axp288_adc_read_raw, 145 .read_raw = &axp288_adc_read_raw,
176 .driver_module = THIS_MODULE, 146 .driver_module = THIS_MODULE,
@@ -199,7 +169,7 @@ static int axp288_adc_probe(struct platform_device *pdev)
199 * Set ADC to enabled state at all time, including system suspend. 169 * Set ADC to enabled state at all time, including system suspend.
200 * otherwise internal fuel gauge functionality may be affected. 170 * otherwise internal fuel gauge functionality may be affected.
201 */ 171 */
202 ret = axp288_adc_set_state(axp20x->regmap); 172 ret = regmap_write(info->regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
203 if (ret) { 173 if (ret) {
204 dev_err(&pdev->dev, "unable to enable ADC device\n"); 174 dev_err(&pdev->dev, "unable to enable ADC device\n");
205 return ret; 175 return ret;
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index c15756d7bf7f..ad1775b5f83c 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -632,7 +632,7 @@ static irqreturn_t exynos_ts_isr(int irq, void *dev_id)
632 input_report_key(info->input, BTN_TOUCH, 1); 632 input_report_key(info->input, BTN_TOUCH, 1);
633 input_sync(info->input); 633 input_sync(info->input);
634 634
635 msleep(1); 635 usleep_range(1000, 1100);
636 }; 636 };
637 637
638 writel(0, ADC_V1_CLRINTPNDNUP(info->regs)); 638 writel(0, ADC_V1_CLRINTPNDNUP(info->regs));
diff --git a/drivers/iio/adc/fsl-imx25-gcq.c b/drivers/iio/adc/fsl-imx25-gcq.c
index 72b32c1ab257..ea264fa9e567 100644
--- a/drivers/iio/adc/fsl-imx25-gcq.c
+++ b/drivers/iio/adc/fsl-imx25-gcq.c
@@ -401,6 +401,7 @@ static const struct of_device_id mx25_gcq_ids[] = {
401 { .compatible = "fsl,imx25-gcq", }, 401 { .compatible = "fsl,imx25-gcq", },
402 { /* Sentinel */ } 402 { /* Sentinel */ }
403}; 403};
404MODULE_DEVICE_TABLE(of, mx25_gcq_ids);
404 405
405static struct platform_driver mx25_gcq_driver = { 406static struct platform_driver mx25_gcq_driver = {
406 .driver = { 407 .driver = {
diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c
new file mode 100644
index 000000000000..139639f73769
--- /dev/null
+++ b/drivers/iio/adc/hx711.c
@@ -0,0 +1,532 @@
1/*
2 * HX711: analog to digital converter for weight sensor module
3 *
4 * Copyright (c) 2016 Andreas Klinger <ak@it-klinger.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16#include <linux/err.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/of.h>
20#include <linux/platform_device.h>
21#include <linux/property.h>
22#include <linux/slab.h>
23#include <linux/sched.h>
24#include <linux/delay.h>
25#include <linux/iio/iio.h>
26#include <linux/iio/sysfs.h>
27#include <linux/gpio/consumer.h>
28#include <linux/regulator/consumer.h>
29
30/* gain to pulse and scale conversion */
31#define HX711_GAIN_MAX 3
32
33struct hx711_gain_to_scale {
34 int gain;
35 int gain_pulse;
36 int scale;
37 int channel;
38};
39
40/*
41 * .scale depends on AVDD which in turn is known as soon as the regulator
42 * is available
43 * therefore we set .scale in hx711_probe()
44 *
45 * channel A in documentation is channel 0 in source code
46 * channel B in documentation is channel 1 in source code
47 */
48static struct hx711_gain_to_scale hx711_gain_to_scale[HX711_GAIN_MAX] = {
49 { 128, 1, 0, 0 },
50 { 32, 2, 0, 1 },
51 { 64, 3, 0, 0 }
52};
53
54static int hx711_get_gain_to_pulse(int gain)
55{
56 int i;
57
58 for (i = 0; i < HX711_GAIN_MAX; i++)
59 if (hx711_gain_to_scale[i].gain == gain)
60 return hx711_gain_to_scale[i].gain_pulse;
61 return 1;
62}
63
64static int hx711_get_gain_to_scale(int gain)
65{
66 int i;
67
68 for (i = 0; i < HX711_GAIN_MAX; i++)
69 if (hx711_gain_to_scale[i].gain == gain)
70 return hx711_gain_to_scale[i].scale;
71 return 0;
72}
73
74static int hx711_get_scale_to_gain(int scale)
75{
76 int i;
77
78 for (i = 0; i < HX711_GAIN_MAX; i++)
79 if (hx711_gain_to_scale[i].scale == scale)
80 return hx711_gain_to_scale[i].gain;
81 return -EINVAL;
82}
83
84struct hx711_data {
85 struct device *dev;
86 struct gpio_desc *gpiod_pd_sck;
87 struct gpio_desc *gpiod_dout;
88 struct regulator *reg_avdd;
89 int gain_set; /* gain set on device */
90 int gain_chan_a; /* gain for channel A */
91 struct mutex lock;
92};
93
94static int hx711_cycle(struct hx711_data *hx711_data)
95{
96 int val;
97
98 /*
99 * if preempted for more then 60us while PD_SCK is high:
100 * hx711 is going in reset
101 * ==> measuring is false
102 */
103 preempt_disable();
104 gpiod_set_value(hx711_data->gpiod_pd_sck, 1);
105 val = gpiod_get_value(hx711_data->gpiod_dout);
106 /*
107 * here we are not waiting for 0.2 us as suggested by the datasheet,
108 * because the oscilloscope showed in a test scenario
109 * at least 1.15 us for PD_SCK high (T3 in datasheet)
110 * and 0.56 us for PD_SCK low on TI Sitara with 800 MHz
111 */
112 gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
113 preempt_enable();
114
115 return val;
116}
117
118static int hx711_read(struct hx711_data *hx711_data)
119{
120 int i, ret;
121 int value = 0;
122 int val = gpiod_get_value(hx711_data->gpiod_dout);
123
124 /* we double check if it's really down */
125 if (val)
126 return -EIO;
127
128 for (i = 0; i < 24; i++) {
129 value <<= 1;
130 ret = hx711_cycle(hx711_data);
131 if (ret)
132 value++;
133 }
134
135 value ^= 0x800000;
136
137 for (i = 0; i < hx711_get_gain_to_pulse(hx711_data->gain_set); i++)
138 hx711_cycle(hx711_data);
139
140 return value;
141}
142
143static int hx711_wait_for_ready(struct hx711_data *hx711_data)
144{
145 int i, val;
146
147 /*
148 * a maximum reset cycle time of 56 ms was measured.
149 * we round it up to 100 ms
150 */
151 for (i = 0; i < 100; i++) {
152 val = gpiod_get_value(hx711_data->gpiod_dout);
153 if (!val)
154 break;
155 /* sleep at least 1 ms */
156 msleep(1);
157 }
158 if (val)
159 return -EIO;
160
161 return 0;
162}
163
164static int hx711_reset(struct hx711_data *hx711_data)
165{
166 int ret;
167 int val = gpiod_get_value(hx711_data->gpiod_dout);
168
169 if (val) {
170 /*
171 * an examination with the oszilloscope indicated
172 * that the first value read after the reset is not stable
173 * if we reset too short;
174 * the shorter the reset cycle
175 * the less reliable the first value after reset is;
176 * there were no problems encountered with a value
177 * of 10 ms or higher
178 */
179 gpiod_set_value(hx711_data->gpiod_pd_sck, 1);
180 msleep(10);
181 gpiod_set_value(hx711_data->gpiod_pd_sck, 0);
182
183 ret = hx711_wait_for_ready(hx711_data);
184 if (ret)
185 return ret;
186 /*
187 * after a reset the gain is 128 so we do a dummy read
188 * to set the gain for the next read
189 */
190 ret = hx711_read(hx711_data);
191 if (ret < 0)
192 return ret;
193
194 /*
195 * after a dummy read we need to wait vor readiness
196 * for not mixing gain pulses with the clock
197 */
198 ret = hx711_wait_for_ready(hx711_data);
199 if (ret)
200 return ret;
201 }
202
203 return val;
204}
205
206static int hx711_set_gain_for_channel(struct hx711_data *hx711_data, int chan)
207{
208 int ret;
209
210 if (chan == 0) {
211 if (hx711_data->gain_set == 32) {
212 hx711_data->gain_set = hx711_data->gain_chan_a;
213
214 ret = hx711_read(hx711_data);
215 if (ret < 0)
216 return ret;
217
218 ret = hx711_wait_for_ready(hx711_data);
219 if (ret)
220 return ret;
221 }
222 } else {
223 if (hx711_data->gain_set != 32) {
224 hx711_data->gain_set = 32;
225
226 ret = hx711_read(hx711_data);
227 if (ret < 0)
228 return ret;
229
230 ret = hx711_wait_for_ready(hx711_data);
231 if (ret)
232 return ret;
233 }
234 }
235
236 return 0;
237}
238
239static int hx711_read_raw(struct iio_dev *indio_dev,
240 const struct iio_chan_spec *chan,
241 int *val, int *val2, long mask)
242{
243 struct hx711_data *hx711_data = iio_priv(indio_dev);
244 int ret;
245
246 switch (mask) {
247 case IIO_CHAN_INFO_RAW:
248 mutex_lock(&hx711_data->lock);
249
250 /*
251 * hx711_reset() must be called from here
252 * because it could be calling hx711_read() by itself
253 */
254 if (hx711_reset(hx711_data)) {
255 mutex_unlock(&hx711_data->lock);
256 dev_err(hx711_data->dev, "reset failed!");
257 return -EIO;
258 }
259
260 ret = hx711_set_gain_for_channel(hx711_data, chan->channel);
261 if (ret < 0) {
262 mutex_unlock(&hx711_data->lock);
263 return ret;
264 }
265
266 *val = hx711_read(hx711_data);
267
268 mutex_unlock(&hx711_data->lock);
269
270 if (*val < 0)
271 return *val;
272 return IIO_VAL_INT;
273 case IIO_CHAN_INFO_SCALE:
274 *val = 0;
275 mutex_lock(&hx711_data->lock);
276
277 *val2 = hx711_get_gain_to_scale(hx711_data->gain_set);
278
279 mutex_unlock(&hx711_data->lock);
280
281 return IIO_VAL_INT_PLUS_NANO;
282 default:
283 return -EINVAL;
284 }
285}
286
287static int hx711_write_raw(struct iio_dev *indio_dev,
288 struct iio_chan_spec const *chan,
289 int val,
290 int val2,
291 long mask)
292{
293 struct hx711_data *hx711_data = iio_priv(indio_dev);
294 int ret;
295 int gain;
296
297 switch (mask) {
298 case IIO_CHAN_INFO_SCALE:
299 /*
300 * a scale greater than 1 mV per LSB is not possible
301 * with the HX711, therefore val must be 0
302 */
303 if (val != 0)
304 return -EINVAL;
305
306 mutex_lock(&hx711_data->lock);
307
308 gain = hx711_get_scale_to_gain(val2);
309 if (gain < 0) {
310 mutex_unlock(&hx711_data->lock);
311 return gain;
312 }
313
314 if (gain != hx711_data->gain_set) {
315 hx711_data->gain_set = gain;
316 if (gain != 32)
317 hx711_data->gain_chan_a = gain;
318
319 ret = hx711_read(hx711_data);
320 if (ret < 0) {
321 mutex_unlock(&hx711_data->lock);
322 return ret;
323 }
324 }
325
326 mutex_unlock(&hx711_data->lock);
327 return 0;
328 default:
329 return -EINVAL;
330 }
331
332 return 0;
333}
334
335static int hx711_write_raw_get_fmt(struct iio_dev *indio_dev,
336 struct iio_chan_spec const *chan,
337 long mask)
338{
339 return IIO_VAL_INT_PLUS_NANO;
340}
341
342static ssize_t hx711_scale_available_show(struct device *dev,
343 struct device_attribute *attr,
344 char *buf)
345{
346 struct iio_dev_attr *iio_attr = to_iio_dev_attr(attr);
347 int channel = iio_attr->address;
348 int i, len = 0;
349
350 for (i = 0; i < HX711_GAIN_MAX; i++)
351 if (hx711_gain_to_scale[i].channel == channel)
352 len += sprintf(buf + len, "0.%09d ",
353 hx711_gain_to_scale[i].scale);
354
355 len += sprintf(buf + len, "\n");
356
357 return len;
358}
359
360static IIO_DEVICE_ATTR(in_voltage0_scale_available, S_IRUGO,
361 hx711_scale_available_show, NULL, 0);
362
363static IIO_DEVICE_ATTR(in_voltage1_scale_available, S_IRUGO,
364 hx711_scale_available_show, NULL, 1);
365
366static struct attribute *hx711_attributes[] = {
367 &iio_dev_attr_in_voltage0_scale_available.dev_attr.attr,
368 &iio_dev_attr_in_voltage1_scale_available.dev_attr.attr,
369 NULL,
370};
371
372static struct attribute_group hx711_attribute_group = {
373 .attrs = hx711_attributes,
374};
375
376static const struct iio_info hx711_iio_info = {
377 .driver_module = THIS_MODULE,
378 .read_raw = hx711_read_raw,
379 .write_raw = hx711_write_raw,
380 .write_raw_get_fmt = hx711_write_raw_get_fmt,
381 .attrs = &hx711_attribute_group,
382};
383
384static const struct iio_chan_spec hx711_chan_spec[] = {
385 {
386 .type = IIO_VOLTAGE,
387 .channel = 0,
388 .indexed = 1,
389 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
390 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
391 },
392 {
393 .type = IIO_VOLTAGE,
394 .channel = 1,
395 .indexed = 1,
396 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
397 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
398 },
399};
400
401static int hx711_probe(struct platform_device *pdev)
402{
403 struct device *dev = &pdev->dev;
404 struct hx711_data *hx711_data;
405 struct iio_dev *indio_dev;
406 int ret;
407 int i;
408
409 indio_dev = devm_iio_device_alloc(dev, sizeof(struct hx711_data));
410 if (!indio_dev) {
411 dev_err(dev, "failed to allocate IIO device\n");
412 return -ENOMEM;
413 }
414
415 hx711_data = iio_priv(indio_dev);
416 hx711_data->dev = dev;
417
418 mutex_init(&hx711_data->lock);
419
420 /*
421 * PD_SCK stands for power down and serial clock input of HX711
422 * in the driver it is an output
423 */
424 hx711_data->gpiod_pd_sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW);
425 if (IS_ERR(hx711_data->gpiod_pd_sck)) {
426 dev_err(dev, "failed to get sck-gpiod: err=%ld\n",
427 PTR_ERR(hx711_data->gpiod_pd_sck));
428 return PTR_ERR(hx711_data->gpiod_pd_sck);
429 }
430
431 /*
432 * DOUT stands for serial data output of HX711
433 * for the driver it is an input
434 */
435 hx711_data->gpiod_dout = devm_gpiod_get(dev, "dout", GPIOD_IN);
436 if (IS_ERR(hx711_data->gpiod_dout)) {
437 dev_err(dev, "failed to get dout-gpiod: err=%ld\n",
438 PTR_ERR(hx711_data->gpiod_dout));
439 return PTR_ERR(hx711_data->gpiod_dout);
440 }
441
442 hx711_data->reg_avdd = devm_regulator_get(dev, "avdd");
443 if (IS_ERR(hx711_data->reg_avdd))
444 return PTR_ERR(hx711_data->reg_avdd);
445
446 ret = regulator_enable(hx711_data->reg_avdd);
447 if (ret < 0)
448 return ret;
449
450 /*
451 * with
452 * full scale differential input range: AVDD / GAIN
453 * full scale output data: 2^24
454 * we can say:
455 * AVDD / GAIN = 2^24
456 * therefore:
457 * 1 LSB = AVDD / GAIN / 2^24
458 * AVDD is in uV, but we need 10^-9 mV
459 * approximately to fit into a 32 bit number:
460 * 1 LSB = (AVDD * 100) / GAIN / 1678 [10^-9 mV]
461 */
462 ret = regulator_get_voltage(hx711_data->reg_avdd);
463 if (ret < 0) {
464 regulator_disable(hx711_data->reg_avdd);
465 return ret;
466 }
467 /* we need 10^-9 mV */
468 ret *= 100;
469
470 for (i = 0; i < HX711_GAIN_MAX; i++)
471 hx711_gain_to_scale[i].scale =
472 ret / hx711_gain_to_scale[i].gain / 1678;
473
474 hx711_data->gain_set = 128;
475 hx711_data->gain_chan_a = 128;
476
477 platform_set_drvdata(pdev, indio_dev);
478
479 indio_dev->name = "hx711";
480 indio_dev->dev.parent = &pdev->dev;
481 indio_dev->info = &hx711_iio_info;
482 indio_dev->modes = INDIO_DIRECT_MODE;
483 indio_dev->channels = hx711_chan_spec;
484 indio_dev->num_channels = ARRAY_SIZE(hx711_chan_spec);
485
486 ret = iio_device_register(indio_dev);
487 if (ret < 0) {
488 dev_err(dev, "Couldn't register the device\n");
489 regulator_disable(hx711_data->reg_avdd);
490 }
491
492 return ret;
493}
494
495static int hx711_remove(struct platform_device *pdev)
496{
497 struct hx711_data *hx711_data;
498 struct iio_dev *indio_dev;
499
500 indio_dev = platform_get_drvdata(pdev);
501 hx711_data = iio_priv(indio_dev);
502
503 iio_device_unregister(indio_dev);
504
505 regulator_disable(hx711_data->reg_avdd);
506
507 return 0;
508}
509
510static const struct of_device_id of_hx711_match[] = {
511 { .compatible = "avia,hx711", },
512 {},
513};
514
515MODULE_DEVICE_TABLE(of, of_hx711_match);
516
517static struct platform_driver hx711_driver = {
518 .probe = hx711_probe,
519 .remove = hx711_remove,
520 .driver = {
521 .name = "hx711-gpio",
522 .of_match_table = of_hx711_match,
523 },
524};
525
526module_platform_driver(hx711_driver);
527
528MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");
529MODULE_DESCRIPTION("HX711 bitbanging driver - ADC for weight cells");
530MODULE_LICENSE("GPL");
531MODULE_ALIAS("platform:hx711-gpio");
532
diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c
index 59b7d76e1ad2..3263231276ca 100644
--- a/drivers/iio/adc/ina2xx-adc.c
+++ b/drivers/iio/adc/ina2xx-adc.c
@@ -22,6 +22,8 @@
22 22
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/iio/iio.h>
26#include <linux/iio/buffer.h>
25#include <linux/iio/kfifo_buf.h> 27#include <linux/iio/kfifo_buf.h>
26#include <linux/iio/sysfs.h> 28#include <linux/iio/sysfs.h>
27#include <linux/kthread.h> 29#include <linux/kthread.h>
diff --git a/drivers/iio/adc/max11100.c b/drivers/iio/adc/max11100.c
new file mode 100644
index 000000000000..a088cf99bfe1
--- /dev/null
+++ b/drivers/iio/adc/max11100.c
@@ -0,0 +1,181 @@
1/*
2 * iio/adc/max11100.c
3 * Maxim max11100 ADC Driver with IIO interface
4 *
5 * Copyright (C) 2016-17 Renesas Electronics Corporation
6 * Copyright (C) 2016-17 Jacopo Mondi
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 version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/delay.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/regulator/consumer.h>
16#include <linux/spi/spi.h>
17
18#include <linux/iio/iio.h>
19#include <linux/iio/driver.h>
20
21/*
22 * LSB is the ADC single digital step
23 * 1 LSB = (vref_mv / 2 ^ 16)
24 *
25 * LSB is used to calculate analog voltage value
26 * from the number of ADC steps count
27 *
28 * Ain = (count * LSB)
29 */
30#define MAX11100_LSB_DIV (1 << 16)
31
32struct max11100_state {
33 struct regulator *vref_reg;
34 struct spi_device *spi;
35
36 /*
37 * DMA (thus cache coherency maintenance) requires the
38 * transfer buffers to live in their own cache lines.
39 */
40 u8 buffer[3] ____cacheline_aligned;
41};
42
43static struct iio_chan_spec max11100_channels[] = {
44 { /* [0] */
45 .type = IIO_VOLTAGE,
46 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
47 BIT(IIO_CHAN_INFO_SCALE),
48 },
49};
50
51static int max11100_read_single(struct iio_dev *indio_dev, int *val)
52{
53 int ret;
54 struct max11100_state *state = iio_priv(indio_dev);
55
56 ret = spi_read(state->spi, state->buffer, sizeof(state->buffer));
57 if (ret) {
58 dev_err(&indio_dev->dev, "SPI transfer failed\n");
59 return ret;
60 }
61
62 /* the first 8 bits sent out from ADC must be 0s */
63 if (state->buffer[0]) {
64 dev_err(&indio_dev->dev, "Invalid value: buffer[0] != 0\n");
65 return -EINVAL;
66 }
67
68 *val = (state->buffer[1] << 8) | state->buffer[2];
69
70 return 0;
71}
72
73static int max11100_read_raw(struct iio_dev *indio_dev,
74 struct iio_chan_spec const *chan,
75 int *val, int *val2, long info)
76{
77 int ret, vref_uv;
78 struct max11100_state *state = iio_priv(indio_dev);
79
80 switch (info) {
81 case IIO_CHAN_INFO_RAW:
82 ret = max11100_read_single(indio_dev, val);
83 if (ret)
84 return ret;
85
86 return IIO_VAL_INT;
87
88 case IIO_CHAN_INFO_SCALE:
89 vref_uv = regulator_get_voltage(state->vref_reg);
90 if (vref_uv < 0)
91 /* dummy regulator "get_voltage" returns -EINVAL */
92 return -EINVAL;
93
94 *val = vref_uv / 1000;
95 *val2 = MAX11100_LSB_DIV;
96 return IIO_VAL_FRACTIONAL;
97 }
98
99 return -EINVAL;
100}
101
102static const struct iio_info max11100_info = {
103 .driver_module = THIS_MODULE,
104 .read_raw = max11100_read_raw,
105};
106
107static int max11100_probe(struct spi_device *spi)
108{
109 int ret;
110 struct iio_dev *indio_dev;
111 struct max11100_state *state;
112
113 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*state));
114 if (!indio_dev)
115 return -ENOMEM;
116
117 spi_set_drvdata(spi, indio_dev);
118
119 state = iio_priv(indio_dev);
120 state->spi = spi;
121
122 indio_dev->dev.parent = &spi->dev;
123 indio_dev->dev.of_node = spi->dev.of_node;
124 indio_dev->name = "max11100";
125 indio_dev->info = &max11100_info;
126 indio_dev->modes = INDIO_DIRECT_MODE;
127 indio_dev->channels = max11100_channels,
128 indio_dev->num_channels = ARRAY_SIZE(max11100_channels),
129
130 state->vref_reg = devm_regulator_get(&spi->dev, "vref");
131 if (IS_ERR(state->vref_reg))
132 return PTR_ERR(state->vref_reg);
133
134 ret = regulator_enable(state->vref_reg);
135 if (ret)
136 return ret;
137
138 ret = iio_device_register(indio_dev);
139 if (ret)
140 goto disable_regulator;
141
142 return 0;
143
144disable_regulator:
145 regulator_disable(state->vref_reg);
146
147 return ret;
148}
149
150static int max11100_remove(struct spi_device *spi)
151{
152 struct iio_dev *indio_dev = spi_get_drvdata(spi);
153 struct max11100_state *state = iio_priv(indio_dev);
154
155 iio_device_unregister(indio_dev);
156 regulator_disable(state->vref_reg);
157
158 return 0;
159}
160
161static const struct of_device_id max11100_ids[] = {
162 {.compatible = "maxim,max11100"},
163 { },
164};
165MODULE_DEVICE_TABLE(of, max11100_ids);
166
167static struct spi_driver max11100_driver = {
168 .driver = {
169 .name = "max11100",
170 .owner = THIS_MODULE,
171 .of_match_table = of_match_ptr(max11100_ids),
172 },
173 .probe = max11100_probe,
174 .remove = max11100_remove,
175};
176
177module_spi_driver(max11100_driver);
178
179MODULE_AUTHOR("Jacopo Mondi <jacopo@jmondi.org>");
180MODULE_DESCRIPTION("Maxim max11100 ADC Driver");
181MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c
index 841a13c9b6ea..c6c12feb4a08 100644
--- a/drivers/iio/adc/max1363.c
+++ b/drivers/iio/adc/max1363.c
@@ -1567,6 +1567,7 @@ static const struct of_device_id max1363_of_match[] = {
1567 MAX1363_COMPATIBLE("maxim,max11647", max11647), 1567 MAX1363_COMPATIBLE("maxim,max11647", max11647),
1568 { /* sentinel */ } 1568 { /* sentinel */ }
1569}; 1569};
1570MODULE_DEVICE_TABLE(of, max1363_of_match);
1570#endif 1571#endif
1571 1572
1572static int max1363_probe(struct i2c_client *client, 1573static int max1363_probe(struct i2c_client *client,
diff --git a/drivers/iio/adc/meson_saradc.c b/drivers/iio/adc/meson_saradc.c
new file mode 100644
index 000000000000..89def6034f40
--- /dev/null
+++ b/drivers/iio/adc/meson_saradc.c
@@ -0,0 +1,922 @@
1/*
2 * Amlogic Meson Successive Approximation Register (SAR) A/D Converter
3 *
4 * Copyright (C) 2017 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * You should have received a copy of the GNU General Public License
11 * along with this program. If not, see <http://www.gnu.org/licenses/>.
12 */
13
14#include <linux/bitfield.h>
15#include <linux/clk.h>
16#include <linux/clk-provider.h>
17#include <linux/delay.h>
18#include <linux/io.h>
19#include <linux/iio/iio.h>
20#include <linux/module.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
23#include <linux/platform_device.h>
24#include <linux/regmap.h>
25#include <linux/regulator/consumer.h>
26
27#define MESON_SAR_ADC_REG0 0x00
28 #define MESON_SAR_ADC_REG0_PANEL_DETECT BIT(31)
29 #define MESON_SAR_ADC_REG0_BUSY_MASK GENMASK(30, 28)
30 #define MESON_SAR_ADC_REG0_DELTA_BUSY BIT(30)
31 #define MESON_SAR_ADC_REG0_AVG_BUSY BIT(29)
32 #define MESON_SAR_ADC_REG0_SAMPLE_BUSY BIT(28)
33 #define MESON_SAR_ADC_REG0_FIFO_FULL BIT(27)
34 #define MESON_SAR_ADC_REG0_FIFO_EMPTY BIT(26)
35 #define MESON_SAR_ADC_REG0_FIFO_COUNT_MASK GENMASK(25, 21)
36 #define MESON_SAR_ADC_REG0_ADC_BIAS_CTRL_MASK GENMASK(20, 19)
37 #define MESON_SAR_ADC_REG0_CURR_CHAN_ID_MASK GENMASK(18, 16)
38 #define MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL BIT(15)
39 #define MESON_SAR_ADC_REG0_SAMPLING_STOP BIT(14)
40 #define MESON_SAR_ADC_REG0_CHAN_DELTA_EN_MASK GENMASK(13, 12)
41 #define MESON_SAR_ADC_REG0_DETECT_IRQ_POL BIT(10)
42 #define MESON_SAR_ADC_REG0_DETECT_IRQ_EN BIT(9)
43 #define MESON_SAR_ADC_REG0_FIFO_CNT_IRQ_MASK GENMASK(8, 4)
44 #define MESON_SAR_ADC_REG0_FIFO_IRQ_EN BIT(3)
45 #define MESON_SAR_ADC_REG0_SAMPLING_START BIT(2)
46 #define MESON_SAR_ADC_REG0_CONTINUOUS_EN BIT(1)
47 #define MESON_SAR_ADC_REG0_SAMPLE_ENGINE_ENABLE BIT(0)
48
49#define MESON_SAR_ADC_CHAN_LIST 0x04
50 #define MESON_SAR_ADC_CHAN_LIST_MAX_INDEX_MASK GENMASK(26, 24)
51 #define MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(_chan) \
52 (GENMASK(2, 0) << ((_chan) * 3))
53
54#define MESON_SAR_ADC_AVG_CNTL 0x08
55 #define MESON_SAR_ADC_AVG_CNTL_AVG_MODE_SHIFT(_chan) \
56 (16 + ((_chan) * 2))
57 #define MESON_SAR_ADC_AVG_CNTL_AVG_MODE_MASK(_chan) \
58 (GENMASK(17, 16) << ((_chan) * 2))
59 #define MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_SHIFT(_chan) \
60 (0 + ((_chan) * 2))
61 #define MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_MASK(_chan) \
62 (GENMASK(1, 0) << ((_chan) * 2))
63
64#define MESON_SAR_ADC_REG3 0x0c
65 #define MESON_SAR_ADC_REG3_CNTL_USE_SC_DLY BIT(31)
66 #define MESON_SAR_ADC_REG3_CLK_EN BIT(30)
67 #define MESON_SAR_ADC_REG3_BL30_INITIALIZED BIT(28)
68 #define MESON_SAR_ADC_REG3_CTRL_CONT_RING_COUNTER_EN BIT(27)
69 #define MESON_SAR_ADC_REG3_CTRL_SAMPLING_CLOCK_PHASE BIT(26)
70 #define MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK GENMASK(25, 23)
71 #define MESON_SAR_ADC_REG3_DETECT_EN BIT(22)
72 #define MESON_SAR_ADC_REG3_ADC_EN BIT(21)
73 #define MESON_SAR_ADC_REG3_PANEL_DETECT_COUNT_MASK GENMASK(20, 18)
74 #define MESON_SAR_ADC_REG3_PANEL_DETECT_FILTER_TB_MASK GENMASK(17, 16)
75 #define MESON_SAR_ADC_REG3_ADC_CLK_DIV_SHIFT 10
76 #define MESON_SAR_ADC_REG3_ADC_CLK_DIV_WIDTH 5
77 #define MESON_SAR_ADC_REG3_BLOCK_DLY_SEL_MASK GENMASK(9, 8)
78 #define MESON_SAR_ADC_REG3_BLOCK_DLY_MASK GENMASK(7, 0)
79
80#define MESON_SAR_ADC_DELAY 0x10
81 #define MESON_SAR_ADC_DELAY_INPUT_DLY_SEL_MASK GENMASK(25, 24)
82 #define MESON_SAR_ADC_DELAY_BL30_BUSY BIT(15)
83 #define MESON_SAR_ADC_DELAY_KERNEL_BUSY BIT(14)
84 #define MESON_SAR_ADC_DELAY_INPUT_DLY_CNT_MASK GENMASK(23, 16)
85 #define MESON_SAR_ADC_DELAY_SAMPLE_DLY_SEL_MASK GENMASK(9, 8)
86 #define MESON_SAR_ADC_DELAY_SAMPLE_DLY_CNT_MASK GENMASK(7, 0)
87
88#define MESON_SAR_ADC_LAST_RD 0x14
89 #define MESON_SAR_ADC_LAST_RD_LAST_CHANNEL1_MASK GENMASK(23, 16)
90 #define MESON_SAR_ADC_LAST_RD_LAST_CHANNEL0_MASK GENMASK(9, 0)
91
92#define MESON_SAR_ADC_FIFO_RD 0x18
93 #define MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK GENMASK(14, 12)
94 #define MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK GENMASK(11, 0)
95
96#define MESON_SAR_ADC_AUX_SW 0x1c
97 #define MESON_SAR_ADC_AUX_SW_MUX_SEL_CHAN_MASK(_chan) \
98 (GENMASK(10, 8) << (((_chan) - 2) * 2))
99 #define MESON_SAR_ADC_AUX_SW_VREF_P_MUX BIT(6)
100 #define MESON_SAR_ADC_AUX_SW_VREF_N_MUX BIT(5)
101 #define MESON_SAR_ADC_AUX_SW_MODE_SEL BIT(4)
102 #define MESON_SAR_ADC_AUX_SW_YP_DRIVE_SW BIT(3)
103 #define MESON_SAR_ADC_AUX_SW_XP_DRIVE_SW BIT(2)
104 #define MESON_SAR_ADC_AUX_SW_YM_DRIVE_SW BIT(1)
105 #define MESON_SAR_ADC_AUX_SW_XM_DRIVE_SW BIT(0)
106
107#define MESON_SAR_ADC_CHAN_10_SW 0x20
108 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_MUX_SEL_MASK GENMASK(25, 23)
109 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_VREF_P_MUX BIT(22)
110 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_VREF_N_MUX BIT(21)
111 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_MODE_SEL BIT(20)
112 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_YP_DRIVE_SW BIT(19)
113 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_XP_DRIVE_SW BIT(18)
114 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_YM_DRIVE_SW BIT(17)
115 #define MESON_SAR_ADC_CHAN_10_SW_CHAN1_XM_DRIVE_SW BIT(16)
116 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_MUX_SEL_MASK GENMASK(9, 7)
117 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_VREF_P_MUX BIT(6)
118 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_VREF_N_MUX BIT(5)
119 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_MODE_SEL BIT(4)
120 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_YP_DRIVE_SW BIT(3)
121 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_XP_DRIVE_SW BIT(2)
122 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_YM_DRIVE_SW BIT(1)
123 #define MESON_SAR_ADC_CHAN_10_SW_CHAN0_XM_DRIVE_SW BIT(0)
124
125#define MESON_SAR_ADC_DETECT_IDLE_SW 0x24
126 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_SW_EN BIT(26)
127 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK GENMASK(25, 23)
128 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_VREF_P_MUX BIT(22)
129 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_VREF_N_MUX BIT(21)
130 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MODE_SEL BIT(20)
131 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_YP_DRIVE_SW BIT(19)
132 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_XP_DRIVE_SW BIT(18)
133 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_YM_DRIVE_SW BIT(17)
134 #define MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_XM_DRIVE_SW BIT(16)
135 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK GENMASK(9, 7)
136 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_VREF_P_MUX BIT(6)
137 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_VREF_N_MUX BIT(5)
138 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MODE_SEL BIT(4)
139 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_YP_DRIVE_SW BIT(3)
140 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_XP_DRIVE_SW BIT(2)
141 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_YM_DRIVE_SW BIT(1)
142 #define MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_XM_DRIVE_SW BIT(0)
143
144#define MESON_SAR_ADC_DELTA_10 0x28
145 #define MESON_SAR_ADC_DELTA_10_TEMP_SEL BIT(27)
146 #define MESON_SAR_ADC_DELTA_10_TS_REVE1 BIT(26)
147 #define MESON_SAR_ADC_DELTA_10_CHAN1_DELTA_VALUE_MASK GENMASK(25, 16)
148 #define MESON_SAR_ADC_DELTA_10_TS_REVE0 BIT(15)
149 #define MESON_SAR_ADC_DELTA_10_TS_C_SHIFT 11
150 #define MESON_SAR_ADC_DELTA_10_TS_C_MASK GENMASK(14, 11)
151 #define MESON_SAR_ADC_DELTA_10_TS_VBG_EN BIT(10)
152 #define MESON_SAR_ADC_DELTA_10_CHAN0_DELTA_VALUE_MASK GENMASK(9, 0)
153
154/*
155 * NOTE: registers from here are undocumented (the vendor Linux kernel driver
156 * and u-boot source served as reference). These only seem to be relevant on
157 * GXBB and newer.
158 */
159#define MESON_SAR_ADC_REG11 0x2c
160 #define MESON_SAR_ADC_REG11_BANDGAP_EN BIT(13)
161
162#define MESON_SAR_ADC_REG13 0x34
163 #define MESON_SAR_ADC_REG13_12BIT_CALIBRATION_MASK GENMASK(13, 8)
164
165#define MESON_SAR_ADC_MAX_FIFO_SIZE 32
166
167#define MESON_SAR_ADC_CHAN(_chan) { \
168 .type = IIO_VOLTAGE, \
169 .indexed = 1, \
170 .channel = _chan, \
171 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
172 BIT(IIO_CHAN_INFO_AVERAGE_RAW), \
173 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
174 .datasheet_name = "SAR_ADC_CH"#_chan, \
175}
176
177/*
178 * TODO: the hardware supports IIO_TEMP for channel 6 as well which is
179 * currently not supported by this driver.
180 */
181static const struct iio_chan_spec meson_sar_adc_iio_channels[] = {
182 MESON_SAR_ADC_CHAN(0),
183 MESON_SAR_ADC_CHAN(1),
184 MESON_SAR_ADC_CHAN(2),
185 MESON_SAR_ADC_CHAN(3),
186 MESON_SAR_ADC_CHAN(4),
187 MESON_SAR_ADC_CHAN(5),
188 MESON_SAR_ADC_CHAN(6),
189 MESON_SAR_ADC_CHAN(7),
190 IIO_CHAN_SOFT_TIMESTAMP(8),
191};
192
193enum meson_sar_adc_avg_mode {
194 NO_AVERAGING = 0x0,
195 MEAN_AVERAGING = 0x1,
196 MEDIAN_AVERAGING = 0x2,
197};
198
199enum meson_sar_adc_num_samples {
200 ONE_SAMPLE = 0x0,
201 TWO_SAMPLES = 0x1,
202 FOUR_SAMPLES = 0x2,
203 EIGHT_SAMPLES = 0x3,
204};
205
206enum meson_sar_adc_chan7_mux_sel {
207 CHAN7_MUX_VSS = 0x0,
208 CHAN7_MUX_VDD_DIV4 = 0x1,
209 CHAN7_MUX_VDD_DIV2 = 0x2,
210 CHAN7_MUX_VDD_MUL3_DIV4 = 0x3,
211 CHAN7_MUX_VDD = 0x4,
212 CHAN7_MUX_CH7_INPUT = 0x7,
213};
214
215struct meson_sar_adc_data {
216 unsigned int resolution;
217 const char *name;
218};
219
220struct meson_sar_adc_priv {
221 struct regmap *regmap;
222 struct regulator *vref;
223 const struct meson_sar_adc_data *data;
224 struct clk *clkin;
225 struct clk *core_clk;
226 struct clk *sana_clk;
227 struct clk *adc_sel_clk;
228 struct clk *adc_clk;
229 struct clk_gate clk_gate;
230 struct clk *adc_div_clk;
231 struct clk_divider clk_div;
232};
233
234static const struct regmap_config meson_sar_adc_regmap_config = {
235 .reg_bits = 8,
236 .val_bits = 32,
237 .reg_stride = 4,
238 .max_register = MESON_SAR_ADC_REG13,
239};
240
241static unsigned int meson_sar_adc_get_fifo_count(struct iio_dev *indio_dev)
242{
243 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
244 u32 regval;
245
246 regmap_read(priv->regmap, MESON_SAR_ADC_REG0, &regval);
247
248 return FIELD_GET(MESON_SAR_ADC_REG0_FIFO_COUNT_MASK, regval);
249}
250
251static int meson_sar_adc_wait_busy_clear(struct iio_dev *indio_dev)
252{
253 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
254 int regval, timeout = 10000;
255
256 /*
257 * NOTE: we need a small delay before reading the status, otherwise
258 * the sample engine may not have started internally (which would
259 * seem to us that sampling is already finished).
260 */
261 do {
262 udelay(1);
263 regmap_read(priv->regmap, MESON_SAR_ADC_REG0, &regval);
264 } while (FIELD_GET(MESON_SAR_ADC_REG0_BUSY_MASK, regval) && timeout--);
265
266 if (timeout < 0)
267 return -ETIMEDOUT;
268
269 return 0;
270}
271
272static int meson_sar_adc_read_raw_sample(struct iio_dev *indio_dev,
273 const struct iio_chan_spec *chan,
274 int *val)
275{
276 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
277 int ret, regval, fifo_chan, fifo_val, sum = 0, count = 0;
278
279 ret = meson_sar_adc_wait_busy_clear(indio_dev);
280 if (ret)
281 return ret;
282
283 while (meson_sar_adc_get_fifo_count(indio_dev) > 0 &&
284 count < MESON_SAR_ADC_MAX_FIFO_SIZE) {
285 regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, &regval);
286
287 fifo_chan = FIELD_GET(MESON_SAR_ADC_FIFO_RD_CHAN_ID_MASK,
288 regval);
289 if (fifo_chan != chan->channel)
290 continue;
291
292 fifo_val = FIELD_GET(MESON_SAR_ADC_FIFO_RD_SAMPLE_VALUE_MASK,
293 regval);
294 fifo_val &= (BIT(priv->data->resolution) - 1);
295
296 sum += fifo_val;
297 count++;
298 }
299
300 if (!count)
301 return -ENOENT;
302
303 *val = sum / count;
304
305 return 0;
306}
307
308static void meson_sar_adc_set_averaging(struct iio_dev *indio_dev,
309 const struct iio_chan_spec *chan,
310 enum meson_sar_adc_avg_mode mode,
311 enum meson_sar_adc_num_samples samples)
312{
313 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
314 int val, channel = chan->channel;
315
316 val = samples << MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_SHIFT(channel);
317 regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL,
318 MESON_SAR_ADC_AVG_CNTL_NUM_SAMPLES_MASK(channel),
319 val);
320
321 val = mode << MESON_SAR_ADC_AVG_CNTL_AVG_MODE_SHIFT(channel);
322 regmap_update_bits(priv->regmap, MESON_SAR_ADC_AVG_CNTL,
323 MESON_SAR_ADC_AVG_CNTL_AVG_MODE_MASK(channel), val);
324}
325
326static void meson_sar_adc_enable_channel(struct iio_dev *indio_dev,
327 const struct iio_chan_spec *chan)
328{
329 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
330 u32 regval;
331
332 /*
333 * the SAR ADC engine allows sampling multiple channels at the same
334 * time. to keep it simple we're only working with one *internal*
335 * channel, which starts counting at index 0 (which means: count = 1).
336 */
337 regval = FIELD_PREP(MESON_SAR_ADC_CHAN_LIST_MAX_INDEX_MASK, 0);
338 regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_LIST,
339 MESON_SAR_ADC_CHAN_LIST_MAX_INDEX_MASK, regval);
340
341 /* map channel index 0 to the channel which we want to read */
342 regval = FIELD_PREP(MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0),
343 chan->channel);
344 regmap_update_bits(priv->regmap, MESON_SAR_ADC_CHAN_LIST,
345 MESON_SAR_ADC_CHAN_LIST_ENTRY_MASK(0), regval);
346
347 regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK,
348 chan->channel);
349 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW,
350 MESON_SAR_ADC_DETECT_IDLE_SW_DETECT_MUX_MASK,
351 regval);
352
353 regval = FIELD_PREP(MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK,
354 chan->channel);
355 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DETECT_IDLE_SW,
356 MESON_SAR_ADC_DETECT_IDLE_SW_IDLE_MUX_SEL_MASK,
357 regval);
358
359 if (chan->channel == 6)
360 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELTA_10,
361 MESON_SAR_ADC_DELTA_10_TEMP_SEL, 0);
362}
363
364static void meson_sar_adc_set_chan7_mux(struct iio_dev *indio_dev,
365 enum meson_sar_adc_chan7_mux_sel sel)
366{
367 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
368 u32 regval;
369
370 regval = FIELD_PREP(MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, sel);
371 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
372 MESON_SAR_ADC_REG3_CTRL_CHAN7_MUX_SEL_MASK, regval);
373
374 usleep_range(10, 20);
375}
376
377static void meson_sar_adc_start_sample_engine(struct iio_dev *indio_dev)
378{
379 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
380
381 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
382 MESON_SAR_ADC_REG0_SAMPLE_ENGINE_ENABLE,
383 MESON_SAR_ADC_REG0_SAMPLE_ENGINE_ENABLE);
384
385 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
386 MESON_SAR_ADC_REG0_SAMPLING_START,
387 MESON_SAR_ADC_REG0_SAMPLING_START);
388}
389
390static void meson_sar_adc_stop_sample_engine(struct iio_dev *indio_dev)
391{
392 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
393
394 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
395 MESON_SAR_ADC_REG0_SAMPLING_STOP,
396 MESON_SAR_ADC_REG0_SAMPLING_STOP);
397
398 /* wait until all modules are stopped */
399 meson_sar_adc_wait_busy_clear(indio_dev);
400
401 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
402 MESON_SAR_ADC_REG0_SAMPLE_ENGINE_ENABLE, 0);
403}
404
405static int meson_sar_adc_lock(struct iio_dev *indio_dev)
406{
407 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
408 int val, timeout = 10000;
409
410 mutex_lock(&indio_dev->mlock);
411
412 /* prevent BL30 from using the SAR ADC while we are using it */
413 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
414 MESON_SAR_ADC_DELAY_KERNEL_BUSY,
415 MESON_SAR_ADC_DELAY_KERNEL_BUSY);
416
417 /* wait until BL30 releases it's lock (so we can use the SAR ADC) */
418 do {
419 udelay(1);
420 regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val);
421 } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--);
422
423 if (timeout < 0)
424 return -ETIMEDOUT;
425
426 return 0;
427}
428
429static void meson_sar_adc_unlock(struct iio_dev *indio_dev)
430{
431 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
432
433 /* allow BL30 to use the SAR ADC again */
434 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
435 MESON_SAR_ADC_DELAY_KERNEL_BUSY, 0);
436
437 mutex_unlock(&indio_dev->mlock);
438}
439
440static void meson_sar_adc_clear_fifo(struct iio_dev *indio_dev)
441{
442 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
443 int count;
444
445 for (count = 0; count < MESON_SAR_ADC_MAX_FIFO_SIZE; count++) {
446 if (!meson_sar_adc_get_fifo_count(indio_dev))
447 break;
448
449 regmap_read(priv->regmap, MESON_SAR_ADC_FIFO_RD, 0);
450 }
451}
452
453static int meson_sar_adc_get_sample(struct iio_dev *indio_dev,
454 const struct iio_chan_spec *chan,
455 enum meson_sar_adc_avg_mode avg_mode,
456 enum meson_sar_adc_num_samples avg_samples,
457 int *val)
458{
459 int ret;
460
461 ret = meson_sar_adc_lock(indio_dev);
462 if (ret)
463 return ret;
464
465 /* clear the FIFO to make sure we're not reading old values */
466 meson_sar_adc_clear_fifo(indio_dev);
467
468 meson_sar_adc_set_averaging(indio_dev, chan, avg_mode, avg_samples);
469
470 meson_sar_adc_enable_channel(indio_dev, chan);
471
472 meson_sar_adc_start_sample_engine(indio_dev);
473 ret = meson_sar_adc_read_raw_sample(indio_dev, chan, val);
474 meson_sar_adc_stop_sample_engine(indio_dev);
475
476 meson_sar_adc_unlock(indio_dev);
477
478 if (ret) {
479 dev_warn(indio_dev->dev.parent,
480 "failed to read sample for channel %d: %d\n",
481 chan->channel, ret);
482 return ret;
483 }
484
485 return IIO_VAL_INT;
486}
487
488static int meson_sar_adc_iio_info_read_raw(struct iio_dev *indio_dev,
489 const struct iio_chan_spec *chan,
490 int *val, int *val2, long mask)
491{
492 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
493 int ret;
494
495 switch (mask) {
496 case IIO_CHAN_INFO_RAW:
497 return meson_sar_adc_get_sample(indio_dev, chan, NO_AVERAGING,
498 ONE_SAMPLE, val);
499 break;
500
501 case IIO_CHAN_INFO_AVERAGE_RAW:
502 return meson_sar_adc_get_sample(indio_dev, chan,
503 MEAN_AVERAGING, EIGHT_SAMPLES,
504 val);
505 break;
506
507 case IIO_CHAN_INFO_SCALE:
508 ret = regulator_get_voltage(priv->vref);
509 if (ret < 0) {
510 dev_err(indio_dev->dev.parent,
511 "failed to get vref voltage: %d\n", ret);
512 return ret;
513 }
514
515 *val = ret / 1000;
516 *val2 = priv->data->resolution;
517 return IIO_VAL_FRACTIONAL_LOG2;
518
519 default:
520 return -EINVAL;
521 }
522}
523
524static int meson_sar_adc_clk_init(struct iio_dev *indio_dev,
525 void __iomem *base)
526{
527 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
528 struct clk_init_data init;
529 const char *clk_parents[1];
530
531 init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_div",
532 of_node_full_name(indio_dev->dev.of_node));
533 init.flags = 0;
534 init.ops = &clk_divider_ops;
535 clk_parents[0] = __clk_get_name(priv->clkin);
536 init.parent_names = clk_parents;
537 init.num_parents = 1;
538
539 priv->clk_div.reg = base + MESON_SAR_ADC_REG3;
540 priv->clk_div.shift = MESON_SAR_ADC_REG3_ADC_CLK_DIV_SHIFT;
541 priv->clk_div.width = MESON_SAR_ADC_REG3_ADC_CLK_DIV_WIDTH;
542 priv->clk_div.hw.init = &init;
543 priv->clk_div.flags = 0;
544
545 priv->adc_div_clk = devm_clk_register(&indio_dev->dev,
546 &priv->clk_div.hw);
547 if (WARN_ON(IS_ERR(priv->adc_div_clk)))
548 return PTR_ERR(priv->adc_div_clk);
549
550 init.name = devm_kasprintf(&indio_dev->dev, GFP_KERNEL, "%s#adc_en",
551 of_node_full_name(indio_dev->dev.of_node));
552 init.flags = CLK_SET_RATE_PARENT;
553 init.ops = &clk_gate_ops;
554 clk_parents[0] = __clk_get_name(priv->adc_div_clk);
555 init.parent_names = clk_parents;
556 init.num_parents = 1;
557
558 priv->clk_gate.reg = base + MESON_SAR_ADC_REG3;
559 priv->clk_gate.bit_idx = fls(MESON_SAR_ADC_REG3_CLK_EN);
560 priv->clk_gate.hw.init = &init;
561
562 priv->adc_clk = devm_clk_register(&indio_dev->dev, &priv->clk_gate.hw);
563 if (WARN_ON(IS_ERR(priv->adc_clk)))
564 return PTR_ERR(priv->adc_clk);
565
566 return 0;
567}
568
569static int meson_sar_adc_init(struct iio_dev *indio_dev)
570{
571 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
572 int regval, ret;
573
574 /*
575 * make sure we start at CH7 input since the other muxes are only used
576 * for internal calibration.
577 */
578 meson_sar_adc_set_chan7_mux(indio_dev, CHAN7_MUX_CH7_INPUT);
579
580 /*
581 * leave sampling delay and the input clocks as configured by BL30 to
582 * make sure BL30 gets the values it expects when reading the
583 * temperature sensor.
584 */
585 regmap_read(priv->regmap, MESON_SAR_ADC_REG3, &regval);
586 if (regval & MESON_SAR_ADC_REG3_BL30_INITIALIZED)
587 return 0;
588
589 meson_sar_adc_stop_sample_engine(indio_dev);
590
591 /* update the channel 6 MUX to select the temperature sensor */
592 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG0,
593 MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL,
594 MESON_SAR_ADC_REG0_ADC_TEMP_SEN_SEL);
595
596 /* disable all channels by default */
597 regmap_write(priv->regmap, MESON_SAR_ADC_CHAN_LIST, 0x0);
598
599 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
600 MESON_SAR_ADC_REG3_CTRL_SAMPLING_CLOCK_PHASE, 0);
601 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
602 MESON_SAR_ADC_REG3_CNTL_USE_SC_DLY,
603 MESON_SAR_ADC_REG3_CNTL_USE_SC_DLY);
604
605 /* delay between two samples = (10+1) * 1uS */
606 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
607 MESON_SAR_ADC_DELAY_INPUT_DLY_CNT_MASK,
608 FIELD_PREP(MESON_SAR_ADC_DELAY_SAMPLE_DLY_CNT_MASK,
609 10));
610 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
611 MESON_SAR_ADC_DELAY_SAMPLE_DLY_SEL_MASK,
612 FIELD_PREP(MESON_SAR_ADC_DELAY_SAMPLE_DLY_SEL_MASK,
613 0));
614
615 /* delay between two samples = (10+1) * 1uS */
616 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
617 MESON_SAR_ADC_DELAY_INPUT_DLY_CNT_MASK,
618 FIELD_PREP(MESON_SAR_ADC_DELAY_INPUT_DLY_CNT_MASK,
619 10));
620 regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
621 MESON_SAR_ADC_DELAY_INPUT_DLY_SEL_MASK,
622 FIELD_PREP(MESON_SAR_ADC_DELAY_INPUT_DLY_SEL_MASK,
623 1));
624
625 ret = clk_set_parent(priv->adc_sel_clk, priv->clkin);
626 if (ret) {
627 dev_err(indio_dev->dev.parent,
628 "failed to set adc parent to clkin\n");
629 return ret;
630 }
631
632 ret = clk_set_rate(priv->adc_clk, 1200000);
633 if (ret) {
634 dev_err(indio_dev->dev.parent,
635 "failed to set adc clock rate\n");
636 return ret;
637 }
638
639 return 0;
640}
641
642static int meson_sar_adc_hw_enable(struct iio_dev *indio_dev)
643{
644 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
645 int ret;
646
647 ret = meson_sar_adc_lock(indio_dev);
648 if (ret)
649 goto err_lock;
650
651 ret = regulator_enable(priv->vref);
652 if (ret < 0) {
653 dev_err(indio_dev->dev.parent,
654 "failed to enable vref regulator\n");
655 goto err_vref;
656 }
657
658 ret = clk_prepare_enable(priv->core_clk);
659 if (ret) {
660 dev_err(indio_dev->dev.parent, "failed to enable core clk\n");
661 goto err_core_clk;
662 }
663
664 ret = clk_prepare_enable(priv->sana_clk);
665 if (ret) {
666 dev_err(indio_dev->dev.parent, "failed to enable sana clk\n");
667 goto err_sana_clk;
668 }
669
670 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11,
671 MESON_SAR_ADC_REG11_BANDGAP_EN,
672 MESON_SAR_ADC_REG11_BANDGAP_EN);
673 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
674 MESON_SAR_ADC_REG3_ADC_EN,
675 MESON_SAR_ADC_REG3_ADC_EN);
676
677 udelay(5);
678
679 ret = clk_prepare_enable(priv->adc_clk);
680 if (ret) {
681 dev_err(indio_dev->dev.parent, "failed to enable adc clk\n");
682 goto err_adc_clk;
683 }
684
685 meson_sar_adc_unlock(indio_dev);
686
687 return 0;
688
689err_adc_clk:
690 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
691 MESON_SAR_ADC_REG3_ADC_EN, 0);
692 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11,
693 MESON_SAR_ADC_REG11_BANDGAP_EN, 0);
694 clk_disable_unprepare(priv->sana_clk);
695err_sana_clk:
696 clk_disable_unprepare(priv->core_clk);
697err_core_clk:
698 regulator_disable(priv->vref);
699err_vref:
700 meson_sar_adc_unlock(indio_dev);
701err_lock:
702 return ret;
703}
704
705static int meson_sar_adc_hw_disable(struct iio_dev *indio_dev)
706{
707 struct meson_sar_adc_priv *priv = iio_priv(indio_dev);
708 int ret;
709
710 ret = meson_sar_adc_lock(indio_dev);
711 if (ret)
712 return ret;
713
714 clk_disable_unprepare(priv->adc_clk);
715
716 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG3,
717 MESON_SAR_ADC_REG3_ADC_EN, 0);
718 regmap_update_bits(priv->regmap, MESON_SAR_ADC_REG11,
719 MESON_SAR_ADC_REG11_BANDGAP_EN, 0);
720
721 clk_disable_unprepare(priv->sana_clk);
722 clk_disable_unprepare(priv->core_clk);
723
724 regulator_disable(priv->vref);
725
726 meson_sar_adc_unlock(indio_dev);
727
728 return 0;
729}
730
731static const struct iio_info meson_sar_adc_iio_info = {
732 .read_raw = meson_sar_adc_iio_info_read_raw,
733 .driver_module = THIS_MODULE,
734};
735
736struct meson_sar_adc_data meson_sar_adc_gxbb_data = {
737 .resolution = 10,
738 .name = "meson-gxbb-saradc",
739};
740
741struct meson_sar_adc_data meson_sar_adc_gxl_data = {
742 .resolution = 12,
743 .name = "meson-gxl-saradc",
744};
745
746struct meson_sar_adc_data meson_sar_adc_gxm_data = {
747 .resolution = 12,
748 .name = "meson-gxm-saradc",
749};
750
751static const struct of_device_id meson_sar_adc_of_match[] = {
752 {
753 .compatible = "amlogic,meson-gxbb-saradc",
754 .data = &meson_sar_adc_gxbb_data,
755 }, {
756 .compatible = "amlogic,meson-gxl-saradc",
757 .data = &meson_sar_adc_gxl_data,
758 }, {
759 .compatible = "amlogic,meson-gxm-saradc",
760 .data = &meson_sar_adc_gxm_data,
761 },
762 {},
763};
764MODULE_DEVICE_TABLE(of, meson_sar_adc_of_match);
765
766static int meson_sar_adc_probe(struct platform_device *pdev)
767{
768 struct meson_sar_adc_priv *priv;
769 struct iio_dev *indio_dev;
770 struct resource *res;
771 void __iomem *base;
772 const struct of_device_id *match;
773 int ret;
774
775 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*priv));
776 if (!indio_dev) {
777 dev_err(&pdev->dev, "failed allocating iio device\n");
778 return -ENOMEM;
779 }
780
781 priv = iio_priv(indio_dev);
782
783 match = of_match_device(meson_sar_adc_of_match, &pdev->dev);
784 priv->data = match->data;
785
786 indio_dev->name = priv->data->name;
787 indio_dev->dev.parent = &pdev->dev;
788 indio_dev->dev.of_node = pdev->dev.of_node;
789 indio_dev->modes = INDIO_DIRECT_MODE;
790 indio_dev->info = &meson_sar_adc_iio_info;
791
792 indio_dev->channels = meson_sar_adc_iio_channels;
793 indio_dev->num_channels = ARRAY_SIZE(meson_sar_adc_iio_channels);
794
795 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
796 base = devm_ioremap_resource(&pdev->dev, res);
797 if (IS_ERR(base))
798 return PTR_ERR(base);
799
800 priv->regmap = devm_regmap_init_mmio(&pdev->dev, base,
801 &meson_sar_adc_regmap_config);
802 if (IS_ERR(priv->regmap))
803 return PTR_ERR(priv->regmap);
804
805 priv->clkin = devm_clk_get(&pdev->dev, "clkin");
806 if (IS_ERR(priv->clkin)) {
807 dev_err(&pdev->dev, "failed to get clkin\n");
808 return PTR_ERR(priv->clkin);
809 }
810
811 priv->core_clk = devm_clk_get(&pdev->dev, "core");
812 if (IS_ERR(priv->core_clk)) {
813 dev_err(&pdev->dev, "failed to get core clk\n");
814 return PTR_ERR(priv->core_clk);
815 }
816
817 priv->sana_clk = devm_clk_get(&pdev->dev, "sana");
818 if (IS_ERR(priv->sana_clk)) {
819 if (PTR_ERR(priv->sana_clk) == -ENOENT) {
820 priv->sana_clk = NULL;
821 } else {
822 dev_err(&pdev->dev, "failed to get sana clk\n");
823 return PTR_ERR(priv->sana_clk);
824 }
825 }
826
827 priv->adc_clk = devm_clk_get(&pdev->dev, "adc_clk");
828 if (IS_ERR(priv->adc_clk)) {
829 if (PTR_ERR(priv->adc_clk) == -ENOENT) {
830 priv->adc_clk = NULL;
831 } else {
832 dev_err(&pdev->dev, "failed to get adc clk\n");
833 return PTR_ERR(priv->adc_clk);
834 }
835 }
836
837 priv->adc_sel_clk = devm_clk_get(&pdev->dev, "adc_sel");
838 if (IS_ERR(priv->adc_sel_clk)) {
839 if (PTR_ERR(priv->adc_sel_clk) == -ENOENT) {
840 priv->adc_sel_clk = NULL;
841 } else {
842 dev_err(&pdev->dev, "failed to get adc_sel clk\n");
843 return PTR_ERR(priv->adc_sel_clk);
844 }
845 }
846
847 /* on pre-GXBB SoCs the SAR ADC itself provides the ADC clock: */
848 if (!priv->adc_clk) {
849 ret = meson_sar_adc_clk_init(indio_dev, base);
850 if (ret)
851 return ret;
852 }
853
854 priv->vref = devm_regulator_get(&pdev->dev, "vref");
855 if (IS_ERR(priv->vref)) {
856 dev_err(&pdev->dev, "failed to get vref regulator\n");
857 return PTR_ERR(priv->vref);
858 }
859
860 ret = meson_sar_adc_init(indio_dev);
861 if (ret)
862 goto err;
863
864 ret = meson_sar_adc_hw_enable(indio_dev);
865 if (ret)
866 goto err;
867
868 platform_set_drvdata(pdev, indio_dev);
869
870 ret = iio_device_register(indio_dev);
871 if (ret)
872 goto err_hw;
873
874 return 0;
875
876err_hw:
877 meson_sar_adc_hw_disable(indio_dev);
878err:
879 return ret;
880}
881
882static int meson_sar_adc_remove(struct platform_device *pdev)
883{
884 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
885
886 iio_device_unregister(indio_dev);
887
888 return meson_sar_adc_hw_disable(indio_dev);
889}
890
891static int __maybe_unused meson_sar_adc_suspend(struct device *dev)
892{
893 struct iio_dev *indio_dev = dev_get_drvdata(dev);
894
895 return meson_sar_adc_hw_disable(indio_dev);
896}
897
898static int __maybe_unused meson_sar_adc_resume(struct device *dev)
899{
900 struct iio_dev *indio_dev = dev_get_drvdata(dev);
901
902 return meson_sar_adc_hw_enable(indio_dev);
903}
904
905static SIMPLE_DEV_PM_OPS(meson_sar_adc_pm_ops,
906 meson_sar_adc_suspend, meson_sar_adc_resume);
907
908static struct platform_driver meson_sar_adc_driver = {
909 .probe = meson_sar_adc_probe,
910 .remove = meson_sar_adc_remove,
911 .driver = {
912 .name = "meson-saradc",
913 .of_match_table = meson_sar_adc_of_match,
914 .pm = &meson_sar_adc_pm_ops,
915 },
916};
917
918module_platform_driver(meson_sar_adc_driver);
919
920MODULE_AUTHOR("Martin Blumenstingl <martin.blumenstingl@googlemail.com>");
921MODULE_DESCRIPTION("Amlogic Meson SAR ADC driver");
922MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
index c2babe50a0d8..0a19761d656c 100644
--- a/drivers/iio/adc/qcom-spmi-vadc.c
+++ b/drivers/iio/adc/qcom-spmi-vadc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. 2 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and 5 * it under the terms of the GNU General Public License version 2 and
@@ -84,7 +84,7 @@
84#define VADC_MAX_ADC_CODE 0xa800 84#define VADC_MAX_ADC_CODE 0xa800
85 85
86#define VADC_ABSOLUTE_RANGE_UV 625000 86#define VADC_ABSOLUTE_RANGE_UV 625000
87#define VADC_RATIOMETRIC_RANGE_UV 1800000 87#define VADC_RATIOMETRIC_RANGE 1800
88 88
89#define VADC_DEF_PRESCALING 0 /* 1:1 */ 89#define VADC_DEF_PRESCALING 0 /* 1:1 */
90#define VADC_DEF_DECIMATION 0 /* 512 */ 90#define VADC_DEF_DECIMATION 0 /* 512 */
@@ -100,9 +100,23 @@
100 100
101#define KELVINMIL_CELSIUSMIL 273150 101#define KELVINMIL_CELSIUSMIL 273150
102 102
103#define PMI_CHG_SCALE_1 -138890
104#define PMI_CHG_SCALE_2 391750000000LL
105
103#define VADC_CHAN_MIN VADC_USBIN 106#define VADC_CHAN_MIN VADC_USBIN
104#define VADC_CHAN_MAX VADC_LR_MUX3_BUF_PU1_PU2_XO_THERM 107#define VADC_CHAN_MAX VADC_LR_MUX3_BUF_PU1_PU2_XO_THERM
105 108
109/**
110 * struct vadc_map_pt - Map the graph representation for ADC channel
111 * @x: Represent the ADC digitized code.
112 * @y: Represent the physical data which can be temperature, voltage,
113 * resistance.
114 */
115struct vadc_map_pt {
116 s32 x;
117 s32 y;
118};
119
106/* 120/*
107 * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. 121 * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels.
108 * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for 122 * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for
@@ -148,6 +162,9 @@ struct vadc_prescale_ratio {
148 * start of conversion. 162 * start of conversion.
149 * @avg_samples: ability to provide single result from the ADC 163 * @avg_samples: ability to provide single result from the ADC
150 * that is an average of multiple measurements. 164 * that is an average of multiple measurements.
165 * @scale_fn: Represents the scaling function to convert voltage
166 * physical units desired by the client for the channel.
167 * Referenced from enum vadc_scale_fn_type.
151 */ 168 */
152struct vadc_channel_prop { 169struct vadc_channel_prop {
153 unsigned int channel; 170 unsigned int channel;
@@ -156,6 +173,7 @@ struct vadc_channel_prop {
156 unsigned int prescale; 173 unsigned int prescale;
157 unsigned int hw_settle_time; 174 unsigned int hw_settle_time;
158 unsigned int avg_samples; 175 unsigned int avg_samples;
176 unsigned int scale_fn;
159}; 177};
160 178
161/** 179/**
@@ -186,6 +204,35 @@ struct vadc_priv {
186 struct mutex lock; 204 struct mutex lock;
187}; 205};
188 206
207/**
208 * struct vadc_scale_fn - Scaling function prototype
209 * @scale: Function pointer to one of the scaling functions
210 * which takes the adc properties, channel properties,
211 * and returns the physical result.
212 */
213struct vadc_scale_fn {
214 int (*scale)(struct vadc_priv *, const struct vadc_channel_prop *,
215 u16, int *);
216};
217
218/**
219 * enum vadc_scale_fn_type - Scaling function to convert ADC code to
220 * physical scaled units for the channel.
221 * SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV).
222 * SCALE_THERM_100K_PULLUP: Returns temperature in millidegC.
223 * Uses a mapping table with 100K pullup.
224 * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
225 * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC.
226 * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp
227 */
228enum vadc_scale_fn_type {
229 SCALE_DEFAULT = 0,
230 SCALE_THERM_100K_PULLUP,
231 SCALE_PMIC_THERM,
232 SCALE_XOTHERM,
233 SCALE_PMI_CHG_TEMP,
234};
235
189static const struct vadc_prescale_ratio vadc_prescale_ratios[] = { 236static const struct vadc_prescale_ratio vadc_prescale_ratios[] = {
190 {.num = 1, .den = 1}, 237 {.num = 1, .den = 1},
191 {.num = 1, .den = 3}, 238 {.num = 1, .den = 3},
@@ -197,6 +244,44 @@ static const struct vadc_prescale_ratio vadc_prescale_ratios[] = {
197 {.num = 1, .den = 10} 244 {.num = 1, .den = 10}
198}; 245};
199 246
247/* Voltage to temperature */
248static const struct vadc_map_pt adcmap_100k_104ef_104fb[] = {
249 {1758, -40},
250 {1742, -35},
251 {1719, -30},
252 {1691, -25},
253 {1654, -20},
254 {1608, -15},
255 {1551, -10},
256 {1483, -5},
257 {1404, 0},
258 {1315, 5},
259 {1218, 10},
260 {1114, 15},
261 {1007, 20},
262 {900, 25},
263 {795, 30},
264 {696, 35},
265 {605, 40},
266 {522, 45},
267 {448, 50},
268 {383, 55},
269 {327, 60},
270 {278, 65},
271 {237, 70},
272 {202, 75},
273 {172, 80},
274 {146, 85},
275 {125, 90},
276 {107, 95},
277 {92, 100},
278 {79, 105},
279 {68, 110},
280 {59, 115},
281 {51, 120},
282 {44, 125}
283};
284
200static int vadc_read(struct vadc_priv *vadc, u16 offset, u8 *data) 285static int vadc_read(struct vadc_priv *vadc, u16 offset, u8 *data)
201{ 286{
202 return regmap_bulk_read(vadc->regmap, vadc->base + offset, data, 1); 287 return regmap_bulk_read(vadc->regmap, vadc->base + offset, data, 1);
@@ -418,7 +503,7 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
418 u16 read_1, read_2; 503 u16 read_1, read_2;
419 int ret; 504 int ret;
420 505
421 vadc->graph[VADC_CALIB_RATIOMETRIC].dx = VADC_RATIOMETRIC_RANGE_UV; 506 vadc->graph[VADC_CALIB_RATIOMETRIC].dx = VADC_RATIOMETRIC_RANGE;
422 vadc->graph[VADC_CALIB_ABSOLUTE].dx = VADC_ABSOLUTE_RANGE_UV; 507 vadc->graph[VADC_CALIB_ABSOLUTE].dx = VADC_ABSOLUTE_RANGE_UV;
423 508
424 prop = vadc_get_channel(vadc, VADC_REF_1250MV); 509 prop = vadc_get_channel(vadc, VADC_REF_1250MV);
@@ -468,27 +553,148 @@ err:
468 return ret; 553 return ret;
469} 554}
470 555
471static s32 vadc_calibrate(struct vadc_priv *vadc, 556static int vadc_map_voltage_temp(const struct vadc_map_pt *pts,
472 const struct vadc_channel_prop *prop, u16 adc_code) 557 u32 tablesize, s32 input, s64 *output)
558{
559 bool descending = 1;
560 u32 i = 0;
561
562 if (!pts)
563 return -EINVAL;
564
565 /* Check if table is descending or ascending */
566 if (tablesize > 1) {
567 if (pts[0].x < pts[1].x)
568 descending = 0;
569 }
570
571 while (i < tablesize) {
572 if ((descending) && (pts[i].x < input)) {
573 /* table entry is less than measured*/
574 /* value and table is descending, stop */
575 break;
576 } else if ((!descending) &&
577 (pts[i].x > input)) {
578 /* table entry is greater than measured*/
579 /*value and table is ascending, stop */
580 break;
581 }
582 i++;
583 }
584
585 if (i == 0) {
586 *output = pts[0].y;
587 } else if (i == tablesize) {
588 *output = pts[tablesize - 1].y;
589 } else {
590 /* result is between search_index and search_index-1 */
591 /* interpolate linearly */
592 *output = (((s32)((pts[i].y - pts[i - 1].y) *
593 (input - pts[i - 1].x)) /
594 (pts[i].x - pts[i - 1].x)) +
595 pts[i - 1].y);
596 }
597
598 return 0;
599}
600
601static void vadc_scale_calib(struct vadc_priv *vadc, u16 adc_code,
602 const struct vadc_channel_prop *prop,
603 s64 *scale_voltage)
604{
605 *scale_voltage = (adc_code -
606 vadc->graph[prop->calibration].gnd);
607 *scale_voltage *= vadc->graph[prop->calibration].dx;
608 *scale_voltage = div64_s64(*scale_voltage,
609 vadc->graph[prop->calibration].dy);
610 if (prop->calibration == VADC_CALIB_ABSOLUTE)
611 *scale_voltage +=
612 vadc->graph[prop->calibration].dx;
613
614 if (*scale_voltage < 0)
615 *scale_voltage = 0;
616}
617
618static int vadc_scale_volt(struct vadc_priv *vadc,
619 const struct vadc_channel_prop *prop, u16 adc_code,
620 int *result_uv)
473{ 621{
474 const struct vadc_prescale_ratio *prescale; 622 const struct vadc_prescale_ratio *prescale;
475 s64 voltage; 623 s64 voltage = 0, result = 0;
476 624
477 voltage = adc_code - vadc->graph[prop->calibration].gnd; 625 vadc_scale_calib(vadc, adc_code, prop, &voltage);
478 voltage *= vadc->graph[prop->calibration].dx; 626
479 voltage = div64_s64(voltage, vadc->graph[prop->calibration].dy); 627 prescale = &vadc_prescale_ratios[prop->prescale];
628 voltage = voltage * prescale->den;
629 result = div64_s64(voltage, prescale->num);
630 *result_uv = result;
631
632 return 0;
633}
634
635static int vadc_scale_therm(struct vadc_priv *vadc,
636 const struct vadc_channel_prop *prop, u16 adc_code,
637 int *result_mdec)
638{
639 s64 voltage = 0, result = 0;
640
641 vadc_scale_calib(vadc, adc_code, prop, &voltage);
480 642
481 if (prop->calibration == VADC_CALIB_ABSOLUTE) 643 if (prop->calibration == VADC_CALIB_ABSOLUTE)
482 voltage += vadc->graph[prop->calibration].dx; 644 voltage = div64_s64(voltage, 1000);
645
646 vadc_map_voltage_temp(adcmap_100k_104ef_104fb,
647 ARRAY_SIZE(adcmap_100k_104ef_104fb),
648 voltage, &result);
649 result *= 1000;
650 *result_mdec = result;
483 651
484 if (voltage < 0) 652 return 0;
653}
654
655static int vadc_scale_die_temp(struct vadc_priv *vadc,
656 const struct vadc_channel_prop *prop,
657 u16 adc_code, int *result_mdec)
658{
659 const struct vadc_prescale_ratio *prescale;
660 s64 voltage = 0;
661 u64 temp; /* Temporary variable for do_div */
662
663 vadc_scale_calib(vadc, adc_code, prop, &voltage);
664
665 if (voltage > 0) {
666 prescale = &vadc_prescale_ratios[prop->prescale];
667 temp = voltage * prescale->den;
668 do_div(temp, prescale->num * 2);
669 voltage = temp;
670 } else {
485 voltage = 0; 671 voltage = 0;
672 }
486 673
487 prescale = &vadc_prescale_ratios[prop->prescale]; 674 voltage -= KELVINMIL_CELSIUSMIL;
675 *result_mdec = voltage;
676
677 return 0;
678}
679
680static int vadc_scale_chg_temp(struct vadc_priv *vadc,
681 const struct vadc_channel_prop *prop,
682 u16 adc_code, int *result_mdec)
683{
684 const struct vadc_prescale_ratio *prescale;
685 s64 voltage = 0, result = 0;
488 686
687 vadc_scale_calib(vadc, adc_code, prop, &voltage);
688
689 prescale = &vadc_prescale_ratios[prop->prescale];
489 voltage = voltage * prescale->den; 690 voltage = voltage * prescale->den;
691 voltage = div64_s64(voltage, prescale->num);
692 voltage = ((PMI_CHG_SCALE_1) * (voltage * 2));
693 voltage = (voltage + PMI_CHG_SCALE_2);
694 result = div64_s64(voltage, 1000000);
695 *result_mdec = result;
490 696
491 return div64_s64(voltage, prescale->num); 697 return 0;
492} 698}
493 699
494static int vadc_decimation_from_dt(u32 value) 700static int vadc_decimation_from_dt(u32 value)
@@ -536,6 +742,14 @@ static int vadc_avg_samples_from_dt(u32 value)
536 return __ffs64(value); 742 return __ffs64(value);
537} 743}
538 744
745static struct vadc_scale_fn scale_fn[] = {
746 [SCALE_DEFAULT] = {vadc_scale_volt},
747 [SCALE_THERM_100K_PULLUP] = {vadc_scale_therm},
748 [SCALE_PMIC_THERM] = {vadc_scale_die_temp},
749 [SCALE_XOTHERM] = {vadc_scale_therm},
750 [SCALE_PMI_CHG_TEMP] = {vadc_scale_chg_temp},
751};
752
539static int vadc_read_raw(struct iio_dev *indio_dev, 753static int vadc_read_raw(struct iio_dev *indio_dev,
540 struct iio_chan_spec const *chan, int *val, int *val2, 754 struct iio_chan_spec const *chan, int *val, int *val2,
541 long mask) 755 long mask)
@@ -552,11 +766,8 @@ static int vadc_read_raw(struct iio_dev *indio_dev,
552 if (ret) 766 if (ret)
553 break; 767 break;
554 768
555 *val = vadc_calibrate(vadc, prop, adc_code); 769 scale_fn[prop->scale_fn].scale(vadc, prop, adc_code, val);
556 770
557 /* 2mV/K, return milli Celsius */
558 *val /= 2;
559 *val -= KELVINMIL_CELSIUSMIL;
560 return IIO_VAL_INT; 771 return IIO_VAL_INT;
561 case IIO_CHAN_INFO_RAW: 772 case IIO_CHAN_INFO_RAW:
562 prop = &vadc->chan_props[chan->address]; 773 prop = &vadc->chan_props[chan->address];
@@ -564,12 +775,8 @@ static int vadc_read_raw(struct iio_dev *indio_dev,
564 if (ret) 775 if (ret)
565 break; 776 break;
566 777
567 *val = vadc_calibrate(vadc, prop, adc_code); 778 *val = (int)adc_code;
568 return IIO_VAL_INT; 779 return IIO_VAL_INT;
569 case IIO_CHAN_INFO_SCALE:
570 *val = 0;
571 *val2 = 1000;
572 return IIO_VAL_INT_PLUS_MICRO;
573 default: 780 default:
574 ret = -EINVAL; 781 ret = -EINVAL;
575 break; 782 break;
@@ -602,22 +809,39 @@ struct vadc_channels {
602 unsigned int prescale_index; 809 unsigned int prescale_index;
603 enum iio_chan_type type; 810 enum iio_chan_type type;
604 long info_mask; 811 long info_mask;
812 unsigned int scale_fn;
605}; 813};
606 814
607#define VADC_CHAN(_dname, _type, _mask, _pre) \ 815#define VADC_CHAN(_dname, _type, _mask, _pre, _scale) \
608 [VADC_##_dname] = { \ 816 [VADC_##_dname] = { \
609 .datasheet_name = __stringify(_dname), \ 817 .datasheet_name = __stringify(_dname), \
610 .prescale_index = _pre, \ 818 .prescale_index = _pre, \
611 .type = _type, \ 819 .type = _type, \
612 .info_mask = _mask \ 820 .info_mask = _mask, \
821 .scale_fn = _scale \
613 }, \ 822 }, \
614 823
615#define VADC_CHAN_TEMP(_dname, _pre) \ 824#define VADC_NO_CHAN(_dname, _type, _mask, _pre) \
616 VADC_CHAN(_dname, IIO_TEMP, BIT(IIO_CHAN_INFO_PROCESSED), _pre) \ 825 [VADC_##_dname] = { \
826 .datasheet_name = __stringify(_dname), \
827 .prescale_index = _pre, \
828 .type = _type, \
829 .info_mask = _mask \
830 },
617 831
618#define VADC_CHAN_VOLT(_dname, _pre) \ 832#define VADC_CHAN_TEMP(_dname, _pre, _scale) \
833 VADC_CHAN(_dname, IIO_TEMP, \
834 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_PROCESSED), \
835 _pre, _scale) \
836
837#define VADC_CHAN_VOLT(_dname, _pre, _scale) \
619 VADC_CHAN(_dname, IIO_VOLTAGE, \ 838 VADC_CHAN(_dname, IIO_VOLTAGE, \
620 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \ 839 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_PROCESSED),\
840 _pre, _scale) \
841
842#define VADC_CHAN_NO_SCALE(_dname, _pre) \
843 VADC_NO_CHAN(_dname, IIO_VOLTAGE, \
844 BIT(IIO_CHAN_INFO_RAW), \
621 _pre) \ 845 _pre) \
622 846
623/* 847/*
@@ -626,106 +850,106 @@ struct vadc_channels {
626 * gaps in the array should be treated as reserved channels. 850 * gaps in the array should be treated as reserved channels.
627 */ 851 */
628static const struct vadc_channels vadc_chans[] = { 852static const struct vadc_channels vadc_chans[] = {
629 VADC_CHAN_VOLT(USBIN, 4) 853 VADC_CHAN_VOLT(USBIN, 4, SCALE_DEFAULT)
630 VADC_CHAN_VOLT(DCIN, 4) 854 VADC_CHAN_VOLT(DCIN, 4, SCALE_DEFAULT)
631 VADC_CHAN_VOLT(VCHG_SNS, 3) 855 VADC_CHAN_NO_SCALE(VCHG_SNS, 3)
632 VADC_CHAN_VOLT(SPARE1_03, 1) 856 VADC_CHAN_NO_SCALE(SPARE1_03, 1)
633 VADC_CHAN_VOLT(USB_ID_MV, 1) 857 VADC_CHAN_NO_SCALE(USB_ID_MV, 1)
634 VADC_CHAN_VOLT(VCOIN, 1) 858 VADC_CHAN_VOLT(VCOIN, 1, SCALE_DEFAULT)
635 VADC_CHAN_VOLT(VBAT_SNS, 1) 859 VADC_CHAN_NO_SCALE(VBAT_SNS, 1)
636 VADC_CHAN_VOLT(VSYS, 1) 860 VADC_CHAN_VOLT(VSYS, 1, SCALE_DEFAULT)
637 VADC_CHAN_TEMP(DIE_TEMP, 0) 861 VADC_CHAN_TEMP(DIE_TEMP, 0, SCALE_PMIC_THERM)
638 VADC_CHAN_VOLT(REF_625MV, 0) 862 VADC_CHAN_VOLT(REF_625MV, 0, SCALE_DEFAULT)
639 VADC_CHAN_VOLT(REF_1250MV, 0) 863 VADC_CHAN_VOLT(REF_1250MV, 0, SCALE_DEFAULT)
640 VADC_CHAN_VOLT(CHG_TEMP, 0) 864 VADC_CHAN_NO_SCALE(CHG_TEMP, 0)
641 VADC_CHAN_VOLT(SPARE1, 0) 865 VADC_CHAN_NO_SCALE(SPARE1, 0)
642 VADC_CHAN_VOLT(SPARE2, 0) 866 VADC_CHAN_TEMP(SPARE2, 0, SCALE_PMI_CHG_TEMP)
643 VADC_CHAN_VOLT(GND_REF, 0) 867 VADC_CHAN_VOLT(GND_REF, 0, SCALE_DEFAULT)
644 VADC_CHAN_VOLT(VDD_VADC, 0) 868 VADC_CHAN_VOLT(VDD_VADC, 0, SCALE_DEFAULT)
645 869
646 VADC_CHAN_VOLT(P_MUX1_1_1, 0) 870 VADC_CHAN_NO_SCALE(P_MUX1_1_1, 0)
647 VADC_CHAN_VOLT(P_MUX2_1_1, 0) 871 VADC_CHAN_NO_SCALE(P_MUX2_1_1, 0)
648 VADC_CHAN_VOLT(P_MUX3_1_1, 0) 872 VADC_CHAN_NO_SCALE(P_MUX3_1_1, 0)
649 VADC_CHAN_VOLT(P_MUX4_1_1, 0) 873 VADC_CHAN_NO_SCALE(P_MUX4_1_1, 0)
650 VADC_CHAN_VOLT(P_MUX5_1_1, 0) 874 VADC_CHAN_NO_SCALE(P_MUX5_1_1, 0)
651 VADC_CHAN_VOLT(P_MUX6_1_1, 0) 875 VADC_CHAN_NO_SCALE(P_MUX6_1_1, 0)
652 VADC_CHAN_VOLT(P_MUX7_1_1, 0) 876 VADC_CHAN_NO_SCALE(P_MUX7_1_1, 0)
653 VADC_CHAN_VOLT(P_MUX8_1_1, 0) 877 VADC_CHAN_NO_SCALE(P_MUX8_1_1, 0)
654 VADC_CHAN_VOLT(P_MUX9_1_1, 0) 878 VADC_CHAN_NO_SCALE(P_MUX9_1_1, 0)
655 VADC_CHAN_VOLT(P_MUX10_1_1, 0) 879 VADC_CHAN_NO_SCALE(P_MUX10_1_1, 0)
656 VADC_CHAN_VOLT(P_MUX11_1_1, 0) 880 VADC_CHAN_NO_SCALE(P_MUX11_1_1, 0)
657 VADC_CHAN_VOLT(P_MUX12_1_1, 0) 881 VADC_CHAN_NO_SCALE(P_MUX12_1_1, 0)
658 VADC_CHAN_VOLT(P_MUX13_1_1, 0) 882 VADC_CHAN_NO_SCALE(P_MUX13_1_1, 0)
659 VADC_CHAN_VOLT(P_MUX14_1_1, 0) 883 VADC_CHAN_NO_SCALE(P_MUX14_1_1, 0)
660 VADC_CHAN_VOLT(P_MUX15_1_1, 0) 884 VADC_CHAN_NO_SCALE(P_MUX15_1_1, 0)
661 VADC_CHAN_VOLT(P_MUX16_1_1, 0) 885 VADC_CHAN_NO_SCALE(P_MUX16_1_1, 0)
662 886
663 VADC_CHAN_VOLT(P_MUX1_1_3, 1) 887 VADC_CHAN_NO_SCALE(P_MUX1_1_3, 1)
664 VADC_CHAN_VOLT(P_MUX2_1_3, 1) 888 VADC_CHAN_NO_SCALE(P_MUX2_1_3, 1)
665 VADC_CHAN_VOLT(P_MUX3_1_3, 1) 889 VADC_CHAN_NO_SCALE(P_MUX3_1_3, 1)
666 VADC_CHAN_VOLT(P_MUX4_1_3, 1) 890 VADC_CHAN_NO_SCALE(P_MUX4_1_3, 1)
667 VADC_CHAN_VOLT(P_MUX5_1_3, 1) 891 VADC_CHAN_NO_SCALE(P_MUX5_1_3, 1)
668 VADC_CHAN_VOLT(P_MUX6_1_3, 1) 892 VADC_CHAN_NO_SCALE(P_MUX6_1_3, 1)
669 VADC_CHAN_VOLT(P_MUX7_1_3, 1) 893 VADC_CHAN_NO_SCALE(P_MUX7_1_3, 1)
670 VADC_CHAN_VOLT(P_MUX8_1_3, 1) 894 VADC_CHAN_NO_SCALE(P_MUX8_1_3, 1)
671 VADC_CHAN_VOLT(P_MUX9_1_3, 1) 895 VADC_CHAN_NO_SCALE(P_MUX9_1_3, 1)
672 VADC_CHAN_VOLT(P_MUX10_1_3, 1) 896 VADC_CHAN_NO_SCALE(P_MUX10_1_3, 1)
673 VADC_CHAN_VOLT(P_MUX11_1_3, 1) 897 VADC_CHAN_NO_SCALE(P_MUX11_1_3, 1)
674 VADC_CHAN_VOLT(P_MUX12_1_3, 1) 898 VADC_CHAN_NO_SCALE(P_MUX12_1_3, 1)
675 VADC_CHAN_VOLT(P_MUX13_1_3, 1) 899 VADC_CHAN_NO_SCALE(P_MUX13_1_3, 1)
676 VADC_CHAN_VOLT(P_MUX14_1_3, 1) 900 VADC_CHAN_NO_SCALE(P_MUX14_1_3, 1)
677 VADC_CHAN_VOLT(P_MUX15_1_3, 1) 901 VADC_CHAN_NO_SCALE(P_MUX15_1_3, 1)
678 VADC_CHAN_VOLT(P_MUX16_1_3, 1) 902 VADC_CHAN_NO_SCALE(P_MUX16_1_3, 1)
679 903
680 VADC_CHAN_VOLT(LR_MUX1_BAT_THERM, 0) 904 VADC_CHAN_NO_SCALE(LR_MUX1_BAT_THERM, 0)
681 VADC_CHAN_VOLT(LR_MUX2_BAT_ID, 0) 905 VADC_CHAN_NO_SCALE(LR_MUX2_BAT_ID, 0)
682 VADC_CHAN_VOLT(LR_MUX3_XO_THERM, 0) 906 VADC_CHAN_NO_SCALE(LR_MUX3_XO_THERM, 0)
683 VADC_CHAN_VOLT(LR_MUX4_AMUX_THM1, 0) 907 VADC_CHAN_NO_SCALE(LR_MUX4_AMUX_THM1, 0)
684 VADC_CHAN_VOLT(LR_MUX5_AMUX_THM2, 0) 908 VADC_CHAN_NO_SCALE(LR_MUX5_AMUX_THM2, 0)
685 VADC_CHAN_VOLT(LR_MUX6_AMUX_THM3, 0) 909 VADC_CHAN_NO_SCALE(LR_MUX6_AMUX_THM3, 0)
686 VADC_CHAN_VOLT(LR_MUX7_HW_ID, 0) 910 VADC_CHAN_NO_SCALE(LR_MUX7_HW_ID, 0)
687 VADC_CHAN_VOLT(LR_MUX8_AMUX_THM4, 0) 911 VADC_CHAN_NO_SCALE(LR_MUX8_AMUX_THM4, 0)
688 VADC_CHAN_VOLT(LR_MUX9_AMUX_THM5, 0) 912 VADC_CHAN_NO_SCALE(LR_MUX9_AMUX_THM5, 0)
689 VADC_CHAN_VOLT(LR_MUX10_USB_ID, 0) 913 VADC_CHAN_NO_SCALE(LR_MUX10_USB_ID, 0)
690 VADC_CHAN_VOLT(AMUX_PU1, 0) 914 VADC_CHAN_NO_SCALE(AMUX_PU1, 0)
691 VADC_CHAN_VOLT(AMUX_PU2, 0) 915 VADC_CHAN_NO_SCALE(AMUX_PU2, 0)
692 VADC_CHAN_VOLT(LR_MUX3_BUF_XO_THERM, 0) 916 VADC_CHAN_NO_SCALE(LR_MUX3_BUF_XO_THERM, 0)
693 917
694 VADC_CHAN_VOLT(LR_MUX1_PU1_BAT_THERM, 0) 918 VADC_CHAN_NO_SCALE(LR_MUX1_PU1_BAT_THERM, 0)
695 VADC_CHAN_VOLT(LR_MUX2_PU1_BAT_ID, 0) 919 VADC_CHAN_NO_SCALE(LR_MUX2_PU1_BAT_ID, 0)
696 VADC_CHAN_VOLT(LR_MUX3_PU1_XO_THERM, 0) 920 VADC_CHAN_NO_SCALE(LR_MUX3_PU1_XO_THERM, 0)
697 VADC_CHAN_VOLT(LR_MUX4_PU1_AMUX_THM1, 0) 921 VADC_CHAN_TEMP(LR_MUX4_PU1_AMUX_THM1, 0, SCALE_THERM_100K_PULLUP)
698 VADC_CHAN_VOLT(LR_MUX5_PU1_AMUX_THM2, 0) 922 VADC_CHAN_TEMP(LR_MUX5_PU1_AMUX_THM2, 0, SCALE_THERM_100K_PULLUP)
699 VADC_CHAN_VOLT(LR_MUX6_PU1_AMUX_THM3, 0) 923 VADC_CHAN_TEMP(LR_MUX6_PU1_AMUX_THM3, 0, SCALE_THERM_100K_PULLUP)
700 VADC_CHAN_VOLT(LR_MUX7_PU1_AMUX_HW_ID, 0) 924 VADC_CHAN_NO_SCALE(LR_MUX7_PU1_AMUX_HW_ID, 0)
701 VADC_CHAN_VOLT(LR_MUX8_PU1_AMUX_THM4, 0) 925 VADC_CHAN_TEMP(LR_MUX8_PU1_AMUX_THM4, 0, SCALE_THERM_100K_PULLUP)
702 VADC_CHAN_VOLT(LR_MUX9_PU1_AMUX_THM5, 0) 926 VADC_CHAN_TEMP(LR_MUX9_PU1_AMUX_THM5, 0, SCALE_THERM_100K_PULLUP)
703 VADC_CHAN_VOLT(LR_MUX10_PU1_AMUX_USB_ID, 0) 927 VADC_CHAN_NO_SCALE(LR_MUX10_PU1_AMUX_USB_ID, 0)
704 VADC_CHAN_VOLT(LR_MUX3_BUF_PU1_XO_THERM, 0) 928 VADC_CHAN_TEMP(LR_MUX3_BUF_PU1_XO_THERM, 0, SCALE_XOTHERM)
705 929
706 VADC_CHAN_VOLT(LR_MUX1_PU2_BAT_THERM, 0) 930 VADC_CHAN_NO_SCALE(LR_MUX1_PU2_BAT_THERM, 0)
707 VADC_CHAN_VOLT(LR_MUX2_PU2_BAT_ID, 0) 931 VADC_CHAN_NO_SCALE(LR_MUX2_PU2_BAT_ID, 0)
708 VADC_CHAN_VOLT(LR_MUX3_PU2_XO_THERM, 0) 932 VADC_CHAN_NO_SCALE(LR_MUX3_PU2_XO_THERM, 0)
709 VADC_CHAN_VOLT(LR_MUX4_PU2_AMUX_THM1, 0) 933 VADC_CHAN_NO_SCALE(LR_MUX4_PU2_AMUX_THM1, 0)
710 VADC_CHAN_VOLT(LR_MUX5_PU2_AMUX_THM2, 0) 934 VADC_CHAN_NO_SCALE(LR_MUX5_PU2_AMUX_THM2, 0)
711 VADC_CHAN_VOLT(LR_MUX6_PU2_AMUX_THM3, 0) 935 VADC_CHAN_NO_SCALE(LR_MUX6_PU2_AMUX_THM3, 0)
712 VADC_CHAN_VOLT(LR_MUX7_PU2_AMUX_HW_ID, 0) 936 VADC_CHAN_NO_SCALE(LR_MUX7_PU2_AMUX_HW_ID, 0)
713 VADC_CHAN_VOLT(LR_MUX8_PU2_AMUX_THM4, 0) 937 VADC_CHAN_NO_SCALE(LR_MUX8_PU2_AMUX_THM4, 0)
714 VADC_CHAN_VOLT(LR_MUX9_PU2_AMUX_THM5, 0) 938 VADC_CHAN_NO_SCALE(LR_MUX9_PU2_AMUX_THM5, 0)
715 VADC_CHAN_VOLT(LR_MUX10_PU2_AMUX_USB_ID, 0) 939 VADC_CHAN_NO_SCALE(LR_MUX10_PU2_AMUX_USB_ID, 0)
716 VADC_CHAN_VOLT(LR_MUX3_BUF_PU2_XO_THERM, 0) 940 VADC_CHAN_NO_SCALE(LR_MUX3_BUF_PU2_XO_THERM, 0)
717 941
718 VADC_CHAN_VOLT(LR_MUX1_PU1_PU2_BAT_THERM, 0) 942 VADC_CHAN_NO_SCALE(LR_MUX1_PU1_PU2_BAT_THERM, 0)
719 VADC_CHAN_VOLT(LR_MUX2_PU1_PU2_BAT_ID, 0) 943 VADC_CHAN_NO_SCALE(LR_MUX2_PU1_PU2_BAT_ID, 0)
720 VADC_CHAN_VOLT(LR_MUX3_PU1_PU2_XO_THERM, 0) 944 VADC_CHAN_NO_SCALE(LR_MUX3_PU1_PU2_XO_THERM, 0)
721 VADC_CHAN_VOLT(LR_MUX4_PU1_PU2_AMUX_THM1, 0) 945 VADC_CHAN_NO_SCALE(LR_MUX4_PU1_PU2_AMUX_THM1, 0)
722 VADC_CHAN_VOLT(LR_MUX5_PU1_PU2_AMUX_THM2, 0) 946 VADC_CHAN_NO_SCALE(LR_MUX5_PU1_PU2_AMUX_THM2, 0)
723 VADC_CHAN_VOLT(LR_MUX6_PU1_PU2_AMUX_THM3, 0) 947 VADC_CHAN_NO_SCALE(LR_MUX6_PU1_PU2_AMUX_THM3, 0)
724 VADC_CHAN_VOLT(LR_MUX7_PU1_PU2_AMUX_HW_ID, 0) 948 VADC_CHAN_NO_SCALE(LR_MUX7_PU1_PU2_AMUX_HW_ID, 0)
725 VADC_CHAN_VOLT(LR_MUX8_PU1_PU2_AMUX_THM4, 0) 949 VADC_CHAN_NO_SCALE(LR_MUX8_PU1_PU2_AMUX_THM4, 0)
726 VADC_CHAN_VOLT(LR_MUX9_PU1_PU2_AMUX_THM5, 0) 950 VADC_CHAN_NO_SCALE(LR_MUX9_PU1_PU2_AMUX_THM5, 0)
727 VADC_CHAN_VOLT(LR_MUX10_PU1_PU2_AMUX_USB_ID, 0) 951 VADC_CHAN_NO_SCALE(LR_MUX10_PU1_PU2_AMUX_USB_ID, 0)
728 VADC_CHAN_VOLT(LR_MUX3_BUF_PU1_PU2_XO_THERM, 0) 952 VADC_CHAN_NO_SCALE(LR_MUX3_BUF_PU1_PU2_XO_THERM, 0)
729}; 953};
730 954
731static int vadc_get_dt_channel_data(struct device *dev, 955static int vadc_get_dt_channel_data(struct device *dev,
@@ -844,6 +1068,7 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
844 return ret; 1068 return ret;
845 } 1069 }
846 1070
1071 prop.scale_fn = vadc_chans[prop.channel].scale_fn;
847 vadc->chan_props[index] = prop; 1072 vadc->chan_props[index] = prop;
848 1073
849 vadc_chan = &vadc_chans[prop.channel]; 1074 vadc_chan = &vadc_chans[prop.channel];
diff --git a/drivers/iio/adc/rcar-gyroadc.c b/drivers/iio/adc/rcar-gyroadc.c
new file mode 100644
index 000000000000..0c44f72c32a8
--- /dev/null
+++ b/drivers/iio/adc/rcar-gyroadc.c
@@ -0,0 +1,631 @@
1/*
2 * Renesas R-Car GyroADC driver
3 *
4 * Copyright 2016 Marek Vasut <marek.vasut@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/delay.h>
20#include <linux/kernel.h>
21#include <linux/slab.h>
22#include <linux/io.h>
23#include <linux/clk.h>
24#include <linux/of.h>
25#include <linux/of_irq.h>
26#include <linux/regulator/consumer.h>
27#include <linux/of_platform.h>
28#include <linux/err.h>
29#include <linux/pm_runtime.h>
30
31#include <linux/iio/iio.h>
32#include <linux/iio/sysfs.h>
33#include <linux/iio/trigger.h>
34
35#define DRIVER_NAME "rcar-gyroadc"
36
37/* GyroADC registers. */
38#define RCAR_GYROADC_MODE_SELECT 0x00
39#define RCAR_GYROADC_MODE_SELECT_1_MB88101A 0x0
40#define RCAR_GYROADC_MODE_SELECT_2_ADCS7476 0x1
41#define RCAR_GYROADC_MODE_SELECT_3_MAX1162 0x3
42
43#define RCAR_GYROADC_START_STOP 0x04
44#define RCAR_GYROADC_START_STOP_START BIT(0)
45
46#define RCAR_GYROADC_CLOCK_LENGTH 0x08
47#define RCAR_GYROADC_1_25MS_LENGTH 0x0c
48
49#define RCAR_GYROADC_REALTIME_DATA(ch) (0x10 + ((ch) * 4))
50#define RCAR_GYROADC_100MS_ADDED_DATA(ch) (0x30 + ((ch) * 4))
51#define RCAR_GYROADC_10MS_AVG_DATA(ch) (0x50 + ((ch) * 4))
52
53#define RCAR_GYROADC_FIFO_STATUS 0x70
54#define RCAR_GYROADC_FIFO_STATUS_EMPTY(ch) BIT(0 + (4 * (ch)))
55#define RCAR_GYROADC_FIFO_STATUS_FULL(ch) BIT(1 + (4 * (ch)))
56#define RCAR_GYROADC_FIFO_STATUS_ERROR(ch) BIT(2 + (4 * (ch)))
57
58#define RCAR_GYROADC_INTR 0x74
59#define RCAR_GYROADC_INTR_INT BIT(0)
60
61#define RCAR_GYROADC_INTENR 0x78
62#define RCAR_GYROADC_INTENR_INTEN BIT(0)
63
64#define RCAR_GYROADC_SAMPLE_RATE 800 /* Hz */
65
66#define RCAR_GYROADC_RUNTIME_PM_DELAY_MS 2000
67
68enum rcar_gyroadc_model {
69 RCAR_GYROADC_MODEL_DEFAULT,
70 RCAR_GYROADC_MODEL_R8A7792,
71};
72
73struct rcar_gyroadc {
74 struct device *dev;
75 void __iomem *regs;
76 struct clk *iclk;
77 struct regulator *vref[8];
78 unsigned int num_channels;
79 enum rcar_gyroadc_model model;
80 unsigned int mode;
81 unsigned int sample_width;
82};
83
84static void rcar_gyroadc_hw_init(struct rcar_gyroadc *priv)
85{
86 const unsigned long clk_mhz = clk_get_rate(priv->iclk) / 1000000;
87 const unsigned long clk_mul =
88 (priv->mode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) ? 10 : 5;
89 unsigned long clk_len = clk_mhz * clk_mul;
90
91 /*
92 * According to the R-Car Gen2 datasheet Rev. 1.01, Sept 08 2014,
93 * page 77-7, clock length must be even number. If it's odd number,
94 * add one.
95 */
96 if (clk_len & 1)
97 clk_len++;
98
99 /* Stop the GyroADC. */
100 writel(0, priv->regs + RCAR_GYROADC_START_STOP);
101
102 /* Disable IRQ on V2H. */
103 if (priv->model == RCAR_GYROADC_MODEL_R8A7792)
104 writel(0, priv->regs + RCAR_GYROADC_INTENR);
105
106 /* Set mode and timing. */
107 writel(priv->mode, priv->regs + RCAR_GYROADC_MODE_SELECT);
108 writel(clk_len, priv->regs + RCAR_GYROADC_CLOCK_LENGTH);
109 writel(clk_mhz * 1250, priv->regs + RCAR_GYROADC_1_25MS_LENGTH);
110}
111
112static void rcar_gyroadc_hw_start(struct rcar_gyroadc *priv)
113{
114 /* Start sampling. */
115 writel(RCAR_GYROADC_START_STOP_START,
116 priv->regs + RCAR_GYROADC_START_STOP);
117
118 /*
119 * Wait for the first conversion to complete. This is longer than
120 * the 1.25 mS in the datasheet because 1.25 mS is not enough for
121 * the hardware to deliver the first sample and the hardware does
122 * then return zeroes instead of valid data.
123 */
124 mdelay(3);
125}
126
127static void rcar_gyroadc_hw_stop(struct rcar_gyroadc *priv)
128{
129 /* Stop the GyroADC. */
130 writel(0, priv->regs + RCAR_GYROADC_START_STOP);
131}
132
133#define RCAR_GYROADC_CHAN(_idx) { \
134 .type = IIO_VOLTAGE, \
135 .indexed = 1, \
136 .channel = (_idx), \
137 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
138 BIT(IIO_CHAN_INFO_SCALE), \
139 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
140}
141
142static const struct iio_chan_spec rcar_gyroadc_iio_channels_1[] = {
143 RCAR_GYROADC_CHAN(0),
144 RCAR_GYROADC_CHAN(1),
145 RCAR_GYROADC_CHAN(2),
146 RCAR_GYROADC_CHAN(3),
147};
148
149static const struct iio_chan_spec rcar_gyroadc_iio_channels_2[] = {
150 RCAR_GYROADC_CHAN(0),
151 RCAR_GYROADC_CHAN(1),
152 RCAR_GYROADC_CHAN(2),
153 RCAR_GYROADC_CHAN(3),
154 RCAR_GYROADC_CHAN(4),
155 RCAR_GYROADC_CHAN(5),
156 RCAR_GYROADC_CHAN(6),
157 RCAR_GYROADC_CHAN(7),
158};
159
160static const struct iio_chan_spec rcar_gyroadc_iio_channels_3[] = {
161 RCAR_GYROADC_CHAN(0),
162 RCAR_GYROADC_CHAN(1),
163 RCAR_GYROADC_CHAN(2),
164 RCAR_GYROADC_CHAN(3),
165 RCAR_GYROADC_CHAN(4),
166 RCAR_GYROADC_CHAN(5),
167 RCAR_GYROADC_CHAN(6),
168 RCAR_GYROADC_CHAN(7),
169};
170
171static int rcar_gyroadc_set_power(struct rcar_gyroadc *priv, bool on)
172{
173 struct device *dev = priv->dev;
174 int ret;
175
176 if (on) {
177 ret = pm_runtime_get_sync(dev);
178 if (ret < 0)
179 pm_runtime_put_noidle(dev);
180 } else {
181 pm_runtime_mark_last_busy(dev);
182 ret = pm_runtime_put_autosuspend(dev);
183 }
184
185 return ret;
186}
187
188static int rcar_gyroadc_read_raw(struct iio_dev *indio_dev,
189 struct iio_chan_spec const *chan,
190 int *val, int *val2, long mask)
191{
192 struct rcar_gyroadc *priv = iio_priv(indio_dev);
193 struct regulator *consumer;
194 unsigned int datareg = RCAR_GYROADC_REALTIME_DATA(chan->channel);
195 unsigned int vref;
196 int ret;
197
198 /*
199 * MB88101 is special in that it has only single regulator for
200 * all four channels.
201 */
202 if (priv->mode == RCAR_GYROADC_MODE_SELECT_1_MB88101A)
203 consumer = priv->vref[0];
204 else
205 consumer = priv->vref[chan->channel];
206
207 switch (mask) {
208 case IIO_CHAN_INFO_RAW:
209 if (chan->type != IIO_VOLTAGE)
210 return -EINVAL;
211
212 /* Channel not connected. */
213 if (!consumer)
214 return -EINVAL;
215
216 ret = iio_device_claim_direct_mode(indio_dev);
217 if (ret)
218 return ret;
219
220 ret = rcar_gyroadc_set_power(priv, true);
221 if (ret < 0) {
222 iio_device_release_direct_mode(indio_dev);
223 return ret;
224 }
225
226 *val = readl(priv->regs + datareg);
227 *val &= BIT(priv->sample_width) - 1;
228
229 ret = rcar_gyroadc_set_power(priv, false);
230 iio_device_release_direct_mode(indio_dev);
231 if (ret < 0)
232 return ret;
233
234 return IIO_VAL_INT;
235 case IIO_CHAN_INFO_SCALE:
236 /* Channel not connected. */
237 if (!consumer)
238 return -EINVAL;
239
240 vref = regulator_get_voltage(consumer);
241 *val = vref / 1000;
242 *val2 = 1 << priv->sample_width;
243
244 return IIO_VAL_FRACTIONAL;
245 case IIO_CHAN_INFO_SAMP_FREQ:
246 *val = RCAR_GYROADC_SAMPLE_RATE;
247
248 return IIO_VAL_INT;
249 default:
250 return -EINVAL;
251 }
252}
253
254static int rcar_gyroadc_reg_access(struct iio_dev *indio_dev,
255 unsigned int reg, unsigned int writeval,
256 unsigned int *readval)
257{
258 struct rcar_gyroadc *priv = iio_priv(indio_dev);
259 unsigned int maxreg = RCAR_GYROADC_FIFO_STATUS;
260
261 if (readval == NULL)
262 return -EINVAL;
263
264 if (reg % 4)
265 return -EINVAL;
266
267 /* Handle the V2H case with extra interrupt block. */
268 if (priv->model == RCAR_GYROADC_MODEL_R8A7792)
269 maxreg = RCAR_GYROADC_INTENR;
270
271 if (reg > maxreg)
272 return -EINVAL;
273
274 *readval = readl(priv->regs + reg);
275
276 return 0;
277}
278
279static const struct iio_info rcar_gyroadc_iio_info = {
280 .driver_module = THIS_MODULE,
281 .read_raw = rcar_gyroadc_read_raw,
282 .debugfs_reg_access = rcar_gyroadc_reg_access,
283};
284
285static const struct of_device_id rcar_gyroadc_match[] = {
286 {
287 /* R-Car compatible GyroADC */
288 .compatible = "renesas,rcar-gyroadc",
289 .data = (void *)RCAR_GYROADC_MODEL_DEFAULT,
290 }, {
291 /* R-Car V2H specialty with interrupt registers. */
292 .compatible = "renesas,r8a7792-gyroadc",
293 .data = (void *)RCAR_GYROADC_MODEL_R8A7792,
294 }, {
295 /* sentinel */
296 }
297};
298
299MODULE_DEVICE_TABLE(of, rcar_gyroadc_match);
300
301static const struct of_device_id rcar_gyroadc_child_match[] = {
302 /* Mode 1 ADCs */
303 {
304 .compatible = "fujitsu,mb88101a",
305 .data = (void *)RCAR_GYROADC_MODE_SELECT_1_MB88101A,
306 },
307 /* Mode 2 ADCs */
308 {
309 .compatible = "ti,adcs7476",
310 .data = (void *)RCAR_GYROADC_MODE_SELECT_2_ADCS7476,
311 }, {
312 .compatible = "ti,adc121",
313 .data = (void *)RCAR_GYROADC_MODE_SELECT_2_ADCS7476,
314 }, {
315 .compatible = "adi,ad7476",
316 .data = (void *)RCAR_GYROADC_MODE_SELECT_2_ADCS7476,
317 },
318 /* Mode 3 ADCs */
319 {
320 .compatible = "maxim,max1162",
321 .data = (void *)RCAR_GYROADC_MODE_SELECT_3_MAX1162,
322 }, {
323 .compatible = "maxim,max11100",
324 .data = (void *)RCAR_GYROADC_MODE_SELECT_3_MAX1162,
325 },
326 { /* sentinel */ }
327};
328
329static int rcar_gyroadc_parse_subdevs(struct iio_dev *indio_dev)
330{
331 const struct of_device_id *of_id;
332 const struct iio_chan_spec *channels;
333 struct rcar_gyroadc *priv = iio_priv(indio_dev);
334 struct device *dev = priv->dev;
335 struct device_node *np = dev->of_node;
336 struct device_node *child;
337 struct regulator *vref;
338 unsigned int reg;
339 unsigned int adcmode, childmode;
340 unsigned int sample_width;
341 unsigned int num_channels;
342 int ret, first = 1;
343
344 for_each_child_of_node(np, child) {
345 of_id = of_match_node(rcar_gyroadc_child_match, child);
346 if (!of_id) {
347 dev_err(dev, "Ignoring unsupported ADC \"%s\".",
348 child->name);
349 continue;
350 }
351
352 childmode = (unsigned int)of_id->data;
353 switch (childmode) {
354 case RCAR_GYROADC_MODE_SELECT_1_MB88101A:
355 sample_width = 12;
356 channels = rcar_gyroadc_iio_channels_1;
357 num_channels = ARRAY_SIZE(rcar_gyroadc_iio_channels_1);
358 break;
359 case RCAR_GYROADC_MODE_SELECT_2_ADCS7476:
360 sample_width = 15;
361 channels = rcar_gyroadc_iio_channels_2;
362 num_channels = ARRAY_SIZE(rcar_gyroadc_iio_channels_2);
363 break;
364 case RCAR_GYROADC_MODE_SELECT_3_MAX1162:
365 sample_width = 16;
366 channels = rcar_gyroadc_iio_channels_3;
367 num_channels = ARRAY_SIZE(rcar_gyroadc_iio_channels_3);
368 break;
369 }
370
371 /*
372 * MB88101 is special in that it's only a single chip taking
373 * up all the CHS lines. Thus, the DT binding is also special
374 * and has no reg property. If we run into such ADC, handle
375 * it here.
376 */
377 if (childmode == RCAR_GYROADC_MODE_SELECT_1_MB88101A) {
378 reg = 0;
379 } else {
380 ret = of_property_read_u32(child, "reg", &reg);
381 if (ret) {
382 dev_err(dev,
383 "Failed to get child reg property of ADC \"%s\".\n",
384 child->name);
385 return ret;
386 }
387
388 /* Channel number is too high. */
389 if (reg >= num_channels) {
390 dev_err(dev,
391 "Only %i channels supported with %s, but reg = <%i>.\n",
392 num_channels, child->name, reg);
393 return ret;
394 }
395 }
396
397 /* Child node selected different mode than the rest. */
398 if (!first && (adcmode != childmode)) {
399 dev_err(dev,
400 "Channel %i uses different ADC mode than the rest.\n",
401 reg);
402 return ret;
403 }
404
405 /* Channel is valid, grab the regulator. */
406 dev->of_node = child;
407 vref = devm_regulator_get(dev, "vref");
408 dev->of_node = np;
409 if (IS_ERR(vref)) {
410 dev_dbg(dev, "Channel %i 'vref' supply not connected.\n",
411 reg);
412 return PTR_ERR(vref);
413 }
414
415 priv->vref[reg] = vref;
416
417 if (!first)
418 continue;
419
420 /* First child node which passed sanity tests. */
421 adcmode = childmode;
422 first = 0;
423
424 priv->num_channels = num_channels;
425 priv->mode = childmode;
426 priv->sample_width = sample_width;
427
428 indio_dev->channels = channels;
429 indio_dev->num_channels = num_channels;
430
431 /*
432 * MB88101 is special and we only have one such device
433 * attached to the GyroADC at a time, so if we found it,
434 * we can stop parsing here.
435 */
436 if (childmode == RCAR_GYROADC_MODE_SELECT_1_MB88101A)
437 break;
438 }
439
440 if (first) {
441 dev_err(dev, "No valid ADC channels found, aborting.\n");
442 return -EINVAL;
443 }
444
445 return 0;
446}
447
448static void rcar_gyroadc_deinit_supplies(struct iio_dev *indio_dev)
449{
450 struct rcar_gyroadc *priv = iio_priv(indio_dev);
451 unsigned int i;
452
453 for (i = 0; i < priv->num_channels; i++) {
454 if (!priv->vref[i])
455 continue;
456
457 regulator_disable(priv->vref[i]);
458 }
459}
460
461static int rcar_gyroadc_init_supplies(struct iio_dev *indio_dev)
462{
463 struct rcar_gyroadc *priv = iio_priv(indio_dev);
464 struct device *dev = priv->dev;
465 unsigned int i;
466 int ret;
467
468 for (i = 0; i < priv->num_channels; i++) {
469 if (!priv->vref[i])
470 continue;
471
472 ret = regulator_enable(priv->vref[i]);
473 if (ret) {
474 dev_err(dev, "Failed to enable regulator %i (ret=%i)\n",
475 i, ret);
476 goto err;
477 }
478 }
479
480 return 0;
481
482err:
483 rcar_gyroadc_deinit_supplies(indio_dev);
484 return ret;
485}
486
487static int rcar_gyroadc_probe(struct platform_device *pdev)
488{
489 const struct of_device_id *of_id =
490 of_match_device(rcar_gyroadc_match, &pdev->dev);
491 struct device *dev = &pdev->dev;
492 struct rcar_gyroadc *priv;
493 struct iio_dev *indio_dev;
494 struct resource *mem;
495 int ret;
496
497 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
498 if (!indio_dev) {
499 dev_err(dev, "Failed to allocate IIO device.\n");
500 return -ENOMEM;
501 }
502
503 priv = iio_priv(indio_dev);
504 priv->dev = dev;
505
506 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
507 priv->regs = devm_ioremap_resource(dev, mem);
508 if (IS_ERR(priv->regs))
509 return PTR_ERR(priv->regs);
510
511 priv->iclk = devm_clk_get(dev, "if");
512 if (IS_ERR(priv->iclk)) {
513 ret = PTR_ERR(priv->iclk);
514 if (ret != -EPROBE_DEFER)
515 dev_err(dev, "Failed to get IF clock (ret=%i)\n", ret);
516 return ret;
517 }
518
519 ret = rcar_gyroadc_parse_subdevs(indio_dev);
520 if (ret)
521 return ret;
522
523 ret = rcar_gyroadc_init_supplies(indio_dev);
524 if (ret)
525 return ret;
526
527 priv->model = (enum rcar_gyroadc_model)of_id->data;
528
529 platform_set_drvdata(pdev, indio_dev);
530
531 indio_dev->name = DRIVER_NAME;
532 indio_dev->dev.parent = dev;
533 indio_dev->dev.of_node = pdev->dev.of_node;
534 indio_dev->info = &rcar_gyroadc_iio_info;
535 indio_dev->modes = INDIO_DIRECT_MODE;
536
537 ret = clk_prepare_enable(priv->iclk);
538 if (ret) {
539 dev_err(dev, "Could not prepare or enable the IF clock.\n");
540 goto err_clk_if_enable;
541 }
542
543 pm_runtime_set_autosuspend_delay(dev, RCAR_GYROADC_RUNTIME_PM_DELAY_MS);
544 pm_runtime_use_autosuspend(dev);
545 pm_runtime_enable(dev);
546
547 pm_runtime_get_sync(dev);
548 rcar_gyroadc_hw_init(priv);
549 rcar_gyroadc_hw_start(priv);
550
551 ret = iio_device_register(indio_dev);
552 if (ret) {
553 dev_err(dev, "Couldn't register IIO device.\n");
554 goto err_iio_device_register;
555 }
556
557 pm_runtime_put_sync(dev);
558
559 return 0;
560
561err_iio_device_register:
562 rcar_gyroadc_hw_stop(priv);
563 pm_runtime_put_sync(dev);
564 pm_runtime_disable(dev);
565 pm_runtime_set_suspended(dev);
566 clk_disable_unprepare(priv->iclk);
567err_clk_if_enable:
568 rcar_gyroadc_deinit_supplies(indio_dev);
569
570 return ret;
571}
572
573static int rcar_gyroadc_remove(struct platform_device *pdev)
574{
575 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
576 struct rcar_gyroadc *priv = iio_priv(indio_dev);
577 struct device *dev = priv->dev;
578
579 iio_device_unregister(indio_dev);
580 pm_runtime_get_sync(dev);
581 rcar_gyroadc_hw_stop(priv);
582 pm_runtime_put_sync(dev);
583 pm_runtime_disable(dev);
584 pm_runtime_set_suspended(dev);
585 clk_disable_unprepare(priv->iclk);
586 rcar_gyroadc_deinit_supplies(indio_dev);
587
588 return 0;
589}
590
591#if defined(CONFIG_PM)
592static int rcar_gyroadc_suspend(struct device *dev)
593{
594 struct iio_dev *indio_dev = dev_get_drvdata(dev);
595 struct rcar_gyroadc *priv = iio_priv(indio_dev);
596
597 rcar_gyroadc_hw_stop(priv);
598
599 return 0;
600}
601
602static int rcar_gyroadc_resume(struct device *dev)
603{
604 struct iio_dev *indio_dev = dev_get_drvdata(dev);
605 struct rcar_gyroadc *priv = iio_priv(indio_dev);
606
607 rcar_gyroadc_hw_start(priv);
608
609 return 0;
610}
611#endif
612
613static const struct dev_pm_ops rcar_gyroadc_pm_ops = {
614 SET_RUNTIME_PM_OPS(rcar_gyroadc_suspend, rcar_gyroadc_resume, NULL)
615};
616
617static struct platform_driver rcar_gyroadc_driver = {
618 .probe = rcar_gyroadc_probe,
619 .remove = rcar_gyroadc_remove,
620 .driver = {
621 .name = DRIVER_NAME,
622 .of_match_table = rcar_gyroadc_match,
623 .pm = &rcar_gyroadc_pm_ops,
624 },
625};
626
627module_platform_driver(rcar_gyroadc_driver);
628
629MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
630MODULE_DESCRIPTION("Renesas R-Car GyroADC driver");
631MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/stm32-adc-core.c b/drivers/iio/adc/stm32-adc-core.c
index 4214b0cd6b1b..22b7c9321e78 100644
--- a/drivers/iio/adc/stm32-adc-core.c
+++ b/drivers/iio/adc/stm32-adc-core.c
@@ -201,6 +201,7 @@ static int stm32_adc_probe(struct platform_device *pdev)
201 priv->common.base = devm_ioremap_resource(&pdev->dev, res); 201 priv->common.base = devm_ioremap_resource(&pdev->dev, res);
202 if (IS_ERR(priv->common.base)) 202 if (IS_ERR(priv->common.base))
203 return PTR_ERR(priv->common.base); 203 return PTR_ERR(priv->common.base);
204 priv->common.phys_base = res->start;
204 205
205 priv->vref = devm_regulator_get(&pdev->dev, "vref"); 206 priv->vref = devm_regulator_get(&pdev->dev, "vref");
206 if (IS_ERR(priv->vref)) { 207 if (IS_ERR(priv->vref)) {
diff --git a/drivers/iio/adc/stm32-adc-core.h b/drivers/iio/adc/stm32-adc-core.h
index 081fa5f55015..2ec7abbfbcaa 100644
--- a/drivers/iio/adc/stm32-adc-core.h
+++ b/drivers/iio/adc/stm32-adc-core.h
@@ -42,10 +42,12 @@
42/** 42/**
43 * struct stm32_adc_common - stm32 ADC driver common data (for all instances) 43 * struct stm32_adc_common - stm32 ADC driver common data (for all instances)
44 * @base: control registers base cpu addr 44 * @base: control registers base cpu addr
45 * @phys_base: control registers base physical addr
45 * @vref_mv: vref voltage (mv) 46 * @vref_mv: vref voltage (mv)
46 */ 47 */
47struct stm32_adc_common { 48struct stm32_adc_common {
48 void __iomem *base; 49 void __iomem *base;
50 phys_addr_t phys_base;
49 int vref_mv; 51 int vref_mv;
50}; 52};
51 53
diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index 5715e79f4935..9b49a6addc2a 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -21,7 +21,14 @@
21 21
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/dma-mapping.h>
25#include <linux/dmaengine.h>
24#include <linux/iio/iio.h> 26#include <linux/iio/iio.h>
27#include <linux/iio/buffer.h>
28#include <linux/iio/timer/stm32-timer-trigger.h>
29#include <linux/iio/trigger.h>
30#include <linux/iio/trigger_consumer.h>
31#include <linux/iio/triggered_buffer.h>
25#include <linux/interrupt.h> 32#include <linux/interrupt.h>
26#include <linux/io.h> 33#include <linux/io.h>
27#include <linux/module.h> 34#include <linux/module.h>
@@ -58,21 +65,71 @@
58 65
59/* STM32F4_ADC_CR2 - bit fields */ 66/* STM32F4_ADC_CR2 - bit fields */
60#define STM32F4_SWSTART BIT(30) 67#define STM32F4_SWSTART BIT(30)
68#define STM32F4_EXTEN_SHIFT 28
61#define STM32F4_EXTEN_MASK GENMASK(29, 28) 69#define STM32F4_EXTEN_MASK GENMASK(29, 28)
70#define STM32F4_EXTSEL_SHIFT 24
71#define STM32F4_EXTSEL_MASK GENMASK(27, 24)
62#define STM32F4_EOCS BIT(10) 72#define STM32F4_EOCS BIT(10)
73#define STM32F4_DDS BIT(9)
74#define STM32F4_DMA BIT(8)
63#define STM32F4_ADON BIT(0) 75#define STM32F4_ADON BIT(0)
64 76
65/* STM32F4_ADC_SQR1 - bit fields */ 77#define STM32_ADC_MAX_SQ 16 /* SQ1..SQ16 */
66#define STM32F4_L_SHIFT 20
67#define STM32F4_L_MASK GENMASK(23, 20)
68
69/* STM32F4_ADC_SQR3 - bit fields */
70#define STM32F4_SQ1_SHIFT 0
71#define STM32F4_SQ1_MASK GENMASK(4, 0)
72
73#define STM32_ADC_TIMEOUT_US 100000 78#define STM32_ADC_TIMEOUT_US 100000
74#define STM32_ADC_TIMEOUT (msecs_to_jiffies(STM32_ADC_TIMEOUT_US / 1000)) 79#define STM32_ADC_TIMEOUT (msecs_to_jiffies(STM32_ADC_TIMEOUT_US / 1000))
75 80
81#define STM32_DMA_BUFFER_SIZE PAGE_SIZE
82
83/* External trigger enable */
84enum stm32_adc_exten {
85 STM32_EXTEN_SWTRIG,
86 STM32_EXTEN_HWTRIG_RISING_EDGE,
87 STM32_EXTEN_HWTRIG_FALLING_EDGE,
88 STM32_EXTEN_HWTRIG_BOTH_EDGES,
89};
90
91/* extsel - trigger mux selection value */
92enum stm32_adc_extsel {
93 STM32_EXT0,
94 STM32_EXT1,
95 STM32_EXT2,
96 STM32_EXT3,
97 STM32_EXT4,
98 STM32_EXT5,
99 STM32_EXT6,
100 STM32_EXT7,
101 STM32_EXT8,
102 STM32_EXT9,
103 STM32_EXT10,
104 STM32_EXT11,
105 STM32_EXT12,
106 STM32_EXT13,
107 STM32_EXT14,
108 STM32_EXT15,
109};
110
111/**
112 * struct stm32_adc_trig_info - ADC trigger info
113 * @name: name of the trigger, corresponding to its source
114 * @extsel: trigger selection
115 */
116struct stm32_adc_trig_info {
117 const char *name;
118 enum stm32_adc_extsel extsel;
119};
120
121/**
122 * stm32_adc_regs - stm32 ADC misc registers & bitfield desc
123 * @reg: register offset
124 * @mask: bitfield mask
125 * @shift: left shift
126 */
127struct stm32_adc_regs {
128 int reg;
129 int mask;
130 int shift;
131};
132
76/** 133/**
77 * struct stm32_adc - private data of each ADC IIO instance 134 * struct stm32_adc - private data of each ADC IIO instance
78 * @common: reference to ADC block common data 135 * @common: reference to ADC block common data
@@ -82,15 +139,29 @@
82 * @clk: clock for this adc instance 139 * @clk: clock for this adc instance
83 * @irq: interrupt for this adc instance 140 * @irq: interrupt for this adc instance
84 * @lock: spinlock 141 * @lock: spinlock
142 * @bufi: data buffer index
143 * @num_conv: expected number of scan conversions
144 * @trigger_polarity: external trigger polarity (e.g. exten)
145 * @dma_chan: dma channel
146 * @rx_buf: dma rx buffer cpu address
147 * @rx_dma_buf: dma rx buffer bus address
148 * @rx_buf_sz: dma rx buffer size
85 */ 149 */
86struct stm32_adc { 150struct stm32_adc {
87 struct stm32_adc_common *common; 151 struct stm32_adc_common *common;
88 u32 offset; 152 u32 offset;
89 struct completion completion; 153 struct completion completion;
90 u16 *buffer; 154 u16 buffer[STM32_ADC_MAX_SQ];
91 struct clk *clk; 155 struct clk *clk;
92 int irq; 156 int irq;
93 spinlock_t lock; /* interrupt lock */ 157 spinlock_t lock; /* interrupt lock */
158 unsigned int bufi;
159 unsigned int num_conv;
160 u32 trigger_polarity;
161 struct dma_chan *dma_chan;
162 u8 *rx_buf;
163 dma_addr_t rx_dma_buf;
164 unsigned int rx_buf_sz;
94}; 165};
95 166
96/** 167/**
@@ -126,6 +197,53 @@ static const struct stm32_adc_chan_spec stm32f4_adc123_channels[] = {
126}; 197};
127 198
128/** 199/**
200 * stm32f4_sq - describe regular sequence registers
201 * - L: sequence len (register & bit field)
202 * - SQ1..SQ16: sequence entries (register & bit field)
203 */
204static const struct stm32_adc_regs stm32f4_sq[STM32_ADC_MAX_SQ + 1] = {
205 /* L: len bit field description to be kept as first element */
206 { STM32F4_ADC_SQR1, GENMASK(23, 20), 20 },
207 /* SQ1..SQ16 registers & bit fields (reg, mask, shift) */
208 { STM32F4_ADC_SQR3, GENMASK(4, 0), 0 },
209 { STM32F4_ADC_SQR3, GENMASK(9, 5), 5 },
210 { STM32F4_ADC_SQR3, GENMASK(14, 10), 10 },
211 { STM32F4_ADC_SQR3, GENMASK(19, 15), 15 },
212 { STM32F4_ADC_SQR3, GENMASK(24, 20), 20 },
213 { STM32F4_ADC_SQR3, GENMASK(29, 25), 25 },
214 { STM32F4_ADC_SQR2, GENMASK(4, 0), 0 },
215 { STM32F4_ADC_SQR2, GENMASK(9, 5), 5 },
216 { STM32F4_ADC_SQR2, GENMASK(14, 10), 10 },
217 { STM32F4_ADC_SQR2, GENMASK(19, 15), 15 },
218 { STM32F4_ADC_SQR2, GENMASK(24, 20), 20 },
219 { STM32F4_ADC_SQR2, GENMASK(29, 25), 25 },
220 { STM32F4_ADC_SQR1, GENMASK(4, 0), 0 },
221 { STM32F4_ADC_SQR1, GENMASK(9, 5), 5 },
222 { STM32F4_ADC_SQR1, GENMASK(14, 10), 10 },
223 { STM32F4_ADC_SQR1, GENMASK(19, 15), 15 },
224};
225
226/* STM32F4 external trigger sources for all instances */
227static struct stm32_adc_trig_info stm32f4_adc_trigs[] = {
228 { TIM1_CH1, STM32_EXT0 },
229 { TIM1_CH2, STM32_EXT1 },
230 { TIM1_CH3, STM32_EXT2 },
231 { TIM2_CH2, STM32_EXT3 },
232 { TIM2_CH3, STM32_EXT4 },
233 { TIM2_CH4, STM32_EXT5 },
234 { TIM2_TRGO, STM32_EXT6 },
235 { TIM3_CH1, STM32_EXT7 },
236 { TIM3_TRGO, STM32_EXT8 },
237 { TIM4_CH4, STM32_EXT9 },
238 { TIM5_CH1, STM32_EXT10 },
239 { TIM5_CH2, STM32_EXT11 },
240 { TIM5_CH3, STM32_EXT12 },
241 { TIM8_CH1, STM32_EXT13 },
242 { TIM8_TRGO, STM32_EXT14 },
243 {}, /* sentinel */
244};
245
246/**
129 * STM32 ADC registers access routines 247 * STM32 ADC registers access routines
130 * @adc: stm32 adc instance 248 * @adc: stm32 adc instance
131 * @reg: reg offset in adc instance 249 * @reg: reg offset in adc instance
@@ -187,10 +305,21 @@ static void stm32_adc_conv_irq_disable(struct stm32_adc *adc)
187/** 305/**
188 * stm32_adc_start_conv() - Start conversions for regular channels. 306 * stm32_adc_start_conv() - Start conversions for regular channels.
189 * @adc: stm32 adc instance 307 * @adc: stm32 adc instance
308 * @dma: use dma to transfer conversion result
309 *
310 * Start conversions for regular channels.
311 * Also take care of normal or DMA mode. Circular DMA may be used for regular
312 * conversions, in IIO buffer modes. Otherwise, use ADC interrupt with direct
313 * DR read instead (e.g. read_raw, or triggered buffer mode without DMA).
190 */ 314 */
191static void stm32_adc_start_conv(struct stm32_adc *adc) 315static void stm32_adc_start_conv(struct stm32_adc *adc, bool dma)
192{ 316{
193 stm32_adc_set_bits(adc, STM32F4_ADC_CR1, STM32F4_SCAN); 317 stm32_adc_set_bits(adc, STM32F4_ADC_CR1, STM32F4_SCAN);
318
319 if (dma)
320 stm32_adc_set_bits(adc, STM32F4_ADC_CR2,
321 STM32F4_DMA | STM32F4_DDS);
322
194 stm32_adc_set_bits(adc, STM32F4_ADC_CR2, STM32F4_EOCS | STM32F4_ADON); 323 stm32_adc_set_bits(adc, STM32F4_ADC_CR2, STM32F4_EOCS | STM32F4_ADON);
195 324
196 /* Wait for Power-up time (tSTAB from datasheet) */ 325 /* Wait for Power-up time (tSTAB from datasheet) */
@@ -207,10 +336,153 @@ static void stm32_adc_stop_conv(struct stm32_adc *adc)
207 stm32_adc_clr_bits(adc, STM32F4_ADC_SR, STM32F4_STRT); 336 stm32_adc_clr_bits(adc, STM32F4_ADC_SR, STM32F4_STRT);
208 337
209 stm32_adc_clr_bits(adc, STM32F4_ADC_CR1, STM32F4_SCAN); 338 stm32_adc_clr_bits(adc, STM32F4_ADC_CR1, STM32F4_SCAN);
210 stm32_adc_clr_bits(adc, STM32F4_ADC_CR2, STM32F4_ADON); 339 stm32_adc_clr_bits(adc, STM32F4_ADC_CR2,
340 STM32F4_ADON | STM32F4_DMA | STM32F4_DDS);
341}
342
343/**
344 * stm32_adc_conf_scan_seq() - Build regular channels scan sequence
345 * @indio_dev: IIO device
346 * @scan_mask: channels to be converted
347 *
348 * Conversion sequence :
349 * Configure ADC scan sequence based on selected channels in scan_mask.
350 * Add channels to SQR registers, from scan_mask LSB to MSB, then
351 * program sequence len.
352 */
353static int stm32_adc_conf_scan_seq(struct iio_dev *indio_dev,
354 const unsigned long *scan_mask)
355{
356 struct stm32_adc *adc = iio_priv(indio_dev);
357 const struct iio_chan_spec *chan;
358 u32 val, bit;
359 int i = 0;
360
361 for_each_set_bit(bit, scan_mask, indio_dev->masklength) {
362 chan = indio_dev->channels + bit;
363 /*
364 * Assign one channel per SQ entry in regular
365 * sequence, starting with SQ1.
366 */
367 i++;
368 if (i > STM32_ADC_MAX_SQ)
369 return -EINVAL;
370
371 dev_dbg(&indio_dev->dev, "%s chan %d to SQ%d\n",
372 __func__, chan->channel, i);
373
374 val = stm32_adc_readl(adc, stm32f4_sq[i].reg);
375 val &= ~stm32f4_sq[i].mask;
376 val |= chan->channel << stm32f4_sq[i].shift;
377 stm32_adc_writel(adc, stm32f4_sq[i].reg, val);
378 }
379
380 if (!i)
381 return -EINVAL;
382
383 /* Sequence len */
384 val = stm32_adc_readl(adc, stm32f4_sq[0].reg);
385 val &= ~stm32f4_sq[0].mask;
386 val |= ((i - 1) << stm32f4_sq[0].shift);
387 stm32_adc_writel(adc, stm32f4_sq[0].reg, val);
388
389 return 0;
390}
391
392/**
393 * stm32_adc_get_trig_extsel() - Get external trigger selection
394 * @trig: trigger
395 *
396 * Returns trigger extsel value, if trig matches, -EINVAL otherwise.
397 */
398static int stm32_adc_get_trig_extsel(struct iio_trigger *trig)
399{
400 int i;
401
402 /* lookup triggers registered by stm32 timer trigger driver */
403 for (i = 0; stm32f4_adc_trigs[i].name; i++) {
404 /**
405 * Checking both stm32 timer trigger type and trig name
406 * should be safe against arbitrary trigger names.
407 */
408 if (is_stm32_timer_trigger(trig) &&
409 !strcmp(stm32f4_adc_trigs[i].name, trig->name)) {
410 return stm32f4_adc_trigs[i].extsel;
411 }
412 }
413
414 return -EINVAL;
211} 415}
212 416
213/** 417/**
418 * stm32_adc_set_trig() - Set a regular trigger
419 * @indio_dev: IIO device
420 * @trig: IIO trigger
421 *
422 * Set trigger source/polarity (e.g. SW, or HW with polarity) :
423 * - if HW trigger disabled (e.g. trig == NULL, conversion launched by sw)
424 * - if HW trigger enabled, set source & polarity
425 */
426static int stm32_adc_set_trig(struct iio_dev *indio_dev,
427 struct iio_trigger *trig)
428{
429 struct stm32_adc *adc = iio_priv(indio_dev);
430 u32 val, extsel = 0, exten = STM32_EXTEN_SWTRIG;
431 unsigned long flags;
432 int ret;
433
434 if (trig) {
435 ret = stm32_adc_get_trig_extsel(trig);
436 if (ret < 0)
437 return ret;
438
439 /* set trigger source and polarity (default to rising edge) */
440 extsel = ret;
441 exten = adc->trigger_polarity + STM32_EXTEN_HWTRIG_RISING_EDGE;
442 }
443
444 spin_lock_irqsave(&adc->lock, flags);
445 val = stm32_adc_readl(adc, STM32F4_ADC_CR2);
446 val &= ~(STM32F4_EXTEN_MASK | STM32F4_EXTSEL_MASK);
447 val |= exten << STM32F4_EXTEN_SHIFT;
448 val |= extsel << STM32F4_EXTSEL_SHIFT;
449 stm32_adc_writel(adc, STM32F4_ADC_CR2, val);
450 spin_unlock_irqrestore(&adc->lock, flags);
451
452 return 0;
453}
454
455static int stm32_adc_set_trig_pol(struct iio_dev *indio_dev,
456 const struct iio_chan_spec *chan,
457 unsigned int type)
458{
459 struct stm32_adc *adc = iio_priv(indio_dev);
460
461 adc->trigger_polarity = type;
462
463 return 0;
464}
465
466static int stm32_adc_get_trig_pol(struct iio_dev *indio_dev,
467 const struct iio_chan_spec *chan)
468{
469 struct stm32_adc *adc = iio_priv(indio_dev);
470
471 return adc->trigger_polarity;
472}
473
474static const char * const stm32_trig_pol_items[] = {
475 "rising-edge", "falling-edge", "both-edges",
476};
477
478static const struct iio_enum stm32_adc_trig_pol = {
479 .items = stm32_trig_pol_items,
480 .num_items = ARRAY_SIZE(stm32_trig_pol_items),
481 .get = stm32_adc_get_trig_pol,
482 .set = stm32_adc_set_trig_pol,
483};
484
485/**
214 * stm32_adc_single_conv() - Performs a single conversion 486 * stm32_adc_single_conv() - Performs a single conversion
215 * @indio_dev: IIO device 487 * @indio_dev: IIO device
216 * @chan: IIO channel 488 * @chan: IIO channel
@@ -228,28 +500,27 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev,
228 struct stm32_adc *adc = iio_priv(indio_dev); 500 struct stm32_adc *adc = iio_priv(indio_dev);
229 long timeout; 501 long timeout;
230 u32 val; 502 u32 val;
231 u16 result;
232 int ret; 503 int ret;
233 504
234 reinit_completion(&adc->completion); 505 reinit_completion(&adc->completion);
235 506
236 adc->buffer = &result; 507 adc->bufi = 0;
237 508
238 /* Program chan number in regular sequence */ 509 /* Program chan number in regular sequence (SQ1) */
239 val = stm32_adc_readl(adc, STM32F4_ADC_SQR3); 510 val = stm32_adc_readl(adc, stm32f4_sq[1].reg);
240 val &= ~STM32F4_SQ1_MASK; 511 val &= ~stm32f4_sq[1].mask;
241 val |= chan->channel << STM32F4_SQ1_SHIFT; 512 val |= chan->channel << stm32f4_sq[1].shift;
242 stm32_adc_writel(adc, STM32F4_ADC_SQR3, val); 513 stm32_adc_writel(adc, stm32f4_sq[1].reg, val);
243 514
244 /* Set regular sequence len (0 for 1 conversion) */ 515 /* Set regular sequence len (0 for 1 conversion) */
245 stm32_adc_clr_bits(adc, STM32F4_ADC_SQR1, STM32F4_L_MASK); 516 stm32_adc_clr_bits(adc, stm32f4_sq[0].reg, stm32f4_sq[0].mask);
246 517
247 /* Trigger detection disabled (conversion can be launched in SW) */ 518 /* Trigger detection disabled (conversion can be launched in SW) */
248 stm32_adc_clr_bits(adc, STM32F4_ADC_CR2, STM32F4_EXTEN_MASK); 519 stm32_adc_clr_bits(adc, STM32F4_ADC_CR2, STM32F4_EXTEN_MASK);
249 520
250 stm32_adc_conv_irq_enable(adc); 521 stm32_adc_conv_irq_enable(adc);
251 522
252 stm32_adc_start_conv(adc); 523 stm32_adc_start_conv(adc, false);
253 524
254 timeout = wait_for_completion_interruptible_timeout( 525 timeout = wait_for_completion_interruptible_timeout(
255 &adc->completion, STM32_ADC_TIMEOUT); 526 &adc->completion, STM32_ADC_TIMEOUT);
@@ -258,7 +529,7 @@ static int stm32_adc_single_conv(struct iio_dev *indio_dev,
258 } else if (timeout < 0) { 529 } else if (timeout < 0) {
259 ret = timeout; 530 ret = timeout;
260 } else { 531 } else {
261 *res = result; 532 *res = adc->buffer[0];
262 ret = IIO_VAL_INT; 533 ret = IIO_VAL_INT;
263 } 534 }
264 535
@@ -301,17 +572,73 @@ static int stm32_adc_read_raw(struct iio_dev *indio_dev,
301static irqreturn_t stm32_adc_isr(int irq, void *data) 572static irqreturn_t stm32_adc_isr(int irq, void *data)
302{ 573{
303 struct stm32_adc *adc = data; 574 struct stm32_adc *adc = data;
575 struct iio_dev *indio_dev = iio_priv_to_dev(adc);
304 u32 status = stm32_adc_readl(adc, STM32F4_ADC_SR); 576 u32 status = stm32_adc_readl(adc, STM32F4_ADC_SR);
305 577
306 if (status & STM32F4_EOC) { 578 if (status & STM32F4_EOC) {
307 *adc->buffer = stm32_adc_readw(adc, STM32F4_ADC_DR); 579 /* Reading DR also clears EOC status flag */
308 complete(&adc->completion); 580 adc->buffer[adc->bufi] = stm32_adc_readw(adc, STM32F4_ADC_DR);
581 if (iio_buffer_enabled(indio_dev)) {
582 adc->bufi++;
583 if (adc->bufi >= adc->num_conv) {
584 stm32_adc_conv_irq_disable(adc);
585 iio_trigger_poll(indio_dev->trig);
586 }
587 } else {
588 complete(&adc->completion);
589 }
309 return IRQ_HANDLED; 590 return IRQ_HANDLED;
310 } 591 }
311 592
312 return IRQ_NONE; 593 return IRQ_NONE;
313} 594}
314 595
596/**
597 * stm32_adc_validate_trigger() - validate trigger for stm32 adc
598 * @indio_dev: IIO device
599 * @trig: new trigger
600 *
601 * Returns: 0 if trig matches one of the triggers registered by stm32 adc
602 * driver, -EINVAL otherwise.
603 */
604static int stm32_adc_validate_trigger(struct iio_dev *indio_dev,
605 struct iio_trigger *trig)
606{
607 return stm32_adc_get_trig_extsel(trig) < 0 ? -EINVAL : 0;
608}
609
610static int stm32_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
611{
612 struct stm32_adc *adc = iio_priv(indio_dev);
613 unsigned int watermark = STM32_DMA_BUFFER_SIZE / 2;
614
615 /*
616 * dma cyclic transfers are used, buffer is split into two periods.
617 * There should be :
618 * - always one buffer (period) dma is working on
619 * - one buffer (period) driver can push with iio_trigger_poll().
620 */
621 watermark = min(watermark, val * (unsigned)(sizeof(u16)));
622 adc->rx_buf_sz = watermark * 2;
623
624 return 0;
625}
626
627static int stm32_adc_update_scan_mode(struct iio_dev *indio_dev,
628 const unsigned long *scan_mask)
629{
630 struct stm32_adc *adc = iio_priv(indio_dev);
631 int ret;
632
633 adc->num_conv = bitmap_weight(scan_mask, indio_dev->masklength);
634
635 ret = stm32_adc_conf_scan_seq(indio_dev, scan_mask);
636 if (ret)
637 return ret;
638
639 return 0;
640}
641
315static int stm32_adc_of_xlate(struct iio_dev *indio_dev, 642static int stm32_adc_of_xlate(struct iio_dev *indio_dev,
316 const struct of_phandle_args *iiospec) 643 const struct of_phandle_args *iiospec)
317{ 644{
@@ -350,11 +677,199 @@ static int stm32_adc_debugfs_reg_access(struct iio_dev *indio_dev,
350 677
351static const struct iio_info stm32_adc_iio_info = { 678static const struct iio_info stm32_adc_iio_info = {
352 .read_raw = stm32_adc_read_raw, 679 .read_raw = stm32_adc_read_raw,
680 .validate_trigger = stm32_adc_validate_trigger,
681 .hwfifo_set_watermark = stm32_adc_set_watermark,
682 .update_scan_mode = stm32_adc_update_scan_mode,
353 .debugfs_reg_access = stm32_adc_debugfs_reg_access, 683 .debugfs_reg_access = stm32_adc_debugfs_reg_access,
354 .of_xlate = stm32_adc_of_xlate, 684 .of_xlate = stm32_adc_of_xlate,
355 .driver_module = THIS_MODULE, 685 .driver_module = THIS_MODULE,
356}; 686};
357 687
688static unsigned int stm32_adc_dma_residue(struct stm32_adc *adc)
689{
690 struct dma_tx_state state;
691 enum dma_status status;
692
693 status = dmaengine_tx_status(adc->dma_chan,
694 adc->dma_chan->cookie,
695 &state);
696 if (status == DMA_IN_PROGRESS) {
697 /* Residue is size in bytes from end of buffer */
698 unsigned int i = adc->rx_buf_sz - state.residue;
699 unsigned int size;
700
701 /* Return available bytes */
702 if (i >= adc->bufi)
703 size = i - adc->bufi;
704 else
705 size = adc->rx_buf_sz + i - adc->bufi;
706
707 return size;
708 }
709
710 return 0;
711}
712
713static void stm32_adc_dma_buffer_done(void *data)
714{
715 struct iio_dev *indio_dev = data;
716
717 iio_trigger_poll_chained(indio_dev->trig);
718}
719
720static int stm32_adc_dma_start(struct iio_dev *indio_dev)
721{
722 struct stm32_adc *adc = iio_priv(indio_dev);
723 struct dma_async_tx_descriptor *desc;
724 dma_cookie_t cookie;
725 int ret;
726
727 if (!adc->dma_chan)
728 return 0;
729
730 dev_dbg(&indio_dev->dev, "%s size=%d watermark=%d\n", __func__,
731 adc->rx_buf_sz, adc->rx_buf_sz / 2);
732
733 /* Prepare a DMA cyclic transaction */
734 desc = dmaengine_prep_dma_cyclic(adc->dma_chan,
735 adc->rx_dma_buf,
736 adc->rx_buf_sz, adc->rx_buf_sz / 2,
737 DMA_DEV_TO_MEM,
738 DMA_PREP_INTERRUPT);
739 if (!desc)
740 return -EBUSY;
741
742 desc->callback = stm32_adc_dma_buffer_done;
743 desc->callback_param = indio_dev;
744
745 cookie = dmaengine_submit(desc);
746 ret = dma_submit_error(cookie);
747 if (ret) {
748 dmaengine_terminate_all(adc->dma_chan);
749 return ret;
750 }
751
752 /* Issue pending DMA requests */
753 dma_async_issue_pending(adc->dma_chan);
754
755 return 0;
756}
757
758static int stm32_adc_buffer_postenable(struct iio_dev *indio_dev)
759{
760 struct stm32_adc *adc = iio_priv(indio_dev);
761 int ret;
762
763 ret = stm32_adc_set_trig(indio_dev, indio_dev->trig);
764 if (ret) {
765 dev_err(&indio_dev->dev, "Can't set trigger\n");
766 return ret;
767 }
768
769 ret = stm32_adc_dma_start(indio_dev);
770 if (ret) {
771 dev_err(&indio_dev->dev, "Can't start dma\n");
772 goto err_clr_trig;
773 }
774
775 ret = iio_triggered_buffer_postenable(indio_dev);
776 if (ret < 0)
777 goto err_stop_dma;
778
779 /* Reset adc buffer index */
780 adc->bufi = 0;
781
782 if (!adc->dma_chan)
783 stm32_adc_conv_irq_enable(adc);
784
785 stm32_adc_start_conv(adc, !!adc->dma_chan);
786
787 return 0;
788
789err_stop_dma:
790 if (adc->dma_chan)
791 dmaengine_terminate_all(adc->dma_chan);
792err_clr_trig:
793 stm32_adc_set_trig(indio_dev, NULL);
794
795 return ret;
796}
797
798static int stm32_adc_buffer_predisable(struct iio_dev *indio_dev)
799{
800 struct stm32_adc *adc = iio_priv(indio_dev);
801 int ret;
802
803 stm32_adc_stop_conv(adc);
804 if (!adc->dma_chan)
805 stm32_adc_conv_irq_disable(adc);
806
807 ret = iio_triggered_buffer_predisable(indio_dev);
808 if (ret < 0)
809 dev_err(&indio_dev->dev, "predisable failed\n");
810
811 if (adc->dma_chan)
812 dmaengine_terminate_all(adc->dma_chan);
813
814 if (stm32_adc_set_trig(indio_dev, NULL))
815 dev_err(&indio_dev->dev, "Can't clear trigger\n");
816
817 return ret;
818}
819
820static const struct iio_buffer_setup_ops stm32_adc_buffer_setup_ops = {
821 .postenable = &stm32_adc_buffer_postenable,
822 .predisable = &stm32_adc_buffer_predisable,
823};
824
825static irqreturn_t stm32_adc_trigger_handler(int irq, void *p)
826{
827 struct iio_poll_func *pf = p;
828 struct iio_dev *indio_dev = pf->indio_dev;
829 struct stm32_adc *adc = iio_priv(indio_dev);
830
831 dev_dbg(&indio_dev->dev, "%s bufi=%d\n", __func__, adc->bufi);
832
833 if (!adc->dma_chan) {
834 /* reset buffer index */
835 adc->bufi = 0;
836 iio_push_to_buffers_with_timestamp(indio_dev, adc->buffer,
837 pf->timestamp);
838 } else {
839 int residue = stm32_adc_dma_residue(adc);
840
841 while (residue >= indio_dev->scan_bytes) {
842 u16 *buffer = (u16 *)&adc->rx_buf[adc->bufi];
843
844 iio_push_to_buffers_with_timestamp(indio_dev, buffer,
845 pf->timestamp);
846 residue -= indio_dev->scan_bytes;
847 adc->bufi += indio_dev->scan_bytes;
848 if (adc->bufi >= adc->rx_buf_sz)
849 adc->bufi = 0;
850 }
851 }
852
853 iio_trigger_notify_done(indio_dev->trig);
854
855 /* re-enable eoc irq */
856 if (!adc->dma_chan)
857 stm32_adc_conv_irq_enable(adc);
858
859 return IRQ_HANDLED;
860}
861
862static const struct iio_chan_spec_ext_info stm32_adc_ext_info[] = {
863 IIO_ENUM("trigger_polarity", IIO_SHARED_BY_ALL, &stm32_adc_trig_pol),
864 {
865 .name = "trigger_polarity_available",
866 .shared = IIO_SHARED_BY_ALL,
867 .read = iio_enum_available_read,
868 .private = (uintptr_t)&stm32_adc_trig_pol,
869 },
870 {},
871};
872
358static void stm32_adc_chan_init_one(struct iio_dev *indio_dev, 873static void stm32_adc_chan_init_one(struct iio_dev *indio_dev,
359 struct iio_chan_spec *chan, 874 struct iio_chan_spec *chan,
360 const struct stm32_adc_chan_spec *channel, 875 const struct stm32_adc_chan_spec *channel,
@@ -370,6 +885,7 @@ static void stm32_adc_chan_init_one(struct iio_dev *indio_dev,
370 chan->scan_type.sign = 'u'; 885 chan->scan_type.sign = 'u';
371 chan->scan_type.realbits = 12; 886 chan->scan_type.realbits = 12;
372 chan->scan_type.storagebits = 16; 887 chan->scan_type.storagebits = 16;
888 chan->ext_info = stm32_adc_ext_info;
373} 889}
374 890
375static int stm32_adc_chan_of_init(struct iio_dev *indio_dev) 891static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
@@ -410,6 +926,45 @@ static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
410 return 0; 926 return 0;
411} 927}
412 928
929static int stm32_adc_dma_request(struct iio_dev *indio_dev)
930{
931 struct stm32_adc *adc = iio_priv(indio_dev);
932 struct dma_slave_config config;
933 int ret;
934
935 adc->dma_chan = dma_request_slave_channel(&indio_dev->dev, "rx");
936 if (!adc->dma_chan)
937 return 0;
938
939 adc->rx_buf = dma_alloc_coherent(adc->dma_chan->device->dev,
940 STM32_DMA_BUFFER_SIZE,
941 &adc->rx_dma_buf, GFP_KERNEL);
942 if (!adc->rx_buf) {
943 ret = -ENOMEM;
944 goto err_release;
945 }
946
947 /* Configure DMA channel to read data register */
948 memset(&config, 0, sizeof(config));
949 config.src_addr = (dma_addr_t)adc->common->phys_base;
950 config.src_addr += adc->offset + STM32F4_ADC_DR;
951 config.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
952
953 ret = dmaengine_slave_config(adc->dma_chan, &config);
954 if (ret)
955 goto err_free;
956
957 return 0;
958
959err_free:
960 dma_free_coherent(adc->dma_chan->device->dev, STM32_DMA_BUFFER_SIZE,
961 adc->rx_buf, adc->rx_dma_buf);
962err_release:
963 dma_release_channel(adc->dma_chan);
964
965 return ret;
966}
967
413static int stm32_adc_probe(struct platform_device *pdev) 968static int stm32_adc_probe(struct platform_device *pdev)
414{ 969{
415 struct iio_dev *indio_dev; 970 struct iio_dev *indio_dev;
@@ -471,14 +1026,37 @@ static int stm32_adc_probe(struct platform_device *pdev)
471 if (ret < 0) 1026 if (ret < 0)
472 goto err_clk_disable; 1027 goto err_clk_disable;
473 1028
1029 ret = stm32_adc_dma_request(indio_dev);
1030 if (ret < 0)
1031 goto err_clk_disable;
1032
1033 ret = iio_triggered_buffer_setup(indio_dev,
1034 &iio_pollfunc_store_time,
1035 &stm32_adc_trigger_handler,
1036 &stm32_adc_buffer_setup_ops);
1037 if (ret) {
1038 dev_err(&pdev->dev, "buffer setup failed\n");
1039 goto err_dma_disable;
1040 }
1041
474 ret = iio_device_register(indio_dev); 1042 ret = iio_device_register(indio_dev);
475 if (ret) { 1043 if (ret) {
476 dev_err(&pdev->dev, "iio dev register failed\n"); 1044 dev_err(&pdev->dev, "iio dev register failed\n");
477 goto err_clk_disable; 1045 goto err_buffer_cleanup;
478 } 1046 }
479 1047
480 return 0; 1048 return 0;
481 1049
1050err_buffer_cleanup:
1051 iio_triggered_buffer_cleanup(indio_dev);
1052
1053err_dma_disable:
1054 if (adc->dma_chan) {
1055 dma_free_coherent(adc->dma_chan->device->dev,
1056 STM32_DMA_BUFFER_SIZE,
1057 adc->rx_buf, adc->rx_dma_buf);
1058 dma_release_channel(adc->dma_chan);
1059 }
482err_clk_disable: 1060err_clk_disable:
483 clk_disable_unprepare(adc->clk); 1061 clk_disable_unprepare(adc->clk);
484 1062
@@ -491,6 +1069,13 @@ static int stm32_adc_remove(struct platform_device *pdev)
491 struct iio_dev *indio_dev = iio_priv_to_dev(adc); 1069 struct iio_dev *indio_dev = iio_priv_to_dev(adc);
492 1070
493 iio_device_unregister(indio_dev); 1071 iio_device_unregister(indio_dev);
1072 iio_triggered_buffer_cleanup(indio_dev);
1073 if (adc->dma_chan) {
1074 dma_free_coherent(adc->dma_chan->device->dev,
1075 STM32_DMA_BUFFER_SIZE,
1076 adc->rx_buf, adc->rx_dma_buf);
1077 dma_release_channel(adc->dma_chan);
1078 }
494 clk_disable_unprepare(adc->clk); 1079 clk_disable_unprepare(adc->clk);
495 1080
496 return 0; 1081 return 0;
diff --git a/drivers/iio/adc/stx104.c b/drivers/iio/adc/stx104.c
index 7e3645749eaf..be2de48844bc 100644
--- a/drivers/iio/adc/stx104.c
+++ b/drivers/iio/adc/stx104.c
@@ -76,16 +76,6 @@ struct stx104_gpio {
76 unsigned int out_state; 76 unsigned int out_state;
77}; 77};
78 78
79/**
80 * struct stx104_dev - STX104 device private data structure
81 * @indio_dev: IIO device
82 * @chip: instance of the gpio_chip
83 */
84struct stx104_dev {
85 struct iio_dev *indio_dev;
86 struct gpio_chip *chip;
87};
88
89static int stx104_read_raw(struct iio_dev *indio_dev, 79static int stx104_read_raw(struct iio_dev *indio_dev,
90 struct iio_chan_spec const *chan, int *val, int *val2, long mask) 80 struct iio_chan_spec const *chan, int *val, int *val2, long mask)
91{ 81{
@@ -266,12 +256,38 @@ static void stx104_gpio_set(struct gpio_chip *chip, unsigned int offset,
266 spin_unlock_irqrestore(&stx104gpio->lock, flags); 256 spin_unlock_irqrestore(&stx104gpio->lock, flags);
267} 257}
268 258
259#define STX104_NGPIO 8
260static const char *stx104_names[STX104_NGPIO] = {
261 "DIN0", "DIN1", "DIN2", "DIN3", "DOUT0", "DOUT1", "DOUT2", "DOUT3"
262};
263
264static void stx104_gpio_set_multiple(struct gpio_chip *chip,
265 unsigned long *mask, unsigned long *bits)
266{
267 struct stx104_gpio *const stx104gpio = gpiochip_get_data(chip);
268 unsigned long flags;
269
270 /* verify masked GPIO are output */
271 if (!(*mask & 0xF0))
272 return;
273
274 *mask >>= 4;
275 *bits >>= 4;
276
277 spin_lock_irqsave(&stx104gpio->lock, flags);
278
279 stx104gpio->out_state &= ~*mask;
280 stx104gpio->out_state |= *mask & *bits;
281 outb(stx104gpio->out_state, stx104gpio->base);
282
283 spin_unlock_irqrestore(&stx104gpio->lock, flags);
284}
285
269static int stx104_probe(struct device *dev, unsigned int id) 286static int stx104_probe(struct device *dev, unsigned int id)
270{ 287{
271 struct iio_dev *indio_dev; 288 struct iio_dev *indio_dev;
272 struct stx104_iio *priv; 289 struct stx104_iio *priv;
273 struct stx104_gpio *stx104gpio; 290 struct stx104_gpio *stx104gpio;
274 struct stx104_dev *stx104dev;
275 int err; 291 int err;
276 292
277 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv)); 293 indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
@@ -282,10 +298,6 @@ static int stx104_probe(struct device *dev, unsigned int id)
282 if (!stx104gpio) 298 if (!stx104gpio)
283 return -ENOMEM; 299 return -ENOMEM;
284 300
285 stx104dev = devm_kzalloc(dev, sizeof(*stx104dev), GFP_KERNEL);
286 if (!stx104dev)
287 return -ENOMEM;
288
289 if (!devm_request_region(dev, base[id], STX104_EXTENT, 301 if (!devm_request_region(dev, base[id], STX104_EXTENT,
290 dev_name(dev))) { 302 dev_name(dev))) {
291 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n", 303 dev_err(dev, "Unable to lock port addresses (0x%X-0x%X)\n",
@@ -324,45 +336,26 @@ static int stx104_probe(struct device *dev, unsigned int id)
324 stx104gpio->chip.parent = dev; 336 stx104gpio->chip.parent = dev;
325 stx104gpio->chip.owner = THIS_MODULE; 337 stx104gpio->chip.owner = THIS_MODULE;
326 stx104gpio->chip.base = -1; 338 stx104gpio->chip.base = -1;
327 stx104gpio->chip.ngpio = 8; 339 stx104gpio->chip.ngpio = STX104_NGPIO;
340 stx104gpio->chip.names = stx104_names;
328 stx104gpio->chip.get_direction = stx104_gpio_get_direction; 341 stx104gpio->chip.get_direction = stx104_gpio_get_direction;
329 stx104gpio->chip.direction_input = stx104_gpio_direction_input; 342 stx104gpio->chip.direction_input = stx104_gpio_direction_input;
330 stx104gpio->chip.direction_output = stx104_gpio_direction_output; 343 stx104gpio->chip.direction_output = stx104_gpio_direction_output;
331 stx104gpio->chip.get = stx104_gpio_get; 344 stx104gpio->chip.get = stx104_gpio_get;
332 stx104gpio->chip.set = stx104_gpio_set; 345 stx104gpio->chip.set = stx104_gpio_set;
346 stx104gpio->chip.set_multiple = stx104_gpio_set_multiple;
333 stx104gpio->base = base[id] + 3; 347 stx104gpio->base = base[id] + 3;
334 stx104gpio->out_state = 0x0; 348 stx104gpio->out_state = 0x0;
335 349
336 spin_lock_init(&stx104gpio->lock); 350 spin_lock_init(&stx104gpio->lock);
337 351
338 stx104dev->indio_dev = indio_dev; 352 err = devm_gpiochip_add_data(dev, &stx104gpio->chip, stx104gpio);
339 stx104dev->chip = &stx104gpio->chip;
340 dev_set_drvdata(dev, stx104dev);
341
342 err = gpiochip_add_data(&stx104gpio->chip, stx104gpio);
343 if (err) { 353 if (err) {
344 dev_err(dev, "GPIO registering failed (%d)\n", err); 354 dev_err(dev, "GPIO registering failed (%d)\n", err);
345 return err; 355 return err;
346 } 356 }
347 357
348 err = iio_device_register(indio_dev); 358 return devm_iio_device_register(dev, indio_dev);
349 if (err) {
350 dev_err(dev, "IIO device registering failed (%d)\n", err);
351 gpiochip_remove(&stx104gpio->chip);
352 return err;
353 }
354
355 return 0;
356}
357
358static int stx104_remove(struct device *dev, unsigned int id)
359{
360 struct stx104_dev *const stx104dev = dev_get_drvdata(dev);
361
362 iio_device_unregister(stx104dev->indio_dev);
363 gpiochip_remove(stx104dev->chip);
364
365 return 0;
366} 359}
367 360
368static struct isa_driver stx104_driver = { 361static struct isa_driver stx104_driver = {
@@ -370,7 +363,6 @@ static struct isa_driver stx104_driver = {
370 .driver = { 363 .driver = {
371 .name = "stx104" 364 .name = "stx104"
372 }, 365 },
373 .remove = stx104_remove
374}; 366};
375 367
376module_isa_driver(stx104_driver, num_stx104); 368module_isa_driver(stx104_driver, num_stx104);
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index cde6f130a99a..422b314f5a3f 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -472,14 +472,14 @@ static const struct attribute_group ads1115_attribute_group = {
472 .attrs = ads1115_attributes, 472 .attrs = ads1115_attributes,
473}; 473};
474 474
475static struct iio_info ads1015_info = { 475static const struct iio_info ads1015_info = {
476 .driver_module = THIS_MODULE, 476 .driver_module = THIS_MODULE,
477 .read_raw = ads1015_read_raw, 477 .read_raw = ads1015_read_raw,
478 .write_raw = ads1015_write_raw, 478 .write_raw = ads1015_write_raw,
479 .attrs = &ads1015_attribute_group, 479 .attrs = &ads1015_attribute_group,
480}; 480};
481 481
482static struct iio_info ads1115_info = { 482static const struct iio_info ads1115_info = {
483 .driver_module = THIS_MODULE, 483 .driver_module = THIS_MODULE,
484 .read_raw = ads1015_read_raw, 484 .read_raw = ads1015_read_raw,
485 .write_raw = ads1015_write_raw, 485 .write_raw = ads1015_write_raw,
diff --git a/drivers/iio/adc/ti-ads7950.c b/drivers/iio/adc/ti-ads7950.c
new file mode 100644
index 000000000000..16a06633332c
--- /dev/null
+++ b/drivers/iio/adc/ti-ads7950.c
@@ -0,0 +1,490 @@
1/*
2 * Texas Instruments ADS7950 SPI ADC driver
3 *
4 * Copyright 2016 David Lechner <david@lechnology.com>
5 *
6 * Based on iio/ad7923.c:
7 * Copyright 2011 Analog Devices Inc
8 * Copyright 2012 CS Systemes d'Information
9 *
10 * And also on hwmon/ads79xx.c
11 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
12 * Nishanth Menon
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation version 2.
17 *
18 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
19 * kind, whether express or implied; without even the implied warranty
20 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */
23
24#include <linux/bitops.h>
25#include <linux/device.h>
26#include <linux/err.h>
27#include <linux/interrupt.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/regulator/consumer.h>
31#include <linux/slab.h>
32#include <linux/spi/spi.h>
33
34#include <linux/iio/buffer.h>
35#include <linux/iio/iio.h>
36#include <linux/iio/sysfs.h>
37#include <linux/iio/trigger_consumer.h>
38#include <linux/iio/triggered_buffer.h>
39
40#define TI_ADS7950_CR_MANUAL BIT(12)
41#define TI_ADS7950_CR_WRITE BIT(11)
42#define TI_ADS7950_CR_CHAN(ch) ((ch) << 7)
43#define TI_ADS7950_CR_RANGE_5V BIT(6)
44
45#define TI_ADS7950_MAX_CHAN 16
46
47#define TI_ADS7950_TIMESTAMP_SIZE (sizeof(int64_t) / sizeof(__be16))
48
49/* val = value, dec = left shift, bits = number of bits of the mask */
50#define TI_ADS7950_EXTRACT(val, dec, bits) \
51 (((val) >> (dec)) & ((1 << (bits)) - 1))
52
53struct ti_ads7950_state {
54 struct spi_device *spi;
55 struct spi_transfer ring_xfer[TI_ADS7950_MAX_CHAN + 2];
56 struct spi_transfer scan_single_xfer[3];
57 struct spi_message ring_msg;
58 struct spi_message scan_single_msg;
59
60 struct regulator *reg;
61
62 unsigned int settings;
63
64 /*
65 * DMA (thus cache coherency maintenance) requires the
66 * transfer buffers to live in their own cache lines.
67 */
68 __be16 rx_buf[TI_ADS7950_MAX_CHAN + TI_ADS7950_TIMESTAMP_SIZE]
69 ____cacheline_aligned;
70 __be16 tx_buf[TI_ADS7950_MAX_CHAN];
71};
72
73struct ti_ads7950_chip_info {
74 const struct iio_chan_spec *channels;
75 unsigned int num_channels;
76};
77
78enum ti_ads7950_id {
79 TI_ADS7950,
80 TI_ADS7951,
81 TI_ADS7952,
82 TI_ADS7953,
83 TI_ADS7954,
84 TI_ADS7955,
85 TI_ADS7956,
86 TI_ADS7957,
87 TI_ADS7958,
88 TI_ADS7959,
89 TI_ADS7960,
90 TI_ADS7961,
91};
92
93#define TI_ADS7950_V_CHAN(index, bits) \
94{ \
95 .type = IIO_VOLTAGE, \
96 .indexed = 1, \
97 .channel = index, \
98 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
99 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
100 .address = index, \
101 .datasheet_name = "CH##index", \
102 .scan_index = index, \
103 .scan_type = { \
104 .sign = 'u', \
105 .realbits = bits, \
106 .storagebits = 16, \
107 .shift = 12 - (bits), \
108 .endianness = IIO_BE, \
109 }, \
110}
111
112#define DECLARE_TI_ADS7950_4_CHANNELS(name, bits) \
113const struct iio_chan_spec name ## _channels[] = { \
114 TI_ADS7950_V_CHAN(0, bits), \
115 TI_ADS7950_V_CHAN(1, bits), \
116 TI_ADS7950_V_CHAN(2, bits), \
117 TI_ADS7950_V_CHAN(3, bits), \
118 IIO_CHAN_SOFT_TIMESTAMP(4), \
119}
120
121#define DECLARE_TI_ADS7950_8_CHANNELS(name, bits) \
122const struct iio_chan_spec name ## _channels[] = { \
123 TI_ADS7950_V_CHAN(0, bits), \
124 TI_ADS7950_V_CHAN(1, bits), \
125 TI_ADS7950_V_CHAN(2, bits), \
126 TI_ADS7950_V_CHAN(3, bits), \
127 TI_ADS7950_V_CHAN(4, bits), \
128 TI_ADS7950_V_CHAN(5, bits), \
129 TI_ADS7950_V_CHAN(6, bits), \
130 TI_ADS7950_V_CHAN(7, bits), \
131 IIO_CHAN_SOFT_TIMESTAMP(8), \
132}
133
134#define DECLARE_TI_ADS7950_12_CHANNELS(name, bits) \
135const struct iio_chan_spec name ## _channels[] = { \
136 TI_ADS7950_V_CHAN(0, bits), \
137 TI_ADS7950_V_CHAN(1, bits), \
138 TI_ADS7950_V_CHAN(2, bits), \
139 TI_ADS7950_V_CHAN(3, bits), \
140 TI_ADS7950_V_CHAN(4, bits), \
141 TI_ADS7950_V_CHAN(5, bits), \
142 TI_ADS7950_V_CHAN(6, bits), \
143 TI_ADS7950_V_CHAN(7, bits), \
144 TI_ADS7950_V_CHAN(8, bits), \
145 TI_ADS7950_V_CHAN(9, bits), \
146 TI_ADS7950_V_CHAN(10, bits), \
147 TI_ADS7950_V_CHAN(11, bits), \
148 IIO_CHAN_SOFT_TIMESTAMP(12), \
149}
150
151#define DECLARE_TI_ADS7950_16_CHANNELS(name, bits) \
152const struct iio_chan_spec name ## _channels[] = { \
153 TI_ADS7950_V_CHAN(0, bits), \
154 TI_ADS7950_V_CHAN(1, bits), \
155 TI_ADS7950_V_CHAN(2, bits), \
156 TI_ADS7950_V_CHAN(3, bits), \
157 TI_ADS7950_V_CHAN(4, bits), \
158 TI_ADS7950_V_CHAN(5, bits), \
159 TI_ADS7950_V_CHAN(6, bits), \
160 TI_ADS7950_V_CHAN(7, bits), \
161 TI_ADS7950_V_CHAN(8, bits), \
162 TI_ADS7950_V_CHAN(9, bits), \
163 TI_ADS7950_V_CHAN(10, bits), \
164 TI_ADS7950_V_CHAN(11, bits), \
165 TI_ADS7950_V_CHAN(12, bits), \
166 TI_ADS7950_V_CHAN(13, bits), \
167 TI_ADS7950_V_CHAN(14, bits), \
168 TI_ADS7950_V_CHAN(15, bits), \
169 IIO_CHAN_SOFT_TIMESTAMP(16), \
170}
171
172static DECLARE_TI_ADS7950_4_CHANNELS(ti_ads7950, 12);
173static DECLARE_TI_ADS7950_8_CHANNELS(ti_ads7951, 12);
174static DECLARE_TI_ADS7950_12_CHANNELS(ti_ads7952, 12);
175static DECLARE_TI_ADS7950_16_CHANNELS(ti_ads7953, 12);
176static DECLARE_TI_ADS7950_4_CHANNELS(ti_ads7954, 10);
177static DECLARE_TI_ADS7950_8_CHANNELS(ti_ads7955, 10);
178static DECLARE_TI_ADS7950_12_CHANNELS(ti_ads7956, 10);
179static DECLARE_TI_ADS7950_16_CHANNELS(ti_ads7957, 10);
180static DECLARE_TI_ADS7950_4_CHANNELS(ti_ads7958, 8);
181static DECLARE_TI_ADS7950_8_CHANNELS(ti_ads7959, 8);
182static DECLARE_TI_ADS7950_12_CHANNELS(ti_ads7960, 8);
183static DECLARE_TI_ADS7950_16_CHANNELS(ti_ads7961, 8);
184
185static const struct ti_ads7950_chip_info ti_ads7950_chip_info[] = {
186 [TI_ADS7950] = {
187 .channels = ti_ads7950_channels,
188 .num_channels = ARRAY_SIZE(ti_ads7950_channels),
189 },
190 [TI_ADS7951] = {
191 .channels = ti_ads7951_channels,
192 .num_channels = ARRAY_SIZE(ti_ads7951_channels),
193 },
194 [TI_ADS7952] = {
195 .channels = ti_ads7952_channels,
196 .num_channels = ARRAY_SIZE(ti_ads7952_channels),
197 },
198 [TI_ADS7953] = {
199 .channels = ti_ads7953_channels,
200 .num_channels = ARRAY_SIZE(ti_ads7953_channels),
201 },
202 [TI_ADS7954] = {
203 .channels = ti_ads7954_channels,
204 .num_channels = ARRAY_SIZE(ti_ads7954_channels),
205 },
206 [TI_ADS7955] = {
207 .channels = ti_ads7955_channels,
208 .num_channels = ARRAY_SIZE(ti_ads7955_channels),
209 },
210 [TI_ADS7956] = {
211 .channels = ti_ads7956_channels,
212 .num_channels = ARRAY_SIZE(ti_ads7956_channels),
213 },
214 [TI_ADS7957] = {
215 .channels = ti_ads7957_channels,
216 .num_channels = ARRAY_SIZE(ti_ads7957_channels),
217 },
218 [TI_ADS7958] = {
219 .channels = ti_ads7958_channels,
220 .num_channels = ARRAY_SIZE(ti_ads7958_channels),
221 },
222 [TI_ADS7959] = {
223 .channels = ti_ads7959_channels,
224 .num_channels = ARRAY_SIZE(ti_ads7959_channels),
225 },
226 [TI_ADS7960] = {
227 .channels = ti_ads7960_channels,
228 .num_channels = ARRAY_SIZE(ti_ads7960_channels),
229 },
230 [TI_ADS7961] = {
231 .channels = ti_ads7961_channels,
232 .num_channels = ARRAY_SIZE(ti_ads7961_channels),
233 },
234};
235
236/*
237 * ti_ads7950_update_scan_mode() setup the spi transfer buffer for the new
238 * scan mask
239 */
240static int ti_ads7950_update_scan_mode(struct iio_dev *indio_dev,
241 const unsigned long *active_scan_mask)
242{
243 struct ti_ads7950_state *st = iio_priv(indio_dev);
244 int i, cmd, len;
245
246 len = 0;
247 for_each_set_bit(i, active_scan_mask, indio_dev->num_channels) {
248 cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(i) | st->settings;
249 st->tx_buf[len++] = cpu_to_be16(cmd);
250 }
251
252 /* Data for the 1st channel is not returned until the 3rd transfer */
253 len += 2;
254 for (i = 0; i < len; i++) {
255 if ((i + 2) < len)
256 st->ring_xfer[i].tx_buf = &st->tx_buf[i];
257 if (i >= 2)
258 st->ring_xfer[i].rx_buf = &st->rx_buf[i - 2];
259 st->ring_xfer[i].len = 2;
260 st->ring_xfer[i].cs_change = 1;
261 }
262 /* make sure last transfer's cs_change is not set */
263 st->ring_xfer[len - 1].cs_change = 0;
264
265 spi_message_init_with_transfers(&st->ring_msg, st->ring_xfer, len);
266
267 return 0;
268}
269
270static irqreturn_t ti_ads7950_trigger_handler(int irq, void *p)
271{
272 struct iio_poll_func *pf = p;
273 struct iio_dev *indio_dev = pf->indio_dev;
274 struct ti_ads7950_state *st = iio_priv(indio_dev);
275 int ret;
276
277 ret = spi_sync(st->spi, &st->ring_msg);
278 if (ret < 0)
279 goto out;
280
281 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
282 iio_get_time_ns(indio_dev));
283
284out:
285 iio_trigger_notify_done(indio_dev->trig);
286
287 return IRQ_HANDLED;
288}
289
290static int ti_ads7950_scan_direct(struct ti_ads7950_state *st, unsigned int ch)
291{
292 int ret, cmd;
293
294 cmd = TI_ADS7950_CR_WRITE | TI_ADS7950_CR_CHAN(ch) | st->settings;
295 st->tx_buf[0] = cpu_to_be16(cmd);
296
297 ret = spi_sync(st->spi, &st->scan_single_msg);
298 if (ret)
299 return ret;
300
301 return be16_to_cpu(st->rx_buf[0]);
302}
303
304static int ti_ads7950_get_range(struct ti_ads7950_state *st)
305{
306 int vref;
307
308 vref = regulator_get_voltage(st->reg);
309 if (vref < 0)
310 return vref;
311
312 vref /= 1000;
313
314 if (st->settings & TI_ADS7950_CR_RANGE_5V)
315 vref *= 2;
316
317 return vref;
318}
319
320static int ti_ads7950_read_raw(struct iio_dev *indio_dev,
321 struct iio_chan_spec const *chan,
322 int *val, int *val2, long m)
323{
324 struct ti_ads7950_state *st = iio_priv(indio_dev);
325 int ret;
326
327 switch (m) {
328 case IIO_CHAN_INFO_RAW:
329
330 ret = iio_device_claim_direct_mode(indio_dev);
331 if (ret < 0)
332 return ret;
333
334 ret = ti_ads7950_scan_direct(st, chan->address);
335 iio_device_release_direct_mode(indio_dev);
336 if (ret < 0)
337 return ret;
338
339 if (chan->address != TI_ADS7950_EXTRACT(ret, 12, 4))
340 return -EIO;
341
342 *val = TI_ADS7950_EXTRACT(ret, chan->scan_type.shift,
343 chan->scan_type.realbits);
344
345 return IIO_VAL_INT;
346 case IIO_CHAN_INFO_SCALE:
347 ret = ti_ads7950_get_range(st);
348 if (ret < 0)
349 return ret;
350
351 *val = ret;
352 *val2 = (1 << chan->scan_type.realbits) - 1;
353
354 return IIO_VAL_FRACTIONAL;
355 }
356
357 return -EINVAL;
358}
359
360static const struct iio_info ti_ads7950_info = {
361 .read_raw = &ti_ads7950_read_raw,
362 .update_scan_mode = ti_ads7950_update_scan_mode,
363 .driver_module = THIS_MODULE,
364};
365
366static int ti_ads7950_probe(struct spi_device *spi)
367{
368 struct ti_ads7950_state *st;
369 struct iio_dev *indio_dev;
370 const struct ti_ads7950_chip_info *info;
371 int ret;
372
373 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
374 if (!indio_dev)
375 return -ENOMEM;
376
377 st = iio_priv(indio_dev);
378
379 spi_set_drvdata(spi, indio_dev);
380
381 st->spi = spi;
382 st->settings = TI_ADS7950_CR_MANUAL | TI_ADS7950_CR_RANGE_5V;
383
384 info = &ti_ads7950_chip_info[spi_get_device_id(spi)->driver_data];
385
386 indio_dev->name = spi_get_device_id(spi)->name;
387 indio_dev->dev.parent = &spi->dev;
388 indio_dev->modes = INDIO_DIRECT_MODE;
389 indio_dev->channels = info->channels;
390 indio_dev->num_channels = info->num_channels;
391 indio_dev->info = &ti_ads7950_info;
392
393 /*
394 * Setup default message. The sample is read at the end of the first
395 * transfer, then it takes one full cycle to convert the sample and one
396 * more cycle to send the value. The conversion process is driven by
397 * the SPI clock, which is why we have 3 transfers. The middle one is
398 * just dummy data sent while the chip is converting the sample that
399 * was read at the end of the first transfer.
400 */
401
402 st->scan_single_xfer[0].tx_buf = &st->tx_buf[0];
403 st->scan_single_xfer[0].len = 2;
404 st->scan_single_xfer[0].cs_change = 1;
405 st->scan_single_xfer[1].tx_buf = &st->tx_buf[0];
406 st->scan_single_xfer[1].len = 2;
407 st->scan_single_xfer[1].cs_change = 1;
408 st->scan_single_xfer[2].rx_buf = &st->rx_buf[0];
409 st->scan_single_xfer[2].len = 2;
410
411 spi_message_init_with_transfers(&st->scan_single_msg,
412 st->scan_single_xfer, 3);
413
414 st->reg = devm_regulator_get(&spi->dev, "vref");
415 if (IS_ERR(st->reg)) {
416 dev_err(&spi->dev, "Failed get get regulator \"vref\"\n");
417 return PTR_ERR(st->reg);
418 }
419
420 ret = regulator_enable(st->reg);
421 if (ret) {
422 dev_err(&spi->dev, "Failed to enable regulator \"vref\"\n");
423 return ret;
424 }
425
426 ret = iio_triggered_buffer_setup(indio_dev, NULL,
427 &ti_ads7950_trigger_handler, NULL);
428 if (ret) {
429 dev_err(&spi->dev, "Failed to setup triggered buffer\n");
430 goto error_disable_reg;
431 }
432
433 ret = iio_device_register(indio_dev);
434 if (ret) {
435 dev_err(&spi->dev, "Failed to register iio device\n");
436 goto error_cleanup_ring;
437 }
438
439 return 0;
440
441error_cleanup_ring:
442 iio_triggered_buffer_cleanup(indio_dev);
443error_disable_reg:
444 regulator_disable(st->reg);
445
446 return ret;
447}
448
449static int ti_ads7950_remove(struct spi_device *spi)
450{
451 struct iio_dev *indio_dev = spi_get_drvdata(spi);
452 struct ti_ads7950_state *st = iio_priv(indio_dev);
453
454 iio_device_unregister(indio_dev);
455 iio_triggered_buffer_cleanup(indio_dev);
456 regulator_disable(st->reg);
457
458 return 0;
459}
460
461static const struct spi_device_id ti_ads7950_id[] = {
462 { "ads7950", TI_ADS7950 },
463 { "ads7951", TI_ADS7951 },
464 { "ads7952", TI_ADS7952 },
465 { "ads7953", TI_ADS7953 },
466 { "ads7954", TI_ADS7954 },
467 { "ads7955", TI_ADS7955 },
468 { "ads7956", TI_ADS7956 },
469 { "ads7957", TI_ADS7957 },
470 { "ads7958", TI_ADS7958 },
471 { "ads7959", TI_ADS7959 },
472 { "ads7960", TI_ADS7960 },
473 { "ads7961", TI_ADS7961 },
474 { }
475};
476MODULE_DEVICE_TABLE(spi, ti_ads7950_id);
477
478static struct spi_driver ti_ads7950_driver = {
479 .driver = {
480 .name = "ads7950",
481 },
482 .probe = ti_ads7950_probe,
483 .remove = ti_ads7950_remove,
484 .id_table = ti_ads7950_id,
485};
486module_spi_driver(ti_ads7950_driver);
487
488MODULE_AUTHOR("David Lechner <david@lechnology.com>");
489MODULE_DESCRIPTION("TI TI_ADS7950 ADC");
490MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/ti-tlc4541.c b/drivers/iio/adc/ti-tlc4541.c
new file mode 100644
index 000000000000..78d91a069ea4
--- /dev/null
+++ b/drivers/iio/adc/ti-tlc4541.c
@@ -0,0 +1,271 @@
1/*
2 * TI tlc4541 ADC Driver
3 *
4 * Copyright (C) 2017 Phil Reid
5 *
6 * Datasheets can be found here:
7 * http://www.ti.com/lit/gpn/tlc3541
8 * http://www.ti.com/lit/gpn/tlc4541
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 version 2 as
12 * published by the Free Software Foundation.
13 *
14 * The tlc4541 requires 24 clock cycles to start a transfer.
15 * Conversion then takes 2.94us to complete before data is ready
16 * Data is returned MSB first.
17 */
18
19#include <linux/delay.h>
20#include <linux/device.h>
21#include <linux/err.h>
22#include <linux/interrupt.h>
23#include <linux/iio/iio.h>
24#include <linux/iio/sysfs.h>
25#include <linux/iio/buffer.h>
26#include <linux/iio/trigger_consumer.h>
27#include <linux/iio/triggered_buffer.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/regulator/consumer.h>
31#include <linux/slab.h>
32#include <linux/spi/spi.h>
33#include <linux/sysfs.h>
34
35struct tlc4541_state {
36 struct spi_device *spi;
37 struct regulator *reg;
38 struct spi_transfer scan_single_xfer[3];
39 struct spi_message scan_single_msg;
40
41 /*
42 * DMA (thus cache coherency maintenance) requires the
43 * transfer buffers to live in their own cache lines.
44 * 2 bytes data + 6 bytes padding + 8 bytes timestamp when
45 * call iio_push_to_buffers_with_timestamp.
46 */
47 __be16 rx_buf[8] ____cacheline_aligned;
48};
49
50struct tlc4541_chip_info {
51 const struct iio_chan_spec *channels;
52 unsigned int num_channels;
53};
54
55enum tlc4541_id {
56 TLC3541,
57 TLC4541,
58};
59
60#define TLC4541_V_CHAN(bits, bitshift) { \
61 .type = IIO_VOLTAGE, \
62 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
63 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
64 .scan_type = { \
65 .sign = 'u', \
66 .realbits = (bits), \
67 .storagebits = 16, \
68 .shift = (bitshift), \
69 .endianness = IIO_BE, \
70 }, \
71 }
72
73#define DECLARE_TLC4541_CHANNELS(name, bits, bitshift) \
74const struct iio_chan_spec name ## _channels[] = { \
75 TLC4541_V_CHAN(bits, bitshift), \
76 IIO_CHAN_SOFT_TIMESTAMP(1), \
77}
78
79static DECLARE_TLC4541_CHANNELS(tlc3541, 14, 2);
80static DECLARE_TLC4541_CHANNELS(tlc4541, 16, 0);
81
82static const struct tlc4541_chip_info tlc4541_chip_info[] = {
83 [TLC3541] = {
84 .channels = tlc3541_channels,
85 .num_channels = ARRAY_SIZE(tlc3541_channels),
86 },
87 [TLC4541] = {
88 .channels = tlc4541_channels,
89 .num_channels = ARRAY_SIZE(tlc4541_channels),
90 },
91};
92
93static irqreturn_t tlc4541_trigger_handler(int irq, void *p)
94{
95 struct iio_poll_func *pf = p;
96 struct iio_dev *indio_dev = pf->indio_dev;
97 struct tlc4541_state *st = iio_priv(indio_dev);
98 int ret;
99
100 ret = spi_sync(st->spi, &st->scan_single_msg);
101 if (ret < 0)
102 goto done;
103
104 iio_push_to_buffers_with_timestamp(indio_dev, st->rx_buf,
105 iio_get_time_ns(indio_dev));
106
107done:
108 iio_trigger_notify_done(indio_dev->trig);
109 return IRQ_HANDLED;
110}
111
112static int tlc4541_get_range(struct tlc4541_state *st)
113{
114 int vref;
115
116 vref = regulator_get_voltage(st->reg);
117 if (vref < 0)
118 return vref;
119
120 vref /= 1000;
121
122 return vref;
123}
124
125static int tlc4541_read_raw(struct iio_dev *indio_dev,
126 struct iio_chan_spec const *chan,
127 int *val,
128 int *val2,
129 long m)
130{
131 int ret = 0;
132 struct tlc4541_state *st = iio_priv(indio_dev);
133
134 switch (m) {
135 case IIO_CHAN_INFO_RAW:
136 ret = iio_device_claim_direct_mode(indio_dev);
137 if (ret)
138 return ret;
139 ret = spi_sync(st->spi, &st->scan_single_msg);
140 iio_device_release_direct_mode(indio_dev);
141 if (ret < 0)
142 return ret;
143 *val = be16_to_cpu(st->rx_buf[0]);
144 *val = *val >> chan->scan_type.shift;
145 *val &= GENMASK(chan->scan_type.realbits - 1, 0);
146 return IIO_VAL_INT;
147 case IIO_CHAN_INFO_SCALE:
148 ret = tlc4541_get_range(st);
149 if (ret < 0)
150 return ret;
151 *val = ret;
152 *val2 = chan->scan_type.realbits;
153 return IIO_VAL_FRACTIONAL_LOG2;
154 }
155 return -EINVAL;
156}
157
158static const struct iio_info tlc4541_info = {
159 .read_raw = &tlc4541_read_raw,
160 .driver_module = THIS_MODULE,
161};
162
163static int tlc4541_probe(struct spi_device *spi)
164{
165 struct tlc4541_state *st;
166 struct iio_dev *indio_dev;
167 const struct tlc4541_chip_info *info;
168 int ret;
169 int8_t device_init = 0;
170
171 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
172 if (indio_dev == NULL)
173 return -ENOMEM;
174
175 st = iio_priv(indio_dev);
176
177 spi_set_drvdata(spi, indio_dev);
178
179 st->spi = spi;
180
181 info = &tlc4541_chip_info[spi_get_device_id(spi)->driver_data];
182
183 indio_dev->name = spi_get_device_id(spi)->name;
184 indio_dev->dev.parent = &spi->dev;
185 indio_dev->modes = INDIO_DIRECT_MODE;
186 indio_dev->channels = info->channels;
187 indio_dev->num_channels = info->num_channels;
188 indio_dev->info = &tlc4541_info;
189
190 /* perform reset */
191 spi_write(spi, &device_init, 1);
192
193 /* Setup default message */
194 st->scan_single_xfer[0].rx_buf = &st->rx_buf[0];
195 st->scan_single_xfer[0].len = 3;
196 st->scan_single_xfer[1].delay_usecs = 3;
197 st->scan_single_xfer[2].rx_buf = &st->rx_buf[0];
198 st->scan_single_xfer[2].len = 2;
199
200 spi_message_init_with_transfers(&st->scan_single_msg,
201 st->scan_single_xfer, 3);
202
203 st->reg = devm_regulator_get(&spi->dev, "vref");
204 if (IS_ERR(st->reg))
205 return PTR_ERR(st->reg);
206
207 ret = regulator_enable(st->reg);
208 if (ret)
209 return ret;
210
211 ret = iio_triggered_buffer_setup(indio_dev, NULL,
212 &tlc4541_trigger_handler, NULL);
213 if (ret)
214 goto error_disable_reg;
215
216 ret = iio_device_register(indio_dev);
217 if (ret)
218 goto error_cleanup_buffer;
219
220 return 0;
221
222error_cleanup_buffer:
223 iio_triggered_buffer_cleanup(indio_dev);
224error_disable_reg:
225 regulator_disable(st->reg);
226
227 return ret;
228}
229
230static int tlc4541_remove(struct spi_device *spi)
231{
232 struct iio_dev *indio_dev = spi_get_drvdata(spi);
233 struct tlc4541_state *st = iio_priv(indio_dev);
234
235 iio_device_unregister(indio_dev);
236 iio_triggered_buffer_cleanup(indio_dev);
237 regulator_disable(st->reg);
238
239 return 0;
240}
241
242#ifdef CONFIG_OF
243static const struct of_device_id tlc4541_dt_ids[] = {
244 { .compatible = "ti,tlc3541", },
245 { .compatible = "ti,tlc4541", },
246 {}
247};
248MODULE_DEVICE_TABLE(of, tlc4541_dt_ids);
249#endif
250
251static const struct spi_device_id tlc4541_id[] = {
252 {"tlc3541", TLC3541},
253 {"tlc4541", TLC4541},
254 {}
255};
256MODULE_DEVICE_TABLE(spi, tlc4541_id);
257
258static struct spi_driver tlc4541_driver = {
259 .driver = {
260 .name = "tlc4541",
261 .of_match_table = of_match_ptr(tlc4541_dt_ids),
262 },
263 .probe = tlc4541_probe,
264 .remove = tlc4541_remove,
265 .id_table = tlc4541_id,
266};
267module_spi_driver(tlc4541_driver);
268
269MODULE_AUTHOR("Phil Reid <preid@electromag.com.au>");
270MODULE_DESCRIPTION("Texas Instruments TLC4541 ADC");
271MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/buffer/industrialio-buffer-cb.c b/drivers/iio/buffer/industrialio-buffer-cb.c
index b8f550e47d3d..4847534700e7 100644
--- a/drivers/iio/buffer/industrialio-buffer-cb.c
+++ b/drivers/iio/buffer/industrialio-buffer-cb.c
@@ -10,7 +10,8 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/err.h> 11#include <linux/err.h>
12#include <linux/export.h> 12#include <linux/export.h>
13#include <linux/iio/buffer.h> 13#include <linux/iio/iio.h>
14#include <linux/iio/buffer_impl.h>
14#include <linux/iio/consumer.h> 15#include <linux/iio/consumer.h>
15 16
16struct iio_cb_buffer { 17struct iio_cb_buffer {
diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
index c5b999f0c519..047fe757ab97 100644
--- a/drivers/iio/buffer/kfifo_buf.c
+++ b/drivers/iio/buffer/kfifo_buf.c
@@ -5,7 +5,10 @@
5#include <linux/workqueue.h> 5#include <linux/workqueue.h>
6#include <linux/kfifo.h> 6#include <linux/kfifo.h>
7#include <linux/mutex.h> 7#include <linux/mutex.h>
8#include <linux/iio/iio.h>
9#include <linux/iio/buffer.h>
8#include <linux/iio/kfifo_buf.h> 10#include <linux/iio/kfifo_buf.h>
11#include <linux/iio/buffer_impl.h>
9#include <linux/sched.h> 12#include <linux/sched.h>
10#include <linux/poll.h> 13#include <linux/poll.h>
11 14
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 7ef94a90ecf7..7afdac42ed42 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -58,6 +58,10 @@ static struct {
58 58
59 {HID_USAGE_SENSOR_PRESSURE, 0, 100, 0}, 59 {HID_USAGE_SENSOR_PRESSURE, 0, 100, 0},
60 {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 0, 1000000}, 60 {HID_USAGE_SENSOR_PRESSURE, HID_USAGE_SENSOR_UNITS_PASCAL, 0, 1000000},
61
62 {HID_USAGE_SENSOR_TIME_TIMESTAMP, 0, 1000000000, 0},
63 {HID_USAGE_SENSOR_TIME_TIMESTAMP, HID_USAGE_SENSOR_UNITS_MILLISECOND,
64 1000000, 0},
61}; 65};
62 66
63static int pow_10(unsigned power) 67static int pow_10(unsigned power)
@@ -346,6 +350,13 @@ int hid_sensor_format_scale(u32 usage_id,
346} 350}
347EXPORT_SYMBOL(hid_sensor_format_scale); 351EXPORT_SYMBOL(hid_sensor_format_scale);
348 352
353int64_t hid_sensor_convert_timestamp(struct hid_sensor_common *st,
354 int64_t raw_value)
355{
356 return st->timestamp_ns_scale * raw_value;
357}
358EXPORT_SYMBOL(hid_sensor_convert_timestamp);
359
349static 360static
350int hid_sensor_get_reporting_interval(struct hid_sensor_hub_device *hsdev, 361int hid_sensor_get_reporting_interval(struct hid_sensor_hub_device *hsdev,
351 u32 usage_id, 362 u32 usage_id,
@@ -367,6 +378,7 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
367 struct hid_sensor_common *st) 378 struct hid_sensor_common *st)
368{ 379{
369 380
381 struct hid_sensor_hub_attribute_info timestamp;
370 382
371 hid_sensor_get_reporting_interval(hsdev, usage_id, st); 383 hid_sensor_get_reporting_interval(hsdev, usage_id, st);
372 384
@@ -385,11 +397,25 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
385 HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS, 397 HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS,
386 &st->sensitivity); 398 &st->sensitivity);
387 399
388 hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x\n", 400 sensor_hub_input_get_attribute_info(hsdev,
389 st->poll.index, st->poll.report_id, 401 HID_INPUT_REPORT, usage_id,
390 st->report_state.index, st->report_state.report_id, 402 HID_USAGE_SENSOR_TIME_TIMESTAMP,
391 st->power_state.index, st->power_state.report_id, 403 &timestamp);
392 st->sensitivity.index, st->sensitivity.report_id); 404 if (timestamp.index >= 0 && timestamp.report_id) {
405 int val0, val1;
406
407 hid_sensor_format_scale(HID_USAGE_SENSOR_TIME_TIMESTAMP,
408 &timestamp, &val0, &val1);
409 st->timestamp_ns_scale = val0;
410 } else
411 st->timestamp_ns_scale = 1000000000;
412
413 hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x %x:%x\n",
414 st->poll.index, st->poll.report_id,
415 st->report_state.index, st->report_state.report_id,
416 st->power_state.index, st->power_state.report_id,
417 st->sensitivity.index, st->sensitivity.report_id,
418 timestamp.index, timestamp.report_id);
393 419
394 return 0; 420 return 0;
395} 421}
diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c b/drivers/iio/common/ssp_sensors/ssp_iio.c
index a3ae165f8d9f..645f2e3975db 100644
--- a/drivers/iio/common/ssp_sensors/ssp_iio.c
+++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/iio/common/ssp_sensors.h> 16#include <linux/iio/common/ssp_sensors.h>
17#include <linux/iio/buffer.h>
17#include <linux/iio/kfifo_buf.h> 18#include <linux/iio/kfifo_buf.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
index b43aa36031f8..c83df4dbfcd7 100644
--- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/iio/iio.h> 14#include <linux/iio/iio.h>
15#include <linux/of_device.h> 15#include <linux/of_device.h>
16#include <linux/acpi.h>
16 17
17#include <linux/iio/common/st_sensors_i2c.h> 18#include <linux/iio/common/st_sensors_i2c.h>
18 19
@@ -107,6 +108,25 @@ void st_sensors_of_i2c_probe(struct i2c_client *client,
107EXPORT_SYMBOL(st_sensors_of_i2c_probe); 108EXPORT_SYMBOL(st_sensors_of_i2c_probe);
108#endif 109#endif
109 110
111#ifdef CONFIG_ACPI
112int st_sensors_match_acpi_device(struct device *dev)
113{
114 const struct acpi_device_id *acpi_id;
115 kernel_ulong_t driver_data = 0;
116
117 if (ACPI_HANDLE(dev)) {
118 acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
119 if (!acpi_id) {
120 dev_err(dev, "No driver data\n");
121 return -EINVAL;
122 }
123 driver_data = acpi_id->driver_data;
124 }
125 return driver_data;
126}
127EXPORT_SYMBOL(st_sensors_match_acpi_device);
128#endif
129
110MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>"); 130MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
111MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver"); 131MODULE_DESCRIPTION("STMicroelectronics ST-sensors i2c driver");
112MODULE_LICENSE("GPL v2"); 132MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/dac/ad5592r.c b/drivers/iio/dac/ad5592r.c
index 6eed5b7729be..6a12a3c9d94f 100644
--- a/drivers/iio/dac/ad5592r.c
+++ b/drivers/iio/dac/ad5592r.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/of.h> 14#include <linux/of.h>
15#include <linux/spi/spi.h> 15#include <linux/spi/spi.h>
16#include <linux/acpi.h>
16 17
17#define AD5592R_GPIO_READBACK_EN BIT(10) 18#define AD5592R_GPIO_READBACK_EN BIT(10)
18#define AD5592R_LDAC_READBACK_EN BIT(6) 19#define AD5592R_LDAC_READBACK_EN BIT(6)
@@ -148,10 +149,17 @@ static const struct of_device_id ad5592r_of_match[] = {
148}; 149};
149MODULE_DEVICE_TABLE(of, ad5592r_of_match); 150MODULE_DEVICE_TABLE(of, ad5592r_of_match);
150 151
152static const struct acpi_device_id ad5592r_acpi_match[] = {
153 {"ADS5592", },
154 { },
155};
156MODULE_DEVICE_TABLE(acpi, ad5592r_acpi_match);
157
151static struct spi_driver ad5592r_spi_driver = { 158static struct spi_driver ad5592r_spi_driver = {
152 .driver = { 159 .driver = {
153 .name = "ad5592r", 160 .name = "ad5592r",
154 .of_match_table = of_match_ptr(ad5592r_of_match), 161 .of_match_table = of_match_ptr(ad5592r_of_match),
162 .acpi_match_table = ACPI_PTR(ad5592r_acpi_match),
155 }, 163 },
156 .probe = ad5592r_spi_probe, 164 .probe = ad5592r_spi_probe,
157 .remove = ad5592r_spi_remove, 165 .remove = ad5592r_spi_remove,
diff --git a/drivers/iio/dac/ad5593r.c b/drivers/iio/dac/ad5593r.c
index dca158a88f47..fc11ea098f98 100644
--- a/drivers/iio/dac/ad5593r.c
+++ b/drivers/iio/dac/ad5593r.c
@@ -13,6 +13,7 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/of.h> 15#include <linux/of.h>
16#include <linux/acpi.h>
16 17
17#define AD5593R_MODE_CONF (0 << 4) 18#define AD5593R_MODE_CONF (0 << 4)
18#define AD5593R_MODE_DAC_WRITE (1 << 4) 19#define AD5593R_MODE_DAC_WRITE (1 << 4)
@@ -115,10 +116,17 @@ static const struct of_device_id ad5593r_of_match[] = {
115}; 116};
116MODULE_DEVICE_TABLE(of, ad5593r_of_match); 117MODULE_DEVICE_TABLE(of, ad5593r_of_match);
117 118
119static const struct acpi_device_id ad5593r_acpi_match[] = {
120 {"ADS5593", },
121 { },
122};
123MODULE_DEVICE_TABLE(acpi, ad5593r_acpi_match);
124
118static struct i2c_driver ad5593r_driver = { 125static struct i2c_driver ad5593r_driver = {
119 .driver = { 126 .driver = {
120 .name = "ad5593r", 127 .name = "ad5593r",
121 .of_match_table = of_match_ptr(ad5593r_of_match), 128 .of_match_table = of_match_ptr(ad5593r_of_match),
129 .acpi_match_table = ACPI_PTR(ad5593r_acpi_match),
122 }, 130 },
123 .probe = ad5593r_i2c_probe, 131 .probe = ad5593r_i2c_probe,
124 .remove = ad5593r_i2c_remove, 132 .remove = ad5593r_i2c_remove,
diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
index b9069a180672..f7005c3f5df3 100644
--- a/drivers/iio/dummy/iio_simple_dummy.h
+++ b/drivers/iio/dummy/iio_simple_dummy.h
@@ -88,11 +88,11 @@ static inline int
88iio_simple_dummy_events_register(struct iio_dev *indio_dev) 88iio_simple_dummy_events_register(struct iio_dev *indio_dev)
89{ 89{
90 return 0; 90 return 0;
91}; 91}
92 92
93static inline void 93static inline void
94iio_simple_dummy_events_unregister(struct iio_dev *indio_dev) 94iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
95{ }; 95{}
96 96
97#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/ 97#endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
98 98
@@ -119,11 +119,11 @@ void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
119static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev) 119static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
120{ 120{
121 return 0; 121 return 0;
122}; 122}
123 123
124static inline 124static inline
125void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) 125void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
126{}; 126{}
127 127
128#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */ 128#endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
129#endif /* _IIO_SIMPLE_DUMMY_H_ */ 129#endif /* _IIO_SIMPLE_DUMMY_H_ */
diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c
index b383892a5193..744ca92c3c99 100644
--- a/drivers/iio/dummy/iio_simple_dummy_buffer.c
+++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/iio/iio.h> 21#include <linux/iio/iio.h>
22#include <linux/iio/trigger_consumer.h> 22#include <linux/iio/trigger_consumer.h>
23#include <linux/iio/buffer.h>
23#include <linux/iio/kfifo_buf.h> 24#include <linux/iio/kfifo_buf.h>
24 25
25#include "iio_simple_dummy.h" 26#include "iio_simple_dummy.h"
@@ -131,9 +132,6 @@ int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
131 132
132 iio_device_attach_buffer(indio_dev, buffer); 133 iio_device_attach_buffer(indio_dev, buffer);
133 134
134 /* Enable timestamps by default */
135 buffer->scan_timestamp = true;
136
137 /* 135 /*
138 * Tell the core what device type specific functions should 136 * Tell the core what device type specific functions should
139 * be run on either side of buffer capture enable / disable. 137 * be run on either side of buffer capture enable / disable.
diff --git a/drivers/iio/gyro/ssp_gyro_sensor.c b/drivers/iio/gyro/ssp_gyro_sensor.c
index 1f25f406c545..2dacd8e01045 100644
--- a/drivers/iio/gyro/ssp_gyro_sensor.c
+++ b/drivers/iio/gyro/ssp_gyro_sensor.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/iio/common/ssp_sensors.h> 16#include <linux/iio/common/ssp_sensors.h>
17#include <linux/iio/iio.h> 17#include <linux/iio/iio.h>
18#include <linux/iio/buffer.h>
18#include <linux/iio/kfifo_buf.h> 19#include <linux/iio/kfifo_buf.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
@@ -134,7 +135,7 @@ static int ssp_gyro_probe(struct platform_device *pdev)
134 135
135 platform_set_drvdata(pdev, indio_dev); 136 platform_set_drvdata(pdev, indio_dev);
136 137
137 ret = iio_device_register(indio_dev); 138 ret = devm_iio_device_register(&pdev->dev, indio_dev);
138 if (ret < 0) 139 if (ret < 0)
139 return ret; 140 return ret;
140 141
@@ -144,21 +145,11 @@ static int ssp_gyro_probe(struct platform_device *pdev)
144 return 0; 145 return 0;
145} 146}
146 147
147static int ssp_gyro_remove(struct platform_device *pdev)
148{
149 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
150
151 iio_device_unregister(indio_dev);
152
153 return 0;
154}
155
156static struct platform_driver ssp_gyro_driver = { 148static struct platform_driver ssp_gyro_driver = {
157 .driver = { 149 .driver = {
158 .name = SSP_GYROSCOPE_NAME, 150 .name = SSP_GYROSCOPE_NAME,
159 }, 151 },
160 .probe = ssp_gyro_probe, 152 .probe = ssp_gyro_probe,
161 .remove = ssp_gyro_remove,
162}; 153};
163 154
164module_platform_driver(ssp_gyro_driver); 155module_platform_driver(ssp_gyro_driver);
diff --git a/drivers/iio/health/max30100.c b/drivers/iio/health/max30100.c
index 183c14329d6e..f6e283c4d686 100644
--- a/drivers/iio/health/max30100.c
+++ b/drivers/iio/health/max30100.c
@@ -378,7 +378,7 @@ static int max30100_get_temp(struct max30100_data *data, int *val)
378 if (ret) 378 if (ret)
379 return ret; 379 return ret;
380 380
381 usleep_range(35000, 50000); 381 msleep(35);
382 382
383 return max30100_read_temp(data, val); 383 return max30100_read_temp(data, val);
384} 384}
diff --git a/drivers/iio/humidity/hts221_i2c.c b/drivers/iio/humidity/hts221_i2c.c
index 367ecd509f31..8333c0296c0e 100644
--- a/drivers/iio/humidity/hts221_i2c.c
+++ b/drivers/iio/humidity/hts221_i2c.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/acpi.h>
13#include <linux/i2c.h> 14#include <linux/i2c.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15#include "hts221.h" 16#include "hts221.h"
@@ -83,6 +84,12 @@ static int hts221_i2c_probe(struct i2c_client *client,
83 return hts221_probe(iio_dev); 84 return hts221_probe(iio_dev);
84} 85}
85 86
87static const struct acpi_device_id hts221_acpi_match[] = {
88 {"SMO9100", 0},
89 { },
90};
91MODULE_DEVICE_TABLE(acpi, hts221_acpi_match);
92
86static const struct of_device_id hts221_i2c_of_match[] = { 93static const struct of_device_id hts221_i2c_of_match[] = {
87 { .compatible = "st,hts221", }, 94 { .compatible = "st,hts221", },
88 {}, 95 {},
@@ -99,6 +106,7 @@ static struct i2c_driver hts221_driver = {
99 .driver = { 106 .driver = {
100 .name = "hts221_i2c", 107 .name = "hts221_i2c",
101 .of_match_table = of_match_ptr(hts221_i2c_of_match), 108 .of_match_table = of_match_ptr(hts221_i2c_of_match),
109 .acpi_match_table = ACPI_PTR(hts221_acpi_match),
102 }, 110 },
103 .probe = hts221_i2c_probe, 111 .probe = hts221_i2c_probe,
104 .id_table = hts221_i2c_id_table, 112 .id_table = hts221_i2c_id_table,
diff --git a/drivers/iio/imu/Kconfig b/drivers/iio/imu/Kconfig
index 1f1ad41ef881..156630a21696 100644
--- a/drivers/iio/imu/Kconfig
+++ b/drivers/iio/imu/Kconfig
@@ -39,6 +39,7 @@ config KMX61
39 be called kmx61. 39 be called kmx61.
40 40
41source "drivers/iio/imu/inv_mpu6050/Kconfig" 41source "drivers/iio/imu/inv_mpu6050/Kconfig"
42source "drivers/iio/imu/st_lsm6dsx/Kconfig"
42 43
43endmenu 44endmenu
44 45
diff --git a/drivers/iio/imu/Makefile b/drivers/iio/imu/Makefile
index c71bcd30dc38..8b563c3323b5 100644
--- a/drivers/iio/imu/Makefile
+++ b/drivers/iio/imu/Makefile
@@ -17,3 +17,5 @@ obj-y += bmi160/
17obj-y += inv_mpu6050/ 17obj-y += inv_mpu6050/
18 18
19obj-$(CONFIG_KMX61) += kmx61.o 19obj-$(CONFIG_KMX61) += kmx61.o
20
21obj-y += st_lsm6dsx/
diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index c9e319bff58b..cfd225ed1c8d 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -325,9 +325,9 @@ static int bmi160_get_data(struct bmi160_data *data, int chan_type,
325 __le16 sample; 325 __le16 sample;
326 enum bmi160_sensor_type t = bmi160_to_sensor(chan_type); 326 enum bmi160_sensor_type t = bmi160_to_sensor(chan_type);
327 327
328 reg = bmi160_regs[t].data + (axis - IIO_MOD_X) * sizeof(__le16); 328 reg = bmi160_regs[t].data + (axis - IIO_MOD_X) * sizeof(sample);
329 329
330 ret = regmap_bulk_read(data->regmap, reg, &sample, sizeof(__le16)); 330 ret = regmap_bulk_read(data->regmap, reg, &sample, sizeof(sample));
331 if (ret < 0) 331 if (ret < 0)
332 return ret; 332 return ret;
333 333
@@ -392,8 +392,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)
392 392
393 for_each_set_bit(i, indio_dev->active_scan_mask, 393 for_each_set_bit(i, indio_dev->active_scan_mask,
394 indio_dev->masklength) { 394 indio_dev->masklength) {
395 ret = regmap_bulk_read(data->regmap, base + i * sizeof(__le16), 395 ret = regmap_bulk_read(data->regmap, base + i * sizeof(sample),
396 &sample, sizeof(__le16)); 396 &sample, sizeof(sample));
397 if (ret < 0) 397 if (ret < 0)
398 goto done; 398 goto done;
399 buf[j++] = sample; 399 buf[j++] = sample;
diff --git a/drivers/iio/imu/bmi160/bmi160_i2c.c b/drivers/iio/imu/bmi160/bmi160_i2c.c
index 07a179d8fb48..155a31f72445 100644
--- a/drivers/iio/imu/bmi160/bmi160_i2c.c
+++ b/drivers/iio/imu/bmi160/bmi160_i2c.c
@@ -11,10 +11,11 @@
11 * - 0x68 if SDO is pulled to GND 11 * - 0x68 if SDO is pulled to GND
12 * - 0x69 if SDO is pulled to VDDIO 12 * - 0x69 if SDO is pulled to VDDIO
13 */ 13 */
14#include <linux/module.h> 14#include <linux/acpi.h>
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/module.h>
17#include <linux/of.h>
16#include <linux/regmap.h> 18#include <linux/regmap.h>
17#include <linux/acpi.h>
18 19
19#include "bmi160.h" 20#include "bmi160.h"
20 21
@@ -56,10 +57,19 @@ static const struct acpi_device_id bmi160_acpi_match[] = {
56}; 57};
57MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 58MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
58 59
60#ifdef CONFIG_OF
61static const struct of_device_id bmi160_of_match[] = {
62 { .compatible = "bosch,bmi160" },
63 { },
64};
65MODULE_DEVICE_TABLE(of, bmi160_of_match);
66#endif
67
59static struct i2c_driver bmi160_i2c_driver = { 68static struct i2c_driver bmi160_i2c_driver = {
60 .driver = { 69 .driver = {
61 .name = "bmi160_i2c", 70 .name = "bmi160_i2c",
62 .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 71 .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
72 .of_match_table = of_match_ptr(bmi160_of_match),
63 }, 73 },
64 .probe = bmi160_i2c_probe, 74 .probe = bmi160_i2c_probe,
65 .remove = bmi160_i2c_remove, 75 .remove = bmi160_i2c_remove,
diff --git a/drivers/iio/imu/bmi160/bmi160_spi.c b/drivers/iio/imu/bmi160/bmi160_spi.c
index 1ec8b12bd984..d34dfdfd1a7d 100644
--- a/drivers/iio/imu/bmi160/bmi160_spi.c
+++ b/drivers/iio/imu/bmi160/bmi160_spi.c
@@ -7,10 +7,11 @@
7 * the GNU General Public License. See the file COPYING in the main 7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details. 8 * directory of this archive for more details.
9 */ 9 */
10#include <linux/acpi.h>
10#include <linux/module.h> 11#include <linux/module.h>
11#include <linux/spi/spi.h> 12#include <linux/of.h>
12#include <linux/regmap.h> 13#include <linux/regmap.h>
13#include <linux/acpi.h> 14#include <linux/spi/spi.h>
14 15
15#include "bmi160.h" 16#include "bmi160.h"
16 17
@@ -47,13 +48,22 @@ static const struct acpi_device_id bmi160_acpi_match[] = {
47}; 48};
48MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match); 49MODULE_DEVICE_TABLE(acpi, bmi160_acpi_match);
49 50
51#ifdef CONFIG_OF
52static const struct of_device_id bmi160_of_match[] = {
53 { .compatible = "bosch,bmi160" },
54 { },
55};
56MODULE_DEVICE_TABLE(of, bmi160_of_match);
57#endif
58
50static struct spi_driver bmi160_spi_driver = { 59static struct spi_driver bmi160_spi_driver = {
51 .probe = bmi160_spi_probe, 60 .probe = bmi160_spi_probe,
52 .remove = bmi160_spi_remove, 61 .remove = bmi160_spi_remove,
53 .id_table = bmi160_spi_id, 62 .id_table = bmi160_spi_id,
54 .driver = { 63 .driver = {
55 .acpi_match_table = ACPI_PTR(bmi160_acpi_match), 64 .acpi_match_table = ACPI_PTR(bmi160_acpi_match),
56 .name = "bmi160_spi", 65 .of_match_table = of_match_ptr(bmi160_of_match),
66 .name = "bmi160_spi",
57 }, 67 },
58}; 68};
59module_spi_driver(bmi160_spi_driver); 69module_spi_driver(bmi160_spi_driver);
diff --git a/drivers/iio/imu/st_lsm6dsx/Kconfig b/drivers/iio/imu/st_lsm6dsx/Kconfig
new file mode 100644
index 000000000000..935d4cd071a3
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/Kconfig
@@ -0,0 +1,22 @@
1
2config IIO_ST_LSM6DSX
3 tristate "ST_LSM6DSx driver for STM 6-axis IMU MEMS sensors"
4 depends on (I2C || SPI)
5 select IIO_BUFFER
6 select IIO_KFIFO_BUF
7 select IIO_ST_LSM6DSX_I2C if (I2C)
8 select IIO_ST_LSM6DSX_SPI if (SPI_MASTER)
9 help
10 Say yes here to build support for STMicroelectronics LSM6DSx imu
11 sensor. Supported devices: lsm6ds3, lsm6dsm
12
13 To compile this driver as a module, choose M here: the module
14 will be called st_lsm6dsx.
15
16config IIO_ST_LSM6DSX_I2C
17 tristate
18 depends on IIO_ST_LSM6DSX
19
20config IIO_ST_LSM6DSX_SPI
21 tristate
22 depends on IIO_ST_LSM6DSX
diff --git a/drivers/iio/imu/st_lsm6dsx/Makefile b/drivers/iio/imu/st_lsm6dsx/Makefile
new file mode 100644
index 000000000000..35919febea2a
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/Makefile
@@ -0,0 +1,5 @@
1st_lsm6dsx-y := st_lsm6dsx_core.o st_lsm6dsx_buffer.o
2
3obj-$(CONFIG_IIO_ST_LSM6DSX) += st_lsm6dsx.o
4obj-$(CONFIG_IIO_ST_LSM6DSX_I2C) += st_lsm6dsx_i2c.o
5obj-$(CONFIG_IIO_ST_LSM6DSX_SPI) += st_lsm6dsx_spi.o
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
new file mode 100644
index 000000000000..69deafe1c10d
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
@@ -0,0 +1,141 @@
1/*
2 * STMicroelectronics st_lsm6dsx sensor driver
3 *
4 * Copyright 2016 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7 * Denis Ciocca <denis.ciocca@st.com>
8 *
9 * Licensed under the GPL-2.
10 */
11
12#ifndef ST_LSM6DSX_H
13#define ST_LSM6DSX_H
14
15#include <linux/device.h>
16
17#define ST_LSM6DS3_DEV_NAME "lsm6ds3"
18#define ST_LSM6DSM_DEV_NAME "lsm6dsm"
19
20enum st_lsm6dsx_hw_id {
21 ST_LSM6DS3_ID,
22 ST_LSM6DSM_ID,
23};
24
25#define ST_LSM6DSX_CHAN_SIZE 2
26#define ST_LSM6DSX_SAMPLE_SIZE 6
27#define ST_LSM6DSX_SAMPLE_DEPTH (ST_LSM6DSX_SAMPLE_SIZE / \
28 ST_LSM6DSX_CHAN_SIZE)
29
30#if defined(CONFIG_SPI_MASTER)
31#define ST_LSM6DSX_RX_MAX_LENGTH 256
32#define ST_LSM6DSX_TX_MAX_LENGTH 8
33
34struct st_lsm6dsx_transfer_buffer {
35 u8 rx_buf[ST_LSM6DSX_RX_MAX_LENGTH];
36 u8 tx_buf[ST_LSM6DSX_TX_MAX_LENGTH] ____cacheline_aligned;
37};
38#endif /* CONFIG_SPI_MASTER */
39
40struct st_lsm6dsx_transfer_function {
41 int (*read)(struct device *dev, u8 addr, int len, u8 *data);
42 int (*write)(struct device *dev, u8 addr, int len, u8 *data);
43};
44
45struct st_lsm6dsx_reg {
46 u8 addr;
47 u8 mask;
48};
49
50struct st_lsm6dsx_settings {
51 u8 wai;
52 u16 max_fifo_size;
53 enum st_lsm6dsx_hw_id id;
54};
55
56enum st_lsm6dsx_sensor_id {
57 ST_LSM6DSX_ID_ACC,
58 ST_LSM6DSX_ID_GYRO,
59 ST_LSM6DSX_ID_MAX,
60};
61
62enum st_lsm6dsx_fifo_mode {
63 ST_LSM6DSX_FIFO_BYPASS = 0x0,
64 ST_LSM6DSX_FIFO_CONT = 0x6,
65};
66
67/**
68 * struct st_lsm6dsx_sensor - ST IMU sensor instance
69 * @id: Sensor identifier.
70 * @hw: Pointer to instance of struct st_lsm6dsx_hw.
71 * @gain: Configured sensor sensitivity.
72 * @odr: Output data rate of the sensor [Hz].
73 * @watermark: Sensor watermark level.
74 * @sip: Number of samples in a given pattern.
75 * @decimator: FIFO decimation factor.
76 * @decimator_mask: Sensor mask for decimation register.
77 * @delta_ts: Delta time between two consecutive interrupts.
78 * @ts: Latest timestamp from the interrupt handler.
79 */
80struct st_lsm6dsx_sensor {
81 enum st_lsm6dsx_sensor_id id;
82 struct st_lsm6dsx_hw *hw;
83
84 u32 gain;
85 u16 odr;
86
87 u16 watermark;
88 u8 sip;
89 u8 decimator;
90 u8 decimator_mask;
91
92 s64 delta_ts;
93 s64 ts;
94};
95
96/**
97 * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
98 * @dev: Pointer to instance of struct device (I2C or SPI).
99 * @irq: Device interrupt line (I2C or SPI).
100 * @lock: Mutex to protect read and write operations.
101 * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
102 * @fifo_mode: FIFO operating mode supported by the device.
103 * @enable_mask: Enabled sensor bitmask.
104 * @sip: Total number of samples (acc/gyro) in a given pattern.
105 * @iio_devs: Pointers to acc/gyro iio_dev instances.
106 * @settings: Pointer to the specific sensor settings in use.
107 * @tf: Transfer function structure used by I/O operations.
108 * @tb: Transfer buffers used by SPI I/O operations.
109 */
110struct st_lsm6dsx_hw {
111 struct device *dev;
112 int irq;
113
114 struct mutex lock;
115 struct mutex fifo_lock;
116
117 enum st_lsm6dsx_fifo_mode fifo_mode;
118 u8 enable_mask;
119 u8 sip;
120
121 struct iio_dev *iio_devs[ST_LSM6DSX_ID_MAX];
122
123 const struct st_lsm6dsx_settings *settings;
124
125 const struct st_lsm6dsx_transfer_function *tf;
126#if defined(CONFIG_SPI_MASTER)
127 struct st_lsm6dsx_transfer_buffer tb;
128#endif /* CONFIG_SPI_MASTER */
129};
130
131int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
132 const struct st_lsm6dsx_transfer_function *tf_ops);
133int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor);
134int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor);
135int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw);
136int st_lsm6dsx_write_with_mask(struct st_lsm6dsx_hw *hw, u8 addr, u8 mask,
137 u8 val);
138int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor,
139 u16 watermark);
140
141#endif /* ST_LSM6DSX_H */
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
new file mode 100644
index 000000000000..78532ce07449
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c
@@ -0,0 +1,454 @@
1/*
2 * STMicroelectronics st_lsm6dsx FIFO buffer library driver
3 *
4 * LSM6DS3/LSM6DSM: The FIFO buffer can be configured to store data
5 * from gyroscope and accelerometer. Samples are queued without any tag
6 * according to a specific pattern based on 'FIFO data sets' (6 bytes each):
7 * - 1st data set is reserved for gyroscope data
8 * - 2nd data set is reserved for accelerometer data
9 * The FIFO pattern changes depending on the ODRs and decimation factors
10 * assigned to the FIFO data sets. The first sequence of data stored in FIFO
11 * buffer contains the data of all the enabled FIFO data sets
12 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated depending on the
13 * value of the decimation factor and ODR set for each FIFO data set.
14 * FIFO supported modes:
15 * - BYPASS: FIFO disabled
16 * - CONTINUOUS: FIFO enabled. When the buffer is full, the FIFO index
17 * restarts from the beginning and the oldest sample is overwritten
18 *
19 * Copyright 2016 STMicroelectronics Inc.
20 *
21 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
22 * Denis Ciocca <denis.ciocca@st.com>
23 *
24 * Licensed under the GPL-2.
25 */
26#include <linux/module.h>
27#include <linux/interrupt.h>
28#include <linux/irq.h>
29#include <linux/iio/kfifo_buf.h>
30#include <linux/iio/iio.h>
31#include <linux/iio/buffer.h>
32
33#include "st_lsm6dsx.h"
34
35#define ST_LSM6DSX_REG_FIFO_THL_ADDR 0x06
36#define ST_LSM6DSX_REG_FIFO_THH_ADDR 0x07
37#define ST_LSM6DSX_FIFO_TH_MASK GENMASK(11, 0)
38#define ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR 0x08
39#define ST_LSM6DSX_REG_FIFO_MODE_ADDR 0x0a
40#define ST_LSM6DSX_FIFO_MODE_MASK GENMASK(2, 0)
41#define ST_LSM6DSX_FIFO_ODR_MASK GENMASK(6, 3)
42#define ST_LSM6DSX_REG_FIFO_DIFFL_ADDR 0x3a
43#define ST_LSM6DSX_FIFO_DIFF_MASK GENMASK(11, 0)
44#define ST_LSM6DSX_FIFO_EMPTY_MASK BIT(12)
45#define ST_LSM6DSX_REG_FIFO_OUTL_ADDR 0x3e
46
47#define ST_LSM6DSX_MAX_FIFO_ODR_VAL 0x08
48
49struct st_lsm6dsx_decimator_entry {
50 u8 decimator;
51 u8 val;
52};
53
54static const
55struct st_lsm6dsx_decimator_entry st_lsm6dsx_decimator_table[] = {
56 { 0, 0x0 },
57 { 1, 0x1 },
58 { 2, 0x2 },
59 { 3, 0x3 },
60 { 4, 0x4 },
61 { 8, 0x5 },
62 { 16, 0x6 },
63 { 32, 0x7 },
64};
65
66static int st_lsm6dsx_get_decimator_val(u8 val)
67{
68 const int max_size = ARRAY_SIZE(st_lsm6dsx_decimator_table);
69 int i;
70
71 for (i = 0; i < max_size; i++)
72 if (st_lsm6dsx_decimator_table[i].decimator == val)
73 break;
74
75 return i == max_size ? 0 : st_lsm6dsx_decimator_table[i].val;
76}
77
78static void st_lsm6dsx_get_max_min_odr(struct st_lsm6dsx_hw *hw,
79 u16 *max_odr, u16 *min_odr)
80{
81 struct st_lsm6dsx_sensor *sensor;
82 int i;
83
84 *max_odr = 0, *min_odr = ~0;
85 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
86 sensor = iio_priv(hw->iio_devs[i]);
87
88 if (!(hw->enable_mask & BIT(sensor->id)))
89 continue;
90
91 *max_odr = max_t(u16, *max_odr, sensor->odr);
92 *min_odr = min_t(u16, *min_odr, sensor->odr);
93 }
94}
95
96static int st_lsm6dsx_update_decimators(struct st_lsm6dsx_hw *hw)
97{
98 struct st_lsm6dsx_sensor *sensor;
99 u16 max_odr, min_odr, sip = 0;
100 int err, i;
101 u8 data;
102
103 st_lsm6dsx_get_max_min_odr(hw, &max_odr, &min_odr);
104
105 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
106 sensor = iio_priv(hw->iio_devs[i]);
107
108 /* update fifo decimators and sample in pattern */
109 if (hw->enable_mask & BIT(sensor->id)) {
110 sensor->sip = sensor->odr / min_odr;
111 sensor->decimator = max_odr / sensor->odr;
112 data = st_lsm6dsx_get_decimator_val(sensor->decimator);
113 } else {
114 sensor->sip = 0;
115 sensor->decimator = 0;
116 data = 0;
117 }
118
119 err = st_lsm6dsx_write_with_mask(hw,
120 ST_LSM6DSX_REG_FIFO_DEC_GXL_ADDR,
121 sensor->decimator_mask, data);
122 if (err < 0)
123 return err;
124
125 sip += sensor->sip;
126 }
127 hw->sip = sip;
128
129 return 0;
130}
131
132static int st_lsm6dsx_set_fifo_mode(struct st_lsm6dsx_hw *hw,
133 enum st_lsm6dsx_fifo_mode fifo_mode)
134{
135 u8 data;
136 int err;
137
138 switch (fifo_mode) {
139 case ST_LSM6DSX_FIFO_BYPASS:
140 data = fifo_mode;
141 break;
142 case ST_LSM6DSX_FIFO_CONT:
143 data = (ST_LSM6DSX_MAX_FIFO_ODR_VAL <<
144 __ffs(ST_LSM6DSX_FIFO_ODR_MASK)) | fifo_mode;
145 break;
146 default:
147 return -EINVAL;
148 }
149
150 err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_MODE_ADDR,
151 sizeof(data), &data);
152 if (err < 0)
153 return err;
154
155 hw->fifo_mode = fifo_mode;
156
157 return 0;
158}
159
160int st_lsm6dsx_update_watermark(struct st_lsm6dsx_sensor *sensor, u16 watermark)
161{
162 u16 fifo_watermark = ~0, cur_watermark, sip = 0;
163 struct st_lsm6dsx_hw *hw = sensor->hw;
164 struct st_lsm6dsx_sensor *cur_sensor;
165 __le16 wdata;
166 int i, err;
167 u8 data;
168
169 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
170 cur_sensor = iio_priv(hw->iio_devs[i]);
171
172 if (!(hw->enable_mask & BIT(cur_sensor->id)))
173 continue;
174
175 cur_watermark = (cur_sensor == sensor) ? watermark
176 : cur_sensor->watermark;
177
178 fifo_watermark = min_t(u16, fifo_watermark, cur_watermark);
179 sip += cur_sensor->sip;
180 }
181
182 if (!sip)
183 return 0;
184
185 fifo_watermark = max_t(u16, fifo_watermark, sip);
186 fifo_watermark = (fifo_watermark / sip) * sip;
187 fifo_watermark = fifo_watermark * ST_LSM6DSX_SAMPLE_DEPTH;
188
189 mutex_lock(&hw->lock);
190
191 err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_THH_ADDR,
192 sizeof(data), &data);
193 if (err < 0)
194 goto out;
195
196 fifo_watermark = ((data & ~ST_LSM6DSX_FIFO_TH_MASK) << 8) |
197 (fifo_watermark & ST_LSM6DSX_FIFO_TH_MASK);
198
199 wdata = cpu_to_le16(fifo_watermark);
200 err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_FIFO_THL_ADDR,
201 sizeof(wdata), (u8 *)&wdata);
202out:
203 mutex_unlock(&hw->lock);
204
205 return err < 0 ? err : 0;
206}
207
208/**
209 * st_lsm6dsx_read_fifo() - LSM6DS3-LSM6DSM read FIFO routine
210 * @hw: Pointer to instance of struct st_lsm6dsx_hw.
211 *
212 * Read samples from the hw FIFO and push them to IIO buffers.
213 *
214 * Return: Number of bytes read from the FIFO
215 */
216static int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw)
217{
218 u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE;
219 int err, acc_sip, gyro_sip, read_len, samples, offset;
220 struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor;
221 s64 acc_ts, acc_delta_ts, gyro_ts, gyro_delta_ts;
222 u8 iio_buff[ALIGN(ST_LSM6DSX_SAMPLE_SIZE, sizeof(s64)) + sizeof(s64)];
223 u8 buff[pattern_len];
224 __le16 fifo_status;
225
226 err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_DIFFL_ADDR,
227 sizeof(fifo_status), (u8 *)&fifo_status);
228 if (err < 0)
229 return err;
230
231 if (fifo_status & cpu_to_le16(ST_LSM6DSX_FIFO_EMPTY_MASK))
232 return 0;
233
234 fifo_len = (le16_to_cpu(fifo_status) & ST_LSM6DSX_FIFO_DIFF_MASK) *
235 ST_LSM6DSX_CHAN_SIZE;
236 samples = fifo_len / ST_LSM6DSX_SAMPLE_SIZE;
237 fifo_len = (fifo_len / pattern_len) * pattern_len;
238
239 /*
240 * compute delta timestamp between two consecutive samples
241 * in order to estimate queueing time of data generated
242 * by the sensor
243 */
244 acc_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_ACC]);
245 acc_ts = acc_sensor->ts - acc_sensor->delta_ts;
246 acc_delta_ts = div_s64(acc_sensor->delta_ts * acc_sensor->decimator,
247 samples);
248
249 gyro_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_GYRO]);
250 gyro_ts = gyro_sensor->ts - gyro_sensor->delta_ts;
251 gyro_delta_ts = div_s64(gyro_sensor->delta_ts * gyro_sensor->decimator,
252 samples);
253
254 for (read_len = 0; read_len < fifo_len; read_len += pattern_len) {
255 err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_FIFO_OUTL_ADDR,
256 sizeof(buff), buff);
257 if (err < 0)
258 return err;
259
260 /*
261 * Data are written to the FIFO with a specific pattern
262 * depending on the configured ODRs. The first sequence of data
263 * stored in FIFO contains the data of all enabled sensors
264 * (e.g. Gx, Gy, Gz, Ax, Ay, Az), then data are repeated
265 * depending on the value of the decimation factor set for each
266 * sensor.
267 *
268 * Supposing the FIFO is storing data from gyroscope and
269 * accelerometer at different ODRs:
270 * - gyroscope ODR = 208Hz, accelerometer ODR = 104Hz
271 * Since the gyroscope ODR is twice the accelerometer one, the
272 * following pattern is repeated every 9 samples:
273 * - Gx, Gy, Gz, Ax, Ay, Az, Gx, Gy, Gz
274 */
275 gyro_sip = gyro_sensor->sip;
276 acc_sip = acc_sensor->sip;
277 offset = 0;
278
279 while (acc_sip > 0 || gyro_sip > 0) {
280 if (gyro_sip-- > 0) {
281 memcpy(iio_buff, &buff[offset],
282 ST_LSM6DSX_SAMPLE_SIZE);
283 iio_push_to_buffers_with_timestamp(
284 hw->iio_devs[ST_LSM6DSX_ID_GYRO],
285 iio_buff, gyro_ts);
286 offset += ST_LSM6DSX_SAMPLE_SIZE;
287 gyro_ts += gyro_delta_ts;
288 }
289
290 if (acc_sip-- > 0) {
291 memcpy(iio_buff, &buff[offset],
292 ST_LSM6DSX_SAMPLE_SIZE);
293 iio_push_to_buffers_with_timestamp(
294 hw->iio_devs[ST_LSM6DSX_ID_ACC],
295 iio_buff, acc_ts);
296 offset += ST_LSM6DSX_SAMPLE_SIZE;
297 acc_ts += acc_delta_ts;
298 }
299 }
300 }
301
302 return read_len;
303}
304
305static int st_lsm6dsx_flush_fifo(struct st_lsm6dsx_hw *hw)
306{
307 int err;
308
309 mutex_lock(&hw->fifo_lock);
310
311 st_lsm6dsx_read_fifo(hw);
312 err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_BYPASS);
313
314 mutex_unlock(&hw->fifo_lock);
315
316 return err;
317}
318
319static int st_lsm6dsx_update_fifo(struct iio_dev *iio_dev, bool enable)
320{
321 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
322 struct st_lsm6dsx_hw *hw = sensor->hw;
323 int err;
324
325 if (hw->fifo_mode != ST_LSM6DSX_FIFO_BYPASS) {
326 err = st_lsm6dsx_flush_fifo(hw);
327 if (err < 0)
328 return err;
329 }
330
331 if (enable) {
332 err = st_lsm6dsx_sensor_enable(sensor);
333 if (err < 0)
334 return err;
335 } else {
336 err = st_lsm6dsx_sensor_disable(sensor);
337 if (err < 0)
338 return err;
339 }
340
341 err = st_lsm6dsx_update_decimators(hw);
342 if (err < 0)
343 return err;
344
345 err = st_lsm6dsx_update_watermark(sensor, sensor->watermark);
346 if (err < 0)
347 return err;
348
349 if (hw->enable_mask) {
350 err = st_lsm6dsx_set_fifo_mode(hw, ST_LSM6DSX_FIFO_CONT);
351 if (err < 0)
352 return err;
353
354 /*
355 * store enable buffer timestamp as reference to compute
356 * first delta timestamp
357 */
358 sensor->ts = iio_get_time_ns(iio_dev);
359 }
360
361 return 0;
362}
363
364static irqreturn_t st_lsm6dsx_handler_irq(int irq, void *private)
365{
366 struct st_lsm6dsx_hw *hw = (struct st_lsm6dsx_hw *)private;
367 struct st_lsm6dsx_sensor *sensor;
368 int i;
369
370 if (!hw->sip)
371 return IRQ_NONE;
372
373 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
374 sensor = iio_priv(hw->iio_devs[i]);
375
376 if (sensor->sip > 0) {
377 s64 timestamp;
378
379 timestamp = iio_get_time_ns(hw->iio_devs[i]);
380 sensor->delta_ts = timestamp - sensor->ts;
381 sensor->ts = timestamp;
382 }
383 }
384
385 return IRQ_WAKE_THREAD;
386}
387
388static irqreturn_t st_lsm6dsx_handler_thread(int irq, void *private)
389{
390 struct st_lsm6dsx_hw *hw = (struct st_lsm6dsx_hw *)private;
391 int count;
392
393 mutex_lock(&hw->fifo_lock);
394 count = st_lsm6dsx_read_fifo(hw);
395 mutex_unlock(&hw->fifo_lock);
396
397 return !count ? IRQ_NONE : IRQ_HANDLED;
398}
399
400static int st_lsm6dsx_buffer_preenable(struct iio_dev *iio_dev)
401{
402 return st_lsm6dsx_update_fifo(iio_dev, true);
403}
404
405static int st_lsm6dsx_buffer_postdisable(struct iio_dev *iio_dev)
406{
407 return st_lsm6dsx_update_fifo(iio_dev, false);
408}
409
410static const struct iio_buffer_setup_ops st_lsm6dsx_buffer_ops = {
411 .preenable = st_lsm6dsx_buffer_preenable,
412 .postdisable = st_lsm6dsx_buffer_postdisable,
413};
414
415int st_lsm6dsx_fifo_setup(struct st_lsm6dsx_hw *hw)
416{
417 struct iio_buffer *buffer;
418 unsigned long irq_type;
419 int i, err;
420
421 irq_type = irqd_get_trigger_type(irq_get_irq_data(hw->irq));
422
423 switch (irq_type) {
424 case IRQF_TRIGGER_HIGH:
425 case IRQF_TRIGGER_RISING:
426 break;
427 default:
428 dev_info(hw->dev, "mode %lx unsupported\n", irq_type);
429 return -EINVAL;
430 }
431
432 err = devm_request_threaded_irq(hw->dev, hw->irq,
433 st_lsm6dsx_handler_irq,
434 st_lsm6dsx_handler_thread,
435 irq_type | IRQF_ONESHOT,
436 "lsm6dsx", hw);
437 if (err) {
438 dev_err(hw->dev, "failed to request trigger irq %d\n",
439 hw->irq);
440 return err;
441 }
442
443 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
444 buffer = devm_iio_kfifo_allocate(hw->dev);
445 if (!buffer)
446 return -ENOMEM;
447
448 iio_device_attach_buffer(hw->iio_devs[i], buffer);
449 hw->iio_devs[i]->modes |= INDIO_BUFFER_SOFTWARE;
450 hw->iio_devs[i]->setup_ops = &st_lsm6dsx_buffer_ops;
451 }
452
453 return 0;
454}
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
new file mode 100644
index 000000000000..c92ddcc190e2
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -0,0 +1,720 @@
1/*
2 * STMicroelectronics st_lsm6dsx sensor driver
3 *
4 * The ST LSM6DSx IMU MEMS series consists of 3D digital accelerometer
5 * and 3D digital gyroscope system-in-package with a digital I2C/SPI serial
6 * interface standard output.
7 * LSM6DSx IMU MEMS series has a dynamic user-selectable full-scale
8 * acceleration range of +-2/+-4/+-8/+-16 g and an angular rate range of
9 * +-125/+-245/+-500/+-1000/+-2000 dps
10 * LSM6DSx series has an integrated First-In-First-Out (FIFO) buffer
11 * allowing dynamic batching of sensor data.
12 *
13 * Supported sensors:
14 * - LSM6DS3:
15 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416
16 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
17 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
18 * - FIFO size: 8KB
19 *
20 * - LSM6DSM:
21 * - Accelerometer/Gyroscope supported ODR [Hz]: 13, 26, 52, 104, 208, 416
22 * - Accelerometer supported full-scale [g]: +-2/+-4/+-8/+-16
23 * - Gyroscope supported full-scale [dps]: +-125/+-245/+-500/+-1000/+-2000
24 * - FIFO size: 4KB
25 *
26 * Copyright 2016 STMicroelectronics Inc.
27 *
28 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
29 * Denis Ciocca <denis.ciocca@st.com>
30 *
31 * Licensed under the GPL-2.
32 */
33
34#include <linux/kernel.h>
35#include <linux/module.h>
36#include <linux/delay.h>
37#include <linux/iio/iio.h>
38#include <linux/iio/sysfs.h>
39
40#include <linux/platform_data/st_sensors_pdata.h>
41
42#include "st_lsm6dsx.h"
43
44#define ST_LSM6DSX_REG_ACC_DEC_MASK GENMASK(2, 0)
45#define ST_LSM6DSX_REG_GYRO_DEC_MASK GENMASK(5, 3)
46#define ST_LSM6DSX_REG_INT1_ADDR 0x0d
47#define ST_LSM6DSX_REG_INT2_ADDR 0x0e
48#define ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK BIT(3)
49#define ST_LSM6DSX_REG_WHOAMI_ADDR 0x0f
50#define ST_LSM6DSX_REG_RESET_ADDR 0x12
51#define ST_LSM6DSX_REG_RESET_MASK BIT(0)
52#define ST_LSM6DSX_REG_BDU_ADDR 0x12
53#define ST_LSM6DSX_REG_BDU_MASK BIT(6)
54#define ST_LSM6DSX_REG_INT2_ON_INT1_ADDR 0x13
55#define ST_LSM6DSX_REG_INT2_ON_INT1_MASK BIT(5)
56#define ST_LSM6DSX_REG_ROUNDING_ADDR 0x16
57#define ST_LSM6DSX_REG_ROUNDING_MASK BIT(2)
58#define ST_LSM6DSX_REG_LIR_ADDR 0x58
59#define ST_LSM6DSX_REG_LIR_MASK BIT(0)
60
61#define ST_LSM6DSX_REG_ACC_ODR_ADDR 0x10
62#define ST_LSM6DSX_REG_ACC_ODR_MASK GENMASK(7, 4)
63#define ST_LSM6DSX_REG_ACC_FS_ADDR 0x10
64#define ST_LSM6DSX_REG_ACC_FS_MASK GENMASK(3, 2)
65#define ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR 0x28
66#define ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR 0x2a
67#define ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR 0x2c
68
69#define ST_LSM6DSX_REG_GYRO_ODR_ADDR 0x11
70#define ST_LSM6DSX_REG_GYRO_ODR_MASK GENMASK(7, 4)
71#define ST_LSM6DSX_REG_GYRO_FS_ADDR 0x11
72#define ST_LSM6DSX_REG_GYRO_FS_MASK GENMASK(3, 2)
73#define ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR 0x22
74#define ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR 0x24
75#define ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR 0x26
76
77#define ST_LSM6DS3_WHOAMI 0x69
78#define ST_LSM6DSM_WHOAMI 0x6a
79
80#define ST_LSM6DS3_MAX_FIFO_SIZE 8192
81#define ST_LSM6DSM_MAX_FIFO_SIZE 4096
82
83#define ST_LSM6DSX_ACC_FS_2G_GAIN IIO_G_TO_M_S_2(61)
84#define ST_LSM6DSX_ACC_FS_4G_GAIN IIO_G_TO_M_S_2(122)
85#define ST_LSM6DSX_ACC_FS_8G_GAIN IIO_G_TO_M_S_2(244)
86#define ST_LSM6DSX_ACC_FS_16G_GAIN IIO_G_TO_M_S_2(488)
87
88#define ST_LSM6DSX_GYRO_FS_245_GAIN IIO_DEGREE_TO_RAD(8750)
89#define ST_LSM6DSX_GYRO_FS_500_GAIN IIO_DEGREE_TO_RAD(17500)
90#define ST_LSM6DSX_GYRO_FS_1000_GAIN IIO_DEGREE_TO_RAD(35000)
91#define ST_LSM6DSX_GYRO_FS_2000_GAIN IIO_DEGREE_TO_RAD(70000)
92
93struct st_lsm6dsx_odr {
94 u16 hz;
95 u8 val;
96};
97
98#define ST_LSM6DSX_ODR_LIST_SIZE 6
99struct st_lsm6dsx_odr_table_entry {
100 struct st_lsm6dsx_reg reg;
101 struct st_lsm6dsx_odr odr_avl[ST_LSM6DSX_ODR_LIST_SIZE];
102};
103
104static const struct st_lsm6dsx_odr_table_entry st_lsm6dsx_odr_table[] = {
105 [ST_LSM6DSX_ID_ACC] = {
106 .reg = {
107 .addr = ST_LSM6DSX_REG_ACC_ODR_ADDR,
108 .mask = ST_LSM6DSX_REG_ACC_ODR_MASK,
109 },
110 .odr_avl[0] = { 13, 0x01 },
111 .odr_avl[1] = { 26, 0x02 },
112 .odr_avl[2] = { 52, 0x03 },
113 .odr_avl[3] = { 104, 0x04 },
114 .odr_avl[4] = { 208, 0x05 },
115 .odr_avl[5] = { 416, 0x06 },
116 },
117 [ST_LSM6DSX_ID_GYRO] = {
118 .reg = {
119 .addr = ST_LSM6DSX_REG_GYRO_ODR_ADDR,
120 .mask = ST_LSM6DSX_REG_GYRO_ODR_MASK,
121 },
122 .odr_avl[0] = { 13, 0x01 },
123 .odr_avl[1] = { 26, 0x02 },
124 .odr_avl[2] = { 52, 0x03 },
125 .odr_avl[3] = { 104, 0x04 },
126 .odr_avl[4] = { 208, 0x05 },
127 .odr_avl[5] = { 416, 0x06 },
128 }
129};
130
131struct st_lsm6dsx_fs {
132 u32 gain;
133 u8 val;
134};
135
136#define ST_LSM6DSX_FS_LIST_SIZE 4
137struct st_lsm6dsx_fs_table_entry {
138 struct st_lsm6dsx_reg reg;
139 struct st_lsm6dsx_fs fs_avl[ST_LSM6DSX_FS_LIST_SIZE];
140};
141
142static const struct st_lsm6dsx_fs_table_entry st_lsm6dsx_fs_table[] = {
143 [ST_LSM6DSX_ID_ACC] = {
144 .reg = {
145 .addr = ST_LSM6DSX_REG_ACC_FS_ADDR,
146 .mask = ST_LSM6DSX_REG_ACC_FS_MASK,
147 },
148 .fs_avl[0] = { ST_LSM6DSX_ACC_FS_2G_GAIN, 0x0 },
149 .fs_avl[1] = { ST_LSM6DSX_ACC_FS_4G_GAIN, 0x2 },
150 .fs_avl[2] = { ST_LSM6DSX_ACC_FS_8G_GAIN, 0x3 },
151 .fs_avl[3] = { ST_LSM6DSX_ACC_FS_16G_GAIN, 0x1 },
152 },
153 [ST_LSM6DSX_ID_GYRO] = {
154 .reg = {
155 .addr = ST_LSM6DSX_REG_GYRO_FS_ADDR,
156 .mask = ST_LSM6DSX_REG_GYRO_FS_MASK,
157 },
158 .fs_avl[0] = { ST_LSM6DSX_GYRO_FS_245_GAIN, 0x0 },
159 .fs_avl[1] = { ST_LSM6DSX_GYRO_FS_500_GAIN, 0x1 },
160 .fs_avl[2] = { ST_LSM6DSX_GYRO_FS_1000_GAIN, 0x2 },
161 .fs_avl[3] = { ST_LSM6DSX_GYRO_FS_2000_GAIN, 0x3 },
162 }
163};
164
165static const struct st_lsm6dsx_settings st_lsm6dsx_sensor_settings[] = {
166 {
167 .wai = ST_LSM6DS3_WHOAMI,
168 .max_fifo_size = ST_LSM6DS3_MAX_FIFO_SIZE,
169 .id = ST_LSM6DS3_ID,
170 },
171 {
172 .wai = ST_LSM6DSM_WHOAMI,
173 .max_fifo_size = ST_LSM6DSM_MAX_FIFO_SIZE,
174 .id = ST_LSM6DSM_ID,
175 },
176};
177
178#define ST_LSM6DSX_CHANNEL(chan_type, addr, mod, scan_idx) \
179{ \
180 .type = chan_type, \
181 .address = addr, \
182 .modified = 1, \
183 .channel2 = mod, \
184 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
185 BIT(IIO_CHAN_INFO_SCALE), \
186 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \
187 .scan_index = scan_idx, \
188 .scan_type = { \
189 .sign = 's', \
190 .realbits = 16, \
191 .storagebits = 16, \
192 .endianness = IIO_LE, \
193 }, \
194}
195
196static const struct iio_chan_spec st_lsm6dsx_acc_channels[] = {
197 ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_X_L_ADDR,
198 IIO_MOD_X, 0),
199 ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Y_L_ADDR,
200 IIO_MOD_Y, 1),
201 ST_LSM6DSX_CHANNEL(IIO_ACCEL, ST_LSM6DSX_REG_ACC_OUT_Z_L_ADDR,
202 IIO_MOD_Z, 2),
203 IIO_CHAN_SOFT_TIMESTAMP(3),
204};
205
206static const struct iio_chan_spec st_lsm6dsx_gyro_channels[] = {
207 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_X_L_ADDR,
208 IIO_MOD_X, 0),
209 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Y_L_ADDR,
210 IIO_MOD_Y, 1),
211 ST_LSM6DSX_CHANNEL(IIO_ANGL_VEL, ST_LSM6DSX_REG_GYRO_OUT_Z_L_ADDR,
212 IIO_MOD_Z, 2),
213 IIO_CHAN_SOFT_TIMESTAMP(3),
214};
215
216int st_lsm6dsx_write_with_mask(struct st_lsm6dsx_hw *hw, u8 addr, u8 mask,
217 u8 val)
218{
219 u8 data;
220 int err;
221
222 mutex_lock(&hw->lock);
223
224 err = hw->tf->read(hw->dev, addr, sizeof(data), &data);
225 if (err < 0) {
226 dev_err(hw->dev, "failed to read %02x register\n", addr);
227 goto out;
228 }
229
230 data = (data & ~mask) | ((val << __ffs(mask)) & mask);
231
232 err = hw->tf->write(hw->dev, addr, sizeof(data), &data);
233 if (err < 0)
234 dev_err(hw->dev, "failed to write %02x register\n", addr);
235
236out:
237 mutex_unlock(&hw->lock);
238
239 return err;
240}
241
242static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id)
243{
244 int err, i;
245 u8 data;
246
247 for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) {
248 if (id == st_lsm6dsx_sensor_settings[i].id)
249 break;
250 }
251
252 if (i == ARRAY_SIZE(st_lsm6dsx_sensor_settings)) {
253 dev_err(hw->dev, "unsupported hw id [%02x]\n", id);
254 return -ENODEV;
255 }
256
257 err = hw->tf->read(hw->dev, ST_LSM6DSX_REG_WHOAMI_ADDR, sizeof(data),
258 &data);
259 if (err < 0) {
260 dev_err(hw->dev, "failed to read whoami register\n");
261 return err;
262 }
263
264 if (data != st_lsm6dsx_sensor_settings[i].wai) {
265 dev_err(hw->dev, "unsupported whoami [%02x]\n", data);
266 return -ENODEV;
267 }
268
269 hw->settings = &st_lsm6dsx_sensor_settings[i];
270
271 return 0;
272}
273
274static int st_lsm6dsx_set_full_scale(struct st_lsm6dsx_sensor *sensor,
275 u32 gain)
276{
277 enum st_lsm6dsx_sensor_id id = sensor->id;
278 int i, err;
279 u8 val;
280
281 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
282 if (st_lsm6dsx_fs_table[id].fs_avl[i].gain == gain)
283 break;
284
285 if (i == ST_LSM6DSX_FS_LIST_SIZE)
286 return -EINVAL;
287
288 val = st_lsm6dsx_fs_table[id].fs_avl[i].val;
289 err = st_lsm6dsx_write_with_mask(sensor->hw,
290 st_lsm6dsx_fs_table[id].reg.addr,
291 st_lsm6dsx_fs_table[id].reg.mask,
292 val);
293 if (err < 0)
294 return err;
295
296 sensor->gain = gain;
297
298 return 0;
299}
300
301static int st_lsm6dsx_set_odr(struct st_lsm6dsx_sensor *sensor, u16 odr)
302{
303 enum st_lsm6dsx_sensor_id id = sensor->id;
304 int i, err;
305 u8 val;
306
307 for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
308 if (st_lsm6dsx_odr_table[id].odr_avl[i].hz == odr)
309 break;
310
311 if (i == ST_LSM6DSX_ODR_LIST_SIZE)
312 return -EINVAL;
313
314 val = st_lsm6dsx_odr_table[id].odr_avl[i].val;
315 err = st_lsm6dsx_write_with_mask(sensor->hw,
316 st_lsm6dsx_odr_table[id].reg.addr,
317 st_lsm6dsx_odr_table[id].reg.mask,
318 val);
319 if (err < 0)
320 return err;
321
322 sensor->odr = odr;
323
324 return 0;
325}
326
327int st_lsm6dsx_sensor_enable(struct st_lsm6dsx_sensor *sensor)
328{
329 int err;
330
331 err = st_lsm6dsx_set_odr(sensor, sensor->odr);
332 if (err < 0)
333 return err;
334
335 sensor->hw->enable_mask |= BIT(sensor->id);
336
337 return 0;
338}
339
340int st_lsm6dsx_sensor_disable(struct st_lsm6dsx_sensor *sensor)
341{
342 enum st_lsm6dsx_sensor_id id = sensor->id;
343 int err;
344
345 err = st_lsm6dsx_write_with_mask(sensor->hw,
346 st_lsm6dsx_odr_table[id].reg.addr,
347 st_lsm6dsx_odr_table[id].reg.mask, 0);
348 if (err < 0)
349 return err;
350
351 sensor->hw->enable_mask &= ~BIT(id);
352
353 return 0;
354}
355
356static int st_lsm6dsx_read_oneshot(struct st_lsm6dsx_sensor *sensor,
357 u8 addr, int *val)
358{
359 int err, delay;
360 __le16 data;
361
362 err = st_lsm6dsx_sensor_enable(sensor);
363 if (err < 0)
364 return err;
365
366 delay = 1000000 / sensor->odr;
367 usleep_range(delay, 2 * delay);
368
369 err = sensor->hw->tf->read(sensor->hw->dev, addr, sizeof(data),
370 (u8 *)&data);
371 if (err < 0)
372 return err;
373
374 st_lsm6dsx_sensor_disable(sensor);
375
376 *val = (s16)data;
377
378 return IIO_VAL_INT;
379}
380
381static int st_lsm6dsx_read_raw(struct iio_dev *iio_dev,
382 struct iio_chan_spec const *ch,
383 int *val, int *val2, long mask)
384{
385 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
386 int ret;
387
388 switch (mask) {
389 case IIO_CHAN_INFO_RAW:
390 ret = iio_device_claim_direct_mode(iio_dev);
391 if (ret)
392 break;
393
394 ret = st_lsm6dsx_read_oneshot(sensor, ch->address, val);
395 iio_device_release_direct_mode(iio_dev);
396 break;
397 case IIO_CHAN_INFO_SAMP_FREQ:
398 *val = sensor->odr;
399 ret = IIO_VAL_INT;
400 break;
401 case IIO_CHAN_INFO_SCALE:
402 *val = 0;
403 *val2 = sensor->gain;
404 ret = IIO_VAL_INT_PLUS_MICRO;
405 break;
406 default:
407 ret = -EINVAL;
408 break;
409 }
410
411 return ret;
412}
413
414static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
415 struct iio_chan_spec const *chan,
416 int val, int val2, long mask)
417{
418 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
419 int err;
420
421 err = iio_device_claim_direct_mode(iio_dev);
422 if (err)
423 return err;
424
425 switch (mask) {
426 case IIO_CHAN_INFO_SCALE:
427 err = st_lsm6dsx_set_full_scale(sensor, val2);
428 break;
429 case IIO_CHAN_INFO_SAMP_FREQ:
430 err = st_lsm6dsx_set_odr(sensor, val);
431 break;
432 default:
433 err = -EINVAL;
434 break;
435 }
436
437 iio_device_release_direct_mode(iio_dev);
438
439 return err;
440}
441
442static int st_lsm6dsx_set_watermark(struct iio_dev *iio_dev, unsigned int val)
443{
444 struct st_lsm6dsx_sensor *sensor = iio_priv(iio_dev);
445 struct st_lsm6dsx_hw *hw = sensor->hw;
446 int err, max_fifo_len;
447
448 max_fifo_len = hw->settings->max_fifo_size / ST_LSM6DSX_SAMPLE_SIZE;
449 if (val < 1 || val > max_fifo_len)
450 return -EINVAL;
451
452 err = st_lsm6dsx_update_watermark(sensor, val);
453 if (err < 0)
454 return err;
455
456 sensor->watermark = val;
457
458 return 0;
459}
460
461static ssize_t
462st_lsm6dsx_sysfs_sampling_frequency_avail(struct device *dev,
463 struct device_attribute *attr,
464 char *buf)
465{
466 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
467 enum st_lsm6dsx_sensor_id id = sensor->id;
468 int i, len = 0;
469
470 for (i = 0; i < ST_LSM6DSX_ODR_LIST_SIZE; i++)
471 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
472 st_lsm6dsx_odr_table[id].odr_avl[i].hz);
473 buf[len - 1] = '\n';
474
475 return len;
476}
477
478static ssize_t st_lsm6dsx_sysfs_scale_avail(struct device *dev,
479 struct device_attribute *attr,
480 char *buf)
481{
482 struct st_lsm6dsx_sensor *sensor = iio_priv(dev_get_drvdata(dev));
483 enum st_lsm6dsx_sensor_id id = sensor->id;
484 int i, len = 0;
485
486 for (i = 0; i < ST_LSM6DSX_FS_LIST_SIZE; i++)
487 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
488 st_lsm6dsx_fs_table[id].fs_avl[i].gain);
489 buf[len - 1] = '\n';
490
491 return len;
492}
493
494static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(st_lsm6dsx_sysfs_sampling_frequency_avail);
495static IIO_DEVICE_ATTR(in_accel_scale_available, 0444,
496 st_lsm6dsx_sysfs_scale_avail, NULL, 0);
497static IIO_DEVICE_ATTR(in_anglvel_scale_available, 0444,
498 st_lsm6dsx_sysfs_scale_avail, NULL, 0);
499
500static struct attribute *st_lsm6dsx_acc_attributes[] = {
501 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
502 &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
503 NULL,
504};
505
506static const struct attribute_group st_lsm6dsx_acc_attribute_group = {
507 .attrs = st_lsm6dsx_acc_attributes,
508};
509
510static const struct iio_info st_lsm6dsx_acc_info = {
511 .driver_module = THIS_MODULE,
512 .attrs = &st_lsm6dsx_acc_attribute_group,
513 .read_raw = st_lsm6dsx_read_raw,
514 .write_raw = st_lsm6dsx_write_raw,
515 .hwfifo_set_watermark = st_lsm6dsx_set_watermark,
516};
517
518static struct attribute *st_lsm6dsx_gyro_attributes[] = {
519 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
520 &iio_dev_attr_in_anglvel_scale_available.dev_attr.attr,
521 NULL,
522};
523
524static const struct attribute_group st_lsm6dsx_gyro_attribute_group = {
525 .attrs = st_lsm6dsx_gyro_attributes,
526};
527
528static const struct iio_info st_lsm6dsx_gyro_info = {
529 .driver_module = THIS_MODULE,
530 .attrs = &st_lsm6dsx_gyro_attribute_group,
531 .read_raw = st_lsm6dsx_read_raw,
532 .write_raw = st_lsm6dsx_write_raw,
533 .hwfifo_set_watermark = st_lsm6dsx_set_watermark,
534};
535
536static const unsigned long st_lsm6dsx_available_scan_masks[] = {0x7, 0x0};
537
538static int st_lsm6dsx_of_get_drdy_pin(struct st_lsm6dsx_hw *hw, int *drdy_pin)
539{
540 struct device_node *np = hw->dev->of_node;
541 int err;
542
543 if (!np)
544 return -EINVAL;
545
546 err = of_property_read_u32(np, "st,drdy-int-pin", drdy_pin);
547 if (err == -ENODATA) {
548 /* if the property has not been specified use default value */
549 *drdy_pin = 1;
550 err = 0;
551 }
552
553 return err;
554}
555
556static int st_lsm6dsx_get_drdy_reg(struct st_lsm6dsx_hw *hw, u8 *drdy_reg)
557{
558 int err = 0, drdy_pin;
559
560 if (st_lsm6dsx_of_get_drdy_pin(hw, &drdy_pin) < 0) {
561 struct st_sensors_platform_data *pdata;
562 struct device *dev = hw->dev;
563
564 pdata = (struct st_sensors_platform_data *)dev->platform_data;
565 drdy_pin = pdata ? pdata->drdy_int_pin : 1;
566 }
567
568 switch (drdy_pin) {
569 case 1:
570 *drdy_reg = ST_LSM6DSX_REG_INT1_ADDR;
571 break;
572 case 2:
573 *drdy_reg = ST_LSM6DSX_REG_INT2_ADDR;
574 break;
575 default:
576 dev_err(hw->dev, "unsupported data ready pin\n");
577 err = -EINVAL;
578 break;
579 }
580
581 return err;
582}
583
584static int st_lsm6dsx_init_device(struct st_lsm6dsx_hw *hw)
585{
586 u8 data, drdy_int_reg;
587 int err;
588
589 data = ST_LSM6DSX_REG_RESET_MASK;
590 err = hw->tf->write(hw->dev, ST_LSM6DSX_REG_RESET_ADDR, sizeof(data),
591 &data);
592 if (err < 0)
593 return err;
594
595 msleep(200);
596
597 /* latch interrupts */
598 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_LIR_ADDR,
599 ST_LSM6DSX_REG_LIR_MASK, 1);
600 if (err < 0)
601 return err;
602
603 /* enable Block Data Update */
604 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_BDU_ADDR,
605 ST_LSM6DSX_REG_BDU_MASK, 1);
606 if (err < 0)
607 return err;
608
609 err = st_lsm6dsx_write_with_mask(hw, ST_LSM6DSX_REG_ROUNDING_ADDR,
610 ST_LSM6DSX_REG_ROUNDING_MASK, 1);
611 if (err < 0)
612 return err;
613
614 /* enable FIFO watermak interrupt */
615 err = st_lsm6dsx_get_drdy_reg(hw, &drdy_int_reg);
616 if (err < 0)
617 return err;
618
619 return st_lsm6dsx_write_with_mask(hw, drdy_int_reg,
620 ST_LSM6DSX_REG_FIFO_FTH_IRQ_MASK, 1);
621}
622
623static struct iio_dev *st_lsm6dsx_alloc_iiodev(struct st_lsm6dsx_hw *hw,
624 enum st_lsm6dsx_sensor_id id)
625{
626 struct st_lsm6dsx_sensor *sensor;
627 struct iio_dev *iio_dev;
628
629 iio_dev = devm_iio_device_alloc(hw->dev, sizeof(*sensor));
630 if (!iio_dev)
631 return NULL;
632
633 iio_dev->modes = INDIO_DIRECT_MODE;
634 iio_dev->dev.parent = hw->dev;
635 iio_dev->available_scan_masks = st_lsm6dsx_available_scan_masks;
636
637 sensor = iio_priv(iio_dev);
638 sensor->id = id;
639 sensor->hw = hw;
640 sensor->odr = st_lsm6dsx_odr_table[id].odr_avl[0].hz;
641 sensor->gain = st_lsm6dsx_fs_table[id].fs_avl[0].gain;
642 sensor->watermark = 1;
643
644 switch (id) {
645 case ST_LSM6DSX_ID_ACC:
646 iio_dev->channels = st_lsm6dsx_acc_channels;
647 iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_acc_channels);
648 iio_dev->name = "lsm6dsx_accel";
649 iio_dev->info = &st_lsm6dsx_acc_info;
650
651 sensor->decimator_mask = ST_LSM6DSX_REG_ACC_DEC_MASK;
652 break;
653 case ST_LSM6DSX_ID_GYRO:
654 iio_dev->channels = st_lsm6dsx_gyro_channels;
655 iio_dev->num_channels = ARRAY_SIZE(st_lsm6dsx_gyro_channels);
656 iio_dev->name = "lsm6dsx_gyro";
657 iio_dev->info = &st_lsm6dsx_gyro_info;
658
659 sensor->decimator_mask = ST_LSM6DSX_REG_GYRO_DEC_MASK;
660 break;
661 default:
662 return NULL;
663 }
664
665 return iio_dev;
666}
667
668int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
669 const struct st_lsm6dsx_transfer_function *tf_ops)
670{
671 struct st_lsm6dsx_hw *hw;
672 int i, err;
673
674 hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
675 if (!hw)
676 return -ENOMEM;
677
678 dev_set_drvdata(dev, (void *)hw);
679
680 mutex_init(&hw->lock);
681 mutex_init(&hw->fifo_lock);
682
683 hw->dev = dev;
684 hw->irq = irq;
685 hw->tf = tf_ops;
686
687 err = st_lsm6dsx_check_whoami(hw, hw_id);
688 if (err < 0)
689 return err;
690
691 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
692 hw->iio_devs[i] = st_lsm6dsx_alloc_iiodev(hw, i);
693 if (!hw->iio_devs[i])
694 return -ENOMEM;
695 }
696
697 err = st_lsm6dsx_init_device(hw);
698 if (err < 0)
699 return err;
700
701 if (hw->irq > 0) {
702 err = st_lsm6dsx_fifo_setup(hw);
703 if (err < 0)
704 return err;
705 }
706
707 for (i = 0; i < ST_LSM6DSX_ID_MAX; i++) {
708 err = devm_iio_device_register(hw->dev, hw->iio_devs[i]);
709 if (err)
710 return err;
711 }
712
713 return 0;
714}
715EXPORT_SYMBOL(st_lsm6dsx_probe);
716
717MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
718MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
719MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx driver");
720MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
new file mode 100644
index 000000000000..ea3041186e1e
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_i2c.c
@@ -0,0 +1,101 @@
1/*
2 * STMicroelectronics st_lsm6dsx i2c driver
3 *
4 * Copyright 2016 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7 * Denis Ciocca <denis.ciocca@st.com>
8 *
9 * Licensed under the GPL-2.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/i2c.h>
15#include <linux/slab.h>
16#include <linux/of.h>
17
18#include "st_lsm6dsx.h"
19
20static int st_lsm6dsx_i2c_read(struct device *dev, u8 addr, int len, u8 *data)
21{
22 struct i2c_client *client = to_i2c_client(dev);
23 struct i2c_msg msg[2];
24
25 msg[0].addr = client->addr;
26 msg[0].flags = client->flags;
27 msg[0].len = 1;
28 msg[0].buf = &addr;
29
30 msg[1].addr = client->addr;
31 msg[1].flags = client->flags | I2C_M_RD;
32 msg[1].len = len;
33 msg[1].buf = data;
34
35 return i2c_transfer(client->adapter, msg, 2);
36}
37
38static int st_lsm6dsx_i2c_write(struct device *dev, u8 addr, int len, u8 *data)
39{
40 struct i2c_client *client = to_i2c_client(dev);
41 struct i2c_msg msg;
42 u8 send[len + 1];
43
44 send[0] = addr;
45 memcpy(&send[1], data, len * sizeof(u8));
46
47 msg.addr = client->addr;
48 msg.flags = client->flags;
49 msg.len = len + 1;
50 msg.buf = send;
51
52 return i2c_transfer(client->adapter, &msg, 1);
53}
54
55static const struct st_lsm6dsx_transfer_function st_lsm6dsx_transfer_fn = {
56 .read = st_lsm6dsx_i2c_read,
57 .write = st_lsm6dsx_i2c_write,
58};
59
60static int st_lsm6dsx_i2c_probe(struct i2c_client *client,
61 const struct i2c_device_id *id)
62{
63 return st_lsm6dsx_probe(&client->dev, client->irq,
64 (int)id->driver_data,
65 &st_lsm6dsx_transfer_fn);
66}
67
68static const struct of_device_id st_lsm6dsx_i2c_of_match[] = {
69 {
70 .compatible = "st,lsm6ds3",
71 .data = (void *)ST_LSM6DS3_ID,
72 },
73 {
74 .compatible = "st,lsm6dsm",
75 .data = (void *)ST_LSM6DSM_ID,
76 },
77 {},
78};
79MODULE_DEVICE_TABLE(of, st_lsm6dsx_i2c_of_match);
80
81static const struct i2c_device_id st_lsm6dsx_i2c_id_table[] = {
82 { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
83 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
84 {},
85};
86MODULE_DEVICE_TABLE(i2c, st_lsm6dsx_i2c_id_table);
87
88static struct i2c_driver st_lsm6dsx_driver = {
89 .driver = {
90 .name = "st_lsm6dsx_i2c",
91 .of_match_table = of_match_ptr(st_lsm6dsx_i2c_of_match),
92 },
93 .probe = st_lsm6dsx_i2c_probe,
94 .id_table = st_lsm6dsx_i2c_id_table,
95};
96module_i2c_driver(st_lsm6dsx_driver);
97
98MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
99MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
100MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx i2c driver");
101MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
new file mode 100644
index 000000000000..fbe72470ed1e
--- /dev/null
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_spi.c
@@ -0,0 +1,118 @@
1/*
2 * STMicroelectronics st_lsm6dsx spi driver
3 *
4 * Copyright 2016 STMicroelectronics Inc.
5 *
6 * Lorenzo Bianconi <lorenzo.bianconi@st.com>
7 * Denis Ciocca <denis.ciocca@st.com>
8 *
9 * Licensed under the GPL-2.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/spi/spi.h>
15#include <linux/slab.h>
16#include <linux/of.h>
17
18#include "st_lsm6dsx.h"
19
20#define SENSORS_SPI_READ BIT(7)
21
22static int st_lsm6dsx_spi_read(struct device *dev, u8 addr, int len,
23 u8 *data)
24{
25 struct spi_device *spi = to_spi_device(dev);
26 struct st_lsm6dsx_hw *hw = spi_get_drvdata(spi);
27 int err;
28
29 struct spi_transfer xfers[] = {
30 {
31 .tx_buf = hw->tb.tx_buf,
32 .bits_per_word = 8,
33 .len = 1,
34 },
35 {
36 .rx_buf = hw->tb.rx_buf,
37 .bits_per_word = 8,
38 .len = len,
39 }
40 };
41
42 hw->tb.tx_buf[0] = addr | SENSORS_SPI_READ;
43
44 err = spi_sync_transfer(spi, xfers, ARRAY_SIZE(xfers));
45 if (err < 0)
46 return err;
47
48 memcpy(data, hw->tb.rx_buf, len * sizeof(u8));
49
50 return len;
51}
52
53static int st_lsm6dsx_spi_write(struct device *dev, u8 addr, int len,
54 u8 *data)
55{
56 struct st_lsm6dsx_hw *hw;
57 struct spi_device *spi;
58
59 if (len >= ST_LSM6DSX_TX_MAX_LENGTH)
60 return -ENOMEM;
61
62 spi = to_spi_device(dev);
63 hw = spi_get_drvdata(spi);
64
65 hw->tb.tx_buf[0] = addr;
66 memcpy(&hw->tb.tx_buf[1], data, len);
67
68 return spi_write(spi, hw->tb.tx_buf, len + 1);
69}
70
71static const struct st_lsm6dsx_transfer_function st_lsm6dsx_transfer_fn = {
72 .read = st_lsm6dsx_spi_read,
73 .write = st_lsm6dsx_spi_write,
74};
75
76static int st_lsm6dsx_spi_probe(struct spi_device *spi)
77{
78 const struct spi_device_id *id = spi_get_device_id(spi);
79
80 return st_lsm6dsx_probe(&spi->dev, spi->irq,
81 (int)id->driver_data,
82 &st_lsm6dsx_transfer_fn);
83}
84
85static const struct of_device_id st_lsm6dsx_spi_of_match[] = {
86 {
87 .compatible = "st,lsm6ds3",
88 .data = (void *)ST_LSM6DS3_ID,
89 },
90 {
91 .compatible = "st,lsm6dsm",
92 .data = (void *)ST_LSM6DSM_ID,
93 },
94 {},
95};
96MODULE_DEVICE_TABLE(of, st_lsm6dsx_spi_of_match);
97
98static const struct spi_device_id st_lsm6dsx_spi_id_table[] = {
99 { ST_LSM6DS3_DEV_NAME, ST_LSM6DS3_ID },
100 { ST_LSM6DSM_DEV_NAME, ST_LSM6DSM_ID },
101 {},
102};
103MODULE_DEVICE_TABLE(spi, st_lsm6dsx_spi_id_table);
104
105static struct spi_driver st_lsm6dsx_driver = {
106 .driver = {
107 .name = "st_lsm6dsx_spi",
108 .of_match_table = of_match_ptr(st_lsm6dsx_spi_of_match),
109 },
110 .probe = st_lsm6dsx_spi_probe,
111 .id_table = st_lsm6dsx_spi_id_table,
112};
113module_spi_driver(st_lsm6dsx_driver);
114
115MODULE_AUTHOR("Lorenzo Bianconi <lorenzo.bianconi@st.com>");
116MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
117MODULE_DESCRIPTION("STMicroelectronics st_lsm6dsx spi driver");
118MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index b12830b09c7d..4972986f6455 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -26,6 +26,7 @@
26#include "iio_core.h" 26#include "iio_core.h"
27#include <linux/iio/sysfs.h> 27#include <linux/iio/sysfs.h>
28#include <linux/iio/buffer.h> 28#include <linux/iio/buffer.h>
29#include <linux/iio/buffer_impl.h>
29 30
30static const char * const iio_endian_prefix[] = { 31static const char * const iio_endian_prefix[] = {
31 [IIO_BE] = "be", 32 [IIO_BE] = "be",
@@ -209,6 +210,18 @@ void iio_buffer_init(struct iio_buffer *buffer)
209} 210}
210EXPORT_SYMBOL(iio_buffer_init); 211EXPORT_SYMBOL(iio_buffer_init);
211 212
213/**
214 * iio_buffer_set_attrs - Set buffer specific attributes
215 * @buffer: The buffer for which we are setting attributes
216 * @attrs: Pointer to a null terminated list of pointers to attributes
217 */
218void iio_buffer_set_attrs(struct iio_buffer *buffer,
219 const struct attribute **attrs)
220{
221 buffer->attrs = attrs;
222}
223EXPORT_SYMBOL_GPL(iio_buffer_set_attrs);
224
212static ssize_t iio_show_scan_index(struct device *dev, 225static ssize_t iio_show_scan_index(struct device *dev,
213 struct device_attribute *attr, 226 struct device_attribute *attr,
214 char *buf) 227 char *buf)
@@ -346,6 +359,19 @@ static int iio_scan_mask_clear(struct iio_buffer *buffer, int bit)
346 return 0; 359 return 0;
347} 360}
348 361
362static int iio_scan_mask_query(struct iio_dev *indio_dev,
363 struct iio_buffer *buffer, int bit)
364{
365 if (bit > indio_dev->masklength)
366 return -EINVAL;
367
368 if (!buffer->scan_mask)
369 return 0;
370
371 /* Ensure return value is 0 or 1. */
372 return !!test_bit(bit, buffer->scan_mask);
373};
374
349static ssize_t iio_scan_el_store(struct device *dev, 375static ssize_t iio_scan_el_store(struct device *dev,
350 struct device_attribute *attr, 376 struct device_attribute *attr,
351 const char *buf, 377 const char *buf,
@@ -751,6 +777,135 @@ static int iio_verify_update(struct iio_dev *indio_dev,
751 return 0; 777 return 0;
752} 778}
753 779
780/**
781 * struct iio_demux_table - table describing demux memcpy ops
782 * @from: index to copy from
783 * @to: index to copy to
784 * @length: how many bytes to copy
785 * @l: list head used for management
786 */
787struct iio_demux_table {
788 unsigned from;
789 unsigned to;
790 unsigned length;
791 struct list_head l;
792};
793
794static void iio_buffer_demux_free(struct iio_buffer *buffer)
795{
796 struct iio_demux_table *p, *q;
797 list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
798 list_del(&p->l);
799 kfree(p);
800 }
801}
802
803static int iio_buffer_add_demux(struct iio_buffer *buffer,
804 struct iio_demux_table **p, unsigned int in_loc, unsigned int out_loc,
805 unsigned int length)
806{
807
808 if (*p && (*p)->from + (*p)->length == in_loc &&
809 (*p)->to + (*p)->length == out_loc) {
810 (*p)->length += length;
811 } else {
812 *p = kmalloc(sizeof(**p), GFP_KERNEL);
813 if (*p == NULL)
814 return -ENOMEM;
815 (*p)->from = in_loc;
816 (*p)->to = out_loc;
817 (*p)->length = length;
818 list_add_tail(&(*p)->l, &buffer->demux_list);
819 }
820
821 return 0;
822}
823
824static int iio_buffer_update_demux(struct iio_dev *indio_dev,
825 struct iio_buffer *buffer)
826{
827 int ret, in_ind = -1, out_ind, length;
828 unsigned in_loc = 0, out_loc = 0;
829 struct iio_demux_table *p = NULL;
830
831 /* Clear out any old demux */
832 iio_buffer_demux_free(buffer);
833 kfree(buffer->demux_bounce);
834 buffer->demux_bounce = NULL;
835
836 /* First work out which scan mode we will actually have */
837 if (bitmap_equal(indio_dev->active_scan_mask,
838 buffer->scan_mask,
839 indio_dev->masklength))
840 return 0;
841
842 /* Now we have the two masks, work from least sig and build up sizes */
843 for_each_set_bit(out_ind,
844 buffer->scan_mask,
845 indio_dev->masklength) {
846 in_ind = find_next_bit(indio_dev->active_scan_mask,
847 indio_dev->masklength,
848 in_ind + 1);
849 while (in_ind != out_ind) {
850 in_ind = find_next_bit(indio_dev->active_scan_mask,
851 indio_dev->masklength,
852 in_ind + 1);
853 length = iio_storage_bytes_for_si(indio_dev, in_ind);
854 /* Make sure we are aligned */
855 in_loc = roundup(in_loc, length) + length;
856 }
857 length = iio_storage_bytes_for_si(indio_dev, in_ind);
858 out_loc = roundup(out_loc, length);
859 in_loc = roundup(in_loc, length);
860 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
861 if (ret)
862 goto error_clear_mux_table;
863 out_loc += length;
864 in_loc += length;
865 }
866 /* Relies on scan_timestamp being last */
867 if (buffer->scan_timestamp) {
868 length = iio_storage_bytes_for_timestamp(indio_dev);
869 out_loc = roundup(out_loc, length);
870 in_loc = roundup(in_loc, length);
871 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
872 if (ret)
873 goto error_clear_mux_table;
874 out_loc += length;
875 in_loc += length;
876 }
877 buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL);
878 if (buffer->demux_bounce == NULL) {
879 ret = -ENOMEM;
880 goto error_clear_mux_table;
881 }
882 return 0;
883
884error_clear_mux_table:
885 iio_buffer_demux_free(buffer);
886
887 return ret;
888}
889
890static int iio_update_demux(struct iio_dev *indio_dev)
891{
892 struct iio_buffer *buffer;
893 int ret;
894
895 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
896 ret = iio_buffer_update_demux(indio_dev, buffer);
897 if (ret < 0)
898 goto error_clear_mux_table;
899 }
900 return 0;
901
902error_clear_mux_table:
903 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
904 iio_buffer_demux_free(buffer);
905
906 return ret;
907}
908
754static int iio_enable_buffers(struct iio_dev *indio_dev, 909static int iio_enable_buffers(struct iio_dev *indio_dev,
755 struct iio_device_config *config) 910 struct iio_device_config *config)
756{ 911{
@@ -1199,34 +1354,6 @@ bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
1199} 1354}
1200EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot); 1355EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot);
1201 1356
1202int iio_scan_mask_query(struct iio_dev *indio_dev,
1203 struct iio_buffer *buffer, int bit)
1204{
1205 if (bit > indio_dev->masklength)
1206 return -EINVAL;
1207
1208 if (!buffer->scan_mask)
1209 return 0;
1210
1211 /* Ensure return value is 0 or 1. */
1212 return !!test_bit(bit, buffer->scan_mask);
1213};
1214EXPORT_SYMBOL_GPL(iio_scan_mask_query);
1215
1216/**
1217 * struct iio_demux_table - table describing demux memcpy ops
1218 * @from: index to copy from
1219 * @to: index to copy to
1220 * @length: how many bytes to copy
1221 * @l: list head used for management
1222 */
1223struct iio_demux_table {
1224 unsigned from;
1225 unsigned to;
1226 unsigned length;
1227 struct list_head l;
1228};
1229
1230static const void *iio_demux(struct iio_buffer *buffer, 1357static const void *iio_demux(struct iio_buffer *buffer,
1231 const void *datain) 1358 const void *datain)
1232{ 1359{
@@ -1258,16 +1385,11 @@ static int iio_push_to_buffer(struct iio_buffer *buffer, const void *data)
1258 return 0; 1385 return 0;
1259} 1386}
1260 1387
1261static void iio_buffer_demux_free(struct iio_buffer *buffer) 1388/**
1262{ 1389 * iio_push_to_buffers() - push to a registered buffer.
1263 struct iio_demux_table *p, *q; 1390 * @indio_dev: iio_dev structure for device.
1264 list_for_each_entry_safe(p, q, &buffer->demux_list, l) { 1391 * @data: Full scan.
1265 list_del(&p->l); 1392 */
1266 kfree(p);
1267 }
1268}
1269
1270
1271int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data) 1393int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data)
1272{ 1394{
1273 int ret; 1395 int ret;
@@ -1283,113 +1405,6 @@ int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data)
1283} 1405}
1284EXPORT_SYMBOL_GPL(iio_push_to_buffers); 1406EXPORT_SYMBOL_GPL(iio_push_to_buffers);
1285 1407
1286static int iio_buffer_add_demux(struct iio_buffer *buffer,
1287 struct iio_demux_table **p, unsigned int in_loc, unsigned int out_loc,
1288 unsigned int length)
1289{
1290
1291 if (*p && (*p)->from + (*p)->length == in_loc &&
1292 (*p)->to + (*p)->length == out_loc) {
1293 (*p)->length += length;
1294 } else {
1295 *p = kmalloc(sizeof(**p), GFP_KERNEL);
1296 if (*p == NULL)
1297 return -ENOMEM;
1298 (*p)->from = in_loc;
1299 (*p)->to = out_loc;
1300 (*p)->length = length;
1301 list_add_tail(&(*p)->l, &buffer->demux_list);
1302 }
1303
1304 return 0;
1305}
1306
1307static int iio_buffer_update_demux(struct iio_dev *indio_dev,
1308 struct iio_buffer *buffer)
1309{
1310 int ret, in_ind = -1, out_ind, length;
1311 unsigned in_loc = 0, out_loc = 0;
1312 struct iio_demux_table *p = NULL;
1313
1314 /* Clear out any old demux */
1315 iio_buffer_demux_free(buffer);
1316 kfree(buffer->demux_bounce);
1317 buffer->demux_bounce = NULL;
1318
1319 /* First work out which scan mode we will actually have */
1320 if (bitmap_equal(indio_dev->active_scan_mask,
1321 buffer->scan_mask,
1322 indio_dev->masklength))
1323 return 0;
1324
1325 /* Now we have the two masks, work from least sig and build up sizes */
1326 for_each_set_bit(out_ind,
1327 buffer->scan_mask,
1328 indio_dev->masklength) {
1329 in_ind = find_next_bit(indio_dev->active_scan_mask,
1330 indio_dev->masklength,
1331 in_ind + 1);
1332 while (in_ind != out_ind) {
1333 in_ind = find_next_bit(indio_dev->active_scan_mask,
1334 indio_dev->masklength,
1335 in_ind + 1);
1336 length = iio_storage_bytes_for_si(indio_dev, in_ind);
1337 /* Make sure we are aligned */
1338 in_loc = roundup(in_loc, length) + length;
1339 }
1340 length = iio_storage_bytes_for_si(indio_dev, in_ind);
1341 out_loc = roundup(out_loc, length);
1342 in_loc = roundup(in_loc, length);
1343 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
1344 if (ret)
1345 goto error_clear_mux_table;
1346 out_loc += length;
1347 in_loc += length;
1348 }
1349 /* Relies on scan_timestamp being last */
1350 if (buffer->scan_timestamp) {
1351 length = iio_storage_bytes_for_timestamp(indio_dev);
1352 out_loc = roundup(out_loc, length);
1353 in_loc = roundup(in_loc, length);
1354 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length);
1355 if (ret)
1356 goto error_clear_mux_table;
1357 out_loc += length;
1358 in_loc += length;
1359 }
1360 buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL);
1361 if (buffer->demux_bounce == NULL) {
1362 ret = -ENOMEM;
1363 goto error_clear_mux_table;
1364 }
1365 return 0;
1366
1367error_clear_mux_table:
1368 iio_buffer_demux_free(buffer);
1369
1370 return ret;
1371}
1372
1373int iio_update_demux(struct iio_dev *indio_dev)
1374{
1375 struct iio_buffer *buffer;
1376 int ret;
1377
1378 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) {
1379 ret = iio_buffer_update_demux(indio_dev, buffer);
1380 if (ret < 0)
1381 goto error_clear_mux_table;
1382 }
1383 return 0;
1384
1385error_clear_mux_table:
1386 list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list)
1387 iio_buffer_demux_free(buffer);
1388
1389 return ret;
1390}
1391EXPORT_SYMBOL_GPL(iio_update_demux);
1392
1393/** 1408/**
1394 * iio_buffer_release() - Free a buffer's resources 1409 * iio_buffer_release() - Free a buffer's resources
1395 * @ref: Pointer to the kref embedded in the iio_buffer struct 1410 * @ref: Pointer to the kref embedded in the iio_buffer struct
@@ -1431,3 +1446,19 @@ void iio_buffer_put(struct iio_buffer *buffer)
1431 kref_put(&buffer->ref, iio_buffer_release); 1446 kref_put(&buffer->ref, iio_buffer_release);
1432} 1447}
1433EXPORT_SYMBOL_GPL(iio_buffer_put); 1448EXPORT_SYMBOL_GPL(iio_buffer_put);
1449
1450/**
1451 * iio_device_attach_buffer - Attach a buffer to a IIO device
1452 * @indio_dev: The device the buffer should be attached to
1453 * @buffer: The buffer to attach to the device
1454 *
1455 * This function attaches a buffer to a IIO device. The buffer stays attached to
1456 * the device until the device is freed. The function should only be called at
1457 * most once per device.
1458 */
1459void iio_device_attach_buffer(struct iio_dev *indio_dev,
1460 struct iio_buffer *buffer)
1461{
1462 indio_dev->buffer = iio_buffer_get(buffer);
1463}
1464EXPORT_SYMBOL_GPL(iio_device_attach_buffer);
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index aaca42862389..d18ded45bedd 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -32,6 +32,7 @@
32#include <linux/iio/sysfs.h> 32#include <linux/iio/sysfs.h>
33#include <linux/iio/events.h> 33#include <linux/iio/events.h>
34#include <linux/iio/buffer.h> 34#include <linux/iio/buffer.h>
35#include <linux/iio/buffer_impl.h>
35 36
36/* IDA to assign each registered device a unique id */ 37/* IDA to assign each registered device a unique id */
37static DEFINE_IDA(iio_ida); 38static DEFINE_IDA(iio_ida);
@@ -83,6 +84,7 @@ static const char * const iio_chan_type_name_spec[] = {
83 [IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity", 84 [IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
84 [IIO_COUNT] = "count", 85 [IIO_COUNT] = "count",
85 [IIO_INDEX] = "index", 86 [IIO_INDEX] = "index",
87 [IIO_GRAVITY] = "gravity",
86}; 88};
87 89
88static const char * const iio_modifier_names[] = { 90static const char * const iio_modifier_names[] = {
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 978729f6d7c4..978e1592c2a3 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -147,8 +147,7 @@ static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
147 return NULL; 147 return NULL;
148} 148}
149 149
150static struct iio_trigger *iio_trigger_find_by_name(const char *name, 150static struct iio_trigger *iio_trigger_acquire_by_name(const char *name)
151 size_t len)
152{ 151{
153 struct iio_trigger *trig = NULL, *iter; 152 struct iio_trigger *trig = NULL, *iter;
154 153
@@ -156,6 +155,7 @@ static struct iio_trigger *iio_trigger_find_by_name(const char *name,
156 list_for_each_entry(iter, &iio_trigger_list, list) 155 list_for_each_entry(iter, &iio_trigger_list, list)
157 if (sysfs_streq(iter->name, name)) { 156 if (sysfs_streq(iter->name, name)) {
158 trig = iter; 157 trig = iter;
158 iio_trigger_get(trig);
159 break; 159 break;
160 } 160 }
161 mutex_unlock(&iio_trigger_list_lock); 161 mutex_unlock(&iio_trigger_list_lock);
@@ -416,20 +416,22 @@ static ssize_t iio_trigger_write_current(struct device *dev,
416 } 416 }
417 mutex_unlock(&indio_dev->mlock); 417 mutex_unlock(&indio_dev->mlock);
418 418
419 trig = iio_trigger_find_by_name(buf, len); 419 trig = iio_trigger_acquire_by_name(buf);
420 if (oldtrig == trig) 420 if (oldtrig == trig) {
421 return len; 421 ret = len;
422 goto out_trigger_put;
423 }
422 424
423 if (trig && indio_dev->info->validate_trigger) { 425 if (trig && indio_dev->info->validate_trigger) {
424 ret = indio_dev->info->validate_trigger(indio_dev, trig); 426 ret = indio_dev->info->validate_trigger(indio_dev, trig);
425 if (ret) 427 if (ret)
426 return ret; 428 goto out_trigger_put;
427 } 429 }
428 430
429 if (trig && trig->ops->validate_device) { 431 if (trig && trig->ops->validate_device) {
430 ret = trig->ops->validate_device(trig, indio_dev); 432 ret = trig->ops->validate_device(trig, indio_dev);
431 if (ret) 433 if (ret)
432 return ret; 434 goto out_trigger_put;
433 } 435 }
434 436
435 indio_dev->trig = trig; 437 indio_dev->trig = trig;
@@ -441,13 +443,16 @@ static ssize_t iio_trigger_write_current(struct device *dev,
441 iio_trigger_put(oldtrig); 443 iio_trigger_put(oldtrig);
442 } 444 }
443 if (indio_dev->trig) { 445 if (indio_dev->trig) {
444 iio_trigger_get(indio_dev->trig);
445 if (indio_dev->modes & INDIO_EVENT_TRIGGERED) 446 if (indio_dev->modes & INDIO_EVENT_TRIGGERED)
446 iio_trigger_attach_poll_func(indio_dev->trig, 447 iio_trigger_attach_poll_func(indio_dev->trig,
447 indio_dev->pollfunc_event); 448 indio_dev->pollfunc_event);
448 } 449 }
449 450
450 return len; 451 return len;
452
453out_trigger_put:
454 iio_trigger_put(trig);
455 return ret;
451} 456}
452 457
453static DEVICE_ATTR(current_trigger, S_IRUGO | S_IWUSR, 458static DEVICE_ATTR(current_trigger, S_IRUGO | S_IWUSR,
@@ -487,7 +492,7 @@ static void iio_trig_release(struct device *device)
487 kfree(trig); 492 kfree(trig);
488} 493}
489 494
490static struct device_type iio_trig_type = { 495static const struct device_type iio_trig_type = {
491 .release = iio_trig_release, 496 .release = iio_trig_release,
492 .groups = iio_trig_dev_groups, 497 .groups = iio_trig_dev_groups,
493}; 498};
@@ -513,46 +518,45 @@ static void iio_trig_subirqunmask(struct irq_data *d)
513static struct iio_trigger *viio_trigger_alloc(const char *fmt, va_list vargs) 518static struct iio_trigger *viio_trigger_alloc(const char *fmt, va_list vargs)
514{ 519{
515 struct iio_trigger *trig; 520 struct iio_trigger *trig;
521 int i;
522
516 trig = kzalloc(sizeof *trig, GFP_KERNEL); 523 trig = kzalloc(sizeof *trig, GFP_KERNEL);
517 if (trig) { 524 if (!trig)
518 int i; 525 return NULL;
519 trig->dev.type = &iio_trig_type;
520 trig->dev.bus = &iio_bus_type;
521 device_initialize(&trig->dev);
522
523 mutex_init(&trig->pool_lock);
524 trig->subirq_base
525 = irq_alloc_descs(-1, 0,
526 CONFIG_IIO_CONSUMERS_PER_TRIGGER,
527 0);
528 if (trig->subirq_base < 0) {
529 kfree(trig);
530 return NULL;
531 }
532 526
533 trig->name = kvasprintf(GFP_KERNEL, fmt, vargs); 527 trig->dev.type = &iio_trig_type;
534 if (trig->name == NULL) { 528 trig->dev.bus = &iio_bus_type;
535 irq_free_descs(trig->subirq_base, 529 device_initialize(&trig->dev);
536 CONFIG_IIO_CONSUMERS_PER_TRIGGER); 530
537 kfree(trig); 531 mutex_init(&trig->pool_lock);
538 return NULL; 532 trig->subirq_base = irq_alloc_descs(-1, 0,
539 } 533 CONFIG_IIO_CONSUMERS_PER_TRIGGER,
540 trig->subirq_chip.name = trig->name; 534 0);
541 trig->subirq_chip.irq_mask = &iio_trig_subirqmask; 535 if (trig->subirq_base < 0)
542 trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask; 536 goto free_trig;
543 for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) { 537
544 irq_set_chip(trig->subirq_base + i, 538 trig->name = kvasprintf(GFP_KERNEL, fmt, vargs);
545 &trig->subirq_chip); 539 if (trig->name == NULL)
546 irq_set_handler(trig->subirq_base + i, 540 goto free_descs;
547 &handle_simple_irq); 541
548 irq_modify_status(trig->subirq_base + i, 542 trig->subirq_chip.name = trig->name;
549 IRQ_NOREQUEST | IRQ_NOAUTOEN, 543 trig->subirq_chip.irq_mask = &iio_trig_subirqmask;
550 IRQ_NOPROBE); 544 trig->subirq_chip.irq_unmask = &iio_trig_subirqunmask;
551 } 545 for (i = 0; i < CONFIG_IIO_CONSUMERS_PER_TRIGGER; i++) {
552 get_device(&trig->dev); 546 irq_set_chip(trig->subirq_base + i, &trig->subirq_chip);
547 irq_set_handler(trig->subirq_base + i, &handle_simple_irq);
548 irq_modify_status(trig->subirq_base + i,
549 IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE);
553 } 550 }
551 get_device(&trig->dev);
554 552
555 return trig; 553 return trig;
554
555free_descs:
556 irq_free_descs(trig->subirq_base, CONFIG_IIO_CONSUMERS_PER_TRIGGER);
557free_trig:
558 kfree(trig);
559 return NULL;
556} 560}
557 561
558struct iio_trigger *iio_trigger_alloc(const char *fmt, ...) 562struct iio_trigger *iio_trigger_alloc(const char *fmt, ...)
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index b0f4630a163f..7a13535dc3e9 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -601,8 +601,14 @@ static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
601 601
602 scale_type = iio_channel_read(chan, &scale_val, &scale_val2, 602 scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
603 IIO_CHAN_INFO_SCALE); 603 IIO_CHAN_INFO_SCALE);
604 if (scale_type < 0) 604 if (scale_type < 0) {
605 return scale_type; 605 /*
606 * Just pass raw values as processed if no scaling is
607 * available.
608 */
609 *processed = raw;
610 return 0;
611 }
606 612
607 switch (scale_type) { 613 switch (scale_type) {
608 case IIO_VAL_INT: 614 case IIO_VAL_INT:
diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig
index 298ea5081a96..5f731ead9d46 100644
--- a/drivers/iio/light/Kconfig
+++ b/drivers/iio/light/Kconfig
@@ -115,6 +115,16 @@ config CM3323
115 To compile this driver as a module, choose M here: the module will 115 To compile this driver as a module, choose M here: the module will
116 be called cm3323. 116 be called cm3323.
117 117
118config CM3605
119 tristate "Capella CM3605 ambient light and proximity sensor"
120 depends on OF
121 help
122 Say Y here if you want to build a driver for Capella CM3605
123 ambient light and short range proximity sensor.
124
125 To compile this driver as a module, choose M here: the module will
126 be called cm3605.
127
118config CM36651 128config CM36651
119 depends on I2C 129 depends on I2C
120 tristate "CM36651 driver" 130 tristate "CM36651 driver"
diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile
index 4de520036e6e..c13a2399e6df 100644
--- a/drivers/iio/light/Makefile
+++ b/drivers/iio/light/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_BH1780) += bh1780.o
13obj-$(CONFIG_CM32181) += cm32181.o 13obj-$(CONFIG_CM32181) += cm32181.o
14obj-$(CONFIG_CM3232) += cm3232.o 14obj-$(CONFIG_CM3232) += cm3232.o
15obj-$(CONFIG_CM3323) += cm3323.o 15obj-$(CONFIG_CM3323) += cm3323.o
16obj-$(CONFIG_CM3605) += cm3605.o
16obj-$(CONFIG_CM36651) += cm36651.o 17obj-$(CONFIG_CM36651) += cm36651.o
17obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o 18obj-$(CONFIG_GP2AP020A00F) += gp2ap020a00f.o
18obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o 19obj-$(CONFIG_HID_SENSOR_ALS) += hid-sensor-als.o
diff --git a/drivers/iio/light/cm3232.c b/drivers/iio/light/cm3232.c
index fe89b6823217..263e97235ea0 100644
--- a/drivers/iio/light/cm3232.c
+++ b/drivers/iio/light/cm3232.c
@@ -119,7 +119,7 @@ static int cm3232_reg_init(struct cm3232_chip *chip)
119 if (ret < 0) 119 if (ret < 0)
120 dev_err(&chip->client->dev, "Error writing reg_cmd\n"); 120 dev_err(&chip->client->dev, "Error writing reg_cmd\n");
121 121
122 return 0; 122 return ret;
123} 123}
124 124
125/** 125/**
diff --git a/drivers/iio/light/cm3605.c b/drivers/iio/light/cm3605.c
new file mode 100644
index 000000000000..980624e9ffb5
--- /dev/null
+++ b/drivers/iio/light/cm3605.c
@@ -0,0 +1,330 @@
1/*
2 * CM3605 Ambient Light and Proximity Sensor
3 *
4 * Copyright (C) 2016 Linaro Ltd.
5 * Author: Linus Walleij <linus.walleij@linaro.org>
6 *
7 * This hardware was found in the very first Nexus One handset from Google/HTC
8 * and an early endavour into mobile light and proximity sensors.
9 */
10
11#include <linux/module.h>
12#include <linux/iio/iio.h>
13#include <linux/iio/sysfs.h>
14#include <linux/iio/events.h>
15#include <linux/iio/consumer.h> /* To get our ADC channel */
16#include <linux/iio/types.h> /* To deal with our ADC channel */
17#include <linux/init.h>
18#include <linux/leds.h>
19#include <linux/platform_device.h>
20#include <linux/of.h>
21#include <linux/regulator/consumer.h>
22#include <linux/gpio/consumer.h>
23#include <linux/interrupt.h>
24#include <linux/math64.h>
25#include <linux/pm.h>
26
27#define CM3605_PROX_CHANNEL 0
28#define CM3605_ALS_CHANNEL 1
29#define CM3605_AOUT_TYP_MAX_MV 1550
30/* It should not go above 1.650V according to the data sheet */
31#define CM3605_AOUT_MAX_MV 1650
32
33/**
34 * struct cm3605 - CM3605 state
35 * @dev: pointer to parent device
36 * @vdd: regulator controlling VDD
37 * @aset: sleep enable GPIO, high = sleep
38 * @aout: IIO ADC channel to convert the AOUT signal
39 * @als_max: maximum LUX detection (depends on RSET)
40 * @dir: proximity direction: start as FALLING
41 * @led: trigger for the infrared LED used by the proximity sensor
42 */
43struct cm3605 {
44 struct device *dev;
45 struct regulator *vdd;
46 struct gpio_desc *aset;
47 struct iio_channel *aout;
48 s32 als_max;
49 enum iio_event_direction dir;
50 struct led_trigger *led;
51};
52
53static irqreturn_t cm3605_prox_irq(int irq, void *d)
54{
55 struct iio_dev *indio_dev = d;
56 struct cm3605 *cm3605 = iio_priv(indio_dev);
57 u64 ev;
58
59 ev = IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, CM3605_PROX_CHANNEL,
60 IIO_EV_TYPE_THRESH, cm3605->dir);
61 iio_push_event(indio_dev, ev, iio_get_time_ns(indio_dev));
62
63 /* Invert the edge for each event */
64 if (cm3605->dir == IIO_EV_DIR_RISING)
65 cm3605->dir = IIO_EV_DIR_FALLING;
66 else
67 cm3605->dir = IIO_EV_DIR_RISING;
68
69 return IRQ_HANDLED;
70}
71
72static int cm3605_get_lux(struct cm3605 *cm3605)
73{
74 int ret, res;
75 s64 lux;
76
77 ret = iio_read_channel_processed(cm3605->aout, &res);
78 if (ret < 0)
79 return ret;
80
81 dev_dbg(cm3605->dev, "read %d mV from ADC\n", res);
82
83 /*
84 * AOUT has an offset of ~30mV then linear at dark
85 * then goes from 2.54 up to 650 LUX yielding 1.55V
86 * (1550 mV) so scale the returned value to this interval
87 * using simple linear interpolation.
88 */
89 if (res < 30)
90 return 0;
91 if (res > CM3605_AOUT_MAX_MV)
92 dev_err(cm3605->dev, "device out of range\n");
93
94 /* Remove bias */
95 lux = res - 30;
96
97 /* Linear interpolation between 0 and ALS typ max */
98 lux *= cm3605->als_max;
99 lux = div64_s64(lux, CM3605_AOUT_TYP_MAX_MV);
100
101 return lux;
102}
103
104static int cm3605_read_raw(struct iio_dev *indio_dev,
105 struct iio_chan_spec const *chan,
106 int *val, int *val2, long mask)
107{
108 struct cm3605 *cm3605 = iio_priv(indio_dev);
109 int ret;
110
111 switch (mask) {
112 case IIO_CHAN_INFO_RAW:
113 switch (chan->type) {
114 case IIO_LIGHT:
115 ret = cm3605_get_lux(cm3605);
116 if (ret < 0)
117 return ret;
118 *val = ret;
119 return IIO_VAL_INT;
120 default:
121 return -EINVAL;
122 }
123 default:
124 return -EINVAL;
125 }
126}
127
128static const struct iio_info cm3605_info = {
129 .driver_module = THIS_MODULE,
130 .read_raw = cm3605_read_raw,
131};
132
133static const struct iio_event_spec cm3605_events[] = {
134 {
135 .type = IIO_EV_TYPE_THRESH,
136 .dir = IIO_EV_DIR_EITHER,
137 .mask_separate = BIT(IIO_EV_INFO_ENABLE),
138 },
139};
140
141static const struct iio_chan_spec cm3605_channels[] = {
142 {
143 .type = IIO_PROXIMITY,
144 .event_spec = cm3605_events,
145 .num_event_specs = ARRAY_SIZE(cm3605_events),
146 },
147 {
148 .type = IIO_LIGHT,
149 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
150 .channel = CM3605_ALS_CHANNEL,
151 },
152};
153
154static int cm3605_probe(struct platform_device *pdev)
155{
156 struct cm3605 *cm3605;
157 struct iio_dev *indio_dev;
158 struct device *dev = &pdev->dev;
159 struct device_node *np = dev->of_node;
160 enum iio_chan_type ch_type;
161 u32 rset;
162 int ret;
163
164 indio_dev = devm_iio_device_alloc(dev, sizeof(*cm3605));
165 if (!indio_dev)
166 return -ENOMEM;
167 platform_set_drvdata(pdev, indio_dev);
168
169 cm3605 = iio_priv(indio_dev);
170 cm3605->dev = dev;
171 cm3605->dir = IIO_EV_DIR_FALLING;
172
173 ret = of_property_read_u32(np, "capella,aset-resistance-ohms", &rset);
174 if (ret) {
175 dev_info(dev, "no RSET specified, assuming 100K\n");
176 rset = 100000;
177 }
178 switch (rset) {
179 case 50000:
180 cm3605->als_max = 650;
181 break;
182 case 100000:
183 cm3605->als_max = 300;
184 break;
185 case 300000:
186 cm3605->als_max = 100;
187 break;
188 case 600000:
189 cm3605->als_max = 50;
190 break;
191 default:
192 dev_info(dev, "non-standard resistance\n");
193 return -EINVAL;
194 }
195
196 cm3605->aout = devm_iio_channel_get(dev, "aout");
197 if (IS_ERR(cm3605->aout)) {
198 if (PTR_ERR(cm3605->aout) == -ENODEV) {
199 dev_err(dev, "no ADC, deferring...\n");
200 return -EPROBE_DEFER;
201 }
202 dev_err(dev, "failed to get AOUT ADC channel\n");
203 return PTR_ERR(cm3605->aout);
204 }
205 ret = iio_get_channel_type(cm3605->aout, &ch_type);
206 if (ret < 0)
207 return ret;
208 if (ch_type != IIO_VOLTAGE) {
209 dev_err(dev, "wrong type of IIO channel specified for AOUT\n");
210 return -EINVAL;
211 }
212
213 cm3605->vdd = devm_regulator_get(dev, "vdd");
214 if (IS_ERR(cm3605->vdd)) {
215 dev_err(dev, "failed to get VDD regulator\n");
216 return PTR_ERR(cm3605->vdd);
217 }
218 ret = regulator_enable(cm3605->vdd);
219 if (ret) {
220 dev_err(dev, "failed to enable VDD regulator\n");
221 return ret;
222 }
223
224 cm3605->aset = devm_gpiod_get(dev, "aset", GPIOD_OUT_HIGH);
225 if (IS_ERR(cm3605->aset)) {
226 dev_err(dev, "no ASET GPIO\n");
227 ret = PTR_ERR(cm3605->aset);
228 goto out_disable_vdd;
229 }
230
231 ret = devm_request_threaded_irq(dev, platform_get_irq(pdev, 0),
232 cm3605_prox_irq, NULL, 0, "cm3605", indio_dev);
233 if (ret) {
234 dev_err(dev, "unable to request IRQ\n");
235 goto out_disable_aset;
236 }
237
238 /* Just name the trigger the same as the driver */
239 led_trigger_register_simple("cm3605", &cm3605->led);
240 led_trigger_event(cm3605->led, LED_FULL);
241
242 indio_dev->dev.parent = dev;
243 indio_dev->info = &cm3605_info;
244 indio_dev->name = "cm3605";
245 indio_dev->channels = cm3605_channels;
246 indio_dev->num_channels = ARRAY_SIZE(cm3605_channels);
247 indio_dev->modes = INDIO_DIRECT_MODE;
248
249 ret = iio_device_register(indio_dev);
250 if (ret)
251 goto out_remove_trigger;
252 dev_info(dev, "Capella Microsystems CM3605 enabled range 0..%d LUX\n",
253 cm3605->als_max);
254
255 return 0;
256
257out_remove_trigger:
258 led_trigger_event(cm3605->led, LED_OFF);
259 led_trigger_unregister_simple(cm3605->led);
260out_disable_aset:
261 gpiod_set_value_cansleep(cm3605->aset, 0);
262out_disable_vdd:
263 regulator_disable(cm3605->vdd);
264 return ret;
265}
266
267static int cm3605_remove(struct platform_device *pdev)
268{
269 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
270 struct cm3605 *cm3605 = iio_priv(indio_dev);
271
272 led_trigger_event(cm3605->led, LED_OFF);
273 led_trigger_unregister_simple(cm3605->led);
274 gpiod_set_value_cansleep(cm3605->aset, 0);
275 iio_device_unregister(indio_dev);
276 regulator_disable(cm3605->vdd);
277
278 return 0;
279}
280
281static int __maybe_unused cm3605_pm_suspend(struct device *dev)
282{
283 struct iio_dev *indio_dev = dev_get_drvdata(dev);
284 struct cm3605 *cm3605 = iio_priv(indio_dev);
285
286 led_trigger_event(cm3605->led, LED_OFF);
287 regulator_disable(cm3605->vdd);
288
289 return 0;
290}
291
292static int __maybe_unused cm3605_pm_resume(struct device *dev)
293{
294 struct iio_dev *indio_dev = dev_get_drvdata(dev);
295 struct cm3605 *cm3605 = iio_priv(indio_dev);
296 int ret;
297
298 ret = regulator_enable(cm3605->vdd);
299 if (ret)
300 dev_err(dev, "failed to enable regulator in resume path\n");
301 led_trigger_event(cm3605->led, LED_FULL);
302
303 return 0;
304}
305
306static const struct dev_pm_ops cm3605_dev_pm_ops = {
307 SET_SYSTEM_SLEEP_PM_OPS(cm3605_pm_suspend,
308 cm3605_pm_resume)
309};
310
311static const struct of_device_id cm3605_of_match[] = {
312 {.compatible = "capella,cm3605"},
313 { },
314};
315MODULE_DEVICE_TABLE(of, cm3605_of_match);
316
317static struct platform_driver cm3605_driver = {
318 .driver = {
319 .name = "cm3605",
320 .of_match_table = cm3605_of_match,
321 .pm = &cm3605_dev_pm_ops,
322 },
323 .probe = cm3605_probe,
324 .remove = cm3605_remove,
325};
326module_platform_driver(cm3605_driver);
327
328MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
329MODULE_DESCRIPTION("CM3605 ambient light and proximity sensor driver");
330MODULE_LICENSE("GPL");
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 8bb1f90ecd51..059d964772c7 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -31,13 +31,17 @@
31#include <linux/iio/triggered_buffer.h> 31#include <linux/iio/triggered_buffer.h>
32#include "../common/hid-sensors/hid-sensor-trigger.h" 32#include "../common/hid-sensors/hid-sensor-trigger.h"
33 33
34#define CHANNEL_SCAN_INDEX_ILLUM 0 34enum {
35 CHANNEL_SCAN_INDEX_INTENSITY = 0,
36 CHANNEL_SCAN_INDEX_ILLUM = 1,
37 CHANNEL_SCAN_INDEX_MAX
38};
35 39
36struct als_state { 40struct als_state {
37 struct hid_sensor_hub_callbacks callbacks; 41 struct hid_sensor_hub_callbacks callbacks;
38 struct hid_sensor_common common_attributes; 42 struct hid_sensor_common common_attributes;
39 struct hid_sensor_hub_attribute_info als_illum; 43 struct hid_sensor_hub_attribute_info als_illum;
40 u32 illum; 44 u32 illum[CHANNEL_SCAN_INDEX_MAX];
41 int scale_pre_decml; 45 int scale_pre_decml;
42 int scale_post_decml; 46 int scale_post_decml;
43 int scale_precision; 47 int scale_precision;
@@ -55,6 +59,15 @@ static const struct iio_chan_spec als_channels[] = {
55 BIT(IIO_CHAN_INFO_SCALE) | 59 BIT(IIO_CHAN_INFO_SCALE) |
56 BIT(IIO_CHAN_INFO_SAMP_FREQ) | 60 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
57 BIT(IIO_CHAN_INFO_HYSTERESIS), 61 BIT(IIO_CHAN_INFO_HYSTERESIS),
62 .scan_index = CHANNEL_SCAN_INDEX_INTENSITY,
63 },
64 {
65 .type = IIO_LIGHT,
66 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
67 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
68 BIT(IIO_CHAN_INFO_SCALE) |
69 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
70 BIT(IIO_CHAN_INFO_HYSTERESIS),
58 .scan_index = CHANNEL_SCAN_INDEX_ILLUM, 71 .scan_index = CHANNEL_SCAN_INDEX_ILLUM,
59 } 72 }
60}; 73};
@@ -86,6 +99,7 @@ static int als_read_raw(struct iio_dev *indio_dev,
86 switch (mask) { 99 switch (mask) {
87 case 0: 100 case 0:
88 switch (chan->scan_index) { 101 switch (chan->scan_index) {
102 case CHANNEL_SCAN_INDEX_INTENSITY:
89 case CHANNEL_SCAN_INDEX_ILLUM: 103 case CHANNEL_SCAN_INDEX_ILLUM:
90 report_id = als_state->als_illum.report_id; 104 report_id = als_state->als_illum.report_id;
91 address = 105 address =
@@ -202,10 +216,12 @@ static int als_capture_sample(struct hid_sensor_hub_device *hsdev,
202 struct iio_dev *indio_dev = platform_get_drvdata(priv); 216 struct iio_dev *indio_dev = platform_get_drvdata(priv);
203 struct als_state *als_state = iio_priv(indio_dev); 217 struct als_state *als_state = iio_priv(indio_dev);
204 int ret = -EINVAL; 218 int ret = -EINVAL;
219 u32 sample_data = *(u32 *)raw_data;
205 220
206 switch (usage_id) { 221 switch (usage_id) {
207 case HID_USAGE_SENSOR_LIGHT_ILLUM: 222 case HID_USAGE_SENSOR_LIGHT_ILLUM:
208 als_state->illum = *(u32 *)raw_data; 223 als_state->illum[CHANNEL_SCAN_INDEX_INTENSITY] = sample_data;
224 als_state->illum[CHANNEL_SCAN_INDEX_ILLUM] = sample_data;
209 ret = 0; 225 ret = 0;
210 break; 226 break;
211 default: 227 default:
@@ -230,6 +246,8 @@ static int als_parse_report(struct platform_device *pdev,
230 &st->als_illum); 246 &st->als_illum);
231 if (ret < 0) 247 if (ret < 0)
232 return ret; 248 return ret;
249 als_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_INTENSITY,
250 st->als_illum.size);
233 als_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_ILLUM, 251 als_adjust_channel_bit_mask(channels, CHANNEL_SCAN_INDEX_ILLUM,
234 st->als_illum.size); 252 st->als_illum.size);
235 253
diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c
index 78c9b3a6453a..b91ebc3483ce 100644
--- a/drivers/iio/light/opt3001.c
+++ b/drivers/iio/light/opt3001.c
@@ -840,6 +840,7 @@ static const struct of_device_id opt3001_of_match[] = {
840 { .compatible = "ti,opt3001" }, 840 { .compatible = "ti,opt3001" },
841 { } 841 { }
842}; 842};
843MODULE_DEVICE_TABLE(of, opt3001_of_match);
843 844
844static struct i2c_driver opt3001_driver = { 845static struct i2c_driver opt3001_driver = {
845 .probe = opt3001_probe, 846 .probe = opt3001_probe,
diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c
index ce09d771c1fb..6dd8cbd7ce95 100644
--- a/drivers/iio/magnetometer/ak8974.c
+++ b/drivers/iio/magnetometer/ak8974.c
@@ -278,13 +278,9 @@ static int ak8974_await_drdy(struct ak8974 *ak8974)
278 if (val & AK8974_STATUS_DRDY) 278 if (val & AK8974_STATUS_DRDY)
279 return 0; 279 return 0;
280 } while (--timeout); 280 } while (--timeout);
281 if (!timeout) {
282 dev_err(&ak8974->i2c->dev,
283 "timeout waiting for DRDY\n");
284 return -ETIMEDOUT;
285 }
286 281
287 return 0; 282 dev_err(&ak8974->i2c->dev, "timeout waiting for DRDY\n");
283 return -ETIMEDOUT;
288} 284}
289 285
290static int ak8974_getresult(struct ak8974 *ak8974, __le16 *result) 286static int ak8974_getresult(struct ak8974 *ak8974, __le16 *result)
diff --git a/drivers/iio/magnetometer/mag3110.c b/drivers/iio/magnetometer/mag3110.c
index f2b3bd7bf862..b4f643fb3b1e 100644
--- a/drivers/iio/magnetometer/mag3110.c
+++ b/drivers/iio/magnetometer/mag3110.c
@@ -222,29 +222,39 @@ static int mag3110_write_raw(struct iio_dev *indio_dev,
222 int val, int val2, long mask) 222 int val, int val2, long mask)
223{ 223{
224 struct mag3110_data *data = iio_priv(indio_dev); 224 struct mag3110_data *data = iio_priv(indio_dev);
225 int rate; 225 int rate, ret;
226 226
227 if (iio_buffer_enabled(indio_dev)) 227 ret = iio_device_claim_direct_mode(indio_dev);
228 return -EBUSY; 228 if (ret)
229 return ret;
229 230
230 switch (mask) { 231 switch (mask) {
231 case IIO_CHAN_INFO_SAMP_FREQ: 232 case IIO_CHAN_INFO_SAMP_FREQ:
232 rate = mag3110_get_samp_freq_index(data, val, val2); 233 rate = mag3110_get_samp_freq_index(data, val, val2);
233 if (rate < 0) 234 if (rate < 0) {
234 return -EINVAL; 235 ret = -EINVAL;
236 break;
237 }
235 238
236 data->ctrl_reg1 &= ~MAG3110_CTRL_DR_MASK; 239 data->ctrl_reg1 &= ~MAG3110_CTRL_DR_MASK;
237 data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT; 240 data->ctrl_reg1 |= rate << MAG3110_CTRL_DR_SHIFT;
238 return i2c_smbus_write_byte_data(data->client, 241 ret = i2c_smbus_write_byte_data(data->client,
239 MAG3110_CTRL_REG1, data->ctrl_reg1); 242 MAG3110_CTRL_REG1, data->ctrl_reg1);
243 break;
240 case IIO_CHAN_INFO_CALIBBIAS: 244 case IIO_CHAN_INFO_CALIBBIAS:
241 if (val < -10000 || val > 10000) 245 if (val < -10000 || val > 10000) {
242 return -EINVAL; 246 ret = -EINVAL;
243 return i2c_smbus_write_word_swapped(data->client, 247 break;
248 }
249 ret = i2c_smbus_write_word_swapped(data->client,
244 MAG3110_OFF_X + 2 * chan->scan_index, val << 1); 250 MAG3110_OFF_X + 2 * chan->scan_index, val << 1);
251 break;
245 default: 252 default:
246 return -EINVAL; 253 ret = -EINVAL;
254 break;
247 } 255 }
256 iio_device_release_direct_mode(indio_dev);
257 return ret;
248} 258}
249 259
250static irqreturn_t mag3110_trigger_handler(int irq, void *p) 260static irqreturn_t mag3110_trigger_handler(int irq, void *p)
diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig
index 2e9da1cf3297..8bf282510be6 100644
--- a/drivers/iio/potentiometer/Kconfig
+++ b/drivers/iio/potentiometer/Kconfig
@@ -15,6 +15,17 @@ config DS1803
15 To compile this driver as a module, choose M here: the 15 To compile this driver as a module, choose M here: the
16 module will be called ds1803. 16 module will be called ds1803.
17 17
18config MAX5481
19 tristate "Maxim MAX5481-MAX5484 Digital Potentiometer driver"
20 depends on SPI
21 help
22 Say yes here to build support for the Maxim
23 MAX5481, MAX5482, MAX5483, MAX5484 digital potentiometer
24 chips.
25
26 To compile this driver as a module, choose M here: the
27 module will be called max5481.
28
18config MAX5487 29config MAX5487
19 tristate "Maxim MAX5487/MAX5488/MAX5489 Digital Potentiometer driver" 30 tristate "Maxim MAX5487/MAX5488/MAX5489 Digital Potentiometer driver"
20 depends on SPI 31 depends on SPI
diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile
index 8adb58f38c0b..2260d40e0936 100644
--- a/drivers/iio/potentiometer/Makefile
+++ b/drivers/iio/potentiometer/Makefile
@@ -4,6 +4,7 @@
4 4
5# When adding new entries keep the list in alphabetical order 5# When adding new entries keep the list in alphabetical order
6obj-$(CONFIG_DS1803) += ds1803.o 6obj-$(CONFIG_DS1803) += ds1803.o
7obj-$(CONFIG_MAX5481) += max5481.o
7obj-$(CONFIG_MAX5487) += max5487.o 8obj-$(CONFIG_MAX5487) += max5487.o
8obj-$(CONFIG_MCP4131) += mcp4131.o 9obj-$(CONFIG_MCP4131) += mcp4131.o
9obj-$(CONFIG_MCP4531) += mcp4531.o 10obj-$(CONFIG_MCP4531) += mcp4531.o
diff --git a/drivers/iio/potentiometer/max5481.c b/drivers/iio/potentiometer/max5481.c
new file mode 100644
index 000000000000..926554991244
--- /dev/null
+++ b/drivers/iio/potentiometer/max5481.c
@@ -0,0 +1,223 @@
1/*
2 * Maxim Integrated MAX5481-MAX5484 digital potentiometer driver
3 * Copyright 2016 Rockwell Collins
4 *
5 * Datasheet:
6 * http://datasheets.maximintegrated.com/en/ds/MAX5481-MAX5484.pdf
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 version 2 as
10 * published by the free software foundation.
11 *
12 */
13
14#include <linux/acpi.h>
15#include <linux/iio/iio.h>
16#include <linux/iio/sysfs.h>
17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/of_device.h>
20#include <linux/spi/spi.h>
21
22/* write wiper reg */
23#define MAX5481_WRITE_WIPER (0 << 4)
24/* copy wiper reg to NV reg */
25#define MAX5481_COPY_AB_TO_NV (2 << 4)
26/* copy NV reg to wiper reg */
27#define MAX5481_COPY_NV_TO_AB (3 << 4)
28
29#define MAX5481_MAX_POS 1023
30
31enum max5481_variant {
32 max5481,
33 max5482,
34 max5483,
35 max5484,
36};
37
38struct max5481_cfg {
39 int kohms;
40};
41
42static const struct max5481_cfg max5481_cfg[] = {
43 [max5481] = { .kohms = 10, },
44 [max5482] = { .kohms = 50, },
45 [max5483] = { .kohms = 10, },
46 [max5484] = { .kohms = 50, },
47};
48
49struct max5481_data {
50 struct spi_device *spi;
51 const struct max5481_cfg *cfg;
52 u8 msg[3] ____cacheline_aligned;
53};
54
55#define MAX5481_CHANNEL { \
56 .type = IIO_RESISTANCE, \
57 .indexed = 1, \
58 .output = 1, \
59 .channel = 0, \
60 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
61 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
62}
63
64static const struct iio_chan_spec max5481_channels[] = {
65 MAX5481_CHANNEL,
66};
67
68static int max5481_write_cmd(struct max5481_data *data, u8 cmd, u16 val)
69{
70 struct spi_device *spi = data->spi;
71
72 data->msg[0] = cmd;
73
74 switch (cmd) {
75 case MAX5481_WRITE_WIPER:
76 data->msg[1] = val >> 2;
77 data->msg[2] = (val & 0x3) << 6;
78 return spi_write(spi, data->msg, 3);
79
80 case MAX5481_COPY_AB_TO_NV:
81 case MAX5481_COPY_NV_TO_AB:
82 return spi_write(spi, data->msg, 1);
83
84 default:
85 return -EIO;
86 }
87}
88
89static int max5481_read_raw(struct iio_dev *indio_dev,
90 struct iio_chan_spec const *chan,
91 int *val, int *val2, long mask)
92{
93 struct max5481_data *data = iio_priv(indio_dev);
94
95 if (mask != IIO_CHAN_INFO_SCALE)
96 return -EINVAL;
97
98 *val = 1000 * data->cfg->kohms;
99 *val2 = MAX5481_MAX_POS;
100
101 return IIO_VAL_FRACTIONAL;
102}
103
104static int max5481_write_raw(struct iio_dev *indio_dev,
105 struct iio_chan_spec const *chan,
106 int val, int val2, long mask)
107{
108 struct max5481_data *data = iio_priv(indio_dev);
109
110 if (mask != IIO_CHAN_INFO_RAW)
111 return -EINVAL;
112
113 if (val < 0 || val > MAX5481_MAX_POS)
114 return -EINVAL;
115
116 return max5481_write_cmd(data, MAX5481_WRITE_WIPER, val);
117}
118
119static const struct iio_info max5481_info = {
120 .read_raw = max5481_read_raw,
121 .write_raw = max5481_write_raw,
122 .driver_module = THIS_MODULE,
123};
124
125#if defined(CONFIG_OF)
126static const struct of_device_id max5481_match[] = {
127 { .compatible = "maxim,max5481", .data = &max5481_cfg[max5481] },
128 { .compatible = "maxim,max5482", .data = &max5481_cfg[max5482] },
129 { .compatible = "maxim,max5483", .data = &max5481_cfg[max5483] },
130 { .compatible = "maxim,max5484", .data = &max5481_cfg[max5484] },
131 { }
132};
133MODULE_DEVICE_TABLE(of, max5481_match);
134#endif
135
136static int max5481_probe(struct spi_device *spi)
137{
138 struct iio_dev *indio_dev;
139 struct max5481_data *data;
140 const struct spi_device_id *id = spi_get_device_id(spi);
141 const struct of_device_id *match;
142 int ret;
143
144 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
145 if (!indio_dev)
146 return -ENOMEM;
147
148 dev_set_drvdata(&spi->dev, indio_dev);
149 data = iio_priv(indio_dev);
150
151 data->spi = spi;
152
153 match = of_match_device(of_match_ptr(max5481_match), &spi->dev);
154 if (match)
155 data->cfg = of_device_get_match_data(&spi->dev);
156 else
157 data->cfg = &max5481_cfg[id->driver_data];
158
159 indio_dev->name = id->name;
160 indio_dev->dev.parent = &spi->dev;
161 indio_dev->modes = INDIO_DIRECT_MODE;
162
163 /* variant specific configuration */
164 indio_dev->info = &max5481_info;
165 indio_dev->channels = max5481_channels;
166 indio_dev->num_channels = ARRAY_SIZE(max5481_channels);
167
168 /* restore wiper from NV */
169 ret = max5481_write_cmd(data, MAX5481_COPY_NV_TO_AB, 0);
170 if (ret < 0)
171 return ret;
172
173 return iio_device_register(indio_dev);
174}
175
176static int max5481_remove(struct spi_device *spi)
177{
178 struct iio_dev *indio_dev = dev_get_drvdata(&spi->dev);
179 struct max5481_data *data = iio_priv(indio_dev);
180
181 iio_device_unregister(indio_dev);
182
183 /* save wiper reg to NV reg */
184 return max5481_write_cmd(data, MAX5481_COPY_AB_TO_NV, 0);
185}
186
187static const struct spi_device_id max5481_id_table[] = {
188 { "max5481", max5481 },
189 { "max5482", max5482 },
190 { "max5483", max5483 },
191 { "max5484", max5484 },
192 { }
193};
194MODULE_DEVICE_TABLE(spi, max5481_id_table);
195
196#if defined(CONFIG_ACPI)
197static const struct acpi_device_id max5481_acpi_match[] = {
198 { "max5481", max5481 },
199 { "max5482", max5482 },
200 { "max5483", max5483 },
201 { "max5484", max5484 },
202 { }
203};
204MODULE_DEVICE_TABLE(acpi, max5481_acpi_match);
205#endif
206
207static struct spi_driver max5481_driver = {
208 .driver = {
209 .name = "max5481",
210 .owner = THIS_MODULE,
211 .of_match_table = of_match_ptr(max5481_match),
212 .acpi_match_table = ACPI_PTR(max5481_acpi_match),
213 },
214 .probe = max5481_probe,
215 .remove = max5481_remove,
216 .id_table = max5481_id_table,
217};
218
219module_spi_driver(max5481_driver);
220
221MODULE_AUTHOR("Maury Anderson <maury.anderson@rockwellcollins.com>");
222MODULE_DESCRIPTION("max5481 SPI driver");
223MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/potentiometer/mcp4531.c b/drivers/iio/potentiometer/mcp4531.c
index 0d1bcf89ae17..314353d7ab59 100644
--- a/drivers/iio/potentiometer/mcp4531.c
+++ b/drivers/iio/potentiometer/mcp4531.c
@@ -284,6 +284,7 @@ static const struct of_device_id mcp4531_of_match[] = {
284 MCP4531_COMPATIBLE("microchip,mcp4662-104", MCP466x_104), 284 MCP4531_COMPATIBLE("microchip,mcp4662-104", MCP466x_104),
285 { /* sentinel */ } 285 { /* sentinel */ }
286}; 286};
287MODULE_DEVICE_TABLE(of, mcp4531_of_match);
287#endif 288#endif
288 289
289static int mcp4531_probe(struct i2c_client *client, 290static int mcp4531_probe(struct i2c_client *client,
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index bd8d96b96771..5d16b252ab6b 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -42,6 +42,16 @@ config BMP280_SPI
42 depends on SPI_MASTER 42 depends on SPI_MASTER
43 select REGMAP 43 select REGMAP
44 44
45config IIO_CROS_EC_BARO
46 tristate "ChromeOS EC Barometer Sensor"
47 depends on IIO_CROS_EC_SENSORS_CORE
48 help
49 Say yes here to build support for the Barometer sensor when
50 presented by the ChromeOS EC Sensor hub.
51
52 To compile this driver as a module, choose M here: the module
53 will be called cros_ec_baro.
54
45config HID_SENSOR_PRESS 55config HID_SENSOR_PRESS
46 depends on HID_SENSOR_HUB 56 depends on HID_SENSOR_HUB
47 select IIO_BUFFER 57 select IIO_BUFFER
diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile
index de3dbc81dc5a..838642789389 100644
--- a/drivers/iio/pressure/Makefile
+++ b/drivers/iio/pressure/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_BMP280) += bmp280.o
8bmp280-objs := bmp280-core.o bmp280-regmap.o 8bmp280-objs := bmp280-core.o bmp280-regmap.o
9obj-$(CONFIG_BMP280_I2C) += bmp280-i2c.o 9obj-$(CONFIG_BMP280_I2C) += bmp280-i2c.o
10obj-$(CONFIG_BMP280_SPI) += bmp280-spi.o 10obj-$(CONFIG_BMP280_SPI) += bmp280-spi.o
11obj-$(CONFIG_IIO_CROS_EC_BARO) += cros_ec_baro.o
11obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o 12obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o
12obj-$(CONFIG_HP03) += hp03.o 13obj-$(CONFIG_HP03) += hp03.o
13obj-$(CONFIG_MPL115) += mpl115.o 14obj-$(CONFIG_MPL115) += mpl115.o
diff --git a/drivers/iio/pressure/bmp280-core.c b/drivers/iio/pressure/bmp280-core.c
index e5a533cbd53f..4d18826ac63c 100644
--- a/drivers/iio/pressure/bmp280-core.c
+++ b/drivers/iio/pressure/bmp280-core.c
@@ -65,7 +65,7 @@ struct bmp280_data {
65 struct bmp180_calib calib; 65 struct bmp180_calib calib;
66 struct regulator *vddd; 66 struct regulator *vddd;
67 struct regulator *vdda; 67 struct regulator *vdda;
68 unsigned int start_up_time; /* in milliseconds */ 68 unsigned int start_up_time; /* in microseconds */
69 69
70 /* log of base 2 of oversampling rate */ 70 /* log of base 2 of oversampling rate */
71 u8 oversampling_press; 71 u8 oversampling_press;
@@ -935,14 +935,14 @@ int bmp280_common_probe(struct device *dev,
935 data->chip_info = &bmp180_chip_info; 935 data->chip_info = &bmp180_chip_info;
936 data->oversampling_press = ilog2(8); 936 data->oversampling_press = ilog2(8);
937 data->oversampling_temp = ilog2(1); 937 data->oversampling_temp = ilog2(1);
938 data->start_up_time = 10; 938 data->start_up_time = 10000;
939 break; 939 break;
940 case BMP280_CHIP_ID: 940 case BMP280_CHIP_ID:
941 indio_dev->num_channels = 2; 941 indio_dev->num_channels = 2;
942 data->chip_info = &bmp280_chip_info; 942 data->chip_info = &bmp280_chip_info;
943 data->oversampling_press = ilog2(16); 943 data->oversampling_press = ilog2(16);
944 data->oversampling_temp = ilog2(2); 944 data->oversampling_temp = ilog2(2);
945 data->start_up_time = 2; 945 data->start_up_time = 2000;
946 break; 946 break;
947 case BME280_CHIP_ID: 947 case BME280_CHIP_ID:
948 indio_dev->num_channels = 3; 948 indio_dev->num_channels = 3;
@@ -950,7 +950,7 @@ int bmp280_common_probe(struct device *dev,
950 data->oversampling_press = ilog2(16); 950 data->oversampling_press = ilog2(16);
951 data->oversampling_humid = ilog2(16); 951 data->oversampling_humid = ilog2(16);
952 data->oversampling_temp = ilog2(2); 952 data->oversampling_temp = ilog2(2);
953 data->start_up_time = 2; 953 data->start_up_time = 2000;
954 break; 954 break;
955 default: 955 default:
956 return -EINVAL; 956 return -EINVAL;
@@ -979,7 +979,7 @@ int bmp280_common_probe(struct device *dev,
979 goto out_disable_vddd; 979 goto out_disable_vddd;
980 } 980 }
981 /* Wait to make sure we started up properly */ 981 /* Wait to make sure we started up properly */
982 mdelay(data->start_up_time); 982 usleep_range(data->start_up_time, data->start_up_time + 100);
983 983
984 /* Bring chip out of reset if there is an assigned GPIO line */ 984 /* Bring chip out of reset if there is an assigned GPIO line */
985 gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 985 gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
@@ -1038,7 +1038,7 @@ int bmp280_common_probe(struct device *dev,
1038 * Set autosuspend to two orders of magnitude larger than the 1038 * Set autosuspend to two orders of magnitude larger than the
1039 * start-up time. 1039 * start-up time.
1040 */ 1040 */
1041 pm_runtime_set_autosuspend_delay(dev, data->start_up_time *100); 1041 pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10);
1042 pm_runtime_use_autosuspend(dev); 1042 pm_runtime_use_autosuspend(dev);
1043 pm_runtime_put(dev); 1043 pm_runtime_put(dev);
1044 1044
@@ -1101,7 +1101,7 @@ static int bmp280_runtime_resume(struct device *dev)
1101 ret = regulator_enable(data->vdda); 1101 ret = regulator_enable(data->vdda);
1102 if (ret) 1102 if (ret)
1103 return ret; 1103 return ret;
1104 msleep(data->start_up_time); 1104 usleep_range(data->start_up_time, data->start_up_time + 100);
1105 return data->chip_info->chip_config(data); 1105 return data->chip_info->chip_config(data);
1106} 1106}
1107#endif /* CONFIG_PM */ 1107#endif /* CONFIG_PM */
diff --git a/drivers/iio/pressure/cros_ec_baro.c b/drivers/iio/pressure/cros_ec_baro.c
new file mode 100644
index 000000000000..48b2a30f57ae
--- /dev/null
+++ b/drivers/iio/pressure/cros_ec_baro.c
@@ -0,0 +1,220 @@
1/*
2 * cros_ec_baro - Driver for barometer sensor behind CrosEC.
3 *
4 * Copyright (C) 2017 Google, 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#include <linux/delay.h>
17#include <linux/device.h>
18#include <linux/iio/buffer.h>
19#include <linux/iio/iio.h>
20#include <linux/iio/kfifo_buf.h>
21#include <linux/iio/trigger.h>
22#include <linux/iio/triggered_buffer.h>
23#include <linux/iio/trigger_consumer.h>
24#include <linux/kernel.h>
25#include <linux/mfd/cros_ec.h>
26#include <linux/mfd/cros_ec_commands.h>
27#include <linux/module.h>
28#include <linux/slab.h>
29#include <linux/platform_device.h>
30
31#include "../common/cros_ec_sensors/cros_ec_sensors_core.h"
32
33/*
34 * One channel for pressure, the other for timestamp.
35 */
36#define CROS_EC_BARO_MAX_CHANNELS (1 + 1)
37
38/* State data for ec_sensors iio driver. */
39struct cros_ec_baro_state {
40 /* Shared by all sensors */
41 struct cros_ec_sensors_core_state core;
42
43 struct iio_chan_spec channels[CROS_EC_BARO_MAX_CHANNELS];
44};
45
46static int cros_ec_baro_read(struct iio_dev *indio_dev,
47 struct iio_chan_spec const *chan,
48 int *val, int *val2, long mask)
49{
50 struct cros_ec_baro_state *st = iio_priv(indio_dev);
51 u16 data = 0;
52 int ret = IIO_VAL_INT;
53 int idx = chan->scan_index;
54
55 mutex_lock(&st->core.cmd_lock);
56
57 switch (mask) {
58 case IIO_CHAN_INFO_RAW:
59 if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx,
60 (s16 *)&data) < 0)
61 ret = -EIO;
62 *val = data;
63 break;
64 case IIO_CHAN_INFO_SCALE:
65 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
66 st->core.param.sensor_range.data = EC_MOTION_SENSE_NO_VALUE;
67
68 if (cros_ec_motion_send_host_cmd(&st->core, 0)) {
69 ret = -EIO;
70 break;
71 }
72 *val = st->core.resp->sensor_range.ret;
73
74 /* scale * in_pressure_raw --> kPa */
75 *val2 = 10 << CROS_EC_SENSOR_BITS;
76 ret = IIO_VAL_FRACTIONAL;
77 break;
78 default:
79 ret = cros_ec_sensors_core_read(&st->core, chan, val, val2,
80 mask);
81 break;
82 }
83
84 mutex_unlock(&st->core.cmd_lock);
85
86 return ret;
87}
88
89static int cros_ec_baro_write(struct iio_dev *indio_dev,
90 struct iio_chan_spec const *chan,
91 int val, int val2, long mask)
92{
93 struct cros_ec_baro_state *st = iio_priv(indio_dev);
94 int ret = 0;
95
96 mutex_lock(&st->core.cmd_lock);
97
98 switch (mask) {
99 case IIO_CHAN_INFO_SCALE:
100 st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE;
101 st->core.param.sensor_range.data = val;
102
103 /* Always roundup, so caller gets at least what it asks for. */
104 st->core.param.sensor_range.roundup = 1;
105
106 if (cros_ec_motion_send_host_cmd(&st->core, 0))
107 ret = -EIO;
108 break;
109 default:
110 ret = cros_ec_sensors_core_write(&st->core, chan, val, val2,
111 mask);
112 break;
113 }
114
115 mutex_unlock(&st->core.cmd_lock);
116
117 return ret;
118}
119
120static const struct iio_info cros_ec_baro_info = {
121 .read_raw = &cros_ec_baro_read,
122 .write_raw = &cros_ec_baro_write,
123 .driver_module = THIS_MODULE,
124};
125
126static int cros_ec_baro_probe(struct platform_device *pdev)
127{
128 struct device *dev = &pdev->dev;
129 struct cros_ec_dev *ec_dev = dev_get_drvdata(dev->parent);
130 struct cros_ec_device *ec_device;
131 struct iio_dev *indio_dev;
132 struct cros_ec_baro_state *state;
133 struct iio_chan_spec *channel;
134 int ret;
135
136 if (!ec_dev || !ec_dev->ec_dev) {
137 dev_warn(dev, "No CROS EC device found.\n");
138 return -EINVAL;
139 }
140 ec_device = ec_dev->ec_dev;
141
142 indio_dev = devm_iio_device_alloc(dev, sizeof(*state));
143 if (!indio_dev)
144 return -ENOMEM;
145
146 ret = cros_ec_sensors_core_init(pdev, indio_dev, true);
147 if (ret)
148 return ret;
149
150 indio_dev->info = &cros_ec_baro_info;
151 state = iio_priv(indio_dev);
152 state->core.type = state->core.resp->info.type;
153 state->core.loc = state->core.resp->info.location;
154 channel = state->channels;
155 /* Common part */
156 channel->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
157 channel->info_mask_shared_by_all =
158 BIT(IIO_CHAN_INFO_SCALE) |
159 BIT(IIO_CHAN_INFO_SAMP_FREQ) |
160 BIT(IIO_CHAN_INFO_FREQUENCY);
161 channel->scan_type.realbits = CROS_EC_SENSOR_BITS;
162 channel->scan_type.storagebits = CROS_EC_SENSOR_BITS;
163 channel->scan_type.shift = 0;
164 channel->scan_index = 0;
165 channel->ext_info = cros_ec_sensors_ext_info;
166 channel->scan_type.sign = 'u';
167
168 state->core.calib[0] = 0;
169
170 /* Sensor specific */
171 switch (state->core.type) {
172 case MOTIONSENSE_TYPE_BARO:
173 channel->type = IIO_PRESSURE;
174 break;
175 default:
176 dev_warn(dev, "Unknown motion sensor\n");
177 return -EINVAL;
178 }
179
180 /* Timestamp */
181 channel++;
182 channel->type = IIO_TIMESTAMP;
183 channel->channel = -1;
184 channel->scan_index = 1;
185 channel->scan_type.sign = 's';
186 channel->scan_type.realbits = 64;
187 channel->scan_type.storagebits = 64;
188
189 indio_dev->channels = state->channels;
190 indio_dev->num_channels = CROS_EC_BARO_MAX_CHANNELS;
191
192 state->core.read_ec_sensors_data = cros_ec_sensors_read_cmd;
193
194 ret = devm_iio_triggered_buffer_setup(dev, indio_dev, NULL,
195 cros_ec_sensors_capture, NULL);
196 if (ret)
197 return ret;
198
199 return devm_iio_device_register(dev, indio_dev);
200}
201
202static const struct platform_device_id cros_ec_baro_ids[] = {
203 {
204 .name = "cros-ec-baro",
205 },
206 { /* sentinel */ }
207};
208MODULE_DEVICE_TABLE(platform, cros_ec_baro_ids);
209
210static struct platform_driver cros_ec_baro_platform_driver = {
211 .driver = {
212 .name = "cros-ec-baro",
213 },
214 .probe = cros_ec_baro_probe,
215 .id_table = cros_ec_baro_ids,
216};
217module_platform_driver(cros_ec_baro_platform_driver);
218
219MODULE_DESCRIPTION("ChromeOS EC barometer sensor driver");
220MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/pressure/mpl115.c b/drivers/iio/pressure/mpl115.c
index 73f2f0c46e62..8f2bce213248 100644
--- a/drivers/iio/pressure/mpl115.c
+++ b/drivers/iio/pressure/mpl115.c
@@ -137,6 +137,7 @@ static const struct iio_chan_spec mpl115_channels[] = {
137 { 137 {
138 .type = IIO_TEMP, 138 .type = IIO_TEMP,
139 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 139 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
140 .info_mask_shared_by_type =
140 BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE), 141 BIT(IIO_CHAN_INFO_OFFSET) | BIT(IIO_CHAN_INFO_SCALE),
141 }, 142 },
142}; 143};
diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
index cc3f84139157..525644a7442d 100644
--- a/drivers/iio/pressure/mpl3115.c
+++ b/drivers/iio/pressure/mpl3115.c
@@ -190,7 +190,7 @@ static const struct iio_chan_spec mpl3115_channels[] = {
190 { 190 {
191 .type = IIO_PRESSURE, 191 .type = IIO_PRESSURE,
192 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 192 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
193 BIT(IIO_CHAN_INFO_SCALE), 193 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
194 .scan_index = 0, 194 .scan_index = 0,
195 .scan_type = { 195 .scan_type = {
196 .sign = 'u', 196 .sign = 'u',
@@ -203,7 +203,7 @@ static const struct iio_chan_spec mpl3115_channels[] = {
203 { 203 {
204 .type = IIO_TEMP, 204 .type = IIO_TEMP,
205 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 205 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
206 BIT(IIO_CHAN_INFO_SCALE), 206 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
207 .scan_index = 1, 207 .scan_index = 1,
208 .scan_type = { 208 .scan_type = {
209 .sign = 's', 209 .sign = 's',
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index 6bd53e702667..2a77a2f15752 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -308,6 +308,7 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
308{ 308{
309 struct ms5611_state *st = iio_priv(indio_dev); 309 struct ms5611_state *st = iio_priv(indio_dev);
310 const struct ms5611_osr *osr = NULL; 310 const struct ms5611_osr *osr = NULL;
311 int ret;
311 312
312 if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO) 313 if (mask != IIO_CHAN_INFO_OVERSAMPLING_RATIO)
313 return -EINVAL; 314 return -EINVAL;
@@ -321,12 +322,11 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
321 if (!osr) 322 if (!osr)
322 return -EINVAL; 323 return -EINVAL;
323 324
324 mutex_lock(&st->lock); 325 ret = iio_device_claim_direct_mode(indio_dev);
326 if (ret)
327 return ret;
325 328
326 if (iio_buffer_enabled(indio_dev)) { 329 mutex_lock(&st->lock);
327 mutex_unlock(&st->lock);
328 return -EBUSY;
329 }
330 330
331 if (chan->type == IIO_TEMP) 331 if (chan->type == IIO_TEMP)
332 st->temp_osr = osr; 332 st->temp_osr = osr;
@@ -334,6 +334,8 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
334 st->pressure_osr = osr; 334 st->pressure_osr = osr;
335 335
336 mutex_unlock(&st->lock); 336 mutex_unlock(&st->lock);
337 iio_device_release_direct_mode(indio_dev);
338
337 return 0; 339 return 0;
338} 340}
339 341
diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h
index 903a21e46874..7d995937adba 100644
--- a/drivers/iio/pressure/st_pressure.h
+++ b/drivers/iio/pressure/st_pressure.h
@@ -14,6 +14,14 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/iio/common/st_sensors.h> 15#include <linux/iio/common/st_sensors.h>
16 16
17enum st_press_type {
18 LPS001WP,
19 LPS25H,
20 LPS331AP,
21 LPS22HB,
22 ST_PRESS_MAX,
23};
24
17#define LPS001WP_PRESS_DEV_NAME "lps001wp" 25#define LPS001WP_PRESS_DEV_NAME "lps001wp"
18#define LPS25H_PRESS_DEV_NAME "lps25h" 26#define LPS25H_PRESS_DEV_NAME "lps25h"
19#define LPS331AP_PRESS_DEV_NAME "lps331ap" 27#define LPS331AP_PRESS_DEV_NAME "lps331ap"
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index e19e0787864c..5f2680855552 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -136,20 +136,21 @@ static const struct iio_chan_spec st_press_1_channels[] = {
136 .address = ST_PRESS_1_OUT_XL_ADDR, 136 .address = ST_PRESS_1_OUT_XL_ADDR,
137 .scan_index = 0, 137 .scan_index = 0,
138 .scan_type = { 138 .scan_type = {
139 .sign = 'u', 139 .sign = 's',
140 .realbits = 24, 140 .realbits = 24,
141 .storagebits = 32, 141 .storagebits = 32,
142 .endianness = IIO_LE, 142 .endianness = IIO_LE,
143 }, 143 },
144 .info_mask_separate = 144 .info_mask_separate =
145 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 145 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
146 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
146 }, 147 },
147 { 148 {
148 .type = IIO_TEMP, 149 .type = IIO_TEMP,
149 .address = ST_TEMP_1_OUT_L_ADDR, 150 .address = ST_TEMP_1_OUT_L_ADDR,
150 .scan_index = 1, 151 .scan_index = 1,
151 .scan_type = { 152 .scan_type = {
152 .sign = 'u', 153 .sign = 's',
153 .realbits = 16, 154 .realbits = 16,
154 .storagebits = 16, 155 .storagebits = 16,
155 .endianness = IIO_LE, 156 .endianness = IIO_LE,
@@ -158,6 +159,7 @@ static const struct iio_chan_spec st_press_1_channels[] = {
158 BIT(IIO_CHAN_INFO_RAW) | 159 BIT(IIO_CHAN_INFO_RAW) |
159 BIT(IIO_CHAN_INFO_SCALE) | 160 BIT(IIO_CHAN_INFO_SCALE) |
160 BIT(IIO_CHAN_INFO_OFFSET), 161 BIT(IIO_CHAN_INFO_OFFSET),
162 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
161 }, 163 },
162 IIO_CHAN_SOFT_TIMESTAMP(2) 164 IIO_CHAN_SOFT_TIMESTAMP(2)
163}; 165};
@@ -168,7 +170,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
168 .address = ST_PRESS_LPS001WP_OUT_L_ADDR, 170 .address = ST_PRESS_LPS001WP_OUT_L_ADDR,
169 .scan_index = 0, 171 .scan_index = 0,
170 .scan_type = { 172 .scan_type = {
171 .sign = 'u', 173 .sign = 's',
172 .realbits = 16, 174 .realbits = 16,
173 .storagebits = 16, 175 .storagebits = 16,
174 .endianness = IIO_LE, 176 .endianness = IIO_LE,
@@ -182,7 +184,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
182 .address = ST_TEMP_LPS001WP_OUT_L_ADDR, 184 .address = ST_TEMP_LPS001WP_OUT_L_ADDR,
183 .scan_index = 1, 185 .scan_index = 1,
184 .scan_type = { 186 .scan_type = {
185 .sign = 'u', 187 .sign = 's',
186 .realbits = 16, 188 .realbits = 16,
187 .storagebits = 16, 189 .storagebits = 16,
188 .endianness = IIO_LE, 190 .endianness = IIO_LE,
@@ -200,7 +202,7 @@ static const struct iio_chan_spec st_press_lps22hb_channels[] = {
200 .address = ST_PRESS_1_OUT_XL_ADDR, 202 .address = ST_PRESS_1_OUT_XL_ADDR,
201 .scan_index = 0, 203 .scan_index = 0,
202 .scan_type = { 204 .scan_type = {
203 .sign = 'u', 205 .sign = 's',
204 .realbits = 24, 206 .realbits = 24,
205 .storagebits = 32, 207 .storagebits = 32,
206 .endianness = IIO_LE, 208 .endianness = IIO_LE,
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index ed18701c68c9..17417a4d5a5f 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/acpi.h>
14#include <linux/i2c.h> 15#include <linux/i2c.h>
15#include <linux/iio/iio.h> 16#include <linux/iio/iio.h>
16 17
@@ -43,25 +44,56 @@ MODULE_DEVICE_TABLE(of, st_press_of_match);
43#define st_press_of_match NULL 44#define st_press_of_match NULL
44#endif 45#endif
45 46
47#ifdef CONFIG_ACPI
48static const struct acpi_device_id st_press_acpi_match[] = {
49 {"SNO9210", LPS22HB},
50 { },
51};
52MODULE_DEVICE_TABLE(acpi, st_press_acpi_match);
53#else
54#define st_press_acpi_match NULL
55#endif
56
57static const struct i2c_device_id st_press_id_table[] = {
58 { LPS001WP_PRESS_DEV_NAME, LPS001WP },
59 { LPS25H_PRESS_DEV_NAME, LPS25H },
60 { LPS331AP_PRESS_DEV_NAME, LPS331AP },
61 { LPS22HB_PRESS_DEV_NAME, LPS22HB },
62 {},
63};
64MODULE_DEVICE_TABLE(i2c, st_press_id_table);
65
46static int st_press_i2c_probe(struct i2c_client *client, 66static int st_press_i2c_probe(struct i2c_client *client,
47 const struct i2c_device_id *id) 67 const struct i2c_device_id *id)
48{ 68{
49 struct iio_dev *indio_dev; 69 struct iio_dev *indio_dev;
50 struct st_sensor_data *press_data; 70 struct st_sensor_data *press_data;
51 int err; 71 int ret;
52 72
53 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data)); 73 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
54 if (!indio_dev) 74 if (!indio_dev)
55 return -ENOMEM; 75 return -ENOMEM;
56 76
57 press_data = iio_priv(indio_dev); 77 press_data = iio_priv(indio_dev);
58 st_sensors_of_i2c_probe(client, st_press_of_match); 78
79 if (client->dev.of_node) {
80 st_sensors_of_i2c_probe(client, st_press_of_match);
81 } else if (ACPI_HANDLE(&client->dev)) {
82 ret = st_sensors_match_acpi_device(&client->dev);
83 if ((ret < 0) || (ret >= ST_PRESS_MAX))
84 return -ENODEV;
85
86 strncpy(client->name, st_press_id_table[ret].name,
87 sizeof(client->name));
88 client->name[sizeof(client->name) - 1] = '\0';
89 } else if (!id)
90 return -ENODEV;
59 91
60 st_sensors_i2c_configure(indio_dev, client, press_data); 92 st_sensors_i2c_configure(indio_dev, client, press_data);
61 93
62 err = st_press_common_probe(indio_dev); 94 ret = st_press_common_probe(indio_dev);
63 if (err < 0) 95 if (ret < 0)
64 return err; 96 return ret;
65 97
66 return 0; 98 return 0;
67} 99}
@@ -73,18 +105,11 @@ static int st_press_i2c_remove(struct i2c_client *client)
73 return 0; 105 return 0;
74} 106}
75 107
76static const struct i2c_device_id st_press_id_table[] = {
77 { LPS001WP_PRESS_DEV_NAME },
78 { LPS25H_PRESS_DEV_NAME },
79 { LPS331AP_PRESS_DEV_NAME },
80 {},
81};
82MODULE_DEVICE_TABLE(i2c, st_press_id_table);
83
84static struct i2c_driver st_press_driver = { 108static struct i2c_driver st_press_driver = {
85 .driver = { 109 .driver = {
86 .name = "st-press-i2c", 110 .name = "st-press-i2c",
87 .of_match_table = of_match_ptr(st_press_of_match), 111 .of_match_table = of_match_ptr(st_press_of_match),
112 .acpi_match_table = ACPI_PTR(st_press_acpi_match),
88 }, 113 },
89 .probe = st_press_i2c_probe, 114 .probe = st_press_i2c_probe,
90 .remove = st_press_i2c_remove, 115 .remove = st_press_i2c_remove,
diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index ef4c73db5b53..ab96cb7a0054 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -18,7 +18,7 @@ config AS3935
18 18
19endmenu 19endmenu
20 20
21menu "Proximity sensors" 21menu "Proximity and distance sensors"
22 22
23config LIDAR_LITE_V2 23config LIDAR_LITE_V2
24 tristate "PulsedLight LIDAR sensor" 24 tristate "PulsedLight LIDAR sensor"
@@ -45,4 +45,15 @@ config SX9500
45 To compile this driver as a module, choose M here: the 45 To compile this driver as a module, choose M here: the
46 module will be called sx9500. 46 module will be called sx9500.
47 47
48config SRF08
49 tristate "Devantech SRF08 ultrasonic ranger sensor"
50 depends on I2C
51 help
52 Say Y here to build a driver for Devantech SRF08 ultrasonic
53 ranger sensor. This driver can be used to measure the distance
54 of objects.
55
56 To compile this driver as a module, choose M here: the
57 module will be called srf08.
58
48endmenu 59endmenu
diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile
index 9aadd9a8ee99..e914c2a5dd49 100644
--- a/drivers/iio/proximity/Makefile
+++ b/drivers/iio/proximity/Makefile
@@ -5,4 +5,5 @@
5# When adding new entries keep the list in alphabetical order 5# When adding new entries keep the list in alphabetical order
6obj-$(CONFIG_AS3935) += as3935.o 6obj-$(CONFIG_AS3935) += as3935.o
7obj-$(CONFIG_LIDAR_LITE_V2) += pulsedlight-lidar-lite-v2.o 7obj-$(CONFIG_LIDAR_LITE_V2) += pulsedlight-lidar-lite-v2.o
8obj-$(CONFIG_SRF08) += srf08.o
8obj-$(CONFIG_SX9500) += sx9500.o 9obj-$(CONFIG_SX9500) += sx9500.o
diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
index 1fa9eefa0982..20c16a08c9d9 100644
--- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
+++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
@@ -326,12 +326,14 @@ static int lidar_remove(struct i2c_client *client)
326 326
327static const struct i2c_device_id lidar_id[] = { 327static const struct i2c_device_id lidar_id[] = {
328 {"lidar-lite-v2", 0}, 328 {"lidar-lite-v2", 0},
329 {"lidar-lite-v3", 0},
329 { }, 330 { },
330}; 331};
331MODULE_DEVICE_TABLE(i2c, lidar_id); 332MODULE_DEVICE_TABLE(i2c, lidar_id);
332 333
333static const struct of_device_id lidar_dt_ids[] = { 334static const struct of_device_id lidar_dt_ids[] = {
334 { .compatible = "pulsedlight,lidar-lite-v2" }, 335 { .compatible = "pulsedlight,lidar-lite-v2" },
336 { .compatible = "grmn,lidar-lite-v3" },
335 { } 337 { }
336}; 338};
337MODULE_DEVICE_TABLE(of, lidar_dt_ids); 339MODULE_DEVICE_TABLE(of, lidar_dt_ids);
diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c
new file mode 100644
index 000000000000..49316cbf7c60
--- /dev/null
+++ b/drivers/iio/proximity/srf08.c
@@ -0,0 +1,398 @@
1/*
2 * srf08.c - Support for Devantech SRF08 ultrasonic ranger
3 *
4 * Copyright (c) 2016 Andreas Klinger <ak@it-klinger.de>
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * For details about the device see:
11 * http://www.robot-electronics.co.uk/htm/srf08tech.html
12 */
13
14#include <linux/err.h>
15#include <linux/i2c.h>
16#include <linux/delay.h>
17#include <linux/module.h>
18#include <linux/bitops.h>
19#include <linux/iio/iio.h>
20#include <linux/iio/sysfs.h>
21
22/* registers of SRF08 device */
23#define SRF08_WRITE_COMMAND 0x00 /* Command Register */
24#define SRF08_WRITE_MAX_GAIN 0x01 /* Max Gain Register: 0 .. 31 */
25#define SRF08_WRITE_RANGE 0x02 /* Range Register: 0 .. 255 */
26#define SRF08_READ_SW_REVISION 0x00 /* Software Revision */
27#define SRF08_READ_LIGHT 0x01 /* Light Sensor during last echo */
28#define SRF08_READ_ECHO_1_HIGH 0x02 /* Range of first echo received */
29#define SRF08_READ_ECHO_1_LOW 0x03 /* Range of first echo received */
30
31#define SRF08_CMD_RANGING_CM 0x51 /* Ranging Mode - Result in cm */
32
33#define SRF08_DEFAULT_GAIN 1025 /* default analogue value of Gain */
34#define SRF08_DEFAULT_RANGE 6020 /* default value of Range in mm */
35
36struct srf08_data {
37 struct i2c_client *client;
38 int sensitivity; /* Gain */
39 int range_mm; /* max. Range in mm */
40 struct mutex lock;
41};
42
43/*
44 * in the documentation one can read about the "Gain" of the device
45 * which is used here for amplifying the signal and filtering out unwanted
46 * ones.
47 * But with ADC's this term is already used differently and that's why it
48 * is called "Sensitivity" here.
49 */
50static const int srf08_sensitivity[] = {
51 94, 97, 100, 103, 107, 110, 114, 118,
52 123, 128, 133, 139, 145, 152, 159, 168,
53 177, 187, 199, 212, 227, 245, 265, 288,
54 317, 352, 395, 450, 524, 626, 777, 1025 };
55
56static int srf08_read_ranging(struct srf08_data *data)
57{
58 struct i2c_client *client = data->client;
59 int ret, i;
60 int waittime;
61
62 mutex_lock(&data->lock);
63
64 ret = i2c_smbus_write_byte_data(data->client,
65 SRF08_WRITE_COMMAND, SRF08_CMD_RANGING_CM);
66 if (ret < 0) {
67 dev_err(&client->dev, "write command - err: %d\n", ret);
68 mutex_unlock(&data->lock);
69 return ret;
70 }
71
72 /*
73 * we read here until a correct version number shows up as
74 * suggested by the documentation
75 *
76 * with an ultrasonic speed of 343 m/s and a roundtrip of it
77 * sleep the expected duration and try to read from the device
78 * if nothing useful is read try it in a shorter grid
79 *
80 * polling for not more than 20 ms should be enough
81 */
82 waittime = 1 + data->range_mm / 172;
83 msleep(waittime);
84 for (i = 0; i < 4; i++) {
85 ret = i2c_smbus_read_byte_data(data->client,
86 SRF08_READ_SW_REVISION);
87
88 /* check if a valid version number is read */
89 if (ret < 255 && ret > 0)
90 break;
91 msleep(5);
92 }
93
94 if (ret >= 255 || ret <= 0) {
95 dev_err(&client->dev, "device not ready\n");
96 mutex_unlock(&data->lock);
97 return -EIO;
98 }
99
100 ret = i2c_smbus_read_word_swapped(data->client,
101 SRF08_READ_ECHO_1_HIGH);
102 if (ret < 0) {
103 dev_err(&client->dev, "cannot read distance: ret=%d\n", ret);
104 mutex_unlock(&data->lock);
105 return ret;
106 }
107
108 mutex_unlock(&data->lock);
109
110 return ret;
111}
112
113static int srf08_read_raw(struct iio_dev *indio_dev,
114 struct iio_chan_spec const *channel, int *val,
115 int *val2, long mask)
116{
117 struct srf08_data *data = iio_priv(indio_dev);
118 int ret;
119
120 if (channel->type != IIO_DISTANCE)
121 return -EINVAL;
122
123 switch (mask) {
124 case IIO_CHAN_INFO_RAW:
125 ret = srf08_read_ranging(data);
126 if (ret < 0)
127 return ret;
128 *val = ret;
129 return IIO_VAL_INT;
130 case IIO_CHAN_INFO_SCALE:
131 /* 1 LSB is 1 cm */
132 *val = 0;
133 *val2 = 10000;
134 return IIO_VAL_INT_PLUS_MICRO;
135 default:
136 return -EINVAL;
137 }
138}
139
140static ssize_t srf08_show_range_mm_available(struct device *dev,
141 struct device_attribute *attr, char *buf)
142{
143 return sprintf(buf, "[0.043 0.043 11.008]\n");
144}
145
146static IIO_DEVICE_ATTR(sensor_max_range_available, S_IRUGO,
147 srf08_show_range_mm_available, NULL, 0);
148
149static ssize_t srf08_show_range_mm(struct device *dev,
150 struct device_attribute *attr, char *buf)
151{
152 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
153 struct srf08_data *data = iio_priv(indio_dev);
154
155 return sprintf(buf, "%d.%03d\n", data->range_mm / 1000,
156 data->range_mm % 1000);
157}
158
159/*
160 * set the range of the sensor to an even multiple of 43 mm
161 * which corresponds to 1 LSB in the register
162 *
163 * register value corresponding range
164 * 0x00 43 mm
165 * 0x01 86 mm
166 * 0x02 129 mm
167 * ...
168 * 0xFF 11008 mm
169 */
170static ssize_t srf08_write_range_mm(struct srf08_data *data, unsigned int val)
171{
172 int ret;
173 struct i2c_client *client = data->client;
174 unsigned int mod;
175 u8 regval;
176
177 ret = val / 43 - 1;
178 mod = val % 43;
179
180 if (mod || (ret < 0) || (ret > 255))
181 return -EINVAL;
182
183 regval = ret;
184
185 mutex_lock(&data->lock);
186
187 ret = i2c_smbus_write_byte_data(client, SRF08_WRITE_RANGE, regval);
188 if (ret < 0) {
189 dev_err(&client->dev, "write_range - err: %d\n", ret);
190 mutex_unlock(&data->lock);
191 return ret;
192 }
193
194 data->range_mm = val;
195
196 mutex_unlock(&data->lock);
197
198 return 0;
199}
200
201static ssize_t srf08_store_range_mm(struct device *dev,
202 struct device_attribute *attr,
203 const char *buf, size_t len)
204{
205 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
206 struct srf08_data *data = iio_priv(indio_dev);
207 int ret;
208 int integer, fract;
209
210 ret = iio_str_to_fixpoint(buf, 100, &integer, &fract);
211 if (ret)
212 return ret;
213
214 ret = srf08_write_range_mm(data, integer * 1000 + fract);
215 if (ret < 0)
216 return ret;
217
218 return len;
219}
220
221static IIO_DEVICE_ATTR(sensor_max_range, S_IRUGO | S_IWUSR,
222 srf08_show_range_mm, srf08_store_range_mm, 0);
223
224static ssize_t srf08_show_sensitivity_available(struct device *dev,
225 struct device_attribute *attr, char *buf)
226{
227 int i, len = 0;
228
229 for (i = 0; i < ARRAY_SIZE(srf08_sensitivity); i++)
230 len += sprintf(buf + len, "%d ", srf08_sensitivity[i]);
231
232 len += sprintf(buf + len, "\n");
233
234 return len;
235}
236
237static IIO_DEVICE_ATTR(sensor_sensitivity_available, S_IRUGO,
238 srf08_show_sensitivity_available, NULL, 0);
239
240static ssize_t srf08_show_sensitivity(struct device *dev,
241 struct device_attribute *attr, char *buf)
242{
243 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
244 struct srf08_data *data = iio_priv(indio_dev);
245 int len;
246
247 len = sprintf(buf, "%d\n", data->sensitivity);
248
249 return len;
250}
251
252static ssize_t srf08_write_sensitivity(struct srf08_data *data,
253 unsigned int val)
254{
255 struct i2c_client *client = data->client;
256 int ret, i;
257 u8 regval;
258
259 for (i = 0; i < ARRAY_SIZE(srf08_sensitivity); i++)
260 if (val == srf08_sensitivity[i]) {
261 regval = i;
262 break;
263 }
264
265 if (i >= ARRAY_SIZE(srf08_sensitivity))
266 return -EINVAL;
267
268 mutex_lock(&data->lock);
269
270 ret = i2c_smbus_write_byte_data(client,
271 SRF08_WRITE_MAX_GAIN, regval);
272 if (ret < 0) {
273 dev_err(&client->dev, "write_sensitivity - err: %d\n", ret);
274 mutex_unlock(&data->lock);
275 return ret;
276 }
277
278 data->sensitivity = val;
279
280 mutex_unlock(&data->lock);
281
282 return 0;
283}
284
285static ssize_t srf08_store_sensitivity(struct device *dev,
286 struct device_attribute *attr,
287 const char *buf, size_t len)
288{
289 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
290 struct srf08_data *data = iio_priv(indio_dev);
291 int ret;
292 unsigned int val;
293
294 ret = kstrtouint(buf, 10, &val);
295 if (ret)
296 return ret;
297
298 ret = srf08_write_sensitivity(data, val);
299 if (ret < 0)
300 return ret;
301
302 return len;
303}
304
305static IIO_DEVICE_ATTR(sensor_sensitivity, S_IRUGO | S_IWUSR,
306 srf08_show_sensitivity, srf08_store_sensitivity, 0);
307
308static struct attribute *srf08_attributes[] = {
309 &iio_dev_attr_sensor_max_range.dev_attr.attr,
310 &iio_dev_attr_sensor_max_range_available.dev_attr.attr,
311 &iio_dev_attr_sensor_sensitivity.dev_attr.attr,
312 &iio_dev_attr_sensor_sensitivity_available.dev_attr.attr,
313 NULL,
314};
315
316static const struct attribute_group srf08_attribute_group = {
317 .attrs = srf08_attributes,
318};
319
320static const struct iio_chan_spec srf08_channels[] = {
321 {
322 .type = IIO_DISTANCE,
323 .info_mask_separate =
324 BIT(IIO_CHAN_INFO_RAW) |
325 BIT(IIO_CHAN_INFO_SCALE),
326 },
327};
328
329static const struct iio_info srf08_info = {
330 .read_raw = srf08_read_raw,
331 .attrs = &srf08_attribute_group,
332 .driver_module = THIS_MODULE,
333};
334
335static int srf08_probe(struct i2c_client *client,
336 const struct i2c_device_id *id)
337{
338 struct iio_dev *indio_dev;
339 struct srf08_data *data;
340 int ret;
341
342 if (!i2c_check_functionality(client->adapter,
343 I2C_FUNC_SMBUS_READ_BYTE_DATA |
344 I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
345 I2C_FUNC_SMBUS_READ_WORD_DATA))
346 return -ENODEV;
347
348 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
349 if (!indio_dev)
350 return -ENOMEM;
351
352 data = iio_priv(indio_dev);
353 i2c_set_clientdata(client, indio_dev);
354 data->client = client;
355
356 indio_dev->name = "srf08";
357 indio_dev->dev.parent = &client->dev;
358 indio_dev->modes = INDIO_DIRECT_MODE;
359 indio_dev->info = &srf08_info;
360 indio_dev->channels = srf08_channels;
361 indio_dev->num_channels = ARRAY_SIZE(srf08_channels);
362
363 mutex_init(&data->lock);
364
365 /*
366 * set default values of device here
367 * these register values cannot be read from the hardware
368 * therefore set driver specific default values
369 */
370 ret = srf08_write_range_mm(data, SRF08_DEFAULT_RANGE);
371 if (ret < 0)
372 return ret;
373
374 ret = srf08_write_sensitivity(data, SRF08_DEFAULT_GAIN);
375 if (ret < 0)
376 return ret;
377
378 return devm_iio_device_register(&client->dev, indio_dev);
379}
380
381static const struct i2c_device_id srf08_id[] = {
382 { "srf08", 0 },
383 { }
384};
385MODULE_DEVICE_TABLE(i2c, srf08_id);
386
387static struct i2c_driver srf08_driver = {
388 .driver = {
389 .name = "srf08",
390 },
391 .probe = srf08_probe,
392 .id_table = srf08_id,
393};
394module_i2c_driver(srf08_driver);
395
396MODULE_AUTHOR("Andreas Klinger <ak@it-klinger.de>");
397MODULE_DESCRIPTION("Devantech SRF08 ultrasonic ranger driver");
398MODULE_LICENSE("GPL");
diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c
index 1f06282ec793..9ea147f1a50d 100644
--- a/drivers/iio/proximity/sx9500.c
+++ b/drivers/iio/proximity/sx9500.c
@@ -387,14 +387,18 @@ static int sx9500_read_raw(struct iio_dev *indio_dev,
387 int *val, int *val2, long mask) 387 int *val, int *val2, long mask)
388{ 388{
389 struct sx9500_data *data = iio_priv(indio_dev); 389 struct sx9500_data *data = iio_priv(indio_dev);
390 int ret;
390 391
391 switch (chan->type) { 392 switch (chan->type) {
392 case IIO_PROXIMITY: 393 case IIO_PROXIMITY:
393 switch (mask) { 394 switch (mask) {
394 case IIO_CHAN_INFO_RAW: 395 case IIO_CHAN_INFO_RAW:
395 if (iio_buffer_enabled(indio_dev)) 396 ret = iio_device_claim_direct_mode(indio_dev);
396 return -EBUSY; 397 if (ret)
397 return sx9500_read_proximity(data, chan, val); 398 return ret;
399 ret = sx9500_read_proximity(data, chan, val);
400 iio_device_release_direct_mode(indio_dev);
401 return ret;
398 case IIO_CHAN_INFO_SAMP_FREQ: 402 case IIO_CHAN_INFO_SAMP_FREQ:
399 return sx9500_read_samp_freq(data, val, val2); 403 return sx9500_read_samp_freq(data, val, val2);
400 default: 404 default:
diff --git a/drivers/iio/temperature/Kconfig b/drivers/iio/temperature/Kconfig
index 5ea77a7e261d..3089e8d0a32d 100644
--- a/drivers/iio/temperature/Kconfig
+++ b/drivers/iio/temperature/Kconfig
@@ -39,6 +39,16 @@ config TMP006
39 This driver can also be built as a module. If so, the module will 39 This driver can also be built as a module. If so, the module will
40 be called tmp006. 40 be called tmp006.
41 41
42config TMP007
43 tristate "TMP007 infrared thermopile sensor with Integrated Math Engine"
44 depends on I2C
45 help
46 If you say yes here you get support for the Texas Instruments
47 TMP007 infrared thermopile sensor with Integrated Math Engine.
48
49 This driver can also be built as a module. If so, the module will
50 be called tmp007.
51
42config TSYS01 52config TSYS01
43 tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection" 53 tristate "Measurement Specialties TSYS01 temperature sensor using I2C bus connection"
44 depends on I2C 54 depends on I2C
diff --git a/drivers/iio/temperature/Makefile b/drivers/iio/temperature/Makefile
index 78c3de0dc3f0..4c4377480726 100644
--- a/drivers/iio/temperature/Makefile
+++ b/drivers/iio/temperature/Makefile
@@ -5,5 +5,6 @@
5obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o 5obj-$(CONFIG_MAXIM_THERMOCOUPLE) += maxim_thermocouple.o
6obj-$(CONFIG_MLX90614) += mlx90614.o 6obj-$(CONFIG_MLX90614) += mlx90614.o
7obj-$(CONFIG_TMP006) += tmp006.o 7obj-$(CONFIG_TMP006) += tmp006.o
8obj-$(CONFIG_TMP007) += tmp007.o
8obj-$(CONFIG_TSYS01) += tsys01.o 9obj-$(CONFIG_TSYS01) += tsys01.o
9obj-$(CONFIG_TSYS02D) += tsys02d.o 10obj-$(CONFIG_TSYS02D) += tsys02d.o
diff --git a/drivers/iio/temperature/tmp007.c b/drivers/iio/temperature/tmp007.c
new file mode 100644
index 000000000000..f04d0d1f6ac8
--- /dev/null
+++ b/drivers/iio/temperature/tmp007.c
@@ -0,0 +1,345 @@
1/*
2 * tmp007.c - Support for TI TMP007 IR thermopile sensor with integrated math engine
3 *
4 * Copyright (c) 2017 Manivannan Sadhasivam <manivannanece23@gmail.com>
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * Driver for the Texas Instruments I2C 16-bit IR thermopile sensor
11 *
12 * (7-bit I2C slave address (0x40 - 0x47), changeable via ADR pins)
13 *
14 * Note: This driver assumes that the sensor has been calibrated beforehand
15 *
16 * TODO: ALERT irq, limit threshold events
17 *
18 */
19
20#include <linux/err.h>
21#include <linux/i2c.h>
22#include <linux/delay.h>
23#include <linux/module.h>
24#include <linux/pm.h>
25#include <linux/bitops.h>
26#include <linux/of.h>
27
28#include <linux/iio/iio.h>
29#include <linux/iio/sysfs.h>
30
31#define TMP007_TDIE 0x01
32#define TMP007_CONFIG 0x02
33#define TMP007_TOBJECT 0x03
34#define TMP007_STATUS 0x04
35#define TMP007_STATUS_MASK 0x05
36#define TMP007_MANUFACTURER_ID 0x1e
37#define TMP007_DEVICE_ID 0x1f
38
39#define TMP007_CONFIG_CONV_EN BIT(12)
40#define TMP007_CONFIG_COMP_EN BIT(5)
41#define TMP007_CONFIG_TC_EN BIT(6)
42#define TMP007_CONFIG_CR_MASK GENMASK(11, 9)
43#define TMP007_CONFIG_CR_SHIFT 9
44
45#define TMP007_STATUS_CONV_READY BIT(14)
46#define TMP007_STATUS_DATA_VALID BIT(9)
47
48#define TMP007_MANUFACTURER_MAGIC 0x5449
49#define TMP007_DEVICE_MAGIC 0x0078
50
51#define TMP007_TEMP_SHIFT 2
52
53struct tmp007_data {
54 struct i2c_client *client;
55 u16 config;
56};
57
58static const int tmp007_avgs[5][2] = { {4, 0}, {2, 0}, {1, 0},
59 {0, 500000}, {0, 250000} };
60
61static int tmp007_read_temperature(struct tmp007_data *data, u8 reg)
62{
63 s32 ret;
64 int tries = 50;
65
66 while (tries-- > 0) {
67 ret = i2c_smbus_read_word_swapped(data->client,
68 TMP007_STATUS);
69 if (ret < 0)
70 return ret;
71 if ((ret & TMP007_STATUS_CONV_READY) &&
72 !(ret & TMP007_STATUS_DATA_VALID))
73 break;
74 msleep(100);
75 }
76
77 if (tries < 0)
78 return -EIO;
79
80 return i2c_smbus_read_word_swapped(data->client, reg);
81}
82
83static int tmp007_powerdown(struct tmp007_data *data)
84{
85 return i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG,
86 data->config & ~TMP007_CONFIG_CONV_EN);
87}
88
89static int tmp007_read_raw(struct iio_dev *indio_dev,
90 struct iio_chan_spec const *channel, int *val,
91 int *val2, long mask)
92{
93 struct tmp007_data *data = iio_priv(indio_dev);
94 s32 ret;
95 int conv_rate;
96
97 switch (mask) {
98 case IIO_CHAN_INFO_RAW:
99 switch (channel->channel2) {
100 case IIO_MOD_TEMP_AMBIENT: /* LSB: 0.03125 degree Celsius */
101 ret = i2c_smbus_read_word_swapped(data->client, TMP007_TDIE);
102 if (ret < 0)
103 return ret;
104 break;
105 case IIO_MOD_TEMP_OBJECT:
106 ret = tmp007_read_temperature(data, TMP007_TOBJECT);
107 if (ret < 0)
108 return ret;
109 break;
110 default:
111 return -EINVAL;
112 }
113
114 *val = sign_extend32(ret, 15) >> TMP007_TEMP_SHIFT;
115
116 return IIO_VAL_INT;
117 case IIO_CHAN_INFO_SCALE:
118 *val = 31;
119 *val2 = 250000;
120
121 return IIO_VAL_INT_PLUS_MICRO;
122 case IIO_CHAN_INFO_SAMP_FREQ:
123 conv_rate = (data->config & TMP007_CONFIG_CR_MASK)
124 >> TMP007_CONFIG_CR_SHIFT;
125 *val = tmp007_avgs[conv_rate][0];
126 *val2 = tmp007_avgs[conv_rate][1];
127
128 return IIO_VAL_INT_PLUS_MICRO;
129 default:
130 return -EINVAL;
131 }
132}
133
134static int tmp007_write_raw(struct iio_dev *indio_dev,
135 struct iio_chan_spec const *channel, int val,
136 int val2, long mask)
137{
138 struct tmp007_data *data = iio_priv(indio_dev);
139 int i;
140 u16 tmp;
141
142 if (mask == IIO_CHAN_INFO_SAMP_FREQ) {
143 for (i = 0; i < ARRAY_SIZE(tmp007_avgs); i++) {
144 if ((val == tmp007_avgs[i][0]) &&
145 (val2 == tmp007_avgs[i][1])) {
146 tmp = data->config & ~TMP007_CONFIG_CR_MASK;
147 tmp |= (i << TMP007_CONFIG_CR_SHIFT);
148
149 return i2c_smbus_write_word_swapped(data->client,
150 TMP007_CONFIG,
151 data->config = tmp);
152 }
153 }
154 }
155
156 return -EINVAL;
157}
158
159static IIO_CONST_ATTR(sampling_frequency_available, "4 2 1 0.5 0.25");
160
161static struct attribute *tmp007_attributes[] = {
162 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
163 NULL
164};
165
166static const struct attribute_group tmp007_attribute_group = {
167 .attrs = tmp007_attributes,
168};
169
170static const struct iio_chan_spec tmp007_channels[] = {
171 {
172 .type = IIO_TEMP,
173 .modified = 1,
174 .channel2 = IIO_MOD_TEMP_AMBIENT,
175 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
176 BIT(IIO_CHAN_INFO_SCALE),
177 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
178 },
179 {
180 .type = IIO_TEMP,
181 .modified = 1,
182 .channel2 = IIO_MOD_TEMP_OBJECT,
183 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
184 BIT(IIO_CHAN_INFO_SCALE),
185 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
186 }
187};
188
189static const struct iio_info tmp007_info = {
190 .read_raw = tmp007_read_raw,
191 .write_raw = tmp007_write_raw,
192 .attrs = &tmp007_attribute_group,
193 .driver_module = THIS_MODULE,
194};
195
196static bool tmp007_identify(struct i2c_client *client)
197{
198 int manf_id, dev_id;
199
200 manf_id = i2c_smbus_read_word_swapped(client, TMP007_MANUFACTURER_ID);
201 if (manf_id < 0)
202 return false;
203
204 dev_id = i2c_smbus_read_word_swapped(client, TMP007_DEVICE_ID);
205 if (dev_id < 0)
206 return false;
207
208 return (manf_id == TMP007_MANUFACTURER_MAGIC && dev_id == TMP007_DEVICE_MAGIC);
209}
210
211static int tmp007_probe(struct i2c_client *client,
212 const struct i2c_device_id *tmp007_id)
213{
214 struct tmp007_data *data;
215 struct iio_dev *indio_dev;
216 int ret;
217 u16 status;
218
219 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA))
220 return -EOPNOTSUPP;
221
222 if (!tmp007_identify(client)) {
223 dev_err(&client->dev, "TMP007 not found\n");
224 return -ENODEV;
225 }
226
227 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
228 if (!indio_dev)
229 return -ENOMEM;
230
231 data = iio_priv(indio_dev);
232 i2c_set_clientdata(client, indio_dev);
233 data->client = client;
234
235 indio_dev->dev.parent = &client->dev;
236 indio_dev->name = "tmp007";
237 indio_dev->modes = INDIO_DIRECT_MODE;
238 indio_dev->info = &tmp007_info;
239
240 indio_dev->channels = tmp007_channels;
241 indio_dev->num_channels = ARRAY_SIZE(tmp007_channels);
242
243 /*
244 * Set Configuration register:
245 * 1. Conversion ON
246 * 2. Comparator mode
247 * 3. Transient correction enable
248 */
249
250 ret = i2c_smbus_read_word_swapped(data->client, TMP007_CONFIG);
251 if (ret < 0)
252 return ret;
253
254 data->config = ret;
255 data->config |= (TMP007_CONFIG_CONV_EN | TMP007_CONFIG_COMP_EN | TMP007_CONFIG_TC_EN);
256
257 ret = i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG,
258 data->config);
259 if (ret < 0)
260 return ret;
261
262 /*
263 * Set Status Mask register:
264 * 1. Conversion ready enable
265 * 2. Data valid enable
266 */
267
268 ret = i2c_smbus_read_word_swapped(data->client, TMP007_STATUS_MASK);
269 if (ret < 0)
270 goto error_powerdown;
271
272 status = ret;
273 status |= (TMP007_STATUS_CONV_READY | TMP007_STATUS_DATA_VALID);
274
275 ret = i2c_smbus_write_word_swapped(data->client, TMP007_STATUS_MASK, status);
276 if (ret < 0)
277 goto error_powerdown;
278
279 return iio_device_register(indio_dev);
280
281error_powerdown:
282 tmp007_powerdown(data);
283
284 return ret;
285}
286
287static int tmp007_remove(struct i2c_client *client)
288{
289 struct iio_dev *indio_dev = i2c_get_clientdata(client);
290 struct tmp007_data *data = iio_priv(indio_dev);
291
292 iio_device_unregister(indio_dev);
293 tmp007_powerdown(data);
294
295 return 0;
296}
297
298#ifdef CONFIG_PM_SLEEP
299static int tmp007_suspend(struct device *dev)
300{
301 struct tmp007_data *data = iio_priv(i2c_get_clientdata(
302 to_i2c_client(dev)));
303
304 return tmp007_powerdown(data);
305}
306
307static int tmp007_resume(struct device *dev)
308{
309 struct tmp007_data *data = iio_priv(i2c_get_clientdata(
310 to_i2c_client(dev)));
311
312 return i2c_smbus_write_word_swapped(data->client, TMP007_CONFIG,
313 data->config | TMP007_CONFIG_CONV_EN);
314}
315#endif
316
317static SIMPLE_DEV_PM_OPS(tmp007_pm_ops, tmp007_suspend, tmp007_resume);
318
319static const struct of_device_id tmp007_of_match[] = {
320 { .compatible = "ti,tmp007", },
321 { },
322};
323MODULE_DEVICE_TABLE(of, tmp007_of_match);
324
325static const struct i2c_device_id tmp007_id[] = {
326 { "tmp007", 0 },
327 { }
328};
329MODULE_DEVICE_TABLE(i2c, tmp007_id);
330
331static struct i2c_driver tmp007_driver = {
332 .driver = {
333 .name = "tmp007",
334 .of_match_table = of_match_ptr(tmp007_of_match),
335 .pm = &tmp007_pm_ops,
336 },
337 .probe = tmp007_probe,
338 .remove = tmp007_remove,
339 .id_table = tmp007_id,
340};
341module_i2c_driver(tmp007_driver);
342
343MODULE_AUTHOR("Manivannan Sadhasivam <manivannanece23@gmail.com>");
344MODULE_DESCRIPTION("TI TMP007 IR thermopile sensor driver");
345MODULE_LICENSE("GPL");
diff --git a/drivers/iio/trigger/Kconfig b/drivers/iio/trigger/Kconfig
index 809b2e7d58fa..e4d4e63434db 100644
--- a/drivers/iio/trigger/Kconfig
+++ b/drivers/iio/trigger/Kconfig
@@ -24,6 +24,15 @@ config IIO_INTERRUPT_TRIGGER
24 To compile this driver as a module, choose M here: the 24 To compile this driver as a module, choose M here: the
25 module will be called iio-trig-interrupt. 25 module will be called iio-trig-interrupt.
26 26
27config IIO_STM32_TIMER_TRIGGER
28 tristate "STM32 Timer Trigger"
29 depends on (ARCH_STM32 && OF && MFD_STM32_TIMERS) || COMPILE_TEST
30 help
31 Select this option to enable STM32 Timer Trigger
32
33 To compile this driver as a module, choose M here: the
34 module will be called stm32-timer-trigger.
35
27config IIO_TIGHTLOOP_TRIGGER 36config IIO_TIGHTLOOP_TRIGGER
28 tristate "A kthread based hammering loop trigger" 37 tristate "A kthread based hammering loop trigger"
29 depends on IIO_SW_TRIGGER 38 depends on IIO_SW_TRIGGER
diff --git a/drivers/iio/trigger/Makefile b/drivers/iio/trigger/Makefile
index aab4dc23303d..5c4ecd380653 100644
--- a/drivers/iio/trigger/Makefile
+++ b/drivers/iio/trigger/Makefile
@@ -6,5 +6,6 @@
6 6
7obj-$(CONFIG_IIO_HRTIMER_TRIGGER) += iio-trig-hrtimer.o 7obj-$(CONFIG_IIO_HRTIMER_TRIGGER) += iio-trig-hrtimer.o
8obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o 8obj-$(CONFIG_IIO_INTERRUPT_TRIGGER) += iio-trig-interrupt.o
9obj-$(CONFIG_IIO_STM32_TIMER_TRIGGER) += stm32-timer-trigger.o
9obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o 10obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o
10obj-$(CONFIG_IIO_TIGHTLOOP_TRIGGER) += iio-trig-loop.o 11obj-$(CONFIG_IIO_TIGHTLOOP_TRIGGER) += iio-trig-loop.o
diff --git a/drivers/iio/trigger/iio-trig-interrupt.c b/drivers/iio/trigger/iio-trig-interrupt.c
index 572bc6f02ca8..e18f12b74610 100644
--- a/drivers/iio/trigger/iio-trig-interrupt.c
+++ b/drivers/iio/trigger/iio-trig-interrupt.c
@@ -58,7 +58,7 @@ static int iio_interrupt_trigger_probe(struct platform_device *pdev)
58 trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL); 58 trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL);
59 if (!trig_info) { 59 if (!trig_info) {
60 ret = -ENOMEM; 60 ret = -ENOMEM;
61 goto error_put_trigger; 61 goto error_free_trigger;
62 } 62 }
63 iio_trigger_set_drvdata(trig, trig_info); 63 iio_trigger_set_drvdata(trig, trig_info);
64 trig_info->irq = irq; 64 trig_info->irq = irq;
@@ -83,8 +83,8 @@ error_release_irq:
83 free_irq(irq, trig); 83 free_irq(irq, trig);
84error_free_trig_info: 84error_free_trig_info:
85 kfree(trig_info); 85 kfree(trig_info);
86error_put_trigger: 86error_free_trigger:
87 iio_trigger_put(trig); 87 iio_trigger_free(trig);
88error_ret: 88error_ret:
89 return ret; 89 return ret;
90} 90}
@@ -99,7 +99,7 @@ static int iio_interrupt_trigger_remove(struct platform_device *pdev)
99 iio_trigger_unregister(trig); 99 iio_trigger_unregister(trig);
100 free_irq(trig_info->irq, trig); 100 free_irq(trig_info->irq, trig);
101 kfree(trig_info); 101 kfree(trig_info);
102 iio_trigger_put(trig); 102 iio_trigger_free(trig);
103 103
104 return 0; 104 return 0;
105} 105}
diff --git a/drivers/iio/trigger/iio-trig-sysfs.c b/drivers/iio/trigger/iio-trig-sysfs.c
index 3dfab2bc6d69..202e8b89caf2 100644
--- a/drivers/iio/trigger/iio-trig-sysfs.c
+++ b/drivers/iio/trigger/iio-trig-sysfs.c
@@ -174,7 +174,7 @@ static int iio_sysfs_trigger_probe(int id)
174 return 0; 174 return 0;
175 175
176out2: 176out2:
177 iio_trigger_put(t->trig); 177 iio_trigger_free(t->trig);
178free_t: 178free_t:
179 kfree(t); 179 kfree(t);
180out1: 180out1:
diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c
new file mode 100644
index 000000000000..994b96d19750
--- /dev/null
+++ b/drivers/iio/trigger/stm32-timer-trigger.c
@@ -0,0 +1,342 @@
1/*
2 * Copyright (C) STMicroelectronics 2016
3 *
4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
5 *
6 * License terms: GNU General Public License (GPL), version 2
7 */
8
9#include <linux/iio/iio.h>
10#include <linux/iio/sysfs.h>
11#include <linux/iio/timer/stm32-timer-trigger.h>
12#include <linux/iio/trigger.h>
13#include <linux/mfd/stm32-timers.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16
17#define MAX_TRIGGERS 6
18
19/* List the triggers created by each timer */
20static const void *triggers_table[][MAX_TRIGGERS] = {
21 { TIM1_TRGO, TIM1_CH1, TIM1_CH2, TIM1_CH3, TIM1_CH4,},
22 { TIM2_TRGO, TIM2_CH1, TIM2_CH2, TIM2_CH3, TIM2_CH4,},
23 { TIM3_TRGO, TIM3_CH1, TIM3_CH2, TIM3_CH3, TIM3_CH4,},
24 { TIM4_TRGO, TIM4_CH1, TIM4_CH2, TIM4_CH3, TIM4_CH4,},
25 { TIM5_TRGO, TIM5_CH1, TIM5_CH2, TIM5_CH3, TIM5_CH4,},
26 { TIM6_TRGO,},
27 { TIM7_TRGO,},
28 { TIM8_TRGO, TIM8_CH1, TIM8_CH2, TIM8_CH3, TIM8_CH4,},
29 { TIM9_TRGO, TIM9_CH1, TIM9_CH2,},
30 { }, /* timer 10 */
31 { }, /* timer 11 */
32 { TIM12_TRGO, TIM12_CH1, TIM12_CH2,},
33};
34
35struct stm32_timer_trigger {
36 struct device *dev;
37 struct regmap *regmap;
38 struct clk *clk;
39 u32 max_arr;
40 const void *triggers;
41};
42
43static int stm32_timer_start(struct stm32_timer_trigger *priv,
44 unsigned int frequency)
45{
46 unsigned long long prd, div;
47 int prescaler = 0;
48 u32 ccer, cr1;
49
50 /* Period and prescaler values depends of clock rate */
51 div = (unsigned long long)clk_get_rate(priv->clk);
52
53 do_div(div, frequency);
54
55 prd = div;
56
57 /*
58 * Increase prescaler value until we get a result that fit
59 * with auto reload register maximum value.
60 */
61 while (div > priv->max_arr) {
62 prescaler++;
63 div = prd;
64 do_div(div, (prescaler + 1));
65 }
66 prd = div;
67
68 if (prescaler > MAX_TIM_PSC) {
69 dev_err(priv->dev, "prescaler exceeds the maximum value\n");
70 return -EINVAL;
71 }
72
73 /* Check if nobody else use the timer */
74 regmap_read(priv->regmap, TIM_CCER, &ccer);
75 if (ccer & TIM_CCER_CCXE)
76 return -EBUSY;
77
78 regmap_read(priv->regmap, TIM_CR1, &cr1);
79 if (!(cr1 & TIM_CR1_CEN))
80 clk_enable(priv->clk);
81
82 regmap_write(priv->regmap, TIM_PSC, prescaler);
83 regmap_write(priv->regmap, TIM_ARR, prd - 1);
84 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
85
86 /* Force master mode to update mode */
87 regmap_update_bits(priv->regmap, TIM_CR2, TIM_CR2_MMS, 0x20);
88
89 /* Make sure that registers are updated */
90 regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
91
92 /* Enable controller */
93 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, TIM_CR1_CEN);
94
95 return 0;
96}
97
98static void stm32_timer_stop(struct stm32_timer_trigger *priv)
99{
100 u32 ccer, cr1;
101
102 regmap_read(priv->regmap, TIM_CCER, &ccer);
103 if (ccer & TIM_CCER_CCXE)
104 return;
105
106 regmap_read(priv->regmap, TIM_CR1, &cr1);
107 if (cr1 & TIM_CR1_CEN)
108 clk_disable(priv->clk);
109
110 /* Stop timer */
111 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
112 regmap_write(priv->regmap, TIM_PSC, 0);
113 regmap_write(priv->regmap, TIM_ARR, 0);
114
115 /* Make sure that registers are updated */
116 regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
117}
118
119static ssize_t stm32_tt_store_frequency(struct device *dev,
120 struct device_attribute *attr,
121 const char *buf, size_t len)
122{
123 struct iio_trigger *trig = to_iio_trigger(dev);
124 struct stm32_timer_trigger *priv = iio_trigger_get_drvdata(trig);
125 unsigned int freq;
126 int ret;
127
128 ret = kstrtouint(buf, 10, &freq);
129 if (ret)
130 return ret;
131
132 if (freq == 0) {
133 stm32_timer_stop(priv);
134 } else {
135 ret = stm32_timer_start(priv, freq);
136 if (ret)
137 return ret;
138 }
139
140 return len;
141}
142
143static ssize_t stm32_tt_read_frequency(struct device *dev,
144 struct device_attribute *attr, char *buf)
145{
146 struct iio_trigger *trig = to_iio_trigger(dev);
147 struct stm32_timer_trigger *priv = iio_trigger_get_drvdata(trig);
148 u32 psc, arr, cr1;
149 unsigned long long freq = 0;
150
151 regmap_read(priv->regmap, TIM_CR1, &cr1);
152 regmap_read(priv->regmap, TIM_PSC, &psc);
153 regmap_read(priv->regmap, TIM_ARR, &arr);
154
155 if (psc && arr && (cr1 & TIM_CR1_CEN)) {
156 freq = (unsigned long long)clk_get_rate(priv->clk);
157 do_div(freq, psc);
158 do_div(freq, arr);
159 }
160
161 return sprintf(buf, "%d\n", (unsigned int)freq);
162}
163
164static IIO_DEV_ATTR_SAMP_FREQ(0660,
165 stm32_tt_read_frequency,
166 stm32_tt_store_frequency);
167
168static char *master_mode_table[] = {
169 "reset",
170 "enable",
171 "update",
172 "compare_pulse",
173 "OC1REF",
174 "OC2REF",
175 "OC3REF",
176 "OC4REF"
177};
178
179static ssize_t stm32_tt_show_master_mode(struct device *dev,
180 struct device_attribute *attr,
181 char *buf)
182{
183 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
184 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
185 u32 cr2;
186
187 regmap_read(priv->regmap, TIM_CR2, &cr2);
188 cr2 = (cr2 & TIM_CR2_MMS) >> TIM_CR2_MMS_SHIFT;
189
190 return snprintf(buf, PAGE_SIZE, "%s\n", master_mode_table[cr2]);
191}
192
193static ssize_t stm32_tt_store_master_mode(struct device *dev,
194 struct device_attribute *attr,
195 const char *buf, size_t len)
196{
197 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
198 struct stm32_timer_trigger *priv = iio_priv(indio_dev);
199 int i;
200
201 for (i = 0; i < ARRAY_SIZE(master_mode_table); i++) {
202 if (!strncmp(master_mode_table[i], buf,
203 strlen(master_mode_table[i]))) {
204 regmap_update_bits(priv->regmap, TIM_CR2,
205 TIM_CR2_MMS, i << TIM_CR2_MMS_SHIFT);
206 /* Make sure that registers are updated */
207 regmap_update_bits(priv->regmap, TIM_EGR,
208 TIM_EGR_UG, TIM_EGR_UG);
209 return len;
210 }
211 }
212
213 return -EINVAL;
214}
215
216static IIO_CONST_ATTR(master_mode_available,
217 "reset enable update compare_pulse OC1REF OC2REF OC3REF OC4REF");
218
219static IIO_DEVICE_ATTR(master_mode, 0660,
220 stm32_tt_show_master_mode,
221 stm32_tt_store_master_mode,
222 0);
223
224static struct attribute *stm32_trigger_attrs[] = {
225 &iio_dev_attr_sampling_frequency.dev_attr.attr,
226 &iio_dev_attr_master_mode.dev_attr.attr,
227 &iio_const_attr_master_mode_available.dev_attr.attr,
228 NULL,
229};
230
231static const struct attribute_group stm32_trigger_attr_group = {
232 .attrs = stm32_trigger_attrs,
233};
234
235static const struct attribute_group *stm32_trigger_attr_groups[] = {
236 &stm32_trigger_attr_group,
237 NULL,
238};
239
240static const struct iio_trigger_ops timer_trigger_ops = {
241 .owner = THIS_MODULE,
242};
243
244static int stm32_setup_iio_triggers(struct stm32_timer_trigger *priv)
245{
246 int ret;
247 const char * const *cur = priv->triggers;
248
249 while (cur && *cur) {
250 struct iio_trigger *trig;
251
252 trig = devm_iio_trigger_alloc(priv->dev, "%s", *cur);
253 if (!trig)
254 return -ENOMEM;
255
256 trig->dev.parent = priv->dev->parent;
257 trig->ops = &timer_trigger_ops;
258
259 /*
260 * sampling frequency and master mode attributes
261 * should only be available on trgo trigger which
262 * is always the first in the list.
263 */
264 if (cur == priv->triggers)
265 trig->dev.groups = stm32_trigger_attr_groups;
266
267 iio_trigger_set_drvdata(trig, priv);
268
269 ret = devm_iio_trigger_register(priv->dev, trig);
270 if (ret)
271 return ret;
272 cur++;
273 }
274
275 return 0;
276}
277
278/**
279 * is_stm32_timer_trigger
280 * @trig: trigger to be checked
281 *
282 * return true if the trigger is a valid stm32 iio timer trigger
283 * either return false
284 */
285bool is_stm32_timer_trigger(struct iio_trigger *trig)
286{
287 return (trig->ops == &timer_trigger_ops);
288}
289EXPORT_SYMBOL(is_stm32_timer_trigger);
290
291static int stm32_timer_trigger_probe(struct platform_device *pdev)
292{
293 struct device *dev = &pdev->dev;
294 struct stm32_timer_trigger *priv;
295 struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
296 unsigned int index;
297 int ret;
298
299 if (of_property_read_u32(dev->of_node, "reg", &index))
300 return -EINVAL;
301
302 if (index >= ARRAY_SIZE(triggers_table))
303 return -EINVAL;
304
305 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
306
307 if (!priv)
308 return -ENOMEM;
309
310 priv->dev = dev;
311 priv->regmap = ddata->regmap;
312 priv->clk = ddata->clk;
313 priv->max_arr = ddata->max_arr;
314 priv->triggers = triggers_table[index];
315
316 ret = stm32_setup_iio_triggers(priv);
317 if (ret)
318 return ret;
319
320 platform_set_drvdata(pdev, priv);
321
322 return 0;
323}
324
325static const struct of_device_id stm32_trig_of_match[] = {
326 { .compatible = "st,stm32-timer-trigger", },
327 { /* end node */ },
328};
329MODULE_DEVICE_TABLE(of, stm32_trig_of_match);
330
331static struct platform_driver stm32_timer_trigger_driver = {
332 .probe = stm32_timer_trigger_probe,
333 .driver = {
334 .name = "stm32-timer-trigger",
335 .of_match_table = stm32_trig_of_match,
336 },
337};
338module_platform_driver(stm32_timer_trigger_driver);
339
340MODULE_ALIAS("platform: stm32-timer-trigger");
341MODULE_DESCRIPTION("STMicroelectronics STM32 Timer Trigger driver");
342MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 4ce3b6f11830..d0c14b88b24e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1621,6 +1621,17 @@ config MFD_STW481X
1621 in various ST Microelectronics and ST-Ericsson embedded 1621 in various ST Microelectronics and ST-Ericsson embedded
1622 Nomadik series. 1622 Nomadik series.
1623 1623
1624config MFD_STM32_TIMERS
1625 tristate "Support for STM32 Timers"
1626 depends on (ARCH_STM32 && OF) || COMPILE_TEST
1627 select MFD_CORE
1628 select REGMAP
1629 select REGMAP_MMIO
1630 help
1631 Select this option to enable STM32 timers driver used
1632 for PWM and IIO Timer. This driver allow to share the
1633 registers between the others drivers.
1634
1624menu "Multimedia Capabilities Port drivers" 1635menu "Multimedia Capabilities Port drivers"
1625 depends on ARCH_SA1100 1636 depends on ARCH_SA1100
1626 1637
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index dda4d4f73ad7..876ca8600c51 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -212,3 +212,5 @@ obj-$(CONFIG_MFD_MT6397) += mt6397-core.o
212 212
213obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o 213obj-$(CONFIG_MFD_ALTERA_A10SR) += altera-a10sr.o
214obj-$(CONFIG_MFD_SUN4I_GPADC) += sun4i-gpadc.o 214obj-$(CONFIG_MFD_SUN4I_GPADC) += sun4i-gpadc.o
215
216obj-$(CONFIG_MFD_STM32_TIMERS) += stm32-timers.o
diff --git a/drivers/mfd/stm32-timers.c b/drivers/mfd/stm32-timers.c
new file mode 100644
index 000000000000..41bd9017f3d0
--- /dev/null
+++ b/drivers/mfd/stm32-timers.c
@@ -0,0 +1,80 @@
1/*
2 * Copyright (C) STMicroelectronics 2016
3 *
4 * Author: Benjamin Gaignard <benjamin.gaignard@st.com>
5 *
6 * License terms: GNU General Public License (GPL), version 2
7 */
8
9#include <linux/mfd/stm32-timers.h>
10#include <linux/module.h>
11#include <linux/of_platform.h>
12#include <linux/reset.h>
13
14static const struct regmap_config stm32_timers_regmap_cfg = {
15 .reg_bits = 32,
16 .val_bits = 32,
17 .reg_stride = sizeof(u32),
18 .max_register = 0x400,
19};
20
21static void stm32_timers_get_arr_size(struct stm32_timers *ddata)
22{
23 /*
24 * Only the available bits will be written so when readback
25 * we get the maximum value of auto reload register
26 */
27 regmap_write(ddata->regmap, TIM_ARR, ~0L);
28 regmap_read(ddata->regmap, TIM_ARR, &ddata->max_arr);
29 regmap_write(ddata->regmap, TIM_ARR, 0x0);
30}
31
32static int stm32_timers_probe(struct platform_device *pdev)
33{
34 struct device *dev = &pdev->dev;
35 struct stm32_timers *ddata;
36 struct resource *res;
37 void __iomem *mmio;
38
39 ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
40 if (!ddata)
41 return -ENOMEM;
42
43 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
44 mmio = devm_ioremap_resource(dev, res);
45 if (IS_ERR(mmio))
46 return PTR_ERR(mmio);
47
48 ddata->regmap = devm_regmap_init_mmio_clk(dev, "int", mmio,
49 &stm32_timers_regmap_cfg);
50 if (IS_ERR(ddata->regmap))
51 return PTR_ERR(ddata->regmap);
52
53 ddata->clk = devm_clk_get(dev, NULL);
54 if (IS_ERR(ddata->clk))
55 return PTR_ERR(ddata->clk);
56
57 stm32_timers_get_arr_size(ddata);
58
59 platform_set_drvdata(pdev, ddata);
60
61 return of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
62}
63
64static const struct of_device_id stm32_timers_of_match[] = {
65 { .compatible = "st,stm32-timers", },
66 { /* end node */ },
67};
68MODULE_DEVICE_TABLE(of, stm32_timers_of_match);
69
70static struct platform_driver stm32_timers_driver = {
71 .probe = stm32_timers_probe,
72 .driver = {
73 .name = "stm32-timers",
74 .of_match_table = stm32_timers_of_match,
75 },
76};
77module_platform_driver(stm32_timers_driver);
78
79MODULE_DESCRIPTION("STMicroelectronics STM32 Timers");
80MODULE_LICENSE("GPL v2");
diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c
index 47268ecedc4d..6f09da4dadb8 100644
--- a/drivers/platform/chrome/cros_ec_dev.c
+++ b/drivers/platform/chrome/cros_ec_dev.c
@@ -328,6 +328,9 @@ static void cros_ec_sensors_register(struct cros_ec_dev *ec)
328 case MOTIONSENSE_TYPE_ACCEL: 328 case MOTIONSENSE_TYPE_ACCEL:
329 sensor_cells[id].name = "cros-ec-accel"; 329 sensor_cells[id].name = "cros-ec-accel";
330 break; 330 break;
331 case MOTIONSENSE_TYPE_BARO:
332 sensor_cells[id].name = "cros-ec-baro";
333 break;
331 case MOTIONSENSE_TYPE_GYRO: 334 case MOTIONSENSE_TYPE_GYRO:
332 sensor_cells[id].name = "cros-ec-gyro"; 335 sensor_cells[id].name = "cros-ec-gyro";
333 break; 336 break;
diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index f92dd41b0395..2d0cfaa6d84c 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -397,6 +397,15 @@ config PWM_STI
397 To compile this driver as a module, choose M here: the module 397 To compile this driver as a module, choose M here: the module
398 will be called pwm-sti. 398 will be called pwm-sti.
399 399
400config PWM_STM32
401 tristate "STMicroelectronics STM32 PWM"
402 depends on MFD_STM32_TIMERS || COMPILE_TEST
403 help
404 Generic PWM framework driver for STM32 SoCs.
405
406 To compile this driver as a module, choose M here: the module
407 will be called pwm-stm32.
408
400config PWM_STMPE 409config PWM_STMPE
401 bool "STMPE expander PWM export" 410 bool "STMPE expander PWM export"
402 depends on MFD_STMPE 411 depends on MFD_STMPE
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index a48bdb517792..346a83b00f28 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_PWM_ROCKCHIP) += pwm-rockchip.o
38obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o 38obj-$(CONFIG_PWM_SAMSUNG) += pwm-samsung.o
39obj-$(CONFIG_PWM_SPEAR) += pwm-spear.o 39obj-$(CONFIG_PWM_SPEAR) += pwm-spear.o
40obj-$(CONFIG_PWM_STI) += pwm-sti.o 40obj-$(CONFIG_PWM_STI) += pwm-sti.o
41obj-$(CONFIG_PWM_STM32) += pwm-stm32.o
41obj-$(CONFIG_PWM_STMPE) += pwm-stmpe.o 42obj-$(CONFIG_PWM_STMPE) += pwm-stmpe.o
42obj-$(CONFIG_PWM_SUN4I) += pwm-sun4i.o 43obj-$(CONFIG_PWM_SUN4I) += pwm-sun4i.o
43obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o 44obj-$(CONFIG_PWM_TEGRA) += pwm-tegra.o
diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
new file mode 100644
index 000000000000..6139512aab7b
--- /dev/null
+++ b/drivers/pwm/pwm-stm32.c
@@ -0,0 +1,397 @@
1/*
2 * Copyright (C) STMicroelectronics 2016
3 *
4 * Author: Gerald Baeza <gerald.baeza@st.com>
5 *
6 * License terms: GNU General Public License (GPL), version 2
7 *
8 * Inspired by timer-stm32.c from Maxime Coquelin
9 * pwm-atmel.c from Bo Shen
10 */
11
12#include <linux/mfd/stm32-timers.h>
13#include <linux/module.h>
14#include <linux/of.h>
15#include <linux/platform_device.h>
16#include <linux/pwm.h>
17
18#define CCMR_CHANNEL_SHIFT 8
19#define CCMR_CHANNEL_MASK 0xFF
20#define MAX_BREAKINPUT 2
21
22struct stm32_pwm {
23 struct pwm_chip chip;
24 struct device *dev;
25 struct clk *clk;
26 struct regmap *regmap;
27 u32 max_arr;
28 bool have_complementary_output;
29};
30
31struct stm32_breakinput {
32 u32 index;
33 u32 level;
34 u32 filter;
35};
36
37static inline struct stm32_pwm *to_stm32_pwm_dev(struct pwm_chip *chip)
38{
39 return container_of(chip, struct stm32_pwm, chip);
40}
41
42static u32 active_channels(struct stm32_pwm *dev)
43{
44 u32 ccer;
45
46 regmap_read(dev->regmap, TIM_CCER, &ccer);
47
48 return ccer & TIM_CCER_CCXE;
49}
50
51static int write_ccrx(struct stm32_pwm *dev, int ch, u32 value)
52{
53 switch (ch) {
54 case 0:
55 return regmap_write(dev->regmap, TIM_CCR1, value);
56 case 1:
57 return regmap_write(dev->regmap, TIM_CCR2, value);
58 case 2:
59 return regmap_write(dev->regmap, TIM_CCR3, value);
60 case 3:
61 return regmap_write(dev->regmap, TIM_CCR4, value);
62 }
63 return -EINVAL;
64}
65
66static int stm32_pwm_config(struct stm32_pwm *priv, int ch,
67 int duty_ns, int period_ns)
68{
69 unsigned long long prd, div, dty;
70 unsigned int prescaler = 0;
71 u32 ccmr, mask, shift;
72
73 /* Period and prescaler values depends on clock rate */
74 div = (unsigned long long)clk_get_rate(priv->clk) * period_ns;
75
76 do_div(div, NSEC_PER_SEC);
77 prd = div;
78
79 while (div > priv->max_arr) {
80 prescaler++;
81 div = prd;
82 do_div(div, prescaler + 1);
83 }
84
85 prd = div;
86
87 if (prescaler > MAX_TIM_PSC)
88 return -EINVAL;
89
90 /*
91 * All channels share the same prescaler and counter so when two
92 * channels are active at the same time we can't change them
93 */
94 if (active_channels(priv) & ~(1 << ch * 4)) {
95 u32 psc, arr;
96
97 regmap_read(priv->regmap, TIM_PSC, &psc);
98 regmap_read(priv->regmap, TIM_ARR, &arr);
99
100 if ((psc != prescaler) || (arr != prd - 1))
101 return -EBUSY;
102 }
103
104 regmap_write(priv->regmap, TIM_PSC, prescaler);
105 regmap_write(priv->regmap, TIM_ARR, prd - 1);
106 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_ARPE, TIM_CR1_ARPE);
107
108 /* Calculate the duty cycles */
109 dty = prd * duty_ns;
110 do_div(dty, period_ns);
111
112 write_ccrx(priv, ch, dty);
113
114 /* Configure output mode */
115 shift = (ch & 0x1) * CCMR_CHANNEL_SHIFT;
116 ccmr = (TIM_CCMR_PE | TIM_CCMR_M1) << shift;
117 mask = CCMR_CHANNEL_MASK << shift;
118
119 if (ch < 2)
120 regmap_update_bits(priv->regmap, TIM_CCMR1, mask, ccmr);
121 else
122 regmap_update_bits(priv->regmap, TIM_CCMR2, mask, ccmr);
123
124 regmap_update_bits(priv->regmap, TIM_BDTR,
125 TIM_BDTR_MOE | TIM_BDTR_AOE,
126 TIM_BDTR_MOE | TIM_BDTR_AOE);
127
128 return 0;
129}
130
131static int stm32_pwm_set_polarity(struct stm32_pwm *priv, int ch,
132 enum pwm_polarity polarity)
133{
134 u32 mask;
135
136 mask = TIM_CCER_CC1P << (ch * 4);
137 if (priv->have_complementary_output)
138 mask |= TIM_CCER_CC1NP << (ch * 4);
139
140 regmap_update_bits(priv->regmap, TIM_CCER, mask,
141 polarity == PWM_POLARITY_NORMAL ? 0 : mask);
142
143 return 0;
144}
145
146static int stm32_pwm_enable(struct stm32_pwm *priv, int ch)
147{
148 u32 mask;
149 int ret;
150
151 ret = clk_enable(priv->clk);
152 if (ret)
153 return ret;
154
155 /* Enable channel */
156 mask = TIM_CCER_CC1E << (ch * 4);
157 if (priv->have_complementary_output)
158 mask |= TIM_CCER_CC1NE << (ch * 4);
159
160 regmap_update_bits(priv->regmap, TIM_CCER, mask, mask);
161
162 /* Make sure that registers are updated */
163 regmap_update_bits(priv->regmap, TIM_EGR, TIM_EGR_UG, TIM_EGR_UG);
164
165 /* Enable controller */
166 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, TIM_CR1_CEN);
167
168 return 0;
169}
170
171static void stm32_pwm_disable(struct stm32_pwm *priv, int ch)
172{
173 u32 mask;
174
175 /* Disable channel */
176 mask = TIM_CCER_CC1E << (ch * 4);
177 if (priv->have_complementary_output)
178 mask |= TIM_CCER_CC1NE << (ch * 4);
179
180 regmap_update_bits(priv->regmap, TIM_CCER, mask, 0);
181
182 /* When all channels are disabled, we can disable the controller */
183 if (!active_channels(priv))
184 regmap_update_bits(priv->regmap, TIM_CR1, TIM_CR1_CEN, 0);
185
186 clk_disable(priv->clk);
187}
188
189static int stm32_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
190 struct pwm_state *state)
191{
192 bool enabled;
193 struct stm32_pwm *priv = to_stm32_pwm_dev(chip);
194 int ret;
195
196 enabled = pwm->state.enabled;
197
198 if (enabled && !state->enabled) {
199 stm32_pwm_disable(priv, pwm->hwpwm);
200 return 0;
201 }
202
203 if (state->polarity != pwm->state.polarity)
204 stm32_pwm_set_polarity(priv, pwm->hwpwm, state->polarity);
205
206 ret = stm32_pwm_config(priv, pwm->hwpwm,
207 state->duty_cycle, state->period);
208 if (ret)
209 return ret;
210
211 if (!enabled && state->enabled)
212 ret = stm32_pwm_enable(priv, pwm->hwpwm);
213
214 return ret;
215}
216
217static const struct pwm_ops stm32pwm_ops = {
218 .owner = THIS_MODULE,
219 .apply = stm32_pwm_apply,
220};
221
222static int stm32_pwm_set_breakinput(struct stm32_pwm *priv,
223 int index, int level, int filter)
224{
225 u32 bke = (index == 0) ? TIM_BDTR_BKE : TIM_BDTR_BK2E;
226 int shift = (index == 0) ? TIM_BDTR_BKF_SHIFT : TIM_BDTR_BK2F_SHIFT;
227 u32 mask = (index == 0) ? TIM_BDTR_BKE | TIM_BDTR_BKP | TIM_BDTR_BKF
228 : TIM_BDTR_BK2E | TIM_BDTR_BK2P | TIM_BDTR_BK2F;
229 u32 bdtr = bke;
230
231 /*
232 * The both bits could be set since only one will be wrote
233 * due to mask value.
234 */
235 if (level)
236 bdtr |= TIM_BDTR_BKP | TIM_BDTR_BK2P;
237
238 bdtr |= (filter & TIM_BDTR_BKF_MASK) << shift;
239
240 regmap_update_bits(priv->regmap, TIM_BDTR, mask, bdtr);
241
242 regmap_read(priv->regmap, TIM_BDTR, &bdtr);
243
244 return (bdtr & bke) ? 0 : -EINVAL;
245}
246
247static int stm32_pwm_apply_breakinputs(struct stm32_pwm *priv,
248 struct device_node *np)
249{
250 struct stm32_breakinput breakinput[MAX_BREAKINPUT];
251 int nb, ret, i, array_size;
252
253 nb = of_property_count_elems_of_size(np, "st,breakinput",
254 sizeof(struct stm32_breakinput));
255
256 /*
257 * Because "st,breakinput" parameter is optional do not make probe
258 * failed if it doesn't exist.
259 */
260 if (nb <= 0)
261 return 0;
262
263 if (nb > MAX_BREAKINPUT)
264 return -EINVAL;
265
266 array_size = nb * sizeof(struct stm32_breakinput) / sizeof(u32);
267 ret = of_property_read_u32_array(np, "st,breakinput",
268 (u32 *)breakinput, array_size);
269 if (ret)
270 return ret;
271
272 for (i = 0; i < nb && !ret; i++) {
273 ret = stm32_pwm_set_breakinput(priv,
274 breakinput[i].index,
275 breakinput[i].level,
276 breakinput[i].filter);
277 }
278
279 return ret;
280}
281
282static void stm32_pwm_detect_complementary(struct stm32_pwm *priv)
283{
284 u32 ccer;
285
286 /*
287 * If complementary bit doesn't exist writing 1 will have no
288 * effect so we can detect it.
289 */
290 regmap_update_bits(priv->regmap,
291 TIM_CCER, TIM_CCER_CC1NE, TIM_CCER_CC1NE);
292 regmap_read(priv->regmap, TIM_CCER, &ccer);
293 regmap_update_bits(priv->regmap, TIM_CCER, TIM_CCER_CC1NE, 0);
294
295 priv->have_complementary_output = (ccer != 0);
296}
297
298static int stm32_pwm_detect_channels(struct stm32_pwm *priv)
299{
300 u32 ccer;
301 int npwm = 0;
302
303 /*
304 * If channels enable bits don't exist writing 1 will have no
305 * effect so we can detect and count them.
306 */
307 regmap_update_bits(priv->regmap,
308 TIM_CCER, TIM_CCER_CCXE, TIM_CCER_CCXE);
309 regmap_read(priv->regmap, TIM_CCER, &ccer);
310 regmap_update_bits(priv->regmap, TIM_CCER, TIM_CCER_CCXE, 0);
311
312 if (ccer & TIM_CCER_CC1E)
313 npwm++;
314
315 if (ccer & TIM_CCER_CC2E)
316 npwm++;
317
318 if (ccer & TIM_CCER_CC3E)
319 npwm++;
320
321 if (ccer & TIM_CCER_CC4E)
322 npwm++;
323
324 return npwm;
325}
326
327static int stm32_pwm_probe(struct platform_device *pdev)
328{
329 struct device *dev = &pdev->dev;
330 struct device_node *np = dev->of_node;
331 struct stm32_timers *ddata = dev_get_drvdata(pdev->dev.parent);
332 struct stm32_pwm *priv;
333 int ret;
334
335 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
336 if (!priv)
337 return -ENOMEM;
338
339 priv->regmap = ddata->regmap;
340 priv->clk = ddata->clk;
341 priv->max_arr = ddata->max_arr;
342
343 if (!priv->regmap || !priv->clk)
344 return -EINVAL;
345
346 ret = stm32_pwm_apply_breakinputs(priv, np);
347 if (ret)
348 return ret;
349
350 stm32_pwm_detect_complementary(priv);
351
352 priv->chip.base = -1;
353 priv->chip.dev = dev;
354 priv->chip.ops = &stm32pwm_ops;
355 priv->chip.npwm = stm32_pwm_detect_channels(priv);
356
357 ret = pwmchip_add(&priv->chip);
358 if (ret < 0)
359 return ret;
360
361 platform_set_drvdata(pdev, priv);
362
363 return 0;
364}
365
366static int stm32_pwm_remove(struct platform_device *pdev)
367{
368 struct stm32_pwm *priv = platform_get_drvdata(pdev);
369 unsigned int i;
370
371 for (i = 0; i < priv->chip.npwm; i++)
372 pwm_disable(&priv->chip.pwms[i]);
373
374 pwmchip_remove(&priv->chip);
375
376 return 0;
377}
378
379static const struct of_device_id stm32_pwm_of_match[] = {
380 { .compatible = "st,stm32-pwm", },
381 { /* end node */ },
382};
383MODULE_DEVICE_TABLE(of, stm32_pwm_of_match);
384
385static struct platform_driver stm32_pwm_driver = {
386 .probe = stm32_pwm_probe,
387 .remove = stm32_pwm_remove,
388 .driver = {
389 .name = "stm32-pwm",
390 .of_match_table = stm32_pwm_of_match,
391 },
392};
393module_platform_driver(stm32_pwm_driver);
394
395MODULE_ALIAS("platform:stm32-pwm");
396MODULE_DESCRIPTION("STMicroelectronics STM32 PWM driver");
397MODULE_LICENSE("GPL v2");
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index cd005cd41413..4c360f8071a8 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -96,12 +96,12 @@ source "drivers/staging/wilc1000/Kconfig"
96 96
97source "drivers/staging/most/Kconfig" 97source "drivers/staging/most/Kconfig"
98 98
99source "drivers/staging/i4l/Kconfig"
100
101source "drivers/staging/ks7010/Kconfig" 99source "drivers/staging/ks7010/Kconfig"
102 100
103source "drivers/staging/greybus/Kconfig" 101source "drivers/staging/greybus/Kconfig"
104 102
105source "drivers/staging/vc04_services/Kconfig" 103source "drivers/staging/vc04_services/Kconfig"
106 104
105source "drivers/staging/bcm2835-audio/Kconfig"
106
107endif # STAGING 107endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 831e2e891989..29cec5aa2945 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -37,7 +37,8 @@ obj-$(CONFIG_FB_TFT) += fbtft/
37obj-$(CONFIG_FSL_MC_BUS) += fsl-mc/ 37obj-$(CONFIG_FSL_MC_BUS) += fsl-mc/
38obj-$(CONFIG_WILC1000) += wilc1000/ 38obj-$(CONFIG_WILC1000) += wilc1000/
39obj-$(CONFIG_MOST) += most/ 39obj-$(CONFIG_MOST) += most/
40obj-$(CONFIG_ISDN_I4L) += i4l/
41obj-$(CONFIG_KS7010) += ks7010/ 40obj-$(CONFIG_KS7010) += ks7010/
42obj-$(CONFIG_GREYBUS) += greybus/ 41obj-$(CONFIG_GREYBUS) += greybus/
43obj-$(CONFIG_BCM2835_VCHIQ) += vc04_services/ 42obj-$(CONFIG_BCM2835_VCHIQ) += vc04_services/
43obj-$(CONFIG_SND_BCM2835) += bcm2835-audio/
44
diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c
index 7e7431d8d49f..9ff815ad1cb1 100644
--- a/drivers/staging/android/ion/ion-ioctl.c
+++ b/drivers/staging/android/ion/ion-ioctl.c
@@ -111,7 +111,8 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
111 struct ion_handle *handle; 111 struct ion_handle *handle;
112 112
113 mutex_lock(&client->lock); 113 mutex_lock(&client->lock);
114 handle = ion_handle_get_by_id_nolock(client, data.handle.handle); 114 handle = ion_handle_get_by_id_nolock(client,
115 data.handle.handle);
115 if (IS_ERR(handle)) { 116 if (IS_ERR(handle)) {
116 mutex_unlock(&client->lock); 117 mutex_unlock(&client->lock);
117 return PTR_ERR(handle); 118 return PTR_ERR(handle);
diff --git a/drivers/staging/android/ion/ion_cma_heap.c b/drivers/staging/android/ion/ion_cma_heap.c
index 6c7de74bc7ab..6c4068523781 100644
--- a/drivers/staging/android/ion/ion_cma_heap.c
+++ b/drivers/staging/android/ion/ion_cma_heap.c
@@ -24,8 +24,6 @@
24#include "ion.h" 24#include "ion.h"
25#include "ion_priv.h" 25#include "ion_priv.h"
26 26
27#define ION_CMA_ALLOCATE_FAILED -1
28
29struct ion_cma_heap { 27struct ion_cma_heap {
30 struct ion_heap heap; 28 struct ion_heap heap;
31 struct device *dev; 29 struct device *dev;
@@ -57,9 +55,9 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
57 if (align > PAGE_SIZE) 55 if (align > PAGE_SIZE)
58 return -EINVAL; 56 return -EINVAL;
59 57
60 info = kzalloc(sizeof(struct ion_cma_buffer_info), GFP_KERNEL); 58 info = kzalloc(sizeof(*info), GFP_KERNEL);
61 if (!info) 59 if (!info)
62 return ION_CMA_ALLOCATE_FAILED; 60 return -ENOMEM;
63 61
64 info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle), 62 info->cpu_addr = dma_alloc_coherent(dev, len, &(info->handle),
65 GFP_HIGHUSER | __GFP_ZERO); 63 GFP_HIGHUSER | __GFP_ZERO);
@@ -69,7 +67,7 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
69 goto err; 67 goto err;
70 } 68 }
71 69
72 info->table = kmalloc(sizeof(struct sg_table), GFP_KERNEL); 70 info->table = kmalloc(sizeof(*info->table), GFP_KERNEL);
73 if (!info->table) 71 if (!info->table)
74 goto free_mem; 72 goto free_mem;
75 73
@@ -88,7 +86,7 @@ free_mem:
88 dma_free_coherent(dev, len, info->cpu_addr, info->handle); 86 dma_free_coherent(dev, len, info->cpu_addr, info->handle);
89err: 87err:
90 kfree(info); 88 kfree(info);
91 return ION_CMA_ALLOCATE_FAILED; 89 return -ENOMEM;
92} 90}
93 91
94static void ion_cma_free(struct ion_buffer *buffer) 92static void ion_cma_free(struct ion_buffer *buffer)
@@ -142,7 +140,7 @@ struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data)
142{ 140{
143 struct ion_cma_heap *cma_heap; 141 struct ion_cma_heap *cma_heap;
144 142
145 cma_heap = kzalloc(sizeof(struct ion_cma_heap), GFP_KERNEL); 143 cma_heap = kzalloc(sizeof(*cma_heap), GFP_KERNEL);
146 144
147 if (!cma_heap) 145 if (!cma_heap)
148 return ERR_PTR(-ENOMEM); 146 return ERR_PTR(-ENOMEM);
diff --git a/drivers/staging/android/ion/ion_of.c b/drivers/staging/android/ion/ion_of.c
index 46b2bb99bfd6..7791c705ea31 100644
--- a/drivers/staging/android/ion/ion_of.c
+++ b/drivers/staging/android/ion/ion_of.c
@@ -161,7 +161,6 @@ static int rmem_ion_device_init(struct reserved_mem *rmem, struct device *dev)
161static void rmem_ion_device_release(struct reserved_mem *rmem, 161static void rmem_ion_device_release(struct reserved_mem *rmem,
162 struct device *dev) 162 struct device *dev)
163{ 163{
164 return;
165} 164}
166 165
167static const struct reserved_mem_ops rmem_dma_ops = { 166static const struct reserved_mem_ops rmem_dma_ops = {
diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h
index 3c3b3245275d..5b3059c78431 100644
--- a/drivers/staging/android/ion/ion_priv.h
+++ b/drivers/staging/android/ion/ion_priv.h
@@ -54,7 +54,7 @@
54 * handle, used for debugging 54 * handle, used for debugging
55 * @pid: pid of last client to reference this buffer in a 55 * @pid: pid of last client to reference this buffer in a
56 * handle, used for debugging 56 * handle, used for debugging
57*/ 57 */
58struct ion_buffer { 58struct ion_buffer {
59 struct kref ref; 59 struct kref ref;
60 union { 60 union {
@@ -287,10 +287,10 @@ void ion_device_add_heap(struct ion_device *dev, struct ion_heap *heap);
287 * some helpers for common operations on buffers using the sg_table 287 * some helpers for common operations on buffers using the sg_table
288 * and vaddr fields 288 * and vaddr fields
289 */ 289 */
290void *ion_heap_map_kernel(struct ion_heap *, struct ion_buffer *); 290void *ion_heap_map_kernel(struct ion_heap *heap, struct ion_buffer *buffer);
291void ion_heap_unmap_kernel(struct ion_heap *, struct ion_buffer *); 291void ion_heap_unmap_kernel(struct ion_heap *heap, struct ion_buffer *buffer);
292int ion_heap_map_user(struct ion_heap *, struct ion_buffer *, 292int ion_heap_map_user(struct ion_heap *heap, struct ion_buffer *buffer,
293 struct vm_area_struct *); 293 struct vm_area_struct *vma);
294int ion_heap_buffer_zero(struct ion_buffer *buffer); 294int ion_heap_buffer_zero(struct ion_buffer *buffer);
295int ion_heap_pages_zero(struct page *page, size_t size, pgprot_t pgprot); 295int ion_heap_pages_zero(struct page *page, size_t size, pgprot_t pgprot);
296 296
@@ -371,21 +371,21 @@ size_t ion_heap_freelist_size(struct ion_heap *heap);
371 * heaps as appropriate. 371 * heaps as appropriate.
372 */ 372 */
373 373
374struct ion_heap *ion_heap_create(struct ion_platform_heap *); 374struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data);
375void ion_heap_destroy(struct ion_heap *); 375void ion_heap_destroy(struct ion_heap *heap);
376struct ion_heap *ion_system_heap_create(struct ion_platform_heap *); 376struct ion_heap *ion_system_heap_create(struct ion_platform_heap *unused);
377void ion_system_heap_destroy(struct ion_heap *); 377void ion_system_heap_destroy(struct ion_heap *heap);
378 378
379struct ion_heap *ion_system_contig_heap_create(struct ion_platform_heap *); 379struct ion_heap *ion_system_contig_heap_create(struct ion_platform_heap *heap);
380void ion_system_contig_heap_destroy(struct ion_heap *); 380void ion_system_contig_heap_destroy(struct ion_heap *heap);
381 381
382struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *); 382struct ion_heap *ion_carveout_heap_create(struct ion_platform_heap *heap_data);
383void ion_carveout_heap_destroy(struct ion_heap *); 383void ion_carveout_heap_destroy(struct ion_heap *heap);
384 384
385struct ion_heap *ion_chunk_heap_create(struct ion_platform_heap *); 385struct ion_heap *ion_chunk_heap_create(struct ion_platform_heap *heap_data);
386void ion_chunk_heap_destroy(struct ion_heap *); 386void ion_chunk_heap_destroy(struct ion_heap *heap);
387struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *); 387struct ion_heap *ion_cma_heap_create(struct ion_platform_heap *data);
388void ion_cma_heap_destroy(struct ion_heap *); 388void ion_cma_heap_destroy(struct ion_heap *heap);
389 389
390/** 390/**
391 * functions for creating and destroying a heap pool -- allows you 391 * functions for creating and destroying a heap pool -- allows you
@@ -427,9 +427,9 @@ struct ion_page_pool {
427 427
428struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order, 428struct ion_page_pool *ion_page_pool_create(gfp_t gfp_mask, unsigned int order,
429 bool cached); 429 bool cached);
430void ion_page_pool_destroy(struct ion_page_pool *); 430void ion_page_pool_destroy(struct ion_page_pool *pool);
431struct page *ion_page_pool_alloc(struct ion_page_pool *); 431struct page *ion_page_pool_alloc(struct ion_page_pool *pool);
432void ion_page_pool_free(struct ion_page_pool *, struct page *); 432void ion_page_pool_free(struct ion_page_pool *pool, struct page *page);
433 433
434/** ion_page_pool_shrink - shrinks the size of the memory cached in the pool 434/** ion_page_pool_shrink - shrinks the size of the memory cached in the pool
435 * @pool: the pool 435 * @pool: the pool
diff --git a/drivers/staging/bcm2835-audio/Kconfig b/drivers/staging/bcm2835-audio/Kconfig
new file mode 100644
index 000000000000..32a2ff9ef9b2
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/Kconfig
@@ -0,0 +1,7 @@
1config SND_BCM2835
2 tristate "BCM2835 ALSA driver"
3 depends on ARCH_BCM2835 && BCM2835_VCHIQ && SND
4 select SND_PCM
5 help
6 Say Y or M if you want to support BCM2835 Alsa pcm card driver
7
diff --git a/drivers/staging/bcm2835-audio/Makefile b/drivers/staging/bcm2835-audio/Makefile
new file mode 100644
index 000000000000..d7b88d164d15
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/Makefile
@@ -0,0 +1,5 @@
1obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
2snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
3
4ccflags-y += -Idrivers/staging/vc04_services -D__VCCOREVER__=0x04000000
5
diff --git a/drivers/staging/bcm2835-audio/TODO b/drivers/staging/bcm2835-audio/TODO
new file mode 100644
index 000000000000..73d41fa631ac
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/TODO
@@ -0,0 +1,29 @@
1*****************************************************************************
2* *
3* TODO: BCM2835-AUDIO *
4* *
5*****************************************************************************
6
7
81) Document the device tree node
9
10The downstream tree(the tree that the driver was imported from) at
11http://www.github.com/raspberrypi/linux uses this node:
12
13audio: audio {
14 compatible = "brcm,bcm2835-audio";
15 brcm,pwm-channels = <8>;
16};
17
18Since the driver requires the use of VCHIQ, it may be useful to have a link
19in the device tree to the VCHIQ driver.
20
212) Gracefully handle the case where VCHIQ is missing from the device tree or
22it has not been initialized yet.
23
243) Review error handling and remove duplicate code.
25
264) Cleanup the logging mechanism. The driver should probably be using the
27standard kernel logging mechanisms such as dev_info, dev_dbg, and friends.
28
295) Fix the remaining checkpatch.pl errors and warnings.
diff --git a/drivers/staging/bcm2835-audio/bcm2835-ctl.c b/drivers/staging/bcm2835-audio/bcm2835-ctl.c
new file mode 100644
index 000000000000..a4ffa1bf53e5
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/bcm2835-ctl.c
@@ -0,0 +1,345 @@
1/*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14
15#include <linux/platform_device.h>
16#include <linux/init.h>
17#include <linux/io.h>
18#include <linux/jiffies.h>
19#include <linux/slab.h>
20#include <linux/time.h>
21#include <linux/wait.h>
22#include <linux/delay.h>
23#include <linux/moduleparam.h>
24#include <linux/sched.h>
25
26#include <sound/core.h>
27#include <sound/control.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/rawmidi.h>
31#include <sound/initval.h>
32#include <sound/tlv.h>
33#include <sound/asoundef.h>
34
35#include "bcm2835.h"
36
37/* volume maximum and minimum in terms of 0.01dB */
38#define CTRL_VOL_MAX 400
39#define CTRL_VOL_MIN -10239 /* originally -10240 */
40
41static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
42 struct snd_ctl_elem_info *uinfo)
43{
44 audio_info(" ... IN\n");
45 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
46 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
47 uinfo->count = 1;
48 uinfo->value.integer.min = CTRL_VOL_MIN;
49 uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
50 } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
51 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
52 uinfo->count = 1;
53 uinfo->value.integer.min = 0;
54 uinfo->value.integer.max = 1;
55 } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
56 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
57 uinfo->count = 1;
58 uinfo->value.integer.min = 0;
59 uinfo->value.integer.max = AUDIO_DEST_MAX - 1;
60 }
61 audio_info(" ... OUT\n");
62 return 0;
63}
64
65/* toggles mute on or off depending on the value of nmute, and returns
66 * 1 if the mute value was changed, otherwise 0
67 */
68static int toggle_mute(struct bcm2835_chip *chip, int nmute)
69{
70 /* if settings are ok, just return 0 */
71 if (chip->mute == nmute)
72 return 0;
73
74 /* if the sound is muted then we need to unmute */
75 if (chip->mute == CTRL_VOL_MUTE) {
76 chip->volume = chip->old_volume; /* copy the old volume back */
77 audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
78 } else /* otherwise we mute */ {
79 chip->old_volume = chip->volume;
80 chip->volume = 26214; /* set volume to minimum level AKA mute */
81 audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
82 }
83
84 chip->mute = nmute;
85 return 1;
86}
87
88static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
89 struct snd_ctl_elem_value *ucontrol)
90{
91 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
92
93 if (mutex_lock_interruptible(&chip->audio_mutex))
94 return -EINTR;
95
96 BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
97
98 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
99 ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
100 else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
101 ucontrol->value.integer.value[0] = chip->mute;
102 else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
103 ucontrol->value.integer.value[0] = chip->dest;
104
105 mutex_unlock(&chip->audio_mutex);
106 return 0;
107}
108
109static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
110 struct snd_ctl_elem_value *ucontrol)
111{
112 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
113 int changed = 0;
114
115 if (mutex_lock_interruptible(&chip->audio_mutex))
116 return -EINTR;
117
118 if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
119 audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int) ucontrol->value.integer.value[0]);
120 if (chip->mute == CTRL_VOL_MUTE) {
121 /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
122 changed = 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
123 goto unlock;
124 }
125 if (changed
126 || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
127
128 chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
129 changed = 1;
130 }
131
132 } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
133 /* Now implemented */
134 audio_info(" Mute attempted\n");
135 changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
136
137 } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
138 if (ucontrol->value.integer.value[0] != chip->dest) {
139 chip->dest = ucontrol->value.integer.value[0];
140 changed = 1;
141 }
142 }
143
144 if (changed) {
145 if (bcm2835_audio_set_ctls(chip))
146 printk(KERN_ERR "Failed to set ALSA controls..\n");
147 }
148
149unlock:
150 mutex_unlock(&chip->audio_mutex);
151 return changed;
152}
153
154static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
155
156static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
157 {
158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
159 .name = "PCM Playback Volume",
160 .index = 0,
161 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
162 .private_value = PCM_PLAYBACK_VOLUME,
163 .info = snd_bcm2835_ctl_info,
164 .get = snd_bcm2835_ctl_get,
165 .put = snd_bcm2835_ctl_put,
166 .count = 1,
167 .tlv = {.p = snd_bcm2835_db_scale}
168 },
169 {
170 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
171 .name = "PCM Playback Switch",
172 .index = 0,
173 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
174 .private_value = PCM_PLAYBACK_MUTE,
175 .info = snd_bcm2835_ctl_info,
176 .get = snd_bcm2835_ctl_get,
177 .put = snd_bcm2835_ctl_put,
178 .count = 1,
179 },
180 {
181 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
182 .name = "PCM Playback Route",
183 .index = 0,
184 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
185 .private_value = PCM_PLAYBACK_DEVICE,
186 .info = snd_bcm2835_ctl_info,
187 .get = snd_bcm2835_ctl_get,
188 .put = snd_bcm2835_ctl_put,
189 .count = 1,
190 },
191};
192
193static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
194 struct snd_ctl_elem_info *uinfo)
195{
196 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
197 uinfo->count = 1;
198 return 0;
199}
200
201static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
202 struct snd_ctl_elem_value *ucontrol)
203{
204 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
205 int i;
206
207 if (mutex_lock_interruptible(&chip->audio_mutex))
208 return -EINTR;
209
210 for (i = 0; i < 4; i++)
211 ucontrol->value.iec958.status[i] =
212 (chip->spdif_status >> (i * 8)) & 0xff;
213
214 mutex_unlock(&chip->audio_mutex);
215 return 0;
216}
217
218static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
219 struct snd_ctl_elem_value *ucontrol)
220{
221 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
222 unsigned int val = 0;
223 int i, change;
224
225 if (mutex_lock_interruptible(&chip->audio_mutex))
226 return -EINTR;
227
228 for (i = 0; i < 4; i++)
229 val |= (unsigned int) ucontrol->value.iec958.status[i] << (i * 8);
230
231 change = val != chip->spdif_status;
232 chip->spdif_status = val;
233
234 mutex_unlock(&chip->audio_mutex);
235 return change;
236}
237
238static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
239 struct snd_ctl_elem_info *uinfo)
240{
241 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
242 uinfo->count = 1;
243 return 0;
244}
245
246static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol)
248{
249 /* bcm2835 supports only consumer mode and sets all other format flags
250 * automatically. So the only thing left is signalling non-audio
251 * content */
252 ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
253 return 0;
254}
255
256static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo)
258{
259 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
260 uinfo->count = 1;
261 return 0;
262}
263
264static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
265 struct snd_ctl_elem_value *ucontrol)
266{
267 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
268 int i;
269
270 if (mutex_lock_interruptible(&chip->audio_mutex))
271 return -EINTR;
272
273 for (i = 0; i < 4; i++)
274 ucontrol->value.iec958.status[i] =
275 (chip->spdif_status >> (i * 8)) & 0xff;
276
277 mutex_unlock(&chip->audio_mutex);
278 return 0;
279}
280
281static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
282 struct snd_ctl_elem_value *ucontrol)
283{
284 struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
285 unsigned int val = 0;
286 int i, change;
287
288 if (mutex_lock_interruptible(&chip->audio_mutex))
289 return -EINTR;
290
291 for (i = 0; i < 4; i++)
292 val |= (unsigned int) ucontrol->value.iec958.status[i] << (i * 8);
293 change = val != chip->spdif_status;
294 chip->spdif_status = val;
295
296 mutex_unlock(&chip->audio_mutex);
297 return change;
298}
299
300static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
301 {
302 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
303 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
304 .info = snd_bcm2835_spdif_default_info,
305 .get = snd_bcm2835_spdif_default_get,
306 .put = snd_bcm2835_spdif_default_put
307 },
308 {
309 .access = SNDRV_CTL_ELEM_ACCESS_READ,
310 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
311 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
312 .info = snd_bcm2835_spdif_mask_info,
313 .get = snd_bcm2835_spdif_mask_get,
314 },
315 {
316 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
317 SNDRV_CTL_ELEM_ACCESS_INACTIVE,
318 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
319 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
320 .info = snd_bcm2835_spdif_stream_info,
321 .get = snd_bcm2835_spdif_stream_get,
322 .put = snd_bcm2835_spdif_stream_put,
323 },
324};
325
326int snd_bcm2835_new_ctl(struct bcm2835_chip *chip)
327{
328 int err;
329 unsigned int idx;
330
331 strcpy(chip->card->mixername, "Broadcom Mixer");
332 for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
333 err = snd_ctl_add(chip->card,
334 snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
335 if (err < 0)
336 return err;
337 }
338 for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
339 err = snd_ctl_add(chip->card,
340 snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
341 if (err < 0)
342 return err;
343 }
344 return 0;
345}
diff --git a/drivers/staging/bcm2835-audio/bcm2835-pcm.c b/drivers/staging/bcm2835-audio/bcm2835-pcm.c
new file mode 100644
index 000000000000..16127e062661
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/bcm2835-pcm.c
@@ -0,0 +1,554 @@
1/*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14
15#include <linux/interrupt.h>
16#include <linux/slab.h>
17
18#include <sound/asoundef.h>
19
20#include "bcm2835.h"
21
22/* hardware definition */
23static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
24 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
25 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
26 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
27 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
28 .rate_min = 8000,
29 .rate_max = 48000,
30 .channels_min = 1,
31 .channels_max = 2,
32 .buffer_bytes_max = 128 * 1024,
33 .period_bytes_min = 1 * 1024,
34 .period_bytes_max = 128 * 1024,
35 .periods_min = 1,
36 .periods_max = 128,
37};
38
39static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
40 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
41 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
42 .formats = SNDRV_PCM_FMTBIT_S16_LE,
43 .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
44 SNDRV_PCM_RATE_48000,
45 .rate_min = 44100,
46 .rate_max = 48000,
47 .channels_min = 2,
48 .channels_max = 2,
49 .buffer_bytes_max = 128 * 1024,
50 .period_bytes_min = 1 * 1024,
51 .period_bytes_max = 128 * 1024,
52 .periods_min = 1,
53 .periods_max = 128,
54};
55
56static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
57{
58 audio_info("Freeing up alsa stream here ..\n");
59 if (runtime->private_data)
60 kfree(runtime->private_data);
61 runtime->private_data = NULL;
62}
63
64void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream)
65{
66 unsigned int consumed = 0;
67 int new_period = 0;
68
69 audio_info(" .. IN\n");
70
71 audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
72 alsa_stream ? alsa_stream->substream : 0);
73
74 if (alsa_stream->open)
75 consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
76
77 /* We get called only if playback was triggered, So, the number of buffers we retrieve in
78 * each iteration are the buffers that have been played out already
79 */
80
81 if (alsa_stream->period_size) {
82 if ((alsa_stream->pos / alsa_stream->period_size) !=
83 ((alsa_stream->pos + consumed) / alsa_stream->period_size))
84 new_period = 1;
85 }
86 audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
87 alsa_stream->pos,
88 consumed,
89 alsa_stream->buffer_size,
90 (int) (alsa_stream->period_size * alsa_stream->substream->runtime->periods),
91 frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
92 new_period);
93 if (alsa_stream->buffer_size) {
94 alsa_stream->pos += consumed &~(1 << 30);
95 alsa_stream->pos %= alsa_stream->buffer_size;
96 }
97
98 if (alsa_stream->substream) {
99 if (new_period)
100 snd_pcm_period_elapsed(alsa_stream->substream);
101 } else {
102 audio_warning(" unexpected NULL substream\n");
103 }
104 audio_info(" .. OUT\n");
105}
106
107/* open callback */
108static int snd_bcm2835_playback_open_generic(
109 struct snd_pcm_substream *substream, int spdif)
110{
111 struct bcm2835_chip *chip = snd_pcm_substream_chip(substream);
112 struct snd_pcm_runtime *runtime = substream->runtime;
113 struct bcm2835_alsa_stream *alsa_stream;
114 int idx;
115 int err;
116
117 audio_info(" .. IN (%d)\n", substream->number);
118
119 if (mutex_lock_interruptible(&chip->audio_mutex)) {
120 audio_error("Interrupted whilst waiting for lock\n");
121 return -EINTR;
122 }
123 audio_info("Alsa open (%d)\n", substream->number);
124 idx = substream->number;
125
126 if (spdif && chip->opened) {
127 err = -EBUSY;
128 goto out;
129 } else if (!spdif && (chip->opened & (1 << idx))) {
130 err = -EBUSY;
131 goto out;
132 }
133 if (idx >= MAX_SUBSTREAMS) {
134 audio_error
135 ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
136 idx, MAX_SUBSTREAMS);
137 err = -ENODEV;
138 goto out;
139 }
140
141 /* Check if we are ready */
142 if (!(chip->avail_substreams & (1 << idx))) {
143 /* We are not ready yet */
144 audio_error("substream(%d) device is not ready yet\n", idx);
145 err = -EAGAIN;
146 goto out;
147 }
148
149 alsa_stream = kzalloc(sizeof(*alsa_stream), GFP_KERNEL);
150 if (!alsa_stream) {
151 err = -ENOMEM;
152 goto out;
153 }
154
155 /* Initialise alsa_stream */
156 alsa_stream->chip = chip;
157 alsa_stream->substream = substream;
158 alsa_stream->idx = idx;
159
160 sema_init(&alsa_stream->buffers_update_sem, 0);
161 sema_init(&alsa_stream->control_sem, 0);
162 spin_lock_init(&alsa_stream->lock);
163
164 err = bcm2835_audio_open(alsa_stream);
165 if (err) {
166 kfree(alsa_stream);
167 goto out;
168 }
169 runtime->private_data = alsa_stream;
170 runtime->private_free = snd_bcm2835_playback_free;
171 if (spdif) {
172 runtime->hw = snd_bcm2835_playback_spdif_hw;
173 } else {
174 /* clear spdif status, as we are not in spdif mode */
175 chip->spdif_status = 0;
176 runtime->hw = snd_bcm2835_playback_hw;
177 }
178 /* minimum 16 bytes alignment (for vchiq bulk transfers) */
179 snd_pcm_hw_constraint_step(runtime,
180 0,
181 SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
182 16);
183
184 chip->alsa_stream[idx] = alsa_stream;
185
186 chip->opened |= (1 << idx);
187 alsa_stream->open = 1;
188 alsa_stream->draining = 1;
189
190out:
191 mutex_unlock(&chip->audio_mutex);
192
193 audio_info(" .. OUT =%d\n", err);
194
195 return err;
196}
197
198static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
199{
200 return snd_bcm2835_playback_open_generic(substream, 0);
201}
202
203static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
204{
205 return snd_bcm2835_playback_open_generic(substream, 1);
206}
207
208/* close callback */
209static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
210{
211 /* the hardware-specific codes will be here */
212
213 struct bcm2835_chip *chip;
214 struct snd_pcm_runtime *runtime;
215 struct bcm2835_alsa_stream *alsa_stream;
216
217 audio_info(" .. IN\n");
218
219 chip = snd_pcm_substream_chip(substream);
220 if (mutex_lock_interruptible(&chip->audio_mutex)) {
221 audio_error("Interrupted whilst waiting for lock\n");
222 return -EINTR;
223 }
224 runtime = substream->runtime;
225 alsa_stream = runtime->private_data;
226
227 audio_info("Alsa close\n");
228
229 /*
230 * Call stop if it's still running. This happens when app
231 * is force killed and we don't get a stop trigger.
232 */
233 if (alsa_stream->running) {
234 int err;
235 err = bcm2835_audio_stop(alsa_stream);
236 alsa_stream->running = 0;
237 if (err)
238 audio_error(" Failed to STOP alsa device\n");
239 }
240
241 alsa_stream->period_size = 0;
242 alsa_stream->buffer_size = 0;
243
244 if (alsa_stream->open) {
245 alsa_stream->open = 0;
246 bcm2835_audio_close(alsa_stream);
247 }
248 if (alsa_stream->chip)
249 alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
250 /*
251 * Do not free up alsa_stream here, it will be freed up by
252 * runtime->private_free callback we registered in *_open above
253 */
254
255 chip->opened &= ~(1 << substream->number);
256
257 mutex_unlock(&chip->audio_mutex);
258 audio_info(" .. OUT\n");
259
260 return 0;
261}
262
263/* hw_params callback */
264static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
265 struct snd_pcm_hw_params *params)
266{
267 struct snd_pcm_runtime *runtime = substream->runtime;
268 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
269 int err;
270
271 audio_info(" .. IN\n");
272
273 err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
274 if (err < 0) {
275 audio_error
276 (" pcm_lib_malloc failed to allocated pages for buffers\n");
277 return err;
278 }
279
280 alsa_stream->channels = params_channels(params);
281 alsa_stream->params_rate = params_rate(params);
282 alsa_stream->pcm_format_width = snd_pcm_format_width(params_format(params));
283 audio_info(" .. OUT\n");
284
285 return err;
286}
287
288/* hw_free callback */
289static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
290{
291 audio_info(" .. IN\n");
292 return snd_pcm_lib_free_pages(substream);
293}
294
295/* prepare callback */
296static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
297{
298 struct bcm2835_chip *chip = snd_pcm_substream_chip(substream);
299 struct snd_pcm_runtime *runtime = substream->runtime;
300 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
301 int channels;
302 int err;
303
304 audio_info(" .. IN\n");
305
306 if (mutex_lock_interruptible(&chip->audio_mutex))
307 return -EINTR;
308
309 /* notify the vchiq that it should enter spdif passthrough mode by
310 * setting channels=0 (see
311 * https://github.com/raspberrypi/linux/issues/528) */
312 if (chip->spdif_status & IEC958_AES0_NONAUDIO)
313 channels = 0;
314 else
315 channels = alsa_stream->channels;
316
317 err = bcm2835_audio_set_params(alsa_stream, channels,
318 alsa_stream->params_rate,
319 alsa_stream->pcm_format_width);
320 if (err < 0) {
321 audio_error(" error setting hw params\n");
322 }
323
324 bcm2835_audio_setup(alsa_stream);
325
326 /* in preparation of the stream, set the controls (volume level) of the stream */
327 bcm2835_audio_set_ctls(alsa_stream->chip);
328
329
330 memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
331
332 alsa_stream->pcm_indirect.hw_buffer_size =
333 alsa_stream->pcm_indirect.sw_buffer_size =
334 snd_pcm_lib_buffer_bytes(substream);
335
336 alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
337 alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
338 alsa_stream->pos = 0;
339
340 audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
341 alsa_stream->buffer_size, alsa_stream->period_size,
342 alsa_stream->pos, runtime->frame_bits);
343
344 mutex_unlock(&chip->audio_mutex);
345 audio_info(" .. OUT\n");
346 return 0;
347}
348
349static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
350 struct snd_pcm_indirect *rec, size_t bytes)
351{
352 struct snd_pcm_runtime *runtime = substream->runtime;
353 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
354 void *src = (void *) (substream->runtime->dma_area + rec->sw_data);
355 int err;
356
357 err = bcm2835_audio_write(alsa_stream, bytes, src);
358 if (err)
359 audio_error(" Failed to transfer to alsa device (%d)\n", err);
360
361}
362
363static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
364{
365 struct snd_pcm_runtime *runtime = substream->runtime;
366 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
367 struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
368
369 pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
370 snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
371 snd_bcm2835_pcm_transfer);
372 return 0;
373}
374
375/* trigger callback */
376static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
377{
378 struct snd_pcm_runtime *runtime = substream->runtime;
379 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
380 int err = 0;
381
382 audio_info(" .. IN\n");
383
384 switch (cmd) {
385 case SNDRV_PCM_TRIGGER_START:
386 audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
387 alsa_stream->running);
388 if (!alsa_stream->running) {
389 err = bcm2835_audio_start(alsa_stream);
390 if (!err) {
391 alsa_stream->pcm_indirect.hw_io =
392 alsa_stream->pcm_indirect.hw_data =
393 bytes_to_frames(runtime,
394 alsa_stream->pos);
395 substream->ops->ack(substream);
396 alsa_stream->running = 1;
397 alsa_stream->draining = 1;
398 } else {
399 audio_error(" Failed to START alsa device (%d)\n", err);
400 }
401 }
402 break;
403 case SNDRV_PCM_TRIGGER_STOP:
404 audio_debug
405 ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
406 alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
407 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
408 audio_info("DRAINING\n");
409 alsa_stream->draining = 1;
410 } else {
411 audio_info("DROPPING\n");
412 alsa_stream->draining = 0;
413 }
414 if (alsa_stream->running) {
415 err = bcm2835_audio_stop(alsa_stream);
416 if (err != 0)
417 audio_error(" Failed to STOP alsa device (%d)\n", err);
418 alsa_stream->running = 0;
419 }
420 break;
421 default:
422 err = -EINVAL;
423 }
424
425 audio_info(" .. OUT\n");
426 return err;
427}
428
429/* pointer callback */
430static snd_pcm_uframes_t
431snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
432{
433 struct snd_pcm_runtime *runtime = substream->runtime;
434 struct bcm2835_alsa_stream *alsa_stream = runtime->private_data;
435
436 audio_info(" .. IN\n");
437
438 audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
439 frames_to_bytes(runtime, runtime->status->hw_ptr),
440 frames_to_bytes(runtime, runtime->control->appl_ptr),
441 alsa_stream->pos);
442
443 audio_info(" .. OUT\n");
444 return snd_pcm_indirect_playback_pointer(substream,
445 &alsa_stream->pcm_indirect,
446 alsa_stream->pos);
447}
448
449static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
450 unsigned int cmd, void *arg)
451{
452 int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
453
454 audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
455 cmd, arg, arg ? *(unsigned *) arg : 0, ret);
456 return ret;
457}
458
459/* operators */
460static struct snd_pcm_ops snd_bcm2835_playback_ops = {
461 .open = snd_bcm2835_playback_open,
462 .close = snd_bcm2835_playback_close,
463 .ioctl = snd_bcm2835_pcm_lib_ioctl,
464 .hw_params = snd_bcm2835_pcm_hw_params,
465 .hw_free = snd_bcm2835_pcm_hw_free,
466 .prepare = snd_bcm2835_pcm_prepare,
467 .trigger = snd_bcm2835_pcm_trigger,
468 .pointer = snd_bcm2835_pcm_pointer,
469 .ack = snd_bcm2835_pcm_ack,
470};
471
472static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
473 .open = snd_bcm2835_playback_spdif_open,
474 .close = snd_bcm2835_playback_close,
475 .ioctl = snd_bcm2835_pcm_lib_ioctl,
476 .hw_params = snd_bcm2835_pcm_hw_params,
477 .hw_free = snd_bcm2835_pcm_hw_free,
478 .prepare = snd_bcm2835_pcm_prepare,
479 .trigger = snd_bcm2835_pcm_trigger,
480 .pointer = snd_bcm2835_pcm_pointer,
481 .ack = snd_bcm2835_pcm_ack,
482};
483
484/* create a pcm device */
485int snd_bcm2835_new_pcm(struct bcm2835_chip *chip)
486{
487 struct snd_pcm *pcm;
488 int err;
489
490 audio_info(" .. IN\n");
491 mutex_init(&chip->audio_mutex);
492 if (mutex_lock_interruptible(&chip->audio_mutex)) {
493 audio_error("Interrupted whilst waiting for lock\n");
494 return -EINTR;
495 }
496 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
497 if (err < 0)
498 goto out;
499 pcm->private_data = chip;
500 strcpy(pcm->name, "bcm2835 ALSA");
501 chip->pcm = pcm;
502 chip->dest = AUDIO_DEST_AUTO;
503 chip->volume = alsa2chip(0);
504 chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
505 /* set operators */
506 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
507 &snd_bcm2835_playback_ops);
508
509 /* pre-allocation of buffers */
510 /* NOTE: this may fail */
511 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
512 snd_dma_continuous_data(GFP_KERNEL),
513 snd_bcm2835_playback_hw.buffer_bytes_max,
514 snd_bcm2835_playback_hw.buffer_bytes_max);
515
516
517out:
518 mutex_unlock(&chip->audio_mutex);
519 audio_info(" .. OUT\n");
520
521 return 0;
522}
523
524int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip)
525{
526 struct snd_pcm *pcm;
527 int err;
528
529 audio_info(" .. IN\n");
530 if (mutex_lock_interruptible(&chip->audio_mutex)) {
531 audio_error("Interrupted whilst waiting for lock\n");
532 return -EINTR;
533 }
534 err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
535 if (err < 0)
536 goto out;
537
538 pcm->private_data = chip;
539 strcpy(pcm->name, "bcm2835 IEC958/HDMI");
540 chip->pcm_spdif = pcm;
541 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
542 &snd_bcm2835_playback_spdif_ops);
543
544 /* pre-allocation of buffers */
545 /* NOTE: this may fail */
546 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
547 snd_dma_continuous_data(GFP_KERNEL),
548 snd_bcm2835_playback_spdif_hw.buffer_bytes_max, snd_bcm2835_playback_spdif_hw.buffer_bytes_max);
549out:
550 mutex_unlock(&chip->audio_mutex);
551 audio_info(" .. OUT\n");
552
553 return 0;
554}
diff --git a/drivers/staging/bcm2835-audio/bcm2835-vchiq.c b/drivers/staging/bcm2835-audio/bcm2835-vchiq.c
new file mode 100644
index 000000000000..fa23a13f8d95
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/bcm2835-vchiq.c
@@ -0,0 +1,912 @@
1/*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14
15#include <linux/device.h>
16#include <sound/core.h>
17#include <sound/initval.h>
18#include <sound/pcm.h>
19#include <linux/io.h>
20#include <linux/interrupt.h>
21#include <linux/fs.h>
22#include <linux/file.h>
23#include <linux/mm.h>
24#include <linux/syscalls.h>
25#include <linux/uaccess.h>
26#include <linux/slab.h>
27#include <linux/delay.h>
28#include <linux/atomic.h>
29#include <linux/module.h>
30#include <linux/completion.h>
31
32#include "bcm2835.h"
33
34/* ---- Include Files -------------------------------------------------------- */
35
36#include "interface/vchi/vchi.h"
37#include "vc_vchi_audioserv_defs.h"
38
39/* ---- Private Constants and Types ------------------------------------------ */
40
41#define BCM2835_AUDIO_STOP 0
42#define BCM2835_AUDIO_START 1
43#define BCM2835_AUDIO_WRITE 2
44
45/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
46#ifdef AUDIO_DEBUG_ENABLE
47#define LOG_ERR(fmt, arg...) pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
48#define LOG_WARN(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
49#define LOG_INFO(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
50#define LOG_DBG(fmt, arg...) pr_info("%s:%d " fmt, __func__, __LINE__, ##arg)
51#else
52#define LOG_ERR(fmt, arg...) pr_err("%s:%d " fmt, __func__, __LINE__, ##arg)
53#define LOG_WARN(fmt, arg...) no_printk(fmt, ##arg)
54#define LOG_INFO(fmt, arg...) no_printk(fmt, ##arg)
55#define LOG_DBG(fmt, arg...) no_printk(fmt, ##arg)
56#endif
57
58struct bcm2835_audio_instance {
59 unsigned int num_connections;
60 VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
61 struct completion msg_avail_comp;
62 struct mutex vchi_mutex;
63 struct bcm2835_alsa_stream *alsa_stream;
64 int result;
65 short peer_version;
66};
67
68static bool force_bulk;
69
70/* ---- Private Variables ---------------------------------------------------- */
71
72/* ---- Private Function Prototypes ------------------------------------------ */
73
74/* ---- Private Functions ---------------------------------------------------- */
75
76static int bcm2835_audio_stop_worker(struct bcm2835_alsa_stream *alsa_stream);
77static int bcm2835_audio_start_worker(struct bcm2835_alsa_stream *alsa_stream);
78static int bcm2835_audio_write_worker(struct bcm2835_alsa_stream *alsa_stream,
79 unsigned int count, void *src);
80
81// Routine to send a message across a service
82
83static int
84bcm2835_vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
85 void *data,
86 unsigned int size)
87{
88 return vchi_queue_kernel_message(handle,
89 data,
90 size);
91}
92
93static const u32 BCM2835_AUDIO_WRITE_COOKIE1 = ('B' << 24 | 'C' << 16 |
94 'M' << 8 | 'A');
95static const u32 BCM2835_AUDIO_WRITE_COOKIE2 = ('D' << 24 | 'A' << 16 |
96 'T' << 8 | 'A');
97
98struct bcm2835_audio_work {
99 struct work_struct my_work;
100 struct bcm2835_alsa_stream *alsa_stream;
101 int cmd;
102 void *src;
103 unsigned int count;
104};
105
106static void my_wq_function(struct work_struct *work)
107{
108 struct bcm2835_audio_work *w =
109 container_of(work, struct bcm2835_audio_work, my_work);
110 int ret = -9;
111
112 LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
113 switch (w->cmd) {
114 case BCM2835_AUDIO_START:
115 ret = bcm2835_audio_start_worker(w->alsa_stream);
116 break;
117 case BCM2835_AUDIO_STOP:
118 ret = bcm2835_audio_stop_worker(w->alsa_stream);
119 break;
120 case BCM2835_AUDIO_WRITE:
121 ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
122 w->src);
123 break;
124 default:
125 LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
126 break;
127 }
128 kfree((void *) work);
129 LOG_DBG(" .. OUT %d\n", ret);
130}
131
132int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream)
133{
134 int ret = -1;
135
136 LOG_DBG(" .. IN\n");
137 if (alsa_stream->my_wq) {
138 struct bcm2835_audio_work *work;
139
140 work = kmalloc(sizeof(*work), GFP_ATOMIC);
141 /*--- Queue some work (item 1) ---*/
142 if (work) {
143 INIT_WORK(&work->my_work, my_wq_function);
144 work->alsa_stream = alsa_stream;
145 work->cmd = BCM2835_AUDIO_START;
146 if (queue_work(alsa_stream->my_wq, &work->my_work))
147 ret = 0;
148 } else
149 LOG_ERR(" .. Error: NULL work kmalloc\n");
150 }
151 LOG_DBG(" .. OUT %d\n", ret);
152 return ret;
153}
154
155int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream)
156{
157 int ret = -1;
158
159 LOG_DBG(" .. IN\n");
160 if (alsa_stream->my_wq) {
161 struct bcm2835_audio_work *work;
162
163 work = kmalloc(sizeof(*work), GFP_ATOMIC);
164 /*--- Queue some work (item 1) ---*/
165 if (work) {
166 INIT_WORK(&work->my_work, my_wq_function);
167 work->alsa_stream = alsa_stream;
168 work->cmd = BCM2835_AUDIO_STOP;
169 if (queue_work(alsa_stream->my_wq, &work->my_work))
170 ret = 0;
171 } else
172 LOG_ERR(" .. Error: NULL work kmalloc\n");
173 }
174 LOG_DBG(" .. OUT %d\n", ret);
175 return ret;
176}
177
178int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
179 unsigned int count, void *src)
180{
181 int ret = -1;
182
183 LOG_DBG(" .. IN\n");
184 if (alsa_stream->my_wq) {
185 struct bcm2835_audio_work *work;
186
187 work = kmalloc(sizeof(*work), GFP_ATOMIC);
188 /*--- Queue some work (item 1) ---*/
189 if (work) {
190 INIT_WORK(&work->my_work, my_wq_function);
191 work->alsa_stream = alsa_stream;
192 work->cmd = BCM2835_AUDIO_WRITE;
193 work->src = src;
194 work->count = count;
195 if (queue_work(alsa_stream->my_wq, &work->my_work))
196 ret = 0;
197 } else
198 LOG_ERR(" .. Error: NULL work kmalloc\n");
199 }
200 LOG_DBG(" .. OUT %d\n", ret);
201 return ret;
202}
203
204static void my_workqueue_init(struct bcm2835_alsa_stream *alsa_stream)
205{
206 alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
207 return;
208}
209
210static void my_workqueue_quit(struct bcm2835_alsa_stream *alsa_stream)
211{
212 if (alsa_stream->my_wq) {
213 flush_workqueue(alsa_stream->my_wq);
214 destroy_workqueue(alsa_stream->my_wq);
215 alsa_stream->my_wq = NULL;
216 }
217 return;
218}
219
220static void audio_vchi_callback(void *param,
221 const VCHI_CALLBACK_REASON_T reason,
222 void *msg_handle)
223{
224 struct bcm2835_audio_instance *instance = param;
225 int status;
226 int msg_len;
227 struct vc_audio_msg m;
228
229 LOG_DBG(" .. IN instance=%p, handle=%p, alsa=%p, reason=%d, handle=%p\n",
230 instance, instance ? instance->vchi_handle[0] : NULL, instance ? instance->alsa_stream : NULL, reason, msg_handle);
231
232 if (reason != VCHI_CALLBACK_MSG_AVAILABLE) {
233 return;
234 }
235 if (!instance) {
236 LOG_ERR(" .. instance is null\n");
237 BUG();
238 return;
239 }
240 if (!instance->vchi_handle[0]) {
241 LOG_ERR(" .. instance->vchi_handle[0] is null\n");
242 BUG();
243 return;
244 }
245 status = vchi_msg_dequeue(instance->vchi_handle[0],
246 &m, sizeof(m), &msg_len, VCHI_FLAGS_NONE);
247 if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
248 LOG_DBG(" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
249 instance, m.u.result.success);
250 instance->result = m.u.result.success;
251 complete(&instance->msg_avail_comp);
252 } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
253 struct bcm2835_alsa_stream *alsa_stream = instance->alsa_stream;
254
255 LOG_DBG(" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
256 instance, m.u.complete.count);
257 if (m.u.complete.cookie1 != BCM2835_AUDIO_WRITE_COOKIE1 ||
258 m.u.complete.cookie2 != BCM2835_AUDIO_WRITE_COOKIE2)
259 LOG_ERR(" .. response is corrupt\n");
260 else if (alsa_stream) {
261 atomic_add(m.u.complete.count,
262 &alsa_stream->retrieved);
263 bcm2835_playback_fifo(alsa_stream);
264 } else {
265 LOG_ERR(" .. unexpected alsa_stream=%p\n",
266 alsa_stream);
267 }
268 } else {
269 LOG_ERR(" .. unexpected m.type=%d\n", m.type);
270 }
271 LOG_DBG(" .. OUT\n");
272}
273
274static struct bcm2835_audio_instance *
275vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
276 VCHI_CONNECTION_T **vchi_connections,
277 unsigned int num_connections)
278{
279 unsigned int i;
280 struct bcm2835_audio_instance *instance;
281 int status;
282
283 LOG_DBG("%s: start", __func__);
284
285 if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
286 LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
287 __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
288
289 return NULL;
290 }
291 /* Allocate memory for this instance */
292 instance = kmalloc(sizeof(*instance), GFP_KERNEL);
293 if (!instance)
294 return NULL;
295
296 memset(instance, 0, sizeof(*instance));
297 instance->num_connections = num_connections;
298
299 /* Create a lock for exclusive, serialized VCHI connection access */
300 mutex_init(&instance->vchi_mutex);
301 /* Open the VCHI service connections */
302 for (i = 0; i < num_connections; i++) {
303 SERVICE_CREATION_T params = {
304 VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
305 VC_AUDIO_SERVER_NAME, // 4cc service code
306 vchi_connections[i], // passed in fn pointers
307 0, // rx fifo size (unused)
308 0, // tx fifo size (unused)
309 audio_vchi_callback, // service callback
310 instance, // service callback parameter
311 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
312 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
313 0 // want crc check on bulk transfers
314 };
315
316 LOG_DBG("%s: about to open %i\n", __func__, i);
317 status = vchi_service_open(vchi_instance, &params,
318 &instance->vchi_handle[i]);
319 LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
320 if (status) {
321 LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n",
322 __func__, status);
323
324 goto err_close_services;
325 }
326 /* Finished with the service for now */
327 vchi_service_release(instance->vchi_handle[i]);
328 }
329
330 LOG_DBG("%s: okay\n", __func__);
331 return instance;
332
333err_close_services:
334 for (i = 0; i < instance->num_connections; i++) {
335 LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]);
336 if (instance->vchi_handle[i])
337 vchi_service_close(instance->vchi_handle[i]);
338 }
339
340 kfree(instance);
341 LOG_ERR("%s: error\n", __func__);
342
343 return NULL;
344}
345
346static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)
347{
348 unsigned int i;
349
350 LOG_DBG(" .. IN\n");
351
352 if (!instance) {
353 LOG_ERR("%s: invalid handle %p\n", __func__, instance);
354
355 return -1;
356 }
357
358 LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
359 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
360 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
361 instance->num_connections);
362 return -EINTR;
363 }
364
365 /* Close all VCHI service connections */
366 for (i = 0; i < instance->num_connections; i++) {
367 int status;
368
369 LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
370 vchi_service_use(instance->vchi_handle[i]);
371
372 status = vchi_service_close(instance->vchi_handle[i]);
373 if (status) {
374 LOG_DBG("%s: failed to close VCHI service connection (status=%d)\n",
375 __func__, status);
376 }
377 }
378
379 mutex_unlock(&instance->vchi_mutex);
380
381 kfree(instance);
382
383 LOG_DBG(" .. OUT\n");
384
385 return 0;
386}
387
388static int bcm2835_audio_open_connection(struct bcm2835_alsa_stream *alsa_stream)
389{
390 static VCHI_INSTANCE_T vchi_instance;
391 static VCHI_CONNECTION_T *vchi_connection;
392 static int initted;
393 struct bcm2835_audio_instance *instance =
394 (struct bcm2835_audio_instance *)alsa_stream->instance;
395 int ret;
396
397 LOG_DBG(" .. IN\n");
398
399 LOG_INFO("%s: start\n", __func__);
400 BUG_ON(instance);
401 if (instance) {
402 LOG_ERR("%s: VCHI instance already open (%p)\n",
403 __func__, instance);
404 instance->alsa_stream = alsa_stream;
405 alsa_stream->instance = instance;
406 ret = 0; // xxx todo -1;
407 goto err_free_mem;
408 }
409
410 /* Initialize and create a VCHI connection */
411 if (!initted) {
412 ret = vchi_initialise(&vchi_instance);
413 if (ret) {
414 LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
415 __func__, ret);
416
417 ret = -EIO;
418 goto err_free_mem;
419 }
420 ret = vchi_connect(NULL, 0, vchi_instance);
421 if (ret) {
422 LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
423 __func__, ret);
424
425 ret = -EIO;
426 goto err_free_mem;
427 }
428 initted = 1;
429 }
430
431 /* Initialize an instance of the audio service */
432 instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
433
434 if (!instance) {
435 LOG_ERR("%s: failed to initialize audio service\n", __func__);
436
437 ret = -EPERM;
438 goto err_free_mem;
439 }
440
441 instance->alsa_stream = alsa_stream;
442 alsa_stream->instance = instance;
443
444 LOG_DBG(" success !\n");
445 ret = 0;
446err_free_mem:
447 LOG_DBG(" .. OUT\n");
448
449 return ret;
450}
451
452int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream)
453{
454 struct bcm2835_audio_instance *instance;
455 struct vc_audio_msg m;
456 int status;
457 int ret;
458
459 LOG_DBG(" .. IN\n");
460
461 my_workqueue_init(alsa_stream);
462
463 ret = bcm2835_audio_open_connection(alsa_stream);
464 if (ret) {
465 ret = -1;
466 goto exit;
467 }
468 instance = alsa_stream->instance;
469 LOG_DBG(" instance (%p)\n", instance);
470
471 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
472 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
473 return -EINTR;
474 }
475 vchi_service_use(instance->vchi_handle[0]);
476
477 m.type = VC_AUDIO_MSG_TYPE_OPEN;
478
479 /* Send the message to the videocore */
480 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
481 &m, sizeof(m));
482
483 if (status) {
484 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
485 __func__, status);
486
487 ret = -1;
488 goto unlock;
489 }
490
491 ret = 0;
492
493unlock:
494 vchi_service_release(instance->vchi_handle[0]);
495 mutex_unlock(&instance->vchi_mutex);
496exit:
497 LOG_DBG(" .. OUT\n");
498 return ret;
499}
500
501static int bcm2835_audio_set_ctls_chan(struct bcm2835_alsa_stream *alsa_stream,
502 struct bcm2835_chip *chip)
503{
504 struct vc_audio_msg m;
505 struct bcm2835_audio_instance *instance = alsa_stream->instance;
506 int status;
507 int ret;
508
509 LOG_DBG(" .. IN\n");
510
511 LOG_INFO(" Setting ALSA dest(%d), volume(%d)\n",
512 chip->dest, chip->volume);
513
514 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
515 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
516 instance->num_connections);
517 return -EINTR;
518 }
519 vchi_service_use(instance->vchi_handle[0]);
520
521 instance->result = -1;
522
523 m.type = VC_AUDIO_MSG_TYPE_CONTROL;
524 m.u.control.dest = chip->dest;
525 m.u.control.volume = chip->volume;
526
527 /* Create the message available completion */
528 init_completion(&instance->msg_avail_comp);
529
530 /* Send the message to the videocore */
531 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
532 &m, sizeof(m));
533
534 if (status) {
535 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
536 __func__, status);
537
538 ret = -1;
539 goto unlock;
540 }
541
542 /* We are expecting a reply from the videocore */
543 wait_for_completion(&instance->msg_avail_comp);
544
545 if (instance->result) {
546 LOG_ERR("%s: result=%d\n", __func__, instance->result);
547
548 ret = -1;
549 goto unlock;
550 }
551
552 ret = 0;
553
554unlock:
555 vchi_service_release(instance->vchi_handle[0]);
556 mutex_unlock(&instance->vchi_mutex);
557
558 LOG_DBG(" .. OUT\n");
559 return ret;
560}
561
562int bcm2835_audio_set_ctls(struct bcm2835_chip *chip)
563{
564 int i;
565 int ret = 0;
566
567 LOG_DBG(" .. IN\n");
568 LOG_DBG(" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
569
570 /* change ctls for all substreams */
571 for (i = 0; i < MAX_SUBSTREAMS; i++) {
572 if (chip->avail_substreams & (1 << i)) {
573 if (!chip->alsa_stream[i]) {
574 LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
575 ret = 0;
576 } else if (bcm2835_audio_set_ctls_chan(chip->alsa_stream[i], chip) != 0) {
577 LOG_ERR("Couldn't set the controls for stream %d\n", i);
578 ret = -1;
579 } else {
580 LOG_DBG(" Controls set for stream %d\n", i);
581 }
582 }
583 }
584 LOG_DBG(" .. OUT ret=%d\n", ret);
585 return ret;
586}
587
588int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
589 unsigned int channels, unsigned int samplerate,
590 unsigned int bps)
591{
592 struct vc_audio_msg m;
593 struct bcm2835_audio_instance *instance = alsa_stream->instance;
594 int status;
595 int ret;
596
597 LOG_DBG(" .. IN\n");
598
599 LOG_INFO(" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
600 channels, samplerate, bps);
601
602 /* resend ctls - alsa_stream may not have been open when first send */
603 ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
604 if (ret) {
605 LOG_ERR(" Alsa controls not supported\n");
606 return -EINVAL;
607 }
608
609 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
610 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n", instance->num_connections);
611 return -EINTR;
612 }
613 vchi_service_use(instance->vchi_handle[0]);
614
615 instance->result = -1;
616
617 m.type = VC_AUDIO_MSG_TYPE_CONFIG;
618 m.u.config.channels = channels;
619 m.u.config.samplerate = samplerate;
620 m.u.config.bps = bps;
621
622 /* Create the message available completion */
623 init_completion(&instance->msg_avail_comp);
624
625 /* Send the message to the videocore */
626 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
627 &m, sizeof(m));
628
629 if (status) {
630 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
631 __func__, status);
632
633 ret = -1;
634 goto unlock;
635 }
636
637 /* We are expecting a reply from the videocore */
638 wait_for_completion(&instance->msg_avail_comp);
639
640 if (instance->result) {
641 LOG_ERR("%s: result=%d", __func__, instance->result);
642
643 ret = -1;
644 goto unlock;
645 }
646
647 ret = 0;
648
649unlock:
650 vchi_service_release(instance->vchi_handle[0]);
651 mutex_unlock(&instance->vchi_mutex);
652
653 LOG_DBG(" .. OUT\n");
654 return ret;
655}
656
657int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream)
658{
659 LOG_DBG(" .. IN\n");
660
661 LOG_DBG(" .. OUT\n");
662
663 return 0;
664}
665
666static int bcm2835_audio_start_worker(struct bcm2835_alsa_stream *alsa_stream)
667{
668 struct vc_audio_msg m;
669 struct bcm2835_audio_instance *instance = alsa_stream->instance;
670 int status;
671 int ret;
672
673 LOG_DBG(" .. IN\n");
674
675 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
676 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
677 instance->num_connections);
678 return -EINTR;
679 }
680 vchi_service_use(instance->vchi_handle[0]);
681
682 m.type = VC_AUDIO_MSG_TYPE_START;
683
684 /* Send the message to the videocore */
685 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
686 &m, sizeof(m));
687
688 if (status) {
689 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
690 __func__, status);
691
692 ret = -1;
693 goto unlock;
694 }
695
696 ret = 0;
697
698unlock:
699 vchi_service_release(instance->vchi_handle[0]);
700 mutex_unlock(&instance->vchi_mutex);
701 LOG_DBG(" .. OUT\n");
702 return ret;
703}
704
705static int bcm2835_audio_stop_worker(struct bcm2835_alsa_stream *alsa_stream)
706{
707 struct vc_audio_msg m;
708 struct bcm2835_audio_instance *instance = alsa_stream->instance;
709 int status;
710 int ret;
711
712 LOG_DBG(" .. IN\n");
713
714 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
715 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
716 instance->num_connections);
717 return -EINTR;
718 }
719 vchi_service_use(instance->vchi_handle[0]);
720
721 m.type = VC_AUDIO_MSG_TYPE_STOP;
722 m.u.stop.draining = alsa_stream->draining;
723
724 /* Send the message to the videocore */
725 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
726 &m, sizeof(m));
727
728 if (status) {
729 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
730 __func__, status);
731
732 ret = -1;
733 goto unlock;
734 }
735
736 ret = 0;
737
738unlock:
739 vchi_service_release(instance->vchi_handle[0]);
740 mutex_unlock(&instance->vchi_mutex);
741 LOG_DBG(" .. OUT\n");
742 return ret;
743}
744
745int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream)
746{
747 struct vc_audio_msg m;
748 struct bcm2835_audio_instance *instance = alsa_stream->instance;
749 int status;
750 int ret;
751
752 LOG_DBG(" .. IN\n");
753
754 my_workqueue_quit(alsa_stream);
755
756 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
757 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
758 instance->num_connections);
759 return -EINTR;
760 }
761 vchi_service_use(instance->vchi_handle[0]);
762
763 m.type = VC_AUDIO_MSG_TYPE_CLOSE;
764
765 /* Create the message available completion */
766 init_completion(&instance->msg_avail_comp);
767
768 /* Send the message to the videocore */
769 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
770 &m, sizeof(m));
771
772 if (status) {
773 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
774 __func__, status);
775 ret = -1;
776 goto unlock;
777 }
778
779 /* We are expecting a reply from the videocore */
780 wait_for_completion(&instance->msg_avail_comp);
781
782 if (instance->result) {
783 LOG_ERR("%s: failed result (result=%d)\n",
784 __func__, instance->result);
785
786 ret = -1;
787 goto unlock;
788 }
789
790 ret = 0;
791
792unlock:
793 vchi_service_release(instance->vchi_handle[0]);
794 mutex_unlock(&instance->vchi_mutex);
795
796 /* Stop the audio service */
797 vc_vchi_audio_deinit(instance);
798 alsa_stream->instance = NULL;
799
800 LOG_DBG(" .. OUT\n");
801 return ret;
802}
803
804static int bcm2835_audio_write_worker(struct bcm2835_alsa_stream *alsa_stream,
805 unsigned int count, void *src)
806{
807 struct vc_audio_msg m;
808 struct bcm2835_audio_instance *instance = alsa_stream->instance;
809 int status;
810 int ret;
811
812 LOG_DBG(" .. IN\n");
813
814 LOG_INFO(" Writing %d bytes from %p\n", count, src);
815
816 if (mutex_lock_interruptible(&instance->vchi_mutex)) {
817 LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",
818 instance->num_connections);
819 return -EINTR;
820 }
821 vchi_service_use(instance->vchi_handle[0]);
822
823 if (instance->peer_version == 0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0) {
824 LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
825 }
826 m.type = VC_AUDIO_MSG_TYPE_WRITE;
827 m.u.write.count = count;
828 // old version uses bulk, new version uses control
829 m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0 : 4000;
830 m.u.write.cookie1 = BCM2835_AUDIO_WRITE_COOKIE1;
831 m.u.write.cookie2 = BCM2835_AUDIO_WRITE_COOKIE2;
832 m.u.write.silence = src == NULL;
833
834 /* Send the message to the videocore */
835 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
836 &m, sizeof(m));
837
838 if (status) {
839 LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
840 __func__, status);
841
842 ret = -1;
843 goto unlock;
844 }
845 if (!m.u.write.silence) {
846 if (!m.u.write.max_packet) {
847 /* Send the message to the videocore */
848 status = vchi_bulk_queue_transmit(instance->vchi_handle[0],
849 src, count,
850 0 *
851 VCHI_FLAGS_BLOCK_UNTIL_QUEUED
852 +
853 1 *
854 VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
855 NULL);
856 } else {
857 while (count > 0) {
858 int bytes = min((int) m.u.write.max_packet, (int) count);
859
860 status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
861 src, bytes);
862 src = (char *)src + bytes;
863 count -= bytes;
864 }
865 }
866 if (status) {
867 LOG_ERR("%s: failed on vchi_bulk_queue_transmit (status=%d)\n",
868 __func__, status);
869
870 ret = -1;
871 goto unlock;
872 }
873 }
874 ret = 0;
875
876unlock:
877 vchi_service_release(instance->vchi_handle[0]);
878 mutex_unlock(&instance->vchi_mutex);
879 LOG_DBG(" .. OUT\n");
880 return ret;
881}
882
883/**
884 * Returns all buffers from arm->vc
885 */
886void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream)
887{
888 LOG_DBG(" .. IN\n");
889 LOG_DBG(" .. OUT\n");
890 return;
891}
892
893/**
894 * Forces VC to flush(drop) its filled playback buffers and
895 * return them the us. (VC->ARM)
896 */
897void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream)
898{
899 LOG_DBG(" .. IN\n");
900 LOG_DBG(" .. OUT\n");
901}
902
903unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream)
904{
905 unsigned int count = atomic_read(&alsa_stream->retrieved);
906
907 atomic_sub(count, &alsa_stream->retrieved);
908 return count;
909}
910
911module_param(force_bulk, bool, 0444);
912MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
diff --git a/drivers/staging/bcm2835-audio/bcm2835.c b/drivers/staging/bcm2835-audio/bcm2835.c
new file mode 100644
index 000000000000..3a5e528e0ec6
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/bcm2835.c
@@ -0,0 +1,250 @@
1/*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14
15#include <linux/platform_device.h>
16
17#include <linux/init.h>
18#include <linux/slab.h>
19#include <linux/module.h>
20#include <linux/of.h>
21
22#include "bcm2835.h"
23
24/* HACKY global pointers needed for successive probes to work : ssp
25 * But compared against the changes we will have to do in VC audio_ipc code
26 * to export 8 audio_ipc devices as a single IPC device and then monitor all
27 * four devices in a thread, this gets things done quickly and should be easier
28 * to debug if we run into issues
29 */
30
31static struct snd_card *g_card;
32static struct bcm2835_chip *g_chip;
33
34static int snd_bcm2835_free(struct bcm2835_chip *chip)
35{
36 kfree(chip);
37 return 0;
38}
39
40/* component-destructor
41 * (see "Management of Cards and Components")
42 */
43static int snd_bcm2835_dev_free(struct snd_device *device)
44{
45 return snd_bcm2835_free(device->device_data);
46}
47
48/* chip-specific constructor
49 * (see "Management of Cards and Components")
50 */
51static int snd_bcm2835_create(struct snd_card *card,
52 struct platform_device *pdev,
53 struct bcm2835_chip **rchip)
54{
55 struct bcm2835_chip *chip;
56 int err;
57 static struct snd_device_ops ops = {
58 .dev_free = snd_bcm2835_dev_free,
59 };
60
61 *rchip = NULL;
62
63 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
64 if (!chip)
65 return -ENOMEM;
66
67 chip->card = card;
68
69 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
70 if (err < 0) {
71 snd_bcm2835_free(chip);
72 return err;
73 }
74
75 *rchip = chip;
76 return 0;
77}
78
79static int snd_bcm2835_alsa_probe_dt(struct platform_device *pdev)
80{
81 struct device *dev = &pdev->dev;
82 struct bcm2835_chip *chip;
83 struct snd_card *card;
84 u32 numchans;
85 int err, i;
86
87 err = of_property_read_u32(dev->of_node, "brcm,pwm-channels",
88 &numchans);
89 if (err) {
90 dev_err(dev, "Failed to get DT property 'brcm,pwm-channels'");
91 return err;
92 }
93
94 if (numchans == 0 || numchans > MAX_SUBSTREAMS) {
95 numchans = MAX_SUBSTREAMS;
96 dev_warn(dev, "Illegal 'brcm,pwm-channels' value, will use %u\n",
97 numchans);
98 }
99
100 err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card);
101 if (err) {
102 dev_err(dev, "Failed to create soundcard structure\n");
103 return err;
104 }
105
106 snd_card_set_dev(card, dev);
107 strcpy(card->driver, "bcm2835");
108 strcpy(card->shortname, "bcm2835 ALSA");
109 sprintf(card->longname, "%s", card->shortname);
110
111 err = snd_bcm2835_create(card, pdev, &chip);
112 if (err < 0) {
113 dev_err(dev, "Failed to create bcm2835 chip\n");
114 goto err_free;
115 }
116
117 err = snd_bcm2835_new_pcm(chip);
118 if (err < 0) {
119 dev_err(dev, "Failed to create new bcm2835 pcm device\n");
120 goto err_free;
121 }
122
123 err = snd_bcm2835_new_spdif_pcm(chip);
124 if (err < 0) {
125 dev_err(dev, "Failed to create new bcm2835 spdif pcm device\n");
126 goto err_free;
127 }
128
129 err = snd_bcm2835_new_ctl(chip);
130 if (err < 0) {
131 dev_err(dev, "Failed to create new bcm2835 ctl\n");
132 goto err_free;
133 }
134
135 for (i = 0; i < numchans; i++) {
136 chip->avail_substreams |= (1 << i);
137 chip->pdev[i] = pdev;
138 }
139
140 err = snd_card_register(card);
141 if (err) {
142 dev_err(dev, "Failed to register bcm2835 ALSA card\n");
143 goto err_free;
144 }
145
146 g_card = card;
147 g_chip = chip;
148 platform_set_drvdata(pdev, card);
149 audio_info("bcm2835 ALSA card created with %u channels\n", numchans);
150
151 return 0;
152
153err_free:
154 snd_card_free(card);
155
156 return err;
157}
158
159static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
160{
161 int idx;
162 void *drv_data;
163
164 drv_data = platform_get_drvdata(pdev);
165
166 if (drv_data == (void *)g_card) {
167 /* This is the card device */
168 snd_card_free((struct snd_card *)drv_data);
169 g_card = NULL;
170 g_chip = NULL;
171 } else {
172 idx = (int)(long)drv_data;
173 if (g_card) {
174 BUG_ON(!g_chip);
175 /* We pass chip device numbers in audio ipc devices
176 * other than the one we registered our card with
177 */
178 idx = (int)(long)drv_data;
179 BUG_ON(!idx || idx > MAX_SUBSTREAMS);
180 g_chip->avail_substreams &= ~(1 << idx);
181 /* There should be atleast one substream registered
182 * after we are done here, as it wil be removed when
183 * the *remove* is called for the card device
184 */
185 BUG_ON(!g_chip->avail_substreams);
186 }
187 }
188
189 platform_set_drvdata(pdev, NULL);
190
191 return 0;
192}
193
194#ifdef CONFIG_PM
195
196static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
197 pm_message_t state)
198{
199 return 0;
200}
201
202static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
203{
204 return 0;
205}
206
207#endif
208
209static const struct of_device_id snd_bcm2835_of_match_table[] = {
210 { .compatible = "brcm,bcm2835-audio",},
211 {},
212};
213MODULE_DEVICE_TABLE(of, snd_bcm2835_of_match_table);
214
215static struct platform_driver bcm2835_alsa0_driver = {
216 .probe = snd_bcm2835_alsa_probe_dt,
217 .remove = snd_bcm2835_alsa_remove,
218#ifdef CONFIG_PM
219 .suspend = snd_bcm2835_alsa_suspend,
220 .resume = snd_bcm2835_alsa_resume,
221#endif
222 .driver = {
223 .name = "bcm2835_AUD0",
224 .owner = THIS_MODULE,
225 .of_match_table = snd_bcm2835_of_match_table,
226 },
227};
228
229static int bcm2835_alsa_device_init(void)
230{
231 int retval;
232
233 retval = platform_driver_register(&bcm2835_alsa0_driver);
234 if (retval)
235 pr_err("Error registering bcm2835_alsa0_driver %d .\n", retval);
236
237 return retval;
238}
239
240static void bcm2835_alsa_device_exit(void)
241{
242 platform_driver_unregister(&bcm2835_alsa0_driver);
243}
244
245late_initcall(bcm2835_alsa_device_init);
246module_exit(bcm2835_alsa_device_exit);
247
248MODULE_AUTHOR("Dom Cobley");
249MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
250MODULE_LICENSE("GPL");
diff --git a/drivers/staging/bcm2835-audio/bcm2835.h b/drivers/staging/bcm2835-audio/bcm2835.h
new file mode 100644
index 000000000000..36e3ef80e60c
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/bcm2835.h
@@ -0,0 +1,167 @@
1/*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14
15#ifndef __SOUND_ARM_BCM2835_H
16#define __SOUND_ARM_BCM2835_H
17
18#include <linux/device.h>
19#include <linux/list.h>
20#include <linux/interrupt.h>
21#include <linux/wait.h>
22#include <sound/core.h>
23#include <sound/initval.h>
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
26#include <sound/pcm-indirect.h>
27#include <linux/workqueue.h>
28
29/*
30#define AUDIO_DEBUG_ENABLE
31#define AUDIO_VERBOSE_DEBUG_ENABLE
32 */
33
34/* Debug macros */
35
36#ifdef AUDIO_DEBUG_ENABLE
37#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
38
39#define audio_debug(fmt, arg...) \
40 printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
41
42#define audio_info(fmt, arg...) \
43 printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
44
45#else
46
47#define audio_debug(fmt, arg...)
48
49#define audio_info(fmt, arg...)
50
51#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
52
53#else
54
55#define audio_debug(fmt, arg...)
56
57#define audio_info(fmt, arg...)
58
59#endif /* AUDIO_DEBUG_ENABLE */
60
61#define audio_error(fmt, arg...) \
62 printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
63
64#define audio_warning(fmt, arg...) \
65 printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
66
67#define audio_alert(fmt, arg...) \
68 printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
69
70#define MAX_SUBSTREAMS (8)
71#define AVAIL_SUBSTREAMS_MASK (0xff)
72
73enum {
74 CTRL_VOL_MUTE,
75 CTRL_VOL_UNMUTE
76};
77
78/* macros for alsa2chip and chip2alsa, instead of functions */
79
80#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
81#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
82
83/* Some constants for values .. */
84enum snd_bcm2835_route {
85 AUDIO_DEST_AUTO = 0,
86 AUDIO_DEST_HEADPHONES = 1,
87 AUDIO_DEST_HDMI = 2,
88 AUDIO_DEST_MAX,
89};
90
91enum snd_bcm2835_ctrl {
92 PCM_PLAYBACK_VOLUME,
93 PCM_PLAYBACK_MUTE,
94 PCM_PLAYBACK_DEVICE,
95};
96
97/* definition of the chip-specific record */
98struct bcm2835_chip {
99 struct snd_card *card;
100 struct snd_pcm *pcm;
101 struct snd_pcm *pcm_spdif;
102 /* Bitmat for valid reg_base and irq numbers */
103 unsigned int avail_substreams;
104 struct platform_device *pdev[MAX_SUBSTREAMS];
105 struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
106
107 int volume;
108 int old_volume; /* stores the volume value whist muted */
109 int dest;
110 int mute;
111
112 unsigned int opened;
113 unsigned int spdif_status;
114 struct mutex audio_mutex;
115};
116
117struct bcm2835_alsa_stream {
118 struct bcm2835_chip *chip;
119 struct snd_pcm_substream *substream;
120 struct snd_pcm_indirect pcm_indirect;
121
122 struct semaphore buffers_update_sem;
123 struct semaphore control_sem;
124 spinlock_t lock;
125 volatile unsigned int control;
126 volatile unsigned int status;
127
128 int open;
129 int running;
130 int draining;
131
132 int channels;
133 int params_rate;
134 int pcm_format_width;
135
136 unsigned int pos;
137 unsigned int buffer_size;
138 unsigned int period_size;
139
140 atomic_t retrieved;
141 struct bcm2835_audio_instance *instance;
142 struct workqueue_struct *my_wq;
143 int idx;
144};
145
146int snd_bcm2835_new_ctl(struct bcm2835_chip *chip);
147int snd_bcm2835_new_pcm(struct bcm2835_chip *chip);
148int snd_bcm2835_new_spdif_pcm(struct bcm2835_chip *chip);
149
150int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa_stream);
151int bcm2835_audio_close(struct bcm2835_alsa_stream *alsa_stream);
152int bcm2835_audio_set_params(struct bcm2835_alsa_stream *alsa_stream,
153 unsigned int channels, unsigned int samplerate,
154 unsigned int bps);
155int bcm2835_audio_setup(struct bcm2835_alsa_stream *alsa_stream);
156int bcm2835_audio_start(struct bcm2835_alsa_stream *alsa_stream);
157int bcm2835_audio_stop(struct bcm2835_alsa_stream *alsa_stream);
158int bcm2835_audio_set_ctls(struct bcm2835_chip *chip);
159int bcm2835_audio_write(struct bcm2835_alsa_stream *alsa_stream,
160 unsigned int count,
161 void *src);
162void bcm2835_playback_fifo(struct bcm2835_alsa_stream *alsa_stream);
163unsigned int bcm2835_audio_retrieve_buffers(struct bcm2835_alsa_stream *alsa_stream);
164void bcm2835_audio_flush_buffers(struct bcm2835_alsa_stream *alsa_stream);
165void bcm2835_audio_flush_playback_buffers(struct bcm2835_alsa_stream *alsa_stream);
166
167#endif /* __SOUND_ARM_BCM2835_H */
diff --git a/drivers/staging/bcm2835-audio/vc_vchi_audioserv_defs.h b/drivers/staging/bcm2835-audio/vc_vchi_audioserv_defs.h
new file mode 100644
index 000000000000..da96f1bc2516
--- /dev/null
+++ b/drivers/staging/bcm2835-audio/vc_vchi_audioserv_defs.h
@@ -0,0 +1,108 @@
1/*****************************************************************************
2 * Copyright 2011 Broadcom Corporation. All rights reserved.
3 *
4 * Unless you and Broadcom execute a separate written software license
5 * agreement governing use of this software, this software is licensed to you
6 * under the terms of the GNU General Public License version 2, available at
7 * http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
8 *
9 * Notwithstanding the above, under no circumstances may you combine this
10 * software in any way with any other Broadcom software provided under a
11 * license other than the GPL, without Broadcom's express prior written
12 * consent.
13 *****************************************************************************/
14
15#ifndef _VC_AUDIO_DEFS_H_
16#define _VC_AUDIO_DEFS_H_
17
18#define VC_AUDIOSERV_MIN_VER 1
19#define VC_AUDIOSERV_VER 2
20
21/* FourCC code used for VCHI connection */
22#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
23
24/*
25 * List of screens that are currently supported
26 * All message types supported for HOST->VC direction
27 */
28
29enum vc_audio_msg_type {
30 VC_AUDIO_MSG_TYPE_RESULT, // Generic result
31 VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
32 VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
33 VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
34 VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
35 VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
36 VC_AUDIO_MSG_TYPE_START, // Configure audio
37 VC_AUDIO_MSG_TYPE_STOP, // Configure audio
38 VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
39 VC_AUDIO_MSG_TYPE_MAX
40};
41
42/* configure the audio */
43
44struct vc_audio_config {
45 u32 channels;
46 u32 samplerate;
47 u32 bps;
48};
49
50struct vc_audio_control {
51 u32 volume;
52 u32 dest;
53};
54
55struct vc_audio_open {
56 u32 dummy;
57};
58
59struct vc_audio_close {
60 u32 dummy;
61};
62
63struct vc_audio_start {
64 u32 dummy;
65};
66
67struct vc_audio_stop {
68 u32 draining;
69};
70
71/* configure the write audio samples */
72struct vc_audio_write {
73 u32 count; // in bytes
74 u32 cookie1;
75 u32 cookie2;
76 s16 silence;
77 s16 max_packet;
78};
79
80/* Generic result for a request (VC->HOST) */
81struct vc_audio_result {
82 s32 success; // Success value
83};
84
85/* Generic result for a request (VC->HOST) */
86struct vc_audio_complete {
87 s32 count; // Success value
88 u32 cookie1;
89 u32 cookie2;
90};
91
92/* Message header for all messages in HOST->VC direction */
93struct vc_audio_msg {
94 s32 type; /* Message type (VC_AUDIO_MSG_TYPE) */
95 union {
96 struct vc_audio_config config;
97 struct vc_audio_control control;
98 struct vc_audio_open open;
99 struct vc_audio_close close;
100 struct vc_audio_start start;
101 struct vc_audio_stop stop;
102 struct vc_audio_write write;
103 struct vc_audio_result result;
104 struct vc_audio_complete complete;
105 } u;
106};
107
108#endif /* _VC_AUDIO_DEFS_H_ */
diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index e7255f811611..942507754cab 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -1025,7 +1025,7 @@ config COMEDI_NI_660X
1025 select COMEDI_NI_TIOCMD 1025 select COMEDI_NI_TIOCMD
1026 ---help--- 1026 ---help---
1027 Enable support for National Instruments PCI-6601 (ni_660x), PCI-6602, 1027 Enable support for National Instruments PCI-6601 (ni_660x), PCI-6602,
1028 PXI-6602, PXI-6608 and PXI-6624. 1028 PXI-6602, PXI-6608, PCI-6624, and PXI-6624.
1029 1029
1030 To compile this driver as a module, choose M here: the module will be 1030 To compile this driver as a module, choose M here: the module will be
1031 called ni_660x. 1031 called ni_660x.
@@ -1070,9 +1070,11 @@ config COMEDI_NI_PCIMIO
1070 PCI-MIO-16E-4, PCI-6014, PCI-6040E, PXI-6040E, PCI-6030E, PCI-6031E, 1070 PCI-MIO-16E-4, PCI-6014, PCI-6040E, PXI-6040E, PCI-6030E, PCI-6031E,
1071 PCI-6032E, PCI-6033E, PCI-6071E, PCI-6023E, PCI-6024E, PCI-6025E, 1071 PCI-6032E, PCI-6033E, PCI-6071E, PCI-6023E, PCI-6024E, PCI-6025E,
1072 PXI-6025E, PCI-6034E, PCI-6035E, PCI-6052E, PCI-6110, PCI-6111, 1072 PXI-6025E, PCI-6034E, PCI-6035E, PCI-6052E, PCI-6110, PCI-6111,
1073 PCI-6220, PCI-6221, PCI-6224, PXI-6224, PCI-6225, PXI-6225, PCI-6229, 1073 PCI-6220, PXI-6220, PCI-6221, PXI-6221, PCI-6224, PXI-6224, PCI-6225,
1074 PCI-6250, PCI-6251, PCIe-6251, PCI-6254, PCI-6259, PCIe-6259, 1074 PXI-6225, PCI-6229, PXI-6229, PCI-6250, PXI-6250, PCI-6251, PXI-6251,
1075 PCI-6280, PCI-6281, PXI-6281, PCI-6284, PCI-6289, PCI-6711, PXI-6711, 1075 PCIe-6251, PXIe-6251, PCI-6254, PXI-6254, PCI-6259, PXI-6259,
1076 PCIe-6259, PXIe-6259, PCI-6280, PXI-6280, PCI-6281, PXI-6281,
1077 PCI-6284, PXI-6284, PCI-6289, PXI-6289, PCI-6711, PXI-6711,
1076 PCI-6713, PXI-6713, PXI-6071E, PCI-6070E, PXI-6070E, PXI-6052E, 1078 PCI-6713, PXI-6713, PXI-6071E, PCI-6070E, PXI-6070E, PXI-6052E,
1077 PCI-6036E, PCI-6731, PCI-6733, PXI-6733, PCI-6143, PXI-6143 1079 PCI-6036E, PCI-6731, PCI-6733, PXI-6733, PCI-6143, PXI-6143
1078 1080
diff --git a/drivers/staging/comedi/comedi_compat32.h b/drivers/staging/comedi/comedi_compat32.h
index 5ce77f3e8c22..0127c1f98bbf 100644
--- a/drivers/staging/comedi/comedi_compat32.h
+++ b/drivers/staging/comedi/comedi_compat32.h
@@ -25,7 +25,8 @@
25#ifdef CONFIG_COMPAT 25#ifdef CONFIG_COMPAT
26 26
27struct file; 27struct file;
28long comedi_compat_ioctl(struct file *, unsigned int cmd, unsigned long arg); 28long comedi_compat_ioctl(struct file *file, unsigned int cmd,
29 unsigned long arg);
29 30
30#else /* CONFIG_COMPAT */ 31#else /* CONFIG_COMPAT */
31 32
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 64b3966c5f1f..57e8599b54e6 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -28,15 +28,11 @@
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/kmod.h>
32#include <linux/poll.h> 31#include <linux/poll.h>
33#include <linux/init.h>
34#include <linux/device.h> 32#include <linux/device.h>
35#include <linux/vmalloc.h>
36#include <linux/fs.h> 33#include <linux/fs.h>
37#include "comedidev.h" 34#include "comedidev.h"
38#include <linux/cdev.h> 35#include <linux/cdev.h>
39#include <linux/stat.h>
40 36
41#include <linux/io.h> 37#include <linux/io.h>
42#include <linux/uaccess.h> 38#include <linux/uaccess.h>
@@ -2898,9 +2894,6 @@ static int __init comedi_init(void)
2898 2894
2899 comedi_class->dev_groups = comedi_dev_groups; 2895 comedi_class->dev_groups = comedi_dev_groups;
2900 2896
2901 /* XXX requires /proc interface */
2902 comedi_proc_init();
2903
2904 /* create devices files for legacy/manual use */ 2897 /* create devices files for legacy/manual use */
2905 for (i = 0; i < comedi_num_legacy_minors; i++) { 2898 for (i = 0; i < comedi_num_legacy_minors; i++) {
2906 struct comedi_device *dev; 2899 struct comedi_device *dev;
@@ -2917,6 +2910,9 @@ static int __init comedi_init(void)
2917 mutex_unlock(&dev->mutex); 2910 mutex_unlock(&dev->mutex);
2918 } 2911 }
2919 2912
2913 /* XXX requires /proc interface */
2914 comedi_proc_init();
2915
2920 return 0; 2916 return 0;
2921} 2917}
2922module_init(comedi_init); 2918module_init(comedi_init);
diff --git a/drivers/staging/comedi/comedi_internal.h b/drivers/staging/comedi/comedi_internal.h
index 3f2c88ae6470..534415e331b6 100644
--- a/drivers/staging/comedi/comedi_internal.h
+++ b/drivers/staging/comedi/comedi_internal.h
@@ -44,11 +44,12 @@ extern unsigned int comedi_default_buf_maxsize_kb;
44extern struct comedi_driver *comedi_drivers; 44extern struct comedi_driver *comedi_drivers;
45extern struct mutex comedi_drivers_list_lock; 45extern struct mutex comedi_drivers_list_lock;
46 46
47int insn_inval(struct comedi_device *, struct comedi_subdevice *, 47int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s,
48 struct comedi_insn *, unsigned int *); 48 struct comedi_insn *insn, unsigned int *data);
49 49
50void comedi_device_detach(struct comedi_device *); 50void comedi_device_detach(struct comedi_device *dev);
51int comedi_device_attach(struct comedi_device *, struct comedi_devconfig *); 51int comedi_device_attach(struct comedi_device *dev,
52 struct comedi_devconfig *it);
52 53
53#ifdef CONFIG_PROC_FS 54#ifdef CONFIG_PROC_FS
54 55
diff --git a/drivers/staging/comedi/comedi_pci.h b/drivers/staging/comedi/comedi_pci.h
index 4005cc9cf7f1..7dfd892c74b0 100644
--- a/drivers/staging/comedi/comedi_pci.h
+++ b/drivers/staging/comedi/comedi_pci.h
@@ -34,18 +34,20 @@
34#define PCI_VENDOR_ID_RTD 0x1435 34#define PCI_VENDOR_ID_RTD 0x1435
35#define PCI_VENDOR_ID_HUMUSOFT 0x186c 35#define PCI_VENDOR_ID_HUMUSOFT 0x186c
36 36
37struct pci_dev *comedi_to_pci_dev(struct comedi_device *); 37struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev);
38 38
39int comedi_pci_enable(struct comedi_device *); 39int comedi_pci_enable(struct comedi_device *dev);
40void comedi_pci_disable(struct comedi_device *); 40void comedi_pci_disable(struct comedi_device *dev);
41void comedi_pci_detach(struct comedi_device *); 41void comedi_pci_detach(struct comedi_device *dev);
42 42
43int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *, 43int comedi_pci_auto_config(struct pci_dev *pcidev, struct comedi_driver *driver,
44 unsigned long context); 44 unsigned long context);
45void comedi_pci_auto_unconfig(struct pci_dev *); 45void comedi_pci_auto_unconfig(struct pci_dev *pcidev);
46 46
47int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *); 47int comedi_pci_driver_register(struct comedi_driver *comedi_driver,
48void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *); 48 struct pci_driver *pci_driver);
49void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver,
50 struct pci_driver *pci_driver);
49 51
50/** 52/**
51 * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver 53 * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver
diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c
index d7072a5c1647..cd4742851c08 100644
--- a/drivers/staging/comedi/comedi_pcmcia.c
+++ b/drivers/staging/comedi/comedi_pcmcia.c
@@ -78,7 +78,8 @@ static int comedi_pcmcia_conf_check(struct pcmcia_device *link,
78 * or a negative error number from pcmcia_enable_device() if it fails. 78 * or a negative error number from pcmcia_enable_device() if it fails.
79 */ 79 */
80int comedi_pcmcia_enable(struct comedi_device *dev, 80int comedi_pcmcia_enable(struct comedi_device *dev,
81 int (*conf_check)(struct pcmcia_device *, void *)) 81 int (*conf_check)(struct pcmcia_device *p_dev,
82 void *priv_data))
82{ 83{
83 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); 84 struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
84 int ret; 85 int ret;
diff --git a/drivers/staging/comedi/comedi_pcmcia.h b/drivers/staging/comedi/comedi_pcmcia.h
index 5a572c200a8b..9e45c7c93278 100644
--- a/drivers/staging/comedi/comedi_pcmcia.h
+++ b/drivers/staging/comedi/comedi_pcmcia.h
@@ -24,19 +24,21 @@
24 24
25#include "comedidev.h" 25#include "comedidev.h"
26 26
27struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *); 27struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *dev);
28 28
29int comedi_pcmcia_enable(struct comedi_device *, 29int comedi_pcmcia_enable(struct comedi_device *dev,
30 int (*conf_check)(struct pcmcia_device *, void *)); 30 int (*conf_check)(struct pcmcia_device *p_dev,
31void comedi_pcmcia_disable(struct comedi_device *); 31 void *priv_data));
32void comedi_pcmcia_disable(struct comedi_device *dev);
32 33
33int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *); 34int comedi_pcmcia_auto_config(struct pcmcia_device *link,
34void comedi_pcmcia_auto_unconfig(struct pcmcia_device *); 35 struct comedi_driver *driver);
36void comedi_pcmcia_auto_unconfig(struct pcmcia_device *link);
35 37
36int comedi_pcmcia_driver_register(struct comedi_driver *, 38int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver,
37 struct pcmcia_driver *); 39 struct pcmcia_driver *pcmcia_driver);
38void comedi_pcmcia_driver_unregister(struct comedi_driver *, 40void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
39 struct pcmcia_driver *); 41 struct pcmcia_driver *pcmcia_driver);
40 42
41/** 43/**
42 * module_comedi_pcmcia_driver() - Helper macro for registering a comedi 44 * module_comedi_pcmcia_driver() - Helper macro for registering a comedi
diff --git a/drivers/staging/comedi/comedi_usb.h b/drivers/staging/comedi/comedi_usb.h
index 721128bece3c..132154ec792f 100644
--- a/drivers/staging/comedi/comedi_usb.h
+++ b/drivers/staging/comedi/comedi_usb.h
@@ -23,15 +23,17 @@
23 23
24#include "comedidev.h" 24#include "comedidev.h"
25 25
26struct usb_interface *comedi_to_usb_interface(struct comedi_device *); 26struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev);
27struct usb_device *comedi_to_usb_dev(struct comedi_device *); 27struct usb_device *comedi_to_usb_dev(struct comedi_device *dev);
28 28
29int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *, 29int comedi_usb_auto_config(struct usb_interface *intf,
30 unsigned long context); 30 struct comedi_driver *driver, unsigned long context);
31void comedi_usb_auto_unconfig(struct usb_interface *); 31void comedi_usb_auto_unconfig(struct usb_interface *intf);
32 32
33int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); 33int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
34void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *); 34 struct usb_driver *usb_driver);
35void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
36 struct usb_driver *usb_driver);
35 37
36/** 38/**
37 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver 39 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index 0c7c37a8ff33..1bb9986f865e 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -612,12 +612,6 @@ extern const struct comedi_lrange range_unknown;
612 612
613#define range_digital range_unipolar5 613#define range_digital range_unipolar5
614 614
615#if __GNUC__ >= 3
616#define GCC_ZERO_LENGTH_ARRAY
617#else
618#define GCC_ZERO_LENGTH_ARRAY 0
619#endif
620
621/** 615/**
622 * struct comedi_lrange - Describes a COMEDI range table 616 * struct comedi_lrange - Describes a COMEDI range table
623 * @length: Number of entries in the range table. 617 * @length: Number of entries in the range table.
@@ -631,7 +625,7 @@ extern const struct comedi_lrange range_unknown;
631 */ 625 */
632struct comedi_lrange { 626struct comedi_lrange {
633 int length; 627 int length;
634 struct comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; 628 struct comedi_krange range[];
635}; 629};
636 630
637/** 631/**
@@ -982,19 +976,21 @@ unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
982 976
983#define COMEDI_TIMEOUT_MS 1000 977#define COMEDI_TIMEOUT_MS 1000
984 978
985int comedi_timeout(struct comedi_device *, struct comedi_subdevice *, 979int comedi_timeout(struct comedi_device *dev, struct comedi_subdevice *s,
986 struct comedi_insn *, 980 struct comedi_insn *insn,
987 int (*cb)(struct comedi_device *, struct comedi_subdevice *, 981 int (*cb)(struct comedi_device *dev,
988 struct comedi_insn *, unsigned long context), 982 struct comedi_subdevice *s,
983 struct comedi_insn *insn, unsigned long context),
989 unsigned long context); 984 unsigned long context);
990 985
991unsigned int comedi_handle_events(struct comedi_device *dev, 986unsigned int comedi_handle_events(struct comedi_device *dev,
992 struct comedi_subdevice *s); 987 struct comedi_subdevice *s);
993 988
994int comedi_dio_insn_config(struct comedi_device *, struct comedi_subdevice *, 989int comedi_dio_insn_config(struct comedi_device *dev,
995 struct comedi_insn *, unsigned int *data, 990 struct comedi_subdevice *s,
991 struct comedi_insn *insn, unsigned int *data,
996 unsigned int mask); 992 unsigned int mask);
997unsigned int comedi_dio_update_state(struct comedi_subdevice *, 993unsigned int comedi_dio_update_state(struct comedi_subdevice *s,
998 unsigned int *data); 994 unsigned int *data);
999unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s); 995unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s);
1000unsigned int comedi_nscans_left(struct comedi_subdevice *s, 996unsigned int comedi_nscans_left(struct comedi_subdevice *s,
@@ -1004,32 +1000,33 @@ unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
1004void comedi_inc_scan_progress(struct comedi_subdevice *s, 1000void comedi_inc_scan_progress(struct comedi_subdevice *s,
1005 unsigned int num_bytes); 1001 unsigned int num_bytes);
1006 1002
1007void *comedi_alloc_devpriv(struct comedi_device *, size_t); 1003void *comedi_alloc_devpriv(struct comedi_device *dev, size_t size);
1008int comedi_alloc_subdevices(struct comedi_device *, int); 1004int comedi_alloc_subdevices(struct comedi_device *dev, int num_subdevices);
1009int comedi_alloc_subdev_readback(struct comedi_subdevice *); 1005int comedi_alloc_subdev_readback(struct comedi_subdevice *s);
1010 1006
1011int comedi_readback_insn_read(struct comedi_device *, struct comedi_subdevice *, 1007int comedi_readback_insn_read(struct comedi_device *dev,
1012 struct comedi_insn *, unsigned int *data); 1008 struct comedi_subdevice *s,
1009 struct comedi_insn *insn, unsigned int *data);
1013 1010
1014int comedi_load_firmware(struct comedi_device *, struct device *, 1011int comedi_load_firmware(struct comedi_device *dev, struct device *hw_dev,
1015 const char *name, 1012 const char *name,
1016 int (*cb)(struct comedi_device *, 1013 int (*cb)(struct comedi_device *dev,
1017 const u8 *data, size_t size, 1014 const u8 *data, size_t size,
1018 unsigned long context), 1015 unsigned long context),
1019 unsigned long context); 1016 unsigned long context);
1020 1017
1021int __comedi_request_region(struct comedi_device *, 1018int __comedi_request_region(struct comedi_device *dev,
1022 unsigned long start, unsigned long len); 1019 unsigned long start, unsigned long len);
1023int comedi_request_region(struct comedi_device *, 1020int comedi_request_region(struct comedi_device *dev,
1024 unsigned long start, unsigned long len); 1021 unsigned long start, unsigned long len);
1025void comedi_legacy_detach(struct comedi_device *); 1022void comedi_legacy_detach(struct comedi_device *dev);
1026 1023
1027int comedi_auto_config(struct device *, struct comedi_driver *, 1024int comedi_auto_config(struct device *hardware_device,
1028 unsigned long context); 1025 struct comedi_driver *driver, unsigned long context);
1029void comedi_auto_unconfig(struct device *); 1026void comedi_auto_unconfig(struct device *hardware_device);
1030 1027
1031int comedi_driver_register(struct comedi_driver *); 1028int comedi_driver_register(struct comedi_driver *driver);
1032void comedi_driver_unregister(struct comedi_driver *); 1029void comedi_driver_unregister(struct comedi_driver *driver);
1033 1030
1034/** 1031/**
1035 * module_comedi_driver() - Helper macro for registering a comedi driver 1032 * module_comedi_driver() - Helper macro for registering a comedi driver
diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c
index 57f0f46de0be..1fdc0f8d7e1a 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3501.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3501.c
@@ -94,7 +94,7 @@ struct apci3501_private {
94 unsigned char timer_mode; 94 unsigned char timer_mode;
95}; 95};
96 96
97static struct comedi_lrange apci3501_ao_range = { 97static const struct comedi_lrange apci3501_ao_range = {
98 2, { 98 2, {
99 BIP_RANGE(10), 99 BIP_RANGE(10),
100 UNI_RANGE(10) 100 UNI_RANGE(10)
diff --git a/drivers/staging/comedi/drivers/addi_watchdog.h b/drivers/staging/comedi/drivers/addi_watchdog.h
index 3f8e7388bbca..b049cfba9813 100644
--- a/drivers/staging/comedi/drivers/addi_watchdog.h
+++ b/drivers/staging/comedi/drivers/addi_watchdog.h
@@ -4,6 +4,6 @@
4struct comedi_subdevice; 4struct comedi_subdevice;
5 5
6void addi_watchdog_reset(unsigned long iobase); 6void addi_watchdog_reset(unsigned long iobase);
7int addi_watchdog_init(struct comedi_subdevice *, unsigned long iobase); 7int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase);
8 8
9#endif 9#endif
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index 86450c08f291..1cc9b7ef1ff9 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -1279,9 +1279,8 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
1279 } else { 1279 } else {
1280 arg = cmd->convert_arg * cmd->chanlist_len; 1280 arg = cmd->convert_arg * cmd->chanlist_len;
1281 } 1281 }
1282 err |= comedi_check_trigger_arg_min(&cmd-> 1282 err |= comedi_check_trigger_arg_min(
1283 scan_begin_arg, 1283 &cmd->scan_begin_arg, arg);
1284 arg);
1285 } 1284 }
1286 } 1285 }
1287 1286
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index cb9c2699277e..efbf27730d71 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -238,7 +238,7 @@ enum daq_atrig_low_4020_contents {
238 EXT_START_TRIG_BNC_BIT = 0x2000, 238 EXT_START_TRIG_BNC_BIT = 0x2000,
239}; 239};
240 240
241static inline uint16_t analog_trig_low_threshold_bits(uint16_t threshold) 241static inline u16 analog_trig_low_threshold_bits(u16 threshold)
242{ 242{
243 return threshold & 0xfff; 243 return threshold & 0xfff;
244} 244}
@@ -280,17 +280,17 @@ enum adc_control1_contents {
280 ADC_MODE_MASK = 0xf000, 280 ADC_MODE_MASK = 0xf000,
281}; 281};
282 282
283static inline uint16_t adc_lo_chan_4020_bits(unsigned int channel) 283static inline u16 adc_lo_chan_4020_bits(unsigned int channel)
284{ 284{
285 return (channel & 0x3) << 8; 285 return (channel & 0x3) << 8;
286}; 286};
287 287
288static inline uint16_t adc_hi_chan_4020_bits(unsigned int channel) 288static inline u16 adc_hi_chan_4020_bits(unsigned int channel)
289{ 289{
290 return (channel & 0x3) << 10; 290 return (channel & 0x3) << 10;
291}; 291};
292 292
293static inline uint16_t adc_mode_bits(unsigned int mode) 293static inline u16 adc_mode_bits(unsigned int mode)
294{ 294{
295 return (mode & 0xf) << 12; 295 return (mode & 0xf) << 12;
296}; 296};
@@ -318,12 +318,12 @@ enum calibration_contents {
318 * 7 : dac channel 1 318 * 7 : dac channel 1
319 */ 319 */
320 320
321static inline uint16_t adc_src_bits(unsigned int source) 321static inline u16 adc_src_bits(unsigned int source)
322{ 322{
323 return (source & 0xf) << 3; 323 return (source & 0xf) << 3;
324}; 324};
325 325
326static inline uint16_t adc_convert_chan_4020_bits(unsigned int channel) 326static inline u16 adc_convert_chan_4020_bits(unsigned int channel)
327{ 327{
328 return (channel & 0x3) << 8; 328 return (channel & 0x3) << 8;
329}; 329};
@@ -337,7 +337,7 @@ enum adc_queue_load_contents {
337 QUEUE_EOSCAN_BIT = 0x8000, /* queue end of scan */ 337 QUEUE_EOSCAN_BIT = 0x8000, /* queue end of scan */
338}; 338};
339 339
340static inline uint16_t adc_chan_bits(unsigned int channel) 340static inline u16 adc_chan_bits(unsigned int channel)
341{ 341{
342 return channel & 0x3f; 342 return channel & 0x3f;
343}; 343};
@@ -384,22 +384,22 @@ enum hw_status_contents {
384 ADC_STOP_BIT = 0x200, 384 ADC_STOP_BIT = 0x200,
385}; 385};
386 386
387static inline uint16_t pipe_full_bits(uint16_t hw_status_bits) 387static inline u16 pipe_full_bits(u16 hw_status_bits)
388{ 388{
389 return (hw_status_bits >> 10) & 0x3; 389 return (hw_status_bits >> 10) & 0x3;
390}; 390};
391 391
392static inline unsigned int dma_chain_flag_bits(uint16_t prepost_bits) 392static inline unsigned int dma_chain_flag_bits(u16 prepost_bits)
393{ 393{
394 return (prepost_bits >> 6) & 0x3; 394 return (prepost_bits >> 6) & 0x3;
395} 395}
396 396
397static inline unsigned int adc_upper_read_ptr_code(uint16_t prepost_bits) 397static inline unsigned int adc_upper_read_ptr_code(u16 prepost_bits)
398{ 398{
399 return (prepost_bits >> 12) & 0x3; 399 return (prepost_bits >> 12) & 0x3;
400} 400}
401 401
402static inline unsigned int adc_upper_write_ptr_code(uint16_t prepost_bits) 402static inline unsigned int adc_upper_write_ptr_code(u16 prepost_bits)
403{ 403{
404 return (prepost_bits >> 14) & 0x3; 404 return (prepost_bits >> 14) & 0x3;
405} 405}
@@ -418,12 +418,12 @@ enum range_cal_i2c_contents {
418 BNC_TRIG_THRESHOLD_0V_BIT = 0x80, 418 BNC_TRIG_THRESHOLD_0V_BIT = 0x80,
419}; 419};
420 420
421static inline uint8_t adc_src_4020_bits(unsigned int source) 421static inline u8 adc_src_4020_bits(unsigned int source)
422{ 422{
423 return (source << 4) & ADC_SRC_4020_MASK; 423 return (source << 4) & ADC_SRC_4020_MASK;
424}; 424};
425 425
426static inline uint8_t attenuate_bit(unsigned int channel) 426static inline u8 attenuate_bit(unsigned int channel)
427{ 427{
428 /* attenuate channel (+-5V input range) */ 428 /* attenuate channel (+-5V input range) */
429 return 1 << (channel & 0x3); 429 return 1 << (channel & 0x3);
@@ -443,7 +443,7 @@ static const struct comedi_lrange ai_ranges_64xx = {
443 } 443 }
444}; 444};
445 445
446static const uint8_t ai_range_code_64xx[8] = { 446static const u8 ai_range_code_64xx[8] = {
447 0x0, 0x1, 0x2, 0x3, /* bipolar 10, 5, 2,5, 1.25 */ 447 0x0, 0x1, 0x2, 0x3, /* bipolar 10, 5, 2,5, 1.25 */
448 0x8, 0x9, 0xa, 0xb /* unipolar 10, 5, 2.5, 1.25 */ 448 0x8, 0x9, 0xa, 0xb /* unipolar 10, 5, 2.5, 1.25 */
449}; 449};
@@ -461,7 +461,7 @@ static const struct comedi_lrange ai_ranges_64_mx = {
461 } 461 }
462}; 462};
463 463
464static const uint8_t ai_range_code_64_mx[7] = { 464static const u8 ai_range_code_64_mx[7] = {
465 0x0, 0x1, 0x2, 0x3, /* bipolar 5, 2.5, 1.25, 0.625 */ 465 0x0, 0x1, 0x2, 0x3, /* bipolar 5, 2.5, 1.25, 0.625 */
466 0x9, 0xa, 0xb /* unipolar 5, 2.5, 1.25 */ 466 0x9, 0xa, 0xb /* unipolar 5, 2.5, 1.25 */
467}; 467};
@@ -476,7 +476,7 @@ static const struct comedi_lrange ai_ranges_60xx = {
476 } 476 }
477}; 477};
478 478
479static const uint8_t ai_range_code_60xx[4] = { 479static const u8 ai_range_code_60xx[4] = {
480 0x0, 0x1, 0x4, 0x7 /* bipolar 10, 5, 0.5, 0.05 */ 480 0x0, 0x1, 0x4, 0x7 /* bipolar 10, 5, 0.5, 0.05 */
481}; 481};
482 482
@@ -500,7 +500,7 @@ static const struct comedi_lrange ai_ranges_6030 = {
500 } 500 }
501}; 501};
502 502
503static const uint8_t ai_range_code_6030[14] = { 503static const u8 ai_range_code_6030[14] = {
504 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, /* bip 10, 5, 2, 1, 0.5, 0.2, 0.1 */ 504 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, /* bip 10, 5, 2, 1, 0.5, 0.2, 0.1 */
505 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* uni 10, 5, 2, 1, 0.5, 0.2, 0.1 */ 505 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* uni 10, 5, 2, 1, 0.5, 0.2, 0.1 */
506}; 506};
@@ -526,7 +526,7 @@ static const struct comedi_lrange ai_ranges_6052 = {
526 } 526 }
527}; 527};
528 528
529static const uint8_t ai_range_code_6052[15] = { 529static const u8 ai_range_code_6052[15] = {
530 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, /* bipolar 10 ... 0.05 */ 530 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, /* bipolar 10 ... 0.05 */
531 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* unipolar 10 ... 0.1 */ 531 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf /* unipolar 10 ... 0.1 */
532}; 532};
@@ -594,7 +594,7 @@ struct hw_fifo_info {
594 unsigned int num_segments; 594 unsigned int num_segments;
595 unsigned int max_segment_length; 595 unsigned int max_segment_length;
596 unsigned int sample_packing_ratio; 596 unsigned int sample_packing_ratio;
597 uint16_t fifo_size_reg_mask; 597 u16 fifo_size_reg_mask;
598}; 598};
599 599
600enum pcidas64_boardid { 600enum pcidas64_boardid {
@@ -634,7 +634,7 @@ struct pcidas64_board {
634 int ai_bits; /* analog input resolution */ 634 int ai_bits; /* analog input resolution */
635 int ai_speed; /* fastest conversion period in ns */ 635 int ai_speed; /* fastest conversion period in ns */
636 const struct comedi_lrange *ai_range_table; 636 const struct comedi_lrange *ai_range_table;
637 const uint8_t *ai_range_code; 637 const u8 *ai_range_code;
638 int ao_nchan; /* number of analog out channels */ 638 int ao_nchan; /* number of analog out channels */
639 int ao_bits; /* analog output resolution */ 639 int ao_bits; /* analog output resolution */
640 int ao_scan_speed; /* analog output scan speed */ 640 int ao_scan_speed; /* analog output scan speed */
@@ -1132,10 +1132,10 @@ struct pcidas64_private {
1132 void __iomem *plx9080_iobase; 1132 void __iomem *plx9080_iobase;
1133 void __iomem *main_iobase; 1133 void __iomem *main_iobase;
1134 /* local address (used by dma controller) */ 1134 /* local address (used by dma controller) */
1135 uint32_t local0_iobase; 1135 u32 local0_iobase;
1136 uint32_t local1_iobase; 1136 u32 local1_iobase;
1137 /* dma buffers for analog input */ 1137 /* dma buffers for analog input */
1138 uint16_t *ai_buffer[MAX_AI_DMA_RING_COUNT]; 1138 u16 *ai_buffer[MAX_AI_DMA_RING_COUNT];
1139 /* physical addresses of ai dma buffers */ 1139 /* physical addresses of ai dma buffers */
1140 dma_addr_t ai_buffer_bus_addr[MAX_AI_DMA_RING_COUNT]; 1140 dma_addr_t ai_buffer_bus_addr[MAX_AI_DMA_RING_COUNT];
1141 /* 1141 /*
@@ -1151,7 +1151,7 @@ struct pcidas64_private {
1151 */ 1151 */
1152 unsigned int ai_dma_index; 1152 unsigned int ai_dma_index;
1153 /* dma buffers for analog output */ 1153 /* dma buffers for analog output */
1154 uint16_t *ao_buffer[AO_DMA_RING_COUNT]; 1154 u16 *ao_buffer[AO_DMA_RING_COUNT];
1155 /* physical addresses of ao dma buffers */ 1155 /* physical addresses of ao dma buffers */
1156 dma_addr_t ao_buffer_bus_addr[AO_DMA_RING_COUNT]; 1156 dma_addr_t ao_buffer_bus_addr[AO_DMA_RING_COUNT];
1157 struct plx_dma_desc *ao_dma_desc; 1157 struct plx_dma_desc *ao_dma_desc;
@@ -1162,20 +1162,20 @@ struct pcidas64_private {
1162 /* last bits sent to INTR_ENABLE_REG register */ 1162 /* last bits sent to INTR_ENABLE_REG register */
1163 unsigned int intr_enable_bits; 1163 unsigned int intr_enable_bits;
1164 /* last bits sent to ADC_CONTROL1_REG register */ 1164 /* last bits sent to ADC_CONTROL1_REG register */
1165 uint16_t adc_control1_bits; 1165 u16 adc_control1_bits;
1166 /* last bits sent to FIFO_SIZE_REG register */ 1166 /* last bits sent to FIFO_SIZE_REG register */
1167 uint16_t fifo_size_bits; 1167 u16 fifo_size_bits;
1168 /* last bits sent to HW_CONFIG_REG register */ 1168 /* last bits sent to HW_CONFIG_REG register */
1169 uint16_t hw_config_bits; 1169 u16 hw_config_bits;
1170 uint16_t dac_control1_bits; 1170 u16 dac_control1_bits;
1171 /* last bits written to plx9080 control register */ 1171 /* last bits written to plx9080 control register */
1172 uint32_t plx_control_bits; 1172 u32 plx_control_bits;
1173 /* last bits written to plx interrupt control and status register */ 1173 /* last bits written to plx interrupt control and status register */
1174 uint32_t plx_intcsr_bits; 1174 u32 plx_intcsr_bits;
1175 /* index of calibration source readable through ai ch0 */ 1175 /* index of calibration source readable through ai ch0 */
1176 int calibration_source; 1176 int calibration_source;
1177 /* bits written to i2c calibration/range register */ 1177 /* bits written to i2c calibration/range register */
1178 uint8_t i2c_cal_range_bits; 1178 u8 i2c_cal_range_bits;
1179 /* configure digital triggers to trigger on falling edge */ 1179 /* configure digital triggers to trigger on falling edge */
1180 unsigned int ext_trig_falling; 1180 unsigned int ext_trig_falling;
1181 short ai_cmd_running; 1181 short ai_cmd_running;
@@ -1193,7 +1193,7 @@ static unsigned int ai_range_bits_6xxx(const struct comedi_device *dev,
1193} 1193}
1194 1194
1195static unsigned int hw_revision(const struct comedi_device *dev, 1195static unsigned int hw_revision(const struct comedi_device *dev,
1196 uint16_t hw_status_bits) 1196 u16 hw_status_bits)
1197{ 1197{
1198 const struct pcidas64_board *board = dev->board_ptr; 1198 const struct pcidas64_board *board = dev->board_ptr;
1199 1199
@@ -1204,7 +1204,7 @@ static unsigned int hw_revision(const struct comedi_device *dev,
1204} 1204}
1205 1205
1206static void set_dac_range_bits(struct comedi_device *dev, 1206static void set_dac_range_bits(struct comedi_device *dev,
1207 uint16_t *bits, unsigned int channel, 1207 u16 *bits, unsigned int channel,
1208 unsigned int range) 1208 unsigned int range)
1209{ 1209{
1210 const struct pcidas64_board *board = dev->board_ptr; 1210 const struct pcidas64_board *board = dev->board_ptr;
@@ -1266,7 +1266,7 @@ static void enable_ai_interrupts(struct comedi_device *dev,
1266{ 1266{
1267 const struct pcidas64_board *board = dev->board_ptr; 1267 const struct pcidas64_board *board = dev->board_ptr;
1268 struct pcidas64_private *devpriv = dev->private; 1268 struct pcidas64_private *devpriv = dev->private;
1269 uint32_t bits; 1269 u32 bits;
1270 unsigned long flags; 1270 unsigned long flags;
1271 1271
1272 bits = EN_ADC_OVERRUN_BIT | EN_ADC_DONE_INTR_BIT | 1272 bits = EN_ADC_OVERRUN_BIT | EN_ADC_DONE_INTR_BIT |
@@ -1292,7 +1292,7 @@ static void init_plx9080(struct comedi_device *dev)
1292{ 1292{
1293 const struct pcidas64_board *board = dev->board_ptr; 1293 const struct pcidas64_board *board = dev->board_ptr;
1294 struct pcidas64_private *devpriv = dev->private; 1294 struct pcidas64_private *devpriv = dev->private;
1295 uint32_t bits; 1295 u32 bits;
1296 void __iomem *plx_iobase = devpriv->plx9080_iobase; 1296 void __iomem *plx_iobase = devpriv->plx9080_iobase;
1297 1297
1298 devpriv->plx_control_bits = 1298 devpriv->plx_control_bits =
@@ -1378,7 +1378,7 @@ static int set_ai_fifo_segment_length(struct comedi_device *dev,
1378 static const int increment_size = 0x100; 1378 static const int increment_size = 0x100;
1379 const struct hw_fifo_info *const fifo = board->ai_fifo; 1379 const struct hw_fifo_info *const fifo = board->ai_fifo;
1380 unsigned int num_increments; 1380 unsigned int num_increments;
1381 uint16_t bits; 1381 u16 bits;
1382 1382
1383 if (num_entries < increment_size) 1383 if (num_entries < increment_size)
1384 num_entries = increment_size; 1384 num_entries = increment_size;
@@ -1437,7 +1437,7 @@ static void init_stc_registers(struct comedi_device *dev)
1437{ 1437{
1438 const struct pcidas64_board *board = dev->board_ptr; 1438 const struct pcidas64_board *board = dev->board_ptr;
1439 struct pcidas64_private *devpriv = dev->private; 1439 struct pcidas64_private *devpriv = dev->private;
1440 uint16_t bits; 1440 u16 bits;
1441 unsigned long flags; 1441 unsigned long flags;
1442 1442
1443 spin_lock_irqsave(&dev->spinlock, flags); 1443 spin_lock_irqsave(&dev->spinlock, flags);
@@ -1657,9 +1657,9 @@ static void i2c_set_scl(struct comedi_device *dev, int state)
1657 } 1657 }
1658} 1658}
1659 1659
1660static void i2c_write_byte(struct comedi_device *dev, uint8_t byte) 1660static void i2c_write_byte(struct comedi_device *dev, u8 byte)
1661{ 1661{
1662 uint8_t bit; 1662 u8 bit;
1663 unsigned int num_bits = 8; 1663 unsigned int num_bits = 8;
1664 1664
1665 for (bit = 1 << (num_bits - 1); bit; bit >>= 1) { 1665 for (bit = 1 << (num_bits - 1); bit; bit >>= 1) {
@@ -1700,11 +1700,11 @@ static void i2c_stop(struct comedi_device *dev)
1700} 1700}
1701 1701
1702static void i2c_write(struct comedi_device *dev, unsigned int address, 1702static void i2c_write(struct comedi_device *dev, unsigned int address,
1703 const uint8_t *data, unsigned int length) 1703 const u8 *data, unsigned int length)
1704{ 1704{
1705 struct pcidas64_private *devpriv = dev->private; 1705 struct pcidas64_private *devpriv = dev->private;
1706 unsigned int i; 1706 unsigned int i;
1707 uint8_t bitstream; 1707 u8 bitstream;
1708 static const int read_bit = 0x1; 1708 static const int read_bit = 0x1;
1709 1709
1710 /* 1710 /*
@@ -1831,7 +1831,7 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
1831 /* set start channel, and rest of settings */ 1831 /* set start channel, and rest of settings */
1832 writew(bits, devpriv->main_iobase + ADC_QUEUE_LOAD_REG); 1832 writew(bits, devpriv->main_iobase + ADC_QUEUE_LOAD_REG);
1833 } else { 1833 } else {
1834 uint8_t old_cal_range_bits = devpriv->i2c_cal_range_bits; 1834 u8 old_cal_range_bits = devpriv->i2c_cal_range_bits;
1835 1835
1836 devpriv->i2c_cal_range_bits &= ~ADC_SRC_4020_MASK; 1836 devpriv->i2c_cal_range_bits &= ~ADC_SRC_4020_MASK;
1837 if (insn->chanspec & CR_ALT_SOURCE) { 1837 if (insn->chanspec & CR_ALT_SOURCE) {
@@ -1850,7 +1850,7 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
1850 * as it is very slow 1850 * as it is very slow
1851 */ 1851 */
1852 if (old_cal_range_bits != devpriv->i2c_cal_range_bits) { 1852 if (old_cal_range_bits != devpriv->i2c_cal_range_bits) {
1853 uint8_t i2c_data = devpriv->i2c_cal_range_bits; 1853 u8 i2c_data = devpriv->i2c_cal_range_bits;
1854 1854
1855 i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data, 1855 i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data,
1856 sizeof(i2c_data)); 1856 sizeof(i2c_data));
@@ -2273,23 +2273,23 @@ static inline unsigned int dma_transfer_size(struct comedi_device *dev)
2273 2273
2274 num_samples = devpriv->ai_fifo_segment_length * 2274 num_samples = devpriv->ai_fifo_segment_length *
2275 board->ai_fifo->sample_packing_ratio; 2275 board->ai_fifo->sample_packing_ratio;
2276 if (num_samples > DMA_BUFFER_SIZE / sizeof(uint16_t)) 2276 if (num_samples > DMA_BUFFER_SIZE / sizeof(u16))
2277 num_samples = DMA_BUFFER_SIZE / sizeof(uint16_t); 2277 num_samples = DMA_BUFFER_SIZE / sizeof(u16);
2278 2278
2279 return num_samples; 2279 return num_samples;
2280} 2280}
2281 2281
2282static uint32_t ai_convert_counter_6xxx(const struct comedi_device *dev, 2282static u32 ai_convert_counter_6xxx(const struct comedi_device *dev,
2283 const struct comedi_cmd *cmd) 2283 const struct comedi_cmd *cmd)
2284{ 2284{
2285 /* supposed to load counter with desired divisor minus 3 */ 2285 /* supposed to load counter with desired divisor minus 3 */
2286 return cmd->convert_arg / TIMER_BASE - 3; 2286 return cmd->convert_arg / TIMER_BASE - 3;
2287} 2287}
2288 2288
2289static uint32_t ai_scan_counter_6xxx(struct comedi_device *dev, 2289static u32 ai_scan_counter_6xxx(struct comedi_device *dev,
2290 struct comedi_cmd *cmd) 2290 struct comedi_cmd *cmd)
2291{ 2291{
2292 uint32_t count; 2292 u32 count;
2293 2293
2294 /* figure out how long we need to delay at end of scan */ 2294 /* figure out how long we need to delay at end of scan */
2295 switch (cmd->scan_begin_src) { 2295 switch (cmd->scan_begin_src) {
@@ -2307,7 +2307,7 @@ static uint32_t ai_scan_counter_6xxx(struct comedi_device *dev,
2307 return count - 3; 2307 return count - 3;
2308} 2308}
2309 2309
2310static uint32_t ai_convert_counter_4020(struct comedi_device *dev, 2310static u32 ai_convert_counter_4020(struct comedi_device *dev,
2311 struct comedi_cmd *cmd) 2311 struct comedi_cmd *cmd)
2312{ 2312{
2313 struct pcidas64_private *devpriv = dev->private; 2313 struct pcidas64_private *devpriv = dev->private;
@@ -2382,7 +2382,7 @@ static void set_ai_pacing(struct comedi_device *dev, struct comedi_cmd *cmd)
2382{ 2382{
2383 const struct pcidas64_board *board = dev->board_ptr; 2383 const struct pcidas64_board *board = dev->board_ptr;
2384 struct pcidas64_private *devpriv = dev->private; 2384 struct pcidas64_private *devpriv = dev->private;
2385 uint32_t convert_counter = 0, scan_counter = 0; 2385 u32 convert_counter = 0, scan_counter = 0;
2386 2386
2387 check_adc_timing(dev, cmd); 2387 check_adc_timing(dev, cmd);
2388 2388
@@ -2529,7 +2529,7 @@ static int setup_channel_queue(struct comedi_device *dev,
2529 * as it is very slow 2529 * as it is very slow
2530 */ 2530 */
2531 if (old_cal_range_bits != devpriv->i2c_cal_range_bits) { 2531 if (old_cal_range_bits != devpriv->i2c_cal_range_bits) {
2532 uint8_t i2c_data = devpriv->i2c_cal_range_bits; 2532 u8 i2c_data = devpriv->i2c_cal_range_bits;
2533 2533
2534 i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data, 2534 i2c_write(dev, RANGE_CAL_I2C_ADDR, &i2c_data,
2535 sizeof(i2c_data)); 2535 sizeof(i2c_data));
@@ -2572,7 +2572,7 @@ static int ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2572 struct pcidas64_private *devpriv = dev->private; 2572 struct pcidas64_private *devpriv = dev->private;
2573 struct comedi_async *async = s->async; 2573 struct comedi_async *async = s->async;
2574 struct comedi_cmd *cmd = &async->cmd; 2574 struct comedi_cmd *cmd = &async->cmd;
2575 uint32_t bits; 2575 u32 bits;
2576 unsigned int i; 2576 unsigned int i;
2577 unsigned long flags; 2577 unsigned long flags;
2578 int retval; 2578 int retval;
@@ -2634,7 +2634,7 @@ static int ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2634 for (i = 0; i < ai_dma_ring_count(board); i++) 2634 for (i = 0; i < ai_dma_ring_count(board); i++)
2635 devpriv->ai_dma_desc[i].transfer_size = 2635 devpriv->ai_dma_desc[i].transfer_size =
2636 cpu_to_le32(dma_transfer_size(dev) * 2636 cpu_to_le32(dma_transfer_size(dev) *
2637 sizeof(uint16_t)); 2637 sizeof(u16));
2638 2638
2639 /* give location of first dma descriptor */ 2639 /* give location of first dma descriptor */
2640 load_first_dma_descriptor(dev, 1, 2640 load_first_dma_descriptor(dev, 1,
@@ -2691,7 +2691,7 @@ static void pio_drain_ai_fifo_16(struct comedi_device *dev)
2691 struct pcidas64_private *devpriv = dev->private; 2691 struct pcidas64_private *devpriv = dev->private;
2692 struct comedi_subdevice *s = dev->read_subdev; 2692 struct comedi_subdevice *s = dev->read_subdev;
2693 unsigned int i; 2693 unsigned int i;
2694 uint16_t prepost_bits; 2694 u16 prepost_bits;
2695 int read_segment, read_index, write_segment, write_index; 2695 int read_segment, read_index, write_segment, write_index;
2696 int num_samples; 2696 int num_samples;
2697 2697
@@ -2754,7 +2754,7 @@ static void pio_drain_ai_fifo_32(struct comedi_device *dev)
2754 struct comedi_subdevice *s = dev->read_subdev; 2754 struct comedi_subdevice *s = dev->read_subdev;
2755 unsigned int nsamples; 2755 unsigned int nsamples;
2756 unsigned int i; 2756 unsigned int i;
2757 uint32_t fifo_data; 2757 u32 fifo_data;
2758 int write_code = 2758 int write_code =
2759 readw(devpriv->main_iobase + ADC_WRITE_PNTR_REG) & 0x7fff; 2759 readw(devpriv->main_iobase + ADC_WRITE_PNTR_REG) & 0x7fff;
2760 int read_code = 2760 int read_code =
@@ -2794,7 +2794,7 @@ static void drain_dma_buffers(struct comedi_device *dev, unsigned int channel)
2794 const struct pcidas64_board *board = dev->board_ptr; 2794 const struct pcidas64_board *board = dev->board_ptr;
2795 struct pcidas64_private *devpriv = dev->private; 2795 struct pcidas64_private *devpriv = dev->private;
2796 struct comedi_subdevice *s = dev->read_subdev; 2796 struct comedi_subdevice *s = dev->read_subdev;
2797 uint32_t next_transfer_addr; 2797 u32 next_transfer_addr;
2798 int j; 2798 int j;
2799 int num_samples = 0; 2799 int num_samples = 0;
2800 void __iomem *pci_addr_reg; 2800 void __iomem *pci_addr_reg;
@@ -2831,7 +2831,7 @@ static void handle_ai_interrupt(struct comedi_device *dev,
2831 struct comedi_subdevice *s = dev->read_subdev; 2831 struct comedi_subdevice *s = dev->read_subdev;
2832 struct comedi_async *async = s->async; 2832 struct comedi_async *async = s->async;
2833 struct comedi_cmd *cmd = &async->cmd; 2833 struct comedi_cmd *cmd = &async->cmd;
2834 uint8_t dma1_status; 2834 u8 dma1_status;
2835 unsigned long flags; 2835 unsigned long flags;
2836 2836
2837 /* check for fifo overrun */ 2837 /* check for fifo overrun */
@@ -3008,7 +3008,7 @@ static void handle_ao_interrupt(struct comedi_device *dev,
3008 struct comedi_subdevice *s = dev->write_subdev; 3008 struct comedi_subdevice *s = dev->write_subdev;
3009 struct comedi_async *async; 3009 struct comedi_async *async;
3010 struct comedi_cmd *cmd; 3010 struct comedi_cmd *cmd;
3011 uint8_t dma0_status; 3011 u8 dma0_status;
3012 unsigned long flags; 3012 unsigned long flags;
3013 3013
3014 /* board might not support ao, in which case write_subdev is NULL */ 3014 /* board might not support ao, in which case write_subdev is NULL */
@@ -3056,8 +3056,8 @@ static irqreturn_t handle_interrupt(int irq, void *d)
3056 struct comedi_device *dev = d; 3056 struct comedi_device *dev = d;
3057 struct pcidas64_private *devpriv = dev->private; 3057 struct pcidas64_private *devpriv = dev->private;
3058 unsigned short status; 3058 unsigned short status;
3059 uint32_t plx_status; 3059 u32 plx_status;
3060 uint32_t plx_bits; 3060 u32 plx_bits;
3061 3061
3062 plx_status = readl(devpriv->plx9080_iobase + PLX_REG_INTCSR); 3062 plx_status = readl(devpriv->plx9080_iobase + PLX_REG_INTCSR);
3063 status = readw(devpriv->main_iobase + HW_STATUS_REG); 3063 status = readw(devpriv->main_iobase + HW_STATUS_REG);
@@ -3180,7 +3180,7 @@ static void set_dac_select_reg(struct comedi_device *dev,
3180 const struct comedi_cmd *cmd) 3180 const struct comedi_cmd *cmd)
3181{ 3181{
3182 struct pcidas64_private *devpriv = dev->private; 3182 struct pcidas64_private *devpriv = dev->private;
3183 uint16_t bits; 3183 u16 bits;
3184 unsigned int first_channel, last_channel; 3184 unsigned int first_channel, last_channel;
3185 3185
3186 first_channel = CR_CHAN(cmd->chanlist[0]); 3186 first_channel = CR_CHAN(cmd->chanlist[0]);
@@ -3523,7 +3523,7 @@ static int dio_60xx_wbits(struct comedi_device *dev,
3523 */ 3523 */
3524 3524
3525static int caldac_8800_write(struct comedi_device *dev, unsigned int address, 3525static int caldac_8800_write(struct comedi_device *dev, unsigned int address,
3526 uint8_t value) 3526 u8 value)
3527{ 3527{
3528 struct pcidas64_private *devpriv = dev->private; 3528 struct pcidas64_private *devpriv = dev->private;
3529 static const int num_caldac_channels = 8; 3529 static const int num_caldac_channels = 8;
@@ -3558,8 +3558,8 @@ static int caldac_8800_write(struct comedi_device *dev, unsigned int address,
3558static int caldac_i2c_write(struct comedi_device *dev, 3558static int caldac_i2c_write(struct comedi_device *dev,
3559 unsigned int caldac_channel, unsigned int value) 3559 unsigned int caldac_channel, unsigned int value)
3560{ 3560{
3561 uint8_t serial_bytes[3]; 3561 u8 serial_bytes[3];
3562 uint8_t i2c_addr; 3562 u8 i2c_addr;
3563 enum pointer_bits { 3563 enum pointer_bits {
3564 /* manual has gain and offset bits switched */ 3564 /* manual has gain and offset bits switched */
3565 OFFSET_0_2 = 0x1, 3565 OFFSET_0_2 = 0x1,
@@ -3708,7 +3708,7 @@ static int cb_pcidas64_ad8402_insn_write(struct comedi_device *dev,
3708 return insn->n; 3708 return insn->n;
3709} 3709}
3710 3710
3711static uint16_t read_eeprom(struct comedi_device *dev, uint8_t address) 3711static u16 read_eeprom(struct comedi_device *dev, u8 address)
3712{ 3712{
3713 struct pcidas64_private *devpriv = dev->private; 3713 struct pcidas64_private *devpriv = dev->private;
3714 static const int bitstream_length = 11; 3714 static const int bitstream_length = 11;
@@ -3717,7 +3717,7 @@ static uint16_t read_eeprom(struct comedi_device *dev, uint8_t address)
3717 unsigned int bit; 3717 unsigned int bit;
3718 void __iomem * const plx_control_addr = 3718 void __iomem * const plx_control_addr =
3719 devpriv->plx9080_iobase + PLX_REG_CNTRL; 3719 devpriv->plx9080_iobase + PLX_REG_CNTRL;
3720 uint16_t value; 3720 u16 value;
3721 static const int value_length = 16; 3721 static const int value_length = 16;
3722 static const int eeprom_udelay = 1; 3722 static const int eeprom_udelay = 1;
3723 3723
@@ -3813,7 +3813,7 @@ static int setup_subdevices(struct comedi_device *dev)
3813 s->do_cmdtest = ai_cmdtest; 3813 s->do_cmdtest = ai_cmdtest;
3814 s->cancel = ai_cancel; 3814 s->cancel = ai_cancel;
3815 if (board->layout == LAYOUT_4020) { 3815 if (board->layout == LAYOUT_4020) {
3816 uint8_t data; 3816 u8 data;
3817 /* 3817 /*
3818 * set adc to read from inputs 3818 * set adc to read from inputs
3819 * (not internal calibration sources) 3819 * (not internal calibration sources)
@@ -3975,7 +3975,7 @@ static int auto_attach(struct comedi_device *dev,
3975 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 3975 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
3976 const struct pcidas64_board *board = NULL; 3976 const struct pcidas64_board *board = NULL;
3977 struct pcidas64_private *devpriv; 3977 struct pcidas64_private *devpriv;
3978 uint32_t local_range, local_decode; 3978 u32 local_range, local_decode;
3979 int retval; 3979 int retval;
3980 3980
3981 if (context < ARRAY_SIZE(pcidas64_boards)) 3981 if (context < ARRAY_SIZE(pcidas64_boards))
@@ -4013,13 +4013,13 @@ static int auto_attach(struct comedi_device *dev,
4013 PLX_LASRR_MEM_MASK; 4013 PLX_LASRR_MEM_MASK;
4014 local_decode = readl(devpriv->plx9080_iobase + PLX_REG_LAS0BA) & 4014 local_decode = readl(devpriv->plx9080_iobase + PLX_REG_LAS0BA) &
4015 local_range & PLX_LASBA_MEM_MASK; 4015 local_range & PLX_LASBA_MEM_MASK;
4016 devpriv->local0_iobase = ((uint32_t)devpriv->main_phys_iobase & 4016 devpriv->local0_iobase = ((u32)devpriv->main_phys_iobase &
4017 ~local_range) | local_decode; 4017 ~local_range) | local_decode;
4018 local_range = readl(devpriv->plx9080_iobase + PLX_REG_LAS1RR) & 4018 local_range = readl(devpriv->plx9080_iobase + PLX_REG_LAS1RR) &
4019 PLX_LASRR_MEM_MASK; 4019 PLX_LASRR_MEM_MASK;
4020 local_decode = readl(devpriv->plx9080_iobase + PLX_REG_LAS1BA) & 4020 local_decode = readl(devpriv->plx9080_iobase + PLX_REG_LAS1BA) &
4021 local_range & PLX_LASBA_MEM_MASK; 4021 local_range & PLX_LASBA_MEM_MASK;
4022 devpriv->local1_iobase = ((uint32_t)devpriv->dio_counter_phys_iobase & 4022 devpriv->local1_iobase = ((u32)devpriv->dio_counter_phys_iobase &
4023 ~local_range) | local_decode; 4023 ~local_range) | local_decode;
4024 4024
4025 retval = alloc_and_init_dma_members(dev); 4025 retval = alloc_and_init_dma_members(dev);
diff --git a/drivers/staging/comedi/drivers/comedi_8254.h b/drivers/staging/comedi/drivers/comedi_8254.h
index a12c29455d9d..326bd44b063e 100644
--- a/drivers/staging/comedi/drivers/comedi_8254.h
+++ b/drivers/staging/comedi/drivers/comedi_8254.h
@@ -100,34 +100,36 @@ struct comedi_8254 {
100 unsigned int gate_src[3]; 100 unsigned int gate_src[3];
101 bool busy[3]; 101 bool busy[3];
102 102
103 int (*insn_config)(struct comedi_device *, struct comedi_subdevice *s, 103 int (*insn_config)(struct comedi_device *dev,
104 struct comedi_insn *, unsigned int *data); 104 struct comedi_subdevice *s,
105 struct comedi_insn *insn, unsigned int *data);
105}; 106};
106 107
107unsigned int comedi_8254_status(struct comedi_8254 *, unsigned int counter); 108unsigned int comedi_8254_status(struct comedi_8254 *i8254,
108unsigned int comedi_8254_read(struct comedi_8254 *, unsigned int counter); 109 unsigned int counter);
109void comedi_8254_write(struct comedi_8254 *, 110unsigned int comedi_8254_read(struct comedi_8254 *i8254, unsigned int counter);
111void comedi_8254_write(struct comedi_8254 *i8254,
110 unsigned int counter, unsigned int val); 112 unsigned int counter, unsigned int val);
111 113
112int comedi_8254_set_mode(struct comedi_8254 *, 114int comedi_8254_set_mode(struct comedi_8254 *i8254,
113 unsigned int counter, unsigned int mode); 115 unsigned int counter, unsigned int mode);
114int comedi_8254_load(struct comedi_8254 *, 116int comedi_8254_load(struct comedi_8254 *i8254,
115 unsigned int counter, unsigned int val, unsigned int mode); 117 unsigned int counter, unsigned int val, unsigned int mode);
116 118
117void comedi_8254_pacer_enable(struct comedi_8254 *, 119void comedi_8254_pacer_enable(struct comedi_8254 *i8254,
118 unsigned int counter1, unsigned int counter2, 120 unsigned int counter1, unsigned int counter2,
119 bool enable); 121 bool enable);
120void comedi_8254_update_divisors(struct comedi_8254 *); 122void comedi_8254_update_divisors(struct comedi_8254 *i8254);
121void comedi_8254_cascade_ns_to_timer(struct comedi_8254 *, 123void comedi_8254_cascade_ns_to_timer(struct comedi_8254 *i8254,
122 unsigned int *nanosec, unsigned int flags); 124 unsigned int *nanosec, unsigned int flags);
123void comedi_8254_ns_to_timer(struct comedi_8254 *, 125void comedi_8254_ns_to_timer(struct comedi_8254 *i8254,
124 unsigned int *nanosec, unsigned int flags); 126 unsigned int *nanosec, unsigned int flags);
125 127
126void comedi_8254_set_busy(struct comedi_8254 *, 128void comedi_8254_set_busy(struct comedi_8254 *i8254,
127 unsigned int counter, bool busy); 129 unsigned int counter, bool busy);
128 130
129void comedi_8254_subdevice_init(struct comedi_subdevice *, 131void comedi_8254_subdevice_init(struct comedi_subdevice *s,
130 struct comedi_8254 *); 132 struct comedi_8254 *i8254);
131 133
132struct comedi_8254 *comedi_8254_init(unsigned long iobase, 134struct comedi_8254 *comedi_8254_init(unsigned long iobase,
133 unsigned int osc_base, 135 unsigned int osc_base,
diff --git a/drivers/staging/comedi/drivers/comedi_isadma.h b/drivers/staging/comedi/drivers/comedi_isadma.h
index 2fb6573ba9e4..a193d3e8d185 100644
--- a/drivers/staging/comedi/drivers/comedi_isadma.h
+++ b/drivers/staging/comedi/drivers/comedi_isadma.h
@@ -63,18 +63,18 @@ struct comedi_isadma {
63 63
64#if IS_ENABLED(CONFIG_ISA_DMA_API) 64#if IS_ENABLED(CONFIG_ISA_DMA_API)
65 65
66void comedi_isadma_program(struct comedi_isadma_desc *); 66void comedi_isadma_program(struct comedi_isadma_desc *desc);
67unsigned int comedi_isadma_disable(unsigned int dma_chan); 67unsigned int comedi_isadma_disable(unsigned int dma_chan);
68unsigned int comedi_isadma_disable_on_sample(unsigned int dma_chan, 68unsigned int comedi_isadma_disable_on_sample(unsigned int dma_chan,
69 unsigned int size); 69 unsigned int size);
70unsigned int comedi_isadma_poll(struct comedi_isadma *); 70unsigned int comedi_isadma_poll(struct comedi_isadma *dma);
71void comedi_isadma_set_mode(struct comedi_isadma_desc *, char dma_dir); 71void comedi_isadma_set_mode(struct comedi_isadma_desc *desc, char dma_dir);
72 72
73struct comedi_isadma *comedi_isadma_alloc(struct comedi_device *, 73struct comedi_isadma *comedi_isadma_alloc(struct comedi_device *dev,
74 int n_desc, unsigned int dma_chan1, 74 int n_desc, unsigned int dma_chan1,
75 unsigned int dma_chan2, 75 unsigned int dma_chan2,
76 unsigned int maxsize, char dma_dir); 76 unsigned int maxsize, char dma_dir);
77void comedi_isadma_free(struct comedi_isadma *); 77void comedi_isadma_free(struct comedi_isadma *dma);
78 78
79#else /* !IS_ENABLED(CONFIG_ISA_DMA_API) */ 79#else /* !IS_ENABLED(CONFIG_ISA_DMA_API) */
80 80
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index ec5b9a23494d..2a063f07fe7b 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -36,7 +36,15 @@
36 * generate sample waveforms on systems that don't have data acquisition 36 * generate sample waveforms on systems that don't have data acquisition
37 * hardware. 37 * hardware.
38 * 38 *
39 * Configuration options: 39 * Auto-configuration is the default mode if no parameter is supplied during
40 * module loading. Manual configuration requires COMEDI userspace tool.
41 * To disable auto-configuration mode, pass "noauto=1" parameter for module
42 * loading. Refer modinfo or MODULE_PARM_DESC description below for details.
43 *
44 * Auto-configuration options:
45 * Refer modinfo or MODULE_PARM_DESC description below for details.
46 *
47 * Manual configuration options:
40 * [0] - Amplitude in microvolts for fake waveforms (default 1 volt) 48 * [0] - Amplitude in microvolts for fake waveforms (default 1 volt)
41 * [1] - Period in microseconds for fake waveforms (default 0.1 sec) 49 * [1] - Period in microseconds for fake waveforms (default 0.1 sec)
42 * 50 *
@@ -53,8 +61,27 @@
53#include <linux/timer.h> 61#include <linux/timer.h>
54#include <linux/ktime.h> 62#include <linux/ktime.h>
55#include <linux/jiffies.h> 63#include <linux/jiffies.h>
64#include <linux/device.h>
65#include <linux/kdev_t.h>
56 66
57#define N_CHANS 8 67#define N_CHANS 8
68#define DEV_NAME "comedi_testd"
69#define CLASS_NAME "comedi_test"
70
71static bool config_mode;
72static unsigned int set_amplitude;
73static unsigned int set_period;
74static struct class *ctcls;
75static struct device *ctdev;
76
77module_param_named(noauto, config_mode, bool, 0444);
78MODULE_PARM_DESC(noauto, "Disable auto-configuration: (1=disable [defaults to enable])");
79
80module_param_named(amplitude, set_amplitude, uint, 0444);
81MODULE_PARM_DESC(amplitude, "Set auto mode wave amplitude in microvolts: (defaults to 1 volt)");
82
83module_param_named(period, set_period, uint, 0444);
84MODULE_PARM_DESC(period, "Set auto mode wave period in microseconds: (defaults to 0.1 sec)");
58 85
59/* Data unique to this driver */ 86/* Data unique to this driver */
60struct waveform_private { 87struct waveform_private {
@@ -607,13 +634,11 @@ static int waveform_ao_insn_write(struct comedi_device *dev,
607 return insn->n; 634 return insn->n;
608} 635}
609 636
610static int waveform_attach(struct comedi_device *dev, 637static int waveform_common_attach(struct comedi_device *dev,
611 struct comedi_devconfig *it) 638 int amplitude, int period)
612{ 639{
613 struct waveform_private *devpriv; 640 struct waveform_private *devpriv;
614 struct comedi_subdevice *s; 641 struct comedi_subdevice *s;
615 int amplitude = it->options[0];
616 int period = it->options[1];
617 int i; 642 int i;
618 int ret; 643 int ret;
619 644
@@ -621,12 +646,6 @@ static int waveform_attach(struct comedi_device *dev,
621 if (!devpriv) 646 if (!devpriv)
622 return -ENOMEM; 647 return -ENOMEM;
623 648
624 /* set default amplitude and period */
625 if (amplitude <= 0)
626 amplitude = 1000000; /* 1 volt */
627 if (period <= 0)
628 period = 100000; /* 0.1 sec */
629
630 devpriv->wf_amplitude = amplitude; 649 devpriv->wf_amplitude = amplitude;
631 devpriv->wf_period = period; 650 devpriv->wf_period = period;
632 651
@@ -678,6 +697,36 @@ static int waveform_attach(struct comedi_device *dev,
678 return 0; 697 return 0;
679} 698}
680 699
700static int waveform_attach(struct comedi_device *dev,
701 struct comedi_devconfig *it)
702{
703 int amplitude = it->options[0];
704 int period = it->options[1];
705
706 /* set default amplitude and period */
707 if (amplitude <= 0)
708 amplitude = 1000000; /* 1 volt */
709 if (period <= 0)
710 period = 100000; /* 0.1 sec */
711
712 return waveform_common_attach(dev, amplitude, period);
713}
714
715static int waveform_auto_attach(struct comedi_device *dev,
716 unsigned long context_unused)
717{
718 int amplitude = set_amplitude;
719 int period = set_period;
720
721 /* set default amplitude and period */
722 if (!amplitude)
723 amplitude = 1000000; /* 1 volt */
724 if (!period)
725 period = 100000; /* 0.1 sec */
726
727 return waveform_common_attach(dev, amplitude, period);
728}
729
681static void waveform_detach(struct comedi_device *dev) 730static void waveform_detach(struct comedi_device *dev)
682{ 731{
683 struct waveform_private *devpriv = dev->private; 732 struct waveform_private *devpriv = dev->private;
@@ -692,9 +741,71 @@ static struct comedi_driver waveform_driver = {
692 .driver_name = "comedi_test", 741 .driver_name = "comedi_test",
693 .module = THIS_MODULE, 742 .module = THIS_MODULE,
694 .attach = waveform_attach, 743 .attach = waveform_attach,
744 .auto_attach = waveform_auto_attach,
695 .detach = waveform_detach, 745 .detach = waveform_detach,
696}; 746};
697module_comedi_driver(waveform_driver); 747
748/*
749 * For auto-configuration, a device is created to stand in for a
750 * real hardware device.
751 */
752static int __init comedi_test_init(void)
753{
754 int ret;
755
756 ret = comedi_driver_register(&waveform_driver);
757 if (ret) {
758 pr_err("comedi_test: unable to register driver\n");
759 return ret;
760 }
761
762 if (!config_mode) {
763 ctcls = class_create(THIS_MODULE, CLASS_NAME);
764 if (IS_ERR(ctcls)) {
765 pr_warn("comedi_test: unable to create class\n");
766 goto clean3;
767 }
768
769 ctdev = device_create(ctcls, NULL, MKDEV(0, 0), NULL, DEV_NAME);
770 if (IS_ERR(ctdev)) {
771 pr_warn("comedi_test: unable to create device\n");
772 goto clean2;
773 }
774
775 ret = comedi_auto_config(ctdev, &waveform_driver, 0);
776 if (ret) {
777 pr_warn("comedi_test: unable to auto-configure device\n");
778 goto clean;
779 }
780 }
781
782 return 0;
783
784clean:
785 device_destroy(ctcls, MKDEV(0, 0));
786clean2:
787 class_destroy(ctcls);
788 ctdev = NULL;
789clean3:
790 ctcls = NULL;
791
792 return 0;
793}
794module_init(comedi_test_init);
795
796static void __exit comedi_test_exit(void)
797{
798 if (ctdev)
799 comedi_auto_unconfig(ctdev);
800
801 if (ctcls) {
802 device_destroy(ctcls, MKDEV(0, 0));
803 class_destroy(ctcls);
804 }
805
806 comedi_driver_unregister(&waveform_driver);
807}
808module_exit(comedi_test_exit);
698 809
699MODULE_AUTHOR("Comedi http://www.comedi.org"); 810MODULE_AUTHOR("Comedi http://www.comedi.org");
700MODULE_DESCRIPTION("Comedi low-level driver"); 811MODULE_DESCRIPTION("Comedi low-level driver");
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index 0f4eb954aa80..32dd8a857b6b 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -109,28 +109,11 @@
109#include "../comedi_pci.h" 109#include "../comedi_pci.h"
110 110
111#include "8255.h" 111#include "8255.h"
112#include "plx9080.h"
112 113
113#define DAQBOARD2000_FIRMWARE "daqboard2000_firmware.bin" 114#define DB2K_FIRMWARE "daqboard2000_firmware.bin"
114 115
115#define DAQBOARD2000_SUBSYSTEM_IDS2 0x0002 /* Daqboard/2000 - 2 Dacs */ 116static const struct comedi_lrange db2k_ai_range = {
116#define DAQBOARD2000_SUBSYSTEM_IDS4 0x0004 /* Daqboard/2000 - 4 Dacs */
117
118/* Initialization bits for the Serial EEPROM Control Register */
119#define DB2K_SECR_PROG_PIN_HI 0x8001767e
120#define DB2K_SECR_PROG_PIN_LO 0x8000767e
121#define DB2K_SECR_LOCAL_BUS_HI 0xc000767e
122#define DB2K_SECR_LOCAL_BUS_LO 0x8000767e
123#define DB2K_SECR_RELOAD_HI 0xa000767e
124#define DB2K_SECR_RELOAD_LO 0x8000767e
125
126/* SECR status bits */
127#define DAQBOARD2000_EEPROM_PRESENT 0x10000000
128
129/* CPLD status bits */
130#define DAQBOARD2000_CPLD_INIT 0x0002
131#define DAQBOARD2000_CPLD_DONE 0x0004
132
133static const struct comedi_lrange range_daqboard2000_ai = {
134 13, { 117 13, {
135 BIP_RANGE(10), 118 BIP_RANGE(10),
136 BIP_RANGE(5), 119 BIP_RANGE(5),
@@ -183,6 +166,10 @@ static const struct comedi_lrange range_daqboard2000_ai = {
183#define DB2K_REG_TRIG_DACS 0xbc /* u16 */ 166#define DB2K_REG_TRIG_DACS 0xbc /* u16 */
184#define DB2K_REG_DIO_P2_EXP_IO_16_BIT(x) (0xc0 + (x) * 2) /* s16 */ 167#define DB2K_REG_DIO_P2_EXP_IO_16_BIT(x) (0xc0 + (x) * 2) /* s16 */
185 168
169/* CPLD registers */
170#define DB2K_REG_CPLD_STATUS 0x1000 /* u16 (r) */
171#define DB2K_REG_CPLD_WDATA 0x1000 /* u16 (w) */
172
186/* Scan Sequencer programming */ 173/* Scan Sequencer programming */
187#define DB2K_ACQ_CONTROL_SEQ_START_SCAN_LIST 0x0011 174#define DB2K_ACQ_CONTROL_SEQ_START_SCAN_LIST 0x0011
188#define DB2K_ACQ_CONTROL_SEQ_STOP_SCAN_LIST 0x0010 175#define DB2K_ACQ_CONTROL_SEQ_STOP_SCAN_LIST 0x0010
@@ -248,33 +235,45 @@ static const struct comedi_lrange range_daqboard2000_ai = {
248#define DB2K_REF_DACS_SELECT_POS_REF 0x0100 235#define DB2K_REF_DACS_SELECT_POS_REF 0x0100
249#define DB2K_REF_DACS_SELECT_NEG_REF 0x0000 236#define DB2K_REF_DACS_SELECT_NEG_REF 0x0000
250 237
251struct daq200_boardtype { 238/* CPLD status bits */
239#define DB2K_CPLD_STATUS_INIT 0x0002
240#define DB2K_CPLD_STATUS_TXREADY 0x0004
241#define DB2K_CPLD_VERSION_MASK 0xf000
242/* "New CPLD" signature. */
243#define DB2K_CPLD_VERSION_NEW 0x5000
244
245enum db2k_boardid {
246 BOARD_DAQBOARD2000,
247 BOARD_DAQBOARD2001
248};
249
250struct db2k_boardtype {
252 const char *name; 251 const char *name;
253 int id; 252 bool has_2_ao:1; /* false: 4 AO chans; true: 2 AO chans */
254}; 253};
255 254
256static const struct daq200_boardtype boardtypes[] = { 255static const struct db2k_boardtype db2k_boardtypes[] = {
257 {"ids2", DAQBOARD2000_SUBSYSTEM_IDS2}, 256 [BOARD_DAQBOARD2000] = {
258 {"ids4", DAQBOARD2000_SUBSYSTEM_IDS4}, 257 .name = "daqboard2000",
258 .has_2_ao = true,
259 },
260 [BOARD_DAQBOARD2001] = {
261 .name = "daqboard2001",
262 },
259}; 263};
260 264
261struct daqboard2000_private { 265struct db2k_private {
262 enum {
263 card_daqboard_2000
264 } card;
265 void __iomem *plx; 266 void __iomem *plx;
266}; 267};
267 268
268static void daqboard2000_write_acq_scan_list_entry(struct comedi_device *dev, 269static void db2k_write_acq_scan_list_entry(struct comedi_device *dev, u16 entry)
269 u16 entry)
270{ 270{
271 writew(entry & 0x00ff, dev->mmio + DB2K_REG_ACQ_SCAN_LIST_FIFO); 271 writew(entry & 0x00ff, dev->mmio + DB2K_REG_ACQ_SCAN_LIST_FIFO);
272 writew((entry >> 8) & 0x00ff, 272 writew((entry >> 8) & 0x00ff,
273 dev->mmio + DB2K_REG_ACQ_SCAN_LIST_FIFO); 273 dev->mmio + DB2K_REG_ACQ_SCAN_LIST_FIFO);
274} 274}
275 275
276static void daqboard2000_setup_sampling(struct comedi_device *dev, int chan, 276static void db2k_setup_sampling(struct comedi_device *dev, int chan, int gain)
277 int gain)
278{ 277{
279 u16 word0, word1, word2, word3; 278 u16 word0, word1, word2, word3;
280 279
@@ -308,16 +307,14 @@ static void daqboard2000_setup_sampling(struct comedi_device *dev, int chan,
308 /* These should be read from EEPROM */ 307 /* These should be read from EEPROM */
309 word2 |= 0x0800; /* offset */ 308 word2 |= 0x0800; /* offset */
310 word3 |= 0xc000; /* gain */ 309 word3 |= 0xc000; /* gain */
311 daqboard2000_write_acq_scan_list_entry(dev, word0); 310 db2k_write_acq_scan_list_entry(dev, word0);
312 daqboard2000_write_acq_scan_list_entry(dev, word1); 311 db2k_write_acq_scan_list_entry(dev, word1);
313 daqboard2000_write_acq_scan_list_entry(dev, word2); 312 db2k_write_acq_scan_list_entry(dev, word2);
314 daqboard2000_write_acq_scan_list_entry(dev, word3); 313 db2k_write_acq_scan_list_entry(dev, word3);
315} 314}
316 315
317static int daqboard2000_ai_status(struct comedi_device *dev, 316static int db2k_ai_status(struct comedi_device *dev, struct comedi_subdevice *s,
318 struct comedi_subdevice *s, 317 struct comedi_insn *insn, unsigned long context)
319 struct comedi_insn *insn,
320 unsigned long context)
321{ 318{
322 unsigned int status; 319 unsigned int status;
323 320
@@ -327,10 +324,9 @@ static int daqboard2000_ai_status(struct comedi_device *dev,
327 return -EBUSY; 324 return -EBUSY;
328} 325}
329 326
330static int daqboard2000_ai_insn_read(struct comedi_device *dev, 327static int db2k_ai_insn_read(struct comedi_device *dev,
331 struct comedi_subdevice *s, 328 struct comedi_subdevice *s,
332 struct comedi_insn *insn, 329 struct comedi_insn *insn, unsigned int *data)
333 unsigned int *data)
334{ 330{
335 int gain, chan; 331 int gain, chan;
336 int ret; 332 int ret;
@@ -359,12 +355,12 @@ static int daqboard2000_ai_insn_read(struct comedi_device *dev,
359 * forced to fix it. --ds 355 * forced to fix it. --ds
360 */ 356 */
361 for (i = 0; i < insn->n; i++) { 357 for (i = 0; i < insn->n; i++) {
362 daqboard2000_setup_sampling(dev, chan, gain); 358 db2k_setup_sampling(dev, chan, gain);
363 /* Enable reading from the scanlist FIFO */ 359 /* Enable reading from the scanlist FIFO */
364 writew(DB2K_ACQ_CONTROL_SEQ_START_SCAN_LIST, 360 writew(DB2K_ACQ_CONTROL_SEQ_START_SCAN_LIST,
365 dev->mmio + DB2K_REG_ACQ_CONTROL); 361 dev->mmio + DB2K_REG_ACQ_CONTROL);
366 362
367 ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status, 363 ret = comedi_timeout(dev, s, insn, db2k_ai_status,
368 DB2K_ACQ_STATUS_CONFIG_PIPE_FULL); 364 DB2K_ACQ_STATUS_CONFIG_PIPE_FULL);
369 if (ret) 365 if (ret)
370 return ret; 366 return ret;
@@ -372,13 +368,13 @@ static int daqboard2000_ai_insn_read(struct comedi_device *dev,
372 writew(DB2K_ACQ_CONTROL_ADC_PACER_ENABLE, 368 writew(DB2K_ACQ_CONTROL_ADC_PACER_ENABLE,
373 dev->mmio + DB2K_REG_ACQ_CONTROL); 369 dev->mmio + DB2K_REG_ACQ_CONTROL);
374 370
375 ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status, 371 ret = comedi_timeout(dev, s, insn, db2k_ai_status,
376 DB2K_ACQ_STATUS_LOGIC_SCANNING); 372 DB2K_ACQ_STATUS_LOGIC_SCANNING);
377 if (ret) 373 if (ret)
378 return ret; 374 return ret;
379 375
380 ret = 376 ret =
381 comedi_timeout(dev, s, insn, daqboard2000_ai_status, 377 comedi_timeout(dev, s, insn, db2k_ai_status,
382 DB2K_ACQ_STATUS_RESULTS_FIFO_HAS_DATA); 378 DB2K_ACQ_STATUS_RESULTS_FIFO_HAS_DATA);
383 if (ret) 379 if (ret)
384 return ret; 380 return ret;
@@ -393,10 +389,8 @@ static int daqboard2000_ai_insn_read(struct comedi_device *dev,
393 return i; 389 return i;
394} 390}
395 391
396static int daqboard2000_ao_eoc(struct comedi_device *dev, 392static int db2k_ao_eoc(struct comedi_device *dev, struct comedi_subdevice *s,
397 struct comedi_subdevice *s, 393 struct comedi_insn *insn, unsigned long context)
398 struct comedi_insn *insn,
399 unsigned long context)
400{ 394{
401 unsigned int chan = CR_CHAN(insn->chanspec); 395 unsigned int chan = CR_CHAN(insn->chanspec);
402 unsigned int status; 396 unsigned int status;
@@ -407,10 +401,9 @@ static int daqboard2000_ao_eoc(struct comedi_device *dev,
407 return -EBUSY; 401 return -EBUSY;
408} 402}
409 403
410static int daqboard2000_ao_insn_write(struct comedi_device *dev, 404static int db2k_ao_insn_write(struct comedi_device *dev,
411 struct comedi_subdevice *s, 405 struct comedi_subdevice *s,
412 struct comedi_insn *insn, 406 struct comedi_insn *insn, unsigned int *data)
413 unsigned int *data)
414{ 407{
415 unsigned int chan = CR_CHAN(insn->chanspec); 408 unsigned int chan = CR_CHAN(insn->chanspec);
416 int i; 409 int i;
@@ -421,7 +414,7 @@ static int daqboard2000_ao_insn_write(struct comedi_device *dev,
421 414
422 writew(val, dev->mmio + DB2K_REG_DAC_SETTING(chan)); 415 writew(val, dev->mmio + DB2K_REG_DAC_SETTING(chan));
423 416
424 ret = comedi_timeout(dev, s, insn, daqboard2000_ao_eoc, 0); 417 ret = comedi_timeout(dev, s, insn, db2k_ao_eoc, 0);
425 if (ret) 418 if (ret)
426 return ret; 419 return ret;
427 420
@@ -431,49 +424,62 @@ static int daqboard2000_ao_insn_write(struct comedi_device *dev,
431 return insn->n; 424 return insn->n;
432} 425}
433 426
434static void daqboard2000_reset_local_bus(struct comedi_device *dev) 427static void db2k_reset_local_bus(struct comedi_device *dev)
435{ 428{
436 struct daqboard2000_private *devpriv = dev->private; 429 struct db2k_private *devpriv = dev->private;
430 u32 cntrl;
437 431
438 writel(DB2K_SECR_LOCAL_BUS_HI, devpriv->plx + 0x6c); 432 cntrl = readl(devpriv->plx + PLX_REG_CNTRL);
433 cntrl |= PLX_CNTRL_RESET;
434 writel(cntrl, devpriv->plx + PLX_REG_CNTRL);
439 mdelay(10); 435 mdelay(10);
440 writel(DB2K_SECR_LOCAL_BUS_LO, devpriv->plx + 0x6c); 436 cntrl &= ~PLX_CNTRL_RESET;
437 writel(cntrl, devpriv->plx + PLX_REG_CNTRL);
441 mdelay(10); 438 mdelay(10);
442} 439}
443 440
444static void daqboard2000_reload_plx(struct comedi_device *dev) 441static void db2k_reload_plx(struct comedi_device *dev)
445{ 442{
446 struct daqboard2000_private *devpriv = dev->private; 443 struct db2k_private *devpriv = dev->private;
444 u32 cntrl;
447 445
448 writel(DB2K_SECR_RELOAD_LO, devpriv->plx + 0x6c); 446 cntrl = readl(devpriv->plx + PLX_REG_CNTRL);
447 cntrl &= ~PLX_CNTRL_EERELOAD;
448 writel(cntrl, devpriv->plx + PLX_REG_CNTRL);
449 mdelay(10); 449 mdelay(10);
450 writel(DB2K_SECR_RELOAD_HI, devpriv->plx + 0x6c); 450 cntrl |= PLX_CNTRL_EERELOAD;
451 writel(cntrl, devpriv->plx + PLX_REG_CNTRL);
451 mdelay(10); 452 mdelay(10);
452 writel(DB2K_SECR_RELOAD_LO, devpriv->plx + 0x6c); 453 cntrl &= ~PLX_CNTRL_EERELOAD;
454 writel(cntrl, devpriv->plx + PLX_REG_CNTRL);
453 mdelay(10); 455 mdelay(10);
454} 456}
455 457
456static void daqboard2000_pulse_prog_pin(struct comedi_device *dev) 458static void db2k_pulse_prog_pin(struct comedi_device *dev)
457{ 459{
458 struct daqboard2000_private *devpriv = dev->private; 460 struct db2k_private *devpriv = dev->private;
461 u32 cntrl;
459 462
460 writel(DB2K_SECR_PROG_PIN_HI, devpriv->plx + 0x6c); 463 cntrl = readl(devpriv->plx + PLX_REG_CNTRL);
464 cntrl |= PLX_CNTRL_USERO;
465 writel(cntrl, devpriv->plx + PLX_REG_CNTRL);
461 mdelay(10); 466 mdelay(10);
462 writel(DB2K_SECR_PROG_PIN_LO, devpriv->plx + 0x6c); 467 cntrl &= ~PLX_CNTRL_USERO;
468 writel(cntrl, devpriv->plx + PLX_REG_CNTRL);
463 mdelay(10); /* Not in the original code, but I like symmetry... */ 469 mdelay(10); /* Not in the original code, but I like symmetry... */
464} 470}
465 471
466static int daqboard2000_poll_cpld(struct comedi_device *dev, int mask) 472static int db2k_wait_cpld_init(struct comedi_device *dev)
467{ 473{
468 int result = 0; 474 int result = -ETIMEDOUT;
469 int i; 475 int i;
470 int cpld; 476 u16 cpld;
471 477
472 /* timeout after 50 tries -> 5ms */ 478 /* timeout after 50 tries -> 5ms */
473 for (i = 0; i < 50; i++) { 479 for (i = 0; i < 50; i++) {
474 cpld = readw(dev->mmio + 0x1000); 480 cpld = readw(dev->mmio + DB2K_REG_CPLD_STATUS);
475 if ((cpld & mask) == mask) { 481 if (cpld & DB2K_CPLD_STATUS_INIT) {
476 result = 1; 482 result = 0;
477 break; 483 break;
478 } 484 }
479 usleep_range(100, 1000); 485 usleep_range(100, 1000);
@@ -482,67 +488,123 @@ static int daqboard2000_poll_cpld(struct comedi_device *dev, int mask)
482 return result; 488 return result;
483} 489}
484 490
485static int daqboard2000_write_cpld(struct comedi_device *dev, int data) 491static int db2k_wait_cpld_txready(struct comedi_device *dev)
492{
493 int i;
494
495 for (i = 0; i < 100; i++) {
496 if (readw(dev->mmio + DB2K_REG_CPLD_STATUS) &
497 DB2K_CPLD_STATUS_TXREADY) {
498 return 0;
499 }
500 udelay(1);
501 }
502 return -ETIMEDOUT;
503}
504
505static int db2k_write_cpld(struct comedi_device *dev, u16 data, bool new_cpld)
486{ 506{
487 int result = 0; 507 int result = 0;
488 508
489 usleep_range(10, 20); 509 if (new_cpld) {
490 writew(data, dev->mmio + 0x1000); 510 result = db2k_wait_cpld_txready(dev);
491 if ((readw(dev->mmio + 0x1000) & DAQBOARD2000_CPLD_INIT) == 511 if (result)
492 DAQBOARD2000_CPLD_INIT) { 512 return result;
493 result = 1; 513 } else {
514 usleep_range(10, 20);
494 } 515 }
516 writew(data, dev->mmio + DB2K_REG_CPLD_WDATA);
517 if (!(readw(dev->mmio + DB2K_REG_CPLD_STATUS) & DB2K_CPLD_STATUS_INIT))
518 result = -EIO;
519
495 return result; 520 return result;
496} 521}
497 522
498static int daqboard2000_load_firmware(struct comedi_device *dev, 523static int db2k_wait_fpga_programmed(struct comedi_device *dev)
499 const u8 *cpld_array, size_t len, 524{
500 unsigned long context) 525 struct db2k_private *devpriv = dev->private;
526 int i;
527
528 /* Time out after 200 tries -> 20ms */
529 for (i = 0; i < 200; i++) {
530 u32 cntrl = readl(devpriv->plx + PLX_REG_CNTRL);
531 /* General Purpose Input (USERI) set on FPGA "DONE". */
532 if (cntrl & PLX_CNTRL_USERI)
533 return 0;
534
535 usleep_range(100, 1000);
536 }
537 return -ETIMEDOUT;
538}
539
540static int db2k_load_firmware(struct comedi_device *dev, const u8 *cpld_array,
541 size_t len, unsigned long context)
501{ 542{
502 struct daqboard2000_private *devpriv = dev->private; 543 struct db2k_private *devpriv = dev->private;
503 int result = -EIO; 544 int result = -EIO;
504 /* Read the serial EEPROM control register */ 545 u32 cntrl;
505 int secr;
506 int retry; 546 int retry;
507 size_t i; 547 size_t i;
548 bool new_cpld;
549
550 /* Look for FPGA start sequence in firmware. */
551 for (i = 0; i + 1 < len; i++) {
552 if (cpld_array[i] == 0xff && cpld_array[i + 1] == 0x20)
553 break;
554 }
555 if (i + 1 >= len) {
556 dev_err(dev->class_dev, "bad firmware - no start sequence\n");
557 return -EINVAL;
558 }
559 /* Check length is even. */
560 if ((len - i) & 1) {
561 dev_err(dev->class_dev,
562 "bad firmware - odd length (%zu = %zu - %zu)\n",
563 len - i, len, i);
564 return -EINVAL;
565 }
566 /* Strip firmware header. */
567 cpld_array += i;
568 len -= i;
508 569
509 /* Check to make sure the serial eeprom is present on the board */ 570 /* Check to make sure the serial eeprom is present on the board */
510 secr = readl(devpriv->plx + 0x6c); 571 cntrl = readl(devpriv->plx + PLX_REG_CNTRL);
511 if (!(secr & DAQBOARD2000_EEPROM_PRESENT)) 572 if (!(cntrl & PLX_CNTRL_EEPRESENT))
512 return -EIO; 573 return -EIO;
513 574
514 for (retry = 0; retry < 3; retry++) { 575 for (retry = 0; retry < 3; retry++) {
515 daqboard2000_reset_local_bus(dev); 576 db2k_reset_local_bus(dev);
516 daqboard2000_reload_plx(dev); 577 db2k_reload_plx(dev);
517 daqboard2000_pulse_prog_pin(dev); 578 db2k_pulse_prog_pin(dev);
518 if (daqboard2000_poll_cpld(dev, DAQBOARD2000_CPLD_INIT)) { 579 result = db2k_wait_cpld_init(dev);
519 for (i = 0; i < len; i++) { 580 if (result)
520 if (cpld_array[i] == 0xff && 581 continue;
521 cpld_array[i + 1] == 0x20) 582
522 break; 583 new_cpld = (readw(dev->mmio + DB2K_REG_CPLD_STATUS) &
523 } 584 DB2K_CPLD_VERSION_MASK) == DB2K_CPLD_VERSION_NEW;
524 for (; i < len; i += 2) { 585 for (; i < len; i += 2) {
525 int data = 586 u16 data = (cpld_array[i] << 8) + cpld_array[i + 1];
526 (cpld_array[i] << 8) + cpld_array[i + 1]; 587
527 if (!daqboard2000_write_cpld(dev, data)) 588 result = db2k_write_cpld(dev, data, new_cpld);
528 break; 589 if (result)
529 }
530 if (i >= len) {
531 daqboard2000_reset_local_bus(dev);
532 daqboard2000_reload_plx(dev);
533 result = 0;
534 break; 590 break;
535 } 591 }
592 if (result == 0)
593 result = db2k_wait_fpga_programmed(dev);
594 if (result == 0) {
595 db2k_reset_local_bus(dev);
596 db2k_reload_plx(dev);
597 break;
536 } 598 }
537 } 599 }
538 return result; 600 return result;
539} 601}
540 602
541static void daqboard2000_adc_stop_dma_transfer(struct comedi_device *dev) 603static void db2k_adc_stop_dma_transfer(struct comedi_device *dev)
542{ 604{
543} 605}
544 606
545static void daqboard2000_adc_disarm(struct comedi_device *dev) 607static void db2k_adc_disarm(struct comedi_device *dev)
546{ 608{
547 /* Disable hardware triggers */ 609 /* Disable hardware triggers */
548 udelay(2); 610 udelay(2);
@@ -563,10 +625,10 @@ static void daqboard2000_adc_disarm(struct comedi_device *dev)
563 dev->mmio + DB2K_REG_ACQ_CONTROL); 625 dev->mmio + DB2K_REG_ACQ_CONTROL);
564 626
565 /* Stop the input dma (abort channel 1) */ 627 /* Stop the input dma (abort channel 1) */
566 daqboard2000_adc_stop_dma_transfer(dev); 628 db2k_adc_stop_dma_transfer(dev);
567} 629}
568 630
569static void daqboard2000_activate_reference_dacs(struct comedi_device *dev) 631static void db2k_activate_reference_dacs(struct comedi_device *dev)
570{ 632{
571 unsigned int val; 633 unsigned int val;
572 int timeout; 634 int timeout;
@@ -592,34 +654,33 @@ static void daqboard2000_activate_reference_dacs(struct comedi_device *dev)
592 } 654 }
593} 655}
594 656
595static void daqboard2000_initialize_ctrs(struct comedi_device *dev) 657static void db2k_initialize_ctrs(struct comedi_device *dev)
596{ 658{
597} 659}
598 660
599static void daqboard2000_initialize_tmrs(struct comedi_device *dev) 661static void db2k_initialize_tmrs(struct comedi_device *dev)
600{ 662{
601} 663}
602 664
603static void daqboard2000_dac_disarm(struct comedi_device *dev) 665static void db2k_dac_disarm(struct comedi_device *dev)
604{ 666{
605} 667}
606 668
607static void daqboard2000_initialize_adc(struct comedi_device *dev) 669static void db2k_initialize_adc(struct comedi_device *dev)
608{ 670{
609 daqboard2000_adc_disarm(dev); 671 db2k_adc_disarm(dev);
610 daqboard2000_activate_reference_dacs(dev); 672 db2k_activate_reference_dacs(dev);
611 daqboard2000_initialize_ctrs(dev); 673 db2k_initialize_ctrs(dev);
612 daqboard2000_initialize_tmrs(dev); 674 db2k_initialize_tmrs(dev);
613} 675}
614 676
615static void daqboard2000_initialize_dac(struct comedi_device *dev) 677static void db2k_initialize_dac(struct comedi_device *dev)
616{ 678{
617 daqboard2000_dac_disarm(dev); 679 db2k_dac_disarm(dev);
618} 680}
619 681
620static int daqboard2000_8255_cb(struct comedi_device *dev, 682static int db2k_8255_cb(struct comedi_device *dev, int dir, int port, int data,
621 int dir, int port, int data, 683 unsigned long iobase)
622 unsigned long iobase)
623{ 684{
624 if (dir) { 685 if (dir) {
625 writew(data, dev->mmio + iobase + port * 2); 686 writew(data, dev->mmio + iobase + port * 2);
@@ -628,34 +689,18 @@ static int daqboard2000_8255_cb(struct comedi_device *dev,
628 return readw(dev->mmio + iobase + port * 2); 689 return readw(dev->mmio + iobase + port * 2);
629} 690}
630 691
631static const void *daqboard2000_find_boardinfo(struct comedi_device *dev, 692static int db2k_auto_attach(struct comedi_device *dev, unsigned long context)
632 struct pci_dev *pcidev)
633{
634 const struct daq200_boardtype *board;
635 int i;
636
637 if (pcidev->subsystem_vendor != PCI_VENDOR_ID_IOTECH)
638 return NULL;
639
640 for (i = 0; i < ARRAY_SIZE(boardtypes); i++) {
641 board = &boardtypes[i];
642 if (pcidev->subsystem_device == board->id)
643 return board;
644 }
645 return NULL;
646}
647
648static int daqboard2000_auto_attach(struct comedi_device *dev,
649 unsigned long context_unused)
650{ 693{
651 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 694 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
652 const struct daq200_boardtype *board; 695 const struct db2k_boardtype *board;
653 struct daqboard2000_private *devpriv; 696 struct db2k_private *devpriv;
654 struct comedi_subdevice *s; 697 struct comedi_subdevice *s;
655 int result; 698 int result;
656 699
657 board = daqboard2000_find_boardinfo(dev, pcidev); 700 if (context >= ARRAY_SIZE(db2k_boardtypes))
658 if (!board) 701 return -ENODEV;
702 board = &db2k_boardtypes[context];
703 if (!board->name)
659 return -ENODEV; 704 return -ENODEV;
660 dev->board_ptr = board; 705 dev->board_ptr = board;
661 dev->board_name = board->name; 706 dev->board_name = board->name;
@@ -677,16 +722,13 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
677 if (result) 722 if (result)
678 return result; 723 return result;
679 724
680 readl(devpriv->plx + 0x6c);
681
682 result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, 725 result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev,
683 DAQBOARD2000_FIRMWARE, 726 DB2K_FIRMWARE, db2k_load_firmware, 0);
684 daqboard2000_load_firmware, 0);
685 if (result < 0) 727 if (result < 0)
686 return result; 728 return result;
687 729
688 daqboard2000_initialize_adc(dev); 730 db2k_initialize_adc(dev);
689 daqboard2000_initialize_dac(dev); 731 db2k_initialize_dac(dev);
690 732
691 s = &dev->subdevices[0]; 733 s = &dev->subdevices[0];
692 /* ai subdevice */ 734 /* ai subdevice */
@@ -694,16 +736,16 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
694 s->subdev_flags = SDF_READABLE | SDF_GROUND; 736 s->subdev_flags = SDF_READABLE | SDF_GROUND;
695 s->n_chan = 24; 737 s->n_chan = 24;
696 s->maxdata = 0xffff; 738 s->maxdata = 0xffff;
697 s->insn_read = daqboard2000_ai_insn_read; 739 s->insn_read = db2k_ai_insn_read;
698 s->range_table = &range_daqboard2000_ai; 740 s->range_table = &db2k_ai_range;
699 741
700 s = &dev->subdevices[1]; 742 s = &dev->subdevices[1];
701 /* ao subdevice */ 743 /* ao subdevice */
702 s->type = COMEDI_SUBD_AO; 744 s->type = COMEDI_SUBD_AO;
703 s->subdev_flags = SDF_WRITABLE; 745 s->subdev_flags = SDF_WRITABLE;
704 s->n_chan = 2; 746 s->n_chan = board->has_2_ao ? 2 : 4;
705 s->maxdata = 0xffff; 747 s->maxdata = 0xffff;
706 s->insn_write = daqboard2000_ao_insn_write; 748 s->insn_write = db2k_ao_insn_write;
707 s->range_table = &range_bipolar10; 749 s->range_table = &range_bipolar10;
708 750
709 result = comedi_alloc_subdev_readback(s); 751 result = comedi_alloc_subdev_readback(s);
@@ -711,48 +753,49 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
711 return result; 753 return result;
712 754
713 s = &dev->subdevices[2]; 755 s = &dev->subdevices[2];
714 return subdev_8255_init(dev, s, daqboard2000_8255_cb, 756 return subdev_8255_init(dev, s, db2k_8255_cb,
715 DB2K_REG_DIO_P2_EXP_IO_8_BIT); 757 DB2K_REG_DIO_P2_EXP_IO_8_BIT);
716} 758}
717 759
718static void daqboard2000_detach(struct comedi_device *dev) 760static void db2k_detach(struct comedi_device *dev)
719{ 761{
720 struct daqboard2000_private *devpriv = dev->private; 762 struct db2k_private *devpriv = dev->private;
721 763
722 if (devpriv && devpriv->plx) 764 if (devpriv && devpriv->plx)
723 iounmap(devpriv->plx); 765 iounmap(devpriv->plx);
724 comedi_pci_detach(dev); 766 comedi_pci_detach(dev);
725} 767}
726 768
727static struct comedi_driver daqboard2000_driver = { 769static struct comedi_driver db2k_driver = {
728 .driver_name = "daqboard2000", 770 .driver_name = "daqboard2000",
729 .module = THIS_MODULE, 771 .module = THIS_MODULE,
730 .auto_attach = daqboard2000_auto_attach, 772 .auto_attach = db2k_auto_attach,
731 .detach = daqboard2000_detach, 773 .detach = db2k_detach,
732}; 774};
733 775
734static int daqboard2000_pci_probe(struct pci_dev *dev, 776static int db2k_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
735 const struct pci_device_id *id)
736{ 777{
737 return comedi_pci_auto_config(dev, &daqboard2000_driver, 778 return comedi_pci_auto_config(dev, &db2k_driver, id->driver_data);
738 id->driver_data);
739} 779}
740 780
741static const struct pci_device_id daqboard2000_pci_table[] = { 781static const struct pci_device_id db2k_pci_table[] = {
742 { PCI_DEVICE(PCI_VENDOR_ID_IOTECH, 0x0409) }, 782 { PCI_DEVICE_SUB(PCI_VENDOR_ID_IOTECH, 0x0409, PCI_VENDOR_ID_IOTECH,
783 0x0002), .driver_data = BOARD_DAQBOARD2000, },
784 { PCI_DEVICE_SUB(PCI_VENDOR_ID_IOTECH, 0x0409, PCI_VENDOR_ID_IOTECH,
785 0x0004), .driver_data = BOARD_DAQBOARD2001, },
743 { 0 } 786 { 0 }
744}; 787};
745MODULE_DEVICE_TABLE(pci, daqboard2000_pci_table); 788MODULE_DEVICE_TABLE(pci, db2k_pci_table);
746 789
747static struct pci_driver daqboard2000_pci_driver = { 790static struct pci_driver db2k_pci_driver = {
748 .name = "daqboard2000", 791 .name = "daqboard2000",
749 .id_table = daqboard2000_pci_table, 792 .id_table = db2k_pci_table,
750 .probe = daqboard2000_pci_probe, 793 .probe = db2k_pci_probe,
751 .remove = comedi_pci_auto_unconfig, 794 .remove = comedi_pci_auto_unconfig,
752}; 795};
753module_comedi_pci_driver(daqboard2000_driver, daqboard2000_pci_driver); 796module_comedi_pci_driver(db2k_driver, db2k_pci_driver);
754 797
755MODULE_AUTHOR("Comedi http://www.comedi.org"); 798MODULE_AUTHOR("Comedi http://www.comedi.org");
756MODULE_DESCRIPTION("Comedi low-level driver"); 799MODULE_DESCRIPTION("Comedi low-level driver");
757MODULE_LICENSE("GPL"); 800MODULE_LICENSE("GPL");
758MODULE_FIRMWARE(DAQBOARD2000_FIRMWARE); 801MODULE_FIRMWARE(DB2K_FIRMWARE);
diff --git a/drivers/staging/comedi/drivers/dmm32at.c b/drivers/staging/comedi/drivers/dmm32at.c
index b8606ded0623..771cceb71069 100644
--- a/drivers/staging/comedi/drivers/dmm32at.c
+++ b/drivers/staging/comedi/drivers/dmm32at.c
@@ -510,7 +510,7 @@ static int dmm32at_reset(struct comedi_device *dev)
510 outb(DMM32AT_CTRL_RESETA, dev->iobase + DMM32AT_CTRL_REG); 510 outb(DMM32AT_CTRL_RESETA, dev->iobase + DMM32AT_CTRL_REG);
511 511
512 /* allow a millisecond to reset */ 512 /* allow a millisecond to reset */
513 udelay(1000); 513 usleep_range(1000, 3000);
514 514
515 /* zero scan and fifo control */ 515 /* zero scan and fifo control */
516 outb(0x0, dev->iobase + DMM32AT_FIFO_CTRL_REG); 516 outb(0x0, dev->iobase + DMM32AT_FIFO_CTRL_REG);
@@ -526,7 +526,7 @@ static int dmm32at_reset(struct comedi_device *dev)
526 outb(DMM32AT_RANGE_U10, dev->iobase + DMM32AT_AI_CFG_REG); 526 outb(DMM32AT_RANGE_U10, dev->iobase + DMM32AT_AI_CFG_REG);
527 527
528 /* should take 10 us to settle, here's a hundred */ 528 /* should take 10 us to settle, here's a hundred */
529 udelay(100); 529 usleep_range(100, 200);
530 530
531 /* read back the values */ 531 /* read back the values */
532 ailo = inb(dev->iobase + DMM32AT_AI_LO_CHAN_REG); 532 ailo = inb(dev->iobase + DMM32AT_AI_LO_CHAN_REG);
diff --git a/drivers/staging/comedi/drivers/dt2801.c b/drivers/staging/comedi/drivers/dt2801.c
index c2ce1eb87385..30805797a957 100644
--- a/drivers/staging/comedi/drivers/dt2801.c
+++ b/drivers/staging/comedi/drivers/dt2801.c
@@ -343,7 +343,7 @@ static int dt2801_reset(struct comedi_device *dev)
343 outb_p(DT_C_STOP, dev->iobase + DT2801_CMD); 343 outb_p(DT_C_STOP, dev->iobase + DT2801_CMD);
344 344
345 /* dt2801_wait_for_ready(dev); */ 345 /* dt2801_wait_for_ready(dev); */
346 udelay(100); 346 usleep_range(100, 200);
347 timeout = 10000; 347 timeout = 10000;
348 do { 348 do {
349 stat = inb_p(dev->iobase + DT2801_STATUS); 349 stat = inb_p(dev->iobase + DT2801_STATUS);
@@ -358,7 +358,7 @@ static int dt2801_reset(struct comedi_device *dev)
358 outb_p(DT_C_RESET, dev->iobase + DT2801_CMD); 358 outb_p(DT_C_RESET, dev->iobase + DT2801_CMD);
359 /* dt2801_writecmd(dev,DT_C_RESET); */ 359 /* dt2801_writecmd(dev,DT_C_RESET); */
360 360
361 udelay(100); 361 usleep_range(100, 200);
362 timeout = 10000; 362 timeout = 10000;
363 do { 363 do {
364 stat = inb_p(dev->iobase + DT2801_STATUS); 364 stat = inb_p(dev->iobase + DT2801_STATUS);
diff --git a/drivers/staging/comedi/drivers/dt2814.c b/drivers/staging/comedi/drivers/dt2814.c
index 2f903bedcefa..09984a66dba3 100644
--- a/drivers/staging/comedi/drivers/dt2814.c
+++ b/drivers/staging/comedi/drivers/dt2814.c
@@ -245,7 +245,7 @@ static int dt2814_attach(struct comedi_device *dev, struct comedi_devconfig *it)
245 return ret; 245 return ret;
246 246
247 outb(0, dev->iobase + DT2814_CSR); 247 outb(0, dev->iobase + DT2814_CSR);
248 udelay(100); 248 usleep_range(100, 200);
249 if (inb(dev->iobase + DT2814_CSR) & DT2814_ERR) { 249 if (inb(dev->iobase + DT2814_CSR) & DT2814_ERR) {
250 dev_err(dev->class_dev, "reset error (fatal)\n"); 250 dev_err(dev->class_dev, "reset error (fatal)\n");
251 return -EIO; 251 return -EIO;
diff --git a/drivers/staging/comedi/drivers/dt2815.c b/drivers/staging/comedi/drivers/dt2815.c
index 0be77cc40a79..ce5571971194 100644
--- a/drivers/staging/comedi/drivers/dt2815.c
+++ b/drivers/staging/comedi/drivers/dt2815.c
@@ -188,7 +188,7 @@ static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
188 /* This is incredibly slow (approx 20 ms) */ 188 /* This is incredibly slow (approx 20 ms) */
189 unsigned int status; 189 unsigned int status;
190 190
191 udelay(1000); 191 usleep_range(1000, 3000);
192 status = inb(dev->iobase + DT2815_STATUS); 192 status = inb(dev->iobase + DT2815_STATUS);
193 if (status == 4) { 193 if (status == 4) {
194 unsigned int program; 194 unsigned int program;
diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index c9eb26fab44e..bab7ac9e6237 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -89,7 +89,7 @@ static int dyna_pci10xx_insn_read_ai(struct comedi_device *dev,
89 /* trigger conversion */ 89 /* trigger conversion */
90 smp_mb(); 90 smp_mb();
91 outw_p(0x0000 + range + chan, dev->iobase + 2); 91 outw_p(0x0000 + range + chan, dev->iobase + 2);
92 udelay(10); 92 usleep_range(10, 20);
93 93
94 ret = comedi_timeout(dev, s, insn, dyna_pci10xx_ai_eoc, 0); 94 ret = comedi_timeout(dev, s, insn, dyna_pci10xx_ai_eoc, 0);
95 if (ret) 95 if (ret)
@@ -125,7 +125,7 @@ static int dyna_pci10xx_insn_write_ao(struct comedi_device *dev,
125 smp_mb(); 125 smp_mb();
126 /* trigger conversion and write data */ 126 /* trigger conversion and write data */
127 outw_p(data[n], dev->iobase); 127 outw_p(data[n], dev->iobase);
128 udelay(10); 128 usleep_range(10, 20);
129 } 129 }
130 mutex_unlock(&devpriv->mutex); 130 mutex_unlock(&devpriv->mutex);
131 return n; 131 return n;
@@ -143,7 +143,7 @@ static int dyna_pci10xx_di_insn_bits(struct comedi_device *dev,
143 mutex_lock(&devpriv->mutex); 143 mutex_lock(&devpriv->mutex);
144 smp_mb(); 144 smp_mb();
145 d = inw_p(devpriv->BADR3); 145 d = inw_p(devpriv->BADR3);
146 udelay(10); 146 usleep_range(10, 100);
147 147
148 /* on return the data[0] contains output and data[1] contains input */ 148 /* on return the data[0] contains output and data[1] contains input */
149 data[1] = d; 149 data[1] = d;
@@ -163,7 +163,7 @@ static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
163 if (comedi_dio_update_state(s, data)) { 163 if (comedi_dio_update_state(s, data)) {
164 smp_mb(); 164 smp_mb();
165 outw_p(s->state, devpriv->BADR3); 165 outw_p(s->state, devpriv->BADR3);
166 udelay(10); 166 usleep_range(10, 100);
167 } 167 }
168 168
169 data[1] = s->state; 169 data[1] = s->state;
diff --git a/drivers/staging/comedi/drivers/mite.h b/drivers/staging/comedi/drivers/mite.h
index b6349aed97d0..02a627d3969d 100644
--- a/drivers/staging/comedi/drivers/mite.h
+++ b/drivers/staging/comedi/drivers/mite.h
@@ -60,35 +60,36 @@ struct mite {
60 spinlock_t lock; 60 spinlock_t lock;
61}; 61};
62 62
63u32 mite_bytes_in_transit(struct mite_channel *); 63u32 mite_bytes_in_transit(struct mite_channel *mite_chan);
64 64
65void mite_sync_dma(struct mite_channel *, struct comedi_subdevice *); 65void mite_sync_dma(struct mite_channel *mite_chan, struct comedi_subdevice *s);
66void mite_ack_linkc(struct mite_channel *, struct comedi_subdevice *s, 66void mite_ack_linkc(struct mite_channel *mite_chan, struct comedi_subdevice *s,
67 bool sync); 67 bool sync);
68int mite_done(struct mite_channel *); 68int mite_done(struct mite_channel *mite_chan);
69 69
70void mite_dma_arm(struct mite_channel *); 70void mite_dma_arm(struct mite_channel *mite_chan);
71void mite_dma_disarm(struct mite_channel *); 71void mite_dma_disarm(struct mite_channel *mite_chan);
72 72
73void mite_prep_dma(struct mite_channel *, 73void mite_prep_dma(struct mite_channel *mite_chan,
74 unsigned int num_device_bits, unsigned int num_memory_bits); 74 unsigned int num_device_bits, unsigned int num_memory_bits);
75 75
76struct mite_channel *mite_request_channel_in_range(struct mite *, 76struct mite_channel *mite_request_channel_in_range(struct mite *mite,
77 struct mite_ring *, 77 struct mite_ring *ring,
78 unsigned int min_channel, 78 unsigned int min_channel,
79 unsigned int max_channel); 79 unsigned int max_channel);
80struct mite_channel *mite_request_channel(struct mite *, struct mite_ring *); 80struct mite_channel *mite_request_channel(struct mite *mite,
81void mite_release_channel(struct mite_channel *); 81 struct mite_ring *ring);
82void mite_release_channel(struct mite_channel *mite_chan);
82 83
83int mite_init_ring_descriptors(struct mite_ring *, struct comedi_subdevice *, 84int mite_init_ring_descriptors(struct mite_ring *ring,
84 unsigned int nbytes); 85 struct comedi_subdevice *s, unsigned int nbytes);
85int mite_buf_change(struct mite_ring *, struct comedi_subdevice *); 86int mite_buf_change(struct mite_ring *ring, struct comedi_subdevice *s);
86 87
87struct mite_ring *mite_alloc_ring(struct mite *); 88struct mite_ring *mite_alloc_ring(struct mite *mite);
88void mite_free_ring(struct mite_ring *); 89void mite_free_ring(struct mite_ring *ring);
89 90
90struct mite *mite_attach(struct comedi_device *, bool use_win1); 91struct mite *mite_attach(struct comedi_device *dev, bool use_win1);
91void mite_detach(struct mite *); 92void mite_detach(struct mite *mite);
92 93
93/* 94/*
94 * Mite registers (used outside of the mite driver) 95 * Mite registers (used outside of the mite driver)
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 0dcb826a9f1f..6aa755ad3953 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -16,13 +16,13 @@
16 * Driver: ni_660x 16 * Driver: ni_660x
17 * Description: National Instruments 660x counter/timer boards 17 * Description: National Instruments 660x counter/timer boards
18 * Devices: [National Instruments] PCI-6601 (ni_660x), PCI-6602, PXI-6602, 18 * Devices: [National Instruments] PCI-6601 (ni_660x), PCI-6602, PXI-6602,
19 * PXI-6608, PXI-6624 19 * PXI-6608, PCI-6624, PXI-6624
20 * Author: J.P. Mellor <jpmellor@rose-hulman.edu>, 20 * Author: J.P. Mellor <jpmellor@rose-hulman.edu>,
21 * Herman.Bruyninckx@mech.kuleuven.ac.be, 21 * Herman.Bruyninckx@mech.kuleuven.ac.be,
22 * Wim.Meeussen@mech.kuleuven.ac.be, 22 * Wim.Meeussen@mech.kuleuven.ac.be,
23 * Klaas.Gadeyne@mech.kuleuven.ac.be, 23 * Klaas.Gadeyne@mech.kuleuven.ac.be,
24 * Frank Mori Hess <fmhess@users.sourceforge.net> 24 * Frank Mori Hess <fmhess@users.sourceforge.net>
25 * Updated: Fri, 15 Mar 2013 10:47:56 +0000 25 * Updated: Mon, 16 Jan 2017 14:00:43 +0000
26 * Status: experimental 26 * Status: experimental
27 * 27 *
28 * Encoders work. PulseGeneration (both single pulse and pulse train) 28 * Encoders work. PulseGeneration (both single pulse and pulse train)
@@ -211,6 +211,7 @@ enum ni_660x_boardid {
211 BOARD_PCI6602, 211 BOARD_PCI6602,
212 BOARD_PXI6602, 212 BOARD_PXI6602,
213 BOARD_PXI6608, 213 BOARD_PXI6608,
214 BOARD_PCI6624,
214 BOARD_PXI6624 215 BOARD_PXI6624
215}; 216};
216 217
@@ -236,6 +237,10 @@ static const struct ni_660x_board ni_660x_boards[] = {
236 .name = "PXI-6608", 237 .name = "PXI-6608",
237 .n_chips = 2, 238 .n_chips = 2,
238 }, 239 },
240 [BOARD_PCI6624] = {
241 .name = "PCI-6624",
242 .n_chips = 2,
243 },
239 [BOARD_PXI6624] = { 244 [BOARD_PXI6624] = {
240 .name = "PXI-6624", 245 .name = "PXI-6624",
241 .n_chips = 2, 246 .n_chips = 2,
@@ -920,6 +925,7 @@ static const struct pci_device_id ni_660x_pci_table[] = {
920 { PCI_VDEVICE(NI, 0x1360), BOARD_PXI6602 }, 925 { PCI_VDEVICE(NI, 0x1360), BOARD_PXI6602 },
921 { PCI_VDEVICE(NI, 0x2c60), BOARD_PCI6601 }, 926 { PCI_VDEVICE(NI, 0x2c60), BOARD_PCI6601 },
922 { PCI_VDEVICE(NI, 0x2cc0), BOARD_PXI6608 }, 927 { PCI_VDEVICE(NI, 0x2cc0), BOARD_PXI6608 },
928 { PCI_VDEVICE(NI, 0x1e30), BOARD_PCI6624 },
923 { PCI_VDEVICE(NI, 0x1e40), BOARD_PXI6624 }, 929 { PCI_VDEVICE(NI, 0x1e40), BOARD_PXI6624 },
924 { 0 } 930 { 0 }
925}; 931};
diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c
index 74911dbb2561..1d3ff60efcb8 100644
--- a/drivers/staging/comedi/drivers/ni_670x.c
+++ b/drivers/staging/comedi/drivers/ni_670x.c
@@ -141,7 +141,7 @@ static int ni_670x_dio_insn_config(struct comedi_device *dev,
141 141
142/* ripped from mite.h and mite_setup2() to avoid mite dependency */ 142/* ripped from mite.h and mite_setup2() to avoid mite dependency */
143#define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */ 143#define MITE_IODWBSR 0xc0 /* IO Device Window Base Size Register */
144#define WENAB (1 << 7) /* window enable */ 144#define WENAB BIT(7) /* window enable */
145 145
146static int ni_670x_mite_init(struct pci_dev *pcidev) 146static int ni_670x_mite_init(struct pci_dev *pcidev)
147{ 147{
diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c b/drivers/staging/comedi/drivers/ni_at_a2150.c
index 5a4dcc6e61d8..c69cd676f357 100644
--- a/drivers/staging/comedi/drivers/ni_at_a2150.c
+++ b/drivers/staging/comedi/drivers/ni_at_a2150.c
@@ -757,7 +757,7 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
757 for (i = 0; i < timeout; i++) { 757 for (i = 0; i < timeout; i++) {
758 if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0) 758 if ((DCAL_BIT & inw(dev->iobase + STATUS_REG)) == 0)
759 break; 759 break;
760 udelay(1000); 760 usleep_range(1000, 3000);
761 } 761 }
762 if (i == timeout) { 762 if (i == timeout) {
763 dev_err(dev->class_dev, 763 dev_err(dev->class_dev,
diff --git a/drivers/staging/comedi/drivers/ni_at_ao.c b/drivers/staging/comedi/drivers/ni_at_ao.c
index f27aa0e82234..158fa29374fc 100644
--- a/drivers/staging/comedi/drivers/ni_at_ao.c
+++ b/drivers/staging/comedi/drivers/ni_at_ao.c
@@ -49,43 +49,43 @@
49#define ATAO_CFG2_REG 0x02 49#define ATAO_CFG2_REG 0x02
50#define ATAO_CFG2_CALLD_NOP (0 << 14) 50#define ATAO_CFG2_CALLD_NOP (0 << 14)
51#define ATAO_CFG2_CALLD(x) ((((x) >> 3) + 1) << 14) 51#define ATAO_CFG2_CALLD(x) ((((x) >> 3) + 1) << 14)
52#define ATAO_CFG2_FFRTEN (1 << 13) 52#define ATAO_CFG2_FFRTEN BIT(13)
53#define ATAO_CFG2_DACS(x) (1 << (((x) / 2) + 8)) 53#define ATAO_CFG2_DACS(x) (1 << (((x) / 2) + 8))
54#define ATAO_CFG2_LDAC(x) (1 << (((x) / 2) + 3)) 54#define ATAO_CFG2_LDAC(x) (1 << (((x) / 2) + 3))
55#define ATAO_CFG2_PROMEN (1 << 2) 55#define ATAO_CFG2_PROMEN BIT(2)
56#define ATAO_CFG2_SCLK (1 << 1) 56#define ATAO_CFG2_SCLK BIT(1)
57#define ATAO_CFG2_SDATA (1 << 0) 57#define ATAO_CFG2_SDATA BIT(0)
58#define ATAO_CFG3_REG 0x04 58#define ATAO_CFG3_REG 0x04
59#define ATAO_CFG3_DMAMODE (1 << 6) 59#define ATAO_CFG3_DMAMODE BIT(6)
60#define ATAO_CFG3_CLKOUT (1 << 5) 60#define ATAO_CFG3_CLKOUT BIT(5)
61#define ATAO_CFG3_RCLKEN (1 << 4) 61#define ATAO_CFG3_RCLKEN BIT(4)
62#define ATAO_CFG3_DOUTEN2 (1 << 3) 62#define ATAO_CFG3_DOUTEN2 BIT(3)
63#define ATAO_CFG3_DOUTEN1 (1 << 2) 63#define ATAO_CFG3_DOUTEN1 BIT(2)
64#define ATAO_CFG3_EN2_5V (1 << 1) 64#define ATAO_CFG3_EN2_5V BIT(1)
65#define ATAO_CFG3_SCANEN (1 << 0) 65#define ATAO_CFG3_SCANEN BIT(0)
66#define ATAO_82C53_BASE 0x06 66#define ATAO_82C53_BASE 0x06
67#define ATAO_CFG1_REG 0x0a 67#define ATAO_CFG1_REG 0x0a
68#define ATAO_CFG1_EXTINT2EN (1 << 15) 68#define ATAO_CFG1_EXTINT2EN BIT(15)
69#define ATAO_CFG1_EXTINT1EN (1 << 14) 69#define ATAO_CFG1_EXTINT1EN BIT(14)
70#define ATAO_CFG1_CNTINT2EN (1 << 13) 70#define ATAO_CFG1_CNTINT2EN BIT(13)
71#define ATAO_CFG1_CNTINT1EN (1 << 12) 71#define ATAO_CFG1_CNTINT1EN BIT(12)
72#define ATAO_CFG1_TCINTEN (1 << 11) 72#define ATAO_CFG1_TCINTEN BIT(11)
73#define ATAO_CFG1_CNT1SRC (1 << 10) 73#define ATAO_CFG1_CNT1SRC BIT(10)
74#define ATAO_CFG1_CNT2SRC (1 << 9) 74#define ATAO_CFG1_CNT2SRC BIT(9)
75#define ATAO_CFG1_FIFOEN (1 << 8) 75#define ATAO_CFG1_FIFOEN BIT(8)
76#define ATAO_CFG1_GRP2WR (1 << 7) 76#define ATAO_CFG1_GRP2WR BIT(7)
77#define ATAO_CFG1_EXTUPDEN (1 << 6) 77#define ATAO_CFG1_EXTUPDEN BIT(6)
78#define ATAO_CFG1_DMARQ (1 << 5) 78#define ATAO_CFG1_DMARQ BIT(5)
79#define ATAO_CFG1_DMAEN (1 << 4) 79#define ATAO_CFG1_DMAEN BIT(4)
80#define ATAO_CFG1_CH(x) (((x) & 0xf) << 0) 80#define ATAO_CFG1_CH(x) (((x) & 0xf) << 0)
81#define ATAO_STATUS_REG 0x0a 81#define ATAO_STATUS_REG 0x0a
82#define ATAO_STATUS_FH (1 << 6) 82#define ATAO_STATUS_FH BIT(6)
83#define ATAO_STATUS_FE (1 << 5) 83#define ATAO_STATUS_FE BIT(5)
84#define ATAO_STATUS_FF (1 << 4) 84#define ATAO_STATUS_FF BIT(4)
85#define ATAO_STATUS_INT2 (1 << 3) 85#define ATAO_STATUS_INT2 BIT(3)
86#define ATAO_STATUS_INT1 (1 << 2) 86#define ATAO_STATUS_INT1 BIT(2)
87#define ATAO_STATUS_TCINT (1 << 1) 87#define ATAO_STATUS_TCINT BIT(1)
88#define ATAO_STATUS_PROMOUT (1 << 0) 88#define ATAO_STATUS_PROMOUT BIT(0)
89#define ATAO_FIFO_WRITE_REG 0x0c 89#define ATAO_FIFO_WRITE_REG 0x0c
90#define ATAO_FIFO_CLEAR_REG 0x0c 90#define ATAO_FIFO_CLEAR_REG 0x0c
91#define ATAO_AO_REG(x) (0x0c + ((x) * 2)) 91#define ATAO_AO_REG(x) (0x0c + ((x) * 2))
@@ -95,7 +95,7 @@
95#define ATAO_2_INT1CLR_REG 0x02 95#define ATAO_2_INT1CLR_REG 0x02
96#define ATAO_2_INT2CLR_REG 0x04 96#define ATAO_2_INT2CLR_REG 0x04
97#define ATAO_2_RTSISHFT_REG 0x06 97#define ATAO_2_RTSISHFT_REG 0x06
98#define ATAO_2_RTSISHFT_RSI (1 << 0) 98#define ATAO_2_RTSISHFT_RSI BIT(0)
99#define ATAO_2_RTSISTRB_REG 0x07 99#define ATAO_2_RTSISTRB_REG 0x07
100 100
101struct atao_board { 101struct atao_board {
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h
index be8d5cd3f7f0..c2edadc7b3c6 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -52,8 +52,8 @@ struct labpc_private {
52 * function pointers so we can use inb/outb or readb/writeb as 52 * function pointers so we can use inb/outb or readb/writeb as
53 * appropriate 53 * appropriate
54 */ 54 */
55 unsigned int (*read_byte)(struct comedi_device *, unsigned long reg); 55 unsigned int (*read_byte)(struct comedi_device *dev, unsigned long reg);
56 void (*write_byte)(struct comedi_device *, 56 void (*write_byte)(struct comedi_device *dev,
57 unsigned int byte, unsigned long reg); 57 unsigned int byte, unsigned long reg);
58}; 58};
59 59
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index daeb4ad7a75f..b27345abebe1 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -65,7 +65,7 @@
65#define WindowAddressStatus_mask 0x7c 65#define WindowAddressStatus_mask 0x7c
66 66
67#define Master_DMA_And_Interrupt_Control 5 /* W */ 67#define Master_DMA_And_Interrupt_Control 5 /* W */
68#define InterruptLine(x) ((x)&3) 68#define InterruptLine(x) ((x) & 3)
69#define OpenInt BIT(2) 69#define OpenInt BIT(2)
70#define Group_Status 5 /* R */ 70#define Group_Status 5 /* R */
71#define DataLeft BIT(0) 71#define DataLeft BIT(0)
@@ -100,38 +100,38 @@
100#define Chip_ID_I 25 100#define Chip_ID_I 25
101#define Chip_ID_O 26 101#define Chip_ID_O 26
102#define Chip_Version 27 102#define Chip_Version 27
103#define Port_IO(x) (28+(x)) 103#define Port_IO(x) (28 + (x))
104#define Port_Pin_Directions(x) (32+(x)) 104#define Port_Pin_Directions(x) (32 + (x))
105#define Port_Pin_Mask(x) (36+(x)) 105#define Port_Pin_Mask(x) (36 + (x))
106#define Port_Pin_Polarities(x) (40+(x)) 106#define Port_Pin_Polarities(x) (40 + (x))
107 107
108#define Master_Clock_Routing 45 108#define Master_Clock_Routing 45
109#define RTSIClocking(x) (((x)&3)<<4) 109#define RTSIClocking(x) (((x) & 3) << 4)
110 110
111#define Group_1_Second_Clear 46 /* W */ 111#define Group_1_Second_Clear 46 /* W */
112#define Group_2_Second_Clear 47 /* W */ 112#define Group_2_Second_Clear 47 /* W */
113#define ClearExpired BIT(0) 113#define ClearExpired BIT(0)
114 114
115#define Port_Pattern(x) (48+(x)) 115#define Port_Pattern(x) (48 + (x))
116 116
117#define Data_Path 64 117#define Data_Path 64
118#define FIFOEnableA BIT(0) 118#define FIFOEnableA BIT(0)
119#define FIFOEnableB BIT(1) 119#define FIFOEnableB BIT(1)
120#define FIFOEnableC BIT(2) 120#define FIFOEnableC BIT(2)
121#define FIFOEnableD BIT(3) 121#define FIFOEnableD BIT(3)
122#define Funneling(x) (((x)&3)<<4) 122#define Funneling(x) (((x) & 3) << 4)
123#define GroupDirection BIT(7) 123#define GroupDirection BIT(7)
124 124
125#define Protocol_Register_1 65 125#define Protocol_Register_1 65
126#define OpMode Protocol_Register_1 126#define OpMode Protocol_Register_1
127#define RunMode(x) ((x)&7) 127#define RunMode(x) ((x) & 7)
128#define Numbered BIT(3) 128#define Numbered BIT(3)
129 129
130#define Protocol_Register_2 66 130#define Protocol_Register_2 66
131#define ClockReg Protocol_Register_2 131#define ClockReg Protocol_Register_2
132#define ClockLine(x) (((x)&3)<<5) 132#define ClockLine(x) (((x) & 3) << 5)
133#define InvertStopTrig BIT(7) 133#define InvertStopTrig BIT(7)
134#define DataLatching(x) (((x)&3)<<5) 134#define DataLatching(x) (((x) & 3) << 5)
135 135
136#define Protocol_Register_3 67 136#define Protocol_Register_3 67
137#define Sequence Protocol_Register_3 137#define Sequence Protocol_Register_3
@@ -141,13 +141,13 @@
141 141
142#define Protocol_Register_4 70 142#define Protocol_Register_4 70
143#define ReqReg Protocol_Register_4 143#define ReqReg Protocol_Register_4
144#define ReqConditioning(x) (((x)&7)<<3) 144#define ReqConditioning(x) (((x) & 7) << 3)
145 145
146#define Protocol_Register_5 71 146#define Protocol_Register_5 71
147#define BlockMode Protocol_Register_5 147#define BlockMode Protocol_Register_5
148 148
149#define FIFO_Control 72 149#define FIFO_Control 72
150#define ReadyLevel(x) ((x)&7) 150#define ReadyLevel(x) ((x) & 7)
151 151
152#define Protocol_Register_6 73 152#define Protocol_Register_6 73
153#define LinePolarities Protocol_Register_6 153#define LinePolarities Protocol_Register_6
@@ -160,7 +160,7 @@
160 160
161#define Protocol_Register_7 74 161#define Protocol_Register_7 74
162#define AckSer Protocol_Register_7 162#define AckSer Protocol_Register_7
163#define AckLine(x) (((x)&3)<<2) 163#define AckLine(x) (((x) & 3) << 2)
164#define ExchangePins BIT(7) 164#define ExchangePins BIT(7)
165 165
166#define Interrupt_Control 75 166#define Interrupt_Control 75
@@ -180,15 +180,15 @@ static inline unsigned int secondary_DMAChannel_bits(unsigned int channel)
180} 180}
181 181
182#define Transfer_Size_Control 77 182#define Transfer_Size_Control 77
183#define TransferWidth(x) ((x)&3) 183#define TransferWidth(x) ((x) & 3)
184#define TransferLength(x) (((x)&3)<<3) 184#define TransferLength(x) (((x) & 3) << 3)
185#define RequireRLevel BIT(5) 185#define RequireRLevel BIT(5)
186 186
187#define Protocol_Register_15 79 187#define Protocol_Register_15 79
188#define DAQOptions Protocol_Register_15 188#define DAQOptions Protocol_Register_15
189#define StartSource(x) ((x)&0x3) 189#define StartSource(x) ((x) & 0x3)
190#define InvertStart BIT(2) 190#define InvertStart BIT(2)
191#define StopSource(x) (((x)&0x3)<<3) 191#define StopSource(x) (((x) & 0x3) << 3)
192#define ReqStart BIT(6) 192#define ReqStart BIT(6)
193#define PreStart BIT(7) 193#define PreStart BIT(7)
194 194
@@ -230,6 +230,7 @@ enum pci_6534_firmware_registers { /* 16 bit */
230 Firmware_Mask_Register = 0x10c, 230 Firmware_Mask_Register = 0x10c,
231 Firmware_Debug_Register = 0x110, 231 Firmware_Debug_Register = 0x110,
232}; 232};
233
233/* main fpga registers (32 bit)*/ 234/* main fpga registers (32 bit)*/
234enum pci_6534_fpga_registers { 235enum pci_6534_fpga_registers {
235 FPGA_Control1_Register = 0x200, 236 FPGA_Control1_Register = 0x200,
@@ -246,6 +247,7 @@ enum pci_6534_fpga_registers {
246 FPGA_ELC_Read_Register = 0x2b8, 247 FPGA_ELC_Read_Register = 0x2b8,
247 FPGA_ELC_Write_Register = 0x2bc, 248 FPGA_ELC_Write_Register = 0x2bc,
248}; 249};
250
249enum FPGA_Control_Bits { 251enum FPGA_Control_Bits {
250 FPGA_Enable_Bit = 0x8000, 252 FPGA_Enable_Bit = 0x8000,
251}; 253};
@@ -253,9 +255,9 @@ enum FPGA_Control_Bits {
253#define TIMER_BASE 50 /* nanoseconds */ 255#define TIMER_BASE 50 /* nanoseconds */
254 256
255#ifdef USE_DMA 257#ifdef USE_DMA
256#define IntEn (CountExpired|Waited|PrimaryTC|SecondaryTC) 258#define IntEn (CountExpired | Waited | PrimaryTC | SecondaryTC)
257#else 259#else
258#define IntEn (TransferReady|CountExpired|Waited|PrimaryTC|SecondaryTC) 260#define IntEn (TransferReady | CountExpired | Waited | PrimaryTC | SecondaryTC)
259#endif 261#endif
260 262
261enum nidio_boardid { 263enum nidio_boardid {
diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index f13a2f7360b3..3a96913c025e 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -25,17 +25,16 @@
25 * PCI-MIO-16XE-10, PXI-6030E, PCI-MIO-16E-1, PCI-MIO-16E-4, PCI-6014, 25 * PCI-MIO-16XE-10, PXI-6030E, PCI-MIO-16E-1, PCI-MIO-16E-4, PCI-6014,
26 * PCI-6040E, PXI-6040E, PCI-6030E, PCI-6031E, PCI-6032E, PCI-6033E, 26 * PCI-6040E, PXI-6040E, PCI-6030E, PCI-6031E, PCI-6032E, PCI-6033E,
27 * PCI-6071E, PCI-6023E, PCI-6024E, PCI-6025E, PXI-6025E, PCI-6034E, 27 * PCI-6071E, PCI-6023E, PCI-6024E, PCI-6025E, PXI-6025E, PCI-6034E,
28 * PCI-6035E, PCI-6052E, 28 * PCI-6035E, PCI-6052E, PCI-6110, PCI-6111, PCI-6220, PXI-6220,
29 * PCI-6110, PCI-6111, PCI-6220, PCI-6221, PCI-6224, PXI-6224, 29 * PCI-6221, PXI-6221, PCI-6224, PXI-6224, PCI-6225, PXI-6225,
30 * PCI-6225, PXI-6225, PCI-6229, PCI-6250, 30 * PCI-6229, PXI-6229, PCI-6250, PXI-6250, PCI-6251, PXI-6251,
31 * PCI-6251, PXI-6251, PCIe-6251, PXIe-6251, 31 * PCIe-6251, PXIe-6251, PCI-6254, PXI-6254, PCI-6259, PXI-6259,
32 * PCI-6254, PCI-6259, PCIe-6259, 32 * PCIe-6259, PXIe-6259, PCI-6280, PXI-6280, PCI-6281, PXI-6281,
33 * PCI-6280, PCI-6281, PXI-6281, PCI-6284, PCI-6289, 33 * PCI-6284, PXI-6284, PCI-6289, PXI-6289, PCI-6711, PXI-6711,
34 * PCI-6711, PXI-6711, PCI-6713, PXI-6713, 34 * PCI-6713, PXI-6713, PXI-6071E, PCI-6070E, PXI-6070E,
35 * PXI-6071E, PCI-6070E, PXI-6070E,
36 * PXI-6052E, PCI-6036E, PCI-6731, PCI-6733, PXI-6733, 35 * PXI-6052E, PCI-6036E, PCI-6731, PCI-6733, PXI-6733,
37 * PCI-6143, PXI-6143 36 * PCI-6143, PXI-6143
38 * Updated: Mon, 09 Jan 2012 14:52:48 +0000 37 * Updated: Mon, 16 Jan 2017 12:56:04 +0000
39 * 38 *
40 * These boards are almost identical to the AT-MIO E series, except that 39 * These boards are almost identical to the AT-MIO E series, except that
41 * they use the PCI bus instead of ISA (i.e., AT). See the notes for the 40 * they use the PCI bus instead of ISA (i.e., AT). See the notes for the
@@ -181,26 +180,36 @@ enum ni_pcimio_boardid {
181 BOARD_PXI6031E, 180 BOARD_PXI6031E,
182 BOARD_PCI6036E, 181 BOARD_PCI6036E,
183 BOARD_PCI6220, 182 BOARD_PCI6220,
183 BOARD_PXI6220,
184 BOARD_PCI6221, 184 BOARD_PCI6221,
185 BOARD_PCI6221_37PIN, 185 BOARD_PCI6221_37PIN,
186 BOARD_PXI6221,
186 BOARD_PCI6224, 187 BOARD_PCI6224,
187 BOARD_PXI6224, 188 BOARD_PXI6224,
188 BOARD_PCI6225, 189 BOARD_PCI6225,
189 BOARD_PXI6225, 190 BOARD_PXI6225,
190 BOARD_PCI6229, 191 BOARD_PCI6229,
192 BOARD_PXI6229,
191 BOARD_PCI6250, 193 BOARD_PCI6250,
194 BOARD_PXI6250,
192 BOARD_PCI6251, 195 BOARD_PCI6251,
193 BOARD_PXI6251, 196 BOARD_PXI6251,
194 BOARD_PCIE6251, 197 BOARD_PCIE6251,
195 BOARD_PXIE6251, 198 BOARD_PXIE6251,
196 BOARD_PCI6254, 199 BOARD_PCI6254,
200 BOARD_PXI6254,
197 BOARD_PCI6259, 201 BOARD_PCI6259,
202 BOARD_PXI6259,
198 BOARD_PCIE6259, 203 BOARD_PCIE6259,
204 BOARD_PXIE6259,
199 BOARD_PCI6280, 205 BOARD_PCI6280,
206 BOARD_PXI6280,
200 BOARD_PCI6281, 207 BOARD_PCI6281,
201 BOARD_PXI6281, 208 BOARD_PXI6281,
202 BOARD_PCI6284, 209 BOARD_PCI6284,
210 BOARD_PXI6284,
203 BOARD_PCI6289, 211 BOARD_PCI6289,
212 BOARD_PXI6289,
204 BOARD_PCI6143, 213 BOARD_PCI6143,
205 BOARD_PXI6143, 214 BOARD_PXI6143,
206}; 215};
@@ -684,6 +693,16 @@ static const struct ni_board_struct ni_boards[] = {
684 .reg_type = ni_reg_622x, 693 .reg_type = ni_reg_622x,
685 .caldac = { caldac_none }, 694 .caldac = { caldac_none },
686 }, 695 },
696 [BOARD_PXI6220] = {
697 .name = "pxi-6220",
698 .n_adchan = 16,
699 .ai_maxdata = 0xffff,
700 .ai_fifo_depth = 512, /* FIXME: guess */
701 .gainlkup = ai_gain_622x,
702 .ai_speed = 4000,
703 .reg_type = ni_reg_622x,
704 .caldac = { caldac_none },
705 },
687 [BOARD_PCI6221] = { 706 [BOARD_PCI6221] = {
688 .name = "pci-6221", 707 .name = "pci-6221",
689 .n_adchan = 16, 708 .n_adchan = 16,
@@ -714,6 +733,21 @@ static const struct ni_board_struct ni_boards[] = {
714 .ao_speed = 1200, 733 .ao_speed = 1200,
715 .caldac = { caldac_none }, 734 .caldac = { caldac_none },
716 }, 735 },
736 [BOARD_PXI6221] = {
737 .name = "pxi-6221",
738 .n_adchan = 16,
739 .ai_maxdata = 0xffff,
740 .ai_fifo_depth = 4095,
741 .gainlkup = ai_gain_622x,
742 .ai_speed = 4000,
743 .n_aochan = 2,
744 .ao_maxdata = 0xffff,
745 .ao_fifo_depth = 8191,
746 .ao_range_table = &range_bipolar10,
747 .reg_type = ni_reg_622x,
748 .ao_speed = 1200,
749 .caldac = { caldac_none },
750 },
717 [BOARD_PCI6224] = { 751 [BOARD_PCI6224] = {
718 .name = "pci-6224", 752 .name = "pci-6224",
719 .n_adchan = 32, 753 .n_adchan = 32,
@@ -784,6 +818,22 @@ static const struct ni_board_struct ni_boards[] = {
784 .has_32dio_chan = 1, 818 .has_32dio_chan = 1,
785 .caldac = { caldac_none }, 819 .caldac = { caldac_none },
786 }, 820 },
821 [BOARD_PXI6229] = {
822 .name = "pxi-6229",
823 .n_adchan = 32,
824 .ai_maxdata = 0xffff,
825 .ai_fifo_depth = 4095,
826 .gainlkup = ai_gain_622x,
827 .ai_speed = 4000,
828 .n_aochan = 4,
829 .ao_maxdata = 0xffff,
830 .ao_fifo_depth = 8191,
831 .ao_range_table = &range_bipolar10,
832 .reg_type = ni_reg_622x,
833 .ao_speed = 1200,
834 .has_32dio_chan = 1,
835 .caldac = { caldac_none },
836 },
787 [BOARD_PCI6250] = { 837 [BOARD_PCI6250] = {
788 .name = "pci-6250", 838 .name = "pci-6250",
789 .n_adchan = 16, 839 .n_adchan = 16,
@@ -794,6 +844,16 @@ static const struct ni_board_struct ni_boards[] = {
794 .reg_type = ni_reg_625x, 844 .reg_type = ni_reg_625x,
795 .caldac = { caldac_none }, 845 .caldac = { caldac_none },
796 }, 846 },
847 [BOARD_PXI6250] = {
848 .name = "pxi-6250",
849 .n_adchan = 16,
850 .ai_maxdata = 0xffff,
851 .ai_fifo_depth = 4095,
852 .gainlkup = ai_gain_628x,
853 .ai_speed = 800,
854 .reg_type = ni_reg_625x,
855 .caldac = { caldac_none },
856 },
797 [BOARD_PCI6251] = { 857 [BOARD_PCI6251] = {
798 .name = "pci-6251", 858 .name = "pci-6251",
799 .n_adchan = 16, 859 .n_adchan = 16,
@@ -865,6 +925,17 @@ static const struct ni_board_struct ni_boards[] = {
865 .has_32dio_chan = 1, 925 .has_32dio_chan = 1,
866 .caldac = { caldac_none }, 926 .caldac = { caldac_none },
867 }, 927 },
928 [BOARD_PXI6254] = {
929 .name = "pxi-6254",
930 .n_adchan = 32,
931 .ai_maxdata = 0xffff,
932 .ai_fifo_depth = 4095,
933 .gainlkup = ai_gain_628x,
934 .ai_speed = 800,
935 .reg_type = ni_reg_625x,
936 .has_32dio_chan = 1,
937 .caldac = { caldac_none },
938 },
868 [BOARD_PCI6259] = { 939 [BOARD_PCI6259] = {
869 .name = "pci-6259", 940 .name = "pci-6259",
870 .n_adchan = 32, 941 .n_adchan = 32,
@@ -881,6 +952,22 @@ static const struct ni_board_struct ni_boards[] = {
881 .has_32dio_chan = 1, 952 .has_32dio_chan = 1,
882 .caldac = { caldac_none }, 953 .caldac = { caldac_none },
883 }, 954 },
955 [BOARD_PXI6259] = {
956 .name = "pxi-6259",
957 .n_adchan = 32,
958 .ai_maxdata = 0xffff,
959 .ai_fifo_depth = 4095,
960 .gainlkup = ai_gain_628x,
961 .ai_speed = 800,
962 .n_aochan = 4,
963 .ao_maxdata = 0xffff,
964 .ao_fifo_depth = 8191,
965 .ao_range_table = &range_ni_M_625x_ao,
966 .reg_type = ni_reg_625x,
967 .ao_speed = 350,
968 .has_32dio_chan = 1,
969 .caldac = { caldac_none },
970 },
884 [BOARD_PCIE6259] = { 971 [BOARD_PCIE6259] = {
885 .name = "pcie-6259", 972 .name = "pcie-6259",
886 .n_adchan = 32, 973 .n_adchan = 32,
@@ -897,6 +984,22 @@ static const struct ni_board_struct ni_boards[] = {
897 .has_32dio_chan = 1, 984 .has_32dio_chan = 1,
898 .caldac = { caldac_none }, 985 .caldac = { caldac_none },
899 }, 986 },
987 [BOARD_PXIE6259] = {
988 .name = "pxie-6259",
989 .n_adchan = 32,
990 .ai_maxdata = 0xffff,
991 .ai_fifo_depth = 4095,
992 .gainlkup = ai_gain_628x,
993 .ai_speed = 800,
994 .n_aochan = 4,
995 .ao_maxdata = 0xffff,
996 .ao_fifo_depth = 8191,
997 .ao_range_table = &range_ni_M_625x_ao,
998 .reg_type = ni_reg_625x,
999 .ao_speed = 350,
1000 .has_32dio_chan = 1,
1001 .caldac = { caldac_none },
1002 },
900 [BOARD_PCI6280] = { 1003 [BOARD_PCI6280] = {
901 .name = "pci-6280", 1004 .name = "pci-6280",
902 .n_adchan = 16, 1005 .n_adchan = 16,
@@ -908,6 +1011,17 @@ static const struct ni_board_struct ni_boards[] = {
908 .reg_type = ni_reg_628x, 1011 .reg_type = ni_reg_628x,
909 .caldac = { caldac_none }, 1012 .caldac = { caldac_none },
910 }, 1013 },
1014 [BOARD_PXI6280] = {
1015 .name = "pxi-6280",
1016 .n_adchan = 16,
1017 .ai_maxdata = 0x3ffff,
1018 .ai_fifo_depth = 2047,
1019 .gainlkup = ai_gain_628x,
1020 .ai_speed = 1600,
1021 .ao_fifo_depth = 8191,
1022 .reg_type = ni_reg_628x,
1023 .caldac = { caldac_none },
1024 },
911 [BOARD_PCI6281] = { 1025 [BOARD_PCI6281] = {
912 .name = "pci-6281", 1026 .name = "pci-6281",
913 .n_adchan = 16, 1027 .n_adchan = 16,
@@ -949,6 +1063,17 @@ static const struct ni_board_struct ni_boards[] = {
949 .has_32dio_chan = 1, 1063 .has_32dio_chan = 1,
950 .caldac = { caldac_none }, 1064 .caldac = { caldac_none },
951 }, 1065 },
1066 [BOARD_PXI6284] = {
1067 .name = "pxi-6284",
1068 .n_adchan = 32,
1069 .ai_maxdata = 0x3ffff,
1070 .ai_fifo_depth = 2047,
1071 .gainlkup = ai_gain_628x,
1072 .ai_speed = 1600,
1073 .reg_type = ni_reg_628x,
1074 .has_32dio_chan = 1,
1075 .caldac = { caldac_none },
1076 },
952 [BOARD_PCI6289] = { 1077 [BOARD_PCI6289] = {
953 .name = "pci-6289", 1078 .name = "pci-6289",
954 .n_adchan = 32, 1079 .n_adchan = 32,
@@ -965,6 +1090,22 @@ static const struct ni_board_struct ni_boards[] = {
965 .has_32dio_chan = 1, 1090 .has_32dio_chan = 1,
966 .caldac = { caldac_none }, 1091 .caldac = { caldac_none },
967 }, 1092 },
1093 [BOARD_PXI6289] = {
1094 .name = "pxi-6289",
1095 .n_adchan = 32,
1096 .ai_maxdata = 0x3ffff,
1097 .ai_fifo_depth = 2047,
1098 .gainlkup = ai_gain_628x,
1099 .ai_speed = 1600,
1100 .n_aochan = 4,
1101 .ao_maxdata = 0xffff,
1102 .ao_fifo_depth = 8191,
1103 .ao_range_table = &range_ni_M_628x_ao,
1104 .reg_type = ni_reg_628x,
1105 .ao_speed = 350,
1106 .has_32dio_chan = 1,
1107 .caldac = { caldac_none },
1108 },
968 [BOARD_PCI6143] = { 1109 [BOARD_PCI6143] = {
969 .name = "pci-6143", 1110 .name = "pci-6143",
970 .n_adchan = 8, 1111 .n_adchan = 8,
@@ -1061,8 +1202,6 @@ static void m_series_init_eeprom_buffer(struct comedi_device *dev)
1061 resource_size_t daq_phys_addr; 1202 resource_size_t daq_phys_addr;
1062 static const int Start_Cal_EEPROM = 0x400; 1203 static const int Start_Cal_EEPROM = 0x400;
1063 static const unsigned int window_size = 10; 1204 static const unsigned int window_size = 10;
1064 static const int serial_number_eeprom_offset = 0x4;
1065 static const int serial_number_eeprom_length = 0x4;
1066 unsigned int old_iodwbsr_bits; 1205 unsigned int old_iodwbsr_bits;
1067 unsigned int old_iodwbsr1_bits; 1206 unsigned int old_iodwbsr1_bits;
1068 unsigned int old_iodwcr1_bits; 1207 unsigned int old_iodwcr1_bits;
@@ -1080,13 +1219,6 @@ static void m_series_init_eeprom_buffer(struct comedi_device *dev)
1080 writel(0x1 | old_iodwcr1_bits, mite->mmio + MITE_IODWCR_1); 1219 writel(0x1 | old_iodwcr1_bits, mite->mmio + MITE_IODWCR_1);
1081 writel(0xf, mite->mmio + 0x30); 1220 writel(0xf, mite->mmio + 0x30);
1082 1221
1083 BUG_ON(serial_number_eeprom_length > sizeof(devpriv->serial_number));
1084 for (i = 0; i < serial_number_eeprom_length; ++i) {
1085 char *byte_ptr = (char *)&devpriv->serial_number + i;
1086 *byte_ptr = ni_readb(dev, serial_number_eeprom_offset + i);
1087 }
1088 devpriv->serial_number = be32_to_cpu(devpriv->serial_number);
1089
1090 for (i = 0; i < M_SERIES_EEPROM_SIZE; ++i) 1222 for (i = 0; i < M_SERIES_EEPROM_SIZE; ++i)
1091 devpriv->eeprom_buffer[i] = ni_readb(dev, Start_Cal_EEPROM + i); 1223 devpriv->eeprom_buffer[i] = ni_readb(dev, Start_Cal_EEPROM + i);
1092 1224
@@ -1284,14 +1416,24 @@ static const struct pci_device_id ni_pcimio_pci_table[] = {
1284 { PCI_VDEVICE(NI, 0x70aa), BOARD_PCI6229 }, 1416 { PCI_VDEVICE(NI, 0x70aa), BOARD_PCI6229 },
1285 { PCI_VDEVICE(NI, 0x70ab), BOARD_PCI6259 }, 1417 { PCI_VDEVICE(NI, 0x70ab), BOARD_PCI6259 },
1286 { PCI_VDEVICE(NI, 0x70ac), BOARD_PCI6289 }, 1418 { PCI_VDEVICE(NI, 0x70ac), BOARD_PCI6289 },
1419 { PCI_VDEVICE(NI, 0x70ad), BOARD_PXI6251 },
1420 { PCI_VDEVICE(NI, 0x70ae), BOARD_PXI6220 },
1287 { PCI_VDEVICE(NI, 0x70af), BOARD_PCI6221 }, 1421 { PCI_VDEVICE(NI, 0x70af), BOARD_PCI6221 },
1288 { PCI_VDEVICE(NI, 0x70b0), BOARD_PCI6220 }, 1422 { PCI_VDEVICE(NI, 0x70b0), BOARD_PCI6220 },
1423 { PCI_VDEVICE(NI, 0x70b1), BOARD_PXI6229 },
1424 { PCI_VDEVICE(NI, 0x70b2), BOARD_PXI6259 },
1425 { PCI_VDEVICE(NI, 0x70b3), BOARD_PXI6289 },
1289 { PCI_VDEVICE(NI, 0x70b4), BOARD_PCI6250 }, 1426 { PCI_VDEVICE(NI, 0x70b4), BOARD_PCI6250 },
1427 { PCI_VDEVICE(NI, 0x70b5), BOARD_PXI6221 },
1290 { PCI_VDEVICE(NI, 0x70b6), BOARD_PCI6280 }, 1428 { PCI_VDEVICE(NI, 0x70b6), BOARD_PCI6280 },
1291 { PCI_VDEVICE(NI, 0x70b7), BOARD_PCI6254 }, 1429 { PCI_VDEVICE(NI, 0x70b7), BOARD_PCI6254 },
1292 { PCI_VDEVICE(NI, 0x70b8), BOARD_PCI6251 }, 1430 { PCI_VDEVICE(NI, 0x70b8), BOARD_PCI6251 },
1431 { PCI_VDEVICE(NI, 0x70b9), BOARD_PXI6250 },
1432 { PCI_VDEVICE(NI, 0x70ba), BOARD_PXI6254 },
1433 { PCI_VDEVICE(NI, 0x70bb), BOARD_PXI6280 },
1293 { PCI_VDEVICE(NI, 0x70bc), BOARD_PCI6284 }, 1434 { PCI_VDEVICE(NI, 0x70bc), BOARD_PCI6284 },
1294 { PCI_VDEVICE(NI, 0x70bd), BOARD_PCI6281 }, 1435 { PCI_VDEVICE(NI, 0x70bd), BOARD_PCI6281 },
1436 { PCI_VDEVICE(NI, 0x70be), BOARD_PXI6284 },
1295 { PCI_VDEVICE(NI, 0x70bf), BOARD_PXI6281 }, 1437 { PCI_VDEVICE(NI, 0x70bf), BOARD_PXI6281 },
1296 { PCI_VDEVICE(NI, 0x70c0), BOARD_PCI6143 }, 1438 { PCI_VDEVICE(NI, 0x70c0), BOARD_PCI6143 },
1297 { PCI_VDEVICE(NI, 0x70f2), BOARD_PCI6224 }, 1439 { PCI_VDEVICE(NI, 0x70f2), BOARD_PCI6224 },
@@ -1299,11 +1441,11 @@ static const struct pci_device_id ni_pcimio_pci_table[] = {
1299 { PCI_VDEVICE(NI, 0x710d), BOARD_PXI6143 }, 1441 { PCI_VDEVICE(NI, 0x710d), BOARD_PXI6143 },
1300 { PCI_VDEVICE(NI, 0x716c), BOARD_PCI6225 }, 1442 { PCI_VDEVICE(NI, 0x716c), BOARD_PCI6225 },
1301 { PCI_VDEVICE(NI, 0x716d), BOARD_PXI6225 }, 1443 { PCI_VDEVICE(NI, 0x716d), BOARD_PXI6225 },
1444 { PCI_VDEVICE(NI, 0x717d), BOARD_PCIE6251 },
1302 { PCI_VDEVICE(NI, 0x717f), BOARD_PCIE6259 }, 1445 { PCI_VDEVICE(NI, 0x717f), BOARD_PCIE6259 },
1303 { PCI_VDEVICE(NI, 0x71bc), BOARD_PCI6221_37PIN }, 1446 { PCI_VDEVICE(NI, 0x71bc), BOARD_PCI6221_37PIN },
1304 { PCI_VDEVICE(NI, 0x717d), BOARD_PCIE6251 },
1305 { PCI_VDEVICE(NI, 0x72e8), BOARD_PXIE6251 }, 1447 { PCI_VDEVICE(NI, 0x72e8), BOARD_PXIE6251 },
1306 { PCI_VDEVICE(NI, 0x70ad), BOARD_PXI6251 }, 1448 { PCI_VDEVICE(NI, 0x72e9), BOARD_PXIE6259 },
1307 { 0 } 1449 { 0 }
1308}; 1450};
1309MODULE_DEVICE_TABLE(pci, ni_pcimio_pci_table); 1451MODULE_DEVICE_TABLE(pci, ni_pcimio_pci_table);
diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h
index f27b545f83eb..61138e86a455 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -1031,7 +1031,6 @@ struct ni_private {
1031 1031
1032 unsigned short ai_fifo_buffer[0x2000]; 1032 unsigned short ai_fifo_buffer[0x2000];
1033 u8 eeprom_buffer[M_SERIES_EEPROM_SIZE]; 1033 u8 eeprom_buffer[M_SERIES_EEPROM_SIZE];
1034 __be32 serial_number;
1035 1034
1036 struct mite *mite; 1035 struct mite *mite;
1037 struct mite_channel *ai_mite_chan; 1036 struct mite_channel *ai_mite_chan;
diff --git a/drivers/staging/comedi/drivers/ni_tio.h b/drivers/staging/comedi/drivers/ni_tio.h
index 4978358f9b13..2012033414d3 100644
--- a/drivers/staging/comedi/drivers/ni_tio.h
+++ b/drivers/staging/comedi/drivers/ni_tio.h
@@ -110,9 +110,9 @@ struct ni_gpct {
110 110
111struct ni_gpct_device { 111struct ni_gpct_device {
112 struct comedi_device *dev; 112 struct comedi_device *dev;
113 void (*write)(struct ni_gpct *, unsigned int value, 113 void (*write)(struct ni_gpct *counter, unsigned int value,
114 enum ni_gpct_register); 114 enum ni_gpct_register);
115 unsigned int (*read)(struct ni_gpct *, enum ni_gpct_register); 115 unsigned int (*read)(struct ni_gpct *counter, enum ni_gpct_register);
116 enum ni_gpct_variant variant; 116 enum ni_gpct_variant variant;
117 struct ni_gpct *counters; 117 struct ni_gpct *counters;
118 unsigned int num_counters; 118 unsigned int num_counters;
@@ -121,28 +121,30 @@ struct ni_gpct_device {
121}; 121};
122 122
123struct ni_gpct_device * 123struct ni_gpct_device *
124ni_gpct_device_construct(struct comedi_device *, 124ni_gpct_device_construct(struct comedi_device *dev,
125 void (*write)(struct ni_gpct *, 125 void (*write)(struct ni_gpct *counter,
126 unsigned int value, 126 unsigned int value,
127 enum ni_gpct_register), 127 enum ni_gpct_register),
128 unsigned int (*read)(struct ni_gpct *, 128 unsigned int (*read)(struct ni_gpct *counter,
129 enum ni_gpct_register), 129 enum ni_gpct_register),
130 enum ni_gpct_variant, 130 enum ni_gpct_variant,
131 unsigned int num_counters); 131 unsigned int num_counters);
132void ni_gpct_device_destroy(struct ni_gpct_device *); 132void ni_gpct_device_destroy(struct ni_gpct_device *counter_dev);
133void ni_tio_init_counter(struct ni_gpct *); 133void ni_tio_init_counter(struct ni_gpct *counter);
134int ni_tio_insn_read(struct comedi_device *, struct comedi_subdevice *, 134int ni_tio_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
135 struct comedi_insn *, unsigned int *data); 135 struct comedi_insn *insn, unsigned int *data);
136int ni_tio_insn_config(struct comedi_device *, struct comedi_subdevice *, 136int ni_tio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s,
137 struct comedi_insn *, unsigned int *data); 137 struct comedi_insn *insn, unsigned int *data);
138int ni_tio_insn_write(struct comedi_device *, struct comedi_subdevice *, 138int ni_tio_insn_write(struct comedi_device *dev, struct comedi_subdevice *s,
139 struct comedi_insn *, unsigned int *data); 139 struct comedi_insn *insn, unsigned int *data);
140int ni_tio_cmd(struct comedi_device *, struct comedi_subdevice *); 140int ni_tio_cmd(struct comedi_device *dev, struct comedi_subdevice *s);
141int ni_tio_cmdtest(struct comedi_device *, struct comedi_subdevice *, 141int ni_tio_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
142 struct comedi_cmd *); 142 struct comedi_cmd *cmd);
143int ni_tio_cancel(struct ni_gpct *); 143int ni_tio_cancel(struct ni_gpct *counter);
144void ni_tio_handle_interrupt(struct ni_gpct *, struct comedi_subdevice *); 144void ni_tio_handle_interrupt(struct ni_gpct *counter,
145void ni_tio_set_mite_channel(struct ni_gpct *, struct mite_channel *); 145 struct comedi_subdevice *s);
146void ni_tio_acknowledge(struct ni_gpct *); 146void ni_tio_set_mite_channel(struct ni_gpct *counter,
147 struct mite_channel *mite_chan);
148void ni_tio_acknowledge(struct ni_gpct *counter);
147 149
148#endif /* _COMEDI_NI_TIO_H */ 150#endif /* _COMEDI_NI_TIO_H */
diff --git a/drivers/staging/comedi/drivers/ni_tio_internal.h b/drivers/staging/comedi/drivers/ni_tio_internal.h
index b15b10833c42..4e024eb5656b 100644
--- a/drivers/staging/comedi/drivers/ni_tio_internal.h
+++ b/drivers/staging/comedi/drivers/ni_tio_internal.h
@@ -160,8 +160,9 @@
160#define GI_TC_INTERRUPT_ENABLE(x) (((x) % 2) ? BIT(9) : BIT(6)) 160#define GI_TC_INTERRUPT_ENABLE(x) (((x) % 2) ? BIT(9) : BIT(6))
161#define GI_GATE_INTERRUPT_ENABLE(x) (((x) % 2) ? BIT(10) : BIT(8)) 161#define GI_GATE_INTERRUPT_ENABLE(x) (((x) % 2) ? BIT(10) : BIT(8))
162 162
163void ni_tio_write(struct ni_gpct *, unsigned int value, enum ni_gpct_register); 163void ni_tio_write(struct ni_gpct *counter, unsigned int value,
164unsigned int ni_tio_read(struct ni_gpct *, enum ni_gpct_register); 164 enum ni_gpct_register);
165unsigned int ni_tio_read(struct ni_gpct *counter, enum ni_gpct_register);
165 166
166static inline bool 167static inline bool
167ni_tio_counting_mode_registers_present(const struct ni_gpct_device *counter_dev) 168ni_tio_counting_mode_registers_present(const struct ni_gpct_device *counter_dev)
@@ -170,12 +171,13 @@ ni_tio_counting_mode_registers_present(const struct ni_gpct_device *counter_dev)
170 return counter_dev->variant != ni_gpct_variant_e_series; 171 return counter_dev->variant != ni_gpct_variant_e_series;
171} 172}
172 173
173void ni_tio_set_bits(struct ni_gpct *, enum ni_gpct_register reg, 174void ni_tio_set_bits(struct ni_gpct *counter, enum ni_gpct_register reg,
174 unsigned int mask, unsigned int value); 175 unsigned int mask, unsigned int value);
175unsigned int ni_tio_get_soft_copy(const struct ni_gpct *, 176unsigned int ni_tio_get_soft_copy(const struct ni_gpct *counter,
176 enum ni_gpct_register reg); 177 enum ni_gpct_register reg);
177 178
178int ni_tio_arm(struct ni_gpct *, bool arm, unsigned int start_trigger); 179int ni_tio_arm(struct ni_gpct *counter, bool arm, unsigned int start_trigger);
179int ni_tio_set_gate_src(struct ni_gpct *, unsigned int gate, unsigned int src); 180int ni_tio_set_gate_src(struct ni_gpct *counter, unsigned int gate,
181 unsigned int src);
180 182
181#endif /* _COMEDI_NI_TIO_INTERNAL_H */ 183#endif /* _COMEDI_NI_TIO_INTERNAL_H */
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index 0dd5fe286855..97939b42cc00 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -1513,7 +1513,7 @@ static int s626_ai_insn_read(struct comedi_device *dev,
1513 1513
1514 for (n = 0; n < insn->n; n++) { 1514 for (n = 0; n < insn->n; n++) {
1515 /* Delay 10 microseconds for analog input settling. */ 1515 /* Delay 10 microseconds for analog input settling. */
1516 udelay(10); 1516 usleep_range(10, 20);
1517 1517
1518 /* Start ADC by pulsing GPIO1 low */ 1518 /* Start ADC by pulsing GPIO1 low */
1519 gpio_image = readl(dev->mmio + S626_P_GPIO); 1519 gpio_image = readl(dev->mmio + S626_P_GPIO);
diff --git a/drivers/staging/comedi/proc.c b/drivers/staging/comedi/proc.c
index 91dea25b5724..2644dd4d6143 100644
--- a/drivers/staging/comedi/proc.c
+++ b/drivers/staging/comedi/proc.c
@@ -80,15 +80,17 @@ static int comedi_proc_open(struct inode *inode, struct file *file)
80} 80}
81 81
82static const struct file_operations comedi_proc_fops = { 82static const struct file_operations comedi_proc_fops = {
83 .owner = THIS_MODULE,
83 .open = comedi_proc_open, 84 .open = comedi_proc_open,
84 .read = seq_read, 85 .read = seq_read,
85 .llseek = seq_lseek, 86 .llseek = seq_lseek,
86 .release = single_release, 87 .release = single_release,
87}; 88};
88 89
89void comedi_proc_init(void) 90void __init comedi_proc_init(void)
90{ 91{
91 proc_create("comedi", 0644, NULL, &comedi_proc_fops); 92 if (!proc_create("comedi", 0444, NULL, &comedi_proc_fops))
93 pr_warn("comedi: unable to create proc entry\n");
92} 94}
93 95
94void comedi_proc_cleanup(void) 96void comedi_proc_cleanup(void)
diff --git a/drivers/staging/dgnc/TODO b/drivers/staging/dgnc/TODO
index 0e0825bd70ae..e26d1d6a5941 100644
--- a/drivers/staging/dgnc/TODO
+++ b/drivers/staging/dgnc/TODO
@@ -1,10 +1,9 @@
1* checkpatch fixes
2* remove unnecessary comments 1* remove unnecessary comments
3* remove unnecessary error messages. Example kzalloc() has its 2* remove unnecessary error messages. Example kzalloc() has its
4 own error message. Adding an extra one is useless. 3 own error message. Adding an extra one is useless.
5* use goto statements for error handling when appropriate 4* use goto statements for error handling when appropriate
6* there is a lot of unnecessary code in the driver. It was 5* there is a lot of unnecessary code in the driver. It was
7 originally a standalone driver. Remove uneeded code. 6 originally a standalone driver. Remove unneeded code.
8 7
9Please send patches to Greg Kroah-Hartman <greg@kroah.com> and 8Please send patches to Greg Kroah-Hartman <greg@kroah.com> and
10Cc: Lidza Louina <lidza.louina@gmail.com> 9Cc: Lidza Louina <lidza.louina@gmail.com>
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 1e10c0fe4745..c63e591631f6 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -971,9 +971,10 @@ static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
971 * touched safely, the close routine will signal the 971 * touched safely, the close routine will signal the
972 * ch_flags_wait to wake us back up. 972 * ch_flags_wait to wake us back up.
973 */ 973 */
974 rc = wait_event_interruptible(ch->ch_flags_wait, 974 rc = wait_event_interruptible(
975 (((ch->ch_tun.un_flags | 975 ch->ch_flags_wait,
976 ch->ch_pun.un_flags) & UN_CLOSING) == 0)); 976 (((ch->ch_tun.un_flags |
977 ch->ch_pun.un_flags) & UN_CLOSING) == 0));
977 978
978 /* If ret is non-zero, user ctrl-c'ed us */ 979 /* If ret is non-zero, user ctrl-c'ed us */
979 if (rc) 980 if (rc)
@@ -1193,7 +1194,8 @@ static int dgnc_block_til_ready(struct tty_struct *tty,
1193 (old_flags != (ch->ch_tun.un_flags | 1194 (old_flags != (ch->ch_tun.un_flags |
1194 ch->ch_pun.un_flags))); 1195 ch->ch_pun.un_flags)));
1195 else 1196 else
1196 retval = wait_event_interruptible(ch->ch_flags_wait, 1197 retval = wait_event_interruptible(
1198 ch->ch_flags_wait,
1197 (old_flags != ch->ch_flags)); 1199 (old_flags != ch->ch_flags));
1198 1200
1199 /* 1201 /*
diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c
index 3f42fa8b0bf3..77b242e09932 100644
--- a/drivers/staging/emxx_udc/emxx_udc.c
+++ b/drivers/staging/emxx_udc/emxx_udc.c
@@ -553,28 +553,22 @@ static void _nbu2ss_dma_unmap_single(
553 553
554/*-------------------------------------------------------------------------*/ 554/*-------------------------------------------------------------------------*/
555/* Endpoint 0 OUT Transfer (PIO) */ 555/* Endpoint 0 OUT Transfer (PIO) */
556static int EP0_out_PIO(struct nbu2ss_udc *udc, u8 *pBuf, u32 length) 556static int ep0_out_pio(struct nbu2ss_udc *udc, u8 *buf, u32 length)
557{ 557{
558 u32 i; 558 u32 i;
559 int nret = 0; 559 u32 numreads = length / sizeof(u32);
560 u32 iWordLength = 0; 560 union usb_reg_access *buf32 = (union usb_reg_access *)buf;
561 union usb_reg_access *pBuf32 = (union usb_reg_access *)pBuf;
562 561
563 /*------------------------------------------------------------*/ 562 if (!numreads)
564 /* Read Length */ 563 return 0;
565 iWordLength = length / sizeof(u32);
566 564
567 /*------------------------------------------------------------*/
568 /* PIO Read */ 565 /* PIO Read */
569 if (iWordLength) { 566 for (i = 0; i < numreads; i++) {
570 for (i = 0; i < iWordLength; i++) { 567 buf32->dw = _nbu2ss_readl(&udc->p_regs->EP0_READ);
571 pBuf32->dw = _nbu2ss_readl(&udc->p_regs->EP0_READ); 568 buf32++;
572 pBuf32++;
573 }
574 nret = iWordLength * sizeof(u32);
575 } 569 }
576 570
577 return nret; 571 return numreads * sizeof(u32);
578} 572}
579 573
580/*-------------------------------------------------------------------------*/ 574/*-------------------------------------------------------------------------*/
@@ -758,7 +752,7 @@ static int _nbu2ss_ep0_out_transfer(
758 pBuffer = (u8 *)req->req.buf; 752 pBuffer = (u8 *)req->req.buf;
759 pBuffer += req->req.actual; 753 pBuffer += req->req.actual;
760 754
761 result = EP0_out_PIO(udc, pBuffer 755 result = ep0_out_pio(udc, pBuffer
762 , min(iRemainSize, iRecvLength)); 756 , min(iRemainSize, iRecvLength));
763 if (result < 0) 757 if (result < 0)
764 return result; 758 return result;
@@ -3137,7 +3131,7 @@ static const struct {
3137}; 3131};
3138 3132
3139/*-------------------------------------------------------------------------*/ 3133/*-------------------------------------------------------------------------*/
3140static void __init nbu2ss_drv_ep_init(struct nbu2ss_udc *udc) 3134static void nbu2ss_drv_ep_init(struct nbu2ss_udc *udc)
3141{ 3135{
3142 int i; 3136 int i;
3143 3137
@@ -3168,7 +3162,7 @@ static void __init nbu2ss_drv_ep_init(struct nbu2ss_udc *udc)
3168 3162
3169/*-------------------------------------------------------------------------*/ 3163/*-------------------------------------------------------------------------*/
3170/* platform_driver */ 3164/* platform_driver */
3171static int __init nbu2ss_drv_contest_init( 3165static int nbu2ss_drv_contest_init(
3172 struct platform_device *pdev, 3166 struct platform_device *pdev,
3173 struct nbu2ss_udc *udc) 3167 struct nbu2ss_udc *udc)
3174{ 3168{
diff --git a/drivers/staging/fbtft/fb_agm1264k-fl.c b/drivers/staging/fbtft/fb_agm1264k-fl.c
index a6e3af74a904..4ee76dbd30b5 100644
--- a/drivers/staging/fbtft/fb_agm1264k-fl.c
+++ b/drivers/staging/fbtft/fb_agm1264k-fl.c
@@ -185,9 +185,9 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
185 buf[i] = (u8)va_arg(args, unsigned int); 185 buf[i] = (u8)va_arg(args, unsigned int);
186 186
187 va_end(args); 187 va_end(args);
188 fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, 188 fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device,
189 par->info->device, u8, buf, len, "%s: ", __func__); 189 u8, buf, len, "%s: ", __func__);
190 } 190}
191 191
192 va_start(args, len); 192 va_start(args, len);
193 193
@@ -246,7 +246,7 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
246 246
247static void 247static void
248construct_line_bitmap(struct fbtft_par *par, u8 *dest, signed short *src, 248construct_line_bitmap(struct fbtft_par *par, u8 *dest, signed short *src,
249 int xs, int xe, int y) 249 int xs, int xe, int y)
250{ 250{
251 int x, i; 251 int x, i;
252 252
@@ -361,7 +361,8 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
361 /* left half of display */ 361 /* left half of display */
362 if (addr_win.xs < par->info->var.xres / 2) { 362 if (addr_win.xs < par->info->var.xres / 2) {
363 construct_line_bitmap(par, buf, convert_buf, 363 construct_line_bitmap(par, buf, convert_buf,
364 addr_win.xs, par->info->var.xres / 2, y); 364 addr_win.xs,
365 par->info->var.xres / 2, y);
365 366
366 len = par->info->var.xres / 2 - addr_win.xs; 367 len = par->info->var.xres / 2 - addr_win.xs;
367 368
@@ -382,8 +383,9 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
382 /* right half of display */ 383 /* right half of display */
383 if (addr_win.xe >= par->info->var.xres / 2) { 384 if (addr_win.xe >= par->info->var.xres / 2) {
384 construct_line_bitmap(par, buf, 385 construct_line_bitmap(par, buf,
385 convert_buf, par->info->var.xres / 2, 386 convert_buf,
386 addr_win.xe + 1, y); 387 par->info->var.xres / 2,
388 addr_win.xe + 1, y);
387 389
388 len = addr_win.xe + 1 - par->info->var.xres / 2; 390 len = addr_win.xe + 1 - par->info->var.xres / 2;
389 391
@@ -413,7 +415,7 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
413static int write(struct fbtft_par *par, void *buf, size_t len) 415static int write(struct fbtft_par *par, void *buf, size_t len)
414{ 416{
415 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len, 417 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
416 "%s(len=%d): ", __func__, len); 418 "%s(len=%d): ", __func__, len);
417 419
418 gpio_set_value(par->RW, 0); /* set write mode */ 420 gpio_set_value(par->RW, 0); /* set write mode */
419 421
diff --git a/drivers/staging/fbtft/fb_hx8340bn.c b/drivers/staging/fbtft/fb_hx8340bn.c
index 9970ed74bb38..1ca1fcd353d6 100644
--- a/drivers/staging/fbtft/fb_hx8340bn.c
+++ b/drivers/staging/fbtft/fb_hx8340bn.c
@@ -37,7 +37,7 @@
37 "3 3 17 8 4 7 05 7 6 0 3 1 6 0 0 " 37 "3 3 17 8 4 7 05 7 6 0 3 1 6 0 0 "
38 38
39static bool emulate; 39static bool emulate;
40module_param(emulate, bool, 0); 40module_param(emulate, bool, 0000);
41MODULE_PARM_DESC(emulate, "Force emulation in 9-bit mode"); 41MODULE_PARM_DESC(emulate, "Force emulation in 9-bit mode");
42 42
43static int init_display(struct fbtft_par *par) 43static int init_display(struct fbtft_par *par)
@@ -158,7 +158,7 @@ static int set_var(struct fbtft_par *par)
158 * ON0 ON1 CN0 CN1 CN2 CN3 CN4 MN0 MN1 MN2 MN3 MN4 MN5 XXXX GC 158 * ON0 ON1 CN0 CN1 CN2 CN3 CN4 MN0 MN1 MN2 MN3 MN4 MN5 XXXX GC
159 */ 159 */
160#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 160#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
161static int set_gamma(struct fbtft_par *par, unsigned long *curves) 161static int set_gamma(struct fbtft_par *par, u32 *curves)
162{ 162{
163 unsigned long mask[] = { 163 unsigned long mask[] = {
164 0x0f, 0x0f, 0x1f, 0x0f, 0x0f, 0x0f, 0x1f, 0x07, 0x07, 0x07, 164 0x0f, 0x0f, 0x1f, 0x0f, 0x0f, 0x0f, 0x1f, 0x07, 0x07, 0x07,
diff --git a/drivers/staging/fbtft/fb_hx8347d.c b/drivers/staging/fbtft/fb_hx8347d.c
index 450a61e3f99c..bbf78f8644a8 100644
--- a/drivers/staging/fbtft/fb_hx8347d.c
+++ b/drivers/staging/fbtft/fb_hx8347d.c
@@ -102,7 +102,7 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
102 * VRN0 VRN1 VRN2 VRN3 VRN4 VRN5 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 CGM 102 * VRN0 VRN1 VRN2 VRN3 VRN4 VRN5 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 CGM
103 */ 103 */
104#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 104#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
105static int set_gamma(struct fbtft_par *par, unsigned long *curves) 105static int set_gamma(struct fbtft_par *par, u32 *curves)
106{ 106{
107 unsigned long mask[] = { 107 unsigned long mask[] = {
108 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x1f, 0x1f, 108 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x7f, 0x7f, 0x1f, 0x1f,
diff --git a/drivers/staging/fbtft/fb_hx8353d.c b/drivers/staging/fbtft/fb_hx8353d.c
index 72e4ff8c5553..2c18051a44b3 100644
--- a/drivers/staging/fbtft/fb_hx8353d.c
+++ b/drivers/staging/fbtft/fb_hx8353d.c
@@ -118,7 +118,7 @@ static int set_var(struct fbtft_par *par)
118} 118}
119 119
120/* gamma string format: */ 120/* gamma string format: */
121static int set_gamma(struct fbtft_par *par, unsigned long *curves) 121static int set_gamma(struct fbtft_par *par, u32 *curves)
122{ 122{
123 write_reg(par, 0xE0, 123 write_reg(par, 0xE0,
124 curves[0], curves[1], curves[2], curves[3], 124 curves[0], curves[1], curves[2], curves[3],
diff --git a/drivers/staging/fbtft/fb_ili9163.c b/drivers/staging/fbtft/fb_ili9163.c
index 6b8f8b17e9a3..579e17734612 100644
--- a/drivers/staging/fbtft/fb_ili9163.c
+++ b/drivers/staging/fbtft/fb_ili9163.c
@@ -202,7 +202,7 @@ static int set_var(struct fbtft_par *par)
202 202
203#ifdef GAMMA_ADJ 203#ifdef GAMMA_ADJ
204#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 204#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
205static int gamma_adj(struct fbtft_par *par, unsigned long *curves) 205static int gamma_adj(struct fbtft_par *par, u32 *curves)
206{ 206{
207 unsigned long mask[] = { 207 unsigned long mask[] = {
208 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 208 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
diff --git a/drivers/staging/fbtft/fb_ili9320.c b/drivers/staging/fbtft/fb_ili9320.c
index 278e4c7e95e5..20ba86da028b 100644
--- a/drivers/staging/fbtft/fb_ili9320.c
+++ b/drivers/staging/fbtft/fb_ili9320.c
@@ -221,7 +221,7 @@ static int set_var(struct fbtft_par *par)
221 * VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5 221 * VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5
222 */ 222 */
223#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 223#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
224static int set_gamma(struct fbtft_par *par, unsigned long *curves) 224static int set_gamma(struct fbtft_par *par, u32 *curves)
225{ 225{
226 unsigned long mask[] = { 226 unsigned long mask[] = {
227 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 227 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
diff --git a/drivers/staging/fbtft/fb_ili9325.c b/drivers/staging/fbtft/fb_ili9325.c
index 19e33bab9cac..7189de5ae4b3 100644
--- a/drivers/staging/fbtft/fb_ili9325.c
+++ b/drivers/staging/fbtft/fb_ili9325.c
@@ -215,7 +215,7 @@ static int set_var(struct fbtft_par *par)
215 * VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5 215 * VRN0 VRN1 RN0 RN1 KN0 KN1 KN2 KN3 KN4 KN5
216 */ 216 */
217#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 217#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
218static int set_gamma(struct fbtft_par *par, unsigned long *curves) 218static int set_gamma(struct fbtft_par *par, u32 *curves)
219{ 219{
220 unsigned long mask[] = { 220 unsigned long mask[] = {
221 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 221 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
diff --git a/drivers/staging/fbtft/fb_ili9341.c b/drivers/staging/fbtft/fb_ili9341.c
index ff35c8624ca3..21a98e9e1a14 100644
--- a/drivers/staging/fbtft/fb_ili9341.c
+++ b/drivers/staging/fbtft/fb_ili9341.c
@@ -121,7 +121,7 @@ static int set_var(struct fbtft_par *par)
121 * Negative: Par1 Par2 [...] Par15 121 * Negative: Par1 Par2 [...] Par15
122 */ 122 */
123#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 123#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
124static int set_gamma(struct fbtft_par *par, unsigned long *curves) 124static int set_gamma(struct fbtft_par *par, u32 *curves)
125{ 125{
126 int i; 126 int i;
127 127
diff --git a/drivers/staging/fbtft/fb_pcd8544.c b/drivers/staging/fbtft/fb_pcd8544.c
index a4710dc067ef..87f678a314cc 100644
--- a/drivers/staging/fbtft/fb_pcd8544.c
+++ b/drivers/staging/fbtft/fb_pcd8544.c
@@ -33,11 +33,11 @@
33#define DEFAULT_GAMMA "40" /* gamma controls the contrast in this driver */ 33#define DEFAULT_GAMMA "40" /* gamma controls the contrast in this driver */
34 34
35static unsigned int tc; 35static unsigned int tc;
36module_param(tc, uint, 0); 36module_param(tc, uint, 0000);
37MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)"); 37MODULE_PARM_DESC(tc, "TC[1:0] Temperature coefficient: 0-3 (default: 0)");
38 38
39static unsigned int bs = 4; 39static unsigned int bs = 4;
40module_param(bs, uint, 0); 40module_param(bs, uint, 0000);
41MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)"); 41MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
42 42
43static int init_display(struct fbtft_par *par) 43static int init_display(struct fbtft_par *par)
@@ -137,7 +137,7 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
137 return ret; 137 return ret;
138} 138}
139 139
140static int set_gamma(struct fbtft_par *par, unsigned long *curves) 140static int set_gamma(struct fbtft_par *par, u32 *curves)
141{ 141{
142 /* apply mask */ 142 /* apply mask */
143 curves[0] &= 0x7F; 143 curves[0] &= 0x7F;
diff --git a/drivers/staging/fbtft/fb_ra8875.c b/drivers/staging/fbtft/fb_ra8875.c
index 308a244972aa..89d36d6d0cd3 100644
--- a/drivers/staging/fbtft/fb_ra8875.c
+++ b/drivers/staging/fbtft/fb_ra8875.c
@@ -33,7 +33,7 @@ static int write_spi(struct fbtft_par *par, void *buf, size_t len)
33 struct spi_message m; 33 struct spi_message m;
34 34
35 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len, 35 fbtft_par_dbg_hex(DEBUG_WRITE, par, par->info->device, u8, buf, len,
36 "%s(len=%d): ", __func__, len); 36 "%s(len=%d): ", __func__, len);
37 37
38 if (!par->spi) { 38 if (!par->spi) {
39 dev_err(par->info->device, 39 dev_err(par->info->device,
@@ -42,10 +42,6 @@ static int write_spi(struct fbtft_par *par, void *buf, size_t len)
42 } 42 }
43 43
44 spi_message_init(&m); 44 spi_message_init(&m);
45 if (par->txbuf.dma && buf == par->txbuf.buf) {
46 t.tx_dma = par->txbuf.dma;
47 m.is_dma_mapped = 1;
48 }
49 spi_message_add_tail(&t, &m); 45 spi_message_add_tail(&t, &m);
50 return spi_sync(par->spi, &m); 46 return spi_sync(par->spi, &m);
51} 47}
@@ -55,9 +51,9 @@ static int init_display(struct fbtft_par *par)
55 gpio_set_value(par->gpio.dc, 1); 51 gpio_set_value(par->gpio.dc, 1);
56 52
57 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, 53 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
58 "%s()\n", __func__); 54 "%s()\n", __func__);
59 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, 55 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
60 "display size %dx%d\n", 56 "display size %dx%d\n",
61 par->info->var.xres, 57 par->info->var.xres,
62 par->info->var.yres); 58 par->info->var.yres);
63 59
@@ -215,7 +211,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
215 buf[i] = (u8)va_arg(args, unsigned int); 211 buf[i] = (u8)va_arg(args, unsigned int);
216 va_end(args); 212 va_end(args);
217 fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device, 213 fbtft_par_dbg_hex(DEBUG_WRITE_REGISTER, par, par->info->device,
218 u8, buf, len, "%s: ", __func__); 214 u8, buf, len, "%s: ", __func__);
219 } 215 }
220 216
221 va_start(args, len); 217 va_start(args, len);
@@ -266,7 +262,7 @@ static int write_vmem16_bus8(struct fbtft_par *par, size_t offset, size_t len)
266 size_t startbyte_size = 0; 262 size_t startbyte_size = 0;
267 263
268 fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n", 264 fbtft_par_dbg(DEBUG_WRITE_VMEM, par, "%s(offset=%zu, len=%zu)\n",
269 __func__, offset, len); 265 __func__, offset, len);
270 266
271 remain = len / 2; 267 remain = len / 2;
272 vmem16 = (u16 *)(par->info->screen_buffer + offset); 268 vmem16 = (u16 *)(par->info->screen_buffer + offset);
diff --git a/drivers/staging/fbtft/fb_s6d1121.c b/drivers/staging/fbtft/fb_s6d1121.c
index 9b1d70b218df..3b36ed50d491 100644
--- a/drivers/staging/fbtft/fb_s6d1121.c
+++ b/drivers/staging/fbtft/fb_s6d1121.c
@@ -130,7 +130,7 @@ static int set_var(struct fbtft_par *par)
130 * PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 PKN6 PKN7 PRN8 PRN9 PRN10 PRN11 VRN0 VRN1 130 * PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 PKN6 PKN7 PRN8 PRN9 PRN10 PRN11 VRN0 VRN1
131 */ 131 */
132#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 132#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
133static int set_gamma(struct fbtft_par *par, unsigned long *curves) 133static int set_gamma(struct fbtft_par *par, u32 *curves)
134{ 134{
135 unsigned long mask[] = { 135 unsigned long mask[] = {
136 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 136 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
diff --git a/drivers/staging/fbtft/fb_ssd1289.c b/drivers/staging/fbtft/fb_ssd1289.c
index 25f9fbe1e76f..c603e1516e64 100644
--- a/drivers/staging/fbtft/fb_ssd1289.c
+++ b/drivers/staging/fbtft/fb_ssd1289.c
@@ -30,7 +30,7 @@
30 "02 03 2 5 7 5 4 2 4 2" 30 "02 03 2 5 7 5 4 2 4 2"
31 31
32static unsigned int reg11 = 0x6040; 32static unsigned int reg11 = 0x6040;
33module_param(reg11, uint, 0); 33module_param(reg11, uint, 0000);
34MODULE_PARM_DESC(reg11, "Register 11h value"); 34MODULE_PARM_DESC(reg11, "Register 11h value");
35 35
36static int init_display(struct fbtft_par *par) 36static int init_display(struct fbtft_par *par)
@@ -136,7 +136,7 @@ static int set_var(struct fbtft_par *par)
136 * VRN0 VRN1 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 PKN5 136 * VRN0 VRN1 PRN0 PRN1 PKN0 PKN1 PKN2 PKN3 PKN4 PKN5
137 */ 137 */
138#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 138#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
139static int set_gamma(struct fbtft_par *par, unsigned long *curves) 139static int set_gamma(struct fbtft_par *par, u32 *curves)
140{ 140{
141 unsigned long mask[] = { 141 unsigned long mask[] = {
142 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 142 0x1f, 0x1f, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
diff --git a/drivers/staging/fbtft/fb_ssd1305.c b/drivers/staging/fbtft/fb_ssd1305.c
index 4b38c3fadd60..33c03872ca84 100644
--- a/drivers/staging/fbtft/fb_ssd1305.c
+++ b/drivers/staging/fbtft/fb_ssd1305.c
@@ -148,7 +148,7 @@ static int blank(struct fbtft_par *par, bool on)
148} 148}
149 149
150/* Gamma is used to control Contrast */ 150/* Gamma is used to control Contrast */
151static int set_gamma(struct fbtft_par *par, unsigned long *curves) 151static int set_gamma(struct fbtft_par *par, u32 *curves)
152{ 152{
153 curves[0] &= 0xFF; 153 curves[0] &= 0xFF;
154 /* Set Contrast Control for BANK0 */ 154 /* Set Contrast Control for BANK0 */
diff --git a/drivers/staging/fbtft/fb_ssd1306.c b/drivers/staging/fbtft/fb_ssd1306.c
index 80fc57029fee..96c58de85288 100644
--- a/drivers/staging/fbtft/fb_ssd1306.c
+++ b/drivers/staging/fbtft/fb_ssd1306.c
@@ -62,6 +62,8 @@ static int init_display(struct fbtft_par *par)
62 write_reg(par, 0xA8); 62 write_reg(par, 0xA8);
63 if (par->info->var.yres == 64) 63 if (par->info->var.yres == 64)
64 write_reg(par, 0x3F); 64 write_reg(par, 0x3F);
65 else if (par->info->var.yres == 48)
66 write_reg(par, 0x2F);
65 else 67 else
66 write_reg(par, 0x1F); 68 write_reg(par, 0x1F);
67 69
@@ -82,7 +84,7 @@ static int init_display(struct fbtft_par *par)
82 /* Vertical addressing mode */ 84 /* Vertical addressing mode */
83 write_reg(par, 0x01); 85 write_reg(par, 0x01);
84 86
85 /*Set Segment Re-map */ 87 /* Set Segment Re-map */
86 /* column address 127 is mapped to SEG0 */ 88 /* column address 127 is mapped to SEG0 */
87 write_reg(par, 0xA0 | 0x1); 89 write_reg(par, 0xA0 | 0x1);
88 90
@@ -95,6 +97,9 @@ static int init_display(struct fbtft_par *par)
95 if (par->info->var.yres == 64) 97 if (par->info->var.yres == 64)
96 /* A[4]=1b, Alternative COM pin configuration */ 98 /* A[4]=1b, Alternative COM pin configuration */
97 write_reg(par, 0x12); 99 write_reg(par, 0x12);
100 else if (par->info->var.yres == 48)
101 /* A[4]=1b, Alternative COM pin configuration */
102 write_reg(par, 0x12);
98 else 103 else
99 /* A[4]=0b, Sequential COM pin configuration */ 104 /* A[4]=0b, Sequential COM pin configuration */
100 write_reg(par, 0x02); 105 write_reg(par, 0x02);
@@ -124,6 +129,19 @@ static int init_display(struct fbtft_par *par)
124 return 0; 129 return 0;
125} 130}
126 131
132static void set_addr_win_64x48(struct fbtft_par *par)
133{
134 /* Set Column Address */
135 write_reg(par, 0x21);
136 write_reg(par, 0x20);
137 write_reg(par, 0x5F);
138
139 /* Set Page Address */
140 write_reg(par, 0x22);
141 write_reg(par, 0x0);
142 write_reg(par, 0x5);
143}
144
127static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye) 145static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
128{ 146{
129 /* Set Lower Column Start Address for Page Addressing Mode */ 147 /* Set Lower Column Start Address for Page Addressing Mode */
@@ -132,12 +150,15 @@ static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
132 write_reg(par, 0x10 | 0x0); 150 write_reg(par, 0x10 | 0x0);
133 /* Set Display Start Line */ 151 /* Set Display Start Line */
134 write_reg(par, 0x40 | 0x0); 152 write_reg(par, 0x40 | 0x0);
153
154 if (par->info->var.xres == 64 && par->info->var.yres == 48)
155 set_addr_win_64x48(par);
135} 156}
136 157
137static int blank(struct fbtft_par *par, bool on) 158static int blank(struct fbtft_par *par, bool on)
138{ 159{
139 fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n", 160 fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
140 __func__, on ? "true" : "false"); 161 __func__, on ? "true" : "false");
141 162
142 if (on) 163 if (on)
143 write_reg(par, 0xAE); 164 write_reg(par, 0xAE);
@@ -147,7 +168,7 @@ static int blank(struct fbtft_par *par, bool on)
147} 168}
148 169
149/* Gamma is used to control Contrast */ 170/* Gamma is used to control Contrast */
150static int set_gamma(struct fbtft_par *par, unsigned long *curves) 171static int set_gamma(struct fbtft_par *par, u32 *curves)
151{ 172{
152 /* apply mask */ 173 /* apply mask */
153 curves[0] &= 0xFF; 174 curves[0] &= 0xFF;
@@ -162,26 +183,24 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
162static int write_vmem(struct fbtft_par *par, size_t offset, size_t len) 183static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
163{ 184{
164 u16 *vmem16 = (u16 *)par->info->screen_buffer; 185 u16 *vmem16 = (u16 *)par->info->screen_buffer;
186 u32 xres = par->info->var.xres;
187 u32 yres = par->info->var.yres;
165 u8 *buf = par->txbuf.buf; 188 u8 *buf = par->txbuf.buf;
166 int x, y, i; 189 int x, y, i;
167 int ret = 0; 190 int ret = 0;
168 191
169 for (x = 0; x < par->info->var.xres; x++) { 192 for (x = 0; x < xres; x++) {
170 for (y = 0; y < par->info->var.yres/8; y++) { 193 for (y = 0; y < yres / 8; y++) {
171 *buf = 0x00; 194 *buf = 0x00;
172 for (i = 0; i < 8; i++) 195 for (i = 0; i < 8; i++)
173 *buf |= (vmem16[(y * 8 + i) * 196 *buf |= (vmem16[(y * 8 + i) * xres + x] ? 1 : 0) << i;
174 par->info->var.xres + x] ?
175 1 : 0) << i;
176 buf++; 197 buf++;
177 } 198 }
178 } 199 }
179 200
180 /* Write data */ 201 /* Write data */
181 gpio_set_value(par->gpio.dc, 1); 202 gpio_set_value(par->gpio.dc, 1);
182 ret = par->fbtftops.write(par, par->txbuf.buf, 203 ret = par->fbtftops.write(par, par->txbuf.buf, xres * yres / 8);
183 par->info->var.xres * par->info->var.yres /
184 8);
185 if (ret < 0) 204 if (ret < 0)
186 dev_err(par->info->device, "write failed and returned: %d\n", 205 dev_err(par->info->device, "write failed and returned: %d\n",
187 ret); 206 ret);
diff --git a/drivers/staging/fbtft/fb_ssd1325.c b/drivers/staging/fbtft/fb_ssd1325.c
index 15078bf2aa4b..b7e40c24f58e 100644
--- a/drivers/staging/fbtft/fb_ssd1325.c
+++ b/drivers/staging/fbtft/fb_ssd1325.c
@@ -116,7 +116,7 @@ static int blank(struct fbtft_par *par, bool on)
116 * 0 = Setting of GS1 < Setting of GS2 < Setting of GS3.....< 116 * 0 = Setting of GS1 < Setting of GS2 < Setting of GS3.....<
117 * Setting of GS14 < Setting of GS15 117 * Setting of GS14 < Setting of GS15
118 */ 118 */
119static int set_gamma(struct fbtft_par *par, unsigned long *curves) 119static int set_gamma(struct fbtft_par *par, u32 *curves)
120{ 120{
121 int i; 121 int i;
122 122
diff --git a/drivers/staging/fbtft/fb_ssd1331.c b/drivers/staging/fbtft/fb_ssd1331.c
index 1d74ac1343a8..26f24e32d979 100644
--- a/drivers/staging/fbtft/fb_ssd1331.c
+++ b/drivers/staging/fbtft/fb_ssd1331.c
@@ -122,7 +122,7 @@ static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
122 * Setting of GS63 has to be > Setting of GS62 +1 122 * Setting of GS63 has to be > Setting of GS62 +1
123 * 123 *
124 */ 124 */
125static int set_gamma(struct fbtft_par *par, unsigned long *curves) 125static int set_gamma(struct fbtft_par *par, u32 *curves)
126{ 126{
127 unsigned long tmp[GAMMA_NUM * GAMMA_LEN]; 127 unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
128 int i, acc = 0; 128 int i, acc = 0;
@@ -145,14 +145,16 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
145 } 145 }
146 146
147 write_reg(par, 0xB8, 147 write_reg(par, 0xB8,
148 tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6], tmp[7], 148 tmp[0], tmp[1], tmp[2], tmp[3], tmp[4], tmp[5], tmp[6],
149 tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13], tmp[14], tmp[15], 149 tmp[7], tmp[8], tmp[9], tmp[10], tmp[11], tmp[12], tmp[13],
150 tmp[16], tmp[17], tmp[18], tmp[19], tmp[20], tmp[21], tmp[22], tmp[23], 150 tmp[14], tmp[15], tmp[16], tmp[17], tmp[18], tmp[19], tmp[20],
151 tmp[24], tmp[25], tmp[26], tmp[27], tmp[28], tmp[29], tmp[30], tmp[31], 151 tmp[21], tmp[22], tmp[23], tmp[24], tmp[25], tmp[26], tmp[27],
152 tmp[32], tmp[33], tmp[34], tmp[35], tmp[36], tmp[37], tmp[38], tmp[39], 152 tmp[28], tmp[29], tmp[30], tmp[31], tmp[32], tmp[33], tmp[34],
153 tmp[40], tmp[41], tmp[42], tmp[43], tmp[44], tmp[45], tmp[46], tmp[47], 153 tmp[35], tmp[36], tmp[37], tmp[38], tmp[39], tmp[40], tmp[41],
154 tmp[48], tmp[49], tmp[50], tmp[51], tmp[52], tmp[53], tmp[54], tmp[55], 154 tmp[42], tmp[43], tmp[44], tmp[45], tmp[46], tmp[47], tmp[48],
155 tmp[56], tmp[57], tmp[58], tmp[59], tmp[60], tmp[61], tmp[62]); 155 tmp[49], tmp[50], tmp[51], tmp[52], tmp[53], tmp[54], tmp[55],
156 tmp[56], tmp[57], tmp[58], tmp[59], tmp[60], tmp[61],
157 tmp[62]);
156 158
157 return 0; 159 return 0;
158} 160}
@@ -160,7 +162,7 @@ static int set_gamma(struct fbtft_par *par, unsigned long *curves)
160static int blank(struct fbtft_par *par, bool on) 162static int blank(struct fbtft_par *par, bool on)
161{ 163{
162 fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n", 164 fbtft_par_dbg(DEBUG_BLANK, par, "%s(blank=%s)\n",
163 __func__, on ? "true" : "false"); 165 __func__, on ? "true" : "false");
164 if (on) 166 if (on)
165 write_reg(par, 0xAE); 167 write_reg(par, 0xAE);
166 else 168 else
diff --git a/drivers/staging/fbtft/fb_ssd1351.c b/drivers/staging/fbtft/fb_ssd1351.c
index 200aa9ba98f9..e62235d4d9e7 100644
--- a/drivers/staging/fbtft/fb_ssd1351.c
+++ b/drivers/staging/fbtft/fb_ssd1351.c
@@ -71,8 +71,8 @@ static int set_var(struct fbtft_par *par)
71 if (par->fbtftops.init_display != init_display) { 71 if (par->fbtftops.init_display != init_display) {
72 /* don't risk messing up register A0h */ 72 /* don't risk messing up register A0h */
73 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, 73 fbtft_par_dbg(DEBUG_INIT_DISPLAY, par,
74 "%s: skipping since custom init_display() is used\n", 74 "%s: skipping since custom init_display() is used\n",
75 __func__); 75 __func__);
76 return 0; 76 return 0;
77 } 77 }
78 78
@@ -117,7 +117,7 @@ static int set_var(struct fbtft_par *par)
117 * Setting of GS63 has to be > Setting of GS62 +1 117 * Setting of GS63 has to be > Setting of GS62 +1
118 * 118 *
119 */ 119 */
120static int set_gamma(struct fbtft_par *par, unsigned long *curves) 120static int set_gamma(struct fbtft_par *par, u32 *curves)
121{ 121{
122 unsigned long tmp[GAMMA_NUM * GAMMA_LEN]; 122 unsigned long tmp[GAMMA_NUM * GAMMA_LEN];
123 int i, acc = 0; 123 int i, acc = 0;
diff --git a/drivers/staging/fbtft/fb_st7735r.c b/drivers/staging/fbtft/fb_st7735r.c
index 710b74bbba97..24d17cdc71ab 100644
--- a/drivers/staging/fbtft/fb_st7735r.c
+++ b/drivers/staging/fbtft/fb_st7735r.c
@@ -143,7 +143,7 @@ static int set_var(struct fbtft_par *par)
143 * VRF0N VOS0N PK0N PK1N PK2N PK3N PK4N PK5N PK6N PK7N PK8N PK9N SELV0N SELV1N SELV62N SELV63N 143 * VRF0N VOS0N PK0N PK1N PK2N PK3N PK4N PK5N PK6N PK7N PK8N PK9N SELV0N SELV1N SELV62N SELV63N
144 */ 144 */
145#define CURVE(num, idx) curves[num * par->gamma.num_values + idx] 145#define CURVE(num, idx) curves[num * par->gamma.num_values + idx]
146static int set_gamma(struct fbtft_par *par, unsigned long *curves) 146static int set_gamma(struct fbtft_par *par, u32 *curves)
147{ 147{
148 int i, j; 148 int i, j;
149 149
diff --git a/drivers/staging/fbtft/fb_st7789v.c b/drivers/staging/fbtft/fb_st7789v.c
index 085e9872c46d..8935a97ec048 100644
--- a/drivers/staging/fbtft/fb_st7789v.c
+++ b/drivers/staging/fbtft/fb_st7789v.c
@@ -178,7 +178,7 @@ static int set_var(struct fbtft_par *par)
178 * 178 *
179 * Return: 0 on success, < 0 if error occurred. 179 * Return: 0 on success, < 0 if error occurred.
180 */ 180 */
181static int set_gamma(struct fbtft_par *par, unsigned long *curves) 181static int set_gamma(struct fbtft_par *par, u32 *curves)
182{ 182{
183 int i; 183 int i;
184 int j; 184 int j;
diff --git a/drivers/staging/fbtft/fb_tls8204.c b/drivers/staging/fbtft/fb_tls8204.c
index ea2ddacb9468..4302e822de3b 100644
--- a/drivers/staging/fbtft/fb_tls8204.c
+++ b/drivers/staging/fbtft/fb_tls8204.c
@@ -36,7 +36,7 @@
36#define DEFAULT_GAMMA "40" 36#define DEFAULT_GAMMA "40"
37 37
38static unsigned int bs = 4; 38static unsigned int bs = 4;
39module_param(bs, uint, 0); 39module_param(bs, uint, 0000);
40MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)"); 40MODULE_PARM_DESC(bs, "BS[2:0] Bias voltage level: 0-7 (default: 4)");
41 41
42static int init_display(struct fbtft_par *par) 42static int init_display(struct fbtft_par *par)
@@ -130,7 +130,7 @@ static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
130 return ret; 130 return ret;
131} 131}
132 132
133static int set_gamma(struct fbtft_par *par, unsigned long *curves) 133static int set_gamma(struct fbtft_par *par, u32 *curves)
134{ 134{
135 /* apply mask */ 135 /* apply mask */
136 curves[0] &= 0x7F; 136 curves[0] &= 0x7F;
diff --git a/drivers/staging/fbtft/fb_uc1611.c b/drivers/staging/fbtft/fb_uc1611.c
index b33b73f17da4..48e3b3fd9fed 100644
--- a/drivers/staging/fbtft/fb_uc1611.c
+++ b/drivers/staging/fbtft/fb_uc1611.c
@@ -42,30 +42,30 @@
42 42
43/* BR -> actual ratio: 0-3 -> 5, 10, 11, 13 */ 43/* BR -> actual ratio: 0-3 -> 5, 10, 11, 13 */
44static unsigned int ratio = 2; 44static unsigned int ratio = 2;
45module_param(ratio, uint, 0); 45module_param(ratio, uint, 0000);
46MODULE_PARM_DESC(ratio, "BR[1:0] Bias voltage ratio: 0-3 (default: 2)"); 46MODULE_PARM_DESC(ratio, "BR[1:0] Bias voltage ratio: 0-3 (default: 2)");
47 47
48static unsigned int gain = 3; 48static unsigned int gain = 3;
49module_param(gain, uint, 0); 49module_param(gain, uint, 0000);
50MODULE_PARM_DESC(gain, "GN[1:0] Bias voltage gain: 0-3 (default: 3)"); 50MODULE_PARM_DESC(gain, "GN[1:0] Bias voltage gain: 0-3 (default: 3)");
51 51
52static unsigned int pot = 16; 52static unsigned int pot = 16;
53module_param(pot, uint, 0); 53module_param(pot, uint, 0000);
54MODULE_PARM_DESC(pot, "PM[6:0] Bias voltage pot.: 0-63 (default: 16)"); 54MODULE_PARM_DESC(pot, "PM[6:0] Bias voltage pot.: 0-63 (default: 16)");
55 55
56/* TC -> % compensation per deg C: 0-3 -> -.05, -.10, -.015, -.20 */ 56/* TC -> % compensation per deg C: 0-3 -> -.05, -.10, -.015, -.20 */
57static unsigned int temp; 57static unsigned int temp;
58module_param(temp, uint, 0); 58module_param(temp, uint, 0000);
59MODULE_PARM_DESC(temp, "TC[1:0] Temperature compensation: 0-3 (default: 0)"); 59MODULE_PARM_DESC(temp, "TC[1:0] Temperature compensation: 0-3 (default: 0)");
60 60
61/* PC[1:0] -> LCD capacitance: 0-3 -> <20nF, 20-28 nF, 29-40 nF, 40-56 nF */ 61/* PC[1:0] -> LCD capacitance: 0-3 -> <20nF, 20-28 nF, 29-40 nF, 40-56 nF */
62static unsigned int load = 1; 62static unsigned int load = 1;
63module_param(load, uint, 0); 63module_param(load, uint, 0000);
64MODULE_PARM_DESC(load, "PC[1:0] Panel Loading: 0-3 (default: 1)"); 64MODULE_PARM_DESC(load, "PC[1:0] Panel Loading: 0-3 (default: 1)");
65 65
66/* PC[3:2] -> V_LCD: 0, 1, 3 -> ext., int. with ratio = 5, int. standard */ 66/* PC[3:2] -> V_LCD: 0, 1, 3 -> ext., int. with ratio = 5, int. standard */
67static unsigned int pump = 3; 67static unsigned int pump = 3;
68module_param(pump, uint, 0); 68module_param(pump, uint, 0000);
69MODULE_PARM_DESC(pump, "PC[3:2] Pump control: 0,1,3 (default: 3)"); 69MODULE_PARM_DESC(pump, "PC[3:2] Pump control: 0,1,3 (default: 3)");
70 70
71static int init_display(struct fbtft_par *par) 71static int init_display(struct fbtft_par *par)
diff --git a/drivers/staging/fbtft/fb_watterott.c b/drivers/staging/fbtft/fb_watterott.c
index a52e28a48825..429304546b44 100644
--- a/drivers/staging/fbtft/fb_watterott.c
+++ b/drivers/staging/fbtft/fb_watterott.c
@@ -40,7 +40,7 @@
40#define COLOR_RGB565 16 40#define COLOR_RGB565 16
41 41
42static short mode = 565; 42static short mode = 565;
43module_param(mode, short, 0); 43module_param(mode, short, 0000);
44MODULE_PARM_DESC(mode, "RGB color transfer mode: 332, 565 (default)"); 44MODULE_PARM_DESC(mode, "RGB color transfer mode: 332, 565 (default)");
45 45
46static void write_reg8_bus8(struct fbtft_par *par, int len, ...) 46static void write_reg8_bus8(struct fbtft_par *par, int len, ...)
diff --git a/drivers/staging/fbtft/fbtft-core.c b/drivers/staging/fbtft/fbtft-core.c
index bbe89c9c4fb9..7c8af29cdb75 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -32,7 +32,6 @@
32#include <linux/backlight.h> 32#include <linux/backlight.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/spinlock.h> 34#include <linux/spinlock.h>
35#include <linux/dma-mapping.h>
36#include <linux/of.h> 35#include <linux/of.h>
37#include <linux/of_gpio.h> 36#include <linux/of_gpio.h>
38#include <video/mipi_display.h> 37#include <video/mipi_display.h>
@@ -41,15 +40,9 @@
41#include "internal.h" 40#include "internal.h"
42 41
43static unsigned long debug; 42static unsigned long debug;
44module_param(debug, ulong, 0); 43module_param(debug, ulong, 0000);
45MODULE_PARM_DESC(debug, "override device debug level"); 44MODULE_PARM_DESC(debug, "override device debug level");
46 45
47#ifdef CONFIG_HAS_DMA
48static bool dma = true;
49module_param(dma, bool, 0);
50MODULE_PARM_DESC(dma, "Use DMA buffer");
51#endif
52
53void fbtft_dbg_hex(const struct device *dev, int groupsize, 46void fbtft_dbg_hex(const struct device *dev, int groupsize,
54 void *buf, size_t len, const char *fmt, ...) 47 void *buf, size_t len, const char *fmt, ...)
55{ 48{
@@ -337,10 +330,10 @@ static void fbtft_reset(struct fbtft_par *par)
337 if (par->gpio.reset == -1) 330 if (par->gpio.reset == -1)
338 return; 331 return;
339 fbtft_par_dbg(DEBUG_RESET, par, "%s()\n", __func__); 332 fbtft_par_dbg(DEBUG_RESET, par, "%s()\n", __func__);
340 gpio_set_value(par->gpio.reset, 0); 333 gpio_set_value_cansleep(par->gpio.reset, 0);
341 udelay(20); 334 usleep_range(20, 40);
342 gpio_set_value(par->gpio.reset, 1); 335 gpio_set_value_cansleep(par->gpio.reset, 1);
343 mdelay(120); 336 msleep(120);
344} 337}
345 338
346static void fbtft_update_display(struct fbtft_par *par, unsigned int start_line, 339static void fbtft_update_display(struct fbtft_par *par, unsigned int start_line,
@@ -668,7 +661,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
668 int vmem_size, i; 661 int vmem_size, i;
669 s16 *init_sequence = display->init_sequence; 662 s16 *init_sequence = display->init_sequence;
670 char *gamma = display->gamma; 663 char *gamma = display->gamma;
671 unsigned long *gamma_curves = NULL; 664 u32 *gamma_curves = NULL;
672 665
673 /* sanity check */ 666 /* sanity check */
674 if (display->gamma_num * display->gamma_len > 667 if (display->gamma_num * display->gamma_len >
@@ -836,17 +829,7 @@ struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
836#endif 829#endif
837 830
838 if (txbuflen > 0) { 831 if (txbuflen > 0) {
839#ifdef CONFIG_HAS_DMA 832 txbuf = devm_kzalloc(par->info->device, txbuflen, GFP_KERNEL);
840 if (dma) {
841 dev->coherent_dma_mask = ~0;
842 txbuf = dmam_alloc_coherent(dev, txbuflen,
843 &par->txbuf.dma, GFP_DMA);
844 } else
845#endif
846 {
847 txbuf = devm_kzalloc(par->info->device,
848 txbuflen, GFP_KERNEL);
849 }
850 if (!txbuf) 833 if (!txbuf)
851 goto alloc_fail; 834 goto alloc_fail;
852 par->txbuf.buf = txbuf; 835 par->txbuf.buf = txbuf;
@@ -975,8 +958,7 @@ int fbtft_register_framebuffer(struct fb_info *fb_info)
975 fbtft_sysfs_init(par); 958 fbtft_sysfs_init(par);
976 959
977 if (par->txbuf.buf) 960 if (par->txbuf.buf)
978 sprintf(text1, ", %zu KiB %sbuffer memory", 961 sprintf(text1, ", %zu KiB buffer memory", par->txbuf.len >> 10);
979 par->txbuf.len >> 10, par->txbuf.dma ? "DMA " : "");
980 if (spi) 962 if (spi)
981 sprintf(text2, ", spi%d.%d at %d MHz", spi->master->bus_num, 963 sprintf(text2, ", spi%d.%d at %d MHz", spi->master->bus_num,
982 spi->chip_select, spi->max_speed_hz / 1000000); 964 spi->chip_select, spi->max_speed_hz / 1000000);
diff --git a/drivers/staging/fbtft/fbtft-io.c b/drivers/staging/fbtft/fbtft-io.c
index 4dcea2e0b3ae..d86840548b74 100644
--- a/drivers/staging/fbtft/fbtft-io.c
+++ b/drivers/staging/fbtft/fbtft-io.c
@@ -22,10 +22,6 @@ int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len)
22 } 22 }
23 23
24 spi_message_init(&m); 24 spi_message_init(&m);
25 if (par->txbuf.dma && buf == par->txbuf.buf) {
26 t.tx_dma = par->txbuf.dma;
27 m.is_dma_mapped = 1;
28 }
29 spi_message_add_tail(&t, &m); 25 spi_message_add_tail(&t, &m);
30 return spi_sync(par->spi, &m); 26 return spi_sync(par->spi, &m);
31} 27}
diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c
index 8d8bd12b90a1..6b6fbaa794f4 100644
--- a/drivers/staging/fbtft/fbtft-sysfs.c
+++ b/drivers/staging/fbtft/fbtft-sysfs.c
@@ -4,7 +4,6 @@
4static int get_next_ulong(char **str_p, unsigned long *val, char *sep, int base) 4static int get_next_ulong(char **str_p, unsigned long *val, char *sep, int base)
5{ 5{
6 char *p_val; 6 char *p_val;
7 int ret;
8 7
9 if (!str_p || !(*str_p)) 8 if (!str_p || !(*str_p))
10 return -EINVAL; 9 return -EINVAL;
@@ -14,14 +13,10 @@ static int get_next_ulong(char **str_p, unsigned long *val, char *sep, int base)
14 if (!p_val) 13 if (!p_val)
15 return -EINVAL; 14 return -EINVAL;
16 15
17 ret = kstrtoul(p_val, base, val); 16 return kstrtoul(p_val, base, val);
18 if (ret)
19 return -EINVAL;
20
21 return 0;
22} 17}
23 18
24int fbtft_gamma_parse_str(struct fbtft_par *par, unsigned long *curves, 19int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
25 const char *str, int size) 20 const char *str, int size)
26{ 21{
27 char *str_p, *curve_p = NULL; 22 char *str_p, *curve_p = NULL;
@@ -94,7 +89,7 @@ out:
94} 89}
95 90
96static ssize_t 91static ssize_t
97sprintf_gamma(struct fbtft_par *par, unsigned long *curves, char *buf) 92sprintf_gamma(struct fbtft_par *par, u32 *curves, char *buf)
98{ 93{
99 ssize_t len = 0; 94 ssize_t len = 0;
100 unsigned int i, j; 95 unsigned int i, j;
@@ -103,7 +98,7 @@ sprintf_gamma(struct fbtft_par *par, unsigned long *curves, char *buf)
103 for (i = 0; i < par->gamma.num_curves; i++) { 98 for (i = 0; i < par->gamma.num_curves; i++) {
104 for (j = 0; j < par->gamma.num_values; j++) 99 for (j = 0; j < par->gamma.num_values; j++)
105 len += scnprintf(&buf[len], PAGE_SIZE, 100 len += scnprintf(&buf[len], PAGE_SIZE,
106 "%04lx ", curves[i * par->gamma.num_values + j]); 101 "%04x ", curves[i * par->gamma.num_values + j]);
107 buf[len - 1] = '\n'; 102 buf[len - 1] = '\n';
108 } 103 }
109 mutex_unlock(&par->gamma.lock); 104 mutex_unlock(&par->gamma.lock);
@@ -117,7 +112,7 @@ static ssize_t store_gamma_curve(struct device *device,
117{ 112{
118 struct fb_info *fb_info = dev_get_drvdata(device); 113 struct fb_info *fb_info = dev_get_drvdata(device);
119 struct fbtft_par *par = fb_info->par; 114 struct fbtft_par *par = fb_info->par;
120 unsigned long tmp_curves[FBTFT_GAMMA_MAX_VALUES_TOTAL]; 115 u32 tmp_curves[FBTFT_GAMMA_MAX_VALUES_TOTAL];
121 int ret; 116 int ret;
122 117
123 ret = fbtft_gamma_parse_str(par, tmp_curves, buf, count); 118 ret = fbtft_gamma_parse_str(par, tmp_curves, buf, count);
diff --git a/drivers/staging/fbtft/fbtft.h b/drivers/staging/fbtft/fbtft.h
index aacdde92cc2e..44cf94d160d4 100644
--- a/drivers/staging/fbtft/fbtft.h
+++ b/drivers/staging/fbtft/fbtft.h
@@ -92,7 +92,7 @@ struct fbtft_ops {
92 void (*unregister_backlight)(struct fbtft_par *par); 92 void (*unregister_backlight)(struct fbtft_par *par);
93 93
94 int (*set_var)(struct fbtft_par *par); 94 int (*set_var)(struct fbtft_par *par);
95 int (*set_gamma)(struct fbtft_par *par, unsigned long *curves); 95 int (*set_gamma)(struct fbtft_par *par, u32 *curves);
96}; 96};
97 97
98/** 98/**
@@ -209,7 +209,6 @@ struct fbtft_par {
209 u32 pseudo_palette[16]; 209 u32 pseudo_palette[16];
210 struct { 210 struct {
211 void *buf; 211 void *buf;
212 dma_addr_t dma;
213 size_t len; 212 size_t len;
214 } txbuf; 213 } txbuf;
215 u8 *buf; 214 u8 *buf;
@@ -232,7 +231,7 @@ struct fbtft_par {
232 s16 *init_sequence; 231 s16 *init_sequence;
233 struct { 232 struct {
234 struct mutex lock; 233 struct mutex lock;
235 unsigned long *curves; 234 u32 *curves;
236 int num_values; 235 int num_values;
237 int num_curves; 236 int num_curves;
238 } gamma; 237 } gamma;
diff --git a/drivers/staging/fbtft/fbtft_device.c b/drivers/staging/fbtft/fbtft_device.c
index de46f8d988d2..9ffb9cecc465 100644
--- a/drivers/staging/fbtft/fbtft_device.c
+++ b/drivers/staging/fbtft/fbtft_device.c
@@ -29,85 +29,85 @@ static struct spi_device *spi_device;
29static struct platform_device *p_device; 29static struct platform_device *p_device;
30 30
31static char *name; 31static char *name;
32module_param(name, charp, 0); 32module_param(name, charp, 0000);
33MODULE_PARM_DESC(name, "Devicename (required). name=list => list all supported devices."); 33MODULE_PARM_DESC(name, "Devicename (required). name=list => list all supported devices.");
34 34
35static unsigned int rotate; 35static unsigned int rotate;
36module_param(rotate, uint, 0); 36module_param(rotate, uint, 0000);
37MODULE_PARM_DESC(rotate, 37MODULE_PARM_DESC(rotate,
38"Angle to rotate display counter clockwise: 0, 90, 180, 270"); 38"Angle to rotate display counter clockwise: 0, 90, 180, 270");
39 39
40static unsigned int busnum; 40static unsigned int busnum;
41module_param(busnum, uint, 0); 41module_param(busnum, uint, 0000);
42MODULE_PARM_DESC(busnum, "SPI bus number (default=0)"); 42MODULE_PARM_DESC(busnum, "SPI bus number (default=0)");
43 43
44static unsigned int cs; 44static unsigned int cs;
45module_param(cs, uint, 0); 45module_param(cs, uint, 0000);
46MODULE_PARM_DESC(cs, "SPI chip select (default=0)"); 46MODULE_PARM_DESC(cs, "SPI chip select (default=0)");
47 47
48static unsigned int speed; 48static unsigned int speed;
49module_param(speed, uint, 0); 49module_param(speed, uint, 0000);
50MODULE_PARM_DESC(speed, "SPI speed (override device default)"); 50MODULE_PARM_DESC(speed, "SPI speed (override device default)");
51 51
52static int mode = -1; 52static int mode = -1;
53module_param(mode, int, 0); 53module_param(mode, int, 0000);
54MODULE_PARM_DESC(mode, "SPI mode (override device default)"); 54MODULE_PARM_DESC(mode, "SPI mode (override device default)");
55 55
56static char *gpios; 56static char *gpios;
57module_param(gpios, charp, 0); 57module_param(gpios, charp, 0000);
58MODULE_PARM_DESC(gpios, 58MODULE_PARM_DESC(gpios,
59"List of gpios. Comma separated with the form: reset:23,dc:24 (when overriding the default, all gpios must be specified)"); 59"List of gpios. Comma separated with the form: reset:23,dc:24 (when overriding the default, all gpios must be specified)");
60 60
61static unsigned int fps; 61static unsigned int fps;
62module_param(fps, uint, 0); 62module_param(fps, uint, 0000);
63MODULE_PARM_DESC(fps, "Frames per second (override driver default)"); 63MODULE_PARM_DESC(fps, "Frames per second (override driver default)");
64 64
65static char *gamma; 65static char *gamma;
66module_param(gamma, charp, 0); 66module_param(gamma, charp, 0000);
67MODULE_PARM_DESC(gamma, 67MODULE_PARM_DESC(gamma,
68"String representation of Gamma Curve(s). Driver specific."); 68"String representation of Gamma Curve(s). Driver specific.");
69 69
70static int txbuflen; 70static int txbuflen;
71module_param(txbuflen, int, 0); 71module_param(txbuflen, int, 0000);
72MODULE_PARM_DESC(txbuflen, "txbuflen (override driver default)"); 72MODULE_PARM_DESC(txbuflen, "txbuflen (override driver default)");
73 73
74static int bgr = -1; 74static int bgr = -1;
75module_param(bgr, int, 0); 75module_param(bgr, int, 0000);
76MODULE_PARM_DESC(bgr, 76MODULE_PARM_DESC(bgr,
77"BGR bit (supported by some drivers)."); 77"BGR bit (supported by some drivers).");
78 78
79static unsigned int startbyte; 79static unsigned int startbyte;
80module_param(startbyte, uint, 0); 80module_param(startbyte, uint, 0000);
81MODULE_PARM_DESC(startbyte, "Sets the Start byte used by some SPI displays."); 81MODULE_PARM_DESC(startbyte, "Sets the Start byte used by some SPI displays.");
82 82
83static bool custom; 83static bool custom;
84module_param(custom, bool, 0); 84module_param(custom, bool, 0000);
85MODULE_PARM_DESC(custom, "Add a custom display device. Use speed= argument to make it a SPI device, else platform_device"); 85MODULE_PARM_DESC(custom, "Add a custom display device. Use speed= argument to make it a SPI device, else platform_device");
86 86
87static unsigned int width; 87static unsigned int width;
88module_param(width, uint, 0); 88module_param(width, uint, 0000);
89MODULE_PARM_DESC(width, "Display width, used with the custom argument"); 89MODULE_PARM_DESC(width, "Display width, used with the custom argument");
90 90
91static unsigned int height; 91static unsigned int height;
92module_param(height, uint, 0); 92module_param(height, uint, 0000);
93MODULE_PARM_DESC(height, "Display height, used with the custom argument"); 93MODULE_PARM_DESC(height, "Display height, used with the custom argument");
94 94
95static unsigned int buswidth = 8; 95static unsigned int buswidth = 8;
96module_param(buswidth, uint, 0); 96module_param(buswidth, uint, 0000);
97MODULE_PARM_DESC(buswidth, "Display bus width, used with the custom argument"); 97MODULE_PARM_DESC(buswidth, "Display bus width, used with the custom argument");
98 98
99static s16 init[FBTFT_MAX_INIT_SEQUENCE]; 99static s16 init[FBTFT_MAX_INIT_SEQUENCE];
100static int init_num; 100static int init_num;
101module_param_array(init, short, &init_num, 0); 101module_param_array(init, short, &init_num, 0000);
102MODULE_PARM_DESC(init, "Init sequence, used with the custom argument"); 102MODULE_PARM_DESC(init, "Init sequence, used with the custom argument");
103 103
104static unsigned long debug; 104static unsigned long debug;
105module_param(debug, ulong, 0); 105module_param(debug, ulong, 0000);
106MODULE_PARM_DESC(debug, 106MODULE_PARM_DESC(debug,
107"level: 0-7 (the remaining 29 bits is for advanced usage)"); 107"level: 0-7 (the remaining 29 bits is for advanced usage)");
108 108
109static unsigned int verbose = 3; 109static unsigned int verbose = 3;
110module_param(verbose, uint, 0); 110module_param(verbose, uint, 0000);
111MODULE_PARM_DESC(verbose, 111MODULE_PARM_DESC(verbose,
112"0 silent, >0 show gpios, >1 show devices, >2 show devices before (default=3)"); 112"0 silent, >0 show gpios, >1 show devices, >2 show devices before (default=3)");
113 113
diff --git a/drivers/staging/fbtft/flexfb.c b/drivers/staging/fbtft/flexfb.c
index ded10718712b..af8422e18780 100644
--- a/drivers/staging/fbtft/flexfb.c
+++ b/drivers/staging/fbtft/flexfb.c
@@ -27,40 +27,40 @@
27#define DRVNAME "flexfb" 27#define DRVNAME "flexfb"
28 28
29static char *chip; 29static char *chip;
30module_param(chip, charp, 0); 30module_param(chip, charp, 0000);
31MODULE_PARM_DESC(chip, "LCD controller"); 31MODULE_PARM_DESC(chip, "LCD controller");
32 32
33static unsigned int width; 33static unsigned int width;
34module_param(width, uint, 0); 34module_param(width, uint, 0000);
35MODULE_PARM_DESC(width, "Display width"); 35MODULE_PARM_DESC(width, "Display width");
36 36
37static unsigned int height; 37static unsigned int height;
38module_param(height, uint, 0); 38module_param(height, uint, 0000);
39MODULE_PARM_DESC(height, "Display height"); 39MODULE_PARM_DESC(height, "Display height");
40 40
41static s16 init[512]; 41static s16 init[512];
42static int init_num; 42static int init_num;
43module_param_array(init, short, &init_num, 0); 43module_param_array(init, short, &init_num, 0000);
44MODULE_PARM_DESC(init, "Init sequence"); 44MODULE_PARM_DESC(init, "Init sequence");
45 45
46static unsigned int setaddrwin; 46static unsigned int setaddrwin;
47module_param(setaddrwin, uint, 0); 47module_param(setaddrwin, uint, 0000);
48MODULE_PARM_DESC(setaddrwin, "Which set_addr_win() implementation to use"); 48MODULE_PARM_DESC(setaddrwin, "Which set_addr_win() implementation to use");
49 49
50static unsigned int buswidth = 8; 50static unsigned int buswidth = 8;
51module_param(buswidth, uint, 0); 51module_param(buswidth, uint, 0000);
52MODULE_PARM_DESC(buswidth, "Width of databus (default: 8)"); 52MODULE_PARM_DESC(buswidth, "Width of databus (default: 8)");
53 53
54static unsigned int regwidth = 8; 54static unsigned int regwidth = 8;
55module_param(regwidth, uint, 0); 55module_param(regwidth, uint, 0000);
56MODULE_PARM_DESC(regwidth, "Width of controller register (default: 8)"); 56MODULE_PARM_DESC(regwidth, "Width of controller register (default: 8)");
57 57
58static bool nobacklight; 58static bool nobacklight;
59module_param(nobacklight, bool, 0); 59module_param(nobacklight, bool, 0000);
60MODULE_PARM_DESC(nobacklight, "Turn off backlight functionality."); 60MODULE_PARM_DESC(nobacklight, "Turn off backlight functionality.");
61 61
62static bool latched; 62static bool latched;
63module_param(latched, bool, 0); 63module_param(latched, bool, 0000);
64MODULE_PARM_DESC(latched, "Use with latched 16-bit databus"); 64MODULE_PARM_DESC(latched, "Use with latched 16-bit databus");
65 65
66static s16 *initp; 66static s16 *initp;
@@ -418,22 +418,6 @@ static const struct flexfb_lcd_controller flexfb_chip_table[] = {
418 .init_seq_sz = ARRAY_SIZE(ili9225_init), 418 .init_seq_sz = ARRAY_SIZE(ili9225_init),
419 }, 419 },
420 { 420 {
421 .name = "ili9225",
422 .width = 176,
423 .height = 220,
424 .regwidth = 16,
425 .init_seq = ili9225_init,
426 .init_seq_sz = ARRAY_SIZE(ili9225_init),
427 },
428 {
429 .name = "ili9225",
430 .width = 176,
431 .height = 220,
432 .regwidth = 16,
433 .init_seq = ili9225_init,
434 .init_seq_sz = ARRAY_SIZE(ili9225_init),
435 },
436 {
437 .name = "ili9320", 421 .name = "ili9320",
438 .width = 240, 422 .width = 240,
439 .height = 320, 423 .height = 320,
diff --git a/drivers/staging/fbtft/internal.h b/drivers/staging/fbtft/internal.h
index eea0ec5ff4d3..25b9bf6f54bb 100644
--- a/drivers/staging/fbtft/internal.h
+++ b/drivers/staging/fbtft/internal.h
@@ -19,7 +19,7 @@
19void fbtft_sysfs_init(struct fbtft_par *par); 19void fbtft_sysfs_init(struct fbtft_par *par);
20void fbtft_sysfs_exit(struct fbtft_par *par); 20void fbtft_sysfs_exit(struct fbtft_par *par);
21void fbtft_expand_debug_value(unsigned long *debug); 21void fbtft_expand_debug_value(unsigned long *debug);
22int fbtft_gamma_parse_str(struct fbtft_par *par, unsigned long *curves, 22int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
23 const char *str, int size); 23 const char *str, int size);
24 24
25#endif /* __LINUX_FBTFT_INTERNAL_H */ 25#endif /* __LINUX_FBTFT_INTERNAL_H */
diff --git a/drivers/staging/fsl-mc/bus/dpbp-cmd.h b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
index 7d86539b5414..8aa65452c872 100644
--- a/drivers/staging/fsl-mc/bus/dpbp-cmd.h
+++ b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
@@ -45,8 +45,6 @@
45/* Command IDs */ 45/* Command IDs */
46#define DPBP_CMDID_CLOSE DPBP_CMD(0x800) 46#define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
47#define DPBP_CMDID_OPEN DPBP_CMD(0x804) 47#define DPBP_CMDID_OPEN DPBP_CMD(0x804)
48#define DPBP_CMDID_CREATE DPBP_CMD(0x904)
49#define DPBP_CMDID_DESTROY DPBP_CMD(0x984)
50#define DPBP_CMDID_GET_API_VERSION DPBP_CMD(0xa04) 48#define DPBP_CMDID_GET_API_VERSION DPBP_CMD(0xa04)
51 49
52#define DPBP_CMDID_ENABLE DPBP_CMD(0x002) 50#define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
@@ -55,18 +53,6 @@
55#define DPBP_CMDID_RESET DPBP_CMD(0x005) 53#define DPBP_CMDID_RESET DPBP_CMD(0x005)
56#define DPBP_CMDID_IS_ENABLED DPBP_CMD(0x006) 54#define DPBP_CMDID_IS_ENABLED DPBP_CMD(0x006)
57 55
58#define DPBP_CMDID_SET_IRQ DPBP_CMD(0x010)
59#define DPBP_CMDID_GET_IRQ DPBP_CMD(0x011)
60#define DPBP_CMDID_SET_IRQ_ENABLE DPBP_CMD(0x012)
61#define DPBP_CMDID_GET_IRQ_ENABLE DPBP_CMD(0x013)
62#define DPBP_CMDID_SET_IRQ_MASK DPBP_CMD(0x014)
63#define DPBP_CMDID_GET_IRQ_MASK DPBP_CMD(0x015)
64#define DPBP_CMDID_GET_IRQ_STATUS DPBP_CMD(0x016)
65#define DPBP_CMDID_CLEAR_IRQ_STATUS DPBP_CMD(0x017)
66
67#define DPBP_CMDID_SET_NOTIFICATIONS DPBP_CMD(0x01b0)
68#define DPBP_CMDID_GET_NOTIFICATIONS DPBP_CMD(0x01b1)
69
70struct dpbp_cmd_open { 56struct dpbp_cmd_open {
71 __le32 dpbp_id; 57 __le32 dpbp_id;
72}; 58};
@@ -81,76 +67,6 @@ struct dpbp_rsp_is_enabled {
81 u8 enabled; 67 u8 enabled;
82}; 68};
83 69
84struct dpbp_cmd_set_irq {
85 /* cmd word 0 */
86 u8 irq_index;
87 u8 pad[3];
88 __le32 irq_val;
89 /* cmd word 1 */
90 __le64 irq_addr;
91 /* cmd word 2 */
92 __le32 irq_num;
93};
94
95struct dpbp_cmd_get_irq {
96 __le32 pad;
97 u8 irq_index;
98};
99
100struct dpbp_rsp_get_irq {
101 /* response word 0 */
102 __le32 irq_val;
103 __le32 pad;
104 /* response word 1 */
105 __le64 irq_addr;
106 /* response word 2 */
107 __le32 irq_num;
108 __le32 type;
109};
110
111struct dpbp_cmd_set_irq_enable {
112 u8 enable;
113 u8 pad[3];
114 u8 irq_index;
115};
116
117struct dpbp_cmd_get_irq_enable {
118 __le32 pad;
119 u8 irq_index;
120};
121
122struct dpbp_rsp_get_irq_enable {
123 u8 enabled;
124};
125
126struct dpbp_cmd_set_irq_mask {
127 __le32 mask;
128 u8 irq_index;
129};
130
131struct dpbp_cmd_get_irq_mask {
132 __le32 pad;
133 u8 irq_index;
134};
135
136struct dpbp_rsp_get_irq_mask {
137 __le32 mask;
138};
139
140struct dpbp_cmd_get_irq_status {
141 __le32 status;
142 u8 irq_index;
143};
144
145struct dpbp_rsp_get_irq_status {
146 __le32 status;
147};
148
149struct dpbp_cmd_clear_irq_status {
150 __le32 status;
151 u8 irq_index;
152};
153
154struct dpbp_rsp_get_attributes { 70struct dpbp_rsp_get_attributes {
155 /* response word 0 */ 71 /* response word 0 */
156 __le16 pad; 72 __le16 pad;
@@ -161,36 +77,4 @@ struct dpbp_rsp_get_attributes {
161 __le16 version_minor; 77 __le16 version_minor;
162}; 78};
163 79
164struct dpbp_cmd_set_notifications {
165 /* cmd word 0 */
166 __le32 depletion_entry;
167 __le32 depletion_exit;
168 /* cmd word 1 */
169 __le32 surplus_entry;
170 __le32 surplus_exit;
171 /* cmd word 2 */
172 __le16 options;
173 __le16 pad[3];
174 /* cmd word 3 */
175 __le64 message_ctx;
176 /* cmd word 4 */
177 __le64 message_iova;
178};
179
180struct dpbp_rsp_get_notifications {
181 /* response word 0 */
182 __le32 depletion_entry;
183 __le32 depletion_exit;
184 /* response word 1 */
185 __le32 surplus_entry;
186 __le32 surplus_exit;
187 /* response word 2 */
188 __le16 options;
189 __le16 pad[3];
190 /* response word 3 */
191 __le64 message_ctx;
192 /* response word 4 */
193 __le64 message_iova;
194};
195
196#endif /* _FSL_DPBP_CMD_H */ 80#endif /* _FSL_DPBP_CMD_H */
diff --git a/drivers/staging/fsl-mc/bus/dpbp.c b/drivers/staging/fsl-mc/bus/dpbp.c
index cf4782f6a049..d9e450a6bad6 100644
--- a/drivers/staging/fsl-mc/bus/dpbp.c
+++ b/drivers/staging/fsl-mc/bus/dpbp.c
@@ -106,77 +106,6 @@ int dpbp_close(struct fsl_mc_io *mc_io,
106EXPORT_SYMBOL(dpbp_close); 106EXPORT_SYMBOL(dpbp_close);
107 107
108/** 108/**
109 * dpbp_create() - Create the DPBP object.
110 * @mc_io: Pointer to MC portal's I/O object
111 * @dprc_token: Parent container token; '0' for default container
112 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
113 * @cfg: Configuration structure
114 * @obj_id: Returned object id; use in subsequent API calls
115 *
116 * Create the DPBP object, allocate required resources and
117 * perform required initialization.
118 *
119 * This function accepts an authentication token of a parent
120 * container that this object should be assigned to and returns
121 * an object id. This object_id will be used in all subsequent calls to
122 * this specific object.
123 *
124 * Return: '0' on Success; Error code otherwise.
125 */
126int dpbp_create(struct fsl_mc_io *mc_io,
127 u16 dprc_token,
128 u32 cmd_flags,
129 const struct dpbp_cfg *cfg,
130 u32 *obj_id)
131{
132 struct mc_command cmd = { 0 };
133 int err;
134
135 (void)(cfg); /* unused */
136
137 /* prepare command */
138 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
139 cmd_flags, dprc_token);
140
141 /* send command to mc*/
142 err = mc_send_command(mc_io, &cmd);
143 if (err)
144 return err;
145
146 /* retrieve response parameters */
147 *obj_id = mc_cmd_read_object_id(&cmd);
148
149 return 0;
150}
151
152/**
153 * dpbp_destroy() - Destroy the DPBP object and release all its resources.
154 * @mc_io: Pointer to MC portal's I/O object
155 * @dprc_token: Parent container token; '0' for default container
156 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
157 * @obj_id: ID of DPBP object
158 *
159 * Return: '0' on Success; error code otherwise.
160 */
161int dpbp_destroy(struct fsl_mc_io *mc_io,
162 u16 dprc_token,
163 u32 cmd_flags,
164 u32 obj_id)
165{
166 struct dpbp_cmd_destroy *cmd_params;
167 struct mc_command cmd = { 0 };
168
169 /* prepare command */
170 cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
171 cmd_flags, dprc_token);
172 cmd_params = (struct dpbp_cmd_destroy *)cmd.params;
173 cmd_params->object_id = cpu_to_le32(obj_id);
174
175 /* send command to mc*/
176 return mc_send_command(mc_io, &cmd);
177}
178
179/**
180 * dpbp_enable() - Enable the DPBP. 109 * dpbp_enable() - Enable the DPBP.
181 * @mc_io: Pointer to MC portal's I/O object 110 * @mc_io: Pointer to MC portal's I/O object
182 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 111 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -254,6 +183,7 @@ int dpbp_is_enabled(struct fsl_mc_io *mc_io,
254 183
255 return 0; 184 return 0;
256} 185}
186EXPORT_SYMBOL(dpbp_is_enabled);
257 187
258/** 188/**
259 * dpbp_reset() - Reset the DPBP, returns the object to initial state. 189 * dpbp_reset() - Reset the DPBP, returns the object to initial state.
@@ -276,310 +206,7 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
276 /* send command to mc*/ 206 /* send command to mc*/
277 return mc_send_command(mc_io, &cmd); 207 return mc_send_command(mc_io, &cmd);
278} 208}
279 209EXPORT_SYMBOL(dpbp_reset);
280/**
281 * dpbp_set_irq() - Set IRQ information for the DPBP to trigger an interrupt.
282 * @mc_io: Pointer to MC portal's I/O object
283 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
284 * @token: Token of DPBP object
285 * @irq_index: Identifies the interrupt index to configure
286 * @irq_cfg: IRQ configuration
287 *
288 * Return: '0' on Success; Error code otherwise.
289 */
290int dpbp_set_irq(struct fsl_mc_io *mc_io,
291 u32 cmd_flags,
292 u16 token,
293 u8 irq_index,
294 struct dpbp_irq_cfg *irq_cfg)
295{
296 struct mc_command cmd = { 0 };
297 struct dpbp_cmd_set_irq *cmd_params;
298
299 /* prepare command */
300 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
301 cmd_flags, token);
302 cmd_params = (struct dpbp_cmd_set_irq *)cmd.params;
303 cmd_params->irq_index = irq_index;
304 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
305 cmd_params->irq_addr = cpu_to_le64(irq_cfg->addr);
306 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
307
308 /* send command to mc*/
309 return mc_send_command(mc_io, &cmd);
310}
311
312/**
313 * dpbp_get_irq() - Get IRQ information from the DPBP.
314 * @mc_io: Pointer to MC portal's I/O object
315 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
316 * @token: Token of DPBP object
317 * @irq_index: The interrupt index to configure
318 * @type: Interrupt type: 0 represents message interrupt
319 * type (both irq_addr and irq_val are valid)
320 * @irq_cfg: IRQ attributes
321 *
322 * Return: '0' on Success; Error code otherwise.
323 */
324int dpbp_get_irq(struct fsl_mc_io *mc_io,
325 u32 cmd_flags,
326 u16 token,
327 u8 irq_index,
328 int *type,
329 struct dpbp_irq_cfg *irq_cfg)
330{
331 struct mc_command cmd = { 0 };
332 struct dpbp_cmd_get_irq *cmd_params;
333 struct dpbp_rsp_get_irq *rsp_params;
334 int err;
335
336 /* prepare command */
337 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
338 cmd_flags, token);
339 cmd_params = (struct dpbp_cmd_get_irq *)cmd.params;
340 cmd_params->irq_index = irq_index;
341
342 /* send command to mc*/
343 err = mc_send_command(mc_io, &cmd);
344 if (err)
345 return err;
346
347 /* retrieve response parameters */
348 rsp_params = (struct dpbp_rsp_get_irq *)cmd.params;
349 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
350 irq_cfg->addr = le64_to_cpu(rsp_params->irq_addr);
351 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
352 *type = le32_to_cpu(rsp_params->type);
353
354 return 0;
355}
356
357/**
358 * dpbp_set_irq_enable() - Set overall interrupt state.
359 * @mc_io: Pointer to MC portal's I/O object
360 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
361 * @token: Token of DPBP object
362 * @irq_index: The interrupt index to configure
363 * @en: Interrupt state - enable = 1, disable = 0
364 *
365 * Allows GPP software to control when interrupts are generated.
366 * Each interrupt can have up to 32 causes. The enable/disable control's the
367 * overall interrupt state. if the interrupt is disabled no causes will cause
368 * an interrupt.
369 *
370 * Return: '0' on Success; Error code otherwise.
371 */
372int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
373 u32 cmd_flags,
374 u16 token,
375 u8 irq_index,
376 u8 en)
377{
378 struct mc_command cmd = { 0 };
379 struct dpbp_cmd_set_irq_enable *cmd_params;
380
381 /* prepare command */
382 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
383 cmd_flags, token);
384 cmd_params = (struct dpbp_cmd_set_irq_enable *)cmd.params;
385 cmd_params->enable = en & DPBP_ENABLE;
386 cmd_params->irq_index = irq_index;
387
388 /* send command to mc*/
389 return mc_send_command(mc_io, &cmd);
390}
391
392/**
393 * dpbp_get_irq_enable() - Get overall interrupt state
394 * @mc_io: Pointer to MC portal's I/O object
395 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
396 * @token: Token of DPBP object
397 * @irq_index: The interrupt index to configure
398 * @en: Returned interrupt state - enable = 1, disable = 0
399 *
400 * Return: '0' on Success; Error code otherwise.
401 */
402int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
403 u32 cmd_flags,
404 u16 token,
405 u8 irq_index,
406 u8 *en)
407{
408 struct mc_command cmd = { 0 };
409 struct dpbp_cmd_get_irq_enable *cmd_params;
410 struct dpbp_rsp_get_irq_enable *rsp_params;
411 int err;
412
413 /* prepare command */
414 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
415 cmd_flags, token);
416 cmd_params = (struct dpbp_cmd_get_irq_enable *)cmd.params;
417 cmd_params->irq_index = irq_index;
418
419 /* send command to mc*/
420 err = mc_send_command(mc_io, &cmd);
421 if (err)
422 return err;
423
424 /* retrieve response parameters */
425 rsp_params = (struct dpbp_rsp_get_irq_enable *)cmd.params;
426 *en = rsp_params->enabled & DPBP_ENABLE;
427 return 0;
428}
429
430/**
431 * dpbp_set_irq_mask() - Set interrupt mask.
432 * @mc_io: Pointer to MC portal's I/O object
433 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
434 * @token: Token of DPBP object
435 * @irq_index: The interrupt index to configure
436 * @mask: Event mask to trigger interrupt;
437 * each bit:
438 * 0 = ignore event
439 * 1 = consider event for asserting IRQ
440 *
441 * Every interrupt can have up to 32 causes and the interrupt model supports
442 * masking/unmasking each cause independently
443 *
444 * Return: '0' on Success; Error code otherwise.
445 */
446int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
447 u32 cmd_flags,
448 u16 token,
449 u8 irq_index,
450 u32 mask)
451{
452 struct mc_command cmd = { 0 };
453 struct dpbp_cmd_set_irq_mask *cmd_params;
454
455 /* prepare command */
456 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
457 cmd_flags, token);
458 cmd_params = (struct dpbp_cmd_set_irq_mask *)cmd.params;
459 cmd_params->mask = cpu_to_le32(mask);
460 cmd_params->irq_index = irq_index;
461
462 /* send command to mc*/
463 return mc_send_command(mc_io, &cmd);
464}
465
466/**
467 * dpbp_get_irq_mask() - Get interrupt mask.
468 * @mc_io: Pointer to MC portal's I/O object
469 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
470 * @token: Token of DPBP object
471 * @irq_index: The interrupt index to configure
472 * @mask: Returned event mask to trigger interrupt
473 *
474 * Every interrupt can have up to 32 causes and the interrupt model supports
475 * masking/unmasking each cause independently
476 *
477 * Return: '0' on Success; Error code otherwise.
478 */
479int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
480 u32 cmd_flags,
481 u16 token,
482 u8 irq_index,
483 u32 *mask)
484{
485 struct mc_command cmd = { 0 };
486 struct dpbp_cmd_get_irq_mask *cmd_params;
487 struct dpbp_rsp_get_irq_mask *rsp_params;
488 int err;
489
490 /* prepare command */
491 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
492 cmd_flags, token);
493 cmd_params = (struct dpbp_cmd_get_irq_mask *)cmd.params;
494 cmd_params->irq_index = irq_index;
495
496 /* send command to mc*/
497 err = mc_send_command(mc_io, &cmd);
498 if (err)
499 return err;
500
501 /* retrieve response parameters */
502 rsp_params = (struct dpbp_rsp_get_irq_mask *)cmd.params;
503 *mask = le32_to_cpu(rsp_params->mask);
504
505 return 0;
506}
507
508/**
509 * dpbp_get_irq_status() - Get the current status of any pending interrupts.
510 *
511 * @mc_io: Pointer to MC portal's I/O object
512 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
513 * @token: Token of DPBP object
514 * @irq_index: The interrupt index to configure
515 * @status: Returned interrupts status - one bit per cause:
516 * 0 = no interrupt pending
517 * 1 = interrupt pending
518 *
519 * Return: '0' on Success; Error code otherwise.
520 */
521int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
522 u32 cmd_flags,
523 u16 token,
524 u8 irq_index,
525 u32 *status)
526{
527 struct mc_command cmd = { 0 };
528 struct dpbp_cmd_get_irq_status *cmd_params;
529 struct dpbp_rsp_get_irq_status *rsp_params;
530 int err;
531
532 /* prepare command */
533 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
534 cmd_flags, token);
535 cmd_params = (struct dpbp_cmd_get_irq_status *)cmd.params;
536 cmd_params->status = cpu_to_le32(*status);
537 cmd_params->irq_index = irq_index;
538
539 /* send command to mc*/
540 err = mc_send_command(mc_io, &cmd);
541 if (err)
542 return err;
543
544 /* retrieve response parameters */
545 rsp_params = (struct dpbp_rsp_get_irq_status *)cmd.params;
546 *status = le32_to_cpu(rsp_params->status);
547
548 return 0;
549}
550
551/**
552 * dpbp_clear_irq_status() - Clear a pending interrupt's status
553 *
554 * @mc_io: Pointer to MC portal's I/O object
555 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
556 * @token: Token of DPBP object
557 * @irq_index: The interrupt index to configure
558 * @status: Bits to clear (W1C) - one bit per cause:
559 * 0 = don't change
560 * 1 = clear status bit
561 *
562 * Return: '0' on Success; Error code otherwise.
563 */
564int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
565 u32 cmd_flags,
566 u16 token,
567 u8 irq_index,
568 u32 status)
569{
570 struct mc_command cmd = { 0 };
571 struct dpbp_cmd_clear_irq_status *cmd_params;
572
573 /* prepare command */
574 cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
575 cmd_flags, token);
576 cmd_params = (struct dpbp_cmd_clear_irq_status *)cmd.params;
577 cmd_params->status = cpu_to_le32(status);
578 cmd_params->irq_index = irq_index;
579
580 /* send command to mc*/
581 return mc_send_command(mc_io, &cmd);
582}
583 210
584/** 211/**
585 * dpbp_get_attributes - Retrieve DPBP attributes. 212 * dpbp_get_attributes - Retrieve DPBP attributes.
@@ -619,80 +246,6 @@ int dpbp_get_attributes(struct fsl_mc_io *mc_io,
619EXPORT_SYMBOL(dpbp_get_attributes); 246EXPORT_SYMBOL(dpbp_get_attributes);
620 247
621/** 248/**
622 * dpbp_set_notifications() - Set notifications towards software
623 * @mc_io: Pointer to MC portal's I/O object
624 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
625 * @token: Token of DPBP object
626 * @cfg: notifications configuration
627 *
628 * Return: '0' on Success; Error code otherwise.
629 */
630int dpbp_set_notifications(struct fsl_mc_io *mc_io,
631 u32 cmd_flags,
632 u16 token,
633 struct dpbp_notification_cfg *cfg)
634{
635 struct mc_command cmd = { 0 };
636 struct dpbp_cmd_set_notifications *cmd_params;
637
638 /* prepare command */
639 cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_NOTIFICATIONS,
640 cmd_flags, token);
641 cmd_params = (struct dpbp_cmd_set_notifications *)cmd.params;
642 cmd_params->depletion_entry = cpu_to_le32(cfg->depletion_entry);
643 cmd_params->depletion_exit = cpu_to_le32(cfg->depletion_exit);
644 cmd_params->surplus_entry = cpu_to_le32(cfg->surplus_entry);
645 cmd_params->surplus_exit = cpu_to_le32(cfg->surplus_exit);
646 cmd_params->options = cpu_to_le16(cfg->options);
647 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
648 cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
649
650 /* send command to mc*/
651 return mc_send_command(mc_io, &cmd);
652}
653
654/**
655 * dpbp_get_notifications() - Get the notifications configuration
656 * @mc_io: Pointer to MC portal's I/O object
657 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
658 * @token: Token of DPBP object
659 * @cfg: notifications configuration
660 *
661 * Return: '0' on Success; Error code otherwise.
662 */
663int dpbp_get_notifications(struct fsl_mc_io *mc_io,
664 u32 cmd_flags,
665 u16 token,
666 struct dpbp_notification_cfg *cfg)
667{
668 struct mc_command cmd = { 0 };
669 struct dpbp_rsp_get_notifications *rsp_params;
670 int err;
671
672 /* prepare command */
673 cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_NOTIFICATIONS,
674 cmd_flags,
675 token);
676
677 /* send command to mc*/
678 err = mc_send_command(mc_io, &cmd);
679 if (err)
680 return err;
681
682 /* retrieve response parameters */
683 rsp_params = (struct dpbp_rsp_get_notifications *)cmd.params;
684 cfg->depletion_entry = le32_to_cpu(rsp_params->depletion_entry);
685 cfg->depletion_exit = le32_to_cpu(rsp_params->depletion_exit);
686 cfg->surplus_entry = le32_to_cpu(rsp_params->surplus_entry);
687 cfg->surplus_exit = le32_to_cpu(rsp_params->surplus_exit);
688 cfg->options = le16_to_cpu(rsp_params->options);
689 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
690 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
691
692 return 0;
693}
694
695/**
696 * dpbp_get_api_version - Get Data Path Buffer Pool API version 249 * dpbp_get_api_version - Get Data Path Buffer Pool API version
697 * @mc_io: Pointer to Mc portal's I/O object 250 * @mc_io: Pointer to Mc portal's I/O object
698 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 251 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -723,3 +276,4 @@ int dpbp_get_api_version(struct fsl_mc_io *mc_io,
723 276
724 return 0; 277 return 0;
725} 278}
279EXPORT_SYMBOL(dpbp_get_api_version);
diff --git a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h b/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
index 7cb514963c26..384a13d0b07f 100644
--- a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
+++ b/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
@@ -45,107 +45,12 @@
45/* Command IDs */ 45/* Command IDs */
46#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800) 46#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
47#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b) 47#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
48#define DPMCP_CMDID_CREATE DPMCP_CMD(0x90b)
49#define DPMCP_CMDID_DESTROY DPMCP_CMD(0x98b)
50#define DPMCP_CMDID_GET_API_VERSION DPMCP_CMD(0xa0b) 48#define DPMCP_CMDID_GET_API_VERSION DPMCP_CMD(0xa0b)
51 49
52#define DPMCP_CMDID_GET_ATTR DPMCP_CMD(0x004)
53#define DPMCP_CMDID_RESET DPMCP_CMD(0x005) 50#define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
54 51
55#define DPMCP_CMDID_SET_IRQ DPMCP_CMD(0x010)
56#define DPMCP_CMDID_GET_IRQ DPMCP_CMD(0x011)
57#define DPMCP_CMDID_SET_IRQ_ENABLE DPMCP_CMD(0x012)
58#define DPMCP_CMDID_GET_IRQ_ENABLE DPMCP_CMD(0x013)
59#define DPMCP_CMDID_SET_IRQ_MASK DPMCP_CMD(0x014)
60#define DPMCP_CMDID_GET_IRQ_MASK DPMCP_CMD(0x015)
61#define DPMCP_CMDID_GET_IRQ_STATUS DPMCP_CMD(0x016)
62
63struct dpmcp_cmd_open { 52struct dpmcp_cmd_open {
64 __le32 dpmcp_id; 53 __le32 dpmcp_id;
65}; 54};
66 55
67struct dpmcp_cmd_create {
68 __le32 portal_id;
69};
70
71struct dpmcp_cmd_destroy {
72 __le32 object_id;
73};
74
75struct dpmcp_cmd_set_irq {
76 /* cmd word 0 */
77 u8 irq_index;
78 u8 pad[3];
79 __le32 irq_val;
80 /* cmd word 1 */
81 __le64 irq_addr;
82 /* cmd word 2 */
83 __le32 irq_num;
84};
85
86struct dpmcp_cmd_get_irq {
87 __le32 pad;
88 u8 irq_index;
89};
90
91struct dpmcp_rsp_get_irq {
92 /* cmd word 0 */
93 __le32 irq_val;
94 __le32 pad;
95 /* cmd word 1 */
96 __le64 irq_paddr;
97 /* cmd word 2 */
98 __le32 irq_num;
99 __le32 type;
100};
101
102#define DPMCP_ENABLE 0x1
103
104struct dpmcp_cmd_set_irq_enable {
105 u8 enable;
106 u8 pad[3];
107 u8 irq_index;
108};
109
110struct dpmcp_cmd_get_irq_enable {
111 __le32 pad;
112 u8 irq_index;
113};
114
115struct dpmcp_rsp_get_irq_enable {
116 u8 enabled;
117};
118
119struct dpmcp_cmd_set_irq_mask {
120 __le32 mask;
121 u8 irq_index;
122};
123
124struct dpmcp_cmd_get_irq_mask {
125 __le32 pad;
126 u8 irq_index;
127};
128
129struct dpmcp_rsp_get_irq_mask {
130 __le32 mask;
131};
132
133struct dpmcp_cmd_get_irq_status {
134 __le32 status;
135 u8 irq_index;
136};
137
138struct dpmcp_rsp_get_irq_status {
139 __le32 status;
140};
141
142struct dpmcp_rsp_get_attributes {
143 /* response word 0 */
144 __le32 pad;
145 __le32 id;
146 /* response word 1 */
147 __le16 version_major;
148 __le16 version_minor;
149};
150
151#endif /* _FSL_DPMCP_CMD_H */ 56#endif /* _FSL_DPMCP_CMD_H */
diff --git a/drivers/staging/fsl-mc/bus/dpmcp.c b/drivers/staging/fsl-mc/bus/dpmcp.c
index e4d16519bcb4..ad4c8b43f065 100644
--- a/drivers/staging/fsl-mc/bus/dpmcp.c
+++ b/drivers/staging/fsl-mc/bus/dpmcp.c
@@ -104,82 +104,6 @@ int dpmcp_close(struct fsl_mc_io *mc_io,
104} 104}
105 105
106/** 106/**
107 * dpmcp_create() - Create the DPMCP object.
108 * @mc_io: Pointer to MC portal's I/O object
109 * @dprc_token: Parent container token; '0' for default container
110 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
111 * @cfg: Configuration structure
112 * @obj_id: Returned object id; use in subsequent API calls
113 *
114 * Create the DPMCP object, allocate required resources and
115 * perform required initialization.
116 *
117 * The object can be created either by declaring it in the
118 * DPL file, or by calling this function.
119
120 * This function accepts an authentication token of a parent
121 * container that this object should be assigned to and returns
122 * an object id. This object_id will be used in all subsequent calls to
123 * this specific object.
124 *
125 * Return: '0' on Success; Error code otherwise.
126 */
127int dpmcp_create(struct fsl_mc_io *mc_io,
128 u16 dprc_token,
129 u32 cmd_flags,
130 const struct dpmcp_cfg *cfg,
131 u32 *obj_id)
132{
133 struct mc_command cmd = { 0 };
134 struct dpmcp_cmd_create *cmd_params;
135
136 int err;
137
138 /* prepare command */
139 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
140 cmd_flags, dprc_token);
141 cmd_params = (struct dpmcp_cmd_create *)cmd.params;
142 cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
143
144 /* send command to mc*/
145 err = mc_send_command(mc_io, &cmd);
146 if (err)
147 return err;
148
149 /* retrieve response parameters */
150 *obj_id = mc_cmd_read_object_id(&cmd);
151
152 return 0;
153}
154
155/**
156 * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
157 * @mc_io: Pointer to MC portal's I/O object
158 * @dprc_token: Parent container token; '0' for default container
159 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
160 * @obj_id: ID of DPMCP object
161 *
162 * Return: '0' on Success; error code otherwise.
163 */
164int dpmcp_destroy(struct fsl_mc_io *mc_io,
165 u16 dprc_token,
166 u32 cmd_flags,
167 u32 obj_id)
168{
169 struct mc_command cmd = { 0 };
170 struct dpmcp_cmd_destroy *cmd_params;
171
172 /* prepare command */
173 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
174 cmd_flags, dprc_token);
175 cmd_params = (struct dpmcp_cmd_destroy *)cmd.params;
176 cmd_params->object_id = cpu_to_le32(obj_id);
177
178 /* send command to mc*/
179 return mc_send_command(mc_io, &cmd);
180}
181
182/**
183 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state. 107 * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
184 * @mc_io: Pointer to MC portal's I/O object 108 * @mc_io: Pointer to MC portal's I/O object
185 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 109 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -202,312 +126,6 @@ int dpmcp_reset(struct fsl_mc_io *mc_io,
202} 126}
203 127
204/** 128/**
205 * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
206 * @mc_io: Pointer to MC portal's I/O object
207 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
208 * @token: Token of DPMCP object
209 * @irq_index: Identifies the interrupt index to configure
210 * @irq_cfg: IRQ configuration
211 *
212 * Return: '0' on Success; Error code otherwise.
213 */
214int dpmcp_set_irq(struct fsl_mc_io *mc_io,
215 u32 cmd_flags,
216 u16 token,
217 u8 irq_index,
218 struct dpmcp_irq_cfg *irq_cfg)
219{
220 struct mc_command cmd = { 0 };
221 struct dpmcp_cmd_set_irq *cmd_params;
222
223 /* prepare command */
224 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
225 cmd_flags, token);
226 cmd_params = (struct dpmcp_cmd_set_irq *)cmd.params;
227 cmd_params->irq_index = irq_index;
228 cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
229 cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
230 cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
231
232 /* send command to mc*/
233 return mc_send_command(mc_io, &cmd);
234}
235
236/**
237 * dpmcp_get_irq() - Get IRQ information from the DPMCP.
238 * @mc_io: Pointer to MC portal's I/O object
239 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
240 * @token: Token of DPMCP object
241 * @irq_index: The interrupt index to configure
242 * @type: Interrupt type: 0 represents message interrupt
243 * type (both irq_addr and irq_val are valid)
244 * @irq_cfg: IRQ attributes
245 *
246 * Return: '0' on Success; Error code otherwise.
247 */
248int dpmcp_get_irq(struct fsl_mc_io *mc_io,
249 u32 cmd_flags,
250 u16 token,
251 u8 irq_index,
252 int *type,
253 struct dpmcp_irq_cfg *irq_cfg)
254{
255 struct mc_command cmd = { 0 };
256 struct dpmcp_cmd_get_irq *cmd_params;
257 struct dpmcp_rsp_get_irq *rsp_params;
258 int err;
259
260 /* prepare command */
261 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
262 cmd_flags, token);
263 cmd_params = (struct dpmcp_cmd_get_irq *)cmd.params;
264 cmd_params->irq_index = irq_index;
265
266 /* send command to mc*/
267 err = mc_send_command(mc_io, &cmd);
268 if (err)
269 return err;
270
271 /* retrieve response parameters */
272 rsp_params = (struct dpmcp_rsp_get_irq *)cmd.params;
273 irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
274 irq_cfg->paddr = le64_to_cpu(rsp_params->irq_paddr);
275 irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
276 *type = le32_to_cpu(rsp_params->type);
277 return 0;
278}
279
280/**
281 * dpmcp_set_irq_enable() - Set overall interrupt state.
282 * @mc_io: Pointer to MC portal's I/O object
283 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
284 * @token: Token of DPMCP object
285 * @irq_index: The interrupt index to configure
286 * @en: Interrupt state - enable = 1, disable = 0
287 *
288 * Allows GPP software to control when interrupts are generated.
289 * Each interrupt can have up to 32 causes. The enable/disable control's the
290 * overall interrupt state. if the interrupt is disabled no causes will cause
291 * an interrupt.
292 *
293 * Return: '0' on Success; Error code otherwise.
294 */
295int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
296 u32 cmd_flags,
297 u16 token,
298 u8 irq_index,
299 u8 en)
300{
301 struct mc_command cmd = { 0 };
302 struct dpmcp_cmd_set_irq_enable *cmd_params;
303
304 /* prepare command */
305 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
306 cmd_flags, token);
307 cmd_params = (struct dpmcp_cmd_set_irq_enable *)cmd.params;
308 cmd_params->enable = en & DPMCP_ENABLE;
309 cmd_params->irq_index = irq_index;
310
311 /* send command to mc*/
312 return mc_send_command(mc_io, &cmd);
313}
314
315/**
316 * dpmcp_get_irq_enable() - Get overall interrupt state
317 * @mc_io: Pointer to MC portal's I/O object
318 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
319 * @token: Token of DPMCP object
320 * @irq_index: The interrupt index to configure
321 * @en: Returned interrupt state - enable = 1, disable = 0
322 *
323 * Return: '0' on Success; Error code otherwise.
324 */
325int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
326 u32 cmd_flags,
327 u16 token,
328 u8 irq_index,
329 u8 *en)
330{
331 struct mc_command cmd = { 0 };
332 struct dpmcp_cmd_get_irq_enable *cmd_params;
333 struct dpmcp_rsp_get_irq_enable *rsp_params;
334 int err;
335
336 /* prepare command */
337 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
338 cmd_flags, token);
339 cmd_params = (struct dpmcp_cmd_get_irq_enable *)cmd.params;
340 cmd_params->irq_index = irq_index;
341
342 /* send command to mc*/
343 err = mc_send_command(mc_io, &cmd);
344 if (err)
345 return err;
346
347 /* retrieve response parameters */
348 rsp_params = (struct dpmcp_rsp_get_irq_enable *)cmd.params;
349 *en = rsp_params->enabled & DPMCP_ENABLE;
350 return 0;
351}
352
353/**
354 * dpmcp_set_irq_mask() - Set interrupt mask.
355 * @mc_io: Pointer to MC portal's I/O object
356 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
357 * @token: Token of DPMCP object
358 * @irq_index: The interrupt index to configure
359 * @mask: Event mask to trigger interrupt;
360 * each bit:
361 * 0 = ignore event
362 * 1 = consider event for asserting IRQ
363 *
364 * Every interrupt can have up to 32 causes and the interrupt model supports
365 * masking/unmasking each cause independently
366 *
367 * Return: '0' on Success; Error code otherwise.
368 */
369int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
370 u32 cmd_flags,
371 u16 token,
372 u8 irq_index,
373 u32 mask)
374{
375 struct mc_command cmd = { 0 };
376 struct dpmcp_cmd_set_irq_mask *cmd_params;
377
378 /* prepare command */
379 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
380 cmd_flags, token);
381 cmd_params = (struct dpmcp_cmd_set_irq_mask *)cmd.params;
382 cmd_params->mask = cpu_to_le32(mask);
383 cmd_params->irq_index = irq_index;
384
385 /* send command to mc*/
386 return mc_send_command(mc_io, &cmd);
387}
388
389/**
390 * dpmcp_get_irq_mask() - Get interrupt mask.
391 * @mc_io: Pointer to MC portal's I/O object
392 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
393 * @token: Token of DPMCP object
394 * @irq_index: The interrupt index to configure
395 * @mask: Returned event mask to trigger interrupt
396 *
397 * Every interrupt can have up to 32 causes and the interrupt model supports
398 * masking/unmasking each cause independently
399 *
400 * Return: '0' on Success; Error code otherwise.
401 */
402int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
403 u32 cmd_flags,
404 u16 token,
405 u8 irq_index,
406 u32 *mask)
407{
408 struct mc_command cmd = { 0 };
409 struct dpmcp_cmd_get_irq_mask *cmd_params;
410 struct dpmcp_rsp_get_irq_mask *rsp_params;
411
412 int err;
413
414 /* prepare command */
415 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
416 cmd_flags, token);
417 cmd_params = (struct dpmcp_cmd_get_irq_mask *)cmd.params;
418 cmd_params->irq_index = irq_index;
419
420 /* send command to mc*/
421 err = mc_send_command(mc_io, &cmd);
422 if (err)
423 return err;
424
425 /* retrieve response parameters */
426 rsp_params = (struct dpmcp_rsp_get_irq_mask *)cmd.params;
427 *mask = le32_to_cpu(rsp_params->mask);
428
429 return 0;
430}
431
432/**
433 * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
434 *
435 * @mc_io: Pointer to MC portal's I/O object
436 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
437 * @token: Token of DPMCP object
438 * @irq_index: The interrupt index to configure
439 * @status: Returned interrupts status - one bit per cause:
440 * 0 = no interrupt pending
441 * 1 = interrupt pending
442 *
443 * Return: '0' on Success; Error code otherwise.
444 */
445int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
446 u32 cmd_flags,
447 u16 token,
448 u8 irq_index,
449 u32 *status)
450{
451 struct mc_command cmd = { 0 };
452 struct dpmcp_cmd_get_irq_status *cmd_params;
453 struct dpmcp_rsp_get_irq_status *rsp_params;
454 int err;
455
456 /* prepare command */
457 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
458 cmd_flags, token);
459 cmd_params = (struct dpmcp_cmd_get_irq_status *)cmd.params;
460 cmd_params->status = cpu_to_le32(*status);
461 cmd_params->irq_index = irq_index;
462
463 /* send command to mc*/
464 err = mc_send_command(mc_io, &cmd);
465 if (err)
466 return err;
467
468 /* retrieve response parameters */
469 rsp_params = (struct dpmcp_rsp_get_irq_status *)cmd.params;
470 *status = le32_to_cpu(rsp_params->status);
471
472 return 0;
473}
474
475/**
476 * dpmcp_get_attributes - Retrieve DPMCP attributes.
477 *
478 * @mc_io: Pointer to MC portal's I/O object
479 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
480 * @token: Token of DPMCP object
481 * @attr: Returned object's attributes
482 *
483 * Return: '0' on Success; Error code otherwise.
484 */
485int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
486 u32 cmd_flags,
487 u16 token,
488 struct dpmcp_attr *attr)
489{
490 struct mc_command cmd = { 0 };
491 struct dpmcp_rsp_get_attributes *rsp_params;
492 int err;
493
494 /* prepare command */
495 cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
496 cmd_flags, token);
497
498 /* send command to mc*/
499 err = mc_send_command(mc_io, &cmd);
500 if (err)
501 return err;
502
503 /* retrieve response parameters */
504 rsp_params = (struct dpmcp_rsp_get_attributes *)cmd.params;
505 attr->id = le32_to_cpu(rsp_params->id);
506
507 return 0;
508}
509
510/**
511 * dpmcp_get_api_version - Get Data Path Management Command Portal API version 129 * dpmcp_get_api_version - Get Data Path Management Command Portal API version
512 * @mc_io: Pointer to Mc portal's I/O object 130 * @mc_io: Pointer to Mc portal's I/O object
513 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 131 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
diff --git a/drivers/staging/fsl-mc/bus/dpmcp.h b/drivers/staging/fsl-mc/bus/dpmcp.h
index 98a100d543f6..f616031e3e59 100644
--- a/drivers/staging/fsl-mc/bus/dpmcp.h
+++ b/drivers/staging/fsl-mc/bus/dpmcp.h
@@ -44,109 +44,17 @@ int dpmcp_open(struct fsl_mc_io *mc_io,
44 int dpmcp_id, 44 int dpmcp_id,
45 u16 *token); 45 u16 *token);
46 46
47/* Get portal ID from pool */
48#define DPMCP_GET_PORTAL_ID_FROM_POOL (-1)
49
50int dpmcp_close(struct fsl_mc_io *mc_io, 47int dpmcp_close(struct fsl_mc_io *mc_io,
51 u32 cmd_flags, 48 u32 cmd_flags,
52 u16 token); 49 u16 token);
53 50
54/** 51int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
55 * struct dpmcp_cfg - Structure representing DPMCP configuration 52 u32 cmd_flags,
56 * @portal_id: Portal ID; 'DPMCP_GET_PORTAL_ID_FROM_POOL' to get the portal ID 53 u16 *major_ver,
57 * from pool 54 u16 *minor_ver);
58 */
59struct dpmcp_cfg {
60 int portal_id;
61};
62
63int dpmcp_create(struct fsl_mc_io *mc_io,
64 u16 dprc_token,
65 u32 cmd_flags,
66 const struct dpmcp_cfg *cfg,
67 u32 *obj_id);
68
69int dpmcp_destroy(struct fsl_mc_io *mc_io,
70 u16 dprc_token,
71 u32 cmd_flags,
72 u32 obj_id);
73 55
74int dpmcp_reset(struct fsl_mc_io *mc_io, 56int dpmcp_reset(struct fsl_mc_io *mc_io,
75 u32 cmd_flags, 57 u32 cmd_flags,
76 u16 token); 58 u16 token);
77 59
78/* IRQ */
79/* IRQ Index */
80#define DPMCP_IRQ_INDEX 0
81/* irq event - Indicates that the link state changed */
82#define DPMCP_IRQ_EVENT_CMD_DONE 0x00000001
83
84/**
85 * struct dpmcp_irq_cfg - IRQ configuration
86 * @paddr: Address that must be written to signal a message-based interrupt
87 * @val: Value to write into irq_addr address
88 * @irq_num: A user defined number associated with this IRQ
89 */
90struct dpmcp_irq_cfg {
91 u64 paddr;
92 u32 val;
93 int irq_num;
94};
95
96int dpmcp_set_irq(struct fsl_mc_io *mc_io,
97 u32 cmd_flags,
98 u16 token,
99 u8 irq_index,
100 struct dpmcp_irq_cfg *irq_cfg);
101
102int dpmcp_get_irq(struct fsl_mc_io *mc_io,
103 u32 cmd_flags,
104 u16 token,
105 u8 irq_index,
106 int *type,
107 struct dpmcp_irq_cfg *irq_cfg);
108
109int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
110 u32 cmd_flags,
111 u16 token,
112 u8 irq_index,
113 u8 en);
114
115int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
116 u32 cmd_flags,
117 u16 token,
118 u8 irq_index,
119 u8 *en);
120
121int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
122 u32 cmd_flags,
123 u16 token,
124 u8 irq_index,
125 u32 mask);
126
127int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
128 u32 cmd_flags,
129 u16 token,
130 u8 irq_index,
131 u32 *mask);
132
133int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
134 u32 cmd_flags,
135 u16 token,
136 u8 irq_index,
137 u32 *status);
138
139/**
140 * struct dpmcp_attr - Structure representing DPMCP attributes
141 * @id: DPMCP object ID
142 */
143struct dpmcp_attr {
144 int id;
145};
146
147int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
148 u32 cmd_flags,
149 u16 token,
150 struct dpmcp_attr *attr);
151
152#endif /* __FSL_DPMCP_H */ 60#endif /* __FSL_DPMCP_H */
diff --git a/drivers/staging/fsl-mc/bus/dprc-cmd.h b/drivers/staging/fsl-mc/bus/dprc-cmd.h
index 588b8cafdbc7..e9fdca41f324 100644
--- a/drivers/staging/fsl-mc/bus/dprc-cmd.h
+++ b/drivers/staging/fsl-mc/bus/dprc-cmd.h
@@ -53,11 +53,9 @@
53/* Command IDs */ 53/* Command IDs */
54#define DPRC_CMDID_CLOSE DPRC_CMD(0x800) 54#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
55#define DPRC_CMDID_OPEN DPRC_CMD(0x805) 55#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
56#define DPRC_CMDID_CREATE DPRC_CMD(0x905)
57#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05) 56#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
58 57
59#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004) 58#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
60#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
61 59
62#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010) 60#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
63#define DPRC_CMDID_GET_IRQ DPRC_CMD(0x011) 61#define DPRC_CMDID_GET_IRQ DPRC_CMD(0x011)
@@ -68,29 +66,13 @@
68#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016) 66#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
69#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017) 67#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
70 68
71#define DPRC_CMDID_CREATE_CONT DPRC_CMD(0x151)
72#define DPRC_CMDID_DESTROY_CONT DPRC_CMD(0x152)
73#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830) 69#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
74#define DPRC_CMDID_SET_RES_QUOTA DPRC_CMD(0x155)
75#define DPRC_CMDID_GET_RES_QUOTA DPRC_CMD(0x156)
76#define DPRC_CMDID_ASSIGN DPRC_CMD(0x157)
77#define DPRC_CMDID_UNASSIGN DPRC_CMD(0x158)
78#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159) 70#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
79#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A) 71#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
80#define DPRC_CMDID_GET_RES_COUNT DPRC_CMD(0x15B) 72#define DPRC_CMDID_GET_RES_COUNT DPRC_CMD(0x15B)
81#define DPRC_CMDID_GET_RES_IDS DPRC_CMD(0x15C)
82#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E) 73#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
83#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F) 74#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
84#define DPRC_CMDID_GET_OBJ_IRQ DPRC_CMD(0x160) 75#define DPRC_CMDID_GET_OBJ_IRQ DPRC_CMD(0x160)
85#define DPRC_CMDID_SET_OBJ_LABEL DPRC_CMD(0x161)
86#define DPRC_CMDID_GET_OBJ_DESC DPRC_CMD(0x162)
87
88#define DPRC_CMDID_CONNECT DPRC_CMD(0x167)
89#define DPRC_CMDID_DISCONNECT DPRC_CMD(0x168)
90#define DPRC_CMDID_GET_POOL DPRC_CMD(0x169)
91#define DPRC_CMDID_GET_POOL_COUNT DPRC_CMD(0x16A)
92
93#define DPRC_CMDID_GET_CONNECTION DPRC_CMD(0x16C)
94 76
95struct dprc_cmd_open { 77struct dprc_cmd_open {
96 __le32 container_id; 78 __le32 container_id;
diff --git a/drivers/staging/fsl-mc/bus/dprc-driver.c b/drivers/staging/fsl-mc/bus/dprc-driver.c
index 4e416d89b736..e4b0341d42d7 100644
--- a/drivers/staging/fsl-mc/bus/dprc-driver.c
+++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
@@ -188,6 +188,7 @@ static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
188 child_dev = fsl_mc_device_lookup(obj_desc, mc_bus_dev); 188 child_dev = fsl_mc_device_lookup(obj_desc, mc_bus_dev);
189 if (child_dev) { 189 if (child_dev) {
190 check_plugged_state_change(child_dev, obj_desc); 190 check_plugged_state_change(child_dev, obj_desc);
191 put_device(&child_dev->dev);
191 continue; 192 continue;
192 } 193 }
193 194
diff --git a/drivers/staging/fsl-mc/bus/dprc.c b/drivers/staging/fsl-mc/bus/dprc.c
index 572edd4c066e..fcf7b4767dc0 100644
--- a/drivers/staging/fsl-mc/bus/dprc.c
+++ b/drivers/staging/fsl-mc/bus/dprc.c
@@ -100,133 +100,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
100EXPORT_SYMBOL(dprc_close); 100EXPORT_SYMBOL(dprc_close);
101 101
102/** 102/**
103 * dprc_create_container() - Create child container
104 * @mc_io: Pointer to MC portal's I/O object
105 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
106 * @token: Token of DPRC object
107 * @cfg: Child container configuration
108 * @child_container_id: Returned child container ID
109 * @child_portal_offset: Returned child portal offset from MC portal base
110 *
111 * Return: '0' on Success; Error code otherwise.
112 */
113int dprc_create_container(struct fsl_mc_io *mc_io,
114 u32 cmd_flags,
115 u16 token,
116 struct dprc_cfg *cfg,
117 int *child_container_id,
118 u64 *child_portal_offset)
119{
120 struct mc_command cmd = { 0 };
121 struct dprc_cmd_create_container *cmd_params;
122 struct dprc_rsp_create_container *rsp_params;
123 int err;
124
125 /* prepare command */
126 cmd_params = (struct dprc_cmd_create_container *)cmd.params;
127 cmd_params->options = cpu_to_le32(cfg->options);
128 cmd_params->icid = cpu_to_le16(cfg->icid);
129 cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
130 strncpy(cmd_params->label, cfg->label, 16);
131 cmd_params->label[15] = '\0';
132
133 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
134 cmd_flags, token);
135
136 /* send command to mc*/
137 err = mc_send_command(mc_io, &cmd);
138 if (err)
139 return err;
140
141 /* retrieve response parameters */
142 rsp_params = (struct dprc_rsp_create_container *)cmd.params;
143 *child_container_id = le32_to_cpu(rsp_params->child_container_id);
144 *child_portal_offset = le64_to_cpu(rsp_params->child_portal_addr);
145
146 return 0;
147}
148
149/**
150 * dprc_destroy_container() - Destroy child container.
151 * @mc_io: Pointer to MC portal's I/O object
152 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
153 * @token: Token of DPRC object
154 * @child_container_id: ID of the container to destroy
155 *
156 * This function terminates the child container, so following this call the
157 * child container ID becomes invalid.
158 *
159 * Notes:
160 * - All resources and objects of the destroyed container are returned to the
161 * parent container or destroyed if were created be the destroyed container.
162 * - This function destroy all the child containers of the specified
163 * container prior to destroying the container itself.
164 *
165 * warning: Only the parent container is allowed to destroy a child policy
166 * Container 0 can't be destroyed
167 *
168 * Return: '0' on Success; Error code otherwise.
169 *
170 */
171int dprc_destroy_container(struct fsl_mc_io *mc_io,
172 u32 cmd_flags,
173 u16 token,
174 int child_container_id)
175{
176 struct mc_command cmd = { 0 };
177 struct dprc_cmd_destroy_container *cmd_params;
178
179 /* prepare command */
180 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
181 cmd_flags, token);
182 cmd_params = (struct dprc_cmd_destroy_container *)cmd.params;
183 cmd_params->child_container_id = cpu_to_le32(child_container_id);
184
185 /* send command to mc*/
186 return mc_send_command(mc_io, &cmd);
187}
188
189/**
190 * dprc_reset_container - Reset child container.
191 * @mc_io: Pointer to MC portal's I/O object
192 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
193 * @token: Token of DPRC object
194 * @child_container_id: ID of the container to reset
195 *
196 * In case a software context crashes or becomes non-responsive, the parent
197 * may wish to reset its resources container before the software context is
198 * restarted.
199 *
200 * This routine informs all objects assigned to the child container that the
201 * container is being reset, so they may perform any cleanup operations that are
202 * needed. All objects handles that were owned by the child container shall be
203 * closed.
204 *
205 * Note that such request may be submitted even if the child software context
206 * has not crashed, but the resulting object cleanup operations will not be
207 * aware of that.
208 *
209 * Return: '0' on Success; Error code otherwise.
210 */
211int dprc_reset_container(struct fsl_mc_io *mc_io,
212 u32 cmd_flags,
213 u16 token,
214 int child_container_id)
215{
216 struct mc_command cmd = { 0 };
217 struct dprc_cmd_reset_container *cmd_params;
218
219 /* prepare command */
220 cmd.header = mc_encode_cmd_header(DPRC_CMDID_RESET_CONT,
221 cmd_flags, token);
222 cmd_params = (struct dprc_cmd_reset_container *)cmd.params;
223 cmd_params->child_container_id = cpu_to_le32(child_container_id);
224
225 /* send command to mc*/
226 return mc_send_command(mc_io, &cmd);
227}
228
229/**
230 * dprc_get_irq() - Get IRQ information from the DPRC. 103 * dprc_get_irq() - Get IRQ information from the DPRC.
231 * @mc_io: Pointer to MC portal's I/O object 104 * @mc_io: Pointer to MC portal's I/O object
232 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 105 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -570,277 +443,6 @@ int dprc_get_attributes(struct fsl_mc_io *mc_io,
570} 443}
571 444
572/** 445/**
573 * dprc_set_res_quota() - Set allocation policy for a specific resource/object
574 * type in a child container
575 * @mc_io: Pointer to MC portal's I/O object
576 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
577 * @token: Token of DPRC object
578 * @child_container_id: ID of the child container
579 * @type: Resource/object type
580 * @quota: Sets the maximum number of resources of the selected type
581 * that the child container is allowed to allocate from its parent;
582 * when quota is set to -1, the policy is the same as container's
583 * general policy.
584 *
585 * Allocation policy determines whether or not a container may allocate
586 * resources from its parent. Each container has a 'global' allocation policy
587 * that is set when the container is created.
588 *
589 * This function sets allocation policy for a specific resource type.
590 * The default policy for all resource types matches the container's 'global'
591 * allocation policy.
592 *
593 * Return: '0' on Success; Error code otherwise.
594 *
595 * @warning Only the parent container is allowed to change a child policy.
596 */
597int dprc_set_res_quota(struct fsl_mc_io *mc_io,
598 u32 cmd_flags,
599 u16 token,
600 int child_container_id,
601 char *type,
602 u16 quota)
603{
604 struct mc_command cmd = { 0 };
605 struct dprc_cmd_set_res_quota *cmd_params;
606
607 /* prepare command */
608 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
609 cmd_flags, token);
610 cmd_params = (struct dprc_cmd_set_res_quota *)cmd.params;
611 cmd_params->child_container_id = cpu_to_le32(child_container_id);
612 cmd_params->quota = cpu_to_le16(quota);
613 strncpy(cmd_params->type, type, 16);
614 cmd_params->type[15] = '\0';
615
616 /* send command to mc*/
617 return mc_send_command(mc_io, &cmd);
618}
619
620/**
621 * dprc_get_res_quota() - Gets the allocation policy of a specific
622 * resource/object type in a child container
623 * @mc_io: Pointer to MC portal's I/O object
624 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
625 * @token: Token of DPRC object
626 * @child_container_id; ID of the child container
627 * @type: resource/object type
628 * @quota: Returnes the maximum number of resources of the selected type
629 * that the child container is allowed to allocate from the parent;
630 * when quota is set to -1, the policy is the same as container's
631 * general policy.
632 *
633 * Return: '0' on Success; Error code otherwise.
634 */
635int dprc_get_res_quota(struct fsl_mc_io *mc_io,
636 u32 cmd_flags,
637 u16 token,
638 int child_container_id,
639 char *type,
640 u16 *quota)
641{
642 struct mc_command cmd = { 0 };
643 struct dprc_cmd_get_res_quota *cmd_params;
644 struct dprc_rsp_get_res_quota *rsp_params;
645 int err;
646
647 /* prepare command */
648 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
649 cmd_flags, token);
650 cmd_params = (struct dprc_cmd_get_res_quota *)cmd.params;
651 cmd_params->child_container_id = cpu_to_le32(child_container_id);
652 strncpy(cmd_params->type, type, 16);
653 cmd_params->type[15] = '\0';
654
655 /* send command to mc*/
656 err = mc_send_command(mc_io, &cmd);
657 if (err)
658 return err;
659
660 /* retrieve response parameters */
661 rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params;
662 *quota = le16_to_cpu(rsp_params->quota);
663
664 return 0;
665}
666
667/**
668 * dprc_assign() - Assigns objects or resource to a child container.
669 * @mc_io: Pointer to MC portal's I/O object
670 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
671 * @token: Token of DPRC object
672 * @container_id: ID of the child container
673 * @res_req: Describes the type and amount of resources to
674 * assign to the given container
675 *
676 * Assignment is usually done by a parent (this DPRC) to one of its child
677 * containers.
678 *
679 * According to the DPRC allocation policy, the assigned resources may be taken
680 * (allocated) from the container's ancestors, if not enough resources are
681 * available in the container itself.
682 *
683 * The type of assignment depends on the dprc_res_req options, as follows:
684 * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
685 * the explicit base ID specified at the id_base_align field of res_req.
686 * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
687 * aligned to the value given at id_base_align field of res_req.
688 * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
689 * and indicates that the object must be set to the plugged state.
690 *
691 * A container may use this function with its own ID in order to change a
692 * object state to plugged or unplugged.
693 *
694 * If IRQ information has been set in the child DPRC, it will signal an
695 * interrupt following every change in its object assignment.
696 *
697 * Return: '0' on Success; Error code otherwise.
698 */
699int dprc_assign(struct fsl_mc_io *mc_io,
700 u32 cmd_flags,
701 u16 token,
702 int container_id,
703 struct dprc_res_req *res_req)
704{
705 struct mc_command cmd = { 0 };
706 struct dprc_cmd_assign *cmd_params;
707
708 /* prepare command */
709 cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
710 cmd_flags, token);
711 cmd_params = (struct dprc_cmd_assign *)cmd.params;
712 cmd_params->container_id = cpu_to_le32(container_id);
713 cmd_params->options = cpu_to_le32(res_req->options);
714 cmd_params->num = cpu_to_le32(res_req->num);
715 cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
716 strncpy(cmd_params->type, res_req->type, 16);
717 cmd_params->type[15] = '\0';
718
719 /* send command to mc*/
720 return mc_send_command(mc_io, &cmd);
721}
722
723/**
724 * dprc_unassign() - Un-assigns objects or resources from a child container
725 * and moves them into this (parent) DPRC.
726 * @mc_io: Pointer to MC portal's I/O object
727 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
728 * @token: Token of DPRC object
729 * @child_container_id: ID of the child container
730 * @res_req: Describes the type and amount of resources to un-assign from
731 * the child container
732 *
733 * Un-assignment of objects can succeed only if the object is not in the
734 * plugged or opened state.
735 *
736 * Return: '0' on Success; Error code otherwise.
737 */
738int dprc_unassign(struct fsl_mc_io *mc_io,
739 u32 cmd_flags,
740 u16 token,
741 int child_container_id,
742 struct dprc_res_req *res_req)
743{
744 struct mc_command cmd = { 0 };
745 struct dprc_cmd_unassign *cmd_params;
746
747 /* prepare command */
748 cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
749 cmd_flags,
750 token);
751 cmd_params = (struct dprc_cmd_unassign *)cmd.params;
752 cmd_params->child_container_id = cpu_to_le32(child_container_id);
753 cmd_params->options = cpu_to_le32(res_req->options);
754 cmd_params->num = cpu_to_le32(res_req->num);
755 cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
756 strncpy(cmd_params->type, res_req->type, 16);
757 cmd_params->type[15] = '\0';
758
759 /* send command to mc*/
760 return mc_send_command(mc_io, &cmd);
761}
762
763/**
764 * dprc_get_pool_count() - Get the number of dprc's pools
765 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
766 * @mc_io: Pointer to MC portal's I/O object
767 * @token: Token of DPRC object
768 * @pool_count: Returned number of resource pools in the dprc
769 *
770 * Return: '0' on Success; Error code otherwise.
771 */
772int dprc_get_pool_count(struct fsl_mc_io *mc_io,
773 u32 cmd_flags,
774 u16 token,
775 int *pool_count)
776{
777 struct mc_command cmd = { 0 };
778 struct dprc_rsp_get_pool_count *rsp_params;
779 int err;
780
781 /* prepare command */
782 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
783 cmd_flags, token);
784
785 /* send command to mc*/
786 err = mc_send_command(mc_io, &cmd);
787 if (err)
788 return err;
789
790 /* retrieve response parameters */
791 rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params;
792 *pool_count = le32_to_cpu(rsp_params->pool_count);
793
794 return 0;
795}
796
797/**
798 * dprc_get_pool() - Get the type (string) of a certain dprc's pool
799 * @mc_io: Pointer to MC portal's I/O object
800 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
801 * @token: Token of DPRC object
802 * @pool_index; Index of the pool to be queried (< pool_count)
803 * @type: The type of the pool
804 *
805 * The pool types retrieved one by one by incrementing
806 * pool_index up to (not including) the value of pool_count returned
807 * from dprc_get_pool_count(). dprc_get_pool_count() must
808 * be called prior to dprc_get_pool().
809 *
810 * Return: '0' on Success; Error code otherwise.
811 */
812int dprc_get_pool(struct fsl_mc_io *mc_io,
813 u32 cmd_flags,
814 u16 token,
815 int pool_index,
816 char *type)
817{
818 struct mc_command cmd = { 0 };
819 struct dprc_cmd_get_pool *cmd_params;
820 struct dprc_rsp_get_pool *rsp_params;
821 int err;
822
823 /* prepare command */
824 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
825 cmd_flags,
826 token);
827 cmd_params = (struct dprc_cmd_get_pool *)cmd.params;
828 cmd_params->pool_index = cpu_to_le32(pool_index);
829
830 /* send command to mc*/
831 err = mc_send_command(mc_io, &cmd);
832 if (err)
833 return err;
834
835 /* retrieve response parameters */
836 rsp_params = (struct dprc_rsp_get_pool *)cmd.params;
837 strncpy(type, rsp_params->type, 16);
838 type[15] = '\0';
839
840 return 0;
841}
842
843/**
844 * dprc_get_obj_count() - Obtains the number of objects in the DPRC 446 * dprc_get_obj_count() - Obtains the number of objects in the DPRC
845 * @mc_io: Pointer to MC portal's I/O object 447 * @mc_io: Pointer to MC portal's I/O object
846 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 448 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -932,64 +534,6 @@ int dprc_get_obj(struct fsl_mc_io *mc_io,
932EXPORT_SYMBOL(dprc_get_obj); 534EXPORT_SYMBOL(dprc_get_obj);
933 535
934/** 536/**
935 * dprc_get_obj_desc() - Get object descriptor.
936 *
937 * @mc_io: Pointer to MC portal's I/O object
938 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
939 * @token: Token of DPRC object
940 * @obj_type: The type of the object to get its descriptor.
941 * @obj_id: The id of the object to get its descriptor
942 * @obj_desc: The returned descriptor to fill and return to the user
943 *
944 * Return: '0' on Success; Error code otherwise.
945 *
946 */
947int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
948 u32 cmd_flags,
949 u16 token,
950 char *obj_type,
951 int obj_id,
952 struct dprc_obj_desc *obj_desc)
953{
954 struct mc_command cmd = { 0 };
955 struct dprc_cmd_get_obj_desc *cmd_params;
956 struct dprc_rsp_get_obj_desc *rsp_params;
957 int err;
958
959 /* prepare command */
960 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
961 cmd_flags,
962 token);
963 cmd_params = (struct dprc_cmd_get_obj_desc *)cmd.params;
964 cmd_params->obj_id = cpu_to_le32(obj_id);
965 strncpy(cmd_params->type, obj_type, 16);
966 cmd_params->type[15] = '\0';
967
968 /* send command to mc*/
969 err = mc_send_command(mc_io, &cmd);
970 if (err)
971 return err;
972
973 /* retrieve response parameters */
974 rsp_params = (struct dprc_rsp_get_obj_desc *)cmd.params;
975 obj_desc->id = le32_to_cpu(rsp_params->id);
976 obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
977 obj_desc->irq_count = rsp_params->irq_count;
978 obj_desc->region_count = rsp_params->region_count;
979 obj_desc->state = le32_to_cpu(rsp_params->state);
980 obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
981 obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
982 obj_desc->flags = le16_to_cpu(rsp_params->flags);
983 strncpy(obj_desc->type, rsp_params->type, 16);
984 obj_desc->type[15] = '\0';
985 strncpy(obj_desc->label, rsp_params->label, 16);
986 obj_desc->label[15] = '\0';
987
988 return 0;
989}
990EXPORT_SYMBOL(dprc_get_obj_desc);
991
992/**
993 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt. 537 * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
994 * @mc_io: Pointer to MC portal's I/O object 538 * @mc_io: Pointer to MC portal's I/O object
995 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 539 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -1128,52 +672,6 @@ int dprc_get_res_count(struct fsl_mc_io *mc_io,
1128EXPORT_SYMBOL(dprc_get_res_count); 672EXPORT_SYMBOL(dprc_get_res_count);
1129 673
1130/** 674/**
1131 * dprc_get_res_ids() - Obtains IDs of free resources in the container
1132 * @mc_io: Pointer to MC portal's I/O object
1133 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1134 * @token: Token of DPRC object
1135 * @type: pool type
1136 * @range_desc: range descriptor
1137 *
1138 * Return: '0' on Success; Error code otherwise.
1139 */
1140int dprc_get_res_ids(struct fsl_mc_io *mc_io,
1141 u32 cmd_flags,
1142 u16 token,
1143 char *type,
1144 struct dprc_res_ids_range_desc *range_desc)
1145{
1146 struct mc_command cmd = { 0 };
1147 struct dprc_cmd_get_res_ids *cmd_params;
1148 struct dprc_rsp_get_res_ids *rsp_params;
1149 int err;
1150
1151 /* prepare command */
1152 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
1153 cmd_flags, token);
1154 cmd_params = (struct dprc_cmd_get_res_ids *)cmd.params;
1155 cmd_params->iter_status = range_desc->iter_status;
1156 cmd_params->base_id = cpu_to_le32(range_desc->base_id);
1157 cmd_params->last_id = cpu_to_le32(range_desc->last_id);
1158 strncpy(cmd_params->type, type, 16);
1159 cmd_params->type[15] = '\0';
1160
1161 /* send command to mc*/
1162 err = mc_send_command(mc_io, &cmd);
1163 if (err)
1164 return err;
1165
1166 /* retrieve response parameters */
1167 rsp_params = (struct dprc_rsp_get_res_ids *)cmd.params;
1168 range_desc->iter_status = rsp_params->iter_status;
1169 range_desc->base_id = le32_to_cpu(rsp_params->base_id);
1170 range_desc->last_id = le32_to_cpu(rsp_params->last_id);
1171
1172 return 0;
1173}
1174EXPORT_SYMBOL(dprc_get_res_ids);
1175
1176/**
1177 * dprc_get_obj_region() - Get region information for a specified object. 675 * dprc_get_obj_region() - Get region information for a specified object.
1178 * @mc_io: Pointer to MC portal's I/O object 676 * @mc_io: Pointer to MC portal's I/O object
1179 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 677 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
@@ -1222,170 +720,6 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io,
1222EXPORT_SYMBOL(dprc_get_obj_region); 720EXPORT_SYMBOL(dprc_get_obj_region);
1223 721
1224/** 722/**
1225 * dprc_set_obj_label() - Set object label.
1226 * @mc_io: Pointer to MC portal's I/O object
1227 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1228 * @token: Token of DPRC object
1229 * @obj_type: Object's type
1230 * @obj_id: Object's ID
1231 * @label: The required label. The maximum length is 16 chars.
1232 *
1233 * Return: '0' on Success; Error code otherwise.
1234 */
1235int dprc_set_obj_label(struct fsl_mc_io *mc_io,
1236 u32 cmd_flags,
1237 u16 token,
1238 char *obj_type,
1239 int obj_id,
1240 char *label)
1241{
1242 struct mc_command cmd = { 0 };
1243 struct dprc_cmd_set_obj_label *cmd_params;
1244
1245 /* prepare command */
1246 cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
1247 cmd_flags,
1248 token);
1249 cmd_params = (struct dprc_cmd_set_obj_label *)cmd.params;
1250 cmd_params->obj_id = cpu_to_le32(obj_id);
1251 strncpy(cmd_params->label, label, 16);
1252 cmd_params->label[15] = '\0';
1253 strncpy(cmd_params->obj_type, obj_type, 16);
1254 cmd_params->obj_type[15] = '\0';
1255
1256 /* send command to mc*/
1257 return mc_send_command(mc_io, &cmd);
1258}
1259EXPORT_SYMBOL(dprc_set_obj_label);
1260
1261/**
1262 * dprc_connect() - Connect two endpoints to create a network link between them
1263 * @mc_io: Pointer to MC portal's I/O object
1264 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1265 * @token: Token of DPRC object
1266 * @endpoint1: Endpoint 1 configuration parameters
1267 * @endpoint2: Endpoint 2 configuration parameters
1268 * @cfg: Connection configuration. The connection configuration is ignored for
1269 * connections made to DPMAC objects, where rate is retrieved from the
1270 * MAC configuration.
1271 *
1272 * Return: '0' on Success; Error code otherwise.
1273 */
1274int dprc_connect(struct fsl_mc_io *mc_io,
1275 u32 cmd_flags,
1276 u16 token,
1277 const struct dprc_endpoint *endpoint1,
1278 const struct dprc_endpoint *endpoint2,
1279 const struct dprc_connection_cfg *cfg)
1280{
1281 struct mc_command cmd = { 0 };
1282 struct dprc_cmd_connect *cmd_params;
1283
1284 /* prepare command */
1285 cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
1286 cmd_flags,
1287 token);
1288 cmd_params = (struct dprc_cmd_connect *)cmd.params;
1289 cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
1290 cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
1291 cmd_params->ep2_id = cpu_to_le32(endpoint2->id);
1292 cmd_params->ep2_interface_id = cpu_to_le32(endpoint2->if_id);
1293 strncpy(cmd_params->ep1_type, endpoint1->type, 16);
1294 cmd_params->ep1_type[15] = '\0';
1295 cmd_params->max_rate = cpu_to_le32(cfg->max_rate);
1296 cmd_params->committed_rate = cpu_to_le32(cfg->committed_rate);
1297 strncpy(cmd_params->ep2_type, endpoint2->type, 16);
1298 cmd_params->ep2_type[15] = '\0';
1299
1300 /* send command to mc*/
1301 return mc_send_command(mc_io, &cmd);
1302}
1303
1304/**
1305 * dprc_disconnect() - Disconnect one endpoint to remove its network connection
1306 * @mc_io: Pointer to MC portal's I/O object
1307 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1308 * @token: Token of DPRC object
1309 * @endpoint: Endpoint configuration parameters
1310 *
1311 * Return: '0' on Success; Error code otherwise.
1312 */
1313int dprc_disconnect(struct fsl_mc_io *mc_io,
1314 u32 cmd_flags,
1315 u16 token,
1316 const struct dprc_endpoint *endpoint)
1317{
1318 struct mc_command cmd = { 0 };
1319 struct dprc_cmd_disconnect *cmd_params;
1320
1321 /* prepare command */
1322 cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
1323 cmd_flags,
1324 token);
1325 cmd_params = (struct dprc_cmd_disconnect *)cmd.params;
1326 cmd_params->id = cpu_to_le32(endpoint->id);
1327 cmd_params->interface_id = cpu_to_le32(endpoint->if_id);
1328 strncpy(cmd_params->type, endpoint->type, 16);
1329 cmd_params->type[15] = '\0';
1330
1331 /* send command to mc*/
1332 return mc_send_command(mc_io, &cmd);
1333}
1334
1335/**
1336 * dprc_get_connection() - Get connected endpoint and link status if connection
1337 * exists.
1338 * @mc_io: Pointer to MC portal's I/O object
1339 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1340 * @token: Token of DPRC object
1341 * @endpoint1: Endpoint 1 configuration parameters
1342 * @endpoint2: Returned endpoint 2 configuration parameters
1343 * @state: Returned link state:
1344 * 1 - link is up;
1345 * 0 - link is down;
1346 * -1 - no connection (endpoint2 information is irrelevant)
1347 *
1348 * Return: '0' on Success; -ENAVAIL if connection does not exist.
1349 */
1350int dprc_get_connection(struct fsl_mc_io *mc_io,
1351 u32 cmd_flags,
1352 u16 token,
1353 const struct dprc_endpoint *endpoint1,
1354 struct dprc_endpoint *endpoint2,
1355 int *state)
1356{
1357 struct mc_command cmd = { 0 };
1358 struct dprc_cmd_get_connection *cmd_params;
1359 struct dprc_rsp_get_connection *rsp_params;
1360 int err;
1361
1362 /* prepare command */
1363 cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
1364 cmd_flags,
1365 token);
1366 cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
1367 cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
1368 cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
1369 strncpy(cmd_params->ep1_type, endpoint1->type, 16);
1370 cmd_params->ep1_type[15] = '\0';
1371
1372 /* send command to mc*/
1373 err = mc_send_command(mc_io, &cmd);
1374 if (err)
1375 return err;
1376
1377 /* retrieve response parameters */
1378 rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
1379 endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
1380 endpoint2->if_id = le32_to_cpu(rsp_params->ep2_interface_id);
1381 strncpy(endpoint2->type, rsp_params->ep2_type, 16);
1382 endpoint2->type[15] = '\0';
1383 *state = le32_to_cpu(rsp_params->state);
1384
1385 return 0;
1386}
1387
1388/**
1389 * dprc_get_api_version - Get Data Path Resource Container API version 723 * dprc_get_api_version - Get Data Path Resource Container API version
1390 * @mc_io: Pointer to Mc portal's I/O object 724 * @mc_io: Pointer to Mc portal's I/O object
1391 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 725 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
index 5ac373c0c716..47acb0a29842 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
@@ -27,8 +27,6 @@
27#include "fsl-mc-private.h" 27#include "fsl-mc-private.h"
28#include "dprc-cmd.h" 28#include "dprc-cmd.h"
29 29
30static struct kmem_cache *mc_dev_cache;
31
32/** 30/**
33 * Default DMA mask for devices on a fsl-mc bus 31 * Default DMA mask for devices on a fsl-mc bus
34 */ 32 */
@@ -77,9 +75,6 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv)
77 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); 75 struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
78 bool found = false; 76 bool found = false;
79 77
80 if (WARN_ON(!fsl_mc_bus_exists()))
81 goto out;
82
83 if (!mc_drv->match_id_table) 78 if (!mc_drv->match_id_table)
84 goto out; 79 goto out;
85 80
@@ -149,8 +144,6 @@ struct bus_type fsl_mc_bus_type = {
149}; 144};
150EXPORT_SYMBOL_GPL(fsl_mc_bus_type); 145EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
151 146
152static atomic_t root_dprc_count = ATOMIC_INIT(0);
153
154static int fsl_mc_driver_probe(struct device *dev) 147static int fsl_mc_driver_probe(struct device *dev)
155{ 148{
156 struct fsl_mc_driver *mc_drv; 149 struct fsl_mc_driver *mc_drv;
@@ -246,15 +239,6 @@ void fsl_mc_driver_unregister(struct fsl_mc_driver *mc_driver)
246EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister); 239EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister);
247 240
248/** 241/**
249 * fsl_mc_bus_exists - check if a root dprc exists
250 */
251bool fsl_mc_bus_exists(void)
252{
253 return atomic_read(&root_dprc_count) > 0;
254}
255EXPORT_SYMBOL_GPL(fsl_mc_bus_exists);
256
257/**
258 * fsl_mc_get_root_dprc - function to traverse to the root dprc 242 * fsl_mc_get_root_dprc - function to traverse to the root dprc
259 */ 243 */
260void fsl_mc_get_root_dprc(struct device *dev, 244void fsl_mc_get_root_dprc(struct device *dev,
@@ -433,6 +417,22 @@ bool fsl_mc_is_root_dprc(struct device *dev)
433 return dev == root_dprc_dev; 417 return dev == root_dprc_dev;
434} 418}
435 419
420static void fsl_mc_device_release(struct device *dev)
421{
422 struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
423 struct fsl_mc_bus *mc_bus = NULL;
424
425 kfree(mc_dev->regions);
426
427 if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
428 mc_bus = to_fsl_mc_bus(mc_dev);
429
430 if (mc_bus)
431 kfree(mc_bus);
432 else
433 kfree(mc_dev);
434}
435
436/** 436/**
437 * Add a newly discovered fsl-mc device to be visible in Linux 437 * Add a newly discovered fsl-mc device to be visible in Linux
438 */ 438 */
@@ -455,7 +455,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
455 /* 455 /*
456 * Allocate an MC bus device object: 456 * Allocate an MC bus device object:
457 */ 457 */
458 mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL); 458 mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL);
459 if (!mc_bus) 459 if (!mc_bus)
460 return -ENOMEM; 460 return -ENOMEM;
461 461
@@ -464,7 +464,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
464 /* 464 /*
465 * Allocate a regular fsl_mc_device object: 465 * Allocate a regular fsl_mc_device object:
466 */ 466 */
467 mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL); 467 mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL);
468 if (!mc_dev) 468 if (!mc_dev)
469 return -ENOMEM; 469 return -ENOMEM;
470 } 470 }
@@ -474,6 +474,7 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
474 device_initialize(&mc_dev->dev); 474 device_initialize(&mc_dev->dev);
475 mc_dev->dev.parent = parent_dev; 475 mc_dev->dev.parent = parent_dev;
476 mc_dev->dev.bus = &fsl_mc_bus_type; 476 mc_dev->dev.bus = &fsl_mc_bus_type;
477 mc_dev->dev.release = fsl_mc_device_release;
477 dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id); 478 dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id);
478 479
479 if (strcmp(obj_desc->type, "dprc") == 0) { 480 if (strcmp(obj_desc->type, "dprc") == 0) {
@@ -506,8 +507,6 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
506 } 507 }
507 508
508 mc_io2 = mc_io; 509 mc_io2 = mc_io;
509
510 atomic_inc(&root_dprc_count);
511 } 510 }
512 511
513 error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid); 512 error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid);
@@ -553,7 +552,6 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
553 goto error_cleanup_dev; 552 goto error_cleanup_dev;
554 } 553 }
555 554
556 (void)get_device(&mc_dev->dev);
557 dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev)); 555 dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));
558 556
559 *new_mc_dev = mc_dev; 557 *new_mc_dev = mc_dev;
@@ -562,9 +560,9 @@ int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
562error_cleanup_dev: 560error_cleanup_dev:
563 kfree(mc_dev->regions); 561 kfree(mc_dev->regions);
564 if (mc_bus) 562 if (mc_bus)
565 devm_kfree(parent_dev, mc_bus); 563 kfree(mc_bus);
566 else 564 else
567 kmem_cache_free(mc_dev_cache, mc_dev); 565 kfree(mc_dev);
568 566
569 return error; 567 return error;
570} 568}
@@ -578,31 +576,11 @@ EXPORT_SYMBOL_GPL(fsl_mc_device_add);
578 */ 576 */
579void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) 577void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
580{ 578{
581 struct fsl_mc_bus *mc_bus = NULL;
582
583 kfree(mc_dev->regions);
584
585 /* 579 /*
586 * The device-specific remove callback will get invoked by device_del() 580 * The device-specific remove callback will get invoked by device_del()
587 */ 581 */
588 device_del(&mc_dev->dev); 582 device_del(&mc_dev->dev);
589 put_device(&mc_dev->dev); 583 put_device(&mc_dev->dev);
590
591 if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) {
592 mc_bus = to_fsl_mc_bus(mc_dev);
593
594 if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
595 if (atomic_read(&root_dprc_count) > 0)
596 atomic_dec(&root_dprc_count);
597 else
598 WARN_ON(1);
599 }
600 }
601
602 if (mc_bus)
603 devm_kfree(mc_dev->dev.parent, mc_bus);
604 else
605 kmem_cache_free(mc_dev_cache, mc_dev);
606} 584}
607EXPORT_SYMBOL_GPL(fsl_mc_device_remove); 585EXPORT_SYMBOL_GPL(fsl_mc_device_remove);
608 586
@@ -774,7 +752,7 @@ static int fsl_mc_bus_probe(struct platform_device *pdev)
774 error = dprc_get_container_id(mc_io, 0, &container_id); 752 error = dprc_get_container_id(mc_io, 0, &container_id);
775 if (error < 0) { 753 if (error < 0) {
776 dev_err(&pdev->dev, 754 dev_err(&pdev->dev,
777 "dpmng_get_container_id() failed: %d\n", error); 755 "dprc_get_container_id() failed: %d\n", error);
778 goto error_cleanup_mc_io; 756 goto error_cleanup_mc_io;
779 } 757 }
780 758
@@ -843,14 +821,6 @@ static int __init fsl_mc_bus_driver_init(void)
843{ 821{
844 int error; 822 int error;
845 823
846 mc_dev_cache = kmem_cache_create("fsl_mc_device",
847 sizeof(struct fsl_mc_device), 0, 0,
848 NULL);
849 if (!mc_dev_cache) {
850 pr_err("Could not create fsl_mc_device cache\n");
851 return -ENOMEM;
852 }
853
854 error = bus_register(&fsl_mc_bus_type); 824 error = bus_register(&fsl_mc_bus_type);
855 if (error < 0) { 825 if (error < 0) {
856 pr_err("bus type registration failed: %d\n", error); 826 pr_err("bus type registration failed: %d\n", error);
@@ -890,7 +860,6 @@ error_cleanup_bus:
890 bus_unregister(&fsl_mc_bus_type); 860 bus_unregister(&fsl_mc_bus_type);
891 861
892error_cleanup_cache: 862error_cleanup_cache:
893 kmem_cache_destroy(mc_dev_cache);
894 return error; 863 return error;
895} 864}
896postcore_initcall(fsl_mc_bus_driver_init); 865postcore_initcall(fsl_mc_bus_driver_init);
diff --git a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
index 7975c6e6fee3..b8b2c86e63d4 100644
--- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
@@ -17,6 +17,7 @@
17#include <linux/irqdomain.h> 17#include <linux/irqdomain.h>
18#include <linux/msi.h> 18#include <linux/msi.h>
19#include "../include/mc-bus.h" 19#include "../include/mc-bus.h"
20#include "fsl-mc-private.h"
20 21
21/* 22/*
22 * Generate a unique ID identifying the interrupt (only used within the MSI 23 * Generate a unique ID identifying the interrupt (only used within the MSI
diff --git a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
index 6b1cd574644f..87e44712b56c 100644
--- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
+++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
@@ -17,6 +17,7 @@
17#include <linux/of.h> 17#include <linux/of.h>
18#include <linux/of_irq.h> 18#include <linux/of_irq.h>
19#include "../include/mc-bus.h" 19#include "../include/mc-bus.h"
20#include "fsl-mc-private.h"
20 21
21static struct irq_chip its_msi_irq_chip = { 22static struct irq_chip its_msi_irq_chip = {
22 .name = "ITS-fMSI", 23 .name = "ITS-fMSI",
@@ -51,7 +52,7 @@ static int its_fsl_mc_msi_prepare(struct irq_domain *msi_domain,
51 return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info); 52 return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info);
52} 53}
53 54
54static struct msi_domain_ops its_fsl_mc_msi_ops = { 55static struct msi_domain_ops its_fsl_mc_msi_ops __ro_after_init = {
55 .msi_prepare = its_fsl_mc_msi_prepare, 56 .msi_prepare = its_fsl_mc_msi_prepare,
56}; 57};
57 58
diff --git a/drivers/staging/fsl-mc/include/dpbp.h b/drivers/staging/fsl-mc/include/dpbp.h
index bf34b1e0e730..e9e04ccea82b 100644
--- a/drivers/staging/fsl-mc/include/dpbp.h
+++ b/drivers/staging/fsl-mc/include/dpbp.h
@@ -49,25 +49,6 @@ int dpbp_close(struct fsl_mc_io *mc_io,
49 u32 cmd_flags, 49 u32 cmd_flags,
50 u16 token); 50 u16 token);
51 51
52/**
53 * struct dpbp_cfg - Structure representing DPBP configuration
54 * @options: place holder
55 */
56struct dpbp_cfg {
57 u32 options;
58};
59
60int dpbp_create(struct fsl_mc_io *mc_io,
61 u16 dprc_token,
62 u32 cmd_flags,
63 const struct dpbp_cfg *cfg,
64 u32 *obj_id);
65
66int dpbp_destroy(struct fsl_mc_io *mc_io,
67 u16 dprc_token,
68 u32 cmd_flags,
69 u32 obj_id);
70
71int dpbp_enable(struct fsl_mc_io *mc_io, 52int dpbp_enable(struct fsl_mc_io *mc_io,
72 u32 cmd_flags, 53 u32 cmd_flags,
73 u16 token); 54 u16 token);
@@ -86,67 +67,6 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
86 u16 token); 67 u16 token);
87 68
88/** 69/**
89 * struct dpbp_irq_cfg - IRQ configuration
90 * @addr: Address that must be written to signal a message-based interrupt
91 * @val: Value to write into irq_addr address
92 * @irq_num: A user defined number associated with this IRQ
93 */
94struct dpbp_irq_cfg {
95 u64 addr;
96 u32 val;
97 int irq_num;
98};
99
100int dpbp_set_irq(struct fsl_mc_io *mc_io,
101 u32 cmd_flags,
102 u16 token,
103 u8 irq_index,
104 struct dpbp_irq_cfg *irq_cfg);
105
106int dpbp_get_irq(struct fsl_mc_io *mc_io,
107 u32 cmd_flags,
108 u16 token,
109 u8 irq_index,
110 int *type,
111 struct dpbp_irq_cfg *irq_cfg);
112
113int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
114 u32 cmd_flags,
115 u16 token,
116 u8 irq_index,
117 u8 en);
118
119int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
120 u32 cmd_flags,
121 u16 token,
122 u8 irq_index,
123 u8 *en);
124
125int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
126 u32 cmd_flags,
127 u16 token,
128 u8 irq_index,
129 u32 mask);
130
131int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
132 u32 cmd_flags,
133 u16 token,
134 u8 irq_index,
135 u32 *mask);
136
137int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
138 u32 cmd_flags,
139 u16 token,
140 u8 irq_index,
141 u32 *status);
142
143int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
144 u32 cmd_flags,
145 u16 token,
146 u8 irq_index,
147 u32 status);
148
149/**
150 * struct dpbp_attr - Structure representing DPBP attributes 70 * struct dpbp_attr - Structure representing DPBP attributes
151 * @id: DPBP object ID 71 * @id: DPBP object ID
152 * @bpid: Hardware buffer pool ID; should be used as an argument in 72 * @bpid: Hardware buffer pool ID; should be used as an argument in
@@ -162,58 +82,9 @@ int dpbp_get_attributes(struct fsl_mc_io *mc_io,
162 u16 token, 82 u16 token,
163 struct dpbp_attr *attr); 83 struct dpbp_attr *attr);
164 84
165/**
166 * DPBP notifications options
167 */
168
169/**
170 * BPSCN write will attempt to allocate into a cache (coherent write)
171 */
172#define DPBP_NOTIF_OPT_COHERENT_WRITE 0x00000001
173
174/**
175 * struct dpbp_notification_cfg - Structure representing DPBP notifications
176 * towards software
177 * @depletion_entry: below this threshold the pool is "depleted";
178 * set it to '0' to disable it
179 * @depletion_exit: greater than or equal to this threshold the pool exit its
180 * "depleted" state
181 * @surplus_entry: above this threshold the pool is in "surplus" state;
182 * set it to '0' to disable it
183 * @surplus_exit: less than or equal to this threshold the pool exit its
184 * "surplus" state
185 * @message_iova: MUST be given if either 'depletion_entry' or 'surplus_entry'
186 * is not '0' (enable); I/O virtual address (must be in DMA-able memory),
187 * must be 16B aligned.
188 * @message_ctx: The context that will be part of the BPSCN message and will
189 * be written to 'message_iova'
190 * @options: Mask of available options; use 'DPBP_NOTIF_OPT_<X>' values
191 */
192struct dpbp_notification_cfg {
193 u32 depletion_entry;
194 u32 depletion_exit;
195 u32 surplus_entry;
196 u32 surplus_exit;
197 u64 message_iova;
198 u64 message_ctx;
199 u16 options;
200};
201
202int dpbp_set_notifications(struct fsl_mc_io *mc_io,
203 u32 cmd_flags,
204 u16 token,
205 struct dpbp_notification_cfg *cfg);
206
207int dpbp_get_notifications(struct fsl_mc_io *mc_io,
208 u32 cmd_flags,
209 u16 token,
210 struct dpbp_notification_cfg *cfg);
211
212int dpbp_get_api_version(struct fsl_mc_io *mc_io, 85int dpbp_get_api_version(struct fsl_mc_io *mc_io,
213 u32 cmd_flags, 86 u32 cmd_flags,
214 u16 *major_ver, 87 u16 *major_ver,
215 u16 *minor_ver); 88 u16 *minor_ver);
216 89
217/** @} */
218
219#endif /* __FSL_DPBP_H */ 90#endif /* __FSL_DPBP_H */
diff --git a/drivers/staging/fsl-mc/include/dpmng.h b/drivers/staging/fsl-mc/include/dpmng.h
index 7d8e255da578..170c07dd376a 100644
--- a/drivers/staging/fsl-mc/include/dpmng.h
+++ b/drivers/staging/fsl-mc/include/dpmng.h
@@ -64,8 +64,4 @@ int mc_get_version(struct fsl_mc_io *mc_io,
64 u32 cmd_flags, 64 u32 cmd_flags,
65 struct mc_version *mc_ver_info); 65 struct mc_version *mc_ver_info);
66 66
67int dpmng_get_container_id(struct fsl_mc_io *mc_io,
68 u32 cmd_flags,
69 int *container_id);
70
71#endif /* __FSL_DPMNG_H */ 67#endif /* __FSL_DPMNG_H */
diff --git a/drivers/staging/fsl-mc/include/dprc.h b/drivers/staging/fsl-mc/include/dprc.h
index f9ea769ccfab..dc985cc1246f 100644
--- a/drivers/staging/fsl-mc/include/dprc.h
+++ b/drivers/staging/fsl-mc/include/dprc.h
@@ -42,20 +42,6 @@
42 42
43struct fsl_mc_io; 43struct fsl_mc_io;
44 44
45/**
46 * Set this value as the icid value in dprc_cfg structure when creating a
47 * container, in case the ICID is not selected by the user and should be
48 * allocated by the DPRC from the pool of ICIDs.
49 */
50#define DPRC_GET_ICID_FROM_POOL (u16)(~(0))
51
52/**
53 * Set this value as the portal_id value in dprc_cfg structure when creating a
54 * container, in case the portal ID is not specifically selected by the
55 * user and should be allocated by the DPRC from the pool of portal ids.
56 */
57#define DPRC_GET_PORTAL_ID_FROM_POOL (int)(~(0))
58
59int dprc_open(struct fsl_mc_io *mc_io, 45int dprc_open(struct fsl_mc_io *mc_io,
60 u32 cmd_flags, 46 u32 cmd_flags,
61 int container_id, 47 int container_id,
@@ -65,79 +51,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
65 u32 cmd_flags, 51 u32 cmd_flags,
66 u16 token); 52 u16 token);
67 53
68/**
69 * Container general options
70 *
71 * These options may be selected at container creation by the container creator
72 * and can be retrieved using dprc_get_attributes()
73 */
74
75/*
76 * Spawn Policy Option allowed - Indicates that the new container is allowed
77 * to spawn and have its own child containers.
78 */
79#define DPRC_CFG_OPT_SPAWN_ALLOWED 0x00000001
80
81/*
82 * General Container allocation policy - Indicates that the new container is
83 * allowed to allocate requested resources from its parent container; if not
84 * set, the container is only allowed to use resources in its own pools; Note
85 * that this is a container's global policy, but the parent container may
86 * override it and set specific quota per resource type.
87 */
88#define DPRC_CFG_OPT_ALLOC_ALLOWED 0x00000002
89
90/*
91 * Object initialization allowed - software context associated with this
92 * container is allowed to invoke object initialization operations.
93 */
94#define DPRC_CFG_OPT_OBJ_CREATE_ALLOWED 0x00000004
95
96/*
97 * Topology change allowed - software context associated with this
98 * container is allowed to invoke topology operations, such as attach/detach
99 * of network objects.
100 */
101#define DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED 0x00000008
102
103/* AIOP - Indicates that container belongs to AIOP. */
104#define DPRC_CFG_OPT_AIOP 0x00000020
105
106/* IRQ Config - Indicates that the container allowed to configure its IRQs. */
107#define DPRC_CFG_OPT_IRQ_CFG_ALLOWED 0x00000040
108
109/**
110 * struct dprc_cfg - Container configuration options
111 * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
112 * ICID value is allocated by the DPRC
113 * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
114 * portal ID is allocated by the DPRC
115 * @options: Combination of 'DPRC_CFG_OPT_<X>' options
116 * @label: Object's label
117 */
118struct dprc_cfg {
119 u16 icid;
120 int portal_id;
121 u64 options;
122 char label[16];
123};
124
125int dprc_create_container(struct fsl_mc_io *mc_io,
126 u32 cmd_flags,
127 u16 token,
128 struct dprc_cfg *cfg,
129 int *child_container_id,
130 u64 *child_portal_offset);
131
132int dprc_destroy_container(struct fsl_mc_io *mc_io,
133 u32 cmd_flags,
134 u16 token,
135 int child_container_id);
136
137int dprc_reset_container(struct fsl_mc_io *mc_io,
138 u32 cmd_flags,
139 u16 token,
140 int child_container_id);
141 54
142/* IRQ */ 55/* IRQ */
143 56
@@ -252,90 +165,6 @@ int dprc_get_attributes(struct fsl_mc_io *mc_io,
252 u16 token, 165 u16 token,
253 struct dprc_attributes *attributes); 166 struct dprc_attributes *attributes);
254 167
255int dprc_set_res_quota(struct fsl_mc_io *mc_io,
256 u32 cmd_flags,
257 u16 token,
258 int child_container_id,
259 char *type,
260 u16 quota);
261
262int dprc_get_res_quota(struct fsl_mc_io *mc_io,
263 u32 cmd_flags,
264 u16 token,
265 int child_container_id,
266 char *type,
267 u16 *quota);
268
269/* Resource request options */
270
271/*
272 * Explicit resource ID request - The requested objects/resources
273 * are explicit and sequential (in case of resources).
274 * The base ID is given at res_req at base_align field
275 */
276#define DPRC_RES_REQ_OPT_EXPLICIT 0x00000001
277
278/*
279 * Aligned resources request - Relevant only for resources
280 * request (and not objects). Indicates that resources base ID should be
281 * sequential and aligned to the value given at dprc_res_req base_align field
282 */
283#define DPRC_RES_REQ_OPT_ALIGNED 0x00000002
284
285/*
286 * Plugged Flag - Relevant only for object assignment request.
287 * Indicates that after all objects assigned. An interrupt will be invoked at
288 * the relevant GPP. The assigned object will be marked as plugged.
289 * plugged objects can't be assigned from their container
290 */
291#define DPRC_RES_REQ_OPT_PLUGGED 0x00000004
292
293/**
294 * struct dprc_res_req - Resource request descriptor, to be used in assignment
295 * or un-assignment of resources and objects.
296 * @type: Resource/object type: Represent as a NULL terminated string.
297 * This string may received by using dprc_get_pool() to get resource
298 * type and dprc_get_obj() to get object type;
299 * Note: it is not possible to assign/un-assign DPRC objects
300 * @num: Number of resources
301 * @options: Request options: combination of DPRC_RES_REQ_OPT_ options
302 * @id_base_align: In case of explicit assignment (DPRC_RES_REQ_OPT_EXPLICIT
303 * is set at option), this field represents the required base ID
304 * for resource allocation; In case of aligned assignment
305 * (DPRC_RES_REQ_OPT_ALIGNED is set at option), this field
306 * indicates the required alignment for the resource ID(s) -
307 * use 0 if there is no alignment or explicit ID requirements
308 */
309struct dprc_res_req {
310 char type[16];
311 u32 num;
312 u32 options;
313 int id_base_align;
314};
315
316int dprc_assign(struct fsl_mc_io *mc_io,
317 u32 cmd_flags,
318 u16 token,
319 int container_id,
320 struct dprc_res_req *res_req);
321
322int dprc_unassign(struct fsl_mc_io *mc_io,
323 u32 cmd_flags,
324 u16 token,
325 int child_container_id,
326 struct dprc_res_req *res_req);
327
328int dprc_get_pool_count(struct fsl_mc_io *mc_io,
329 u32 cmd_flags,
330 u16 token,
331 int *pool_count);
332
333int dprc_get_pool(struct fsl_mc_io *mc_io,
334 u32 cmd_flags,
335 u16 token,
336 int pool_index,
337 char *type);
338
339int dprc_get_obj_count(struct fsl_mc_io *mc_io, 168int dprc_get_obj_count(struct fsl_mc_io *mc_io,
340 u32 cmd_flags, 169 u32 cmd_flags,
341 u16 token, 170 u16 token,
@@ -430,27 +259,6 @@ enum dprc_iter_status {
430 DPRC_ITER_STATUS_LAST = 2 259 DPRC_ITER_STATUS_LAST = 2
431}; 260};
432 261
433/**
434 * struct dprc_res_ids_range_desc - Resource ID range descriptor
435 * @base_id: Base resource ID of this range
436 * @last_id: Last resource ID of this range
437 * @iter_status: Iteration status - should be set to DPRC_ITER_STATUS_FIRST at
438 * first iteration; while the returned marker is DPRC_ITER_STATUS_MORE,
439 * additional iterations are needed, until the returned marker is
440 * DPRC_ITER_STATUS_LAST
441 */
442struct dprc_res_ids_range_desc {
443 int base_id;
444 int last_id;
445 enum dprc_iter_status iter_status;
446};
447
448int dprc_get_res_ids(struct fsl_mc_io *mc_io,
449 u32 cmd_flags,
450 u16 token,
451 char *type,
452 struct dprc_res_ids_range_desc *range_desc);
453
454/* Region flags */ 262/* Region flags */
455/* Cacheable - Indicates that region should be mapped as cacheable */ 263/* Cacheable - Indicates that region should be mapped as cacheable */
456#define DPRC_REGION_CACHEABLE 0x00000001 264#define DPRC_REGION_CACHEABLE 0x00000001
@@ -490,57 +298,6 @@ int dprc_get_obj_region(struct fsl_mc_io *mc_io,
490 u8 region_index, 298 u8 region_index,
491 struct dprc_region_desc *region_desc); 299 struct dprc_region_desc *region_desc);
492 300
493int dprc_set_obj_label(struct fsl_mc_io *mc_io,
494 u32 cmd_flags,
495 u16 token,
496 char *obj_type,
497 int obj_id,
498 char *label);
499
500/**
501 * struct dprc_endpoint - Endpoint description for link connect/disconnect
502 * operations
503 * @type: Endpoint object type: NULL terminated string
504 * @id: Endpoint object ID
505 * @if_id: Interface ID; should be set for endpoints with multiple
506 * interfaces ("dpsw", "dpdmux"); for others, always set to 0
507 */
508struct dprc_endpoint {
509 char type[16];
510 int id;
511 int if_id;
512};
513
514/**
515 * struct dprc_connection_cfg - Connection configuration.
516 * Used for virtual connections only
517 * @committed_rate: Committed rate (Mbits/s)
518 * @max_rate: Maximum rate (Mbits/s)
519 */
520struct dprc_connection_cfg {
521 u32 committed_rate;
522 u32 max_rate;
523};
524
525int dprc_connect(struct fsl_mc_io *mc_io,
526 u32 cmd_flags,
527 u16 token,
528 const struct dprc_endpoint *endpoint1,
529 const struct dprc_endpoint *endpoint2,
530 const struct dprc_connection_cfg *cfg);
531
532int dprc_disconnect(struct fsl_mc_io *mc_io,
533 u32 cmd_flags,
534 u16 token,
535 const struct dprc_endpoint *endpoint);
536
537int dprc_get_connection(struct fsl_mc_io *mc_io,
538 u32 cmd_flags,
539 u16 token,
540 const struct dprc_endpoint *endpoint1,
541 struct dprc_endpoint *endpoint2,
542 int *state);
543
544int dprc_get_api_version(struct fsl_mc_io *mc_io, 301int dprc_get_api_version(struct fsl_mc_io *mc_io,
545 u32 cmd_flags, 302 u32 cmd_flags,
546 u16 *major_ver, 303 u16 *major_ver,
diff --git a/drivers/staging/gdm724x/gdm_endian.c b/drivers/staging/gdm724x/gdm_endian.c
index d7144e7afa32..d0b43e20ec06 100644
--- a/drivers/staging/gdm724x/gdm_endian.c
+++ b/drivers/staging/gdm724x/gdm_endian.c
@@ -22,34 +22,34 @@ void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian)
22 ed->dev_ed = ENDIANNESS_LITTLE; 22 ed->dev_ed = ENDIANNESS_LITTLE;
23} 23}
24 24
25u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x) 25__dev16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x)
26{ 26{
27 if (ed->dev_ed == ENDIANNESS_LITTLE) 27 if (ed->dev_ed == ENDIANNESS_LITTLE)
28 return cpu_to_le16(x); 28 return (__force __dev16)cpu_to_le16(x);
29 else 29 else
30 return cpu_to_be16(x); 30 return (__force __dev16)cpu_to_be16(x);
31} 31}
32 32
33u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x) 33u16 gdm_dev16_to_cpu(struct gdm_endian *ed, __dev16 x)
34{ 34{
35 if (ed->dev_ed == ENDIANNESS_LITTLE) 35 if (ed->dev_ed == ENDIANNESS_LITTLE)
36 return le16_to_cpu(x); 36 return le16_to_cpu((__force __le16)x);
37 else 37 else
38 return be16_to_cpu(x); 38 return be16_to_cpu((__force __be16)x);
39} 39}
40 40
41u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x) 41__dev32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x)
42{ 42{
43 if (ed->dev_ed == ENDIANNESS_LITTLE) 43 if (ed->dev_ed == ENDIANNESS_LITTLE)
44 return cpu_to_le32(x); 44 return (__force __dev32)cpu_to_le32(x);
45 else 45 else
46 return cpu_to_be32(x); 46 return (__force __dev32)cpu_to_be32(x);
47} 47}
48 48
49u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x) 49u32 gdm_dev32_to_cpu(struct gdm_endian *ed, __dev32 x)
50{ 50{
51 if (ed->dev_ed == ENDIANNESS_LITTLE) 51 if (ed->dev_ed == ENDIANNESS_LITTLE)
52 return le32_to_cpu(x); 52 return le32_to_cpu((__force __le32)x);
53 else 53 else
54 return be32_to_cpu(x); 54 return be32_to_cpu((__force __be32)x);
55} 55}
diff --git a/drivers/staging/gdm724x/gdm_endian.h b/drivers/staging/gdm724x/gdm_endian.h
index 6177870830e5..a785f30bb369 100644
--- a/drivers/staging/gdm724x/gdm_endian.h
+++ b/drivers/staging/gdm724x/gdm_endian.h
@@ -16,6 +16,13 @@
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18 18
19/*
20 * For data in "device-endian" byte order (device endianness is model
21 * dependent). Analogous to __leXX or __beXX.
22 */
23typedef __u32 __bitwise __dev32;
24typedef __u16 __bitwise __dev16;
25
19enum { 26enum {
20 ENDIANNESS_MIN = 0, 27 ENDIANNESS_MIN = 0,
21 ENDIANNESS_UNKNOWN, 28 ENDIANNESS_UNKNOWN,
@@ -30,9 +37,9 @@ struct gdm_endian {
30}; 37};
31 38
32void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian); 39void gdm_set_endian(struct gdm_endian *ed, u8 dev_endian);
33u16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x); 40__dev16 gdm_cpu_to_dev16(struct gdm_endian *ed, u16 x);
34u16 gdm_dev16_to_cpu(struct gdm_endian *ed, u16 x); 41u16 gdm_dev16_to_cpu(struct gdm_endian *ed, __dev16 x);
35u32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x); 42__dev32 gdm_cpu_to_dev32(struct gdm_endian *ed, u32 x);
36u32 gdm_dev32_to_cpu(struct gdm_endian *ed, u32 x); 43u32 gdm_dev32_to_cpu(struct gdm_endian *ed, __dev32 x);
37 44
38#endif /*__GDM_ENDIAN_H__*/ 45#endif /*__GDM_ENDIAN_H__*/
diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c
index e72dfa9699f3..a3e046c3f65c 100644
--- a/drivers/staging/gdm724x/gdm_lte.c
+++ b/drivers/staging/gdm724x/gdm_lte.c
@@ -198,7 +198,7 @@ static int icmp6_checksum(struct ipv6hdr *ipv6, u16 *ptr, int len)
198 memset(&pseudo_header, 0, sizeof(pseudo_header)); 198 memset(&pseudo_header, 0, sizeof(pseudo_header));
199 memcpy(&pseudo_header.ph.ph_src, &ipv6->saddr.in6_u.u6_addr8, 16); 199 memcpy(&pseudo_header.ph.ph_src, &ipv6->saddr.in6_u.u6_addr8, 16);
200 memcpy(&pseudo_header.ph.ph_dst, &ipv6->daddr.in6_u.u6_addr8, 16); 200 memcpy(&pseudo_header.ph.ph_dst, &ipv6->daddr.in6_u.u6_addr8, 16);
201 pseudo_header.ph.ph_len = ipv6->payload_len; 201 pseudo_header.ph.ph_len = be16_to_cpu(ipv6->payload_len);
202 pseudo_header.ph.ph_nxt = ipv6->nexthdr; 202 pseudo_header.ph.ph_nxt = ipv6->nexthdr;
203 203
204 w = (u16 *)&pseudo_header; 204 w = (u16 *)&pseudo_header;
@@ -560,13 +560,13 @@ void gdm_lte_event_exit(void)
560 } 560 }
561} 561}
562 562
563static u8 find_dev_index(u32 nic_type) 563static int find_dev_index(u32 nic_type)
564{ 564{
565 u8 index; 565 u8 index;
566 566
567 index = (u8)(nic_type & 0x0000000f); 567 index = (u8)(nic_type & 0x0000000f);
568 if (index > MAX_NIC_TYPE) 568 if (index >= MAX_NIC_TYPE)
569 index = 0; 569 return -EINVAL;
570 570
571 return index; 571 return index;
572} 572}
@@ -688,28 +688,24 @@ static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len)
688 struct net_device *dev; 688 struct net_device *dev;
689 struct multi_sdu *multi_sdu = (struct multi_sdu *)buf; 689 struct multi_sdu *multi_sdu = (struct multi_sdu *)buf;
690 struct sdu *sdu = NULL; 690 struct sdu *sdu = NULL;
691 struct gdm_endian *endian = phy_dev->get_endian(phy_dev->priv_dev);
691 u8 *data = (u8 *)multi_sdu->data; 692 u8 *data = (u8 *)multi_sdu->data;
692 u16 i = 0; 693 u16 i = 0;
693 u16 num_packet; 694 u16 num_packet;
694 u16 hci_len; 695 u16 hci_len;
695 u16 cmd_evt; 696 u16 cmd_evt;
696 u32 nic_type; 697 u32 nic_type;
697 u8 index; 698 int index;
698 699
699 hci_len = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev), 700 hci_len = gdm_dev16_to_cpu(endian, multi_sdu->len);
700 multi_sdu->len); 701 num_packet = gdm_dev16_to_cpu(endian, multi_sdu->num_packet);
701 num_packet = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev),
702 multi_sdu->num_packet);
703 702
704 for (i = 0; i < num_packet; i++) { 703 for (i = 0; i < num_packet; i++) {
705 sdu = (struct sdu *)data; 704 sdu = (struct sdu *)data;
706 705
707 cmd_evt = gdm_dev16_to_cpu(phy_dev-> 706 cmd_evt = gdm_dev16_to_cpu(endian, sdu->cmd_evt);
708 get_endian(phy_dev->priv_dev), sdu->cmd_evt); 707 hci_len = gdm_dev16_to_cpu(endian, sdu->len);
709 hci_len = gdm_dev16_to_cpu(phy_dev-> 708 nic_type = gdm_dev32_to_cpu(endian, sdu->nic_type);
710 get_endian(phy_dev->priv_dev), sdu->len);
711 nic_type = gdm_dev32_to_cpu(phy_dev->
712 get_endian(phy_dev->priv_dev), sdu->nic_type);
713 709
714 if (cmd_evt != LTE_RX_SDU) { 710 if (cmd_evt != LTE_RX_SDU) {
715 pr_err("rx sdu wrong hci %04x\n", cmd_evt); 711 pr_err("rx sdu wrong hci %04x\n", cmd_evt);
@@ -721,13 +717,13 @@ static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len)
721 } 717 }
722 718
723 index = find_dev_index(nic_type); 719 index = find_dev_index(nic_type);
724 if (index < MAX_NIC_TYPE) { 720 if (index < 0) {
725 dev = phy_dev->dev[index];
726 gdm_lte_netif_rx(dev, (char *)sdu->data,
727 (int)(hci_len - 12), nic_type);
728 } else {
729 pr_err("rx sdu invalid nic_type :%x\n", nic_type); 721 pr_err("rx sdu invalid nic_type :%x\n", nic_type);
722 return;
730 } 723 }
724 dev = phy_dev->dev[index];
725 gdm_lte_netif_rx(dev, (char *)sdu->data,
726 (int)(hci_len - 12), nic_type);
731 727
732 data += ((hci_len + 3) & 0xfffc) + HCI_HEADER_SIZE; 728 data += ((hci_len + 3) & 0xfffc) + HCI_HEADER_SIZE;
733 } 729 }
@@ -761,18 +757,18 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len)
761{ 757{
762 struct hci_packet *hci = (struct hci_packet *)buf; 758 struct hci_packet *hci = (struct hci_packet *)buf;
763 struct hci_pdn_table_ind *pdn_table = (struct hci_pdn_table_ind *)buf; 759 struct hci_pdn_table_ind *pdn_table = (struct hci_pdn_table_ind *)buf;
760 struct gdm_endian *endian = phy_dev->get_endian(phy_dev->priv_dev);
764 struct sdu *sdu; 761 struct sdu *sdu;
765 struct net_device *dev; 762 struct net_device *dev;
766 int ret = 0; 763 int ret = 0;
767 u16 cmd_evt; 764 u16 cmd_evt;
768 u32 nic_type; 765 u32 nic_type;
769 u8 index; 766 int index;
770 767
771 if (!len) 768 if (!len)
772 return ret; 769 return ret;
773 770
774 cmd_evt = gdm_dev16_to_cpu(phy_dev->get_endian(phy_dev->priv_dev), 771 cmd_evt = gdm_dev16_to_cpu(endian, hci->cmd_evt);
775 hci->cmd_evt);
776 772
777 dev = phy_dev->dev[0]; 773 dev = phy_dev->dev[0];
778 if (!dev) 774 if (!dev)
@@ -781,9 +777,10 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len)
781 switch (cmd_evt) { 777 switch (cmd_evt) {
782 case LTE_RX_SDU: 778 case LTE_RX_SDU:
783 sdu = (struct sdu *)hci->data; 779 sdu = (struct sdu *)hci->data;
784 nic_type = gdm_dev32_to_cpu(phy_dev-> 780 nic_type = gdm_dev32_to_cpu(endian, sdu->nic_type);
785 get_endian(phy_dev->priv_dev), sdu->nic_type);
786 index = find_dev_index(nic_type); 781 index = find_dev_index(nic_type);
782 if (index < 0)
783 return index;
787 dev = phy_dev->dev[index]; 784 dev = phy_dev->dev[index];
788 gdm_lte_netif_rx(dev, hci->data, len, nic_type); 785 gdm_lte_netif_rx(dev, hci->data, len, nic_type);
789 break; 786 break;
@@ -797,10 +794,10 @@ static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len)
797 break; 794 break;
798 case LTE_PDN_TABLE_IND: 795 case LTE_PDN_TABLE_IND:
799 pdn_table = (struct hci_pdn_table_ind *)buf; 796 pdn_table = (struct hci_pdn_table_ind *)buf;
800 nic_type = gdm_dev32_to_cpu(phy_dev-> 797 nic_type = gdm_dev32_to_cpu(endian, pdn_table->nic_type);
801 get_endian(phy_dev->priv_dev),
802 pdn_table->nic_type);
803 index = find_dev_index(nic_type); 798 index = find_dev_index(nic_type);
799 if (index < 0)
800 return index;
804 dev = phy_dev->dev[index]; 801 dev = phy_dev->dev[index];
805 gdm_lte_pdn_table(dev, buf, len); 802 gdm_lte_pdn_table(dev, buf, len);
806 /* Fall through */ 803 /* Fall through */
diff --git a/drivers/staging/gdm724x/hci_packet.h b/drivers/staging/gdm724x/hci_packet.h
index 4644f84038c9..22ce8b9477b6 100644
--- a/drivers/staging/gdm724x/hci_packet.h
+++ b/drivers/staging/gdm724x/hci_packet.h
@@ -36,8 +36,8 @@
36#define NIC_TYPE_F_VLAN 0x00100000 36#define NIC_TYPE_F_VLAN 0x00100000
37 37
38struct hci_packet { 38struct hci_packet {
39 u16 cmd_evt; 39 __dev16 cmd_evt;
40 u16 len; 40 __dev16 len;
41 u8 data[0]; 41 u8 data[0];
42} __packed; 42} __packed;
43 43
@@ -48,45 +48,45 @@ struct tlv {
48} __packed; 48} __packed;
49 49
50struct sdu_header { 50struct sdu_header {
51 u16 cmd_evt; 51 __dev16 cmd_evt;
52 u16 len; 52 __dev16 len;
53 u32 dftEpsId; 53 __dev32 dftEpsId;
54 u32 bearer_ID; 54 __dev32 bearer_ID;
55 u32 nic_type; 55 __dev32 nic_type;
56} __packed; 56} __packed;
57 57
58struct sdu { 58struct sdu {
59 u16 cmd_evt; 59 __dev16 cmd_evt;
60 u16 len; 60 __dev16 len;
61 u32 dft_eps_ID; 61 __dev32 dft_eps_ID;
62 u32 bearer_ID; 62 __dev32 bearer_ID;
63 u32 nic_type; 63 __dev32 nic_type;
64 u8 data[0]; 64 u8 data[0];
65} __packed; 65} __packed;
66 66
67struct multi_sdu { 67struct multi_sdu {
68 u16 cmd_evt; 68 __dev16 cmd_evt;
69 u16 len; 69 __dev16 len;
70 u16 num_packet; 70 __dev16 num_packet;
71 u16 reserved; 71 __dev16 reserved;
72 u8 data[0]; 72 u8 data[0];
73} __packed; 73} __packed;
74 74
75struct hci_pdn_table_ind { 75struct hci_pdn_table_ind {
76 u16 cmd_evt; 76 __dev16 cmd_evt;
77 u16 len; 77 __dev16 len;
78 u8 activate; 78 u8 activate;
79 u32 dft_eps_id; 79 __dev32 dft_eps_id;
80 u32 nic_type; 80 __dev32 nic_type;
81 u8 pdn_type; 81 u8 pdn_type;
82 u8 ipv4_addr[4]; 82 u8 ipv4_addr[4];
83 u8 ipv6_intf_id[8]; 83 u8 ipv6_intf_id[8];
84} __packed; 84} __packed;
85 85
86struct hci_connect_ind { 86struct hci_connect_ind {
87 u16 cmd_evt; 87 __dev16 cmd_evt;
88 u16 len; 88 __dev16 len;
89 u32 connect; 89 __dev32 connect;
90} __packed; 90} __packed;
91 91
92#endif /* _HCI_PACKET_H_ */ 92#endif /* _HCI_PACKET_H_ */
diff --git a/drivers/staging/greybus/Makefile b/drivers/staging/greybus/Makefile
index f337b7b70782..b26b9a35bdd5 100644
--- a/drivers/staging/greybus/Makefile
+++ b/drivers/staging/greybus/Makefile
@@ -10,9 +10,7 @@ greybus-y := core.o \
10 control.o \ 10 control.o \
11 svc.o \ 11 svc.o \
12 svc_watchdog.o \ 12 svc_watchdog.o \
13 operation.o \ 13 operation.o
14 timesync.o \
15 timesync_platform.o
16 14
17obj-$(CONFIG_GREYBUS) += greybus.o 15obj-$(CONFIG_GREYBUS) += greybus.o
18 16
diff --git a/drivers/staging/greybus/arche-apb-ctrl.c b/drivers/staging/greybus/arche-apb-ctrl.c
index 3fda0cd6bb42..02243b4fd898 100644
--- a/drivers/staging/greybus/arche-apb-ctrl.c
+++ b/drivers/staging/greybus/arche-apb-ctrl.c
@@ -168,7 +168,10 @@ static int standby_boot_seq(struct platform_device *pdev)
168 if (apb->init_disabled) 168 if (apb->init_disabled)
169 return 0; 169 return 0;
170 170
171 /* Even if it is in OFF state, then we do not want to change the state */ 171 /*
172 * Even if it is in OFF state,
173 * then we do not want to change the state
174 */
172 if (apb->state == ARCHE_PLATFORM_STATE_STANDBY || 175 if (apb->state == ARCHE_PLATFORM_STATE_STANDBY ||
173 apb->state == ARCHE_PLATFORM_STATE_OFF) 176 apb->state == ARCHE_PLATFORM_STATE_OFF)
174 return 0; 177 return 0;
@@ -461,7 +464,7 @@ static int arche_apb_ctrl_remove(struct platform_device *pdev)
461 return 0; 464 return 0;
462} 465}
463 466
464static int arche_apb_ctrl_suspend(struct device *dev) 467static int __maybe_unused arche_apb_ctrl_suspend(struct device *dev)
465{ 468{
466 /* 469 /*
467 * If timing profile permits, we may shutdown bridge 470 * If timing profile permits, we may shutdown bridge
@@ -475,7 +478,7 @@ static int arche_apb_ctrl_suspend(struct device *dev)
475 return 0; 478 return 0;
476} 479}
477 480
478static int arche_apb_ctrl_resume(struct device *dev) 481static int __maybe_unused arche_apb_ctrl_resume(struct device *dev)
479{ 482{
480 /* 483 /*
481 * Atleast for ES2 we have to meet the delay requirement between 484 * Atleast for ES2 we have to meet the delay requirement between
diff --git a/drivers/staging/greybus/arche-platform.c b/drivers/staging/greybus/arche-platform.c
index 338c2d3ee842..aac1145f1983 100644
--- a/drivers/staging/greybus/arche-platform.c
+++ b/drivers/staging/greybus/arche-platform.c
@@ -312,9 +312,11 @@ static irqreturn_t arche_platform_wd_irq(int irq, void *devid)
312 if (arche_pdata->wake_detect_state == WD_STATE_IDLE) { 312 if (arche_pdata->wake_detect_state == WD_STATE_IDLE) {
313 arche_pdata->wake_detect_start = jiffies; 313 arche_pdata->wake_detect_start = jiffies;
314 /* 314 /*
315 * In the begining, when wake/detect goes low (first time), we assume 315 * In the begining, when wake/detect goes low
316 * it is meant for coldboot and set the flag. If wake/detect line stays low 316 * (first time), we assume it is meant for coldboot
317 * beyond 30msec, then it is coldboot else fallback to standby boot. 317 * and set the flag. If wake/detect line stays low
318 * beyond 30msec, then it is coldboot else fallback
319 * to standby boot.
318 */ 320 */
319 arche_platform_set_wake_detect_state(arche_pdata, 321 arche_platform_set_wake_detect_state(arche_pdata,
320 WD_STATE_BOOT_INIT); 322 WD_STATE_BOOT_INIT);
@@ -330,7 +332,8 @@ exit:
330/* 332/*
331 * Requires arche_pdata->platform_state_mutex to be held 333 * Requires arche_pdata->platform_state_mutex to be held
332 */ 334 */
333static int arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata) 335static int
336arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdata)
334{ 337{
335 int ret; 338 int ret;
336 339
@@ -364,7 +367,8 @@ static int arche_platform_coldboot_seq(struct arche_platform_drvdata *arche_pdat
364/* 367/*
365 * Requires arche_pdata->platform_state_mutex to be held 368 * Requires arche_pdata->platform_state_mutex to be held
366 */ 369 */
367static int arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata) 370static int
371arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_pdata)
368{ 372{
369 int ret; 373 int ret;
370 374
@@ -398,7 +402,8 @@ static int arche_platform_fw_flashing_seq(struct arche_platform_drvdata *arche_p
398/* 402/*
399 * Requires arche_pdata->platform_state_mutex to be held 403 * Requires arche_pdata->platform_state_mutex to be held
400 */ 404 */
401static void arche_platform_poweroff_seq(struct arche_platform_drvdata *arche_pdata) 405static void
406arche_platform_poweroff_seq(struct arche_platform_drvdata *arche_pdata)
402{ 407{
403 unsigned long flags; 408 unsigned long flags;
404 409
@@ -561,14 +566,17 @@ static int arche_platform_probe(struct platform_device *pdev)
561 struct device_node *np = dev->of_node; 566 struct device_node *np = dev->of_node;
562 int ret; 567 int ret;
563 568
564 arche_pdata = devm_kzalloc(&pdev->dev, sizeof(*arche_pdata), GFP_KERNEL); 569 arche_pdata = devm_kzalloc(&pdev->dev, sizeof(*arche_pdata),
570 GFP_KERNEL);
565 if (!arche_pdata) 571 if (!arche_pdata)
566 return -ENOMEM; 572 return -ENOMEM;
567 573
568 /* setup svc reset gpio */ 574 /* setup svc reset gpio */
569 arche_pdata->is_reset_act_hi = of_property_read_bool(np, 575 arche_pdata->is_reset_act_hi = of_property_read_bool(np,
570 "svc,reset-active-high"); 576 "svc,reset-active-high");
571 arche_pdata->svc_reset_gpio = of_get_named_gpio(np, "svc,reset-gpio", 0); 577 arche_pdata->svc_reset_gpio = of_get_named_gpio(np,
578 "svc,reset-gpio",
579 0);
572 if (arche_pdata->svc_reset_gpio < 0) { 580 if (arche_pdata->svc_reset_gpio < 0) {
573 dev_err(dev, "failed to get reset-gpio\n"); 581 dev_err(dev, "failed to get reset-gpio\n");
574 return arche_pdata->svc_reset_gpio; 582 return arche_pdata->svc_reset_gpio;
@@ -610,7 +618,8 @@ static int arche_platform_probe(struct platform_device *pdev)
610 dev_err(dev, "failed to get svc clock-req gpio\n"); 618 dev_err(dev, "failed to get svc clock-req gpio\n");
611 return arche_pdata->svc_refclk_req; 619 return arche_pdata->svc_refclk_req;
612 } 620 }
613 ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req, "svc-clk-req"); 621 ret = devm_gpio_request(dev, arche_pdata->svc_refclk_req,
622 "svc-clk-req");
614 if (ret) { 623 if (ret) {
615 dev_err(dev, "failed to request svc-clk-req gpio: %d\n", ret); 624 dev_err(dev, "failed to request svc-clk-req gpio: %d\n", ret);
616 return ret; 625 return ret;
@@ -634,13 +643,16 @@ static int arche_platform_probe(struct platform_device *pdev)
634 arche_pdata->num_apbs = of_get_child_count(np); 643 arche_pdata->num_apbs = of_get_child_count(np);
635 dev_dbg(dev, "Number of APB's available - %d\n", arche_pdata->num_apbs); 644 dev_dbg(dev, "Number of APB's available - %d\n", arche_pdata->num_apbs);
636 645
637 arche_pdata->wake_detect_gpio = of_get_named_gpio(np, "svc,wake-detect-gpio", 0); 646 arche_pdata->wake_detect_gpio = of_get_named_gpio(np,
647 "svc,wake-detect-gpio",
648 0);
638 if (arche_pdata->wake_detect_gpio < 0) { 649 if (arche_pdata->wake_detect_gpio < 0) {
639 dev_err(dev, "failed to get wake detect gpio\n"); 650 dev_err(dev, "failed to get wake detect gpio\n");
640 return arche_pdata->wake_detect_gpio; 651 return arche_pdata->wake_detect_gpio;
641 } 652 }
642 653
643 ret = devm_gpio_request(dev, arche_pdata->wake_detect_gpio, "wake detect"); 654 ret = devm_gpio_request(dev, arche_pdata->wake_detect_gpio,
655 "wake detect");
644 if (ret) { 656 if (ret) {
645 dev_err(dev, "Failed requesting wake_detect gpio %d\n", 657 dev_err(dev, "Failed requesting wake_detect gpio %d\n",
646 arche_pdata->wake_detect_gpio); 658 arche_pdata->wake_detect_gpio);
@@ -658,10 +670,11 @@ static int arche_platform_probe(struct platform_device *pdev)
658 gpio_to_irq(arche_pdata->wake_detect_gpio); 670 gpio_to_irq(arche_pdata->wake_detect_gpio);
659 671
660 ret = devm_request_threaded_irq(dev, arche_pdata->wake_detect_irq, 672 ret = devm_request_threaded_irq(dev, arche_pdata->wake_detect_irq,
661 arche_platform_wd_irq, 673 arche_platform_wd_irq,
662 arche_platform_wd_irq_thread, 674 arche_platform_wd_irq_thread,
663 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT, 675 IRQF_TRIGGER_FALLING |
664 dev_name(dev), arche_pdata); 676 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
677 dev_name(dev), arche_pdata);
665 if (ret) { 678 if (ret) {
666 dev_err(dev, "failed to request wake detect IRQ %d\n", ret); 679 dev_err(dev, "failed to request wake detect IRQ %d\n", ret);
667 return ret; 680 return ret;
diff --git a/drivers/staging/greybus/arche_platform.h b/drivers/staging/greybus/arche_platform.h
index bd12345b82a2..c0591df9b9d6 100644
--- a/drivers/staging/greybus/arche_platform.h
+++ b/drivers/staging/greybus/arche_platform.h
@@ -10,8 +10,6 @@
10#ifndef __ARCHE_PLATFORM_H 10#ifndef __ARCHE_PLATFORM_H
11#define __ARCHE_PLATFORM_H 11#define __ARCHE_PLATFORM_H
12 12
13#include "timesync.h"
14
15enum arche_platform_state { 13enum arche_platform_state {
16 ARCHE_PLATFORM_STATE_OFF, 14 ARCHE_PLATFORM_STATE_OFF,
17 ARCHE_PLATFORM_STATE_ACTIVE, 15 ARCHE_PLATFORM_STATE_ACTIVE,
diff --git a/drivers/staging/greybus/arpc.h b/drivers/staging/greybus/arpc.h
index 7fbddfc40d83..c0b63c0130c5 100644
--- a/drivers/staging/greybus/arpc.h
+++ b/drivers/staging/greybus/arpc.h
@@ -74,7 +74,6 @@ struct arpc_response_message {
74 __u8 result; /* Result of RPC */ 74 __u8 result; /* Result of RPC */
75} __packed; 75} __packed;
76 76
77
78/* ARPC requests */ 77/* ARPC requests */
79#define ARPC_TYPE_CPORT_CONNECTED 0x01 78#define ARPC_TYPE_CPORT_CONNECTED 0x01
80#define ARPC_TYPE_CPORT_QUIESCE 0x02 79#define ARPC_TYPE_CPORT_QUIESCE 0x02
diff --git a/drivers/staging/greybus/audio_codec.c b/drivers/staging/greybus/audio_codec.c
index f8862c6d7102..25c8bb4cb0de 100644
--- a/drivers/staging/greybus/audio_codec.c
+++ b/drivers/staging/greybus/audio_codec.c
@@ -496,6 +496,11 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
496 496
497 gb_pm_runtime_put_noidle(bundle); 497 gb_pm_runtime_put_noidle(bundle);
498 498
499 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
500 sig_bits = dai->driver->playback.sig_bits;
501 else
502 sig_bits = dai->driver->capture.sig_bits;
503
499 params->state = GBAUDIO_CODEC_HWPARAMS; 504 params->state = GBAUDIO_CODEC_HWPARAMS;
500 params->format = format; 505 params->format = format;
501 params->rate = rate; 506 params->rate = rate;
@@ -689,6 +694,7 @@ static struct snd_soc_dai_driver gbaudio_dai[] = {
689 .rate_min = 48000, 694 .rate_min = 48000,
690 .channels_min = 1, 695 .channels_min = 1,
691 .channels_max = 2, 696 .channels_max = 2,
697 .sig_bits = 16,
692 }, 698 },
693 .capture = { 699 .capture = {
694 .stream_name = "I2S 0 Capture", 700 .stream_name = "I2S 0 Capture",
@@ -698,6 +704,7 @@ static struct snd_soc_dai_driver gbaudio_dai[] = {
698 .rate_min = 48000, 704 .rate_min = 48000,
699 .channels_min = 1, 705 .channels_min = 1,
700 .channels_max = 2, 706 .channels_max = 2,
707 .sig_bits = 16,
701 }, 708 },
702 .ops = &gbcodec_dai_ops, 709 .ops = &gbcodec_dai_ops,
703 }, 710 },
@@ -831,7 +838,10 @@ int gbaudio_register_module(struct gbaudio_module_info *module)
831 snd_soc_dapm_link_component_dai_widgets(codec->card, 838 snd_soc_dapm_link_component_dai_widgets(codec->card,
832 &codec->dapm); 839 &codec->dapm);
833#ifdef CONFIG_SND_JACK 840#ifdef CONFIG_SND_JACK
834 /* register jack devices for this module from codec->jack_list */ 841 /*
842 * register jack devices for this module
843 * from codec->jack_list
844 */
835 list_for_each_entry(jack, &codec->jack_list, list) { 845 list_for_each_entry(jack, &codec->jack_list, list) {
836 if ((jack == &module->headset_jack) 846 if ((jack == &module->headset_jack)
837 || (jack == &module->button_jack)) 847 || (jack == &module->button_jack))
@@ -1019,47 +1029,16 @@ static int gbcodec_remove(struct snd_soc_codec *codec)
1019 return 0; 1029 return 0;
1020} 1030}
1021 1031
1022static u8 gbcodec_reg[GBCODEC_REG_COUNT] = {
1023 [GBCODEC_CTL_REG] = GBCODEC_CTL_REG_DEFAULT,
1024 [GBCODEC_MUTE_REG] = GBCODEC_MUTE_REG_DEFAULT,
1025 [GBCODEC_PB_LVOL_REG] = GBCODEC_PB_VOL_REG_DEFAULT,
1026 [GBCODEC_PB_RVOL_REG] = GBCODEC_PB_VOL_REG_DEFAULT,
1027 [GBCODEC_CAP_LVOL_REG] = GBCODEC_CAP_VOL_REG_DEFAULT,
1028 [GBCODEC_CAP_RVOL_REG] = GBCODEC_CAP_VOL_REG_DEFAULT,
1029 [GBCODEC_APB1_MUX_REG] = GBCODEC_APB1_MUX_REG_DEFAULT,
1030 [GBCODEC_APB2_MUX_REG] = GBCODEC_APB2_MUX_REG_DEFAULT,
1031};
1032
1033static int gbcodec_write(struct snd_soc_codec *codec, unsigned int reg, 1032static int gbcodec_write(struct snd_soc_codec *codec, unsigned int reg,
1034 unsigned int value) 1033 unsigned int value)
1035{ 1034{
1036 int ret = 0; 1035 return 0;
1037
1038 if (reg == SND_SOC_NOPM)
1039 return 0;
1040
1041 BUG_ON(reg >= GBCODEC_REG_COUNT);
1042
1043 gbcodec_reg[reg] = value;
1044 dev_dbg(codec->dev, "reg[%d] = 0x%x\n", reg, value);
1045
1046 return ret;
1047} 1036}
1048 1037
1049static unsigned int gbcodec_read(struct snd_soc_codec *codec, 1038static unsigned int gbcodec_read(struct snd_soc_codec *codec,
1050 unsigned int reg) 1039 unsigned int reg)
1051{ 1040{
1052 unsigned int val = 0; 1041 return 0;
1053
1054 if (reg == SND_SOC_NOPM)
1055 return 0;
1056
1057 BUG_ON(reg >= GBCODEC_REG_COUNT);
1058
1059 val = gbcodec_reg[reg];
1060 dev_dbg(codec->dev, "reg[%d] = 0x%x\n", reg, val);
1061
1062 return val;
1063} 1042}
1064 1043
1065static struct snd_soc_codec_driver soc_codec_dev_gbaudio = { 1044static struct snd_soc_codec_driver soc_codec_dev_gbaudio = {
@@ -1069,10 +1048,6 @@ static struct snd_soc_codec_driver soc_codec_dev_gbaudio = {
1069 .read = gbcodec_read, 1048 .read = gbcodec_read,
1070 .write = gbcodec_write, 1049 .write = gbcodec_write,
1071 1050
1072 .reg_cache_size = GBCODEC_REG_COUNT,
1073 .reg_cache_default = gbcodec_reg_defaults,
1074 .reg_word_size = 1,
1075
1076 .idle_bias_off = true, 1051 .idle_bias_off = true,
1077 .ignore_pmdown_time = 1, 1052 .ignore_pmdown_time = 1,
1078}; 1053};
diff --git a/drivers/staging/greybus/audio_codec.h b/drivers/staging/greybus/audio_codec.h
index 62fd93939a1f..6fb064c69a36 100644
--- a/drivers/staging/greybus/audio_codec.h
+++ b/drivers/staging/greybus/audio_codec.h
@@ -24,18 +24,6 @@ enum {
24 NUM_CODEC_DAIS, 24 NUM_CODEC_DAIS,
25}; 25};
26 26
27enum gbcodec_reg_index {
28 GBCODEC_CTL_REG,
29 GBCODEC_MUTE_REG,
30 GBCODEC_PB_LVOL_REG,
31 GBCODEC_PB_RVOL_REG,
32 GBCODEC_CAP_LVOL_REG,
33 GBCODEC_CAP_RVOL_REG,
34 GBCODEC_APB1_MUX_REG,
35 GBCODEC_APB2_MUX_REG,
36 GBCODEC_REG_COUNT
37};
38
39/* device_type should be same as defined in audio.h (Android media layer) */ 27/* device_type should be same as defined in audio.h (Android media layer) */
40enum { 28enum {
41 GBAUDIO_DEVICE_NONE = 0x0, 29 GBAUDIO_DEVICE_NONE = 0x0,
@@ -51,42 +39,9 @@ enum {
51 GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10, 39 GBAUDIO_DEVICE_IN_WIRED_HEADSET = GBAUDIO_DEVICE_BIT_IN | 0x10,
52}; 40};
53 41
54/* bit 0-SPK, 1-HP, 2-DAC,
55 * 4-MIC, 5-HSMIC, 6-MIC2
56 */
57#define GBCODEC_CTL_REG_DEFAULT 0x00
58
59/* bit 0,1 - APB1-PB-L/R
60 * bit 2,3 - APB2-PB-L/R
61 * bit 4,5 - APB1-Cap-L/R
62 * bit 6,7 - APB2-Cap-L/R
63 */
64#define GBCODEC_MUTE_REG_DEFAULT 0x00
65
66/* 0-127 steps */
67#define GBCODEC_PB_VOL_REG_DEFAULT 0x00
68#define GBCODEC_CAP_VOL_REG_DEFAULT 0x00
69
70/* bit 0,1,2 - PB stereo, left, right
71 * bit 8,9,10 - Cap stereo, left, right
72 */
73#define GBCODEC_APB1_MUX_REG_DEFAULT 0x00
74#define GBCODEC_APB2_MUX_REG_DEFAULT 0x00
75
76#define GBCODEC_JACK_MASK 0x0000FFFF 42#define GBCODEC_JACK_MASK 0x0000FFFF
77#define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000 43#define GBCODEC_JACK_BUTTON_MASK 0xFFFF0000
78 44
79static const u8 gbcodec_reg_defaults[GBCODEC_REG_COUNT] = {
80 GBCODEC_CTL_REG_DEFAULT,
81 GBCODEC_MUTE_REG_DEFAULT,
82 GBCODEC_PB_VOL_REG_DEFAULT,
83 GBCODEC_PB_VOL_REG_DEFAULT,
84 GBCODEC_CAP_VOL_REG_DEFAULT,
85 GBCODEC_CAP_VOL_REG_DEFAULT,
86 GBCODEC_APB1_MUX_REG_DEFAULT,
87 GBCODEC_APB2_MUX_REG_DEFAULT,
88};
89
90enum gbaudio_codec_state { 45enum gbaudio_codec_state {
91 GBAUDIO_CODEC_SHUTDOWN = 0, 46 GBAUDIO_CODEC_SHUTDOWN = 0,
92 GBAUDIO_CODEC_STARTUP, 47 GBAUDIO_CODEC_STARTUP,
@@ -116,7 +71,6 @@ struct gbaudio_codec_info {
116 /* to maintain runtime stream params for each DAI */ 71 /* to maintain runtime stream params for each DAI */
117 struct list_head dai_list; 72 struct list_head dai_list;
118 struct mutex lock; 73 struct mutex lock;
119 u8 reg[GBCODEC_REG_COUNT];
120}; 74};
121 75
122struct gbaudio_widget { 76struct gbaudio_widget {
diff --git a/drivers/staging/greybus/audio_gb.c b/drivers/staging/greybus/audio_gb.c
index 42f287dd7b84..7884d8482dc0 100644
--- a/drivers/staging/greybus/audio_gb.c
+++ b/drivers/staging/greybus/audio_gb.c
@@ -108,7 +108,7 @@ int gb_audio_gb_disable_widget(struct gb_connection *connection,
108EXPORT_SYMBOL_GPL(gb_audio_gb_disable_widget); 108EXPORT_SYMBOL_GPL(gb_audio_gb_disable_widget);
109 109
110int gb_audio_gb_get_pcm(struct gb_connection *connection, u16 data_cport, 110int gb_audio_gb_get_pcm(struct gb_connection *connection, u16 data_cport,
111 uint32_t *format, uint32_t *rate, u8 *channels, 111 u32 *format, u32 *rate, u8 *channels,
112 u8 *sig_bits) 112 u8 *sig_bits)
113{ 113{
114 struct gb_audio_get_pcm_request req; 114 struct gb_audio_get_pcm_request req;
@@ -132,7 +132,7 @@ int gb_audio_gb_get_pcm(struct gb_connection *connection, u16 data_cport,
132EXPORT_SYMBOL_GPL(gb_audio_gb_get_pcm); 132EXPORT_SYMBOL_GPL(gb_audio_gb_get_pcm);
133 133
134int gb_audio_gb_set_pcm(struct gb_connection *connection, u16 data_cport, 134int gb_audio_gb_set_pcm(struct gb_connection *connection, u16 data_cport,
135 uint32_t format, uint32_t rate, u8 channels, 135 u32 format, u32 rate, u8 channels,
136 u8 sig_bits) 136 u8 sig_bits)
137{ 137{
138 struct gb_audio_set_pcm_request req; 138 struct gb_audio_set_pcm_request req;
diff --git a/drivers/staging/greybus/audio_module.c b/drivers/staging/greybus/audio_module.c
index 17a9948b1ba1..094c3be79b33 100644
--- a/drivers/staging/greybus/audio_module.c
+++ b/drivers/staging/greybus/audio_module.c
@@ -134,7 +134,7 @@ static int gbaudio_request_stream(struct gbaudio_module_info *module,
134 struct gb_audio_streaming_event_request *req) 134 struct gb_audio_streaming_event_request *req)
135{ 135{
136 dev_warn(module->dev, "Audio Event received: cport: %u, event: %u\n", 136 dev_warn(module->dev, "Audio Event received: cport: %u, event: %u\n",
137 req->data_cport, req->event); 137 le16_to_cpu(req->data_cport), req->event);
138 138
139 return 0; 139 return 0;
140} 140}
diff --git a/drivers/staging/greybus/audio_topology.c b/drivers/staging/greybus/audio_topology.c
index 8b216ca99cf9..07fac3948f3a 100644
--- a/drivers/staging/greybus/audio_topology.c
+++ b/drivers/staging/greybus/audio_topology.c
@@ -141,13 +141,14 @@ static const char **gb_generate_enum_strings(struct gbaudio_module_info *gb,
141{ 141{
142 const char **strings; 142 const char **strings;
143 int i; 143 int i;
144 unsigned int items;
144 __u8 *data; 145 __u8 *data;
145 146
146 strings = devm_kzalloc(gb->dev, sizeof(char *) * gbenum->items, 147 items = le32_to_cpu(gbenum->items);
147 GFP_KERNEL); 148 strings = devm_kzalloc(gb->dev, sizeof(char *) * items, GFP_KERNEL);
148 data = gbenum->names; 149 data = gbenum->names;
149 150
150 for (i = 0; i < gbenum->items; i++) { 151 for (i = 0; i < items; i++) {
151 strings[i] = (const char *)data; 152 strings[i] = (const char *)data;
152 while (*data != '\0') 153 while (*data != '\0')
153 data++; 154 data++;
@@ -185,11 +186,11 @@ static int gbcodec_mixer_ctl_info(struct snd_kcontrol *kcontrol,
185 switch (info->type) { 186 switch (info->type) {
186 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN: 187 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN:
187 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER: 188 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER:
188 uinfo->value.integer.min = info->value.integer.min; 189 uinfo->value.integer.min = le32_to_cpu(info->value.integer.min);
189 uinfo->value.integer.max = info->value.integer.max; 190 uinfo->value.integer.max = le32_to_cpu(info->value.integer.max);
190 break; 191 break;
191 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: 192 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED:
192 max = info->value.enumerated.items; 193 max = le32_to_cpu(info->value.enumerated.items);
193 uinfo->value.enumerated.items = max; 194 uinfo->value.enumerated.items = max;
194 if (uinfo->value.enumerated.item > max - 1) 195 if (uinfo->value.enumerated.item > max - 1)
195 uinfo->value.enumerated.item = max - 1; 196 uinfo->value.enumerated.item = max - 1;
@@ -249,17 +250,17 @@ static int gbcodec_mixer_ctl_get(struct snd_kcontrol *kcontrol,
249 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN: 250 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN:
250 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER: 251 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER:
251 ucontrol->value.integer.value[0] = 252 ucontrol->value.integer.value[0] =
252 gbvalue.value.integer_value[0]; 253 le32_to_cpu(gbvalue.value.integer_value[0]);
253 if (data->vcount == 2) 254 if (data->vcount == 2)
254 ucontrol->value.integer.value[1] = 255 ucontrol->value.integer.value[1] =
255 gbvalue.value.integer_value[1]; 256 le32_to_cpu(gbvalue.value.integer_value[1]);
256 break; 257 break;
257 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: 258 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED:
258 ucontrol->value.enumerated.item[0] = 259 ucontrol->value.enumerated.item[0] =
259 gbvalue.value.enumerated_item[0]; 260 le32_to_cpu(gbvalue.value.enumerated_item[0]);
260 if (data->vcount == 2) 261 if (data->vcount == 2)
261 ucontrol->value.enumerated.item[1] = 262 ucontrol->value.enumerated.item[1] =
262 gbvalue.value.enumerated_item[1]; 263 le32_to_cpu(gbvalue.value.enumerated_item[1]);
263 break; 264 break;
264 default: 265 default:
265 dev_err(codec->dev, "Invalid type: %d for %s:kcontrol\n", 266 dev_err(codec->dev, "Invalid type: %d for %s:kcontrol\n",
@@ -296,17 +297,17 @@ static int gbcodec_mixer_ctl_put(struct snd_kcontrol *kcontrol,
296 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN: 297 case GB_AUDIO_CTL_ELEM_TYPE_BOOLEAN:
297 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER: 298 case GB_AUDIO_CTL_ELEM_TYPE_INTEGER:
298 gbvalue.value.integer_value[0] = 299 gbvalue.value.integer_value[0] =
299 ucontrol->value.integer.value[0]; 300 cpu_to_le32(ucontrol->value.integer.value[0]);
300 if (data->vcount == 2) 301 if (data->vcount == 2)
301 gbvalue.value.integer_value[1] = 302 gbvalue.value.integer_value[1] =
302 ucontrol->value.integer.value[1]; 303 cpu_to_le32(ucontrol->value.integer.value[1]);
303 break; 304 break;
304 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED: 305 case GB_AUDIO_CTL_ELEM_TYPE_ENUMERATED:
305 gbvalue.value.enumerated_item[0] = 306 gbvalue.value.enumerated_item[0] =
306 ucontrol->value.enumerated.item[0]; 307 cpu_to_le32(ucontrol->value.enumerated.item[0]);
307 if (data->vcount == 2) 308 if (data->vcount == 2)
308 gbvalue.value.enumerated_item[1] = 309 gbvalue.value.enumerated_item[1] =
309 ucontrol->value.enumerated.item[1]; 310 cpu_to_le32(ucontrol->value.enumerated.item[1]);
310 break; 311 break;
311 default: 312 default:
312 dev_err(codec->dev, "Invalid type: %d for %s:kcontrol\n", 313 dev_err(codec->dev, "Invalid type: %d for %s:kcontrol\n",
@@ -361,8 +362,8 @@ static int gbcodec_mixer_dapm_ctl_info(struct snd_kcontrol *kcontrol,
361 info = (struct gb_audio_ctl_elem_info *)data->info; 362 info = (struct gb_audio_ctl_elem_info *)data->info;
362 363
363 /* update uinfo */ 364 /* update uinfo */
364 platform_max = info->value.integer.max; 365 platform_max = le32_to_cpu(info->value.integer.max);
365 platform_min = info->value.integer.min; 366 platform_min = le32_to_cpu(info->value.integer.min);
366 367
367 if (platform_max == 1 && 368 if (platform_max == 1 &&
368 !strnstr(kcontrol->id.name, " Volume", NAME_SIZE)) 369 !strnstr(kcontrol->id.name, " Volume", NAME_SIZE))
@@ -371,12 +372,8 @@ static int gbcodec_mixer_dapm_ctl_info(struct snd_kcontrol *kcontrol,
371 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 372 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
372 373
373 uinfo->count = data->vcount; 374 uinfo->count = data->vcount;
374 uinfo->value.integer.min = 0; 375 uinfo->value.integer.min = platform_min;
375 if (info->value.integer.min < 0 && 376 uinfo->value.integer.max = platform_max;
376 (uinfo->type == SNDRV_CTL_ELEM_TYPE_INTEGER))
377 uinfo->value.integer.max = platform_max - platform_min;
378 else
379 uinfo->value.integer.max = platform_max;
380 377
381 return 0; 378 return 0;
382} 379}
@@ -424,7 +421,8 @@ static int gbcodec_mixer_dapm_ctl_get(struct snd_kcontrol *kcontrol,
424 return ret; 421 return ret;
425 } 422 }
426 /* update ucontrol */ 423 /* update ucontrol */
427 ucontrol->value.integer.value[0] = gbvalue.value.integer_value[0]; 424 ucontrol->value.integer.value[0] =
425 le32_to_cpu(gbvalue.value.integer_value[0]);
428 426
429 return ret; 427 return ret;
430} 428}
@@ -458,7 +456,7 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
458 "GB: Control '%s' is stereo, which is not supported\n", 456 "GB: Control '%s' is stereo, which is not supported\n",
459 kcontrol->id.name); 457 kcontrol->id.name);
460 458
461 max = info->value.integer.max; 459 max = le32_to_cpu(info->value.integer.max);
462 mask = (1 << fls(max)) - 1; 460 mask = (1 << fls(max)) - 1;
463 val = ucontrol->value.integer.value[0] & mask; 461 val = ucontrol->value.integer.value[0] & mask;
464 connect = !!val; 462 connect = !!val;
@@ -474,7 +472,7 @@ static int gbcodec_mixer_dapm_ctl_put(struct snd_kcontrol *kcontrol,
474 connect); 472 connect);
475 } 473 }
476 gbvalue.value.integer_value[0] = 474 gbvalue.value.integer_value[0] =
477 ucontrol->value.integer.value[0]; 475 cpu_to_le32(ucontrol->value.integer.value[0]);
478 476
479 ret = gb_pm_runtime_get_sync(bundle); 477 ret = gb_pm_runtime_get_sync(bundle);
480 if (ret) 478 if (ret)
@@ -588,10 +586,11 @@ static int gbcodec_enum_ctl_get(struct snd_kcontrol *kcontrol,
588 return ret; 586 return ret;
589 } 587 }
590 588
591 ucontrol->value.enumerated.item[0] = gbvalue.value.enumerated_item[0]; 589 ucontrol->value.enumerated.item[0] =
590 le32_to_cpu(gbvalue.value.enumerated_item[0]);
592 if (e->shift_l != e->shift_r) 591 if (e->shift_l != e->shift_r)
593 ucontrol->value.enumerated.item[1] = 592 ucontrol->value.enumerated.item[1] =
594 gbvalue.value.enumerated_item[1]; 593 le32_to_cpu(gbvalue.value.enumerated_item[1]);
595 594
596 return 0; 595 return 0;
597} 596}
@@ -617,13 +616,14 @@ static int gbcodec_enum_ctl_put(struct snd_kcontrol *kcontrol,
617 616
618 if (ucontrol->value.enumerated.item[0] > e->max - 1) 617 if (ucontrol->value.enumerated.item[0] > e->max - 1)
619 return -EINVAL; 618 return -EINVAL;
620 gbvalue.value.enumerated_item[0] = ucontrol->value.enumerated.item[0]; 619 gbvalue.value.enumerated_item[0] =
620 cpu_to_le32(ucontrol->value.enumerated.item[0]);
621 621
622 if (e->shift_l != e->shift_r) { 622 if (e->shift_l != e->shift_r) {
623 if (ucontrol->value.enumerated.item[1] > e->max - 1) 623 if (ucontrol->value.enumerated.item[1] > e->max - 1)
624 return -EINVAL; 624 return -EINVAL;
625 gbvalue.value.enumerated_item[1] = 625 gbvalue.value.enumerated_item[1] =
626 ucontrol->value.enumerated.item[1]; 626 cpu_to_le32(ucontrol->value.enumerated.item[1]);
627 } 627 }
628 628
629 bundle = to_gb_bundle(module->dev); 629 bundle = to_gb_bundle(module->dev);
@@ -660,13 +660,13 @@ static int gbaudio_tplg_create_enum_kctl(struct gbaudio_module_info *gb,
660 gb_enum = &ctl->info.value.enumerated; 660 gb_enum = &ctl->info.value.enumerated;
661 661
662 /* since count=1, and reg is dummy */ 662 /* since count=1, and reg is dummy */
663 gbe->max = gb_enum->items; 663 gbe->max = le32_to_cpu(gb_enum->items);
664 gbe->texts = gb_generate_enum_strings(gb, gb_enum); 664 gbe->texts = gb_generate_enum_strings(gb, gb_enum);
665 665
666 /* debug enum info */ 666 /* debug enum info */
667 dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gb_enum->items, 667 dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->max,
668 gb_enum->names_length); 668 le16_to_cpu(gb_enum->names_length));
669 for (i = 0; i < gb_enum->items; i++) 669 for (i = 0; i < gbe->max; i++)
670 dev_dbg(gb->dev, "src[%d]: %s\n", i, gbe->texts[i]); 670 dev_dbg(gb->dev, "src[%d]: %s\n", i, gbe->texts[i]);
671 671
672 *kctl = (struct snd_kcontrol_new) 672 *kctl = (struct snd_kcontrol_new)
@@ -695,7 +695,7 @@ static int gbaudio_tplg_create_kcontrol(struct gbaudio_module_info *gb,
695 if (!ctldata) 695 if (!ctldata)
696 return -ENOMEM; 696 return -ENOMEM;
697 ctldata->ctl_id = ctl->id; 697 ctldata->ctl_id = ctl->id;
698 ctldata->data_cport = ctl->data_cport; 698 ctldata->data_cport = le16_to_cpu(ctl->data_cport);
699 ctldata->access = ctl->access; 699 ctldata->access = ctl->access;
700 ctldata->vcount = ctl->count_values; 700 ctldata->vcount = ctl->count_values;
701 ctldata->info = &ctl->info; 701 ctldata->info = &ctl->info;
@@ -869,13 +869,13 @@ static int gbaudio_tplg_create_enum_ctl(struct gbaudio_module_info *gb,
869 gb_enum = &ctl->info.value.enumerated; 869 gb_enum = &ctl->info.value.enumerated;
870 870
871 /* since count=1, and reg is dummy */ 871 /* since count=1, and reg is dummy */
872 gbe->max = gb_enum->items; 872 gbe->max = le32_to_cpu(gb_enum->items);
873 gbe->texts = gb_generate_enum_strings(gb, gb_enum); 873 gbe->texts = gb_generate_enum_strings(gb, gb_enum);
874 874
875 /* debug enum info */ 875 /* debug enum info */
876 dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gb_enum->items, 876 dev_dbg(gb->dev, "Max:%d, name_length:%d\n", gbe->max,
877 gb_enum->names_length); 877 le16_to_cpu(gb_enum->names_length));
878 for (i = 0; i < gb_enum->items; i++) 878 for (i = 0; i < gbe->max; i++)
879 dev_dbg(gb->dev, "src[%d]: %s\n", i, gbe->texts[i]); 879 dev_dbg(gb->dev, "src[%d]: %s\n", i, gbe->texts[i]);
880 880
881 *kctl = (struct snd_kcontrol_new) 881 *kctl = (struct snd_kcontrol_new)
@@ -895,7 +895,7 @@ static int gbaudio_tplg_create_mixer_ctl(struct gbaudio_module_info *gb,
895 if (!ctldata) 895 if (!ctldata)
896 return -ENOMEM; 896 return -ENOMEM;
897 ctldata->ctl_id = ctl->id; 897 ctldata->ctl_id = ctl->id;
898 ctldata->data_cport = ctl->data_cport; 898 ctldata->data_cport = le16_to_cpu(ctl->data_cport);
899 ctldata->access = ctl->access; 899 ctldata->access = ctl->access;
900 ctldata->vcount = ctl->count_values; 900 ctldata->vcount = ctl->count_values;
901 ctldata->info = &ctl->info; 901 ctldata->info = &ctl->info;
@@ -1041,10 +1041,10 @@ static int gbaudio_tplg_create_widget(struct gbaudio_module_info *module,
1041 csize = offsetof(struct gb_audio_control, info); 1041 csize = offsetof(struct gb_audio_control, info);
1042 csize += offsetof(struct gb_audio_ctl_elem_info, value); 1042 csize += offsetof(struct gb_audio_ctl_elem_info, value);
1043 csize += offsetof(struct gb_audio_enumerated, names); 1043 csize += offsetof(struct gb_audio_enumerated, names);
1044 csize += gbenum->names_length; 1044 csize += le16_to_cpu(gbenum->names_length);
1045 control->texts = (const char * const *) 1045 control->texts = (const char * const *)
1046 gb_generate_enum_strings(module, gbenum); 1046 gb_generate_enum_strings(module, gbenum);
1047 control->items = gbenum->items; 1047 control->items = le32_to_cpu(gbenum->items);
1048 } else { 1048 } else {
1049 csize = sizeof(struct gb_audio_control); 1049 csize = sizeof(struct gb_audio_control);
1050 } 1050 }
@@ -1189,10 +1189,10 @@ static int gbaudio_tplg_process_kcontrols(struct gbaudio_module_info *module,
1189 csize = offsetof(struct gb_audio_control, info); 1189 csize = offsetof(struct gb_audio_control, info);
1190 csize += offsetof(struct gb_audio_ctl_elem_info, value); 1190 csize += offsetof(struct gb_audio_ctl_elem_info, value);
1191 csize += offsetof(struct gb_audio_enumerated, names); 1191 csize += offsetof(struct gb_audio_enumerated, names);
1192 csize += gbenum->names_length; 1192 csize += le16_to_cpu(gbenum->names_length);
1193 control->texts = (const char * const *) 1193 control->texts = (const char * const *)
1194 gb_generate_enum_strings(module, gbenum); 1194 gb_generate_enum_strings(module, gbenum);
1195 control->items = gbenum->items; 1195 control->items = le32_to_cpu(gbenum->items);
1196 } else { 1196 } else {
1197 csize = sizeof(struct gb_audio_control); 1197 csize = sizeof(struct gb_audio_control);
1198 } 1198 }
@@ -1312,7 +1312,7 @@ static int gbaudio_tplg_process_routes(struct gbaudio_module_info *module,
1312 goto error; 1312 goto error;
1313 } 1313 }
1314 dev_dbg(module->dev, "Route {%s, %s, %s}\n", dapm_routes->sink, 1314 dev_dbg(module->dev, "Route {%s, %s, %s}\n", dapm_routes->sink,
1315 (dapm_routes->control) ? dapm_routes->control:"NULL", 1315 (dapm_routes->control) ? dapm_routes->control : "NULL",
1316 dapm_routes->source); 1316 dapm_routes->source);
1317 dapm_routes++; 1317 dapm_routes++;
1318 curr++; 1318 curr++;
@@ -1335,11 +1335,12 @@ static int gbaudio_tplg_process_header(struct gbaudio_module_info *module,
1335 1335
1336 /* update block offset */ 1336 /* update block offset */
1337 module->dai_offset = (unsigned long)&tplg_data->data; 1337 module->dai_offset = (unsigned long)&tplg_data->data;
1338 module->control_offset = module->dai_offset + tplg_data->size_dais; 1338 module->control_offset = module->dai_offset +
1339 le32_to_cpu(tplg_data->size_dais);
1339 module->widget_offset = module->control_offset + 1340 module->widget_offset = module->control_offset +
1340 tplg_data->size_controls; 1341 le32_to_cpu(tplg_data->size_controls);
1341 module->route_offset = module->widget_offset + 1342 module->route_offset = module->widget_offset +
1342 tplg_data->size_widgets; 1343 le32_to_cpu(tplg_data->size_widgets);
1343 1344
1344 dev_dbg(module->dev, "DAI offset is 0x%lx\n", module->dai_offset); 1345 dev_dbg(module->dev, "DAI offset is 0x%lx\n", module->dai_offset);
1345 dev_dbg(module->dev, "control offset is %lx\n", 1346 dev_dbg(module->dev, "control offset is %lx\n",
@@ -1357,6 +1358,7 @@ int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
1357 struct gb_audio_control *controls; 1358 struct gb_audio_control *controls;
1358 struct gb_audio_widget *widgets; 1359 struct gb_audio_widget *widgets;
1359 struct gb_audio_route *routes; 1360 struct gb_audio_route *routes;
1361 unsigned int jack_type;
1360 1362
1361 if (!tplg_data) 1363 if (!tplg_data)
1362 return -EINVAL; 1364 return -EINVAL;
@@ -1399,10 +1401,10 @@ int gbaudio_tplg_parse_data(struct gbaudio_module_info *module,
1399 dev_dbg(module->dev, "Route parsing finished\n"); 1401 dev_dbg(module->dev, "Route parsing finished\n");
1400 1402
1401 /* parse jack capabilities */ 1403 /* parse jack capabilities */
1402 if (tplg_data->jack_type) { 1404 jack_type = le32_to_cpu(tplg_data->jack_type);
1403 module->jack_mask = tplg_data->jack_type & GBCODEC_JACK_MASK; 1405 if (jack_type) {
1404 module->button_mask = tplg_data->jack_type & 1406 module->jack_mask = jack_type & GBCODEC_JACK_MASK;
1405 GBCODEC_JACK_BUTTON_MASK; 1407 module->button_mask = jack_type & GBCODEC_JACK_BUTTON_MASK;
1406 } 1408 }
1407 1409
1408 return ret; 1410 return ret;
diff --git a/drivers/staging/greybus/authentication.c b/drivers/staging/greybus/authentication.c
index 168626ba0c03..6c5dcb1c226b 100644
--- a/drivers/staging/greybus/authentication.c
+++ b/drivers/staging/greybus/authentication.c
@@ -16,7 +16,6 @@
16 16
17#include "greybus_authentication.h" 17#include "greybus_authentication.h"
18#include "firmware.h" 18#include "firmware.h"
19#include "greybus.h"
20 19
21#define CAP_TIMEOUT_MS 1000 20#define CAP_TIMEOUT_MS 1000
22 21
diff --git a/drivers/staging/greybus/bootrom.c b/drivers/staging/greybus/bootrom.c
index 5f90721bcc51..06df0ce03150 100644
--- a/drivers/staging/greybus/bootrom.c
+++ b/drivers/staging/greybus/bootrom.c
@@ -53,7 +53,8 @@ static void free_firmware(struct gb_bootrom *bootrom)
53static void gb_bootrom_timedout(struct work_struct *work) 53static void gb_bootrom_timedout(struct work_struct *work)
54{ 54{
55 struct delayed_work *dwork = to_delayed_work(work); 55 struct delayed_work *dwork = to_delayed_work(work);
56 struct gb_bootrom *bootrom = container_of(dwork, struct gb_bootrom, dwork); 56 struct gb_bootrom *bootrom = container_of(dwork,
57 struct gb_bootrom, dwork);
57 struct device *dev = &bootrom->connection->bundle->dev; 58 struct device *dev = &bootrom->connection->bundle->dev;
58 const char *reason; 59 const char *reason;
59 60
@@ -187,7 +188,8 @@ static int find_firmware(struct gb_bootrom *bootrom, u8 stage)
187static int gb_bootrom_firmware_size_request(struct gb_operation *op) 188static int gb_bootrom_firmware_size_request(struct gb_operation *op)
188{ 189{
189 struct gb_bootrom *bootrom = gb_connection_get_data(op->connection); 190 struct gb_bootrom *bootrom = gb_connection_get_data(op->connection);
190 struct gb_bootrom_firmware_size_request *size_request = op->request->payload; 191 struct gb_bootrom_firmware_size_request *size_request =
192 op->request->payload;
191 struct gb_bootrom_firmware_size_response *size_response; 193 struct gb_bootrom_firmware_size_response *size_response;
192 struct device *dev = &op->connection->bundle->dev; 194 struct device *dev = &op->connection->bundle->dev;
193 int ret; 195 int ret;
@@ -220,7 +222,8 @@ static int gb_bootrom_firmware_size_request(struct gb_operation *op)
220 size_response = op->response->payload; 222 size_response = op->response->payload;
221 size_response->size = cpu_to_le32(bootrom->fw->size); 223 size_response->size = cpu_to_le32(bootrom->fw->size);
222 224
223 dev_dbg(dev, "%s: firmware size %d bytes\n", __func__, size_response->size); 225 dev_dbg(dev, "%s: firmware size %d bytes\n",
226 __func__, size_response->size);
224 227
225unlock: 228unlock:
226 mutex_unlock(&bootrom->mutex); 229 mutex_unlock(&bootrom->mutex);
@@ -287,8 +290,8 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
287 firmware_response = op->response->payload; 290 firmware_response = op->response->payload;
288 memcpy(firmware_response->data, fw->data + offset, size); 291 memcpy(firmware_response->data, fw->data + offset, size);
289 292
290 dev_dbg(dev, "responding with firmware (offs = %u, size = %u)\n", offset, 293 dev_dbg(dev, "responding with firmware (offs = %u, size = %u)\n",
291 size); 294 offset, size);
292 295
293unlock: 296unlock:
294 mutex_unlock(&bootrom->mutex); 297 mutex_unlock(&bootrom->mutex);
diff --git a/drivers/staging/greybus/camera.c b/drivers/staging/greybus/camera.c
index 0ee291ca2c72..a64517eabff4 100644
--- a/drivers/staging/greybus/camera.c
+++ b/drivers/staging/greybus/camera.c
@@ -1067,22 +1067,22 @@ struct gb_camera_debugfs_entry {
1067static const struct gb_camera_debugfs_entry gb_camera_debugfs_entries[] = { 1067static const struct gb_camera_debugfs_entry gb_camera_debugfs_entries[] = {
1068 { 1068 {
1069 .name = "capabilities", 1069 .name = "capabilities",
1070 .mask = S_IFREG | S_IRUGO, 1070 .mask = S_IFREG | 0444,
1071 .buffer = GB_CAMERA_DEBUGFS_BUFFER_CAPABILITIES, 1071 .buffer = GB_CAMERA_DEBUGFS_BUFFER_CAPABILITIES,
1072 .execute = gb_camera_debugfs_capabilities, 1072 .execute = gb_camera_debugfs_capabilities,
1073 }, { 1073 }, {
1074 .name = "configure_streams", 1074 .name = "configure_streams",
1075 .mask = S_IFREG | S_IRUGO | S_IWUGO, 1075 .mask = S_IFREG | 0666,
1076 .buffer = GB_CAMERA_DEBUGFS_BUFFER_STREAMS, 1076 .buffer = GB_CAMERA_DEBUGFS_BUFFER_STREAMS,
1077 .execute = gb_camera_debugfs_configure_streams, 1077 .execute = gb_camera_debugfs_configure_streams,
1078 }, { 1078 }, {
1079 .name = "capture", 1079 .name = "capture",
1080 .mask = S_IFREG | S_IRUGO | S_IWUGO, 1080 .mask = S_IFREG | 0666,
1081 .buffer = GB_CAMERA_DEBUGFS_BUFFER_CAPTURE, 1081 .buffer = GB_CAMERA_DEBUGFS_BUFFER_CAPTURE,
1082 .execute = gb_camera_debugfs_capture, 1082 .execute = gb_camera_debugfs_capture,
1083 }, { 1083 }, {
1084 .name = "flush", 1084 .name = "flush",
1085 .mask = S_IFREG | S_IRUGO | S_IWUGO, 1085 .mask = S_IFREG | 0666,
1086 .buffer = GB_CAMERA_DEBUGFS_BUFFER_FLUSH, 1086 .buffer = GB_CAMERA_DEBUGFS_BUFFER_FLUSH,
1087 .execute = gb_camera_debugfs_flush, 1087 .execute = gb_camera_debugfs_flush,
1088 }, 1088 },
@@ -1097,7 +1097,7 @@ static ssize_t gb_camera_debugfs_read(struct file *file, char __user *buf,
1097 ssize_t ret; 1097 ssize_t ret;
1098 1098
1099 /* For read-only entries the operation is triggered by a read. */ 1099 /* For read-only entries the operation is triggered by a read. */
1100 if (!(op->mask & S_IWUGO)) { 1100 if (!(op->mask & 0222)) {
1101 ret = op->execute(gcam, NULL, 0); 1101 ret = op->execute(gcam, NULL, 0);
1102 if (ret < 0) 1102 if (ret < 0)
1103 return ret; 1103 return ret;
diff --git a/drivers/staging/greybus/connection.c b/drivers/staging/greybus/connection.c
index 557075147f2d..1bf0ee403106 100644
--- a/drivers/staging/greybus/connection.c
+++ b/drivers/staging/greybus/connection.c
@@ -357,6 +357,9 @@ static int gb_connection_hd_cport_quiesce(struct gb_connection *connection)
357 size_t peer_space; 357 size_t peer_space;
358 int ret; 358 int ret;
359 359
360 if (!hd->driver->cport_quiesce)
361 return 0;
362
360 peer_space = sizeof(struct gb_operation_msg_hdr) + 363 peer_space = sizeof(struct gb_operation_msg_hdr) +
361 sizeof(struct gb_cport_shutdown_request); 364 sizeof(struct gb_cport_shutdown_request);
362 365
@@ -380,6 +383,9 @@ static int gb_connection_hd_cport_clear(struct gb_connection *connection)
380 struct gb_host_device *hd = connection->hd; 383 struct gb_host_device *hd = connection->hd;
381 int ret; 384 int ret;
382 385
386 if (!hd->driver->cport_clear)
387 return 0;
388
383 ret = hd->driver->cport_clear(hd, connection->hd_cport_id); 389 ret = hd->driver->cport_clear(hd, connection->hd_cport_id);
384 if (ret) { 390 if (ret) {
385 dev_err(&hd->dev, "%s: failed to clear host cport: %d\n", 391 dev_err(&hd->dev, "%s: failed to clear host cport: %d\n",
diff --git a/drivers/staging/greybus/control.c b/drivers/staging/greybus/control.c
index 4716190e740a..5b30be30a3a4 100644
--- a/drivers/staging/greybus/control.c
+++ b/drivers/staging/greybus/control.c
@@ -198,56 +198,6 @@ int gb_control_mode_switch_operation(struct gb_control *control)
198 return ret; 198 return ret;
199} 199}
200 200
201int gb_control_timesync_enable(struct gb_control *control, u8 count,
202 u64 frame_time, u32 strobe_delay, u32 refclk)
203{
204 struct gb_control_timesync_enable_request request;
205
206 request.count = count;
207 request.frame_time = cpu_to_le64(frame_time);
208 request.strobe_delay = cpu_to_le32(strobe_delay);
209 request.refclk = cpu_to_le32(refclk);
210 return gb_operation_sync(control->connection,
211 GB_CONTROL_TYPE_TIMESYNC_ENABLE, &request,
212 sizeof(request), NULL, 0);
213}
214
215int gb_control_timesync_disable(struct gb_control *control)
216{
217 return gb_operation_sync(control->connection,
218 GB_CONTROL_TYPE_TIMESYNC_DISABLE, NULL, 0,
219 NULL, 0);
220}
221
222int gb_control_timesync_get_last_event(struct gb_control *control,
223 u64 *frame_time)
224{
225 struct gb_control_timesync_get_last_event_response response;
226 int ret;
227
228 ret = gb_operation_sync(control->connection,
229 GB_CONTROL_TYPE_TIMESYNC_GET_LAST_EVENT,
230 NULL, 0, &response, sizeof(response));
231 if (!ret)
232 *frame_time = le64_to_cpu(response.frame_time);
233 return ret;
234}
235
236int gb_control_timesync_authoritative(struct gb_control *control,
237 u64 *frame_time)
238{
239 struct gb_control_timesync_authoritative_request request;
240 int i;
241
242 for (i = 0; i < GB_TIMESYNC_MAX_STROBES; i++)
243 request.frame_time[i] = cpu_to_le64(frame_time[i]);
244
245 return gb_operation_sync(control->connection,
246 GB_CONTROL_TYPE_TIMESYNC_AUTHORITATIVE,
247 &request, sizeof(request),
248 NULL, 0);
249}
250
251static int gb_control_bundle_pm_status_map(u8 status) 201static int gb_control_bundle_pm_status_map(u8 status)
252{ 202{
253 switch (status) { 203 switch (status) {
diff --git a/drivers/staging/greybus/control.h b/drivers/staging/greybus/control.h
index f9a60daf9a72..4dcaec8b9cfe 100644
--- a/drivers/staging/greybus/control.h
+++ b/drivers/staging/greybus/control.h
@@ -48,13 +48,6 @@ void gb_control_mode_switch_complete(struct gb_control *control);
48int gb_control_get_manifest_size_operation(struct gb_interface *intf); 48int gb_control_get_manifest_size_operation(struct gb_interface *intf);
49int gb_control_get_manifest_operation(struct gb_interface *intf, void *manifest, 49int gb_control_get_manifest_operation(struct gb_interface *intf, void *manifest,
50 size_t size); 50 size_t size);
51int gb_control_timesync_enable(struct gb_control *control, u8 count,
52 u64 frame_time, u32 strobe_delay, u32 refclk);
53int gb_control_timesync_disable(struct gb_control *control);
54int gb_control_timesync_get_last_event(struct gb_control *control,
55 u64 *frame_time);
56int gb_control_timesync_authoritative(struct gb_control *control,
57 u64 *frame_time);
58int gb_control_bundle_suspend(struct gb_control *control, u8 bundle_id); 51int gb_control_bundle_suspend(struct gb_control *control, u8 bundle_id);
59int gb_control_bundle_resume(struct gb_control *control, u8 bundle_id); 52int gb_control_bundle_resume(struct gb_control *control, u8 bundle_id);
60int gb_control_bundle_deactivate(struct gb_control *control, u8 bundle_id); 53int gb_control_bundle_deactivate(struct gb_control *control, u8 bundle_id);
diff --git a/drivers/staging/greybus/core.c b/drivers/staging/greybus/core.c
index 1049e9c0edb0..ba761905b790 100644
--- a/drivers/staging/greybus/core.c
+++ b/drivers/staging/greybus/core.c
@@ -218,8 +218,6 @@ static int greybus_probe(struct device *dev)
218 return retval; 218 return retval;
219 } 219 }
220 220
221 gb_timesync_schedule_synchronous(bundle->intf);
222
223 pm_runtime_put(&bundle->intf->dev); 221 pm_runtime_put(&bundle->intf->dev);
224 222
225 return 0; 223 return 0;
@@ -326,16 +324,8 @@ static int __init gb_init(void)
326 pr_err("gb_operation_init failed (%d)\n", retval); 324 pr_err("gb_operation_init failed (%d)\n", retval);
327 goto error_operation; 325 goto error_operation;
328 } 326 }
329
330 retval = gb_timesync_init();
331 if (retval) {
332 pr_err("gb_timesync_init failed\n");
333 goto error_timesync;
334 }
335 return 0; /* Success */ 327 return 0; /* Success */
336 328
337error_timesync:
338 gb_operation_exit();
339error_operation: 329error_operation:
340 gb_hd_exit(); 330 gb_hd_exit();
341error_hd: 331error_hd:
@@ -349,7 +339,6 @@ module_init(gb_init);
349 339
350static void __exit gb_exit(void) 340static void __exit gb_exit(void)
351{ 341{
352 gb_timesync_exit();
353 gb_operation_exit(); 342 gb_operation_exit();
354 gb_hd_exit(); 343 gb_hd_exit();
355 bus_unregister(&greybus_bus_type); 344 bus_unregister(&greybus_bus_type);
diff --git a/drivers/staging/greybus/es2.c b/drivers/staging/greybus/es2.c
index c1929dfa9b31..f7b24e0eaa6f 100644
--- a/drivers/staging/greybus/es2.c
+++ b/drivers/staging/greybus/es2.c
@@ -127,29 +127,6 @@ struct es2_ap_dev {
127 struct list_head arpcs; 127 struct list_head arpcs;
128}; 128};
129 129
130/**
131 * timesync_enable_request - Enable timesync in an APBridge
132 * @count: number of TimeSync Pulses to expect
133 * @frame_time: the initial FrameTime at the first TimeSync Pulse
134 * @strobe_delay: the expected delay in microseconds between each TimeSync Pulse
135 * @refclk: The AP mandated reference clock to run FrameTime at
136 */
137struct timesync_enable_request {
138 __u8 count;
139 __le64 frame_time;
140 __le32 strobe_delay;
141 __le32 refclk;
142} __packed;
143
144/**
145 * timesync_authoritative_request - Transmit authoritative FrameTime to APBridge
146 * @frame_time: An array of authoritative FrameTimes provided by the SVC
147 * and relayed to the APBridge by the AP
148 */
149struct timesync_authoritative_request {
150 __le64 frame_time[GB_TIMESYNC_MAX_STROBES];
151} __packed;
152
153struct arpc { 130struct arpc {
154 struct list_head list; 131 struct list_head list;
155 struct arpc_request_message *req; 132 struct arpc_request_message *req;
@@ -754,111 +731,6 @@ static int latency_tag_disable(struct gb_host_device *hd, u16 cport_id)
754 return retval; 731 return retval;
755} 732}
756 733
757static int timesync_enable(struct gb_host_device *hd, u8 count,
758 u64 frame_time, u32 strobe_delay, u32 refclk)
759{
760 int retval;
761 struct es2_ap_dev *es2 = hd_to_es2(hd);
762 struct usb_device *udev = es2->usb_dev;
763 struct gb_control_timesync_enable_request *request;
764
765 request = kzalloc(sizeof(*request), GFP_KERNEL);
766 if (!request)
767 return -ENOMEM;
768
769 request->count = count;
770 request->frame_time = cpu_to_le64(frame_time);
771 request->strobe_delay = cpu_to_le32(strobe_delay);
772 request->refclk = cpu_to_le32(refclk);
773 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
774 GB_APB_REQUEST_TIMESYNC_ENABLE,
775 USB_DIR_OUT | USB_TYPE_VENDOR |
776 USB_RECIP_INTERFACE, 0, 0, request,
777 sizeof(*request), ES2_USB_CTRL_TIMEOUT);
778 if (retval < 0)
779 dev_err(&udev->dev, "Cannot enable timesync %d\n", retval);
780
781 kfree(request);
782 return retval;
783}
784
785static int timesync_disable(struct gb_host_device *hd)
786{
787 int retval;
788 struct es2_ap_dev *es2 = hd_to_es2(hd);
789 struct usb_device *udev = es2->usb_dev;
790
791 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
792 GB_APB_REQUEST_TIMESYNC_DISABLE,
793 USB_DIR_OUT | USB_TYPE_VENDOR |
794 USB_RECIP_INTERFACE, 0, 0, NULL,
795 0, ES2_USB_CTRL_TIMEOUT);
796 if (retval < 0)
797 dev_err(&udev->dev, "Cannot disable timesync %d\n", retval);
798
799 return retval;
800}
801
802static int timesync_authoritative(struct gb_host_device *hd, u64 *frame_time)
803{
804 int retval, i;
805 struct es2_ap_dev *es2 = hd_to_es2(hd);
806 struct usb_device *udev = es2->usb_dev;
807 struct timesync_authoritative_request *request;
808
809 request = kzalloc(sizeof(*request), GFP_KERNEL);
810 if (!request)
811 return -ENOMEM;
812
813 for (i = 0; i < GB_TIMESYNC_MAX_STROBES; i++)
814 request->frame_time[i] = cpu_to_le64(frame_time[i]);
815
816 retval = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
817 GB_APB_REQUEST_TIMESYNC_AUTHORITATIVE,
818 USB_DIR_OUT | USB_TYPE_VENDOR |
819 USB_RECIP_INTERFACE, 0, 0, request,
820 sizeof(*request), ES2_USB_CTRL_TIMEOUT);
821 if (retval < 0)
822 dev_err(&udev->dev, "Cannot timesync authoritative out %d\n", retval);
823
824 kfree(request);
825 return retval;
826}
827
828static int timesync_get_last_event(struct gb_host_device *hd, u64 *frame_time)
829{
830 int retval;
831 struct es2_ap_dev *es2 = hd_to_es2(hd);
832 struct usb_device *udev = es2->usb_dev;
833 __le64 *response_frame_time;
834
835 response_frame_time = kzalloc(sizeof(*response_frame_time), GFP_KERNEL);
836 if (!response_frame_time)
837 return -ENOMEM;
838
839 retval = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
840 GB_APB_REQUEST_TIMESYNC_GET_LAST_EVENT,
841 USB_DIR_IN | USB_TYPE_VENDOR |
842 USB_RECIP_INTERFACE, 0, 0, response_frame_time,
843 sizeof(*response_frame_time),
844 ES2_USB_CTRL_TIMEOUT);
845
846 if (retval != sizeof(*response_frame_time)) {
847 dev_err(&udev->dev, "Cannot get last TimeSync event: %d\n",
848 retval);
849
850 if (retval >= 0)
851 retval = -EIO;
852
853 goto out;
854 }
855 *frame_time = le64_to_cpu(*response_frame_time);
856 retval = 0;
857out:
858 kfree(response_frame_time);
859 return retval;
860}
861
862static struct gb_hd_driver es2_driver = { 734static struct gb_hd_driver es2_driver = {
863 .hd_priv_size = sizeof(struct es2_ap_dev), 735 .hd_priv_size = sizeof(struct es2_ap_dev),
864 .message_send = message_send, 736 .message_send = message_send,
@@ -874,10 +746,6 @@ static struct gb_hd_driver es2_driver = {
874 .latency_tag_enable = latency_tag_enable, 746 .latency_tag_enable = latency_tag_enable,
875 .latency_tag_disable = latency_tag_disable, 747 .latency_tag_disable = latency_tag_disable,
876 .output = output, 748 .output = output,
877 .timesync_enable = timesync_enable,
878 .timesync_disable = timesync_disable,
879 .timesync_authoritative = timesync_authoritative,
880 .timesync_get_last_event = timesync_get_last_event,
881}; 749};
882 750
883/* Common function to report consistent warnings based on URB status */ 751/* Common function to report consistent warnings based on URB status */
@@ -1217,7 +1085,8 @@ static void apb_log_get(struct es2_ap_dev *es2, char *buf)
1217 retval = usb_control_msg(es2->usb_dev, 1085 retval = usb_control_msg(es2->usb_dev,
1218 usb_rcvctrlpipe(es2->usb_dev, 0), 1086 usb_rcvctrlpipe(es2->usb_dev, 0),
1219 GB_APB_REQUEST_LOG, 1087 GB_APB_REQUEST_LOG,
1220 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 1088 USB_DIR_IN | USB_TYPE_VENDOR |
1089 USB_RECIP_INTERFACE,
1221 0x00, 0x00, 1090 0x00, 0x00,
1222 buf, 1091 buf,
1223 APB1_LOG_MSG_SIZE, 1092 APB1_LOG_MSG_SIZE,
@@ -1283,7 +1152,7 @@ static void usb_log_enable(struct es2_ap_dev *es2)
1283 if (IS_ERR(es2->apb_log_task)) 1152 if (IS_ERR(es2->apb_log_task))
1284 return; 1153 return;
1285 /* XXX We will need to rename this per APB */ 1154 /* XXX We will need to rename this per APB */
1286 es2->apb_log_dentry = debugfs_create_file("apb_log", S_IRUGO, 1155 es2->apb_log_dentry = debugfs_create_file("apb_log", 0444,
1287 gb_debugfs_get(), es2, 1156 gb_debugfs_get(), es2,
1288 &apb_log_fops); 1157 &apb_log_fops);
1289} 1158}
@@ -1540,7 +1409,7 @@ static int ap_probe(struct usb_interface *interface,
1540 1409
1541 /* XXX We will need to rename this per APB */ 1410 /* XXX We will need to rename this per APB */
1542 es2->apb_log_enable_dentry = debugfs_create_file("apb_log_enable", 1411 es2->apb_log_enable_dentry = debugfs_create_file("apb_log_enable",
1543 (S_IWUSR | S_IRUGO), 1412 0644,
1544 gb_debugfs_get(), es2, 1413 gb_debugfs_get(), es2,
1545 &apb_log_enable_fops); 1414 &apb_log_enable_fops);
1546 1415
diff --git a/drivers/staging/greybus/fw-download.c b/drivers/staging/greybus/fw-download.c
index 2d7246887547..8a1a413c6cb3 100644
--- a/drivers/staging/greybus/fw-download.c
+++ b/drivers/staging/greybus/fw-download.c
@@ -130,7 +130,8 @@ static void free_firmware(struct fw_download *fw_download,
130static void fw_request_timedout(struct work_struct *work) 130static void fw_request_timedout(struct work_struct *work)
131{ 131{
132 struct delayed_work *dwork = to_delayed_work(work); 132 struct delayed_work *dwork = to_delayed_work(work);
133 struct fw_request *fw_req = container_of(dwork, struct fw_request, dwork); 133 struct fw_request *fw_req = container_of(dwork,
134 struct fw_request, dwork);
134 struct fw_download *fw_download = fw_req->fw_download; 135 struct fw_download *fw_download = fw_req->fw_download;
135 136
136 dev_err(fw_download->parent, 137 dev_err(fw_download->parent,
@@ -239,7 +240,8 @@ static int fw_download_find_firmware(struct gb_operation *op)
239 tag = (const char *)request->firmware_tag; 240 tag = (const char *)request->firmware_tag;
240 241
241 /* firmware_tag must be null-terminated */ 242 /* firmware_tag must be null-terminated */
242 if (strnlen(tag, GB_FIRMWARE_TAG_MAX_SIZE) == GB_FIRMWARE_TAG_MAX_SIZE) { 243 if (strnlen(tag, GB_FIRMWARE_TAG_MAX_SIZE) ==
244 GB_FIRMWARE_TAG_MAX_SIZE) {
243 dev_err(fw_download->parent, 245 dev_err(fw_download->parent,
244 "firmware-tag is not null-terminated\n"); 246 "firmware-tag is not null-terminated\n");
245 return -EINVAL; 247 return -EINVAL;
diff --git a/drivers/staging/greybus/gbphy.c b/drivers/staging/greybus/gbphy.c
index bcde7c9a0f17..64a1eb93ec96 100644
--- a/drivers/staging/greybus/gbphy.c
+++ b/drivers/staging/greybus/gbphy.c
@@ -104,7 +104,8 @@ static int gbphy_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
104} 104}
105 105
106static const struct gbphy_device_id * 106static const struct gbphy_device_id *
107gbphy_dev_match_id(struct gbphy_device *gbphy_dev, struct gbphy_driver *gbphy_drv) 107gbphy_dev_match_id(struct gbphy_device *gbphy_dev,
108 struct gbphy_driver *gbphy_drv)
108{ 109{
109 const struct gbphy_device_id *id = gbphy_drv->id_table; 110 const struct gbphy_device_id *id = gbphy_drv->id_table;
110 111
diff --git a/drivers/staging/greybus/gpio.c b/drivers/staging/greybus/gpio.c
index 51384bdde450..ee5f998b174f 100644
--- a/drivers/staging/greybus/gpio.c
+++ b/drivers/staging/greybus/gpio.c
@@ -410,21 +410,21 @@ static int gb_gpio_request_handler(struct gb_operation *op)
410 return 0; 410 return 0;
411} 411}
412 412
413static int gb_gpio_request(struct gpio_chip *chip, unsigned offset) 413static int gb_gpio_request(struct gpio_chip *chip, unsigned int offset)
414{ 414{
415 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 415 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
416 416
417 return gb_gpio_activate_operation(ggc, (u8)offset); 417 return gb_gpio_activate_operation(ggc, (u8)offset);
418} 418}
419 419
420static void gb_gpio_free(struct gpio_chip *chip, unsigned offset) 420static void gb_gpio_free(struct gpio_chip *chip, unsigned int offset)
421{ 421{
422 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 422 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
423 423
424 gb_gpio_deactivate_operation(ggc, (u8)offset); 424 gb_gpio_deactivate_operation(ggc, (u8)offset);
425} 425}
426 426
427static int gb_gpio_get_direction(struct gpio_chip *chip, unsigned offset) 427static int gb_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
428{ 428{
429 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 429 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
430 u8 which; 430 u8 which;
@@ -438,22 +438,22 @@ static int gb_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
438 return ggc->lines[which].direction ? 1 : 0; 438 return ggc->lines[which].direction ? 1 : 0;
439} 439}
440 440
441static int gb_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 441static int gb_gpio_direction_input(struct gpio_chip *chip, unsigned int offset)
442{ 442{
443 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 443 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
444 444
445 return gb_gpio_direction_in_operation(ggc, (u8)offset); 445 return gb_gpio_direction_in_operation(ggc, (u8)offset);
446} 446}
447 447
448static int gb_gpio_direction_output(struct gpio_chip *chip, unsigned offset, 448static int gb_gpio_direction_output(struct gpio_chip *chip, unsigned int offset,
449 int value) 449 int value)
450{ 450{
451 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 451 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
452 452
453 return gb_gpio_direction_out_operation(ggc, (u8)offset, !!value); 453 return gb_gpio_direction_out_operation(ggc, (u8)offset, !!value);
454} 454}
455 455
456static int gb_gpio_get(struct gpio_chip *chip, unsigned offset) 456static int gb_gpio_get(struct gpio_chip *chip, unsigned int offset)
457{ 457{
458 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 458 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
459 u8 which; 459 u8 which;
@@ -467,14 +467,14 @@ static int gb_gpio_get(struct gpio_chip *chip, unsigned offset)
467 return ggc->lines[which].value; 467 return ggc->lines[which].value;
468} 468}
469 469
470static void gb_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 470static void gb_gpio_set(struct gpio_chip *chip, unsigned int offset, int value)
471{ 471{
472 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 472 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
473 473
474 gb_gpio_set_value_operation(ggc, (u8)offset, !!value); 474 gb_gpio_set_value_operation(ggc, (u8)offset, !!value);
475} 475}
476 476
477static int gb_gpio_set_config(struct gpio_chip *chip, unsigned offset, 477static int gb_gpio_set_config(struct gpio_chip *chip, unsigned int offset,
478 unsigned long config) 478 unsigned long config)
479{ 479{
480 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 480 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
@@ -560,7 +560,8 @@ static void gb_gpio_irqchip_remove(struct gb_gpio_controller *ggc)
560 /* Remove all IRQ mappings and delete the domain */ 560 /* Remove all IRQ mappings and delete the domain */
561 if (ggc->irqdomain) { 561 if (ggc->irqdomain) {
562 for (offset = 0; offset < (ggc->line_max + 1); offset++) 562 for (offset = 0; offset < (ggc->line_max + 1); offset++)
563 irq_dispose_mapping(irq_find_mapping(ggc->irqdomain, offset)); 563 irq_dispose_mapping(irq_find_mapping(ggc->irqdomain,
564 offset));
564 irq_domain_remove(ggc->irqdomain); 565 irq_domain_remove(ggc->irqdomain);
565 } 566 }
566 567
@@ -596,7 +597,7 @@ static int gb_gpio_irqchip_add(struct gpio_chip *chip,
596{ 597{
597 struct gb_gpio_controller *ggc; 598 struct gb_gpio_controller *ggc;
598 unsigned int offset; 599 unsigned int offset;
599 unsigned irq_base; 600 unsigned int irq_base;
600 601
601 if (!chip || !irqchip) 602 if (!chip || !irqchip)
602 return -EINVAL; 603 return -EINVAL;
@@ -628,7 +629,7 @@ static int gb_gpio_irqchip_add(struct gpio_chip *chip,
628 return 0; 629 return 0;
629} 630}
630 631
631static int gb_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 632static int gb_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
632{ 633{
633 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip); 634 struct gb_gpio_controller *ggc = gpio_chip_to_gb_gpio_controller(chip);
634 635
diff --git a/drivers/staging/greybus/greybus.h b/drivers/staging/greybus/greybus.h
index 12526887ae2e..c9bb93f23927 100644
--- a/drivers/staging/greybus/greybus.h
+++ b/drivers/staging/greybus/greybus.h
@@ -33,7 +33,6 @@
33#include "bundle.h" 33#include "bundle.h"
34#include "connection.h" 34#include "connection.h"
35#include "operation.h" 35#include "operation.h"
36#include "timesync.h"
37 36
38/* Matches up with the Greybus Protocol specification document */ 37/* Matches up with the Greybus Protocol specification document */
39#define GREYBUS_VERSION_MAJOR 0x00 38#define GREYBUS_VERSION_MAJOR 0x00
diff --git a/drivers/staging/greybus/greybus_protocols.h b/drivers/staging/greybus/greybus_protocols.h
index 639578309c2a..b1be0b0af464 100644
--- a/drivers/staging/greybus/greybus_protocols.h
+++ b/drivers/staging/greybus/greybus_protocols.h
@@ -173,26 +173,6 @@ struct gb_control_disconnected_request {
173} __packed; 173} __packed;
174/* Control protocol [dis]connected response has no payload */ 174/* Control protocol [dis]connected response has no payload */
175 175
176#define GB_TIMESYNC_MAX_STROBES 0x04
177
178struct gb_control_timesync_enable_request {
179 __u8 count;
180 __le64 frame_time;
181 __le32 strobe_delay;
182 __le32 refclk;
183} __packed;
184/* timesync enable response has no payload */
185
186struct gb_control_timesync_authoritative_request {
187 __le64 frame_time[GB_TIMESYNC_MAX_STROBES];
188} __packed;
189/* timesync authoritative response has no payload */
190
191/* timesync get_last_event_request has no payload */
192struct gb_control_timesync_get_last_event_response {
193 __le64 frame_time;
194} __packed;
195
196/* 176/*
197 * All Bundle power management operations use the same request and response 177 * All Bundle power management operations use the same request and response
198 * layout and status codes. 178 * layout and status codes.
@@ -1169,33 +1149,6 @@ struct gb_svc_intf_unipro_response {
1169#define GB_SVC_INTF_UNIPRO_NOT_OFF 0x03 1149#define GB_SVC_INTF_UNIPRO_NOT_OFF 0x03
1170} __packed; 1150} __packed;
1171 1151
1172struct gb_svc_timesync_enable_request {
1173 __u8 count;
1174 __le64 frame_time;
1175 __le32 strobe_delay;
1176 __le32 refclk;
1177} __packed;
1178/* timesync enable response has no payload */
1179
1180/* timesync authoritative request has no payload */
1181struct gb_svc_timesync_authoritative_response {
1182 __le64 frame_time[GB_TIMESYNC_MAX_STROBES];
1183};
1184
1185struct gb_svc_timesync_wake_pins_acquire_request {
1186 __le32 strobe_mask;
1187};
1188
1189/* timesync wake pins acquire response has no payload */
1190
1191/* timesync wake pins release request has no payload */
1192/* timesync wake pins release response has no payload */
1193
1194/* timesync svc ping request has no payload */
1195struct gb_svc_timesync_ping_response {
1196 __le64 frame_time;
1197} __packed;
1198
1199#define GB_SVC_UNIPRO_FAST_MODE 0x01 1152#define GB_SVC_UNIPRO_FAST_MODE 0x01
1200#define GB_SVC_UNIPRO_SLOW_MODE 0x02 1153#define GB_SVC_UNIPRO_SLOW_MODE 0x02
1201#define GB_SVC_UNIPRO_FAST_AUTO_MODE 0x04 1154#define GB_SVC_UNIPRO_FAST_AUTO_MODE 0x04
diff --git a/drivers/staging/greybus/greybus_trace.h b/drivers/staging/greybus/greybus_trace.h
index 6f8692da9ec8..f8feae4dc3b5 100644
--- a/drivers/staging/greybus/greybus_trace.h
+++ b/drivers/staging/greybus/greybus_trace.h
@@ -488,34 +488,6 @@ DEFINE_HD_EVENT(gb_hd_in);
488 488
489#undef DEFINE_HD_EVENT 489#undef DEFINE_HD_EVENT
490 490
491/*
492 * Occurs on a TimeSync synchronization event or a TimeSync ping event.
493 */
494TRACE_EVENT(gb_timesync_irq,
495
496 TP_PROTO(u8 ping, u8 strobe, u8 count, u64 frame_time),
497
498 TP_ARGS(ping, strobe, count, frame_time),
499
500 TP_STRUCT__entry(
501 __field(u8, ping)
502 __field(u8, strobe)
503 __field(u8, count)
504 __field(u64, frame_time)
505 ),
506
507 TP_fast_assign(
508 __entry->ping = ping;
509 __entry->strobe = strobe;
510 __entry->count = count;
511 __entry->frame_time = frame_time;
512 ),
513
514 TP_printk("%s %d/%d frame-time %llu\n",
515 __entry->ping ? "ping" : "strobe", __entry->strobe,
516 __entry->count, __entry->frame_time)
517);
518
519#endif /* _TRACE_GREYBUS_H */ 491#endif /* _TRACE_GREYBUS_H */
520 492
521/* This part must be outside protection */ 493/* This part must be outside protection */
diff --git a/drivers/staging/greybus/hd.h b/drivers/staging/greybus/hd.h
index c4250cfe595f..e7927bb1761c 100644
--- a/drivers/staging/greybus/hd.h
+++ b/drivers/staging/greybus/hd.h
@@ -37,13 +37,6 @@ struct gb_hd_driver {
37 int (*latency_tag_disable)(struct gb_host_device *hd, u16 cport_id); 37 int (*latency_tag_disable)(struct gb_host_device *hd, u16 cport_id);
38 int (*output)(struct gb_host_device *hd, void *req, u16 size, u8 cmd, 38 int (*output)(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
39 bool async); 39 bool async);
40 int (*timesync_enable)(struct gb_host_device *hd, u8 count,
41 u64 frame_time, u32 strobe_delay, u32 refclk);
42 int (*timesync_disable)(struct gb_host_device *hd);
43 int (*timesync_authoritative)(struct gb_host_device *hd,
44 u64 *frame_time);
45 int (*timesync_get_last_event)(struct gb_host_device *hd,
46 u64 *frame_time);
47}; 40};
48 41
49struct gb_host_device { 42struct gb_host_device {
diff --git a/drivers/staging/greybus/interface.c b/drivers/staging/greybus/interface.c
index 546b090e2d51..a4fd51632232 100644
--- a/drivers/staging/greybus/interface.c
+++ b/drivers/staging/greybus/interface.c
@@ -702,14 +702,12 @@ static void gb_interface_release(struct device *dev)
702static int gb_interface_suspend(struct device *dev) 702static int gb_interface_suspend(struct device *dev)
703{ 703{
704 struct gb_interface *intf = to_gb_interface(dev); 704 struct gb_interface *intf = to_gb_interface(dev);
705 int ret, timesync_ret; 705 int ret;
706 706
707 ret = gb_control_interface_suspend_prepare(intf->control); 707 ret = gb_control_interface_suspend_prepare(intf->control);
708 if (ret) 708 if (ret)
709 return ret; 709 return ret;
710 710
711 gb_timesync_interface_remove(intf);
712
713 ret = gb_control_suspend(intf->control); 711 ret = gb_control_suspend(intf->control);
714 if (ret) 712 if (ret)
715 goto err_hibernate_abort; 713 goto err_hibernate_abort;
@@ -730,12 +728,6 @@ static int gb_interface_suspend(struct device *dev)
730err_hibernate_abort: 728err_hibernate_abort:
731 gb_control_interface_hibernate_abort(intf->control); 729 gb_control_interface_hibernate_abort(intf->control);
732 730
733 timesync_ret = gb_timesync_interface_add(intf);
734 if (timesync_ret) {
735 dev_err(dev, "failed to add to timesync: %d\n", timesync_ret);
736 return timesync_ret;
737 }
738
739 return ret; 731 return ret;
740} 732}
741 733
@@ -757,18 +749,6 @@ static int gb_interface_resume(struct device *dev)
757 if (ret) 749 if (ret)
758 return ret; 750 return ret;
759 751
760 ret = gb_timesync_interface_add(intf);
761 if (ret) {
762 dev_err(dev, "failed to add to timesync: %d\n", ret);
763 return ret;
764 }
765
766 ret = gb_timesync_schedule_synchronous(intf);
767 if (ret) {
768 dev_err(dev, "failed to synchronize FrameTime: %d\n", ret);
769 return ret;
770 }
771
772 return 0; 752 return 0;
773} 753}
774 754
@@ -1152,16 +1132,10 @@ int gb_interface_enable(struct gb_interface *intf)
1152 if (ret) 1132 if (ret)
1153 goto err_destroy_bundles; 1133 goto err_destroy_bundles;
1154 1134
1155 ret = gb_timesync_interface_add(intf);
1156 if (ret) {
1157 dev_err(&intf->dev, "failed to add to timesync: %d\n", ret);
1158 goto err_destroy_bundles;
1159 }
1160
1161 /* Register the control device and any bundles */ 1135 /* Register the control device and any bundles */
1162 ret = gb_control_add(intf->control); 1136 ret = gb_control_add(intf->control);
1163 if (ret) 1137 if (ret)
1164 goto err_remove_timesync; 1138 goto err_destroy_bundles;
1165 1139
1166 pm_runtime_use_autosuspend(&intf->dev); 1140 pm_runtime_use_autosuspend(&intf->dev);
1167 pm_runtime_get_noresume(&intf->dev); 1141 pm_runtime_get_noresume(&intf->dev);
@@ -1186,8 +1160,6 @@ int gb_interface_enable(struct gb_interface *intf)
1186 1160
1187 return 0; 1161 return 0;
1188 1162
1189err_remove_timesync:
1190 gb_timesync_interface_remove(intf);
1191err_destroy_bundles: 1163err_destroy_bundles:
1192 list_for_each_entry_safe(bundle, tmp, &intf->bundles, links) 1164 list_for_each_entry_safe(bundle, tmp, &intf->bundles, links)
1193 gb_bundle_destroy(bundle); 1165 gb_bundle_destroy(bundle);
@@ -1230,7 +1202,6 @@ void gb_interface_disable(struct gb_interface *intf)
1230 gb_control_interface_deactivate_prepare(intf->control); 1202 gb_control_interface_deactivate_prepare(intf->control);
1231 1203
1232 gb_control_del(intf->control); 1204 gb_control_del(intf->control);
1233 gb_timesync_interface_remove(intf);
1234 gb_control_disable(intf->control); 1205 gb_control_disable(intf->control);
1235 gb_control_put(intf->control); 1206 gb_control_put(intf->control);
1236 intf->control = NULL; 1207 intf->control = NULL;
@@ -1243,29 +1214,6 @@ void gb_interface_disable(struct gb_interface *intf)
1243 pm_runtime_put_noidle(&intf->dev); 1214 pm_runtime_put_noidle(&intf->dev);
1244} 1215}
1245 1216
1246/* Enable TimeSync on an Interface control connection. */
1247int gb_interface_timesync_enable(struct gb_interface *intf, u8 count,
1248 u64 frame_time, u32 strobe_delay, u32 refclk)
1249{
1250 return gb_control_timesync_enable(intf->control, count,
1251 frame_time, strobe_delay,
1252 refclk);
1253}
1254
1255/* Disable TimeSync on an Interface control connection. */
1256int gb_interface_timesync_disable(struct gb_interface *intf)
1257{
1258 return gb_control_timesync_disable(intf->control);
1259}
1260
1261/* Transmit the Authoritative FrameTime via an Interface control connection. */
1262int gb_interface_timesync_authoritative(struct gb_interface *intf,
1263 u64 *frame_time)
1264{
1265 return gb_control_timesync_authoritative(intf->control,
1266 frame_time);
1267}
1268
1269/* Register an interface. */ 1217/* Register an interface. */
1270int gb_interface_add(struct gb_interface *intf) 1218int gb_interface_add(struct gb_interface *intf)
1271{ 1219{
diff --git a/drivers/staging/greybus/interface.h b/drivers/staging/greybus/interface.h
index 03299d2a8be5..bd31b8c18d5b 100644
--- a/drivers/staging/greybus/interface.h
+++ b/drivers/staging/greybus/interface.h
@@ -72,11 +72,6 @@ int gb_interface_activate(struct gb_interface *intf);
72void gb_interface_deactivate(struct gb_interface *intf); 72void gb_interface_deactivate(struct gb_interface *intf);
73int gb_interface_enable(struct gb_interface *intf); 73int gb_interface_enable(struct gb_interface *intf);
74void gb_interface_disable(struct gb_interface *intf); 74void gb_interface_disable(struct gb_interface *intf);
75int gb_interface_timesync_enable(struct gb_interface *intf, u8 count,
76 u64 frame_time, u32 strobe_delay, u32 refclk);
77int gb_interface_timesync_authoritative(struct gb_interface *intf,
78 u64 *frame_time);
79int gb_interface_timesync_disable(struct gb_interface *intf);
80int gb_interface_add(struct gb_interface *intf); 75int gb_interface_add(struct gb_interface *intf);
81void gb_interface_del(struct gb_interface *intf); 76void gb_interface_del(struct gb_interface *intf);
82void gb_interface_put(struct gb_interface *intf); 77void gb_interface_put(struct gb_interface *intf);
diff --git a/drivers/staging/greybus/log.c b/drivers/staging/greybus/log.c
index 1a18ab1ff8aa..5c5bedaf69a6 100644
--- a/drivers/staging/greybus/log.c
+++ b/drivers/staging/greybus/log.c
@@ -37,9 +37,9 @@ static int gb_log_request_handler(struct gb_operation *op)
37 } 37 }
38 receive = op->request->payload; 38 receive = op->request->payload;
39 len = le16_to_cpu(receive->len); 39 len = le16_to_cpu(receive->len);
40 if (len != (int)(op->request->payload_size - sizeof(*receive))) { 40 if (len != (op->request->payload_size - sizeof(*receive))) {
41 dev_err(dev, "log request wrong size %d vs %d\n", len, 41 dev_err(dev, "log request wrong size %d vs %zu\n", len,
42 (int)(op->request->payload_size - sizeof(*receive))); 42 (op->request->payload_size - sizeof(*receive)));
43 return -EINVAL; 43 return -EINVAL;
44 } 44 }
45 if (len == 0) { 45 if (len == 0) {
diff --git a/drivers/staging/greybus/loopback.c b/drivers/staging/greybus/loopback.c
index 7882306adeca..aaf29a5fac83 100644
--- a/drivers/staging/greybus/loopback.c
+++ b/drivers/staging/greybus/loopback.c
@@ -124,7 +124,7 @@ static DEFINE_IDA(loopback_ida);
124 124
125#define GB_LOOPBACK_FIFO_DEFAULT 8192 125#define GB_LOOPBACK_FIFO_DEFAULT 8192
126 126
127static unsigned kfifo_depth = GB_LOOPBACK_FIFO_DEFAULT; 127static unsigned int kfifo_depth = GB_LOOPBACK_FIFO_DEFAULT;
128module_param(kfifo_depth, uint, 0444); 128module_param(kfifo_depth, uint, 0444);
129 129
130/* Maximum size of any one send data buffer we support */ 130/* Maximum size of any one send data buffer we support */
@@ -629,6 +629,7 @@ static int gb_loopback_async_operation(struct gb_loopback *gb, int type,
629 mutex_lock(&gb->mutex); 629 mutex_lock(&gb->mutex);
630 ret = gb_operation_request_send(operation, 630 ret = gb_operation_request_send(operation,
631 gb_loopback_async_operation_callback, 631 gb_loopback_async_operation_callback,
632 0,
632 GFP_KERNEL); 633 GFP_KERNEL);
633 if (ret) 634 if (ret)
634 goto error; 635 goto error;
@@ -1008,11 +1009,22 @@ static int gb_loopback_fn(void *data)
1008 1009
1009 /* Optionally terminate */ 1010 /* Optionally terminate */
1010 if (gb->send_count == gb->iteration_max) { 1011 if (gb->send_count == gb->iteration_max) {
1012 mutex_unlock(&gb->mutex);
1013
1014 /* Wait for synchronous and asynchronus completion */
1015 gb_loopback_async_wait_all(gb);
1016
1017 /* Mark complete unless user-space has poked us */
1018 mutex_lock(&gb->mutex);
1011 if (gb->iteration_count == gb->iteration_max) { 1019 if (gb->iteration_count == gb->iteration_max) {
1012 gb->type = 0; 1020 gb->type = 0;
1013 gb->send_count = 0; 1021 gb->send_count = 0;
1014 sysfs_notify(&gb->dev->kobj, NULL, 1022 sysfs_notify(&gb->dev->kobj, NULL,
1015 "iteration_count"); 1023 "iteration_count");
1024 dev_dbg(&bundle->dev, "load test complete\n");
1025 } else {
1026 dev_dbg(&bundle->dev,
1027 "continuing on with new test set\n");
1016 } 1028 }
1017 mutex_unlock(&gb->mutex); 1029 mutex_unlock(&gb->mutex);
1018 continue; 1030 continue;
@@ -1026,13 +1038,12 @@ static int gb_loopback_fn(void *data)
1026 1038
1027 /* Else operations to perform */ 1039 /* Else operations to perform */
1028 if (gb->async) { 1040 if (gb->async) {
1029 if (type == GB_LOOPBACK_TYPE_PING) { 1041 if (type == GB_LOOPBACK_TYPE_PING)
1030 error = gb_loopback_async_ping(gb); 1042 error = gb_loopback_async_ping(gb);
1031 } else if (type == GB_LOOPBACK_TYPE_TRANSFER) { 1043 else if (type == GB_LOOPBACK_TYPE_TRANSFER)
1032 error = gb_loopback_async_transfer(gb, size); 1044 error = gb_loopback_async_transfer(gb, size);
1033 } else if (type == GB_LOOPBACK_TYPE_SINK) { 1045 else if (type == GB_LOOPBACK_TYPE_SINK)
1034 error = gb_loopback_async_sink(gb, size); 1046 error = gb_loopback_async_sink(gb, size);
1035 }
1036 1047
1037 if (error) 1048 if (error)
1038 gb->error++; 1049 gb->error++;
@@ -1051,8 +1062,13 @@ static int gb_loopback_fn(void *data)
1051 gb_loopback_calculate_stats(gb, !!error); 1062 gb_loopback_calculate_stats(gb, !!error);
1052 } 1063 }
1053 gb->send_count++; 1064 gb->send_count++;
1054 if (us_wait) 1065
1055 udelay(us_wait); 1066 if (us_wait) {
1067 if (us_wait < 20000)
1068 usleep_range(us_wait, us_wait + 100);
1069 else
1070 msleep(us_wait / 1000);
1071 }
1056 } 1072 }
1057 1073
1058 gb_pm_runtime_put_autosuspend(bundle); 1074 gb_pm_runtime_put_autosuspend(bundle);
@@ -1199,7 +1215,7 @@ static int gb_loopback_probe(struct gb_bundle *bundle,
1199 /* Create per-connection sysfs and debugfs data-points */ 1215 /* Create per-connection sysfs and debugfs data-points */
1200 snprintf(name, sizeof(name), "raw_latency_%s", 1216 snprintf(name, sizeof(name), "raw_latency_%s",
1201 dev_name(&connection->bundle->dev)); 1217 dev_name(&connection->bundle->dev));
1202 gb->file = debugfs_create_file(name, S_IFREG | S_IRUGO, gb_dev.root, gb, 1218 gb->file = debugfs_create_file(name, S_IFREG | 0444, gb_dev.root, gb,
1203 &gb_loopback_debugfs_latency_ops); 1219 &gb_loopback_debugfs_latency_ops);
1204 1220
1205 gb->id = ida_simple_get(&loopback_ida, 0, 0, GFP_KERNEL); 1221 gb->id = ida_simple_get(&loopback_ida, 0, 0, GFP_KERNEL);
diff --git a/drivers/staging/greybus/operation.c b/drivers/staging/greybus/operation.c
index 0123109a1070..3023012808d9 100644
--- a/drivers/staging/greybus/operation.c
+++ b/drivers/staging/greybus/operation.c
@@ -273,18 +273,40 @@ static void gb_operation_request_handle(struct gb_operation *operation)
273static void gb_operation_work(struct work_struct *work) 273static void gb_operation_work(struct work_struct *work)
274{ 274{
275 struct gb_operation *operation; 275 struct gb_operation *operation;
276 int ret;
276 277
277 operation = container_of(work, struct gb_operation, work); 278 operation = container_of(work, struct gb_operation, work);
278 279
279 if (gb_operation_is_incoming(operation)) 280 if (gb_operation_is_incoming(operation)) {
280 gb_operation_request_handle(operation); 281 gb_operation_request_handle(operation);
281 else 282 } else {
283 ret = del_timer_sync(&operation->timer);
284 if (!ret) {
285 /* Cancel request message if scheduled by timeout. */
286 if (gb_operation_result(operation) == -ETIMEDOUT)
287 gb_message_cancel(operation->request);
288 }
289
282 operation->callback(operation); 290 operation->callback(operation);
291 }
283 292
284 gb_operation_put_active(operation); 293 gb_operation_put_active(operation);
285 gb_operation_put(operation); 294 gb_operation_put(operation);
286} 295}
287 296
297static void gb_operation_timeout(unsigned long arg)
298{
299 struct gb_operation *operation = (void *)arg;
300
301 if (gb_operation_result_set(operation, -ETIMEDOUT)) {
302 /*
303 * A stuck request message will be cancelled from the
304 * workqueue.
305 */
306 queue_work(gb_operation_completion_wq, &operation->work);
307 }
308}
309
288static void gb_operation_message_init(struct gb_host_device *hd, 310static void gb_operation_message_init(struct gb_host_device *hd,
289 struct gb_message *message, u16 operation_id, 311 struct gb_message *message, u16 operation_id,
290 size_t payload_size, u8 type) 312 size_t payload_size, u8 type)
@@ -518,6 +540,9 @@ gb_operation_create_common(struct gb_connection *connection, u8 type,
518 gfp_flags)) { 540 gfp_flags)) {
519 goto err_request; 541 goto err_request;
520 } 542 }
543
544 setup_timer(&operation->timer, gb_operation_timeout,
545 (unsigned long)operation);
521 } 546 }
522 547
523 operation->flags = op_flags; 548 operation->flags = op_flags;
@@ -679,6 +704,7 @@ static void gb_operation_sync_callback(struct gb_operation *operation)
679 * gb_operation_request_send() - send an operation request message 704 * gb_operation_request_send() - send an operation request message
680 * @operation: the operation to initiate 705 * @operation: the operation to initiate
681 * @callback: the operation completion callback 706 * @callback: the operation completion callback
707 * @timeout: operation timeout in milliseconds, or zero for no timeout
682 * @gfp: the memory flags to use for any allocations 708 * @gfp: the memory flags to use for any allocations
683 * 709 *
684 * The caller has filled in any payload so the request message is ready to go. 710 * The caller has filled in any payload so the request message is ready to go.
@@ -693,6 +719,7 @@ static void gb_operation_sync_callback(struct gb_operation *operation)
693 */ 719 */
694int gb_operation_request_send(struct gb_operation *operation, 720int gb_operation_request_send(struct gb_operation *operation,
695 gb_operation_callback callback, 721 gb_operation_callback callback,
722 unsigned int timeout,
696 gfp_t gfp) 723 gfp_t gfp)
697{ 724{
698 struct gb_connection *connection = operation->connection; 725 struct gb_connection *connection = operation->connection;
@@ -742,6 +769,11 @@ int gb_operation_request_send(struct gb_operation *operation,
742 if (ret) 769 if (ret)
743 goto err_put_active; 770 goto err_put_active;
744 771
772 if (timeout) {
773 operation->timer.expires = jiffies + msecs_to_jiffies(timeout);
774 add_timer(&operation->timer);
775 }
776
745 return 0; 777 return 0;
746 778
747err_put_active: 779err_put_active:
@@ -763,26 +795,16 @@ int gb_operation_request_send_sync_timeout(struct gb_operation *operation,
763 unsigned int timeout) 795 unsigned int timeout)
764{ 796{
765 int ret; 797 int ret;
766 unsigned long timeout_jiffies;
767 798
768 ret = gb_operation_request_send(operation, gb_operation_sync_callback, 799 ret = gb_operation_request_send(operation, gb_operation_sync_callback,
769 GFP_KERNEL); 800 timeout, GFP_KERNEL);
770 if (ret) 801 if (ret)
771 return ret; 802 return ret;
772 803
773 if (timeout) 804 ret = wait_for_completion_interruptible(&operation->completion);
774 timeout_jiffies = msecs_to_jiffies(timeout);
775 else
776 timeout_jiffies = MAX_SCHEDULE_TIMEOUT;
777
778 ret = wait_for_completion_interruptible_timeout(&operation->completion,
779 timeout_jiffies);
780 if (ret < 0) { 805 if (ret < 0) {
781 /* Cancel the operation if interrupted */ 806 /* Cancel the operation if interrupted */
782 gb_operation_cancel(operation, -ECANCELED); 807 gb_operation_cancel(operation, -ECANCELED);
783 } else if (ret == 0) {
784 /* Cancel the operation if op timed out */
785 gb_operation_cancel(operation, -ETIMEDOUT);
786 } 808 }
787 809
788 return gb_operation_result(operation); 810 return gb_operation_result(operation);
diff --git a/drivers/staging/greybus/operation.h b/drivers/staging/greybus/operation.h
index de09a2c7de54..7529f01b2529 100644
--- a/drivers/staging/greybus/operation.h
+++ b/drivers/staging/greybus/operation.h
@@ -98,6 +98,7 @@ struct gb_operation {
98 struct work_struct work; 98 struct work_struct work;
99 gb_operation_callback callback; 99 gb_operation_callback callback;
100 struct completion completion; 100 struct completion completion;
101 struct timer_list timer;
101 102
102 struct kref kref; 103 struct kref kref;
103 atomic_t waiters; 104 atomic_t waiters;
@@ -164,6 +165,7 @@ bool gb_operation_response_alloc(struct gb_operation *operation,
164 165
165int gb_operation_request_send(struct gb_operation *operation, 166int gb_operation_request_send(struct gb_operation *operation,
166 gb_operation_callback callback, 167 gb_operation_callback callback,
168 unsigned int timeout,
167 gfp_t gfp); 169 gfp_t gfp);
168int gb_operation_request_send_sync_timeout(struct gb_operation *operation, 170int gb_operation_request_send_sync_timeout(struct gb_operation *operation,
169 unsigned int timeout); 171 unsigned int timeout);
diff --git a/drivers/staging/greybus/sdio.c b/drivers/staging/greybus/sdio.c
index 66b37ea29ef0..101ca5097fc9 100644
--- a/drivers/staging/greybus/sdio.c
+++ b/drivers/staging/greybus/sdio.c
@@ -52,7 +52,7 @@ struct gb_sdio_host {
52 52
53static inline bool single_op(struct mmc_command *cmd) 53static inline bool single_op(struct mmc_command *cmd)
54{ 54{
55 uint32_t opcode = cmd->opcode; 55 u32 opcode = cmd->opcode;
56 56
57 return opcode == MMC_WRITE_BLOCK || 57 return opcode == MMC_WRITE_BLOCK ||
58 opcode == MMC_READ_SINGLE_BLOCK; 58 opcode == MMC_READ_SINGLE_BLOCK;
diff --git a/drivers/staging/greybus/svc.c b/drivers/staging/greybus/svc.c
index 8779270cadc1..516f827e5ed9 100644
--- a/drivers/staging/greybus/svc.c
+++ b/drivers/staging/greybus/svc.c
@@ -518,85 +518,6 @@ void gb_svc_connection_destroy(struct gb_svc *svc, u8 intf1_id, u16 cport1_id,
518 } 518 }
519} 519}
520 520
521int gb_svc_timesync_enable(struct gb_svc *svc, u8 count, u64 frame_time,
522 u32 strobe_delay, u32 refclk)
523{
524 struct gb_connection *connection = svc->connection;
525 struct gb_svc_timesync_enable_request request;
526
527 request.count = count;
528 request.frame_time = cpu_to_le64(frame_time);
529 request.strobe_delay = cpu_to_le32(strobe_delay);
530 request.refclk = cpu_to_le32(refclk);
531 return gb_operation_sync(connection,
532 GB_SVC_TYPE_TIMESYNC_ENABLE,
533 &request, sizeof(request), NULL, 0);
534}
535
536int gb_svc_timesync_disable(struct gb_svc *svc)
537{
538 struct gb_connection *connection = svc->connection;
539
540 return gb_operation_sync(connection,
541 GB_SVC_TYPE_TIMESYNC_DISABLE,
542 NULL, 0, NULL, 0);
543}
544
545int gb_svc_timesync_authoritative(struct gb_svc *svc, u64 *frame_time)
546{
547 struct gb_connection *connection = svc->connection;
548 struct gb_svc_timesync_authoritative_response response;
549 int ret, i;
550
551 ret = gb_operation_sync(connection,
552 GB_SVC_TYPE_TIMESYNC_AUTHORITATIVE, NULL, 0,
553 &response, sizeof(response));
554 if (ret < 0)
555 return ret;
556
557 for (i = 0; i < GB_TIMESYNC_MAX_STROBES; i++)
558 frame_time[i] = le64_to_cpu(response.frame_time[i]);
559 return 0;
560}
561
562int gb_svc_timesync_ping(struct gb_svc *svc, u64 *frame_time)
563{
564 struct gb_connection *connection = svc->connection;
565 struct gb_svc_timesync_ping_response response;
566 int ret;
567
568 ret = gb_operation_sync(connection,
569 GB_SVC_TYPE_TIMESYNC_PING,
570 NULL, 0,
571 &response, sizeof(response));
572 if (ret < 0)
573 return ret;
574
575 *frame_time = le64_to_cpu(response.frame_time);
576 return 0;
577}
578
579int gb_svc_timesync_wake_pins_acquire(struct gb_svc *svc, u32 strobe_mask)
580{
581 struct gb_connection *connection = svc->connection;
582 struct gb_svc_timesync_wake_pins_acquire_request request;
583
584 request.strobe_mask = cpu_to_le32(strobe_mask);
585 return gb_operation_sync(connection,
586 GB_SVC_TYPE_TIMESYNC_WAKE_PINS_ACQUIRE,
587 &request, sizeof(request),
588 NULL, 0);
589}
590
591int gb_svc_timesync_wake_pins_release(struct gb_svc *svc)
592{
593 struct gb_connection *connection = svc->connection;
594
595 return gb_operation_sync(connection,
596 GB_SVC_TYPE_TIMESYNC_WAKE_PINS_RELEASE,
597 NULL, 0, NULL, 0);
598}
599
600/* Creates bi-directional routes between the devices */ 521/* Creates bi-directional routes between the devices */
601int gb_svc_route_create(struct gb_svc *svc, u8 intf1_id, u8 dev1_id, 522int gb_svc_route_create(struct gb_svc *svc, u8 intf1_id, u8 dev1_id,
602 u8 intf2_id, u8 dev2_id) 523 u8 intf2_id, u8 dev2_id)
@@ -757,7 +678,8 @@ static int gb_svc_version_request(struct gb_operation *op)
757static ssize_t pwr_debugfs_voltage_read(struct file *file, char __user *buf, 678static ssize_t pwr_debugfs_voltage_read(struct file *file, char __user *buf,
758 size_t len, loff_t *offset) 679 size_t len, loff_t *offset)
759{ 680{
760 struct svc_debugfs_pwrmon_rail *pwrmon_rails = file_inode(file)->i_private; 681 struct svc_debugfs_pwrmon_rail *pwrmon_rails =
682 file_inode(file)->i_private;
761 struct gb_svc *svc = pwrmon_rails->svc; 683 struct gb_svc *svc = pwrmon_rails->svc;
762 int ret, desc; 684 int ret, desc;
763 u32 value; 685 u32 value;
@@ -780,7 +702,8 @@ static ssize_t pwr_debugfs_voltage_read(struct file *file, char __user *buf,
780static ssize_t pwr_debugfs_current_read(struct file *file, char __user *buf, 702static ssize_t pwr_debugfs_current_read(struct file *file, char __user *buf,
781 size_t len, loff_t *offset) 703 size_t len, loff_t *offset)
782{ 704{
783 struct svc_debugfs_pwrmon_rail *pwrmon_rails = file_inode(file)->i_private; 705 struct svc_debugfs_pwrmon_rail *pwrmon_rails =
706 file_inode(file)->i_private;
784 struct gb_svc *svc = pwrmon_rails->svc; 707 struct gb_svc *svc = pwrmon_rails->svc;
785 int ret, desc; 708 int ret, desc;
786 u32 value; 709 u32 value;
@@ -803,7 +726,8 @@ static ssize_t pwr_debugfs_current_read(struct file *file, char __user *buf,
803static ssize_t pwr_debugfs_power_read(struct file *file, char __user *buf, 726static ssize_t pwr_debugfs_power_read(struct file *file, char __user *buf,
804 size_t len, loff_t *offset) 727 size_t len, loff_t *offset)
805{ 728{
806 struct svc_debugfs_pwrmon_rail *pwrmon_rails = file_inode(file)->i_private; 729 struct svc_debugfs_pwrmon_rail *pwrmon_rails =
730 file_inode(file)->i_private;
807 struct gb_svc *svc = pwrmon_rails->svc; 731 struct gb_svc *svc = pwrmon_rails->svc;
808 int ret, desc; 732 int ret, desc;
809 u32 value; 733 u32 value;
@@ -879,11 +803,11 @@ static void gb_svc_pwrmon_debugfs_init(struct gb_svc *svc)
879 rail->svc = svc; 803 rail->svc = svc;
880 804
881 dir = debugfs_create_dir(fname, dent); 805 dir = debugfs_create_dir(fname, dent);
882 debugfs_create_file("voltage_now", S_IRUGO, dir, rail, 806 debugfs_create_file("voltage_now", 0444, dir, rail,
883 &pwrmon_debugfs_voltage_fops); 807 &pwrmon_debugfs_voltage_fops);
884 debugfs_create_file("current_now", S_IRUGO, dir, rail, 808 debugfs_create_file("current_now", 0444, dir, rail,
885 &pwrmon_debugfs_current_fops); 809 &pwrmon_debugfs_current_fops);
886 debugfs_create_file("power_now", S_IRUGO, dir, rail, 810 debugfs_create_file("power_now", 0444, dir, rail,
887 &pwrmon_debugfs_power_fops); 811 &pwrmon_debugfs_power_fops);
888 } 812 }
889 813
@@ -945,13 +869,6 @@ static int gb_svc_hello(struct gb_operation *op)
945 869
946 gb_svc_debugfs_init(svc); 870 gb_svc_debugfs_init(svc);
947 871
948 ret = gb_timesync_svc_add(svc);
949 if (ret) {
950 dev_err(&svc->dev, "failed to add SVC to timesync: %d\n", ret);
951 gb_svc_debugfs_exit(svc);
952 goto err_unregister_device;
953 }
954
955 return gb_svc_queue_deferred_request(op); 872 return gb_svc_queue_deferred_request(op);
956 873
957err_unregister_device: 874err_unregister_device:
@@ -1010,14 +927,15 @@ static void gb_svc_process_hello_deferred(struct gb_operation *operation)
1010 * Power Mode Changes is resolved. 927 * Power Mode Changes is resolved.
1011 */ 928 */
1012 ret = gb_svc_intf_set_power_mode(svc, svc->ap_intf_id, 929 ret = gb_svc_intf_set_power_mode(svc, svc->ap_intf_id,
1013 GB_SVC_UNIPRO_HS_SERIES_A, 930 GB_SVC_UNIPRO_HS_SERIES_A,
1014 GB_SVC_UNIPRO_SLOW_AUTO_MODE, 931 GB_SVC_UNIPRO_SLOW_AUTO_MODE,
1015 2, 1, 932 2, 1,
1016 GB_SVC_SMALL_AMPLITUDE, GB_SVC_NO_DE_EMPHASIS, 933 GB_SVC_SMALL_AMPLITUDE,
1017 GB_SVC_UNIPRO_SLOW_AUTO_MODE, 934 GB_SVC_NO_DE_EMPHASIS,
1018 2, 1, 935 GB_SVC_UNIPRO_SLOW_AUTO_MODE,
1019 0, 0, 936 2, 1,
1020 NULL, NULL); 937 0, 0,
938 NULL, NULL);
1021 939
1022 if (ret) 940 if (ret)
1023 dev_warn(&svc->dev, 941 dev_warn(&svc->dev,
@@ -1467,7 +1385,6 @@ void gb_svc_del(struct gb_svc *svc)
1467 * The SVC device may have been registered from the request handler. 1385 * The SVC device may have been registered from the request handler.
1468 */ 1386 */
1469 if (device_is_registered(&svc->dev)) { 1387 if (device_is_registered(&svc->dev)) {
1470 gb_timesync_svc_remove(svc);
1471 gb_svc_debugfs_exit(svc); 1388 gb_svc_debugfs_exit(svc);
1472 gb_svc_watchdog_destroy(svc); 1389 gb_svc_watchdog_destroy(svc);
1473 device_del(&svc->dev); 1390 device_del(&svc->dev);
diff --git a/drivers/staging/greybus/svc.h b/drivers/staging/greybus/svc.h
index d1d7ef967385..226c2a396fc8 100644
--- a/drivers/staging/greybus/svc.h
+++ b/drivers/staging/greybus/svc.h
@@ -95,13 +95,6 @@ void gb_svc_watchdog_destroy(struct gb_svc *svc);
95bool gb_svc_watchdog_enabled(struct gb_svc *svc); 95bool gb_svc_watchdog_enabled(struct gb_svc *svc);
96int gb_svc_watchdog_enable(struct gb_svc *svc); 96int gb_svc_watchdog_enable(struct gb_svc *svc);
97int gb_svc_watchdog_disable(struct gb_svc *svc); 97int gb_svc_watchdog_disable(struct gb_svc *svc);
98int gb_svc_timesync_enable(struct gb_svc *svc, u8 count, u64 frame_time,
99 u32 strobe_delay, u32 refclk);
100int gb_svc_timesync_disable(struct gb_svc *svc);
101int gb_svc_timesync_authoritative(struct gb_svc *svc, u64 *frame_time);
102int gb_svc_timesync_ping(struct gb_svc *svc, u64 *frame_time);
103int gb_svc_timesync_wake_pins_acquire(struct gb_svc *svc, u32 strobe_mask);
104int gb_svc_timesync_wake_pins_release(struct gb_svc *svc);
105 98
106int gb_svc_protocol_init(void); 99int gb_svc_protocol_init(void);
107void gb_svc_protocol_exit(void); 100void gb_svc_protocol_exit(void);
diff --git a/drivers/staging/greybus/svc_watchdog.c b/drivers/staging/greybus/svc_watchdog.c
index 12cef5c06e27..779fbea5d4ba 100644
--- a/drivers/staging/greybus/svc_watchdog.c
+++ b/drivers/staging/greybus/svc_watchdog.c
@@ -11,7 +11,7 @@
11#include <linux/workqueue.h> 11#include <linux/workqueue.h>
12#include "greybus.h" 12#include "greybus.h"
13 13
14#define SVC_WATCHDOG_PERIOD (2*HZ) 14#define SVC_WATCHDOG_PERIOD (2 * HZ)
15 15
16struct gb_svc_watchdog { 16struct gb_svc_watchdog {
17 struct delayed_work work; 17 struct delayed_work work;
@@ -56,7 +56,7 @@ static void greybus_reset(struct work_struct *work)
56 NULL, 56 NULL,
57 }; 57 };
58 58
59 printk(KERN_ERR "svc_watchdog: calling \"%s %s\" to reset greybus network!\n", 59 pr_err("svc_watchdog: calling \"%s %s\" to reset greybus network!\n",
60 argv[0], argv[1]); 60 argv[0], argv[1]);
61 call_usermodehelper(start_path, argv, envp, UMH_WAIT_EXEC); 61 call_usermodehelper(start_path, argv, envp, UMH_WAIT_EXEC);
62} 62}
diff --git a/drivers/staging/greybus/timesync.c b/drivers/staging/greybus/timesync.c
deleted file mode 100644
index 29e6c1c12807..000000000000
--- a/drivers/staging/greybus/timesync.c
+++ /dev/null
@@ -1,1357 +0,0 @@
1/*
2 * TimeSync API driver.
3 *
4 * Copyright 2016 Google Inc.
5 * Copyright 2016 Linaro Ltd.
6 *
7 * Released under the GPLv2 only.
8 */
9#include <linux/debugfs.h>
10#include <linux/hrtimer.h>
11#include "greybus.h"
12#include "timesync.h"
13#include "greybus_trace.h"
14
15/*
16 * Minimum inter-strobe value of one millisecond is chosen because it
17 * just-about fits the common definition of a jiffy.
18 *
19 * Maximum value OTOH is constrained by the number of bits the SVC can fit
20 * into a 16 bit up-counter. The SVC configures the timer in microseconds
21 * so the maximum allowable value is 65535 microseconds. We clip that value
22 * to 10000 microseconds for the sake of using nice round base 10 numbers
23 * and since right-now there's no imaginable use-case requiring anything
24 * other than a one millisecond inter-strobe time, let alone something
25 * higher than ten milliseconds.
26 */
27#define GB_TIMESYNC_STROBE_DELAY_US 1000
28#define GB_TIMESYNC_DEFAULT_OFFSET_US 1000
29
30/* Work queue timers long, short and SVC strobe timeout */
31#define GB_TIMESYNC_DELAYED_WORK_LONG msecs_to_jiffies(10)
32#define GB_TIMESYNC_DELAYED_WORK_SHORT msecs_to_jiffies(1)
33#define GB_TIMESYNC_MAX_WAIT_SVC msecs_to_jiffies(5000)
34#define GB_TIMESYNC_KTIME_UPDATE msecs_to_jiffies(1000)
35#define GB_TIMESYNC_MAX_KTIME_CONVERSION 15
36
37/* Maximum number of times we'll retry a failed synchronous sync */
38#define GB_TIMESYNC_MAX_RETRIES 5
39
40/* Reported nanoseconds/femtoseconds per clock */
41static u64 gb_timesync_ns_per_clock;
42static u64 gb_timesync_fs_per_clock;
43
44/* Maximum difference we will accept converting FrameTime to ktime */
45static u32 gb_timesync_max_ktime_diff;
46
47/* Reported clock rate */
48static unsigned long gb_timesync_clock_rate;
49
50/* Workqueue */
51static void gb_timesync_worker(struct work_struct *work);
52
53/* List of SVCs with one FrameTime per SVC */
54static LIST_HEAD(gb_timesync_svc_list);
55
56/* Synchronize parallel contexts accessing a valid timesync_svc pointer */
57static DEFINE_MUTEX(gb_timesync_svc_list_mutex);
58
59/* Structure to convert from FrameTime to timespec/ktime */
60struct gb_timesync_frame_time_data {
61 u64 frame_time;
62 struct timespec ts;
63};
64
65struct gb_timesync_svc {
66 struct list_head list;
67 struct list_head interface_list;
68 struct gb_svc *svc;
69 struct gb_timesync_host_device *timesync_hd;
70
71 spinlock_t spinlock; /* Per SVC spinlock to sync with ISR */
72 struct mutex mutex; /* Per SVC mutex for regular synchronization */
73
74 struct dentry *frame_time_dentry;
75 struct dentry *frame_ktime_dentry;
76 struct workqueue_struct *work_queue;
77 wait_queue_head_t wait_queue;
78 struct delayed_work delayed_work;
79 struct timer_list ktime_timer;
80
81 /* The current local FrameTime */
82 u64 frame_time_offset;
83 struct gb_timesync_frame_time_data strobe_data[GB_TIMESYNC_MAX_STROBES];
84 struct gb_timesync_frame_time_data ktime_data;
85
86 /* The SVC FrameTime and relative AP FrameTime @ last TIMESYNC_PING */
87 u64 svc_ping_frame_time;
88 u64 ap_ping_frame_time;
89
90 /* Transitory settings */
91 u32 strobe_mask;
92 bool offset_down;
93 bool print_ping;
94 bool capture_ping;
95 int strobe;
96
97 /* Current state */
98 int state;
99};
100
101struct gb_timesync_host_device {
102 struct list_head list;
103 struct gb_host_device *hd;
104 u64 ping_frame_time;
105};
106
107struct gb_timesync_interface {
108 struct list_head list;
109 struct gb_interface *interface;
110 u64 ping_frame_time;
111};
112
113enum gb_timesync_state {
114 GB_TIMESYNC_STATE_INVALID = 0,
115 GB_TIMESYNC_STATE_INACTIVE = 1,
116 GB_TIMESYNC_STATE_INIT = 2,
117 GB_TIMESYNC_STATE_WAIT_SVC = 3,
118 GB_TIMESYNC_STATE_AUTHORITATIVE = 4,
119 GB_TIMESYNC_STATE_PING = 5,
120 GB_TIMESYNC_STATE_ACTIVE = 6,
121};
122
123static void gb_timesync_ktime_timer_fn(unsigned long data);
124
125static u64 gb_timesync_adjust_count(struct gb_timesync_svc *timesync_svc,
126 u64 counts)
127{
128 if (timesync_svc->offset_down)
129 return counts - timesync_svc->frame_time_offset;
130 else
131 return counts + timesync_svc->frame_time_offset;
132}
133
134/*
135 * This function provides the authoritative FrameTime to a calling function. It
136 * is designed to be lockless and should remain that way the caller is assumed
137 * to be state-aware.
138 */
139static u64 __gb_timesync_get_frame_time(struct gb_timesync_svc *timesync_svc)
140{
141 u64 clocks = gb_timesync_platform_get_counter();
142
143 return gb_timesync_adjust_count(timesync_svc, clocks);
144}
145
146static void gb_timesync_schedule_svc_timeout(struct gb_timesync_svc
147 *timesync_svc)
148{
149 queue_delayed_work(timesync_svc->work_queue,
150 &timesync_svc->delayed_work,
151 GB_TIMESYNC_MAX_WAIT_SVC);
152}
153
154static void gb_timesync_set_state(struct gb_timesync_svc *timesync_svc,
155 int state)
156{
157 switch (state) {
158 case GB_TIMESYNC_STATE_INVALID:
159 timesync_svc->state = state;
160 wake_up(&timesync_svc->wait_queue);
161 break;
162 case GB_TIMESYNC_STATE_INACTIVE:
163 timesync_svc->state = state;
164 wake_up(&timesync_svc->wait_queue);
165 break;
166 case GB_TIMESYNC_STATE_INIT:
167 if (timesync_svc->state != GB_TIMESYNC_STATE_INVALID) {
168 timesync_svc->strobe = 0;
169 timesync_svc->frame_time_offset = 0;
170 timesync_svc->state = state;
171 cancel_delayed_work(&timesync_svc->delayed_work);
172 queue_delayed_work(timesync_svc->work_queue,
173 &timesync_svc->delayed_work,
174 GB_TIMESYNC_DELAYED_WORK_LONG);
175 }
176 break;
177 case GB_TIMESYNC_STATE_WAIT_SVC:
178 if (timesync_svc->state == GB_TIMESYNC_STATE_INIT)
179 timesync_svc->state = state;
180 break;
181 case GB_TIMESYNC_STATE_AUTHORITATIVE:
182 if (timesync_svc->state == GB_TIMESYNC_STATE_WAIT_SVC) {
183 timesync_svc->state = state;
184 cancel_delayed_work(&timesync_svc->delayed_work);
185 queue_delayed_work(timesync_svc->work_queue,
186 &timesync_svc->delayed_work, 0);
187 }
188 break;
189 case GB_TIMESYNC_STATE_PING:
190 if (timesync_svc->state == GB_TIMESYNC_STATE_ACTIVE) {
191 timesync_svc->state = state;
192 queue_delayed_work(timesync_svc->work_queue,
193 &timesync_svc->delayed_work,
194 GB_TIMESYNC_DELAYED_WORK_SHORT);
195 }
196 break;
197 case GB_TIMESYNC_STATE_ACTIVE:
198 if (timesync_svc->state == GB_TIMESYNC_STATE_AUTHORITATIVE ||
199 timesync_svc->state == GB_TIMESYNC_STATE_PING) {
200 timesync_svc->state = state;
201 wake_up(&timesync_svc->wait_queue);
202 }
203 break;
204 }
205
206 if (WARN_ON(timesync_svc->state != state)) {
207 pr_err("Invalid state transition %d=>%d\n",
208 timesync_svc->state, state);
209 }
210}
211
212static void gb_timesync_set_state_atomic(struct gb_timesync_svc *timesync_svc,
213 int state)
214{
215 unsigned long flags;
216
217 spin_lock_irqsave(&timesync_svc->spinlock, flags);
218 gb_timesync_set_state(timesync_svc, state);
219 spin_unlock_irqrestore(&timesync_svc->spinlock, flags);
220}
221
222static u64 gb_timesync_diff(u64 x, u64 y)
223{
224 if (x > y)
225 return x - y;
226 else
227 return y - x;
228}
229
230static void gb_timesync_adjust_to_svc(struct gb_timesync_svc *svc,
231 u64 svc_frame_time, u64 ap_frame_time)
232{
233 if (svc_frame_time > ap_frame_time) {
234 svc->frame_time_offset = svc_frame_time - ap_frame_time;
235 svc->offset_down = false;
236 } else {
237 svc->frame_time_offset = ap_frame_time - svc_frame_time;
238 svc->offset_down = true;
239 }
240}
241
242/*
243 * Associate a FrameTime with a ktime timestamp represented as struct timespec
244 * Requires the calling context to hold timesync_svc->mutex
245 */
246static void gb_timesync_store_ktime(struct gb_timesync_svc *timesync_svc,
247 struct timespec ts, u64 frame_time)
248{
249 timesync_svc->ktime_data.ts = ts;
250 timesync_svc->ktime_data.frame_time = frame_time;
251}
252
253/*
254 * Find the two pulses that best-match our expected inter-strobe gap and
255 * then calculate the difference between the SVC time at the second pulse
256 * to the local time at the second pulse.
257 */
258static void gb_timesync_collate_frame_time(struct gb_timesync_svc *timesync_svc,
259 u64 *frame_time)
260{
261 int i = 0;
262 u64 delta, ap_frame_time;
263 u64 strobe_delay_ns = GB_TIMESYNC_STROBE_DELAY_US * NSEC_PER_USEC;
264 u64 least = 0;
265
266 for (i = 1; i < GB_TIMESYNC_MAX_STROBES; i++) {
267 delta = timesync_svc->strobe_data[i].frame_time -
268 timesync_svc->strobe_data[i - 1].frame_time;
269 delta *= gb_timesync_ns_per_clock;
270 delta = gb_timesync_diff(delta, strobe_delay_ns);
271
272 if (!least || delta < least) {
273 least = delta;
274 gb_timesync_adjust_to_svc(timesync_svc, frame_time[i],
275 timesync_svc->strobe_data[i].frame_time);
276
277 ap_frame_time = timesync_svc->strobe_data[i].frame_time;
278 ap_frame_time = gb_timesync_adjust_count(timesync_svc,
279 ap_frame_time);
280 gb_timesync_store_ktime(timesync_svc,
281 timesync_svc->strobe_data[i].ts,
282 ap_frame_time);
283
284 pr_debug("adjust %s local %llu svc %llu delta %llu\n",
285 timesync_svc->offset_down ? "down" : "up",
286 timesync_svc->strobe_data[i].frame_time,
287 frame_time[i], delta);
288 }
289 }
290}
291
292static void gb_timesync_teardown(struct gb_timesync_svc *timesync_svc)
293{
294 struct gb_timesync_interface *timesync_interface;
295 struct gb_svc *svc = timesync_svc->svc;
296 struct gb_interface *interface;
297 struct gb_host_device *hd;
298 int ret;
299
300 list_for_each_entry(timesync_interface,
301 &timesync_svc->interface_list, list) {
302 interface = timesync_interface->interface;
303 ret = gb_interface_timesync_disable(interface);
304 if (ret) {
305 dev_err(&interface->dev,
306 "interface timesync_disable %d\n", ret);
307 }
308 }
309
310 hd = timesync_svc->timesync_hd->hd;
311 ret = hd->driver->timesync_disable(hd);
312 if (ret < 0) {
313 dev_err(&hd->dev, "host timesync_disable %d\n",
314 ret);
315 }
316
317 gb_svc_timesync_wake_pins_release(svc);
318 gb_svc_timesync_disable(svc);
319 gb_timesync_platform_unlock_bus();
320
321 gb_timesync_set_state_atomic(timesync_svc, GB_TIMESYNC_STATE_INACTIVE);
322}
323
324static void gb_timesync_platform_lock_bus_fail(struct gb_timesync_svc
325 *timesync_svc, int ret)
326{
327 if (ret == -EAGAIN) {
328 gb_timesync_set_state(timesync_svc, timesync_svc->state);
329 } else {
330 pr_err("Failed to lock timesync bus %d\n", ret);
331 gb_timesync_set_state(timesync_svc, GB_TIMESYNC_STATE_INACTIVE);
332 }
333}
334
335static void gb_timesync_enable(struct gb_timesync_svc *timesync_svc)
336{
337 struct gb_svc *svc = timesync_svc->svc;
338 struct gb_host_device *hd;
339 struct gb_timesync_interface *timesync_interface;
340 struct gb_interface *interface;
341 u64 init_frame_time;
342 unsigned long clock_rate = gb_timesync_clock_rate;
343 int ret;
344
345 /*
346 * Get access to the wake pins in the AP and SVC
347 * Release these pins either in gb_timesync_teardown() or in
348 * gb_timesync_authoritative()
349 */
350 ret = gb_timesync_platform_lock_bus(timesync_svc);
351 if (ret < 0) {
352 gb_timesync_platform_lock_bus_fail(timesync_svc, ret);
353 return;
354 }
355 ret = gb_svc_timesync_wake_pins_acquire(svc, timesync_svc->strobe_mask);
356 if (ret) {
357 dev_err(&svc->dev,
358 "gb_svc_timesync_wake_pins_acquire %d\n", ret);
359 gb_timesync_teardown(timesync_svc);
360 return;
361 }
362
363 /* Choose an initial time in the future */
364 init_frame_time = __gb_timesync_get_frame_time(timesync_svc) + 100000UL;
365
366 /* Send enable command to all relevant participants */
367 list_for_each_entry(timesync_interface, &timesync_svc->interface_list,
368 list) {
369 interface = timesync_interface->interface;
370 ret = gb_interface_timesync_enable(interface,
371 GB_TIMESYNC_MAX_STROBES,
372 init_frame_time,
373 GB_TIMESYNC_STROBE_DELAY_US,
374 clock_rate);
375 if (ret) {
376 dev_err(&interface->dev,
377 "interface timesync_enable %d\n", ret);
378 }
379 }
380
381 hd = timesync_svc->timesync_hd->hd;
382 ret = hd->driver->timesync_enable(hd, GB_TIMESYNC_MAX_STROBES,
383 init_frame_time,
384 GB_TIMESYNC_STROBE_DELAY_US,
385 clock_rate);
386 if (ret < 0) {
387 dev_err(&hd->dev, "host timesync_enable %d\n",
388 ret);
389 }
390
391 gb_timesync_set_state_atomic(timesync_svc, GB_TIMESYNC_STATE_WAIT_SVC);
392 ret = gb_svc_timesync_enable(svc, GB_TIMESYNC_MAX_STROBES,
393 init_frame_time,
394 GB_TIMESYNC_STROBE_DELAY_US,
395 clock_rate);
396 if (ret) {
397 dev_err(&svc->dev,
398 "gb_svc_timesync_enable %d\n", ret);
399 gb_timesync_teardown(timesync_svc);
400 return;
401 }
402
403 /* Schedule a timeout waiting for SVC to complete strobing */
404 gb_timesync_schedule_svc_timeout(timesync_svc);
405}
406
407static void gb_timesync_authoritative(struct gb_timesync_svc *timesync_svc)
408{
409 struct gb_svc *svc = timesync_svc->svc;
410 struct gb_host_device *hd;
411 struct gb_timesync_interface *timesync_interface;
412 struct gb_interface *interface;
413 u64 svc_frame_time[GB_TIMESYNC_MAX_STROBES];
414 int ret;
415
416 /* Get authoritative time from SVC and adjust local clock */
417 ret = gb_svc_timesync_authoritative(svc, svc_frame_time);
418 if (ret) {
419 dev_err(&svc->dev,
420 "gb_svc_timesync_authoritative %d\n", ret);
421 gb_timesync_teardown(timesync_svc);
422 return;
423 }
424 gb_timesync_collate_frame_time(timesync_svc, svc_frame_time);
425
426 /* Transmit authoritative time to downstream slaves */
427 hd = timesync_svc->timesync_hd->hd;
428 ret = hd->driver->timesync_authoritative(hd, svc_frame_time);
429 if (ret < 0)
430 dev_err(&hd->dev, "host timesync_authoritative %d\n", ret);
431
432 list_for_each_entry(timesync_interface,
433 &timesync_svc->interface_list, list) {
434 interface = timesync_interface->interface;
435 ret = gb_interface_timesync_authoritative(
436 interface,
437 svc_frame_time);
438 if (ret) {
439 dev_err(&interface->dev,
440 "interface timesync_authoritative %d\n", ret);
441 }
442 }
443
444 /* Release wake pins */
445 gb_svc_timesync_wake_pins_release(svc);
446 gb_timesync_platform_unlock_bus();
447
448 /* Transition to state ACTIVE */
449 gb_timesync_set_state_atomic(timesync_svc, GB_TIMESYNC_STATE_ACTIVE);
450
451 /* Schedule a ping to verify the synchronized system time */
452 timesync_svc->print_ping = true;
453 gb_timesync_set_state_atomic(timesync_svc, GB_TIMESYNC_STATE_PING);
454}
455
456static int __gb_timesync_get_status(struct gb_timesync_svc *timesync_svc)
457{
458 int ret = -EINVAL;
459
460 switch (timesync_svc->state) {
461 case GB_TIMESYNC_STATE_INVALID:
462 case GB_TIMESYNC_STATE_INACTIVE:
463 ret = -ENODEV;
464 break;
465 case GB_TIMESYNC_STATE_INIT:
466 case GB_TIMESYNC_STATE_WAIT_SVC:
467 case GB_TIMESYNC_STATE_AUTHORITATIVE:
468 ret = -EAGAIN;
469 break;
470 case GB_TIMESYNC_STATE_PING:
471 case GB_TIMESYNC_STATE_ACTIVE:
472 ret = 0;
473 break;
474 }
475 return ret;
476}
477
478/*
479 * This routine takes a FrameTime and derives the difference with-respect
480 * to a reference FrameTime/ktime pair. It then returns the calculated
481 * ktime based on the difference between the supplied FrameTime and
482 * the reference FrameTime.
483 *
484 * The time difference is calculated to six decimal places. Taking 19.2MHz
485 * as an example this means we have 52.083333~ nanoseconds per clock or
486 * 52083333~ femtoseconds per clock.
487 *
488 * Naively taking the count difference and converting to
489 * seconds/nanoseconds would quickly see the 0.0833 component produce
490 * noticeable errors. For example a time difference of one second would
491 * loose 19200000 * 0.08333x nanoseconds or 1.59 seconds.
492 *
493 * In contrast calculating in femtoseconds the same example of 19200000 *
494 * 0.000000083333x nanoseconds per count of error is just 1.59 nanoseconds!
495 *
496 * Continuing the example of 19.2 MHz we cap the maximum error difference
497 * at a worst-case 0.3 microseconds over a potential calculation window of
498 * abount 15 seconds, meaning you can convert a FrameTime that is <= 15
499 * seconds older/younger than the reference time with a maximum error of
500 * 0.2385 useconds. Note 19.2MHz is an example frequency not a requirement.
501 */
502static int gb_timesync_to_timespec(struct gb_timesync_svc *timesync_svc,
503 u64 frame_time, struct timespec *ts)
504{
505 unsigned long flags;
506 u64 delta_fs, counts, sec, nsec;
507 bool add;
508 int ret = 0;
509
510 memset(ts, 0x00, sizeof(*ts));
511 mutex_lock(&timesync_svc->mutex);
512 spin_lock_irqsave(&timesync_svc->spinlock, flags);
513
514 ret = __gb_timesync_get_status(timesync_svc);
515 if (ret)
516 goto done;
517
518 /* Support calculating ktime upwards or downwards from the reference */
519 if (frame_time < timesync_svc->ktime_data.frame_time) {
520 add = false;
521 counts = timesync_svc->ktime_data.frame_time - frame_time;
522 } else {
523 add = true;
524 counts = frame_time - timesync_svc->ktime_data.frame_time;
525 }
526
527 /* Enforce the .23 of a usecond boundary @ 19.2MHz */
528 if (counts > gb_timesync_max_ktime_diff) {
529 ret = -EINVAL;
530 goto done;
531 }
532
533 /* Determine the time difference in femtoseconds */
534 delta_fs = counts * gb_timesync_fs_per_clock;
535
536 /* Convert to seconds */
537 sec = delta_fs;
538 do_div(sec, NSEC_PER_SEC);
539 do_div(sec, 1000000UL);
540
541 /* Get the nanosecond remainder */
542 nsec = do_div(delta_fs, sec);
543 do_div(nsec, 1000000UL);
544
545 if (add) {
546 /* Add the calculated offset - overflow nanoseconds upwards */
547 ts->tv_sec = timesync_svc->ktime_data.ts.tv_sec + sec;
548 ts->tv_nsec = timesync_svc->ktime_data.ts.tv_nsec + nsec;
549 if (ts->tv_nsec >= NSEC_PER_SEC) {
550 ts->tv_sec++;
551 ts->tv_nsec -= NSEC_PER_SEC;
552 }
553 } else {
554 /* Subtract the difference over/underflow as necessary */
555 if (nsec > timesync_svc->ktime_data.ts.tv_nsec) {
556 sec++;
557 nsec = nsec + timesync_svc->ktime_data.ts.tv_nsec;
558 nsec = do_div(nsec, NSEC_PER_SEC);
559 } else {
560 nsec = timesync_svc->ktime_data.ts.tv_nsec - nsec;
561 }
562 /* Cannot return a negative second value */
563 if (sec > timesync_svc->ktime_data.ts.tv_sec) {
564 ret = -EINVAL;
565 goto done;
566 }
567 ts->tv_sec = timesync_svc->ktime_data.ts.tv_sec - sec;
568 ts->tv_nsec = nsec;
569 }
570done:
571 spin_unlock_irqrestore(&timesync_svc->spinlock, flags);
572 mutex_unlock(&timesync_svc->mutex);
573 return ret;
574}
575
576static size_t gb_timesync_log_frame_time(struct gb_timesync_svc *timesync_svc,
577 char *buf, size_t buflen)
578{
579 struct gb_svc *svc = timesync_svc->svc;
580 struct gb_host_device *hd;
581 struct gb_timesync_interface *timesync_interface;
582 struct gb_interface *interface;
583 unsigned int len;
584 size_t off;
585
586 /* AP/SVC */
587 off = snprintf(buf, buflen, "%s frametime: ap=%llu %s=%llu ",
588 greybus_bus_type.name,
589 timesync_svc->ap_ping_frame_time, dev_name(&svc->dev),
590 timesync_svc->svc_ping_frame_time);
591 len = buflen - off;
592
593 /* APB/GPB */
594 if (len < buflen) {
595 hd = timesync_svc->timesync_hd->hd;
596 off += snprintf(&buf[off], len, "%s=%llu ", dev_name(&hd->dev),
597 timesync_svc->timesync_hd->ping_frame_time);
598 len = buflen - off;
599 }
600
601 list_for_each_entry(timesync_interface,
602 &timesync_svc->interface_list, list) {
603 if (len < buflen) {
604 interface = timesync_interface->interface;
605 off += snprintf(&buf[off], len, "%s=%llu ",
606 dev_name(&interface->dev),
607 timesync_interface->ping_frame_time);
608 len = buflen - off;
609 }
610 }
611 if (len < buflen)
612 off += snprintf(&buf[off], len, "\n");
613 return off;
614}
615
616static size_t gb_timesync_log_frame_ktime(struct gb_timesync_svc *timesync_svc,
617 char *buf, size_t buflen)
618{
619 struct gb_svc *svc = timesync_svc->svc;
620 struct gb_host_device *hd;
621 struct gb_timesync_interface *timesync_interface;
622 struct gb_interface *interface;
623 struct timespec ts;
624 unsigned int len;
625 size_t off;
626
627 /* AP */
628 gb_timesync_to_timespec(timesync_svc, timesync_svc->ap_ping_frame_time,
629 &ts);
630 off = snprintf(buf, buflen, "%s frametime: ap=%lu.%lu ",
631 greybus_bus_type.name, ts.tv_sec, ts.tv_nsec);
632 len = buflen - off;
633 if (len >= buflen)
634 goto done;
635
636 /* SVC */
637 gb_timesync_to_timespec(timesync_svc, timesync_svc->svc_ping_frame_time,
638 &ts);
639 off += snprintf(&buf[off], len, "%s=%lu.%lu ", dev_name(&svc->dev),
640 ts.tv_sec, ts.tv_nsec);
641 len = buflen - off;
642 if (len >= buflen)
643 goto done;
644
645 /* APB/GPB */
646 hd = timesync_svc->timesync_hd->hd;
647 gb_timesync_to_timespec(timesync_svc,
648 timesync_svc->timesync_hd->ping_frame_time,
649 &ts);
650 off += snprintf(&buf[off], len, "%s=%lu.%lu ",
651 dev_name(&hd->dev),
652 ts.tv_sec, ts.tv_nsec);
653 len = buflen - off;
654 if (len >= buflen)
655 goto done;
656
657 list_for_each_entry(timesync_interface,
658 &timesync_svc->interface_list, list) {
659 interface = timesync_interface->interface;
660 gb_timesync_to_timespec(timesync_svc,
661 timesync_interface->ping_frame_time,
662 &ts);
663 off += snprintf(&buf[off], len, "%s=%lu.%lu ",
664 dev_name(&interface->dev),
665 ts.tv_sec, ts.tv_nsec);
666 len = buflen - off;
667 if (len >= buflen)
668 goto done;
669 }
670 off += snprintf(&buf[off], len, "\n");
671done:
672 return off;
673}
674
675/*
676 * Send an SVC initiated wake 'ping' to each TimeSync participant.
677 * Get the FrameTime from each participant associated with the wake
678 * ping.
679 */
680static void gb_timesync_ping(struct gb_timesync_svc *timesync_svc)
681{
682 struct gb_svc *svc = timesync_svc->svc;
683 struct gb_host_device *hd;
684 struct gb_timesync_interface *timesync_interface;
685 struct gb_control *control;
686 u64 *ping_frame_time;
687 int ret;
688
689 /* Get access to the wake pins in the AP and SVC */
690 ret = gb_timesync_platform_lock_bus(timesync_svc);
691 if (ret < 0) {
692 gb_timesync_platform_lock_bus_fail(timesync_svc, ret);
693 return;
694 }
695 ret = gb_svc_timesync_wake_pins_acquire(svc, timesync_svc->strobe_mask);
696 if (ret) {
697 dev_err(&svc->dev,
698 "gb_svc_timesync_wake_pins_acquire %d\n", ret);
699 gb_timesync_teardown(timesync_svc);
700 return;
701 }
702
703 /* Have SVC generate a timesync ping */
704 timesync_svc->capture_ping = true;
705 timesync_svc->svc_ping_frame_time = 0;
706 ret = gb_svc_timesync_ping(svc, &timesync_svc->svc_ping_frame_time);
707 timesync_svc->capture_ping = false;
708 if (ret) {
709 dev_err(&svc->dev,
710 "gb_svc_timesync_ping %d\n", ret);
711 gb_timesync_teardown(timesync_svc);
712 return;
713 }
714
715 /* Get the ping FrameTime from each APB/GPB */
716 hd = timesync_svc->timesync_hd->hd;
717 timesync_svc->timesync_hd->ping_frame_time = 0;
718 ret = hd->driver->timesync_get_last_event(hd,
719 &timesync_svc->timesync_hd->ping_frame_time);
720 if (ret)
721 dev_err(&hd->dev, "host timesync_get_last_event %d\n", ret);
722
723 list_for_each_entry(timesync_interface,
724 &timesync_svc->interface_list, list) {
725 control = timesync_interface->interface->control;
726 timesync_interface->ping_frame_time = 0;
727 ping_frame_time = &timesync_interface->ping_frame_time;
728 ret = gb_control_timesync_get_last_event(control,
729 ping_frame_time);
730 if (ret) {
731 dev_err(&timesync_interface->interface->dev,
732 "gb_control_timesync_get_last_event %d\n", ret);
733 }
734 }
735
736 /* Ping success - move to timesync active */
737 gb_svc_timesync_wake_pins_release(svc);
738 gb_timesync_platform_unlock_bus();
739 gb_timesync_set_state_atomic(timesync_svc, GB_TIMESYNC_STATE_ACTIVE);
740}
741
742static void gb_timesync_log_ping_time(struct gb_timesync_svc *timesync_svc)
743{
744 char *buf;
745
746 if (!timesync_svc->print_ping)
747 return;
748
749 buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
750 if (buf) {
751 gb_timesync_log_frame_time(timesync_svc, buf, PAGE_SIZE);
752 dev_dbg(&timesync_svc->svc->dev, "%s", buf);
753 kfree(buf);
754 }
755}
756
757/*
758 * Perform the actual work of scheduled TimeSync logic.
759 */
760static void gb_timesync_worker(struct work_struct *work)
761{
762 struct delayed_work *delayed_work = to_delayed_work(work);
763 struct gb_timesync_svc *timesync_svc =
764 container_of(delayed_work, struct gb_timesync_svc, delayed_work);
765
766 mutex_lock(&timesync_svc->mutex);
767
768 switch (timesync_svc->state) {
769 case GB_TIMESYNC_STATE_INIT:
770 gb_timesync_enable(timesync_svc);
771 break;
772
773 case GB_TIMESYNC_STATE_WAIT_SVC:
774 dev_err(&timesync_svc->svc->dev,
775 "timeout SVC strobe completion %d/%d\n",
776 timesync_svc->strobe, GB_TIMESYNC_MAX_STROBES);
777 gb_timesync_teardown(timesync_svc);
778 break;
779
780 case GB_TIMESYNC_STATE_AUTHORITATIVE:
781 gb_timesync_authoritative(timesync_svc);
782 break;
783
784 case GB_TIMESYNC_STATE_PING:
785 gb_timesync_ping(timesync_svc);
786 gb_timesync_log_ping_time(timesync_svc);
787 break;
788
789 default:
790 pr_err("Invalid state %d for delayed work\n",
791 timesync_svc->state);
792 break;
793 }
794
795 mutex_unlock(&timesync_svc->mutex);
796}
797
798/*
799 * Schedule a new TimeSync INIT or PING operation serialized w/r to
800 * gb_timesync_worker().
801 */
802static int gb_timesync_schedule(struct gb_timesync_svc *timesync_svc, int state)
803{
804 int ret = 0;
805
806 if (state != GB_TIMESYNC_STATE_INIT && state != GB_TIMESYNC_STATE_PING)
807 return -EINVAL;
808
809 mutex_lock(&timesync_svc->mutex);
810 if (timesync_svc->state != GB_TIMESYNC_STATE_INVALID)
811 gb_timesync_set_state_atomic(timesync_svc, state);
812 else
813 ret = -ENODEV;
814
815 mutex_unlock(&timesync_svc->mutex);
816 return ret;
817}
818
819static int __gb_timesync_schedule_synchronous(
820 struct gb_timesync_svc *timesync_svc, int state)
821{
822 unsigned long flags;
823 int ret;
824
825 ret = gb_timesync_schedule(timesync_svc, state);
826 if (ret)
827 return ret;
828
829 ret = wait_event_interruptible(timesync_svc->wait_queue,
830 (timesync_svc->state == GB_TIMESYNC_STATE_ACTIVE ||
831 timesync_svc->state == GB_TIMESYNC_STATE_INACTIVE ||
832 timesync_svc->state == GB_TIMESYNC_STATE_INVALID));
833 if (ret)
834 return ret;
835
836 mutex_lock(&timesync_svc->mutex);
837 spin_lock_irqsave(&timesync_svc->spinlock, flags);
838
839 ret = __gb_timesync_get_status(timesync_svc);
840
841 spin_unlock_irqrestore(&timesync_svc->spinlock, flags);
842 mutex_unlock(&timesync_svc->mutex);
843
844 return ret;
845}
846
847static struct gb_timesync_svc *gb_timesync_find_timesync_svc(
848 struct gb_host_device *hd)
849{
850 struct gb_timesync_svc *timesync_svc;
851
852 list_for_each_entry(timesync_svc, &gb_timesync_svc_list, list) {
853 if (timesync_svc->svc == hd->svc)
854 return timesync_svc;
855 }
856 return NULL;
857}
858
859static struct gb_timesync_interface *gb_timesync_find_timesync_interface(
860 struct gb_timesync_svc *timesync_svc,
861 struct gb_interface *interface)
862{
863 struct gb_timesync_interface *timesync_interface;
864
865 list_for_each_entry(timesync_interface, &timesync_svc->interface_list, list) {
866 if (timesync_interface->interface == interface)
867 return timesync_interface;
868 }
869 return NULL;
870}
871
872int gb_timesync_schedule_synchronous(struct gb_interface *interface)
873{
874 int ret;
875 struct gb_timesync_svc *timesync_svc;
876 int retries;
877
878 if (!(interface->features & GREYBUS_INTERFACE_FEATURE_TIMESYNC))
879 return 0;
880
881 mutex_lock(&gb_timesync_svc_list_mutex);
882 for (retries = 0; retries < GB_TIMESYNC_MAX_RETRIES; retries++) {
883 timesync_svc = gb_timesync_find_timesync_svc(interface->hd);
884 if (!timesync_svc) {
885 ret = -ENODEV;
886 goto done;
887 }
888
889 ret = __gb_timesync_schedule_synchronous(timesync_svc,
890 GB_TIMESYNC_STATE_INIT);
891 if (!ret)
892 break;
893 }
894 if (ret && retries == GB_TIMESYNC_MAX_RETRIES)
895 ret = -ETIMEDOUT;
896done:
897 mutex_unlock(&gb_timesync_svc_list_mutex);
898 return ret;
899}
900EXPORT_SYMBOL_GPL(gb_timesync_schedule_synchronous);
901
902void gb_timesync_schedule_asynchronous(struct gb_interface *interface)
903{
904 struct gb_timesync_svc *timesync_svc;
905
906 if (!(interface->features & GREYBUS_INTERFACE_FEATURE_TIMESYNC))
907 return;
908
909 mutex_lock(&gb_timesync_svc_list_mutex);
910 timesync_svc = gb_timesync_find_timesync_svc(interface->hd);
911 if (!timesync_svc)
912 goto done;
913
914 gb_timesync_schedule(timesync_svc, GB_TIMESYNC_STATE_INIT);
915done:
916 mutex_unlock(&gb_timesync_svc_list_mutex);
917 return;
918}
919EXPORT_SYMBOL_GPL(gb_timesync_schedule_asynchronous);
920
921static ssize_t gb_timesync_ping_read(struct file *file, char __user *ubuf,
922 size_t len, loff_t *offset, bool ktime)
923{
924 struct gb_timesync_svc *timesync_svc = file_inode(file)->i_private;
925 char *buf;
926 ssize_t ret = 0;
927
928 mutex_lock(&gb_timesync_svc_list_mutex);
929 mutex_lock(&timesync_svc->mutex);
930 if (list_empty(&timesync_svc->interface_list))
931 ret = -ENODEV;
932 timesync_svc->print_ping = false;
933 mutex_unlock(&timesync_svc->mutex);
934 if (ret)
935 goto done;
936
937 ret = __gb_timesync_schedule_synchronous(timesync_svc,
938 GB_TIMESYNC_STATE_PING);
939 if (ret)
940 goto done;
941
942 buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
943 if (!buf) {
944 ret = -ENOMEM;
945 goto done;
946 }
947
948 if (ktime)
949 ret = gb_timesync_log_frame_ktime(timesync_svc, buf, PAGE_SIZE);
950 else
951 ret = gb_timesync_log_frame_time(timesync_svc, buf, PAGE_SIZE);
952 if (ret > 0)
953 ret = simple_read_from_buffer(ubuf, len, offset, buf, ret);
954 kfree(buf);
955done:
956 mutex_unlock(&gb_timesync_svc_list_mutex);
957 return ret;
958}
959
960static ssize_t gb_timesync_ping_read_frame_time(struct file *file,
961 char __user *buf,
962 size_t len, loff_t *offset)
963{
964 return gb_timesync_ping_read(file, buf, len, offset, false);
965}
966
967static ssize_t gb_timesync_ping_read_frame_ktime(struct file *file,
968 char __user *buf,
969 size_t len, loff_t *offset)
970{
971 return gb_timesync_ping_read(file, buf, len, offset, true);
972}
973
974static const struct file_operations gb_timesync_debugfs_frame_time_ops = {
975 .read = gb_timesync_ping_read_frame_time,
976};
977
978static const struct file_operations gb_timesync_debugfs_frame_ktime_ops = {
979 .read = gb_timesync_ping_read_frame_ktime,
980};
981
982static int gb_timesync_hd_add(struct gb_timesync_svc *timesync_svc,
983 struct gb_host_device *hd)
984{
985 struct gb_timesync_host_device *timesync_hd;
986
987 timesync_hd = kzalloc(sizeof(*timesync_hd), GFP_KERNEL);
988 if (!timesync_hd)
989 return -ENOMEM;
990
991 WARN_ON(timesync_svc->timesync_hd);
992 timesync_hd->hd = hd;
993 timesync_svc->timesync_hd = timesync_hd;
994
995 return 0;
996}
997
998static void gb_timesync_hd_remove(struct gb_timesync_svc *timesync_svc,
999 struct gb_host_device *hd)
1000{
1001 if (timesync_svc->timesync_hd->hd == hd) {
1002 kfree(timesync_svc->timesync_hd);
1003 timesync_svc->timesync_hd = NULL;
1004 return;
1005 }
1006 WARN_ON(1);
1007}
1008
1009int gb_timesync_svc_add(struct gb_svc *svc)
1010{
1011 struct gb_timesync_svc *timesync_svc;
1012 int ret;
1013
1014 timesync_svc = kzalloc(sizeof(*timesync_svc), GFP_KERNEL);
1015 if (!timesync_svc)
1016 return -ENOMEM;
1017
1018 timesync_svc->work_queue =
1019 create_singlethread_workqueue("gb-timesync-work_queue");
1020
1021 if (!timesync_svc->work_queue) {
1022 kfree(timesync_svc);
1023 return -ENOMEM;
1024 }
1025
1026 mutex_lock(&gb_timesync_svc_list_mutex);
1027 INIT_LIST_HEAD(&timesync_svc->interface_list);
1028 INIT_DELAYED_WORK(&timesync_svc->delayed_work, gb_timesync_worker);
1029 mutex_init(&timesync_svc->mutex);
1030 spin_lock_init(&timesync_svc->spinlock);
1031 init_waitqueue_head(&timesync_svc->wait_queue);
1032
1033 timesync_svc->svc = svc;
1034 timesync_svc->frame_time_offset = 0;
1035 timesync_svc->capture_ping = false;
1036 gb_timesync_set_state_atomic(timesync_svc, GB_TIMESYNC_STATE_INACTIVE);
1037
1038 timesync_svc->frame_time_dentry =
1039 debugfs_create_file("frame-time", S_IRUGO, svc->debugfs_dentry,
1040 timesync_svc,
1041 &gb_timesync_debugfs_frame_time_ops);
1042 timesync_svc->frame_ktime_dentry =
1043 debugfs_create_file("frame-ktime", S_IRUGO, svc->debugfs_dentry,
1044 timesync_svc,
1045 &gb_timesync_debugfs_frame_ktime_ops);
1046
1047 list_add(&timesync_svc->list, &gb_timesync_svc_list);
1048 ret = gb_timesync_hd_add(timesync_svc, svc->hd);
1049 if (ret) {
1050 list_del(&timesync_svc->list);
1051 debugfs_remove(timesync_svc->frame_ktime_dentry);
1052 debugfs_remove(timesync_svc->frame_time_dentry);
1053 destroy_workqueue(timesync_svc->work_queue);
1054 kfree(timesync_svc);
1055 goto done;
1056 }
1057
1058 init_timer(&timesync_svc->ktime_timer);
1059 timesync_svc->ktime_timer.function = gb_timesync_ktime_timer_fn;
1060 timesync_svc->ktime_timer.expires = jiffies + GB_TIMESYNC_KTIME_UPDATE;
1061 timesync_svc->ktime_timer.data = (unsigned long)timesync_svc;
1062 add_timer(&timesync_svc->ktime_timer);
1063done:
1064 mutex_unlock(&gb_timesync_svc_list_mutex);
1065 return ret;
1066}
1067EXPORT_SYMBOL_GPL(gb_timesync_svc_add);
1068
1069void gb_timesync_svc_remove(struct gb_svc *svc)
1070{
1071 struct gb_timesync_svc *timesync_svc;
1072 struct gb_timesync_interface *timesync_interface;
1073 struct gb_timesync_interface *next;
1074
1075 mutex_lock(&gb_timesync_svc_list_mutex);
1076 timesync_svc = gb_timesync_find_timesync_svc(svc->hd);
1077 if (!timesync_svc)
1078 goto done;
1079
1080 cancel_delayed_work_sync(&timesync_svc->delayed_work);
1081
1082 mutex_lock(&timesync_svc->mutex);
1083
1084 gb_timesync_set_state_atomic(timesync_svc, GB_TIMESYNC_STATE_INVALID);
1085 del_timer_sync(&timesync_svc->ktime_timer);
1086 gb_timesync_teardown(timesync_svc);
1087
1088 gb_timesync_hd_remove(timesync_svc, svc->hd);
1089 list_for_each_entry_safe(timesync_interface, next,
1090 &timesync_svc->interface_list, list) {
1091 list_del(&timesync_interface->list);
1092 kfree(timesync_interface);
1093 }
1094 debugfs_remove(timesync_svc->frame_ktime_dentry);
1095 debugfs_remove(timesync_svc->frame_time_dentry);
1096 destroy_workqueue(timesync_svc->work_queue);
1097 list_del(&timesync_svc->list);
1098
1099 mutex_unlock(&timesync_svc->mutex);
1100
1101 kfree(timesync_svc);
1102done:
1103 mutex_unlock(&gb_timesync_svc_list_mutex);
1104}
1105EXPORT_SYMBOL_GPL(gb_timesync_svc_remove);
1106
1107/*
1108 * Add a Greybus Interface to the set of TimeSync Interfaces.
1109 */
1110int gb_timesync_interface_add(struct gb_interface *interface)
1111{
1112 struct gb_timesync_svc *timesync_svc;
1113 struct gb_timesync_interface *timesync_interface;
1114 int ret = 0;
1115
1116 if (!(interface->features & GREYBUS_INTERFACE_FEATURE_TIMESYNC))
1117 return 0;
1118
1119 mutex_lock(&gb_timesync_svc_list_mutex);
1120 timesync_svc = gb_timesync_find_timesync_svc(interface->hd);
1121 if (!timesync_svc) {
1122 ret = -ENODEV;
1123 goto done;
1124 }
1125
1126 timesync_interface = kzalloc(sizeof(*timesync_interface), GFP_KERNEL);
1127 if (!timesync_interface) {
1128 ret = -ENOMEM;
1129 goto done;
1130 }
1131
1132 mutex_lock(&timesync_svc->mutex);
1133 timesync_interface->interface = interface;
1134 list_add(&timesync_interface->list, &timesync_svc->interface_list);
1135 timesync_svc->strobe_mask |= 1 << interface->interface_id;
1136 mutex_unlock(&timesync_svc->mutex);
1137
1138done:
1139 mutex_unlock(&gb_timesync_svc_list_mutex);
1140 return ret;
1141}
1142EXPORT_SYMBOL_GPL(gb_timesync_interface_add);
1143
1144/*
1145 * Remove a Greybus Interface from the set of TimeSync Interfaces.
1146 */
1147void gb_timesync_interface_remove(struct gb_interface *interface)
1148{
1149 struct gb_timesync_svc *timesync_svc;
1150 struct gb_timesync_interface *timesync_interface;
1151
1152 if (!(interface->features & GREYBUS_INTERFACE_FEATURE_TIMESYNC))
1153 return;
1154
1155 mutex_lock(&gb_timesync_svc_list_mutex);
1156 timesync_svc = gb_timesync_find_timesync_svc(interface->hd);
1157 if (!timesync_svc)
1158 goto done;
1159
1160 timesync_interface = gb_timesync_find_timesync_interface(timesync_svc,
1161 interface);
1162 if (!timesync_interface)
1163 goto done;
1164
1165 mutex_lock(&timesync_svc->mutex);
1166 timesync_svc->strobe_mask &= ~(1 << interface->interface_id);
1167 list_del(&timesync_interface->list);
1168 kfree(timesync_interface);
1169 mutex_unlock(&timesync_svc->mutex);
1170done:
1171 mutex_unlock(&gb_timesync_svc_list_mutex);
1172}
1173EXPORT_SYMBOL_GPL(gb_timesync_interface_remove);
1174
1175/*
1176 * Give the authoritative FrameTime to the calling function. Returns zero if we
1177 * are not in GB_TIMESYNC_STATE_ACTIVE.
1178 */
1179static u64 gb_timesync_get_frame_time(struct gb_timesync_svc *timesync_svc)
1180{
1181 unsigned long flags;
1182 u64 ret;
1183
1184 spin_lock_irqsave(&timesync_svc->spinlock, flags);
1185 if (timesync_svc->state == GB_TIMESYNC_STATE_ACTIVE)
1186 ret = __gb_timesync_get_frame_time(timesync_svc);
1187 else
1188 ret = 0;
1189 spin_unlock_irqrestore(&timesync_svc->spinlock, flags);
1190 return ret;
1191}
1192
1193u64 gb_timesync_get_frame_time_by_interface(struct gb_interface *interface)
1194{
1195 struct gb_timesync_svc *timesync_svc;
1196 u64 ret = 0;
1197
1198 mutex_lock(&gb_timesync_svc_list_mutex);
1199 timesync_svc = gb_timesync_find_timesync_svc(interface->hd);
1200 if (!timesync_svc)
1201 goto done;
1202
1203 ret = gb_timesync_get_frame_time(timesync_svc);
1204done:
1205 mutex_unlock(&gb_timesync_svc_list_mutex);
1206 return ret;
1207}
1208EXPORT_SYMBOL_GPL(gb_timesync_get_frame_time_by_interface);
1209
1210u64 gb_timesync_get_frame_time_by_svc(struct gb_svc *svc)
1211{
1212 struct gb_timesync_svc *timesync_svc;
1213 u64 ret = 0;
1214
1215 mutex_lock(&gb_timesync_svc_list_mutex);
1216 timesync_svc = gb_timesync_find_timesync_svc(svc->hd);
1217 if (!timesync_svc)
1218 goto done;
1219
1220 ret = gb_timesync_get_frame_time(timesync_svc);
1221done:
1222 mutex_unlock(&gb_timesync_svc_list_mutex);
1223 return ret;
1224}
1225EXPORT_SYMBOL_GPL(gb_timesync_get_frame_time_by_svc);
1226
1227/* Incrementally updates the conversion base from FrameTime to ktime */
1228static void gb_timesync_ktime_timer_fn(unsigned long data)
1229{
1230 struct gb_timesync_svc *timesync_svc =
1231 (struct gb_timesync_svc *)data;
1232 unsigned long flags;
1233 u64 frame_time;
1234 struct timespec ts;
1235
1236 spin_lock_irqsave(&timesync_svc->spinlock, flags);
1237
1238 if (timesync_svc->state != GB_TIMESYNC_STATE_ACTIVE)
1239 goto done;
1240
1241 ktime_get_ts(&ts);
1242 frame_time = __gb_timesync_get_frame_time(timesync_svc);
1243 gb_timesync_store_ktime(timesync_svc, ts, frame_time);
1244
1245done:
1246 spin_unlock_irqrestore(&timesync_svc->spinlock, flags);
1247 mod_timer(&timesync_svc->ktime_timer,
1248 jiffies + GB_TIMESYNC_KTIME_UPDATE);
1249}
1250
1251int gb_timesync_to_timespec_by_svc(struct gb_svc *svc, u64 frame_time,
1252 struct timespec *ts)
1253{
1254 struct gb_timesync_svc *timesync_svc;
1255 int ret = 0;
1256
1257 mutex_lock(&gb_timesync_svc_list_mutex);
1258 timesync_svc = gb_timesync_find_timesync_svc(svc->hd);
1259 if (!timesync_svc) {
1260 ret = -ENODEV;
1261 goto done;
1262 }
1263 ret = gb_timesync_to_timespec(timesync_svc, frame_time, ts);
1264done:
1265 mutex_unlock(&gb_timesync_svc_list_mutex);
1266 return ret;
1267}
1268EXPORT_SYMBOL_GPL(gb_timesync_to_timespec_by_svc);
1269
1270int gb_timesync_to_timespec_by_interface(struct gb_interface *interface,
1271 u64 frame_time, struct timespec *ts)
1272{
1273 struct gb_timesync_svc *timesync_svc;
1274 int ret = 0;
1275
1276 mutex_lock(&gb_timesync_svc_list_mutex);
1277 timesync_svc = gb_timesync_find_timesync_svc(interface->hd);
1278 if (!timesync_svc) {
1279 ret = -ENODEV;
1280 goto done;
1281 }
1282
1283 ret = gb_timesync_to_timespec(timesync_svc, frame_time, ts);
1284done:
1285 mutex_unlock(&gb_timesync_svc_list_mutex);
1286 return ret;
1287}
1288EXPORT_SYMBOL_GPL(gb_timesync_to_timespec_by_interface);
1289
1290void gb_timesync_irq(struct gb_timesync_svc *timesync_svc)
1291{
1292 unsigned long flags;
1293 u64 strobe_time;
1294 bool strobe_is_ping = true;
1295 struct timespec ts;
1296
1297 ktime_get_ts(&ts);
1298 strobe_time = __gb_timesync_get_frame_time(timesync_svc);
1299
1300 spin_lock_irqsave(&timesync_svc->spinlock, flags);
1301
1302 if (timesync_svc->state == GB_TIMESYNC_STATE_PING) {
1303 if (!timesync_svc->capture_ping)
1304 goto done_nolog;
1305 timesync_svc->ap_ping_frame_time = strobe_time;
1306 goto done_log;
1307 } else if (timesync_svc->state != GB_TIMESYNC_STATE_WAIT_SVC) {
1308 goto done_nolog;
1309 }
1310
1311 timesync_svc->strobe_data[timesync_svc->strobe].frame_time = strobe_time;
1312 timesync_svc->strobe_data[timesync_svc->strobe].ts = ts;
1313
1314 if (++timesync_svc->strobe == GB_TIMESYNC_MAX_STROBES) {
1315 gb_timesync_set_state(timesync_svc,
1316 GB_TIMESYNC_STATE_AUTHORITATIVE);
1317 }
1318 strobe_is_ping = false;
1319done_log:
1320 trace_gb_timesync_irq(strobe_is_ping, timesync_svc->strobe,
1321 GB_TIMESYNC_MAX_STROBES, strobe_time);
1322done_nolog:
1323 spin_unlock_irqrestore(&timesync_svc->spinlock, flags);
1324}
1325EXPORT_SYMBOL(gb_timesync_irq);
1326
1327int __init gb_timesync_init(void)
1328{
1329 int ret = 0;
1330
1331 ret = gb_timesync_platform_init();
1332 if (ret) {
1333 pr_err("timesync platform init fail!\n");
1334 return ret;
1335 }
1336
1337 gb_timesync_clock_rate = gb_timesync_platform_get_clock_rate();
1338
1339 /* Calculate nanoseconds and femtoseconds per clock */
1340 gb_timesync_fs_per_clock = FSEC_PER_SEC;
1341 do_div(gb_timesync_fs_per_clock, gb_timesync_clock_rate);
1342 gb_timesync_ns_per_clock = NSEC_PER_SEC;
1343 do_div(gb_timesync_ns_per_clock, gb_timesync_clock_rate);
1344
1345 /* Calculate the maximum number of clocks we will convert to ktime */
1346 gb_timesync_max_ktime_diff =
1347 GB_TIMESYNC_MAX_KTIME_CONVERSION * gb_timesync_clock_rate;
1348
1349 pr_info("Time-Sync @ %lu Hz max ktime conversion +/- %d seconds\n",
1350 gb_timesync_clock_rate, GB_TIMESYNC_MAX_KTIME_CONVERSION);
1351 return 0;
1352}
1353
1354void gb_timesync_exit(void)
1355{
1356 gb_timesync_platform_exit();
1357}
diff --git a/drivers/staging/greybus/timesync.h b/drivers/staging/greybus/timesync.h
deleted file mode 100644
index 72fc9a35a002..000000000000
--- a/drivers/staging/greybus/timesync.h
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * TimeSync API driver.
3 *
4 * Copyright 2016 Google Inc.
5 * Copyright 2016 Linaro Ltd.
6 *
7 * Released under the GPLv2 only.
8 */
9
10#ifndef __TIMESYNC_H
11#define __TIMESYNC_H
12
13struct gb_svc;
14struct gb_interface;
15struct gb_timesync_svc;
16
17/* Platform */
18u64 gb_timesync_platform_get_counter(void);
19u32 gb_timesync_platform_get_clock_rate(void);
20int gb_timesync_platform_lock_bus(struct gb_timesync_svc *pdata);
21void gb_timesync_platform_unlock_bus(void);
22
23int gb_timesync_platform_init(void);
24void gb_timesync_platform_exit(void);
25
26/* Core API */
27int gb_timesync_interface_add(struct gb_interface *interface);
28void gb_timesync_interface_remove(struct gb_interface *interface);
29int gb_timesync_svc_add(struct gb_svc *svc);
30void gb_timesync_svc_remove(struct gb_svc *svc);
31
32u64 gb_timesync_get_frame_time_by_interface(struct gb_interface *interface);
33u64 gb_timesync_get_frame_time_by_svc(struct gb_svc *svc);
34int gb_timesync_to_timespec_by_svc(struct gb_svc *svc, u64 frame_time,
35 struct timespec *ts);
36int gb_timesync_to_timespec_by_interface(struct gb_interface *interface,
37 u64 frame_time, struct timespec *ts);
38
39int gb_timesync_schedule_synchronous(struct gb_interface *intf);
40void gb_timesync_schedule_asynchronous(struct gb_interface *intf);
41void gb_timesync_irq(struct gb_timesync_svc *timesync_svc);
42int gb_timesync_init(void);
43void gb_timesync_exit(void);
44
45#endif /* __TIMESYNC_H */
diff --git a/drivers/staging/greybus/timesync_platform.c b/drivers/staging/greybus/timesync_platform.c
deleted file mode 100644
index 27f75b17679b..000000000000
--- a/drivers/staging/greybus/timesync_platform.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/*
2 * TimeSync API driver.
3 *
4 * Copyright 2016 Google Inc.
5 * Copyright 2016 Linaro Ltd.
6 *
7 * Released under the GPLv2 only.
8 *
9 * This code reads directly from an ARMv7 memory-mapped timer that lives in
10 * MMIO space. Since this counter lives inside of MMIO space its shared between
11 * cores and that means we don't have to worry about issues like TSC on x86
12 * where each time-stamp-counter (TSC) is local to a particular core.
13 *
14 * Register-level access code is based on
15 * drivers/clocksource/arm_arch_timer.c
16 */
17#include <linux/cpufreq.h>
18#include <linux/of_platform.h>
19
20#include "greybus.h"
21#include "arche_platform.h"
22
23#define DEFAULT_FRAMETIME_CLOCK_HZ 19200000
24
25static u32 gb_timesync_clock_frequency;
26int (*arche_platform_change_state_cb)(enum arche_platform_state state,
27 struct gb_timesync_svc *pdata);
28EXPORT_SYMBOL_GPL(arche_platform_change_state_cb);
29
30u64 gb_timesync_platform_get_counter(void)
31{
32 return (u64)get_cycles();
33}
34
35u32 gb_timesync_platform_get_clock_rate(void)
36{
37 if (unlikely(!gb_timesync_clock_frequency)) {
38 gb_timesync_clock_frequency = cpufreq_get(0);
39 if (!gb_timesync_clock_frequency)
40 gb_timesync_clock_frequency = DEFAULT_FRAMETIME_CLOCK_HZ;
41 }
42
43 return gb_timesync_clock_frequency;
44}
45
46int gb_timesync_platform_lock_bus(struct gb_timesync_svc *pdata)
47{
48 if (!arche_platform_change_state_cb)
49 return 0;
50
51 return arche_platform_change_state_cb(ARCHE_PLATFORM_STATE_TIME_SYNC,
52 pdata);
53}
54
55void gb_timesync_platform_unlock_bus(void)
56{
57 if (!arche_platform_change_state_cb)
58 return;
59
60 arche_platform_change_state_cb(ARCHE_PLATFORM_STATE_ACTIVE, NULL);
61}
62
63static const struct of_device_id arch_timer_of_match[] = {
64 { .compatible = "google,greybus-frame-time-counter", },
65 {},
66};
67
68int __init gb_timesync_platform_init(void)
69{
70 struct device_node *np;
71
72 np = of_find_matching_node(NULL, arch_timer_of_match);
73 if (!np) {
74 /* Tolerate not finding to allow BBB etc to continue */
75 pr_warn("Unable to find a compatible ARMv7 timer\n");
76 return 0;
77 }
78
79 if (of_property_read_u32(np, "clock-frequency",
80 &gb_timesync_clock_frequency)) {
81 pr_err("Unable to find timer clock-frequency\n");
82 return -ENODEV;
83 }
84
85 return 0;
86}
87
88void gb_timesync_platform_exit(void) {}
diff --git a/drivers/staging/greybus/tools/loopback_test.c b/drivers/staging/greybus/tools/loopback_test.c
index f7f4cd6fb55b..18d7a3d1f3c7 100644
--- a/drivers/staging/greybus/tools/loopback_test.c
+++ b/drivers/staging/greybus/tools/loopback_test.c
@@ -168,7 +168,7 @@ GET_AVG(latency_avg);
168GET_AVG(apbridge_unipro_latency_avg); 168GET_AVG(apbridge_unipro_latency_avg);
169GET_AVG(gbphy_firmware_latency_avg); 169GET_AVG(gbphy_firmware_latency_avg);
170 170
171void abort() 171void abort(void)
172{ 172{
173 _exit(1); 173 _exit(1);
174} 174}
@@ -521,7 +521,6 @@ static int log_results(struct loopback_test *t)
521 int fd, i, len, ret; 521 int fd, i, len, ret;
522 struct tm tm; 522 struct tm tm;
523 time_t local_time; 523 time_t local_time;
524 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
525 char file_name[MAX_SYSFS_PATH]; 524 char file_name[MAX_SYSFS_PATH];
526 char data[CSV_MAX_LINE]; 525 char data[CSV_MAX_LINE];
527 526
@@ -538,7 +537,7 @@ static int log_results(struct loopback_test *t)
538 snprintf(file_name, sizeof(file_name), "%s_%d_%d.csv", 537 snprintf(file_name, sizeof(file_name), "%s_%d_%d.csv",
539 t->test_name, t->size, t->iteration_max); 538 t->test_name, t->size, t->iteration_max);
540 539
541 fd = open(file_name, O_WRONLY | O_CREAT | O_APPEND, mode); 540 fd = open(file_name, O_WRONLY | O_CREAT | O_APPEND, 0644);
542 if (fd < 0) { 541 if (fd < 0) {
543 fprintf(stderr, "unable to open %s for appendation\n", file_name); 542 fprintf(stderr, "unable to open %s for appendation\n", file_name);
544 abort(); 543 abort();
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 6d39f4a04754..ab0dbf5cab5a 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -624,14 +624,14 @@ static int get_serial_info(struct gb_tty *gb_tty,
624 struct serial_struct tmp; 624 struct serial_struct tmp;
625 625
626 memset(&tmp, 0, sizeof(tmp)); 626 memset(&tmp, 0, sizeof(tmp));
627 tmp.flags = ASYNC_LOW_LATENCY | ASYNC_SKIP_TEST;
628 tmp.type = PORT_16550A; 627 tmp.type = PORT_16550A;
629 tmp.line = gb_tty->minor; 628 tmp.line = gb_tty->minor;
630 tmp.xmit_fifo_size = 16; 629 tmp.xmit_fifo_size = 16;
631 tmp.baud_base = 9600; 630 tmp.baud_base = 9600;
632 tmp.close_delay = gb_tty->port.close_delay / 10; 631 tmp.close_delay = gb_tty->port.close_delay / 10;
633 tmp.closing_wait = gb_tty->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? 632 tmp.closing_wait =
634 ASYNC_CLOSING_WAIT_NONE : gb_tty->port.closing_wait / 10; 633 gb_tty->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
634 ASYNC_CLOSING_WAIT_NONE : gb_tty->port.closing_wait / 10;
635 635
636 if (copy_to_user(info, &tmp, sizeof(tmp))) 636 if (copy_to_user(info, &tmp, sizeof(tmp)))
637 return -EFAULT; 637 return -EFAULT;
@@ -1000,7 +1000,8 @@ static int gb_tty_init(void)
1000 gb_tty_driver->subtype = SERIAL_TYPE_NORMAL; 1000 gb_tty_driver->subtype = SERIAL_TYPE_NORMAL;
1001 gb_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1001 gb_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1002 gb_tty_driver->init_termios = tty_std_termios; 1002 gb_tty_driver->init_termios = tty_std_termios;
1003 gb_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1003 gb_tty_driver->init_termios.c_cflag = B9600 | CS8 |
1004 CREAD | HUPCL | CLOCAL;
1004 tty_set_operations(gb_tty_driver, &gb_ops); 1005 tty_set_operations(gb_tty_driver, &gb_ops);
1005 1006
1006 retval = tty_register_driver(gb_tty_driver); 1007 retval = tty_register_driver(gb_tty_driver);
diff --git a/drivers/staging/greybus/vibrator.c b/drivers/staging/greybus/vibrator.c
index 4ba0e168930f..77a2365a55e6 100644
--- a/drivers/staging/greybus/vibrator.c
+++ b/drivers/staging/greybus/vibrator.c
@@ -70,7 +70,9 @@ static void gb_vibrator_worker(struct work_struct *work)
70{ 70{
71 struct delayed_work *delayed_work = to_delayed_work(work); 71 struct delayed_work *delayed_work = to_delayed_work(work);
72 struct gb_vibrator_device *vib = 72 struct gb_vibrator_device *vib =
73 container_of(delayed_work, struct gb_vibrator_device, delayed_work); 73 container_of(delayed_work,
74 struct gb_vibrator_device,
75 delayed_work);
74 76
75 turn_off(vib); 77 turn_off(vib);
76} 78}
diff --git a/drivers/staging/i4l/Documentation/README.act2000 b/drivers/staging/i4l/Documentation/README.act2000
deleted file mode 100644
index ce7115e7f4ce..000000000000
--- a/drivers/staging/i4l/Documentation/README.act2000
+++ /dev/null
@@ -1,104 +0,0 @@
1$Id: README.act2000,v 1.3 2000/08/06 09:22:51 armin Exp $
2
3This document describes the ACT2000 driver for the
4IBM Active 2000 ISDN card.
5
6There are 3 Types of this card available. A ISA-, MCA-, and PCMCIA-Bus
7Version. Currently, only the ISA-Bus version of the card is supported.
8However MCA and PCMCIA will follow soon.
9
10The ISA-Bus Version uses 8 IO-ports. The base port address has to be set
11manually using the DIP switches.
12
13Setting up the DIP switches for the IBM Active 2000 ISDN card:
14
15 Note: S5 and S6 always set off!
16
17 S1 S2 S3 S4 Base-port
18 on on on on 0x0200 (Factory default)
19 off on on on 0x0240
20 on off on on 0x0280
21 off off on on 0x02c0
22 on on off on 0x0300
23 off on off on 0x0340
24 on off off on 0x0380
25 on on on off 0xcfe0
26 off on on off 0xcfa0
27 on off on off 0xcf60
28 off off on off 0xcf20
29 on on off off 0xcee0
30 off on off off 0xcea0
31 on off off off 0xce60
32 off off off off Card disabled
33
34IRQ is configured by software. Possible values are:
35
36 3, 5, 7, 10, 11, 12, 15 and none (polled mode)
37
38
39The ACT2000 driver may either be built into the kernel or as a module.
40Initialization depends on how the driver is built:
41
42Driver built into the kernel:
43
44 The ACT2000 driver can be configured using the commandline-feature while
45 loading the kernel with LILO or LOADLIN. It accepts the following syntax:
46
47 act2000=b,p,i[,idstring]
48
49 where
50
51 b = Bus-Type (1=ISA, 2=MCA, 3=PCMCIA)
52 p = portbase (-1 means autoprobe)
53 i = Interrupt (-1 means use next free IRQ, 0 means polled mode)
54
55 The idstring is an arbitrary string used for referencing the card
56 by the actctrl tool later.
57
58 Defaults used, when no parameters given at all:
59
60 1,-1,-1,""
61
62 which means: Autoprobe for an ISA card, use next free IRQ, let the
63 ISDN linklevel fill the IdString (usually "line0" for the first card).
64
65 If you like to use more than one card, you can use the program
66 "actctrl" from the utility-package to configure additional cards.
67
68 Using the "actctrl"-utility, portbase and irq can also be changed
69 during runtime. The D-channel protocol is configured by the "dproto"
70 option of the "actctrl"-utility after loading the firmware into the
71 card's memory using the "actctrl"-utility.
72
73Driver built as module:
74
75 The module act2000.o can be configured during modprobe (insmod) by
76 appending its parameters to the modprobe resp. insmod commandline.
77 The following syntax is accepted:
78
79 act_bus=b act_port=p act_irq=i act_id=idstring
80
81 where b, p, i and idstring have the same meanings as the parameters
82 described for the builtin version above.
83
84 Using the "actctrl"-utility, the same features apply to the modularized
85 version as to the kernel-builtin one. (i.e. loading of firmware and
86 configuring the D-channel protocol)
87
88Loading the firmware into the card:
89
90 The firmware is supplied together with the isdn4k-utils package. It
91 can be found in the subdirectory act2000/firmware/
92
93 Assuming you have installed the utility-package correctly, the firmware
94 will be downloaded into the card using the following command:
95
96 actctrl -d idstring load /etc/isdn/bip11.btl
97
98 where idstring is the Name of the card, given during insmod-time or
99 (for kernel-builtin driver) on the kernel commandline. If only one
100 ISDN card is used, the -d isdstrin may be omitted.
101
102 For further documentation (adding more IBM Active 2000 cards), refer to
103 the manpage actctrl.8 which is included in the isdn4k-utils package.
104
diff --git a/drivers/staging/i4l/Documentation/README.icn b/drivers/staging/i4l/Documentation/README.icn
deleted file mode 100644
index 13f833d4e910..000000000000
--- a/drivers/staging/i4l/Documentation/README.icn
+++ /dev/null
@@ -1,148 +0,0 @@
1$Id: README.icn,v 1.7 2000/08/06 09:22:51 armin Exp $
2
3You can get the ICN-ISDN-card from:
4
5Thinking Objects Software GmbH
6Versbacher Röthe 159
797078 Würzburg
8Tel: +49 931 2877950
9Fax: +49 931 2877951
10
11email info@think.de
12WWW http:/www.think.de
13
14
15The card communicates with the PC by two interfaces:
16 1. A range of 4 successive port-addresses, whose base address can be
17 configured with the switches.
18 2. A memory window with 16KB-256KB size, which can be setup in 16k steps
19 over the whole range of 16MB. Isdn4linux only uses a 16k window.
20 The base address of the window can be configured when loading
21 the lowlevel-module (see README). If using more than one card,
22 all cards are mapped to the same window and activated as needed.
23
24Setting up the IO-address dipswitches for the ICN-ISDN-card:
25
26 Two types of cards exist, one with dip-switches and one with
27 hook-switches.
28
29 1. Setting for the card with hook-switches:
30
31 (0 = switch closed, 1 = switch open)
32
33 S3 S2 S1 Base-address
34 0 0 0 0x300
35 0 0 1 0x310
36 0 1 0 0x320 (Default for isdn4linux)
37 0 1 1 0x330
38 1 0 0 0x340
39 1 0 1 0x350
40 1 1 0 0x360
41 1 1 1 NOT ALLOWED!
42
43 2. Setting for the card with dip-switches:
44
45 (0 = switch closed, 1 = switch open)
46
47 S1 S2 S3 S4 Base-Address
48 0 0 0 0 0x300
49 0 0 0 1 0x310
50 0 0 1 0 0x320 (Default for isdn4linux)
51 0 0 1 1 0x330
52 0 1 0 0 0x340
53 0 1 0 1 0x350
54 0 1 1 0 0x360
55 0 1 1 1 NOT ALLOWED!
56 1 0 0 0 0x308
57 1 0 0 1 0x318
58 1 0 1 0 0x328
59 1 0 1 1 0x338
60 1 1 0 0 0x348
61 1 1 0 1 0x358
62 1 1 1 0 0x368
63 1 1 1 1 NOT ALLOWED!
64
65The ICN driver may be built into the kernel or as a module. Initialization
66depends on how the driver is built:
67
68Driver built into the kernel:
69
70 The ICN driver can be configured using the commandline-feature while
71 loading the kernel with LILO or LOADLIN. It accepts the following syntax:
72
73 icn=p,m[,idstring1[,idstring2]]
74
75 where
76
77 p = portbase (default: 0x320)
78 m = shared memory (default: 0xd0000)
79
80 When using the ICN double card (4B), you MUST define TWO idstrings.
81 idstring must start with a character! There is no way for the driver
82 to distinguish between a 2B and 4B type card. Therefore, by supplying
83 TWO idstrings, you tell the driver that you have a 4B installed.
84
85 If you like to use more than one card, you can use the program
86 "icnctrl" from the utility-package to configure additional cards.
87 You need to configure shared memory only once, since the icn-driver
88 maps all cards into the same address-space.
89
90 Using the "icnctrl"-utility, portbase and shared memory can also be
91 changed during runtime.
92
93 The D-channel protocol is configured by loading different firmware
94 into the card's memory using the "icnctrl"-utility.
95
96
97Driver built as module:
98
99 The module icn.o can be configured during "insmod'ing" it by
100 appending its parameters to the insmod-commandline. The following
101 syntax is accepted:
102
103 portbase=p membase=m icn_id=idstring [icn_id2=idstring2]
104
105 where p, m, idstring1 and idstring2 have the same meanings as the
106 parameters described for the kernel-version above.
107
108 When using the ICN double card (4B), you MUST define TWO idstrings.
109 idstring must start with a character! There is no way for the driver
110 to distinguish between a 2B and 4B type card. Therefore, by supplying
111 TWO idstrings, you tell the driver that you have a 4B installed.
112
113 Using the "icnctrl"-utility, the same features apply to the modularized
114 version like to the kernel-builtin one.
115
116 The D-channel protocol is configured by loading different firmware
117 into the card's memory using the "icnctrl"-utility.
118
119Loading the firmware into the card:
120
121 The firmware is supplied together with the isdn4k-utils package. It
122 can be found in the subdirectory icnctrl/firmware/
123
124 There are 3 files:
125
126 loadpg.bin - Image of the bootstrap loader.
127 pc_1t_ca.bin - Image of firmware for german 1TR6 protocol.
128 pc_eu_ca.bin - Image if firmware for EDSS1 (Euro-ISDN) protocol.
129
130 Assuming you have installed the utility-package correctly, the firmware
131 will be downloaded into the 2B-card using the following command:
132
133 icnctrl -d Idstring load /etc/isdn/loadpg.bin /etc/isdn/pc_XX_ca.bin
134
135 where XX is either "1t" or "eu", depending on the D-Channel protocol
136 used on your S0-bus and Idstring is the Name of the card, given during
137 insmod-time or (for kernel-builtin driver) on the kernel commandline.
138
139 To load a 4B-card, the same command is used, except a second firmware
140 file is appended to the commandline of icnctrl.
141
142 -> After downloading firmware, the two LEDs at the back cover of the card
143 (ICN-4B: 4 LEDs) must be blinking intermittently now. If a connection
144 is up, the corresponding led is lit continuously.
145
146 For further documentation (adding more ICN-cards), refer to the manpage
147 icnctrl.8 which is included in the isdn4k-utils package.
148
diff --git a/drivers/staging/i4l/Documentation/README.pcbit b/drivers/staging/i4l/Documentation/README.pcbit
deleted file mode 100644
index 5125002282e5..000000000000
--- a/drivers/staging/i4l/Documentation/README.pcbit
+++ /dev/null
@@ -1,40 +0,0 @@
1------------------------------------------------------------------------------
2 README file for the PCBIT-D Device Driver.
3------------------------------------------------------------------------------
4
5The PCBIT is a Euro ISDN adapter manufactured in Portugal by Octal and
6developed in cooperation with Portugal Telecom and Inesc.
7The driver interfaces with the standard kernel isdn facilities
8originally developed by Fritz Elfert in the isdn4linux project.
9
10The common versions of the pcbit board require a firmware that is
11distributed (and copyrighted) by the manufacturer. To load this
12firmware you need "pcbitctl" available on the standard isdn4k-utils
13package or in the pcbit package available in:
14
15ftp://ftp.di.fc.ul.pt/pub/systems/Linux/isdn
16
17Known Limitations:
18
19- The board reset procedure is at the moment incorrect and will only
20allow you to load the firmware after a hard reset.
21
22- Only HDLC in B-channels is supported at the moment. There is no
23current support for X.25 in B or D channels nor LAPD in B
24channels. The main reason is that these two other protocol modes have,
25to my knowledge, very little use. If you want to see them implemented
26*do* send me a mail.
27
28- The driver often triggers errors in the board that I and the
29manufacturer believe to be caused by bugs in the firmware. The current
30version includes several procedures for error recovery that should
31allow normal operation. Plans for the future include cooperation with
32the manufacturer in order to solve this problem.
33
34Information/hints/help can be obtained in the linux isdn
35mailing list (isdn4linux@listserv.isdn4linux.de) or directly from me.
36
37regards,
38 Pedro.
39
40<roque@di.fc.ul.pt>
diff --git a/drivers/staging/i4l/Documentation/README.sc b/drivers/staging/i4l/Documentation/README.sc
deleted file mode 100644
index 1153cd926059..000000000000
--- a/drivers/staging/i4l/Documentation/README.sc
+++ /dev/null
@@ -1,281 +0,0 @@
1Welcome to Beta Release 2 of the combination ISDN driver for SpellCaster's
2ISA ISDN adapters. Please note this release 2 includes support for the
3DataCommute/BRI and TeleCommute/BRI adapters only and any other use is
4guaranteed to fail. If you have a DataCommute/PRI installed in the test
5computer, we recommend removing it as it will be detected but will not
6be usable. To see what we have done to Beta Release 2, see section 3.
7
8Speaking of guarantees, THIS IS BETA SOFTWARE and as such contains
9bugs and defects either known or unknown. Use this software at your own
10risk. There is NO SUPPORT for this software. Some help may be available
11through the web site or the mailing list but such support is totally at
12our own option and without warranty. If you choose to assume all and
13total risk by using this driver, we encourage you to join the beta
14mailing list.
15
16To join the Linux beta mailing list, send a message to:
17majordomo@spellcast.com with the words "subscribe linux-beta" as the only
18contents of the message. Do not include a signature. If you choose to
19remove yourself from this list at a later date, send another message to
20the same address with the words "unsubscribe linux-beta" as its only
21contents.
22
23TABLE OF CONTENTS
24-----------------
25 1. Introduction
26 1.1 What is ISDN4Linux?
27 1.2 What is different between this driver and previous drivers?
28 1.3 How do I setup my system with the correct software to use
29 this driver release?
30
31 2. Basic Operations
32 2.1 Unpacking and installing the driver
33 2.2 Read the man pages!!!
34 2.3 Installing the driver
35 2.4 Removing the driver
36 2.5 What to do if it doesn't load
37 2.6 How to setup ISDN4Linux with the driver
38
39 3. Beta Change Summaries and Miscellaneous Notes
40
411. Introduction
42---------------
43
44The revision 2 Linux driver for SpellCaster ISA ISDN adapters is built
45upon ISDN4Linux available separately or as included in Linux 2.0 and later.
46The driver will support a maximum of 4 adapters in any one system of any
47type including DataCommute/BRI, DataCommute/PRI and TeleCommute/BRI for a
48maximum of 92 channels for host. The driver is supplied as a module in
49source form and needs to be complied before it can be used. It has been
50tested on Linux 2.0.20.
51
521.1 What Is ISDN4Linux
53
54ISDN4Linux is a driver and set of tools used to access and use ISDN devices
55on a Linux platform in a common and standard way. It supports HDLC and PPP
56protocols and offers channel bundling and MLPPP support. To use ISDN4Linux
57you need to configure your kernel for ISDN support and get the ISDN4Linux
58tool kit from our web site.
59
60ISDN4Linux creates a channel pool from all of the available ISDN channels
61and therefore can function across adapters. When an ISDN4Linux compliant
62driver (such as ours) is loaded, all of the channels go into a pool and
63are used on a first-come first-served basis. In addition, individual
64channels can be specifically bound to particular interfaces.
65
661.2 What is different between this driver and previous drivers?
67
68The revision 2 driver besides adopting the ISDN4Linux architecture has many
69subtle and not so subtle functional differences from previous releases. These
70include:
71 - More efficient shared memory management combined with a simpler
72 configuration. All adapters now use only 16Kbytes of shared RAM
73 versus between 16K and 64K. New methods for using the shared RAM
74 allow us to utilize all of the available RAM on the adapter through
75 only one 16K page.
76 - Better detection of available upper memory. The probing routines
77 have been improved to better detect available shared RAM pages and
78 used pages are now locked.
79 - Decreased loading time and a wider range of I/O ports probed.
80 We have significantly reduced the amount of time it takes to load
81 the driver and at the same time doubled the number of I/O ports
82 probed increasing the likelihood of finding an adapter.
83 - We now support all ISA adapter models with a single driver instead
84 of separate drivers for each model. The revision 2 driver supports
85 the DataCommute/BRI, DataCommute/PRI and TeleCommute/BRI in any
86 combination up to a maximum of four adapters per system.
87 - On board PPP protocol support has been removed in favour of the
88 sync-PPP support used in ISDN4Linux. This means more control of
89 the protocol parameters, faster negotiation time and a more
90 familiar interface.
91
921.3 How do I setup my system with the correct software to use
93 this driver release?
94
95Before you can compile, install and use the SpellCaster ISA ISDN driver, you
96must ensure that the following software is installed, configured and running:
97
98 - Linux kernel 2.0.20 or later with the required init and ps
99 versions. Please see your distribution vendor for the correct
100 utility packages. The latest kernel is available from
101 ftp://sunsite.unc.edu/pub/Linux/kernel/v2.0/
102
103 - The latest modules package (modules-2.0.0.tar.gz) from
104 ftp://sunsite.unc.edu/pub/Linux/kernel/modules-2.0.0.tar.gz
105
106 - The ISDN4Linux tools available from
107 ftp://ftp.franken.de/pub/isdn4linux/v2.0/isdn4k-utils-2.0.tar.gz
108 This package may fail to compile for you so you can alternatively
109 get a pre-compiled version from
110 ftp://ftp.spellcast.com/pub/drivers/isdn4linux/isdn4k-bin-2.0.tar.gz
111
112
1132. Basic Operations
114-------------------
115
1162.1 Unpacking and installing the driver
117
118 1. As root, create a directory in a convenient place. We suggest
119 /usr/src/spellcaster.
120
121 2. Unpack the archive with :
122 tar xzf sc-n.nn.tar.gz -C /usr/src/spellcaster
123
124 3. Change directory to /usr/src/spellcaster
125
126 4. Read the README and RELNOTES files.
127
128 5. Run 'make' and if all goes well, run 'make install'.
129
1302.2 Read the man pages!!!
131
132Make sure you read the scctrl(8) and sc(4) manual pages before continuing
133any further. Type 'man 8 scctrl' and 'man 4 sc'.
134
1352.3 Installing the driver
136
137To install the driver, type '/sbin/insmod sc' as root. sc(4) details options
138you can specify but you shouldn't need to use any unless this doesn't work.
139
140Make sure the driver loaded and detected all of the adapters by typing
141'dmesg'.
142
143The driver can be configured so that it is loaded upon startup. To do this,
144edit the file "/etc/modules/'uname -f'/'uname -v'" and insert the driver name
145"sc" into this file.
146
1472.4 Removing the driver
148
149To remove the driver, delete any interfaces that may exist (see isdnctrl(8)
150for more on this) and then type '/sbin/rmmod sc'.
151
1522.5 What to do if it doesn't load
153
154If, when you try to install the driver, you get a message mentioning
155'register_isdn' then you do not have the ISDN4Linux system installed. Please
156make sure that ISDN support is configured in the kernel.
157
158If you get a message that says 'initialization of sc failed', then the
159driver failed to detect an adapter or failed to find resources needed such
160as a free IRQ line or shared memory segment. If you are sure there are free
161resources available, use the insmod options detailed in sc(4) to override
162the probing function.
163
164Upon testing, the following problem was noted, the driver would load without
165problems, but the board would not respond beyond that point. When a check was
166done with 'cat /proc/interrupts' the interrupt count for sc was 0. In the event
167of this problem, change the BIOS settings so that the interrupts in question are
168reserved for ISA use only.
169
170
1712.6 How to setup ISDN4Linux with the driver
172
173There are three main configurations which you can use with the driver:
174
175A) Basic HDLC connection
176B) PPP connection
177C) MLPPP connection
178
179It should be mentioned here that you may also use a tty connection if you
180desire. The Documentation directory of the isdn4linux subsystem offers good
181documentation on this feature.
182
183A) 10 steps to the establishment of a basic HDLC connection
184-----------------------------------------------------------
185
186- please open the isdn-hdlc file in the examples directory and follow along...
187
188 This file is a script used to configure a BRI ISDN TA to establish a
189 basic HDLC connection between its two channels. Two network
190 interfaces are created and two routes added between the channels.
191
192 i) using the isdnctrl utility, add an interface with "addif" and
193 name it "isdn0"
194 ii) add the outgoing and inbound telephone numbers
195 iii) set the Layer 2 protocol to hdlc
196 iv) set the eaz of the interface to be the phone number of that
197 specific channel
198 v) to turn the callback features off, set the callback to "off" and
199 the callback delay (cbdelay) to 0.
200 vi) the hangup timeout can be set to a specified number of seconds
201 vii) the hangup upon incoming call can be set on or off
202 viii) use the ifconfig command to bring up the network interface with
203 a specific IP address and point to point address
204 ix) add a route to the IP address through the isdn0 interface
205 x) a ping should result in the establishment of the connection
206
207
208B) Establishment of a PPP connection
209------------------------------------
210
211- please open the isdn-ppp file in the examples directory and follow along...
212
213 This file is a script used to configure a BRI ISDN TA to establish a
214 PPP connection between the two channels. The file is almost
215 identical to the HDLC connection example except that the packet
216 encapsulation type has to be set.
217
218 use the same procedure as in the HDLC connection from steps i) to
219 iii) then, after the Layer 2 protocol is set, set the encapsulation
220 "encap" to syncppp. With this done, the rest of the steps, iv) to x)
221 can be followed from above.
222
223 Then, the ipppd (ippp daemon) must be setup:
224
225 xi) use the ipppd function found in /sbin/ipppd to set the following:
226 xii) take out (minus) VJ compression and bsd compression
227 xiii) set the mru size to 2000
228 xiv) link the two /dev interfaces to the daemon
229
230NOTE: A "*" in the inbound telephone number specifies that a call can be
231accepted on any number.
232
233C) Establishment of a MLPPP connection
234--------------------------------------
235
236- please open the isdn-mppp file in the examples directory and follow along...
237
238 This file is a script used to configure a BRI ISDN TA to accept a
239 Multi Link PPP connection.
240
241 i) using the isdnctrl utility, add an interface with "addif" and
242 name it "ippp0"
243 ii) add the inbound telephone number
244 iii) set the Layer 2 protocol to hdlc and the Layer 3 protocol to
245 trans (transparent)
246 iv) set the packet encapsulation to syncppp
247 v) set the eaz of the interface to be the phone number of that
248 specific channel
249 vi) to turn the callback features off, set the callback to "off" and
250 the callback delay (cbdelay) to 0.
251 vi) the hangup timeout can be set to a specified number of seconds
252 vii) the hangup upon incoming call can be set on or off
253 viii) add a slave interface and name it "ippp32" for example
254 ix) set the similar parameters for the ippp32 interface
255 x) use the ifconfig command to bring-up the ippp0 interface with a
256 specific IP address and point to point address
257 xi) add a route to the IP address through the ippp0 interface
258 xii) use the ipppd function found in /sbin/ipppd to set the following:
259 xiii) take out (minus) bsd compression
260 xiv) set the mru size to 2000
261 xv) add (+) the multi-link function "+mp"
262 xvi) link the two /dev interfaces to the daemon
263
264NOTE: To use the MLPPP connection to dial OUT to a MLPPP connection, change
265the inbound telephone numbers to the outgoing telephone numbers of the MLPPP
266host.
267
268
2693. Beta Change Summaries and Miscellaneous Notes
270------------------------------------------------
271When using the "scctrl" utility to upload firmware revisions on the board,
272please note that the byte count displayed at the end of the operation may be
273different from the total number of bytes in the "dcbfwn.nn.sr" file. Please
274disregard the displayed byte count.
275
276It was noted that in Beta Release 1, the module would fail to load and result
277in a segmentation fault when 'insmod'ed. This problem was created when one of
278the isdn4linux parameters, (isdn_ctrl, data field) was filled in. In some
279cases, this data field was NULL, and was left unchecked, so when it was
280referenced... segv. The bug has been fixed around line 63-68 of event.c.
281
diff --git a/drivers/staging/i4l/Kconfig b/drivers/staging/i4l/Kconfig
deleted file mode 100644
index 920216e88de7..000000000000
--- a/drivers/staging/i4l/Kconfig
+++ /dev/null
@@ -1,13 +0,0 @@
1#
2# Old ISDN4Linux config
3#
4menu "Old ISDN4Linux (deprecated)"
5 depends on ISDN_I4L
6
7source "drivers/staging/i4l/icn/Kconfig"
8
9source "drivers/staging/i4l/pcbit/Kconfig"
10
11source "drivers/staging/i4l/act2000/Kconfig"
12
13endmenu
diff --git a/drivers/staging/i4l/Makefile b/drivers/staging/i4l/Makefile
deleted file mode 100644
index 158b87093db5..000000000000
--- a/drivers/staging/i4l/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1# Makefile for the old ISDN I4L subsystem and device drivers.
2
3obj-$(CONFIG_ISDN_DRV_ICN) += icn/
4obj-$(CONFIG_ISDN_DRV_PCBIT) += pcbit/
5obj-$(CONFIG_ISDN_DRV_ACT2000) += act2000/
diff --git a/drivers/staging/i4l/TODO b/drivers/staging/i4l/TODO
deleted file mode 100644
index 6fe2c08bec7a..000000000000
--- a/drivers/staging/i4l/TODO
+++ /dev/null
@@ -1,3 +0,0 @@
1* The icn, pcbit and act2000 drivers are dead, remove them in 2017
2 after another longterm kernel has been released, just in the
3 unlikely case someone still has this hardware.
diff --git a/drivers/staging/i4l/act2000/Kconfig b/drivers/staging/i4l/act2000/Kconfig
deleted file mode 100644
index fa2673fc69c2..000000000000
--- a/drivers/staging/i4l/act2000/Kconfig
+++ /dev/null
@@ -1,9 +0,0 @@
1config ISDN_DRV_ACT2000
2 tristate "IBM Active 2000 support"
3 depends on ISA
4 help
5 Say Y here if you have an IBM Active 2000 ISDN card. In order to use
6 this card, additional firmware is necessary, which has to be loaded
7 into the card using a utility which is part of the latest
8 isdn4k-utils package. Please read the file
9 <file:Documentation/isdn/README.act2000> for more information.
diff --git a/drivers/staging/i4l/act2000/Makefile b/drivers/staging/i4l/act2000/Makefile
deleted file mode 100644
index 05e582fb5c00..000000000000
--- a/drivers/staging/i4l/act2000/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1# Makefile for the act2000 ISDN device driver
2
3# Each configuration option enables a list of files.
4
5obj-$(CONFIG_ISDN_DRV_ACT2000) += act2000.o
6
7# Multipart objects.
8
9act2000-y := module.o capi.o act2000_isa.o
diff --git a/drivers/staging/i4l/act2000/act2000.h b/drivers/staging/i4l/act2000/act2000.h
deleted file mode 100644
index 321d437f579e..000000000000
--- a/drivers/staging/i4l/act2000/act2000.h
+++ /dev/null
@@ -1,202 +0,0 @@
1/* $Id: act2000.h,v 1.8.6.3 2001/09/23 22:24:32 kai Exp $
2 *
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000.
4 *
5 * Author Fritz Elfert
6 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 * Thanks to Friedemann Baitinger and IBM Germany
12 *
13 */
14
15#ifndef act2000_h
16#define act2000_h
17
18#include <linux/compiler.h>
19
20#define ACT2000_IOCTL_SETPORT 1
21#define ACT2000_IOCTL_GETPORT 2
22#define ACT2000_IOCTL_SETIRQ 3
23#define ACT2000_IOCTL_GETIRQ 4
24#define ACT2000_IOCTL_SETBUS 5
25#define ACT2000_IOCTL_GETBUS 6
26#define ACT2000_IOCTL_SETPROTO 7
27#define ACT2000_IOCTL_GETPROTO 8
28#define ACT2000_IOCTL_SETMSN 9
29#define ACT2000_IOCTL_GETMSN 10
30#define ACT2000_IOCTL_LOADBOOT 11
31#define ACT2000_IOCTL_ADDCARD 12
32
33#define ACT2000_IOCTL_TEST 98
34#define ACT2000_IOCTL_DEBUGVAR 99
35
36#define ACT2000_BUS_ISA 1
37#define ACT2000_BUS_MCA 2
38#define ACT2000_BUS_PCMCIA 3
39
40/* Struct for adding new cards */
41typedef struct act2000_cdef {
42 int bus;
43 int port;
44 int irq;
45 char id[10];
46} act2000_cdef;
47
48/* Struct for downloading firmware */
49typedef struct act2000_ddef {
50 int length; /* Length of code */
51 char __user *buffer; /* Ptr. to code */
52} act2000_ddef;
53
54typedef struct act2000_fwid {
55 char isdn[4];
56 char revlen[2];
57 char revision[504];
58} act2000_fwid;
59
60#if defined(__KERNEL__) || defined(__DEBUGVAR__)
61
62#ifdef __KERNEL__
63/* Kernel includes */
64
65#include <linux/sched.h>
66#include <linux/string.h>
67#include <linux/workqueue.h>
68#include <linux/interrupt.h>
69#include <linux/skbuff.h>
70#include <linux/errno.h>
71#include <linux/fs.h>
72#include <linux/major.h>
73#include <asm/io.h>
74#include <linux/kernel.h>
75#include <linux/signal.h>
76#include <linux/slab.h>
77#include <linux/mm.h>
78#include <linux/mman.h>
79#include <linux/ioport.h>
80#include <linux/timer.h>
81#include <linux/wait.h>
82#include <linux/delay.h>
83#include <linux/ctype.h>
84#include <linux/isdnif.h>
85
86#endif /* __KERNEL__ */
87
88#define ACT2000_PORTLEN 8
89
90#define ACT2000_FLAGS_RUNNING 1 /* Cards driver activated */
91#define ACT2000_FLAGS_PVALID 2 /* Cards port is valid */
92#define ACT2000_FLAGS_IVALID 4 /* Cards irq is valid */
93#define ACT2000_FLAGS_LOADED 8 /* Firmware loaded */
94
95#define ACT2000_BCH 2 /* # of channels per card */
96
97/* D-Channel states */
98#define ACT2000_STATE_NULL 0
99#define ACT2000_STATE_ICALL 1
100#define ACT2000_STATE_OCALL 2
101#define ACT2000_STATE_IWAIT 3
102#define ACT2000_STATE_OWAIT 4
103#define ACT2000_STATE_IBWAIT 5
104#define ACT2000_STATE_OBWAIT 6
105#define ACT2000_STATE_BWAIT 7
106#define ACT2000_STATE_BHWAIT 8
107#define ACT2000_STATE_BHWAIT2 9
108#define ACT2000_STATE_DHWAIT 10
109#define ACT2000_STATE_DHWAIT2 11
110#define ACT2000_STATE_BSETUP 12
111#define ACT2000_STATE_ACTIVE 13
112
113#define ACT2000_MAX_QUEUED 8000 /* 2 * maxbuff */
114
115#define ACT2000_LOCK_TX 0
116#define ACT2000_LOCK_RX 1
117
118typedef struct act2000_chan {
119 unsigned short callref; /* Call Reference */
120 unsigned short fsm_state; /* Current D-Channel state */
121 unsigned short eazmask; /* EAZ-Mask for this Channel */
122 short queued; /* User-Data Bytes in TX queue */
123 unsigned short plci;
124 unsigned short ncci;
125 unsigned char l2prot; /* Layer 2 protocol */
126 unsigned char l3prot; /* Layer 3 protocol */
127} act2000_chan;
128
129typedef struct msn_entry {
130 char eaz;
131 char msn[16];
132 struct msn_entry *next;
133} msn_entry;
134
135typedef struct irq_data_isa {
136 __u8 *rcvptr;
137 __u16 rcvidx;
138 __u16 rcvlen;
139 struct sk_buff *rcvskb;
140 __u8 rcvignore;
141 __u8 rcvhdr[8];
142} irq_data_isa;
143
144typedef union act2000_irq_data {
145 irq_data_isa isa;
146} act2000_irq_data;
147
148/*
149 * Per card driver data
150 */
151typedef struct act2000_card {
152 unsigned short port; /* Base-port-address */
153 unsigned short irq; /* Interrupt */
154 u_char ptype; /* Protocol type (1TR6 or Euro) */
155 u_char bus; /* Cardtype (ISA, MCA, PCMCIA) */
156 struct act2000_card *next; /* Pointer to next device struct */
157 spinlock_t lock; /* protect critical operations */
158 int myid; /* Driver-Nr. assigned by linklevel */
159 unsigned long flags; /* Statusflags */
160 unsigned long ilock; /* Semaphores for IRQ-Routines */
161 struct sk_buff_head rcvq; /* Receive-Message queue */
162 struct sk_buff_head sndq; /* Send-Message queue */
163 struct sk_buff_head ackq; /* Data-Ack-Message queue */
164 u_char *ack_msg; /* Ptr to User Data in User skb */
165 __u16 need_b3ack; /* Flag: Need ACK for current skb */
166 struct sk_buff *sbuf; /* skb which is currently sent */
167 struct timer_list ptimer; /* Poll timer */
168 struct work_struct snd_tq; /* Task struct for xmit bh */
169 struct work_struct rcv_tq; /* Task struct for rcv bh */
170 struct work_struct poll_tq; /* Task struct for polled rcv bh */
171 msn_entry *msn_list;
172 unsigned short msgnum; /* Message number for sending */
173 spinlock_t mnlock; /* lock for msgnum */
174 act2000_chan bch[ACT2000_BCH]; /* B-Channel status/control */
175 char status_buf[256]; /* Buffer for status messages */
176 char *status_buf_read;
177 char *status_buf_write;
178 char *status_buf_end;
179 act2000_irq_data idat; /* Data used for IRQ handler */
180 isdn_if interface; /* Interface to upper layer */
181 char regname[35]; /* Name used for request_region */
182} act2000_card;
183
184static inline void act2000_schedule_tx(act2000_card *card)
185{
186 schedule_work(&card->snd_tq);
187}
188
189static inline void act2000_schedule_rx(act2000_card *card)
190{
191 schedule_work(&card->rcv_tq);
192}
193
194static inline void act2000_schedule_poll(act2000_card *card)
195{
196 schedule_work(&card->poll_tq);
197}
198
199extern char *act2000_find_eaz(act2000_card *, char);
200
201#endif /* defined(__KERNEL__) || defined(__DEBUGVAR__) */
202#endif /* act2000_h */
diff --git a/drivers/staging/i4l/act2000/act2000_isa.c b/drivers/staging/i4l/act2000/act2000_isa.c
deleted file mode 100644
index 76ff5de65781..000000000000
--- a/drivers/staging/i4l/act2000/act2000_isa.c
+++ /dev/null
@@ -1,444 +0,0 @@
1/* $Id: act2000_isa.c,v 1.11.6.3 2001/09/23 22:24:32 kai Exp $
2 *
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000 (ISA-Version).
4 *
5 * Author Fritz Elfert
6 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 * Thanks to Friedemann Baitinger and IBM Germany
12 *
13 */
14
15#include "act2000.h"
16#include "act2000_isa.h"
17#include "capi.h"
18
19/*
20 * Reset Controller, then try to read the Card's signature.
21 + Return:
22 * 1 = Signature found.
23 * 0 = Signature not found.
24 */
25static int
26act2000_isa_reset(unsigned short portbase)
27{
28 unsigned char reg;
29 int i;
30 int found;
31 int serial = 0;
32
33 found = 0;
34 reg = inb(portbase + ISA_COR);
35 if (reg != 0xff) {
36 outb(reg | ISA_COR_RESET, portbase + ISA_COR);
37 mdelay(10);
38 outb(reg, portbase + ISA_COR);
39 mdelay(10);
40
41 for (i = 0; i < 16; i++) {
42 if (inb(portbase + ISA_ISR) & ISA_ISR_SERIAL)
43 serial |= 0x10000;
44 serial >>= 1;
45 }
46 if (serial == ISA_SER_ID)
47 found++;
48 }
49 return found;
50}
51
52int
53act2000_isa_detect(unsigned short portbase)
54{
55 int ret = 0;
56
57 if (request_region(portbase, ACT2000_PORTLEN, "act2000isa")) {
58 ret = act2000_isa_reset(portbase);
59 release_region(portbase, ISA_REGION);
60 }
61 return ret;
62}
63
64static irqreturn_t
65act2000_isa_interrupt(int dummy, void *dev_id)
66{
67 act2000_card *card = dev_id;
68 u_char istatus;
69
70 istatus = (inb(ISA_PORT_ISR) & 0x07);
71 if (istatus & ISA_ISR_OUT) {
72 /* RX fifo has data */
73 istatus &= ISA_ISR_OUT_MASK;
74 outb(0, ISA_PORT_SIS);
75 act2000_isa_receive(card);
76 outb(ISA_SIS_INT, ISA_PORT_SIS);
77 }
78 if (istatus & ISA_ISR_ERR) {
79 /* Error Interrupt */
80 istatus &= ISA_ISR_ERR_MASK;
81 printk(KERN_WARNING "act2000: errIRQ\n");
82 }
83 if (istatus)
84 printk(KERN_DEBUG "act2000: ?IRQ %d %02x\n", card->irq, istatus);
85 return IRQ_HANDLED;
86}
87
88static void
89act2000_isa_select_irq(act2000_card *card)
90{
91 unsigned char reg;
92
93 reg = (inb(ISA_PORT_COR) & ~ISA_COR_IRQOFF) | ISA_COR_PERR;
94 switch (card->irq) {
95 case 3:
96 reg = ISA_COR_IRQ03;
97 break;
98 case 5:
99 reg = ISA_COR_IRQ05;
100 break;
101 case 7:
102 reg = ISA_COR_IRQ07;
103 break;
104 case 10:
105 reg = ISA_COR_IRQ10;
106 break;
107 case 11:
108 reg = ISA_COR_IRQ11;
109 break;
110 case 12:
111 reg = ISA_COR_IRQ12;
112 break;
113 case 15:
114 reg = ISA_COR_IRQ15;
115 break;
116 }
117 outb(reg, ISA_PORT_COR);
118}
119
120static void
121act2000_isa_enable_irq(act2000_card *card)
122{
123 act2000_isa_select_irq(card);
124 /* Enable READ irq */
125 outb(ISA_SIS_INT, ISA_PORT_SIS);
126}
127
128/*
129 * Install interrupt handler, enable irq on card.
130 * If irq is -1, choose next free irq, else irq is given explicitly.
131 */
132int
133act2000_isa_config_irq(act2000_card *card, short irq)
134{
135 int old_irq;
136
137 if (card->flags & ACT2000_FLAGS_IVALID)
138 free_irq(card->irq, card);
139
140 card->flags &= ~ACT2000_FLAGS_IVALID;
141 outb(ISA_COR_IRQOFF, ISA_PORT_COR);
142 if (!irq)
143 return 0;
144
145 old_irq = card->irq;
146 card->irq = irq;
147 if (request_irq(irq, &act2000_isa_interrupt, 0, card->regname, card)) {
148 card->irq = old_irq;
149 card->flags |= ACT2000_FLAGS_IVALID;
150 printk(KERN_WARNING
151 "act2000: Could not request irq %d\n", irq);
152 return -EBUSY;
153 } else {
154 act2000_isa_select_irq(card);
155 /* Disable READ and WRITE irq */
156 outb(0, ISA_PORT_SIS);
157 outb(0, ISA_PORT_SOS);
158 }
159 return 0;
160}
161
162int
163act2000_isa_config_port(act2000_card *card, unsigned short portbase)
164{
165 if (card->flags & ACT2000_FLAGS_PVALID) {
166 release_region(card->port, ISA_REGION);
167 card->flags &= ~ACT2000_FLAGS_PVALID;
168 }
169 if (!request_region(portbase, ACT2000_PORTLEN, card->regname))
170 return -EBUSY;
171 else {
172 card->port = portbase;
173 card->flags |= ACT2000_FLAGS_PVALID;
174 return 0;
175 }
176}
177
178/*
179 * Release resources, used by an adaptor.
180 */
181void
182act2000_isa_release(act2000_card *card)
183{
184 unsigned long flags;
185
186 spin_lock_irqsave(&card->lock, flags);
187 if (card->flags & ACT2000_FLAGS_IVALID)
188 free_irq(card->irq, card);
189
190 card->flags &= ~ACT2000_FLAGS_IVALID;
191 if (card->flags & ACT2000_FLAGS_PVALID)
192 release_region(card->port, ISA_REGION);
193 card->flags &= ~ACT2000_FLAGS_PVALID;
194 spin_unlock_irqrestore(&card->lock, flags);
195}
196
197static int
198act2000_isa_writeb(act2000_card *card, u_char data)
199{
200 u_char timeout = 40;
201
202 while (timeout) {
203 if (inb(ISA_PORT_SOS) & ISA_SOS_READY) {
204 outb(data, ISA_PORT_SDO);
205 return 0;
206 } else {
207 timeout--;
208 udelay(10);
209 }
210 }
211 return 1;
212}
213
214static int
215act2000_isa_readb(act2000_card *card, u_char *data)
216{
217 u_char timeout = 40;
218
219 while (timeout) {
220 if (inb(ISA_PORT_SIS) & ISA_SIS_READY) {
221 *data = inb(ISA_PORT_SDI);
222 return 0;
223 } else {
224 timeout--;
225 udelay(10);
226 }
227 }
228 return 1;
229}
230
231void
232act2000_isa_receive(act2000_card *card)
233{
234 u_char c;
235
236 if (test_and_set_bit(ACT2000_LOCK_RX, (void *)&card->ilock) != 0)
237 return;
238 while (!act2000_isa_readb(card, &c)) {
239 if (card->idat.isa.rcvidx < 8) {
240 card->idat.isa.rcvhdr[card->idat.isa.rcvidx++] = c;
241 if (card->idat.isa.rcvidx == 8) {
242 int valid = actcapi_chkhdr(card, (actcapi_msghdr *)&card->idat.isa.rcvhdr);
243
244 if (valid) {
245 card->idat.isa.rcvlen = ((actcapi_msghdr *)&card->idat.isa.rcvhdr)->len;
246 card->idat.isa.rcvskb = dev_alloc_skb(card->idat.isa.rcvlen);
247 if (!card->idat.isa.rcvskb) {
248 card->idat.isa.rcvignore = 1;
249 printk(KERN_WARNING
250 "act2000_isa_receive: no memory\n");
251 test_and_clear_bit(ACT2000_LOCK_RX, (void *)&card->ilock);
252 return;
253 }
254 memcpy(skb_put(card->idat.isa.rcvskb, 8), card->idat.isa.rcvhdr, 8);
255 card->idat.isa.rcvptr = skb_put(card->idat.isa.rcvskb, card->idat.isa.rcvlen - 8);
256 } else {
257 card->idat.isa.rcvidx = 0;
258 printk(KERN_WARNING
259 "act2000_isa_receive: Invalid CAPI msg\n");
260 {
261 int i; __u8 *p; __u8 *t; __u8 tmp[30];
262
263 for (i = 0, p = (__u8 *)&card->idat.isa.rcvhdr, t = tmp; i < 8; i++)
264 t += sprintf(t, "%02x ", *(p++));
265 printk(KERN_WARNING "act2000_isa_receive: %s\n", tmp);
266 }
267 }
268 }
269 } else {
270 if (!card->idat.isa.rcvignore)
271 *card->idat.isa.rcvptr++ = c;
272 if (++card->idat.isa.rcvidx >= card->idat.isa.rcvlen) {
273 if (!card->idat.isa.rcvignore) {
274 skb_queue_tail(&card->rcvq, card->idat.isa.rcvskb);
275 act2000_schedule_rx(card);
276 }
277 card->idat.isa.rcvidx = 0;
278 card->idat.isa.rcvlen = 8;
279 card->idat.isa.rcvignore = 0;
280 card->idat.isa.rcvskb = NULL;
281 card->idat.isa.rcvptr = card->idat.isa.rcvhdr;
282 }
283 }
284 }
285 if (!(card->flags & ACT2000_FLAGS_IVALID)) {
286 /* In polling mode, schedule myself */
287 if ((card->idat.isa.rcvidx) &&
288 (card->idat.isa.rcvignore ||
289 (card->idat.isa.rcvidx < card->idat.isa.rcvlen)))
290 act2000_schedule_poll(card);
291 }
292 test_and_clear_bit(ACT2000_LOCK_RX, (void *)&card->ilock);
293}
294
295void
296act2000_isa_send(act2000_card *card)
297{
298 unsigned long flags;
299 struct sk_buff *skb;
300 actcapi_msg *msg;
301 int l;
302
303 if (test_and_set_bit(ACT2000_LOCK_TX, (void *)&card->ilock) != 0)
304 return;
305 while (1) {
306 spin_lock_irqsave(&card->lock, flags);
307 if (!(card->sbuf)) {
308 card->sbuf = skb_dequeue(&card->sndq);
309 if (card->sbuf) {
310 card->ack_msg = card->sbuf->data;
311 msg = (actcapi_msg *)card->sbuf->data;
312 if ((msg->hdr.cmd.cmd == 0x86) &&
313 (msg->hdr.cmd.subcmd == 0)) {
314 /* Save flags in message */
315 card->need_b3ack = msg->msg.data_b3_req.flags;
316 msg->msg.data_b3_req.flags = 0;
317 }
318 }
319 }
320 spin_unlock_irqrestore(&card->lock, flags);
321 if (!(card->sbuf)) {
322 /* No more data to send */
323 test_and_clear_bit(ACT2000_LOCK_TX, (void *)&card->ilock);
324 return;
325 }
326 skb = card->sbuf;
327 l = 0;
328 while (skb->len) {
329 if (act2000_isa_writeb(card, *(skb->data))) {
330 /* Fifo is full, but more data to send */
331 test_and_clear_bit(ACT2000_LOCK_TX, (void *)&card->ilock);
332 /* Schedule myself */
333 act2000_schedule_tx(card);
334 return;
335 }
336 skb_pull(skb, 1);
337 l++;
338 }
339 msg = (actcapi_msg *)card->ack_msg;
340 if ((msg->hdr.cmd.cmd == 0x86) &&
341 (msg->hdr.cmd.subcmd == 0)) {
342 /*
343 * If it's user data, reset data-ptr
344 * and put skb into ackq.
345 */
346 skb->data = card->ack_msg;
347 /* Restore flags in message */
348 msg->msg.data_b3_req.flags = card->need_b3ack;
349 skb_queue_tail(&card->ackq, skb);
350 } else
351 dev_kfree_skb(skb);
352 card->sbuf = NULL;
353 }
354}
355
356/*
357 * Get firmware ID, check for 'ISDN' signature.
358 */
359static int
360act2000_isa_getid(act2000_card *card)
361{
362 act2000_fwid fid;
363 u_char *p = (u_char *)&fid;
364 int count = 0;
365
366 while (1) {
367 if (count > 510)
368 return -EPROTO;
369 if (act2000_isa_readb(card, p++))
370 break;
371 count++;
372 }
373 if (count <= 20) {
374 printk(KERN_WARNING "act2000: No Firmware-ID!\n");
375 return -ETIME;
376 }
377 *p = '\0';
378 fid.revlen[0] = '\0';
379 if (strcmp(fid.isdn, "ISDN")) {
380 printk(KERN_WARNING "act2000: Wrong Firmware-ID!\n");
381 return -EPROTO;
382 }
383 p = strchr(fid.revision, '\n');
384 if (p)
385 *p = '\0';
386 printk(KERN_INFO "act2000: Firmware-ID: %s\n", fid.revision);
387 if (card->flags & ACT2000_FLAGS_IVALID) {
388 printk(KERN_DEBUG "Enabling Interrupts ...\n");
389 act2000_isa_enable_irq(card);
390 }
391 return 0;
392}
393
394/*
395 * Download microcode into card, check Firmware signature.
396 */
397int
398act2000_isa_download(act2000_card *card, act2000_ddef __user *cb)
399{
400 unsigned int length;
401 int l;
402 int c;
403 u_char *b;
404 u_char __user *p;
405 u_char *buf;
406 act2000_ddef cblock;
407
408 if (!act2000_isa_reset(card->port))
409 return -ENXIO;
410 msleep_interruptible(500);
411 if (copy_from_user(&cblock, cb, sizeof(cblock)))
412 return -EFAULT;
413 length = cblock.length;
414 p = cblock.buffer;
415 if (!access_ok(VERIFY_READ, p, length))
416 return -EFAULT;
417 buf = kmalloc(1024, GFP_KERNEL);
418 if (!buf)
419 return -ENOMEM;
420 while (length) {
421 l = (length > 1024) ? 1024 : length;
422 c = 0;
423 b = buf;
424 if (copy_from_user(buf, p, l)) {
425 kfree(buf);
426 return -EFAULT;
427 }
428 while (c < l) {
429 if (act2000_isa_writeb(card, *b++)) {
430 printk(KERN_WARNING
431 "act2000: loader timed out"
432 " len=%d c=%d\n", length, c);
433 kfree(buf);
434 return -ETIME;
435 }
436 c++;
437 }
438 length -= l;
439 p += l;
440 }
441 kfree(buf);
442 msleep_interruptible(500);
443 return act2000_isa_getid(card);
444}
diff --git a/drivers/staging/i4l/act2000/act2000_isa.h b/drivers/staging/i4l/act2000/act2000_isa.h
deleted file mode 100644
index 1a728984ede1..000000000000
--- a/drivers/staging/i4l/act2000/act2000_isa.h
+++ /dev/null
@@ -1,136 +0,0 @@
1/* $Id: act2000_isa.h,v 1.4.6.1 2001/09/23 22:24:32 kai Exp $
2 *
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000 (ISA-Version).
4 *
5 * Author Fritz Elfert
6 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 * Thanks to Friedemann Baitinger and IBM Germany
12 *
13 */
14
15#ifndef act2000_isa_h
16#define act2000_isa_h
17
18#define ISA_POLL_LOOP 40 /* Try to read-write before give up */
19
20typedef enum {
21 INT_NO_CHANGE = 0, /* Do not change the Mask */
22 INT_ON = 1, /* Set to Enable */
23 INT_OFF = 2, /* Set to Disable */
24} ISA_INT_T;
25
26/**************************************************************************/
27/* Configuration Register COR (RW) */
28/**************************************************************************/
29/* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 */
30/* Soft Res| IRQM | IRQ Select | N/A | WAIT |Proc err */
31/**************************************************************************/
32#define ISA_COR 0 /* Offset for ISA config register */
33#define ISA_COR_PERR 0x01 /* Processor Error Enabled */
34#define ISA_COR_WS 0x02 /* Insert Wait State if 1 */
35#define ISA_COR_IRQOFF 0x38 /* No Interrupt */
36#define ISA_COR_IRQ07 0x30 /* IRQ 7 Enable */
37#define ISA_COR_IRQ05 0x28 /* IRQ 5 Enable */
38#define ISA_COR_IRQ03 0x20 /* IRQ 3 Enable */
39#define ISA_COR_IRQ10 0x18 /* IRQ 10 Enable */
40#define ISA_COR_IRQ11 0x10 /* IRQ 11 Enable */
41#define ISA_COR_IRQ12 0x08 /* IRQ 12 Enable */
42#define ISA_COR_IRQ15 0x00 /* IRQ 15 Enable */
43#define ISA_COR_IRQPULSE 0x40 /* 0 = Level 1 = Pulse Interrupt */
44#define ISA_COR_RESET 0x80 /* Soft Reset for Transputer */
45
46/**************************************************************************/
47/* Interrupt Source Register ISR (RO) */
48/**************************************************************************/
49/* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 */
50/* N/A | N/A | N/A |Err sig |Ser ID |IN Intr |Out Intr| Error */
51/**************************************************************************/
52#define ISA_ISR 1 /* Offset for Interrupt Register */
53#define ISA_ISR_ERR 0x01 /* Error Interrupt */
54#define ISA_ISR_OUT 0x02 /* Output Interrupt */
55#define ISA_ISR_INP 0x04 /* Input Interrupt */
56#define ISA_ISR_SERIAL 0x08 /* Read out Serial ID after Reset */
57#define ISA_ISR_ERRSIG 0x10 /* Error Signal Input */
58#define ISA_ISR_ERR_MASK 0xfe /* Mask Error Interrupt */
59#define ISA_ISR_OUT_MASK 0xfd /* Mask Output Interrupt */
60#define ISA_ISR_INP_MASK 0xfb /* Mask Input Interrupt */
61
62/* Signature delivered after Reset at ISA_ISR_SERIAL (LSB first) */
63#define ISA_SER_ID 0x0201 /* ID for ISA Card */
64
65/**************************************************************************/
66/* EEPROM Register EPR (RW) */
67/**************************************************************************/
68/* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 */
69/* N/A | N/A | N/A |ROM Hold| ROM CS |ROM CLK | ROM IN |ROM Out */
70/**************************************************************************/
71#define ISA_EPR 2 /* Offset for this Register */
72#define ISA_EPR_OUT 0x01 /* Rome Register Out (RO) */
73#define ISA_EPR_IN 0x02 /* Rom Register In (WR) */
74#define ISA_EPR_CLK 0x04 /* Rom Clock (WR) */
75#define ISA_EPR_CS 0x08 /* Rom Cip Select (WR) */
76#define ISA_EPR_HOLD 0x10 /* Rom Hold Signal (WR) */
77
78/**************************************************************************/
79/* EEPROM enable Register EER (unused) */
80/**************************************************************************/
81#define ISA_EER 3 /* Offset for this Register */
82
83/**************************************************************************/
84/* SLC Data Input SDI (RO) */
85/**************************************************************************/
86#define ISA_SDI 4 /* Offset for this Register */
87
88/**************************************************************************/
89/* SLC Data Output SDO (WO) */
90/**************************************************************************/
91#define ISA_SDO 5 /* Offset for this Register */
92
93/**************************************************************************/
94/* IMS C011 Mode 2 Input Status Register for INMOS CPU SIS (RW) */
95/**************************************************************************/
96/* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 */
97/* N/A | N/A | N/A | N/A | N/A | N/A |Int Ena |Data Pre */
98/**************************************************************************/
99#define ISA_SIS 6 /* Offset for this Register */
100#define ISA_SIS_READY 0x01 /* If 1 : data is available */
101#define ISA_SIS_INT 0x02 /* Enable Interrupt for READ */
102
103/**************************************************************************/
104/* IMS C011 Mode 2 Output Status Register from INMOS CPU SOS (RW) */
105/**************************************************************************/
106/* 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 */
107/* N/A | N/A | N/A | N/A | N/A | N/A |Int Ena |Out Rdy */
108/**************************************************************************/
109#define ISA_SOS 7 /* Offset for this Register */
110#define ISA_SOS_READY 0x01 /* If 1 : we can write Data */
111#define ISA_SOS_INT 0x02 /* Enable Interrupt for WRITE */
112
113#define ISA_REGION 8 /* Number of Registers */
114
115
116/* Macros for accessing ports */
117#define ISA_PORT_COR (card->port + ISA_COR)
118#define ISA_PORT_ISR (card->port + ISA_ISR)
119#define ISA_PORT_EPR (card->port + ISA_EPR)
120#define ISA_PORT_EER (card->port + ISA_EER)
121#define ISA_PORT_SDI (card->port + ISA_SDI)
122#define ISA_PORT_SDO (card->port + ISA_SDO)
123#define ISA_PORT_SIS (card->port + ISA_SIS)
124#define ISA_PORT_SOS (card->port + ISA_SOS)
125
126/* Prototypes */
127
128extern int act2000_isa_detect(unsigned short portbase);
129extern int act2000_isa_config_irq(act2000_card *card, short irq);
130extern int act2000_isa_config_port(act2000_card *card, unsigned short portbase);
131extern int act2000_isa_download(act2000_card *card, act2000_ddef __user *cb);
132extern void act2000_isa_release(act2000_card *card);
133extern void act2000_isa_receive(act2000_card *card);
134extern void act2000_isa_send(act2000_card *card);
135
136#endif /* act2000_isa_h */
diff --git a/drivers/staging/i4l/act2000/capi.c b/drivers/staging/i4l/act2000/capi.c
deleted file mode 100644
index 61386a78fb91..000000000000
--- a/drivers/staging/i4l/act2000/capi.c
+++ /dev/null
@@ -1,1187 +0,0 @@
1/* $Id: capi.c,v 1.9.6.2 2001/09/23 22:24:32 kai Exp $
2 *
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000.
4 * CAPI encoder/decoder
5 *
6 * Author Fritz Elfert
7 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
8 *
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
11 *
12 * Thanks to Friedemann Baitinger and IBM Germany
13 *
14 */
15
16#include "act2000.h"
17#include "capi.h"
18
19static actcapi_msgdsc valid_msg[] = {
20 {{ 0x86, 0x02}, "DATA_B3_IND"}, /* DATA_B3_IND/CONF must be first because of speed!!! */
21 {{ 0x86, 0x01}, "DATA_B3_CONF"},
22 {{ 0x02, 0x01}, "CONNECT_CONF"},
23 {{ 0x02, 0x02}, "CONNECT_IND"},
24 {{ 0x09, 0x01}, "CONNECT_INFO_CONF"},
25 {{ 0x03, 0x02}, "CONNECT_ACTIVE_IND"},
26 {{ 0x04, 0x01}, "DISCONNECT_CONF"},
27 {{ 0x04, 0x02}, "DISCONNECT_IND"},
28 {{ 0x05, 0x01}, "LISTEN_CONF"},
29 {{ 0x06, 0x01}, "GET_PARAMS_CONF"},
30 {{ 0x07, 0x01}, "INFO_CONF"},
31 {{ 0x07, 0x02}, "INFO_IND"},
32 {{ 0x08, 0x01}, "DATA_CONF"},
33 {{ 0x08, 0x02}, "DATA_IND"},
34 {{ 0x40, 0x01}, "SELECT_B2_PROTOCOL_CONF"},
35 {{ 0x80, 0x01}, "SELECT_B3_PROTOCOL_CONF"},
36 {{ 0x81, 0x01}, "LISTEN_B3_CONF"},
37 {{ 0x82, 0x01}, "CONNECT_B3_CONF"},
38 {{ 0x82, 0x02}, "CONNECT_B3_IND"},
39 {{ 0x83, 0x02}, "CONNECT_B3_ACTIVE_IND"},
40 {{ 0x84, 0x01}, "DISCONNECT_B3_CONF"},
41 {{ 0x84, 0x02}, "DISCONNECT_B3_IND"},
42 {{ 0x85, 0x01}, "GET_B3_PARAMS_CONF"},
43 {{ 0x01, 0x01}, "RESET_B3_CONF"},
44 {{ 0x01, 0x02}, "RESET_B3_IND"},
45 /* {{ 0x87, 0x02, "HANDSET_IND"}, not implemented */
46 {{ 0xff, 0x01}, "MANUFACTURER_CONF"},
47 {{ 0xff, 0x02}, "MANUFACTURER_IND"},
48#ifdef DEBUG_MSG
49 /* Requests */
50 {{ 0x01, 0x00}, "RESET_B3_REQ"},
51 {{ 0x02, 0x00}, "CONNECT_REQ"},
52 {{ 0x04, 0x00}, "DISCONNECT_REQ"},
53 {{ 0x05, 0x00}, "LISTEN_REQ"},
54 {{ 0x06, 0x00}, "GET_PARAMS_REQ"},
55 {{ 0x07, 0x00}, "INFO_REQ"},
56 {{ 0x08, 0x00}, "DATA_REQ"},
57 {{ 0x09, 0x00}, "CONNECT_INFO_REQ"},
58 {{ 0x40, 0x00}, "SELECT_B2_PROTOCOL_REQ"},
59 {{ 0x80, 0x00}, "SELECT_B3_PROTOCOL_REQ"},
60 {{ 0x81, 0x00}, "LISTEN_B3_REQ"},
61 {{ 0x82, 0x00}, "CONNECT_B3_REQ"},
62 {{ 0x84, 0x00}, "DISCONNECT_B3_REQ"},
63 {{ 0x85, 0x00}, "GET_B3_PARAMS_REQ"},
64 {{ 0x86, 0x00}, "DATA_B3_REQ"},
65 {{ 0xff, 0x00}, "MANUFACTURER_REQ"},
66 /* Responses */
67 {{ 0x01, 0x03}, "RESET_B3_RESP"},
68 {{ 0x02, 0x03}, "CONNECT_RESP"},
69 {{ 0x03, 0x03}, "CONNECT_ACTIVE_RESP"},
70 {{ 0x04, 0x03}, "DISCONNECT_RESP"},
71 {{ 0x07, 0x03}, "INFO_RESP"},
72 {{ 0x08, 0x03}, "DATA_RESP"},
73 {{ 0x82, 0x03}, "CONNECT_B3_RESP"},
74 {{ 0x83, 0x03}, "CONNECT_B3_ACTIVE_RESP"},
75 {{ 0x84, 0x03}, "DISCONNECT_B3_RESP"},
76 {{ 0x86, 0x03}, "DATA_B3_RESP"},
77 {{ 0xff, 0x03}, "MANUFACTURER_RESP"},
78#endif
79 {{ 0x00, 0x00}, NULL},
80};
81#define num_valid_imsg 27 /* MANUFACTURER_IND */
82
83/*
84 * Check for a valid incoming CAPI message.
85 * Return:
86 * 0 = Invalid message
87 * 1 = Valid message, no B-Channel-data
88 * 2 = Valid message, B-Channel-data
89 */
90int
91actcapi_chkhdr(act2000_card *card, actcapi_msghdr *hdr)
92{
93 int i;
94
95 if (hdr->applicationID != 1)
96 return 0;
97 if (hdr->len < 9)
98 return 0;
99 for (i = 0; i < num_valid_imsg; i++)
100 if ((hdr->cmd.cmd == valid_msg[i].cmd.cmd) &&
101 (hdr->cmd.subcmd == valid_msg[i].cmd.subcmd)) {
102 return i ? 1 : 2;
103 }
104 return 0;
105}
106
107#define ACTCAPI_MKHDR(l, c, s) { \
108 skb = alloc_skb(l + 8, GFP_ATOMIC); \
109 if (skb) { \
110 m = (actcapi_msg *)skb_put(skb, l + 8); \
111 m->hdr.len = l + 8; \
112 m->hdr.applicationID = 1; \
113 m->hdr.cmd.cmd = c; \
114 m->hdr.cmd.subcmd = s; \
115 m->hdr.msgnum = actcapi_nextsmsg(card); \
116 } else { \
117 m = NULL; \
118 } \
119 }
120
121#define ACTCAPI_CHKSKB if (!skb) { \
122 printk(KERN_WARNING "actcapi: alloc_skb failed\n"); \
123 return; \
124 }
125
126#define ACTCAPI_QUEUE_TX { \
127 actcapi_debug_msg(skb, 1); \
128 skb_queue_tail(&card->sndq, skb); \
129 act2000_schedule_tx(card); \
130 }
131
132int
133actcapi_listen_req(act2000_card *card)
134{
135 __u16 eazmask = 0;
136 int i;
137 actcapi_msg *m;
138 struct sk_buff *skb;
139
140 for (i = 0; i < ACT2000_BCH; i++)
141 eazmask |= card->bch[i].eazmask;
142 ACTCAPI_MKHDR(9, 0x05, 0x00);
143 if (!skb) {
144 printk(KERN_WARNING "actcapi: alloc_skb failed\n");
145 return -ENOMEM;
146 }
147 m->msg.listen_req.controller = 0;
148 m->msg.listen_req.infomask = 0x3f; /* All information */
149 m->msg.listen_req.eazmask = eazmask;
150 m->msg.listen_req.simask = (eazmask) ? 0x86 : 0; /* All SI's */
151 ACTCAPI_QUEUE_TX;
152 return 0;
153}
154
155int
156actcapi_connect_req(act2000_card *card, act2000_chan *chan, char *phone,
157 char eaz, int si1, int si2)
158{
159 actcapi_msg *m;
160 struct sk_buff *skb;
161
162 ACTCAPI_MKHDR((11 + strlen(phone)), 0x02, 0x00);
163 if (!skb) {
164 printk(KERN_WARNING "actcapi: alloc_skb failed\n");
165 chan->fsm_state = ACT2000_STATE_NULL;
166 return -ENOMEM;
167 }
168 m->msg.connect_req.controller = 0;
169 m->msg.connect_req.bchan = 0x83;
170 m->msg.connect_req.infomask = 0x3f;
171 m->msg.connect_req.si1 = si1;
172 m->msg.connect_req.si2 = si2;
173 m->msg.connect_req.eaz = eaz ? eaz : '0';
174 m->msg.connect_req.addr.len = strlen(phone) + 1;
175 m->msg.connect_req.addr.tnp = 0x81;
176 memcpy(m->msg.connect_req.addr.num, phone, strlen(phone));
177 chan->callref = m->hdr.msgnum;
178 ACTCAPI_QUEUE_TX;
179 return 0;
180}
181
182static void
183actcapi_connect_b3_req(act2000_card *card, act2000_chan *chan)
184{
185 actcapi_msg *m;
186 struct sk_buff *skb;
187
188 ACTCAPI_MKHDR(17, 0x82, 0x00);
189 ACTCAPI_CHKSKB;
190 m->msg.connect_b3_req.plci = chan->plci;
191 memset(&m->msg.connect_b3_req.ncpi, 0,
192 sizeof(m->msg.connect_b3_req.ncpi));
193 m->msg.connect_b3_req.ncpi.len = 13;
194 m->msg.connect_b3_req.ncpi.modulo = 8;
195 ACTCAPI_QUEUE_TX;
196}
197
198/*
199 * Set net type (1TR6) or (EDSS1)
200 */
201int
202actcapi_manufacturer_req_net(act2000_card *card)
203{
204 actcapi_msg *m;
205 struct sk_buff *skb;
206
207 ACTCAPI_MKHDR(5, 0xff, 0x00);
208 if (!skb) {
209 printk(KERN_WARNING "actcapi: alloc_skb failed\n");
210 return -ENOMEM;
211 }
212 m->msg.manufacturer_req_net.manuf_msg = 0x11;
213 m->msg.manufacturer_req_net.controller = 1;
214 m->msg.manufacturer_req_net.nettype = (card->ptype == ISDN_PTYPE_EURO) ? 1 : 0;
215 ACTCAPI_QUEUE_TX;
216 printk(KERN_INFO "act2000 %s: D-channel protocol now %s\n",
217 card->interface.id, (card->ptype == ISDN_PTYPE_EURO) ? "euro" : "1tr6");
218 card->interface.features &=
219 ~(ISDN_FEATURE_P_UNKNOWN | ISDN_FEATURE_P_EURO | ISDN_FEATURE_P_1TR6);
220 card->interface.features |=
221 ((card->ptype == ISDN_PTYPE_EURO) ? ISDN_FEATURE_P_EURO : ISDN_FEATURE_P_1TR6);
222 return 0;
223}
224
225/*
226 * Switch V.42 on or off
227 */
228#if 0
229int
230actcapi_manufacturer_req_v42(act2000_card *card, ulong arg)
231{
232 actcapi_msg *m;
233 struct sk_buff *skb;
234
235 ACTCAPI_MKHDR(8, 0xff, 0x00);
236 if (!skb) {
237
238 printk(KERN_WARNING "actcapi: alloc_skb failed\n");
239 return -ENOMEM;
240 }
241 m->msg.manufacturer_req_v42.manuf_msg = 0x10;
242 m->msg.manufacturer_req_v42.controller = 0;
243 m->msg.manufacturer_req_v42.v42control = (arg ? 1 : 0);
244 ACTCAPI_QUEUE_TX;
245 return 0;
246}
247#endif /* 0 */
248
249/*
250 * Set error-handler
251 */
252int
253actcapi_manufacturer_req_errh(act2000_card *card)
254{
255 actcapi_msg *m;
256 struct sk_buff *skb;
257
258 ACTCAPI_MKHDR(4, 0xff, 0x00);
259 if (!skb) {
260
261 printk(KERN_WARNING "actcapi: alloc_skb failed\n");
262 return -ENOMEM;
263 }
264 m->msg.manufacturer_req_err.manuf_msg = 0x03;
265 m->msg.manufacturer_req_err.controller = 0;
266 ACTCAPI_QUEUE_TX;
267 return 0;
268}
269
270/*
271 * Set MSN-Mapping.
272 */
273int
274actcapi_manufacturer_req_msn(act2000_card *card)
275{
276 msn_entry *p = card->msn_list;
277 actcapi_msg *m;
278 struct sk_buff *skb;
279 int len;
280
281 while (p) {
282 int i;
283
284 len = strlen(p->msn);
285 for (i = 0; i < 2; i++) {
286 ACTCAPI_MKHDR(6 + len, 0xff, 0x00);
287 if (!skb) {
288 printk(KERN_WARNING "actcapi: alloc_skb failed\n");
289 return -ENOMEM;
290 }
291 m->msg.manufacturer_req_msn.manuf_msg = 0x13 + i;
292 m->msg.manufacturer_req_msn.controller = 0;
293 m->msg.manufacturer_req_msn.msnmap.eaz = p->eaz;
294 m->msg.manufacturer_req_msn.msnmap.len = len;
295 memcpy(m->msg.manufacturer_req_msn.msnmap.msn, p->msn, len);
296 ACTCAPI_QUEUE_TX;
297 }
298 p = p->next;
299 }
300 return 0;
301}
302
303void
304actcapi_select_b2_protocol_req(act2000_card *card, act2000_chan *chan)
305{
306 actcapi_msg *m;
307 struct sk_buff *skb;
308
309 ACTCAPI_MKHDR(10, 0x40, 0x00);
310 ACTCAPI_CHKSKB;
311 m->msg.select_b2_protocol_req.plci = chan->plci;
312 memset(&m->msg.select_b2_protocol_req.dlpd, 0,
313 sizeof(m->msg.select_b2_protocol_req.dlpd));
314 m->msg.select_b2_protocol_req.dlpd.len = 6;
315 switch (chan->l2prot) {
316 case ISDN_PROTO_L2_TRANS:
317 m->msg.select_b2_protocol_req.protocol = 0x03;
318 m->msg.select_b2_protocol_req.dlpd.dlen = 4000;
319 break;
320 case ISDN_PROTO_L2_HDLC:
321 m->msg.select_b2_protocol_req.protocol = 0x02;
322 m->msg.select_b2_protocol_req.dlpd.dlen = 4000;
323 break;
324 case ISDN_PROTO_L2_X75I:
325 case ISDN_PROTO_L2_X75UI:
326 case ISDN_PROTO_L2_X75BUI:
327 m->msg.select_b2_protocol_req.protocol = 0x01;
328 m->msg.select_b2_protocol_req.dlpd.dlen = 4000;
329 m->msg.select_b2_protocol_req.dlpd.laa = 3;
330 m->msg.select_b2_protocol_req.dlpd.lab = 1;
331 m->msg.select_b2_protocol_req.dlpd.win = 7;
332 m->msg.select_b2_protocol_req.dlpd.modulo = 8;
333 break;
334 }
335 ACTCAPI_QUEUE_TX;
336}
337
338static void
339actcapi_select_b3_protocol_req(act2000_card *card, act2000_chan *chan)
340{
341 actcapi_msg *m;
342 struct sk_buff *skb;
343
344 ACTCAPI_MKHDR(17, 0x80, 0x00);
345 ACTCAPI_CHKSKB;
346 m->msg.select_b3_protocol_req.plci = chan->plci;
347 memset(&m->msg.select_b3_protocol_req.ncpd, 0,
348 sizeof(m->msg.select_b3_protocol_req.ncpd));
349 switch (chan->l3prot) {
350 case ISDN_PROTO_L3_TRANS:
351 m->msg.select_b3_protocol_req.protocol = 0x04;
352 m->msg.select_b3_protocol_req.ncpd.len = 13;
353 m->msg.select_b3_protocol_req.ncpd.modulo = 8;
354 break;
355 }
356 ACTCAPI_QUEUE_TX;
357}
358
359static void
360actcapi_listen_b3_req(act2000_card *card, act2000_chan *chan)
361{
362 actcapi_msg *m;
363 struct sk_buff *skb;
364
365 ACTCAPI_MKHDR(2, 0x81, 0x00);
366 ACTCAPI_CHKSKB;
367 m->msg.listen_b3_req.plci = chan->plci;
368 ACTCAPI_QUEUE_TX;
369}
370
371static void
372actcapi_disconnect_req(act2000_card *card, act2000_chan *chan)
373{
374 actcapi_msg *m;
375 struct sk_buff *skb;
376
377 ACTCAPI_MKHDR(3, 0x04, 0x00);
378 ACTCAPI_CHKSKB;
379 m->msg.disconnect_req.plci = chan->plci;
380 m->msg.disconnect_req.cause = 0;
381 ACTCAPI_QUEUE_TX;
382}
383
384void
385actcapi_disconnect_b3_req(act2000_card *card, act2000_chan *chan)
386{
387 actcapi_msg *m;
388 struct sk_buff *skb;
389
390 ACTCAPI_MKHDR(17, 0x84, 0x00);
391 ACTCAPI_CHKSKB;
392 m->msg.disconnect_b3_req.ncci = chan->ncci;
393 memset(&m->msg.disconnect_b3_req.ncpi, 0,
394 sizeof(m->msg.disconnect_b3_req.ncpi));
395 m->msg.disconnect_b3_req.ncpi.len = 13;
396 m->msg.disconnect_b3_req.ncpi.modulo = 8;
397 chan->fsm_state = ACT2000_STATE_BHWAIT;
398 ACTCAPI_QUEUE_TX;
399}
400
401void
402actcapi_connect_resp(act2000_card *card, act2000_chan *chan, __u8 cause)
403{
404 actcapi_msg *m;
405 struct sk_buff *skb;
406
407 ACTCAPI_MKHDR(3, 0x02, 0x03);
408 ACTCAPI_CHKSKB;
409 m->msg.connect_resp.plci = chan->plci;
410 m->msg.connect_resp.rejectcause = cause;
411 if (cause) {
412 chan->fsm_state = ACT2000_STATE_NULL;
413 chan->plci = 0x8000;
414 } else
415 chan->fsm_state = ACT2000_STATE_IWAIT;
416 ACTCAPI_QUEUE_TX;
417}
418
419static void
420actcapi_connect_active_resp(act2000_card *card, act2000_chan *chan)
421{
422 actcapi_msg *m;
423 struct sk_buff *skb;
424
425 ACTCAPI_MKHDR(2, 0x03, 0x03);
426 ACTCAPI_CHKSKB;
427 m->msg.connect_resp.plci = chan->plci;
428 if (chan->fsm_state == ACT2000_STATE_IWAIT)
429 chan->fsm_state = ACT2000_STATE_IBWAIT;
430 ACTCAPI_QUEUE_TX;
431}
432
433static void
434actcapi_connect_b3_resp(act2000_card *card, act2000_chan *chan, __u8 rejectcause)
435{
436 actcapi_msg *m;
437 struct sk_buff *skb;
438
439 ACTCAPI_MKHDR((rejectcause ? 3 : 17), 0x82, 0x03);
440 ACTCAPI_CHKSKB;
441 m->msg.connect_b3_resp.ncci = chan->ncci;
442 m->msg.connect_b3_resp.rejectcause = rejectcause;
443 if (!rejectcause) {
444 memset(&m->msg.connect_b3_resp.ncpi, 0,
445 sizeof(m->msg.connect_b3_resp.ncpi));
446 m->msg.connect_b3_resp.ncpi.len = 13;
447 m->msg.connect_b3_resp.ncpi.modulo = 8;
448 chan->fsm_state = ACT2000_STATE_BWAIT;
449 }
450 ACTCAPI_QUEUE_TX;
451}
452
453static void
454actcapi_connect_b3_active_resp(act2000_card *card, act2000_chan *chan)
455{
456 actcapi_msg *m;
457 struct sk_buff *skb;
458
459 ACTCAPI_MKHDR(2, 0x83, 0x03);
460 ACTCAPI_CHKSKB;
461 m->msg.connect_b3_active_resp.ncci = chan->ncci;
462 chan->fsm_state = ACT2000_STATE_ACTIVE;
463 ACTCAPI_QUEUE_TX;
464}
465
466static void
467actcapi_info_resp(act2000_card *card, act2000_chan *chan)
468{
469 actcapi_msg *m;
470 struct sk_buff *skb;
471
472 ACTCAPI_MKHDR(2, 0x07, 0x03);
473 ACTCAPI_CHKSKB;
474 m->msg.info_resp.plci = chan->plci;
475 ACTCAPI_QUEUE_TX;
476}
477
478static void
479actcapi_disconnect_b3_resp(act2000_card *card, act2000_chan *chan)
480{
481 actcapi_msg *m;
482 struct sk_buff *skb;
483
484 ACTCAPI_MKHDR(2, 0x84, 0x03);
485 ACTCAPI_CHKSKB;
486 m->msg.disconnect_b3_resp.ncci = chan->ncci;
487 chan->ncci = 0x8000;
488 chan->queued = 0;
489 ACTCAPI_QUEUE_TX;
490}
491
492static void
493actcapi_disconnect_resp(act2000_card *card, act2000_chan *chan)
494{
495 actcapi_msg *m;
496 struct sk_buff *skb;
497
498 ACTCAPI_MKHDR(2, 0x04, 0x03);
499 ACTCAPI_CHKSKB;
500 m->msg.disconnect_resp.plci = chan->plci;
501 chan->plci = 0x8000;
502 ACTCAPI_QUEUE_TX;
503}
504
505static int
506new_plci(act2000_card *card, __u16 plci)
507{
508 int i;
509
510 for (i = 0; i < ACT2000_BCH; i++)
511 if (card->bch[i].plci == 0x8000) {
512 card->bch[i].plci = plci;
513 return i;
514 }
515 return -1;
516}
517
518static int
519find_plci(act2000_card *card, __u16 plci)
520{
521 int i;
522
523 for (i = 0; i < ACT2000_BCH; i++)
524 if (card->bch[i].plci == plci)
525 return i;
526 return -1;
527}
528
529static int
530find_ncci(act2000_card *card, __u16 ncci)
531{
532 int i;
533
534 for (i = 0; i < ACT2000_BCH; i++)
535 if (card->bch[i].ncci == ncci)
536 return i;
537 return -1;
538}
539
540static int
541find_dialing(act2000_card *card, __u16 callref)
542{
543 int i;
544
545 for (i = 0; i < ACT2000_BCH; i++)
546 if ((card->bch[i].callref == callref) &&
547 (card->bch[i].fsm_state == ACT2000_STATE_OCALL))
548 return i;
549 return -1;
550}
551
552static int
553actcapi_data_b3_ind(act2000_card *card, struct sk_buff *skb) {
554 __u16 plci;
555 __u16 ncci;
556 __u8 blocknr;
557 int chan;
558 actcapi_msg *msg = (actcapi_msg *)skb->data;
559
560 EVAL_NCCI(msg->msg.data_b3_ind.fakencci, plci, ncci);
561 chan = find_ncci(card, ncci);
562 if (chan < 0)
563 return 0;
564 if (card->bch[chan].fsm_state != ACT2000_STATE_ACTIVE)
565 return 0;
566 if (card->bch[chan].plci != plci)
567 return 0;
568 blocknr = msg->msg.data_b3_ind.blocknr;
569 skb_pull(skb, 19);
570 card->interface.rcvcallb_skb(card->myid, chan, skb);
571 if (!(skb = alloc_skb(11, GFP_ATOMIC))) {
572 printk(KERN_WARNING "actcapi: alloc_skb failed\n");
573 return 1;
574 }
575 msg = (actcapi_msg *)skb_put(skb, 11);
576 msg->hdr.len = 11;
577 msg->hdr.applicationID = 1;
578 msg->hdr.cmd.cmd = 0x86;
579 msg->hdr.cmd.subcmd = 0x03;
580 msg->hdr.msgnum = actcapi_nextsmsg(card);
581 msg->msg.data_b3_resp.ncci = ncci;
582 msg->msg.data_b3_resp.blocknr = blocknr;
583 ACTCAPI_QUEUE_TX;
584 return 1;
585}
586
587/*
588 * Walk over ackq, unlink DATA_B3_REQ from it, if
589 * ncci and blocknr are matching.
590 * Decrement queued-bytes counter.
591 */
592static int
593handle_ack(act2000_card *card, act2000_chan *chan, __u8 blocknr) {
594 unsigned long flags;
595 struct sk_buff *skb;
596 struct sk_buff *tmp;
597 struct actcapi_msg *m;
598 int ret = 0;
599
600 spin_lock_irqsave(&card->lock, flags);
601 skb = skb_peek(&card->ackq);
602 spin_unlock_irqrestore(&card->lock, flags);
603 if (!skb) {
604 printk(KERN_WARNING "act2000: handle_ack nothing found!\n");
605 return 0;
606 }
607 tmp = skb;
608 while (1) {
609 m = (actcapi_msg *)tmp->data;
610 if ((((m->msg.data_b3_req.fakencci >> 8) & 0xff) == chan->ncci) &&
611 (m->msg.data_b3_req.blocknr == blocknr)) {
612 /* found corresponding DATA_B3_REQ */
613 skb_unlink(tmp, &card->ackq);
614 chan->queued -= m->msg.data_b3_req.datalen;
615 if (m->msg.data_b3_req.flags)
616 ret = m->msg.data_b3_req.datalen;
617 dev_kfree_skb(tmp);
618 if (chan->queued < 0)
619 chan->queued = 0;
620 return ret;
621 }
622 spin_lock_irqsave(&card->lock, flags);
623 tmp = skb_peek((struct sk_buff_head *)tmp);
624 spin_unlock_irqrestore(&card->lock, flags);
625 if ((tmp == skb) || !tmp) {
626 /* reached end of queue */
627 printk(KERN_WARNING "act2000: handle_ack nothing found!\n");
628 return 0;
629 }
630 }
631}
632
633void
634actcapi_dispatch(struct work_struct *work)
635{
636 struct act2000_card *card =
637 container_of(work, struct act2000_card, rcv_tq);
638 struct sk_buff *skb;
639 actcapi_msg *msg;
640 __u16 ccmd;
641 int chan;
642 int len;
643 act2000_chan *ctmp;
644 isdn_ctrl cmd;
645 char tmp[170];
646
647 while ((skb = skb_dequeue(&card->rcvq))) {
648 actcapi_debug_msg(skb, 0);
649 msg = (actcapi_msg *)skb->data;
650 ccmd = ((msg->hdr.cmd.cmd << 8) | msg->hdr.cmd.subcmd);
651 switch (ccmd) {
652 case 0x8602:
653 /* DATA_B3_IND */
654 if (actcapi_data_b3_ind(card, skb))
655 return;
656 break;
657 case 0x8601:
658 /* DATA_B3_CONF */
659 chan = find_ncci(card, msg->msg.data_b3_conf.ncci);
660 if ((chan >= 0) && (card->bch[chan].fsm_state == ACT2000_STATE_ACTIVE)) {
661 if (msg->msg.data_b3_conf.info != 0)
662 printk(KERN_WARNING "act2000: DATA_B3_CONF: %04x\n",
663 msg->msg.data_b3_conf.info);
664 len = handle_ack(card, &card->bch[chan],
665 msg->msg.data_b3_conf.blocknr);
666 if (len) {
667 cmd.driver = card->myid;
668 cmd.command = ISDN_STAT_BSENT;
669 cmd.arg = chan;
670 cmd.parm.length = len;
671 card->interface.statcallb(&cmd);
672 }
673 }
674 break;
675 case 0x0201:
676 /* CONNECT_CONF */
677 chan = find_dialing(card, msg->hdr.msgnum);
678 if (chan >= 0) {
679 if (msg->msg.connect_conf.info) {
680 card->bch[chan].fsm_state = ACT2000_STATE_NULL;
681 cmd.driver = card->myid;
682 cmd.command = ISDN_STAT_DHUP;
683 cmd.arg = chan;
684 card->interface.statcallb(&cmd);
685 } else {
686 card->bch[chan].fsm_state = ACT2000_STATE_OWAIT;
687 card->bch[chan].plci = msg->msg.connect_conf.plci;
688 }
689 }
690 break;
691 case 0x0202:
692 /* CONNECT_IND */
693 chan = new_plci(card, msg->msg.connect_ind.plci);
694 if (chan < 0) {
695 ctmp = (act2000_chan *)tmp;
696 ctmp->plci = msg->msg.connect_ind.plci;
697 actcapi_connect_resp(card, ctmp, 0x11); /* All Card-Cannels busy */
698 } else {
699 card->bch[chan].fsm_state = ACT2000_STATE_ICALL;
700 cmd.driver = card->myid;
701 cmd.command = ISDN_STAT_ICALL;
702 cmd.arg = chan;
703 cmd.parm.setup.si1 = msg->msg.connect_ind.si1;
704 cmd.parm.setup.si2 = msg->msg.connect_ind.si2;
705 if (card->ptype == ISDN_PTYPE_EURO)
706 strcpy(cmd.parm.setup.eazmsn,
707 act2000_find_eaz(card, msg->msg.connect_ind.eaz));
708 else {
709 cmd.parm.setup.eazmsn[0] = msg->msg.connect_ind.eaz;
710 cmd.parm.setup.eazmsn[1] = 0;
711 }
712 memset(cmd.parm.setup.phone, 0, sizeof(cmd.parm.setup.phone));
713 memcpy(cmd.parm.setup.phone, msg->msg.connect_ind.addr.num,
714 msg->msg.connect_ind.addr.len - 1);
715 cmd.parm.setup.plan = msg->msg.connect_ind.addr.tnp;
716 cmd.parm.setup.screen = 0;
717 if (card->interface.statcallb(&cmd) == 2)
718 actcapi_connect_resp(card, &card->bch[chan], 0x15); /* Reject Call */
719 }
720 break;
721 case 0x0302:
722 /* CONNECT_ACTIVE_IND */
723 chan = find_plci(card, msg->msg.connect_active_ind.plci);
724 if (chan >= 0)
725 switch (card->bch[chan].fsm_state) {
726 case ACT2000_STATE_IWAIT:
727 actcapi_connect_active_resp(card, &card->bch[chan]);
728 break;
729 case ACT2000_STATE_OWAIT:
730 actcapi_connect_active_resp(card, &card->bch[chan]);
731 actcapi_select_b2_protocol_req(card, &card->bch[chan]);
732 break;
733 }
734 break;
735 case 0x8202:
736 /* CONNECT_B3_IND */
737 chan = find_plci(card, msg->msg.connect_b3_ind.plci);
738 if ((chan >= 0) && (card->bch[chan].fsm_state == ACT2000_STATE_IBWAIT)) {
739 card->bch[chan].ncci = msg->msg.connect_b3_ind.ncci;
740 actcapi_connect_b3_resp(card, &card->bch[chan], 0);
741 } else {
742 ctmp = (act2000_chan *)tmp;
743 ctmp->ncci = msg->msg.connect_b3_ind.ncci;
744 actcapi_connect_b3_resp(card, ctmp, 0x11); /* All Card-Cannels busy */
745 }
746 break;
747 case 0x8302:
748 /* CONNECT_B3_ACTIVE_IND */
749 chan = find_ncci(card, msg->msg.connect_b3_active_ind.ncci);
750 if ((chan >= 0) && (card->bch[chan].fsm_state == ACT2000_STATE_BWAIT)) {
751 actcapi_connect_b3_active_resp(card, &card->bch[chan]);
752 cmd.driver = card->myid;
753 cmd.command = ISDN_STAT_BCONN;
754 cmd.arg = chan;
755 card->interface.statcallb(&cmd);
756 }
757 break;
758 case 0x8402:
759 /* DISCONNECT_B3_IND */
760 chan = find_ncci(card, msg->msg.disconnect_b3_ind.ncci);
761 if (chan >= 0) {
762 ctmp = &card->bch[chan];
763 actcapi_disconnect_b3_resp(card, ctmp);
764 switch (ctmp->fsm_state) {
765 case ACT2000_STATE_ACTIVE:
766 ctmp->fsm_state = ACT2000_STATE_DHWAIT2;
767 cmd.driver = card->myid;
768 cmd.command = ISDN_STAT_BHUP;
769 cmd.arg = chan;
770 card->interface.statcallb(&cmd);
771 break;
772 case ACT2000_STATE_BHWAIT2:
773 actcapi_disconnect_req(card, ctmp);
774 ctmp->fsm_state = ACT2000_STATE_DHWAIT;
775 cmd.driver = card->myid;
776 cmd.command = ISDN_STAT_BHUP;
777 cmd.arg = chan;
778 card->interface.statcallb(&cmd);
779 break;
780 }
781 }
782 break;
783 case 0x0402:
784 /* DISCONNECT_IND */
785 chan = find_plci(card, msg->msg.disconnect_ind.plci);
786 if (chan >= 0) {
787 ctmp = &card->bch[chan];
788 actcapi_disconnect_resp(card, ctmp);
789 ctmp->fsm_state = ACT2000_STATE_NULL;
790 cmd.driver = card->myid;
791 cmd.command = ISDN_STAT_DHUP;
792 cmd.arg = chan;
793 card->interface.statcallb(&cmd);
794 } else {
795 ctmp = (act2000_chan *)tmp;
796 ctmp->plci = msg->msg.disconnect_ind.plci;
797 actcapi_disconnect_resp(card, ctmp);
798 }
799 break;
800 case 0x4001:
801 /* SELECT_B2_PROTOCOL_CONF */
802 chan = find_plci(card, msg->msg.select_b2_protocol_conf.plci);
803 if (chan >= 0)
804 switch (card->bch[chan].fsm_state) {
805 case ACT2000_STATE_ICALL:
806 case ACT2000_STATE_OWAIT:
807 ctmp = &card->bch[chan];
808 if (msg->msg.select_b2_protocol_conf.info == 0)
809 actcapi_select_b3_protocol_req(card, ctmp);
810 else {
811 ctmp->fsm_state = ACT2000_STATE_NULL;
812 cmd.driver = card->myid;
813 cmd.command = ISDN_STAT_DHUP;
814 cmd.arg = chan;
815 card->interface.statcallb(&cmd);
816 }
817 break;
818 }
819 break;
820 case 0x8001:
821 /* SELECT_B3_PROTOCOL_CONF */
822 chan = find_plci(card, msg->msg.select_b3_protocol_conf.plci);
823 if (chan >= 0)
824 switch (card->bch[chan].fsm_state) {
825 case ACT2000_STATE_ICALL:
826 case ACT2000_STATE_OWAIT:
827 ctmp = &card->bch[chan];
828 if (msg->msg.select_b3_protocol_conf.info == 0)
829 actcapi_listen_b3_req(card, ctmp);
830 else {
831 ctmp->fsm_state = ACT2000_STATE_NULL;
832 cmd.driver = card->myid;
833 cmd.command = ISDN_STAT_DHUP;
834 cmd.arg = chan;
835 card->interface.statcallb(&cmd);
836 }
837 }
838 break;
839 case 0x8101:
840 /* LISTEN_B3_CONF */
841 chan = find_plci(card, msg->msg.listen_b3_conf.plci);
842 if (chan >= 0)
843 switch (card->bch[chan].fsm_state) {
844 case ACT2000_STATE_ICALL:
845 ctmp = &card->bch[chan];
846 if (msg->msg.listen_b3_conf.info == 0)
847 actcapi_connect_resp(card, ctmp, 0);
848 else {
849 ctmp->fsm_state = ACT2000_STATE_NULL;
850 cmd.driver = card->myid;
851 cmd.command = ISDN_STAT_DHUP;
852 cmd.arg = chan;
853 card->interface.statcallb(&cmd);
854 }
855 break;
856 case ACT2000_STATE_OWAIT:
857 ctmp = &card->bch[chan];
858 if (msg->msg.listen_b3_conf.info == 0) {
859 actcapi_connect_b3_req(card, ctmp);
860 ctmp->fsm_state = ACT2000_STATE_OBWAIT;
861 cmd.driver = card->myid;
862 cmd.command = ISDN_STAT_DCONN;
863 cmd.arg = chan;
864 card->interface.statcallb(&cmd);
865 } else {
866 ctmp->fsm_state = ACT2000_STATE_NULL;
867 cmd.driver = card->myid;
868 cmd.command = ISDN_STAT_DHUP;
869 cmd.arg = chan;
870 card->interface.statcallb(&cmd);
871 }
872 break;
873 }
874 break;
875 case 0x8201:
876 /* CONNECT_B3_CONF */
877 chan = find_plci(card, msg->msg.connect_b3_conf.plci);
878 if ((chan >= 0) && (card->bch[chan].fsm_state == ACT2000_STATE_OBWAIT)) {
879 ctmp = &card->bch[chan];
880 if (msg->msg.connect_b3_conf.info) {
881 ctmp->fsm_state = ACT2000_STATE_NULL;
882 cmd.driver = card->myid;
883 cmd.command = ISDN_STAT_DHUP;
884 cmd.arg = chan;
885 card->interface.statcallb(&cmd);
886 } else {
887 ctmp->ncci = msg->msg.connect_b3_conf.ncci;
888 ctmp->fsm_state = ACT2000_STATE_BWAIT;
889 }
890 }
891 break;
892 case 0x8401:
893 /* DISCONNECT_B3_CONF */
894 chan = find_ncci(card, msg->msg.disconnect_b3_conf.ncci);
895 if ((chan >= 0) && (card->bch[chan].fsm_state == ACT2000_STATE_BHWAIT))
896 card->bch[chan].fsm_state = ACT2000_STATE_BHWAIT2;
897 break;
898 case 0x0702:
899 /* INFO_IND */
900 chan = find_plci(card, msg->msg.info_ind.plci);
901 if (chan >= 0)
902 /* TODO: Eval Charging info / cause */
903 actcapi_info_resp(card, &card->bch[chan]);
904 break;
905 case 0x0401:
906 /* LISTEN_CONF */
907 case 0x0501:
908 /* LISTEN_CONF */
909 case 0xff01:
910 /* MANUFACTURER_CONF */
911 break;
912 case 0xff02:
913 /* MANUFACTURER_IND */
914 if (msg->msg.manuf_msg == 3) {
915 memset(tmp, 0, sizeof(tmp));
916 strncpy(tmp,
917 &msg->msg.manufacturer_ind_err.errstring,
918 msg->hdr.len - 16);
919 if (msg->msg.manufacturer_ind_err.errcode)
920 printk(KERN_WARNING "act2000: %s\n", tmp);
921 else {
922 printk(KERN_DEBUG "act2000: %s\n", tmp);
923 if ((!strncmp(tmp, "INFO: Trace buffer con", 22)) ||
924 (!strncmp(tmp, "INFO: Compile Date/Tim", 22))) {
925 card->flags |= ACT2000_FLAGS_RUNNING;
926 cmd.command = ISDN_STAT_RUN;
927 cmd.driver = card->myid;
928 cmd.arg = 0;
929 actcapi_manufacturer_req_net(card);
930 actcapi_manufacturer_req_msn(card);
931 actcapi_listen_req(card);
932 card->interface.statcallb(&cmd);
933 }
934 }
935 }
936 break;
937 default:
938 printk(KERN_WARNING "act2000: UNHANDLED Message %04x\n", ccmd);
939 break;
940 }
941 dev_kfree_skb(skb);
942 }
943}
944
945#ifdef DEBUG_MSG
946static void
947actcapi_debug_caddr(actcapi_addr *addr)
948{
949 char tmp[30];
950
951 printk(KERN_DEBUG " Alen = %d\n", addr->len);
952 if (addr->len > 0)
953 printk(KERN_DEBUG " Atnp = 0x%02x\n", addr->tnp);
954 if (addr->len > 1) {
955 memset(tmp, 0, 30);
956 memcpy(tmp, addr->num, addr->len - 1);
957 printk(KERN_DEBUG " Anum = '%s'\n", tmp);
958 }
959}
960
961static void
962actcapi_debug_ncpi(actcapi_ncpi *ncpi)
963{
964 printk(KERN_DEBUG " ncpi.len = %d\n", ncpi->len);
965 if (ncpi->len >= 2)
966 printk(KERN_DEBUG " ncpi.lic = 0x%04x\n", ncpi->lic);
967 if (ncpi->len >= 4)
968 printk(KERN_DEBUG " ncpi.hic = 0x%04x\n", ncpi->hic);
969 if (ncpi->len >= 6)
970 printk(KERN_DEBUG " ncpi.ltc = 0x%04x\n", ncpi->ltc);
971 if (ncpi->len >= 8)
972 printk(KERN_DEBUG " ncpi.htc = 0x%04x\n", ncpi->htc);
973 if (ncpi->len >= 10)
974 printk(KERN_DEBUG " ncpi.loc = 0x%04x\n", ncpi->loc);
975 if (ncpi->len >= 12)
976 printk(KERN_DEBUG " ncpi.hoc = 0x%04x\n", ncpi->hoc);
977 if (ncpi->len >= 13)
978 printk(KERN_DEBUG " ncpi.mod = %d\n", ncpi->modulo);
979}
980
981static void
982actcapi_debug_dlpd(actcapi_dlpd *dlpd)
983{
984 printk(KERN_DEBUG " dlpd.len = %d\n", dlpd->len);
985 if (dlpd->len >= 2)
986 printk(KERN_DEBUG " dlpd.dlen = 0x%04x\n", dlpd->dlen);
987 if (dlpd->len >= 3)
988 printk(KERN_DEBUG " dlpd.laa = 0x%02x\n", dlpd->laa);
989 if (dlpd->len >= 4)
990 printk(KERN_DEBUG " dlpd.lab = 0x%02x\n", dlpd->lab);
991 if (dlpd->len >= 5)
992 printk(KERN_DEBUG " dlpd.modulo = %d\n", dlpd->modulo);
993 if (dlpd->len >= 6)
994 printk(KERN_DEBUG " dlpd.win = %d\n", dlpd->win);
995}
996
997#ifdef DEBUG_DUMP_SKB
998static void dump_skb(struct sk_buff *skb)
999{
1000 char tmp[80];
1001 char *p = skb->data;
1002 char *t = tmp;
1003 int i;
1004
1005 for (i = 0; i < skb->len; i++) {
1006 t += sprintf(t, "%02x ", *p++ & 0xff);
1007 if ((i & 0x0f) == 8) {
1008 printk(KERN_DEBUG "dump: %s\n", tmp);
1009 t = tmp;
1010 }
1011 }
1012 if (i & 0x07)
1013 printk(KERN_DEBUG "dump: %s\n", tmp);
1014}
1015#endif
1016
1017void
1018actcapi_debug_msg(struct sk_buff *skb, int direction)
1019{
1020 actcapi_msg *msg = (actcapi_msg *)skb->data;
1021 char *descr;
1022 int i;
1023 char tmp[170];
1024
1025#ifndef DEBUG_DATA_MSG
1026 if (msg->hdr.cmd.cmd == 0x86)
1027 return;
1028#endif
1029 descr = "INVALID";
1030#ifdef DEBUG_DUMP_SKB
1031 dump_skb(skb);
1032#endif
1033 for (i = 0; i < ARRAY_SIZE(valid_msg); i++)
1034 if ((msg->hdr.cmd.cmd == valid_msg[i].cmd.cmd) &&
1035 (msg->hdr.cmd.subcmd == valid_msg[i].cmd.subcmd)) {
1036 descr = valid_msg[i].description;
1037 break;
1038 }
1039 printk(KERN_DEBUG "%s %s msg\n", direction ? "Outgoing" : "Incoming", descr);
1040 printk(KERN_DEBUG " ApplID = %d\n", msg->hdr.applicationID);
1041 printk(KERN_DEBUG " Len = %d\n", msg->hdr.len);
1042 printk(KERN_DEBUG " MsgNum = 0x%04x\n", msg->hdr.msgnum);
1043 printk(KERN_DEBUG " Cmd = 0x%02x\n", msg->hdr.cmd.cmd);
1044 printk(KERN_DEBUG " SubCmd = 0x%02x\n", msg->hdr.cmd.subcmd);
1045 switch (i) {
1046 case 0:
1047 /* DATA B3 IND */
1048 printk(KERN_DEBUG " BLOCK = 0x%02x\n",
1049 msg->msg.data_b3_ind.blocknr);
1050 break;
1051 case 2:
1052 /* CONNECT CONF */
1053 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1054 msg->msg.connect_conf.plci);
1055 printk(KERN_DEBUG " Info = 0x%04x\n",
1056 msg->msg.connect_conf.info);
1057 break;
1058 case 3:
1059 /* CONNECT IND */
1060 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1061 msg->msg.connect_ind.plci);
1062 printk(KERN_DEBUG " Contr = %d\n",
1063 msg->msg.connect_ind.controller);
1064 printk(KERN_DEBUG " SI1 = %d\n",
1065 msg->msg.connect_ind.si1);
1066 printk(KERN_DEBUG " SI2 = %d\n",
1067 msg->msg.connect_ind.si2);
1068 printk(KERN_DEBUG " EAZ = '%c'\n",
1069 msg->msg.connect_ind.eaz);
1070 actcapi_debug_caddr(&msg->msg.connect_ind.addr);
1071 break;
1072 case 5:
1073 /* CONNECT ACTIVE IND */
1074 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1075 msg->msg.connect_active_ind.plci);
1076 actcapi_debug_caddr(&msg->msg.connect_active_ind.addr);
1077 break;
1078 case 8:
1079 /* LISTEN CONF */
1080 printk(KERN_DEBUG " Contr = %d\n",
1081 msg->msg.listen_conf.controller);
1082 printk(KERN_DEBUG " Info = 0x%04x\n",
1083 msg->msg.listen_conf.info);
1084 break;
1085 case 11:
1086 /* INFO IND */
1087 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1088 msg->msg.info_ind.plci);
1089 printk(KERN_DEBUG " Imsk = 0x%04x\n",
1090 msg->msg.info_ind.nr.mask);
1091 if (msg->hdr.len > 12) {
1092 int l = msg->hdr.len - 12;
1093 int j;
1094 char *p = tmp;
1095
1096 for (j = 0; j < l; j++)
1097 p += sprintf(p, "%02x ", msg->msg.info_ind.el.display[j]);
1098 printk(KERN_DEBUG " D = '%s'\n", tmp);
1099 }
1100 break;
1101 case 14:
1102 /* SELECT B2 PROTOCOL CONF */
1103 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1104 msg->msg.select_b2_protocol_conf.plci);
1105 printk(KERN_DEBUG " Info = 0x%04x\n",
1106 msg->msg.select_b2_protocol_conf.info);
1107 break;
1108 case 15:
1109 /* SELECT B3 PROTOCOL CONF */
1110 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1111 msg->msg.select_b3_protocol_conf.plci);
1112 printk(KERN_DEBUG " Info = 0x%04x\n",
1113 msg->msg.select_b3_protocol_conf.info);
1114 break;
1115 case 16:
1116 /* LISTEN B3 CONF */
1117 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1118 msg->msg.listen_b3_conf.plci);
1119 printk(KERN_DEBUG " Info = 0x%04x\n",
1120 msg->msg.listen_b3_conf.info);
1121 break;
1122 case 18:
1123 /* CONNECT B3 IND */
1124 printk(KERN_DEBUG " NCCI = 0x%04x\n",
1125 msg->msg.connect_b3_ind.ncci);
1126 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1127 msg->msg.connect_b3_ind.plci);
1128 actcapi_debug_ncpi(&msg->msg.connect_b3_ind.ncpi);
1129 break;
1130 case 19:
1131 /* CONNECT B3 ACTIVE IND */
1132 printk(KERN_DEBUG " NCCI = 0x%04x\n",
1133 msg->msg.connect_b3_active_ind.ncci);
1134 actcapi_debug_ncpi(&msg->msg.connect_b3_active_ind.ncpi);
1135 break;
1136 case 26:
1137 /* MANUFACTURER IND */
1138 printk(KERN_DEBUG " Mmsg = 0x%02x\n",
1139 msg->msg.manufacturer_ind_err.manuf_msg);
1140 switch (msg->msg.manufacturer_ind_err.manuf_msg) {
1141 case 3:
1142 printk(KERN_DEBUG " Contr = %d\n",
1143 msg->msg.manufacturer_ind_err.controller);
1144 printk(KERN_DEBUG " Code = 0x%08x\n",
1145 msg->msg.manufacturer_ind_err.errcode);
1146 memset(tmp, 0, sizeof(tmp));
1147 strncpy(tmp, &msg->msg.manufacturer_ind_err.errstring,
1148 msg->hdr.len - 16);
1149 printk(KERN_DEBUG " Emsg = '%s'\n", tmp);
1150 break;
1151 }
1152 break;
1153 case 30:
1154 /* LISTEN REQ */
1155 printk(KERN_DEBUG " Imsk = 0x%08x\n",
1156 msg->msg.listen_req.infomask);
1157 printk(KERN_DEBUG " Emsk = 0x%04x\n",
1158 msg->msg.listen_req.eazmask);
1159 printk(KERN_DEBUG " Smsk = 0x%04x\n",
1160 msg->msg.listen_req.simask);
1161 break;
1162 case 35:
1163 /* SELECT_B2_PROTOCOL_REQ */
1164 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1165 msg->msg.select_b2_protocol_req.plci);
1166 printk(KERN_DEBUG " prot = 0x%02x\n",
1167 msg->msg.select_b2_protocol_req.protocol);
1168 if (msg->hdr.len >= 11)
1169 printk(KERN_DEBUG "No dlpd\n");
1170 else
1171 actcapi_debug_dlpd(&msg->msg.select_b2_protocol_req.dlpd);
1172 break;
1173 case 44:
1174 /* CONNECT RESP */
1175 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1176 msg->msg.connect_resp.plci);
1177 printk(KERN_DEBUG " CAUSE = 0x%02x\n",
1178 msg->msg.connect_resp.rejectcause);
1179 break;
1180 case 45:
1181 /* CONNECT ACTIVE RESP */
1182 printk(KERN_DEBUG " PLCI = 0x%04x\n",
1183 msg->msg.connect_active_resp.plci);
1184 break;
1185 }
1186}
1187#endif
diff --git a/drivers/staging/i4l/act2000/capi.h b/drivers/staging/i4l/act2000/capi.h
deleted file mode 100644
index 34884a5efee5..000000000000
--- a/drivers/staging/i4l/act2000/capi.h
+++ /dev/null
@@ -1,357 +0,0 @@
1/* $Id: capi.h,v 1.6.6.2 2001/09/23 22:24:32 kai Exp $
2 *
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000.
4 *
5 * Author Fritz Elfert
6 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 * Thanks to Friedemann Baitinger and IBM Germany
12 *
13 */
14
15#ifndef CAPI_H
16#define CAPI_H
17
18/* Command-part of a CAPI message */
19typedef struct actcapi_msgcmd {
20 __u8 cmd;
21 __u8 subcmd;
22} actcapi_msgcmd;
23
24/* CAPI message header */
25typedef struct actcapi_msghdr {
26 __u16 len;
27 __u16 applicationID;
28 actcapi_msgcmd cmd;
29 __u16 msgnum;
30} actcapi_msghdr;
31
32/* CAPI message description (for debugging) */
33typedef struct actcapi_msgdsc {
34 actcapi_msgcmd cmd;
35 char *description;
36} actcapi_msgdsc;
37
38/* CAPI Address */
39typedef struct actcapi_addr {
40 __u8 len; /* Length of element */
41 __u8 tnp; /* Type/Numbering Plan */
42 __u8 num[20]; /* Caller ID */
43} actcapi_addr;
44
45/* CAPI INFO element mask */
46typedef union actcapi_infonr { /* info number */
47 __u16 mask; /* info-mask field */
48 struct bmask { /* bit definitions */
49 unsigned codes:3; /* code set */
50 unsigned rsvd:5; /* reserved */
51 unsigned svind:1; /* single, variable length ind. */
52 unsigned wtype:7; /* W-element type */
53 } bmask;
54} actcapi_infonr;
55
56/* CAPI INFO element */
57typedef union actcapi_infoel { /* info element */
58 __u8 len; /* length of info element */
59 __u8 display[40]; /* display contents */
60 __u8 uuinfo[40]; /* User-user info field */
61 struct cause { /* Cause information */
62 unsigned ext2:1; /* extension */
63 unsigned cod:2; /* coding standard */
64 unsigned spare:1; /* spare */
65 unsigned loc:4; /* location */
66 unsigned ext1:1; /* extension */
67 unsigned cval:7; /* Cause value */
68 } cause;
69 struct charge { /* Charging information */
70 __u8 toc; /* type of charging info */
71 __u8 unit[10]; /* charging units */
72 } charge;
73 __u8 date[20]; /* date fields */
74 __u8 stat; /* state of remote party */
75} actcapi_infoel;
76
77/* Message for EAZ<->MSN Mapping */
78typedef struct actcapi_msn {
79 __u8 eaz;
80 __u8 len; /* Length of MSN */
81 __u8 msn[15];
82} __attribute__((packed)) actcapi_msn;
83
84typedef struct actcapi_dlpd {
85 __u8 len; /* Length of structure */
86 __u16 dlen; /* Data Length */
87 __u8 laa; /* Link Address A */
88 __u8 lab; /* Link Address B */
89 __u8 modulo; /* Modulo Mode */
90 __u8 win; /* Window size */
91 __u8 xid[100]; /* XID Information */
92} __attribute__((packed)) actcapi_dlpd;
93
94typedef struct actcapi_ncpd {
95 __u8 len; /* Length of structure */
96 __u16 lic;
97 __u16 hic;
98 __u16 ltc;
99 __u16 htc;
100 __u16 loc;
101 __u16 hoc;
102 __u8 modulo;
103} __attribute__((packed)) actcapi_ncpd;
104#define actcapi_ncpi actcapi_ncpd
105
106/*
107 * Layout of NCCI field in a B3 DATA CAPI message is different from
108 * standard at act2000:
109 *
110 * Bit 0-4 = PLCI
111 * Bit 5-7 = Controller
112 * Bit 8-15 = NCCI
113 */
114#define MAKE_NCCI(plci, contr, ncci) \
115 ((plci & 0x1f) | ((contr & 0x7) << 5) | ((ncci & 0xff) << 8))
116
117#define EVAL_NCCI(fakencci, plci, ncci) { \
118 plci = fakencci & 0x1f; \
119 ncci = (fakencci >> 8) & 0xff; \
120 }
121
122/*
123 * Layout of PLCI field in a B3 DATA CAPI message is different from
124 * standard at act2000:
125 *
126 * Bit 0-4 = PLCI
127 * Bit 5-7 = Controller
128 * Bit 8-15 = reserved (must be 0)
129 */
130
131typedef struct actcapi_msg {
132 actcapi_msghdr hdr;
133 union {
134 __u16 manuf_msg;
135 struct manufacturer_req_net {
136 __u16 manuf_msg;
137 __u16 controller;
138 __u8 nettype;
139 } manufacturer_req_net;
140 struct manufacturer_req_v42 {
141 __u16 manuf_msg;
142 __u16 controller;
143 __u32 v42control;
144 } manufacturer_req_v42;
145 struct manufacturer_conf_v42 {
146 __u16 manuf_msg;
147 __u16 controller;
148 } manufacturer_conf_v42;
149 struct manufacturer_req_err {
150 __u16 manuf_msg;
151 __u16 controller;
152 } manufacturer_req_err;
153 struct manufacturer_ind_err {
154 __u16 manuf_msg;
155 __u16 controller;
156 __u32 errcode;
157 __u8 errstring; /* actually up to 160 */
158 } manufacturer_ind_err;
159 struct manufacturer_req_msn {
160 __u16 manuf_msg;
161 __u16 controller;
162 actcapi_msn msnmap;
163 } __attribute ((packed)) manufacturer_req_msn;
164 /* TODO: TraceInit-req/conf/ind/resp and
165 * TraceDump-req/conf/ind/resp
166 */
167 struct connect_req {
168 __u8 controller;
169 __u8 bchan;
170 __u32 infomask;
171 __u8 si1;
172 __u8 si2;
173 __u8 eaz;
174 actcapi_addr addr;
175 } __attribute__ ((packed)) connect_req;
176 struct connect_conf {
177 __u16 plci;
178 __u16 info;
179 } connect_conf;
180 struct connect_ind {
181 __u16 plci;
182 __u8 controller;
183 __u8 si1;
184 __u8 si2;
185 __u8 eaz;
186 actcapi_addr addr;
187 } __attribute__ ((packed)) connect_ind;
188 struct connect_resp {
189 __u16 plci;
190 __u8 rejectcause;
191 } connect_resp;
192 struct connect_active_ind {
193 __u16 plci;
194 actcapi_addr addr;
195 } __attribute__ ((packed)) connect_active_ind;
196 struct connect_active_resp {
197 __u16 plci;
198 } connect_active_resp;
199 struct connect_b3_req {
200 __u16 plci;
201 actcapi_ncpi ncpi;
202 } __attribute__ ((packed)) connect_b3_req;
203 struct connect_b3_conf {
204 __u16 plci;
205 __u16 ncci;
206 __u16 info;
207 } connect_b3_conf;
208 struct connect_b3_ind {
209 __u16 ncci;
210 __u16 plci;
211 actcapi_ncpi ncpi;
212 } __attribute__ ((packed)) connect_b3_ind;
213 struct connect_b3_resp {
214 __u16 ncci;
215 __u8 rejectcause;
216 actcapi_ncpi ncpi;
217 } __attribute__ ((packed)) connect_b3_resp;
218 struct disconnect_req {
219 __u16 plci;
220 __u8 cause;
221 } disconnect_req;
222 struct disconnect_conf {
223 __u16 plci;
224 __u16 info;
225 } disconnect_conf;
226 struct disconnect_ind {
227 __u16 plci;
228 __u16 info;
229 } disconnect_ind;
230 struct disconnect_resp {
231 __u16 plci;
232 } disconnect_resp;
233 struct connect_b3_active_ind {
234 __u16 ncci;
235 actcapi_ncpi ncpi;
236 } __attribute__ ((packed)) connect_b3_active_ind;
237 struct connect_b3_active_resp {
238 __u16 ncci;
239 } connect_b3_active_resp;
240 struct disconnect_b3_req {
241 __u16 ncci;
242 actcapi_ncpi ncpi;
243 } __attribute__ ((packed)) disconnect_b3_req;
244 struct disconnect_b3_conf {
245 __u16 ncci;
246 __u16 info;
247 } disconnect_b3_conf;
248 struct disconnect_b3_ind {
249 __u16 ncci;
250 __u16 info;
251 actcapi_ncpi ncpi;
252 } __attribute__ ((packed)) disconnect_b3_ind;
253 struct disconnect_b3_resp {
254 __u16 ncci;
255 } disconnect_b3_resp;
256 struct info_ind {
257 __u16 plci;
258 actcapi_infonr nr;
259 actcapi_infoel el;
260 } __attribute__ ((packed)) info_ind;
261 struct info_resp {
262 __u16 plci;
263 } info_resp;
264 struct listen_b3_req {
265 __u16 plci;
266 } listen_b3_req;
267 struct listen_b3_conf {
268 __u16 plci;
269 __u16 info;
270 } listen_b3_conf;
271 struct select_b2_protocol_req {
272 __u16 plci;
273 __u8 protocol;
274 actcapi_dlpd dlpd;
275 } __attribute__ ((packed)) select_b2_protocol_req;
276 struct select_b2_protocol_conf {
277 __u16 plci;
278 __u16 info;
279 } select_b2_protocol_conf;
280 struct select_b3_protocol_req {
281 __u16 plci;
282 __u8 protocol;
283 actcapi_ncpd ncpd;
284 } __attribute__ ((packed)) select_b3_protocol_req;
285 struct select_b3_protocol_conf {
286 __u16 plci;
287 __u16 info;
288 } select_b3_protocol_conf;
289 struct listen_req {
290 __u8 controller;
291 __u32 infomask;
292 __u16 eazmask;
293 __u16 simask;
294 } __attribute__ ((packed)) listen_req;
295 struct listen_conf {
296 __u8 controller;
297 __u16 info;
298 } __attribute__ ((packed)) listen_conf;
299 struct data_b3_req {
300 __u16 fakencci;
301 __u16 datalen;
302 __u32 unused;
303 __u8 blocknr;
304 __u16 flags;
305 } __attribute ((packed)) data_b3_req;
306 struct data_b3_ind {
307 __u16 fakencci;
308 __u16 datalen;
309 __u32 unused;
310 __u8 blocknr;
311 __u16 flags;
312 } __attribute__ ((packed)) data_b3_ind;
313 struct data_b3_resp {
314 __u16 ncci;
315 __u8 blocknr;
316 } __attribute__ ((packed)) data_b3_resp;
317 struct data_b3_conf {
318 __u16 ncci;
319 __u8 blocknr;
320 __u16 info;
321 } __attribute__ ((packed)) data_b3_conf;
322 } msg;
323} __attribute__ ((packed)) actcapi_msg;
324
325static inline unsigned short
326actcapi_nextsmsg(act2000_card *card)
327{
328 unsigned long flags;
329 unsigned short n;
330
331 spin_lock_irqsave(&card->mnlock, flags);
332 n = card->msgnum;
333 card->msgnum++;
334 card->msgnum &= 0x7fff;
335 spin_unlock_irqrestore(&card->mnlock, flags);
336 return n;
337}
338#define DEBUG_MSG
339#undef DEBUG_DATA_MSG
340#undef DEBUG_DUMP_SKB
341
342extern int actcapi_chkhdr(act2000_card *, actcapi_msghdr *);
343extern int actcapi_listen_req(act2000_card *);
344extern int actcapi_manufacturer_req_net(act2000_card *);
345extern int actcapi_manufacturer_req_errh(act2000_card *);
346extern int actcapi_manufacturer_req_msn(act2000_card *);
347extern int actcapi_connect_req(act2000_card *, act2000_chan *, char *, char, int, int);
348extern void actcapi_select_b2_protocol_req(act2000_card *, act2000_chan *);
349extern void actcapi_disconnect_b3_req(act2000_card *, act2000_chan *);
350extern void actcapi_connect_resp(act2000_card *, act2000_chan *, __u8);
351extern void actcapi_dispatch(struct work_struct *);
352#ifdef DEBUG_MSG
353extern void actcapi_debug_msg(struct sk_buff *skb, int);
354#else
355#define actcapi_debug_msg(skb, len)
356#endif
357#endif
diff --git a/drivers/staging/i4l/act2000/module.c b/drivers/staging/i4l/act2000/module.c
deleted file mode 100644
index 6aa120319e52..000000000000
--- a/drivers/staging/i4l/act2000/module.c
+++ /dev/null
@@ -1,816 +0,0 @@
1/* $Id: module.c,v 1.14.6.4 2001/09/23 22:24:32 kai Exp $
2 *
3 * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000.
4 *
5 * Author Fritz Elfert
6 * Copyright by Fritz Elfert <fritz@isdn4linux.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 * Thanks to Friedemann Baitinger and IBM Germany
12 *
13 */
14
15#include "act2000.h"
16#include "act2000_isa.h"
17#include "capi.h"
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/init.h>
21
22static unsigned short act2000_isa_ports[] = {
23 0x0200, 0x0240, 0x0280, 0x02c0, 0x0300, 0x0340, 0x0380,
24 0xcfe0, 0xcfa0, 0xcf60, 0xcf20, 0xcee0, 0xcea0, 0xce60,
25};
26
27static act2000_card *cards = (act2000_card *) NULL;
28
29/* Parameters to be set by insmod */
30static int act_bus;
31static int act_port = -1; /* -1 = Autoprobe */
32static int act_irq = -1;
33static char *act_id = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
34
35MODULE_DESCRIPTION("ISDN4Linux: Driver for IBM Active 2000 ISDN card");
36MODULE_AUTHOR("Fritz Elfert");
37MODULE_LICENSE("GPL");
38MODULE_PARM_DESC(act_bus, "BusType of first card, 1=ISA, 2=MCA, 3=PCMCIA, currently only ISA");
39MODULE_PARM_DESC(act_port, "Base port address of first card");
40MODULE_PARM_DESC(act_irq, "IRQ of first card");
41MODULE_PARM_DESC(act_id, "ID-String of first card");
42module_param(act_bus, int, 0);
43module_param(act_port, int, 0);
44module_param(act_irq, int, 0);
45module_param(act_id, charp, 0);
46
47static int act2000_addcard(int, int, int, char *);
48
49static act2000_chan *
50find_channel(act2000_card *card, int channel)
51{
52 if ((channel >= 0) && (channel < ACT2000_BCH))
53 return &(card->bch[channel]);
54 printk(KERN_WARNING "act2000: Invalid channel %d\n", channel);
55 return NULL;
56}
57
58/*
59 * Free MSN list
60 */
61static void
62act2000_clear_msn(act2000_card *card)
63{
64 struct msn_entry *p = card->msn_list;
65 struct msn_entry *q;
66 unsigned long flags;
67
68 spin_lock_irqsave(&card->lock, flags);
69 card->msn_list = NULL;
70 spin_unlock_irqrestore(&card->lock, flags);
71 while (p) {
72 q = p->next;
73 kfree(p);
74 p = q;
75 }
76}
77
78/*
79 * Find an MSN entry in the list.
80 * If ia5 != 0, return IA5-encoded EAZ, else
81 * return a bitmask with corresponding bit set.
82 */
83static __u16
84act2000_find_msn(act2000_card *card, char *msn, int ia5)
85{
86 struct msn_entry *p = card->msn_list;
87 __u8 eaz = '0';
88
89 while (p) {
90 if (!strcmp(p->msn, msn)) {
91 eaz = p->eaz;
92 break;
93 }
94 p = p->next;
95 }
96 if (!ia5)
97 return 1 << (eaz - '0');
98 else
99 return eaz;
100}
101
102/*
103 * Find an EAZ entry in the list.
104 * return a string with corresponding msn.
105 */
106char *
107act2000_find_eaz(act2000_card *card, char eaz)
108{
109 struct msn_entry *p = card->msn_list;
110
111 while (p) {
112 if (p->eaz == eaz)
113 return p->msn;
114 p = p->next;
115 }
116 return "\0";
117}
118
119/*
120 * Add or delete an MSN to the MSN list
121 *
122 * First character of msneaz is EAZ, rest is MSN.
123 * If length of eazmsn is 1, delete that entry.
124 */
125static int
126act2000_set_msn(act2000_card *card, char *eazmsn)
127{
128 struct msn_entry *p = card->msn_list;
129 struct msn_entry *q = NULL;
130 unsigned long flags;
131 int i;
132
133 if (!strlen(eazmsn))
134 return 0;
135 if (strlen(eazmsn) > 16)
136 return -EINVAL;
137 for (i = 0; i < strlen(eazmsn); i++)
138 if (!isdigit(eazmsn[i]))
139 return -EINVAL;
140 if (strlen(eazmsn) == 1) {
141 /* Delete a single MSN */
142 while (p) {
143 if (p->eaz == eazmsn[0]) {
144 spin_lock_irqsave(&card->lock, flags);
145 if (q)
146 q->next = p->next;
147 else
148 card->msn_list = p->next;
149 spin_unlock_irqrestore(&card->lock, flags);
150 kfree(p);
151 printk(KERN_DEBUG
152 "Mapping for EAZ %c deleted\n",
153 eazmsn[0]);
154 return 0;
155 }
156 q = p;
157 p = p->next;
158 }
159 return 0;
160 }
161 /* Add a single MSN */
162 while (p) {
163 /* Found in list, replace MSN */
164 if (p->eaz == eazmsn[0]) {
165 spin_lock_irqsave(&card->lock, flags);
166 strcpy(p->msn, &eazmsn[1]);
167 spin_unlock_irqrestore(&card->lock, flags);
168 printk(KERN_DEBUG
169 "Mapping for EAZ %c changed to %s\n",
170 eazmsn[0],
171 &eazmsn[1]);
172 return 0;
173 }
174 p = p->next;
175 }
176 /* Not found in list, add new entry */
177 p = kmalloc(sizeof(msn_entry), GFP_KERNEL);
178 if (!p)
179 return -ENOMEM;
180 p->eaz = eazmsn[0];
181 strcpy(p->msn, &eazmsn[1]);
182 p->next = card->msn_list;
183 spin_lock_irqsave(&card->lock, flags);
184 card->msn_list = p;
185 spin_unlock_irqrestore(&card->lock, flags);
186 printk(KERN_DEBUG
187 "Mapping %c -> %s added\n",
188 eazmsn[0],
189 &eazmsn[1]);
190 return 0;
191}
192
193static void
194act2000_transmit(struct work_struct *work)
195{
196 struct act2000_card *card =
197 container_of(work, struct act2000_card, snd_tq);
198
199 switch (card->bus) {
200 case ACT2000_BUS_ISA:
201 act2000_isa_send(card);
202 break;
203 case ACT2000_BUS_PCMCIA:
204 case ACT2000_BUS_MCA:
205 default:
206 printk(KERN_WARNING
207 "act2000_transmit: Illegal bustype %d\n", card->bus);
208 }
209}
210
211static void
212act2000_receive(struct work_struct *work)
213{
214 struct act2000_card *card =
215 container_of(work, struct act2000_card, poll_tq);
216
217 switch (card->bus) {
218 case ACT2000_BUS_ISA:
219 act2000_isa_receive(card);
220 break;
221 case ACT2000_BUS_PCMCIA:
222 case ACT2000_BUS_MCA:
223 default:
224 printk(KERN_WARNING
225 "act2000_receive: Illegal bustype %d\n", card->bus);
226 }
227}
228
229static void
230act2000_poll(unsigned long data)
231{
232 act2000_card *card = (act2000_card *)data;
233 unsigned long flags;
234
235 act2000_receive(&card->poll_tq);
236 spin_lock_irqsave(&card->lock, flags);
237 mod_timer(&card->ptimer, jiffies + 3);
238 spin_unlock_irqrestore(&card->lock, flags);
239}
240
241static int
242act2000_command(act2000_card *card, isdn_ctrl *c)
243{
244 ulong a;
245 act2000_chan *chan;
246 act2000_cdef cdef;
247 isdn_ctrl cmd;
248 char tmp[17];
249 int ret;
250 unsigned long flags;
251 void __user *arg;
252
253 switch (c->command) {
254 case ISDN_CMD_IOCTL:
255 memcpy(&a, c->parm.num, sizeof(ulong));
256 arg = (void __user *)a;
257 switch (c->arg) {
258 case ACT2000_IOCTL_LOADBOOT:
259 switch (card->bus) {
260 case ACT2000_BUS_ISA:
261 ret = act2000_isa_download(card,
262 arg);
263 if (!ret) {
264 card->flags |= ACT2000_FLAGS_LOADED;
265 if (!(card->flags & ACT2000_FLAGS_IVALID)) {
266 card->ptimer.expires = jiffies + 3;
267 card->ptimer.function = act2000_poll;
268 card->ptimer.data = (unsigned long)card;
269 add_timer(&card->ptimer);
270 }
271 actcapi_manufacturer_req_errh(card);
272 }
273 break;
274 default:
275 printk(KERN_WARNING
276 "act2000: Illegal BUS type %d\n",
277 card->bus);
278 ret = -EIO;
279 }
280 return ret;
281 case ACT2000_IOCTL_SETPROTO:
282 card->ptype = a ? ISDN_PTYPE_EURO : ISDN_PTYPE_1TR6;
283 if (!(card->flags & ACT2000_FLAGS_RUNNING))
284 return 0;
285 actcapi_manufacturer_req_net(card);
286 return 0;
287 case ACT2000_IOCTL_SETMSN:
288 if (copy_from_user(tmp, arg,
289 sizeof(tmp)))
290 return -EFAULT;
291 ret = act2000_set_msn(card, tmp);
292 if (ret)
293 return ret;
294 if (card->flags & ACT2000_FLAGS_RUNNING)
295 return actcapi_manufacturer_req_msn(card);
296 return 0;
297 case ACT2000_IOCTL_ADDCARD:
298 if (copy_from_user(&cdef, arg,
299 sizeof(cdef)))
300 return -EFAULT;
301 if (act2000_addcard(cdef.bus, cdef.port, cdef.irq, cdef.id))
302 return -EIO;
303 return 0;
304 case ACT2000_IOCTL_TEST:
305 if (!(card->flags & ACT2000_FLAGS_RUNNING))
306 return -ENODEV;
307 return 0;
308 default:
309 return -EINVAL;
310 }
311 break;
312 case ISDN_CMD_DIAL:
313 if (!(card->flags & ACT2000_FLAGS_RUNNING))
314 return -ENODEV;
315 if (!(chan = find_channel(card, c->arg & 0x0f)))
316 break;
317 spin_lock_irqsave(&card->lock, flags);
318 if (chan->fsm_state != ACT2000_STATE_NULL) {
319 spin_unlock_irqrestore(&card->lock, flags);
320 printk(KERN_WARNING "Dial on channel with state %d\n",
321 chan->fsm_state);
322 return -EBUSY;
323 }
324 if (card->ptype == ISDN_PTYPE_EURO)
325 tmp[0] = act2000_find_msn(card, c->parm.setup.eazmsn, 1);
326 else
327 tmp[0] = c->parm.setup.eazmsn[0];
328 chan->fsm_state = ACT2000_STATE_OCALL;
329 chan->callref = 0xffff;
330 spin_unlock_irqrestore(&card->lock, flags);
331 ret = actcapi_connect_req(card, chan, c->parm.setup.phone,
332 tmp[0], c->parm.setup.si1,
333 c->parm.setup.si2);
334 if (ret) {
335 cmd.driver = card->myid;
336 cmd.command = ISDN_STAT_DHUP;
337 cmd.arg &= 0x0f;
338 card->interface.statcallb(&cmd);
339 }
340 return ret;
341 case ISDN_CMD_ACCEPTD:
342 if (!(card->flags & ACT2000_FLAGS_RUNNING))
343 return -ENODEV;
344 if (!(chan = find_channel(card, c->arg & 0x0f)))
345 break;
346 if (chan->fsm_state == ACT2000_STATE_ICALL)
347 actcapi_select_b2_protocol_req(card, chan);
348 return 0;
349 case ISDN_CMD_ACCEPTB:
350 if (!(card->flags & ACT2000_FLAGS_RUNNING))
351 return -ENODEV;
352 return 0;
353 case ISDN_CMD_HANGUP:
354 if (!(card->flags & ACT2000_FLAGS_RUNNING))
355 return -ENODEV;
356 if (!(chan = find_channel(card, c->arg & 0x0f)))
357 break;
358 switch (chan->fsm_state) {
359 case ACT2000_STATE_ICALL:
360 case ACT2000_STATE_BSETUP:
361 actcapi_connect_resp(card, chan, 0x15);
362 break;
363 case ACT2000_STATE_ACTIVE:
364 actcapi_disconnect_b3_req(card, chan);
365 break;
366 }
367 return 0;
368 case ISDN_CMD_SETEAZ:
369 if (!(card->flags & ACT2000_FLAGS_RUNNING))
370 return -ENODEV;
371 if (!(chan = find_channel(card, c->arg & 0x0f)))
372 break;
373 if (strlen(c->parm.num)) {
374 if (card->ptype == ISDN_PTYPE_EURO) {
375 chan->eazmask = act2000_find_msn(card, c->parm.num, 0);
376 }
377 if (card->ptype == ISDN_PTYPE_1TR6) {
378 int i;
379
380 chan->eazmask = 0;
381 for (i = 0; i < strlen(c->parm.num); i++)
382 if (isdigit(c->parm.num[i]))
383 chan->eazmask |= (1 << (c->parm.num[i] - '0'));
384 }
385 } else
386 chan->eazmask = 0x3ff;
387 actcapi_listen_req(card);
388 return 0;
389 case ISDN_CMD_CLREAZ:
390 if (!(card->flags & ACT2000_FLAGS_RUNNING))
391 return -ENODEV;
392 if (!(chan = find_channel(card, c->arg & 0x0f)))
393 break;
394 chan->eazmask = 0;
395 actcapi_listen_req(card);
396 return 0;
397 case ISDN_CMD_SETL2:
398 if (!(card->flags & ACT2000_FLAGS_RUNNING))
399 return -ENODEV;
400 if (!(chan = find_channel(card, c->arg & 0x0f)))
401 break;
402 chan->l2prot = (c->arg >> 8);
403 return 0;
404 case ISDN_CMD_SETL3:
405 if (!(card->flags & ACT2000_FLAGS_RUNNING))
406 return -ENODEV;
407 if ((c->arg >> 8) != ISDN_PROTO_L3_TRANS) {
408 printk(KERN_WARNING "L3 protocol unknown\n");
409 return -1;
410 }
411 if (!(chan = find_channel(card, c->arg & 0x0f)))
412 break;
413 chan->l3prot = (c->arg >> 8);
414 return 0;
415 }
416
417 return -EINVAL;
418}
419
420static int
421act2000_sendbuf(act2000_card *card, int channel, int ack, struct sk_buff *skb)
422{
423 struct sk_buff *xmit_skb;
424 int len;
425 act2000_chan *chan;
426 actcapi_msg *msg;
427
428 if (!(chan = find_channel(card, channel)))
429 return -1;
430 if (chan->fsm_state != ACT2000_STATE_ACTIVE)
431 return -1;
432 len = skb->len;
433 if ((chan->queued + len) >= ACT2000_MAX_QUEUED)
434 return 0;
435 if (!len)
436 return 0;
437 if (skb_headroom(skb) < 19) {
438 printk(KERN_WARNING "act2000_sendbuf: Headroom only %d\n",
439 skb_headroom(skb));
440 xmit_skb = alloc_skb(len + 19, GFP_ATOMIC);
441 if (!xmit_skb) {
442 printk(KERN_WARNING "act2000_sendbuf: Out of memory\n");
443 return 0;
444 }
445 skb_reserve(xmit_skb, 19);
446 skb_copy_from_linear_data(skb, skb_put(xmit_skb, len), len);
447 } else {
448 xmit_skb = skb_clone(skb, GFP_ATOMIC);
449 if (!xmit_skb) {
450 printk(KERN_WARNING "act2000_sendbuf: Out of memory\n");
451 return 0;
452 }
453 }
454 dev_kfree_skb(skb);
455 msg = (actcapi_msg *)skb_push(xmit_skb, 19);
456 msg->hdr.len = 19 + len;
457 msg->hdr.applicationID = 1;
458 msg->hdr.cmd.cmd = 0x86;
459 msg->hdr.cmd.subcmd = 0x00;
460 msg->hdr.msgnum = actcapi_nextsmsg(card);
461 msg->msg.data_b3_req.datalen = len;
462 msg->msg.data_b3_req.blocknr = (msg->hdr.msgnum & 0xff);
463 msg->msg.data_b3_req.fakencci = MAKE_NCCI(chan->plci, 0, chan->ncci);
464 msg->msg.data_b3_req.flags = ack; /* Will be set to 0 on actual sending */
465 actcapi_debug_msg(xmit_skb, 1);
466 chan->queued += len;
467 skb_queue_tail(&card->sndq, xmit_skb);
468 act2000_schedule_tx(card);
469 return len;
470}
471
472
473/* Read the Status-replies from the Interface */
474static int
475act2000_readstatus(u_char __user *buf, int len, act2000_card *card)
476{
477 int count;
478 u_char __user *p;
479
480 for (p = buf, count = 0; count < len; p++, count++) {
481 if (card->status_buf_read == card->status_buf_write)
482 return count;
483 put_user(*card->status_buf_read++, p);
484 if (card->status_buf_read > card->status_buf_end)
485 card->status_buf_read = card->status_buf;
486 }
487 return count;
488}
489
490/*
491 * Find card with given driverId
492 */
493static inline act2000_card *
494act2000_findcard(int driverid)
495{
496 act2000_card *p = cards;
497
498 while (p) {
499 if (p->myid == driverid)
500 return p;
501 p = p->next;
502 }
503 return (act2000_card *) 0;
504}
505
506/*
507 * Wrapper functions for interface to linklevel
508 */
509static int
510if_command(isdn_ctrl *c)
511{
512 act2000_card *card = act2000_findcard(c->driver);
513
514 if (card)
515 return act2000_command(card, c);
516 printk(KERN_ERR
517 "act2000: if_command %d called with invalid driverId %d!\n",
518 c->command, c->driver);
519 return -ENODEV;
520}
521
522static int
523if_writecmd(const u_char __user *buf, int len, int id, int channel)
524{
525 act2000_card *card = act2000_findcard(id);
526
527 if (card) {
528 if (!(card->flags & ACT2000_FLAGS_RUNNING))
529 return -ENODEV;
530 return len;
531 }
532 printk(KERN_ERR
533 "act2000: if_writecmd called with invalid driverId!\n");
534 return -ENODEV;
535}
536
537static int
538if_readstatus(u_char __user *buf, int len, int id, int channel)
539{
540 act2000_card *card = act2000_findcard(id);
541
542 if (card) {
543 if (!(card->flags & ACT2000_FLAGS_RUNNING))
544 return -ENODEV;
545 return act2000_readstatus(buf, len, card);
546 }
547 printk(KERN_ERR
548 "act2000: if_readstatus called with invalid driverId!\n");
549 return -ENODEV;
550}
551
552static int
553if_sendbuf(int id, int channel, int ack, struct sk_buff *skb)
554{
555 act2000_card *card = act2000_findcard(id);
556
557 if (card) {
558 if (!(card->flags & ACT2000_FLAGS_RUNNING))
559 return -ENODEV;
560 return act2000_sendbuf(card, channel, ack, skb);
561 }
562 printk(KERN_ERR
563 "act2000: if_sendbuf called with invalid driverId!\n");
564 return -ENODEV;
565}
566
567
568/*
569 * Allocate a new card-struct, initialize it
570 * link it into cards-list.
571 */
572static void
573act2000_alloccard(int bus, int port, int irq, char *id)
574{
575 int i;
576 act2000_card *card;
577
578 if (!(card = kzalloc(sizeof(act2000_card), GFP_KERNEL))) {
579 printk(KERN_WARNING
580 "act2000: (%s) Could not allocate card-struct.\n", id);
581 return;
582 }
583 spin_lock_init(&card->lock);
584 spin_lock_init(&card->mnlock);
585 skb_queue_head_init(&card->sndq);
586 skb_queue_head_init(&card->rcvq);
587 skb_queue_head_init(&card->ackq);
588 INIT_WORK(&card->snd_tq, act2000_transmit);
589 INIT_WORK(&card->rcv_tq, actcapi_dispatch);
590 INIT_WORK(&card->poll_tq, act2000_receive);
591 init_timer(&card->ptimer);
592 card->interface.owner = THIS_MODULE;
593 card->interface.channels = ACT2000_BCH;
594 card->interface.maxbufsize = 4000;
595 card->interface.command = if_command;
596 card->interface.writebuf_skb = if_sendbuf;
597 card->interface.writecmd = if_writecmd;
598 card->interface.readstat = if_readstatus;
599 card->interface.features =
600 ISDN_FEATURE_L2_X75I |
601 ISDN_FEATURE_L2_HDLC |
602 ISDN_FEATURE_L3_TRANS |
603 ISDN_FEATURE_P_UNKNOWN;
604 card->interface.hl_hdrlen = 20;
605 card->ptype = ISDN_PTYPE_EURO;
606 strlcpy(card->interface.id, id, sizeof(card->interface.id));
607 for (i = 0; i < ACT2000_BCH; i++) {
608 card->bch[i].plci = 0x8000;
609 card->bch[i].ncci = 0x8000;
610 card->bch[i].l2prot = ISDN_PROTO_L2_X75I;
611 card->bch[i].l3prot = ISDN_PROTO_L3_TRANS;
612 }
613 card->myid = -1;
614 card->bus = bus;
615 card->port = port;
616 card->irq = irq;
617 card->next = cards;
618 cards = card;
619}
620
621/*
622 * register card at linklevel
623 */
624static int
625act2000_registercard(act2000_card *card)
626{
627 switch (card->bus) {
628 case ACT2000_BUS_ISA:
629 break;
630 case ACT2000_BUS_MCA:
631 case ACT2000_BUS_PCMCIA:
632 default:
633 printk(KERN_WARNING
634 "act2000: Illegal BUS type %d\n",
635 card->bus);
636 return -1;
637 }
638 if (!register_isdn(&card->interface)) {
639 printk(KERN_WARNING
640 "act2000: Unable to register %s\n",
641 card->interface.id);
642 return -1;
643 }
644 card->myid = card->interface.channels;
645 sprintf(card->regname, "act2000-isdn (%s)", card->interface.id);
646 return 0;
647}
648
649static void
650unregister_card(act2000_card *card)
651{
652 isdn_ctrl cmd;
653
654 cmd.command = ISDN_STAT_UNLOAD;
655 cmd.driver = card->myid;
656 card->interface.statcallb(&cmd);
657 switch (card->bus) {
658 case ACT2000_BUS_ISA:
659 act2000_isa_release(card);
660 break;
661 case ACT2000_BUS_MCA:
662 case ACT2000_BUS_PCMCIA:
663 default:
664 printk(KERN_WARNING
665 "act2000: Invalid BUS type %d\n",
666 card->bus);
667 break;
668 }
669}
670
671static int
672act2000_addcard(int bus, int port, int irq, char *id)
673{
674 act2000_card *p;
675 act2000_card *q = NULL;
676 int initialized;
677 int added = 0;
678 int failed = 0;
679 int i;
680
681 if (!bus)
682 bus = ACT2000_BUS_ISA;
683 if (port != -1) {
684 /* Port defined, do fixed setup */
685 act2000_alloccard(bus, port, irq, id);
686 } else {
687 /* No port defined, perform autoprobing.
688 * This may result in more than one card detected.
689 */
690 switch (bus) {
691 case ACT2000_BUS_ISA:
692 for (i = 0; i < ARRAY_SIZE(act2000_isa_ports); i++)
693 if (act2000_isa_detect(act2000_isa_ports[i])) {
694 printk(KERN_INFO "act2000: Detected "
695 "ISA card at port 0x%x\n",
696 act2000_isa_ports[i]);
697 act2000_alloccard(bus,
698 act2000_isa_ports[i], irq, id);
699 }
700 break;
701 case ACT2000_BUS_MCA:
702 case ACT2000_BUS_PCMCIA:
703 default:
704 printk(KERN_WARNING
705 "act2000: addcard: Invalid BUS type %d\n", bus);
706 }
707 }
708 if (!cards)
709 return 1;
710 p = cards;
711 while (p) {
712 initialized = 0;
713 if (!p->interface.statcallb) {
714 /* Not yet registered.
715 * Try to register and activate it.
716 */
717 added++;
718 switch (p->bus) {
719 case ACT2000_BUS_ISA:
720 if (act2000_isa_detect(p->port)) {
721 if (act2000_registercard(p))
722 break;
723 if (act2000_isa_config_port(p, p->port)) {
724 printk(KERN_WARNING
725 "act2000: Could not request port 0x%04x\n",
726 p->port);
727 unregister_card(p);
728 p->interface.statcallb = NULL;
729 break;
730 }
731 if (act2000_isa_config_irq(p, p->irq)) {
732 printk(KERN_INFO
733 "act2000: No IRQ available, fallback to polling\n");
734 /* Fall back to polled operation */
735 p->irq = 0;
736 }
737 printk(KERN_INFO
738 "act2000: ISA"
739 "-type card at port "
740 "0x%04x ",
741 p->port);
742 if (p->irq)
743 printk("irq %d\n", p->irq);
744 else
745 printk("polled\n");
746 initialized = 1;
747 }
748 break;
749 case ACT2000_BUS_MCA:
750 case ACT2000_BUS_PCMCIA:
751 default:
752 printk(KERN_WARNING
753 "act2000: addcard: Invalid BUS type %d\n",
754 p->bus);
755 }
756 } else
757 /* Card already initialized */
758 initialized = 1;
759 if (initialized) {
760 /* Init OK, next card ... */
761 q = p;
762 p = p->next;
763 } else {
764 /* Init failed, remove card from list, free memory */
765 printk(KERN_WARNING
766 "act2000: Initialization of %s failed\n",
767 p->interface.id);
768 if (q) {
769 q->next = p->next;
770 kfree(p);
771 p = q->next;
772 } else {
773 cards = p->next;
774 kfree(p);
775 p = cards;
776 }
777 failed++;
778 }
779 }
780 return added - failed;
781}
782
783#define DRIVERNAME "IBM Active 2000 ISDN driver"
784
785static int __init act2000_init(void)
786{
787 printk(KERN_INFO "%s\n", DRIVERNAME);
788 if (!cards)
789 act2000_addcard(act_bus, act_port, act_irq, act_id);
790 if (!cards)
791 printk(KERN_INFO "act2000: No cards defined yet\n");
792 return 0;
793}
794
795static void __exit act2000_exit(void)
796{
797 act2000_card *card = cards;
798 act2000_card *last;
799
800 while (card) {
801 unregister_card(card);
802 del_timer_sync(&card->ptimer);
803 card = card->next;
804 }
805 card = cards;
806 while (card) {
807 last = card;
808 card = card->next;
809 act2000_clear_msn(last);
810 kfree(last);
811 }
812 printk(KERN_INFO "%s unloaded\n", DRIVERNAME);
813}
814
815module_init(act2000_init);
816module_exit(act2000_exit);
diff --git a/drivers/staging/i4l/icn/Kconfig b/drivers/staging/i4l/icn/Kconfig
deleted file mode 100644
index 4534f21a1852..000000000000
--- a/drivers/staging/i4l/icn/Kconfig
+++ /dev/null
@@ -1,12 +0,0 @@
1config ISDN_DRV_ICN
2 tristate "ICN 2B and 4B support"
3 depends on ISA
4 help
5 This enables support for two kinds of ISDN-cards made by a German
6 company called ICN. 2B is the standard version for a single ISDN
7 line with two B-channels, 4B supports two ISDN lines. For running
8 this card, additional firmware is necessary, which has to be
9 downloaded into the card using a utility which is distributed
10 separately. See <file:Documentation/isdn/README> and
11 <file:Documentation/isdn/README.icn> for more
12 information.
diff --git a/drivers/staging/i4l/icn/Makefile b/drivers/staging/i4l/icn/Makefile
deleted file mode 100644
index d9b476fcf384..000000000000
--- a/drivers/staging/i4l/icn/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
1# Makefile for the icn ISDN device driver
2
3# Each configuration option enables a list of files.
4
5obj-$(CONFIG_ISDN_DRV_ICN) += icn.o
diff --git a/drivers/staging/i4l/icn/icn.c b/drivers/staging/i4l/icn/icn.c
deleted file mode 100644
index 3750ba38adc5..000000000000
--- a/drivers/staging/i4l/icn/icn.c
+++ /dev/null
@@ -1,1696 +0,0 @@
1/* $Id: icn.c,v 1.65.6.8 2001/09/23 22:24:55 kai Exp $
2 *
3 * ISDN low-level module for the ICN active ISDN-Card.
4 *
5 * Copyright 1994,95,96 by Fritz Elfert (fritz@isdn4linux.de)
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
9 *
10 */
11
12#include "icn.h"
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/slab.h>
16#include <linux/sched.h>
17
18static int portbase = ICN_BASEADDR;
19static unsigned long membase = ICN_MEMADDR;
20static char *icn_id = "\0";
21static char *icn_id2 = "\0";
22
23MODULE_DESCRIPTION("ISDN4Linux: Driver for ICN active ISDN card");
24MODULE_AUTHOR("Fritz Elfert");
25MODULE_LICENSE("GPL");
26module_param(portbase, int, 0);
27MODULE_PARM_DESC(portbase, "Port address of first card");
28module_param(membase, ulong, 0);
29MODULE_PARM_DESC(membase, "Shared memory address of all cards");
30module_param(icn_id, charp, 0);
31MODULE_PARM_DESC(icn_id, "ID-String of first card");
32module_param(icn_id2, charp, 0);
33MODULE_PARM_DESC(icn_id2, "ID-String of first card, second S0 (4B only)");
34
35/*
36 * Verbose bootcode- and protocol-downloading.
37 */
38#undef BOOT_DEBUG
39
40/*
41 * Verbose Shmem-Mapping.
42 */
43#undef MAP_DEBUG
44
45static char
46*revision = "$Revision: 1.65.6.8 $";
47
48static int icn_addcard(int, char *, char *);
49
50/*
51 * Free send-queue completely.
52 * Parameter:
53 * card = pointer to card struct
54 * channel = channel number
55 */
56static void
57icn_free_queue(icn_card *card, int channel)
58{
59 struct sk_buff_head *queue = &card->spqueue[channel];
60 struct sk_buff *skb;
61
62 skb_queue_purge(queue);
63 card->xlen[channel] = 0;
64 card->sndcount[channel] = 0;
65 skb = card->xskb[channel];
66 if (skb) {
67 card->xskb[channel] = NULL;
68 dev_kfree_skb(skb);
69 }
70}
71
72/* Put a value into a shift-register, highest bit first.
73 * Parameters:
74 * port = port for output (bit 0 is significant)
75 * val = value to be output
76 * firstbit = Bit-Number of highest bit
77 * bitcount = Number of bits to output
78 */
79static inline void
80icn_shiftout(unsigned short port,
81 unsigned long val,
82 int firstbit,
83 int bitcount)
84{
85 register u_char s;
86 register u_char c;
87
88 for (s = firstbit, c = bitcount; c > 0; s--, c--)
89 OUTB_P((u_char)((val >> s) & 1) ? 0xff : 0, port);
90}
91
92/*
93 * disable a cards shared memory
94 */
95static inline void
96icn_disable_ram(icn_card *card)
97{
98 OUTB_P(0, ICN_MAPRAM);
99}
100
101/*
102 * enable a cards shared memory
103 */
104static inline void
105icn_enable_ram(icn_card *card)
106{
107 OUTB_P(0xff, ICN_MAPRAM);
108}
109
110/*
111 * Map a cards channel0 (Bank0/Bank8) or channel1 (Bank4/Bank12)
112 *
113 * must called with holding the devlock
114 */
115static inline void
116icn_map_channel(icn_card *card, int channel)
117{
118#ifdef MAP_DEBUG
119 printk(KERN_DEBUG "icn_map_channel %d %d\n", dev.channel, channel);
120#endif
121 if ((channel == dev.channel) && (card == dev.mcard))
122 return;
123 if (dev.mcard)
124 icn_disable_ram(dev.mcard);
125 icn_shiftout(ICN_BANK, chan2bank[channel], 3, 4); /* Select Bank */
126 icn_enable_ram(card);
127 dev.mcard = card;
128 dev.channel = channel;
129#ifdef MAP_DEBUG
130 printk(KERN_DEBUG "icn_map_channel done\n");
131#endif
132}
133
134/*
135 * Lock a cards channel.
136 * Return 0 if requested card/channel is unmapped (failure).
137 * Return 1 on success.
138 *
139 * must called with holding the devlock
140 */
141static inline int
142icn_lock_channel(icn_card *card, int channel)
143{
144 register int retval;
145
146#ifdef MAP_DEBUG
147 printk(KERN_DEBUG "icn_lock_channel %d\n", channel);
148#endif
149 if ((dev.channel == channel) && (card == dev.mcard)) {
150 dev.chanlock++;
151 retval = 1;
152#ifdef MAP_DEBUG
153 printk(KERN_DEBUG "icn_lock_channel %d OK\n", channel);
154#endif
155 } else {
156 retval = 0;
157#ifdef MAP_DEBUG
158 printk(KERN_DEBUG "icn_lock_channel %d FAILED, dc=%d\n", channel, dev.channel);
159#endif
160 }
161 return retval;
162}
163
164/*
165 * Release current card/channel lock
166 *
167 * must called with holding the devlock
168 */
169static inline void
170__icn_release_channel(void)
171{
172#ifdef MAP_DEBUG
173 printk(KERN_DEBUG "icn_release_channel l=%d\n", dev.chanlock);
174#endif
175 if (dev.chanlock > 0)
176 dev.chanlock--;
177}
178
179/*
180 * Release current card/channel lock
181 */
182static inline void
183icn_release_channel(void)
184{
185 ulong flags;
186
187 spin_lock_irqsave(&dev.devlock, flags);
188 __icn_release_channel();
189 spin_unlock_irqrestore(&dev.devlock, flags);
190}
191
192/*
193 * Try to map and lock a cards channel.
194 * Return 1 on success, 0 on failure.
195 */
196static inline int
197icn_trymaplock_channel(icn_card *card, int channel)
198{
199 ulong flags;
200
201#ifdef MAP_DEBUG
202 printk(KERN_DEBUG "trymaplock c=%d dc=%d l=%d\n", channel, dev.channel,
203 dev.chanlock);
204#endif
205 spin_lock_irqsave(&dev.devlock, flags);
206 if ((!dev.chanlock) ||
207 ((dev.channel == channel) && (dev.mcard == card))) {
208 dev.chanlock++;
209 icn_map_channel(card, channel);
210 spin_unlock_irqrestore(&dev.devlock, flags);
211#ifdef MAP_DEBUG
212 printk(KERN_DEBUG "trymaplock %d OK\n", channel);
213#endif
214 return 1;
215 }
216 spin_unlock_irqrestore(&dev.devlock, flags);
217#ifdef MAP_DEBUG
218 printk(KERN_DEBUG "trymaplock %d FAILED\n", channel);
219#endif
220 return 0;
221}
222
223/*
224 * Release current card/channel lock,
225 * then map same or other channel without locking.
226 */
227static inline void
228icn_maprelease_channel(icn_card *card, int channel)
229{
230 ulong flags;
231
232#ifdef MAP_DEBUG
233 printk(KERN_DEBUG "map_release c=%d l=%d\n", channel, dev.chanlock);
234#endif
235 spin_lock_irqsave(&dev.devlock, flags);
236 if (dev.chanlock > 0)
237 dev.chanlock--;
238 if (!dev.chanlock)
239 icn_map_channel(card, channel);
240 spin_unlock_irqrestore(&dev.devlock, flags);
241}
242
243/* Get Data from the B-Channel, assemble fragmented packets and put them
244 * into receive-queue. Wake up any B-Channel-reading processes.
245 * This routine is called via timer-callback from icn_pollbchan().
246 */
247
248static void
249icn_pollbchan_receive(int channel, icn_card *card)
250{
251 int mch = channel + ((card->secondhalf) ? 2 : 0);
252 int eflag;
253 int cnt;
254 struct sk_buff *skb;
255
256 if (icn_trymaplock_channel(card, mch)) {
257 while (rbavl) {
258 cnt = readb(&rbuf_l);
259 if ((card->rcvidx[channel] + cnt) > 4000) {
260 printk(KERN_WARNING
261 "icn: (%s) bogus packet on ch%d, dropping.\n",
262 CID,
263 channel + 1);
264 card->rcvidx[channel] = 0;
265 eflag = 0;
266 } else {
267 memcpy_fromio(&card->rcvbuf[channel][card->rcvidx[channel]],
268 &rbuf_d, cnt);
269 card->rcvidx[channel] += cnt;
270 eflag = readb(&rbuf_f);
271 }
272 rbnext;
273 icn_maprelease_channel(card, mch & 2);
274 if (!eflag) {
275 cnt = card->rcvidx[channel];
276 if (cnt) {
277 skb = dev_alloc_skb(cnt);
278 if (!skb) {
279 printk(KERN_WARNING "icn: receive out of memory\n");
280 break;
281 }
282 memcpy(skb_put(skb, cnt), card->rcvbuf[channel], cnt);
283 card->rcvidx[channel] = 0;
284 card->interface.rcvcallb_skb(card->myid, channel, skb);
285 }
286 }
287 if (!icn_trymaplock_channel(card, mch))
288 break;
289 }
290 icn_maprelease_channel(card, mch & 2);
291 }
292}
293
294/* Send data-packet to B-Channel, split it up into fragments of
295 * ICN_FRAGSIZE length. If last fragment is sent out, signal
296 * success to upper layers via statcallb with ISDN_STAT_BSENT argument.
297 * This routine is called via timer-callback from icn_pollbchan() or
298 * directly from icn_sendbuf().
299 */
300
301static void
302icn_pollbchan_send(int channel, icn_card *card)
303{
304 int mch = channel + ((card->secondhalf) ? 2 : 0);
305 int cnt;
306 unsigned long flags;
307 struct sk_buff *skb;
308 isdn_ctrl cmd;
309
310 if (!(card->sndcount[channel] || card->xskb[channel] ||
311 !skb_queue_empty(&card->spqueue[channel])))
312 return;
313 if (icn_trymaplock_channel(card, mch)) {
314 while (sbfree &&
315 (card->sndcount[channel] ||
316 !skb_queue_empty(&card->spqueue[channel]) ||
317 card->xskb[channel])) {
318 spin_lock_irqsave(&card->lock, flags);
319 if (card->xmit_lock[channel]) {
320 spin_unlock_irqrestore(&card->lock, flags);
321 break;
322 }
323 card->xmit_lock[channel]++;
324 spin_unlock_irqrestore(&card->lock, flags);
325 skb = card->xskb[channel];
326 if (!skb) {
327 skb = skb_dequeue(&card->spqueue[channel]);
328 if (skb) {
329 /* Pop ACK-flag off skb.
330 * Store length to xlen.
331 */
332 if (*(skb_pull(skb, 1)))
333 card->xlen[channel] = skb->len;
334 else
335 card->xlen[channel] = 0;
336 }
337 }
338 if (!skb)
339 break;
340 if (skb->len > ICN_FRAGSIZE) {
341 writeb(0xff, &sbuf_f);
342 cnt = ICN_FRAGSIZE;
343 } else {
344 writeb(0x0, &sbuf_f);
345 cnt = skb->len;
346 }
347 writeb(cnt, &sbuf_l);
348 memcpy_toio(&sbuf_d, skb->data, cnt);
349 skb_pull(skb, cnt);
350 sbnext; /* switch to next buffer */
351 icn_maprelease_channel(card, mch & 2);
352 spin_lock_irqsave(&card->lock, flags);
353 card->sndcount[channel] -= cnt;
354 if (!skb->len) {
355 if (card->xskb[channel])
356 card->xskb[channel] = NULL;
357 card->xmit_lock[channel] = 0;
358 spin_unlock_irqrestore(&card->lock, flags);
359 dev_kfree_skb(skb);
360 if (card->xlen[channel]) {
361 cmd.command = ISDN_STAT_BSENT;
362 cmd.driver = card->myid;
363 cmd.arg = channel;
364 cmd.parm.length = card->xlen[channel];
365 card->interface.statcallb(&cmd);
366 }
367 } else {
368 card->xskb[channel] = skb;
369 card->xmit_lock[channel] = 0;
370 spin_unlock_irqrestore(&card->lock, flags);
371 }
372 if (!icn_trymaplock_channel(card, mch))
373 break;
374 }
375 icn_maprelease_channel(card, mch & 2);
376 }
377}
378
379/* Send/Receive Data to/from the B-Channel.
380 * This routine is called via timer-callback.
381 * It schedules itself while any B-Channel is open.
382 */
383
384static void
385icn_pollbchan(unsigned long data)
386{
387 icn_card *card = (icn_card *)data;
388 unsigned long flags;
389
390 if (card->flags & ICN_FLAGS_B1ACTIVE) {
391 icn_pollbchan_receive(0, card);
392 icn_pollbchan_send(0, card);
393 }
394 if (card->flags & ICN_FLAGS_B2ACTIVE) {
395 icn_pollbchan_receive(1, card);
396 icn_pollbchan_send(1, card);
397 }
398 if (card->flags & (ICN_FLAGS_B1ACTIVE | ICN_FLAGS_B2ACTIVE)) {
399 /* schedule b-channel polling again */
400 spin_lock_irqsave(&card->lock, flags);
401 mod_timer(&card->rb_timer, jiffies + ICN_TIMER_BCREAD);
402 card->flags |= ICN_FLAGS_RBTIMER;
403 spin_unlock_irqrestore(&card->lock, flags);
404 } else
405 card->flags &= ~ICN_FLAGS_RBTIMER;
406}
407
408typedef struct icn_stat {
409 char *statstr;
410 int command;
411 int action;
412} icn_stat;
413/* *INDENT-OFF* */
414static icn_stat icn_stat_table[] = {
415 {"BCON_", ISDN_STAT_BCONN, 1}, /* B-Channel connected */
416 {"BDIS_", ISDN_STAT_BHUP, 2}, /* B-Channel disconnected */
417 /*
418 ** add d-channel connect and disconnect support to link-level
419 */
420 {"DCON_", ISDN_STAT_DCONN, 10}, /* D-Channel connected */
421 {"DDIS_", ISDN_STAT_DHUP, 11}, /* D-Channel disconnected */
422 {"DCAL_I", ISDN_STAT_ICALL, 3}, /* Incoming call dialup-line */
423 {"DSCA_I", ISDN_STAT_ICALL, 3}, /* Incoming call 1TR6-SPV */
424 {"FCALL", ISDN_STAT_ICALL, 4}, /* Leased line connection up */
425 {"CIF", ISDN_STAT_CINF, 5}, /* Charge-info, 1TR6-type */
426 {"AOC", ISDN_STAT_CINF, 6}, /* Charge-info, DSS1-type */
427 {"CAU", ISDN_STAT_CAUSE, 7}, /* Cause code */
428 {"TEI OK", ISDN_STAT_RUN, 0}, /* Card connected to wallplug */
429 {"E_L1: ACT FAIL", ISDN_STAT_BHUP, 8}, /* Layer-1 activation failed */
430 {"E_L2: DATA LIN", ISDN_STAT_BHUP, 8}, /* Layer-2 data link lost */
431 {"E_L1: ACTIVATION FAILED",
432 ISDN_STAT_BHUP, 8}, /* Layer-1 activation failed */
433 {NULL, 0, -1}
434};
435/* *INDENT-ON* */
436
437
438/*
439 * Check Statusqueue-Pointer from isdn-cards.
440 * If there are new status-replies from the interface, check
441 * them against B-Channel-connects/disconnects and set flags accordingly.
442 * Wake-Up any processes, who are reading the status-device.
443 * If there are B-Channels open, initiate a timer-callback to
444 * icn_pollbchan().
445 * This routine is called periodically via timer.
446 */
447
448static void
449icn_parse_status(u_char *status, int channel, icn_card *card)
450{
451 icn_stat *s = icn_stat_table;
452 int action = -1;
453 unsigned long flags;
454 isdn_ctrl cmd;
455
456 while (s->statstr) {
457 if (!strncmp(status, s->statstr, strlen(s->statstr))) {
458 cmd.command = s->command;
459 action = s->action;
460 break;
461 }
462 s++;
463 }
464 if (action == -1)
465 return;
466 cmd.driver = card->myid;
467 cmd.arg = channel;
468 switch (action) {
469 case 11:
470 spin_lock_irqsave(&card->lock, flags);
471 icn_free_queue(card, channel);
472 card->rcvidx[channel] = 0;
473
474 if (card->flags &
475 ((channel) ? ICN_FLAGS_B2ACTIVE : ICN_FLAGS_B1ACTIVE)) {
476 isdn_ctrl ncmd;
477
478 card->flags &= ~((channel) ?
479 ICN_FLAGS_B2ACTIVE : ICN_FLAGS_B1ACTIVE);
480
481 memset(&ncmd, 0, sizeof(ncmd));
482
483 ncmd.driver = card->myid;
484 ncmd.arg = channel;
485 ncmd.command = ISDN_STAT_BHUP;
486 spin_unlock_irqrestore(&card->lock, flags);
487 card->interface.statcallb(&cmd);
488 } else
489 spin_unlock_irqrestore(&card->lock, flags);
490 break;
491 case 1:
492 spin_lock_irqsave(&card->lock, flags);
493 icn_free_queue(card, channel);
494 card->flags |= (channel) ?
495 ICN_FLAGS_B2ACTIVE : ICN_FLAGS_B1ACTIVE;
496 spin_unlock_irqrestore(&card->lock, flags);
497 break;
498 case 2:
499 spin_lock_irqsave(&card->lock, flags);
500 card->flags &= ~((channel) ?
501 ICN_FLAGS_B2ACTIVE : ICN_FLAGS_B1ACTIVE);
502 icn_free_queue(card, channel);
503 card->rcvidx[channel] = 0;
504 spin_unlock_irqrestore(&card->lock, flags);
505 break;
506 case 3:
507 {
508 char *t = status + 6;
509 char *s = strchr(t, ',');
510
511 *s++ = '\0';
512 strlcpy(cmd.parm.setup.phone, t,
513 sizeof(cmd.parm.setup.phone));
514 s = strchr(t = s, ',');
515 *s++ = '\0';
516 if (!strlen(t))
517 cmd.parm.setup.si1 = 0;
518 else
519 cmd.parm.setup.si1 =
520 simple_strtoul(t, NULL, 10);
521 s = strchr(t = s, ',');
522 *s++ = '\0';
523 if (!strlen(t))
524 cmd.parm.setup.si2 = 0;
525 else
526 cmd.parm.setup.si2 =
527 simple_strtoul(t, NULL, 10);
528 strlcpy(cmd.parm.setup.eazmsn, s,
529 sizeof(cmd.parm.setup.eazmsn));
530 }
531 cmd.parm.setup.plan = 0;
532 cmd.parm.setup.screen = 0;
533 break;
534 case 4:
535 sprintf(cmd.parm.setup.phone, "LEASED%d", card->myid);
536 sprintf(cmd.parm.setup.eazmsn, "%d", channel + 1);
537 cmd.parm.setup.si1 = 7;
538 cmd.parm.setup.si2 = 0;
539 cmd.parm.setup.plan = 0;
540 cmd.parm.setup.screen = 0;
541 break;
542 case 5:
543 strlcpy(cmd.parm.num, status + 3, sizeof(cmd.parm.num));
544 break;
545 case 6:
546 snprintf(cmd.parm.num, sizeof(cmd.parm.num), "%d",
547 (int)simple_strtoul(status + 7, NULL, 16));
548 break;
549 case 7:
550 status += 3;
551 if (strlen(status) == 4)
552 snprintf(cmd.parm.num, sizeof(cmd.parm.num), "%s%c%c",
553 status + 2, *status, *(status + 1));
554 else
555 strlcpy(cmd.parm.num, status + 1, sizeof(cmd.parm.num));
556 break;
557 case 8:
558 spin_lock_irqsave(&card->lock, flags);
559 card->flags &= ~ICN_FLAGS_B1ACTIVE;
560 icn_free_queue(card, 0);
561 card->rcvidx[0] = 0;
562 spin_unlock_irqrestore(&card->lock, flags);
563 cmd.arg = 0;
564 cmd.driver = card->myid;
565 card->interface.statcallb(&cmd);
566 cmd.command = ISDN_STAT_DHUP;
567 cmd.arg = 0;
568 cmd.driver = card->myid;
569 card->interface.statcallb(&cmd);
570 cmd.command = ISDN_STAT_BHUP;
571 spin_lock_irqsave(&card->lock, flags);
572 card->flags &= ~ICN_FLAGS_B2ACTIVE;
573 icn_free_queue(card, 1);
574 card->rcvidx[1] = 0;
575 spin_unlock_irqrestore(&card->lock, flags);
576 cmd.arg = 1;
577 cmd.driver = card->myid;
578 card->interface.statcallb(&cmd);
579 cmd.command = ISDN_STAT_DHUP;
580 cmd.arg = 1;
581 cmd.driver = card->myid;
582 break;
583 }
584 card->interface.statcallb(&cmd);
585 return;
586}
587
588static void
589icn_putmsg(icn_card *card, unsigned char c)
590{
591 ulong flags;
592
593 spin_lock_irqsave(&card->lock, flags);
594 *card->msg_buf_write++ = (c == 0xff) ? '\n' : c;
595 if (card->msg_buf_write == card->msg_buf_read) {
596 if (++card->msg_buf_read > card->msg_buf_end)
597 card->msg_buf_read = card->msg_buf;
598 }
599 if (card->msg_buf_write > card->msg_buf_end)
600 card->msg_buf_write = card->msg_buf;
601 spin_unlock_irqrestore(&card->lock, flags);
602}
603
604static void
605icn_polldchan(unsigned long data)
606{
607 icn_card *card = (icn_card *)data;
608 int mch = card->secondhalf ? 2 : 0;
609 int avail = 0;
610 int left;
611 u_char c;
612 int ch;
613 unsigned long flags;
614 int i;
615 u_char *p;
616 isdn_ctrl cmd;
617
618 if (icn_trymaplock_channel(card, mch)) {
619 avail = msg_avail;
620 for (left = avail, i = readb(&msg_o); left > 0; i++, left--) {
621 c = readb(&dev.shmem->comm_buffers.iopc_buf[i & 0xff]);
622 icn_putmsg(card, c);
623 if (c == 0xff) {
624 card->imsg[card->iptr] = 0;
625 card->iptr = 0;
626 if (card->imsg[0] == '0' && card->imsg[1] >= '0' &&
627 card->imsg[1] <= '2' && card->imsg[2] == ';') {
628 ch = (card->imsg[1] - '0') - 1;
629 p = &card->imsg[3];
630 icn_parse_status(p, ch, card);
631 } else {
632 p = card->imsg;
633 if (!strncmp(p, "DRV1.", 5)) {
634 u_char vstr[10];
635 u_char *q = vstr;
636
637 printk(KERN_INFO "icn: (%s) %s\n", CID, p);
638 if (!strncmp(p + 7, "TC", 2)) {
639 card->ptype = ISDN_PTYPE_1TR6;
640 card->interface.features |= ISDN_FEATURE_P_1TR6;
641 printk(KERN_INFO
642 "icn: (%s) 1TR6-Protocol loaded and running\n", CID);
643 }
644 if (!strncmp(p + 7, "EC", 2)) {
645 card->ptype = ISDN_PTYPE_EURO;
646 card->interface.features |= ISDN_FEATURE_P_EURO;
647 printk(KERN_INFO
648 "icn: (%s) Euro-Protocol loaded and running\n", CID);
649 }
650 p = strstr(card->imsg, "BRV") + 3;
651 while (*p) {
652 if (*p >= '0' && *p <= '9')
653 *q++ = *p;
654 p++;
655 }
656 *q = '\0';
657 strcat(vstr, "000");
658 vstr[3] = '\0';
659 card->fw_rev = (int)simple_strtoul(vstr, NULL, 10);
660 continue;
661 }
662 }
663 } else {
664 card->imsg[card->iptr] = c;
665 if (card->iptr < 59)
666 card->iptr++;
667 }
668 }
669 writeb((readb(&msg_o) + avail) & 0xff, &msg_o);
670 icn_release_channel();
671 }
672 if (avail) {
673 cmd.command = ISDN_STAT_STAVAIL;
674 cmd.driver = card->myid;
675 cmd.arg = avail;
676 card->interface.statcallb(&cmd);
677 }
678 spin_lock_irqsave(&card->lock, flags);
679 if (card->flags & (ICN_FLAGS_B1ACTIVE | ICN_FLAGS_B2ACTIVE))
680 if (!(card->flags & ICN_FLAGS_RBTIMER)) {
681 /* schedule b-channel polling */
682 card->flags |= ICN_FLAGS_RBTIMER;
683 del_timer(&card->rb_timer);
684 card->rb_timer.function = icn_pollbchan;
685 card->rb_timer.data = (unsigned long)card;
686 card->rb_timer.expires = jiffies + ICN_TIMER_BCREAD;
687 add_timer(&card->rb_timer);
688 }
689 /* schedule again */
690 mod_timer(&card->st_timer, jiffies + ICN_TIMER_DCREAD);
691 spin_unlock_irqrestore(&card->lock, flags);
692}
693
694/* Append a packet to the transmit buffer-queue.
695 * Parameters:
696 * channel = Number of B-channel
697 * skb = pointer to sk_buff
698 * card = pointer to card-struct
699 * Return:
700 * Number of bytes transferred, -E??? on error
701 */
702
703static int
704icn_sendbuf(int channel, int ack, struct sk_buff *skb, icn_card *card)
705{
706 int len = skb->len;
707 unsigned long flags;
708 struct sk_buff *nskb;
709
710 if (len > 4000) {
711 printk(KERN_WARNING
712 "icn: Send packet too large\n");
713 return -EINVAL;
714 }
715 if (len) {
716 if (!(card->flags & (channel) ? ICN_FLAGS_B2ACTIVE : ICN_FLAGS_B1ACTIVE))
717 return 0;
718 if (card->sndcount[channel] > ICN_MAX_SQUEUE)
719 return 0;
720 /* TODO test headroom or use skb->nb to flag ACK */
721 nskb = skb_clone(skb, GFP_ATOMIC);
722 if (nskb) {
723 /* Push ACK flag as one
724 * byte in front of data.
725 */
726 *(skb_push(nskb, 1)) = ack ? 1 : 0;
727 skb_queue_tail(&card->spqueue[channel], nskb);
728 dev_kfree_skb(skb);
729 } else
730 len = 0;
731 spin_lock_irqsave(&card->lock, flags);
732 card->sndcount[channel] += len;
733 spin_unlock_irqrestore(&card->lock, flags);
734 }
735 return len;
736}
737
738/*
739 * Check card's status after starting the bootstrap loader.
740 * On entry, the card's shared memory has already to be mapped.
741 * Return:
742 * 0 on success (Boot loader ready)
743 * -EIO on failure (timeout)
744 */
745static int
746icn_check_loader(int cardnumber)
747{
748 int timer = 0;
749
750 while (1) {
751#ifdef BOOT_DEBUG
752 printk(KERN_DEBUG "Loader %d ?\n", cardnumber);
753#endif
754 if (readb(&dev.shmem->data_control.scns) ||
755 readb(&dev.shmem->data_control.scnr)) {
756 if (timer++ > 5) {
757 printk(KERN_WARNING
758 "icn: Boot-Loader %d timed out.\n",
759 cardnumber);
760 icn_release_channel();
761 return -EIO;
762 }
763#ifdef BOOT_DEBUG
764 printk(KERN_DEBUG "Loader %d TO?\n", cardnumber);
765#endif
766 msleep_interruptible(ICN_BOOT_TIMEOUT1);
767 } else {
768#ifdef BOOT_DEBUG
769 printk(KERN_DEBUG "Loader %d OK\n", cardnumber);
770#endif
771 icn_release_channel();
772 return 0;
773 }
774 }
775}
776
777/* Load the boot-code into the interface-card's memory and start it.
778 * Always called from user-process.
779 *
780 * Parameters:
781 * buffer = pointer to packet
782 * Return:
783 * 0 if successfully loaded
784 */
785
786#ifdef BOOT_DEBUG
787#define SLEEP(sec) { \
788 int slsec = sec; \
789 printk(KERN_DEBUG "SLEEP(%d)\n", slsec); \
790 while (slsec) { \
791 msleep_interruptible(1000); \
792 slsec--; \
793 } \
794 }
795#else
796#define SLEEP(sec)
797#endif
798
799static int
800icn_loadboot(u_char __user *buffer, icn_card *card)
801{
802 int ret;
803 u_char *codebuf;
804 unsigned long flags;
805
806#ifdef BOOT_DEBUG
807 printk(KERN_DEBUG "icn_loadboot called, buffaddr=%08lx\n", (ulong)buffer);
808#endif
809 codebuf = memdup_user(buffer, ICN_CODE_STAGE1);
810 if (IS_ERR(codebuf))
811 return PTR_ERR(codebuf);
812
813 if (!card->rvalid) {
814 if (!request_region(card->port, ICN_PORTLEN, card->regname)) {
815 printk(KERN_WARNING
816 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
817 CID,
818 card->port,
819 card->port + ICN_PORTLEN);
820 ret = -EBUSY;
821 goto out_kfree;
822 }
823 card->rvalid = 1;
824 if (card->doubleS0)
825 card->other->rvalid = 1;
826 }
827 if (!dev.mvalid) {
828 if (!request_mem_region(dev.memaddr, 0x4000, "icn-isdn (all cards)")) {
829 printk(KERN_WARNING
830 "icn: memory at 0x%08lx in use.\n", dev.memaddr);
831 ret = -EBUSY;
832 goto out_kfree;
833 }
834 dev.shmem = ioremap(dev.memaddr, 0x4000);
835 dev.mvalid = 1;
836 }
837 OUTB_P(0, ICN_RUN); /* Reset Controller */
838 OUTB_P(0, ICN_MAPRAM); /* Disable RAM */
839 icn_shiftout(ICN_CFG, 0x0f, 3, 4); /* Windowsize= 16k */
840 icn_shiftout(ICN_CFG, dev.memaddr, 23, 10); /* Set RAM-Addr. */
841#ifdef BOOT_DEBUG
842 printk(KERN_DEBUG "shmem=%08lx\n", dev.memaddr);
843#endif
844 SLEEP(1);
845#ifdef BOOT_DEBUG
846 printk(KERN_DEBUG "Map Bank 0\n");
847#endif
848 spin_lock_irqsave(&dev.devlock, flags);
849 icn_map_channel(card, 0); /* Select Bank 0 */
850 icn_lock_channel(card, 0); /* Lock Bank 0 */
851 spin_unlock_irqrestore(&dev.devlock, flags);
852 SLEEP(1);
853 memcpy_toio(dev.shmem, codebuf, ICN_CODE_STAGE1); /* Copy code */
854#ifdef BOOT_DEBUG
855 printk(KERN_DEBUG "Bootloader transferred\n");
856#endif
857 if (card->doubleS0) {
858 SLEEP(1);
859#ifdef BOOT_DEBUG
860 printk(KERN_DEBUG "Map Bank 8\n");
861#endif
862 spin_lock_irqsave(&dev.devlock, flags);
863 __icn_release_channel();
864 icn_map_channel(card, 2); /* Select Bank 8 */
865 icn_lock_channel(card, 2); /* Lock Bank 8 */
866 spin_unlock_irqrestore(&dev.devlock, flags);
867 SLEEP(1);
868 memcpy_toio(dev.shmem, codebuf, ICN_CODE_STAGE1); /* Copy code */
869#ifdef BOOT_DEBUG
870 printk(KERN_DEBUG "Bootloader transferred\n");
871#endif
872 }
873 SLEEP(1);
874 OUTB_P(0xff, ICN_RUN); /* Start Boot-Code */
875 ret = icn_check_loader(card->doubleS0 ? 2 : 1);
876 if (ret)
877 goto out_kfree;
878 if (!card->doubleS0) {
879 ret = 0;
880 goto out_kfree;
881 }
882 /* reached only, if we have a Double-S0-Card */
883#ifdef BOOT_DEBUG
884 printk(KERN_DEBUG "Map Bank 0\n");
885#endif
886 spin_lock_irqsave(&dev.devlock, flags);
887 icn_map_channel(card, 0); /* Select Bank 0 */
888 icn_lock_channel(card, 0); /* Lock Bank 0 */
889 spin_unlock_irqrestore(&dev.devlock, flags);
890 SLEEP(1);
891 ret = (icn_check_loader(1));
892
893out_kfree:
894 kfree(codebuf);
895 return ret;
896}
897
898static int
899icn_loadproto(u_char __user *buffer, icn_card *card)
900{
901 register u_char __user *p = buffer;
902 u_char codebuf[256];
903 uint left = ICN_CODE_STAGE2;
904 uint cnt;
905 int timer;
906 unsigned long flags;
907
908#ifdef BOOT_DEBUG
909 printk(KERN_DEBUG "icn_loadproto called\n");
910#endif
911 if (!access_ok(VERIFY_READ, buffer, ICN_CODE_STAGE2))
912 return -EFAULT;
913 timer = 0;
914 spin_lock_irqsave(&dev.devlock, flags);
915 if (card->secondhalf) {
916 icn_map_channel(card, 2);
917 icn_lock_channel(card, 2);
918 } else {
919 icn_map_channel(card, 0);
920 icn_lock_channel(card, 0);
921 }
922 spin_unlock_irqrestore(&dev.devlock, flags);
923 while (left) {
924 if (sbfree) { /* If there is a free buffer... */
925 cnt = left;
926 if (cnt > 256)
927 cnt = 256;
928 if (copy_from_user(codebuf, p, cnt)) {
929 icn_maprelease_channel(card, 0);
930 return -EFAULT;
931 }
932 memcpy_toio(&sbuf_l, codebuf, cnt); /* copy data */
933 sbnext; /* switch to next buffer */
934 p += cnt;
935 left -= cnt;
936 timer = 0;
937 } else {
938#ifdef BOOT_DEBUG
939 printk(KERN_DEBUG "boot 2 !sbfree\n");
940#endif
941 if (timer++ > 5) {
942 icn_maprelease_channel(card, 0);
943 return -EIO;
944 }
945 schedule_timeout_interruptible(10);
946 }
947 }
948 writeb(0x20, &sbuf_n);
949 timer = 0;
950 while (1) {
951 if (readb(&cmd_o) || readb(&cmd_i)) {
952#ifdef BOOT_DEBUG
953 printk(KERN_DEBUG "Proto?\n");
954#endif
955 if (timer++ > 5) {
956 printk(KERN_WARNING
957 "icn: (%s) Protocol timed out.\n",
958 CID);
959#ifdef BOOT_DEBUG
960 printk(KERN_DEBUG "Proto TO!\n");
961#endif
962 icn_maprelease_channel(card, 0);
963 return -EIO;
964 }
965#ifdef BOOT_DEBUG
966 printk(KERN_DEBUG "Proto TO?\n");
967#endif
968 msleep_interruptible(ICN_BOOT_TIMEOUT1);
969 } else {
970 if ((card->secondhalf) || (!card->doubleS0)) {
971#ifdef BOOT_DEBUG
972 printk(KERN_DEBUG "Proto loaded, install poll-timer %d\n",
973 card->secondhalf);
974#endif
975 spin_lock_irqsave(&card->lock, flags);
976 setup_timer(&card->st_timer, icn_polldchan,
977 (unsigned long)card);
978 mod_timer(&card->st_timer,
979 jiffies + ICN_TIMER_DCREAD);
980 card->flags |= ICN_FLAGS_RUNNING;
981 if (card->doubleS0) {
982 setup_timer(&card->other->st_timer,
983 icn_polldchan,
984 (unsigned long)card->other);
985 mod_timer(&card->other->st_timer,
986 jiffies + ICN_TIMER_DCREAD);
987 card->other->flags |= ICN_FLAGS_RUNNING;
988 }
989 spin_unlock_irqrestore(&card->lock, flags);
990 }
991 icn_maprelease_channel(card, 0);
992 return 0;
993 }
994 }
995}
996
997/* Read the Status-replies from the Interface */
998static int
999icn_readstatus(u_char __user *buf, int len, icn_card *card)
1000{
1001 int count;
1002 u_char __user *p;
1003
1004 for (p = buf, count = 0; count < len; p++, count++) {
1005 if (card->msg_buf_read == card->msg_buf_write)
1006 return count;
1007 if (put_user(*card->msg_buf_read++, p))
1008 return -EFAULT;
1009 if (card->msg_buf_read > card->msg_buf_end)
1010 card->msg_buf_read = card->msg_buf;
1011 }
1012 return count;
1013}
1014
1015/* Put command-strings into the command-queue of the Interface */
1016static int
1017icn_writecmd(const u_char __user *ubuf, const u_char *kbuf, int len,
1018 int user, icn_card *card)
1019{
1020 int mch = card->secondhalf ? 2 : 0;
1021 int pp;
1022 int i;
1023 int count;
1024 int xcount;
1025 int ocount;
1026 int loop;
1027 unsigned long flags;
1028 int lastmap_channel;
1029 struct icn_card *lastmap_card;
1030 u_char *p;
1031 isdn_ctrl cmd;
1032 u_char msg[0x100];
1033
1034 ocount = 1;
1035 xcount = loop = 0;
1036 while (len) {
1037 count = cmd_free;
1038 if (count > len)
1039 count = len;
1040 if (user) {
1041 if (copy_from_user(msg, ubuf, count))
1042 return -EFAULT;
1043 } else
1044 memcpy(msg, kbuf, count);
1045
1046 spin_lock_irqsave(&dev.devlock, flags);
1047 lastmap_card = dev.mcard;
1048 lastmap_channel = dev.channel;
1049 icn_map_channel(card, mch);
1050
1051 icn_putmsg(card, '>');
1052 for (p = msg, pp = readb(&cmd_i), i = count; i > 0; i--, p++, pp
1053 ++) {
1054 writeb((*p == '\n') ? 0xff : *p,
1055 &dev.shmem->comm_buffers.pcio_buf[pp & 0xff]);
1056 len--;
1057 xcount++;
1058 icn_putmsg(card, *p);
1059 if ((*p == '\n') && (i > 1)) {
1060 icn_putmsg(card, '>');
1061 ocount++;
1062 }
1063 ocount++;
1064 }
1065 writeb((readb(&cmd_i) + count) & 0xff, &cmd_i);
1066 if (lastmap_card)
1067 icn_map_channel(lastmap_card, lastmap_channel);
1068 spin_unlock_irqrestore(&dev.devlock, flags);
1069 if (len) {
1070 mdelay(1);
1071 if (loop++ > 20)
1072 break;
1073 } else
1074 break;
1075 }
1076 if (len && (!user))
1077 printk(KERN_WARNING "icn: writemsg incomplete!\n");
1078 cmd.command = ISDN_STAT_STAVAIL;
1079 cmd.driver = card->myid;
1080 cmd.arg = ocount;
1081 card->interface.statcallb(&cmd);
1082 return xcount;
1083}
1084
1085/*
1086 * Delete card's pending timers, send STOP to linklevel
1087 */
1088static void
1089icn_stopcard(icn_card *card)
1090{
1091 unsigned long flags;
1092 isdn_ctrl cmd;
1093
1094 spin_lock_irqsave(&card->lock, flags);
1095 if (card->flags & ICN_FLAGS_RUNNING) {
1096 card->flags &= ~ICN_FLAGS_RUNNING;
1097 del_timer(&card->st_timer);
1098 del_timer(&card->rb_timer);
1099 spin_unlock_irqrestore(&card->lock, flags);
1100 cmd.command = ISDN_STAT_STOP;
1101 cmd.driver = card->myid;
1102 card->interface.statcallb(&cmd);
1103 if (card->doubleS0)
1104 icn_stopcard(card->other);
1105 } else
1106 spin_unlock_irqrestore(&card->lock, flags);
1107}
1108
1109static void
1110icn_stopallcards(void)
1111{
1112 icn_card *p = cards;
1113
1114 while (p) {
1115 icn_stopcard(p);
1116 p = p->next;
1117 }
1118}
1119
1120/*
1121 * Unmap all cards, because some of them may be mapped accidetly during
1122 * autoprobing of some network drivers (SMC-driver?)
1123 */
1124static void
1125icn_disable_cards(void)
1126{
1127 icn_card *card = cards;
1128
1129 while (card) {
1130 if (!request_region(card->port, ICN_PORTLEN, "icn-isdn")) {
1131 printk(KERN_WARNING
1132 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
1133 CID,
1134 card->port,
1135 card->port + ICN_PORTLEN);
1136 } else {
1137 OUTB_P(0, ICN_RUN); /* Reset Controller */
1138 OUTB_P(0, ICN_MAPRAM); /* Disable RAM */
1139 release_region(card->port, ICN_PORTLEN);
1140 }
1141 card = card->next;
1142 }
1143}
1144
1145static int
1146icn_command(isdn_ctrl *c, icn_card *card)
1147{
1148 ulong a;
1149 ulong flags;
1150 int i;
1151 char cbuf[80];
1152 isdn_ctrl cmd;
1153 icn_cdef cdef;
1154 char __user *arg;
1155
1156 switch (c->command) {
1157 case ISDN_CMD_IOCTL:
1158 memcpy(&a, c->parm.num, sizeof(ulong));
1159 arg = (char __user *)a;
1160 switch (c->arg) {
1161 case ICN_IOCTL_SETMMIO:
1162 if (dev.memaddr != (a & 0x0ffc000)) {
1163 if (!request_mem_region(a & 0x0ffc000, 0x4000, "icn-isdn (all cards)")) {
1164 printk(KERN_WARNING
1165 "icn: memory at 0x%08lx in use.\n",
1166 a & 0x0ffc000);
1167 return -EINVAL;
1168 }
1169 release_mem_region(a & 0x0ffc000, 0x4000);
1170 icn_stopallcards();
1171 spin_lock_irqsave(&card->lock, flags);
1172 if (dev.mvalid) {
1173 iounmap(dev.shmem);
1174 release_mem_region(dev.memaddr, 0x4000);
1175 }
1176 dev.mvalid = 0;
1177 dev.memaddr = a & 0x0ffc000;
1178 spin_unlock_irqrestore(&card->lock, flags);
1179 printk(KERN_INFO
1180 "icn: (%s) mmio set to 0x%08lx\n",
1181 CID,
1182 dev.memaddr);
1183 }
1184 break;
1185 case ICN_IOCTL_GETMMIO:
1186 return (long)dev.memaddr;
1187 case ICN_IOCTL_SETPORT:
1188 if (a == 0x300 || a == 0x310 || a == 0x320 || a == 0x330
1189 || a == 0x340 || a == 0x350 || a == 0x360 ||
1190 a == 0x308 || a == 0x318 || a == 0x328 || a == 0x338
1191 || a == 0x348 || a == 0x358 || a == 0x368) {
1192 if (card->port != (unsigned short)a) {
1193 if (!request_region((unsigned short)a, ICN_PORTLEN, "icn-isdn")) {
1194 printk(KERN_WARNING
1195 "icn: (%s) ports 0x%03x-0x%03x in use.\n",
1196 CID, (int)a, (int)a + ICN_PORTLEN);
1197 return -EINVAL;
1198 }
1199 release_region((unsigned short)a, ICN_PORTLEN);
1200 icn_stopcard(card);
1201 spin_lock_irqsave(&card->lock, flags);
1202 if (card->rvalid)
1203 release_region(card->port, ICN_PORTLEN);
1204 card->port = (unsigned short)a;
1205 card->rvalid = 0;
1206 if (card->doubleS0) {
1207 card->other->port = (unsigned short)a;
1208 card->other->rvalid = 0;
1209 }
1210 spin_unlock_irqrestore(&card->lock, flags);
1211 printk(KERN_INFO
1212 "icn: (%s) port set to 0x%03x\n",
1213 CID, card->port);
1214 }
1215 } else
1216 return -EINVAL;
1217 break;
1218 case ICN_IOCTL_GETPORT:
1219 return (int)card->port;
1220 case ICN_IOCTL_GETDOUBLE:
1221 return (int)card->doubleS0;
1222 case ICN_IOCTL_DEBUGVAR:
1223 if (copy_to_user(arg,
1224 &card,
1225 sizeof(ulong)))
1226 return -EFAULT;
1227 a += sizeof(ulong);
1228 {
1229 ulong l = (ulong)&dev;
1230 if (copy_to_user(arg,
1231 &l,
1232 sizeof(ulong)))
1233 return -EFAULT;
1234 }
1235 return 0;
1236 case ICN_IOCTL_LOADBOOT:
1237 if (dev.firstload) {
1238 icn_disable_cards();
1239 dev.firstload = 0;
1240 }
1241 icn_stopcard(card);
1242 return icn_loadboot(arg, card);
1243 case ICN_IOCTL_LOADPROTO:
1244 icn_stopcard(card);
1245 i = (icn_loadproto(arg, card));
1246 if (i)
1247 return i;
1248 if (card->doubleS0)
1249 i = icn_loadproto(arg + ICN_CODE_STAGE2, card->other);
1250 return i;
1251 break;
1252 case ICN_IOCTL_ADDCARD:
1253 if (!dev.firstload)
1254 return -EBUSY;
1255 if (copy_from_user(&cdef,
1256 arg,
1257 sizeof(cdef)))
1258 return -EFAULT;
1259 return icn_addcard(cdef.port, cdef.id1, cdef.id2);
1260 break;
1261 case ICN_IOCTL_LEASEDCFG:
1262 if (a) {
1263 if (!card->leased) {
1264 card->leased = 1;
1265 while (card->ptype == ISDN_PTYPE_UNKNOWN)
1266 msleep_interruptible(ICN_BOOT_TIMEOUT1);
1267 msleep_interruptible(ICN_BOOT_TIMEOUT1);
1268 sprintf(cbuf, "00;FV2ON\n01;EAZ%c\n02;EAZ%c\n",
1269 (a & 1) ? '1' : 'C', (a & 2) ? '2' : 'C');
1270 i = icn_writecmd(NULL, cbuf,
1271 strlen(cbuf),
1272 0, card);
1273 printk(KERN_INFO
1274 "icn: (%s) Leased-line mode enabled\n",
1275 CID);
1276 cmd.command = ISDN_STAT_RUN;
1277 cmd.driver = card->myid;
1278 cmd.arg = 0;
1279 card->interface.statcallb(&cmd);
1280 }
1281 } else {
1282 if (card->leased) {
1283 card->leased = 0;
1284 sprintf(cbuf, "00;FV2OFF\n");
1285 i = icn_writecmd(NULL, cbuf,
1286 strlen(cbuf),
1287 0, card);
1288 printk(KERN_INFO
1289 "icn: (%s) Leased-line mode disabled\n",
1290 CID);
1291 cmd.command = ISDN_STAT_RUN;
1292 cmd.driver = card->myid;
1293 cmd.arg = 0;
1294 card->interface.statcallb(&cmd);
1295 }
1296 }
1297 return 0;
1298 default:
1299 return -EINVAL;
1300 }
1301 break;
1302 case ISDN_CMD_DIAL:
1303 if (!(card->flags & ICN_FLAGS_RUNNING))
1304 return -ENODEV;
1305 if (card->leased)
1306 break;
1307 if ((c->arg & 255) < ICN_BCH) {
1308 char *p;
1309 char dcode[4];
1310
1311 a = c->arg;
1312 p = c->parm.setup.phone;
1313 if (*p == 's' || *p == 'S') {
1314 /* Dial for SPV */
1315 p++;
1316 strcpy(dcode, "SCA");
1317 } else
1318 /* Normal Dial */
1319 strcpy(dcode, "CAL");
1320 snprintf(cbuf, sizeof(cbuf),
1321 "%02d;D%s_R%s,%02d,%02d,%s\n", (int)(a + 1),
1322 dcode, p, c->parm.setup.si1,
1323 c->parm.setup.si2, c->parm.setup.eazmsn);
1324 i = icn_writecmd(NULL, cbuf, strlen(cbuf), 0, card);
1325 }
1326 break;
1327 case ISDN_CMD_ACCEPTD:
1328 if (!(card->flags & ICN_FLAGS_RUNNING))
1329 return -ENODEV;
1330 if (c->arg < ICN_BCH) {
1331 a = c->arg + 1;
1332 if (card->fw_rev >= 300) {
1333 switch (card->l2_proto[a - 1]) {
1334 case ISDN_PROTO_L2_X75I:
1335 sprintf(cbuf, "%02d;BX75\n", (int)a);
1336 break;
1337 case ISDN_PROTO_L2_HDLC:
1338 sprintf(cbuf, "%02d;BTRA\n", (int)a);
1339 break;
1340 }
1341 i = icn_writecmd(NULL, cbuf,
1342 strlen(cbuf), 0,
1343 card);
1344 }
1345 sprintf(cbuf, "%02d;DCON_R\n", (int)a);
1346 i = icn_writecmd(NULL, cbuf, strlen(cbuf), 0, card);
1347 }
1348 break;
1349 case ISDN_CMD_ACCEPTB:
1350 if (!(card->flags & ICN_FLAGS_RUNNING))
1351 return -ENODEV;
1352 if (c->arg < ICN_BCH) {
1353 a = c->arg + 1;
1354 if (card->fw_rev >= 300)
1355 switch (card->l2_proto[a - 1]) {
1356 case ISDN_PROTO_L2_X75I:
1357 sprintf(cbuf, "%02d;BCON_R,BX75\n", (int)a);
1358 break;
1359 case ISDN_PROTO_L2_HDLC:
1360 sprintf(cbuf, "%02d;BCON_R,BTRA\n", (int)a);
1361 break;
1362 } else
1363 sprintf(cbuf, "%02d;BCON_R\n", (int)a);
1364 i = icn_writecmd(NULL, cbuf, strlen(cbuf), 0, card);
1365 }
1366 break;
1367 case ISDN_CMD_HANGUP:
1368 if (!(card->flags & ICN_FLAGS_RUNNING))
1369 return -ENODEV;
1370 if (c->arg < ICN_BCH) {
1371 a = c->arg + 1;
1372 sprintf(cbuf, "%02d;BDIS_R\n%02d;DDIS_R\n", (int)a, (int)a);
1373 i = icn_writecmd(NULL, cbuf, strlen(cbuf), 0, card);
1374 }
1375 break;
1376 case ISDN_CMD_SETEAZ:
1377 if (!(card->flags & ICN_FLAGS_RUNNING))
1378 return -ENODEV;
1379 if (card->leased)
1380 break;
1381 if (c->arg < ICN_BCH) {
1382 a = c->arg + 1;
1383 if (card->ptype == ISDN_PTYPE_EURO) {
1384 sprintf(cbuf, "%02d;MS%s%s\n", (int)a,
1385 c->parm.num[0] ? "N" : "ALL", c->parm.num);
1386 } else
1387 sprintf(cbuf, "%02d;EAZ%s\n", (int)a,
1388 c->parm.num[0] ? (char *)(c->parm.num) : "0123456789");
1389 i = icn_writecmd(NULL, cbuf, strlen(cbuf), 0, card);
1390 }
1391 break;
1392 case ISDN_CMD_CLREAZ:
1393 if (!(card->flags & ICN_FLAGS_RUNNING))
1394 return -ENODEV;
1395 if (card->leased)
1396 break;
1397 if (c->arg < ICN_BCH) {
1398 a = c->arg + 1;
1399 if (card->ptype == ISDN_PTYPE_EURO)
1400 sprintf(cbuf, "%02d;MSNC\n", (int)a);
1401 else
1402 sprintf(cbuf, "%02d;EAZC\n", (int)a);
1403 i = icn_writecmd(NULL, cbuf, strlen(cbuf), 0, card);
1404 }
1405 break;
1406 case ISDN_CMD_SETL2:
1407 if (!(card->flags & ICN_FLAGS_RUNNING))
1408 return -ENODEV;
1409 if ((c->arg & 255) < ICN_BCH) {
1410 a = c->arg;
1411 switch (a >> 8) {
1412 case ISDN_PROTO_L2_X75I:
1413 sprintf(cbuf, "%02d;BX75\n", (int)(a & 255) + 1);
1414 break;
1415 case ISDN_PROTO_L2_HDLC:
1416 sprintf(cbuf, "%02d;BTRA\n", (int)(a & 255) + 1);
1417 break;
1418 default:
1419 return -EINVAL;
1420 }
1421 i = icn_writecmd(NULL, cbuf, strlen(cbuf), 0, card);
1422 card->l2_proto[a & 255] = (a >> 8);
1423 }
1424 break;
1425 case ISDN_CMD_SETL3:
1426 if (!(card->flags & ICN_FLAGS_RUNNING))
1427 return -ENODEV;
1428 return 0;
1429 default:
1430 return -EINVAL;
1431 }
1432 return 0;
1433}
1434
1435/*
1436 * Find card with given driverId
1437 */
1438static inline icn_card *
1439icn_findcard(int driverid)
1440{
1441 icn_card *p = cards;
1442
1443 while (p) {
1444 if (p->myid == driverid)
1445 return p;
1446 p = p->next;
1447 }
1448 return (icn_card *)0;
1449}
1450
1451/*
1452 * Wrapper functions for interface to linklevel
1453 */
1454static int
1455if_command(isdn_ctrl *c)
1456{
1457 icn_card *card = icn_findcard(c->driver);
1458
1459 if (card)
1460 return icn_command(c, card);
1461 printk(KERN_ERR
1462 "icn: if_command %d called with invalid driverId %d!\n",
1463 c->command, c->driver);
1464 return -ENODEV;
1465}
1466
1467static int
1468if_writecmd(const u_char __user *buf, int len, int id, int channel)
1469{
1470 icn_card *card = icn_findcard(id);
1471
1472 if (card) {
1473 if (!(card->flags & ICN_FLAGS_RUNNING))
1474 return -ENODEV;
1475 return icn_writecmd(buf, NULL, len, 1, card);
1476 }
1477 printk(KERN_ERR
1478 "icn: if_writecmd called with invalid driverId!\n");
1479 return -ENODEV;
1480}
1481
1482static int
1483if_readstatus(u_char __user *buf, int len, int id, int channel)
1484{
1485 icn_card *card = icn_findcard(id);
1486
1487 if (card) {
1488 if (!(card->flags & ICN_FLAGS_RUNNING))
1489 return -ENODEV;
1490 return icn_readstatus(buf, len, card);
1491 }
1492 printk(KERN_ERR
1493 "icn: if_readstatus called with invalid driverId!\n");
1494 return -ENODEV;
1495}
1496
1497static int
1498if_sendbuf(int id, int channel, int ack, struct sk_buff *skb)
1499{
1500 icn_card *card = icn_findcard(id);
1501
1502 if (card) {
1503 if (!(card->flags & ICN_FLAGS_RUNNING))
1504 return -ENODEV;
1505 return icn_sendbuf(channel, ack, skb, card);
1506 }
1507 printk(KERN_ERR
1508 "icn: if_sendbuf called with invalid driverId!\n");
1509 return -ENODEV;
1510}
1511
1512/*
1513 * Allocate a new card-struct, initialize it
1514 * link it into cards-list and register it at linklevel.
1515 */
1516static icn_card *
1517icn_initcard(int port, char *id)
1518{
1519 icn_card *card;
1520 int i;
1521
1522 card = kzalloc(sizeof(icn_card), GFP_KERNEL);
1523 if (!card) {
1524 printk(KERN_WARNING
1525 "icn: (%s) Could not allocate card-struct.\n", id);
1526 return (icn_card *)0;
1527 }
1528 spin_lock_init(&card->lock);
1529 card->port = port;
1530 card->interface.owner = THIS_MODULE;
1531 card->interface.hl_hdrlen = 1;
1532 card->interface.channels = ICN_BCH;
1533 card->interface.maxbufsize = 4000;
1534 card->interface.command = if_command;
1535 card->interface.writebuf_skb = if_sendbuf;
1536 card->interface.writecmd = if_writecmd;
1537 card->interface.readstat = if_readstatus;
1538 card->interface.features = ISDN_FEATURE_L2_X75I |
1539 ISDN_FEATURE_L2_HDLC |
1540 ISDN_FEATURE_L3_TRANS |
1541 ISDN_FEATURE_P_UNKNOWN;
1542 card->ptype = ISDN_PTYPE_UNKNOWN;
1543 strlcpy(card->interface.id, id, sizeof(card->interface.id));
1544 card->msg_buf_write = card->msg_buf;
1545 card->msg_buf_read = card->msg_buf;
1546 card->msg_buf_end = &card->msg_buf[sizeof(card->msg_buf) - 1];
1547 for (i = 0; i < ICN_BCH; i++) {
1548 card->l2_proto[i] = ISDN_PROTO_L2_X75I;
1549 skb_queue_head_init(&card->spqueue[i]);
1550 }
1551 card->next = cards;
1552 cards = card;
1553 if (!register_isdn(&card->interface)) {
1554 cards = cards->next;
1555 printk(KERN_WARNING
1556 "icn: Unable to register %s\n", id);
1557 kfree(card);
1558 return (icn_card *)0;
1559 }
1560 card->myid = card->interface.channels;
1561 sprintf(card->regname, "icn-isdn (%s)", card->interface.id);
1562 return card;
1563}
1564
1565static int
1566icn_addcard(int port, char *id1, char *id2)
1567{
1568 icn_card *card;
1569 icn_card *card2;
1570
1571 card = icn_initcard(port, id1);
1572 if (!card)
1573 return -EIO;
1574 if (!strlen(id2)) {
1575 printk(KERN_INFO
1576 "icn: (%s) ICN-2B, port 0x%x added\n",
1577 card->interface.id, port);
1578 return 0;
1579 }
1580 card2 = icn_initcard(port, id2);
1581 if (!card2) {
1582 printk(KERN_INFO
1583 "icn: (%s) half ICN-4B, port 0x%x added\n", id2, port);
1584 return 0;
1585 }
1586 card->doubleS0 = 1;
1587 card->secondhalf = 0;
1588 card->other = card2;
1589 card2->doubleS0 = 1;
1590 card2->secondhalf = 1;
1591 card2->other = card;
1592 printk(KERN_INFO
1593 "icn: (%s and %s) ICN-4B, port 0x%x added\n",
1594 card->interface.id, card2->interface.id, port);
1595 return 0;
1596}
1597
1598#ifndef MODULE
1599static int __init
1600icn_setup(char *line)
1601{
1602 char *p, *str;
1603 int ints[3];
1604 static char sid[20];
1605 static char sid2[20];
1606
1607 str = get_options(line, 2, ints);
1608 if (ints[0])
1609 portbase = ints[1];
1610 if (ints[0] > 1)
1611 membase = (unsigned long)ints[2];
1612 if (str && *str) {
1613 strlcpy(sid, str, sizeof(sid));
1614 icn_id = sid;
1615 p = strchr(sid, ',');
1616 if (p) {
1617 *p++ = 0;
1618 strcpy(sid2, p);
1619 icn_id2 = sid2;
1620 }
1621 }
1622 return 1;
1623}
1624__setup("icn=", icn_setup);
1625#endif /* MODULE */
1626
1627static int __init icn_init(void)
1628{
1629 char *p;
1630 char rev[21];
1631
1632 memset(&dev, 0, sizeof(icn_dev));
1633 dev.memaddr = (membase & 0x0ffc000);
1634 dev.channel = -1;
1635 dev.mcard = NULL;
1636 dev.firstload = 1;
1637 spin_lock_init(&dev.devlock);
1638
1639 p = strchr(revision, ':');
1640 if (p) {
1641 strncpy(rev, p + 1, 20);
1642 rev[20] = '\0';
1643 p = strchr(rev, '$');
1644 if (p)
1645 *p = 0;
1646 } else
1647 strcpy(rev, " ??? ");
1648 printk(KERN_NOTICE "ICN-ISDN-driver Rev%smem=0x%08lx\n", rev,
1649 dev.memaddr);
1650 return icn_addcard(portbase, icn_id, icn_id2);
1651}
1652
1653static void __exit icn_exit(void)
1654{
1655 isdn_ctrl cmd;
1656 icn_card *card = cards;
1657 icn_card *last, *tmpcard;
1658 int i;
1659 unsigned long flags;
1660
1661 icn_stopallcards();
1662 while (card) {
1663 cmd.command = ISDN_STAT_UNLOAD;
1664 cmd.driver = card->myid;
1665 card->interface.statcallb(&cmd);
1666 spin_lock_irqsave(&card->lock, flags);
1667 if (card->rvalid) {
1668 OUTB_P(0, ICN_RUN); /* Reset Controller */
1669 OUTB_P(0, ICN_MAPRAM); /* Disable RAM */
1670 if (card->secondhalf || (!card->doubleS0)) {
1671 release_region(card->port, ICN_PORTLEN);
1672 card->rvalid = 0;
1673 }
1674 for (i = 0; i < ICN_BCH; i++)
1675 icn_free_queue(card, i);
1676 }
1677 tmpcard = card->next;
1678 spin_unlock_irqrestore(&card->lock, flags);
1679 card = tmpcard;
1680 }
1681 card = cards;
1682 cards = NULL;
1683 while (card) {
1684 last = card;
1685 card = card->next;
1686 kfree(last);
1687 }
1688 if (dev.mvalid) {
1689 iounmap(dev.shmem);
1690 release_mem_region(dev.memaddr, 0x4000);
1691 }
1692 printk(KERN_NOTICE "ICN-ISDN-driver unloaded\n");
1693}
1694
1695module_init(icn_init);
1696module_exit(icn_exit);
diff --git a/drivers/staging/i4l/icn/icn.h b/drivers/staging/i4l/icn/icn.h
deleted file mode 100644
index 07e2e0196527..000000000000
--- a/drivers/staging/i4l/icn/icn.h
+++ /dev/null
@@ -1,252 +0,0 @@
1/* $Id: icn.h,v 1.30.6.5 2001/09/23 22:24:55 kai Exp $
2 *
3 * ISDN lowlevel-module for the ICN active ISDN-Card.
4 *
5 * Copyright 1994 by Fritz Elfert (fritz@isdn4linux.de)
6 *
7 * This software may be used and distributed according to the terms
8 * of the GNU General Public License, incorporated herein by reference.
9 *
10 */
11
12#ifndef icn_h
13#define icn_h
14
15#define ICN_IOCTL_SETMMIO 0
16#define ICN_IOCTL_GETMMIO 1
17#define ICN_IOCTL_SETPORT 2
18#define ICN_IOCTL_GETPORT 3
19#define ICN_IOCTL_LOADBOOT 4
20#define ICN_IOCTL_LOADPROTO 5
21#define ICN_IOCTL_LEASEDCFG 6
22#define ICN_IOCTL_GETDOUBLE 7
23#define ICN_IOCTL_DEBUGVAR 8
24#define ICN_IOCTL_ADDCARD 9
25
26/* Struct for adding new cards */
27typedef struct icn_cdef {
28 int port;
29 char id1[10];
30 char id2[10];
31} icn_cdef;
32
33#if defined(__KERNEL__) || defined(__DEBUGVAR__)
34
35#ifdef __KERNEL__
36/* Kernel includes */
37
38#include <linux/errno.h>
39#include <linux/fs.h>
40#include <linux/major.h>
41#include <linux/io.h>
42#include <linux/kernel.h>
43#include <linux/signal.h>
44#include <linux/slab.h>
45#include <linux/mm.h>
46#include <linux/mman.h>
47#include <linux/ioport.h>
48#include <linux/timer.h>
49#include <linux/wait.h>
50#include <linux/delay.h>
51#include <linux/isdnif.h>
52
53#endif /* __KERNEL__ */
54
55/* some useful macros for debugging */
56#ifdef ICN_DEBUG_PORT
57#define OUTB_P(v, p) {pr_debug("icn: outb_p(0x%02x,0x%03x)\n", v, p); outb_p(v, p);}
58#else
59#define OUTB_P outb
60#endif
61
62/* Defaults for Port-Address and shared-memory */
63#define ICN_BASEADDR 0x320
64#define ICN_PORTLEN (0x04)
65#define ICN_MEMADDR 0x0d0000
66
67#define ICN_FLAGS_B1ACTIVE 1 /* B-Channel-1 is open */
68#define ICN_FLAGS_B2ACTIVE 2 /* B-Channel-2 is open */
69#define ICN_FLAGS_RUNNING 4 /* Cards driver activated */
70#define ICN_FLAGS_RBTIMER 8 /* cyclic scheduling of B-Channel-poll */
71
72#define ICN_BOOT_TIMEOUT1 1000 /* Delay for Boot-download (msecs) */
73
74#define ICN_TIMER_BCREAD (HZ / 100) /* B-Channel poll-cycle */
75#define ICN_TIMER_DCREAD (HZ / 2) /* D-Channel poll-cycle */
76
77#define ICN_CODE_STAGE1 4096 /* Size of bootcode */
78#define ICN_CODE_STAGE2 65536 /* Size of protocol-code */
79
80#define ICN_MAX_SQUEUE 8000 /* Max. outstanding send-data (2* hw-buf.) */
81#define ICN_FRAGSIZE (250) /* Max. size of send-fragments */
82#define ICN_BCH 2 /* Number of supported channels per card */
83
84/* type-definitions for accessing the mmap-io-areas */
85
86#define SHM_DCTL_OFFSET (0) /* Offset to data-controlstructures in shm */
87#define SHM_CCTL_OFFSET (0x1d2) /* Offset to comm-controlstructures in shm */
88#define SHM_CBUF_OFFSET (0x200) /* Offset to comm-buffers in shm */
89#define SHM_DBUF_OFFSET (0x2000) /* Offset to data-buffers in shm */
90
91/*
92 * Layout of card's data buffers
93 */
94typedef struct {
95 unsigned char length; /* Bytecount of fragment (max 250) */
96 unsigned char endflag; /* 0=last frag., 0xff=frag. continued */
97 unsigned char data[ICN_FRAGSIZE]; /* The data */
98 /* Fill to 256 bytes */
99 char unused[0x100 - ICN_FRAGSIZE - 2];
100} frag_buf;
101
102/*
103 * Layout of card's shared memory
104 */
105typedef union {
106 struct {
107 unsigned char scns; /* Index to free SendFrag. */
108 unsigned char scnr; /* Index to active SendFrag READONLY */
109 unsigned char ecns; /* Index to free RcvFrag. READONLY */
110 unsigned char ecnr; /* Index to valid RcvFrag */
111 char unused[6];
112 unsigned short fuell1; /* Internal Buf Bytecount */
113 } data_control;
114 struct {
115 char unused[SHM_CCTL_OFFSET];
116 unsigned char iopc_i; /* Read-Ptr Status-Queue READONLY */
117 unsigned char iopc_o; /* Write-Ptr Status-Queue */
118 unsigned char pcio_i; /* Write-Ptr Command-Queue */
119 unsigned char pcio_o; /* Read-Ptr Command Queue READONLY */
120 } comm_control;
121 struct {
122 char unused[SHM_CBUF_OFFSET];
123 unsigned char pcio_buf[0x100]; /* Ring-Buffer Command-Queue */
124 unsigned char iopc_buf[0x100]; /* Ring-Buffer Status-Queue */
125 } comm_buffers;
126 struct {
127 char unused[SHM_DBUF_OFFSET];
128 frag_buf receive_buf[0x10];
129 frag_buf send_buf[0x10];
130 } data_buffers;
131} icn_shmem;
132
133/*
134 * Per card driver data
135 */
136typedef struct icn_card {
137 struct icn_card *next; /* Pointer to next device struct */
138 struct icn_card *other; /* Pointer to other card for ICN4B */
139 unsigned short port; /* Base-port-address */
140 int myid; /* Driver-Nr. assigned by linklevel */
141 int rvalid; /* IO-portregion has been requested */
142 int leased; /* Flag: This Adapter is connected */
143 /* to a leased line */
144 unsigned short flags; /* Statusflags */
145 int doubleS0; /* Flag: ICN4B */
146 int secondhalf; /* Flag: Second half of a doubleS0 */
147 int fw_rev; /* Firmware revision loaded */
148 int ptype; /* Protocol type (1TR6 or Euro) */
149 struct timer_list st_timer; /* Timer for Status-Polls */
150 struct timer_list rb_timer; /* Timer for B-Channel-Polls */
151 u_char rcvbuf[ICN_BCH][4096]; /* B-Channel-Receive-Buffers */
152 int rcvidx[ICN_BCH]; /* Index for above buffers */
153 int l2_proto[ICN_BCH]; /* Current layer-2-protocol */
154 isdn_if interface; /* Interface to upper layer */
155 int iptr; /* Index to imsg-buffer */
156 char imsg[60]; /* Internal buf for status-parsing */
157 char msg_buf[2048]; /* Buffer for status-messages */
158 char *msg_buf_write; /* Writepointer for statusbuffer */
159 char *msg_buf_read; /* Readpointer for statusbuffer */
160 char *msg_buf_end; /* Pointer to end of statusbuffer */
161 int sndcount[ICN_BCH]; /* Byte-counters for B-Ch.-send */
162 int xlen[ICN_BCH]; /* Byte-counters/Flags for sent-ACK */
163 struct sk_buff *xskb[ICN_BCH]; /* Current transmitted skb */
164 struct sk_buff_head spqueue[ICN_BCH]; /* Sendqueue */
165 char regname[35]; /* Name used for request_region */
166 u_char xmit_lock[ICN_BCH]; /* Semaphore for pollbchan_send()*/
167 spinlock_t lock; /* protect critical operations */
168} icn_card;
169
170/*
171 * Main driver data
172 */
173typedef struct icn_dev {
174 spinlock_t devlock; /* spinlock to protect this struct */
175 unsigned long memaddr; /* Address of memory mapped buffers */
176 icn_shmem __iomem *shmem; /* Pointer to memory-mapped-buffers */
177 int mvalid; /* IO-shmem has been requested */
178 int channel; /* Currently mapped channel */
179 struct icn_card *mcard; /* Currently mapped card */
180 int chanlock; /* Semaphore for channel-mapping */
181 int firstload; /* Flag: firmware never loaded */
182} icn_dev;
183
184typedef icn_dev *icn_devptr;
185
186#ifdef __KERNEL__
187
188static icn_card *cards = (icn_card *) 0;
189static u_char chan2bank[] = {0, 4, 8, 12}; /* for icn_map_channel() */
190
191static icn_dev dev;
192
193#endif /* __KERNEL__ */
194
195/* Utility-Macros */
196
197/* Macros for accessing ports */
198#define ICN_CFG (card->port)
199#define ICN_MAPRAM (card->port + 1)
200#define ICN_RUN (card->port + 2)
201#define ICN_BANK (card->port + 3)
202
203/* Return true, if there is a free transmit-buffer */
204#define sbfree (((readb(&dev.shmem->data_control.scns) + 1) & 0xf) != \
205 readb(&dev.shmem->data_control.scnr))
206
207/* Switch to next transmit-buffer */
208#define sbnext (writeb((readb(&dev.shmem->data_control.scns) + 1) & 0xf, \
209 &dev.shmem->data_control.scns))
210
211/* Shortcuts for transmit-buffer-access */
212#define sbuf_n dev.shmem->data_control.scns
213#define sbuf_d dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].data
214#define sbuf_l dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].length
215#define sbuf_f dev.shmem->data_buffers.send_buf[readb(&sbuf_n)].endflag
216
217/* Return true, if there is receive-data is available */
218#define rbavl (readb(&dev.shmem->data_control.ecnr) != \
219 readb(&dev.shmem->data_control.ecns))
220
221/* Switch to next receive-buffer */
222#define rbnext (writeb((readb(&dev.shmem->data_control.ecnr) + 1) & 0xf, \
223 &dev.shmem->data_control.ecnr))
224
225/* Shortcuts for receive-buffer-access */
226#define rbuf_n dev.shmem->data_control.ecnr
227#define rbuf_d dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].data
228#define rbuf_l dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].length
229#define rbuf_f dev.shmem->data_buffers.receive_buf[readb(&rbuf_n)].endflag
230
231/* Shortcuts for command-buffer-access */
232#define cmd_o (dev.shmem->comm_control.pcio_o)
233#define cmd_i (dev.shmem->comm_control.pcio_i)
234
235/* Return free space in command-buffer */
236#define cmd_free ((readb(&cmd_i) >= readb(&cmd_o)) ? \
237 0x100 - readb(&cmd_i) + readb(&cmd_o) : \
238 readb(&cmd_o) - readb(&cmd_i))
239
240/* Shortcuts for message-buffer-access */
241#define msg_o (dev.shmem->comm_control.iopc_o)
242#define msg_i (dev.shmem->comm_control.iopc_i)
243
244/* Return length of Message, if avail. */
245#define msg_avail ((readb(&msg_o) > readb(&msg_i)) ? \
246 0x100 - readb(&msg_o) + readb(&msg_i) : \
247 readb(&msg_i) - readb(&msg_o))
248
249#define CID (card->interface.id)
250
251#endif /* defined(__KERNEL__) || defined(__DEBUGVAR__) */
252#endif /* icn_h */
diff --git a/drivers/staging/i4l/pcbit/Kconfig b/drivers/staging/i4l/pcbit/Kconfig
deleted file mode 100644
index e9b2dd85d410..000000000000
--- a/drivers/staging/i4l/pcbit/Kconfig
+++ /dev/null
@@ -1,10 +0,0 @@
1config ISDN_DRV_PCBIT
2 tristate "PCBIT-D support"
3 depends on ISA && (BROKEN || X86)
4 help
5 This enables support for the PCBIT ISDN-card. This card is
6 manufactured in Portugal by Octal. For running this card,
7 additional firmware is necessary, which has to be downloaded into
8 the card using a utility which is distributed separately. See
9 <file:Documentation/isdn/README> and
10 <file:Documentation/isdn/README.pcbit> for more information.
diff --git a/drivers/staging/i4l/pcbit/Makefile b/drivers/staging/i4l/pcbit/Makefile
deleted file mode 100644
index 2d026c3242e8..000000000000
--- a/drivers/staging/i4l/pcbit/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1# Makefile for the pcbit ISDN device driver
2
3# Each configuration option enables a list of files.
4
5obj-$(CONFIG_ISDN_DRV_PCBIT) += pcbit.o
6
7# Multipart objects.
8
9pcbit-y := module.o edss1.o drv.o layer2.o capi.o callbacks.o
diff --git a/drivers/staging/i4l/pcbit/callbacks.c b/drivers/staging/i4l/pcbit/callbacks.c
deleted file mode 100644
index 212ab0b229d4..000000000000
--- a/drivers/staging/i4l/pcbit/callbacks.c
+++ /dev/null
@@ -1,345 +0,0 @@
1/*
2 * Callbacks for the FSM
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12/*
13 * Fix: 19981230 - Carlos Morgado <chbm@techie.com>
14 * Port of Nelson Escravana's <nelson.escravana@usa.net> fix to CalledPN
15 * NULL pointer dereference in cb_in_1 (originally fixed in 2.0)
16 */
17
18#include <linux/string.h>
19#include <linux/kernel.h>
20
21#include <linux/types.h>
22#include <linux/mm.h>
23#include <linux/skbuff.h>
24
25#include <linux/io.h>
26
27#include <linux/isdnif.h>
28
29#include "pcbit.h"
30#include "layer2.h"
31#include "edss1.h"
32#include "callbacks.h"
33#include "capi.h"
34
35ushort last_ref_num = 1;
36
37/*
38 * send_conn_req
39 *
40 */
41
42void cb_out_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
43 struct callb_data *cbdata)
44{
45 struct sk_buff *skb;
46 int len;
47 ushort refnum;
48
49
50#ifdef DEBUG
51 printk(KERN_DEBUG "Called Party Number: %s\n",
52 cbdata->data.setup.CalledPN);
53#endif
54 /*
55 * hdr - kmalloc in capi_conn_req
56 * - kfree when msg has been sent
57 */
58
59 if ((len = capi_conn_req(cbdata->data.setup.CalledPN, &skb,
60 chan->proto)) < 0)
61 {
62 printk("capi_conn_req failed\n");
63 return;
64 }
65
66
67 refnum = last_ref_num++ & 0x7fffU;
68
69 chan->callref = 0;
70 chan->layer2link = 0;
71 chan->snum = 0;
72 chan->s_refnum = refnum;
73
74 pcbit_l2_write(dev, MSG_CONN_REQ, refnum, skb, len);
75}
76
77/*
78 * rcv CONNECT
79 * will go into ACTIVE state
80 * send CONN_ACTIVE_RESP
81 * send Select protocol request
82 */
83
84void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
85 struct callb_data *data)
86{
87 isdn_ctrl ictl;
88 struct sk_buff *skb;
89 int len;
90 ushort refnum;
91
92 if ((len = capi_conn_active_resp(chan, &skb)) < 0)
93 {
94 printk("capi_conn_active_req failed\n");
95 return;
96 }
97
98 refnum = last_ref_num++ & 0x7fffU;
99 chan->s_refnum = refnum;
100
101 pcbit_l2_write(dev, MSG_CONN_ACTV_RESP, refnum, skb, len);
102
103
104 ictl.command = ISDN_STAT_DCONN;
105 ictl.driver = dev->id;
106 ictl.arg = chan->id;
107 dev->dev_if->statcallb(&ictl);
108
109 /* ACTIVE D-channel */
110
111 /* Select protocol */
112
113 if ((len = capi_select_proto_req(chan, &skb, 1 /*outgoing*/)) < 0) {
114 printk("capi_select_proto_req failed\n");
115 return;
116 }
117
118 refnum = last_ref_num++ & 0x7fffU;
119 chan->s_refnum = refnum;
120
121 pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len);
122}
123
124
125/*
126 * Incoming call received
127 * inform user
128 */
129
130void cb_in_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
131 struct callb_data *cbdata)
132{
133 isdn_ctrl ictl;
134 unsigned short refnum;
135 struct sk_buff *skb;
136 int len;
137
138
139 ictl.command = ISDN_STAT_ICALL;
140 ictl.driver = dev->id;
141 ictl.arg = chan->id;
142
143 /*
144 * ictl.num >= strlen() + strlen() + 5
145 */
146
147 if (cbdata->data.setup.CallingPN == NULL) {
148 printk(KERN_DEBUG "NULL CallingPN to phone; using 0\n");
149 strcpy(ictl.parm.setup.phone, "0");
150 }
151 else {
152 strcpy(ictl.parm.setup.phone, cbdata->data.setup.CallingPN);
153 }
154 if (cbdata->data.setup.CalledPN == NULL) {
155 printk(KERN_DEBUG "NULL CalledPN to eazmsn; using 0\n");
156 strcpy(ictl.parm.setup.eazmsn, "0");
157 }
158 else {
159 strcpy(ictl.parm.setup.eazmsn, cbdata->data.setup.CalledPN);
160 }
161 ictl.parm.setup.si1 = 7;
162 ictl.parm.setup.si2 = 0;
163 ictl.parm.setup.plan = 0;
164 ictl.parm.setup.screen = 0;
165
166#ifdef DEBUG
167 printk(KERN_DEBUG "statstr: %s\n", ictl.num);
168#endif
169
170 dev->dev_if->statcallb(&ictl);
171
172
173 if ((len = capi_conn_resp(chan, &skb)) < 0) {
174 printk(KERN_DEBUG "capi_conn_resp failed\n");
175 return;
176 }
177
178 refnum = last_ref_num++ & 0x7fffU;
179 chan->s_refnum = refnum;
180
181 pcbit_l2_write(dev, MSG_CONN_RESP, refnum, skb, len);
182}
183
184/*
185 * user has replied
186 * open the channel
187 * send CONNECT message CONNECT_ACTIVE_REQ in CAPI
188 */
189
190void cb_in_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
191 struct callb_data *data)
192{
193 unsigned short refnum;
194 struct sk_buff *skb;
195 int len;
196
197 if ((len = capi_conn_active_req(chan, &skb)) < 0) {
198 printk(KERN_DEBUG "capi_conn_active_req failed\n");
199 return;
200 }
201
202
203 refnum = last_ref_num++ & 0x7fffU;
204 chan->s_refnum = refnum;
205
206 printk(KERN_DEBUG "sending MSG_CONN_ACTV_REQ\n");
207 pcbit_l2_write(dev, MSG_CONN_ACTV_REQ, refnum, skb, len);
208}
209
210/*
211 * CONN_ACK arrived
212 * start b-proto selection
213 *
214 */
215
216void cb_in_3(struct pcbit_dev *dev, struct pcbit_chan *chan,
217 struct callb_data *data)
218{
219 unsigned short refnum;
220 struct sk_buff *skb;
221 int len;
222
223 if ((len = capi_select_proto_req(chan, &skb, 0 /*incoming*/)) < 0)
224 {
225 printk("capi_select_proto_req failed\n");
226 return;
227 }
228
229 refnum = last_ref_num++ & 0x7fffU;
230 chan->s_refnum = refnum;
231
232 pcbit_l2_write(dev, MSG_SELP_REQ, refnum, skb, len);
233
234}
235
236
237/*
238 * Received disconnect ind on active state
239 * send disconnect resp
240 * send msg to user
241 */
242void cb_disc_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
243 struct callb_data *data)
244{
245 struct sk_buff *skb;
246 int len;
247 ushort refnum;
248 isdn_ctrl ictl;
249
250 if ((len = capi_disc_resp(chan, &skb)) < 0) {
251 printk("capi_disc_resp failed\n");
252 return;
253 }
254
255 refnum = last_ref_num++ & 0x7fffU;
256 chan->s_refnum = refnum;
257
258 pcbit_l2_write(dev, MSG_DISC_RESP, refnum, skb, len);
259
260 ictl.command = ISDN_STAT_BHUP;
261 ictl.driver = dev->id;
262 ictl.arg = chan->id;
263 dev->dev_if->statcallb(&ictl);
264}
265
266
267/*
268 * User HANGUP on active/call proceeding state
269 * send disc.req
270 */
271void cb_disc_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
272 struct callb_data *data)
273{
274 struct sk_buff *skb;
275 int len;
276 ushort refnum;
277
278 if ((len = capi_disc_req(chan->callref, &skb, CAUSE_NORMAL)) < 0)
279 {
280 printk("capi_disc_req failed\n");
281 return;
282 }
283
284 refnum = last_ref_num++ & 0x7fffU;
285 chan->s_refnum = refnum;
286
287 pcbit_l2_write(dev, MSG_DISC_REQ, refnum, skb, len);
288}
289
290/*
291 * Disc confirm received send BHUP
292 * Problem: when the HL driver sends the disc req itself
293 * LL receives BHUP
294 */
295void cb_disc_3(struct pcbit_dev *dev, struct pcbit_chan *chan,
296 struct callb_data *data)
297{
298 isdn_ctrl ictl;
299
300 ictl.command = ISDN_STAT_BHUP;
301 ictl.driver = dev->id;
302 ictl.arg = chan->id;
303 dev->dev_if->statcallb(&ictl);
304}
305
306void cb_notdone(struct pcbit_dev *dev, struct pcbit_chan *chan,
307 struct callb_data *data)
308{
309}
310
311/*
312 * send activate b-chan protocol
313 */
314void cb_selp_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
315 struct callb_data *data)
316{
317 struct sk_buff *skb;
318 int len;
319 ushort refnum;
320
321 if ((len = capi_activate_transp_req(chan, &skb)) < 0)
322 {
323 printk("capi_conn_activate_transp_req failed\n");
324 return;
325 }
326
327 refnum = last_ref_num++ & 0x7fffU;
328 chan->s_refnum = refnum;
329
330 pcbit_l2_write(dev, MSG_ACT_TRANSP_REQ, refnum, skb, len);
331}
332
333/*
334 * Inform User that the B-channel is available
335 */
336void cb_open(struct pcbit_dev *dev, struct pcbit_chan *chan,
337 struct callb_data *data)
338{
339 isdn_ctrl ictl;
340
341 ictl.command = ISDN_STAT_BCONN;
342 ictl.driver = dev->id;
343 ictl.arg = chan->id;
344 dev->dev_if->statcallb(&ictl);
345}
diff --git a/drivers/staging/i4l/pcbit/callbacks.h b/drivers/staging/i4l/pcbit/callbacks.h
deleted file mode 100644
index a036b4a7ffad..000000000000
--- a/drivers/staging/i4l/pcbit/callbacks.h
+++ /dev/null
@@ -1,44 +0,0 @@
1/*
2 * Callbacks prototypes for FSM
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12#ifndef CALLBACKS_H
13#define CALLBACKS_H
14
15
16extern void cb_out_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
17 struct callb_data *data);
18
19extern void cb_out_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
20 struct callb_data *data);
21
22extern void cb_in_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
23 struct callb_data *data);
24extern void cb_in_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
25 struct callb_data *data);
26extern void cb_in_3(struct pcbit_dev *dev, struct pcbit_chan *chan,
27 struct callb_data *data);
28
29extern void cb_disc_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
30 struct callb_data *data);
31extern void cb_disc_2(struct pcbit_dev *dev, struct pcbit_chan *chan,
32 struct callb_data *data);
33extern void cb_disc_3(struct pcbit_dev *dev, struct pcbit_chan *chan,
34 struct callb_data *data);
35
36extern void cb_notdone(struct pcbit_dev *dev, struct pcbit_chan *chan,
37 struct callb_data *data);
38
39extern void cb_selp_1(struct pcbit_dev *dev, struct pcbit_chan *chan,
40 struct callb_data *data);
41extern void cb_open(struct pcbit_dev *dev, struct pcbit_chan *chan,
42 struct callb_data *data);
43
44#endif
diff --git a/drivers/staging/i4l/pcbit/capi.c b/drivers/staging/i4l/pcbit/capi.c
deleted file mode 100644
index a6c4e00dc726..000000000000
--- a/drivers/staging/i4l/pcbit/capi.c
+++ /dev/null
@@ -1,646 +0,0 @@
1/*
2 * CAPI encoder/decoder for
3 * Portugal Telecom CAPI 2.0
4 *
5 * Copyright (C) 1996 Universidade de Lisboa
6 *
7 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
8 *
9 * This software may be used and distributed according to the terms of
10 * the GNU General Public License, incorporated herein by reference.
11 *
12 * Not compatible with the AVM Gmbh. CAPI 2.0
13 *
14 */
15
16/*
17 * Documentation:
18 * - "Common ISDN API - Perfil Português - Versão 2.1",
19 * Telecom Portugal, Fev 1992.
20 * - "Common ISDN API - Especificação de protocolos para
21 * acesso aos canais B", Inesc, Jan 1994.
22 */
23
24/*
25 * TODO: better decoding of Information Elements
26 * for debug purposes mainly
27 * encode our number in CallerPN and ConnectedPN
28 */
29
30#include <linux/kernel.h>
31
32#include <linux/types.h>
33#include <linux/slab.h>
34#include <linux/mm.h>
35
36#include <linux/skbuff.h>
37
38#include <linux/io.h>
39#include <linux/string.h>
40
41#include <linux/isdnif.h>
42
43#include "pcbit.h"
44#include "edss1.h"
45#include "capi.h"
46
47
48/*
49 * Encoding of CAPI messages
50 *
51 */
52
53int capi_conn_req(const char *calledPN, struct sk_buff **skb, int proto)
54{
55 ushort len;
56
57 /*
58 * length
59 * AppInfoMask - 2
60 * BC0 - 3
61 * BC1 - 1
62 * Chan - 2
63 * Keypad - 1
64 * CPN - 1
65 * CPSA - 1
66 * CalledPN - 2 + strlen
67 * CalledPSA - 1
68 * rest... - 4
69 * ----------------
70 * Total 18 + strlen
71 */
72
73 len = 18 + strlen(calledPN);
74
75 if (proto == ISDN_PROTO_L2_TRANS)
76 len++;
77
78 if ((*skb = dev_alloc_skb(len)) == NULL) {
79
80 printk(KERN_WARNING "capi_conn_req: alloc_skb failed\n");
81 return -1;
82 }
83
84 /* InfoElmMask */
85 *((ushort *)skb_put(*skb, 2)) = AppInfoMask;
86
87 if (proto == ISDN_PROTO_L2_TRANS)
88 {
89 /* Bearer Capability - Mandatory*/
90 *(skb_put(*skb, 1)) = 3; /* BC0.Length */
91 *(skb_put(*skb, 1)) = 0x80; /* Speech */
92 *(skb_put(*skb, 1)) = 0x10; /* Circuit Mode */
93 *(skb_put(*skb, 1)) = 0x23; /* A-law */
94 } else {
95 /* Bearer Capability - Mandatory*/
96 *(skb_put(*skb, 1)) = 2; /* BC0.Length */
97 *(skb_put(*skb, 1)) = 0x88; /* Digital Information */
98 *(skb_put(*skb, 1)) = 0x90; /* BC0.Octect4 */
99 }
100
101 /* Bearer Capability - Optional*/
102 *(skb_put(*skb, 1)) = 0; /* BC1.Length = 0 */
103
104 *(skb_put(*skb, 1)) = 1; /* ChannelID.Length = 1 */
105 *(skb_put(*skb, 1)) = 0x83; /* Basic Interface - Any Channel */
106
107 *(skb_put(*skb, 1)) = 0; /* Keypad.Length = 0 */
108
109
110 *(skb_put(*skb, 1)) = 0; /* CallingPN.Length = 0 */
111 *(skb_put(*skb, 1)) = 0; /* CallingPSA.Length = 0 */
112
113 /* Called Party Number */
114 *(skb_put(*skb, 1)) = strlen(calledPN) + 1;
115 *(skb_put(*skb, 1)) = 0x81;
116 memcpy(skb_put(*skb, strlen(calledPN)), calledPN, strlen(calledPN));
117
118 /* '#' */
119
120 *(skb_put(*skb, 1)) = 0; /* CalledPSA.Length = 0 */
121
122 /* LLC.Length = 0; */
123 /* HLC0.Length = 0; */
124 /* HLC1.Length = 0; */
125 /* UTUS.Length = 0; */
126 memset(skb_put(*skb, 4), 0, 4);
127
128 return len;
129}
130
131int capi_conn_resp(struct pcbit_chan *chan, struct sk_buff **skb)
132{
133
134 if ((*skb = dev_alloc_skb(5)) == NULL) {
135
136 printk(KERN_WARNING "capi_conn_resp: alloc_skb failed\n");
137 return -1;
138 }
139
140 *((ushort *)skb_put(*skb, 2)) = chan->callref;
141 *(skb_put(*skb, 1)) = 0x01; /* ACCEPT_CALL */
142 *(skb_put(*skb, 1)) = 0;
143 *(skb_put(*skb, 1)) = 0;
144
145 return 5;
146}
147
148int capi_conn_active_req(struct pcbit_chan *chan, struct sk_buff **skb)
149{
150 /*
151 * 8 bytes
152 */
153
154 if ((*skb = dev_alloc_skb(8)) == NULL) {
155
156 printk(KERN_WARNING "capi_conn_active_req: alloc_skb failed\n");
157 return -1;
158 }
159
160 *((ushort *)skb_put(*skb, 2)) = chan->callref;
161
162#ifdef DEBUG
163 printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref);
164#endif
165
166 *(skb_put(*skb, 1)) = 0; /* BC.Length = 0; */
167 *(skb_put(*skb, 1)) = 0; /* ConnectedPN.Length = 0 */
168 *(skb_put(*skb, 1)) = 0; /* PSA.Length */
169 *(skb_put(*skb, 1)) = 0; /* LLC.Length = 0; */
170 *(skb_put(*skb, 1)) = 0; /* HLC.Length = 0; */
171 *(skb_put(*skb, 1)) = 0; /* UTUS.Length = 0; */
172
173 return 8;
174}
175
176int capi_conn_active_resp(struct pcbit_chan *chan, struct sk_buff **skb)
177{
178 /*
179 * 2 bytes
180 */
181
182 if ((*skb = dev_alloc_skb(2)) == NULL) {
183
184 printk(KERN_WARNING "capi_conn_active_resp: alloc_skb failed\n");
185 return -1;
186 }
187
188 *((ushort *)skb_put(*skb, 2)) = chan->callref;
189
190 return 2;
191}
192
193
194int capi_select_proto_req(struct pcbit_chan *chan, struct sk_buff **skb,
195 int outgoing)
196{
197
198 /*
199 * 18 bytes
200 */
201
202 if ((*skb = dev_alloc_skb(18)) == NULL) {
203
204 printk(KERN_WARNING "capi_select_proto_req: alloc_skb failed\n");
205 return -1;
206 }
207
208 *((ushort *)skb_put(*skb, 2)) = chan->callref;
209
210 /* Layer2 protocol */
211
212 switch (chan->proto) {
213 case ISDN_PROTO_L2_X75I:
214 *(skb_put(*skb, 1)) = 0x05; /* LAPB */
215 break;
216 case ISDN_PROTO_L2_HDLC:
217 *(skb_put(*skb, 1)) = 0x02;
218 break;
219 case ISDN_PROTO_L2_TRANS:
220 /*
221 * Voice (a-law)
222 */
223 *(skb_put(*skb, 1)) = 0x06;
224 break;
225 default:
226#ifdef DEBUG
227 printk(KERN_DEBUG "Transparent\n");
228#endif
229 *(skb_put(*skb, 1)) = 0x03;
230 break;
231 }
232
233 *(skb_put(*skb, 1)) = (outgoing ? 0x02 : 0x42); /* Don't ask */
234 *(skb_put(*skb, 1)) = 0x00;
235
236 *((ushort *) skb_put(*skb, 2)) = MRU;
237
238
239 *(skb_put(*skb, 1)) = 0x08; /* Modulo */
240 *(skb_put(*skb, 1)) = 0x07; /* Max Window */
241
242 *(skb_put(*skb, 1)) = 0x01; /* No Layer3 Protocol */
243
244 /*
245 * 2 - layer3 MTU [10]
246 * - Modulo [12]
247 * - Window
248 * - layer1 proto [14]
249 * - bitrate
250 * - sub-channel [16]
251 * - layer1dataformat [17]
252 */
253
254 memset(skb_put(*skb, 8), 0, 8);
255
256 return 18;
257}
258
259
260int capi_activate_transp_req(struct pcbit_chan *chan, struct sk_buff **skb)
261{
262
263 if ((*skb = dev_alloc_skb(7)) == NULL) {
264
265 printk(KERN_WARNING "capi_activate_transp_req: alloc_skb failed\n");
266 return -1;
267 }
268
269 *((ushort *)skb_put(*skb, 2)) = chan->callref;
270
271
272 *(skb_put(*skb, 1)) = chan->layer2link; /* Layer2 id */
273 *(skb_put(*skb, 1)) = 0x00; /* Transmit by default */
274
275 *((ushort *) skb_put(*skb, 2)) = MRU;
276
277 *(skb_put(*skb, 1)) = 0x01; /* Enables reception*/
278
279 return 7;
280}
281
282int capi_tdata_req(struct pcbit_chan *chan, struct sk_buff *skb)
283{
284 ushort data_len;
285
286
287 /*
288 * callref - 2
289 * layer2link - 1
290 * wBlockLength - 2
291 * data - 4
292 * sernum - 1
293 */
294
295 data_len = skb->len;
296
297 if (skb_headroom(skb) < 10)
298 {
299 printk(KERN_CRIT "No headspace (%u) on headroom %p for capi header\n", skb_headroom(skb), skb);
300 }
301 else
302 {
303 skb_push(skb, 10);
304 }
305
306 *((u16 *) (skb->data)) = chan->callref;
307 skb->data[2] = chan->layer2link;
308 *((u16 *) (skb->data + 3)) = data_len;
309
310 chan->s_refnum = (chan->s_refnum + 1) % 8;
311 *((u32 *) (skb->data + 5)) = chan->s_refnum;
312
313 skb->data[9] = 0; /* HDLC frame number */
314
315 return 10;
316}
317
318int capi_tdata_resp(struct pcbit_chan *chan, struct sk_buff **skb)
319
320{
321 if ((*skb = dev_alloc_skb(4)) == NULL) {
322
323 printk(KERN_WARNING "capi_tdata_resp: alloc_skb failed\n");
324 return -1;
325 }
326
327 *((ushort *)skb_put(*skb, 2)) = chan->callref;
328
329 *(skb_put(*skb, 1)) = chan->layer2link;
330 *(skb_put(*skb, 1)) = chan->r_refnum;
331
332 return (*skb)->len;
333}
334
335int capi_disc_req(ushort callref, struct sk_buff **skb, u_char cause)
336{
337
338 if ((*skb = dev_alloc_skb(6)) == NULL) {
339
340 printk(KERN_WARNING "capi_disc_req: alloc_skb failed\n");
341 return -1;
342 }
343
344 *((ushort *)skb_put(*skb, 2)) = callref;
345
346 *(skb_put(*skb, 1)) = 2; /* Cause.Length = 2; */
347 *(skb_put(*skb, 1)) = 0x80;
348 *(skb_put(*skb, 1)) = 0x80 | cause;
349
350 /*
351 * Change it: we should send 'Sic transit gloria Mundi' here ;-)
352 */
353
354 *(skb_put(*skb, 1)) = 0; /* UTUS.Length = 0; */
355
356 return 6;
357}
358
359int capi_disc_resp(struct pcbit_chan *chan, struct sk_buff **skb)
360{
361 if ((*skb = dev_alloc_skb(2)) == NULL) {
362
363 printk(KERN_WARNING "capi_disc_resp: alloc_skb failed\n");
364 return -1;
365 }
366
367 *((ushort *)skb_put(*skb, 2)) = chan->callref;
368
369 return 2;
370}
371
372
373/*
374 * Decoding of CAPI messages
375 *
376 */
377
378int capi_decode_conn_ind(struct pcbit_chan *chan,
379 struct sk_buff *skb,
380 struct callb_data *info)
381{
382 int CIlen, len;
383
384 /* Call Reference [CAPI] */
385 chan->callref = *((ushort *)skb->data);
386 skb_pull(skb, 2);
387
388#ifdef DEBUG
389 printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref);
390#endif
391
392 /* Channel Identification */
393
394 /* Expect
395 Len = 1
396 Octect 3 = 0100 10CC - [ 7 Basic, 4 , 2-1 chan ]
397 */
398
399 CIlen = skb->data[0];
400#ifdef DEBUG
401 if (CIlen == 1) {
402
403 if (((skb->data[1]) & 0xFC) == 0x48)
404 printk(KERN_DEBUG "decode_conn_ind: chan ok\n");
405 printk(KERN_DEBUG "phyChan = %d\n", skb->data[1] & 0x03);
406 }
407 else
408 printk(KERN_DEBUG "conn_ind: CIlen = %d\n", CIlen);
409#endif
410 skb_pull(skb, CIlen + 1);
411
412 /* Calling Party Number */
413 /* An "additional service" as far as Portugal Telecom is concerned */
414
415 len = skb->data[0];
416
417 if (len > 0) {
418 int count = 1;
419
420#ifdef DEBUG
421 printk(KERN_DEBUG "CPN: Octect 3 %02x\n", skb->data[1]);
422#endif
423 if ((skb->data[1] & 0x80) == 0)
424 count = 2;
425
426 if (!(info->data.setup.CallingPN = kmalloc(len - count + 1, GFP_ATOMIC)))
427 return -1;
428
429 skb_copy_from_linear_data_offset(skb, count + 1,
430 info->data.setup.CallingPN,
431 len - count);
432 info->data.setup.CallingPN[len - count] = 0;
433
434 }
435 else {
436 info->data.setup.CallingPN = NULL;
437 printk(KERN_DEBUG "NULL CallingPN\n");
438 }
439
440 skb_pull(skb, len + 1);
441
442 /* Calling Party Subaddress */
443 skb_pull(skb, skb->data[0] + 1);
444
445 /* Called Party Number */
446
447 len = skb->data[0];
448
449 if (len > 0) {
450 int count = 1;
451
452 if ((skb->data[1] & 0x80) == 0)
453 count = 2;
454
455 if (!(info->data.setup.CalledPN = kmalloc(len - count + 1, GFP_ATOMIC)))
456 return -1;
457
458 skb_copy_from_linear_data_offset(skb, count + 1,
459 info->data.setup.CalledPN,
460 len - count);
461 info->data.setup.CalledPN[len - count] = 0;
462
463 }
464 else {
465 info->data.setup.CalledPN = NULL;
466 printk(KERN_DEBUG "NULL CalledPN\n");
467 }
468
469 skb_pull(skb, len + 1);
470
471 /* Called Party Subaddress */
472 skb_pull(skb, skb->data[0] + 1);
473
474 /* LLC */
475 skb_pull(skb, skb->data[0] + 1);
476
477 /* HLC */
478 skb_pull(skb, skb->data[0] + 1);
479
480 /* U2U */
481 skb_pull(skb, skb->data[0] + 1);
482
483 return 0;
484}
485
486/*
487 * returns errcode
488 */
489
490int capi_decode_conn_conf(struct pcbit_chan *chan, struct sk_buff *skb,
491 int *complete)
492{
493 int errcode;
494
495 chan->callref = *((ushort *)skb->data); /* Update CallReference */
496 skb_pull(skb, 2);
497
498 errcode = *((ushort *) skb->data); /* read errcode */
499 skb_pull(skb, 2);
500
501 *complete = *(skb->data);
502 skb_pull(skb, 1);
503
504 /* FIX ME */
505 /* This is actually a firmware bug */
506 if (!*complete)
507 {
508 printk(KERN_DEBUG "complete=%02x\n", *complete);
509 *complete = 1;
510 }
511
512
513 /* Optional Bearer Capability */
514 skb_pull(skb, *(skb->data) + 1);
515
516 /* Channel Identification */
517 skb_pull(skb, *(skb->data) + 1);
518
519 /* High Layer Compatibility follows */
520 skb_pull(skb, *(skb->data) + 1);
521
522 return errcode;
523}
524
525int capi_decode_conn_actv_ind(struct pcbit_chan *chan, struct sk_buff *skb)
526{
527 ushort len;
528#ifdef DEBUG
529 char str[32];
530#endif
531
532 /* Yet Another Bearer Capability */
533 skb_pull(skb, *(skb->data) + 1);
534
535
536 /* Connected Party Number */
537 len = *(skb->data);
538
539#ifdef DEBUG
540 if (len > 1 && len < 31) {
541 skb_copy_from_linear_data_offset(skb, 2, str, len - 1);
542 str[len] = 0;
543 printk(KERN_DEBUG "Connected Party Number: %s\n", str);
544 }
545 else
546 printk(KERN_DEBUG "actv_ind CPN len = %d\n", len);
547#endif
548
549 skb_pull(skb, len + 1);
550
551 /* Connected Subaddress */
552 skb_pull(skb, *(skb->data) + 1);
553
554 /* Low Layer Capability */
555 skb_pull(skb, *(skb->data) + 1);
556
557 /* High Layer Capability */
558 skb_pull(skb, *(skb->data) + 1);
559
560 return 0;
561}
562
563int capi_decode_conn_actv_conf(struct pcbit_chan *chan, struct sk_buff *skb)
564{
565 ushort errcode;
566
567 errcode = *((ushort *)skb->data);
568 skb_pull(skb, 2);
569
570 /* Channel Identification
571 skb_pull(skb, skb->data[0] + 1);
572 */
573 return errcode;
574}
575
576
577int capi_decode_sel_proto_conf(struct pcbit_chan *chan, struct sk_buff *skb)
578{
579 ushort errcode;
580
581 chan->layer2link = *(skb->data);
582 skb_pull(skb, 1);
583
584 errcode = *((ushort *)skb->data);
585 skb_pull(skb, 2);
586
587 return errcode;
588}
589
590int capi_decode_actv_trans_conf(struct pcbit_chan *chan, struct sk_buff *skb)
591{
592 ushort errcode;
593
594 if (chan->layer2link != *(skb->data))
595 printk("capi_decode_actv_trans_conf: layer2link doesn't match\n");
596
597 skb_pull(skb, 1);
598
599 errcode = *((ushort *)skb->data);
600 skb_pull(skb, 2);
601
602 return errcode;
603}
604
605int capi_decode_disc_ind(struct pcbit_chan *chan, struct sk_buff *skb)
606{
607 ushort len;
608#ifdef DEBUG
609 int i;
610#endif
611 /* Cause */
612
613 len = *(skb->data);
614 skb_pull(skb, 1);
615
616#ifdef DEBUG
617
618 for (i = 0; i < len; i++)
619 printk(KERN_DEBUG "Cause Octect %d: %02x\n", i + 3,
620 *(skb->data + i));
621#endif
622
623 skb_pull(skb, len);
624
625 return 0;
626}
627
628#ifdef DEBUG
629int capi_decode_debug_188(u_char *hdr, ushort hdrlen)
630{
631 char str[64];
632 int len;
633
634 len = hdr[0];
635
636 if (len < 64 && len == hdrlen - 1) {
637 memcpy(str, hdr + 1, hdrlen - 1);
638 str[hdrlen - 1] = 0;
639 printk("%s\n", str);
640 }
641 else
642 printk("debug message incorrect\n");
643
644 return 0;
645}
646#endif
diff --git a/drivers/staging/i4l/pcbit/capi.h b/drivers/staging/i4l/pcbit/capi.h
deleted file mode 100644
index 6f6f4dd0714e..000000000000
--- a/drivers/staging/i4l/pcbit/capi.h
+++ /dev/null
@@ -1,81 +0,0 @@
1/*
2 * CAPI encode/decode prototypes and defines
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12#ifndef CAPI_H
13#define CAPI_H
14
15
16#define REQ_CAUSE 0x01
17#define REQ_DISPLAY 0x04
18#define REQ_USER_TO_USER 0x08
19
20#define AppInfoMask (REQ_CAUSE | REQ_DISPLAY | REQ_USER_TO_USER)
21
22/* Connection Setup */
23extern int capi_conn_req(const char *calledPN, struct sk_buff **buf,
24 int proto);
25extern int capi_decode_conn_conf(struct pcbit_chan *chan, struct sk_buff *skb,
26 int *complete);
27
28extern int capi_decode_conn_ind(struct pcbit_chan *chan, struct sk_buff *skb,
29 struct callb_data *info);
30extern int capi_conn_resp(struct pcbit_chan *chan, struct sk_buff **skb);
31
32extern int capi_conn_active_req(struct pcbit_chan *chan, struct sk_buff **skb);
33extern int capi_decode_conn_actv_conf(struct pcbit_chan *chan,
34 struct sk_buff *skb);
35
36extern int capi_decode_conn_actv_ind(struct pcbit_chan *chan,
37 struct sk_buff *skb);
38extern int capi_conn_active_resp(struct pcbit_chan *chan,
39 struct sk_buff **skb);
40
41/* Data */
42extern int capi_select_proto_req(struct pcbit_chan *chan, struct sk_buff **skb,
43 int outgoing);
44extern int capi_decode_sel_proto_conf(struct pcbit_chan *chan,
45 struct sk_buff *skb);
46
47extern int capi_activate_transp_req(struct pcbit_chan *chan,
48 struct sk_buff **skb);
49extern int capi_decode_actv_trans_conf(struct pcbit_chan *chan,
50 struct sk_buff *skb);
51
52extern int capi_tdata_req(struct pcbit_chan *chan, struct sk_buff *skb);
53extern int capi_tdata_resp(struct pcbit_chan *chan, struct sk_buff **skb);
54
55/* Connection Termination */
56extern int capi_disc_req(ushort callref, struct sk_buff **skb, u_char cause);
57
58extern int capi_decode_disc_ind(struct pcbit_chan *chan, struct sk_buff *skb);
59extern int capi_disc_resp(struct pcbit_chan *chan, struct sk_buff **skb);
60
61#ifdef DEBUG
62extern int capi_decode_debug_188(u_char *hdr, ushort hdrlen);
63#endif
64
65static inline struct pcbit_chan *
66capi_channel(struct pcbit_dev *dev, struct sk_buff *skb)
67{
68 ushort callref;
69
70 callref = *((ushort *)skb->data);
71 skb_pull(skb, 2);
72
73 if (dev->b1->callref == callref)
74 return dev->b1;
75 else if (dev->b2->callref == callref)
76 return dev->b2;
77
78 return NULL;
79}
80
81#endif
diff --git a/drivers/staging/i4l/pcbit/drv.c b/drivers/staging/i4l/pcbit/drv.c
deleted file mode 100644
index 89b0b5b94ce5..000000000000
--- a/drivers/staging/i4l/pcbit/drv.c
+++ /dev/null
@@ -1,1070 +0,0 @@
1/*
2 * PCBIT-D interface with isdn4linux
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12/*
13 * Fixes:
14 *
15 * Nuno Grilo <l38486@alfa.ist.utl.pt>
16 * fixed msn_list NULL pointer dereference.
17 *
18 */
19
20#include <linux/module.h>
21
22
23#include <linux/kernel.h>
24
25#include <linux/types.h>
26#include <linux/sched.h>
27#include <linux/slab.h>
28#include <linux/mm.h>
29#include <linux/interrupt.h>
30#include <linux/skbuff.h>
31
32#include <linux/isdnif.h>
33#include <linux/string.h>
34#include <linux/io.h>
35#include <linux/ioport.h>
36
37#include "pcbit.h"
38#include "edss1.h"
39#include "layer2.h"
40#include "capi.h"
41
42
43extern ushort last_ref_num;
44
45static int pcbit_ioctl(isdn_ctrl *ctl);
46
47static char *pcbit_devname[MAX_PCBIT_CARDS] = {
48 "pcbit0",
49 "pcbit1",
50 "pcbit2",
51 "pcbit3"
52};
53
54/*
55 * prototypes
56 */
57
58static int pcbit_command(isdn_ctrl *ctl);
59static int pcbit_stat(u_char __user *buf, int len, int, int);
60static int pcbit_xmit(int driver, int chan, int ack, struct sk_buff *skb);
61static int pcbit_writecmd(const u_char __user *, int, int, int);
62
63static int set_protocol_running(struct pcbit_dev *dev);
64
65static void pcbit_clear_msn(struct pcbit_dev *dev);
66static void pcbit_set_msn(struct pcbit_dev *dev, char *list);
67static int pcbit_check_msn(struct pcbit_dev *dev, char *msn);
68
69
70int pcbit_init_dev(int board, int mem_base, int irq)
71{
72 struct pcbit_dev *dev;
73 isdn_if *dev_if;
74
75 if ((dev = kzalloc(sizeof(struct pcbit_dev), GFP_KERNEL)) == NULL)
76 {
77 printk("pcbit_init: couldn't malloc pcbit_dev struct\n");
78 return -ENOMEM;
79 }
80
81 dev_pcbit[board] = dev;
82 init_waitqueue_head(&dev->set_running_wq);
83 spin_lock_init(&dev->lock);
84
85 if (mem_base >= 0xA0000 && mem_base <= 0xFFFFF) {
86 dev->ph_mem = mem_base;
87 if (!request_mem_region(dev->ph_mem, 4096, "PCBIT mem")) {
88 printk(KERN_WARNING
89 "PCBIT: memory region %lx-%lx already in use\n",
90 dev->ph_mem, dev->ph_mem + 4096);
91 kfree(dev);
92 dev_pcbit[board] = NULL;
93 return -EACCES;
94 }
95 dev->sh_mem = ioremap(dev->ph_mem, 4096);
96 }
97 else
98 {
99 printk("memory address invalid");
100 kfree(dev);
101 dev_pcbit[board] = NULL;
102 return -EACCES;
103 }
104
105 dev->b1 = kzalloc(sizeof(struct pcbit_chan), GFP_KERNEL);
106 if (!dev->b1) {
107 printk("pcbit_init: couldn't malloc pcbit_chan struct\n");
108 iounmap(dev->sh_mem);
109 release_mem_region(dev->ph_mem, 4096);
110 kfree(dev);
111 return -ENOMEM;
112 }
113
114 dev->b2 = kzalloc(sizeof(struct pcbit_chan), GFP_KERNEL);
115 if (!dev->b2) {
116 printk("pcbit_init: couldn't malloc pcbit_chan struct\n");
117 kfree(dev->b1);
118 iounmap(dev->sh_mem);
119 release_mem_region(dev->ph_mem, 4096);
120 kfree(dev);
121 return -ENOMEM;
122 }
123
124 dev->b2->id = 1;
125
126 INIT_WORK(&dev->qdelivery, pcbit_deliver);
127
128 /*
129 * interrupts
130 */
131
132 if (request_irq(irq, &pcbit_irq_handler, 0, pcbit_devname[board], dev) != 0)
133 {
134 kfree(dev->b1);
135 kfree(dev->b2);
136 iounmap(dev->sh_mem);
137 release_mem_region(dev->ph_mem, 4096);
138 kfree(dev);
139 dev_pcbit[board] = NULL;
140 return -EIO;
141 }
142
143 dev->irq = irq;
144
145 /* next frame to be received */
146 dev->rcv_seq = 0;
147 dev->send_seq = 0;
148 dev->unack_seq = 0;
149
150 dev->hl_hdrlen = 16;
151
152 dev_if = kmalloc(sizeof(isdn_if), GFP_KERNEL);
153
154 if (!dev_if) {
155 free_irq(irq, dev);
156 kfree(dev->b1);
157 kfree(dev->b2);
158 iounmap(dev->sh_mem);
159 release_mem_region(dev->ph_mem, 4096);
160 kfree(dev);
161 dev_pcbit[board] = NULL;
162 return -EIO;
163 }
164
165 dev->dev_if = dev_if;
166
167 dev_if->owner = THIS_MODULE;
168
169 dev_if->channels = 2;
170
171 dev_if->features = (ISDN_FEATURE_P_EURO | ISDN_FEATURE_L3_TRANS |
172 ISDN_FEATURE_L2_HDLC | ISDN_FEATURE_L2_TRANS);
173
174 dev_if->writebuf_skb = pcbit_xmit;
175 dev_if->hl_hdrlen = 16;
176
177 dev_if->maxbufsize = MAXBUFSIZE;
178 dev_if->command = pcbit_command;
179
180 dev_if->writecmd = pcbit_writecmd;
181 dev_if->readstat = pcbit_stat;
182
183
184 strcpy(dev_if->id, pcbit_devname[board]);
185
186 if (!register_isdn(dev_if)) {
187 free_irq(irq, dev);
188 kfree(dev->b1);
189 kfree(dev->b2);
190 iounmap(dev->sh_mem);
191 release_mem_region(dev->ph_mem, 4096);
192 kfree(dev);
193 dev_pcbit[board] = NULL;
194 return -EIO;
195 }
196
197 dev->id = dev_if->channels;
198
199
200 dev->l2_state = L2_DOWN;
201 dev->free = 511;
202
203 /*
204 * set_protocol_running(dev);
205 */
206
207 return 0;
208}
209
210#ifdef MODULE
211void pcbit_terminate(int board)
212{
213 struct pcbit_dev *dev;
214
215 dev = dev_pcbit[board];
216
217 if (dev) {
218 /* unregister_isdn(dev->dev_if); */
219 free_irq(dev->irq, dev);
220 pcbit_clear_msn(dev);
221 kfree(dev->dev_if);
222 if (dev->b1->fsm_timer.function)
223 del_timer(&dev->b1->fsm_timer);
224 if (dev->b2->fsm_timer.function)
225 del_timer(&dev->b2->fsm_timer);
226 kfree(dev->b1);
227 kfree(dev->b2);
228 iounmap(dev->sh_mem);
229 release_mem_region(dev->ph_mem, 4096);
230 kfree(dev);
231 }
232}
233#endif
234
235static int pcbit_command(isdn_ctrl *ctl)
236{
237 struct pcbit_dev *dev;
238 struct pcbit_chan *chan;
239 struct callb_data info;
240
241 dev = finddev(ctl->driver);
242
243 if (!dev)
244 {
245 printk("pcbit_command: unknown device\n");
246 return -1;
247 }
248
249 chan = (ctl->arg & 0x0F) ? dev->b2 : dev->b1;
250
251
252 switch (ctl->command) {
253 case ISDN_CMD_IOCTL:
254 return pcbit_ioctl(ctl);
255 break;
256 case ISDN_CMD_DIAL:
257 info.type = EV_USR_SETUP_REQ;
258 info.data.setup.CalledPN = (char *) &ctl->parm.setup.phone;
259 pcbit_fsm_event(dev, chan, EV_USR_SETUP_REQ, &info);
260 break;
261 case ISDN_CMD_ACCEPTD:
262 pcbit_fsm_event(dev, chan, EV_USR_SETUP_RESP, NULL);
263 break;
264 case ISDN_CMD_ACCEPTB:
265 printk("ISDN_CMD_ACCEPTB - not really needed\n");
266 break;
267 case ISDN_CMD_HANGUP:
268 pcbit_fsm_event(dev, chan, EV_USR_RELEASE_REQ, NULL);
269 break;
270 case ISDN_CMD_SETL2:
271 chan->proto = (ctl->arg >> 8);
272 break;
273 case ISDN_CMD_CLREAZ:
274 pcbit_clear_msn(dev);
275 break;
276 case ISDN_CMD_SETEAZ:
277 pcbit_set_msn(dev, ctl->parm.num);
278 break;
279 case ISDN_CMD_SETL3:
280 if ((ctl->arg >> 8) != ISDN_PROTO_L3_TRANS)
281 printk(KERN_DEBUG "L3 protocol unknown\n");
282 break;
283 default:
284 printk(KERN_DEBUG "pcbit_command: unknown command\n");
285 break;
286 }
287
288 return 0;
289}
290
291/*
292 * Another Hack :-(
293 * on some conditions the board stops sending TDATA_CONFs
294 * let's see if we can turn around the problem
295 */
296
297#ifdef BLOCK_TIMER
298static void pcbit_block_timer(unsigned long data)
299{
300 struct pcbit_chan *chan;
301 struct pcbit_dev *dev;
302 isdn_ctrl ictl;
303
304 chan = (struct pcbit_chan *)data;
305
306 dev = chan2dev(chan);
307
308 if (dev == NULL) {
309 printk(KERN_DEBUG "pcbit: chan2dev failed\n");
310 return;
311 }
312
313 del_timer(&chan->block_timer);
314 chan->block_timer.function = NULL;
315
316#ifdef DEBUG
317 printk(KERN_DEBUG "pcbit_block_timer\n");
318#endif
319 chan->queued = 0;
320 ictl.driver = dev->id;
321 ictl.command = ISDN_STAT_BSENT;
322 ictl.arg = chan->id;
323 dev->dev_if->statcallb(&ictl);
324}
325#endif
326
327static int pcbit_xmit(int driver, int chnum, int ack, struct sk_buff *skb)
328{
329 ushort hdrlen;
330 int refnum, len;
331 struct pcbit_chan *chan;
332 struct pcbit_dev *dev;
333
334 dev = finddev(driver);
335 if (dev == NULL)
336 {
337 printk("finddev returned NULL");
338 return -1;
339 }
340
341 chan = chnum ? dev->b2 : dev->b1;
342
343
344 if (chan->fsm_state != ST_ACTIVE)
345 return -1;
346
347 if (chan->queued >= MAX_QUEUED)
348 {
349#ifdef DEBUG_QUEUE
350 printk(KERN_DEBUG
351 "pcbit: %d packets already in queue - write fails\n",
352 chan->queued);
353#endif
354 /*
355 * packet stays on the head of the device queue
356 * since dev_start_xmit will fail
357 * see net/core/dev.c
358 */
359#ifdef BLOCK_TIMER
360 if (chan->block_timer.function == NULL) {
361 setup_timer(&chan->block_timer, &pcbit_block_timer,
362 (long)chan);
363 mod_timer(&chan->block_timer, jiffies + 1 * HZ);
364 }
365#endif
366 return 0;
367 }
368
369
370 chan->queued++;
371
372 len = skb->len;
373
374 hdrlen = capi_tdata_req(chan, skb);
375
376 refnum = last_ref_num++ & 0x7fffU;
377 chan->s_refnum = refnum;
378
379 pcbit_l2_write(dev, MSG_TDATA_REQ, refnum, skb, hdrlen);
380
381 return len;
382}
383
384static int pcbit_writecmd(const u_char __user *buf, int len, int driver, int channel)
385{
386 struct pcbit_dev *dev;
387 int i, j;
388 const u_char *loadbuf;
389 u_char *ptr = NULL;
390 u_char *cbuf;
391
392 int errstat;
393
394 dev = finddev(driver);
395
396 if (!dev)
397 {
398 printk("pcbit_writecmd: couldn't find device");
399 return -ENODEV;
400 }
401
402 switch (dev->l2_state) {
403 case L2_LWMODE:
404 /* check (size <= rdp_size); write buf into board */
405 if (len < 0 || len > BANK4 + 1 || len > 1024)
406 {
407 printk("pcbit_writecmd: invalid length %d\n", len);
408 return -EINVAL;
409 }
410
411 cbuf = memdup_user(buf, len);
412 if (IS_ERR(cbuf))
413 return PTR_ERR(cbuf);
414
415 memcpy_toio(dev->sh_mem, cbuf, len);
416 kfree(cbuf);
417 return len;
418 case L2_FWMODE:
419 /* this is the hard part */
420 /* dumb board */
421 /* get it into kernel space */
422 if ((ptr = kmalloc(len, GFP_KERNEL)) == NULL)
423 return -ENOMEM;
424 if (copy_from_user(ptr, buf, len)) {
425 kfree(ptr);
426 return -EFAULT;
427 }
428 loadbuf = ptr;
429
430 errstat = 0;
431
432 for (i = 0; i < len; i++)
433 {
434 for (j = 0; j < LOAD_RETRY; j++)
435 if (!(readb(dev->sh_mem + dev->loadptr)))
436 break;
437
438 if (j == LOAD_RETRY)
439 {
440 errstat = -ETIME;
441 printk("TIMEOUT i=%d\n", i);
442 break;
443 }
444 writeb(loadbuf[i], dev->sh_mem + dev->loadptr + 1);
445 writeb(0x01, dev->sh_mem + dev->loadptr);
446
447 dev->loadptr += 2;
448 if (dev->loadptr > LOAD_ZONE_END)
449 dev->loadptr = LOAD_ZONE_START;
450 }
451 kfree(ptr);
452
453 return errstat ? errstat : len;
454 default:
455 return -EBUSY;
456 }
457}
458
459/*
460 * demultiplexing of messages
461 *
462 */
463
464void pcbit_l3_receive(struct pcbit_dev *dev, ulong msg,
465 struct sk_buff *skb,
466 ushort hdr_len, ushort refnum)
467{
468 struct pcbit_chan *chan;
469 struct sk_buff *skb2;
470 unsigned short len;
471 struct callb_data cbdata;
472 int complete, err;
473 isdn_ctrl ictl;
474
475 switch (msg) {
476
477 case MSG_TDATA_IND:
478 if (!(chan = capi_channel(dev, skb))) {
479 printk(KERN_WARNING
480 "CAPI header: unknown channel id\n");
481 break;
482 }
483 chan->r_refnum = skb->data[7];
484 skb_pull(skb, 8);
485
486 dev->dev_if->rcvcallb_skb(dev->id, chan->id, skb);
487
488 if (capi_tdata_resp(chan, &skb2) > 0)
489 pcbit_l2_write(dev, MSG_TDATA_RESP, refnum,
490 skb2, skb2->len);
491 return;
492 break;
493 case MSG_TDATA_CONF:
494 if (!(chan = capi_channel(dev, skb))) {
495 printk(KERN_WARNING
496 "CAPI header: unknown channel id\n");
497 break;
498 }
499
500#ifdef DEBUG
501 if ((*((ushort *)(skb->data + 2))) != 0) {
502 printk(KERN_DEBUG "TDATA_CONF error\n");
503 }
504#endif
505#ifdef BLOCK_TIMER
506 if (chan->queued == MAX_QUEUED) {
507 del_timer(&chan->block_timer);
508 chan->block_timer.function = NULL;
509 }
510
511#endif
512 chan->queued--;
513
514 ictl.driver = dev->id;
515 ictl.command = ISDN_STAT_BSENT;
516 ictl.arg = chan->id;
517 dev->dev_if->statcallb(&ictl);
518 break;
519
520 case MSG_CONN_IND:
521 /*
522 * channel: 1st not used will do
523 * if both are used we're in trouble
524 */
525
526 if (!dev->b1->fsm_state)
527 chan = dev->b1;
528 else if (!dev->b2->fsm_state)
529 chan = dev->b2;
530 else {
531 printk(KERN_INFO
532 "Incoming connection: no channels available");
533
534 if ((len = capi_disc_req(*(ushort *)(skb->data), &skb2, CAUSE_NOCHAN)) > 0)
535 pcbit_l2_write(dev, MSG_DISC_REQ, refnum, skb2, len);
536 break;
537 }
538
539 cbdata.data.setup.CalledPN = NULL;
540 cbdata.data.setup.CallingPN = NULL;
541
542 capi_decode_conn_ind(chan, skb, &cbdata);
543 cbdata.type = EV_NET_SETUP;
544
545 pcbit_fsm_event(dev, chan, EV_NET_SETUP, NULL);
546
547 if (pcbit_check_msn(dev, cbdata.data.setup.CallingPN))
548 pcbit_fsm_event(dev, chan, EV_USR_PROCED_REQ, &cbdata);
549 else
550 pcbit_fsm_event(dev, chan, EV_USR_RELEASE_REQ, NULL);
551
552 kfree(cbdata.data.setup.CalledPN);
553 kfree(cbdata.data.setup.CallingPN);
554 break;
555
556 case MSG_CONN_CONF:
557 /*
558 * We should be able to find the channel by the message
559 * reference number. The current version of the firmware
560 * doesn't sent the ref number correctly.
561 */
562#ifdef DEBUG
563 printk(KERN_DEBUG "refnum=%04x b1=%04x b2=%04x\n", refnum,
564 dev->b1->s_refnum,
565 dev->b2->s_refnum);
566#endif
567 /* We just try to find a channel in the right state */
568
569 if (dev->b1->fsm_state == ST_CALL_INIT)
570 chan = dev->b1;
571 else {
572 if (dev->b2->s_refnum == ST_CALL_INIT)
573 chan = dev->b2;
574 else {
575 chan = NULL;
576 printk(KERN_WARNING "Connection Confirm - no channel in Call Init state\n");
577 break;
578 }
579 }
580 if (capi_decode_conn_conf(chan, skb, &complete)) {
581 printk(KERN_DEBUG "conn_conf indicates error\n");
582 pcbit_fsm_event(dev, chan, EV_ERROR, NULL);
583 }
584 else
585 if (complete)
586 pcbit_fsm_event(dev, chan, EV_NET_CALL_PROC, NULL);
587 else
588 pcbit_fsm_event(dev, chan, EV_NET_SETUP_ACK, NULL);
589 break;
590 case MSG_CONN_ACTV_IND:
591
592 if (!(chan = capi_channel(dev, skb))) {
593 printk(KERN_WARNING
594 "CAPI header: unknown channel id\n");
595 break;
596 }
597
598 if (capi_decode_conn_actv_ind(chan, skb)) {
599 printk("error in capi_decode_conn_actv_ind\n");
600 /* pcbit_fsm_event(dev, chan, EV_ERROR, NULL); */
601 break;
602 }
603 chan->r_refnum = refnum;
604 pcbit_fsm_event(dev, chan, EV_NET_CONN, NULL);
605 break;
606 case MSG_CONN_ACTV_CONF:
607
608 if (!(chan = capi_channel(dev, skb))) {
609 printk(KERN_WARNING
610 "CAPI header: unknown channel id\n");
611 break;
612 }
613
614 if (capi_decode_conn_actv_conf(chan, skb) == 0)
615 pcbit_fsm_event(dev, chan, EV_NET_CONN_ACK, NULL);
616
617 else
618 printk(KERN_DEBUG "decode_conn_actv_conf failed\n");
619 break;
620
621 case MSG_SELP_CONF:
622
623 if (!(chan = capi_channel(dev, skb))) {
624 printk(KERN_WARNING
625 "CAPI header: unknown channel id\n");
626 break;
627 }
628
629 if (!(err = capi_decode_sel_proto_conf(chan, skb)))
630 pcbit_fsm_event(dev, chan, EV_NET_SELP_RESP, NULL);
631 else {
632 /* Error */
633 printk("error %d - capi_decode_sel_proto_conf\n", err);
634 }
635 break;
636 case MSG_ACT_TRANSP_CONF:
637 if (!(chan = capi_channel(dev, skb))) {
638 printk(KERN_WARNING
639 "CAPI header: unknown channel id\n");
640 break;
641 }
642
643 if (!capi_decode_actv_trans_conf(chan, skb))
644 pcbit_fsm_event(dev, chan, EV_NET_ACTV_RESP, NULL);
645 break;
646
647 case MSG_DISC_IND:
648
649 if (!(chan = capi_channel(dev, skb))) {
650 printk(KERN_WARNING
651 "CAPI header: unknown channel id\n");
652 break;
653 }
654
655 if (!capi_decode_disc_ind(chan, skb))
656 pcbit_fsm_event(dev, chan, EV_NET_DISC, NULL);
657 else
658 printk(KERN_WARNING "capi_decode_disc_ind - error\n");
659 break;
660 case MSG_DISC_CONF:
661 if (!(chan = capi_channel(dev, skb))) {
662 printk(KERN_WARNING
663 "CAPI header: unknown channel id\n");
664 break;
665 }
666
667 if (!capi_decode_disc_ind(chan, skb))
668 pcbit_fsm_event(dev, chan, EV_NET_RELEASE, NULL);
669 else
670 printk(KERN_WARNING "capi_decode_disc_conf - error\n");
671 break;
672 case MSG_INFO_IND:
673#ifdef DEBUG
674 printk(KERN_DEBUG "received Info Indication - discarded\n");
675#endif
676 break;
677#ifdef DEBUG
678 case MSG_DEBUG_188:
679 capi_decode_debug_188(skb->data, skb->len);
680 break;
681
682 default:
683 printk(KERN_DEBUG "pcbit_l3_receive: unknown message %08lx\n",
684 msg);
685 break;
686#endif
687 }
688
689 kfree_skb(skb);
690
691}
692
693/*
694 * Single statbuf
695 * should be a statbuf per device
696 */
697
698static char statbuf[STATBUF_LEN];
699static int stat_st;
700static int stat_end;
701
702static int pcbit_stat(u_char __user *buf, int len, int driver, int channel)
703{
704 int stat_count;
705 stat_count = stat_end - stat_st;
706
707 if (stat_count < 0)
708 stat_count = STATBUF_LEN - stat_st + stat_end;
709
710 /* FIXME: should we sleep and wait for more cookies ? */
711 if (len > stat_count)
712 len = stat_count;
713
714 if (stat_st < stat_end)
715 {
716 if (copy_to_user(buf, statbuf + stat_st, len))
717 return -EFAULT;
718 stat_st += len;
719 }
720 else
721 {
722 if (len > STATBUF_LEN - stat_st)
723 {
724 if (copy_to_user(buf, statbuf + stat_st,
725 STATBUF_LEN - stat_st))
726 return -EFAULT;
727 if (copy_to_user(buf, statbuf,
728 len - (STATBUF_LEN - stat_st)))
729 return -EFAULT;
730
731 stat_st = len - (STATBUF_LEN - stat_st);
732 }
733 else
734 {
735 if (copy_to_user(buf, statbuf + stat_st, len))
736 return -EFAULT;
737
738 stat_st += len;
739
740 if (stat_st == STATBUF_LEN)
741 stat_st = 0;
742 }
743 }
744
745 if (stat_st == stat_end)
746 stat_st = stat_end = 0;
747
748 return len;
749}
750
751static void pcbit_logstat(struct pcbit_dev *dev, char *str)
752{
753 int i;
754 isdn_ctrl ictl;
755
756 for (i = stat_end; i < strlen(str); i++)
757 {
758 statbuf[i] = str[i];
759 stat_end = (stat_end + 1) % STATBUF_LEN;
760 if (stat_end == stat_st)
761 stat_st = (stat_st + 1) % STATBUF_LEN;
762 }
763
764 ictl.command = ISDN_STAT_STAVAIL;
765 ictl.driver = dev->id;
766 ictl.arg = strlen(str);
767 dev->dev_if->statcallb(&ictl);
768}
769
770void pcbit_state_change(struct pcbit_dev *dev, struct pcbit_chan *chan,
771 unsigned short i, unsigned short ev, unsigned short f)
772{
773 char buf[256];
774
775 sprintf(buf, "change on device: %d channel:%d\n%s -> %s -> %s\n",
776 dev->id, chan->id,
777 isdn_state_table[i], strisdnevent(ev), isdn_state_table[f]
778 );
779
780#ifdef DEBUG
781 printk("%s", buf);
782#endif
783
784 pcbit_logstat(dev, buf);
785}
786
787static void set_running_timeout(unsigned long ptr)
788{
789 struct pcbit_dev *dev;
790
791#ifdef DEBUG
792 printk(KERN_DEBUG "set_running_timeout\n");
793#endif
794 dev = (struct pcbit_dev *) ptr;
795
796 dev->l2_state = L2_DOWN;
797 wake_up_interruptible(&dev->set_running_wq);
798}
799
800static int set_protocol_running(struct pcbit_dev *dev)
801{
802 isdn_ctrl ctl;
803
804 setup_timer(&dev->set_running_timer, &set_running_timeout, (ulong)dev);
805
806 /* kick it */
807
808 dev->l2_state = L2_STARTING;
809
810 writeb((0x80U | ((dev->rcv_seq & 0x07) << 3) | (dev->send_seq & 0x07)),
811 dev->sh_mem + BANK4);
812
813 mod_timer(&dev->set_running_timer, jiffies + SET_RUN_TIMEOUT);
814
815 wait_event(dev->set_running_wq, dev->l2_state == L2_RUNNING ||
816 dev->l2_state == L2_DOWN);
817
818 del_timer(&dev->set_running_timer);
819
820 if (dev->l2_state == L2_RUNNING)
821 {
822 printk(KERN_DEBUG "pcbit: running\n");
823
824 dev->unack_seq = dev->send_seq;
825
826 dev->writeptr = dev->sh_mem;
827 dev->readptr = dev->sh_mem + BANK2;
828
829 /* tell the good news to the upper layer */
830 ctl.driver = dev->id;
831 ctl.command = ISDN_STAT_RUN;
832
833 dev->dev_if->statcallb(&ctl);
834 }
835 else
836 {
837 printk(KERN_DEBUG "pcbit: initialization failed\n");
838 printk(KERN_DEBUG "pcbit: firmware not loaded\n");
839
840#ifdef DEBUG
841 printk(KERN_DEBUG "Bank3 = %02x\n",
842 readb(dev->sh_mem + BANK3));
843#endif
844 writeb(0x40, dev->sh_mem + BANK4);
845
846 /* warn the upper layer */
847 ctl.driver = dev->id;
848 ctl.command = ISDN_STAT_STOP;
849
850 dev->dev_if->statcallb(&ctl);
851
852 return -EL2HLT; /* Level 2 halted */
853 }
854
855 return 0;
856}
857
858static int pcbit_ioctl(isdn_ctrl *ctl)
859{
860 struct pcbit_dev *dev;
861 struct pcbit_ioctl *cmd;
862
863 dev = finddev(ctl->driver);
864
865 if (!dev)
866 {
867 printk(KERN_DEBUG "pcbit_ioctl: unknown device\n");
868 return -ENODEV;
869 }
870
871 cmd = (struct pcbit_ioctl *) ctl->parm.num;
872
873 switch (ctl->arg) {
874 case PCBIT_IOCTL_GETSTAT:
875 cmd->info.l2_status = dev->l2_state;
876 break;
877
878 case PCBIT_IOCTL_STRLOAD:
879 if (dev->l2_state == L2_RUNNING)
880 return -EBUSY;
881
882 dev->unack_seq = dev->send_seq = dev->rcv_seq = 0;
883
884 dev->writeptr = dev->sh_mem;
885 dev->readptr = dev->sh_mem + BANK2;
886
887 dev->l2_state = L2_LOADING;
888 break;
889
890 case PCBIT_IOCTL_LWMODE:
891 if (dev->l2_state != L2_LOADING)
892 return -EINVAL;
893
894 dev->l2_state = L2_LWMODE;
895 break;
896
897 case PCBIT_IOCTL_FWMODE:
898 if (dev->l2_state == L2_RUNNING)
899 return -EBUSY;
900 dev->loadptr = LOAD_ZONE_START;
901 dev->l2_state = L2_FWMODE;
902
903 break;
904 case PCBIT_IOCTL_ENDLOAD:
905 if (dev->l2_state == L2_RUNNING)
906 return -EBUSY;
907 dev->l2_state = L2_DOWN;
908 break;
909
910 case PCBIT_IOCTL_SETBYTE:
911 if (dev->l2_state == L2_RUNNING)
912 return -EBUSY;
913
914 /* check addr */
915 if (cmd->info.rdp_byte.addr > BANK4)
916 return -EFAULT;
917
918 writeb(cmd->info.rdp_byte.value, dev->sh_mem + cmd->info.rdp_byte.addr);
919 break;
920 case PCBIT_IOCTL_GETBYTE:
921 if (dev->l2_state == L2_RUNNING)
922 return -EBUSY;
923
924 /* check addr */
925
926 if (cmd->info.rdp_byte.addr > BANK4)
927 {
928 printk("getbyte: invalid addr %04x\n", cmd->info.rdp_byte.addr);
929 return -EFAULT;
930 }
931
932 cmd->info.rdp_byte.value = readb(dev->sh_mem + cmd->info.rdp_byte.addr);
933 break;
934 case PCBIT_IOCTL_RUNNING:
935 if (dev->l2_state == L2_RUNNING)
936 return -EBUSY;
937 return set_protocol_running(dev);
938 break;
939 case PCBIT_IOCTL_WATCH188:
940 if (dev->l2_state != L2_LOADING)
941 return -EINVAL;
942 pcbit_l2_write(dev, MSG_WATCH188, 0x0001, NULL, 0);
943 break;
944 case PCBIT_IOCTL_PING188:
945 if (dev->l2_state != L2_LOADING)
946 return -EINVAL;
947 pcbit_l2_write(dev, MSG_PING188_REQ, 0x0001, NULL, 0);
948 break;
949 case PCBIT_IOCTL_APION:
950 if (dev->l2_state != L2_LOADING)
951 return -EINVAL;
952 pcbit_l2_write(dev, MSG_API_ON, 0x0001, NULL, 0);
953 break;
954 case PCBIT_IOCTL_STOP:
955 dev->l2_state = L2_DOWN;
956 writeb(0x40, dev->sh_mem + BANK4);
957 dev->rcv_seq = 0;
958 dev->send_seq = 0;
959 dev->unack_seq = 0;
960 break;
961 default:
962 printk("error: unknown ioctl\n");
963 break;
964 }
965 return 0;
966}
967
968/*
969 * MSN list handling
970 *
971 * if null reject all calls
972 * if first entry has null MSN accept all calls
973 */
974
975static void pcbit_clear_msn(struct pcbit_dev *dev)
976{
977 struct msn_entry *ptr, *back;
978
979 for (ptr = dev->msn_list; ptr;)
980 {
981 back = ptr->next;
982 kfree(ptr);
983 ptr = back;
984 }
985
986 dev->msn_list = NULL;
987}
988
989static void pcbit_set_msn(struct pcbit_dev *dev, char *list)
990{
991 struct msn_entry *ptr;
992 struct msn_entry *back = NULL;
993 char *cp, *sp;
994 int len;
995
996 if (strlen(list) == 0) {
997 ptr = kmalloc(sizeof(struct msn_entry), GFP_ATOMIC);
998 if (!ptr) {
999 printk(KERN_WARNING "kmalloc failed\n");
1000 return;
1001 }
1002
1003 ptr->msn = NULL;
1004
1005 ptr->next = dev->msn_list;
1006 dev->msn_list = ptr;
1007
1008 return;
1009 }
1010
1011 if (dev->msn_list)
1012 for (back = dev->msn_list; back->next; back = back->next);
1013
1014 sp = list;
1015
1016 do {
1017 cp = strchr(sp, ',');
1018 if (cp)
1019 len = cp - sp;
1020 else
1021 len = strlen(sp);
1022
1023 ptr = kmalloc(sizeof(struct msn_entry), GFP_ATOMIC);
1024
1025 if (!ptr) {
1026 printk(KERN_WARNING "kmalloc failed\n");
1027 return;
1028 }
1029 ptr->next = NULL;
1030
1031 ptr->msn = kmalloc(len + 1, GFP_ATOMIC);
1032 if (!ptr->msn) {
1033 printk(KERN_WARNING "kmalloc failed\n");
1034 kfree(ptr);
1035 return;
1036 }
1037
1038 memcpy(ptr->msn, sp, len);
1039 ptr->msn[len] = 0;
1040
1041#ifdef DEBUG
1042 printk(KERN_DEBUG "msn: %s\n", ptr->msn);
1043#endif
1044 if (dev->msn_list == NULL)
1045 dev->msn_list = ptr;
1046 else
1047 back->next = ptr;
1048 back = ptr;
1049 sp += len;
1050 } while (cp);
1051}
1052
1053/*
1054 * check if we do signal or reject an incoming call
1055 */
1056static int pcbit_check_msn(struct pcbit_dev *dev, char *msn)
1057{
1058 struct msn_entry *ptr;
1059
1060 for (ptr = dev->msn_list; ptr; ptr = ptr->next) {
1061
1062 if (ptr->msn == NULL)
1063 return 1;
1064
1065 if (strcmp(ptr->msn, msn) == 0)
1066 return 1;
1067 }
1068
1069 return 0;
1070}
diff --git a/drivers/staging/i4l/pcbit/edss1.c b/drivers/staging/i4l/pcbit/edss1.c
deleted file mode 100644
index 5980d1b5da95..000000000000
--- a/drivers/staging/i4l/pcbit/edss1.c
+++ /dev/null
@@ -1,310 +0,0 @@
1/*
2 * DSS.1 Finite State Machine
3 * base: ITU-T Rec Q.931
4 *
5 * Copyright (C) 1996 Universidade de Lisboa
6 *
7 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
8 *
9 * This software may be used and distributed according to the terms of
10 * the GNU General Public License, incorporated herein by reference.
11 */
12
13/*
14 * TODO: complete the FSM
15 * move state/event descriptions to a user space logger
16 */
17
18#include <linux/string.h>
19#include <linux/kernel.h>
20
21#include <linux/types.h>
22#include <linux/mm.h>
23#include <linux/skbuff.h>
24
25#include <linux/timer.h>
26#include <linux/io.h>
27
28#include <linux/isdnif.h>
29
30#include "pcbit.h"
31#include "edss1.h"
32#include "layer2.h"
33#include "callbacks.h"
34
35
36const char * const isdn_state_table[] = {
37 "Closed",
38 "Call initiated",
39 "Overlap sending",
40 "Outgoing call proceeding",
41 "NOT DEFINED",
42 "Call delivered",
43 "Call present",
44 "Call received",
45 "Connect request",
46 "Incoming call proceeding",
47 "Active",
48 "Disconnect request",
49 "Disconnect indication",
50 "NOT DEFINED",
51 "NOT DEFINED",
52 "Suspend request",
53 "NOT DEFINED",
54 "Resume request",
55 "NOT DEFINED",
56 "Release Request",
57 "NOT DEFINED",
58 "NOT DEFINED",
59 "NOT DEFINED",
60 "NOT DEFINED",
61 "NOT DEFINED",
62 "Overlap receiving",
63 "Select protocol on B-Channel",
64 "Activate B-channel protocol"
65};
66
67#ifdef DEBUG_ERRS
68static
69struct CauseValue {
70 byte nr;
71 char *descr;
72} cvlist[] = {
73 {0x01, "Unallocated (unassigned) number"},
74 {0x02, "No route to specified transit network"},
75 {0x03, "No route to destination"},
76 {0x04, "Send special information tone"},
77 {0x05, "Misdialled trunk prefix"},
78 {0x06, "Channel unacceptable"},
79 {0x07, "Channel awarded and being delivered in an established channel"},
80 {0x08, "Preemption"},
81 {0x09, "Preemption - circuit reserved for reuse"},
82 {0x10, "Normal call clearing"},
83 {0x11, "User busy"},
84 {0x12, "No user responding"},
85 {0x13, "No answer from user (user alerted)"},
86 {0x14, "Subscriber absent"},
87 {0x15, "Call rejected"},
88 {0x16, "Number changed"},
89 {0x1a, "non-selected user clearing"},
90 {0x1b, "Destination out of order"},
91 {0x1c, "Invalid number format (address incomplete)"},
92 {0x1d, "Facility rejected"},
93 {0x1e, "Response to Status enquiry"},
94 {0x1f, "Normal, unspecified"},
95 {0x22, "No circuit/channel available"},
96 {0x26, "Network out of order"},
97 {0x27, "Permanent frame mode connection out-of-service"},
98 {0x28, "Permanent frame mode connection operational"},
99 {0x29, "Temporary failure"},
100 {0x2a, "Switching equipment congestion"},
101 {0x2b, "Access information discarded"},
102 {0x2c, "Requested circuit/channel not available"},
103 {0x2e, "Precedence call blocked"},
104 {0x2f, "Resource unavailable, unspecified"},
105 {0x31, "Quality of service unavailable"},
106 {0x32, "Requested facility not subscribed"},
107 {0x35, "Outgoing calls barred within CUG"},
108 {0x37, "Incoming calls barred within CUG"},
109 {0x39, "Bearer capability not authorized"},
110 {0x3a, "Bearer capability not presently available"},
111 {0x3e, "Inconsistency in designated outgoing access information and subscriber class"},
112 {0x3f, "Service or option not available, unspecified"},
113 {0x41, "Bearer capability not implemented"},
114 {0x42, "Channel type not implemented"},
115 {0x43, "Requested facility not implemented"},
116 {0x44, "Only restricted digital information bearer capability is available"},
117 {0x4f, "Service or option not implemented"},
118 {0x51, "Invalid call reference value"},
119 {0x52, "Identified channel does not exist"},
120 {0x53, "A suspended call exists, but this call identity does not"},
121 {0x54, "Call identity in use"},
122 {0x55, "No call suspended"},
123 {0x56, "Call having the requested call identity has been cleared"},
124 {0x57, "User not member of CUG"},
125 {0x58, "Incompatible destination"},
126 {0x5a, "Non-existent CUG"},
127 {0x5b, "Invalid transit network selection"},
128 {0x5f, "Invalid message, unspecified"},
129 {0x60, "Mandatory information element is missing"},
130 {0x61, "Message type non-existent or not implemented"},
131 {0x62, "Message not compatible with call state or message type non-existent or not implemented"},
132 {0x63, "Information element/parameter non-existent or not implemented"},
133 {0x64, "Invalid information element contents"},
134 {0x65, "Message not compatible with call state"},
135 {0x66, "Recovery on timer expiry"},
136 {0x67, "Parameter non-existent or not implemented - passed on"},
137 {0x6e, "Message with unrecognized parameter discarded"},
138 {0x6f, "Protocol error, unspecified"},
139 {0x7f, "Interworking, unspecified"}
140};
141
142#endif
143
144static struct isdn_event_desc {
145 unsigned short ev;
146 char *desc;
147} isdn_event_table[] = {
148 {EV_USR_SETUP_REQ, "CC->L3: Setup Request"},
149 {EV_USR_SETUP_RESP, "CC->L3: Setup Response"},
150 {EV_USR_PROCED_REQ, "CC->L3: Proceeding Request"},
151 {EV_USR_RELEASE_REQ, "CC->L3: Release Request"},
152
153 {EV_NET_SETUP, "NET->TE: setup "},
154 {EV_NET_CALL_PROC, "NET->TE: call proceeding"},
155 {EV_NET_SETUP_ACK, "NET->TE: setup acknowledge (more info needed)"},
156 {EV_NET_CONN, "NET->TE: connect"},
157 {EV_NET_CONN_ACK, "NET->TE: connect acknowledge"},
158 {EV_NET_DISC, "NET->TE: disconnect indication"},
159 {EV_NET_RELEASE, "NET->TE: release"},
160 {EV_NET_RELEASE_COMP, "NET->TE: release complete"},
161 {EV_NET_SELP_RESP, "Board: Select B-channel protocol ack"},
162 {EV_NET_ACTV_RESP, "Board: Activate B-channel protocol ack"},
163 {EV_TIMER, "Timeout"},
164 {0, "NULL"}
165};
166
167char *strisdnevent(ushort ev)
168{
169 struct isdn_event_desc *entry;
170
171 for (entry = isdn_event_table; entry->ev; entry++)
172 if (entry->ev == ev)
173 break;
174
175 return entry->desc;
176}
177
178/*
179 * Euro ISDN finite state machine
180 */
181
182static struct fsm_timer_entry fsm_timers[] = {
183 {ST_CALL_PROC, 10},
184 {ST_DISC_REQ, 2},
185 {ST_ACTIVE_SELP, 5},
186 {ST_ACTIVE_ACTV, 5},
187 {ST_INCM_PROC, 10},
188 {ST_CONN_REQ, 2},
189 {0xff, 0}
190};
191
192static struct fsm_entry fsm_table[] = {
193/* Connect Phase */
194 /* Outgoing */
195 {ST_NULL, ST_CALL_INIT, EV_USR_SETUP_REQ, cb_out_1},
196
197 {ST_CALL_INIT, ST_OVER_SEND, EV_NET_SETUP_ACK, cb_notdone},
198 {ST_CALL_INIT, ST_CALL_PROC, EV_NET_CALL_PROC, NULL},
199 {ST_CALL_INIT, ST_NULL, EV_NET_DISC, cb_out_2},
200
201 {ST_CALL_PROC, ST_ACTIVE_SELP, EV_NET_CONN, cb_out_2},
202 {ST_CALL_PROC, ST_NULL, EV_NET_DISC, cb_disc_1},
203 {ST_CALL_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
204
205 /* Incoming */
206 {ST_NULL, ST_CALL_PRES, EV_NET_SETUP, NULL},
207
208 {ST_CALL_PRES, ST_INCM_PROC, EV_USR_PROCED_REQ, cb_in_1},
209 {ST_CALL_PRES, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
210
211 {ST_INCM_PROC, ST_CONN_REQ, EV_USR_SETUP_RESP, cb_in_2},
212 {ST_INCM_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
213
214 {ST_CONN_REQ, ST_ACTIVE_SELP, EV_NET_CONN_ACK, cb_in_3},
215
216 /* Active */
217 {ST_ACTIVE, ST_NULL, EV_NET_DISC, cb_disc_1},
218 {ST_ACTIVE, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
219 {ST_ACTIVE, ST_NULL, EV_NET_RELEASE, cb_disc_3},
220
221 /* Disconnect */
222
223 {ST_DISC_REQ, ST_NULL, EV_NET_DISC, cb_disc_1},
224 {ST_DISC_REQ, ST_NULL, EV_NET_RELEASE, cb_disc_3},
225
226 /* protocol selection */
227 {ST_ACTIVE_SELP, ST_ACTIVE_ACTV, EV_NET_SELP_RESP, cb_selp_1},
228 {ST_ACTIVE_SELP, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
229
230 {ST_ACTIVE_ACTV, ST_ACTIVE, EV_NET_ACTV_RESP, cb_open},
231 {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
232
233 /* Timers */
234 {ST_CALL_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
235 {ST_DISC_REQ, ST_NULL, EV_TIMER, cb_disc_3},
236 {ST_ACTIVE_SELP, ST_DISC_REQ, EV_TIMER, cb_disc_2},
237 {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_TIMER, cb_disc_2},
238 {ST_INCM_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
239 {ST_CONN_REQ, ST_CONN_REQ, EV_TIMER, cb_in_2},
240
241 {0xff, 0, 0, NULL}
242};
243
244
245static void pcbit_fsm_timer(unsigned long data)
246{
247 struct pcbit_dev *dev;
248 struct pcbit_chan *chan;
249
250 chan = (struct pcbit_chan *) data;
251
252 del_timer(&chan->fsm_timer);
253 chan->fsm_timer.function = NULL;
254
255 dev = chan2dev(chan);
256
257 if (!dev) {
258 printk(KERN_WARNING "pcbit: timer for unknown device\n");
259 return;
260 }
261
262 pcbit_fsm_event(dev, chan, EV_TIMER, NULL);
263}
264
265
266void pcbit_fsm_event(struct pcbit_dev *dev, struct pcbit_chan *chan,
267 unsigned short event, struct callb_data *data)
268{
269 struct fsm_entry *action;
270 struct fsm_timer_entry *tentry;
271 unsigned long flags;
272
273 spin_lock_irqsave(&dev->lock, flags);
274
275 for (action = fsm_table; action->init != 0xff; action++)
276 if (action->init == chan->fsm_state && action->event == event)
277 break;
278
279 if (action->init == 0xff) {
280
281 spin_unlock_irqrestore(&dev->lock, flags);
282 printk(KERN_DEBUG "fsm error: event %x on state %x\n",
283 event, chan->fsm_state);
284 return;
285 }
286
287 if (chan->fsm_timer.function) {
288 del_timer(&chan->fsm_timer);
289 chan->fsm_timer.function = NULL;
290 }
291
292 chan->fsm_state = action->final;
293
294 pcbit_state_change(dev, chan, action->init, event, action->final);
295
296 for (tentry = fsm_timers; tentry->init != 0xff; tentry++)
297 if (tentry->init == chan->fsm_state)
298 break;
299
300 if (tentry->init != 0xff) {
301 setup_timer(&chan->fsm_timer, &pcbit_fsm_timer, (ulong)chan);
302 mod_timer(&chan->fsm_timer, jiffies + tentry->timeout * HZ);
303 }
304
305 spin_unlock_irqrestore(&dev->lock, flags);
306
307 if (action->callb)
308 action->callb(dev, chan, data);
309
310}
diff --git a/drivers/staging/i4l/pcbit/edss1.h b/drivers/staging/i4l/pcbit/edss1.h
deleted file mode 100644
index 2f6b3a8edfba..000000000000
--- a/drivers/staging/i4l/pcbit/edss1.h
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 * DSS.1 module definitions
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12#ifndef EDSS1_H
13#define EDSS1_H
14
15/* ISDN states */
16
17#define ST_NULL 0
18#define ST_CALL_INIT 1 /* Call initiated */
19#define ST_OVER_SEND 2 /* Overlap sending - Requests More Info 4 call */
20#define ST_CALL_PROC 3 /* Call Proceeding */
21#define ST_CALL_DELV 4
22#define ST_CALL_PRES 6 /* Call Present - Received CONN.IND */
23#define ST_CALL_RECV 7 /* Alerting sent */
24#define ST_CONN_REQ 8 /* Answered - waiting 4 CONN.CONF */
25#define ST_INCM_PROC 9
26#define ST_ACTIVE 10
27#define ST_DISC_REQ 11
28#define ST_DISC_IND 12
29#define ST_SUSP_REQ 15
30#define ST_RESM_REQ 17
31#define ST_RELS_REQ 19
32#define ST_OVER_RECV 25
33
34#define ST_ACTIVE_SELP 26 /* Select protocol on B-Channel */
35#define ST_ACTIVE_ACTV 27 /* Activate B-channel protocol */
36
37#define MAX_STATE ST_ACTIVE_ACTV
38
39#define EV_NULL 0
40#define EV_USR_SETUP_REQ 1
41#define EV_USR_SETUP_RESP 2
42#define EV_USR_PROCED_REQ 3
43#define EV_USR_RELEASE_REQ 4
44#define EV_USR_REJECT_REQ 4
45
46#define EV_NET_SETUP 16
47#define EV_NET_CALL_PROC 17
48#define EV_NET_SETUP_ACK 18
49#define EV_NET_CONN 19
50#define EV_NET_CONN_ACK 20
51
52#define EV_NET_SELP_RESP 21
53#define EV_NET_ACTV_RESP 22
54
55#define EV_NET_DISC 23
56#define EV_NET_RELEASE 24
57#define EV_NET_RELEASE_COMP 25
58
59#define EV_TIMER 26
60#define EV_ERROR 32
61
62/*
63 * Cause values
64 * only the ones we use
65 */
66
67#define CAUSE_NORMAL 0x10U
68#define CAUSE_NOCHAN 0x22U
69
70struct callb_data {
71 unsigned short type;
72 union {
73 struct ConnInfo {
74 char *CalledPN;
75 char *CallingPN;
76 } setup;
77 unsigned short cause;
78 } data;
79};
80
81struct fsm_entry {
82 unsigned short init;
83 unsigned short final;
84 unsigned short event;
85 void (*callb)(struct pcbit_dev *, struct pcbit_chan *, struct callb_data*);
86};
87
88struct fsm_timer_entry {
89 unsigned short init;
90 unsigned long timeout; /* in seconds */
91};
92
93extern const char * const isdn_state_table[];
94
95void pcbit_fsm_event(struct pcbit_dev *, struct pcbit_chan *,
96 unsigned short event, struct callb_data *);
97char *strisdnevent(ushort ev);
98
99#endif
diff --git a/drivers/staging/i4l/pcbit/layer2.c b/drivers/staging/i4l/pcbit/layer2.c
deleted file mode 100644
index 0592bf6ee9c9..000000000000
--- a/drivers/staging/i4l/pcbit/layer2.c
+++ /dev/null
@@ -1,710 +0,0 @@
1/*
2 * PCBIT-D low-layer interface
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12/*
13 * 19991203 - Fernando Carvalho - takion@superbofh.org
14 * Hacked to compile with egcs and run with current version of isdn modules
15 */
16
17/*
18 * Based on documentation provided by Inesc:
19 * - "Interface com bus do PC para o PCBIT e PCBIT-D", Inesc, Jan 93
20 */
21
22/*
23 * TODO: better handling of errors
24 * re-write/remove debug printks
25 */
26
27#include <linux/string.h>
28#include <linux/kernel.h>
29#include <linux/types.h>
30#include <linux/sched.h>
31#include <linux/slab.h>
32#include <linux/interrupt.h>
33#include <linux/workqueue.h>
34#include <linux/mm.h>
35#include <linux/skbuff.h>
36
37#include <linux/isdnif.h>
38
39#include <linux/io.h>
40
41
42#include "pcbit.h"
43#include "layer2.h"
44#include "edss1.h"
45
46#undef DEBUG_FRAG
47
48
49/*
50 * Prototypes
51 */
52
53static void pcbit_transmit(struct pcbit_dev *dev);
54
55static void pcbit_recv_ack(struct pcbit_dev *dev, unsigned char ack);
56
57static void pcbit_l2_error(struct pcbit_dev *dev);
58static void pcbit_l2_active_conf(struct pcbit_dev *dev, u_char info);
59static void pcbit_l2_err_recover(unsigned long data);
60
61static void pcbit_firmware_bug(struct pcbit_dev *dev);
62
63static __inline__ void
64pcbit_sched_delivery(struct pcbit_dev *dev)
65{
66 schedule_work(&dev->qdelivery);
67}
68
69
70/*
71 * Called from layer3
72 */
73
74int
75pcbit_l2_write(struct pcbit_dev *dev, ulong msg, ushort refnum,
76 struct sk_buff *skb, unsigned short hdr_len)
77{
78 struct frame_buf *frame,
79 *ptr;
80 unsigned long flags;
81
82 if (dev->l2_state != L2_RUNNING && dev->l2_state != L2_LOADING) {
83 dev_kfree_skb(skb);
84 return -1;
85 }
86 if ((frame = kmalloc(sizeof(struct frame_buf),
87 GFP_ATOMIC)) == NULL) {
88 dev_kfree_skb(skb);
89 return -1;
90 }
91 frame->msg = msg;
92 frame->refnum = refnum;
93 frame->copied = 0;
94 frame->hdr_len = hdr_len;
95
96 if (skb)
97 frame->dt_len = skb->len - hdr_len;
98 else
99 frame->dt_len = 0;
100
101 frame->skb = skb;
102
103 frame->next = NULL;
104
105 spin_lock_irqsave(&dev->lock, flags);
106
107 if (dev->write_queue == NULL) {
108 dev->write_queue = frame;
109 spin_unlock_irqrestore(&dev->lock, flags);
110 pcbit_transmit(dev);
111 } else {
112 for (ptr = dev->write_queue; ptr->next; ptr = ptr->next);
113 ptr->next = frame;
114
115 spin_unlock_irqrestore(&dev->lock, flags);
116 }
117 return 0;
118}
119
120static __inline__ void
121pcbit_tx_update(struct pcbit_dev *dev, ushort len)
122{
123 u_char info;
124
125 dev->send_seq = (dev->send_seq + 1) % 8;
126
127 dev->fsize[dev->send_seq] = len;
128 info = 0;
129 info |= dev->rcv_seq << 3;
130 info |= dev->send_seq;
131
132 writeb(info, dev->sh_mem + BANK4);
133
134}
135
136/*
137 * called by interrupt service routine or by write_2
138 */
139
140static void
141pcbit_transmit(struct pcbit_dev *dev)
142{
143 struct frame_buf *frame = NULL;
144 unsigned char unacked;
145 int flen; /* fragment frame length including all headers */
146 int free;
147 int count,
148 cp_len;
149 unsigned long flags;
150 unsigned short tt;
151
152 if (dev->l2_state != L2_RUNNING && dev->l2_state != L2_LOADING)
153 return;
154
155 unacked = (dev->send_seq + (8 - dev->unack_seq)) & 0x07;
156
157 spin_lock_irqsave(&dev->lock, flags);
158
159 if (dev->free > 16 && dev->write_queue && unacked < 7) {
160
161 if (!dev->w_busy)
162 dev->w_busy = 1;
163 else {
164 spin_unlock_irqrestore(&dev->lock, flags);
165 return;
166 }
167
168
169 frame = dev->write_queue;
170 free = dev->free;
171
172 spin_unlock_irqrestore(&dev->lock, flags);
173
174 if (frame->copied == 0) {
175
176 /* Type 0 frame */
177
178 ulong msg;
179
180 if (frame->skb)
181 flen = FRAME_HDR_LEN + PREHDR_LEN + frame->skb->len;
182 else
183 flen = FRAME_HDR_LEN + PREHDR_LEN;
184
185 if (flen > free)
186 flen = free;
187
188 msg = frame->msg;
189
190 /*
191 * Board level 2 header
192 */
193
194 pcbit_writew(dev, flen - FRAME_HDR_LEN);
195
196 pcbit_writeb(dev, GET_MSG_CPU(msg));
197
198 pcbit_writeb(dev, GET_MSG_PROC(msg));
199
200 /* TH */
201 pcbit_writew(dev, frame->hdr_len + PREHDR_LEN);
202
203 /* TD */
204 pcbit_writew(dev, frame->dt_len);
205
206
207 /*
208 * Board level 3 fixed-header
209 */
210
211 /* LEN = TH */
212 pcbit_writew(dev, frame->hdr_len + PREHDR_LEN);
213
214 /* XX */
215 pcbit_writew(dev, 0);
216
217 /* C + S */
218 pcbit_writeb(dev, GET_MSG_CMD(msg));
219 pcbit_writeb(dev, GET_MSG_SCMD(msg));
220
221 /* NUM */
222 pcbit_writew(dev, frame->refnum);
223
224 count = FRAME_HDR_LEN + PREHDR_LEN;
225 } else {
226 /* Type 1 frame */
227
228 flen = 2 + (frame->skb->len - frame->copied);
229
230 if (flen > free)
231 flen = free;
232
233 /* TT */
234 tt = ((ushort) (flen - 2)) | 0x8000U; /* Type 1 */
235 pcbit_writew(dev, tt);
236
237 count = 2;
238 }
239
240 if (frame->skb) {
241 cp_len = frame->skb->len - frame->copied;
242 if (cp_len > flen - count)
243 cp_len = flen - count;
244
245 memcpy_topcbit(dev, frame->skb->data + frame->copied,
246 cp_len);
247 frame->copied += cp_len;
248 }
249 /* bookkeeping */
250 dev->free -= flen;
251 pcbit_tx_update(dev, flen);
252
253 spin_lock_irqsave(&dev->lock, flags);
254
255 if (frame->skb == NULL || frame->copied == frame->skb->len) {
256
257 dev->write_queue = frame->next;
258
259 if (frame->skb != NULL) {
260 /* free frame */
261 dev_kfree_skb(frame->skb);
262 }
263 kfree(frame);
264 }
265 dev->w_busy = 0;
266 spin_unlock_irqrestore(&dev->lock, flags);
267 } else {
268 spin_unlock_irqrestore(&dev->lock, flags);
269#ifdef DEBUG
270 printk(KERN_DEBUG "unacked %d free %d write_queue %s\n",
271 unacked, dev->free, dev->write_queue ? "not empty" :
272 "empty");
273#endif
274 }
275}
276
277
278/*
279 * deliver a queued frame to the upper layer
280 */
281
282void
283pcbit_deliver(struct work_struct *work)
284{
285 struct frame_buf *frame;
286 unsigned long flags, msg;
287 struct pcbit_dev *dev =
288 container_of(work, struct pcbit_dev, qdelivery);
289
290 spin_lock_irqsave(&dev->lock, flags);
291
292 while ((frame = dev->read_queue)) {
293 dev->read_queue = frame->next;
294 spin_unlock_irqrestore(&dev->lock, flags);
295
296 msg = 0;
297 SET_MSG_CPU(msg, 0);
298 SET_MSG_PROC(msg, 0);
299 SET_MSG_CMD(msg, frame->skb->data[2]);
300 SET_MSG_SCMD(msg, frame->skb->data[3]);
301
302 frame->refnum = *((ushort *)frame->skb->data + 4);
303 frame->msg = *((ulong *)&msg);
304
305 skb_pull(frame->skb, 6);
306
307 pcbit_l3_receive(dev, frame->msg, frame->skb, frame->hdr_len,
308 frame->refnum);
309
310 kfree(frame);
311
312 spin_lock_irqsave(&dev->lock, flags);
313 }
314
315 spin_unlock_irqrestore(&dev->lock, flags);
316}
317
318/*
319 * Reads BANK 2 & Reassembles
320 */
321
322static void
323pcbit_receive(struct pcbit_dev *dev)
324{
325 unsigned short tt;
326 u_char cpu,
327 proc;
328 struct frame_buf *frame = NULL;
329 unsigned long flags;
330 u_char type1;
331
332 if (dev->l2_state != L2_RUNNING && dev->l2_state != L2_LOADING)
333 return;
334
335 tt = pcbit_readw(dev);
336
337 if ((tt & 0x7fffU) > 511) {
338 printk(KERN_INFO "pcbit: invalid frame length -> TT=%04x\n",
339 tt);
340 pcbit_l2_error(dev);
341 return;
342 }
343 if (!(tt & 0x8000U)) { /* Type 0 */
344 type1 = 0;
345
346 if (dev->read_frame) {
347 printk(KERN_DEBUG "pcbit_receive: Type 0 frame and read_frame != NULL\n");
348 /* discard previous queued frame */
349 kfree_skb(dev->read_frame->skb);
350 kfree(dev->read_frame);
351 dev->read_frame = NULL;
352 }
353 frame = kzalloc(sizeof(struct frame_buf), GFP_ATOMIC);
354
355 if (frame == NULL) {
356 printk(KERN_WARNING "kmalloc failed\n");
357 return;
358 }
359
360 cpu = pcbit_readb(dev);
361 proc = pcbit_readb(dev);
362
363
364 if (cpu != 0x06 && cpu != 0x02) {
365 printk(KERN_DEBUG "pcbit: invalid cpu value\n");
366 kfree(frame);
367 pcbit_l2_error(dev);
368 return;
369 }
370 /*
371 * we discard cpu & proc on receiving
372 * but we read it to update the pointer
373 */
374
375 frame->hdr_len = pcbit_readw(dev);
376 frame->dt_len = pcbit_readw(dev);
377
378 /*
379 * 0 sized packet
380 * I don't know if they are an error or not...
381 * But they are very frequent
382 * Not documented
383 */
384
385 if (frame->hdr_len == 0) {
386 kfree(frame);
387#ifdef DEBUG
388 printk(KERN_DEBUG "0 sized frame\n");
389#endif
390 pcbit_firmware_bug(dev);
391 return;
392 }
393 /* sanity check the length values */
394 if (frame->hdr_len > 1024 || frame->dt_len > 2048) {
395#ifdef DEBUG
396 printk(KERN_DEBUG "length problem: ");
397 printk(KERN_DEBUG "TH=%04x TD=%04x\n",
398 frame->hdr_len,
399 frame->dt_len);
400#endif
401 pcbit_l2_error(dev);
402 kfree(frame);
403 return;
404 }
405 /* minimum frame read */
406
407 frame->skb = dev_alloc_skb(frame->hdr_len + frame->dt_len +
408 ((frame->hdr_len + 15) & ~15));
409
410 if (!frame->skb) {
411 printk(KERN_DEBUG "pcbit_receive: out of memory\n");
412 kfree(frame);
413 return;
414 }
415 /* 16 byte alignment for IP */
416 if (frame->dt_len)
417 skb_reserve(frame->skb, (frame->hdr_len + 15) & ~15);
418
419 } else {
420 /* Type 1 */
421 type1 = 1;
422 tt &= 0x7fffU;
423
424 if (!(frame = dev->read_frame)) {
425 printk("Type 1 frame and no frame queued\n");
426 /* usually after an error: toss frame */
427 dev->readptr += tt;
428 if (dev->readptr > dev->sh_mem + BANK2 + BANKLEN)
429 dev->readptr -= BANKLEN;
430 return;
431
432 }
433 }
434
435 memcpy_frompcbit(dev, skb_put(frame->skb, tt), tt);
436
437 frame->copied += tt;
438 spin_lock_irqsave(&dev->lock, flags);
439 if (frame->copied == frame->hdr_len + frame->dt_len) {
440
441 if (type1) {
442 dev->read_frame = NULL;
443 }
444 if (dev->read_queue) {
445 struct frame_buf *ptr;
446 for (ptr = dev->read_queue; ptr->next; ptr = ptr->next);
447 ptr->next = frame;
448 } else
449 dev->read_queue = frame;
450
451 } else {
452 dev->read_frame = frame;
453 }
454 spin_unlock_irqrestore(&dev->lock, flags);
455}
456
457/*
458 * The board sends 0 sized frames
459 * They are TDATA_CONFs that get messed up somehow
460 * gotta send a fake acknowledgment to the upper layer somehow
461 */
462
463static __inline__ void
464pcbit_fake_conf(struct pcbit_dev *dev, struct pcbit_chan *chan)
465{
466 isdn_ctrl ictl;
467
468 if (chan->queued) {
469 chan->queued--;
470
471 ictl.driver = dev->id;
472 ictl.command = ISDN_STAT_BSENT;
473 ictl.arg = chan->id;
474 dev->dev_if->statcallb(&ictl);
475 }
476}
477
478static void
479pcbit_firmware_bug(struct pcbit_dev *dev)
480{
481 struct pcbit_chan *chan;
482
483 chan = dev->b1;
484
485 if (chan->fsm_state == ST_ACTIVE) {
486 pcbit_fake_conf(dev, chan);
487 }
488 chan = dev->b2;
489
490 if (chan->fsm_state == ST_ACTIVE) {
491 pcbit_fake_conf(dev, chan);
492 }
493}
494
495irqreturn_t
496pcbit_irq_handler(int interrupt, void *devptr)
497{
498 struct pcbit_dev *dev;
499 u_char info,
500 ack_seq,
501 read_seq;
502
503 dev = (struct pcbit_dev *) devptr;
504
505 if (!dev) {
506 printk(KERN_WARNING "pcbit_irq_handler: wrong device\n");
507 return IRQ_NONE;
508 }
509 if (dev->interrupt) {
510 printk(KERN_DEBUG "pcbit: reentering interrupt handler\n");
511 return IRQ_HANDLED;
512 }
513 dev->interrupt = 1;
514
515 info = readb(dev->sh_mem + BANK3);
516
517 if (dev->l2_state == L2_STARTING || dev->l2_state == L2_ERROR) {
518 pcbit_l2_active_conf(dev, info);
519 dev->interrupt = 0;
520 return IRQ_HANDLED;
521 }
522 if (info & 0x40U) { /* E bit set */
523#ifdef DEBUG
524 printk(KERN_DEBUG "pcbit_irq_handler: E bit on\n");
525#endif
526 pcbit_l2_error(dev);
527 dev->interrupt = 0;
528 return IRQ_HANDLED;
529 }
530 if (dev->l2_state != L2_RUNNING && dev->l2_state != L2_LOADING) {
531 dev->interrupt = 0;
532 return IRQ_HANDLED;
533 }
534 ack_seq = (info >> 3) & 0x07U;
535 read_seq = (info & 0x07U);
536
537 dev->interrupt = 0;
538
539 if (read_seq != dev->rcv_seq) {
540 while (read_seq != dev->rcv_seq) {
541 pcbit_receive(dev);
542 dev->rcv_seq = (dev->rcv_seq + 1) % 8;
543 }
544 pcbit_sched_delivery(dev);
545 }
546 if (ack_seq != dev->unack_seq) {
547 pcbit_recv_ack(dev, ack_seq);
548 }
549 info = dev->rcv_seq << 3;
550 info |= dev->send_seq;
551
552 writeb(info, dev->sh_mem + BANK4);
553 return IRQ_HANDLED;
554}
555
556
557static void
558pcbit_l2_active_conf(struct pcbit_dev *dev, u_char info)
559{
560 u_char state;
561
562 state = dev->l2_state;
563
564#ifdef DEBUG
565 printk(KERN_DEBUG "layer2_active_confirm\n");
566#endif
567
568
569 if (info & 0x80U) {
570 dev->rcv_seq = info & 0x07U;
571 dev->l2_state = L2_RUNNING;
572 } else
573 dev->l2_state = L2_DOWN;
574
575 if (state == L2_STARTING)
576 wake_up_interruptible(&dev->set_running_wq);
577
578 if (state == L2_ERROR && dev->l2_state == L2_RUNNING) {
579 pcbit_transmit(dev);
580 }
581}
582
583static void
584pcbit_l2_err_recover(unsigned long data)
585{
586
587 struct pcbit_dev *dev;
588 struct frame_buf *frame;
589
590 dev = (struct pcbit_dev *) data;
591
592 del_timer(&dev->error_recover_timer);
593 if (dev->w_busy || dev->r_busy) {
594 init_timer(&dev->error_recover_timer);
595 dev->error_recover_timer.expires = jiffies + ERRTIME;
596 add_timer(&dev->error_recover_timer);
597 return;
598 }
599 dev->w_busy = dev->r_busy = 1;
600
601 if (dev->read_frame) {
602 kfree_skb(dev->read_frame->skb);
603 kfree(dev->read_frame);
604 dev->read_frame = NULL;
605 }
606 if (dev->write_queue) {
607 frame = dev->write_queue;
608#ifdef FREE_ON_ERROR
609 dev->write_queue = dev->write_queue->next;
610
611 if (frame->skb) {
612 dev_kfree_skb(frame->skb);
613 }
614 kfree(frame);
615#else
616 frame->copied = 0;
617#endif
618 }
619 dev->rcv_seq = dev->send_seq = dev->unack_seq = 0;
620 dev->free = 511;
621 dev->l2_state = L2_ERROR;
622
623 /* this is an hack... */
624 pcbit_firmware_bug(dev);
625
626 dev->writeptr = dev->sh_mem;
627 dev->readptr = dev->sh_mem + BANK2;
628
629 writeb((0x80U | ((dev->rcv_seq & 0x07) << 3) | (dev->send_seq & 0x07)),
630 dev->sh_mem + BANK4);
631 dev->w_busy = dev->r_busy = 0;
632
633}
634
635static void
636pcbit_l2_error(struct pcbit_dev *dev)
637{
638 if (dev->l2_state == L2_RUNNING) {
639
640 printk(KERN_INFO "pcbit: layer 2 error\n");
641
642#ifdef DEBUG
643 log_state(dev);
644#endif
645
646 dev->l2_state = L2_DOWN;
647
648 setup_timer(&dev->error_recover_timer, &pcbit_l2_err_recover,
649 (ulong)dev);
650 mod_timer(&dev->error_recover_timer, jiffies + ERRTIME);
651 }
652}
653
654/*
655 * Description:
656 * if board acks frames
657 * update dev->free
658 * call pcbit_transmit to write possible queued frames
659 */
660
661static void
662pcbit_recv_ack(struct pcbit_dev *dev, unsigned char ack)
663{
664 int i,
665 count;
666 int unacked;
667
668 unacked = (dev->send_seq + (8 - dev->unack_seq)) & 0x07;
669
670 /* dev->unack_seq < ack <= dev->send_seq; */
671
672 if (unacked) {
673
674 if (dev->send_seq > dev->unack_seq) {
675 if (ack <= dev->unack_seq || ack > dev->send_seq) {
676 printk(KERN_DEBUG
677 "layer 2 ack unacceptable - dev %d",
678 dev->id);
679
680 pcbit_l2_error(dev);
681 } else if (ack > dev->send_seq && ack <= dev->unack_seq) {
682 printk(KERN_DEBUG
683 "layer 2 ack unacceptable - dev %d",
684 dev->id);
685 pcbit_l2_error(dev);
686 }
687 }
688 /* ack is acceptable */
689
690
691 i = dev->unack_seq;
692
693 do {
694 dev->unack_seq = i = (i + 1) % 8;
695 dev->free += dev->fsize[i];
696 } while (i != ack);
697
698 count = 0;
699 while (count < 7 && dev->write_queue) {
700 u8 lsend_seq = dev->send_seq;
701
702 pcbit_transmit(dev);
703
704 if (dev->send_seq == lsend_seq)
705 break;
706 count++;
707 }
708 } else
709 printk(KERN_DEBUG "recv_ack: unacked = 0\n");
710}
diff --git a/drivers/staging/i4l/pcbit/layer2.h b/drivers/staging/i4l/pcbit/layer2.h
deleted file mode 100644
index 6b9063e388cd..000000000000
--- a/drivers/staging/i4l/pcbit/layer2.h
+++ /dev/null
@@ -1,281 +0,0 @@
1/*
2 * PCBIT-D low-layer interface definitions
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12/*
13 * 19991203 - Fernando Carvalho - takion@superbofh.org
14 * Hacked to compile with egcs and run with current version of isdn modules
15 */
16
17#ifndef LAYER2_H
18#define LAYER2_H
19
20#include <linux/interrupt.h>
21
22#include <asm/byteorder.h>
23
24#define BANK1 0x0000U /* PC -> Board */
25#define BANK2 0x01ffU /* Board -> PC */
26#define BANK3 0x03feU /* Att Board */
27#define BANK4 0x03ffU /* Att PC */
28
29#define BANKLEN 0x01FFU
30
31#define LOAD_ZONE_START 0x03f8U
32#define LOAD_ZONE_END 0x03fdU
33
34#define LOAD_RETRY 18000000
35
36
37
38/* TAM - XX - C - S - NUM */
39#define PREHDR_LEN 8
40/* TT - M - I - TH - TD */
41#define FRAME_HDR_LEN 8
42
43#define MSG_CONN_REQ 0x08000100
44#define MSG_CONN_CONF 0x00000101
45#define MSG_CONN_IND 0x00000102
46#define MSG_CONN_RESP 0x08000103
47
48#define MSG_CONN_ACTV_REQ 0x08000300
49#define MSG_CONN_ACTV_CONF 0x00000301
50#define MSG_CONN_ACTV_IND 0x00000302
51#define MSG_CONN_ACTV_RESP 0x08000303
52
53#define MSG_DISC_REQ 0x08000400
54#define MSG_DISC_CONF 0x00000401
55#define MSG_DISC_IND 0x00000402
56#define MSG_DISC_RESP 0x08000403
57
58#define MSG_TDATA_REQ 0x0908E200
59#define MSG_TDATA_CONF 0x0000E201
60#define MSG_TDATA_IND 0x0000E202
61#define MSG_TDATA_RESP 0x0908E203
62
63#define MSG_SELP_REQ 0x09004000
64#define MSG_SELP_CONF 0x00004001
65
66#define MSG_ACT_TRANSP_REQ 0x0908E000
67#define MSG_ACT_TRANSP_CONF 0x0000E001
68
69#define MSG_STPROT_REQ 0x09004100
70#define MSG_STPROT_CONF 0x00004101
71
72#define MSG_PING188_REQ 0x09030500
73#define MSG_PING188_CONF 0x000005bc
74
75#define MSG_WATCH188 0x09030400
76
77#define MSG_API_ON 0x08020102
78#define MSG_POOL_PCBIT 0x08020400
79#define MSG_POOL_PCBIT_CONF 0x00000401
80
81#define MSG_INFO_IND 0x00002602
82#define MSG_INFO_RESP 0x08002603
83
84#define MSG_DEBUG_188 0x0000ff00
85
86/*
87
88 long 4 3 2 1
89 Intel 1 2 3 4
90*/
91
92#ifdef __LITTLE_ENDIAN
93#define SET_MSG_SCMD(msg, ch) (msg = (msg & 0xffffff00) | (((ch) & 0xff)))
94#define SET_MSG_CMD(msg, ch) (msg = (msg & 0xffff00ff) | (((ch) & 0xff) << 8))
95#define SET_MSG_PROC(msg, ch) (msg = (msg & 0xff00ffff) | (((ch) & 0xff) << 16))
96#define SET_MSG_CPU(msg, ch) (msg = (msg & 0x00ffffff) | (((ch) & 0xff) << 24))
97
98#define GET_MSG_SCMD(msg) ((msg) & 0xFF)
99#define GET_MSG_CMD(msg) ((msg) >> 8 & 0xFF)
100#define GET_MSG_PROC(msg) ((msg) >> 16 & 0xFF)
101#define GET_MSG_CPU(msg) ((msg) >> 24)
102
103#else
104#error "Non-Intel CPU"
105#endif
106
107#define MAX_QUEUED 7
108
109#define SCHED_READ 0x01
110#define SCHED_WRITE 0x02
111
112#define SET_RUN_TIMEOUT (2 * HZ) /* 2 seconds */
113
114struct frame_buf {
115 ulong msg;
116 unsigned int refnum;
117 unsigned int dt_len;
118 unsigned int hdr_len;
119 struct sk_buff *skb;
120 unsigned int copied;
121 struct frame_buf *next;
122};
123
124extern int pcbit_l2_write(struct pcbit_dev *dev, ulong msg, ushort refnum,
125 struct sk_buff *skb, unsigned short hdr_len);
126
127extern irqreturn_t pcbit_irq_handler(int interrupt, void *);
128
129extern struct pcbit_dev *dev_pcbit[MAX_PCBIT_CARDS];
130
131#ifdef DEBUG
132static __inline__ void log_state(struct pcbit_dev *dev) {
133 printk(KERN_DEBUG "writeptr = %ld\n",
134 (ulong) (dev->writeptr - dev->sh_mem));
135 printk(KERN_DEBUG "readptr = %ld\n",
136 (ulong) (dev->readptr - (dev->sh_mem + BANK2)));
137 printk(KERN_DEBUG "{rcv_seq=%01x, send_seq=%01x, unack_seq=%01x}\n",
138 dev->rcv_seq, dev->send_seq, dev->unack_seq);
139}
140#endif
141
142static __inline__ struct pcbit_dev *chan2dev(struct pcbit_chan *chan)
143{
144 struct pcbit_dev *dev;
145 int i;
146
147
148 for (i = 0; i < MAX_PCBIT_CARDS; i++)
149 if ((dev = dev_pcbit[i]))
150 if (dev->b1 == chan || dev->b2 == chan)
151 return dev;
152 return NULL;
153
154}
155
156static __inline__ struct pcbit_dev *finddev(int id)
157{
158 struct pcbit_dev *dev;
159 int i;
160
161 for (i = 0; i < MAX_PCBIT_CARDS; i++)
162 if ((dev = dev_pcbit[i]))
163 if (dev->id == id)
164 return dev;
165 return NULL;
166}
167
168
169/*
170 * Support routines for reading and writing in the board
171 */
172
173static __inline__ void pcbit_writeb(struct pcbit_dev *dev, unsigned char dt)
174{
175 writeb(dt, dev->writeptr++);
176 if (dev->writeptr == dev->sh_mem + BANKLEN)
177 dev->writeptr = dev->sh_mem;
178}
179
180static __inline__ void pcbit_writew(struct pcbit_dev *dev, unsigned short dt)
181{
182 int dist;
183
184 dist = BANKLEN - (dev->writeptr - dev->sh_mem);
185 switch (dist) {
186 case 2:
187 writew(dt, dev->writeptr);
188 dev->writeptr = dev->sh_mem;
189 break;
190 case 1:
191 writeb((u_char) (dt & 0x00ffU), dev->writeptr);
192 dev->writeptr = dev->sh_mem;
193 writeb((u_char) (dt >> 8), dev->writeptr++);
194 break;
195 default:
196 writew(dt, dev->writeptr);
197 dev->writeptr += 2;
198 break;
199 };
200}
201
202static __inline__ void memcpy_topcbit(struct pcbit_dev *dev, u_char *data,
203 int len)
204{
205 int diff;
206
207 diff = len - (BANKLEN - (dev->writeptr - dev->sh_mem));
208
209 if (diff > 0)
210 {
211 memcpy_toio(dev->writeptr, data, len - diff);
212 memcpy_toio(dev->sh_mem, data + (len - diff), diff);
213 dev->writeptr = dev->sh_mem + diff;
214 }
215 else
216 {
217 memcpy_toio(dev->writeptr, data, len);
218
219 dev->writeptr += len;
220 if (diff == 0)
221 dev->writeptr = dev->sh_mem;
222 }
223}
224
225static __inline__ unsigned char pcbit_readb(struct pcbit_dev *dev)
226{
227 unsigned char val;
228
229 val = readb(dev->readptr++);
230 if (dev->readptr == dev->sh_mem + BANK2 + BANKLEN)
231 dev->readptr = dev->sh_mem + BANK2;
232
233 return val;
234}
235
236static __inline__ unsigned short pcbit_readw(struct pcbit_dev *dev)
237{
238 int dist;
239 unsigned short val;
240
241 dist = BANKLEN - (dev->readptr - (dev->sh_mem + BANK2));
242 switch (dist) {
243 case 2:
244 val = readw(dev->readptr);
245 dev->readptr = dev->sh_mem + BANK2;
246 break;
247 case 1:
248 val = readb(dev->readptr);
249 dev->readptr = dev->sh_mem + BANK2;
250 val = (readb(dev->readptr++) << 8) | val;
251 break;
252 default:
253 val = readw(dev->readptr);
254 dev->readptr += 2;
255 break;
256 };
257 return val;
258}
259
260static __inline__ void memcpy_frompcbit(struct pcbit_dev *dev, u_char *data, int len)
261{
262 int diff;
263
264 diff = len - (BANKLEN - (dev->readptr - (dev->sh_mem + BANK2)));
265 if (diff > 0)
266 {
267 memcpy_fromio(data, dev->readptr, len - diff);
268 memcpy_fromio(data + (len - diff), dev->sh_mem + BANK2 , diff);
269 dev->readptr = dev->sh_mem + BANK2 + diff;
270 }
271 else
272 {
273 memcpy_fromio(data, dev->readptr, len);
274 dev->readptr += len;
275 if (diff == 0)
276 dev->readptr = dev->sh_mem + BANK2;
277 }
278}
279
280
281#endif
diff --git a/drivers/staging/i4l/pcbit/module.c b/drivers/staging/i4l/pcbit/module.c
deleted file mode 100644
index 0a59bd0b8210..000000000000
--- a/drivers/staging/i4l/pcbit/module.c
+++ /dev/null
@@ -1,125 +0,0 @@
1/*
2 * PCBIT-D module support
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/string.h>
15#include <linux/kernel.h>
16#include <linux/skbuff.h>
17
18#include <linux/isdnif.h>
19#include "pcbit.h"
20
21MODULE_DESCRIPTION("ISDN4Linux: Driver for PCBIT-T card");
22MODULE_AUTHOR("Pedro Roque Marques");
23MODULE_LICENSE("GPL");
24
25static int mem[MAX_PCBIT_CARDS];
26static int irq[MAX_PCBIT_CARDS];
27
28module_param_array(mem, int, NULL, 0);
29module_param_array(irq, int, NULL, 0);
30
31static int num_boards;
32struct pcbit_dev *dev_pcbit[MAX_PCBIT_CARDS];
33
34static int __init pcbit_init(void)
35{
36 int board;
37
38 num_boards = 0;
39
40 printk(KERN_NOTICE
41 "PCBIT-D device driver v 0.5-fjpc0 19991204 - "
42 "Copyright (C) 1996 Universidade de Lisboa\n");
43
44 if (mem[0] || irq[0])
45 {
46 for (board = 0; board < MAX_PCBIT_CARDS && mem[board] && irq[board]; board++)
47 {
48 if (!mem[board])
49 mem[board] = 0xD0000;
50 if (!irq[board])
51 irq[board] = 5;
52
53 if (pcbit_init_dev(board, mem[board], irq[board]) == 0)
54 num_boards++;
55
56 else
57 {
58 printk(KERN_WARNING
59 "pcbit_init failed for dev %d",
60 board + 1);
61 return -EIO;
62 }
63 }
64 }
65
66 /* Hardcoded default settings detection */
67
68 if (!num_boards)
69 {
70 printk(KERN_INFO
71 "Trying to detect board using default settings\n");
72 if (pcbit_init_dev(0, 0xD0000, 5) == 0)
73 num_boards++;
74 else
75 return -EIO;
76 }
77 return 0;
78}
79
80static void __exit pcbit_exit(void)
81{
82#ifdef MODULE
83 int board;
84
85 for (board = 0; board < num_boards; board++)
86 pcbit_terminate(board);
87 printk(KERN_NOTICE
88 "PCBIT-D module unloaded\n");
89#endif
90}
91
92#ifndef MODULE
93#define MAX_PARA (MAX_PCBIT_CARDS * 2)
94static int __init pcbit_setup(char *line)
95{
96 int i, j, argc;
97 char *str;
98 int ints[MAX_PARA + 1];
99
100 str = get_options(line, MAX_PARA, ints);
101 argc = ints[0];
102 i = 0;
103 j = 1;
104
105 while (argc && (i < MAX_PCBIT_CARDS)) {
106
107 if (argc) {
108 mem[i] = ints[j];
109 j++; argc--;
110 }
111
112 if (argc) {
113 irq[i] = ints[j];
114 j++; argc--;
115 }
116
117 i++;
118 }
119 return (1);
120}
121__setup("pcbit=", pcbit_setup);
122#endif
123
124module_init(pcbit_init);
125module_exit(pcbit_exit);
diff --git a/drivers/staging/i4l/pcbit/pcbit.h b/drivers/staging/i4l/pcbit/pcbit.h
deleted file mode 100644
index 0a5a99440a80..000000000000
--- a/drivers/staging/i4l/pcbit/pcbit.h
+++ /dev/null
@@ -1,177 +0,0 @@
1/*
2 * PCBIT-D device driver definitions
3 *
4 * Copyright (C) 1996 Universidade de Lisboa
5 *
6 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
7 *
8 * This software may be used and distributed according to the terms of
9 * the GNU General Public License, incorporated herein by reference.
10 */
11
12#ifndef PCBIT_H
13#define PCBIT_H
14
15#include <linux/workqueue.h>
16
17#define MAX_PCBIT_CARDS 4
18
19
20#define BLOCK_TIMER
21
22#ifdef __KERNEL__
23
24struct pcbit_chan {
25 unsigned short id;
26 unsigned short callref; /* Call Reference */
27 unsigned char proto; /* layer2protocol */
28 unsigned char queued; /* unacked data messages */
29 unsigned char layer2link; /* used in TData */
30 unsigned char snum; /* used in TData */
31 unsigned short s_refnum;
32 unsigned short r_refnum;
33 unsigned short fsm_state;
34 struct timer_list fsm_timer;
35#ifdef BLOCK_TIMER
36 struct timer_list block_timer;
37#endif
38};
39
40struct msn_entry {
41 char *msn;
42 struct msn_entry *next;
43};
44
45struct pcbit_dev {
46 /* board */
47
48 volatile unsigned char __iomem *sh_mem; /* RDP address */
49 unsigned long ph_mem;
50 unsigned int irq;
51 unsigned int id;
52 unsigned int interrupt; /* set during interrupt
53 processing */
54 spinlock_t lock;
55 /* isdn4linux */
56
57 struct msn_entry *msn_list; /* ISDN address list */
58
59 isdn_if *dev_if;
60
61 ushort ll_hdrlen;
62 ushort hl_hdrlen;
63
64 /* link layer */
65 unsigned char l2_state;
66
67 struct frame_buf *read_queue;
68 struct frame_buf *read_frame;
69 struct frame_buf *write_queue;
70
71 /* Protocol start */
72 wait_queue_head_t set_running_wq;
73 struct timer_list set_running_timer;
74
75 struct timer_list error_recover_timer;
76
77 struct work_struct qdelivery;
78
79 u_char w_busy;
80 u_char r_busy;
81
82 volatile unsigned char __iomem *readptr;
83 volatile unsigned char __iomem *writeptr;
84
85 ushort loadptr;
86
87 unsigned short fsize[8]; /* sent layer2 frames size */
88
89 unsigned char send_seq;
90 unsigned char rcv_seq;
91 unsigned char unack_seq;
92
93 unsigned short free;
94
95 /* channels */
96
97 struct pcbit_chan *b1;
98 struct pcbit_chan *b2;
99};
100
101#define STATS_TIMER (10 * HZ)
102#define ERRTIME (HZ / 10)
103
104/* MRU */
105#define MAXBUFSIZE 1534
106#define MRU MAXBUFSIZE
107
108#define STATBUF_LEN 2048
109/*
110 *
111 */
112
113#endif /* __KERNEL__ */
114
115/* isdn_ctrl only allows a long sized argument */
116
117struct pcbit_ioctl {
118 union {
119 struct byte_op {
120 ushort addr;
121 ushort value;
122 } rdp_byte;
123 unsigned long l2_status;
124 } info;
125};
126
127
128
129#define PCBIT_IOCTL_GETSTAT 0x01 /* layer2 status */
130#define PCBIT_IOCTL_LWMODE 0x02 /* linear write mode */
131#define PCBIT_IOCTL_STRLOAD 0x03 /* start load mode */
132#define PCBIT_IOCTL_ENDLOAD 0x04 /* end load mode */
133#define PCBIT_IOCTL_SETBYTE 0x05 /* set byte */
134#define PCBIT_IOCTL_GETBYTE 0x06 /* get byte */
135#define PCBIT_IOCTL_RUNNING 0x07 /* set protocol running */
136#define PCBIT_IOCTL_WATCH188 0x08 /* set watch 188 */
137#define PCBIT_IOCTL_PING188 0x09 /* ping 188 */
138#define PCBIT_IOCTL_FWMODE 0x0A /* firmware write mode */
139#define PCBIT_IOCTL_STOP 0x0B /* stop protocol */
140#define PCBIT_IOCTL_APION 0x0C /* issue API_ON */
141
142#ifndef __KERNEL__
143
144#define PCBIT_GETSTAT (PCBIT_IOCTL_GETSTAT + IIOCDRVCTL)
145#define PCBIT_LWMODE (PCBIT_IOCTL_LWMODE + IIOCDRVCTL)
146#define PCBIT_STRLOAD (PCBIT_IOCTL_STRLOAD + IIOCDRVCTL)
147#define PCBIT_ENDLOAD (PCBIT_IOCTL_ENDLOAD + IIOCDRVCTL)
148#define PCBIT_SETBYTE (PCBIT_IOCTL_SETBYTE + IIOCDRVCTL)
149#define PCBIT_GETBYTE (PCBIT_IOCTL_GETBYTE + IIOCDRVCTL)
150#define PCBIT_RUNNING (PCBIT_IOCTL_RUNNING + IIOCDRVCTL)
151#define PCBIT_WATCH188 (PCBIT_IOCTL_WATCH188 + IIOCDRVCTL)
152#define PCBIT_PING188 (PCBIT_IOCTL_PING188 + IIOCDRVCTL)
153#define PCBIT_FWMODE (PCBIT_IOCTL_FWMODE + IIOCDRVCTL)
154#define PCBIT_STOP (PCBIT_IOCTL_STOP + IIOCDRVCTL)
155#define PCBIT_APION (PCBIT_IOCTL_APION + IIOCDRVCTL)
156
157#define MAXSUPERLINE 3000
158
159#endif
160
161#define L2_DOWN 0
162#define L2_LOADING 1
163#define L2_LWMODE 2
164#define L2_FWMODE 3
165#define L2_STARTING 4
166#define L2_RUNNING 5
167#define L2_ERROR 6
168
169void pcbit_deliver(struct work_struct *work);
170int pcbit_init_dev(int board, int mem_base, int irq);
171void pcbit_terminate(int board);
172void pcbit_l3_receive(struct pcbit_dev *dev, ulong msg, struct sk_buff *skb,
173 ushort hdr_len, ushort refnum);
174void pcbit_state_change(struct pcbit_dev *dev, struct pcbit_chan *chan,
175 unsigned short i, unsigned short ev, unsigned short f);
176
177#endif
diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c
index 6f3f8ff2a066..7963d4a83f84 100644
--- a/drivers/staging/iio/accel/adis16201_core.c
+++ b/drivers/staging/iio/accel/adis16201_core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ADIS16201 Programmable Digital Vibration Sensor driver 2 * ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer
3 * 3 *
4 * Copyright 2010 Analog Devices Inc. 4 * Copyright 2010 Analog Devices Inc.
5 * 5 *
@@ -243,6 +243,6 @@ static struct spi_driver adis16201_driver = {
243module_spi_driver(adis16201_driver); 243module_spi_driver(adis16201_driver);
244 244
245MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 245MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
246MODULE_DESCRIPTION("Analog Devices ADIS16201 Programmable Digital Vibration Sensor driver"); 246MODULE_DESCRIPTION("Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer");
247MODULE_LICENSE("GPL v2"); 247MODULE_LICENSE("GPL v2");
248MODULE_ALIAS("spi:adis16201"); 248MODULE_ALIAS("spi:adis16201");
diff --git a/drivers/staging/iio/accel/adis16203_core.c b/drivers/staging/iio/accel/adis16203_core.c
index c70671778bae..bd8119a23339 100644
--- a/drivers/staging/iio/accel/adis16203_core.c
+++ b/drivers/staging/iio/accel/adis16203_core.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * ADIS16203 Programmable Digital Vibration Sensor driver 2 * ADIS16203 Programmable 360 Degrees Inclinometer
3 * 3 *
4 * Copyright 2030 Analog Devices Inc. 4 * Copyright 2010 Analog Devices Inc.
5 * 5 *
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
@@ -211,6 +211,6 @@ static struct spi_driver adis16203_driver = {
211module_spi_driver(adis16203_driver); 211module_spi_driver(adis16203_driver);
212 212
213MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 213MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
214MODULE_DESCRIPTION("Analog Devices ADIS16203 Programmable Digital Vibration Sensor driver"); 214MODULE_DESCRIPTION("Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer");
215MODULE_LICENSE("GPL v2"); 215MODULE_LICENSE("GPL v2");
216MODULE_ALIAS("spi:adis16203"); 216MODULE_ALIAS("spi:adis16203");
diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c
index 8dbad58628a1..a599e19303d3 100644
--- a/drivers/staging/iio/accel/adis16209_core.c
+++ b/drivers/staging/iio/accel/adis16209_core.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ADIS16209 Programmable Digital Vibration Sensor driver 2 * ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer
3 * 3 *
4 * Copyright 2010 Analog Devices Inc. 4 * Copyright 2010 Analog Devices Inc.
5 * 5 *
@@ -243,6 +243,6 @@ static struct spi_driver adis16209_driver = {
243module_spi_driver(adis16209_driver); 243module_spi_driver(adis16209_driver);
244 244
245MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>"); 245MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
246MODULE_DESCRIPTION("Analog Devices ADIS16209 Digital Vibration Sensor driver"); 246MODULE_DESCRIPTION("Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer");
247MODULE_LICENSE("GPL v2"); 247MODULE_LICENSE("GPL v2");
248MODULE_ALIAS("spi:adis16209"); 248MODULE_ALIAS("spi:adis16209");
diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c
index 453190864b2f..9dbfa64b1e53 100644
--- a/drivers/staging/iio/adc/ad7606.c
+++ b/drivers/staging/iio/adc/ad7606.c
@@ -26,6 +26,11 @@
26 26
27#include "ad7606.h" 27#include "ad7606.h"
28 28
29/* Scales are computed as 2.5/2**16 and 5/2**16 respectively */
30static const unsigned int scale_avail[2][2] = {
31 {0, 38147}, {0, 76294}
32};
33
29static int ad7606_reset(struct ad7606_state *st) 34static int ad7606_reset(struct ad7606_state *st)
30{ 35{
31 if (st->gpio_reset) { 36 if (st->gpio_reset) {
@@ -151,9 +156,9 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
151 *val = (short)ret; 156 *val = (short)ret;
152 return IIO_VAL_INT; 157 return IIO_VAL_INT;
153 case IIO_CHAN_INFO_SCALE: 158 case IIO_CHAN_INFO_SCALE:
154 *val = st->range * 2; 159 *val = scale_avail[st->range][0];
155 *val2 = st->chip_info->channels[0].scan_type.realbits; 160 *val2 = scale_avail[st->range][1];
156 return IIO_VAL_FRACTIONAL_LOG2; 161 return IIO_VAL_INT_PLUS_MICRO;
157 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 162 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
158 *val = st->oversampling; 163 *val = st->oversampling;
159 return IIO_VAL_INT; 164 return IIO_VAL_INT;
@@ -161,42 +166,22 @@ static int ad7606_read_raw(struct iio_dev *indio_dev,
161 return -EINVAL; 166 return -EINVAL;
162} 167}
163 168
164static ssize_t ad7606_show_range(struct device *dev, 169static ssize_t in_voltage_scale_available_show(struct device *dev,
165 struct device_attribute *attr, char *buf) 170 struct device_attribute *attr,
166{ 171 char *buf)
167 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
168 struct ad7606_state *st = iio_priv(indio_dev);
169
170 return sprintf(buf, "%u\n", st->range);
171}
172
173static ssize_t ad7606_store_range(struct device *dev,
174 struct device_attribute *attr,
175 const char *buf, size_t count)
176{ 172{
177 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 173 int i, len = 0;
178 struct ad7606_state *st = iio_priv(indio_dev);
179 unsigned long lval;
180 int ret;
181
182 ret = kstrtoul(buf, 10, &lval);
183 if (ret)
184 return ret;
185 174
186 if (!(lval == 5000 || lval == 10000)) 175 for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
187 return -EINVAL; 176 len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06u ",
177 scale_avail[i][0], scale_avail[i][1]);
188 178
189 mutex_lock(&indio_dev->mlock); 179 buf[len - 1] = '\n';
190 gpiod_set_value(st->gpio_range, lval == 10000);
191 st->range = lval;
192 mutex_unlock(&indio_dev->mlock);
193 180
194 return count; 181 return len;
195} 182}
196 183
197static IIO_DEVICE_ATTR(in_voltage_range, S_IRUGO | S_IWUSR, 184static IIO_DEVICE_ATTR_RO(in_voltage_scale_available, 0);
198 ad7606_show_range, ad7606_store_range, 0);
199static IIO_CONST_ATTR(in_voltage_range_available, "5000 10000");
200 185
201static int ad7606_oversampling_get_index(unsigned int val) 186static int ad7606_oversampling_get_index(unsigned int val)
202{ 187{
@@ -218,9 +203,23 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
218{ 203{
219 struct ad7606_state *st = iio_priv(indio_dev); 204 struct ad7606_state *st = iio_priv(indio_dev);
220 int values[3]; 205 int values[3];
221 int ret; 206 int ret, i;
222 207
223 switch (mask) { 208 switch (mask) {
209 case IIO_CHAN_INFO_SCALE:
210 ret = -EINVAL;
211 mutex_lock(&indio_dev->mlock);
212 for (i = 0; i < ARRAY_SIZE(scale_avail); i++)
213 if (val2 == scale_avail[i][1]) {
214 gpiod_set_value(st->gpio_range, i);
215 st->range = i;
216
217 ret = 0;
218 break;
219 }
220 mutex_unlock(&indio_dev->mlock);
221
222 return ret;
224 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 223 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
225 if (val2) 224 if (val2)
226 return -EINVAL; 225 return -EINVAL;
@@ -247,8 +246,7 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
247static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64"); 246static IIO_CONST_ATTR(oversampling_ratio_available, "1 2 4 8 16 32 64");
248 247
249static struct attribute *ad7606_attributes_os_and_range[] = { 248static struct attribute *ad7606_attributes_os_and_range[] = {
250 &iio_dev_attr_in_voltage_range.dev_attr.attr, 249 &iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
251 &iio_const_attr_in_voltage_range_available.dev_attr.attr,
252 &iio_const_attr_oversampling_ratio_available.dev_attr.attr, 250 &iio_const_attr_oversampling_ratio_available.dev_attr.attr,
253 NULL, 251 NULL,
254}; 252};
@@ -267,8 +265,7 @@ static const struct attribute_group ad7606_attribute_group_os = {
267}; 265};
268 266
269static struct attribute *ad7606_attributes_range[] = { 267static struct attribute *ad7606_attributes_range[] = {
270 &iio_dev_attr_in_voltage_range.dev_attr.attr, 268 &iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
271 &iio_const_attr_in_voltage_range_available.dev_attr.attr,
272 NULL, 269 NULL,
273}; 270};
274 271
@@ -397,6 +394,7 @@ static const struct iio_info ad7606_info_os = {
397static const struct iio_info ad7606_info_range = { 394static const struct iio_info ad7606_info_range = {
398 .driver_module = THIS_MODULE, 395 .driver_module = THIS_MODULE,
399 .read_raw = &ad7606_read_raw, 396 .read_raw = &ad7606_read_raw,
397 .write_raw = &ad7606_write_raw,
400 .attrs = &ad7606_attribute_group_range, 398 .attrs = &ad7606_attribute_group_range,
401}; 399};
402 400
@@ -417,7 +415,8 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
417 st->dev = dev; 415 st->dev = dev;
418 st->bops = bops; 416 st->bops = bops;
419 st->base_address = base_address; 417 st->base_address = base_address;
420 st->range = 5000; 418 /* tied to logic low, analog input range is +/- 5V */
419 st->range = 0;
421 st->oversampling = 1; 420 st->oversampling = 1;
422 INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring); 421 INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
423 422
@@ -525,7 +524,7 @@ static int ad7606_resume(struct device *dev)
525 struct ad7606_state *st = iio_priv(indio_dev); 524 struct ad7606_state *st = iio_priv(indio_dev);
526 525
527 if (st->gpio_standby) { 526 if (st->gpio_standby) {
528 gpiod_set_value(st->gpio_range, st->range == 10000); 527 gpiod_set_value(st->gpio_range, st->range);
529 gpiod_set_value(st->gpio_standby, 1); 528 gpiod_set_value(st->gpio_standby, 1);
530 ad7606_reset(st); 529 ad7606_reset(st);
531 } 530 }
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 72551f827382..17d280581e24 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -139,7 +139,7 @@ static ssize_t ad7816_store_mode(struct device *dev,
139 return len; 139 return len;
140} 140}
141 141
142static IIO_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, 142static IIO_DEVICE_ATTR(mode, 0644,
143 ad7816_show_mode, 143 ad7816_show_mode,
144 ad7816_store_mode, 144 ad7816_store_mode,
145 0); 145 0);
@@ -151,7 +151,7 @@ static ssize_t ad7816_show_available_modes(struct device *dev,
151 return sprintf(buf, "full\npower-save\n"); 151 return sprintf(buf, "full\npower-save\n");
152} 152}
153 153
154static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7816_show_available_modes, 154static IIO_DEVICE_ATTR(available_modes, 0444, ad7816_show_available_modes,
155 NULL, 0); 155 NULL, 0);
156 156
157static ssize_t ad7816_show_channel(struct device *dev, 157static ssize_t ad7816_show_channel(struct device *dev,
@@ -197,7 +197,7 @@ static ssize_t ad7816_store_channel(struct device *dev,
197 return len; 197 return len;
198} 198}
199 199
200static IIO_DEVICE_ATTR(channel, S_IRUGO | S_IWUSR, 200static IIO_DEVICE_ATTR(channel, 0644,
201 ad7816_show_channel, 201 ad7816_show_channel,
202 ad7816_store_channel, 202 ad7816_store_channel,
203 0); 203 0);
@@ -228,7 +228,7 @@ static ssize_t ad7816_show_value(struct device *dev,
228 return sprintf(buf, "%u\n", data); 228 return sprintf(buf, "%u\n", data);
229} 229}
230 230
231static IIO_DEVICE_ATTR(value, S_IRUGO, ad7816_show_value, NULL, 0); 231static IIO_DEVICE_ATTR(value, 0444, ad7816_show_value, NULL, 0);
232 232
233static struct attribute *ad7816_attributes[] = { 233static struct attribute *ad7816_attributes[] = {
234 &iio_dev_attr_available_modes.dev_attr.attr, 234 &iio_dev_attr_available_modes.dev_attr.attr,
@@ -319,7 +319,7 @@ static inline ssize_t ad7816_set_oti(struct device *dev,
319 return len; 319 return len;
320} 320}
321 321
322static IIO_DEVICE_ATTR(oti, S_IRUGO | S_IWUSR, 322static IIO_DEVICE_ATTR(oti, 0644,
323 ad7816_show_oti, ad7816_set_oti, 0); 323 ad7816_show_oti, ad7816_set_oti, 0);
324 324
325static struct attribute *ad7816_event_attributes[] = { 325static struct attribute *ad7816_event_attributes[] = {
diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c
index 0ccf192b9a03..f66dd3ebbab1 100644
--- a/drivers/staging/iio/addac/adt7316-i2c.c
+++ b/drivers/staging/iio/addac/adt7316-i2c.c
@@ -93,7 +93,7 @@ static int adt7316_i2c_multi_write(void *client, u8 reg, u8 count, u8 *data)
93 */ 93 */
94 94
95static int adt7316_i2c_probe(struct i2c_client *client, 95static int adt7316_i2c_probe(struct i2c_client *client,
96 const struct i2c_device_id *id) 96 const struct i2c_device_id *id)
97{ 97{
98 struct adt7316_bus bus = { 98 struct adt7316_bus bus = {
99 .client = client, 99 .client = client,
diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c
index a7d90c8bac5e..6054c7298fce 100644
--- a/drivers/staging/iio/addac/adt7316.c
+++ b/drivers/staging/iio/addac/adt7316.c
@@ -661,8 +661,9 @@ static ssize_t adt7316_store_da_high_resolution(struct device *dev,
661 chip->dac_bits = 12; 661 chip->dac_bits = 12;
662 else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517) 662 else if (chip->id == ID_ADT7317 || chip->id == ID_ADT7517)
663 chip->dac_bits = 10; 663 chip->dac_bits = 10;
664 } else 664 } else {
665 config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION); 665 config3 = chip->config3 & (~ADT7316_DA_HIGH_RESOLUTION);
666 }
666 667
667 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3); 668 ret = chip->bus.write(chip->bus.client, ADT7316_CONFIG3, config3);
668 if (ret) 669 if (ret)
diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c
index 6998c3ddfb6a..ca72af3e9d4b 100644
--- a/drivers/staging/iio/cdc/ad7150.c
+++ b/drivers/staging/iio/cdc/ad7150.c
@@ -274,7 +274,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
274error_ret: 274error_ret:
275 mutex_unlock(&chip->state_lock); 275 mutex_unlock(&chip->state_lock);
276 276
277 return 0; 277 return ret;
278} 278}
279 279
280static int ad7150_read_event_value(struct iio_dev *indio_dev, 280static int ad7150_read_event_value(struct iio_dev *indio_dev,
@@ -414,7 +414,7 @@ error_ret:
414 414
415#define AD7150_TIMEOUT(chan, type, dir, ev_type, ev_dir) \ 415#define AD7150_TIMEOUT(chan, type, dir, ev_type, ev_dir) \
416 IIO_DEVICE_ATTR(in_capacitance##chan##_##type##_##dir##_timeout, \ 416 IIO_DEVICE_ATTR(in_capacitance##chan##_##type##_##dir##_timeout, \
417 S_IRUGO | S_IWUSR, \ 417 0644, \
418 &ad7150_show_timeout, \ 418 &ad7150_show_timeout, \
419 &ad7150_store_timeout, \ 419 &ad7150_store_timeout, \
420 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, \ 420 IIO_UNMOD_EVENT_CODE(IIO_CAPACITANCE, \
@@ -610,27 +610,27 @@ static int ad7150_probe(struct i2c_client *client,
610 610
611 if (client->irq) { 611 if (client->irq) {
612 ret = devm_request_threaded_irq(&client->dev, client->irq, 612 ret = devm_request_threaded_irq(&client->dev, client->irq,
613 NULL, 613 NULL,
614 &ad7150_event_handler, 614 &ad7150_event_handler,
615 IRQF_TRIGGER_RISING | 615 IRQF_TRIGGER_RISING |
616 IRQF_TRIGGER_FALLING | 616 IRQF_TRIGGER_FALLING |
617 IRQF_ONESHOT, 617 IRQF_ONESHOT,
618 "ad7150_irq1", 618 "ad7150_irq1",
619 indio_dev); 619 indio_dev);
620 if (ret) 620 if (ret)
621 return ret; 621 return ret;
622 } 622 }
623 623
624 if (client->dev.platform_data) { 624 if (client->dev.platform_data) {
625 ret = devm_request_threaded_irq(&client->dev, *(unsigned int *) 625 ret = devm_request_threaded_irq(&client->dev, *(unsigned int *)
626 client->dev.platform_data, 626 client->dev.platform_data,
627 NULL, 627 NULL,
628 &ad7150_event_handler, 628 &ad7150_event_handler,
629 IRQF_TRIGGER_RISING | 629 IRQF_TRIGGER_RISING |
630 IRQF_TRIGGER_FALLING | 630 IRQF_TRIGGER_FALLING |
631 IRQF_ONESHOT, 631 IRQF_ONESHOT,
632 "ad7150_irq2", 632 "ad7150_irq2",
633 indio_dev); 633 indio_dev);
634 if (ret) 634 if (ret)
635 return ret; 635 return ret;
636 } 636 }
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 944789843938..5e96352fa4ac 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -23,8 +23,8 @@
23#include <linux/iio/kfifo_buf.h> 23#include <linux/iio/kfifo_buf.h>
24 24
25/* AD5933/AD5934 Registers */ 25/* AD5933/AD5934 Registers */
26#define AD5933_REG_CONTROL_HB 0x80 /* R/W, 2 bytes */ 26#define AD5933_REG_CONTROL_HB 0x80 /* R/W, 1 byte */
27#define AD5933_REG_CONTROL_LB 0x81 /* R/W, 2 bytes */ 27#define AD5933_REG_CONTROL_LB 0x81 /* R/W, 1 byte */
28#define AD5933_REG_FREQ_START 0x82 /* R/W, 3 bytes */ 28#define AD5933_REG_FREQ_START 0x82 /* R/W, 3 bytes */
29#define AD5933_REG_FREQ_INC 0x85 /* R/W, 3 bytes */ 29#define AD5933_REG_FREQ_INC 0x85 /* R/W, 3 bytes */
30#define AD5933_REG_INC_NUM 0x88 /* R/W, 2 bytes, 9 bit */ 30#define AD5933_REG_INC_NUM 0x88 /* R/W, 2 bytes, 9 bit */
diff --git a/drivers/staging/iio/light/isl29028.c b/drivers/staging/iio/light/isl29028.c
index aa413e5878b9..6bb6d37cc7d1 100644
--- a/drivers/staging/iio/light/isl29028.c
+++ b/drivers/staging/iio/light/isl29028.c
@@ -26,39 +26,42 @@
26#include <linux/regmap.h> 26#include <linux/regmap.h>
27#include <linux/iio/iio.h> 27#include <linux/iio/iio.h>
28#include <linux/iio/sysfs.h> 28#include <linux/iio/sysfs.h>
29#include <linux/pm_runtime.h>
29 30
30#define ISL29028_CONV_TIME_MS 100 31#define ISL29028_CONV_TIME_MS 100
31 32
32#define ISL29028_REG_CONFIGURE 0x01 33#define ISL29028_REG_CONFIGURE 0x01
33 34
34#define ISL29028_CONF_ALS_IR_MODE_ALS 0 35#define ISL29028_CONF_ALS_IR_MODE_ALS 0
35#define ISL29028_CONF_ALS_IR_MODE_IR BIT(0) 36#define ISL29028_CONF_ALS_IR_MODE_IR BIT(0)
36#define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0) 37#define ISL29028_CONF_ALS_IR_MODE_MASK BIT(0)
37 38
38#define ISL29028_CONF_ALS_RANGE_LOW_LUX 0 39#define ISL29028_CONF_ALS_RANGE_LOW_LUX 0
39#define ISL29028_CONF_ALS_RANGE_HIGH_LUX BIT(1) 40#define ISL29028_CONF_ALS_RANGE_HIGH_LUX BIT(1)
40#define ISL29028_CONF_ALS_RANGE_MASK BIT(1) 41#define ISL29028_CONF_ALS_RANGE_MASK BIT(1)
41 42
42#define ISL29028_CONF_ALS_DIS 0 43#define ISL29028_CONF_ALS_DIS 0
43#define ISL29028_CONF_ALS_EN BIT(2) 44#define ISL29028_CONF_ALS_EN BIT(2)
44#define ISL29028_CONF_ALS_EN_MASK BIT(2) 45#define ISL29028_CONF_ALS_EN_MASK BIT(2)
45 46
46#define ISL29028_CONF_PROX_SLP_SH 4 47#define ISL29028_CONF_PROX_SLP_SH 4
47#define ISL29028_CONF_PROX_SLP_MASK (7 << ISL29028_CONF_PROX_SLP_SH) 48#define ISL29028_CONF_PROX_SLP_MASK (7 << ISL29028_CONF_PROX_SLP_SH)
48 49
49#define ISL29028_CONF_PROX_EN BIT(7) 50#define ISL29028_CONF_PROX_EN BIT(7)
50#define ISL29028_CONF_PROX_EN_MASK BIT(7) 51#define ISL29028_CONF_PROX_EN_MASK BIT(7)
51 52
52#define ISL29028_REG_INTERRUPT 0x02 53#define ISL29028_REG_INTERRUPT 0x02
53 54
54#define ISL29028_REG_PROX_DATA 0x08 55#define ISL29028_REG_PROX_DATA 0x08
55#define ISL29028_REG_ALSIR_L 0x09 56#define ISL29028_REG_ALSIR_L 0x09
56#define ISL29028_REG_ALSIR_U 0x0A 57#define ISL29028_REG_ALSIR_U 0x0A
57 58
58#define ISL29028_REG_TEST1_MODE 0x0E 59#define ISL29028_REG_TEST1_MODE 0x0E
59#define ISL29028_REG_TEST2_MODE 0x0F 60#define ISL29028_REG_TEST2_MODE 0x0F
60 61
61#define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1) 62#define ISL29028_NUM_REGS (ISL29028_REG_TEST2_MODE + 1)
63
64#define ISL29028_POWER_OFF_DELAY_MS 2000
62 65
63enum isl29028_als_ir_mode { 66enum isl29028_als_ir_mode {
64 ISL29028_MODE_NONE = 0, 67 ISL29028_MODE_NONE = 0,
@@ -67,62 +70,93 @@ enum isl29028_als_ir_mode {
67}; 70};
68 71
69struct isl29028_chip { 72struct isl29028_chip {
70 struct mutex lock; 73 struct mutex lock;
71 struct regmap *regmap; 74 struct regmap *regmap;
72 75 unsigned int prox_sampling;
73 unsigned int prox_sampling; 76 bool enable_prox;
74 bool enable_prox; 77 int lux_scale;
75
76 int lux_scale;
77 enum isl29028_als_ir_mode als_ir_mode; 78 enum isl29028_als_ir_mode als_ir_mode;
78}; 79};
79 80
80static int isl29028_set_proxim_sampling(struct isl29028_chip *chip, 81static int isl29028_set_proxim_sampling(struct isl29028_chip *chip,
81 unsigned int sampling) 82 unsigned int sampling)
82{ 83{
84 struct device *dev = regmap_get_device(chip->regmap);
83 static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0}; 85 static unsigned int prox_period[] = {800, 400, 200, 100, 75, 50, 12, 0};
84 int sel;
85 unsigned int period = DIV_ROUND_UP(1000, sampling); 86 unsigned int period = DIV_ROUND_UP(1000, sampling);
87 int sel, ret;
86 88
87 for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) { 89 for (sel = 0; sel < ARRAY_SIZE(prox_period); ++sel) {
88 if (period >= prox_period[sel]) 90 if (period >= prox_period[sel])
89 break; 91 break;
90 } 92 }
91 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 93
92 ISL29028_CONF_PROX_SLP_MASK, 94 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
93 sel << ISL29028_CONF_PROX_SLP_SH); 95 ISL29028_CONF_PROX_SLP_MASK,
96 sel << ISL29028_CONF_PROX_SLP_SH);
97
98 if (ret < 0) {
99 dev_err(dev, "%s(): Error %d setting the proximity sampling\n",
100 __func__, ret);
101 return ret;
102 }
103
104 chip->prox_sampling = sampling;
105
106 return ret;
94} 107}
95 108
96static int isl29028_enable_proximity(struct isl29028_chip *chip, bool enable) 109static int isl29028_enable_proximity(struct isl29028_chip *chip)
97{ 110{
98 int ret; 111 int ret;
99 int val = 0;
100 112
101 if (enable) 113 ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling);
102 val = ISL29028_CONF_PROX_EN; 114 if (ret < 0)
115 return ret;
116
103 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 117 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
104 ISL29028_CONF_PROX_EN_MASK, val); 118 ISL29028_CONF_PROX_EN_MASK,
119 ISL29028_CONF_PROX_EN);
105 if (ret < 0) 120 if (ret < 0)
106 return ret; 121 return ret;
107 122
108 /* Wait for conversion to be complete for first sample */ 123 /* Wait for conversion to be complete for first sample */
109 mdelay(DIV_ROUND_UP(1000, chip->prox_sampling)); 124 mdelay(DIV_ROUND_UP(1000, chip->prox_sampling));
125
110 return 0; 126 return 0;
111} 127}
112 128
113static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale) 129static int isl29028_set_als_scale(struct isl29028_chip *chip, int lux_scale)
114{ 130{
131 struct device *dev = regmap_get_device(chip->regmap);
115 int val = (lux_scale == 2000) ? ISL29028_CONF_ALS_RANGE_HIGH_LUX : 132 int val = (lux_scale == 2000) ? ISL29028_CONF_ALS_RANGE_HIGH_LUX :
116 ISL29028_CONF_ALS_RANGE_LOW_LUX; 133 ISL29028_CONF_ALS_RANGE_LOW_LUX;
134 int ret;
117 135
118 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 136 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
119 ISL29028_CONF_ALS_RANGE_MASK, val); 137 ISL29028_CONF_ALS_RANGE_MASK, val);
138 if (ret < 0) {
139 dev_err(dev, "%s(): Error %d setting the ALS scale\n", __func__,
140 ret);
141 return ret;
142 }
143
144 chip->lux_scale = lux_scale;
145
146 return ret;
120} 147}
121 148
122static int isl29028_set_als_ir_mode(struct isl29028_chip *chip, 149static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
123 enum isl29028_als_ir_mode mode) 150 enum isl29028_als_ir_mode mode)
124{ 151{
125 int ret = 0; 152 int ret;
153
154 if (chip->als_ir_mode == mode)
155 return 0;
156
157 ret = isl29028_set_als_scale(chip, chip->lux_scale);
158 if (ret < 0)
159 return ret;
126 160
127 switch (mode) { 161 switch (mode) {
128 case ISL29028_MODE_ALS: 162 case ISL29028_MODE_ALS:
@@ -136,16 +170,15 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
136 ISL29028_CONF_ALS_RANGE_MASK, 170 ISL29028_CONF_ALS_RANGE_MASK,
137 ISL29028_CONF_ALS_RANGE_HIGH_LUX); 171 ISL29028_CONF_ALS_RANGE_HIGH_LUX);
138 break; 172 break;
139
140 case ISL29028_MODE_IR: 173 case ISL29028_MODE_IR:
141 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 174 ret = regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
142 ISL29028_CONF_ALS_IR_MODE_MASK, 175 ISL29028_CONF_ALS_IR_MODE_MASK,
143 ISL29028_CONF_ALS_IR_MODE_IR); 176 ISL29028_CONF_ALS_IR_MODE_IR);
144 break; 177 break;
145
146 case ISL29028_MODE_NONE: 178 case ISL29028_MODE_NONE:
147 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE, 179 return regmap_update_bits(chip->regmap, ISL29028_REG_CONFIGURE,
148 ISL29028_CONF_ALS_EN_MASK, ISL29028_CONF_ALS_DIS); 180 ISL29028_CONF_ALS_EN_MASK,
181 ISL29028_CONF_ALS_DIS);
149 } 182 }
150 183
151 if (ret < 0) 184 if (ret < 0)
@@ -160,6 +193,9 @@ static int isl29028_set_als_ir_mode(struct isl29028_chip *chip,
160 193
161 /* Need to wait for conversion time if ALS/IR mode enabled */ 194 /* Need to wait for conversion time if ALS/IR mode enabled */
162 mdelay(ISL29028_CONV_TIME_MS); 195 mdelay(ISL29028_CONV_TIME_MS);
196
197 chip->als_ir_mode = mode;
198
163 return 0; 199 return 0;
164} 200}
165 201
@@ -173,18 +209,21 @@ static int isl29028_read_als_ir(struct isl29028_chip *chip, int *als_ir)
173 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb); 209 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_L, &lsb);
174 if (ret < 0) { 210 if (ret < 0) {
175 dev_err(dev, 211 dev_err(dev,
176 "Error in reading register ALSIR_L err %d\n", ret); 212 "%s(): Error %d reading register ALSIR_L\n",
213 __func__, ret);
177 return ret; 214 return ret;
178 } 215 }
179 216
180 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb); 217 ret = regmap_read(chip->regmap, ISL29028_REG_ALSIR_U, &msb);
181 if (ret < 0) { 218 if (ret < 0) {
182 dev_err(dev, 219 dev_err(dev,
183 "Error in reading register ALSIR_U err %d\n", ret); 220 "%s(): Error %d reading register ALSIR_U\n",
221 __func__, ret);
184 return ret; 222 return ret;
185 } 223 }
186 224
187 *als_ir = ((msb & 0xF) << 8) | (lsb & 0xFF); 225 *als_ir = ((msb & 0xF) << 8) | (lsb & 0xFF);
226
188 return 0; 227 return 0;
189} 228}
190 229
@@ -194,27 +233,24 @@ static int isl29028_read_proxim(struct isl29028_chip *chip, int *prox)
194 unsigned int data; 233 unsigned int data;
195 int ret; 234 int ret;
196 235
236 if (!chip->enable_prox) {
237 ret = isl29028_enable_proximity(chip);
238 if (ret < 0)
239 return ret;
240
241 chip->enable_prox = true;
242 }
243
197 ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data); 244 ret = regmap_read(chip->regmap, ISL29028_REG_PROX_DATA, &data);
198 if (ret < 0) { 245 if (ret < 0) {
199 dev_err(dev, "Error in reading register %d, error %d\n", 246 dev_err(dev, "%s(): Error %d reading register PROX_DATA\n",
200 ISL29028_REG_PROX_DATA, ret); 247 __func__, ret);
201 return ret; 248 return ret;
202 } 249 }
203 *prox = data;
204 return 0;
205}
206 250
207static int isl29028_proxim_get(struct isl29028_chip *chip, int *prox_data) 251 *prox = data;
208{
209 int ret;
210 252
211 if (!chip->enable_prox) { 253 return 0;
212 ret = isl29028_enable_proximity(chip, true);
213 if (ret < 0)
214 return ret;
215 chip->enable_prox = true;
216 }
217 return isl29028_read_proxim(chip, prox_data);
218} 254}
219 255
220static int isl29028_als_get(struct isl29028_chip *chip, int *als_data) 256static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
@@ -223,14 +259,11 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
223 int ret; 259 int ret;
224 int als_ir_data; 260 int als_ir_data;
225 261
226 if (chip->als_ir_mode != ISL29028_MODE_ALS) { 262 ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS);
227 ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_ALS); 263 if (ret < 0) {
228 if (ret < 0) { 264 dev_err(dev, "%s(): Error %d enabling ALS mode\n", __func__,
229 dev_err(dev, 265 ret);
230 "Error in enabling ALS mode err %d\n", ret); 266 return ret;
231 return ret;
232 }
233 chip->als_ir_mode = ISL29028_MODE_ALS;
234 } 267 }
235 268
236 ret = isl29028_read_als_ir(chip, &als_ir_data); 269 ret = isl29028_read_als_ir(chip, &als_ir_data);
@@ -248,6 +281,7 @@ static int isl29028_als_get(struct isl29028_chip *chip, int *als_data)
248 als_ir_data = (als_ir_data * 49) / 100; 281 als_ir_data = (als_ir_data * 49) / 100;
249 282
250 *als_data = als_ir_data; 283 *als_data = als_ir_data;
284
251 return 0; 285 return 0;
252} 286}
253 287
@@ -256,18 +290,33 @@ static int isl29028_ir_get(struct isl29028_chip *chip, int *ir_data)
256 struct device *dev = regmap_get_device(chip->regmap); 290 struct device *dev = regmap_get_device(chip->regmap);
257 int ret; 291 int ret;
258 292
259 if (chip->als_ir_mode != ISL29028_MODE_IR) { 293 ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR);
260 ret = isl29028_set_als_ir_mode(chip, ISL29028_MODE_IR); 294 if (ret < 0) {
261 if (ret < 0) { 295 dev_err(dev, "%s(): Error %d enabling IR mode\n", __func__,
262 dev_err(dev, 296 ret);
263 "Error in enabling IR mode err %d\n", ret); 297 return ret;
264 return ret;
265 }
266 chip->als_ir_mode = ISL29028_MODE_IR;
267 } 298 }
299
268 return isl29028_read_als_ir(chip, ir_data); 300 return isl29028_read_als_ir(chip, ir_data);
269} 301}
270 302
303static int isl29028_set_pm_runtime_busy(struct isl29028_chip *chip, bool on)
304{
305 struct device *dev = regmap_get_device(chip->regmap);
306 int ret;
307
308 if (on) {
309 ret = pm_runtime_get_sync(dev);
310 if (ret < 0)
311 pm_runtime_put_noidle(dev);
312 } else {
313 pm_runtime_mark_last_busy(dev);
314 ret = pm_runtime_put_autosuspend(dev);
315 }
316
317 return ret;
318}
319
271/* Channel IO */ 320/* Channel IO */
272static int isl29028_write_raw(struct iio_dev *indio_dev, 321static int isl29028_write_raw(struct iio_dev *indio_dev,
273 struct iio_chan_spec const *chan, 322 struct iio_chan_spec const *chan,
@@ -275,58 +324,65 @@ static int isl29028_write_raw(struct iio_dev *indio_dev,
275{ 324{
276 struct isl29028_chip *chip = iio_priv(indio_dev); 325 struct isl29028_chip *chip = iio_priv(indio_dev);
277 struct device *dev = regmap_get_device(chip->regmap); 326 struct device *dev = regmap_get_device(chip->regmap);
278 int ret = -EINVAL; 327 int ret;
328
329 ret = isl29028_set_pm_runtime_busy(chip, true);
330 if (ret < 0)
331 return ret;
279 332
280 mutex_lock(&chip->lock); 333 mutex_lock(&chip->lock);
334
335 ret = -EINVAL;
281 switch (chan->type) { 336 switch (chan->type) {
282 case IIO_PROXIMITY: 337 case IIO_PROXIMITY:
283 if (mask != IIO_CHAN_INFO_SAMP_FREQ) { 338 if (mask != IIO_CHAN_INFO_SAMP_FREQ) {
284 dev_err(dev, 339 dev_err(dev,
285 "proximity: mask value 0x%08lx not supported\n", 340 "%s(): proximity: Mask value 0x%08lx is not supported\n",
286 mask); 341 __func__, mask);
287 break; 342 break;
288 } 343 }
344
289 if (val < 1 || val > 100) { 345 if (val < 1 || val > 100) {
290 dev_err(dev, 346 dev_err(dev,
291 "Samp_freq %d is not in range[1:100]\n", val); 347 "%s(): proximity: Sampling frequency %d is not in the range [1:100]\n",
348 __func__, val);
292 break; 349 break;
293 } 350 }
351
294 ret = isl29028_set_proxim_sampling(chip, val); 352 ret = isl29028_set_proxim_sampling(chip, val);
295 if (ret < 0) {
296 dev_err(dev,
297 "Setting proximity samp_freq fail, err %d\n",
298 ret);
299 break;
300 }
301 chip->prox_sampling = val;
302 break; 353 break;
303
304 case IIO_LIGHT: 354 case IIO_LIGHT:
305 if (mask != IIO_CHAN_INFO_SCALE) { 355 if (mask != IIO_CHAN_INFO_SCALE) {
306 dev_err(dev, 356 dev_err(dev,
307 "light: mask value 0x%08lx not supported\n", 357 "%s(): light: Mask value 0x%08lx is not supported\n",
308 mask); 358 __func__, mask);
309 break; 359 break;
310 } 360 }
311 if ((val != 125) && (val != 2000)) { 361
362 if (val != 125 && val != 2000) {
312 dev_err(dev, 363 dev_err(dev,
313 "lux scale %d is invalid [125, 2000]\n", val); 364 "%s(): light: Lux scale %d is not in the set {125, 2000}\n",
365 __func__, val);
314 break; 366 break;
315 } 367 }
368
316 ret = isl29028_set_als_scale(chip, val); 369 ret = isl29028_set_als_scale(chip, val);
317 if (ret < 0) {
318 dev_err(dev,
319 "Setting lux scale fail with error %d\n", ret);
320 break;
321 }
322 chip->lux_scale = val;
323 break; 370 break;
324
325 default: 371 default:
326 dev_err(dev, "Unsupported channel type\n"); 372 dev_err(dev, "%s(): Unsupported channel type %x\n",
373 __func__, chan->type);
327 break; 374 break;
328 } 375 }
376
329 mutex_unlock(&chip->lock); 377 mutex_unlock(&chip->lock);
378
379 if (ret < 0)
380 return ret;
381
382 ret = isl29028_set_pm_runtime_busy(chip, false);
383 if (ret < 0)
384 return ret;
385
330 return ret; 386 return ret;
331} 387}
332 388
@@ -336,9 +392,15 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,
336{ 392{
337 struct isl29028_chip *chip = iio_priv(indio_dev); 393 struct isl29028_chip *chip = iio_priv(indio_dev);
338 struct device *dev = regmap_get_device(chip->regmap); 394 struct device *dev = regmap_get_device(chip->regmap);
339 int ret = -EINVAL; 395 int ret, pm_ret;
396
397 ret = isl29028_set_pm_runtime_busy(chip, true);
398 if (ret < 0)
399 return ret;
340 400
341 mutex_lock(&chip->lock); 401 mutex_lock(&chip->lock);
402
403 ret = -EINVAL;
342 switch (mask) { 404 switch (mask) {
343 case IIO_CHAN_INFO_RAW: 405 case IIO_CHAN_INFO_RAW:
344 case IIO_CHAN_INFO_PROCESSED: 406 case IIO_CHAN_INFO_PROCESSED:
@@ -350,35 +412,50 @@ static int isl29028_read_raw(struct iio_dev *indio_dev,
350 ret = isl29028_ir_get(chip, val); 412 ret = isl29028_ir_get(chip, val);
351 break; 413 break;
352 case IIO_PROXIMITY: 414 case IIO_PROXIMITY:
353 ret = isl29028_proxim_get(chip, val); 415 ret = isl29028_read_proxim(chip, val);
354 break; 416 break;
355 default: 417 default:
356 break; 418 break;
357 } 419 }
420
358 if (ret < 0) 421 if (ret < 0)
359 break; 422 break;
423
360 ret = IIO_VAL_INT; 424 ret = IIO_VAL_INT;
361 break; 425 break;
362
363 case IIO_CHAN_INFO_SAMP_FREQ: 426 case IIO_CHAN_INFO_SAMP_FREQ:
364 if (chan->type != IIO_PROXIMITY) 427 if (chan->type != IIO_PROXIMITY)
365 break; 428 break;
429
366 *val = chip->prox_sampling; 430 *val = chip->prox_sampling;
367 ret = IIO_VAL_INT; 431 ret = IIO_VAL_INT;
368 break; 432 break;
369
370 case IIO_CHAN_INFO_SCALE: 433 case IIO_CHAN_INFO_SCALE:
371 if (chan->type != IIO_LIGHT) 434 if (chan->type != IIO_LIGHT)
372 break; 435 break;
373 *val = chip->lux_scale; 436 *val = chip->lux_scale;
374 ret = IIO_VAL_INT; 437 ret = IIO_VAL_INT;
375 break; 438 break;
376
377 default: 439 default:
378 dev_err(dev, "mask value 0x%08lx not supported\n", mask); 440 dev_err(dev, "%s(): mask value 0x%08lx is not supported\n",
441 __func__, mask);
379 break; 442 break;
380 } 443 }
444
381 mutex_unlock(&chip->lock); 445 mutex_unlock(&chip->lock);
446
447 if (ret < 0)
448 return ret;
449
450 /**
451 * Preserve the ret variable if the call to
452 * isl29028_set_pm_runtime_busy() is successful so the reading
453 * (if applicable) is returned to user space.
454 */
455 pm_ret = isl29028_set_pm_runtime_busy(chip, false);
456 if (pm_ret < 0)
457 return pm_ret;
458
382 return ret; 459 return ret;
383} 460}
384 461
@@ -386,7 +463,6 @@ static IIO_CONST_ATTR(in_proximity_sampling_frequency_available,
386 "1 3 5 10 13 20 83 100"); 463 "1 3 5 10 13 20 83 100");
387static IIO_CONST_ATTR(in_illuminance_scale_available, "125 2000"); 464static IIO_CONST_ATTR(in_illuminance_scale_available, "125 2000");
388 465
389#define ISL29028_DEV_ATTR(name) (&iio_dev_attr_##name.dev_attr.attr)
390#define ISL29028_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr) 466#define ISL29028_CONST_ATTR(name) (&iio_const_attr_##name.dev_attr.attr)
391static struct attribute *isl29028_attributes[] = { 467static struct attribute *isl29028_attributes[] = {
392 ISL29028_CONST_ATTR(in_proximity_sampling_frequency_available), 468 ISL29028_CONST_ATTR(in_proximity_sampling_frequency_available),
@@ -420,45 +496,19 @@ static const struct iio_info isl29028_info = {
420 .write_raw = isl29028_write_raw, 496 .write_raw = isl29028_write_raw,
421}; 497};
422 498
423static int isl29028_chip_init(struct isl29028_chip *chip) 499static int isl29028_clear_configure_reg(struct isl29028_chip *chip)
424{ 500{
425 struct device *dev = regmap_get_device(chip->regmap); 501 struct device *dev = regmap_get_device(chip->regmap);
426 int ret; 502 int ret;
427 503
428 chip->enable_prox = false;
429 chip->prox_sampling = 20;
430 chip->lux_scale = 2000;
431 chip->als_ir_mode = ISL29028_MODE_NONE;
432
433 ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0);
434 if (ret < 0) {
435 dev_err(dev, "%s(): write to reg %d failed, err = %d\n",
436 __func__, ISL29028_REG_TEST1_MODE, ret);
437 return ret;
438 }
439 ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0);
440 if (ret < 0) {
441 dev_err(dev, "%s(): write to reg %d failed, err = %d\n",
442 __func__, ISL29028_REG_TEST2_MODE, ret);
443 return ret;
444 }
445
446 ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0); 504 ret = regmap_write(chip->regmap, ISL29028_REG_CONFIGURE, 0x0);
447 if (ret < 0) { 505 if (ret < 0)
448 dev_err(dev, "%s(): write to reg %d failed, err = %d\n", 506 dev_err(dev, "%s(): Error %d clearing the CONFIGURE register\n",
449 __func__, ISL29028_REG_CONFIGURE, ret); 507 __func__, ret);
450 return ret;
451 }
452 508
453 ret = isl29028_set_proxim_sampling(chip, chip->prox_sampling); 509 chip->als_ir_mode = ISL29028_MODE_NONE;
454 if (ret < 0) { 510 chip->enable_prox = false;
455 dev_err(dev, "setting the proximity, err = %d\n", ret);
456 return ret;
457 }
458 511
459 ret = isl29028_set_als_scale(chip, chip->lux_scale);
460 if (ret < 0)
461 dev_err(dev, "setting als scale failed, err = %d\n", ret);
462 return ret; 512 return ret;
463} 513}
464 514
@@ -492,10 +542,8 @@ static int isl29028_probe(struct i2c_client *client,
492 int ret; 542 int ret;
493 543
494 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip)); 544 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
495 if (!indio_dev) { 545 if (!indio_dev)
496 dev_err(&client->dev, "iio allocation fails\n");
497 return -ENOMEM; 546 return -ENOMEM;
498 }
499 547
500 chip = iio_priv(indio_dev); 548 chip = iio_priv(indio_dev);
501 549
@@ -505,33 +553,102 @@ static int isl29028_probe(struct i2c_client *client,
505 chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config); 553 chip->regmap = devm_regmap_init_i2c(client, &isl29028_regmap_config);
506 if (IS_ERR(chip->regmap)) { 554 if (IS_ERR(chip->regmap)) {
507 ret = PTR_ERR(chip->regmap); 555 ret = PTR_ERR(chip->regmap);
508 dev_err(&client->dev, "regmap initialization failed: %d\n", 556 dev_err(&client->dev, "%s: Error %d initializing regmap\n",
509 ret); 557 __func__, ret);
510 return ret; 558 return ret;
511 } 559 }
512 560
513 ret = isl29028_chip_init(chip); 561 chip->enable_prox = false;
562 chip->prox_sampling = 20;
563 chip->lux_scale = 2000;
564
565 ret = regmap_write(chip->regmap, ISL29028_REG_TEST1_MODE, 0x0);
514 if (ret < 0) { 566 if (ret < 0) {
515 dev_err(&client->dev, "chip initialization failed: %d\n", ret); 567 dev_err(&client->dev,
568 "%s(): Error %d writing to TEST1_MODE register\n",
569 __func__, ret);
516 return ret; 570 return ret;
517 } 571 }
518 572
573 ret = regmap_write(chip->regmap, ISL29028_REG_TEST2_MODE, 0x0);
574 if (ret < 0) {
575 dev_err(&client->dev,
576 "%s(): Error %d writing to TEST2_MODE register\n",
577 __func__, ret);
578 return ret;
579 }
580
581 ret = isl29028_clear_configure_reg(chip);
582 if (ret < 0)
583 return ret;
584
519 indio_dev->info = &isl29028_info; 585 indio_dev->info = &isl29028_info;
520 indio_dev->channels = isl29028_channels; 586 indio_dev->channels = isl29028_channels;
521 indio_dev->num_channels = ARRAY_SIZE(isl29028_channels); 587 indio_dev->num_channels = ARRAY_SIZE(isl29028_channels);
522 indio_dev->name = id->name; 588 indio_dev->name = id->name;
523 indio_dev->dev.parent = &client->dev; 589 indio_dev->dev.parent = &client->dev;
524 indio_dev->modes = INDIO_DIRECT_MODE; 590 indio_dev->modes = INDIO_DIRECT_MODE;
591
592 pm_runtime_enable(&client->dev);
593 pm_runtime_set_autosuspend_delay(&client->dev,
594 ISL29028_POWER_OFF_DELAY_MS);
595 pm_runtime_use_autosuspend(&client->dev);
596
525 ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); 597 ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev);
526 if (ret < 0) { 598 if (ret < 0) {
527 dev_err(&client->dev, 599 dev_err(&client->dev,
528 "iio registration fails with error %d\n", 600 "%s(): iio registration failed with error %d\n",
529 ret); 601 __func__, ret);
530 return ret; 602 return ret;
531 } 603 }
604
532 return 0; 605 return 0;
533} 606}
534 607
608static int isl29028_remove(struct i2c_client *client)
609{
610 struct iio_dev *indio_dev = i2c_get_clientdata(client);
611 struct isl29028_chip *chip = iio_priv(indio_dev);
612
613 iio_device_unregister(indio_dev);
614
615 pm_runtime_disable(&client->dev);
616 pm_runtime_set_suspended(&client->dev);
617 pm_runtime_put_noidle(&client->dev);
618
619 return isl29028_clear_configure_reg(chip);
620}
621
622static int __maybe_unused isl29028_suspend(struct device *dev)
623{
624 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
625 struct isl29028_chip *chip = iio_priv(indio_dev);
626 int ret;
627
628 mutex_lock(&chip->lock);
629
630 ret = isl29028_clear_configure_reg(chip);
631
632 mutex_unlock(&chip->lock);
633
634 return ret;
635}
636
637static int __maybe_unused isl29028_resume(struct device *dev)
638{
639 /**
640 * The specific component (ALS/IR or proximity) will enable itself as
641 * needed the next time that the user requests a reading. This is done
642 * above in isl29028_set_als_ir_mode() and isl29028_enable_proximity().
643 */
644 return 0;
645}
646
647static const struct dev_pm_ops isl29028_pm_ops = {
648 SET_SYSTEM_SLEEP_PM_OPS(isl29028_suspend, isl29028_resume)
649 SET_RUNTIME_PM_OPS(isl29028_suspend, isl29028_resume, NULL)
650};
651
535static const struct i2c_device_id isl29028_id[] = { 652static const struct i2c_device_id isl29028_id[] = {
536 {"isl29028", 0}, 653 {"isl29028", 0},
537 {} 654 {}
@@ -548,9 +665,11 @@ MODULE_DEVICE_TABLE(of, isl29028_of_match);
548static struct i2c_driver isl29028_driver = { 665static struct i2c_driver isl29028_driver = {
549 .driver = { 666 .driver = {
550 .name = "isl29028", 667 .name = "isl29028",
668 .pm = &isl29028_pm_ops,
551 .of_match_table = isl29028_of_match, 669 .of_match_table = isl29028_of_match,
552 }, 670 },
553 .probe = isl29028_probe, 671 .probe = isl29028_probe,
672 .remove = isl29028_remove,
554 .id_table = isl29028_id, 673 .id_table = isl29028_id,
555}; 674};
556 675
diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c
index 4b5f05fdadcd..671dc9971610 100644
--- a/drivers/staging/iio/meter/ade7753.c
+++ b/drivers/staging/iio/meter/ade7753.c
@@ -377,7 +377,7 @@ static int ade7753_initial_setup(struct iio_dev *indio_dev)
377 } 377 }
378 378
379 ade7753_reset(dev); 379 ade7753_reset(dev);
380 msleep(ADE7753_STARTUP_DELAY); 380 usleep_range(ADE7753_STARTUP_DELAY, ADE7753_STARTUP_DELAY + 100);
381 381
382err_ret: 382err_ret:
383 return ret; 383 return ret;
diff --git a/drivers/staging/iio/meter/ade7753.h b/drivers/staging/iio/meter/ade7753.h
index a9d93cc1c414..bfe749156bce 100644
--- a/drivers/staging/iio/meter/ade7753.h
+++ b/drivers/staging/iio/meter/ade7753.h
@@ -49,7 +49,7 @@
49 49
50#define ADE7753_MAX_TX 4 50#define ADE7753_MAX_TX 4
51#define ADE7753_MAX_RX 4 51#define ADE7753_MAX_RX 4
52#define ADE7753_STARTUP_DELAY 1 52#define ADE7753_STARTUP_DELAY 1000
53 53
54#define ADE7753_SPI_SLOW (u32)(300 * 1000) 54#define ADE7753_SPI_SLOW (u32)(300 * 1000)
55#define ADE7753_SPI_BURST (u32)(1000 * 1000) 55#define ADE7753_SPI_BURST (u32)(1000 * 1000)
diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c
index 17309591ca57..024463a11c47 100644
--- a/drivers/staging/iio/meter/ade7754.c
+++ b/drivers/staging/iio/meter/ade7754.c
@@ -389,7 +389,7 @@ static int ade7754_initial_setup(struct iio_dev *indio_dev)
389 } 389 }
390 390
391 ade7754_reset(dev); 391 ade7754_reset(dev);
392 msleep(ADE7754_STARTUP_DELAY); 392 usleep_range(ADE7754_STARTUP_DELAY, ADE7754_STARTUP_DELAY + 100);
393 393
394err_ret: 394err_ret:
395 return ret; 395 return ret;
diff --git a/drivers/staging/iio/meter/ade7754.h b/drivers/staging/iio/meter/ade7754.h
index e42ffc387a14..28f71c2cde0c 100644
--- a/drivers/staging/iio/meter/ade7754.h
+++ b/drivers/staging/iio/meter/ade7754.h
@@ -67,7 +67,7 @@
67 67
68#define ADE7754_MAX_TX 4 68#define ADE7754_MAX_TX 4
69#define ADE7754_MAX_RX 4 69#define ADE7754_MAX_RX 4
70#define ADE7754_STARTUP_DELAY 1 70#define ADE7754_STARTUP_DELAY 1000
71 71
72#define ADE7754_SPI_SLOW (u32)(300 * 1000) 72#define ADE7754_SPI_SLOW (u32)(300 * 1000)
73#define ADE7754_SPI_BURST (u32)(1000 * 1000) 73#define ADE7754_SPI_BURST (u32)(1000 * 1000)
diff --git a/drivers/staging/iio/meter/ade7758.h b/drivers/staging/iio/meter/ade7758.h
index 1d04ec9524c8..6ae78d8aa24f 100644
--- a/drivers/staging/iio/meter/ade7758.h
+++ b/drivers/staging/iio/meter/ade7758.h
@@ -89,7 +89,7 @@
89 89
90#define ADE7758_MAX_TX 8 90#define ADE7758_MAX_TX 8
91#define ADE7758_MAX_RX 4 91#define ADE7758_MAX_RX 4
92#define ADE7758_STARTUP_DELAY 1 92#define ADE7758_STARTUP_DELAY 1000
93 93
94#define AD7758_NUM_WAVSEL 5 94#define AD7758_NUM_WAVSEL 5
95#define AD7758_NUM_PHSEL 3 95#define AD7758_NUM_PHSEL 3
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index 3af8f77b8e41..99c89e606c8d 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -459,7 +459,7 @@ static int ade7758_initial_setup(struct iio_dev *indio_dev)
459 } 459 }
460 460
461 ade7758_reset(dev); 461 ade7758_reset(dev);
462 msleep(ADE7758_STARTUP_DELAY); 462 usleep_range(ADE7758_STARTUP_DELAY, ADE7758_STARTUP_DELAY + 100);
463 463
464err_ret: 464err_ret:
465 return ret; 465 return ret;
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index 57c213dfadcc..6d7444d6e880 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -13,6 +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 <linux/iio/buffer.h>
16#include <linux/iio/kfifo_buf.h> 17#include <linux/iio/kfifo_buf.h>
17#include <linux/iio/trigger_consumer.h> 18#include <linux/iio/trigger_consumer.h>
18#include "ade7758.h" 19#include "ade7758.h"
diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c
index 80144d40d9ca..944ee3401029 100644
--- a/drivers/staging/iio/meter/ade7759.c
+++ b/drivers/staging/iio/meter/ade7759.c
@@ -338,7 +338,7 @@ static int ade7759_initial_setup(struct iio_dev *indio_dev)
338 } 338 }
339 339
340 ade7759_reset(dev); 340 ade7759_reset(dev);
341 msleep(ADE7759_STARTUP_DELAY); 341 usleep_range(ADE7759_STARTUP_DELAY, ADE7759_STARTUP_DELAY + 100);
342 342
343err_ret: 343err_ret:
344 return ret; 344 return ret;
diff --git a/drivers/staging/iio/meter/ade7759.h b/drivers/staging/iio/meter/ade7759.h
index f9ff1f8e7372..f0716d2fdf8e 100644
--- a/drivers/staging/iio/meter/ade7759.h
+++ b/drivers/staging/iio/meter/ade7759.h
@@ -30,7 +30,7 @@
30 30
31#define ADE7759_MAX_TX 6 31#define ADE7759_MAX_TX 6
32#define ADE7759_MAX_RX 6 32#define ADE7759_MAX_RX 6
33#define ADE7759_STARTUP_DELAY 1 33#define ADE7759_STARTUP_DELAY 1000
34 34
35#define ADE7759_SPI_SLOW (u32)(300 * 1000) 35#define ADE7759_SPI_SLOW (u32)(300 * 1000)
36#define ADE7759_SPI_BURST (u32)(1000 * 1000) 36#define ADE7759_SPI_BURST (u32)(1000 * 1000)
diff --git a/drivers/staging/iio/meter/ade7854.c b/drivers/staging/iio/meter/ade7854.c
index 24edbc39ab4e..e8007f0c5186 100644
--- a/drivers/staging/iio/meter/ade7854.c
+++ b/drivers/staging/iio/meter/ade7854.c
@@ -444,7 +444,7 @@ static int ade7854_initial_setup(struct iio_dev *indio_dev)
444 } 444 }
445 445
446 ade7854_reset(dev); 446 ade7854_reset(dev);
447 msleep(ADE7854_STARTUP_DELAY); 447 usleep_range(ADE7854_STARTUP_DELAY, ADE7854_STARTUP_DELAY + 100);
448 448
449err_ret: 449err_ret:
450 return ret; 450 return ret;
diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h
index 52f4195cf6f4..dbd97def9cd8 100644
--- a/drivers/staging/iio/meter/ade7854.h
+++ b/drivers/staging/iio/meter/ade7854.h
@@ -136,7 +136,7 @@
136 136
137#define ADE7854_MAX_TX 7 137#define ADE7854_MAX_TX 7
138#define ADE7854_MAX_RX 7 138#define ADE7854_MAX_RX 7
139#define ADE7854_STARTUP_DELAY 1 139#define ADE7854_STARTUP_DELAY 1000
140 140
141#define ADE7854_SPI_SLOW (u32)(300 * 1000) 141#define ADE7854_SPI_SLOW (u32)(300 * 1000)
142#define ADE7854_SPI_BURST (u32)(1000 * 1000) 142#define ADE7854_SPI_BURST (u32)(1000 * 1000)
diff --git a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
index 38dca69a06eb..4e0b4eedb53d 100644
--- a/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
+++ b/drivers/staging/iio/trigger/iio-trig-bfin-timer.c
@@ -133,7 +133,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
133 return sprintf(buf, "%lu\n", val); 133 return sprintf(buf, "%lu\n", val);
134} 134}
135 135
136static DEVICE_ATTR(frequency, S_IRUGO | S_IWUSR, iio_bfin_tmr_frequency_show, 136static DEVICE_ATTR(frequency, 0644, iio_bfin_tmr_frequency_show,
137 iio_bfin_tmr_frequency_store); 137 iio_bfin_tmr_frequency_store);
138 138
139static struct attribute *iio_bfin_tmr_trigger_attrs[] = { 139static struct attribute *iio_bfin_tmr_trigger_attrs[] = {
@@ -260,7 +260,7 @@ out_free_irq:
260out1: 260out1:
261 iio_trigger_unregister(st->trig); 261 iio_trigger_unregister(st->trig);
262out: 262out:
263 iio_trigger_put(st->trig); 263 iio_trigger_free(st->trig);
264 return ret; 264 return ret;
265} 265}
266 266
@@ -273,7 +273,7 @@ static int iio_bfin_tmr_trigger_remove(struct platform_device *pdev)
273 peripheral_free(st->t->pin); 273 peripheral_free(st->t->pin);
274 free_irq(st->irq, st); 274 free_irq(st->irq, st);
275 iio_trigger_unregister(st->trig); 275 iio_trigger_unregister(st->trig);
276 iio_trigger_put(st->trig); 276 iio_trigger_free(st->trig);
277 277
278 return 0; 278 return 0;
279} 279}
diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
index a604c83c957e..6f9f746a3a61 100644
--- a/drivers/staging/ks7010/ks7010_sdio.c
+++ b/drivers/staging/ks7010/ks7010_sdio.c
@@ -884,7 +884,6 @@ static void ks7010_card_init(struct ks_wlan_private *priv)
884 if (priv->mac_address_valid && priv->version_size) 884 if (priv->mac_address_valid && priv->version_size)
885 priv->dev_state = DEVICE_STATE_PREINIT; 885 priv->dev_state = DEVICE_STATE_PREINIT;
886 886
887
888 hostif_sme_enqueue(priv, SME_GET_EEPROM_CKSUM); 887 hostif_sme_enqueue(priv, SME_GET_EEPROM_CKSUM);
889 888
890 /* load initial wireless parameter */ 889 /* load initial wireless parameter */
diff --git a/drivers/staging/ks7010/ks7010_sdio.h b/drivers/staging/ks7010/ks7010_sdio.h
index 0f5fd848e23d..d7e1523a222f 100644
--- a/drivers/staging/ks7010/ks7010_sdio.h
+++ b/drivers/staging/ks7010/ks7010_sdio.h
@@ -81,11 +81,11 @@
81 81
82/* AHB Data Window 0x010000-0x01FFFF */ 82/* AHB Data Window 0x010000-0x01FFFF */
83#define DATA_WINDOW 0x010000 83#define DATA_WINDOW 0x010000
84#define WINDOW_SIZE 64*1024 84#define WINDOW_SIZE (64 * 1024)
85 85
86#define KS7010_IRAM_ADDRESS 0x06000000 86#define KS7010_IRAM_ADDRESS 0x06000000
87 87
88/* 88/*
89 * struct define 89 * struct define
90 */ 90 */
91struct hw_info_t { 91struct hw_info_t {
@@ -142,6 +142,7 @@ struct rx_device {
142 unsigned int qtail; /* rx buffer queue last pointer */ 142 unsigned int qtail; /* rx buffer queue last pointer */
143 spinlock_t rx_dev_lock; 143 spinlock_t rx_dev_lock;
144}; 144};
145
145#define ROM_FILE "ks7010sd.rom" 146#define ROM_FILE "ks7010sd.rom"
146 147
147#endif /* _KS7010_SDIO_H */ 148#endif /* _KS7010_SDIO_H */
diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
index c7652c35be19..da7c42ef05f5 100644
--- a/drivers/staging/ks7010/ks_hostif.c
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -727,7 +727,6 @@ void hostif_power_mngmt_confirm(struct ks_wlan_private *priv)
727 } else { 727 } else {
728 priv->dev_state = DEVICE_STATE_READY; 728 priv->dev_state = DEVICE_STATE_READY;
729 } 729 }
730
731} 730}
732 731
733static 732static
@@ -853,7 +852,6 @@ void hostif_scan_indication(struct ks_wlan_private *priv)
853 DPRINTK(4, " count over :: scan_ind_count=%d\n", 852 DPRINTK(4, " count over :: scan_ind_count=%d\n",
854 priv->scan_ind_count); 853 priv->scan_ind_count);
855 } 854 }
856
857} 855}
858 856
859static 857static
@@ -900,7 +898,6 @@ void hostif_ps_adhoc_set_confirm(struct ks_wlan_private *priv)
900 DPRINTK(3, "\n"); 898 DPRINTK(3, "\n");
901 priv->infra_status = 0; /* infrastructure mode cancel */ 899 priv->infra_status = 0; /* infrastructure mode cancel */
902 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM); 900 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
903
904} 901}
905 902
906static 903static
@@ -1102,7 +1099,7 @@ void hostif_event_check(struct ks_wlan_private *priv)
1102 priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE; 1099 priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
1103} 1100}
1104 1101
1105#define CHECK_ALINE(size) (size%4 ? (size+(4-(size%4))):size) 1102#define CHECK_ALINE(size) (size % 4 ? (size + (4 - (size % 4))) : size)
1106 1103
1107int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet) 1104int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
1108{ 1105{
@@ -1916,7 +1913,6 @@ void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
1916 sizeof(val), MIB_VALUE_TYPE_BOOL, &val); 1913 sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
1917 break; 1914 break;
1918 } 1915 }
1919
1920} 1916}
1921 1917
1922struct wpa_suite_t { 1918struct wpa_suite_t {
@@ -2103,7 +2099,6 @@ void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)
2103 hostif_mib_set_request(priv, LOCAL_RSN_MODE, sizeof(rsn_mode), 2099 hostif_mib_set_request(priv, LOCAL_RSN_MODE, sizeof(rsn_mode),
2104 MIB_VALUE_TYPE_OSTRING, &rsn_mode); 2100 MIB_VALUE_TYPE_OSTRING, &rsn_mode);
2105 break; 2101 break;
2106
2107 } 2102 }
2108} 2103}
2109 2104
@@ -2211,13 +2206,11 @@ void hostif_sme_mode_setup(struct ks_wlan_private *priv)
2211 default: 2206 default:
2212 break; 2207 break;
2213 } 2208 }
2214
2215} 2209}
2216 2210
2217static 2211static
2218void hostif_sme_multicast_set(struct ks_wlan_private *priv) 2212void hostif_sme_multicast_set(struct ks_wlan_private *priv)
2219{ 2213{
2220
2221 struct net_device *dev = priv->net_dev; 2214 struct net_device *dev = priv->net_dev;
2222 int mc_count; 2215 int mc_count;
2223 struct netdev_hw_addr *ha; 2216 struct netdev_hw_addr *ha;
@@ -2267,7 +2260,6 @@ void hostif_sme_multicast_set(struct ks_wlan_private *priv)
2267 } 2260 }
2268 2261
2269 spin_unlock(&priv->multicast_spin); 2262 spin_unlock(&priv->multicast_spin);
2270
2271} 2263}
2272 2264
2273static 2265static
@@ -2311,7 +2303,6 @@ void hostif_sme_powermgt_set(struct ks_wlan_private *priv)
2311 break; 2303 break;
2312 } 2304 }
2313 hostif_power_mngmt_request(priv, mode, wake_up, receiveDTIMs); 2305 hostif_power_mngmt_request(priv, mode, wake_up, receiveDTIMs);
2314
2315} 2306}
2316 2307
2317static 2308static
@@ -2328,7 +2319,6 @@ void hostif_sme_sleep_set(struct ks_wlan_private *priv)
2328 default: 2319 default:
2329 break; 2320 break;
2330 } 2321 }
2331
2332} 2322}
2333 2323
2334static 2324static
@@ -2639,7 +2629,6 @@ void hostif_sme_enqueue(struct ks_wlan_private *priv, unsigned short event)
2639 } 2629 }
2640 2630
2641 tasklet_schedule(&priv->sme_task); 2631 tasklet_schedule(&priv->sme_task);
2642
2643} 2632}
2644 2633
2645int hostif_init(struct ks_wlan_private *priv) 2634int hostif_init(struct ks_wlan_private *priv)
diff --git a/drivers/staging/ks7010/ks_hostif.h b/drivers/staging/ks7010/ks_hostif.h
index 743f31ead56e..30c49b699d62 100644
--- a/drivers/staging/ks7010/ks_hostif.h
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -553,34 +553,34 @@ struct hostif_mic_failure_confirm_t {
553#define TX_RATE_FIXED 5 553#define TX_RATE_FIXED 5
554 554
555/* 11b rate */ 555/* 11b rate */
556#define TX_RATE_1M (uint8_t)(10/5) /* 11b 11g basic rate */ 556#define TX_RATE_1M (uint8_t)(10 / 5) /* 11b 11g basic rate */
557#define TX_RATE_2M (uint8_t)(20/5) /* 11b 11g basic rate */ 557#define TX_RATE_2M (uint8_t)(20 / 5) /* 11b 11g basic rate */
558#define TX_RATE_5M (uint8_t)(55/5) /* 11g basic rate */ 558#define TX_RATE_5M (uint8_t)(55 / 5) /* 11g basic rate */
559#define TX_RATE_11M (uint8_t)(110/5) /* 11g basic rate */ 559#define TX_RATE_11M (uint8_t)(110 / 5) /* 11g basic rate */
560 560
561/* 11g rate */ 561/* 11g rate */
562#define TX_RATE_6M (uint8_t)(60/5) /* 11g basic rate */ 562#define TX_RATE_6M (uint8_t)(60 / 5) /* 11g basic rate */
563#define TX_RATE_12M (uint8_t)(120/5) /* 11g basic rate */ 563#define TX_RATE_12M (uint8_t)(120 / 5) /* 11g basic rate */
564#define TX_RATE_24M (uint8_t)(240/5) /* 11g basic rate */ 564#define TX_RATE_24M (uint8_t)(240 / 5) /* 11g basic rate */
565#define TX_RATE_9M (uint8_t)(90/5) 565#define TX_RATE_9M (uint8_t)(90 / 5)
566#define TX_RATE_18M (uint8_t)(180/5) 566#define TX_RATE_18M (uint8_t)(180 / 5)
567#define TX_RATE_36M (uint8_t)(360/5) 567#define TX_RATE_36M (uint8_t)(360 / 5)
568#define TX_RATE_48M (uint8_t)(480/5) 568#define TX_RATE_48M (uint8_t)(480 / 5)
569#define TX_RATE_54M (uint8_t)(540/5) 569#define TX_RATE_54M (uint8_t)(540 / 5)
570 570
571#define IS_11B_RATE(A) (((A&RATE_MASK)==TX_RATE_1M)||((A&RATE_MASK)==TX_RATE_2M)||\ 571#define IS_11B_RATE(A) (((A & RATE_MASK) == TX_RATE_1M ) || ((A & RATE_MASK) == TX_RATE_2M) || \
572 ((A&RATE_MASK)==TX_RATE_5M)||((A&RATE_MASK)==TX_RATE_11M)) 572 ((A & RATE_MASK) == TX_RATE_5M) || ((A & RATE_MASK) == TX_RATE_11M))
573 573
574#define IS_OFDM_RATE(A) (((A&RATE_MASK)==TX_RATE_6M)||((A&RATE_MASK)==TX_RATE_12M)||\ 574#define IS_OFDM_RATE(A) (((A & RATE_MASK) == TX_RATE_6M) || ((A & RATE_MASK) == TX_RATE_12M) || \
575 ((A&RATE_MASK)==TX_RATE_24M)||((A&RATE_MASK)==TX_RATE_9M)||\ 575 ((A & RATE_MASK) == TX_RATE_24M) || ((A & RATE_MASK) == TX_RATE_9M) || \
576 ((A&RATE_MASK)==TX_RATE_18M)||((A&RATE_MASK)==TX_RATE_36M)||\ 576 ((A & RATE_MASK) == TX_RATE_18M) || ((A & RATE_MASK) == TX_RATE_36M) || \
577 ((A&RATE_MASK)==TX_RATE_48M)||((A&RATE_MASK)==TX_RATE_54M)) 577 ((A & RATE_MASK) == TX_RATE_48M) || ((A & RATE_MASK) == TX_RATE_54M))
578 578
579#define IS_11BG_RATE(A) (IS_11B_RATE(A)||IS_OFDM_RATE(A)) 579#define IS_11BG_RATE(A) (IS_11B_RATE(A) || IS_OFDM_RATE(A))
580 580
581#define IS_OFDM_EXT_RATE(A) (((A&RATE_MASK)==TX_RATE_9M)||((A&RATE_MASK)==TX_RATE_18M)||\ 581#define IS_OFDM_EXT_RATE(A) (((A & RATE_MASK) == TX_RATE_9M) || ((A & RATE_MASK) == TX_RATE_18M) || \
582 ((A&RATE_MASK)==TX_RATE_36M)||((A&RATE_MASK)==TX_RATE_48M)||\ 582 ((A & RATE_MASK) == TX_RATE_36M) || ((A & RATE_MASK) == TX_RATE_48M) || \
583 ((A&RATE_MASK)==TX_RATE_54M)) 583 ((A & RATE_MASK) == TX_RATE_54M))
584 584
585enum { 585enum {
586 CONNECT_STATUS = 0, 586 CONNECT_STATUS = 0,
@@ -602,16 +602,16 @@ enum {
602 602
603/* macro function */ 603/* macro function */
604#define HIF_EVENT_MASK 0xE800 604#define HIF_EVENT_MASK 0xE800
605#define IS_HIF_IND(_EVENT) ((_EVENT&HIF_EVENT_MASK)==0xE800 && \ 605#define IS_HIF_IND(_EVENT) ((_EVENT & HIF_EVENT_MASK) == 0xE800 && \
606 ((_EVENT&~HIF_EVENT_MASK)==0x0001 || \ 606 ((_EVENT & ~HIF_EVENT_MASK) == 0x0001 || \
607 (_EVENT&~HIF_EVENT_MASK)==0x0006 || \ 607 (_EVENT & ~HIF_EVENT_MASK) == 0x0006 || \
608 (_EVENT&~HIF_EVENT_MASK)==0x000C || \ 608 (_EVENT & ~HIF_EVENT_MASK) == 0x000C || \
609 (_EVENT&~HIF_EVENT_MASK)==0x0011 || \ 609 (_EVENT & ~HIF_EVENT_MASK) == 0x0011 || \
610 (_EVENT&~HIF_EVENT_MASK)==0x0012)) 610 (_EVENT & ~HIF_EVENT_MASK) == 0x0012))
611 611
612#define IS_HIF_CONF(_EVENT) ((_EVENT&HIF_EVENT_MASK)==0xE800 && \ 612#define IS_HIF_CONF(_EVENT) ((_EVENT & HIF_EVENT_MASK) == 0xE800 && \
613 (_EVENT&~HIF_EVENT_MASK)>0x0000 && \ 613 (_EVENT & ~HIF_EVENT_MASK) > 0x0000 && \
614 (_EVENT&~HIF_EVENT_MASK)<0x0012 && \ 614 (_EVENT & ~HIF_EVENT_MASK) < 0x0012 && \
615 !IS_HIF_IND(_EVENT) ) 615 !IS_HIF_IND(_EVENT) )
616 616
617#ifdef __KERNEL__ 617#ifdef __KERNEL__
diff --git a/drivers/staging/ks7010/ks_wlan.h b/drivers/staging/ks7010/ks_wlan.h
index 279e9b06fc4b..9ab80e1f123e 100644
--- a/drivers/staging/ks7010/ks_wlan.h
+++ b/drivers/staging/ks7010/ks_wlan.h
@@ -36,7 +36,7 @@
36 36
37#ifdef KS_WLAN_DEBUG 37#ifdef KS_WLAN_DEBUG
38#define DPRINTK(n, fmt, args...) \ 38#define DPRINTK(n, fmt, args...) \
39 if (KS_WLAN_DEBUG>(n)) printk(KERN_NOTICE "%s: "fmt, __FUNCTION__, ## args) 39 if (KS_WLAN_DEBUG > (n)) printk(KERN_NOTICE "%s: "fmt, __FUNCTION__, ## args)
40#else 40#else
41#define DPRINTK(n, fmt, args...) 41#define DPRINTK(n, fmt, args...)
42#endif 42#endif
@@ -94,7 +94,7 @@ enum {
94#define SME_WEP_VAL2 (1<<6) 94#define SME_WEP_VAL2 (1<<6)
95#define SME_WEP_VAL3 (1<<7) 95#define SME_WEP_VAL3 (1<<7)
96#define SME_WEP_VAL4 (1<<8) 96#define SME_WEP_VAL4 (1<<8)
97#define SME_WEP_VAL_MASK (SME_WEP_VAL1|SME_WEP_VAL2|SME_WEP_VAL3|SME_WEP_VAL4) 97#define SME_WEP_VAL_MASK (SME_WEP_VAL1 | SME_WEP_VAL2 | SME_WEP_VAL3 | SME_WEP_VAL4)
98#define SME_RSN (1<<9) 98#define SME_RSN (1<<9)
99#define SME_RSN_MULTICAST (1<<10) 99#define SME_RSN_MULTICAST (1<<10)
100#define SME_RSN_UNICAST (1<<11) 100#define SME_RSN_UNICAST (1<<11)
@@ -363,6 +363,7 @@ struct wpa_key_t {
363 u8 tx_mic_key[MIC_KEY_SIZE]; 363 u8 tx_mic_key[MIC_KEY_SIZE];
364 u8 rx_mic_key[MIC_KEY_SIZE]; 364 u8 rx_mic_key[MIC_KEY_SIZE];
365}; 365};
366
366#define WPA_KEY_INDEX_MAX 4 367#define WPA_KEY_INDEX_MAX 4
367#define WPA_RX_SEQ_LEN 6 368#define WPA_RX_SEQ_LEN 6
368 369
@@ -408,7 +409,6 @@ struct wps_status_t {
408#endif /* WPS */ 409#endif /* WPS */
409 410
410struct ks_wlan_private { 411struct ks_wlan_private {
411
412 struct hw_info_t ks_wlan_hw; /* hardware information */ 412 struct hw_info_t ks_wlan_hw; /* hardware information */
413 413
414 struct net_device *net_dev; 414 struct net_device *net_dev;
diff --git a/drivers/staging/ks7010/ks_wlan_ioctl.h b/drivers/staging/ks7010/ks_wlan_ioctl.h
index 84554b6bb239..8e62b10effd6 100644
--- a/drivers/staging/ks7010/ks_wlan_ioctl.h
+++ b/drivers/staging/ks7010/ks_wlan_ioctl.h
@@ -15,43 +15,43 @@
15#include <linux/wireless.h> 15#include <linux/wireless.h>
16/* The low order bit identify a SET (0) or a GET (1) ioctl. */ 16/* The low order bit identify a SET (0) or a GET (1) ioctl. */
17 17
18/* SIOCIWFIRSTPRIV+0 */ 18/* SIOCIWFIRSTPRIV + 0 */
19/* former KS_WLAN_GET_DRIVER_VERSION SIOCIWFIRSTPRIV+1 */ 19/* former KS_WLAN_GET_DRIVER_VERSION SIOCIWFIRSTPRIV + 1 */
20/* SIOCIWFIRSTPRIV+2 */ 20/* SIOCIWFIRSTPRIV + 2 */
21#define KS_WLAN_GET_FIRM_VERSION SIOCIWFIRSTPRIV+3 21#define KS_WLAN_GET_FIRM_VERSION SIOCIWFIRSTPRIV + 3
22#ifdef WPS 22#ifdef WPS
23#define KS_WLAN_SET_WPS_ENABLE SIOCIWFIRSTPRIV+4 23#define KS_WLAN_SET_WPS_ENABLE SIOCIWFIRSTPRIV + 4
24#define KS_WLAN_GET_WPS_ENABLE SIOCIWFIRSTPRIV+5 24#define KS_WLAN_GET_WPS_ENABLE SIOCIWFIRSTPRIV + 5
25#define KS_WLAN_SET_WPS_PROBE_REQ SIOCIWFIRSTPRIV+6 25#define KS_WLAN_SET_WPS_PROBE_REQ SIOCIWFIRSTPRIV + 6
26#endif 26#endif
27#define KS_WLAN_GET_EEPROM_CKSUM SIOCIWFIRSTPRIV+7 27#define KS_WLAN_GET_EEPROM_CKSUM SIOCIWFIRSTPRIV + 7
28#define KS_WLAN_SET_PREAMBLE SIOCIWFIRSTPRIV+8 28#define KS_WLAN_SET_PREAMBLE SIOCIWFIRSTPRIV + 8
29#define KS_WLAN_GET_PREAMBLE SIOCIWFIRSTPRIV+9 29#define KS_WLAN_GET_PREAMBLE SIOCIWFIRSTPRIV + 9
30#define KS_WLAN_SET_POWER_SAVE SIOCIWFIRSTPRIV+10 30#define KS_WLAN_SET_POWER_SAVE SIOCIWFIRSTPRIV + 10
31#define KS_WLAN_GET_POWER_SAVE SIOCIWFIRSTPRIV+11 31#define KS_WLAN_GET_POWER_SAVE SIOCIWFIRSTPRIV + 11
32#define KS_WLAN_SET_SCAN_TYPE SIOCIWFIRSTPRIV+12 32#define KS_WLAN_SET_SCAN_TYPE SIOCIWFIRSTPRIV + 12
33#define KS_WLAN_GET_SCAN_TYPE SIOCIWFIRSTPRIV+13 33#define KS_WLAN_GET_SCAN_TYPE SIOCIWFIRSTPRIV + 13
34#define KS_WLAN_SET_RX_GAIN SIOCIWFIRSTPRIV+14 34#define KS_WLAN_SET_RX_GAIN SIOCIWFIRSTPRIV + 14
35#define KS_WLAN_GET_RX_GAIN SIOCIWFIRSTPRIV+15 35#define KS_WLAN_GET_RX_GAIN SIOCIWFIRSTPRIV + 15
36#define KS_WLAN_HOSTT SIOCIWFIRSTPRIV+16 /* unused */ 36#define KS_WLAN_HOSTT SIOCIWFIRSTPRIV + 16 /* unused */
37//#define KS_WLAN_SET_REGION SIOCIWFIRSTPRIV+17 37//#define KS_WLAN_SET_REGION SIOCIWFIRSTPRIV + 17
38#define KS_WLAN_SET_BEACON_LOST SIOCIWFIRSTPRIV+18 38#define KS_WLAN_SET_BEACON_LOST SIOCIWFIRSTPRIV + 18
39#define KS_WLAN_GET_BEACON_LOST SIOCIWFIRSTPRIV+19 39#define KS_WLAN_GET_BEACON_LOST SIOCIWFIRSTPRIV + 19
40 40
41#define KS_WLAN_SET_TX_GAIN SIOCIWFIRSTPRIV+20 41#define KS_WLAN_SET_TX_GAIN SIOCIWFIRSTPRIV + 20
42#define KS_WLAN_GET_TX_GAIN SIOCIWFIRSTPRIV+21 42#define KS_WLAN_GET_TX_GAIN SIOCIWFIRSTPRIV + 21
43 43
44/* for KS7010 */ 44/* for KS7010 */
45#define KS_WLAN_SET_PHY_TYPE SIOCIWFIRSTPRIV+22 45#define KS_WLAN_SET_PHY_TYPE SIOCIWFIRSTPRIV + 22
46#define KS_WLAN_GET_PHY_TYPE SIOCIWFIRSTPRIV+23 46#define KS_WLAN_GET_PHY_TYPE SIOCIWFIRSTPRIV + 23
47#define KS_WLAN_SET_CTS_MODE SIOCIWFIRSTPRIV+24 47#define KS_WLAN_SET_CTS_MODE SIOCIWFIRSTPRIV + 24
48#define KS_WLAN_GET_CTS_MODE SIOCIWFIRSTPRIV+25 48#define KS_WLAN_GET_CTS_MODE SIOCIWFIRSTPRIV + 25
49/* SIOCIWFIRSTPRIV+26 */ 49/* SIOCIWFIRSTPRIV + 26 */
50/* SIOCIWFIRSTPRIV+27 */ 50/* SIOCIWFIRSTPRIV + 27 */
51#define KS_WLAN_SET_SLEEP_MODE SIOCIWFIRSTPRIV+28 /* sleep mode */ 51#define KS_WLAN_SET_SLEEP_MODE SIOCIWFIRSTPRIV + 28 /* sleep mode */
52#define KS_WLAN_GET_SLEEP_MODE SIOCIWFIRSTPRIV+29 /* sleep mode */ 52#define KS_WLAN_GET_SLEEP_MODE SIOCIWFIRSTPRIV + 29 /* sleep mode */
53/* SIOCIWFIRSTPRIV+30 */ 53/* SIOCIWFIRSTPRIV + 30 */
54/* SIOCIWFIRSTPRIV+31 */ 54/* SIOCIWFIRSTPRIV + 31 */
55 55
56#ifdef __KERNEL__ 56#ifdef __KERNEL__
57 57
diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
index e5d04adaeb1a..121e1530fdba 100644
--- a/drivers/staging/ks7010/ks_wlan_net.c
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -285,7 +285,6 @@ static int ks_wlan_set_essid(struct net_device *dev,
285 if (priv->sleep_mode == SLP_SLEEP) 285 if (priv->sleep_mode == SLP_SLEEP)
286 return -EPERM; 286 return -EPERM;
287 287
288
289 /* for SLEEP MODE */ 288 /* for SLEEP MODE */
290 /* Check if we asked for `any' */ 289 /* Check if we asked for `any' */
291 if (dwrq->flags == 0) { 290 if (dwrq->flags == 0) {
@@ -342,7 +341,6 @@ static int ks_wlan_get_essid(struct net_device *dev,
342 if (priv->sleep_mode == SLP_SLEEP) 341 if (priv->sleep_mode == SLP_SLEEP)
343 return -EPERM; 342 return -EPERM;
344 343
345
346 /* for SLEEP MODE */ 344 /* for SLEEP MODE */
347 /* Note : if dwrq->flags != 0, we should 345 /* Note : if dwrq->flags != 0, we should
348 * get the relevant SSID from the SSID list... */ 346 * get the relevant SSID from the SSID list... */
@@ -2095,7 +2093,6 @@ static int ks_wlan_set_pmksa(struct net_device *dev,
2095 2093
2096static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev) 2094static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2097{ 2095{
2098
2099 struct ks_wlan_private *priv = 2096 struct ks_wlan_private *priv =
2100 (struct ks_wlan_private *)netdev_priv(dev); 2097 (struct ks_wlan_private *)netdev_priv(dev);
2101 struct iw_statistics *wstats = &priv->wstats; 2098 struct iw_statistics *wstats = &priv->wstats;
@@ -2264,7 +2261,6 @@ static int ks_wlan_set_preamble(struct net_device *dev,
2264 2261
2265 priv->need_commit |= SME_MODE_SET; 2262 priv->need_commit |= SME_MODE_SET;
2266 return -EINPROGRESS; /* Call commit handler */ 2263 return -EINPROGRESS; /* Call commit handler */
2267
2268} 2264}
2269 2265
2270/*------------------------------------------------------------------*/ 2266/*------------------------------------------------------------------*/
@@ -2455,7 +2451,7 @@ static int ks_wlan_data_read(struct net_device *dev,
2455#if 0 2451#if 0
2456/*------------------------------------------------------------------*/ 2452/*------------------------------------------------------------------*/
2457/* Private handler : get wep string */ 2453/* Private handler : get wep string */
2458#define WEP_ASCII_BUFF_SIZE (17+64*4+1) 2454#define WEP_ASCII_BUFF_SIZE (17 + 64 * 4 + 1)
2459static int ks_wlan_get_wep_ascii(struct net_device *dev, 2455static int ks_wlan_get_wep_ascii(struct net_device *dev,
2460 struct iw_request_info *info, 2456 struct iw_request_info *info,
2461 struct iw_point *dwrq, char *extra) 2457 struct iw_point *dwrq, char *extra)
@@ -2933,7 +2929,6 @@ static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2933 2929
2934static void print_hif_event(struct net_device *dev, int event) 2930static void print_hif_event(struct net_device *dev, int event)
2935{ 2931{
2936
2937 switch (event) { 2932 switch (event) {
2938 case HIF_DATA_REQ: 2933 case HIF_DATA_REQ:
2939 netdev_info(dev, "HIF_DATA_REQ\n"); 2934 netdev_info(dev, "HIF_DATA_REQ\n");
@@ -3353,7 +3348,6 @@ void send_packet_complete(void *arg1, void *arg2)
3353 dev_kfree_skb(packet); 3348 dev_kfree_skb(packet);
3354 packet = NULL; 3349 packet = NULL;
3355 } 3350 }
3356
3357} 3351}
3358 3352
3359/* Set or clear the multicast filter for this adaptor. 3353/* Set or clear the multicast filter for this adaptor.
@@ -3388,7 +3382,6 @@ int ks_wlan_open(struct net_device *dev)
3388static 3382static
3389int ks_wlan_close(struct net_device *dev) 3383int ks_wlan_close(struct net_device *dev)
3390{ 3384{
3391
3392 netif_stop_queue(dev); 3385 netif_stop_queue(dev);
3393 3386
3394 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n", 3387 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
@@ -3399,9 +3392,10 @@ int ks_wlan_close(struct net_device *dev)
3399 3392
3400/* Operational parameters that usually are not changed. */ 3393/* Operational parameters that usually are not changed. */
3401/* Time in jiffies before concluding the transmitter is hung. */ 3394/* Time in jiffies before concluding the transmitter is hung. */
3402#define TX_TIMEOUT (3*HZ) 3395#define TX_TIMEOUT (3 * HZ)
3403static const unsigned char dummy_addr[] = 3396static const unsigned char dummy_addr[] = {
3404 { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 }; 3397 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00
3398};
3405 3399
3406static const struct net_device_ops ks_wlan_netdev_ops = { 3400static const struct net_device_ops ks_wlan_netdev_ops = {
3407 .ndo_start_xmit = ks_wlan_start_xmit, 3401 .ndo_start_xmit = ks_wlan_start_xmit,
diff --git a/drivers/staging/ks7010/michael_mic.c b/drivers/staging/ks7010/michael_mic.c
index 2f535c08e172..f6e70fa2a12f 100644
--- a/drivers/staging/ks7010/michael_mic.c
+++ b/drivers/staging/ks7010/michael_mic.c
@@ -14,11 +14,11 @@
14#include "michael_mic.h" 14#include "michael_mic.h"
15 15
16// Rotation functions on 32 bit values 16// Rotation functions on 32 bit values
17#define ROL32(A, n) (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1))) 17#define ROL32(A, n) (((A) << (n)) | (((A) >> (32 - (n))) & ((1UL << (n)) - 1)))
18#define ROR32(A, n) ROL32((A), 32-(n)) 18#define ROR32(A, n) ROL32((A), 32 - (n))
19// Convert from Byte[] to UInt32 in a portable way 19// Convert from Byte[] to UInt32 in a portable way
20#define getUInt32(A, B) ((uint32_t)(A[B+0] << 0) \ 20#define getUInt32(A, B) ((uint32_t)(A[B + 0] << 0) \
21 + (A[B+1] << 8) + (A[B+2] << 16) + (A[B+3] << 24)) 21 + (A[B + 1] << 8) + (A[B + 2] << 16) + (A[B + 3] << 24))
22 22
23// Convert from UInt32 to Byte[] in a portable way 23// Convert from UInt32 to Byte[] in a portable way
24#define putUInt32(A, B, C) \ 24#define putUInt32(A, B, C) \
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
index 8f34c5ddc63e..3f773a4a344b 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
@@ -53,16 +53,56 @@ enum cfs_crypto_hash_alg {
53}; 53};
54 54
55static struct cfs_crypto_hash_type hash_types[] = { 55static struct cfs_crypto_hash_type hash_types[] = {
56 [CFS_HASH_ALG_NULL] = { "null", 0, 0 }, 56 [CFS_HASH_ALG_NULL] = {
57 [CFS_HASH_ALG_ADLER32] = { "adler32", 1, 4 }, 57 .cht_name = "null",
58 [CFS_HASH_ALG_CRC32] = { "crc32", ~0, 4 }, 58 .cht_key = 0,
59 [CFS_HASH_ALG_CRC32C] = { "crc32c", ~0, 4 }, 59 .cht_size = 0
60 [CFS_HASH_ALG_MD5] = { "md5", 0, 16 }, 60 },
61 [CFS_HASH_ALG_SHA1] = { "sha1", 0, 20 }, 61 [CFS_HASH_ALG_ADLER32] = {
62 [CFS_HASH_ALG_SHA256] = { "sha256", 0, 32 }, 62 .cht_name = "adler32",
63 [CFS_HASH_ALG_SHA384] = { "sha384", 0, 48 }, 63 .cht_key = 1,
64 [CFS_HASH_ALG_SHA512] = { "sha512", 0, 64 }, 64 .cht_size = 4
65 [CFS_HASH_ALG_MAX] = { NULL, 0, 64 }, 65 },
66 [CFS_HASH_ALG_CRC32] = {
67 .cht_name = "crc32",
68 .cht_key = ~0,
69 .cht_size = 4
70 },
71 [CFS_HASH_ALG_CRC32C] = {
72 .cht_name = "crc32c",
73 .cht_key = ~0,
74 .cht_size = 4
75 },
76 [CFS_HASH_ALG_MD5] = {
77 .cht_name = "md5",
78 .cht_key = 0,
79 .cht_size = 16
80 },
81 [CFS_HASH_ALG_SHA1] = {
82 .cht_name = "sha1",
83 .cht_key = 0,
84 .cht_size = 20
85 },
86 [CFS_HASH_ALG_SHA256] = {
87 .cht_name = "sha256",
88 .cht_key = 0,
89 .cht_size = 32
90 },
91 [CFS_HASH_ALG_SHA384] = {
92 .cht_name = "sha384",
93 .cht_key = 0,
94 .cht_size = 48
95 },
96 [CFS_HASH_ALG_SHA512] = {
97 .cht_name = "sha512",
98 .cht_key = 0,
99 .cht_size = 64
100 },
101 [CFS_HASH_ALG_MAX] = {
102 .cht_name = NULL,
103 .cht_key = 0,
104 .cht_size = 64
105 },
66}; 106};
67 107
68/* Maximum size of hash_types[].cht_size */ 108/* Maximum size of hash_types[].cht_size */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
index aab15d8112a4..2dae85798ec1 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
@@ -277,22 +277,6 @@ do { \
277#define CFS_ALLOC_PTR(ptr) LIBCFS_ALLOC(ptr, sizeof(*(ptr))) 277#define CFS_ALLOC_PTR(ptr) LIBCFS_ALLOC(ptr, sizeof(*(ptr)))
278#define CFS_FREE_PTR(ptr) LIBCFS_FREE(ptr, sizeof(*(ptr))) 278#define CFS_FREE_PTR(ptr) LIBCFS_FREE(ptr, sizeof(*(ptr)))
279 279
280/** Compile-time assertion.
281 *
282 * Check an invariant described by a constant expression at compile time by
283 * forcing a compiler error if it does not hold. \a cond must be a constant
284 * expression as defined by the ISO C Standard:
285 *
286 * 6.8.4.2 The switch statement
287 * ....
288 * [#3] The expression of each case label shall be an integer
289 * constant expression and no two of the case constant
290 * expressions in the same switch statement shall have the same
291 * value after conversion...
292 *
293 */
294#define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)
295
296/* max value for numeric network address */ 280/* max value for numeric network address */
297#define MAX_NUMERIC_VALUE 0xffffffff 281#define MAX_NUMERIC_VALUE 0xffffffff
298 282
diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h
index e8695e4a39d1..fa0808d2953b 100644
--- a/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h
@@ -125,10 +125,6 @@ do { \
125 125
126#include <linux/capability.h> 126#include <linux/capability.h>
127 127
128/* long integer with size equal to pointer */
129typedef unsigned long ulong_ptr_t;
130typedef long long_ptr_t;
131
132#ifndef WITH_WATCHDOG 128#ifndef WITH_WATCHDOG
133#define WITH_WATCHDOG 129#define WITH_WATCHDOG
134#endif 130#endif
diff --git a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h
index a59c5e99cbd3..3d19402ba728 100644
--- a/drivers/staging/lustre/include/linux/lnet/lib-lnet.h
+++ b/drivers/staging/lustre/include/linux/lnet/lib-lnet.h
@@ -78,7 +78,7 @@ static inline int lnet_is_route_alive(lnet_route_t *route)
78 return route->lr_downis == 0; 78 return route->lr_downis == 0;
79} 79}
80 80
81static inline int lnet_is_wire_handle_none(lnet_handle_wire_t *wh) 81static inline int lnet_is_wire_handle_none(struct lnet_handle_wire *wh)
82{ 82{
83 return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE && 83 return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
84 wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE); 84 wh->wh_object_cookie == LNET_WIRE_HANDLE_COOKIE_NONE);
@@ -323,7 +323,7 @@ lnet_handle2md(lnet_handle_md_t *handle)
323} 323}
324 324
325static inline lnet_libmd_t * 325static inline lnet_libmd_t *
326lnet_wire_handle2md(lnet_handle_wire_t *wh) 326lnet_wire_handle2md(struct lnet_handle_wire *wh)
327{ 327{
328 /* ALWAYS called with resource lock held */ 328 /* ALWAYS called with resource lock held */
329 lnet_libhandle_t *lh; 329 lnet_libhandle_t *lh;
@@ -552,7 +552,7 @@ int lnet_portals_create(void);
552void lnet_portals_destroy(void); 552void lnet_portals_destroy(void);
553 553
554/* message functions */ 554/* message functions */
555int lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, 555int lnet_parse(lnet_ni_t *ni, struct lnet_hdr *hdr,
556 lnet_nid_t fromnid, void *private, int rdma_req); 556 lnet_nid_t fromnid, void *private, int rdma_req);
557int lnet_parse_local(lnet_ni_t *ni, lnet_msg_t *msg); 557int lnet_parse_local(lnet_ni_t *ni, lnet_msg_t *msg);
558int lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg); 558int lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg);
@@ -579,7 +579,7 @@ void lnet_msg_containers_destroy(void);
579int lnet_msg_containers_create(void); 579int lnet_msg_containers_create(void);
580 580
581char *lnet_msgtyp2str(int type); 581char *lnet_msgtyp2str(int type);
582void lnet_print_hdr(lnet_hdr_t *hdr); 582void lnet_print_hdr(struct lnet_hdr *hdr);
583int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold); 583int lnet_fail_nid(lnet_nid_t nid, unsigned int threshold);
584 584
585/** \addtogroup lnet_fault_simulation @{ */ 585/** \addtogroup lnet_fault_simulation @{ */
@@ -588,7 +588,7 @@ int lnet_fault_ctl(int cmd, struct libcfs_ioctl_data *data);
588int lnet_fault_init(void); 588int lnet_fault_init(void);
589void lnet_fault_fini(void); 589void lnet_fault_fini(void);
590 590
591bool lnet_drop_rule_match(lnet_hdr_t *hdr); 591bool lnet_drop_rule_match(struct lnet_hdr *hdr);
592 592
593int lnet_delay_rule_add(struct lnet_fault_attr *attr); 593int lnet_delay_rule_add(struct lnet_fault_attr *attr);
594int lnet_delay_rule_del(lnet_nid_t src, lnet_nid_t dst, bool shutdown); 594int lnet_delay_rule_del(lnet_nid_t src, lnet_nid_t dst, bool shutdown);
@@ -596,7 +596,7 @@ int lnet_delay_rule_list(int pos, struct lnet_fault_attr *attr,
596 struct lnet_fault_stat *stat); 596 struct lnet_fault_stat *stat);
597void lnet_delay_rule_reset(void); 597void lnet_delay_rule_reset(void);
598void lnet_delay_rule_check(void); 598void lnet_delay_rule_check(void);
599bool lnet_delay_rule_match_locked(lnet_hdr_t *hdr, struct lnet_msg *msg); 599bool lnet_delay_rule_match_locked(struct lnet_hdr *hdr, struct lnet_msg *msg);
600 600
601/** @} lnet_fault_simulation */ 601/** @} lnet_fault_simulation */
602 602
@@ -664,7 +664,7 @@ int lnet_peer_buffer_credits(lnet_ni_t *ni);
664int lnet_router_checker_start(void); 664int lnet_router_checker_start(void);
665void lnet_router_checker_stop(void); 665void lnet_router_checker_stop(void);
666void lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net); 666void lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net);
667void lnet_swap_pinginfo(lnet_ping_info_t *info); 667void lnet_swap_pinginfo(struct lnet_ping_info *info);
668 668
669int lnet_parse_ip2nets(char **networksp, char *ip2nets); 669int lnet_parse_ip2nets(char **networksp, char *ip2nets);
670int lnet_parse_routes(char *route_str, int *im_a_router); 670int lnet_parse_routes(char *route_str, int *im_a_router);
diff --git a/drivers/staging/lustre/include/linux/lnet/lib-types.h b/drivers/staging/lustre/include/linux/lnet/lib-types.h
index b84a5bb9186c..9850398bf29a 100644
--- a/drivers/staging/lustre/include/linux/lnet/lib-types.h
+++ b/drivers/staging/lustre/include/linux/lnet/lib-types.h
@@ -105,7 +105,7 @@ typedef struct lnet_msg {
105 lnet_kiov_t *msg_kiov; 105 lnet_kiov_t *msg_kiov;
106 106
107 lnet_event_t msg_ev; 107 lnet_event_t msg_ev;
108 lnet_hdr_t msg_hdr; 108 struct lnet_hdr msg_hdr;
109} lnet_msg_t; 109} lnet_msg_t;
110 110
111typedef struct lnet_libhandle { 111typedef struct lnet_libhandle {
@@ -270,7 +270,7 @@ typedef struct lnet_ni {
270 struct lnet_tx_queue **ni_tx_queues; /* percpt TX queues */ 270 struct lnet_tx_queue **ni_tx_queues; /* percpt TX queues */
271 int **ni_refs; /* percpt reference count */ 271 int **ni_refs; /* percpt reference count */
272 time64_t ni_last_alive;/* when I was last alive */ 272 time64_t ni_last_alive;/* when I was last alive */
273 lnet_ni_status_t *ni_status; /* my health status */ 273 struct lnet_ni_status *ni_status; /* my health status */
274 /* per NI LND tunables */ 274 /* per NI LND tunables */
275 struct lnet_ioctl_config_lnd_tunables *ni_lnd_tunables; 275 struct lnet_ioctl_config_lnd_tunables *ni_lnd_tunables;
276 /* equivalent interfaces to use */ 276 /* equivalent interfaces to use */
@@ -295,13 +295,13 @@ typedef struct lnet_ni {
295 295
296/* router checker data, per router */ 296/* router checker data, per router */
297#define LNET_MAX_RTR_NIS 16 297#define LNET_MAX_RTR_NIS 16
298#define LNET_PINGINFO_SIZE offsetof(lnet_ping_info_t, pi_ni[LNET_MAX_RTR_NIS]) 298#define LNET_PINGINFO_SIZE offsetof(struct lnet_ping_info, pi_ni[LNET_MAX_RTR_NIS])
299typedef struct { 299typedef struct {
300 /* chain on the_lnet.ln_zombie_rcd or ln_deathrow_rcd */ 300 /* chain on the_lnet.ln_zombie_rcd or ln_deathrow_rcd */
301 struct list_head rcd_list; 301 struct list_head rcd_list;
302 lnet_handle_md_t rcd_mdh; /* ping buffer MD */ 302 lnet_handle_md_t rcd_mdh; /* ping buffer MD */
303 struct lnet_peer *rcd_gateway; /* reference to gateway */ 303 struct lnet_peer *rcd_gateway; /* reference to gateway */
304 lnet_ping_info_t *rcd_pinginfo; /* ping buffer */ 304 struct lnet_ping_info *rcd_pinginfo; /* ping buffer */
305} lnet_rc_data_t; 305} lnet_rc_data_t;
306 306
307typedef struct lnet_peer { 307typedef struct lnet_peer {
@@ -599,7 +599,7 @@ typedef struct {
599 599
600 lnet_handle_md_t ln_ping_target_md; 600 lnet_handle_md_t ln_ping_target_md;
601 lnet_handle_eq_t ln_ping_target_eq; 601 lnet_handle_eq_t ln_ping_target_eq;
602 lnet_ping_info_t *ln_ping_info; 602 struct lnet_ping_info *ln_ping_info;
603 603
604 /* router checker startup/shutdown state */ 604 /* router checker startup/shutdown state */
605 int ln_rc_state; 605 int ln_rc_state;
diff --git a/drivers/staging/lustre/include/linux/lnet/lnetst.h b/drivers/staging/lustre/include/linux/lnet/lnetst.h
index 8a84888635ff..c81c246ef221 100644
--- a/drivers/staging/lustre/include/linux/lnet/lnetst.h
+++ b/drivers/staging/lustre/include/linux/lnet/lnetst.h
@@ -68,16 +68,16 @@
68#define LSTIO_BATCH_QUERY 0xC27 /* query batch status */ 68#define LSTIO_BATCH_QUERY 0xC27 /* query batch status */
69#define LSTIO_STAT_QUERY 0xC30 /* get stats */ 69#define LSTIO_STAT_QUERY 0xC30 /* get stats */
70 70
71typedef struct { 71struct lst_sid {
72 lnet_nid_t ses_nid; /* nid of console node */ 72 lnet_nid_t ses_nid; /* nid of console node */
73 __u64 ses_stamp; /* time stamp */ 73 __u64 ses_stamp; /* time stamp */
74} lst_sid_t; /*** session id */ 74}; /*** session id */
75 75
76extern lst_sid_t LST_INVALID_SID; 76extern struct lst_sid LST_INVALID_SID;
77 77
78typedef struct { 78struct lst_bid {
79 __u64 bat_id; /* unique id in session */ 79 __u64 bat_id; /* unique id in session */
80} lst_bid_t; /*** batch id (group of tests) */ 80}; /*** batch id (group of tests) */
81 81
82/* Status of test node */ 82/* Status of test node */
83#define LST_NODE_ACTIVE 0x1 /* node in this session */ 83#define LST_NODE_ACTIVE 0x1 /* node in this session */
@@ -85,59 +85,59 @@ typedef struct {
85#define LST_NODE_DOWN 0x4 /* node is down */ 85#define LST_NODE_DOWN 0x4 /* node is down */
86#define LST_NODE_UNKNOWN 0x8 /* node not in session */ 86#define LST_NODE_UNKNOWN 0x8 /* node not in session */
87 87
88typedef struct { 88struct lstcon_node_ent {
89 lnet_process_id_t nde_id; /* id of node */ 89 lnet_process_id_t nde_id; /* id of node */
90 int nde_state; /* state of node */ 90 int nde_state; /* state of node */
91} lstcon_node_ent_t; /*** node entry, for list_group command */ 91}; /*** node entry, for list_group command */
92 92
93typedef struct { 93struct lstcon_ndlist_ent {
94 int nle_nnode; /* # of nodes */ 94 int nle_nnode; /* # of nodes */
95 int nle_nactive; /* # of active nodes */ 95 int nle_nactive; /* # of active nodes */
96 int nle_nbusy; /* # of busy nodes */ 96 int nle_nbusy; /* # of busy nodes */
97 int nle_ndown; /* # of down nodes */ 97 int nle_ndown; /* # of down nodes */
98 int nle_nunknown; /* # of unknown nodes */ 98 int nle_nunknown; /* # of unknown nodes */
99} lstcon_ndlist_ent_t; /*** node_list entry, for list_batch command */ 99}; /*** node_list entry, for list_batch command */
100 100
101typedef struct { 101struct lstcon_test_ent {
102 int tse_type; /* test type */ 102 int tse_type; /* test type */
103 int tse_loop; /* loop count */ 103 int tse_loop; /* loop count */
104 int tse_concur; /* concurrency of test */ 104 int tse_concur; /* concurrency of test */
105} lstcon_test_ent_t; /*** test summary entry, for 105}; /*** test summary entry, for
106 *** list_batch command */ 106 *** list_batch command */
107 107
108typedef struct { 108struct lstcon_batch_ent {
109 int bae_state; /* batch status */ 109 int bae_state; /* batch status */
110 int bae_timeout; /* batch timeout */ 110 int bae_timeout; /* batch timeout */
111 int bae_ntest; /* # of tests in the batch */ 111 int bae_ntest; /* # of tests in the batch */
112} lstcon_batch_ent_t; /*** batch summary entry, for 112}; /*** batch summary entry, for
113 *** list_batch command */ 113 *** list_batch command */
114 114
115typedef struct { 115struct lstcon_test_batch_ent {
116 lstcon_ndlist_ent_t tbe_cli_nle; /* client (group) node_list 116 struct lstcon_ndlist_ent tbe_cli_nle; /* client (group) node_list
117 * entry */ 117 * entry */
118 lstcon_ndlist_ent_t tbe_srv_nle; /* server (group) node_list 118 struct lstcon_ndlist_ent tbe_srv_nle; /* server (group) node_list
119 * entry */ 119 * entry */
120 union { 120 union {
121 lstcon_test_ent_t tbe_test; /* test entry */ 121 struct lstcon_test_ent tbe_test; /* test entry */
122 lstcon_batch_ent_t tbe_batch; /* batch entry */ 122 struct lstcon_batch_ent tbe_batch;/* batch entry */
123 } u; 123 } u;
124} lstcon_test_batch_ent_t; /*** test/batch verbose information entry, 124}; /*** test/batch verbose information entry,
125 *** for list_batch command */ 125 *** for list_batch command */
126 126
127typedef struct { 127struct lstcon_rpc_ent {
128 struct list_head rpe_link; /* link chain */ 128 struct list_head rpe_link; /* link chain */
129 lnet_process_id_t rpe_peer; /* peer's id */ 129 lnet_process_id_t rpe_peer; /* peer's id */
130 struct timeval rpe_stamp; /* time stamp of RPC */ 130 struct timeval rpe_stamp; /* time stamp of RPC */
131 int rpe_state; /* peer's state */ 131 int rpe_state; /* peer's state */
132 int rpe_rpc_errno; /* RPC errno */ 132 int rpe_rpc_errno; /* RPC errno */
133 133
134 lst_sid_t rpe_sid; /* peer's session id */ 134 struct lst_sid rpe_sid; /* peer's session id */
135 int rpe_fwk_errno; /* framework errno */ 135 int rpe_fwk_errno; /* framework errno */
136 int rpe_priv[4]; /* private data */ 136 int rpe_priv[4]; /* private data */
137 char rpe_payload[0]; /* private reply payload */ 137 char rpe_payload[0]; /* private reply payload */
138} lstcon_rpc_ent_t; 138};
139 139
140typedef struct { 140struct lstcon_trans_stat {
141 int trs_rpc_stat[4]; /* RPCs stat (0: total 141 int trs_rpc_stat[4]; /* RPCs stat (0: total
142 1: failed 142 1: failed
143 2: finished 143 2: finished
@@ -146,125 +146,125 @@ typedef struct {
146 int trs_fwk_stat[8]; /* framework stat */ 146 int trs_fwk_stat[8]; /* framework stat */
147 int trs_fwk_errno; /* errno of the first remote error */ 147 int trs_fwk_errno; /* errno of the first remote error */
148 void *trs_fwk_private; /* private framework stat */ 148 void *trs_fwk_private; /* private framework stat */
149} lstcon_trans_stat_t; 149};
150 150
151static inline int 151static inline int
152lstcon_rpc_stat_total(lstcon_trans_stat_t *stat, int inc) 152lstcon_rpc_stat_total(struct lstcon_trans_stat *stat, int inc)
153{ 153{
154 return inc ? ++stat->trs_rpc_stat[0] : stat->trs_rpc_stat[0]; 154 return inc ? ++stat->trs_rpc_stat[0] : stat->trs_rpc_stat[0];
155} 155}
156 156
157static inline int 157static inline int
158lstcon_rpc_stat_success(lstcon_trans_stat_t *stat, int inc) 158lstcon_rpc_stat_success(struct lstcon_trans_stat *stat, int inc)
159{ 159{
160 return inc ? ++stat->trs_rpc_stat[1] : stat->trs_rpc_stat[1]; 160 return inc ? ++stat->trs_rpc_stat[1] : stat->trs_rpc_stat[1];
161} 161}
162 162
163static inline int 163static inline int
164lstcon_rpc_stat_failure(lstcon_trans_stat_t *stat, int inc) 164lstcon_rpc_stat_failure(struct lstcon_trans_stat *stat, int inc)
165{ 165{
166 return inc ? ++stat->trs_rpc_stat[2] : stat->trs_rpc_stat[2]; 166 return inc ? ++stat->trs_rpc_stat[2] : stat->trs_rpc_stat[2];
167} 167}
168 168
169static inline int 169static inline int
170lstcon_sesop_stat_success(lstcon_trans_stat_t *stat, int inc) 170lstcon_sesop_stat_success(struct lstcon_trans_stat *stat, int inc)
171{ 171{
172 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0]; 172 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0];
173} 173}
174 174
175static inline int 175static inline int
176lstcon_sesop_stat_failure(lstcon_trans_stat_t *stat, int inc) 176lstcon_sesop_stat_failure(struct lstcon_trans_stat *stat, int inc)
177{ 177{
178 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1]; 178 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1];
179} 179}
180 180
181static inline int 181static inline int
182lstcon_sesqry_stat_active(lstcon_trans_stat_t *stat, int inc) 182lstcon_sesqry_stat_active(struct lstcon_trans_stat *stat, int inc)
183{ 183{
184 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0]; 184 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0];
185} 185}
186 186
187static inline int 187static inline int
188lstcon_sesqry_stat_busy(lstcon_trans_stat_t *stat, int inc) 188lstcon_sesqry_stat_busy(struct lstcon_trans_stat *stat, int inc)
189{ 189{
190 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1]; 190 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1];
191} 191}
192 192
193static inline int 193static inline int
194lstcon_sesqry_stat_unknown(lstcon_trans_stat_t *stat, int inc) 194lstcon_sesqry_stat_unknown(struct lstcon_trans_stat *stat, int inc)
195{ 195{
196 return inc ? ++stat->trs_fwk_stat[2] : stat->trs_fwk_stat[2]; 196 return inc ? ++stat->trs_fwk_stat[2] : stat->trs_fwk_stat[2];
197} 197}
198 198
199static inline int 199static inline int
200lstcon_tsbop_stat_success(lstcon_trans_stat_t *stat, int inc) 200lstcon_tsbop_stat_success(struct lstcon_trans_stat *stat, int inc)
201{ 201{
202 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0]; 202 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0];
203} 203}
204 204
205static inline int 205static inline int
206lstcon_tsbop_stat_failure(lstcon_trans_stat_t *stat, int inc) 206lstcon_tsbop_stat_failure(struct lstcon_trans_stat *stat, int inc)
207{ 207{
208 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1]; 208 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1];
209} 209}
210 210
211static inline int 211static inline int
212lstcon_tsbqry_stat_idle(lstcon_trans_stat_t *stat, int inc) 212lstcon_tsbqry_stat_idle(struct lstcon_trans_stat *stat, int inc)
213{ 213{
214 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0]; 214 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0];
215} 215}
216 216
217static inline int 217static inline int
218lstcon_tsbqry_stat_run(lstcon_trans_stat_t *stat, int inc) 218lstcon_tsbqry_stat_run(struct lstcon_trans_stat *stat, int inc)
219{ 219{
220 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1]; 220 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1];
221} 221}
222 222
223static inline int 223static inline int
224lstcon_tsbqry_stat_failure(lstcon_trans_stat_t *stat, int inc) 224lstcon_tsbqry_stat_failure(struct lstcon_trans_stat *stat, int inc)
225{ 225{
226 return inc ? ++stat->trs_fwk_stat[2] : stat->trs_fwk_stat[2]; 226 return inc ? ++stat->trs_fwk_stat[2] : stat->trs_fwk_stat[2];
227} 227}
228 228
229static inline int 229static inline int
230lstcon_statqry_stat_success(lstcon_trans_stat_t *stat, int inc) 230lstcon_statqry_stat_success(struct lstcon_trans_stat *stat, int inc)
231{ 231{
232 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0]; 232 return inc ? ++stat->trs_fwk_stat[0] : stat->trs_fwk_stat[0];
233} 233}
234 234
235static inline int 235static inline int
236lstcon_statqry_stat_failure(lstcon_trans_stat_t *stat, int inc) 236lstcon_statqry_stat_failure(struct lstcon_trans_stat *stat, int inc)
237{ 237{
238 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1]; 238 return inc ? ++stat->trs_fwk_stat[1] : stat->trs_fwk_stat[1];
239} 239}
240 240
241/* create a session */ 241/* create a session */
242typedef struct { 242struct lstio_session_new_args {
243 int lstio_ses_key; /* IN: local key */ 243 int lstio_ses_key; /* IN: local key */
244 int lstio_ses_timeout; /* IN: session timeout */ 244 int lstio_ses_timeout; /* IN: session timeout */
245 int lstio_ses_force; /* IN: force create ? */ 245 int lstio_ses_force; /* IN: force create ? */
246 /** IN: session features */ 246 /** IN: session features */
247 unsigned int lstio_ses_feats; 247 unsigned int lstio_ses_feats;
248 lst_sid_t __user *lstio_ses_idp; /* OUT: session id */ 248 struct lst_sid __user *lstio_ses_idp; /* OUT: session id */
249 int lstio_ses_nmlen; /* IN: name length */ 249 int lstio_ses_nmlen; /* IN: name length */
250 char __user *lstio_ses_namep; /* IN: session name */ 250 char __user *lstio_ses_namep; /* IN: session name */
251} lstio_session_new_args_t; 251};
252 252
253/* query current session */ 253/* query current session */
254typedef struct { 254struct lstio_session_info_args {
255 lst_sid_t __user *lstio_ses_idp; /* OUT: session id */ 255 struct lst_sid __user *lstio_ses_idp; /* OUT: session id */
256 int __user *lstio_ses_keyp; /* OUT: local key */ 256 int __user *lstio_ses_keyp; /* OUT: local key */
257 /** OUT: session features */ 257 /** OUT: session features */
258 unsigned int __user *lstio_ses_featp; 258 unsigned int __user *lstio_ses_featp;
259 lstcon_ndlist_ent_t __user *lstio_ses_ndinfo; /* OUT: */ 259 struct lstcon_ndlist_ent __user *lstio_ses_ndinfo;/* OUT: */
260 int lstio_ses_nmlen; /* IN: name length */ 260 int lstio_ses_nmlen; /* IN: name length */
261 char __user *lstio_ses_namep; /* OUT: session name */ 261 char __user *lstio_ses_namep; /* OUT: session name */
262} lstio_session_info_args_t; 262};
263 263
264/* delete a session */ 264/* delete a session */
265typedef struct { 265struct lstio_session_end_args {
266 int lstio_ses_key; /* IN: session key */ 266 int lstio_ses_key; /* IN: session key */
267} lstio_session_end_args_t; 267};
268 268
269#define LST_OPC_SESSION 1 269#define LST_OPC_SESSION 1
270#define LST_OPC_GROUP 2 270#define LST_OPC_GROUP 2
@@ -272,7 +272,7 @@ typedef struct {
272#define LST_OPC_BATCHCLI 4 272#define LST_OPC_BATCHCLI 4
273#define LST_OPC_BATCHSRV 5 273#define LST_OPC_BATCHSRV 5
274 274
275typedef struct { 275struct lstio_debug_args {
276 int lstio_dbg_key; /* IN: session key */ 276 int lstio_dbg_key; /* IN: session key */
277 int lstio_dbg_type; /* IN: debug 277 int lstio_dbg_type; /* IN: debug
278 session|batch| 278 session|batch|
@@ -291,26 +291,26 @@ typedef struct {
291 nodes */ 291 nodes */
292 struct list_head __user *lstio_dbg_resultp; /* OUT: list head of 292 struct list_head __user *lstio_dbg_resultp; /* OUT: list head of
293 result buffer */ 293 result buffer */
294} lstio_debug_args_t; 294};
295 295
296typedef struct { 296struct lstio_group_add_args {
297 int lstio_grp_key; /* IN: session key */ 297 int lstio_grp_key; /* IN: session key */
298 int lstio_grp_nmlen; /* IN: name length */ 298 int lstio_grp_nmlen; /* IN: name length */
299 char __user *lstio_grp_namep; /* IN: group name */ 299 char __user *lstio_grp_namep; /* IN: group name */
300} lstio_group_add_args_t; 300};
301 301
302typedef struct { 302struct lstio_group_del_args {
303 int lstio_grp_key; /* IN: session key */ 303 int lstio_grp_key; /* IN: session key */
304 int lstio_grp_nmlen; /* IN: name length */ 304 int lstio_grp_nmlen; /* IN: name length */
305 char __user *lstio_grp_namep; /* IN: group name */ 305 char __user *lstio_grp_namep; /* IN: group name */
306} lstio_group_del_args_t; 306};
307 307
308#define LST_GROUP_CLEAN 1 /* remove inactive nodes in the group */ 308#define LST_GROUP_CLEAN 1 /* remove inactive nodes in the group */
309#define LST_GROUP_REFRESH 2 /* refresh inactive nodes 309#define LST_GROUP_REFRESH 2 /* refresh inactive nodes
310 * in the group */ 310 * in the group */
311#define LST_GROUP_RMND 3 /* delete nodes from the group */ 311#define LST_GROUP_RMND 3 /* delete nodes from the group */
312 312
313typedef struct { 313struct lstio_group_update_args {
314 int lstio_grp_key; /* IN: session key */ 314 int lstio_grp_key; /* IN: session key */
315 int lstio_grp_opc; /* IN: OPC */ 315 int lstio_grp_opc; /* IN: OPC */
316 int lstio_grp_args; /* IN: arguments */ 316 int lstio_grp_args; /* IN: arguments */
@@ -320,9 +320,9 @@ typedef struct {
320 lnet_process_id_t __user *lstio_grp_idsp; /* IN: array of nodes */ 320 lnet_process_id_t __user *lstio_grp_idsp; /* IN: array of nodes */
321 struct list_head __user *lstio_grp_resultp; /* OUT: list head of 321 struct list_head __user *lstio_grp_resultp; /* OUT: list head of
322 result buffer */ 322 result buffer */
323} lstio_group_update_args_t; 323};
324 324
325typedef struct { 325struct lstio_group_nodes_args {
326 int lstio_grp_key; /* IN: session key */ 326 int lstio_grp_key; /* IN: session key */
327 int lstio_grp_nmlen; /* IN: name length */ 327 int lstio_grp_nmlen; /* IN: name length */
328 char __user *lstio_grp_namep; /* IN: group name */ 328 char __user *lstio_grp_namep; /* IN: group name */
@@ -332,41 +332,41 @@ typedef struct {
332 lnet_process_id_t __user *lstio_grp_idsp; /* IN: nodes */ 332 lnet_process_id_t __user *lstio_grp_idsp; /* IN: nodes */
333 struct list_head __user *lstio_grp_resultp; /* OUT: list head of 333 struct list_head __user *lstio_grp_resultp; /* OUT: list head of
334 result buffer */ 334 result buffer */
335} lstio_group_nodes_args_t; 335};
336 336
337typedef struct { 337struct lstio_group_list_args {
338 int lstio_grp_key; /* IN: session key */ 338 int lstio_grp_key; /* IN: session key */
339 int lstio_grp_idx; /* IN: group idx */ 339 int lstio_grp_idx; /* IN: group idx */
340 int lstio_grp_nmlen; /* IN: name len */ 340 int lstio_grp_nmlen; /* IN: name len */
341 char __user *lstio_grp_namep; /* OUT: name */ 341 char __user *lstio_grp_namep; /* OUT: name */
342} lstio_group_list_args_t; 342};
343 343
344typedef struct { 344struct lstio_group_info_args {
345 int lstio_grp_key; /* IN: session key */ 345 int lstio_grp_key; /* IN: session key */
346 int lstio_grp_nmlen; /* IN: name len */ 346 int lstio_grp_nmlen; /* IN: name len */
347 char __user *lstio_grp_namep; /* IN: name */ 347 char __user *lstio_grp_namep; /* IN: name */
348 lstcon_ndlist_ent_t __user *lstio_grp_entp; /* OUT: description of 348 struct lstcon_ndlist_ent __user *lstio_grp_entp;/* OUT: description of
349 group */ 349 group */
350 int __user *lstio_grp_idxp; /* IN/OUT: node index */ 350 int __user *lstio_grp_idxp; /* IN/OUT: node index */
351 int __user *lstio_grp_ndentp; /* IN/OUT: # of nodent */ 351 int __user *lstio_grp_ndentp; /* IN/OUT: # of nodent */
352 lstcon_node_ent_t __user *lstio_grp_dentsp; /* OUT: nodent array */ 352 struct lstcon_node_ent __user *lstio_grp_dentsp;/* OUT: nodent array */
353} lstio_group_info_args_t; 353};
354 354
355#define LST_DEFAULT_BATCH "batch" /* default batch name */ 355#define LST_DEFAULT_BATCH "batch" /* default batch name */
356 356
357typedef struct { 357struct lstio_batch_add_args {
358 int lstio_bat_key; /* IN: session key */ 358 int lstio_bat_key; /* IN: session key */
359 int lstio_bat_nmlen; /* IN: name length */ 359 int lstio_bat_nmlen; /* IN: name length */
360 char __user *lstio_bat_namep; /* IN: batch name */ 360 char __user *lstio_bat_namep; /* IN: batch name */
361} lstio_batch_add_args_t; 361};
362 362
363typedef struct { 363struct lstio_batch_del_args {
364 int lstio_bat_key; /* IN: session key */ 364 int lstio_bat_key; /* IN: session key */
365 int lstio_bat_nmlen; /* IN: name length */ 365 int lstio_bat_nmlen; /* IN: name length */
366 char __user *lstio_bat_namep; /* IN: batch name */ 366 char __user *lstio_bat_namep; /* IN: batch name */
367} lstio_batch_del_args_t; 367};
368 368
369typedef struct { 369struct lstio_batch_run_args {
370 int lstio_bat_key; /* IN: session key */ 370 int lstio_bat_key; /* IN: session key */
371 int lstio_bat_timeout; /* IN: timeout for 371 int lstio_bat_timeout; /* IN: timeout for
372 the batch */ 372 the batch */
@@ -374,9 +374,9 @@ typedef struct {
374 char __user *lstio_bat_namep; /* IN: batch name */ 374 char __user *lstio_bat_namep; /* IN: batch name */
375 struct list_head __user *lstio_bat_resultp; /* OUT: list head of 375 struct list_head __user *lstio_bat_resultp; /* OUT: list head of
376 result buffer */ 376 result buffer */
377} lstio_batch_run_args_t; 377};
378 378
379typedef struct { 379struct lstio_batch_stop_args {
380 int lstio_bat_key; /* IN: session key */ 380 int lstio_bat_key; /* IN: session key */
381 int lstio_bat_force; /* IN: abort unfinished 381 int lstio_bat_force; /* IN: abort unfinished
382 test RPC */ 382 test RPC */
@@ -384,9 +384,9 @@ typedef struct {
384 char __user *lstio_bat_namep; /* IN: batch name */ 384 char __user *lstio_bat_namep; /* IN: batch name */
385 struct list_head __user *lstio_bat_resultp; /* OUT: list head of 385 struct list_head __user *lstio_bat_resultp; /* OUT: list head of
386 result buffer */ 386 result buffer */
387} lstio_batch_stop_args_t; 387};
388 388
389typedef struct { 389struct lstio_batch_query_args {
390 int lstio_bat_key; /* IN: session key */ 390 int lstio_bat_key; /* IN: session key */
391 int lstio_bat_testidx; /* IN: test index */ 391 int lstio_bat_testidx; /* IN: test index */
392 int lstio_bat_client; /* IN: we testing 392 int lstio_bat_client; /* IN: we testing
@@ -397,31 +397,31 @@ typedef struct {
397 char __user *lstio_bat_namep; /* IN: batch name */ 397 char __user *lstio_bat_namep; /* IN: batch name */
398 struct list_head __user *lstio_bat_resultp; /* OUT: list head of 398 struct list_head __user *lstio_bat_resultp; /* OUT: list head of
399 result buffer */ 399 result buffer */
400} lstio_batch_query_args_t; 400};
401 401
402typedef struct { 402struct lstio_batch_list_args {
403 int lstio_bat_key; /* IN: session key */ 403 int lstio_bat_key; /* IN: session key */
404 int lstio_bat_idx; /* IN: index */ 404 int lstio_bat_idx; /* IN: index */
405 int lstio_bat_nmlen; /* IN: name length */ 405 int lstio_bat_nmlen; /* IN: name length */
406 char __user *lstio_bat_namep; /* IN: batch name */ 406 char __user *lstio_bat_namep; /* IN: batch name */
407} lstio_batch_list_args_t; 407};
408 408
409typedef struct { 409struct lstio_batch_info_args {
410 int lstio_bat_key; /* IN: session key */ 410 int lstio_bat_key; /* IN: session key */
411 int lstio_bat_nmlen; /* IN: name length */ 411 int lstio_bat_nmlen; /* IN: name length */
412 char __user *lstio_bat_namep; /* IN: name */ 412 char __user *lstio_bat_namep; /* IN: name */
413 int lstio_bat_server; /* IN: query server 413 int lstio_bat_server; /* IN: query server
414 or not */ 414 or not */
415 int lstio_bat_testidx; /* IN: test index */ 415 int lstio_bat_testidx; /* IN: test index */
416 lstcon_test_batch_ent_t __user *lstio_bat_entp; /* OUT: batch ent */ 416 struct lstcon_test_batch_ent __user *lstio_bat_entp;/* OUT: batch ent */
417 417
418 int __user *lstio_bat_idxp; /* IN/OUT: index of node */ 418 int __user *lstio_bat_idxp; /* IN/OUT: index of node */
419 int __user *lstio_bat_ndentp; /* IN/OUT: # of nodent */ 419 int __user *lstio_bat_ndentp; /* IN/OUT: # of nodent */
420 lstcon_node_ent_t __user *lstio_bat_dentsp; /* array of nodent */ 420 struct lstcon_node_ent __user *lstio_bat_dentsp;/* array of nodent */
421} lstio_batch_info_args_t; 421};
422 422
423/* add stat in session */ 423/* add stat in session */
424typedef struct { 424struct lstio_stat_args {
425 int lstio_sta_key; /* IN: session key */ 425 int lstio_sta_key; /* IN: session key */
426 int lstio_sta_timeout; /* IN: timeout for 426 int lstio_sta_timeout; /* IN: timeout for
427 stat request */ 427 stat request */
@@ -432,17 +432,17 @@ typedef struct {
432 lnet_process_id_t __user *lstio_sta_idsp; /* IN: pid */ 432 lnet_process_id_t __user *lstio_sta_idsp; /* IN: pid */
433 struct list_head __user *lstio_sta_resultp; /* OUT: list head of 433 struct list_head __user *lstio_sta_resultp; /* OUT: list head of
434 result buffer */ 434 result buffer */
435} lstio_stat_args_t; 435};
436 436
437typedef enum { 437enum lst_test_type {
438 LST_TEST_BULK = 1, 438 LST_TEST_BULK = 1,
439 LST_TEST_PING = 2 439 LST_TEST_PING = 2
440} lst_test_type_t; 440};
441 441
442/* create a test in a batch */ 442/* create a test in a batch */
443#define LST_MAX_CONCUR 1024 /* Max concurrency of test */ 443#define LST_MAX_CONCUR 1024 /* Max concurrency of test */
444 444
445typedef struct { 445struct lstio_test_args {
446 int lstio_tes_key; /* IN: session key */ 446 int lstio_tes_key; /* IN: session key */
447 int lstio_tes_bat_nmlen; /* IN: batch name len */ 447 int lstio_tes_bat_nmlen; /* IN: batch name len */
448 char __user *lstio_tes_bat_name; /* IN: batch name */ 448 char __user *lstio_tes_bat_name; /* IN: batch name */
@@ -472,36 +472,36 @@ typedef struct {
472 value */ 472 value */
473 struct list_head __user *lstio_tes_resultp;/* OUT: list head of 473 struct list_head __user *lstio_tes_resultp;/* OUT: list head of
474 result buffer */ 474 result buffer */
475} lstio_test_args_t; 475};
476 476
477typedef enum { 477enum lst_brw_type {
478 LST_BRW_READ = 1, 478 LST_BRW_READ = 1,
479 LST_BRW_WRITE = 2 479 LST_BRW_WRITE = 2
480} lst_brw_type_t; 480};
481 481
482typedef enum { 482enum lst_brw_flags {
483 LST_BRW_CHECK_NONE = 1, 483 LST_BRW_CHECK_NONE = 1,
484 LST_BRW_CHECK_SIMPLE = 2, 484 LST_BRW_CHECK_SIMPLE = 2,
485 LST_BRW_CHECK_FULL = 3 485 LST_BRW_CHECK_FULL = 3
486} lst_brw_flags_t; 486};
487 487
488typedef struct { 488struct lst_test_bulk_param {
489 int blk_opc; /* bulk operation code */ 489 int blk_opc; /* bulk operation code */
490 int blk_size; /* size (bytes) */ 490 int blk_size; /* size (bytes) */
491 int blk_time; /* time of running the test*/ 491 int blk_time; /* time of running the test*/
492 int blk_flags; /* reserved flags */ 492 int blk_flags; /* reserved flags */
493 int blk_cli_off; /* bulk offset on client */ 493 int blk_cli_off; /* bulk offset on client */
494 int blk_srv_off; /* reserved: bulk offset on server */ 494 int blk_srv_off; /* reserved: bulk offset on server */
495} lst_test_bulk_param_t; 495};
496 496
497typedef struct { 497struct lst_test_ping_param {
498 int png_size; /* size of ping message */ 498 int png_size; /* size of ping message */
499 int png_time; /* time */ 499 int png_time; /* time */
500 int png_loop; /* loop */ 500 int png_loop; /* loop */
501 int png_flags; /* reserved flags */ 501 int png_flags; /* reserved flags */
502} lst_test_ping_param_t; 502};
503 503
504typedef struct { 504struct srpc_counters {
505 __u32 errors; 505 __u32 errors;
506 __u32 rpcs_sent; 506 __u32 rpcs_sent;
507 __u32 rpcs_rcvd; 507 __u32 rpcs_rcvd;
@@ -509,15 +509,15 @@ typedef struct {
509 __u32 rpcs_expired; 509 __u32 rpcs_expired;
510 __u64 bulk_get; 510 __u64 bulk_get;
511 __u64 bulk_put; 511 __u64 bulk_put;
512} WIRE_ATTR srpc_counters_t; 512} WIRE_ATTR;
513 513
514typedef struct { 514struct sfw_counters {
515 /** milliseconds since current session started */ 515 /** milliseconds since current session started */
516 __u32 running_ms; 516 __u32 running_ms;
517 __u32 active_batches; 517 __u32 active_batches;
518 __u32 zombie_sessions; 518 __u32 zombie_sessions;
519 __u32 brw_errors; 519 __u32 brw_errors;
520 __u32 ping_errors; 520 __u32 ping_errors;
521} WIRE_ATTR sfw_counters_t; 521} WIRE_ATTR;
522 522
523#endif 523#endif
diff --git a/drivers/staging/lustre/include/linux/lnet/socklnd.h b/drivers/staging/lustre/include/linux/lnet/socklnd.h
index bc32403f4a08..acf20ce6f403 100644
--- a/drivers/staging/lustre/include/linux/lnet/socklnd.h
+++ b/drivers/staging/lustre/include/linux/lnet/socklnd.h
@@ -60,7 +60,7 @@ typedef struct {
60} WIRE_ATTR ksock_hello_msg_t; 60} WIRE_ATTR ksock_hello_msg_t;
61 61
62typedef struct { 62typedef struct {
63 lnet_hdr_t ksnm_hdr; /* lnet hdr */ 63 struct lnet_hdr ksnm_hdr; /* lnet hdr */
64 64
65 /* 65 /*
66 * ksnm_payload is removed because of winnt compiler's limitation: 66 * ksnm_payload is removed because of winnt compiler's limitation:
@@ -80,15 +80,6 @@ typedef struct {
80 } WIRE_ATTR ksm_u; 80 } WIRE_ATTR ksm_u;
81} WIRE_ATTR ksock_msg_t; 81} WIRE_ATTR ksock_msg_t;
82 82
83static inline void
84socklnd_init_msg(ksock_msg_t *msg, int type)
85{
86 msg->ksm_csum = 0;
87 msg->ksm_type = type;
88 msg->ksm_zc_cookies[0] = 0;
89 msg->ksm_zc_cookies[1] = 0;
90}
91
92#define KSOCK_MSG_NOOP 0xC0 /* ksm_u empty */ 83#define KSOCK_MSG_NOOP 0xC0 /* ksm_u empty */
93#define KSOCK_MSG_LNET 0xC1 /* lnet msg */ 84#define KSOCK_MSG_LNET 0xC1 /* lnet msg */
94 85
diff --git a/drivers/staging/lustre/include/linux/lnet/types.h b/drivers/staging/lustre/include/linux/lnet/types.h
index 8ca1e9d0cfe2..1c8de72e6d6b 100644
--- a/drivers/staging/lustre/include/linux/lnet/types.h
+++ b/drivers/staging/lustre/include/linux/lnet/types.h
@@ -115,11 +115,11 @@ static inline __u32 LNET_MKNET(__u32 type, __u32 num)
115#define WIRE_ATTR __packed 115#define WIRE_ATTR __packed
116 116
117/* Packed version of lnet_process_id_t to transfer via network */ 117/* Packed version of lnet_process_id_t to transfer via network */
118typedef struct { 118struct lnet_process_id_packed {
119 /* node id / process id */ 119 /* node id / process id */
120 lnet_nid_t nid; 120 lnet_nid_t nid;
121 lnet_pid_t pid; 121 lnet_pid_t pid;
122} WIRE_ATTR lnet_process_id_packed_t; 122} WIRE_ATTR;
123 123
124/* 124/*
125 * The wire handle's interface cookie only matches one network interface in 125 * The wire handle's interface cookie only matches one network interface in
@@ -127,10 +127,10 @@ typedef struct {
127 * reboots). The object cookie only matches one object on that interface 127 * reboots). The object cookie only matches one object on that interface
128 * during that object's lifetime (i.e. no cookie re-use). 128 * during that object's lifetime (i.e. no cookie re-use).
129 */ 129 */
130typedef struct { 130struct lnet_handle_wire {
131 __u64 wh_interface_cookie; 131 __u64 wh_interface_cookie;
132 __u64 wh_object_cookie; 132 __u64 wh_object_cookie;
133} WIRE_ATTR lnet_handle_wire_t; 133} WIRE_ATTR;
134 134
135typedef enum { 135typedef enum {
136 LNET_MSG_ACK = 0, 136 LNET_MSG_ACK = 0,
@@ -146,38 +146,38 @@ typedef enum {
146 * wire structs MUST be fixed size and the smaller types are placed at the 146 * wire structs MUST be fixed size and the smaller types are placed at the
147 * end. 147 * end.
148 */ 148 */
149typedef struct lnet_ack { 149struct lnet_ack {
150 lnet_handle_wire_t dst_wmd; 150 struct lnet_handle_wire dst_wmd;
151 __u64 match_bits; 151 __u64 match_bits;
152 __u32 mlength; 152 __u32 mlength;
153} WIRE_ATTR lnet_ack_t; 153} WIRE_ATTR;
154 154
155typedef struct lnet_put { 155struct lnet_put {
156 lnet_handle_wire_t ack_wmd; 156 struct lnet_handle_wire ack_wmd;
157 __u64 match_bits; 157 __u64 match_bits;
158 __u64 hdr_data; 158 __u64 hdr_data;
159 __u32 ptl_index; 159 __u32 ptl_index;
160 __u32 offset; 160 __u32 offset;
161} WIRE_ATTR lnet_put_t; 161} WIRE_ATTR;
162 162
163typedef struct lnet_get { 163struct lnet_get {
164 lnet_handle_wire_t return_wmd; 164 struct lnet_handle_wire return_wmd;
165 __u64 match_bits; 165 __u64 match_bits;
166 __u32 ptl_index; 166 __u32 ptl_index;
167 __u32 src_offset; 167 __u32 src_offset;
168 __u32 sink_length; 168 __u32 sink_length;
169} WIRE_ATTR lnet_get_t; 169} WIRE_ATTR;
170 170
171typedef struct lnet_reply { 171struct lnet_reply {
172 lnet_handle_wire_t dst_wmd; 172 struct lnet_handle_wire dst_wmd;
173} WIRE_ATTR lnet_reply_t; 173} WIRE_ATTR;
174 174
175typedef struct lnet_hello { 175struct lnet_hello {
176 __u64 incarnation; 176 __u64 incarnation;
177 __u32 type; 177 __u32 type;
178} WIRE_ATTR lnet_hello_t; 178} WIRE_ATTR;
179 179
180typedef struct { 180struct lnet_hdr {
181 lnet_nid_t dest_nid; 181 lnet_nid_t dest_nid;
182 lnet_nid_t src_nid; 182 lnet_nid_t src_nid;
183 lnet_pid_t dest_pid; 183 lnet_pid_t dest_pid;
@@ -186,13 +186,13 @@ typedef struct {
186 __u32 payload_length; /* payload data to follow */ 186 __u32 payload_length; /* payload data to follow */
187 /*<------__u64 aligned------->*/ 187 /*<------__u64 aligned------->*/
188 union { 188 union {
189 lnet_ack_t ack; 189 struct lnet_ack ack;
190 lnet_put_t put; 190 struct lnet_put put;
191 lnet_get_t get; 191 struct lnet_get get;
192 lnet_reply_t reply; 192 struct lnet_reply reply;
193 lnet_hello_t hello; 193 struct lnet_hello hello;
194 } msg; 194 } msg;
195} WIRE_ATTR lnet_hdr_t; 195} WIRE_ATTR;
196 196
197/* 197/*
198 * A HELLO message contains a magic number and protocol version 198 * A HELLO message contains a magic number and protocol version
@@ -202,13 +202,13 @@ typedef struct {
202 * This is for use by byte-stream LNDs (e.g. TCP/IP) to check the peer is 202 * This is for use by byte-stream LNDs (e.g. TCP/IP) to check the peer is
203 * running the same protocol and to find out its NID. These LNDs should 203 * running the same protocol and to find out its NID. These LNDs should
204 * exchange HELLO messages when a connection is first established. Individual 204 * exchange HELLO messages when a connection is first established. Individual
205 * LNDs can put whatever else they fancy in lnet_hdr_t::msg. 205 * LNDs can put whatever else they fancy in struct lnet_hdr::msg.
206 */ 206 */
207typedef struct { 207struct lnet_magicversion {
208 __u32 magic; /* LNET_PROTO_TCP_MAGIC */ 208 __u32 magic; /* LNET_PROTO_TCP_MAGIC */
209 __u16 version_major; /* increment on incompatible change */ 209 __u16 version_major; /* increment on incompatible change */
210 __u16 version_minor; /* increment on compatible change */ 210 __u16 version_minor; /* increment on compatible change */
211} WIRE_ATTR lnet_magicversion_t; 211} WIRE_ATTR;
212 212
213/* PROTO MAGIC for LNDs */ 213/* PROTO MAGIC for LNDs */
214#define LNET_PROTO_IB_MAGIC 0x0be91b91 214#define LNET_PROTO_IB_MAGIC 0x0be91b91
@@ -228,27 +228,27 @@ typedef struct {
228#define LNET_PROTO_TCP_VERSION_MINOR 0 228#define LNET_PROTO_TCP_VERSION_MINOR 0
229 229
230/* Acceptor connection request */ 230/* Acceptor connection request */
231typedef struct { 231struct lnet_acceptor_connreq {
232 __u32 acr_magic; /* PTL_ACCEPTOR_PROTO_MAGIC */ 232 __u32 acr_magic; /* PTL_ACCEPTOR_PROTO_MAGIC */
233 __u32 acr_version; /* protocol version */ 233 __u32 acr_version; /* protocol version */
234 __u64 acr_nid; /* target NID */ 234 __u64 acr_nid; /* target NID */
235} WIRE_ATTR lnet_acceptor_connreq_t; 235} WIRE_ATTR;
236 236
237#define LNET_PROTO_ACCEPTOR_VERSION 1 237#define LNET_PROTO_ACCEPTOR_VERSION 1
238 238
239typedef struct { 239struct lnet_ni_status {
240 lnet_nid_t ns_nid; 240 lnet_nid_t ns_nid;
241 __u32 ns_status; 241 __u32 ns_status;
242 __u32 ns_unused; 242 __u32 ns_unused;
243} WIRE_ATTR lnet_ni_status_t; 243} WIRE_ATTR;
244 244
245typedef struct { 245struct lnet_ping_info {
246 __u32 pi_magic; 246 __u32 pi_magic;
247 __u32 pi_features; 247 __u32 pi_features;
248 lnet_pid_t pi_pid; 248 lnet_pid_t pi_pid;
249 __u32 pi_nnis; 249 __u32 pi_nnis;
250 lnet_ni_status_t pi_ni[0]; 250 struct lnet_ni_status pi_ni[0];
251} WIRE_ATTR lnet_ping_info_t; 251} WIRE_ATTR;
252 252
253typedef struct lnet_counters { 253typedef struct lnet_counters {
254 __u32 msgs_alloc; 254 __u32 msgs_alloc;
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 7f761b327166..b1e8508f9fc7 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -258,8 +258,8 @@ int kiblnd_unpack_msg(struct kib_msg *msg, int nob)
258 if (flip) { 258 if (flip) {
259 /* leave magic unflipped as a clue to peer endianness */ 259 /* leave magic unflipped as a clue to peer endianness */
260 msg->ibm_version = version; 260 msg->ibm_version = version;
261 CLASSERT(sizeof(msg->ibm_type) == 1); 261 BUILD_BUG_ON(sizeof(msg->ibm_type) != 1);
262 CLASSERT(sizeof(msg->ibm_credits) == 1); 262 BUILD_BUG_ON(sizeof(msg->ibm_credits) != 1);
263 msg->ibm_nob = msg_nob; 263 msg->ibm_nob = msg_nob;
264 __swab64s(&msg->ibm_srcnid); 264 __swab64s(&msg->ibm_srcnid);
265 __swab64s(&msg->ibm_srcstamp); 265 __swab64s(&msg->ibm_srcstamp);
@@ -1247,10 +1247,10 @@ static void kiblnd_map_tx_pool(struct kib_tx_pool *tpo)
1247 dev = net->ibn_dev; 1247 dev = net->ibn_dev;
1248 1248
1249 /* pre-mapped messages are not bigger than 1 page */ 1249 /* pre-mapped messages are not bigger than 1 page */
1250 CLASSERT(IBLND_MSG_SIZE <= PAGE_SIZE); 1250 BUILD_BUG_ON(IBLND_MSG_SIZE > PAGE_SIZE);
1251 1251
1252 /* No fancy arithmetic when we do the buffer calculations */ 1252 /* No fancy arithmetic when we do the buffer calculations */
1253 CLASSERT(!(PAGE_SIZE % IBLND_MSG_SIZE)); 1253 BUILD_BUG_ON(PAGE_SIZE % IBLND_MSG_SIZE);
1254 1254
1255 tpo->tpo_hdev = kiblnd_current_hdev(dev); 1255 tpo->tpo_hdev = kiblnd_current_hdev(dev);
1256 1256
@@ -2943,7 +2943,7 @@ static int kiblnd_startup(lnet_ni_t *ni)
2943 if (ni->ni_interfaces[0]) { 2943 if (ni->ni_interfaces[0]) {
2944 /* Use the IPoIB interface specified in 'networks=' */ 2944 /* Use the IPoIB interface specified in 'networks=' */
2945 2945
2946 CLASSERT(LNET_MAX_INTERFACES > 1); 2946 BUILD_BUG_ON(LNET_MAX_INTERFACES <= 1);
2947 if (ni->ni_interfaces[1]) { 2947 if (ni->ni_interfaces[1]) {
2948 CERROR("Multiple interfaces not supported\n"); 2948 CERROR("Multiple interfaces not supported\n");
2949 goto failed; 2949 goto failed;
@@ -3020,11 +3020,11 @@ static void __exit ko2iblnd_exit(void)
3020 3020
3021static int __init ko2iblnd_init(void) 3021static int __init ko2iblnd_init(void)
3022{ 3022{
3023 CLASSERT(sizeof(struct kib_msg) <= IBLND_MSG_SIZE); 3023 BUILD_BUG_ON(sizeof(struct kib_msg) > IBLND_MSG_SIZE);
3024 CLASSERT(offsetof(struct kib_msg, 3024 BUILD_BUG_ON(!offsetof(struct kib_msg,
3025 ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) 3025 ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS])
3026 <= IBLND_MSG_SIZE); 3026 <= IBLND_MSG_SIZE);
3027 CLASSERT(offsetof(struct kib_msg, 3027 BUILD_BUG_ON(!offsetof(struct kib_msg,
3028 ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) 3028 ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS])
3029 <= IBLND_MSG_SIZE); 3029 <= IBLND_MSG_SIZE);
3030 3030
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
index 14576977200f..2cb429830681 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
@@ -364,7 +364,7 @@ struct kib_connparams {
364} WIRE_ATTR; 364} WIRE_ATTR;
365 365
366struct kib_immediate_msg { 366struct kib_immediate_msg {
367 lnet_hdr_t ibim_hdr; /* portals header */ 367 struct lnet_hdr ibim_hdr; /* portals header */
368 char ibim_payload[0]; /* piggy-backed payload */ 368 char ibim_payload[0]; /* piggy-backed payload */
369} WIRE_ATTR; 369} WIRE_ATTR;
370 370
@@ -380,7 +380,7 @@ struct kib_rdma_desc {
380} WIRE_ATTR; 380} WIRE_ATTR;
381 381
382struct kib_putreq_msg { 382struct kib_putreq_msg {
383 lnet_hdr_t ibprm_hdr; /* portals header */ 383 struct lnet_hdr ibprm_hdr; /* portals header */
384 __u64 ibprm_cookie; /* opaque completion cookie */ 384 __u64 ibprm_cookie; /* opaque completion cookie */
385} WIRE_ATTR; 385} WIRE_ATTR;
386 386
@@ -391,7 +391,7 @@ struct kib_putack_msg {
391} WIRE_ATTR; 391} WIRE_ATTR;
392 392
393struct kib_get_msg { 393struct kib_get_msg {
394 lnet_hdr_t ibgm_hdr; /* portals header */ 394 struct lnet_hdr ibgm_hdr; /* portals header */
395 __u64 ibgm_cookie; /* opaque completion cookie */ 395 __u64 ibgm_cookie; /* opaque completion cookie */
396 struct kib_rdma_desc ibgm_rd; /* rdma descriptor */ 396 struct kib_rdma_desc ibgm_rd; /* rdma descriptor */
397} WIRE_ATTR; 397} WIRE_ATTR;
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
index c7917abf9944..e2f3f7294260 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
@@ -1490,7 +1490,7 @@ kiblnd_launch_tx(lnet_ni_t *ni, struct kib_tx *tx, lnet_nid_t nid)
1490int 1490int
1491kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg) 1491kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1492{ 1492{
1493 lnet_hdr_t *hdr = &lntmsg->msg_hdr; 1493 struct lnet_hdr *hdr = &lntmsg->msg_hdr;
1494 int type = lntmsg->msg_type; 1494 int type = lntmsg->msg_type;
1495 lnet_process_id_t target = lntmsg->msg_target; 1495 lnet_process_id_t target = lntmsg->msg_target;
1496 int target_is_router = lntmsg->msg_target_is_router; 1496 int target_is_router = lntmsg->msg_target_is_router;
@@ -3546,7 +3546,7 @@ kiblnd_scheduler(void *arg)
3546 3546
3547 rc = cfs_cpt_bind(lnet_cpt_table(), sched->ibs_cpt); 3547 rc = cfs_cpt_bind(lnet_cpt_table(), sched->ibs_cpt);
3548 if (rc) { 3548 if (rc) {
3549 CWARN("Failed to bind on CPT %d, please verify whether all CPUs are healthy and reload modules if necessary, otherwise your system might under risk of low performance\n", 3549 CWARN("Unable to bind on CPU partition %d, please verify whether all CPUs are healthy and reload modules if necessary, otherwise your system might under risk of low performance\n",
3550 sched->ibs_cpt); 3550 sched->ibs_cpt);
3551 } 3551 }
3552 3552
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
index b74cf635faee..f25de3d7f6e8 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
@@ -1108,12 +1108,12 @@ ksocknal_create_conn(lnet_ni_t *ni, struct ksock_route *route,
1108 write_unlock_bh(global_lock); 1108 write_unlock_bh(global_lock);
1109 1109
1110 if (!conn->ksnc_proto) { 1110 if (!conn->ksnc_proto) {
1111 conn->ksnc_proto = &ksocknal_protocol_v3x; 1111 conn->ksnc_proto = &ksocknal_protocol_v3x;
1112#if SOCKNAL_VERSION_DEBUG 1112#if SOCKNAL_VERSION_DEBUG
1113 if (*ksocknal_tunables.ksnd_protocol == 2) 1113 if (*ksocknal_tunables.ksnd_protocol == 2)
1114 conn->ksnc_proto = &ksocknal_protocol_v2x; 1114 conn->ksnc_proto = &ksocknal_protocol_v2x;
1115 else if (*ksocknal_tunables.ksnd_protocol == 1) 1115 else if (*ksocknal_tunables.ksnd_protocol == 1)
1116 conn->ksnc_proto = &ksocknal_protocol_v1x; 1116 conn->ksnc_proto = &ksocknal_protocol_v1x;
1117#endif 1117#endif
1118 } 1118 }
1119 1119
@@ -2507,7 +2507,7 @@ ksocknal_base_startup(void)
2507 2507
2508 snprintf(name, sizeof(name), "socknal_cd%02d", i); 2508 snprintf(name, sizeof(name), "socknal_cd%02d", i);
2509 rc = ksocknal_thread_start(ksocknal_connd, 2509 rc = ksocknal_thread_start(ksocknal_connd,
2510 (void *)((ulong_ptr_t)i), name); 2510 (void *)((uintptr_t)i), name);
2511 if (rc) { 2511 if (rc) {
2512 spin_lock_bh(&ksocknal_data.ksnd_connd_lock); 2512 spin_lock_bh(&ksocknal_data.ksnd_connd_lock);
2513 ksocknal_data.ksnd_connd_starting--; 2513 ksocknal_data.ksnd_connd_starting--;
@@ -2904,8 +2904,8 @@ static int __init ksocklnd_init(void)
2904 int rc; 2904 int rc;
2905 2905
2906 /* check ksnr_connected/connecting field large enough */ 2906 /* check ksnr_connected/connecting field large enough */
2907 CLASSERT(SOCKLND_CONN_NTYPES <= 4); 2907 BUILD_BUG_ON(SOCKLND_CONN_NTYPES > 4);
2908 CLASSERT(SOCKLND_CONN_ACK == SOCKLND_CONN_BULK_IN); 2908 BUILD_BUG_ON(SOCKLND_CONN_ACK != SOCKLND_CONN_BULK_IN);
2909 2909
2910 /* initialize the_ksocklnd */ 2910 /* initialize the_ksocklnd */
2911 the_ksocklnd.lnd_type = SOCKLND; 2911 the_ksocklnd.lnd_type = SOCKLND;
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
index 842c45393b38..9e86563b8c70 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
@@ -373,7 +373,7 @@ struct ksock_conn {
373 * V2.x message takes the 373 * V2.x message takes the
374 * whole struct 374 * whole struct
375 * V1.x message is a bare 375 * V1.x message is a bare
376 * lnet_hdr_t, it's stored in 376 * struct lnet_hdr, it's stored in
377 * ksnc_msg.ksm_u.lnetmsg 377 * ksnc_msg.ksm_u.lnetmsg
378 */ 378 */
379 /* WRITER */ 379 /* WRITER */
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index 972f6094be75..4c9f92725a44 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -80,7 +80,9 @@ ksocknal_alloc_tx_noop(__u64 cookie, int nonblk)
80 tx->tx_niov = 1; 80 tx->tx_niov = 1;
81 tx->tx_nonblk = nonblk; 81 tx->tx_nonblk = nonblk;
82 82
83 socklnd_init_msg(&tx->tx_msg, KSOCK_MSG_NOOP); 83 tx->tx_msg.ksm_csum = 0;
84 tx->tx_msg.ksm_type = KSOCK_MSG_NOOP;
85 tx->tx_msg.ksm_zc_cookies[0] = 0;
84 tx->tx_msg.ksm_zc_cookies[1] = cookie; 86 tx->tx_msg.ksm_zc_cookies[1] = cookie;
85 87
86 return tx; 88 return tx;
@@ -1004,7 +1006,10 @@ ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1004 tx->tx_zc_capable = 1; 1006 tx->tx_zc_capable = 1;
1005 } 1007 }
1006 1008
1007 socklnd_init_msg(&tx->tx_msg, KSOCK_MSG_LNET); 1009 tx->tx_msg.ksm_csum = 0;
1010 tx->tx_msg.ksm_type = KSOCK_MSG_LNET;
1011 tx->tx_msg.ksm_zc_cookies[0] = 0;
1012 tx->tx_msg.ksm_zc_cookies[1] = 0;
1008 1013
1009 /* The first fragment will be set later in pro_pack */ 1014 /* The first fragment will be set later in pro_pack */
1010 rc = ksocknal_launch_packet(ni, tx, target); 1015 rc = ksocknal_launch_packet(ni, tx, target);
@@ -1073,14 +1078,14 @@ ksocknal_new_packet(struct ksock_conn *conn, int nob_to_skip)
1073 break; 1078 break;
1074 1079
1075 case KSOCK_PROTO_V1: 1080 case KSOCK_PROTO_V1:
1076 /* Receiving bare lnet_hdr_t */ 1081 /* Receiving bare struct lnet_hdr */
1077 conn->ksnc_rx_state = SOCKNAL_RX_LNET_HEADER; 1082 conn->ksnc_rx_state = SOCKNAL_RX_LNET_HEADER;
1078 conn->ksnc_rx_nob_wanted = sizeof(lnet_hdr_t); 1083 conn->ksnc_rx_nob_wanted = sizeof(struct lnet_hdr);
1079 conn->ksnc_rx_nob_left = sizeof(lnet_hdr_t); 1084 conn->ksnc_rx_nob_left = sizeof(struct lnet_hdr);
1080 1085
1081 conn->ksnc_rx_iov = (struct kvec *)&conn->ksnc_rx_iov_space; 1086 conn->ksnc_rx_iov = (struct kvec *)&conn->ksnc_rx_iov_space;
1082 conn->ksnc_rx_iov[0].iov_base = &conn->ksnc_msg.ksm_u.lnetmsg; 1087 conn->ksnc_rx_iov[0].iov_base = &conn->ksnc_msg.ksm_u.lnetmsg;
1083 conn->ksnc_rx_iov[0].iov_len = sizeof(lnet_hdr_t); 1088 conn->ksnc_rx_iov[0].iov_len = sizeof(struct lnet_hdr);
1084 break; 1089 break;
1085 1090
1086 default: 1091 default:
@@ -1126,7 +1131,7 @@ ksocknal_new_packet(struct ksock_conn *conn, int nob_to_skip)
1126static int 1131static int
1127ksocknal_process_receive(struct ksock_conn *conn) 1132ksocknal_process_receive(struct ksock_conn *conn)
1128{ 1133{
1129 lnet_hdr_t *lhdr; 1134 struct lnet_hdr *lhdr;
1130 lnet_process_id_t *id; 1135 lnet_process_id_t *id;
1131 int rc; 1136 int rc;
1132 1137
@@ -1414,8 +1419,8 @@ int ksocknal_scheduler(void *arg)
1414 1419
1415 rc = cfs_cpt_bind(lnet_cpt_table(), info->ksi_cpt); 1420 rc = cfs_cpt_bind(lnet_cpt_table(), info->ksi_cpt);
1416 if (rc) { 1421 if (rc) {
1417 CERROR("Can't set CPT affinity to %d: %d\n", 1422 CWARN("Can't set CPU partition affinity to %d: %d\n",
1418 info->ksi_cpt, rc); 1423 info->ksi_cpt, rc);
1419 } 1424 }
1420 1425
1421 spin_lock_bh(&sched->kss_lock); 1426 spin_lock_bh(&sched->kss_lock);
@@ -1656,9 +1661,9 @@ ksocknal_parse_proto_version(ksock_hello_msg_t *hello)
1656 } 1661 }
1657 1662
1658 if (hello->kshm_magic == le32_to_cpu(LNET_PROTO_TCP_MAGIC)) { 1663 if (hello->kshm_magic == le32_to_cpu(LNET_PROTO_TCP_MAGIC)) {
1659 lnet_magicversion_t *hmv = (lnet_magicversion_t *)hello; 1664 struct lnet_magicversion *hmv = (struct lnet_magicversion *)hello;
1660 1665
1661 CLASSERT(sizeof(lnet_magicversion_t) == 1666 BUILD_BUG_ON(sizeof(struct lnet_magicversion) !=
1662 offsetof(ksock_hello_msg_t, kshm_src_nid)); 1667 offsetof(ksock_hello_msg_t, kshm_src_nid));
1663 1668
1664 if (hmv->version_major == cpu_to_le16(KSOCK_PROTO_V1_MAJOR) && 1669 if (hmv->version_major == cpu_to_le16(KSOCK_PROTO_V1_MAJOR) &&
@@ -2456,6 +2461,7 @@ ksocknal_check_peer_timeouts(int idx)
2456 2461
2457 list_for_each_entry(peer, peers, ksnp_list) { 2462 list_for_each_entry(peer, peers, ksnp_list) {
2458 unsigned long deadline = 0; 2463 unsigned long deadline = 0;
2464 struct ksock_tx *tx_stale;
2459 int resid = 0; 2465 int resid = 0;
2460 int n = 0; 2466 int n = 0;
2461 2467
@@ -2503,6 +2509,7 @@ ksocknal_check_peer_timeouts(int idx)
2503 if (list_empty(&peer->ksnp_zc_req_list)) 2509 if (list_empty(&peer->ksnp_zc_req_list))
2504 continue; 2510 continue;
2505 2511
2512 tx_stale = NULL;
2506 spin_lock(&peer->ksnp_lock); 2513 spin_lock(&peer->ksnp_lock);
2507 list_for_each_entry(tx, &peer->ksnp_zc_req_list, tx_zc_list) { 2514 list_for_each_entry(tx, &peer->ksnp_zc_req_list, tx_zc_list) {
2508 if (!cfs_time_aftereq(cfs_time_current(), 2515 if (!cfs_time_aftereq(cfs_time_current(),
@@ -2511,26 +2518,26 @@ ksocknal_check_peer_timeouts(int idx)
2511 /* ignore the TX if connection is being closed */ 2518 /* ignore the TX if connection is being closed */
2512 if (tx->tx_conn->ksnc_closing) 2519 if (tx->tx_conn->ksnc_closing)
2513 continue; 2520 continue;
2521 if (!tx_stale)
2522 tx_stale = tx;
2514 n++; 2523 n++;
2515 } 2524 }
2516 2525
2517 if (!n) { 2526 if (!tx_stale) {
2518 spin_unlock(&peer->ksnp_lock); 2527 spin_unlock(&peer->ksnp_lock);
2519 continue; 2528 continue;
2520 } 2529 }
2521 2530
2522 tx = list_entry(peer->ksnp_zc_req_list.next, 2531 deadline = tx_stale->tx_deadline;
2523 struct ksock_tx, tx_zc_list); 2532 resid = tx_stale->tx_resid;
2524 deadline = tx->tx_deadline; 2533 conn = tx_stale->tx_conn;
2525 resid = tx->tx_resid;
2526 conn = tx->tx_conn;
2527 ksocknal_conn_addref(conn); 2534 ksocknal_conn_addref(conn);
2528 2535
2529 spin_unlock(&peer->ksnp_lock); 2536 spin_unlock(&peer->ksnp_lock);
2530 read_unlock(&ksocknal_data.ksnd_global_lock); 2537 read_unlock(&ksocknal_data.ksnd_global_lock);
2531 2538
2532 CERROR("Total %d stale ZC_REQs for peer %s detected; the oldest(%p) timed out %ld secs ago, resid: %d, wmem: %d\n", 2539 CERROR("Total %d stale ZC_REQs for peer %s detected; the oldest(%p) timed out %ld secs ago, resid: %d, wmem: %d\n",
2533 n, libcfs_nid2str(peer->ksnp_id.nid), tx, 2540 n, libcfs_nid2str(peer->ksnp_id.nid), tx_stale,
2534 cfs_duration_sec(cfs_time_current() - deadline), 2541 cfs_duration_sec(cfs_time_current() - deadline),
2535 resid, conn->ksnc_sock->sk->sk_wmem_queued); 2542 resid, conn->ksnc_sock->sk->sk_wmem_queued);
2536 2543
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
index 8f0ff6ca1f39..d367e74d46c2 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
@@ -291,7 +291,7 @@ ksocknal_match_tx(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
291 } else { 291 } else {
292 nob = tx->tx_lnetmsg->msg_len + 292 nob = tx->tx_lnetmsg->msg_len +
293 ((conn->ksnc_proto == &ksocknal_protocol_v1x) ? 293 ((conn->ksnc_proto == &ksocknal_protocol_v1x) ?
294 sizeof(lnet_hdr_t) : sizeof(ksock_msg_t)); 294 sizeof(struct lnet_hdr) : sizeof(ksock_msg_t));
295 } 295 }
296 296
297 /* default checking for typed connection */ 297 /* default checking for typed connection */
@@ -459,23 +459,23 @@ static int
459ksocknal_send_hello_v1(struct ksock_conn *conn, ksock_hello_msg_t *hello) 459ksocknal_send_hello_v1(struct ksock_conn *conn, ksock_hello_msg_t *hello)
460{ 460{
461 struct socket *sock = conn->ksnc_sock; 461 struct socket *sock = conn->ksnc_sock;
462 lnet_hdr_t *hdr; 462 struct lnet_hdr *hdr;
463 lnet_magicversion_t *hmv; 463 struct lnet_magicversion *hmv;
464 int rc; 464 int rc;
465 int i; 465 int i;
466 466
467 CLASSERT(sizeof(lnet_magicversion_t) == offsetof(lnet_hdr_t, src_nid)); 467 BUILD_BUG_ON(sizeof(struct lnet_magicversion) != offsetof(struct lnet_hdr, src_nid));
468 468
469 LIBCFS_ALLOC(hdr, sizeof(*hdr)); 469 LIBCFS_ALLOC(hdr, sizeof(*hdr));
470 if (!hdr) { 470 if (!hdr) {
471 CERROR("Can't allocate lnet_hdr_t\n"); 471 CERROR("Can't allocate struct lnet_hdr\n");
472 return -ENOMEM; 472 return -ENOMEM;
473 } 473 }
474 474
475 hmv = (lnet_magicversion_t *)&hdr->dest_nid; 475 hmv = (struct lnet_magicversion *)&hdr->dest_nid;
476 476
477 /* 477 /*
478 * Re-organize V2.x message header to V1.x (lnet_hdr_t) 478 * Re-organize V2.x message header to V1.x (struct lnet_hdr)
479 * header and send out 479 * header and send out
480 */ 480 */
481 hmv->magic = cpu_to_le32(LNET_PROTO_TCP_MAGIC); 481 hmv->magic = cpu_to_le32(LNET_PROTO_TCP_MAGIC);
@@ -577,18 +577,18 @@ ksocknal_recv_hello_v1(struct ksock_conn *conn, ksock_hello_msg_t *hello,
577 int timeout) 577 int timeout)
578{ 578{
579 struct socket *sock = conn->ksnc_sock; 579 struct socket *sock = conn->ksnc_sock;
580 lnet_hdr_t *hdr; 580 struct lnet_hdr *hdr;
581 int rc; 581 int rc;
582 int i; 582 int i;
583 583
584 LIBCFS_ALLOC(hdr, sizeof(*hdr)); 584 LIBCFS_ALLOC(hdr, sizeof(*hdr));
585 if (!hdr) { 585 if (!hdr) {
586 CERROR("Can't allocate lnet_hdr_t\n"); 586 CERROR("Can't allocate struct lnet_hdr\n");
587 return -ENOMEM; 587 return -ENOMEM;
588 } 588 }
589 589
590 rc = lnet_sock_read(sock, &hdr->src_nid, 590 rc = lnet_sock_read(sock, &hdr->src_nid,
591 sizeof(*hdr) - offsetof(lnet_hdr_t, src_nid), 591 sizeof(*hdr) - offsetof(struct lnet_hdr, src_nid),
592 timeout); 592 timeout);
593 if (rc) { 593 if (rc) {
594 CERROR("Error %d reading rest of HELLO hdr from %pI4h\n", 594 CERROR("Error %d reading rest of HELLO hdr from %pI4h\n",
@@ -723,10 +723,10 @@ ksocknal_pack_msg_v1(struct ksock_tx *tx)
723 LASSERT(tx->tx_lnetmsg); 723 LASSERT(tx->tx_lnetmsg);
724 724
725 tx->tx_iov[0].iov_base = &tx->tx_lnetmsg->msg_hdr; 725 tx->tx_iov[0].iov_base = &tx->tx_lnetmsg->msg_hdr;
726 tx->tx_iov[0].iov_len = sizeof(lnet_hdr_t); 726 tx->tx_iov[0].iov_len = sizeof(struct lnet_hdr);
727 727
728 tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(lnet_hdr_t); 728 tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr);
729 tx->tx_resid = tx->tx_lnetmsg->msg_len + sizeof(lnet_hdr_t); 729 tx->tx_resid = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr);
730} 730}
731 731
732static void 732static void
diff --git a/drivers/staging/lustre/lnet/libcfs/debug.c b/drivers/staging/lustre/lnet/libcfs/debug.c
index a38db2322225..3408041355e3 100644
--- a/drivers/staging/lustre/lnet/libcfs/debug.c
+++ b/drivers/staging/lustre/lnet/libcfs/debug.c
@@ -343,7 +343,7 @@ void libcfs_debug_dumplog_internal(void *arg)
343 last_dump_time = current_time; 343 last_dump_time = current_time;
344 snprintf(debug_file_name, sizeof(debug_file_name) - 1, 344 snprintf(debug_file_name, sizeof(debug_file_name) - 1,
345 "%s.%lld.%ld", libcfs_debug_file_path_arr, 345 "%s.%lld.%ld", libcfs_debug_file_path_arr,
346 (s64)current_time, (long_ptr_t)arg); 346 (s64)current_time, (long)arg);
347 pr_alert("LustreError: dumping log to %s\n", debug_file_name); 347 pr_alert("LustreError: dumping log to %s\n", debug_file_name);
348 cfs_tracefile_dump_all_pages(debug_file_name); 348 cfs_tracefile_dump_all_pages(debug_file_name);
349 libcfs_run_debug_log_upcall(debug_file_name); 349 libcfs_run_debug_log_upcall(debug_file_name);
diff --git a/drivers/staging/lustre/lnet/libcfs/hash.c b/drivers/staging/lustre/lnet/libcfs/hash.c
index c93c59d8fe6c..5c2ce2ee6fd9 100644
--- a/drivers/staging/lustre/lnet/libcfs/hash.c
+++ b/drivers/staging/lustre/lnet/libcfs/hash.c
@@ -1000,7 +1000,7 @@ cfs_hash_create(char *name, unsigned int cur_bits, unsigned int max_bits,
1000 struct cfs_hash *hs; 1000 struct cfs_hash *hs;
1001 int len; 1001 int len;
1002 1002
1003 CLASSERT(CFS_HASH_THETA_BITS < 15); 1003 BUILD_BUG_ON(CFS_HASH_THETA_BITS >= 15);
1004 1004
1005 LASSERT(name); 1005 LASSERT(name);
1006 LASSERT(ops->hs_key); 1006 LASSERT(ops->hs_key);
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
index 427e2198bb9e..4d35a371216c 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-cpu.c
@@ -59,7 +59,7 @@ MODULE_PARM_DESC(cpu_npartitions, "# of CPU partitions");
59 * 59 *
60 * NB: If user specified cpu_pattern, cpu_npartitions will be ignored 60 * NB: If user specified cpu_pattern, cpu_npartitions will be ignored
61 */ 61 */
62static char *cpu_pattern = ""; 62static char *cpu_pattern = "N";
63module_param(cpu_pattern, charp, 0444); 63module_param(cpu_pattern, charp, 0444);
64MODULE_PARM_DESC(cpu_pattern, "CPU partitions pattern"); 64MODULE_PARM_DESC(cpu_pattern, "CPU partitions pattern");
65 65
@@ -1050,7 +1050,15 @@ cfs_cpu_init(void)
1050 ret = -EINVAL; 1050 ret = -EINVAL;
1051 1051
1052 if (*cpu_pattern) { 1052 if (*cpu_pattern) {
1053 cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern); 1053 char *cpu_pattern_dup = kstrdup(cpu_pattern, GFP_KERNEL);
1054
1055 if (!cpu_pattern_dup) {
1056 CERROR("Failed to duplicate cpu_pattern\n");
1057 goto failed;
1058 }
1059
1060 cfs_cpt_table = cfs_cpt_table_create_pattern(cpu_pattern_dup);
1061 kfree(cpu_pattern_dup);
1054 if (!cfs_cpt_table) { 1062 if (!cfs_cpt_table) {
1055 CERROR("Failed to create cptab from pattern %s\n", 1063 CERROR("Failed to create cptab from pattern %s\n",
1056 cpu_pattern); 1064 cpu_pattern);
@@ -1074,8 +1082,9 @@ cfs_cpu_init(void)
1074 } 1082 }
1075 spin_unlock(&cpt_data.cpt_lock); 1083 spin_unlock(&cpt_data.cpt_lock);
1076 1084
1077 LCONSOLE(0, "HW CPU cores: %d, npartitions: %d\n", 1085 LCONSOLE(0, "HW nodes: %d, HW CPU cores: %d, npartitions: %d\n",
1078 num_online_cpus(), cfs_cpt_number(cfs_cpt_table)); 1086 num_online_nodes(), num_online_cpus(),
1087 cfs_cpt_number(cfs_cpt_table));
1079 return 0; 1088 return 0;
1080 1089
1081 failed: 1090 failed:
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index 3f5d58babc2f..075826bd3a2a 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -122,7 +122,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
122 const struct libcfs_ioctl_hdr __user *uhdr) 122 const struct libcfs_ioctl_hdr __user *uhdr)
123{ 123{
124 struct libcfs_ioctl_hdr hdr; 124 struct libcfs_ioctl_hdr hdr;
125 int err = 0; 125 int err;
126 126
127 if (copy_from_user(&hdr, uhdr, sizeof(hdr))) 127 if (copy_from_user(&hdr, uhdr, sizeof(hdr)))
128 return -EFAULT; 128 return -EFAULT;
@@ -150,9 +150,20 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
150 return -ENOMEM; 150 return -ENOMEM;
151 151
152 if (copy_from_user(*hdr_pp, uhdr, hdr.ioc_len)) { 152 if (copy_from_user(*hdr_pp, uhdr, hdr.ioc_len)) {
153 LIBCFS_FREE(*hdr_pp, hdr.ioc_len);
154 err = -EFAULT; 153 err = -EFAULT;
154 goto free;
155 } 155 }
156
157 if ((*hdr_pp)->ioc_version != hdr.ioc_version ||
158 (*hdr_pp)->ioc_len != hdr.ioc_len) {
159 err = -EINVAL;
160 goto free;
161 }
162
163 return 0;
164
165free:
166 LIBCFS_FREE(*hdr_pp, hdr.ioc_len);
156 return err; 167 return err;
157} 168}
158 169
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/lustre/lnet/libcfs/module.c
index 161e04226521..c388550c2d10 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -488,10 +488,10 @@ static const struct file_operations lnet_debugfs_file_operations_wo = {
488 488
489static const struct file_operations *lnet_debugfs_fops_select(umode_t mode) 489static const struct file_operations *lnet_debugfs_fops_select(umode_t mode)
490{ 490{
491 if (!(mode & S_IWUGO)) 491 if (!(mode & 0222))
492 return &lnet_debugfs_file_operations_ro; 492 return &lnet_debugfs_file_operations_ro;
493 493
494 if (!(mode & S_IRUGO)) 494 if (!(mode & 0444))
495 return &lnet_debugfs_file_operations_wo; 495 return &lnet_debugfs_file_operations_wo;
496 496
497 return &lnet_debugfs_file_operations_rw; 497 return &lnet_debugfs_file_operations_rw;
diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c
index d0512da6bcde..dbc2a9b8dff8 100644
--- a/drivers/staging/lustre/lnet/libcfs/workitem.c
+++ b/drivers/staging/lustre/lnet/libcfs/workitem.c
@@ -209,7 +209,7 @@ static int cfs_wi_scheduler(void *arg)
209 /* CPT affinity scheduler? */ 209 /* CPT affinity scheduler? */
210 if (sched->ws_cptab) 210 if (sched->ws_cptab)
211 if (cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt)) 211 if (cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt))
212 CWARN("Failed to bind %s on CPT %d\n", 212 CWARN("Unable to bind %s on CPU partition %d\n",
213 sched->ws_name, sched->ws_cpt); 213 sched->ws_name, sched->ws_cpt);
214 214
215 spin_lock(&cfs_wi_data.wi_glock); 215 spin_lock(&cfs_wi_data.wi_glock);
diff --git a/drivers/staging/lustre/lnet/lnet/acceptor.c b/drivers/staging/lustre/lnet/lnet/acceptor.c
index 8c50c99d82d5..69bbd594b9bd 100644
--- a/drivers/staging/lustre/lnet/lnet/acceptor.c
+++ b/drivers/staging/lustre/lnet/lnet/acceptor.c
@@ -143,13 +143,13 @@ int
143lnet_connect(struct socket **sockp, lnet_nid_t peer_nid, 143lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
144 __u32 local_ip, __u32 peer_ip, int peer_port) 144 __u32 local_ip, __u32 peer_ip, int peer_port)
145{ 145{
146 lnet_acceptor_connreq_t cr; 146 struct lnet_acceptor_connreq cr;
147 struct socket *sock; 147 struct socket *sock;
148 int rc; 148 int rc;
149 int port; 149 int port;
150 int fatal; 150 int fatal;
151 151
152 CLASSERT(sizeof(cr) <= 16); /* not too big to be on the stack */ 152 BUILD_BUG_ON(sizeof(cr) > 16); /* too big to be on the stack */
153 153
154 for (port = LNET_ACCEPTOR_MAX_RESERVED_PORT; 154 for (port = LNET_ACCEPTOR_MAX_RESERVED_PORT;
155 port >= LNET_ACCEPTOR_MIN_RESERVED_PORT; 155 port >= LNET_ACCEPTOR_MIN_RESERVED_PORT;
@@ -164,7 +164,7 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
164 continue; 164 continue;
165 } 165 }
166 166
167 CLASSERT(LNET_PROTO_ACCEPTOR_VERSION == 1); 167 BUILD_BUG_ON(LNET_PROTO_ACCEPTOR_VERSION != 1);
168 168
169 cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC; 169 cr.acr_magic = LNET_PROTO_ACCEPTOR_MAGIC;
170 cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION; 170 cr.acr_version = LNET_PROTO_ACCEPTOR_VERSION;
@@ -206,7 +206,7 @@ EXPORT_SYMBOL(lnet_connect);
206static int 206static int
207lnet_accept(struct socket *sock, __u32 magic) 207lnet_accept(struct socket *sock, __u32 magic)
208{ 208{
209 lnet_acceptor_connreq_t cr; 209 struct lnet_acceptor_connreq cr;
210 __u32 peer_ip; 210 __u32 peer_ip;
211 int peer_port; 211 int peer_port;
212 int rc; 212 int rc;
@@ -284,7 +284,7 @@ lnet_accept(struct socket *sock, __u32 magic)
284 284
285 rc = lnet_sock_read(sock, &cr.acr_nid, 285 rc = lnet_sock_read(sock, &cr.acr_nid,
286 sizeof(cr) - 286 sizeof(cr) -
287 offsetof(lnet_acceptor_connreq_t, acr_nid), 287 offsetof(struct lnet_acceptor_connreq, acr_nid),
288 accept_timeout); 288 accept_timeout);
289 if (rc) { 289 if (rc) {
290 CERROR("Error %d reading connection request from %pI4h\n", 290 CERROR("Error %d reading connection request from %pI4h\n",
@@ -330,7 +330,7 @@ lnet_acceptor(void *arg)
330 __u32 magic; 330 __u32 magic;
331 __u32 peer_ip; 331 __u32 peer_ip;
332 int peer_port; 332 int peer_port;
333 int secure = (int)((long_ptr_t)arg); 333 int secure = (int)((long)arg);
334 334
335 LASSERT(!lnet_acceptor_state.pta_sock); 335 LASSERT(!lnet_acceptor_state.pta_sock);
336 336
@@ -459,7 +459,7 @@ lnet_acceptor_start(void)
459 if (!lnet_count_acceptor_nis()) /* not required */ 459 if (!lnet_count_acceptor_nis()) /* not required */
460 return 0; 460 return 0;
461 461
462 task = kthread_run(lnet_acceptor, (void *)(ulong_ptr_t)secure, 462 task = kthread_run(lnet_acceptor, (void *)(uintptr_t)secure,
463 "acceptor_%03ld", secure); 463 "acceptor_%03ld", secure);
464 if (IS_ERR(task)) { 464 if (IS_ERR(task)) {
465 rc2 = PTR_ERR(task); 465 rc2 = PTR_ERR(task);
diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c
index b2ba10d59f84..08b38ef67784 100644
--- a/drivers/staging/lustre/lnet/lnet/api-ni.c
+++ b/drivers/staging/lustre/lnet/lnet/api-ni.c
@@ -180,89 +180,89 @@ static void lnet_assert_wire_constants(void)
180 */ 180 */
181 181
182 /* Constants... */ 182 /* Constants... */
183 CLASSERT(LNET_PROTO_TCP_MAGIC == 0xeebc0ded); 183 BUILD_BUG_ON(LNET_PROTO_TCP_MAGIC != 0xeebc0ded);
184 CLASSERT(LNET_PROTO_TCP_VERSION_MAJOR == 1); 184 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MAJOR != 1);
185 CLASSERT(LNET_PROTO_TCP_VERSION_MINOR == 0); 185 BUILD_BUG_ON(LNET_PROTO_TCP_VERSION_MINOR != 0);
186 CLASSERT(LNET_MSG_ACK == 0); 186 BUILD_BUG_ON(LNET_MSG_ACK != 0);
187 CLASSERT(LNET_MSG_PUT == 1); 187 BUILD_BUG_ON(LNET_MSG_PUT != 1);
188 CLASSERT(LNET_MSG_GET == 2); 188 BUILD_BUG_ON(LNET_MSG_GET != 2);
189 CLASSERT(LNET_MSG_REPLY == 3); 189 BUILD_BUG_ON(LNET_MSG_REPLY != 3);
190 CLASSERT(LNET_MSG_HELLO == 4); 190 BUILD_BUG_ON(LNET_MSG_HELLO != 4);
191 191
192 /* Checks for struct ptl_handle_wire_t */ 192 /* Checks for struct ptl_handle_wire_t */
193 CLASSERT((int)sizeof(lnet_handle_wire_t) == 16); 193 BUILD_BUG_ON((int)sizeof(struct lnet_handle_wire) != 16);
194 CLASSERT((int)offsetof(lnet_handle_wire_t, wh_interface_cookie) == 0); 194 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire, wh_interface_cookie) != 0);
195 CLASSERT((int)sizeof(((lnet_handle_wire_t *)0)->wh_interface_cookie) == 8); 195 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_interface_cookie) != 8);
196 CLASSERT((int)offsetof(lnet_handle_wire_t, wh_object_cookie) == 8); 196 BUILD_BUG_ON((int)offsetof(struct lnet_handle_wire, wh_object_cookie) != 8);
197 CLASSERT((int)sizeof(((lnet_handle_wire_t *)0)->wh_object_cookie) == 8); 197 BUILD_BUG_ON((int)sizeof(((struct lnet_handle_wire *)0)->wh_object_cookie) != 8);
198 198
199 /* Checks for struct lnet_magicversion_t */ 199 /* Checks for struct struct lnet_magicversion */
200 CLASSERT((int)sizeof(lnet_magicversion_t) == 8); 200 BUILD_BUG_ON((int)sizeof(struct lnet_magicversion) != 8);
201 CLASSERT((int)offsetof(lnet_magicversion_t, magic) == 0); 201 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, magic) != 0);
202 CLASSERT((int)sizeof(((lnet_magicversion_t *)0)->magic) == 4); 202 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->magic) != 4);
203 CLASSERT((int)offsetof(lnet_magicversion_t, version_major) == 4); 203 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_major) != 4);
204 CLASSERT((int)sizeof(((lnet_magicversion_t *)0)->version_major) == 2); 204 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_major) != 2);
205 CLASSERT((int)offsetof(lnet_magicversion_t, version_minor) == 6); 205 BUILD_BUG_ON((int)offsetof(struct lnet_magicversion, version_minor) != 6);
206 CLASSERT((int)sizeof(((lnet_magicversion_t *)0)->version_minor) == 2); 206 BUILD_BUG_ON((int)sizeof(((struct lnet_magicversion *)0)->version_minor) != 2);
207 207
208 /* Checks for struct lnet_hdr_t */ 208 /* Checks for struct struct lnet_hdr */
209 CLASSERT((int)sizeof(lnet_hdr_t) == 72); 209 BUILD_BUG_ON((int)sizeof(struct lnet_hdr) != 72);
210 CLASSERT((int)offsetof(lnet_hdr_t, dest_nid) == 0); 210 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_nid) != 0);
211 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->dest_nid) == 8); 211 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_nid) != 8);
212 CLASSERT((int)offsetof(lnet_hdr_t, src_nid) == 8); 212 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_nid) != 8);
213 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->src_nid) == 8); 213 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_nid) != 8);
214 CLASSERT((int)offsetof(lnet_hdr_t, dest_pid) == 16); 214 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, dest_pid) != 16);
215 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->dest_pid) == 4); 215 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->dest_pid) != 4);
216 CLASSERT((int)offsetof(lnet_hdr_t, src_pid) == 20); 216 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, src_pid) != 20);
217 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->src_pid) == 4); 217 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->src_pid) != 4);
218 CLASSERT((int)offsetof(lnet_hdr_t, type) == 24); 218 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, type) != 24);
219 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->type) == 4); 219 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->type) != 4);
220 CLASSERT((int)offsetof(lnet_hdr_t, payload_length) == 28); 220 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, payload_length) != 28);
221 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->payload_length) == 4); 221 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->payload_length) != 4);
222 CLASSERT((int)offsetof(lnet_hdr_t, msg) == 32); 222 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg) != 32);
223 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg) == 40); 223 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg) != 40);
224 224
225 /* Ack */ 225 /* Ack */
226 CLASSERT((int)offsetof(lnet_hdr_t, msg.ack.dst_wmd) == 32); 226 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.dst_wmd) != 32);
227 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.ack.dst_wmd) == 16); 227 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.dst_wmd) != 16);
228 CLASSERT((int)offsetof(lnet_hdr_t, msg.ack.match_bits) == 48); 228 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.match_bits) != 48);
229 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.ack.match_bits) == 8); 229 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.match_bits) != 8);
230 CLASSERT((int)offsetof(lnet_hdr_t, msg.ack.mlength) == 56); 230 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.ack.mlength) != 56);
231 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.ack.mlength) == 4); 231 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.ack.mlength) != 4);
232 232
233 /* Put */ 233 /* Put */
234 CLASSERT((int)offsetof(lnet_hdr_t, msg.put.ack_wmd) == 32); 234 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ack_wmd) != 32);
235 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.put.ack_wmd) == 16); 235 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ack_wmd) != 16);
236 CLASSERT((int)offsetof(lnet_hdr_t, msg.put.match_bits) == 48); 236 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.match_bits) != 48);
237 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.put.match_bits) == 8); 237 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.match_bits) != 8);
238 CLASSERT((int)offsetof(lnet_hdr_t, msg.put.hdr_data) == 56); 238 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.hdr_data) != 56);
239 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.put.hdr_data) == 8); 239 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.hdr_data) != 8);
240 CLASSERT((int)offsetof(lnet_hdr_t, msg.put.ptl_index) == 64); 240 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.ptl_index) != 64);
241 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.put.ptl_index) == 4); 241 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.ptl_index) != 4);
242 CLASSERT((int)offsetof(lnet_hdr_t, msg.put.offset) == 68); 242 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.put.offset) != 68);
243 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.put.offset) == 4); 243 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.put.offset) != 4);
244 244
245 /* Get */ 245 /* Get */
246 CLASSERT((int)offsetof(lnet_hdr_t, msg.get.return_wmd) == 32); 246 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.return_wmd) != 32);
247 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.get.return_wmd) == 16); 247 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.return_wmd) != 16);
248 CLASSERT((int)offsetof(lnet_hdr_t, msg.get.match_bits) == 48); 248 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.match_bits) != 48);
249 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.get.match_bits) == 8); 249 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.match_bits) != 8);
250 CLASSERT((int)offsetof(lnet_hdr_t, msg.get.ptl_index) == 56); 250 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.ptl_index) != 56);
251 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.get.ptl_index) == 4); 251 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.ptl_index) != 4);
252 CLASSERT((int)offsetof(lnet_hdr_t, msg.get.src_offset) == 60); 252 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.src_offset) != 60);
253 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.get.src_offset) == 4); 253 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.src_offset) != 4);
254 CLASSERT((int)offsetof(lnet_hdr_t, msg.get.sink_length) == 64); 254 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.get.sink_length) != 64);
255 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.get.sink_length) == 4); 255 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.get.sink_length) != 4);
256 256
257 /* Reply */ 257 /* Reply */
258 CLASSERT((int)offsetof(lnet_hdr_t, msg.reply.dst_wmd) == 32); 258 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.reply.dst_wmd) != 32);
259 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.reply.dst_wmd) == 16); 259 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.reply.dst_wmd) != 16);
260 260
261 /* Hello */ 261 /* Hello */
262 CLASSERT((int)offsetof(lnet_hdr_t, msg.hello.incarnation) == 32); 262 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.incarnation) != 32);
263 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.hello.incarnation) == 8); 263 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.incarnation) != 8);
264 CLASSERT((int)offsetof(lnet_hdr_t, msg.hello.type) == 40); 264 BUILD_BUG_ON((int)offsetof(struct lnet_hdr, msg.hello.type) != 40);
265 CLASSERT((int)sizeof(((lnet_hdr_t *)0)->msg.hello.type) == 4); 265 BUILD_BUG_ON((int)sizeof(((struct lnet_hdr *)0)->msg.hello.type) != 4);
266} 266}
267 267
268static lnd_t * 268static lnd_t *
@@ -822,13 +822,13 @@ lnet_count_acceptor_nis(void)
822 return count; 822 return count;
823} 823}
824 824
825static lnet_ping_info_t * 825static struct lnet_ping_info *
826lnet_ping_info_create(int num_ni) 826lnet_ping_info_create(int num_ni)
827{ 827{
828 lnet_ping_info_t *ping_info; 828 struct lnet_ping_info *ping_info;
829 unsigned int infosz; 829 unsigned int infosz;
830 830
831 infosz = offsetof(lnet_ping_info_t, pi_ni[num_ni]); 831 infosz = offsetof(struct lnet_ping_info, pi_ni[num_ni]);
832 LIBCFS_ALLOC(ping_info, infosz); 832 LIBCFS_ALLOC(ping_info, infosz);
833 if (!ping_info) { 833 if (!ping_info) {
834 CERROR("Can't allocate ping info[%d]\n", num_ni); 834 CERROR("Can't allocate ping info[%d]\n", num_ni);
@@ -860,10 +860,10 @@ lnet_get_ni_count(void)
860} 860}
861 861
862static inline void 862static inline void
863lnet_ping_info_free(lnet_ping_info_t *pinfo) 863lnet_ping_info_free(struct lnet_ping_info *pinfo)
864{ 864{
865 LIBCFS_FREE(pinfo, 865 LIBCFS_FREE(pinfo,
866 offsetof(lnet_ping_info_t, 866 offsetof(struct lnet_ping_info,
867 pi_ni[pinfo->pi_nnis])); 867 pi_ni[pinfo->pi_nnis]));
868} 868}
869 869
@@ -889,14 +889,14 @@ lnet_ping_info_destroy(void)
889static void 889static void
890lnet_ping_event_handler(lnet_event_t *event) 890lnet_ping_event_handler(lnet_event_t *event)
891{ 891{
892 lnet_ping_info_t *pinfo = event->md.user_ptr; 892 struct lnet_ping_info *pinfo = event->md.user_ptr;
893 893
894 if (event->unlinked) 894 if (event->unlinked)
895 pinfo->pi_features = LNET_PING_FEAT_INVAL; 895 pinfo->pi_features = LNET_PING_FEAT_INVAL;
896} 896}
897 897
898static int 898static int
899lnet_ping_info_setup(lnet_ping_info_t **ppinfo, lnet_handle_md_t *md_handle, 899lnet_ping_info_setup(struct lnet_ping_info **ppinfo, lnet_handle_md_t *md_handle,
900 int ni_count, bool set_eq) 900 int ni_count, bool set_eq)
901{ 901{
902 lnet_process_id_t id = {LNET_NID_ANY, LNET_PID_ANY}; 902 lnet_process_id_t id = {LNET_NID_ANY, LNET_PID_ANY};
@@ -930,7 +930,7 @@ lnet_ping_info_setup(lnet_ping_info_t **ppinfo, lnet_handle_md_t *md_handle,
930 930
931 /* initialize md content */ 931 /* initialize md content */
932 md.start = *ppinfo; 932 md.start = *ppinfo;
933 md.length = offsetof(lnet_ping_info_t, 933 md.length = offsetof(struct lnet_ping_info,
934 pi_ni[(*ppinfo)->pi_nnis]); 934 pi_ni[(*ppinfo)->pi_nnis]);
935 md.threshold = LNET_MD_THRESH_INF; 935 md.threshold = LNET_MD_THRESH_INF;
936 md.max_size = 0; 936 md.max_size = 0;
@@ -961,7 +961,7 @@ failed_0:
961} 961}
962 962
963static void 963static void
964lnet_ping_md_unlink(lnet_ping_info_t *pinfo, lnet_handle_md_t *md_handle) 964lnet_ping_md_unlink(struct lnet_ping_info *pinfo, lnet_handle_md_t *md_handle)
965{ 965{
966 sigset_t blocked = cfs_block_allsigs(); 966 sigset_t blocked = cfs_block_allsigs();
967 967
@@ -979,9 +979,9 @@ lnet_ping_md_unlink(lnet_ping_info_t *pinfo, lnet_handle_md_t *md_handle)
979} 979}
980 980
981static void 981static void
982lnet_ping_info_install_locked(lnet_ping_info_t *ping_info) 982lnet_ping_info_install_locked(struct lnet_ping_info *ping_info)
983{ 983{
984 lnet_ni_status_t *ns; 984 struct lnet_ni_status *ns;
985 lnet_ni_t *ni; 985 lnet_ni_t *ni;
986 int i = 0; 986 int i = 0;
987 987
@@ -1003,9 +1003,9 @@ lnet_ping_info_install_locked(lnet_ping_info_t *ping_info)
1003} 1003}
1004 1004
1005static void 1005static void
1006lnet_ping_target_update(lnet_ping_info_t *pinfo, lnet_handle_md_t md_handle) 1006lnet_ping_target_update(struct lnet_ping_info *pinfo, lnet_handle_md_t md_handle)
1007{ 1007{
1008 lnet_ping_info_t *old_pinfo = NULL; 1008 struct lnet_ping_info *old_pinfo = NULL;
1009 lnet_handle_md_t old_md; 1009 lnet_handle_md_t old_md;
1010 1010
1011 /* switch the NIs to point to the new ping info created */ 1011 /* switch the NIs to point to the new ping info created */
@@ -1496,7 +1496,7 @@ LNetNIInit(lnet_pid_t requested_pid)
1496 int im_a_router = 0; 1496 int im_a_router = 0;
1497 int rc; 1497 int rc;
1498 int ni_count; 1498 int ni_count;
1499 lnet_ping_info_t *pinfo; 1499 struct lnet_ping_info *pinfo;
1500 lnet_handle_md_t md_handle; 1500 lnet_handle_md_t md_handle;
1501 struct list_head net_head; 1501 struct list_head net_head;
1502 1502
@@ -1754,7 +1754,7 @@ int
1754lnet_dyn_add_ni(lnet_pid_t requested_pid, struct lnet_ioctl_config_data *conf) 1754lnet_dyn_add_ni(lnet_pid_t requested_pid, struct lnet_ioctl_config_data *conf)
1755{ 1755{
1756 char *nets = conf->cfg_config_u.cfg_net.net_intf; 1756 char *nets = conf->cfg_config_u.cfg_net.net_intf;
1757 lnet_ping_info_t *pinfo; 1757 struct lnet_ping_info *pinfo;
1758 lnet_handle_md_t md_handle; 1758 lnet_handle_md_t md_handle;
1759 struct lnet_ni *ni; 1759 struct lnet_ni *ni;
1760 struct list_head net_head; 1760 struct list_head net_head;
@@ -1834,7 +1834,7 @@ int
1834lnet_dyn_del_ni(__u32 net) 1834lnet_dyn_del_ni(__u32 net)
1835{ 1835{
1836 lnet_ni_t *ni; 1836 lnet_ni_t *ni;
1837 lnet_ping_info_t *pinfo; 1837 struct lnet_ping_info *pinfo;
1838 lnet_handle_md_t md_handle; 1838 lnet_handle_md_t md_handle;
1839 int rc; 1839 int rc;
1840 1840
@@ -2147,7 +2147,7 @@ static int lnet_ping(lnet_process_id_t id, int timeout_ms,
2147 int replied = 0; 2147 int replied = 0;
2148 const int a_long_time = 60000; /* mS */ 2148 const int a_long_time = 60000; /* mS */
2149 int infosz; 2149 int infosz;
2150 lnet_ping_info_t *info; 2150 struct lnet_ping_info *info;
2151 lnet_process_id_t tmpid; 2151 lnet_process_id_t tmpid;
2152 int i; 2152 int i;
2153 int nob; 2153 int nob;
@@ -2155,7 +2155,7 @@ static int lnet_ping(lnet_process_id_t id, int timeout_ms,
2155 int rc2; 2155 int rc2;
2156 sigset_t blocked; 2156 sigset_t blocked;
2157 2157
2158 infosz = offsetof(lnet_ping_info_t, pi_ni[n_ids]); 2158 infosz = offsetof(struct lnet_ping_info, pi_ni[n_ids]);
2159 2159
2160 if (n_ids <= 0 || 2160 if (n_ids <= 0 ||
2161 id.nid == LNET_NID_ANY || 2161 id.nid == LNET_NID_ANY ||
@@ -2283,18 +2283,18 @@ static int lnet_ping(lnet_process_id_t id, int timeout_ms,
2283 goto out_1; 2283 goto out_1;
2284 } 2284 }
2285 2285
2286 if (nob < offsetof(lnet_ping_info_t, pi_ni[0])) { 2286 if (nob < offsetof(struct lnet_ping_info, pi_ni[0])) {
2287 CERROR("%s: Short reply %d(%d min)\n", libcfs_id2str(id), 2287 CERROR("%s: Short reply %d(%d min)\n", libcfs_id2str(id),
2288 nob, (int)offsetof(lnet_ping_info_t, pi_ni[0])); 2288 nob, (int)offsetof(struct lnet_ping_info, pi_ni[0]));
2289 goto out_1; 2289 goto out_1;
2290 } 2290 }
2291 2291
2292 if (info->pi_nnis < n_ids) 2292 if (info->pi_nnis < n_ids)
2293 n_ids = info->pi_nnis; 2293 n_ids = info->pi_nnis;
2294 2294
2295 if (nob < offsetof(lnet_ping_info_t, pi_ni[n_ids])) { 2295 if (nob < offsetof(struct lnet_ping_info, pi_ni[n_ids])) {
2296 CERROR("%s: Short reply %d(%d expected)\n", libcfs_id2str(id), 2296 CERROR("%s: Short reply %d(%d expected)\n", libcfs_id2str(id),
2297 nob, (int)offsetof(lnet_ping_info_t, pi_ni[n_ids])); 2297 nob, (int)offsetof(struct lnet_ping_info, pi_ni[n_ids]));
2298 goto out_1; 2298 goto out_1;
2299 } 2299 }
2300 2300
diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c
index f3dd6e42f4d4..6b0be6c23fff 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-move.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-move.c
@@ -641,7 +641,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
641 !list_empty(&lp->lp_txq)); 641 !list_empty(&lp->lp_txq));
642 642
643 msg->msg_peertxcredit = 1; 643 msg->msg_peertxcredit = 1;
644 lp->lp_txqnob += msg->msg_len + sizeof(lnet_hdr_t); 644 lp->lp_txqnob += msg->msg_len + sizeof(struct lnet_hdr);
645 lp->lp_txcredits--; 645 lp->lp_txcredits--;
646 646
647 if (lp->lp_txcredits < lp->lp_mintxcredits) 647 if (lp->lp_txcredits < lp->lp_mintxcredits)
@@ -811,7 +811,7 @@ lnet_return_tx_credits_locked(lnet_msg_t *msg)
811 LASSERT((txpeer->lp_txcredits < 0) == 811 LASSERT((txpeer->lp_txcredits < 0) ==
812 !list_empty(&txpeer->lp_txq)); 812 !list_empty(&txpeer->lp_txq));
813 813
814 txpeer->lp_txqnob -= msg->msg_len + sizeof(lnet_hdr_t); 814 txpeer->lp_txqnob -= msg->msg_len + sizeof(struct lnet_hdr);
815 LASSERT(txpeer->lp_txqnob >= 0); 815 LASSERT(txpeer->lp_txqnob >= 0);
816 816
817 txpeer->lp_txcredits++; 817 txpeer->lp_txcredits++;
@@ -1245,7 +1245,7 @@ lnet_drop_message(lnet_ni_t *ni, int cpt, void *private, unsigned int nob)
1245static void 1245static void
1246lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg) 1246lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg)
1247{ 1247{
1248 lnet_hdr_t *hdr = &msg->msg_hdr; 1248 struct lnet_hdr *hdr = &msg->msg_hdr;
1249 1249
1250 if (msg->msg_wanted) 1250 if (msg->msg_wanted)
1251 lnet_setpayloadbuffer(msg); 1251 lnet_setpayloadbuffer(msg);
@@ -1266,7 +1266,7 @@ lnet_recv_put(lnet_ni_t *ni, lnet_msg_t *msg)
1266static int 1266static int
1267lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg) 1267lnet_parse_put(lnet_ni_t *ni, lnet_msg_t *msg)
1268{ 1268{
1269 lnet_hdr_t *hdr = &msg->msg_hdr; 1269 struct lnet_hdr *hdr = &msg->msg_hdr;
1270 struct lnet_match_info info; 1270 struct lnet_match_info info;
1271 bool ready_delay; 1271 bool ready_delay;
1272 int rc; 1272 int rc;
@@ -1325,8 +1325,8 @@ static int
1325lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get) 1325lnet_parse_get(lnet_ni_t *ni, lnet_msg_t *msg, int rdma_get)
1326{ 1326{
1327 struct lnet_match_info info; 1327 struct lnet_match_info info;
1328 lnet_hdr_t *hdr = &msg->msg_hdr; 1328 struct lnet_hdr *hdr = &msg->msg_hdr;
1329 lnet_handle_wire_t reply_wmd; 1329 struct lnet_handle_wire reply_wmd;
1330 int rc; 1330 int rc;
1331 1331
1332 /* Convert get fields to host byte order */ 1332 /* Convert get fields to host byte order */
@@ -1389,7 +1389,7 @@ static int
1389lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg) 1389lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1390{ 1390{
1391 void *private = msg->msg_private; 1391 void *private = msg->msg_private;
1392 lnet_hdr_t *hdr = &msg->msg_hdr; 1392 struct lnet_hdr *hdr = &msg->msg_hdr;
1393 lnet_process_id_t src = {0}; 1393 lnet_process_id_t src = {0};
1394 lnet_libmd_t *md; 1394 lnet_libmd_t *md;
1395 int rlength; 1395 int rlength;
@@ -1453,7 +1453,7 @@ lnet_parse_reply(lnet_ni_t *ni, lnet_msg_t *msg)
1453static int 1453static int
1454lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg) 1454lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
1455{ 1455{
1456 lnet_hdr_t *hdr = &msg->msg_hdr; 1456 struct lnet_hdr *hdr = &msg->msg_hdr;
1457 lnet_process_id_t src = {0}; 1457 lnet_process_id_t src = {0};
1458 lnet_libmd_t *md; 1458 lnet_libmd_t *md;
1459 int cpt; 1459 int cpt;
@@ -1576,7 +1576,7 @@ lnet_msgtyp2str(int type)
1576} 1576}
1577 1577
1578void 1578void
1579lnet_print_hdr(lnet_hdr_t *hdr) 1579lnet_print_hdr(struct lnet_hdr *hdr)
1580{ 1580{
1581 lnet_process_id_t src = {0}; 1581 lnet_process_id_t src = {0};
1582 lnet_process_id_t dst = {0}; 1582 lnet_process_id_t dst = {0};
@@ -1634,7 +1634,7 @@ lnet_print_hdr(lnet_hdr_t *hdr)
1634} 1634}
1635 1635
1636int 1636int
1637lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid, 1637lnet_parse(lnet_ni_t *ni, struct lnet_hdr *hdr, lnet_nid_t from_nid,
1638 void *private, int rdma_req) 1638 void *private, int rdma_req)
1639{ 1639{
1640 int rc = 0; 1640 int rc = 0;
diff --git a/drivers/staging/lustre/lnet/lnet/lib-msg.c b/drivers/staging/lustre/lnet/lnet/lib-msg.c
index 0897e588bd54..7ee164e67fbe 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-msg.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-msg.c
@@ -56,7 +56,7 @@ lnet_build_unlink_event(lnet_libmd_t *md, lnet_event_t *ev)
56void 56void
57lnet_build_msg_event(lnet_msg_t *msg, lnet_event_kind_t ev_type) 57lnet_build_msg_event(lnet_msg_t *msg, lnet_event_kind_t ev_type)
58{ 58{
59 lnet_hdr_t *hdr = &msg->msg_hdr; 59 struct lnet_hdr *hdr = &msg->msg_hdr;
60 lnet_event_t *ev = &msg->msg_ev; 60 lnet_event_t *ev = &msg->msg_ev;
61 61
62 LASSERT(!msg->msg_routing); 62 LASSERT(!msg->msg_routing);
@@ -361,7 +361,7 @@ lnet_msg_detach_md(lnet_msg_t *msg, int status)
361static int 361static int
362lnet_complete_msg_locked(lnet_msg_t *msg, int cpt) 362lnet_complete_msg_locked(lnet_msg_t *msg, int cpt)
363{ 363{
364 lnet_handle_wire_t ack_wmd; 364 struct lnet_handle_wire ack_wmd;
365 int rc; 365 int rc;
366 int status = msg->msg_ev.status; 366 int status = msg->msg_ev.status;
367 367
diff --git a/drivers/staging/lustre/lnet/lnet/lib-ptl.c b/drivers/staging/lustre/lnet/lnet/lib-ptl.c
index 3947e8b711c0..fa515af2ac1d 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-ptl.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-ptl.c
@@ -680,7 +680,7 @@ lnet_ptl_attach_md(lnet_me_t *me, lnet_libmd_t *md,
680 again: 680 again:
681 list_for_each_entry_safe(msg, tmp, head, msg_list) { 681 list_for_each_entry_safe(msg, tmp, head, msg_list) {
682 struct lnet_match_info info; 682 struct lnet_match_info info;
683 lnet_hdr_t *hdr; 683 struct lnet_hdr *hdr;
684 int rc; 684 int rc;
685 685
686 LASSERT(msg->msg_rx_delayed || head == &ptl->ptl_msg_stealing); 686 LASSERT(msg->msg_rx_delayed || head == &ptl->ptl_msg_stealing);
diff --git a/drivers/staging/lustre/lnet/lnet/lib-socket.c b/drivers/staging/lustre/lnet/lnet/lib-socket.c
index 4e6dd5149b4f..b7b87ecefcdf 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-socket.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-socket.c
@@ -97,7 +97,7 @@ lnet_ipif_query(char *name, int *up, __u32 *ip, __u32 *mask)
97 return -EINVAL; 97 return -EINVAL;
98 } 98 }
99 99
100 CLASSERT(sizeof(ifr.ifr_name) >= IFNAMSIZ); 100 BUILD_BUG_ON(sizeof(ifr.ifr_name) < IFNAMSIZ);
101 101
102 if (strlen(name) > sizeof(ifr.ifr_name) - 1) 102 if (strlen(name) > sizeof(ifr.ifr_name) - 1)
103 return -E2BIG; 103 return -E2BIG;
@@ -393,8 +393,10 @@ lnet_sock_create(struct socket **sockp, int *fatal, __u32 local_ip,
393 memset(&locaddr, 0, sizeof(locaddr)); 393 memset(&locaddr, 0, sizeof(locaddr));
394 locaddr.sin_family = AF_INET; 394 locaddr.sin_family = AF_INET;
395 locaddr.sin_port = htons(local_port); 395 locaddr.sin_port = htons(local_port);
396 locaddr.sin_addr.s_addr = !local_ip ? 396 if (!local_ip)
397 INADDR_ANY : htonl(local_ip); 397 locaddr.sin_addr.s_addr = htonl(INADDR_ANY);
398 else
399 locaddr.sin_addr.s_addr = htonl(local_ip);
398 400
399 rc = kernel_bind(sock, (struct sockaddr *)&locaddr, 401 rc = kernel_bind(sock, (struct sockaddr *)&locaddr,
400 sizeof(locaddr)); 402 sizeof(locaddr));
diff --git a/drivers/staging/lustre/lnet/lnet/net_fault.c b/drivers/staging/lustre/lnet/lnet/net_fault.c
index e4aceb71c4ec..18183cbb9859 100644
--- a/drivers/staging/lustre/lnet/lnet/net_fault.c
+++ b/drivers/staging/lustre/lnet/lnet/net_fault.c
@@ -349,7 +349,7 @@ drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src,
349 * Check if message from \a src to \a dst can match any existed drop rule 349 * Check if message from \a src to \a dst can match any existed drop rule
350 */ 350 */
351bool 351bool
352lnet_drop_rule_match(lnet_hdr_t *hdr) 352lnet_drop_rule_match(struct lnet_hdr *hdr)
353{ 353{
354 struct lnet_drop_rule *rule; 354 struct lnet_drop_rule *rule;
355 lnet_nid_t src = le64_to_cpu(hdr->src_nid); 355 lnet_nid_t src = le64_to_cpu(hdr->src_nid);
@@ -530,7 +530,7 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t src,
530 * will be delayed if there is a match. 530 * will be delayed if there is a match.
531 */ 531 */
532bool 532bool
533lnet_delay_rule_match_locked(lnet_hdr_t *hdr, struct lnet_msg *msg) 533lnet_delay_rule_match_locked(struct lnet_hdr *hdr, struct lnet_msg *msg)
534{ 534{
535 struct lnet_delay_rule *rule; 535 struct lnet_delay_rule *rule;
536 lnet_nid_t src = le64_to_cpu(hdr->src_nid); 536 lnet_nid_t src = le64_to_cpu(hdr->src_nid);
@@ -997,10 +997,10 @@ lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data)
997int 997int
998lnet_fault_init(void) 998lnet_fault_init(void)
999{ 999{
1000 CLASSERT(LNET_PUT_BIT == 1 << LNET_MSG_PUT); 1000 BUILD_BUG_ON(LNET_PUT_BIT != 1 << LNET_MSG_PUT);
1001 CLASSERT(LNET_ACK_BIT == 1 << LNET_MSG_ACK); 1001 BUILD_BUG_ON(LNET_ACK_BIT != 1 << LNET_MSG_ACK);
1002 CLASSERT(LNET_GET_BIT == 1 << LNET_MSG_GET); 1002 BUILD_BUG_ON(LNET_GET_BIT != 1 << LNET_MSG_GET);
1003 CLASSERT(LNET_REPLY_BIT == 1 << LNET_MSG_REPLY); 1003 BUILD_BUG_ON(LNET_REPLY_BIT != 1 << LNET_MSG_REPLY);
1004 1004
1005 mutex_init(&delay_dd.dd_mutex); 1005 mutex_init(&delay_dd.dd_mutex);
1006 spin_lock_init(&delay_dd.dd_lock); 1006 spin_lock_init(&delay_dd.dd_lock);
diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c
index 8afa0abf15cd..cf22525d7129 100644
--- a/drivers/staging/lustre/lnet/lnet/router.c
+++ b/drivers/staging/lustre/lnet/lnet/router.c
@@ -621,10 +621,10 @@ lnet_get_route(int idx, __u32 *net, __u32 *hops,
621} 621}
622 622
623void 623void
624lnet_swap_pinginfo(lnet_ping_info_t *info) 624lnet_swap_pinginfo(struct lnet_ping_info *info)
625{ 625{
626 int i; 626 int i;
627 lnet_ni_status_t *stat; 627 struct lnet_ni_status *stat;
628 628
629 __swab32s(&info->pi_magic); 629 __swab32s(&info->pi_magic);
630 __swab32s(&info->pi_features); 630 __swab32s(&info->pi_features);
@@ -644,7 +644,7 @@ lnet_swap_pinginfo(lnet_ping_info_t *info)
644static void 644static void
645lnet_parse_rc_info(lnet_rc_data_t *rcd) 645lnet_parse_rc_info(lnet_rc_data_t *rcd)
646{ 646{
647 lnet_ping_info_t *info = rcd->rcd_pinginfo; 647 struct lnet_ping_info *info = rcd->rcd_pinginfo;
648 struct lnet_peer *gw = rcd->rcd_gateway; 648 struct lnet_peer *gw = rcd->rcd_gateway;
649 lnet_route_t *rte; 649 lnet_route_t *rte;
650 650
@@ -683,7 +683,7 @@ lnet_parse_rc_info(lnet_rc_data_t *rcd)
683 } 683 }
684 684
685 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) { 685 for (i = 0; i < info->pi_nnis && i < LNET_MAX_RTR_NIS; i++) {
686 lnet_ni_status_t *stat = &info->pi_ni[i]; 686 struct lnet_ni_status *stat = &info->pi_ni[i];
687 lnet_nid_t nid = stat->ns_nid; 687 lnet_nid_t nid = stat->ns_nid;
688 688
689 if (nid == LNET_NID_ANY) { 689 if (nid == LNET_NID_ANY) {
@@ -902,7 +902,7 @@ static lnet_rc_data_t *
902lnet_create_rc_data_locked(lnet_peer_t *gateway) 902lnet_create_rc_data_locked(lnet_peer_t *gateway)
903{ 903{
904 lnet_rc_data_t *rcd = NULL; 904 lnet_rc_data_t *rcd = NULL;
905 lnet_ping_info_t *pi; 905 struct lnet_ping_info *pi;
906 lnet_md_t md; 906 lnet_md_t md;
907 int rc; 907 int rc;
908 int i; 908 int i;
diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c
index 65f65a3fc901..a19e1405e3ea 100644
--- a/drivers/staging/lustre/lnet/lnet/router_proc.c
+++ b/drivers/staging/lustre/lnet/lnet/router_proc.c
@@ -139,7 +139,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write,
139 int ver; 139 int ver;
140 int off; 140 int off;
141 141
142 CLASSERT(sizeof(loff_t) >= 4); 142 BUILD_BUG_ON(sizeof(loff_t) < 4);
143 143
144 off = LNET_PROC_HOFF_GET(*ppos); 144 off = LNET_PROC_HOFF_GET(*ppos);
145 ver = LNET_PROC_VER_GET(*ppos); 145 ver = LNET_PROC_VER_GET(*ppos);
@@ -404,7 +404,7 @@ static int proc_lnet_peers(struct ctl_table *table, int write,
404 int rc = 0; 404 int rc = 0;
405 int len; 405 int len;
406 406
407 CLASSERT(LNET_PROC_HASH_BITS >= LNET_PEER_HASH_BITS); 407 BUILD_BUG_ON(LNET_PROC_HASH_BITS < LNET_PEER_HASH_BITS);
408 LASSERT(!write); 408 LASSERT(!write);
409 409
410 if (!*lenp) 410 if (!*lenp)
diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
index 67b460f41d6e..b9ac34ecbd53 100644
--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
@@ -136,7 +136,7 @@ brw_client_init(struct sfw_test_instance *tsi)
136 return 0; 136 return 0;
137} 137}
138 138
139int brw_inject_one_error(void) 139static int brw_inject_one_error(void)
140{ 140{
141 struct timespec64 ts; 141 struct timespec64 ts;
142 142
diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c
index 94383023c1be..6ca7192b03b7 100644
--- a/drivers/staging/lustre/lnet/selftest/conctl.c
+++ b/drivers/staging/lustre/lnet/selftest/conctl.c
@@ -42,7 +42,7 @@
42#include "console.h" 42#include "console.h"
43 43
44static int 44static int
45lst_session_new_ioctl(lstio_session_new_args_t *args) 45lst_session_new_ioctl(struct lstio_session_new_args *args)
46{ 46{
47 char *name; 47 char *name;
48 int rc; 48 int rc;
@@ -78,7 +78,7 @@ lst_session_new_ioctl(lstio_session_new_args_t *args)
78} 78}
79 79
80static int 80static int
81lst_session_end_ioctl(lstio_session_end_args_t *args) 81lst_session_end_ioctl(struct lstio_session_end_args *args)
82{ 82{
83 if (args->lstio_ses_key != console_session.ses_key) 83 if (args->lstio_ses_key != console_session.ses_key)
84 return -EACCES; 84 return -EACCES;
@@ -87,7 +87,7 @@ lst_session_end_ioctl(lstio_session_end_args_t *args)
87} 87}
88 88
89static int 89static int
90lst_session_info_ioctl(lstio_session_info_args_t *args) 90lst_session_info_ioctl(struct lstio_session_info_args *args)
91{ 91{
92 /* no checking of key */ 92 /* no checking of key */
93 93
@@ -109,7 +109,7 @@ lst_session_info_ioctl(lstio_session_info_args_t *args)
109} 109}
110 110
111static int 111static int
112lst_debug_ioctl(lstio_debug_args_t *args) 112lst_debug_ioctl(struct lstio_debug_args *args)
113{ 113{
114 char *name = NULL; 114 char *name = NULL;
115 int client = 1; 115 int client = 1;
@@ -190,7 +190,7 @@ out:
190} 190}
191 191
192static int 192static int
193lst_group_add_ioctl(lstio_group_add_args_t *args) 193lst_group_add_ioctl(struct lstio_group_add_args *args)
194{ 194{
195 char *name; 195 char *name;
196 int rc; 196 int rc;
@@ -223,7 +223,7 @@ lst_group_add_ioctl(lstio_group_add_args_t *args)
223} 223}
224 224
225static int 225static int
226lst_group_del_ioctl(lstio_group_del_args_t *args) 226lst_group_del_ioctl(struct lstio_group_del_args *args)
227{ 227{
228 int rc; 228 int rc;
229 char *name; 229 char *name;
@@ -256,7 +256,7 @@ lst_group_del_ioctl(lstio_group_del_args_t *args)
256} 256}
257 257
258static int 258static int
259lst_group_update_ioctl(lstio_group_update_args_t *args) 259lst_group_update_ioctl(struct lstio_group_update_args *args)
260{ 260{
261 int rc; 261 int rc;
262 char *name; 262 char *name;
@@ -313,7 +313,7 @@ lst_group_update_ioctl(lstio_group_update_args_t *args)
313} 313}
314 314
315static int 315static int
316lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) 316lst_nodes_add_ioctl(struct lstio_group_nodes_args *args)
317{ 317{
318 unsigned int feats; 318 unsigned int feats;
319 int rc; 319 int rc;
@@ -358,7 +358,7 @@ lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
358} 358}
359 359
360static int 360static int
361lst_group_list_ioctl(lstio_group_list_args_t *args) 361lst_group_list_ioctl(struct lstio_group_list_args *args)
362{ 362{
363 if (args->lstio_grp_key != console_session.ses_key) 363 if (args->lstio_grp_key != console_session.ses_key)
364 return -EACCES; 364 return -EACCES;
@@ -375,7 +375,7 @@ lst_group_list_ioctl(lstio_group_list_args_t *args)
375} 375}
376 376
377static int 377static int
378lst_group_info_ioctl(lstio_group_info_args_t *args) 378lst_group_info_ioctl(struct lstio_group_info_args *args)
379{ 379{
380 char *name; 380 char *name;
381 int ndent; 381 int ndent;
@@ -438,7 +438,7 @@ lst_group_info_ioctl(lstio_group_info_args_t *args)
438} 438}
439 439
440static int 440static int
441lst_batch_add_ioctl(lstio_batch_add_args_t *args) 441lst_batch_add_ioctl(struct lstio_batch_add_args *args)
442{ 442{
443 int rc; 443 int rc;
444 char *name; 444 char *name;
@@ -471,7 +471,7 @@ lst_batch_add_ioctl(lstio_batch_add_args_t *args)
471} 471}
472 472
473static int 473static int
474lst_batch_run_ioctl(lstio_batch_run_args_t *args) 474lst_batch_run_ioctl(struct lstio_batch_run_args *args)
475{ 475{
476 int rc; 476 int rc;
477 char *name; 477 char *name;
@@ -505,7 +505,7 @@ lst_batch_run_ioctl(lstio_batch_run_args_t *args)
505} 505}
506 506
507static int 507static int
508lst_batch_stop_ioctl(lstio_batch_stop_args_t *args) 508lst_batch_stop_ioctl(struct lstio_batch_stop_args *args)
509{ 509{
510 int rc; 510 int rc;
511 char *name; 511 char *name;
@@ -540,7 +540,7 @@ lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
540} 540}
541 541
542static int 542static int
543lst_batch_query_ioctl(lstio_batch_query_args_t *args) 543lst_batch_query_ioctl(struct lstio_batch_query_args *args)
544{ 544{
545 char *name; 545 char *name;
546 int rc; 546 int rc;
@@ -581,7 +581,7 @@ lst_batch_query_ioctl(lstio_batch_query_args_t *args)
581} 581}
582 582
583static int 583static int
584lst_batch_list_ioctl(lstio_batch_list_args_t *args) 584lst_batch_list_ioctl(struct lstio_batch_list_args *args)
585{ 585{
586 if (args->lstio_bat_key != console_session.ses_key) 586 if (args->lstio_bat_key != console_session.ses_key)
587 return -EACCES; 587 return -EACCES;
@@ -598,7 +598,7 @@ lst_batch_list_ioctl(lstio_batch_list_args_t *args)
598} 598}
599 599
600static int 600static int
601lst_batch_info_ioctl(lstio_batch_info_args_t *args) 601lst_batch_info_ioctl(struct lstio_batch_info_args *args)
602{ 602{
603 char *name; 603 char *name;
604 int rc; 604 int rc;
@@ -662,7 +662,7 @@ lst_batch_info_ioctl(lstio_batch_info_args_t *args)
662} 662}
663 663
664static int 664static int
665lst_stat_query_ioctl(lstio_stat_args_t *args) 665lst_stat_query_ioctl(struct lstio_stat_args *args)
666{ 666{
667 int rc; 667 int rc;
668 char *name = NULL; 668 char *name = NULL;
@@ -707,7 +707,7 @@ lst_stat_query_ioctl(lstio_stat_args_t *args)
707 return rc; 707 return rc;
708} 708}
709 709
710static int lst_test_add_ioctl(lstio_test_args_t *args) 710static int lst_test_add_ioctl(struct lstio_test_args *args)
711{ 711{
712 char *batch_name; 712 char *batch_name;
713 char *src_name = NULL; 713 char *src_name = NULL;
@@ -851,69 +851,69 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
851 goto out; 851 goto out;
852 } 852 }
853 853
854 memset(&console_session.ses_trans_stat, 0, sizeof(lstcon_trans_stat_t)); 854 memset(&console_session.ses_trans_stat, 0, sizeof(struct lstcon_trans_stat));
855 855
856 switch (opc) { 856 switch (opc) {
857 case LSTIO_SESSION_NEW: 857 case LSTIO_SESSION_NEW:
858 rc = lst_session_new_ioctl((lstio_session_new_args_t *)buf); 858 rc = lst_session_new_ioctl((struct lstio_session_new_args *)buf);
859 break; 859 break;
860 case LSTIO_SESSION_END: 860 case LSTIO_SESSION_END:
861 rc = lst_session_end_ioctl((lstio_session_end_args_t *)buf); 861 rc = lst_session_end_ioctl((struct lstio_session_end_args *)buf);
862 break; 862 break;
863 case LSTIO_SESSION_INFO: 863 case LSTIO_SESSION_INFO:
864 rc = lst_session_info_ioctl((lstio_session_info_args_t *)buf); 864 rc = lst_session_info_ioctl((struct lstio_session_info_args *)buf);
865 break; 865 break;
866 case LSTIO_DEBUG: 866 case LSTIO_DEBUG:
867 rc = lst_debug_ioctl((lstio_debug_args_t *)buf); 867 rc = lst_debug_ioctl((struct lstio_debug_args *)buf);
868 break; 868 break;
869 case LSTIO_GROUP_ADD: 869 case LSTIO_GROUP_ADD:
870 rc = lst_group_add_ioctl((lstio_group_add_args_t *)buf); 870 rc = lst_group_add_ioctl((struct lstio_group_add_args *)buf);
871 break; 871 break;
872 case LSTIO_GROUP_DEL: 872 case LSTIO_GROUP_DEL:
873 rc = lst_group_del_ioctl((lstio_group_del_args_t *)buf); 873 rc = lst_group_del_ioctl((struct lstio_group_del_args *)buf);
874 break; 874 break;
875 case LSTIO_GROUP_UPDATE: 875 case LSTIO_GROUP_UPDATE:
876 rc = lst_group_update_ioctl((lstio_group_update_args_t *)buf); 876 rc = lst_group_update_ioctl((struct lstio_group_update_args *)buf);
877 break; 877 break;
878 case LSTIO_NODES_ADD: 878 case LSTIO_NODES_ADD:
879 rc = lst_nodes_add_ioctl((lstio_group_nodes_args_t *)buf); 879 rc = lst_nodes_add_ioctl((struct lstio_group_nodes_args *)buf);
880 break; 880 break;
881 case LSTIO_GROUP_LIST: 881 case LSTIO_GROUP_LIST:
882 rc = lst_group_list_ioctl((lstio_group_list_args_t *)buf); 882 rc = lst_group_list_ioctl((struct lstio_group_list_args *)buf);
883 break; 883 break;
884 case LSTIO_GROUP_INFO: 884 case LSTIO_GROUP_INFO:
885 rc = lst_group_info_ioctl((lstio_group_info_args_t *)buf); 885 rc = lst_group_info_ioctl((struct lstio_group_info_args *)buf);
886 break; 886 break;
887 case LSTIO_BATCH_ADD: 887 case LSTIO_BATCH_ADD:
888 rc = lst_batch_add_ioctl((lstio_batch_add_args_t *)buf); 888 rc = lst_batch_add_ioctl((struct lstio_batch_add_args *)buf);
889 break; 889 break;
890 case LSTIO_BATCH_START: 890 case LSTIO_BATCH_START:
891 rc = lst_batch_run_ioctl((lstio_batch_run_args_t *)buf); 891 rc = lst_batch_run_ioctl((struct lstio_batch_run_args *)buf);
892 break; 892 break;
893 case LSTIO_BATCH_STOP: 893 case LSTIO_BATCH_STOP:
894 rc = lst_batch_stop_ioctl((lstio_batch_stop_args_t *)buf); 894 rc = lst_batch_stop_ioctl((struct lstio_batch_stop_args *)buf);
895 break; 895 break;
896 case LSTIO_BATCH_QUERY: 896 case LSTIO_BATCH_QUERY:
897 rc = lst_batch_query_ioctl((lstio_batch_query_args_t *)buf); 897 rc = lst_batch_query_ioctl((struct lstio_batch_query_args *)buf);
898 break; 898 break;
899 case LSTIO_BATCH_LIST: 899 case LSTIO_BATCH_LIST:
900 rc = lst_batch_list_ioctl((lstio_batch_list_args_t *)buf); 900 rc = lst_batch_list_ioctl((struct lstio_batch_list_args *)buf);
901 break; 901 break;
902 case LSTIO_BATCH_INFO: 902 case LSTIO_BATCH_INFO:
903 rc = lst_batch_info_ioctl((lstio_batch_info_args_t *)buf); 903 rc = lst_batch_info_ioctl((struct lstio_batch_info_args *)buf);
904 break; 904 break;
905 case LSTIO_TEST_ADD: 905 case LSTIO_TEST_ADD:
906 rc = lst_test_add_ioctl((lstio_test_args_t *)buf); 906 rc = lst_test_add_ioctl((struct lstio_test_args *)buf);
907 break; 907 break;
908 case LSTIO_STAT_QUERY: 908 case LSTIO_STAT_QUERY:
909 rc = lst_stat_query_ioctl((lstio_stat_args_t *)buf); 909 rc = lst_stat_query_ioctl((struct lstio_stat_args *)buf);
910 break; 910 break;
911 default: 911 default:
912 rc = -EINVAL; 912 rc = -EINVAL;
913 } 913 }
914 914
915 if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat, 915 if (copy_to_user(data->ioc_pbuf2, &console_session.ses_trans_stat,
916 sizeof(lstcon_trans_stat_t))) 916 sizeof(struct lstcon_trans_stat)))
917 rc = -EFAULT; 917 rc = -EFAULT;
918out: 918out:
919 mutex_unlock(&console_session.ses_mutex); 919 mutex_unlock(&console_session.ses_mutex);
diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c
index 994422c62487..c6a683bda75e 100644
--- a/drivers/staging/lustre/lnet/selftest/conrpc.c
+++ b/drivers/staging/lustre/lnet/selftest/conrpc.c
@@ -43,7 +43,7 @@
43#include "console.h" 43#include "console.h"
44 44
45void lstcon_rpc_stat_reply(struct lstcon_rpc_trans *, struct srpc_msg *, 45void lstcon_rpc_stat_reply(struct lstcon_rpc_trans *, struct srpc_msg *,
46 struct lstcon_node *, lstcon_trans_stat_t *); 46 struct lstcon_node *, struct lstcon_trans_stat *);
47 47
48static void 48static void
49lstcon_rpc_done(struct srpc_client_rpc *rpc) 49lstcon_rpc_done(struct srpc_client_rpc *rpc)
@@ -420,7 +420,7 @@ lstcon_rpc_get_reply(struct lstcon_rpc *crpc, struct srpc_msg **msgpp)
420} 420}
421 421
422void 422void
423lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans, lstcon_trans_stat_t *stat) 423lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans, struct lstcon_trans_stat *stat)
424{ 424{
425 struct lstcon_rpc *crpc; 425 struct lstcon_rpc *crpc;
426 struct srpc_msg *rep; 426 struct srpc_msg *rep;
@@ -469,7 +469,7 @@ lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
469{ 469{
470 struct list_head tmp; 470 struct list_head tmp;
471 struct list_head __user *next; 471 struct list_head __user *next;
472 lstcon_rpc_ent_t *ent; 472 struct lstcon_rpc_ent *ent;
473 struct srpc_generic_reply *rep; 473 struct srpc_generic_reply *rep;
474 struct lstcon_rpc *crpc; 474 struct lstcon_rpc *crpc;
475 struct srpc_msg *msg; 475 struct srpc_msg *msg;
@@ -492,7 +492,7 @@ lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
492 492
493 next = tmp.next; 493 next = tmp.next;
494 494
495 ent = list_entry(next, lstcon_rpc_ent_t, rpe_link); 495 ent = list_entry(next, struct lstcon_rpc_ent, rpe_link);
496 496
497 LASSERT(crpc->crp_stamp); 497 LASSERT(crpc->crp_stamp);
498 498
@@ -519,7 +519,7 @@ lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
519 /* RPC is done */ 519 /* RPC is done */
520 rep = (struct srpc_generic_reply *)&msg->msg_body.reply; 520 rep = (struct srpc_generic_reply *)&msg->msg_body.reply;
521 521
522 if (copy_to_user(&ent->rpe_sid, &rep->sid, sizeof(lst_sid_t)) || 522 if (copy_to_user(&ent->rpe_sid, &rep->sid, sizeof(rep->sid)) ||
523 copy_to_user(&ent->rpe_fwk_errno, &rep->status, 523 copy_to_user(&ent->rpe_fwk_errno, &rep->status,
524 sizeof(rep->status))) 524 sizeof(rep->status)))
525 return -EFAULT; 525 return -EFAULT;
@@ -698,17 +698,17 @@ lstcon_statrpc_prep(struct lstcon_node *nd, unsigned int feats,
698 return 0; 698 return 0;
699} 699}
700 700
701static lnet_process_id_packed_t * 701static struct lnet_process_id_packed *
702lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov) 702lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
703{ 703{
704 lnet_process_id_packed_t *pid; 704 struct lnet_process_id_packed *pid;
705 int i; 705 int i;
706 706
707 i = idx / SFW_ID_PER_PAGE; 707 i = idx / SFW_ID_PER_PAGE;
708 708
709 LASSERT(i < nkiov); 709 LASSERT(i < nkiov);
710 710
711 pid = (lnet_process_id_packed_t *)page_address(kiov[i].bv_page); 711 pid = (struct lnet_process_id_packed *)page_address(kiov[i].bv_page);
712 712
713 return &pid[idx % SFW_ID_PER_PAGE]; 713 return &pid[idx % SFW_ID_PER_PAGE];
714} 714}
@@ -717,7 +717,7 @@ static int
717lstcon_dstnodes_prep(struct lstcon_group *grp, int idx, 717lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
718 int dist, int span, int nkiov, lnet_kiov_t *kiov) 718 int dist, int span, int nkiov, lnet_kiov_t *kiov)
719{ 719{
720 lnet_process_id_packed_t *pid; 720 struct lnet_process_id_packed *pid;
721 struct lstcon_ndlink *ndl; 721 struct lstcon_ndlink *ndl;
722 struct lstcon_node *nd; 722 struct lstcon_node *nd;
723 int start; 723 int start;
@@ -768,7 +768,7 @@ lstcon_dstnodes_prep(struct lstcon_group *grp, int idx,
768} 768}
769 769
770static int 770static int
771lstcon_pingrpc_prep(lst_test_ping_param_t *param, struct srpc_test_reqst *req) 771lstcon_pingrpc_prep(struct lst_test_ping_param *param, struct srpc_test_reqst *req)
772{ 772{
773 struct test_ping_req *prq = &req->tsr_u.ping; 773 struct test_ping_req *prq = &req->tsr_u.ping;
774 774
@@ -779,7 +779,7 @@ lstcon_pingrpc_prep(lst_test_ping_param_t *param, struct srpc_test_reqst *req)
779} 779}
780 780
781static int 781static int
782lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, 782lstcon_bulkrpc_v0_prep(struct lst_test_bulk_param *param,
783 struct srpc_test_reqst *req) 783 struct srpc_test_reqst *req)
784{ 784{
785 struct test_bulk_req *brq = &req->tsr_u.bulk_v0; 785 struct test_bulk_req *brq = &req->tsr_u.bulk_v0;
@@ -793,7 +793,7 @@ lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param,
793} 793}
794 794
795static int 795static int
796lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, bool is_client, 796lstcon_bulkrpc_v1_prep(struct lst_test_bulk_param *param, bool is_client,
797 struct srpc_test_reqst *req) 797 struct srpc_test_reqst *req)
798{ 798{
799 struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1; 799 struct test_bulk_req_v1 *brq = &req->tsr_u.bulk_v1;
@@ -823,7 +823,7 @@ lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
823 npg = sfw_id_pages(test->tes_span); 823 npg = sfw_id_pages(test->tes_span);
824 nob = !(feats & LST_FEAT_BULK_LEN) ? 824 nob = !(feats & LST_FEAT_BULK_LEN) ?
825 npg * PAGE_SIZE : 825 npg * PAGE_SIZE :
826 sizeof(lnet_process_id_packed_t) * test->tes_span; 826 sizeof(struct lnet_process_id_packed) * test->tes_span;
827 } 827 }
828 828
829 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc); 829 rc = lstcon_rpc_prep(nd, SRPC_SERVICE_TEST, feats, npg, nob, crpc);
@@ -891,17 +891,17 @@ lstcon_testrpc_prep(struct lstcon_node *nd, int transop, unsigned int feats,
891 switch (test->tes_type) { 891 switch (test->tes_type) {
892 case LST_TEST_PING: 892 case LST_TEST_PING:
893 trq->tsr_service = SRPC_SERVICE_PING; 893 trq->tsr_service = SRPC_SERVICE_PING;
894 rc = lstcon_pingrpc_prep((lst_test_ping_param_t *) 894 rc = lstcon_pingrpc_prep((struct lst_test_ping_param *)
895 &test->tes_param[0], trq); 895 &test->tes_param[0], trq);
896 break; 896 break;
897 897
898 case LST_TEST_BULK: 898 case LST_TEST_BULK:
899 trq->tsr_service = SRPC_SERVICE_BRW; 899 trq->tsr_service = SRPC_SERVICE_BRW;
900 if (!(feats & LST_FEAT_BULK_LEN)) { 900 if (!(feats & LST_FEAT_BULK_LEN)) {
901 rc = lstcon_bulkrpc_v0_prep((lst_test_bulk_param_t *) 901 rc = lstcon_bulkrpc_v0_prep((struct lst_test_bulk_param *)
902 &test->tes_param[0], trq); 902 &test->tes_param[0], trq);
903 } else { 903 } else {
904 rc = lstcon_bulkrpc_v1_prep((lst_test_bulk_param_t *) 904 rc = lstcon_bulkrpc_v1_prep((struct lst_test_bulk_param *)
905 &test->tes_param[0], 905 &test->tes_param[0],
906 trq->tsr_is_client, trq); 906 trq->tsr_is_client, trq);
907 } 907 }
@@ -964,7 +964,7 @@ lstcon_sesnew_stat_reply(struct lstcon_rpc_trans *trans,
964 964
965void 965void
966lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg, 966lstcon_rpc_stat_reply(struct lstcon_rpc_trans *trans, struct srpc_msg *msg,
967 struct lstcon_node *nd, lstcon_trans_stat_t *stat) 967 struct lstcon_node *nd, struct lstcon_trans_stat *stat)
968{ 968{
969 struct srpc_rmsn_reply *rmsn_rep; 969 struct srpc_rmsn_reply *rmsn_rep;
970 struct srpc_debug_reply *dbg_rep; 970 struct srpc_debug_reply *dbg_rep;
@@ -1320,7 +1320,7 @@ lstcon_rpc_pinger_stop(void)
1320 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat()); 1320 lstcon_rpc_trans_stat(console_session.ses_ping, lstcon_trans_stat());
1321 lstcon_rpc_trans_destroy(console_session.ses_ping); 1321 lstcon_rpc_trans_destroy(console_session.ses_ping);
1322 1322
1323 memset(lstcon_trans_stat(), 0, sizeof(lstcon_trans_stat_t)); 1323 memset(lstcon_trans_stat(), 0, sizeof(struct lstcon_trans_stat));
1324 1324
1325 console_session.ses_ping = NULL; 1325 console_session.ses_ping = NULL;
1326} 1326}
diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.h b/drivers/staging/lustre/lnet/selftest/conrpc.h
index e629e87c461c..7141d2c902a5 100644
--- a/drivers/staging/lustre/lnet/selftest/conrpc.h
+++ b/drivers/staging/lustre/lnet/selftest/conrpc.h
@@ -103,7 +103,7 @@ struct lstcon_rpc_trans {
103 103
104typedef int (*lstcon_rpc_cond_func_t)(int, struct lstcon_node *, void *); 104typedef int (*lstcon_rpc_cond_func_t)(int, struct lstcon_node *, void *);
105typedef int (*lstcon_rpc_readent_func_t)(int, struct srpc_msg *, 105typedef int (*lstcon_rpc_readent_func_t)(int, struct srpc_msg *,
106 lstcon_rpc_ent_t __user *); 106 struct lstcon_rpc_ent __user *);
107 107
108int lstcon_sesrpc_prep(struct lstcon_node *nd, int transop, 108int lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
109 unsigned int version, struct lstcon_rpc **crpc); 109 unsigned int version, struct lstcon_rpc **crpc);
@@ -125,7 +125,7 @@ int lstcon_rpc_trans_ndlist(struct list_head *ndlist,
125 void *arg, lstcon_rpc_cond_func_t condition, 125 void *arg, lstcon_rpc_cond_func_t condition,
126 struct lstcon_rpc_trans **transpp); 126 struct lstcon_rpc_trans **transpp);
127void lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans, 127void lstcon_rpc_trans_stat(struct lstcon_rpc_trans *trans,
128 lstcon_trans_stat_t *stat); 128 struct lstcon_trans_stat *stat);
129int lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans, 129int lstcon_rpc_trans_interpreter(struct lstcon_rpc_trans *trans,
130 struct list_head __user *head_up, 130 struct list_head __user *head_up,
131 lstcon_rpc_readent_func_t readent); 131 lstcon_rpc_readent_func_t readent);
diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c
index 1456d2395cc9..4e7e5c862c64 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -368,7 +368,7 @@ lstcon_sesrpc_condition(int transop, struct lstcon_node *nd, void *arg)
368 368
369static int 369static int
370lstcon_sesrpc_readent(int transop, struct srpc_msg *msg, 370lstcon_sesrpc_readent(int transop, struct srpc_msg *msg,
371 lstcon_rpc_ent_t __user *ent_up) 371 struct lstcon_rpc_ent __user *ent_up)
372{ 372{
373 struct srpc_debug_reply *rep; 373 struct srpc_debug_reply *rep;
374 374
@@ -741,7 +741,7 @@ lstcon_group_list(int index, int len, char __user *name_up)
741 741
742static int 742static int
743lstcon_nodes_getent(struct list_head *head, int *index_p, 743lstcon_nodes_getent(struct list_head *head, int *index_p,
744 int *count_p, lstcon_node_ent_t __user *dents_up) 744 int *count_p, struct lstcon_node_ent __user *dents_up)
745{ 745{
746 struct lstcon_ndlink *ndl; 746 struct lstcon_ndlink *ndl;
747 struct lstcon_node *nd; 747 struct lstcon_node *nd;
@@ -780,11 +780,11 @@ lstcon_nodes_getent(struct list_head *head, int *index_p,
780} 780}
781 781
782int 782int
783lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gents_p, 783lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p,
784 int *index_p, int *count_p, 784 int *index_p, int *count_p,
785 lstcon_node_ent_t __user *dents_up) 785 struct lstcon_node_ent __user *dents_up)
786{ 786{
787 lstcon_ndlist_ent_t *gentp; 787 struct lstcon_ndlist_ent *gentp;
788 struct lstcon_group *grp; 788 struct lstcon_group *grp;
789 struct lstcon_ndlink *ndl; 789 struct lstcon_ndlink *ndl;
790 int rc; 790 int rc;
@@ -805,7 +805,7 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gents_p,
805 } 805 }
806 806
807 /* non-verbose query */ 807 /* non-verbose query */
808 LIBCFS_ALLOC(gentp, sizeof(lstcon_ndlist_ent_t)); 808 LIBCFS_ALLOC(gentp, sizeof(struct lstcon_ndlist_ent));
809 if (!gentp) { 809 if (!gentp) {
810 CERROR("Can't allocate ndlist_ent\n"); 810 CERROR("Can't allocate ndlist_ent\n");
811 lstcon_group_decref(grp); 811 lstcon_group_decref(grp);
@@ -817,9 +817,9 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gents_p,
817 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp); 817 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
818 818
819 rc = copy_to_user(gents_p, gentp, 819 rc = copy_to_user(gents_p, gentp,
820 sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0; 820 sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0;
821 821
822 LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t)); 822 LIBCFS_FREE(gentp, sizeof(struct lstcon_ndlist_ent));
823 823
824 lstcon_group_decref(grp); 824 lstcon_group_decref(grp);
825 825
@@ -926,11 +926,11 @@ lstcon_batch_list(int index, int len, char __user *name_up)
926} 926}
927 927
928int 928int
929lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up, 929lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
930 int server, int testidx, int *index_p, int *ndent_p, 930 int server, int testidx, int *index_p, int *ndent_p,
931 lstcon_node_ent_t __user *dents_up) 931 struct lstcon_node_ent __user *dents_up)
932{ 932{
933 lstcon_test_batch_ent_t *entp; 933 struct lstcon_test_batch_ent *entp;
934 struct list_head *clilst; 934 struct list_head *clilst;
935 struct list_head *srvlst; 935 struct list_head *srvlst;
936 struct lstcon_test *test = NULL; 936 struct lstcon_test *test = NULL;
@@ -969,7 +969,7 @@ lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up,
969 } 969 }
970 970
971 /* non-verbose query */ 971 /* non-verbose query */
972 LIBCFS_ALLOC(entp, sizeof(lstcon_test_batch_ent_t)); 972 LIBCFS_ALLOC(entp, sizeof(struct lstcon_test_batch_ent));
973 if (!entp) 973 if (!entp)
974 return -ENOMEM; 974 return -ENOMEM;
975 975
@@ -989,9 +989,9 @@ lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up,
989 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle); 989 LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
990 990
991 rc = copy_to_user(ent_up, entp, 991 rc = copy_to_user(ent_up, entp,
992 sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0; 992 sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0;
993 993
994 LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t)); 994 LIBCFS_FREE(entp, sizeof(struct lstcon_test_batch_ent));
995 995
996 return rc; 996 return rc;
997} 997}
@@ -1385,7 +1385,7 @@ lstcon_test_find(struct lstcon_batch *batch, int idx,
1385 1385
1386static int 1386static int
1387lstcon_tsbrpc_readent(int transop, struct srpc_msg *msg, 1387lstcon_tsbrpc_readent(int transop, struct srpc_msg *msg,
1388 lstcon_rpc_ent_t __user *ent_up) 1388 struct lstcon_rpc_ent __user *ent_up)
1389{ 1389{
1390 struct srpc_batch_reply *rep = &msg->msg_body.bat_reply; 1390 struct srpc_batch_reply *rep = &msg->msg_body.bat_reply;
1391 1391
@@ -1464,18 +1464,18 @@ lstcon_test_batch_query(char *name, int testidx, int client,
1464 1464
1465static int 1465static int
1466lstcon_statrpc_readent(int transop, struct srpc_msg *msg, 1466lstcon_statrpc_readent(int transop, struct srpc_msg *msg,
1467 lstcon_rpc_ent_t __user *ent_up) 1467 struct lstcon_rpc_ent __user *ent_up)
1468{ 1468{
1469 struct srpc_stat_reply *rep = &msg->msg_body.stat_reply; 1469 struct srpc_stat_reply *rep = &msg->msg_body.stat_reply;
1470 sfw_counters_t __user *sfwk_stat; 1470 struct sfw_counters __user *sfwk_stat;
1471 srpc_counters_t __user *srpc_stat; 1471 struct srpc_counters __user *srpc_stat;
1472 lnet_counters_t __user *lnet_stat; 1472 lnet_counters_t __user *lnet_stat;
1473 1473
1474 if (rep->str_status) 1474 if (rep->str_status)
1475 return 0; 1475 return 0;
1476 1476
1477 sfwk_stat = (sfw_counters_t __user *)&ent_up->rpe_payload[0]; 1477 sfwk_stat = (struct sfw_counters __user *)&ent_up->rpe_payload[0];
1478 srpc_stat = (srpc_counters_t __user *)(sfwk_stat + 1); 1478 srpc_stat = (struct srpc_counters __user *)(sfwk_stat + 1);
1479 lnet_stat = (lnet_counters_t __user *)(srpc_stat + 1); 1479 lnet_stat = (lnet_counters_t __user *)(srpc_stat + 1);
1480 1480
1481 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) || 1481 if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
@@ -1688,14 +1688,14 @@ lstcon_nodes_debug(int timeout,
1688} 1688}
1689 1689
1690int 1690int
1691lstcon_session_match(lst_sid_t sid) 1691lstcon_session_match(struct lst_sid sid)
1692{ 1692{
1693 return (console_session.ses_id.ses_nid == sid.ses_nid && 1693 return (console_session.ses_id.ses_nid == sid.ses_nid &&
1694 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1 : 0; 1694 console_session.ses_id.ses_stamp == sid.ses_stamp) ? 1 : 0;
1695} 1695}
1696 1696
1697static void 1697static void
1698lstcon_new_session_id(lst_sid_t *sid) 1698lstcon_new_session_id(struct lst_sid *sid)
1699{ 1699{
1700 lnet_process_id_t id; 1700 lnet_process_id_t id;
1701 1701
@@ -1708,7 +1708,7 @@ lstcon_new_session_id(lst_sid_t *sid)
1708 1708
1709int 1709int
1710lstcon_session_new(char *name, int key, unsigned int feats, 1710lstcon_session_new(char *name, int key, unsigned int feats,
1711 int timeout, int force, lst_sid_t __user *sid_up) 1711 int timeout, int force, struct lst_sid __user *sid_up)
1712{ 1712{
1713 int rc = 0; 1713 int rc = 0;
1714 int i; 1714 int i;
@@ -1767,7 +1767,7 @@ lstcon_session_new(char *name, int key, unsigned int feats,
1767 } 1767 }
1768 1768
1769 if (!copy_to_user(sid_up, &console_session.ses_id, 1769 if (!copy_to_user(sid_up, &console_session.ses_id,
1770 sizeof(lst_sid_t))) 1770 sizeof(struct lst_sid)))
1771 return rc; 1771 return rc;
1772 1772
1773 lstcon_session_end(); 1773 lstcon_session_end();
@@ -1776,12 +1776,12 @@ lstcon_session_new(char *name, int key, unsigned int feats,
1776} 1776}
1777 1777
1778int 1778int
1779lstcon_session_info(lst_sid_t __user *sid_up, int __user *key_up, 1779lstcon_session_info(struct lst_sid __user *sid_up, int __user *key_up,
1780 unsigned __user *featp, 1780 unsigned __user *featp,
1781 lstcon_ndlist_ent_t __user *ndinfo_up, 1781 struct lstcon_ndlist_ent __user *ndinfo_up,
1782 char __user *name_up, int len) 1782 char __user *name_up, int len)
1783{ 1783{
1784 lstcon_ndlist_ent_t *entp; 1784 struct lstcon_ndlist_ent *entp;
1785 struct lstcon_ndlink *ndl; 1785 struct lstcon_ndlink *ndl;
1786 int rc = 0; 1786 int rc = 0;
1787 1787
@@ -1796,7 +1796,7 @@ lstcon_session_info(lst_sid_t __user *sid_up, int __user *key_up,
1796 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp); 1796 LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
1797 1797
1798 if (copy_to_user(sid_up, &console_session.ses_id, 1798 if (copy_to_user(sid_up, &console_session.ses_id,
1799 sizeof(lst_sid_t)) || 1799 sizeof(*sid_up)) ||
1800 copy_to_user(key_up, &console_session.ses_key, 1800 copy_to_user(key_up, &console_session.ses_key,
1801 sizeof(*key_up)) || 1801 sizeof(*key_up)) ||
1802 copy_to_user(featp, &console_session.ses_features, 1802 copy_to_user(featp, &console_session.ses_features,
diff --git a/drivers/staging/lustre/lnet/selftest/console.h b/drivers/staging/lustre/lnet/selftest/console.h
index 5dc1de48a10e..05b4b7013d2e 100644
--- a/drivers/staging/lustre/lnet/selftest/console.h
+++ b/drivers/staging/lustre/lnet/selftest/console.h
@@ -81,7 +81,7 @@ struct lstcon_group {
81#define LST_BATCH_RUNNING 0xB1 /* running batch */ 81#define LST_BATCH_RUNNING 0xB1 /* running batch */
82 82
83struct lstcon_tsb_hdr { 83struct lstcon_tsb_hdr {
84 lst_bid_t tsb_id; /* batch ID */ 84 struct lst_bid tsb_id; /* batch ID */
85 int tsb_index; /* test index */ 85 int tsb_index; /* test index */
86}; 86};
87 87
@@ -140,7 +140,7 @@ struct lstcon_test {
140 140
141struct lstcon_session { 141struct lstcon_session {
142 struct mutex ses_mutex; /* only 1 thread in session */ 142 struct mutex ses_mutex; /* only 1 thread in session */
143 lst_sid_t ses_id; /* global session id */ 143 struct lst_sid ses_id; /* global session id */
144 int ses_key; /* local session key */ 144 int ses_key; /* local session key */
145 int ses_state; /* state of session */ 145 int ses_state; /* state of session */
146 int ses_timeout; /* timeout in seconds */ 146 int ses_timeout; /* timeout in seconds */
@@ -158,7 +158,7 @@ struct lstcon_session {
158 char ses_name[LST_NAME_SIZE];/* session name */ 158 char ses_name[LST_NAME_SIZE];/* session name */
159 struct lstcon_rpc_trans *ses_ping; /* session pinger */ 159 struct lstcon_rpc_trans *ses_ping; /* session pinger */
160 struct stt_timer ses_ping_timer; /* timer for pinger */ 160 struct stt_timer ses_ping_timer; /* timer for pinger */
161 lstcon_trans_stat_t ses_trans_stat; /* transaction stats */ 161 struct lstcon_trans_stat ses_trans_stat; /* transaction stats */
162 162
163 struct list_head ses_trans_list; /* global list of transaction */ 163 struct list_head ses_trans_list; /* global list of transaction */
164 struct list_head ses_grp_list; /* global list of groups */ 164 struct list_head ses_grp_list; /* global list of groups */
@@ -173,7 +173,7 @@ struct lstcon_session {
173 173
174extern struct lstcon_session console_session; 174extern struct lstcon_session console_session;
175 175
176static inline lstcon_trans_stat_t * 176static inline struct lstcon_trans_stat *
177lstcon_trans_stat(void) 177lstcon_trans_stat(void)
178{ 178{
179 return &console_session.ses_trans_stat; 179 return &console_session.ses_trans_stat;
@@ -190,11 +190,11 @@ lstcon_id2hash(lnet_process_id_t id, struct list_head *hash)
190int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr); 190int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
191int lstcon_console_init(void); 191int lstcon_console_init(void);
192int lstcon_console_fini(void); 192int lstcon_console_fini(void);
193int lstcon_session_match(lst_sid_t sid); 193int lstcon_session_match(struct lst_sid sid);
194int lstcon_session_new(char *name, int key, unsigned int version, 194int lstcon_session_new(char *name, int key, unsigned int version,
195 int timeout, int flags, lst_sid_t __user *sid_up); 195 int timeout, int flags, struct lst_sid __user *sid_up);
196int lstcon_session_info(lst_sid_t __user *sid_up, int __user *key, 196int lstcon_session_info(struct lst_sid __user *sid_up, int __user *key,
197 unsigned __user *verp, lstcon_ndlist_ent_t __user *entp, 197 unsigned __user *verp, struct lstcon_ndlist_ent __user *entp,
198 char __user *name_up, int len); 198 char __user *name_up, int len);
199int lstcon_session_end(void); 199int lstcon_session_end(void);
200int lstcon_session_debug(int timeout, struct list_head __user *result_up); 200int lstcon_session_debug(int timeout, struct list_head __user *result_up);
@@ -213,9 +213,9 @@ int lstcon_nodes_add(char *name, int nnd, lnet_process_id_t __user *nds_up,
213 unsigned int *featp, struct list_head __user *result_up); 213 unsigned int *featp, struct list_head __user *result_up);
214int lstcon_nodes_remove(char *name, int nnd, lnet_process_id_t __user *nds_up, 214int lstcon_nodes_remove(char *name, int nnd, lnet_process_id_t __user *nds_up,
215 struct list_head __user *result_up); 215 struct list_head __user *result_up);
216int lstcon_group_info(char *name, lstcon_ndlist_ent_t __user *gent_up, 216int lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gent_up,
217 int *index_p, int *ndent_p, 217 int *index_p, int *ndent_p,
218 lstcon_node_ent_t __user *ndents_up); 218 struct lstcon_node_ent __user *ndents_up);
219int lstcon_group_list(int idx, int len, char __user *name_up); 219int lstcon_group_list(int idx, int len, char __user *name_up);
220int lstcon_batch_add(char *name); 220int lstcon_batch_add(char *name);
221int lstcon_batch_run(char *name, int timeout, 221int lstcon_batch_run(char *name, int timeout,
@@ -227,9 +227,9 @@ int lstcon_test_batch_query(char *name, int testidx,
227 struct list_head __user *result_up); 227 struct list_head __user *result_up);
228int lstcon_batch_del(char *name); 228int lstcon_batch_del(char *name);
229int lstcon_batch_list(int idx, int namelen, char __user *name_up); 229int lstcon_batch_list(int idx, int namelen, char __user *name_up);
230int lstcon_batch_info(char *name, lstcon_test_batch_ent_t __user *ent_up, 230int lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
231 int server, int testidx, int *index_p, 231 int server, int testidx, int *index_p,
232 int *ndent_p, lstcon_node_ent_t __user *dents_up); 232 int *ndent_p, struct lstcon_node_ent __user *dents_up);
233int lstcon_group_stat(char *grp_name, int timeout, 233int lstcon_group_stat(char *grp_name, int timeout,
234 struct list_head __user *result_up); 234 struct list_head __user *result_up);
235int lstcon_nodes_stat(int count, lnet_process_id_t __user *ids_up, 235int lstcon_nodes_stat(int count, lnet_process_id_t __user *ids_up,
diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
index 48dcc330dc9b..9dd4e1a70329 100644
--- a/drivers/staging/lustre/lnet/selftest/framework.c
+++ b/drivers/staging/lustre/lnet/selftest/framework.c
@@ -39,7 +39,7 @@
39 39
40#include "selftest.h" 40#include "selftest.h"
41 41
42lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1}; 42struct lst_sid LST_INVALID_SID = {LNET_NID_ANY, -1};
43 43
44static int session_timeout = 100; 44static int session_timeout = 100;
45module_param(session_timeout, int, 0444); 45module_param(session_timeout, int, 0444);
@@ -254,7 +254,7 @@ sfw_session_expired(void *data)
254} 254}
255 255
256static inline void 256static inline void
257sfw_init_session(struct sfw_session *sn, lst_sid_t sid, 257sfw_init_session(struct sfw_session *sn, struct lst_sid sid,
258 unsigned int features, const char *name) 258 unsigned int features, const char *name)
259{ 259{
260 struct stt_timer *timer = &sn->sn_timer; 260 struct stt_timer *timer = &sn->sn_timer;
@@ -316,7 +316,7 @@ sfw_client_rpc_fini(struct srpc_client_rpc *rpc)
316} 316}
317 317
318static struct sfw_batch * 318static struct sfw_batch *
319sfw_find_batch(lst_bid_t bid) 319sfw_find_batch(struct lst_bid bid)
320{ 320{
321 struct sfw_session *sn = sfw_data.fw_session; 321 struct sfw_session *sn = sfw_data.fw_session;
322 struct sfw_batch *bat; 322 struct sfw_batch *bat;
@@ -332,7 +332,7 @@ sfw_find_batch(lst_bid_t bid)
332} 332}
333 333
334static struct sfw_batch * 334static struct sfw_batch *
335sfw_bid2batch(lst_bid_t bid) 335sfw_bid2batch(struct lst_bid bid)
336{ 336{
337 struct sfw_session *sn = sfw_data.fw_session; 337 struct sfw_session *sn = sfw_data.fw_session;
338 struct sfw_batch *bat; 338 struct sfw_batch *bat;
@@ -361,7 +361,7 @@ static int
361sfw_get_stats(struct srpc_stat_reqst *request, struct srpc_stat_reply *reply) 361sfw_get_stats(struct srpc_stat_reqst *request, struct srpc_stat_reply *reply)
362{ 362{
363 struct sfw_session *sn = sfw_data.fw_session; 363 struct sfw_session *sn = sfw_data.fw_session;
364 sfw_counters_t *cnt = &reply->str_fw; 364 struct sfw_counters *cnt = &reply->str_fw;
365 struct sfw_batch *bat; 365 struct sfw_batch *bat;
366 366
367 reply->str_sid = !sn ? LST_INVALID_SID : sn->sn_id; 367 reply->str_sid = !sn ? LST_INVALID_SID : sn->sn_id;
@@ -777,14 +777,14 @@ sfw_add_test_instance(struct sfw_batch *tsb, struct srpc_server_rpc *rpc)
777 LASSERT(bk); 777 LASSERT(bk);
778 LASSERT(bk->bk_niov * SFW_ID_PER_PAGE >= (unsigned int)ndest); 778 LASSERT(bk->bk_niov * SFW_ID_PER_PAGE >= (unsigned int)ndest);
779 LASSERT((unsigned int)bk->bk_len >= 779 LASSERT((unsigned int)bk->bk_len >=
780 sizeof(lnet_process_id_packed_t) * ndest); 780 sizeof(struct lnet_process_id_packed) * ndest);
781 781
782 sfw_unpack_addtest_req(msg); 782 sfw_unpack_addtest_req(msg);
783 memcpy(&tsi->tsi_u, &req->tsr_u, sizeof(tsi->tsi_u)); 783 memcpy(&tsi->tsi_u, &req->tsr_u, sizeof(tsi->tsi_u));
784 784
785 for (i = 0; i < ndest; i++) { 785 for (i = 0; i < ndest; i++) {
786 lnet_process_id_packed_t *dests; 786 struct lnet_process_id_packed *dests;
787 lnet_process_id_packed_t id; 787 struct lnet_process_id_packed id;
788 int j; 788 int j;
789 789
790 dests = page_address(bk->bk_iovs[i / SFW_ID_PER_PAGE].bv_page); 790 dests = page_address(bk->bk_iovs[i / SFW_ID_PER_PAGE].bv_page);
@@ -1164,7 +1164,7 @@ sfw_add_test(struct srpc_server_rpc *rpc)
1164 len = npg * PAGE_SIZE; 1164 len = npg * PAGE_SIZE;
1165 1165
1166 } else { 1166 } else {
1167 len = sizeof(lnet_process_id_packed_t) * 1167 len = sizeof(struct lnet_process_id_packed) *
1168 request->tsr_ndest; 1168 request->tsr_ndest;
1169 } 1169 }
1170 1170
diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c
index 71485f992297..b5d556fa48ab 100644
--- a/drivers/staging/lustre/lnet/selftest/module.c
+++ b/drivers/staging/lustre/lnet/selftest/module.c
@@ -112,7 +112,8 @@ lnet_selftest_init(void)
112 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i, 112 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
113 nthrs, &lst_sched_test[i]); 113 nthrs, &lst_sched_test[i]);
114 if (rc) { 114 if (rc) {
115 CERROR("Failed to create CPT affinity WI scheduler %d for LST\n", i); 115 CWARN("Failed to create CPU partition affinity WI scheduler %d for LST\n",
116 i);
116 goto error; 117 goto error;
117 } 118 }
118 } 119 }
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c
index ce9de8c9be57..92cd4113cf75 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.c
+++ b/drivers/staging/lustre/lnet/selftest/rpc.c
@@ -55,7 +55,7 @@ static struct smoketest_rpc {
55 struct srpc_service *rpc_services[SRPC_SERVICE_MAX_ID + 1]; 55 struct srpc_service *rpc_services[SRPC_SERVICE_MAX_ID + 1];
56 lnet_handle_eq_t rpc_lnet_eq; /* _the_ LNet event queue */ 56 lnet_handle_eq_t rpc_lnet_eq; /* _the_ LNet event queue */
57 enum srpc_state rpc_state; 57 enum srpc_state rpc_state;
58 srpc_counters_t rpc_counters; 58 struct srpc_counters rpc_counters;
59 __u64 rpc_matchbits; /* matchbits counter */ 59 __u64 rpc_matchbits; /* matchbits counter */
60} srpc_data; 60} srpc_data;
61 61
@@ -69,14 +69,14 @@ srpc_serv_portal(int svc_id)
69/* forward ref's */ 69/* forward ref's */
70int srpc_handle_rpc(struct swi_workitem *wi); 70int srpc_handle_rpc(struct swi_workitem *wi);
71 71
72void srpc_get_counters(srpc_counters_t *cnt) 72void srpc_get_counters(struct srpc_counters *cnt)
73{ 73{
74 spin_lock(&srpc_data.rpc_glock); 74 spin_lock(&srpc_data.rpc_glock);
75 *cnt = srpc_data.rpc_counters; 75 *cnt = srpc_data.rpc_counters;
76 spin_unlock(&srpc_data.rpc_glock); 76 spin_unlock(&srpc_data.rpc_glock);
77} 77}
78 78
79void srpc_set_counters(const srpc_counters_t *cnt) 79void srpc_set_counters(const struct srpc_counters *cnt)
80{ 80{
81 spin_lock(&srpc_data.rpc_glock); 81 spin_lock(&srpc_data.rpc_glock);
82 srpc_data.rpc_counters = *cnt; 82 srpc_data.rpc_counters = *cnt;
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.h b/drivers/staging/lustre/lnet/selftest/rpc.h
index f353a634cc8e..418c9c96abe6 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.h
+++ b/drivers/staging/lustre/lnet/selftest/rpc.h
@@ -75,43 +75,43 @@ struct srpc_generic_reqst {
75 75
76struct srpc_generic_reply { 76struct srpc_generic_reply {
77 __u32 status; 77 __u32 status;
78 lst_sid_t sid; 78 struct lst_sid sid;
79} WIRE_ATTR; 79} WIRE_ATTR;
80 80
81/* FRAMEWORK RPCs */ 81/* FRAMEWORK RPCs */
82struct srpc_mksn_reqst { 82struct srpc_mksn_reqst {
83 __u64 mksn_rpyid; /* reply buffer matchbits */ 83 __u64 mksn_rpyid; /* reply buffer matchbits */
84 lst_sid_t mksn_sid; /* session id */ 84 struct lst_sid mksn_sid; /* session id */
85 __u32 mksn_force; /* use brute force */ 85 __u32 mksn_force; /* use brute force */
86 char mksn_name[LST_NAME_SIZE]; 86 char mksn_name[LST_NAME_SIZE];
87} WIRE_ATTR; /* make session request */ 87} WIRE_ATTR; /* make session request */
88 88
89struct srpc_mksn_reply { 89struct srpc_mksn_reply {
90 __u32 mksn_status; /* session status */ 90 __u32 mksn_status; /* session status */
91 lst_sid_t mksn_sid; /* session id */ 91 struct lst_sid mksn_sid; /* session id */
92 __u32 mksn_timeout; /* session timeout */ 92 __u32 mksn_timeout; /* session timeout */
93 char mksn_name[LST_NAME_SIZE]; 93 char mksn_name[LST_NAME_SIZE];
94} WIRE_ATTR; /* make session reply */ 94} WIRE_ATTR; /* make session reply */
95 95
96struct srpc_rmsn_reqst { 96struct srpc_rmsn_reqst {
97 __u64 rmsn_rpyid; /* reply buffer matchbits */ 97 __u64 rmsn_rpyid; /* reply buffer matchbits */
98 lst_sid_t rmsn_sid; /* session id */ 98 struct lst_sid rmsn_sid; /* session id */
99} WIRE_ATTR; /* remove session request */ 99} WIRE_ATTR; /* remove session request */
100 100
101struct srpc_rmsn_reply { 101struct srpc_rmsn_reply {
102 __u32 rmsn_status; 102 __u32 rmsn_status;
103 lst_sid_t rmsn_sid; /* session id */ 103 struct lst_sid rmsn_sid; /* session id */
104} WIRE_ATTR; /* remove session reply */ 104} WIRE_ATTR; /* remove session reply */
105 105
106struct srpc_join_reqst { 106struct srpc_join_reqst {
107 __u64 join_rpyid; /* reply buffer matchbits */ 107 __u64 join_rpyid; /* reply buffer matchbits */
108 lst_sid_t join_sid; /* session id to join */ 108 struct lst_sid join_sid; /* session id to join */
109 char join_group[LST_NAME_SIZE]; /* group name */ 109 char join_group[LST_NAME_SIZE]; /* group name */
110} WIRE_ATTR; 110} WIRE_ATTR;
111 111
112struct srpc_join_reply { 112struct srpc_join_reply {
113 __u32 join_status; /* returned status */ 113 __u32 join_status; /* returned status */
114 lst_sid_t join_sid; /* session id */ 114 struct lst_sid join_sid; /* session id */
115 __u32 join_timeout; /* # seconds' inactivity to 115 __u32 join_timeout; /* # seconds' inactivity to
116 * expire 116 * expire
117 */ 117 */
@@ -120,13 +120,13 @@ struct srpc_join_reply {
120 120
121struct srpc_debug_reqst { 121struct srpc_debug_reqst {
122 __u64 dbg_rpyid; /* reply buffer matchbits */ 122 __u64 dbg_rpyid; /* reply buffer matchbits */
123 lst_sid_t dbg_sid; /* session id */ 123 struct lst_sid dbg_sid; /* session id */
124 __u32 dbg_flags; /* bitmap of debug */ 124 __u32 dbg_flags; /* bitmap of debug */
125} WIRE_ATTR; 125} WIRE_ATTR;
126 126
127struct srpc_debug_reply { 127struct srpc_debug_reply {
128 __u32 dbg_status; /* returned code */ 128 __u32 dbg_status; /* returned code */
129 lst_sid_t dbg_sid; /* session id */ 129 struct lst_sid dbg_sid; /* session id */
130 __u32 dbg_timeout; /* session timeout */ 130 __u32 dbg_timeout; /* session timeout */
131 __u32 dbg_nbatch; /* # of batches in the node */ 131 __u32 dbg_nbatch; /* # of batches in the node */
132 char dbg_name[LST_NAME_SIZE]; /* session name */ 132 char dbg_name[LST_NAME_SIZE]; /* session name */
@@ -138,8 +138,8 @@ struct srpc_debug_reply {
138 138
139struct srpc_batch_reqst { 139struct srpc_batch_reqst {
140 __u64 bar_rpyid; /* reply buffer matchbits */ 140 __u64 bar_rpyid; /* reply buffer matchbits */
141 lst_sid_t bar_sid; /* session id */ 141 struct lst_sid bar_sid; /* session id */
142 lst_bid_t bar_bid; /* batch id */ 142 struct lst_bid bar_bid; /* batch id */
143 __u32 bar_opc; /* create/start/stop batch */ 143 __u32 bar_opc; /* create/start/stop batch */
144 __u32 bar_testidx; /* index of test */ 144 __u32 bar_testidx; /* index of test */
145 __u32 bar_arg; /* parameters */ 145 __u32 bar_arg; /* parameters */
@@ -147,22 +147,22 @@ struct srpc_batch_reqst {
147 147
148struct srpc_batch_reply { 148struct srpc_batch_reply {
149 __u32 bar_status; /* status of request */ 149 __u32 bar_status; /* status of request */
150 lst_sid_t bar_sid; /* session id */ 150 struct lst_sid bar_sid; /* session id */
151 __u32 bar_active; /* # of active tests in batch/test */ 151 __u32 bar_active; /* # of active tests in batch/test */
152 __u32 bar_time; /* remained time */ 152 __u32 bar_time; /* remained time */
153} WIRE_ATTR; 153} WIRE_ATTR;
154 154
155struct srpc_stat_reqst { 155struct srpc_stat_reqst {
156 __u64 str_rpyid; /* reply buffer matchbits */ 156 __u64 str_rpyid; /* reply buffer matchbits */
157 lst_sid_t str_sid; /* session id */ 157 struct lst_sid str_sid; /* session id */
158 __u32 str_type; /* type of stat */ 158 __u32 str_type; /* type of stat */
159} WIRE_ATTR; 159} WIRE_ATTR;
160 160
161struct srpc_stat_reply { 161struct srpc_stat_reply {
162 __u32 str_status; 162 __u32 str_status;
163 lst_sid_t str_sid; 163 struct lst_sid str_sid;
164 sfw_counters_t str_fw; 164 struct sfw_counters str_fw;
165 srpc_counters_t str_rpc; 165 struct srpc_counters str_rpc;
166 lnet_counters_t str_lnet; 166 lnet_counters_t str_lnet;
167} WIRE_ATTR; 167} WIRE_ATTR;
168 168
@@ -187,8 +187,8 @@ struct test_ping_req {
187struct srpc_test_reqst { 187struct srpc_test_reqst {
188 __u64 tsr_rpyid; /* reply buffer matchbits */ 188 __u64 tsr_rpyid; /* reply buffer matchbits */
189 __u64 tsr_bulkid; /* bulk buffer matchbits */ 189 __u64 tsr_bulkid; /* bulk buffer matchbits */
190 lst_sid_t tsr_sid; /* session id */ 190 struct lst_sid tsr_sid; /* session id */
191 lst_bid_t tsr_bid; /* batch id */ 191 struct lst_bid tsr_bid; /* batch id */
192 __u32 tsr_service; /* test type: bulk|ping|... */ 192 __u32 tsr_service; /* test type: bulk|ping|... */
193 __u32 tsr_loop; /* test client loop count or 193 __u32 tsr_loop; /* test client loop count or
194 * # server buffers needed 194 * # server buffers needed
@@ -207,7 +207,7 @@ struct srpc_test_reqst {
207 207
208struct srpc_test_reply { 208struct srpc_test_reply {
209 __u32 tsr_status; /* returned code */ 209 __u32 tsr_status; /* returned code */
210 lst_sid_t tsr_sid; 210 struct lst_sid tsr_sid;
211} WIRE_ATTR; 211} WIRE_ATTR;
212 212
213/* TEST RPCs */ 213/* TEST RPCs */
diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h
index c8833a016b6d..f25948087ee0 100644
--- a/drivers/staging/lustre/lnet/selftest/selftest.h
+++ b/drivers/staging/lustre/lnet/selftest/selftest.h
@@ -322,7 +322,7 @@ struct srpc_service {
322 322
323struct sfw_session { 323struct sfw_session {
324 struct list_head sn_list; /* chain on fw_zombie_sessions */ 324 struct list_head sn_list; /* chain on fw_zombie_sessions */
325 lst_sid_t sn_id; /* unique identifier */ 325 struct lst_sid sn_id; /* unique identifier */
326 unsigned int sn_timeout; /* # seconds' inactivity to expire */ 326 unsigned int sn_timeout; /* # seconds' inactivity to expire */
327 int sn_timer_active; 327 int sn_timer_active;
328 unsigned int sn_features; 328 unsigned int sn_features;
@@ -340,7 +340,7 @@ struct sfw_session {
340 340
341struct sfw_batch { 341struct sfw_batch {
342 struct list_head bat_list; /* chain on sn_batches */ 342 struct list_head bat_list; /* chain on sn_batches */
343 lst_bid_t bat_id; /* batch id */ 343 struct lst_bid bat_id; /* batch id */
344 int bat_error; /* error code of batch */ 344 int bat_error; /* error code of batch */
345 struct sfw_session *bat_session; /* batch's session */ 345 struct sfw_session *bat_session; /* batch's session */
346 atomic_t bat_nactive; /* # of active tests */ 346 atomic_t bat_nactive; /* # of active tests */
@@ -396,7 +396,7 @@ struct sfw_test_instance {
396 * pages are not used 396 * pages are not used
397 */ 397 */
398#define SFW_MAX_CONCUR LST_MAX_CONCUR 398#define SFW_MAX_CONCUR LST_MAX_CONCUR
399#define SFW_ID_PER_PAGE (PAGE_SIZE / sizeof(lnet_process_id_packed_t)) 399#define SFW_ID_PER_PAGE (PAGE_SIZE / sizeof(struct lnet_process_id_packed))
400#define SFW_MAX_NDESTS (LNET_MAX_IOV * SFW_ID_PER_PAGE) 400#define SFW_MAX_NDESTS (LNET_MAX_IOV * SFW_ID_PER_PAGE)
401#define sfw_id_pages(n) (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE) 401#define sfw_id_pages(n) (((n) + SFW_ID_PER_PAGE - 1) / SFW_ID_PER_PAGE)
402 402
@@ -453,8 +453,8 @@ void srpc_abort_service(struct srpc_service *sv);
453int srpc_finish_service(struct srpc_service *sv); 453int srpc_finish_service(struct srpc_service *sv);
454int srpc_service_add_buffers(struct srpc_service *sv, int nbuffer); 454int srpc_service_add_buffers(struct srpc_service *sv, int nbuffer);
455void srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer); 455void srpc_service_remove_buffers(struct srpc_service *sv, int nbuffer);
456void srpc_get_counters(srpc_counters_t *cnt); 456void srpc_get_counters(struct srpc_counters *cnt);
457void srpc_set_counters(const srpc_counters_t *cnt); 457void srpc_set_counters(const struct srpc_counters *cnt);
458 458
459extern struct cfs_wi_sched *lst_sched_serial; 459extern struct cfs_wi_sched *lst_sched_serial;
460extern struct cfs_wi_sched **lst_sched_test; 460extern struct cfs_wi_sched **lst_sched_test;
diff --git a/drivers/staging/lustre/lustre/fid/fid_lib.c b/drivers/staging/lustre/lustre/fid/fid_lib.c
index 4e49cb356d64..9eb405905d1a 100644
--- a/drivers/staging/lustre/lustre/fid/fid_lib.c
+++ b/drivers/staging/lustre/lustre/fid/fid_lib.c
@@ -60,14 +60,13 @@
60 * FID_SEQ_START + 2 is for .lustre directory and its objects 60 * FID_SEQ_START + 2 is for .lustre directory and its objects
61 */ 61 */
62const struct lu_seq_range LUSTRE_SEQ_SPACE_RANGE = { 62const struct lu_seq_range LUSTRE_SEQ_SPACE_RANGE = {
63 FID_SEQ_NORMAL, 63 .lsr_start = FID_SEQ_NORMAL,
64 (__u64)~0ULL 64 .lsr_end = (__u64)~0ULL,
65}; 65};
66 66
67/* Zero range, used for init and other purposes. */ 67/* Zero range, used for init and other purposes. */
68const struct lu_seq_range LUSTRE_SEQ_ZERO_RANGE = { 68const struct lu_seq_range LUSTRE_SEQ_ZERO_RANGE = {
69 0, 69 .lsr_start = 0,
70 0
71}; 70};
72 71
73/* Lustre Big Fs Lock fid. */ 72/* Lustre Big Fs Lock fid. */
diff --git a/drivers/staging/lustre/lustre/fid/lproc_fid.c b/drivers/staging/lustre/lustre/fid/lproc_fid.c
index 97d4849c7199..3eed83808545 100644
--- a/drivers/staging/lustre/lustre/fid/lproc_fid.c
+++ b/drivers/staging/lustre/lustre/fid/lproc_fid.c
@@ -203,9 +203,13 @@ LPROC_SEQ_FOPS_RO(ldebugfs_fid_server);
203LPROC_SEQ_FOPS_RO(ldebugfs_fid_fid); 203LPROC_SEQ_FOPS_RO(ldebugfs_fid_fid);
204 204
205struct lprocfs_vars seq_client_debugfs_list[] = { 205struct lprocfs_vars seq_client_debugfs_list[] = {
206 { "space", &ldebugfs_fid_space_fops }, 206 { .name = "space",
207 { "width", &ldebugfs_fid_width_fops }, 207 .fops = &ldebugfs_fid_space_fops },
208 { "server", &ldebugfs_fid_server_fops }, 208 { .name = "width",
209 { "fid", &ldebugfs_fid_fid_fops }, 209 .fops = &ldebugfs_fid_width_fops },
210 { .name = "server",
211 .fops = &ldebugfs_fid_server_fops },
212 { .name = "fid",
213 .fops = &ldebugfs_fid_fid_fops },
210 { NULL } 214 { NULL }
211}; 215};
diff --git a/drivers/staging/lustre/lustre/include/cl_object.h b/drivers/staging/lustre/lustre/include/cl_object.h
index dc685610c4c4..e4c0c440f01b 100644
--- a/drivers/staging/lustre/lustre/include/cl_object.h
+++ b/drivers/staging/lustre/lustre/include/cl_object.h
@@ -284,12 +284,6 @@ struct cl_layout {
284 size_t cl_size; 284 size_t cl_size;
285 /** Layout generation. */ 285 /** Layout generation. */
286 u32 cl_layout_gen; 286 u32 cl_layout_gen;
287 /**
288 * True if this is a released file.
289 * Temporarily added for released file truncate in ll_setattr_raw().
290 * It will be removed later. -Jinshan
291 */
292 bool cl_is_released;
293}; 287};
294 288
295/** 289/**
@@ -1458,8 +1452,10 @@ struct cl_read_ahead {
1458 * cra_end is included. 1452 * cra_end is included.
1459 */ 1453 */
1460 pgoff_t cra_end; 1454 pgoff_t cra_end;
1455 /* optimal RPC size for this read, by pages */
1456 unsigned long cra_rpc_size;
1461 /* 1457 /*
1462 * Release routine. If readahead holds resources underneath, this 1458 * Release callback. If readahead holds resources underneath, this
1463 * function should be called to release it. 1459 * function should be called to release it.
1464 */ 1460 */
1465 void (*cra_release)(const struct lu_env *env, void *cbdata); 1461 void (*cra_release)(const struct lu_env *env, void *cbdata);
@@ -2311,7 +2307,7 @@ struct cl_io *cl_io_top(struct cl_io *io);
2311do { \ 2307do { \
2312 typeof(foo_io) __foo_io = (foo_io); \ 2308 typeof(foo_io) __foo_io = (foo_io); \
2313 \ 2309 \
2314 CLASSERT(offsetof(typeof(*__foo_io), base) == 0); \ 2310 BUILD_BUG_ON(offsetof(typeof(*__foo_io), base) != 0); \
2315 memset(&__foo_io->base + 1, 0, \ 2311 memset(&__foo_io->base + 1, 0, \
2316 sizeof(*__foo_io) - sizeof(__foo_io->base)); \ 2312 sizeof(*__foo_io) - sizeof(__foo_io->base)); \
2317} while (0) 2313} while (0)
diff --git a/drivers/staging/lustre/lustre/include/interval_tree.h b/drivers/staging/lustre/lustre/include/interval_tree.h
index 5d387d372547..0d4f92ec8334 100644
--- a/drivers/staging/lustre/lustre/include/interval_tree.h
+++ b/drivers/staging/lustre/lustre/include/interval_tree.h
@@ -36,7 +36,9 @@
36#ifndef _INTERVAL_H__ 36#ifndef _INTERVAL_H__
37#define _INTERVAL_H__ 37#define _INTERVAL_H__
38 38
39#include "../../include/linux/libcfs/libcfs.h" /* LASSERT. */ 39#include <linux/errno.h>
40#include <linux/string.h>
41#include <linux/types.h>
40 42
41struct interval_node { 43struct interval_node {
42 struct interval_node *in_left; 44 struct interval_node *in_left;
@@ -73,13 +75,15 @@ static inline __u64 interval_high(struct interval_node *node)
73 return node->in_extent.end; 75 return node->in_extent.end;
74} 76}
75 77
76static inline void interval_set(struct interval_node *node, 78static inline int interval_set(struct interval_node *node,
77 __u64 start, __u64 end) 79 __u64 start, __u64 end)
78{ 80{
79 LASSERT(start <= end); 81 if (start > end)
82 return -ERANGE;
80 node->in_extent.start = start; 83 node->in_extent.start = start;
81 node->in_extent.end = end; 84 node->in_extent.end = end;
82 node->in_max_high = end; 85 node->in_max_high = end;
86 return 0;
83} 87}
84 88
85/* 89/*
diff --git a/drivers/staging/lustre/lustre/include/lu_object.h b/drivers/staging/lustre/lustre/include/lu_object.h
index 260643ee0d48..7a4f412a85a3 100644
--- a/drivers/staging/lustre/lustre/include/lu_object.h
+++ b/drivers/staging/lustre/lustre/include/lu_object.h
@@ -34,6 +34,7 @@
34#define __LUSTRE_LU_OBJECT_H 34#define __LUSTRE_LU_OBJECT_H
35 35
36#include <stdarg.h> 36#include <stdarg.h>
37#include <linux/percpu_counter.h>
37#include "../../include/linux/libcfs/libcfs.h" 38#include "../../include/linux/libcfs/libcfs.h"
38#include "lustre/lustre_idl.h" 39#include "lustre/lustre_idl.h"
39#include "lu_ref.h" 40#include "lu_ref.h"
@@ -580,7 +581,6 @@ enum {
580 LU_SS_CACHE_RACE, 581 LU_SS_CACHE_RACE,
581 LU_SS_CACHE_DEATH_RACE, 582 LU_SS_CACHE_DEATH_RACE,
582 LU_SS_LRU_PURGED, 583 LU_SS_LRU_PURGED,
583 LU_SS_LRU_LEN, /* # of objects in lsb_lru lists */
584 LU_SS_LAST_STAT 584 LU_SS_LAST_STAT
585}; 585};
586 586
@@ -635,6 +635,10 @@ struct lu_site {
635 * XXX: a hack! fld has to find md_site via site, remove when possible 635 * XXX: a hack! fld has to find md_site via site, remove when possible
636 */ 636 */
637 struct seq_server_site *ld_seq_site; 637 struct seq_server_site *ld_seq_site;
638 /**
639 * Number of objects in lsb_lru_lists - used for shrinking
640 */
641 struct percpu_counter ls_lru_len_counter;
638}; 642};
639 643
640static inline struct lu_site_bkt_data * 644static inline struct lu_site_bkt_data *
@@ -708,8 +712,14 @@ static inline int lu_object_is_dying(const struct lu_object_header *h)
708 712
709void lu_object_put(const struct lu_env *env, struct lu_object *o); 713void lu_object_put(const struct lu_env *env, struct lu_object *o);
710void lu_object_unhash(const struct lu_env *env, struct lu_object *o); 714void lu_object_unhash(const struct lu_env *env, struct lu_object *o);
715int lu_site_purge_objects(const struct lu_env *env, struct lu_site *s, int nr,
716 bool canblock);
711 717
712int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr); 718static inline int lu_site_purge(const struct lu_env *env, struct lu_site *s,
719 int nr)
720{
721 return lu_site_purge_objects(env, s, nr, true);
722}
713 723
714void lu_site_print(const struct lu_env *env, struct lu_site *s, void *cookie, 724void lu_site_print(const struct lu_env *env, struct lu_site *s, void *cookie,
715 lu_printer_t printer); 725 lu_printer_t printer);
@@ -1120,7 +1130,7 @@ struct lu_context_key {
1120 { \ 1130 { \
1121 type *value; \ 1131 type *value; \
1122 \ 1132 \
1123 CLASSERT(PAGE_SIZE >= sizeof(*value)); \ 1133 BUILD_BUG_ON(PAGE_SIZE < sizeof(*value)); \
1124 \ 1134 \
1125 value = kzalloc(sizeof(*value), GFP_NOFS); \ 1135 value = kzalloc(sizeof(*value), GFP_NOFS); \
1126 if (!value) \ 1136 if (!value) \
@@ -1326,5 +1336,8 @@ void lu_buf_realloc(struct lu_buf *buf, size_t size);
1326int lu_buf_check_and_grow(struct lu_buf *buf, size_t len); 1336int lu_buf_check_and_grow(struct lu_buf *buf, size_t len);
1327struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len); 1337struct lu_buf *lu_buf_check_and_alloc(struct lu_buf *buf, size_t len);
1328 1338
1339extern __u32 lu_context_tags_default;
1340extern __u32 lu_session_tags_default;
1341
1329/** @} lu */ 1342/** @} lu */
1330#endif /* __LUSTRE_LU_OBJECT_H */ 1343#endif /* __LUSTRE_LU_OBJECT_H */
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
index 65ce503ad595..b0eb80d70c23 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
@@ -3130,52 +3130,6 @@ struct obdo {
3130#define o_cksum o_nlink 3130#define o_cksum o_nlink
3131#define o_grant_used o_data_version 3131#define o_grant_used o_data_version
3132 3132
3133static inline void lustre_set_wire_obdo(const struct obd_connect_data *ocd,
3134 struct obdo *wobdo,
3135 const struct obdo *lobdo)
3136{
3137 *wobdo = *lobdo;
3138 wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
3139 if (!ocd)
3140 return;
3141
3142 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
3143 fid_seq_is_echo(ostid_seq(&lobdo->o_oi))) {
3144 /* Currently OBD_FL_OSTID will only be used when 2.4 echo
3145 * client communicate with pre-2.4 server
3146 */
3147 wobdo->o_oi.oi.oi_id = fid_oid(&lobdo->o_oi.oi_fid);
3148 wobdo->o_oi.oi.oi_seq = fid_seq(&lobdo->o_oi.oi_fid);
3149 }
3150}
3151
3152static inline void lustre_get_wire_obdo(const struct obd_connect_data *ocd,
3153 struct obdo *lobdo,
3154 const struct obdo *wobdo)
3155{
3156 __u32 local_flags = 0;
3157
3158 if (lobdo->o_valid & OBD_MD_FLFLAGS)
3159 local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
3160
3161 *lobdo = *wobdo;
3162 if (local_flags != 0) {
3163 lobdo->o_valid |= OBD_MD_FLFLAGS;
3164 lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
3165 lobdo->o_flags |= local_flags;
3166 }
3167 if (!ocd)
3168 return;
3169
3170 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
3171 fid_seq_is_echo(wobdo->o_oi.oi.oi_seq)) {
3172 /* see above */
3173 lobdo->o_oi.oi_fid.f_seq = wobdo->o_oi.oi.oi_seq;
3174 lobdo->o_oi.oi_fid.f_oid = wobdo->o_oi.oi.oi_id;
3175 lobdo->o_oi.oi_fid.f_ver = 0;
3176 }
3177}
3178
3179/* request structure for OST's */ 3133/* request structure for OST's */
3180struct ost_body { 3134struct ost_body {
3181 struct obdo oa; 3135 struct obdo oa;
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
index 3301ad652db1..21aec0ca9ad3 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
@@ -1209,23 +1209,21 @@ struct hsm_action_item {
1209 * \retval buffer 1209 * \retval buffer
1210 */ 1210 */
1211static inline char *hai_dump_data_field(struct hsm_action_item *hai, 1211static inline char *hai_dump_data_field(struct hsm_action_item *hai,
1212 char *buffer, int len) 1212 char *buffer, size_t len)
1213{ 1213{
1214 int i, sz, data_len; 1214 int i, data_len;
1215 char *ptr; 1215 char *ptr;
1216 1216
1217 ptr = buffer; 1217 ptr = buffer;
1218 sz = len;
1219 data_len = hai->hai_len - sizeof(*hai); 1218 data_len = hai->hai_len - sizeof(*hai);
1220 for (i = 0 ; (i < data_len) && (sz > 0) ; i++) { 1219 for (i = 0; (i < data_len) && (len > 2); i++) {
1221 int cnt; 1220 snprintf(ptr, 3, "%02X", (unsigned char)hai->hai_data[i]);
1222 1221 ptr += 2;
1223 cnt = snprintf(ptr, sz, "%.2X", 1222 len -= 2;
1224 (unsigned char)hai->hai_data[i]);
1225 ptr += cnt;
1226 sz -= cnt;
1227 } 1223 }
1224
1228 *ptr = '\0'; 1225 *ptr = '\0';
1226
1229 return buffer; 1227 return buffer;
1230} 1228}
1231 1229
diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h
index 411eb0dc7f38..1b48df0d4862 100644
--- a/drivers/staging/lustre/lustre/include/lustre_net.h
+++ b/drivers/staging/lustre/lustre/include/lustre_net.h
@@ -315,8 +315,8 @@ struct ptlrpc_client {
315union ptlrpc_async_args { 315union ptlrpc_async_args {
316 /** 316 /**
317 * Scratchpad for passing args to completion interpreter. Users 317 * Scratchpad for passing args to completion interpreter. Users
318 * cast to the struct of their choosing, and CLASSERT that this is 318 * cast to the struct of their choosing, and BUILD_BUG_ON oversized
319 * big enough. For _tons_ of context, kmalloc a struct and store 319 * arguments. For _tons_ of context, kmalloc a struct and store
320 * a pointer to it here. The pointer_arg ensures this struct is at 320 * a pointer to it here. The pointer_arg ensures this struct is at
321 * least big enough for that. 321 * least big enough for that.
322 */ 322 */
@@ -1661,10 +1661,6 @@ struct ptlrpcd_ctl {
1661 */ 1661 */
1662 char pc_name[16]; 1662 char pc_name[16];
1663 /** 1663 /**
1664 * Environment for request interpreters to run in.
1665 */
1666 struct lu_env pc_env;
1667 /**
1668 * CPT the thread is bound on. 1664 * CPT the thread is bound on.
1669 */ 1665 */
1670 int pc_cpt; 1666 int pc_cpt;
diff --git a/drivers/staging/lustre/lustre/include/lustre_obdo.h b/drivers/staging/lustre/lustre/include/lustre_obdo.h
new file mode 100644
index 000000000000..1e12f8c0f157
--- /dev/null
+++ b/drivers/staging/lustre/lustre/include/lustre_obdo.h
@@ -0,0 +1,54 @@
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * GPL HEADER END
21 */
22/*
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright (c) 2011, 2014, Intel Corporation.
27 *
28 * Copyright 2015 Cray Inc, all rights reserved.
29 * Author: Ben Evans.
30 *
31 * Define obdo associated functions
32 * obdo: OBject Device o...
33 */
34
35#ifndef _LUSTRE_OBDO_H_
36#define _LUSTRE_OBDO_H_
37
38#include "lustre/lustre_idl.h"
39
40/**
41 * Create an obdo to send over the wire
42 */
43void lustre_set_wire_obdo(const struct obd_connect_data *ocd,
44 struct obdo *wobdo,
45 const struct obdo *lobdo);
46
47/**
48 * Create a local obdo from a wire based odbo
49 */
50void lustre_get_wire_obdo(const struct obd_connect_data *ocd,
51 struct obdo *lobdo,
52 const struct obdo *wobdo);
53
54#endif
diff --git a/drivers/staging/lustre/lustre/include/lustre_req_layout.h b/drivers/staging/lustre/lustre/include/lustre_req_layout.h
index fbcd39572cd0..cd62ccd53e2c 100644
--- a/drivers/staging/lustre/lustre/include/lustre_req_layout.h
+++ b/drivers/staging/lustre/lustre/include/lustre_req_layout.h
@@ -39,6 +39,8 @@
39#ifndef _LUSTRE_REQ_LAYOUT_H__ 39#ifndef _LUSTRE_REQ_LAYOUT_H__
40#define _LUSTRE_REQ_LAYOUT_H__ 40#define _LUSTRE_REQ_LAYOUT_H__
41 41
42#include <linux/types.h>
43
42/** \defgroup req_layout req_layout 44/** \defgroup req_layout req_layout
43 * 45 *
44 * @{ 46 * @{
@@ -66,11 +68,6 @@ struct req_capsule {
66 __u32 rc_area[RCL_NR][REQ_MAX_FIELD_NR]; 68 __u32 rc_area[RCL_NR][REQ_MAX_FIELD_NR];
67}; 69};
68 70
69#if !defined(__REQ_LAYOUT_USER__)
70
71/* struct ptlrpc_request, lustre_msg* */
72#include "lustre_net.h"
73
74void req_capsule_init(struct req_capsule *pill, struct ptlrpc_request *req, 71void req_capsule_init(struct req_capsule *pill, struct ptlrpc_request *req,
75 enum req_location location); 72 enum req_location location);
76void req_capsule_fini(struct req_capsule *pill); 73void req_capsule_fini(struct req_capsule *pill);
@@ -120,9 +117,6 @@ void req_capsule_shrink(struct req_capsule *pill,
120int req_layout_init(void); 117int req_layout_init(void);
121void req_layout_fini(void); 118void req_layout_fini(void);
122 119
123/* __REQ_LAYOUT_USER__ */
124#endif
125
126extern struct req_format RQF_OBD_PING; 120extern struct req_format RQF_OBD_PING;
127extern struct req_format RQF_OBD_SET_INFO; 121extern struct req_format RQF_OBD_SET_INFO;
128extern struct req_format RQF_SEC_CTX; 122extern struct req_format RQF_SEC_CTX;
diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
index 0f48e9c3d9e3..4ce85064f9d0 100644
--- a/drivers/staging/lustre/lustre/include/obd.h
+++ b/drivers/staging/lustre/lustre/include/obd.h
@@ -43,6 +43,7 @@
43#include "lustre_fld.h" 43#include "lustre_fld.h"
44#include "lustre_handles.h" 44#include "lustre_handles.h"
45#include "lustre_intent.h" 45#include "lustre_intent.h"
46#include "cl_object.h"
46 47
47#define MAX_OBD_DEVICES 8192 48#define MAX_OBD_DEVICES 8192
48 49
@@ -76,6 +77,8 @@ static inline void loi_init(struct lov_oinfo *loi)
76struct lov_stripe_md; 77struct lov_stripe_md;
77struct obd_info; 78struct obd_info;
78 79
80int lov_read_and_clear_async_rc(struct cl_object *clob);
81
79typedef int (*obd_enqueue_update_f)(void *cookie, int rc); 82typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
80 83
81/* obd info for a particular level (lov, osc). */ 84/* obd info for a particular level (lov, osc). */
@@ -284,6 +287,8 @@ struct client_obd {
284 * the transaction has NOT yet committed. 287 * the transaction has NOT yet committed.
285 */ 288 */
286 atomic_long_t cl_unstable_count; 289 atomic_long_t cl_unstable_count;
290 /** Link to osc_shrinker_list */
291 struct list_head cl_shrink_list;
287 292
288 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */ 293 /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
289 atomic_t cl_destroy_in_flight; 294 atomic_t cl_destroy_in_flight;
@@ -398,18 +403,10 @@ struct lmv_tgt_desc {
398 unsigned long ltd_active:1; /* target up for requests */ 403 unsigned long ltd_active:1; /* target up for requests */
399}; 404};
400 405
401enum placement_policy {
402 PLACEMENT_CHAR_POLICY = 0,
403 PLACEMENT_NID_POLICY = 1,
404 PLACEMENT_INVAL_POLICY = 2,
405 PLACEMENT_MAX_POLICY
406};
407
408struct lmv_obd { 406struct lmv_obd {
409 int refcount; 407 int refcount;
410 struct lu_client_fld lmv_fld; 408 struct lu_client_fld lmv_fld;
411 spinlock_t lmv_lock; 409 spinlock_t lmv_lock;
412 enum placement_policy lmv_placement;
413 struct lmv_desc desc; 410 struct lmv_desc desc;
414 struct obd_uuid cluuid; 411 struct obd_uuid cluuid;
415 struct obd_export *exp; 412 struct obd_export *exp;
@@ -478,16 +475,12 @@ struct niobuf_local {
478 * Events signalled through obd_notify() upcall-chain. 475 * Events signalled through obd_notify() upcall-chain.
479 */ 476 */
480enum obd_notify_event { 477enum obd_notify_event {
481 /* target added */
482 OBD_NOTIFY_CREATE,
483 /* Device connect start */ 478 /* Device connect start */
484 OBD_NOTIFY_CONNECT, 479 OBD_NOTIFY_CONNECT,
485 /* Device activated */ 480 /* Device activated */
486 OBD_NOTIFY_ACTIVE, 481 OBD_NOTIFY_ACTIVE,
487 /* Device deactivated */ 482 /* Device deactivated */
488 OBD_NOTIFY_INACTIVE, 483 OBD_NOTIFY_INACTIVE,
489 /* Device disconnected */
490 OBD_NOTIFY_DISCON,
491 /* Connect data for import were changed */ 484 /* Connect data for import were changed */
492 OBD_NOTIFY_OCD, 485 OBD_NOTIFY_OCD,
493 /* Sync request */ 486 /* Sync request */
@@ -758,6 +751,7 @@ struct md_enqueue_info {
758 struct lookup_intent mi_it; 751 struct lookup_intent mi_it;
759 struct lustre_handle mi_lockh; 752 struct lustre_handle mi_lockh;
760 struct inode *mi_dir; 753 struct inode *mi_dir;
754 struct ldlm_enqueue_info mi_einfo;
761 int (*mi_cb)(struct ptlrpc_request *req, 755 int (*mi_cb)(struct ptlrpc_request *req,
762 struct md_enqueue_info *minfo, int rc); 756 struct md_enqueue_info *minfo, int rc);
763 void *mi_cbdata; 757 void *mi_cbdata;
@@ -889,7 +883,7 @@ struct obd_client_handle {
889 struct md_open_data *och_mod; 883 struct md_open_data *och_mod;
890 struct lustre_handle och_lease_handle; /* open lock for lease */ 884 struct lustre_handle och_lease_handle; /* open lock for lease */
891 __u32 och_magic; 885 __u32 och_magic;
892 int och_flags; 886 fmode_t och_flags;
893}; 887};
894 888
895#define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed 889#define OBD_CLIENT_HANDLE_MAGIC 0xd15ea5ed
@@ -975,8 +969,7 @@ struct md_ops {
975 struct lu_fid *fid); 969 struct lu_fid *fid);
976 970
977 int (*intent_getattr_async)(struct obd_export *, 971 int (*intent_getattr_async)(struct obd_export *,
978 struct md_enqueue_info *, 972 struct md_enqueue_info *);
979 struct ldlm_enqueue_info *);
980 973
981 int (*revalidate_lock)(struct obd_export *, struct lookup_intent *, 974 int (*revalidate_lock)(struct obd_export *, struct lookup_intent *,
982 struct lu_fid *, __u64 *bits); 975 struct lu_fid *, __u64 *bits);
diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h
index 7ec25202cd22..083a6ff56a05 100644
--- a/drivers/staging/lustre/lustre/include/obd_class.h
+++ b/drivers/staging/lustre/lustre/include/obd_class.h
@@ -1444,14 +1444,13 @@ static inline int md_init_ea_size(struct obd_export *exp, u32 easize,
1444} 1444}
1445 1445
1446static inline int md_intent_getattr_async(struct obd_export *exp, 1446static inline int md_intent_getattr_async(struct obd_export *exp,
1447 struct md_enqueue_info *minfo, 1447 struct md_enqueue_info *minfo)
1448 struct ldlm_enqueue_info *einfo)
1449{ 1448{
1450 int rc; 1449 int rc;
1451 1450
1452 EXP_CHECK_MD_OP(exp, intent_getattr_async); 1451 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1453 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async); 1452 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1454 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo); 1453 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1455 return rc; 1454 return rc;
1456} 1455}
1457 1456
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index 32b73ee62639..08f97e2117ed 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -162,7 +162,7 @@ void ldlm_extent_add_lock(struct ldlm_resource *res,
162 struct interval_node *found, **root; 162 struct interval_node *found, **root;
163 struct ldlm_interval *node; 163 struct ldlm_interval *node;
164 struct ldlm_extent *extent; 164 struct ldlm_extent *extent;
165 int idx; 165 int idx, rc;
166 166
167 LASSERT(lock->l_granted_mode == lock->l_req_mode); 167 LASSERT(lock->l_granted_mode == lock->l_req_mode);
168 168
@@ -176,7 +176,8 @@ void ldlm_extent_add_lock(struct ldlm_resource *res,
176 176
177 /* node extent initialize */ 177 /* node extent initialize */
178 extent = &lock->l_policy_data.l_extent; 178 extent = &lock->l_policy_data.l_extent;
179 interval_set(&node->li_node, extent->start, extent->end); 179 rc = interval_set(&node->li_node, extent->start, extent->end);
180 LASSERT(!rc);
180 181
181 root = &res->lr_itree[idx].lit_root; 182 root = &res->lr_itree[idx].lit_root;
182 found = interval_insert(&node->li_node, root); 183 found = interval_insert(&node->li_node, root);
@@ -243,7 +244,6 @@ void ldlm_extent_unlink_lock(struct ldlm_lock *lock)
243void ldlm_extent_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy, 244void ldlm_extent_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy,
244 union ldlm_policy_data *lpolicy) 245 union ldlm_policy_data *lpolicy)
245{ 246{
246 memset(lpolicy, 0, sizeof(*lpolicy));
247 lpolicy->l_extent.start = wpolicy->l_extent.start; 247 lpolicy->l_extent.start = wpolicy->l_extent.start;
248 lpolicy->l_extent.end = wpolicy->l_extent.end; 248 lpolicy->l_extent.end = wpolicy->l_extent.end;
249 lpolicy->l_extent.gid = wpolicy->l_extent.gid; 249 lpolicy->l_extent.gid = wpolicy->l_extent.gid;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
index 722160784f83..b7f28b39c7b3 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
@@ -143,7 +143,7 @@ static int ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags,
143 int added = (mode == LCK_NL); 143 int added = (mode == LCK_NL);
144 int overlaps = 0; 144 int overlaps = 0;
145 int splitted = 0; 145 int splitted = 0;
146 const struct ldlm_callback_suite null_cbs = { NULL }; 146 const struct ldlm_callback_suite null_cbs = { };
147 147
148 CDEBUG(D_DLMTRACE, 148 CDEBUG(D_DLMTRACE,
149 "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n", 149 "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
@@ -615,7 +615,6 @@ EXPORT_SYMBOL(ldlm_flock_completion_ast);
615void ldlm_flock_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy, 615void ldlm_flock_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy,
616 union ldlm_policy_data *lpolicy) 616 union ldlm_policy_data *lpolicy)
617{ 617{
618 memset(lpolicy, 0, sizeof(*lpolicy));
619 lpolicy->l_flock.start = wpolicy->l_flock.lfw_start; 618 lpolicy->l_flock.start = wpolicy->l_flock.lfw_start;
620 lpolicy->l_flock.end = wpolicy->l_flock.lfw_end; 619 lpolicy->l_flock.end = wpolicy->l_flock.lfw_end;
621 lpolicy->l_flock.pid = wpolicy->l_flock.lfw_pid; 620 lpolicy->l_flock.pid = wpolicy->l_flock.lfw_pid;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c b/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
index 8e1709dc073c..ae37c3686b1b 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
@@ -57,7 +57,6 @@
57void ldlm_ibits_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy, 57void ldlm_ibits_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy,
58 union ldlm_policy_data *lpolicy) 58 union ldlm_policy_data *lpolicy)
59{ 59{
60 memset(lpolicy, 0, sizeof(*lpolicy));
61 lpolicy->l_inodebits.bits = wpolicy->l_inodebits.bits; 60 lpolicy->l_inodebits.bits = wpolicy->l_inodebits.bits;
62} 61}
63 62
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
index 9be01426c955..3663c5cdb051 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
@@ -336,6 +336,7 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
336 INIT_LIST_HEAD(&cli->cl_lru_list); 336 INIT_LIST_HEAD(&cli->cl_lru_list);
337 spin_lock_init(&cli->cl_lru_list_lock); 337 spin_lock_init(&cli->cl_lru_list_lock);
338 atomic_long_set(&cli->cl_unstable_count, 0); 338 atomic_long_set(&cli->cl_unstable_count, 0);
339 INIT_LIST_HEAD(&cli->cl_shrink_list);
339 340
340 init_waitqueue_head(&cli->cl_destroy_waitq); 341 init_waitqueue_head(&cli->cl_destroy_waitq);
341 atomic_set(&cli->cl_destroy_in_flight, 0); 342 atomic_set(&cli->cl_destroy_in_flight, 0);
@@ -350,13 +351,11 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
350 cli->cl_supp_cksum_types = OBD_CKSUM_CRC32; 351 cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
351 atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS); 352 atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS);
352 353
353 /* This value may be reduced at connect time in 354 /*
354 * ptlrpc_connect_interpret() . We initialize it to only 355 * Set it to possible maximum size. It may be reduced by ocd_brw_size
355 * 1MB until we know what the performance looks like. 356 * from OFD after connecting.
356 * In the future this should likely be increased. LU-1431
357 */ 357 */
358 cli->cl_max_pages_per_rpc = min_t(int, PTLRPC_MAX_BRW_PAGES, 358 cli->cl_max_pages_per_rpc = PTLRPC_MAX_BRW_PAGES;
359 LNET_MTU >> PAGE_SHIFT);
360 359
361 /* 360 /*
362 * set cl_chunkbits default value to PAGE_CACHE_SHIFT, 361 * set cl_chunkbits default value to PAGE_CACHE_SHIFT,
@@ -524,6 +523,8 @@ int client_connect_import(const struct lu_env *env,
524 523
525 rc = ptlrpc_connect_import(imp); 524 rc = ptlrpc_connect_import(imp);
526 if (rc != 0) { 525 if (rc != 0) {
526 if (data && is_mdc)
527 data->ocd_connect_flags &= ~OBD_CONNECT_MULTIMODRPCS;
527 LASSERT(imp->imp_state == LUSTRE_IMP_DISCON); 528 LASSERT(imp->imp_state == LUSTRE_IMP_DISCON);
528 goto out_ldlm; 529 goto out_ldlm;
529 } 530 }
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index a4a291acb659..5a94265fe60b 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -533,6 +533,13 @@ struct ldlm_lock *__ldlm_handle2lock(const struct lustre_handle *handle,
533 if (!lock) 533 if (!lock)
534 return NULL; 534 return NULL;
535 535
536 if (lock->l_export && lock->l_export->exp_failed) {
537 CDEBUG(D_INFO, "lock export failed: lock %p, exp %p\n",
538 lock, lock->l_export);
539 LDLM_LOCK_PUT(lock);
540 return NULL;
541 }
542
536 /* It's unlikely but possible that someone marked the lock as 543 /* It's unlikely but possible that someone marked the lock as
537 * destroyed after we did handle2object on it 544 * destroyed after we did handle2object on it
538 */ 545 */
@@ -1131,8 +1138,7 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
1131 if (!data->lmd_unref && LDLM_HAVE_MASK(lock, GONE)) 1138 if (!data->lmd_unref && LDLM_HAVE_MASK(lock, GONE))
1132 return INTERVAL_ITER_CONT; 1139 return INTERVAL_ITER_CONT;
1133 1140
1134 if ((data->lmd_flags & LDLM_FL_LOCAL_ONLY) && 1141 if (!equi(data->lmd_flags & LDLM_FL_LOCAL_ONLY, ldlm_is_local(lock)))
1135 !ldlm_is_local(lock))
1136 return INTERVAL_ITER_CONT; 1142 return INTERVAL_ITER_CONT;
1137 1143
1138 if (data->lmd_flags & LDLM_FL_TEST_LOCK) { 1144 if (data->lmd_flags & LDLM_FL_TEST_LOCK) {
@@ -1148,7 +1154,7 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
1148 return INTERVAL_ITER_STOP; 1154 return INTERVAL_ITER_STOP;
1149} 1155}
1150 1156
1151static unsigned int itree_overlap_cb(struct interval_node *in, void *args) 1157static enum interval_iter itree_overlap_cb(struct interval_node *in, void *args)
1152{ 1158{
1153 struct ldlm_interval *node = to_ldlm_interval(in); 1159 struct ldlm_interval *node = to_ldlm_interval(in);
1154 struct lock_match_data *data = args; 1160 struct lock_match_data *data = args;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
index c1f8693f94a5..ebfda368b057 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
@@ -1972,7 +1972,7 @@ static int replay_one_lock(struct obd_import *imp, struct ldlm_lock *lock)
1972 LDLM_DEBUG(lock, "replaying lock:"); 1972 LDLM_DEBUG(lock, "replaying lock:");
1973 1973
1974 atomic_inc(&req->rq_import->imp_replay_inflight); 1974 atomic_inc(&req->rq_import->imp_replay_inflight);
1975 CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); 1975 BUILD_BUG_ON(sizeof(*aa) > sizeof(req->rq_async_args));
1976 aa = ptlrpc_req_async_args(req); 1976 aa = ptlrpc_req_async_args(req);
1977 aa->lock_handle = body->lock_handle[0]; 1977 aa->lock_handle = body->lock_handle[0];
1978 req->rq_interpret_reply = (ptlrpc_interpterer_t)replay_lock_interpret; 1978 req->rq_interpret_reply = (ptlrpc_interpterer_t)replay_lock_interpret;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index b22f5bae7201..d16f5e95ef0b 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -1368,7 +1368,7 @@ void ldlm_resource_dump(int level, struct ldlm_resource *res)
1368 struct ldlm_lock *lock; 1368 struct ldlm_lock *lock;
1369 unsigned int granted = 0; 1369 unsigned int granted = 0;
1370 1370
1371 CLASSERT(RES_NAME_SIZE == 4); 1371 BUILD_BUG_ON(RES_NAME_SIZE != 4);
1372 1372
1373 if (!((libcfs_debug | D_ERROR) & level)) 1373 if (!((libcfs_debug | D_ERROR) & level))
1374 return; 1374 return;
diff --git a/drivers/staging/lustre/lustre/llite/dcache.c b/drivers/staging/lustre/lustre/llite/dcache.c
index 65bf0c401b44..966f580e26fb 100644
--- a/drivers/staging/lustre/lustre/llite/dcache.c
+++ b/drivers/staging/lustre/lustre/llite/dcache.c
@@ -247,17 +247,14 @@ static int ll_revalidate_dentry(struct dentry *dentry,
247 return 1; 247 return 1;
248 248
249 /* 249 /*
250 * if open&create is set, talk to MDS to make sure file is created if 250 * VFS warns us that this is the second go around and previous
251 * necessary, because we can't do this in ->open() later since that's 251 * operation failed (most likely open|creat), so this time
252 * called on an inode. return 0 here to let lookup to handle this. 252 * we better talk to the server via the lookup path by name,
253 * not by fid.
253 */ 254 */
254 if ((lookup_flags & (LOOKUP_OPEN | LOOKUP_CREATE)) == 255 if (lookup_flags & LOOKUP_REVAL)
255 (LOOKUP_OPEN | LOOKUP_CREATE))
256 return 0; 256 return 0;
257 257
258 if (lookup_flags & (LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE))
259 return 1;
260
261 if (!dentry_may_statahead(dir, dentry)) 258 if (!dentry_may_statahead(dir, dentry))
262 return 1; 259 return 1;
263 260
diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
index ea5d247a3f70..13b35922a4ca 100644
--- a/drivers/staging/lustre/lustre/llite/dir.c
+++ b/drivers/staging/lustre/lustre/llite/dir.c
@@ -432,7 +432,7 @@ static int ll_dir_setdirstripe(struct inode *parent, struct lmv_user_md *lump,
432 432
433 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent))) 433 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
434 mode &= ~current_umask(); 434 mode &= ~current_umask();
435 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR; 435 mode = (mode & (0777 | S_ISVTX)) | S_IFDIR;
436 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname, 436 op_data = ll_prep_md_op_data(NULL, parent, NULL, dirname,
437 strlen(dirname), mode, LUSTRE_OPC_MKDIR, 437 strlen(dirname), mode, LUSTRE_OPC_MKDIR,
438 lump); 438 lump);
@@ -521,12 +521,15 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
521 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req); 521 rc = md_setattr(sbi->ll_md_exp, op_data, lump, lum_size, &req);
522 ll_finish_md_op_data(op_data); 522 ll_finish_md_op_data(op_data);
523 ptlrpc_req_finished(req); 523 ptlrpc_req_finished(req);
524 if (rc) { 524 if (rc)
525 if (rc != -EPERM && rc != -EACCES) 525 return rc;
526 CERROR("mdc_setattr fails: rc = %d\n", rc);
527 }
528 526
529 /* In the following we use the fact that LOV_USER_MAGIC_V1 and 527#if OBD_OCD_VERSION(2, 13, 53, 0) > LUSTRE_VERSION_CODE
528 /*
529 * 2.9 server has stored filesystem default stripe in ROOT xattr,
530 * and it's stored into system config for backward compatibility.
531 *
532 * In the following we use the fact that LOV_USER_MAGIC_V1 and
530 * LOV_USER_MAGIC_V3 have the same initial fields so we do not 533 * LOV_USER_MAGIC_V3 have the same initial fields so we do not
531 * need to make the distinction between the 2 versions 534 * need to make the distinction between the 2 versions
532 */ 535 */
@@ -567,6 +570,7 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
567end: 570end:
568 kfree(param); 571 kfree(param);
569 } 572 }
573#endif
570 return rc; 574 return rc;
571} 575}
572 576
diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index f634c11216e6..10adfcdd7035 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -122,26 +122,25 @@ static int ll_close_inode_openhandle(struct obd_export *md_exp,
122 enum mds_op_bias bias, 122 enum mds_op_bias bias,
123 void *data) 123 void *data)
124{ 124{
125 struct obd_export *exp = ll_i2mdexp(inode); 125 const struct ll_inode_info *lli = ll_i2info(inode);
126 struct md_op_data *op_data; 126 struct md_op_data *op_data;
127 struct ptlrpc_request *req = NULL; 127 struct ptlrpc_request *req = NULL;
128 struct obd_device *obd = class_exp2obd(exp);
129 int rc; 128 int rc;
130 129
131 if (!obd) { 130 if (!class_exp2obd(md_exp)) {
132 /* 131 CERROR("%s: invalid MDC connection handle closing " DFID "\n",
133 * XXX: in case of LMV, is this correct to access 132 ll_get_fsname(inode->i_sb, NULL, 0),
134 * ->exp_handle? 133 PFID(&lli->lli_fid));
135 */
136 CERROR("Invalid MDC connection handle %#llx\n",
137 ll_i2mdexp(inode)->exp_handle.h_cookie);
138 rc = 0; 134 rc = 0;
139 goto out; 135 goto out;
140 } 136 }
141 137
142 op_data = kzalloc(sizeof(*op_data), GFP_NOFS); 138 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
139 /*
140 * We leak openhandle and request here on error, but not much to be
141 * done in OOM case since app won't retry close on error either.
142 */
143 if (!op_data) { 143 if (!op_data) {
144 /* XXX We leak openhandle and request here. */
145 rc = -ENOMEM; 144 rc = -ENOMEM;
146 goto out; 145 goto out;
147 } 146 }
@@ -170,10 +169,9 @@ static int ll_close_inode_openhandle(struct obd_export *md_exp,
170 } 169 }
171 170
172 rc = md_close(md_exp, op_data, och->och_mod, &req); 171 rc = md_close(md_exp, op_data, och->och_mod, &req);
173 if (rc) { 172 if (rc && rc != -EINTR) {
174 CERROR("%s: inode "DFID" mdc close failed: rc = %d\n", 173 CERROR("%s: inode " DFID " mdc close failed: rc = %d\n",
175 ll_i2mdexp(inode)->exp_obd->obd_name, 174 md_exp->exp_obd->obd_name, PFID(&lli->lli_fid), rc);
176 PFID(ll_inode2fid(inode)), rc);
177 } 175 }
178 176
179 if (op_data->op_bias & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP) && 177 if (op_data->op_bias & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP) &&
@@ -192,8 +190,7 @@ out:
192 och->och_fh.cookie = DEAD_HANDLE_MAGIC; 190 och->och_fh.cookie = DEAD_HANDLE_MAGIC;
193 kfree(och); 191 kfree(och);
194 192
195 if (req) /* This is close request */ 193 ptlrpc_req_finished(req);
196 ptlrpc_req_finished(req);
197 return rc; 194 return rc;
198} 195}
199 196
@@ -420,6 +417,17 @@ out:
420 ptlrpc_req_finished(req); 417 ptlrpc_req_finished(req);
421 ll_intent_drop_lock(itp); 418 ll_intent_drop_lock(itp);
422 419
420 /*
421 * We did open by fid, but by the time we got to the server,
422 * the object disappeared. If this is a create, we cannot really
423 * tell the userspace that the file it was trying to create
424 * does not exist. Instead let's return -ESTALE, and the VFS will
425 * retry the create with LOOKUP_REVAL that we are going to catch
426 * in ll_revalidate_dentry() and use lookup then.
427 */
428 if (rc == -ENOENT && itp->it_op & IT_CREAT)
429 rc = -ESTALE;
430
423 return rc; 431 return rc;
424} 432}
425 433
@@ -1016,7 +1024,7 @@ static bool file_is_noatime(const struct file *file)
1016 return false; 1024 return false;
1017} 1025}
1018 1026
1019void ll_io_init(struct cl_io *io, const struct file *file, int write) 1027static void ll_io_init(struct cl_io *io, const struct file *file, int write)
1020{ 1028{
1021 struct inode *inode = file_inode(file); 1029 struct inode *inode = file_inode(file);
1022 1030
@@ -1821,7 +1829,7 @@ free:
1821 return rc; 1829 return rc;
1822} 1830}
1823 1831
1824static int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss) 1832int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss)
1825{ 1833{
1826 struct md_op_data *op_data; 1834 struct md_op_data *op_data;
1827 int rc; 1835 int rc;
@@ -1883,7 +1891,7 @@ static int ll_hsm_import(struct inode *inode, struct file *file,
1883 goto free_hss; 1891 goto free_hss;
1884 } 1892 }
1885 1893
1886 attr->ia_mode = hui->hui_mode & (S_IRWXU | S_IRWXG | S_IRWXO); 1894 attr->ia_mode = hui->hui_mode & 0777;
1887 attr->ia_mode |= S_IFREG; 1895 attr->ia_mode |= S_IFREG;
1888 attr->ia_uid = make_kuid(&init_user_ns, hui->hui_uid); 1896 attr->ia_uid = make_kuid(&init_user_ns, hui->hui_uid);
1889 attr->ia_gid = make_kgid(&init_user_ns, hui->hui_gid); 1897 attr->ia_gid = make_kgid(&init_user_ns, hui->hui_gid);
@@ -2618,18 +2626,18 @@ int ll_migrate(struct inode *parent, struct file *file, int mdtidx,
2618 ll_get_fsname(parent->i_sb, NULL, 0), name, 2626 ll_get_fsname(parent->i_sb, NULL, 0), name,
2619 PFID(&op_data->op_fid3)); 2627 PFID(&op_data->op_fid3));
2620 rc = -EINVAL; 2628 rc = -EINVAL;
2621 goto out_free; 2629 goto out_unlock;
2622 } 2630 }
2623 2631
2624 rc = ll_get_mdt_idx_by_fid(ll_i2sbi(parent), &op_data->op_fid3); 2632 rc = ll_get_mdt_idx_by_fid(ll_i2sbi(parent), &op_data->op_fid3);
2625 if (rc < 0) 2633 if (rc < 0)
2626 goto out_free; 2634 goto out_unlock;
2627 2635
2628 if (rc == mdtidx) { 2636 if (rc == mdtidx) {
2629 CDEBUG(D_INFO, "%s:"DFID" is already on MDT%d.\n", name, 2637 CDEBUG(D_INFO, "%s:"DFID" is already on MDT%d.\n", name,
2630 PFID(&op_data->op_fid3), mdtidx); 2638 PFID(&op_data->op_fid3), mdtidx);
2631 rc = 0; 2639 rc = 0;
2632 goto out_free; 2640 goto out_unlock;
2633 } 2641 }
2634again: 2642again:
2635 if (S_ISREG(child_inode->i_mode)) { 2643 if (S_ISREG(child_inode->i_mode)) {
@@ -2637,13 +2645,13 @@ again:
2637 if (IS_ERR(och)) { 2645 if (IS_ERR(och)) {
2638 rc = PTR_ERR(och); 2646 rc = PTR_ERR(och);
2639 och = NULL; 2647 och = NULL;
2640 goto out_free; 2648 goto out_unlock;
2641 } 2649 }
2642 2650
2643 rc = ll_data_version(child_inode, &data_version, 2651 rc = ll_data_version(child_inode, &data_version,
2644 LL_DV_WR_FLUSH); 2652 LL_DV_WR_FLUSH);
2645 if (rc) 2653 if (rc)
2646 goto out_free; 2654 goto out_close;
2647 2655
2648 op_data->op_handle = och->och_fh; 2656 op_data->op_handle = och->och_fh;
2649 op_data->op_data = och->och_mod; 2657 op_data->op_data = och->och_mod;
@@ -2656,40 +2664,45 @@ again:
2656 op_data->op_cli_flags = CLI_MIGRATE; 2664 op_data->op_cli_flags = CLI_MIGRATE;
2657 rc = md_rename(ll_i2sbi(parent)->ll_md_exp, op_data, name, 2665 rc = md_rename(ll_i2sbi(parent)->ll_md_exp, op_data, name,
2658 namelen, name, namelen, &request); 2666 namelen, name, namelen, &request);
2659 if (!rc) 2667 if (!rc) {
2668 LASSERT(request);
2660 ll_update_times(request, parent); 2669 ll_update_times(request, parent);
2661 2670
2662 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY); 2671 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
2663 if (!body) { 2672 LASSERT(body);
2664 rc = -EPROTO; 2673
2665 goto out_free; 2674 /*
2675 * If the server does release layout lock, then we cleanup
2676 * the client och here, otherwise release it in out_close:
2677 */
2678 if (och && body->mbo_valid & OBD_MD_CLOSE_INTENT_EXECED) {
2679 obd_mod_put(och->och_mod);
2680 md_clear_open_replay_data(ll_i2sbi(parent)->ll_md_exp,
2681 och);
2682 och->och_fh.cookie = DEAD_HANDLE_MAGIC;
2683 kfree(och);
2684 och = NULL;
2685 }
2666 } 2686 }
2667 2687
2668 /* 2688 if (request) {
2669 * If the server does release layout lock, then we cleanup 2689 ptlrpc_req_finished(request);
2670 * the client och here, otherwise release it in out_free: 2690 request = NULL;
2671 */
2672 if (och && body->mbo_valid & OBD_MD_CLOSE_INTENT_EXECED) {
2673 obd_mod_put(och->och_mod);
2674 md_clear_open_replay_data(ll_i2sbi(parent)->ll_md_exp, och);
2675 och->och_fh.cookie = DEAD_HANDLE_MAGIC;
2676 kfree(och);
2677 och = NULL;
2678 } 2691 }
2679 2692
2680 ptlrpc_req_finished(request);
2681 /* Try again if the file layout has changed. */ 2693 /* Try again if the file layout has changed. */
2682 if (rc == -EAGAIN && S_ISREG(child_inode->i_mode)) 2694 if (rc == -EAGAIN && S_ISREG(child_inode->i_mode))
2683 goto again; 2695 goto again;
2684out_free:
2685 if (child_inode) {
2686 if (och) /* close the file */
2687 ll_lease_close(och, child_inode, NULL);
2688 clear_nlink(child_inode);
2689 inode_unlock(child_inode);
2690 iput(child_inode);
2691 }
2692 2696
2697out_close:
2698 if (och) /* close the file */
2699 ll_lease_close(och, child_inode, NULL);
2700 if (!rc)
2701 clear_nlink(child_inode);
2702out_unlock:
2703 inode_unlock(child_inode);
2704 iput(child_inode);
2705out_free:
2693 ll_finish_md_op_data(op_data); 2706 ll_finish_md_op_data(op_data);
2694 return rc; 2707 return rc;
2695} 2708}
diff --git a/drivers/staging/lustre/lustre/llite/lcommon_cl.c b/drivers/staging/lustre/lustre/llite/lcommon_cl.c
index dd1cfd8f5213..f1036f477a51 100644
--- a/drivers/staging/lustre/lustre/llite/lcommon_cl.c
+++ b/drivers/staging/lustre/lustre/llite/lcommon_cl.c
@@ -94,6 +94,7 @@ int cl_setattr_ost(struct cl_object *obj, const struct iattr *attr,
94 94
95 io = vvp_env_thread_io(env); 95 io = vvp_env_thread_io(env);
96 io->ci_obj = obj; 96 io->ci_obj = obj;
97 io->ci_verify_layout = 1;
97 98
98 io->u.ci_setattr.sa_attr.lvb_atime = LTIME_S(attr->ia_atime); 99 io->u.ci_setattr.sa_attr.lvb_atime = LTIME_S(attr->ia_atime);
99 io->u.ci_setattr.sa_attr.lvb_mtime = LTIME_S(attr->ia_mtime); 100 io->u.ci_setattr.sa_attr.lvb_mtime = LTIME_S(attr->ia_mtime);
@@ -120,13 +121,7 @@ again:
120 cl_io_fini(env, io); 121 cl_io_fini(env, io);
121 if (unlikely(io->ci_need_restart)) 122 if (unlikely(io->ci_need_restart))
122 goto again; 123 goto again;
123 /* HSM import case: file is released, cannot be restored 124
124 * no need to fail except if restore registration failed
125 * with -ENODATA
126 */
127 if (result == -ENODATA && io->ci_restore_needed &&
128 io->ci_result != -ENODATA)
129 result = 0;
130 cl_env_put(env, &refcheck); 125 cl_env_put(env, &refcheck);
131 return result; 126 return result;
132} 127}
diff --git a/drivers/staging/lustre/lustre/llite/lcommon_misc.c b/drivers/staging/lustre/lustre/llite/lcommon_misc.c
index f48660ed350f..f0c132e2cf92 100644
--- a/drivers/staging/lustre/lustre/llite/lcommon_misc.c
+++ b/drivers/staging/lustre/lustre/llite/lcommon_misc.c
@@ -33,6 +33,7 @@
33 * future). 33 * future).
34 * 34 *
35 */ 35 */
36#define DEBUG_SUBSYSTEM S_LLITE
36#include "../include/obd_class.h" 37#include "../include/obd_class.h"
37#include "../include/obd_support.h" 38#include "../include/obd_support.h"
38#include "../include/obd.h" 39#include "../include/obd.h"
@@ -132,7 +133,6 @@ int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
132 133
133 io = vvp_env_thread_io(env); 134 io = vvp_env_thread_io(env);
134 io->ci_obj = obj; 135 io->ci_obj = obj;
135 io->ci_ignore_layout = 1;
136 136
137 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj); 137 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj);
138 if (rc != 0) { 138 if (rc != 0) {
diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h
index 065a9a7e120a..ecdfd0c29b7f 100644
--- a/drivers/staging/lustre/lustre/llite/llite_internal.h
+++ b/drivers/staging/lustre/lustre/llite/llite_internal.h
@@ -281,10 +281,8 @@ static inline struct ll_inode_info *ll_i2info(struct inode *inode)
281 return container_of(inode, struct ll_inode_info, lli_vfs_inode); 281 return container_of(inode, struct ll_inode_info, lli_vfs_inode);
282} 282}
283 283
284/* default to about 40meg of readahead on a given system. That much tied 284/* default to about 64M of readahead on a given system. */
285 * up in 512k readahead requests serviced at 40ms each is about 1GB/s. 285#define SBI_DEFAULT_READAHEAD_MAX (64UL << (20 - PAGE_SHIFT))
286 */
287#define SBI_DEFAULT_READAHEAD_MAX (40UL << (20 - PAGE_SHIFT))
288 286
289/* default to read-ahead full files smaller than 2MB on the second read */ 287/* default to read-ahead full files smaller than 2MB on the second read */
290#define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_SHIFT)) 288#define SBI_DEFAULT_READAHEAD_WHOLE_MAX (2UL << (20 - PAGE_SHIFT))
@@ -321,6 +319,9 @@ struct ll_ra_info {
321struct ra_io_arg { 319struct ra_io_arg {
322 unsigned long ria_start; /* start offset of read-ahead*/ 320 unsigned long ria_start; /* start offset of read-ahead*/
323 unsigned long ria_end; /* end offset of read-ahead*/ 321 unsigned long ria_end; /* end offset of read-ahead*/
322 unsigned long ria_reserved; /* reserved pages for read-ahead */
323 unsigned long ria_end_min; /* minimum end to cover current read */
324 bool ria_eof; /* reach end of file */
324 /* If stride read pattern is detected, ria_stoff means where 325 /* If stride read pattern is detected, ria_stoff means where
325 * stride read is started. Note: for normal read-ahead, the 326 * stride read is started. Note: for normal read-ahead, the
326 * value here is meaningless, and also it will not be accessed 327 * value here is meaningless, and also it will not be accessed
@@ -505,6 +506,7 @@ struct ll_sb_info {
505 */ 506 */
506 /* root squash */ 507 /* root squash */
507 struct root_squash_info ll_squash; 508 struct root_squash_info ll_squash;
509 struct path ll_mnt;
508 510
509 __kernel_fsid_t ll_fsid; 511 __kernel_fsid_t ll_fsid;
510 struct kobject ll_kobj; /* sysfs object */ 512 struct kobject ll_kobj; /* sysfs object */
@@ -551,6 +553,11 @@ struct ll_readahead_state {
551 */ 553 */
552 unsigned long ras_window_start, ras_window_len; 554 unsigned long ras_window_start, ras_window_len;
553 /* 555 /*
556 * Optimal RPC size. It decides how many pages will be sent
557 * for each read-ahead.
558 */
559 unsigned long ras_rpc_size;
560 /*
554 * Where next read-ahead should start at. This lies within read-ahead 561 * Where next read-ahead should start at. This lies within read-ahead
555 * window. Read-ahead window is read in pieces rather than at once 562 * window. Read-ahead window is read in pieces rather than at once
556 * because: 1. lustre limits total number of pages under read-ahead by 563 * because: 1. lustre limits total number of pages under read-ahead by
@@ -766,6 +773,7 @@ int ll_merge_attr(const struct lu_env *env, struct inode *inode);
766int ll_fid2path(struct inode *inode, void __user *arg); 773int ll_fid2path(struct inode *inode, void __user *arg);
767int ll_data_version(struct inode *inode, __u64 *data_version, int flags); 774int ll_data_version(struct inode *inode, __u64 *data_version, int flags);
768int ll_hsm_release(struct inode *inode); 775int ll_hsm_release(struct inode *inode);
776int ll_hsm_state_set(struct inode *inode, struct hsm_state_set *hss);
769 777
770/* llite/dcache.c */ 778/* llite/dcache.c */
771 779
diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 25f5aed97f63..b229cbc7bb33 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -103,6 +103,7 @@ static struct ll_sb_info *ll_init_sbi(struct super_block *sb)
103 sbi->ll_flags |= LL_SBI_CHECKSUM; 103 sbi->ll_flags |= LL_SBI_CHECKSUM;
104 104
105 sbi->ll_flags |= LL_SBI_LRU_RESIZE; 105 sbi->ll_flags |= LL_SBI_LRU_RESIZE;
106 sbi->ll_flags |= LL_SBI_LAZYSTATFS;
106 107
107 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) { 108 for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
108 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i]. 109 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
@@ -303,6 +304,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
303 sb->s_magic = LL_SUPER_MAGIC; 304 sb->s_magic = LL_SUPER_MAGIC;
304 sb->s_maxbytes = MAX_LFS_FILESIZE; 305 sb->s_maxbytes = MAX_LFS_FILESIZE;
305 sbi->ll_namelen = osfs->os_namelen; 306 sbi->ll_namelen = osfs->os_namelen;
307 sbi->ll_mnt.mnt = current->fs->root.mnt;
306 308
307 if ((sbi->ll_flags & LL_SBI_USER_XATTR) && 309 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
308 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) { 310 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
@@ -1402,7 +1404,11 @@ static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1402 * cache is not cleared yet. 1404 * cache is not cleared yet.
1403 */ 1405 */
1404 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE); 1406 op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1407 if (S_ISREG(inode->i_mode))
1408 inode_lock(inode);
1405 rc = simple_setattr(dentry, &op_data->op_attr); 1409 rc = simple_setattr(dentry, &op_data->op_attr);
1410 if (S_ISREG(inode->i_mode))
1411 inode_unlock(inode);
1406 op_data->op_attr.ia_valid = ia_valid; 1412 op_data->op_attr.ia_valid = ia_valid;
1407 1413
1408 rc = ll_update_inode(inode, &md); 1414 rc = ll_update_inode(inode, &md);
@@ -1431,7 +1437,6 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1431 struct inode *inode = d_inode(dentry); 1437 struct inode *inode = d_inode(dentry);
1432 struct ll_inode_info *lli = ll_i2info(inode); 1438 struct ll_inode_info *lli = ll_i2info(inode);
1433 struct md_op_data *op_data = NULL; 1439 struct md_op_data *op_data = NULL;
1434 bool file_is_released = false;
1435 int rc = 0; 1440 int rc = 0;
1436 1441
1437 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, valid %x, hsm_import %d\n", 1442 CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, valid %x, hsm_import %d\n",
@@ -1486,76 +1491,35 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1486 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime), 1491 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1487 (s64)ktime_get_real_seconds()); 1492 (s64)ktime_get_real_seconds());
1488 1493
1489 /* We always do an MDS RPC, even if we're only changing the size; 1494 if (S_ISREG(inode->i_mode))
1490 * only the MDS knows whether truncate() should fail with -ETXTBUSY
1491 */
1492
1493 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1494 if (!op_data)
1495 return -ENOMEM;
1496
1497 if (!S_ISDIR(inode->i_mode))
1498 inode_unlock(inode); 1495 inode_unlock(inode);
1499 1496
1500 /* truncate on a released file must failed with -ENODATA, 1497 /*
1501 * so size must not be set on MDS for released file 1498 * We always do an MDS RPC, even if we're only changing the size;
1502 * but other attributes must be set 1499 * only the MDS knows whether truncate() should fail with -ETXTBUSY
1503 */ 1500 */
1504 if (S_ISREG(inode->i_mode)) { 1501 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1505 struct cl_layout cl = { 1502 if (!op_data) {
1506 .cl_is_released = false, 1503 rc = -ENOMEM;
1507 }; 1504 goto out;
1508 struct lu_env *env; 1505 }
1509 int refcheck;
1510 __u32 gen;
1511 1506
1512 rc = ll_layout_refresh(inode, &gen); 1507 op_data->op_attr = *attr;
1513 if (rc < 0)
1514 goto out;
1515 1508
1509 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1516 /* 1510 /*
1517 * XXX: the only place we need to know the layout type, 1511 * If we are changing file size, file content is
1518 * this will be removed by a later patch. -Jinshan 1512 * modified, flag it.
1519 */ 1513 */
1520 env = cl_env_get(&refcheck); 1514 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1521 if (IS_ERR(env)) { 1515 op_data->op_bias |= MDS_DATA_MODIFIED;
1522 rc = PTR_ERR(env);
1523 goto out;
1524 }
1525
1526 rc = cl_object_layout_get(env, lli->lli_clob, &cl);
1527 cl_env_put(env, &refcheck);
1528 if (rc < 0)
1529 goto out;
1530
1531 file_is_released = cl.cl_is_released;
1532
1533 if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1534 if (file_is_released) {
1535 rc = ll_layout_restore(inode, 0, attr->ia_size);
1536 if (rc < 0)
1537 goto out;
1538
1539 file_is_released = false;
1540 ll_layout_refresh(inode, &gen);
1541 }
1542
1543 /*
1544 * If we are changing file size, file content is
1545 * modified, flag it.
1546 */
1547 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1548 op_data->op_bias |= MDS_DATA_MODIFIED;
1549 }
1550 } 1516 }
1551 1517
1552 memcpy(&op_data->op_attr, attr, sizeof(*attr));
1553
1554 rc = ll_md_setattr(dentry, op_data); 1518 rc = ll_md_setattr(dentry, op_data);
1555 if (rc) 1519 if (rc)
1556 goto out; 1520 goto out;
1557 1521
1558 if (!S_ISREG(inode->i_mode) || file_is_released) { 1522 if (!S_ISREG(inode->i_mode) || hsm_import) {
1559 rc = 0; 1523 rc = 0;
1560 goto out; 1524 goto out;
1561 } 1525 }
@@ -1572,11 +1536,40 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1572 */ 1536 */
1573 rc = cl_setattr_ost(ll_i2info(inode)->lli_clob, attr, 0); 1537 rc = cl_setattr_ost(ll_i2info(inode)->lli_clob, attr, 0);
1574 } 1538 }
1539
1540 /*
1541 * If the file was restored, it needs to set dirty flag.
1542 *
1543 * We've already sent MDS_DATA_MODIFIED flag in
1544 * ll_md_setattr() for truncate. However, the MDT refuses to
1545 * set the HS_DIRTY flag on released files, so we have to set
1546 * it again if the file has been restored. Please check how
1547 * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
1548 *
1549 * Please notice that if the file is not released, the previous
1550 * MDS_DATA_MODIFIED has taken effect and usually
1551 * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
1552 * This way we can save an RPC for common open + trunc
1553 * operation.
1554 */
1555 if (test_and_clear_bit(LLIF_DATA_MODIFIED, &lli->lli_flags)) {
1556 struct hsm_state_set hss = {
1557 .hss_valid = HSS_SETMASK,
1558 .hss_setmask = HS_DIRTY,
1559 };
1560 int rc2;
1561
1562 rc2 = ll_hsm_state_set(inode, &hss);
1563 if (rc2 < 0)
1564 CERROR(DFID "HSM set dirty failed: rc2 = %d\n",
1565 PFID(ll_inode2fid(inode)), rc2);
1566 }
1567
1575out: 1568out:
1576 if (op_data) 1569 if (op_data)
1577 ll_finish_md_op_data(op_data); 1570 ll_finish_md_op_data(op_data);
1578 1571
1579 if (!S_ISDIR(inode->i_mode)) { 1572 if (S_ISREG(inode->i_mode)) {
1580 inode_lock(inode); 1573 inode_lock(inode);
1581 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import) 1574 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1582 inode_dio_wait(inode); 1575 inode_dio_wait(inode);
@@ -1599,7 +1592,7 @@ int ll_setattr(struct dentry *de, struct iattr *attr)
1599 if (((attr->ia_valid & (ATTR_MODE | ATTR_FORCE | ATTR_SIZE)) == 1592 if (((attr->ia_valid & (ATTR_MODE | ATTR_FORCE | ATTR_SIZE)) ==
1600 (ATTR_SIZE | ATTR_MODE)) && 1593 (ATTR_SIZE | ATTR_MODE)) &&
1601 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) || 1594 (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1602 (((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) && 1595 (((mode & (S_ISGID | 0010)) == (S_ISGID | 0010)) &&
1603 !(attr->ia_mode & S_ISGID)))) 1596 !(attr->ia_mode & S_ISGID))))
1604 attr->ia_valid |= ATTR_FORCE; 1597 attr->ia_valid |= ATTR_FORCE;
1605 1598
@@ -1610,7 +1603,7 @@ int ll_setattr(struct dentry *de, struct iattr *attr)
1610 attr->ia_valid |= ATTR_KILL_SUID; 1603 attr->ia_valid |= ATTR_KILL_SUID;
1611 1604
1612 if ((attr->ia_valid & ATTR_MODE) && 1605 if ((attr->ia_valid & ATTR_MODE) &&
1613 ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) && 1606 ((mode & (S_ISGID | 0010)) == (S_ISGID | 0010)) &&
1614 !(attr->ia_mode & S_ISGID) && 1607 !(attr->ia_mode & S_ISGID) &&
1615 !(attr->ia_valid & ATTR_KILL_SGID)) 1608 !(attr->ia_valid & ATTR_KILL_SGID))
1616 attr->ia_valid |= ATTR_KILL_SGID; 1609 attr->ia_valid |= ATTR_KILL_SGID;
@@ -1998,6 +1991,8 @@ void ll_umount_begin(struct super_block *sb)
1998 struct ll_sb_info *sbi = ll_s2sbi(sb); 1991 struct ll_sb_info *sbi = ll_s2sbi(sb);
1999 struct obd_device *obd; 1992 struct obd_device *obd;
2000 struct obd_ioctl_data *ioc_data; 1993 struct obd_ioctl_data *ioc_data;
1994 wait_queue_head_t waitq;
1995 struct l_wait_info lwi;
2001 1996
2002 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb, 1997 CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2003 sb->s_count, atomic_read(&sb->s_active)); 1998 sb->s_count, atomic_read(&sb->s_active));
@@ -2030,9 +2025,14 @@ void ll_umount_begin(struct super_block *sb)
2030 } 2025 }
2031 2026
2032 /* Really, we'd like to wait until there are no requests outstanding, 2027 /* Really, we'd like to wait until there are no requests outstanding,
2033 * and then continue. For now, we just invalidate the requests, 2028 * and then continue. For now, we just periodically checking for vfs
2034 * schedule() and sleep one second if needed, and hope. 2029 * to decrement mnt_cnt and hope to finish it within 10sec.
2035 */ 2030 */
2031 init_waitqueue_head(&waitq);
2032 lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10),
2033 cfs_time_seconds(1), NULL, NULL);
2034 l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi);
2035
2036 schedule(); 2036 schedule();
2037} 2037}
2038 2038
diff --git a/drivers/staging/lustre/lustre/llite/lproc_llite.c b/drivers/staging/lustre/lustre/llite/lproc_llite.c
index 03682c10fc9e..f3ee584157e0 100644
--- a/drivers/staging/lustre/lustre/llite/lproc_llite.c
+++ b/drivers/staging/lustre/lustre/llite/lproc_llite.c
@@ -924,27 +924,29 @@ static ssize_t ll_unstable_stats_seq_write(struct file *file,
924} 924}
925LPROC_SEQ_FOPS(ll_unstable_stats); 925LPROC_SEQ_FOPS(ll_unstable_stats);
926 926
927static ssize_t root_squash_show(struct kobject *kobj, struct attribute *attr, 927static int ll_root_squash_seq_show(struct seq_file *m, void *v)
928 char *buf)
929{ 928{
930 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, 929 struct super_block *sb = m->private;
931 ll_kobj); 930 struct ll_sb_info *sbi = ll_s2sbi(sb);
932 struct root_squash_info *squash = &sbi->ll_squash; 931 struct root_squash_info *squash = &sbi->ll_squash;
933 932
934 return sprintf(buf, "%u:%u\n", squash->rsi_uid, squash->rsi_gid); 933 seq_printf(m, "%u:%u\n", squash->rsi_uid, squash->rsi_gid);
934 return 0;
935} 935}
936 936
937static ssize_t root_squash_store(struct kobject *kobj, struct attribute *attr, 937static ssize_t ll_root_squash_seq_write(struct file *file,
938 const char *buffer, size_t count) 938 const char __user *buffer,
939 size_t count, loff_t *off)
939{ 940{
940 struct ll_sb_info *sbi = container_of(kobj, struct ll_sb_info, 941 struct seq_file *m = file->private_data;
941 ll_kobj); 942 struct super_block *sb = m->private;
943 struct ll_sb_info *sbi = ll_s2sbi(sb);
942 struct root_squash_info *squash = &sbi->ll_squash; 944 struct root_squash_info *squash = &sbi->ll_squash;
943 945
944 return lprocfs_wr_root_squash(buffer, count, squash, 946 return lprocfs_wr_root_squash(buffer, count, squash,
945 ll_get_fsname(sbi->ll_sb, NULL, 0)); 947 ll_get_fsname(sb, NULL, 0));
946} 948}
947LUSTRE_RW_ATTR(root_squash); 949LPROC_SEQ_FOPS(ll_root_squash);
948 950
949static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v) 951static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
950{ 952{
@@ -997,6 +999,8 @@ static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
997 { "statahead_stats", &ll_statahead_stats_fops, NULL, 0 }, 999 { "statahead_stats", &ll_statahead_stats_fops, NULL, 0 },
998 { "unstable_stats", &ll_unstable_stats_fops, NULL }, 1000 { "unstable_stats", &ll_unstable_stats_fops, NULL },
999 { "sbi_flags", &ll_sbi_flags_fops, NULL, 0 }, 1001 { "sbi_flags", &ll_sbi_flags_fops, NULL, 0 },
1002 { .name = "root_squash",
1003 .fops = &ll_root_squash_fops },
1000 { .name = "nosquash_nids", 1004 { .name = "nosquash_nids",
1001 .fops = &ll_nosquash_nids_fops }, 1005 .fops = &ll_nosquash_nids_fops },
1002 { NULL } 1006 { NULL }
@@ -1027,7 +1031,6 @@ static struct attribute *llite_attrs[] = {
1027 &lustre_attr_max_easize.attr, 1031 &lustre_attr_max_easize.attr,
1028 &lustre_attr_default_easize.attr, 1032 &lustre_attr_default_easize.attr,
1029 &lustre_attr_xattr_cache.attr, 1033 &lustre_attr_xattr_cache.attr,
1030 &lustre_attr_root_squash.attr,
1031 NULL, 1034 NULL,
1032}; 1035};
1033 1036
diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
index a8f4e7fb0a46..fc176540bb95 100644
--- a/drivers/staging/lustre/lustre/llite/namei.c
+++ b/drivers/staging/lustre/lustre/llite/namei.c
@@ -994,11 +994,6 @@ static int ll_create_nd(struct inode *dir, struct dentry *dentry,
994 return rc; 994 return rc;
995} 995}
996 996
997/* ll_unlink() doesn't update the inode with the new link count.
998 * Instead, ll_ddelete() and ll_d_iput() will update it based upon if there
999 * is any lock existing. They will recycle dentries and inodes based upon locks
1000 * too. b=20433
1001 */
1002static int ll_unlink(struct inode *dir, struct dentry *dchild) 997static int ll_unlink(struct inode *dir, struct dentry *dchild)
1003{ 998{
1004 struct ptlrpc_request *request = NULL; 999 struct ptlrpc_request *request = NULL;
@@ -1041,7 +1036,7 @@ static int ll_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
1041 1036
1042 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir))) 1037 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1043 mode &= ~current_umask(); 1038 mode &= ~current_umask();
1044 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR; 1039 mode = (mode & (0777 | S_ISVTX)) | S_IFDIR;
1045 1040
1046 err = ll_new_node(dir, dentry, NULL, mode, 0, LUSTRE_OPC_MKDIR); 1041 err = ll_new_node(dir, dentry, NULL, mode, 0, LUSTRE_OPC_MKDIR);
1047 if (!err) 1042 if (!err)
@@ -1089,7 +1084,7 @@ static int ll_symlink(struct inode *dir, struct dentry *dentry,
1089 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),target=%.*s\n", 1084 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),target=%.*s\n",
1090 dentry, PFID(ll_inode2fid(dir)), dir, 3000, oldname); 1085 dentry, PFID(ll_inode2fid(dir)), dir, 3000, oldname);
1091 1086
1092 err = ll_new_node(dir, dentry, oldname, S_IFLNK | S_IRWXUGO, 1087 err = ll_new_node(dir, dentry, oldname, S_IFLNK | 0777,
1093 0, LUSTRE_OPC_SYMLINK); 1088 0, LUSTRE_OPC_SYMLINK);
1094 1089
1095 if (!err) 1090 if (!err)
diff --git a/drivers/staging/lustre/lustre/llite/range_lock.c b/drivers/staging/lustre/lustre/llite/range_lock.c
index 94c818f1478b..14148a097476 100644
--- a/drivers/staging/lustre/lustre/llite/range_lock.c
+++ b/drivers/staging/lustre/lustre/llite/range_lock.c
@@ -61,17 +61,23 @@ void range_lock_tree_init(struct range_lock_tree *tree)
61 * Pre: Caller should have allocated the range lock node. 61 * Pre: Caller should have allocated the range lock node.
62 * Post: The range lock node is meant to cover [start, end] region 62 * Post: The range lock node is meant to cover [start, end] region
63 */ 63 */
64void range_lock_init(struct range_lock *lock, __u64 start, __u64 end) 64int range_lock_init(struct range_lock *lock, __u64 start, __u64 end)
65{ 65{
66 int rc;
67
66 memset(&lock->rl_node, 0, sizeof(lock->rl_node)); 68 memset(&lock->rl_node, 0, sizeof(lock->rl_node));
67 if (end != LUSTRE_EOF) 69 if (end != LUSTRE_EOF)
68 end >>= PAGE_SHIFT; 70 end >>= PAGE_SHIFT;
69 interval_set(&lock->rl_node, start >> PAGE_SHIFT, end); 71 rc = interval_set(&lock->rl_node, start >> PAGE_SHIFT, end);
72 if (rc)
73 return rc;
74
70 INIT_LIST_HEAD(&lock->rl_next_lock); 75 INIT_LIST_HEAD(&lock->rl_next_lock);
71 lock->rl_task = NULL; 76 lock->rl_task = NULL;
72 lock->rl_lock_count = 0; 77 lock->rl_lock_count = 0;
73 lock->rl_blocking_ranges = 0; 78 lock->rl_blocking_ranges = 0;
74 lock->rl_sequence = 0; 79 lock->rl_sequence = 0;
80 return rc;
75} 81}
76 82
77static inline struct range_lock *next_lock(struct range_lock *lock) 83static inline struct range_lock *next_lock(struct range_lock *lock)
diff --git a/drivers/staging/lustre/lustre/llite/range_lock.h b/drivers/staging/lustre/lustre/llite/range_lock.h
index c6d04a6f99fd..779091ccec4e 100644
--- a/drivers/staging/lustre/lustre/llite/range_lock.h
+++ b/drivers/staging/lustre/lustre/llite/range_lock.h
@@ -76,7 +76,7 @@ struct range_lock_tree {
76}; 76};
77 77
78void range_lock_tree_init(struct range_lock_tree *tree); 78void range_lock_tree_init(struct range_lock_tree *tree);
79void range_lock_init(struct range_lock *lock, __u64 start, __u64 end); 79int range_lock_init(struct range_lock *lock, __u64 start, __u64 end);
80int range_lock(struct range_lock_tree *tree, struct range_lock *lock); 80int range_lock(struct range_lock_tree *tree, struct range_lock *lock);
81void range_unlock(struct range_lock_tree *tree, struct range_lock *lock); 81void range_unlock(struct range_lock_tree *tree, struct range_lock *lock);
82#endif 82#endif
diff --git a/drivers/staging/lustre/lustre/llite/rw.c b/drivers/staging/lustre/lustre/llite/rw.c
index f10e092979fe..50d027e0cfab 100644
--- a/drivers/staging/lustre/lustre/llite/rw.c
+++ b/drivers/staging/lustre/lustre/llite/rw.c
@@ -92,25 +92,6 @@ static unsigned long ll_ra_count_get(struct ll_sb_info *sbi,
92 goto out; 92 goto out;
93 } 93 }
94 94
95 /* If the non-strided (ria_pages == 0) readahead window
96 * (ria_start + ret) has grown across an RPC boundary, then trim
97 * readahead size by the amount beyond the RPC so it ends on an
98 * RPC boundary. If the readahead window is already ending on
99 * an RPC boundary (beyond_rpc == 0), or smaller than a full
100 * RPC (beyond_rpc < ret) the readahead size is unchanged.
101 * The (beyond_rpc != 0) check is skipped since the conditional
102 * branch is more expensive than subtracting zero from the result.
103 *
104 * Strided read is left unaligned to avoid small fragments beyond
105 * the RPC boundary from needing an extra read RPC.
106 */
107 if (ria->ria_pages == 0) {
108 long beyond_rpc = (ria->ria_start + ret) % PTLRPC_MAX_BRW_PAGES;
109
110 if (/* beyond_rpc != 0 && */ beyond_rpc < ret)
111 ret -= beyond_rpc;
112 }
113
114 if (atomic_add_return(ret, &ra->ra_cur_pages) > ra->ra_max_pages) { 95 if (atomic_add_return(ret, &ra->ra_cur_pages) > ra->ra_max_pages) {
115 atomic_sub(ret, &ra->ra_cur_pages); 96 atomic_sub(ret, &ra->ra_cur_pages);
116 ret = 0; 97 ret = 0;
@@ -147,11 +128,12 @@ void ll_ra_stats_inc(struct inode *inode, enum ra_stat which)
147 128
148#define RAS_CDEBUG(ras) \ 129#define RAS_CDEBUG(ras) \
149 CDEBUG(D_READA, \ 130 CDEBUG(D_READA, \
150 "lrp %lu cr %lu cp %lu ws %lu wl %lu nra %lu r %lu ri %lu" \ 131 "lrp %lu cr %lu cp %lu ws %lu wl %lu nra %lu rpc %lu " \
151 "csr %lu sf %lu sp %lu sl %lu\n", \ 132 "r %lu ri %lu csr %lu sf %lu sp %lu sl %lu\n", \
152 ras->ras_last_readpage, ras->ras_consecutive_requests, \ 133 ras->ras_last_readpage, ras->ras_consecutive_requests, \
153 ras->ras_consecutive_pages, ras->ras_window_start, \ 134 ras->ras_consecutive_pages, ras->ras_window_start, \
154 ras->ras_window_len, ras->ras_next_readahead, \ 135 ras->ras_window_len, ras->ras_next_readahead, \
136 ras->ras_rpc_size, \
155 ras->ras_requests, ras->ras_request_index, \ 137 ras->ras_requests, ras->ras_request_index, \
156 ras->ras_consecutive_stride_requests, ras->ras_stride_offset, \ 138 ras->ras_consecutive_stride_requests, ras->ras_stride_offset, \
157 ras->ras_stride_pages, ras->ras_stride_length) 139 ras->ras_stride_pages, ras->ras_stride_length)
@@ -261,20 +243,6 @@ out:
261 ria->ria_start, ria->ria_end, ria->ria_stoff, ria->ria_length,\ 243 ria->ria_start, ria->ria_end, ria->ria_stoff, ria->ria_length,\
262 ria->ria_pages) 244 ria->ria_pages)
263 245
264/* Limit this to the blocksize instead of PTLRPC_BRW_MAX_SIZE, since we don't
265 * know what the actual RPC size is. If this needs to change, it makes more
266 * sense to tune the i_blkbits value for the file based on the OSTs it is
267 * striped over, rather than having a constant value for all files here.
268 */
269
270/* RAS_INCREASE_STEP should be (1UL << (inode->i_blkbits - PAGE_SHIFT)).
271 * Temporarily set RAS_INCREASE_STEP to 1MB. After 4MB RPC is enabled
272 * by default, this should be adjusted corresponding with max_read_ahead_mb
273 * and max_read_ahead_per_file_mb otherwise the readahead budget can be used
274 * up quickly which will affect read performance significantly. See LU-2816
275 */
276#define RAS_INCREASE_STEP(inode) (ONE_MB_BRW_SIZE >> PAGE_SHIFT)
277
278static inline int stride_io_mode(struct ll_readahead_state *ras) 246static inline int stride_io_mode(struct ll_readahead_state *ras)
279{ 247{
280 return ras->ras_consecutive_stride_requests > 1; 248 return ras->ras_consecutive_stride_requests > 1;
@@ -345,6 +313,17 @@ static int ria_page_count(struct ra_io_arg *ria)
345 length); 313 length);
346} 314}
347 315
316static unsigned long ras_align(struct ll_readahead_state *ras,
317 unsigned long index,
318 unsigned long *remainder)
319{
320 unsigned long rem = index % ras->ras_rpc_size;
321
322 if (remainder)
323 *remainder = rem;
324 return index - rem;
325}
326
348/*Check whether the index is in the defined ra-window */ 327/*Check whether the index is in the defined ra-window */
349static int ras_inside_ra_window(unsigned long idx, struct ra_io_arg *ria) 328static int ras_inside_ra_window(unsigned long idx, struct ra_io_arg *ria)
350{ 329{
@@ -358,42 +337,63 @@ static int ras_inside_ra_window(unsigned long idx, struct ra_io_arg *ria)
358 ria->ria_length < ria->ria_pages); 337 ria->ria_length < ria->ria_pages);
359} 338}
360 339
361static int ll_read_ahead_pages(const struct lu_env *env, 340static unsigned long
362 struct cl_io *io, struct cl_page_list *queue, 341ll_read_ahead_pages(const struct lu_env *env, struct cl_io *io,
363 struct ra_io_arg *ria, 342 struct cl_page_list *queue, struct ll_readahead_state *ras,
364 unsigned long *reserved_pages, 343 struct ra_io_arg *ria)
365 pgoff_t *ra_end)
366{ 344{
367 struct cl_read_ahead ra = { 0 }; 345 struct cl_read_ahead ra = { 0 };
368 int rc, count = 0; 346 unsigned long ra_end = 0;
369 bool stride_ria; 347 bool stride_ria;
370 pgoff_t page_idx; 348 pgoff_t page_idx;
349 int rc;
371 350
372 LASSERT(ria); 351 LASSERT(ria);
373 RIA_DEBUG(ria); 352 RIA_DEBUG(ria);
374 353
375 stride_ria = ria->ria_length > ria->ria_pages && ria->ria_pages > 0; 354 stride_ria = ria->ria_length > ria->ria_pages && ria->ria_pages > 0;
376 for (page_idx = ria->ria_start; 355 for (page_idx = ria->ria_start;
377 page_idx <= ria->ria_end && *reserved_pages > 0; page_idx++) { 356 page_idx <= ria->ria_end && ria->ria_reserved > 0; page_idx++) {
378 if (ras_inside_ra_window(page_idx, ria)) { 357 if (ras_inside_ra_window(page_idx, ria)) {
379 if (!ra.cra_end || ra.cra_end < page_idx) { 358 if (!ra.cra_end || ra.cra_end < page_idx) {
359 unsigned long end;
360
380 cl_read_ahead_release(env, &ra); 361 cl_read_ahead_release(env, &ra);
381 362
382 rc = cl_io_read_ahead(env, io, page_idx, &ra); 363 rc = cl_io_read_ahead(env, io, page_idx, &ra);
383 if (rc < 0) 364 if (rc < 0)
384 break; 365 break;
385 366
367 CDEBUG(D_READA, "idx: %lu, ra: %lu, rpc: %lu\n",
368 page_idx, ra.cra_end, ra.cra_rpc_size);
386 LASSERTF(ra.cra_end >= page_idx, 369 LASSERTF(ra.cra_end >= page_idx,
387 "object: %p, indcies %lu / %lu\n", 370 "object: %p, indcies %lu / %lu\n",
388 io->ci_obj, ra.cra_end, page_idx); 371 io->ci_obj, ra.cra_end, page_idx);
372 /*
373 * update read ahead RPC size.
374 * NB: it's racy but doesn't matter
375 */
376 if (ras->ras_rpc_size > ra.cra_rpc_size &&
377 ra.cra_rpc_size > 0)
378 ras->ras_rpc_size = ra.cra_rpc_size;
379 /* trim it to align with optimal RPC size */
380 end = ras_align(ras, ria->ria_end + 1, NULL);
381 if (end > 0 && !ria->ria_eof)
382 ria->ria_end = end - 1;
383 if (ria->ria_end < ria->ria_end_min)
384 ria->ria_end = ria->ria_end_min;
385 if (ria->ria_end > ra.cra_end)
386 ria->ria_end = ra.cra_end;
389 } 387 }
390 388
391 /* If the page is inside the read-ahead window*/ 389 /* If the page is inside the read-ahead window */
392 rc = ll_read_ahead_page(env, io, queue, page_idx); 390 rc = ll_read_ahead_page(env, io, queue, page_idx);
393 if (!rc) { 391 if (rc < 0)
394 (*reserved_pages)--; 392 break;
395 count++; 393
396 } 394 ra_end = page_idx;
395 if (!rc)
396 ria->ria_reserved--;
397 } else if (stride_ria) { 397 } else if (stride_ria) {
398 /* If it is not in the read-ahead window, and it is 398 /* If it is not in the read-ahead window, and it is
399 * read-ahead mode, then check whether it should skip 399 * read-ahead mode, then check whether it should skip
@@ -420,8 +420,7 @@ static int ll_read_ahead_pages(const struct lu_env *env,
420 } 420 }
421 cl_read_ahead_release(env, &ra); 421 cl_read_ahead_release(env, &ra);
422 422
423 *ra_end = page_idx; 423 return ra_end;
424 return count;
425} 424}
426 425
427static int ll_readahead(const struct lu_env *env, struct cl_io *io, 426static int ll_readahead(const struct lu_env *env, struct cl_io *io,
@@ -431,7 +430,7 @@ static int ll_readahead(const struct lu_env *env, struct cl_io *io,
431 struct vvp_io *vio = vvp_env_io(env); 430 struct vvp_io *vio = vvp_env_io(env);
432 struct ll_thread_info *lti = ll_env_info(env); 431 struct ll_thread_info *lti = ll_env_info(env);
433 struct cl_attr *attr = vvp_env_thread_attr(env); 432 struct cl_attr *attr = vvp_env_thread_attr(env);
434 unsigned long len, mlen = 0, reserved; 433 unsigned long len, mlen = 0;
435 pgoff_t ra_end, start = 0, end = 0; 434 pgoff_t ra_end, start = 0, end = 0;
436 struct inode *inode; 435 struct inode *inode;
437 struct ra_io_arg *ria = &lti->lti_ria; 436 struct ra_io_arg *ria = &lti->lti_ria;
@@ -478,29 +477,15 @@ static int ll_readahead(const struct lu_env *env, struct cl_io *io,
478 end < vio->vui_ra_start + vio->vui_ra_count - 1) 477 end < vio->vui_ra_start + vio->vui_ra_count - 1)
479 end = vio->vui_ra_start + vio->vui_ra_count - 1; 478 end = vio->vui_ra_start + vio->vui_ra_count - 1;
480 479
481 if (end != 0) { 480 if (end) {
482 unsigned long rpc_boundary; 481 unsigned long end_index;
483 /*
484 * Align RA window to an optimal boundary.
485 *
486 * XXX This would be better to align to cl_max_pages_per_rpc
487 * instead of PTLRPC_MAX_BRW_PAGES, because the RPC size may
488 * be aligned to the RAID stripe size in the future and that
489 * is more important than the RPC size.
490 */
491 /* Note: we only trim the RPC, instead of extending the RPC
492 * to the boundary, so to avoid reading too much pages during
493 * random reading.
494 */
495 rpc_boundary = (end + 1) & (~(PTLRPC_MAX_BRW_PAGES - 1));
496 if (rpc_boundary > 0)
497 rpc_boundary--;
498
499 if (rpc_boundary > start)
500 end = rpc_boundary;
501 482
502 /* Truncate RA window to end of file */ 483 /* Truncate RA window to end of file */
503 end = min(end, (unsigned long)((kms - 1) >> PAGE_SHIFT)); 484 end_index = (unsigned long)((kms - 1) >> PAGE_SHIFT);
485 if (end_index <= end) {
486 end = end_index;
487 ria->ria_eof = true;
488 }
504 489
505 ras->ras_next_readahead = max(end, end + 1); 490 ras->ras_next_readahead = max(end, end + 1);
506 RAS_CDEBUG(ras); 491 RAS_CDEBUG(ras);
@@ -535,28 +520,31 @@ static int ll_readahead(const struct lu_env *env, struct cl_io *io,
535 /* at least to extend the readahead window to cover current read */ 520 /* at least to extend the readahead window to cover current read */
536 if (!hit && vio->vui_ra_valid && 521 if (!hit && vio->vui_ra_valid &&
537 vio->vui_ra_start + vio->vui_ra_count > ria->ria_start) { 522 vio->vui_ra_start + vio->vui_ra_count > ria->ria_start) {
523 unsigned long remainder;
524
538 /* to the end of current read window. */ 525 /* to the end of current read window. */
539 mlen = vio->vui_ra_start + vio->vui_ra_count - ria->ria_start; 526 mlen = vio->vui_ra_start + vio->vui_ra_count - ria->ria_start;
540 /* trim to RPC boundary */ 527 /* trim to RPC boundary */
541 start = ria->ria_start & (PTLRPC_MAX_BRW_PAGES - 1); 528 ras_align(ras, ria->ria_start, &remainder);
542 mlen = min(mlen, PTLRPC_MAX_BRW_PAGES - start); 529 mlen = min(mlen, ras->ras_rpc_size - remainder);
530 ria->ria_end_min = ria->ria_start + mlen;
543 } 531 }
544 532
545 reserved = ll_ra_count_get(ll_i2sbi(inode), ria, len, mlen); 533 ria->ria_reserved = ll_ra_count_get(ll_i2sbi(inode), ria, len, mlen);
546 if (reserved < len) 534 if (ria->ria_reserved < len)
547 ll_ra_stats_inc(inode, RA_STAT_MAX_IN_FLIGHT); 535 ll_ra_stats_inc(inode, RA_STAT_MAX_IN_FLIGHT);
548 536
549 CDEBUG(D_READA, "reserved pages %lu/%lu/%lu, ra_cur %d, ra_max %lu\n", 537 CDEBUG(D_READA, "reserved pages %lu/%lu/%lu, ra_cur %d, ra_max %lu\n",
550 reserved, len, mlen, 538 ria->ria_reserved, len, mlen,
551 atomic_read(&ll_i2sbi(inode)->ll_ra_info.ra_cur_pages), 539 atomic_read(&ll_i2sbi(inode)->ll_ra_info.ra_cur_pages),
552 ll_i2sbi(inode)->ll_ra_info.ra_max_pages); 540 ll_i2sbi(inode)->ll_ra_info.ra_max_pages);
553 541
554 ret = ll_read_ahead_pages(env, io, queue, ria, &reserved, &ra_end); 542 ra_end = ll_read_ahead_pages(env, io, queue, ras, ria);
555 543
556 if (reserved != 0) 544 if (ria->ria_reserved)
557 ll_ra_count_put(ll_i2sbi(inode), reserved); 545 ll_ra_count_put(ll_i2sbi(inode), ria->ria_reserved);
558 546
559 if (ra_end == end + 1 && ra_end == (kms >> PAGE_SHIFT)) 547 if (ra_end == end && ra_end == (kms >> PAGE_SHIFT))
560 ll_ra_stats_inc(inode, RA_STAT_EOF); 548 ll_ra_stats_inc(inode, RA_STAT_EOF);
561 549
562 /* if we didn't get to the end of the region we reserved from 550 /* if we didn't get to the end of the region we reserved from
@@ -568,13 +556,13 @@ static int ll_readahead(const struct lu_env *env, struct cl_io *io,
568 CDEBUG(D_READA, "ra_end = %lu end = %lu stride end = %lu pages = %d\n", 556 CDEBUG(D_READA, "ra_end = %lu end = %lu stride end = %lu pages = %d\n",
569 ra_end, end, ria->ria_end, ret); 557 ra_end, end, ria->ria_end, ret);
570 558
571 if (ra_end != end + 1) { 559 if (ra_end > 0 && ra_end != end) {
572 ll_ra_stats_inc(inode, RA_STAT_FAILED_REACH_END); 560 ll_ra_stats_inc(inode, RA_STAT_FAILED_REACH_END);
573 spin_lock(&ras->ras_lock); 561 spin_lock(&ras->ras_lock);
574 if (ra_end < ras->ras_next_readahead && 562 if (ra_end <= ras->ras_next_readahead &&
575 index_in_window(ra_end, ras->ras_window_start, 0, 563 index_in_window(ra_end, ras->ras_window_start, 0,
576 ras->ras_window_len)) { 564 ras->ras_window_len)) {
577 ras->ras_next_readahead = ra_end; 565 ras->ras_next_readahead = ra_end + 1;
578 RAS_CDEBUG(ras); 566 RAS_CDEBUG(ras);
579 } 567 }
580 spin_unlock(&ras->ras_lock); 568 spin_unlock(&ras->ras_lock);
@@ -586,7 +574,7 @@ static int ll_readahead(const struct lu_env *env, struct cl_io *io,
586static void ras_set_start(struct inode *inode, struct ll_readahead_state *ras, 574static void ras_set_start(struct inode *inode, struct ll_readahead_state *ras,
587 unsigned long index) 575 unsigned long index)
588{ 576{
589 ras->ras_window_start = index & (~(RAS_INCREASE_STEP(inode) - 1)); 577 ras->ras_window_start = ras_align(ras, index, NULL);
590} 578}
591 579
592/* called with the ras_lock held or from places where it doesn't matter */ 580/* called with the ras_lock held or from places where it doesn't matter */
@@ -615,6 +603,7 @@ static void ras_stride_reset(struct ll_readahead_state *ras)
615void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras) 603void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras)
616{ 604{
617 spin_lock_init(&ras->ras_lock); 605 spin_lock_init(&ras->ras_lock);
606 ras->ras_rpc_size = PTLRPC_MAX_BRW_PAGES;
618 ras_reset(inode, ras, 0); 607 ras_reset(inode, ras, 0);
619 ras->ras_requests = 0; 608 ras->ras_requests = 0;
620} 609}
@@ -719,12 +708,15 @@ static void ras_increase_window(struct inode *inode,
719 * but current clio architecture does not support retrieve such 708 * but current clio architecture does not support retrieve such
720 * information from lower layer. FIXME later 709 * information from lower layer. FIXME later
721 */ 710 */
722 if (stride_io_mode(ras)) 711 if (stride_io_mode(ras)) {
723 ras_stride_increase_window(ras, ra, RAS_INCREASE_STEP(inode)); 712 ras_stride_increase_window(ras, ra, ras->ras_rpc_size);
724 else 713 } else {
725 ras->ras_window_len = min(ras->ras_window_len + 714 unsigned long wlen;
726 RAS_INCREASE_STEP(inode), 715
727 ra->ra_max_pages_per_file); 716 wlen = min(ras->ras_window_len + ras->ras_rpc_size,
717 ra->ra_max_pages_per_file);
718 ras->ras_window_len = ras_align(ras, wlen, NULL);
719 }
728} 720}
729 721
730static void ras_update(struct ll_sb_info *sbi, struct inode *inode, 722static void ras_update(struct ll_sb_info *sbi, struct inode *inode,
@@ -737,6 +729,10 @@ static void ras_update(struct ll_sb_info *sbi, struct inode *inode,
737 729
738 spin_lock(&ras->ras_lock); 730 spin_lock(&ras->ras_lock);
739 731
732 if (!hit)
733 CDEBUG(D_READA, DFID " pages at %lu miss.\n",
734 PFID(ll_inode2fid(inode)), index);
735
740 ll_ra_stats_inc_sbi(sbi, hit ? RA_STAT_HIT : RA_STAT_MISS); 736 ll_ra_stats_inc_sbi(sbi, hit ? RA_STAT_HIT : RA_STAT_MISS);
741 737
742 /* reset the read-ahead window in two cases. First when the app seeks 738 /* reset the read-ahead window in two cases. First when the app seeks
@@ -852,6 +848,8 @@ static void ras_update(struct ll_sb_info *sbi, struct inode *inode,
852 * instead of ras_window_start, which is RPC aligned 848 * instead of ras_window_start, which is RPC aligned
853 */ 849 */
854 ras->ras_next_readahead = max(index, ras->ras_next_readahead); 850 ras->ras_next_readahead = max(index, ras->ras_next_readahead);
851 ras->ras_window_start = max(ras->ras_stride_offset,
852 ras->ras_window_start);
855 } else { 853 } else {
856 if (ras->ras_next_readahead < ras->ras_window_start) 854 if (ras->ras_next_readahead < ras->ras_window_start)
857 ras->ras_next_readahead = ras->ras_window_start; 855 ras->ras_next_readahead = ras->ras_window_start;
@@ -881,7 +879,7 @@ static void ras_update(struct ll_sb_info *sbi, struct inode *inode,
881 */ 879 */
882 ras->ras_next_readahead = max(index, ras->ras_next_readahead); 880 ras->ras_next_readahead = max(index, ras->ras_next_readahead);
883 ras->ras_stride_offset = index; 881 ras->ras_stride_offset = index;
884 ras->ras_window_len = RAS_INCREASE_STEP(inode); 882 ras->ras_window_start = max(index, ras->ras_window_start);
885 } 883 }
886 884
887 /* The initial ras_window_len is set to the request size. To avoid 885 /* The initial ras_window_len is set to the request size. To avoid
@@ -1098,38 +1096,39 @@ static int ll_io_read_page(const struct lu_env *env, struct cl_io *io,
1098 struct cl_2queue *queue = &io->ci_queue; 1096 struct cl_2queue *queue = &io->ci_queue;
1099 struct ll_sb_info *sbi = ll_i2sbi(inode); 1097 struct ll_sb_info *sbi = ll_i2sbi(inode);
1100 struct vvp_page *vpg; 1098 struct vvp_page *vpg;
1099 bool uptodate;
1101 int rc = 0; 1100 int rc = 0;
1102 1101
1103 vpg = cl2vvp_page(cl_object_page_slice(page->cp_obj, page)); 1102 vpg = cl2vvp_page(cl_object_page_slice(page->cp_obj, page));
1103 uptodate = vpg->vpg_defer_uptodate;
1104
1104 if (sbi->ll_ra_info.ra_max_pages_per_file > 0 && 1105 if (sbi->ll_ra_info.ra_max_pages_per_file > 0 &&
1105 sbi->ll_ra_info.ra_max_pages > 0) { 1106 sbi->ll_ra_info.ra_max_pages > 0) {
1106 struct vvp_io *vio = vvp_env_io(env); 1107 struct vvp_io *vio = vvp_env_io(env);
1107 enum ras_update_flags flags = 0; 1108 enum ras_update_flags flags = 0;
1108 1109
1109 if (vpg->vpg_defer_uptodate) 1110 if (uptodate)
1110 flags |= LL_RAS_HIT; 1111 flags |= LL_RAS_HIT;
1111 if (!vio->vui_ra_valid) 1112 if (!vio->vui_ra_valid)
1112 flags |= LL_RAS_MMAP; 1113 flags |= LL_RAS_MMAP;
1113 ras_update(sbi, inode, ras, vvp_index(vpg), flags); 1114 ras_update(sbi, inode, ras, vvp_index(vpg), flags);
1114 } 1115 }
1115 1116
1116 if (vpg->vpg_defer_uptodate) { 1117 cl_2queue_init(queue);
1118 if (uptodate) {
1117 vpg->vpg_ra_used = 1; 1119 vpg->vpg_ra_used = 1;
1118 cl_page_export(env, page, 1); 1120 cl_page_export(env, page, 1);
1121 cl_page_disown(env, io, page);
1122 } else {
1123 cl_page_list_add(&queue->c2_qin, page);
1119 } 1124 }
1120 1125
1121 cl_2queue_init(queue);
1122 /*
1123 * Add page into the queue even when it is marked uptodate above.
1124 * this will unlock it automatically as part of cl_page_list_disown().
1125 */
1126 cl_page_list_add(&queue->c2_qin, page);
1127 if (sbi->ll_ra_info.ra_max_pages_per_file > 0 && 1126 if (sbi->ll_ra_info.ra_max_pages_per_file > 0 &&
1128 sbi->ll_ra_info.ra_max_pages > 0) { 1127 sbi->ll_ra_info.ra_max_pages > 0) {
1129 int rc2; 1128 int rc2;
1130 1129
1131 rc2 = ll_readahead(env, io, &queue->c2_qin, ras, 1130 rc2 = ll_readahead(env, io, &queue->c2_qin, ras,
1132 vpg->vpg_defer_uptodate); 1131 uptodate);
1133 CDEBUG(D_READA, DFID "%d pages read ahead at %lu\n", 1132 CDEBUG(D_READA, DFID "%d pages read ahead at %lu\n",
1134 PFID(ll_inode2fid(inode)), rc2, vvp_index(vpg)); 1133 PFID(ll_inode2fid(inode)), rc2, vvp_index(vpg));
1135 } 1134 }
diff --git a/drivers/staging/lustre/lustre/llite/rw26.c b/drivers/staging/lustre/lustre/llite/rw26.c
index 21e06e5b514e..d89e79599199 100644
--- a/drivers/staging/lustre/lustre/llite/rw26.c
+++ b/drivers/staging/lustre/lustre/llite/rw26.c
@@ -345,6 +345,10 @@ static ssize_t ll_direct_IO_26(struct kiocb *iocb, struct iov_iter *iter)
345 ssize_t tot_bytes = 0, result = 0; 345 ssize_t tot_bytes = 0, result = 0;
346 long size = MAX_DIO_SIZE; 346 long size = MAX_DIO_SIZE;
347 347
348 /* Check EOF by ourselves */
349 if (iov_iter_rw(iter) == READ && file_offset >= i_size_read(inode))
350 return 0;
351
348 /* FIXME: io smaller than PAGE_SIZE is broken on ia64 ??? */ 352 /* FIXME: io smaller than PAGE_SIZE is broken on ia64 ??? */
349 if ((file_offset & ~PAGE_MASK) || (count & ~PAGE_MASK)) 353 if ((file_offset & ~PAGE_MASK) || (count & ~PAGE_MASK))
350 return -EINVAL; 354 return -EINVAL;
diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c
index f1ee17f9ec0d..fb7c315b33cb 100644
--- a/drivers/staging/lustre/lustre/llite/statahead.c
+++ b/drivers/staging/lustre/lustre/llite/statahead.c
@@ -79,6 +79,8 @@ struct sa_entry {
79 struct inode *se_inode; 79 struct inode *se_inode;
80 /* entry name */ 80 /* entry name */
81 struct qstr se_qstr; 81 struct qstr se_qstr;
82 /* entry fid */
83 struct lu_fid se_fid;
82}; 84};
83 85
84static unsigned int sai_generation; 86static unsigned int sai_generation;
@@ -169,7 +171,7 @@ static inline int is_omitted_entry(struct ll_statahead_info *sai, __u64 index)
169/* allocate sa_entry and hash it to allow scanner process to find it */ 171/* allocate sa_entry and hash it to allow scanner process to find it */
170static struct sa_entry * 172static struct sa_entry *
171sa_alloc(struct dentry *parent, struct ll_statahead_info *sai, __u64 index, 173sa_alloc(struct dentry *parent, struct ll_statahead_info *sai, __u64 index,
172 const char *name, int len) 174 const char *name, int len, const struct lu_fid *fid)
173{ 175{
174 struct ll_inode_info *lli; 176 struct ll_inode_info *lli;
175 struct sa_entry *entry; 177 struct sa_entry *entry;
@@ -194,6 +196,7 @@ sa_alloc(struct dentry *parent, struct ll_statahead_info *sai, __u64 index,
194 entry->se_qstr.hash = full_name_hash(parent, name, len); 196 entry->se_qstr.hash = full_name_hash(parent, name, len);
195 entry->se_qstr.len = len; 197 entry->se_qstr.len = len;
196 entry->se_qstr.name = dname; 198 entry->se_qstr.name = dname;
199 entry->se_fid = *fid;
197 200
198 lli = ll_i2info(sai->sai_dentry->d_inode); 201 lli = ll_i2info(sai->sai_dentry->d_inode);
199 spin_lock(&lli->lli_sa_lock); 202 spin_lock(&lli->lli_sa_lock);
@@ -566,24 +569,8 @@ static void sa_instantiate(struct ll_statahead_info *sai,
566 } 569 }
567 570
568 child = entry->se_inode; 571 child = entry->se_inode;
569 if (!child) { 572 if (child) {
570 /* 573 /* revalidate; unlinked and re-created with the same name */
571 * lookup.
572 */
573 LASSERT(fid_is_zero(&minfo->mi_data.op_fid2));
574
575 /* XXX: No fid in reply, this is probably cross-ref case.
576 * SA can't handle it yet.
577 */
578 if (body->mbo_valid & OBD_MD_MDS) {
579 rc = -EAGAIN;
580 goto out;
581 }
582 } else {
583 /*
584 * revalidate.
585 */
586 /* unlinked and re-created with the same name */
587 if (unlikely(!lu_fid_eq(&minfo->mi_data.op_fid2, &body->mbo_fid1))) { 574 if (unlikely(!lu_fid_eq(&minfo->mi_data.op_fid2, &body->mbo_fid1))) {
588 entry->se_inode = NULL; 575 entry->se_inode = NULL;
589 iput(child); 576 iput(child);
@@ -720,50 +707,42 @@ static int ll_statahead_interpret(struct ptlrpc_request *req,
720} 707}
721 708
722/* finish async stat RPC arguments */ 709/* finish async stat RPC arguments */
723static void sa_fini_data(struct md_enqueue_info *minfo, 710static void sa_fini_data(struct md_enqueue_info *minfo)
724 struct ldlm_enqueue_info *einfo)
725{ 711{
726 LASSERT(minfo && einfo);
727 iput(minfo->mi_dir); 712 iput(minfo->mi_dir);
728 kfree(minfo); 713 kfree(minfo);
729 kfree(einfo);
730} 714}
731 715
732/** 716/**
733 * prepare arguments for async stat RPC. 717 * prepare arguments for async stat RPC.
734 */ 718 */
735static int sa_prep_data(struct inode *dir, struct inode *child, 719static struct md_enqueue_info *
736 struct sa_entry *entry, struct md_enqueue_info **pmi, 720sa_prep_data(struct inode *dir, struct inode *child, struct sa_entry *entry)
737 struct ldlm_enqueue_info **pei)
738{ 721{
739 const struct qstr *qstr = &entry->se_qstr;
740 struct md_enqueue_info *minfo; 722 struct md_enqueue_info *minfo;
741 struct ldlm_enqueue_info *einfo; 723 struct ldlm_enqueue_info *einfo;
742 struct md_op_data *op_data; 724 struct md_op_data *op_data;
743 725
744 einfo = kzalloc(sizeof(*einfo), GFP_NOFS);
745 if (!einfo)
746 return -ENOMEM;
747
748 minfo = kzalloc(sizeof(*minfo), GFP_NOFS); 726 minfo = kzalloc(sizeof(*minfo), GFP_NOFS);
749 if (!minfo) { 727 if (!minfo)
750 kfree(einfo); 728 return ERR_PTR(-ENOMEM);
751 return -ENOMEM;
752 }
753 729
754 op_data = ll_prep_md_op_data(&minfo->mi_data, dir, child, qstr->name, 730 op_data = ll_prep_md_op_data(&minfo->mi_data, dir, child, NULL, 0, 0,
755 qstr->len, 0, LUSTRE_OPC_ANY, NULL); 731 LUSTRE_OPC_ANY, NULL);
756 if (IS_ERR(op_data)) { 732 if (IS_ERR(op_data)) {
757 kfree(einfo);
758 kfree(minfo); 733 kfree(minfo);
759 return PTR_ERR(op_data); 734 return (struct md_enqueue_info *)op_data;
760 } 735 }
761 736
737 if (!child)
738 op_data->op_fid2 = entry->se_fid;
739
762 minfo->mi_it.it_op = IT_GETATTR; 740 minfo->mi_it.it_op = IT_GETATTR;
763 minfo->mi_dir = igrab(dir); 741 minfo->mi_dir = igrab(dir);
764 minfo->mi_cb = ll_statahead_interpret; 742 minfo->mi_cb = ll_statahead_interpret;
765 minfo->mi_cbdata = entry; 743 minfo->mi_cbdata = entry;
766 744
745 einfo = &minfo->mi_einfo;
767 einfo->ei_type = LDLM_IBITS; 746 einfo->ei_type = LDLM_IBITS;
768 einfo->ei_mode = it_to_lock_mode(&minfo->mi_it); 747 einfo->ei_mode = it_to_lock_mode(&minfo->mi_it);
769 einfo->ei_cb_bl = ll_md_blocking_ast; 748 einfo->ei_cb_bl = ll_md_blocking_ast;
@@ -771,26 +750,22 @@ static int sa_prep_data(struct inode *dir, struct inode *child,
771 einfo->ei_cb_gl = NULL; 750 einfo->ei_cb_gl = NULL;
772 einfo->ei_cbdata = NULL; 751 einfo->ei_cbdata = NULL;
773 752
774 *pmi = minfo; 753 return minfo;
775 *pei = einfo;
776
777 return 0;
778} 754}
779 755
780/* async stat for file not found in dcache */ 756/* async stat for file not found in dcache */
781static int sa_lookup(struct inode *dir, struct sa_entry *entry) 757static int sa_lookup(struct inode *dir, struct sa_entry *entry)
782{ 758{
783 struct md_enqueue_info *minfo; 759 struct md_enqueue_info *minfo;
784 struct ldlm_enqueue_info *einfo;
785 int rc; 760 int rc;
786 761
787 rc = sa_prep_data(dir, NULL, entry, &minfo, &einfo); 762 minfo = sa_prep_data(dir, NULL, entry);
788 if (rc) 763 if (IS_ERR(minfo))
789 return rc; 764 return PTR_ERR(minfo);
790 765
791 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo, einfo); 766 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo);
792 if (rc) 767 if (rc)
793 sa_fini_data(minfo, einfo); 768 sa_fini_data(minfo);
794 769
795 return rc; 770 return rc;
796} 771}
@@ -809,7 +784,6 @@ static int sa_revalidate(struct inode *dir, struct sa_entry *entry,
809 struct lookup_intent it = { .it_op = IT_GETATTR, 784 struct lookup_intent it = { .it_op = IT_GETATTR,
810 .it_lock_handle = 0 }; 785 .it_lock_handle = 0 };
811 struct md_enqueue_info *minfo; 786 struct md_enqueue_info *minfo;
812 struct ldlm_enqueue_info *einfo;
813 int rc; 787 int rc;
814 788
815 if (unlikely(!inode)) 789 if (unlikely(!inode))
@@ -827,25 +801,26 @@ static int sa_revalidate(struct inode *dir, struct sa_entry *entry,
827 return 1; 801 return 1;
828 } 802 }
829 803
830 rc = sa_prep_data(dir, inode, entry, &minfo, &einfo); 804 minfo = sa_prep_data(dir, inode, entry);
831 if (rc) { 805 if (IS_ERR(minfo)) {
832 entry->se_inode = NULL; 806 entry->se_inode = NULL;
833 iput(inode); 807 iput(inode);
834 return rc; 808 return PTR_ERR(minfo);
835 } 809 }
836 810
837 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo, einfo); 811 rc = md_intent_getattr_async(ll_i2mdexp(dir), minfo);
838 if (rc) { 812 if (rc) {
839 entry->se_inode = NULL; 813 entry->se_inode = NULL;
840 iput(inode); 814 iput(inode);
841 sa_fini_data(minfo, einfo); 815 sa_fini_data(minfo);
842 } 816 }
843 817
844 return rc; 818 return rc;
845} 819}
846 820
847/* async stat for file with @name */ 821/* async stat for file with @name */
848static void sa_statahead(struct dentry *parent, const char *name, int len) 822static void sa_statahead(struct dentry *parent, const char *name, int len,
823 const struct lu_fid *fid)
849{ 824{
850 struct inode *dir = d_inode(parent); 825 struct inode *dir = d_inode(parent);
851 struct ll_inode_info *lli = ll_i2info(dir); 826 struct ll_inode_info *lli = ll_i2info(dir);
@@ -854,7 +829,7 @@ static void sa_statahead(struct dentry *parent, const char *name, int len)
854 struct sa_entry *entry; 829 struct sa_entry *entry;
855 int rc; 830 int rc;
856 831
857 entry = sa_alloc(parent, sai, sai->sai_index, name, len); 832 entry = sa_alloc(parent, sai, sai->sai_index, name, len, fid);
858 if (IS_ERR(entry)) 833 if (IS_ERR(entry))
859 return; 834 return;
860 835
@@ -1043,6 +1018,7 @@ static int ll_statahead_thread(void *arg)
1043 for (ent = lu_dirent_start(dp); 1018 for (ent = lu_dirent_start(dp);
1044 ent && thread_is_running(sa_thread) && !sa_low_hit(sai); 1019 ent && thread_is_running(sa_thread) && !sa_low_hit(sai);
1045 ent = lu_dirent_next(ent)) { 1020 ent = lu_dirent_next(ent)) {
1021 struct lu_fid fid;
1046 __u64 hash; 1022 __u64 hash;
1047 int namelen; 1023 int namelen;
1048 char *name; 1024 char *name;
@@ -1088,6 +1064,8 @@ static int ll_statahead_thread(void *arg)
1088 if (unlikely(++first == 1)) 1064 if (unlikely(++first == 1))
1089 continue; 1065 continue;
1090 1066
1067 fid_le_to_cpu(&fid, &ent->lde_fid);
1068
1091 /* wait for spare statahead window */ 1069 /* wait for spare statahead window */
1092 do { 1070 do {
1093 l_wait_event(sa_thread->t_ctl_waitq, 1071 l_wait_event(sa_thread->t_ctl_waitq,
@@ -1117,7 +1095,7 @@ static int ll_statahead_thread(void *arg)
1117 } while (sa_sent_full(sai) && 1095 } while (sa_sent_full(sai) &&
1118 thread_is_running(sa_thread)); 1096 thread_is_running(sa_thread));
1119 1097
1120 sa_statahead(parent, name, namelen); 1098 sa_statahead(parent, name, namelen, &fid);
1121 } 1099 }
1122 1100
1123 pos = le64_to_cpu(dp->ldp_hash_end); 1101 pos = le64_to_cpu(dp->ldp_hash_end);
diff --git a/drivers/staging/lustre/lustre/llite/super25.c b/drivers/staging/lustre/lustre/llite/super25.c
index 106cd00910a7..4759802e062d 100644
--- a/drivers/staging/lustre/lustre/llite/super25.c
+++ b/drivers/staging/lustre/lustre/llite/super25.c
@@ -88,7 +88,7 @@ static int __init lustre_init(void)
88 struct timespec64 ts; 88 struct timespec64 ts;
89 int i, rc, seed[2]; 89 int i, rc, seed[2];
90 90
91 CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1); 91 BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) != LUSTRE_VOLATILE_HDR_LEN + 1);
92 92
93 /* print an address of _any_ initialized kernel symbol from this 93 /* print an address of _any_ initialized kernel symbol from this
94 * module, to allow debugging with gdb that doesn't support data 94 * module, to allow debugging with gdb that doesn't support data
diff --git a/drivers/staging/lustre/lustre/llite/vvp_dev.c b/drivers/staging/lustre/lustre/llite/vvp_dev.c
index 12c129f7e4ad..3669ea77ee93 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_dev.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_dev.c
@@ -391,7 +391,7 @@ struct vvp_pgcache_id {
391 391
392static void vvp_pgcache_id_unpack(loff_t pos, struct vvp_pgcache_id *id) 392static void vvp_pgcache_id_unpack(loff_t pos, struct vvp_pgcache_id *id)
393{ 393{
394 CLASSERT(sizeof(pos) == sizeof(__u64)); 394 BUILD_BUG_ON(sizeof(pos) != sizeof(__u64));
395 395
396 id->vpi_index = pos & 0xffffffff; 396 id->vpi_index = pos & 0xffffffff;
397 id->vpi_depth = (pos >> PGC_DEPTH_SHIFT) & 0xf; 397 id->vpi_depth = (pos >> PGC_DEPTH_SHIFT) & 0xf;
diff --git a/drivers/staging/lustre/lustre/llite/vvp_internal.h b/drivers/staging/lustre/lustre/llite/vvp_internal.h
index c60d0414ac25..f40fd7f115d1 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_internal.h
+++ b/drivers/staging/lustre/lustre/llite/vvp_internal.h
@@ -301,8 +301,6 @@ static inline struct vvp_lock *cl2vvp_lock(const struct cl_lock_slice *slice)
301# define CLOBINVRNT(env, clob, expr) \ 301# define CLOBINVRNT(env, clob, expr) \
302 ((void)sizeof(env), (void)sizeof(clob), (void)sizeof(!!(expr))) 302 ((void)sizeof(env), (void)sizeof(clob), (void)sizeof(!!(expr)))
303 303
304int lov_read_and_clear_async_rc(struct cl_object *clob);
305
306int vvp_io_init(const struct lu_env *env, struct cl_object *obj, 304int vvp_io_init(const struct lu_env *env, struct cl_object *obj,
307 struct cl_io *io); 305 struct cl_io *io);
308int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io); 306int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io);
diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c
index 697cbfbe9374..3e9cf710501b 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_io.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_io.c
@@ -288,7 +288,7 @@ static void vvp_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
288 io->ci_ignore_layout, io->ci_verify_layout, 288 io->ci_ignore_layout, io->ci_verify_layout,
289 vio->vui_layout_gen, io->ci_restore_needed); 289 vio->vui_layout_gen, io->ci_restore_needed);
290 290
291 if (io->ci_restore_needed == 1) { 291 if (io->ci_restore_needed) {
292 int rc; 292 int rc;
293 293
294 /* file was detected release, we need to restore it 294 /* file was detected release, we need to restore it
@@ -657,7 +657,15 @@ static void vvp_io_setattr_end(const struct lu_env *env,
657static void vvp_io_setattr_fini(const struct lu_env *env, 657static void vvp_io_setattr_fini(const struct lu_env *env,
658 const struct cl_io_slice *ios) 658 const struct cl_io_slice *ios)
659{ 659{
660 bool restore_needed = ios->cis_io->ci_restore_needed;
661 struct inode *inode = vvp_object_inode(ios->cis_obj);
662
660 vvp_io_fini(env, ios); 663 vvp_io_fini(env, ios);
664
665 if (restore_needed && !ios->cis_io->ci_restore_needed) {
666 /* restore finished, set data modified flag for HSM */
667 set_bit(LLIF_DATA_MODIFIED, &(ll_i2info(inode))->lli_flags);
668 }
661} 669}
662 670
663static int vvp_io_read_start(const struct lu_env *env, 671static int vvp_io_read_start(const struct lu_env *env,
@@ -1340,13 +1348,6 @@ int vvp_io_init(const struct lu_env *env, struct cl_object *obj,
1340 io->ci_lockreq = CILR_MANDATORY; 1348 io->ci_lockreq = CILR_MANDATORY;
1341 } 1349 }
1342 1350
1343 /* ignore layout change for generic CIT_MISC but not for glimpse.
1344 * io context for glimpse must set ci_verify_layout to true,
1345 * see cl_glimpse_size0() for details.
1346 */
1347 if (io->ci_type == CIT_MISC && !io->ci_verify_layout)
1348 io->ci_ignore_layout = 1;
1349
1350 /* Enqueue layout lock and get layout version. We need to do this 1351 /* Enqueue layout lock and get layout version. We need to do this
1351 * even for operations requiring to open file, such as read and write, 1352 * even for operations requiring to open file, such as read and write,
1352 * because it might not grant layout lock in IT_OPEN. 1353 * because it might not grant layout lock in IT_OPEN.
diff --git a/drivers/staging/lustre/lustre/llite/vvp_page.c b/drivers/staging/lustre/lustre/llite/vvp_page.c
index 23d66308ff20..687c0c79d621 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_page.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_page.c
@@ -227,7 +227,8 @@ static int vvp_page_prep_write(const struct lu_env *env,
227 * This takes inode as a separate argument, because inode on which error is to 227 * This takes inode as a separate argument, because inode on which error is to
228 * be set can be different from \a vmpage inode in case of direct-io. 228 * be set can be different from \a vmpage inode in case of direct-io.
229 */ 229 */
230static void vvp_vmpage_error(struct inode *inode, struct page *vmpage, int ioret) 230static void vvp_vmpage_error(struct inode *inode, struct page *vmpage,
231 int ioret)
231{ 232{
232 struct vvp_object *obj = cl_inode2vvp(inode); 233 struct vvp_object *obj = cl_inode2vvp(inode);
233 234
diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 7a848ebc57c1..421cc04ecf1e 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -132,6 +132,15 @@ ll_xattr_set_common(const struct xattr_handler *handler,
132 (!strcmp(name, "ima") || !strcmp(name, "evm"))) 132 (!strcmp(name, "ima") || !strcmp(name, "evm")))
133 return -EOPNOTSUPP; 133 return -EOPNOTSUPP;
134 134
135 /*
136 * In user.* namespace, only regular files and directories can have
137 * extended attributes.
138 */
139 if (handler->flags == XATTR_USER_T) {
140 if (!S_ISREG(inode->i_mode) && !S_ISDIR(inode->i_mode))
141 return -EPERM;
142 }
143
135 sprintf(fullname, "%s%s\n", handler->prefix, name); 144 sprintf(fullname, "%s%s\n", handler->prefix, name);
136 rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), 145 rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode),
137 valid, fullname, pv, size, 0, flags, 146 valid, fullname, pv, size, 0, flags,
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_intent.c b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
index b1071cf5a70c..aa42066678e0 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_intent.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
@@ -220,21 +220,7 @@ int lmv_revalidate_slaves(struct obd_export *exp,
220 /* refresh slave from server */ 220 /* refresh slave from server */
221 body = req_capsule_server_get(&req->rq_pill, 221 body = req_capsule_server_get(&req->rq_pill,
222 &RMF_MDT_BODY); 222 &RMF_MDT_BODY);
223 LASSERT(body); 223 if (!body) {
224
225 if (unlikely(body->mbo_nlink < 2)) {
226 /*
227 * If this is bad stripe, most likely due
228 * to the race between close(unlink) and
229 * getattr, let's return -EONENT, so llite
230 * will revalidate the dentry see
231 * ll_inode_revalidate_fini()
232 */
233 CDEBUG(D_INODE, "%s: nlink %d < 2 corrupt stripe %d "DFID":" DFID"\n",
234 obd->obd_name, body->mbo_nlink, i,
235 PFID(&lsm->lsm_md_oinfo[i].lmo_fid),
236 PFID(&lsm->lsm_md_oinfo[0].lmo_fid));
237
238 if (it.it_lock_mode && lockh) { 224 if (it.it_lock_mode && lockh) {
239 ldlm_lock_decref(lockh, it.it_lock_mode); 225 ldlm_lock_decref(lockh, it.it_lock_mode);
240 it.it_lock_mode = 0; 226 it.it_lock_mode = 0;
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
index f124f6c05ea4..271e18966f50 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
@@ -173,14 +173,7 @@ static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
173 */ 173 */
174 obd->obd_self_export->exp_connect_data = *conn_data; 174 obd->obd_self_export->exp_connect_data = *conn_data;
175 } 175 }
176#if 0 176
177 else if (ev == OBD_NOTIFY_DISCON) {
178 /*
179 * For disconnect event, flush fld cache for failout MDS case.
180 */
181 fld_client_flush(&lmv->lmv_fld);
182 }
183#endif
184 /* 177 /*
185 * Pass the notification up the chain. 178 * Pass the notification up the chain.
186 */ 179 */
@@ -736,16 +729,18 @@ static int lmv_hsm_req_count(struct lmv_obd *lmv,
736 /* count how many requests must be sent to the given target */ 729 /* count how many requests must be sent to the given target */
737 for (i = 0; i < hur->hur_request.hr_itemcount; i++) { 730 for (i = 0; i < hur->hur_request.hr_itemcount; i++) {
738 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid); 731 curr_tgt = lmv_find_target(lmv, &hur->hur_user_item[i].hui_fid);
732 if (IS_ERR(curr_tgt))
733 return PTR_ERR(curr_tgt);
739 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) 734 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid))
740 nr++; 735 nr++;
741 } 736 }
742 return nr; 737 return nr;
743} 738}
744 739
745static void lmv_hsm_req_build(struct lmv_obd *lmv, 740static int lmv_hsm_req_build(struct lmv_obd *lmv,
746 struct hsm_user_request *hur_in, 741 struct hsm_user_request *hur_in,
747 const struct lmv_tgt_desc *tgt_mds, 742 const struct lmv_tgt_desc *tgt_mds,
748 struct hsm_user_request *hur_out) 743 struct hsm_user_request *hur_out)
749{ 744{
750 int i, nr_out; 745 int i, nr_out;
751 struct lmv_tgt_desc *curr_tgt; 746 struct lmv_tgt_desc *curr_tgt;
@@ -756,6 +751,8 @@ static void lmv_hsm_req_build(struct lmv_obd *lmv,
756 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) { 751 for (i = 0; i < hur_in->hur_request.hr_itemcount; i++) {
757 curr_tgt = lmv_find_target(lmv, 752 curr_tgt = lmv_find_target(lmv,
758 &hur_in->hur_user_item[i].hui_fid); 753 &hur_in->hur_user_item[i].hui_fid);
754 if (IS_ERR(curr_tgt))
755 return PTR_ERR(curr_tgt);
759 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) { 756 if (obd_uuid_equals(&curr_tgt->ltd_uuid, &tgt_mds->ltd_uuid)) {
760 hur_out->hur_user_item[nr_out] = 757 hur_out->hur_user_item[nr_out] =
761 hur_in->hur_user_item[i]; 758 hur_in->hur_user_item[i];
@@ -765,13 +762,14 @@ static void lmv_hsm_req_build(struct lmv_obd *lmv,
765 hur_out->hur_request.hr_itemcount = nr_out; 762 hur_out->hur_request.hr_itemcount = nr_out;
766 memcpy(hur_data(hur_out), hur_data(hur_in), 763 memcpy(hur_data(hur_out), hur_data(hur_in),
767 hur_in->hur_request.hr_data_len); 764 hur_in->hur_request.hr_data_len);
765
766 return 0;
768} 767}
769 768
770static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len, 769static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
771 struct lustre_kernelcomm *lk, 770 struct lustre_kernelcomm *lk,
772 void __user *uarg) 771 void __user *uarg)
773{ 772{
774 int rc = 0;
775 __u32 i; 773 __u32 i;
776 774
777 /* unregister request (call from llapi_hsm_copytool_fini) */ 775 /* unregister request (call from llapi_hsm_copytool_fini) */
@@ -791,9 +789,7 @@ static int lmv_hsm_ct_unregister(struct lmv_obd *lmv, unsigned int cmd, int len,
791 * Unreached coordinators will get EPIPE on next requests 789 * Unreached coordinators will get EPIPE on next requests
792 * and will unregister automatically. 790 * and will unregister automatically.
793 */ 791 */
794 rc = libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group); 792 return libcfs_kkuc_group_rem(lk->lk_uid, lk->lk_group);
795
796 return rc;
797} 793}
798 794
799static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len, 795static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
@@ -1044,15 +1040,17 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1044 } else { 1040 } else {
1045 /* split fid list to their respective MDS */ 1041 /* split fid list to their respective MDS */
1046 for (i = 0; i < count; i++) { 1042 for (i = 0; i < count; i++) {
1047 unsigned int nr, reqlen;
1048 int rc1;
1049 struct hsm_user_request *req; 1043 struct hsm_user_request *req;
1044 size_t reqlen;
1045 int nr, rc1;
1050 1046
1051 tgt = lmv->tgts[i]; 1047 tgt = lmv->tgts[i];
1052 if (!tgt || !tgt->ltd_exp) 1048 if (!tgt || !tgt->ltd_exp)
1053 continue; 1049 continue;
1054 1050
1055 nr = lmv_hsm_req_count(lmv, hur, tgt); 1051 nr = lmv_hsm_req_count(lmv, hur, tgt);
1052 if (nr < 0)
1053 return nr;
1056 if (nr == 0) /* nothing for this MDS */ 1054 if (nr == 0) /* nothing for this MDS */
1057 continue; 1055 continue;
1058 1056
@@ -1064,10 +1062,13 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1064 if (!req) 1062 if (!req)
1065 return -ENOMEM; 1063 return -ENOMEM;
1066 1064
1067 lmv_hsm_req_build(lmv, hur, tgt, req); 1065 rc1 = lmv_hsm_req_build(lmv, hur, tgt, req);
1066 if (rc1 < 0)
1067 goto hsm_req_err;
1068 1068
1069 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen, 1069 rc1 = obd_iocontrol(cmd, tgt->ltd_exp, reqlen,
1070 req, uarg); 1070 req, uarg);
1071hsm_req_err:
1071 if (rc1 != 0 && rc == 0) 1072 if (rc1 != 0 && rc == 0)
1072 rc = rc1; 1073 rc = rc1;
1073 kvfree(req); 1074 kvfree(req);
@@ -1276,7 +1277,6 @@ static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
1276 lmv->desc.ld_active_tgt_count = 0; 1277 lmv->desc.ld_active_tgt_count = 0;
1277 lmv->max_def_easize = 0; 1278 lmv->max_def_easize = 0;
1278 lmv->max_easize = 0; 1279 lmv->max_easize = 0;
1279 lmv->lmv_placement = PLACEMENT_CHAR_POLICY;
1280 1280
1281 spin_lock_init(&lmv->lmv_lock); 1281 spin_lock_init(&lmv->lmv_lock);
1282 mutex_init(&lmv->lmv_init_mutex); 1282 mutex_init(&lmv->lmv_init_mutex);
@@ -1425,8 +1425,7 @@ static int lmv_getstatus(struct obd_export *exp,
1425 if (rc) 1425 if (rc)
1426 return rc; 1426 return rc;
1427 1427
1428 rc = md_getstatus(lmv->tgts[0]->ltd_exp, fid); 1428 return md_getstatus(lmv->tgts[0]->ltd_exp, fid);
1429 return rc;
1430} 1429}
1431 1430
1432static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid, 1431static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
@@ -1447,10 +1446,8 @@ static int lmv_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1447 if (IS_ERR(tgt)) 1446 if (IS_ERR(tgt))
1448 return PTR_ERR(tgt); 1447 return PTR_ERR(tgt);
1449 1448
1450 rc = md_getxattr(tgt->ltd_exp, fid, valid, name, input, 1449 return md_getxattr(tgt->ltd_exp, fid, valid, name, input,
1451 input_size, output_size, flags, request); 1450 input_size, output_size, flags, request);
1452
1453 return rc;
1454} 1451}
1455 1452
1456static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid, 1453static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
@@ -1472,11 +1469,9 @@ static int lmv_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1472 if (IS_ERR(tgt)) 1469 if (IS_ERR(tgt))
1473 return PTR_ERR(tgt); 1470 return PTR_ERR(tgt);
1474 1471
1475 rc = md_setxattr(tgt->ltd_exp, fid, valid, name, input, 1472 return md_setxattr(tgt->ltd_exp, fid, valid, name, input,
1476 input_size, output_size, flags, suppgid, 1473 input_size, output_size, flags, suppgid,
1477 request); 1474 request);
1478
1479 return rc;
1480} 1475}
1481 1476
1482static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data, 1477static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
@@ -1500,9 +1495,7 @@ static int lmv_getattr(struct obd_export *exp, struct md_op_data *op_data,
1500 return 0; 1495 return 0;
1501 } 1496 }
1502 1497
1503 rc = md_getattr(tgt->ltd_exp, op_data, request); 1498 return md_getattr(tgt->ltd_exp, op_data, request);
1504
1505 return rc;
1506} 1499}
1507 1500
1508static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid) 1501static int lmv_null_inode(struct obd_export *exp, const struct lu_fid *fid)
@@ -1549,8 +1542,7 @@ static int lmv_close(struct obd_export *exp, struct md_op_data *op_data,
1549 return PTR_ERR(tgt); 1542 return PTR_ERR(tgt);
1550 1543
1551 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1)); 1544 CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
1552 rc = md_close(tgt->ltd_exp, op_data, mod, request); 1545 return md_close(tgt->ltd_exp, op_data, mod, request);
1553 return rc;
1554} 1546}
1555 1547
1556/** 1548/**
@@ -1743,10 +1735,8 @@ lmv_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
1743 CDEBUG(D_INODE, "ENQUEUE '%s' on " DFID " -> mds #%u\n", 1735 CDEBUG(D_INODE, "ENQUEUE '%s' on " DFID " -> mds #%u\n",
1744 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx); 1736 LL_IT2STR(it), PFID(&op_data->op_fid1), tgt->ltd_idx);
1745 1737
1746 rc = md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh, 1738 return md_enqueue(tgt->ltd_exp, einfo, policy, it, op_data, lockh,
1747 extra_lock_flags); 1739 extra_lock_flags);
1748
1749 return rc;
1750} 1740}
1751 1741
1752static int 1742static int
@@ -1894,9 +1884,7 @@ static int lmv_link(struct obd_export *exp, struct md_op_data *op_data,
1894 if (rc != 0) 1884 if (rc != 0)
1895 return rc; 1885 return rc;
1896 1886
1897 rc = md_link(tgt->ltd_exp, op_data, request); 1887 return md_link(tgt->ltd_exp, op_data, request);
1898
1899 return rc;
1900} 1888}
1901 1889
1902static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data, 1890static int lmv_rename(struct obd_export *exp, struct md_op_data *op_data,
@@ -2109,8 +2097,7 @@ static int lmv_sync(struct obd_export *exp, const struct lu_fid *fid,
2109 if (IS_ERR(tgt)) 2097 if (IS_ERR(tgt))
2110 return PTR_ERR(tgt); 2098 return PTR_ERR(tgt);
2111 2099
2112 rc = md_sync(tgt->ltd_exp, fid, request); 2100 return md_sync(tgt->ltd_exp, fid, request);
2113 return rc;
2114} 2101}
2115 2102
2116/** 2103/**
@@ -2428,17 +2415,14 @@ static int lmv_read_page(struct obd_export *exp, struct md_op_data *op_data,
2428 return rc; 2415 return rc;
2429 2416
2430 if (unlikely(lsm)) { 2417 if (unlikely(lsm)) {
2431 rc = lmv_read_striped_page(exp, op_data, cb_op, offset, ppage); 2418 return lmv_read_striped_page(exp, op_data, cb_op, offset, ppage);
2432 return rc;
2433 } 2419 }
2434 2420
2435 tgt = lmv_find_target(lmv, &op_data->op_fid1); 2421 tgt = lmv_find_target(lmv, &op_data->op_fid1);
2436 if (IS_ERR(tgt)) 2422 if (IS_ERR(tgt))
2437 return PTR_ERR(tgt); 2423 return PTR_ERR(tgt);
2438 2424
2439 rc = md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage); 2425 return md_read_page(tgt->ltd_exp, op_data, cb_op, offset, ppage);
2440
2441 return rc;
2442} 2426}
2443 2427
2444/** 2428/**
@@ -2922,13 +2906,11 @@ static int lmv_set_lock_data(struct obd_export *exp,
2922{ 2906{
2923 struct lmv_obd *lmv = &exp->exp_obd->u.lmv; 2907 struct lmv_obd *lmv = &exp->exp_obd->u.lmv;
2924 struct lmv_tgt_desc *tgt = lmv->tgts[0]; 2908 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2925 int rc;
2926 2909
2927 if (!tgt || !tgt->ltd_exp) 2910 if (!tgt || !tgt->ltd_exp)
2928 return -EINVAL; 2911 return -EINVAL;
2929 2912
2930 rc = md_set_lock_data(tgt->ltd_exp, lockh, data, bits); 2913 return md_set_lock_data(tgt->ltd_exp, lockh, data, bits);
2931 return rc;
2932} 2914}
2933 2915
2934static enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags, 2916static enum ldlm_mode lmv_lock_match(struct obd_export *exp, __u64 flags,
@@ -3033,25 +3015,40 @@ static int lmv_clear_open_replay_data(struct obd_export *exp,
3033} 3015}
3034 3016
3035static int lmv_intent_getattr_async(struct obd_export *exp, 3017static int lmv_intent_getattr_async(struct obd_export *exp,
3036 struct md_enqueue_info *minfo, 3018 struct md_enqueue_info *minfo)
3037 struct ldlm_enqueue_info *einfo)
3038{ 3019{
3039 struct md_op_data *op_data = &minfo->mi_data; 3020 struct md_op_data *op_data = &minfo->mi_data;
3040 struct obd_device *obd = exp->exp_obd; 3021 struct obd_device *obd = exp->exp_obd;
3041 struct lmv_obd *lmv = &obd->u.lmv; 3022 struct lmv_obd *lmv = &obd->u.lmv;
3042 struct lmv_tgt_desc *tgt = NULL; 3023 struct lmv_tgt_desc *ptgt = NULL;
3024 struct lmv_tgt_desc *ctgt = NULL;
3043 int rc; 3025 int rc;
3044 3026
3027 if (!fid_is_sane(&op_data->op_fid2))
3028 return -EINVAL;
3029
3045 rc = lmv_check_connect(obd); 3030 rc = lmv_check_connect(obd);
3046 if (rc) 3031 if (rc)
3047 return rc; 3032 return rc;
3048 3033
3049 tgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1); 3034 ptgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid1);
3050 if (IS_ERR(tgt)) 3035 if (IS_ERR(ptgt))
3051 return PTR_ERR(tgt); 3036 return PTR_ERR(ptgt);
3052 3037
3053 rc = md_intent_getattr_async(tgt->ltd_exp, minfo, einfo); 3038 ctgt = lmv_locate_mds(lmv, op_data, &op_data->op_fid2);
3054 return rc; 3039 if (IS_ERR(ctgt))
3040 return PTR_ERR(ctgt);
3041
3042 /*
3043 * if child is on remote MDT, we need 2 async RPCs to fetch both LOOKUP
3044 * lock on parent, and UPDATE lock on child MDT, which makes all
3045 * complicated. Considering remote dir is rare case, and not supporting
3046 * it in statahead won't cause any issue, drop its support for now.
3047 */
3048 if (ptgt != ctgt)
3049 return -ENOTSUPP;
3050
3051 return md_intent_getattr_async(ptgt->ltd_exp, minfo);
3055} 3052}
3056 3053
3057static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it, 3054static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
@@ -3070,8 +3067,7 @@ static int lmv_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
3070 if (IS_ERR(tgt)) 3067 if (IS_ERR(tgt))
3071 return PTR_ERR(tgt); 3068 return PTR_ERR(tgt);
3072 3069
3073 rc = md_revalidate_lock(tgt->ltd_exp, it, fid, bits); 3070 return md_revalidate_lock(tgt->ltd_exp, it, fid, bits);
3074 return rc;
3075} 3071}
3076 3072
3077static int 3073static int
@@ -3113,8 +3109,7 @@ static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
3113 } 3109 }
3114 3110
3115 if (oqctl->qc_cmd != Q_GETOQUOTA) { 3111 if (oqctl->qc_cmd != Q_GETOQUOTA) {
3116 rc = obd_quotactl(tgt->ltd_exp, oqctl); 3112 return obd_quotactl(tgt->ltd_exp, oqctl);
3117 return rc;
3118 } 3113 }
3119 3114
3120 for (i = 0; i < lmv->desc.ld_tgt_count; i++) { 3115 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
@@ -3234,13 +3229,11 @@ static struct md_ops lmv_md_ops = {
3234static int __init lmv_init(void) 3229static int __init lmv_init(void)
3235{ 3230{
3236 struct lprocfs_static_vars lvars; 3231 struct lprocfs_static_vars lvars;
3237 int rc;
3238 3232
3239 lprocfs_lmv_init_vars(&lvars); 3233 lprocfs_lmv_init_vars(&lvars);
3240 3234
3241 rc = class_register_type(&lmv_obd_ops, &lmv_md_ops, 3235 return class_register_type(&lmv_obd_ops, &lmv_md_ops,
3242 LUSTRE_LMV_NAME, NULL); 3236 LUSTRE_LMV_NAME, NULL);
3243 return rc;
3244} 3237}
3245 3238
3246static void lmv_exit(void) 3239static void lmv_exit(void)
diff --git a/drivers/staging/lustre/lustre/lmv/lproc_lmv.c b/drivers/staging/lustre/lustre/lmv/lproc_lmv.c
index 20bbdfc21d15..ff458020b96a 100644
--- a/drivers/staging/lustre/lustre/lmv/lproc_lmv.c
+++ b/drivers/staging/lustre/lustre/lmv/lproc_lmv.c
@@ -50,73 +50,6 @@ static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr,
50} 50}
51LUSTRE_RO_ATTR(numobd); 51LUSTRE_RO_ATTR(numobd);
52 52
53static const char *placement_name[] = {
54 [PLACEMENT_CHAR_POLICY] = "CHAR",
55 [PLACEMENT_NID_POLICY] = "NID",
56 [PLACEMENT_INVAL_POLICY] = "INVAL"
57};
58
59static enum placement_policy placement_name2policy(char *name, int len)
60{
61 int i;
62
63 for (i = 0; i < PLACEMENT_MAX_POLICY; i++) {
64 if (!strncmp(placement_name[i], name, len))
65 return i;
66 }
67 return PLACEMENT_INVAL_POLICY;
68}
69
70static const char *placement_policy2name(enum placement_policy placement)
71{
72 LASSERT(placement < PLACEMENT_MAX_POLICY);
73 return placement_name[placement];
74}
75
76static ssize_t placement_show(struct kobject *kobj, struct attribute *attr,
77 char *buf)
78{
79 struct obd_device *dev = container_of(kobj, struct obd_device,
80 obd_kobj);
81 struct lmv_obd *lmv;
82
83 lmv = &dev->u.lmv;
84 return sprintf(buf, "%s\n", placement_policy2name(lmv->lmv_placement));
85}
86
87#define MAX_POLICY_STRING_SIZE 64
88
89static ssize_t placement_store(struct kobject *kobj, struct attribute *attr,
90 const char *buffer,
91 size_t count)
92{
93 struct obd_device *dev = container_of(kobj, struct obd_device,
94 obd_kobj);
95 char dummy[MAX_POLICY_STRING_SIZE + 1];
96 enum placement_policy policy;
97 struct lmv_obd *lmv = &dev->u.lmv;
98
99 memcpy(dummy, buffer, MAX_POLICY_STRING_SIZE);
100
101 if (count > MAX_POLICY_STRING_SIZE)
102 count = MAX_POLICY_STRING_SIZE;
103
104 if (dummy[count - 1] == '\n')
105 count--;
106 dummy[count] = '\0';
107
108 policy = placement_name2policy(dummy, count);
109 if (policy != PLACEMENT_INVAL_POLICY) {
110 spin_lock(&lmv->lmv_lock);
111 lmv->lmv_placement = policy;
112 spin_unlock(&lmv->lmv_lock);
113 } else {
114 return -EINVAL;
115 }
116 return count;
117}
118LUSTRE_RW_ATTR(placement);
119
120static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr, 53static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr,
121 char *buf) 54 char *buf)
122{ 55{
@@ -147,7 +80,13 @@ static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos)
147 struct obd_device *dev = p->private; 80 struct obd_device *dev = p->private;
148 struct lmv_obd *lmv = &dev->u.lmv; 81 struct lmv_obd *lmv = &dev->u.lmv;
149 82
150 return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos]; 83 while (*pos < lmv->tgts_size) {
84 if (lmv->tgts[*pos])
85 return lmv->tgts[*pos];
86 ++*pos;
87 }
88
89 return NULL;
151} 90}
152 91
153static void lmv_tgt_seq_stop(struct seq_file *p, void *v) 92static void lmv_tgt_seq_stop(struct seq_file *p, void *v)
@@ -159,8 +98,15 @@ static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos)
159{ 98{
160 struct obd_device *dev = p->private; 99 struct obd_device *dev = p->private;
161 struct lmv_obd *lmv = &dev->u.lmv; 100 struct lmv_obd *lmv = &dev->u.lmv;
101
162 ++*pos; 102 ++*pos;
163 return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos]; 103 while (*pos < lmv->tgts_size) {
104 if (lmv->tgts[*pos])
105 return lmv->tgts[*pos];
106 ++*pos;
107 }
108
109 return NULL;
164} 110}
165 111
166static int lmv_tgt_seq_show(struct seq_file *p, void *v) 112static int lmv_tgt_seq_show(struct seq_file *p, void *v)
@@ -213,7 +159,6 @@ const struct file_operations lmv_proc_target_fops = {
213static struct attribute *lmv_attrs[] = { 159static struct attribute *lmv_attrs[] = {
214 &lustre_attr_activeobd.attr, 160 &lustre_attr_activeobd.attr,
215 &lustre_attr_numobd.attr, 161 &lustre_attr_numobd.attr,
216 &lustre_attr_placement.attr,
217 NULL, 162 NULL,
218}; 163};
219 164
diff --git a/drivers/staging/lustre/lustre/lov/lov_io.c b/drivers/staging/lustre/lustre/lov/lov_io.c
index 002326c282a7..e0f0756ee883 100644
--- a/drivers/staging/lustre/lustre/lov/lov_io.c
+++ b/drivers/staging/lustre/lustre/lov/lov_io.c
@@ -1056,9 +1056,12 @@ int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
1056 * - in setattr, for truncate 1056 * - in setattr, for truncate
1057 */ 1057 */
1058 /* the truncate is for size > 0 so triggers a restore */ 1058 /* the truncate is for size > 0 so triggers a restore */
1059 if (cl_io_is_trunc(io)) 1059 if (cl_io_is_trunc(io)) {
1060 io->ci_restore_needed = 1; 1060 io->ci_restore_needed = 1;
1061 result = -ENODATA; 1061 result = -ENODATA;
1062 } else {
1063 result = 1;
1064 }
1062 break; 1065 break;
1063 case CIT_READ: 1066 case CIT_READ:
1064 case CIT_WRITE: 1067 case CIT_WRITE:
diff --git a/drivers/staging/lustre/lustre/lov/lov_lock.c b/drivers/staging/lustre/lustre/lov/lov_lock.c
index f3a0583f28f5..8502128e8248 100644
--- a/drivers/staging/lustre/lustre/lov/lov_lock.c
+++ b/drivers/staging/lustre/lustre/lov/lov_lock.c
@@ -134,6 +134,11 @@ static struct lov_lock *lov_lock_sub_init(const struct lu_env *env,
134 struct lov_layout_raid0 *r0 = lov_r0(loo); 134 struct lov_layout_raid0 *r0 = lov_r0(loo);
135 struct lov_lock *lovlck; 135 struct lov_lock *lovlck;
136 136
137 CDEBUG(D_INODE, "%p: lock/io FID " DFID "/" DFID ", lock/io clobj %p/%p\n",
138 loo, PFID(lu_object_fid(lov2lu(loo))),
139 PFID(lu_object_fid(&obj->co_lu)),
140 lov2cl(loo), obj);
141
137 file_start = cl_offset(lov2cl(loo), lock->cll_descr.cld_start); 142 file_start = cl_offset(lov2cl(loo), lock->cll_descr.cld_start);
138 file_end = cl_offset(lov2cl(loo), lock->cll_descr.cld_end + 1) - 1; 143 file_end = cl_offset(lov2cl(loo), lock->cll_descr.cld_end + 1) - 1;
139 144
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index 63b064523c6a..b3161fb6d4b5 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -592,8 +592,6 @@ static int lov_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
592 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n", 592 CDEBUG(D_CONFIG, "idx=%d ltd_gen=%d ld_tgt_count=%d\n",
593 index, tgt->ltd_gen, lov->desc.ld_tgt_count); 593 index, tgt->ltd_gen, lov->desc.ld_tgt_count);
594 594
595 rc = obd_notify(obd, tgt_obd, OBD_NOTIFY_CREATE, &index);
596
597 if (lov->lov_connects == 0) { 595 if (lov->lov_connects == 0) {
598 /* lov_connect hasn't been called yet. We'll do the 596 /* lov_connect hasn't been called yet. We'll do the
599 * lov_connect_obd on this target when that fn first runs, 597 * lov_connect_obd on this target when that fn first runs,
diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c
index 76d4256fa828..977579c9c519 100644
--- a/drivers/staging/lustre/lustre/lov/lov_object.c
+++ b/drivers/staging/lustre/lustre/lov/lov_object.c
@@ -266,6 +266,13 @@ static int lov_init_raid0(const struct lu_env *env, struct lov_device *dev,
266 if (result != 0) 266 if (result != 0)
267 goto out; 267 goto out;
268 268
269 if (!dev->ld_target[ost_idx]) {
270 CERROR("%s: OST %04x is not initialized\n",
271 lov2obd(dev->ld_lov)->obd_name, ost_idx);
272 result = -EIO;
273 goto out;
274 }
275
269 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]); 276 subdev = lovsub2cl_dev(dev->ld_target[ost_idx]);
270 subconf->u.coc_oinfo = oinfo; 277 subconf->u.coc_oinfo = oinfo;
271 LASSERTF(subdev, "not init ost %d\n", ost_idx); 278 LASSERTF(subdev, "not init ost %d\n", ost_idx);
@@ -650,12 +657,16 @@ static enum lov_layout_type lov_type(struct lov_stripe_md *lsm)
650 657
651static inline void lov_conf_freeze(struct lov_object *lov) 658static inline void lov_conf_freeze(struct lov_object *lov)
652{ 659{
660 CDEBUG(D_INODE, "To take share lov(%p) owner %p/%p\n",
661 lov, lov->lo_owner, current);
653 if (lov->lo_owner != current) 662 if (lov->lo_owner != current)
654 down_read(&lov->lo_type_guard); 663 down_read(&lov->lo_type_guard);
655} 664}
656 665
657static inline void lov_conf_thaw(struct lov_object *lov) 666static inline void lov_conf_thaw(struct lov_object *lov)
658{ 667{
668 CDEBUG(D_INODE, "To release share lov(%p) owner %p/%p\n",
669 lov, lov->lo_owner, current);
659 if (lov->lo_owner != current) 670 if (lov->lo_owner != current)
660 up_read(&lov->lo_type_guard); 671 up_read(&lov->lo_type_guard);
661} 672}
@@ -698,10 +709,14 @@ static void lov_conf_lock(struct lov_object *lov)
698 down_write(&lov->lo_type_guard); 709 down_write(&lov->lo_type_guard);
699 LASSERT(!lov->lo_owner); 710 LASSERT(!lov->lo_owner);
700 lov->lo_owner = current; 711 lov->lo_owner = current;
712 CDEBUG(D_INODE, "Took exclusive lov(%p) owner %p\n",
713 lov, lov->lo_owner);
701} 714}
702 715
703static void lov_conf_unlock(struct lov_object *lov) 716static void lov_conf_unlock(struct lov_object *lov)
704{ 717{
718 CDEBUG(D_INODE, "To release exclusive lov(%p) owner %p\n",
719 lov, lov->lo_owner);
705 lov->lo_owner = NULL; 720 lov->lo_owner = NULL;
706 up_write(&lov->lo_type_guard); 721 up_write(&lov->lo_type_guard);
707} 722}
@@ -725,6 +740,7 @@ static int lov_layout_change(const struct lu_env *unused,
725 struct lov_object *lov, struct lov_stripe_md *lsm, 740 struct lov_object *lov, struct lov_stripe_md *lsm,
726 const struct cl_object_conf *conf) 741 const struct cl_object_conf *conf)
727{ 742{
743 struct lov_device *lov_dev = lov_object_dev(lov);
728 enum lov_layout_type llt = lov_type(lsm); 744 enum lov_layout_type llt = lov_type(lsm);
729 union lov_layout_state *state = &lov->u; 745 union lov_layout_state *state = &lov->u;
730 const struct lov_layout_operations *old_ops; 746 const struct lov_layout_operations *old_ops;
@@ -760,14 +776,21 @@ static int lov_layout_change(const struct lu_env *unused,
760 776
761 LASSERT(!atomic_read(&lov->lo_active_ios)); 777 LASSERT(!atomic_read(&lov->lo_active_ios));
762 778
779 CDEBUG(D_INODE, DFID "Apply new layout lov %p, type %d\n",
780 PFID(lu_object_fid(lov2lu(lov))), lov, llt);
781
763 lov->lo_type = LLT_EMPTY; 782 lov->lo_type = LLT_EMPTY;
764 783
765 /* page bufsize fixup */ 784 /* page bufsize fixup */
766 cl_object_header(&lov->lo_cl)->coh_page_bufsize -= 785 cl_object_header(&lov->lo_cl)->coh_page_bufsize -=
767 lov_page_slice_fixup(lov, NULL); 786 lov_page_slice_fixup(lov, NULL);
768 787
769 rc = new_ops->llo_init(env, lov_object_dev(lov), lov, lsm, conf, state); 788 rc = new_ops->llo_init(env, lov_dev, lov, lsm, conf, state);
770 if (rc) { 789 if (rc) {
790 struct obd_device *obd = lov2obd(lov_dev->ld_lov);
791
792 CERROR("%s: cannot apply new layout on " DFID " : rc = %d\n",
793 obd->obd_name, PFID(lu_object_fid(lov2lu(lov))), rc);
771 new_ops->llo_delete(env, lov, state); 794 new_ops->llo_delete(env, lov, state);
772 new_ops->llo_fini(env, lov, state); 795 new_ops->llo_fini(env, lov, state);
773 /* this file becomes an EMPTY file. */ 796 /* this file becomes an EMPTY file. */
@@ -923,6 +946,11 @@ int lov_io_init(const struct lu_env *env, struct cl_object *obj,
923 struct cl_io *io) 946 struct cl_io *io)
924{ 947{
925 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl); 948 CL_IO_SLICE_CLEAN(lov_env_io(env), lis_cl);
949
950 CDEBUG(D_INODE, DFID "io %p type %d ignore/verify layout %d/%d\n",
951 PFID(lu_object_fid(&obj->co_lu)), io, io->ci_type,
952 io->ci_ignore_layout, io->ci_verify_layout);
953
926 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init, 954 return LOV_2DISPATCH_MAYLOCK(cl2lov(obj), llo_io_init,
927 !io->ci_ignore_layout, env, obj, io); 955 !io->ci_ignore_layout, env, obj, io);
928} 956}
@@ -1453,14 +1481,11 @@ static int lov_object_layout_get(const struct lu_env *env,
1453 if (!lsm) { 1481 if (!lsm) {
1454 cl->cl_size = 0; 1482 cl->cl_size = 0;
1455 cl->cl_layout_gen = CL_LAYOUT_GEN_EMPTY; 1483 cl->cl_layout_gen = CL_LAYOUT_GEN_EMPTY;
1456 cl->cl_is_released = false;
1457
1458 return 0; 1484 return 0;
1459 } 1485 }
1460 1486
1461 cl->cl_size = lov_mds_md_size(lsm->lsm_stripe_count, lsm->lsm_magic); 1487 cl->cl_size = lov_mds_md_size(lsm->lsm_stripe_count, lsm->lsm_magic);
1462 cl->cl_layout_gen = lsm->lsm_layout_gen; 1488 cl->cl_layout_gen = lsm->lsm_layout_gen;
1463 cl->cl_is_released = lsm_is_released(lsm);
1464 1489
1465 rc = lov_lsm_pack(lsm, buf->lb_buf, buf->lb_len); 1490 rc = lov_lsm_pack(lsm, buf->lb_buf, buf->lb_len);
1466 lov_lsm_put(lsm); 1491 lov_lsm_put(lsm);
diff --git a/drivers/staging/lustre/lustre/lov/lov_pack.c b/drivers/staging/lustre/lustre/lov/lov_pack.c
index 6c93d180aef7..2e1bd47337fd 100644
--- a/drivers/staging/lustre/lustre/lov/lov_pack.c
+++ b/drivers/staging/lustre/lustre/lov/lov_pack.c
@@ -136,7 +136,7 @@ ssize_t lov_lsm_pack(const struct lov_stripe_md *lsm, void *buf,
136 lmmv1->lmm_layout_gen = cpu_to_le16(lsm->lsm_layout_gen); 136 lmmv1->lmm_layout_gen = cpu_to_le16(lsm->lsm_layout_gen);
137 137
138 if (lsm->lsm_magic == LOV_MAGIC_V3) { 138 if (lsm->lsm_magic == LOV_MAGIC_V3) {
139 CLASSERT(sizeof(lsm->lsm_pool_name) == 139 BUILD_BUG_ON(sizeof(lsm->lsm_pool_name) !=
140 sizeof(lmmv3->lmm_pool_name)); 140 sizeof(lmmv3->lmm_pool_name));
141 strlcpy(lmmv3->lmm_pool_name, lsm->lsm_pool_name, 141 strlcpy(lmmv3->lmm_pool_name, lsm->lsm_pool_name,
142 sizeof(lmmv3->lmm_pool_name)); 142 sizeof(lmmv3->lmm_pool_name));
@@ -198,7 +198,8 @@ static int lov_verify_lmm(void *lmm, int lmm_bytes, __u16 *stripe_count)
198 return rc; 198 return rc;
199} 199}
200 200
201struct lov_stripe_md *lov_lsm_alloc(u16 stripe_count, u32 pattern, u32 magic) 201static struct lov_stripe_md *lov_lsm_alloc(u16 stripe_count, u32 pattern,
202 u32 magic)
202{ 203{
203 struct lov_stripe_md *lsm; 204 struct lov_stripe_md *lsm;
204 unsigned int i; 205 unsigned int i;
@@ -356,8 +357,8 @@ int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm,
356 357
357 /* FIXME: Bug 1185 - copy fields properly when structs change */ 358 /* FIXME: Bug 1185 - copy fields properly when structs change */
358 /* struct lov_user_md_v3 and struct lov_mds_md_v3 must be the same */ 359 /* struct lov_user_md_v3 and struct lov_mds_md_v3 must be the same */
359 CLASSERT(sizeof(lum) == sizeof(struct lov_mds_md_v3)); 360 BUILD_BUG_ON(sizeof(lum) != sizeof(struct lov_mds_md_v3));
360 CLASSERT(sizeof(lum.lmm_objects[0]) == sizeof(lmmk->lmm_objects[0])); 361 BUILD_BUG_ON(sizeof(lum.lmm_objects[0]) != sizeof(lmmk->lmm_objects[0]));
361 362
362 if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC && 363 if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC &&
363 (lmmk->lmm_magic == cpu_to_le32(LOV_MAGIC_V1) || 364 (lmmk->lmm_magic == cpu_to_le32(LOV_MAGIC_V1) ||
diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c
index d43cc88ae641..3a747913fb4f 100644
--- a/drivers/staging/lustre/lustre/lov/lov_request.c
+++ b/drivers/staging/lustre/lustre/lov/lov_request.c
@@ -344,9 +344,6 @@ int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
344 continue; 344 continue;
345 } 345 }
346 346
347 if (!lov->lov_tgts[i]->ltd_active)
348 lov_check_and_wait_active(lov, i);
349
350 /* skip targets that have been explicitly disabled by the 347 /* skip targets that have been explicitly disabled by the
351 * administrator 348 * administrator
352 */ 349 */
@@ -355,6 +352,9 @@ int lov_prep_statfs_set(struct obd_device *obd, struct obd_info *oinfo,
355 continue; 352 continue;
356 } 353 }
357 354
355 if (!lov->lov_tgts[i]->ltd_active)
356 lov_check_and_wait_active(lov, i);
357
358 req = kzalloc(sizeof(*req), GFP_NOFS); 358 req = kzalloc(sizeof(*req), GFP_NOFS);
359 if (!req) { 359 if (!req) {
360 rc = -ENOMEM; 360 rc = -ENOMEM;
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_internal.h b/drivers/staging/lustre/lustre/mdc/mdc_internal.h
index 881c6a0676a6..fecedc8819ed 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_internal.h
+++ b/drivers/staging/lustre/lustre/mdc/mdc_internal.h
@@ -116,8 +116,7 @@ int mdc_revalidate_lock(struct obd_export *exp, struct lookup_intent *it,
116 struct lu_fid *fid, __u64 *bits); 116 struct lu_fid *fid, __u64 *bits);
117 117
118int mdc_intent_getattr_async(struct obd_export *exp, 118int mdc_intent_getattr_async(struct obd_export *exp,
119 struct md_enqueue_info *minfo, 119 struct md_enqueue_info *minfo);
120 struct ldlm_enqueue_info *einfo);
121 120
122enum ldlm_mode mdc_lock_match(struct obd_export *exp, __u64 flags, 121enum ldlm_mode mdc_lock_match(struct obd_export *exp, __u64 flags,
123 const struct lu_fid *fid, enum ldlm_type type, 122 const struct lu_fid *fid, enum ldlm_type type,
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_lib.c b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
index f35e1f9afdef..b1853ff7f8b9 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_lib.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
@@ -125,7 +125,7 @@ void mdc_create_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
125 char *tmp; 125 char *tmp;
126 __u64 flags; 126 __u64 flags;
127 127
128 CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_create)); 128 BUILD_BUG_ON(sizeof(struct mdt_rec_reint) != sizeof(struct mdt_rec_create));
129 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); 129 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
130 130
131 rec->cr_opcode = REINT_CREATE; 131 rec->cr_opcode = REINT_CREATE;
@@ -189,7 +189,7 @@ void mdc_open_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
189 char *tmp; 189 char *tmp;
190 __u64 cr_flags; 190 __u64 cr_flags;
191 191
192 CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_create)); 192 BUILD_BUG_ON(sizeof(struct mdt_rec_reint) != sizeof(struct mdt_rec_create));
193 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); 193 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
194 194
195 /* XXX do something about time, uid, gid */ 195 /* XXX do something about time, uid, gid */
@@ -313,7 +313,7 @@ void mdc_setattr_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
313 struct mdt_rec_setattr *rec; 313 struct mdt_rec_setattr *rec;
314 struct lov_user_md *lum = NULL; 314 struct lov_user_md *lum = NULL;
315 315
316 CLASSERT(sizeof(struct mdt_rec_reint) == 316 BUILD_BUG_ON(sizeof(struct mdt_rec_reint) !=
317 sizeof(struct mdt_rec_setattr)); 317 sizeof(struct mdt_rec_setattr));
318 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); 318 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
319 mdc_setattr_pack_rec(rec, op_data); 319 mdc_setattr_pack_rec(rec, op_data);
@@ -336,7 +336,7 @@ void mdc_unlink_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
336{ 336{
337 struct mdt_rec_unlink *rec; 337 struct mdt_rec_unlink *rec;
338 338
339 CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_unlink)); 339 BUILD_BUG_ON(sizeof(struct mdt_rec_reint) != sizeof(struct mdt_rec_unlink));
340 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); 340 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
341 341
342 rec->ul_opcode = op_data->op_cli_flags & CLI_RM_ENTRY ? 342 rec->ul_opcode = op_data->op_cli_flags & CLI_RM_ENTRY ?
@@ -359,7 +359,7 @@ void mdc_link_pack(struct ptlrpc_request *req, struct md_op_data *op_data)
359{ 359{
360 struct mdt_rec_link *rec; 360 struct mdt_rec_link *rec;
361 361
362 CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_link)); 362 BUILD_BUG_ON(sizeof(struct mdt_rec_reint) != sizeof(struct mdt_rec_link));
363 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); 363 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
364 364
365 rec->lk_opcode = REINT_LINK; 365 rec->lk_opcode = REINT_LINK;
@@ -407,7 +407,7 @@ void mdc_rename_pack(struct ptlrpc_request *req, struct md_op_data *op_data,
407{ 407{
408 struct mdt_rec_rename *rec; 408 struct mdt_rec_rename *rec;
409 409
410 CLASSERT(sizeof(struct mdt_rec_reint) == sizeof(struct mdt_rec_rename)); 410 BUILD_BUG_ON(sizeof(struct mdt_rec_reint) != sizeof(struct mdt_rec_rename));
411 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); 411 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
412 412
413 /* XXX do something about time, uid, gid */ 413 /* XXX do something about time, uid, gid */
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_locks.c b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
index 54ebb9952d66..392b0e38a91e 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_locks.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
@@ -49,7 +49,6 @@
49struct mdc_getattr_args { 49struct mdc_getattr_args {
50 struct obd_export *ga_exp; 50 struct obd_export *ga_exp;
51 struct md_enqueue_info *ga_minfo; 51 struct md_enqueue_info *ga_minfo;
52 struct ldlm_enqueue_info *ga_einfo;
53}; 52};
54 53
55int it_open_error(int phase, struct lookup_intent *it) 54int it_open_error(int phase, struct lookup_intent *it)
@@ -722,7 +721,7 @@ int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
722 LASSERT(!policy); 721 LASSERT(!policy);
723 722
724 saved_flags |= LDLM_FL_HAS_INTENT; 723 saved_flags |= LDLM_FL_HAS_INTENT;
725 if (it->it_op & (IT_OPEN | IT_UNLINK | IT_GETATTR | IT_READDIR)) 724 if (it->it_op & (IT_UNLINK | IT_GETATTR | IT_READDIR))
726 policy = &update_policy; 725 policy = &update_policy;
727 else if (it->it_op & IT_LAYOUT) 726 else if (it->it_op & IT_LAYOUT)
728 policy = &layout_policy; 727 policy = &layout_policy;
@@ -1111,7 +1110,7 @@ static int mdc_intent_getattr_async_interpret(const struct lu_env *env,
1111 struct mdc_getattr_args *ga = args; 1110 struct mdc_getattr_args *ga = args;
1112 struct obd_export *exp = ga->ga_exp; 1111 struct obd_export *exp = ga->ga_exp;
1113 struct md_enqueue_info *minfo = ga->ga_minfo; 1112 struct md_enqueue_info *minfo = ga->ga_minfo;
1114 struct ldlm_enqueue_info *einfo = ga->ga_einfo; 1113 struct ldlm_enqueue_info *einfo = &minfo->mi_einfo;
1115 struct lookup_intent *it; 1114 struct lookup_intent *it;
1116 struct lustre_handle *lockh; 1115 struct lustre_handle *lockh;
1117 struct obd_device *obddev; 1116 struct obd_device *obddev;
@@ -1147,14 +1146,12 @@ static int mdc_intent_getattr_async_interpret(const struct lu_env *env,
1147 rc = mdc_finish_intent_lock(exp, req, &minfo->mi_data, it, lockh); 1146 rc = mdc_finish_intent_lock(exp, req, &minfo->mi_data, it, lockh);
1148 1147
1149out: 1148out:
1150 kfree(einfo);
1151 minfo->mi_cb(req, minfo, rc); 1149 minfo->mi_cb(req, minfo, rc);
1152 return 0; 1150 return 0;
1153} 1151}
1154 1152
1155int mdc_intent_getattr_async(struct obd_export *exp, 1153int mdc_intent_getattr_async(struct obd_export *exp,
1156 struct md_enqueue_info *minfo, 1154 struct md_enqueue_info *minfo)
1157 struct ldlm_enqueue_info *einfo)
1158{ 1155{
1159 struct md_op_data *op_data = &minfo->mi_data; 1156 struct md_op_data *op_data = &minfo->mi_data;
1160 struct lookup_intent *it = &minfo->mi_it; 1157 struct lookup_intent *it = &minfo->mi_it;
@@ -1162,10 +1159,6 @@ int mdc_intent_getattr_async(struct obd_export *exp,
1162 struct mdc_getattr_args *ga; 1159 struct mdc_getattr_args *ga;
1163 struct obd_device *obddev = class_exp2obd(exp); 1160 struct obd_device *obddev = class_exp2obd(exp);
1164 struct ldlm_res_id res_id; 1161 struct ldlm_res_id res_id;
1165 /*XXX: Both MDS_INODELOCK_LOOKUP and MDS_INODELOCK_UPDATE are needed
1166 * for statahead currently. Consider CMD in future, such two bits
1167 * maybe managed by different MDS, should be adjusted then.
1168 */
1169 union ldlm_policy_data policy = { 1162 union ldlm_policy_data policy = {
1170 .l_inodebits = { MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE } 1163 .l_inodebits = { MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE }
1171 }; 1164 };
@@ -1188,19 +1181,18 @@ int mdc_intent_getattr_async(struct obd_export *exp,
1188 return rc; 1181 return rc;
1189 } 1182 }
1190 1183
1191 rc = ldlm_cli_enqueue(exp, &req, einfo, &res_id, &policy, &flags, NULL, 1184 rc = ldlm_cli_enqueue(exp, &req, &minfo->mi_einfo, &res_id, &policy,
1192 0, LVB_T_NONE, &minfo->mi_lockh, 1); 1185 &flags, NULL, 0, LVB_T_NONE, &minfo->mi_lockh, 1);
1193 if (rc < 0) { 1186 if (rc < 0) {
1194 obd_put_request_slot(&obddev->u.cli); 1187 obd_put_request_slot(&obddev->u.cli);
1195 ptlrpc_req_finished(req); 1188 ptlrpc_req_finished(req);
1196 return rc; 1189 return rc;
1197 } 1190 }
1198 1191
1199 CLASSERT(sizeof(*ga) <= sizeof(req->rq_async_args)); 1192 BUILD_BUG_ON(sizeof(*ga) > sizeof(req->rq_async_args));
1200 ga = ptlrpc_req_async_args(req); 1193 ga = ptlrpc_req_async_args(req);
1201 ga->ga_exp = exp; 1194 ga->ga_exp = exp;
1202 ga->ga_minfo = minfo; 1195 ga->ga_minfo = minfo;
1203 ga->ga_einfo = einfo;
1204 1196
1205 req->rq_interpret_reply = mdc_intent_getattr_async_interpret; 1197 req->rq_interpret_reply = mdc_intent_getattr_async_interpret;
1206 ptlrpcd_add_req(req); 1198 ptlrpcd_add_req(req);
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 2cfd913f9bc5..6bc2fb858680 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -295,7 +295,7 @@ static int mdc_xattr_common(struct obd_export *exp,
295 if (opcode == MDS_REINT) { 295 if (opcode == MDS_REINT) {
296 struct mdt_rec_setxattr *rec; 296 struct mdt_rec_setxattr *rec;
297 297
298 CLASSERT(sizeof(struct mdt_rec_setxattr) == 298 BUILD_BUG_ON(sizeof(struct mdt_rec_setxattr) !=
299 sizeof(struct mdt_rec_reint)); 299 sizeof(struct mdt_rec_reint));
300 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); 300 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
301 rec->sx_opcode = REINT_SETXATTR; 301 rec->sx_opcode = REINT_SETXATTR;
@@ -762,6 +762,7 @@ static int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
762 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE); 762 rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
763 if (rc) { 763 if (rc) {
764 ptlrpc_request_free(req); 764 ptlrpc_request_free(req);
765 req = NULL;
765 goto out; 766 goto out;
766 } 767 }
767 768
@@ -2465,13 +2466,6 @@ static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
2465 LASSERT(imp->imp_obd == obd); 2466 LASSERT(imp->imp_obd == obd);
2466 2467
2467 switch (event) { 2468 switch (event) {
2468 case IMP_EVENT_DISCON: {
2469#if 0
2470 /* XXX Pass event up to OBDs stack. used only for FLD now */
2471 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
2472#endif
2473 break;
2474 }
2475 case IMP_EVENT_INACTIVE: { 2469 case IMP_EVENT_INACTIVE: {
2476 struct client_obd *cli = &obd->u.cli; 2470 struct client_obd *cli = &obd->u.cli;
2477 /* 2471 /*
@@ -2503,6 +2497,7 @@ static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
2503 case IMP_EVENT_OCD: 2497 case IMP_EVENT_OCD:
2504 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL); 2498 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
2505 break; 2499 break;
2500 case IMP_EVENT_DISCON:
2506 case IMP_EVENT_DEACTIVATE: 2501 case IMP_EVENT_DEACTIVATE:
2507 case IMP_EVENT_ACTIVATE: 2502 case IMP_EVENT_ACTIVATE:
2508 break; 2503 break;
diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index b9c522a3c7a4..6a76605b3c3d 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -142,10 +142,10 @@ static void config_log_put(struct config_llog_data *cld)
142 142
143 if (cld->cld_recover) 143 if (cld->cld_recover)
144 config_log_put(cld->cld_recover); 144 config_log_put(cld->cld_recover);
145 if (cld->cld_sptlrpc)
146 config_log_put(cld->cld_sptlrpc);
147 if (cld->cld_params) 145 if (cld->cld_params)
148 config_log_put(cld->cld_params); 146 config_log_put(cld->cld_params);
147 if (cld->cld_sptlrpc)
148 config_log_put(cld->cld_sptlrpc);
149 if (cld_is_sptlrpc(cld)) 149 if (cld_is_sptlrpc(cld))
150 sptlrpc_conf_log_stop(cld->cld_logname); 150 sptlrpc_conf_log_stop(cld->cld_logname);
151 151
@@ -175,13 +175,10 @@ struct config_llog_data *config_log_find(char *logname,
175 /* instance may be NULL, should check name */ 175 /* instance may be NULL, should check name */
176 if (strcmp(logname, cld->cld_logname) == 0) { 176 if (strcmp(logname, cld->cld_logname) == 0) {
177 found = cld; 177 found = cld;
178 config_log_get(found);
178 break; 179 break;
179 } 180 }
180 } 181 }
181 if (found) {
182 atomic_inc(&found->cld_refcount);
183 LASSERT(found->cld_stopping == 0 || cld_is_sptlrpc(found) == 0);
184 }
185 spin_unlock(&config_list_lock); 182 spin_unlock(&config_list_lock);
186 return found; 183 return found;
187} 184}
@@ -203,6 +200,12 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
203 if (!cld) 200 if (!cld)
204 return ERR_PTR(-ENOMEM); 201 return ERR_PTR(-ENOMEM);
205 202
203 rc = mgc_logname2resid(logname, &cld->cld_resid, type);
204 if (rc) {
205 kfree(cld);
206 return ERR_PTR(rc);
207 }
208
206 strcpy(cld->cld_logname, logname); 209 strcpy(cld->cld_logname, logname);
207 if (cfg) 210 if (cfg)
208 cld->cld_cfg = *cfg; 211 cld->cld_cfg = *cfg;
@@ -223,17 +226,10 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
223 cld->cld_cfg.cfg_obdname = obd->obd_name; 226 cld->cld_cfg.cfg_obdname = obd->obd_name;
224 } 227 }
225 228
226 rc = mgc_logname2resid(logname, &cld->cld_resid, type);
227
228 spin_lock(&config_list_lock); 229 spin_lock(&config_list_lock);
229 list_add(&cld->cld_list_chain, &config_llog_list); 230 list_add(&cld->cld_list_chain, &config_llog_list);
230 spin_unlock(&config_list_lock); 231 spin_unlock(&config_list_lock);
231 232
232 if (rc) {
233 config_log_put(cld);
234 return ERR_PTR(rc);
235 }
236
237 if (cld_is_sptlrpc(cld)) { 233 if (cld_is_sptlrpc(cld)) {
238 rc = mgc_process_log(obd, cld); 234 rc = mgc_process_log(obd, cld);
239 if (rc && rc != -ENOENT) 235 if (rc && rc != -ENOENT)
@@ -284,14 +280,15 @@ config_params_log_add(struct obd_device *obd,
284 * We have one active log per "mount" - client instance or servername. 280 * We have one active log per "mount" - client instance or servername.
285 * Each instance may be at a different point in the log. 281 * Each instance may be at a different point in the log.
286 */ 282 */
287static int config_log_add(struct obd_device *obd, char *logname, 283static struct config_llog_data *
288 struct config_llog_instance *cfg, 284config_log_add(struct obd_device *obd, char *logname,
289 struct super_block *sb) 285 struct config_llog_instance *cfg, struct super_block *sb)
290{ 286{
291 struct lustre_sb_info *lsi = s2lsi(sb); 287 struct lustre_sb_info *lsi = s2lsi(sb);
292 struct config_llog_data *cld; 288 struct config_llog_data *cld;
293 struct config_llog_data *sptlrpc_cld; 289 struct config_llog_data *sptlrpc_cld;
294 struct config_llog_data *params_cld; 290 struct config_llog_data *params_cld;
291 bool locked = false;
295 char seclogname[32]; 292 char seclogname[32];
296 char *ptr; 293 char *ptr;
297 int rc; 294 int rc;
@@ -305,7 +302,7 @@ static int config_log_add(struct obd_device *obd, char *logname,
305 ptr = strrchr(logname, '-'); 302 ptr = strrchr(logname, '-');
306 if (!ptr || ptr - logname > 8) { 303 if (!ptr || ptr - logname > 8) {
307 CERROR("logname %s is too long\n", logname); 304 CERROR("logname %s is too long\n", logname);
308 return -EINVAL; 305 return ERR_PTR(-EINVAL);
309 } 306 }
310 307
311 memcpy(seclogname, logname, ptr - logname); 308 memcpy(seclogname, logname, ptr - logname);
@@ -326,14 +323,14 @@ static int config_log_add(struct obd_device *obd, char *logname,
326 rc = PTR_ERR(params_cld); 323 rc = PTR_ERR(params_cld);
327 CERROR("%s: can't create params log: rc = %d\n", 324 CERROR("%s: can't create params log: rc = %d\n",
328 obd->obd_name, rc); 325 obd->obd_name, rc);
329 goto out_err1; 326 goto out_sptlrpc;
330 } 327 }
331 328
332 cld = do_config_log_add(obd, logname, CONFIG_T_CONFIG, cfg, sb); 329 cld = do_config_log_add(obd, logname, CONFIG_T_CONFIG, cfg, sb);
333 if (IS_ERR(cld)) { 330 if (IS_ERR(cld)) {
334 CERROR("can't create log: %s\n", logname); 331 CERROR("can't create log: %s\n", logname);
335 rc = PTR_ERR(cld); 332 rc = PTR_ERR(cld);
336 goto out_err2; 333 goto out_params;
337 } 334 }
338 335
339 cld->cld_sptlrpc = sptlrpc_cld; 336 cld->cld_sptlrpc = sptlrpc_cld;
@@ -350,33 +347,52 @@ static int config_log_add(struct obd_device *obd, char *logname,
350 CERROR("%s: sptlrpc log name not correct, %s: rc = %d\n", 347 CERROR("%s: sptlrpc log name not correct, %s: rc = %d\n",
351 obd->obd_name, seclogname, -EINVAL); 348 obd->obd_name, seclogname, -EINVAL);
352 config_log_put(cld); 349 config_log_put(cld);
353 return -EINVAL; 350 rc = -EINVAL;
351 goto out_cld;
354 } 352 }
355 recover_cld = config_recover_log_add(obd, seclogname, cfg, sb); 353 recover_cld = config_recover_log_add(obd, seclogname, cfg, sb);
356 if (IS_ERR(recover_cld)) { 354 if (IS_ERR(recover_cld)) {
357 rc = PTR_ERR(recover_cld); 355 rc = PTR_ERR(recover_cld);
358 goto out_err3; 356 goto out_cld;
359 } 357 }
358
359 mutex_lock(&cld->cld_lock);
360 locked = true;
360 cld->cld_recover = recover_cld; 361 cld->cld_recover = recover_cld;
361 } 362 }
362 363
363 return 0; 364 if (!locked)
365 mutex_lock(&cld->cld_lock);
366 cld->cld_params = params_cld;
367 cld->cld_sptlrpc = sptlrpc_cld;
368 mutex_unlock(&cld->cld_lock);
369
370 return cld;
364 371
365out_err3: 372out_cld:
366 config_log_put(cld); 373 config_log_put(cld);
367 374
368out_err2: 375out_params:
369 config_log_put(params_cld); 376 config_log_put(params_cld);
370 377
371out_err1: 378out_sptlrpc:
372 config_log_put(sptlrpc_cld); 379 config_log_put(sptlrpc_cld);
373 380
374out_err: 381out_err:
375 return rc; 382 return ERR_PTR(rc);
376} 383}
377 384
378static DEFINE_MUTEX(llog_process_lock); 385static DEFINE_MUTEX(llog_process_lock);
379 386
387static inline void config_mark_cld_stop(struct config_llog_data *cld)
388{
389 mutex_lock(&cld->cld_lock);
390 spin_lock(&config_list_lock);
391 cld->cld_stopping = 1;
392 spin_unlock(&config_list_lock);
393 mutex_unlock(&cld->cld_lock);
394}
395
380/** Stop watching for updates on this log. 396/** Stop watching for updates on this log.
381 */ 397 */
382static int config_log_end(char *logname, struct config_llog_instance *cfg) 398static int config_log_end(char *logname, struct config_llog_instance *cfg)
@@ -406,36 +422,32 @@ static int config_log_end(char *logname, struct config_llog_instance *cfg)
406 return rc; 422 return rc;
407 } 423 }
408 424
425 spin_lock(&config_list_lock);
409 cld->cld_stopping = 1; 426 cld->cld_stopping = 1;
427 spin_unlock(&config_list_lock);
410 428
411 cld_recover = cld->cld_recover; 429 cld_recover = cld->cld_recover;
412 cld->cld_recover = NULL; 430 cld->cld_recover = NULL;
431
432 cld_params = cld->cld_params;
433 cld->cld_params = NULL;
434 cld_sptlrpc = cld->cld_sptlrpc;
435 cld->cld_sptlrpc = NULL;
413 mutex_unlock(&cld->cld_lock); 436 mutex_unlock(&cld->cld_lock);
414 437
415 if (cld_recover) { 438 if (cld_recover) {
416 mutex_lock(&cld_recover->cld_lock); 439 config_mark_cld_stop(cld_recover);
417 cld_recover->cld_stopping = 1;
418 mutex_unlock(&cld_recover->cld_lock);
419 config_log_put(cld_recover); 440 config_log_put(cld_recover);
420 } 441 }
421 442
422 spin_lock(&config_list_lock);
423 cld_sptlrpc = cld->cld_sptlrpc;
424 cld->cld_sptlrpc = NULL;
425 cld_params = cld->cld_params;
426 cld->cld_params = NULL;
427 spin_unlock(&config_list_lock);
428
429 if (cld_sptlrpc)
430 config_log_put(cld_sptlrpc);
431
432 if (cld_params) { 443 if (cld_params) {
433 mutex_lock(&cld_params->cld_lock); 444 config_mark_cld_stop(cld_params);
434 cld_params->cld_stopping = 1;
435 mutex_unlock(&cld_params->cld_lock);
436 config_log_put(cld_params); 445 config_log_put(cld_params);
437 } 446 }
438 447
448 if (cld_sptlrpc)
449 config_log_put(cld_sptlrpc);
450
439 /* drop the ref from the find */ 451 /* drop the ref from the find */
440 config_log_put(cld); 452 config_log_put(cld);
441 /* drop the start ref */ 453 /* drop the start ref */
@@ -531,11 +543,10 @@ static int mgc_requeue_thread(void *data)
531 /* Keep trying failed locks periodically */ 543 /* Keep trying failed locks periodically */
532 spin_lock(&config_list_lock); 544 spin_lock(&config_list_lock);
533 rq_state |= RQ_RUNNING; 545 rq_state |= RQ_RUNNING;
534 while (1) { 546 while (!(rq_state & RQ_STOP)) {
535 struct l_wait_info lwi; 547 struct l_wait_info lwi;
536 struct config_llog_data *cld, *cld_prev; 548 struct config_llog_data *cld, *cld_prev;
537 int rand = cfs_rand() & MGC_TIMEOUT_RAND_CENTISEC; 549 int rand = cfs_rand() & MGC_TIMEOUT_RAND_CENTISEC;
538 int stopped = !!(rq_state & RQ_STOP);
539 int to; 550 int to;
540 551
541 /* Any new or requeued lostlocks will change the state */ 552 /* Any new or requeued lostlocks will change the state */
@@ -571,44 +582,40 @@ static int mgc_requeue_thread(void *data)
571 spin_lock(&config_list_lock); 582 spin_lock(&config_list_lock);
572 rq_state &= ~RQ_PRECLEANUP; 583 rq_state &= ~RQ_PRECLEANUP;
573 list_for_each_entry(cld, &config_llog_list, cld_list_chain) { 584 list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
574 if (!cld->cld_lostlock) 585 if (!cld->cld_lostlock || cld->cld_stopping)
575 continue; 586 continue;
576 587
588 /*
589 * hold reference to avoid being freed during
590 * subsequent processing.
591 */
592 config_log_get(cld);
593 cld->cld_lostlock = 0;
577 spin_unlock(&config_list_lock); 594 spin_unlock(&config_list_lock);
578 595
579 LASSERT(atomic_read(&cld->cld_refcount) > 0);
580
581 /* Whether we enqueued again or not in mgc_process_log,
582 * we're done with the ref from the old enqueue
583 */
584 if (cld_prev) 596 if (cld_prev)
585 config_log_put(cld_prev); 597 config_log_put(cld_prev);
586 cld_prev = cld; 598 cld_prev = cld;
587 599
588 cld->cld_lostlock = 0; 600 if (likely(!(rq_state & RQ_STOP))) {
589 if (likely(!stopped))
590 do_requeue(cld); 601 do_requeue(cld);
591 602 spin_lock(&config_list_lock);
592 spin_lock(&config_list_lock); 603 } else {
604 spin_lock(&config_list_lock);
605 break;
606 }
593 } 607 }
594 spin_unlock(&config_list_lock); 608 spin_unlock(&config_list_lock);
595 if (cld_prev) 609 if (cld_prev)
596 config_log_put(cld_prev); 610 config_log_put(cld_prev);
597 611
598 /* break after scanning the list so that we can drop
599 * refcount to losing lock clds
600 */
601 if (unlikely(stopped)) {
602 spin_lock(&config_list_lock);
603 break;
604 }
605
606 /* Wait a bit to see if anyone else needs a requeue */ 612 /* Wait a bit to see if anyone else needs a requeue */
607 lwi = (struct l_wait_info) { 0 }; 613 lwi = (struct l_wait_info) { 0 };
608 l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP), 614 l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP),
609 &lwi); 615 &lwi);
610 spin_lock(&config_list_lock); 616 spin_lock(&config_list_lock);
611 } 617 }
618
612 /* spinlock and while guarantee RQ_NOW and RQ_LATER are not set */ 619 /* spinlock and while guarantee RQ_NOW and RQ_LATER are not set */
613 rq_state &= ~RQ_RUNNING; 620 rq_state &= ~RQ_RUNNING;
614 spin_unlock(&config_list_lock); 621 spin_unlock(&config_list_lock);
@@ -624,32 +631,24 @@ static int mgc_requeue_thread(void *data)
624 */ 631 */
625static void mgc_requeue_add(struct config_llog_data *cld) 632static void mgc_requeue_add(struct config_llog_data *cld)
626{ 633{
634 bool wakeup = false;
635
627 CDEBUG(D_INFO, "log %s: requeue (r=%d sp=%d st=%x)\n", 636 CDEBUG(D_INFO, "log %s: requeue (r=%d sp=%d st=%x)\n",
628 cld->cld_logname, atomic_read(&cld->cld_refcount), 637 cld->cld_logname, atomic_read(&cld->cld_refcount),
629 cld->cld_stopping, rq_state); 638 cld->cld_stopping, rq_state);
630 LASSERT(atomic_read(&cld->cld_refcount) > 0); 639 LASSERT(atomic_read(&cld->cld_refcount) > 0);
631 640
632 mutex_lock(&cld->cld_lock); 641 mutex_lock(&cld->cld_lock);
633 if (cld->cld_stopping || cld->cld_lostlock) {
634 mutex_unlock(&cld->cld_lock);
635 return;
636 }
637 /* this refcount will be released in mgc_requeue_thread. */
638 config_log_get(cld);
639 cld->cld_lostlock = 1;
640 mutex_unlock(&cld->cld_lock);
641
642 /* Hold lock for rq_state */
643 spin_lock(&config_list_lock); 642 spin_lock(&config_list_lock);
644 if (rq_state & RQ_STOP) { 643 if (!(rq_state & RQ_STOP) && !cld->cld_stopping && !cld->cld_lostlock) {
645 spin_unlock(&config_list_lock); 644 cld->cld_lostlock = 1;
646 cld->cld_lostlock = 0;
647 config_log_put(cld);
648 } else {
649 rq_state |= RQ_NOW; 645 rq_state |= RQ_NOW;
650 spin_unlock(&config_list_lock); 646 wakeup = true;
651 wake_up(&rq_waitq);
652 } 647 }
648 spin_unlock(&config_list_lock);
649 mutex_unlock(&cld->cld_lock);
650 if (wakeup)
651 wake_up(&rq_waitq);
653} 652}
654 653
655static int mgc_llog_init(const struct lu_env *env, struct obd_device *obd) 654static int mgc_llog_init(const struct lu_env *env, struct obd_device *obd)
@@ -812,6 +811,8 @@ static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
812 811
813 /* held at mgc_process_log(). */ 812 /* held at mgc_process_log(). */
814 LASSERT(atomic_read(&cld->cld_refcount) > 0); 813 LASSERT(atomic_read(&cld->cld_refcount) > 0);
814
815 lock->l_ast_data = NULL;
815 /* Are we done with this log? */ 816 /* Are we done with this log? */
816 if (cld->cld_stopping) { 817 if (cld->cld_stopping) {
817 CDEBUG(D_MGC, "log %s: stopping, won't requeue\n", 818 CDEBUG(D_MGC, "log %s: stopping, won't requeue\n",
@@ -1661,16 +1662,18 @@ restart:
1661 goto restart; 1662 goto restart;
1662 } else { 1663 } else {
1663 mutex_lock(&cld->cld_lock); 1664 mutex_lock(&cld->cld_lock);
1665 spin_lock(&config_list_lock);
1664 cld->cld_lostlock = 1; 1666 cld->cld_lostlock = 1;
1667 spin_unlock(&config_list_lock);
1665 } 1668 }
1666 } else { 1669 } else {
1667 /* mark cld_lostlock so that it will requeue 1670 /* mark cld_lostlock so that it will requeue
1668 * after MGC becomes available. 1671 * after MGC becomes available.
1669 */ 1672 */
1673 spin_lock(&config_list_lock);
1670 cld->cld_lostlock = 1; 1674 cld->cld_lostlock = 1;
1675 spin_unlock(&config_list_lock);
1671 } 1676 }
1672 /* Get extra reference, it will be put in requeue thread */
1673 config_log_get(cld);
1674 } 1677 }
1675 1678
1676 if (cld_is_recover(cld)) { 1679 if (cld_is_recover(cld)) {
@@ -1681,7 +1684,9 @@ restart:
1681 CERROR("%s: recover log %s failed: rc = %d not fatal.\n", 1684 CERROR("%s: recover log %s failed: rc = %d not fatal.\n",
1682 mgc->obd_name, cld->cld_logname, rc); 1685 mgc->obd_name, cld->cld_logname, rc);
1683 rc = 0; 1686 rc = 0;
1687 spin_lock(&config_list_lock);
1684 cld->cld_lostlock = 1; 1688 cld->cld_lostlock = 1;
1689 spin_unlock(&config_list_lock);
1685 } 1690 }
1686 } 1691 }
1687 } else { 1692 } else {
@@ -1749,12 +1754,9 @@ static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)
1749 cfg->cfg_last_idx); 1754 cfg->cfg_last_idx);
1750 1755
1751 /* We're only called through here on the initial mount */ 1756 /* We're only called through here on the initial mount */
1752 rc = config_log_add(obd, logname, cfg, sb); 1757 cld = config_log_add(obd, logname, cfg, sb);
1753 if (rc) 1758 if (IS_ERR(cld)) {
1754 break; 1759 rc = PTR_ERR(cld);
1755 cld = config_log_find(logname, cfg);
1756 if (!cld) {
1757 rc = -ENOENT;
1758 break; 1760 break;
1759 } 1761 }
1760 1762
@@ -1770,11 +1772,15 @@ static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)
1770 imp_connect_data, IMP_RECOV)) { 1772 imp_connect_data, IMP_RECOV)) {
1771 rc = mgc_process_log(obd, cld->cld_recover); 1773 rc = mgc_process_log(obd, cld->cld_recover);
1772 } else { 1774 } else {
1773 struct config_llog_data *cir = cld->cld_recover; 1775 struct config_llog_data *cir;
1774 1776
1777 mutex_lock(&cld->cld_lock);
1778 cir = cld->cld_recover;
1775 cld->cld_recover = NULL; 1779 cld->cld_recover = NULL;
1780 mutex_unlock(&cld->cld_lock);
1776 config_log_put(cir); 1781 config_log_put(cir);
1777 } 1782 }
1783
1778 if (rc) 1784 if (rc)
1779 CERROR("Cannot process recover llog %d\n", rc); 1785 CERROR("Cannot process recover llog %d\n", rc);
1780 } 1786 }
@@ -1792,7 +1798,6 @@ static int mgc_process_config(struct obd_device *obd, u32 len, void *buf)
1792 "%s: can't process params llog: rc = %d\n", 1798 "%s: can't process params llog: rc = %d\n",
1793 obd->obd_name, rc); 1799 obd->obd_name, rc);
1794 } 1800 }
1795 config_log_put(cld);
1796 1801
1797 break; 1802 break;
1798 } 1803 }
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c
index 3f42457b0d7d..ee7d67761191 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_io.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c
@@ -1119,9 +1119,9 @@ int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor,
1119 LASSERT(atomic_read(&anchor->csi_sync_nr) == 0); 1119 LASSERT(atomic_read(&anchor->csi_sync_nr) == 0);
1120 1120
1121 /* wait until cl_sync_io_note() has done wakeup */ 1121 /* wait until cl_sync_io_note() has done wakeup */
1122 while (unlikely(atomic_read(&anchor->csi_barrier) != 0)) { 1122 while (unlikely(atomic_read(&anchor->csi_barrier) != 0))
1123 cpu_relax(); 1123 cpu_relax();
1124 } 1124
1125 1125
1126 return rc; 1126 return rc;
1127} 1127}
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
index f5d4e23c64b7..703cb67ce42e 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
@@ -54,6 +54,7 @@
54#include <linux/list.h> 54#include <linux/list.h>
55#include "../../include/linux/libcfs/libcfs_hash.h" /* for cfs_hash stuff */ 55#include "../../include/linux/libcfs/libcfs_hash.h" /* for cfs_hash stuff */
56#include "../include/cl_object.h" 56#include "../include/cl_object.h"
57#include "../include/lu_object.h"
57#include "cl_internal.h" 58#include "cl_internal.h"
58 59
59static struct kmem_cache *cl_env_kmem; 60static struct kmem_cache *cl_env_kmem;
@@ -61,8 +62,6 @@ static struct kmem_cache *cl_env_kmem;
61/** Lock class of cl_object_header::coh_attr_guard */ 62/** Lock class of cl_object_header::coh_attr_guard */
62static struct lock_class_key cl_attr_guard_class; 63static struct lock_class_key cl_attr_guard_class;
63 64
64extern __u32 lu_context_tags_default;
65extern __u32 lu_session_tags_default;
66/** 65/**
67 * Initialize cl_object_header. 66 * Initialize cl_object_header.
68 */ 67 */
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
index 7971562a3efd..abcf951208d2 100644
--- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
@@ -60,7 +60,7 @@ enum {
60 LU_CACHE_PERCENT_DEFAULT = 20 60 LU_CACHE_PERCENT_DEFAULT = 20
61}; 61};
62 62
63#define LU_CACHE_NR_MAX_ADJUST 128 63#define LU_CACHE_NR_MAX_ADJUST 512
64#define LU_CACHE_NR_UNLIMITED -1 64#define LU_CACHE_NR_UNLIMITED -1
65#define LU_CACHE_NR_DEFAULT LU_CACHE_NR_UNLIMITED 65#define LU_CACHE_NR_DEFAULT LU_CACHE_NR_UNLIMITED
66#define LU_CACHE_NR_LDISKFS_LIMIT LU_CACHE_NR_UNLIMITED 66#define LU_CACHE_NR_LDISKFS_LIMIT LU_CACHE_NR_UNLIMITED
@@ -151,7 +151,7 @@ void lu_object_put(const struct lu_env *env, struct lu_object *o)
151 LASSERT(list_empty(&top->loh_lru)); 151 LASSERT(list_empty(&top->loh_lru));
152 list_add_tail(&top->loh_lru, &bkt->lsb_lru); 152 list_add_tail(&top->loh_lru, &bkt->lsb_lru);
153 bkt->lsb_lru_len++; 153 bkt->lsb_lru_len++;
154 lprocfs_counter_incr(site->ls_stats, LU_SS_LRU_LEN); 154 percpu_counter_inc(&site->ls_lru_len_counter);
155 CDEBUG(D_INODE, "Add %p to site lru. hash: %p, bkt: %p, lru_len: %ld\n", 155 CDEBUG(D_INODE, "Add %p to site lru. hash: %p, bkt: %p, lru_len: %ld\n",
156 o, site->ls_obj_hash, bkt, bkt->lsb_lru_len); 156 o, site->ls_obj_hash, bkt, bkt->lsb_lru_len);
157 cfs_hash_bd_unlock(site->ls_obj_hash, &bd, 1); 157 cfs_hash_bd_unlock(site->ls_obj_hash, &bd, 1);
@@ -202,7 +202,7 @@ void lu_object_unhash(const struct lu_env *env, struct lu_object *o)
202 list_del_init(&top->loh_lru); 202 list_del_init(&top->loh_lru);
203 bkt = cfs_hash_bd_extra_get(obj_hash, &bd); 203 bkt = cfs_hash_bd_extra_get(obj_hash, &bd);
204 bkt->lsb_lru_len--; 204 bkt->lsb_lru_len--;
205 lprocfs_counter_decr(site->ls_stats, LU_SS_LRU_LEN); 205 percpu_counter_dec(&site->ls_lru_len_counter);
206 } 206 }
207 cfs_hash_bd_del_locked(obj_hash, &bd, &top->loh_hash); 207 cfs_hash_bd_del_locked(obj_hash, &bd, &top->loh_hash);
208 cfs_hash_bd_unlock(obj_hash, &bd, 1); 208 cfs_hash_bd_unlock(obj_hash, &bd, 1);
@@ -329,8 +329,11 @@ static void lu_object_free(const struct lu_env *env, struct lu_object *o)
329 329
330/** 330/**
331 * Free \a nr objects from the cold end of the site LRU list. 331 * Free \a nr objects from the cold end of the site LRU list.
332 * if canblock is false, then don't block awaiting for another
333 * instance of lu_site_purge() to complete
332 */ 334 */
333int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr) 335int lu_site_purge_objects(const struct lu_env *env, struct lu_site *s,
336 int nr, bool canblock)
334{ 337{
335 struct lu_object_header *h; 338 struct lu_object_header *h;
336 struct lu_object_header *temp; 339 struct lu_object_header *temp;
@@ -360,7 +363,11 @@ int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr)
360 * It doesn't make any sense to make purge threads parallel, that can 363 * It doesn't make any sense to make purge threads parallel, that can
361 * only bring troubles to us. See LU-5331. 364 * only bring troubles to us. See LU-5331.
362 */ 365 */
363 mutex_lock(&s->ls_purge_mutex); 366 if (canblock)
367 mutex_lock(&s->ls_purge_mutex);
368 else if (!mutex_trylock(&s->ls_purge_mutex))
369 goto out;
370
364 did_sth = 0; 371 did_sth = 0;
365 cfs_hash_for_each_bucket(s->ls_obj_hash, &bd, i) { 372 cfs_hash_for_each_bucket(s->ls_obj_hash, &bd, i) {
366 if (i < start) 373 if (i < start)
@@ -379,7 +386,7 @@ int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr)
379 &bd2, &h->loh_hash); 386 &bd2, &h->loh_hash);
380 list_move(&h->loh_lru, &dispose); 387 list_move(&h->loh_lru, &dispose);
381 bkt->lsb_lru_len--; 388 bkt->lsb_lru_len--;
382 lprocfs_counter_decr(s->ls_stats, LU_SS_LRU_LEN); 389 percpu_counter_dec(&s->ls_lru_len_counter);
383 if (did_sth == 0) 390 if (did_sth == 0)
384 did_sth = 1; 391 did_sth = 1;
385 392
@@ -414,10 +421,10 @@ int lu_site_purge(const struct lu_env *env, struct lu_site *s, int nr)
414 } 421 }
415 /* race on s->ls_purge_start, but nobody cares */ 422 /* race on s->ls_purge_start, but nobody cares */
416 s->ls_purge_start = i % CFS_HASH_NBKT(s->ls_obj_hash); 423 s->ls_purge_start = i % CFS_HASH_NBKT(s->ls_obj_hash);
417 424out:
418 return nr; 425 return nr;
419} 426}
420EXPORT_SYMBOL(lu_site_purge); 427EXPORT_SYMBOL(lu_site_purge_objects);
421 428
422/* 429/*
423 * Object printing. 430 * Object printing.
@@ -578,7 +585,7 @@ static struct lu_object *htable_lookup(struct lu_site *s,
578 if (!list_empty(&h->loh_lru)) { 585 if (!list_empty(&h->loh_lru)) {
579 list_del_init(&h->loh_lru); 586 list_del_init(&h->loh_lru);
580 bkt->lsb_lru_len--; 587 bkt->lsb_lru_len--;
581 lprocfs_counter_decr(s->ls_stats, LU_SS_LRU_LEN); 588 percpu_counter_dec(&s->ls_lru_len_counter);
582 } 589 }
583 return lu_object_top(h); 590 return lu_object_top(h);
584 } 591 }
@@ -625,9 +632,12 @@ static void lu_object_limit(const struct lu_env *env, struct lu_device *dev)
625 632
626 size = cfs_hash_size_get(dev->ld_site->ls_obj_hash); 633 size = cfs_hash_size_get(dev->ld_site->ls_obj_hash);
627 nr = (__u64)lu_cache_nr; 634 nr = (__u64)lu_cache_nr;
628 if (size > nr) 635 if (size <= nr)
629 lu_site_purge(env, dev->ld_site, 636 return;
630 min_t(__u64, size - nr, LU_CACHE_NR_MAX_ADJUST)); 637
638 lu_site_purge_objects(env, dev->ld_site,
639 min_t(__u64, size - nr, LU_CACHE_NR_MAX_ADJUST),
640 false);
631} 641}
632 642
633static struct lu_object *lu_object_new(const struct lu_env *env, 643static struct lu_object *lu_object_new(const struct lu_env *env,
@@ -820,7 +830,7 @@ EXPORT_SYMBOL(lu_device_type_fini);
820 * Global list of all sites on this node 830 * Global list of all sites on this node
821 */ 831 */
822static LIST_HEAD(lu_sites); 832static LIST_HEAD(lu_sites);
823static DEFINE_MUTEX(lu_sites_guard); 833static DECLARE_RWSEM(lu_sites_guard);
824 834
825/** 835/**
826 * Global environment used by site shrinker. 836 * Global environment used by site shrinker.
@@ -994,9 +1004,15 @@ int lu_site_init(struct lu_site *s, struct lu_device *top)
994 unsigned long bits; 1004 unsigned long bits;
995 unsigned long i; 1005 unsigned long i;
996 char name[16]; 1006 char name[16];
1007 int rc;
997 1008
998 memset(s, 0, sizeof(*s)); 1009 memset(s, 0, sizeof(*s));
999 mutex_init(&s->ls_purge_mutex); 1010 mutex_init(&s->ls_purge_mutex);
1011
1012 rc = percpu_counter_init(&s->ls_lru_len_counter, 0, GFP_NOFS);
1013 if (rc)
1014 return -ENOMEM;
1015
1000 snprintf(name, sizeof(name), "lu_site_%s", top->ld_type->ldt_name); 1016 snprintf(name, sizeof(name), "lu_site_%s", top->ld_type->ldt_name);
1001 for (bits = lu_htable_order(top); bits >= LU_SITE_BITS_MIN; bits--) { 1017 for (bits = lu_htable_order(top); bits >= LU_SITE_BITS_MIN; bits--) {
1002 s->ls_obj_hash = cfs_hash_create(name, bits, bits, 1018 s->ls_obj_hash = cfs_hash_create(name, bits, bits,
@@ -1042,12 +1058,6 @@ int lu_site_init(struct lu_site *s, struct lu_device *top)
1042 0, "cache_death_race", "cache_death_race"); 1058 0, "cache_death_race", "cache_death_race");
1043 lprocfs_counter_init(s->ls_stats, LU_SS_LRU_PURGED, 1059 lprocfs_counter_init(s->ls_stats, LU_SS_LRU_PURGED,
1044 0, "lru_purged", "lru_purged"); 1060 0, "lru_purged", "lru_purged");
1045 /*
1046 * Unlike other counters, lru_len can be decremented so
1047 * need lc_sum instead of just lc_count
1048 */
1049 lprocfs_counter_init(s->ls_stats, LU_SS_LRU_LEN,
1050 LPROCFS_CNTR_AVGMINMAX, "lru_len", "lru_len");
1051 1061
1052 INIT_LIST_HEAD(&s->ls_linkage); 1062 INIT_LIST_HEAD(&s->ls_linkage);
1053 s->ls_top_dev = top; 1063 s->ls_top_dev = top;
@@ -1069,9 +1079,11 @@ EXPORT_SYMBOL(lu_site_init);
1069 */ 1079 */
1070void lu_site_fini(struct lu_site *s) 1080void lu_site_fini(struct lu_site *s)
1071{ 1081{
1072 mutex_lock(&lu_sites_guard); 1082 down_write(&lu_sites_guard);
1073 list_del_init(&s->ls_linkage); 1083 list_del_init(&s->ls_linkage);
1074 mutex_unlock(&lu_sites_guard); 1084 up_write(&lu_sites_guard);
1085
1086 percpu_counter_destroy(&s->ls_lru_len_counter);
1075 1087
1076 if (s->ls_obj_hash) { 1088 if (s->ls_obj_hash) {
1077 cfs_hash_putref(s->ls_obj_hash); 1089 cfs_hash_putref(s->ls_obj_hash);
@@ -1097,11 +1109,11 @@ int lu_site_init_finish(struct lu_site *s)
1097{ 1109{
1098 int result; 1110 int result;
1099 1111
1100 mutex_lock(&lu_sites_guard); 1112 down_write(&lu_sites_guard);
1101 result = lu_context_refill(&lu_shrink_env.le_ctx); 1113 result = lu_context_refill(&lu_shrink_env.le_ctx);
1102 if (result == 0) 1114 if (result == 0)
1103 list_add(&s->ls_linkage, &lu_sites); 1115 list_add(&s->ls_linkage, &lu_sites);
1104 mutex_unlock(&lu_sites_guard); 1116 up_write(&lu_sites_guard);
1105 return result; 1117 return result;
1106} 1118}
1107EXPORT_SYMBOL(lu_site_init_finish); 1119EXPORT_SYMBOL(lu_site_init_finish);
@@ -1820,12 +1832,15 @@ static void lu_site_stats_get(struct cfs_hash *hs,
1820} 1832}
1821 1833
1822/* 1834/*
1823 * lu_cache_shrink_count returns the number of cached objects that are 1835 * lu_cache_shrink_count() returns an approximate number of cached objects
1824 * candidates to be freed by shrink_slab(). A counter, which tracks 1836 * that can be freed by shrink_slab(). A counter, which tracks the
1825 * the number of items in the site's lru, is maintained in the per cpu 1837 * number of items in the site's lru, is maintained in a percpu_counter
1826 * stats of each site. The counter is incremented when an object is added 1838 * for each site. The percpu values are incremented and decremented as
1827 * to a site's lru and decremented when one is removed. The number of 1839 * objects are added or removed from the lru. The percpu values are summed
1828 * free-able objects is the sum of all per cpu counters for all sites. 1840 * and saved whenever a percpu value exceeds a threshold. Thus the saved,
1841 * summed value at any given time may not accurately reflect the current
1842 * lru length. But this value is sufficiently accurate for the needs of
1843 * a shrinker.
1829 * 1844 *
1830 * Using a per cpu counter is a compromise solution to concurrent access: 1845 * Using a per cpu counter is a compromise solution to concurrent access:
1831 * lu_object_put() can update the counter without locking the site and 1846 * lu_object_put() can update the counter without locking the site and
@@ -1842,11 +1857,10 @@ static unsigned long lu_cache_shrink_count(struct shrinker *sk,
1842 if (!(sc->gfp_mask & __GFP_FS)) 1857 if (!(sc->gfp_mask & __GFP_FS))
1843 return 0; 1858 return 0;
1844 1859
1845 mutex_lock(&lu_sites_guard); 1860 down_read(&lu_sites_guard);
1846 list_for_each_entry_safe(s, tmp, &lu_sites, ls_linkage) { 1861 list_for_each_entry_safe(s, tmp, &lu_sites, ls_linkage)
1847 cached += ls_stats_read(s->ls_stats, LU_SS_LRU_LEN); 1862 cached += percpu_counter_read_positive(&s->ls_lru_len_counter);
1848 } 1863 up_read(&lu_sites_guard);
1849 mutex_unlock(&lu_sites_guard);
1850 1864
1851 cached = (cached / 100) * sysctl_vfs_cache_pressure; 1865 cached = (cached / 100) * sysctl_vfs_cache_pressure;
1852 CDEBUG(D_INODE, "%ld objects cached, cache pressure %d\n", 1866 CDEBUG(D_INODE, "%ld objects cached, cache pressure %d\n",
@@ -1877,7 +1891,7 @@ static unsigned long lu_cache_shrink_scan(struct shrinker *sk,
1877 */ 1891 */
1878 return SHRINK_STOP; 1892 return SHRINK_STOP;
1879 1893
1880 mutex_lock(&lu_sites_guard); 1894 down_write(&lu_sites_guard);
1881 list_for_each_entry_safe(s, tmp, &lu_sites, ls_linkage) { 1895 list_for_each_entry_safe(s, tmp, &lu_sites, ls_linkage) {
1882 freed = lu_site_purge(&lu_shrink_env, s, remain); 1896 freed = lu_site_purge(&lu_shrink_env, s, remain);
1883 remain -= freed; 1897 remain -= freed;
@@ -1888,7 +1902,7 @@ static unsigned long lu_cache_shrink_scan(struct shrinker *sk,
1888 list_move_tail(&s->ls_linkage, &splice); 1902 list_move_tail(&s->ls_linkage, &splice);
1889 } 1903 }
1890 list_splice(&splice, lu_sites.prev); 1904 list_splice(&splice, lu_sites.prev);
1891 mutex_unlock(&lu_sites_guard); 1905 up_write(&lu_sites_guard);
1892 1906
1893 return sc->nr_to_scan - remain; 1907 return sc->nr_to_scan - remain;
1894} 1908}
@@ -1925,9 +1939,9 @@ int lu_global_init(void)
1925 * conservatively. This should not be too bad, because this 1939 * conservatively. This should not be too bad, because this
1926 * environment is global. 1940 * environment is global.
1927 */ 1941 */
1928 mutex_lock(&lu_sites_guard); 1942 down_write(&lu_sites_guard);
1929 result = lu_env_init(&lu_shrink_env, LCT_SHRINKER); 1943 result = lu_env_init(&lu_shrink_env, LCT_SHRINKER);
1930 mutex_unlock(&lu_sites_guard); 1944 up_write(&lu_sites_guard);
1931 if (result != 0) 1945 if (result != 0)
1932 return result; 1946 return result;
1933 1947
@@ -1953,9 +1967,9 @@ void lu_global_fini(void)
1953 * Tear shrinker environment down _after_ de-registering 1967 * Tear shrinker environment down _after_ de-registering
1954 * lu_global_key, because the latter has a value in the former. 1968 * lu_global_key, because the latter has a value in the former.
1955 */ 1969 */
1956 mutex_lock(&lu_sites_guard); 1970 down_write(&lu_sites_guard);
1957 lu_env_fini(&lu_shrink_env); 1971 lu_env_fini(&lu_shrink_env);
1958 mutex_unlock(&lu_sites_guard); 1972 up_write(&lu_sites_guard);
1959 1973
1960 lu_ref_global_fini(); 1974 lu_ref_global_fini();
1961} 1975}
@@ -1965,13 +1979,6 @@ static __u32 ls_stats_read(struct lprocfs_stats *stats, int idx)
1965 struct lprocfs_counter ret; 1979 struct lprocfs_counter ret;
1966 1980
1967 lprocfs_stats_collect(stats, idx, &ret); 1981 lprocfs_stats_collect(stats, idx, &ret);
1968 if (idx == LU_SS_LRU_LEN)
1969 /*
1970 * protect against counter on cpu A being decremented
1971 * before counter is incremented on cpu B; unlikely
1972 */
1973 return (__u32)((ret.lc_sum > 0) ? ret.lc_sum : 0);
1974
1975 return (__u32)ret.lc_count; 1982 return (__u32)ret.lc_count;
1976} 1983}
1977 1984
@@ -1986,7 +1993,7 @@ int lu_site_stats_print(const struct lu_site *s, struct seq_file *m)
1986 memset(&stats, 0, sizeof(stats)); 1993 memset(&stats, 0, sizeof(stats));
1987 lu_site_stats_get(s->ls_obj_hash, &stats, 1); 1994 lu_site_stats_get(s->ls_obj_hash, &stats, 1);
1988 1995
1989 seq_printf(m, "%d/%d %d/%ld %d %d %d %d %d %d %d %d\n", 1996 seq_printf(m, "%d/%d %d/%ld %d %d %d %d %d %d %d\n",
1990 stats.lss_busy, 1997 stats.lss_busy,
1991 stats.lss_total, 1998 stats.lss_total,
1992 stats.lss_populated, 1999 stats.lss_populated,
@@ -1997,8 +2004,7 @@ int lu_site_stats_print(const struct lu_site *s, struct seq_file *m)
1997 ls_stats_read(s->ls_stats, LU_SS_CACHE_MISS), 2004 ls_stats_read(s->ls_stats, LU_SS_CACHE_MISS),
1998 ls_stats_read(s->ls_stats, LU_SS_CACHE_RACE), 2005 ls_stats_read(s->ls_stats, LU_SS_CACHE_RACE),
1999 ls_stats_read(s->ls_stats, LU_SS_CACHE_DEATH_RACE), 2006 ls_stats_read(s->ls_stats, LU_SS_CACHE_DEATH_RACE),
2000 ls_stats_read(s->ls_stats, LU_SS_LRU_PURGED), 2007 ls_stats_read(s->ls_stats, LU_SS_LRU_PURGED));
2001 ls_stats_read(s->ls_stats, LU_SS_LRU_LEN));
2002 return 0; 2008 return 0;
2003} 2009}
2004EXPORT_SYMBOL(lu_site_stats_print); 2010EXPORT_SYMBOL(lu_site_stats_print);
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index 2283e920d839..8e0d4b1d86dc 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -877,7 +877,7 @@ static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr)
877 */ 877 */
878static int lmd_parse(char *options, struct lustre_mount_data *lmd) 878static int lmd_parse(char *options, struct lustre_mount_data *lmd)
879{ 879{
880 char *s1, *s2, *s3, *devname = NULL; 880 char *s1, *s2, *devname = NULL;
881 struct lustre_mount_data *raw = (struct lustre_mount_data *)options; 881 struct lustre_mount_data *raw = (struct lustre_mount_data *)options;
882 int rc = 0; 882 int rc = 0;
883 883
@@ -906,6 +906,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
906 while (*s1) { 906 while (*s1) {
907 int clear = 0; 907 int clear = 0;
908 int time_min = OBD_RECOVERY_TIME_MIN; 908 int time_min = OBD_RECOVERY_TIME_MIN;
909 char *s3;
909 910
910 /* Skip whitespace and extra commas */ 911 /* Skip whitespace and extra commas */
911 while (*s1 == ' ' || *s1 == ',') 912 while (*s1 == ' ' || *s1 == ',')
diff --git a/drivers/staging/lustre/lustre/obdclass/obdo.c b/drivers/staging/lustre/lustre/obdclass/obdo.c
index c52b9e07d7dd..b1dfa1622ae7 100644
--- a/drivers/staging/lustre/lustre/obdclass/obdo.c
+++ b/drivers/staging/lustre/lustre/obdclass/obdo.c
@@ -40,6 +40,7 @@
40 40
41#include "../include/obd_class.h" 41#include "../include/obd_class.h"
42#include "../include/lustre/lustre_idl.h" 42#include "../include/lustre/lustre_idl.h"
43#include "../include/lustre_obdo.h"
43 44
44void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent) 45void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent)
45{ 46{
@@ -124,3 +125,56 @@ void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj)
124 ioobj->ioo_max_brw = 0; 125 ioobj->ioo_max_brw = 0;
125} 126}
126EXPORT_SYMBOL(obdo_to_ioobj); 127EXPORT_SYMBOL(obdo_to_ioobj);
128
129/**
130 * Create an obdo to send over the wire
131 */
132void lustre_set_wire_obdo(const struct obd_connect_data *ocd,
133 struct obdo *wobdo, const struct obdo *lobdo)
134{
135 *wobdo = *lobdo;
136 wobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
137 if (!ocd)
138 return;
139
140 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
141 fid_seq_is_echo(ostid_seq(&lobdo->o_oi))) {
142 /*
143 * Currently OBD_FL_OSTID will only be used when 2.4 echo
144 * client communicate with pre-2.4 server
145 */
146 wobdo->o_oi.oi.oi_id = fid_oid(&lobdo->o_oi.oi_fid);
147 wobdo->o_oi.oi.oi_seq = fid_seq(&lobdo->o_oi.oi_fid);
148 }
149}
150EXPORT_SYMBOL(lustre_set_wire_obdo);
151
152/**
153 * Create a local obdo from a wire based odbo
154 */
155void lustre_get_wire_obdo(const struct obd_connect_data *ocd,
156 struct obdo *lobdo, const struct obdo *wobdo)
157{
158 u32 local_flags = 0;
159
160 if (lobdo->o_valid & OBD_MD_FLFLAGS)
161 local_flags = lobdo->o_flags & OBD_FL_LOCAL_MASK;
162
163 *lobdo = *wobdo;
164 if (local_flags) {
165 lobdo->o_valid |= OBD_MD_FLFLAGS;
166 lobdo->o_flags &= ~OBD_FL_LOCAL_MASK;
167 lobdo->o_flags |= local_flags;
168 }
169 if (!ocd)
170 return;
171
172 if (unlikely(!(ocd->ocd_connect_flags & OBD_CONNECT_FID)) &&
173 fid_seq_is_echo(wobdo->o_oi.oi.oi_seq)) {
174 /* see above */
175 lobdo->o_oi.oi_fid.f_seq = wobdo->o_oi.oi.oi_seq;
176 lobdo->o_oi.oi_fid.f_oid = wobdo->o_oi.oi.oi_id;
177 lobdo->o_oi.oi_fid.f_ver = 0;
178 }
179}
180EXPORT_SYMBOL(lustre_get_wire_obdo);
diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c
index b0f030c6c9c9..0490478393df 100644
--- a/drivers/staging/lustre/lustre/osc/osc_cache.c
+++ b/drivers/staging/lustre/lustre/osc/osc_cache.c
@@ -142,10 +142,7 @@ static const char *oes_strings[] = {
142 142
143static inline struct osc_extent *rb_extent(struct rb_node *n) 143static inline struct osc_extent *rb_extent(struct rb_node *n)
144{ 144{
145 if (!n) 145 return rb_entry_safe(n, struct osc_extent, oe_node);
146 return NULL;
147
148 return container_of(n, struct osc_extent, oe_node);
149} 146}
150 147
151static inline struct osc_extent *next_extent(struct osc_extent *ext) 148static inline struct osc_extent *next_extent(struct osc_extent *ext)
@@ -247,7 +244,7 @@ static int osc_extent_sanity_check0(struct osc_extent *ext,
247 goto out; 244 goto out;
248 } 245 }
249 246
250 if (ext->oe_dlmlock) { 247 if (ext->oe_dlmlock && !ldlm_is_failed(ext->oe_dlmlock)) {
251 struct ldlm_extent *extent; 248 struct ldlm_extent *extent;
252 249
253 extent = &ext->oe_dlmlock->l_policy_data.l_extent; 250 extent = &ext->oe_dlmlock->l_policy_data.l_extent;
@@ -1004,6 +1001,7 @@ static int osc_extent_truncate(struct osc_extent *ext, pgoff_t trunc_index,
1004 env = cl_env_get(&refcheck); 1001 env = cl_env_get(&refcheck);
1005 io = &osc_env_info(env)->oti_io; 1002 io = &osc_env_info(env)->oti_io;
1006 io->ci_obj = cl_object_top(osc2cl(obj)); 1003 io->ci_obj = cl_object_top(osc2cl(obj));
1004 io->ci_ignore_layout = 1;
1007 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj); 1005 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj);
1008 if (rc < 0) 1006 if (rc < 0)
1009 goto out; 1007 goto out;
@@ -1884,16 +1882,32 @@ static void osc_ap_completion(const struct lu_env *env, struct client_obd *cli,
1884 oap, osc, rc); 1882 oap, osc, rc);
1885} 1883}
1886 1884
1885struct extent_rpc_data {
1886 struct list_head *erd_rpc_list;
1887 unsigned int erd_page_count;
1888 unsigned int erd_max_pages;
1889 unsigned int erd_max_chunks;
1890};
1891
1892static inline unsigned osc_extent_chunks(const struct osc_extent *ext)
1893{
1894 struct client_obd *cli = osc_cli(ext->oe_obj);
1895 unsigned ppc_bits = cli->cl_chunkbits - PAGE_SHIFT;
1896
1897 return (ext->oe_end >> ppc_bits) - (ext->oe_start >> ppc_bits) + 1;
1898}
1899
1887/** 1900/**
1888 * Try to add extent to one RPC. We need to think about the following things: 1901 * Try to add extent to one RPC. We need to think about the following things:
1889 * - # of pages must not be over max_pages_per_rpc 1902 * - # of pages must not be over max_pages_per_rpc
1890 * - extent must be compatible with previous ones 1903 * - extent must be compatible with previous ones
1891 */ 1904 */
1892static int try_to_add_extent_for_io(struct client_obd *cli, 1905static int try_to_add_extent_for_io(struct client_obd *cli,
1893 struct osc_extent *ext, struct list_head *rpclist, 1906 struct osc_extent *ext,
1894 unsigned int *pc, unsigned int *max_pages) 1907 struct extent_rpc_data *data)
1895{ 1908{
1896 struct osc_extent *tmp; 1909 struct osc_extent *tmp;
1910 unsigned int chunk_count;
1897 struct osc_async_page *oap = list_first_entry(&ext->oe_pages, 1911 struct osc_async_page *oap = list_first_entry(&ext->oe_pages,
1898 struct osc_async_page, 1912 struct osc_async_page,
1899 oap_pending_item); 1913 oap_pending_item);
@@ -1901,19 +1915,22 @@ static int try_to_add_extent_for_io(struct client_obd *cli,
1901 EASSERT((ext->oe_state == OES_CACHE || ext->oe_state == OES_LOCK_DONE), 1915 EASSERT((ext->oe_state == OES_CACHE || ext->oe_state == OES_LOCK_DONE),
1902 ext); 1916 ext);
1903 1917
1904 *max_pages = max(ext->oe_mppr, *max_pages); 1918 chunk_count = osc_extent_chunks(ext);
1905 if (*pc + ext->oe_nr_pages > *max_pages) 1919 if (chunk_count > data->erd_max_chunks)
1920 return 0;
1921
1922 data->erd_max_pages = max(ext->oe_mppr, data->erd_max_pages);
1923 if (data->erd_page_count + ext->oe_nr_pages > data->erd_max_pages)
1906 return 0; 1924 return 0;
1907 1925
1908 list_for_each_entry(tmp, rpclist, oe_link) { 1926 list_for_each_entry(tmp, data->erd_rpc_list, oe_link) {
1909 struct osc_async_page *oap2; 1927 struct osc_async_page *oap2;
1910 1928
1911 oap2 = list_first_entry(&tmp->oe_pages, struct osc_async_page, 1929 oap2 = list_first_entry(&tmp->oe_pages, struct osc_async_page,
1912 oap_pending_item); 1930 oap_pending_item);
1913 EASSERT(tmp->oe_owner == current, tmp); 1931 EASSERT(tmp->oe_owner == current, tmp);
1914 if (oap2cl_page(oap)->cp_type != oap2cl_page(oap2)->cp_type) { 1932 if (oap2cl_page(oap)->cp_type != oap2cl_page(oap2)->cp_type) {
1915 CDEBUG(D_CACHE, "Do not permit different type of IO" 1933 CDEBUG(D_CACHE, "Do not permit different type of IO in one RPC\n");
1916 " for a same RPC\n");
1917 return 0; 1934 return 0;
1918 } 1935 }
1919 1936
@@ -1926,12 +1943,41 @@ static int try_to_add_extent_for_io(struct client_obd *cli,
1926 break; 1943 break;
1927 } 1944 }
1928 1945
1929 *pc += ext->oe_nr_pages; 1946 data->erd_max_chunks -= chunk_count;
1930 list_move_tail(&ext->oe_link, rpclist); 1947 data->erd_page_count += ext->oe_nr_pages;
1948 list_move_tail(&ext->oe_link, data->erd_rpc_list);
1931 ext->oe_owner = current; 1949 ext->oe_owner = current;
1932 return 1; 1950 return 1;
1933} 1951}
1934 1952
1953static inline unsigned osc_max_write_chunks(const struct client_obd *cli)
1954{
1955 /*
1956 * LU-8135:
1957 *
1958 * The maximum size of a single transaction is about 64MB in ZFS.
1959 * #define DMU_MAX_ACCESS (64 * 1024 * 1024)
1960 *
1961 * Since ZFS is a copy-on-write file system, a single dirty page in
1962 * a chunk will result in the rewrite of the whole chunk, therefore
1963 * an RPC shouldn't be allowed to contain too many chunks otherwise
1964 * it will make transaction size much bigger than 64MB, especially
1965 * with big block size for ZFS.
1966 *
1967 * This piece of code is to make sure that OSC won't send write RPCs
1968 * with too many chunks. The maximum chunk size that an RPC can cover
1969 * is set to PTLRPC_MAX_BRW_SIZE, which is defined to 16MB. Ideally
1970 * OST should tell the client what the biggest transaction size is,
1971 * but it's good enough for now.
1972 *
1973 * This limitation doesn't apply to ldiskfs, which allows as many
1974 * chunks in one RPC as we want. However, it won't have any benefits
1975 * to have too many discontiguous pages in one RPC. Therefore, it
1976 * can only have 256 chunks at most in one RPC.
1977 */
1978 return min(PTLRPC_MAX_BRW_SIZE >> cli->cl_chunkbits, 256);
1979}
1980
1935/** 1981/**
1936 * In order to prevent multiple ptlrpcd from breaking contiguous extents, 1982 * In order to prevent multiple ptlrpcd from breaking contiguous extents,
1937 * get_write_extent() takes all appropriate extents in atomic. 1983 * get_write_extent() takes all appropriate extents in atomic.
@@ -1951,26 +1997,28 @@ static unsigned int get_write_extents(struct osc_object *obj,
1951 struct client_obd *cli = osc_cli(obj); 1997 struct client_obd *cli = osc_cli(obj);
1952 struct osc_extent *ext; 1998 struct osc_extent *ext;
1953 struct osc_extent *temp; 1999 struct osc_extent *temp;
1954 unsigned int page_count = 0; 2000 struct extent_rpc_data data = {
1955 unsigned int max_pages = cli->cl_max_pages_per_rpc; 2001 .erd_rpc_list = rpclist,
2002 .erd_page_count = 0,
2003 .erd_max_pages = cli->cl_max_pages_per_rpc,
2004 .erd_max_chunks = osc_max_write_chunks(cli),
2005 };
1956 2006
1957 LASSERT(osc_object_is_locked(obj)); 2007 LASSERT(osc_object_is_locked(obj));
1958 list_for_each_entry_safe(ext, temp, &obj->oo_hp_exts, oe_link) { 2008 list_for_each_entry_safe(ext, temp, &obj->oo_hp_exts, oe_link) {
1959 LASSERT(ext->oe_state == OES_CACHE); 2009 LASSERT(ext->oe_state == OES_CACHE);
1960 if (!try_to_add_extent_for_io(cli, ext, rpclist, &page_count, 2010 if (!try_to_add_extent_for_io(cli, ext, &data))
1961 &max_pages)) 2011 return data.erd_page_count;
1962 return page_count; 2012 EASSERT(ext->oe_nr_pages <= data.erd_max_pages, ext);
1963 EASSERT(ext->oe_nr_pages <= max_pages, ext);
1964 } 2013 }
1965 if (page_count == max_pages) 2014 if (data.erd_page_count == data.erd_max_pages)
1966 return page_count; 2015 return data.erd_page_count;
1967 2016
1968 while (!list_empty(&obj->oo_urgent_exts)) { 2017 while (!list_empty(&obj->oo_urgent_exts)) {
1969 ext = list_entry(obj->oo_urgent_exts.next, 2018 ext = list_entry(obj->oo_urgent_exts.next,
1970 struct osc_extent, oe_link); 2019 struct osc_extent, oe_link);
1971 if (!try_to_add_extent_for_io(cli, ext, rpclist, &page_count, 2020 if (!try_to_add_extent_for_io(cli, ext, &data))
1972 &max_pages)) 2021 return data.erd_page_count;
1973 return page_count;
1974 2022
1975 if (!ext->oe_intree) 2023 if (!ext->oe_intree)
1976 continue; 2024 continue;
@@ -1981,13 +2029,12 @@ static unsigned int get_write_extents(struct osc_object *obj,
1981 ext->oe_owner)) 2029 ext->oe_owner))
1982 continue; 2030 continue;
1983 2031
1984 if (!try_to_add_extent_for_io(cli, ext, rpclist, 2032 if (!try_to_add_extent_for_io(cli, ext, &data))
1985 &page_count, &max_pages)) 2033 return data.erd_page_count;
1986 return page_count;
1987 } 2034 }
1988 } 2035 }
1989 if (page_count == max_pages) 2036 if (data.erd_page_count == data.erd_max_pages)
1990 return page_count; 2037 return data.erd_page_count;
1991 2038
1992 ext = first_extent(obj); 2039 ext = first_extent(obj);
1993 while (ext) { 2040 while (ext) {
@@ -1998,13 +2045,12 @@ static unsigned int get_write_extents(struct osc_object *obj,
1998 continue; 2045 continue;
1999 } 2046 }
2000 2047
2001 if (!try_to_add_extent_for_io(cli, ext, rpclist, &page_count, 2048 if (!try_to_add_extent_for_io(cli, ext, &data))
2002 &max_pages)) 2049 return data.erd_page_count;
2003 return page_count;
2004 2050
2005 ext = next_extent(ext); 2051 ext = next_extent(ext);
2006 } 2052 }
2007 return page_count; 2053 return data.erd_page_count;
2008} 2054}
2009 2055
2010static int 2056static int
@@ -2089,27 +2135,29 @@ osc_send_read_rpc(const struct lu_env *env, struct client_obd *cli,
2089 struct osc_extent *ext; 2135 struct osc_extent *ext;
2090 struct osc_extent *next; 2136 struct osc_extent *next;
2091 LIST_HEAD(rpclist); 2137 LIST_HEAD(rpclist);
2092 unsigned int page_count = 0; 2138 struct extent_rpc_data data = {
2093 unsigned int max_pages = cli->cl_max_pages_per_rpc; 2139 .erd_rpc_list = &rpclist,
2140 .erd_page_count = 0,
2141 .erd_max_pages = cli->cl_max_pages_per_rpc,
2142 .erd_max_chunks = UINT_MAX,
2143 };
2094 int rc = 0; 2144 int rc = 0;
2095 2145
2096 LASSERT(osc_object_is_locked(osc)); 2146 LASSERT(osc_object_is_locked(osc));
2097 list_for_each_entry_safe(ext, next, &osc->oo_reading_exts, oe_link) { 2147 list_for_each_entry_safe(ext, next, &osc->oo_reading_exts, oe_link) {
2098 EASSERT(ext->oe_state == OES_LOCK_DONE, ext); 2148 EASSERT(ext->oe_state == OES_LOCK_DONE, ext);
2099 if (!try_to_add_extent_for_io(cli, ext, &rpclist, &page_count, 2149 if (!try_to_add_extent_for_io(cli, ext, &data))
2100 &max_pages))
2101 break; 2150 break;
2102 osc_extent_state_set(ext, OES_RPC); 2151 osc_extent_state_set(ext, OES_RPC);
2103 EASSERT(ext->oe_nr_pages <= max_pages, ext); 2152 EASSERT(ext->oe_nr_pages <= data.erd_max_pages, ext);
2104 } 2153 }
2105 LASSERT(page_count <= max_pages); 2154 LASSERT(data.erd_page_count <= data.erd_max_pages);
2106 2155
2107 osc_update_pending(osc, OBD_BRW_READ, -page_count); 2156 osc_update_pending(osc, OBD_BRW_READ, -data.erd_page_count);
2108 2157
2109 if (!list_empty(&rpclist)) { 2158 if (!list_empty(&rpclist)) {
2110 osc_object_unlock(osc); 2159 osc_object_unlock(osc);
2111 2160
2112 LASSERT(page_count > 0);
2113 rc = osc_build_rpc(env, cli, &rpclist, OBD_BRW_READ); 2161 rc = osc_build_rpc(env, cli, &rpclist, OBD_BRW_READ);
2114 LASSERT(list_empty(&rpclist)); 2162 LASSERT(list_empty(&rpclist));
2115 2163
@@ -2710,8 +2758,8 @@ int osc_queue_sync_pages(const struct lu_env *env, struct osc_object *obj,
2710/** 2758/**
2711 * Called by osc_io_setattr_start() to freeze and destroy covering extents. 2759 * Called by osc_io_setattr_start() to freeze and destroy covering extents.
2712 */ 2760 */
2713int osc_cache_truncate_start(const struct lu_env *env, struct osc_io *oio, 2761int osc_cache_truncate_start(const struct lu_env *env, struct osc_object *obj,
2714 struct osc_object *obj, __u64 size) 2762 u64 size, struct osc_extent **extp)
2715{ 2763{
2716 struct client_obd *cli = osc_cli(obj); 2764 struct client_obd *cli = osc_cli(obj);
2717 struct osc_extent *ext; 2765 struct osc_extent *ext;
@@ -2808,9 +2856,11 @@ again:
2808 /* we need to hold this extent in OES_TRUNC state so 2856 /* we need to hold this extent in OES_TRUNC state so
2809 * that no writeback will happen. This is to avoid 2857 * that no writeback will happen. This is to avoid
2810 * BUG 17397. 2858 * BUG 17397.
2859 * Only partial truncate can reach here, if @size is
2860 * not zero, the caller should provide a valid @extp.
2811 */ 2861 */
2812 LASSERT(!oio->oi_trunc); 2862 LASSERT(!*extp);
2813 oio->oi_trunc = osc_extent_get(ext); 2863 *extp = osc_extent_get(ext);
2814 OSC_EXTENT_DUMP(D_CACHE, ext, 2864 OSC_EXTENT_DUMP(D_CACHE, ext,
2815 "trunc at %llu\n", size); 2865 "trunc at %llu\n", size);
2816 } 2866 }
@@ -2836,13 +2886,10 @@ again:
2836/** 2886/**
2837 * Called after osc_io_setattr_end to add oio->oi_trunc back to cache. 2887 * Called after osc_io_setattr_end to add oio->oi_trunc back to cache.
2838 */ 2888 */
2839void osc_cache_truncate_end(const struct lu_env *env, struct osc_io *oio, 2889void osc_cache_truncate_end(const struct lu_env *env, struct osc_extent *ext)
2840 struct osc_object *obj)
2841{ 2890{
2842 struct osc_extent *ext = oio->oi_trunc;
2843
2844 oio->oi_trunc = NULL;
2845 if (ext) { 2891 if (ext) {
2892 struct osc_object *obj = ext->oe_obj;
2846 bool unplug = false; 2893 bool unplug = false;
2847 2894
2848 EASSERT(ext->oe_nr_pages > 0, ext); 2895 EASSERT(ext->oe_nr_pages > 0, ext);
@@ -3183,8 +3230,10 @@ static int discard_cb(const struct lu_env *env, struct cl_io *io,
3183 /* page is top page. */ 3230 /* page is top page. */
3184 info->oti_next_index = osc_index(ops) + 1; 3231 info->oti_next_index = osc_index(ops) + 1;
3185 if (cl_page_own(env, io, page) == 0) { 3232 if (cl_page_own(env, io, page) == 0) {
3186 KLASSERT(ergo(page->cp_type == CPT_CACHEABLE, 3233 if (page->cp_type == CPT_CACHEABLE &&
3187 !PageDirty(cl_page_vmpage(page)))); 3234 PageDirty(cl_page_vmpage(page)))
3235 CL_PAGE_DEBUG(D_ERROR, env, page,
3236 "discard dirty page?\n");
3188 3237
3189 /* discard the page */ 3238 /* discard the page */
3190 cl_page_discard(env, io, page); 3239 cl_page_discard(env, io, page);
diff --git a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
index cce55a9689f0..c09ab97d64ae 100644
--- a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
+++ b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
@@ -159,6 +159,10 @@ struct osc_object {
159 /* Protect osc_lock this osc_object has */ 159 /* Protect osc_lock this osc_object has */
160 spinlock_t oo_ol_spin; 160 spinlock_t oo_ol_spin;
161 struct list_head oo_ol_list; 161 struct list_head oo_ol_list;
162
163 /** number of active IOs of this object */
164 atomic_t oo_nr_ios;
165 wait_queue_head_t oo_io_waitq;
162}; 166};
163 167
164static inline void osc_object_lock(struct osc_object *obj) 168static inline void osc_object_lock(struct osc_object *obj)
@@ -399,10 +403,9 @@ int osc_flush_async_page(const struct lu_env *env, struct cl_io *io,
399 struct osc_page *ops); 403 struct osc_page *ops);
400int osc_queue_sync_pages(const struct lu_env *env, struct osc_object *obj, 404int osc_queue_sync_pages(const struct lu_env *env, struct osc_object *obj,
401 struct list_head *list, int cmd, int brw_flags); 405 struct list_head *list, int cmd, int brw_flags);
402int osc_cache_truncate_start(const struct lu_env *env, struct osc_io *oio, 406int osc_cache_truncate_start(const struct lu_env *env, struct osc_object *obj,
403 struct osc_object *obj, __u64 size); 407 u64 size, struct osc_extent **extp);
404void osc_cache_truncate_end(const struct lu_env *env, struct osc_io *oio, 408void osc_cache_truncate_end(const struct lu_env *env, struct osc_extent *ext);
405 struct osc_object *obj);
406int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj, 409int osc_cache_writeback_range(const struct lu_env *env, struct osc_object *obj,
407 pgoff_t start, pgoff_t end, int hp, int discard); 410 pgoff_t start, pgoff_t end, int hp, int discard);
408int osc_cache_wait_range(const struct lu_env *env, struct osc_object *obj, 411int osc_cache_wait_range(const struct lu_env *env, struct osc_object *obj,
diff --git a/drivers/staging/lustre/lustre/osc/osc_internal.h b/drivers/staging/lustre/lustre/osc/osc_internal.h
index 688783dcc1e4..8abd83f26716 100644
--- a/drivers/staging/lustre/lustre/osc/osc_internal.h
+++ b/drivers/staging/lustre/lustre/osc/osc_internal.h
@@ -114,9 +114,9 @@ int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
114 struct ptlrpc_request_set *rqset, int async, int agl); 114 struct ptlrpc_request_set *rqset, int async, int agl);
115 115
116int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id, 116int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id,
117 __u32 type, union ldlm_policy_data *policy, __u32 mode, 117 enum ldlm_type type, union ldlm_policy_data *policy,
118 __u64 *flags, void *data, struct lustre_handle *lockh, 118 enum ldlm_mode mode, __u64 *flags, void *data,
119 int unref); 119 struct lustre_handle *lockh, int unref);
120 120
121int osc_setattr_async(struct obd_export *exp, struct obdo *oa, 121int osc_setattr_async(struct obd_export *exp, struct obdo *oa,
122 obd_enqueue_update_f upcall, void *cookie, 122 obd_enqueue_update_f upcall, void *cookie,
@@ -181,6 +181,8 @@ static inline struct osc_device *obd2osc_dev(const struct obd_device *d)
181 return container_of0(d->obd_lu_dev, struct osc_device, od_cl.cd_lu_dev); 181 return container_of0(d->obd_lu_dev, struct osc_device, od_cl.cd_lu_dev);
182} 182}
183 183
184extern struct lu_kmem_descr osc_caches[];
185
184extern struct kmem_cache *osc_quota_kmem; 186extern struct kmem_cache *osc_quota_kmem;
185struct osc_quota_info { 187struct osc_quota_info {
186 /** linkage for quota hash table */ 188 /** linkage for quota hash table */
@@ -218,4 +220,15 @@ struct ldlm_lock *osc_dlmlock_at_pgoff(const struct lu_env *env,
218 struct osc_object *obj, pgoff_t index, 220 struct osc_object *obj, pgoff_t index,
219 enum osc_dap_flags flags); 221 enum osc_dap_flags flags);
220 222
223int osc_object_invalidate(const struct lu_env *env, struct osc_object *osc);
224
225/** osc shrink list to link all osc client obd */
226extern struct list_head osc_shrink_list;
227/** spin lock to protect osc_shrink_list */
228extern spinlock_t osc_shrink_lock;
229unsigned long osc_cache_shrink_count(struct shrinker *sk,
230 struct shrink_control *sc);
231unsigned long osc_cache_shrink_scan(struct shrinker *sk,
232 struct shrink_control *sc);
233
221#endif /* OSC_INTERNAL_H */ 234#endif /* OSC_INTERNAL_H */
diff --git a/drivers/staging/lustre/lustre/osc/osc_io.c b/drivers/staging/lustre/lustre/osc/osc_io.c
index 228a97c098fe..0b4cc4283b05 100644
--- a/drivers/staging/lustre/lustre/osc/osc_io.c
+++ b/drivers/staging/lustre/lustre/osc/osc_io.c
@@ -37,6 +37,8 @@
37 37
38#define DEBUG_SUBSYSTEM S_OSC 38#define DEBUG_SUBSYSTEM S_OSC
39 39
40#include "../include/lustre_obdo.h"
41
40#include "osc_cl_internal.h" 42#include "osc_cl_internal.h"
41 43
42/** \addtogroup osc 44/** \addtogroup osc
@@ -97,6 +99,7 @@ static int osc_io_read_ahead(const struct lu_env *env,
97 ldlm_lock_decref(&lockh, dlmlock->l_req_mode); 99 ldlm_lock_decref(&lockh, dlmlock->l_req_mode);
98 } 100 }
99 101
102 ra->cra_rpc_size = osc_cli(osc)->cl_max_pages_per_rpc;
100 ra->cra_end = cl_index(osc2cl(osc), 103 ra->cra_end = cl_index(osc2cl(osc),
101 dlmlock->l_policy_data.l_extent.end); 104 dlmlock->l_policy_data.l_extent.end);
102 ra->cra_release = osc_read_ahead_release; 105 ra->cra_release = osc_read_ahead_release;
@@ -136,7 +139,7 @@ static int osc_io_submit(const struct lu_env *env,
136 139
137 LASSERT(qin->pl_nr > 0); 140 LASSERT(qin->pl_nr > 0);
138 141
139 CDEBUG(D_CACHE, "%d %d\n", qin->pl_nr, crt); 142 CDEBUG(D_CACHE | D_READA, "%d %d\n", qin->pl_nr, crt);
140 143
141 osc = cl2osc(ios->cis_obj); 144 osc = cl2osc(ios->cis_obj);
142 cli = osc_cli(osc); 145 cli = osc_cli(osc);
@@ -207,6 +210,18 @@ static int osc_io_submit(const struct lu_env *env,
207 if (queued > 0) 210 if (queued > 0)
208 result = osc_queue_sync_pages(env, osc, &list, cmd, brw_flags); 211 result = osc_queue_sync_pages(env, osc, &list, cmd, brw_flags);
209 212
213 /* Update c/mtime for sync write. LU-7310 */
214 if (qout->pl_nr > 0 && !result) {
215 struct cl_attr *attr = &osc_env_info(env)->oti_attr;
216 struct cl_object *obj = ios->cis_obj;
217
218 cl_object_attr_lock(obj);
219 attr->cat_mtime = LTIME_S(CURRENT_TIME);
220 attr->cat_ctime = attr->cat_mtime;
221 cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
222 cl_object_attr_unlock(obj);
223 }
224
210 CDEBUG(D_INFO, "%d/%d %d\n", qin->pl_nr, qout->pl_nr, result); 225 CDEBUG(D_INFO, "%d/%d %d\n", qin->pl_nr, qout->pl_nr, result);
211 return qout->pl_nr > 0 ? 0 : result; 226 return qout->pl_nr > 0 ? 0 : result;
212} 227}
@@ -330,8 +345,25 @@ static int osc_io_commit_async(const struct lu_env *env,
330 return result; 345 return result;
331} 346}
332 347
333static int osc_io_rw_iter_init(const struct lu_env *env, 348static int osc_io_iter_init(const struct lu_env *env,
334 const struct cl_io_slice *ios) 349 const struct cl_io_slice *ios)
350{
351 struct osc_object *osc = cl2osc(ios->cis_obj);
352 struct obd_import *imp = osc_cli(osc)->cl_import;
353 int rc = -EIO;
354
355 spin_lock(&imp->imp_lock);
356 if (likely(!imp->imp_invalid)) {
357 atomic_inc(&osc->oo_nr_ios);
358 rc = 0;
359 }
360 spin_unlock(&imp->imp_lock);
361
362 return rc;
363}
364
365static int osc_io_write_iter_init(const struct lu_env *env,
366 const struct cl_io_slice *ios)
335{ 367{
336 struct cl_io *io = ios->cis_io; 368 struct cl_io *io = ios->cis_io;
337 struct osc_io *oio = osc_env_io(env); 369 struct osc_io *oio = osc_env_io(env);
@@ -342,7 +374,7 @@ static int osc_io_rw_iter_init(const struct lu_env *env,
342 unsigned long max_pages; 374 unsigned long max_pages;
343 375
344 if (cl_io_is_append(io)) 376 if (cl_io_is_append(io))
345 return 0; 377 return osc_io_iter_init(env, ios);
346 378
347 npages = io->u.ci_rw.crw_count >> PAGE_SHIFT; 379 npages = io->u.ci_rw.crw_count >> PAGE_SHIFT;
348 if (io->u.ci_rw.crw_pos & ~PAGE_MASK) 380 if (io->u.ci_rw.crw_pos & ~PAGE_MASK)
@@ -374,11 +406,21 @@ static int osc_io_rw_iter_init(const struct lu_env *env,
374 (void)ptlrpcd_queue_work(cli->cl_lru_work); 406 (void)ptlrpcd_queue_work(cli->cl_lru_work);
375 } 407 }
376 408
377 return 0; 409 return osc_io_iter_init(env, ios);
378} 410}
379 411
380static void osc_io_rw_iter_fini(const struct lu_env *env, 412static void osc_io_iter_fini(const struct lu_env *env,
381 const struct cl_io_slice *ios) 413 const struct cl_io_slice *ios)
414{
415 struct osc_object *osc = cl2osc(ios->cis_obj);
416
417 LASSERT(atomic_read(&osc->oo_nr_ios) > 0);
418 if (atomic_dec_and_test(&osc->oo_nr_ios))
419 wake_up_all(&osc->oo_io_waitq);
420}
421
422static void osc_io_write_iter_fini(const struct lu_env *env,
423 const struct cl_io_slice *ios)
382{ 424{
383 struct osc_io *oio = osc_env_io(env); 425 struct osc_io *oio = osc_env_io(env);
384 struct osc_object *osc = cl2osc(ios->cis_obj); 426 struct osc_object *osc = cl2osc(ios->cis_obj);
@@ -389,6 +431,8 @@ static void osc_io_rw_iter_fini(const struct lu_env *env,
389 oio->oi_lru_reserved = 0; 431 oio->oi_lru_reserved = 0;
390 } 432 }
391 oio->oi_write_osclock = NULL; 433 oio->oi_write_osclock = NULL;
434
435 osc_io_iter_fini(env, ios);
392} 436}
393 437
394static int osc_io_fault_start(const struct lu_env *env, 438static int osc_io_fault_start(const struct lu_env *env,
@@ -479,7 +523,8 @@ static int osc_io_setattr_start(const struct lu_env *env,
479 523
480 /* truncate cache dirty pages first */ 524 /* truncate cache dirty pages first */
481 if (cl_io_is_trunc(io)) 525 if (cl_io_is_trunc(io))
482 result = osc_cache_truncate_start(env, oio, cl2osc(obj), size); 526 result = osc_cache_truncate_start(env, cl2osc(obj), size,
527 &oio->oi_trunc);
483 528
484 if (result == 0 && oio->oi_lockless == 0) { 529 if (result == 0 && oio->oi_lockless == 0) {
485 cl_object_attr_lock(obj); 530 cl_object_attr_lock(obj);
@@ -589,10 +634,8 @@ static void osc_io_setattr_end(const struct lu_env *env,
589 __u64 size = io->u.ci_setattr.sa_attr.lvb_size; 634 __u64 size = io->u.ci_setattr.sa_attr.lvb_size;
590 635
591 osc_trunc_check(env, io, oio, size); 636 osc_trunc_check(env, io, oio, size);
592 if (oio->oi_trunc) { 637 osc_cache_truncate_end(env, oio->oi_trunc);
593 osc_cache_truncate_end(env, oio, cl2osc(obj)); 638 oio->oi_trunc = NULL;
594 oio->oi_trunc = NULL;
595 }
596 } 639 }
597} 640}
598 641
@@ -669,7 +712,7 @@ static int osc_io_data_version_start(const struct lu_env *env,
669 712
670 ptlrpc_request_set_replen(req); 713 ptlrpc_request_set_replen(req);
671 req->rq_interpret_reply = osc_data_version_interpret; 714 req->rq_interpret_reply = osc_data_version_interpret;
672 CLASSERT(sizeof(*dva) <= sizeof(req->rq_async_args)); 715 BUILD_BUG_ON(sizeof(*dva) > sizeof(req->rq_async_args));
673 dva = ptlrpc_req_async_args(req); 716 dva = ptlrpc_req_async_args(req);
674 dva->dva_oio = oio; 717 dva->dva_oio = oio;
675 718
@@ -832,17 +875,21 @@ static void osc_io_end(const struct lu_env *env,
832static const struct cl_io_operations osc_io_ops = { 875static const struct cl_io_operations osc_io_ops = {
833 .op = { 876 .op = {
834 [CIT_READ] = { 877 [CIT_READ] = {
878 .cio_iter_init = osc_io_iter_init,
879 .cio_iter_fini = osc_io_iter_fini,
835 .cio_start = osc_io_read_start, 880 .cio_start = osc_io_read_start,
836 .cio_fini = osc_io_fini 881 .cio_fini = osc_io_fini
837 }, 882 },
838 [CIT_WRITE] = { 883 [CIT_WRITE] = {
839 .cio_iter_init = osc_io_rw_iter_init, 884 .cio_iter_init = osc_io_write_iter_init,
840 .cio_iter_fini = osc_io_rw_iter_fini, 885 .cio_iter_fini = osc_io_write_iter_fini,
841 .cio_start = osc_io_write_start, 886 .cio_start = osc_io_write_start,
842 .cio_end = osc_io_end, 887 .cio_end = osc_io_end,
843 .cio_fini = osc_io_fini 888 .cio_fini = osc_io_fini
844 }, 889 },
845 [CIT_SETATTR] = { 890 [CIT_SETATTR] = {
891 .cio_iter_init = osc_io_iter_init,
892 .cio_iter_fini = osc_io_iter_fini,
846 .cio_start = osc_io_setattr_start, 893 .cio_start = osc_io_setattr_start,
847 .cio_end = osc_io_setattr_end 894 .cio_end = osc_io_setattr_end
848 }, 895 },
@@ -851,6 +898,8 @@ static const struct cl_io_operations osc_io_ops = {
851 .cio_end = osc_io_data_version_end, 898 .cio_end = osc_io_data_version_end,
852 }, 899 },
853 [CIT_FAULT] = { 900 [CIT_FAULT] = {
901 .cio_iter_init = osc_io_iter_init,
902 .cio_iter_fini = osc_io_iter_fini,
854 .cio_start = osc_io_fault_start, 903 .cio_start = osc_io_fault_start,
855 .cio_end = osc_io_end, 904 .cio_end = osc_io_end,
856 .cio_fini = osc_io_fini 905 .cio_fini = osc_io_fini
diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c
index e0c3324857dd..d3e5ca7db7b2 100644
--- a/drivers/staging/lustre/lustre/osc/osc_object.c
+++ b/drivers/staging/lustre/lustre/osc/osc_object.c
@@ -78,6 +78,9 @@ static int osc_object_init(const struct lu_env *env, struct lu_object *obj,
78 INIT_LIST_HEAD(&osc->oo_write_item); 78 INIT_LIST_HEAD(&osc->oo_write_item);
79 INIT_LIST_HEAD(&osc->oo_read_item); 79 INIT_LIST_HEAD(&osc->oo_read_item);
80 80
81 atomic_set(&osc->oo_nr_ios, 0);
82 init_waitqueue_head(&osc->oo_io_waitq);
83
81 osc->oo_root.rb_node = NULL; 84 osc->oo_root.rb_node = NULL;
82 INIT_LIST_HEAD(&osc->oo_hp_exts); 85 INIT_LIST_HEAD(&osc->oo_hp_exts);
83 INIT_LIST_HEAD(&osc->oo_urgent_exts); 86 INIT_LIST_HEAD(&osc->oo_urgent_exts);
@@ -112,6 +115,7 @@ static void osc_object_free(const struct lu_env *env, struct lu_object *obj)
112 LASSERT(atomic_read(&osc->oo_nr_reads) == 0); 115 LASSERT(atomic_read(&osc->oo_nr_reads) == 0);
113 LASSERT(atomic_read(&osc->oo_nr_writes) == 0); 116 LASSERT(atomic_read(&osc->oo_nr_writes) == 0);
114 LASSERT(list_empty(&osc->oo_ol_list)); 117 LASSERT(list_empty(&osc->oo_ol_list));
118 LASSERT(!atomic_read(&osc->oo_nr_ios));
115 119
116 lu_object_fini(obj); 120 lu_object_fini(obj);
117 kmem_cache_free(osc_object_kmem, osc); 121 kmem_cache_free(osc_object_kmem, osc);
@@ -444,4 +448,19 @@ struct lu_object *osc_object_alloc(const struct lu_env *env,
444 return obj; 448 return obj;
445} 449}
446 450
451int osc_object_invalidate(const struct lu_env *env, struct osc_object *osc)
452{
453 struct l_wait_info lwi = { 0 };
454
455 CDEBUG(D_INODE, "Invalidate osc object: %p, # of active IOs: %d\n",
456 osc, atomic_read(&osc->oo_nr_ios));
457
458 l_wait_event(osc->oo_io_waitq, !atomic_read(&osc->oo_nr_ios), &lwi);
459
460 /* Discard all pages of this object. */
461 osc_cache_truncate_start(env, osc, 0, NULL);
462
463 return 0;
464}
465
447/** @} osc */ 466/** @} osc */
diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c
index e356e4af08e1..ab9d0d7bb943 100644
--- a/drivers/staging/lustre/lustre/osc/osc_page.c
+++ b/drivers/staging/lustre/lustre/osc/osc_page.c
@@ -370,12 +370,17 @@ static int osc_cache_too_much(struct client_obd *cli)
370 return lru_shrink_min(cli); 370 return lru_shrink_min(cli);
371 } else { 371 } else {
372 time64_t duration = ktime_get_real_seconds(); 372 time64_t duration = ktime_get_real_seconds();
373 long timediff;
373 374
374 /* knock out pages by duration of no IO activity */ 375 /* knock out pages by duration of no IO activity */
375 duration -= cli->cl_lru_last_used; 376 duration -= cli->cl_lru_last_used;
376 duration >>= 6; /* approximately 1 minute */ 377 /*
377 if (duration > 0 && 378 * The difference shouldn't be more than 70 years
378 pages >= div64_s64((s64)budget, duration)) 379 * so we can safely case to a long. Round to
380 * approximately 1 minute.
381 */
382 timediff = (long)(duration >> 6);
383 if (timediff > 0 && pages >= budget / timediff)
379 return lru_shrink_min(cli); 384 return lru_shrink_min(cli);
380 } 385 }
381 return 0; 386 return 0;
@@ -943,4 +948,91 @@ bool osc_over_unstable_soft_limit(struct client_obd *cli)
943 cli->cl_max_rpcs_in_flight; 948 cli->cl_max_rpcs_in_flight;
944} 949}
945 950
951/**
952 * Return how many LRU pages in the cache of all OSC devices
953 *
954 * Return: return # of cached LRU pages times reclaimation tendency
955 * SHRINK_STOP if it cannot do any scanning in this time
956 */
957unsigned long osc_cache_shrink_count(struct shrinker *sk,
958 struct shrink_control *sc)
959{
960 struct client_obd *cli;
961 unsigned long cached = 0;
962
963 spin_lock(&osc_shrink_lock);
964 list_for_each_entry(cli, &osc_shrink_list, cl_shrink_list)
965 cached += atomic_long_read(&cli->cl_lru_in_list);
966 spin_unlock(&osc_shrink_lock);
967
968 return (cached * sysctl_vfs_cache_pressure) / 100;
969}
970
971/**
972 * Scan and try to reclaim sc->nr_to_scan cached LRU pages
973 *
974 * Return: number of cached LRU pages reclaimed
975 * SHRINK_STOP if it cannot do any scanning in this time
976 *
977 * Linux kernel will loop calling this shrinker scan routine with
978 * sc->nr_to_scan = SHRINK_BATCH(128 for now) until kernel got enough memory.
979 *
980 * If sc->nr_to_scan is 0, the VM is querying the cache size, we don't need
981 * to scan and try to reclaim LRU pages, just return 0 and
982 * osc_cache_shrink_count() will report the LRU page number.
983 */
984unsigned long osc_cache_shrink_scan(struct shrinker *sk,
985 struct shrink_control *sc)
986{
987 struct client_obd *stop_anchor = NULL;
988 struct client_obd *cli;
989 struct lu_env *env;
990 long shrank = 0;
991 int refcheck;
992 int rc;
993
994 if (!sc->nr_to_scan)
995 return 0;
996
997 if (!(sc->gfp_mask & __GFP_FS))
998 return SHRINK_STOP;
999
1000 env = cl_env_get(&refcheck);
1001 if (IS_ERR(env))
1002 return SHRINK_STOP;
1003
1004 spin_lock(&osc_shrink_lock);
1005 while (!list_empty(&osc_shrink_list)) {
1006 cli = list_entry(osc_shrink_list.next, struct client_obd,
1007 cl_shrink_list);
1008
1009 if (!stop_anchor)
1010 stop_anchor = cli;
1011 else if (cli == stop_anchor)
1012 break;
1013
1014 list_move_tail(&cli->cl_shrink_list, &osc_shrink_list);
1015 spin_unlock(&osc_shrink_lock);
1016
1017 /* shrink no more than max_pages_per_rpc for an OSC */
1018 rc = osc_lru_shrink(env, cli, (sc->nr_to_scan - shrank) >
1019 cli->cl_max_pages_per_rpc ?
1020 cli->cl_max_pages_per_rpc :
1021 sc->nr_to_scan - shrank, true);
1022 if (rc > 0)
1023 shrank += rc;
1024
1025 if (shrank >= sc->nr_to_scan)
1026 goto out;
1027
1028 spin_lock(&osc_shrink_lock);
1029 }
1030 spin_unlock(&osc_shrink_lock);
1031
1032out:
1033 cl_env_put(env, &refcheck);
1034
1035 return shrank;
1036}
1037
946/** @} osc */ 1038/** @} osc */
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 7143564ae7e7..c4cfe18c3294 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -43,6 +43,7 @@
43#include "../include/lprocfs_status.h" 43#include "../include/lprocfs_status.h"
44#include "../include/lustre/lustre_ioctl.h" 44#include "../include/lustre/lustre_ioctl.h"
45#include "../include/lustre_debug.h" 45#include "../include/lustre_debug.h"
46#include "../include/lustre_obdo.h"
46#include "../include/lustre_param.h" 47#include "../include/lustre_param.h"
47#include "../include/lustre_fid.h" 48#include "../include/lustre_fid.h"
48#include "../include/obd_class.h" 49#include "../include/obd_class.h"
@@ -250,7 +251,7 @@ int osc_setattr_async(struct obd_export *exp, struct obdo *oa,
250 req->rq_interpret_reply = 251 req->rq_interpret_reply =
251 (ptlrpc_interpterer_t)osc_setattr_interpret; 252 (ptlrpc_interpterer_t)osc_setattr_interpret;
252 253
253 CLASSERT(sizeof(*sa) <= sizeof(req->rq_async_args)); 254 BUILD_BUG_ON(sizeof(*sa) > sizeof(req->rq_async_args));
254 sa = ptlrpc_req_async_args(req); 255 sa = ptlrpc_req_async_args(req);
255 sa->sa_oa = oa; 256 sa->sa_oa = oa;
256 sa->sa_upcall = upcall; 257 sa->sa_upcall = upcall;
@@ -348,7 +349,7 @@ int osc_punch_base(struct obd_export *exp, struct obdo *oa,
348 ptlrpc_request_set_replen(req); 349 ptlrpc_request_set_replen(req);
349 350
350 req->rq_interpret_reply = (ptlrpc_interpterer_t)osc_setattr_interpret; 351 req->rq_interpret_reply = (ptlrpc_interpterer_t)osc_setattr_interpret;
351 CLASSERT(sizeof(*sa) <= sizeof(req->rq_async_args)); 352 BUILD_BUG_ON(sizeof(*sa) > sizeof(req->rq_async_args));
352 sa = ptlrpc_req_async_args(req); 353 sa = ptlrpc_req_async_args(req);
353 sa->sa_oa = oa; 354 sa->sa_oa = oa;
354 sa->sa_upcall = upcall; 355 sa->sa_upcall = upcall;
@@ -429,7 +430,7 @@ int osc_sync_base(struct osc_object *obj, struct obdo *oa,
429 ptlrpc_request_set_replen(req); 430 ptlrpc_request_set_replen(req);
430 req->rq_interpret_reply = osc_sync_interpret; 431 req->rq_interpret_reply = osc_sync_interpret;
431 432
432 CLASSERT(sizeof(*fa) <= sizeof(req->rq_async_args)); 433 BUILD_BUG_ON(sizeof(*fa) > sizeof(req->rq_async_args));
433 fa = ptlrpc_req_async_args(req); 434 fa = ptlrpc_req_async_args(req);
434 fa->fa_obj = obj; 435 fa->fa_obj = obj;
435 fa->fa_oa = oa; 436 fa->fa_oa = oa;
@@ -1170,7 +1171,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
1170 } 1171 }
1171 ptlrpc_request_set_replen(req); 1172 ptlrpc_request_set_replen(req);
1172 1173
1173 CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); 1174 BUILD_BUG_ON(sizeof(*aa) > sizeof(req->rq_async_args));
1174 aa = ptlrpc_req_async_args(req); 1175 aa = ptlrpc_req_async_args(req);
1175 aa->aa_oa = oa; 1176 aa->aa_oa = oa;
1176 aa->aa_requested_nob = requested_nob; 1177 aa->aa_requested_nob = requested_nob;
@@ -1757,7 +1758,7 @@ int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
1757 cl_req_attr_set(env, osc2cl(obj), crattr); 1758 cl_req_attr_set(env, osc2cl(obj), crattr);
1758 lustre_msg_set_jobid(req->rq_reqmsg, crattr->cra_jobid); 1759 lustre_msg_set_jobid(req->rq_reqmsg, crattr->cra_jobid);
1759 1760
1760 CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); 1761 BUILD_BUG_ON(sizeof(*aa) > sizeof(req->rq_async_args));
1761 aa = ptlrpc_req_async_args(req); 1762 aa = ptlrpc_req_async_args(req);
1762 INIT_LIST_HEAD(&aa->aa_oaps); 1763 INIT_LIST_HEAD(&aa->aa_oaps);
1763 list_splice_init(&rpc_list, &aa->aa_oaps); 1764 list_splice_init(&rpc_list, &aa->aa_oaps);
@@ -2038,7 +2039,7 @@ no_match:
2038 if (!rc) { 2039 if (!rc) {
2039 struct osc_enqueue_args *aa; 2040 struct osc_enqueue_args *aa;
2040 2041
2041 CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); 2042 BUILD_BUG_ON(sizeof(*aa) > sizeof(req->rq_async_args));
2042 aa = ptlrpc_req_async_args(req); 2043 aa = ptlrpc_req_async_args(req);
2043 aa->oa_exp = exp; 2044 aa->oa_exp = exp;
2044 aa->oa_mode = einfo->ei_mode; 2045 aa->oa_mode = einfo->ei_mode;
@@ -2080,9 +2081,9 @@ no_match:
2080} 2081}
2081 2082
2082int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id, 2083int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id,
2083 __u32 type, union ldlm_policy_data *policy, __u32 mode, 2084 enum ldlm_type type, union ldlm_policy_data *policy,
2084 __u64 *flags, void *data, struct lustre_handle *lockh, 2085 enum ldlm_mode mode, __u64 *flags, void *data,
2085 int unref) 2086 struct lustre_handle *lockh, int unref)
2086{ 2087{
2087 struct obd_device *obd = exp->exp_obd; 2088 struct obd_device *obd = exp->exp_obd;
2088 __u64 lflags = *flags; 2089 __u64 lflags = *flags;
@@ -2195,7 +2196,7 @@ static int osc_statfs_async(struct obd_export *exp,
2195 } 2196 }
2196 2197
2197 req->rq_interpret_reply = (ptlrpc_interpterer_t)osc_statfs_interpret; 2198 req->rq_interpret_reply = (ptlrpc_interpterer_t)osc_statfs_interpret;
2198 CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); 2199 BUILD_BUG_ON(sizeof(*aa) > sizeof(req->rq_async_args));
2199 aa = ptlrpc_req_async_args(req); 2200 aa = ptlrpc_req_async_args(req);
2200 aa->aa_oi = oinfo; 2201 aa->aa_oi = oinfo;
2201 2202
@@ -2400,7 +2401,7 @@ static int osc_set_info_async(const struct lu_env *env, struct obd_export *exp,
2400 struct osc_brw_async_args *aa; 2401 struct osc_brw_async_args *aa;
2401 struct obdo *oa; 2402 struct obdo *oa;
2402 2403
2403 CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args)); 2404 BUILD_BUG_ON(sizeof(*aa) > sizeof(req->rq_async_args));
2404 aa = ptlrpc_req_async_args(req); 2405 aa = ptlrpc_req_async_args(req);
2405 oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS); 2406 oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS);
2406 if (!oa) { 2407 if (!oa) {
@@ -2479,6 +2480,33 @@ static int osc_disconnect(struct obd_export *exp)
2479 return rc; 2480 return rc;
2480} 2481}
2481 2482
2483static int osc_ldlm_resource_invalidate(struct cfs_hash *hs,
2484 struct cfs_hash_bd *bd,
2485 struct hlist_node *hnode, void *arg)
2486{
2487 struct ldlm_resource *res = cfs_hash_object(hs, hnode);
2488 struct osc_object *osc = NULL;
2489 struct lu_env *env = arg;
2490 struct ldlm_lock *lock;
2491
2492 lock_res(res);
2493 list_for_each_entry(lock, &res->lr_granted, l_res_link) {
2494 if (lock->l_ast_data && !osc) {
2495 osc = lock->l_ast_data;
2496 cl_object_get(osc2cl(osc));
2497 }
2498 lock->l_ast_data = NULL;
2499 }
2500 unlock_res(res);
2501
2502 if (osc) {
2503 osc_object_invalidate(env, osc);
2504 cl_object_put(env, osc2cl(osc));
2505 }
2506
2507 return 0;
2508}
2509
2482static int osc_import_event(struct obd_device *obd, 2510static int osc_import_event(struct obd_device *obd,
2483 struct obd_import *imp, 2511 struct obd_import *imp,
2484 enum obd_import_event event) 2512 enum obd_import_event event)
@@ -2506,17 +2534,18 @@ static int osc_import_event(struct obd_device *obd,
2506 struct lu_env *env; 2534 struct lu_env *env;
2507 int refcheck; 2535 int refcheck;
2508 2536
2537 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2538
2509 env = cl_env_get(&refcheck); 2539 env = cl_env_get(&refcheck);
2510 if (!IS_ERR(env)) { 2540 if (!IS_ERR(env)) {
2511 /* Reset grants */ 2541 osc_io_unplug(env, &obd->u.cli, NULL);
2512 cli = &obd->u.cli;
2513 /* all pages go to failing rpcs due to the invalid
2514 * import
2515 */
2516 osc_io_unplug(env, cli, NULL);
2517 2542
2518 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY); 2543 cfs_hash_for_each_nolock(ns->ns_rs_hash,
2544 osc_ldlm_resource_invalidate,
2545 env, 0);
2519 cl_env_put(env, &refcheck); 2546 cl_env_put(env, &refcheck);
2547
2548 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
2520 } else { 2549 } else {
2521 rc = PTR_ERR(env); 2550 rc = PTR_ERR(env);
2522 } 2551 }
@@ -2646,6 +2675,11 @@ int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
2646 2675
2647 INIT_LIST_HEAD(&cli->cl_grant_shrink_list); 2676 INIT_LIST_HEAD(&cli->cl_grant_shrink_list);
2648 ns_register_cancel(obd->obd_namespace, osc_cancel_weight); 2677 ns_register_cancel(obd->obd_namespace, osc_cancel_weight);
2678
2679 spin_lock(&osc_shrink_lock);
2680 list_add_tail(&cli->cl_shrink_list, &osc_shrink_list);
2681 spin_unlock(&osc_shrink_lock);
2682
2649 return rc; 2683 return rc;
2650 2684
2651out_ptlrpcd_work: 2685out_ptlrpcd_work:
@@ -2699,6 +2733,10 @@ static int osc_cleanup(struct obd_device *obd)
2699 struct client_obd *cli = &obd->u.cli; 2733 struct client_obd *cli = &obd->u.cli;
2700 int rc; 2734 int rc;
2701 2735
2736 spin_lock(&osc_shrink_lock);
2737 list_del(&cli->cl_shrink_list);
2738 spin_unlock(&osc_shrink_lock);
2739
2702 /* lru cleanup */ 2740 /* lru cleanup */
2703 if (cli->cl_cache) { 2741 if (cli->cl_cache) {
2704 LASSERT(atomic_read(&cli->cl_cache->ccc_users) > 0); 2742 LASSERT(atomic_read(&cli->cl_cache->ccc_users) > 0);
@@ -2766,7 +2804,14 @@ static struct obd_ops osc_obd_ops = {
2766 .quotactl = osc_quotactl, 2804 .quotactl = osc_quotactl,
2767}; 2805};
2768 2806
2769extern struct lu_kmem_descr osc_caches[]; 2807struct list_head osc_shrink_list = LIST_HEAD_INIT(osc_shrink_list);
2808DEFINE_SPINLOCK(osc_shrink_lock);
2809
2810static struct shrinker osc_cache_shrinker = {
2811 .count_objects = osc_cache_shrink_count,
2812 .scan_objects = osc_cache_shrink_scan,
2813 .seeks = DEFAULT_SEEKS,
2814};
2770 2815
2771static int __init osc_init(void) 2816static int __init osc_init(void)
2772{ 2817{
@@ -2792,6 +2837,8 @@ static int __init osc_init(void)
2792 if (rc) 2837 if (rc)
2793 goto out_kmem; 2838 goto out_kmem;
2794 2839
2840 register_shrinker(&osc_cache_shrinker);
2841
2795 /* This is obviously too much memory, only prevent overflow here */ 2842 /* This is obviously too much memory, only prevent overflow here */
2796 if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0) { 2843 if (osc_reqpool_mem_max >= 1 << 12 || osc_reqpool_mem_max == 0) {
2797 rc = -EINVAL; 2844 rc = -EINVAL;
@@ -2830,6 +2877,7 @@ out_kmem:
2830 2877
2831static void /*__exit*/ osc_exit(void) 2878static void /*__exit*/ osc_exit(void)
2832{ 2879{
2880 unregister_shrinker(&osc_cache_shrinker);
2833 class_unregister_type(LUSTRE_OSC_NAME); 2881 class_unregister_type(LUSTRE_OSC_NAME);
2834 lu_kmem_fini(osc_caches); 2882 lu_kmem_fini(osc_caches);
2835 ptlrpc_free_rq_pool(osc_rq_pool); 2883 ptlrpc_free_rq_pool(osc_rq_pool);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index 804741362bc0..04a98a08ece1 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -1160,7 +1160,7 @@ static int ptlrpc_import_delay_req(struct obd_import *imp,
1160 if (atomic_read(&imp->imp_inval_count) != 0) { 1160 if (atomic_read(&imp->imp_inval_count) != 0) {
1161 DEBUG_REQ(D_ERROR, req, "invalidate in flight"); 1161 DEBUG_REQ(D_ERROR, req, "invalidate in flight");
1162 *status = -EIO; 1162 *status = -EIO;
1163 } else if (imp->imp_dlm_fake || req->rq_no_delay) { 1163 } else if (req->rq_no_delay) {
1164 *status = -EWOULDBLOCK; 1164 *status = -EWOULDBLOCK;
1165 } else if (req->rq_allow_replay && 1165 } else if (req->rq_allow_replay &&
1166 (imp->imp_state == LUSTRE_IMP_REPLAY || 1166 (imp->imp_state == LUSTRE_IMP_REPLAY ||
@@ -2662,11 +2662,16 @@ free_req:
2662 list_for_each_entry_safe(req, saved, &imp->imp_committed_list, 2662 list_for_each_entry_safe(req, saved, &imp->imp_committed_list,
2663 rq_replay_list) { 2663 rq_replay_list) {
2664 LASSERT(req->rq_transno != 0); 2664 LASSERT(req->rq_transno != 0);
2665 if (req->rq_import_generation < imp->imp_generation) { 2665 if (req->rq_import_generation < imp->imp_generation ||
2666 DEBUG_REQ(D_RPCTRACE, req, "free stale open request"); 2666 !req->rq_replay) {
2667 ptlrpc_free_request(req); 2667 DEBUG_REQ(D_RPCTRACE, req, "free %s open request",
2668 } else if (!req->rq_replay) { 2668 req->rq_import_generation <
2669 DEBUG_REQ(D_RPCTRACE, req, "free closed open request"); 2669 imp->imp_generation ? "stale" : "closed");
2670
2671 if (imp->imp_replay_cursor == &req->rq_replay_list)
2672 imp->imp_replay_cursor =
2673 req->rq_replay_list.next;
2674
2670 ptlrpc_free_request(req); 2675 ptlrpc_free_request(req);
2671 } 2676 }
2672 } 2677 }
@@ -3070,7 +3075,7 @@ void ptlrpc_init_xid(void)
3070 } 3075 }
3071 3076
3072 /* Always need to be aligned to a power-of-two for multi-bulk BRW */ 3077 /* Always need to be aligned to a power-of-two for multi-bulk BRW */
3073 CLASSERT(((PTLRPC_BULK_OPS_COUNT - 1) & PTLRPC_BULK_OPS_COUNT) == 0); 3078 BUILD_BUG_ON(((PTLRPC_BULK_OPS_COUNT - 1) & PTLRPC_BULK_OPS_COUNT) != 0);
3074 ptlrpc_last_xid &= PTLRPC_BULK_OPS_MASK; 3079 ptlrpc_last_xid &= PTLRPC_BULK_OPS_MASK;
3075} 3080}
3076 3081
@@ -3123,8 +3128,11 @@ void ptlrpc_set_bulk_mbits(struct ptlrpc_request *req)
3123 req->rq_mbits = ptlrpc_next_xid(); 3128 req->rq_mbits = ptlrpc_next_xid();
3124 } else { 3129 } else {
3125 /* old version transfers rq_xid to peer as matchbits */ 3130 /* old version transfers rq_xid to peer as matchbits */
3126 req->rq_mbits = ptlrpc_next_xid(); 3131 spin_lock(&req->rq_import->imp_lock);
3127 req->rq_xid = req->rq_mbits; 3132 list_del_init(&req->rq_unreplied_list);
3133 ptlrpc_assign_next_xid_nolock(req);
3134 req->rq_mbits = req->rq_xid;
3135 spin_unlock(&req->rq_import->imp_lock);
3128 } 3136 }
3129 3137
3130 CDEBUG(D_HA, "resend bulk old x%llu new x%llu\n", 3138 CDEBUG(D_HA, "resend bulk old x%llu new x%llu\n",
@@ -3256,7 +3264,7 @@ void *ptlrpcd_alloc_work(struct obd_import *imp,
3256 req->rq_no_resend = 1; 3264 req->rq_no_resend = 1;
3257 req->rq_pill.rc_fmt = (void *)&worker_format; 3265 req->rq_pill.rc_fmt = (void *)&worker_format;
3258 3266
3259 CLASSERT(sizeof(*args) <= sizeof(req->rq_async_args)); 3267 BUILD_BUG_ON(sizeof(*args) > sizeof(req->rq_async_args));
3260 args = ptlrpc_req_async_args(req); 3268 args = ptlrpc_req_async_args(req);
3261 args->cb = cb; 3269 args->cb = cb;
3262 args->cbdata = cbdata; 3270 args->cbdata = cbdata;
diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
index 49f3e6368415..dc0fe9d660da 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/events.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
@@ -277,7 +277,7 @@ static void ptlrpc_req_add_history(struct ptlrpc_service_part *svcpt,
277 * then we hope there will be less RPCs per bucket at some 277 * then we hope there will be less RPCs per bucket at some
278 * point, and sequence will catch up again 278 * point, and sequence will catch up again
279 */ 279 */
280 svcpt->scp_hist_seq += (1U << REQS_SEQ_SHIFT(svcpt)); 280 svcpt->scp_hist_seq += (1ULL << REQS_SEQ_SHIFT(svcpt));
281 new_seq = svcpt->scp_hist_seq; 281 new_seq = svcpt->scp_hist_seq;
282 } 282 }
283 283
@@ -420,7 +420,8 @@ void reply_out_callback(lnet_event_t *ev)
420 rs->rs_on_net = 0; 420 rs->rs_on_net = 0;
421 if (!rs->rs_no_ack || 421 if (!rs->rs_no_ack ||
422 rs->rs_transno <= 422 rs->rs_transno <=
423 rs->rs_export->exp_obd->obd_last_committed) 423 rs->rs_export->exp_obd->obd_last_committed ||
424 list_empty(&rs->rs_obd_list))
424 ptlrpc_schedule_difficult_reply(rs); 425 ptlrpc_schedule_difficult_reply(rs);
425 426
426 spin_unlock(&rs->rs_lock); 427 spin_unlock(&rs->rs_lock);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c
index e8280194001c..93e172fe9ce4 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/import.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/import.c
@@ -703,7 +703,7 @@ int ptlrpc_connect_import(struct obd_import *imp)
703 ptlrpc_request_set_replen(request); 703 ptlrpc_request_set_replen(request);
704 request->rq_interpret_reply = ptlrpc_connect_interpret; 704 request->rq_interpret_reply = ptlrpc_connect_interpret;
705 705
706 CLASSERT(sizeof(*aa) <= sizeof(request->rq_async_args)); 706 BUILD_BUG_ON(sizeof(*aa) > sizeof(request->rq_async_args));
707 aa = ptlrpc_req_async_args(request); 707 aa = ptlrpc_req_async_args(request);
708 memset(aa, 0, sizeof(*aa)); 708 memset(aa, 0, sizeof(*aa));
709 709
diff --git a/drivers/staging/lustre/lustre/ptlrpc/layout.c b/drivers/staging/lustre/lustre/ptlrpc/layout.c
index 99d7c667df28..356d73511ea3 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/layout.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/layout.c
@@ -42,8 +42,6 @@
42 * of the format that the request conforms to. 42 * of the format that the request conforms to.
43 */ 43 */
44 44
45#if !defined(__REQ_LAYOUT_USER__)
46
47#define DEBUG_SUBSYSTEM S_RPC 45#define DEBUG_SUBSYSTEM S_RPC
48 46
49#include <linux/module.h> 47#include <linux/module.h>
@@ -57,8 +55,6 @@
57#include "../include/obd.h" 55#include "../include/obd.h"
58#include "../include/obd_support.h" 56#include "../include/obd_support.h"
59 57
60/* __REQ_LAYOUT_USER__ */
61#endif
62/* struct ptlrpc_request, lustre_msg* */ 58/* struct ptlrpc_request, lustre_msg* */
63#include "../include/lustre_req_layout.h" 59#include "../include/lustre_req_layout.h"
64#include "../include/lustre_acl.h" 60#include "../include/lustre_acl.h"
@@ -1181,6 +1177,23 @@ struct req_format RQF_FLD_QUERY =
1181 DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server); 1177 DEFINE_REQ_FMT0("FLD_QUERY", fld_query_client, fld_query_server);
1182EXPORT_SYMBOL(RQF_FLD_QUERY); 1178EXPORT_SYMBOL(RQF_FLD_QUERY);
1183 1179
1180/*
1181 * The 'fld_read_server' uses 'RMF_GENERIC_DATA' to hold the 'FLD_QUERY'
1182 * RPC reply that is composed of 'struct lu_seq_range_array'. But there
1183 * is not registered swabber function for 'RMF_GENERIC_DATA'. So the RPC
1184 * peers need to handle the RPC reply with fixed little-endian format.
1185 *
1186 * In theory, we can define new structure with some swabber registered to
1187 * handle the 'FLD_QUERY' RPC reply result automatically. But from the
1188 * implementation view, it is not easy to be done within current "struct
1189 * req_msg_field" framework. Because the sequence range array in the RPC
1190 * reply is not fixed length, instead, its length depends on 'lu_seq_range'
1191 * count, that is unknown when prepare the RPC buffer. Generally, for such
1192 * flexible length RPC usage, there will be a field in the RPC layout to
1193 * indicate the data length. But for the 'FLD_READ' RPC, we have no way to
1194 * do that unless we add new length filed that will broken the on-wire RPC
1195 * protocol and cause interoperability trouble with old peer.
1196 */
1184struct req_format RQF_FLD_READ = 1197struct req_format RQF_FLD_READ =
1185 DEFINE_REQ_FMT0("FLD_READ", fld_read_client, fld_read_server); 1198 DEFINE_REQ_FMT0("FLD_READ", fld_read_client, fld_read_server);
1186EXPORT_SYMBOL(RQF_FLD_READ); 1199EXPORT_SYMBOL(RQF_FLD_READ);
@@ -1541,8 +1554,6 @@ struct req_format RQF_OST_GET_INFO_FIEMAP =
1541 ost_get_fiemap_server); 1554 ost_get_fiemap_server);
1542EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP); 1555EXPORT_SYMBOL(RQF_OST_GET_INFO_FIEMAP);
1543 1556
1544#if !defined(__REQ_LAYOUT_USER__)
1545
1546/* Convenience macro */ 1557/* Convenience macro */
1547#define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)] 1558#define FMT_FIELD(fmt, i, j) (fmt)->rf_fields[(i)].d[(j)]
1548 1559
@@ -2221,6 +2232,3 @@ void req_capsule_shrink(struct req_capsule *pill,
2221 1); 2232 1);
2222} 2233}
2223EXPORT_SYMBOL(req_capsule_shrink); 2234EXPORT_SYMBOL(req_capsule_shrink);
2224
2225/* __REQ_LAYOUT_USER__ */
2226#endif
diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
index da1209e40f03..b8701841ab4a 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
@@ -522,13 +522,14 @@ int ptl_send_rpc(struct ptlrpc_request *request, int noreply)
522 */ 522 */
523 spin_lock(&imp->imp_lock); 523 spin_lock(&imp->imp_lock);
524 ptlrpc_assign_next_xid_nolock(request); 524 ptlrpc_assign_next_xid_nolock(request);
525 request->rq_mbits = request->rq_xid;
526 min_xid = ptlrpc_known_replied_xid(imp); 525 min_xid = ptlrpc_known_replied_xid(imp);
527 spin_unlock(&imp->imp_lock); 526 spin_unlock(&imp->imp_lock);
528 527
529 lustre_msg_set_last_xid(request->rq_reqmsg, min_xid); 528 lustre_msg_set_last_xid(request->rq_reqmsg, min_xid);
530 DEBUG_REQ(D_RPCTRACE, request, "Allocating new xid for resend on EINPROGRESS"); 529 DEBUG_REQ(D_RPCTRACE, request, "Allocating new xid for resend on EINPROGRESS");
531 } else if (request->rq_bulk) { 530 }
531
532 if (request->rq_bulk) {
532 ptlrpc_set_bulk_mbits(request); 533 ptlrpc_set_bulk_mbits(request);
533 lustre_msg_set_mbits(request->rq_reqmsg, request->rq_mbits); 534 lustre_msg_set_mbits(request->rq_reqmsg, request->rq_mbits);
534 } 535 }
diff --git a/drivers/staging/lustre/lustre/ptlrpc/nrs.c b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
index 7b6ffb195834..ef19dbe2ea5c 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
@@ -1559,9 +1559,6 @@ out:
1559 return rc; 1559 return rc;
1560} 1560}
1561 1561
1562/* ptlrpc/nrs_fifo.c */
1563extern struct ptlrpc_nrs_pol_conf nrs_conf_fifo;
1564
1565/** 1562/**
1566 * Adds all policies that ship with the ptlrpc module, to NRS core's list of 1563 * Adds all policies that ship with the ptlrpc module, to NRS core's list of
1567 * policies \e nrs_core.nrs_policies. 1564 * policies \e nrs_core.nrs_policies.
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
index 13f00b7cbbe5..9456a1825918 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
@@ -469,6 +469,7 @@ int lustre_shrink_msg(struct lustre_msg *msg, int segment,
469 default: 469 default:
470 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic); 470 LASSERTF(0, "incorrect message magic: %08x\n", msg->lm_magic);
471 } 471 }
472 return 0;
472} 473}
473EXPORT_SYMBOL(lustre_shrink_msg); 474EXPORT_SYMBOL(lustre_shrink_msg);
474 475
@@ -509,8 +510,8 @@ static int lustre_unpack_msg_v2(struct lustre_msg_v2 *m, int len)
509 __swab32s(&m->lm_repsize); 510 __swab32s(&m->lm_repsize);
510 __swab32s(&m->lm_cksum); 511 __swab32s(&m->lm_cksum);
511 __swab32s(&m->lm_flags); 512 __swab32s(&m->lm_flags);
512 CLASSERT(offsetof(typeof(*m), lm_padding_2) != 0); 513 BUILD_BUG_ON(offsetof(typeof(*m), lm_padding_2) == 0);
513 CLASSERT(offsetof(typeof(*m), lm_padding_3) != 0); 514 BUILD_BUG_ON(offsetof(typeof(*m), lm_padding_3) == 0);
514 } 515 }
515 516
516 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount); 517 required_len = lustre_msg_hdr_size_v2(m->lm_bufcount);
@@ -1525,18 +1526,18 @@ void lustre_swab_ptlrpc_body(struct ptlrpc_body *b)
1525 __swab64s(&b->pb_pre_versions[2]); 1526 __swab64s(&b->pb_pre_versions[2]);
1526 __swab64s(&b->pb_pre_versions[3]); 1527 __swab64s(&b->pb_pre_versions[3]);
1527 __swab64s(&b->pb_mbits); 1528 __swab64s(&b->pb_mbits);
1528 CLASSERT(offsetof(typeof(*b), pb_padding0) != 0); 1529 BUILD_BUG_ON(offsetof(typeof(*b), pb_padding0) == 0);
1529 CLASSERT(offsetof(typeof(*b), pb_padding1) != 0); 1530 BUILD_BUG_ON(offsetof(typeof(*b), pb_padding1) == 0);
1530 CLASSERT(offsetof(typeof(*b), pb_padding64_0) != 0); 1531 BUILD_BUG_ON(offsetof(typeof(*b), pb_padding64_0) == 0);
1531 CLASSERT(offsetof(typeof(*b), pb_padding64_1) != 0); 1532 BUILD_BUG_ON(offsetof(typeof(*b), pb_padding64_1) == 0);
1532 CLASSERT(offsetof(typeof(*b), pb_padding64_2) != 0); 1533 BUILD_BUG_ON(offsetof(typeof(*b), pb_padding64_2) == 0);
1533 /* While we need to maintain compatibility between 1534 /* While we need to maintain compatibility between
1534 * clients and servers without ptlrpc_body_v2 (< 2.3) 1535 * clients and servers without ptlrpc_body_v2 (< 2.3)
1535 * do not swab any fields beyond pb_jobid, as we are 1536 * do not swab any fields beyond pb_jobid, as we are
1536 * using this swab function for both ptlrpc_body 1537 * using this swab function for both ptlrpc_body
1537 * and ptlrpc_body_v2. 1538 * and ptlrpc_body_v2.
1538 */ 1539 */
1539 CLASSERT(offsetof(typeof(*b), pb_jobid) != 0); 1540 BUILD_BUG_ON(offsetof(typeof(*b), pb_jobid) == 0);
1540} 1541}
1541 1542
1542void lustre_swab_connect(struct obd_connect_data *ocd) 1543void lustre_swab_connect(struct obd_connect_data *ocd)
@@ -1567,23 +1568,23 @@ void lustre_swab_connect(struct obd_connect_data *ocd)
1567 __swab64s(&ocd->ocd_maxbytes); 1568 __swab64s(&ocd->ocd_maxbytes);
1568 if (ocd->ocd_connect_flags & OBD_CONNECT_MULTIMODRPCS) 1569 if (ocd->ocd_connect_flags & OBD_CONNECT_MULTIMODRPCS)
1569 __swab16s(&ocd->ocd_maxmodrpcs); 1570 __swab16s(&ocd->ocd_maxmodrpcs);
1570 CLASSERT(offsetof(typeof(*ocd), padding0)); 1571 BUILD_BUG_ON(!offsetof(typeof(*ocd), padding0));
1571 CLASSERT(offsetof(typeof(*ocd), padding1) != 0); 1572 BUILD_BUG_ON(offsetof(typeof(*ocd), padding1) == 0);
1572 if (ocd->ocd_connect_flags & OBD_CONNECT_FLAGS2) 1573 if (ocd->ocd_connect_flags & OBD_CONNECT_FLAGS2)
1573 __swab64s(&ocd->ocd_connect_flags2); 1574 __swab64s(&ocd->ocd_connect_flags2);
1574 CLASSERT(offsetof(typeof(*ocd), padding3) != 0); 1575 BUILD_BUG_ON(offsetof(typeof(*ocd), padding3) == 0);
1575 CLASSERT(offsetof(typeof(*ocd), padding4) != 0); 1576 BUILD_BUG_ON(offsetof(typeof(*ocd), padding4) == 0);
1576 CLASSERT(offsetof(typeof(*ocd), padding5) != 0); 1577 BUILD_BUG_ON(offsetof(typeof(*ocd), padding5) == 0);
1577 CLASSERT(offsetof(typeof(*ocd), padding6) != 0); 1578 BUILD_BUG_ON(offsetof(typeof(*ocd), padding6) == 0);
1578 CLASSERT(offsetof(typeof(*ocd), padding7) != 0); 1579 BUILD_BUG_ON(offsetof(typeof(*ocd), padding7) == 0);
1579 CLASSERT(offsetof(typeof(*ocd), padding8) != 0); 1580 BUILD_BUG_ON(offsetof(typeof(*ocd), padding8) == 0);
1580 CLASSERT(offsetof(typeof(*ocd), padding9) != 0); 1581 BUILD_BUG_ON(offsetof(typeof(*ocd), padding9) == 0);
1581 CLASSERT(offsetof(typeof(*ocd), paddingA) != 0); 1582 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingA) == 0);
1582 CLASSERT(offsetof(typeof(*ocd), paddingB) != 0); 1583 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingB) == 0);
1583 CLASSERT(offsetof(typeof(*ocd), paddingC) != 0); 1584 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingC) == 0);
1584 CLASSERT(offsetof(typeof(*ocd), paddingD) != 0); 1585 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingD) == 0);
1585 CLASSERT(offsetof(typeof(*ocd), paddingE) != 0); 1586 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingE) == 0);
1586 CLASSERT(offsetof(typeof(*ocd), paddingF) != 0); 1587 BUILD_BUG_ON(offsetof(typeof(*ocd), paddingF) == 0);
1587} 1588}
1588 1589
1589static void lustre_swab_obdo(struct obdo *o) 1590static void lustre_swab_obdo(struct obdo *o)
@@ -1613,9 +1614,9 @@ static void lustre_swab_obdo(struct obdo *o)
1613 __swab32s(&o->o_uid_h); 1614 __swab32s(&o->o_uid_h);
1614 __swab32s(&o->o_gid_h); 1615 __swab32s(&o->o_gid_h);
1615 __swab64s(&o->o_data_version); 1616 __swab64s(&o->o_data_version);
1616 CLASSERT(offsetof(typeof(*o), o_padding_4) != 0); 1617 BUILD_BUG_ON(offsetof(typeof(*o), o_padding_4) == 0);
1617 CLASSERT(offsetof(typeof(*o), o_padding_5) != 0); 1618 BUILD_BUG_ON(offsetof(typeof(*o), o_padding_5) == 0);
1618 CLASSERT(offsetof(typeof(*o), o_padding_6) != 0); 1619 BUILD_BUG_ON(offsetof(typeof(*o), o_padding_6) == 0);
1619} 1620}
1620 1621
1621void lustre_swab_obd_statfs(struct obd_statfs *os) 1622void lustre_swab_obd_statfs(struct obd_statfs *os)
@@ -1631,15 +1632,15 @@ void lustre_swab_obd_statfs(struct obd_statfs *os)
1631 __swab32s(&os->os_namelen); 1632 __swab32s(&os->os_namelen);
1632 __swab64s(&os->os_maxbytes); 1633 __swab64s(&os->os_maxbytes);
1633 __swab32s(&os->os_state); 1634 __swab32s(&os->os_state);
1634 CLASSERT(offsetof(typeof(*os), os_fprecreated) != 0); 1635 BUILD_BUG_ON(offsetof(typeof(*os), os_fprecreated) == 0);
1635 CLASSERT(offsetof(typeof(*os), os_spare2) != 0); 1636 BUILD_BUG_ON(offsetof(typeof(*os), os_spare2) == 0);
1636 CLASSERT(offsetof(typeof(*os), os_spare3) != 0); 1637 BUILD_BUG_ON(offsetof(typeof(*os), os_spare3) == 0);
1637 CLASSERT(offsetof(typeof(*os), os_spare4) != 0); 1638 BUILD_BUG_ON(offsetof(typeof(*os), os_spare4) == 0);
1638 CLASSERT(offsetof(typeof(*os), os_spare5) != 0); 1639 BUILD_BUG_ON(offsetof(typeof(*os), os_spare5) == 0);
1639 CLASSERT(offsetof(typeof(*os), os_spare6) != 0); 1640 BUILD_BUG_ON(offsetof(typeof(*os), os_spare6) == 0);
1640 CLASSERT(offsetof(typeof(*os), os_spare7) != 0); 1641 BUILD_BUG_ON(offsetof(typeof(*os), os_spare7) == 0);
1641 CLASSERT(offsetof(typeof(*os), os_spare8) != 0); 1642 BUILD_BUG_ON(offsetof(typeof(*os), os_spare8) == 0);
1642 CLASSERT(offsetof(typeof(*os), os_spare9) != 0); 1643 BUILD_BUG_ON(offsetof(typeof(*os), os_spare9) == 0);
1643} 1644}
1644 1645
1645void lustre_swab_obd_ioobj(struct obd_ioobj *ioo) 1646void lustre_swab_obd_ioobj(struct obd_ioobj *ioo)
@@ -1679,7 +1680,7 @@ void lustre_swab_gl_desc(union ldlm_gl_desc *desc)
1679 __swab64s(&desc->lquota_desc.gl_hardlimit); 1680 __swab64s(&desc->lquota_desc.gl_hardlimit);
1680 __swab64s(&desc->lquota_desc.gl_softlimit); 1681 __swab64s(&desc->lquota_desc.gl_softlimit);
1681 __swab64s(&desc->lquota_desc.gl_time); 1682 __swab64s(&desc->lquota_desc.gl_time);
1682 CLASSERT(offsetof(typeof(desc->lquota_desc), gl_pad2) != 0); 1683 BUILD_BUG_ON(offsetof(typeof(desc->lquota_desc), gl_pad2) == 0);
1683} 1684}
1684 1685
1685void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb) 1686void lustre_swab_ost_lvb_v1(struct ost_lvb_v1 *lvb)
@@ -1738,24 +1739,24 @@ void lustre_swab_mdt_body(struct mdt_body *b)
1738 __swab32s(&b->mbo_flags); 1739 __swab32s(&b->mbo_flags);
1739 __swab32s(&b->mbo_rdev); 1740 __swab32s(&b->mbo_rdev);
1740 __swab32s(&b->mbo_nlink); 1741 __swab32s(&b->mbo_nlink);
1741 CLASSERT(offsetof(typeof(*b), mbo_unused2) != 0); 1742 BUILD_BUG_ON(offsetof(typeof(*b), mbo_unused2) == 0);
1742 __swab32s(&b->mbo_suppgid); 1743 __swab32s(&b->mbo_suppgid);
1743 __swab32s(&b->mbo_eadatasize); 1744 __swab32s(&b->mbo_eadatasize);
1744 __swab32s(&b->mbo_aclsize); 1745 __swab32s(&b->mbo_aclsize);
1745 __swab32s(&b->mbo_max_mdsize); 1746 __swab32s(&b->mbo_max_mdsize);
1746 CLASSERT(offsetof(typeof(*b), mbo_unused3)); 1747 BUILD_BUG_ON(!offsetof(typeof(*b), mbo_unused3));
1747 __swab32s(&b->mbo_uid_h); 1748 __swab32s(&b->mbo_uid_h);
1748 __swab32s(&b->mbo_gid_h); 1749 __swab32s(&b->mbo_gid_h);
1749 CLASSERT(offsetof(typeof(*b), mbo_padding_5) != 0); 1750 BUILD_BUG_ON(offsetof(typeof(*b), mbo_padding_5) == 0);
1750} 1751}
1751 1752
1752void lustre_swab_mdt_ioepoch(struct mdt_ioepoch *b) 1753void lustre_swab_mdt_ioepoch(struct mdt_ioepoch *b)
1753{ 1754{
1754 /* handle is opaque */ 1755 /* handle is opaque */
1755 /* mio_handle is opaque */ 1756 /* mio_handle is opaque */
1756 CLASSERT(offsetof(typeof(*b), mio_unused1)); 1757 BUILD_BUG_ON(!offsetof(typeof(*b), mio_unused1));
1757 CLASSERT(offsetof(typeof(*b), mio_unused2)); 1758 BUILD_BUG_ON(!offsetof(typeof(*b), mio_unused2));
1758 CLASSERT(offsetof(typeof(*b), mio_padding)); 1759 BUILD_BUG_ON(!offsetof(typeof(*b), mio_padding));
1759} 1760}
1760 1761
1761void lustre_swab_mgs_target_info(struct mgs_target_info *mti) 1762void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
@@ -1768,7 +1769,7 @@ void lustre_swab_mgs_target_info(struct mgs_target_info *mti)
1768 __swab32s(&mti->mti_flags); 1769 __swab32s(&mti->mti_flags);
1769 __swab32s(&mti->mti_instance); 1770 __swab32s(&mti->mti_instance);
1770 __swab32s(&mti->mti_nid_count); 1771 __swab32s(&mti->mti_nid_count);
1771 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64)); 1772 BUILD_BUG_ON(sizeof(lnet_nid_t) != sizeof(__u64));
1772 for (i = 0; i < MTI_NIDS_MAX; i++) 1773 for (i = 0; i < MTI_NIDS_MAX; i++)
1773 __swab64s(&mti->mti_nids[i]); 1774 __swab64s(&mti->mti_nids[i]);
1774} 1775}
@@ -1784,13 +1785,13 @@ void lustre_swab_mgs_nidtbl_entry(struct mgs_nidtbl_entry *entry)
1784 1785
1785 /* mne_nid_(count|type) must be one byte size because we're gonna 1786 /* mne_nid_(count|type) must be one byte size because we're gonna
1786 * access it w/o swapping. */ 1787 * access it w/o swapping. */
1787 CLASSERT(sizeof(entry->mne_nid_count) == sizeof(__u8)); 1788 BUILD_BUG_ON(sizeof(entry->mne_nid_count) != sizeof(__u8));
1788 CLASSERT(sizeof(entry->mne_nid_type) == sizeof(__u8)); 1789 BUILD_BUG_ON(sizeof(entry->mne_nid_type) != sizeof(__u8));
1789 1790
1790 /* remove this assertion if ipv6 is supported. */ 1791 /* remove this assertion if ipv6 is supported. */
1791 LASSERT(entry->mne_nid_type == 0); 1792 LASSERT(entry->mne_nid_type == 0);
1792 for (i = 0; i < entry->mne_nid_count; i++) { 1793 for (i = 0; i < entry->mne_nid_count; i++) {
1793 CLASSERT(sizeof(lnet_nid_t) == sizeof(__u64)); 1794 BUILD_BUG_ON(sizeof(lnet_nid_t) != sizeof(__u64));
1794 __swab64s(&entry->u.nids[i]); 1795 __swab64s(&entry->u.nids[i]);
1795 } 1796 }
1796} 1797}
@@ -1828,7 +1829,7 @@ static void lustre_swab_obd_dqblk(struct obd_dqblk *b)
1828 __swab64s(&b->dqb_btime); 1829 __swab64s(&b->dqb_btime);
1829 __swab64s(&b->dqb_itime); 1830 __swab64s(&b->dqb_itime);
1830 __swab32s(&b->dqb_valid); 1831 __swab32s(&b->dqb_valid);
1831 CLASSERT(offsetof(typeof(*b), dqb_padding) != 0); 1832 BUILD_BUG_ON(offsetof(typeof(*b), dqb_padding) == 0);
1832} 1833}
1833 1834
1834void lustre_swab_obd_quotactl(struct obd_quotactl *q) 1835void lustre_swab_obd_quotactl(struct obd_quotactl *q)
@@ -1899,7 +1900,7 @@ void lustre_swab_mdt_rec_reint (struct mdt_rec_reint *rr)
1899 __swab32s(&rr->rr_flags_h); 1900 __swab32s(&rr->rr_flags_h);
1900 __swab32s(&rr->rr_umask); 1901 __swab32s(&rr->rr_umask);
1901 1902
1902 CLASSERT(offsetof(typeof(*rr), rr_padding_4) != 0); 1903 BUILD_BUG_ON(offsetof(typeof(*rr), rr_padding_4) == 0);
1903}; 1904};
1904 1905
1905void lustre_swab_lov_desc(struct lov_desc *ld) 1906void lustre_swab_lov_desc(struct lov_desc *ld)
@@ -1948,7 +1949,7 @@ void lustre_swab_lmv_user_md(struct lmv_user_md *lum)
1948 __swab32s(&lum->lum_stripe_offset); 1949 __swab32s(&lum->lum_stripe_offset);
1949 __swab32s(&lum->lum_hash_type); 1950 __swab32s(&lum->lum_hash_type);
1950 __swab32s(&lum->lum_type); 1951 __swab32s(&lum->lum_type);
1951 CLASSERT(offsetof(typeof(*lum), lum_padding1)); 1952 BUILD_BUG_ON(!offsetof(typeof(*lum), lum_padding1));
1952} 1953}
1953EXPORT_SYMBOL(lustre_swab_lmv_user_md); 1954EXPORT_SYMBOL(lustre_swab_lmv_user_md);
1954 1955
@@ -2037,7 +2038,7 @@ void lustre_swab_ldlm_intent(struct ldlm_intent *i)
2037static void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r) 2038static void lustre_swab_ldlm_resource_desc(struct ldlm_resource_desc *r)
2038{ 2039{
2039 __swab32s(&r->lr_type); 2040 __swab32s(&r->lr_type);
2040 CLASSERT(offsetof(typeof(*r), lr_padding) != 0); 2041 BUILD_BUG_ON(offsetof(typeof(*r), lr_padding) == 0);
2041 lustre_swab_ldlm_res_id(&r->lr_name); 2042 lustre_swab_ldlm_res_id(&r->lr_name);
2042} 2043}
2043 2044
@@ -2060,7 +2061,7 @@ void lustre_swab_ldlm_request(struct ldlm_request *rq)
2060void lustre_swab_ldlm_reply(struct ldlm_reply *r) 2061void lustre_swab_ldlm_reply(struct ldlm_reply *r)
2061{ 2062{
2062 __swab32s(&r->lock_flags); 2063 __swab32s(&r->lock_flags);
2063 CLASSERT(offsetof(typeof(*r), lock_padding) != 0); 2064 BUILD_BUG_ON(offsetof(typeof(*r), lock_padding) == 0);
2064 lustre_swab_ldlm_lock_desc(&r->lock_desc); 2065 lustre_swab_ldlm_lock_desc(&r->lock_desc);
2065 /* lock_handle opaque */ 2066 /* lock_handle opaque */
2066 __swab64s(&r->lock_policy_res1); 2067 __swab64s(&r->lock_policy_res1);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pers.c b/drivers/staging/lustre/lustre/ptlrpc/pers.c
index 94e9fa85d774..601acb84f343 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pers.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pers.c
@@ -45,7 +45,7 @@ void ptlrpc_fill_bulk_md(lnet_md_t *md, struct ptlrpc_bulk_desc *desc,
45{ 45{
46 int offset = mdidx * LNET_MAX_IOV; 46 int offset = mdidx * LNET_MAX_IOV;
47 47
48 CLASSERT(PTLRPC_MAX_BRW_PAGES < LI_POISON); 48 BUILD_BUG_ON(PTLRPC_MAX_BRW_PAGES >= LI_POISON);
49 49
50 LASSERT(mdidx < desc->bd_md_max_brw); 50 LASSERT(mdidx < desc->bd_md_max_brw);
51 LASSERT(desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES); 51 LASSERT(desc->bd_iov_count <= PTLRPC_MAX_BRW_PAGES);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
index e0f859ca6223..8e6a805487ec 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
@@ -226,6 +226,9 @@ struct ptlrpc_nrs_policy *nrs_request_policy(struct ptlrpc_nrs_request *nrq)
226 sizeof(NRS_LPROCFS_QUANTUM_NAME_REG __stringify(LPROCFS_NRS_QUANTUM_MAX) " " \ 226 sizeof(NRS_LPROCFS_QUANTUM_NAME_REG __stringify(LPROCFS_NRS_QUANTUM_MAX) " " \
227 NRS_LPROCFS_QUANTUM_NAME_HP __stringify(LPROCFS_NRS_QUANTUM_MAX)) 227 NRS_LPROCFS_QUANTUM_NAME_HP __stringify(LPROCFS_NRS_QUANTUM_MAX))
228 228
229/* ptlrpc/nrs_fifo.c */
230extern struct ptlrpc_nrs_pol_conf nrs_conf_fifo;
231
229/* recovd_thread.c */ 232/* recovd_thread.c */
230 233
231int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink); 234int ptlrpc_expire_one_request(struct ptlrpc_request *req, int async_unlink);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
index 1f55d642aa75..59b5813bd559 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
@@ -82,7 +82,8 @@ struct ptlrpcd {
82 */ 82 */
83static int max_ptlrpcds; 83static int max_ptlrpcds;
84module_param(max_ptlrpcds, int, 0644); 84module_param(max_ptlrpcds, int, 0644);
85MODULE_PARM_DESC(max_ptlrpcds, "Max ptlrpcd thread count to be started."); 85MODULE_PARM_DESC(max_ptlrpcds,
86 "Max ptlrpcd thread count to be started (obsolete).");
86 87
87/* 88/*
88 * ptlrpcd_bind_policy is obsolete, but retained to ensure that 89 * ptlrpcd_bind_policy is obsolete, but retained to ensure that
@@ -102,7 +103,7 @@ MODULE_PARM_DESC(ptlrpcd_bind_policy,
102static int ptlrpcd_per_cpt_max; 103static int ptlrpcd_per_cpt_max;
103module_param(ptlrpcd_per_cpt_max, int, 0644); 104module_param(ptlrpcd_per_cpt_max, int, 0644);
104MODULE_PARM_DESC(ptlrpcd_per_cpt_max, 105MODULE_PARM_DESC(ptlrpcd_per_cpt_max,
105 "Max ptlrpcd thread count to be started per cpt."); 106 "Max ptlrpcd thread count to be started per CPT.");
106 107
107/* 108/*
108 * ptlrpcd_partner_group_size: The desired number of threads in each 109 * ptlrpcd_partner_group_size: The desired number of threads in each
@@ -562,15 +563,6 @@ int ptlrpcd_start(struct ptlrpcd_ctl *pc)
562 return 0; 563 return 0;
563 } 564 }
564 565
565 /*
566 * So far only "client" ptlrpcd uses an environment. In the future,
567 * ptlrpcd thread (or a thread-set) has to be given an argument,
568 * describing its "scope".
569 */
570 rc = lu_context_init(&pc->pc_env.le_ctx, LCT_CL_THREAD | LCT_REMEMBER);
571 if (rc != 0)
572 goto out;
573
574 task = kthread_run(ptlrpcd, pc, "%s", pc->pc_name); 566 task = kthread_run(ptlrpcd, pc, "%s", pc->pc_name);
575 if (IS_ERR(task)) { 567 if (IS_ERR(task)) {
576 rc = PTR_ERR(task); 568 rc = PTR_ERR(task);
@@ -593,9 +585,6 @@ out_set:
593 spin_unlock(&pc->pc_lock); 585 spin_unlock(&pc->pc_lock);
594 ptlrpc_set_destroy(set); 586 ptlrpc_set_destroy(set);
595 } 587 }
596 lu_context_fini(&pc->pc_env.le_ctx);
597
598out:
599 clear_bit(LIOD_START, &pc->pc_flags); 588 clear_bit(LIOD_START, &pc->pc_flags);
600 return rc; 589 return rc;
601} 590}
@@ -623,7 +612,6 @@ void ptlrpcd_free(struct ptlrpcd_ctl *pc)
623 } 612 }
624 613
625 wait_for_completion(&pc->pc_finishing); 614 wait_for_completion(&pc->pc_finishing);
626 lu_context_fini(&pc->pc_env.le_ctx);
627 615
628 spin_lock(&pc->pc_lock); 616 spin_lock(&pc->pc_lock);
629 pc->pc_set = NULL; 617 pc->pc_set = NULL;
diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c
index c00449036884..7b58545c2de4 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/recover.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c
@@ -78,28 +78,11 @@ int ptlrpc_replay_next(struct obd_import *imp, int *inflight)
78 imp->imp_last_transno_checked = 0; 78 imp->imp_last_transno_checked = 0;
79 ptlrpc_free_committed(imp); 79 ptlrpc_free_committed(imp);
80 last_transno = imp->imp_last_replay_transno; 80 last_transno = imp->imp_last_replay_transno;
81 spin_unlock(&imp->imp_lock);
82 81
83 CDEBUG(D_HA, "import %p from %s committed %llu last %llu\n", 82 CDEBUG(D_HA, "import %p from %s committed %llu last %llu\n",
84 imp, obd2cli_tgt(imp->imp_obd), 83 imp, obd2cli_tgt(imp->imp_obd),
85 imp->imp_peer_committed_transno, last_transno); 84 imp->imp_peer_committed_transno, last_transno);
86 85
87 /* Do I need to hold a lock across this iteration? We shouldn't be
88 * racing with any additions to the list, because we're in recovery
89 * and are therefore not processing additional requests to add. Calls
90 * to ptlrpc_free_committed might commit requests, but nothing "newer"
91 * than the one we're replaying (it can't be committed until it's
92 * replayed, and we're doing that here). l_f_e_safe protects against
93 * problems with the current request being committed, in the unlikely
94 * event of that race. So, in conclusion, I think that it's safe to
95 * perform this list-walk without the imp_lock held.
96 *
97 * But, the {mdc,osc}_replay_open callbacks both iterate
98 * request lists, and have comments saying they assume the
99 * imp_lock is being held by ptlrpc_replay, but it's not. it's
100 * just a little race...
101 */
102
103 /* Replay all the committed open requests on committed_list first */ 86 /* Replay all the committed open requests on committed_list first */
104 if (!list_empty(&imp->imp_committed_list)) { 87 if (!list_empty(&imp->imp_committed_list)) {
105 tmp = imp->imp_committed_list.prev; 88 tmp = imp->imp_committed_list.prev;
@@ -107,10 +90,6 @@ int ptlrpc_replay_next(struct obd_import *imp, int *inflight)
107 90
108 /* The last request on committed_list hasn't been replayed */ 91 /* The last request on committed_list hasn't been replayed */
109 if (req->rq_transno > last_transno) { 92 if (req->rq_transno > last_transno) {
110 /* Since the imp_committed_list is immutable before
111 * all of it's requests being replayed, it's safe to
112 * use a cursor to accelerate the search
113 */
114 if (!imp->imp_resend_replay || 93 if (!imp->imp_resend_replay ||
115 imp->imp_replay_cursor == &imp->imp_committed_list) 94 imp->imp_replay_cursor == &imp->imp_committed_list)
116 imp->imp_replay_cursor = imp->imp_replay_cursor->next; 95 imp->imp_replay_cursor = imp->imp_replay_cursor->next;
@@ -124,6 +103,7 @@ int ptlrpc_replay_next(struct obd_import *imp, int *inflight)
124 break; 103 break;
125 104
126 req = NULL; 105 req = NULL;
106 LASSERT(!list_empty(imp->imp_replay_cursor));
127 imp->imp_replay_cursor = 107 imp->imp_replay_cursor =
128 imp->imp_replay_cursor->next; 108 imp->imp_replay_cursor->next;
129 } 109 }
@@ -156,7 +136,6 @@ int ptlrpc_replay_next(struct obd_import *imp, int *inflight)
156 if (req && imp->imp_resend_replay) 136 if (req && imp->imp_resend_replay)
157 lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT); 137 lustre_msg_add_flags(req->rq_reqmsg, MSG_RESENT);
158 138
159 spin_lock(&imp->imp_lock);
160 /* The resend replay request may have been removed from the 139 /* The resend replay request may have been removed from the
161 * unreplied list. 140 * unreplied list.
162 */ 141 */
@@ -221,6 +200,7 @@ int ptlrpc_resend(struct obd_import *imp)
221 } 200 }
222 spin_unlock(&imp->imp_lock); 201 spin_unlock(&imp->imp_lock);
223 202
203 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_ENQUEUE_OLD_EXPORT, 2);
224 return 0; 204 return 0;
225} 205}
226 206
diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
index 70c70558e177..b8091c118302 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -1264,20 +1264,15 @@ static int ptlrpc_server_hpreq_init(struct ptlrpc_service_part *svcpt,
1264 */ 1264 */
1265 if (req->rq_ops->hpreq_check) { 1265 if (req->rq_ops->hpreq_check) {
1266 rc = req->rq_ops->hpreq_check(req); 1266 rc = req->rq_ops->hpreq_check(req);
1267 /** 1267 if (rc == -ESTALE) {
1268 * XXX: Out of all current 1268 req->rq_status = rc;
1269 * ptlrpc_hpreq_ops::hpreq_check(), only 1269 ptlrpc_error(req);
1270 * ldlm_cancel_hpreq_check() can return an error code; 1270 }
1271 * other functions assert in similar places, which seems 1271 /** can only return error,
1272 * odd. What also does not seem right is that handlers 1272 * 0 for normal request,
1273 * for those RPCs do not assert on the same checks, but 1273 * or 1 for high priority request
1274 * rather handle the error cases. e.g. see
1275 * ost_rw_hpreq_check(), and ost_brw_read(),
1276 * ost_brw_write().
1277 */ 1274 */
1278 if (rc < 0) 1275 LASSERT(rc <= 1);
1279 return rc;
1280 LASSERT(rc == 0 || rc == 1);
1281 } 1276 }
1282 1277
1283 spin_lock_bh(&req->rq_export->exp_rpc_lock); 1278 spin_lock_bh(&req->rq_export->exp_rpc_lock);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/wiretest.c b/drivers/staging/lustre/lustre/ptlrpc/wiretest.c
index a04e36cf6dd4..367f7e24e3da 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/wiretest.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/wiretest.c
@@ -61,7 +61,7 @@ void lustre_assert_wire_constants(void)
61 MDS_DIR_END_OFF); 61 MDS_DIR_END_OFF);
62 LASSERTF(DEAD_HANDLE_MAGIC == 0xdeadbeefcafebabeULL, "found 0x%.16llxULL\n", 62 LASSERTF(DEAD_HANDLE_MAGIC == 0xdeadbeefcafebabeULL, "found 0x%.16llxULL\n",
63 DEAD_HANDLE_MAGIC); 63 DEAD_HANDLE_MAGIC);
64 CLASSERT(MTI_NAME_MAXLEN == 64); 64 BUILD_BUG_ON(MTI_NAME_MAXLEN != 64);
65 LASSERTF(OST_REPLY == 0, "found %lld\n", 65 LASSERTF(OST_REPLY == 0, "found %lld\n",
66 (long long)OST_REPLY); 66 (long long)OST_REPLY);
67 LASSERTF(OST_GETATTR == 1, "found %lld\n", 67 LASSERTF(OST_GETATTR == 1, "found %lld\n",
@@ -306,16 +306,16 @@ void lustre_assert_wire_constants(void)
306 (long long)LCK_MAXMODE); 306 (long long)LCK_MAXMODE);
307 LASSERTF(LCK_MODE_NUM == 8, "found %lld\n", 307 LASSERTF(LCK_MODE_NUM == 8, "found %lld\n",
308 (long long)LCK_MODE_NUM); 308 (long long)LCK_MODE_NUM);
309 CLASSERT(LDLM_PLAIN == 10); 309 BUILD_BUG_ON(LDLM_PLAIN != 10);
310 CLASSERT(LDLM_EXTENT == 11); 310 BUILD_BUG_ON(LDLM_EXTENT != 11);
311 CLASSERT(LDLM_FLOCK == 12); 311 BUILD_BUG_ON(LDLM_FLOCK != 12);
312 CLASSERT(LDLM_IBITS == 13); 312 BUILD_BUG_ON(LDLM_IBITS != 13);
313 CLASSERT(LDLM_MAX_TYPE == 14); 313 BUILD_BUG_ON(LDLM_MAX_TYPE != 14);
314 CLASSERT(LUSTRE_RES_ID_SEQ_OFF == 0); 314 BUILD_BUG_ON(LUSTRE_RES_ID_SEQ_OFF != 0);
315 CLASSERT(LUSTRE_RES_ID_VER_OID_OFF == 1); 315 BUILD_BUG_ON(LUSTRE_RES_ID_VER_OID_OFF != 1);
316 CLASSERT(LUSTRE_RES_ID_QUOTA_SEQ_OFF == 2); 316 BUILD_BUG_ON(LUSTRE_RES_ID_QUOTA_SEQ_OFF != 2);
317 CLASSERT(LUSTRE_RES_ID_QUOTA_VER_OID_OFF == 3); 317 BUILD_BUG_ON(LUSTRE_RES_ID_QUOTA_VER_OID_OFF != 3);
318 CLASSERT(LUSTRE_RES_ID_HSH_OFF == 3); 318 BUILD_BUG_ON(LUSTRE_RES_ID_HSH_OFF != 3);
319 LASSERTF(OBD_PING == 400, "found %lld\n", 319 LASSERTF(OBD_PING == 400, "found %lld\n",
320 (long long)OBD_PING); 320 (long long)OBD_PING);
321 LASSERTF(OBD_LOG_CANCEL == 401, "found %lld\n", 321 LASSERTF(OBD_LOG_CANCEL == 401, "found %lld\n",
@@ -661,7 +661,7 @@ void lustre_assert_wire_constants(void)
661 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_slv)); 661 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_slv));
662 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_slv) == 8, "found %lld\n", 662 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_slv) == 8, "found %lld\n",
663 (long long)(int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_slv)); 663 (long long)(int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_slv));
664 CLASSERT(PTLRPC_NUM_VERSIONS == 4); 664 BUILD_BUG_ON(PTLRPC_NUM_VERSIONS != 4);
665 LASSERTF((int)offsetof(struct ptlrpc_body_v3, pb_pre_versions) == 88, "found %lld\n", 665 LASSERTF((int)offsetof(struct ptlrpc_body_v3, pb_pre_versions) == 88, "found %lld\n",
666 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_pre_versions)); 666 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_pre_versions));
667 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_pre_versions) == 32, "found %lld\n", 667 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_pre_versions) == 32, "found %lld\n",
@@ -682,7 +682,7 @@ void lustre_assert_wire_constants(void)
682 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_padding64_2)); 682 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_padding64_2));
683 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_padding64_2) == 8, "found %lld\n", 683 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_padding64_2) == 8, "found %lld\n",
684 (long long)(int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_padding64_2)); 684 (long long)(int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_padding64_2));
685 CLASSERT(LUSTRE_JOBID_SIZE == 32); 685 BUILD_BUG_ON(LUSTRE_JOBID_SIZE != 32);
686 LASSERTF((int)offsetof(struct ptlrpc_body_v3, pb_jobid) == 152, "found %lld\n", 686 LASSERTF((int)offsetof(struct ptlrpc_body_v3, pb_jobid) == 152, "found %lld\n",
687 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_jobid)); 687 (long long)(int)offsetof(struct ptlrpc_body_v3, pb_jobid));
688 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_jobid) == 32, "found %lld\n", 688 LASSERTF((int)sizeof(((struct ptlrpc_body_v3 *)0)->pb_jobid) == 32, "found %lld\n",
@@ -1319,27 +1319,27 @@ void lustre_assert_wire_constants(void)
1319 OBD_MD_FLGETATTRLOCK); 1319 OBD_MD_FLGETATTRLOCK);
1320 LASSERTF(OBD_MD_FLDATAVERSION == (0x0010000000000000ULL), "found 0x%.16llxULL\n", 1320 LASSERTF(OBD_MD_FLDATAVERSION == (0x0010000000000000ULL), "found 0x%.16llxULL\n",
1321 OBD_MD_FLDATAVERSION); 1321 OBD_MD_FLDATAVERSION);
1322 CLASSERT(OBD_FL_INLINEDATA == 0x00000001); 1322 BUILD_BUG_ON(OBD_FL_INLINEDATA != 0x00000001);
1323 CLASSERT(OBD_FL_OBDMDEXISTS == 0x00000002); 1323 BUILD_BUG_ON(OBD_FL_OBDMDEXISTS != 0x00000002);
1324 CLASSERT(OBD_FL_DELORPHAN == 0x00000004); 1324 BUILD_BUG_ON(OBD_FL_DELORPHAN != 0x00000004);
1325 CLASSERT(OBD_FL_NORPC == 0x00000008); 1325 BUILD_BUG_ON(OBD_FL_NORPC != 0x00000008);
1326 CLASSERT(OBD_FL_IDONLY == 0x00000010); 1326 BUILD_BUG_ON(OBD_FL_IDONLY != 0x00000010);
1327 CLASSERT(OBD_FL_RECREATE_OBJS == 0x00000020); 1327 BUILD_BUG_ON(OBD_FL_RECREATE_OBJS != 0x00000020);
1328 CLASSERT(OBD_FL_DEBUG_CHECK == 0x00000040); 1328 BUILD_BUG_ON(OBD_FL_DEBUG_CHECK != 0x00000040);
1329 CLASSERT(OBD_FL_NO_USRQUOTA == 0x00000100); 1329 BUILD_BUG_ON(OBD_FL_NO_USRQUOTA != 0x00000100);
1330 CLASSERT(OBD_FL_NO_GRPQUOTA == 0x00000200); 1330 BUILD_BUG_ON(OBD_FL_NO_GRPQUOTA != 0x00000200);
1331 CLASSERT(OBD_FL_CREATE_CROW == 0x00000400); 1331 BUILD_BUG_ON(OBD_FL_CREATE_CROW != 0x00000400);
1332 CLASSERT(OBD_FL_SRVLOCK == 0x00000800); 1332 BUILD_BUG_ON(OBD_FL_SRVLOCK != 0x00000800);
1333 CLASSERT(OBD_FL_CKSUM_CRC32 == 0x00001000); 1333 BUILD_BUG_ON(OBD_FL_CKSUM_CRC32 != 0x00001000);
1334 CLASSERT(OBD_FL_CKSUM_ADLER == 0x00002000); 1334 BUILD_BUG_ON(OBD_FL_CKSUM_ADLER != 0x00002000);
1335 CLASSERT(OBD_FL_CKSUM_CRC32C == 0x00004000); 1335 BUILD_BUG_ON(OBD_FL_CKSUM_CRC32C != 0x00004000);
1336 CLASSERT(OBD_FL_CKSUM_RSVD2 == 0x00008000); 1336 BUILD_BUG_ON(OBD_FL_CKSUM_RSVD2 != 0x00008000);
1337 CLASSERT(OBD_FL_CKSUM_RSVD3 == 0x00010000); 1337 BUILD_BUG_ON(OBD_FL_CKSUM_RSVD3 != 0x00010000);
1338 CLASSERT(OBD_FL_SHRINK_GRANT == 0x00020000); 1338 BUILD_BUG_ON(OBD_FL_SHRINK_GRANT != 0x00020000);
1339 CLASSERT(OBD_FL_MMAP == 0x00040000); 1339 BUILD_BUG_ON(OBD_FL_MMAP != 0x00040000);
1340 CLASSERT(OBD_FL_RECOV_RESEND == 0x00080000); 1340 BUILD_BUG_ON(OBD_FL_RECOV_RESEND != 0x00080000);
1341 CLASSERT(OBD_FL_NOSPC_BLK == 0x00100000); 1341 BUILD_BUG_ON(OBD_FL_NOSPC_BLK != 0x00100000);
1342 CLASSERT(OBD_FL_LOCAL_MASK == 0xf0000000); 1342 BUILD_BUG_ON(OBD_FL_LOCAL_MASK != 0xf0000000);
1343 1343
1344 /* Checks for struct lov_ost_data_v1 */ 1344 /* Checks for struct lov_ost_data_v1 */
1345 LASSERTF((int)sizeof(struct lov_ost_data_v1) == 24, "found %lld\n", 1345 LASSERTF((int)sizeof(struct lov_ost_data_v1) == 24, "found %lld\n",
@@ -1388,7 +1388,7 @@ void lustre_assert_wire_constants(void)
1388 (long long)(int)offsetof(struct lov_mds_md_v1, lmm_objects[0])); 1388 (long long)(int)offsetof(struct lov_mds_md_v1, lmm_objects[0]));
1389 LASSERTF((int)sizeof(((struct lov_mds_md_v1 *)0)->lmm_objects[0]) == 24, "found %lld\n", 1389 LASSERTF((int)sizeof(((struct lov_mds_md_v1 *)0)->lmm_objects[0]) == 24, "found %lld\n",
1390 (long long)(int)sizeof(((struct lov_mds_md_v1 *)0)->lmm_objects[0])); 1390 (long long)(int)sizeof(((struct lov_mds_md_v1 *)0)->lmm_objects[0]));
1391 CLASSERT(LOV_MAGIC_V1 == (0x0BD10000 | 0x0BD0)); 1391 BUILD_BUG_ON(LOV_MAGIC_V1 != (0x0BD10000 | 0x0BD0));
1392 1392
1393 /* Checks for struct lov_mds_md_v3 */ 1393 /* Checks for struct lov_mds_md_v3 */
1394 LASSERTF((int)sizeof(struct lov_mds_md_v3) == 48, "found %lld\n", 1394 LASSERTF((int)sizeof(struct lov_mds_md_v3) == 48, "found %lld\n",
@@ -1417,7 +1417,7 @@ void lustre_assert_wire_constants(void)
1417 (long long)(int)offsetof(struct lov_mds_md_v3, lmm_layout_gen)); 1417 (long long)(int)offsetof(struct lov_mds_md_v3, lmm_layout_gen));
1418 LASSERTF((int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_layout_gen) == 2, "found %lld\n", 1418 LASSERTF((int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_layout_gen) == 2, "found %lld\n",
1419 (long long)(int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_layout_gen)); 1419 (long long)(int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_layout_gen));
1420 CLASSERT(LOV_MAXPOOLNAME == 15); 1420 BUILD_BUG_ON(LOV_MAXPOOLNAME != 15);
1421 LASSERTF((int)offsetof(struct lov_mds_md_v3, lmm_pool_name[16]) == 48, "found %lld\n", 1421 LASSERTF((int)offsetof(struct lov_mds_md_v3, lmm_pool_name[16]) == 48, "found %lld\n",
1422 (long long)(int)offsetof(struct lov_mds_md_v3, lmm_pool_name[16])); 1422 (long long)(int)offsetof(struct lov_mds_md_v3, lmm_pool_name[16]));
1423 LASSERTF((int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_pool_name[16]) == 1, "found %lld\n", 1423 LASSERTF((int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_pool_name[16]) == 1, "found %lld\n",
@@ -1426,7 +1426,7 @@ void lustre_assert_wire_constants(void)
1426 (long long)(int)offsetof(struct lov_mds_md_v3, lmm_objects[0])); 1426 (long long)(int)offsetof(struct lov_mds_md_v3, lmm_objects[0]));
1427 LASSERTF((int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_objects[0]) == 24, "found %lld\n", 1427 LASSERTF((int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_objects[0]) == 24, "found %lld\n",
1428 (long long)(int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_objects[0])); 1428 (long long)(int)sizeof(((struct lov_mds_md_v3 *)0)->lmm_objects[0]));
1429 CLASSERT(LOV_MAGIC_V3 == (0x0BD30000 | 0x0BD0)); 1429 BUILD_BUG_ON(LOV_MAGIC_V3 != (0x0BD30000 | 0x0BD0));
1430 LASSERTF(LOV_PATTERN_RAID0 == 0x00000001UL, "found 0x%.8xUL\n", 1430 LASSERTF(LOV_PATTERN_RAID0 == 0x00000001UL, "found 0x%.8xUL\n",
1431 (unsigned int)LOV_PATTERN_RAID0); 1431 (unsigned int)LOV_PATTERN_RAID0);
1432 LASSERTF(LOV_PATTERN_RAID1 == 0x00000002UL, "found 0x%.8xUL\n", 1432 LASSERTF(LOV_PATTERN_RAID1 == 0x00000002UL, "found 0x%.8xUL\n",
@@ -1479,11 +1479,11 @@ void lustre_assert_wire_constants(void)
1479 (long long)(int)offsetof(struct lmv_mds_md_v1, lmv_stripe_fids[0])); 1479 (long long)(int)offsetof(struct lmv_mds_md_v1, lmv_stripe_fids[0]));
1480 LASSERTF((int)sizeof(((struct lmv_mds_md_v1 *)0)->lmv_stripe_fids[0]) == 16, "found %lld\n", 1480 LASSERTF((int)sizeof(((struct lmv_mds_md_v1 *)0)->lmv_stripe_fids[0]) == 16, "found %lld\n",
1481 (long long)(int)sizeof(((struct lmv_mds_md_v1 *)0)->lmv_stripe_fids[0])); 1481 (long long)(int)sizeof(((struct lmv_mds_md_v1 *)0)->lmv_stripe_fids[0]));
1482 CLASSERT(LMV_MAGIC_V1 == 0x0CD20CD0); 1482 BUILD_BUG_ON(LMV_MAGIC_V1 != 0x0CD20CD0);
1483 CLASSERT(LMV_MAGIC_STRIPE == 0x0CD40CD0); 1483 BUILD_BUG_ON(LMV_MAGIC_STRIPE != 0x0CD40CD0);
1484 CLASSERT(LMV_HASH_TYPE_MASK == 0x0000ffff); 1484 BUILD_BUG_ON(LMV_HASH_TYPE_MASK != 0x0000ffff);
1485 CLASSERT(LMV_HASH_FLAG_MIGRATION == 0x80000000); 1485 BUILD_BUG_ON(LMV_HASH_FLAG_MIGRATION != 0x80000000);
1486 CLASSERT(LMV_HASH_FLAG_DEAD == 0x40000000); 1486 BUILD_BUG_ON(LMV_HASH_FLAG_DEAD != 0x40000000);
1487 1487
1488 /* Checks for struct obd_statfs */ 1488 /* Checks for struct obd_statfs */
1489 LASSERTF((int)sizeof(struct obd_statfs) == 144, "found %lld\n", 1489 LASSERTF((int)sizeof(struct obd_statfs) == 144, "found %lld\n",
@@ -2761,12 +2761,12 @@ void lustre_assert_wire_constants(void)
2761 (long long)(int)offsetof(struct lov_desc, ld_uuid)); 2761 (long long)(int)offsetof(struct lov_desc, ld_uuid));
2762 LASSERTF((int)sizeof(((struct lov_desc *)0)->ld_uuid) == 40, "found %lld\n", 2762 LASSERTF((int)sizeof(((struct lov_desc *)0)->ld_uuid) == 40, "found %lld\n",
2763 (long long)(int)sizeof(((struct lov_desc *)0)->ld_uuid)); 2763 (long long)(int)sizeof(((struct lov_desc *)0)->ld_uuid));
2764 CLASSERT(LOV_DESC_MAGIC == 0xB0CCDE5C); 2764 BUILD_BUG_ON(LOV_DESC_MAGIC != 0xB0CCDE5C);
2765 2765
2766 /* Checks for struct ldlm_res_id */ 2766 /* Checks for struct ldlm_res_id */
2767 LASSERTF((int)sizeof(struct ldlm_res_id) == 32, "found %lld\n", 2767 LASSERTF((int)sizeof(struct ldlm_res_id) == 32, "found %lld\n",
2768 (long long)(int)sizeof(struct ldlm_res_id)); 2768 (long long)(int)sizeof(struct ldlm_res_id));
2769 CLASSERT(RES_NAME_SIZE == 4); 2769 BUILD_BUG_ON(RES_NAME_SIZE != 4);
2770 LASSERTF((int)offsetof(struct ldlm_res_id, name[4]) == 32, "found %lld\n", 2770 LASSERTF((int)offsetof(struct ldlm_res_id, name[4]) == 32, "found %lld\n",
2771 (long long)(int)offsetof(struct ldlm_res_id, name[4])); 2771 (long long)(int)offsetof(struct ldlm_res_id, name[4]));
2772 LASSERTF((int)sizeof(((struct ldlm_res_id *)0)->name[4]) == 8, "found %lld\n", 2772 LASSERTF((int)sizeof(((struct ldlm_res_id *)0)->name[4]) == 8, "found %lld\n",
@@ -3037,7 +3037,7 @@ void lustre_assert_wire_constants(void)
3037 /* Checks for struct mgs_send_param */ 3037 /* Checks for struct mgs_send_param */
3038 LASSERTF((int)sizeof(struct mgs_send_param) == 1024, "found %lld\n", 3038 LASSERTF((int)sizeof(struct mgs_send_param) == 1024, "found %lld\n",
3039 (long long)(int)sizeof(struct mgs_send_param)); 3039 (long long)(int)sizeof(struct mgs_send_param));
3040 CLASSERT(MGS_PARAM_MAXLEN == 1024); 3040 BUILD_BUG_ON(MGS_PARAM_MAXLEN != 1024);
3041 LASSERTF((int)offsetof(struct mgs_send_param, mgs_param[1024]) == 1024, "found %lld\n", 3041 LASSERTF((int)offsetof(struct mgs_send_param, mgs_param[1024]) == 1024, "found %lld\n",
3042 (long long)(int)offsetof(struct mgs_send_param, mgs_param[1024])); 3042 (long long)(int)offsetof(struct mgs_send_param, mgs_param[1024]));
3043 LASSERTF((int)sizeof(((struct mgs_send_param *)0)->mgs_param[1024]) == 1, "found %lld\n", 3043 LASSERTF((int)sizeof(((struct mgs_send_param *)0)->mgs_param[1024]) == 1, "found %lld\n",
@@ -3090,16 +3090,16 @@ void lustre_assert_wire_constants(void)
3090 (long long)(int)offsetof(struct llog_logid, lgl_ogen)); 3090 (long long)(int)offsetof(struct llog_logid, lgl_ogen));
3091 LASSERTF((int)sizeof(((struct llog_logid *)0)->lgl_ogen) == 4, "found %lld\n", 3091 LASSERTF((int)sizeof(((struct llog_logid *)0)->lgl_ogen) == 4, "found %lld\n",
3092 (long long)(int)sizeof(((struct llog_logid *)0)->lgl_ogen)); 3092 (long long)(int)sizeof(((struct llog_logid *)0)->lgl_ogen));
3093 CLASSERT(OST_SZ_REC == 274730752); 3093 BUILD_BUG_ON(OST_SZ_REC != 274730752);
3094 CLASSERT(MDS_UNLINK_REC == 274801668); 3094 BUILD_BUG_ON(MDS_UNLINK_REC != 274801668);
3095 CLASSERT(MDS_UNLINK64_REC == 275325956); 3095 BUILD_BUG_ON(MDS_UNLINK64_REC != 275325956);
3096 CLASSERT(MDS_SETATTR64_REC == 275325953); 3096 BUILD_BUG_ON(MDS_SETATTR64_REC != 275325953);
3097 CLASSERT(OBD_CFG_REC == 274857984); 3097 BUILD_BUG_ON(OBD_CFG_REC != 274857984);
3098 CLASSERT(LLOG_GEN_REC == 274989056); 3098 BUILD_BUG_ON(LLOG_GEN_REC != 274989056);
3099 CLASSERT(CHANGELOG_REC == 275120128); 3099 BUILD_BUG_ON(CHANGELOG_REC != 275120128);
3100 CLASSERT(CHANGELOG_USER_REC == 275185664); 3100 BUILD_BUG_ON(CHANGELOG_USER_REC != 275185664);
3101 CLASSERT(LLOG_HDR_MAGIC == 275010873); 3101 BUILD_BUG_ON(LLOG_HDR_MAGIC != 275010873);
3102 CLASSERT(LLOG_LOGID_MAGIC == 275010875); 3102 BUILD_BUG_ON(LLOG_LOGID_MAGIC != 275010875);
3103 3103
3104 /* Checks for struct llog_catid */ 3104 /* Checks for struct llog_catid */
3105 LASSERTF((int)sizeof(struct llog_catid) == 32, "found %lld\n", 3105 LASSERTF((int)sizeof(struct llog_catid) == 32, "found %lld\n",
@@ -3519,30 +3519,30 @@ void lustre_assert_wire_constants(void)
3519 (long long)(int)offsetof(struct llogd_body, lgd_cur_offset)); 3519 (long long)(int)offsetof(struct llogd_body, lgd_cur_offset));
3520 LASSERTF((int)sizeof(((struct llogd_body *)0)->lgd_cur_offset) == 8, "found %lld\n", 3520 LASSERTF((int)sizeof(((struct llogd_body *)0)->lgd_cur_offset) == 8, "found %lld\n",
3521 (long long)(int)sizeof(((struct llogd_body *)0)->lgd_cur_offset)); 3521 (long long)(int)sizeof(((struct llogd_body *)0)->lgd_cur_offset));
3522 CLASSERT(LLOG_ORIGIN_HANDLE_CREATE == 501); 3522 BUILD_BUG_ON(LLOG_ORIGIN_HANDLE_CREATE != 501);
3523 CLASSERT(LLOG_ORIGIN_HANDLE_NEXT_BLOCK == 502); 3523 BUILD_BUG_ON(LLOG_ORIGIN_HANDLE_NEXT_BLOCK != 502);
3524 CLASSERT(LLOG_ORIGIN_HANDLE_READ_HEADER == 503); 3524 BUILD_BUG_ON(LLOG_ORIGIN_HANDLE_READ_HEADER != 503);
3525 CLASSERT(LLOG_ORIGIN_HANDLE_WRITE_REC == 504); 3525 BUILD_BUG_ON(LLOG_ORIGIN_HANDLE_WRITE_REC != 504);
3526 CLASSERT(LLOG_ORIGIN_HANDLE_CLOSE == 505); 3526 BUILD_BUG_ON(LLOG_ORIGIN_HANDLE_CLOSE != 505);
3527 CLASSERT(LLOG_ORIGIN_CONNECT == 506); 3527 BUILD_BUG_ON(LLOG_ORIGIN_CONNECT != 506);
3528 CLASSERT(LLOG_CATINFO == 507); 3528 BUILD_BUG_ON(LLOG_CATINFO != 507);
3529 CLASSERT(LLOG_ORIGIN_HANDLE_PREV_BLOCK == 508); 3529 BUILD_BUG_ON(LLOG_ORIGIN_HANDLE_PREV_BLOCK != 508);
3530 CLASSERT(LLOG_ORIGIN_HANDLE_DESTROY == 509); 3530 BUILD_BUG_ON(LLOG_ORIGIN_HANDLE_DESTROY != 509);
3531 CLASSERT(LLOG_FIRST_OPC == 501); 3531 BUILD_BUG_ON(LLOG_FIRST_OPC != 501);
3532 CLASSERT(LLOG_LAST_OPC == 510); 3532 BUILD_BUG_ON(LLOG_LAST_OPC != 510);
3533 CLASSERT(LLOG_CONFIG_ORIG_CTXT == 0); 3533 BUILD_BUG_ON(LLOG_CONFIG_ORIG_CTXT != 0);
3534 CLASSERT(LLOG_CONFIG_REPL_CTXT == 1); 3534 BUILD_BUG_ON(LLOG_CONFIG_REPL_CTXT != 1);
3535 CLASSERT(LLOG_MDS_OST_ORIG_CTXT == 2); 3535 BUILD_BUG_ON(LLOG_MDS_OST_ORIG_CTXT != 2);
3536 CLASSERT(LLOG_MDS_OST_REPL_CTXT == 3); 3536 BUILD_BUG_ON(LLOG_MDS_OST_REPL_CTXT != 3);
3537 CLASSERT(LLOG_SIZE_ORIG_CTXT == 4); 3537 BUILD_BUG_ON(LLOG_SIZE_ORIG_CTXT != 4);
3538 CLASSERT(LLOG_SIZE_REPL_CTXT == 5); 3538 BUILD_BUG_ON(LLOG_SIZE_REPL_CTXT != 5);
3539 CLASSERT(LLOG_TEST_ORIG_CTXT == 8); 3539 BUILD_BUG_ON(LLOG_TEST_ORIG_CTXT != 8);
3540 CLASSERT(LLOG_TEST_REPL_CTXT == 9); 3540 BUILD_BUG_ON(LLOG_TEST_REPL_CTXT != 9);
3541 CLASSERT(LLOG_CHANGELOG_ORIG_CTXT == 12); 3541 BUILD_BUG_ON(LLOG_CHANGELOG_ORIG_CTXT != 12);
3542 CLASSERT(LLOG_CHANGELOG_REPL_CTXT == 13); 3542 BUILD_BUG_ON(LLOG_CHANGELOG_REPL_CTXT != 13);
3543 CLASSERT(LLOG_CHANGELOG_USER_ORIG_CTXT == 14); 3543 BUILD_BUG_ON(LLOG_CHANGELOG_USER_ORIG_CTXT != 14);
3544 CLASSERT(LLOG_AGENT_ORIG_CTXT == 15); 3544 BUILD_BUG_ON(LLOG_AGENT_ORIG_CTXT != 15);
3545 CLASSERT(LLOG_MAX_CTXTS == 16); 3545 BUILD_BUG_ON(LLOG_MAX_CTXTS != 16);
3546 3546
3547 /* Checks for struct llogd_conn_body */ 3547 /* Checks for struct llogd_conn_body */
3548 LASSERTF((int)sizeof(struct llogd_conn_body) == 40, "found %lld\n", 3548 LASSERTF((int)sizeof(struct llogd_conn_body) == 40, "found %lld\n",
@@ -3659,7 +3659,7 @@ void lustre_assert_wire_constants(void)
3659 (long long)(int)offsetof(struct lustre_capa, lc_expiry)); 3659 (long long)(int)offsetof(struct lustre_capa, lc_expiry));
3660 LASSERTF((int)sizeof(((struct lustre_capa *)0)->lc_expiry) == 4, "found %lld\n", 3660 LASSERTF((int)sizeof(((struct lustre_capa *)0)->lc_expiry) == 4, "found %lld\n",
3661 (long long)(int)sizeof(((struct lustre_capa *)0)->lc_expiry)); 3661 (long long)(int)sizeof(((struct lustre_capa *)0)->lc_expiry));
3662 CLASSERT(CAPA_HMAC_MAX_LEN == 64); 3662 BUILD_BUG_ON(CAPA_HMAC_MAX_LEN != 64);
3663 LASSERTF((int)offsetof(struct lustre_capa, lc_hmac[64]) == 120, "found %lld\n", 3663 LASSERTF((int)offsetof(struct lustre_capa, lc_hmac[64]) == 120, "found %lld\n",
3664 (long long)(int)offsetof(struct lustre_capa, lc_hmac[64])); 3664 (long long)(int)offsetof(struct lustre_capa, lc_hmac[64]));
3665 LASSERTF((int)sizeof(((struct lustre_capa *)0)->lc_hmac[64]) == 1, "found %lld\n", 3665 LASSERTF((int)sizeof(((struct lustre_capa *)0)->lc_hmac[64]) == 1, "found %lld\n",
@@ -3680,7 +3680,7 @@ void lustre_assert_wire_constants(void)
3680 (long long)(int)offsetof(struct lustre_capa_key, lk_padding)); 3680 (long long)(int)offsetof(struct lustre_capa_key, lk_padding));
3681 LASSERTF((int)sizeof(((struct lustre_capa_key *)0)->lk_padding) == 4, "found %lld\n", 3681 LASSERTF((int)sizeof(((struct lustre_capa_key *)0)->lk_padding) == 4, "found %lld\n",
3682 (long long)(int)sizeof(((struct lustre_capa_key *)0)->lk_padding)); 3682 (long long)(int)sizeof(((struct lustre_capa_key *)0)->lk_padding));
3683 CLASSERT(CAPA_HMAC_KEY_MAX_LEN == 56); 3683 BUILD_BUG_ON(CAPA_HMAC_KEY_MAX_LEN != 56);
3684 LASSERTF((int)offsetof(struct lustre_capa_key, lk_key[56]) == 72, "found %lld\n", 3684 LASSERTF((int)offsetof(struct lustre_capa_key, lk_key[56]) == 72, "found %lld\n",
3685 (long long)(int)offsetof(struct lustre_capa_key, lk_key[56])); 3685 (long long)(int)offsetof(struct lustre_capa_key, lk_key[56]));
3686 LASSERTF((int)sizeof(((struct lustre_capa_key *)0)->lk_key[56]) == 1, "found %lld\n", 3686 LASSERTF((int)sizeof(((struct lustre_capa_key *)0)->lk_key[56]) == 1, "found %lld\n",
@@ -3741,9 +3741,9 @@ void lustre_assert_wire_constants(void)
3741 (long long)(int)offsetof(struct fiemap, fm_extents)); 3741 (long long)(int)offsetof(struct fiemap, fm_extents));
3742 LASSERTF((int)sizeof(((struct fiemap *)0)->fm_extents) == 0, "found %lld\n", 3742 LASSERTF((int)sizeof(((struct fiemap *)0)->fm_extents) == 0, "found %lld\n",
3743 (long long)(int)sizeof(((struct fiemap *)0)->fm_extents)); 3743 (long long)(int)sizeof(((struct fiemap *)0)->fm_extents));
3744 CLASSERT(FIEMAP_FLAG_SYNC == 0x00000001); 3744 BUILD_BUG_ON(FIEMAP_FLAG_SYNC != 0x00000001);
3745 CLASSERT(FIEMAP_FLAG_XATTR == 0x00000002); 3745 BUILD_BUG_ON(FIEMAP_FLAG_XATTR != 0x00000002);
3746 CLASSERT(FIEMAP_FLAG_DEVICE_ORDER == 0x40000000); 3746 BUILD_BUG_ON(FIEMAP_FLAG_DEVICE_ORDER != 0x40000000);
3747 3747
3748 /* Checks for struct fiemap_extent */ 3748 /* Checks for struct fiemap_extent */
3749 LASSERTF((int)sizeof(struct fiemap_extent) == 56, "found %lld\n", 3749 LASSERTF((int)sizeof(struct fiemap_extent) == 56, "found %lld\n",
@@ -3768,18 +3768,18 @@ void lustre_assert_wire_constants(void)
3768 (long long)(int)offsetof(struct fiemap_extent, fe_reserved[0])); 3768 (long long)(int)offsetof(struct fiemap_extent, fe_reserved[0]));
3769 LASSERTF((int)sizeof(((struct fiemap_extent *)0)->fe_reserved[0]) == 4, "found %lld\n", 3769 LASSERTF((int)sizeof(((struct fiemap_extent *)0)->fe_reserved[0]) == 4, "found %lld\n",
3770 (long long)(int)sizeof(((struct fiemap_extent *)0)->fe_reserved[0])); 3770 (long long)(int)sizeof(((struct fiemap_extent *)0)->fe_reserved[0]));
3771 CLASSERT(FIEMAP_EXTENT_LAST == 0x00000001); 3771 BUILD_BUG_ON(FIEMAP_EXTENT_LAST != 0x00000001);
3772 CLASSERT(FIEMAP_EXTENT_UNKNOWN == 0x00000002); 3772 BUILD_BUG_ON(FIEMAP_EXTENT_UNKNOWN != 0x00000002);
3773 CLASSERT(FIEMAP_EXTENT_DELALLOC == 0x00000004); 3773 BUILD_BUG_ON(FIEMAP_EXTENT_DELALLOC != 0x00000004);
3774 CLASSERT(FIEMAP_EXTENT_ENCODED == 0x00000008); 3774 BUILD_BUG_ON(FIEMAP_EXTENT_ENCODED != 0x00000008);
3775 CLASSERT(FIEMAP_EXTENT_DATA_ENCRYPTED == 0x00000080); 3775 BUILD_BUG_ON(FIEMAP_EXTENT_DATA_ENCRYPTED != 0x00000080);
3776 CLASSERT(FIEMAP_EXTENT_NOT_ALIGNED == 0x00000100); 3776 BUILD_BUG_ON(FIEMAP_EXTENT_NOT_ALIGNED != 0x00000100);
3777 CLASSERT(FIEMAP_EXTENT_DATA_INLINE == 0x00000200); 3777 BUILD_BUG_ON(FIEMAP_EXTENT_DATA_INLINE != 0x00000200);
3778 CLASSERT(FIEMAP_EXTENT_DATA_TAIL == 0x00000400); 3778 BUILD_BUG_ON(FIEMAP_EXTENT_DATA_TAIL != 0x00000400);
3779 CLASSERT(FIEMAP_EXTENT_UNWRITTEN == 0x00000800); 3779 BUILD_BUG_ON(FIEMAP_EXTENT_UNWRITTEN != 0x00000800);
3780 CLASSERT(FIEMAP_EXTENT_MERGED == 0x00001000); 3780 BUILD_BUG_ON(FIEMAP_EXTENT_MERGED != 0x00001000);
3781 CLASSERT(FIEMAP_EXTENT_NO_DIRECT == 0x40000000); 3781 BUILD_BUG_ON(FIEMAP_EXTENT_NO_DIRECT != 0x40000000);
3782 CLASSERT(FIEMAP_EXTENT_NET == 0x80000000); 3782 BUILD_BUG_ON(FIEMAP_EXTENT_NET != 0x80000000);
3783 3783
3784 /* Checks for type posix_acl_xattr_entry */ 3784 /* Checks for type posix_acl_xattr_entry */
3785 LASSERTF((int)sizeof(struct posix_acl_xattr_entry) == 8, "found %lld\n", 3785 LASSERTF((int)sizeof(struct posix_acl_xattr_entry) == 8, "found %lld\n",
@@ -3828,7 +3828,7 @@ void lustre_assert_wire_constants(void)
3828 (long long)(int)offsetof(struct link_ea_header, padding2)); 3828 (long long)(int)offsetof(struct link_ea_header, padding2));
3829 LASSERTF((int)sizeof(((struct link_ea_header *)0)->padding2) == 4, "found %lld\n", 3829 LASSERTF((int)sizeof(((struct link_ea_header *)0)->padding2) == 4, "found %lld\n",
3830 (long long)(int)sizeof(((struct link_ea_header *)0)->padding2)); 3830 (long long)(int)sizeof(((struct link_ea_header *)0)->padding2));
3831 CLASSERT(LINK_EA_MAGIC == 0x11EAF1DFUL); 3831 BUILD_BUG_ON(LINK_EA_MAGIC != 0x11EAF1DFUL);
3832 3832
3833 /* Checks for struct link_ea_entry */ 3833 /* Checks for struct link_ea_entry */
3834 LASSERTF((int)sizeof(struct link_ea_entry) == 18, "found %lld\n", 3834 LASSERTF((int)sizeof(struct link_ea_entry) == 18, "found %lld\n",
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index ffb8fa72c3da..abd0e2d57c20 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -27,6 +27,8 @@ source "drivers/staging/media/davinci_vpfe/Kconfig"
27 27
28source "drivers/staging/media/omap4iss/Kconfig" 28source "drivers/staging/media/omap4iss/Kconfig"
29 29
30source "drivers/staging/media/platform/bcm2835/Kconfig"
31
30source "drivers/staging/media/s5p-cec/Kconfig" 32source "drivers/staging/media/s5p-cec/Kconfig"
31 33
32# Keep LIRC at the end, as it has sub-menus 34# Keep LIRC at the end, as it has sub-menus
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index a28e82cf6447..dc89325c463d 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -2,6 +2,7 @@ obj-$(CONFIG_I2C_BCM2048) += bcm2048/
2obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC) += s5p-cec/ 2obj-$(CONFIG_VIDEO_SAMSUNG_S5P_CEC) += s5p-cec/
3obj-$(CONFIG_DVB_CXD2099) += cxd2099/ 3obj-$(CONFIG_DVB_CXD2099) += cxd2099/
4obj-$(CONFIG_LIRC_STAGING) += lirc/ 4obj-$(CONFIG_LIRC_STAGING) += lirc/
5obj-$(CONFIG_VIDEO_BCM2835) += platform/bcm2835/
5obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/ 6obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
6obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/ 7obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/
7obj-$(CONFIG_VIDEO_STI_HDMI_CEC) += st-cec/ 8obj-$(CONFIG_VIDEO_STI_HDMI_CEC) += st-cec/
diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c
index 37bd439ee08b..d605c41d0424 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.c
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.c
@@ -300,7 +300,7 @@ struct bcm2048_device {
300}; 300};
301 301
302static int radio_nr = -1; /* radio device minor (-1 ==> auto assign) */ 302static int radio_nr = -1; /* radio device minor (-1 ==> auto assign) */
303module_param(radio_nr, int, 0); 303module_param(radio_nr, int, 0000);
304MODULE_PARM_DESC(radio_nr, 304MODULE_PARM_DESC(radio_nr,
305 "Minor number for radio device (-1 ==> auto assign)"); 305 "Minor number for radio device (-1 ==> auto assign)");
306 306
diff --git a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
index bf077f8342f6..32109cdd73a6 100644
--- a/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
+++ b/drivers/staging/media/davinci_vpfe/vpfe_mc_capture.c
@@ -74,7 +74,7 @@
74static bool debug; 74static bool debug;
75static bool interface; 75static bool interface;
76 76
77module_param(interface, bool, S_IRUGO); 77module_param(interface, bool, 0444);
78module_param(debug, bool, 0644); 78module_param(debug, bool, 0644);
79 79
80/** 80/**
diff --git a/drivers/staging/media/platform/bcm2835/Kconfig b/drivers/staging/media/platform/bcm2835/Kconfig
new file mode 100644
index 000000000000..7c5245dc3225
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/Kconfig
@@ -0,0 +1,10 @@
1config VIDEO_BCM2835
2 tristate "Broadcom BCM2835 camera driver"
3 depends on VIDEO_V4L2 && (ARCH_BCM2835 || COMPILE_TEST)
4 depends on BCM2835_VCHIQ
5 depends on ARM
6 select VIDEOBUF2_VMALLOC
7 help
8 Say Y here to enable camera host interface devices for
9 Broadcom BCM2835 SoC. This operates over the VCHIQ interface
10 to a service running on VideoCore.
diff --git a/drivers/staging/media/platform/bcm2835/Makefile b/drivers/staging/media/platform/bcm2835/Makefile
new file mode 100644
index 000000000000..8307f30517d5
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/Makefile
@@ -0,0 +1,10 @@
1bcm2835-v4l2-$(CONFIG_VIDEO_BCM2835) := \
2 bcm2835-camera.o \
3 controls.o \
4 mmal-vchiq.o
5
6obj-$(CONFIG_VIDEO_BCM2835) += bcm2835-v4l2.o
7
8ccflags-y += \
9 -Idrivers/staging/vc04_services \
10 -D__VCCOREVER__=0x04000000
diff --git a/drivers/staging/media/platform/bcm2835/TODO b/drivers/staging/media/platform/bcm2835/TODO
new file mode 100644
index 000000000000..61a509992b9a
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/TODO
@@ -0,0 +1,39 @@
11) Support dma-buf memory management.
2
3In order to zero-copy import camera images into the 3D or display
4pipelines, we need to export our buffers through dma-buf so that the
5vc4 driver can import them. This may involve bringing in the VCSM
6driver (which allows long-term management of regions of memory in the
7space that the VPU reserved and Linux otherwise doesn't have access
8to), or building some new protocol that allows VCSM-style management
9of Linux's CMA memory.
10
112) Avoid extra copies for padding of images.
12
13We expose V4L2_PIX_FMT_* formats that have a specified stride/height
14padding in the V4L2 spec, but that padding doesn't match what the
15hardware can do. If we exposed the native padding requirements
16through the V4L2 "multiplanar" formats, the firmware would have one
17less copy it needed to do.
18
193) Port to ARM64
20
21The bulk_receive() does some manual cache flushing that are 32-bit ARM
22only, which we should convert to proper cross-platform APIs.
23
244) Convert to be a platform driver.
25
26Right now when the module probes, it tries to initialize VCHI and
27errors out if it wasn't ready yet. If bcm2835-v4l2 was built in, then
28VCHI generally isn't ready because it depends on both the firmware and
29mailbox drivers having already loaded.
30
31We should have VCHI create a platform device once it's initialized,
32and have this driver bind to it, so that we automatically load the
33v4l2 module after VCHI loads.
34
355) Drop the gstreamer workaround.
36
37This was a temporary workaround for a bug that was fixed mid-2014, and
38we should remove it before stabilizing the driver.
39
diff --git a/drivers/staging/media/platform/bcm2835/bcm2835-camera.c b/drivers/staging/media/platform/bcm2835/bcm2835-camera.c
new file mode 100644
index 000000000000..ca15a698e018
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/bcm2835-camera.c
@@ -0,0 +1,2024 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15
16#include <linux/errno.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <media/videobuf2-vmalloc.h>
21#include <media/videobuf2-dma-contig.h>
22#include <media/v4l2-device.h>
23#include <media/v4l2-ioctl.h>
24#include <media/v4l2-ctrls.h>
25#include <media/v4l2-fh.h>
26#include <media/v4l2-event.h>
27#include <media/v4l2-common.h>
28#include <linux/delay.h>
29
30#include "mmal-common.h"
31#include "mmal-encodings.h"
32#include "mmal-vchiq.h"
33#include "mmal-msg.h"
34#include "mmal-parameters.h"
35#include "bcm2835-camera.h"
36
37#define BM2835_MMAL_VERSION "0.0.2"
38#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
39#define MIN_WIDTH 32
40#define MIN_HEIGHT 32
41#define MIN_BUFFER_SIZE (80 * 1024)
42
43#define MAX_VIDEO_MODE_WIDTH 1280
44#define MAX_VIDEO_MODE_HEIGHT 720
45
46#define MAX_BCM2835_CAMERAS 2
47
48MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
49MODULE_AUTHOR("Vincent Sanders");
50MODULE_LICENSE("GPL");
51MODULE_VERSION(BM2835_MMAL_VERSION);
52
53int bcm2835_v4l2_debug;
54module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
55MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
56
57#define UNSET (-1)
58static int video_nr[] = {[0 ... (MAX_BCM2835_CAMERAS - 1)] = UNSET };
59module_param_array(video_nr, int, NULL, 0644);
60MODULE_PARM_DESC(video_nr, "videoX start numbers, -1 is autodetect");
61
62static int max_video_width = MAX_VIDEO_MODE_WIDTH;
63static int max_video_height = MAX_VIDEO_MODE_HEIGHT;
64module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
65MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
66module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
67MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
68
69/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
70 * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
71 * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
72 * It's happier if we just don't say anything at all, when it then
73 * sets up a load of defaults that it thinks might work.
74 * If gst_v4l2src_is_broken is non-zero, then we remove the function from
75 * our function table list (actually switch to an alternate set, but same
76 * result).
77 */
78static int gst_v4l2src_is_broken;
79module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
80MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
81
82/* global device data array */
83static struct bm2835_mmal_dev *gdev[MAX_BCM2835_CAMERAS];
84
85#define FPS_MIN 1
86#define FPS_MAX 90
87
88/* timeperframe: min/max and default */
89static const struct v4l2_fract
90 tpf_min = {.numerator = 1, .denominator = FPS_MAX},
91 tpf_max = {.numerator = 1, .denominator = FPS_MIN},
92 tpf_default = {.numerator = 1000, .denominator = 30000};
93
94/* video formats */
95static struct mmal_fmt formats[] = {
96 {
97 .name = "4:2:0, planar, YUV",
98 .fourcc = V4L2_PIX_FMT_YUV420,
99 .flags = 0,
100 .mmal = MMAL_ENCODING_I420,
101 .depth = 12,
102 .mmal_component = MMAL_COMPONENT_CAMERA,
103 .ybbp = 1,
104 },
105 {
106 .name = "4:2:2, packed, YUYV",
107 .fourcc = V4L2_PIX_FMT_YUYV,
108 .flags = 0,
109 .mmal = MMAL_ENCODING_YUYV,
110 .depth = 16,
111 .mmal_component = MMAL_COMPONENT_CAMERA,
112 .ybbp = 2,
113 },
114 {
115 .name = "RGB24 (LE)",
116 .fourcc = V4L2_PIX_FMT_RGB24,
117 .flags = 0,
118 .mmal = MMAL_ENCODING_RGB24,
119 .depth = 24,
120 .mmal_component = MMAL_COMPONENT_CAMERA,
121 .ybbp = 3,
122 },
123 {
124 .name = "JPEG",
125 .fourcc = V4L2_PIX_FMT_JPEG,
126 .flags = V4L2_FMT_FLAG_COMPRESSED,
127 .mmal = MMAL_ENCODING_JPEG,
128 .depth = 8,
129 .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
130 .ybbp = 0,
131 },
132 {
133 .name = "H264",
134 .fourcc = V4L2_PIX_FMT_H264,
135 .flags = V4L2_FMT_FLAG_COMPRESSED,
136 .mmal = MMAL_ENCODING_H264,
137 .depth = 8,
138 .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
139 .ybbp = 0,
140 },
141 {
142 .name = "MJPEG",
143 .fourcc = V4L2_PIX_FMT_MJPEG,
144 .flags = V4L2_FMT_FLAG_COMPRESSED,
145 .mmal = MMAL_ENCODING_MJPEG,
146 .depth = 8,
147 .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
148 .ybbp = 0,
149 },
150 {
151 .name = "4:2:2, packed, YVYU",
152 .fourcc = V4L2_PIX_FMT_YVYU,
153 .flags = 0,
154 .mmal = MMAL_ENCODING_YVYU,
155 .depth = 16,
156 .mmal_component = MMAL_COMPONENT_CAMERA,
157 .ybbp = 2,
158 },
159 {
160 .name = "4:2:2, packed, VYUY",
161 .fourcc = V4L2_PIX_FMT_VYUY,
162 .flags = 0,
163 .mmal = MMAL_ENCODING_VYUY,
164 .depth = 16,
165 .mmal_component = MMAL_COMPONENT_CAMERA,
166 .ybbp = 2,
167 },
168 {
169 .name = "4:2:2, packed, UYVY",
170 .fourcc = V4L2_PIX_FMT_UYVY,
171 .flags = 0,
172 .mmal = MMAL_ENCODING_UYVY,
173 .depth = 16,
174 .mmal_component = MMAL_COMPONENT_CAMERA,
175 .ybbp = 2,
176 },
177 {
178 .name = "4:2:0, planar, NV12",
179 .fourcc = V4L2_PIX_FMT_NV12,
180 .flags = 0,
181 .mmal = MMAL_ENCODING_NV12,
182 .depth = 12,
183 .mmal_component = MMAL_COMPONENT_CAMERA,
184 .ybbp = 1,
185 },
186 {
187 .name = "RGB24 (BE)",
188 .fourcc = V4L2_PIX_FMT_BGR24,
189 .flags = 0,
190 .mmal = MMAL_ENCODING_BGR24,
191 .depth = 24,
192 .mmal_component = MMAL_COMPONENT_CAMERA,
193 .ybbp = 3,
194 },
195 {
196 .name = "4:2:0, planar, YVU",
197 .fourcc = V4L2_PIX_FMT_YVU420,
198 .flags = 0,
199 .mmal = MMAL_ENCODING_YV12,
200 .depth = 12,
201 .mmal_component = MMAL_COMPONENT_CAMERA,
202 .ybbp = 1,
203 },
204 {
205 .name = "4:2:0, planar, NV21",
206 .fourcc = V4L2_PIX_FMT_NV21,
207 .flags = 0,
208 .mmal = MMAL_ENCODING_NV21,
209 .depth = 12,
210 .mmal_component = MMAL_COMPONENT_CAMERA,
211 .ybbp = 1,
212 },
213 {
214 .name = "RGB32 (BE)",
215 .fourcc = V4L2_PIX_FMT_BGR32,
216 .flags = 0,
217 .mmal = MMAL_ENCODING_BGRA,
218 .depth = 32,
219 .mmal_component = MMAL_COMPONENT_CAMERA,
220 .ybbp = 4,
221 },
222};
223
224static struct mmal_fmt *get_format(struct v4l2_format *f)
225{
226 struct mmal_fmt *fmt;
227 unsigned int k;
228
229 for (k = 0; k < ARRAY_SIZE(formats); k++) {
230 fmt = &formats[k];
231 if (fmt->fourcc == f->fmt.pix.pixelformat)
232 break;
233 }
234
235 if (k == ARRAY_SIZE(formats))
236 return NULL;
237
238 return &formats[k];
239}
240
241/* ------------------------------------------------------------------
242 Videobuf queue operations
243 ------------------------------------------------------------------*/
244
245static int queue_setup(struct vb2_queue *vq,
246 unsigned int *nbuffers, unsigned int *nplanes,
247 unsigned int sizes[], struct device *alloc_ctxs[])
248{
249 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
250 unsigned long size;
251
252 /* refuse queue setup if port is not configured */
253 if (dev->capture.port == NULL) {
254 v4l2_err(&dev->v4l2_dev,
255 "%s: capture port not configured\n", __func__);
256 return -EINVAL;
257 }
258
259 size = dev->capture.port->current_buffer.size;
260 if (size == 0) {
261 v4l2_err(&dev->v4l2_dev,
262 "%s: capture port buffer size is zero\n", __func__);
263 return -EINVAL;
264 }
265
266 if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
267 *nbuffers = (dev->capture.port->current_buffer.num + 2);
268
269 *nplanes = 1;
270
271 sizes[0] = size;
272
273 /*
274 * videobuf2-vmalloc allocator is context-less so no need to set
275 * alloc_ctxs array.
276 */
277
278 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
279 __func__, dev);
280
281 return 0;
282}
283
284static int buffer_prepare(struct vb2_buffer *vb)
285{
286 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
287 unsigned long size;
288
289 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
290 __func__, dev);
291
292 BUG_ON(dev->capture.port == NULL);
293 BUG_ON(dev->capture.fmt == NULL);
294
295 size = dev->capture.stride * dev->capture.height;
296 if (vb2_plane_size(vb, 0) < size) {
297 v4l2_err(&dev->v4l2_dev,
298 "%s data will not fit into plane (%lu < %lu)\n",
299 __func__, vb2_plane_size(vb, 0), size);
300 return -EINVAL;
301 }
302
303 return 0;
304}
305
306static inline bool is_capturing(struct bm2835_mmal_dev *dev)
307{
308 return dev->capture.camera_port ==
309 &dev->
310 component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
311}
312
313static void buffer_cb(struct vchiq_mmal_instance *instance,
314 struct vchiq_mmal_port *port,
315 int status,
316 struct mmal_buffer *buf,
317 unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
318{
319 struct bm2835_mmal_dev *dev = port->cb_ctx;
320
321 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
322 "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
323 __func__, status, buf, length, mmal_flags, pts);
324
325 if (status != 0) {
326 /* error in transfer */
327 if (buf != NULL) {
328 /* there was a buffer with the error so return it */
329 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
330 }
331 return;
332 } else if (length == 0) {
333 /* stream ended */
334 if (buf != NULL) {
335 /* this should only ever happen if the port is
336 * disabled and there are buffers still queued
337 */
338 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
339 pr_debug("Empty buffer");
340 } else if (dev->capture.frame_count) {
341 /* grab another frame */
342 if (is_capturing(dev)) {
343 pr_debug("Grab another frame");
344 vchiq_mmal_port_parameter_set(
345 instance,
346 dev->capture.
347 camera_port,
348 MMAL_PARAMETER_CAPTURE,
349 &dev->capture.
350 frame_count,
351 sizeof(dev->capture.frame_count));
352 }
353 } else {
354 /* signal frame completion */
355 complete(&dev->capture.frame_cmplt);
356 }
357 } else {
358 if (dev->capture.frame_count) {
359 if (dev->capture.vc_start_timestamp != -1 &&
360 pts != 0) {
361 struct timeval timestamp;
362 s64 runtime_us = pts -
363 dev->capture.vc_start_timestamp;
364 u32 div = 0;
365 u32 rem = 0;
366
367 div =
368 div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
369 timestamp.tv_sec =
370 dev->capture.kernel_start_ts.tv_sec + div;
371 timestamp.tv_usec =
372 dev->capture.kernel_start_ts.tv_usec + rem;
373
374 if (timestamp.tv_usec >=
375 USEC_PER_SEC) {
376 timestamp.tv_sec++;
377 timestamp.tv_usec -=
378 USEC_PER_SEC;
379 }
380 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
381 "Convert start time %d.%06d and %llu "
382 "with offset %llu to %d.%06d\n",
383 (int)dev->capture.kernel_start_ts.
384 tv_sec,
385 (int)dev->capture.kernel_start_ts.
386 tv_usec,
387 dev->capture.vc_start_timestamp, pts,
388 (int)timestamp.tv_sec,
389 (int)timestamp.tv_usec);
390 buf->vb.vb2_buf.timestamp = timestamp.tv_sec * 1000000000ULL +
391 timestamp.tv_usec * 1000ULL;
392 } else {
393 buf->vb.vb2_buf.timestamp = ktime_get_ns();
394 }
395
396 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
397 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
398
399 if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
400 is_capturing(dev)) {
401 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
402 "Grab another frame as buffer has EOS");
403 vchiq_mmal_port_parameter_set(
404 instance,
405 dev->capture.
406 camera_port,
407 MMAL_PARAMETER_CAPTURE,
408 &dev->capture.
409 frame_count,
410 sizeof(dev->capture.frame_count));
411 }
412 } else {
413 /* signal frame completion */
414 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
415 complete(&dev->capture.frame_cmplt);
416 }
417 }
418}
419
420static int enable_camera(struct bm2835_mmal_dev *dev)
421{
422 int ret;
423
424 if (!dev->camera_use_count) {
425 ret = vchiq_mmal_port_parameter_set(
426 dev->instance,
427 &dev->component[MMAL_COMPONENT_CAMERA]->control,
428 MMAL_PARAMETER_CAMERA_NUM, &dev->camera_num,
429 sizeof(dev->camera_num));
430 if (ret < 0) {
431 v4l2_err(&dev->v4l2_dev,
432 "Failed setting camera num, ret %d\n", ret);
433 return -EINVAL;
434 }
435
436 ret = vchiq_mmal_component_enable(
437 dev->instance,
438 dev->component[MMAL_COMPONENT_CAMERA]);
439 if (ret < 0) {
440 v4l2_err(&dev->v4l2_dev,
441 "Failed enabling camera, ret %d\n", ret);
442 return -EINVAL;
443 }
444 }
445 dev->camera_use_count++;
446 v4l2_dbg(1, bcm2835_v4l2_debug,
447 &dev->v4l2_dev, "enabled camera (refcount %d)\n",
448 dev->camera_use_count);
449 return 0;
450}
451
452static int disable_camera(struct bm2835_mmal_dev *dev)
453{
454 int ret;
455
456 if (!dev->camera_use_count) {
457 v4l2_err(&dev->v4l2_dev,
458 "Disabled the camera when already disabled\n");
459 return -EINVAL;
460 }
461 dev->camera_use_count--;
462 if (!dev->camera_use_count) {
463 unsigned int i = 0xFFFFFFFF;
464
465 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
466 "Disabling camera\n");
467 ret =
468 vchiq_mmal_component_disable(
469 dev->instance,
470 dev->component[MMAL_COMPONENT_CAMERA]);
471 if (ret < 0) {
472 v4l2_err(&dev->v4l2_dev,
473 "Failed disabling camera, ret %d\n", ret);
474 return -EINVAL;
475 }
476 vchiq_mmal_port_parameter_set(
477 dev->instance,
478 &dev->component[MMAL_COMPONENT_CAMERA]->control,
479 MMAL_PARAMETER_CAMERA_NUM, &i,
480 sizeof(i));
481 }
482 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
483 "Camera refcount now %d\n", dev->camera_use_count);
484 return 0;
485}
486
487static void buffer_queue(struct vb2_buffer *vb)
488{
489 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
490 struct vb2_v4l2_buffer *vb2 = to_vb2_v4l2_buffer(vb);
491 struct mmal_buffer *buf = container_of(vb2, struct mmal_buffer, vb);
492 int ret;
493
494 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
495 "%s: dev:%p buf:%p\n", __func__, dev, buf);
496
497 buf->buffer = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
498 buf->buffer_size = vb2_plane_size(&buf->vb.vb2_buf, 0);
499
500 ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
501 if (ret < 0)
502 v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
503 __func__);
504}
505
506static int start_streaming(struct vb2_queue *vq, unsigned int count)
507{
508 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
509 int ret;
510 int parameter_size;
511
512 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
513 __func__, dev);
514
515 /* ensure a format has actually been set */
516 if (dev->capture.port == NULL)
517 return -EINVAL;
518
519 if (enable_camera(dev) < 0) {
520 v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
521 return -EINVAL;
522 }
523
524 /*init_completion(&dev->capture.frame_cmplt); */
525
526 /* enable frame capture */
527 dev->capture.frame_count = 1;
528
529 /* if the preview is not already running, wait for a few frames for AGC
530 * to settle down.
531 */
532 if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
533 msleep(300);
534
535 /* enable the connection from camera to encoder (if applicable) */
536 if (dev->capture.camera_port != dev->capture.port
537 && dev->capture.camera_port) {
538 ret = vchiq_mmal_port_enable(dev->instance,
539 dev->capture.camera_port, NULL);
540 if (ret) {
541 v4l2_err(&dev->v4l2_dev,
542 "Failed to enable encode tunnel - error %d\n",
543 ret);
544 return -1;
545 }
546 }
547
548 /* Get VC timestamp at this point in time */
549 parameter_size = sizeof(dev->capture.vc_start_timestamp);
550 if (vchiq_mmal_port_parameter_get(dev->instance,
551 dev->capture.camera_port,
552 MMAL_PARAMETER_SYSTEM_TIME,
553 &dev->capture.vc_start_timestamp,
554 &parameter_size)) {
555 v4l2_err(&dev->v4l2_dev,
556 "Failed to get VC start time - update your VC f/w\n");
557
558 /* Flag to indicate just to rely on kernel timestamps */
559 dev->capture.vc_start_timestamp = -1;
560 } else
561 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
562 "Start time %lld size %d\n",
563 dev->capture.vc_start_timestamp, parameter_size);
564
565 v4l2_get_timestamp(&dev->capture.kernel_start_ts);
566
567 /* enable the camera port */
568 dev->capture.port->cb_ctx = dev;
569 ret =
570 vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
571 if (ret) {
572 v4l2_err(&dev->v4l2_dev,
573 "Failed to enable capture port - error %d. "
574 "Disabling camera port again\n", ret);
575
576 vchiq_mmal_port_disable(dev->instance,
577 dev->capture.camera_port);
578 if (disable_camera(dev) < 0) {
579 v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
580 return -EINVAL;
581 }
582 return -1;
583 }
584
585 /* capture the first frame */
586 vchiq_mmal_port_parameter_set(dev->instance,
587 dev->capture.camera_port,
588 MMAL_PARAMETER_CAPTURE,
589 &dev->capture.frame_count,
590 sizeof(dev->capture.frame_count));
591 return 0;
592}
593
594/* abort streaming and wait for last buffer */
595static void stop_streaming(struct vb2_queue *vq)
596{
597 int ret;
598 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
599
600 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
601 __func__, dev);
602
603 init_completion(&dev->capture.frame_cmplt);
604 dev->capture.frame_count = 0;
605
606 /* ensure a format has actually been set */
607 if (dev->capture.port == NULL) {
608 v4l2_err(&dev->v4l2_dev,
609 "no capture port - stream not started?\n");
610 return;
611 }
612
613 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
614
615 /* stop capturing frames */
616 vchiq_mmal_port_parameter_set(dev->instance,
617 dev->capture.camera_port,
618 MMAL_PARAMETER_CAPTURE,
619 &dev->capture.frame_count,
620 sizeof(dev->capture.frame_count));
621
622 /* wait for last frame to complete */
623 ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
624 if (ret <= 0)
625 v4l2_err(&dev->v4l2_dev,
626 "error %d waiting for frame completion\n", ret);
627
628 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
629 "disabling connection\n");
630
631 /* disable the connection from camera to encoder */
632 ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
633 if (!ret && dev->capture.camera_port != dev->capture.port) {
634 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
635 "disabling port\n");
636 ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
637 } else if (dev->capture.camera_port != dev->capture.port) {
638 v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
639 ret);
640 }
641
642 if (disable_camera(dev) < 0)
643 v4l2_err(&dev->v4l2_dev, "Failed to disable camera\n");
644}
645
646static void bm2835_mmal_lock(struct vb2_queue *vq)
647{
648 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
649
650 mutex_lock(&dev->mutex);
651}
652
653static void bm2835_mmal_unlock(struct vb2_queue *vq)
654{
655 struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
656
657 mutex_unlock(&dev->mutex);
658}
659
660static struct vb2_ops bm2835_mmal_video_qops = {
661 .queue_setup = queue_setup,
662 .buf_prepare = buffer_prepare,
663 .buf_queue = buffer_queue,
664 .start_streaming = start_streaming,
665 .stop_streaming = stop_streaming,
666 .wait_prepare = bm2835_mmal_unlock,
667 .wait_finish = bm2835_mmal_lock,
668};
669
670/* ------------------------------------------------------------------
671 IOCTL operations
672 ------------------------------------------------------------------*/
673
674static int set_overlay_params(struct bm2835_mmal_dev *dev,
675 struct vchiq_mmal_port *port)
676{
677 int ret;
678 struct mmal_parameter_displayregion prev_config = {
679 .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
680 MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
681 .layer = PREVIEW_LAYER,
682 .alpha = dev->overlay.global_alpha,
683 .fullscreen = 0,
684 .dest_rect = {
685 .x = dev->overlay.w.left,
686 .y = dev->overlay.w.top,
687 .width = dev->overlay.w.width,
688 .height = dev->overlay.w.height,
689 },
690 };
691 ret = vchiq_mmal_port_parameter_set(dev->instance, port,
692 MMAL_PARAMETER_DISPLAYREGION,
693 &prev_config, sizeof(prev_config));
694
695 return ret;
696}
697
698/* overlay ioctl */
699static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
700 struct v4l2_fmtdesc *f)
701{
702 struct mmal_fmt *fmt;
703
704 if (f->index >= ARRAY_SIZE(formats))
705 return -EINVAL;
706
707 fmt = &formats[f->index];
708
709 strlcpy(f->description, fmt->name, sizeof(f->description));
710 f->pixelformat = fmt->fourcc;
711 f->flags = fmt->flags;
712
713 return 0;
714}
715
716static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
717 struct v4l2_format *f)
718{
719 struct bm2835_mmal_dev *dev = video_drvdata(file);
720
721 f->fmt.win = dev->overlay;
722
723 return 0;
724}
725
726static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
727 struct v4l2_format *f)
728{
729 struct bm2835_mmal_dev *dev = video_drvdata(file);
730
731 f->fmt.win.field = V4L2_FIELD_NONE;
732 f->fmt.win.chromakey = 0;
733 f->fmt.win.clips = NULL;
734 f->fmt.win.clipcount = 0;
735 f->fmt.win.bitmap = NULL;
736
737 v4l_bound_align_image(&f->fmt.win.w.width, MIN_WIDTH, dev->max_width, 1,
738 &f->fmt.win.w.height, MIN_HEIGHT, dev->max_height,
739 1, 0);
740 v4l_bound_align_image(&f->fmt.win.w.left, MIN_WIDTH, dev->max_width, 1,
741 &f->fmt.win.w.top, MIN_HEIGHT, dev->max_height,
742 1, 0);
743
744 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
745 "Overlay: Now w/h %dx%d l/t %dx%d\n",
746 f->fmt.win.w.width, f->fmt.win.w.height,
747 f->fmt.win.w.left, f->fmt.win.w.top);
748
749 v4l2_dump_win_format(1,
750 bcm2835_v4l2_debug,
751 &dev->v4l2_dev,
752 &f->fmt.win,
753 __func__);
754 return 0;
755}
756
757static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
758 struct v4l2_format *f)
759{
760 struct bm2835_mmal_dev *dev = video_drvdata(file);
761
762 vidioc_try_fmt_vid_overlay(file, priv, f);
763
764 dev->overlay = f->fmt.win;
765 if (dev->component[MMAL_COMPONENT_PREVIEW]->enabled) {
766 set_overlay_params(dev,
767 &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
768 }
769
770 return 0;
771}
772
773static int vidioc_overlay(struct file *file, void *f, unsigned int on)
774{
775 int ret;
776 struct bm2835_mmal_dev *dev = video_drvdata(file);
777 struct vchiq_mmal_port *src;
778 struct vchiq_mmal_port *dst;
779
780 if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
781 (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
782 return 0; /* already in requested state */
783
784 src =
785 &dev->component[MMAL_COMPONENT_CAMERA]->
786 output[MMAL_CAMERA_PORT_PREVIEW];
787
788 if (!on) {
789 /* disconnect preview ports and disable component */
790 ret = vchiq_mmal_port_disable(dev->instance, src);
791 if (!ret)
792 ret =
793 vchiq_mmal_port_connect_tunnel(dev->instance, src,
794 NULL);
795 if (ret >= 0)
796 ret = vchiq_mmal_component_disable(
797 dev->instance,
798 dev->component[MMAL_COMPONENT_PREVIEW]);
799
800 disable_camera(dev);
801 return ret;
802 }
803
804 /* set preview port format and connect it to output */
805 dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
806
807 ret = vchiq_mmal_port_set_format(dev->instance, src);
808 if (ret < 0)
809 goto error;
810
811 ret = set_overlay_params(dev, dst);
812 if (ret < 0)
813 goto error;
814
815 if (enable_camera(dev) < 0)
816 goto error;
817
818 ret = vchiq_mmal_component_enable(
819 dev->instance,
820 dev->component[MMAL_COMPONENT_PREVIEW]);
821 if (ret < 0)
822 goto error;
823
824 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
825 src, dst);
826 ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
827 if (!ret)
828 ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
829error:
830 return ret;
831}
832
833static int vidioc_g_fbuf(struct file *file, void *fh,
834 struct v4l2_framebuffer *a)
835{
836 /* The video overlay must stay within the framebuffer and can't be
837 positioned independently. */
838 struct bm2835_mmal_dev *dev = video_drvdata(file);
839 struct vchiq_mmal_port *preview_port =
840 &dev->component[MMAL_COMPONENT_CAMERA]->
841 output[MMAL_CAMERA_PORT_PREVIEW];
842
843 a->capability = V4L2_FBUF_CAP_EXTERNOVERLAY |
844 V4L2_FBUF_CAP_GLOBAL_ALPHA;
845 a->flags = V4L2_FBUF_FLAG_OVERLAY;
846 a->fmt.width = preview_port->es.video.width;
847 a->fmt.height = preview_port->es.video.height;
848 a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
849 a->fmt.bytesperline = preview_port->es.video.width;
850 a->fmt.sizeimage = (preview_port->es.video.width *
851 preview_port->es.video.height * 3) >> 1;
852 a->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
853
854 return 0;
855}
856
857/* input ioctls */
858static int vidioc_enum_input(struct file *file, void *priv,
859 struct v4l2_input *inp)
860{
861 /* only a single camera input */
862 if (inp->index != 0)
863 return -EINVAL;
864
865 inp->type = V4L2_INPUT_TYPE_CAMERA;
866 sprintf(inp->name, "Camera %u", inp->index);
867 return 0;
868}
869
870static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
871{
872 *i = 0;
873 return 0;
874}
875
876static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
877{
878 if (i != 0)
879 return -EINVAL;
880
881 return 0;
882}
883
884/* capture ioctls */
885static int vidioc_querycap(struct file *file, void *priv,
886 struct v4l2_capability *cap)
887{
888 struct bm2835_mmal_dev *dev = video_drvdata(file);
889 u32 major;
890 u32 minor;
891
892 vchiq_mmal_version(dev->instance, &major, &minor);
893
894 strcpy(cap->driver, "bm2835 mmal");
895 snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
896 major, minor);
897
898 snprintf(cap->bus_info, sizeof(cap->bus_info),
899 "platform:%s", dev->v4l2_dev.name);
900 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
901 V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
902 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
903
904 return 0;
905}
906
907static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
908 struct v4l2_fmtdesc *f)
909{
910 struct mmal_fmt *fmt;
911
912 if (f->index >= ARRAY_SIZE(formats))
913 return -EINVAL;
914
915 fmt = &formats[f->index];
916
917 strlcpy(f->description, fmt->name, sizeof(f->description));
918 f->pixelformat = fmt->fourcc;
919 f->flags = fmt->flags;
920
921 return 0;
922}
923
924static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
925 struct v4l2_format *f)
926{
927 struct bm2835_mmal_dev *dev = video_drvdata(file);
928
929 f->fmt.pix.width = dev->capture.width;
930 f->fmt.pix.height = dev->capture.height;
931 f->fmt.pix.field = V4L2_FIELD_NONE;
932 f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
933 f->fmt.pix.bytesperline = dev->capture.stride;
934 f->fmt.pix.sizeimage = dev->capture.buffersize;
935
936 if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
937 f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
938 else if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_JPEG)
939 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
940 else
941 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
942 f->fmt.pix.priv = 0;
943
944 v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
945 __func__);
946 return 0;
947}
948
949static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
950 struct v4l2_format *f)
951{
952 struct bm2835_mmal_dev *dev = video_drvdata(file);
953 struct mmal_fmt *mfmt;
954
955 mfmt = get_format(f);
956 if (!mfmt) {
957 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
958 "Fourcc format (0x%08x) unknown.\n",
959 f->fmt.pix.pixelformat);
960 f->fmt.pix.pixelformat = formats[0].fourcc;
961 mfmt = get_format(f);
962 }
963
964 f->fmt.pix.field = V4L2_FIELD_NONE;
965
966 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
967 "Clipping/aligning %dx%d format %08X\n",
968 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
969
970 v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, dev->max_width, 1,
971 &f->fmt.pix.height, MIN_HEIGHT, dev->max_height,
972 1, 0);
973 f->fmt.pix.bytesperline = f->fmt.pix.width * mfmt->ybbp;
974
975 /* Image buffer has to be padded to allow for alignment, even though
976 * we then remove that padding before delivering the buffer.
977 */
978 f->fmt.pix.sizeimage = ((f->fmt.pix.height + 15) & ~15) *
979 (((f->fmt.pix.width + 31) & ~31) * mfmt->depth) >> 3;
980
981 if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
982 f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
983 f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
984
985 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24)
986 f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
987 else if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
988 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
989 else
990 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
991 f->fmt.pix.priv = 0;
992
993 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
994 "Now %dx%d format %08X\n",
995 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
996
997 v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
998 __func__);
999 return 0;
1000}
1001
1002static int mmal_setup_components(struct bm2835_mmal_dev *dev,
1003 struct v4l2_format *f)
1004{
1005 int ret;
1006 struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
1007 struct vchiq_mmal_component *encode_component = NULL;
1008 struct mmal_fmt *mfmt = get_format(f);
1009
1010 BUG_ON(!mfmt);
1011
1012 if (dev->capture.encode_component) {
1013 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1014 "vid_cap - disconnect previous tunnel\n");
1015
1016 /* Disconnect any previous connection */
1017 vchiq_mmal_port_connect_tunnel(dev->instance,
1018 dev->capture.camera_port, NULL);
1019 dev->capture.camera_port = NULL;
1020 ret = vchiq_mmal_component_disable(dev->instance,
1021 dev->capture.
1022 encode_component);
1023 if (ret)
1024 v4l2_err(&dev->v4l2_dev,
1025 "Failed to disable encode component %d\n",
1026 ret);
1027
1028 dev->capture.encode_component = NULL;
1029 }
1030 /* format dependent port setup */
1031 switch (mfmt->mmal_component) {
1032 case MMAL_COMPONENT_CAMERA:
1033 /* Make a further decision on port based on resolution */
1034 if (f->fmt.pix.width <= max_video_width
1035 && f->fmt.pix.height <= max_video_height)
1036 camera_port = port =
1037 &dev->component[MMAL_COMPONENT_CAMERA]->
1038 output[MMAL_CAMERA_PORT_VIDEO];
1039 else
1040 camera_port = port =
1041 &dev->component[MMAL_COMPONENT_CAMERA]->
1042 output[MMAL_CAMERA_PORT_CAPTURE];
1043 break;
1044 case MMAL_COMPONENT_IMAGE_ENCODE:
1045 encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
1046 port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
1047 camera_port =
1048 &dev->component[MMAL_COMPONENT_CAMERA]->
1049 output[MMAL_CAMERA_PORT_CAPTURE];
1050 break;
1051 case MMAL_COMPONENT_VIDEO_ENCODE:
1052 encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
1053 port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
1054 camera_port =
1055 &dev->component[MMAL_COMPONENT_CAMERA]->
1056 output[MMAL_CAMERA_PORT_VIDEO];
1057 break;
1058 default:
1059 break;
1060 }
1061
1062 if (!port)
1063 return -EINVAL;
1064
1065 if (encode_component)
1066 camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
1067 else
1068 camera_port->format.encoding = mfmt->mmal;
1069
1070 if (dev->rgb_bgr_swapped) {
1071 if (camera_port->format.encoding == MMAL_ENCODING_RGB24)
1072 camera_port->format.encoding = MMAL_ENCODING_BGR24;
1073 else if (camera_port->format.encoding == MMAL_ENCODING_BGR24)
1074 camera_port->format.encoding = MMAL_ENCODING_RGB24;
1075 }
1076
1077 camera_port->format.encoding_variant = 0;
1078 camera_port->es.video.width = f->fmt.pix.width;
1079 camera_port->es.video.height = f->fmt.pix.height;
1080 camera_port->es.video.crop.x = 0;
1081 camera_port->es.video.crop.y = 0;
1082 camera_port->es.video.crop.width = f->fmt.pix.width;
1083 camera_port->es.video.crop.height = f->fmt.pix.height;
1084 camera_port->es.video.frame_rate.num = 0;
1085 camera_port->es.video.frame_rate.den = 1;
1086 camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
1087
1088 ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
1089
1090 if (!ret
1091 && camera_port ==
1092 &dev->component[MMAL_COMPONENT_CAMERA]->
1093 output[MMAL_CAMERA_PORT_VIDEO]) {
1094 bool overlay_enabled =
1095 !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
1096 struct vchiq_mmal_port *preview_port =
1097 &dev->component[MMAL_COMPONENT_CAMERA]->
1098 output[MMAL_CAMERA_PORT_PREVIEW];
1099 /* Preview and encode ports need to match on resolution */
1100 if (overlay_enabled) {
1101 /* Need to disable the overlay before we can update
1102 * the resolution
1103 */
1104 ret =
1105 vchiq_mmal_port_disable(dev->instance,
1106 preview_port);
1107 if (!ret)
1108 ret =
1109 vchiq_mmal_port_connect_tunnel(
1110 dev->instance,
1111 preview_port,
1112 NULL);
1113 }
1114 preview_port->es.video.width = f->fmt.pix.width;
1115 preview_port->es.video.height = f->fmt.pix.height;
1116 preview_port->es.video.crop.x = 0;
1117 preview_port->es.video.crop.y = 0;
1118 preview_port->es.video.crop.width = f->fmt.pix.width;
1119 preview_port->es.video.crop.height = f->fmt.pix.height;
1120 preview_port->es.video.frame_rate.num =
1121 dev->capture.timeperframe.denominator;
1122 preview_port->es.video.frame_rate.den =
1123 dev->capture.timeperframe.numerator;
1124 ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
1125 if (overlay_enabled) {
1126 ret = vchiq_mmal_port_connect_tunnel(
1127 dev->instance,
1128 preview_port,
1129 &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
1130 if (!ret)
1131 ret = vchiq_mmal_port_enable(dev->instance,
1132 preview_port,
1133 NULL);
1134 }
1135 }
1136
1137 if (ret) {
1138 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1139 "%s failed to set format %dx%d %08X\n", __func__,
1140 f->fmt.pix.width, f->fmt.pix.height,
1141 f->fmt.pix.pixelformat);
1142 /* ensure capture is not going to be tried */
1143 dev->capture.port = NULL;
1144 } else {
1145 if (encode_component) {
1146 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1147 "vid_cap - set up encode comp\n");
1148
1149 /* configure buffering */
1150 camera_port->current_buffer.size =
1151 camera_port->recommended_buffer.size;
1152 camera_port->current_buffer.num =
1153 camera_port->recommended_buffer.num;
1154
1155 ret =
1156 vchiq_mmal_port_connect_tunnel(
1157 dev->instance,
1158 camera_port,
1159 &encode_component->input[0]);
1160 if (ret) {
1161 v4l2_dbg(1, bcm2835_v4l2_debug,
1162 &dev->v4l2_dev,
1163 "%s failed to create connection\n",
1164 __func__);
1165 /* ensure capture is not going to be tried */
1166 dev->capture.port = NULL;
1167 } else {
1168 port->es.video.width = f->fmt.pix.width;
1169 port->es.video.height = f->fmt.pix.height;
1170 port->es.video.crop.x = 0;
1171 port->es.video.crop.y = 0;
1172 port->es.video.crop.width = f->fmt.pix.width;
1173 port->es.video.crop.height = f->fmt.pix.height;
1174 port->es.video.frame_rate.num =
1175 dev->capture.timeperframe.denominator;
1176 port->es.video.frame_rate.den =
1177 dev->capture.timeperframe.numerator;
1178
1179 port->format.encoding = mfmt->mmal;
1180 port->format.encoding_variant = 0;
1181 /* Set any encoding specific parameters */
1182 switch (mfmt->mmal_component) {
1183 case MMAL_COMPONENT_VIDEO_ENCODE:
1184 port->format.bitrate =
1185 dev->capture.encode_bitrate;
1186 break;
1187 case MMAL_COMPONENT_IMAGE_ENCODE:
1188 /* Could set EXIF parameters here */
1189 break;
1190 default:
1191 break;
1192 }
1193 ret = vchiq_mmal_port_set_format(dev->instance,
1194 port);
1195 if (ret)
1196 v4l2_dbg(1, bcm2835_v4l2_debug,
1197 &dev->v4l2_dev,
1198 "%s failed to set format %dx%d fmt %08X\n",
1199 __func__,
1200 f->fmt.pix.width,
1201 f->fmt.pix.height,
1202 f->fmt.pix.pixelformat
1203 );
1204 }
1205
1206 if (!ret) {
1207 ret = vchiq_mmal_component_enable(
1208 dev->instance,
1209 encode_component);
1210 if (ret) {
1211 v4l2_dbg(1, bcm2835_v4l2_debug,
1212 &dev->v4l2_dev,
1213 "%s Failed to enable encode components\n",
1214 __func__);
1215 }
1216 }
1217 if (!ret) {
1218 /* configure buffering */
1219 port->current_buffer.num = 1;
1220 port->current_buffer.size =
1221 f->fmt.pix.sizeimage;
1222 if (port->format.encoding ==
1223 MMAL_ENCODING_JPEG) {
1224 v4l2_dbg(1, bcm2835_v4l2_debug,
1225 &dev->v4l2_dev,
1226 "JPG - buf size now %d was %d\n",
1227 f->fmt.pix.sizeimage,
1228 port->current_buffer.size);
1229 port->current_buffer.size =
1230 (f->fmt.pix.sizeimage <
1231 (100 << 10))
1232 ? (100 << 10) : f->fmt.pix.
1233 sizeimage;
1234 }
1235 v4l2_dbg(1, bcm2835_v4l2_debug,
1236 &dev->v4l2_dev,
1237 "vid_cap - cur_buf.size set to %d\n",
1238 f->fmt.pix.sizeimage);
1239 port->current_buffer.alignment = 0;
1240 }
1241 } else {
1242 /* configure buffering */
1243 camera_port->current_buffer.num = 1;
1244 camera_port->current_buffer.size = f->fmt.pix.sizeimage;
1245 camera_port->current_buffer.alignment = 0;
1246 }
1247
1248 if (!ret) {
1249 dev->capture.fmt = mfmt;
1250 dev->capture.stride = f->fmt.pix.bytesperline;
1251 dev->capture.width = camera_port->es.video.crop.width;
1252 dev->capture.height = camera_port->es.video.crop.height;
1253 dev->capture.buffersize = port->current_buffer.size;
1254
1255 /* select port for capture */
1256 dev->capture.port = port;
1257 dev->capture.camera_port = camera_port;
1258 dev->capture.encode_component = encode_component;
1259 v4l2_dbg(1, bcm2835_v4l2_debug,
1260 &dev->v4l2_dev,
1261 "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
1262 port->format.encoding,
1263 dev->capture.width, dev->capture.height,
1264 dev->capture.stride, dev->capture.buffersize);
1265 }
1266 }
1267
1268 /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
1269 return ret;
1270}
1271
1272static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1273 struct v4l2_format *f)
1274{
1275 int ret;
1276 struct bm2835_mmal_dev *dev = video_drvdata(file);
1277 struct mmal_fmt *mfmt;
1278
1279 /* try the format to set valid parameters */
1280 ret = vidioc_try_fmt_vid_cap(file, priv, f);
1281 if (ret) {
1282 v4l2_err(&dev->v4l2_dev,
1283 "vid_cap - vidioc_try_fmt_vid_cap failed\n");
1284 return ret;
1285 }
1286
1287 /* if a capture is running refuse to set format */
1288 if (vb2_is_busy(&dev->capture.vb_vidq)) {
1289 v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
1290 return -EBUSY;
1291 }
1292
1293 /* If the format is unsupported v4l2 says we should switch to
1294 * a supported one and not return an error. */
1295 mfmt = get_format(f);
1296 if (!mfmt) {
1297 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1298 "Fourcc format (0x%08x) unknown.\n",
1299 f->fmt.pix.pixelformat);
1300 f->fmt.pix.pixelformat = formats[0].fourcc;
1301 mfmt = get_format(f);
1302 }
1303
1304 ret = mmal_setup_components(dev, f);
1305 if (ret != 0) {
1306 v4l2_err(&dev->v4l2_dev,
1307 "%s: failed to setup mmal components: %d\n",
1308 __func__, ret);
1309 ret = -EINVAL;
1310 }
1311
1312 return ret;
1313}
1314
1315static int vidioc_enum_framesizes(struct file *file, void *fh,
1316 struct v4l2_frmsizeenum *fsize)
1317{
1318 struct bm2835_mmal_dev *dev = video_drvdata(file);
1319 static const struct v4l2_frmsize_stepwise sizes = {
1320 MIN_WIDTH, 0, 2,
1321 MIN_HEIGHT, 0, 2
1322 };
1323 int i;
1324
1325 if (fsize->index)
1326 return -EINVAL;
1327 for (i = 0; i < ARRAY_SIZE(formats); i++)
1328 if (formats[i].fourcc == fsize->pixel_format)
1329 break;
1330 if (i == ARRAY_SIZE(formats))
1331 return -EINVAL;
1332 fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
1333 fsize->stepwise = sizes;
1334 fsize->stepwise.max_width = dev->max_width;
1335 fsize->stepwise.max_height = dev->max_height;
1336 return 0;
1337}
1338
1339/* timeperframe is arbitrary and continuous */
1340static int vidioc_enum_frameintervals(struct file *file, void *priv,
1341 struct v4l2_frmivalenum *fival)
1342{
1343 struct bm2835_mmal_dev *dev = video_drvdata(file);
1344 int i;
1345
1346 if (fival->index)
1347 return -EINVAL;
1348
1349 for (i = 0; i < ARRAY_SIZE(formats); i++)
1350 if (formats[i].fourcc == fival->pixel_format)
1351 break;
1352 if (i == ARRAY_SIZE(formats))
1353 return -EINVAL;
1354
1355 /* regarding width & height - we support any within range */
1356 if (fival->width < MIN_WIDTH || fival->width > dev->max_width ||
1357 fival->height < MIN_HEIGHT || fival->height > dev->max_height)
1358 return -EINVAL;
1359
1360 fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
1361
1362 /* fill in stepwise (step=1.0 is required by V4L2 spec) */
1363 fival->stepwise.min = tpf_min;
1364 fival->stepwise.max = tpf_max;
1365 fival->stepwise.step = (struct v4l2_fract) {1, 1};
1366
1367 return 0;
1368}
1369
1370static int vidioc_g_parm(struct file *file, void *priv,
1371 struct v4l2_streamparm *parm)
1372{
1373 struct bm2835_mmal_dev *dev = video_drvdata(file);
1374
1375 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1376 return -EINVAL;
1377
1378 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1379 parm->parm.capture.timeperframe = dev->capture.timeperframe;
1380 parm->parm.capture.readbuffers = 1;
1381 return 0;
1382}
1383
1384#define FRACT_CMP(a, OP, b) \
1385 ((u64)(a).numerator * (b).denominator OP \
1386 (u64)(b).numerator * (a).denominator)
1387
1388static int vidioc_s_parm(struct file *file, void *priv,
1389 struct v4l2_streamparm *parm)
1390{
1391 struct bm2835_mmal_dev *dev = video_drvdata(file);
1392 struct v4l2_fract tpf;
1393 struct mmal_parameter_rational fps_param;
1394
1395 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1396 return -EINVAL;
1397
1398 tpf = parm->parm.capture.timeperframe;
1399
1400 /* tpf: {*, 0} resets timing; clip to [min, max]*/
1401 tpf = tpf.denominator ? tpf : tpf_default;
1402 tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
1403 tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
1404
1405 dev->capture.timeperframe = tpf;
1406 parm->parm.capture.timeperframe = tpf;
1407 parm->parm.capture.readbuffers = 1;
1408 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1409
1410 fps_param.num = 0; /* Select variable fps, and then use
1411 * FPS_RANGE to select the actual limits.
1412 */
1413 fps_param.den = 1;
1414 set_framerate_params(dev);
1415
1416 return 0;
1417}
1418
1419static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
1420 /* overlay */
1421 .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
1422 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
1423 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
1424 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
1425 .vidioc_overlay = vidioc_overlay,
1426 .vidioc_g_fbuf = vidioc_g_fbuf,
1427
1428 /* inputs */
1429 .vidioc_enum_input = vidioc_enum_input,
1430 .vidioc_g_input = vidioc_g_input,
1431 .vidioc_s_input = vidioc_s_input,
1432
1433 /* capture */
1434 .vidioc_querycap = vidioc_querycap,
1435 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1436 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1437 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1438 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1439
1440 /* buffer management */
1441 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1442 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1443 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
1444 .vidioc_querybuf = vb2_ioctl_querybuf,
1445 .vidioc_qbuf = vb2_ioctl_qbuf,
1446 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1447 .vidioc_enum_framesizes = vidioc_enum_framesizes,
1448 .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
1449 .vidioc_g_parm = vidioc_g_parm,
1450 .vidioc_s_parm = vidioc_s_parm,
1451 .vidioc_streamon = vb2_ioctl_streamon,
1452 .vidioc_streamoff = vb2_ioctl_streamoff,
1453
1454 .vidioc_log_status = v4l2_ctrl_log_status,
1455 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1456 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1457};
1458
1459static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
1460 /* overlay */
1461 .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
1462 .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
1463 .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
1464 .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
1465 .vidioc_overlay = vidioc_overlay,
1466 .vidioc_g_fbuf = vidioc_g_fbuf,
1467
1468 /* inputs */
1469 .vidioc_enum_input = vidioc_enum_input,
1470 .vidioc_g_input = vidioc_g_input,
1471 .vidioc_s_input = vidioc_s_input,
1472
1473 /* capture */
1474 .vidioc_querycap = vidioc_querycap,
1475 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1476 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
1477 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1478 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
1479
1480 /* buffer management */
1481 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1482 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1483 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
1484 .vidioc_querybuf = vb2_ioctl_querybuf,
1485 .vidioc_qbuf = vb2_ioctl_qbuf,
1486 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1487 /* Remove this function ptr to fix gstreamer bug
1488 .vidioc_enum_framesizes = vidioc_enum_framesizes, */
1489 .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
1490 .vidioc_g_parm = vidioc_g_parm,
1491 .vidioc_s_parm = vidioc_s_parm,
1492 .vidioc_streamon = vb2_ioctl_streamon,
1493 .vidioc_streamoff = vb2_ioctl_streamoff,
1494
1495 .vidioc_log_status = v4l2_ctrl_log_status,
1496 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1497 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1498};
1499
1500/* ------------------------------------------------------------------
1501 Driver init/finalise
1502 ------------------------------------------------------------------*/
1503
1504static const struct v4l2_file_operations camera0_fops = {
1505 .owner = THIS_MODULE,
1506 .open = v4l2_fh_open,
1507 .release = vb2_fop_release,
1508 .read = vb2_fop_read,
1509 .poll = vb2_fop_poll,
1510 .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
1511 .mmap = vb2_fop_mmap,
1512};
1513
1514static struct video_device vdev_template = {
1515 .name = "camera0",
1516 .fops = &camera0_fops,
1517 .ioctl_ops = &camera0_ioctl_ops,
1518 .release = video_device_release_empty,
1519};
1520
1521/* Returns the number of cameras, and also the max resolution supported
1522 * by those cameras.
1523 */
1524static int get_num_cameras(struct vchiq_mmal_instance *instance,
1525 unsigned int resolutions[][2], int num_resolutions)
1526{
1527 int ret;
1528 struct vchiq_mmal_component *cam_info_component;
1529 struct mmal_parameter_camera_info_t cam_info = {0};
1530 int param_size = sizeof(cam_info);
1531 int i;
1532
1533 /* create a camera_info component */
1534 ret = vchiq_mmal_component_init(instance, "camera_info",
1535 &cam_info_component);
1536 if (ret < 0)
1537 /* Unusual failure - let's guess one camera. */
1538 return 1;
1539
1540 if (vchiq_mmal_port_parameter_get(instance,
1541 &cam_info_component->control,
1542 MMAL_PARAMETER_CAMERA_INFO,
1543 &cam_info,
1544 &param_size)) {
1545 pr_info("Failed to get camera info\n");
1546 }
1547 for (i = 0;
1548 i < (cam_info.num_cameras > num_resolutions ?
1549 num_resolutions :
1550 cam_info.num_cameras);
1551 i++) {
1552 resolutions[i][0] = cam_info.cameras[i].max_width;
1553 resolutions[i][1] = cam_info.cameras[i].max_height;
1554 }
1555
1556 vchiq_mmal_component_finalise(instance,
1557 cam_info_component);
1558
1559 return cam_info.num_cameras;
1560}
1561
1562static int set_camera_parameters(struct vchiq_mmal_instance *instance,
1563 struct vchiq_mmal_component *camera,
1564 struct bm2835_mmal_dev *dev)
1565{
1566 int ret;
1567 struct mmal_parameter_camera_config cam_config = {
1568 .max_stills_w = dev->max_width,
1569 .max_stills_h = dev->max_height,
1570 .stills_yuv422 = 1,
1571 .one_shot_stills = 1,
1572 .max_preview_video_w = (max_video_width > 1920) ?
1573 max_video_width : 1920,
1574 .max_preview_video_h = (max_video_height > 1088) ?
1575 max_video_height : 1088,
1576 .num_preview_video_frames = 3,
1577 .stills_capture_circular_buffer_height = 0,
1578 .fast_preview_resume = 0,
1579 .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
1580 };
1581
1582 ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
1583 MMAL_PARAMETER_CAMERA_CONFIG,
1584 &cam_config, sizeof(cam_config));
1585 return ret;
1586}
1587
1588#define MAX_SUPPORTED_ENCODINGS 20
1589
1590/* MMAL instance and component init */
1591static int __init mmal_init(struct bm2835_mmal_dev *dev)
1592{
1593 int ret;
1594 struct mmal_es_format *format;
1595 u32 bool_true = 1;
1596 u32 supported_encodings[MAX_SUPPORTED_ENCODINGS];
1597 int param_size;
1598 struct vchiq_mmal_component *camera;
1599
1600 ret = vchiq_mmal_init(&dev->instance);
1601 if (ret < 0)
1602 return ret;
1603
1604 /* get the camera component ready */
1605 ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
1606 &dev->component[MMAL_COMPONENT_CAMERA]);
1607 if (ret < 0)
1608 goto unreg_mmal;
1609
1610 camera = dev->component[MMAL_COMPONENT_CAMERA];
1611 if (camera->outputs < MMAL_CAMERA_PORT_COUNT) {
1612 ret = -EINVAL;
1613 goto unreg_camera;
1614 }
1615
1616 ret = set_camera_parameters(dev->instance,
1617 camera,
1618 dev);
1619 if (ret < 0)
1620 goto unreg_camera;
1621
1622 /* There was an error in the firmware that meant the camera component
1623 * produced BGR instead of RGB.
1624 * This is now fixed, but in order to support the old firmwares, we
1625 * have to check.
1626 */
1627 dev->rgb_bgr_swapped = true;
1628 param_size = sizeof(supported_encodings);
1629 ret = vchiq_mmal_port_parameter_get(dev->instance,
1630 &camera->output[MMAL_CAMERA_PORT_CAPTURE],
1631 MMAL_PARAMETER_SUPPORTED_ENCODINGS,
1632 &supported_encodings,
1633 &param_size);
1634 if (ret == 0) {
1635 int i;
1636
1637 for (i = 0; i < param_size / sizeof(u32); i++) {
1638 if (supported_encodings[i] == MMAL_ENCODING_BGR24) {
1639 /* Found BGR24 first - old firmware. */
1640 break;
1641 }
1642 if (supported_encodings[i] == MMAL_ENCODING_RGB24) {
1643 /* Found RGB24 first
1644 * new firmware, so use RGB24.
1645 */
1646 dev->rgb_bgr_swapped = false;
1647 break;
1648 }
1649 }
1650 }
1651 format = &camera->output[MMAL_CAMERA_PORT_PREVIEW].format;
1652
1653 format->encoding = MMAL_ENCODING_OPAQUE;
1654 format->encoding_variant = MMAL_ENCODING_I420;
1655
1656 format->es->video.width = 1024;
1657 format->es->video.height = 768;
1658 format->es->video.crop.x = 0;
1659 format->es->video.crop.y = 0;
1660 format->es->video.crop.width = 1024;
1661 format->es->video.crop.height = 768;
1662 format->es->video.frame_rate.num = 0; /* Rely on fps_range */
1663 format->es->video.frame_rate.den = 1;
1664
1665 format = &camera->output[MMAL_CAMERA_PORT_VIDEO].format;
1666
1667 format->encoding = MMAL_ENCODING_OPAQUE;
1668 format->encoding_variant = MMAL_ENCODING_I420;
1669
1670 format->es->video.width = 1024;
1671 format->es->video.height = 768;
1672 format->es->video.crop.x = 0;
1673 format->es->video.crop.y = 0;
1674 format->es->video.crop.width = 1024;
1675 format->es->video.crop.height = 768;
1676 format->es->video.frame_rate.num = 0; /* Rely on fps_range */
1677 format->es->video.frame_rate.den = 1;
1678
1679 vchiq_mmal_port_parameter_set(dev->instance,
1680 &camera->output[MMAL_CAMERA_PORT_VIDEO],
1681 MMAL_PARAMETER_NO_IMAGE_PADDING,
1682 &bool_true, sizeof(bool_true));
1683
1684 format = &camera->output[MMAL_CAMERA_PORT_CAPTURE].format;
1685
1686 format->encoding = MMAL_ENCODING_OPAQUE;
1687
1688 format->es->video.width = 2592;
1689 format->es->video.height = 1944;
1690 format->es->video.crop.x = 0;
1691 format->es->video.crop.y = 0;
1692 format->es->video.crop.width = 2592;
1693 format->es->video.crop.height = 1944;
1694 format->es->video.frame_rate.num = 0; /* Rely on fps_range */
1695 format->es->video.frame_rate.den = 1;
1696
1697 dev->capture.width = format->es->video.width;
1698 dev->capture.height = format->es->video.height;
1699 dev->capture.fmt = &formats[0];
1700 dev->capture.encode_component = NULL;
1701 dev->capture.timeperframe = tpf_default;
1702 dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
1703 dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
1704
1705 vchiq_mmal_port_parameter_set(dev->instance,
1706 &camera->output[MMAL_CAMERA_PORT_CAPTURE],
1707 MMAL_PARAMETER_NO_IMAGE_PADDING,
1708 &bool_true, sizeof(bool_true));
1709
1710 /* get the preview component ready */
1711 ret = vchiq_mmal_component_init(
1712 dev->instance, "ril.video_render",
1713 &dev->component[MMAL_COMPONENT_PREVIEW]);
1714 if (ret < 0)
1715 goto unreg_camera;
1716
1717 if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
1718 ret = -EINVAL;
1719 pr_debug("too few input ports %d needed %d\n",
1720 dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
1721 goto unreg_preview;
1722 }
1723
1724 /* get the image encoder component ready */
1725 ret = vchiq_mmal_component_init(
1726 dev->instance, "ril.image_encode",
1727 &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
1728 if (ret < 0)
1729 goto unreg_preview;
1730
1731 if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
1732 ret = -EINVAL;
1733 v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
1734 dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
1735 1);
1736 goto unreg_image_encoder;
1737 }
1738
1739 /* get the video encoder component ready */
1740 ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
1741 &dev->
1742 component[MMAL_COMPONENT_VIDEO_ENCODE]);
1743 if (ret < 0)
1744 goto unreg_image_encoder;
1745
1746 if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
1747 ret = -EINVAL;
1748 v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
1749 dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
1750 1);
1751 goto unreg_vid_encoder;
1752 }
1753
1754 {
1755 struct vchiq_mmal_port *encoder_port =
1756 &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
1757 encoder_port->format.encoding = MMAL_ENCODING_H264;
1758 ret = vchiq_mmal_port_set_format(dev->instance,
1759 encoder_port);
1760 }
1761
1762 {
1763 unsigned int enable = 1;
1764
1765 vchiq_mmal_port_parameter_set(
1766 dev->instance,
1767 &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
1768 MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
1769 &enable, sizeof(enable));
1770
1771 vchiq_mmal_port_parameter_set(dev->instance,
1772 &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
1773 MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
1774 &enable,
1775 sizeof(enable));
1776 }
1777 ret = bm2835_mmal_set_all_camera_controls(dev);
1778 if (ret < 0)
1779 goto unreg_vid_encoder;
1780
1781 return 0;
1782
1783unreg_vid_encoder:
1784 pr_err("Cleanup: Destroy video encoder\n");
1785 vchiq_mmal_component_finalise(
1786 dev->instance,
1787 dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
1788
1789unreg_image_encoder:
1790 pr_err("Cleanup: Destroy image encoder\n");
1791 vchiq_mmal_component_finalise(
1792 dev->instance,
1793 dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
1794
1795unreg_preview:
1796 pr_err("Cleanup: Destroy video render\n");
1797 vchiq_mmal_component_finalise(dev->instance,
1798 dev->component[MMAL_COMPONENT_PREVIEW]);
1799
1800unreg_camera:
1801 pr_err("Cleanup: Destroy camera\n");
1802 vchiq_mmal_component_finalise(dev->instance,
1803 dev->component[MMAL_COMPONENT_CAMERA]);
1804
1805unreg_mmal:
1806 vchiq_mmal_finalise(dev->instance);
1807 return ret;
1808}
1809
1810static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
1811 struct video_device *vfd)
1812{
1813 int ret;
1814
1815 *vfd = vdev_template;
1816 if (gst_v4l2src_is_broken) {
1817 v4l2_info(&dev->v4l2_dev,
1818 "Work-around for gstreamer issue is active.\n");
1819 vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
1820 }
1821
1822 vfd->v4l2_dev = &dev->v4l2_dev;
1823
1824 vfd->lock = &dev->mutex;
1825
1826 vfd->queue = &dev->capture.vb_vidq;
1827
1828 /* video device needs to be able to access instance data */
1829 video_set_drvdata(vfd, dev);
1830
1831 ret = video_register_device(vfd,
1832 VFL_TYPE_GRABBER,
1833 video_nr[dev->camera_num]);
1834 if (ret < 0)
1835 return ret;
1836
1837 v4l2_info(vfd->v4l2_dev,
1838 "V4L2 device registered as %s - stills mode > %dx%d\n",
1839 video_device_node_name(vfd),
1840 max_video_width, max_video_height);
1841
1842 return 0;
1843}
1844
1845static void bcm2835_cleanup_instance(struct bm2835_mmal_dev *dev)
1846{
1847 if (!dev)
1848 return;
1849
1850 v4l2_info(&dev->v4l2_dev, "unregistering %s\n",
1851 video_device_node_name(&dev->vdev));
1852
1853 video_unregister_device(&dev->vdev);
1854
1855 if (dev->capture.encode_component) {
1856 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1857 "mmal_exit - disconnect tunnel\n");
1858 vchiq_mmal_port_connect_tunnel(dev->instance,
1859 dev->capture.camera_port, NULL);
1860 vchiq_mmal_component_disable(dev->instance,
1861 dev->capture.encode_component);
1862 }
1863 vchiq_mmal_component_disable(dev->instance,
1864 dev->component[MMAL_COMPONENT_CAMERA]);
1865
1866 vchiq_mmal_component_finalise(dev->instance,
1867 dev->
1868 component[MMAL_COMPONENT_VIDEO_ENCODE]);
1869
1870 vchiq_mmal_component_finalise(dev->instance,
1871 dev->
1872 component[MMAL_COMPONENT_IMAGE_ENCODE]);
1873
1874 vchiq_mmal_component_finalise(dev->instance,
1875 dev->component[MMAL_COMPONENT_PREVIEW]);
1876
1877 vchiq_mmal_component_finalise(dev->instance,
1878 dev->component[MMAL_COMPONENT_CAMERA]);
1879
1880 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1881
1882 v4l2_device_unregister(&dev->v4l2_dev);
1883
1884 kfree(dev);
1885}
1886
1887static struct v4l2_format default_v4l2_format = {
1888 .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
1889 .fmt.pix.width = 1024,
1890 .fmt.pix.bytesperline = 0,
1891 .fmt.pix.height = 768,
1892 .fmt.pix.sizeimage = 1024 * 768,
1893};
1894
1895static int __init bm2835_mmal_init(void)
1896{
1897 int ret;
1898 struct bm2835_mmal_dev *dev;
1899 struct vb2_queue *q;
1900 int camera;
1901 unsigned int num_cameras;
1902 struct vchiq_mmal_instance *instance;
1903 unsigned int resolutions[MAX_BCM2835_CAMERAS][2];
1904
1905 ret = vchiq_mmal_init(&instance);
1906 if (ret < 0)
1907 return ret;
1908
1909 num_cameras = get_num_cameras(instance,
1910 resolutions,
1911 MAX_BCM2835_CAMERAS);
1912 if (num_cameras > MAX_BCM2835_CAMERAS)
1913 num_cameras = MAX_BCM2835_CAMERAS;
1914
1915 for (camera = 0; camera < num_cameras; camera++) {
1916 dev = kzalloc(sizeof(struct bm2835_mmal_dev), GFP_KERNEL);
1917 if (!dev)
1918 return -ENOMEM;
1919
1920 dev->camera_num = camera;
1921 dev->max_width = resolutions[camera][0];
1922 dev->max_height = resolutions[camera][1];
1923
1924 /* setup device defaults */
1925 dev->overlay.w.left = 150;
1926 dev->overlay.w.top = 50;
1927 dev->overlay.w.width = 1024;
1928 dev->overlay.w.height = 768;
1929 dev->overlay.clipcount = 0;
1930 dev->overlay.field = V4L2_FIELD_NONE;
1931 dev->overlay.global_alpha = 255;
1932
1933 dev->capture.fmt = &formats[3]; /* JPEG */
1934
1935 /* v4l device registration */
1936 snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
1937 "%s", BM2835_MMAL_MODULE_NAME);
1938 ret = v4l2_device_register(NULL, &dev->v4l2_dev);
1939 if (ret)
1940 goto free_dev;
1941
1942 /* setup v4l controls */
1943 ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
1944 if (ret < 0)
1945 goto unreg_dev;
1946 dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
1947
1948 /* mmal init */
1949 dev->instance = instance;
1950 ret = mmal_init(dev);
1951 if (ret < 0)
1952 goto unreg_dev;
1953
1954 /* initialize queue */
1955 q = &dev->capture.vb_vidq;
1956 memset(q, 0, sizeof(*q));
1957 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1958 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1959 q->drv_priv = dev;
1960 q->buf_struct_size = sizeof(struct mmal_buffer);
1961 q->ops = &bm2835_mmal_video_qops;
1962 q->mem_ops = &vb2_vmalloc_memops;
1963 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1964 ret = vb2_queue_init(q);
1965 if (ret < 0)
1966 goto unreg_dev;
1967
1968 /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
1969 mutex_init(&dev->mutex);
1970
1971 /* initialise video devices */
1972 ret = bm2835_mmal_init_device(dev, &dev->vdev);
1973 if (ret < 0)
1974 goto unreg_dev;
1975
1976 /* Really want to call vidioc_s_fmt_vid_cap with the default
1977 * format, but currently the APIs don't join up.
1978 */
1979 ret = mmal_setup_components(dev, &default_v4l2_format);
1980 if (ret < 0) {
1981 v4l2_err(&dev->v4l2_dev,
1982 "%s: could not setup components\n", __func__);
1983 goto unreg_dev;
1984 }
1985
1986 v4l2_info(&dev->v4l2_dev,
1987 "Broadcom 2835 MMAL video capture ver %s loaded.\n",
1988 BM2835_MMAL_VERSION);
1989
1990 gdev[camera] = dev;
1991 }
1992 return 0;
1993
1994unreg_dev:
1995 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1996 v4l2_device_unregister(&dev->v4l2_dev);
1997
1998free_dev:
1999 kfree(dev);
2000
2001 for ( ; camera > 0; camera--) {
2002 bcm2835_cleanup_instance(gdev[camera]);
2003 gdev[camera] = NULL;
2004 }
2005 pr_info("%s: error %d while loading driver\n",
2006 BM2835_MMAL_MODULE_NAME, ret);
2007
2008 return ret;
2009}
2010
2011static void __exit bm2835_mmal_exit(void)
2012{
2013 int camera;
2014 struct vchiq_mmal_instance *instance = gdev[0]->instance;
2015
2016 for (camera = 0; camera < MAX_BCM2835_CAMERAS; camera++) {
2017 bcm2835_cleanup_instance(gdev[camera]);
2018 gdev[camera] = NULL;
2019 }
2020 vchiq_mmal_finalise(instance);
2021}
2022
2023module_init(bm2835_mmal_init);
2024module_exit(bm2835_mmal_exit);
diff --git a/drivers/staging/media/platform/bcm2835/bcm2835-camera.h b/drivers/staging/media/platform/bcm2835/bcm2835-camera.h
new file mode 100644
index 000000000000..e6aeb7e7e381
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/bcm2835-camera.h
@@ -0,0 +1,145 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 *
15 * core driver device
16 */
17
18#define V4L2_CTRL_COUNT 29 /* number of v4l controls */
19
20enum {
21 MMAL_COMPONENT_CAMERA = 0,
22 MMAL_COMPONENT_PREVIEW,
23 MMAL_COMPONENT_IMAGE_ENCODE,
24 MMAL_COMPONENT_VIDEO_ENCODE,
25 MMAL_COMPONENT_COUNT
26};
27
28enum {
29 MMAL_CAMERA_PORT_PREVIEW = 0,
30 MMAL_CAMERA_PORT_VIDEO,
31 MMAL_CAMERA_PORT_CAPTURE,
32 MMAL_CAMERA_PORT_COUNT
33};
34
35#define PREVIEW_LAYER 2
36
37extern int bcm2835_v4l2_debug;
38
39struct bm2835_mmal_dev {
40 /* v4l2 devices */
41 struct v4l2_device v4l2_dev;
42 struct video_device vdev;
43 struct mutex mutex;
44
45 /* controls */
46 struct v4l2_ctrl_handler ctrl_handler;
47 struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
48 enum v4l2_scene_mode scene_mode;
49 struct mmal_colourfx colourfx;
50 int hflip;
51 int vflip;
52 int red_gain;
53 int blue_gain;
54 enum mmal_parameter_exposuremode exposure_mode_user;
55 enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
56 /* active exposure mode may differ if selected via a scene mode */
57 enum mmal_parameter_exposuremode exposure_mode_active;
58 enum mmal_parameter_exposuremeteringmode metering_mode;
59 unsigned int manual_shutter_speed;
60 bool exp_auto_priority;
61 bool manual_iso_enabled;
62 uint32_t iso;
63
64 /* allocated mmal instance and components */
65 struct vchiq_mmal_instance *instance;
66 struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
67 int camera_use_count;
68
69 struct v4l2_window overlay;
70
71 struct {
72 unsigned int width; /* width */
73 unsigned int height; /* height */
74 unsigned int stride; /* stride */
75 unsigned int buffersize; /* buffer size with padding */
76 struct mmal_fmt *fmt;
77 struct v4l2_fract timeperframe;
78
79 /* H264 encode bitrate */
80 int encode_bitrate;
81 /* H264 bitrate mode. CBR/VBR */
82 int encode_bitrate_mode;
83 /* H264 profile */
84 enum v4l2_mpeg_video_h264_profile enc_profile;
85 /* H264 level */
86 enum v4l2_mpeg_video_h264_level enc_level;
87 /* JPEG Q-factor */
88 int q_factor;
89
90 struct vb2_queue vb_vidq;
91
92 /* VC start timestamp for streaming */
93 s64 vc_start_timestamp;
94 /* Kernel start timestamp for streaming */
95 struct timeval kernel_start_ts;
96
97 struct vchiq_mmal_port *port; /* port being used for capture */
98 /* camera port being used for capture */
99 struct vchiq_mmal_port *camera_port;
100 /* component being used for encode */
101 struct vchiq_mmal_component *encode_component;
102 /* number of frames remaining which driver should capture */
103 unsigned int frame_count;
104 /* last frame completion */
105 struct completion frame_cmplt;
106
107 } capture;
108
109 unsigned int camera_num;
110 unsigned int max_width;
111 unsigned int max_height;
112 unsigned int rgb_bgr_swapped;
113};
114
115int bm2835_mmal_init_controls(
116 struct bm2835_mmal_dev *dev,
117 struct v4l2_ctrl_handler *hdl);
118
119int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
120int set_framerate_params(struct bm2835_mmal_dev *dev);
121
122/* Debug helpers */
123
124#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
125{ \
126 v4l2_dbg(level, debug, dev, \
127"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
128 desc == NULL ? "" : desc, \
129 (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
130 (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
131 (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
132}
133#define v4l2_dump_win_format(level, debug, dev, win_fmt, desc) \
134{ \
135 v4l2_dbg(level, debug, dev, \
136"%s: w %u h %u l %u t %u field %u chromakey %06X clip %p " \
137"clipcount %u bitmap %p\n", \
138 desc == NULL ? "" : desc, \
139 (win_fmt)->w.width, (win_fmt)->w.height, \
140 (win_fmt)->w.left, (win_fmt)->w.top, \
141 (win_fmt)->field, \
142 (win_fmt)->chromakey, \
143 (win_fmt)->clips, (win_fmt)->clipcount, \
144 (win_fmt)->bitmap); \
145}
diff --git a/drivers/staging/media/platform/bcm2835/controls.c b/drivers/staging/media/platform/bcm2835/controls.c
new file mode 100644
index 000000000000..a40987b2e75d
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/controls.c
@@ -0,0 +1,1335 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15
16#include <linux/errno.h>
17#include <linux/kernel.h>
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <media/videobuf2-vmalloc.h>
21#include <media/v4l2-device.h>
22#include <media/v4l2-ioctl.h>
23#include <media/v4l2-ctrls.h>
24#include <media/v4l2-fh.h>
25#include <media/v4l2-event.h>
26#include <media/v4l2-common.h>
27
28#include "mmal-common.h"
29#include "mmal-vchiq.h"
30#include "mmal-parameters.h"
31#include "bcm2835-camera.h"
32
33/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
34 * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
35 * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
36 * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
37 * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
38 * -4 to +4
39 */
40static const s64 ev_bias_qmenu[] = {
41 -4000, -3667, -3333,
42 -3000, -2667, -2333,
43 -2000, -1667, -1333,
44 -1000, -667, -333,
45 0, 333, 667,
46 1000, 1333, 1667,
47 2000, 2333, 2667,
48 3000, 3333, 3667,
49 4000
50};
51
52/* Supported ISO values (*1000)
53 * ISOO = auto ISO
54 */
55static const s64 iso_qmenu[] = {
56 0, 100000, 200000, 400000, 800000,
57};
58static const uint32_t iso_values[] = {
59 0, 100, 200, 400, 800,
60};
61
62static const s64 mains_freq_qmenu[] = {
63 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
64 V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
65 V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
66 V4L2_CID_POWER_LINE_FREQUENCY_AUTO
67};
68
69/* Supported video encode modes */
70static const s64 bitrate_mode_qmenu[] = {
71 (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
72 (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
73};
74
75enum bm2835_mmal_ctrl_type {
76 MMAL_CONTROL_TYPE_STD,
77 MMAL_CONTROL_TYPE_STD_MENU,
78 MMAL_CONTROL_TYPE_INT_MENU,
79 MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
80};
81
82struct bm2835_mmal_v4l2_ctrl;
83
84typedef int(bm2835_mmal_v4l2_ctrl_cb)(
85 struct bm2835_mmal_dev *dev,
86 struct v4l2_ctrl *ctrl,
87 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
88
89struct bm2835_mmal_v4l2_ctrl {
90 u32 id; /* v4l2 control identifier */
91 enum bm2835_mmal_ctrl_type type;
92 /* control minimum value or
93 * mask for MMAL_CONTROL_TYPE_STD_MENU */
94 s32 min;
95 s32 max; /* maximum value of control */
96 s32 def; /* default value of control */
97 s32 step; /* step size of the control */
98 const s64 *imenu; /* integer menu array */
99 u32 mmal_id; /* mmal parameter id */
100 bm2835_mmal_v4l2_ctrl_cb *setter;
101 bool ignore_errors;
102};
103
104struct v4l2_to_mmal_effects_setting {
105 u32 v4l2_effect;
106 u32 mmal_effect;
107 s32 col_fx_enable;
108 s32 col_fx_fixed_cbcr;
109 u32 u;
110 u32 v;
111 u32 num_effect_params;
112 u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
113};
114
115static const struct v4l2_to_mmal_effects_setting
116 v4l2_to_mmal_effects_values[] = {
117 { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
118 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
119 { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
120 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
121 { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
122 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
123 { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
124 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
125 { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
126 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
127 { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
128 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
129 { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
130 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
131 { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
132 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
133 { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
134 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
135 { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
136 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
137 { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
138 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
139 { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
140 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
141 { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
142 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
143 { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
144 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
145 { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
146 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
147 { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
148 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
149};
150
151struct v4l2_mmal_scene_config {
152 enum v4l2_scene_mode v4l2_scene;
153 enum mmal_parameter_exposuremode exposure_mode;
154 enum mmal_parameter_exposuremeteringmode metering_mode;
155};
156
157static const struct v4l2_mmal_scene_config scene_configs[] = {
158 /* V4L2_SCENE_MODE_NONE automatically added */
159 {
160 V4L2_SCENE_MODE_NIGHT,
161 MMAL_PARAM_EXPOSUREMODE_NIGHT,
162 MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
163 },
164 {
165 V4L2_SCENE_MODE_SPORTS,
166 MMAL_PARAM_EXPOSUREMODE_SPORTS,
167 MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
168 },
169};
170
171/* control handlers*/
172
173static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
174 struct v4l2_ctrl *ctrl,
175 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
176{
177 struct mmal_parameter_rational rational_value;
178 struct vchiq_mmal_port *control;
179
180 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
181
182 rational_value.num = ctrl->val;
183 rational_value.den = 100;
184
185 return vchiq_mmal_port_parameter_set(dev->instance, control,
186 mmal_ctrl->mmal_id,
187 &rational_value,
188 sizeof(rational_value));
189}
190
191static int ctrl_set_value(struct bm2835_mmal_dev *dev,
192 struct v4l2_ctrl *ctrl,
193 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
194{
195 u32 u32_value;
196 struct vchiq_mmal_port *control;
197
198 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
199
200 u32_value = ctrl->val;
201
202 return vchiq_mmal_port_parameter_set(dev->instance, control,
203 mmal_ctrl->mmal_id,
204 &u32_value, sizeof(u32_value));
205}
206
207static int ctrl_set_iso(struct bm2835_mmal_dev *dev,
208 struct v4l2_ctrl *ctrl,
209 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
210{
211 u32 u32_value;
212 struct vchiq_mmal_port *control;
213
214 if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
215 return 1;
216
217 if (ctrl->id == V4L2_CID_ISO_SENSITIVITY)
218 dev->iso = iso_values[ctrl->val];
219 else if (ctrl->id == V4L2_CID_ISO_SENSITIVITY_AUTO)
220 dev->manual_iso_enabled =
221 (ctrl->val == V4L2_ISO_SENSITIVITY_MANUAL ?
222 true :
223 false);
224
225 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
226
227 if (dev->manual_iso_enabled)
228 u32_value = dev->iso;
229 else
230 u32_value = 0;
231
232 return vchiq_mmal_port_parameter_set(dev->instance, control,
233 MMAL_PARAMETER_ISO,
234 &u32_value, sizeof(u32_value));
235}
236
237static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
238 struct v4l2_ctrl *ctrl,
239 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
240{
241 s32 s32_value;
242 struct vchiq_mmal_port *control;
243
244 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
245
246 s32_value = (ctrl->val - 12) * 2; /* Convert from index to 1/6ths */
247
248 return vchiq_mmal_port_parameter_set(dev->instance, control,
249 mmal_ctrl->mmal_id,
250 &s32_value, sizeof(s32_value));
251}
252
253static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
254 struct v4l2_ctrl *ctrl,
255 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
256{
257 int ret;
258 u32 u32_value;
259 struct vchiq_mmal_component *camera;
260
261 camera = dev->component[MMAL_COMPONENT_CAMERA];
262
263 u32_value = ((ctrl->val % 360) / 90) * 90;
264
265 ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
266 mmal_ctrl->mmal_id,
267 &u32_value, sizeof(u32_value));
268 if (ret < 0)
269 return ret;
270
271 ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
272 mmal_ctrl->mmal_id,
273 &u32_value, sizeof(u32_value));
274 if (ret < 0)
275 return ret;
276
277 ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
278 mmal_ctrl->mmal_id,
279 &u32_value, sizeof(u32_value));
280
281 return ret;
282}
283
284static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
285 struct v4l2_ctrl *ctrl,
286 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
287{
288 int ret;
289 u32 u32_value;
290 struct vchiq_mmal_component *camera;
291
292 if (ctrl->id == V4L2_CID_HFLIP)
293 dev->hflip = ctrl->val;
294 else
295 dev->vflip = ctrl->val;
296
297 camera = dev->component[MMAL_COMPONENT_CAMERA];
298
299 if (dev->hflip && dev->vflip)
300 u32_value = MMAL_PARAM_MIRROR_BOTH;
301 else if (dev->hflip)
302 u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
303 else if (dev->vflip)
304 u32_value = MMAL_PARAM_MIRROR_VERTICAL;
305 else
306 u32_value = MMAL_PARAM_MIRROR_NONE;
307
308 ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
309 mmal_ctrl->mmal_id,
310 &u32_value, sizeof(u32_value));
311 if (ret < 0)
312 return ret;
313
314 ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
315 mmal_ctrl->mmal_id,
316 &u32_value, sizeof(u32_value));
317 if (ret < 0)
318 return ret;
319
320 ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
321 mmal_ctrl->mmal_id,
322 &u32_value, sizeof(u32_value));
323
324 return ret;
325}
326
327static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
328 struct v4l2_ctrl *ctrl,
329 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
330{
331 enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
332 u32 shutter_speed = 0;
333 struct vchiq_mmal_port *control;
334 int ret = 0;
335
336 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
337
338 if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
339 /* V4L2 is in 100usec increments.
340 * MMAL is 1usec.
341 */
342 dev->manual_shutter_speed = ctrl->val * 100;
343 } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
344 switch (ctrl->val) {
345 case V4L2_EXPOSURE_AUTO:
346 exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
347 break;
348
349 case V4L2_EXPOSURE_MANUAL:
350 exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
351 break;
352 }
353 dev->exposure_mode_user = exp_mode;
354 dev->exposure_mode_v4l2_user = ctrl->val;
355 } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
356 dev->exp_auto_priority = ctrl->val;
357 }
358
359 if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
360 if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
361 shutter_speed = dev->manual_shutter_speed;
362
363 ret = vchiq_mmal_port_parameter_set(dev->instance,
364 control,
365 MMAL_PARAMETER_SHUTTER_SPEED,
366 &shutter_speed,
367 sizeof(shutter_speed));
368 ret += vchiq_mmal_port_parameter_set(dev->instance,
369 control,
370 MMAL_PARAMETER_EXPOSURE_MODE,
371 &exp_mode,
372 sizeof(u32));
373 dev->exposure_mode_active = exp_mode;
374 }
375 /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
376 * always apply irrespective of scene mode.
377 */
378 ret += set_framerate_params(dev);
379
380 return ret;
381}
382
383static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
384 struct v4l2_ctrl *ctrl,
385 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
386{
387 switch (ctrl->val) {
388 case V4L2_EXPOSURE_METERING_AVERAGE:
389 dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
390 break;
391
392 case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
393 dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
394 break;
395
396 case V4L2_EXPOSURE_METERING_SPOT:
397 dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
398 break;
399
400 /* todo matrix weighting not added to Linux API till 3.9
401 case V4L2_EXPOSURE_METERING_MATRIX:
402 dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
403 break;
404 */
405 }
406
407 if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
408 struct vchiq_mmal_port *control;
409 u32 u32_value = dev->metering_mode;
410
411 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
412
413 return vchiq_mmal_port_parameter_set(dev->instance, control,
414 mmal_ctrl->mmal_id,
415 &u32_value, sizeof(u32_value));
416 } else
417 return 0;
418}
419
420static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
421 struct v4l2_ctrl *ctrl,
422 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
423{
424 u32 u32_value;
425 struct vchiq_mmal_port *control;
426
427 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
428
429 switch (ctrl->val) {
430 case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
431 u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
432 break;
433 case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
434 u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
435 break;
436 case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
437 u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
438 break;
439 case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
440 u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
441 break;
442 }
443
444 return vchiq_mmal_port_parameter_set(dev->instance, control,
445 mmal_ctrl->mmal_id,
446 &u32_value, sizeof(u32_value));
447}
448
449static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
450 struct v4l2_ctrl *ctrl,
451 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
452{
453 u32 u32_value;
454 struct vchiq_mmal_port *control;
455
456 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
457
458 switch (ctrl->val) {
459 case V4L2_WHITE_BALANCE_MANUAL:
460 u32_value = MMAL_PARAM_AWBMODE_OFF;
461 break;
462
463 case V4L2_WHITE_BALANCE_AUTO:
464 u32_value = MMAL_PARAM_AWBMODE_AUTO;
465 break;
466
467 case V4L2_WHITE_BALANCE_INCANDESCENT:
468 u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
469 break;
470
471 case V4L2_WHITE_BALANCE_FLUORESCENT:
472 u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
473 break;
474
475 case V4L2_WHITE_BALANCE_FLUORESCENT_H:
476 u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
477 break;
478
479 case V4L2_WHITE_BALANCE_HORIZON:
480 u32_value = MMAL_PARAM_AWBMODE_HORIZON;
481 break;
482
483 case V4L2_WHITE_BALANCE_DAYLIGHT:
484 u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
485 break;
486
487 case V4L2_WHITE_BALANCE_FLASH:
488 u32_value = MMAL_PARAM_AWBMODE_FLASH;
489 break;
490
491 case V4L2_WHITE_BALANCE_CLOUDY:
492 u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
493 break;
494
495 case V4L2_WHITE_BALANCE_SHADE:
496 u32_value = MMAL_PARAM_AWBMODE_SHADE;
497 break;
498 }
499
500 return vchiq_mmal_port_parameter_set(dev->instance, control,
501 mmal_ctrl->mmal_id,
502 &u32_value, sizeof(u32_value));
503}
504
505static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
506 struct v4l2_ctrl *ctrl,
507 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
508{
509 struct vchiq_mmal_port *control;
510 struct mmal_parameter_awbgains gains;
511
512 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
513
514 if (ctrl->id == V4L2_CID_RED_BALANCE)
515 dev->red_gain = ctrl->val;
516 else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
517 dev->blue_gain = ctrl->val;
518
519 gains.r_gain.num = dev->red_gain;
520 gains.b_gain.num = dev->blue_gain;
521 gains.r_gain.den = gains.b_gain.den = 1000;
522
523 return vchiq_mmal_port_parameter_set(dev->instance, control,
524 mmal_ctrl->mmal_id,
525 &gains, sizeof(gains));
526}
527
528static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
529 struct v4l2_ctrl *ctrl,
530 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
531{
532 int ret = -EINVAL;
533 int i, j;
534 struct vchiq_mmal_port *control;
535 struct mmal_parameter_imagefx_parameters imagefx;
536
537 for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
538 if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
539 imagefx.effect =
540 v4l2_to_mmal_effects_values[i].mmal_effect;
541 imagefx.num_effect_params =
542 v4l2_to_mmal_effects_values[i].num_effect_params;
543
544 if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
545 imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
546
547 for (j = 0; j < imagefx.num_effect_params; j++)
548 imagefx.effect_parameter[j] =
549 v4l2_to_mmal_effects_values[i].effect_params[j];
550
551 dev->colourfx.enable =
552 v4l2_to_mmal_effects_values[i].col_fx_enable;
553 if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
554 dev->colourfx.u =
555 v4l2_to_mmal_effects_values[i].u;
556 dev->colourfx.v =
557 v4l2_to_mmal_effects_values[i].v;
558 }
559
560 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
561
562 ret = vchiq_mmal_port_parameter_set(
563 dev->instance, control,
564 MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
565 &imagefx, sizeof(imagefx));
566 if (ret)
567 goto exit;
568
569 ret = vchiq_mmal_port_parameter_set(
570 dev->instance, control,
571 MMAL_PARAMETER_COLOUR_EFFECT,
572 &dev->colourfx, sizeof(dev->colourfx));
573 }
574 }
575
576exit:
577 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
578 "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
579 mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
580 dev->colourfx.enable ? "true" : "false",
581 dev->colourfx.u, dev->colourfx.v,
582 ret, (ret == 0 ? 0 : -EINVAL));
583 return (ret == 0 ? 0 : EINVAL);
584}
585
586static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
587 struct v4l2_ctrl *ctrl,
588 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
589{
590 int ret = -EINVAL;
591 struct vchiq_mmal_port *control;
592
593 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
594
595 dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
596 dev->colourfx.enable = ctrl->val & 0xff;
597
598 ret = vchiq_mmal_port_parameter_set(dev->instance, control,
599 MMAL_PARAMETER_COLOUR_EFFECT,
600 &dev->colourfx,
601 sizeof(dev->colourfx));
602
603 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
604 "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
605 __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
606 (ret == 0 ? 0 : -EINVAL));
607 return (ret == 0 ? 0 : EINVAL);
608}
609
610static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
611 struct v4l2_ctrl *ctrl,
612 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
613{
614 int ret;
615 struct vchiq_mmal_port *encoder_out;
616
617 dev->capture.encode_bitrate = ctrl->val;
618
619 encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
620
621 ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
622 mmal_ctrl->mmal_id,
623 &ctrl->val, sizeof(ctrl->val));
624 ret = 0;
625 return ret;
626}
627
628static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
629 struct v4l2_ctrl *ctrl,
630 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
631{
632 u32 bitrate_mode;
633 struct vchiq_mmal_port *encoder_out;
634
635 encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
636
637 dev->capture.encode_bitrate_mode = ctrl->val;
638 switch (ctrl->val) {
639 default:
640 case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
641 bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
642 break;
643 case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
644 bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
645 break;
646 }
647
648 vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
649 mmal_ctrl->mmal_id,
650 &bitrate_mode,
651 sizeof(bitrate_mode));
652 return 0;
653}
654
655static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
656 struct v4l2_ctrl *ctrl,
657 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
658{
659 u32 u32_value;
660 struct vchiq_mmal_port *jpeg_out;
661
662 jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
663
664 u32_value = ctrl->val;
665
666 return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
667 mmal_ctrl->mmal_id,
668 &u32_value, sizeof(u32_value));
669}
670
671static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
672 struct v4l2_ctrl *ctrl,
673 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
674{
675 u32 u32_value;
676 struct vchiq_mmal_port *vid_enc_ctl;
677
678 vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
679
680 u32_value = ctrl->val;
681
682 return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
683 mmal_ctrl->mmal_id,
684 &u32_value, sizeof(u32_value));
685}
686
687static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
688 struct v4l2_ctrl *ctrl,
689 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
690{
691 struct mmal_parameter_video_profile param;
692 int ret = 0;
693
694 if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
695 switch (ctrl->val) {
696 case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
697 case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
698 case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
699 case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
700 dev->capture.enc_profile = ctrl->val;
701 break;
702 default:
703 ret = -EINVAL;
704 break;
705 }
706 } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
707 switch (ctrl->val) {
708 case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
709 case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
710 case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
711 case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
712 case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
713 case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
714 case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
715 case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
716 case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
717 case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
718 case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
719 case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
720 dev->capture.enc_level = ctrl->val;
721 break;
722 default:
723 ret = -EINVAL;
724 break;
725 }
726 }
727
728 if (!ret) {
729 switch (dev->capture.enc_profile) {
730 case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
731 param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
732 break;
733 case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
734 param.profile =
735 MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
736 break;
737 case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
738 param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
739 break;
740 case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
741 param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
742 break;
743 default:
744 /* Should never get here */
745 break;
746 }
747
748 switch (dev->capture.enc_level) {
749 case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
750 param.level = MMAL_VIDEO_LEVEL_H264_1;
751 break;
752 case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
753 param.level = MMAL_VIDEO_LEVEL_H264_1b;
754 break;
755 case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
756 param.level = MMAL_VIDEO_LEVEL_H264_11;
757 break;
758 case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
759 param.level = MMAL_VIDEO_LEVEL_H264_12;
760 break;
761 case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
762 param.level = MMAL_VIDEO_LEVEL_H264_13;
763 break;
764 case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
765 param.level = MMAL_VIDEO_LEVEL_H264_2;
766 break;
767 case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
768 param.level = MMAL_VIDEO_LEVEL_H264_21;
769 break;
770 case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
771 param.level = MMAL_VIDEO_LEVEL_H264_22;
772 break;
773 case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
774 param.level = MMAL_VIDEO_LEVEL_H264_3;
775 break;
776 case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
777 param.level = MMAL_VIDEO_LEVEL_H264_31;
778 break;
779 case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
780 param.level = MMAL_VIDEO_LEVEL_H264_32;
781 break;
782 case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
783 param.level = MMAL_VIDEO_LEVEL_H264_4;
784 break;
785 default:
786 /* Should never get here */
787 break;
788 }
789
790 ret = vchiq_mmal_port_parameter_set(dev->instance,
791 &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
792 mmal_ctrl->mmal_id,
793 &param, sizeof(param));
794 }
795 return ret;
796}
797
798static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
799 struct v4l2_ctrl *ctrl,
800 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
801{
802 int ret = 0;
803 int shutter_speed;
804 struct vchiq_mmal_port *control;
805
806 v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
807 "scene mode selected %d, was %d\n", ctrl->val,
808 dev->scene_mode);
809 control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
810
811 if (ctrl->val == dev->scene_mode)
812 return 0;
813
814 if (ctrl->val == V4L2_SCENE_MODE_NONE) {
815 /* Restore all user selections */
816 dev->scene_mode = V4L2_SCENE_MODE_NONE;
817
818 if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
819 shutter_speed = dev->manual_shutter_speed;
820 else
821 shutter_speed = 0;
822
823 v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
824 "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
825 __func__, shutter_speed, dev->exposure_mode_user,
826 dev->metering_mode);
827 ret = vchiq_mmal_port_parameter_set(dev->instance,
828 control,
829 MMAL_PARAMETER_SHUTTER_SPEED,
830 &shutter_speed,
831 sizeof(shutter_speed));
832 ret += vchiq_mmal_port_parameter_set(dev->instance,
833 control,
834 MMAL_PARAMETER_EXPOSURE_MODE,
835 &dev->exposure_mode_user,
836 sizeof(u32));
837 dev->exposure_mode_active = dev->exposure_mode_user;
838 ret += vchiq_mmal_port_parameter_set(dev->instance,
839 control,
840 MMAL_PARAMETER_EXP_METERING_MODE,
841 &dev->metering_mode,
842 sizeof(u32));
843 ret += set_framerate_params(dev);
844 } else {
845 /* Set up scene mode */
846 int i;
847 const struct v4l2_mmal_scene_config *scene = NULL;
848 int shutter_speed;
849 enum mmal_parameter_exposuremode exposure_mode;
850 enum mmal_parameter_exposuremeteringmode metering_mode;
851
852 for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
853 if (scene_configs[i].v4l2_scene ==
854 ctrl->val) {
855 scene = &scene_configs[i];
856 break;
857 }
858 }
859 if (!scene)
860 return -EINVAL;
861 if (i >= ARRAY_SIZE(scene_configs))
862 return -EINVAL;
863
864 /* Set all the values */
865 dev->scene_mode = ctrl->val;
866
867 if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
868 shutter_speed = dev->manual_shutter_speed;
869 else
870 shutter_speed = 0;
871 exposure_mode = scene->exposure_mode;
872 metering_mode = scene->metering_mode;
873
874 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
875 "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
876 __func__, shutter_speed, exposure_mode, metering_mode);
877
878 ret = vchiq_mmal_port_parameter_set(dev->instance, control,
879 MMAL_PARAMETER_SHUTTER_SPEED,
880 &shutter_speed,
881 sizeof(shutter_speed));
882 ret += vchiq_mmal_port_parameter_set(dev->instance, control,
883 MMAL_PARAMETER_EXPOSURE_MODE,
884 &exposure_mode,
885 sizeof(u32));
886 dev->exposure_mode_active = exposure_mode;
887 ret += vchiq_mmal_port_parameter_set(dev->instance, control,
888 MMAL_PARAMETER_EXPOSURE_MODE,
889 &exposure_mode,
890 sizeof(u32));
891 ret += vchiq_mmal_port_parameter_set(dev->instance, control,
892 MMAL_PARAMETER_EXP_METERING_MODE,
893 &metering_mode,
894 sizeof(u32));
895 ret += set_framerate_params(dev);
896 }
897 if (ret) {
898 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
899 "%s: Setting scene to %d, ret=%d\n",
900 __func__, ctrl->val, ret);
901 ret = -EINVAL;
902 }
903 return 0;
904}
905
906static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
907{
908 struct bm2835_mmal_dev *dev =
909 container_of(ctrl->handler, struct bm2835_mmal_dev,
910 ctrl_handler);
911 const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
912 int ret;
913
914 if ((mmal_ctrl == NULL) ||
915 (mmal_ctrl->id != ctrl->id) ||
916 (mmal_ctrl->setter == NULL)) {
917 pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
918 return -EINVAL;
919 }
920
921 ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
922 if (ret)
923 pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
924 ctrl->id, mmal_ctrl->mmal_id, ret);
925 if (mmal_ctrl->ignore_errors)
926 ret = 0;
927 return ret;
928}
929
930static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
931 .s_ctrl = bm2835_mmal_s_ctrl,
932};
933
934static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
935 {
936 V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
937 -100, 100, 0, 1, NULL,
938 MMAL_PARAMETER_SATURATION,
939 &ctrl_set_rational,
940 false
941 },
942 {
943 V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
944 -100, 100, 0, 1, NULL,
945 MMAL_PARAMETER_SHARPNESS,
946 &ctrl_set_rational,
947 false
948 },
949 {
950 V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
951 -100, 100, 0, 1, NULL,
952 MMAL_PARAMETER_CONTRAST,
953 &ctrl_set_rational,
954 false
955 },
956 {
957 V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
958 0, 100, 50, 1, NULL,
959 MMAL_PARAMETER_BRIGHTNESS,
960 &ctrl_set_rational,
961 false
962 },
963 {
964 V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
965 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
966 MMAL_PARAMETER_ISO,
967 &ctrl_set_iso,
968 false
969 },
970 {
971 V4L2_CID_ISO_SENSITIVITY_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
972 0, 1, V4L2_ISO_SENSITIVITY_AUTO, 1, NULL,
973 MMAL_PARAMETER_ISO,
974 &ctrl_set_iso,
975 false
976 },
977 {
978 V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
979 0, 1, 0, 1, NULL,
980 MMAL_PARAMETER_VIDEO_STABILISATION,
981 &ctrl_set_value,
982 false
983 },
984/* {
985 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
986 }, */
987 {
988 V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
989 ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
990 MMAL_PARAMETER_EXPOSURE_MODE,
991 &ctrl_set_exposure,
992 false
993 },
994/* todo this needs mixing in with set exposure
995 {
996 V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
997 },
998 */
999 {
1000 V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
1001 /* Units of 100usecs */
1002 1, 1 * 1000 * 10, 100 * 10, 1, NULL,
1003 MMAL_PARAMETER_SHUTTER_SPEED,
1004 &ctrl_set_exposure,
1005 false
1006 },
1007 {
1008 V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
1009 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
1010 (ARRAY_SIZE(ev_bias_qmenu) + 1) / 2 - 1, 0, ev_bias_qmenu,
1011 MMAL_PARAMETER_EXPOSURE_COMP,
1012 &ctrl_set_value_ev,
1013 false
1014 },
1015 {
1016 V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
1017 0, 1,
1018 0, 1, NULL,
1019 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
1020 &ctrl_set_exposure,
1021 false
1022 },
1023 {
1024 V4L2_CID_EXPOSURE_METERING,
1025 MMAL_CONTROL_TYPE_STD_MENU,
1026 ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
1027 MMAL_PARAMETER_EXP_METERING_MODE,
1028 &ctrl_set_metering_mode,
1029 false
1030 },
1031 {
1032 V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
1033 MMAL_CONTROL_TYPE_STD_MENU,
1034 ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
1035 MMAL_PARAMETER_AWB_MODE,
1036 &ctrl_set_awb_mode,
1037 false
1038 },
1039 {
1040 V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
1041 1, 7999, 1000, 1, NULL,
1042 MMAL_PARAMETER_CUSTOM_AWB_GAINS,
1043 &ctrl_set_awb_gains,
1044 false
1045 },
1046 {
1047 V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
1048 1, 7999, 1000, 1, NULL,
1049 MMAL_PARAMETER_CUSTOM_AWB_GAINS,
1050 &ctrl_set_awb_gains,
1051 false
1052 },
1053 {
1054 V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
1055 0, 15, V4L2_COLORFX_NONE, 0, NULL,
1056 MMAL_PARAMETER_IMAGE_EFFECT,
1057 &ctrl_set_image_effect,
1058 false
1059 },
1060 {
1061 V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
1062 0, 0xffff, 0x8080, 1, NULL,
1063 MMAL_PARAMETER_COLOUR_EFFECT,
1064 &ctrl_set_colfx,
1065 false
1066 },
1067 {
1068 V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
1069 0, 360, 0, 90, NULL,
1070 MMAL_PARAMETER_ROTATION,
1071 &ctrl_set_rotate,
1072 false
1073 },
1074 {
1075 V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
1076 0, 1, 0, 1, NULL,
1077 MMAL_PARAMETER_MIRROR,
1078 &ctrl_set_flip,
1079 false
1080 },
1081 {
1082 V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
1083 0, 1, 0, 1, NULL,
1084 MMAL_PARAMETER_MIRROR,
1085 &ctrl_set_flip,
1086 false
1087 },
1088 {
1089 V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
1090 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
1091 0, 0, bitrate_mode_qmenu,
1092 MMAL_PARAMETER_RATECONTROL,
1093 &ctrl_set_bitrate_mode,
1094 false
1095 },
1096 {
1097 V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
1098 25 * 1000, 25 * 1000 * 1000, 10 * 1000 * 1000, 25 * 1000, NULL,
1099 MMAL_PARAMETER_VIDEO_BIT_RATE,
1100 &ctrl_set_bitrate,
1101 false
1102 },
1103 {
1104 V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
1105 1, 100,
1106 30, 1, NULL,
1107 MMAL_PARAMETER_JPEG_Q_FACTOR,
1108 &ctrl_set_image_encode_output,
1109 false
1110 },
1111 {
1112 V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
1113 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
1114 1, 1, NULL,
1115 MMAL_PARAMETER_FLICKER_AVOID,
1116 &ctrl_set_flicker_avoidance,
1117 false
1118 },
1119 {
1120 V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
1121 0, 1,
1122 0, 1, NULL,
1123 MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
1124 &ctrl_set_video_encode_param_output,
1125 true /* Errors ignored as requires latest firmware to work */
1126 },
1127 {
1128 V4L2_CID_MPEG_VIDEO_H264_PROFILE,
1129 MMAL_CONTROL_TYPE_STD_MENU,
1130 ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
1131 (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
1132 (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
1133 (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
1134 V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
1135 V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
1136 MMAL_PARAMETER_PROFILE,
1137 &ctrl_set_video_encode_profile_level,
1138 false
1139 },
1140 {
1141 V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
1142 ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
1143 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
1144 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
1145 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
1146 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
1147 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
1148 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
1149 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
1150 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
1151 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
1152 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
1153 (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
1154 V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
1155 V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
1156 MMAL_PARAMETER_PROFILE,
1157 &ctrl_set_video_encode_profile_level,
1158 false
1159 },
1160 {
1161 V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
1162 -1, /* Min is computed at runtime */
1163 V4L2_SCENE_MODE_TEXT,
1164 V4L2_SCENE_MODE_NONE, 1, NULL,
1165 MMAL_PARAMETER_PROFILE,
1166 &ctrl_set_scene_mode,
1167 false
1168 },
1169 {
1170 V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
1171 0, 0x7FFFFFFF, 60, 1, NULL,
1172 MMAL_PARAMETER_INTRAPERIOD,
1173 &ctrl_set_video_encode_param_output,
1174 false
1175 },
1176};
1177
1178int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
1179{
1180 int c;
1181 int ret = 0;
1182
1183 for (c = 0; c < V4L2_CTRL_COUNT; c++) {
1184 if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
1185 ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
1186 &v4l2_ctrls[c]);
1187 if (!v4l2_ctrls[c].ignore_errors && ret) {
1188 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1189 "Failed when setting default values for ctrl %d\n",
1190 c);
1191 break;
1192 }
1193 }
1194 }
1195 return ret;
1196}
1197
1198int set_framerate_params(struct bm2835_mmal_dev *dev)
1199{
1200 struct mmal_parameter_fps_range fps_range;
1201 int ret;
1202
1203 if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
1204 (dev->exp_auto_priority)) {
1205 /* Variable FPS. Define min FPS as 1fps.
1206 * Max as max defined FPS.
1207 */
1208 fps_range.fps_low.num = 1;
1209 fps_range.fps_low.den = 1;
1210 fps_range.fps_high.num = dev->capture.timeperframe.denominator;
1211 fps_range.fps_high.den = dev->capture.timeperframe.numerator;
1212 } else {
1213 /* Fixed FPS - set min and max to be the same */
1214 fps_range.fps_low.num = fps_range.fps_high.num =
1215 dev->capture.timeperframe.denominator;
1216 fps_range.fps_low.den = fps_range.fps_high.den =
1217 dev->capture.timeperframe.numerator;
1218 }
1219
1220 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
1221 "Set fps range to %d/%d to %d/%d\n",
1222 fps_range.fps_low.num,
1223 fps_range.fps_low.den,
1224 fps_range.fps_high.num,
1225 fps_range.fps_high.den);
1226
1227 ret = vchiq_mmal_port_parameter_set(dev->instance,
1228 &dev->component[MMAL_COMPONENT_CAMERA]->
1229 output[MMAL_CAMERA_PORT_PREVIEW],
1230 MMAL_PARAMETER_FPS_RANGE,
1231 &fps_range, sizeof(fps_range));
1232 ret += vchiq_mmal_port_parameter_set(dev->instance,
1233 &dev->component[MMAL_COMPONENT_CAMERA]->
1234 output[MMAL_CAMERA_PORT_VIDEO],
1235 MMAL_PARAMETER_FPS_RANGE,
1236 &fps_range, sizeof(fps_range));
1237 ret += vchiq_mmal_port_parameter_set(dev->instance,
1238 &dev->component[MMAL_COMPONENT_CAMERA]->
1239 output[MMAL_CAMERA_PORT_CAPTURE],
1240 MMAL_PARAMETER_FPS_RANGE,
1241 &fps_range, sizeof(fps_range));
1242 if (ret)
1243 v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
1244 "Failed to set fps ret %d\n", ret);
1245
1246 return ret;
1247}
1248
1249int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
1250 struct v4l2_ctrl_handler *hdl)
1251{
1252 int c;
1253 const struct bm2835_mmal_v4l2_ctrl *ctrl;
1254
1255 v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
1256
1257 for (c = 0; c < V4L2_CTRL_COUNT; c++) {
1258 ctrl = &v4l2_ctrls[c];
1259
1260 switch (ctrl->type) {
1261 case MMAL_CONTROL_TYPE_STD:
1262 dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
1263 &bm2835_mmal_ctrl_ops, ctrl->id,
1264 ctrl->min, ctrl->max, ctrl->step, ctrl->def);
1265 break;
1266
1267 case MMAL_CONTROL_TYPE_STD_MENU:
1268 {
1269 int mask = ctrl->min;
1270
1271 if (ctrl->id == V4L2_CID_SCENE_MODE) {
1272 /* Special handling to work out the mask
1273 * value based on the scene_configs array
1274 * at runtime. Reduces the chance of
1275 * mismatches.
1276 */
1277 int i;
1278 mask = 1<<V4L2_SCENE_MODE_NONE;
1279 for (i = 0;
1280 i < ARRAY_SIZE(scene_configs);
1281 i++) {
1282 mask |= 1<<scene_configs[i].v4l2_scene;
1283 }
1284 mask = ~mask;
1285 }
1286
1287 dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
1288 &bm2835_mmal_ctrl_ops, ctrl->id,
1289 ctrl->max, mask, ctrl->def);
1290 break;
1291 }
1292
1293 case MMAL_CONTROL_TYPE_INT_MENU:
1294 dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
1295 &bm2835_mmal_ctrl_ops, ctrl->id,
1296 ctrl->max, ctrl->def, ctrl->imenu);
1297 break;
1298
1299 case MMAL_CONTROL_TYPE_CLUSTER:
1300 /* skip this entry when constructing controls */
1301 continue;
1302 }
1303
1304 if (hdl->error)
1305 break;
1306
1307 dev->ctrls[c]->priv = (void *)ctrl;
1308 }
1309
1310 if (hdl->error) {
1311 pr_err("error adding control %d/%d id 0x%x\n", c,
1312 V4L2_CTRL_COUNT, ctrl->id);
1313 return hdl->error;
1314 }
1315
1316 for (c = 0; c < V4L2_CTRL_COUNT; c++) {
1317 ctrl = &v4l2_ctrls[c];
1318
1319 switch (ctrl->type) {
1320 case MMAL_CONTROL_TYPE_CLUSTER:
1321 v4l2_ctrl_auto_cluster(ctrl->min,
1322 &dev->ctrls[c + 1],
1323 ctrl->max,
1324 ctrl->def);
1325 break;
1326
1327 case MMAL_CONTROL_TYPE_STD:
1328 case MMAL_CONTROL_TYPE_STD_MENU:
1329 case MMAL_CONTROL_TYPE_INT_MENU:
1330 break;
1331 }
1332 }
1333
1334 return 0;
1335}
diff --git a/drivers/staging/media/platform/bcm2835/mmal-common.h b/drivers/staging/media/platform/bcm2835/mmal-common.h
new file mode 100644
index 000000000000..840fd139e033
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-common.h
@@ -0,0 +1,53 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 *
15 * MMAL structures
16 *
17 */
18
19#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
20#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
21
22/** Special value signalling that time is not known */
23#define MMAL_TIME_UNKNOWN (1LL<<63)
24
25/* mapping between v4l and mmal video modes */
26struct mmal_fmt {
27 char *name;
28 u32 fourcc; /* v4l2 format id */
29 int flags; /* v4l2 flags field */
30 u32 mmal;
31 int depth;
32 u32 mmal_component; /* MMAL component index to be used to encode */
33 u32 ybbp; /* depth of first Y plane for planar formats */
34};
35
36/* buffer for one video frame */
37struct mmal_buffer {
38 /* v4l buffer data -- must be first */
39 struct vb2_v4l2_buffer vb;
40
41 /* list of buffers available */
42 struct list_head list;
43
44 void *buffer; /* buffer pointer */
45 unsigned long buffer_size; /* size of allocated buffer */
46};
47
48/* */
49struct mmal_colourfx {
50 s32 enable;
51 u32 u;
52 u32 v;
53};
diff --git a/drivers/staging/media/platform/bcm2835/mmal-encodings.h b/drivers/staging/media/platform/bcm2835/mmal-encodings.h
new file mode 100644
index 000000000000..024d620dc1df
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-encodings.h
@@ -0,0 +1,127 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15#ifndef MMAL_ENCODINGS_H
16#define MMAL_ENCODINGS_H
17
18#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
19#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
20#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
21#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
22#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
23#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
24#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
25#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
26#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
27#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
28#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
29#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
30#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
31#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
32#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
33
34#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
35#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
36#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
37#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
38#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
39#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
40
41#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
42#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
43#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
44#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
45#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
46#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
47#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
48#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
49#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
50#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
51#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
52#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
53#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
54#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
55#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
56#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
57#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
58#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
59#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
60#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
61#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
62
63/** SAND Video (YUVUV128) format, native format understood by VideoCore.
64 * This format is *not* opaque - if requested you will receive full frames
65 * of YUV_UV video.
66 */
67#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
68
69/** VideoCore opaque image format, image handles are returned to
70 * the host but not the actual image data.
71 */
72#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
73
74/** An EGL image handle
75 */
76#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
77
78/* }@ */
79
80/** \name Pre-defined audio encodings */
81/* @{ */
82#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
83#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
84#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
85#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
86#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
87#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
88
89/* Pre-defined H264 encoding variants */
90
91/** ISO 14496-10 Annex B byte stream format */
92#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
93/** ISO 14496-15 AVC stream format */
94#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
95/** Implicitly delineated NAL units without emulation prevention */
96#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
97
98
99/** \defgroup MmalColorSpace List of pre-defined video color spaces
100 * This defines a list of common color spaces. This list isn't exhaustive and
101 * is only provided as a convenience to avoid clients having to use FourCC
102 * codes directly. However components are allowed to define and use their own
103 * FourCC codes.
104 */
105/* @{ */
106
107/** Unknown color space */
108#define MMAL_COLOR_SPACE_UNKNOWN 0
109/** ITU-R BT.601-5 [SDTV] */
110#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
111/** ITU-R BT.709-3 [HDTV] */
112#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
113/** JPEG JFIF */
114#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
115/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
116#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
117/** Society of Motion Picture and Television Engineers 240M (1999) */
118#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
119/** ITU-R BT.470-2 System M */
120#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
121/** ITU-R BT.470-2 System BG */
122#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
123/** JPEG JFIF, but with 16..255 luma */
124#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
125/* @} MmalColorSpace List */
126
127#endif /* MMAL_ENCODINGS_H */
diff --git a/drivers/staging/media/platform/bcm2835/mmal-msg-common.h b/drivers/staging/media/platform/bcm2835/mmal-msg-common.h
new file mode 100644
index 000000000000..66e8a6edf628
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-msg-common.h
@@ -0,0 +1,50 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15
16#ifndef MMAL_MSG_COMMON_H
17#define MMAL_MSG_COMMON_H
18
19enum mmal_msg_status {
20 MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
21 MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
22 MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
23 MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
24 MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
25 MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
26 MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
27 MMAL_MSG_STATUS_EIO, /**< I/O error */
28 MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
29 MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
30 MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
31 MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
32 MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
33 MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
34 MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
35 MMAL_MSG_STATUS_EFAULT, /**< Bad address */
36};
37
38struct mmal_rect {
39 s32 x; /**< x coordinate (from left) */
40 s32 y; /**< y coordinate (from top) */
41 s32 width; /**< width */
42 s32 height; /**< height */
43};
44
45struct mmal_rational {
46 s32 num; /**< Numerator */
47 s32 den; /**< Denominator */
48};
49
50#endif /* MMAL_MSG_COMMON_H */
diff --git a/drivers/staging/media/platform/bcm2835/mmal-msg-format.h b/drivers/staging/media/platform/bcm2835/mmal-msg-format.h
new file mode 100644
index 000000000000..123d86ef582b
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-msg-format.h
@@ -0,0 +1,81 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15
16#ifndef MMAL_MSG_FORMAT_H
17#define MMAL_MSG_FORMAT_H
18
19#include "mmal-msg-common.h"
20
21/* MMAL_ES_FORMAT_T */
22
23
24struct mmal_audio_format {
25 u32 channels; /**< Number of audio channels */
26 u32 sample_rate; /**< Sample rate */
27
28 u32 bits_per_sample; /**< Bits per sample */
29 u32 block_align; /**< Size of a block of data */
30};
31
32struct mmal_video_format {
33 u32 width; /**< Width of frame in pixels */
34 u32 height; /**< Height of frame in rows of pixels */
35 struct mmal_rect crop; /**< Visible region of the frame */
36 struct mmal_rational frame_rate; /**< Frame rate */
37 struct mmal_rational par; /**< Pixel aspect ratio */
38
39 /* FourCC specifying the color space of the video stream. See the
40 * \ref MmalColorSpace "pre-defined color spaces" for some examples.
41 */
42 u32 color_space;
43};
44
45struct mmal_subpicture_format {
46 u32 x_offset;
47 u32 y_offset;
48};
49
50union mmal_es_specific_format {
51 struct mmal_audio_format audio;
52 struct mmal_video_format video;
53 struct mmal_subpicture_format subpicture;
54};
55
56/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
57struct mmal_es_format {
58 u32 type; /* enum mmal_es_type */
59
60 u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
61 u32 encoding_variant; /* FourCC specifying the specific
62 * encoding variant of the elementary
63 * stream.
64 */
65
66 union mmal_es_specific_format *es; /* TODO: pointers in
67 * message serialisation?!?
68 */
69 /* Type specific
70 * information for the
71 * elementary stream
72 */
73
74 u32 bitrate; /**< Bitrate in bits per second */
75 u32 flags; /**< Flags describing properties of the elementary stream. */
76
77 u32 extradata_size; /**< Size of the codec specific data */
78 u8 *extradata; /**< Codec specific data */
79};
80
81#endif /* MMAL_MSG_FORMAT_H */
diff --git a/drivers/staging/media/platform/bcm2835/mmal-msg-port.h b/drivers/staging/media/platform/bcm2835/mmal-msg-port.h
new file mode 100644
index 000000000000..a55c1ea2eceb
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-msg-port.h
@@ -0,0 +1,107 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15
16/* MMAL_PORT_TYPE_T */
17enum mmal_port_type {
18 MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
19 MMAL_PORT_TYPE_CONTROL, /**< Control port */
20 MMAL_PORT_TYPE_INPUT, /**< Input port */
21 MMAL_PORT_TYPE_OUTPUT, /**< Output port */
22 MMAL_PORT_TYPE_CLOCK, /**< Clock port */
23};
24
25/** The port is pass-through and doesn't need buffer headers allocated */
26#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
27/** The port wants to allocate the buffer payloads.
28 * This signals a preference that payload allocation should be done
29 * on this port for efficiency reasons. */
30#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
31/** The port supports format change events.
32 * This applies to input ports and is used to let the client know
33 * whether the port supports being reconfigured via a format
34 * change event (i.e. without having to disable the port). */
35#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
36
37/* mmal port structure (MMAL_PORT_T)
38 *
39 * most elements are informational only, the pointer values for
40 * interogation messages are generally provided as additional
41 * strucures within the message. When used to set values only teh
42 * buffer_num, buffer_size and userdata parameters are writable.
43 */
44struct mmal_port {
45 void *priv; /* Private member used by the framework */
46 const char *name; /* Port name. Used for debugging purposes (RO) */
47
48 u32 type; /* Type of the port (RO) enum mmal_port_type */
49 u16 index; /* Index of the port in its type list (RO) */
50 u16 index_all; /* Index of the port in the list of all ports (RO) */
51
52 u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
53 struct mmal_es_format *format; /* Format of the elementary stream */
54
55 u32 buffer_num_min; /* Minimum number of buffers the port
56 * requires (RO). This is set by the
57 * component.
58 */
59
60 u32 buffer_size_min; /* Minimum size of buffers the port
61 * requires (RO). This is set by the
62 * component.
63 */
64
65 u32 buffer_alignment_min; /* Minimum alignment requirement for
66 * the buffers (RO). A value of
67 * zero means no special alignment
68 * requirements. This is set by the
69 * component.
70 */
71
72 u32 buffer_num_recommended; /* Number of buffers the port
73 * recommends for optimal
74 * performance (RO). A value of
75 * zero means no special
76 * recommendation. This is set
77 * by the component.
78 */
79
80 u32 buffer_size_recommended; /* Size of buffers the port
81 * recommends for optimal
82 * performance (RO). A value of
83 * zero means no special
84 * recommendation. This is set
85 * by the component.
86 */
87
88 u32 buffer_num; /* Actual number of buffers the port will use.
89 * This is set by the client.
90 */
91
92 u32 buffer_size; /* Actual maximum size of the buffers that
93 * will be sent to the port. This is set by
94 * the client.
95 */
96
97 void *component; /* Component this port belongs to (Read Only) */
98
99 void *userdata; /* Field reserved for use by the client */
100
101 u32 capabilities; /* Flags describing the capabilities of a
102 * port (RO). Bitwise combination of \ref
103 * portcapabilities "Port capabilities"
104 * values.
105 */
106
107};
diff --git a/drivers/staging/media/platform/bcm2835/mmal-msg.h b/drivers/staging/media/platform/bcm2835/mmal-msg.h
new file mode 100644
index 000000000000..67b1076015a5
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-msg.h
@@ -0,0 +1,404 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15
16/* all the data structures which serialise the MMAL protocol. note
17 * these are directly mapped onto the recived message data.
18 *
19 * BEWARE: They seem to *assume* pointers are u32 and that there is no
20 * structure padding!
21 *
22 * NOTE: this implementation uses kernel types to ensure sizes. Rather
23 * than assigning values to enums to force their size the
24 * implementation uses fixed size types and not the enums (though the
25 * comments have the actual enum type
26 */
27
28#define VC_MMAL_VER 15
29#define VC_MMAL_MIN_VER 10
30#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
31
32/* max total message size is 512 bytes */
33#define MMAL_MSG_MAX_SIZE 512
34/* with six 32bit header elements max payload is therefore 488 bytes */
35#define MMAL_MSG_MAX_PAYLOAD 488
36
37#include "mmal-msg-common.h"
38#include "mmal-msg-format.h"
39#include "mmal-msg-port.h"
40
41enum mmal_msg_type {
42 MMAL_MSG_TYPE_QUIT = 1,
43 MMAL_MSG_TYPE_SERVICE_CLOSED,
44 MMAL_MSG_TYPE_GET_VERSION,
45 MMAL_MSG_TYPE_COMPONENT_CREATE,
46 MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
47 MMAL_MSG_TYPE_COMPONENT_ENABLE,
48 MMAL_MSG_TYPE_COMPONENT_DISABLE,
49 MMAL_MSG_TYPE_PORT_INFO_GET,
50 MMAL_MSG_TYPE_PORT_INFO_SET,
51 MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
52 MMAL_MSG_TYPE_BUFFER_FROM_HOST,
53 MMAL_MSG_TYPE_BUFFER_TO_HOST,
54 MMAL_MSG_TYPE_GET_STATS,
55 MMAL_MSG_TYPE_PORT_PARAMETER_SET,
56 MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
57 MMAL_MSG_TYPE_EVENT_TO_HOST,
58 MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
59 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
60 MMAL_MSG_TYPE_CONSUME_MEM,
61 MMAL_MSG_TYPE_LMK, /* 20 */
62 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
63 MMAL_MSG_TYPE_DRM_GET_LHS32,
64 MMAL_MSG_TYPE_DRM_GET_TIME,
65 MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
66 MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
67 MMAL_MSG_TYPE_HOST_LOG,
68 MMAL_MSG_TYPE_MSG_LAST
69};
70
71/* port action request messages differ depending on the action type */
72enum mmal_msg_port_action_type {
73 MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
74 MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
75 MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
76 MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
77 MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
78 MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
79 MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
80};
81
82struct mmal_msg_header {
83 u32 magic;
84 u32 type; /** enum mmal_msg_type */
85
86 /* Opaque handle to the control service */
87 struct mmal_control_service *control_service;
88
89 struct mmal_msg_context *context; /** a u32 per message context */
90 u32 status; /** The status of the vchiq operation */
91 u32 padding;
92};
93
94/* Send from VC to host to report version */
95struct mmal_msg_version {
96 u32 flags;
97 u32 major;
98 u32 minor;
99 u32 minimum;
100};
101
102/* request to VC to create component */
103struct mmal_msg_component_create {
104 void *client_component; /* component context */
105 char name[128];
106 u32 pid; /* For debug */
107};
108
109/* reply from VC to component creation request */
110struct mmal_msg_component_create_reply {
111 u32 status; /** enum mmal_msg_status - how does this differ to
112 * the one in the header?
113 */
114 u32 component_handle; /* VideoCore handle for component */
115 u32 input_num; /* Number of input ports */
116 u32 output_num; /* Number of output ports */
117 u32 clock_num; /* Number of clock ports */
118};
119
120/* request to VC to destroy a component */
121struct mmal_msg_component_destroy {
122 u32 component_handle;
123};
124
125struct mmal_msg_component_destroy_reply {
126 u32 status; /** The component destruction status */
127};
128
129
130/* request and reply to VC to enable a component */
131struct mmal_msg_component_enable {
132 u32 component_handle;
133};
134
135struct mmal_msg_component_enable_reply {
136 u32 status; /** The component enable status */
137};
138
139
140/* request and reply to VC to disable a component */
141struct mmal_msg_component_disable {
142 u32 component_handle;
143};
144
145struct mmal_msg_component_disable_reply {
146 u32 status; /** The component disable status */
147};
148
149/* request to VC to get port information */
150struct mmal_msg_port_info_get {
151 u32 component_handle; /* component handle port is associated with */
152 u32 port_type; /* enum mmal_msg_port_type */
153 u32 index; /* port index to query */
154};
155
156/* reply from VC to get port info request */
157struct mmal_msg_port_info_get_reply {
158 u32 status; /** enum mmal_msg_status */
159 u32 component_handle; /* component handle port is associated with */
160 u32 port_type; /* enum mmal_msg_port_type */
161 u32 port_index; /* port indexed in query */
162 s32 found; /* unused */
163 u32 port_handle; /**< Handle to use for this port */
164 struct mmal_port port;
165 struct mmal_es_format format; /* elementry stream format */
166 union mmal_es_specific_format es; /* es type specific data */
167 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
168};
169
170/* request to VC to set port information */
171struct mmal_msg_port_info_set {
172 u32 component_handle;
173 u32 port_type; /* enum mmal_msg_port_type */
174 u32 port_index; /* port indexed in query */
175 struct mmal_port port;
176 struct mmal_es_format format;
177 union mmal_es_specific_format es;
178 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
179};
180
181/* reply from VC to port info set request */
182struct mmal_msg_port_info_set_reply {
183 u32 status;
184 u32 component_handle; /* component handle port is associated with */
185 u32 port_type; /* enum mmal_msg_port_type */
186 u32 index; /* port indexed in query */
187 s32 found; /* unused */
188 u32 port_handle; /**< Handle to use for this port */
189 struct mmal_port port;
190 struct mmal_es_format format;
191 union mmal_es_specific_format es;
192 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
193};
194
195
196/* port action requests that take a mmal_port as a parameter */
197struct mmal_msg_port_action_port {
198 u32 component_handle;
199 u32 port_handle;
200 u32 action; /* enum mmal_msg_port_action_type */
201 struct mmal_port port;
202};
203
204/* port action requests that take handles as a parameter */
205struct mmal_msg_port_action_handle {
206 u32 component_handle;
207 u32 port_handle;
208 u32 action; /* enum mmal_msg_port_action_type */
209 u32 connect_component_handle;
210 u32 connect_port_handle;
211};
212
213struct mmal_msg_port_action_reply {
214 u32 status; /** The port action operation status */
215};
216
217
218
219
220/* MMAL buffer transfer */
221
222/** Size of space reserved in a buffer message for short messages. */
223#define MMAL_VC_SHORT_DATA 128
224
225/** Signals that the current payload is the end of the stream of data */
226#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
227/** Signals that the start of the current payload starts a frame */
228#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
229/** Signals that the end of the current payload ends a frame */
230#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
231/** Signals that the current payload contains only complete frames (>1) */
232#define MMAL_BUFFER_HEADER_FLAG_FRAME \
233 (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
234/** Signals that the current payload is a keyframe (i.e. self decodable) */
235#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
236/** Signals a discontinuity in the stream of data (e.g. after a seek).
237 * Can be used for instance by a decoder to reset its state */
238#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
239/** Signals a buffer containing some kind of config data for the component
240 * (e.g. codec config data) */
241#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
242/** Signals an encrypted payload */
243#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
244/** Signals a buffer containing side information */
245#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
246/** Signals a buffer which is the snapshot/postview image from a stills
247 * capture
248 */
249#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
250/** Signals a buffer which contains data known to be corrupted */
251#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
252/** Signals that a buffer failed to be transmitted */
253#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
254
255struct mmal_driver_buffer {
256 u32 magic;
257 u32 component_handle;
258 u32 port_handle;
259 void *client_context;
260};
261
262/* buffer header */
263struct mmal_buffer_header {
264 struct mmal_buffer_header *next; /* next header */
265 void *priv; /* framework private data */
266 u32 cmd;
267 void *data;
268 u32 alloc_size;
269 u32 length;
270 u32 offset;
271 u32 flags;
272 s64 pts;
273 s64 dts;
274 void *type;
275 void *user_data;
276};
277
278struct mmal_buffer_header_type_specific {
279 union {
280 struct {
281 u32 planes;
282 u32 offset[4];
283 u32 pitch[4];
284 u32 flags;
285 } video;
286 } u;
287};
288
289struct mmal_msg_buffer_from_host {
290 /* The front 32 bytes of the buffer header are copied
291 * back to us in the reply to allow for context. This
292 * area is used to store two mmal_driver_buffer structures to
293 * allow for multiple concurrent service users.
294 */
295 /* control data */
296 struct mmal_driver_buffer drvbuf;
297
298 /* referenced control data for passthrough buffer management */
299 struct mmal_driver_buffer drvbuf_ref;
300 struct mmal_buffer_header buffer_header; /* buffer header itself */
301 struct mmal_buffer_header_type_specific buffer_header_type_specific;
302 s32 is_zero_copy;
303 s32 has_reference;
304
305 /** allows short data to be xfered in control message */
306 u32 payload_in_message;
307 u8 short_data[MMAL_VC_SHORT_DATA];
308};
309
310
311/* port parameter setting */
312
313#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
314
315struct mmal_msg_port_parameter_set {
316 u32 component_handle; /* component */
317 u32 port_handle; /* port */
318 u32 id; /* Parameter ID */
319 u32 size; /* Parameter size */
320 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
321};
322
323struct mmal_msg_port_parameter_set_reply {
324 u32 status; /** enum mmal_msg_status todo: how does this
325 * differ to the one in the header?
326 */
327};
328
329/* port parameter getting */
330
331struct mmal_msg_port_parameter_get {
332 u32 component_handle; /* component */
333 u32 port_handle; /* port */
334 u32 id; /* Parameter ID */
335 u32 size; /* Parameter size */
336};
337
338struct mmal_msg_port_parameter_get_reply {
339 u32 status; /* Status of mmal_port_parameter_get call */
340 u32 id; /* Parameter ID */
341 u32 size; /* Parameter size */
342 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
343};
344
345/* event messages */
346#define MMAL_WORKER_EVENT_SPACE 256
347
348struct mmal_msg_event_to_host {
349 void *client_component; /* component context */
350
351 u32 port_type;
352 u32 port_num;
353
354 u32 cmd;
355 u32 length;
356 u8 data[MMAL_WORKER_EVENT_SPACE];
357 struct mmal_buffer_header *delayed_buffer;
358};
359
360/* all mmal messages are serialised through this structure */
361struct mmal_msg {
362 /* header */
363 struct mmal_msg_header h;
364 /* payload */
365 union {
366 struct mmal_msg_version version;
367
368 struct mmal_msg_component_create component_create;
369 struct mmal_msg_component_create_reply component_create_reply;
370
371 struct mmal_msg_component_destroy component_destroy;
372 struct mmal_msg_component_destroy_reply component_destroy_reply;
373
374 struct mmal_msg_component_enable component_enable;
375 struct mmal_msg_component_enable_reply component_enable_reply;
376
377 struct mmal_msg_component_disable component_disable;
378 struct mmal_msg_component_disable_reply component_disable_reply;
379
380 struct mmal_msg_port_info_get port_info_get;
381 struct mmal_msg_port_info_get_reply port_info_get_reply;
382
383 struct mmal_msg_port_info_set port_info_set;
384 struct mmal_msg_port_info_set_reply port_info_set_reply;
385
386 struct mmal_msg_port_action_port port_action_port;
387 struct mmal_msg_port_action_handle port_action_handle;
388 struct mmal_msg_port_action_reply port_action_reply;
389
390 struct mmal_msg_buffer_from_host buffer_from_host;
391
392 struct mmal_msg_port_parameter_set port_parameter_set;
393 struct mmal_msg_port_parameter_set_reply
394 port_parameter_set_reply;
395 struct mmal_msg_port_parameter_get
396 port_parameter_get;
397 struct mmal_msg_port_parameter_get_reply
398 port_parameter_get_reply;
399
400 struct mmal_msg_event_to_host event_to_host;
401
402 u8 payload[MMAL_MSG_MAX_PAYLOAD];
403 } u;
404};
diff --git a/drivers/staging/media/platform/bcm2835/mmal-parameters.h b/drivers/staging/media/platform/bcm2835/mmal-parameters.h
new file mode 100644
index 000000000000..f6abb5cfa49d
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-parameters.h
@@ -0,0 +1,689 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 */
15
16/* common parameters */
17
18/** @name Parameter groups
19 * Parameters are divided into groups, and then allocated sequentially within
20 * a group using an enum.
21 * @{
22 */
23
24/** Common parameter ID group, used with many types of component. */
25#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
26/** Camera-specific parameter ID group. */
27#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
28/** Video-specific parameter ID group. */
29#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
30/** Audio-specific parameter ID group. */
31#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
32/** Clock-specific parameter ID group. */
33#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
34/** Miracast-specific parameter ID group. */
35#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
36
37/* Common parameters */
38enum mmal_parameter_common_type {
39 MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
40 = MMAL_PARAMETER_GROUP_COMMON,
41 MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
42 MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
43
44 /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
45 MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
46
47 /** MMAL_PARAMETER_BOOLEAN_T */
48 MMAL_PARAMETER_ZERO_COPY,
49
50 /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
51 MMAL_PARAMETER_BUFFER_REQUIREMENTS,
52
53 MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
54 MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
55 MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
56 MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
57 MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
58 MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
59 MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
60 MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
61 MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
62};
63
64/* camera parameters */
65
66enum mmal_parameter_camera_type {
67 /* 0 */
68 /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
69 MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
70 = MMAL_PARAMETER_GROUP_CAMERA,
71 MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
72 MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
73 MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
74 MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
75 MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
76 MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
77 MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
78 MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
79 MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
80 MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
81 MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
82 MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
83 MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
84 MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
85 MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
86
87 /* 0x10 */
88 MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
89 MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
90 MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
91 MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
92 MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
93 MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
94 MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
95 MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
96 MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
97 MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
98 MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
99 MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
100 MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
101 MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
102 MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
103 MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
104
105 /* 0x20 */
106 MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
107 MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
108 MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
109 MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
110 MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
111 MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
112 MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
113 MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
114 MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
115 MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
116 MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
117 MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
118 MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
119 MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
120 MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
121 MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
122
123 /* 0x30 */
124 MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
125 MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
126
127 /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
128 MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
129
130 /** @ref MMAL_PARAMETER_BOOLEAN_T */
131 MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
132
133 /** @ref MMAL_PARAMETER_UINT32_T */
134 MMAL_PARAMETER_CAMERA_MIN_ISO,
135
136 /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
137 MMAL_PARAMETER_CAMERA_USE_CASE,
138
139 /**< @ref MMAL_PARAMETER_BOOLEAN_T */
140 MMAL_PARAMETER_CAPTURE_STATS_PASS,
141
142 /** @ref MMAL_PARAMETER_UINT32_T */
143 MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
144
145 /** @ref MMAL_PARAMETER_BOOLEAN_T */
146 MMAL_PARAMETER_ENABLE_REGISTER_FILE,
147
148 /** @ref MMAL_PARAMETER_BOOLEAN_T */
149 MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
150
151 /** @ref MMAL_PARAMETER_CONFIGFILE_T */
152 MMAL_PARAMETER_CONFIGFILE_REGISTERS,
153
154 /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
155 MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
156 MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
157 MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
158 MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
159 MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
160
161 /* 0x40 */
162 MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
163 MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
164 MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
165 MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
166 MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
167};
168
169struct mmal_parameter_rational {
170 s32 num; /**< Numerator */
171 s32 den; /**< Denominator */
172};
173
174enum mmal_parameter_camera_config_timestamp_mode {
175 MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
176 MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
177 * for the frame timestamp
178 */
179 MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
180 * but subtract the
181 * timestamp of the first
182 * frame sent to give a
183 * zero based timestamp.
184 */
185};
186
187struct mmal_parameter_fps_range {
188 /**< Low end of the permitted framerate range */
189 struct mmal_parameter_rational fps_low;
190 /**< High end of the permitted framerate range */
191 struct mmal_parameter_rational fps_high;
192};
193
194
195/* camera configuration parameter */
196struct mmal_parameter_camera_config {
197 /* Parameters for setting up the image pools */
198 u32 max_stills_w; /* Max size of stills capture */
199 u32 max_stills_h;
200 u32 stills_yuv422; /* Allow YUV422 stills capture */
201 u32 one_shot_stills; /* Continuous or one shot stills captures. */
202
203 u32 max_preview_video_w; /* Max size of the preview or video
204 * capture frames
205 */
206 u32 max_preview_video_h;
207 u32 num_preview_video_frames;
208
209 /** Sets the height of the circular buffer for stills capture. */
210 u32 stills_capture_circular_buffer_height;
211
212 /** Allows preview/encode to resume as fast as possible after the stills
213 * input frame has been received, and then processes the still frame in
214 * the background whilst preview/encode has resumed.
215 * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
216 */
217 u32 fast_preview_resume;
218
219 /** Selects algorithm for timestamping frames if
220 * there is no clock component connected.
221 * enum mmal_parameter_camera_config_timestamp_mode
222 */
223 s32 use_stc_timestamp;
224};
225
226
227enum mmal_parameter_exposuremode {
228 MMAL_PARAM_EXPOSUREMODE_OFF,
229 MMAL_PARAM_EXPOSUREMODE_AUTO,
230 MMAL_PARAM_EXPOSUREMODE_NIGHT,
231 MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
232 MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
233 MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
234 MMAL_PARAM_EXPOSUREMODE_SPORTS,
235 MMAL_PARAM_EXPOSUREMODE_SNOW,
236 MMAL_PARAM_EXPOSUREMODE_BEACH,
237 MMAL_PARAM_EXPOSUREMODE_VERYLONG,
238 MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
239 MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
240 MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
241};
242
243enum mmal_parameter_exposuremeteringmode {
244 MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
245 MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
246 MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
247 MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
248};
249
250enum mmal_parameter_awbmode {
251 MMAL_PARAM_AWBMODE_OFF,
252 MMAL_PARAM_AWBMODE_AUTO,
253 MMAL_PARAM_AWBMODE_SUNLIGHT,
254 MMAL_PARAM_AWBMODE_CLOUDY,
255 MMAL_PARAM_AWBMODE_SHADE,
256 MMAL_PARAM_AWBMODE_TUNGSTEN,
257 MMAL_PARAM_AWBMODE_FLUORESCENT,
258 MMAL_PARAM_AWBMODE_INCANDESCENT,
259 MMAL_PARAM_AWBMODE_FLASH,
260 MMAL_PARAM_AWBMODE_HORIZON,
261};
262
263enum mmal_parameter_imagefx {
264 MMAL_PARAM_IMAGEFX_NONE,
265 MMAL_PARAM_IMAGEFX_NEGATIVE,
266 MMAL_PARAM_IMAGEFX_SOLARIZE,
267 MMAL_PARAM_IMAGEFX_POSTERIZE,
268 MMAL_PARAM_IMAGEFX_WHITEBOARD,
269 MMAL_PARAM_IMAGEFX_BLACKBOARD,
270 MMAL_PARAM_IMAGEFX_SKETCH,
271 MMAL_PARAM_IMAGEFX_DENOISE,
272 MMAL_PARAM_IMAGEFX_EMBOSS,
273 MMAL_PARAM_IMAGEFX_OILPAINT,
274 MMAL_PARAM_IMAGEFX_HATCH,
275 MMAL_PARAM_IMAGEFX_GPEN,
276 MMAL_PARAM_IMAGEFX_PASTEL,
277 MMAL_PARAM_IMAGEFX_WATERCOLOUR,
278 MMAL_PARAM_IMAGEFX_FILM,
279 MMAL_PARAM_IMAGEFX_BLUR,
280 MMAL_PARAM_IMAGEFX_SATURATION,
281 MMAL_PARAM_IMAGEFX_COLOURSWAP,
282 MMAL_PARAM_IMAGEFX_WASHEDOUT,
283 MMAL_PARAM_IMAGEFX_POSTERISE,
284 MMAL_PARAM_IMAGEFX_COLOURPOINT,
285 MMAL_PARAM_IMAGEFX_COLOURBALANCE,
286 MMAL_PARAM_IMAGEFX_CARTOON,
287};
288
289enum MMAL_PARAM_FLICKERAVOID_T {
290 MMAL_PARAM_FLICKERAVOID_OFF,
291 MMAL_PARAM_FLICKERAVOID_AUTO,
292 MMAL_PARAM_FLICKERAVOID_50HZ,
293 MMAL_PARAM_FLICKERAVOID_60HZ,
294 MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
295};
296
297struct mmal_parameter_awbgains {
298 struct mmal_parameter_rational r_gain; /**< Red gain */
299 struct mmal_parameter_rational b_gain; /**< Blue gain */
300};
301
302/** Manner of video rate control */
303enum mmal_parameter_rate_control_mode {
304 MMAL_VIDEO_RATECONTROL_DEFAULT,
305 MMAL_VIDEO_RATECONTROL_VARIABLE,
306 MMAL_VIDEO_RATECONTROL_CONSTANT,
307 MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
308 MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
309};
310
311enum mmal_video_profile {
312 MMAL_VIDEO_PROFILE_H263_BASELINE,
313 MMAL_VIDEO_PROFILE_H263_H320CODING,
314 MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
315 MMAL_VIDEO_PROFILE_H263_ISWV2,
316 MMAL_VIDEO_PROFILE_H263_ISWV3,
317 MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
318 MMAL_VIDEO_PROFILE_H263_INTERNET,
319 MMAL_VIDEO_PROFILE_H263_INTERLACE,
320 MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
321 MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
322 MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
323 MMAL_VIDEO_PROFILE_MP4V_CORE,
324 MMAL_VIDEO_PROFILE_MP4V_MAIN,
325 MMAL_VIDEO_PROFILE_MP4V_NBIT,
326 MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
327 MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
328 MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
329 MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
330 MMAL_VIDEO_PROFILE_MP4V_HYBRID,
331 MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
332 MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
333 MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
334 MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
335 MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
336 MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
337 MMAL_VIDEO_PROFILE_H264_BASELINE,
338 MMAL_VIDEO_PROFILE_H264_MAIN,
339 MMAL_VIDEO_PROFILE_H264_EXTENDED,
340 MMAL_VIDEO_PROFILE_H264_HIGH,
341 MMAL_VIDEO_PROFILE_H264_HIGH10,
342 MMAL_VIDEO_PROFILE_H264_HIGH422,
343 MMAL_VIDEO_PROFILE_H264_HIGH444,
344 MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
345 MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
346};
347
348enum mmal_video_level {
349 MMAL_VIDEO_LEVEL_H263_10,
350 MMAL_VIDEO_LEVEL_H263_20,
351 MMAL_VIDEO_LEVEL_H263_30,
352 MMAL_VIDEO_LEVEL_H263_40,
353 MMAL_VIDEO_LEVEL_H263_45,
354 MMAL_VIDEO_LEVEL_H263_50,
355 MMAL_VIDEO_LEVEL_H263_60,
356 MMAL_VIDEO_LEVEL_H263_70,
357 MMAL_VIDEO_LEVEL_MP4V_0,
358 MMAL_VIDEO_LEVEL_MP4V_0b,
359 MMAL_VIDEO_LEVEL_MP4V_1,
360 MMAL_VIDEO_LEVEL_MP4V_2,
361 MMAL_VIDEO_LEVEL_MP4V_3,
362 MMAL_VIDEO_LEVEL_MP4V_4,
363 MMAL_VIDEO_LEVEL_MP4V_4a,
364 MMAL_VIDEO_LEVEL_MP4V_5,
365 MMAL_VIDEO_LEVEL_MP4V_6,
366 MMAL_VIDEO_LEVEL_H264_1,
367 MMAL_VIDEO_LEVEL_H264_1b,
368 MMAL_VIDEO_LEVEL_H264_11,
369 MMAL_VIDEO_LEVEL_H264_12,
370 MMAL_VIDEO_LEVEL_H264_13,
371 MMAL_VIDEO_LEVEL_H264_2,
372 MMAL_VIDEO_LEVEL_H264_21,
373 MMAL_VIDEO_LEVEL_H264_22,
374 MMAL_VIDEO_LEVEL_H264_3,
375 MMAL_VIDEO_LEVEL_H264_31,
376 MMAL_VIDEO_LEVEL_H264_32,
377 MMAL_VIDEO_LEVEL_H264_4,
378 MMAL_VIDEO_LEVEL_H264_41,
379 MMAL_VIDEO_LEVEL_H264_42,
380 MMAL_VIDEO_LEVEL_H264_5,
381 MMAL_VIDEO_LEVEL_H264_51,
382 MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
383};
384
385struct mmal_parameter_video_profile {
386 enum mmal_video_profile profile;
387 enum mmal_video_level level;
388};
389
390/* video parameters */
391
392enum mmal_parameter_video_type {
393 /** @ref MMAL_DISPLAYREGION_T */
394 MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
395
396 /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
397 MMAL_PARAMETER_SUPPORTED_PROFILES,
398
399 /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
400 MMAL_PARAMETER_PROFILE,
401
402 /** @ref MMAL_PARAMETER_UINT32_T */
403 MMAL_PARAMETER_INTRAPERIOD,
404
405 /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
406 MMAL_PARAMETER_RATECONTROL,
407
408 /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
409 MMAL_PARAMETER_NALUNITFORMAT,
410
411 /** @ref MMAL_PARAMETER_BOOLEAN_T */
412 MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
413
414 /** @ref MMAL_PARAMETER_UINT32_T.
415 * Setting the value to zero resets to the default (one slice per frame).
416 */
417 MMAL_PARAMETER_MB_ROWS_PER_SLICE,
418
419 /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
420 MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
421
422 /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
423 MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
424
425 /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
426 MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
427
428 /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
429 MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
430 /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
431 MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
432
433 /** @ref MMAL_PARAMETER_BOOLEAN_T. */
434 MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
435
436 /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
437 MMAL_PARAMETER_VIDEO_BIT_RATE,
438
439 /** @ref MMAL_PARAMETER_FRAME_RATE_T */
440 MMAL_PARAMETER_VIDEO_FRAME_RATE,
441
442 /** @ref MMAL_PARAMETER_UINT32_T. */
443 MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
444
445 /** @ref MMAL_PARAMETER_UINT32_T. */
446 MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
447
448 /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
449 MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
450
451 MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
452 /** @ref MMAL_PARAMETER_UINT32_T.
453 * Changing this parameter from the default can reduce frame rate
454 * because image buffers need to be re-pitched.
455 */
456 MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
457
458 /** @ref MMAL_PARAMETER_UINT32_T.
459 * Changing this parameter from the default can reduce frame rate
460 * because image buffers need to be re-pitched.
461 */
462 MMAL_PARAMETER_VIDEO_ALIGN_VERT,
463
464 /** @ref MMAL_PARAMETER_BOOLEAN_T. */
465 MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
466
467 /** @ref MMAL_PARAMETER_UINT32_T. */
468 MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
469
470 /**< @ref MMAL_PARAMETER_UINT32_T. */
471 MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
472
473 /**< @ref MMAL_PARAMETER_UINT32_T. */
474 MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
475
476 /** @ref MMAL_PARAMETER_UINT32_T */
477 MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
478
479 /** @ref MMAL_PARAMETER_UINT32_T. */
480 MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
481
482 /* H264 specific parameters */
483
484 /** @ref MMAL_PARAMETER_BOOLEAN_T. */
485 MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
486
487 /** @ref MMAL_PARAMETER_BOOLEAN_T. */
488 MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
489
490 /** @ref MMAL_PARAMETER_BOOLEAN_T. */
491 MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
492
493 /** @ref MMAL_PARAMETER_UINT32_T. */
494 MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
495
496 /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
497 MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
498
499 /** @ref MMAL_PARAMETER_BOOLEAN_T */
500 MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
501
502 /** @ref MMAL_PARAMETER_BOOLEAN_T */
503 MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
504
505 /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
506 MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
507
508 /** @ref MMAL_PARAMETER_BOOLEAN_T */
509 MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
510
511 /** @ref MMAL_PARAMETER_BOOLEAN_T */
512 MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
513
514 /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
515 MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
516
517 /** @ref MMAL_PARAMETER_BYTES_T */
518 MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
519
520 /**< @ref MMAL_PARAMETER_BOOLEAN_T */
521 MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
522
523 /**< @ref MMAL_PARAMETER_BOOLEAN_T */
524 MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
525
526 /**< @ref MMAL_PARAMETER_BOOLEAN_T */
527 MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
528};
529
530/** Valid mirror modes */
531enum mmal_parameter_mirror {
532 MMAL_PARAM_MIRROR_NONE,
533 MMAL_PARAM_MIRROR_VERTICAL,
534 MMAL_PARAM_MIRROR_HORIZONTAL,
535 MMAL_PARAM_MIRROR_BOTH,
536};
537
538enum mmal_parameter_displaytransform {
539 MMAL_DISPLAY_ROT0 = 0,
540 MMAL_DISPLAY_MIRROR_ROT0 = 1,
541 MMAL_DISPLAY_MIRROR_ROT180 = 2,
542 MMAL_DISPLAY_ROT180 = 3,
543 MMAL_DISPLAY_MIRROR_ROT90 = 4,
544 MMAL_DISPLAY_ROT270 = 5,
545 MMAL_DISPLAY_ROT90 = 6,
546 MMAL_DISPLAY_MIRROR_ROT270 = 7,
547};
548
549enum mmal_parameter_displaymode {
550 MMAL_DISPLAY_MODE_FILL = 0,
551 MMAL_DISPLAY_MODE_LETTERBOX = 1,
552};
553
554enum mmal_parameter_displayset {
555 MMAL_DISPLAY_SET_NONE = 0,
556 MMAL_DISPLAY_SET_NUM = 1,
557 MMAL_DISPLAY_SET_FULLSCREEN = 2,
558 MMAL_DISPLAY_SET_TRANSFORM = 4,
559 MMAL_DISPLAY_SET_DEST_RECT = 8,
560 MMAL_DISPLAY_SET_SRC_RECT = 0x10,
561 MMAL_DISPLAY_SET_MODE = 0x20,
562 MMAL_DISPLAY_SET_PIXEL = 0x40,
563 MMAL_DISPLAY_SET_NOASPECT = 0x80,
564 MMAL_DISPLAY_SET_LAYER = 0x100,
565 MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
566 MMAL_DISPLAY_SET_ALPHA = 0x400,
567};
568
569struct mmal_parameter_displayregion {
570 /** Bitfield that indicates which fields are set and should be
571 * used. All other fields will maintain their current value.
572 * \ref MMAL_DISPLAYSET_T defines the bits that can be
573 * combined.
574 */
575 u32 set;
576
577 /** Describes the display output device, with 0 typically
578 * being a directly connected LCD display. The actual values
579 * will depend on the hardware. Code using hard-wired numbers
580 * (e.g. 2) is certain to fail.
581 */
582
583 u32 display_num;
584 /** Indicates that we are using the full device screen area,
585 * rather than a window of the display. If zero, then
586 * dest_rect is used to specify a region of the display to
587 * use.
588 */
589
590 s32 fullscreen;
591 /** Indicates any rotation or flipping used to map frames onto
592 * the natural display orientation.
593 */
594 u32 transform; /* enum mmal_parameter_displaytransform */
595
596 /** Where to display the frame within the screen, if
597 * fullscreen is zero.
598 */
599 struct vchiq_mmal_rect dest_rect;
600
601 /** Indicates which area of the frame to display. If all
602 * values are zero, the whole frame will be used.
603 */
604 struct vchiq_mmal_rect src_rect;
605
606 /** If set to non-zero, indicates that any display scaling
607 * should disregard the aspect ratio of the frame region being
608 * displayed.
609 */
610 s32 noaspect;
611
612 /** Indicates how the image should be scaled to fit the
613 * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
614 * that the image should fill the screen by potentially
615 * cropping the frames. Setting \code mode \endcode to \code
616 * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
617 * source region should be displayed and black bars added if
618 * necessary.
619 */
620 u32 mode; /* enum mmal_parameter_displaymode */
621
622 /** If non-zero, defines the width of a source pixel relative
623 * to \code pixel_y \endcode. If zero, then pixels default to
624 * being square.
625 */
626 u32 pixel_x;
627
628 /** If non-zero, defines the height of a source pixel relative
629 * to \code pixel_x \endcode. If zero, then pixels default to
630 * being square.
631 */
632 u32 pixel_y;
633
634 /** Sets the relative depth of the images, with greater values
635 * being in front of smaller values.
636 */
637 u32 layer;
638
639 /** Set to non-zero to ensure copy protection is used on
640 * output.
641 */
642 s32 copyprotect_required;
643
644 /** Level of opacity of the layer, where zero is fully
645 * transparent and 255 is fully opaque.
646 */
647 u32 alpha;
648};
649
650#define MMAL_MAX_IMAGEFX_PARAMETERS 5
651
652struct mmal_parameter_imagefx_parameters {
653 enum mmal_parameter_imagefx effect;
654 u32 num_effect_params;
655 u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
656};
657
658#define MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS 4
659#define MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES 2
660#define MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN 16
661
662struct mmal_parameter_camera_info_camera_t {
663 u32 port_id;
664 u32 max_width;
665 u32 max_height;
666 u32 lens_present;
667 u8 camera_name[MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN];
668};
669
670enum mmal_parameter_camera_info_flash_type_t {
671 /* Make values explicit to ensure they match values in config ini */
672 MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_XENON = 0,
673 MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_LED = 1,
674 MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_OTHER = 2,
675 MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_MAX = 0x7FFFFFFF
676};
677
678struct mmal_parameter_camera_info_flash_t {
679 enum mmal_parameter_camera_info_flash_type_t flash_type;
680};
681
682struct mmal_parameter_camera_info_t {
683 u32 num_cameras;
684 u32 num_flashes;
685 struct mmal_parameter_camera_info_camera_t
686 cameras[MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS];
687 struct mmal_parameter_camera_info_flash_t
688 flashes[MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES];
689};
diff --git a/drivers/staging/media/platform/bcm2835/mmal-vchiq.c b/drivers/staging/media/platform/bcm2835/mmal-vchiq.c
new file mode 100644
index 000000000000..f0639ee6c8b9
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-vchiq.c
@@ -0,0 +1,1913 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 *
15 * V4L2 driver MMAL vchiq interface code
16 */
17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
20#include <linux/errno.h>
21#include <linux/kernel.h>
22#include <linux/mutex.h>
23#include <linux/mm.h>
24#include <linux/slab.h>
25#include <linux/completion.h>
26#include <linux/vmalloc.h>
27#include <asm/cacheflush.h>
28#include <media/videobuf2-vmalloc.h>
29
30#include "mmal-common.h"
31#include "mmal-vchiq.h"
32#include "mmal-msg.h"
33
34#define USE_VCHIQ_ARM
35#include "interface/vchi/vchi.h"
36
37/* maximum number of components supported */
38#define VCHIQ_MMAL_MAX_COMPONENTS 4
39
40/*#define FULL_MSG_DUMP 1*/
41
42#ifdef DEBUG
43static const char *const msg_type_names[] = {
44 "UNKNOWN",
45 "QUIT",
46 "SERVICE_CLOSED",
47 "GET_VERSION",
48 "COMPONENT_CREATE",
49 "COMPONENT_DESTROY",
50 "COMPONENT_ENABLE",
51 "COMPONENT_DISABLE",
52 "PORT_INFO_GET",
53 "PORT_INFO_SET",
54 "PORT_ACTION",
55 "BUFFER_FROM_HOST",
56 "BUFFER_TO_HOST",
57 "GET_STATS",
58 "PORT_PARAMETER_SET",
59 "PORT_PARAMETER_GET",
60 "EVENT_TO_HOST",
61 "GET_CORE_STATS_FOR_PORT",
62 "OPAQUE_ALLOCATOR",
63 "CONSUME_MEM",
64 "LMK",
65 "OPAQUE_ALLOCATOR_DESC",
66 "DRM_GET_LHS32",
67 "DRM_GET_TIME",
68 "BUFFER_FROM_HOST_ZEROLEN",
69 "PORT_FLUSH",
70 "HOST_LOG",
71};
72#endif
73
74static const char *const port_action_type_names[] = {
75 "UNKNOWN",
76 "ENABLE",
77 "DISABLE",
78 "FLUSH",
79 "CONNECT",
80 "DISCONNECT",
81 "SET_REQUIREMENTS",
82};
83
84#if defined(DEBUG)
85#if defined(FULL_MSG_DUMP)
86#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
87 do { \
88 pr_debug(TITLE" type:%s(%d) length:%d\n", \
89 msg_type_names[(MSG)->h.type], \
90 (MSG)->h.type, (MSG_LEN)); \
91 print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
92 16, 4, (MSG), \
93 sizeof(struct mmal_msg_header), 1); \
94 print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
95 16, 4, \
96 ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
97 (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
98 } while (0)
99#else
100#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
101 { \
102 pr_debug(TITLE" type:%s(%d) length:%d\n", \
103 msg_type_names[(MSG)->h.type], \
104 (MSG)->h.type, (MSG_LEN)); \
105 }
106#endif
107#else
108#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
109#endif
110
111/* normal message context */
112struct mmal_msg_context {
113 union {
114 struct {
115 /* work struct for defered callback - must come first */
116 struct work_struct work;
117 /* mmal instance */
118 struct vchiq_mmal_instance *instance;
119 /* mmal port */
120 struct vchiq_mmal_port *port;
121 /* actual buffer used to store bulk reply */
122 struct mmal_buffer *buffer;
123 /* amount of buffer used */
124 unsigned long buffer_used;
125 /* MMAL buffer flags */
126 u32 mmal_flags;
127 /* Presentation and Decode timestamps */
128 s64 pts;
129 s64 dts;
130
131 int status; /* context status */
132
133 } bulk; /* bulk data */
134
135 struct {
136 /* message handle to release */
137 VCHI_HELD_MSG_T msg_handle;
138 /* pointer to received message */
139 struct mmal_msg *msg;
140 /* received message length */
141 u32 msg_len;
142 /* completion upon reply */
143 struct completion cmplt;
144 } sync; /* synchronous response */
145 } u;
146
147};
148
149struct vchiq_mmal_instance {
150 VCHI_SERVICE_HANDLE_T handle;
151
152 /* ensure serialised access to service */
153 struct mutex vchiq_mutex;
154
155 /* ensure serialised access to bulk operations */
156 struct mutex bulk_mutex;
157
158 /* vmalloc page to receive scratch bulk xfers into */
159 void *bulk_scratch;
160
161 /* component to use next */
162 int component_idx;
163 struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
164};
165
166static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
167 *instance)
168{
169 struct mmal_msg_context *msg_context;
170
171 /* todo: should this be allocated from a pool to avoid kmalloc */
172 msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
173 memset(msg_context, 0, sizeof(*msg_context));
174
175 return msg_context;
176}
177
178static void release_msg_context(struct mmal_msg_context *msg_context)
179{
180 kfree(msg_context);
181}
182
183/* deals with receipt of event to host message */
184static void event_to_host_cb(struct vchiq_mmal_instance *instance,
185 struct mmal_msg *msg, u32 msg_len)
186{
187 pr_debug("unhandled event\n");
188 pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
189 msg->u.event_to_host.client_component,
190 msg->u.event_to_host.port_type,
191 msg->u.event_to_host.port_num,
192 msg->u.event_to_host.cmd, msg->u.event_to_host.length);
193}
194
195/* workqueue scheduled callback
196 *
197 * we do this because it is important we do not call any other vchiq
198 * sync calls from witin the message delivery thread
199 */
200static void buffer_work_cb(struct work_struct *work)
201{
202 struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
203
204 msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
205 msg_context->u.bulk.port,
206 msg_context->u.bulk.status,
207 msg_context->u.bulk.buffer,
208 msg_context->u.bulk.buffer_used,
209 msg_context->u.bulk.mmal_flags,
210 msg_context->u.bulk.dts,
211 msg_context->u.bulk.pts);
212
213 /* release message context */
214 release_msg_context(msg_context);
215}
216
217/* enqueue a bulk receive for a given message context */
218static int bulk_receive(struct vchiq_mmal_instance *instance,
219 struct mmal_msg *msg,
220 struct mmal_msg_context *msg_context)
221{
222 unsigned long rd_len;
223 unsigned long flags = 0;
224 int ret;
225
226 /* bulk mutex stops other bulk operations while we have a
227 * receive in progress - released in callback
228 */
229 ret = mutex_lock_interruptible(&instance->bulk_mutex);
230 if (ret != 0)
231 return ret;
232
233 rd_len = msg->u.buffer_from_host.buffer_header.length;
234
235 /* take buffer from queue */
236 spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
237 if (list_empty(&msg_context->u.bulk.port->buffers)) {
238 spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
239 pr_err("buffer list empty trying to submit bulk receive\n");
240
241 /* todo: this is a serious error, we should never have
242 * committed a buffer_to_host operation to the mmal
243 * port without the buffer to back it up (underflow
244 * handling) and there is no obvious way to deal with
245 * this - how is the mmal servie going to react when
246 * we fail to do the xfer and reschedule a buffer when
247 * it arrives? perhaps a starved flag to indicate a
248 * waiting bulk receive?
249 */
250
251 mutex_unlock(&instance->bulk_mutex);
252
253 return -EINVAL;
254 }
255
256 msg_context->u.bulk.buffer =
257 list_entry(msg_context->u.bulk.port->buffers.next,
258 struct mmal_buffer, list);
259 list_del(&msg_context->u.bulk.buffer->list);
260
261 spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
262
263 /* ensure we do not overrun the available buffer */
264 if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
265 rd_len = msg_context->u.bulk.buffer->buffer_size;
266 pr_warn("short read as not enough receive buffer space\n");
267 /* todo: is this the correct response, what happens to
268 * the rest of the message data?
269 */
270 }
271
272 /* store length */
273 msg_context->u.bulk.buffer_used = rd_len;
274 msg_context->u.bulk.mmal_flags =
275 msg->u.buffer_from_host.buffer_header.flags;
276 msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
277 msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
278
279 // only need to flush L1 cache here, as VCHIQ takes care of the L2
280 // cache.
281 __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
282
283 /* queue the bulk submission */
284 vchi_service_use(instance->handle);
285 ret = vchi_bulk_queue_receive(instance->handle,
286 msg_context->u.bulk.buffer->buffer,
287 /* Actual receive needs to be a multiple
288 * of 4 bytes
289 */
290 (rd_len + 3) & ~3,
291 VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
292 VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
293 msg_context);
294
295 vchi_service_release(instance->handle);
296
297 if (ret != 0) {
298 /* callback will not be clearing the mutex */
299 mutex_unlock(&instance->bulk_mutex);
300 }
301
302 return ret;
303}
304
305/* enque a dummy bulk receive for a given message context */
306static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
307 struct mmal_msg_context *msg_context)
308{
309 int ret;
310
311 /* bulk mutex stops other bulk operations while we have a
312 * receive in progress - released in callback
313 */
314 ret = mutex_lock_interruptible(&instance->bulk_mutex);
315 if (ret != 0)
316 return ret;
317
318 /* zero length indicates this was a dummy transfer */
319 msg_context->u.bulk.buffer_used = 0;
320
321 /* queue the bulk submission */
322 vchi_service_use(instance->handle);
323
324 ret = vchi_bulk_queue_receive(instance->handle,
325 instance->bulk_scratch,
326 8,
327 VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
328 VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
329 msg_context);
330
331 vchi_service_release(instance->handle);
332
333 if (ret != 0) {
334 /* callback will not be clearing the mutex */
335 mutex_unlock(&instance->bulk_mutex);
336 }
337
338 return ret;
339}
340
341/* data in message, memcpy from packet into output buffer */
342static int inline_receive(struct vchiq_mmal_instance *instance,
343 struct mmal_msg *msg,
344 struct mmal_msg_context *msg_context)
345{
346 unsigned long flags = 0;
347
348 /* take buffer from queue */
349 spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
350 if (list_empty(&msg_context->u.bulk.port->buffers)) {
351 spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
352 pr_err("buffer list empty trying to receive inline\n");
353
354 /* todo: this is a serious error, we should never have
355 * committed a buffer_to_host operation to the mmal
356 * port without the buffer to back it up (with
357 * underflow handling) and there is no obvious way to
358 * deal with this. Less bad than the bulk case as we
359 * can just drop this on the floor but...unhelpful
360 */
361 return -EINVAL;
362 }
363
364 msg_context->u.bulk.buffer =
365 list_entry(msg_context->u.bulk.port->buffers.next,
366 struct mmal_buffer, list);
367 list_del(&msg_context->u.bulk.buffer->list);
368
369 spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
370
371 memcpy(msg_context->u.bulk.buffer->buffer,
372 msg->u.buffer_from_host.short_data,
373 msg->u.buffer_from_host.payload_in_message);
374
375 msg_context->u.bulk.buffer_used =
376 msg->u.buffer_from_host.payload_in_message;
377
378 return 0;
379}
380
381/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
382static int
383buffer_from_host(struct vchiq_mmal_instance *instance,
384 struct vchiq_mmal_port *port, struct mmal_buffer *buf)
385{
386 struct mmal_msg_context *msg_context;
387 struct mmal_msg m;
388 int ret;
389
390 pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
391
392 /* bulk mutex stops other bulk operations while we
393 * have a receive in progress
394 */
395 if (mutex_lock_interruptible(&instance->bulk_mutex))
396 return -EINTR;
397
398 /* get context */
399 msg_context = get_msg_context(instance);
400 if (msg_context == NULL)
401 return -ENOMEM;
402
403 /* store bulk message context for when data arrives */
404 msg_context->u.bulk.instance = instance;
405 msg_context->u.bulk.port = port;
406 msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
407 msg_context->u.bulk.buffer_used = 0;
408
409 /* initialise work structure ready to schedule callback */
410 INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
411
412 /* prep the buffer from host message */
413 memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
414
415 m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
416 m.h.magic = MMAL_MAGIC;
417 m.h.context = msg_context;
418 m.h.status = 0;
419
420 /* drvbuf is our private data passed back */
421 m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
422 m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
423 m.u.buffer_from_host.drvbuf.port_handle = port->handle;
424 m.u.buffer_from_host.drvbuf.client_context = msg_context;
425
426 /* buffer header */
427 m.u.buffer_from_host.buffer_header.cmd = 0;
428 m.u.buffer_from_host.buffer_header.data = buf->buffer;
429 m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
430 m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
431 m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
432 m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
433 m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
434 m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
435
436 /* clear buffer type sepecific data */
437 memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
438 sizeof(m.u.buffer_from_host.buffer_header_type_specific));
439
440 /* no payload in message */
441 m.u.buffer_from_host.payload_in_message = 0;
442
443 vchi_service_use(instance->handle);
444
445 ret = vchi_queue_kernel_message(instance->handle,
446 &m,
447 sizeof(struct mmal_msg_header) +
448 sizeof(m.u.buffer_from_host));
449
450 if (ret != 0) {
451 release_msg_context(msg_context);
452 /* todo: is this correct error value? */
453 }
454
455 vchi_service_release(instance->handle);
456
457 mutex_unlock(&instance->bulk_mutex);
458
459 return ret;
460}
461
462/* submit a buffer to the mmal sevice
463 *
464 * the buffer_from_host uses size data from the ports next available
465 * mmal_buffer and deals with there being no buffer available by
466 * incrementing the underflow for later
467 */
468static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
469 struct vchiq_mmal_port *port)
470{
471 int ret;
472 struct mmal_buffer *buf;
473 unsigned long flags = 0;
474
475 if (!port->enabled)
476 return -EINVAL;
477
478 /* peek buffer from queue */
479 spin_lock_irqsave(&port->slock, flags);
480 if (list_empty(&port->buffers)) {
481 port->buffer_underflow++;
482 spin_unlock_irqrestore(&port->slock, flags);
483 return -ENOSPC;
484 }
485
486 buf = list_entry(port->buffers.next, struct mmal_buffer, list);
487
488 spin_unlock_irqrestore(&port->slock, flags);
489
490 /* issue buffer to mmal service */
491 ret = buffer_from_host(instance, port, buf);
492 if (ret) {
493 pr_err("adding buffer header failed\n");
494 /* todo: how should this be dealt with */
495 }
496
497 return ret;
498}
499
500/* deals with receipt of buffer to host message */
501static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
502 struct mmal_msg *msg, u32 msg_len)
503{
504 struct mmal_msg_context *msg_context;
505
506 pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
507 instance, msg, msg_len);
508
509 if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
510 msg_context = msg->u.buffer_from_host.drvbuf.client_context;
511 } else {
512 pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
513 return;
514 }
515
516 if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
517 /* message reception had an error */
518 pr_warn("error %d in reply\n", msg->h.status);
519
520 msg_context->u.bulk.status = msg->h.status;
521
522 } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
523 /* empty buffer */
524 if (msg->u.buffer_from_host.buffer_header.flags &
525 MMAL_BUFFER_HEADER_FLAG_EOS) {
526 msg_context->u.bulk.status =
527 dummy_bulk_receive(instance, msg_context);
528 if (msg_context->u.bulk.status == 0)
529 return; /* successful bulk submission, bulk
530 * completion will trigger callback
531 */
532 } else {
533 /* do callback with empty buffer - not EOS though */
534 msg_context->u.bulk.status = 0;
535 msg_context->u.bulk.buffer_used = 0;
536 }
537 } else if (msg->u.buffer_from_host.payload_in_message == 0) {
538 /* data is not in message, queue a bulk receive */
539 msg_context->u.bulk.status =
540 bulk_receive(instance, msg, msg_context);
541 if (msg_context->u.bulk.status == 0)
542 return; /* successful bulk submission, bulk
543 * completion will trigger callback
544 */
545
546 /* failed to submit buffer, this will end badly */
547 pr_err("error %d on bulk submission\n",
548 msg_context->u.bulk.status);
549
550 } else if (msg->u.buffer_from_host.payload_in_message <=
551 MMAL_VC_SHORT_DATA) {
552 /* data payload within message */
553 msg_context->u.bulk.status = inline_receive(instance, msg,
554 msg_context);
555 } else {
556 pr_err("message with invalid short payload\n");
557
558 /* signal error */
559 msg_context->u.bulk.status = -EINVAL;
560 msg_context->u.bulk.buffer_used =
561 msg->u.buffer_from_host.payload_in_message;
562 }
563
564 /* replace the buffer header */
565 port_buffer_from_host(instance, msg_context->u.bulk.port);
566
567 /* schedule the port callback */
568 schedule_work(&msg_context->u.bulk.work);
569}
570
571static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
572 struct mmal_msg_context *msg_context)
573{
574 /* bulk receive operation complete */
575 mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
576
577 /* replace the buffer header */
578 port_buffer_from_host(msg_context->u.bulk.instance,
579 msg_context->u.bulk.port);
580
581 msg_context->u.bulk.status = 0;
582
583 /* schedule the port callback */
584 schedule_work(&msg_context->u.bulk.work);
585}
586
587static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
588 struct mmal_msg_context *msg_context)
589{
590 pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
591
592 /* bulk receive operation complete */
593 mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
594
595 /* replace the buffer header */
596 port_buffer_from_host(msg_context->u.bulk.instance,
597 msg_context->u.bulk.port);
598
599 msg_context->u.bulk.status = -EINTR;
600
601 schedule_work(&msg_context->u.bulk.work);
602}
603
604/* incoming event service callback */
605static void service_callback(void *param,
606 const VCHI_CALLBACK_REASON_T reason,
607 void *bulk_ctx)
608{
609 struct vchiq_mmal_instance *instance = param;
610 int status;
611 u32 msg_len;
612 struct mmal_msg *msg;
613 VCHI_HELD_MSG_T msg_handle;
614
615 if (!instance) {
616 pr_err("Message callback passed NULL instance\n");
617 return;
618 }
619
620 switch (reason) {
621 case VCHI_CALLBACK_MSG_AVAILABLE:
622 status = vchi_msg_hold(instance->handle, (void **)&msg,
623 &msg_len, VCHI_FLAGS_NONE, &msg_handle);
624 if (status) {
625 pr_err("Unable to dequeue a message (%d)\n", status);
626 break;
627 }
628
629 DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
630
631 /* handling is different for buffer messages */
632 switch (msg->h.type) {
633 case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
634 vchi_held_msg_release(&msg_handle);
635 break;
636
637 case MMAL_MSG_TYPE_EVENT_TO_HOST:
638 event_to_host_cb(instance, msg, msg_len);
639 vchi_held_msg_release(&msg_handle);
640
641 break;
642
643 case MMAL_MSG_TYPE_BUFFER_TO_HOST:
644 buffer_to_host_cb(instance, msg, msg_len);
645 vchi_held_msg_release(&msg_handle);
646 break;
647
648 default:
649 /* messages dependent on header context to complete */
650
651 /* todo: the msg.context really ought to be sanity
652 * checked before we just use it, afaict it comes back
653 * and is used raw from the videocore. Perhaps it
654 * should be verified the address lies in the kernel
655 * address space.
656 */
657 if (msg->h.context == NULL) {
658 pr_err("received message context was null!\n");
659 vchi_held_msg_release(&msg_handle);
660 break;
661 }
662
663 /* fill in context values */
664 msg->h.context->u.sync.msg_handle = msg_handle;
665 msg->h.context->u.sync.msg = msg;
666 msg->h.context->u.sync.msg_len = msg_len;
667
668 /* todo: should this check (completion_done()
669 * == 1) for no one waiting? or do we need a
670 * flag to tell us the completion has been
671 * interrupted so we can free the message and
672 * its context. This probably also solves the
673 * message arriving after interruption todo
674 * below
675 */
676
677 /* complete message so caller knows it happened */
678 complete(&msg->h.context->u.sync.cmplt);
679 break;
680 }
681
682 break;
683
684 case VCHI_CALLBACK_BULK_RECEIVED:
685 bulk_receive_cb(instance, bulk_ctx);
686 break;
687
688 case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
689 bulk_abort_cb(instance, bulk_ctx);
690 break;
691
692 case VCHI_CALLBACK_SERVICE_CLOSED:
693 /* TODO: consider if this requires action if received when
694 * driver is not explicitly closing the service
695 */
696 break;
697
698 default:
699 pr_err("Received unhandled message reason %d\n", reason);
700 break;
701 }
702}
703
704static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
705 struct mmal_msg *msg,
706 unsigned int payload_len,
707 struct mmal_msg **msg_out,
708 VCHI_HELD_MSG_T *msg_handle_out)
709{
710 struct mmal_msg_context msg_context;
711 int ret;
712
713 /* payload size must not cause message to exceed max size */
714 if (payload_len >
715 (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
716 pr_err("payload length %d exceeds max:%d\n", payload_len,
717 (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
718 return -EINVAL;
719 }
720
721 init_completion(&msg_context.u.sync.cmplt);
722
723 msg->h.magic = MMAL_MAGIC;
724 msg->h.context = &msg_context;
725 msg->h.status = 0;
726
727 DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
728 ">>> sync message");
729
730 vchi_service_use(instance->handle);
731
732 ret = vchi_queue_kernel_message(instance->handle,
733 msg,
734 sizeof(struct mmal_msg_header) +
735 payload_len);
736
737 vchi_service_release(instance->handle);
738
739 if (ret) {
740 pr_err("error %d queuing message\n", ret);
741 return ret;
742 }
743
744 ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3 * HZ);
745 if (ret <= 0) {
746 pr_err("error %d waiting for sync completion\n", ret);
747 if (ret == 0)
748 ret = -ETIME;
749 /* todo: what happens if the message arrives after aborting */
750 return ret;
751 }
752
753 *msg_out = msg_context.u.sync.msg;
754 *msg_handle_out = msg_context.u.sync.msg_handle;
755
756 return 0;
757}
758
759static void dump_port_info(struct vchiq_mmal_port *port)
760{
761 pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
762
763 pr_debug("buffer minimum num:%d size:%d align:%d\n",
764 port->minimum_buffer.num,
765 port->minimum_buffer.size, port->minimum_buffer.alignment);
766
767 pr_debug("buffer recommended num:%d size:%d align:%d\n",
768 port->recommended_buffer.num,
769 port->recommended_buffer.size,
770 port->recommended_buffer.alignment);
771
772 pr_debug("buffer current values num:%d size:%d align:%d\n",
773 port->current_buffer.num,
774 port->current_buffer.size, port->current_buffer.alignment);
775
776 pr_debug("elementry stream: type:%d encoding:0x%x variant:0x%x\n",
777 port->format.type,
778 port->format.encoding, port->format.encoding_variant);
779
780 pr_debug(" bitrate:%d flags:0x%x\n",
781 port->format.bitrate, port->format.flags);
782
783 if (port->format.type == MMAL_ES_TYPE_VIDEO) {
784 pr_debug
785 ("es video format: width:%d height:%d colourspace:0x%x\n",
786 port->es.video.width, port->es.video.height,
787 port->es.video.color_space);
788
789 pr_debug(" : crop xywh %d,%d,%d,%d\n",
790 port->es.video.crop.x,
791 port->es.video.crop.y,
792 port->es.video.crop.width, port->es.video.crop.height);
793 pr_debug(" : framerate %d/%d aspect %d/%d\n",
794 port->es.video.frame_rate.num,
795 port->es.video.frame_rate.den,
796 port->es.video.par.num, port->es.video.par.den);
797 }
798}
799
800static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
801{
802 /* todo do readonly fields need setting at all? */
803 p->type = port->type;
804 p->index = port->index;
805 p->index_all = 0;
806 p->is_enabled = port->enabled;
807 p->buffer_num_min = port->minimum_buffer.num;
808 p->buffer_size_min = port->minimum_buffer.size;
809 p->buffer_alignment_min = port->minimum_buffer.alignment;
810 p->buffer_num_recommended = port->recommended_buffer.num;
811 p->buffer_size_recommended = port->recommended_buffer.size;
812
813 /* only three writable fields in a port */
814 p->buffer_num = port->current_buffer.num;
815 p->buffer_size = port->current_buffer.size;
816 p->userdata = port;
817}
818
819static int port_info_set(struct vchiq_mmal_instance *instance,
820 struct vchiq_mmal_port *port)
821{
822 int ret;
823 struct mmal_msg m;
824 struct mmal_msg *rmsg;
825 VCHI_HELD_MSG_T rmsg_handle;
826
827 pr_debug("setting port info port %p\n", port);
828 if (!port)
829 return -1;
830 dump_port_info(port);
831
832 m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
833
834 m.u.port_info_set.component_handle = port->component->handle;
835 m.u.port_info_set.port_type = port->type;
836 m.u.port_info_set.port_index = port->index;
837
838 port_to_mmal_msg(port, &m.u.port_info_set.port);
839
840 /* elementry stream format setup */
841 m.u.port_info_set.format.type = port->format.type;
842 m.u.port_info_set.format.encoding = port->format.encoding;
843 m.u.port_info_set.format.encoding_variant =
844 port->format.encoding_variant;
845 m.u.port_info_set.format.bitrate = port->format.bitrate;
846 m.u.port_info_set.format.flags = port->format.flags;
847
848 memcpy(&m.u.port_info_set.es, &port->es,
849 sizeof(union mmal_es_specific_format));
850
851 m.u.port_info_set.format.extradata_size = port->format.extradata_size;
852 memcpy(&m.u.port_info_set.extradata, port->format.extradata,
853 port->format.extradata_size);
854
855 ret = send_synchronous_mmal_msg(instance, &m,
856 sizeof(m.u.port_info_set),
857 &rmsg, &rmsg_handle);
858 if (ret)
859 return ret;
860
861 if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
862 /* got an unexpected message type in reply */
863 ret = -EINVAL;
864 goto release_msg;
865 }
866
867 /* return operation status */
868 ret = -rmsg->u.port_info_get_reply.status;
869
870 pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
871 port->component->handle, port->handle);
872
873release_msg:
874 vchi_held_msg_release(&rmsg_handle);
875
876 return ret;
877}
878
879/* use port info get message to retrieve port information */
880static int port_info_get(struct vchiq_mmal_instance *instance,
881 struct vchiq_mmal_port *port)
882{
883 int ret;
884 struct mmal_msg m;
885 struct mmal_msg *rmsg;
886 VCHI_HELD_MSG_T rmsg_handle;
887
888 /* port info time */
889 m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
890 m.u.port_info_get.component_handle = port->component->handle;
891 m.u.port_info_get.port_type = port->type;
892 m.u.port_info_get.index = port->index;
893
894 ret = send_synchronous_mmal_msg(instance, &m,
895 sizeof(m.u.port_info_get),
896 &rmsg, &rmsg_handle);
897 if (ret)
898 return ret;
899
900 if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
901 /* got an unexpected message type in reply */
902 ret = -EINVAL;
903 goto release_msg;
904 }
905
906 /* return operation status */
907 ret = -rmsg->u.port_info_get_reply.status;
908 if (ret != MMAL_MSG_STATUS_SUCCESS)
909 goto release_msg;
910
911 if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
912 port->enabled = false;
913 else
914 port->enabled = true;
915
916 /* copy the values out of the message */
917 port->handle = rmsg->u.port_info_get_reply.port_handle;
918
919 /* port type and index cached to use on port info set because
920 * it does not use a port handle
921 */
922 port->type = rmsg->u.port_info_get_reply.port_type;
923 port->index = rmsg->u.port_info_get_reply.port_index;
924
925 port->minimum_buffer.num =
926 rmsg->u.port_info_get_reply.port.buffer_num_min;
927 port->minimum_buffer.size =
928 rmsg->u.port_info_get_reply.port.buffer_size_min;
929 port->minimum_buffer.alignment =
930 rmsg->u.port_info_get_reply.port.buffer_alignment_min;
931
932 port->recommended_buffer.alignment =
933 rmsg->u.port_info_get_reply.port.buffer_alignment_min;
934 port->recommended_buffer.num =
935 rmsg->u.port_info_get_reply.port.buffer_num_recommended;
936
937 port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
938 port->current_buffer.size =
939 rmsg->u.port_info_get_reply.port.buffer_size;
940
941 /* stream format */
942 port->format.type = rmsg->u.port_info_get_reply.format.type;
943 port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
944 port->format.encoding_variant =
945 rmsg->u.port_info_get_reply.format.encoding_variant;
946 port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
947 port->format.flags = rmsg->u.port_info_get_reply.format.flags;
948
949 /* elementry stream format */
950 memcpy(&port->es,
951 &rmsg->u.port_info_get_reply.es,
952 sizeof(union mmal_es_specific_format));
953 port->format.es = &port->es;
954
955 port->format.extradata_size =
956 rmsg->u.port_info_get_reply.format.extradata_size;
957 memcpy(port->format.extradata,
958 rmsg->u.port_info_get_reply.extradata,
959 port->format.extradata_size);
960
961 pr_debug("received port info\n");
962 dump_port_info(port);
963
964release_msg:
965
966 pr_debug("%s:result:%d component:0x%x port:%d\n",
967 __func__, ret, port->component->handle, port->handle);
968
969 vchi_held_msg_release(&rmsg_handle);
970
971 return ret;
972}
973
974/* create comonent on vc */
975static int create_component(struct vchiq_mmal_instance *instance,
976 struct vchiq_mmal_component *component,
977 const char *name)
978{
979 int ret;
980 struct mmal_msg m;
981 struct mmal_msg *rmsg;
982 VCHI_HELD_MSG_T rmsg_handle;
983
984 /* build component create message */
985 m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
986 m.u.component_create.client_component = component;
987 strncpy(m.u.component_create.name, name,
988 sizeof(m.u.component_create.name));
989
990 ret = send_synchronous_mmal_msg(instance, &m,
991 sizeof(m.u.component_create),
992 &rmsg, &rmsg_handle);
993 if (ret)
994 return ret;
995
996 if (rmsg->h.type != m.h.type) {
997 /* got an unexpected message type in reply */
998 ret = -EINVAL;
999 goto release_msg;
1000 }
1001
1002 ret = -rmsg->u.component_create_reply.status;
1003 if (ret != MMAL_MSG_STATUS_SUCCESS)
1004 goto release_msg;
1005
1006 /* a valid component response received */
1007 component->handle = rmsg->u.component_create_reply.component_handle;
1008 component->inputs = rmsg->u.component_create_reply.input_num;
1009 component->outputs = rmsg->u.component_create_reply.output_num;
1010 component->clocks = rmsg->u.component_create_reply.clock_num;
1011
1012 pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
1013 component->handle,
1014 component->inputs, component->outputs, component->clocks);
1015
1016release_msg:
1017 vchi_held_msg_release(&rmsg_handle);
1018
1019 return ret;
1020}
1021
1022/* destroys a component on vc */
1023static int destroy_component(struct vchiq_mmal_instance *instance,
1024 struct vchiq_mmal_component *component)
1025{
1026 int ret;
1027 struct mmal_msg m;
1028 struct mmal_msg *rmsg;
1029 VCHI_HELD_MSG_T rmsg_handle;
1030
1031 m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
1032 m.u.component_destroy.component_handle = component->handle;
1033
1034 ret = send_synchronous_mmal_msg(instance, &m,
1035 sizeof(m.u.component_destroy),
1036 &rmsg, &rmsg_handle);
1037 if (ret)
1038 return ret;
1039
1040 if (rmsg->h.type != m.h.type) {
1041 /* got an unexpected message type in reply */
1042 ret = -EINVAL;
1043 goto release_msg;
1044 }
1045
1046 ret = -rmsg->u.component_destroy_reply.status;
1047
1048release_msg:
1049
1050 vchi_held_msg_release(&rmsg_handle);
1051
1052 return ret;
1053}
1054
1055/* enable a component on vc */
1056static int enable_component(struct vchiq_mmal_instance *instance,
1057 struct vchiq_mmal_component *component)
1058{
1059 int ret;
1060 struct mmal_msg m;
1061 struct mmal_msg *rmsg;
1062 VCHI_HELD_MSG_T rmsg_handle;
1063
1064 m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
1065 m.u.component_enable.component_handle = component->handle;
1066
1067 ret = send_synchronous_mmal_msg(instance, &m,
1068 sizeof(m.u.component_enable),
1069 &rmsg, &rmsg_handle);
1070 if (ret)
1071 return ret;
1072
1073 if (rmsg->h.type != m.h.type) {
1074 /* got an unexpected message type in reply */
1075 ret = -EINVAL;
1076 goto release_msg;
1077 }
1078
1079 ret = -rmsg->u.component_enable_reply.status;
1080
1081release_msg:
1082 vchi_held_msg_release(&rmsg_handle);
1083
1084 return ret;
1085}
1086
1087/* disable a component on vc */
1088static int disable_component(struct vchiq_mmal_instance *instance,
1089 struct vchiq_mmal_component *component)
1090{
1091 int ret;
1092 struct mmal_msg m;
1093 struct mmal_msg *rmsg;
1094 VCHI_HELD_MSG_T rmsg_handle;
1095
1096 m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
1097 m.u.component_disable.component_handle = component->handle;
1098
1099 ret = send_synchronous_mmal_msg(instance, &m,
1100 sizeof(m.u.component_disable),
1101 &rmsg, &rmsg_handle);
1102 if (ret)
1103 return ret;
1104
1105 if (rmsg->h.type != m.h.type) {
1106 /* got an unexpected message type in reply */
1107 ret = -EINVAL;
1108 goto release_msg;
1109 }
1110
1111 ret = -rmsg->u.component_disable_reply.status;
1112
1113release_msg:
1114
1115 vchi_held_msg_release(&rmsg_handle);
1116
1117 return ret;
1118}
1119
1120/* get version of mmal implementation */
1121static int get_version(struct vchiq_mmal_instance *instance,
1122 u32 *major_out, u32 *minor_out)
1123{
1124 int ret;
1125 struct mmal_msg m;
1126 struct mmal_msg *rmsg;
1127 VCHI_HELD_MSG_T rmsg_handle;
1128
1129 m.h.type = MMAL_MSG_TYPE_GET_VERSION;
1130
1131 ret = send_synchronous_mmal_msg(instance, &m,
1132 sizeof(m.u.version),
1133 &rmsg, &rmsg_handle);
1134 if (ret)
1135 return ret;
1136
1137 if (rmsg->h.type != m.h.type) {
1138 /* got an unexpected message type in reply */
1139 ret = -EINVAL;
1140 goto release_msg;
1141 }
1142
1143 *major_out = rmsg->u.version.major;
1144 *minor_out = rmsg->u.version.minor;
1145
1146release_msg:
1147 vchi_held_msg_release(&rmsg_handle);
1148
1149 return ret;
1150}
1151
1152/* do a port action with a port as a parameter */
1153static int port_action_port(struct vchiq_mmal_instance *instance,
1154 struct vchiq_mmal_port *port,
1155 enum mmal_msg_port_action_type action_type)
1156{
1157 int ret;
1158 struct mmal_msg m;
1159 struct mmal_msg *rmsg;
1160 VCHI_HELD_MSG_T rmsg_handle;
1161
1162 m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
1163 m.u.port_action_port.component_handle = port->component->handle;
1164 m.u.port_action_port.port_handle = port->handle;
1165 m.u.port_action_port.action = action_type;
1166
1167 port_to_mmal_msg(port, &m.u.port_action_port.port);
1168
1169 ret = send_synchronous_mmal_msg(instance, &m,
1170 sizeof(m.u.port_action_port),
1171 &rmsg, &rmsg_handle);
1172 if (ret)
1173 return ret;
1174
1175 if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
1176 /* got an unexpected message type in reply */
1177 ret = -EINVAL;
1178 goto release_msg;
1179 }
1180
1181 ret = -rmsg->u.port_action_reply.status;
1182
1183 pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
1184 __func__,
1185 ret, port->component->handle, port->handle,
1186 port_action_type_names[action_type], action_type);
1187
1188release_msg:
1189 vchi_held_msg_release(&rmsg_handle);
1190
1191 return ret;
1192}
1193
1194/* do a port action with handles as parameters */
1195static int port_action_handle(struct vchiq_mmal_instance *instance,
1196 struct vchiq_mmal_port *port,
1197 enum mmal_msg_port_action_type action_type,
1198 u32 connect_component_handle,
1199 u32 connect_port_handle)
1200{
1201 int ret;
1202 struct mmal_msg m;
1203 struct mmal_msg *rmsg;
1204 VCHI_HELD_MSG_T rmsg_handle;
1205
1206 m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
1207
1208 m.u.port_action_handle.component_handle = port->component->handle;
1209 m.u.port_action_handle.port_handle = port->handle;
1210 m.u.port_action_handle.action = action_type;
1211
1212 m.u.port_action_handle.connect_component_handle =
1213 connect_component_handle;
1214 m.u.port_action_handle.connect_port_handle = connect_port_handle;
1215
1216 ret = send_synchronous_mmal_msg(instance, &m,
1217 sizeof(m.u.port_action_handle),
1218 &rmsg, &rmsg_handle);
1219 if (ret)
1220 return ret;
1221
1222 if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
1223 /* got an unexpected message type in reply */
1224 ret = -EINVAL;
1225 goto release_msg;
1226 }
1227
1228 ret = -rmsg->u.port_action_reply.status;
1229
1230 pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
1231 " connect component:0x%x connect port:%d\n",
1232 __func__,
1233 ret, port->component->handle, port->handle,
1234 port_action_type_names[action_type],
1235 action_type, connect_component_handle, connect_port_handle);
1236
1237release_msg:
1238 vchi_held_msg_release(&rmsg_handle);
1239
1240 return ret;
1241}
1242
1243static int port_parameter_set(struct vchiq_mmal_instance *instance,
1244 struct vchiq_mmal_port *port,
1245 u32 parameter_id, void *value, u32 value_size)
1246{
1247 int ret;
1248 struct mmal_msg m;
1249 struct mmal_msg *rmsg;
1250 VCHI_HELD_MSG_T rmsg_handle;
1251
1252 m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
1253
1254 m.u.port_parameter_set.component_handle = port->component->handle;
1255 m.u.port_parameter_set.port_handle = port->handle;
1256 m.u.port_parameter_set.id = parameter_id;
1257 m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
1258 memcpy(&m.u.port_parameter_set.value, value, value_size);
1259
1260 ret = send_synchronous_mmal_msg(instance, &m,
1261 (4 * sizeof(u32)) + value_size,
1262 &rmsg, &rmsg_handle);
1263 if (ret)
1264 return ret;
1265
1266 if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
1267 /* got an unexpected message type in reply */
1268 ret = -EINVAL;
1269 goto release_msg;
1270 }
1271
1272 ret = -rmsg->u.port_parameter_set_reply.status;
1273
1274 pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
1275 __func__,
1276 ret, port->component->handle, port->handle, parameter_id);
1277
1278release_msg:
1279 vchi_held_msg_release(&rmsg_handle);
1280
1281 return ret;
1282}
1283
1284static int port_parameter_get(struct vchiq_mmal_instance *instance,
1285 struct vchiq_mmal_port *port,
1286 u32 parameter_id, void *value, u32 *value_size)
1287{
1288 int ret;
1289 struct mmal_msg m;
1290 struct mmal_msg *rmsg;
1291 VCHI_HELD_MSG_T rmsg_handle;
1292
1293 m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
1294
1295 m.u.port_parameter_get.component_handle = port->component->handle;
1296 m.u.port_parameter_get.port_handle = port->handle;
1297 m.u.port_parameter_get.id = parameter_id;
1298 m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
1299
1300 ret = send_synchronous_mmal_msg(instance, &m,
1301 sizeof(struct
1302 mmal_msg_port_parameter_get),
1303 &rmsg, &rmsg_handle);
1304 if (ret)
1305 return ret;
1306
1307 if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
1308 /* got an unexpected message type in reply */
1309 pr_err("Incorrect reply type %d\n", rmsg->h.type);
1310 ret = -EINVAL;
1311 goto release_msg;
1312 }
1313
1314 ret = -rmsg->u.port_parameter_get_reply.status;
1315 if (ret) {
1316 /* Copy only as much as we have space for
1317 * but report true size of parameter
1318 */
1319 memcpy(value, &rmsg->u.port_parameter_get_reply.value,
1320 *value_size);
1321 *value_size = rmsg->u.port_parameter_get_reply.size;
1322 } else
1323 memcpy(value, &rmsg->u.port_parameter_get_reply.value,
1324 rmsg->u.port_parameter_get_reply.size);
1325
1326 pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
1327 ret, port->component->handle, port->handle, parameter_id);
1328
1329release_msg:
1330 vchi_held_msg_release(&rmsg_handle);
1331
1332 return ret;
1333}
1334
1335/* disables a port and drains buffers from it */
1336static int port_disable(struct vchiq_mmal_instance *instance,
1337 struct vchiq_mmal_port *port)
1338{
1339 int ret;
1340 struct list_head *q, *buf_head;
1341 unsigned long flags = 0;
1342
1343 if (!port->enabled)
1344 return 0;
1345
1346 port->enabled = false;
1347
1348 ret = port_action_port(instance, port,
1349 MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
1350 if (ret == 0) {
1351 /* drain all queued buffers on port */
1352 spin_lock_irqsave(&port->slock, flags);
1353
1354 list_for_each_safe(buf_head, q, &port->buffers) {
1355 struct mmal_buffer *mmalbuf;
1356
1357 mmalbuf = list_entry(buf_head, struct mmal_buffer,
1358 list);
1359 list_del(buf_head);
1360 if (port->buffer_cb)
1361 port->buffer_cb(instance,
1362 port, 0, mmalbuf, 0, 0,
1363 MMAL_TIME_UNKNOWN,
1364 MMAL_TIME_UNKNOWN);
1365 }
1366
1367 spin_unlock_irqrestore(&port->slock, flags);
1368
1369 ret = port_info_get(instance, port);
1370 }
1371
1372 return ret;
1373}
1374
1375/* enable a port */
1376static int port_enable(struct vchiq_mmal_instance *instance,
1377 struct vchiq_mmal_port *port)
1378{
1379 unsigned int hdr_count;
1380 struct list_head *buf_head;
1381 int ret;
1382
1383 if (port->enabled)
1384 return 0;
1385
1386 /* ensure there are enough buffers queued to cover the buffer headers */
1387 if (port->buffer_cb != NULL) {
1388 hdr_count = 0;
1389 list_for_each(buf_head, &port->buffers) {
1390 hdr_count++;
1391 }
1392 if (hdr_count < port->current_buffer.num)
1393 return -ENOSPC;
1394 }
1395
1396 ret = port_action_port(instance, port,
1397 MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
1398 if (ret)
1399 goto done;
1400
1401 port->enabled = true;
1402
1403 if (port->buffer_cb) {
1404 /* send buffer headers to videocore */
1405 hdr_count = 1;
1406 list_for_each(buf_head, &port->buffers) {
1407 struct mmal_buffer *mmalbuf;
1408
1409 mmalbuf = list_entry(buf_head, struct mmal_buffer,
1410 list);
1411 ret = buffer_from_host(instance, port, mmalbuf);
1412 if (ret)
1413 goto done;
1414
1415 hdr_count++;
1416 if (hdr_count > port->current_buffer.num)
1417 break;
1418 }
1419 }
1420
1421 ret = port_info_get(instance, port);
1422
1423done:
1424 return ret;
1425}
1426
1427/* ------------------------------------------------------------------
1428 * Exported API
1429 *------------------------------------------------------------------*/
1430
1431int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
1432 struct vchiq_mmal_port *port)
1433{
1434 int ret;
1435
1436 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1437 return -EINTR;
1438
1439 ret = port_info_set(instance, port);
1440 if (ret)
1441 goto release_unlock;
1442
1443 /* read what has actually been set */
1444 ret = port_info_get(instance, port);
1445
1446release_unlock:
1447 mutex_unlock(&instance->vchiq_mutex);
1448
1449 return ret;
1450}
1451
1452int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
1453 struct vchiq_mmal_port *port,
1454 u32 parameter, void *value, u32 value_size)
1455{
1456 int ret;
1457
1458 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1459 return -EINTR;
1460
1461 ret = port_parameter_set(instance, port, parameter, value, value_size);
1462
1463 mutex_unlock(&instance->vchiq_mutex);
1464
1465 return ret;
1466}
1467
1468int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
1469 struct vchiq_mmal_port *port,
1470 u32 parameter, void *value, u32 *value_size)
1471{
1472 int ret;
1473
1474 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1475 return -EINTR;
1476
1477 ret = port_parameter_get(instance, port, parameter, value, value_size);
1478
1479 mutex_unlock(&instance->vchiq_mutex);
1480
1481 return ret;
1482}
1483
1484/* enable a port
1485 *
1486 * enables a port and queues buffers for satisfying callbacks if we
1487 * provide a callback handler
1488 */
1489int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
1490 struct vchiq_mmal_port *port,
1491 vchiq_mmal_buffer_cb buffer_cb)
1492{
1493 int ret;
1494
1495 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1496 return -EINTR;
1497
1498 /* already enabled - noop */
1499 if (port->enabled) {
1500 ret = 0;
1501 goto unlock;
1502 }
1503
1504 port->buffer_cb = buffer_cb;
1505
1506 ret = port_enable(instance, port);
1507
1508unlock:
1509 mutex_unlock(&instance->vchiq_mutex);
1510
1511 return ret;
1512}
1513
1514int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
1515 struct vchiq_mmal_port *port)
1516{
1517 int ret;
1518
1519 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1520 return -EINTR;
1521
1522 if (!port->enabled) {
1523 mutex_unlock(&instance->vchiq_mutex);
1524 return 0;
1525 }
1526
1527 ret = port_disable(instance, port);
1528
1529 mutex_unlock(&instance->vchiq_mutex);
1530
1531 return ret;
1532}
1533
1534/* ports will be connected in a tunneled manner so data buffers
1535 * are not handled by client.
1536 */
1537int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
1538 struct vchiq_mmal_port *src,
1539 struct vchiq_mmal_port *dst)
1540{
1541 int ret;
1542
1543 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1544 return -EINTR;
1545
1546 /* disconnect ports if connected */
1547 if (src->connected != NULL) {
1548 ret = port_disable(instance, src);
1549 if (ret) {
1550 pr_err("failed disabling src port(%d)\n", ret);
1551 goto release_unlock;
1552 }
1553
1554 /* do not need to disable the destination port as they
1555 * are connected and it is done automatically
1556 */
1557
1558 ret = port_action_handle(instance, src,
1559 MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
1560 src->connected->component->handle,
1561 src->connected->handle);
1562 if (ret < 0) {
1563 pr_err("failed disconnecting src port\n");
1564 goto release_unlock;
1565 }
1566 src->connected->enabled = false;
1567 src->connected = NULL;
1568 }
1569
1570 if (dst == NULL) {
1571 /* do not make new connection */
1572 ret = 0;
1573 pr_debug("not making new connection\n");
1574 goto release_unlock;
1575 }
1576
1577 /* copy src port format to dst */
1578 dst->format.encoding = src->format.encoding;
1579 dst->es.video.width = src->es.video.width;
1580 dst->es.video.height = src->es.video.height;
1581 dst->es.video.crop.x = src->es.video.crop.x;
1582 dst->es.video.crop.y = src->es.video.crop.y;
1583 dst->es.video.crop.width = src->es.video.crop.width;
1584 dst->es.video.crop.height = src->es.video.crop.height;
1585 dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
1586 dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
1587
1588 /* set new format */
1589 ret = port_info_set(instance, dst);
1590 if (ret) {
1591 pr_debug("setting port info failed\n");
1592 goto release_unlock;
1593 }
1594
1595 /* read what has actually been set */
1596 ret = port_info_get(instance, dst);
1597 if (ret) {
1598 pr_debug("read back port info failed\n");
1599 goto release_unlock;
1600 }
1601
1602 /* connect two ports together */
1603 ret = port_action_handle(instance, src,
1604 MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
1605 dst->component->handle, dst->handle);
1606 if (ret < 0) {
1607 pr_debug("connecting port %d:%d to %d:%d failed\n",
1608 src->component->handle, src->handle,
1609 dst->component->handle, dst->handle);
1610 goto release_unlock;
1611 }
1612 src->connected = dst;
1613
1614release_unlock:
1615
1616 mutex_unlock(&instance->vchiq_mutex);
1617
1618 return ret;
1619}
1620
1621int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
1622 struct vchiq_mmal_port *port,
1623 struct mmal_buffer *buffer)
1624{
1625 unsigned long flags = 0;
1626
1627 spin_lock_irqsave(&port->slock, flags);
1628 list_add_tail(&buffer->list, &port->buffers);
1629 spin_unlock_irqrestore(&port->slock, flags);
1630
1631 /* the port previously underflowed because it was missing a
1632 * mmal_buffer which has just been added, submit that buffer
1633 * to the mmal service.
1634 */
1635 if (port->buffer_underflow) {
1636 port_buffer_from_host(instance, port);
1637 port->buffer_underflow--;
1638 }
1639
1640 return 0;
1641}
1642
1643/* Initialise a mmal component and its ports
1644 *
1645 */
1646int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
1647 const char *name,
1648 struct vchiq_mmal_component **component_out)
1649{
1650 int ret;
1651 int idx; /* port index */
1652 struct vchiq_mmal_component *component;
1653
1654 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1655 return -EINTR;
1656
1657 if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
1658 ret = -EINVAL; /* todo is this correct error? */
1659 goto unlock;
1660 }
1661
1662 component = &instance->component[instance->component_idx];
1663
1664 ret = create_component(instance, component, name);
1665 if (ret < 0)
1666 goto unlock;
1667
1668 /* ports info needs gathering */
1669 component->control.type = MMAL_PORT_TYPE_CONTROL;
1670 component->control.index = 0;
1671 component->control.component = component;
1672 spin_lock_init(&component->control.slock);
1673 INIT_LIST_HEAD(&component->control.buffers);
1674 ret = port_info_get(instance, &component->control);
1675 if (ret < 0)
1676 goto release_component;
1677
1678 for (idx = 0; idx < component->inputs; idx++) {
1679 component->input[idx].type = MMAL_PORT_TYPE_INPUT;
1680 component->input[idx].index = idx;
1681 component->input[idx].component = component;
1682 spin_lock_init(&component->input[idx].slock);
1683 INIT_LIST_HEAD(&component->input[idx].buffers);
1684 ret = port_info_get(instance, &component->input[idx]);
1685 if (ret < 0)
1686 goto release_component;
1687 }
1688
1689 for (idx = 0; idx < component->outputs; idx++) {
1690 component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
1691 component->output[idx].index = idx;
1692 component->output[idx].component = component;
1693 spin_lock_init(&component->output[idx].slock);
1694 INIT_LIST_HEAD(&component->output[idx].buffers);
1695 ret = port_info_get(instance, &component->output[idx]);
1696 if (ret < 0)
1697 goto release_component;
1698 }
1699
1700 for (idx = 0; idx < component->clocks; idx++) {
1701 component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
1702 component->clock[idx].index = idx;
1703 component->clock[idx].component = component;
1704 spin_lock_init(&component->clock[idx].slock);
1705 INIT_LIST_HEAD(&component->clock[idx].buffers);
1706 ret = port_info_get(instance, &component->clock[idx]);
1707 if (ret < 0)
1708 goto release_component;
1709 }
1710
1711 instance->component_idx++;
1712
1713 *component_out = component;
1714
1715 mutex_unlock(&instance->vchiq_mutex);
1716
1717 return 0;
1718
1719release_component:
1720 destroy_component(instance, component);
1721unlock:
1722 mutex_unlock(&instance->vchiq_mutex);
1723
1724 return ret;
1725}
1726
1727/*
1728 * cause a mmal component to be destroyed
1729 */
1730int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
1731 struct vchiq_mmal_component *component)
1732{
1733 int ret;
1734
1735 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1736 return -EINTR;
1737
1738 if (component->enabled)
1739 ret = disable_component(instance, component);
1740
1741 ret = destroy_component(instance, component);
1742
1743 mutex_unlock(&instance->vchiq_mutex);
1744
1745 return ret;
1746}
1747
1748/*
1749 * cause a mmal component to be enabled
1750 */
1751int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
1752 struct vchiq_mmal_component *component)
1753{
1754 int ret;
1755
1756 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1757 return -EINTR;
1758
1759 if (component->enabled) {
1760 mutex_unlock(&instance->vchiq_mutex);
1761 return 0;
1762 }
1763
1764 ret = enable_component(instance, component);
1765 if (ret == 0)
1766 component->enabled = true;
1767
1768 mutex_unlock(&instance->vchiq_mutex);
1769
1770 return ret;
1771}
1772
1773/*
1774 * cause a mmal component to be enabled
1775 */
1776int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
1777 struct vchiq_mmal_component *component)
1778{
1779 int ret;
1780
1781 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1782 return -EINTR;
1783
1784 if (!component->enabled) {
1785 mutex_unlock(&instance->vchiq_mutex);
1786 return 0;
1787 }
1788
1789 ret = disable_component(instance, component);
1790 if (ret == 0)
1791 component->enabled = false;
1792
1793 mutex_unlock(&instance->vchiq_mutex);
1794
1795 return ret;
1796}
1797
1798int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
1799 u32 *major_out, u32 *minor_out)
1800{
1801 int ret;
1802
1803 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1804 return -EINTR;
1805
1806 ret = get_version(instance, major_out, minor_out);
1807
1808 mutex_unlock(&instance->vchiq_mutex);
1809
1810 return ret;
1811}
1812
1813int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
1814{
1815 int status = 0;
1816
1817 if (instance == NULL)
1818 return -EINVAL;
1819
1820 if (mutex_lock_interruptible(&instance->vchiq_mutex))
1821 return -EINTR;
1822
1823 vchi_service_use(instance->handle);
1824
1825 status = vchi_service_close(instance->handle);
1826 if (status != 0)
1827 pr_err("mmal-vchiq: VCHIQ close failed");
1828
1829 mutex_unlock(&instance->vchiq_mutex);
1830
1831 vfree(instance->bulk_scratch);
1832
1833 kfree(instance);
1834
1835 return status;
1836}
1837
1838int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
1839{
1840 int status;
1841 struct vchiq_mmal_instance *instance;
1842 static VCHI_CONNECTION_T *vchi_connection;
1843 static VCHI_INSTANCE_T vchi_instance;
1844 SERVICE_CREATION_T params = {
1845 VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
1846 VC_MMAL_SERVER_NAME,
1847 vchi_connection,
1848 0, /* rx fifo size (unused) */
1849 0, /* tx fifo size (unused) */
1850 service_callback,
1851 NULL, /* service callback parameter */
1852 1, /* unaligned bulk receives */
1853 1, /* unaligned bulk transmits */
1854 0 /* want crc check on bulk transfers */
1855 };
1856
1857 /* compile time checks to ensure structure size as they are
1858 * directly (de)serialised from memory.
1859 */
1860
1861 /* ensure the header structure has packed to the correct size */
1862 BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
1863
1864 /* ensure message structure does not exceed maximum length */
1865 BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
1866
1867 /* mmal port struct is correct size */
1868 BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
1869
1870 /* create a vchi instance */
1871 status = vchi_initialise(&vchi_instance);
1872 if (status) {
1873 pr_err("Failed to initialise VCHI instance (status=%d)\n",
1874 status);
1875 return -EIO;
1876 }
1877
1878 status = vchi_connect(NULL, 0, vchi_instance);
1879 if (status) {
1880 pr_err("Failed to connect VCHI instance (status=%d)\n", status);
1881 return -EIO;
1882 }
1883
1884 instance = kmalloc(sizeof(*instance), GFP_KERNEL);
1885 memset(instance, 0, sizeof(*instance));
1886
1887 mutex_init(&instance->vchiq_mutex);
1888 mutex_init(&instance->bulk_mutex);
1889
1890 instance->bulk_scratch = vmalloc(PAGE_SIZE);
1891
1892 params.callback_param = instance;
1893
1894 status = vchi_service_open(vchi_instance, &params, &instance->handle);
1895 if (status) {
1896 pr_err("Failed to open VCHI service connection (status=%d)\n",
1897 status);
1898 goto err_close_services;
1899 }
1900
1901 vchi_service_release(instance->handle);
1902
1903 *out_instance = instance;
1904
1905 return 0;
1906
1907err_close_services:
1908
1909 vchi_service_close(instance->handle);
1910 vfree(instance->bulk_scratch);
1911 kfree(instance);
1912 return -ENODEV;
1913}
diff --git a/drivers/staging/media/platform/bcm2835/mmal-vchiq.h b/drivers/staging/media/platform/bcm2835/mmal-vchiq.h
new file mode 100644
index 000000000000..9d1d11e4a53e
--- /dev/null
+++ b/drivers/staging/media/platform/bcm2835/mmal-vchiq.h
@@ -0,0 +1,178 @@
1/*
2 * Broadcom BM2835 V4L2 driver
3 *
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
14 *
15 * MMAL interface to VCHIQ message passing
16 */
17
18#ifndef MMAL_VCHIQ_H
19#define MMAL_VCHIQ_H
20
21#include "mmal-msg-format.h"
22
23#define MAX_PORT_COUNT 4
24
25/* Maximum size of the format extradata. */
26#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
27
28struct vchiq_mmal_instance;
29
30enum vchiq_mmal_es_type {
31 MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
32 MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
33 MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
34 MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
35 MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
36};
37
38/* rectangle, used lots so it gets its own struct */
39struct vchiq_mmal_rect {
40 s32 x;
41 s32 y;
42 s32 width;
43 s32 height;
44};
45
46struct vchiq_mmal_port_buffer {
47 unsigned int num; /* number of buffers */
48 u32 size; /* size of buffers */
49 u32 alignment; /* alignment of buffers */
50};
51
52struct vchiq_mmal_port;
53
54typedef void (*vchiq_mmal_buffer_cb)(
55 struct vchiq_mmal_instance *instance,
56 struct vchiq_mmal_port *port,
57 int status, struct mmal_buffer *buffer,
58 unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
59
60struct vchiq_mmal_port {
61 bool enabled;
62 u32 handle;
63 u32 type; /* port type, cached to use on port info set */
64 u32 index; /* port index, cached to use on port info set */
65
66 /* component port belongs to, allows simple deref */
67 struct vchiq_mmal_component *component;
68
69 struct vchiq_mmal_port *connected; /* port conencted to */
70
71 /* buffer info */
72 struct vchiq_mmal_port_buffer minimum_buffer;
73 struct vchiq_mmal_port_buffer recommended_buffer;
74 struct vchiq_mmal_port_buffer current_buffer;
75
76 /* stream format */
77 struct mmal_es_format format;
78 /* elementry stream format */
79 union mmal_es_specific_format es;
80
81 /* data buffers to fill */
82 struct list_head buffers;
83 /* lock to serialise adding and removing buffers from list */
84 spinlock_t slock;
85 /* count of how many buffer header refils have failed because
86 * there was no buffer to satisfy them
87 */
88 int buffer_underflow;
89 /* callback on buffer completion */
90 vchiq_mmal_buffer_cb buffer_cb;
91 /* callback context */
92 void *cb_ctx;
93};
94
95struct vchiq_mmal_component {
96 bool enabled;
97 u32 handle; /* VideoCore handle for component */
98 u32 inputs; /* Number of input ports */
99 u32 outputs; /* Number of output ports */
100 u32 clocks; /* Number of clock ports */
101 struct vchiq_mmal_port control; /* control port */
102 struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
103 struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
104 struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
105};
106
107
108int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
109int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
110
111/* Initialise a mmal component and its ports
112*
113*/
114int vchiq_mmal_component_init(
115 struct vchiq_mmal_instance *instance,
116 const char *name,
117 struct vchiq_mmal_component **component_out);
118
119int vchiq_mmal_component_finalise(
120 struct vchiq_mmal_instance *instance,
121 struct vchiq_mmal_component *component);
122
123int vchiq_mmal_component_enable(
124 struct vchiq_mmal_instance *instance,
125 struct vchiq_mmal_component *component);
126
127int vchiq_mmal_component_disable(
128 struct vchiq_mmal_instance *instance,
129 struct vchiq_mmal_component *component);
130
131
132
133/* enable a mmal port
134 *
135 * enables a port and if a buffer callback provided enque buffer
136 * headers as apropriate for the port.
137 */
138int vchiq_mmal_port_enable(
139 struct vchiq_mmal_instance *instance,
140 struct vchiq_mmal_port *port,
141 vchiq_mmal_buffer_cb buffer_cb);
142
143/* disable a port
144 *
145 * disable a port will dequeue any pending buffers
146 */
147int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
148 struct vchiq_mmal_port *port);
149
150
151int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
152 struct vchiq_mmal_port *port,
153 u32 parameter,
154 void *value,
155 u32 value_size);
156
157int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
158 struct vchiq_mmal_port *port,
159 u32 parameter,
160 void *value,
161 u32 *value_size);
162
163int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
164 struct vchiq_mmal_port *port);
165
166int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
167 struct vchiq_mmal_port *src,
168 struct vchiq_mmal_port *dst);
169
170int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
171 u32 *major_out,
172 u32 *minor_out);
173
174int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
175 struct vchiq_mmal_port *port,
176 struct mmal_buffer *buf);
177
178#endif /* MMAL_VCHIQ_H */
diff --git a/drivers/staging/most/hdm-dim2/dim2_hdm.c b/drivers/staging/most/hdm-dim2/dim2_hdm.c
index 35aee9fbbf02..902824e728ea 100644
--- a/drivers/staging/most/hdm-dim2/dim2_hdm.c
+++ b/drivers/staging/most/hdm-dim2/dim2_hdm.c
@@ -41,7 +41,7 @@
41 41
42/* command line parameter to select clock speed */ 42/* command line parameter to select clock speed */
43static char *clock_speed; 43static char *clock_speed;
44module_param(clock_speed, charp, 0); 44module_param(clock_speed, charp, 0000);
45MODULE_PARM_DESC(clock_speed, "MediaLB Clock Speed"); 45MODULE_PARM_DESC(clock_speed, "MediaLB Clock Speed");
46 46
47/* 47/*
@@ -52,7 +52,7 @@ MODULE_PARM_DESC(clock_speed, "MediaLB Clock Speed");
52 * sub-buffer 1, 2, 4, 8, 16, 32, 64. 52 * sub-buffer 1, 2, 4, 8, 16, 32, 64.
53 */ 53 */
54static u8 fcnt = 4; /* (1 << fcnt) frames per subbuffer */ 54static u8 fcnt = 4; /* (1 << fcnt) frames per subbuffer */
55module_param(fcnt, byte, 0); 55module_param(fcnt, byte, 0000);
56MODULE_PARM_DESC(fcnt, "Num of frames per sub-buffer for sync channels as a power of 2"); 56MODULE_PARM_DESC(fcnt, "Num of frames per sub-buffer for sync channels as a power of 2");
57 57
58static DEFINE_SPINLOCK(dim_lock); 58static DEFINE_SPINLOCK(dim_lock);
diff --git a/drivers/staging/most/hdm-i2c/hdm_i2c.c b/drivers/staging/most/hdm-i2c/hdm_i2c.c
index ba0263bb3d12..1d5b22927bcd 100644
--- a/drivers/staging/most/hdm-i2c/hdm_i2c.c
+++ b/drivers/staging/most/hdm-i2c/hdm_i2c.c
@@ -37,7 +37,7 @@ enum { CH_RX, CH_TX, NUM_CHANNELS };
37 37
38/* IRQ / Polling option */ 38/* IRQ / Polling option */
39static bool polling_req; 39static bool polling_req;
40module_param(polling_req, bool, S_IRUGO); 40module_param(polling_req, bool, 0444);
41MODULE_PARM_DESC(polling_req, "Request Polling. Default = 0 (use irq)"); 41MODULE_PARM_DESC(polling_req, "Request Polling. Default = 0 (use irq)");
42 42
43/* Polling Rate */ 43/* Polling Rate */
diff --git a/drivers/staging/most/hdm-usb/hdm_usb.c b/drivers/staging/most/hdm-usb/hdm_usb.c
index d6db0bd65be0..65211d1824b7 100644
--- a/drivers/staging/most/hdm-usb/hdm_usb.c
+++ b/drivers/staging/most/hdm-usb/hdm_usb.c
@@ -145,7 +145,7 @@ static void wq_netinfo(struct work_struct *wq_obj);
145static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf) 145static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf)
146{ 146{
147 int retval; 147 int retval;
148 u16 *dma_buf = kzalloc(sizeof(u16), GFP_KERNEL); 148 __le16 *dma_buf = kzalloc(sizeof(*dma_buf), GFP_KERNEL);
149 u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE; 149 u8 req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE;
150 150
151 if (!dma_buf) 151 if (!dma_buf)
@@ -154,7 +154,7 @@ static inline int drci_rd_reg(struct usb_device *dev, u16 reg, u16 *buf)
154 retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), 154 retval = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
155 DRCI_READ_REQ, req_type, 155 DRCI_READ_REQ, req_type,
156 0x0000, 156 0x0000,
157 reg, dma_buf, sizeof(u16), 5 * HZ); 157 reg, dma_buf, sizeof(*dma_buf), 5 * HZ);
158 *buf = le16_to_cpu(*dma_buf); 158 *buf = le16_to_cpu(*dma_buf);
159 kfree(dma_buf); 159 kfree(dma_buf);
160 160
@@ -846,15 +846,15 @@ static struct usb_device_id usbid[] = {
846 846
847#define MOST_DCI_RO_ATTR(_name) \ 847#define MOST_DCI_RO_ATTR(_name) \
848 struct most_dci_attribute most_dci_attr_##_name = \ 848 struct most_dci_attribute most_dci_attr_##_name = \
849 __ATTR(_name, S_IRUGO, show_value, NULL) 849 __ATTR(_name, 0444, show_value, NULL)
850 850
851#define MOST_DCI_ATTR(_name) \ 851#define MOST_DCI_ATTR(_name) \
852 struct most_dci_attribute most_dci_attr_##_name = \ 852 struct most_dci_attribute most_dci_attr_##_name = \
853 __ATTR(_name, S_IRUGO | S_IWUSR, show_value, store_value) 853 __ATTR(_name, 0644, show_value, store_value)
854 854
855#define MOST_DCI_WO_ATTR(_name) \ 855#define MOST_DCI_WO_ATTR(_name) \
856 struct most_dci_attribute most_dci_attr_##_name = \ 856 struct most_dci_attribute most_dci_attr_##_name = \
857 __ATTR(_name, S_IWUSR, NULL, store_value) 857 __ATTR(_name, 0200, NULL, store_value)
858 858
859/** 859/**
860 * struct most_dci_attribute - to access the attributes of a dci object 860 * struct most_dci_attribute - to access the attributes of a dci object
diff --git a/drivers/staging/nvec/nvec.h b/drivers/staging/nvec/nvec.h
index c03ca8d9572a..aa7c70ef94f5 100644
--- a/drivers/staging/nvec/nvec.h
+++ b/drivers/staging/nvec/nvec.h
@@ -138,7 +138,7 @@ struct nvec_chip {
138 struct device *dev; 138 struct device *dev;
139 int gpio; 139 int gpio;
140 int irq; 140 int irq;
141 int i2c_addr; 141 u32 i2c_addr;
142 void __iomem *base; 142 void __iomem *base;
143 struct clk *i2c_clk; 143 struct clk *i2c_clk;
144 struct reset_control *rst; 144 struct reset_control *rst;
diff --git a/drivers/staging/nvec/nvec_power.c b/drivers/staging/nvec/nvec_power.c
index fcbb0fa03765..3b144a9ea055 100644
--- a/drivers/staging/nvec/nvec_power.c
+++ b/drivers/staging/nvec/nvec_power.c
@@ -442,7 +442,7 @@ static struct platform_driver nvec_power_driver = {
442 .remove = nvec_power_remove, 442 .remove = nvec_power_remove,
443 .driver = { 443 .driver = {
444 .name = "nvec-power", 444 .name = "nvec-power",
445 } 445 }
446}; 446};
447 447
448module_platform_driver(nvec_power_driver); 448module_platform_driver(nvec_power_driver);
diff --git a/drivers/staging/nvec/nvec_ps2.c b/drivers/staging/nvec/nvec_ps2.c
index 499952c8ef39..3b7bce3ffd19 100644
--- a/drivers/staging/nvec/nvec_ps2.c
+++ b/drivers/staging/nvec/nvec_ps2.c
@@ -107,7 +107,7 @@ static int nvec_mouse_probe(struct platform_device *pdev)
107 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent); 107 struct nvec_chip *nvec = dev_get_drvdata(pdev->dev.parent);
108 struct serio *ser_dev; 108 struct serio *ser_dev;
109 109
110 ser_dev = kzalloc(sizeof(struct serio), GFP_KERNEL); 110 ser_dev = kzalloc(sizeof(*ser_dev), GFP_KERNEL);
111 if (!ser_dev) 111 if (!ser_dev)
112 return -ENOMEM; 112 return -ENOMEM;
113 113
diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
index fc849d4a1b5d..7f8cf875157c 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -356,8 +356,8 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
356 356
357 /* Increment RX stats for virtual ports */ 357 /* Increment RX stats for virtual ports */
358 if (port >= CVMX_PIP_NUM_INPUT_PORTS) { 358 if (port >= CVMX_PIP_NUM_INPUT_PORTS) {
359 priv->stats.rx_packets++; 359 dev->stats.rx_packets++;
360 priv->stats.rx_bytes += skb->len; 360 dev->stats.rx_bytes += skb->len;
361 } 361 }
362 netif_receive_skb(skb); 362 netif_receive_skb(skb);
363 } else { 363 } else {
@@ -365,7 +365,7 @@ static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
365 * Drop any packet received for a device that 365 * Drop any packet received for a device that
366 * isn't up. 366 * isn't up.
367 */ 367 */
368 priv->stats.rx_dropped++; 368 dev->stats.rx_dropped++;
369 dev_kfree_skb_irq(skb); 369 dev_kfree_skb_irq(skb);
370 } 370 }
371 } else { 371 } else {
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 0b8053205091..ff4119e8de42 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -459,7 +459,7 @@ skip_xmit:
459 case QUEUE_DROP: 459 case QUEUE_DROP:
460 skb->next = to_free_list; 460 skb->next = to_free_list;
461 to_free_list = skb; 461 to_free_list = skb;
462 priv->stats.tx_dropped++; 462 dev->stats.tx_dropped++;
463 break; 463 break;
464 case QUEUE_HW: 464 case QUEUE_HW:
465 cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, -1); 465 cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, -1);
@@ -534,7 +534,7 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
534 if (unlikely(!work)) { 534 if (unlikely(!work)) {
535 printk_ratelimited("%s: Failed to allocate a work queue entry\n", 535 printk_ratelimited("%s: Failed to allocate a work queue entry\n",
536 dev->name); 536 dev->name);
537 priv->stats.tx_dropped++; 537 dev->stats.tx_dropped++;
538 dev_kfree_skb_any(skb); 538 dev_kfree_skb_any(skb);
539 return 0; 539 return 0;
540 } 540 }
@@ -545,7 +545,7 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
545 printk_ratelimited("%s: Failed to allocate a packet buffer\n", 545 printk_ratelimited("%s: Failed to allocate a packet buffer\n",
546 dev->name); 546 dev->name);
547 cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, 1); 547 cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, 1);
548 priv->stats.tx_dropped++; 548 dev->stats.tx_dropped++;
549 dev_kfree_skb_any(skb); 549 dev_kfree_skb_any(skb);
550 return 0; 550 return 0;
551 } 551 }
@@ -662,8 +662,8 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
662 /* Submit the packet to the POW */ 662 /* Submit the packet to the POW */
663 cvmx_pow_work_submit(work, work->word1.tag, work->word1.tag_type, 663 cvmx_pow_work_submit(work, work->word1.tag, work->word1.tag_type,
664 cvmx_wqe_get_qos(work), cvmx_wqe_get_grp(work)); 664 cvmx_wqe_get_qos(work), cvmx_wqe_get_grp(work));
665 priv->stats.tx_packets++; 665 dev->stats.tx_packets++;
666 priv->stats.tx_bytes += skb->len; 666 dev->stats.tx_bytes += skb->len;
667 dev_consume_skb_any(skb); 667 dev_consume_skb_any(skb);
668 return 0; 668 return 0;
669} 669}
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index 4971aa54756a..429e24adfcf5 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -228,17 +228,17 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
228 cvmx_pko_get_port_status(priv->port, 1, &tx_status); 228 cvmx_pko_get_port_status(priv->port, 1, &tx_status);
229 } 229 }
230 230
231 priv->stats.rx_packets += rx_status.inb_packets; 231 dev->stats.rx_packets += rx_status.inb_packets;
232 priv->stats.tx_packets += tx_status.packets; 232 dev->stats.tx_packets += tx_status.packets;
233 priv->stats.rx_bytes += rx_status.inb_octets; 233 dev->stats.rx_bytes += rx_status.inb_octets;
234 priv->stats.tx_bytes += tx_status.octets; 234 dev->stats.tx_bytes += tx_status.octets;
235 priv->stats.multicast += rx_status.multicast_packets; 235 dev->stats.multicast += rx_status.multicast_packets;
236 priv->stats.rx_crc_errors += rx_status.inb_errors; 236 dev->stats.rx_crc_errors += rx_status.inb_errors;
237 priv->stats.rx_frame_errors += rx_status.fcs_align_err_packets; 237 dev->stats.rx_frame_errors += rx_status.fcs_align_err_packets;
238 priv->stats.rx_dropped += rx_status.dropped_packets; 238 dev->stats.rx_dropped += rx_status.dropped_packets;
239 } 239 }
240 240
241 return &priv->stats; 241 return &dev->stats;
242} 242}
243 243
244/** 244/**
@@ -889,7 +889,8 @@ static int cvm_oct_probe(struct platform_device *pdev)
889 fau -= 889 fau -=
890 cvmx_pko_get_num_queues(priv->port) * 890 cvmx_pko_get_num_queues(priv->port) *
891 sizeof(u32); 891 sizeof(u32);
892 schedule_delayed_work(&priv->port_periodic_work, HZ); 892 schedule_delayed_work(&priv->port_periodic_work,
893 HZ);
893 } 894 }
894 } 895 }
895 } 896 }
diff --git a/drivers/staging/octeon/octeon-ethernet.h b/drivers/staging/octeon/octeon-ethernet.h
index 9c6852d61c0d..9c3f453adaa0 100644
--- a/drivers/staging/octeon/octeon-ethernet.h
+++ b/drivers/staging/octeon/octeon-ethernet.h
@@ -38,8 +38,6 @@ struct octeon_ethernet {
38 int imode; 38 int imode;
39 /* List of outstanding tx buffers per queue */ 39 /* List of outstanding tx buffers per queue */
40 struct sk_buff_head tx_free_list[16]; 40 struct sk_buff_head tx_free_list[16];
41 /* Device statistics */
42 struct net_device_stats stats;
43 unsigned int last_speed; 41 unsigned int last_speed;
44 unsigned int last_link; 42 unsigned int last_link;
45 /* Last negotiated link state */ 43 /* Last negotiated link state */
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index f45b2ef05f48..684815c98789 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -81,7 +81,7 @@ static int dcon_hw_init(struct dcon_priv *dcon, int is_init)
81 81
82 if (ver < 0xdc02) { 82 if (ver < 0xdc02) {
83 dev_err(&dcon->client->dev, 83 dev_err(&dcon->client->dev,
84 "DCON v1 is unsupported, giving up..\n"); 84 "DCON v1 is unsupported, giving up..\n");
85 rc = -ENODEV; 85 rc = -ENODEV;
86 goto err; 86 goto err;
87 } 87 }
@@ -90,7 +90,7 @@ static int dcon_hw_init(struct dcon_priv *dcon, int is_init)
90 dcon_write(dcon, 0x3a, 0xc040); 90 dcon_write(dcon, 0x3a, 0xc040);
91 dcon_write(dcon, DCON_REG_MEM_OPT_A, 0x0000); /* clear option bits */ 91 dcon_write(dcon, DCON_REG_MEM_OPT_A, 0x0000); /* clear option bits */
92 dcon_write(dcon, DCON_REG_MEM_OPT_A, 92 dcon_write(dcon, DCON_REG_MEM_OPT_A,
93 MEM_DLL_CLOCK_DELAY | MEM_POWER_DOWN); 93 MEM_DLL_CLOCK_DELAY | MEM_POWER_DOWN);
94 dcon_write(dcon, DCON_REG_MEM_OPT_B, MEM_SOFT_RESET); 94 dcon_write(dcon, DCON_REG_MEM_OPT_B, MEM_SOFT_RESET);
95 95
96 /* Colour swizzle, AA, no passthrough, backlight */ 96 /* Colour swizzle, AA, no passthrough, backlight */
@@ -261,14 +261,14 @@ static bool dcon_blank_fb(struct dcon_priv *dcon, bool blank)
261 261
262 dcon->ignore_fb_events = true; 262 dcon->ignore_fb_events = true;
263 err = fb_blank(dcon->fbinfo, 263 err = fb_blank(dcon->fbinfo,
264 blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK); 264 blank ? FB_BLANK_POWERDOWN : FB_BLANK_UNBLANK);
265 dcon->ignore_fb_events = false; 265 dcon->ignore_fb_events = false;
266 unlock_fb_info(dcon->fbinfo); 266 unlock_fb_info(dcon->fbinfo);
267 console_unlock(); 267 console_unlock();
268 268
269 if (err) { 269 if (err) {
270 dev_err(&dcon->client->dev, "couldn't %sblank framebuffer\n", 270 dev_err(&dcon->client->dev, "couldn't %sblank framebuffer\n",
271 blank ? "" : "un"); 271 blank ? "" : "un");
272 return false; 272 return false;
273 } 273 }
274 return true; 274 return true;
@@ -293,7 +293,7 @@ static void dcon_source_switch(struct work_struct *work)
293 pr_info("dcon_source_switch to CPU\n"); 293 pr_info("dcon_source_switch to CPU\n");
294 /* Enable the scanline interrupt bit */ 294 /* Enable the scanline interrupt bit */
295 if (dcon_write(dcon, DCON_REG_MODE, 295 if (dcon_write(dcon, DCON_REG_MODE,
296 dcon->disp_mode | MODE_SCAN_INT)) 296 dcon->disp_mode | MODE_SCAN_INT))
297 pr_err("couldn't enable scanline interrupt!\n"); 297 pr_err("couldn't enable scanline interrupt!\n");
298 else 298 else
299 /* Wait up to one second for the scanline interrupt */ 299 /* Wait up to one second for the scanline interrupt */
@@ -336,7 +336,7 @@ static void dcon_source_switch(struct work_struct *work)
336 pdata->set_dconload(0); 336 pdata->set_dconload(0);
337 dcon->load_time = ktime_get(); 337 dcon->load_time = ktime_get();
338 338
339 wait_event_timeout(dcon->waitq, dcon->switched, HZ/2); 339 wait_event_timeout(dcon->waitq, dcon->switched, HZ / 2);
340 340
341 if (!dcon->switched) { 341 if (!dcon->switched) {
342 pr_err("Timeout entering DCON mode; expect a screen glitch.\n"); 342 pr_err("Timeout entering DCON mode; expect a screen glitch.\n");
@@ -646,7 +646,7 @@ static int dcon_probe(struct i2c_client *client, const struct i2c_device_id *id)
646 dcon, &dcon_bl_ops, &dcon_bl_props); 646 dcon, &dcon_bl_ops, &dcon_bl_props);
647 if (IS_ERR(dcon->bl_dev)) { 647 if (IS_ERR(dcon->bl_dev)) {
648 dev_err(&client->dev, "cannot register backlight dev (%ld)\n", 648 dev_err(&client->dev, "cannot register backlight dev (%ld)\n",
649 PTR_ERR(dcon->bl_dev)); 649 PTR_ERR(dcon->bl_dev));
650 dcon->bl_dev = NULL; 650 dcon->bl_dev = NULL;
651 } 651 }
652 652
diff --git a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
index 1e23ef15b263..75c3c2fe9560 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon_xo_1_5.c
@@ -53,9 +53,8 @@ static int dcon_was_irq(void)
53 53
54 /* irq status will appear in PMIO_Rx50[6] on gpio12 */ 54 /* irq status will appear in PMIO_Rx50[6] on gpio12 */
55 tmp = inb(VX855_GPI_STATUS_CHG); 55 tmp = inb(VX855_GPI_STATUS_CHG);
56 return !!(tmp & BIT_GPIO12);
57 56
58 return 0; 57 return !!(tmp & BIT_GPIO12);
59} 58}
60 59
61static int dcon_init_xo_1_5(struct dcon_priv *dcon) 60static int dcon_init_xo_1_5(struct dcon_priv *dcon)
@@ -108,7 +107,6 @@ static void set_i2c_line(int sda, int scl)
108 outb(tmp, 0x3c5); 107 outb(tmp, 0x3c5);
109} 108}
110 109
111
112static void dcon_wiggle_xo_1_5(void) 110static void dcon_wiggle_xo_1_5(void)
113{ 111{
114 int x; 112 int x;
diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
index 553e8d50352f..1c8fa3a1f5bb 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ap.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -26,7 +26,7 @@
26 26
27void init_mlme_ap_info(struct adapter *padapter) 27void init_mlme_ap_info(struct adapter *padapter)
28{ 28{
29 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 29 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
30 struct sta_priv *pstapriv = &padapter->stapriv; 30 struct sta_priv *pstapriv = &padapter->stapriv;
31 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; 31 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
32 32
@@ -43,7 +43,7 @@ void free_mlme_ap_info(struct adapter *padapter)
43{ 43{
44 struct sta_info *psta = NULL; 44 struct sta_info *psta = NULL;
45 struct sta_priv *pstapriv = &padapter->stapriv; 45 struct sta_priv *pstapriv = &padapter->stapriv;
46 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 46 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
47 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 47 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
48 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 48 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
49 49
@@ -59,17 +59,17 @@ void free_mlme_ap_info(struct adapter *padapter)
59 59
60 /* free bc/mc sta_info */ 60 /* free bc/mc sta_info */
61 psta = rtw_get_bcmc_stainfo(padapter); 61 psta = rtw_get_bcmc_stainfo(padapter);
62 spin_lock_bh(&(pstapriv->sta_hash_lock)); 62 spin_lock_bh(&pstapriv->sta_hash_lock);
63 rtw_free_stainfo(padapter, psta); 63 rtw_free_stainfo(padapter, psta);
64 spin_unlock_bh(&(pstapriv->sta_hash_lock)); 64 spin_unlock_bh(&pstapriv->sta_hash_lock);
65} 65}
66 66
67static void update_BCNTIM(struct adapter *padapter) 67static void update_BCNTIM(struct adapter *padapter)
68{ 68{
69 struct sta_priv *pstapriv = &padapter->stapriv; 69 struct sta_priv *pstapriv = &padapter->stapriv;
70 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 70 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
71 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 71 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
72 struct wlan_bssid_ex *pnetwork_mlmeext = &(pmlmeinfo->network); 72 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
73 unsigned char *pie = pnetwork_mlmeext->IEs; 73 unsigned char *pie = pnetwork_mlmeext->IEs;
74 u8 *p, *dst_ie, *premainder_ie = NULL; 74 u8 *p, *dst_ie, *premainder_ie = NULL;
75 u8 *pbackup_remainder_ie = NULL; 75 u8 *pbackup_remainder_ie = NULL;
@@ -94,10 +94,9 @@ static void update_BCNTIM(struct adapter *padapter)
94 offset += pnetwork_mlmeext->Ssid.SsidLength + 2; 94 offset += pnetwork_mlmeext->Ssid.SsidLength + 2;
95 95
96 /* get supported rates len */ 96 /* get supported rates len */
97 p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, 97 p = rtw_get_ie(pie + _BEACON_IE_OFFSET_, _SUPPORTEDRATES_IE_,
98 _SUPPORTEDRATES_IE_, &tmp_len, 98 &tmp_len, (pnetwork_mlmeext->IELength -
99 (pnetwork_mlmeext->IELength - 99 _BEACON_IE_OFFSET_));
100 _BEACON_IE_OFFSET_));
101 if (p) 100 if (p)
102 offset += tmp_len+2; 101 offset += tmp_len+2;
103 102
@@ -116,13 +115,12 @@ static void update_BCNTIM(struct adapter *padapter)
116 if (remainder_ielen > 0) { 115 if (remainder_ielen > 0) {
117 pbackup_remainder_ie = rtw_malloc(remainder_ielen); 116 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
118 if (pbackup_remainder_ie && premainder_ie) 117 if (pbackup_remainder_ie && premainder_ie)
119 memcpy(pbackup_remainder_ie, 118 memcpy(pbackup_remainder_ie, premainder_ie,
120 premainder_ie, remainder_ielen); 119 remainder_ielen);
121 } 120 }
122 *dst_ie++ = _TIM_IE_; 121 *dst_ie++ = _TIM_IE_;
123 122
124 if ((pstapriv->tim_bitmap&0xff00) && 123 if ((pstapriv->tim_bitmap&0xff00) && (pstapriv->tim_bitmap&0x00fc))
125 (pstapriv->tim_bitmap&0x00fc))
126 tim_ielen = 5; 124 tim_ielen = 5;
127 else 125 else
128 tim_ielen = 4; 126 tim_ielen = 4;
@@ -157,7 +155,7 @@ static void update_BCNTIM(struct adapter *padapter)
157} 155}
158 156
159void rtw_add_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork, 157void rtw_add_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork,
160 u8 index, u8 *data, u8 len) 158 u8 index, u8 *data, u8 len)
161{ 159{
162 struct ndis_802_11_var_ie *pIE; 160 struct ndis_802_11_var_ie *pIE;
163 u8 bmatch = false; 161 u8 bmatch = false;
@@ -201,8 +199,8 @@ void rtw_add_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork,
201 if (remainder_ielen > 0) { 199 if (remainder_ielen > 0) {
202 pbackup_remainder_ie = rtw_malloc(remainder_ielen); 200 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
203 if (pbackup_remainder_ie && premainder_ie) 201 if (pbackup_remainder_ie && premainder_ie)
204 memcpy(pbackup_remainder_ie, 202 memcpy(pbackup_remainder_ie, premainder_ie,
205 premainder_ie, remainder_ielen); 203 remainder_ielen);
206 } 204 }
207 205
208 *dst_ie++ = index; 206 *dst_ie++ = index;
@@ -223,7 +221,7 @@ void rtw_add_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork,
223} 221}
224 222
225void rtw_remove_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork, 223void rtw_remove_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork,
226 u8 index) 224 u8 index)
227{ 225{
228 u8 *p, *dst_ie = NULL, *premainder_ie = NULL; 226 u8 *p, *dst_ie = NULL, *premainder_ie = NULL;
229 u8 *pbackup_remainder_ie = NULL; 227 u8 *pbackup_remainder_ie = NULL;
@@ -247,8 +245,8 @@ void rtw_remove_bcn_ie(struct adapter *padapter, struct wlan_bssid_ex *pnetwork,
247 if (remainder_ielen > 0) { 245 if (remainder_ielen > 0) {
248 pbackup_remainder_ie = rtw_malloc(remainder_ielen); 246 pbackup_remainder_ie = rtw_malloc(remainder_ielen);
249 if (pbackup_remainder_ie && premainder_ie) 247 if (pbackup_remainder_ie && premainder_ie)
250 memcpy(pbackup_remainder_ie, 248 memcpy(pbackup_remainder_ie, premainder_ie,
251 premainder_ie, remainder_ielen); 249 remainder_ielen);
252 } 250 }
253 251
254 /* copy remainder IE */ 252 /* copy remainder IE */
@@ -310,9 +308,9 @@ void expire_timeout_chk(struct adapter *padapter)
310 308
311 spin_unlock_bh(&pstapriv->auth_list_lock); 309 spin_unlock_bh(&pstapriv->auth_list_lock);
312 310
313 spin_lock_bh(&(pstapriv->sta_hash_lock)); 311 spin_lock_bh(&pstapriv->sta_hash_lock);
314 rtw_free_stainfo(padapter, psta); 312 rtw_free_stainfo(padapter, psta);
315 spin_unlock_bh(&(pstapriv->sta_hash_lock)); 313 spin_unlock_bh(&pstapriv->sta_hash_lock);
316 314
317 spin_lock_bh(&pstapriv->auth_list_lock); 315 spin_lock_bh(&pstapriv->auth_list_lock);
318 } 316 }
@@ -361,8 +359,8 @@ void expire_timeout_chk(struct adapter *padapter)
361 * for this station 359 * for this station
362 */ 360 */
363 pstapriv->tim_bitmap |= BIT(psta->aid); 361 pstapriv->tim_bitmap |= BIT(psta->aid);
364 update_beacon(padapter, _TIM_IE_, 362 update_beacon(padapter, _TIM_IE_, NULL,
365 NULL, false); 363 false);
366 364
367 if (!pmlmeext->active_keep_alive_check) 365 if (!pmlmeext->active_keep_alive_check)
368 continue; 366 continue;
@@ -456,7 +454,7 @@ void add_RATid(struct adapter *padapter, struct sta_info *psta, u8 rssi_level)
456 unsigned char limit; 454 unsigned char limit;
457 unsigned int tx_ra_bitmap = 0; 455 unsigned int tx_ra_bitmap = 0;
458 struct ht_priv *psta_ht = NULL; 456 struct ht_priv *psta_ht = NULL;
459 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 457 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
460 struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; 458 struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
461 459
462 if (psta) 460 if (psta)
@@ -548,7 +546,7 @@ static void update_bmc_sta(struct adapter *padapter)
548 unsigned char network_type, raid; 546 unsigned char network_type, raid;
549 int i, supportRateNum = 0; 547 int i, supportRateNum = 0;
550 unsigned int tx_ra_bitmap = 0; 548 unsigned int tx_ra_bitmap = 0;
551 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 549 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
552 struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; 550 struct wlan_bssid_ex *pcur_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
553 struct sta_info *psta = rtw_get_bcmc_stainfo(padapter); 551 struct sta_info *psta = rtw_get_bcmc_stainfo(padapter);
554 552
@@ -630,9 +628,9 @@ static void update_bmc_sta(struct adapter *padapter)
630 628
631void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta) 629void update_sta_info_apmode(struct adapter *padapter, struct sta_info *psta)
632{ 630{
633 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 631 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
634 struct security_priv *psecuritypriv = &padapter->securitypriv; 632 struct security_priv *psecuritypriv = &padapter->securitypriv;
635 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 633 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
636 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv; 634 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
637 struct ht_priv *phtpriv_sta = &psta->htpriv; 635 struct ht_priv *phtpriv_sta = &psta->htpriv;
638 636
@@ -700,7 +698,7 @@ static void update_hw_ht_param(struct adapter *padapter)
700 unsigned char max_AMPDU_len; 698 unsigned char max_AMPDU_len;
701 unsigned char min_MPDU_spacing; 699 unsigned char min_MPDU_spacing;
702 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 700 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
703 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 701 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
704 702
705 DBG_88E("%s\n", __func__); 703 DBG_88E("%s\n", __func__);
706 704
@@ -733,12 +731,12 @@ static void start_bss_network(struct adapter *padapter, u8 *pbuf)
733 u32 acparm; 731 u32 acparm;
734 int ie_len; 732 int ie_len;
735 struct registry_priv *pregpriv = &padapter->registrypriv; 733 struct registry_priv *pregpriv = &padapter->registrypriv;
736 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 734 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
737 struct security_priv *psecuritypriv = &(padapter->securitypriv); 735 struct security_priv *psecuritypriv = &padapter->securitypriv;
738 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; 736 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
739 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 737 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
740 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 738 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
741 struct wlan_bssid_ex *pnetwork_mlmeext = &(pmlmeinfo->network); 739 struct wlan_bssid_ex *pnetwork_mlmeext = &pmlmeinfo->network;
742 struct HT_info_element *pht_info = NULL; 740 struct HT_info_element *pht_info = NULL;
743 741
744 bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod; 742 bcn_interval = (u16)pnetwork->Configuration.BeaconPeriod;
@@ -869,7 +867,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
869 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01}; 867 u8 WMM_PARA_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x01, 0x01};
870 struct registry_priv *pregistrypriv = &padapter->registrypriv; 868 struct registry_priv *pregistrypriv = &padapter->registrypriv;
871 struct security_priv *psecuritypriv = &padapter->securitypriv; 869 struct security_priv *psecuritypriv = &padapter->securitypriv;
872 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 870 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
873 struct wlan_bssid_ex *pbss_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network; 871 struct wlan_bssid_ex *pbss_network = (struct wlan_bssid_ex *)&pmlmepriv->cur_network.network;
874 u8 *ie = pbss_network->IEs; 872 u8 *ie = pbss_network->IEs;
875 873
@@ -905,7 +903,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
905 903
906 pbss_network->Rssi = 0; 904 pbss_network->Rssi = 0;
907 905
908 ether_addr_copy(pbss_network->MacAddress, myid(&(padapter->eeprompriv))); 906 ether_addr_copy(pbss_network->MacAddress, myid(&padapter->eeprompriv));
909 907
910 /* beacon interval */ 908 /* beacon interval */
911 p = rtw_get_beacon_interval_from_ie(ie);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */ 909 p = rtw_get_beacon_interval_from_ie(ie);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
@@ -1150,7 +1148,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1150 if ((NUM_ACL - 1) < pacl_list->num) 1148 if ((NUM_ACL - 1) < pacl_list->num)
1151 return -1; 1149 return -1;
1152 1150
1153 spin_lock_bh(&(pacl_node_q->lock)); 1151 spin_lock_bh(&pacl_node_q->lock);
1154 1152
1155 phead = get_list_head(pacl_node_q); 1153 phead = get_list_head(pacl_node_q);
1156 plist = phead->next; 1154 plist = phead->next;
@@ -1168,12 +1166,12 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1168 } 1166 }
1169 } 1167 }
1170 1168
1171 spin_unlock_bh(&(pacl_node_q->lock)); 1169 spin_unlock_bh(&pacl_node_q->lock);
1172 1170
1173 if (added) 1171 if (added)
1174 return ret; 1172 return ret;
1175 1173
1176 spin_lock_bh(&(pacl_node_q->lock)); 1174 spin_lock_bh(&pacl_node_q->lock);
1177 1175
1178 for (i = 0; i < NUM_ACL; i++) { 1176 for (i = 0; i < NUM_ACL; i++) {
1179 paclnode = &pacl_list->aclnode[i]; 1177 paclnode = &pacl_list->aclnode[i];
@@ -1195,7 +1193,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1195 1193
1196 DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num); 1194 DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num);
1197 1195
1198 spin_unlock_bh(&(pacl_node_q->lock)); 1196 spin_unlock_bh(&pacl_node_q->lock);
1199 1197
1200 return ret; 1198 return ret;
1201} 1199}
@@ -1210,7 +1208,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1210 1208
1211 DBG_88E("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, (addr)); 1209 DBG_88E("%s(acl_num =%d) =%pM\n", __func__, pacl_list->num, (addr));
1212 1210
1213 spin_lock_bh(&(pacl_node_q->lock)); 1211 spin_lock_bh(&pacl_node_q->lock);
1214 1212
1215 phead = get_list_head(pacl_node_q); 1213 phead = get_list_head(pacl_node_q);
1216 plist = phead->next; 1214 plist = phead->next;
@@ -1230,7 +1228,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1230 } 1228 }
1231 } 1229 }
1232 1230
1233 spin_unlock_bh(&(pacl_node_q->lock)); 1231 spin_unlock_bh(&pacl_node_q->lock);
1234 1232
1235 DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num); 1233 DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num);
1236 return 0; 1234 return 0;
@@ -1238,10 +1236,10 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1238 1236
1239static void update_bcn_erpinfo_ie(struct adapter *padapter) 1237static void update_bcn_erpinfo_ie(struct adapter *padapter)
1240{ 1238{
1241 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1239 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1242 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 1240 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1243 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 1241 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1244 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); 1242 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1245 unsigned char *p, *ie = pnetwork->IEs; 1243 unsigned char *p, *ie = pnetwork->IEs;
1246 u32 len = 0; 1244 u32 len = 0;
1247 1245
@@ -1275,10 +1273,10 @@ static void update_bcn_wps_ie(struct adapter *padapter)
1275 u8 *pwps_ie = NULL, *pwps_ie_src; 1273 u8 *pwps_ie = NULL, *pwps_ie_src;
1276 u8 *premainder_ie, *pbackup_remainder_ie = NULL; 1274 u8 *premainder_ie, *pbackup_remainder_ie = NULL;
1277 uint wps_ielen = 0, wps_offset, remainder_ielen; 1275 uint wps_ielen = 0, wps_offset, remainder_ielen;
1278 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1276 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1279 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 1277 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1280 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 1278 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1281 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); 1279 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
1282 unsigned char *ie = pnetwork->IEs; 1280 unsigned char *ie = pnetwork->IEs;
1283 u32 ielen = pnetwork->IELength; 1281 u32 ielen = pnetwork->IELength;
1284 1282
@@ -1338,8 +1336,8 @@ void update_beacon(struct adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1338 if (!padapter) 1336 if (!padapter)
1339 return; 1337 return;
1340 1338
1341 pmlmepriv = &(padapter->mlmepriv); 1339 pmlmepriv = &padapter->mlmepriv;
1342 pmlmeext = &(padapter->mlmeextpriv); 1340 pmlmeext = &padapter->mlmeextpriv;
1343 1341
1344 if (!pmlmeext->bstart_bss) 1342 if (!pmlmeext->bstart_bss)
1345 return; 1343 return;
@@ -1384,7 +1382,7 @@ static int rtw_ht_operation_update(struct adapter *padapter)
1384{ 1382{
1385 u16 cur_op_mode, new_op_mode; 1383 u16 cur_op_mode, new_op_mode;
1386 int op_mode_changes = 0; 1384 int op_mode_changes = 0;
1387 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1385 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1388 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv; 1386 struct ht_priv *phtpriv_ap = &pmlmepriv->htpriv;
1389 1387
1390 if (pmlmepriv->htpriv.ht_option) 1388 if (pmlmepriv->htpriv.ht_option)
@@ -1477,8 +1475,8 @@ void associated_clients_update(struct adapter *padapter, u8 updated)
1477void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta) 1475void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
1478{ 1476{
1479 u8 beacon_updated = false; 1477 u8 beacon_updated = false;
1480 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1478 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1481 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 1479 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1482 1480
1483 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) { 1481 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
1484 if (!psta->no_short_preamble_set) { 1482 if (!psta->no_short_preamble_set) {
@@ -1573,8 +1571,8 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
1573 pmlmepriv->num_sta_ht_no_gf++; 1571 pmlmepriv->num_sta_ht_no_gf++;
1574 } 1572 }
1575 DBG_88E("%s STA %pM - no greenfield, num of non-gf stations %d\n", 1573 DBG_88E("%s STA %pM - no greenfield, num of non-gf stations %d\n",
1576 __func__, (psta->hwaddr), 1574 __func__, (psta->hwaddr),
1577 pmlmepriv->num_sta_ht_no_gf); 1575 pmlmepriv->num_sta_ht_no_gf);
1578 } 1576 }
1579 1577
1580 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) { 1578 if ((ht_capab & IEEE80211_HT_CAP_SUP_WIDTH) == 0) {
@@ -1583,8 +1581,8 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
1583 pmlmepriv->num_sta_ht_20mhz++; 1581 pmlmepriv->num_sta_ht_20mhz++;
1584 } 1582 }
1585 DBG_88E("%s STA %pM - 20 MHz HT, num of 20MHz HT STAs %d\n", 1583 DBG_88E("%s STA %pM - 20 MHz HT, num of 20MHz HT STAs %d\n",
1586 __func__, (psta->hwaddr), 1584 __func__, (psta->hwaddr),
1587 pmlmepriv->num_sta_ht_20mhz); 1585 pmlmepriv->num_sta_ht_20mhz);
1588 } 1586 }
1589 } else { 1587 } else {
1590 if (!psta->no_ht_set) { 1588 if (!psta->no_ht_set) {
@@ -1612,8 +1610,8 @@ void bss_cap_update_on_sta_join(struct adapter *padapter, struct sta_info *psta)
1612u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta) 1610u8 bss_cap_update_on_sta_leave(struct adapter *padapter, struct sta_info *psta)
1613{ 1611{
1614 u8 beacon_updated = false; 1612 u8 beacon_updated = false;
1615 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1613 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1616 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv); 1614 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1617 1615
1618 if (!psta) 1616 if (!psta)
1619 return beacon_updated; 1617 return beacon_updated;
@@ -1708,9 +1706,9 @@ u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta,
1708 1706
1709 beacon_updated = bss_cap_update_on_sta_leave(padapter, psta); 1707 beacon_updated = bss_cap_update_on_sta_leave(padapter, psta);
1710 1708
1711 spin_lock_bh(&(pstapriv->sta_hash_lock)); 1709 spin_lock_bh(&pstapriv->sta_hash_lock);
1712 rtw_free_stainfo(padapter, psta); 1710 rtw_free_stainfo(padapter, psta);
1713 spin_unlock_bh(&(pstapriv->sta_hash_lock)); 1711 spin_unlock_bh(&pstapriv->sta_hash_lock);
1714 1712
1715 return beacon_updated; 1713 return beacon_updated;
1716} 1714}
@@ -1721,7 +1719,7 @@ int rtw_sta_flush(struct adapter *padapter)
1721 struct sta_info *psta = NULL; 1719 struct sta_info *psta = NULL;
1722 struct sta_priv *pstapriv = &padapter->stapriv; 1720 struct sta_priv *pstapriv = &padapter->stapriv;
1723 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1721 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1724 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 1722 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1725 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 1723 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1726 1724
1727 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev)); 1725 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
@@ -1758,7 +1756,7 @@ int rtw_sta_flush(struct adapter *padapter)
1758void sta_info_update(struct adapter *padapter, struct sta_info *psta) 1756void sta_info_update(struct adapter *padapter, struct sta_info *psta)
1759{ 1757{
1760 int flags = psta->flags; 1758 int flags = psta->flags;
1761 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1759 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1762 1760
1763 /* update wmm cap. */ 1761 /* update wmm cap. */
1764 if (WLAN_STA_WME&flags) 1762 if (WLAN_STA_WME&flags)
@@ -1795,7 +1793,7 @@ void ap_sta_info_defer_update(struct adapter *padapter, struct sta_info *psta)
1795void start_ap_mode(struct adapter *padapter) 1793void start_ap_mode(struct adapter *padapter)
1796{ 1794{
1797 int i; 1795 int i;
1798 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1796 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1799 struct sta_priv *pstapriv = &padapter->stapriv; 1797 struct sta_priv *pstapriv = &padapter->stapriv;
1800 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1798 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1801 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; 1799 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
@@ -1828,7 +1826,7 @@ void start_ap_mode(struct adapter *padapter)
1828 pmlmepriv->wps_assoc_resp_ie = NULL; 1826 pmlmepriv->wps_assoc_resp_ie = NULL;
1829 1827
1830 /* for ACL */ 1828 /* for ACL */
1831 INIT_LIST_HEAD(&(pacl_list->acl_node_q.queue)); 1829 INIT_LIST_HEAD(&pacl_list->acl_node_q.queue);
1832 pacl_list->num = 0; 1830 pacl_list->num = 0;
1833 pacl_list->mode = 0; 1831 pacl_list->mode = 0;
1834 for (i = 0; i < NUM_ACL; i++) { 1832 for (i = 0; i < NUM_ACL; i++) {
@@ -1843,7 +1841,7 @@ void stop_ap_mode(struct adapter *padapter)
1843 struct rtw_wlan_acl_node *paclnode; 1841 struct rtw_wlan_acl_node *paclnode;
1844 struct sta_info *psta = NULL; 1842 struct sta_info *psta = NULL;
1845 struct sta_priv *pstapriv = &padapter->stapriv; 1843 struct sta_priv *pstapriv = &padapter->stapriv;
1846 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 1844 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1847 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1845 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1848 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; 1846 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1849 struct __queue *pacl_node_q = &pacl_list->acl_node_q; 1847 struct __queue *pacl_node_q = &pacl_list->acl_node_q;
@@ -1857,7 +1855,7 @@ void stop_ap_mode(struct adapter *padapter)
1857 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled; 1855 padapter->securitypriv.ndisencryptstatus = Ndis802_11WEPDisabled;
1858 1856
1859 /* for ACL */ 1857 /* for ACL */
1860 spin_lock_bh(&(pacl_node_q->lock)); 1858 spin_lock_bh(&pacl_node_q->lock);
1861 phead = get_list_head(pacl_node_q); 1859 phead = get_list_head(pacl_node_q);
1862 plist = phead->next; 1860 plist = phead->next;
1863 while (phead != plist) { 1861 while (phead != plist) {
@@ -1872,7 +1870,7 @@ void stop_ap_mode(struct adapter *padapter)
1872 pacl_list->num--; 1870 pacl_list->num--;
1873 } 1871 }
1874 } 1872 }
1875 spin_unlock_bh(&(pacl_node_q->lock)); 1873 spin_unlock_bh(&pacl_node_q->lock);
1876 1874
1877 DBG_88E("%s, free acl_node_queue, num =%d\n", __func__, pacl_list->num); 1875 DBG_88E("%s, free acl_node_queue, num =%d\n", __func__, pacl_list->num);
1878 1876
@@ -1882,9 +1880,9 @@ void stop_ap_mode(struct adapter *padapter)
1882 rtw_free_all_stainfo(padapter); 1880 rtw_free_all_stainfo(padapter);
1883 1881
1884 psta = rtw_get_bcmc_stainfo(padapter); 1882 psta = rtw_get_bcmc_stainfo(padapter);
1885 spin_lock_bh(&(pstapriv->sta_hash_lock)); 1883 spin_lock_bh(&pstapriv->sta_hash_lock);
1886 rtw_free_stainfo(padapter, psta); 1884 rtw_free_stainfo(padapter, psta);
1887 spin_unlock_bh(&(pstapriv->sta_hash_lock)); 1885 spin_unlock_bh(&pstapriv->sta_hash_lock);
1888 1886
1889 rtw_init_bcmc_stainfo(padapter); 1887 rtw_init_bcmc_stainfo(padapter);
1890 1888
diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 36109cec8706..14979666dadd 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -1321,9 +1321,6 @@ void rtw_setassocsta_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *
1321 1321
1322 spin_lock_bh(&pmlmepriv->lock); 1322 spin_lock_bh(&pmlmepriv->lock);
1323 1323
1324 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) && (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true))
1325 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
1326
1327 set_fwstate(pmlmepriv, _FW_LINKED); 1324 set_fwstate(pmlmepriv, _FW_LINKED);
1328 spin_unlock_bh(&pmlmepriv->lock); 1325 spin_unlock_bh(&pmlmepriv->lock);
1329 1326
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 16cc7706a1e6..b9bdff0490ca 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -253,6 +253,7 @@ static void efuse_read_phymap_from_txpktbuf(
253 u8 lenc[2]; 253 u8 lenc[2];
254 u16 lenbak, aaabak; 254 u16 lenbak, aaabak;
255 u16 aaa; 255 u16 aaa;
256
256 lenc[0] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L); 257 lenc[0] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L);
257 lenc[1] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L+1); 258 lenc[1] = usb_read8(adapter, REG_PKTBUF_DBG_DATA_L+1);
258 259
@@ -562,13 +563,14 @@ static bool hal_EfusePgPacketWrite2ByteHeader(struct adapter *pAdapter, u8 efuse
562 } 563 }
563 564
564 if ((tmp_header & 0x0F) == 0x0F) { /* word_en PG fail */ 565 if ((tmp_header & 0x0F) == 0x0F) { /* word_en PG fail */
565 if (repeatcnt++ > EFUSE_REPEAT_THRESHOLD_) { 566 if (repeatcnt++ > EFUSE_REPEAT_THRESHOLD_)
566 return false; 567 return false;
567 } 568
568 efuse_addr++; 569 efuse_addr++;
569 continue; 570 continue;
570 } else if (pg_header != tmp_header) { /* offset PG fail */ 571 } else if (pg_header != tmp_header) { /* offset PG fail */
571 struct pgpkt fixPkt; 572 struct pgpkt fixPkt;
573
572 fixPkt.offset = ((pg_header_temp & 0xE0) >> 5) | ((tmp_header & 0xF0) >> 1); 574 fixPkt.offset = ((pg_header_temp & 0xE0) >> 5) | ((tmp_header & 0xF0) >> 1);
573 fixPkt.word_en = tmp_header & 0x0F; 575 fixPkt.word_en = tmp_header & 0x0F;
574 fixPkt.word_cnts = Efuse_CalculateWordCnts(fixPkt.word_en); 576 fixPkt.word_cnts = Efuse_CalculateWordCnts(fixPkt.word_en);
@@ -611,6 +613,7 @@ static bool hal_EfusePgPacketWrite1ByteHeader(struct adapter *pAdapter, u8 efuse
611 bRet = true; 613 bRet = true;
612 } else { 614 } else {
613 struct pgpkt fixPkt; 615 struct pgpkt fixPkt;
616
614 fixPkt.offset = (tmp_header>>4) & 0x0F; 617 fixPkt.offset = (tmp_header>>4) & 0x0F;
615 fixPkt.word_en = tmp_header & 0x0F; 618 fixPkt.word_en = tmp_header & 0x0F;
616 fixPkt.word_cnts = Efuse_CalculateWordCnts(fixPkt.word_en); 619 fixPkt.word_cnts = Efuse_CalculateWordCnts(fixPkt.word_en);
@@ -819,6 +822,7 @@ bool Efuse_PgPacketWrite(struct adapter *pAdapter, u8 offset, u8 word_en, u8 *pD
819u8 Efuse_CalculateWordCnts(u8 word_en) 822u8 Efuse_CalculateWordCnts(u8 word_en)
820{ 823{
821 u8 word_cnts = 0; 824 u8 word_cnts = 0;
825
822 if (!(word_en & BIT(0))) 826 if (!(word_en & BIT(0)))
823 word_cnts++; /* 0 : write enable */ 827 word_cnts++; /* 0 : write enable */
824 if (!(word_en & BIT(1))) 828 if (!(word_en & BIT(1)))
diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
index 914c4923421b..d1cd34011602 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
@@ -71,8 +71,8 @@ int rtw_get_bit_value_from_ieee_value(u8 val)
71 unsigned char dot11_rate_table[] = { 71 unsigned char dot11_rate_table[] = {
72 2, 4, 11, 22, 12, 18, 24, 36, 48, 72 2, 4, 11, 22, 12, 18, 24, 36, 48,
73 72, 96, 108, 0}; /* last element must be zero!! */ 73 72, 96, 108, 0}; /* last element must be zero!! */
74
75 int i = 0; 74 int i = 0;
75
76 while (dot11_rate_table[i] != 0) { 76 while (dot11_rate_table[i] != 0) {
77 if (dot11_rate_table[i] == val) 77 if (dot11_rate_table[i] == val)
78 return BIT(i); 78 return BIT(i);
@@ -162,6 +162,7 @@ u8 *rtw_get_ie(u8 *pbuf, int index, int *len, int limit)
162{ 162{
163 int tmp, i; 163 int tmp, i;
164 u8 *p; 164 u8 *p;
165
165 if (limit < 1) 166 if (limit < 1)
166 return NULL; 167 return NULL;
167 168
@@ -211,6 +212,7 @@ void rtw_set_supported_rate(u8 *SupportedRates, uint mode)
211uint rtw_get_rateset_len(u8 *rateset) 212uint rtw_get_rateset_len(u8 *rateset)
212{ 213{
213 uint i = 0; 214 uint i = 0;
215
214 while (1) { 216 while (1) {
215 if ((rateset[i]) == 0) 217 if ((rateset[i]) == 0)
216 break; 218 break;
@@ -998,10 +1000,11 @@ int ieee80211_get_hdrlen(u16 fc)
998 1000
999static int rtw_get_cipher_info(struct wlan_network *pnetwork) 1001static int rtw_get_cipher_info(struct wlan_network *pnetwork)
1000{ 1002{
1001 u32 wpa_ielen; 1003 int wpa_ielen;
1002 unsigned char *pbuf; 1004 unsigned char *pbuf;
1003 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0; 1005 int group_cipher = 0, pairwise_cipher = 0, is8021x = 0;
1004 int ret = _FAIL; 1006 int ret = _FAIL;
1007
1005 pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12); 1008 pbuf = rtw_get_wpa_ie(&pnetwork->network.IEs[12], &wpa_ielen, pnetwork->network.IELength - 12);
1006 1009
1007 if (pbuf && (wpa_ielen > 0)) { 1010 if (pbuf && (wpa_ielen > 0)) {
@@ -1042,7 +1045,7 @@ void rtw_get_bcn_info(struct wlan_network *pnetwork)
1042 __le16 le_tmp; 1045 __le16 le_tmp;
1043 u16 wpa_len = 0, rsn_len = 0; 1046 u16 wpa_len = 0, rsn_len = 0;
1044 struct HT_info_element *pht_info = NULL; 1047 struct HT_info_element *pht_info = NULL;
1045 unsigned int len; 1048 int len;
1046 unsigned char *p; 1049 unsigned char *p;
1047 1050
1048 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2); 1051 memcpy(&le_tmp, rtw_get_capability_from_ie(pnetwork->network.IEs), 2);
diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index 6ed23f4db38c..67508a6cf0e5 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -573,11 +573,6 @@ u16 rtw_get_cur_max_rate(struct adapter *adapter)
573 u8 bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0; 573 u8 bw_40MHz = 0, short_GI_20 = 0, short_GI_40 = 0;
574 u32 ht_ielen = 0; 574 u32 ht_ielen = 0;
575 575
576 if (adapter->registrypriv.mp_mode == 1) {
577 if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
578 return 0;
579 }
580
581 if ((!check_fwstate(pmlmepriv, _FW_LINKED)) && 576 if ((!check_fwstate(pmlmepriv, _FW_LINKED)) &&
582 (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE))) 577 (!check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
583 return 0; 578 return 0;
diff --git a/drivers/staging/rtl8188eu/core/rtw_led.c b/drivers/staging/rtl8188eu/core/rtw_led.c
index c1478cff5854..1b9bc9817a57 100644
--- a/drivers/staging/rtl8188eu/core/rtw_led.c
+++ b/drivers/staging/rtl8188eu/core/rtw_led.c
@@ -39,7 +39,9 @@ void BlinkTimerCallback(unsigned long data)
39/* */ 39/* */
40void BlinkWorkItemCallback(struct work_struct *work) 40void BlinkWorkItemCallback(struct work_struct *work)
41{ 41{
42 struct LED_871x *pLed = container_of(work, struct LED_871x, BlinkWorkItem); 42 struct LED_871x *pLed = container_of(work, struct LED_871x,
43 BlinkWorkItem);
44
43 BlinkHandler(pLed); 45 BlinkHandler(pLed);
44} 46}
45 47
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 032f783b0d83..a71928952eca 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -659,6 +659,7 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf)
659 } 659 }
660 } else { 660 } else {
661 int s_ret; 661 int s_ret;
662
662 set_fwstate(pmlmepriv, _FW_UNDER_LINKING); 663 set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
663 pmlmepriv->to_join = false; 664 pmlmepriv->to_join = false;
664 s_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv); 665 s_ret = rtw_select_and_join_from_scanned_queue(pmlmepriv);
@@ -1256,6 +1257,7 @@ void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf)
1256 1257
1257 if (mac_id >= 0) { 1258 if (mac_id >= 0) {
1258 u16 media_status; 1259 u16 media_status;
1260
1259 media_status = (mac_id<<8)|0; /* MACID|OPMODE:0 means disconnect */ 1261 media_status = (mac_id<<8)|0; /* MACID|OPMODE:0 means disconnect */
1260 /* for STA, AP, ADHOC mode, report disconnect stauts to FW */ 1262 /* for STA, AP, ADHOC mode, report disconnect stauts to FW */
1261 rtw_hal_set_hwreg(adapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status); 1263 rtw_hal_set_hwreg(adapter, HW_VAR_H2C_MEDIA_STATUS_RPT, (u8 *)&media_status);
@@ -1542,6 +1544,7 @@ int rtw_select_and_join_from_scanned_queue(struct mlme_priv *pmlmepriv)
1542 rtw_hal_get_def_var(adapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &(supp_ant_div)); 1544 rtw_hal_get_def_var(adapter, HAL_DEF_IS_SUPPORT_ANT_DIV, &(supp_ant_div));
1543 if (supp_ant_div) { 1545 if (supp_ant_div) {
1544 u8 cur_ant; 1546 u8 cur_ant;
1547
1545 rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &(cur_ant)); 1548 rtw_hal_get_def_var(adapter, HAL_DEF_CURRENT_ANTENNA, &(cur_ant));
1546 DBG_88E("#### Opt_Ant_(%s), cur_Ant(%s)\n", 1549 DBG_88E("#### Opt_Ant_(%s), cur_Ant(%s)\n",
1547 (2 == candidate->network.PhyInfo.Optimum_antenna) ? "A" : "B", 1550 (2 == candidate->network.PhyInfo.Optimum_antenna) ? "A" : "B",
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index d9c114776cab..f45af407f76d 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -147,6 +147,7 @@ static const struct rt_channel_plan_map RTW_CHANNEL_PLAN_MAP_REALTEK_DEFINE = {
147int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch) 147int rtw_ch_set_search_ch(struct rt_channel_info *ch_set, const u32 ch)
148{ 148{
149 int i; 149 int i;
150
150 for (i = 0; ch_set[i].ChannelNum != 0; i++) { 151 for (i = 0; ch_set[i].ChannelNum != 0; i++) {
151 if (ch == ch_set[i].ChannelNum) 152 if (ch == ch_set[i].ChannelNum)
152 break; 153 break;
@@ -274,9 +275,8 @@ static s32 dump_mgntframe_and_wait_ack(struct adapter *padapter,
274 pxmitpriv->ack_tx = true; 275 pxmitpriv->ack_tx = true;
275 276
276 pmgntframe->ack_report = 1; 277 pmgntframe->ack_report = 1;
277 if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS) { 278 if (rtw_hal_mgnt_xmit(padapter, pmgntframe) == _SUCCESS)
278 ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms); 279 ret = rtw_ack_tx_wait(pxmitpriv, timeout_ms);
279 }
280 280
281 pxmitpriv->ack_tx = false; 281 pxmitpriv->ack_tx = false;
282 mutex_unlock(&pxmitpriv->ack_tx_mutex); 282 mutex_unlock(&pxmitpriv->ack_tx_mutex);
@@ -371,6 +371,7 @@ static void issue_beacon(struct adapter *padapter, int timeout_ms)
371 u8 *wps_ie; 371 u8 *wps_ie;
372 uint wps_ielen; 372 uint wps_ielen;
373 u8 sr = 0; 373 u8 sr = 0;
374
374 memcpy(pframe, cur_network->IEs, cur_network->IELength); 375 memcpy(pframe, cur_network->IEs, cur_network->IELength);
375 len_diff = update_hidden_ssid( 376 len_diff = update_hidden_ssid(
376 pframe+_BEACON_IE_OFFSET_ 377 pframe+_BEACON_IE_OFFSET_
@@ -829,6 +830,7 @@ static void issue_auth(struct adapter *padapter, struct sta_info *psta,
829 } else { 830 } else {
830 __le32 le_tmp32; 831 __le32 le_tmp32;
831 __le16 le_tmp16; 832 __le16 le_tmp16;
833
832 ether_addr_copy(pwlanhdr->addr1, pnetwork->MacAddress); 834 ether_addr_copy(pwlanhdr->addr1, pnetwork->MacAddress);
833 ether_addr_copy(pwlanhdr->addr2, myid(&padapter->eeprompriv)); 835 ether_addr_copy(pwlanhdr->addr2, myid(&padapter->eeprompriv));
834 ether_addr_copy(pwlanhdr->addr3, pnetwork->MacAddress); 836 ether_addr_copy(pwlanhdr->addr3, pnetwork->MacAddress);
@@ -1963,6 +1965,7 @@ static void site_survey(struct adapter *padapter)
1963 1965
1964 if (ScanType == SCAN_ACTIVE) { /* obey the channel plan setting... */ 1966 if (ScanType == SCAN_ACTIVE) { /* obey the channel plan setting... */
1965 int i; 1967 int i;
1968
1966 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) { 1969 for (i = 0; i < RTW_SSID_SCAN_AMOUNT; i++) {
1967 if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) { 1970 if (pmlmeext->sitesurvey_res.ssid[i].SsidLength) {
1968 /* todo: to issue two probe req??? */ 1971 /* todo: to issue two probe req??? */
@@ -2050,8 +2053,8 @@ static u8 collect_bss_info(struct adapter *padapter,
2050 u32 len; 2053 u32 len;
2051 u8 *p; 2054 u8 *p;
2052 u16 val16, subtype; 2055 u16 val16, subtype;
2053 u8 *pframe = precv_frame->rx_data; 2056 u8 *pframe = precv_frame->pkt->data;
2054 u32 packet_len = precv_frame->len; 2057 u32 packet_len = precv_frame->pkt->len;
2055 u8 ie_offset; 2058 u8 ie_offset;
2056 struct registry_priv *pregistrypriv = &padapter->registrypriv; 2059 struct registry_priv *pregistrypriv = &padapter->registrypriv;
2057 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 2060 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -2155,6 +2158,7 @@ static u8 collect_bss_info(struct adapter *padapter,
2155 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset); 2158 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_ADD_INFO_IE_, &len, bssid->IELength - ie_offset);
2156 if (p) { 2159 if (p) {
2157 struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2); 2160 struct HT_info_element *HT_info = (struct HT_info_element *)(p + 2);
2161
2158 bssid->Configuration.DSConfig = HT_info->primary_channel; 2162 bssid->Configuration.DSConfig = HT_info->primary_channel;
2159 } else { /* use current channel */ 2163 } else { /* use current channel */
2160 bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter); 2164 bssid->Configuration.DSConfig = rtw_get_oper_ch(padapter);
@@ -2192,6 +2196,7 @@ static u8 collect_bss_info(struct adapter *padapter,
2192 /* 20/40 BSS Coexistence check */ 2196 /* 20/40 BSS Coexistence check */
2193 if ((pregistrypriv->wifi_spec == 1) && (!pmlmeinfo->bwmode_updated)) { 2197 if ((pregistrypriv->wifi_spec == 1) && (!pmlmeinfo->bwmode_updated)) {
2194 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 2198 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2199
2195 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset); 2200 p = rtw_get_ie(bssid->IEs + ie_offset, _HT_CAPABILITY_IE_, &len, bssid->IELength - ie_offset);
2196 if (p && len > 0) { 2201 if (p && len > 0) {
2197 struct ieee80211_ht_cap *pHT_caps = 2202 struct ieee80211_ht_cap *pHT_caps =
@@ -2218,6 +2223,7 @@ static void start_create_ibss(struct adapter *padapter)
2218 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 2223 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2219 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 2224 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2220 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network)); 2225 struct wlan_bssid_ex *pnetwork = (struct wlan_bssid_ex *)(&(pmlmeinfo->network));
2226
2221 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig; 2227 pmlmeext->cur_channel = (u8)pnetwork->Configuration.DSConfig;
2222 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork); 2228 pmlmeinfo->bcn_interval = get_beacon_interval(pnetwork);
2223 2229
@@ -2557,8 +2563,8 @@ static unsigned int OnProbeReq(struct adapter *padapter,
2557 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 2563 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2558 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 2564 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2559 struct wlan_bssid_ex *cur = &(pmlmeinfo->network); 2565 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
2560 u8 *pframe = precv_frame->rx_data; 2566 u8 *pframe = precv_frame->pkt->data;
2561 uint len = precv_frame->len; 2567 uint len = precv_frame->pkt->len;
2562 2568
2563 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) 2569 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
2564 return _SUCCESS; 2570 return _SUCCESS;
@@ -2605,8 +2611,8 @@ static unsigned int OnBeacon(struct adapter *padapter,
2605 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 2611 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2606 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 2612 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
2607 struct sta_priv *pstapriv = &padapter->stapriv; 2613 struct sta_priv *pstapriv = &padapter->stapriv;
2608 u8 *pframe = precv_frame->rx_data; 2614 u8 *pframe = precv_frame->pkt->data;
2609 uint len = precv_frame->len; 2615 uint len = precv_frame->pkt->len;
2610 struct wlan_bssid_ex *pbss; 2616 struct wlan_bssid_ex *pbss;
2611 int ret = _SUCCESS; 2617 int ret = _SUCCESS;
2612 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); 2618 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
@@ -2702,8 +2708,8 @@ static unsigned int OnAuth(struct adapter *padapter,
2702 struct security_priv *psecuritypriv = &padapter->securitypriv; 2708 struct security_priv *psecuritypriv = &padapter->securitypriv;
2703 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 2709 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2704 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 2710 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2705 u8 *pframe = precv_frame->rx_data; 2711 u8 *pframe = precv_frame->pkt->data;
2706 uint len = precv_frame->len; 2712 uint len = precv_frame->pkt->len;
2707 2713
2708 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE) 2714 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
2709 return _FAIL; 2715 return _FAIL;
@@ -2865,8 +2871,8 @@ static unsigned int OnAuthClient(struct adapter *padapter,
2865 unsigned int go2asoc = 0; 2871 unsigned int go2asoc = 0;
2866 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 2872 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
2867 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 2873 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2868 u8 *pframe = precv_frame->rx_data; 2874 u8 *pframe = precv_frame->pkt->data;
2869 uint pkt_len = precv_frame->len; 2875 uint pkt_len = precv_frame->pkt->len;
2870 2876
2871 DBG_88E("%s\n", __func__); 2877 DBG_88E("%s\n", __func__);
2872 2878
@@ -2953,8 +2959,8 @@ static unsigned int OnAssocReq(struct adapter *padapter,
2953 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 2959 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2954 struct wlan_bssid_ex *cur = &(pmlmeinfo->network); 2960 struct wlan_bssid_ex *cur = &(pmlmeinfo->network);
2955 struct sta_priv *pstapriv = &padapter->stapriv; 2961 struct sta_priv *pstapriv = &padapter->stapriv;
2956 u8 *pframe = precv_frame->rx_data; 2962 u8 *pframe = precv_frame->pkt->data;
2957 uint pkt_len = precv_frame->len; 2963 uint pkt_len = precv_frame->pkt->len;
2958 2964
2959 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE) 2965 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
2960 return _FAIL; 2966 return _FAIL;
@@ -3385,8 +3391,8 @@ static unsigned int OnAssocRsp(struct adapter *padapter,
3385 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 3391 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3386 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 3392 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3387 /* struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); */ 3393 /* struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network); */
3388 u8 *pframe = precv_frame->rx_data; 3394 u8 *pframe = precv_frame->pkt->data;
3389 uint pkt_len = precv_frame->len; 3395 uint pkt_len = precv_frame->pkt->len;
3390 3396
3391 DBG_88E("%s\n", __func__); 3397 DBG_88E("%s\n", __func__);
3392 3398
@@ -3453,11 +3459,10 @@ static unsigned int OnAssocRsp(struct adapter *padapter,
3453 UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates); 3459 UpdateBrateTbl(padapter, pmlmeinfo->network.SupportedRates);
3454 3460
3455report_assoc_result: 3461report_assoc_result:
3456 if (res > 0) { 3462 if (res > 0)
3457 rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len); 3463 rtw_buf_update(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len, pframe, pkt_len);
3458 } else { 3464 else
3459 rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len); 3465 rtw_buf_free(&pmlmepriv->assoc_rsp, &pmlmepriv->assoc_rsp_len);
3460 }
3461 3466
3462 report_join_res(padapter, res); 3467 report_join_res(padapter, res);
3463 3468
@@ -3471,7 +3476,7 @@ static unsigned int OnDeAuth(struct adapter *padapter,
3471 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 3476 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3472 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 3477 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3473 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 3478 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3474 u8 *pframe = precv_frame->rx_data; 3479 u8 *pframe = precv_frame->pkt->data;
3475 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); 3480 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
3476 3481
3477 /* check A3 */ 3482 /* check A3 */
@@ -3526,7 +3531,7 @@ static unsigned int OnDisassoc(struct adapter *padapter,
3526 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 3531 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
3527 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 3532 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3528 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 3533 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3529 u8 *pframe = precv_frame->rx_data; 3534 u8 *pframe = precv_frame->pkt->data;
3530 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network); 3535 struct wlan_bssid_ex *pnetwork = &(pmlmeinfo->network);
3531 3536
3532 /* check A3 */ 3537 /* check A3 */
@@ -3585,7 +3590,7 @@ static unsigned int on_action_spct(struct adapter *padapter,
3585{ 3590{
3586 struct sta_info *psta = NULL; 3591 struct sta_info *psta = NULL;
3587 struct sta_priv *pstapriv = &padapter->stapriv; 3592 struct sta_priv *pstapriv = &padapter->stapriv;
3588 u8 *pframe = precv_frame->rx_data; 3593 u8 *pframe = precv_frame->pkt->data;
3589 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); 3594 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr);
3590 u8 category; 3595 u8 category;
3591 u8 action; 3596 u8 action;
@@ -3641,7 +3646,7 @@ static unsigned int OnAction_back(struct adapter *padapter,
3641 unsigned short tid, status, reason_code = 0; 3646 unsigned short tid, status, reason_code = 0;
3642 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 3647 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
3643 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 3648 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
3644 u8 *pframe = precv_frame->rx_data; 3649 u8 *pframe = precv_frame->pkt->data;
3645 struct sta_priv *pstapriv = &padapter->stapriv; 3650 struct sta_priv *pstapriv = &padapter->stapriv;
3646 /* check RA matches or not */ 3651 /* check RA matches or not */
3647 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe), 3652 if (memcmp(myid(&(padapter->eeprompriv)), GetAddr1Ptr(pframe),
@@ -3714,7 +3719,7 @@ static s32 rtw_action_public_decache(struct recv_frame *recv_frame, s32 token)
3714{ 3719{
3715 struct adapter *adapter = recv_frame->adapter; 3720 struct adapter *adapter = recv_frame->adapter;
3716 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv); 3721 struct mlme_ext_priv *mlmeext = &(adapter->mlmeextpriv);
3717 u8 *frame = recv_frame->rx_data; 3722 u8 *frame = recv_frame->pkt->data;
3718 u16 seq_ctrl = ((recv_frame->attrib.seq_num&0xffff) << 4) | 3723 u16 seq_ctrl = ((recv_frame->attrib.seq_num&0xffff) << 4) |
3719 (recv_frame->attrib.frag_num & 0xf); 3724 (recv_frame->attrib.frag_num & 0xf);
3720 3725
@@ -3744,11 +3749,11 @@ static s32 rtw_action_public_decache(struct recv_frame *recv_frame, s32 token)
3744 3749
3745static unsigned int on_action_public_p2p(struct recv_frame *precv_frame) 3750static unsigned int on_action_public_p2p(struct recv_frame *precv_frame)
3746{ 3751{
3747 u8 *pframe = precv_frame->rx_data; 3752 u8 *pframe = precv_frame->pkt->data;
3748 u8 *frame_body; 3753 u8 *frame_body;
3749 u8 dialogToken = 0; 3754 u8 dialogToken = 0;
3750 frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr));
3751 3755
3756 frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr));
3752 dialogToken = frame_body[7]; 3757 dialogToken = frame_body[7];
3753 3758
3754 if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL) 3759 if (rtw_action_public_decache(precv_frame, dialogToken) == _FAIL)
@@ -3760,7 +3765,7 @@ static unsigned int on_action_public_p2p(struct recv_frame *precv_frame)
3760static unsigned int on_action_public_vendor(struct recv_frame *precv_frame) 3765static unsigned int on_action_public_vendor(struct recv_frame *precv_frame)
3761{ 3766{
3762 unsigned int ret = _FAIL; 3767 unsigned int ret = _FAIL;
3763 u8 *pframe = precv_frame->rx_data; 3768 u8 *pframe = precv_frame->pkt->data;
3764 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); 3769 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr);
3765 3770
3766 if (!memcmp(frame_body + 2, P2P_OUI, 4)) 3771 if (!memcmp(frame_body + 2, P2P_OUI, 4))
@@ -3772,7 +3777,7 @@ static unsigned int on_action_public_vendor(struct recv_frame *precv_frame)
3772static unsigned int on_action_public_default(struct recv_frame *precv_frame, u8 action) 3777static unsigned int on_action_public_default(struct recv_frame *precv_frame, u8 action)
3773{ 3778{
3774 unsigned int ret = _FAIL; 3779 unsigned int ret = _FAIL;
3775 u8 *pframe = precv_frame->rx_data; 3780 u8 *pframe = precv_frame->pkt->data;
3776 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); 3781 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr);
3777 u8 token; 3782 u8 token;
3778 3783
@@ -3791,7 +3796,7 @@ static unsigned int on_action_public(struct adapter *padapter,
3791 struct recv_frame *precv_frame) 3796 struct recv_frame *precv_frame)
3792{ 3797{
3793 unsigned int ret = _FAIL; 3798 unsigned int ret = _FAIL;
3794 u8 *pframe = precv_frame->rx_data; 3799 u8 *pframe = precv_frame->pkt->data;
3795 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr); 3800 u8 *frame_body = pframe + sizeof(struct ieee80211_hdr_3addr);
3796 u8 category, action; 3801 u8 category, action;
3797 3802
@@ -3862,7 +3867,7 @@ static unsigned int OnAction(struct adapter *padapter,
3862 unsigned char category; 3867 unsigned char category;
3863 struct action_handler *ptable; 3868 struct action_handler *ptable;
3864 unsigned char *frame_body; 3869 unsigned char *frame_body;
3865 u8 *pframe = precv_frame->rx_data; 3870 u8 *pframe = precv_frame->pkt->data;
3866 3871
3867 frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr)); 3872 frame_body = (unsigned char *)(pframe + sizeof(struct ieee80211_hdr_3addr));
3868 3873
@@ -4002,9 +4007,8 @@ static void init_channel_list(struct adapter *padapter, struct rt_channel_info *
4002 struct p2p_reg_class *reg = NULL; 4007 struct p2p_reg_class *reg = NULL;
4003 4008
4004 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) { 4009 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
4005 if (!has_channel(channel_set, chanset_size, ch)) { 4010 if (!has_channel(channel_set, chanset_size, ch))
4006 continue; 4011 continue;
4007 }
4008 4012
4009 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc)) 4013 if ((0 == padapter->registrypriv.ht_enable) && (8 == o->inc))
4010 continue; 4014 continue;
@@ -4119,7 +4123,7 @@ void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
4119static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptable, struct recv_frame *precv_frame) 4123static void _mgt_dispatcher(struct adapter *padapter, struct mlme_handler *ptable, struct recv_frame *precv_frame)
4120{ 4124{
4121 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 4125 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4122 u8 *pframe = precv_frame->rx_data; 4126 u8 *pframe = precv_frame->pkt->data;
4123 4127
4124 if (ptable->func) { 4128 if (ptable->func) {
4125 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */ 4129 /* receive the frames that ra(a1) is my address or ra(a1) is bc address. */
@@ -4138,7 +4142,7 @@ void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame)
4138 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 4142 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
4139#endif /* CONFIG_88EU_AP_MODE */ 4143#endif /* CONFIG_88EU_AP_MODE */
4140 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 4144 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4141 u8 *pframe = precv_frame->rx_data; 4145 u8 *pframe = precv_frame->pkt->data;
4142 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe)); 4146 struct sta_info *psta = rtw_get_stainfo(&padapter->stapriv, GetAddr2Ptr(pframe));
4143 4147
4144 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, 4148 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_,
@@ -4664,23 +4668,6 @@ void mlmeext_sta_del_event_callback(struct adapter *padapter)
4664Following are the functions for the timer handlers 4668Following are the functions for the timer handlers
4665 4669
4666*****************************************************************************/ 4670*****************************************************************************/
4667void _linked_rx_signal_strehgth_display(struct adapter *padapter);
4668void _linked_rx_signal_strehgth_display(struct adapter *padapter)
4669{
4670 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4671 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4672 u8 mac_id;
4673 int UndecoratedSmoothedPWDB;
4674 if ((pmlmeinfo->state&0x03) == WIFI_FW_STATION_STATE)
4675 mac_id = 0;
4676 else if ((pmlmeinfo->state&0x03) == _HW_STATE_AP_)
4677 mac_id = 2;
4678
4679 rtw_hal_get_def_var(padapter, HW_DEF_RA_INFO_DUMP, &mac_id);
4680
4681 rtw_hal_get_def_var(padapter, HAL_DEF_UNDERCORATEDSMOOTHEDPWDB, &UndecoratedSmoothedPWDB);
4682 DBG_88E("UndecoratedSmoothedPWDB:%d\n", UndecoratedSmoothedPWDB);
4683}
4684 4671
4685static u8 chk_ap_is_alive(struct adapter *padapter, struct sta_info *psta) 4672static u8 chk_ap_is_alive(struct adapter *padapter, struct sta_info *psta)
4686{ 4673{
@@ -4707,9 +4694,6 @@ void linked_status_chk(struct adapter *padapter)
4707 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 4694 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4708 struct sta_priv *pstapriv = &padapter->stapriv; 4695 struct sta_priv *pstapriv = &padapter->stapriv;
4709 4696
4710 if (padapter->bRxRSSIDisplay)
4711 _linked_rx_signal_strehgth_display(padapter);
4712
4713 if (is_client_associated_to_ap(padapter)) { 4697 if (is_client_associated_to_ap(padapter)) {
4714 /* linked infrastructure client mode */ 4698 /* linked infrastructure client mode */
4715 4699
@@ -4767,9 +4751,8 @@ void linked_status_chk(struct adapter *padapter)
4767 } 4751 }
4768 } 4752 }
4769 4753
4770 if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf) { 4754 if (tx_chk != _SUCCESS && pmlmeinfo->link_count++ == 0xf)
4771 tx_chk = issue_nulldata(padapter, NULL, 0, 1, 0); 4755 tx_chk = issue_nulldata(padapter, NULL, 0, 1, 0);
4772 }
4773 } 4756 }
4774 4757
4775 if (rx_chk == _FAIL) { 4758 if (rx_chk == _FAIL) {
diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index 4032121a06f3..f86c9cebf09a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -180,9 +180,9 @@ int ips_leave(struct adapter *padapter)
180 DBG_88E("==>ips_leave cnts:%d\n", pwrpriv->ips_leave_cnts); 180 DBG_88E("==>ips_leave cnts:%d\n", pwrpriv->ips_leave_cnts);
181 181
182 result = rtw_ips_pwr_up(padapter); 182 result = rtw_ips_pwr_up(padapter);
183 if (result == _SUCCESS) { 183 if (result == _SUCCESS)
184 pwrpriv->rf_pwrstate = rf_on; 184 pwrpriv->rf_pwrstate = rf_on;
185 } 185
186 DBG_88E_LEVEL(_drv_info_, "nolinked power save leave\n"); 186 DBG_88E_LEVEL(_drv_info_, "nolinked power save leave\n");
187 187
188 if ((_WEP40_ == psecuritypriv->dot11PrivacyAlgrthm) || (_WEP104_ == psecuritypriv->dot11PrivacyAlgrthm)) { 188 if ((_WEP40_ == psecuritypriv->dot11PrivacyAlgrthm) || (_WEP104_ == psecuritypriv->dot11PrivacyAlgrthm)) {
@@ -279,6 +279,7 @@ exit:
279static void pwr_state_check_handler(unsigned long data) 279static void pwr_state_check_handler(unsigned long data)
280{ 280{
281 struct adapter *padapter = (struct adapter *)data; 281 struct adapter *padapter = (struct adapter *)data;
282
282 rtw_ps_cmd(padapter); 283 rtw_ps_cmd(padapter);
283} 284}
284 285
diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
index 3e6edb63d36b..53dc33c3f913 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -80,7 +80,6 @@ int _rtw_init_recv_priv(struct recv_priv *precvpriv, struct adapter *padapter)
80 &(precvpriv->free_recv_queue.queue)); 80 &(precvpriv->free_recv_queue.queue));
81 81
82 precvframe->pkt = NULL; 82 precvframe->pkt = NULL;
83 precvframe->len = 0;
84 83
85 precvframe->adapter = padapter; 84 precvframe->adapter = padapter;
86 precvframe++; 85 precvframe++;
@@ -149,8 +148,6 @@ int rtw_free_recvframe(struct recv_frame *precvframe,
149 148
150 list_del_init(&(precvframe->list)); 149 list_del_init(&(precvframe->list));
151 150
152 precvframe->len = 0;
153
154 list_add_tail(&(precvframe->list), get_list_head(pfree_recv_queue)); 151 list_add_tail(&(precvframe->list), get_list_head(pfree_recv_queue));
155 152
156 spin_unlock_bh(&pfree_recv_queue->lock); 153 spin_unlock_bh(&pfree_recv_queue->lock);
@@ -211,6 +208,7 @@ u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter)
211{ 208{
212 u32 cnt = 0; 209 u32 cnt = 0;
213 struct recv_frame *pending_frame; 210 struct recv_frame *pending_frame;
211
214 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) { 212 while ((pending_frame = rtw_alloc_recvframe(&adapter->recvpriv.uc_swdec_pending_queue))) {
215 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue); 213 rtw_free_recvframe(pending_frame, &adapter->recvpriv.free_recv_queue);
216 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__); 214 DBG_88E("%s: dequeue uc_swdec_pending_queue\n", __func__);
@@ -261,9 +259,9 @@ static int recvframe_chkmic(struct adapter *adapter,
261 } 259 }
262 260
263 /* icv_len included the mic code */ 261 /* icv_len included the mic code */
264 datalen = precvframe->len-prxattrib->hdrlen - 262 datalen = precvframe->pkt->len-prxattrib->hdrlen -
265 prxattrib->iv_len-prxattrib->icv_len-8; 263 prxattrib->iv_len-prxattrib->icv_len-8;
266 pframe = precvframe->rx_data; 264 pframe = precvframe->pkt->data;
267 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len; 265 payload = pframe+prxattrib->hdrlen+prxattrib->iv_len;
268 266
269 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len)); 267 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("\n prxattrib->iv_len=%d prxattrib->icv_len=%d\n", prxattrib->iv_len, prxattrib->icv_len));
@@ -296,26 +294,27 @@ static int recvframe_chkmic(struct adapter *adapter,
296 *(pframemic-10), *(pframemic-9))); 294 *(pframemic-10), *(pframemic-9)));
297 { 295 {
298 uint i; 296 uint i;
297
299 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, 298 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
300 ("\n ======demp packet (len=%d)======\n", 299 ("\n ======demp packet (len=%d)======\n",
301 precvframe->len)); 300 precvframe->pkt->len));
302 for (i = 0; i < precvframe->len; i += 8) { 301 for (i = 0; i < precvframe->pkt->len; i += 8) {
303 RT_TRACE(_module_rtl871x_recv_c_, 302 RT_TRACE(_module_rtl871x_recv_c_,
304 _drv_err_, 303 _drv_err_,
305 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x", 304 ("0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x",
306 *(precvframe->rx_data+i), 305 *(precvframe->pkt->data+i),
307 *(precvframe->rx_data+i+1), 306 *(precvframe->pkt->data+i+1),
308 *(precvframe->rx_data+i+2), 307 *(precvframe->pkt->data+i+2),
309 *(precvframe->rx_data+i+3), 308 *(precvframe->pkt->data+i+3),
310 *(precvframe->rx_data+i+4), 309 *(precvframe->pkt->data+i+4),
311 *(precvframe->rx_data+i+5), 310 *(precvframe->pkt->data+i+5),
312 *(precvframe->rx_data+i+6), 311 *(precvframe->pkt->data+i+6),
313 *(precvframe->rx_data+i+7))); 312 *(precvframe->pkt->data+i+7)));
314 } 313 }
315 RT_TRACE(_module_rtl871x_recv_c_, 314 RT_TRACE(_module_rtl871x_recv_c_,
316 _drv_err_, 315 _drv_err_,
317 ("\n ====== demp packet end [len=%d]======\n", 316 ("\n ====== demp packet end [len=%d]======\n",
318 precvframe->len)); 317 precvframe->pkt->len));
319 RT_TRACE(_module_rtl871x_recv_c_, 318 RT_TRACE(_module_rtl871x_recv_c_,
320 _drv_err_, 319 _drv_err_,
321 ("\n hrdlen=%d,\n", 320 ("\n hrdlen=%d,\n",
@@ -352,7 +351,7 @@ static int recvframe_chkmic(struct adapter *adapter,
352 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n")); 351 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("recvframe_chkmic: rtw_get_stainfo==NULL!!!\n"));
353 } 352 }
354 353
355 recvframe_pull_tail(precvframe, 8); 354 skb_trim(precvframe->pkt, precvframe->pkt->len - 8);
356 } 355 }
357 356
358exit: 357exit:
@@ -372,7 +371,8 @@ static struct recv_frame *decryptor(struct adapter *padapter,
372 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt)); 371 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, ("prxstat->decrypted=%x prxattrib->encrypt=0x%03x\n", prxattrib->bdecrypted, prxattrib->encrypt));
373 372
374 if (prxattrib->encrypt > 0) { 373 if (prxattrib->encrypt > 0) {
375 u8 *iv = precv_frame->rx_data+prxattrib->hdrlen; 374 u8 *iv = precv_frame->pkt->data+prxattrib->hdrlen;
375
376 prxattrib->key_index = (((iv[3])>>6)&0x3); 376 prxattrib->key_index = (((iv[3])>>6)&0x3);
377 377
378 if (prxattrib->key_index > WEP_KEYS) { 378 if (prxattrib->key_index > WEP_KEYS) {
@@ -440,7 +440,7 @@ static struct recv_frame *portctrl(struct adapter *adapter,
440 440
441 auth_alg = adapter->securitypriv.dot11AuthAlgrthm; 441 auth_alg = adapter->securitypriv.dot11AuthAlgrthm;
442 442
443 ptr = precv_frame->rx_data; 443 ptr = precv_frame->pkt->data;
444 pfhdr = precv_frame; 444 pfhdr = precv_frame;
445 pattrib = &pfhdr->attrib; 445 pattrib = &pfhdr->attrib;
446 psta_addr = pattrib->ta; 446 psta_addr = pattrib->ta;
@@ -529,7 +529,7 @@ static void process_pwrbit_data(struct adapter *padapter,
529{ 529{
530#ifdef CONFIG_88EU_AP_MODE 530#ifdef CONFIG_88EU_AP_MODE
531 unsigned char pwrbit; 531 unsigned char pwrbit;
532 u8 *ptr = precv_frame->rx_data; 532 u8 *ptr = precv_frame->pkt->data;
533 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 533 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
534 struct sta_priv *pstapriv = &padapter->stapriv; 534 struct sta_priv *pstapriv = &padapter->stapriv;
535 struct sta_info *psta = NULL; 535 struct sta_info *psta = NULL;
@@ -617,7 +617,7 @@ static void count_rx_stats(struct adapter *padapter,
617 struct rx_pkt_attrib *pattrib = &prframe->attrib; 617 struct rx_pkt_attrib *pattrib = &prframe->attrib;
618 struct recv_priv *precvpriv = &padapter->recvpriv; 618 struct recv_priv *precvpriv = &padapter->recvpriv;
619 619
620 sz = prframe->len; 620 sz = prframe->pkt->len;
621 precvpriv->rx_bytes += sz; 621 precvpriv->rx_bytes += sz;
622 622
623 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++; 623 padapter->mlmepriv.LinkDetectInfo.NumRxOkInPeriod++;
@@ -647,7 +647,6 @@ int sta2sta_data_frame(
647int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame, 647int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
648 struct sta_info **psta) 648 struct sta_info **psta)
649{ 649{
650 u8 *ptr = precv_frame->rx_data;
651 int ret = _SUCCESS; 650 int ret = _SUCCESS;
652 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 651 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
653 struct sta_priv *pstapriv = &adapter->stapriv; 652 struct sta_priv *pstapriv = &adapter->stapriv;
@@ -703,14 +702,6 @@ int sta2sta_data_frame(struct adapter *adapter, struct recv_frame *precv_frame,
703 702
704 sta_addr = pattrib->src; 703 sta_addr = pattrib->src;
705 } 704 }
706 } else if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
707 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
708 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
709 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
710 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
711 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
712
713 sta_addr = mybssid;
714 } else { 705 } else {
715 ret = _FAIL; 706 ret = _FAIL;
716 } 707 }
@@ -735,7 +726,7 @@ static int ap2sta_data_frame(
735 struct recv_frame *precv_frame, 726 struct recv_frame *precv_frame,
736 struct sta_info **psta) 727 struct sta_info **psta)
737{ 728{
738 u8 *ptr = precv_frame->rx_data; 729 u8 *ptr = precv_frame->pkt->data;
739 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 730 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
740 int ret = _SUCCESS; 731 int ret = _SUCCESS;
741 struct sta_priv *pstapriv = &adapter->stapriv; 732 struct sta_priv *pstapriv = &adapter->stapriv;
@@ -799,23 +790,6 @@ static int ap2sta_data_frame(
799 ret = RTW_RX_HANDLED; 790 ret = RTW_RX_HANDLED;
800 goto exit; 791 goto exit;
801 } 792 }
802 } else if ((check_fwstate(pmlmepriv, WIFI_MP_STATE) == true) &&
803 (check_fwstate(pmlmepriv, _FW_LINKED) == true)) {
804 memcpy(pattrib->dst, GetAddr1Ptr(ptr), ETH_ALEN);
805 memcpy(pattrib->src, GetAddr2Ptr(ptr), ETH_ALEN);
806 memcpy(pattrib->bssid, GetAddr3Ptr(ptr), ETH_ALEN);
807 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
808 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
809
810 /* */
811 memcpy(pattrib->bssid, mybssid, ETH_ALEN);
812
813 *psta = rtw_get_stainfo(pstapriv, pattrib->bssid); /* get sta_info */
814 if (*psta == NULL) {
815 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("can't get psta under MP_MODE ; drop pkt\n"));
816 ret = _FAIL;
817 goto exit;
818 }
819 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { 793 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
820 /* Special case */ 794 /* Special case */
821 ret = RTW_RX_HANDLED; 795 ret = RTW_RX_HANDLED;
@@ -845,7 +819,7 @@ static int sta2ap_data_frame(struct adapter *adapter,
845 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 819 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
846 struct sta_priv *pstapriv = &adapter->stapriv; 820 struct sta_priv *pstapriv = &adapter->stapriv;
847 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 821 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
848 u8 *ptr = precv_frame->rx_data; 822 u8 *ptr = precv_frame->pkt->data;
849 unsigned char *mybssid = get_bssid(pmlmepriv); 823 unsigned char *mybssid = get_bssid(pmlmepriv);
850 int ret = _SUCCESS; 824 int ret = _SUCCESS;
851 825
@@ -880,6 +854,7 @@ static int sta2ap_data_frame(struct adapter *adapter,
880 } 854 }
881 } else { 855 } else {
882 u8 *myhwaddr = myid(&adapter->eeprompriv); 856 u8 *myhwaddr = myid(&adapter->eeprompriv);
857
883 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) { 858 if (memcmp(pattrib->ra, myhwaddr, ETH_ALEN)) {
884 ret = RTW_RX_HANDLED; 859 ret = RTW_RX_HANDLED;
885 goto exit; 860 goto exit;
@@ -901,7 +876,7 @@ static int validate_recv_ctrl_frame(struct adapter *padapter,
901#ifdef CONFIG_88EU_AP_MODE 876#ifdef CONFIG_88EU_AP_MODE
902 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 877 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
903 struct sta_priv *pstapriv = &padapter->stapriv; 878 struct sta_priv *pstapriv = &padapter->stapriv;
904 u8 *pframe = precv_frame->rx_data; 879 u8 *pframe = precv_frame->pkt->data;
905 880
906 if (GetFrameType(pframe) != WIFI_CTRL_TYPE) 881 if (GetFrameType(pframe) != WIFI_CTRL_TYPE)
907 return _FAIL; 882 return _FAIL;
@@ -1038,19 +1013,19 @@ static int validate_recv_mgnt_frame(struct adapter *padapter,
1038 1013
1039 /* for rx pkt statistics */ 1014 /* for rx pkt statistics */
1040 psta = rtw_get_stainfo(&padapter->stapriv, 1015 psta = rtw_get_stainfo(&padapter->stapriv,
1041 GetAddr2Ptr(precv_frame->rx_data)); 1016 GetAddr2Ptr(precv_frame->pkt->data));
1042 if (psta) { 1017 if (psta) {
1043 psta->sta_stats.rx_mgnt_pkts++; 1018 psta->sta_stats.rx_mgnt_pkts++;
1044 if (GetFrameSubType(precv_frame->rx_data) == WIFI_BEACON) { 1019 if (GetFrameSubType(precv_frame->pkt->data) == WIFI_BEACON) {
1045 psta->sta_stats.rx_beacon_pkts++; 1020 psta->sta_stats.rx_beacon_pkts++;
1046 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBEREQ) { 1021 } else if (GetFrameSubType(precv_frame->pkt->data) == WIFI_PROBEREQ) {
1047 psta->sta_stats.rx_probereq_pkts++; 1022 psta->sta_stats.rx_probereq_pkts++;
1048 } else if (GetFrameSubType(precv_frame->rx_data) == WIFI_PROBERSP) { 1023 } else if (GetFrameSubType(precv_frame->pkt->data) == WIFI_PROBERSP) {
1049 if (!memcmp(padapter->eeprompriv.mac_addr, 1024 if (!memcmp(padapter->eeprompriv.mac_addr,
1050 GetAddr1Ptr(precv_frame->rx_data), ETH_ALEN)) 1025 GetAddr1Ptr(precv_frame->pkt->data), ETH_ALEN))
1051 psta->sta_stats.rx_probersp_pkts++; 1026 psta->sta_stats.rx_probersp_pkts++;
1052 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->rx_data)) || 1027 else if (is_broadcast_mac_addr(GetAddr1Ptr(precv_frame->pkt->data)) ||
1053 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->rx_data))) 1028 is_multicast_mac_addr(GetAddr1Ptr(precv_frame->pkt->data)))
1054 psta->sta_stats.rx_probersp_bm_pkts++; 1029 psta->sta_stats.rx_probersp_bm_pkts++;
1055 else 1030 else
1056 psta->sta_stats.rx_probersp_uo_pkts++; 1031 psta->sta_stats.rx_probersp_uo_pkts++;
@@ -1068,7 +1043,7 @@ static int validate_recv_data_frame(struct adapter *adapter,
1068 u8 bretry; 1043 u8 bretry;
1069 u8 *psa, *pda, *pbssid; 1044 u8 *psa, *pda, *pbssid;
1070 struct sta_info *psta = NULL; 1045 struct sta_info *psta = NULL;
1071 u8 *ptr = precv_frame->rx_data; 1046 u8 *ptr = precv_frame->pkt->data;
1072 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 1047 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1073 struct security_priv *psecuritypriv = &adapter->securitypriv; 1048 struct security_priv *psecuritypriv = &adapter->securitypriv;
1074 int ret = _SUCCESS; 1049 int ret = _SUCCESS;
@@ -1115,11 +1090,10 @@ static int validate_recv_data_frame(struct adapter *adapter,
1115 break; 1090 break;
1116 } 1091 }
1117 1092
1118 if (ret == _FAIL) { 1093 if (ret == _FAIL)
1119 goto exit; 1094 goto exit;
1120 } else if (ret == RTW_RX_HANDLED) { 1095 else if (ret == RTW_RX_HANDLED)
1121 goto exit; 1096 goto exit;
1122 }
1123 1097
1124 if (psta == NULL) { 1098 if (psta == NULL) {
1125 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n")); 1099 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, (" after to_fr_ds_chk; psta==NULL\n"));
@@ -1191,12 +1165,13 @@ static int validate_recv_frame(struct adapter *adapter,
1191 int retval = _SUCCESS; 1165 int retval = _SUCCESS;
1192 u8 bDumpRxPkt; 1166 u8 bDumpRxPkt;
1193 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 1167 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1194 u8 *ptr = precv_frame->rx_data; 1168 u8 *ptr = precv_frame->pkt->data;
1195 u8 ver = (unsigned char)(*ptr)&0x3; 1169 u8 ver = (unsigned char)(*ptr)&0x3;
1196 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; 1170 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1197 1171
1198 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) { 1172 if (pmlmeext->sitesurvey_res.state == SCAN_PROCESS) {
1199 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter)); 1173 int ch_set_idx = rtw_ch_set_search_ch(pmlmeext->channel_set, rtw_get_oper_ch(adapter));
1174
1200 if (ch_set_idx >= 0) 1175 if (ch_set_idx >= 0)
1201 pmlmeext->channel_set[ch_set_idx].rx_count++; 1176 pmlmeext->channel_set[ch_set_idx].rx_count++;
1202 } 1177 }
@@ -1265,6 +1240,7 @@ static int validate_recv_frame(struct adapter *adapter,
1265 retval = validate_recv_data_frame(adapter, precv_frame); 1240 retval = validate_recv_data_frame(adapter, precv_frame);
1266 if (retval == _FAIL) { 1241 if (retval == _FAIL) {
1267 struct recv_priv *precvpriv = &adapter->recvpriv; 1242 struct recv_priv *precvpriv = &adapter->recvpriv;
1243
1268 precvpriv->rx_drop++; 1244 precvpriv->rx_drop++;
1269 } 1245 }
1270 break; 1246 break;
@@ -1303,13 +1279,11 @@ static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1303 u8 *psnap_type; 1279 u8 *psnap_type;
1304 struct ieee80211_snap_hdr *psnap; 1280 struct ieee80211_snap_hdr *psnap;
1305 1281
1306 struct adapter *adapter = precvframe->adapter; 1282 u8 *ptr = precvframe->pkt->data;
1307 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1308 u8 *ptr = precvframe->rx_data;
1309 struct rx_pkt_attrib *pattrib = &precvframe->attrib; 1283 struct rx_pkt_attrib *pattrib = &precvframe->attrib;
1310 1284
1311 if (pattrib->encrypt) 1285 if (pattrib->encrypt)
1312 recvframe_pull_tail(precvframe, pattrib->icv_len); 1286 skb_trim(precvframe->pkt, precvframe->pkt->len - pattrib->icv_len);
1313 1287
1314 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len); 1288 psnap = (struct ieee80211_snap_hdr *)(ptr+pattrib->hdrlen + pattrib->iv_len);
1315 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE; 1289 psnap_type = ptr+pattrib->hdrlen + pattrib->iv_len+SNAP_SIZE;
@@ -1326,7 +1300,7 @@ static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1326 } 1300 }
1327 1301
1328 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0); 1302 rmv_len = pattrib->hdrlen + pattrib->iv_len + (bsnaphdr ? SNAP_SIZE : 0);
1329 len = precvframe->len - rmv_len; 1303 len = precvframe->pkt->len - rmv_len;
1330 1304
1331 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, 1305 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1332 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len)); 1306 ("\n===pattrib->hdrlen: %x, pattrib->iv_len:%x===\n\n", pattrib->hdrlen, pattrib->iv_len));
@@ -1335,19 +1309,9 @@ static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1335 eth_type = ntohs(be_tmp); /* pattrib->ether_type */ 1309 eth_type = ntohs(be_tmp); /* pattrib->ether_type */
1336 pattrib->eth_type = eth_type; 1310 pattrib->eth_type = eth_type;
1337 1311
1338 if ((check_fwstate(pmlmepriv, WIFI_MP_STATE))) { 1312 ptr = skb_pull(precvframe->pkt, rmv_len - sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0));
1339 ptr += rmv_len; 1313 if (!ptr)
1340 *ptr = 0x87; 1314 return _FAIL;
1341 *(ptr+1) = 0x12;
1342
1343 eth_type = 0x8712;
1344 /* append rx status for mp test packets */
1345 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr)+2)-24);
1346 memcpy(ptr, get_rxmem(precvframe), 24);
1347 ptr += 24;
1348 } else {
1349 ptr = recvframe_pull(precvframe, (rmv_len-sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
1350 }
1351 1315
1352 memcpy(ptr, pattrib->dst, ETH_ALEN); 1316 memcpy(ptr, pattrib->dst, ETH_ALEN);
1353 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN); 1317 memcpy(ptr+ETH_ALEN, pattrib->src, ETH_ALEN);
@@ -1416,15 +1380,16 @@ static struct recv_frame *recvframe_defrag(struct adapter *adapter,
1416 1380
1417 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len; 1381 wlanhdr_offset = pnfhdr->attrib.hdrlen + pnfhdr->attrib.iv_len;
1418 1382
1419 recvframe_pull(pnextrframe, wlanhdr_offset); 1383 skb_pull(pnextrframe->pkt, wlanhdr_offset);
1420 1384
1421 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */ 1385 /* append to first fragment frame's tail (if privacy frame, pull the ICV) */
1422 recvframe_pull_tail(prframe, pfhdr->attrib.icv_len); 1386 skb_trim(prframe->pkt, prframe->pkt->len - pfhdr->attrib.icv_len);
1423 1387
1424 /* memcpy */ 1388 /* memcpy */
1425 memcpy(pfhdr->rx_tail, pnfhdr->rx_data, pnfhdr->len); 1389 memcpy(skb_tail_pointer(pfhdr->pkt), pnfhdr->pkt->data,
1390 pnfhdr->pkt->len);
1426 1391
1427 recvframe_put(prframe, pnfhdr->len); 1392 skb_put(prframe->pkt, pnfhdr->pkt->len);
1428 1393
1429 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len; 1394 pfhdr->attrib.icv_len = pnfhdr->attrib.icv_len;
1430 plist = plist->next; 1395 plist = plist->next;
@@ -1465,7 +1430,8 @@ struct recv_frame *recvframe_chk_defrag(struct adapter *padapter,
1465 psta_addr = pfhdr->attrib.ta; 1430 psta_addr = pfhdr->attrib.ta;
1466 psta = rtw_get_stainfo(pstapriv, psta_addr); 1431 psta = rtw_get_stainfo(pstapriv, psta_addr);
1467 if (psta == NULL) { 1432 if (psta == NULL) {
1468 u8 type = GetFrameType(pfhdr->rx_data); 1433 u8 type = GetFrameType(pfhdr->pkt->data);
1434
1469 if (type != WIFI_DATA_TYPE) { 1435 if (type != WIFI_DATA_TYPE) {
1470 psta = rtw_get_bcmc_stainfo(padapter); 1436 psta = rtw_get_bcmc_stainfo(padapter);
1471 pdefrag_q = &psta->sta_recvpriv.defrag_q; 1437 pdefrag_q = &psta->sta_recvpriv.defrag_q;
@@ -1548,18 +1514,18 @@ static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1548 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT]; 1514 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1549 struct recv_priv *precvpriv = &padapter->recvpriv; 1515 struct recv_priv *precvpriv = &padapter->recvpriv;
1550 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue); 1516 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1551 nr_subframes = 0;
1552 1517
1518 nr_subframes = 0;
1553 pattrib = &prframe->attrib; 1519 pattrib = &prframe->attrib;
1554 1520
1555 recvframe_pull(prframe, prframe->attrib.hdrlen); 1521 skb_pull(prframe->pkt, prframe->attrib.hdrlen);
1556 1522
1557 if (prframe->attrib.iv_len > 0) 1523 if (prframe->attrib.iv_len > 0)
1558 recvframe_pull(prframe, prframe->attrib.iv_len); 1524 skb_pull(prframe->pkt, prframe->attrib.iv_len);
1559 1525
1560 a_len = prframe->len; 1526 a_len = prframe->pkt->len;
1561 1527
1562 pdata = prframe->rx_data; 1528 pdata = prframe->pkt->data;
1563 1529
1564 while (a_len > ETH_HLEN) { 1530 while (a_len > ETH_HLEN) {
1565 /* Offset 12 denote 2 mac address */ 1531 /* Offset 12 denote 2 mac address */
@@ -1606,9 +1572,9 @@ static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1606 if (padding_len == 4) 1572 if (padding_len == 4)
1607 padding_len = 0; 1573 padding_len = 0;
1608 1574
1609 if (a_len < padding_len) { 1575 if (a_len < padding_len)
1610 goto exit; 1576 goto exit;
1611 } 1577
1612 pdata += padding_len; 1578 pdata += padding_len;
1613 a_len -= padding_len; 1579 a_len -= padding_len;
1614 } 1580 }
@@ -1646,8 +1612,6 @@ static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1646 } 1612 }
1647 1613
1648exit: 1614exit:
1649
1650 prframe->len = 0;
1651 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */ 1615 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1652 1616
1653 return _SUCCESS; 1617 return _SUCCESS;
@@ -2064,45 +2028,48 @@ static void rtw_signal_stat_timer_hdl(unsigned long data)
2064 u8 avg_signal_qual = 0; 2028 u8 avg_signal_qual = 0;
2065 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */ 2029 u8 _alpha = 3; /* this value is based on converging_constant = 5000 and sampling_interval = 1000 */
2066 2030
2067 if (adapter->recvpriv.is_signal_dbg) { 2031 if (recvpriv->signal_strength_data.update_req == 0) {
2068 /* update the user specific value, signal_strength_dbg, to signal_strength, rssi */ 2032 /* update_req is clear, means we got rx */
2069 adapter->recvpriv.signal_strength = adapter->recvpriv.signal_strength_dbg; 2033 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2070 adapter->recvpriv.rssi = (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg); 2034 /* after avg_vals are acquired, we can re-stat the signal
2071 } else { 2035 * values
2072 if (recvpriv->signal_strength_data.update_req == 0) {/* update_req is clear, means we got rx */ 2036 */
2073 avg_signal_strength = recvpriv->signal_strength_data.avg_val; 2037 recvpriv->signal_strength_data.update_req = 1;
2074 /* after avg_vals are acquired, we can re-stat the signal values */ 2038 }
2075 recvpriv->signal_strength_data.update_req = 1;
2076 }
2077
2078 if (recvpriv->signal_qual_data.update_req == 0) {/* update_req is clear, means we got rx */
2079 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2080 /* after avg_vals are acquired, we can re-stat the signal values */
2081 recvpriv->signal_qual_data.update_req = 1;
2082 }
2083 2039
2084 /* update value of signal_strength, rssi, signal_qual */ 2040 if (recvpriv->signal_qual_data.update_req == 0) {
2085 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) { 2041 /* update_req is clear, means we got rx */
2086 tmp_s = avg_signal_strength+(_alpha-1)*recvpriv->signal_strength; 2042 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2087 if (tmp_s % _alpha) 2043 /* after avg_vals are acquired, we can re-stat the signal
2088 tmp_s = tmp_s/_alpha + 1; 2044 * values
2089 else 2045 */
2090 tmp_s = tmp_s/_alpha; 2046 recvpriv->signal_qual_data.update_req = 1;
2091 if (tmp_s > 100) 2047 }
2092 tmp_s = 100;
2093 2048
2094 tmp_q = avg_signal_qual+(_alpha-1)*recvpriv->signal_qual; 2049 /* update value of signal_strength, rssi, signal_qual */
2095 if (tmp_q % _alpha) 2050 if (check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY) == false) {
2096 tmp_q = tmp_q/_alpha + 1; 2051 tmp_s = avg_signal_strength +
2097 else 2052 (_alpha - 1) * recvpriv->signal_strength;
2098 tmp_q = tmp_q/_alpha; 2053 if (tmp_s % _alpha)
2099 if (tmp_q > 100) 2054 tmp_s = tmp_s / _alpha + 1;
2100 tmp_q = 100; 2055 else
2056 tmp_s = tmp_s / _alpha;
2057 if (tmp_s > 100)
2058 tmp_s = 100;
2059
2060 tmp_q = avg_signal_qual +
2061 (_alpha - 1) * recvpriv->signal_qual;
2062 if (tmp_q % _alpha)
2063 tmp_q = tmp_q / _alpha + 1;
2064 else
2065 tmp_q = tmp_q / _alpha;
2066 if (tmp_q > 100)
2067 tmp_q = 100;
2101 2068
2102 recvpriv->signal_strength = tmp_s; 2069 recvpriv->signal_strength = tmp_s;
2103 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s); 2070 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2104 recvpriv->signal_qual = tmp_q; 2071 recvpriv->signal_qual = tmp_q;
2105 }
2106 } 2072 }
2073
2107 rtw_set_signal_stat_timer(recvpriv); 2074 rtw_set_signal_stat_timer(recvpriv);
2108} 2075}
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c
index 85bb441a7214..b283a4903369 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -36,6 +36,7 @@ static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
36 u32 stateindex; 36 u32 stateindex;
37 u8 *state; 37 u8 *state;
38 u32 counter; 38 u32 counter;
39
39 state = parc4ctx->state; 40 state = parc4ctx->state;
40 parc4ctx->x = 0; 41 parc4ctx->x = 0;
41 parc4ctx->y = 0; 42 parc4ctx->y = 0;
@@ -60,6 +61,7 @@ static u32 arcfour_byte(struct arc4context *parc4ctx)
60 u32 y; 61 u32 y;
61 u32 sx, sy; 62 u32 sx, sy;
62 u8 *state; 63 u8 *state;
64
63 state = parc4ctx->state; 65 state = parc4ctx->state;
64 x = (parc4ctx->x + 1) & 0xff; 66 x = (parc4ctx->x + 1) & 0xff;
65 sx = state[x]; 67 sx = state[x];
@@ -75,6 +77,7 @@ static u32 arcfour_byte(struct arc4context *parc4ctx)
75static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, u32 len) 77static void arcfour_encrypt(struct arc4context *parc4ctx, u8 *dest, u8 *src, u32 len)
76{ 78{
77 u32 i; 79 u32 i;
80
78 for (i = 0; i < len; i++) 81 for (i = 0; i < len; i++)
79 dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx); 82 dest[i] = src[i] ^ (unsigned char)arcfour_byte(parc4ctx);
80} 83}
@@ -120,6 +123,7 @@ static __le32 getcrc32(u8 *buf, int len)
120{ 123{
121 u8 *p; 124 u8 *p;
122 u32 crc; 125 u32 crc;
126
123 if (bcrc32initialized == 0) 127 if (bcrc32initialized == 0)
124 crc32_init(); 128 crc32_init();
125 129
@@ -204,7 +208,7 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
204 struct security_priv *psecuritypriv = &padapter->securitypriv; 208 struct security_priv *psecuritypriv = &padapter->securitypriv;
205 209
206 210
207 pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data; 211 pframe = (unsigned char *)((struct recv_frame *)precvframe)->pkt->data;
208 212
209 /* start to decrypt recvframe */ 213 /* start to decrypt recvframe */
210 if ((prxattrib->encrypt == _WEP40_) || (prxattrib->encrypt == _WEP104_)) { 214 if ((prxattrib->encrypt == _WEP40_) || (prxattrib->encrypt == _WEP104_)) {
@@ -213,7 +217,7 @@ void rtw_wep_decrypt(struct adapter *padapter, u8 *precvframe)
213 keylength = psecuritypriv->dot11DefKeylen[keyindex]; 217 keylength = psecuritypriv->dot11DefKeylen[keyindex];
214 memcpy(&wepkey[0], iv, 3); 218 memcpy(&wepkey[0], iv, 3);
215 memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0], keylength); 219 memcpy(&wepkey[3], &psecuritypriv->dot11DefKey[keyindex].skey[0], keylength);
216 length = ((struct recv_frame *)precvframe)->len-prxattrib->hdrlen-prxattrib->iv_len; 220 length = ((struct recv_frame *)precvframe)->pkt->len-prxattrib->hdrlen-prxattrib->iv_len;
217 221
218 payload = pframe+prxattrib->iv_len+prxattrib->hdrlen; 222 payload = pframe+prxattrib->iv_len+prxattrib->hdrlen;
219 223
@@ -242,6 +246,7 @@ static u32 secmicgetuint32(u8 *p)
242{ 246{
243 s32 i; 247 s32 i;
244 u32 res = 0; 248 u32 res = 0;
249
245 for (i = 0; i < 4; i++) 250 for (i = 0; i < 4; i++)
246 res |= ((u32)(*p++)) << (8*i); 251 res |= ((u32)(*p++)) << (8*i);
247 return res; 252 return res;
@@ -251,6 +256,7 @@ static void secmicputuint32(u8 *p, u32 val)
251/* Convert from Us3232 to Byte[] in a portable way */ 256/* Convert from Us3232 to Byte[] in a portable way */
252{ 257{
253 long i; 258 long i;
259
254 for (i = 0; i < 4; i++) { 260 for (i = 0; i < 4; i++) {
255 *p++ = (u8)(val & 0xff); 261 *p++ = (u8)(val & 0xff);
256 val >>= 8; 262 val >>= 8;
@@ -328,6 +334,7 @@ void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len, u8 *mic_cod
328{ 334{
329 struct mic_data micdata; 335 struct mic_data micdata;
330 u8 priority[4] = {0x0, 0x0, 0x0, 0x0}; 336 u8 priority[4] = {0x0, 0x0, 0x0, 0x0};
337
331 rtw_secmicsetkey(&micdata, key); 338 rtw_secmicsetkey(&micdata, key);
332 priority[0] = pri; 339 priority[0] = pri;
333 340
@@ -378,73 +385,73 @@ void rtw_seccalctkipmic(u8 *key, u8 *header, u8 *data, u32 data_len, u8 *mic_cod
378/* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */ 385/* 2-unsigned char by 2-unsigned char subset of the full AES S-box table */
379static const unsigned short Sbox1[2][256] = { /* Sbox for hash (can be in ROM) */ 386static const unsigned short Sbox1[2][256] = { /* Sbox for hash (can be in ROM) */
380{ 387{
381 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154, 388 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
382 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A, 389 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
383 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B, 390 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
384 0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B, 391 0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
385 0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F, 392 0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
386 0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F, 393 0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
387 0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5, 394 0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
388 0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F, 395 0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
389 0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB, 396 0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
390 0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397, 397 0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
391 0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED, 398 0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
392 0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A, 399 0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
393 0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194, 400 0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
394 0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3, 401 0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
395 0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104, 402 0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
396 0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D, 403 0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
397 0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39, 404 0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
398 0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695, 405 0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
399 0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83, 406 0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
400 0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76, 407 0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
401 0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4, 408 0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
402 0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B, 409 0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
403 0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0, 410 0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
404 0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018, 411 0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
405 0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751, 412 0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
406 0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85, 413 0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
407 0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12, 414 0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
408 0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9, 415 0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
409 0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7, 416 0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
410 0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A, 417 0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
411 0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8, 418 0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
412 0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A, 419 0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
413 }, 420 },
414 421
415 { /* second half of table is unsigned char-reversed version of first! */ 422 { /* second half of table is unsigned char-reversed version of first! */
416 0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491, 423 0xA5C6, 0x84F8, 0x99EE, 0x8DF6, 0x0DFF, 0xBDD6, 0xB1DE, 0x5491,
417 0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC, 424 0x5060, 0x0302, 0xA9CE, 0x7D56, 0x19E7, 0x62B5, 0xE64D, 0x9AEC,
418 0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB, 425 0x458F, 0x9D1F, 0x4089, 0x87FA, 0x15EF, 0xEBB2, 0xC98E, 0x0BFB,
419 0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B, 426 0xEC41, 0x67B3, 0xFD5F, 0xEA45, 0xBF23, 0xF753, 0x96E4, 0x5B9B,
420 0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83, 427 0xC275, 0x1CE1, 0xAE3D, 0x6A4C, 0x5A6C, 0x417E, 0x02F5, 0x4F83,
421 0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A, 428 0x5C68, 0xF451, 0x34D1, 0x08F9, 0x93E2, 0x73AB, 0x5362, 0x3F2A,
422 0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F, 429 0x0C08, 0x5295, 0x6546, 0x5E9D, 0x2830, 0xA137, 0x0F0A, 0xB52F,
423 0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA, 430 0x090E, 0x3624, 0x9B1B, 0x3DDF, 0x26CD, 0x694E, 0xCD7F, 0x9FEA,
424 0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B, 431 0x1B12, 0x9E1D, 0x7458, 0x2E34, 0x2D36, 0xB2DC, 0xEEB4, 0xFB5B,
425 0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713, 432 0xF6A4, 0x4D76, 0x61B7, 0xCE7D, 0x7B52, 0x3EDD, 0x715E, 0x9713,
426 0xF5A6, 0x68B9, 0x0000, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6, 433 0xF5A6, 0x68B9, 0x0000, 0x2CC1, 0x6040, 0x1FE3, 0xC879, 0xEDB6,
427 0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85, 434 0xBED4, 0x468D, 0xD967, 0x4B72, 0xDE94, 0xD498, 0xE8B0, 0x4A85,
428 0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411, 435 0x6BBB, 0x2AC5, 0xE54F, 0x16ED, 0xC586, 0xD79A, 0x5566, 0x9411,
429 0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B, 436 0xCF8A, 0x10E9, 0x0604, 0x81FE, 0xF0A0, 0x4478, 0xBA25, 0xE34B,
430 0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1, 437 0xF3A2, 0xFE5D, 0xC080, 0x8A05, 0xAD3F, 0xBC21, 0x4870, 0x04F1,
431 0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF, 438 0xDF63, 0xC177, 0x75AF, 0x6342, 0x3020, 0x1AE5, 0x0EFD, 0x6DBF,
432 0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E, 439 0x4C81, 0x1418, 0x3526, 0x2FC3, 0xE1BE, 0xA235, 0xCC88, 0x392E,
433 0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6, 440 0x5793, 0xF255, 0x82FC, 0x477A, 0xACC8, 0xE7BA, 0x2B32, 0x95E6,
434 0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B, 441 0xA0C0, 0x9819, 0xD19E, 0x7FA3, 0x6644, 0x7E54, 0xAB3B, 0x830B,
435 0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD, 442 0xCA8C, 0x29C7, 0xD36B, 0x3C28, 0x79A7, 0xE2BC, 0x1D16, 0x76AD,
436 0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8, 443 0x3BDB, 0x5664, 0x4E74, 0x1E14, 0xDB92, 0x0A0C, 0x6C48, 0xE4B8,
437 0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2, 444 0x5D9F, 0x6EBD, 0xEF43, 0xA6C4, 0xA839, 0xA431, 0x37D3, 0x8BF2,
438 0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049, 445 0x32D5, 0x438B, 0x596E, 0xB7DA, 0x8C01, 0x64B1, 0xD29C, 0xE049,
439 0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810, 446 0xB4D8, 0xFAAC, 0x07F3, 0x25CF, 0xAFCA, 0x8EF4, 0xE947, 0x1810,
440 0xD56F, 0x88F0, 0x6F4A, 0x725C, 0x2438, 0xF157, 0xC773, 0x5197, 447 0xD56F, 0x88F0, 0x6F4A, 0x725C, 0x2438, 0xF157, 0xC773, 0x5197,
441 0x23CB, 0x7CA1, 0x9CE8, 0x213E, 0xDD96, 0xDC61, 0x860D, 0x850F, 448 0x23CB, 0x7CA1, 0x9CE8, 0x213E, 0xDD96, 0xDC61, 0x860D, 0x850F,
442 0x90E0, 0x427C, 0xC471, 0xAACC, 0xD890, 0x0506, 0x01F7, 0x121C, 449 0x90E0, 0x427C, 0xC471, 0xAACC, 0xD890, 0x0506, 0x01F7, 0x121C,
443 0xA3C2, 0x5F6A, 0xF9AE, 0xD069, 0x9117, 0x5899, 0x273A, 0xB927, 450 0xA3C2, 0x5F6A, 0xF9AE, 0xD069, 0x9117, 0x5899, 0x273A, 0xB927,
444 0x38D9, 0x13EB, 0xB32B, 0x3322, 0xBBD2, 0x70A9, 0x8907, 0xA733, 451 0x38D9, 0x13EB, 0xB32B, 0x3322, 0xBBD2, 0x70A9, 0x8907, 0xA733,
445 0xB62D, 0x223C, 0x9215, 0x20C9, 0x4987, 0xFFAA, 0x7850, 0x7AA5, 452 0xB62D, 0x223C, 0x9215, 0x20C9, 0x4987, 0xFFAA, 0x7850, 0x7AA5,
446 0x8F03, 0xF859, 0x8009, 0x171A, 0xDA65, 0x31D7, 0xC684, 0xB8D0, 453 0x8F03, 0xF859, 0x8009, 0x171A, 0xDA65, 0x31D7, 0xC684, 0xB8D0,
447 0xC382, 0xB029, 0x775A, 0x111E, 0xCB7B, 0xFCA8, 0xD66D, 0x3A2C, 454 0xC382, 0xB029, 0x775A, 0x111E, 0xCB7B, 0xFCA8, 0xD66D, 0x3A2C,
448 } 455 }
449}; 456};
450 457
@@ -652,7 +659,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
652 u32 res = _SUCCESS; 659 u32 res = _SUCCESS;
653 660
654 661
655 pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data; 662 pframe = (unsigned char *)((struct recv_frame *)precvframe)->pkt->data;
656 663
657 /* 4 start to decrypt recvframe */ 664 /* 4 start to decrypt recvframe */
658 if (prxattrib->encrypt == _TKIP_) { 665 if (prxattrib->encrypt == _TKIP_) {
@@ -672,7 +679,7 @@ u32 rtw_tkip_decrypt(struct adapter *padapter, u8 *precvframe)
672 679
673 iv = pframe+prxattrib->hdrlen; 680 iv = pframe+prxattrib->hdrlen;
674 payload = pframe+prxattrib->iv_len+prxattrib->hdrlen; 681 payload = pframe+prxattrib->iv_len+prxattrib->hdrlen;
675 length = ((struct recv_frame *)precvframe)->len-prxattrib->hdrlen-prxattrib->iv_len; 682 length = ((struct recv_frame *)precvframe)->pkt->len-prxattrib->hdrlen-prxattrib->iv_len;
676 683
677 GET_TKIP_PN(iv, dot11txpn); 684 GET_TKIP_PN(iv, dot11txpn);
678 685
@@ -776,6 +783,7 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext);
776static void xor_128(u8 *a, u8 *b, u8 *out) 783static void xor_128(u8 *a, u8 *b, u8 *out)
777{ 784{
778 int i; 785 int i;
786
779 for (i = 0; i < 16; i++) 787 for (i = 0; i < 16; i++)
780 out[i] = a[i] ^ b[i]; 788 out[i] = a[i] ^ b[i];
781} 789}
@@ -783,6 +791,7 @@ static void xor_128(u8 *a, u8 *b, u8 *out)
783static void xor_32(u8 *a, u8 *b, u8 *out) 791static void xor_32(u8 *a, u8 *b, u8 *out)
784{ 792{
785 int i; 793 int i;
794
786 for (i = 0; i < 4; i++) 795 for (i = 0; i < 4; i++)
787 out[i] = a[i] ^ b[i]; 796 out[i] = a[i] ^ b[i];
788} 797}
@@ -800,6 +809,7 @@ static void next_key(u8 *key, int round)
800 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 809 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
801 0x1b, 0x36, 0x36, 0x36 810 0x1b, 0x36, 0x36, 0x36
802 }; 811 };
812
803 sbox_key[0] = sbox(key[13]); 813 sbox_key[0] = sbox(key[13]);
804 sbox_key[1] = sbox(key[14]); 814 sbox_key[1] = sbox(key[14]);
805 sbox_key[2] = sbox(key[15]); 815 sbox_key[2] = sbox(key[15]);
@@ -853,6 +863,7 @@ static void mix_column(u8 *in, u8 *out)
853 u8 rotr[4]; 863 u8 rotr[4];
854 u8 temp[4]; 864 u8 temp[4];
855 u8 tempb[4]; 865 u8 tempb[4];
866
856 for (i = 0 ; i < 4; i++) { 867 for (i = 0 ; i < 4; i++) {
857 if ((in[i] & 0x80) == 0x80) 868 if ((in[i] & 0x80) == 0x80)
858 add1b[i] = 0x1b; 869 add1b[i] = 0x1b;
@@ -905,6 +916,7 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
905 u8 intermediatea[16]; 916 u8 intermediatea[16];
906 u8 intermediateb[16]; 917 u8 intermediateb[16];
907 u8 round_key[16]; 918 u8 round_key[16];
919
908 for (i = 0; i < 16; i++) 920 for (i = 0; i < 16; i++)
909 round_key[i] = key[i]; 921 round_key[i] = key[i];
910 for (round = 0; round < 11; round++) { 922 for (round = 0; round < 11; round++) {
@@ -936,6 +948,7 @@ static void construct_mic_iv(u8 *mic_iv, int qc_exists, int a4_exists, u8 *mpdu,
936 uint payload_length, u8 *pn_vector) 948 uint payload_length, u8 *pn_vector)
937{ 949{
938 int i; 950 int i;
951
939 mic_iv[0] = 0x59; 952 mic_iv[0] = 0x59;
940 if (qc_exists && a4_exists) 953 if (qc_exists && a4_exists)
941 mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */ 954 mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */
@@ -984,6 +997,7 @@ static void construct_mic_header1(u8 *mic_header1, int header_length, u8 *mpdu)
984static void construct_mic_header2(u8 *mic_header2, u8 *mpdu, int a4_exists, int qc_exists) 997static void construct_mic_header2(u8 *mic_header2, u8 *mpdu, int a4_exists, int qc_exists)
985{ 998{
986 int i; 999 int i;
1000
987 for (i = 0; i < 16; i++) 1001 for (i = 0; i < 16; i++)
988 mic_header2[i] = 0x00; 1002 mic_header2[i] = 0x00;
989 1003
@@ -1025,6 +1039,7 @@ static void construct_mic_header2(u8 *mic_header2, u8 *mpdu, int a4_exists, int
1025static void construct_ctr_preload(u8 *ctr_preload, int a4_exists, int qc_exists, u8 *mpdu, u8 *pn_vector, int c) 1039static void construct_ctr_preload(u8 *ctr_preload, int a4_exists, int qc_exists, u8 *mpdu, u8 *pn_vector, int c)
1026{ 1040{
1027 int i; 1041 int i;
1042
1028 for (i = 0; i < 16; i++) 1043 for (i = 0; i < 16; i++)
1029 ctr_preload[i] = 0x00; 1044 ctr_preload[i] = 0x00;
1030 i = 0; 1045 i = 0;
@@ -1050,6 +1065,7 @@ static void construct_ctr_preload(u8 *ctr_preload, int a4_exists, int qc_exists,
1050static void bitwise_xor(u8 *ina, u8 *inb, u8 *out) 1065static void bitwise_xor(u8 *ina, u8 *inb, u8 *out)
1051{ 1066{
1052 int i; 1067 int i;
1068
1053 for (i = 0; i < 16; i++) 1069 for (i = 0; i < 16; i++)
1054 out[i] = ina[i] ^ inb[i]; 1070 out[i] = ina[i] ^ inb[i];
1055} 1071}
@@ -1256,6 +1272,7 @@ static int aes_decipher(u8 *key, uint hdrlen,
1256 uint qc_exists, a4_exists, i, j, payload_remainder, 1272 uint qc_exists, a4_exists, i, j, payload_remainder,
1257 num_blocks, payload_index; 1273 num_blocks, payload_index;
1258 int res = _SUCCESS; 1274 int res = _SUCCESS;
1275
1259 u8 pn_vector[6]; 1276 u8 pn_vector[6];
1260 u8 mic_iv[16]; 1277 u8 mic_iv[16];
1261 u8 mic_header1[16]; 1278 u8 mic_header1[16];
@@ -1452,7 +1469,8 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
1452 struct rx_pkt_attrib *prxattrib = &((struct recv_frame *)precvframe)->attrib; 1469 struct rx_pkt_attrib *prxattrib = &((struct recv_frame *)precvframe)->attrib;
1453 struct security_priv *psecuritypriv = &padapter->securitypriv; 1470 struct security_priv *psecuritypriv = &padapter->securitypriv;
1454 u32 res = _SUCCESS; 1471 u32 res = _SUCCESS;
1455 pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data; 1472
1473 pframe = (unsigned char *)((struct recv_frame *)precvframe)->pkt->data;
1456 /* 4 start to encrypt each fragment */ 1474 /* 4 start to encrypt each fragment */
1457 if (prxattrib->encrypt == _AES_) { 1475 if (prxattrib->encrypt == _AES_) {
1458 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); 1476 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]);
@@ -1476,7 +1494,7 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
1476 } else { 1494 } else {
1477 prwskey = &stainfo->dot118021x_UncstKey.skey[0]; 1495 prwskey = &stainfo->dot118021x_UncstKey.skey[0];
1478 } 1496 }
1479 length = ((struct recv_frame *)precvframe)->len-prxattrib->hdrlen-prxattrib->iv_len; 1497 length = ((struct recv_frame *)precvframe)->pkt->len-prxattrib->hdrlen-prxattrib->iv_len;
1480 res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length); 1498 res = aes_decipher(prwskey, prxattrib->hdrlen, pframe, length);
1481 } else { 1499 } else {
1482 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_encrypt: stainfo==NULL!!!\n")); 1500 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_encrypt: stainfo==NULL!!!\n"));
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index 941d1a069d20..2ecfb117bf3f 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -154,6 +154,7 @@ u32 _rtw_free_sta_priv(struct sta_priv *pstapriv)
154 154
155 while (phead != plist) { 155 while (phead != plist) {
156 int i; 156 int i;
157
157 psta = container_of(plist, struct sta_info, 158 psta = container_of(plist, struct sta_info,
158 hash_list); 159 hash_list);
159 plist = plist->next; 160 plist = plist->next;
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index 2a65ac702129..f6f1b09466a8 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -379,6 +379,7 @@ int get_bsstype(unsigned short capability)
379u16 get_beacon_interval(struct wlan_bssid_ex *bss) 379u16 get_beacon_interval(struct wlan_bssid_ex *bss)
380{ 380{
381 __le16 val; 381 __le16 val;
382
382 memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2); 383 memcpy((unsigned char *)&val, rtw_get_beacon_interval_from_ie(bss->IEs), 2);
383 384
384 return le16_to_cpu(val); 385 return le16_to_cpu(val);
@@ -1306,6 +1307,7 @@ void set_sta_rate(struct adapter *padapter, struct sta_info *psta)
1306void update_tx_basic_rate(struct adapter *padapter, u8 wirelessmode) 1307void update_tx_basic_rate(struct adapter *padapter, u8 wirelessmode)
1307{ 1308{
1308 unsigned char supported_rates[NDIS_802_11_LENGTH_RATES_EX]; 1309 unsigned char supported_rates[NDIS_802_11_LENGTH_RATES_EX];
1310
1309 memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX); 1311 memset(supported_rates, 0, NDIS_802_11_LENGTH_RATES_EX);
1310 1312
1311 if ((wirelessmode & WIRELESS_11B) && (wirelessmode == WIRELESS_11B)) 1313 if ((wirelessmode & WIRELESS_11B) && (wirelessmode == WIRELESS_11B))
@@ -1330,6 +1332,7 @@ unsigned char check_assoc_AP(u8 *pframe, uint len)
1330 struct ndis_802_11_var_ie *pIE; 1332 struct ndis_802_11_var_ie *pIE;
1331 u8 epigram_vendor_flag; 1333 u8 epigram_vendor_flag;
1332 u8 ralink_vendor_flag; 1334 u8 ralink_vendor_flag;
1335
1333 epigram_vendor_flag = 0; 1336 epigram_vendor_flag = 0;
1334 ralink_vendor_flag = 0; 1337 ralink_vendor_flag = 0;
1335 1338
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index b60b126b860e..630fdc33d58a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -246,8 +246,7 @@ void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv)
246 pxmitbuf++; 246 pxmitbuf++;
247 } 247 }
248 248
249 if (pxmitpriv->pallocated_xmit_extbuf) 249 vfree(pxmitpriv->pallocated_xmit_extbuf);
250 vfree(pxmitpriv->pallocated_xmit_extbuf);
251 250
252 rtw_free_hwxmits(padapter); 251 rtw_free_hwxmits(padapter);
253 252
@@ -304,6 +303,7 @@ static void update_attrib_vcs_info(struct adapter *padapter, struct xmit_frame *
304 /* check HT op mode */ 303 /* check HT op mode */
305 if (pattrib->ht_en) { 304 if (pattrib->ht_en) {
306 u8 htopmode = pmlmeinfo->HT_protection; 305 u8 htopmode = pmlmeinfo->HT_protection;
306
307 if ((pmlmeext->cur_bwmode && (htopmode == 2 || htopmode == 3)) || 307 if ((pmlmeext->cur_bwmode && (htopmode == 2 || htopmode == 3)) ||
308 (!pmlmeext->cur_bwmode && htopmode == 3)) { 308 (!pmlmeext->cur_bwmode && htopmode == 3)) {
309 pattrib->vcs_mode = RTS_CTS; 309 pattrib->vcs_mode = RTS_CTS;
@@ -454,6 +454,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
454 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */ 454 /* The following is for DHCP and ARP packet, we use cck1M to tx these packets and let LPS awake some time */
455 /* to prevent DHCP protocol fail */ 455 /* to prevent DHCP protocol fail */
456 u8 tmp[24]; 456 u8 tmp[24];
457
457 _rtw_pktfile_read(&pktfile, &tmp[0], 24); 458 _rtw_pktfile_read(&pktfile, &tmp[0], 24);
458 pattrib->dhcp_pkt = 0; 459 pattrib->dhcp_pkt = 0;
459 if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */ 460 if (pktfile.pkt_len > 282) {/* MINIMUM_DHCP_PACKET_SIZE) { */
@@ -530,7 +531,7 @@ static s32 update_attrib(struct adapter *padapter, struct sk_buff *pkt, struct p
530 531
531 pattrib->encrypt = 0; 532 pattrib->encrypt = 0;
532 533
533 if ((pattrib->ether_type != ETH_P_PAE) && !check_fwstate(pmlmepriv, WIFI_MP_STATE)) { 534 if (pattrib->ether_type != ETH_P_PAE) {
534 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\npsta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != ETH_P_PAE\n", pattrib->ether_type)); 535 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, ("\npsta->ieee8021x_blocked == true, pattrib->ether_type(%.4x) != ETH_P_PAE\n", pattrib->ether_type));
535 res = _FAIL; 536 res = _FAIL;
536 goto exit; 537 goto exit;
@@ -1605,6 +1606,7 @@ void rtw_free_hwxmits(struct adapter *padapter)
1605void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry) 1606void rtw_init_hwxmits(struct hw_xmit *phwxmit, int entry)
1606{ 1607{
1607 int i; 1608 int i;
1609
1608 for (i = 0; i < entry; i++, phwxmit++) 1610 for (i = 0; i < entry; i++, phwxmit++)
1609 phwxmit->accnt = 0; 1611 phwxmit->accnt = 0;
1610} 1612}
diff --git a/drivers/staging/rtl8188eu/hal/bb_cfg.c b/drivers/staging/rtl8188eu/hal/bb_cfg.c
index 134fa6c595a8..26e0ef224299 100644
--- a/drivers/staging/rtl8188eu/hal/bb_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/bb_cfg.c
@@ -534,9 +534,8 @@ static void store_pwrindex_offset(struct adapter *adapter,
534 power_level_offset[11] = data; 534 power_level_offset[11] = data;
535 if (regaddr == rTxAGC_B_Mcs11_Mcs08) 535 if (regaddr == rTxAGC_B_Mcs11_Mcs08)
536 power_level_offset[12] = data; 536 power_level_offset[12] = data;
537 if (regaddr == rTxAGC_B_Mcs15_Mcs12) { 537 if (regaddr == rTxAGC_B_Mcs15_Mcs12)
538 power_level_offset[13] = data; 538 power_level_offset[13] = data;
539 }
540} 539}
541 540
542static void rtl_addr_delay(struct adapter *adapt, 541static void rtl_addr_delay(struct adapter *adapt,
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c b/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c
index fa2cfd5768de..d9fa290c5f78 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_rxdesc.c
@@ -150,7 +150,7 @@ void update_recvframe_phyinfo_88e(struct recv_frame *precvframe,
150 pkt_info.bPacketToSelf = false; 150 pkt_info.bPacketToSelf = false;
151 pkt_info.bPacketBeacon = false; 151 pkt_info.bPacketBeacon = false;
152 152
153 wlanhdr = precvframe->rx_data; 153 wlanhdr = precvframe->pkt->data;
154 154
155 pkt_info.bPacketMatchBSSID = ((!IsFrameTypeCtrl(wlanhdr)) && 155 pkt_info.bPacketMatchBSSID = ((!IsFrameTypeCtrl(wlanhdr)) &&
156 !pattrib->icv_err && !pattrib->crc_err && 156 !pattrib->icv_err && !pattrib->crc_err &&
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c
index 85650b2663ec..53e312aaefb5 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c
@@ -635,7 +635,7 @@ s32 rtw_hal_xmit(struct adapter *adapt, struct xmit_frame *pxmitframe)
635 if (res == _SUCCESS) { 635 if (res == _SUCCESS) {
636 rtw_dump_xframe(adapt, pxmitframe); 636 rtw_dump_xframe(adapt, pxmitframe);
637 } else { 637 } else {
638 DBG_88E("==> %s xmitframe_coalsece failed\n", __func__); 638 DBG_88E("==> %s xmitframe_coalesce failed\n", __func__);
639 rtw_free_xmitbuf(pxmitpriv, pxmitbuf); 639 rtw_free_xmitbuf(pxmitpriv, pxmitbuf);
640 rtw_free_xmitframe(pxmitpriv, pxmitframe); 640 rtw_free_xmitframe(pxmitpriv, pxmitframe);
641 } 641 }
diff --git a/drivers/staging/rtl8188eu/include/drv_types.h b/drivers/staging/rtl8188eu/include/drv_types.h
index e86419e525d8..0fd2a2d9be20 100644
--- a/drivers/staging/rtl8188eu/include/drv_types.h
+++ b/drivers/staging/rtl8188eu/include/drv_types.h
@@ -168,7 +168,6 @@ struct adapter {
168 u8 bFWReady; 168 u8 bFWReady;
169 u8 bReadPortCancel; 169 u8 bReadPortCancel;
170 u8 bWritePortCancel; 170 u8 bWritePortCancel;
171 u8 bRxRSSIDisplay;
172 171
173 struct mutex hw_init_mutex; 172 struct mutex hw_init_mutex;
174}; 173};
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
index 9047b6dec9ed..ee3f5ee06529 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -69,9 +69,6 @@ static inline int rtw_netif_queue_stopped(struct net_device *pnetdev)
69 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3)); 69 netif_tx_queue_stopped(netdev_get_tx_queue(pnetdev, 3));
70} 70}
71 71
72int RTW_STATUS_CODE(int error_code);
73
74#define rtw_update_mem_stat(flag, sz) do {} while (0)
75u8 *_rtw_malloc(u32 sz); 72u8 *_rtw_malloc(u32 sz);
76#define rtw_malloc(sz) _rtw_malloc((sz)) 73#define rtw_malloc(sz) _rtw_malloc((sz))
77 74
@@ -88,10 +85,6 @@ struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv);
88 (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv) 85 (((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
89void rtw_free_netdev(struct net_device *netdev); 86void rtw_free_netdev(struct net_device *netdev);
90 87
91#define NDEV_FMT "%s"
92#define NDEV_ARG(ndev) ndev->name
93#define ADPT_FMT "%s"
94#define ADPT_ARG(adapter) adapter->pnetdev->name
95#define FUNC_NDEV_FMT "%s(%s)" 88#define FUNC_NDEV_FMT "%s(%s)"
96#define FUNC_NDEV_ARG(ndev) __func__, ndev->name 89#define FUNC_NDEV_ARG(ndev) __func__, ndev->name
97#define FUNC_ADPT_FMT "%s(%s)" 90#define FUNC_ADPT_FMT "%s(%s)"
diff --git a/drivers/staging/rtl8188eu/include/rtw_debug.h b/drivers/staging/rtl8188eu/include/rtw_debug.h
index 95590a1a7b1b..9cc4b8c7c166 100644
--- a/drivers/staging/rtl8188eu/include/rtw_debug.h
+++ b/drivers/staging/rtl8188eu/include/rtw_debug.h
@@ -70,7 +70,7 @@ extern u32 GlobalDebugLevel;
70#define DBG_88E_LEVEL(_level, fmt, arg...) \ 70#define DBG_88E_LEVEL(_level, fmt, arg...) \
71 do { \ 71 do { \
72 if (_level <= GlobalDebugLevel) \ 72 if (_level <= GlobalDebugLevel) \
73 pr_info(DRIVER_PREFIX"ERROR " fmt, ##arg); \ 73 pr_info(DRIVER_PREFIX fmt, ##arg); \
74 } while (0) 74 } while (0)
75 75
76#define DBG_88E(...) \ 76#define DBG_88E(...) \
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme.h b/drivers/staging/rtl8188eu/include/rtw_mlme.h
index 18fb7e7b2273..7324a95bb162 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme.h
@@ -47,14 +47,6 @@
47#define WIFI_STA_ALIVE_CHK_STATE 0x00000400 47#define WIFI_STA_ALIVE_CHK_STATE 0x00000400
48#define WIFI_SITE_MONITOR 0x00000800 /* to indicate the station is under site surveying */ 48#define WIFI_SITE_MONITOR 0x00000800 /* to indicate the station is under site surveying */
49 49
50#define WIFI_MP_STATE 0x00010000
51#define WIFI_MP_CTX_BACKGROUND 0x00020000 /* in continuous tx background */
52#define WIFI_MP_CTX_ST 0x00040000 /* in continuous tx with single-tone */
53#define WIFI_MP_CTX_BACKGROUND_PENDING 0x00080000 /* pending in continuous tx background due to out of skb */
54#define WIFI_MP_CTX_CCK_HW 0x00100000 /* in continuous tx */
55#define WIFI_MP_CTX_CCK_CS 0x00200000 /* in continuous tx with carrier suppression */
56#define WIFI_MP_LPBK_STATE 0x00400000
57
58#define _FW_UNDER_LINKING WIFI_UNDER_LINKING 50#define _FW_UNDER_LINKING WIFI_UNDER_LINKING
59#define _FW_LINKED WIFI_ASOC_STATE 51#define _FW_LINKED WIFI_ASOC_STATE
60#define _FW_UNDER_SURVEY WIFI_SITE_MONITOR 52#define _FW_UNDER_SURVEY WIFI_SITE_MONITOR
@@ -115,183 +107,6 @@ struct rt_link_detect {
115 * to Tx traffic. */ 107 * to Tx traffic. */
116}; 108};
117 109
118struct profile_info {
119 u8 ssidlen;
120 u8 ssid[WLAN_SSID_MAXLEN];
121 u8 peermac[ETH_ALEN];
122};
123
124struct tx_invite_req_info {
125 u8 token;
126 u8 benable;
127 u8 go_ssid[WLAN_SSID_MAXLEN];
128 u8 ssidlen;
129 u8 go_bssid[ETH_ALEN];
130 u8 peer_macaddr[ETH_ALEN];
131 u8 operating_ch; /* This information will be set by using the
132 * p2p_set op_ch=x */
133 u8 peer_ch; /* The listen channel for peer P2P device */
134};
135
136struct tx_invite_resp_info {
137 u8 token; /* Used to record the dialog token of p2p invitation
138 * request frame. */
139};
140
141struct tx_provdisc_req_info {
142 u16 wps_config_method_request; /* Used when sending the
143 * provisioning request frame*/
144 u16 peer_channel_num[2]; /* The channel number which the
145 * receiver stands. */
146 struct ndis_802_11_ssid ssid;
147 u8 peerDevAddr[ETH_ALEN]; /* Peer device address */
148 u8 peerIFAddr[ETH_ALEN]; /* Peer interface address */
149 u8 benable; /* This provision discovery
150 * request frame is trigger
151 * to send or not */
152};
153
154/* When peer device issue prov_disc_req first, we should store the following
155 * information */
156/* The UI must know this information to know which config method the
157 * remote p2p device needs. */
158struct rx_provdisc_req_info {
159 u8 peerDevAddr[ETH_ALEN]; /* Peer device address */
160 u8 strconfig_method_desc_of_prov_disc_req[4]; /* description
161 * for the config method located in the provisioning
162 * discovery request frame. */
163};
164
165struct tx_nego_req_info {
166 u16 peer_channel_num[2]; /* The channel number. */
167 u8 peerDevAddr[ETH_ALEN]; /* Peer device address */
168 u8 benable; /* This negotiation request frame is
169 * trigger to send or not */
170};
171
172struct group_id_info {
173 u8 go_device_addr[ETH_ALEN]; /* The GO's device address of
174 * this P2P group */
175 u8 ssid[WLAN_SSID_MAXLEN]; /* The SSID of this P2P group */
176};
177
178struct scan_limit_info {
179 u8 scan_op_ch_only; /* When this flag is set, the driver
180 * should only scan the op. channel */
181 u8 operation_ch[2]; /* Store the op. chan of invitation */
182};
183
184struct wifidirect_info {
185 struct adapter *padapter;
186 struct timer_list find_phase_timer;
187 struct timer_list restore_p2p_state_timer;
188
189 /* Used to do the scanning. After confirming the peer is availalble,
190 * the driver transmits the P2P frame to peer. */
191 struct timer_list pre_tx_scan_timer;
192 struct timer_list reset_ch_sitesurvey;
193 struct timer_list reset_ch_sitesurvey2; /* Just for resetting the scan
194 * limit function by using p2p nego */
195 struct tx_provdisc_req_info tx_prov_disc_info;
196 struct rx_provdisc_req_info rx_prov_disc_info;
197 struct tx_invite_req_info invitereq_info;
198 /* Store the profile information of persistent group */
199 struct profile_info profileinfo[P2P_MAX_PERSISTENT_GROUP_NUM];
200 struct tx_invite_resp_info inviteresp_info;
201 struct tx_nego_req_info nego_req_info;
202 /* Store the group id info when doing the group negot handshake. */
203 struct group_id_info groupid_info;
204 /* Used for get the limit scan channel from the Invitation procedure */
205 struct scan_limit_info rx_invitereq_info;
206 /* Used for get the limit scan chan from the P2P negotiation handshake*/
207 struct scan_limit_info p2p_info;
208 enum P2P_ROLE role;
209 enum P2P_STATE pre_p2p_state;
210 enum P2P_STATE p2p_state;
211 /* The device address should be the mac address of this device. */
212 u8 device_addr[ETH_ALEN];
213 u8 interface_addr[ETH_ALEN];
214 u8 social_chan[4];
215 u8 listen_channel;
216 u8 operating_channel;
217 u8 listen_dwell; /* This value should be between 1 and 3 */
218 u8 support_rate[8];
219 u8 p2p_wildcard_ssid[P2P_WILDCARD_SSID_LEN];
220 u8 intent; /* should only include the intent value. */
221 u8 p2p_peer_interface_addr[ETH_ALEN];
222 u8 p2p_peer_device_addr[ETH_ALEN];
223 u8 peer_intent; /* Included the intent value and tie breaker value. */
224 /* Device name for displaying on searching device screen */
225 u8 device_name[WPS_MAX_DEVICE_NAME_LEN];
226 u8 device_name_len;
227 u8 profileindex; /* Used to point to the index of profileinfo array */
228 u8 peer_operating_ch;
229 u8 find_phase_state_exchange_cnt;
230 /* The device password ID for group negotiation */
231 u16 device_password_id_for_nego;
232 u8 negotiation_dialog_token;
233 /* SSID information for group negotitation */
234 u8 nego_ssid[WLAN_SSID_MAXLEN];
235 u8 nego_ssidlen;
236 u8 p2p_group_ssid[WLAN_SSID_MAXLEN];
237 u8 p2p_group_ssid_len;
238 /* Flag to know if the persistent function should be supported or not.*/
239 u8 persistent_supported;
240 /* In the Sigma test, the Sigma will provide this enable from the
241 * sta_set_p2p CAPI. */
242 /* 0: disable */
243 /* 1: enable */
244 u8 session_available; /* Flag to set the WFD session available to
245 * enable or disable "by Sigma" */
246 /* In the Sigma test, the Sigma will disable the session available
247 * by using the sta_preset CAPI. */
248 /* 0: disable */
249 /* 1: enable */
250 u8 wfd_tdls_enable; /* Flag to enable or disable the TDLS by WFD Sigma*/
251 /* 0: disable */
252 /* 1: enable */
253 u8 wfd_tdls_weaksec; /* Flag to enable or disable the weak security
254 * function for TDLS by WFD Sigma */
255 /* 0: disable */
256 /* In this case, the driver can't issue the tdsl
257 * setup request frame. */
258 /* 1: enable */
259 /* In this case, the driver can issue the tdls
260 * setup request frame */
261 /* even the current security is weak security. */
262
263 /* This field will store the WPS value (PIN value or PBC) that UI had
264 * got from the user. */
265 enum P2P_WPSINFO ui_got_wps_info;
266 u16 supported_wps_cm; /* This field describes the WPS config method
267 * which this driver supported. */
268 /* The value should be the combination of config
269 * method defined in page104 of WPS v2.0 spec.*/
270 /* This field will contain the length of body of P2P Channel List
271 * attribute of group negotiation response frame. */
272 uint channel_list_attr_len;
273 /* This field will contain the body of P2P Channel List attribute of
274 * group negotitation response frame. */
275 /* We will use the channel_cnt and channel_list fields when constructing
276 * the group negotiation confirm frame. */
277 u8 channel_list_attr[100];
278 enum P2P_PS_MODE p2p_ps_mode; /* indicate p2p ps mode */
279 enum P2P_PS_STATE p2p_ps_state; /* indicate p2p ps state */
280 u8 noa_index; /* Identifies and instance of Notice of Absence timing. */
281 u8 ctwindow; /* Client traffic window. A period of time in TU after TBTT. */
282 u8 opp_ps; /* opportunistic power save. */
283 u8 noa_num; /* number of NoA descriptor in P2P IE. */
284 u8 noa_count[P2P_MAX_NOA_NUM]; /* Count for owner, Type of client. */
285 /* Max duration for owner, preferred or min acceptable duration for
286 * client. */
287 u32 noa_duration[P2P_MAX_NOA_NUM];
288 /* Length of interval for owner, preferred or max acceptable interval
289 * of client. */
290 u32 noa_interval[P2P_MAX_NOA_NUM];
291 /* schedule expressed in terms of the lower 4 bytes of the TSF timer. */
292 u32 noa_start_time[P2P_MAX_NOA_NUM];
293};
294
295struct mlme_priv { 110struct mlme_priv {
296 spinlock_t lock; 111 spinlock_t lock;
297 int fw_state; /* shall we protect this variable? maybe not necessarily... */ 112 int fw_state; /* shall we protect this variable? maybe not necessarily... */
diff --git a/drivers/staging/rtl8188eu/include/rtw_recv.h b/drivers/staging/rtl8188eu/include/rtw_recv.h
index 052af7b891da..b369f08d4a15 100644
--- a/drivers/staging/rtl8188eu/include/rtw_recv.h
+++ b/drivers/staging/rtl8188eu/include/rtw_recv.h
@@ -151,8 +151,6 @@ struct recv_stat {
151 __le32 rxdw5; 151 __le32 rxdw5;
152}; 152};
153 153
154#define EOR BIT(30)
155
156/* 154/*
157accesser of recv_priv: rtw_recv_entry(dispatch / passive level); 155accesser of recv_priv: rtw_recv_entry(dispatch / passive level);
158recv_thread(passive) ; returnpkt(dispatch) 156recv_thread(passive) ; returnpkt(dispatch)
@@ -179,8 +177,6 @@ struct recv_priv {
179 struct recv_buf *precv_buf; /* 4 alignment */ 177 struct recv_buf *precv_buf; /* 4 alignment */
180 struct __queue free_recv_buf_queue; 178 struct __queue free_recv_buf_queue;
181 /* For display the phy informatiom */ 179 /* For display the phy informatiom */
182 u8 is_signal_dbg; /* for debug */
183 u8 signal_strength_dbg; /* for debug */
184 s8 rssi; 180 s8 rssi;
185 s8 rxpwdb; 181 s8 rxpwdb;
186 u8 signal_strength; 182 u8 signal_strength;
@@ -232,11 +228,6 @@ struct recv_frame {
232 struct sk_buff *pkt; 228 struct sk_buff *pkt;
233 struct adapter *adapter; 229 struct adapter *adapter;
234 struct rx_pkt_attrib attrib; 230 struct rx_pkt_attrib attrib;
235 uint len;
236 u8 *rx_head;
237 u8 *rx_data;
238 u8 *rx_tail;
239 u8 *rx_end;
240 struct sta_info *psta; 231 struct sta_info *psta;
241 /* for A-MPDU Rx reordering buffer control */ 232 /* for A-MPDU Rx reordering buffer control */
242 struct recv_reorder_ctrl *preorder_ctrl; 233 struct recv_reorder_ctrl *preorder_ctrl;
@@ -258,70 +249,6 @@ u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
258 249
259void rtw_reordering_ctrl_timeout_handler(unsigned long data); 250void rtw_reordering_ctrl_timeout_handler(unsigned long data);
260 251
261static inline u8 *get_rxmem(struct recv_frame *precvframe)
262{
263 /* always return rx_head... */
264 if (precvframe == NULL)
265 return NULL;
266 return precvframe->rx_head;
267}
268
269static inline u8 *recvframe_pull(struct recv_frame *precvframe, int sz)
270{
271 /* rx_data += sz; move rx_data sz bytes hereafter */
272
273 /* used for extract sz bytes from rx_data, update rx_data and return
274 * the updated rx_data to the caller */
275
276 if (precvframe == NULL)
277 return NULL;
278 precvframe->rx_data += sz;
279 if (precvframe->rx_data > precvframe->rx_tail) {
280 precvframe->rx_data -= sz;
281 return NULL;
282 }
283 precvframe->len -= sz;
284 return precvframe->rx_data;
285}
286
287static inline u8 *recvframe_put(struct recv_frame *precvframe, int sz)
288{
289 /* used for append sz bytes from ptr to rx_tail, update rx_tail
290 * and return the updated rx_tail to the caller */
291 /* after putting, rx_tail must be still larger than rx_end. */
292
293 if (precvframe == NULL)
294 return NULL;
295
296 precvframe->rx_tail += sz;
297
298 if (precvframe->rx_tail > precvframe->rx_end) {
299 precvframe->rx_tail -= sz;
300 return NULL;
301 }
302 precvframe->len += sz;
303 return precvframe->rx_tail;
304}
305
306static inline u8 *recvframe_pull_tail(struct recv_frame *precvframe, int sz)
307{
308 /* rmv data from rx_tail (by yitsen) */
309
310 /* used for extract sz bytes from rx_end, update rx_end and return
311 * the updated rx_end to the caller */
312 /* after pulling, rx_end must be still larger than rx_data. */
313
314 if (precvframe == NULL)
315 return NULL;
316 precvframe->rx_tail -= sz;
317 if (precvframe->rx_tail < precvframe->rx_data) {
318 precvframe->rx_tail += sz;
319 return NULL;
320 }
321 precvframe->len -= sz;
322 return precvframe->rx_tail;
323}
324
325static inline s32 translate_percentage_to_dbm(u32 sig_stren_index) 252static inline s32 translate_percentage_to_dbm(u32 sig_stren_index)
326{ 253{
327 s32 power; /* in dBm. */ 254 s32 power; /* in dBm. */
diff --git a/drivers/staging/rtl8188eu/include/rtw_security.h b/drivers/staging/rtl8188eu/include/rtw_security.h
index 2663e60bb6c6..7100d6b01b32 100644
--- a/drivers/staging/rtl8188eu/include/rtw_security.h
+++ b/drivers/staging/rtl8188eu/include/rtw_security.h
@@ -255,42 +255,6 @@ static inline u32 rotr(u32 val, int bits)
255#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16) 255#define TE2(i) rotr(Te0[((i) >> 8) & 0xff], 16)
256#define TE3(i) rotr(Te0[(i) & 0xff], 24) 256#define TE3(i) rotr(Te0[(i) & 0xff], 24)
257 257
258#define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ \
259 ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))
260
261#define PUTU32(ct, st) { \
262(ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
263(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
264
265#define WPA_GET_BE32(a) ((((u32)(a)[0]) << 24) | (((u32)(a)[1]) << 16) | \
266 (((u32)(a)[2]) << 8) | ((u32)(a)[3]))
267
268#define WPA_PUT_LE16(a, val) \
269 do { \
270 (a)[1] = ((u16)(val)) >> 8; \
271 (a)[0] = ((u16)(val)) & 0xff; \
272 } while (0)
273
274#define WPA_PUT_BE32(a, val) \
275 do { \
276 (a)[0] = (u8)((((u32)(val)) >> 24) & 0xff); \
277 (a)[1] = (u8)((((u32)(val)) >> 16) & 0xff); \
278 (a)[2] = (u8)((((u32)(val)) >> 8) & 0xff); \
279 (a)[3] = (u8)(((u32)(val)) & 0xff); \
280 } while (0)
281
282#define WPA_PUT_BE64(a, val) \
283 do { \
284 (a)[0] = (u8)(((u64)(val)) >> 56); \
285 (a)[1] = (u8)(((u64)(val)) >> 48); \
286 (a)[2] = (u8)(((u64)(val)) >> 40); \
287 (a)[3] = (u8)(((u64)(val)) >> 32); \
288 (a)[4] = (u8)(((u64)(val)) >> 24); \
289 (a)[5] = (u8)(((u64)(val)) >> 16); \
290 (a)[6] = (u8)(((u64)(val)) >> 8); \
291 (a)[7] = (u8)(((u64)(val)) & 0xff); \
292 } while (0)
293
294/* ===== start - public domain SHA256 implementation ===== */ 258/* ===== start - public domain SHA256 implementation ===== */
295 259
296/* This is based on SHA256 implementation in LibTomCrypt that was released into 260/* This is based on SHA256 implementation in LibTomCrypt that was released into
diff --git a/drivers/staging/rtl8188eu/include/wifi.h b/drivers/staging/rtl8188eu/include/wifi.h
index 9e08e6842eca..cb46d353327b 100644
--- a/drivers/staging/rtl8188eu/include/wifi.h
+++ b/drivers/staging/rtl8188eu/include/wifi.h
@@ -23,7 +23,6 @@
23#define WLAN_HDR_A4_LEN 30 23#define WLAN_HDR_A4_LEN 30
24#define WLAN_HDR_A3_QOS_LEN 26 24#define WLAN_HDR_A3_QOS_LEN 26
25#define WLAN_HDR_A4_QOS_LEN 32 25#define WLAN_HDR_A4_QOS_LEN 32
26#define WLAN_SSID_MAXLEN 32
27#define WLAN_DATA_MAXLEN 2312 26#define WLAN_DATA_MAXLEN 2312
28 27
29#define WLAN_A3_PN_OFFSET 24 28#define WLAN_A3_PN_OFFSET 24
@@ -480,30 +479,6 @@ static inline int IsFrameTypeCtrl(unsigned char *pframe)
480 Below is the definition for 802.11n 479 Below is the definition for 802.11n
481------------------------------------------------------------------------------*/ 480------------------------------------------------------------------------------*/
482 481
483#define SetOrderBit(pbuf) \
484 do { \
485 *(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \
486 } while (0)
487
488#define GetOrderBit(pbuf) \
489 (((*(unsigned short *)(pbuf)) & le16_to_cpu(_ORDER_)) != 0)
490
491
492/**
493 * struct rtw_ieee80211_bar - HT Block Ack Request
494 *
495 * This structure refers to "HT BlockAckReq" as
496 * described in 802.11n draft section 7.2.1.7.1
497 */
498struct rtw_ieee80211_bar {
499 unsigned short frame_control;
500 unsigned short duration;
501 unsigned char ra[6];
502 unsigned char ta[6];
503 unsigned short control;
504 unsigned short start_seq_num;
505} __packed;
506
507/* 802.11 BAR control masks */ 482/* 802.11 BAR control masks */
508#define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000 483#define IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL 0x0000
509#define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004 484#define IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA 0x0004
@@ -653,9 +628,6 @@ enum ht_cap_ampdu_factor {
653#define WPS_ATTR_VENDOR_EXT 0x1049 628#define WPS_ATTR_VENDOR_EXT 0x1049
654#define WPS_ATTR_SELECTED_REGISTRAR 0x1041 629#define WPS_ATTR_SELECTED_REGISTRAR 0x1041
655 630
656/* Value of WPS attribute "WPS_ATTR_DEVICE_NAME */
657#define WPS_MAX_DEVICE_NAME_LEN 32
658
659/* Value of WPS Request Type Attribute */ 631/* Value of WPS Request Type Attribute */
660#define WPS_REQ_TYPE_ENROLLEE_INFO_ONLY 0x00 632#define WPS_REQ_TYPE_ENROLLEE_INFO_ONLY 0x00
661#define WPS_REQ_TYPE_ENROLLEE_OPEN_8021X 0x01 633#define WPS_REQ_TYPE_ENROLLEE_OPEN_8021X 0x01
@@ -758,14 +730,6 @@ enum ht_cap_ampdu_factor {
758#define P2P_STATUS_FAIL_USER_REJECT 0x0B 730#define P2P_STATUS_FAIL_USER_REJECT 0x0B
759 731
760/* Value of Invitation Flags Attribute */ 732/* Value of Invitation Flags Attribute */
761#define P2P_INVITATION_FLAGS_PERSISTENT BIT(0)
762
763#define DMP_P2P_DEVCAP_SUPPORT (P2P_DEVCAP_SERVICE_DISCOVERY | \
764 P2P_DEVCAP_CLIENT_DISCOVERABILITY | \
765 P2P_DEVCAP_CONCURRENT_OPERATION | \
766 P2P_DEVCAP_INVITATION_PROC)
767
768#define DMP_P2P_GRPCAP_SUPPORT (P2P_GRPCAP_INTRABSS)
769 733
770/* Value of Device Capability Bitmap */ 734/* Value of Device Capability Bitmap */
771#define P2P_DEVCAP_SERVICE_DISCOVERY BIT(0) 735#define P2P_DEVCAP_SERVICE_DISCOVERY BIT(0)
@@ -804,13 +768,8 @@ enum ht_cap_ampdu_factor {
804#define P2P_PRESENCE_RESPONSE 2 768#define P2P_PRESENCE_RESPONSE 2
805#define P2P_GO_DISC_REQUEST 3 769#define P2P_GO_DISC_REQUEST 3
806 770
807
808#define P2P_MAX_PERSISTENT_GROUP_NUM 10
809
810#define P2P_PROVISIONING_SCAN_CNT 3 771#define P2P_PROVISIONING_SCAN_CNT 3
811 772
812#define P2P_WILDCARD_SSID_LEN 7
813
814/* default value, used when: (1)p2p disabled or (2)p2p enabled 773/* default value, used when: (1)p2p disabled or (2)p2p enabled
815 * but only do 1 scan phase */ 774 * but only do 1 scan phase */
816#define P2P_FINDPHASE_EX_NONE 0 775#define P2P_FINDPHASE_EX_NONE 0
@@ -839,8 +798,6 @@ enum ht_cap_ampdu_factor {
839#define P2P_RESET_SCAN_CH 25000 798#define P2P_RESET_SCAN_CH 25000
840#define P2P_MAX_INTENT 15 799#define P2P_MAX_INTENT 15
841 800
842#define P2P_MAX_NOA_NUM 2
843
844/* WPS Configuration Method */ 801/* WPS Configuration Method */
845#define WPS_CM_NONE 0x0000 802#define WPS_CM_NONE 0x0000
846#define WPS_CM_LABEL 0x0004 803#define WPS_CM_LABEL 0x0004
@@ -855,64 +812,6 @@ enum ht_cap_ampdu_factor {
855#define WPS_CM_SW_DISPLAY_P 0x2008 812#define WPS_CM_SW_DISPLAY_P 0x2008
856#define WPS_CM_LCD_DISPLAY_P 0x4008 813#define WPS_CM_LCD_DISPLAY_P 0x4008
857 814
858enum P2P_ROLE {
859 P2P_ROLE_DISABLE = 0,
860 P2P_ROLE_DEVICE = 1,
861 P2P_ROLE_CLIENT = 2,
862 P2P_ROLE_GO = 3
863};
864
865enum P2P_STATE {
866 P2P_STATE_NONE = 0, /* P2P disable */
867 /* P2P had enabled and do nothing */
868 P2P_STATE_IDLE = 1,
869 P2P_STATE_LISTEN = 2, /* In pure listen state */
870 P2P_STATE_SCAN = 3, /* In scan phase */
871 /* In the listen state of find phase */
872 P2P_STATE_FIND_PHASE_LISTEN = 4,
873 /* In the search state of find phase */
874 P2P_STATE_FIND_PHASE_SEARCH = 5,
875 /* In P2P provisioning discovery */
876 P2P_STATE_TX_PROVISION_DIS_REQ = 6,
877 P2P_STATE_RX_PROVISION_DIS_RSP = 7,
878 P2P_STATE_RX_PROVISION_DIS_REQ = 8,
879 /* Doing the group owner negotiation handshake */
880 P2P_STATE_GONEGO_ING = 9,
881 /* finish the group negotiation handshake with success */
882 P2P_STATE_GONEGO_OK = 10,
883 /* finish the group negotiation handshake with failure */
884 P2P_STATE_GONEGO_FAIL = 11,
885 /* receiving the P2P Invitation request and match with the profile. */
886 P2P_STATE_RECV_INVITE_REQ_MATCH = 12,
887 /* Doing the P2P WPS */
888 P2P_STATE_PROVISIONING_ING = 13,
889 /* Finish the P2P WPS */
890 P2P_STATE_PROVISIONING_DONE = 14,
891 /* Transmit the P2P Invitation request */
892 P2P_STATE_TX_INVITE_REQ = 15,
893 /* Receiving the P2P Invitation response */
894 P2P_STATE_RX_INVITE_RESP_OK = 16,
895 /* receiving the P2P Invitation request and dismatch with the profile. */
896 P2P_STATE_RECV_INVITE_REQ_DISMATCH = 17,
897 /* receiving the P2P Invitation request and this wifi is GO. */
898 P2P_STATE_RECV_INVITE_REQ_GO = 18,
899 /* receiving the P2P Invitation request to join an existing P2P Group. */
900 P2P_STATE_RECV_INVITE_REQ_JOIN = 19,
901 /* receiving the P2P Invitation response with failure */
902 P2P_STATE_RX_INVITE_RESP_FAIL = 20,
903 /* receiving p2p negotiation response with information is not available */
904 P2P_STATE_RX_INFOR_NOREADY = 21,
905 /* sending p2p negotiation response with information is not available */
906 P2P_STATE_TX_INFOR_NOREADY = 22,
907};
908
909enum P2P_WPSINFO {
910 P2P_NO_WPSINFO = 0,
911 P2P_GOT_WPSINFO_PEER_DISPLAY_PIN = 1,
912 P2P_GOT_WPSINFO_SELF_DISPLAY_PIN = 2,
913 P2P_GOT_WPSINFO_PBC = 3,
914};
915
916#define P2P_PRIVATE_IOCTL_SET_LEN 64 815#define P2P_PRIVATE_IOCTL_SET_LEN 64
917 816
918enum P2P_PROTO_WK_ID { 817enum P2P_PROTO_WK_ID {
@@ -925,21 +824,6 @@ enum P2P_PROTO_WK_ID {
925 P2P_RO_CH_WK = 6, 824 P2P_RO_CH_WK = 6,
926}; 825};
927 826
928enum P2P_PS_STATE {
929 P2P_PS_DISABLE = 0,
930 P2P_PS_ENABLE = 1,
931 P2P_PS_SCAN = 2,
932 P2P_PS_SCAN_DONE = 3,
933 P2P_PS_ALLSTASLEEP = 4, /* for P2P GO */
934};
935
936enum P2P_PS_MODE {
937 P2P_PS_NONE = 0,
938 P2P_PS_CTWINDOW = 1,
939 P2P_PS_NOA = 2,
940 P2P_PS_MIX = 3, /* CTWindow and NoA */
941};
942
943/* =====================WFD Section===================== */ 827/* =====================WFD Section===================== */
944/* For Wi-Fi Display */ 828/* For Wi-Fi Display */
945#define WFD_ATTR_DEVICE_INFO 0x00 829#define WFD_ATTR_DEVICE_INFO 0x00
diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
index 4de9dbc93380..763eccd0c7c9 100644
--- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
@@ -134,6 +134,7 @@ static char *translate_scan(struct adapter *padapter,
134 if (p && ht_ielen > 0) { 134 if (p && ht_ielen > 0) {
135 struct ieee80211_ht_cap *pht_capie; 135 struct ieee80211_ht_cap *pht_capie;
136 ht_cap = true; 136 ht_cap = true;
137
137 pht_capie = (struct ieee80211_ht_cap *)(p + 2); 138 pht_capie = (struct ieee80211_ht_cap *)(p + 2);
138 memcpy(&mcs_rate, pht_capie->mcs.rx_mask, 2); 139 memcpy(&mcs_rate, pht_capie->mcs.rx_mask, 2);
139 bw_40MHz = !!(le16_to_cpu(pht_capie->cap_info) & 140 bw_40MHz = !!(le16_to_cpu(pht_capie->cap_info) &
@@ -285,8 +286,8 @@ static char *translate_scan(struct adapter *padapter,
285 uint cnt = 0, total_ielen; 286 uint cnt = 0, total_ielen;
286 u8 *wpsie_ptr = NULL; 287 u8 *wpsie_ptr = NULL;
287 uint wps_ielen = 0; 288 uint wps_ielen = 0;
288
289 u8 *ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_; 289 u8 *ie_ptr = pnetwork->network.IEs + _FIXED_IE_LENGTH_;
290
290 total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_; 291 total_ielen = pnetwork->network.IELength - _FIXED_IE_LENGTH_;
291 292
292 while (cnt < total_ielen) { 293 while (cnt < total_ielen) {
@@ -442,7 +443,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
442 struct sta_info *psta, *pbcmc_sta; 443 struct sta_info *psta, *pbcmc_sta;
443 struct sta_priv *pstapriv = &padapter->stapriv; 444 struct sta_priv *pstapriv = &padapter->stapriv;
444 445
445 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE | WIFI_MP_STATE)) { /* sta mode */ 446 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) { /* sta mode */
446 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv)); 447 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
447 if (!psta) { 448 if (!psta) {
448 ; 449 ;
@@ -523,6 +524,7 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie
523 /* dump */ 524 /* dump */
524 { 525 {
525 int i; 526 int i;
527
526 DBG_88E("\n wpa_ie(length:%d):\n", ielen); 528 DBG_88E("\n wpa_ie(length:%d):\n", ielen);
527 for (i = 0; i < ielen; i += 8) 529 for (i = 0; i < ielen; i += 8)
528 DBG_88E("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4], buf[i+5], buf[i+6], buf[i+7]); 530 DBG_88E("0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", buf[i], buf[i+1], buf[i+2], buf[i+3], buf[i+4], buf[i+5], buf[i+6], buf[i+7]);
@@ -1084,14 +1086,9 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
1084 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 1086 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1085 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1087 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1086 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT]; 1088 struct ndis_802_11_ssid ssid[RTW_SSID_SCAN_AMOUNT];
1089
1087 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_set_scan\n")); 1090 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_set_scan\n"));
1088 1091
1089 if (padapter->registrypriv.mp_mode == 1) {
1090 if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) {
1091 ret = -1;
1092 goto exit;
1093 }
1094 }
1095 if (_FAIL == rtw_pwr_wakeup(padapter)) { 1092 if (_FAIL == rtw_pwr_wakeup(padapter)) {
1096 ret = -1; 1093 ret = -1;
1097 goto exit; 1094 goto exit;
@@ -1225,6 +1222,7 @@ static int rtw_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
1225 u32 cnt = 0; 1222 u32 cnt = 0;
1226 u32 wait_for_surveydone; 1223 u32 wait_for_surveydone;
1227 int wait_status; 1224 int wait_status;
1225
1228 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan\n")); 1226 RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan\n"));
1229 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, (" Start of Query SIOCGIWSCAN .\n")); 1227 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, (" Start of Query SIOCGIWSCAN .\n"));
1230 1228
@@ -1613,6 +1611,7 @@ static int rtw_wx_set_enc(struct net_device *dev,
1613 struct iw_point *erq = &(wrqu->encoding); 1611 struct iw_point *erq = &(wrqu->encoding);
1614 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 1612 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
1615 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; 1613 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
1614
1616 DBG_88E("+rtw_wx_set_enc, flags = 0x%x\n", erq->flags); 1615 DBG_88E("+rtw_wx_set_enc, flags = 0x%x\n", erq->flags);
1617 1616
1618 memset(&wep, 0, sizeof(struct ndis_802_11_wep)); 1617 memset(&wep, 0, sizeof(struct ndis_802_11_wep));
diff --git a/drivers/staging/rtl8188eu/os_dep/mon.c b/drivers/staging/rtl8188eu/os_dep/mon.c
index c9c9821cfc32..cfe37eb026d6 100644
--- a/drivers/staging/rtl8188eu/os_dep/mon.c
+++ b/drivers/staging/rtl8188eu/os_dep/mon.c
@@ -92,8 +92,8 @@ void rtl88eu_mon_recv_hook(struct net_device *dev, struct recv_frame *frame)
92 return; 92 return;
93 93
94 attr = &frame->attrib; 94 attr = &frame->attrib;
95 data = frame->rx_data; 95 data = frame->pkt->data;
96 data_len = frame->len; 96 data_len = frame->pkt->len;
97 97
98 /* Broadcast and multicast frames don't have attr->{iv,icv}_len set */ 98 /* Broadcast and multicast frames don't have attr->{iv,icv}_len set */
99 SET_ICE_IV_LEN(iv_len, icv_len, attr->encrypt); 99 SET_ICE_IV_LEN(iv_len, icv_len, attr->encrypt);
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index 8fc3fadf065f..5f6a24546a91 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -413,7 +413,6 @@ static u8 rtw_init_default_value(struct adapter *padapter)
413 /* misc. */ 413 /* misc. */
414 padapter->bReadPortCancel = false; 414 padapter->bReadPortCancel = false;
415 padapter->bWritePortCancel = false; 415 padapter->bWritePortCancel = false;
416 padapter->bRxRSSIDisplay = 0;
417 return _SUCCESS; 416 return _SUCCESS;
418} 417}
419 418
@@ -426,7 +425,6 @@ u8 rtw_reset_drv_sw(struct adapter *padapter)
426 rtw_hal_def_value_init(padapter); 425 rtw_hal_def_value_init(padapter);
427 padapter->bReadPortCancel = false; 426 padapter->bReadPortCancel = false;
428 padapter->bWritePortCancel = false; 427 padapter->bWritePortCancel = false;
429 padapter->bRxRSSIDisplay = 0;
430 pmlmepriv->scan_interval = SCAN_INTERVAL;/* 30*2 sec = 60sec */ 428 pmlmepriv->scan_interval = SCAN_INTERVAL;/* 30*2 sec = 60sec */
431 429
432 padapter->xmitpriv.tx_pkts = 0; 430 padapter->xmitpriv.tx_pkts = 0;
diff --git a/drivers/staging/rtl8188eu/os_dep/osdep_service.c b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
index 6ff836f481da..3be87252fd62 100644
--- a/drivers/staging/rtl8188eu/os_dep/osdep_service.c
+++ b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
@@ -21,18 +21,6 @@
21#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
22#include <rtw_ioctl_set.h> 22#include <rtw_ioctl_set.h>
23 23
24/*
25 * Translate the OS dependent @param error_code to OS independent
26 * RTW_STATUS_CODE
27 * @return: one of RTW_STATUS_CODE
28 */
29inline int RTW_STATUS_CODE(int error_code)
30{
31 if (error_code >= 0)
32 return _SUCCESS;
33 return _FAIL;
34}
35
36u8 *_rtw_malloc(u32 sz) 24u8 *_rtw_malloc(u32 sz)
37{ 25{
38 return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); 26 return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
@@ -41,8 +29,8 @@ u8 *_rtw_malloc(u32 sz)
41void *rtw_malloc2d(int h, int w, int size) 29void *rtw_malloc2d(int h, int w, int size)
42{ 30{
43 int j; 31 int j;
44
45 void **a = kzalloc(h * sizeof(void *) + h * w * size, GFP_KERNEL); 32 void **a = kzalloc(h * sizeof(void *) + h * w * size, GFP_KERNEL);
33
46 if (!a) 34 if (!a)
47 goto out; 35 goto out;
48 36
diff --git a/drivers/staging/rtl8188eu/os_dep/recv_linux.c b/drivers/staging/rtl8188eu/os_dep/recv_linux.c
index b85824ec5354..d14bc2b68d98 100644
--- a/drivers/staging/rtl8188eu/os_dep/recv_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/recv_linux.c
@@ -88,27 +88,6 @@ int rtw_recv_indicatepkt(struct adapter *padapter,
88 goto _recv_indicatepkt_drop; 88 goto _recv_indicatepkt_drop;
89 } 89 }
90 90
91 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
92 ("rtw_recv_indicatepkt():skb != NULL !!!\n"));
93 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
94 ("rtw_recv_indicatepkt():precv_frame->rx_head =%p precv_frame->hdr.rx_data =%p\n",
95 precv_frame->rx_head, precv_frame->rx_data));
96 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
97 ("precv_frame->hdr.rx_tail =%p precv_frame->rx_end =%p precv_frame->hdr.len =%d\n",
98 precv_frame->rx_tail, precv_frame->rx_end,
99 precv_frame->len));
100
101 skb->data = precv_frame->rx_data;
102
103 skb_set_tail_pointer(skb, precv_frame->len);
104
105 skb->len = precv_frame->len;
106
107 RT_TRACE(_module_recv_osdep_c_, _drv_info_,
108 ("skb->head =%p skb->data =%p skb->tail =%p skb->end =%p skb->len =%d\n",
109 skb->head, skb->data, skb_tail_pointer(skb),
110 skb_end_pointer(skb), skb->len));
111
112 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) { 91 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
113 struct sk_buff *pskb2 = NULL; 92 struct sk_buff *pskb2 = NULL;
114 struct sta_info *psta = NULL; 93 struct sta_info *psta = NULL;
diff --git a/drivers/staging/rtl8188eu/os_dep/rtw_android.c b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
index 41e1b1d15b81..336e7023f7f7 100644
--- a/drivers/staging/rtl8188eu/os_dep/rtw_android.c
+++ b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
@@ -73,6 +73,7 @@ static int g_wifi_on = true;
73int rtw_android_cmdstr_to_num(char *cmdstr) 73int rtw_android_cmdstr_to_num(char *cmdstr)
74{ 74{
75 int cmd_num; 75 int cmd_num;
76
76 for (cmd_num = 0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++) 77 for (cmd_num = 0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
77 if (0 == strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num], 78 if (0 == strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num],
78 strlen(android_wifi_cmd_str[cmd_num]))) 79 strlen(android_wifi_cmd_str[cmd_num])))
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index c6316ffa64d3..963235fd7292 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -83,6 +83,7 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
83 83
84 for (i = 0; i < piface_desc->bNumEndpoints; i++) { 84 for (i = 0; i < piface_desc->bNumEndpoints; i++) {
85 int ep_num; 85 int ep_num;
86
86 pendp_desc = &phost_iface->endpoint[i].desc; 87 pendp_desc = &phost_iface->endpoint[i].desc;
87 88
88 ep_num = usb_endpoint_num(pendp_desc); 89 ep_num = usb_endpoint_num(pendp_desc);
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index e2dbe1b4afd3..64397b6f1248 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -73,7 +73,6 @@ static int recvbuf2recvframe(struct adapter *adapt, struct sk_buff *pskb)
73 } 73 }
74 74
75 INIT_LIST_HEAD(&precvframe->list); 75 INIT_LIST_HEAD(&precvframe->list);
76 precvframe->len = 0;
77 76
78 update_recvframe_attrib_88e(precvframe, prxstat); 77 update_recvframe_attrib_88e(precvframe, prxstat);
79 78
@@ -125,34 +124,16 @@ static int recvbuf2recvframe(struct adapter *adapt, struct sk_buff *pskb)
125 if (pkt_copy) { 124 if (pkt_copy) {
126 pkt_copy->dev = adapt->pnetdev; 125 pkt_copy->dev = adapt->pnetdev;
127 precvframe->pkt = pkt_copy; 126 precvframe->pkt = pkt_copy;
128 precvframe->rx_head = pkt_copy->data;
129 precvframe->rx_end = pkt_copy->data + alloc_sz;
130 skb_reserve(pkt_copy, 8 - ((size_t)(pkt_copy->data) & 7));/* force pkt_copy->data at 8-byte alignment address */ 127 skb_reserve(pkt_copy, 8 - ((size_t)(pkt_copy->data) & 7));/* force pkt_copy->data at 8-byte alignment address */
131 skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */ 128 skb_reserve(pkt_copy, shift_sz);/* force ip_hdr at 8-byte alignment address according to shift_sz. */
132 memcpy(pkt_copy->data, (pbuf + pattrib->drvinfo_sz + RXDESC_SIZE), skb_len); 129 memcpy(pkt_copy->data, (pbuf + pattrib->drvinfo_sz + RXDESC_SIZE), skb_len);
133 precvframe->rx_tail = pkt_copy->data; 130 skb_put(precvframe->pkt, skb_len);
134 precvframe->rx_data = pkt_copy->data;
135 } else { 131 } else {
136 if ((pattrib->mfrag == 1) && (pattrib->frag_num == 0)) { 132 DBG_88E("recvbuf2recvframe: alloc_skb fail , drop frag frame\n");
137 DBG_88E("recvbuf2recvframe: alloc_skb fail , drop frag frame\n"); 133 rtw_free_recvframe(precvframe, pfree_recv_queue);
138 rtw_free_recvframe(precvframe, pfree_recv_queue); 134 goto _exit_recvbuf2recvframe;
139 goto _exit_recvbuf2recvframe;
140 }
141 precvframe->pkt = skb_clone(pskb, GFP_ATOMIC);
142 if (precvframe->pkt) {
143 precvframe->rx_tail = pbuf + pattrib->drvinfo_sz + RXDESC_SIZE;
144 precvframe->rx_head = precvframe->rx_tail;
145 precvframe->rx_data = precvframe->rx_tail;
146 precvframe->rx_end = pbuf + pattrib->drvinfo_sz + RXDESC_SIZE + alloc_sz;
147 } else {
148 DBG_88E("recvbuf2recvframe: skb_clone fail\n");
149 rtw_free_recvframe(precvframe, pfree_recv_queue);
150 goto _exit_recvbuf2recvframe;
151 }
152 } 135 }
153 136
154 recvframe_put(precvframe, skb_len);
155
156 switch (haldata->UsbRxAggMode) { 137 switch (haldata->UsbRxAggMode) {
157 case USB_RX_AGG_DMA: 138 case USB_RX_AGG_DMA:
158 case USB_RX_AGG_MIX: 139 case USB_RX_AGG_MIX:
@@ -174,19 +155,19 @@ static int recvbuf2recvframe(struct adapter *adapt, struct sk_buff *pskb)
174 } 155 }
175 } else if (pattrib->pkt_rpt_type == TX_REPORT1) { 156 } else if (pattrib->pkt_rpt_type == TX_REPORT1) {
176 /* CCX-TXRPT ack for xmit mgmt frames. */ 157 /* CCX-TXRPT ack for xmit mgmt frames. */
177 handle_txrpt_ccx_88e(adapt, precvframe->rx_data); 158 handle_txrpt_ccx_88e(adapt, precvframe->pkt->data);
178 rtw_free_recvframe(precvframe, pfree_recv_queue); 159 rtw_free_recvframe(precvframe, pfree_recv_queue);
179 } else if (pattrib->pkt_rpt_type == TX_REPORT2) { 160 } else if (pattrib->pkt_rpt_type == TX_REPORT2) {
180 ODM_RA_TxRPT2Handle_8188E( 161 ODM_RA_TxRPT2Handle_8188E(
181 &haldata->odmpriv, 162 &haldata->odmpriv,
182 precvframe->rx_data, 163 precvframe->pkt->data,
183 pattrib->pkt_len, 164 pattrib->pkt_len,
184 pattrib->MacIDValidEntry[0], 165 pattrib->MacIDValidEntry[0],
185 pattrib->MacIDValidEntry[1] 166 pattrib->MacIDValidEntry[1]
186 ); 167 );
187 rtw_free_recvframe(precvframe, pfree_recv_queue); 168 rtw_free_recvframe(precvframe, pfree_recv_queue);
188 } else if (pattrib->pkt_rpt_type == HIS_REPORT) { 169 } else if (pattrib->pkt_rpt_type == HIS_REPORT) {
189 interrupt_handler_8188eu(adapt, pattrib->pkt_len, precvframe->rx_data); 170 interrupt_handler_8188eu(adapt, pattrib->pkt_len, precvframe->pkt->data);
190 rtw_free_recvframe(precvframe, pfree_recv_queue); 171 rtw_free_recvframe(precvframe, pfree_recv_queue);
191 } 172 }
192 pkt_cnt--; 173 pkt_cnt--;
@@ -471,7 +452,7 @@ u32 usb_read_port(struct adapter *adapter, u32 addr, struct recv_buf *precvbuf)
471 452
472 if ((!precvbuf->reuse) || (precvbuf->pskb == NULL)) { 453 if ((!precvbuf->reuse) || (precvbuf->pskb == NULL)) {
473 precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue); 454 precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue);
474 if (NULL != precvbuf->pskb) 455 if (precvbuf->pskb != NULL)
475 precvbuf->reuse = true; 456 precvbuf->reuse = true;
476 } 457 }
477 458
diff --git a/drivers/staging/rtl8192e/dot11d.h b/drivers/staging/rtl8192e/dot11d.h
index aac395f26652..623075cf0c05 100644
--- a/drivers/staging/rtl8192e/dot11d.h
+++ b/drivers/staging/rtl8192e/dot11d.h
@@ -11,7 +11,7 @@
11 * 11 *
12 * Contact Information: 12 * Contact Information:
13 * wlanfae <wlanfae@realtek.com> 13 * wlanfae <wlanfae@realtek.com>
14******************************************************************************/ 14 ******************************************************************************/
15#ifndef __INC_DOT11D_H 15#ifndef __INC_DOT11D_H
16#define __INC_DOT11D_H 16#define __INC_DOT11D_H
17 17
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 8a9172aa8178..4c0caa6701a9 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -2695,10 +2695,8 @@ static void _rtl92e_pci_disconnect(struct pci_dev *pdev)
2695 priv->polling_timer_on = 0; 2695 priv->polling_timer_on = 0;
2696 _rtl92e_down(dev, true); 2696 _rtl92e_down(dev, true);
2697 rtl92e_dm_deinit(dev); 2697 rtl92e_dm_deinit(dev);
2698 if (priv->pFirmware) { 2698 vfree(priv->pFirmware);
2699 vfree(priv->pFirmware); 2699 priv->pFirmware = NULL;
2700 priv->pFirmware = NULL;
2701 }
2702 _rtl92e_free_rx_ring(dev); 2700 _rtl92e_free_rx_ring(dev);
2703 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) 2701 for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
2704 _rtl92e_free_tx_ring(dev, i); 2702 _rtl92e_free_tx_ring(dev, i);
@@ -2797,9 +2795,9 @@ MODULE_FIRMWARE(RTL8192E_BOOT_IMG_FW);
2797MODULE_FIRMWARE(RTL8192E_MAIN_IMG_FW); 2795MODULE_FIRMWARE(RTL8192E_MAIN_IMG_FW);
2798MODULE_FIRMWARE(RTL8192E_DATA_IMG_FW); 2796MODULE_FIRMWARE(RTL8192E_DATA_IMG_FW);
2799 2797
2800module_param(ifname, charp, S_IRUGO|S_IWUSR); 2798module_param(ifname, charp, 0644);
2801module_param(hwwep, int, S_IRUGO|S_IWUSR); 2799module_param(hwwep, int, 0644);
2802module_param(channels, int, S_IRUGO|S_IWUSR); 2800module_param(channels, int, 0644);
2803 2801
2804MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default"); 2802MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default");
2805MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)"); 2803MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)");
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index 1430ba27b049..eeda17d6409b 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -3365,23 +3365,21 @@ static int rtllib_wpa_set_encryption(struct rtllib_device *ieee,
3365 } else 3365 } else
3366 sec.flags &= ~SEC_ACTIVE_KEY; 3366 sec.flags &= ~SEC_ACTIVE_KEY;
3367 3367
3368 if (param->u.crypt.alg != NULL) { 3368 memcpy(sec.keys[param->u.crypt.idx],
3369 memcpy(sec.keys[param->u.crypt.idx], 3369 param->u.crypt.key,
3370 param->u.crypt.key, 3370 param->u.crypt.key_len);
3371 param->u.crypt.key_len); 3371 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3372 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len; 3372 sec.flags |= (1 << param->u.crypt.idx);
3373 sec.flags |= (1 << param->u.crypt.idx); 3373
3374 3374 if (strcmp(param->u.crypt.alg, "R-WEP") == 0) {
3375 if (strcmp(param->u.crypt.alg, "R-WEP") == 0) { 3375 sec.flags |= SEC_LEVEL;
3376 sec.flags |= SEC_LEVEL; 3376 sec.level = SEC_LEVEL_1;
3377 sec.level = SEC_LEVEL_1; 3377 } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) {
3378 } else if (strcmp(param->u.crypt.alg, "R-TKIP") == 0) { 3378 sec.flags |= SEC_LEVEL;
3379 sec.flags |= SEC_LEVEL; 3379 sec.level = SEC_LEVEL_2;
3380 sec.level = SEC_LEVEL_2; 3380 } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) {
3381 } else if (strcmp(param->u.crypt.alg, "R-CCMP") == 0) { 3381 sec.flags |= SEC_LEVEL;
3382 sec.flags |= SEC_LEVEL; 3382 sec.level = SEC_LEVEL_3;
3383 sec.level = SEC_LEVEL_3;
3384 }
3385 } 3383 }
3386 done: 3384 done:
3387 if (ieee->set_security) 3385 if (ieee->set_security)
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index 077ea13eb1e7..0d247058bce4 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -83,7 +83,7 @@
83#define SUPPORT_CKIP_PK 0x10 // bit4 83#define SUPPORT_CKIP_PK 0x10 // bit4
84/* defined for skb cb field */ 84/* defined for skb cb field */
85/* At most 28 byte */ 85/* At most 28 byte */
86typedef struct cb_desc { 86struct cb_desc {
87 /* Tx Desc Related flags (8-9) */ 87 /* Tx Desc Related flags (8-9) */
88 u8 bLastIniPkt:1; 88 u8 bLastIniPkt:1;
89 u8 bCmdOrInit:1; 89 u8 bCmdOrInit:1;
@@ -139,7 +139,7 @@ typedef struct cb_desc {
139 u8 DrvAggrNum; 139 u8 DrvAggrNum;
140 u16 pkt_size; 140 u16 pkt_size;
141 u8 reserved12; 141 u8 reserved12;
142}cb_desc, *pcb_desc; 142};
143 143
144/*--------------------------Define -------------------------------------------*/ 144/*--------------------------Define -------------------------------------------*/
145#define MGN_1M 0x02 145#define MGN_1M 0x02
@@ -329,12 +329,13 @@ typedef struct ieee_param {
329// linux under 2.6.9 release may not support it, so modify it for common use 329// linux under 2.6.9 release may not support it, so modify it for common use
330#define IEEE80211_DATA_LEN 2304 330#define IEEE80211_DATA_LEN 2304
331/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section 331/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
332 6.2.1.1.2. 332 * 6.2.1.1.2.
333 333 *
334 The figure in section 7.1.2 suggests a body size of up to 2312 334 * The figure in section 7.1.2 suggests a body size of up to 2312
335 bytes is allowed, which is a bit confusing, I suspect this 335 * bytes is allowed, which is a bit confusing, I suspect this
336 represents the 2304 bytes of real data, plus a possible 8 bytes of 336 * represents the 2304 bytes of real data, plus a possible 8 bytes of
337 WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */ 337 * WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro)
338 */
338#define IEEE80211_1ADDR_LEN 10 339#define IEEE80211_1ADDR_LEN 10
339#define IEEE80211_2ADDR_LEN 16 340#define IEEE80211_2ADDR_LEN 16
340#define IEEE80211_3ADDR_LEN 24 341#define IEEE80211_3ADDR_LEN 24
@@ -685,7 +686,8 @@ struct ieee_ibss_seq {
685 686
686/* NOTE: This data is for statistical purposes; not all hardware provides this 687/* NOTE: This data is for statistical purposes; not all hardware provides this
687 * information for frames received. Not setting these will not cause 688 * information for frames received. Not setting these will not cause
688 * any adverse affects. */ 689 * any adverse affects.
690 */
689struct ieee80211_rx_stats { 691struct ieee80211_rx_stats {
690 u32 mac_time[2]; 692 u32 mac_time[2];
691 s8 rssi; 693 s8 rssi;
@@ -754,7 +756,8 @@ struct ieee80211_rx_stats {
754/* IEEE 802.11 requires that STA supports concurrent reception of at least 756/* IEEE 802.11 requires that STA supports concurrent reception of at least
755 * three fragmented frames. This define can be increased to support more 757 * three fragmented frames. This define can be increased to support more
756 * concurrent frames, but it should be noted that each entry can consume about 758 * concurrent frames, but it should be noted that each entry can consume about
757 * 2 kB of RAM and increasing cache size will slow down frame reassembly. */ 759 * 2 kB of RAM and increasing cache size will slow down frame reassembly.
760 */
758#define IEEE80211_FRAG_CACHE_LEN 4 761#define IEEE80211_FRAG_CACHE_LEN 4
759 762
760struct ieee80211_frag_entry { 763struct ieee80211_frag_entry {
@@ -836,15 +839,15 @@ struct ieee80211_security {
836 839
837 840
838/* 841/*
839 802.11 data frame from AP 842 * 802.11 data frame from AP
840 ,-------------------------------------------------------------------. 843 * ,-------------------------------------------------------------------.
841Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 | 844 * Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
842 |------|------|---------|---------|---------|------|---------|------| 845 * |------|------|---------|---------|---------|------|---------|------|
843Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs | 846 * Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | frame | fcs |
844 | | tion | (BSSID) | | | ence | data | | 847 * | | tion | (BSSID) | | | ence | data | |
845 `-------------------------------------------------------------------' 848 * `-------------------------------------------------------------------'
846Total: 28-2340 bytes 849 * Total: 28-2340 bytes
847*/ 850 */
848 851
849/* Management Frame Information Element Types */ 852/* Management Frame Information Element Types */
850enum ieee80211_mfie { 853enum ieee80211_mfie {
@@ -882,7 +885,8 @@ enum ieee80211_mfie {
882 885
883/* Minimal header; can be used for passing 802.11 frames with sufficient 886/* Minimal header; can be used for passing 802.11 frames with sufficient
884 * information to determine what type of underlying data type is actually 887 * information to determine what type of underlying data type is actually
885 * stored in the data. */ 888 * stored in the data.
889 */
886struct rtl_80211_hdr { 890struct rtl_80211_hdr {
887 __le16 frame_ctl; 891 __le16 frame_ctl;
888 __le16 duration_id; 892 __le16 duration_id;
@@ -980,7 +984,8 @@ struct ieee80211_probe_response {
980 __le16 beacon_interval; 984 __le16 beacon_interval;
981 __le16 capability; 985 __le16 capability;
982 /* SSID, supported rates, FH params, DS params, 986 /* SSID, supported rates, FH params, DS params,
983 * CF params, IBSS params, TIM (if beacon), RSN */ 987 * CF params, IBSS params, TIM (if beacon), RSN
988 */
984 struct ieee80211_info_element info_element[0]; 989 struct ieee80211_info_element info_element[0];
985} __packed; 990} __packed;
986 991
@@ -1055,7 +1060,8 @@ typedef union _frameqos {
1055/* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs 1060/* MAX_RATES_LENGTH needs to be 12. The spec says 8, and many APs
1056 * only use 8, and then use extended rates for the remaining supported 1061 * only use 8, and then use extended rates for the remaining supported
1057 * rates. Other APs, however, stick all of their supported rates on the 1062 * rates. Other APs, however, stick all of their supported rates on the
1058 * main rates information element... */ 1063 * main rates information element...
1064 */
1059#define MAX_RATES_LENGTH ((u8)12) 1065#define MAX_RATES_LENGTH ((u8)12)
1060#define MAX_RATES_EX_LENGTH ((u8)16) 1066#define MAX_RATES_EX_LENGTH ((u8)16)
1061#define MAX_NETWORK_COUNT 128 1067#define MAX_NETWORK_COUNT 128
@@ -1677,14 +1683,16 @@ struct ieee80211_device {
1677 spinlock_t wpax_suitlist_lock; 1683 spinlock_t wpax_suitlist_lock;
1678 1684
1679 int tx_headroom; /* Set to size of any additional room needed at front 1685 int tx_headroom; /* Set to size of any additional room needed at front
1680 * of allocated Tx SKBs */ 1686 * of allocated Tx SKBs
1687 */
1681 u32 config; 1688 u32 config;
1682 1689
1683 /* WEP and other encryption related settings at the device level */ 1690 /* WEP and other encryption related settings at the device level */
1684 int open_wep; /* Set to 1 to allow unencrypted frames */ 1691 int open_wep; /* Set to 1 to allow unencrypted frames */
1685 int auth_mode; 1692 int auth_mode;
1686 int reset_on_keychange; /* Set to 1 if the HW needs to be reset on 1693 int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1687 * WEP key changes */ 1694 * WEP key changes
1695 */
1688 1696
1689 /* If the host performs {en,de}cryption, then set to 1 */ 1697 /* If the host performs {en,de}cryption, then set to 1 */
1690 int host_encrypt; 1698 int host_encrypt;
@@ -1719,7 +1727,8 @@ struct ieee80211_device {
1719 int crypt_quiesced; 1727 int crypt_quiesced;
1720 1728
1721 int bcrx_sta_key; /* use individual keys to override default keys even 1729 int bcrx_sta_key; /* use individual keys to override default keys even
1722 * with RX of broad/multicast frames */ 1730 * with RX of broad/multicast frames
1731 */
1723 1732
1724 /* Fragmentation structures */ 1733 /* Fragmentation structures */
1725 // each streaming contain a entry 1734 // each streaming contain a entry
@@ -1894,6 +1903,7 @@ struct ieee80211_device {
1894 //u32 STA_EDCA_PARAM[4]; 1903 //u32 STA_EDCA_PARAM[4];
1895 //CHANNEL_ACCESS_SETTING ChannelAccessSetting; 1904 //CHANNEL_ACCESS_SETTING ChannelAccessSetting;
1896 1905
1906 struct ieee80211_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
1897 1907
1898 /* Callback functions */ 1908 /* Callback functions */
1899 void (*set_security)(struct net_device *dev, 1909 void (*set_security)(struct net_device *dev,
@@ -2003,7 +2013,8 @@ struct ieee80211_device {
2003 void (*InitialGainHandler)(struct net_device *dev, u8 Operation); 2013 void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
2004 2014
2005 /* This must be the last item so that it points to the data 2015 /* This must be the last item so that it points to the data
2006 * allocated beyond this structure by alloc_ieee80211 */ 2016 * allocated beyond this structure by alloc_ieee80211
2017 */
2007 u8 priv[0]; 2018 u8 priv[0];
2008}; 2019};
2009 2020
@@ -2032,7 +2043,8 @@ struct ieee80211_device {
2032 2043
2033/* The ieee802.11 stack will manages the netif queue 2044/* The ieee802.11 stack will manages the netif queue
2034 * wake/stop for the driver, taking care of 802.11 2045 * wake/stop for the driver, taking care of 802.11
2035 * fragmentation. See softmac.c for details. */ 2046 * fragmentation. See softmac.c for details.
2047 */
2036#define IEEE_SOFTMAC_TX_QUEUE (1<<7) 2048#define IEEE_SOFTMAC_TX_QUEUE (1<<7)
2037 2049
2038/* Uses only the softmac_data_hard_start_xmit 2050/* Uses only the softmac_data_hard_start_xmit
@@ -2255,7 +2267,6 @@ void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee);
2255 2267
2256/* ieee80211_crypt_ccmp&tkip&wep.c */ 2268/* ieee80211_crypt_ccmp&tkip&wep.c */
2257void ieee80211_tkip_null(void); 2269void ieee80211_tkip_null(void);
2258void ieee80211_ccmp_null(void);
2259 2270
2260int ieee80211_crypto_init(void); 2271int ieee80211_crypto_init(void);
2261void ieee80211_crypto_deinit(void); 2272void ieee80211_crypto_deinit(void);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c
index 9cf90d040cfe..48e80be90ba5 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.c
@@ -80,7 +80,7 @@ void ieee80211_crypt_delayed_deinit(struct ieee80211_device *ieee,
80 struct ieee80211_crypt_data *tmp; 80 struct ieee80211_crypt_data *tmp;
81 unsigned long flags; 81 unsigned long flags;
82 82
83 if (*crypt == NULL) 83 if (!(*crypt))
84 return; 84 return;
85 85
86 tmp = *crypt; 86 tmp = *crypt;
@@ -88,7 +88,8 @@ void ieee80211_crypt_delayed_deinit(struct ieee80211_device *ieee,
88 88
89 /* must not run ops->deinit() while there may be pending encrypt or 89 /* must not run ops->deinit() while there may be pending encrypt or
90 * decrypt operations. Use a list of delayed deinits to avoid needing 90 * decrypt operations. Use a list of delayed deinits to avoid needing
91 * locking. */ 91 * locking.
92 */
92 93
93 spin_lock_irqsave(&ieee->lock, flags); 94 spin_lock_irqsave(&ieee->lock, flags);
94 list_add(&tmp->list, &ieee->crypt_deinit_list); 95 list_add(&tmp->list, &ieee->crypt_deinit_list);
@@ -104,11 +105,11 @@ int ieee80211_register_crypto_ops(struct ieee80211_crypto_ops *ops)
104 unsigned long flags; 105 unsigned long flags;
105 struct ieee80211_crypto_alg *alg; 106 struct ieee80211_crypto_alg *alg;
106 107
107 if (hcrypt == NULL) 108 if (!hcrypt)
108 return -1; 109 return -1;
109 110
110 alg = kzalloc(sizeof(*alg), GFP_KERNEL); 111 alg = kzalloc(sizeof(*alg), GFP_KERNEL);
111 if (alg == NULL) 112 if (!alg)
112 return -ENOMEM; 113 return -ENOMEM;
113 114
114 alg->ops = ops; 115 alg->ops = ops;
@@ -129,13 +130,13 @@ int ieee80211_unregister_crypto_ops(struct ieee80211_crypto_ops *ops)
129 struct list_head *ptr; 130 struct list_head *ptr;
130 struct ieee80211_crypto_alg *del_alg = NULL; 131 struct ieee80211_crypto_alg *del_alg = NULL;
131 132
132 if (hcrypt == NULL) 133 if (!hcrypt)
133 return -1; 134 return -1;
134 135
135 spin_lock_irqsave(&hcrypt->lock, flags); 136 spin_lock_irqsave(&hcrypt->lock, flags);
136 for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) { 137 for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) {
137 struct ieee80211_crypto_alg *alg = 138 struct ieee80211_crypto_alg *alg =
138 (struct ieee80211_crypto_alg *) ptr; 139 (struct ieee80211_crypto_alg *)ptr;
139 if (alg->ops == ops) { 140 if (alg->ops == ops) {
140 list_del(&alg->list); 141 list_del(&alg->list);
141 del_alg = alg; 142 del_alg = alg;
@@ -160,13 +161,13 @@ struct ieee80211_crypto_ops *ieee80211_get_crypto_ops(const char *name)
160 struct list_head *ptr; 161 struct list_head *ptr;
161 struct ieee80211_crypto_alg *found_alg = NULL; 162 struct ieee80211_crypto_alg *found_alg = NULL;
162 163
163 if (hcrypt == NULL) 164 if (!hcrypt)
164 return NULL; 165 return NULL;
165 166
166 spin_lock_irqsave(&hcrypt->lock, flags); 167 spin_lock_irqsave(&hcrypt->lock, flags);
167 for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) { 168 for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) {
168 struct ieee80211_crypto_alg *alg = 169 struct ieee80211_crypto_alg *alg =
169 (struct ieee80211_crypto_alg *) ptr; 170 (struct ieee80211_crypto_alg *)ptr;
170 if (strcmp(alg->ops->name, name) == 0) { 171 if (strcmp(alg->ops->name, name) == 0) {
171 found_alg = alg; 172 found_alg = alg;
172 break; 173 break;
@@ -222,13 +223,13 @@ void __exit ieee80211_crypto_deinit(void)
222{ 223{
223 struct list_head *ptr, *n; 224 struct list_head *ptr, *n;
224 225
225 if (hcrypt == NULL) 226 if (!hcrypt)
226 return; 227 return;
227 228
228 for (ptr = hcrypt->algs.next, n = ptr->next; ptr != &hcrypt->algs; 229 for (ptr = hcrypt->algs.next, n = ptr->next; ptr != &hcrypt->algs;
229 ptr = n, n = ptr->next) { 230 ptr = n, n = ptr->next) {
230 struct ieee80211_crypto_alg *alg = 231 struct ieee80211_crypto_alg *alg =
231 (struct ieee80211_crypto_alg *) ptr; 232 (struct ieee80211_crypto_alg *)ptr;
232 list_del(ptr); 233 list_del(ptr);
233 pr_debug("ieee80211_crypt: unregistered algorithm '%s' (deinit)\n", 234 pr_debug("ieee80211_crypt: unregistered algorithm '%s' (deinit)\n",
234 alg->ops->name); 235 alg->ops->name);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.h b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.h
index 0b4ea431982d..005bf89aae65 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt.h
@@ -30,7 +30,8 @@ struct ieee80211_crypto_ops {
30 30
31 /* init new crypto context (e.g., allocate private data space, 31 /* init new crypto context (e.g., allocate private data space,
32 * select IV, etc.); returns NULL on failure or pointer to allocated 32 * select IV, etc.); returns NULL on failure or pointer to allocated
33 * private data on success */ 33 * private data on success
34 */
34 void * (*init)(int keyidx); 35 void * (*init)(int keyidx);
35 36
36 /* deinitialize crypto context and free allocated private data */ 37 /* deinitialize crypto context and free allocated private data */
@@ -46,7 +47,8 @@ struct ieee80211_crypto_ops {
46 int (*decrypt_mpdu)(struct sk_buff *skb, int hdr_len, void *priv); 47 int (*decrypt_mpdu)(struct sk_buff *skb, int hdr_len, void *priv);
47 48
48 /* These functions are called for full MSDUs, i.e. full frames. 49 /* These functions are called for full MSDUs, i.e. full frames.
49 * These can be NULL if full MSDU operations are not needed. */ 50 * These can be NULL if full MSDU operations are not needed.
51 */
50 int (*encrypt_msdu)(struct sk_buff *skb, int hdr_len, void *priv); 52 int (*encrypt_msdu)(struct sk_buff *skb, int hdr_len, void *priv);
51 int (*decrypt_msdu)(struct sk_buff *skb, int keyidx, int hdr_len, 53 int (*decrypt_msdu)(struct sk_buff *skb, int keyidx, int hdr_len,
52 void *priv); 54 void *priv);
@@ -55,14 +57,16 @@ struct ieee80211_crypto_ops {
55 int (*get_key)(void *key, int len, u8 *seq, void *priv); 57 int (*get_key)(void *key, int len, u8 *seq, void *priv);
56 58
57 /* procfs handler for printing out key information and possible 59 /* procfs handler for printing out key information and possible
58 * statistics */ 60 * statistics
61 */
59 char * (*print_stats)(char *p, void *priv); 62 char * (*print_stats)(char *p, void *priv);
60 63
61 /* maximum number of bytes added by encryption; encrypt buf is 64 /* maximum number of bytes added by encryption; encrypt buf is
62 * allocated with extra_prefix_len bytes, copy of in_buf, and 65 * allocated with extra_prefix_len bytes, copy of in_buf, and
63 * extra_postfix_len; encrypt need not use all this space, but 66 * extra_postfix_len; encrypt need not use all this space, but
64 * the result must start at the beginning of the buffer and correct 67 * the result must start at the beginning of the buffer and correct
65 * length must be returned */ 68 * length must be returned
69 */
66 int extra_prefix_len, extra_postfix_len; 70 int extra_prefix_len, extra_postfix_len;
67 71
68 struct module *owner; 72 struct module *owner;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
index 2dc25cc2c726..e6648f7723ce 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_ccmp.c
@@ -67,7 +67,7 @@ static void *ieee80211_ccmp_init(int key_idx)
67 struct ieee80211_ccmp_data *priv; 67 struct ieee80211_ccmp_data *priv;
68 68
69 priv = kzalloc(sizeof(*priv), GFP_ATOMIC); 69 priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
70 if (priv == NULL) 70 if (!priv)
71 goto fail; 71 goto fail;
72 priv->key_idx = key_idx; 72 priv->key_idx = key_idx;
73 73
@@ -90,7 +90,6 @@ fail:
90 return NULL; 90 return NULL;
91} 91}
92 92
93
94static void ieee80211_ccmp_deinit(void *priv) 93static void ieee80211_ccmp_deinit(void *priv)
95{ 94{
96 struct ieee80211_ccmp_data *_priv = priv; 95 struct ieee80211_ccmp_data *_priv = priv;
@@ -100,7 +99,6 @@ static void ieee80211_ccmp_deinit(void *priv)
100 kfree(priv); 99 kfree(priv);
101} 100}
102 101
103
104static inline void xor_block(u8 *b, u8 *a, size_t len) 102static inline void xor_block(u8 *b, u8 *a, size_t len)
105{ 103{
106 int i; 104 int i;
@@ -109,8 +107,6 @@ static inline void xor_block(u8 *b, u8 *a, size_t len)
109 b[i] ^= a[i]; 107 b[i] ^= a[i];
110} 108}
111 109
112
113
114static void ccmp_init_blocks(struct crypto_tfm *tfm, 110static void ccmp_init_blocks(struct crypto_tfm *tfm,
115 struct rtl_80211_hdr_4addr *hdr, 111 struct rtl_80211_hdr_4addr *hdr,
116 u8 *pn, size_t dlen, u8 *b0, u8 *auth, 112 u8 *pn, size_t dlen, u8 *b0, u8 *auth,
@@ -135,7 +131,7 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
135 if (a4_included) 131 if (a4_included)
136 aad_len += 6; 132 aad_len += 6;
137 if (qc_included) { 133 if (qc_included) {
138 pos = (u8 *) &hdr->addr4; 134 pos = (u8 *)&hdr->addr4;
139 if (a4_included) 135 if (a4_included)
140 pos += 6; 136 pos += 6;
141 qc = *pos & 0x0f; 137 qc = *pos & 0x0f;
@@ -161,13 +157,13 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
161 * A4 (if present) 157 * A4 (if present)
162 * QC (if present) 158 * QC (if present)
163 */ 159 */
164 pos = (u8 *) hdr; 160 pos = (u8 *)hdr;
165 aad[0] = 0; /* aad_len >> 8 */ 161 aad[0] = 0; /* aad_len >> 8 */
166 aad[1] = aad_len & 0xff; 162 aad[1] = aad_len & 0xff;
167 aad[2] = pos[0] & 0x8f; 163 aad[2] = pos[0] & 0x8f;
168 aad[3] = pos[1] & 0xc7; 164 aad[3] = pos[1] & 0xc7;
169 memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN); 165 memcpy(aad + 4, hdr->addr1, 3 * ETH_ALEN);
170 pos = (u8 *) &hdr->seq_ctl; 166 pos = (u8 *)&hdr->seq_ctl;
171 aad[22] = pos[0] & 0x0f; 167 aad[22] = pos[0] & 0x0f;
172 aad[23] = 0; /* all bits masked */ 168 aad[23] = 0; /* all bits masked */
173 memset(aad + 24, 0, 8); 169 memset(aad + 24, 0, 8);
@@ -185,19 +181,18 @@ static void ccmp_init_blocks(struct crypto_tfm *tfm,
185 xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN); 181 xor_block(auth, &aad[AES_BLOCK_LEN], AES_BLOCK_LEN);
186 ieee80211_ccmp_aes_encrypt(tfm, auth, auth); 182 ieee80211_ccmp_aes_encrypt(tfm, auth, auth);
187 b0[0] &= 0x07; 183 b0[0] &= 0x07;
188 b0[14] = b0[15] = 0; 184 b0[14] = 0;
185 b0[15] = 0;
189 ieee80211_ccmp_aes_encrypt(tfm, b0, s0); 186 ieee80211_ccmp_aes_encrypt(tfm, b0, s0);
190} 187}
191 188
192
193
194static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv) 189static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
195{ 190{
196 struct ieee80211_ccmp_data *key = priv; 191 struct ieee80211_ccmp_data *key = priv;
197 int data_len, i; 192 int data_len, i;
198 u8 *pos; 193 u8 *pos;
199 struct rtl_80211_hdr_4addr *hdr; 194 struct rtl_80211_hdr_4addr *hdr;
200 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 195 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
201 196
202 if (skb_headroom(skb) < CCMP_HDR_LEN || 197 if (skb_headroom(skb) < CCMP_HDR_LEN ||
203 skb_tailroom(skb) < CCMP_MIC_LEN || 198 skb_tailroom(skb) < CCMP_MIC_LEN ||
@@ -227,8 +222,7 @@ static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
227 *pos++ = key->tx_pn[1]; 222 *pos++ = key->tx_pn[1];
228 *pos++ = key->tx_pn[0]; 223 *pos++ = key->tx_pn[0];
229 224
230 225 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
231 hdr = (struct rtl_80211_hdr_4addr *) skb->data;
232 if (!tcb_desc->bHwSec) { 226 if (!tcb_desc->bHwSec) {
233 int blocks, last, len; 227 int blocks, last, len;
234 u8 *mic; 228 u8 *mic;
@@ -264,13 +258,12 @@ static int ieee80211_ccmp_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
264 return 0; 258 return 0;
265} 259}
266 260
267
268static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv) 261static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
269{ 262{
270 struct ieee80211_ccmp_data *key = priv; 263 struct ieee80211_ccmp_data *key = priv;
271 u8 keyidx, *pos; 264 u8 keyidx, *pos;
272 struct rtl_80211_hdr_4addr *hdr; 265 struct rtl_80211_hdr_4addr *hdr;
273 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 266 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
274 u8 pn[6]; 267 u8 pn[6];
275 268
276 if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) { 269 if (skb->len < hdr_len + CCMP_HDR_LEN + CCMP_MIC_LEN) {
@@ -278,7 +271,7 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
278 return -1; 271 return -1;
279 } 272 }
280 273
281 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 274 hdr = (struct rtl_80211_hdr_4addr *)skb->data;
282 pos = skb->data + hdr_len; 275 pos = skb->data + hdr_len;
283 keyidx = pos[3]; 276 keyidx = pos[3];
284 if (!(keyidx & (1 << 5))) { 277 if (!(keyidx & (1 << 5))) {
@@ -327,7 +320,6 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
327 u8 *a = key->rx_a; 320 u8 *a = key->rx_a;
328 int i, blocks, last, len; 321 int i, blocks, last, len;
329 322
330
331 ccmp_init_blocks(key->tfm, hdr, pn, data_len, b0, a, b); 323 ccmp_init_blocks(key->tfm, hdr, pn, data_len, b0, a, b);
332 xor_block(mic, b, CCMP_MIC_LEN); 324 xor_block(mic, b, CCMP_MIC_LEN);
333 325
@@ -366,7 +358,6 @@ static int ieee80211_ccmp_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
366 return keyidx; 358 return keyidx;
367} 359}
368 360
369
370static int ieee80211_ccmp_set_key(void *key, int len, u8 *seq, void *priv) 361static int ieee80211_ccmp_set_key(void *key, int len, u8 *seq, void *priv)
371{ 362{
372 struct ieee80211_ccmp_data *data = priv; 363 struct ieee80211_ccmp_data *data = priv;
@@ -389,15 +380,15 @@ static int ieee80211_ccmp_set_key(void *key, int len, u8 *seq, void *priv)
389 data->rx_pn[5] = seq[0]; 380 data->rx_pn[5] = seq[0];
390 } 381 }
391 crypto_cipher_setkey((void *)data->tfm, data->key, CCMP_TK_LEN); 382 crypto_cipher_setkey((void *)data->tfm, data->key, CCMP_TK_LEN);
392 } else if (len == 0) 383 } else if (len == 0) {
393 data->key_set = 0; 384 data->key_set = 0;
394 else 385 } else {
395 return -1; 386 return -1;
387 }
396 388
397 return 0; 389 return 0;
398} 390}
399 391
400
401static int ieee80211_ccmp_get_key(void *key, int len, u8 *seq, void *priv) 392static int ieee80211_ccmp_get_key(void *key, int len, u8 *seq, void *priv)
402{ 393{
403 struct ieee80211_ccmp_data *data = priv; 394 struct ieee80211_ccmp_data *data = priv;
@@ -421,7 +412,6 @@ static int ieee80211_ccmp_get_key(void *key, int len, u8 *seq, void *priv)
421 return CCMP_TK_LEN; 412 return CCMP_TK_LEN;
422} 413}
423 414
424
425static char *ieee80211_ccmp_print_stats(char *p, void *priv) 415static char *ieee80211_ccmp_print_stats(char *p, void *priv)
426{ 416{
427 struct ieee80211_ccmp_data *ccmp = priv; 417 struct ieee80211_ccmp_data *ccmp = priv;
@@ -436,12 +426,6 @@ static char *ieee80211_ccmp_print_stats(char *p, void *priv)
436 return p; 426 return p;
437} 427}
438 428
439void ieee80211_ccmp_null(void)
440{
441 /* printk("============>%s()\n", __func__); */
442 return;
443}
444
445static struct ieee80211_crypto_ops ieee80211_crypt_ccmp = { 429static struct ieee80211_crypto_ops ieee80211_crypt_ccmp = {
446 .name = "CCMP", 430 .name = "CCMP",
447 .init = ieee80211_ccmp_init, 431 .init = ieee80211_ccmp_init,
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
index e68850897adf..2453413757b6 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_tkip.c
@@ -304,7 +304,7 @@ static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
304 int len; 304 int len;
305 u8 *pos; 305 u8 *pos;
306 struct rtl_80211_hdr_4addr *hdr; 306 struct rtl_80211_hdr_4addr *hdr;
307 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 307 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
308 int ret = 0; 308 int ret = 0;
309 u8 rc4key[16], *icv; 309 u8 rc4key[16], *icv;
310 u32 crc; 310 u32 crc;
@@ -387,7 +387,7 @@ static int ieee80211_tkip_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
387 u32 iv32; 387 u32 iv32;
388 u16 iv16; 388 u16 iv16;
389 struct rtl_80211_hdr_4addr *hdr; 389 struct rtl_80211_hdr_4addr *hdr;
390 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 390 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
391 u8 rc4key[16]; 391 u8 rc4key[16];
392 u8 icv[4]; 392 u8 icv[4];
393 u32 crc; 393 u32 crc;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c
index 1999bc5cbbc1..0e8c876c1404 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_crypt_wep.c
@@ -88,7 +88,7 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
88 u32 klen, len; 88 u32 klen, len;
89 u8 key[WEP_KEY_LEN + 3]; 89 u8 key[WEP_KEY_LEN + 3];
90 u8 *pos; 90 u8 *pos;
91 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 91 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
92 u32 crc; 92 u32 crc;
93 u8 *icv; 93 u8 *icv;
94 struct scatterlist sg; 94 struct scatterlist sg;
@@ -109,7 +109,8 @@ static int prism2_wep_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
109 109
110 /* Fluhrer, Mantin, and Shamir have reported weaknesses in the key 110 /* Fluhrer, Mantin, and Shamir have reported weaknesses in the key
111 * scheduling algorithm of RC4. At least IVs (KeyByte + 3, 0xff, N) 111 * scheduling algorithm of RC4. At least IVs (KeyByte + 3, 0xff, N)
112 * can be used to speedup attacks, so avoid using them. */ 112 * can be used to speedup attacks, so avoid using them.
113 */
113 if ((wep->iv & 0xff00) == 0xff00) { 114 if ((wep->iv & 0xff00) == 0xff00) {
114 u8 B = (wep->iv >> 16) & 0xff; 115 u8 B = (wep->iv >> 16) & 0xff;
115 116
@@ -166,7 +167,7 @@ static int prism2_wep_decrypt(struct sk_buff *skb, int hdr_len, void *priv)
166 u32 klen, plen; 167 u32 klen, plen;
167 u8 key[WEP_KEY_LEN + 3]; 168 u8 key[WEP_KEY_LEN + 3];
168 u8 keyidx, *pos; 169 u8 keyidx, *pos;
169 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 170 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
170 u32 crc; 171 u32 crc;
171 u8 icv[4]; 172 u8 icv[4];
172 struct scatterlist sg; 173 struct scatterlist sg;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
index 30fff6c5696b..5fdfff0816c5 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_module.c
@@ -1,34 +1,34 @@
1/******************************************************************************* 1/*******************************************************************************
2 2 *
3 Copyright(c) 2004 Intel Corporation. All rights reserved. 3 * Copyright(c) 2004 Intel Corporation. All rights reserved.
4 4 *
5 Portions of this file are based on the WEP enablement code provided by the 5 * Portions of this file are based on the WEP enablement code provided by the
6 Host AP project hostap-drivers v0.1.3 6 * Host AP project hostap-drivers v0.1.3
7 Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 7 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
8 <jkmaline@cc.hut.fi> 8 * <jkmaline@cc.hut.fi>
9 Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi> 9 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
10 10 *
11 This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
12 under the terms of version 2 of the GNU General Public License as 12 * under the terms of version 2 of the GNU General Public License as
13 published by the Free Software Foundation. 13 * published by the Free Software Foundation.
14 14 *
15 This program is distributed in the hope that it will be useful, but WITHOUT 15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 more details. 18 * more details.
19 19 *
20 You should have received a copy of the GNU General Public License along with 20 * You should have received a copy of the GNU General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 21 * this program; if not, write to the Free Software Foundation, Inc., 59
22 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 23 *
24 The full GNU General Public License is included in this distribution in the 24 * The full GNU General Public License is included in this distribution in the
25 file called LICENSE. 25 * file called LICENSE.
26 26 *
27 Contact Information: 27 * Contact Information:
28 James P. Ketrenos <ipw2100-admin@linux.intel.com> 28 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
29 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 30 *
31*******************************************************************************/ 31 *******************************************************************************/
32 32
33#include <linux/compiler.h> 33#include <linux/compiler.h>
34/* #include <linux/config.h> */ 34/* #include <linux/config.h> */
@@ -141,8 +141,8 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
141 spin_lock_init(&ieee->bw_spinlock); 141 spin_lock_init(&ieee->bw_spinlock);
142 spin_lock_init(&ieee->reorder_spinlock); 142 spin_lock_init(&ieee->reorder_spinlock);
143 /* added by WB */ 143 /* added by WB */
144 atomic_set(&(ieee->atm_chnlop), 0); 144 atomic_set(&ieee->atm_chnlop, 0);
145 atomic_set(&(ieee->atm_swbw), 0); 145 atomic_set(&ieee->atm_swbw, 0);
146 146
147 ieee->wpax_type_set = 0; 147 ieee->wpax_type_set = 0;
148 ieee->wpa_enabled = 0; 148 ieee->wpa_enabled = 0;
@@ -177,7 +177,6 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
177 177
178/* These function were added to load crypte module autoly */ 178/* These function were added to load crypte module autoly */
179 ieee80211_tkip_null(); 179 ieee80211_tkip_null();
180 ieee80211_ccmp_null();
181 180
182 return dev; 181 return dev;
183 182
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index b1f2fdfcb718..5241c5003ebf 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -345,7 +345,7 @@ ieee80211_rx_frame_decrypt(struct ieee80211_device *ieee, struct sk_buff *skb,
345 return 0; 345 return 0;
346 if (ieee->hwsec_active) 346 if (ieee->hwsec_active)
347 { 347 {
348 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE); 348 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
349 tcb_desc->bHwSec = 1; 349 tcb_desc->bHwSec = 1;
350 } 350 }
351 hdr = (struct rtl_80211_hdr_4addr *) skb->data; 351 hdr = (struct rtl_80211_hdr_4addr *) skb->data;
@@ -392,7 +392,7 @@ ieee80211_rx_frame_decrypt_msdu(struct ieee80211_device *ieee, struct sk_buff *s
392 return 0; 392 return 0;
393 if (ieee->hwsec_active) 393 if (ieee->hwsec_active)
394 { 394 {
395 cb_desc *tcb_desc = (cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE); 395 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb+ MAX_DEV_ADDR_SIZE);
396 tcb_desc->bHwSec = 1; 396 tcb_desc->bHwSec = 1;
397 } 397 }
398 398
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index d7d85b3f19c4..1bff0e91cc0c 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -146,6 +146,7 @@ static void ieee80211_TURBO_Info(struct ieee80211_device *ieee, u8 **tag_p)
146static void enqueue_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb) 146static void enqueue_mgmt(struct ieee80211_device *ieee, struct sk_buff *skb)
147{ 147{
148 int nh; 148 int nh;
149
149 nh = (ieee->mgmt_queue_head +1) % MGMT_QUEUE_NUM; 150 nh = (ieee->mgmt_queue_head +1) % MGMT_QUEUE_NUM;
150 151
151/* 152/*
@@ -225,7 +226,8 @@ inline void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee
225 struct rtl_80211_hdr_3addr *header= 226 struct rtl_80211_hdr_3addr *header=
226 (struct rtl_80211_hdr_3addr *) skb->data; 227 (struct rtl_80211_hdr_3addr *) skb->data;
227 228
228 cb_desc *tcb_desc = (cb_desc *)(skb->cb + 8); 229 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + 8);
230
229 spin_lock_irqsave(&ieee->lock, flags); 231 spin_lock_irqsave(&ieee->lock, flags);
230 232
231 /* called with 2nd param 0, no mgmt lock required */ 233 /* called with 2nd param 0, no mgmt lock required */
@@ -364,6 +366,7 @@ struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee);
364static void ieee80211_send_beacon(struct ieee80211_device *ieee) 366static void ieee80211_send_beacon(struct ieee80211_device *ieee)
365{ 367{
366 struct sk_buff *skb; 368 struct sk_buff *skb;
369
367 if(!ieee->ieee_up) 370 if(!ieee->ieee_up)
368 return; 371 return;
369 //unsigned long flags; 372 //unsigned long flags;
@@ -427,6 +430,7 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
427{ 430{
428 short ch = 0; 431 short ch = 0;
429 u8 channel_map[MAX_CHANNEL_NUMBER+1]; 432 u8 channel_map[MAX_CHANNEL_NUMBER+1];
433
430 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 434 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
431 mutex_lock(&ieee->scan_mutex); 435 mutex_lock(&ieee->scan_mutex);
432 436
@@ -493,6 +497,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct *work)
493 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq); 497 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, softmac_scan_wq);
494 static short watchdog; 498 static short watchdog;
495 u8 channel_map[MAX_CHANNEL_NUMBER+1]; 499 u8 channel_map[MAX_CHANNEL_NUMBER+1];
500
496 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 501 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
497 if(!ieee->ieee_up) 502 if(!ieee->ieee_up)
498 return; 503 return;
@@ -2142,7 +2147,7 @@ void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *
2142 unsigned int queue_index = txb->queue_index; 2147 unsigned int queue_index = txb->queue_index;
2143 unsigned long flags; 2148 unsigned long flags;
2144 int i; 2149 int i;
2145 cb_desc *tcb_desc = NULL; 2150 struct cb_desc *tcb_desc = NULL;
2146 2151
2147 spin_lock_irqsave(&ieee->lock, flags); 2152 spin_lock_irqsave(&ieee->lock, flags);
2148 2153
@@ -2152,7 +2157,7 @@ void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *
2152 /* update the tx status */ 2157 /* update the tx status */
2153 ieee->stats.tx_bytes += le16_to_cpu(txb->payload_size); 2158 ieee->stats.tx_bytes += le16_to_cpu(txb->payload_size);
2154 ieee->stats.tx_packets++; 2159 ieee->stats.tx_packets++;
2155 tcb_desc = (cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE); 2160 tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE);
2156 if (tcb_desc->bMulticast) { 2161 if (tcb_desc->bMulticast) {
2157 ieee->stats.multicast++; 2162 ieee->stats.multicast++;
2158 } 2163 }
@@ -2623,6 +2628,7 @@ void ieee80211_start_protocol(struct ieee80211_device *ieee)
2623{ 2628{
2624 short ch = 0; 2629 short ch = 0;
2625 int i = 0; 2630 int i = 0;
2631
2626 if (ieee->proto_started) 2632 if (ieee->proto_started)
2627 return; 2633 return;
2628 2634
@@ -2766,7 +2772,7 @@ static int ieee80211_wpa_enable(struct ieee80211_device *ieee, int value)
2766{ 2772{
2767 /* This is called when wpa_supplicant loads and closes the driver 2773 /* This is called when wpa_supplicant loads and closes the driver
2768 * interface. */ 2774 * interface. */
2769 printk("%s WPA\n",value ? "enabling" : "disabling"); 2775 printk("%s WPA\n", value ? "enabling" : "disabling");
2770 ieee->wpa_enabled = value; 2776 ieee->wpa_enabled = value;
2771 return 0; 2777 return 0;
2772} 2778}
@@ -2869,7 +2875,7 @@ static int ieee80211_wpa_set_auth_algs(struct ieee80211_device *ieee, int value)
2869 2875
2870static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 value) 2876static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 value)
2871{ 2877{
2872 int ret=0; 2878 int ret = 0;
2873 unsigned long flags; 2879 unsigned long flags;
2874 2880
2875 switch (name) { 2881 switch (name) {
@@ -2878,7 +2884,7 @@ static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 v
2878 break; 2884 break;
2879 2885
2880 case IEEE_PARAM_TKIP_COUNTERMEASURES: 2886 case IEEE_PARAM_TKIP_COUNTERMEASURES:
2881 ieee->tkip_countermeasures=value; 2887 ieee->tkip_countermeasures = value;
2882 break; 2888 break;
2883 2889
2884 case IEEE_PARAM_DROP_UNENCRYPTED: { 2890 case IEEE_PARAM_DROP_UNENCRYPTED: {
@@ -2915,7 +2921,7 @@ static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 v
2915 } 2921 }
2916 2922
2917 case IEEE_PARAM_PRIVACY_INVOKED: 2923 case IEEE_PARAM_PRIVACY_INVOKED:
2918 ieee->privacy_invoked=value; 2924 ieee->privacy_invoked = value;
2919 break; 2925 break;
2920 2926
2921 case IEEE_PARAM_AUTH_ALGS: 2927 case IEEE_PARAM_AUTH_ALGS:
@@ -2923,7 +2929,7 @@ static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 v
2923 break; 2929 break;
2924 2930
2925 case IEEE_PARAM_IEEE_802_1X: 2931 case IEEE_PARAM_IEEE_802_1X:
2926 ieee->ieee802_1x=value; 2932 ieee->ieee802_1x = value;
2927 break; 2933 break;
2928 case IEEE_PARAM_WPAX_SELECT: 2934 case IEEE_PARAM_WPAX_SELECT:
2929 // added for WPA2 mixed mode 2935 // added for WPA2 mixed mode
@@ -2934,7 +2940,7 @@ static int ieee80211_wpa_set_param(struct ieee80211_device *ieee, u8 name, u32 v
2934 break; 2940 break;
2935 2941
2936 default: 2942 default:
2937 printk("Unknown WPA param: %d\n",name); 2943 printk("Unknown WPA param: %d\n", name);
2938 ret = -EOPNOTSUPP; 2944 ret = -EOPNOTSUPP;
2939 } 2945 }
2940 2946
@@ -3056,23 +3062,21 @@ static int ieee80211_wpa_set_encryption(struct ieee80211_device *ieee,
3056 } else 3062 } else
3057 sec.flags &= ~SEC_ACTIVE_KEY; 3063 sec.flags &= ~SEC_ACTIVE_KEY;
3058 3064
3059 if (param->u.crypt.alg != NULL) { 3065 memcpy(sec.keys[param->u.crypt.idx],
3060 memcpy(sec.keys[param->u.crypt.idx], 3066 param->u.crypt.key,
3061 param->u.crypt.key, 3067 param->u.crypt.key_len);
3062 param->u.crypt.key_len); 3068 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
3063 sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len; 3069 sec.flags |= (1 << param->u.crypt.idx);
3064 sec.flags |= (1 << param->u.crypt.idx); 3070
3065 3071 if (strcmp(param->u.crypt.alg, "WEP") == 0) {
3066 if (strcmp(param->u.crypt.alg, "WEP") == 0) { 3072 sec.flags |= SEC_LEVEL;
3067 sec.flags |= SEC_LEVEL; 3073 sec.level = SEC_LEVEL_1;
3068 sec.level = SEC_LEVEL_1; 3074 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
3069 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) { 3075 sec.flags |= SEC_LEVEL;
3070 sec.flags |= SEC_LEVEL; 3076 sec.level = SEC_LEVEL_2;
3071 sec.level = SEC_LEVEL_2; 3077 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
3072 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) { 3078 sec.flags |= SEC_LEVEL;
3073 sec.flags |= SEC_LEVEL; 3079 sec.level = SEC_LEVEL_3;
3074 sec.level = SEC_LEVEL_3;
3075 }
3076 } 3080 }
3077 done: 3081 done:
3078 if (ieee->set_security) 3082 if (ieee->set_security)
@@ -3107,7 +3111,7 @@ static inline struct sk_buff *ieee80211_disassociate_skb(
3107 if (!skb) 3111 if (!skb)
3108 return NULL; 3112 return NULL;
3109 3113
3110 disass = (struct ieee80211_disassoc *) skb_put(skb,sizeof(struct ieee80211_disassoc)); 3114 disass = (struct ieee80211_disassoc *) skb_put(skb, sizeof(struct ieee80211_disassoc));
3111 disass->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_DISASSOC); 3115 disass->header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_DISASSOC);
3112 disass->header.duration_id = 0; 3116 disass->header.duration_id = 0;
3113 3117
@@ -3129,7 +3133,8 @@ SendDisassociation(
3129{ 3133{
3130 struct ieee80211_network *beacon = &ieee->current_network; 3134 struct ieee80211_network *beacon = &ieee->current_network;
3131 struct sk_buff *skb; 3135 struct sk_buff *skb;
3132 skb = ieee80211_disassociate_skb(beacon,ieee,asRsn); 3136
3137 skb = ieee80211_disassociate_skb(beacon, ieee, asRsn);
3133 if (skb) { 3138 if (skb) {
3134 softmac_mgmt_xmit(skb, ieee); 3139 softmac_mgmt_xmit(skb, ieee);
3135 //dev_kfree_skb_any(skb);//edit by thomas 3140 //dev_kfree_skb_any(skb);//edit by thomas
@@ -3140,7 +3145,7 @@ EXPORT_SYMBOL(SendDisassociation);
3140int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p) 3145int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p)
3141{ 3146{
3142 struct ieee_param *param; 3147 struct ieee_param *param;
3143 int ret=0; 3148 int ret = 0;
3144 3149
3145 mutex_lock(&ieee->wx_mutex); 3150 mutex_lock(&ieee->wx_mutex);
3146 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length); 3151 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
@@ -3196,6 +3201,7 @@ EXPORT_SYMBOL(ieee80211_wpa_supplicant_ioctl);
3196void notify_wx_assoc_event(struct ieee80211_device *ieee) 3201void notify_wx_assoc_event(struct ieee80211_device *ieee)
3197{ 3202{
3198 union iwreq_data wrqu; 3203 union iwreq_data wrqu;
3204
3199 wrqu.ap_addr.sa_family = ARPHRD_ETHER; 3205 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3200 if (ieee->state == IEEE80211_LINKED) 3206 if (ieee->state == IEEE80211_LINKED)
3201 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN); 3207 memcpy(wrqu.ap_addr.sa_data, ieee->current_network.bssid, ETH_ALEN);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 1ab0aead298b..5704e4d7aa68 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -1,35 +1,34 @@
1/****************************************************************************** 1/******************************************************************************
2 2 *
3 Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved. 3 * Copyright(c) 2003 - 2004 Intel Corporation. All rights reserved.
4 4 *
5 This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 under the terms of version 2 of the GNU General Public License as 6 * under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 8 *
9 This program is distributed in the hope that it will be useful, but WITHOUT 9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details. 12 * more details.
13 13 *
14 You should have received a copy of the GNU General Public License along with 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., 59 15 * this program; if not, write to the Free Software Foundation, Inc., 59
16 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 17 *
18 The full GNU General Public License is included in this distribution in the 18 * The full GNU General Public License is included in this distribution in the
19 file called LICENSE. 19 * file called LICENSE.
20 20 *
21 Contact Information: 21 * Contact Information:
22 James P. Ketrenos <ipw2100-admin@linux.intel.com> 22 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 24 *
25****************************************************************************** 25 *
26 26 * Few modifications for Realtek's Wi-Fi drivers by
27 Few modifications for Realtek's Wi-Fi drivers by 27 * Andrea Merello <andrea.merello@gmail.com>
28 Andrea Merello <andrea.merello@gmail.com> 28 *
29 29 * A special thanks goes to Realtek for their support !
30 A special thanks goes to Realtek for their support ! 30 *
31 31 ******************************************************************************/
32******************************************************************************/
33 32
34#include <linux/compiler.h> 33#include <linux/compiler.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
@@ -55,101 +54,101 @@
55 54
56 55
57/* 56/*
58 57 *
59 58 *
60802.11 Data Frame 59 * 802.11 Data Frame
61 60 *
62 61 *
63802.11 frame_contorl for data frames - 2 bytes 62 * 802.11 frame_contorl for data frames - 2 bytes
64 ,-----------------------------------------------------------------------------------------. 63 * ,-----------------------------------------------------------------------------------------.
65bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e | 64 * bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e |
66 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------| 65 * |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
67val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x | x | x | 66 * val | 0 | 0 | 0 | 1 | x | 0 | 0 | 0 | 1 | 0 | x | x | x | x | x |
68 |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------| 67 * |----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|------|
69desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep | 68 * desc | ^-ver-^ | ^type-^ | ^-----subtype-----^ | to |from |more |retry| pwr |more |wep |
70 | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | | 69 * | | | x=0 data,x=1 data+ack | DS | DS |frag | | mgm |data | |
71 '-----------------------------------------------------------------------------------------' 70 * '-----------------------------------------------------------------------------------------'
72 /\ 71 * /\
73 | 72 * |
74802.11 Data Frame | 73 * 802.11 Data Frame |
75 ,--------- 'ctrl' expands to >-----------' 74 * ,--------- 'ctrl' expands to >-----------'
76 | 75 * |
77 ,--'---,-------------------------------------------------------------. 76 * ,--'---,-------------------------------------------------------------.
78Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 | 77 * Bytes | 2 | 2 | 6 | 6 | 6 | 2 | 0..2312 | 4 |
79 |------|------|---------|---------|---------|------|---------|------| 78 * |------|------|---------|---------|---------|------|---------|------|
80Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs | 79 * Desc. | ctrl | dura | DA/RA | TA | SA | Sequ | Frame | fcs |
81 | | tion | (BSSID) | | | ence | data | | 80 * | | tion | (BSSID) | | | ence | data | |
82 `--------------------------------------------------| |------' 81 * `--------------------------------------------------| |------'
83Total: 28 non-data bytes `----.----' 82 * Total: 28 non-data bytes `----.----'
84 | 83 * |
85 .- 'Frame data' expands to <---------------------------' 84 * .- 'Frame data' expands to <---------------------------'
86 | 85 * |
87 V 86 * V
88 ,---------------------------------------------------. 87 * ,---------------------------------------------------.
89Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 | 88 * Bytes | 1 | 1 | 1 | 3 | 2 | 0-2304 |
90 |------|------|---------|----------|------|---------| 89 * |------|------|---------|----------|------|---------|
91Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP | 90 * Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
92 | DSAP | SSAP | | | | Packet | 91 * | DSAP | SSAP | | | | Packet |
93 | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | | 92 * | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
94 `-----------------------------------------| | 93 * `-----------------------------------------| |
95Total: 8 non-data bytes `----.----' 94 * Total: 8 non-data bytes `----.----'
96 | 95 * |
97 .- 'IP Packet' expands, if WEP enabled, to <--' 96 * .- 'IP Packet' expands, if WEP enabled, to <--'
98 | 97 * |
99 V 98 * V
100 ,-----------------------. 99 * ,-----------------------.
101Bytes | 4 | 0-2296 | 4 | 100 * Bytes | 4 | 0-2296 | 4 |
102 |-----|-----------|-----| 101 * |-----|-----------|-----|
103Desc. | IV | Encrypted | ICV | 102 * Desc. | IV | Encrypted | ICV |
104 | | IP Packet | | 103 * | | IP Packet | |
105 `-----------------------' 104 * `-----------------------'
106Total: 8 non-data bytes 105 * Total: 8 non-data bytes
107 106 *
108 107 *
109802.3 Ethernet Data Frame 108 * 802.3 Ethernet Data Frame
110 109 *
111 ,-----------------------------------------. 110 * ,-----------------------------------------.
112Bytes | 6 | 6 | 2 | Variable | 4 | 111 * Bytes | 6 | 6 | 2 | Variable | 4 |
113 |-------|-------|------|-----------|------| 112 * |-------|-------|------|-----------|------|
114Desc. | Dest. | Source| Type | IP Packet | fcs | 113 * Desc. | Dest. | Source| Type | IP Packet | fcs |
115 | MAC | MAC | | | | 114 * | MAC | MAC | | | |
116 `-----------------------------------------' 115 * `-----------------------------------------'
117Total: 18 non-data bytes 116 * Total: 18 non-data bytes
118 117 *
119In the event that fragmentation is required, the incoming payload is split into 118 * In the event that fragmentation is required, the incoming payload is split into
120N parts of size ieee->fts. The first fragment contains the SNAP header and the 119 * N parts of size ieee->fts. The first fragment contains the SNAP header and the
121remaining packets are just data. 120 * remaining packets are just data.
122 121 *
123If encryption is enabled, each fragment payload size is reduced by enough space 122 * If encryption is enabled, each fragment payload size is reduced by enough space
124to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP) 123 * to add the prefix and postfix (IV and ICV totalling 8 bytes in the case of WEP)
125So if you have 1500 bytes of payload with ieee->fts set to 500 without 124 * So if you have 1500 bytes of payload with ieee->fts set to 500 without
126encryption it will take 3 frames. With WEP it will take 4 frames as the 125 * encryption it will take 3 frames. With WEP it will take 4 frames as the
127payload of each frame is reduced to 492 bytes. 126 * payload of each frame is reduced to 492 bytes.
128 127 *
129* SKB visualization 128 * SKB visualization
130* 129 *
131* ,- skb->data 130 * ,- skb->data
132* | 131 * |
133* | ETHERNET HEADER ,-<-- PAYLOAD 132 * | ETHERNET HEADER ,-<-- PAYLOAD
134* | | 14 bytes from skb->data 133 * | | 14 bytes from skb->data
135* | 2 bytes for Type --> ,T. | (sizeof ethhdr) 134 * | 2 bytes for Type --> ,T. | (sizeof ethhdr)
136* | | | | 135 * | | | |
137* |,-Dest.--. ,--Src.---. | | | 136 * |,-Dest.--. ,--Src.---. | | |
138* | 6 bytes| | 6 bytes | | | | 137 * | 6 bytes| | 6 bytes | | | |
139* v | | | | | | 138 * v | | | | | |
140* 0 | v 1 | v | v 2 139 * 0 | v 1 | v | v 2
141* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 140 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
142* ^ | ^ | ^ | 141 * ^ | ^ | ^ |
143* | | | | | | 142 * | | | | | |
144* | | | | `T' <---- 2 bytes for Type 143 * | | | | `T' <---- 2 bytes for Type
145* | | | | 144 * | | | |
146* | | '---SNAP--' <-------- 6 bytes for SNAP 145 * | | '---SNAP--' <-------- 6 bytes for SNAP
147* | | 146 * | |
148* `-IV--' <-------------------- 4 bytes for IV (WEP) 147 * `-IV--' <-------------------- 4 bytes for IV (WEP)
149* 148 *
150* SNAP HEADER 149 * SNAP HEADER
151* 150 *
152*/ 151 */
153 152
154static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 }; 153static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
155static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 }; 154static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
@@ -205,11 +204,13 @@ int ieee80211_encrypt_fragment(
205 } 204 }
206 205
207 /* To encrypt, frame format is: 206 /* To encrypt, frame format is:
208 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes) */ 207 * IV (4 bytes), clear payload (including SNAP), ICV (4 bytes)
208 */
209 209
210 // PR: FIXME: Copied from hostap. Check fragmentation/MSDU/MPDU encryption. 210 // PR: FIXME: Copied from hostap. Check fragmentation/MSDU/MPDU encryption.
211 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so 211 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
212 * call both MSDU and MPDU encryption functions from here. */ 212 * call both MSDU and MPDU encryption functions from here.
213 */
213 atomic_inc(&crypt->refcnt); 214 atomic_inc(&crypt->refcnt);
214 res = 0; 215 res = 0;
215 if (crypt->ops->encrypt_msdu) 216 if (crypt->ops->encrypt_msdu)
@@ -250,7 +251,7 @@ static struct ieee80211_txb *ieee80211_alloc_txb(int nr_frags, int txb_size,
250 251
251 memset(txb, 0, sizeof(struct ieee80211_txb)); 252 memset(txb, 0, sizeof(struct ieee80211_txb));
252 txb->nr_frags = nr_frags; 253 txb->nr_frags = nr_frags;
253 txb->frag_size = txb_size; 254 txb->frag_size = __cpu_to_le16(txb_size);
254 255
255 for (i = 0; i < nr_frags; i++) { 256 for (i = 0; i < nr_frags; i++) {
256 txb->fragments[i] = dev_alloc_skb(txb_size); 257 txb->fragments[i] = dev_alloc_skb(txb_size);
@@ -304,7 +305,7 @@ ieee80211_classify(struct sk_buff *skb, struct ieee80211_network *network)
304 305
305#define SN_LESS(a, b) (((a-b)&0x800)!=0) 306#define SN_LESS(a, b) (((a-b)&0x800)!=0)
306static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee, 307static void ieee80211_tx_query_agg_cap(struct ieee80211_device *ieee,
307 struct sk_buff *skb, cb_desc *tcb_desc) 308 struct sk_buff *skb, struct cb_desc *tcb_desc)
308{ 309{
309 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 310 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
310 PTX_TS_RECORD pTxTs = NULL; 311 PTX_TS_RECORD pTxTs = NULL;
@@ -379,7 +380,7 @@ FORCED_AGG_SETTING:
379} 380}
380 381
381static void ieee80211_qurey_ShortPreambleMode(struct ieee80211_device *ieee, 382static void ieee80211_qurey_ShortPreambleMode(struct ieee80211_device *ieee,
382 cb_desc *tcb_desc) 383 struct cb_desc *tcb_desc)
383{ 384{
384 tcb_desc->bUseShortPreamble = false; 385 tcb_desc->bUseShortPreamble = false;
385 if (tcb_desc->data_rate == 2) 386 if (tcb_desc->data_rate == 2)
@@ -393,7 +394,7 @@ static void ieee80211_qurey_ShortPreambleMode(struct ieee80211_device *ieee,
393 return; 394 return;
394} 395}
395static void 396static void
396ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, cb_desc *tcb_desc) 397ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, struct cb_desc *tcb_desc)
397{ 398{
398 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 399 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
399 400
@@ -415,7 +416,7 @@ ieee80211_query_HTCapShortGI(struct ieee80211_device *ieee, cb_desc *tcb_desc)
415} 416}
416 417
417static void ieee80211_query_BandwidthMode(struct ieee80211_device *ieee, 418static void ieee80211_query_BandwidthMode(struct ieee80211_device *ieee,
418 cb_desc *tcb_desc) 419 struct cb_desc *tcb_desc)
419{ 420{
420 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo; 421 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
421 422
@@ -436,7 +437,7 @@ static void ieee80211_query_BandwidthMode(struct ieee80211_device *ieee,
436} 437}
437 438
438static void ieee80211_query_protectionmode(struct ieee80211_device *ieee, 439static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
439 cb_desc *tcb_desc, 440 struct cb_desc *tcb_desc,
440 struct sk_buff *skb) 441 struct sk_buff *skb)
441{ 442{
442 // Common Settings 443 // Common Settings
@@ -548,7 +549,7 @@ NO_PROTECTION:
548 549
549 550
550static void ieee80211_txrate_selectmode(struct ieee80211_device *ieee, 551static void ieee80211_txrate_selectmode(struct ieee80211_device *ieee,
551 cb_desc *tcb_desc) 552 struct cb_desc *tcb_desc)
552{ 553{
553#ifdef TO_DO_LIST 554#ifdef TO_DO_LIST
554 if(!IsDataFrame(pFrame)) 555 if(!IsDataFrame(pFrame))
@@ -615,12 +616,13 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
615 616
616 struct ieee80211_crypt_data *crypt; 617 struct ieee80211_crypt_data *crypt;
617 618
618 cb_desc *tcb_desc; 619 struct cb_desc *tcb_desc;
619 620
620 spin_lock_irqsave(&ieee->lock, flags); 621 spin_lock_irqsave(&ieee->lock, flags);
621 622
622 /* If there is no driver handler to take the TXB, dont' bother 623 /* If there is no driver handler to take the TXB, dont' bother
623 * creating it... */ 624 * creating it...
625 */
624 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE))|| 626 if ((!ieee->hard_start_xmit && !(ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE))||
625 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) { 627 ((!ieee->softmac_data_hard_start_xmit && (ieee->softmac_features & IEEE_SOFTMAC_TX_QUEUE)))) {
626 printk(KERN_WARNING "%s: No xmit handler.\n", 628 printk(KERN_WARNING "%s: No xmit handler.\n",
@@ -683,13 +685,15 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
683 if (ieee->iw_mode == IW_MODE_INFRA) { 685 if (ieee->iw_mode == IW_MODE_INFRA) {
684 fc |= IEEE80211_FCTL_TODS; 686 fc |= IEEE80211_FCTL_TODS;
685 /* To DS: Addr1 = BSSID, Addr2 = SA, 687 /* To DS: Addr1 = BSSID, Addr2 = SA,
686 Addr3 = DA */ 688 * Addr3 = DA
689 */
687 memcpy(&header.addr1, ieee->current_network.bssid, ETH_ALEN); 690 memcpy(&header.addr1, ieee->current_network.bssid, ETH_ALEN);
688 memcpy(&header.addr2, &src, ETH_ALEN); 691 memcpy(&header.addr2, &src, ETH_ALEN);
689 memcpy(&header.addr3, &dest, ETH_ALEN); 692 memcpy(&header.addr3, &dest, ETH_ALEN);
690 } else if (ieee->iw_mode == IW_MODE_ADHOC) { 693 } else if (ieee->iw_mode == IW_MODE_ADHOC) {
691 /* not From/To DS: Addr1 = DA, Addr2 = SA, 694 /* not From/To DS: Addr1 = DA, Addr2 = SA,
692 Addr3 = BSSID */ 695 * Addr3 = BSSID
696 */
693 memcpy(&header.addr1, dest, ETH_ALEN); 697 memcpy(&header.addr1, dest, ETH_ALEN);
694 memcpy(&header.addr2, src, ETH_ALEN); 698 memcpy(&header.addr2, src, ETH_ALEN);
695 memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN); 699 memcpy(&header.addr3, ieee->current_network.bssid, ETH_ALEN);
@@ -698,7 +702,8 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
698 header.frame_ctl = cpu_to_le16(fc); 702 header.frame_ctl = cpu_to_le16(fc);
699 703
700 /* Determine fragmentation size based on destination (multicast 704 /* Determine fragmentation size based on destination (multicast
701 * and broadcast are not fragmented) */ 705 * and broadcast are not fragmented)
706 */
702 if (is_multicast_ether_addr(header.addr1)) { 707 if (is_multicast_ether_addr(header.addr1)) {
703 frag_size = MAX_FRAG_THRESHOLD; 708 frag_size = MAX_FRAG_THRESHOLD;
704 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK; 709 qos_ctl |= QOS_CTL_NOTCONTAIN_ACK;
@@ -720,9 +725,10 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
720 hdr_len = IEEE80211_3ADDR_LEN; 725 hdr_len = IEEE80211_3ADDR_LEN;
721 } 726 }
722 /* Determine amount of payload per fragment. Regardless of if 727 /* Determine amount of payload per fragment. Regardless of if
723 * this stack is providing the full 802.11 header, one will 728 * this stack is providing the full 802.11 header, one will
724 * eventually be affixed to this fragment -- so we must account for 729 * eventually be affixed to this fragment -- so we must account for
725 * it when determining the amount of payload space. */ 730 * it when determining the amount of payload space.
731 */
726 bytes_per_frag = frag_size - hdr_len; 732 bytes_per_frag = frag_size - hdr_len;
727 if (ieee->config & 733 if (ieee->config &
728 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS)) 734 (CFG_IEEE80211_COMPUTE_FCS | CFG_IEEE80211_RESERVE_FCS))
@@ -734,7 +740,8 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
734 crypt->ops->extra_postfix_len; 740 crypt->ops->extra_postfix_len;
735 741
736 /* Number of fragments is the total bytes_per_frag / 742 /* Number of fragments is the total bytes_per_frag /
737 * payload_per_fragment */ 743 * payload_per_fragment
744 */
738 nr_frags = bytes / bytes_per_frag; 745 nr_frags = bytes / bytes_per_frag;
739 bytes_last_frag = bytes % bytes_per_frag; 746 bytes_last_frag = bytes % bytes_per_frag;
740 if (bytes_last_frag) 747 if (bytes_last_frag)
@@ -743,8 +750,9 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
743 bytes_last_frag = bytes_per_frag; 750 bytes_last_frag = bytes_per_frag;
744 751
745 /* When we allocate the TXB we allocate enough space for the reserve 752 /* When we allocate the TXB we allocate enough space for the reserve
746 * and full fragment bytes (bytes_per_frag doesn't include prefix, 753 * and full fragment bytes (bytes_per_frag doesn't include prefix,
747 * postfix, header, FCS, etc.) */ 754 * postfix, header, FCS, etc.)
755 */
748 txb = ieee80211_alloc_txb(nr_frags, frag_size + ieee->tx_headroom, GFP_ATOMIC); 756 txb = ieee80211_alloc_txb(nr_frags, frag_size + ieee->tx_headroom, GFP_ATOMIC);
749 if (unlikely(!txb)) { 757 if (unlikely(!txb)) {
750 printk(KERN_WARNING "%s: Could not allocate TXB\n", 758 printk(KERN_WARNING "%s: Could not allocate TXB\n",
@@ -752,7 +760,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
752 goto failed; 760 goto failed;
753 } 761 }
754 txb->encrypted = encrypt; 762 txb->encrypted = encrypt;
755 txb->payload_size = bytes; 763 txb->payload_size = __cpu_to_le16(bytes);
756 764
757 //if (ieee->current_network.QoS_Enable) 765 //if (ieee->current_network.QoS_Enable)
758 if(qos_actived) 766 if(qos_actived)
@@ -766,7 +774,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
766 774
767 for (i = 0; i < nr_frags; i++) { 775 for (i = 0; i < nr_frags; i++) {
768 skb_frag = txb->fragments[i]; 776 skb_frag = txb->fragments[i];
769 tcb_desc = (cb_desc *)(skb_frag->cb + MAX_DEV_ADDR_SIZE); 777 tcb_desc = (struct cb_desc *)(skb_frag->cb + MAX_DEV_ADDR_SIZE);
770 if(qos_actived){ 778 if(qos_actived){
771 skb_frag->priority = skb->priority;//UP2AC(skb->priority); 779 skb_frag->priority = skb->priority;//UP2AC(skb->priority);
772 tcb_desc->queue_index = UP2AC(skb->priority); 780 tcb_desc->queue_index = UP2AC(skb->priority);
@@ -791,7 +799,8 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
791 memcpy(frag_hdr, &header, hdr_len); 799 memcpy(frag_hdr, &header, hdr_len);
792 800
793 /* If this is not the last fragment, then add the MOREFRAGS 801 /* If this is not the last fragment, then add the MOREFRAGS
794 * bit to the frame control */ 802 * bit to the frame control
803 */
795 if (i != nr_frags - 1) { 804 if (i != nr_frags - 1) {
796 frag_hdr->frame_ctl = cpu_to_le16( 805 frag_hdr->frame_ctl = cpu_to_le16(
797 fc | IEEE80211_FCTL_MOREFRAGS); 806 fc | IEEE80211_FCTL_MOREFRAGS);
@@ -824,7 +833,8 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
824 skb_pull(skb, bytes); 833 skb_pull(skb, bytes);
825 834
826 /* Encryption routine will move the header forward in order 835 /* Encryption routine will move the header forward in order
827 * to insert the IV between the header and the payload */ 836 * to insert the IV between the header and the payload
837 */
828 if (encrypt) 838 if (encrypt)
829 ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len); 839 ieee80211_encrypt_fragment(ieee, skb_frag, hdr_len);
830 if (ieee->config & 840 if (ieee->config &
@@ -859,7 +869,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
859 } 869 }
860 870
861 txb->encrypted = 0; 871 txb->encrypted = 0;
862 txb->payload_size = skb->len; 872 txb->payload_size = __cpu_to_le16(skb->len);
863 memcpy(skb_put(txb->fragments[0],skb->len), skb->data, skb->len); 873 memcpy(skb_put(txb->fragments[0],skb->len), skb->data, skb->len);
864 } 874 }
865 875
@@ -867,7 +877,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
867//WB add to fill data tcb_desc here. only first fragment is considered, need to change, and you may remove to other place. 877//WB add to fill data tcb_desc here. only first fragment is considered, need to change, and you may remove to other place.
868 if (txb) 878 if (txb)
869 { 879 {
870 cb_desc *tcb_desc = (cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE); 880 struct cb_desc *tcb_desc = (struct cb_desc *)(txb->fragments[0]->cb + MAX_DEV_ADDR_SIZE);
871 tcb_desc->bTxEnableFwCalcDur = 1; 881 tcb_desc->bTxEnableFwCalcDur = 1;
872 if (is_multicast_ether_addr(header.addr1)) 882 if (is_multicast_ether_addr(header.addr1))
873 tcb_desc->bMulticast = 1; 883 tcb_desc->bMulticast = 1;
@@ -896,7 +906,7 @@ int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev)
896 }else{ 906 }else{
897 if ((*ieee->hard_start_xmit)(txb, dev) == 0) { 907 if ((*ieee->hard_start_xmit)(txb, dev) == 0) {
898 stats->tx_packets++; 908 stats->tx_packets++;
899 stats->tx_bytes += txb->payload_size; 909 stats->tx_bytes += __le16_to_cpu(txb->payload_size);
900 return 0; 910 return 0;
901 } 911 }
902 ieee80211_txb_free(txb); 912 ieee80211_txb_free(txb);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
index 563d7fed6e1c..e383ec2fb335 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
@@ -623,7 +623,6 @@ int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
623 goto done; 623 goto done;
624 } 624 }
625 *crypt = new_crypt; 625 *crypt = new_crypt;
626
627 } 626 }
628 627
629 if (ext->key_len > 0 && (*crypt)->ops->set_key && 628 if (ext->key_len > 0 && (*crypt)->ops->set_key &&
@@ -725,7 +724,6 @@ int ieee80211_wx_get_encode_ext(struct ieee80211_device *ieee,
725 (ext->alg == IW_ENCODE_ALG_TKIP || 724 (ext->alg == IW_ENCODE_ALG_TKIP ||
726 ext->alg == IW_ENCODE_ALG_CCMP)) 725 ext->alg == IW_ENCODE_ALG_CCMP))
727 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID; 726 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
728
729 } 727 }
730 728
731 return 0; 729 return 0;
@@ -839,6 +837,5 @@ int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len)
839 ieee->wpa_ie_len = 0; 837 ieee->wpa_ie_len = 0;
840 } 838 }
841 return 0; 839 return 0;
842
843} 840}
844EXPORT_SYMBOL(ieee80211_wx_set_gen_ie); 841EXPORT_SYMBOL(ieee80211_wx_set_gen_ie);
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
index 98fbb6ef484d..6619b8fb9700 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
@@ -14,7 +14,7 @@
14 * input: PBA_RECORD pBA //BA entry to be enabled 14 * input: PBA_RECORD pBA //BA entry to be enabled
15 * u16 Time //indicate time delay. 15 * u16 Time //indicate time delay.
16 * output: none 16 * output: none
17********************************************************************************************************************/ 17 ********************************************************************************************************************/
18static void ActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA, u16 Time) 18static void ActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA, u16 Time)
19{ 19{
20 pBA->bValid = true; 20 pBA->bValid = true;
@@ -26,7 +26,7 @@ static void ActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA, u16 T
26 *function: deactivate BA entry, including its timer. 26 *function: deactivate BA entry, including its timer.
27 * input: PBA_RECORD pBA //BA entry to be disabled 27 * input: PBA_RECORD pBA //BA entry to be disabled
28 * output: none 28 * output: none
29********************************************************************************************************************/ 29 ********************************************************************************************************************/
30static void DeActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA) 30static void DeActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA)
31{ 31{
32 pBA->bValid = false; 32 pBA->bValid = false;
@@ -38,7 +38,7 @@ static void DeActivateBAEntry(struct ieee80211_device *ieee, PBA_RECORD pBA)
38 * PTX_TS_RECORD pTxTs //Tx Ts which is to deactivate BA entry. 38 * PTX_TS_RECORD pTxTs //Tx Ts which is to deactivate BA entry.
39 * output: none 39 * output: none
40 * notice: As PTX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME 40 * notice: As PTX_TS_RECORD structure will be defined in QOS, so wait to be merged. //FIXME
41********************************************************************************************************************/ 41 ********************************************************************************************************************/
42static u8 TxTsDeleteBA(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTs) 42static u8 TxTsDeleteBA(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTs)
43{ 43{
44 PBA_RECORD pAdmittedBa = &pTxTs->TxAdmittedBARecord; //These two BA entries must exist in TS structure 44 PBA_RECORD pAdmittedBa = &pTxTs->TxAdmittedBARecord; //These two BA entries must exist in TS structure
@@ -46,15 +46,13 @@ static u8 TxTsDeleteBA(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTs)
46 u8 bSendDELBA = false; 46 u8 bSendDELBA = false;
47 47
48 // Delete pending BA 48 // Delete pending BA
49 if (pPendingBa->bValid) 49 if (pPendingBa->bValid) {
50 {
51 DeActivateBAEntry(ieee, pPendingBa); 50 DeActivateBAEntry(ieee, pPendingBa);
52 bSendDELBA = true; 51 bSendDELBA = true;
53 } 52 }
54 53
55 // Delete admitted BA 54 // Delete admitted BA
56 if (pAdmittedBa->bValid) 55 if (pAdmittedBa->bValid) {
57 {
58 DeActivateBAEntry(ieee, pAdmittedBa); 56 DeActivateBAEntry(ieee, pAdmittedBa);
59 bSendDELBA = true; 57 bSendDELBA = true;
60 } 58 }
@@ -68,14 +66,13 @@ static u8 TxTsDeleteBA(struct ieee80211_device *ieee, PTX_TS_RECORD pTxTs)
68 * 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.
69 * output: none 67 * output: none
70 * 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
71********************************************************************************************************************/ 69 ********************************************************************************************************************/
72static u8 RxTsDeleteBA(struct ieee80211_device *ieee, PRX_TS_RECORD pRxTs) 70static u8 RxTsDeleteBA(struct ieee80211_device *ieee, PRX_TS_RECORD pRxTs)
73{ 71{
74 PBA_RECORD pBa = &pRxTs->RxAdmittedBARecord; 72 PBA_RECORD pBa = &pRxTs->RxAdmittedBARecord;
75 u8 bSendDELBA = false; 73 u8 bSendDELBA = false;
76 74
77 if (pBa->bValid) 75 if (pBa->bValid) {
78 {
79 DeActivateBAEntry(ieee, pBa); 76 DeActivateBAEntry(ieee, pBa);
80 bSendDELBA = true; 77 bSendDELBA = true;
81 } 78 }
@@ -88,7 +85,7 @@ static u8 RxTsDeleteBA(struct ieee80211_device *ieee, PRX_TS_RECORD pRxTs)
88 * input: 85 * input:
89 * PBA_RECORD pBA //entry to be reset 86 * PBA_RECORD pBA //entry to be reset
90 * output: none 87 * output: none
91********************************************************************************************************************/ 88 ********************************************************************************************************************/
92void ResetBaEntry(PBA_RECORD pBA) 89void ResetBaEntry(PBA_RECORD pBA)
93{ 90{
94 pBA->bValid = false; 91 pBA->bValid = false;
@@ -106,7 +103,7 @@ void ResetBaEntry(PBA_RECORD pBA)
106 * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ) 103 * u8 type //indicate whether it's RSP(ACT_ADDBARSP) ow REQ(ACT_ADDBAREQ)
107 * output: none 104 * output: none
108 * return: sk_buff* skb //return constructed skb to xmit 105 * return: sk_buff* skb //return constructed skb to xmit
109*******************************************************************************************************************************/ 106 *******************************************************************************************************************************/
110static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, PBA_RECORD pBA, u16 StatusCode, u8 type) 107static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, PBA_RECORD pBA, u16 StatusCode, u8 type)
111{ 108{
112 struct sk_buff *skb = NULL; 109 struct sk_buff *skb = NULL;
@@ -115,14 +112,12 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
115 u16 len = ieee->tx_headroom + 9; 112 u16 len = ieee->tx_headroom + 9;
116 //category(1) + action field(1) + Dialog Token(1) + BA Parameter Set(2) + BA Timeout Value(2) + BA Start SeqCtrl(2)(or StatusCode(2)) 113 //category(1) + action field(1) + Dialog Token(1) + BA Parameter Set(2) + BA Timeout Value(2) + BA Start SeqCtrl(2)(or StatusCode(2))
117 IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "========>%s(), frame(%d) sentd to:%pM, ieee->dev:%p\n", __func__, type, Dst, ieee->dev); 114 IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "========>%s(), frame(%d) sentd to:%pM, ieee->dev:%p\n", __func__, type, Dst, ieee->dev);
118 if (pBA == NULL) 115 if (pBA == NULL) {
119 {
120 IEEE80211_DEBUG(IEEE80211_DL_ERR, "pBA is NULL\n"); 116 IEEE80211_DEBUG(IEEE80211_DL_ERR, "pBA is NULL\n");
121 return NULL; 117 return NULL;
122 } 118 }
123 skb = dev_alloc_skb(len + sizeof( struct rtl_80211_hdr_3addr)); //need to add something others? FIXME 119 skb = dev_alloc_skb(len + sizeof( struct rtl_80211_hdr_3addr)); //need to add something others? FIXME
124 if (skb == NULL) 120 if (skb == NULL) {
125 {
126 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc skb for ADDBA_REQ\n"); 121 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc skb for ADDBA_REQ\n");
127 return NULL; 122 return NULL;
128 } 123 }
@@ -146,10 +141,9 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
146 // Dialog Token 141 // Dialog Token
147 *tag ++= pBA->DialogToken; 142 *tag ++= pBA->DialogToken;
148 143
149 if (ACT_ADDBARSP == type) 144 if (ACT_ADDBARSP == type) {
150 {
151 // Status Code 145 // Status Code
152 printk("=====>to send ADDBARSP\n"); 146 printk(KERN_INFO "=====>to send ADDBARSP\n");
153 147
154 put_unaligned_le16(StatusCode, tag); 148 put_unaligned_le16(StatusCode, tag);
155 tag += 2; 149 tag += 2;
@@ -163,8 +157,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
163 put_unaligned_le16(pBA->BaTimeoutValue, tag); 157 put_unaligned_le16(pBA->BaTimeoutValue, tag);
164 tag += 2; 158 tag += 2;
165 159
166 if (ACT_ADDBAREQ == type) 160 if (ACT_ADDBAREQ == type) {
167 {
168 // BA Start SeqCtrl 161 // BA Start SeqCtrl
169 memcpy(tag, (u8 *)&(pBA->BaStartSeqCtrl), 2); 162 memcpy(tag, (u8 *)&(pBA->BaStartSeqCtrl), 2);
170 tag += 2; 163 tag += 2;
@@ -184,7 +177,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
184 * u16 ReasonCode //status code. 177 * u16 ReasonCode //status code.
185 * output: none 178 * output: none
186 * return: sk_buff* skb //return constructed skb to xmit 179 * return: sk_buff* skb //return constructed skb to xmit
187********************************************************************************************************************/ 180 ********************************************************************************************************************/
188static struct sk_buff *ieee80211_DELBA( 181static struct sk_buff *ieee80211_DELBA(
189 struct ieee80211_device *ieee, 182 struct ieee80211_device *ieee,
190 u8 *dst, 183 u8 *dst,
@@ -209,8 +202,7 @@ static struct sk_buff *ieee80211_DELBA(
209 DelbaParamSet.field.TID = pBA->BaParamSet.field.TID; 202 DelbaParamSet.field.TID = pBA->BaParamSet.field.TID;
210 203
211 skb = dev_alloc_skb(len + sizeof( struct rtl_80211_hdr_3addr)); //need to add something others? FIXME 204 skb = dev_alloc_skb(len + sizeof( struct rtl_80211_hdr_3addr)); //need to add something others? FIXME
212 if (skb == NULL) 205 if (skb == NULL) {
213 {
214 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc skb for ADDBA_REQ\n"); 206 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't alloc skb for ADDBA_REQ\n");
215 return NULL; 207 return NULL;
216 } 208 }
@@ -250,25 +242,22 @@ static struct sk_buff *ieee80211_DELBA(
250 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA 242 * PBA_RECORD pBA //BA_RECORD entry which stores the necessary information for BA
251 * output: none 243 * output: none
252 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 244 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
253********************************************************************************************************************/ 245 ********************************************************************************************************************/
254static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee, 246static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee,
255 u8 *dst, PBA_RECORD pBA) 247 u8 *dst, PBA_RECORD pBA)
256{ 248{
257 struct sk_buff *skb; 249 struct sk_buff *skb;
258 skb = ieee80211_ADDBA(ieee, dst, pBA, 0, ACT_ADDBAREQ); //construct ACT_ADDBAREQ frames so set statuscode zero. 250 skb = ieee80211_ADDBA(ieee, dst, pBA, 0, ACT_ADDBAREQ); //construct ACT_ADDBAREQ frames so set statuscode zero.
259 251
260 if (skb) 252 if (skb) {
261 {
262 softmac_mgmt_xmit(skb, ieee); 253 softmac_mgmt_xmit(skb, ieee);
263 //add statistic needed here. 254 //add statistic needed here.
264 //and skb will be freed in softmac_mgmt_xmit(), so omit all dev_kfree_skb_any() outside softmac_mgmt_xmit() 255 //and skb will be freed in softmac_mgmt_xmit(), so omit all dev_kfree_skb_any() outside softmac_mgmt_xmit()
265 //WB 256 //WB
266 } 257 }
267 else 258 else {
268 {
269 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__); 259 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__);
270 } 260 }
271 return;
272} 261}
273 262
274/******************************************************************************************************************** 263/********************************************************************************************************************
@@ -278,19 +267,17 @@ static void ieee80211_send_ADDBAReq(struct ieee80211_device *ieee,
278 * u16 StatusCode //RSP StatusCode 267 * u16 StatusCode //RSP StatusCode
279 * output: none 268 * output: none
280 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 269 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
281********************************************************************************************************************/ 270 ********************************************************************************************************************/
282static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst, 271static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst,
283 PBA_RECORD pBA, u16 StatusCode) 272 PBA_RECORD pBA, u16 StatusCode)
284{ 273{
285 struct sk_buff *skb; 274 struct sk_buff *skb;
286 skb = ieee80211_ADDBA(ieee, dst, pBA, StatusCode, ACT_ADDBARSP); //construct ACT_ADDBARSP frames 275 skb = ieee80211_ADDBA(ieee, dst, pBA, StatusCode, ACT_ADDBARSP); //construct ACT_ADDBARSP frames
287 if (skb) 276 if (skb) {
288 {
289 softmac_mgmt_xmit(skb, ieee); 277 softmac_mgmt_xmit(skb, ieee);
290 //same above 278 //same above
291 } 279 }
292 else 280 else {
293 {
294 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__); 281 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__);
295 } 282 }
296 283
@@ -305,7 +292,7 @@ static void ieee80211_send_ADDBARsp(struct ieee80211_device *ieee, u8 *dst,
305 * u16 ReasonCode //DEL ReasonCode 292 * u16 ReasonCode //DEL ReasonCode
306 * output: none 293 * output: none
307 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does 294 * notice: If any possible, please hide pBA in ieee. And temporarily use Manage Queue as softmac_mgmt_xmit() usually does
308********************************************************************************************************************/ 295 ********************************************************************************************************************/
309 296
310static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst, 297static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst,
311 PBA_RECORD pBA, TR_SELECT TxRxSelect, 298 PBA_RECORD pBA, TR_SELECT TxRxSelect,
@@ -313,16 +300,13 @@ static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst,
313{ 300{
314 struct sk_buff *skb; 301 struct sk_buff *skb;
315 skb = ieee80211_DELBA(ieee, dst, pBA, TxRxSelect, ReasonCode); //construct ACT_ADDBARSP frames 302 skb = ieee80211_DELBA(ieee, dst, pBA, TxRxSelect, ReasonCode); //construct ACT_ADDBARSP frames
316 if (skb) 303 if (skb) {
317 {
318 softmac_mgmt_xmit(skb, ieee); 304 softmac_mgmt_xmit(skb, ieee);
319 //same above 305 //same above
320 } 306 }
321 else 307 else {
322 {
323 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__); 308 IEEE80211_DEBUG(IEEE80211_DL_ERR, "alloc skb error in function %s()\n", __func__);
324 } 309 }
325 return ;
326} 310}
327 311
328/******************************************************************************************************************** 312/********************************************************************************************************************
@@ -330,7 +314,7 @@ static void ieee80211_send_DELBA(struct ieee80211_device *ieee, u8 *dst,
330 * input: struct sk_buff * skb //incoming ADDBAReq skb. 314 * input: struct sk_buff * skb //incoming ADDBAReq skb.
331 * return: 0(pass), other(fail) 315 * return: 0(pass), other(fail)
332 * notice: As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support. 316 * notice: As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
333********************************************************************************************************************/ 317 ********************************************************************************************************************/
334int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb) 318int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
335{ 319{
336 struct rtl_80211_hdr_3addr *req = NULL; 320 struct rtl_80211_hdr_3addr *req = NULL;
@@ -361,7 +345,7 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
361 pBaTimeoutVal = (u16 *)(tag + 5); 345 pBaTimeoutVal = (u16 *)(tag + 5);
362 pBaStartSeqCtrl = (PSEQUENCE_CONTROL)(req + 7); 346 pBaStartSeqCtrl = (PSEQUENCE_CONTROL)(req + 7);
363 347
364 printk("====================>rx ADDBAREQ from :%pM\n", dst); 348 printk(KERN_INFO "====================>rx ADDBAREQ from :%pM\n", dst);
365//some other capability is not ready now. 349//some other capability is not ready now.
366 if ((ieee->current_network.qos_data.active == 0) || 350 if ((ieee->current_network.qos_data.active == 0) ||
367 (!ieee->pHTInfo->bCurrentHTSupport)) //|| 351 (!ieee->pHTInfo->bCurrentHTSupport)) //||
@@ -379,8 +363,7 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
379 dst, 363 dst,
380 (u8)(pBaParamSet->field.TID), 364 (u8)(pBaParamSet->field.TID),
381 RX_DIR, 365 RX_DIR,
382 true) ) 366 true) ) {
383 {
384 rc = ADDBA_STATUS_REFUSED; 367 rc = ADDBA_STATUS_REFUSED;
385 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__); 368 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__);
386 goto OnADDBAReq_Fail; 369 goto OnADDBAReq_Fail;
@@ -390,8 +373,7 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
390 // We can do much more check here, including BufferSize, AMSDU_Support, Policy, StartSeqCtrl... 373 // We can do much more check here, including BufferSize, AMSDU_Support, Policy, StartSeqCtrl...
391 // I want to check StartSeqCtrl to make sure when we start aggregation!!! 374 // I want to check StartSeqCtrl to make sure when we start aggregation!!!
392 // 375 //
393 if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) 376 if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) {
394 {
395 rc = ADDBA_STATUS_INVALID_PARAM; 377 rc = ADDBA_STATUS_INVALID_PARAM;
396 IEEE80211_DEBUG(IEEE80211_DL_ERR, "BA Policy is not correct in %s()\n", __func__); 378 IEEE80211_DEBUG(IEEE80211_DL_ERR, "BA Policy is not correct in %s()\n", __func__);
397 goto OnADDBAReq_Fail; 379 goto OnADDBAReq_Fail;
@@ -432,7 +414,7 @@ OnADDBAReq_Fail:
432 * input: struct sk_buff * skb //incoming ADDBAReq skb. 414 * input: struct sk_buff * skb //incoming ADDBAReq skb.
433 * return: 0(pass), other(fail) 415 * return: 0(pass), other(fail)
434 * notice: As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support. 416 * notice: As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
435********************************************************************************************************************/ 417 ********************************************************************************************************************/
436int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb) 418int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
437{ 419{
438 struct rtl_80211_hdr_3addr *rsp = NULL; 420 struct rtl_80211_hdr_3addr *rsp = NULL;
@@ -480,8 +462,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
480 dst, 462 dst,
481 (u8)(pBaParamSet->field.TID), 463 (u8)(pBaParamSet->field.TID),
482 TX_DIR, 464 TX_DIR,
483 false) ) 465 false) ) {
484 {
485 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__); 466 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS in %s()\n", __func__);
486 ReasonCode = DELBA_REASON_UNKNOWN_BA; 467 ReasonCode = DELBA_REASON_UNKNOWN_BA;
487 goto OnADDBARsp_Reject; 468 goto OnADDBARsp_Reject;
@@ -496,34 +477,29 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
496 // Check if related BA is waiting for setup. 477 // Check if related BA is waiting for setup.
497 // If not, reject by sending DELBA frame. 478 // If not, reject by sending DELBA frame.
498 // 479 //
499 if((pAdmittedBA->bValid==true)) 480 if (pAdmittedBA->bValid) {
500 {
501 // Since BA is already setup, we ignore all other ADDBA Response. 481 // Since BA is already setup, we ignore all other ADDBA Response.
502 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n"); 482 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. Drop because already admit it! \n");
503 return -1; 483 return -1;
504 } 484 }
505 else if((!pPendingBA->bValid) ||(*pDialogToken != pPendingBA->DialogToken)) 485 else if((!pPendingBA->bValid) ||(*pDialogToken != pPendingBA->DialogToken)) {
506 {
507 IEEE80211_DEBUG(IEEE80211_DL_ERR, "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n"); 486 IEEE80211_DEBUG(IEEE80211_DL_ERR, "OnADDBARsp(): Recv ADDBA Rsp. BA invalid, DELBA! \n");
508 ReasonCode = DELBA_REASON_UNKNOWN_BA; 487 ReasonCode = DELBA_REASON_UNKNOWN_BA;
509 goto OnADDBARsp_Reject; 488 goto OnADDBARsp_Reject;
510 } 489 }
511 else 490 else {
512 {
513 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. BA is admitted! Status code:%X\n", *pStatusCode); 491 IEEE80211_DEBUG(IEEE80211_DL_BA, "OnADDBARsp(): Recv ADDBA Rsp. BA is admitted! Status code:%X\n", *pStatusCode);
514 DeActivateBAEntry(ieee, pPendingBA); 492 DeActivateBAEntry(ieee, pPendingBA);
515 } 493 }
516 494
517 495
518 if(*pStatusCode == ADDBA_STATUS_SUCCESS) 496 if(*pStatusCode == ADDBA_STATUS_SUCCESS) {
519 {
520 // 497 //
521 // Determine ADDBA Rsp content here. 498 // Determine ADDBA Rsp content here.
522 // We can compare the value of BA parameter set that Peer returned and Self sent. 499 // We can compare the value of BA parameter set that Peer returned and Self sent.
523 // If it is OK, then admitted. Or we can send DELBA to cancel BA mechanism. 500 // If it is OK, then admitted. Or we can send DELBA to cancel BA mechanism.
524 // 501 //
525 if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) 502 if (pBaParamSet->field.BAPolicy == BA_POLICY_DELAYED) {
526 {
527 // Since this is a kind of ADDBA failed, we delay next ADDBA process. 503 // Since this is a kind of ADDBA failed, we delay next ADDBA process.
528 pTS->bAddBaReqDelayed = true; 504 pTS->bAddBaReqDelayed = true;
529 DeActivateBAEntry(ieee, pAdmittedBA); 505 DeActivateBAEntry(ieee, pAdmittedBA);
@@ -542,8 +518,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
542 DeActivateBAEntry(ieee, pAdmittedBA); 518 DeActivateBAEntry(ieee, pAdmittedBA);
543 ActivateBAEntry(ieee, pAdmittedBA, *pBaTimeoutVal); 519 ActivateBAEntry(ieee, pAdmittedBA, *pBaTimeoutVal);
544 } 520 }
545 else 521 else {
546 {
547 // Delay next ADDBA process. 522 // Delay next ADDBA process.
548 pTS->bAddBaReqDelayed = true; 523 pTS->bAddBaReqDelayed = true;
549 } 524 }
@@ -566,7 +541,7 @@ OnADDBARsp_Reject:
566 * input: struct sk_buff * skb //incoming ADDBAReq skb. 541 * input: struct sk_buff * skb //incoming ADDBAReq skb.
567 * return: 0(pass), other(fail) 542 * return: 0(pass), other(fail)
568 * notice: As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support. 543 * notice: As this function need support of QOS, I comment some code out. And when qos is ready, this code need to be support.
569********************************************************************************************************************/ 544 ********************************************************************************************************************/
570int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb) 545int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
571{ 546{
572 struct rtl_80211_hdr_3addr *delba = NULL; 547 struct rtl_80211_hdr_3addr *delba = NULL;
@@ -582,8 +557,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
582 } 557 }
583 558
584 if (ieee->current_network.qos_data.active == 0 || 559 if (ieee->current_network.qos_data.active == 0 ||
585 !ieee->pHTInfo->bCurrentHTSupport) 560 !ieee->pHTInfo->bCurrentHTSupport) {
586 {
587 IEEE80211_DEBUG(IEEE80211_DL_ERR, "received DELBA while QOS or HT is not supported(%d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport); 561 IEEE80211_DEBUG(IEEE80211_DL_ERR, "received DELBA while QOS or HT is not supported(%d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport);
588 return -1; 562 return -1;
589 } 563 }
@@ -593,8 +567,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
593 dst = &delba->addr2[0]; 567 dst = &delba->addr2[0];
594 pDelBaParamSet = (PDELBA_PARAM_SET)&delba->payload[2]; 568 pDelBaParamSet = (PDELBA_PARAM_SET)&delba->payload[2];
595 569
596 if(pDelBaParamSet->field.Initiator == 1) 570 if(pDelBaParamSet->field.Initiator == 1) {
597 {
598 PRX_TS_RECORD pRxTs; 571 PRX_TS_RECORD pRxTs;
599 572
600 if (!GetTs( 573 if (!GetTs(
@@ -603,16 +576,14 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
603 dst, 576 dst,
604 (u8)pDelBaParamSet->field.TID, 577 (u8)pDelBaParamSet->field.TID,
605 RX_DIR, 578 RX_DIR,
606 false) ) 579 false) ) {
607 {
608 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for RXTS in %s()\n", __func__); 580 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for RXTS in %s()\n", __func__);
609 return -1; 581 return -1;
610 } 582 }
611 583
612 RxTsDeleteBA(ieee, pRxTs); 584 RxTsDeleteBA(ieee, pRxTs);
613 } 585 }
614 else 586 else {
615 {
616 PTX_TS_RECORD pTxTs; 587 PTX_TS_RECORD pTxTs;
617 588
618 if (!GetTs( 589 if (!GetTs(
@@ -621,8 +592,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
621 dst, 592 dst,
622 (u8)pDelBaParamSet->field.TID, 593 (u8)pDelBaParamSet->field.TID,
623 TX_DIR, 594 TX_DIR,
624 false) ) 595 false) ) {
625 {
626 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for TXTS in %s()\n", __func__); 596 IEEE80211_DEBUG(IEEE80211_DL_ERR, "can't get TS for TXTS in %s()\n", __func__);
627 return -1; 597 return -1;
628 } 598 }
@@ -650,7 +620,7 @@ TsInitAddBA(
650{ 620{
651 PBA_RECORD pBA = &pTS->TxPendingBARecord; 621 PBA_RECORD pBA = &pTS->TxPendingBARecord;
652 622
653 if(pBA->bValid==true && bOverwritePending==false) 623 if (pBA->bValid && !bOverwritePending)
654 return; 624 return;
655 625
656 // Set parameters to "Pending" variable set 626 // Set parameters to "Pending" variable set
@@ -674,8 +644,7 @@ void
674TsInitDelBA( struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect) 644TsInitDelBA( struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SELECT TxRxSelect)
675{ 645{
676 646
677 if(TxRxSelect == TX_DIR) 647 if(TxRxSelect == TX_DIR) {
678 {
679 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)pTsCommonInfo; 648 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)pTsCommonInfo;
680 649
681 if(TxTsDeleteBA(ieee, pTxTs)) 650 if(TxTsDeleteBA(ieee, pTxTs))
@@ -686,8 +655,7 @@ TsInitDelBA( struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SE
686 TxRxSelect, 655 TxRxSelect,
687 DELBA_REASON_END_BA); 656 DELBA_REASON_END_BA);
688 } 657 }
689 else if(TxRxSelect == RX_DIR) 658 else if(TxRxSelect == RX_DIR) {
690 {
691 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)pTsCommonInfo; 659 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)pTsCommonInfo;
692 if(RxTsDeleteBA(ieee, pRxTs)) 660 if(RxTsDeleteBA(ieee, pRxTs))
693 ieee80211_send_DELBA( 661 ieee80211_send_DELBA(
@@ -703,7 +671,7 @@ TsInitDelBA( struct ieee80211_device *ieee, PTS_COMMON_INFO pTsCommonInfo, TR_SE
703 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer 671 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
704 * return: NULL 672 * return: NULL
705 * notice: 673 * notice:
706********************************************************************************************************************/ 674 ********************************************************************************************************************/
707void BaSetupTimeOut(unsigned long data) 675void BaSetupTimeOut(unsigned long data)
708{ 676{
709 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data; 677 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data;
@@ -738,5 +706,4 @@ void RxBaInactTimeout(unsigned long data)
738 &pRxTs->RxAdmittedBARecord, 706 &pRxTs->RxAdmittedBARecord,
739 RX_DIR, 707 RX_DIR,
740 DELBA_REASON_TIMEOUT); 708 DELBA_REASON_TIMEOUT);
741 return ;
742} 709}
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
index c3aabbaac7ae..5f54d93dfb66 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HT.h
@@ -35,7 +35,7 @@
35#define HT_SUPPORTED_MCS_1SS_2SS_BITMAP HT_MCS_1SS_BITMAP|HT_MCS_1SS_2SS_BITMAP 35#define HT_SUPPORTED_MCS_1SS_2SS_BITMAP HT_MCS_1SS_BITMAP|HT_MCS_1SS_2SS_BITMAP
36 36
37 37
38typedef enum _HT_MCS_RATE{ 38typedef enum _HT_MCS_RATE {
39 HT_MCS0 = 0x00000001, 39 HT_MCS0 = 0x00000001,
40 HT_MCS1 = 0x00000002, 40 HT_MCS1 = 0x00000002,
41 HT_MCS2 = 0x00000004, 41 HT_MCS2 = 0x00000004,
@@ -58,7 +58,7 @@ typedef enum _HT_MCS_RATE{
58// 58//
59// Represent Channel Width in HT Capabilities 59// Represent Channel Width in HT Capabilities
60// 60//
61typedef enum _HT_CHANNEL_WIDTH{ 61typedef enum _HT_CHANNEL_WIDTH {
62 HT_CHANNEL_WIDTH_20 = 0, 62 HT_CHANNEL_WIDTH_20 = 0,
63 HT_CHANNEL_WIDTH_20_40 = 1, 63 HT_CHANNEL_WIDTH_20_40 = 1,
64}HT_CHANNEL_WIDTH, *PHT_CHANNEL_WIDTH; 64}HT_CHANNEL_WIDTH, *PHT_CHANNEL_WIDTH;
@@ -67,14 +67,14 @@ typedef enum _HT_CHANNEL_WIDTH{
67// Represent Extension Channel Offset in HT Capabilities 67// Represent Extension Channel Offset in HT Capabilities
68// This is available only in 40Mhz mode. 68// This is available only in 40Mhz mode.
69// 69//
70typedef enum _HT_EXTCHNL_OFFSET{ 70typedef enum _HT_EXTCHNL_OFFSET {
71 HT_EXTCHNL_OFFSET_NO_EXT = 0, 71 HT_EXTCHNL_OFFSET_NO_EXT = 0,
72 HT_EXTCHNL_OFFSET_UPPER = 1, 72 HT_EXTCHNL_OFFSET_UPPER = 1,
73 HT_EXTCHNL_OFFSET_NO_DEF = 2, 73 HT_EXTCHNL_OFFSET_NO_DEF = 2,
74 HT_EXTCHNL_OFFSET_LOWER = 3, 74 HT_EXTCHNL_OFFSET_LOWER = 3,
75}HT_EXTCHNL_OFFSET, *PHT_EXTCHNL_OFFSET; 75}HT_EXTCHNL_OFFSET, *PHT_EXTCHNL_OFFSET;
76 76
77typedef enum _CHNLOP{ 77typedef enum _CHNLOP {
78 CHNLOP_NONE = 0, // No Action now 78 CHNLOP_NONE = 0, // No Action now
79 CHNLOP_SCAN = 1, // Scan in progress 79 CHNLOP_SCAN = 1, // Scan in progress
80 CHNLOP_SWBW = 2, // Bandwidth switching in progress 80 CHNLOP_SWBW = 2, // Bandwidth switching in progress
@@ -119,7 +119,7 @@ typedef union _HT_CAPABILITY_MACPARA{
119}HT_CAPABILITY_MACPARA, *PHT_CAPABILITY_MACPARA; 119}HT_CAPABILITY_MACPARA, *PHT_CAPABILITY_MACPARA;
120*/ 120*/
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,
@@ -134,14 +134,14 @@ typedef enum _HT_ACTION{
134 134
135 135
136/* 2007/06/07 MH Define sub-carrier mode for 40MHZ. */ 136/* 2007/06/07 MH Define sub-carrier mode for 40MHZ. */
137typedef enum _HT_Bandwidth_40MHZ_Sub_Carrier{ 137typedef enum _HT_Bandwidth_40MHZ_Sub_Carrier {
138 SC_MODE_DUPLICATE = 0, 138 SC_MODE_DUPLICATE = 0,
139 SC_MODE_LOWER = 1, 139 SC_MODE_LOWER = 1,
140 SC_MODE_UPPER = 2, 140 SC_MODE_UPPER = 2,
141 SC_MODE_FULL40MHZ = 3, 141 SC_MODE_FULL40MHZ = 3,
142}HT_BW40_SC_E; 142}HT_BW40_SC_E;
143 143
144typedef struct _HT_CAPABILITY_ELE{ 144typedef struct _HT_CAPABILITY_ELE {
145 145
146 //HT capability info 146 //HT capability info
147 u8 AdvCoding:1; 147 u8 AdvCoding:1;
@@ -184,7 +184,7 @@ typedef struct _HT_CAPABILITY_ELE{
184// Only AP is required to include this element 184// Only AP is required to include this element
185//------------------------------------------------------------ 185//------------------------------------------------------------
186 186
187typedef struct _HT_INFORMATION_ELE{ 187typedef struct _HT_INFORMATION_ELE {
188 u8 ControlChl; 188 u8 ControlChl;
189 189
190 u8 ExtChlOffset:2; 190 u8 ExtChlOffset:2;
@@ -215,18 +215,18 @@ typedef struct _HT_INFORMATION_ELE{
215// MIMO Power Save control field. 215// MIMO Power Save control field.
216// This is appear in MIMO Power Save Action Frame 216// This is appear in MIMO Power Save Action Frame
217// 217//
218typedef struct _MIMOPS_CTRL{ 218typedef struct _MIMOPS_CTRL {
219 u8 MimoPsEnable:1; 219 u8 MimoPsEnable:1;
220 u8 MimoPsMode:1; 220 u8 MimoPsMode:1;
221 u8 Reserved:6; 221 u8 Reserved:6;
222} MIMOPS_CTRL, *PMIMOPS_CTRL; 222} MIMOPS_CTRL, *PMIMOPS_CTRL;
223 223
224typedef enum _HT_SPEC_VER{ 224typedef enum _HT_SPEC_VER {
225 HT_SPEC_VER_IEEE = 0, 225 HT_SPEC_VER_IEEE = 0,
226 HT_SPEC_VER_EWC = 1, 226 HT_SPEC_VER_EWC = 1,
227}HT_SPEC_VER, *PHT_SPEC_VER; 227}HT_SPEC_VER, *PHT_SPEC_VER;
228 228
229typedef enum _HT_AGGRE_MODE_E{ 229typedef enum _HT_AGGRE_MODE_E {
230 HT_AGG_AUTO = 0, 230 HT_AGG_AUTO = 0,
231 HT_AGG_FORCE_ENABLE = 1, 231 HT_AGG_FORCE_ENABLE = 1,
232 HT_AGG_FORCE_DISABLE = 2, 232 HT_AGG_FORCE_DISABLE = 2,
@@ -238,7 +238,7 @@ typedef enum _HT_AGGRE_MODE_E{
238// to default value in HTInitializeHTInfo() 238// to default value in HTInitializeHTInfo()
239//------------------------------------------------------------ 239//------------------------------------------------------------
240 240
241typedef struct _RT_HIGH_THROUGHPUT{ 241typedef struct _RT_HIGH_THROUGHPUT {
242 u8 bEnableHT; 242 u8 bEnableHT;
243 u8 bCurrentHTSupport; 243 u8 bCurrentHTSupport;
244 244
@@ -347,7 +347,7 @@ typedef struct _RT_HIGH_THROUGHPUT{
347// when card is configured as "AP mode" 347// when card is configured as "AP mode"
348//------------------------------------------------------------ 348//------------------------------------------------------------
349 349
350typedef struct _RT_HTINFO_STA_ENTRY{ 350typedef struct _RT_HTINFO_STA_ENTRY {
351 u8 bEnableHT; 351 u8 bEnableHT;
352 352
353 u8 bSupportCck; 353 u8 bSupportCck;
@@ -377,7 +377,7 @@ typedef struct _RT_HTINFO_STA_ENTRY{
377// when card is configured as "STA mode" 377// when card is configured as "STA mode"
378//------------------------------------------------------------ 378//------------------------------------------------------------
379 379
380typedef struct _BSS_HT{ 380typedef struct _BSS_HT {
381 381
382 u8 bdSupportHT; 382 u8 bdSupportHT;
383 383
@@ -395,7 +395,7 @@ typedef struct _BSS_HT{
395 u8 bdRT2RTLongSlotTime; 395 u8 bdRT2RTLongSlotTime;
396} __attribute__ ((packed)) BSS_HT, *PBSS_HT; 396} __attribute__ ((packed)) BSS_HT, *PBSS_HT;
397 397
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;
@@ -404,12 +404,12 @@ typedef struct _MIMO_RSSI{
404 u32 Average; 404 u32 Average;
405}MIMO_RSSI, *PMIMO_RSSI; 405}MIMO_RSSI, *PMIMO_RSSI;
406 406
407typedef struct _MIMO_EVM{ 407typedef struct _MIMO_EVM {
408 u32 EVM1; 408 u32 EVM1;
409 u32 EVM2; 409 u32 EVM2;
410}MIMO_EVM, *PMIMO_EVM; 410}MIMO_EVM, *PMIMO_EVM;
411 411
412typedef struct _FALSE_ALARM_STATISTICS{ 412typedef struct _FALSE_ALARM_STATISTICS {
413 u32 Cnt_Parity_Fail; 413 u32 Cnt_Parity_Fail;
414 u32 Cnt_Rate_Illegal; 414 u32 Cnt_Rate_Illegal;
415 u32 Cnt_Crc8_fail; 415 u32 Cnt_Crc8_fail;
@@ -442,7 +442,7 @@ extern u8 MCS_FILTER_1SS[16];
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,
447 HT_AGG_SIZE_16K = 1, 447 HT_AGG_SIZE_16K = 1,
448 HT_AGG_SIZE_32K = 2, 448 HT_AGG_SIZE_32K = 2,
@@ -464,7 +464,7 @@ typedef enum _HT_IOT_PEER
464// 464//
465// IOT Action for different AP 465// IOT Action for different AP
466// 466//
467typedef enum _HT_IOT_ACTION{ 467typedef enum _HT_IOT_ACTION {
468 HT_IOT_ACT_TX_USE_AMSDU_4K = 0x00000001, 468 HT_IOT_ACT_TX_USE_AMSDU_4K = 0x00000001,
469 HT_IOT_ACT_TX_USE_AMSDU_8K = 0x00000002, 469 HT_IOT_ACT_TX_USE_AMSDU_8K = 0x00000002,
470 HT_IOT_ACT_DISABLE_MCS14 = 0x00000004, 470 HT_IOT_ACT_DISABLE_MCS14 = 0x00000004,
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
index 873969c9f226..e25b69777ee7 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TS.h
@@ -14,7 +14,7 @@ typedef enum _TR_SELECT {
14 RX_DIR = 1, 14 RX_DIR = 1,
15} TR_SELECT, *PTR_SELECT; 15} TR_SELECT, *PTR_SELECT;
16 16
17typedef struct _TS_COMMON_INFO{ 17typedef struct _TS_COMMON_INFO {
18 struct list_head List; 18 struct list_head List;
19 struct timer_list SetupTimer; 19 struct timer_list SetupTimer;
20 struct timer_list InactTimer; 20 struct timer_list InactTimer;
@@ -25,7 +25,7 @@ typedef struct _TS_COMMON_INFO{
25 u8 TClasNum; 25 u8 TClasNum;
26} TS_COMMON_INFO, *PTS_COMMON_INFO; 26} TS_COMMON_INFO, *PTS_COMMON_INFO;
27 27
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 */
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
index 6033502eff3d..b4c13fff2c65 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_TSProc.c
@@ -21,7 +21,7 @@ static void TsInactTimeout(unsigned long data)
21 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer 21 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
22 * return: NULL 22 * return: NULL
23 * notice: 23 * notice:
24********************************************************************************************************************/ 24 ********************************************************************************************************************/
25static void RxPktPendingTimeout(unsigned long data) 25static void RxPktPendingTimeout(unsigned long data)
26{ 26{
27 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data; 27 PRX_TS_RECORD pRxTs = (PRX_TS_RECORD)data;
@@ -31,7 +31,6 @@ static void RxPktPendingTimeout(unsigned long data)
31 31
32 //u32 flags = 0; 32 //u32 flags = 0;
33 unsigned long flags = 0; 33 unsigned long flags = 0;
34 struct ieee80211_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
35 u8 index = 0; 34 u8 index = 0;
36 bool bPktInBuf = false; 35 bool bPktInBuf = false;
37 36
@@ -55,7 +54,7 @@ static void RxPktPendingTimeout(unsigned long data)
55 pRxTs->RxIndicateSeq = (pRxTs->RxIndicateSeq + 1) % 4096; 54 pRxTs->RxIndicateSeq = (pRxTs->RxIndicateSeq + 1) % 4096;
56 55
57 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum); 56 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"RxPktPendingTimeout(): IndicateSeq: %d\n", pReorderEntry->SeqNum);
58 stats_IndicateArray[index] = pReorderEntry->prxb; 57 ieee->stats_IndicateArray[index] = pReorderEntry->prxb;
59 index++; 58 index++;
60 59
61 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List); 60 list_add_tail(&pReorderEntry->List, &ieee->RxReorder_Unused_List);
@@ -79,7 +78,7 @@ static void RxPktPendingTimeout(unsigned long data)
79 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags); 78 spin_unlock_irqrestore(&(ieee->reorder_spinlock), flags);
80 return; 79 return;
81 } 80 }
82 ieee80211_indicate_packets(ieee, stats_IndicateArray, index); 81 ieee80211_indicate_packets(ieee, ieee->stats_IndicateArray, index);
83 } 82 }
84 83
85 if(bPktInBuf && (pRxTs->RxTimeoutIndicateSeq==0xffff)) 84 if(bPktInBuf && (pRxTs->RxTimeoutIndicateSeq==0xffff))
@@ -96,7 +95,7 @@ static void RxPktPendingTimeout(unsigned long data)
96 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer 95 * input: unsigned long data //acturally we send TX_TS_RECORD or RX_TS_RECORD to these timer
97 * return: NULL 96 * return: NULL
98 * notice: 97 * notice:
99********************************************************************************************************************/ 98 ********************************************************************************************************************/
100static void TsAddBaProcess(unsigned long data) 99static void TsAddBaProcess(unsigned long data)
101{ 100{
102 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data; 101 PTX_TS_RECORD pTxTs = (PTX_TS_RECORD)data;
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c
index f35defc36fd9..c414efc0662e 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This files contains card eeprom (93c46 or 93c56) programming routines, 2 * This files contains card eeprom (93c46 or 93c56) programming routines,
3 memory is addressed by 16 bits words. 3 * memory is addressed by 16 bits words.
4 4 *
5 This is part of rtl8180 OpenSource driver. 5 * This is part of rtl8180 OpenSource driver.
6 Copyright (C) Andrea Merello 2004 <andrea.merello@gmail.com> 6 * Copyright (C) Andrea Merello 2004 <andrea.merello@gmail.com>
7 Released under the terms of GPL (General Public Licence) 7 * Released under the terms of GPL (General Public Licence)
8 8 *
9 Parts of this driver are based on the GPL part of the 9 * Parts of this driver are based on the GPL part of the
10 official realtek driver. 10 * official realtek driver.
11 11 *
12 Parts of this driver are based on the rtl8180 driver skeleton 12 * Parts of this driver are based on the rtl8180 driver skeleton
13 from Patric Schenke & Andres Salomon. 13 * from Patric Schenke & Andres Salomon.
14 14 *
15 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver. 15 * Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
16 16 *
17 We want to thank the Authors of those projects and the Ndiswrapper 17 * We want to thank the Authors of those projects and the Ndiswrapper
18 project Authors. 18 * project Authors.
19*/ 19 */
20 20
21#include "r8180_93cx6.h" 21#include "r8180_93cx6.h"
22 22
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.h b/drivers/staging/rtl8192u/r8180_93cx6.h
index 9cf7f587c3ab..643d465e7105 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.h
+++ b/drivers/staging/rtl8192u/r8180_93cx6.h
@@ -1,17 +1,17 @@
1/* 1/*
2 This is part of rtl8187 OpenSource driver 2 * This is part of rtl8187 OpenSource driver
3 Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 3 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com>
4 Released under the terms of GPL (General Public Licence) 4 * Released under the terms of GPL (General Public Licence)
5 5 *
6 Parts of this driver are based on the GPL part of the 6 * Parts of this driver are based on the GPL part of the
7 official realtek driver 7 * official realtek driver
8 Parts of this driver are based on the rtl8180 driver skeleton 8 * Parts of this driver are based on the rtl8180 driver skeleton
9 from Patric Schenke & Andres Salomon 9 * from Patric Schenke & Andres Salomon
10 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver 10 * Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver
11 11 *
12 We want to thank the Authors of such projects and the Ndiswrapper 12 * We want to thank the Authors of such projects and the Ndiswrapper
13 project Authors. 13 * project Authors.
14*/ 14 */
15 15
16/*This files contains card eeprom (93c46 or 93c56) programming routines*/ 16/*This files contains card eeprom (93c46 or 93c56) programming routines*/
17/*memory is addressed by WORDS*/ 17/*memory is addressed by WORDS*/
@@ -39,5 +39,4 @@
39#define EPROM_TXPW2 0x1b 39#define EPROM_TXPW2 0x1b
40#define EPROM_TXPW1 0x3d 40#define EPROM_TXPW1 0x3d
41 41
42
43int eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */ 42int eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */
diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.c b/drivers/staging/rtl8192u/r8190_rtl8256.c
index d733fb2ade91..e54f6fad2e68 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.c
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.c
@@ -1,12 +1,12 @@
1/* 1/*
2* This is part of the rtl8192 driver 2 * This is part of the rtl8192 driver
3* released under the GPL (See file COPYING for details). 3 * released under the GPL (See file COPYING for details).
4* 4 *
5* This files contains programming code for the rtl8256 5 * This files contains programming code for the rtl8256
6* radio frontend. 6 * radio frontend.
7* 7 *
8* *Many* thanks to Realtek Corp. for their great support! 8 * *Many* thanks to Realtek Corp. for their great support!
9*/ 9 */
10 10
11#include "r8192U.h" 11#include "r8192U.h"
12#include "r8192U_hw.h" 12#include "r8192U_hw.h"
diff --git a/drivers/staging/rtl8192u/r8190_rtl8256.h b/drivers/staging/rtl8192u/r8190_rtl8256.h
index 1ba4f83b520e..5c325ce9d631 100644
--- a/drivers/staging/rtl8192u/r8190_rtl8256.h
+++ b/drivers/staging/rtl8192u/r8190_rtl8256.h
@@ -1,14 +1,14 @@
1/* 1/*
2 This is part of the rtl8180-sa2400 driver 2 * This is part of the rtl8180-sa2400 driver
3 released under the GPL (See file COPYING for details). 3 * released under the GPL (See file COPYING for details).
4 Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com> 4 * Copyright (c) 2005 Andrea Merello <andrea.merello@gmail.com>
5 5 *
6 This files contains programming code for the rtl8256 6 *
7 radio frontend. 7 * This files contains programming code for the rtl8256
8 8 * radio frontend.
9 *Many* thanks to Realtek Corp. for their great support! 9 *
10 10 * *Many* thanks to Realtek Corp. for their great support!
11*/ 11 */
12 12
13#ifndef RTL8225H 13#ifndef RTL8225H
14#define RTL8225H 14#define RTL8225H
diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
index 0b7b04ea0910..a7ba8f37384e 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -626,7 +626,8 @@ typedef struct Stats {
626 long signal_quality; 626 long signal_quality;
627 long last_signal_strength_inpercent; 627 long last_signal_strength_inpercent;
628 /* Correct smoothed ss in dbm, only used in driver 628 /* Correct smoothed ss in dbm, only used in driver
629 * to report real power now */ 629 * to report real power now
630 */
630 long recv_signal_power; 631 long recv_signal_power;
631 u8 rx_rssi_percentage[4]; 632 u8 rx_rssi_percentage[4];
632 u8 rx_evm_percentage[2]; 633 u8 rx_evm_percentage[2];
@@ -672,32 +673,40 @@ typedef struct _BB_REGISTER_DEFINITION {
672 /* Tx gain stage: 0x80c~0x80f [4 bytes] */ 673 /* Tx gain stage: 0x80c~0x80f [4 bytes] */
673 u32 rfTxGainStage; 674 u32 rfTxGainStage;
674 /* wire parameter control1: 0x820~0x823, 0x828~0x82b, 675 /* wire parameter control1: 0x820~0x823, 0x828~0x82b,
675 * 0x830~0x833, 0x838~0x83b [16 bytes] */ 676 * 0x830~0x833, 0x838~0x83b [16 bytes]
677 */
676 u32 rfHSSIPara1; 678 u32 rfHSSIPara1;
677 /* wire parameter control2: 0x824~0x827, 0x82c~0x82f, 679 /* wire parameter control2: 0x824~0x827, 0x82c~0x82f,
678 * 0x834~0x837, 0x83c~0x83f [16 bytes] */ 680 * 0x834~0x837, 0x83c~0x83f [16 bytes]
681 */
679 u32 rfHSSIPara2; 682 u32 rfHSSIPara2;
680 /* Tx Rx antenna control: 0x858~0x85f [16 bytes] */ 683 /* Tx Rx antenna control: 0x858~0x85f [16 bytes] */
681 u32 rfSwitchControl; 684 u32 rfSwitchControl;
682 /* AGC parameter control1: 0xc50~0xc53, 0xc58~0xc5b, 685 /* AGC parameter control1: 0xc50~0xc53, 0xc58~0xc5b,
683 * 0xc60~0xc63, 0xc68~0xc6b [16 bytes] */ 686 * 0xc60~0xc63, 0xc68~0xc6b [16 bytes]
687 */
684 u32 rfAGCControl1; 688 u32 rfAGCControl1;
685 /* AGC parameter control2: 0xc54~0xc57, 0xc5c~0xc5f, 689 /* AGC parameter control2: 0xc54~0xc57, 0xc5c~0xc5f,
686 * 0xc64~0xc67, 0xc6c~0xc6f [16 bytes] */ 690 * 0xc64~0xc67, 0xc6c~0xc6f [16 bytes]
691 */
687 u32 rfAGCControl2; 692 u32 rfAGCControl2;
688 /* OFDM Rx IQ imbalance matrix: 0xc14~0xc17, 0xc1c~0xc1f, 693 /* OFDM Rx IQ imbalance matrix: 0xc14~0xc17, 0xc1c~0xc1f,
689 * 0xc24~0xc27, 0xc2c~0xc2f [16 bytes] */ 694 * 0xc24~0xc27, 0xc2c~0xc2f [16 bytes]
695 */
690 u32 rfRxIQImbalance; 696 u32 rfRxIQImbalance;
691 /* Rx IQ DC offset and Rx digital filter, Rx DC notch filter: 697 /* Rx IQ DC offset and Rx digital filter, Rx DC notch filter:
692 * 0xc10~0xc13, 0xc18~0xc1b, 698 * 0xc10~0xc13, 0xc18~0xc1b,
693 * 0xc20~0xc23, 0xc28~0xc2b [16 bytes] */ 699 * 0xc20~0xc23, 0xc28~0xc2b [16 bytes]
700 */
694 u32 rfRxAFE; 701 u32 rfRxAFE;
695 /* OFDM Tx IQ imbalance matrix: 0xc80~0xc83, 0xc88~0xc8b, 702 /* OFDM Tx IQ imbalance matrix: 0xc80~0xc83, 0xc88~0xc8b,
696 * 0xc90~0xc93, 0xc98~0xc9b [16 bytes] */ 703 * 0xc90~0xc93, 0xc98~0xc9b [16 bytes]
704 */
697 u32 rfTxIQImbalance; 705 u32 rfTxIQImbalance;
698 /* Tx IQ DC Offset and Tx DFIR type: 706 /* Tx IQ DC Offset and Tx DFIR type:
699 * 0xc84~0xc87, 0xc8c~0xc8f, 707 * 0xc84~0xc87, 0xc8c~0xc8f,
700 * 0xc94~0xc97, 0xc9c~0xc9f [16 bytes] */ 708 * 0xc94~0xc97, 0xc9c~0xc9f [16 bytes]
709 */
701 u32 rfTxAFE; 710 u32 rfTxAFE;
702 /* LSSI RF readback data: 0x8a0~0x8af [16 bytes] */ 711 /* LSSI RF readback data: 0x8a0~0x8af [16 bytes] */
703 u32 rfLSSIReadBack; 712 u32 rfLSSIReadBack;
@@ -776,7 +785,8 @@ typedef struct _phy_ofdm_rx_status_report_819xusb {
776typedef struct _phy_cck_rx_status_report_819xusb { 785typedef struct _phy_cck_rx_status_report_819xusb {
777 /* For CCK rate descriptor. This is an unsigned 8:1 variable. 786 /* For CCK rate descriptor. This is an unsigned 8:1 variable.
778 * LSB bit presend 0.5. And MSB 7 bts presend a signed value. 787 * LSB bit presend 0.5. And MSB 7 bts presend a signed value.
779 * Range from -64~+63.5. */ 788 * Range from -64~+63.5.
789 */
780 u8 adc_pwdb_X[4]; 790 u8 adc_pwdb_X[4];
781 u8 sq_rpt; 791 u8 sq_rpt;
782 u8 cck_agc_rpt; 792 u8 cck_agc_rpt;
@@ -991,7 +1001,8 @@ typedef struct r8192_priv {
991 /* Control channel sub-carrier */ 1001 /* Control channel sub-carrier */
992 u8 nCur40MhzPrimeSC; 1002 u8 nCur40MhzPrimeSC;
993 /* Test for shorten RF configuration time. 1003 /* Test for shorten RF configuration time.
994 * We save RF reg0 in this variable to reduce RF reading. */ 1004 * We save RF reg0 in this variable to reduce RF reading.
1005 */
995 u32 RfReg0Value[4]; 1006 u32 RfReg0Value[4];
996 u8 NumTotalRFPath; 1007 u8 NumTotalRFPath;
997 bool brfpath_rxenable[4]; 1008 bool brfpath_rxenable[4];
@@ -1009,11 +1020,13 @@ typedef struct r8192_priv {
1009 1020
1010 bool bstore_last_dtpflag; 1021 bool bstore_last_dtpflag;
1011 /* Define to discriminate on High power State or 1022 /* Define to discriminate on High power State or
1012 * on sitesurvey to change Tx gain index */ 1023 * on sitesurvey to change Tx gain index
1024 */
1013 bool bstart_txctrl_bydtp; 1025 bool bstart_txctrl_bydtp;
1014 rate_adaptive rate_adaptive; 1026 rate_adaptive rate_adaptive;
1015 /* TX power tracking 1027 /* TX power tracking
1016 * OPEN/CLOSE TX POWER TRACKING */ 1028 * OPEN/CLOSE TX POWER TRACKING
1029 */
1017 txbbgain_struct txbbgain_table[TxBBGainTableLength]; 1030 txbbgain_struct txbbgain_table[TxBBGainTableLength];
1018 u8 txpower_count; /* For 6 sec do tracking again */ 1031 u8 txpower_count; /* For 6 sec do tracking again */
1019 bool btxpower_trackingInit; 1032 bool btxpower_trackingInit;
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index fdb03dccb449..b631990b4969 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -503,8 +503,7 @@ static void watch_dog_timer_callback(unsigned long data);
503 503
504/**************************************************************************** 504/****************************************************************************
505 * -----------------------------PROCFS STUFF------------------------- 505 * -----------------------------PROCFS STUFF-------------------------
506***************************************************************************** 506 ****************************************************************************/
507 */
508 507
509static struct proc_dir_entry *rtl8192_proc; 508static struct proc_dir_entry *rtl8192_proc;
510 509
@@ -715,8 +714,8 @@ static void rtl8192_proc_remove_one(struct net_device *dev)
715} 714}
716 715
717/**************************************************************************** 716/****************************************************************************
718 -----------------------------MISC STUFF------------------------- 717 * -----------------------------MISC STUFF-------------------------
719*****************************************************************************/ 718 *****************************************************************************/
720 719
721short check_nic_enough_desc(struct net_device *dev, int queue_index) 720short check_nic_enough_desc(struct net_device *dev, int queue_index)
722{ 721{
@@ -1009,7 +1008,7 @@ static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1009 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); 1008 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1010 int ret; 1009 int ret;
1011 unsigned long flags; 1010 unsigned long flags;
1012 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 1011 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1013 u8 queue_index = tcb_desc->queue_index; 1012 u8 queue_index = tcb_desc->queue_index;
1014 1013
1015 /* shall not be referred by command packet */ 1014 /* shall not be referred by command packet */
@@ -1035,7 +1034,7 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1035 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); 1034 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1036 int ret; 1035 int ret;
1037 unsigned long flags; 1036 unsigned long flags;
1038 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 1037 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1039 u8 queue_index = tcb_desc->queue_index; 1038 u8 queue_index = tcb_desc->queue_index;
1040 1039
1041 1040
@@ -1061,14 +1060,14 @@ static void rtl8192_tx_isr(struct urb *tx_urb)
1061 struct sk_buff *skb = (struct sk_buff *)tx_urb->context; 1060 struct sk_buff *skb = (struct sk_buff *)tx_urb->context;
1062 struct net_device *dev; 1061 struct net_device *dev;
1063 struct r8192_priv *priv = NULL; 1062 struct r8192_priv *priv = NULL;
1064 cb_desc *tcb_desc; 1063 struct cb_desc *tcb_desc;
1065 u8 queue_index; 1064 u8 queue_index;
1066 1065
1067 if (!skb) 1066 if (!skb)
1068 return; 1067 return;
1069 1068
1070 dev = *(struct net_device **)(skb->cb); 1069 dev = *(struct net_device **)(skb->cb);
1071 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 1070 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1072 queue_index = tcb_desc->queue_index; 1071 queue_index = tcb_desc->queue_index;
1073 1072
1074 priv = ieee80211_priv(dev); 1073 priv = ieee80211_priv(dev);
@@ -1285,7 +1284,7 @@ short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1285 struct urb *tx_urb; 1284 struct urb *tx_urb;
1286 unsigned int idx_pipe; 1285 unsigned int idx_pipe;
1287 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data; 1286 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
1288 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 1287 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1289 u8 queue_index = tcb_desc->queue_index; 1288 u8 queue_index = tcb_desc->queue_index;
1290 1289
1291 atomic_inc(&priv->tx_pending[queue_index]); 1290 atomic_inc(&priv->tx_pending[queue_index]);
@@ -1328,7 +1327,7 @@ short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
1328 * 2006.10.30 by Emily 1327 * 2006.10.30 by Emily
1329 * 1328 *
1330 * \param QUEUEID Software Queue 1329 * \param QUEUEID Software Queue
1331*/ 1330 */
1332static u8 MapHwQueueToFirmwareQueue(u8 QueueID) 1331static u8 MapHwQueueToFirmwareQueue(u8 QueueID)
1333{ 1332{
1334 u8 QueueSelect = 0x0; /* default set to */ 1333 u8 QueueSelect = 0x0; /* default set to */
@@ -1477,7 +1476,7 @@ static u8 MRateToHwRate8190Pci(u8 rate)
1477} 1476}
1478 1477
1479 1478
1480static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc) 1479static u8 QueryIsShort(u8 TxHT, u8 TxRate, struct cb_desc *tcb_desc)
1481{ 1480{
1482 u8 tmp_Short; 1481 u8 tmp_Short;
1483 1482
@@ -1499,11 +1498,11 @@ static void tx_zero_isr(struct urb *tx_urb)
1499 * The tx procedure is just as following, 1498 * The tx procedure is just as following,
1500 * skb->cb will contain all the following information, 1499 * skb->cb will contain all the following information,
1501 * priority, morefrag, rate, &dev. 1500 * priority, morefrag, rate, &dev.
1502 * */ 1501 */
1503short rtl8192_tx(struct net_device *dev, struct sk_buff *skb) 1502short rtl8192_tx(struct net_device *dev, struct sk_buff *skb)
1504{ 1503{
1505 struct r8192_priv *priv = ieee80211_priv(dev); 1504 struct r8192_priv *priv = ieee80211_priv(dev);
1506 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 1505 struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1507 tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data; 1506 tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data;
1508 tx_fwinfo_819x_usb *tx_fwinfo = 1507 tx_fwinfo_819x_usb *tx_fwinfo =
1509 (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN); 1508 (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);
@@ -1840,8 +1839,8 @@ static void rtl8192_update_beacon(struct work_struct *work)
1840} 1839}
1841 1840
1842/* 1841/*
1843* background support to run QoS activate functionality 1842 * background support to run QoS activate functionality
1844*/ 1843 */
1845static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK, 1844static int WDCAPARA_ADD[] = {EDCAPARA_BE, EDCAPARA_BK,
1846 EDCAPARA_VI, EDCAPARA_VO}; 1845 EDCAPARA_VI, EDCAPARA_VO};
1847static void rtl8192_qos_activate(struct work_struct *work) 1846static void rtl8192_qos_activate(struct work_struct *work)
@@ -1946,10 +1945,10 @@ static int rtl8192_handle_beacon(struct net_device *dev,
1946} 1945}
1947 1946
1948/* 1947/*
1949* handling the beaconing responses. if we get different QoS setting 1948 * handling the beaconing responses. if we get different QoS setting
1950* off the network from the associated setting, adjust the QoS 1949 * off the network from the associated setting, adjust the QoS
1951* setting 1950 * setting
1952*/ 1951 */
1953static int rtl8192_qos_association_resp(struct r8192_priv *priv, 1952static int rtl8192_qos_association_resp(struct r8192_priv *priv,
1954 struct ieee80211_network *network) 1953 struct ieee80211_network *network)
1955{ 1954{
@@ -3045,8 +3044,8 @@ static bool rtl8192_adapter_start(struct net_device *dev)
3045 * be used to stop beacon transmission 3044 * be used to stop beacon transmission
3046 */ 3045 */
3047/*************************************************************************** 3046/***************************************************************************
3048 -------------------------------NET STUFF--------------------------- 3047 * -------------------------------NET STUFF---------------------------
3049***************************************************************************/ 3048 ***************************************************************************/
3050 3049
3051static struct net_device_stats *rtl8192_stats(struct net_device *dev) 3050static struct net_device_stats *rtl8192_stats(struct net_device *dev)
3052{ 3051{
@@ -3074,9 +3073,9 @@ static bool HalTxCheckStuck819xUsb(struct net_device *dev)
3074} 3073}
3075 3074
3076/* 3075/*
3077* <Assumption: RT_TX_SPINLOCK is acquired.> 3076 * <Assumption: RT_TX_SPINLOCK is acquired.>
3078* First added: 2006.11.19 by emily 3077 * First added: 2006.11.19 by emily
3079*/ 3078 */
3080static RESET_TYPE TxCheckStuck(struct net_device *dev) 3079static RESET_TYPE TxCheckStuck(struct net_device *dev)
3081{ 3080{
3082 struct r8192_priv *priv = ieee80211_priv(dev); 3081 struct r8192_priv *priv = ieee80211_priv(dev);
@@ -4156,7 +4155,8 @@ static void rtl8192_process_phyinfo(struct r8192_priv *priv, u8 *buffer,
4156 * Output: NONE 4155 * Output: NONE
4157 * 4156 *
4158 * Return: 0-100 percentage 4157 * Return: 0-100 percentage
4159 *---------------------------------------------------------------------------*/ 4158 *---------------------------------------------------------------------------
4159 */
4160static u8 rtl819x_query_rxpwrpercentage(s8 antpower) 4160static u8 rtl819x_query_rxpwrpercentage(s8 antpower)
4161{ 4161{
4162 if ((antpower <= -100) || (antpower >= 20)) 4162 if ((antpower <= -100) || (antpower >= 20))
@@ -4529,19 +4529,19 @@ static void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
4529} 4529}
4530 4530
4531/** 4531/**
4532* Function: UpdateReceivedRateHistogramStatistics 4532 * Function: UpdateReceivedRateHistogramStatistics
4533* Overview: Record the received data rate 4533 * Overview: Record the received data rate
4534* 4534 *
4535* Input: 4535 * Input:
4536* struct net_device *dev 4536 * struct net_device *dev
4537* struct ieee80211_rx_stats *stats 4537 * struct ieee80211_rx_stats *stats
4538* 4538 *
4539* Output: 4539 * Output:
4540* 4540 *
4541* (priv->stats.ReceivedRateHistogram[] is updated) 4541 * (priv->stats.ReceivedRateHistogram[] is updated)
4542* Return: 4542 * Return:
4543* None 4543 * None
4544*/ 4544 */
4545static void 4545static void
4546UpdateReceivedRateHistogramStatistics8190(struct net_device *dev, 4546UpdateReceivedRateHistogramStatistics8190(struct net_device *dev,
4547 struct ieee80211_rx_stats *stats) 4547 struct ieee80211_rx_stats *stats)
@@ -4935,8 +4935,8 @@ static const struct net_device_ops rtl8192_netdev_ops = {
4935 4935
4936 4936
4937/**************************************************************************** 4937/****************************************************************************
4938 ---------------------------- USB_STUFF--------------------------- 4938 * ---------------------------- USB_STUFF---------------------------
4939*****************************************************************************/ 4939 *****************************************************************************/
4940 4940
4941static int rtl8192_usb_probe(struct usb_interface *intf, 4941static int rtl8192_usb_probe(struct usb_interface *intf,
4942 const struct usb_device_id *id) 4942 const struct usb_device_id *id)
@@ -5177,7 +5177,7 @@ void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
5177} 5177}
5178 5178
5179/*************************************************************************** 5179/***************************************************************************
5180 ------------------- module init / exit stubs ---------------- 5180 * ------------------- module init / exit stubs ----------------
5181****************************************************************************/ 5181 ****************************************************************************/
5182module_init(rtl8192_usb_module_init); 5182module_init(rtl8192_usb_module_init);
5183module_exit(rtl8192_usb_module_exit); 5183module_exit(rtl8192_usb_module_exit);
diff --git a/drivers/staging/rtl8192u/r8192U_hw.h b/drivers/staging/rtl8192u/r8192U_hw.h
index e07d65d04dbc..174ccf618d3e 100644
--- a/drivers/staging/rtl8192u/r8192U_hw.h
+++ b/drivers/staging/rtl8192u/r8192U_hw.h
@@ -1,18 +1,18 @@
1/* 1/*
2 This is part of rtl8187 OpenSource driver. 2 * This is part of rtl8187 OpenSource driver.
3 Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com> 3 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com>
4 Released under the terms of GPL (General Public Licence) 4 * Released under the terms of GPL (General Public Licence)
5 5 *
6 Parts of this driver are based on the GPL part of the 6 * Parts of this driver are based on the GPL part of the
7 official Realtek driver. 7 * official Realtek driver.
8 Parts of this driver are based on the rtl8180 driver skeleton 8 * Parts of this driver are based on the rtl8180 driver skeleton
9 from Patric Schenke & Andres Salomon. 9 * from Patric Schenke & Andres Salomon.
10 Parts of this driver are based on the Intel Pro Wireless 10 * Parts of this driver are based on the Intel Pro Wireless
11 2100 GPL driver. 11 * 2100 GPL driver.
12 12 *
13 We want to thank the Authors of those projects 13 * We want to thank the Authors of those projects
14 and the Ndiswrapper project Authors. 14 * and the Ndiswrapper project Authors.
15*/ 15 */
16 16
17/* Mariusz Matuszek added full registers definition with Realtek's name */ 17/* Mariusz Matuszek added full registers definition with Realtek's name */
18 18
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c
index d2f2f246063f..a9545386fbc5 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.c
+++ b/drivers/staging/rtl8192u/r8192U_wx.c
@@ -562,7 +562,7 @@ static int r8192_wx_set_enc(struct net_device *dev,
562 } 562 }
563 563
564 if (wrqu->encoding.length == 0x5) { 564 if (wrqu->encoding.length == 0x5) {
565 ieee->pairwise_key_type = KEY_TYPE_WEP40; 565 ieee->pairwise_key_type = KEY_TYPE_WEP40;
566 EnableHWSecurityConfig8192(dev); 566 EnableHWSecurityConfig8192(dev);
567 567
568 setKey(dev, 568 setKey(dev,
@@ -576,8 +576,8 @@ static int r8192_wx_set_enc(struct net_device *dev,
576 } 576 }
577 577
578 else if (wrqu->encoding.length == 0xd) { 578 else if (wrqu->encoding.length == 0xd) {
579 ieee->pairwise_key_type = KEY_TYPE_WEP104; 579 ieee->pairwise_key_type = KEY_TYPE_WEP104;
580 EnableHWSecurityConfig8192(dev); 580 EnableHWSecurityConfig8192(dev);
581 581
582 setKey(dev, 582 setKey(dev,
583 key_idx, /* EntryNo */ 583 key_idx, /* EntryNo */
diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.c b/drivers/staging/rtl8192u/r819xU_cmdpkt.c
index 545f49ec9c03..3e0731b04619 100644
--- a/drivers/staging/rtl8192u/r819xU_cmdpkt.c
+++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.c
@@ -30,16 +30,17 @@ rt_status SendTxCommandPacket(struct net_device *dev, void *pData, u32 DataLen)
30{ 30{
31 struct r8192_priv *priv = ieee80211_priv(dev); 31 struct r8192_priv *priv = ieee80211_priv(dev);
32 struct sk_buff *skb; 32 struct sk_buff *skb;
33 cb_desc *tcb_desc; 33 struct cb_desc *tcb_desc;
34 unsigned char *ptr_buf; 34 unsigned char *ptr_buf;
35 35
36 /* Get TCB and local buffer from common pool. 36 /* Get TCB and local buffer from common pool.
37 (It is shared by CmdQ, MgntQ, and USB coalesce DataQ) */ 37 * (It is shared by CmdQ, MgntQ, and USB coalesce DataQ)
38 */
38 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + DataLen + 4); 39 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + DataLen + 4);
39 if (!skb) 40 if (!skb)
40 return RT_STATUS_FAILURE; 41 return RT_STATUS_FAILURE;
41 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); 42 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
42 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 43 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
43 tcb_desc->queue_index = TXCMD_QUEUE; 44 tcb_desc->queue_index = TXCMD_QUEUE;
44 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_NORMAL; 45 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_NORMAL;
45 tcb_desc->bLastIniPkt = 0; 46 tcb_desc->bLastIniPkt = 0;
@@ -76,7 +77,8 @@ rt_status SendTxCommandPacket(struct net_device *dev, void *pData, u32 DataLen)
76 * When Who Remark 77 * When Who Remark
77 * 05/12/2008 amy Create Version 0 porting from windows code. 78 * 05/12/2008 amy Create Version 0 porting from windows code.
78 * 79 *
79 *---------------------------------------------------------------------------*/ 80 *---------------------------------------------------------------------------
81 */
80static void cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb) 82static void cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb)
81{ 83{
82 struct r8192_priv *priv = ieee80211_priv(dev); 84 struct r8192_priv *priv = ieee80211_priv(dev);
@@ -87,8 +89,9 @@ static void cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb)
87 (pu1Byte)(&rtState)); 89 (pu1Byte)(&rtState));
88 90
89 /* When RF is off, we should not count the packet for hw/sw synchronize 91 /* When RF is off, we should not count the packet for hw/sw synchronize
90 reason, ie. there may be a duration while sw switch is changed and 92 * reason, ie. there may be a duration while sw switch is changed and
91 hw switch is being changed. */ 93 * hw switch is being changed.
94 */
92 if (rtState == eRfOff) 95 if (rtState == eRfOff)
93 return; 96 return;
94#endif 97#endif
@@ -98,8 +101,9 @@ static void cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb)
98 return; 101 return;
99#endif 102#endif
100 /* We can not know the packet length and transmit type: 103 /* We can not know the packet length and transmit type:
101 broadcast or uni or multicast. So the relative statistics 104 * broadcast or uni or multicast. So the relative statistics
102 must be collected in tx feedback info. */ 105 * must be collected in tx feedback info.
106 */
103 if (pstx_fb->tok) { 107 if (pstx_fb->tok) {
104 priv->stats.txfeedbackok++; 108 priv->stats.txfeedbackok++;
105 priv->stats.txoktotal++; 109 priv->stats.txoktotal++;
@@ -133,11 +137,8 @@ static void cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb)
133 137
134 priv->stats.txretrycount += pstx_fb->retry_cnt; 138 priv->stats.txretrycount += pstx_fb->retry_cnt;
135 priv->stats.txfeedbackretry += pstx_fb->retry_cnt; 139 priv->stats.txfeedbackretry += pstx_fb->retry_cnt;
136
137} 140}
138 141
139
140
141/*----------------------------------------------------------------------------- 142/*-----------------------------------------------------------------------------
142 * Function: cmpk_handle_tx_feedback() 143 * Function: cmpk_handle_tx_feedback()
143 * 144 *
@@ -158,7 +159,8 @@ static void cmpk_count_txstatistic(struct net_device *dev, cmpk_txfb_t *pstx_fb)
158 * When Who Remark 159 * When Who Remark
159 * 05/08/2008 amy Create Version 0 porting from windows code. 160 * 05/08/2008 amy Create Version 0 porting from windows code.
160 * 161 *
161 *---------------------------------------------------------------------------*/ 162 *---------------------------------------------------------------------------
163 */
162static void cmpk_handle_tx_feedback(struct net_device *dev, u8 *pmsg) 164static void cmpk_handle_tx_feedback(struct net_device *dev, u8 *pmsg)
163{ 165{
164 struct r8192_priv *priv = ieee80211_priv(dev); 166 struct r8192_priv *priv = ieee80211_priv(dev);
@@ -168,8 +170,9 @@ static void cmpk_handle_tx_feedback(struct net_device *dev, u8 *pmsg)
168 170
169 /* 1. Extract TX feedback info from RFD to temp structure buffer. */ 171 /* 1. Extract TX feedback info from RFD to temp structure buffer. */
170 /* It seems that FW use big endian(MIPS) and DRV use little endian in 172 /* It seems that FW use big endian(MIPS) and DRV use little endian in
171 windows OS. So we have to read the content byte by byte or transfer 173 * windows OS. So we have to read the content byte by byte or transfer
172 endian type before copy the message copy. */ 174 * endian type before copy the message copy.
175 */
173 /* Use pointer to transfer structure memory. */ 176 /* Use pointer to transfer structure memory. */
174 memcpy((u8 *)&rx_tx_fb, pmsg, sizeof(cmpk_txfb_t)); 177 memcpy((u8 *)&rx_tx_fb, pmsg, sizeof(cmpk_txfb_t));
175 /* 2. Use tx feedback info to count TX statistics. */ 178 /* 2. Use tx feedback info to count TX statistics. */
@@ -177,8 +180,8 @@ static void cmpk_handle_tx_feedback(struct net_device *dev, u8 *pmsg)
177 /* Comment previous method for TX statistic function. */ 180 /* Comment previous method for TX statistic function. */
178 /* Collect info TX feedback packet to fill TCB. */ 181 /* Collect info TX feedback packet to fill TCB. */
179 /* We can not know the packet length and transmit type: broadcast or uni 182 /* We can not know the packet length and transmit type: broadcast or uni
180 or multicast. */ 183 * or multicast.
181 184 */
182} 185}
183 186
184static void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev) 187static void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev)
@@ -187,9 +190,9 @@ static void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev)
187 u16 tx_rate; 190 u16 tx_rate;
188 /* 87B have to S/W beacon for DTM encryption_cmn. */ 191 /* 87B have to S/W beacon for DTM encryption_cmn. */
189 if (priv->ieee80211->current_network.mode == IEEE_A || 192 if (priv->ieee80211->current_network.mode == IEEE_A ||
190 priv->ieee80211->current_network.mode == IEEE_N_5G || 193 priv->ieee80211->current_network.mode == IEEE_N_5G ||
191 (priv->ieee80211->current_network.mode == IEEE_N_24G && 194 (priv->ieee80211->current_network.mode == IEEE_N_24G &&
192 (!priv->ieee80211->pHTInfo->bCurSuppCCK))) { 195 (!priv->ieee80211->pHTInfo->bCurSuppCCK))) {
193 tx_rate = 60; 196 tx_rate = 60;
194 DMESG("send beacon frame tx rate is 6Mbpm\n"); 197 DMESG("send beacon frame tx rate is 6Mbpm\n");
195 } else { 198 } else {
@@ -198,13 +201,8 @@ static void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev)
198 } 201 }
199 202
200 rtl819xusb_beacon_tx(dev, tx_rate); /* HW Beacon */ 203 rtl819xusb_beacon_tx(dev, tx_rate); /* HW Beacon */
201
202
203} 204}
204 205
205
206
207
208/*----------------------------------------------------------------------------- 206/*-----------------------------------------------------------------------------
209 * Function: cmpk_handle_interrupt_status() 207 * Function: cmpk_handle_interrupt_status()
210 * 208 *
@@ -224,7 +222,8 @@ static void cmdpkt_beacontimerinterrupt_819xusb(struct net_device *dev)
224 * When Who Remark 222 * When Who Remark
225 * 05/12/2008 amy Add this for rtl8192 porting from windows code. 223 * 05/12/2008 amy Add this for rtl8192 porting from windows code.
226 * 224 *
227 *---------------------------------------------------------------------------*/ 225 *---------------------------------------------------------------------------
226 */
228static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg) 227static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg)
229{ 228{
230 cmpk_intr_sta_t rx_intr_status; /* */ 229 cmpk_intr_sta_t rx_intr_status; /* */
@@ -234,15 +233,15 @@ static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg)
234 233
235 /* 1. Extract TX feedback info from RFD to temp structure buffer. */ 234 /* 1. Extract TX feedback info from RFD to temp structure buffer. */
236 /* It seems that FW use big endian(MIPS) and DRV use little endian in 235 /* It seems that FW use big endian(MIPS) and DRV use little endian in
237 windows OS. So we have to read the content byte by byte or transfer 236 * windows OS. So we have to read the content byte by byte or transfer
238 endian type before copy the message copy. */ 237 * endian type before copy the message copy.
238 */
239 rx_intr_status.length = pmsg[1]; 239 rx_intr_status.length = pmsg[1];
240 if (rx_intr_status.length != (sizeof(cmpk_intr_sta_t) - 2)) { 240 if (rx_intr_status.length != (sizeof(cmpk_intr_sta_t) - 2)) {
241 DMESG("cmpk_Handle_Interrupt_Status: wrong length!\n"); 241 DMESG("cmpk_Handle_Interrupt_Status: wrong length!\n");
242 return; 242 return;
243 } 243 }
244 244
245
246 /* Statistics of beacon for ad-hoc mode. */ 245 /* Statistics of beacon for ad-hoc mode. */
247 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) { 246 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) {
248 /* 2 maybe need endian transform? */ 247 /* 2 maybe need endian transform? */
@@ -261,17 +260,13 @@ static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg)
261 260
262 if (rx_intr_status.interrupt_status & ISR_BcnTimerIntr) 261 if (rx_intr_status.interrupt_status & ISR_BcnTimerIntr)
263 cmdpkt_beacontimerinterrupt_819xusb(dev); 262 cmdpkt_beacontimerinterrupt_819xusb(dev);
264
265 } 263 }
266 264
267 /* Other informations in interrupt status we need? */ 265 /* Other informations in interrupt status we need? */
268 266
269
270 DMESG("<---- cmpk_handle_interrupt_status()\n"); 267 DMESG("<---- cmpk_handle_interrupt_status()\n");
271
272} 268}
273 269
274
275/*----------------------------------------------------------------------------- 270/*-----------------------------------------------------------------------------
276 * Function: cmpk_handle_query_config_rx() 271 * Function: cmpk_handle_query_config_rx()
277 * 272 *
@@ -290,16 +285,17 @@ static void cmpk_handle_interrupt_status(struct net_device *dev, u8 *pmsg)
290 * When Who Remark 285 * When Who Remark
291 * 05/12/2008 amy Create Version 0 porting from windows code. 286 * 05/12/2008 amy Create Version 0 porting from windows code.
292 * 287 *
293 *---------------------------------------------------------------------------*/ 288 *---------------------------------------------------------------------------
289 */
294static void cmpk_handle_query_config_rx(struct net_device *dev, u8 *pmsg) 290static void cmpk_handle_query_config_rx(struct net_device *dev, u8 *pmsg)
295{ 291{
296 cmpk_query_cfg_t rx_query_cfg; 292 cmpk_query_cfg_t rx_query_cfg;
297 293
298
299 /* 1. Extract TX feedback info from RFD to temp structure buffer. */ 294 /* 1. Extract TX feedback info from RFD to temp structure buffer. */
300 /* It seems that FW use big endian(MIPS) and DRV use little endian in 295 /* It seems that FW use big endian(MIPS) and DRV use little endian in
301 windows OS. So we have to read the content byte by byte or transfer 296 * windows OS. So we have to read the content byte by byte or transfer
302 endian type before copy the message copy. */ 297 * endian type before copy the message copy.
298 */
303 rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000) >> 31; 299 rx_query_cfg.cfg_action = (pmsg[4] & 0x80000000) >> 31;
304 rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5; 300 rx_query_cfg.cfg_type = (pmsg[4] & 0x60) >> 5;
305 rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3; 301 rx_query_cfg.cfg_size = (pmsg[4] & 0x18) >> 3;
@@ -309,10 +305,8 @@ static void cmpk_handle_query_config_rx(struct net_device *dev, u8 *pmsg)
309 (pmsg[10] << 8) | (pmsg[11] << 0); 305 (pmsg[10] << 8) | (pmsg[11] << 0);
310 rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) | 306 rx_query_cfg.mask = (pmsg[12] << 24) | (pmsg[13] << 16) |
311 (pmsg[14] << 8) | (pmsg[15] << 0); 307 (pmsg[14] << 8) | (pmsg[15] << 0);
312
313} 308}
314 309
315
316/*----------------------------------------------------------------------------- 310/*-----------------------------------------------------------------------------
317 * Function: cmpk_count_tx_status() 311 * Function: cmpk_count_tx_status()
318 * 312 *
@@ -329,7 +323,8 @@ static void cmpk_handle_query_config_rx(struct net_device *dev, u8 *pmsg)
329 * When Who Remark 323 * When Who Remark
330 * 05/12/2008 amy Create Version 0 porting from windows code. 324 * 05/12/2008 amy Create Version 0 porting from windows code.
331 * 325 *
332 *---------------------------------------------------------------------------*/ 326 *---------------------------------------------------------------------------
327 */
333static void cmpk_count_tx_status(struct net_device *dev, 328static void cmpk_count_tx_status(struct net_device *dev,
334 cmpk_tx_status_t *pstx_status) 329 cmpk_tx_status_t *pstx_status)
335{ 330{
@@ -343,8 +338,9 @@ static void cmpk_count_tx_status(struct net_device *dev,
343 (pu1Byte)(&rtState)); 338 (pu1Byte)(&rtState));
344 339
345 /* When RF is off, we should not count the packet for hw/sw synchronize 340 /* When RF is off, we should not count the packet for hw/sw synchronize
346 reason, ie. there may be a duration while sw switch is changed and 341 * reason, ie. there may be a duration while sw switch is changed and
347 hw switch is being changed. */ 342 * hw switch is being changed.
343 */
348 if (rtState == eRfOff) 344 if (rtState == eRfOff)
349 return; 345 return;
350#endif 346#endif
@@ -374,8 +370,6 @@ static void cmpk_count_tx_status(struct net_device *dev,
374 priv->stats.last_packet_rate = pstx_status->rate; 370 priv->stats.last_packet_rate = pstx_status->rate;
375} 371}
376 372
377
378
379/*----------------------------------------------------------------------------- 373/*-----------------------------------------------------------------------------
380 * Function: cmpk_handle_tx_status() 374 * Function: cmpk_handle_tx_status()
381 * 375 *
@@ -392,7 +386,8 @@ static void cmpk_count_tx_status(struct net_device *dev,
392 * When Who Remark 386 * When Who Remark
393 * 05/12/2008 amy Create Version 0 porting from windows code. 387 * 05/12/2008 amy Create Version 0 porting from windows code.
394 * 388 *
395 *---------------------------------------------------------------------------*/ 389 *---------------------------------------------------------------------------
390 */
396static void cmpk_handle_tx_status(struct net_device *dev, u8 *pmsg) 391static void cmpk_handle_tx_status(struct net_device *dev, u8 *pmsg)
397{ 392{
398 cmpk_tx_status_t rx_tx_sts; 393 cmpk_tx_status_t rx_tx_sts;
@@ -400,10 +395,8 @@ static void cmpk_handle_tx_status(struct net_device *dev, u8 *pmsg)
400 memcpy((void *)&rx_tx_sts, (void *)pmsg, sizeof(cmpk_tx_status_t)); 395 memcpy((void *)&rx_tx_sts, (void *)pmsg, sizeof(cmpk_tx_status_t));
401 /* 2. Use tx feedback info to count TX statistics. */ 396 /* 2. Use tx feedback info to count TX statistics. */
402 cmpk_count_tx_status(dev, &rx_tx_sts); 397 cmpk_count_tx_status(dev, &rx_tx_sts);
403
404} 398}
405 399
406
407/*----------------------------------------------------------------------------- 400/*-----------------------------------------------------------------------------
408 * Function: cmpk_handle_tx_rate_history() 401 * Function: cmpk_handle_tx_rate_history()
409 * 402 *
@@ -419,7 +412,8 @@ static void cmpk_handle_tx_status(struct net_device *dev, u8 *pmsg)
419 * When Who Remark 412 * When Who Remark
420 * 05/12/2008 amy Create Version 0 porting from windows code. 413 * 05/12/2008 amy Create Version 0 porting from windows code.
421 * 414 *
422 *---------------------------------------------------------------------------*/ 415 *---------------------------------------------------------------------------
416 */
423static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg) 417static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
424{ 418{
425 cmpk_tx_rahis_t *ptxrate; 419 cmpk_tx_rahis_t *ptxrate;
@@ -428,14 +422,14 @@ static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
428 u32 *ptemp; 422 u32 *ptemp;
429 struct r8192_priv *priv = ieee80211_priv(dev); 423 struct r8192_priv *priv = ieee80211_priv(dev);
430 424
431
432#ifdef ENABLE_PS 425#ifdef ENABLE_PS
433 pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE, 426 pAdapter->HalFunc.GetHwRegHandler(pAdapter, HW_VAR_RF_STATE,
434 (pu1Byte)(&rtState)); 427 (pu1Byte)(&rtState));
435 428
436 /* When RF is off, we should not count the packet for hw/sw synchronize 429 /* When RF is off, we should not count the packet for hw/sw synchronize
437 reason, ie. there may be a duration while sw switch is changed and 430 * reason, ie. there may be a duration while sw switch is changed and
438 hw switch is being changed. */ 431 * hw switch is being changed.
432 */
439 if (rtState == eRfOff) 433 if (rtState == eRfOff)
440 return; 434 return;
441#endif 435#endif
@@ -443,7 +437,8 @@ static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
443 ptemp = (u32 *)pmsg; 437 ptemp = (u32 *)pmsg;
444 438
445 /* Do endian transfer to word alignment(16 bits) for windows system. 439 /* Do endian transfer to word alignment(16 bits) for windows system.
446 You must do different endian transfer for linux and MAC OS */ 440 * You must do different endian transfer for linux and MAC OS
441 */
447 for (i = 0; i < (length/4); i++) { 442 for (i = 0; i < (length/4); i++) {
448 u16 temp1, temp2; 443 u16 temp1, temp2;
449 444
@@ -469,10 +464,8 @@ static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
469 for (j = 0; j < 4; j++) 464 for (j = 0; j < 4; j++)
470 priv->stats.txrate.ht_mcs[j][i] += ptxrate->ht_mcs[j][i]; 465 priv->stats.txrate.ht_mcs[j][i] += ptxrate->ht_mcs[j][i];
471 } 466 }
472
473} 467}
474 468
475
476/*----------------------------------------------------------------------------- 469/*-----------------------------------------------------------------------------
477 * Function: cmpk_message_handle_rx() 470 * Function: cmpk_message_handle_rx()
478 * 471 *
@@ -492,7 +485,8 @@ static void cmpk_handle_tx_rate_history(struct net_device *dev, u8 *pmsg)
492 * When Who Remark 485 * When Who Remark
493 * 05/06/2008 amy Create Version 0 porting from windows code. 486 * 05/06/2008 amy Create Version 0 porting from windows code.
494 * 487 *
495 *---------------------------------------------------------------------------*/ 488 *---------------------------------------------------------------------------
489 */
496u32 cmpk_message_handle_rx(struct net_device *dev, 490u32 cmpk_message_handle_rx(struct net_device *dev,
497 struct ieee80211_rx_stats *pstats) 491 struct ieee80211_rx_stats *pstats)
498{ 492{
@@ -502,7 +496,8 @@ u32 cmpk_message_handle_rx(struct net_device *dev,
502 u8 *pcmd_buff; 496 u8 *pcmd_buff;
503 497
504 /* 0. Check inpt arguments. If is is a command queue message or 498 /* 0. Check inpt arguments. If is is a command queue message or
505 pointer is null. */ 499 * pointer is null.
500 */
506 if (pstats == NULL) 501 if (pstats == NULL)
507 return 0; /* This is not a command packet. */ 502 return 0; /* This is not a command packet. */
508 503
@@ -516,10 +511,12 @@ u32 cmpk_message_handle_rx(struct net_device *dev,
516 element_id = pcmd_buff[0]; 511 element_id = pcmd_buff[0];
517 512
518 /* 4. Check every received command packet content according to different 513 /* 4. Check every received command packet content according to different
519 element type. Because FW may aggregate RX command packet to 514 * element type. Because FW may aggregate RX command packet to
520 minimize transmit time between DRV and FW.*/ 515 * minimize transmit time between DRV and FW.
516 */
521 /* Add a counter to prevent the lock in the loop from being held too 517 /* Add a counter to prevent the lock in the loop from being held too
522 long */ 518 * long
519 */
523 while (total_length > 0 && exe_cnt++ < 100) { 520 while (total_length > 0 && exe_cnt++ < 100) {
524 /* We support aggregation of different cmd in the same packet */ 521 /* We support aggregation of different cmd in the same packet */
525 element_id = pcmd_buff[0]; 522 element_id = pcmd_buff[0];
@@ -547,7 +544,8 @@ u32 cmpk_message_handle_rx(struct net_device *dev,
547 544
548 case RX_TX_PER_PKT_FEEDBACK: 545 case RX_TX_PER_PKT_FEEDBACK:
549 /* You must at lease add a switch case element here, 546 /* You must at lease add a switch case element here,
550 Otherwise, we will jump to default case. */ 547 * Otherwise, we will jump to default case.
548 */
551 cmd_length = CMPK_RX_TX_FB_SIZE; 549 cmd_length = CMPK_RX_TX_FB_SIZE;
552 break; 550 break;
553 551
@@ -567,5 +565,4 @@ u32 cmpk_message_handle_rx(struct net_device *dev,
567 pcmd_buff += cmd_length; 565 pcmd_buff += cmd_length;
568 } 566 }
569 return 1; /* This is a command packet. */ 567 return 1; /* This is a command packet. */
570
571} 568}
diff --git a/drivers/staging/rtl8192u/r819xU_cmdpkt.h b/drivers/staging/rtl8192u/r819xU_cmdpkt.h
index f490e253ee50..ad0f6003570d 100644
--- a/drivers/staging/rtl8192u/r819xU_cmdpkt.h
+++ b/drivers/staging/rtl8192u/r819xU_cmdpkt.h
@@ -55,7 +55,8 @@ typedef struct tag_cmd_pkt_tx_feedback {
55} cmpk_txfb_t; 55} cmpk_txfb_t;
56 56
57/* 2. RX side: Interrupt status packet. It includes Beacon State, 57/* 2. RX side: Interrupt status packet. It includes Beacon State,
58 * Beacon Timer Interrupt and other useful informations in MAC ISR Reg. */ 58 * Beacon Timer Interrupt and other useful informations in MAC ISR Reg.
59 */
59typedef struct tag_cmd_pkt_interrupt_status { 60typedef struct tag_cmd_pkt_interrupt_status {
60 u8 element_id; /* Command packet type. */ 61 u8 element_id; /* Command packet type. */
61 u8 length; /* Command packet length. */ 62 u8 length; /* Command packet length. */
@@ -83,13 +84,15 @@ typedef struct tag_cmd_pkt_set_configuration {
83} cmpk_set_cfg_t; 84} cmpk_set_cfg_t;
84 85
85/* 4. Both side : TX/RX query configuraton packet. The query structure is the 86/* 4. Both side : TX/RX query configuraton packet. The query structure is the
86 same as set configuration. */ 87 * same as set configuration.
88 */
87#define cmpk_query_cfg_t cmpk_set_cfg_t 89#define cmpk_query_cfg_t cmpk_set_cfg_t
88 90
89/* 5. Multi packet feedback status. */ 91/* 5. Multi packet feedback status. */
90typedef struct tag_tx_stats_feedback { 92typedef struct tag_tx_stats_feedback {
91 /* For endian transfer --> Driver will not the same as 93 /* For endian transfer --> Driver will not the same as
92 firmware structure. */ 94 * firmware structure.
95 */
93 /* DW 0 */ 96 /* DW 0 */
94 u16 reserve1; 97 u16 reserve1;
95 u8 length; /* Command packet length */ 98 u8 length; /* Command packet length */
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
index 08302dfb0d90..35d1786703a7 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.c
+++ b/drivers/staging/rtl8192u/r819xU_firmware.c
@@ -10,7 +10,7 @@
10 * Returns: 10 * Returns:
11 * NDIS_STATUS_FAILURE - the following initialization process should be terminated 11 * NDIS_STATUS_FAILURE - the following initialization process should be terminated
12 * NDIS_STATUS_SUCCESS - if firmware initialization process success 12 * NDIS_STATUS_SUCCESS - if firmware initialization process success
13**************************************************************************************************/ 13 **************************************************************************************************/
14 14
15#include "r8192U.h" 15#include "r8192U.h"
16#include "r8192U_hw.h" 16#include "r8192U_hw.h"
@@ -42,7 +42,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
42 rt_firmware *pfirmware = priv->pFirmware; 42 rt_firmware *pfirmware = priv->pFirmware;
43 struct sk_buff *skb; 43 struct sk_buff *skb;
44 unsigned char *seg_ptr; 44 unsigned char *seg_ptr;
45 cb_desc *tcb_desc; 45 struct cb_desc *tcb_desc;
46 u8 bLastIniPkt; 46 u8 bLastIniPkt;
47 u8 index; 47 u8 index;
48 48
@@ -62,12 +62,12 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
62 62
63 /* Allocate skb buffer to contain firmware info and tx descriptor info 63 /* Allocate skb buffer to contain firmware info and tx descriptor info
64 * add 4 to avoid packet appending overflow. 64 * add 4 to avoid packet appending overflow.
65 * */ 65 */
66 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + frag_length + 4); 66 skb = dev_alloc_skb(USB_HWDESC_HEADER_LEN + frag_length + 4);
67 if (!skb) 67 if (!skb)
68 return false; 68 return false;
69 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); 69 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
70 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); 70 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
71 tcb_desc->queue_index = TXCMD_QUEUE; 71 tcb_desc->queue_index = TXCMD_QUEUE;
72 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_INIT; 72 tcb_desc->bCmdOrInit = DESC_PACKET_TYPE_INIT;
73 tcb_desc->bLastIniPkt = bLastIniPkt; 73 tcb_desc->bLastIniPkt = bLastIniPkt;
@@ -277,7 +277,7 @@ bool init_firmware(struct net_device *dev)
277 * 2. each packet segment will be put in the skb_buff packet. 277 * 2. each packet segment will be put in the skb_buff packet.
278 * 3. each skb_buff packet data content will already include the firmware info 278 * 3. each skb_buff packet data content will already include the firmware info
279 * and Tx descriptor info 279 * and Tx descriptor info
280 * */ 280 */
281 rt_status = fw_download_code(dev, mapped_file, file_length); 281 rt_status = fw_download_code(dev, mapped_file, file_length);
282 if (rst_opt == OPT_SYSTEM_RESET) 282 if (rst_opt == OPT_SYSTEM_RESET)
283 release_firmware(fw_entry); 283 release_firmware(fw_entry);
diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c
index 696df3440077..c99130fdb8ee 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -367,7 +367,8 @@ static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
367 /* Firmware RF Write control. 367 /* Firmware RF Write control.
368 * We can not execute the scheme in the initial step. 368 * We can not execute the scheme in the initial step.
369 * Otherwise, RF-R/W will waste much time. 369 * Otherwise, RF-R/W will waste much time.
370 * This is only for site survey. */ 370 * This is only for site survey.
371 */
371 /* 1. Read operation need not insert data. bit 0-11 */ 372 /* 1. Read operation need not insert data. bit 0-11 */
372 /* 2. Write RF register address. bit 12-19 */ 373 /* 2. Write RF register address. bit 12-19 */
373 data |= ((offset&0xFF)<<12); 374 data |= ((offset&0xFF)<<12);
@@ -380,7 +381,8 @@ static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
380 read_nic_dword(dev, QPNR, &tmp); 381 read_nic_dword(dev, QPNR, &tmp);
381 while (tmp & 0x80000000) { 382 while (tmp & 0x80000000) {
382 /* If FW can not finish RF-R/W for more than ?? times. 383 /* If FW can not finish RF-R/W for more than ?? times.
383 We must reset FW. */ 384 * We must reset FW.
385 */
384 if (time++ < 100) { 386 if (time++ < 100) {
385 udelay(10); 387 udelay(10);
386 read_nic_dword(dev, QPNR, &tmp); 388 read_nic_dword(dev, QPNR, &tmp);
@@ -394,7 +396,8 @@ static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
394 read_nic_dword(dev, QPNR, &tmp); 396 read_nic_dword(dev, QPNR, &tmp);
395 while (tmp & 0x80000000) { 397 while (tmp & 0x80000000) {
396 /* If FW can not finish RF-R/W for more than ?? times. 398 /* If FW can not finish RF-R/W for more than ?? times.
397 We must reset FW. */ 399 * We must reset FW.
400 */
398 if (time++ < 100) { 401 if (time++ < 100) {
399 udelay(10); 402 udelay(10);
400 read_nic_dword(dev, QPNR, &tmp); 403 read_nic_dword(dev, QPNR, &tmp);
@@ -426,7 +429,8 @@ static void phy_FwRFSerialWrite(struct net_device *dev,
426 /* Firmware RF Write control. 429 /* Firmware RF Write control.
427 * We can not execute the scheme in the initial step. 430 * We can not execute the scheme in the initial step.
428 * Otherwise, RF-R/W will waste much time. 431 * Otherwise, RF-R/W will waste much time.
429 * This is only for site survey. */ 432 * This is only for site survey.
433 */
430 434
431 /* 1. Set driver write bit and 12 bit data. bit 0-11 */ 435 /* 1. Set driver write bit and 12 bit data. bit 0-11 */
432 /* 2. Write RF register address. bit 12-19 */ 436 /* 2. Write RF register address. bit 12-19 */
@@ -442,7 +446,8 @@ static void phy_FwRFSerialWrite(struct net_device *dev,
442 read_nic_dword(dev, QPNR, &tmp); 446 read_nic_dword(dev, QPNR, &tmp);
443 while (tmp & 0x80000000) { 447 while (tmp & 0x80000000) {
444 /* If FW can not finish RF-R/W for more than ?? times. 448 /* If FW can not finish RF-R/W for more than ?? times.
445 We must reset FW. */ 449 * We must reset FW.
450 */
446 if (time++ < 100) { 451 if (time++ < 100) {
447 udelay(10); 452 udelay(10);
448 read_nic_dword(dev, QPNR, &tmp); 453 read_nic_dword(dev, QPNR, &tmp);
@@ -451,10 +456,12 @@ static void phy_FwRFSerialWrite(struct net_device *dev,
451 } 456 }
452 } 457 }
453 /* 7. No matter check bit. We always force the write. 458 /* 7. No matter check bit. We always force the write.
454 Because FW will not accept the command. */ 459 * Because FW will not accept the command.
460 */
455 write_nic_dword(dev, QPNR, data); 461 write_nic_dword(dev, QPNR, data);
456 /* According to test, we must delay 20us to wait firmware 462 /* According to test, we must delay 20us to wait firmware
457 to finish RF write operation. */ 463 * to finish RF write operation.
464 */
458 /* We support delay in firmware side now. */ 465 /* We support delay in firmware side now. */
459} 466}
460 467
@@ -723,7 +730,8 @@ u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, HW90_BLOCK_E CheckBlock,
723 WriteAddr[HW90_BLOCK_RF], 730 WriteAddr[HW90_BLOCK_RF],
724 bMask12Bits, WriteData[i]); 731 bMask12Bits, WriteData[i]);
725 /* TODO: we should not delay for such a long time. 732 /* TODO: we should not delay for such a long time.
726 Ask SD3 */ 733 * Ask SD3
734 */
727 usleep_range(1000, 1000); 735 usleep_range(1000, 1000);
728 reg = rtl8192_phy_QueryRFReg(dev, eRFPath, 736 reg = rtl8192_phy_QueryRFReg(dev, eRFPath,
729 WriteAddr[HW90_BLOCK_RF], 737 WriteAddr[HW90_BLOCK_RF],
@@ -820,7 +828,8 @@ static void rtl8192_BB_Config_ParaFile(struct net_device *dev)
820 } 828 }
821 829
822 /* Check if the CCK HighPower is turned ON. 830 /* Check if the CCK HighPower is turned ON.
823 This is used to calculate PWDB. */ 831 * This is used to calculate PWDB.
832 */
824 priv->bCckHighPower = (u8)rtl8192_QueryBBReg(dev, 833 priv->bCckHighPower = (u8)rtl8192_QueryBBReg(dev,
825 rFPGA0_XA_HSSIParameter2, 834 rFPGA0_XA_HSSIParameter2,
826 0x200); 835 0x200);
@@ -839,7 +848,8 @@ void rtl8192_BBConfig(struct net_device *dev)
839 rtl8192_InitBBRFRegDef(dev); 848 rtl8192_InitBBRFRegDef(dev);
840 /* config BB&RF. As hardCode based initialization has not been well 849 /* config BB&RF. As hardCode based initialization has not been well
841 * implemented, so use file first. 850 * implemented, so use file first.
842 * FIXME: should implement it for hardcode? */ 851 * FIXME: should implement it for hardcode?
852 */
843 rtl8192_BB_Config_ParaFile(dev); 853 rtl8192_BB_Config_ParaFile(dev);
844} 854}
845 855
@@ -1158,7 +1168,8 @@ bool rtl8192_SetRFPowerState(struct net_device *dev,
1158 switch (pHalData->eRFPowerState) { 1168 switch (pHalData->eRFPowerState) {
1159 case eRfOff: 1169 case eRfOff:
1160 /* If Rf off reason is from IPS, 1170 /* If Rf off reason is from IPS,
1161 LED should blink with no link */ 1171 * LED should blink with no link
1172 */
1162 if (pMgntInfo->RfOffReason == RF_CHANGE_BY_IPS) 1173 if (pMgntInfo->RfOffReason == RF_CHANGE_BY_IPS)
1163 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK); 1174 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
1164 else 1175 else
@@ -1168,7 +1179,7 @@ bool rtl8192_SetRFPowerState(struct net_device *dev,
1168 1179
1169 case eRfOn: 1180 case eRfOn:
1170 /* Turn on RF we are still linked, which might 1181 /* Turn on RF we are still linked, which might
1171 happen when we quickly turn off and on HW RF. 1182 * happen when we quickly turn off and on HW RF.
1172 */ 1183 */
1173 if (pMgntInfo->bMediaConnect) 1184 if (pMgntInfo->bMediaConnect)
1174 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_LINK); 1185 Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_LINK);
@@ -1263,7 +1274,8 @@ static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
1263 if (!IsLegalChannel(priv->ieee80211, channel)) { 1274 if (!IsLegalChannel(priv->ieee80211, channel)) {
1264 RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel); 1275 RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel);
1265 /* return true to tell upper caller function this channel 1276 /* return true to tell upper caller function this channel
1266 setting is finished! Or it will in while loop. */ 1277 * setting is finished! Or it will in while loop.
1278 */
1267 return true; 1279 return true;
1268 } 1280 }
1269 /* FIXME: need to check whether channel is legal or not here */ 1281 /* FIXME: need to check whether channel is legal or not here */
@@ -1609,7 +1621,8 @@ void rtl8192_SetBWModeWorkItem(struct net_device *dev)
1609 1621
1610 } 1622 }
1611 /* Skip over setting of J-mode in BB register here. 1623 /* Skip over setting of J-mode in BB register here.
1612 Default value is "None J mode". */ 1624 * Default value is "None J mode".
1625 */
1613 1626
1614 /* <3> Set RF related register */ 1627 /* <3> Set RF related register */
1615 switch (priv->rf_chip) { 1628 switch (priv->rf_chip) {
diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c
index 0dd458d1402c..c83d7ebb164f 100644
--- a/drivers/staging/rtl8712/hal_init.c
+++ b/drivers/staging/rtl8712/hal_init.c
@@ -117,16 +117,16 @@ static void fill_fwpriv(struct _adapter *padapter, struct fw_priv *pfwpriv)
117 117
118static void update_fwhdr(struct fw_hdr *pfwhdr, const u8 *pmappedfw) 118static void update_fwhdr(struct fw_hdr *pfwhdr, const u8 *pmappedfw)
119{ 119{
120 pfwhdr->signature = le16_to_cpu(*(u16 *)pmappedfw); 120 pfwhdr->signature = le16_to_cpu(*(__le16 *)pmappedfw);
121 pfwhdr->version = le16_to_cpu(*(u16 *)(pmappedfw + 2)); 121 pfwhdr->version = le16_to_cpu(*(__le16 *)(pmappedfw + 2));
122 /* define the size of boot loader */ 122 /* define the size of boot loader */
123 pfwhdr->dmem_size = le32_to_cpu(*(uint *)(pmappedfw + 4)); 123 pfwhdr->dmem_size = le32_to_cpu(*(__le32 *)(pmappedfw + 4));
124 /* define the size of FW in IMEM */ 124 /* define the size of FW in IMEM */
125 pfwhdr->img_IMEM_size = le32_to_cpu(*(uint *)(pmappedfw + 8)); 125 pfwhdr->img_IMEM_size = le32_to_cpu(*(__le32 *)(pmappedfw + 8));
126 /* define the size of FW in SRAM */ 126 /* define the size of FW in SRAM */
127 pfwhdr->img_SRAM_size = le32_to_cpu(*(uint *)(pmappedfw + 12)); 127 pfwhdr->img_SRAM_size = le32_to_cpu(*(__le32 *)(pmappedfw + 12));
128 /* define the size of DMEM variable */ 128 /* define the size of DMEM variable */
129 pfwhdr->fw_priv_sz = le32_to_cpu(*(uint *)(pmappedfw + 16)); 129 pfwhdr->fw_priv_sz = le32_to_cpu(*(__le32 *)(pmappedfw + 16));
130} 130}
131 131
132static u8 chk_fwhdr(struct fw_hdr *pfwhdr, u32 ulfilelength) 132static u8 chk_fwhdr(struct fw_hdr *pfwhdr, u32 ulfilelength)
diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
index 5dc3b5b9bfff..d84da2b6d6b3 100644
--- a/drivers/staging/rtl8712/ieee80211.c
+++ b/drivers/staging/rtl8712/ieee80211.c
@@ -174,16 +174,16 @@ int r8712_generate_ie(struct registry_priv *pregistrypriv)
174 sz += 8; 174 sz += 8;
175 ie += sz; 175 ie += sz;
176 /*beacon interval : 2bytes*/ 176 /*beacon interval : 2bytes*/
177 *(u16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod); 177 *(__le16 *)ie = cpu_to_le16((u16)pdev_network->Configuration.BeaconPeriod);
178 sz += 2; 178 sz += 2;
179 ie += 2; 179 ie += 2;
180 /*capability info*/ 180 /*capability info*/
181 *(u16 *)ie = 0; 181 *(u16 *)ie = 0;
182 *(u16 *)ie |= cpu_to_le16(cap_IBSS); 182 *(__le16 *)ie |= cpu_to_le16(cap_IBSS);
183 if (pregistrypriv->preamble == PREAMBLE_SHORT) 183 if (pregistrypriv->preamble == PREAMBLE_SHORT)
184 *(u16 *)ie |= cpu_to_le16(cap_ShortPremble); 184 *(__le16 *)ie |= cpu_to_le16(cap_ShortPremble);
185 if (pdev_network->Privacy) 185 if (pdev_network->Privacy)
186 *(u16 *)ie |= cpu_to_le16(cap_Privacy); 186 *(__le16 *)ie |= cpu_to_le16(cap_Privacy);
187 sz += 2; 187 sz += 2;
188 ie += 2; 188 ie += 2;
189 /*SSID*/ 189 /*SSID*/
@@ -202,10 +202,10 @@ int r8712_generate_ie(struct registry_priv *pregistrypriv)
202 rateLen, pdev_network->rates, &sz); 202 rateLen, pdev_network->rates, &sz);
203 /*DS parameter set*/ 203 /*DS parameter set*/
204 ie = r8712_set_ie(ie, _DSSET_IE_, 1, 204 ie = r8712_set_ie(ie, _DSSET_IE_, 1,
205 (u8 *)&(pdev_network->Configuration.DSConfig), &sz); 205 (u8 *)&pdev_network->Configuration.DSConfig, &sz);
206 /*IBSS Parameter Set*/ 206 /*IBSS Parameter Set*/
207 ie = r8712_set_ie(ie, _IBSS_PARA_IE_, 2, 207 ie = r8712_set_ie(ie, _IBSS_PARA_IE_, 2,
208 (u8 *)&(pdev_network->Configuration.ATIMWindow), &sz); 208 (u8 *)&pdev_network->Configuration.ATIMWindow, &sz);
209 return sz; 209 return sz;
210} 210}
211 211
@@ -224,7 +224,7 @@ unsigned char *r8712_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
224 goto check_next_ie; 224 goto check_next_ie;
225 /*check version...*/ 225 /*check version...*/
226 memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16)); 226 memcpy((u8 *)&val16, (pbuf + 6), sizeof(val16));
227 val16 = le16_to_cpu(val16); 227 le16_to_cpus(&val16);
228 if (val16 != 0x0001) 228 if (val16 != 0x0001)
229 goto check_next_ie; 229 goto check_next_ie;
230 *wpa_ie_len = *(pbuf + 1); 230 *wpa_ie_len = *(pbuf + 1);
@@ -304,7 +304,7 @@ int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher,
304 } 304 }
305 /*pairwise_cipher*/ 305 /*pairwise_cipher*/
306 if (left >= 2) { 306 if (left >= 2) {
307 count = le16_to_cpu(*(u16 *)pos); 307 count = le16_to_cpu(*(__le16 *)pos);
308 pos += 2; 308 pos += 2;
309 left -= 2; 309 left -= 2;
310 if (count == 0 || left < count * WPA_SELECTOR_LEN) 310 if (count == 0 || left < count * WPA_SELECTOR_LEN)
@@ -347,7 +347,7 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
347 } 347 }
348 /*pairwise_cipher*/ 348 /*pairwise_cipher*/
349 if (left >= 2) { 349 if (left >= 2) {
350 count = le16_to_cpu(*(u16 *)pos); 350 count = le16_to_cpu(*(__le16 *)pos);
351 pos += 2; 351 pos += 2;
352 left -= 2; 352 left -= 2;
353 if (count == 0 || left < count * RSN_SELECTOR_LEN) 353 if (count == 0 || left < count * RSN_SELECTOR_LEN)
diff --git a/drivers/staging/rtl8712/ieee80211.h b/drivers/staging/rtl8712/ieee80211.h
index 67ab58084e8a..68fd65e80906 100644
--- a/drivers/staging/rtl8712/ieee80211.h
+++ b/drivers/staging/rtl8712/ieee80211.h
@@ -138,51 +138,51 @@ struct ieee_ibss_seq {
138}; 138};
139 139
140struct ieee80211_hdr { 140struct ieee80211_hdr {
141 u16 frame_ctl; 141 __le16 frame_ctl;
142 u16 duration_id; 142 __le16 duration_id;
143 u8 addr1[ETH_ALEN]; 143 u8 addr1[ETH_ALEN];
144 u8 addr2[ETH_ALEN]; 144 u8 addr2[ETH_ALEN];
145 u8 addr3[ETH_ALEN]; 145 u8 addr3[ETH_ALEN];
146 u16 seq_ctl; 146 __le16 seq_ctl;
147 u8 addr4[ETH_ALEN]; 147 u8 addr4[ETH_ALEN];
148} __packed; 148} __packed __aligned(2);
149 149
150struct ieee80211_hdr_3addr { 150struct ieee80211_hdr_3addr {
151 u16 frame_ctl; 151 __le16 frame_ctl;
152 u16 duration_id; 152 __le16 duration_id;
153 u8 addr1[ETH_ALEN]; 153 u8 addr1[ETH_ALEN];
154 u8 addr2[ETH_ALEN]; 154 u8 addr2[ETH_ALEN];
155 u8 addr3[ETH_ALEN]; 155 u8 addr3[ETH_ALEN];
156 u16 seq_ctl; 156 __le16 seq_ctl;
157} __packed; 157} __packed __aligned(2);
158 158
159struct ieee80211_hdr_qos { 159struct ieee80211_hdr_qos {
160 u16 frame_ctl; 160 __le16 frame_ctl;
161 u16 duration_id; 161 __le16 duration_id;
162 u8 addr1[ETH_ALEN]; 162 u8 addr1[ETH_ALEN];
163 u8 addr2[ETH_ALEN]; 163 u8 addr2[ETH_ALEN];
164 u8 addr3[ETH_ALEN]; 164 u8 addr3[ETH_ALEN];
165 u16 seq_ctl; 165 __le16 seq_ctl;
166 u8 addr4[ETH_ALEN]; 166 u8 addr4[ETH_ALEN];
167 u16 qc; 167 __le16 qc;
168} __packed; 168} __packed __aligned(2);
169 169
170struct ieee80211_hdr_3addr_qos { 170struct ieee80211_hdr_3addr_qos {
171 u16 frame_ctl; 171 __le16 frame_ctl;
172 u16 duration_id; 172 __le16 duration_id;
173 u8 addr1[ETH_ALEN]; 173 u8 addr1[ETH_ALEN];
174 u8 addr2[ETH_ALEN]; 174 u8 addr2[ETH_ALEN];
175 u8 addr3[ETH_ALEN]; 175 u8 addr3[ETH_ALEN];
176 u16 seq_ctl; 176 __le16 seq_ctl;
177 u16 qc; 177 __le16 qc;
178} __packed; 178} __packed;
179 179
180struct eapol { 180struct eapol {
181 u8 snap[6]; 181 u8 snap[6];
182 u16 ethertype; 182 __be16 ethertype;
183 u8 version; 183 u8 version;
184 u8 type; 184 u8 type;
185 u16 length; 185 __le16 length;
186} __packed; 186} __packed;
187 187
188enum eap_type { 188enum eap_type {
@@ -514,13 +514,13 @@ struct ieee80211_security {
514 */ 514 */
515 515
516struct ieee80211_header_data { 516struct ieee80211_header_data {
517 u16 frame_ctl; 517 __le16 frame_ctl;
518 u16 duration_id; 518 __le16 duration_id;
519 u8 addr1[6]; 519 u8 addr1[6];
520 u8 addr2[6]; 520 u8 addr2[6];
521 u8 addr3[6]; 521 u8 addr3[6];
522 u16 seq_ctrl; 522 __le16 seq_ctrl;
523}; 523} __packed __aligned(2);
524 524
525#define BEACON_PROBE_SSID_ID_POSITION 12 525#define BEACON_PROBE_SSID_ID_POSITION 12
526 526
@@ -552,18 +552,18 @@ struct ieee80211_info_element {
552/* 552/*
553 * These are the data types that can make up management packets 553 * These are the data types that can make up management packets
554 * 554 *
555 u16 auth_algorithm; 555 __le16 auth_algorithm;
556 u16 auth_sequence; 556 __le16 auth_sequence;
557 u16 beacon_interval; 557 __le16 beacon_interval;
558 u16 capability; 558 __le16 capability;
559 u8 current_ap[ETH_ALEN]; 559 u8 current_ap[ETH_ALEN];
560 u16 listen_interval; 560 __le16 listen_interval;
561 struct { 561 struct {
562 u16 association_id:14, reserved:2; 562 u16 association_id:14, reserved:2;
563 } __packed; 563 } __packed;
564 u32 time_stamp[2]; 564 __le32 time_stamp[2];
565 u16 reason; 565 __le16 reason;
566 u16 status; 566 __le16 status;
567*/ 567*/
568 568
569#define IEEE80211_DEFAULT_TX_ESSID "Penguin" 569#define IEEE80211_DEFAULT_TX_ESSID "Penguin"
@@ -571,16 +571,16 @@ struct ieee80211_info_element {
571 571
572struct ieee80211_authentication { 572struct ieee80211_authentication {
573 struct ieee80211_header_data header; 573 struct ieee80211_header_data header;
574 u16 algorithm; 574 __le16 algorithm;
575 u16 transaction; 575 __le16 transaction;
576 u16 status; 576 __le16 status;
577} __packed; 577} __packed;
578 578
579struct ieee80211_probe_response { 579struct ieee80211_probe_response {
580 struct ieee80211_header_data header; 580 struct ieee80211_header_data header;
581 u32 time_stamp[2]; 581 __le32 time_stamp[2];
582 u16 beacon_interval; 582 __le16 beacon_interval;
583 u16 capability; 583 __le16 capability;
584 struct ieee80211_info_element info_element; 584 struct ieee80211_info_element info_element;
585} __packed; 585} __packed;
586 586
@@ -590,16 +590,16 @@ struct ieee80211_probe_request {
590 590
591struct ieee80211_assoc_request_frame { 591struct ieee80211_assoc_request_frame {
592 struct ieee80211_hdr_3addr header; 592 struct ieee80211_hdr_3addr header;
593 u16 capability; 593 __le16 capability;
594 u16 listen_interval; 594 __le16 listen_interval;
595 struct ieee80211_info_element_hdr info_element; 595 struct ieee80211_info_element_hdr info_element;
596} __packed; 596} __packed;
597 597
598struct ieee80211_assoc_response_frame { 598struct ieee80211_assoc_response_frame {
599 struct ieee80211_hdr_3addr header; 599 struct ieee80211_hdr_3addr header;
600 u16 capability; 600 __le16 capability;
601 u16 status; 601 __le16 status;
602 u16 aid; 602 __le16 aid;
603} __packed; 603} __packed;
604 604
605struct ieee80211_txb { 605struct ieee80211_txb {
diff --git a/drivers/staging/rtl8712/mlme_linux.c b/drivers/staging/rtl8712/mlme_linux.c
index af7c4a47738a..999c16d9c6c1 100644
--- a/drivers/staging/rtl8712/mlme_linux.c
+++ b/drivers/staging/rtl8712/mlme_linux.c
@@ -117,7 +117,7 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
117 backupTKIPCountermeasure = adapter->securitypriv. 117 backupTKIPCountermeasure = adapter->securitypriv.
118 btkip_countermeasure; 118 btkip_countermeasure;
119 memset((unsigned char *)&adapter->securitypriv, 0, 119 memset((unsigned char *)&adapter->securitypriv, 0,
120 sizeof(struct security_priv)); 120 sizeof(struct security_priv));
121 setup_timer(&adapter->securitypriv.tkip_timer, 121 setup_timer(&adapter->securitypriv.tkip_timer,
122 r8712_use_tkipkey_handler, 122 r8712_use_tkipkey_handler,
123 (unsigned long)adapter); 123 (unsigned long)adapter);
@@ -125,8 +125,8 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter)
125 * for the following connection. 125 * for the following connection.
126 */ 126 */
127 memcpy(&adapter->securitypriv.PMKIDList[0], 127 memcpy(&adapter->securitypriv.PMKIDList[0],
128 &backupPMKIDList[0], 128 &backupPMKIDList[0],
129 sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE); 129 sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE);
130 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex; 130 adapter->securitypriv.PMKIDIndex = backupPMKIDIndex;
131 adapter->securitypriv.btkip_countermeasure = 131 adapter->securitypriv.btkip_countermeasure =
132 backupTKIPCountermeasure; 132 backupTKIPCountermeasure;
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 9f61583af150..f19b6b27aa71 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -314,7 +314,8 @@ void r8712_fw_cmd_data(struct _adapter *pAdapter, u32 *value, u8 flag)
314int r8712_cmd_thread(void *context) 314int r8712_cmd_thread(void *context)
315{ 315{
316 struct cmd_obj *pcmd; 316 struct cmd_obj *pcmd;
317 unsigned int cmdsz, wr_sz, *pcmdbuf; 317 unsigned int cmdsz, wr_sz;
318 __le32 *pcmdbuf;
318 struct tx_desc *pdesc; 319 struct tx_desc *pdesc;
319 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd); 320 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd);
320 struct _adapter *padapter = context; 321 struct _adapter *padapter = context;
@@ -334,7 +335,7 @@ _next:
334 r8712_unregister_cmd_alive(padapter); 335 r8712_unregister_cmd_alive(padapter);
335 continue; 336 continue;
336 } 337 }
337 pcmdbuf = (unsigned int *)pcmdpriv->cmd_buf; 338 pcmdbuf = (__le32 *)pcmdpriv->cmd_buf;
338 pdesc = (struct tx_desc *)pcmdbuf; 339 pdesc = (struct tx_desc *)pcmdbuf;
339 memset(pdesc, 0, TXDESC_SIZE); 340 memset(pdesc, 0, TXDESC_SIZE);
340 pcmd = cmd_hdl_filter(padapter, pcmd); 341 pcmd = cmd_hdl_filter(padapter, pcmd);
@@ -424,7 +425,7 @@ _next:
424 thread_exit(); 425 thread_exit();
425} 426}
426 427
427void r8712_event_handle(struct _adapter *padapter, uint *peventbuf) 428void r8712_event_handle(struct _adapter *padapter, __le32 *peventbuf)
428{ 429{
429 u8 evt_code, evt_seq; 430 u8 evt_code, evt_seq;
430 u16 evt_sz; 431 u16 evt_sz;
diff --git a/drivers/staging/rtl8712/rtl8712_event.h b/drivers/staging/rtl8712/rtl8712_event.h
index 29a4c23a0d23..b38374025c93 100644
--- a/drivers/staging/rtl8712/rtl8712_event.h
+++ b/drivers/staging/rtl8712/rtl8712_event.h
@@ -26,7 +26,7 @@
26#ifndef _RTL8712_EVENT_H_ 26#ifndef _RTL8712_EVENT_H_
27#define _RTL8712_EVENT_H_ 27#define _RTL8712_EVENT_H_
28 28
29void r8712_event_handle(struct _adapter *padapter, uint *peventbuf); 29void r8712_event_handle(struct _adapter *padapter, __le32 *peventbuf);
30void r8712_got_addbareq_event_callback(struct _adapter *adapter, u8 *pbuf); 30void r8712_got_addbareq_event_callback(struct _adapter *adapter, u8 *pbuf);
31 31
32enum rtl8712_c2h_event { 32enum rtl8712_c2h_event {
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index 66f0e0a35167..20fe45a43e53 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -408,7 +408,7 @@ static int amsdu_to_msdu(struct _adapter *padapter, union recv_frame *prframe)
408 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst, 408 memcpy(skb_push(sub_skb, ETH_ALEN), pattrib->dst,
409 ETH_ALEN); 409 ETH_ALEN);
410 } else { 410 } else {
411 u16 len; 411 __be16 len;
412 /* Leave Ethernet header part of hdr and full payload */ 412 /* Leave Ethernet header part of hdr and full payload */
413 len = htons(sub_skb->len); 413 len = htons(sub_skb->len);
414 memcpy(skb_push(sub_skb, 2), &len, 2); 414 memcpy(skb_push(sub_skb, 2), &len, 2);
@@ -439,21 +439,21 @@ exit:
439 439
440void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf) 440void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf)
441{ 441{
442 uint voffset; 442 __le32 voffset;
443 u8 *poffset; 443 u8 *poffset;
444 u16 cmd_len, drvinfo_sz; 444 u16 cmd_len, drvinfo_sz;
445 struct recv_stat *prxstat; 445 struct recv_stat *prxstat;
446 446
447 poffset = (u8 *)prxcmdbuf; 447 poffset = (u8 *)prxcmdbuf;
448 voffset = *(uint *)poffset; 448 voffset = *(__le32 *)poffset;
449 prxstat = (struct recv_stat *)prxcmdbuf; 449 prxstat = (struct recv_stat *)prxcmdbuf;
450 drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16; 450 drvinfo_sz = (le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16;
451 drvinfo_sz <<= 3; 451 drvinfo_sz <<= 3;
452 poffset += RXDESC_SIZE + drvinfo_sz; 452 poffset += RXDESC_SIZE + drvinfo_sz;
453 do { 453 do {
454 voffset = *(uint *)poffset; 454 voffset = *(__le32 *)poffset;
455 cmd_len = (u16)(le32_to_cpu(voffset) & 0xffff); 455 cmd_len = (u16)(le32_to_cpu(voffset) & 0xffff);
456 r8712_event_handle(padapter, (uint *)poffset); 456 r8712_event_handle(padapter, (__le32 *)poffset);
457 poffset += (cmd_len + 8);/*8 bytes alignment*/ 457 poffset += (cmd_len + 8);/*8 bytes alignment*/
458 } while (le32_to_cpu(voffset) & BIT(31)); 458 } while (le32_to_cpu(voffset) & BIT(31));
459 459
@@ -758,7 +758,7 @@ static void query_rx_phy_status(struct _adapter *padapter,
758 /* CCK Driver info Structure is not the same as OFDM packet.*/ 758 /* CCK Driver info Structure is not the same as OFDM packet.*/
759 pcck_buf = (struct phy_cck_rx_status *)pphy_stat; 759 pcck_buf = (struct phy_cck_rx_status *)pphy_stat;
760 /* (1)Hardware does not provide RSSI for CCK 760 /* (1)Hardware does not provide RSSI for CCK
761 * (2)PWDB, Average PWDB cacluated by hardware 761 * (2)PWDB, Average PWDB calculated by hardware
762 * (for rate adaptive) 762 * (for rate adaptive)
763 */ 763 */
764 if (!cck_highpwr) { 764 if (!cck_highpwr) {
@@ -853,7 +853,7 @@ static void query_rx_phy_status(struct _adapter *padapter,
853 rssi = query_rx_pwr_percentage(rx_pwr[i]); 853 rssi = query_rx_pwr_percentage(rx_pwr[i]);
854 total_rssi += rssi; 854 total_rssi += rssi;
855 } 855 }
856 /* (2)PWDB, Average PWDB cacluated by hardware (for 856 /* (2)PWDB, Average PWDB calculated by hardware (for
857 * rate adaptive) 857 * rate adaptive)
858 */ 858 */
859 rx_pwr_all = (((pphy_head[PHY_STAT_PWDB_ALL_SHT]) >> 1) & 0x7f) 859 rx_pwr_all = (((pphy_head[PHY_STAT_PWDB_ALL_SHT]) >> 1) & 0x7f)
diff --git a/drivers/staging/rtl8712/rtl8712_recv.h b/drivers/staging/rtl8712/rtl8712_recv.h
index 0b0c2730aac5..0352e6fafd90 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.h
+++ b/drivers/staging/rtl8712/rtl8712_recv.h
@@ -50,12 +50,12 @@
50#define REORDER_WAIT_TIME 30 /* (ms)*/ 50#define REORDER_WAIT_TIME 30 /* (ms)*/
51 51
52struct recv_stat { 52struct recv_stat {
53 unsigned int rxdw0; 53 __le32 rxdw0;
54 unsigned int rxdw1; 54 __le32 rxdw1;
55 unsigned int rxdw2; 55 __le32 rxdw2;
56 unsigned int rxdw3; 56 __le32 rxdw3;
57 unsigned int rxdw4; 57 __le32 rxdw4;
58 unsigned int rxdw5; 58 __le32 rxdw5;
59}; 59};
60 60
61struct phy_cck_rx_status { 61struct phy_cck_rx_status {
@@ -69,14 +69,14 @@ struct phy_cck_rx_status {
69}; 69};
70 70
71struct phy_stat { 71struct phy_stat {
72 unsigned int phydw0; 72 __le32 phydw0;
73 unsigned int phydw1; 73 __le32 phydw1;
74 unsigned int phydw2; 74 __le32 phydw2;
75 unsigned int phydw3; 75 __le32 phydw3;
76 unsigned int phydw4; 76 __le32 phydw4;
77 unsigned int phydw5; 77 __le32 phydw5;
78 unsigned int phydw6; 78 __le32 phydw6;
79 unsigned int phydw7; 79 __le32 phydw7;
80}; 80};
81#define PHY_STAT_GAIN_TRSW_SHT 0 81#define PHY_STAT_GAIN_TRSW_SHT 0
82#define PHY_STAT_PWDB_ALL_SHT 4 82#define PHY_STAT_PWDB_ALL_SHT 4
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.c b/drivers/staging/rtl8712/rtl8712_xmit.c
index c4f03a602a2e..7fe626583c8a 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.c
+++ b/drivers/staging/rtl8712/rtl8712_xmit.c
@@ -302,7 +302,7 @@ u8 r8712_append_mpdu_unit(struct xmit_buf *pxmitbuf,
302 int last_txcmdsz = 0; 302 int last_txcmdsz = 0;
303 int padding_sz = 0; 303 int padding_sz = 0;
304 304
305 /* 802.3->802.11 convertor */ 305 /* 802.3->802.11 converter */
306 r8712_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe); 306 r8712_xmitframe_coalesce(padapter, pxmitframe->pkt, pxmitframe);
307 /* free skb struct */ 307 /* free skb struct */
308 r8712_xmit_complete(padapter, pxmitframe); 308 r8712_xmit_complete(padapter, pxmitframe);
@@ -561,19 +561,19 @@ static void update_txdesc(struct xmit_frame *pxmitframe, uint *pmem, int sz)
561 561
562 ptxdesc_mp = &txdesc_mp; 562 ptxdesc_mp = &txdesc_mp;
563 /* offset 8 */ 563 /* offset 8 */
564 ptxdesc->txdw2 = cpu_to_le32(ptxdesc_mp->txdw2); 564 ptxdesc->txdw2 = ptxdesc_mp->txdw2;
565 if (bmcst) 565 if (bmcst)
566 ptxdesc->txdw2 |= cpu_to_le32(BMC); 566 ptxdesc->txdw2 |= cpu_to_le32(BMC);
567 ptxdesc->txdw2 |= cpu_to_le32(BK); 567 ptxdesc->txdw2 |= cpu_to_le32(BK);
568 /* offset 16 */ 568 /* offset 16 */
569 ptxdesc->txdw4 = cpu_to_le32(ptxdesc_mp->txdw4); 569 ptxdesc->txdw4 = ptxdesc_mp->txdw4;
570 /* offset 20 */ 570 /* offset 20 */
571 ptxdesc->txdw5 = cpu_to_le32(ptxdesc_mp->txdw5); 571 ptxdesc->txdw5 = ptxdesc_mp->txdw5;
572 pattrib->pctrl = 0;/* reset to zero; */ 572 pattrib->pctrl = 0;/* reset to zero; */
573 } 573 }
574 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) { 574 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
575 /* offset 4 */ 575 /* offset 4 */
576 ptxdesc->txdw1 |= (0x05) & 0x1f;/*CAM_ID(MAC_ID), default=5;*/ 576 ptxdesc->txdw1 |= cpu_to_le32((0x05) & 0x1f);/*CAM_ID(MAC_ID), default=5;*/
577 qsel = (uint)(pattrib->qsel & 0x0000001f); 577 qsel = (uint)(pattrib->qsel & 0x0000001f);
578 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00); 578 ptxdesc->txdw1 |= cpu_to_le32((qsel << QSEL_SHT) & 0x00001f00);
579 ptxdesc->txdw1 |= cpu_to_le32(BIT(16));/* Non-QoS */ 579 ptxdesc->txdw1 |= cpu_to_le32(BIT(16));/* Non-QoS */
diff --git a/drivers/staging/rtl8712/rtl8712_xmit.h b/drivers/staging/rtl8712/rtl8712_xmit.h
index b50e7a1f3a42..02b1593ada01 100644
--- a/drivers/staging/rtl8712/rtl8712_xmit.h
+++ b/drivers/staging/rtl8712/rtl8712_xmit.h
@@ -91,14 +91,14 @@
91 91
92struct tx_desc { 92struct tx_desc {
93 /*DWORD 0*/ 93 /*DWORD 0*/
94 unsigned int txdw0; 94 __le32 txdw0;
95 unsigned int txdw1; 95 __le32 txdw1;
96 unsigned int txdw2; 96 __le32 txdw2;
97 unsigned int txdw3; 97 __le32 txdw3;
98 unsigned int txdw4; 98 __le32 txdw4;
99 unsigned int txdw5; 99 __le32 txdw5;
100 unsigned int txdw6; 100 __le32 txdw6;
101 unsigned int txdw7; 101 __le32 txdw7;
102}; 102};
103 103
104 104
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h b/drivers/staging/rtl8712/rtl871x_cmd.h
index 3284dcf2f1a9..4734ca856aa2 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -156,9 +156,9 @@ struct setopmode_parm {
156 * Command-Event Mode 156 * Command-Event Mode
157 */ 157 */
158struct sitesurvey_parm { 158struct sitesurvey_parm {
159 sint passive_mode; /*active: 1, passive: 0 */ 159 __le32 passive_mode; /*active: 1, passive: 0 */
160 sint bsslimit; /* 1 ~ 48 */ 160 __le32 bsslimit; /* 1 ~ 48 */
161 sint ss_ssidlen; 161 __le32 ss_ssidlen;
162 u8 ss_ssid[IW_ESSID_MAX_SIZE + 1]; 162 u8 ss_ssid[IW_ESSID_MAX_SIZE + 1];
163}; 163};
164 164
diff --git a/drivers/staging/rtl8712/rtl871x_event.h b/drivers/staging/rtl8712/rtl871x_event.h
index 697c8d735150..5db8620980e5 100644
--- a/drivers/staging/rtl8712/rtl871x_event.h
+++ b/drivers/staging/rtl8712/rtl871x_event.h
@@ -66,7 +66,7 @@ struct joinbss_event {
66struct stassoc_event { 66struct stassoc_event {
67 unsigned char macaddr[6]; 67 unsigned char macaddr[6];
68 unsigned char rsvd[2]; 68 unsigned char rsvd[2];
69 int cam_id; 69 __le32 cam_id;
70}; 70};
71 71
72struct stadel_event { 72struct stadel_event {
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 590acb5aea3d..f4167f14af70 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -199,7 +199,7 @@ static noinline_for_stack char *translate_scan(struct _adapter *padapter,
199 iwe.cmd = SIOCGIWMODE; 199 iwe.cmd = SIOCGIWMODE;
200 memcpy((u8 *)&cap, r8712_get_capability_from_ie(pnetwork->network.IEs), 200 memcpy((u8 *)&cap, r8712_get_capability_from_ie(pnetwork->network.IEs),
201 2); 201 2);
202 cap = le16_to_cpu(cap); 202 le16_to_cpus(&cap);
203 if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) { 203 if (cap & (WLAN_CAPABILITY_IBSS | WLAN_CAPABILITY_BSS)) {
204 if (cap & WLAN_CAPABILITY_BSS) 204 if (cap & WLAN_CAPABILITY_BSS)
205 iwe.u.mode = (u32)IW_MODE_MASTER; 205 iwe.u.mode = (u32)IW_MODE_MASTER;
@@ -1419,9 +1419,9 @@ static int r8711_wx_get_rate(struct net_device *dev,
1419 ht_cap = true; 1419 ht_cap = true;
1420 pht_capie = (struct ieee80211_ht_cap *)(p + 2); 1420 pht_capie = (struct ieee80211_ht_cap *)(p + 2);
1421 memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2); 1421 memcpy(&mcs_rate, pht_capie->supp_mcs_set, 2);
1422 bw_40MHz = (pht_capie->cap_info & 1422 bw_40MHz = (le16_to_cpu(pht_capie->cap_info) &
1423 IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0; 1423 IEEE80211_HT_CAP_SUP_WIDTH) ? 1 : 0;
1424 short_GI = (pht_capie->cap_info & 1424 short_GI = (le16_to_cpu(pht_capie->cap_info) &
1425 (IEEE80211_HT_CAP_SGI_20 | 1425 (IEEE80211_HT_CAP_SGI_20 |
1426 IEEE80211_HT_CAP_SGI_40)) ? 1 : 0; 1426 IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
1427 } 1427 }
@@ -2322,7 +2322,7 @@ static struct iw_statistics *r871x_get_wireless_stats(struct net_device *dev)
2322 piwstats->qual.level = 0; 2322 piwstats->qual.level = 0;
2323 piwstats->qual.noise = 0; 2323 piwstats->qual.noise = 0;
2324 } else { 2324 } else {
2325 /* show percentage, we need transfer dbm to orignal value. */ 2325 /* show percentage, we need transfer dbm to original value. */
2326 tmp_level = padapter->recvpriv.fw_rssi; 2326 tmp_level = padapter->recvpriv.fw_rssi;
2327 tmp_qual = padapter->recvpriv.signal; 2327 tmp_qual = padapter->recvpriv.signal;
2328 tmp_noise = padapter->recvpriv.noise; 2328 tmp_noise = padapter->recvpriv.noise;
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index 35cbdc71cad4..bf1ac22bae1c 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -257,10 +257,10 @@ int r8712_is_same_ibss(struct _adapter *adapter, struct wlan_network *pnetwork)
257 struct security_priv *psecuritypriv = &adapter->securitypriv; 257 struct security_priv *psecuritypriv = &adapter->securitypriv;
258 258
259 if ((psecuritypriv->PrivacyAlgrthm != _NO_PRIVACY_) && 259 if ((psecuritypriv->PrivacyAlgrthm != _NO_PRIVACY_) &&
260 (pnetwork->network.Privacy == 0)) 260 (pnetwork->network.Privacy == cpu_to_le32(0)))
261 ret = false; 261 ret = false;
262 else if ((psecuritypriv->PrivacyAlgrthm == _NO_PRIVACY_) && 262 else if ((psecuritypriv->PrivacyAlgrthm == _NO_PRIVACY_) &&
263 (pnetwork->network.Privacy == 1)) 263 (pnetwork->network.Privacy == cpu_to_le32(1)))
264 ret = false; 264 ret = false;
265 else 265 else
266 ret = true; 266 ret = true;
@@ -933,7 +933,7 @@ void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf)
933 return; 933 return;
934 /* to do : init sta_info variable */ 934 /* to do : init sta_info variable */
935 psta->qos_option = 0; 935 psta->qos_option = 0;
936 psta->mac_id = le32_to_cpu((uint)pstassoc->cam_id); 936 psta->mac_id = le32_to_cpu(pstassoc->cam_id);
937 /* psta->aid = (uint)pstassoc->cam_id; */ 937 /* psta->aid = (uint)pstassoc->cam_id; */
938 938
939 if (adapter->securitypriv.AuthAlgrthm == 2) 939 if (adapter->securitypriv.AuthAlgrthm == 2)
@@ -1637,25 +1637,23 @@ void r8712_update_registrypriv_dev_network(struct _adapter *adapter)
1637 pdev_network->Rssi = 0; 1637 pdev_network->Rssi = 0;
1638 switch (pregistrypriv->wireless_mode) { 1638 switch (pregistrypriv->wireless_mode) {
1639 case WIRELESS_11B: 1639 case WIRELESS_11B:
1640 pdev_network->NetworkTypeInUse = cpu_to_le32(Ndis802_11DS); 1640 pdev_network->NetworkTypeInUse = Ndis802_11DS;
1641 break; 1641 break;
1642 case WIRELESS_11G: 1642 case WIRELESS_11G:
1643 case WIRELESS_11BG: 1643 case WIRELESS_11BG:
1644 pdev_network->NetworkTypeInUse = cpu_to_le32(Ndis802_11OFDM24); 1644 pdev_network->NetworkTypeInUse = Ndis802_11OFDM24;
1645 break; 1645 break;
1646 case WIRELESS_11A: 1646 case WIRELESS_11A:
1647 pdev_network->NetworkTypeInUse = cpu_to_le32(Ndis802_11OFDM5); 1647 pdev_network->NetworkTypeInUse = Ndis802_11OFDM5;
1648 break; 1648 break;
1649 default: 1649 default:
1650 /* TODO */ 1650 /* TODO */
1651 break; 1651 break;
1652 } 1652 }
1653 pdev_network->Configuration.DSConfig = cpu_to_le32( 1653 pdev_network->Configuration.DSConfig = pregistrypriv->channel;
1654 pregistrypriv->channel);
1655 if (cur_network->network.InfrastructureMode == Ndis802_11IBSS) 1654 if (cur_network->network.InfrastructureMode == Ndis802_11IBSS)
1656 pdev_network->Configuration.ATIMWindow = cpu_to_le32(3); 1655 pdev_network->Configuration.ATIMWindow = 3;
1657 pdev_network->InfrastructureMode = cpu_to_le32( 1656 pdev_network->InfrastructureMode = cur_network->network.InfrastructureMode;
1658 cur_network->network.InfrastructureMode);
1659 /* 1. Supported rates 1657 /* 1. Supported rates
1660 * 2. IE 1658 * 2. IE
1661 */ 1659 */
@@ -1710,12 +1708,12 @@ unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
1710 } 1708 }
1711 out_len = *pout_len; 1709 out_len = *pout_len;
1712 memset(&ht_capie, 0, sizeof(struct ieee80211_ht_cap)); 1710 memset(&ht_capie, 0, sizeof(struct ieee80211_ht_cap));
1713 ht_capie.cap_info = IEEE80211_HT_CAP_SUP_WIDTH | 1711 ht_capie.cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH |
1714 IEEE80211_HT_CAP_SGI_20 | 1712 IEEE80211_HT_CAP_SGI_20 |
1715 IEEE80211_HT_CAP_SGI_40 | 1713 IEEE80211_HT_CAP_SGI_40 |
1716 IEEE80211_HT_CAP_TX_STBC | 1714 IEEE80211_HT_CAP_TX_STBC |
1717 IEEE80211_HT_CAP_MAX_AMSDU | 1715 IEEE80211_HT_CAP_MAX_AMSDU |
1718 IEEE80211_HT_CAP_DSSSCCK40; 1716 IEEE80211_HT_CAP_DSSSCCK40);
1719 ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR & 1717 ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR &
1720 0x03) | (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00); 1718 0x03) | (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
1721 r8712_set_ie(out_ie + out_len, _HT_CAPABILITY_IE_, 1719 r8712_set_ie(out_ie + out_len, _HT_CAPABILITY_IE_,
diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
index b98a596757f5..6e264a8d0087 100644
--- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
+++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
@@ -202,7 +202,7 @@ static int mp_start_test(struct _adapter *padapter)
202 res = _FAIL; 202 res = _FAIL;
203 goto end_of_mp_start_test; 203 goto end_of_mp_start_test;
204 } 204 }
205 /* 3 3. join psudo AdHoc */ 205 /* 3 3. join pseudo AdHoc */
206 tgt_network->join_res = 1; 206 tgt_network->join_res = 1;
207 tgt_network->aid = psta->aid = 1; 207 tgt_network->aid = psta->aid = 1;
208 memcpy(&tgt_network->network, &bssid, length); 208 memcpy(&tgt_network->network, &bssid, length);
@@ -227,7 +227,7 @@ static int mp_stop_test(struct _adapter *padapter)
227 spin_lock_irqsave(&pmlmepriv->lock, irqL); 227 spin_lock_irqsave(&pmlmepriv->lock, irqL);
228 if (!check_fwstate(pmlmepriv, WIFI_MP_STATE)) 228 if (!check_fwstate(pmlmepriv, WIFI_MP_STATE))
229 goto end_of_mp_stop_test; 229 goto end_of_mp_stop_test;
230 /* 3 1. disconnect psudo AdHoc */ 230 /* 3 1. disconnect pseudo AdHoc */
231 r8712_os_indicate_disconnect(padapter); 231 r8712_os_indicate_disconnect(padapter);
232 /* 3 2. clear psta used in mp test mode. */ 232 /* 3 2. clear psta used in mp test mode. */
233 psta = r8712_get_stainfo(&padapter->stapriv, 233 psta = r8712_get_stainfo(&padapter->stapriv,
diff --git a/drivers/staging/rtl8712/rtl871x_recv.c b/drivers/staging/rtl8712/rtl871x_recv.c
index 35c721a50598..2ef31a4e9a6b 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -258,7 +258,7 @@ union recv_frame *r8712_portctrl(struct _adapter *adapter,
258 /* get ether_type */ 258 /* get ether_type */
259 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE; 259 ptr = ptr + pfhdr->attrib.hdrlen + LLC_HEADER_SIZE;
260 memcpy(&ether_type, ptr, 2); 260 memcpy(&ether_type, ptr, 2);
261 ether_type = ntohs((unsigned short)ether_type); 261 be16_to_cpus(&ether_type);
262 262
263 if ((psta != NULL) && (psta->ieee8021x_blocked)) { 263 if ((psta != NULL) && (psta->ieee8021x_blocked)) {
264 /* blocked 264 /* blocked
@@ -640,17 +640,23 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
640 /* append rx status for mp test packets */ 640 /* append rx status for mp test packets */
641 ptr = recvframe_pull(precvframe, (rmv_len - 641 ptr = recvframe_pull(precvframe, (rmv_len -
642 sizeof(struct ethhdr) + 2) - 24); 642 sizeof(struct ethhdr) + 2) - 24);
643 if (!ptr)
644 return _FAIL;
643 memcpy(ptr, get_rxmem(precvframe), 24); 645 memcpy(ptr, get_rxmem(precvframe), 24);
644 ptr += 24; 646 ptr += 24;
645 } else 647 } else {
646 ptr = recvframe_pull(precvframe, (rmv_len - 648 ptr = recvframe_pull(precvframe, (rmv_len -
647 sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0))); 649 sizeof(struct ethhdr) + (bsnaphdr ? 2 : 0)));
650 if (!ptr)
651 return _FAIL;
652 }
648 653
649 memcpy(ptr, pattrib->dst, ETH_ALEN); 654 memcpy(ptr, pattrib->dst, ETH_ALEN);
650 memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN); 655 memcpy(ptr + ETH_ALEN, pattrib->src, ETH_ALEN);
651 if (!bsnaphdr) { 656 if (!bsnaphdr) {
652 len = htons(len); 657 __be16 be_tmp = htons(len);
653 memcpy(ptr + 12, &len, 2); 658
659 memcpy(ptr + 12, &be_tmp, 2);
654 } 660 }
655 return _SUCCESS; 661 return _SUCCESS;
656} 662}
diff --git a/drivers/staging/rtl8712/rtl871x_security.c b/drivers/staging/rtl8712/rtl871x_security.c
index a7f04a4b089d..bd83fb492c45 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -192,7 +192,7 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
192 length = pattrib->last_txcmdsz - pattrib-> 192 length = pattrib->last_txcmdsz - pattrib->
193 hdrlen - pattrib->iv_len - 193 hdrlen - pattrib->iv_len -
194 pattrib->icv_len; 194 pattrib->icv_len;
195 *((u32 *)crc) = cpu_to_le32(getcrc32( 195 *((__le32 *)crc) = cpu_to_le32(getcrc32(
196 payload, length)); 196 payload, length));
197 arcfour_init(&mycontext, wepkey, 3 + keylength); 197 arcfour_init(&mycontext, wepkey, 3 + keylength);
198 arcfour_encrypt(&mycontext, payload, payload, 198 arcfour_encrypt(&mycontext, payload, payload,
@@ -203,7 +203,7 @@ void r8712_wep_encrypt(struct _adapter *padapter, u8 *pxmitframe)
203 length = pxmitpriv->frag_len - 203 length = pxmitpriv->frag_len -
204 pattrib->hdrlen - pattrib->iv_len - 204 pattrib->hdrlen - pattrib->iv_len -
205 pattrib->icv_len; 205 pattrib->icv_len;
206 *((u32 *)crc) = cpu_to_le32(getcrc32( 206 *((__le32 *)crc) = cpu_to_le32(getcrc32(
207 payload, length)); 207 payload, length));
208 arcfour_init(&mycontext, wepkey, 3 + keylength); 208 arcfour_init(&mycontext, wepkey, 3 + keylength);
209 arcfour_encrypt(&mycontext, payload, payload, 209 arcfour_encrypt(&mycontext, payload, payload,
@@ -248,7 +248,7 @@ void r8712_wep_decrypt(struct _adapter *padapter, u8 *precvframe)
248 arcfour_init(&mycontext, wepkey, 3 + keylength); 248 arcfour_init(&mycontext, wepkey, 3 + keylength);
249 arcfour_encrypt(&mycontext, payload, payload, length); 249 arcfour_encrypt(&mycontext, payload, payload, length);
250 /* calculate icv and compare the icv */ 250 /* calculate icv and compare the icv */
251 *((u32 *)crc) = cpu_to_le32(getcrc32(payload, length - 4)); 251 *((__le32 *)crc) = cpu_to_le32(getcrc32(payload, length - 4));
252 } 252 }
253} 253}
254 254
@@ -616,7 +616,7 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
616 pattrib->hdrlen - 616 pattrib->hdrlen -
617 pattrib->iv_len - 617 pattrib->iv_len -
618 pattrib->icv_len; 618 pattrib->icv_len;
619 *((u32 *)crc) = cpu_to_le32( 619 *((__le32 *)crc) = cpu_to_le32(
620 getcrc32(payload, length)); 620 getcrc32(payload, length));
621 arcfour_init(&mycontext, rc4key, 16); 621 arcfour_init(&mycontext, rc4key, 16);
622 arcfour_encrypt(&mycontext, payload, 622 arcfour_encrypt(&mycontext, payload,
@@ -628,7 +628,7 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
628 pattrib->hdrlen - 628 pattrib->hdrlen -
629 pattrib->iv_len - 629 pattrib->iv_len -
630 pattrib->icv_len; 630 pattrib->icv_len;
631 *((u32 *)crc) = cpu_to_le32(getcrc32( 631 *((__le32 *)crc) = cpu_to_le32(getcrc32(
632 payload, length)); 632 payload, length));
633 arcfour_init(&mycontext, rc4key, 16); 633 arcfour_init(&mycontext, rc4key, 16);
634 arcfour_encrypt(&mycontext, payload, 634 arcfour_encrypt(&mycontext, payload,
@@ -696,7 +696,7 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
696 /* 4 decrypt payload include icv */ 696 /* 4 decrypt payload include icv */
697 arcfour_init(&mycontext, rc4key, 16); 697 arcfour_init(&mycontext, rc4key, 16);
698 arcfour_encrypt(&mycontext, payload, payload, length); 698 arcfour_encrypt(&mycontext, payload, payload, length);
699 *((u32 *)crc) = cpu_to_le32(getcrc32(payload, 699 *((__le32 *)crc) = cpu_to_le32(getcrc32(payload,
700 length - 4)); 700 length - 4));
701 if (crc[3] != payload[length - 1] || 701 if (crc[3] != payload[length - 1] ||
702 crc[2] != payload[length - 2] || 702 crc[2] != payload[length - 2] ||
@@ -833,7 +833,7 @@ static void mix_column(u8 *in, u8 *out)
833 u8 add1b[4]; 833 u8 add1b[4];
834 u8 add1bf7[4]; 834 u8 add1bf7[4];
835 u8 rotl[4]; 835 u8 rotl[4];
836 u8 swap_halfs[4]; 836 u8 swap_halves[4];
837 u8 andf7[4]; 837 u8 andf7[4];
838 u8 rotr[4]; 838 u8 rotr[4];
839 u8 temp[4]; 839 u8 temp[4];
@@ -845,10 +845,10 @@ static void mix_column(u8 *in, u8 *out)
845 else 845 else
846 add1b[i] = 0x00; 846 add1b[i] = 0x00;
847 } 847 }
848 swap_halfs[0] = in[2]; /* Swap halves */ 848 swap_halves[0] = in[2]; /* Swap halves */
849 swap_halfs[1] = in[3]; 849 swap_halves[1] = in[3];
850 swap_halfs[2] = in[0]; 850 swap_halves[2] = in[0];
851 swap_halfs[3] = in[1]; 851 swap_halves[3] = in[1];
852 rotl[0] = in[3]; /* Rotate left 8 bits */ 852 rotl[0] = in[3]; /* Rotate left 8 bits */
853 rotl[1] = in[0]; 853 rotl[1] = in[0];
854 rotl[2] = in[1]; 854 rotl[2] = in[1];
@@ -872,7 +872,7 @@ static void mix_column(u8 *in, u8 *out)
872 rotr[2] = rotr[3]; 872 rotr[2] = rotr[3];
873 rotr[3] = temp[0]; 873 rotr[3] = temp[0];
874 xor_32(add1bf7, rotr, temp); 874 xor_32(add1bf7, rotr, temp);
875 xor_32(swap_halfs, rotl, tempb); 875 xor_32(swap_halves, rotl, tempb);
876 xor_32(temp, tempb, out); 876 xor_32(temp, tempb, out);
877} 877}
878 878
@@ -1047,8 +1047,8 @@ static sint aes_cipher(u8 *key, uint hdrlen,
1047 u8 aes_out[16]; 1047 u8 aes_out[16];
1048 u8 padded_buffer[16]; 1048 u8 padded_buffer[16];
1049 u8 mic[8]; 1049 u8 mic[8];
1050 uint frtype = GetFrameType(pframe); 1050 u16 frtype = GetFrameType(pframe);
1051 uint frsubtype = GetFrameSubType(pframe); 1051 u16 frsubtype = GetFrameSubType(pframe);
1052 1052
1053 frsubtype >>= 4; 1053 frsubtype >>= 4;
1054 memset((void *)mic_iv, 0, 16); 1054 memset((void *)mic_iv, 0, 16);
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c
index 4ab82ba9bb3f..de88819faf05 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -347,7 +347,8 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
347 * some settings above. 347 * some settings above.
348 */ 348 */
349 if (check_fwstate(pmlmepriv, WIFI_MP_STATE)) 349 if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
350 pattrib->priority = (txdesc.txdw1 >> QSEL_SHT) & 0x1f; 350 pattrib->priority =
351 (le32_to_cpu(txdesc.txdw1) >> QSEL_SHT) & 0x1f;
351 return _SUCCESS; 352 return _SUCCESS;
352} 353}
353 354
@@ -488,7 +489,7 @@ static sint make_wlanhdr(struct _adapter *padapter, u8 *hdr,
488 struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr; 489 struct ieee80211_hdr *pwlanhdr = (struct ieee80211_hdr *)hdr;
489 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 490 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
490 struct qos_priv *pqospriv = &pmlmepriv->qospriv; 491 struct qos_priv *pqospriv = &pmlmepriv->qospriv;
491 u16 *fctrl = &pwlanhdr->frame_ctl; 492 __le16 *fctrl = &pwlanhdr->frame_ctl;
492 493
493 memset(hdr, 0, WLANHDR_OFFSET); 494 memset(hdr, 0, WLANHDR_OFFSET);
494 SetFrameSubType(fctrl, pattrib->subtype); 495 SetFrameSubType(fctrl, pattrib->subtype);
@@ -577,7 +578,7 @@ static sint r8712_put_snap(u8 *data, u16 h_proto)
577 snap->oui[0] = oui[0]; 578 snap->oui[0] = oui[0];
578 snap->oui[1] = oui[1]; 579 snap->oui[1] = oui[1];
579 snap->oui[2] = oui[2]; 580 snap->oui[2] = oui[2];
580 *(u16 *)(data + SNAP_SIZE) = htons(h_proto); 581 *(__be16 *)(data + SNAP_SIZE) = htons(h_proto);
581 return SNAP_SIZE + sizeof(u16); 582 return SNAP_SIZE + sizeof(u16);
582} 583}
583 584
diff --git a/drivers/staging/rtl8712/usb_ops.c b/drivers/staging/rtl8712/usb_ops.c
index 9172400efe9a..332e2e51d778 100644
--- a/drivers/staging/rtl8712/usb_ops.c
+++ b/drivers/staging/rtl8712/usb_ops.c
@@ -41,7 +41,7 @@ static u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
41 u16 wvalue; 41 u16 wvalue;
42 u16 index; 42 u16 index;
43 u16 len; 43 u16 len;
44 u32 data; 44 __le32 data;
45 struct intf_priv *pintfpriv = pintfhdl->pintfpriv; 45 struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
46 46
47 request = 0x05; 47 request = 0x05;
@@ -61,7 +61,7 @@ static u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
61 u16 wvalue; 61 u16 wvalue;
62 u16 index; 62 u16 index;
63 u16 len; 63 u16 len;
64 u32 data; 64 __le32 data;
65 struct intf_priv *pintfpriv = pintfhdl->pintfpriv; 65 struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
66 66
67 request = 0x05; 67 request = 0x05;
@@ -81,7 +81,7 @@ static u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
81 u16 wvalue; 81 u16 wvalue;
82 u16 index; 82 u16 index;
83 u16 len; 83 u16 len;
84 u32 data; 84 __le32 data;
85 struct intf_priv *pintfpriv = pintfhdl->pintfpriv; 85 struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
86 86
87 request = 0x05; 87 request = 0x05;
@@ -101,7 +101,7 @@ static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
101 u16 wvalue; 101 u16 wvalue;
102 u16 index; 102 u16 index;
103 u16 len; 103 u16 len;
104 u32 data; 104 __le32 data;
105 struct intf_priv *pintfpriv = pintfhdl->pintfpriv; 105 struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
106 106
107 request = 0x05; 107 request = 0x05;
@@ -109,8 +109,7 @@ static void usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
109 index = 0; 109 index = 0;
110 wvalue = (u16)(addr & 0x0000ffff); 110 wvalue = (u16)(addr & 0x0000ffff);
111 len = 1; 111 len = 1;
112 data = val; 112 data = cpu_to_le32((u32)val & 0x000000ff);
113 data = cpu_to_le32(data & 0x000000ff);
114 r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len, 113 r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
115 requesttype); 114 requesttype);
116} 115}
@@ -122,7 +121,7 @@ static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
122 u16 wvalue; 121 u16 wvalue;
123 u16 index; 122 u16 index;
124 u16 len; 123 u16 len;
125 u32 data; 124 __le32 data;
126 struct intf_priv *pintfpriv = pintfhdl->pintfpriv; 125 struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
127 126
128 request = 0x05; 127 request = 0x05;
@@ -130,8 +129,7 @@ static void usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
130 index = 0; 129 index = 0;
131 wvalue = (u16)(addr & 0x0000ffff); 130 wvalue = (u16)(addr & 0x0000ffff);
132 len = 2; 131 len = 2;
133 data = val; 132 data = cpu_to_le32((u32)val & 0x0000ffff);
134 data = cpu_to_le32(data & 0x0000ffff);
135 r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len, 133 r8712_usbctrl_vendorreq(pintfpriv, request, wvalue, index, &data, len,
136 requesttype); 134 requesttype);
137} 135}
@@ -143,7 +141,7 @@ static void usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
143 u16 wvalue; 141 u16 wvalue;
144 u16 index; 142 u16 index;
145 u16 len; 143 u16 len;
146 u32 data; 144 __le32 data;
147 struct intf_priv *pintfpriv = pintfhdl->pintfpriv; 145 struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
148 146
149 request = 0x05; 147 request = 0x05;
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c
index fc6bb0be2a28..441e76b8959d 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -192,7 +192,8 @@ void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
192 192
193static void r8712_usb_read_port_complete(struct urb *purb) 193static void r8712_usb_read_port_complete(struct urb *purb)
194{ 194{
195 uint isevt, *pbuf; 195 uint isevt;
196 __le32 *pbuf;
196 struct recv_buf *precvbuf = (struct recv_buf *)purb->context; 197 struct recv_buf *precvbuf = (struct recv_buf *)purb->context;
197 struct _adapter *padapter = (struct _adapter *)precvbuf->adapter; 198 struct _adapter *padapter = (struct _adapter *)precvbuf->adapter;
198 struct recv_priv *precvpriv = &padapter->recvpriv; 199 struct recv_priv *precvpriv = &padapter->recvpriv;
@@ -208,7 +209,7 @@ static void r8712_usb_read_port_complete(struct urb *purb)
208 _pkt *pskb = precvbuf->pskb; 209 _pkt *pskb = precvbuf->pskb;
209 210
210 precvbuf->transfer_len = purb->actual_length; 211 precvbuf->transfer_len = purb->actual_length;
211 pbuf = (uint *)precvbuf->pbuf; 212 pbuf = (__le32 *)precvbuf->pbuf;
212 isevt = le32_to_cpu(*(pbuf + 1)) & 0x1ff; 213 isevt = le32_to_cpu(*(pbuf + 1)) & 0x1ff;
213 if ((isevt & 0x1ff) == 0x1ff) { 214 if ((isevt & 0x1ff) == 0x1ff) {
214 r8712_rxcmd_event_hdl(padapter, pbuf); 215 r8712_rxcmd_event_hdl(padapter, pbuf);
diff --git a/drivers/staging/rtl8712/wifi.h b/drivers/staging/rtl8712/wifi.h
index b8af9656e6da..74dfc9b0e494 100644
--- a/drivers/staging/rtl8712/wifi.h
+++ b/drivers/staging/rtl8712/wifi.h
@@ -151,138 +151,133 @@ enum WIFI_REG_DOMAIN {
151#define _ORDER_ BIT(15) 151#define _ORDER_ BIT(15)
152 152
153#define SetToDs(pbuf) ({ \ 153#define SetToDs(pbuf) ({ \
154 *(unsigned short *)(pbuf) |= cpu_to_le16(_TO_DS_); \ 154 *(__le16 *)(pbuf) |= cpu_to_le16(_TO_DS_); \
155}) 155})
156 156
157#define GetToDs(pbuf) (((*(unsigned short *)(pbuf)) & \ 157#define GetToDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_TO_DS_)) != 0)
158 le16_to_cpu(_TO_DS_)) != 0)
159 158
160#define ClearToDs(pbuf) ({ \ 159#define ClearToDs(pbuf) ({ \
161 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \ 160 *(__le16 *)(pbuf) &= (~cpu_to_le16(_TO_DS_)); \
162}) 161})
163 162
164#define SetFrDs(pbuf) ({ \ 163#define SetFrDs(pbuf) ({ \
165 *(unsigned short *)(pbuf) |= cpu_to_le16(_FROM_DS_); \ 164 *(__le16 *)(pbuf) |= cpu_to_le16(_FROM_DS_); \
166}) 165})
167 166
168#define GetFrDs(pbuf) (((*(unsigned short *)(pbuf)) & \ 167#define GetFrDs(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_FROM_DS_)) != 0)
169 le16_to_cpu(_FROM_DS_)) != 0)
170 168
171#define ClearFrDs(pbuf) ({ \ 169#define ClearFrDs(pbuf) ({ \
172 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \ 170 *(__le16 *)(pbuf) &= (~cpu_to_le16(_FROM_DS_)); \
173}) 171})
174 172
175#define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe)) 173#define get_tofr_ds(pframe) ((GetToDs(pframe) << 1) | GetFrDs(pframe))
176 174
177 175
178#define SetMFrag(pbuf) ({ \ 176#define SetMFrag(pbuf) ({ \
179 *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \ 177 *(__le16 *)(pbuf) |= cpu_to_le16(_MORE_FRAG_); \
180}) 178})
181 179
182#define GetMFrag(pbuf) (((*(unsigned short *)(pbuf)) & \ 180#define GetMFrag(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_MORE_FRAG_)) != 0)
183 le16_to_cpu(_MORE_FRAG_)) != 0)
184 181
185#define ClearMFrag(pbuf) ({ \ 182#define ClearMFrag(pbuf) ({ \
186 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \ 183 *(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_FRAG_)); \
187}) 184})
188 185
189#define SetRetry(pbuf) ({ \ 186#define SetRetry(pbuf) ({ \
190 *(unsigned short *)(pbuf) |= cpu_to_le16(_RETRY_); \ 187 *(__le16 *)(pbuf) |= cpu_to_le16(_RETRY_); \
191}) 188})
192 189
193#define GetRetry(pbuf) (((*(unsigned short *)(pbuf)) & \ 190#define GetRetry(pbuf) (((*(__le16 *)(pbuf)) & cpu_to_le16(_RETRY_)) != 0)
194 le16_to_cpu(_RETRY_)) != 0)
195 191
196#define ClearRetry(pbuf) ({ \ 192#define ClearRetry(pbuf) ({ \
197 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \ 193 *(__le16 *)(pbuf) &= (~cpu_to_le16(_RETRY_)); \
198}) 194})
199 195
200#define SetPwrMgt(pbuf) ({ \ 196#define SetPwrMgt(pbuf) ({ \
201 *(unsigned short *)(pbuf) |= cpu_to_le16(_PWRMGT_); \ 197 *(__le16 *)(pbuf) |= cpu_to_le16(_PWRMGT_); \
202}) 198})
203 199
204#define GetPwrMgt(pbuf) (((*(unsigned short *)(pbuf)) & \ 200#define GetPwrMgt(pbuf) (((*(__le16 *)(pbuf)) & \
205 le16_to_cpu(_PWRMGT_)) != 0) 201 cpu_to_le16(_PWRMGT_)) != 0)
206 202
207#define ClearPwrMgt(pbuf) ({ \ 203#define ClearPwrMgt(pbuf) ({ \
208 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \ 204 *(__le16 *)(pbuf) &= (~cpu_to_le16(_PWRMGT_)); \
209}) 205})
210 206
211#define SetMData(pbuf) ({ \ 207#define SetMData(pbuf) ({ \
212 *(unsigned short *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \ 208 *(__le16 *)(pbuf) |= cpu_to_le16(_MORE_DATA_); \
213}) 209})
214 210
215#define GetMData(pbuf) (((*(unsigned short *)(pbuf)) & \ 211#define GetMData(pbuf) (((*(__le16 *)(pbuf)) & \
216 le16_to_cpu(_MORE_DATA_)) != 0) 212 cpu_to_le16(_MORE_DATA_)) != 0)
217 213
218#define ClearMData(pbuf) ({ \ 214#define ClearMData(pbuf) ({ \
219 *(unsigned short *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \ 215 *(__le16 *)(pbuf) &= (~cpu_to_le16(_MORE_DATA_)); \
220}) 216})
221 217
222#define SetPrivacy(pbuf) ({ \ 218#define SetPrivacy(pbuf) ({ \
223 *(unsigned short *)(pbuf) |= cpu_to_le16(_PRIVACY_); \ 219 *(__le16 *)(pbuf) |= cpu_to_le16(_PRIVACY_); \
224}) 220})
225 221
226#define GetPrivacy(pbuf) (((*(unsigned short *)(pbuf)) & \ 222#define GetPrivacy(pbuf) (((*(__le16 *)(pbuf)) & \
227 le16_to_cpu(_PRIVACY_)) != 0) 223 cpu_to_le16(_PRIVACY_)) != 0)
228 224
229#define GetOrder(pbuf) (((*(unsigned short *)(pbuf)) & \ 225#define GetOrder(pbuf) (((*(__le16 *)(pbuf)) & \
230 le16_to_cpu(_ORDER_)) != 0) 226 cpu_to_le16(_ORDER_)) != 0)
231 227
232#define GetFrameType(pbuf) (le16_to_cpu(*(unsigned short *)(pbuf)) & \ 228#define GetFrameType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
233 (BIT(3) | BIT(2))) 229 (BIT(3) | BIT(2)))
234 230
235#define SetFrameType(pbuf, type) \ 231#define SetFrameType(pbuf, type) \
236 do { \ 232 do { \
237 *(unsigned short *)(pbuf) &= cpu_to_le16(~(BIT(3) | \ 233 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(3) | \
238 BIT(2))); \ 234 BIT(2))); \
239 *(unsigned short *)(pbuf) |= cpu_to_le16(type); \ 235 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
240 } while (0) 236 } while (0)
241 237
242#define GetFrameSubType(pbuf) (cpu_to_le16(*(unsigned short *)(pbuf)) & \ 238#define GetFrameSubType(pbuf) (le16_to_cpu(*(__le16 *)(pbuf)) & \
243 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \ 239 (BIT(7) | BIT(6) | BIT(5) | BIT(4) | BIT(3) | \
244 BIT(2))) 240 BIT(2)))
245 241
246#define SetFrameSubType(pbuf, type) \ 242#define SetFrameSubType(pbuf, type) \
247 do { \ 243 do { \
248 *(unsigned short *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \ 244 *(__le16 *)(pbuf) &= cpu_to_le16(~(BIT(7) | BIT(6) | \
249 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \ 245 BIT(5) | BIT(4) | BIT(3) | BIT(2))); \
250 *(unsigned short *)(pbuf) |= cpu_to_le16(type); \ 246 *(__le16 *)(pbuf) |= cpu_to_le16(type); \
251 } while (0) 247 } while (0)
252 248
253#define GetSequence(pbuf) (cpu_to_le16(*(unsigned short *)\ 249#define GetSequence(pbuf) (le16_to_cpu(*(__le16 *)\
254 ((addr_t)(pbuf) + 22)) >> 4) 250 ((addr_t)(pbuf) + 22)) >> 4)
255 251
256#define GetFragNum(pbuf) (cpu_to_le16(*(unsigned short *)((addr_t)\ 252#define GetFragNum(pbuf) (le16_to_cpu(*(__le16 *)((addr_t)\
257 (pbuf) + 22)) & 0x0f) 253 (pbuf) + 22)) & 0x0f)
258 254
259#define SetSeqNum(pbuf, num) ({ \ 255#define SetSeqNum(pbuf, num) ({ \
260 *(unsigned short *)((addr_t)(pbuf) + 22) = \ 256 *(__le16 *)((addr_t)(pbuf) + 22) = \
261 ((*(unsigned short *)((addr_t)(pbuf) + 22)) & \ 257 cpu_to_le16((le16_to_cpu(*(__le16 *)((addr_t)(pbuf) + 22)) & \
262 le16_to_cpu((unsigned short)0x000f)) | \ 258 0x000f) | (0xfff0 & (num << 4))); \
263 le16_to_cpu((unsigned short)(0xfff0 & (num << 4))); \
264}) 259})
265 260
266#define SetDuration(pbuf, dur) ({ \ 261#define SetDuration(pbuf, dur) ({ \
267 *(unsigned short *)((addr_t)(pbuf) + 2) |= \ 262 *(__le16 *)((addr_t)(pbuf) + 2) |= \
268 cpu_to_le16(0xffff & (dur)); \ 263 cpu_to_le16(0xffff & (dur)); \
269}) 264})
270 265
271#define SetPriority(pbuf, tid) ({ \ 266#define SetPriority(pbuf, tid) ({ \
272 *(unsigned short *)(pbuf) |= cpu_to_le16(tid & 0xf); \ 267 *(__le16 *)(pbuf) |= cpu_to_le16(tid & 0xf); \
273}) 268})
274 269
275#define GetPriority(pbuf) ((le16_to_cpu(*(unsigned short *)(pbuf))) & 0xf) 270#define GetPriority(pbuf) ((le16_to_cpu(*(__le16 *)(pbuf))) & 0xf)
276 271
277#define SetAckpolicy(pbuf, ack) ({ \ 272#define SetAckpolicy(pbuf, ack) ({ \
278 *(unsigned short *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \ 273 *(__le16 *)(pbuf) |= cpu_to_le16((ack & 3) << 5); \
279}) 274})
280 275
281#define GetAckpolicy(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 5) & 0x3) 276#define GetAckpolicy(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 5) & 0x3)
282 277
283#define GetAMsdu(pbuf) (((le16_to_cpu(*(unsigned short *)pbuf)) >> 7) & 0x1) 278#define GetAMsdu(pbuf) (((le16_to_cpu(*(__le16 *)pbuf)) >> 7) & 0x1)
284 279
285#define GetAid(pbuf) (cpu_to_le16(*(unsigned short *)((addr_t)(pbuf) + 2)) \ 280#define GetAid(pbuf) (cpu_to_le16(*(__le16 *)((addr_t)(pbuf) + 2)) \
286 & 0x3fff) 281 & 0x3fff)
287 282
288#define GetAddr1Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 4)) 283#define GetAddr1Ptr(pbuf) ((unsigned char *)((addr_t)(pbuf) + 4))
@@ -476,10 +471,10 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
476#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800 471#define IEEE80211_DELBA_PARAM_INITIATOR_MASK 0x0800
477 472
478#define SetOrderBit(pbuf) ({ \ 473#define SetOrderBit(pbuf) ({ \
479 *(unsigned short *)(pbuf) |= cpu_to_le16(_ORDER_); \ 474 *(__le16 *)(pbuf) |= cpu_to_le16(_ORDER_); \
480}) 475})
481 476
482#define GetOrderBit(pbuf) (((*(unsigned short *)(pbuf)) & \ 477#define GetOrderBit(pbuf) (((*(__le16 *)(pbuf)) & \
483 le16_to_cpu(_ORDER_)) != 0) 478 le16_to_cpu(_ORDER_)) != 0)
484 479
485 480
@@ -490,12 +485,12 @@ static inline unsigned char *get_hdr_bssid(unsigned char *pframe)
490 * described in 802.11n draft section 7.2.1.7.1 485 * described in 802.11n draft section 7.2.1.7.1
491 */ 486 */
492struct ieee80211_bar { 487struct ieee80211_bar {
493 unsigned short frame_control; 488 __le16 frame_control;
494 unsigned short duration; 489 __le16 duration;
495 unsigned char ra[6]; 490 unsigned char ra[6];
496 unsigned char ta[6]; 491 unsigned char ta[6];
497 unsigned short control; 492 __le16 control;
498 unsigned short start_seq_num; 493 __le16 start_seq_num;
499} __packed; 494} __packed;
500 495
501/* 802.11 BAR control masks */ 496/* 802.11 BAR control masks */
@@ -511,11 +506,11 @@ struct ieee80211_bar {
511 */ 506 */
512 507
513struct ieee80211_ht_cap { 508struct ieee80211_ht_cap {
514 unsigned short cap_info; 509 __le16 cap_info;
515 unsigned char ampdu_params_info; 510 unsigned char ampdu_params_info;
516 unsigned char supp_mcs_set[16]; 511 unsigned char supp_mcs_set[16];
517 unsigned short extended_ht_cap_info; 512 __le16 extended_ht_cap_info;
518 unsigned int tx_BF_cap_info; 513 __le32 tx_BF_cap_info;
519 unsigned char antenna_selection_info; 514 unsigned char antenna_selection_info;
520} __packed; 515} __packed;
521 516
@@ -528,8 +523,8 @@ struct ieee80211_ht_cap {
528struct ieee80211_ht_addt_info { 523struct ieee80211_ht_addt_info {
529 unsigned char control_chan; 524 unsigned char control_chan;
530 unsigned char ht_param; 525 unsigned char ht_param;
531 unsigned short operation_mode; 526 __le16 operation_mode;
532 unsigned short stbc_param; 527 __le16 stbc_param;
533 unsigned char basic_set[16]; 528 unsigned char basic_set[16];
534} __packed; 529} __packed;
535 530
diff --git a/drivers/staging/rtl8712/wlan_bssdef.h b/drivers/staging/rtl8712/wlan_bssdef.h
index 86a88b493a43..c0654ae4d70d 100644
--- a/drivers/staging/rtl8712/wlan_bssdef.h
+++ b/drivers/staging/rtl8712/wlan_bssdef.h
@@ -83,7 +83,7 @@ struct wlan_bssid_ex {
83 unsigned char MacAddress[6]; 83 unsigned char MacAddress[6];
84 u8 Reserved[2]; 84 u8 Reserved[2];
85 struct ndis_802_11_ssid Ssid; 85 struct ndis_802_11_ssid Ssid;
86 u32 Privacy; 86 __le32 Privacy;
87 s32 Rssi; 87 s32 Rssi;
88 enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; 88 enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
89 struct NDIS_802_11_CONFIGURATION Configuration; 89 struct NDIS_802_11_CONFIGURATION Configuration;
diff --git a/drivers/staging/rts5208/ms.c b/drivers/staging/rts5208/ms.c
index 28d56c5d1449..806c12180714 100644
--- a/drivers/staging/rts5208/ms.c
+++ b/drivers/staging/rts5208/ms.c
@@ -1108,12 +1108,6 @@ static int ms_read_attribute_info(struct rtsx_chip *chip)
1108 i++; 1108 i++;
1109 } while (i < 1024); 1109 } while (i < 1024);
1110 1110
1111 if (retval != STATUS_SUCCESS) {
1112 kfree(buf);
1113 rtsx_trace(chip);
1114 return STATUS_FAIL;
1115 }
1116
1117 if ((buf[0] != 0xa5) && (buf[1] != 0xc3)) { 1111 if ((buf[0] != 0xa5) && (buf[1] != 0xc3)) {
1118 /* Signature code is wrong */ 1112 /* Signature code is wrong */
1119 kfree(buf); 1113 kfree(buf);
diff --git a/drivers/staging/rts5208/rtsx.c b/drivers/staging/rts5208/rtsx.c
index 68d75d0d5efd..b8177f50fabc 100644
--- a/drivers/staging/rts5208/rtsx.c
+++ b/drivers/staging/rts5208/rtsx.c
@@ -198,23 +198,21 @@ static int command_abort(struct scsi_cmnd *srb)
198 */ 198 */
199static int device_reset(struct scsi_cmnd *srb) 199static int device_reset(struct scsi_cmnd *srb)
200{ 200{
201 int result = 0;
202 struct rtsx_dev *dev = host_to_rtsx(srb->device->host); 201 struct rtsx_dev *dev = host_to_rtsx(srb->device->host);
203 202
204 dev_info(&dev->pci->dev, "%s called\n", __func__); 203 dev_info(&dev->pci->dev, "%s called\n", __func__);
205 204
206 return result < 0 ? FAILED : SUCCESS; 205 return SUCCESS;
207} 206}
208 207
209/* Simulate a SCSI bus reset by resetting the device's USB port. */ 208/* Simulate a SCSI bus reset by resetting the device's USB port. */
210static int bus_reset(struct scsi_cmnd *srb) 209static int bus_reset(struct scsi_cmnd *srb)
211{ 210{
212 int result = 0;
213 struct rtsx_dev *dev = host_to_rtsx(srb->device->host); 211 struct rtsx_dev *dev = host_to_rtsx(srb->device->host);
214 212
215 dev_info(&dev->pci->dev, "%s called\n", __func__); 213 dev_info(&dev->pci->dev, "%s called\n", __func__);
216 214
217 return result < 0 ? FAILED : SUCCESS; 215 return SUCCESS;
218} 216}
219 217
220/* 218/*
diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
index 4d8e7c5c26d5..23799013c432 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -207,7 +207,7 @@ handle_errors:
207void rtsx_add_cmd(struct rtsx_chip *chip, 207void rtsx_add_cmd(struct rtsx_chip *chip,
208 u8 cmd_type, u16 reg_addr, u8 mask, u8 data) 208 u8 cmd_type, u16 reg_addr, u8 mask, u8 data)
209{ 209{
210 u32 *cb = (u32 *)(chip->host_cmds_ptr); 210 __le32 *cb = (__le32 *)(chip->host_cmds_ptr);
211 u32 val = 0; 211 u32 val = 0;
212 212
213 val |= (u32)(cmd_type & 0x03) << 30; 213 val |= (u32)(cmd_type & 0x03) << 30;
@@ -300,7 +300,7 @@ finish_send_cmd:
300static inline void rtsx_add_sg_tbl( 300static inline void rtsx_add_sg_tbl(
301 struct rtsx_chip *chip, u32 addr, u32 len, u8 option) 301 struct rtsx_chip *chip, u32 addr, u32 len, u8 option)
302{ 302{
303 u64 *sgb = (u64 *)(chip->host_sg_tbl_ptr); 303 __le64 *sgb = (__le64 *)(chip->host_sg_tbl_ptr);
304 u64 val = 0; 304 u64 val = 0;
305 u32 temp_len = 0; 305 u32 temp_len = 0;
306 u8 temp_opt = 0; 306 u8 temp_opt = 0;
diff --git a/drivers/staging/skein/skein_base.c b/drivers/staging/skein/skein_base.c
index c24a57396483..8db858a11875 100644
--- a/drivers/staging/skein/skein_base.c
+++ b/drivers/staging/skein/skein_base.c
@@ -1,12 +1,12 @@
1/*********************************************************************** 1/***********************************************************************
2** 2 **
3** Implementation of the Skein hash function. 3 ** Implementation of the Skein hash function.
4** 4 **
5** Source code author: Doug Whiting, 2008. 5 ** Source code author: Doug Whiting, 2008.
6** 6 **
7** This algorithm and source code is released to the public domain. 7 ** This algorithm and source code is released to the public domain.
8** 8 **
9************************************************************************/ 9 ************************************************************************/
10 10
11#include <linux/string.h> /* get the memcpy/memset functions */ 11#include <linux/string.h> /* get the memcpy/memset functions */
12#include <linux/export.h> 12#include <linux/export.h>
diff --git a/drivers/staging/skein/skein_base.h b/drivers/staging/skein/skein_base.h
index dc464f334a58..cd794c1bc1bb 100644
--- a/drivers/staging/skein/skein_base.h
+++ b/drivers/staging/skein/skein_base.h
@@ -1,28 +1,30 @@
1#ifndef _SKEIN_H_ 1#ifndef _SKEIN_H_
2#define _SKEIN_H_ 1 2#define _SKEIN_H_ 1
3/************************************************************************** 3/*
4** 4 **************************************************************************
5** Interface declarations and internal definitions for Skein hashing. 5 *
6** 6 * Interface declarations and internal definitions for Skein hashing.
7** Source code author: Doug Whiting, 2008. 7 *
8** 8 * Source code author: Doug Whiting, 2008.
9** This algorithm and source code is released to the public domain. 9 *
10** 10 * This algorithm and source code is released to the public domain.
11*************************************************************************** 11 *
12** 12 **************************************************************************
13** The following compile-time switches may be defined to control some 13 *
14** tradeoffs between speed, code size, error checking, and security. 14 * The following compile-time switches may be defined to control some
15** 15 * tradeoffs between speed, code size, error checking, and security.
16** The "default" note explains what happens when the switch is not defined. 16 *
17** 17 * The "default" note explains what happens when the switch is not defined.
18** SKEIN_ERR_CHECK -- how error checking is handled inside Skein 18 *
19** code. If not defined, most error checking 19 * SKEIN_ERR_CHECK -- how error checking is handled inside Skein
20** is disabled (for performance). Otherwise, 20 * code. If not defined, most error checking
21** the switch value is interpreted as: 21 * is disabled (for performance). Otherwise,
22** 0: use assert() to flag errors 22 * the switch value is interpreted as:
23** 1: return SKEIN_FAIL to flag errors 23 * 0: use assert() to flag errors
24** 24 * 1: return SKEIN_FAIL to flag errors
25***************************************************************************/ 25 *
26 **************************************************************************
27 */
26 28
27/*Skein digest sizes for crypto api*/ 29/*Skein digest sizes for crypto api*/
28#define SKEIN256_DIGEST_BIT_SIZE 256 30#define SKEIN256_DIGEST_BIT_SIZE 256
@@ -101,19 +103,19 @@ int skein_512_final(struct skein_512_ctx *ctx, u8 *hash_val);
101int skein_1024_final(struct skein_1024_ctx *ctx, u8 *hash_val); 103int skein_1024_final(struct skein_1024_ctx *ctx, u8 *hash_val);
102 104
103/* 105/*
104** Skein APIs for "extended" initialization: MAC keys, tree hashing. 106 * Skein APIs for "extended" initialization: MAC keys, tree hashing.
105** After an init_ext() call, just use update/final calls as with init(). 107 * After an init_ext() call, just use update/final calls as with init().
106** 108 *
107** Notes: Same parameters as _init() calls, plus tree_info/key/key_bytes. 109 * Notes: Same parameters as _init() calls, plus tree_info/key/key_bytes.
108** When key_bytes == 0 and tree_info == SKEIN_SEQUENTIAL, 110 * When key_bytes == 0 and tree_info == SKEIN_SEQUENTIAL,
109** the results of init_ext() are identical to calling init(). 111 * the results of init_ext() are identical to calling init().
110** The function init() may be called once to "precompute" the IV for 112 * The function init() may be called once to "precompute" the IV for
111** a given hash_bit_len value, then by saving a copy of the context 113 * a given hash_bit_len value, then by saving a copy of the context
112** the IV computation may be avoided in later calls. 114 * the IV computation may be avoided in later calls.
113** Similarly, the function init_ext() may be called once per MAC key 115 * Similarly, the function init_ext() may be called once per MAC key
114** to precompute the MAC IV, then a copy of the context saved and 116 * to precompute the MAC IV, then a copy of the context saved and
115** reused for each new MAC computation. 117 * reused for each new MAC computation.
116**/ 118 */
117int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len, 119int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len,
118 u64 tree_info, const u8 *key, size_t key_bytes); 120 u64 tree_info, const u8 *key, size_t key_bytes);
119int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len, 121int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len,
@@ -122,10 +124,10 @@ int skein_1024_init_ext(struct skein_1024_ctx *ctx, size_t hash_bit_len,
122 u64 tree_info, const u8 *key, size_t key_bytes); 124 u64 tree_info, const u8 *key, size_t key_bytes);
123 125
124/* 126/*
125** Skein APIs for MAC and tree hash: 127 * Skein APIs for MAC and tree hash:
126** final_pad: pad, do final block, but no OUTPUT type 128 * final_pad: pad, do final block, but no OUTPUT type
127** output: do just the output stage 129 * output: do just the output stage
128*/ 130 */
129int skein_256_final_pad(struct skein_256_ctx *ctx, u8 *hash_val); 131int skein_256_final_pad(struct skein_256_ctx *ctx, u8 *hash_val);
130int skein_512_final_pad(struct skein_512_ctx *ctx, u8 *hash_val); 132int skein_512_final_pad(struct skein_512_ctx *ctx, u8 *hash_val);
131int skein_1024_final_pad(struct skein_1024_ctx *ctx, u8 *hash_val); 133int skein_1024_final_pad(struct skein_1024_ctx *ctx, u8 *hash_val);
@@ -139,13 +141,15 @@ int skein_512_output(struct skein_512_ctx *ctx, u8 *hash_val);
139int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val); 141int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val);
140#endif 142#endif
141 143
142/***************************************************************** 144/*
143** "Internal" Skein definitions 145 *****************************************************************
144** -- not needed for sequential hashing API, but will be 146 * "Internal" Skein definitions
145** helpful for other uses of Skein (e.g., tree hash mode). 147 * -- not needed for sequential hashing API, but will be
146** -- included here so that they can be shared between 148 * helpful for other uses of Skein (e.g., tree hash mode).
147** reference and optimized code. 149 * -- included here so that they can be shared between
148******************************************************************/ 150 * reference and optimized code.
151 *****************************************************************
152 */
149 153
150/* tweak word tweak[1]: bit field starting positions */ 154/* tweak word tweak[1]: bit field starting positions */
151#define SKEIN_T1_BIT(BIT) ((BIT) - 64) /* second word */ 155#define SKEIN_T1_BIT(BIT) ((BIT) - 64) /* second word */
@@ -226,9 +230,9 @@ int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val);
226#define SKEIN_CFG_TREE_INFO_SEQUENTIAL SKEIN_CFG_TREE_INFO(0, 0, 0) 230#define SKEIN_CFG_TREE_INFO_SEQUENTIAL SKEIN_CFG_TREE_INFO(0, 0, 0)
227 231
228/* 232/*
229** Skein macros for getting/setting tweak words, etc. 233 * Skein macros for getting/setting tweak words, etc.
230** These are useful for partial input bytes, hash tree init/update, etc. 234 * These are useful for partial input bytes, hash tree init/update, etc.
231**/ 235 */
232#define skein_get_tweak(ctx_ptr, TWK_NUM) ((ctx_ptr)->h.tweak[TWK_NUM]) 236#define skein_get_tweak(ctx_ptr, TWK_NUM) ((ctx_ptr)->h.tweak[TWK_NUM])
233#define skein_set_tweak(ctx_ptr, TWK_NUM, t_val) { \ 237#define skein_set_tweak(ctx_ptr, TWK_NUM, t_val) { \
234 (ctx_ptr)->h.tweak[TWK_NUM] = (t_val); \ 238 (ctx_ptr)->h.tweak[TWK_NUM] = (t_val); \
@@ -274,9 +278,11 @@ int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val);
274#define skein_assert_ret(x, ret_code) 278#define skein_assert_ret(x, ret_code)
275#define skein_assert(x) 279#define skein_assert(x)
276 280
277/***************************************************************** 281/*
278** Skein block function constants (shared across Ref and Opt code) 282 *****************************************************************
279******************************************************************/ 283 * Skein block function constants (shared across Ref and Opt code)
284 *****************************************************************
285 */
280enum { 286enum {
281 /* SKEIN_256 round rotation constants */ 287 /* SKEIN_256 round rotation constants */
282 R_256_0_0 = 14, R_256_0_1 = 16, 288 R_256_0_0 = 14, R_256_0_1 = 16,
diff --git a/drivers/staging/skein/skein_block.c b/drivers/staging/skein/skein_block.c
index 59a0a8a82118..256657077a46 100644
--- a/drivers/staging/skein/skein_block.c
+++ b/drivers/staging/skein/skein_block.c
@@ -1,18 +1,20 @@
1/*********************************************************************** 1/*
2** 2 ***********************************************************************
3** Implementation of the Skein block functions. 3 *
4** 4 * Implementation of the Skein block functions.
5** Source code author: Doug Whiting, 2008. 5 *
6** 6 * Source code author: Doug Whiting, 2008.
7** This algorithm and source code is released to the public domain. 7 *
8** 8 * This algorithm and source code is released to the public domain.
9** Compile-time switches: 9 *
10** 10 * Compile-time switches:
11** SKEIN_USE_ASM -- set bits (256/512/1024) to select which 11 *
12** versions use ASM code for block processing 12 * SKEIN_USE_ASM -- set bits (256/512/1024) to select which
13** [default: use C for all block sizes] 13 * versions use ASM code for block processing
14** 14 * [default: use C for all block sizes]
15************************************************************************/ 15 *
16 ***********************************************************************
17 */
16 18
17#include <linux/string.h> 19#include <linux/string.h>
18#include <linux/bitops.h> 20#include <linux/bitops.h>
diff --git a/drivers/staging/skein/skein_block.h b/drivers/staging/skein/skein_block.h
index 9d40f4a5267b..ec1baea25c9e 100644
--- a/drivers/staging/skein/skein_block.h
+++ b/drivers/staging/skein/skein_block.h
@@ -1,12 +1,14 @@
1/*********************************************************************** 1/*
2** 2 ***********************************************************************
3** Implementation of the Skein hash function. 3 *
4** 4 * Implementation of the Skein hash function.
5** Source code author: Doug Whiting, 2008. 5 *
6** 6 * Source code author: Doug Whiting, 2008.
7** This algorithm and source code is released to the public domain. 7 *
8** 8 * This algorithm and source code is released to the public domain.
9************************************************************************/ 9 *
10 ***********************************************************************
11 */
10#ifndef _SKEIN_BLOCK_H_ 12#ifndef _SKEIN_BLOCK_H_
11#define _SKEIN_BLOCK_H_ 13#define _SKEIN_BLOCK_H_
12 14
diff --git a/drivers/staging/skein/skein_iv.h b/drivers/staging/skein/skein_iv.h
index 8a06314d0ed4..509d464c65a3 100644
--- a/drivers/staging/skein/skein_iv.h
+++ b/drivers/staging/skein/skein_iv.h
@@ -4,18 +4,18 @@
4#include "skein_base.h" /* get Skein macros and types */ 4#include "skein_base.h" /* get Skein macros and types */
5 5
6/* 6/*
7***************** Pre-computed Skein IVs ******************* 7 **************** Pre-computed Skein IVs *******************
8** 8 *
9** NOTE: these values are not "magic" constants, but 9 * NOTE: these values are not "magic" constants, but
10** are generated using the Threefish block function. 10 * are generated using the Threefish block function.
11** They are pre-computed here only for speed; i.e., to 11 * They are pre-computed here only for speed; i.e., to
12** avoid the need for a Threefish call during Init(). 12 * avoid the need for a Threefish call during Init().
13** 13 *
14** The IV for any fixed hash length may be pre-computed. 14 * The IV for any fixed hash length may be pre-computed.
15** Only the most common values are included here. 15 * Only the most common values are included here.
16** 16 *
17************************************************************ 17 ***********************************************************
18**/ 18 */
19 19
20#define MK_64 SKEIN_MK_64 20#define MK_64 SKEIN_MK_64
21 21
diff --git a/drivers/staging/sm750fb/ddk750_chip.c b/drivers/staging/sm750fb/ddk750_chip.c
index f59ce5c0867d..10cf7295dc6c 100644
--- a/drivers/staging/sm750fb/ddk750_chip.c
+++ b/drivers/staging/sm750fb/ddk750_chip.c
@@ -25,8 +25,9 @@ void sm750_set_chip_type(unsigned short devId, u8 revId)
25 chip = SM750LE; 25 chip = SM750LE;
26 pr_info("found sm750le\n"); 26 pr_info("found sm750le\n");
27 } 27 }
28 } else 28 } else {
29 chip = SM_UNKNOWN; 29 chip = SM_UNKNOWN;
30 }
30} 31}
31 32
32static unsigned int get_mxclk_freq(void) 33static unsigned int get_mxclk_freq(void)
@@ -37,7 +38,7 @@ static unsigned int get_mxclk_freq(void)
37 if (sm750_get_chip_type() == SM750LE) 38 if (sm750_get_chip_type() == SM750LE)
38 return MHz(130); 39 return MHz(130);
39 40
40 pll_reg = PEEK32(MXCLK_PLL_CTRL); 41 pll_reg = peek32(MXCLK_PLL_CTRL);
41 M = (pll_reg & PLL_CTRL_M_MASK) >> PLL_CTRL_M_SHIFT; 42 M = (pll_reg & PLL_CTRL_M_MASK) >> PLL_CTRL_M_SHIFT;
42 N = (pll_reg & PLL_CTRL_N_MASK) >> PLL_CTRL_M_SHIFT; 43 N = (pll_reg & PLL_CTRL_N_MASK) >> PLL_CTRL_M_SHIFT;
43 OD = (pll_reg & PLL_CTRL_OD_MASK) >> PLL_CTRL_OD_SHIFT; 44 OD = (pll_reg & PLL_CTRL_OD_MASK) >> PLL_CTRL_OD_SHIFT;
@@ -77,7 +78,7 @@ static void set_chip_clock(unsigned int frequency)
77 ulActualMxClk = sm750_calc_pll_value(frequency, &pll); 78 ulActualMxClk = sm750_calc_pll_value(frequency, &pll);
78 79
79 /* Master Clock Control: MXCLK_PLL */ 80 /* Master Clock Control: MXCLK_PLL */
80 POKE32(MXCLK_PLL_CTRL, sm750_format_pll_reg(&pll)); 81 poke32(MXCLK_PLL_CTRL, sm750_format_pll_reg(&pll));
81 } 82 }
82} 83}
83 84
@@ -104,7 +105,7 @@ static void set_memory_clock(unsigned int frequency)
104 divisor = DIV_ROUND_CLOSEST(get_mxclk_freq(), frequency); 105 divisor = DIV_ROUND_CLOSEST(get_mxclk_freq(), frequency);
105 106
106 /* Set the corresponding divisor in the register. */ 107 /* Set the corresponding divisor in the register. */
107 reg = PEEK32(CURRENT_GATE) & ~CURRENT_GATE_M2XCLK_MASK; 108 reg = peek32(CURRENT_GATE) & ~CURRENT_GATE_M2XCLK_MASK;
108 switch (divisor) { 109 switch (divisor) {
109 default: 110 default:
110 case 1: 111 case 1:
@@ -156,7 +157,7 @@ static void set_master_clock(unsigned int frequency)
156 divisor = DIV_ROUND_CLOSEST(get_mxclk_freq(), frequency); 157 divisor = DIV_ROUND_CLOSEST(get_mxclk_freq(), frequency);
157 158
158 /* Set the corresponding divisor in the register. */ 159 /* Set the corresponding divisor in the register. */
159 reg = PEEK32(CURRENT_GATE) & ~CURRENT_GATE_MCLK_MASK; 160 reg = peek32(CURRENT_GATE) & ~CURRENT_GATE_MCLK_MASK;
160 switch (divisor) { 161 switch (divisor) {
161 default: 162 default:
162 case 3: 163 case 3:
@@ -187,12 +188,12 @@ unsigned int ddk750_get_vm_size(void)
187 return SZ_64M; 188 return SZ_64M;
188 189
189 /* for 750,always use power mode0*/ 190 /* for 750,always use power mode0*/
190 reg = PEEK32(MODE0_GATE); 191 reg = peek32(MODE0_GATE);
191 reg |= MODE0_GATE_GPIO; 192 reg |= MODE0_GATE_GPIO;
192 POKE32(MODE0_GATE, reg); 193 poke32(MODE0_GATE, reg);
193 194
194 /* get frame buffer size from GPIO */ 195 /* get frame buffer size from GPIO */
195 reg = PEEK32(MISC_CTRL) & MISC_CTRL_LOCALMEM_SIZE_MASK; 196 reg = peek32(MISC_CTRL) & MISC_CTRL_LOCALMEM_SIZE_MASK;
196 switch (reg) { 197 switch (reg) {
197 case MISC_CTRL_LOCALMEM_SIZE_8M: 198 case MISC_CTRL_LOCALMEM_SIZE_8M:
198 data = SZ_8M; break; /* 8 Mega byte */ 199 data = SZ_8M; break; /* 8 Mega byte */
@@ -218,15 +219,15 @@ int ddk750_init_hw(struct initchip_param *pInitParam)
218 sm750_set_power_mode(pInitParam->powerMode); 219 sm750_set_power_mode(pInitParam->powerMode);
219 220
220 /* Enable display power gate & LOCALMEM power gate*/ 221 /* Enable display power gate & LOCALMEM power gate*/
221 reg = PEEK32(CURRENT_GATE); 222 reg = peek32(CURRENT_GATE);
222 reg |= (CURRENT_GATE_DISPLAY | CURRENT_GATE_LOCALMEM); 223 reg |= (CURRENT_GATE_DISPLAY | CURRENT_GATE_LOCALMEM);
223 sm750_set_current_gate(reg); 224 sm750_set_current_gate(reg);
224 225
225 if (sm750_get_chip_type() != SM750LE) { 226 if (sm750_get_chip_type() != SM750LE) {
226 /* set panel pll and graphic mode via mmio_88 */ 227 /* set panel pll and graphic mode via mmio_88 */
227 reg = PEEK32(VGA_CONFIGURATION); 228 reg = peek32(VGA_CONFIGURATION);
228 reg |= (VGA_CONFIGURATION_PLL | VGA_CONFIGURATION_MODE); 229 reg |= (VGA_CONFIGURATION_PLL | VGA_CONFIGURATION_MODE);
229 POKE32(VGA_CONFIGURATION, reg); 230 poke32(VGA_CONFIGURATION, reg);
230 } else { 231 } else {
231#if defined(__i386__) || defined(__x86_64__) 232#if defined(__i386__) || defined(__x86_64__)
232 /* set graphic mode via IO method */ 233 /* set graphic mode via IO method */
@@ -244,7 +245,6 @@ int ddk750_init_hw(struct initchip_param *pInitParam)
244 /* Set up master clock */ 245 /* Set up master clock */
245 set_master_clock(MHz(pInitParam->masterClock)); 246 set_master_clock(MHz(pInitParam->masterClock));
246 247
247
248 /* 248 /*
249 * Reset the memory controller. 249 * Reset the memory controller.
250 * If the memory controller is not reset in SM750, 250 * If the memory controller is not reset in SM750,
@@ -252,36 +252,36 @@ int ddk750_init_hw(struct initchip_param *pInitParam)
252 * The memory should be resetted after changing the MXCLK. 252 * The memory should be resetted after changing the MXCLK.
253 */ 253 */
254 if (pInitParam->resetMemory == 1) { 254 if (pInitParam->resetMemory == 1) {
255 reg = PEEK32(MISC_CTRL); 255 reg = peek32(MISC_CTRL);
256 reg &= ~MISC_CTRL_LOCALMEM_RESET; 256 reg &= ~MISC_CTRL_LOCALMEM_RESET;
257 POKE32(MISC_CTRL, reg); 257 poke32(MISC_CTRL, reg);
258 258
259 reg |= MISC_CTRL_LOCALMEM_RESET; 259 reg |= MISC_CTRL_LOCALMEM_RESET;
260 POKE32(MISC_CTRL, reg); 260 poke32(MISC_CTRL, reg);
261 } 261 }
262 262
263 if (pInitParam->setAllEngOff == 1) { 263 if (pInitParam->setAllEngOff == 1) {
264 sm750_enable_2d_engine(0); 264 sm750_enable_2d_engine(0);
265 265
266 /* Disable Overlay, if a former application left it on */ 266 /* Disable Overlay, if a former application left it on */
267 reg = PEEK32(VIDEO_DISPLAY_CTRL); 267 reg = peek32(VIDEO_DISPLAY_CTRL);
268 reg &= ~DISPLAY_CTRL_PLANE; 268 reg &= ~DISPLAY_CTRL_PLANE;
269 POKE32(VIDEO_DISPLAY_CTRL, reg); 269 poke32(VIDEO_DISPLAY_CTRL, reg);
270 270
271 /* Disable video alpha, if a former application left it on */ 271 /* Disable video alpha, if a former application left it on */
272 reg = PEEK32(VIDEO_ALPHA_DISPLAY_CTRL); 272 reg = peek32(VIDEO_ALPHA_DISPLAY_CTRL);
273 reg &= ~DISPLAY_CTRL_PLANE; 273 reg &= ~DISPLAY_CTRL_PLANE;
274 POKE32(VIDEO_ALPHA_DISPLAY_CTRL, reg); 274 poke32(VIDEO_ALPHA_DISPLAY_CTRL, reg);
275 275
276 /* Disable alpha plane, if a former application left it on */ 276 /* Disable alpha plane, if a former application left it on */
277 reg = PEEK32(ALPHA_DISPLAY_CTRL); 277 reg = peek32(ALPHA_DISPLAY_CTRL);
278 reg &= ~DISPLAY_CTRL_PLANE; 278 reg &= ~DISPLAY_CTRL_PLANE;
279 POKE32(ALPHA_DISPLAY_CTRL, reg); 279 poke32(ALPHA_DISPLAY_CTRL, reg);
280 280
281 /* Disable DMA Channel, if a former application left it on */ 281 /* Disable DMA Channel, if a former application left it on */
282 reg = PEEK32(DMA_ABORT_INTERRUPT); 282 reg = peek32(DMA_ABORT_INTERRUPT);
283 reg |= DMA_ABORT_INTERRUPT_ABORT_1; 283 reg |= DMA_ABORT_INTERRUPT_ABORT_1;
284 POKE32(DMA_ABORT_INTERRUPT, reg); 284 poke32(DMA_ABORT_INTERRUPT, reg);
285 285
286 /* Disable DMA Power, if a former application left it on */ 286 /* Disable DMA Power, if a former application left it on */
287 sm750_enable_dma(0); 287 sm750_enable_dma(0);
@@ -407,5 +407,3 @@ unsigned int sm750_format_pll_reg(struct pll_value *pPLL)
407 407
408 return reg; 408 return reg;
409} 409}
410
411
diff --git a/drivers/staging/sm750fb/ddk750_chip.h b/drivers/staging/sm750fb/ddk750_chip.h
index e63b8b293816..fbeb615aa432 100644
--- a/drivers/staging/sm750fb/ddk750_chip.h
+++ b/drivers/staging/sm750fb/ddk750_chip.h
@@ -9,11 +9,18 @@
9#include <linux/ioport.h> 9#include <linux/ioport.h>
10#include <linux/uaccess.h> 10#include <linux/uaccess.h>
11 11
12extern void __iomem *mmio750;
13
12/* software control endianness */ 14/* software control endianness */
13#define PEEK32(addr) readl(addr + mmio750) 15static inline u32 peek32(u32 addr)
14#define POKE32(addr, data) writel(data, addr + mmio750) 16{
17 return readl(addr + mmio750);
18}
15 19
16extern void __iomem *mmio750; 20static inline void poke32(u32 data, u32 addr)
21{
22 writel(data, addr + mmio750);
23}
17 24
18/* This is all the chips recognized by this library */ 25/* This is all the chips recognized by this library */
19typedef enum _logical_chip_type_t { 26typedef enum _logical_chip_type_t {
diff --git a/drivers/staging/sm750fb/ddk750_display.c b/drivers/staging/sm750fb/ddk750_display.c
index c347803f7e19..e4724a660d07 100644
--- a/drivers/staging/sm750fb/ddk750_display.c
+++ b/drivers/staging/sm750fb/ddk750_display.c
@@ -18,7 +18,7 @@ static void setDisplayControl(int ctrl, int disp_state)
18 reserved = CRT_DISPLAY_CTRL_RESERVED_MASK; 18 reserved = CRT_DISPLAY_CTRL_RESERVED_MASK;
19 } 19 }
20 20
21 val = PEEK32(reg); 21 val = peek32(reg);
22 if (disp_state) { 22 if (disp_state) {
23 /* 23 /*
24 * Timing should be enabled first before enabling the 24 * Timing should be enabled first before enabling the
@@ -27,7 +27,7 @@ static void setDisplayControl(int ctrl, int disp_state)
27 * disabled. 27 * disabled.
28 */ 28 */
29 val |= DISPLAY_CTRL_TIMING; 29 val |= DISPLAY_CTRL_TIMING;
30 POKE32(reg, val); 30 poke32(reg, val);
31 31
32 val |= DISPLAY_CTRL_PLANE; 32 val |= DISPLAY_CTRL_PLANE;
33 33
@@ -38,8 +38,8 @@ static void setDisplayControl(int ctrl, int disp_state)
38 */ 38 */
39 do { 39 do {
40 cnt++; 40 cnt++;
41 POKE32(reg, val); 41 poke32(reg, val);
42 } while ((PEEK32(reg) & ~reserved) != (val & ~reserved)); 42 } while ((peek32(reg) & ~reserved) != (val & ~reserved));
43 pr_debug("Set Plane enbit:after tried %d times\n", cnt); 43 pr_debug("Set Plane enbit:after tried %d times\n", cnt);
44 } else { 44 } else {
45 /* 45 /*
@@ -52,10 +52,10 @@ static void setDisplayControl(int ctrl, int disp_state)
52 * before modifying the timing enable bit. 52 * before modifying the timing enable bit.
53 */ 53 */
54 val &= ~DISPLAY_CTRL_PLANE; 54 val &= ~DISPLAY_CTRL_PLANE;
55 POKE32(reg, val); 55 poke32(reg, val);
56 56
57 val &= ~DISPLAY_CTRL_TIMING; 57 val &= ~DISPLAY_CTRL_TIMING;
58 POKE32(reg, val); 58 poke32(reg, val);
59 } 59 }
60} 60}
61 61
@@ -67,19 +67,19 @@ static void primary_wait_vertical_sync(int delay)
67 * Do not wait when the Primary PLL is off or display control is 67 * Do not wait when the Primary PLL is off or display control is
68 * already off. This will prevent the software to wait forever. 68 * already off. This will prevent the software to wait forever.
69 */ 69 */
70 if (!(PEEK32(PANEL_PLL_CTRL) & PLL_CTRL_POWER) || 70 if (!(peek32(PANEL_PLL_CTRL) & PLL_CTRL_POWER) ||
71 !(PEEK32(PANEL_DISPLAY_CTRL) & DISPLAY_CTRL_TIMING)) 71 !(peek32(PANEL_DISPLAY_CTRL) & DISPLAY_CTRL_TIMING))
72 return; 72 return;
73 73
74 while (delay-- > 0) { 74 while (delay-- > 0) {
75 /* Wait for end of vsync. */ 75 /* Wait for end of vsync. */
76 do { 76 do {
77 status = PEEK32(SYSTEM_CTRL); 77 status = peek32(SYSTEM_CTRL);
78 } while (status & SYSTEM_CTRL_PANEL_VSYNC_ACTIVE); 78 } while (status & SYSTEM_CTRL_PANEL_VSYNC_ACTIVE);
79 79
80 /* Wait for start of vsync. */ 80 /* Wait for start of vsync. */
81 do { 81 do {
82 status = PEEK32(SYSTEM_CTRL); 82 status = peek32(SYSTEM_CTRL);
83 } while (!(status & SYSTEM_CTRL_PANEL_VSYNC_ACTIVE)); 83 } while (!(status & SYSTEM_CTRL_PANEL_VSYNC_ACTIVE));
84 } 84 }
85} 85}
@@ -89,24 +89,24 @@ static void swPanelPowerSequence(int disp, int delay)
89 unsigned int reg; 89 unsigned int reg;
90 90
91 /* disp should be 1 to open sequence */ 91 /* disp should be 1 to open sequence */
92 reg = PEEK32(PANEL_DISPLAY_CTRL); 92 reg = peek32(PANEL_DISPLAY_CTRL);
93 reg |= (disp ? PANEL_DISPLAY_CTRL_FPEN : 0); 93 reg |= (disp ? PANEL_DISPLAY_CTRL_FPEN : 0);
94 POKE32(PANEL_DISPLAY_CTRL, reg); 94 poke32(PANEL_DISPLAY_CTRL, reg);
95 primary_wait_vertical_sync(delay); 95 primary_wait_vertical_sync(delay);
96 96
97 reg = PEEK32(PANEL_DISPLAY_CTRL); 97 reg = peek32(PANEL_DISPLAY_CTRL);
98 reg |= (disp ? PANEL_DISPLAY_CTRL_DATA : 0); 98 reg |= (disp ? PANEL_DISPLAY_CTRL_DATA : 0);
99 POKE32(PANEL_DISPLAY_CTRL, reg); 99 poke32(PANEL_DISPLAY_CTRL, reg);
100 primary_wait_vertical_sync(delay); 100 primary_wait_vertical_sync(delay);
101 101
102 reg = PEEK32(PANEL_DISPLAY_CTRL); 102 reg = peek32(PANEL_DISPLAY_CTRL);
103 reg |= (disp ? PANEL_DISPLAY_CTRL_VBIASEN : 0); 103 reg |= (disp ? PANEL_DISPLAY_CTRL_VBIASEN : 0);
104 POKE32(PANEL_DISPLAY_CTRL, reg); 104 poke32(PANEL_DISPLAY_CTRL, reg);
105 primary_wait_vertical_sync(delay); 105 primary_wait_vertical_sync(delay);
106 106
107 reg = PEEK32(PANEL_DISPLAY_CTRL); 107 reg = peek32(PANEL_DISPLAY_CTRL);
108 reg |= (disp ? PANEL_DISPLAY_CTRL_FPEN : 0); 108 reg |= (disp ? PANEL_DISPLAY_CTRL_FPEN : 0);
109 POKE32(PANEL_DISPLAY_CTRL, reg); 109 poke32(PANEL_DISPLAY_CTRL, reg);
110 primary_wait_vertical_sync(delay); 110 primary_wait_vertical_sync(delay);
111} 111}
112 112
@@ -116,22 +116,22 @@ void ddk750_setLogicalDispOut(disp_output_t output)
116 116
117 if (output & PNL_2_USAGE) { 117 if (output & PNL_2_USAGE) {
118 /* set panel path controller select */ 118 /* set panel path controller select */
119 reg = PEEK32(PANEL_DISPLAY_CTRL); 119 reg = peek32(PANEL_DISPLAY_CTRL);
120 reg &= ~PANEL_DISPLAY_CTRL_SELECT_MASK; 120 reg &= ~PANEL_DISPLAY_CTRL_SELECT_MASK;
121 reg |= (((output & PNL_2_MASK) >> PNL_2_OFFSET) << 121 reg |= (((output & PNL_2_MASK) >> PNL_2_OFFSET) <<
122 PANEL_DISPLAY_CTRL_SELECT_SHIFT); 122 PANEL_DISPLAY_CTRL_SELECT_SHIFT);
123 POKE32(PANEL_DISPLAY_CTRL, reg); 123 poke32(PANEL_DISPLAY_CTRL, reg);
124 } 124 }
125 125
126 if (output & CRT_2_USAGE) { 126 if (output & CRT_2_USAGE) {
127 /* set crt path controller select */ 127 /* set crt path controller select */
128 reg = PEEK32(CRT_DISPLAY_CTRL); 128 reg = peek32(CRT_DISPLAY_CTRL);
129 reg &= ~CRT_DISPLAY_CTRL_SELECT_MASK; 129 reg &= ~CRT_DISPLAY_CTRL_SELECT_MASK;
130 reg |= (((output & CRT_2_MASK) >> CRT_2_OFFSET) << 130 reg |= (((output & CRT_2_MASK) >> CRT_2_OFFSET) <<
131 CRT_DISPLAY_CTRL_SELECT_SHIFT); 131 CRT_DISPLAY_CTRL_SELECT_SHIFT);
132 /*se blank off */ 132 /*se blank off */
133 reg &= ~CRT_DISPLAY_CTRL_BLANK; 133 reg &= ~CRT_DISPLAY_CTRL_BLANK;
134 POKE32(CRT_DISPLAY_CTRL, reg); 134 poke32(CRT_DISPLAY_CTRL, reg);
135 } 135 }
136 136
137 if (output & PRI_TP_USAGE) { 137 if (output & PRI_TP_USAGE) {
diff --git a/drivers/staging/sm750fb/ddk750_hwi2c.c b/drivers/staging/sm750fb/ddk750_hwi2c.c
index 05d4a73aa1d4..68716ef7cb06 100644
--- a/drivers/staging/sm750fb/ddk750_hwi2c.c
+++ b/drivers/staging/sm750fb/ddk750_hwi2c.c
@@ -15,10 +15,10 @@ unsigned char bus_speed_mode
15 unsigned int value; 15 unsigned int value;
16 16
17 /* Enable GPIO 30 & 31 as IIC clock & data */ 17 /* Enable GPIO 30 & 31 as IIC clock & data */
18 value = PEEK32(GPIO_MUX); 18 value = peek32(GPIO_MUX);
19 19
20 value |= (GPIO_MUX_30 | GPIO_MUX_31); 20 value |= (GPIO_MUX_30 | GPIO_MUX_31);
21 POKE32(GPIO_MUX, value); 21 poke32(GPIO_MUX, value);
22 22
23 /* 23 /*
24 * Enable Hardware I2C power. 24 * Enable Hardware I2C power.
@@ -27,11 +27,11 @@ unsigned char bus_speed_mode
27 sm750_enable_i2c(1); 27 sm750_enable_i2c(1);
28 28
29 /* Enable the I2C Controller and set the bus speed mode */ 29 /* Enable the I2C Controller and set the bus speed mode */
30 value = PEEK32(I2C_CTRL) & ~(I2C_CTRL_MODE | I2C_CTRL_EN); 30 value = peek32(I2C_CTRL) & ~(I2C_CTRL_MODE | I2C_CTRL_EN);
31 if (bus_speed_mode) 31 if (bus_speed_mode)
32 value |= I2C_CTRL_MODE; 32 value |= I2C_CTRL_MODE;
33 value |= I2C_CTRL_EN; 33 value |= I2C_CTRL_EN;
34 POKE32(I2C_CTRL, value); 34 poke32(I2C_CTRL, value);
35 35
36 return 0; 36 return 0;
37} 37}
@@ -41,17 +41,17 @@ void sm750_hw_i2c_close(void)
41 unsigned int value; 41 unsigned int value;
42 42
43 /* Disable I2C controller */ 43 /* Disable I2C controller */
44 value = PEEK32(I2C_CTRL) & ~I2C_CTRL_EN; 44 value = peek32(I2C_CTRL) & ~I2C_CTRL_EN;
45 POKE32(I2C_CTRL, value); 45 poke32(I2C_CTRL, value);
46 46
47 /* Disable I2C Power */ 47 /* Disable I2C Power */
48 sm750_enable_i2c(0); 48 sm750_enable_i2c(0);
49 49
50 /* Set GPIO 30 & 31 back as GPIO pins */ 50 /* Set GPIO 30 & 31 back as GPIO pins */
51 value = PEEK32(GPIO_MUX); 51 value = peek32(GPIO_MUX);
52 value &= ~GPIO_MUX_30; 52 value &= ~GPIO_MUX_30;
53 value &= ~GPIO_MUX_31; 53 value &= ~GPIO_MUX_31;
54 POKE32(GPIO_MUX, value); 54 poke32(GPIO_MUX, value);
55} 55}
56 56
57static long hw_i2c_wait_tx_done(void) 57static long hw_i2c_wait_tx_done(void)
@@ -60,7 +60,7 @@ static long hw_i2c_wait_tx_done(void)
60 60
61 /* Wait until the transfer is completed. */ 61 /* Wait until the transfer is completed. */
62 timeout = HWI2C_WAIT_TIMEOUT; 62 timeout = HWI2C_WAIT_TIMEOUT;
63 while (!(PEEK32(I2C_STATUS) & I2C_STATUS_TX) && (timeout != 0)) 63 while (!(peek32(I2C_STATUS) & I2C_STATUS_TX) && (timeout != 0))
64 timeout--; 64 timeout--;
65 65
66 if (timeout == 0) 66 if (timeout == 0)
@@ -91,7 +91,7 @@ static unsigned int hw_i2c_write_data(
91 unsigned int total_bytes = 0; 91 unsigned int total_bytes = 0;
92 92
93 /* Set the Device Address */ 93 /* Set the Device Address */
94 POKE32(I2C_SLAVE_ADDRESS, addr & ~0x01); 94 poke32(I2C_SLAVE_ADDRESS, addr & ~0x01);
95 95
96 /* 96 /*
97 * Write data. 97 * Write data.
@@ -103,21 +103,21 @@ static unsigned int hw_i2c_write_data(
103 * Reset I2C by writing 0 to I2C_RESET register to 103 * Reset I2C by writing 0 to I2C_RESET register to
104 * clear the previous status. 104 * clear the previous status.
105 */ 105 */
106 POKE32(I2C_RESET, 0); 106 poke32(I2C_RESET, 0);
107 107
108 /* Set the number of bytes to be written */ 108 /* Set the number of bytes to be written */
109 if (length < MAX_HWI2C_FIFO) 109 if (length < MAX_HWI2C_FIFO)
110 count = length - 1; 110 count = length - 1;
111 else 111 else
112 count = MAX_HWI2C_FIFO - 1; 112 count = MAX_HWI2C_FIFO - 1;
113 POKE32(I2C_BYTE_COUNT, count); 113 poke32(I2C_BYTE_COUNT, count);
114 114
115 /* Move the data to the I2C data register */ 115 /* Move the data to the I2C data register */
116 for (i = 0; i <= count; i++) 116 for (i = 0; i <= count; i++)
117 POKE32(I2C_DATA0 + i, *buf++); 117 poke32(I2C_DATA0 + i, *buf++);
118 118
119 /* Start the I2C */ 119 /* Start the I2C */
120 POKE32(I2C_CTRL, PEEK32(I2C_CTRL) | I2C_CTRL_CTRL); 120 poke32(I2C_CTRL, peek32(I2C_CTRL) | I2C_CTRL_CTRL);
121 121
122 /* Wait until the transfer is completed. */ 122 /* Wait until the transfer is completed. */
123 if (hw_i2c_wait_tx_done() != 0) 123 if (hw_i2c_wait_tx_done() != 0)
@@ -158,7 +158,7 @@ static unsigned int hw_i2c_read_data(
158 unsigned int total_bytes = 0; 158 unsigned int total_bytes = 0;
159 159
160 /* Set the Device Address */ 160 /* Set the Device Address */
161 POKE32(I2C_SLAVE_ADDRESS, addr | 0x01); 161 poke32(I2C_SLAVE_ADDRESS, addr | 0x01);
162 162
163 /* 163 /*
164 * Read data and save them to the buffer. 164 * Read data and save them to the buffer.
@@ -170,17 +170,17 @@ static unsigned int hw_i2c_read_data(
170 * Reset I2C by writing 0 to I2C_RESET register to 170 * Reset I2C by writing 0 to I2C_RESET register to
171 * clear all the status. 171 * clear all the status.
172 */ 172 */
173 POKE32(I2C_RESET, 0); 173 poke32(I2C_RESET, 0);
174 174
175 /* Set the number of bytes to be read */ 175 /* Set the number of bytes to be read */
176 if (length <= MAX_HWI2C_FIFO) 176 if (length <= MAX_HWI2C_FIFO)
177 count = length - 1; 177 count = length - 1;
178 else 178 else
179 count = MAX_HWI2C_FIFO - 1; 179 count = MAX_HWI2C_FIFO - 1;
180 POKE32(I2C_BYTE_COUNT, count); 180 poke32(I2C_BYTE_COUNT, count);
181 181
182 /* Start the I2C */ 182 /* Start the I2C */
183 POKE32(I2C_CTRL, PEEK32(I2C_CTRL) | I2C_CTRL_CTRL); 183 poke32(I2C_CTRL, peek32(I2C_CTRL) | I2C_CTRL_CTRL);
184 184
185 /* Wait until transaction done. */ 185 /* Wait until transaction done. */
186 if (hw_i2c_wait_tx_done() != 0) 186 if (hw_i2c_wait_tx_done() != 0)
@@ -188,7 +188,7 @@ static unsigned int hw_i2c_read_data(
188 188
189 /* Save the data to the given buffer */ 189 /* Save the data to the given buffer */
190 for (i = 0; i <= count; i++) 190 for (i = 0; i <= count; i++)
191 *buf++ = PEEK32(I2C_DATA0 + i); 191 *buf++ = peek32(I2C_DATA0 + i);
192 192
193 /* Subtract length by 16 */ 193 /* Subtract length by 16 */
194 length -= (count + 1); 194 length -= (count + 1);
diff --git a/drivers/staging/sm750fb/ddk750_mode.c b/drivers/staging/sm750fb/ddk750_mode.c
index 4a4b1de97a87..1df7d57dea6d 100644
--- a/drivers/staging/sm750fb/ddk750_mode.c
+++ b/drivers/staging/sm750fb/ddk750_mode.c
@@ -25,9 +25,9 @@ static unsigned long displayControlAdjust_SM750LE(mode_parameter_t *pModeParam,
25 * Note that normal SM750/SM718 only use those two register for 25 * Note that normal SM750/SM718 only use those two register for
26 * auto-centering mode. 26 * auto-centering mode.
27 */ 27 */
28 POKE32(CRT_AUTO_CENTERING_TL, 0); 28 poke32(CRT_AUTO_CENTERING_TL, 0);
29 29
30 POKE32(CRT_AUTO_CENTERING_BR, 30 poke32(CRT_AUTO_CENTERING_BR,
31 (((y - 1) << CRT_AUTO_CENTERING_BR_BOTTOM_SHIFT) & 31 (((y - 1) << CRT_AUTO_CENTERING_BR_BOTTOM_SHIFT) &
32 CRT_AUTO_CENTERING_BR_BOTTOM_MASK) | 32 CRT_AUTO_CENTERING_BR_BOTTOM_MASK) |
33 ((x - 1) & CRT_AUTO_CENTERING_BR_RIGHT_MASK)); 33 ((x - 1) & CRT_AUTO_CENTERING_BR_RIGHT_MASK));
@@ -66,7 +66,7 @@ static unsigned long displayControlAdjust_SM750LE(mode_parameter_t *pModeParam,
66 /* Set bit 14 of display controller */ 66 /* Set bit 14 of display controller */
67 dispControl |= DISPLAY_CTRL_CLOCK_PHASE; 67 dispControl |= DISPLAY_CTRL_CLOCK_PHASE;
68 68
69 POKE32(CRT_DISPLAY_CTRL, dispControl); 69 poke32(CRT_DISPLAY_CTRL, dispControl);
70 70
71 return dispControl; 71 return dispControl;
72} 72}
@@ -83,29 +83,29 @@ static int programModeRegisters(mode_parameter_t *pModeParam,
83 83
84 if (pll->clockType == SECONDARY_PLL) { 84 if (pll->clockType == SECONDARY_PLL) {
85 /* programe secondary pixel clock */ 85 /* programe secondary pixel clock */
86 POKE32(CRT_PLL_CTRL, sm750_format_pll_reg(pll)); 86 poke32(CRT_PLL_CTRL, sm750_format_pll_reg(pll));
87 POKE32(CRT_HORIZONTAL_TOTAL, 87 poke32(CRT_HORIZONTAL_TOTAL,
88 (((pModeParam->horizontal_total - 1) << 88 (((pModeParam->horizontal_total - 1) <<
89 CRT_HORIZONTAL_TOTAL_TOTAL_SHIFT) & 89 CRT_HORIZONTAL_TOTAL_TOTAL_SHIFT) &
90 CRT_HORIZONTAL_TOTAL_TOTAL_MASK) | 90 CRT_HORIZONTAL_TOTAL_TOTAL_MASK) |
91 ((pModeParam->horizontal_display_end - 1) & 91 ((pModeParam->horizontal_display_end - 1) &
92 CRT_HORIZONTAL_TOTAL_DISPLAY_END_MASK)); 92 CRT_HORIZONTAL_TOTAL_DISPLAY_END_MASK));
93 93
94 POKE32(CRT_HORIZONTAL_SYNC, 94 poke32(CRT_HORIZONTAL_SYNC,
95 ((pModeParam->horizontal_sync_width << 95 ((pModeParam->horizontal_sync_width <<
96 CRT_HORIZONTAL_SYNC_WIDTH_SHIFT) & 96 CRT_HORIZONTAL_SYNC_WIDTH_SHIFT) &
97 CRT_HORIZONTAL_SYNC_WIDTH_MASK) | 97 CRT_HORIZONTAL_SYNC_WIDTH_MASK) |
98 ((pModeParam->horizontal_sync_start - 1) & 98 ((pModeParam->horizontal_sync_start - 1) &
99 CRT_HORIZONTAL_SYNC_START_MASK)); 99 CRT_HORIZONTAL_SYNC_START_MASK));
100 100
101 POKE32(CRT_VERTICAL_TOTAL, 101 poke32(CRT_VERTICAL_TOTAL,
102 (((pModeParam->vertical_total - 1) << 102 (((pModeParam->vertical_total - 1) <<
103 CRT_VERTICAL_TOTAL_TOTAL_SHIFT) & 103 CRT_VERTICAL_TOTAL_TOTAL_SHIFT) &
104 CRT_VERTICAL_TOTAL_TOTAL_MASK) | 104 CRT_VERTICAL_TOTAL_TOTAL_MASK) |
105 ((pModeParam->vertical_display_end - 1) & 105 ((pModeParam->vertical_display_end - 1) &
106 CRT_VERTICAL_TOTAL_DISPLAY_END_MASK)); 106 CRT_VERTICAL_TOTAL_DISPLAY_END_MASK));
107 107
108 POKE32(CRT_VERTICAL_SYNC, 108 poke32(CRT_VERTICAL_SYNC,
109 ((pModeParam->vertical_sync_height << 109 ((pModeParam->vertical_sync_height <<
110 CRT_VERTICAL_SYNC_HEIGHT_SHIFT) & 110 CRT_VERTICAL_SYNC_HEIGHT_SHIFT) &
111 CRT_VERTICAL_SYNC_HEIGHT_MASK) | 111 CRT_VERTICAL_SYNC_HEIGHT_MASK) |
@@ -122,41 +122,41 @@ static int programModeRegisters(mode_parameter_t *pModeParam,
122 if (sm750_get_chip_type() == SM750LE) { 122 if (sm750_get_chip_type() == SM750LE) {
123 displayControlAdjust_SM750LE(pModeParam, tmp); 123 displayControlAdjust_SM750LE(pModeParam, tmp);
124 } else { 124 } else {
125 reg = PEEK32(CRT_DISPLAY_CTRL) & 125 reg = peek32(CRT_DISPLAY_CTRL) &
126 ~(DISPLAY_CTRL_VSYNC_PHASE | 126 ~(DISPLAY_CTRL_VSYNC_PHASE |
127 DISPLAY_CTRL_HSYNC_PHASE | 127 DISPLAY_CTRL_HSYNC_PHASE |
128 DISPLAY_CTRL_TIMING | DISPLAY_CTRL_PLANE); 128 DISPLAY_CTRL_TIMING | DISPLAY_CTRL_PLANE);
129 129
130 POKE32(CRT_DISPLAY_CTRL, tmp | reg); 130 poke32(CRT_DISPLAY_CTRL, tmp | reg);
131 } 131 }
132 132
133 } else if (pll->clockType == PRIMARY_PLL) { 133 } else if (pll->clockType == PRIMARY_PLL) {
134 unsigned int reserved; 134 unsigned int reserved;
135 135
136 POKE32(PANEL_PLL_CTRL, sm750_format_pll_reg(pll)); 136 poke32(PANEL_PLL_CTRL, sm750_format_pll_reg(pll));
137 137
138 reg = ((pModeParam->horizontal_total - 1) << 138 reg = ((pModeParam->horizontal_total - 1) <<
139 PANEL_HORIZONTAL_TOTAL_TOTAL_SHIFT) & 139 PANEL_HORIZONTAL_TOTAL_TOTAL_SHIFT) &
140 PANEL_HORIZONTAL_TOTAL_TOTAL_MASK; 140 PANEL_HORIZONTAL_TOTAL_TOTAL_MASK;
141 reg |= ((pModeParam->horizontal_display_end - 1) & 141 reg |= ((pModeParam->horizontal_display_end - 1) &
142 PANEL_HORIZONTAL_TOTAL_DISPLAY_END_MASK); 142 PANEL_HORIZONTAL_TOTAL_DISPLAY_END_MASK);
143 POKE32(PANEL_HORIZONTAL_TOTAL, reg); 143 poke32(PANEL_HORIZONTAL_TOTAL, reg);
144 144
145 POKE32(PANEL_HORIZONTAL_SYNC, 145 poke32(PANEL_HORIZONTAL_SYNC,
146 ((pModeParam->horizontal_sync_width << 146 ((pModeParam->horizontal_sync_width <<
147 PANEL_HORIZONTAL_SYNC_WIDTH_SHIFT) & 147 PANEL_HORIZONTAL_SYNC_WIDTH_SHIFT) &
148 PANEL_HORIZONTAL_SYNC_WIDTH_MASK) | 148 PANEL_HORIZONTAL_SYNC_WIDTH_MASK) |
149 ((pModeParam->horizontal_sync_start - 1) & 149 ((pModeParam->horizontal_sync_start - 1) &
150 PANEL_HORIZONTAL_SYNC_START_MASK)); 150 PANEL_HORIZONTAL_SYNC_START_MASK));
151 151
152 POKE32(PANEL_VERTICAL_TOTAL, 152 poke32(PANEL_VERTICAL_TOTAL,
153 (((pModeParam->vertical_total - 1) << 153 (((pModeParam->vertical_total - 1) <<
154 PANEL_VERTICAL_TOTAL_TOTAL_SHIFT) & 154 PANEL_VERTICAL_TOTAL_TOTAL_SHIFT) &
155 PANEL_VERTICAL_TOTAL_TOTAL_MASK) | 155 PANEL_VERTICAL_TOTAL_TOTAL_MASK) |
156 ((pModeParam->vertical_display_end - 1) & 156 ((pModeParam->vertical_display_end - 1) &
157 PANEL_VERTICAL_TOTAL_DISPLAY_END_MASK)); 157 PANEL_VERTICAL_TOTAL_DISPLAY_END_MASK));
158 158
159 POKE32(PANEL_VERTICAL_SYNC, 159 poke32(PANEL_VERTICAL_SYNC,
160 ((pModeParam->vertical_sync_height << 160 ((pModeParam->vertical_sync_height <<
161 PANEL_VERTICAL_SYNC_HEIGHT_SHIFT) & 161 PANEL_VERTICAL_SYNC_HEIGHT_SHIFT) &
162 PANEL_VERTICAL_SYNC_HEIGHT_MASK) | 162 PANEL_VERTICAL_SYNC_HEIGHT_MASK) |
@@ -174,7 +174,7 @@ static int programModeRegisters(mode_parameter_t *pModeParam,
174 reserved = PANEL_DISPLAY_CTRL_RESERVED_MASK | 174 reserved = PANEL_DISPLAY_CTRL_RESERVED_MASK |
175 PANEL_DISPLAY_CTRL_VSYNC; 175 PANEL_DISPLAY_CTRL_VSYNC;
176 176
177 reg = (PEEK32(PANEL_DISPLAY_CTRL) & ~reserved) & 177 reg = (peek32(PANEL_DISPLAY_CTRL) & ~reserved) &
178 ~(DISPLAY_CTRL_CLOCK_PHASE | DISPLAY_CTRL_VSYNC_PHASE | 178 ~(DISPLAY_CTRL_CLOCK_PHASE | DISPLAY_CTRL_VSYNC_PHASE |
179 DISPLAY_CTRL_HSYNC_PHASE | DISPLAY_CTRL_TIMING | 179 DISPLAY_CTRL_HSYNC_PHASE | DISPLAY_CTRL_TIMING |
180 DISPLAY_CTRL_PLANE); 180 DISPLAY_CTRL_PLANE);
@@ -187,14 +187,14 @@ static int programModeRegisters(mode_parameter_t *pModeParam,
187 * Note: This problem happens by design. The hardware will wait 187 * Note: This problem happens by design. The hardware will wait
188 * for the next vertical sync to turn on/off the plane. 188 * for the next vertical sync to turn on/off the plane.
189 */ 189 */
190 POKE32(PANEL_DISPLAY_CTRL, tmp | reg); 190 poke32(PANEL_DISPLAY_CTRL, tmp | reg);
191 191
192 while ((PEEK32(PANEL_DISPLAY_CTRL) & ~reserved) != 192 while ((peek32(PANEL_DISPLAY_CTRL) & ~reserved) !=
193 (tmp | reg)) { 193 (tmp | reg)) {
194 cnt++; 194 cnt++;
195 if (cnt > 1000) 195 if (cnt > 1000)
196 break; 196 break;
197 POKE32(PANEL_DISPLAY_CTRL, tmp | reg); 197 poke32(PANEL_DISPLAY_CTRL, tmp | reg);
198 } 198 }
199 } else { 199 } else {
200 ret = -1; 200 ret = -1;
diff --git a/drivers/staging/sm750fb/ddk750_power.c b/drivers/staging/sm750fb/ddk750_power.c
index 6167e30e8e01..02ff6204ee1e 100644
--- a/drivers/staging/sm750fb/ddk750_power.c
+++ b/drivers/staging/sm750fb/ddk750_power.c
@@ -7,13 +7,13 @@ void ddk750_set_dpms(DPMS_t state)
7 unsigned int value; 7 unsigned int value;
8 8
9 if (sm750_get_chip_type() == SM750LE) { 9 if (sm750_get_chip_type() == SM750LE) {
10 value = PEEK32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_DPMS_MASK; 10 value = peek32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_DPMS_MASK;
11 value |= (state << CRT_DISPLAY_CTRL_DPMS_SHIFT); 11 value |= (state << CRT_DISPLAY_CTRL_DPMS_SHIFT);
12 POKE32(CRT_DISPLAY_CTRL, value); 12 poke32(CRT_DISPLAY_CTRL, value);
13 } else { 13 } else {
14 value = PEEK32(SYSTEM_CTRL); 14 value = peek32(SYSTEM_CTRL);
15 value = (value & ~SYSTEM_CTRL_DPMS_MASK) | state; 15 value = (value & ~SYSTEM_CTRL_DPMS_MASK) | state;
16 POKE32(SYSTEM_CTRL, value); 16 poke32(SYSTEM_CTRL, value);
17 } 17 }
18} 18}
19 19
@@ -21,7 +21,7 @@ static unsigned int get_power_mode(void)
21{ 21{
22 if (sm750_get_chip_type() == SM750LE) 22 if (sm750_get_chip_type() == SM750LE)
23 return 0; 23 return 0;
24 return PEEK32(POWER_MODE_CTRL) & POWER_MODE_CTRL_MODE_MASK; 24 return peek32(POWER_MODE_CTRL) & POWER_MODE_CTRL_MODE_MASK;
25} 25}
26 26
27 27
@@ -33,7 +33,7 @@ void sm750_set_power_mode(unsigned int mode)
33{ 33{
34 unsigned int ctrl = 0; 34 unsigned int ctrl = 0;
35 35
36 ctrl = PEEK32(POWER_MODE_CTRL) & ~POWER_MODE_CTRL_MODE_MASK; 36 ctrl = peek32(POWER_MODE_CTRL) & ~POWER_MODE_CTRL_MODE_MASK;
37 37
38 if (sm750_get_chip_type() == SM750LE) 38 if (sm750_get_chip_type() == SM750LE)
39 return; 39 return;
@@ -69,15 +69,15 @@ void sm750_set_power_mode(unsigned int mode)
69 } 69 }
70 70
71 /* Program new power mode. */ 71 /* Program new power mode. */
72 POKE32(POWER_MODE_CTRL, ctrl); 72 poke32(POWER_MODE_CTRL, ctrl);
73} 73}
74 74
75void sm750_set_current_gate(unsigned int gate) 75void sm750_set_current_gate(unsigned int gate)
76{ 76{
77 if (get_power_mode() == POWER_MODE_CTRL_MODE_MODE1) 77 if (get_power_mode() == POWER_MODE_CTRL_MODE_MODE1)
78 POKE32(MODE1_GATE, gate); 78 poke32(MODE1_GATE, gate);
79 else 79 else
80 POKE32(MODE0_GATE, gate); 80 poke32(MODE0_GATE, gate);
81} 81}
82 82
83 83
@@ -89,7 +89,7 @@ void sm750_enable_2d_engine(unsigned int enable)
89{ 89{
90 u32 gate; 90 u32 gate;
91 91
92 gate = PEEK32(CURRENT_GATE); 92 gate = peek32(CURRENT_GATE);
93 if (enable) 93 if (enable)
94 gate |= (CURRENT_GATE_DE | CURRENT_GATE_CSC); 94 gate |= (CURRENT_GATE_DE | CURRENT_GATE_CSC);
95 else 95 else
@@ -103,7 +103,7 @@ void sm750_enable_dma(unsigned int enable)
103 u32 gate; 103 u32 gate;
104 104
105 /* Enable DMA Gate */ 105 /* Enable DMA Gate */
106 gate = PEEK32(CURRENT_GATE); 106 gate = peek32(CURRENT_GATE);
107 if (enable) 107 if (enable)
108 gate |= CURRENT_GATE_DMA; 108 gate |= CURRENT_GATE_DMA;
109 else 109 else
@@ -120,7 +120,7 @@ void sm750_enable_gpio(unsigned int enable)
120 u32 gate; 120 u32 gate;
121 121
122 /* Enable GPIO Gate */ 122 /* Enable GPIO Gate */
123 gate = PEEK32(CURRENT_GATE); 123 gate = peek32(CURRENT_GATE);
124 if (enable) 124 if (enable)
125 gate |= CURRENT_GATE_GPIO; 125 gate |= CURRENT_GATE_GPIO;
126 else 126 else
@@ -137,7 +137,7 @@ void sm750_enable_i2c(unsigned int enable)
137 u32 gate; 137 u32 gate;
138 138
139 /* Enable I2C Gate */ 139 /* Enable I2C Gate */
140 gate = PEEK32(CURRENT_GATE); 140 gate = peek32(CURRENT_GATE);
141 if (enable) 141 if (enable)
142 gate |= CURRENT_GATE_I2C; 142 gate |= CURRENT_GATE_I2C;
143 else 143 else
diff --git a/drivers/staging/sm750fb/ddk750_power.h b/drivers/staging/sm750fb/ddk750_power.h
index eb088b0d805f..4274d74d47c1 100644
--- a/drivers/staging/sm750fb/ddk750_power.h
+++ b/drivers/staging/sm750fb/ddk750_power.h
@@ -10,8 +10,8 @@ typedef enum _DPMS_t {
10DPMS_t; 10DPMS_t;
11 11
12#define setDAC(off) { \ 12#define setDAC(off) { \
13 POKE32(MISC_CTRL, \ 13 poke32(MISC_CTRL, \
14 (PEEK32(MISC_CTRL) & ~MISC_CTRL_DAC_POWER_OFF) | (off)); \ 14 (peek32(MISC_CTRL) & ~MISC_CTRL_DAC_POWER_OFF) | (off)); \
15} 15}
16 16
17void ddk750_set_dpms(DPMS_t); 17void ddk750_set_dpms(DPMS_t);
diff --git a/drivers/staging/sm750fb/ddk750_swi2c.c b/drivers/staging/sm750fb/ddk750_swi2c.c
index b8a4e44359af..a4ac07cd50cb 100644
--- a/drivers/staging/sm750fb/ddk750_swi2c.c
+++ b/drivers/staging/sm750fb/ddk750_swi2c.c
@@ -119,23 +119,23 @@ static void sw_i2c_scl(unsigned char value)
119 unsigned long gpio_data; 119 unsigned long gpio_data;
120 unsigned long gpio_dir; 120 unsigned long gpio_dir;
121 121
122 gpio_dir = PEEK32(sw_i2c_clk_gpio_data_dir_reg); 122 gpio_dir = peek32(sw_i2c_clk_gpio_data_dir_reg);
123 if (value) { /* High */ 123 if (value) { /* High */
124 /* 124 /*
125 * Set direction as input. This will automatically 125 * Set direction as input. This will automatically
126 * pull the signal up. 126 * pull the signal up.
127 */ 127 */
128 gpio_dir &= ~(1 << sw_i2c_clk_gpio); 128 gpio_dir &= ~(1 << sw_i2c_clk_gpio);
129 POKE32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir); 129 poke32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir);
130 } else { /* Low */ 130 } else { /* Low */
131 /* Set the signal down */ 131 /* Set the signal down */
132 gpio_data = PEEK32(sw_i2c_clk_gpio_data_reg); 132 gpio_data = peek32(sw_i2c_clk_gpio_data_reg);
133 gpio_data &= ~(1 << sw_i2c_clk_gpio); 133 gpio_data &= ~(1 << sw_i2c_clk_gpio);
134 POKE32(sw_i2c_clk_gpio_data_reg, gpio_data); 134 poke32(sw_i2c_clk_gpio_data_reg, gpio_data);
135 135
136 /* Set direction as output */ 136 /* Set direction as output */
137 gpio_dir |= (1 << sw_i2c_clk_gpio); 137 gpio_dir |= (1 << sw_i2c_clk_gpio);
138 POKE32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir); 138 poke32(sw_i2c_clk_gpio_data_dir_reg, gpio_dir);
139 } 139 }
140} 140}
141 141
@@ -156,23 +156,23 @@ static void sw_i2c_sda(unsigned char value)
156 unsigned long gpio_data; 156 unsigned long gpio_data;
157 unsigned long gpio_dir; 157 unsigned long gpio_dir;
158 158
159 gpio_dir = PEEK32(sw_i2c_data_gpio_data_dir_reg); 159 gpio_dir = peek32(sw_i2c_data_gpio_data_dir_reg);
160 if (value) { /* High */ 160 if (value) { /* High */
161 /* 161 /*
162 * Set direction as input. This will automatically 162 * Set direction as input. This will automatically
163 * pull the signal up. 163 * pull the signal up.
164 */ 164 */
165 gpio_dir &= ~(1 << sw_i2c_data_gpio); 165 gpio_dir &= ~(1 << sw_i2c_data_gpio);
166 POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir); 166 poke32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
167 } else { /* Low */ 167 } else { /* Low */
168 /* Set the signal down */ 168 /* Set the signal down */
169 gpio_data = PEEK32(sw_i2c_data_gpio_data_reg); 169 gpio_data = peek32(sw_i2c_data_gpio_data_reg);
170 gpio_data &= ~(1 << sw_i2c_data_gpio); 170 gpio_data &= ~(1 << sw_i2c_data_gpio);
171 POKE32(sw_i2c_data_gpio_data_reg, gpio_data); 171 poke32(sw_i2c_data_gpio_data_reg, gpio_data);
172 172
173 /* Set direction as output */ 173 /* Set direction as output */
174 gpio_dir |= (1 << sw_i2c_data_gpio); 174 gpio_dir |= (1 << sw_i2c_data_gpio);
175 POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir); 175 poke32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
176 } 176 }
177} 177}
178 178
@@ -189,14 +189,14 @@ static unsigned char sw_i2c_read_sda(void)
189 unsigned long dir_mask = 1 << sw_i2c_data_gpio; 189 unsigned long dir_mask = 1 << sw_i2c_data_gpio;
190 190
191 /* Make sure that the direction is input (High) */ 191 /* Make sure that the direction is input (High) */
192 gpio_dir = PEEK32(sw_i2c_data_gpio_data_dir_reg); 192 gpio_dir = peek32(sw_i2c_data_gpio_data_dir_reg);
193 if ((gpio_dir & dir_mask) != ~dir_mask) { 193 if ((gpio_dir & dir_mask) != ~dir_mask) {
194 gpio_dir &= ~(1 << sw_i2c_data_gpio); 194 gpio_dir &= ~(1 << sw_i2c_data_gpio);
195 POKE32(sw_i2c_data_gpio_data_dir_reg, gpio_dir); 195 poke32(sw_i2c_data_gpio_data_dir_reg, gpio_dir);
196 } 196 }
197 197
198 /* Now read the SDA line */ 198 /* Now read the SDA line */
199 gpio_data = PEEK32(sw_i2c_data_gpio_data_reg); 199 gpio_data = peek32(sw_i2c_data_gpio_data_reg);
200 if (gpio_data & (1 << sw_i2c_data_gpio)) 200 if (gpio_data & (1 << sw_i2c_data_gpio))
201 return 1; 201 return 1;
202 else 202 else
@@ -422,10 +422,10 @@ long sm750_sw_i2c_init(
422 sw_i2c_data_gpio = data_gpio; 422 sw_i2c_data_gpio = data_gpio;
423 423
424 /* Enable the GPIO pins for the i2c Clock and Data (GPIO MUX) */ 424 /* Enable the GPIO pins for the i2c Clock and Data (GPIO MUX) */
425 POKE32(sw_i2c_clk_gpio_mux_reg, 425 poke32(sw_i2c_clk_gpio_mux_reg,
426 PEEK32(sw_i2c_clk_gpio_mux_reg) & ~(1 << sw_i2c_clk_gpio)); 426 peek32(sw_i2c_clk_gpio_mux_reg) & ~(1 << sw_i2c_clk_gpio));
427 POKE32(sw_i2c_data_gpio_mux_reg, 427 poke32(sw_i2c_data_gpio_mux_reg,
428 PEEK32(sw_i2c_data_gpio_mux_reg) & ~(1 << sw_i2c_data_gpio)); 428 peek32(sw_i2c_data_gpio_mux_reg) & ~(1 << sw_i2c_data_gpio));
429 429
430 /* Enable GPIO power */ 430 /* Enable GPIO power */
431 sm750_enable_gpio(1); 431 sm750_enable_gpio(1);
diff --git a/drivers/staging/sm750fb/sm750.c b/drivers/staging/sm750fb/sm750.c
index e9632f162f99..e49f8845f923 100644
--- a/drivers/staging/sm750fb/sm750.c
+++ b/drivers/staging/sm750fb/sm750.c
@@ -100,7 +100,6 @@ static const struct fb_videomode lynx750_ext[] = {
100 FB_VMODE_NONINTERLACED}, 100 FB_VMODE_NONINTERLACED},
101}; 101};
102 102
103
104/* no hardware cursor supported under version 2.6.10, kernel bug */ 103/* no hardware cursor supported under version 2.6.10, kernel bug */
105static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor) 104static int lynxfb_ops_cursor(struct fb_info *info, struct fb_cursor *fbcursor)
106{ 105{
@@ -974,10 +973,12 @@ static void sm750fb_setup(struct sm750_dev *sm750_dev, char *src)
974 else { 973 else {
975 if (!g_fbmode[0]) { 974 if (!g_fbmode[0]) {
976 g_fbmode[0] = opt; 975 g_fbmode[0] = opt;
977 dev_info(&sm750_dev->pdev->dev, "find fbmode0 : %s\n", g_fbmode[0]); 976 dev_info(&sm750_dev->pdev->dev,
977 "find fbmode0 : %s\n", g_fbmode[0]);
978 } else if (!g_fbmode[1]) { 978 } else if (!g_fbmode[1]) {
979 g_fbmode[1] = opt; 979 g_fbmode[1] = opt;
980 dev_info(&sm750_dev->pdev->dev, "find fbmode1 : %s\n", g_fbmode[1]); 980 dev_info(&sm750_dev->pdev->dev,
981 "find fbmode1 : %s\n", g_fbmode[1]);
981 } else { 982 } else {
982 dev_warn(&sm750_dev->pdev->dev, "How many view you wann set?\n"); 983 dev_warn(&sm750_dev->pdev->dev, "How many view you wann set?\n");
983 } 984 }
@@ -1228,7 +1229,7 @@ static void __exit lynxfb_exit(void)
1228} 1229}
1229module_exit(lynxfb_exit); 1230module_exit(lynxfb_exit);
1230 1231
1231module_param(g_option, charp, S_IRUGO); 1232module_param(g_option, charp, 0444);
1232 1233
1233MODULE_PARM_DESC(g_option, 1234MODULE_PARM_DESC(g_option,
1234 "\n\t\tCommon options:\n" 1235 "\n\t\tCommon options:\n"
diff --git a/drivers/staging/sm750fb/sm750_cursor.c b/drivers/staging/sm750fb/sm750_cursor.c
index 2a13353fc492..b1651b0d2034 100644
--- a/drivers/staging/sm750fb/sm750_cursor.c
+++ b/drivers/staging/sm750fb/sm750_cursor.c
@@ -20,7 +20,7 @@
20 20
21 21
22 22
23#define POKE32(addr, data) \ 23#define poke32(addr, data) \
24writel((data), cursor->mmio + (addr)) 24writel((data), cursor->mmio + (addr))
25 25
26/* cursor control for voyager and 718/750*/ 26/* cursor control for voyager and 718/750*/
@@ -52,11 +52,11 @@ void sm750_hw_cursor_enable(struct lynx_cursor *cursor)
52 u32 reg; 52 u32 reg;
53 53
54 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE; 54 reg = (cursor->offset & HWC_ADDRESS_ADDRESS_MASK) | HWC_ADDRESS_ENABLE;
55 POKE32(HWC_ADDRESS, reg); 55 poke32(HWC_ADDRESS, reg);
56} 56}
57void sm750_hw_cursor_disable(struct lynx_cursor *cursor) 57void sm750_hw_cursor_disable(struct lynx_cursor *cursor)
58{ 58{
59 POKE32(HWC_ADDRESS, 0); 59 poke32(HWC_ADDRESS, 0);
60} 60}
61 61
62void sm750_hw_cursor_setSize(struct lynx_cursor *cursor, 62void sm750_hw_cursor_setSize(struct lynx_cursor *cursor,
@@ -72,7 +72,7 @@ void sm750_hw_cursor_setPos(struct lynx_cursor *cursor,
72 72
73 reg = (((y << HWC_LOCATION_Y_SHIFT) & HWC_LOCATION_Y_MASK) | 73 reg = (((y << HWC_LOCATION_Y_SHIFT) & HWC_LOCATION_Y_MASK) |
74 (x & HWC_LOCATION_X_MASK)); 74 (x & HWC_LOCATION_X_MASK));
75 POKE32(HWC_LOCATION, reg); 75 poke32(HWC_LOCATION, reg);
76} 76}
77void sm750_hw_cursor_setColor(struct lynx_cursor *cursor, 77void sm750_hw_cursor_setColor(struct lynx_cursor *cursor,
78 u32 fg, u32 bg) 78 u32 fg, u32 bg)
@@ -80,8 +80,8 @@ void sm750_hw_cursor_setColor(struct lynx_cursor *cursor,
80 u32 reg = (fg << HWC_COLOR_12_2_RGB565_SHIFT) & 80 u32 reg = (fg << HWC_COLOR_12_2_RGB565_SHIFT) &
81 HWC_COLOR_12_2_RGB565_MASK; 81 HWC_COLOR_12_2_RGB565_MASK;
82 82
83 POKE32(HWC_COLOR_12, reg | (bg & HWC_COLOR_12_1_RGB565_MASK)); 83 poke32(HWC_COLOR_12, reg | (bg & HWC_COLOR_12_1_RGB565_MASK));
84 POKE32(HWC_COLOR_3, 0xffe0); 84 poke32(HWC_COLOR_3, 0xffe0);
85} 85}
86 86
87void sm750_hw_cursor_setData(struct lynx_cursor *cursor, 87void sm750_hw_cursor_setData(struct lynx_cursor *cursor,
diff --git a/drivers/staging/sm750fb/sm750_hw.c b/drivers/staging/sm750fb/sm750_hw.c
index b6af3b53076b..fab3fc9c8330 100644
--- a/drivers/staging/sm750fb/sm750_hw.c
+++ b/drivers/staging/sm750fb/sm750_hw.c
@@ -108,30 +108,30 @@ int hw_sm750_inithw(struct sm750_dev *sm750_dev, struct pci_dev *pdev)
108 ddk750_init_hw((struct initchip_param *)&sm750_dev->initParm); 108 ddk750_init_hw((struct initchip_param *)&sm750_dev->initParm);
109 /* for sm718, open pci burst */ 109 /* for sm718, open pci burst */
110 if (sm750_dev->devid == 0x718) { 110 if (sm750_dev->devid == 0x718) {
111 POKE32(SYSTEM_CTRL, 111 poke32(SYSTEM_CTRL,
112 PEEK32(SYSTEM_CTRL) | SYSTEM_CTRL_PCI_BURST); 112 peek32(SYSTEM_CTRL) | SYSTEM_CTRL_PCI_BURST);
113 } 113 }
114 114
115 if (sm750_get_chip_type() != SM750LE) { 115 if (sm750_get_chip_type() != SM750LE) {
116 unsigned int val; 116 unsigned int val;
117 /* does user need CRT? */ 117 /* does user need CRT? */
118 if (sm750_dev->nocrt) { 118 if (sm750_dev->nocrt) {
119 POKE32(MISC_CTRL, 119 poke32(MISC_CTRL,
120 PEEK32(MISC_CTRL) | MISC_CTRL_DAC_POWER_OFF); 120 peek32(MISC_CTRL) | MISC_CTRL_DAC_POWER_OFF);
121 /* shut off dpms */ 121 /* shut off dpms */
122 val = PEEK32(SYSTEM_CTRL) & ~SYSTEM_CTRL_DPMS_MASK; 122 val = peek32(SYSTEM_CTRL) & ~SYSTEM_CTRL_DPMS_MASK;
123 val |= SYSTEM_CTRL_DPMS_VPHN; 123 val |= SYSTEM_CTRL_DPMS_VPHN;
124 POKE32(SYSTEM_CTRL, val); 124 poke32(SYSTEM_CTRL, val);
125 } else { 125 } else {
126 POKE32(MISC_CTRL, 126 poke32(MISC_CTRL,
127 PEEK32(MISC_CTRL) & ~MISC_CTRL_DAC_POWER_OFF); 127 peek32(MISC_CTRL) & ~MISC_CTRL_DAC_POWER_OFF);
128 /* turn on dpms */ 128 /* turn on dpms */
129 val = PEEK32(SYSTEM_CTRL) & ~SYSTEM_CTRL_DPMS_MASK; 129 val = peek32(SYSTEM_CTRL) & ~SYSTEM_CTRL_DPMS_MASK;
130 val |= SYSTEM_CTRL_DPMS_VPHP; 130 val |= SYSTEM_CTRL_DPMS_VPHP;
131 POKE32(SYSTEM_CTRL, val); 131 poke32(SYSTEM_CTRL, val);
132 } 132 }
133 133
134 val = PEEK32(PANEL_DISPLAY_CTRL) & 134 val = peek32(PANEL_DISPLAY_CTRL) &
135 ~(PANEL_DISPLAY_CTRL_DUAL_DISPLAY | 135 ~(PANEL_DISPLAY_CTRL_DUAL_DISPLAY |
136 PANEL_DISPLAY_CTRL_DOUBLE_PIXEL); 136 PANEL_DISPLAY_CTRL_DOUBLE_PIXEL);
137 switch (sm750_dev->pnltype) { 137 switch (sm750_dev->pnltype) {
@@ -144,7 +144,7 @@ int hw_sm750_inithw(struct sm750_dev *sm750_dev, struct pci_dev *pdev)
144 val |= PANEL_DISPLAY_CTRL_DUAL_DISPLAY; 144 val |= PANEL_DISPLAY_CTRL_DUAL_DISPLAY;
145 break; 145 break;
146 } 146 }
147 POKE32(PANEL_DISPLAY_CTRL, val); 147 poke32(PANEL_DISPLAY_CTRL, val);
148 } else { 148 } else {
149 /* 149 /*
150 * for 750LE, no DVI chip initialization 150 * for 750LE, no DVI chip initialization
@@ -211,9 +211,9 @@ int hw_sm750_output_setMode(struct lynxfb_output *output,
211 /* just open DISPLAY_CONTROL_750LE register bit 3:0 */ 211 /* just open DISPLAY_CONTROL_750LE register bit 3:0 */
212 u32 reg; 212 u32 reg;
213 213
214 reg = PEEK32(DISPLAY_CONTROL_750LE); 214 reg = peek32(DISPLAY_CONTROL_750LE);
215 reg |= 0xf; 215 reg |= 0xf;
216 POKE32(DISPLAY_CONTROL_750LE, reg); 216 poke32(DISPLAY_CONTROL_750LE, reg);
217 } 217 }
218 218
219 pr_info("ddk setlogicdispout done\n"); 219 pr_info("ddk setlogicdispout done\n");
@@ -312,7 +312,7 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
312 312
313 if (crtc->channel != sm750_secondary) { 313 if (crtc->channel != sm750_secondary) {
314 /* set pitch, offset, width, start address, etc... */ 314 /* set pitch, offset, width, start address, etc... */
315 POKE32(PANEL_FB_ADDRESS, 315 poke32(PANEL_FB_ADDRESS,
316 crtc->oScreen & PANEL_FB_ADDRESS_ADDRESS_MASK); 316 crtc->oScreen & PANEL_FB_ADDRESS_ADDRESS_MASK);
317 317
318 reg = var->xres * (var->bits_per_pixel >> 3); 318 reg = var->xres * (var->bits_per_pixel >> 3);
@@ -324,32 +324,32 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
324 reg = (reg << PANEL_FB_WIDTH_WIDTH_SHIFT) & 324 reg = (reg << PANEL_FB_WIDTH_WIDTH_SHIFT) &
325 PANEL_FB_WIDTH_WIDTH_MASK; 325 PANEL_FB_WIDTH_WIDTH_MASK;
326 reg |= (fix->line_length & PANEL_FB_WIDTH_OFFSET_MASK); 326 reg |= (fix->line_length & PANEL_FB_WIDTH_OFFSET_MASK);
327 POKE32(PANEL_FB_WIDTH, reg); 327 poke32(PANEL_FB_WIDTH, reg);
328 328
329 reg = ((var->xres - 1) << PANEL_WINDOW_WIDTH_WIDTH_SHIFT) & 329 reg = ((var->xres - 1) << PANEL_WINDOW_WIDTH_WIDTH_SHIFT) &
330 PANEL_WINDOW_WIDTH_WIDTH_MASK; 330 PANEL_WINDOW_WIDTH_WIDTH_MASK;
331 reg |= (var->xoffset & PANEL_WINDOW_WIDTH_X_MASK); 331 reg |= (var->xoffset & PANEL_WINDOW_WIDTH_X_MASK);
332 POKE32(PANEL_WINDOW_WIDTH, reg); 332 poke32(PANEL_WINDOW_WIDTH, reg);
333 333
334 reg = (var->yres_virtual - 1) << 334 reg = (var->yres_virtual - 1) <<
335 PANEL_WINDOW_HEIGHT_HEIGHT_SHIFT; 335 PANEL_WINDOW_HEIGHT_HEIGHT_SHIFT;
336 reg &= PANEL_WINDOW_HEIGHT_HEIGHT_MASK; 336 reg &= PANEL_WINDOW_HEIGHT_HEIGHT_MASK;
337 reg |= (var->yoffset & PANEL_WINDOW_HEIGHT_Y_MASK); 337 reg |= (var->yoffset & PANEL_WINDOW_HEIGHT_Y_MASK);
338 POKE32(PANEL_WINDOW_HEIGHT, reg); 338 poke32(PANEL_WINDOW_HEIGHT, reg);
339 339
340 POKE32(PANEL_PLANE_TL, 0); 340 poke32(PANEL_PLANE_TL, 0);
341 341
342 reg = ((var->yres - 1) << PANEL_PLANE_BR_BOTTOM_SHIFT) & 342 reg = ((var->yres - 1) << PANEL_PLANE_BR_BOTTOM_SHIFT) &
343 PANEL_PLANE_BR_BOTTOM_MASK; 343 PANEL_PLANE_BR_BOTTOM_MASK;
344 reg |= ((var->xres - 1) & PANEL_PLANE_BR_RIGHT_MASK); 344 reg |= ((var->xres - 1) & PANEL_PLANE_BR_RIGHT_MASK);
345 POKE32(PANEL_PLANE_BR, reg); 345 poke32(PANEL_PLANE_BR, reg);
346 346
347 /* set pixel format */ 347 /* set pixel format */
348 reg = PEEK32(PANEL_DISPLAY_CTRL); 348 reg = peek32(PANEL_DISPLAY_CTRL);
349 POKE32(PANEL_DISPLAY_CTRL, reg | (var->bits_per_pixel >> 4)); 349 poke32(PANEL_DISPLAY_CTRL, reg | (var->bits_per_pixel >> 4));
350 } else { 350 } else {
351 /* not implemented now */ 351 /* not implemented now */
352 POKE32(CRT_FB_ADDRESS, crtc->oScreen); 352 poke32(CRT_FB_ADDRESS, crtc->oScreen);
353 reg = var->xres * (var->bits_per_pixel >> 3); 353 reg = var->xres * (var->bits_per_pixel >> 3);
354 /* 354 /*
355 * crtc->channel is not equal to par->index on numeric, 355 * crtc->channel is not equal to par->index on numeric,
@@ -358,13 +358,13 @@ int hw_sm750_crtc_setMode(struct lynxfb_crtc *crtc,
358 reg = ALIGN(reg, crtc->line_pad) << CRT_FB_WIDTH_WIDTH_SHIFT; 358 reg = ALIGN(reg, crtc->line_pad) << CRT_FB_WIDTH_WIDTH_SHIFT;
359 reg &= CRT_FB_WIDTH_WIDTH_MASK; 359 reg &= CRT_FB_WIDTH_WIDTH_MASK;
360 reg |= (fix->line_length & CRT_FB_WIDTH_OFFSET_MASK); 360 reg |= (fix->line_length & CRT_FB_WIDTH_OFFSET_MASK);
361 POKE32(CRT_FB_WIDTH, reg); 361 poke32(CRT_FB_WIDTH, reg);
362 362
363 /* SET PIXEL FORMAT */ 363 /* SET PIXEL FORMAT */
364 reg = PEEK32(CRT_DISPLAY_CTRL); 364 reg = peek32(CRT_DISPLAY_CTRL);
365 reg |= ((var->bits_per_pixel >> 4) & 365 reg |= ((var->bits_per_pixel >> 4) &
366 CRT_DISPLAY_CTRL_FORMAT_MASK); 366 CRT_DISPLAY_CTRL_FORMAT_MASK);
367 POKE32(CRT_DISPLAY_CTRL, reg); 367 poke32(CRT_DISPLAY_CTRL, reg);
368 } 368 }
369 369
370exit: 370exit:
@@ -376,7 +376,7 @@ int hw_sm750_setColReg(struct lynxfb_crtc *crtc, ushort index,
376{ 376{
377 static unsigned int add[] = {PANEL_PALETTE_RAM, CRT_PALETTE_RAM}; 377 static unsigned int add[] = {PANEL_PALETTE_RAM, CRT_PALETTE_RAM};
378 378
379 POKE32(add[crtc->channel] + index * 4, 379 poke32(add[crtc->channel] + index * 4,
380 (red << 16) | (green << 8) | blue); 380 (red << 16) | (green << 8) | blue);
381 return 0; 381 return 0;
382} 382}
@@ -413,11 +413,11 @@ int hw_sm750le_setBLANK(struct lynxfb_output *output, int blank)
413 if (output->paths & sm750_crt) { 413 if (output->paths & sm750_crt) {
414 unsigned int val; 414 unsigned int val;
415 415
416 val = PEEK32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_DPMS_MASK; 416 val = peek32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_DPMS_MASK;
417 POKE32(CRT_DISPLAY_CTRL, val | dpms); 417 poke32(CRT_DISPLAY_CTRL, val | dpms);
418 418
419 val = PEEK32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_BLANK; 419 val = peek32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_BLANK;
420 POKE32(CRT_DISPLAY_CTRL, val | crtdb); 420 poke32(CRT_DISPLAY_CTRL, val | crtdb);
421 } 421 }
422 return 0; 422 return 0;
423} 423}
@@ -456,20 +456,20 @@ int hw_sm750_setBLANK(struct lynxfb_output *output, int blank)
456 } 456 }
457 457
458 if (output->paths & sm750_crt) { 458 if (output->paths & sm750_crt) {
459 unsigned int val = PEEK32(SYSTEM_CTRL) & ~SYSTEM_CTRL_DPMS_MASK; 459 unsigned int val = peek32(SYSTEM_CTRL) & ~SYSTEM_CTRL_DPMS_MASK;
460 460
461 POKE32(SYSTEM_CTRL, val | dpms); 461 poke32(SYSTEM_CTRL, val | dpms);
462 462
463 val = PEEK32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_BLANK; 463 val = peek32(CRT_DISPLAY_CTRL) & ~CRT_DISPLAY_CTRL_BLANK;
464 POKE32(CRT_DISPLAY_CTRL, val | crtdb); 464 poke32(CRT_DISPLAY_CTRL, val | crtdb);
465 } 465 }
466 466
467 if (output->paths & sm750_panel) { 467 if (output->paths & sm750_panel) {
468 unsigned int val = PEEK32(PANEL_DISPLAY_CTRL); 468 unsigned int val = peek32(PANEL_DISPLAY_CTRL);
469 469
470 val &= ~PANEL_DISPLAY_CTRL_DATA; 470 val &= ~PANEL_DISPLAY_CTRL_DATA;
471 val |= pps; 471 val |= pps;
472 POKE32(PANEL_DISPLAY_CTRL, val); 472 poke32(PANEL_DISPLAY_CTRL, val);
473 } 473 }
474 474
475 return 0; 475 return 0;
@@ -482,23 +482,23 @@ void hw_sm750_initAccel(struct sm750_dev *sm750_dev)
482 sm750_enable_2d_engine(1); 482 sm750_enable_2d_engine(1);
483 483
484 if (sm750_get_chip_type() == SM750LE) { 484 if (sm750_get_chip_type() == SM750LE) {
485 reg = PEEK32(DE_STATE1); 485 reg = peek32(DE_STATE1);
486 reg |= DE_STATE1_DE_ABORT; 486 reg |= DE_STATE1_DE_ABORT;
487 POKE32(DE_STATE1, reg); 487 poke32(DE_STATE1, reg);
488 488
489 reg = PEEK32(DE_STATE1); 489 reg = peek32(DE_STATE1);
490 reg &= ~DE_STATE1_DE_ABORT; 490 reg &= ~DE_STATE1_DE_ABORT;
491 POKE32(DE_STATE1, reg); 491 poke32(DE_STATE1, reg);
492 492
493 } else { 493 } else {
494 /* engine reset */ 494 /* engine reset */
495 reg = PEEK32(SYSTEM_CTRL); 495 reg = peek32(SYSTEM_CTRL);
496 reg |= SYSTEM_CTRL_DE_ABORT; 496 reg |= SYSTEM_CTRL_DE_ABORT;
497 POKE32(SYSTEM_CTRL, reg); 497 poke32(SYSTEM_CTRL, reg);
498 498
499 reg = PEEK32(SYSTEM_CTRL); 499 reg = peek32(SYSTEM_CTRL);
500 reg &= ~SYSTEM_CTRL_DE_ABORT; 500 reg &= ~SYSTEM_CTRL_DE_ABORT;
501 POKE32(SYSTEM_CTRL, reg); 501 poke32(SYSTEM_CTRL, reg);
502 } 502 }
503 503
504 /* call 2d init */ 504 /* call 2d init */
@@ -512,7 +512,7 @@ int hw_sm750le_deWait(void)
512 DE_STATE2_DE_MEM_FIFO_EMPTY; 512 DE_STATE2_DE_MEM_FIFO_EMPTY;
513 513
514 while (i--) { 514 while (i--) {
515 unsigned int val = PEEK32(DE_STATE2); 515 unsigned int val = peek32(DE_STATE2);
516 516
517 if ((val & mask) == 517 if ((val & mask) ==
518 (DE_STATE2_DE_FIFO_EMPTY | DE_STATE2_DE_MEM_FIFO_EMPTY)) 518 (DE_STATE2_DE_FIFO_EMPTY | DE_STATE2_DE_MEM_FIFO_EMPTY))
@@ -530,7 +530,7 @@ int hw_sm750_deWait(void)
530 SYSTEM_CTRL_DE_MEM_FIFO_EMPTY; 530 SYSTEM_CTRL_DE_MEM_FIFO_EMPTY;
531 531
532 while (i--) { 532 while (i--) {
533 unsigned int val = PEEK32(SYSTEM_CTRL); 533 unsigned int val = peek32(SYSTEM_CTRL);
534 534
535 if ((val & mask) == 535 if ((val & mask) ==
536 (SYSTEM_CTRL_DE_FIFO_EMPTY | SYSTEM_CTRL_DE_MEM_FIFO_EMPTY)) 536 (SYSTEM_CTRL_DE_FIFO_EMPTY | SYSTEM_CTRL_DE_MEM_FIFO_EMPTY))
@@ -555,12 +555,12 @@ int hw_sm750_pan_display(struct lynxfb_crtc *crtc,
555 ((var->xoffset * var->bits_per_pixel) >> 3); 555 ((var->xoffset * var->bits_per_pixel) >> 3);
556 total += crtc->oScreen; 556 total += crtc->oScreen;
557 if (crtc->channel == sm750_primary) { 557 if (crtc->channel == sm750_primary) {
558 POKE32(PANEL_FB_ADDRESS, 558 poke32(PANEL_FB_ADDRESS,
559 PEEK32(PANEL_FB_ADDRESS) | 559 peek32(PANEL_FB_ADDRESS) |
560 (total & PANEL_FB_ADDRESS_ADDRESS_MASK)); 560 (total & PANEL_FB_ADDRESS_ADDRESS_MASK));
561 } else { 561 } else {
562 POKE32(CRT_FB_ADDRESS, 562 poke32(CRT_FB_ADDRESS,
563 PEEK32(CRT_FB_ADDRESS) | 563 peek32(CRT_FB_ADDRESS) |
564 (total & CRT_FB_ADDRESS_ADDRESS_MASK)); 564 (total & CRT_FB_ADDRESS_ADDRESS_MASK));
565 } 565 }
566 return 0; 566 return 0;
diff --git a/drivers/staging/speakup/fakekey.c b/drivers/staging/speakup/fakekey.c
index 8f058b42f68d..d76da0a1382c 100644
--- a/drivers/staging/speakup/fakekey.c
+++ b/drivers/staging/speakup/fakekey.c
@@ -63,8 +63,8 @@ void speakup_remove_virtual_keyboard(void)
63} 63}
64 64
65/* 65/*
66 * Send a simulated down-arrow to the application. 66 * Send a simulated down-arrow to the application.
67 */ 67 */
68void speakup_fake_down_arrow(void) 68void speakup_fake_down_arrow(void)
69{ 69{
70 unsigned long flags; 70 unsigned long flags;
@@ -87,9 +87,9 @@ void speakup_fake_down_arrow(void)
87} 87}
88 88
89/* 89/*
90 * Are we handling a simulated keypress on the current CPU? 90 * Are we handling a simulated keypress on the current CPU?
91 * Returns a boolean. 91 * Returns a boolean.
92 */ 92 */
93bool speakup_fake_key_pressed(void) 93bool speakup_fake_key_pressed(void)
94{ 94{
95 return this_cpu_read(reporting_keystroke); 95 return this_cpu_read(reporting_keystroke);
diff --git a/drivers/staging/speakup/i18n.c b/drivers/staging/speakup/i18n.c
index 8960079e4d60..2f9b3df7f78d 100644
--- a/drivers/staging/speakup/i18n.c
+++ b/drivers/staging/speakup/i18n.c
@@ -401,7 +401,7 @@ char *spk_msg_get(enum msg_index_t index)
401 * Finds the start of the next format specifier in the argument string. 401 * Finds the start of the next format specifier in the argument string.
402 * Return value: pointer to start of format 402 * Return value: pointer to start of format
403 * specifier, or NULL if no specifier exists. 403 * specifier, or NULL if no specifier exists.
404*/ 404 */
405static char *next_specifier(char *input) 405static char *next_specifier(char *input)
406{ 406{
407 int found = 0; 407 int found = 0;
@@ -450,7 +450,7 @@ static char *skip_width(char *input)
450 * Note that this code only accepts a handful of conversion specifiers: 450 * Note that this code only accepts a handful of conversion specifiers:
451 * c d s x and ld. Not accidental; these are exactly the ones used in 451 * c d s x and ld. Not accidental; these are exactly the ones used in
452 * the default group of formatted messages. 452 * the default group of formatted messages.
453*/ 453 */
454static char *skip_conversion(char *input) 454static char *skip_conversion(char *input)
455{ 455{
456 if ((input[0] == 'l') && (input[1] == 'd')) 456 if ((input[0] == 'l') && (input[1] == 'd'))
@@ -463,7 +463,7 @@ static char *skip_conversion(char *input)
463/* 463/*
464 * Function: find_specifier_end 464 * Function: find_specifier_end
465 * Return a pointer to the end of the format specifier. 465 * Return a pointer to the end of the format specifier.
466*/ 466 */
467static char *find_specifier_end(char *input) 467static char *find_specifier_end(char *input)
468{ 468{
469 input++; /* Advance over %. */ 469 input++; /* Advance over %. */
@@ -478,7 +478,7 @@ static char *find_specifier_end(char *input)
478 * Compare the format specifiers pointed to by *input1 and *input2. 478 * Compare the format specifiers pointed to by *input1 and *input2.
479 * Return 1 if they are the same, 0 otherwise. Advance *input1 and *input2 479 * Return 1 if they are the same, 0 otherwise. Advance *input1 and *input2
480 * so that they point to the character following the end of the specifier. 480 * so that they point to the character following the end of the specifier.
481*/ 481 */
482static int compare_specifiers(char **input1, char **input2) 482static int compare_specifiers(char **input1, char **input2)
483{ 483{
484 int same = 0; 484 int same = 0;
@@ -500,7 +500,7 @@ static int compare_specifiers(char **input1, char **input2)
500 * Check that two format strings contain the same number of format specifiers, 500 * Check that two format strings contain the same number of format specifiers,
501 * and that the order of specifiers is the same in both strings. 501 * and that the order of specifiers is the same in both strings.
502 * Return 1 if the condition holds, 0 if it doesn't. 502 * Return 1 if the condition holds, 0 if it doesn't.
503*/ 503 */
504static int fmt_validate(char *template, char *user) 504static int fmt_validate(char *template, char *user)
505{ 505{
506 int valid = 1; 506 int valid = 1;
@@ -537,7 +537,7 @@ static int fmt_validate(char *template, char *user)
537 * Failure conditions: 537 * Failure conditions:
538 * -EINVAL - Invalid format specifiers in formatted message or illegal index. 538 * -EINVAL - Invalid format specifiers in formatted message or illegal index.
539 * -ENOMEM - Unable to allocate memory. 539 * -ENOMEM - Unable to allocate memory.
540*/ 540 */
541ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length) 541ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
542{ 542{
543 int rc = 0; 543 int rc = 0;
@@ -573,7 +573,7 @@ ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
573/* 573/*
574 * Find a message group, given its name. Return a pointer to the structure 574 * Find a message group, given its name. Return a pointer to the structure
575 * if found, or NULL otherwise. 575 * if found, or NULL otherwise.
576*/ 576 */
577struct msg_group_t *spk_find_msg_group(const char *group_name) 577struct msg_group_t *spk_find_msg_group(const char *group_name)
578{ 578{
579 struct msg_group_t *group = NULL; 579 struct msg_group_t *group = NULL;
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index e744aa9730ff..4e7ebc306488 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -865,66 +865,66 @@ static struct kobj_attribute version_attribute =
865 __ATTR_RO(version); 865 __ATTR_RO(version);
866 866
867static struct kobj_attribute delimiters_attribute = 867static struct kobj_attribute delimiters_attribute =
868 __ATTR(delimiters, S_IWUSR | S_IRUGO, punc_show, punc_store); 868 __ATTR(delimiters, 0644, punc_show, punc_store);
869static struct kobj_attribute ex_num_attribute = 869static struct kobj_attribute ex_num_attribute =
870 __ATTR(ex_num, S_IWUSR | S_IRUGO, punc_show, punc_store); 870 __ATTR(ex_num, 0644, punc_show, punc_store);
871static struct kobj_attribute punc_all_attribute = 871static struct kobj_attribute punc_all_attribute =
872 __ATTR(punc_all, S_IWUSR | S_IRUGO, punc_show, punc_store); 872 __ATTR(punc_all, 0644, punc_show, punc_store);
873static struct kobj_attribute punc_most_attribute = 873static struct kobj_attribute punc_most_attribute =
874 __ATTR(punc_most, S_IWUSR | S_IRUGO, punc_show, punc_store); 874 __ATTR(punc_most, 0644, punc_show, punc_store);
875static struct kobj_attribute punc_some_attribute = 875static struct kobj_attribute punc_some_attribute =
876 __ATTR(punc_some, S_IWUSR | S_IRUGO, punc_show, punc_store); 876 __ATTR(punc_some, 0644, punc_show, punc_store);
877static struct kobj_attribute repeats_attribute = 877static struct kobj_attribute repeats_attribute =
878 __ATTR(repeats, S_IWUSR | S_IRUGO, punc_show, punc_store); 878 __ATTR(repeats, 0644, punc_show, punc_store);
879 879
880static struct kobj_attribute attrib_bleep_attribute = 880static struct kobj_attribute attrib_bleep_attribute =
881 __ATTR(attrib_bleep, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 881 __ATTR(attrib_bleep, 0644, spk_var_show, spk_var_store);
882static struct kobj_attribute bell_pos_attribute = 882static struct kobj_attribute bell_pos_attribute =
883 __ATTR(bell_pos, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 883 __ATTR(bell_pos, 0644, spk_var_show, spk_var_store);
884static struct kobj_attribute bleep_time_attribute = 884static struct kobj_attribute bleep_time_attribute =
885 __ATTR(bleep_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 885 __ATTR(bleep_time, 0644, spk_var_show, spk_var_store);
886static struct kobj_attribute bleeps_attribute = 886static struct kobj_attribute bleeps_attribute =
887 __ATTR(bleeps, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 887 __ATTR(bleeps, 0644, spk_var_show, spk_var_store);
888static struct kobj_attribute cursor_time_attribute = 888static struct kobj_attribute cursor_time_attribute =
889 __ATTR(cursor_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 889 __ATTR(cursor_time, 0644, spk_var_show, spk_var_store);
890static struct kobj_attribute key_echo_attribute = 890static struct kobj_attribute key_echo_attribute =
891 __ATTR(key_echo, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 891 __ATTR(key_echo, 0644, spk_var_show, spk_var_store);
892static struct kobj_attribute no_interrupt_attribute = 892static struct kobj_attribute no_interrupt_attribute =
893 __ATTR(no_interrupt, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 893 __ATTR(no_interrupt, 0644, spk_var_show, spk_var_store);
894static struct kobj_attribute punc_level_attribute = 894static struct kobj_attribute punc_level_attribute =
895 __ATTR(punc_level, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 895 __ATTR(punc_level, 0644, spk_var_show, spk_var_store);
896static struct kobj_attribute reading_punc_attribute = 896static struct kobj_attribute reading_punc_attribute =
897 __ATTR(reading_punc, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 897 __ATTR(reading_punc, 0644, spk_var_show, spk_var_store);
898static struct kobj_attribute say_control_attribute = 898static struct kobj_attribute say_control_attribute =
899 __ATTR(say_control, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 899 __ATTR(say_control, 0644, spk_var_show, spk_var_store);
900static struct kobj_attribute say_word_ctl_attribute = 900static struct kobj_attribute say_word_ctl_attribute =
901 __ATTR(say_word_ctl, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 901 __ATTR(say_word_ctl, 0644, spk_var_show, spk_var_store);
902static struct kobj_attribute spell_delay_attribute = 902static struct kobj_attribute spell_delay_attribute =
903 __ATTR(spell_delay, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 903 __ATTR(spell_delay, 0644, spk_var_show, spk_var_store);
904 904
905/* 905/*
906 * These attributes are i18n related. 906 * These attributes are i18n related.
907 */ 907 */
908static struct kobj_attribute announcements_attribute = 908static struct kobj_attribute announcements_attribute =
909 __ATTR(announcements, S_IWUSR | S_IRUGO, message_show, message_store); 909 __ATTR(announcements, 0644, message_show, message_store);
910static struct kobj_attribute characters_attribute = 910static struct kobj_attribute characters_attribute =
911 __ATTR(characters, S_IWUSR | S_IRUGO, chars_chartab_show, 911 __ATTR(characters, 0644, chars_chartab_show,
912 chars_chartab_store); 912 chars_chartab_store);
913static struct kobj_attribute chartab_attribute = 913static struct kobj_attribute chartab_attribute =
914 __ATTR(chartab, S_IWUSR | S_IRUGO, chars_chartab_show, 914 __ATTR(chartab, 0644, chars_chartab_show,
915 chars_chartab_store); 915 chars_chartab_store);
916static struct kobj_attribute ctl_keys_attribute = 916static struct kobj_attribute ctl_keys_attribute =
917 __ATTR(ctl_keys, S_IWUSR | S_IRUGO, message_show, message_store); 917 __ATTR(ctl_keys, 0644, message_show, message_store);
918static struct kobj_attribute colors_attribute = 918static struct kobj_attribute colors_attribute =
919 __ATTR(colors, S_IWUSR | S_IRUGO, message_show, message_store); 919 __ATTR(colors, 0644, message_show, message_store);
920static struct kobj_attribute formatted_attribute = 920static struct kobj_attribute formatted_attribute =
921 __ATTR(formatted, S_IWUSR | S_IRUGO, message_show, message_store); 921 __ATTR(formatted, 0644, message_show, message_store);
922static struct kobj_attribute function_names_attribute = 922static struct kobj_attribute function_names_attribute =
923 __ATTR(function_names, S_IWUSR | S_IRUGO, message_show, message_store); 923 __ATTR(function_names, 0644, message_show, message_store);
924static struct kobj_attribute key_names_attribute = 924static struct kobj_attribute key_names_attribute =
925 __ATTR(key_names, S_IWUSR | S_IRUGO, message_show, message_store); 925 __ATTR(key_names, 0644, message_show, message_store);
926static struct kobj_attribute states_attribute = 926static struct kobj_attribute states_attribute =
927 __ATTR(states, S_IWUSR | S_IRUGO, message_show, message_store); 927 __ATTR(states, 0644, message_show, message_store);
928 928
929/* 929/*
930 * Create groups of attributes so that we can create and destroy them all 930 * Create groups of attributes so that we can create and destroy them all
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index 5c192042eeac..c2f70ef5b9b3 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -16,7 +16,7 @@
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19*/ 19 */
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/vt.h> 22#include <linux/vt.h>
@@ -58,8 +58,8 @@ MODULE_LICENSE("GPL");
58MODULE_VERSION(SPEAKUP_VERSION); 58MODULE_VERSION(SPEAKUP_VERSION);
59 59
60char *synth_name; 60char *synth_name;
61module_param_named(synth, synth_name, charp, S_IRUGO); 61module_param_named(synth, synth_name, charp, 0444);
62module_param_named(quiet, spk_quiet_boot, bool, S_IRUGO); 62module_param_named(quiet, spk_quiet_boot, bool, 0444);
63 63
64MODULE_PARM_DESC(synth, "Synth to start if speakup is built in."); 64MODULE_PARM_DESC(synth, "Synth to start if speakup is built in.");
65MODULE_PARM_DESC(quiet, "Do not announce when the synthesizer is found."); 65MODULE_PARM_DESC(quiet, "Do not announce when the synthesizer is found.");
diff --git a/drivers/staging/speakup/speakup.h b/drivers/staging/speakup/speakup.h
index df74c912da72..b203f0f883a9 100644
--- a/drivers/staging/speakup/speakup.h
+++ b/drivers/staging/speakup/speakup.h
@@ -9,10 +9,6 @@
9#define SHIFT_TBL_SIZE 64 9#define SHIFT_TBL_SIZE 64
10#define MAX_DESC_LEN 72 10#define MAX_DESC_LEN 72
11 11
12/* proc permissions */
13#define USER_R (S_IFREG|S_IRUGO)
14#define USER_W (S_IFREG|S_IWUGO)
15
16#define TOGGLE_0 .u.n = {NULL, 0, 0, 1, 0, 0, NULL } 12#define TOGGLE_0 .u.n = {NULL, 0, 0, 1, 0, 0, NULL }
17#define TOGGLE_1 .u.n = {NULL, 1, 0, 1, 0, 0, NULL } 13#define TOGGLE_1 .u.n = {NULL, 1, 0, 1, 0, 0, NULL }
18#define MAXVARLEN 15 14#define MAXVARLEN 15
diff --git a/drivers/staging/speakup/speakup_acntpc.c b/drivers/staging/speakup/speakup_acntpc.c
index efb791bb642b..c7fab261d860 100644
--- a/drivers/staging/speakup/speakup_acntpc.c
+++ b/drivers/staging/speakup/speakup_acntpc.c
@@ -57,28 +57,28 @@ static struct var_t vars[] = {
57 * These attributes will appear in /sys/accessibility/speakup/acntpc. 57 * These attributes will appear in /sys/accessibility/speakup/acntpc.
58 */ 58 */
59static struct kobj_attribute caps_start_attribute = 59static struct kobj_attribute caps_start_attribute =
60 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 60 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
61static struct kobj_attribute caps_stop_attribute = 61static struct kobj_attribute caps_stop_attribute =
62 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 62 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
63static struct kobj_attribute pitch_attribute = 63static struct kobj_attribute pitch_attribute =
64 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 64 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
65static struct kobj_attribute rate_attribute = 65static struct kobj_attribute rate_attribute =
66 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 66 __ATTR(rate, 0644, spk_var_show, spk_var_store);
67static struct kobj_attribute tone_attribute = 67static struct kobj_attribute tone_attribute =
68 __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 68 __ATTR(tone, 0644, spk_var_show, spk_var_store);
69static struct kobj_attribute vol_attribute = 69static struct kobj_attribute vol_attribute =
70 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 70 __ATTR(vol, 0644, spk_var_show, spk_var_store);
71 71
72static struct kobj_attribute delay_time_attribute = 72static struct kobj_attribute delay_time_attribute =
73 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 73 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
74static struct kobj_attribute direct_attribute = 74static struct kobj_attribute direct_attribute =
75 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 75 __ATTR(direct, 0644, spk_var_show, spk_var_store);
76static struct kobj_attribute full_time_attribute = 76static struct kobj_attribute full_time_attribute =
77 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 77 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
78static struct kobj_attribute jiffy_delta_attribute = 78static struct kobj_attribute jiffy_delta_attribute =
79 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 79 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
80static struct kobj_attribute trigger_time_attribute = 80static struct kobj_attribute trigger_time_attribute =
81 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 81 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
82 82
83/* 83/*
84 * Create a group of attributes so that we can create and destroy them all 84 * Create a group of attributes so that we can create and destroy them all
@@ -307,8 +307,8 @@ static void accent_release(void)
307 speakup_info.port_tts = 0; 307 speakup_info.port_tts = 0;
308} 308}
309 309
310module_param_named(port, port_forced, int, S_IRUGO); 310module_param_named(port, port_forced, int, 0444);
311module_param_named(start, synth_acntpc.startup, short, S_IRUGO); 311module_param_named(start, synth_acntpc.startup, short, 0444);
312 312
313MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing)."); 313MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
314MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 314MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_acntsa.c b/drivers/staging/speakup/speakup_acntsa.c
index 34f45d3549b2..b2e352712766 100644
--- a/drivers/staging/speakup/speakup_acntsa.c
+++ b/drivers/staging/speakup/speakup_acntsa.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3* this version considerably modified by David Borowski, david575@rogers.com 3 * this version considerably modified by David Borowski, david575@rogers.com
4 * 4 *
5 * Copyright (C) 1998-99 Kirk Reiser. 5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 6 * Copyright (C) 2003 David Borowski.
@@ -43,28 +43,28 @@ static struct var_t vars[] = {
43 * These attributes will appear in /sys/accessibility/speakup/acntsa. 43 * These attributes will appear in /sys/accessibility/speakup/acntsa.
44 */ 44 */
45static struct kobj_attribute caps_start_attribute = 45static struct kobj_attribute caps_start_attribute =
46 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 46 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
47static struct kobj_attribute caps_stop_attribute = 47static struct kobj_attribute caps_stop_attribute =
48 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 48 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
49static struct kobj_attribute pitch_attribute = 49static struct kobj_attribute pitch_attribute =
50 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 50 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
51static struct kobj_attribute rate_attribute = 51static struct kobj_attribute rate_attribute =
52 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 52 __ATTR(rate, 0644, spk_var_show, spk_var_store);
53static struct kobj_attribute tone_attribute = 53static struct kobj_attribute tone_attribute =
54 __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 54 __ATTR(tone, 0644, spk_var_show, spk_var_store);
55static struct kobj_attribute vol_attribute = 55static struct kobj_attribute vol_attribute =
56 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 56 __ATTR(vol, 0644, spk_var_show, spk_var_store);
57 57
58static struct kobj_attribute delay_time_attribute = 58static struct kobj_attribute delay_time_attribute =
59 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 59 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
60static struct kobj_attribute direct_attribute = 60static struct kobj_attribute direct_attribute =
61 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 61 __ATTR(direct, 0644, spk_var_show, spk_var_store);
62static struct kobj_attribute full_time_attribute = 62static struct kobj_attribute full_time_attribute =
63 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 63 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
64static struct kobj_attribute jiffy_delta_attribute = 64static struct kobj_attribute jiffy_delta_attribute =
65 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 65 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
66static struct kobj_attribute trigger_time_attribute = 66static struct kobj_attribute trigger_time_attribute =
67 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 67 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
68 68
69/* 69/*
70 * Create a group of attributes so that we can create and destroy them all 70 * Create a group of attributes so that we can create and destroy them all
@@ -133,8 +133,8 @@ static int synth_probe(struct spk_synth *synth)
133 return failed; 133 return failed;
134} 134}
135 135
136module_param_named(ser, synth_acntsa.ser, int, S_IRUGO); 136module_param_named(ser, synth_acntsa.ser, int, 0444);
137module_param_named(start, synth_acntsa.startup, short, S_IRUGO); 137module_param_named(start, synth_acntsa.startup, short, 0444);
138 138
139MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 139MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
140MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 140MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_apollo.c b/drivers/staging/speakup/speakup_apollo.c
index 3cbc8a7ad1ef..3f43f8105bc0 100644
--- a/drivers/staging/speakup/speakup_apollo.c
+++ b/drivers/staging/speakup/speakup_apollo.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3* this version considerably modified by David Borowski, david575@rogers.com 3 * this version considerably modified by David Borowski, david575@rogers.com
4 * 4 *
5 * Copyright (C) 1998-99 Kirk Reiser. 5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 6 * Copyright (C) 2003 David Borowski.
@@ -49,30 +49,30 @@ static struct var_t vars[] = {
49 * These attributes will appear in /sys/accessibility/speakup/apollo. 49 * These attributes will appear in /sys/accessibility/speakup/apollo.
50 */ 50 */
51static struct kobj_attribute caps_start_attribute = 51static struct kobj_attribute caps_start_attribute =
52 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 52 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
53static struct kobj_attribute caps_stop_attribute = 53static struct kobj_attribute caps_stop_attribute =
54 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 54 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
55static struct kobj_attribute lang_attribute = 55static struct kobj_attribute lang_attribute =
56 __ATTR(lang, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 56 __ATTR(lang, 0644, spk_var_show, spk_var_store);
57static struct kobj_attribute pitch_attribute = 57static struct kobj_attribute pitch_attribute =
58 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 58 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
59static struct kobj_attribute rate_attribute = 59static struct kobj_attribute rate_attribute =
60 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 60 __ATTR(rate, 0644, spk_var_show, spk_var_store);
61static struct kobj_attribute voice_attribute = 61static struct kobj_attribute voice_attribute =
62 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 62 __ATTR(voice, 0644, spk_var_show, spk_var_store);
63static struct kobj_attribute vol_attribute = 63static struct kobj_attribute vol_attribute =
64 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 64 __ATTR(vol, 0644, spk_var_show, spk_var_store);
65 65
66static struct kobj_attribute delay_time_attribute = 66static struct kobj_attribute delay_time_attribute =
67 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 67 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
68static struct kobj_attribute direct_attribute = 68static struct kobj_attribute direct_attribute =
69 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 69 __ATTR(direct, 0644, spk_var_show, spk_var_store);
70static struct kobj_attribute full_time_attribute = 70static struct kobj_attribute full_time_attribute =
71 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 71 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
72static struct kobj_attribute jiffy_delta_attribute = 72static struct kobj_attribute jiffy_delta_attribute =
73 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 73 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
74static struct kobj_attribute trigger_time_attribute = 74static struct kobj_attribute trigger_time_attribute =
75 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 75 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
76 76
77/* 77/*
78 * Create a group of attributes so that we can create and destroy them all 78 * Create a group of attributes so that we can create and destroy them all
@@ -197,8 +197,8 @@ static void do_catch_up(struct spk_synth *synth)
197 spk_serial_out(PROCSPEECH); 197 spk_serial_out(PROCSPEECH);
198} 198}
199 199
200module_param_named(ser, synth_apollo.ser, int, S_IRUGO); 200module_param_named(ser, synth_apollo.ser, int, 0444);
201module_param_named(start, synth_apollo.startup, short, S_IRUGO); 201module_param_named(start, synth_apollo.startup, short, 0444);
202 202
203MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 203MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
204MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 204MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_audptr.c b/drivers/staging/speakup/speakup_audptr.c
index 7a12b8408b67..e696b87bf515 100644
--- a/drivers/staging/speakup/speakup_audptr.c
+++ b/drivers/staging/speakup/speakup_audptr.c
@@ -45,30 +45,30 @@ static struct var_t vars[] = {
45 * These attributes will appear in /sys/accessibility/speakup/audptr. 45 * These attributes will appear in /sys/accessibility/speakup/audptr.
46 */ 46 */
47static struct kobj_attribute caps_start_attribute = 47static struct kobj_attribute caps_start_attribute =
48 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 48 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
49static struct kobj_attribute caps_stop_attribute = 49static struct kobj_attribute caps_stop_attribute =
50 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 50 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
51static struct kobj_attribute pitch_attribute = 51static struct kobj_attribute pitch_attribute =
52 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 52 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
53static struct kobj_attribute punct_attribute = 53static struct kobj_attribute punct_attribute =
54 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 54 __ATTR(punct, 0644, spk_var_show, spk_var_store);
55static struct kobj_attribute rate_attribute = 55static struct kobj_attribute rate_attribute =
56 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 56 __ATTR(rate, 0644, spk_var_show, spk_var_store);
57static struct kobj_attribute tone_attribute = 57static struct kobj_attribute tone_attribute =
58 __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 58 __ATTR(tone, 0644, spk_var_show, spk_var_store);
59static struct kobj_attribute vol_attribute = 59static struct kobj_attribute vol_attribute =
60 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 60 __ATTR(vol, 0644, spk_var_show, spk_var_store);
61 61
62static struct kobj_attribute delay_time_attribute = 62static struct kobj_attribute delay_time_attribute =
63 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 63 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
64static struct kobj_attribute direct_attribute = 64static struct kobj_attribute direct_attribute =
65 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 65 __ATTR(direct, 0644, spk_var_show, spk_var_store);
66static struct kobj_attribute full_time_attribute = 66static struct kobj_attribute full_time_attribute =
67 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 67 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
68static struct kobj_attribute jiffy_delta_attribute = 68static struct kobj_attribute jiffy_delta_attribute =
69 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 69 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
70static struct kobj_attribute trigger_time_attribute = 70static struct kobj_attribute trigger_time_attribute =
71 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 71 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
72 72
73/* 73/*
74 * Create a group of attributes so that we can create and destroy them all 74 * Create a group of attributes so that we can create and destroy them all
@@ -167,8 +167,8 @@ static int synth_probe(struct spk_synth *synth)
167 return 0; 167 return 0;
168} 168}
169 169
170module_param_named(ser, synth_audptr.ser, int, S_IRUGO); 170module_param_named(ser, synth_audptr.ser, int, 0444);
171module_param_named(start, synth_audptr.startup, short, S_IRUGO); 171module_param_named(start, synth_audptr.startup, short, 0444);
172 172
173MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 173MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
174MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 174MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_bns.c b/drivers/staging/speakup/speakup_bns.c
index 570f0c21745e..da158c968e7c 100644
--- a/drivers/staging/speakup/speakup_bns.c
+++ b/drivers/staging/speakup/speakup_bns.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3* this version considerably modified by David Borowski, david575@rogers.com 3 * this version considerably modified by David Borowski, david575@rogers.com
4 * 4 *
5 * Copyright (C) 1998-99 Kirk Reiser. 5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 6 * Copyright (C) 2003 David Borowski.
@@ -40,28 +40,28 @@ static struct var_t vars[] = {
40 * These attributes will appear in /sys/accessibility/speakup/bns. 40 * These attributes will appear in /sys/accessibility/speakup/bns.
41 */ 41 */
42static struct kobj_attribute caps_start_attribute = 42static struct kobj_attribute caps_start_attribute =
43 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 43 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
44static struct kobj_attribute caps_stop_attribute = 44static struct kobj_attribute caps_stop_attribute =
45 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 45 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
46static struct kobj_attribute pitch_attribute = 46static struct kobj_attribute pitch_attribute =
47 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 47 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
48static struct kobj_attribute rate_attribute = 48static struct kobj_attribute rate_attribute =
49 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 49 __ATTR(rate, 0644, spk_var_show, spk_var_store);
50static struct kobj_attribute tone_attribute = 50static struct kobj_attribute tone_attribute =
51 __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 51 __ATTR(tone, 0644, spk_var_show, spk_var_store);
52static struct kobj_attribute vol_attribute = 52static struct kobj_attribute vol_attribute =
53 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 53 __ATTR(vol, 0644, spk_var_show, spk_var_store);
54 54
55static struct kobj_attribute delay_time_attribute = 55static struct kobj_attribute delay_time_attribute =
56 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 56 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
57static struct kobj_attribute direct_attribute = 57static struct kobj_attribute direct_attribute =
58 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 58 __ATTR(direct, 0644, spk_var_show, spk_var_store);
59static struct kobj_attribute full_time_attribute = 59static struct kobj_attribute full_time_attribute =
60 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 60 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
61static struct kobj_attribute jiffy_delta_attribute = 61static struct kobj_attribute jiffy_delta_attribute =
62 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 62 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
63static struct kobj_attribute trigger_time_attribute = 63static struct kobj_attribute trigger_time_attribute =
64 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 64 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
65 65
66/* 66/*
67 * Create a group of attributes so that we can create and destroy them all 67 * Create a group of attributes so that we can create and destroy them all
@@ -117,8 +117,8 @@ static struct spk_synth synth_bns = {
117 }, 117 },
118}; 118};
119 119
120module_param_named(ser, synth_bns.ser, int, S_IRUGO); 120module_param_named(ser, synth_bns.ser, int, 0444);
121module_param_named(start, synth_bns.startup, short, S_IRUGO); 121module_param_named(start, synth_bns.startup, short, 0444);
122 122
123MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 123MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
124MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 124MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_decext.c b/drivers/staging/speakup/speakup_decext.c
index 1a5cf3d0a559..6b74a97385da 100644
--- a/drivers/staging/speakup/speakup_decext.c
+++ b/drivers/staging/speakup/speakup_decext.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3* this version considerably modified by David Borowski, david575@rogers.com 3 * this version considerably modified by David Borowski, david575@rogers.com
4 * 4 *
5 * Copyright (C) 1998-99 Kirk Reiser. 5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 6 * Copyright (C) 2003 David Borowski.
@@ -67,30 +67,30 @@ static struct var_t vars[] = {
67 * These attributes will appear in /sys/accessibility/speakup/decext. 67 * These attributes will appear in /sys/accessibility/speakup/decext.
68 */ 68 */
69static struct kobj_attribute caps_start_attribute = 69static struct kobj_attribute caps_start_attribute =
70 __ATTR(caps_start, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 70 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
71static struct kobj_attribute caps_stop_attribute = 71static struct kobj_attribute caps_stop_attribute =
72 __ATTR(caps_stop, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 72 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
73static struct kobj_attribute pitch_attribute = 73static struct kobj_attribute pitch_attribute =
74 __ATTR(pitch, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 74 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
75static struct kobj_attribute punct_attribute = 75static struct kobj_attribute punct_attribute =
76 __ATTR(punct, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 76 __ATTR(punct, 0644, spk_var_show, spk_var_store);
77static struct kobj_attribute rate_attribute = 77static struct kobj_attribute rate_attribute =
78 __ATTR(rate, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 78 __ATTR(rate, 0644, spk_var_show, spk_var_store);
79static struct kobj_attribute voice_attribute = 79static struct kobj_attribute voice_attribute =
80 __ATTR(voice, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 80 __ATTR(voice, 0644, spk_var_show, spk_var_store);
81static struct kobj_attribute vol_attribute = 81static struct kobj_attribute vol_attribute =
82 __ATTR(vol, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 82 __ATTR(vol, 0644, spk_var_show, spk_var_store);
83 83
84static struct kobj_attribute delay_time_attribute = 84static struct kobj_attribute delay_time_attribute =
85 __ATTR(delay_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 85 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
86static struct kobj_attribute direct_attribute = 86static struct kobj_attribute direct_attribute =
87 __ATTR(direct, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 87 __ATTR(direct, 0644, spk_var_show, spk_var_store);
88static struct kobj_attribute full_time_attribute = 88static struct kobj_attribute full_time_attribute =
89 __ATTR(full_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 89 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
90static struct kobj_attribute jiffy_delta_attribute = 90static struct kobj_attribute jiffy_delta_attribute =
91 __ATTR(jiffy_delta, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 91 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
92static struct kobj_attribute trigger_time_attribute = 92static struct kobj_attribute trigger_time_attribute =
93 __ATTR(trigger_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 93 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
94 94
95/* 95/*
96 * Create a group of attributes so that we can create and destroy them all 96 * Create a group of attributes so that we can create and destroy them all
@@ -226,8 +226,8 @@ static void synth_flush(struct spk_synth *synth)
226 spk_synth_immediate(synth, "\033P;10z\033\\"); 226 spk_synth_immediate(synth, "\033P;10z\033\\");
227} 227}
228 228
229module_param_named(ser, synth_decext.ser, int, S_IRUGO); 229module_param_named(ser, synth_decext.ser, int, 0444);
230module_param_named(start, synth_decext.startup, short, S_IRUGO); 230module_param_named(start, synth_decext.startup, short, 0444);
231 231
232MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 232MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
233MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 233MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_decpc.c b/drivers/staging/speakup/speakup_decpc.c
index d6479bd2163b..6bf38e49a96d 100644
--- a/drivers/staging/speakup/speakup_decpc.c
+++ b/drivers/staging/speakup/speakup_decpc.c
@@ -85,8 +85,8 @@
85#define CTRL_io_priority 0x0c00 /* change i/o priority */ 85#define CTRL_io_priority 0x0c00 /* change i/o priority */
86#define CTRL_free_mem 0x0d00 /* get free paragraphs on module */ 86#define CTRL_free_mem 0x0d00 /* get free paragraphs on module */
87#define CTRL_get_lang 0x0e00 /* return bit mask of loaded 87#define CTRL_get_lang 0x0e00 /* return bit mask of loaded
88 * languages 88 * languages
89 */ 89 */
90#define CMD_test 0x2000 /* self-test request */ 90#define CMD_test 0x2000 /* self-test request */
91#define TEST_mask 0x0F00 /* isolate test field */ 91#define TEST_mask 0x0F00 /* isolate test field */
92#define TEST_null 0x0000 /* no test requested */ 92#define TEST_null 0x0000 /* no test requested */
@@ -161,30 +161,30 @@ static struct var_t vars[] = {
161 * These attributes will appear in /sys/accessibility/speakup/decpc. 161 * These attributes will appear in /sys/accessibility/speakup/decpc.
162 */ 162 */
163static struct kobj_attribute caps_start_attribute = 163static struct kobj_attribute caps_start_attribute =
164 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 164 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
165static struct kobj_attribute caps_stop_attribute = 165static struct kobj_attribute caps_stop_attribute =
166 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 166 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
167static struct kobj_attribute pitch_attribute = 167static struct kobj_attribute pitch_attribute =
168 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 168 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
169static struct kobj_attribute punct_attribute = 169static struct kobj_attribute punct_attribute =
170 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 170 __ATTR(punct, 0644, spk_var_show, spk_var_store);
171static struct kobj_attribute rate_attribute = 171static struct kobj_attribute rate_attribute =
172 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 172 __ATTR(rate, 0644, spk_var_show, spk_var_store);
173static struct kobj_attribute voice_attribute = 173static struct kobj_attribute voice_attribute =
174 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 174 __ATTR(voice, 0644, spk_var_show, spk_var_store);
175static struct kobj_attribute vol_attribute = 175static struct kobj_attribute vol_attribute =
176 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 176 __ATTR(vol, 0644, spk_var_show, spk_var_store);
177 177
178static struct kobj_attribute delay_time_attribute = 178static struct kobj_attribute delay_time_attribute =
179 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 179 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
180static struct kobj_attribute direct_attribute = 180static struct kobj_attribute direct_attribute =
181 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 181 __ATTR(direct, 0644, spk_var_show, spk_var_store);
182static struct kobj_attribute full_time_attribute = 182static struct kobj_attribute full_time_attribute =
183 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 183 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
184static struct kobj_attribute jiffy_delta_attribute = 184static struct kobj_attribute jiffy_delta_attribute =
185 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 185 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
186static struct kobj_attribute trigger_time_attribute = 186static struct kobj_attribute trigger_time_attribute =
187 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 187 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
188 188
189/* 189/*
190 * Create a group of attributes so that we can create and destroy them all 190 * Create a group of attributes so that we can create and destroy them all
@@ -486,7 +486,7 @@ static void dtpc_release(void)
486 speakup_info.port_tts = 0; 486 speakup_info.port_tts = 0;
487} 487}
488 488
489module_param_named(start, synth_dec_pc.startup, short, S_IRUGO); 489module_param_named(start, synth_dec_pc.startup, short, 0444);
490 490
491MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 491MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
492 492
diff --git a/drivers/staging/speakup/speakup_dectlk.c b/drivers/staging/speakup/speakup_dectlk.c
index 764656759fbf..26036050cdb2 100644
--- a/drivers/staging/speakup/speakup_dectlk.c
+++ b/drivers/staging/speakup/speakup_dectlk.c
@@ -66,30 +66,30 @@ static struct var_t vars[] = {
66 * These attributes will appear in /sys/accessibility/speakup/dectlk. 66 * These attributes will appear in /sys/accessibility/speakup/dectlk.
67 */ 67 */
68static struct kobj_attribute caps_start_attribute = 68static struct kobj_attribute caps_start_attribute =
69 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 69 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
70static struct kobj_attribute caps_stop_attribute = 70static struct kobj_attribute caps_stop_attribute =
71 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 71 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
72static struct kobj_attribute pitch_attribute = 72static struct kobj_attribute pitch_attribute =
73 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 73 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
74static struct kobj_attribute punct_attribute = 74static struct kobj_attribute punct_attribute =
75 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 75 __ATTR(punct, 0644, spk_var_show, spk_var_store);
76static struct kobj_attribute rate_attribute = 76static struct kobj_attribute rate_attribute =
77 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 77 __ATTR(rate, 0644, spk_var_show, spk_var_store);
78static struct kobj_attribute voice_attribute = 78static struct kobj_attribute voice_attribute =
79 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 79 __ATTR(voice, 0644, spk_var_show, spk_var_store);
80static struct kobj_attribute vol_attribute = 80static struct kobj_attribute vol_attribute =
81 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 81 __ATTR(vol, 0644, spk_var_show, spk_var_store);
82 82
83static struct kobj_attribute delay_time_attribute = 83static struct kobj_attribute delay_time_attribute =
84 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 84 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
85static struct kobj_attribute direct_attribute = 85static struct kobj_attribute direct_attribute =
86 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 86 __ATTR(direct, 0644, spk_var_show, spk_var_store);
87static struct kobj_attribute full_time_attribute = 87static struct kobj_attribute full_time_attribute =
88 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 88 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
89static struct kobj_attribute jiffy_delta_attribute = 89static struct kobj_attribute jiffy_delta_attribute =
90 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 90 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
91static struct kobj_attribute trigger_time_attribute = 91static struct kobj_attribute trigger_time_attribute =
92 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 92 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
93 93
94/* 94/*
95 * Create a group of attributes so that we can create and destroy them all 95 * Create a group of attributes so that we can create and destroy them all
@@ -295,8 +295,8 @@ static void synth_flush(struct spk_synth *synth)
295 spk_serial_out(SYNTH_CLEAR); 295 spk_serial_out(SYNTH_CLEAR);
296} 296}
297 297
298module_param_named(ser, synth_dectlk.ser, int, S_IRUGO); 298module_param_named(ser, synth_dectlk.ser, int, 0444);
299module_param_named(start, synth_dectlk.startup, short, S_IRUGO); 299module_param_named(start, synth_dectlk.startup, short, 0444);
300 300
301MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 301MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
302MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 302MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_dtlk.c b/drivers/staging/speakup/speakup_dtlk.c
index 38aa4013bf62..e2bf20806d8d 100644
--- a/drivers/staging/speakup/speakup_dtlk.c
+++ b/drivers/staging/speakup/speakup_dtlk.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3* this version considerably modified by David Borowski, david575@rogers.com 3 * this version considerably modified by David Borowski, david575@rogers.com
4 * 4 *
5 * Copyright (C) 1998-99 Kirk Reiser. 5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 6 * Copyright (C) 2003 David Borowski.
@@ -63,34 +63,34 @@ static struct var_t vars[] = {
63 * These attributes will appear in /sys/accessibility/speakup/dtlk. 63 * These attributes will appear in /sys/accessibility/speakup/dtlk.
64 */ 64 */
65static struct kobj_attribute caps_start_attribute = 65static struct kobj_attribute caps_start_attribute =
66 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 66 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
67static struct kobj_attribute caps_stop_attribute = 67static struct kobj_attribute caps_stop_attribute =
68 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 68 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
69static struct kobj_attribute freq_attribute = 69static struct kobj_attribute freq_attribute =
70 __ATTR(freq, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 70 __ATTR(freq, 0644, spk_var_show, spk_var_store);
71static struct kobj_attribute pitch_attribute = 71static struct kobj_attribute pitch_attribute =
72 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 72 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
73static struct kobj_attribute punct_attribute = 73static struct kobj_attribute punct_attribute =
74 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 74 __ATTR(punct, 0644, spk_var_show, spk_var_store);
75static struct kobj_attribute rate_attribute = 75static struct kobj_attribute rate_attribute =
76 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 76 __ATTR(rate, 0644, spk_var_show, spk_var_store);
77static struct kobj_attribute tone_attribute = 77static struct kobj_attribute tone_attribute =
78 __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 78 __ATTR(tone, 0644, spk_var_show, spk_var_store);
79static struct kobj_attribute voice_attribute = 79static struct kobj_attribute voice_attribute =
80 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 80 __ATTR(voice, 0644, spk_var_show, spk_var_store);
81static struct kobj_attribute vol_attribute = 81static struct kobj_attribute vol_attribute =
82 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 82 __ATTR(vol, 0644, spk_var_show, spk_var_store);
83 83
84static struct kobj_attribute delay_time_attribute = 84static struct kobj_attribute delay_time_attribute =
85 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 85 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
86static struct kobj_attribute direct_attribute = 86static struct kobj_attribute direct_attribute =
87 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 87 __ATTR(direct, 0644, spk_var_show, spk_var_store);
88static struct kobj_attribute full_time_attribute = 88static struct kobj_attribute full_time_attribute =
89 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 89 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
90static struct kobj_attribute jiffy_delta_attribute = 90static struct kobj_attribute jiffy_delta_attribute =
91 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 91 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
92static struct kobj_attribute trigger_time_attribute = 92static struct kobj_attribute trigger_time_attribute =
93 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 93 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
94 94
95/* 95/*
96 * Create a group of attributes so that we can create and destroy them all 96 * Create a group of attributes so that we can create and destroy them all
@@ -378,8 +378,8 @@ static void dtlk_release(void)
378 speakup_info.port_tts = 0; 378 speakup_info.port_tts = 0;
379} 379}
380 380
381module_param_named(port, port_forced, int, S_IRUGO); 381module_param_named(port, port_forced, int, 0444);
382module_param_named(start, synth_dtlk.startup, short, S_IRUGO); 382module_param_named(start, synth_dtlk.startup, short, 0444);
383 383
384MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing)."); 384MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
385MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 385MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_dtlk.h b/drivers/staging/speakup/speakup_dtlk.h
index 46d885fcfb20..b3b3cfc3db07 100644
--- a/drivers/staging/speakup/speakup_dtlk.h
+++ b/drivers/staging/speakup/speakup_dtlk.h
@@ -24,11 +24,11 @@
24 * usec later. 24 * usec later.
25 */ 25 */
26#define TTS_ALMOST_FULL 0x08 /* mask for AF bit: When set to 1, 26#define TTS_ALMOST_FULL 0x08 /* mask for AF bit: When set to 1,
27 * indicates that less than 300 bytes 27 * indicates that less than 300 bytes
28 * are available in the TTS input 28 * are available in the TTS input
29 * buffer. AF is always 0 in the PCM, 29 * buffer. AF is always 0 in the PCM,
30 * TGN and CVSD modes. 30 * TGN and CVSD modes.
31 */ 31 */
32#define TTS_ALMOST_EMPTY 0x04 /* mask for AE bit: When set to 1, 32#define TTS_ALMOST_EMPTY 0x04 /* mask for AE bit: When set to 1,
33 * indicates that less than 300 bytes 33 * indicates that less than 300 bytes
34 * are remaining in DoubleTalk's input 34 * are remaining in DoubleTalk's input
diff --git a/drivers/staging/speakup/speakup_dummy.c b/drivers/staging/speakup/speakup_dummy.c
index 87d2a8002b47..cb7cef30c124 100644
--- a/drivers/staging/speakup/speakup_dummy.c
+++ b/drivers/staging/speakup/speakup_dummy.c
@@ -42,28 +42,28 @@ static struct var_t vars[] = {
42 * These attributes will appear in /sys/accessibility/speakup/dummy. 42 * These attributes will appear in /sys/accessibility/speakup/dummy.
43 */ 43 */
44static struct kobj_attribute caps_start_attribute = 44static struct kobj_attribute caps_start_attribute =
45 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 45 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
46static struct kobj_attribute caps_stop_attribute = 46static struct kobj_attribute caps_stop_attribute =
47 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 47 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
48static struct kobj_attribute pitch_attribute = 48static struct kobj_attribute pitch_attribute =
49 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 49 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
50static struct kobj_attribute rate_attribute = 50static struct kobj_attribute rate_attribute =
51 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 51 __ATTR(rate, 0644, spk_var_show, spk_var_store);
52static struct kobj_attribute tone_attribute = 52static struct kobj_attribute tone_attribute =
53 __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 53 __ATTR(tone, 0644, spk_var_show, spk_var_store);
54static struct kobj_attribute vol_attribute = 54static struct kobj_attribute vol_attribute =
55 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 55 __ATTR(vol, 0644, spk_var_show, spk_var_store);
56 56
57static struct kobj_attribute delay_time_attribute = 57static struct kobj_attribute delay_time_attribute =
58 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 58 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
59static struct kobj_attribute direct_attribute = 59static struct kobj_attribute direct_attribute =
60 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 60 __ATTR(direct, 0644, spk_var_show, spk_var_store);
61static struct kobj_attribute full_time_attribute = 61static struct kobj_attribute full_time_attribute =
62 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 62 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
63static struct kobj_attribute jiffy_delta_attribute = 63static struct kobj_attribute jiffy_delta_attribute =
64 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 64 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
65static struct kobj_attribute trigger_time_attribute = 65static struct kobj_attribute trigger_time_attribute =
66 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 66 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
67 67
68/* 68/*
69 * Create a group of attributes so that we can create and destroy them all 69 * Create a group of attributes so that we can create and destroy them all
@@ -119,8 +119,8 @@ static struct spk_synth synth_dummy = {
119 }, 119 },
120}; 120};
121 121
122module_param_named(ser, synth_dummy.ser, int, S_IRUGO); 122module_param_named(ser, synth_dummy.ser, int, 0444);
123module_param_named(start, synth_dummy.startup, short, S_IRUGO); 123module_param_named(start, synth_dummy.startup, short, 0444);
124 124
125MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 125MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
126MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 126MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_keypc.c b/drivers/staging/speakup/speakup_keypc.c
index 5e2170bf4a8b..10f4964782e2 100644
--- a/drivers/staging/speakup/speakup_keypc.c
+++ b/drivers/staging/speakup/speakup_keypc.c
@@ -55,24 +55,24 @@ static struct var_t vars[] = {
55 * These attributes will appear in /sys/accessibility/speakup/keypc. 55 * These attributes will appear in /sys/accessibility/speakup/keypc.
56 */ 56 */
57static struct kobj_attribute caps_start_attribute = 57static struct kobj_attribute caps_start_attribute =
58 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 58 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
59static struct kobj_attribute caps_stop_attribute = 59static struct kobj_attribute caps_stop_attribute =
60 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 60 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
61static struct kobj_attribute pitch_attribute = 61static struct kobj_attribute pitch_attribute =
62 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 62 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
63static struct kobj_attribute rate_attribute = 63static struct kobj_attribute rate_attribute =
64 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 64 __ATTR(rate, 0644, spk_var_show, spk_var_store);
65 65
66static struct kobj_attribute delay_time_attribute = 66static struct kobj_attribute delay_time_attribute =
67 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 67 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
68static struct kobj_attribute direct_attribute = 68static struct kobj_attribute direct_attribute =
69 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 69 __ATTR(direct, 0644, spk_var_show, spk_var_store);
70static struct kobj_attribute full_time_attribute = 70static struct kobj_attribute full_time_attribute =
71 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 71 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
72static struct kobj_attribute jiffy_delta_attribute = 72static struct kobj_attribute jiffy_delta_attribute =
73 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 73 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
74static struct kobj_attribute trigger_time_attribute = 74static struct kobj_attribute trigger_time_attribute =
75 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 75 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
76 76
77/* 77/*
78 * Create a group of attributes so that we can create and destroy them all 78 * Create a group of attributes so that we can create and destroy them all
@@ -309,8 +309,8 @@ static void keynote_release(void)
309 synth_port = 0; 309 synth_port = 0;
310} 310}
311 311
312module_param_named(port, port_forced, int, S_IRUGO); 312module_param_named(port, port_forced, int, 0444);
313module_param_named(start, synth_keypc.startup, short, S_IRUGO); 313module_param_named(start, synth_keypc.startup, short, 0444);
314 314
315MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing)."); 315MODULE_PARM_DESC(port, "Set the port for the synthesizer (override probing).");
316MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 316MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_ltlk.c b/drivers/staging/speakup/speakup_ltlk.c
index b474e8b65f9a..9d22198a0339 100644
--- a/drivers/staging/speakup/speakup_ltlk.c
+++ b/drivers/staging/speakup/speakup_ltlk.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca> 2 * originally written by: Kirk Reiser <kirk@braille.uwo.ca>
3* this version considerably modified by David Borowski, david575@rogers.com 3 * this version considerably modified by David Borowski, david575@rogers.com
4 * 4 *
5 * Copyright (C) 1998-99 Kirk Reiser. 5 * Copyright (C) 1998-99 Kirk Reiser.
6 * Copyright (C) 2003 David Borowski. 6 * Copyright (C) 2003 David Borowski.
@@ -46,34 +46,34 @@ static struct var_t vars[] = {
46 * These attributes will appear in /sys/accessibility/speakup/ltlk. 46 * These attributes will appear in /sys/accessibility/speakup/ltlk.
47 */ 47 */
48static struct kobj_attribute caps_start_attribute = 48static struct kobj_attribute caps_start_attribute =
49 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 49 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
50static struct kobj_attribute caps_stop_attribute = 50static struct kobj_attribute caps_stop_attribute =
51 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 51 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
52static struct kobj_attribute freq_attribute = 52static struct kobj_attribute freq_attribute =
53 __ATTR(freq, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 53 __ATTR(freq, 0644, spk_var_show, spk_var_store);
54static struct kobj_attribute pitch_attribute = 54static struct kobj_attribute pitch_attribute =
55 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 55 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
56static struct kobj_attribute punct_attribute = 56static struct kobj_attribute punct_attribute =
57 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 57 __ATTR(punct, 0644, spk_var_show, spk_var_store);
58static struct kobj_attribute rate_attribute = 58static struct kobj_attribute rate_attribute =
59 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 59 __ATTR(rate, 0644, spk_var_show, spk_var_store);
60static struct kobj_attribute tone_attribute = 60static struct kobj_attribute tone_attribute =
61 __ATTR(tone, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 61 __ATTR(tone, 0644, spk_var_show, spk_var_store);
62static struct kobj_attribute voice_attribute = 62static struct kobj_attribute voice_attribute =
63 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 63 __ATTR(voice, 0644, spk_var_show, spk_var_store);
64static struct kobj_attribute vol_attribute = 64static struct kobj_attribute vol_attribute =
65 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 65 __ATTR(vol, 0644, spk_var_show, spk_var_store);
66 66
67static struct kobj_attribute delay_time_attribute = 67static struct kobj_attribute delay_time_attribute =
68 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 68 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
69static struct kobj_attribute direct_attribute = 69static struct kobj_attribute direct_attribute =
70 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 70 __ATTR(direct, 0644, spk_var_show, spk_var_store);
71static struct kobj_attribute full_time_attribute = 71static struct kobj_attribute full_time_attribute =
72 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 72 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
73static struct kobj_attribute jiffy_delta_attribute = 73static struct kobj_attribute jiffy_delta_attribute =
74 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 74 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
75static struct kobj_attribute trigger_time_attribute = 75static struct kobj_attribute trigger_time_attribute =
76 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 76 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
77 77
78/* 78/*
79 * Create a group of attributes so that we can create and destroy them all 79 * Create a group of attributes so that we can create and destroy them all
@@ -165,8 +165,8 @@ static int synth_probe(struct spk_synth *synth)
165 return failed; 165 return failed;
166} 166}
167 167
168module_param_named(ser, synth_ltlk.ser, int, S_IRUGO); 168module_param_named(ser, synth_ltlk.ser, int, 0444);
169module_param_named(start, synth_ltlk.startup, short, S_IRUGO); 169module_param_named(start, synth_ltlk.startup, short, 0444);
170 170
171MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 171MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
172MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 172MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
index ed3e4282f41c..ff68a384f9c2 100644
--- a/drivers/staging/speakup/speakup_soft.c
+++ b/drivers/staging/speakup/speakup_soft.c
@@ -58,41 +58,41 @@ static struct var_t vars[] = {
58/* These attributes will appear in /sys/accessibility/speakup/soft. */ 58/* These attributes will appear in /sys/accessibility/speakup/soft. */
59 59
60static struct kobj_attribute caps_start_attribute = 60static struct kobj_attribute caps_start_attribute =
61 __ATTR(caps_start, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 61 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
62static struct kobj_attribute caps_stop_attribute = 62static struct kobj_attribute caps_stop_attribute =
63 __ATTR(caps_stop, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 63 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
64static struct kobj_attribute freq_attribute = 64static struct kobj_attribute freq_attribute =
65 __ATTR(freq, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 65 __ATTR(freq, 0644, spk_var_show, spk_var_store);
66static struct kobj_attribute pitch_attribute = 66static struct kobj_attribute pitch_attribute =
67 __ATTR(pitch, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 67 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
68static struct kobj_attribute punct_attribute = 68static struct kobj_attribute punct_attribute =
69 __ATTR(punct, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 69 __ATTR(punct, 0644, spk_var_show, spk_var_store);
70static struct kobj_attribute rate_attribute = 70static struct kobj_attribute rate_attribute =
71 __ATTR(rate, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 71 __ATTR(rate, 0644, spk_var_show, spk_var_store);
72static struct kobj_attribute tone_attribute = 72static struct kobj_attribute tone_attribute =
73 __ATTR(tone, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 73 __ATTR(tone, 0644, spk_var_show, spk_var_store);
74static struct kobj_attribute voice_attribute = 74static struct kobj_attribute voice_attribute =
75 __ATTR(voice, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 75 __ATTR(voice, 0644, spk_var_show, spk_var_store);
76static struct kobj_attribute vol_attribute = 76static struct kobj_attribute vol_attribute =
77 __ATTR(vol, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 77 __ATTR(vol, 0644, spk_var_show, spk_var_store);
78 78
79/* 79/*
80 * We should uncomment the following definition, when we agree on a 80 * We should uncomment the following definition, when we agree on a
81 * method of passing a language designation to the software synthesizer. 81 * method of passing a language designation to the software synthesizer.
82 * static struct kobj_attribute lang_attribute = 82 * static struct kobj_attribute lang_attribute =
83 * __ATTR(lang, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store); 83 * __ATTR(lang, 0644, spk_var_show, spk_var_store);
84 */ 84 */
85 85
86static struct kobj_attribute delay_time_attribute = 86static struct kobj_attribute delay_time_attribute =
87 __ATTR(delay_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 87 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
88static struct kobj_attribute direct_attribute = 88static struct kobj_attribute direct_attribute =
89 __ATTR(direct, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 89 __ATTR(direct, 0644, spk_var_show, spk_var_store);
90static struct kobj_attribute full_time_attribute = 90static struct kobj_attribute full_time_attribute =
91 __ATTR(full_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 91 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
92static struct kobj_attribute jiffy_delta_attribute = 92static struct kobj_attribute jiffy_delta_attribute =
93 __ATTR(jiffy_delta, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 93 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
94static struct kobj_attribute trigger_time_attribute = 94static struct kobj_attribute trigger_time_attribute =
95 __ATTR(trigger_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 95 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
96 96
97/* 97/*
98 * Create a group of attributes so that we can create and destroy them all 98 * Create a group of attributes so that we can create and destroy them all
@@ -340,7 +340,7 @@ static int softsynth_is_alive(struct spk_synth *synth)
340 return 0; 340 return 0;
341} 341}
342 342
343module_param_named(start, synth_soft.startup, short, S_IRUGO); 343module_param_named(start, synth_soft.startup, short, 0444);
344 344
345MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 345MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
346 346
diff --git a/drivers/staging/speakup/speakup_spkout.c b/drivers/staging/speakup/speakup_spkout.c
index 586890908826..143fadabfe6c 100644
--- a/drivers/staging/speakup/speakup_spkout.c
+++ b/drivers/staging/speakup/speakup_spkout.c
@@ -43,30 +43,30 @@ static struct var_t vars[] = {
43/* These attributes will appear in /sys/accessibility/speakup/spkout. */ 43/* These attributes will appear in /sys/accessibility/speakup/spkout. */
44 44
45static struct kobj_attribute caps_start_attribute = 45static struct kobj_attribute caps_start_attribute =
46 __ATTR(caps_start, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 46 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
47static struct kobj_attribute caps_stop_attribute = 47static struct kobj_attribute caps_stop_attribute =
48 __ATTR(caps_stop, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 48 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
49static struct kobj_attribute pitch_attribute = 49static struct kobj_attribute pitch_attribute =
50 __ATTR(pitch, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 50 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
51static struct kobj_attribute punct_attribute = 51static struct kobj_attribute punct_attribute =
52 __ATTR(punct, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 52 __ATTR(punct, 0644, spk_var_show, spk_var_store);
53static struct kobj_attribute rate_attribute = 53static struct kobj_attribute rate_attribute =
54 __ATTR(rate, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 54 __ATTR(rate, 0644, spk_var_show, spk_var_store);
55static struct kobj_attribute tone_attribute = 55static struct kobj_attribute tone_attribute =
56 __ATTR(tone, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 56 __ATTR(tone, 0644, spk_var_show, spk_var_store);
57static struct kobj_attribute vol_attribute = 57static struct kobj_attribute vol_attribute =
58 __ATTR(vol, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 58 __ATTR(vol, 0644, spk_var_show, spk_var_store);
59 59
60static struct kobj_attribute delay_time_attribute = 60static struct kobj_attribute delay_time_attribute =
61 __ATTR(delay_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 61 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
62static struct kobj_attribute direct_attribute = 62static struct kobj_attribute direct_attribute =
63 __ATTR(direct, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 63 __ATTR(direct, 0644, spk_var_show, spk_var_store);
64static struct kobj_attribute full_time_attribute = 64static struct kobj_attribute full_time_attribute =
65 __ATTR(full_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 65 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
66static struct kobj_attribute jiffy_delta_attribute = 66static struct kobj_attribute jiffy_delta_attribute =
67 __ATTR(jiffy_delta, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 67 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
68static struct kobj_attribute trigger_time_attribute = 68static struct kobj_attribute trigger_time_attribute =
69 __ATTR(trigger_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 69 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
70 70
71/* 71/*
72 * Create a group of attributes so that we can create and destroy them all 72 * Create a group of attributes so that we can create and destroy them all
@@ -135,8 +135,8 @@ static void synth_flush(struct spk_synth *synth)
135 outb(SYNTH_CLEAR, speakup_info.port_tts); 135 outb(SYNTH_CLEAR, speakup_info.port_tts);
136} 136}
137 137
138module_param_named(ser, synth_spkout.ser, int, S_IRUGO); 138module_param_named(ser, synth_spkout.ser, int, 0444);
139module_param_named(start, synth_spkout.startup, short, S_IRUGO); 139module_param_named(start, synth_spkout.startup, short, 0444);
140 140
141MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 141MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
142MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 142MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/speakup_txprt.c b/drivers/staging/speakup/speakup_txprt.c
index b3d2cfd20ac8..aa2f338d15d8 100644
--- a/drivers/staging/speakup/speakup_txprt.c
+++ b/drivers/staging/speakup/speakup_txprt.c
@@ -39,28 +39,28 @@ static struct var_t vars[] = {
39/* These attributes will appear in /sys/accessibility/speakup/txprt. */ 39/* These attributes will appear in /sys/accessibility/speakup/txprt. */
40 40
41static struct kobj_attribute caps_start_attribute = 41static struct kobj_attribute caps_start_attribute =
42 __ATTR(caps_start, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 42 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
43static struct kobj_attribute caps_stop_attribute = 43static struct kobj_attribute caps_stop_attribute =
44 __ATTR(caps_stop, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 44 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
45static struct kobj_attribute pitch_attribute = 45static struct kobj_attribute pitch_attribute =
46 __ATTR(pitch, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 46 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
47static struct kobj_attribute rate_attribute = 47static struct kobj_attribute rate_attribute =
48 __ATTR(rate, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 48 __ATTR(rate, 0644, spk_var_show, spk_var_store);
49static struct kobj_attribute tone_attribute = 49static struct kobj_attribute tone_attribute =
50 __ATTR(tone, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 50 __ATTR(tone, 0644, spk_var_show, spk_var_store);
51static struct kobj_attribute vol_attribute = 51static struct kobj_attribute vol_attribute =
52 __ATTR(vol, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 52 __ATTR(vol, 0644, spk_var_show, spk_var_store);
53 53
54static struct kobj_attribute delay_time_attribute = 54static struct kobj_attribute delay_time_attribute =
55 __ATTR(delay_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 55 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
56static struct kobj_attribute direct_attribute = 56static struct kobj_attribute direct_attribute =
57 __ATTR(direct, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 57 __ATTR(direct, 0644, spk_var_show, spk_var_store);
58static struct kobj_attribute full_time_attribute = 58static struct kobj_attribute full_time_attribute =
59 __ATTR(full_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 59 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
60static struct kobj_attribute jiffy_delta_attribute = 60static struct kobj_attribute jiffy_delta_attribute =
61 __ATTR(jiffy_delta, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 61 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
62static struct kobj_attribute trigger_time_attribute = 62static struct kobj_attribute trigger_time_attribute =
63 __ATTR(trigger_time, S_IWUSR | S_IRUGO, spk_var_show, spk_var_store); 63 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
64 64
65/* 65/*
66 * Create a group of attributes so that we can create and destroy them all 66 * Create a group of attributes so that we can create and destroy them all
@@ -116,8 +116,8 @@ static struct spk_synth synth_txprt = {
116 }, 116 },
117}; 117};
118 118
119module_param_named(ser, synth_txprt.ser, int, S_IRUGO); 119module_param_named(ser, synth_txprt.ser, int, 0444);
120module_param_named(start, synth_txprt.startup, short, S_IRUGO); 120module_param_named(start, synth_txprt.startup, short, 0444);
121 121
122MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based)."); 122MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
123MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded."); 123MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
diff --git a/drivers/staging/speakup/spk_priv.h b/drivers/staging/speakup/spk_priv.h
index 98c4b6f0344a..d5aa41d82122 100644
--- a/drivers/staging/speakup/spk_priv.h
+++ b/drivers/staging/speakup/spk_priv.h
@@ -64,8 +64,8 @@ void spk_synth_flush(struct spk_synth *synth);
64int spk_synth_is_alive_nop(struct spk_synth *synth); 64int spk_synth_is_alive_nop(struct spk_synth *synth);
65int spk_synth_is_alive_restart(struct spk_synth *synth); 65int spk_synth_is_alive_restart(struct spk_synth *synth);
66void synth_printf(const char *buf, ...); 66void synth_printf(const char *buf, ...);
67int synth_request_region(u_long, u_long); 67int synth_request_region(unsigned long start, unsigned long n);
68int synth_release_region(u_long, u_long); 68int synth_release_region(unsigned long start, unsigned long n);
69int synth_add(struct spk_synth *in_synth); 69int synth_add(struct spk_synth *in_synth);
70void synth_remove(struct spk_synth *in_synth); 70void synth_remove(struct spk_synth *in_synth);
71 71
diff --git a/drivers/staging/unisys/include/channel.h b/drivers/staging/unisys/include/channel.h
index 259ef6487959..1c95302f7f1b 100644
--- a/drivers/staging/unisys/include/channel.h
+++ b/drivers/staging/unisys/include/channel.h
@@ -21,11 +21,11 @@
21#include <linux/uuid.h> 21#include <linux/uuid.h>
22 22
23/* 23/*
24* Whenever this file is changed a corresponding change must be made in 24 * Whenever this file is changed a corresponding change must be made in
25* the Console/ServicePart/visordiag_early/supervisor_channel.h file 25 * the Console/ServicePart/visordiag_early/supervisor_channel.h file
26* which is needed for Linux kernel compiles. These two files must be 26 * which is needed for Linux kernel compiles. These two files must be
27* in sync. 27 * in sync.
28*/ 28 */
29 29
30/* define the following to prevent include nesting in kernel header 30/* define the following to prevent include nesting in kernel header
31 * files of similar abbreviated content 31 * files of similar abbreviated content
@@ -310,82 +310,82 @@ static inline int spar_check_channel_server(uuid_le typeuuid, char *name,
310} 310}
311 311
312/* 312/*
313* Routine Description: 313 * Routine Description:
314* Tries to insert the prebuilt signal pointed to by pSignal into the nth 314 * Tries to insert the prebuilt signal pointed to by pSignal into the nth
315* Queue of the Channel pointed to by pChannel 315 * Queue of the Channel pointed to by pChannel
316* 316 *
317* Parameters: 317 * Parameters:
318* pChannel: (IN) points to the IO Channel 318 * pChannel: (IN) points to the IO Channel
319* Queue: (IN) nth Queue of the IO Channel 319 * Queue: (IN) nth Queue of the IO Channel
320* pSignal: (IN) pointer to the signal 320 * pSignal: (IN) pointer to the signal
321* 321 *
322* Assumptions: 322 * Assumptions:
323* - pChannel, Queue and pSignal are valid. 323 * - pChannel, Queue and pSignal are valid.
324* - If insertion fails due to a full queue, the caller will determine the 324 * - If insertion fails due to a full queue, the caller will determine the
325* retry policy (e.g. wait & try again, report an error, etc.). 325 * retry policy (e.g. wait & try again, report an error, etc.).
326* 326 *
327* Return value: 1 if the insertion succeeds, 0 if the queue was 327 * Return value: 1 if the insertion succeeds, 0 if the queue was
328* full. 328 * full.
329*/ 329 */
330 330
331unsigned char spar_signal_insert(struct channel_header __iomem *ch, u32 queue, 331unsigned char spar_signal_insert(struct channel_header __iomem *ch, u32 queue,
332 void *sig); 332 void *sig);
333 333
334/* 334/*
335* Routine Description: 335 * Routine Description:
336* Removes one signal from Channel pChannel's nth Queue at the 336 * Removes one signal from Channel pChannel's nth Queue at the
337* time of the call and copies it into the memory pointed to by 337 * time of the call and copies it into the memory pointed to by
338* pSignal. 338 * pSignal.
339* 339 *
340* Parameters: 340 * Parameters:
341* pChannel: (IN) points to the IO Channel 341 * pChannel: (IN) points to the IO Channel
342* Queue: (IN) nth Queue of the IO Channel 342 * Queue: (IN) nth Queue of the IO Channel
343* pSignal: (IN) pointer to where the signals are to be copied 343 * pSignal: (IN) pointer to where the signals are to be copied
344* 344 *
345* Assumptions: 345 * Assumptions:
346* - pChannel and Queue are valid. 346 * - pChannel and Queue are valid.
347* - pSignal points to a memory area large enough to hold queue's SignalSize 347 * - pSignal points to a memory area large enough to hold queue's SignalSize
348* 348 *
349* Return value: 1 if the removal succeeds, 0 if the queue was 349 * Return value: 1 if the removal succeeds, 0 if the queue was
350* empty. 350 * empty.
351*/ 351 */
352 352
353unsigned char spar_signal_remove(struct channel_header __iomem *ch, u32 queue, 353unsigned char spar_signal_remove(struct channel_header __iomem *ch, u32 queue,
354 void *sig); 354 void *sig);
355 355
356/* 356/*
357* Routine Description: 357 * Routine Description:
358* Removes all signals present in Channel pChannel's nth Queue at the 358 * Removes all signals present in Channel pChannel's nth Queue at the
359* time of the call and copies them into the memory pointed to by 359 * time of the call and copies them into the memory pointed to by
360* pSignal. Returns the # of signals copied as the value of the routine. 360 * pSignal. Returns the # of signals copied as the value of the routine.
361* 361 *
362* Parameters: 362 * Parameters:
363* pChannel: (IN) points to the IO Channel 363 * pChannel: (IN) points to the IO Channel
364* Queue: (IN) nth Queue of the IO Channel 364 * Queue: (IN) nth Queue of the IO Channel
365* pSignal: (IN) pointer to where the signals are to be copied 365 * pSignal: (IN) pointer to where the signals are to be copied
366* 366 *
367* Assumptions: 367 * Assumptions:
368* - pChannel and Queue are valid. 368 * - pChannel and Queue are valid.
369* - pSignal points to a memory area large enough to hold Queue's MaxSignals 369 * - pSignal points to a memory area large enough to hold Queue's MaxSignals
370* # of signals, each of which is Queue's SignalSize. 370 * # of signals, each of which is Queue's SignalSize.
371* 371 *
372* Return value: 372 * Return value:
373* # of signals copied. 373 * # of signals copied.
374*/ 374 */
375unsigned int spar_signal_remove_all(struct channel_header *ch, u32 queue, 375unsigned int spar_signal_remove_all(struct channel_header *ch, u32 queue,
376 void *sig); 376 void *sig);
377 377
378/* 378/*
379* Routine Description: 379 * Routine Description:
380* Determine whether a signal queue is empty. 380 * Determine whether a signal queue is empty.
381* 381 *
382* Parameters: 382 * Parameters:
383* pChannel: (IN) points to the IO Channel 383 * pChannel: (IN) points to the IO Channel
384* Queue: (IN) nth Queue of the IO Channel 384 * Queue: (IN) nth Queue of the IO Channel
385* 385 *
386* Return value: 386 * Return value:
387* 1 if the signal queue is empty, 0 otherwise. 387 * 1 if the signal queue is empty, 0 otherwise.
388*/ 388 */
389unsigned char spar_signalqueue_empty(struct channel_header __iomem *ch, 389unsigned char spar_signalqueue_empty(struct channel_header __iomem *ch,
390 u32 queue); 390 u32 queue);
391 391
diff --git a/drivers/staging/unisys/visorbus/controlvmchannel.h b/drivers/staging/unisys/visorbus/controlvmchannel.h
index f0bfc4ded892..859345243afe 100644
--- a/drivers/staging/unisys/visorbus/controlvmchannel.h
+++ b/drivers/staging/unisys/visorbus/controlvmchannel.h
@@ -43,8 +43,6 @@
43 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID, \ 43 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID, \
44 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE) 44 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE)
45 45
46#define MAX_SERIAL_NUM 32
47
48/* Defines for various channel queues */ 46/* Defines for various channel queues */
49#define CONTROLVM_QUEUE_REQUEST 0 47#define CONTROLVM_QUEUE_REQUEST 0
50#define CONTROLVM_QUEUE_RESPONSE 1 48#define CONTROLVM_QUEUE_RESPONSE 1
@@ -436,26 +434,6 @@ struct spar_controlvm_channel_protocol {
436 struct controlvm_message saved_crash_msg[CONTROLVM_CRASHMSG_MAX]; 434 struct controlvm_message saved_crash_msg[CONTROLVM_CRASHMSG_MAX];
437}; 435};
438 436
439/* Offsets for VM channel attributes */
440#define VM_CH_REQ_QUEUE_OFFSET \
441 offsetof(struct spar_controlvm_channel_protocol, request_queue)
442#define VM_CH_RESP_QUEUE_OFFSET \
443 offsetof(struct spar_controlvm_channel_protocol, response_queue)
444#define VM_CH_EVENT_QUEUE_OFFSET \
445 offsetof(struct spar_controlvm_channel_protocol, event_queue)
446#define VM_CH_ACK_QUEUE_OFFSET \
447 offsetof(struct spar_controlvm_channel_protocol, event_ack_queue)
448#define VM_CH_REQ_MSG_OFFSET \
449 offsetof(struct spar_controlvm_channel_protocol, request_msg)
450#define VM_CH_RESP_MSG_OFFSET \
451 offsetof(struct spar_controlvm_channel_protocol, response_msg)
452#define VM_CH_EVENT_MSG_OFFSET \
453 offsetof(struct spar_controlvm_channel_protocol, event_msg)
454#define VM_CH_ACK_MSG_OFFSET \
455 offsetof(struct spar_controlvm_channel_protocol, event_ack_msg)
456#define VM_CH_CRASH_MSG_OFFSET \
457 offsetof(struct spar_controlvm_channel_protocol, saved_crash_msg)
458
459/* The following header will be located at the beginning of PayloadVmOffset for 437/* The following header will be located at the beginning of PayloadVmOffset for
460 * various ControlVm commands. The receiver of a ControlVm command with a 438 * various ControlVm commands. The receiver of a ControlVm command with a
461 * PayloadVmOffset will dereference this address and then use connection_offset, 439 * PayloadVmOffset will dereference this address and then use connection_offset,
@@ -484,56 +462,55 @@ struct spar_controlvm_parameters_header {
484 462
485/* General Errors------------------------------------------------------[0-99] */ 463/* General Errors------------------------------------------------------[0-99] */
486#define CONTROLVM_RESP_SUCCESS 0 464#define CONTROLVM_RESP_SUCCESS 0
487#define CONTROLVM_RESP_ERROR_ALREADY_DONE 1 465#define CONTROLVM_RESP_ALREADY_DONE 1
488#define CONTROLVM_RESP_ERROR_IOREMAP_FAILED 2 466#define CONTROLVM_RESP_IOREMAP_FAILED 2
489#define CONTROLVM_RESP_ERROR_KMALLOC_FAILED 3 467#define CONTROLVM_RESP_KMALLOC_FAILED 3
490#define CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN 4 468#define CONTROLVM_RESP_ID_UNKNOWN 4
491#define CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT 5 469#define CONTROLVM_RESP_ID_INVALID_FOR_CLIENT 5
492 470
493/* CONTROLVM_INIT_CHIPSET-------------------------------------------[100-199] */ 471/* CONTROLVM_INIT_CHIPSET-------------------------------------------[100-199] */
494#define CONTROLVM_RESP_ERROR_CLIENT_SWITCHCOUNT_NONZERO 100 472#define CONTROLVM_RESP_CLIENT_SWITCHCOUNT_NONZERO 100
495#define CONTROLVM_RESP_ERROR_EXPECTED_CHIPSET_INIT 101 473#define CONTROLVM_RESP_EXPECTED_CHIPSET_INIT 101
496 474
497/* Maximum Limit----------------------------------------------------[200-299] */ 475/* Maximum Limit----------------------------------------------------[200-299] */
498#define CONTROLVM_RESP_ERROR_MAX_BUSES 201 /* BUS_CREATE */ 476#define CONTROLVM_RESP_ERROR_MAX_BUSES 201 /* BUS_CREATE */
499#define CONTROLVM_RESP_ERROR_MAX_DEVICES 202 /* DEVICE_CREATE */ 477#define CONTROLVM_RESP_ERROR_MAX_DEVICES 202 /* DEVICE_CREATE */
500/* Payload and Parameter Related------------------------------------[400-499] */ 478/* Payload and Parameter Related------------------------------------[400-499] */
501#define CONTROLVM_RESP_ERROR_PAYLOAD_INVALID 400 /* SWITCH_ATTACHEXTPORT, 479#define CONTROLVM_RESP_PAYLOAD_INVALID 400 /* SWITCH_ATTACHEXTPORT,
502 * DEVICE_CONFIGURE 480 * DEVICE_CONFIGURE
503 */ 481 */
504#define CONTROLVM_RESP_ERROR_INITIATOR_PARAMETER_INVALID 401 /* Multiple */ 482#define CONTROLVM_RESP_INITIATOR_PARAMETER_INVALID 401 /* Multiple */
505#define CONTROLVM_RESP_ERROR_TARGET_PARAMETER_INVALID 402 /* DEVICE_CONFIGURE */ 483#define CONTROLVM_RESP_TARGET_PARAMETER_INVALID 402 /* DEVICE_CONFIGURE */
506#define CONTROLVM_RESP_ERROR_CLIENT_PARAMETER_INVALID 403 /* DEVICE_CONFIGURE */ 484#define CONTROLVM_RESP_CLIENT_PARAMETER_INVALID 403 /* DEVICE_CONFIGURE */
507/* Specified[Packet Structure] Value-------------------------------[500-599] */ 485/* Specified[Packet Structure] Value-------------------------------[500-599] */
508#define CONTROLVM_RESP_ERROR_BUS_INVALID 500 /* SWITCH_ATTACHINTPORT, 486#define CONTROLVM_RESP_BUS_INVALID 500 /* SWITCH_ATTACHINTPORT,
509 * BUS_CONFIGURE, 487 * BUS_CONFIGURE,
510 * DEVICE_CREATE, 488 * DEVICE_CREATE,
511 * DEVICE_CONFIG 489 * DEVICE_CONFIG
512 * DEVICE_DESTROY 490 * DEVICE_DESTROY
513 */ 491 */
514#define CONTROLVM_RESP_ERROR_DEVICE_INVALID 501 /* SWITCH_ATTACHINTPORT */ 492#define CONTROLVM_RESP_DEVICE_INVALID 501 /* SWITCH_ATTACHINTPORT */
515 /* DEVICE_CREATE, 493 /* DEVICE_CREATE,
516 * DEVICE_CONFIGURE, 494 * DEVICE_CONFIGURE,
517 * DEVICE_DESTROY 495 * DEVICE_DESTROY
518 */ 496 */
519#define CONTROLVM_RESP_ERROR_CHANNEL_INVALID 502 /* DEVICE_CREATE, 497#define CONTROLVM_RESP_CHANNEL_INVALID 502 /* DEVICE_CREATE,
520 * DEVICE_CONFIGURE 498 * DEVICE_CONFIGURE
521 */ 499 */
522/* Partition Driver Callback Interface----------------------[600-699] */ 500/* Partition Driver Callback Interface----------------------[600-699] */
523#define CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE 604 /* BUS_CREATE, 501#define CONTROLVM_RESP_VIRTPCI_DRIVER_FAILURE 604 /* BUS_CREATE,
524 * BUS_DESTROY, 502 * BUS_DESTROY,
525 * DEVICE_CREATE, 503 * DEVICE_CREATE,
526 * DEVICE_DESTROY 504 * DEVICE_DESTROY
527 */ 505 */
528/* Unable to invoke VIRTPCI callback */ 506/* Unable to invoke VIRTPCI callback */
529#define CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR 605 507#define CONTROLVM_RESP_VIRTPCI_DRIVER_CALLBACK_ERROR 605 /* BUS_CREATE,
530 /* BUS_CREATE, 508 * BUS_DESTROY,
531 * BUS_DESTROY, 509 * DEVICE_CREATE,
532 * DEVICE_CREATE, 510 * DEVICE_DESTROY
533 * DEVICE_DESTROY 511 */
534 */
535/* VIRTPCI Callback returned error */ 512/* VIRTPCI Callback returned error */
536#define CONTROLVM_RESP_ERROR_GENERIC_DRIVER_CALLBACK_ERROR 606 513#define CONTROLVM_RESP_GENERIC_DRIVER_CALLBACK_ERROR 606
537 /* SWITCH_ATTACHEXTPORT, 514 /* SWITCH_ATTACHEXTPORT,
538 * SWITCH_DETACHEXTPORT 515 * SWITCH_DETACHEXTPORT
539 * DEVICE_CONFIGURE 516 * DEVICE_CONFIGURE
@@ -543,19 +520,19 @@ struct spar_controlvm_parameters_header {
543/* Bus Related------------------------------------------------------[700-799] */ 520/* Bus Related------------------------------------------------------[700-799] */
544#define CONTROLVM_RESP_ERROR_BUS_DEVICE_ATTACHED 700 /* BUS_DESTROY */ 521#define CONTROLVM_RESP_ERROR_BUS_DEVICE_ATTACHED 700 /* BUS_DESTROY */
545/* Channel Related--------------------------------------------------[800-899] */ 522/* Channel Related--------------------------------------------------[800-899] */
546#define CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN 800 /* GET_CHANNELINFO, 523#define CONTROLVM_RESP_CHANNEL_TYPE_UNKNOWN 800 /* GET_CHANNELINFO,
547 * DEVICE_DESTROY 524 * DEVICE_DESTROY
548 */ 525 */
549#define CONTROLVM_RESP_ERROR_CHANNEL_SIZE_TOO_SMALL 801 /* DEVICE_CREATE */ 526#define CONTROLVM_RESP_CHANNEL_SIZE_TOO_SMALL 801 /* DEVICE_CREATE */
550/* Chipset Shutdown Related---------------------------------------[1000-1099] */ 527/* Chipset Shutdown Related---------------------------------------[1000-1099] */
551#define CONTROLVM_RESP_ERROR_CHIPSET_SHUTDOWN_FAILED 1000 528#define CONTROLVM_RESP_CHIPSET_SHUTDOWN_FAILED 1000
552#define CONTROLVM_RESP_ERROR_CHIPSET_SHUTDOWN_ALREADY_ACTIVE 1001 529#define CONTROLVM_RESP_CHIPSET_SHUTDOWN_ALREADY_ACTIVE 1001
553 530
554/* Chipset Stop Related-------------------------------------------[1100-1199] */ 531/* Chipset Stop Related-------------------------------------------[1100-1199] */
555#define CONTROLVM_RESP_ERROR_CHIPSET_STOP_FAILED_BUS 1100 532#define CONTROLVM_RESP_CHIPSET_STOP_FAILED_BUS 1100
556#define CONTROLVM_RESP_ERROR_CHIPSET_STOP_FAILED_SWITCH 1101 533#define CONTROLVM_RESP_CHIPSET_STOP_FAILED_SWITCH 1101
557 534
558/* Device Related-------------------------------------------------[1400-1499] */ 535/* Device Related-------------------------------------------------[1400-1499] */
559#define CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT 1400 536#define CONTROLVM_RESP_DEVICE_UDEV_TIMEOUT 1400
560 537
561#endif /* __CONTROLVMCHANNEL_H__ */ 538#endif /* __CONTROLVMCHANNEL_H__ */
diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c
index 3457ef338e1e..55f29ae8e015 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -49,7 +49,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
49 49
50 vdev = to_visor_device(dev); 50 vdev = to_visor_device(dev);
51 guid = visorchannel_get_uuid(vdev->visorchannel); 51 guid = visorchannel_get_uuid(vdev->visorchannel);
52 return snprintf(buf, PAGE_SIZE, "visorbus:%pUl\n", &guid); 52 return sprintf(buf, "visorbus:%pUl\n", &guid);
53} 53}
54static DEVICE_ATTR_RO(modalias); 54static DEVICE_ATTR_RO(modalias);
55 55
@@ -187,8 +187,8 @@ static ssize_t physaddr_show(struct device *dev, struct device_attribute *attr,
187 187
188 if (!vdev->visorchannel) 188 if (!vdev->visorchannel)
189 return 0; 189 return 0;
190 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 190 return sprintf(buf, "0x%llx\n",
191 visorchannel_get_physaddr(vdev->visorchannel)); 191 visorchannel_get_physaddr(vdev->visorchannel));
192} 192}
193static DEVICE_ATTR_RO(physaddr); 193static DEVICE_ATTR_RO(physaddr);
194 194
@@ -199,7 +199,7 @@ static ssize_t nbytes_show(struct device *dev, struct device_attribute *attr,
199 199
200 if (!vdev->visorchannel) 200 if (!vdev->visorchannel)
201 return 0; 201 return 0;
202 return snprintf(buf, PAGE_SIZE, "0x%lx\n", 202 return sprintf(buf, "0x%lx\n",
203 visorchannel_get_nbytes(vdev->visorchannel)); 203 visorchannel_get_nbytes(vdev->visorchannel));
204} 204}
205static DEVICE_ATTR_RO(nbytes); 205static DEVICE_ATTR_RO(nbytes);
@@ -211,8 +211,8 @@ static ssize_t clientpartition_show(struct device *dev,
211 211
212 if (!vdev->visorchannel) 212 if (!vdev->visorchannel)
213 return 0; 213 return 0;
214 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 214 return sprintf(buf, "0x%llx\n",
215 visorchannel_get_clientpartition(vdev->visorchannel)); 215 visorchannel_get_clientpartition(vdev->visorchannel));
216} 216}
217static DEVICE_ATTR_RO(clientpartition); 217static DEVICE_ATTR_RO(clientpartition);
218 218
@@ -224,8 +224,8 @@ static ssize_t typeguid_show(struct device *dev, struct device_attribute *attr,
224 224
225 if (!vdev->visorchannel) 225 if (!vdev->visorchannel)
226 return 0; 226 return 0;
227 return snprintf(buf, PAGE_SIZE, "%s\n", 227 return sprintf(buf, "%s\n",
228 visorchannel_id(vdev->visorchannel, typeid)); 228 visorchannel_id(vdev->visorchannel, typeid));
229} 229}
230static DEVICE_ATTR_RO(typeguid); 230static DEVICE_ATTR_RO(typeguid);
231 231
@@ -237,8 +237,8 @@ static ssize_t zoneguid_show(struct device *dev, struct device_attribute *attr,
237 237
238 if (!vdev->visorchannel) 238 if (!vdev->visorchannel)
239 return 0; 239 return 0;
240 return snprintf(buf, PAGE_SIZE, "%s\n", 240 return sprintf(buf, "%s\n",
241 visorchannel_zoneid(vdev->visorchannel, zoneid)); 241 visorchannel_zoneid(vdev->visorchannel, zoneid));
242} 242}
243static DEVICE_ATTR_RO(zoneguid); 243static DEVICE_ATTR_RO(zoneguid);
244 244
@@ -257,7 +257,7 @@ static ssize_t typename_show(struct device *dev, struct device_attribute *attr,
257 if (!i) 257 if (!i)
258 return 0; 258 return 0;
259 drv = to_visor_driver(xdrv); 259 drv = to_visor_driver(xdrv);
260 return snprintf(buf, PAGE_SIZE, "%s\n", drv->channel_types[i - 1].name); 260 return sprintf(buf, "%s\n", drv->channel_types[i - 1].name);
261} 261}
262static DEVICE_ATTR_RO(typename); 262static DEVICE_ATTR_RO(typename);
263 263
@@ -296,7 +296,7 @@ static ssize_t partition_handle_show(struct device *dev,
296 struct visor_device *vdev = to_visor_device(dev); 296 struct visor_device *vdev = to_visor_device(dev);
297 u64 handle = visorchannel_get_clientpartition(vdev->visorchannel); 297 u64 handle = visorchannel_get_clientpartition(vdev->visorchannel);
298 298
299 return snprintf(buf, PAGE_SIZE, "0x%llx\n", handle); 299 return sprintf(buf, "0x%llx\n", handle);
300} 300}
301static DEVICE_ATTR_RO(partition_handle); 301static DEVICE_ATTR_RO(partition_handle);
302 302
@@ -305,7 +305,7 @@ static ssize_t partition_guid_show(struct device *dev,
305 char *buf) { 305 char *buf) {
306 struct visor_device *vdev = to_visor_device(dev); 306 struct visor_device *vdev = to_visor_device(dev);
307 307
308 return snprintf(buf, PAGE_SIZE, "{%pUb}\n", &vdev->partition_uuid); 308 return sprintf(buf, "{%pUb}\n", &vdev->partition_uuid);
309} 309}
310static DEVICE_ATTR_RO(partition_guid); 310static DEVICE_ATTR_RO(partition_guid);
311 311
@@ -314,7 +314,7 @@ static ssize_t partition_name_show(struct device *dev,
314 char *buf) { 314 char *buf) {
315 struct visor_device *vdev = to_visor_device(dev); 315 struct visor_device *vdev = to_visor_device(dev);
316 316
317 return snprintf(buf, PAGE_SIZE, "%s\n", vdev->name); 317 return sprintf(buf, "%s\n", vdev->name);
318} 318}
319static DEVICE_ATTR_RO(partition_name); 319static DEVICE_ATTR_RO(partition_name);
320 320
@@ -324,7 +324,7 @@ static ssize_t channel_addr_show(struct device *dev,
324 struct visor_device *vdev = to_visor_device(dev); 324 struct visor_device *vdev = to_visor_device(dev);
325 u64 addr = visorchannel_get_physaddr(vdev->visorchannel); 325 u64 addr = visorchannel_get_physaddr(vdev->visorchannel);
326 326
327 return snprintf(buf, PAGE_SIZE, "0x%llx\n", addr); 327 return sprintf(buf, "0x%llx\n", addr);
328} 328}
329static DEVICE_ATTR_RO(channel_addr); 329static DEVICE_ATTR_RO(channel_addr);
330 330
@@ -334,7 +334,7 @@ static ssize_t channel_bytes_show(struct device *dev,
334 struct visor_device *vdev = to_visor_device(dev); 334 struct visor_device *vdev = to_visor_device(dev);
335 u64 nbytes = visorchannel_get_nbytes(vdev->visorchannel); 335 u64 nbytes = visorchannel_get_nbytes(vdev->visorchannel);
336 336
337 return snprintf(buf, PAGE_SIZE, "0x%llx\n", nbytes); 337 return sprintf(buf, "0x%llx\n", nbytes);
338} 338}
339static DEVICE_ATTR_RO(channel_bytes); 339static DEVICE_ATTR_RO(channel_bytes);
340 340
@@ -438,8 +438,7 @@ dev_periodic_work(unsigned long __opaque)
438 struct visor_device *dev = (struct visor_device *)__opaque; 438 struct visor_device *dev = (struct visor_device *)__opaque;
439 struct visor_driver *drv = to_visor_driver(dev->device.driver); 439 struct visor_driver *drv = to_visor_driver(dev->device.driver);
440 440
441 if (drv->channel_interrupt) 441 drv->channel_interrupt(dev);
442 drv->channel_interrupt(dev);
443 mod_timer(&dev->timer, jiffies + POLLJIFFIES_NORMALCHANNEL); 442 mod_timer(&dev->timer, jiffies + POLLJIFFIES_NORMALCHANNEL);
444} 443}
445 444
@@ -561,6 +560,13 @@ EXPORT_SYMBOL_GPL(visorbus_write_channel);
561void 560void
562visorbus_enable_channel_interrupts(struct visor_device *dev) 561visorbus_enable_channel_interrupts(struct visor_device *dev)
563{ 562{
563 struct visor_driver *drv = to_visor_driver(dev->device.driver);
564
565 if (!drv->channel_interrupt) {
566 dev_err(&dev->device, "%s no interrupt function!\n", __func__);
567 return;
568 }
569
564 dev_start_periodic_work(dev); 570 dev_start_periodic_work(dev);
565} 571}
566EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts); 572EXPORT_SYMBOL_GPL(visorbus_enable_channel_interrupts);
@@ -617,9 +623,7 @@ create_visor_device(struct visor_device *dev)
617 dev->device.release = visorbus_release_device; 623 dev->device.release = visorbus_release_device;
618 /* keep a reference just for us (now 2) */ 624 /* keep a reference just for us (now 2) */
619 get_device(&dev->device); 625 get_device(&dev->device);
620 init_timer(&dev->timer); 626 setup_timer(&dev->timer, dev_periodic_work, (unsigned long)dev);
621 dev->timer.data = (unsigned long)(dev);
622 dev->timer.function = dev_periodic_work;
623 627
624 /* 628 /*
625 * bus_id must be a unique name with respect to this bus TYPE 629 * bus_id must be a unique name with respect to this bus TYPE
@@ -984,7 +988,7 @@ create_bus_instance(struct visor_device *dev)
984 goto err_hdr_info; 988 goto err_hdr_info;
985 } 989 }
986 dev->debugfs_client_bus_info = 990 dev->debugfs_client_bus_info =
987 debugfs_create_file("client_bus_info", S_IRUSR | S_IRGRP, 991 debugfs_create_file("client_bus_info", 0440,
988 dev->debugfs_dir, dev, 992 dev->debugfs_dir, dev,
989 &client_bus_info_debugfs_fops); 993 &client_bus_info_debugfs_fops);
990 if (!dev->debugfs_client_bus_info) { 994 if (!dev->debugfs_client_bus_info) {
@@ -1337,10 +1341,10 @@ visorbus_exit(void)
1337 debugfs_remove_recursive(visorbus_debugfs_dir); 1341 debugfs_remove_recursive(visorbus_debugfs_dir);
1338} 1342}
1339 1343
1340module_param_named(forcematch, visorbus_forcematch, int, S_IRUGO); 1344module_param_named(forcematch, visorbus_forcematch, int, 0444);
1341MODULE_PARM_DESC(visorbus_forcematch, 1345MODULE_PARM_DESC(visorbus_forcematch,
1342 "1 to force a successful dev <--> drv match"); 1346 "1 to force a successful dev <--> drv match");
1343 1347
1344module_param_named(forcenomatch, visorbus_forcenomatch, int, S_IRUGO); 1348module_param_named(forcenomatch, visorbus_forcenomatch, int, 0444);
1345MODULE_PARM_DESC(visorbus_forcenomatch, 1349MODULE_PARM_DESC(visorbus_forcenomatch,
1346 "1 to force an UNsuccessful dev <--> drv match"); 1350 "1 to force an UNsuccessful dev <--> drv match");
diff --git a/drivers/staging/unisys/visorbus/visorchannel.c b/drivers/staging/unisys/visorbus/visorchannel.c
index f51a7258bef0..e91febcc6c1e 100644
--- a/drivers/staging/unisys/visorbus/visorchannel.c
+++ b/drivers/staging/unisys/visorbus/visorchannel.c
@@ -45,12 +45,6 @@ struct visorchannel {
45 spinlock_t insert_lock; /* protect head writes in chan_hdr */ 45 spinlock_t insert_lock; /* protect head writes in chan_hdr */
46 spinlock_t remove_lock; /* protect tail writes in chan_hdr */ 46 spinlock_t remove_lock; /* protect tail writes in chan_hdr */
47 47
48 struct {
49 struct signal_queue_header req_queue;
50 struct signal_queue_header rsp_queue;
51 struct signal_queue_header event_queue;
52 struct signal_queue_header ack_queue;
53 } safe_uis_queue;
54 uuid_le type; 48 uuid_le type;
55 uuid_le inst; 49 uuid_le inst;
56}; 50};
diff --git a/drivers/staging/unisys/visorbus/visorchipset.c b/drivers/staging/unisys/visorbus/visorchipset.c
index d7148c351d3f..97778d733e1e 100644
--- a/drivers/staging/unisys/visorbus/visorchipset.c
+++ b/drivers/staging/unisys/visorbus/visorchipset.c
@@ -91,18 +91,6 @@ static struct cdev file_cdev;
91static struct visorchannel **file_controlvm_channel; 91static struct visorchannel **file_controlvm_channel;
92 92
93static struct visorchannel *controlvm_channel; 93static struct visorchannel *controlvm_channel;
94
95/* Manages the request payload in the controlvm channel */
96struct visor_controlvm_payload_info {
97 u8 *ptr; /* pointer to base address of payload pool */
98 u64 offset; /*
99 * offset from beginning of controlvm
100 * channel to beginning of payload * pool
101 */
102 u32 bytes; /* number of bytes in payload pool */
103};
104
105static struct visor_controlvm_payload_info controlvm_payload_info;
106static unsigned long controlvm_payload_bytes_buffered; 94static unsigned long controlvm_payload_bytes_buffered;
107 95
108/* 96/*
@@ -114,60 +102,6 @@ static unsigned long controlvm_payload_bytes_buffered;
114static struct controlvm_message controlvm_pending_msg; 102static struct controlvm_message controlvm_pending_msg;
115static bool controlvm_pending_msg_valid; 103static bool controlvm_pending_msg_valid;
116 104
117/*
118 * This describes a buffer and its current state of transfer (e.g., how many
119 * bytes have already been supplied as putfile data, and how many bytes are
120 * remaining) for a putfile_request.
121 */
122struct putfile_active_buffer {
123 /* a payload from a controlvm message, containing a file data buffer */
124 struct parser_context *parser_ctx;
125 /* points within data area of parser_ctx to next byte of data */
126 size_t bytes_remaining;
127};
128
129#define PUTFILE_REQUEST_SIG 0x0906101302281211
130/*
131 * This identifies a single remote --> local CONTROLVM_TRANSMIT_FILE
132 * conversation. Structs of this type are dynamically linked into
133 * <Putfile_request_list>.
134 */
135struct putfile_request {
136 u64 sig; /* PUTFILE_REQUEST_SIG */
137
138 /* header from original TransmitFile request */
139 struct controlvm_message_header controlvm_header;
140
141 /* link to next struct putfile_request */
142 struct list_head next_putfile_request;
143
144 /*
145 * head of putfile_buffer_entry list, which describes the data to be
146 * supplied as putfile data;
147 * - this list is added to when controlvm messages come in that supply
148 * file data
149 * - this list is removed from via the hotplug program that is actually
150 * consuming these buffers to write as file data
151 */
152 struct list_head input_buffer_list;
153 spinlock_t req_list_lock; /* lock for input_buffer_list */
154
155 /* waiters for input_buffer_list to go non-empty */
156 wait_queue_head_t input_buffer_wq;
157
158 /* data not yet read within current putfile_buffer_entry */
159 struct putfile_active_buffer active_buf;
160
161 /*
162 * <0 = failed, 0 = in-progress, >0 = successful;
163 * note that this must be set with req_list_lock, and if you set <0,
164 * it is your responsibility to also free up all of the other objects
165 * in this struct (like input_buffer_list, active_buf.parser_ctx)
166 * before releasing the lock
167 */
168 int completion_status;
169};
170
171struct parahotplug_request { 105struct parahotplug_request {
172 struct list_head list; 106 struct list_head list;
173 int id; 107 int id;
@@ -188,7 +122,7 @@ static ssize_t toolaction_show(struct device *dev,
188 visorchannel_read(controlvm_channel, 122 visorchannel_read(controlvm_channel,
189 offsetof(struct spar_controlvm_channel_protocol, 123 offsetof(struct spar_controlvm_channel_protocol,
190 tool_action), &tool_action, sizeof(u8)); 124 tool_action), &tool_action, sizeof(u8));
191 return scnprintf(buf, PAGE_SIZE, "%u\n", tool_action); 125 return sprintf(buf, "%u\n", tool_action);
192} 126}
193 127
194static ssize_t toolaction_store(struct device *dev, 128static ssize_t toolaction_store(struct device *dev,
@@ -223,8 +157,7 @@ static ssize_t boottotool_show(struct device *dev,
223 offsetof(struct spar_controlvm_channel_protocol, 157 offsetof(struct spar_controlvm_channel_protocol,
224 efi_spar_ind), &efi_spar_indication, 158 efi_spar_ind), &efi_spar_indication,
225 sizeof(struct efi_spar_indication)); 159 sizeof(struct efi_spar_indication));
226 return scnprintf(buf, PAGE_SIZE, "%u\n", 160 return sprintf(buf, "%u\n", efi_spar_indication.boot_to_tool);
227 efi_spar_indication.boot_to_tool);
228} 161}
229 162
230static ssize_t boottotool_store(struct device *dev, 163static ssize_t boottotool_store(struct device *dev,
@@ -259,7 +192,7 @@ static ssize_t error_show(struct device *dev, struct device_attribute *attr,
259 offsetof(struct spar_controlvm_channel_protocol, 192 offsetof(struct spar_controlvm_channel_protocol,
260 installation_error), 193 installation_error),
261 &error, sizeof(u32)); 194 &error, sizeof(u32));
262 return scnprintf(buf, PAGE_SIZE, "%i\n", error); 195 return sprintf(buf, "%i\n", error);
263} 196}
264 197
265static ssize_t error_store(struct device *dev, struct device_attribute *attr, 198static ssize_t error_store(struct device *dev, struct device_attribute *attr,
@@ -292,7 +225,7 @@ static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
292 offsetof(struct spar_controlvm_channel_protocol, 225 offsetof(struct spar_controlvm_channel_protocol,
293 installation_text_id), 226 installation_text_id),
294 &text_id, sizeof(u32)); 227 &text_id, sizeof(u32));
295 return scnprintf(buf, PAGE_SIZE, "%i\n", text_id); 228 return sprintf(buf, "%i\n", text_id);
296} 229}
297 230
298static ssize_t textid_store(struct device *dev, struct device_attribute *attr, 231static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
@@ -324,7 +257,7 @@ static ssize_t remaining_steps_show(struct device *dev,
324 offsetof(struct spar_controlvm_channel_protocol, 257 offsetof(struct spar_controlvm_channel_protocol,
325 installation_remaining_steps), 258 installation_remaining_steps),
326 &remaining_steps, sizeof(u16)); 259 &remaining_steps, sizeof(u16));
327 return scnprintf(buf, PAGE_SIZE, "%hu\n", remaining_steps); 260 return sprintf(buf, "%hu\n", remaining_steps);
328} 261}
329 262
330static ssize_t remaining_steps_store(struct device *dev, 263static ssize_t remaining_steps_store(struct device *dev,
@@ -353,60 +286,12 @@ parser_id_get(struct parser_context *ctx)
353{ 286{
354 struct spar_controlvm_parameters_header *phdr = NULL; 287 struct spar_controlvm_parameters_header *phdr = NULL;
355 288
356 if (!ctx)
357 return NULL_UUID_LE;
358 phdr = (struct spar_controlvm_parameters_header *)(ctx->data); 289 phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
359 return phdr->id; 290 return phdr->id;
360} 291}
361 292
362/*
363 * Describes the state from the perspective of which controlvm messages have
364 * been received for a bus or device.
365 */
366
367enum PARSER_WHICH_STRING {
368 PARSERSTRING_INITIATOR,
369 PARSERSTRING_TARGET,
370 PARSERSTRING_CONNECTION,
371 PARSERSTRING_NAME, /* TODO: only PARSERSTRING_NAME is used ? */
372};
373
374static void
375parser_param_start(struct parser_context *ctx,
376 enum PARSER_WHICH_STRING which_string)
377{
378 struct spar_controlvm_parameters_header *phdr = NULL;
379
380 if (!ctx)
381 return;
382
383 phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
384 switch (which_string) {
385 case PARSERSTRING_INITIATOR:
386 ctx->curr = ctx->data + phdr->initiator_offset;
387 ctx->bytes_remaining = phdr->initiator_length;
388 break;
389 case PARSERSTRING_TARGET:
390 ctx->curr = ctx->data + phdr->target_offset;
391 ctx->bytes_remaining = phdr->target_length;
392 break;
393 case PARSERSTRING_CONNECTION:
394 ctx->curr = ctx->data + phdr->connection_offset;
395 ctx->bytes_remaining = phdr->connection_length;
396 break;
397 case PARSERSTRING_NAME:
398 ctx->curr = ctx->data + phdr->name_offset;
399 ctx->bytes_remaining = phdr->name_length;
400 break;
401 default:
402 break;
403 }
404}
405
406static void parser_done(struct parser_context *ctx) 293static void parser_done(struct parser_context *ctx)
407{ 294{
408 if (!ctx)
409 return;
410 controlvm_payload_bytes_buffered -= ctx->param_bytes; 295 controlvm_payload_bytes_buffered -= ctx->param_bytes;
411 kfree(ctx); 296 kfree(ctx);
412} 297}
@@ -420,8 +305,6 @@ parser_string_get(struct parser_context *ctx)
420 void *value = NULL; 305 void *value = NULL;
421 int i; 306 int i;
422 307
423 if (!ctx)
424 return NULL;
425 pscan = ctx->curr; 308 pscan = ctx->curr;
426 nscan = ctx->bytes_remaining; 309 nscan = ctx->bytes_remaining;
427 if (nscan == 0) 310 if (nscan == 0)
@@ -444,6 +327,21 @@ parser_string_get(struct parser_context *ctx)
444 return value; 327 return value;
445} 328}
446 329
330static void *
331parser_name_get(struct parser_context *ctx)
332{
333 struct spar_controlvm_parameters_header *phdr = NULL;
334
335 phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
336
337 if (phdr->name_offset + phdr->name_length > ctx->param_bytes)
338 return NULL;
339
340 ctx->curr = ctx->data + phdr->name_offset;
341 ctx->bytes_remaining = phdr->name_length;
342 return parser_string_get(ctx);
343}
344
447struct visor_busdev { 345struct visor_busdev {
448 u32 bus_no; 346 u32 bus_no;
449 u32 dev_no; 347 u32 dev_no;
@@ -521,7 +419,7 @@ chipset_init(struct controlvm_message *inmsg)
521 419
522 POSTCODE_LINUX(CHIPSET_INIT_ENTRY_PC, 0, 0, DIAG_SEVERITY_PRINT); 420 POSTCODE_LINUX(CHIPSET_INIT_ENTRY_PC, 0, 0, DIAG_SEVERITY_PRINT);
523 if (chipset_inited) { 421 if (chipset_inited) {
524 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; 422 rc = -CONTROLVM_RESP_ALREADY_DONE;
525 res = -EIO; 423 res = -EIO;
526 goto out_respond; 424 goto out_respond;
527 } 425 }
@@ -613,27 +511,33 @@ save_crash_message(struct controlvm_message *msg, enum crash_obj_type typ)
613 return err; 511 return err;
614 } 512 }
615 513
616 if (typ == CRASH_BUS) { 514 switch (typ) {
515 case CRASH_DEV:
516 local_crash_msg_offset += sizeof(struct controlvm_message);
617 err = visorchannel_write(controlvm_channel, 517 err = visorchannel_write(controlvm_channel,
618 local_crash_msg_offset, 518 local_crash_msg_offset,
619 msg, 519 msg,
620 sizeof(struct controlvm_message)); 520 sizeof(struct controlvm_message));
621 if (err) { 521 if (err) {
622 POSTCODE_LINUX(SAVE_MSG_BUS_FAILURE_PC, 0, 0, 522 POSTCODE_LINUX(SAVE_MSG_DEV_FAILURE_PC, 0, 0,
623 DIAG_SEVERITY_ERR); 523 DIAG_SEVERITY_ERR);
624 return err; 524 return err;
625 } 525 }
626 } else { 526 break;
627 local_crash_msg_offset += sizeof(struct controlvm_message); 527 case CRASH_BUS:
628 err = visorchannel_write(controlvm_channel, 528 err = visorchannel_write(controlvm_channel,
629 local_crash_msg_offset, 529 local_crash_msg_offset,
630 msg, 530 msg,
631 sizeof(struct controlvm_message)); 531 sizeof(struct controlvm_message));
632 if (err) { 532 if (err) {
633 POSTCODE_LINUX(SAVE_MSG_DEV_FAILURE_PC, 0, 0, 533 POSTCODE_LINUX(SAVE_MSG_BUS_FAILURE_PC, 0, 0,
634 DIAG_SEVERITY_ERR); 534 DIAG_SEVERITY_ERR);
635 return err; 535 return err;
636 } 536 }
537 break;
538 default:
539 pr_info("Invalid crash_obj_type\n");
540 break;
637 } 541 }
638 return 0; 542 return 0;
639} 543}
@@ -722,8 +626,11 @@ bus_create(struct controlvm_message *inmsg)
722 626
723 POSTCODE_LINUX(BUS_CREATE_ENTRY_PC, 0, bus_no, DIAG_SEVERITY_PRINT); 627 POSTCODE_LINUX(BUS_CREATE_ENTRY_PC, 0, bus_no, DIAG_SEVERITY_PRINT);
724 628
725 if (uuid_le_cmp(cmd->create_bus.bus_inst_uuid, spar_siovm_uuid) == 0) 629 if (uuid_le_cmp(cmd->create_bus.bus_inst_uuid, spar_siovm_uuid) == 0) {
726 save_crash_message(inmsg, CRASH_BUS); 630 err = save_crash_message(inmsg, CRASH_BUS);
631 if (err)
632 goto err_free_bus_info;
633 }
727 634
728 if (inmsg->hdr.flags.response_expected == 1) { 635 if (inmsg->hdr.flags.response_expected == 1) {
729 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), 636 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr),
@@ -857,9 +764,10 @@ bus_configure(struct controlvm_message *inmsg,
857 if (err) 764 if (err)
858 goto err_respond; 765 goto err_respond;
859 766
860 bus_info->partition_uuid = parser_id_get(parser_ctx); 767 if (parser_ctx) {
861 parser_param_start(parser_ctx, PARSERSTRING_NAME); 768 bus_info->partition_uuid = parser_id_get(parser_ctx);
862 bus_info->name = parser_string_get(parser_ctx); 769 bus_info->name = parser_name_get(parser_ctx);
770 }
863 771
864 POSTCODE_LINUX(BUS_CONFIGURE_EXIT_PC, 0, bus_no, 772 POSTCODE_LINUX(BUS_CONFIGURE_EXIT_PC, 0, bus_no,
865 DIAG_SEVERITY_PRINT); 773 DIAG_SEVERITY_PRINT);
@@ -874,7 +782,7 @@ err_respond:
874 return err; 782 return err;
875} 783}
876 784
877static void 785static int
878my_device_create(struct controlvm_message *inmsg) 786my_device_create(struct controlvm_message *inmsg)
879{ 787{
880 struct controlvm_message_packet *cmd = &inmsg->cmd; 788 struct controlvm_message_packet *cmd = &inmsg->cmd;
@@ -884,37 +792,37 @@ my_device_create(struct controlvm_message *inmsg)
884 struct visor_device *dev_info = NULL; 792 struct visor_device *dev_info = NULL;
885 struct visor_device *bus_info; 793 struct visor_device *bus_info;
886 struct visorchannel *visorchannel; 794 struct visorchannel *visorchannel;
887 int rc = CONTROLVM_RESP_SUCCESS; 795 int err;
888 796
889 bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL); 797 bus_info = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL);
890 if (!bus_info) { 798 if (!bus_info) {
891 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, 799 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
892 DIAG_SEVERITY_ERR); 800 DIAG_SEVERITY_ERR);
893 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; 801 err = -ENODEV;
894 goto out_respond; 802 goto err_respond;
895 } 803 }
896 804
897 if (bus_info->state.created == 0) { 805 if (bus_info->state.created == 0) {
898 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, 806 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
899 DIAG_SEVERITY_ERR); 807 DIAG_SEVERITY_ERR);
900 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; 808 err = -EINVAL;
901 goto out_respond; 809 goto err_respond;
902 } 810 }
903 811
904 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL); 812 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
905 if (dev_info && (dev_info->state.created == 1)) { 813 if (dev_info && (dev_info->state.created == 1)) {
906 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, 814 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
907 DIAG_SEVERITY_ERR); 815 DIAG_SEVERITY_ERR);
908 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; 816 err = -EEXIST;
909 goto out_respond; 817 goto err_respond;
910 } 818 }
911 819
912 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); 820 dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL);
913 if (!dev_info) { 821 if (!dev_info) {
914 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, 822 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
915 DIAG_SEVERITY_ERR); 823 DIAG_SEVERITY_ERR);
916 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; 824 err = -ENOMEM;
917 goto out_respond; 825 goto err_respond;
918 } 826 }
919 827
920 dev_info->chipset_bus_no = bus_no; 828 dev_info->chipset_bus_no = bus_no;
@@ -936,20 +844,23 @@ my_device_create(struct controlvm_message *inmsg)
936 if (!visorchannel) { 844 if (!visorchannel) {
937 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, 845 POSTCODE_LINUX(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
938 DIAG_SEVERITY_ERR); 846 DIAG_SEVERITY_ERR);
939 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; 847 err = -ENOMEM;
940 goto out_free_dev_info; 848 goto err_free_dev_info;
941 } 849 }
942 dev_info->visorchannel = visorchannel; 850 dev_info->visorchannel = visorchannel;
943 dev_info->channel_type_guid = cmd->create_device.data_type_uuid; 851 dev_info->channel_type_guid = cmd->create_device.data_type_uuid;
944 if (uuid_le_cmp(cmd->create_device.data_type_uuid, 852 if (uuid_le_cmp(cmd->create_device.data_type_uuid,
945 spar_vhba_channel_protocol_uuid) == 0) 853 spar_vhba_channel_protocol_uuid) == 0) {
946 save_crash_message(inmsg, CRASH_DEV); 854 err = save_crash_message(inmsg, CRASH_DEV);
855 if (err)
856 goto err_free_dev_info;
857 }
947 858
948 if (inmsg->hdr.flags.response_expected == 1) { 859 if (inmsg->hdr.flags.response_expected == 1) {
949 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL); 860 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
950 if (!pmsg_hdr) { 861 if (!pmsg_hdr) {
951 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; 862 err = -ENOMEM;
952 goto out_free_dev_info; 863 goto err_free_dev_info;
953 } 864 }
954 865
955 memcpy(pmsg_hdr, &inmsg->hdr, 866 memcpy(pmsg_hdr, &inmsg->hdr,
@@ -960,17 +871,18 @@ my_device_create(struct controlvm_message *inmsg)
960 chipset_device_create(dev_info); 871 chipset_device_create(dev_info);
961 POSTCODE_LINUX(DEVICE_CREATE_EXIT_PC, dev_no, bus_no, 872 POSTCODE_LINUX(DEVICE_CREATE_EXIT_PC, dev_no, bus_no,
962 DIAG_SEVERITY_PRINT); 873 DIAG_SEVERITY_PRINT);
963 return; 874 return 0;
964 875
965out_free_dev_info: 876err_free_dev_info:
966 kfree(dev_info); 877 kfree(dev_info);
967 878
968out_respond: 879err_respond:
969 if (inmsg->hdr.flags.response_expected == 1) 880 if (inmsg->hdr.flags.response_expected == 1)
970 device_responder(inmsg->hdr.id, &inmsg->hdr, rc); 881 device_responder(inmsg->hdr.id, &inmsg->hdr, err);
882 return err;
971} 883}
972 884
973static void 885static int
974my_device_changestate(struct controlvm_message *inmsg) 886my_device_changestate(struct controlvm_message *inmsg)
975{ 887{
976 struct controlvm_message_packet *cmd = &inmsg->cmd; 888 struct controlvm_message_packet *cmd = &inmsg->cmd;
@@ -979,30 +891,30 @@ my_device_changestate(struct controlvm_message *inmsg)
979 u32 dev_no = cmd->device_change_state.dev_no; 891 u32 dev_no = cmd->device_change_state.dev_no;
980 struct spar_segment_state state = cmd->device_change_state.state; 892 struct spar_segment_state state = cmd->device_change_state.state;
981 struct visor_device *dev_info; 893 struct visor_device *dev_info;
982 int rc = CONTROLVM_RESP_SUCCESS; 894 int err;
983 895
984 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL); 896 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
985 if (!dev_info) { 897 if (!dev_info) {
986 POSTCODE_LINUX(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no, 898 POSTCODE_LINUX(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no,
987 DIAG_SEVERITY_ERR); 899 DIAG_SEVERITY_ERR);
988 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; 900 err = -ENODEV;
989 goto err_respond; 901 goto err_respond;
990 } 902 }
991 if (dev_info->state.created == 0) { 903 if (dev_info->state.created == 0) {
992 POSTCODE_LINUX(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no, 904 POSTCODE_LINUX(DEVICE_CHANGESTATE_FAILURE_PC, dev_no, bus_no,
993 DIAG_SEVERITY_ERR); 905 DIAG_SEVERITY_ERR);
994 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; 906 err = -EINVAL;
995 goto err_respond; 907 goto err_respond;
996 } 908 }
997 if (dev_info->pending_msg_hdr) { 909 if (dev_info->pending_msg_hdr) {
998 /* only non-NULL if dev is still waiting on a response */ 910 /* only non-NULL if dev is still waiting on a response */
999 rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT; 911 err = -EIO;
1000 goto err_respond; 912 goto err_respond;
1001 } 913 }
1002 if (inmsg->hdr.flags.response_expected == 1) { 914 if (inmsg->hdr.flags.response_expected == 1) {
1003 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL); 915 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
1004 if (!pmsg_hdr) { 916 if (!pmsg_hdr) {
1005 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; 917 err = -ENOMEM;
1006 goto err_respond; 918 goto err_respond;
1007 } 919 }
1008 920
@@ -1023,15 +935,15 @@ my_device_changestate(struct controlvm_message *inmsg)
1023 * Response will be sent from chipset_device_pause. 935 * Response will be sent from chipset_device_pause.
1024 */ 936 */
1025 chipset_device_pause(dev_info); 937 chipset_device_pause(dev_info);
1026 938 return 0;
1027 return;
1028 939
1029err_respond: 940err_respond:
1030 if (inmsg->hdr.flags.response_expected == 1) 941 if (inmsg->hdr.flags.response_expected == 1)
1031 device_responder(inmsg->hdr.id, &inmsg->hdr, rc); 942 device_responder(inmsg->hdr.id, &inmsg->hdr, err);
943 return err;
1032} 944}
1033 945
1034static void 946static int
1035my_device_destroy(struct controlvm_message *inmsg) 947my_device_destroy(struct controlvm_message *inmsg)
1036{ 948{
1037 struct controlvm_message_packet *cmd = &inmsg->cmd; 949 struct controlvm_message_packet *cmd = &inmsg->cmd;
@@ -1039,27 +951,27 @@ my_device_destroy(struct controlvm_message *inmsg)
1039 u32 bus_no = cmd->destroy_device.bus_no; 951 u32 bus_no = cmd->destroy_device.bus_no;
1040 u32 dev_no = cmd->destroy_device.dev_no; 952 u32 dev_no = cmd->destroy_device.dev_no;
1041 struct visor_device *dev_info; 953 struct visor_device *dev_info;
1042 int rc = CONTROLVM_RESP_SUCCESS; 954 int err;
1043 955
1044 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL); 956 dev_info = visorbus_get_device_by_id(bus_no, dev_no, NULL);
1045 if (!dev_info) { 957 if (!dev_info) {
1046 rc = -CONTROLVM_RESP_ERROR_DEVICE_INVALID; 958 err = -ENODEV;
1047 goto err_respond; 959 goto err_respond;
1048 } 960 }
1049 if (dev_info->state.created == 0) { 961 if (dev_info->state.created == 0) {
1050 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; 962 err = -EINVAL;
1051 goto err_respond; 963 goto err_respond;
1052 } 964 }
1053 965
1054 if (dev_info->pending_msg_hdr) { 966 if (dev_info->pending_msg_hdr) {
1055 /* only non-NULL if dev is still waiting on a response */ 967 /* only non-NULL if dev is still waiting on a response */
1056 rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT; 968 err = -EIO;
1057 goto err_respond; 969 goto err_respond;
1058 } 970 }
1059 if (inmsg->hdr.flags.response_expected == 1) { 971 if (inmsg->hdr.flags.response_expected == 1) {
1060 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL); 972 pmsg_hdr = kzalloc(sizeof(*pmsg_hdr), GFP_KERNEL);
1061 if (!pmsg_hdr) { 973 if (!pmsg_hdr) {
1062 rc = -CONTROLVM_RESP_ERROR_KMALLOC_FAILED; 974 err = -ENOMEM;
1063 goto err_respond; 975 goto err_respond;
1064 } 976 }
1065 977
@@ -1069,107 +981,33 @@ my_device_destroy(struct controlvm_message *inmsg)
1069 } 981 }
1070 982
1071 chipset_device_destroy(dev_info); 983 chipset_device_destroy(dev_info);
1072 return; 984 return 0;
1073 985
1074err_respond: 986err_respond:
1075 if (inmsg->hdr.flags.response_expected == 1) 987 if (inmsg->hdr.flags.response_expected == 1)
1076 device_responder(inmsg->hdr.id, &inmsg->hdr, rc); 988 device_responder(inmsg->hdr.id, &inmsg->hdr, err);
1077} 989 return err;
1078
1079/**
1080 * initialize_controlvm_payload_info() - init controlvm_payload_info struct
1081 * @phys_addr: the physical address of controlvm channel
1082 * @offset: the offset to payload
1083 * @bytes: the size of the payload in bytes
1084 * @info: the returning valid struct
1085 *
1086 * When provided with the physical address of the controlvm channel
1087 * (phys_addr), the offset to the payload area we need to manage
1088 * (offset), and the size of this payload area (bytes), fills in the
1089 * controlvm_payload_info struct.
1090 *
1091 * Return: CONTROLVM_RESP_SUCCESS for success or a negative for failure
1092 */
1093static int
1094initialize_controlvm_payload_info(u64 phys_addr, u64 offset, u32 bytes,
1095 struct visor_controlvm_payload_info *info)
1096{
1097 u8 *payload = NULL;
1098
1099 if (!info)
1100 return -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
1101
1102 if ((offset == 0) || (bytes == 0))
1103 return -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
1104
1105 payload = memremap(phys_addr + offset, bytes, MEMREMAP_WB);
1106 if (!payload)
1107 return -CONTROLVM_RESP_ERROR_IOREMAP_FAILED;
1108
1109 memset(info, 0, sizeof(struct visor_controlvm_payload_info));
1110 info->offset = offset;
1111 info->bytes = bytes;
1112 info->ptr = payload;
1113
1114 return CONTROLVM_RESP_SUCCESS;
1115}
1116
1117static void
1118destroy_controlvm_payload_info(struct visor_controlvm_payload_info *info)
1119{
1120 if (info->ptr) {
1121 memunmap(info->ptr);
1122 info->ptr = NULL;
1123 }
1124 memset(info, 0, sizeof(struct visor_controlvm_payload_info));
1125}
1126
1127static void
1128initialize_controlvm_payload(void)
1129{
1130 u64 phys_addr = visorchannel_get_physaddr(controlvm_channel);
1131 u64 payload_offset = 0;
1132 u32 payload_bytes = 0;
1133
1134 if (visorchannel_read(controlvm_channel,
1135 offsetof(struct spar_controlvm_channel_protocol,
1136 request_payload_offset),
1137 &payload_offset, sizeof(payload_offset)) < 0) {
1138 POSTCODE_LINUX(CONTROLVM_INIT_FAILURE_PC, 0, 0,
1139 DIAG_SEVERITY_ERR);
1140 return;
1141 }
1142 if (visorchannel_read(controlvm_channel,
1143 offsetof(struct spar_controlvm_channel_protocol,
1144 request_payload_bytes),
1145 &payload_bytes, sizeof(payload_bytes)) < 0) {
1146 POSTCODE_LINUX(CONTROLVM_INIT_FAILURE_PC, 0, 0,
1147 DIAG_SEVERITY_ERR);
1148 return;
1149 }
1150 initialize_controlvm_payload_info(phys_addr,
1151 payload_offset, payload_bytes,
1152 &controlvm_payload_info);
1153} 990}
1154 991
1155/* 992/*
1156 * The general parahotplug flow works as follows. The visorchipset 993 * The general parahotplug flow works as follows. The visorchipset receives
1157 * driver receives a DEVICE_CHANGESTATE message from Command 994 * a DEVICE_CHANGESTATE message from Command specifying a physical device
1158 * specifying a physical device to enable or disable. The CONTROLVM 995 * to enable or disable. The CONTROLVM message handler calls
1159 * message handler calls parahotplug_process_message, which then adds 996 * parahotplug_process_message, which then adds the message to a global list
1160 * the message to a global list and kicks off a udev event which 997 * and kicks off a udev event which causes a user level script to enable or
1161 * causes a user level script to enable or disable the specified 998 * disable the specified device. The udev script then writes to
1162 * device. The udev script then writes to 999 * /sys/devices/platform/visorchipset/parahotplug, which causes the
1163 * /proc/visorchipset/parahotplug, which causes parahotplug_proc_write 1000 * parahotplug store functions to get called, at which point the
1164 * to get called, at which point the appropriate CONTROLVM message is 1001 * appropriate CONTROLVM message is retrieved from the list and responded
1165 * retrieved from the list and responded to. 1002 * to.
1166 */ 1003 */
1167 1004
1168#define PARAHOTPLUG_TIMEOUT_MS 2000 1005#define PARAHOTPLUG_TIMEOUT_MS 2000
1169 1006
1170/** 1007/**
1171 * parahotplug_next_id() - generate unique int to match an outstanding CONTROLVM 1008 * parahotplug_next_id() - generate unique int to match an outstanding
1172 * message with a udev script /proc response 1009 * CONTROLVM message with a udev script /sys
1010 * response
1173 * 1011 *
1174 * Return: a unique integer value 1012 * Return: a unique integer value
1175 */ 1013 */
@@ -1236,7 +1074,7 @@ static DEFINE_SPINLOCK(parahotplug_request_list_lock); /* lock for above */
1236 * @id: the id of the request 1074 * @id: the id of the request
1237 * @active: indicates whether the request is assigned to active partition 1075 * @active: indicates whether the request is assigned to active partition
1238 * 1076 *
1239 * Called from the /proc handler, which means the user script has 1077 * Called from the /sys handler, which means the user script has
1240 * finished the enable/disable. Find the matching identifier, and 1078 * finished the enable/disable. Find the matching identifier, and
1241 * respond to the CONTROLVM message with success. 1079 * respond to the CONTROLVM message with success.
1242 * 1080 *
@@ -1433,7 +1271,7 @@ parahotplug_process_message(struct controlvm_message *inmsg)
1433 * 1271 *
1434 * devices are automatically enabled at 1272 * devices are automatically enabled at
1435 * initialization. 1273 * initialization.
1436 */ 1274 */
1437 parahotplug_request_kickoff(req); 1275 parahotplug_request_kickoff(req);
1438 controlvm_respond_physdev_changestate 1276 controlvm_respond_physdev_changestate
1439 (&inmsg->hdr, 1277 (&inmsg->hdr,
@@ -1455,22 +1293,33 @@ parahotplug_process_message(struct controlvm_message *inmsg)
1455 } 1293 }
1456} 1294}
1457 1295
1458/** 1296/*
1459 * visorchipset_chipset_ready() - sends chipset_ready action 1297 * chipset_ready_uevent() - sends chipset_ready action
1460 * 1298 *
1461 * Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset. 1299 * Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1462 * 1300 *
1463 * Return: CONTROLVM_RESP_SUCCESS 1301 * Return: 0 on success, negative on failure
1464 */ 1302 */
1465static int 1303static int
1466visorchipset_chipset_ready(void) 1304chipset_ready_uevent(struct controlvm_message_header *msg_hdr)
1467{ 1305{
1468 kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_ONLINE); 1306 kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_ONLINE);
1469 return CONTROLVM_RESP_SUCCESS; 1307
1308 if (msg_hdr->flags.response_expected)
1309 return controlvm_respond(msg_hdr, CONTROLVM_RESP_SUCCESS);
1310
1311 return 0;
1470} 1312}
1471 1313
1314/*
1315 * chipset_selftest_uevent() - sends chipset_selftest action
1316 *
1317 * Send ACTION=online for DEVPATH=/sys/devices/platform/visorchipset.
1318 *
1319 * Return: 0 on success, negative on failure
1320 */
1472static int 1321static int
1473visorchipset_chipset_selftest(void) 1322chipset_selftest_uevent(struct controlvm_message_header *msg_hdr)
1474{ 1323{
1475 char env_selftest[20]; 1324 char env_selftest[20];
1476 char *envp[] = { env_selftest, NULL }; 1325 char *envp[] = { env_selftest, NULL };
@@ -1478,54 +1327,29 @@ visorchipset_chipset_selftest(void)
1478 sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1); 1327 sprintf(env_selftest, "SPARSP_SELFTEST=%d", 1);
1479 kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE, 1328 kobject_uevent_env(&visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
1480 envp); 1329 envp);
1481 return CONTROLVM_RESP_SUCCESS; 1330
1331 if (msg_hdr->flags.response_expected)
1332 return controlvm_respond(msg_hdr, CONTROLVM_RESP_SUCCESS);
1333
1334 return 0;
1482} 1335}
1483 1336
1484/** 1337/*
1485 * visorchipset_chipset_notready() - sends chipset_notready action 1338 * chipset_notready_uevent() - sends chipset_notready action
1486 * 1339 *
1487 * Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset. 1340 * Send ACTION=offline for DEVPATH=/sys/devices/platform/visorchipset.
1488 * 1341 *
1489 * Return: CONTROLVM_RESP_SUCCESS 1342 * Return: 0 on success, negative on failure
1490 */ 1343 */
1491static int 1344static int
1492visorchipset_chipset_notready(void) 1345chipset_notready_uevent(struct controlvm_message_header *msg_hdr)
1493{ 1346{
1494 kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_OFFLINE); 1347 kobject_uevent(&visorchipset_platform_device.dev.kobj, KOBJ_OFFLINE);
1495 return CONTROLVM_RESP_SUCCESS;
1496}
1497
1498static void
1499chipset_ready(struct controlvm_message_header *msg_hdr)
1500{
1501 int rc = visorchipset_chipset_ready();
1502 1348
1503 if (rc != CONTROLVM_RESP_SUCCESS)
1504 rc = -rc;
1505 if (msg_hdr->flags.response_expected) 1349 if (msg_hdr->flags.response_expected)
1506 controlvm_respond(msg_hdr, rc); 1350 return controlvm_respond(msg_hdr, CONTROLVM_RESP_SUCCESS);
1507}
1508
1509static void
1510chipset_selftest(struct controlvm_message_header *msg_hdr)
1511{
1512 int rc = visorchipset_chipset_selftest();
1513 1351
1514 if (rc != CONTROLVM_RESP_SUCCESS) 1352 return 0;
1515 rc = -rc;
1516 if (msg_hdr->flags.response_expected)
1517 controlvm_respond(msg_hdr, rc);
1518}
1519
1520static void
1521chipset_notready(struct controlvm_message_header *msg_hdr)
1522{
1523 int rc = visorchipset_chipset_notready();
1524
1525 if (rc != CONTROLVM_RESP_SUCCESS)
1526 rc = -rc;
1527 if (msg_hdr->flags.response_expected)
1528 controlvm_respond(msg_hdr, rc);
1529} 1353}
1530 1354
1531static inline unsigned int 1355static inline unsigned int
@@ -1846,8 +1670,7 @@ parser_init_byte_stream(u64 addr, u32 bytes, bool local, bool *retry)
1846 int allocbytes = sizeof(struct parser_context) + bytes; 1670 int allocbytes = sizeof(struct parser_context) + bytes;
1847 struct parser_context *ctx; 1671 struct parser_context *ctx;
1848 1672
1849 if (retry) 1673 *retry = false;
1850 *retry = false;
1851 1674
1852 /* 1675 /*
1853 * alloc an 0 extra byte to ensure payload is 1676 * alloc an 0 extra byte to ensure payload is
@@ -1856,14 +1679,12 @@ parser_init_byte_stream(u64 addr, u32 bytes, bool local, bool *retry)
1856 allocbytes++; 1679 allocbytes++;
1857 if ((controlvm_payload_bytes_buffered + bytes) 1680 if ((controlvm_payload_bytes_buffered + bytes)
1858 > MAX_CONTROLVM_PAYLOAD_BYTES) { 1681 > MAX_CONTROLVM_PAYLOAD_BYTES) {
1859 if (retry) 1682 *retry = true;
1860 *retry = true;
1861 return NULL; 1683 return NULL;
1862 } 1684 }
1863 ctx = kzalloc(allocbytes, GFP_KERNEL | __GFP_NORETRY); 1685 ctx = kzalloc(allocbytes, GFP_KERNEL | __GFP_NORETRY);
1864 if (!ctx) { 1686 if (!ctx) {
1865 if (retry) 1687 *retry = true;
1866 *retry = true;
1867 return NULL; 1688 return NULL;
1868 } 1689 }
1869 1690
@@ -1990,19 +1811,18 @@ handle_command(struct controlvm_message inmsg, u64 channel_addr)
1990 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS); 1811 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS);
1991 break; 1812 break;
1992 case CONTROLVM_CHIPSET_READY: 1813 case CONTROLVM_CHIPSET_READY:
1993 chipset_ready(&inmsg.hdr); 1814 chipset_ready_uevent(&inmsg.hdr);
1994 break; 1815 break;
1995 case CONTROLVM_CHIPSET_SELFTEST: 1816 case CONTROLVM_CHIPSET_SELFTEST:
1996 chipset_selftest(&inmsg.hdr); 1817 chipset_selftest_uevent(&inmsg.hdr);
1997 break; 1818 break;
1998 case CONTROLVM_CHIPSET_STOP: 1819 case CONTROLVM_CHIPSET_STOP:
1999 chipset_notready(&inmsg.hdr); 1820 chipset_notready_uevent(&inmsg.hdr);
2000 break; 1821 break;
2001 default: 1822 default:
2002 if (inmsg.hdr.flags.response_expected) 1823 if (inmsg.hdr.flags.response_expected)
2003 controlvm_respond 1824 controlvm_respond
2004 (&inmsg.hdr, 1825 (&inmsg.hdr, -CONTROLVM_RESP_ID_UNKNOWN);
2005 -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN);
2006 break; 1826 break;
2007 } 1827 }
2008 1828
@@ -2057,7 +1877,7 @@ parahotplug_process_list(void)
2057 if (req->msg.hdr.flags.response_expected) 1877 if (req->msg.hdr.flags.response_expected)
2058 controlvm_respond_physdev_changestate( 1878 controlvm_respond_physdev_changestate(
2059 &req->msg.hdr, 1879 &req->msg.hdr,
2060 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT, 1880 CONTROLVM_RESP_DEVICE_UDEV_TIMEOUT,
2061 req->msg.cmd.device_change_state.state); 1881 req->msg.cmd.device_change_state.state);
2062 parahotplug_request_destroy(req); 1882 parahotplug_request_destroy(req);
2063 } 1883 }
@@ -2148,17 +1968,14 @@ visorchipset_init(struct acpi_device *acpi_device)
2148 if (!controlvm_channel) 1968 if (!controlvm_channel)
2149 goto error; 1969 goto error;
2150 1970
2151 if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT( 1971 if (!SPAR_CONTROLVM_CHANNEL_OK_CLIENT(
2152 visorchannel_get_header(controlvm_channel))) { 1972 visorchannel_get_header(controlvm_channel)))
2153 initialize_controlvm_payload();
2154 } else {
2155 goto error_destroy_channel; 1973 goto error_destroy_channel;
2156 }
2157 1974
2158 major_dev = MKDEV(visorchipset_major, 0); 1975 major_dev = MKDEV(visorchipset_major, 0);
2159 err = visorchipset_file_init(major_dev, &controlvm_channel); 1976 err = visorchipset_file_init(major_dev, &controlvm_channel);
2160 if (err < 0) 1977 if (err < 0)
2161 goto error_destroy_payload; 1978 goto error_destroy_channel;
2162 1979
2163 /* if booting in a crash kernel */ 1980 /* if booting in a crash kernel */
2164 if (is_kdump_kernel()) 1981 if (is_kdump_kernel())
@@ -2194,9 +2011,6 @@ error_cancel_work:
2194 cancel_delayed_work_sync(&periodic_controlvm_work); 2011 cancel_delayed_work_sync(&periodic_controlvm_work);
2195 visorchipset_file_cleanup(major_dev); 2012 visorchipset_file_cleanup(major_dev);
2196 2013
2197error_destroy_payload:
2198 destroy_controlvm_payload_info(&controlvm_payload_info);
2199
2200error_destroy_channel: 2014error_destroy_channel:
2201 visorchannel_destroy(controlvm_channel); 2015 visorchannel_destroy(controlvm_channel);
2202 2016
@@ -2213,7 +2027,6 @@ visorchipset_exit(struct acpi_device *acpi_device)
2213 visorbus_exit(); 2027 visorbus_exit();
2214 2028
2215 cancel_delayed_work_sync(&periodic_controlvm_work); 2029 cancel_delayed_work_sync(&periodic_controlvm_work);
2216 destroy_controlvm_payload_info(&controlvm_payload_info);
2217 2030
2218 visorchannel_destroy(controlvm_channel); 2031 visorchannel_destroy(controlvm_channel);
2219 2032
@@ -2277,7 +2090,7 @@ static void exit_unisys(void)
2277 acpi_bus_unregister_driver(&unisys_acpi_driver); 2090 acpi_bus_unregister_driver(&unisys_acpi_driver);
2278} 2091}
2279 2092
2280module_param_named(major, visorchipset_major, int, S_IRUGO); 2093module_param_named(major, visorchipset_major, int, 0444);
2281MODULE_PARM_DESC(visorchipset_major, 2094MODULE_PARM_DESC(visorchipset_major,
2282 "major device number to use for the device node"); 2095 "major device number to use for the device node");
2283 2096
diff --git a/drivers/staging/unisys/visorbus/vmcallinterface.h b/drivers/staging/unisys/visorbus/vmcallinterface.h
index 674a88b657d3..d1d72c184e29 100644
--- a/drivers/staging/unisys/visorbus/vmcallinterface.h
+++ b/drivers/staging/unisys/visorbus/vmcallinterface.h
@@ -16,10 +16,10 @@
16#define __IOMONINTF_H__ 16#define __IOMONINTF_H__
17 17
18/* 18/*
19* This file contains all structures needed to support the VMCALLs for IO 19 * This file contains all structures needed to support the VMCALLs for IO
20* Virtualization. The VMCALLs are provided by Monitor and used by IO code 20 * Virtualization. The VMCALLs are provided by Monitor and used by IO code
21* running on IO Partitions. 21 * running on IO Partitions.
22*/ 22 */
23static inline unsigned long 23static inline unsigned long
24__unisys_vmcall_gnuc(unsigned long tuple, unsigned long reg_ebx, 24__unisys_vmcall_gnuc(unsigned long tuple, unsigned long reg_ebx,
25 unsigned long reg_ecx) 25 unsigned long reg_ecx)
diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c
index 5a7a87efed27..0ce92c85157c 100644
--- a/drivers/staging/unisys/visorhba/visorhba_main.c
+++ b/drivers/staging/unisys/visorhba/visorhba_main.c
@@ -29,10 +29,6 @@
29/* The Send and Receive Buffers of the IO Queue may both be full */ 29/* The Send and Receive Buffers of the IO Queue may both be full */
30 30
31#define IOS_ERROR_THRESHOLD 1000 31#define IOS_ERROR_THRESHOLD 1000
32/* MAX_BUF = 6 lines x 10 MAXVHBA x 80 characters
33 * = 4800 bytes ~ 2^13 = 8192 bytes
34 */
35#define MAX_BUF 8192
36#define MAX_PENDING_REQUESTS (MIN_NUMSIGNALS * 2) 32#define MAX_PENDING_REQUESTS (MIN_NUMSIGNALS * 2)
37#define VISORHBA_ERROR_COUNT 30 33#define VISORHBA_ERROR_COUNT 30
38 34
diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
index ca3743d273e0..73a01a70b106 100644
--- a/drivers/staging/unisys/visornic/visornic_main.c
+++ b/drivers/staging/unisys/visornic/visornic_main.c
@@ -423,7 +423,7 @@ send_enbdis(struct net_device *netdev, int state,
423 423
424/** 424/**
425 * visornic_disable_with_timeout - Disable network adapter 425 * visornic_disable_with_timeout - Disable network adapter
426 * @netdev: netdevice to disale 426 * @netdev: netdevice to disable
427 * @timeout: timeout to wait for disable 427 * @timeout: timeout to wait for disable
428 * 428 *
429 * Disable the network adapter and inform the IO Partition that we 429 * Disable the network adapter and inform the IO Partition that we
@@ -461,10 +461,9 @@ visornic_disable_with_timeout(struct net_device *netdev, const int timeout)
461 if (devdata->enab_dis_acked) 461 if (devdata->enab_dis_acked)
462 break; 462 break;
463 if (devdata->server_down || devdata->server_change_state) { 463 if (devdata->server_down || devdata->server_change_state) {
464 spin_unlock_irqrestore(&devdata->priv_lock, flags);
465 dev_dbg(&netdev->dev, "%s server went away\n", 464 dev_dbg(&netdev->dev, "%s server went away\n",
466 __func__); 465 __func__);
467 return -EIO; 466 break;
468 } 467 }
469 set_current_state(TASK_INTERRUPTIBLE); 468 set_current_state(TASK_INTERRUPTIBLE);
470 spin_unlock_irqrestore(&devdata->priv_lock, flags); 469 spin_unlock_irqrestore(&devdata->priv_lock, flags);
@@ -533,7 +532,7 @@ init_rcv_bufs(struct net_device *netdev, struct visornic_devdata *devdata)
533 return -ENOMEM; 532 return -ENOMEM;
534 count = i; 533 count = i;
535 534
536 /* Ensure we can alloc 2/3rd of the requeested number of buffers. 535 /* Ensure we can alloc 2/3rd of the requested number of buffers.
537 * 2/3 is an arbitrary choice; used also in ndis init.c 536 * 2/3 is an arbitrary choice; used also in ndis init.c
538 */ 537 */
539 if (count < ((2 * devdata->num_rcv_bufs) / 3)) { 538 if (count < ((2 * devdata->num_rcv_bufs) / 3)) {
@@ -562,7 +561,7 @@ init_rcv_bufs(struct net_device *netdev, struct visornic_devdata *devdata)
562 * 561 *
563 * Sends enable to IOVM, inits, and posts receive buffers to IOVM 562 * Sends enable to IOVM, inits, and posts receive buffers to IOVM
564 * timeout is defined in msecs (timeout of 0 specifies infinite wait) 563 * timeout is defined in msecs (timeout of 0 specifies infinite wait)
565 * Return 0 for success, negavite for failure. 564 * Return 0 for success, negative for failure.
566 */ 565 */
567static int 566static int
568visornic_enable_with_timeout(struct net_device *netdev, const int timeout) 567visornic_enable_with_timeout(struct net_device *netdev, const int timeout)
@@ -572,6 +571,8 @@ visornic_enable_with_timeout(struct net_device *netdev, const int timeout)
572 unsigned long flags; 571 unsigned long flags;
573 int wait = 0; 572 int wait = 0;
574 573
574 napi_enable(&devdata->napi);
575
575 /* NOTE: the other end automatically unposts the rcv buffers when it 576 /* NOTE: the other end automatically unposts the rcv buffers when it
576 * gets a disable. 577 * gets a disable.
577 */ 578 */
@@ -595,7 +596,6 @@ visornic_enable_with_timeout(struct net_device *netdev, const int timeout)
595 /* send enable and wait for ack -- don't hold lock when sending enable 596 /* send enable and wait for ack -- don't hold lock when sending enable
596 * because if the queue is full, insert might sleep. 597 * because if the queue is full, insert might sleep.
597 */ 598 */
598 napi_enable(&devdata->napi);
599 send_enbdis(netdev, 1, devdata); 599 send_enbdis(netdev, 1, devdata);
600 600
601 spin_lock_irqsave(&devdata->priv_lock, flags); 601 spin_lock_irqsave(&devdata->priv_lock, flags);
@@ -604,10 +604,9 @@ visornic_enable_with_timeout(struct net_device *netdev, const int timeout)
604 if (devdata->enab_dis_acked) 604 if (devdata->enab_dis_acked)
605 break; 605 break;
606 if (devdata->server_down || devdata->server_change_state) { 606 if (devdata->server_down || devdata->server_change_state) {
607 spin_unlock_irqrestore(&devdata->priv_lock, flags);
608 dev_dbg(&netdev->dev, "%s server went away\n", 607 dev_dbg(&netdev->dev, "%s server went away\n",
609 __func__); 608 __func__);
610 return -EIO; 609 break;
611 } 610 }
612 set_current_state(TASK_INTERRUPTIBLE); 611 set_current_state(TASK_INTERRUPTIBLE);
613 spin_unlock_irqrestore(&devdata->priv_lock, flags); 612 spin_unlock_irqrestore(&devdata->priv_lock, flags);
@@ -751,7 +750,7 @@ static inline bool vnic_hit_low_watermark(struct visornic_devdata *devdata,
751 * @skb: Packet to be sent 750 * @skb: Packet to be sent
752 * @netdev: net device the packet is being sent from 751 * @netdev: net device the packet is being sent from
753 * 752 *
754 * Convert the skb to a cmdrsp so the IO Partition can undersand it. 753 * Convert the skb to a cmdrsp so the IO Partition can understand it.
755 * Send the XMIT command to the IO Partition for processing. This 754 * Send the XMIT command to the IO Partition for processing. This
756 * function is protected from concurrent calls by a spinlock xmit_lock 755 * function is protected from concurrent calls by a spinlock xmit_lock
757 * in the net_device struct, but as soon as the function returns it 756 * in the net_device struct, but as soon as the function returns it
@@ -1098,7 +1097,7 @@ repost_return(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata,
1098 * 1097 *
1099 * Got a receive packet back from the IO Part, handle it and send 1098 * Got a receive packet back from the IO Part, handle it and send
1100 * it up the stack. 1099 * it up the stack.
1101 * Returns 1 iff an skb was receieved, otherwise 0 1100 * Returns 1 iff an skb was received, otherwise 0
1102 */ 1101 */
1103static int 1102static int
1104visornic_rx(struct uiscmdrsp *cmdrsp) 1103visornic_rx(struct uiscmdrsp *cmdrsp)
@@ -1228,7 +1227,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1228 } 1227 }
1229 } 1228 }
1230 1229
1231 /* set up packet's protocl type using ethernet header - this 1230 /* set up packet's protocol type using ethernet header - this
1232 * sets up skb->pkt_type & it also PULLS out the eth header 1231 * sets up skb->pkt_type & it also PULLS out the eth header
1233 */ 1232 */
1234 skb->protocol = eth_type_trans(skb, netdev); 1233 skb->protocol = eth_type_trans(skb, netdev);
@@ -1550,7 +1549,7 @@ drain_resp_queue(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata)
1550 * @cmdrsp: io channel command response message 1549 * @cmdrsp: io channel command response message
1551 * @devdata: visornic device to drain 1550 * @devdata: visornic device to drain
1552 * 1551 *
1553 * Drain the respones queue of any responses from the IO partition. 1552 * Drain the response queue of any responses from the IO partition.
1554 * Process the responses as we get them. 1553 * Process the responses as we get them.
1555 * Returns when response queue is empty or when the thread stops. 1554 * Returns when response queue is empty or when the thread stops.
1556 */ 1555 */
@@ -1666,7 +1665,7 @@ static int visornic_poll(struct napi_struct *napi, int budget)
1666 * poll_for_irq - Checks the status of the response queue. 1665 * poll_for_irq - Checks the status of the response queue.
1667 * @v: void pointer to the visronic devdata 1666 * @v: void pointer to the visronic devdata
1668 * 1667 *
1669 * Main function of the vnic_incoming thread. Peridocially check the 1668 * Main function of the vnic_incoming thread. Periodically check the
1670 * response queue and drain it if needed. 1669 * response queue and drain it if needed.
1671 * Returns when thread has stopped. 1670 * Returns when thread has stopped.
1672 */ 1671 */
@@ -1712,7 +1711,7 @@ static int visornic_probe(struct visor_device *dev)
1712 netdev->watchdog_timeo = 5 * HZ; 1711 netdev->watchdog_timeo = 5 * HZ;
1713 SET_NETDEV_DEV(netdev, &dev->device); 1712 SET_NETDEV_DEV(netdev, &dev->device);
1714 1713
1715 /* Get MAC adddress from channel and read it into the device. */ 1714 /* Get MAC address from channel and read it into the device. */
1716 netdev->addr_len = ETH_ALEN; 1715 netdev->addr_len = ETH_ALEN;
1717 channel_offset = offsetof(struct spar_io_channel_protocol, 1716 channel_offset = offsetof(struct spar_io_channel_protocol,
1718 vnic.macaddr); 1717 vnic.macaddr);
@@ -1803,7 +1802,7 @@ static int visornic_probe(struct visor_device *dev)
1803 1802
1804 /* TODO: Setup Interrupt information */ 1803 /* TODO: Setup Interrupt information */
1805 /* Let's start our threads to get responses */ 1804 /* Let's start our threads to get responses */
1806 netif_napi_add(netdev, &devdata->napi, visornic_poll, 64); 1805 netif_napi_add(netdev, &devdata->napi, visornic_poll, NAPI_WEIGHT);
1807 1806
1808 setup_timer(&devdata->irq_poll_timer, poll_for_irq, 1807 setup_timer(&devdata->irq_poll_timer, poll_for_irq,
1809 (unsigned long)devdata); 1808 (unsigned long)devdata);
@@ -1833,10 +1832,7 @@ static int visornic_probe(struct visor_device *dev)
1833 goto cleanup_napi_add; 1832 goto cleanup_napi_add;
1834 } 1833 }
1835 1834
1836 /* Let's start our threads to get responses */ 1835 /* Note: Interrupts have to be enable before the while
1837 netif_napi_add(netdev, &devdata->napi, visornic_poll, NAPI_WEIGHT);
1838
1839 /* Note: Interupts have to be enable before the while
1840 * loop below because the napi routine is responsible for 1836 * loop below because the napi routine is responsible for
1841 * setting enab_dis_acked 1837 * setting enab_dis_acked
1842 */ 1838 */
@@ -1849,7 +1845,7 @@ static int visornic_probe(struct visor_device *dev)
1849 goto cleanup_napi_add; 1845 goto cleanup_napi_add;
1850 } 1846 }
1851 1847
1852 /* create debgug/sysfs directories */ 1848 /* create debug/sysfs directories */
1853 devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name, 1849 devdata->eth_debugfs_dir = debugfs_create_dir(netdev->name,
1854 visornic_debugfs_dir); 1850 visornic_debugfs_dir);
1855 if (!devdata->eth_debugfs_dir) { 1851 if (!devdata->eth_debugfs_dir) {
@@ -2017,8 +2013,6 @@ static int visornic_resume(struct visor_device *dev,
2017 */ 2013 */
2018 mod_timer(&devdata->irq_poll_timer, msecs_to_jiffies(2)); 2014 mod_timer(&devdata->irq_poll_timer, msecs_to_jiffies(2));
2019 2015
2020 init_rcv_bufs(netdev, devdata);
2021
2022 rtnl_lock(); 2016 rtnl_lock();
2023 dev_open(netdev); 2017 dev_open(netdev);
2024 rtnl_unlock(); 2018 rtnl_unlock();
diff --git a/drivers/staging/vc04_services/interface/vchi/connections/connection.h b/drivers/staging/vc04_services/interface/vchi/connections/connection.h
index fef6ac34c6d2..e793cdf2847c 100644
--- a/drivers/staging/vc04_services/interface/vchi/connections/connection.h
+++ b/drivers/staging/vc04_services/interface/vchi/connections/connection.h
@@ -217,8 +217,7 @@ typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_hand
217 System driver struct 217 System driver struct
218 *****************************************************************************/ 218 *****************************************************************************/
219 219
220struct opaque_vchi_connection_api_t 220struct opaque_vchi_connection_api_t {
221{
222 // Routine to init the connection 221 // Routine to init the connection
223 VCHI_CONNECTION_INIT_T init; 222 VCHI_CONNECTION_INIT_T init;
224 223
diff --git a/drivers/staging/vc04_services/interface/vchi/message_drivers/message.h b/drivers/staging/vc04_services/interface/vchi/message_drivers/message.h
index 8b3f76735bd4..a7740a425388 100644
--- a/drivers/staging/vc04_services/interface/vchi/message_drivers/message.h
+++ b/drivers/staging/vc04_services/interface/vchi/message_drivers/message.h
@@ -53,14 +53,12 @@ typedef enum message_event_type {
53 MESSAGE_EVENT_MSG_DISCARDED 53 MESSAGE_EVENT_MSG_DISCARDED
54} MESSAGE_EVENT_TYPE_T; 54} MESSAGE_EVENT_TYPE_T;
55 55
56typedef enum vchi_msg_flags 56typedef enum vchi_msg_flags {
57{
58 VCHI_MSG_FLAGS_NONE = 0x0, 57 VCHI_MSG_FLAGS_NONE = 0x0,
59 VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1 58 VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
60} VCHI_MSG_FLAGS_T; 59} VCHI_MSG_FLAGS_T;
61 60
62typedef enum message_tx_channel 61typedef enum message_tx_channel {
63{
64 MESSAGE_TX_CHANNEL_MESSAGE = 0, 62 MESSAGE_TX_CHANNEL_MESSAGE = 0,
65 MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards 63 MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
66} MESSAGE_TX_CHANNEL_T; 64} MESSAGE_TX_CHANNEL_T;
@@ -69,8 +67,7 @@ typedef enum message_tx_channel
69#define MESSAGE_TX_CHANNEL_BULK_PREV(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION-1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION) 67#define MESSAGE_TX_CHANNEL_BULK_PREV(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION-1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
70#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION) 68#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
71 69
72typedef enum message_rx_channel 70typedef enum message_rx_channel {
73{
74 MESSAGE_RX_CHANNEL_MESSAGE = 0, 71 MESSAGE_RX_CHANNEL_MESSAGE = 0,
75 MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards 72 MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
76} MESSAGE_RX_CHANNEL_T; 73} MESSAGE_RX_CHANNEL_T;
diff --git a/drivers/staging/vc04_services/interface/vchi/vchi.h b/drivers/staging/vc04_services/interface/vchi/vchi.h
index d6937288210c..addb7b00b688 100644
--- a/drivers/staging/vc04_services/interface/vchi/vchi.h
+++ b/drivers/staging/vc04_services/interface/vchi/vchi.h
@@ -61,8 +61,7 @@ struct vchi_version {
61#define VCHI_VERSION(v_) { v_, v_ } 61#define VCHI_VERSION(v_) { v_, v_ }
62#define VCHI_VERSION_EX(v_, m_) { v_, m_ } 62#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
63 63
64typedef enum 64typedef enum {
65{
66 VCHI_VEC_POINTER, 65 VCHI_VEC_POINTER,
67 VCHI_VEC_HANDLE, 66 VCHI_VEC_HANDLE,
68 VCHI_VEC_LIST 67 VCHI_VEC_LIST
@@ -71,26 +70,22 @@ typedef enum
71typedef struct vchi_msg_vector_ex { 70typedef struct vchi_msg_vector_ex {
72 71
73 VCHI_MSG_VECTOR_TYPE_T type; 72 VCHI_MSG_VECTOR_TYPE_T type;
74 union 73 union {
75 {
76 // a memory handle 74 // a memory handle
77 struct 75 struct {
78 {
79 VCHI_MEM_HANDLE_T handle; 76 VCHI_MEM_HANDLE_T handle;
80 uint32_t offset; 77 uint32_t offset;
81 int32_t vec_len; 78 int32_t vec_len;
82 } handle; 79 } handle;
83 80
84 // an ordinary data pointer 81 // an ordinary data pointer
85 struct 82 struct {
86 {
87 const void *vec_base; 83 const void *vec_base;
88 int32_t vec_len; 84 int32_t vec_len;
89 } ptr; 85 } ptr;
90 86
91 // a nested vector list 87 // a nested vector list
92 struct 88 struct {
93 {
94 struct vchi_msg_vector_ex *vec; 89 struct vchi_msg_vector_ex *vec;
95 uint32_t vec_len; 90 uint32_t vec_len;
96 } list; 91 } list;
@@ -114,8 +109,7 @@ struct opaque_vchi_service_t;
114 109
115// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold, 110// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
116// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only. 111// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
117typedef struct 112typedef struct {
118{
119 struct opaque_vchi_service_t *service; 113 struct opaque_vchi_service_t *service;
120 void *message; 114 void *message;
121} VCHI_HELD_MSG_T; 115} VCHI_HELD_MSG_T;
@@ -225,13 +219,17 @@ extern int32_t vchi_service_set_option( const VCHI_SERVICE_HANDLE_T handle,
225 VCHI_SERVICE_OPTION_T option, 219 VCHI_SERVICE_OPTION_T option,
226 int value); 220 int value);
227 221
228// Routine to send a message across a service 222/* Routine to send a message from kernel memory across a service */
229extern int32_t 223extern int
230 vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle, 224vchi_queue_kernel_message(VCHI_SERVICE_HANDLE_T handle,
231 ssize_t (*copy_callback)(void *context, void *dest, 225 void *data,
232 size_t offset, size_t maxsize), 226 unsigned int size);
233 void *context, 227
234 uint32_t data_size); 228/* Routine to send a message from user memory across a service */
229extern int
230vchi_queue_user_message(VCHI_SERVICE_HANDLE_T handle,
231 void __user *data,
232 unsigned int size);
235 233
236// Routine to receive a msg from a service 234// Routine to receive a msg from a service
237// Dequeue is equivalent to hold, copy into client buffer, release 235// Dequeue is equivalent to hold, copy into client buffer, release
diff --git a/drivers/staging/vc04_services/interface/vchi/vchi_common.h b/drivers/staging/vc04_services/interface/vchi/vchi_common.h
index d535a72970d3..45c2070d46b0 100644
--- a/drivers/staging/vc04_services/interface/vchi/vchi_common.h
+++ b/drivers/staging/vc04_services/interface/vchi/vchi_common.h
@@ -36,8 +36,7 @@
36 36
37 37
38//flags used when sending messages (must be bitmapped) 38//flags used when sending messages (must be bitmapped)
39typedef enum 39typedef enum {
40{
41 VCHI_FLAGS_NONE = 0x0, 40 VCHI_FLAGS_NONE = 0x0,
42 VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE = 0x1, // waits for message to be received, or sent (NB. not the same as being seen on other side) 41 VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE = 0x1, // waits for message to be received, or sent (NB. not the same as being seen on other side)
43 VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent 42 VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
@@ -62,8 +61,7 @@ typedef enum {
62} VCHI_CRC_CONTROL_T; 61} VCHI_CRC_CONTROL_T;
63 62
64//callback reasons when an event occurs on a service 63//callback reasons when an event occurs on a service
65typedef enum 64typedef enum {
66{
67 VCHI_CALLBACK_REASON_MIN, 65 VCHI_CALLBACK_REASON_MIN,
68 66
69 //This indicates that there is data available 67 //This indicates that there is data available
@@ -111,8 +109,7 @@ typedef enum
111} VCHI_CALLBACK_REASON_T; 109} VCHI_CALLBACK_REASON_T;
112 110
113// service control options 111// service control options
114typedef enum 112typedef enum {
115{
116 VCHI_SERVICE_OPTION_MIN, 113 VCHI_SERVICE_OPTION_MIN,
117 114
118 VCHI_SERVICE_OPTION_TRACE, 115 VCHI_SERVICE_OPTION_TRACE,
@@ -123,9 +120,9 @@ typedef enum
123 120
124 121
125//Callback used by all services / bulk transfers 122//Callback used by all services / bulk transfers
126typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param 123typedef void (*VCHI_CALLBACK_T)(void *callback_param, //my service local param
127 VCHI_CALLBACK_REASON_T reason, 124 VCHI_CALLBACK_REASON_T reason,
128 void *handle ); //for transmitting msg's only 125 void *handle); //for transmitting msg's only
129 126
130 127
131 128
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835.h
deleted file mode 100644
index 7ea5c64d5343..000000000000
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/**
2 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions, and the following disclaimer,
9 * without modification.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the above-listed copyright holders may not be used
14 * to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * ALTERNATIVELY, this software may be distributed under the terms of the
18 * GNU General Public License ("GPL") version 2, as published by the Free
19 * Software Foundation.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef VCHIQ_2835_H
35#define VCHIQ_2835_H
36
37#include "vchiq_pagelist.h"
38
39#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
40#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
41
42#endif /* VCHIQ_2835_H */
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
index 2b500d85cebc..e6241fb5cfa6 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
@@ -48,18 +48,21 @@
48#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32) 48#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
49 49
50#include "vchiq_arm.h" 50#include "vchiq_arm.h"
51#include "vchiq_2835.h"
52#include "vchiq_connected.h" 51#include "vchiq_connected.h"
53#include "vchiq_killable.h" 52#include "vchiq_killable.h"
53#include "vchiq_pagelist.h"
54 54
55#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2) 55#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
56 56
57#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
58#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
59
57#define BELL0 0x00 60#define BELL0 0x00
58#define BELL2 0x08 61#define BELL2 0x08
59 62
60typedef struct vchiq_2835_state_struct { 63typedef struct vchiq_2835_state_struct {
61 int inited; 64 int inited;
62 VCHIQ_ARM_STATE_T arm_state; 65 VCHIQ_ARM_STATE_T arm_state;
63} VCHIQ_2835_ARM_STATE_T; 66} VCHIQ_2835_ARM_STATE_T;
64 67
65struct vchiq_pagelist_info { 68struct vchiq_pagelist_info {
@@ -192,31 +195,31 @@ int vchiq_platform_init(struct platform_device *pdev, VCHIQ_STATE_T *state)
192 195
193 vchiq_call_connected_callbacks(); 196 vchiq_call_connected_callbacks();
194 197
195 return 0; 198 return 0;
196} 199}
197 200
198VCHIQ_STATUS_T 201VCHIQ_STATUS_T
199vchiq_platform_init_state(VCHIQ_STATE_T *state) 202vchiq_platform_init_state(VCHIQ_STATE_T *state)
200{ 203{
201 VCHIQ_STATUS_T status = VCHIQ_SUCCESS; 204 VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
202 state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL); 205 state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
203 ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1; 206 ((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->inited = 1;
204 status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state); 207 status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->arm_state);
205 if(status != VCHIQ_SUCCESS) 208 if (status != VCHIQ_SUCCESS)
206 { 209 {
207 ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0; 210 ((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->inited = 0;
208 } 211 }
209 return status; 212 return status;
210} 213}
211 214
212VCHIQ_ARM_STATE_T* 215VCHIQ_ARM_STATE_T*
213vchiq_platform_get_arm_state(VCHIQ_STATE_T *state) 216vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
214{ 217{
215 if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited) 218 if (!((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->inited)
216 { 219 {
217 BUG(); 220 BUG();
218 } 221 }
219 return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state; 222 return &((VCHIQ_2835_ARM_STATE_T *)state->platform_state)->arm_state;
220} 223}
221 224
222void 225void
@@ -292,13 +295,13 @@ vchiq_dump_platform_state(void *dump_context)
292VCHIQ_STATUS_T 295VCHIQ_STATUS_T
293vchiq_platform_suspend(VCHIQ_STATE_T *state) 296vchiq_platform_suspend(VCHIQ_STATE_T *state)
294{ 297{
295 return VCHIQ_ERROR; 298 return VCHIQ_ERROR;
296} 299}
297 300
298VCHIQ_STATUS_T 301VCHIQ_STATUS_T
299vchiq_platform_resume(VCHIQ_STATE_T *state) 302vchiq_platform_resume(VCHIQ_STATE_T *state)
300{ 303{
301 return VCHIQ_SUCCESS; 304 return VCHIQ_SUCCESS;
302} 305}
303 306
304void 307void
@@ -312,15 +315,15 @@ vchiq_platform_resumed(VCHIQ_STATE_T *state)
312} 315}
313 316
314int 317int
315vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state) 318vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state)
316{ 319{
317 return 1; // autosuspend not supported - videocore always wanted 320 return 1; // autosuspend not supported - videocore always wanted
318} 321}
319 322
320int 323int
321vchiq_platform_use_suspend_timer(void) 324vchiq_platform_use_suspend_timer(void)
322{ 325{
323 return 0; 326 return 0;
324} 327}
325void 328void
326vchiq_dump_platform_use_state(VCHIQ_STATE_T *state) 329vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
index 0d987898b4f8..1dc8627e65b0 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
@@ -64,10 +64,10 @@
64#define VCHIQ_MINOR 0 64#define VCHIQ_MINOR 0
65 65
66/* Some per-instance constants */ 66/* Some per-instance constants */
67#define MAX_COMPLETIONS 16 67#define MAX_COMPLETIONS 128
68#define MAX_SERVICES 64 68#define MAX_SERVICES 64
69#define MAX_ELEMENTS 8 69#define MAX_ELEMENTS 8
70#define MSG_QUEUE_SIZE 64 70#define MSG_QUEUE_SIZE 128
71 71
72#define KEEPALIVE_VER 1 72#define KEEPALIVE_VER 1
73#define KEEPALIVE_VER_MIN KEEPALIVE_VER 73#define KEEPALIVE_VER_MIN KEEPALIVE_VER
@@ -194,7 +194,7 @@ vchiq_static_assert(ARRAY_SIZE(ioctl_names) ==
194 (VCHIQ_IOC_MAX + 1)); 194 (VCHIQ_IOC_MAX + 1));
195 195
196static void 196static void
197dump_phys_mem(void *virt_addr, uint32_t num_bytes); 197dump_phys_mem(void *virt_addr, u32 num_bytes);
198 198
199/**************************************************************************** 199/****************************************************************************
200* 200*
@@ -208,10 +208,11 @@ add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
208 void *bulk_userdata) 208 void *bulk_userdata)
209{ 209{
210 VCHIQ_COMPLETION_DATA_T *completion; 210 VCHIQ_COMPLETION_DATA_T *completion;
211 int insert;
211 DEBUG_INITIALISE(g_state.local) 212 DEBUG_INITIALISE(g_state.local)
212 213
213 while (instance->completion_insert == 214 insert = instance->completion_insert;
214 (instance->completion_remove + MAX_COMPLETIONS)) { 215 while ((insert - instance->completion_remove) >= MAX_COMPLETIONS) {
215 /* Out of space - wait for the client */ 216 /* Out of space - wait for the client */
216 DEBUG_TRACE(SERVICE_CALLBACK_LINE); 217 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
217 vchiq_log_trace(vchiq_arm_log_level, 218 vchiq_log_trace(vchiq_arm_log_level,
@@ -224,14 +225,12 @@ add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
224 } else if (instance->closing) { 225 } else if (instance->closing) {
225 vchiq_log_info(vchiq_arm_log_level, 226 vchiq_log_info(vchiq_arm_log_level,
226 "service_callback closing"); 227 "service_callback closing");
227 return VCHIQ_ERROR; 228 return VCHIQ_SUCCESS;
228 } 229 }
229 DEBUG_TRACE(SERVICE_CALLBACK_LINE); 230 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
230 } 231 }
231 232
232 completion = 233 completion = &instance->completions[insert & (MAX_COMPLETIONS - 1)];
233 &instance->completions[instance->completion_insert &
234 (MAX_COMPLETIONS - 1)];
235 234
236 completion->header = header; 235 completion->header = header;
237 completion->reason = reason; 236 completion->reason = reason;
@@ -252,9 +251,10 @@ add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
252 wmb(); 251 wmb();
253 252
254 if (reason == VCHIQ_MESSAGE_AVAILABLE) 253 if (reason == VCHIQ_MESSAGE_AVAILABLE)
255 user_service->message_available_pos = 254 user_service->message_available_pos = insert;
256 instance->completion_insert; 255
257 instance->completion_insert++; 256 insert++;
257 instance->completion_insert = insert;
258 258
259 up(&instance->insert_event); 259 up(&instance->insert_event);
260 260
@@ -279,6 +279,7 @@ service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
279 USER_SERVICE_T *user_service; 279 USER_SERVICE_T *user_service;
280 VCHIQ_SERVICE_T *service; 280 VCHIQ_SERVICE_T *service;
281 VCHIQ_INSTANCE_T instance; 281 VCHIQ_INSTANCE_T instance;
282 bool skip_completion = false;
282 DEBUG_INITIALISE(g_state.local) 283 DEBUG_INITIALISE(g_state.local)
283 284
284 DEBUG_TRACE(SERVICE_CALLBACK_LINE); 285 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
@@ -345,9 +346,6 @@ service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
345 user_service->msg_queue[user_service->msg_insert & 346 user_service->msg_queue[user_service->msg_insert &
346 (MSG_QUEUE_SIZE - 1)] = header; 347 (MSG_QUEUE_SIZE - 1)] = header;
347 user_service->msg_insert++; 348 user_service->msg_insert++;
348 spin_unlock(&msg_queue_spinlock);
349
350 up(&user_service->insert_event);
351 349
352 /* If there is a thread waiting in DEQUEUE_MESSAGE, or if 350 /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
353 ** there is a MESSAGE_AVAILABLE in the completion queue then 351 ** there is a MESSAGE_AVAILABLE in the completion queue then
@@ -356,15 +354,20 @@ service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
356 if (((user_service->message_available_pos - 354 if (((user_service->message_available_pos -
357 instance->completion_remove) >= 0) || 355 instance->completion_remove) >= 0) ||
358 user_service->dequeue_pending) { 356 user_service->dequeue_pending) {
359 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
360 user_service->dequeue_pending = 0; 357 user_service->dequeue_pending = 0;
361 return VCHIQ_SUCCESS; 358 skip_completion = true;
362 } 359 }
363 360
361 spin_unlock(&msg_queue_spinlock);
362 up(&user_service->insert_event);
363
364 header = NULL; 364 header = NULL;
365 } 365 }
366 DEBUG_TRACE(SERVICE_CALLBACK_LINE); 366 DEBUG_TRACE(SERVICE_CALLBACK_LINE);
367 367
368 if (skip_completion)
369 return VCHIQ_SUCCESS;
370
368 return add_completion(instance, reason, header, user_service, 371 return add_completion(instance, reason, header, user_service,
369 bulk_userdata); 372 bulk_userdata);
370} 373}
@@ -665,7 +668,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
665 USER_SERVICE_T *user_service = 668 USER_SERVICE_T *user_service =
666 (USER_SERVICE_T *)service->base.userdata; 669 (USER_SERVICE_T *)service->base.userdata;
667 /* close_pending is false on first entry, and when the 670 /* close_pending is false on first entry, and when the
668 wait in vchiq_close_service has been interrupted. */ 671 wait in vchiq_close_service has been interrupted. */
669 if (!user_service->close_pending) { 672 if (!user_service->close_pending) {
670 status = vchiq_close_service(service->handle); 673 status = vchiq_close_service(service->handle);
671 if (status != VCHIQ_SUCCESS) 674 if (status != VCHIQ_SUCCESS)
@@ -691,7 +694,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
691 USER_SERVICE_T *user_service = 694 USER_SERVICE_T *user_service =
692 (USER_SERVICE_T *)service->base.userdata; 695 (USER_SERVICE_T *)service->base.userdata;
693 /* close_pending is false on first entry, and when the 696 /* close_pending is false on first entry, and when the
694 wait in vchiq_close_service has been interrupted. */ 697 wait in vchiq_close_service has been interrupted. */
695 if (!user_service->close_pending) { 698 if (!user_service->close_pending) {
696 status = vchiq_remove_service(service->handle); 699 status = vchiq_remove_service(service->handle);
697 if (status != VCHIQ_SUCCESS) 700 if (status != VCHIQ_SUCCESS)
@@ -892,24 +895,27 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
892 } 895 }
893 DEBUG_TRACE(AWAIT_COMPLETION_LINE); 896 DEBUG_TRACE(AWAIT_COMPLETION_LINE);
894 897
895 /* A read memory barrier is needed to stop prefetch of a stale
896 ** completion record
897 */
898 rmb();
899
900 if (ret == 0) { 898 if (ret == 0) {
901 int msgbufcount = args.msgbufcount; 899 int msgbufcount = args.msgbufcount;
900 int remove = instance->completion_remove;
901
902 for (ret = 0; ret < args.count; ret++) { 902 for (ret = 0; ret < args.count; ret++) {
903 VCHIQ_COMPLETION_DATA_T *completion; 903 VCHIQ_COMPLETION_DATA_T *completion;
904 VCHIQ_SERVICE_T *service; 904 VCHIQ_SERVICE_T *service;
905 USER_SERVICE_T *user_service; 905 USER_SERVICE_T *user_service;
906 VCHIQ_HEADER_T *header; 906 VCHIQ_HEADER_T *header;
907 if (instance->completion_remove == 907
908 instance->completion_insert) 908 if (remove == instance->completion_insert)
909 break; 909 break;
910
910 completion = &instance->completions[ 911 completion = &instance->completions[
911 instance->completion_remove & 912 remove & (MAX_COMPLETIONS - 1)];
912 (MAX_COMPLETIONS - 1)]; 913
914 /*
915 * A read memory barrier is needed to stop
916 * prefetch of a stale completion record
917 */
918 rmb();
913 919
914 service = completion->service_userdata; 920 service = completion->service_userdata;
915 user_service = service->base.userdata; 921 user_service = service->base.userdata;
@@ -984,7 +990,13 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
984 break; 990 break;
985 } 991 }
986 992
987 instance->completion_remove++; 993 /*
994 * Ensure that the above copy has completed
995 * before advancing the remove pointer.
996 */
997 mb();
998 remove++;
999 instance->completion_remove = remove;
988 } 1000 }
989 1001
990 if (msgbufcount != args.msgbufcount) { 1002 if (msgbufcount != args.msgbufcount) {
@@ -1535,10 +1547,10 @@ vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
1535***************************************************************************/ 1547***************************************************************************/
1536 1548
1537static void 1549static void
1538dump_phys_mem(void *virt_addr, uint32_t num_bytes) 1550dump_phys_mem(void *virt_addr, u32 num_bytes)
1539{ 1551{
1540 int rc; 1552 int rc;
1541 uint8_t *end_virt_addr = virt_addr + num_bytes; 1553 u8 *end_virt_addr = virt_addr + num_bytes;
1542 int num_pages; 1554 int num_pages;
1543 int offset; 1555 int offset;
1544 int end_offset; 1556 int end_offset;
@@ -1546,7 +1558,7 @@ dump_phys_mem(void *virt_addr, uint32_t num_bytes)
1546 int prev_idx; 1558 int prev_idx;
1547 struct page *page; 1559 struct page *page;
1548 struct page **pages; 1560 struct page **pages;
1549 uint8_t *kmapped_virt_ptr; 1561 u8 *kmapped_virt_ptr;
1550 1562
1551 /* Align virtAddr and endVirtAddr to 16 byte boundaries. */ 1563 /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
1552 1564
@@ -1602,7 +1614,7 @@ dump_phys_mem(void *virt_addr, uint32_t num_bytes)
1602 1614
1603 if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE) 1615 if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
1604 vchiq_log_dump_mem("ph", 1616 vchiq_log_dump_mem("ph",
1605 (uint32_t)(unsigned long)&kmapped_virt_ptr[ 1617 (u32)(unsigned long)&kmapped_virt_ptr[
1606 page_offset], 1618 page_offset],
1607 &kmapped_virt_ptr[page_offset], 16); 1619 &kmapped_virt_ptr[page_offset], 16);
1608 1620
@@ -1996,7 +2008,7 @@ block_resume(VCHIQ_ARM_STATE_T *arm_state)
1996 &arm_state->blocked_blocker, timeout_val) 2008 &arm_state->blocked_blocker, timeout_val)
1997 <= 0) { 2009 <= 0) {
1998 vchiq_log_error(vchiq_susp_log_level, "%s wait for " 2010 vchiq_log_error(vchiq_susp_log_level, "%s wait for "
1999 "previously blocked clients failed" , __func__); 2011 "previously blocked clients failed", __func__);
2000 status = VCHIQ_ERROR; 2012 status = VCHIQ_ERROR;
2001 write_lock_bh(&arm_state->susp_res_lock); 2013 write_lock_bh(&arm_state->susp_res_lock);
2002 goto out; 2014 goto out;
@@ -2012,7 +2024,7 @@ block_resume(VCHIQ_ARM_STATE_T *arm_state)
2012 if (resume_count > 1) { 2024 if (resume_count > 1) {
2013 status = VCHIQ_ERROR; 2025 status = VCHIQ_ERROR;
2014 vchiq_log_error(vchiq_susp_log_level, "%s waited too " 2026 vchiq_log_error(vchiq_susp_log_level, "%s waited too "
2015 "many times for resume" , __func__); 2027 "many times for resume", __func__);
2016 goto out; 2028 goto out;
2017 } 2029 }
2018 write_unlock_bh(&arm_state->susp_res_lock); 2030 write_unlock_bh(&arm_state->susp_res_lock);
@@ -2372,52 +2384,6 @@ out:
2372 return resume; 2384 return resume;
2373} 2385}
2374 2386
2375void
2376vchiq_platform_check_resume(VCHIQ_STATE_T *state)
2377{
2378 VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
2379 int res = 0;
2380
2381 if (!arm_state)
2382 goto out;
2383
2384 vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
2385
2386 write_lock_bh(&arm_state->susp_res_lock);
2387 if (arm_state->wake_address == 0) {
2388 vchiq_log_info(vchiq_susp_log_level,
2389 "%s: already awake", __func__);
2390 goto unlock;
2391 }
2392 if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
2393 vchiq_log_info(vchiq_susp_log_level,
2394 "%s: already resuming", __func__);
2395 goto unlock;
2396 }
2397
2398 if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
2399 set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
2400 res = 1;
2401 } else
2402 vchiq_log_trace(vchiq_susp_log_level,
2403 "%s: not resuming (resume state %s)", __func__,
2404 resume_state_names[arm_state->vc_resume_state +
2405 VC_RESUME_NUM_OFFSET]);
2406
2407unlock:
2408 write_unlock_bh(&arm_state->susp_res_lock);
2409
2410 if (res)
2411 vchiq_platform_resume(state);
2412
2413out:
2414 vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
2415 return;
2416
2417}
2418
2419
2420
2421VCHIQ_STATUS_T 2387VCHIQ_STATUS_T
2422vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, 2388vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
2423 enum USE_TYPE_E use_type) 2389 enum USE_TYPE_E use_type)
@@ -2870,10 +2836,10 @@ void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
2870 if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) { 2836 if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
2871 write_lock_bh(&arm_state->susp_res_lock); 2837 write_lock_bh(&arm_state->susp_res_lock);
2872 if (!arm_state->first_connect) { 2838 if (!arm_state->first_connect) {
2873 char threadname[10]; 2839 char threadname[16];
2874 arm_state->first_connect = 1; 2840 arm_state->first_connect = 1;
2875 write_unlock_bh(&arm_state->susp_res_lock); 2841 write_unlock_bh(&arm_state->susp_res_lock);
2876 snprintf(threadname, sizeof(threadname), "VCHIQka-%d", 2842 snprintf(threadname, sizeof(threadname), "vchiq-keep/%d",
2877 state->id); 2843 state->id);
2878 arm_state->ka_thread = kthread_create( 2844 arm_state->ka_thread = kthread_create(
2879 &vchiq_keepalive_thread_func, 2845 &vchiq_keepalive_thread_func,
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
index 9740e1afbc9d..bfbd81d9db33 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
@@ -154,7 +154,7 @@ vchiq_check_resume(VCHIQ_STATE_T *state);
154 154
155extern void 155extern void
156vchiq_check_suspend(VCHIQ_STATE_T *state); 156vchiq_check_suspend(VCHIQ_STATE_T *state);
157 VCHIQ_STATUS_T 157VCHIQ_STATUS_T
158vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle); 158vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
159 159
160extern VCHIQ_STATUS_T 160extern VCHIQ_STATUS_T
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
index 028e90bc1cdc..d587097b261c 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -90,7 +90,7 @@ static atomic_t pause_bulks_count = ATOMIC_INIT(0);
90 90
91static DEFINE_SPINLOCK(service_spinlock); 91static DEFINE_SPINLOCK(service_spinlock);
92DEFINE_SPINLOCK(bulk_waiter_spinlock); 92DEFINE_SPINLOCK(bulk_waiter_spinlock);
93DEFINE_SPINLOCK(quota_spinlock); 93static DEFINE_SPINLOCK(quota_spinlock);
94 94
95VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES]; 95VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
96static unsigned int handle_seq; 96static unsigned int handle_seq;
@@ -517,7 +517,7 @@ get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
517inline void 517inline void
518request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type) 518request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
519{ 519{
520 uint32_t value; 520 u32 value;
521 521
522 if (service) { 522 if (service) {
523 do { 523 do {
@@ -607,15 +607,17 @@ process_free_queue(VCHIQ_STATE_T *state)
607 BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)]; 607 BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
608 int slot_queue_available; 608 int slot_queue_available;
609 609
610 /* Use a read memory barrier to ensure that any state that may have
611 ** been modified by another thread is not masked by stale prefetched
612 ** values. */
613 rmb();
614
615 /* Find slots which have been freed by the other side, and return them 610 /* Find slots which have been freed by the other side, and return them
616 ** to the available queue. */ 611 ** to the available queue. */
617 slot_queue_available = state->slot_queue_available; 612 slot_queue_available = state->slot_queue_available;
618 613
614 /*
615 * Use a memory barrier to ensure that any state that may have been
616 * modified by another thread is not masked by stale prefetched
617 * values.
618 */
619 mb();
620
619 while (slot_queue_available != local->slot_queue_recycle) { 621 while (slot_queue_available != local->slot_queue_recycle) {
620 unsigned int pos; 622 unsigned int pos;
621 int slot_index = local->slot_queue[slot_queue_available++ & 623 int slot_index = local->slot_queue[slot_queue_available++ &
@@ -623,6 +625,12 @@ process_free_queue(VCHIQ_STATE_T *state)
623 char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index); 625 char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
624 int data_found = 0; 626 int data_found = 0;
625 627
628 /*
629 * Beware of the address dependency - data is calculated
630 * using an index written by the other side.
631 */
632 rmb();
633
626 vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%pK %x %x", 634 vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%pK %x %x",
627 state->id, slot_index, data, 635 state->id, slot_index, data,
628 local->slot_queue_recycle, slot_queue_available); 636 local->slot_queue_recycle, slot_queue_available);
@@ -721,6 +729,12 @@ process_free_queue(VCHIQ_STATE_T *state)
721 up(&state->data_quota_event); 729 up(&state->data_quota_event);
722 } 730 }
723 731
732 /*
733 * Don't allow the slot to be reused until we are no
734 * longer interested in it.
735 */
736 mb();
737
724 state->slot_queue_available = slot_queue_available; 738 state->slot_queue_available = slot_queue_available;
725 up(&state->slot_available_event); 739 up(&state->slot_available_event);
726 } 740 }
@@ -920,7 +934,7 @@ queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
920 VCHIQ_LOG_INFO)) 934 VCHIQ_LOG_INFO))
921 vchiq_log_dump_mem("Sent", 0, 935 vchiq_log_dump_mem("Sent", 0,
922 header->data, 936 header->data,
923 min((size_t)64, 937 min((size_t)16,
924 (size_t)callback_result)); 938 (size_t)callback_result));
925 939
926 spin_lock(&quota_spinlock); 940 spin_lock(&quota_spinlock);
@@ -1073,7 +1087,7 @@ queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
1073 VCHIQ_LOG_INFO)) 1087 VCHIQ_LOG_INFO))
1074 vchiq_log_dump_mem("Sent", 0, 1088 vchiq_log_dump_mem("Sent", 0,
1075 header->data, 1089 header->data,
1076 min((size_t)64, 1090 min((size_t)16,
1077 (size_t)callback_result)); 1091 (size_t)callback_result));
1078 1092
1079 VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count); 1093 VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
@@ -1286,14 +1300,14 @@ poll_services(VCHIQ_STATE_T *state)
1286 int group, i; 1300 int group, i;
1287 1301
1288 for (group = 0; group < BITSET_SIZE(state->unused_service); group++) { 1302 for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
1289 uint32_t flags; 1303 u32 flags;
1290 flags = atomic_xchg(&state->poll_services[group], 0); 1304 flags = atomic_xchg(&state->poll_services[group], 0);
1291 for (i = 0; flags; i++) { 1305 for (i = 0; flags; i++) {
1292 if (flags & (1 << i)) { 1306 if (flags & (1 << i)) {
1293 VCHIQ_SERVICE_T *service = 1307 VCHIQ_SERVICE_T *service =
1294 find_service_by_port(state, 1308 find_service_by_port(state,
1295 (group<<5) + i); 1309 (group<<5) + i);
1296 uint32_t service_flags; 1310 u32 service_flags;
1297 flags &= ~(1 << i); 1311 flags &= ~(1 << i);
1298 if (!service) 1312 if (!service)
1299 continue; 1313 continue;
@@ -1513,12 +1527,10 @@ parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
1513{ 1527{
1514 VCHIQ_SERVICE_T *service = NULL; 1528 VCHIQ_SERVICE_T *service = NULL;
1515 int msgid, size; 1529 int msgid, size;
1516 int type;
1517 unsigned int localport, remoteport; 1530 unsigned int localport, remoteport;
1518 1531
1519 msgid = header->msgid; 1532 msgid = header->msgid;
1520 size = header->size; 1533 size = header->size;
1521 type = VCHIQ_MSG_TYPE(msgid);
1522 localport = VCHIQ_MSG_DSTPORT(msgid); 1534 localport = VCHIQ_MSG_DSTPORT(msgid);
1523 remoteport = VCHIQ_MSG_SRCPORT(msgid); 1535 remoteport = VCHIQ_MSG_SRCPORT(msgid);
1524 if (size >= sizeof(struct vchiq_open_payload)) { 1536 if (size >= sizeof(struct vchiq_open_payload)) {
@@ -1620,7 +1632,7 @@ fail_open:
1620 /* No available service, or an invalid request - send a CLOSE */ 1632 /* No available service, or an invalid request - send a CLOSE */
1621 if (queue_message(state, NULL, 1633 if (queue_message(state, NULL,
1622 VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)), 1634 VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
1623 NULL, 0, 0, 0) == VCHIQ_RETRY) 1635 NULL, NULL, 0, 0) == VCHIQ_RETRY)
1624 goto bail_not_ready; 1636 goto bail_not_ready;
1625 1637
1626 return 1; 1638 return 1;
@@ -1736,7 +1748,7 @@ parse_rx_slots(VCHIQ_STATE_T *state)
1736 remoteport, localport, size); 1748 remoteport, localport, size);
1737 if (size > 0) 1749 if (size > 0)
1738 vchiq_log_dump_mem("Rcvd", 0, header->data, 1750 vchiq_log_dump_mem("Rcvd", 0, header->data,
1739 min(64, size)); 1751 min(16, size));
1740 } 1752 }
1741 1753
1742 if (((unsigned long)header & VCHIQ_SLOT_MASK) + 1754 if (((unsigned long)header & VCHIQ_SLOT_MASK) +
@@ -1973,7 +1985,7 @@ parse_rx_slots(VCHIQ_STATE_T *state)
1973 /* Send a PAUSE in response */ 1985 /* Send a PAUSE in response */
1974 if (queue_message(state, NULL, 1986 if (queue_message(state, NULL,
1975 VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0), 1987 VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
1976 NULL, 0, 0, QMFLAGS_NO_MUTEX_UNLOCK) 1988 NULL, NULL, 0, QMFLAGS_NO_MUTEX_UNLOCK)
1977 == VCHIQ_RETRY) 1989 == VCHIQ_RETRY)
1978 goto bail_not_ready; 1990 goto bail_not_ready;
1979 if (state->is_master) 1991 if (state->is_master)
@@ -2072,7 +2084,7 @@ slot_handler_func(void *v)
2072 pause_bulks(state); 2084 pause_bulks(state);
2073 if (queue_message(state, NULL, 2085 if (queue_message(state, NULL,
2074 VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0), 2086 VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
2075 NULL, 0, 0, 2087 NULL, NULL, 0,
2076 QMFLAGS_NO_MUTEX_UNLOCK) 2088 QMFLAGS_NO_MUTEX_UNLOCK)
2077 != VCHIQ_RETRY) { 2089 != VCHIQ_RETRY) {
2078 vchiq_set_conn_state(state, 2090 vchiq_set_conn_state(state,
@@ -2092,7 +2104,7 @@ slot_handler_func(void *v)
2092 case VCHIQ_CONNSTATE_RESUMING: 2104 case VCHIQ_CONNSTATE_RESUMING:
2093 if (queue_message(state, NULL, 2105 if (queue_message(state, NULL,
2094 VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0), 2106 VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
2095 NULL, 0, 0, QMFLAGS_NO_MUTEX_LOCK) 2107 NULL, NULL, 0, QMFLAGS_NO_MUTEX_LOCK)
2096 != VCHIQ_RETRY) { 2108 != VCHIQ_RETRY) {
2097 if (state->is_master) 2109 if (state->is_master)
2098 resume_bulks(state); 2110 resume_bulks(state);
@@ -2193,7 +2205,7 @@ sync_func(void *v)
2193 remoteport, localport, size); 2205 remoteport, localport, size);
2194 if (size > 0) 2206 if (size > 0)
2195 vchiq_log_dump_mem("Rcvd", 0, header->data, 2207 vchiq_log_dump_mem("Rcvd", 0, header->data,
2196 min(64, size)); 2208 min(16, size));
2197 } 2209 }
2198 2210
2199 switch (type) { 2211 switch (type) {
@@ -2317,7 +2329,7 @@ vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
2317 VCHIQ_SHARED_STATE_T *local; 2329 VCHIQ_SHARED_STATE_T *local;
2318 VCHIQ_SHARED_STATE_T *remote; 2330 VCHIQ_SHARED_STATE_T *remote;
2319 VCHIQ_STATUS_T status; 2331 VCHIQ_STATUS_T status;
2320 char threadname[10]; 2332 char threadname[16];
2321 static int id; 2333 static int id;
2322 int i; 2334 int i;
2323 2335
@@ -2485,7 +2497,7 @@ vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
2485 /* 2497 /*
2486 bring up slot handler thread 2498 bring up slot handler thread
2487 */ 2499 */
2488 snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id); 2500 snprintf(threadname, sizeof(threadname), "vchiq-slot/%d", state->id);
2489 state->slot_handler_thread = kthread_create(&slot_handler_func, 2501 state->slot_handler_thread = kthread_create(&slot_handler_func,
2490 (void *)state, 2502 (void *)state,
2491 threadname); 2503 threadname);
@@ -2499,7 +2511,7 @@ vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
2499 set_user_nice(state->slot_handler_thread, -19); 2511 set_user_nice(state->slot_handler_thread, -19);
2500 wake_up_process(state->slot_handler_thread); 2512 wake_up_process(state->slot_handler_thread);
2501 2513
2502 snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id); 2514 snprintf(threadname, sizeof(threadname), "vchiq-recy/%d", state->id);
2503 state->recycle_thread = kthread_create(&recycle_func, 2515 state->recycle_thread = kthread_create(&recycle_func,
2504 (void *)state, 2516 (void *)state,
2505 threadname); 2517 threadname);
@@ -2512,7 +2524,7 @@ vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
2512 set_user_nice(state->recycle_thread, -19); 2524 set_user_nice(state->recycle_thread, -19);
2513 wake_up_process(state->recycle_thread); 2525 wake_up_process(state->recycle_thread);
2514 2526
2515 snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id); 2527 snprintf(threadname, sizeof(threadname), "vchiq-sync/%d", state->id);
2516 state->sync_thread = kthread_create(&sync_func, 2528 state->sync_thread = kthread_create(&sync_func,
2517 (void *)state, 2529 (void *)state,
2518 threadname); 2530 threadname);
@@ -2904,7 +2916,7 @@ vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
2904 (VCHIQ_MSG_CLOSE, 2916 (VCHIQ_MSG_CLOSE,
2905 service->localport, 2917 service->localport,
2906 VCHIQ_MSG_DSTPORT(service->remoteport)), 2918 VCHIQ_MSG_DSTPORT(service->remoteport)),
2907 NULL, 0, 0, 0); 2919 NULL, NULL, 0, 0);
2908 } 2920 }
2909 break; 2921 break;
2910 2922
@@ -2926,7 +2938,7 @@ vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
2926 (VCHIQ_MSG_CLOSE, 2938 (VCHIQ_MSG_CLOSE,
2927 service->localport, 2939 service->localport,
2928 VCHIQ_MSG_DSTPORT(service->remoteport)), 2940 VCHIQ_MSG_DSTPORT(service->remoteport)),
2929 NULL, 0, 0, QMFLAGS_NO_MUTEX_UNLOCK); 2941 NULL, NULL, 0, QMFLAGS_NO_MUTEX_UNLOCK);
2930 2942
2931 if (status == VCHIQ_SUCCESS) { 2943 if (status == VCHIQ_SUCCESS) {
2932 if (!close_recvd) { 2944 if (!close_recvd) {
@@ -3056,7 +3068,7 @@ vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
3056 3068
3057 if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) { 3069 if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
3058 if (queue_message(state, NULL, 3070 if (queue_message(state, NULL,
3059 VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0, 3071 VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, NULL,
3060 0, QMFLAGS_IS_BLOCKING) == VCHIQ_RETRY) 3072 0, QMFLAGS_IS_BLOCKING) == VCHIQ_RETRY)
3061 return VCHIQ_RETRY; 3073 return VCHIQ_RETRY;
3062 3074
@@ -3509,20 +3521,20 @@ release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
3509VCHIQ_STATUS_T 3521VCHIQ_STATUS_T
3510vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version) 3522vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
3511{ 3523{
3512 VCHIQ_STATUS_T status = VCHIQ_ERROR; 3524 VCHIQ_STATUS_T status = VCHIQ_ERROR;
3513 VCHIQ_SERVICE_T *service = find_service_by_handle(handle); 3525 VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
3514 3526
3515 if (!service || 3527 if (!service ||
3516 (vchiq_check_service(service) != VCHIQ_SUCCESS) || 3528 (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
3517 !peer_version) 3529 !peer_version)
3518 goto exit; 3530 goto exit;
3519 *peer_version = service->peer_version; 3531 *peer_version = service->peer_version;
3520 status = VCHIQ_SUCCESS; 3532 status = VCHIQ_SUCCESS;
3521 3533
3522exit: 3534exit:
3523 if (service) 3535 if (service)
3524 unlock_service(service); 3536 unlock_service(service);
3525 return status; 3537 return status;
3526} 3538}
3527 3539
3528VCHIQ_STATUS_T 3540VCHIQ_STATUS_T
@@ -3626,7 +3638,7 @@ vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
3626 return status; 3638 return status;
3627} 3639}
3628 3640
3629void 3641static void
3630vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state, 3642vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
3631 VCHIQ_SHARED_STATE_T *shared, const char *label) 3643 VCHIQ_SHARED_STATE_T *shared, const char *label)
3632{ 3644{
@@ -3816,7 +3828,7 @@ vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
3816 service->stats.bulk_stalls, 3828 service->stats.bulk_stalls,
3817 service->stats.bulk_aborted_count, 3829 service->stats.bulk_aborted_count,
3818 service->stats.error_count); 3830 service->stats.error_count);
3819 } 3831 }
3820 } 3832 }
3821 3833
3822 vchiq_dump(dump_context, buf, len + 1); 3834 vchiq_dump(dump_context, buf, len + 1);
@@ -3857,7 +3869,7 @@ VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
3857 if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED) 3869 if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
3858 status = queue_message(state, NULL, 3870 status = queue_message(state, NULL,
3859 VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0), 3871 VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
3860 NULL, 0, 0, 0); 3872 NULL, NULL, 0, 0);
3861 return status; 3873 return status;
3862} 3874}
3863 3875
@@ -3867,7 +3879,7 @@ VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
3867 if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED) 3879 if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
3868 status = queue_message(state, NULL, 3880 status = queue_message(state, NULL,
3869 VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0), 3881 VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
3870 NULL, 0, 0, 0); 3882 NULL, NULL, 0, 0);
3871 return status; 3883 return status;
3872} 3884}
3873 3885
@@ -3877,14 +3889,14 @@ VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
3877 if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED) 3889 if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
3878 status = queue_message(state, NULL, 3890 status = queue_message(state, NULL,
3879 VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0), 3891 VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
3880 NULL, 0, 0, 0); 3892 NULL, NULL, 0, 0);
3881 return status; 3893 return status;
3882} 3894}
3883 3895
3884void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *void_mem, 3896void vchiq_log_dump_mem(const char *label, u32 addr, const void *void_mem,
3885 size_t num_bytes) 3897 size_t num_bytes)
3886{ 3898{
3887 const uint8_t *mem = (const uint8_t *)void_mem; 3899 const u8 *mem = (const u8 *)void_mem;
3888 size_t offset; 3900 size_t offset;
3889 char line_buf[100]; 3901 char line_buf[100];
3890 char *s; 3902 char *s;
@@ -3901,7 +3913,7 @@ void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *void_mem,
3901 3913
3902 for (offset = 0; offset < 16; offset++) { 3914 for (offset = 0; offset < 16; offset++) {
3903 if (offset < num_bytes) { 3915 if (offset < num_bytes) {
3904 uint8_t ch = mem[offset]; 3916 u8 ch = mem[offset];
3905 3917
3906 if ((ch < ' ') || (ch > '~')) 3918 if ((ch < ' ') || (ch > '~'))
3907 ch = '.'; 3919 ch = '.';
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.h
index 4d6a3788e9c5..1d95e3d70621 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.h
@@ -36,8 +36,7 @@
36 36
37#include "vchiq_core.h" 37#include "vchiq_core.h"
38 38
39typedef struct vchiq_debugfs_node_struct 39typedef struct vchiq_debugfs_node_struct {
40{
41 struct dentry *dentry; 40 struct dentry *dentry;
42} VCHIQ_DEBUGFS_NODE_T; 41} VCHIQ_DEBUGFS_NODE_T;
43 42
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
index e93922a87263..4317c06943a6 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
@@ -75,23 +75,23 @@ VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instance_out)
75 VCHIQ_STATUS_T status = VCHIQ_ERROR; 75 VCHIQ_STATUS_T status = VCHIQ_ERROR;
76 VCHIQ_STATE_T *state; 76 VCHIQ_STATE_T *state;
77 VCHIQ_INSTANCE_T instance = NULL; 77 VCHIQ_INSTANCE_T instance = NULL;
78 int i; 78 int i;
79 79
80 vchiq_log_trace(vchiq_core_log_level, "%s called", __func__); 80 vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
81 81
82 /* VideoCore may not be ready due to boot up timing. 82 /* VideoCore may not be ready due to boot up timing.
83 It may never be ready if kernel and firmware are mismatched, so don't block forever. */ 83 It may never be ready if kernel and firmware are mismatched, so don't block forever. */
84 for (i=0; i<VCHIQ_INIT_RETRIES; i++) { 84 for (i = 0; i < VCHIQ_INIT_RETRIES; i++) {
85 state = vchiq_get_state(); 85 state = vchiq_get_state();
86 if (state) 86 if (state)
87 break; 87 break;
88 udelay(500); 88 udelay(500);
89 } 89 }
90 if (i==VCHIQ_INIT_RETRIES) { 90 if (i == VCHIQ_INIT_RETRIES) {
91 vchiq_log_error(vchiq_core_log_level, 91 vchiq_log_error(vchiq_core_log_level,
92 "%s: videocore not initialized\n", __func__); 92 "%s: videocore not initialized\n", __func__);
93 goto failed; 93 goto failed;
94 } else if (i>0) { 94 } else if (i > 0) {
95 vchiq_log_warning(vchiq_core_log_level, 95 vchiq_log_warning(vchiq_core_log_level,
96 "%s: videocore initialized after %d retries\n", __func__, i); 96 "%s: videocore initialized after %d retries\n", __func__, i);
97 } 97 }
@@ -172,7 +172,7 @@ EXPORT_SYMBOL(vchiq_shutdown);
172* 172*
173***************************************************************************/ 173***************************************************************************/
174 174
175int vchiq_is_connected(VCHIQ_INSTANCE_T instance) 175static int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
176{ 176{
177 return instance->connected; 177 return instance->connected;
178} 178}
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
index d9771394a041..48984abc3854 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
@@ -39,8 +39,6 @@
39 39
40#include "vchiq_util.h" 40#include "vchiq_util.h"
41 41
42#include <stddef.h>
43
44#define vchiq_status_to_vchi(status) ((int32_t)status) 42#define vchiq_status_to_vchi(status) ((int32_t)status)
45 43
46typedef struct { 44typedef struct {
@@ -158,6 +156,7 @@ EXPORT_SYMBOL(vchi_msg_remove);
158 * Returns: int32_t - success == 0 156 * Returns: int32_t - success == 0
159 * 157 *
160 ***********************************************************/ 158 ***********************************************************/
159static
161int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle, 160int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
162 ssize_t (*copy_callback)(void *context, void *dest, 161 ssize_t (*copy_callback)(void *context, void *dest,
163 size_t offset, size_t maxsize), 162 size_t offset, size_t maxsize),
@@ -186,7 +185,62 @@ int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
186 185
187 return vchiq_status_to_vchi(status); 186 return vchiq_status_to_vchi(status);
188} 187}
189EXPORT_SYMBOL(vchi_msg_queue); 188
189static ssize_t
190vchi_queue_kernel_message_callback(void *context,
191 void *dest,
192 size_t offset,
193 size_t maxsize)
194{
195 memcpy(dest, context + offset, maxsize);
196 return maxsize;
197}
198
199int
200vchi_queue_kernel_message(VCHI_SERVICE_HANDLE_T handle,
201 void *data,
202 unsigned int size)
203{
204 return vchi_msg_queue(handle,
205 vchi_queue_kernel_message_callback,
206 data,
207 size);
208}
209EXPORT_SYMBOL(vchi_queue_kernel_message);
210
211struct vchi_queue_user_message_context {
212 void __user *data;
213};
214
215static ssize_t
216vchi_queue_user_message_callback(void *context,
217 void *dest,
218 size_t offset,
219 size_t maxsize)
220{
221 struct vchi_queue_user_message_context *copycontext = context;
222
223 if (copy_from_user(dest, copycontext->data + offset, maxsize))
224 return -EFAULT;
225
226 return maxsize;
227}
228
229int
230vchi_queue_user_message(VCHI_SERVICE_HANDLE_T handle,
231 void __user *data,
232 unsigned int size)
233{
234 struct vchi_queue_user_message_context copycontext = {
235 .data = data
236 };
237
238 return vchi_msg_queue(handle,
239 vchi_queue_user_message_callback,
240 &copycontext,
241 size);
242}
243EXPORT_SYMBOL(vchi_queue_user_message);
190 244
191/*********************************************************** 245/***********************************************************
192 * Name: vchi_bulk_queue_receive 246 * Name: vchi_bulk_queue_receive
@@ -527,7 +581,7 @@ static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
527 SHIM_SERVICE_T *service = 581 SHIM_SERVICE_T *service =
528 (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle); 582 (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
529 583
530 if (!service->callback) 584 if (!service->callback)
531 goto release; 585 goto release;
532 586
533 switch (reason) { 587 switch (reason) {
@@ -577,7 +631,7 @@ static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
577 } 631 }
578 632
579release: 633release:
580 vchiq_release_message(service->handle, header); 634 vchiq_release_message(service->handle, header);
581done: 635done:
582 return VCHIQ_SUCCESS; 636 return VCHIQ_SUCCESS;
583} 637}
@@ -739,16 +793,18 @@ int32_t vchi_service_set_option(const VCHI_SERVICE_HANDLE_T handle,
739} 793}
740EXPORT_SYMBOL(vchi_service_set_option); 794EXPORT_SYMBOL(vchi_service_set_option);
741 795
742int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version ) 796int32_t vchi_get_peer_version(const VCHI_SERVICE_HANDLE_T handle, short *peer_version)
743{ 797{
744 int32_t ret = -1; 798 int32_t ret = -1;
745 SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle; 799 SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
746 if(service) 800 if (service)
747 { 801 {
748 VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version); 802 VCHIQ_STATUS_T status;
749 ret = vchiq_status_to_vchi( status ); 803
750 } 804 status = vchiq_get_peer_version(service->handle, peer_version);
751 return ret; 805 ret = vchiq_status_to_vchi(status);
806 }
807 return ret;
752} 808}
753EXPORT_SYMBOL(vchi_get_peer_version); 809EXPORT_SYMBOL(vchi_get_peer_version);
754 810
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c
index f76f4d790532..e0ba0ed704fd 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c
@@ -80,9 +80,8 @@ void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
80 return; 80 return;
81 81
82 while (queue->write == queue->read + queue->size) { 82 while (queue->write == queue->read + queue->size) {
83 if (down_interruptible(&queue->pop) != 0) { 83 if (down_interruptible(&queue->pop) != 0)
84 flush_signals(current); 84 flush_signals(current);
85 }
86 } 85 }
87 86
88 /* 87 /*
@@ -107,9 +106,8 @@ void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
107VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue) 106VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
108{ 107{
109 while (queue->write == queue->read) { 108 while (queue->write == queue->read) {
110 if (down_interruptible(&queue->push) != 0) { 109 if (down_interruptible(&queue->push) != 0)
111 flush_signals(current); 110 flush_signals(current);
112 }
113 } 111 }
114 112
115 up(&queue->push); // We haven't removed anything from the queue. 113 up(&queue->push); // We haven't removed anything from the queue.
@@ -128,9 +126,8 @@ VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
128 VCHIQ_HEADER_T *header; 126 VCHIQ_HEADER_T *header;
129 127
130 while (queue->write == queue->read) { 128 while (queue->write == queue->read) {
131 if (down_interruptible(&queue->push) != 0) { 129 if (down_interruptible(&queue->push) != 0)
132 flush_signals(current); 130 flush_signals(current);
133 }
134 } 131 }
135 132
136 /* 133 /*
diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c
index 87aa5174df22..69e9a7705afb 100644
--- a/drivers/staging/vme/devices/vme_user.c
+++ b/drivers/staging/vme/devices/vme_user.c
@@ -47,7 +47,8 @@ static const char driver_name[] = "vme_user";
47static int bus[VME_USER_BUS_MAX]; 47static int bus[VME_USER_BUS_MAX];
48static unsigned int bus_num; 48static unsigned int bus_num;
49 49
50/* Currently Documentation/admin-guide/devices.rst defines the following for VME: 50/* Currently Documentation/admin-guide/devices.rst defines the
51 * following for VME:
51 * 52 *
52 * 221 char VME bus 53 * 221 char VME bus
53 * 0 = /dev/bus/vme/m0 First master image 54 * 0 = /dev/bus/vme/m0 First master image
diff --git a/drivers/staging/vt6655/baseband.h b/drivers/staging/vt6655/baseband.h
index 8a567c9155b4..c351e03f6ad2 100644
--- a/drivers/staging/vt6655/baseband.h
+++ b/drivers/staging/vt6655/baseband.h
@@ -75,13 +75,13 @@ void BBvSetShortSlotTime(struct vnt_private *);
75void BBvSetVGAGainOffset(struct vnt_private *, unsigned char byData); 75void BBvSetVGAGainOffset(struct vnt_private *, unsigned char byData);
76 76
77/* VT3253 Baseband */ 77/* VT3253 Baseband */
78bool BBbVT3253Init(struct vnt_private *); 78bool BBbVT3253Init(struct vnt_private *priv);
79void BBvSoftwareReset(struct vnt_private *); 79void BBvSoftwareReset(struct vnt_private *priv);
80void BBvPowerSaveModeON(struct vnt_private *); 80void BBvPowerSaveModeON(struct vnt_private *priv);
81void BBvPowerSaveModeOFF(struct vnt_private *); 81void BBvPowerSaveModeOFF(struct vnt_private *priv);
82void BBvSetTxAntennaMode(struct vnt_private *, unsigned char byAntennaMode); 82void BBvSetTxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode);
83void BBvSetRxAntennaMode(struct vnt_private *, unsigned char byAntennaMode); 83void BBvSetRxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode);
84void BBvSetDeepSleep(struct vnt_private *, unsigned char byLocalID); 84void BBvSetDeepSleep(struct vnt_private *priv, unsigned char byLocalID);
85void BBvExitDeepSleep(struct vnt_private *, unsigned char byLocalID); 85void BBvExitDeepSleep(struct vnt_private *priv, unsigned char byLocalID);
86 86
87#endif /* __BASEBAND_H__ */ 87#endif /* __BASEBAND_H__ */
diff --git a/drivers/staging/vt6656/card.h b/drivers/staging/vt6656/card.h
index c2cde7e92c8f..7f08cda27e2c 100644
--- a/drivers/staging/vt6656/card.h
+++ b/drivers/staging/vt6656/card.h
@@ -35,21 +35,23 @@
35 35
36struct vnt_private; 36struct vnt_private;
37 37
38void vnt_set_channel(struct vnt_private *, u32); 38void vnt_set_channel(struct vnt_private *priv, u32 connection_channel);
39void vnt_set_rspinf(struct vnt_private *, u8); 39void vnt_set_rspinf(struct vnt_private *priv, u8 bb_type);
40void vnt_update_ifs(struct vnt_private *); 40void vnt_update_ifs(struct vnt_private *priv);
41void vnt_update_top_rates(struct vnt_private *); 41void vnt_update_top_rates(struct vnt_private *priv);
42int vnt_ofdm_min_rate(struct vnt_private *); 42int vnt_ofdm_min_rate(struct vnt_private *priv);
43void vnt_adjust_tsf(struct vnt_private *, u8, u64, u64); 43void vnt_adjust_tsf(struct vnt_private *priv, u8 rx_rate,
44bool vnt_get_current_tsf(struct vnt_private *, u64 *); 44 u64 time_stamp, u64 local_tsf);
45bool vnt_clear_current_tsf(struct vnt_private *); 45bool vnt_get_current_tsf(struct vnt_private *priv, u64 *current_tsf);
46void vnt_reset_next_tbtt(struct vnt_private *, u16); 46bool vnt_clear_current_tsf(struct vnt_private *priv);
47void vnt_update_next_tbtt(struct vnt_private *, u64, u16); 47void vnt_reset_next_tbtt(struct vnt_private *priv, u16 beacon_interval);
48u64 vnt_get_next_tbtt(u64, u16); 48void vnt_update_next_tbtt(struct vnt_private *priv, u64 tsf,
49u64 vnt_get_tsf_offset(u8 byRxRate, u64 qwTSF1, u64 qwTSF2); 49 u16 beacon_interval);
50int vnt_radio_power_off(struct vnt_private *); 50u64 vnt_get_next_tbtt(u64 tsf, u16 beacon_interval);
51int vnt_radio_power_on(struct vnt_private *); 51u64 vnt_get_tsf_offset(u8 rx_rate, u64 tsf1, u64 tsf2);
52u8 vnt_get_pkt_type(struct vnt_private *); 52int vnt_radio_power_off(struct vnt_private *priv);
53void vnt_set_bss_mode(struct vnt_private *); 53int vnt_radio_power_on(struct vnt_private *priv);
54u8 vnt_get_pkt_type(struct vnt_private *priv);
55void vnt_set_bss_mode(struct vnt_private *priv);
54 56
55#endif /* __CARD_H__ */ 57#endif /* __CARD_H__ */
diff --git a/drivers/staging/vt6656/channel.h b/drivers/staging/vt6656/channel.h
index fcea6995fe26..62f18a959098 100644
--- a/drivers/staging/vt6656/channel.h
+++ b/drivers/staging/vt6656/channel.h
@@ -28,6 +28,6 @@
28 28
29#include "device.h" 29#include "device.h"
30 30
31void vnt_init_bands(struct vnt_private *); 31void vnt_init_bands(struct vnt_private *priv);
32 32
33#endif /* _CHANNEL_H_ */ 33#endif /* _CHANNEL_H_ */
diff --git a/drivers/staging/vt6656/dpc.h b/drivers/staging/vt6656/dpc.h
index ff1850c4a927..5d0454f3af0e 100644
--- a/drivers/staging/vt6656/dpc.h
+++ b/drivers/staging/vt6656/dpc.h
@@ -28,7 +28,7 @@
28 28
29#include "device.h" 29#include "device.h"
30 30
31int vnt_rx_data(struct vnt_private *, struct vnt_rcb *, 31int vnt_rx_data(struct vnt_private *priv, struct vnt_rcb *ptr_rcb,
32 unsigned long bytes_received); 32 unsigned long bytes_received);
33 33
34#endif /* __RXTX_H__ */ 34#endif /* __RXTX_H__ */
diff --git a/drivers/staging/vt6656/firmware.c b/drivers/staging/vt6656/firmware.c
index 1b48f9c86f63..282f665aacfa 100644
--- a/drivers/staging/vt6656/firmware.c
+++ b/drivers/staging/vt6656/firmware.c
@@ -64,11 +64,11 @@ int vnt_download_firmware(struct vnt_private *priv)
64 memcpy(buffer, fw->data + ii, length); 64 memcpy(buffer, fw->data + ii, length);
65 65
66 status = vnt_control_out(priv, 66 status = vnt_control_out(priv,
67 0, 67 0,
68 0x1200+ii, 68 0x1200+ii,
69 0x0000, 69 0x0000,
70 length, 70 length,
71 buffer); 71 buffer);
72 72
73 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size); 73 dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
74 74
@@ -94,11 +94,11 @@ int vnt_firmware_branch_to_sram(struct vnt_private *priv)
94 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n"); 94 dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
95 95
96 status = vnt_control_out(priv, 96 status = vnt_control_out(priv,
97 1, 97 1,
98 0x1200, 98 0x1200,
99 0x0000, 99 0x0000,
100 0, 100 0,
101 NULL); 101 NULL);
102 return status == STATUS_SUCCESS; 102 return status == STATUS_SUCCESS;
103} 103}
104 104
@@ -107,14 +107,14 @@ int vnt_check_firmware_version(struct vnt_private *priv)
107 int status; 107 int status;
108 108
109 status = vnt_control_in(priv, 109 status = vnt_control_in(priv,
110 MESSAGE_TYPE_READ, 110 MESSAGE_TYPE_READ,
111 0, 111 0,
112 MESSAGE_REQUEST_VERSION, 112 MESSAGE_REQUEST_VERSION,
113 2, 113 2,
114 (u8 *)&priv->firmware_version); 114 (u8 *)&priv->firmware_version);
115 115
116 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n", 116 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
117 priv->firmware_version); 117 priv->firmware_version);
118 118
119 if (status != STATUS_SUCCESS) { 119 if (status != STATUS_SUCCESS) {
120 dev_dbg(&priv->usb->dev, "Firmware Invalid.\n"); 120 dev_dbg(&priv->usb->dev, "Firmware Invalid.\n");
@@ -126,7 +126,7 @@ int vnt_check_firmware_version(struct vnt_private *priv)
126 } 126 }
127 127
128 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n", 128 dev_dbg(&priv->usb->dev, "Firmware Version [%04x]\n",
129 priv->firmware_version); 129 priv->firmware_version);
130 130
131 if (priv->firmware_version < FIRMWARE_VERSION) { 131 if (priv->firmware_version < FIRMWARE_VERSION) {
132 /* branch to loader for download new firmware */ 132 /* branch to loader for download new firmware */
diff --git a/drivers/staging/vt6656/firmware.h b/drivers/staging/vt6656/firmware.h
index e2b54acb8fdb..f753019c94c9 100644
--- a/drivers/staging/vt6656/firmware.h
+++ b/drivers/staging/vt6656/firmware.h
@@ -28,8 +28,8 @@
28 28
29#include "device.h" 29#include "device.h"
30 30
31int vnt_download_firmware(struct vnt_private *); 31int vnt_download_firmware(struct vnt_private *priv);
32int vnt_firmware_branch_to_sram(struct vnt_private *); 32int vnt_firmware_branch_to_sram(struct vnt_private *priv);
33int vnt_check_firmware_version(struct vnt_private *); 33int vnt_check_firmware_version(struct vnt_private *priv);
34 34
35#endif /* __FIRMWARE_H__ */ 35#endif /* __FIRMWARE_H__ */
diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c
index 73538fb4e4e2..c6ffbe0e2728 100644
--- a/drivers/staging/vt6656/int.c
+++ b/drivers/staging/vt6656/int.c
@@ -142,7 +142,7 @@ void vnt_int_process_data(struct vnt_private *priv)
142 142
143 if (int_data->isr0 != 0) { 143 if (int_data->isr0 != 0) {
144 if (int_data->isr0 & ISR_BNTX && 144 if (int_data->isr0 & ISR_BNTX &&
145 priv->op_mode == NL80211_IFTYPE_AP) 145 priv->op_mode == NL80211_IFTYPE_AP)
146 vnt_schedule_command(priv, WLAN_CMD_BECON_SEND); 146 vnt_schedule_command(priv, WLAN_CMD_BECON_SEND);
147 147
148 if (int_data->isr0 & ISR_TBTT && 148 if (int_data->isr0 & ISR_TBTT &&
diff --git a/drivers/staging/vt6656/int.h b/drivers/staging/vt6656/int.h
index 97e55bacbb7c..b5f1b4b02ce4 100644
--- a/drivers/staging/vt6656/int.h
+++ b/drivers/staging/vt6656/int.h
@@ -51,7 +51,7 @@ struct vnt_interrupt_data {
51 u8 sw[2]; 51 u8 sw[2];
52} __packed; 52} __packed;
53 53
54void vnt_int_start_interrupt(struct vnt_private *); 54void vnt_int_start_interrupt(struct vnt_private *priv);
55void vnt_int_process_data(struct vnt_private *); 55void vnt_int_process_data(struct vnt_private *priv);
56 56
57#endif /* __INT_H__ */ 57#endif /* __INT_H__ */
diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c
index 0246a8fc47fe..cc18cb141bff 100644
--- a/drivers/staging/vt6656/key.c
+++ b/drivers/staging/vt6656/key.c
@@ -44,8 +44,8 @@ int vnt_key_init_table(struct vnt_private *priv)
44} 44}
45 45
46static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr, 46static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
47 struct ieee80211_key_conf *key, u32 key_type, u32 mode, 47 struct ieee80211_key_conf *key, u32 key_type,
48 bool onfly_latch) 48 u32 mode, bool onfly_latch)
49{ 49{
50 struct vnt_private *priv = hw->priv; 50 struct vnt_private *priv = hw->priv;
51 u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 51 u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
@@ -115,7 +115,7 @@ static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
115} 115}
116 116
117int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 117int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
118 struct ieee80211_vif *vif, struct ieee80211_key_conf *key) 118 struct ieee80211_vif *vif, struct ieee80211_key_conf *key)
119{ 119{
120 struct ieee80211_bss_conf *conf = &vif->bss_conf; 120 struct ieee80211_bss_conf *conf = &vif->bss_conf;
121 struct vnt_private *priv = hw->priv; 121 struct vnt_private *priv = hw->priv;
@@ -138,7 +138,7 @@ int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
138 vnt_mac_disable_keyentry(priv, u); 138 vnt_mac_disable_keyentry(priv, u);
139 139
140 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY, 140 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY,
141 KEY_CTL_WEP, true); 141 KEY_CTL_WEP, true);
142 142
143 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 143 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
144 144
@@ -161,13 +161,13 @@ int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
161 161
162 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { 162 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
163 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_PAIRWISE, 163 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_PAIRWISE,
164 key_dec_mode, true); 164 key_dec_mode, true);
165 } else { 165 } else {
166 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY, 166 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY,
167 key_dec_mode, true); 167 key_dec_mode, true);
168 168
169 vnt_set_keymode(hw, (u8 *)conf->bssid, key, 169 vnt_set_keymode(hw, (u8 *)conf->bssid, key,
170 VNT_KEY_GROUP_ADDRESS, key_dec_mode, true); 170 VNT_KEY_GROUP_ADDRESS, key_dec_mode, true);
171 } 171 }
172 172
173 return 0; 173 return 0;
diff --git a/drivers/staging/vt6656/key.h b/drivers/staging/vt6656/key.h
index 7861faf5138f..906d3454591d 100644
--- a/drivers/staging/vt6656/key.h
+++ b/drivers/staging/vt6656/key.h
@@ -43,9 +43,9 @@
43#define VNT_KEY_ONFLY 0x8000 43#define VNT_KEY_ONFLY 0x8000
44#define VNT_KEY_ONFLY_ALL 0x4000 44#define VNT_KEY_ONFLY_ALL 0x4000
45 45
46int vnt_key_init_table(struct vnt_private *); 46int vnt_key_init_table(struct vnt_private *priv);
47 47
48int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta, 48int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
49 struct ieee80211_vif *vif, struct ieee80211_key_conf *key); 49 struct ieee80211_vif *vif, struct ieee80211_key_conf *key);
50 50
51#endif /* __KEY_H__ */ 51#endif /* __KEY_H__ */
diff --git a/drivers/staging/vt6656/mac.c b/drivers/staging/vt6656/mac.c
index 611da4929ddc..417fdad1f9ae 100644
--- a/drivers/staging/vt6656/mac.c
+++ b/drivers/staging/vt6656/mac.c
@@ -50,7 +50,7 @@ void vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter)
50 __le64 le_mc = cpu_to_le64(mc_filter); 50 __le64 le_mc = cpu_to_le64(mc_filter);
51 51
52 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0, 52 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_MAR0,
53 MESSAGE_REQUEST_MACREG, sizeof(le_mc), (u8 *)&le_mc); 53 MESSAGE_REQUEST_MACREG, sizeof(le_mc), (u8 *)&le_mc);
54} 54}
55 55
56/* 56/*
@@ -77,7 +77,7 @@ void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
77 data[1] = EnCFG_BBType_MASK; 77 data[1] = EnCFG_BBType_MASK;
78 78
79 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0, 79 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
80 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 80 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
81} 81}
82 82
83/* 83/*
@@ -97,7 +97,7 @@ void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type)
97void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx) 97void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
98{ 98{
99 vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0, 99 vnt_control_out(priv, MESSAGE_TYPE_CLRKEYENTRY, 0, 0,
100 sizeof(entry_idx), &entry_idx); 100 sizeof(entry_idx), &entry_idx);
101} 101}
102 102
103/* 103/*
@@ -115,7 +115,7 @@ void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx)
115 * 115 *
116 */ 116 */
117void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx, 117void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
118 u32 key_idx, u8 *addr, u8 *key) 118 u32 key_idx, u8 *addr, u8 *key)
119{ 119{
120 struct vnt_mac_set_key set_key; 120 struct vnt_mac_set_key set_key;
121 u16 offset; 121 u16 offset;
@@ -132,10 +132,11 @@ void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
132 memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP); 132 memcpy(set_key.key, key, WLAN_KEY_LEN_CCMP);
133 133
134 dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n", 134 dev_dbg(&priv->usb->dev, "offset %d key ctl %d set key %24ph\n",
135 offset, key_ctl, (u8 *)&set_key); 135 offset, key_ctl, (u8 *)&set_key);
136 136
137 vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset, 137 vnt_control_out(priv, MESSAGE_TYPE_SETKEY, offset,
138 (u16)key_idx, sizeof(struct vnt_mac_set_key), (u8 *)&set_key); 138 (u16)key_idx, sizeof(struct vnt_mac_set_key),
139 (u8 *)&set_key);
139} 140}
140 141
141void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits) 142void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
@@ -146,7 +147,8 @@ void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits)
146 data[1] = bits; 147 data[1] = bits;
147 148
148 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 149 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK,
149 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 150 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data),
151 data);
150} 152}
151 153
152void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits) 154void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
@@ -156,8 +158,8 @@ void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits)
156 data[0] = bits; 158 data[0] = bits;
157 data[1] = bits; 159 data[1] = bits;
158 160
159 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 161 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, reg_ofs,
160 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 162 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
161} 163}
162 164
163void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word) 165void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
@@ -167,14 +169,14 @@ void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word)
167 data[0] = (u8)(word & 0xff); 169 data[0] = (u8)(word & 0xff);
168 data[1] = (u8)(word >> 8); 170 data[1] = (u8)(word >> 8);
169 171
170 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 172 vnt_control_out(priv, MESSAGE_TYPE_WRITE, reg_ofs,
171 reg_ofs, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 173 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
172} 174}
173 175
174void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr) 176void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr)
175{ 177{
176 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0, 178 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BSSID0,
177 MESSAGE_REQUEST_MACREG, ETH_ALEN, addr); 179 MESSAGE_REQUEST_MACREG, ETH_ALEN, addr);
178} 180}
179 181
180void vnt_mac_enable_protect_mode(struct vnt_private *priv) 182void vnt_mac_enable_protect_mode(struct vnt_private *priv)
@@ -184,8 +186,8 @@ void vnt_mac_enable_protect_mode(struct vnt_private *priv)
184 data[0] = EnCFG_ProtectMd; 186 data[0] = EnCFG_ProtectMd;
185 data[1] = EnCFG_ProtectMd; 187 data[1] = EnCFG_ProtectMd;
186 188
187 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 189 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
188 MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 190 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
189} 191}
190 192
191void vnt_mac_disable_protect_mode(struct vnt_private *priv) 193void vnt_mac_disable_protect_mode(struct vnt_private *priv)
@@ -195,8 +197,8 @@ void vnt_mac_disable_protect_mode(struct vnt_private *priv)
195 data[0] = 0; 197 data[0] = 0;
196 data[1] = EnCFG_ProtectMd; 198 data[1] = EnCFG_ProtectMd;
197 199
198 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 200 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG0,
199 MAC_REG_ENCFG0, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 201 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
200} 202}
201 203
202void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv) 204void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
@@ -206,8 +208,8 @@ void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv)
206 data[0] = EnCFG_BarkerPream; 208 data[0] = EnCFG_BarkerPream;
207 data[1] = EnCFG_BarkerPream; 209 data[1] = EnCFG_BarkerPream;
208 210
209 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 211 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
210 MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 212 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
211} 213}
212 214
213void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv) 215void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
@@ -217,8 +219,8 @@ void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv)
217 data[0] = 0; 219 data[0] = 0;
218 data[1] = EnCFG_BarkerPream; 220 data[1] = EnCFG_BarkerPream;
219 221
220 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, 222 vnt_control_out(priv, MESSAGE_TYPE_WRITE_MASK, MAC_REG_ENCFG2,
221 MAC_REG_ENCFG2, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 223 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
222} 224}
223 225
224void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval) 226void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
@@ -228,8 +230,8 @@ void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval)
228 data[0] = (u8)(interval & 0xff); 230 data[0] = (u8)(interval & 0xff);
229 data[1] = (u8)(interval >> 8); 231 data[1] = (u8)(interval >> 8);
230 232
231 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 233 vnt_control_out(priv, MESSAGE_TYPE_WRITE, MAC_REG_BI,
232 MAC_REG_BI, MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data); 234 MESSAGE_REQUEST_MACREG, ARRAY_SIZE(data), data);
233} 235}
234 236
235void vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led) 237void vnt_mac_set_led(struct vnt_private *priv, u8 state, u8 led)
diff --git a/drivers/staging/vt6656/mac.h b/drivers/staging/vt6656/mac.h
index 4c6e610f1bc1..29f37a0ff156 100644
--- a/drivers/staging/vt6656/mac.h
+++ b/drivers/staging/vt6656/mac.h
@@ -364,20 +364,21 @@ struct vnt_mac_set_key {
364 u8 key[WLAN_KEY_LEN_CCMP]; 364 u8 key[WLAN_KEY_LEN_CCMP];
365} __packed; 365} __packed;
366 366
367void vnt_mac_set_filter(struct vnt_private *, u64); 367void vnt_mac_set_filter(struct vnt_private *priv, u64 mc_filter);
368void vnt_mac_shutdown(struct vnt_private *); 368void vnt_mac_shutdown(struct vnt_private *priv);
369void vnt_mac_set_bb_type(struct vnt_private *, u8); 369void vnt_mac_set_bb_type(struct vnt_private *priv, u8 type);
370void vnt_mac_disable_keyentry(struct vnt_private *, u8); 370void vnt_mac_disable_keyentry(struct vnt_private *priv, u8 entry_idx);
371void vnt_mac_set_keyentry(struct vnt_private *, u16, u32, u32, u8 *, u8 *); 371void vnt_mac_set_keyentry(struct vnt_private *priv, u16 key_ctl, u32 entry_idx,
372void vnt_mac_reg_bits_off(struct vnt_private *, u8, u8); 372 u32 key_idx, u8 *addr, u8 *key);
373void vnt_mac_reg_bits_on(struct vnt_private *, u8, u8); 373void vnt_mac_reg_bits_off(struct vnt_private *priv, u8 reg_ofs, u8 bits);
374void vnt_mac_write_word(struct vnt_private *, u8, u16); 374void vnt_mac_reg_bits_on(struct vnt_private *priv, u8 reg_ofs, u8 bits);
375void vnt_mac_set_bssid_addr(struct vnt_private *, u8 *); 375void vnt_mac_write_word(struct vnt_private *priv, u8 reg_ofs, u16 word);
376void vnt_mac_enable_protect_mode(struct vnt_private *); 376void vnt_mac_set_bssid_addr(struct vnt_private *priv, u8 *addr);
377void vnt_mac_disable_protect_mode(struct vnt_private *); 377void vnt_mac_enable_protect_mode(struct vnt_private *priv);
378void vnt_mac_enable_barker_preamble_mode(struct vnt_private *); 378void vnt_mac_disable_protect_mode(struct vnt_private *priv);
379void vnt_mac_disable_barker_preamble_mode(struct vnt_private *); 379void vnt_mac_enable_barker_preamble_mode(struct vnt_private *priv);
380void vnt_mac_set_beacon_interval(struct vnt_private *, u16); 380void vnt_mac_disable_barker_preamble_mode(struct vnt_private *priv);
381void vnt_mac_set_led(struct vnt_private *priv, u8, u8); 381void vnt_mac_set_beacon_interval(struct vnt_private *priv, u16 interval);
382void vnt_mac_set_led(struct vnt_private *privpriv, u8 state, u8 led);
382 383
383#endif /* __MAC_H__ */ 384#endif /* __MAC_H__ */
diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index 50d02d9aa535..9e074e9daf4e 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -128,7 +128,7 @@ static int vnt_init_registers(struct vnt_private *priv)
128 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0; 128 u8 calib_tx_iq = 0, calib_tx_dc = 0, calib_rx_iq = 0;
129 129
130 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n", 130 dev_dbg(&priv->usb->dev, "---->INIbInitAdapter. [%d][%d]\n",
131 DEVICE_INIT_COLD, priv->packet_type); 131 DEVICE_INIT_COLD, priv->packet_type);
132 132
133 if (!vnt_check_firmware_version(priv)) { 133 if (!vnt_check_firmware_version(priv)) {
134 if (vnt_download_firmware(priv) == true) { 134 if (vnt_download_firmware(priv) == true) {
@@ -156,16 +156,17 @@ static int vnt_init_registers(struct vnt_private *priv)
156 init_cmd->long_retry_limit = priv->long_retry_limit; 156 init_cmd->long_retry_limit = priv->long_retry_limit;
157 157
158 /* issue card_init command to device */ 158 /* issue card_init command to device */
159 status = vnt_control_out(priv, 159 status = vnt_control_out(priv, MESSAGE_TYPE_CARDINIT, 0, 0,
160 MESSAGE_TYPE_CARDINIT, 0, 0, 160 sizeof(struct vnt_cmd_card_init),
161 sizeof(struct vnt_cmd_card_init), (u8 *)init_cmd); 161 (u8 *)init_cmd);
162 if (status != STATUS_SUCCESS) { 162 if (status != STATUS_SUCCESS) {
163 dev_dbg(&priv->usb->dev, "Issue Card init fail\n"); 163 dev_dbg(&priv->usb->dev, "Issue Card init fail\n");
164 return false; 164 return false;
165 } 165 }
166 166
167 status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0, 167 status = vnt_control_in(priv, MESSAGE_TYPE_INIT_RSP, 0, 0,
168 sizeof(struct vnt_rsp_card_init), (u8 *)init_rsp); 168 sizeof(struct vnt_rsp_card_init),
169 (u8 *)init_rsp);
169 if (status != STATUS_SUCCESS) { 170 if (status != STATUS_SUCCESS) {
170 dev_dbg(&priv->usb->dev, 171 dev_dbg(&priv->usb->dev,
171 "Cardinit request in status fail!\n"); 172 "Cardinit request in status fail!\n");
@@ -173,9 +174,8 @@ static int vnt_init_registers(struct vnt_private *priv)
173 } 174 }
174 175
175 /* local ID for AES functions */ 176 /* local ID for AES functions */
176 status = vnt_control_in(priv, MESSAGE_TYPE_READ, 177 status = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_LOCALID,
177 MAC_REG_LOCALID, MESSAGE_REQUEST_MACREG, 1, 178 MESSAGE_REQUEST_MACREG, 1, &priv->local_id);
178 &priv->local_id);
179 if (status != STATUS_SUCCESS) 179 if (status != STATUS_SUCCESS)
180 return false; 180 return false;
181 181
@@ -278,7 +278,6 @@ static int vnt_init_registers(struct vnt_private *priv)
278 if (priv->rf_type == RF_VT3226D0) { 278 if (priv->rf_type == RF_VT3226D0) {
279 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) && 279 if ((priv->eeprom[EEP_OFS_MAJOR_VER] == 0x1) &&
280 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) { 280 (priv->eeprom[EEP_OFS_MINOR_VER] >= 0x4)) {
281
282 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ]; 281 calib_tx_iq = priv->eeprom[EEP_OFS_CALIB_TX_IQ];
283 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC]; 282 calib_tx_dc = priv->eeprom[EEP_OFS_CALIB_TX_DC];
284 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ]; 283 calib_rx_iq = priv->eeprom[EEP_OFS_CALIB_RX_IQ];
@@ -340,17 +339,18 @@ static int vnt_init_registers(struct vnt_private *priv)
340 339
341 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) { 340 if ((priv->radio_ctl & EEP_RADIOCTL_ENABLE) != 0) {
342 status = vnt_control_in(priv, MESSAGE_TYPE_READ, 341 status = vnt_control_in(priv, MESSAGE_TYPE_READ,
343 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 1, &tmp); 342 MAC_REG_GPIOCTL1,
343 MESSAGE_REQUEST_MACREG, 1, &tmp);
344 344
345 if (status != STATUS_SUCCESS) 345 if (status != STATUS_SUCCESS)
346 return false; 346 return false;
347 347
348 if ((tmp & GPIO3_DATA) == 0) 348 if ((tmp & GPIO3_DATA) == 0)
349 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1, 349 vnt_mac_reg_bits_on(priv, MAC_REG_GPIOCTL1,
350 GPIO3_INTMD); 350 GPIO3_INTMD);
351 else 351 else
352 vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, 352 vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1,
353 GPIO3_INTMD); 353 GPIO3_INTMD);
354 } 354 }
355 355
356 vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38); 356 vnt_mac_set_led(priv, LEDSTS_TMLEN, 0x38);
@@ -430,7 +430,7 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
430 430
431 for (ii = 0; ii < priv->num_tx_context; ii++) { 431 for (ii = 0; ii < priv->num_tx_context; ii++) {
432 tx_context = kmalloc(sizeof(struct vnt_usb_send_context), 432 tx_context = kmalloc(sizeof(struct vnt_usb_send_context),
433 GFP_KERNEL); 433 GFP_KERNEL);
434 if (!tx_context) 434 if (!tx_context)
435 goto free_tx; 435 goto free_tx;
436 436
@@ -450,7 +450,7 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
450 priv->rcb[ii] = kzalloc(sizeof(struct vnt_rcb), GFP_KERNEL); 450 priv->rcb[ii] = kzalloc(sizeof(struct vnt_rcb), GFP_KERNEL);
451 if (!priv->rcb[ii]) { 451 if (!priv->rcb[ii]) {
452 dev_err(&priv->usb->dev, 452 dev_err(&priv->usb->dev,
453 "failed to allocate rcb no %d\n", ii); 453 "failed to allocate rcb no %d\n", ii);
454 goto free_rx_tx; 454 goto free_rx_tx;
455 } 455 }
456 456
@@ -496,7 +496,8 @@ free_tx:
496} 496}
497 497
498static void vnt_tx_80211(struct ieee80211_hw *hw, 498static void vnt_tx_80211(struct ieee80211_hw *hw,
499 struct ieee80211_tx_control *control, struct sk_buff *skb) 499 struct ieee80211_tx_control *control,
500 struct sk_buff *skb)
500{ 501{
501 struct vnt_private *priv = hw->priv; 502 struct vnt_private *priv = hw->priv;
502 503
@@ -610,7 +611,7 @@ static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
610} 611}
611 612
612static void vnt_remove_interface(struct ieee80211_hw *hw, 613static void vnt_remove_interface(struct ieee80211_hw *hw,
613 struct ieee80211_vif *vif) 614 struct ieee80211_vif *vif)
614{ 615{
615 struct vnt_private *priv = hw->priv; 616 struct vnt_private *priv = hw->priv;
616 617
@@ -653,7 +654,7 @@ static int vnt_config(struct ieee80211_hw *hw, u32 changed)
653 } 654 }
654 655
655 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || 656 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
656 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) { 657 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
657 vnt_set_channel(priv, conf->chandef.chan->hw_value); 658 vnt_set_channel(priv, conf->chandef.chan->hw_value);
658 659
659 if (conf->chandef.chan->band == NL80211_BAND_5GHZ) 660 if (conf->chandef.chan->band == NL80211_BAND_5GHZ)
@@ -682,8 +683,8 @@ static int vnt_config(struct ieee80211_hw *hw, u32 changed)
682} 683}
683 684
684static void vnt_bss_info_changed(struct ieee80211_hw *hw, 685static void vnt_bss_info_changed(struct ieee80211_hw *hw,
685 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf, 686 struct ieee80211_vif *vif,
686 u32 changed) 687 struct ieee80211_bss_conf *conf, u32 changed)
687{ 688{
688 struct vnt_private *priv = hw->priv; 689 struct vnt_private *priv = hw->priv;
689 690
@@ -692,7 +693,6 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
692 if (changed & BSS_CHANGED_BSSID && conf->bssid) 693 if (changed & BSS_CHANGED_BSSID && conf->bssid)
693 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid); 694 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
694 695
695
696 if (changed & BSS_CHANGED_BASIC_RATES) { 696 if (changed & BSS_CHANGED_BASIC_RATES) {
697 priv->basic_rates = conf->basic_rates; 697 priv->basic_rates = conf->basic_rates;
698 698
@@ -731,11 +731,11 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
731 731
732 if (changed & BSS_CHANGED_TXPOWER) 732 if (changed & BSS_CHANGED_TXPOWER)
733 vnt_rf_setpower(priv, priv->current_rate, 733 vnt_rf_setpower(priv, priv->current_rate,
734 conf->chandef.chan->hw_value); 734 conf->chandef.chan->hw_value);
735 735
736 if (changed & BSS_CHANGED_BEACON_ENABLED) { 736 if (changed & BSS_CHANGED_BEACON_ENABLED) {
737 dev_dbg(&priv->usb->dev, 737 dev_dbg(&priv->usb->dev,
738 "Beacon enable %d\n", conf->enable_beacon); 738 "Beacon enable %d\n", conf->enable_beacon);
739 739
740 if (conf->enable_beacon) { 740 if (conf->enable_beacon) {
741 vnt_beacon_enable(priv, vif, conf); 741 vnt_beacon_enable(priv, vif, conf);
@@ -768,7 +768,7 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
768} 768}
769 769
770static u64 vnt_prepare_multicast(struct ieee80211_hw *hw, 770static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
771 struct netdev_hw_addr_list *mc_list) 771 struct netdev_hw_addr_list *mc_list)
772{ 772{
773 struct vnt_private *priv = hw->priv; 773 struct vnt_private *priv = hw->priv;
774 struct netdev_hw_addr *ha; 774 struct netdev_hw_addr *ha;
@@ -787,7 +787,8 @@ static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
787} 787}
788 788
789static void vnt_configure(struct ieee80211_hw *hw, 789static void vnt_configure(struct ieee80211_hw *hw,
790 unsigned int changed_flags, unsigned int *total_flags, u64 multicast) 790 unsigned int changed_flags,
791 unsigned int *total_flags, u64 multicast)
791{ 792{
792 struct vnt_private *priv = hw->priv; 793 struct vnt_private *priv = hw->priv;
793 u8 rx_mode = 0; 794 u8 rx_mode = 0;
@@ -796,7 +797,7 @@ static void vnt_configure(struct ieee80211_hw *hw,
796 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC; 797 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
797 798
798 rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR, 799 rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
799 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode); 800 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
800 801
801 if (!rc) 802 if (!rc)
802 rx_mode = RCR_MULTICAST | RCR_BROADCAST; 803 rx_mode = RCR_MULTICAST | RCR_BROADCAST;
@@ -814,7 +815,6 @@ static void vnt_configure(struct ieee80211_hw *hw,
814 } else { 815 } else {
815 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST); 816 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
816 } 817 }
817
818 } 818 }
819 819
820 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) { 820 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
@@ -830,8 +830,8 @@ static void vnt_configure(struct ieee80211_hw *hw,
830} 830}
831 831
832static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 832static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
833 struct ieee80211_vif *vif, struct ieee80211_sta *sta, 833 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
834 struct ieee80211_key_conf *key) 834 struct ieee80211_key_conf *key)
835{ 835{
836 struct vnt_private *priv = hw->priv; 836 struct vnt_private *priv = hw->priv;
837 837
@@ -871,7 +871,7 @@ static void vnt_sw_scan_complete(struct ieee80211_hw *hw,
871} 871}
872 872
873static int vnt_get_stats(struct ieee80211_hw *hw, 873static int vnt_get_stats(struct ieee80211_hw *hw,
874 struct ieee80211_low_level_stats *stats) 874 struct ieee80211_low_level_stats *stats)
875{ 875{
876 struct vnt_private *priv = hw->priv; 876 struct vnt_private *priv = hw->priv;
877 877
@@ -925,7 +925,6 @@ static const struct ieee80211_ops vnt_mac_ops = {
925 925
926int vnt_init(struct vnt_private *priv) 926int vnt_init(struct vnt_private *priv)
927{ 927{
928
929 if (!(vnt_init_registers(priv))) 928 if (!(vnt_init_registers(priv)))
930 return -EAGAIN; 929 return -EAGAIN;
931 930
@@ -955,9 +954,9 @@ vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
955 udev = usb_get_dev(interface_to_usbdev(intf)); 954 udev = usb_get_dev(interface_to_usbdev(intf));
956 955
957 dev_notice(&udev->dev, "%s Ver. %s\n", 956 dev_notice(&udev->dev, "%s Ver. %s\n",
958 DEVICE_FULL_DRV_NAM, DEVICE_VERSION); 957 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
959 dev_notice(&udev->dev, 958 dev_notice(&udev->dev,
960 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n"); 959 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
961 960
962 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops); 961 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
963 if (!hw) { 962 if (!hw) {
diff --git a/drivers/staging/vt6656/power.h b/drivers/staging/vt6656/power.h
index 9d1ebb695f9d..859e75fc77ac 100644
--- a/drivers/staging/vt6656/power.h
+++ b/drivers/staging/vt6656/power.h
@@ -28,8 +28,8 @@
28 28
29#define C_PWBT 1000 /* micro sec. power up before TBTT */ 29#define C_PWBT 1000 /* micro sec. power up before TBTT */
30 30
31void vnt_disable_power_saving(struct vnt_private *); 31void vnt_disable_power_saving(struct vnt_private *priv);
32void vnt_enable_power_saving(struct vnt_private *, u16); 32void vnt_enable_power_saving(struct vnt_private *priv, u16 listen_interval);
33int vnt_next_tbtt_wakeup(struct vnt_private *); 33int vnt_next_tbtt_wakeup(struct vnt_private *priv);
34 34
35#endif /* __POWER_H__ */ 35#endif /* __POWER_H__ */
diff --git a/drivers/staging/vt6656/rf.c b/drivers/staging/vt6656/rf.c
index 6101a35582b6..068c1c89f653 100644
--- a/drivers/staging/vt6656/rf.c
+++ b/drivers/staging/vt6656/rf.c
@@ -771,7 +771,7 @@ int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate)
771 ret &= vnt_rf_write_embedded(priv, 0x015C0800); 771 ret &= vnt_rf_write_embedded(priv, 0x015C0800);
772 } else { 772 } else {
773 dev_dbg(&priv->usb->dev, 773 dev_dbg(&priv->usb->dev,
774 "@@@@ vnt_rf_set_txpower> 11G mode\n"); 774 "@@@@ vnt_rf_set_txpower> 11G mode\n");
775 775
776 power_setting = ((0x3f - power) << 20) | (0x7 << 8); 776 power_setting = ((0x3f - power) << 20) | (0x7 << 8);
777 777
@@ -876,7 +876,7 @@ void vnt_rf_table_download(struct vnt_private *priv)
876 memcpy(array, addr1, length1); 876 memcpy(array, addr1, length1);
877 877
878 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0, 878 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
879 MESSAGE_REQUEST_RF_INIT, length1, array); 879 MESSAGE_REQUEST_RF_INIT, length1, array);
880 880
881 /* Channel Table 0 */ 881 /* Channel Table 0 */
882 value = 0; 882 value = 0;
@@ -889,7 +889,7 @@ void vnt_rf_table_download(struct vnt_private *priv)
889 memcpy(array, addr2, length); 889 memcpy(array, addr2, length);
890 890
891 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 891 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
892 value, MESSAGE_REQUEST_RF_CH0, length, array); 892 value, MESSAGE_REQUEST_RF_CH0, length, array);
893 893
894 length2 -= length; 894 length2 -= length;
895 value += length; 895 value += length;
@@ -907,7 +907,7 @@ void vnt_rf_table_download(struct vnt_private *priv)
907 memcpy(array, addr3, length); 907 memcpy(array, addr3, length);
908 908
909 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 909 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
910 value, MESSAGE_REQUEST_RF_CH1, length, array); 910 value, MESSAGE_REQUEST_RF_CH1, length, array);
911 911
912 length3 -= length; 912 length3 -= length;
913 value += length; 913 value += length;
@@ -924,7 +924,7 @@ void vnt_rf_table_download(struct vnt_private *priv)
924 924
925 /* Init Table 2 */ 925 /* Init Table 2 */
926 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 926 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
927 0, MESSAGE_REQUEST_RF_INIT2, length1, array); 927 0, MESSAGE_REQUEST_RF_INIT2, length1, array);
928 928
929 /* Channel Table 0 */ 929 /* Channel Table 0 */
930 value = 0; 930 value = 0;
@@ -937,7 +937,7 @@ void vnt_rf_table_download(struct vnt_private *priv)
937 memcpy(array, addr2, length); 937 memcpy(array, addr2, length);
938 938
939 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 939 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
940 value, MESSAGE_REQUEST_RF_CH2, length, array); 940 value, MESSAGE_REQUEST_RF_CH2, length, array);
941 941
942 length2 -= length; 942 length2 -= length;
943 value += length; 943 value += length;
diff --git a/drivers/staging/vt6656/rf.h b/drivers/staging/vt6656/rf.h
index c3d4f06d65f4..c907a18047d2 100644
--- a/drivers/staging/vt6656/rf.h
+++ b/drivers/staging/vt6656/rf.h
@@ -50,10 +50,10 @@
50#define VNT_RF_MAX_POWER 0x3f 50#define VNT_RF_MAX_POWER 0x3f
51#define VNT_RF_REG_LEN 0x17 /* 24 bit length */ 51#define VNT_RF_REG_LEN 0x17 /* 24 bit length */
52 52
53int vnt_rf_write_embedded(struct vnt_private *, u32); 53int vnt_rf_write_embedded(struct vnt_private *priv, u32 data);
54int vnt_rf_setpower(struct vnt_private *, u32, u32); 54int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel);
55int vnt_rf_set_txpower(struct vnt_private *, u8, u32); 55int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate);
56void vnt_rf_rssi_to_dbm(struct vnt_private *, u8, long *); 56void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm);
57void vnt_rf_table_download(struct vnt_private *); 57void vnt_rf_table_download(struct vnt_private *priv);
58 58
59#endif /* __RF_H__ */ 59#endif /* __RF_H__ */
diff --git a/drivers/staging/vt6656/rxtx.c b/drivers/staging/vt6656/rxtx.c
index aa59e7f14ab3..1835cd13ef49 100644
--- a/drivers/staging/vt6656/rxtx.c
+++ b/drivers/staging/vt6656/rxtx.c
@@ -90,7 +90,7 @@ static struct vnt_usb_send_context
90 if (!context->in_use) { 90 if (!context->in_use) {
91 context->in_use = true; 91 context->in_use = true;
92 memset(context->data, 0, 92 memset(context->data, 0,
93 MAX_TOTAL_SIZE_WITH_ALL_HEADERS); 93 MAX_TOTAL_SIZE_WITH_ALL_HEADERS);
94 94
95 context->hdr = NULL; 95 context->hdr = NULL;
96 96
@@ -114,19 +114,19 @@ static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
114} 114}
115 115
116static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type, 116static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
117 u32 frame_length, u16 rate, int need_ack) 117 u32 frame_length, u16 rate, int need_ack)
118{ 118{
119 u32 data_time, ack_time; 119 u32 data_time, ack_time;
120 120
121 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 121 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
122 frame_length, rate); 122 frame_length, rate);
123 123
124 if (pkt_type == PK_TYPE_11B) 124 if (pkt_type == PK_TYPE_11B)
125 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 125 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
126 14, (u16)priv->top_cck_basic_rate); 126 14, (u16)priv->top_cck_basic_rate);
127 else 127 else
128 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 128 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
129 14, (u16)priv->top_ofdm_basic_rate); 129 14, (u16)priv->top_ofdm_basic_rate);
130 130
131 if (need_ack) 131 if (need_ack)
132 return data_time + priv->sifs + ack_time; 132 return data_time + priv->sifs + ack_time;
@@ -135,21 +135,21 @@ static u32 vnt_get_rsvtime(struct vnt_private *priv, u8 pkt_type,
135} 135}
136 136
137static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type, 137static __le16 vnt_rxtx_rsvtime_le16(struct vnt_private *priv, u8 pkt_type,
138 u32 frame_length, u16 rate, int need_ack) 138 u32 frame_length, u16 rate, int need_ack)
139{ 139{
140 return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type, 140 return cpu_to_le16((u16)vnt_get_rsvtime(priv, pkt_type,
141 frame_length, rate, need_ack)); 141 frame_length, rate, need_ack));
142} 142}
143 143
144static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv, 144static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
145 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate) 145 u8 rsv_type, u8 pkt_type, u32 frame_length, u16 current_rate)
146{ 146{
147 u32 rrv_time, rts_time, cts_time, ack_time, data_time; 147 u32 rrv_time, rts_time, cts_time, ack_time, data_time;
148 148
149 rrv_time = rts_time = cts_time = ack_time = data_time = 0; 149 rrv_time = rts_time = cts_time = ack_time = data_time = 0;
150 150
151 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 151 data_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
152 frame_length, current_rate); 152 frame_length, current_rate);
153 153
154 if (rsv_type == 0) { 154 if (rsv_type == 0) {
155 rts_time = vnt_get_frame_time(priv->preamble_type, 155 rts_time = vnt_get_frame_time(priv->preamble_type,
@@ -160,19 +160,19 @@ static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
160 rts_time = vnt_get_frame_time(priv->preamble_type, 160 rts_time = vnt_get_frame_time(priv->preamble_type,
161 pkt_type, 20, priv->top_cck_basic_rate); 161 pkt_type, 20, priv->top_cck_basic_rate);
162 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 162 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
163 14, priv->top_cck_basic_rate); 163 14, priv->top_cck_basic_rate);
164 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 164 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
165 14, priv->top_ofdm_basic_rate); 165 14, priv->top_ofdm_basic_rate);
166 } else if (rsv_type == 2) { 166 } else if (rsv_type == 2) {
167 rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 167 rts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
168 20, priv->top_ofdm_basic_rate); 168 20, priv->top_ofdm_basic_rate);
169 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type, 169 cts_time = ack_time = vnt_get_frame_time(priv->preamble_type,
170 pkt_type, 14, priv->top_ofdm_basic_rate); 170 pkt_type, 14, priv->top_ofdm_basic_rate);
171 } else if (rsv_type == 3) { 171 } else if (rsv_type == 3) {
172 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 172 cts_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
173 14, priv->top_cck_basic_rate); 173 14, priv->top_cck_basic_rate);
174 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type, 174 ack_time = vnt_get_frame_time(priv->preamble_type, pkt_type,
175 14, priv->top_ofdm_basic_rate); 175 14, priv->top_ofdm_basic_rate);
176 176
177 rrv_time = cts_time + ack_time + data_time + 2 * priv->sifs; 177 rrv_time = cts_time + ack_time + data_time + 2 * priv->sifs;
178 178
@@ -185,7 +185,7 @@ static __le16 vnt_get_rtscts_rsvtime_le(struct vnt_private *priv,
185} 185}
186 186
187static __le16 vnt_get_duration_le(struct vnt_private *priv, 187static __le16 vnt_get_duration_le(struct vnt_private *priv,
188 u8 pkt_type, int need_ack) 188 u8 pkt_type, int need_ack)
189{ 189{
190 u32 ack_time = 0; 190 u32 ack_time = 0;
191 191
@@ -220,17 +220,17 @@ static __le16 vnt_get_rtscts_duration_le(struct vnt_usb_send_context *context,
220 pkt_type, 14, priv->top_cck_basic_rate); 220 pkt_type, 14, priv->top_cck_basic_rate);
221 dur_time = cts_time + 2 * priv->sifs + 221 dur_time = cts_time + 2 * priv->sifs +
222 vnt_get_rsvtime(priv, pkt_type, 222 vnt_get_rsvtime(priv, pkt_type,
223 frame_length, rate, need_ack); 223 frame_length, rate, need_ack);
224 break; 224 break;
225 225
226 case RTSDUR_AA: 226 case RTSDUR_AA:
227 case RTSDUR_AA_F0: 227 case RTSDUR_AA_F0:
228 case RTSDUR_AA_F1: 228 case RTSDUR_AA_F1:
229 cts_time = vnt_get_frame_time(priv->preamble_type, 229 cts_time = vnt_get_frame_time(priv->preamble_type,
230 pkt_type, 14, priv->top_ofdm_basic_rate); 230 pkt_type, 14, priv->top_ofdm_basic_rate);
231 dur_time = cts_time + 2 * priv->sifs + 231 dur_time = cts_time + 2 * priv->sifs +
232 vnt_get_rsvtime(priv, pkt_type, 232 vnt_get_rsvtime(priv, pkt_type,
233 frame_length, rate, need_ack); 233 frame_length, rate, need_ack);
234 break; 234 break;
235 235
236 case CTSDUR_BA: 236 case CTSDUR_BA:
@@ -410,7 +410,7 @@ static u16 vnt_rxtx_rts_g_head(struct vnt_usb_send_context *tx_context,
410 u16 current_rate = tx_context->tx_rate; 410 u16 current_rate = tx_context->tx_rate;
411 411
412 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate, 412 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
413 PK_TYPE_11B, &buf->b); 413 PK_TYPE_11B, &buf->b);
414 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, 414 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
415 tx_context->pkt_type, &buf->a); 415 tx_context->pkt_type, &buf->a);
416 416
@@ -437,7 +437,7 @@ static u16 vnt_rxtx_rts_g_fb_head(struct vnt_usb_send_context *tx_context,
437 u16 rts_frame_len = 20; 437 u16 rts_frame_len = 20;
438 438
439 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate, 439 vnt_get_phy_field(priv, rts_frame_len, priv->top_cck_basic_rate,
440 PK_TYPE_11B, &buf->b); 440 PK_TYPE_11B, &buf->b);
441 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate, 441 vnt_get_phy_field(priv, rts_frame_len, priv->top_ofdm_basic_rate,
442 tx_context->pkt_type, &buf->a); 442 tx_context->pkt_type, &buf->a);
443 443
@@ -683,17 +683,17 @@ static u16 vnt_rxtx_ab(struct vnt_usb_send_context *tx_context,
683} 683}
684 684
685static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context, 685static u16 vnt_generate_tx_parameter(struct vnt_usb_send_context *tx_context,
686 struct vnt_tx_buffer *tx_buffer, 686 struct vnt_tx_buffer *tx_buffer,
687 struct vnt_mic_hdr **mic_hdr, u32 need_mic, 687 struct vnt_mic_hdr **mic_hdr, u32 need_mic,
688 bool need_rts) 688 bool need_rts)
689{ 689{
690 690
691 if (tx_context->pkt_type == PK_TYPE_11GB || 691 if (tx_context->pkt_type == PK_TYPE_11GB ||
692 tx_context->pkt_type == PK_TYPE_11GA) { 692 tx_context->pkt_type == PK_TYPE_11GA) {
693 if (need_rts) { 693 if (need_rts) {
694 if (need_mic) 694 if (need_mic)
695 *mic_hdr = &tx_buffer-> 695 *mic_hdr =
696 tx_head.tx_rts.tx.mic.hdr; 696 &tx_buffer->tx_head.tx_rts.tx.mic.hdr;
697 697
698 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head, 698 return vnt_rxtx_rts(tx_context, &tx_buffer->tx_head,
699 need_mic); 699 need_mic);
@@ -732,7 +732,7 @@ static void vnt_fill_txkey(struct vnt_usb_send_context *tx_context,
732 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) { 732 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
733 memcpy(key_buffer + 8, iv, 3); 733 memcpy(key_buffer + 8, iv, 3);
734 memcpy(key_buffer + 11, 734 memcpy(key_buffer + 11,
735 tx_key->key, WLAN_KEY_LEN_WEP40); 735 tx_key->key, WLAN_KEY_LEN_WEP40);
736 } 736 }
737 737
738 break; 738 break;
@@ -1024,11 +1024,11 @@ static int vnt_beacon_xmit(struct vnt_private *priv,
1024 1024
1025 /* Get SignalField,ServiceField,Length */ 1025 /* Get SignalField,ServiceField,Length */
1026 vnt_get_phy_field(priv, frame_size, current_rate, 1026 vnt_get_phy_field(priv, frame_size, current_rate,
1027 PK_TYPE_11A, &short_head->ab); 1027 PK_TYPE_11A, &short_head->ab);
1028 1028
1029 /* Get Duration and TimeStampOff */ 1029 /* Get Duration and TimeStampOff */
1030 short_head->duration = vnt_get_duration_le(priv, 1030 short_head->duration = vnt_get_duration_le(priv,
1031 PK_TYPE_11A, false); 1031 PK_TYPE_11A, false);
1032 short_head->time_stamp_off = 1032 short_head->time_stamp_off =
1033 vnt_time_stamp_off(priv, current_rate); 1033 vnt_time_stamp_off(priv, current_rate);
1034 } else { 1034 } else {
@@ -1037,7 +1037,7 @@ static int vnt_beacon_xmit(struct vnt_private *priv,
1037 1037
1038 /* Get SignalField,ServiceField,Length */ 1038 /* Get SignalField,ServiceField,Length */
1039 vnt_get_phy_field(priv, frame_size, current_rate, 1039 vnt_get_phy_field(priv, frame_size, current_rate,
1040 PK_TYPE_11B, &short_head->ab); 1040 PK_TYPE_11B, &short_head->ab);
1041 1041
1042 /* Get Duration and TimeStampOff */ 1042 /* Get Duration and TimeStampOff */
1043 short_head->duration = vnt_get_duration_le(priv, 1043 short_head->duration = vnt_get_duration_le(priv,
@@ -1101,7 +1101,7 @@ int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
1101} 1101}
1102 1102
1103int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif, 1103int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
1104 struct ieee80211_bss_conf *conf) 1104 struct ieee80211_bss_conf *conf)
1105{ 1105{
1106 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX); 1106 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1107 1107
diff --git a/drivers/staging/vt6656/rxtx.h b/drivers/staging/vt6656/rxtx.h
index 4a79c404275b..1ba8647bea86 100644
--- a/drivers/staging/vt6656/rxtx.h
+++ b/drivers/staging/vt6656/rxtx.h
@@ -249,9 +249,9 @@ struct vnt_beacon_buffer {
249 struct ieee80211_mgmt mgmt_hdr; 249 struct ieee80211_mgmt mgmt_hdr;
250} __packed; 250} __packed;
251 251
252int vnt_tx_packet(struct vnt_private *, struct sk_buff *); 252int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb);
253int vnt_beacon_make(struct vnt_private *, struct ieee80211_vif *); 253int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif);
254int vnt_beacon_enable(struct vnt_private *, struct ieee80211_vif *, 254int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
255 struct ieee80211_bss_conf *); 255 struct ieee80211_bss_conf *conf);
256 256
257#endif /* __RXTX_H__ */ 257#endif /* __RXTX_H__ */
diff --git a/drivers/staging/vt6656/usbpipe.c b/drivers/staging/vt6656/usbpipe.c
index e9b6b21f7422..1ae6a64c7fd4 100644
--- a/drivers/staging/vt6656/usbpipe.c
+++ b/drivers/staging/vt6656/usbpipe.c
@@ -44,7 +44,7 @@
44#define USB_CTL_WAIT 500 /* ms */ 44#define USB_CTL_WAIT 500 /* ms */
45 45
46int vnt_control_out(struct vnt_private *priv, u8 request, u16 value, 46int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
47 u16 index, u16 length, u8 *buffer) 47 u16 index, u16 length, u8 *buffer)
48{ 48{
49 int status = 0; 49 int status = 0;
50 50
@@ -68,11 +68,11 @@ int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
68void vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data) 68void vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 data)
69{ 69{
70 vnt_control_out(priv, MESSAGE_TYPE_WRITE, 70 vnt_control_out(priv, MESSAGE_TYPE_WRITE,
71 reg_off, reg, sizeof(u8), &data); 71 reg_off, reg, sizeof(u8), &data);
72} 72}
73 73
74int vnt_control_in(struct vnt_private *priv, u8 request, u16 value, 74int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
75 u16 index, u16 length, u8 *buffer) 75 u16 index, u16 length, u8 *buffer)
76{ 76{
77 int status; 77 int status;
78 78
@@ -82,8 +82,8 @@ int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
82 mutex_lock(&priv->usb_lock); 82 mutex_lock(&priv->usb_lock);
83 83
84 status = usb_control_msg(priv->usb, 84 status = usb_control_msg(priv->usb,
85 usb_rcvctrlpipe(priv->usb, 0), request, 0xc0, value, 85 usb_rcvctrlpipe(priv->usb, 0), request, 0xc0, value,
86 index, buffer, length, USB_CTL_WAIT); 86 index, buffer, length, USB_CTL_WAIT);
87 87
88 mutex_unlock(&priv->usb_lock); 88 mutex_unlock(&priv->usb_lock);
89 89
@@ -96,7 +96,7 @@ int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
96void vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data) 96void vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data)
97{ 97{
98 vnt_control_in(priv, MESSAGE_TYPE_READ, 98 vnt_control_in(priv, MESSAGE_TYPE_READ,
99 reg_off, reg, sizeof(u8), data); 99 reg_off, reg, sizeof(u8), data);
100} 100}
101 101
102static void vnt_start_interrupt_urb_complete(struct urb *urb) 102static void vnt_start_interrupt_urb_complete(struct urb *urb)
diff --git a/drivers/staging/vt6656/usbpipe.h b/drivers/staging/vt6656/usbpipe.h
index 8bafd9aee1fa..9fc5ac0ef6c1 100644
--- a/drivers/staging/vt6656/usbpipe.h
+++ b/drivers/staging/vt6656/usbpipe.h
@@ -28,14 +28,17 @@
28 28
29#include "device.h" 29#include "device.h"
30 30
31int vnt_control_out(struct vnt_private *, u8, u16, u16, u16, u8 *); 31int vnt_control_out(struct vnt_private *priv, u8 request, u16 value,
32int vnt_control_in(struct vnt_private *, u8, u16, u16, u16, u8 *); 32 u16 index, u16 length, u8 *buffer);
33int vnt_control_in(struct vnt_private *priv, u8 request, u16 value,
34 u16 index, u16 length, u8 *buffer);
33 35
34void vnt_control_out_u8(struct vnt_private *, u8, u8, u8); 36void vnt_control_out_u8(struct vnt_private *priv, u8 reg, u8 ref_off, u8 data);
35void vnt_control_in_u8(struct vnt_private *, u8, u8, u8 *); 37void vnt_control_in_u8(struct vnt_private *priv, u8 reg, u8 reg_off, u8 *data);
36 38
37int vnt_start_interrupt_urb(struct vnt_private *); 39int vnt_start_interrupt_urb(struct vnt_private *priv);
38int vnt_submit_rx_urb(struct vnt_private *, struct vnt_rcb *); 40int vnt_submit_rx_urb(struct vnt_private *priv, struct vnt_rcb *rcb);
39int vnt_tx_context(struct vnt_private *, struct vnt_usb_send_context *); 41int vnt_tx_context(struct vnt_private *priv,
42 struct vnt_usb_send_context *context);
40 43
41#endif /* __USBPIPE_H__ */ 44#endif /* __USBPIPE_H__ */
diff --git a/drivers/staging/vt6656/wcmd.c b/drivers/staging/vt6656/wcmd.c
index 95faaeb7432a..9f6cc2ef08dd 100644
--- a/drivers/staging/vt6656/wcmd.c
+++ b/drivers/staging/vt6656/wcmd.c
@@ -139,7 +139,7 @@ void vnt_run_command(struct work_struct *work)
139 139
140 case WLAN_CMD_CHANGE_ANTENNA_START: 140 case WLAN_CMD_CHANGE_ANTENNA_START:
141 dev_dbg(&priv->usb->dev, "Change from Antenna%d to", 141 dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
142 priv->rx_antenna_sel); 142 priv->rx_antenna_sel);
143 143
144 if (priv->rx_antenna_sel == 0) { 144 if (priv->rx_antenna_sel == 0) {
145 priv->rx_antenna_sel = 1; 145 priv->rx_antenna_sel = 1;
diff --git a/drivers/staging/vt6656/wcmd.h b/drivers/staging/vt6656/wcmd.h
index 764c09ccd42d..727ec14380c4 100644
--- a/drivers/staging/vt6656/wcmd.h
+++ b/drivers/staging/vt6656/wcmd.h
@@ -51,9 +51,9 @@ enum vnt_cmd_state {
51 51
52struct vnt_private; 52struct vnt_private;
53 53
54void vnt_reset_command_timer(struct vnt_private *); 54void vnt_reset_command_timer(struct vnt_private *priv);
55 55
56int vnt_schedule_command(struct vnt_private *, enum vnt_cmd); 56int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd);
57 57
58void vnt_run_command(struct work_struct *work); 58void vnt_run_command(struct work_struct *work);
59 59
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index b00ea75524e4..c307ccef790e 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3998,8 +3998,9 @@ static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo)
3998 pNewJoinBssParam->rsn_found = true; 3998 pNewJoinBssParam->rsn_found = true;
3999 index += pu8IEs[index + 1] + 2; 3999 index += pu8IEs[index + 1] + 2;
4000 continue; 4000 continue;
4001 } else 4001 } else {
4002 index += pu8IEs[index + 1] + 2; 4002 index += pu8IEs[index + 1] + 2;
4003 }
4003 } 4004 }
4004 } 4005 }
4005 4006
diff --git a/drivers/staging/wilc1000/linux_wlan.c b/drivers/staging/wilc1000/linux_wlan.c
index 3775706578b2..9ab43935869e 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -364,7 +364,7 @@ static int linux_wlan_start_firmware(struct net_device *dev)
364 return ret; 364 return ret;
365 365
366 if (!wait_for_completion_timeout(&wilc->sync_event, 366 if (!wait_for_completion_timeout(&wilc->sync_event,
367 msecs_to_jiffies(5000))) 367 msecs_to_jiffies(5000)))
368 return -ETIME; 368 return -ETIME;
369 369
370 return 0; 370 return 0;
@@ -992,7 +992,7 @@ int wilc_mac_xmit(struct sk_buff *skb, struct net_device *ndev)
992 tx_data->skb = skb; 992 tx_data->skb = skb;
993 993
994 eth_h = (struct ethhdr *)(skb->data); 994 eth_h = (struct ethhdr *)(skb->data);
995 if (eth_h->h_proto == 0x8e88) 995 if (eth_h->h_proto == cpu_to_be16(0x8e88))
996 netdev_dbg(ndev, "EAPOL transmitted\n"); 996 netdev_dbg(ndev, "EAPOL transmitted\n");
997 997
998 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr)); 998 ih = (struct iphdr *)(skb->data + sizeof(struct ethhdr));
diff --git a/drivers/staging/wilc1000/wilc_debugfs.c b/drivers/staging/wilc1000/wilc_debugfs.c
index 07260c497db4..7d32de930576 100644
--- a/drivers/staging/wilc1000/wilc_debugfs.c
+++ b/drivers/staging/wilc1000/wilc_debugfs.c
@@ -17,7 +17,6 @@
17 17
18#include "wilc_wlan_if.h" 18#include "wilc_wlan_if.h"
19 19
20
21static struct dentry *wilc_dir; 20static struct dentry *wilc_dir;
22 21
23/* 22/*
@@ -36,7 +35,6 @@ EXPORT_SYMBOL_GPL(WILC_DEBUG_LEVEL);
36 * -------------------------------------------------------------------------------- 35 * --------------------------------------------------------------------------------
37 */ 36 */
38 37
39
40static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos) 38static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
41{ 39{
42 char buf[128]; 40 char buf[128];
@@ -52,7 +50,7 @@ static ssize_t wilc_debug_level_read(struct file *file, char __user *userbuf, si
52} 50}
53 51
54static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf, 52static ssize_t wilc_debug_level_write(struct file *filp, const char __user *buf,
55 size_t count, loff_t *ppos) 53 size_t count, loff_t *ppos)
56{ 54{
57 int flag = 0; 55 int flag = 0;
58 int ret; 56 int ret;
diff --git a/drivers/staging/wilc1000/wilc_sdio.c b/drivers/staging/wilc1000/wilc_sdio.c
index 3ad7cec4662d..cd6b8badc5f3 100644
--- a/drivers/staging/wilc1000/wilc_sdio.c
+++ b/drivers/staging/wilc1000/wilc_sdio.c
@@ -81,7 +81,6 @@ static int wilc_sdio_cmd52(struct wilc *wilc, struct sdio_cmd52 *cmd)
81 return ret; 81 return ret;
82} 82}
83 83
84
85static int wilc_sdio_cmd53(struct wilc *wilc, struct sdio_cmd53 *cmd) 84static int wilc_sdio_cmd53(struct wilc *wilc, struct sdio_cmd53 *cmd)
86{ 85{
87 struct sdio_func *func = container_of(wilc->dev, struct sdio_func, dev); 86 struct sdio_func *func = container_of(wilc->dev, struct sdio_func, dev);
@@ -127,7 +126,7 @@ static int linux_sdio_probe(struct sdio_func *func,
127 126
128 dev_dbg(&func->dev, "Initializing netdev\n"); 127 dev_dbg(&func->dev, "Initializing netdev\n");
129 ret = wilc_netdev_init(&wilc, &func->dev, HIF_SDIO, gpio, 128 ret = wilc_netdev_init(&wilc, &func->dev, HIF_SDIO, gpio,
130 &wilc_hif_sdio); 129 &wilc_hif_sdio);
131 if (ret) { 130 if (ret) {
132 dev_err(&func->dev, "Couldn't initialize netdev\n"); 131 dev_err(&func->dev, "Couldn't initialize netdev\n");
133 return ret; 132 return ret;
@@ -915,7 +914,6 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
915 __LINE__); 914 __LINE__);
916 goto _fail_; 915 goto _fail_;
917 } 916 }
918
919 } 917 }
920 } else { 918 } else {
921 if (g_sdio.irq_gpio) { 919 if (g_sdio.irq_gpio) {
@@ -945,7 +943,6 @@ static int sdio_clear_int_ext(struct wilc *wilc, u32 val)
945 __LINE__); 943 __LINE__);
946 goto _fail_; 944 goto _fail_;
947 } 945 }
948
949 } 946 }
950 if (!ret) 947 if (!ret)
951 break; 948 break;
diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index c1a24f7bc85f..f7ce47cac2aa 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -665,6 +665,7 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
665{ 665{
666 s32 s32Error = 0; 666 s32 s32Error = 0;
667 u32 i; 667 u32 i;
668 u32 sel_bssi_idx = UINT_MAX;
668 u8 u8security = NO_ENCRYPT; 669 u8 u8security = NO_ENCRYPT;
669 enum AUTHTYPE tenuAuth_type = ANY; 670 enum AUTHTYPE tenuAuth_type = ANY;
670 671
@@ -688,18 +689,24 @@ static int connect(struct wiphy *wiphy, struct net_device *dev,
688 memcmp(last_scanned_shadow[i].ssid, 689 memcmp(last_scanned_shadow[i].ssid,
689 sme->ssid, 690 sme->ssid,
690 sme->ssid_len) == 0) { 691 sme->ssid_len) == 0) {
691 if (!sme->bssid) 692 if (!sme->bssid) {
692 break; 693 if (sel_bssi_idx == UINT_MAX ||
693 else 694 last_scanned_shadow[i].rssi >
695 last_scanned_shadow[sel_bssi_idx].rssi)
696 sel_bssi_idx = i;
697 } else {
694 if (memcmp(last_scanned_shadow[i].bssid, 698 if (memcmp(last_scanned_shadow[i].bssid,
695 sme->bssid, 699 sme->bssid,
696 ETH_ALEN) == 0) 700 ETH_ALEN) == 0) {
701 sel_bssi_idx = i;
697 break; 702 break;
703 }
704 }
698 } 705 }
699 } 706 }
700 707
701 if (i < last_scanned_cnt) { 708 if (sel_bssi_idx < last_scanned_cnt) {
702 pstrNetworkInfo = &last_scanned_shadow[i]; 709 pstrNetworkInfo = &last_scanned_shadow[sel_bssi_idx];
703 } else { 710 } else {
704 s32Error = -ENOENT; 711 s32Error = -ENOENT;
705 wilc_connecting = 0; 712 wilc_connecting = 0;
@@ -2285,8 +2292,11 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net, struct device *de
2285 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types; 2292 wdev->wiphy->mgmt_stypes = wilc_wfi_cfg80211_mgmt_types;
2286 2293
2287 wdev->wiphy->max_remain_on_channel_duration = 500; 2294 wdev->wiphy->max_remain_on_channel_duration = 500;
2288 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP) | BIT(NL80211_IFTYPE_MONITOR) | BIT(NL80211_IFTYPE_P2P_GO) | 2295 wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
2289 BIT(NL80211_IFTYPE_P2P_CLIENT); 2296 BIT(NL80211_IFTYPE_AP) |
2297 BIT(NL80211_IFTYPE_MONITOR) |
2298 BIT(NL80211_IFTYPE_P2P_GO) |
2299 BIT(NL80211_IFTYPE_P2P_CLIENT);
2290 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; 2300 wdev->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
2291 wdev->iftype = NL80211_IFTYPE_STATION; 2301 wdev->iftype = NL80211_IFTYPE_STATION;
2292 2302
diff --git a/drivers/staging/wlan-ng/cfg80211.c b/drivers/staging/wlan-ng/cfg80211.c
index aa0e5a3d4a89..11870cb3f254 100644
--- a/drivers/staging/wlan-ng/cfg80211.c
+++ b/drivers/staging/wlan-ng/cfg80211.c
@@ -483,8 +483,8 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,
483 msg_join.authtype.data = P80211ENUM_authalg_sharedkey; 483 msg_join.authtype.data = P80211ENUM_authalg_sharedkey;
484 else 484 else
485 netdev_warn(dev, 485 netdev_warn(dev,
486 "Unhandled authorisation type for connect (%d)\n", 486 "Unhandled authorisation type for connect (%d)\n",
487 sme->auth_type); 487 sme->auth_type);
488 488
489 /* Set the encryption - we only support wep */ 489 /* Set the encryption - we only support wep */
490 if (is_wep) { 490 if (is_wep) {
@@ -667,7 +667,7 @@ void prism2_disconnected(struct wlandevice *wlandev)
667void prism2_roamed(struct wlandevice *wlandev) 667void prism2_roamed(struct wlandevice *wlandev)
668{ 668{
669 cfg80211_roamed(wlandev->netdev, NULL, wlandev->bssid, 669 cfg80211_roamed(wlandev->netdev, NULL, wlandev->bssid,
670 NULL, 0, NULL, 0, GFP_KERNEL); 670 NULL, 0, NULL, 0, GFP_KERNEL);
671} 671}
672 672
673/* Structures for declaring wiphy interface */ 673/* Structures for declaring wiphy interface */
diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h
index 60caf9c37727..5f1851c85f12 100644
--- a/drivers/staging/wlan-ng/hfa384x.h
+++ b/drivers/staging/wlan-ng/hfa384x.h
@@ -1388,13 +1388,13 @@ static inline int hfa384x_drvr_getconfig16(struct hfa384x *hw, u16 rid, void *va
1388 1388
1389 result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(u16)); 1389 result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(u16));
1390 if (result == 0) 1390 if (result == 0)
1391 *((u16 *)val) = le16_to_cpu(*((u16 *)val)); 1391 le16_to_cpus(val);
1392 return result; 1392 return result;
1393} 1393}
1394 1394
1395static inline int hfa384x_drvr_setconfig16(struct hfa384x *hw, u16 rid, u16 val) 1395static inline int hfa384x_drvr_setconfig16(struct hfa384x *hw, u16 rid, u16 val)
1396{ 1396{
1397 u16 value = cpu_to_le16(val); 1397 __le16 value = cpu_to_le16(val);
1398 1398
1399 return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(value)); 1399 return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(value));
1400} 1400}
diff --git a/drivers/staging/wlan-ng/p80211conv.c b/drivers/staging/wlan-ng/p80211conv.c
index 8387e6a3031a..8b0905e7c9be 100644
--- a/drivers/staging/wlan-ng/p80211conv.c
+++ b/drivers/staging/wlan-ng/p80211conv.c
@@ -387,7 +387,7 @@ int skb_p80211_to_ether(struct wlandevice *wlandev, u32 ethconv,
387 (((memcmp(e_snap->oui, oui_rfc1042, 387 (((memcmp(e_snap->oui, oui_rfc1042,
388 WLAN_IEEE_OUI_LEN) == 0) && 388 WLAN_IEEE_OUI_LEN) == 0) &&
389 (ethconv == WLAN_ETHCONV_8021h) && 389 (ethconv == WLAN_ETHCONV_8021h) &&
390 (p80211_stt_findproto(le16_to_cpu(e_snap->type)))) || 390 (p80211_stt_findproto(be16_to_cpu(e_snap->type)))) ||
391 (memcmp(e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN) != 391 (memcmp(e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN) !=
392 0))) { 392 0))) {
393 pr_debug("SNAP+RFC1042 len: %d\n", payload_length); 393 pr_debug("SNAP+RFC1042 len: %d\n", payload_length);
diff --git a/drivers/staging/wlan-ng/p80211conv.h b/drivers/staging/wlan-ng/p80211conv.h
index ed70d98e5cf1..04bac2ed0e8a 100644
--- a/drivers/staging/wlan-ng/p80211conv.h
+++ b/drivers/staging/wlan-ng/p80211conv.h
@@ -130,7 +130,7 @@ struct p80211_metawep {
130struct wlan_ethhdr { 130struct wlan_ethhdr {
131 u8 daddr[ETH_ALEN]; 131 u8 daddr[ETH_ALEN];
132 u8 saddr[ETH_ALEN]; 132 u8 saddr[ETH_ALEN];
133 u16 type; 133 __be16 type;
134} __packed; 134} __packed;
135 135
136/* local llc header type */ 136/* local llc header type */
@@ -143,7 +143,7 @@ struct wlan_llc {
143/* local snap header type */ 143/* local snap header type */
144struct wlan_snap { 144struct wlan_snap {
145 u8 oui[WLAN_IEEE_OUI_LEN]; 145 u8 oui[WLAN_IEEE_OUI_LEN];
146 u16 type; 146 __be16 type;
147} __packed; 147} __packed;
148 148
149/* Circular include trick */ 149/* Circular include trick */
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index 53dbbd69e552..021fb23ae9ba 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -237,7 +237,7 @@ static int p80211_convert_to_ether(struct wlandevice *wlandev,
237 struct p80211_hdr_a3 *hdr; 237 struct p80211_hdr_a3 *hdr;
238 238
239 hdr = (struct p80211_hdr_a3 *)skb->data; 239 hdr = (struct p80211_hdr_a3 *)skb->data;
240 if (p80211_rx_typedrop(wlandev, hdr->fc)) 240 if (p80211_rx_typedrop(wlandev, le16_to_cpu(hdr->fc)))
241 return CONV_TO_ETHER_SKIPPED; 241 return CONV_TO_ETHER_SKIPPED;
242 242
243 /* perform mcast filtering: allow my local address through but reject 243 /* perform mcast filtering: allow my local address through but reject
diff --git a/drivers/staging/wlan-ng/prism2mgmt.c b/drivers/staging/wlan-ng/prism2mgmt.c
index c558ad656c49..0e671c3b308d 100644
--- a/drivers/staging/wlan-ng/prism2mgmt.c
+++ b/drivers/staging/wlan-ng/prism2mgmt.c
@@ -1303,14 +1303,13 @@ int prism2mgmt_wlansniff(struct wlandevice *wlandev, void *msgp)
1303 /* Set the driver state */ 1303 /* Set the driver state */
1304 /* Do we want the prism2 header? */ 1304 /* Do we want the prism2 header? */
1305 if ((msg->prismheader.status == 1305 if ((msg->prismheader.status ==
1306 P80211ENUM_msgitem_status_data_ok) 1306 P80211ENUM_msgitem_status_data_ok) &&
1307 && (msg->prismheader.data == P80211ENUM_truth_true)) { 1307 (msg->prismheader.data == P80211ENUM_truth_true)) {
1308 hw->sniffhdr = 0; 1308 hw->sniffhdr = 0;
1309 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM; 1309 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1310 } else 1310 } else if ((msg->wlanheader.status ==
1311 if ((msg->wlanheader.status == 1311 P80211ENUM_msgitem_status_data_ok) &&
1312 P80211ENUM_msgitem_status_data_ok) 1312 (msg->wlanheader.data == P80211ENUM_truth_true)) {
1313 && (msg->wlanheader.data == P80211ENUM_truth_true)) {
1314 hw->sniffhdr = 1; 1313 hw->sniffhdr = 1;
1315 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM; 1314 wlandev->netdev->type = ARPHRD_IEEE80211_PRISM;
1316 } else { 1315 } else {
diff --git a/drivers/staging/wlan-ng/prism2mib.c b/drivers/staging/wlan-ng/prism2mib.c
index 8ea6a647d037..28df1f3d6f4a 100644
--- a/drivers/staging/wlan-ng/prism2mib.c
+++ b/drivers/staging/wlan-ng/prism2mib.c
@@ -146,7 +146,6 @@ static int prism2mib_priv(struct mibrec *mib,
146 struct p80211msg_dot11req_mibset *msg, void *data); 146 struct p80211msg_dot11req_mibset *msg, void *data);
147 147
148static struct mibrec mibtab[] = { 148static struct mibrec mibtab[] = {
149
150 /* dot11smt MIB's */ 149 /* dot11smt MIB's */
151 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1), 150 {DIDmib_dot11smt_dot11WEPDefaultKeysTable_key(1),
152 F_STA | F_WRITE, 151 F_STA | F_WRITE,
@@ -624,7 +623,6 @@ static int prism2mib_excludeunencrypted(struct mibrec *mib,
624 struct p80211msg_dot11req_mibset *msg, 623 struct p80211msg_dot11req_mibset *msg,
625 void *data) 624 void *data)
626{ 625{
627
628 return prism2mib_flag(mib, isget, wlandev, hw, msg, data); 626 return prism2mib_flag(mib, isget, wlandev, hw, msg, data);
629} 627}
630 628
@@ -747,7 +745,7 @@ static int prism2mib_priv(struct mibrec *mib,
747 * pstr wlan message data 745 * pstr wlan message data
748 * 746 *
749 * Returns: 747 * Returns:
750 * Nothing 748 * Nothing
751 * 749 *
752 */ 750 */
753 751
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index 777cd6e11694..6930f7eb741b 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -607,8 +607,12 @@ static void XGIfb_bpp_to_var(struct xgifb_video_info *xgifb_info,
607{ 607{
608 switch (var->bits_per_pixel) { 608 switch (var->bits_per_pixel) {
609 case 8: 609 case 8:
610 var->red.offset = var->green.offset = var->blue.offset = 0; 610 var->red.offset = 0;
611 var->red.length = var->green.length = var->blue.length = 6; 611 var->green.offset = 0;
612 var->blue.offset = 0;
613 var->red.length = 6;
614 var->green.length = 6;
615 var->blue.length = 6;
612 xgifb_info->video_cmap_len = 256; 616 xgifb_info->video_cmap_len = 256;
613 break; 617 break;
614 case 16: 618 case 16:
@@ -1015,7 +1019,8 @@ static int XGIfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
1015 xgifb_info->video_vheight = info->var.yres_virtual; 1019 xgifb_info->video_vheight = info->var.yres_virtual;
1016 xgifb_info->video_height = 1020 xgifb_info->video_height =
1017 XGIbios_mode[xgifb_info->mode_idx].yres; 1021 XGIbios_mode[xgifb_info->mode_idx].yres;
1018 xgifb_info->org_x = xgifb_info->org_y = 0; 1022 xgifb_info->org_x = 0;
1023 xgifb_info->org_y = 0;
1019 xgifb_info->video_linelength = info->var.xres_virtual 1024 xgifb_info->video_linelength = info->var.xres_virtual
1020 * (xgifb_info->video_bpp >> 3); 1025 * (xgifb_info->video_bpp >> 3);
1021 switch (xgifb_info->video_bpp) { 1026 switch (xgifb_info->video_bpp) {
@@ -1311,10 +1316,12 @@ static int XGIfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1311 var->yoffset = var->yres_virtual - var->yres - 1; 1316 var->yoffset = var->yres_virtual - var->yres - 1;
1312 1317
1313 /* Set everything else to 0 */ 1318 /* Set everything else to 0 */
1314 var->red.msb_right = 1319 var->red.msb_right = 0;
1315 var->green.msb_right = 1320 var->green.msb_right = 0;
1316 var->blue.msb_right = 1321 var->blue.msb_right = 0;
1317 var->transp.offset = var->transp.length = var->transp.msb_right = 0; 1322 var->transp.offset = 0;
1323 var->transp.length = 0;
1324 var->transp.msb_right = 0;
1318 1325
1319 return 0; 1326 return 0;
1320} 1327}
@@ -1468,7 +1475,8 @@ static void XGIfb_detect_VB(struct xgifb_video_info *xgifb_info)
1468{ 1475{
1469 u8 cr32, temp = 0; 1476 u8 cr32, temp = 0;
1470 1477
1471 xgifb_info->TV_plug = xgifb_info->TV_type = 0; 1478 xgifb_info->TV_plug = 0;
1479 xgifb_info->TV_type = 0;
1472 1480
1473 cr32 = xgifb_reg_get(XGICR, IND_XGI_SCRATCH_REG_CR32); 1481 cr32 = xgifb_reg_get(XGICR, IND_XGI_SCRATCH_REG_CR32);
1474 1482
@@ -1738,7 +1746,9 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1738 goto error_0; 1746 goto error_0;
1739 } 1747 }
1740 1748
1741 xgifb_info->video_vbase = hw_info->pjVideoMemoryAddress = 1749 xgifb_info->video_vbase =
1750 ioremap_wc(xgifb_info->video_base, xgifb_info->video_size);
1751 hw_info->pjVideoMemoryAddress =
1742 ioremap_wc(xgifb_info->video_base, xgifb_info->video_size); 1752 ioremap_wc(xgifb_info->video_base, xgifb_info->video_size);
1743 xgifb_info->mmio_vbase = ioremap(xgifb_info->mmio_base, 1753 xgifb_info->mmio_vbase = ioremap(xgifb_info->mmio_base,
1744 xgifb_info->mmio_size); 1754 xgifb_info->mmio_size);
@@ -1897,7 +1907,8 @@ static int xgifb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1897 xgifb_info->video_vheight = 1907 xgifb_info->video_vheight =
1898 xgifb_info->video_height = 1908 xgifb_info->video_height =
1899 XGIbios_mode[xgifb_info->mode_idx].yres; 1909 XGIbios_mode[xgifb_info->mode_idx].yres;
1900 xgifb_info->org_x = xgifb_info->org_y = 0; 1910 xgifb_info->org_x = 0;
1911 xgifb_info->org_y = 0;
1901 xgifb_info->video_linelength = 1912 xgifb_info->video_linelength =
1902 xgifb_info->video_width * 1913 xgifb_info->video_width *
1903 (xgifb_info->video_bpp >> 3); 1914 (xgifb_info->video_bpp >> 3);
diff --git a/drivers/staging/xgifb/vb_init.c b/drivers/staging/xgifb/vb_init.c
index 14af157958cd..591a3c9babf5 100644
--- a/drivers/staging/xgifb/vb_init.c
+++ b/drivers/staging/xgifb/vb_init.c
@@ -579,8 +579,7 @@ static unsigned char XGINew_CheckFrequence(struct vb_device_info *pVBInfo)
579 579
580 if ((data & 0x10) == 0) { 580 if ((data & 0x10) == 0) {
581 data = xgifb_reg_get(pVBInfo->P3c4, 0x39); 581 data = xgifb_reg_get(pVBInfo->P3c4, 0x39);
582 data = (data & 0x02) >> 1; 582 return (data & 0x02) >> 1;
583 return data;
584 } 583 }
585 return data & 0x01; 584 return data & 0x01;
586} 585}
diff --git a/drivers/staging/xgifb/vb_setmode.h b/drivers/staging/xgifb/vb_setmode.h
index 6f082a7a5a4a..c6317ab00474 100644
--- a/drivers/staging/xgifb/vb_setmode.h
+++ b/drivers/staging/xgifb/vb_setmode.h
@@ -1,14 +1,14 @@
1#ifndef _VBSETMODE_ 1#ifndef _VBSETMODE_
2#define _VBSETMODE_ 2#define _VBSETMODE_
3 3
4void InitTo330Pointer(unsigned char, struct vb_device_info *); 4void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo);
5void XGI_UnLockCRT2(struct vb_device_info *); 5void XGI_UnLockCRT2(struct vb_device_info *pVBInfo);
6void XGI_LockCRT2(struct vb_device_info *); 6void XGI_LockCRT2(struct vb_device_info *pVBInfo);
7void XGI_DisplayOff(struct xgifb_video_info *, 7void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
8 struct xgi_hw_device_info *, 8 struct xgi_hw_device_info *pXGIHWDE,
9 struct vb_device_info *); 9 struct vb_device_info *pVBInfo);
10void XGI_GetVBType(struct vb_device_info *); 10void XGI_GetVBType(struct vb_device_info *pVBInfo);
11void XGI_SenseCRT1(struct vb_device_info *); 11void XGI_SenseCRT1(struct vb_device_info *pVBInfo);
12unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info, 12unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
13 struct xgi_hw_device_info *HwDeviceExtension, 13 struct xgi_hw_device_info *HwDeviceExtension,
14 unsigned short ModeNo); 14 unsigned short ModeNo);
@@ -18,6 +18,6 @@ unsigned char XGI_SearchModeID(unsigned short ModeNo,
18unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE, 18unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
19 unsigned short ModeNo, 19 unsigned short ModeNo,
20 unsigned short ModeIdIndex, 20 unsigned short ModeIdIndex,
21 struct vb_device_info *); 21 struct vb_device_info *pVBInfo);
22 22
23#endif 23#endif