aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/configfs-iio13
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio7
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio-health-afe440x63
-rw-r--r--Documentation/devicetree/bindings/iio/chemical/atlas,ec-sm.txt22
-rw-r--r--Documentation/devicetree/bindings/iio/st-sensors.txt1
-rw-r--r--MAINTAINERS2
-rw-r--r--drivers/iio/Kconfig8
-rw-r--r--drivers/iio/Makefile1
-rw-r--r--drivers/iio/accel/Kconfig20
-rw-r--r--drivers/iio/accel/Makefile3
-rw-r--r--drivers/iio/accel/bma220_spi.c338
-rw-r--r--drivers/iio/accel/mma7660.c277
-rw-r--r--drivers/iio/accel/mma8452.c185
-rw-r--r--drivers/iio/accel/st_accel_core.c12
-rw-r--r--drivers/iio/adc/ad7266.c7
-rw-r--r--drivers/iio/adc/ad7476.c11
-rw-r--r--drivers/iio/adc/ad7791.c36
-rw-r--r--drivers/iio/adc/ad7793.c32
-rw-r--r--drivers/iio/adc/ad7887.c11
-rw-r--r--drivers/iio/adc/ad7923.c11
-rw-r--r--drivers/iio/adc/ad799x.c24
-rw-r--r--drivers/iio/adc/mxs-lradc.c34
-rw-r--r--drivers/iio/adc/nau7802.c19
-rw-r--r--drivers/iio/adc/ti-ads1015.c128
-rw-r--r--drivers/iio/adc/ti_am335x_adc.c22
-rw-r--r--drivers/iio/chemical/Kconfig8
-rw-r--r--drivers/iio/chemical/atlas-ph-sensor.c267
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_buffer.c3
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c29
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_i2c.c4
-rw-r--r--drivers/iio/dummy/Kconfig1
-rw-r--r--drivers/iio/dummy/iio_simple_dummy.c102
-rw-r--r--drivers/iio/gyro/st_gyro_core.c12
-rw-r--r--drivers/iio/health/afe4403.c299
-rw-r--r--drivers/iio/health/afe4404.c308
-rw-r--r--drivers/iio/health/afe440x.h48
-rw-r--r--drivers/iio/humidity/am2315.c1
-rw-r--r--drivers/iio/humidity/htu21.c1
-rw-r--r--drivers/iio/imu/bmi160/bmi160_core.c27
-rw-r--r--drivers/iio/industrialio-core.c1
-rw-r--r--drivers/iio/industrialio-sw-device.c182
-rw-r--r--drivers/iio/industrialio-trigger.c13
-rw-r--r--drivers/iio/light/jsa1212.c3
-rw-r--r--drivers/iio/magnetometer/Kconfig2
-rw-r--r--drivers/iio/magnetometer/ak8975.c20
-rw-r--r--drivers/iio/magnetometer/bmc150_magn_i2c.c3
-rw-r--r--drivers/iio/magnetometer/bmc150_magn_spi.c3
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c12
-rw-r--r--drivers/iio/potentiometer/Kconfig11
-rw-r--r--drivers/iio/potentiometer/Makefile1
-rw-r--r--drivers/iio/potentiometer/max5487.c161
-rw-r--r--drivers/iio/potentiometer/tpl0102.c4
-rw-r--r--drivers/iio/pressure/Kconfig5
-rw-r--r--drivers/iio/pressure/bmp280.c200
-rw-r--r--drivers/iio/pressure/hp206c.c1
-rw-r--r--drivers/iio/pressure/ms5637.c1
-rw-r--r--drivers/iio/pressure/st_pressure.h1
-rw-r--r--drivers/iio/pressure/st_pressure_core.c105
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c4
-rw-r--r--drivers/iio/pressure/st_pressure_spi.c1
-rw-r--r--drivers/iio/proximity/as3935.c1
-rw-r--r--drivers/iio/temperature/tsys02d.c1
-rw-r--r--drivers/iio/trigger/Kconfig12
-rw-r--r--drivers/iio/trigger/Makefile1
-rw-r--r--drivers/iio/trigger/iio-trig-loop.c143
-rw-r--r--drivers/staging/Kconfig2
-rw-r--r--drivers/staging/Makefile1
-rw-r--r--drivers/staging/android/Kconfig17
-rw-r--r--drivers/staging/android/Makefile3
-rw-r--r--drivers/staging/android/sw_sync.c341
-rw-r--r--drivers/staging/android/sw_sync.h59
-rw-r--r--drivers/staging/android/sync.c221
-rw-r--r--drivers/staging/android/sync.h154
-rw-r--r--drivers/staging/android/sync_debug.c165
-rw-r--r--drivers/staging/android/sync_debug.h83
-rw-r--r--drivers/staging/android/trace/sync.h14
-rw-r--r--drivers/staging/android/uapi/sw_sync.h32
-rw-r--r--drivers/staging/comedi/comedi.h2
-rw-r--r--drivers/staging/comedi/comedi_fops.c21
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c187
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1564.c305
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9118.c8
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas64.c209
-rw-r--r--drivers/staging/comedi/drivers/comedi_bond.c10
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c380
-rw-r--r--drivers/staging/comedi/drivers/das16.c39
-rw-r--r--drivers/staging/comedi/drivers/das16m1.c482
-rw-r--r--drivers/staging/comedi/drivers/das6402.c74
-rw-r--r--drivers/staging/comedi/drivers/das800.c106
-rw-r--r--drivers/staging/comedi/drivers/dmm32at.c98
-rw-r--r--drivers/staging/comedi/drivers/dt2801.c95
-rw-r--r--drivers/staging/comedi/drivers/dt2811.c852
-rw-r--r--drivers/staging/comedi/drivers/dt2814.c72
-rw-r--r--drivers/staging/comedi/drivers/dt2815.c140
-rw-r--r--drivers/staging/comedi/drivers/dt2817.c64
-rw-r--r--drivers/staging/comedi/drivers/gsc_hpdi.c87
-rw-r--r--drivers/staging/comedi/drivers/jr3_pci.c36
-rw-r--r--drivers/staging/comedi/drivers/me_daq.c2
-rw-r--r--drivers/staging/comedi/drivers/mpc624.c4
-rw-r--r--drivers/staging/comedi/drivers/ni_65xx.c18
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c4
-rw-r--r--drivers/staging/comedi/drivers/ni_pcimio.c8
-rw-r--r--drivers/staging/comedi/drivers/pcmmio.c40
-rw-r--r--drivers/staging/comedi/drivers/pcmuio.c2
-rw-r--r--drivers/staging/comedi/drivers/plx9080.h957
-rw-r--r--drivers/staging/comedi/drivers/quatech_daqp_cs.c2
-rw-r--r--drivers/staging/comedi/drivers/rtd520.c15
-rw-r--r--drivers/staging/comedi/drivers/s626.c8
-rw-r--r--drivers/staging/comedi/drivers/s626.h356
-rw-r--r--drivers/staging/comedi/drivers/serial2002.c7
-rw-r--r--drivers/staging/ks7010/Kconfig10
-rw-r--r--drivers/staging/ks7010/Makefile4
-rw-r--r--drivers/staging/ks7010/TODO36
-rw-r--r--drivers/staging/ks7010/eap_packet.h129
-rw-r--r--drivers/staging/ks7010/ks7010_sdio.c1236
-rw-r--r--drivers/staging/ks7010/ks7010_sdio.h147
-rw-r--r--drivers/staging/ks7010/ks_hostif.c2760
-rw-r--r--drivers/staging/ks7010/ks_hostif.h644
-rw-r--r--drivers/staging/ks7010/ks_wlan.h505
-rw-r--r--drivers/staging/ks7010/ks_wlan_ioctl.h67
-rw-r--r--drivers/staging/ks7010/ks_wlan_net.c3528
-rw-r--r--drivers/staging/ks7010/michael_mic.c139
-rw-r--r--drivers/staging/ks7010/michael_mic.h26
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/curproc.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h4
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_prim.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_private.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_string.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_time.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h6
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h6
-rw-r--r--drivers/staging/lustre/include/linux/lnet/lib-dlc.h2
-rw-r--r--drivers/staging/lustre/include/linux/lnet/lib-types.h3
-rw-r--r--drivers/staging/lustre/include/linux/lnet/types.h4
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c354
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h307
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c384
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c8
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c308
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h209
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c204
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c40
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c2
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c74
-rw-r--r--drivers/staging/lustre/lnet/libcfs/debug.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/fail.c4
-rw-r--r--drivers/staging/lustre/lnet/libcfs/hash.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/libcfs_string.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c1
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-debug.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c2
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-module.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/linux/linux-tracefile.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/module.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/prng.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/tracefile.c6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/tracefile.h6
-rw-r--r--drivers/staging/lustre/lnet/libcfs/workitem.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/acceptor.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/api-ni.c8
-rw-r--r--drivers/staging/lustre/lnet/lnet/config.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-eq.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-md.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-me.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-move.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-msg.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/lo.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/module.c8
-rw-r--r--drivers/staging/lustre/lnet/lnet/net_fault.c4
-rw-r--r--drivers/staging/lustre/lnet/lnet/nidstrings.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/peer.c6
-rw-r--r--drivers/staging/lustre/lnet/lnet/router.c9
-rw-r--r--drivers/staging/lustre/lnet/selftest/brw_test.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/conctl.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/conrpc.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/conrpc.h6
-rw-r--r--drivers/staging/lustre/lnet/selftest/console.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/console.h6
-rw-r--r--drivers/staging/lustre/lnet/selftest/framework.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/module.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/ping_test.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/rpc.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/rpc.h6
-rw-r--r--drivers/staging/lustre/lnet/selftest/selftest.h7
-rw-r--r--drivers/staging/lustre/lnet/selftest/timer.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/timer.h6
-rw-r--r--drivers/staging/lustre/lustre/Kconfig6
-rw-r--r--drivers/staging/lustre/lustre/fid/fid_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/fid/fid_lib.c6
-rw-r--r--drivers/staging/lustre/lustre/fid/fid_request.c12
-rw-r--r--drivers/staging/lustre/lustre/fid/lproc_fid.c6
-rw-r--r--drivers/staging/lustre/lustre/fld/fld_cache.c6
-rw-r--r--drivers/staging/lustre/lustre/fld/fld_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/fld/fld_request.c6
-rw-r--r--drivers/staging/lustre/lustre/fld/lproc_fld.c6
-rw-r--r--drivers/staging/lustre/lustre/include/cl_object.h6
-rw-r--r--drivers/staging/lustre/lustre/include/interval_tree.h6
-rw-r--r--drivers/staging/lustre/lustre/include/linux/lustre_compat25.h6
-rw-r--r--drivers/staging/lustre/lustre/include/linux/lustre_lite.h6
-rw-r--r--drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h6
-rw-r--r--drivers/staging/lustre/lustre/include/linux/lustre_user.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lprocfs_status.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lu_object.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_idl.h10
-rw-r--r--drivers/staging/lustre/lustre/include/lustre/lustre_user.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_acl.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_cfg.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_debug.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_disk.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_dlm.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_eacl.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_export.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_fid.h8
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_fld.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_ha.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_handles.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_import.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_intent.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_lib.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_lite.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_log.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_mdc.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_mds.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_net.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_param.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_req_layout.h6
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_sec.h12
-rw-r--r--drivers/staging/lustre/lustre/include/obd.h6
-rw-r--r--drivers/staging/lustre/lustre/include/obd_cksum.h6
-rw-r--r--drivers/staging/lustre/lustre/include/obd_class.h6
-rw-r--r--drivers/staging/lustre/lustre/include/obd_support.h6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/interval_tree.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/l_lock.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_extent.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_flock.c15
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lib.c9
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lock.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c14
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_plain.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_pool.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_request.c6
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_resource.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/Makefile3
-rw-r--r--drivers/staging/lustre/lustre/llite/dcache.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/dir.c18
-rw-r--r--drivers/staging/lustre/lustre/llite/file.c18
-rw-r--r--drivers/staging/lustre/lustre/llite/glimpse.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/lcommon_cl.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/lcommon_misc.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_close.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_internal.h17
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_lib.c9
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_mmap.c11
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_nfs.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_rmtacl.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/lloop.c883
-rw-r--r--drivers/staging/lustre/lustre/llite/lproc_llite.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/namei.c9
-rw-r--r--drivers/staging/lustre/lustre/llite/remote_perm.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/rw.c151
-rw-r--r--drivers/staging/lustre/lustre/llite/rw26.c23
-rw-r--r--drivers/staging/lustre/lustre/llite/statahead.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/super25.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/symlink.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_dev.c16
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_io.c15
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_lock.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_object.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_page.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_req.c12
-rw-r--r--drivers/staging/lustre/lustre/llite/xattr.c6
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_fld.c6
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_intent.c6
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_obd.c9
-rw-r--r--drivers/staging/lustre/lustre/lmv/lproc_lmv.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_cl_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_dev.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_ea.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_io.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_lock.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_merge.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_obd.c15
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_object.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_offset.c8
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_pack.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_page.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_pool.c8
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_request.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lovsub_dev.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lovsub_io.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lovsub_lock.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lovsub_object.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lovsub_page.c6
-rw-r--r--drivers/staging/lustre/lustre/lov/lproc_lov.c6
-rw-r--r--drivers/staging/lustre/lustre/mdc/lproc_mdc.c6
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_lib.c6
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_locks.c6
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_reint.c6
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_request.c10
-rw-r--r--drivers/staging/lustre/lustre/mgc/lproc_mgc.c6
-rw-r--r--drivers/staging/lustre/lustre/mgc/mgc_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/mgc/mgc_request.c10
-rw-r--r--drivers/staging/lustre/lustre/obdclass/acl.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_io.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_lock.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_object.c12
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_page.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/class_obd.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/debug.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/genops.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/kernelcomm.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-module.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog.c12
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_cat.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_obd.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_swab.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lprocfs_status.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lu_object.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lu_ref.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lustre_handles.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lustre_peer.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_config.c12
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_mount.c8
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obdo.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/statfs_pack.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/uuid.c6
-rw-r--r--drivers/staging/lustre/lustre/obdecho/echo_client.c6
-rw-r--r--drivers/staging/lustre/lustre/osc/lproc_osc.c6
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_cache.c12
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_cl_internal.h11
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_dev.c6
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_io.c18
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_lock.c9
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_object.c6
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_page.c28
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_request.c12
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/client.c12
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/connection.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/events.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/import.c9
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/layout.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/llog_client.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/llog_net.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c10
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/niobuf.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/nrs.c2
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pack_generic.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pers.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pinger.c9
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/recover.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec.c13
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c8
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_config.c8
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_gc.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_lproc.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_null.c13
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_plain.c24
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/service.c6
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/wiretest.c6
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211.h4
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c54
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c34
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c6
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.c30
-rw-r--r--drivers/staging/rtl8192u/r8180_93cx6.h2
-rw-r--r--drivers/staging/rtl8192u/r8192U.h11
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c198
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.c80
-rw-r--r--drivers/staging/unisys/visorbus/iovmcall_gnuc.h4
-rw-r--r--drivers/staging/unisys/visorbus/visorbus_main.c12
-rw-r--r--drivers/staging/unisys/visorbus/visorchipset.c2
-rw-r--r--drivers/staging/unisys/visorhba/visorhba_main.c394
-rw-r--r--drivers/staging/unisys/visorinput/visorinput.c2
-rw-r--r--drivers/staging/unisys/visornic/visornic_main.c73
-rw-r--r--include/linux/fence.h2
-rw-r--r--include/linux/iio/common/st_sensors.h4
-rw-r--r--include/linux/iio/sw_device.h70
-rw-r--r--include/uapi/linux/iio/types.h1
-rw-r--r--tools/iio/Makefile21
-rw-r--r--tools/iio/iio_generic_buffer.c (renamed from tools/iio/generic_buffer.c)261
402 files changed, 16906 insertions, 7314 deletions
diff --git a/Documentation/ABI/testing/configfs-iio b/Documentation/ABI/testing/configfs-iio
index 2483756fccf5..aebda53ec0f7 100644
--- a/Documentation/ABI/testing/configfs-iio
+++ b/Documentation/ABI/testing/configfs-iio
@@ -19,3 +19,16 @@ KernelVersion: 4.4
19Description: 19Description:
20 High resolution timers directory. Creating a directory here 20 High resolution timers directory. Creating a directory here
21 will result in creating a hrtimer trigger in the IIO subsystem. 21 will result in creating a hrtimer trigger in the IIO subsystem.
22
23What: /config/iio/devices
24Date: April 2016
25KernelVersion: 4.7
26Description:
27 Industrial IO software devices directory.
28
29What: /config/iio/devices/dummy
30Date: April 2016
31KernelVersion: 4.7
32Description:
33 Dummy IIO devices directory. Creating a directory here will result
34 in creating a dummy IIO device in the IIO subystem.
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index df44998e7506..e7f590c6ef8e 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -1565,3 +1565,10 @@ Description:
1565 * X is in the plane of the propellers, perpendicular to Y axis, 1565 * X is in the plane of the propellers, perpendicular to Y axis,
1566 and positive towards the starboard side of the UAV ; 1566 and positive towards the starboard side of the UAV ;
1567 * Z is perpendicular to propellers plane and positive upwards. 1567 * Z is perpendicular to propellers plane and positive upwards.
1568
1569What: /sys/bus/iio/devices/iio:deviceX/in_electricalconductivity_raw
1570KernelVersion: 4.8
1571Contact: linux-iio@vger.kernel.org
1572Description:
1573 Raw (unscaled no offset etc.) electric conductivity reading that
1574 can be processed to siemens per meter.
diff --git a/Documentation/ABI/testing/sysfs-bus-iio-health-afe440x b/Documentation/ABI/testing/sysfs-bus-iio-health-afe440x
index 3740f253d406..6adba9058b22 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio-health-afe440x
+++ b/Documentation/ABI/testing/sysfs-bus-iio-health-afe440x
@@ -1,54 +1,41 @@
1What: /sys/bus/iio/devices/iio:deviceX/tia_resistanceY 1What: /sys/bus/iio/devices/iio:deviceX/in_intensityY_raw
2 /sys/bus/iio/devices/iio:deviceX/tia_capacitanceY 2Date: May 2016
3Date: December 2015
4KernelVersion:
5Contact: Andrew F. Davis <afd@ti.com>
6Description:
7 Get and set the resistance and the capacitance settings for the
8 Transimpedance Amplifier. Y is 1 for Rf1 and Cf1, Y is 2 for
9 Rf2 and Cf2 values.
10
11What: /sys/bus/iio/devices/iio:deviceX/tia_separate_en
12Date: December 2015
13KernelVersion:
14Contact: Andrew F. Davis <afd@ti.com>
15Description:
16 Enable or disable separate settings for the TransImpedance
17 Amplifier above, when disabled both values are set by the
18 first channel.
19
20What: /sys/bus/iio/devices/iio:deviceX/in_intensity_ledY_raw
21 /sys/bus/iio/devices/iio:deviceX/in_intensity_ledY_ambient_raw
22Date: December 2015
23KernelVersion: 3KernelVersion:
24Contact: Andrew F. Davis <afd@ti.com> 4Contact: Andrew F. Davis <afd@ti.com>
25Description: 5Description:
26 Get measured values from the ADC for these stages. Y is the 6 Get measured values from the ADC for these stages. Y is the
27 specific LED number. The values are expressed in 24-bit twos 7 specific stage number corresponding to datasheet stage names
28 complement. 8 as follows:
9 1 -> LED2
10 2 -> ALED2/LED3
11 3 -> LED1
12 4 -> ALED1/LED4
13 Note that channels 5 and 6 represent LED2-ALED2 and LED1-ALED1
14 respectively which simply helper channels containing the
15 calculated difference in the value of stage 1 - 2 and 3 - 4.
16 The values are expressed in 24-bit twos complement.
29 17
30What: /sys/bus/iio/devices/iio:deviceX/in_intensity_ledY-ledY_ambient_raw 18What: /sys/bus/iio/devices/iio:deviceX/in_intensityY_offset
31Date: December 2015 19Date: May 2016
32KernelVersion: 20KernelVersion:
33Contact: Andrew F. Davis <afd@ti.com> 21Contact: Andrew F. Davis <afd@ti.com>
34Description: 22Description:
35 Get differential values from the ADC for these stages. Y is the 23 Get and set the offset cancellation DAC setting for these
36 specific LED number. The values are expressed in 24-bit twos 24 stages. The values are expressed in 5-bit sign-magnitude.
37 complement for the specified LEDs.
38 25
39What: /sys/bus/iio/devices/iio:deviceX/out_current_ledY_offset 26What: /sys/bus/iio/devices/iio:deviceX/in_intensityY_resistance
40 /sys/bus/iio/devices/iio:deviceX/out_current_ledY_ambient_offset 27What: /sys/bus/iio/devices/iio:deviceX/in_intensityY_capacitance
41Date: December 2015 28Date: May 2016
42KernelVersion: 29KernelVersion:
43Contact: Andrew F. Davis <afd@ti.com> 30Contact: Andrew F. Davis <afd@ti.com>
44Description: 31Description:
45 Get and set the offset cancellation DAC setting for these 32 Get and set the resistance and the capacitance settings for the
46 stages. The values are expressed in 5-bit sign-magnitude. 33 Transimpedance Amplifier during the associated stage.
47 34
48What: /sys/bus/iio/devices/iio:deviceX/out_current_ledY_raw 35What: /sys/bus/iio/devices/iio:deviceX/out_currentY_raw
49Date: December 2015 36Date: May 2016
50KernelVersion: 37KernelVersion:
51Contact: Andrew F. Davis <afd@ti.com> 38Contact: Andrew F. Davis <afd@ti.com>
52Description: 39Description:
53 Get and set the LED current for the specified LED. Y is the 40 Get and set the LED current for the specified LED active during
54 specific LED number. 41 this stage. Y is the specific stage number.
diff --git a/Documentation/devicetree/bindings/iio/chemical/atlas,ec-sm.txt b/Documentation/devicetree/bindings/iio/chemical/atlas,ec-sm.txt
new file mode 100644
index 000000000000..2962bd9a2b3d
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/chemical/atlas,ec-sm.txt
@@ -0,0 +1,22 @@
1* Atlas Scientific EC-SM OEM sensor
2
3http://www.atlas-scientific.com/_files/_datasheets/_oem/EC_oem_datasheet.pdf
4
5Required properties:
6
7 - compatible: must be "atlas,ec-sm"
8 - reg: the I2C address of the sensor
9 - interrupt-parent: should be the phandle for the interrupt controller
10 - interrupts: the sole interrupt generated by the device
11
12 Refer to interrupt-controller/interrupts.txt for generic interrupt client
13 node bindings.
14
15Example:
16
17atlas@64 {
18 compatible = "atlas,ec-sm";
19 reg = <0x64>;
20 interrupt-parent = <&gpio1>;
21 interrupts = <16 2>;
22};
diff --git a/Documentation/devicetree/bindings/iio/st-sensors.txt b/Documentation/devicetree/bindings/iio/st-sensors.txt
index 5844cf72862d..e41fe340162b 100644
--- a/Documentation/devicetree/bindings/iio/st-sensors.txt
+++ b/Documentation/devicetree/bindings/iio/st-sensors.txt
@@ -64,3 +64,4 @@ Pressure sensors:
64- st,lps001wp-press 64- st,lps001wp-press
65- st,lps25h-press 65- st,lps25h-press
66- st,lps331ap-press 66- st,lps331ap-press
67- st,lps22hb-press
diff --git a/MAINTAINERS b/MAINTAINERS
index e1b090f86e0d..c1e4bf3ea8ec 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5786,6 +5786,7 @@ R: Lars-Peter Clausen <lars@metafoo.de>
5786R: Peter Meerwald-Stadler <pmeerw@pmeerw.net> 5786R: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
5787L: linux-iio@vger.kernel.org 5787L: linux-iio@vger.kernel.org
5788S: Maintained 5788S: Maintained
5789F: Documentation/devicetree/bindings/iio/
5789F: drivers/iio/ 5790F: drivers/iio/
5790F: drivers/staging/iio/ 5791F: drivers/staging/iio/
5791F: include/linux/iio/ 5792F: include/linux/iio/
@@ -10856,6 +10857,7 @@ STAGING - INDUSTRIAL IO
10856M: Jonathan Cameron <jic23@kernel.org> 10857M: Jonathan Cameron <jic23@kernel.org>
10857L: linux-iio@vger.kernel.org 10858L: linux-iio@vger.kernel.org
10858S: Odd Fixes 10859S: Odd Fixes
10860F: Documentation/devicetree/bindings/staging/iio/
10859F: drivers/staging/iio/ 10861F: drivers/staging/iio/
10860 10862
10861STAGING - LIRC (LINUX INFRARED REMOTE CONTROL) DRIVERS 10863STAGING - LIRC (LINUX INFRARED REMOTE CONTROL) DRIVERS
diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 505e921f0b19..6743b18194fb 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -46,6 +46,14 @@ config IIO_CONSUMERS_PER_TRIGGER
46 This value controls the maximum number of consumers that a 46 This value controls the maximum number of consumers that a
47 given trigger may handle. Default is 2. 47 given trigger may handle. Default is 2.
48 48
49config IIO_SW_DEVICE
50 tristate "Enable software IIO device support"
51 select IIO_CONFIGFS
52 help
53 Provides IIO core support for software devices. A software
54 device can be created via configfs or directly by a driver
55 using the API provided.
56
49config IIO_SW_TRIGGER 57config IIO_SW_TRIGGER
50 tristate "Enable software triggers support" 58 tristate "Enable software triggers support"
51 select IIO_CONFIGFS 59 select IIO_CONFIGFS
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index 20f649073462..87e4c4369e2f 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -8,6 +8,7 @@ industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
8industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o 8industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
9 9
10obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o 10obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o
11obj-$(CONFIG_IIO_SW_DEVICE) += industrialio-sw-device.o
11obj-$(CONFIG_IIO_SW_TRIGGER) += industrialio-sw-trigger.o 12obj-$(CONFIG_IIO_SW_TRIGGER) += industrialio-sw-trigger.o
12obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o 13obj-$(CONFIG_IIO_TRIGGERED_EVENT) += industrialio-triggered-event.o
13 14
diff --git a/drivers/iio/accel/Kconfig b/drivers/iio/accel/Kconfig
index e4a758cd7d35..31325870a9ef 100644
--- a/drivers/iio/accel/Kconfig
+++ b/drivers/iio/accel/Kconfig
@@ -17,6 +17,16 @@ config BMA180
17 To compile this driver as a module, choose M here: the 17 To compile this driver as a module, choose M here: the
18 module will be called bma180. 18 module will be called bma180.
19 19
20config BMA220
21 tristate "Bosch BMA220 3-Axis Accelerometer Driver"
22 depends on SPI
23 help
24 Say yes here to add support for the Bosch BMA220 triaxial
25 acceleration sensor.
26
27 To compile this driver as a module, choose M here: the
28 module will be called bma220_spi.
29
20config BMC150_ACCEL 30config BMC150_ACCEL
21 tristate "Bosch BMC150 Accelerometer Driver" 31 tristate "Bosch BMC150 Accelerometer Driver"
22 select IIO_BUFFER 32 select IIO_BUFFER
@@ -136,6 +146,16 @@ config MMA7455_SPI
136 To compile this driver as a module, choose M here: the module 146 To compile this driver as a module, choose M here: the module
137 will be called mma7455_spi. 147 will be called mma7455_spi.
138 148
149config MMA7660
150 tristate "Freescale MMA7660FC 3-Axis Accelerometer Driver"
151 depends on I2C
152 help
153 Say yes here to get support for the Freescale MMA7660FC 3-Axis
154 accelerometer.
155
156 Choosing M will build the driver as a module. If so, the module
157 will be called mma7660.
158
139config MMA8452 159config MMA8452
140 tristate "Freescale MMA8452Q and similar Accelerometers Driver" 160 tristate "Freescale MMA8452Q and similar Accelerometers Driver"
141 depends on I2C 161 depends on I2C
diff --git a/drivers/iio/accel/Makefile b/drivers/iio/accel/Makefile
index 71b6794de885..6cedbecca2ee 100644
--- a/drivers/iio/accel/Makefile
+++ b/drivers/iio/accel/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_BMA180) += bma180.o 6obj-$(CONFIG_BMA180) += bma180.o
7obj-$(CONFIG_BMA220) += bma220_spi.o
7obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o 8obj-$(CONFIG_BMC150_ACCEL) += bmc150-accel-core.o
8obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o 9obj-$(CONFIG_BMC150_ACCEL_I2C) += bmc150-accel-i2c.o
9obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o 10obj-$(CONFIG_BMC150_ACCEL_SPI) += bmc150-accel-spi.o
@@ -15,6 +16,8 @@ obj-$(CONFIG_MMA7455) += mma7455_core.o
15obj-$(CONFIG_MMA7455_I2C) += mma7455_i2c.o 16obj-$(CONFIG_MMA7455_I2C) += mma7455_i2c.o
16obj-$(CONFIG_MMA7455_SPI) += mma7455_spi.o 17obj-$(CONFIG_MMA7455_SPI) += mma7455_spi.o
17 18
19obj-$(CONFIG_MMA7660) += mma7660.o
20
18obj-$(CONFIG_MMA8452) += mma8452.o 21obj-$(CONFIG_MMA8452) += mma8452.o
19 22
20obj-$(CONFIG_MMA9551_CORE) += mma9551_core.o 23obj-$(CONFIG_MMA9551_CORE) += mma9551_core.o
diff --git a/drivers/iio/accel/bma220_spi.c b/drivers/iio/accel/bma220_spi.c
new file mode 100644
index 000000000000..1098d10df8e8
--- /dev/null
+++ b/drivers/iio/accel/bma220_spi.c
@@ -0,0 +1,338 @@
1/**
2 * BMA220 Digital triaxial acceleration sensor driver
3 *
4 * Copyright (c) 2016, Intel Corporation.
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 */
10
11#include <linux/acpi.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/iio/buffer.h>
15#include <linux/iio/iio.h>
16#include <linux/iio/sysfs.h>
17#include <linux/spi/spi.h>
18#include <linux/iio/trigger_consumer.h>
19#include <linux/iio/triggered_buffer.h>
20
21#define BMA220_REG_ID 0x00
22#define BMA220_REG_ACCEL_X 0x02
23#define BMA220_REG_ACCEL_Y 0x03
24#define BMA220_REG_ACCEL_Z 0x04
25#define BMA220_REG_RANGE 0x11
26#define BMA220_REG_SUSPEND 0x18
27
28#define BMA220_CHIP_ID 0xDD
29#define BMA220_READ_MASK 0x80
30#define BMA220_RANGE_MASK 0x03
31#define BMA220_DATA_SHIFT 2
32#define BMA220_SUSPEND_SLEEP 0xFF
33#define BMA220_SUSPEND_WAKE 0x00
34
35#define BMA220_DEVICE_NAME "bma220"
36#define BMA220_SCALE_AVAILABLE "0.623 1.248 2.491 4.983"
37
38#define BMA220_ACCEL_CHANNEL(index, reg, axis) { \
39 .type = IIO_ACCEL, \
40 .address = reg, \
41 .modified = 1, \
42 .channel2 = IIO_MOD_##axis, \
43 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
44 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
45 .scan_index = index, \
46 .scan_type = { \
47 .sign = 's', \
48 .realbits = 6, \
49 .storagebits = 8, \
50 .shift = BMA220_DATA_SHIFT, \
51 .endianness = IIO_CPU, \
52 }, \
53}
54
55enum bma220_axis {
56 AXIS_X,
57 AXIS_Y,
58 AXIS_Z,
59};
60
61static IIO_CONST_ATTR(in_accel_scale_available, BMA220_SCALE_AVAILABLE);
62
63static struct attribute *bma220_attributes[] = {
64 &iio_const_attr_in_accel_scale_available.dev_attr.attr,
65 NULL,
66};
67
68static const struct attribute_group bma220_attribute_group = {
69 .attrs = bma220_attributes,
70};
71
72static const int bma220_scale_table[][4] = {
73 {0, 623000}, {1, 248000}, {2, 491000}, {4, 983000}
74};
75
76struct bma220_data {
77 struct spi_device *spi_device;
78 struct mutex lock;
79 s8 buffer[16]; /* 3x8-bit channels + 5x8 padding + 8x8 timestamp */
80 u8 tx_buf[2] ____cacheline_aligned;
81};
82
83static const struct iio_chan_spec bma220_channels[] = {
84 BMA220_ACCEL_CHANNEL(0, BMA220_REG_ACCEL_X, X),
85 BMA220_ACCEL_CHANNEL(1, BMA220_REG_ACCEL_Y, Y),
86 BMA220_ACCEL_CHANNEL(2, BMA220_REG_ACCEL_Z, Z),
87 IIO_CHAN_SOFT_TIMESTAMP(3),
88};
89
90static inline int bma220_read_reg(struct spi_device *spi, u8 reg)
91{
92 return spi_w8r8(spi, reg | BMA220_READ_MASK);
93}
94
95static const unsigned long bma220_accel_scan_masks[] = {
96 BIT(AXIS_X) | BIT(AXIS_Y) | BIT(AXIS_Z),
97 0
98};
99
100static irqreturn_t bma220_trigger_handler(int irq, void *p)
101{
102 int ret;
103 struct iio_poll_func *pf = p;
104 struct iio_dev *indio_dev = pf->indio_dev;
105 struct bma220_data *data = iio_priv(indio_dev);
106 struct spi_device *spi = data->spi_device;
107
108 mutex_lock(&data->lock);
109 data->tx_buf[0] = BMA220_REG_ACCEL_X | BMA220_READ_MASK;
110 ret = spi_write_then_read(spi, data->tx_buf, 1, data->buffer,
111 ARRAY_SIZE(bma220_channels) - 1);
112 if (ret < 0)
113 goto err;
114
115 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
116 pf->timestamp);
117err:
118 mutex_unlock(&data->lock);
119 iio_trigger_notify_done(indio_dev->trig);
120
121 return IRQ_HANDLED;
122}
123
124static int bma220_read_raw(struct iio_dev *indio_dev,
125 struct iio_chan_spec const *chan,
126 int *val, int *val2, long mask)
127{
128 int ret;
129 u8 range_idx;
130 struct bma220_data *data = iio_priv(indio_dev);
131
132 switch (mask) {
133 case IIO_CHAN_INFO_RAW:
134 ret = bma220_read_reg(data->spi_device, chan->address);
135 if (ret < 0)
136 return -EINVAL;
137 *val = sign_extend32(ret >> BMA220_DATA_SHIFT, 5);
138 return IIO_VAL_INT;
139 case IIO_CHAN_INFO_SCALE:
140 ret = bma220_read_reg(data->spi_device, BMA220_REG_RANGE);
141 if (ret < 0)
142 return ret;
143 range_idx = ret & BMA220_RANGE_MASK;
144 *val = bma220_scale_table[range_idx][0];
145 *val2 = bma220_scale_table[range_idx][1];
146 return IIO_VAL_INT_PLUS_MICRO;
147 }
148
149 return -EINVAL;
150}
151
152static int bma220_write_raw(struct iio_dev *indio_dev,
153 struct iio_chan_spec const *chan,
154 int val, int val2, long mask)
155{
156 int i;
157 int ret;
158 int index = -1;
159 struct bma220_data *data = iio_priv(indio_dev);
160
161 switch (mask) {
162 case IIO_CHAN_INFO_SCALE:
163 for (i = 0; i < ARRAY_SIZE(bma220_scale_table); i++)
164 if (val == bma220_scale_table[i][0] &&
165 val2 == bma220_scale_table[i][1]) {
166 index = i;
167 break;
168 }
169 if (index < 0)
170 return -EINVAL;
171
172 mutex_lock(&data->lock);
173 data->tx_buf[0] = BMA220_REG_RANGE;
174 data->tx_buf[1] = index;
175 ret = spi_write(data->spi_device, data->tx_buf,
176 sizeof(data->tx_buf));
177 if (ret < 0)
178 dev_err(&data->spi_device->dev,
179 "failed to set measurement range\n");
180 mutex_unlock(&data->lock);
181
182 return 0;
183 }
184
185 return -EINVAL;
186}
187
188static const struct iio_info bma220_info = {
189 .driver_module = THIS_MODULE,
190 .read_raw = bma220_read_raw,
191 .write_raw = bma220_write_raw,
192 .attrs = &bma220_attribute_group,
193};
194
195static int bma220_init(struct spi_device *spi)
196{
197 int ret;
198
199 ret = bma220_read_reg(spi, BMA220_REG_ID);
200 if (ret != BMA220_CHIP_ID)
201 return -ENODEV;
202
203 /* Make sure the chip is powered on */
204 ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
205 if (ret < 0)
206 return ret;
207 else if (ret == BMA220_SUSPEND_WAKE)
208 return bma220_read_reg(spi, BMA220_REG_SUSPEND);
209
210 return 0;
211}
212
213static int bma220_deinit(struct spi_device *spi)
214{
215 int ret;
216
217 /* Make sure the chip is powered off */
218 ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
219 if (ret < 0)
220 return ret;
221 else if (ret == BMA220_SUSPEND_SLEEP)
222 return bma220_read_reg(spi, BMA220_REG_SUSPEND);
223
224 return 0;
225}
226
227static int bma220_probe(struct spi_device *spi)
228{
229 int ret;
230 struct iio_dev *indio_dev;
231 struct bma220_data *data;
232
233 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
234 if (!indio_dev) {
235 dev_err(&spi->dev, "iio allocation failed!\n");
236 return -ENOMEM;
237 }
238
239 data = iio_priv(indio_dev);
240 data->spi_device = spi;
241 spi_set_drvdata(spi, indio_dev);
242 mutex_init(&data->lock);
243
244 indio_dev->dev.parent = &spi->dev;
245 indio_dev->info = &bma220_info;
246 indio_dev->name = BMA220_DEVICE_NAME;
247 indio_dev->modes = INDIO_DIRECT_MODE;
248 indio_dev->channels = bma220_channels;
249 indio_dev->num_channels = ARRAY_SIZE(bma220_channels);
250 indio_dev->available_scan_masks = bma220_accel_scan_masks;
251
252 ret = bma220_init(data->spi_device);
253 if (ret < 0)
254 return ret;
255
256 ret = iio_triggered_buffer_setup(indio_dev, NULL,
257 bma220_trigger_handler, NULL);
258 if (ret < 0) {
259 dev_err(&spi->dev, "iio triggered buffer setup failed\n");
260 goto err_suspend;
261 }
262
263 ret = iio_device_register(indio_dev);
264 if (ret < 0) {
265 dev_err(&spi->dev, "iio_device_register failed\n");
266 iio_triggered_buffer_cleanup(indio_dev);
267 goto err_suspend;
268 }
269
270 return 0;
271
272err_suspend:
273 return bma220_deinit(spi);
274}
275
276static int bma220_remove(struct spi_device *spi)
277{
278 struct iio_dev *indio_dev = spi_get_drvdata(spi);
279
280 iio_device_unregister(indio_dev);
281 iio_triggered_buffer_cleanup(indio_dev);
282
283 return bma220_deinit(spi);
284}
285
286#ifdef CONFIG_PM_SLEEP
287static int bma220_suspend(struct device *dev)
288{
289 struct bma220_data *data =
290 iio_priv(spi_get_drvdata(to_spi_device(dev)));
291
292 /* The chip can be suspended/woken up by a simple register read. */
293 return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND);
294}
295
296static int bma220_resume(struct device *dev)
297{
298 struct bma220_data *data =
299 iio_priv(spi_get_drvdata(to_spi_device(dev)));
300
301 return bma220_read_reg(data->spi_device, BMA220_REG_SUSPEND);
302}
303
304static SIMPLE_DEV_PM_OPS(bma220_pm_ops, bma220_suspend, bma220_resume);
305
306#define BMA220_PM_OPS (&bma220_pm_ops)
307#else
308#define BMA220_PM_OPS NULL
309#endif
310
311static const struct spi_device_id bma220_spi_id[] = {
312 {"bma220", 0},
313 {}
314};
315
316static const struct acpi_device_id bma220_acpi_id[] = {
317 {"BMA0220", 0},
318 {}
319};
320
321MODULE_DEVICE_TABLE(spi, bma220_spi_id);
322
323static struct spi_driver bma220_driver = {
324 .driver = {
325 .name = "bma220_spi",
326 .pm = BMA220_PM_OPS,
327 .acpi_match_table = ACPI_PTR(bma220_acpi_id),
328 },
329 .probe = bma220_probe,
330 .remove = bma220_remove,
331 .id_table = bma220_spi_id,
332};
333
334module_spi_driver(bma220_driver);
335
336MODULE_AUTHOR("Tiberiu Breana <tiberiu.a.breana@intel.com>");
337MODULE_DESCRIPTION("BMA220 acceleration sensor driver");
338MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/mma7660.c b/drivers/iio/accel/mma7660.c
new file mode 100644
index 000000000000..0acdee516973
--- /dev/null
+++ b/drivers/iio/accel/mma7660.c
@@ -0,0 +1,277 @@
1/**
2 * Freescale MMA7660FC 3-Axis Accelerometer
3 *
4 * Copyright (c) 2016, Intel Corporation.
5 *
6 * This file is subject to the terms and conditions of version 2 of
7 * the GNU General Public License. See the file COPYING in the main
8 * directory of this archive for more details.
9 *
10 * IIO driver for Freescale MMA7660FC; 7-bit I2C address: 0x4c.
11 */
12
13#include <linux/acpi.h>
14#include <linux/i2c.h>
15#include <linux/module.h>
16#include <linux/iio/iio.h>
17#include <linux/iio/sysfs.h>
18
19#define MMA7660_DRIVER_NAME "mma7660"
20
21#define MMA7660_REG_XOUT 0x00
22#define MMA7660_REG_YOUT 0x01
23#define MMA7660_REG_ZOUT 0x02
24#define MMA7660_REG_OUT_BIT_ALERT BIT(6)
25
26#define MMA7660_REG_MODE 0x07
27#define MMA7660_REG_MODE_BIT_MODE BIT(0)
28#define MMA7660_REG_MODE_BIT_TON BIT(2)
29
30#define MMA7660_I2C_READ_RETRIES 5
31
32/*
33 * The accelerometer has one measurement range:
34 *
35 * -1.5g - +1.5g (6-bit, signed)
36 *
37 * scale = (1.5 + 1.5) * 9.81 / (2^6 - 1) = 0.467142857
38 */
39
40#define MMA7660_SCALE_AVAIL "0.467142857"
41
42const int mma7660_nscale = 467142857;
43
44#define MMA7660_CHANNEL(reg, axis) { \
45 .type = IIO_ACCEL, \
46 .address = reg, \
47 .modified = 1, \
48 .channel2 = IIO_MOD_##axis, \
49 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
50 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
51}
52
53static const struct iio_chan_spec mma7660_channels[] = {
54 MMA7660_CHANNEL(MMA7660_REG_XOUT, X),
55 MMA7660_CHANNEL(MMA7660_REG_YOUT, Y),
56 MMA7660_CHANNEL(MMA7660_REG_ZOUT, Z),
57};
58
59enum mma7660_mode {
60 MMA7660_MODE_STANDBY,
61 MMA7660_MODE_ACTIVE
62};
63
64struct mma7660_data {
65 struct i2c_client *client;
66 struct mutex lock;
67 enum mma7660_mode mode;
68};
69
70static IIO_CONST_ATTR(in_accel_scale_available, MMA7660_SCALE_AVAIL);
71
72static struct attribute *mma7660_attributes[] = {
73 &iio_const_attr_in_accel_scale_available.dev_attr.attr,
74 NULL,
75};
76
77static const struct attribute_group mma7660_attribute_group = {
78 .attrs = mma7660_attributes
79};
80
81static int mma7660_set_mode(struct mma7660_data *data,
82 enum mma7660_mode mode)
83{
84 int ret;
85 struct i2c_client *client = data->client;
86
87 if (mode == data->mode)
88 return 0;
89
90 ret = i2c_smbus_read_byte_data(client, MMA7660_REG_MODE);
91 if (ret < 0) {
92 dev_err(&client->dev, "failed to read sensor mode\n");
93 return ret;
94 }
95
96 if (mode == MMA7660_MODE_ACTIVE) {
97 ret &= ~MMA7660_REG_MODE_BIT_TON;
98 ret |= MMA7660_REG_MODE_BIT_MODE;
99 } else {
100 ret &= ~MMA7660_REG_MODE_BIT_TON;
101 ret &= ~MMA7660_REG_MODE_BIT_MODE;
102 }
103
104 ret = i2c_smbus_write_byte_data(client, MMA7660_REG_MODE, ret);
105 if (ret < 0) {
106 dev_err(&client->dev, "failed to change sensor mode\n");
107 return ret;
108 }
109
110 data->mode = mode;
111
112 return ret;
113}
114
115static int mma7660_read_accel(struct mma7660_data *data, u8 address)
116{
117 int ret, retries = MMA7660_I2C_READ_RETRIES;
118 struct i2c_client *client = data->client;
119
120 /*
121 * Read data. If the Alert bit is set, the register was read at
122 * the same time as the device was attempting to update the content.
123 * The solution is to read the register again. Do this only
124 * MMA7660_I2C_READ_RETRIES times to avoid spending too much time
125 * in the kernel.
126 */
127 do {
128 ret = i2c_smbus_read_byte_data(client, address);
129 if (ret < 0) {
130 dev_err(&client->dev, "register read failed\n");
131 return ret;
132 }
133 } while (retries-- > 0 && ret & MMA7660_REG_OUT_BIT_ALERT);
134
135 if (ret & MMA7660_REG_OUT_BIT_ALERT) {
136 dev_err(&client->dev, "all register read retries failed\n");
137 return -ETIMEDOUT;
138 }
139
140 return ret;
141}
142
143static int mma7660_read_raw(struct iio_dev *indio_dev,
144 struct iio_chan_spec const *chan,
145 int *val, int *val2, long mask)
146{
147 struct mma7660_data *data = iio_priv(indio_dev);
148 int ret;
149
150 switch (mask) {
151 case IIO_CHAN_INFO_RAW:
152 mutex_lock(&data->lock);
153 ret = mma7660_read_accel(data, chan->address);
154 mutex_unlock(&data->lock);
155 if (ret < 0)
156 return ret;
157 *val = sign_extend32(ret, 5);
158 return IIO_VAL_INT;
159 case IIO_CHAN_INFO_SCALE:
160 *val = 0;
161 *val2 = mma7660_nscale;
162 return IIO_VAL_INT_PLUS_NANO;
163 default:
164 return -EINVAL;
165 }
166
167 return -EINVAL;
168}
169
170static const struct iio_info mma7660_info = {
171 .driver_module = THIS_MODULE,
172 .read_raw = mma7660_read_raw,
173 .attrs = &mma7660_attribute_group,
174};
175
176static int mma7660_probe(struct i2c_client *client,
177 const struct i2c_device_id *id)
178{
179 int ret;
180 struct iio_dev *indio_dev;
181 struct mma7660_data *data;
182
183 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
184 if (!indio_dev) {
185 dev_err(&client->dev, "iio allocation failed!\n");
186 return -ENOMEM;
187 }
188
189 data = iio_priv(indio_dev);
190 data->client = client;
191 i2c_set_clientdata(client, indio_dev);
192 mutex_init(&data->lock);
193 data->mode = MMA7660_MODE_STANDBY;
194
195 indio_dev->dev.parent = &client->dev;
196 indio_dev->info = &mma7660_info;
197 indio_dev->name = MMA7660_DRIVER_NAME;
198 indio_dev->modes = INDIO_DIRECT_MODE;
199 indio_dev->channels = mma7660_channels;
200 indio_dev->num_channels = ARRAY_SIZE(mma7660_channels);
201
202 ret = mma7660_set_mode(data, MMA7660_MODE_ACTIVE);
203 if (ret < 0)
204 return ret;
205
206 ret = iio_device_register(indio_dev);
207 if (ret < 0) {
208 dev_err(&client->dev, "device_register failed\n");
209 mma7660_set_mode(data, MMA7660_MODE_STANDBY);
210 }
211
212 return ret;
213}
214
215static int mma7660_remove(struct i2c_client *client)
216{
217 struct iio_dev *indio_dev = i2c_get_clientdata(client);
218
219 iio_device_unregister(indio_dev);
220
221 return mma7660_set_mode(iio_priv(indio_dev), MMA7660_MODE_STANDBY);
222}
223
224#ifdef CONFIG_PM_SLEEP
225static int mma7660_suspend(struct device *dev)
226{
227 struct mma7660_data *data;
228
229 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
230
231 return mma7660_set_mode(data, MMA7660_MODE_STANDBY);
232}
233
234static int mma7660_resume(struct device *dev)
235{
236 struct mma7660_data *data;
237
238 data = iio_priv(i2c_get_clientdata(to_i2c_client(dev)));
239
240 return mma7660_set_mode(data, MMA7660_MODE_ACTIVE);
241}
242
243static SIMPLE_DEV_PM_OPS(mma7660_pm_ops, mma7660_suspend, mma7660_resume);
244
245#define MMA7660_PM_OPS (&mma7660_pm_ops)
246#else
247#define MMA7660_PM_OPS NULL
248#endif
249
250static const struct i2c_device_id mma7660_i2c_id[] = {
251 {"mma7660", 0},
252 {}
253};
254
255static const struct acpi_device_id mma7660_acpi_id[] = {
256 {"MMA7660", 0},
257 {}
258};
259
260MODULE_DEVICE_TABLE(acpi, mma7660_acpi_id);
261
262static struct i2c_driver mma7660_driver = {
263 .driver = {
264 .name = "mma7660",
265 .pm = MMA7660_PM_OPS,
266 .acpi_match_table = ACPI_PTR(mma7660_acpi_id),
267 },
268 .probe = mma7660_probe,
269 .remove = mma7660_remove,
270 .id_table = mma7660_i2c_id,
271};
272
273module_i2c_driver(mma7660_driver);
274
275MODULE_AUTHOR("Constantin Musca <constantin.musca@intel.com>");
276MODULE_DESCRIPTION("Freescale MMA7660FC 3-Axis Accelerometer driver");
277MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index e225d3c53bd5..458c82715427 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -76,6 +76,8 @@
76#define MMA8452_CTRL_DR_DEFAULT 0x4 /* 50 Hz sample frequency */ 76#define MMA8452_CTRL_DR_DEFAULT 0x4 /* 50 Hz sample frequency */
77#define MMA8452_CTRL_REG2 0x2b 77#define MMA8452_CTRL_REG2 0x2b
78#define MMA8452_CTRL_REG2_RST BIT(6) 78#define MMA8452_CTRL_REG2_RST BIT(6)
79#define MMA8452_CTRL_REG2_MODS_SHIFT 3
80#define MMA8452_CTRL_REG2_MODS_MASK 0x1b
79#define MMA8452_CTRL_REG4 0x2d 81#define MMA8452_CTRL_REG4 0x2d
80#define MMA8452_CTRL_REG5 0x2e 82#define MMA8452_CTRL_REG5 0x2e
81#define MMA8452_OFF_X 0x2f 83#define MMA8452_OFF_X 0x2f
@@ -257,20 +259,17 @@ static const int mma8452_samp_freq[8][2] = {
257 {6, 250000}, {1, 560000} 259 {6, 250000}, {1, 560000}
258}; 260};
259 261
260/* Datasheet table 35 (step time vs sample frequency) */ 262/* Datasheet table: step time "Relationship with the ODR" (sample frequency) */
261static const int mma8452_transient_time_step_us[8] = { 263static const int mma8452_transient_time_step_us[4][8] = {
262 1250, 264 { 1250, 2500, 5000, 10000, 20000, 20000, 20000, 20000 }, /* normal */
263 2500, 265 { 1250, 2500, 5000, 10000, 20000, 80000, 80000, 80000 }, /* l p l n */
264 5000, 266 { 1250, 2500, 2500, 2500, 2500, 2500, 2500, 2500 }, /* high res*/
265 10000, 267 { 1250, 2500, 5000, 10000, 20000, 80000, 160000, 160000 } /* l p */
266 20000,
267 20000,
268 20000,
269 20000
270}; 268};
271 269
272/* Datasheet table 18 (normal mode) */ 270/* Datasheet table "High-Pass Filter Cutoff Options" */
273static const int mma8452_hp_filter_cutoff[8][4][2] = { 271static const int mma8452_hp_filter_cutoff[4][8][4][2] = {
272 { /* normal */
274 { {16, 0}, {8, 0}, {4, 0}, {2, 0} }, /* 800 Hz sample */ 273 { {16, 0}, {8, 0}, {4, 0}, {2, 0} }, /* 800 Hz sample */
275 { {16, 0}, {8, 0}, {4, 0}, {2, 0} }, /* 400 Hz sample */ 274 { {16, 0}, {8, 0}, {4, 0}, {2, 0} }, /* 400 Hz sample */
276 { {8, 0}, {4, 0}, {2, 0}, {1, 0} }, /* 200 Hz sample */ 275 { {8, 0}, {4, 0}, {2, 0}, {1, 0} }, /* 200 Hz sample */
@@ -279,8 +278,61 @@ static const int mma8452_hp_filter_cutoff[8][4][2] = {
279 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} }, /* 12.5 Hz sample */ 278 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} }, /* 12.5 Hz sample */
280 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} }, /* 6.25 Hz sample */ 279 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} }, /* 6.25 Hz sample */
281 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} } /* 1.56 Hz sample */ 280 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} } /* 1.56 Hz sample */
281 },
282 { /* low noise low power */
283 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
284 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
285 { {8, 0}, {4, 0}, {2, 0}, {1, 0} },
286 { {4, 0}, {2, 0}, {1, 0}, {0, 500000} },
287 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} },
288 { {0, 500000}, {0, 250000}, {0, 125000}, {0, 063000} },
289 { {0, 500000}, {0, 250000}, {0, 125000}, {0, 063000} },
290 { {0, 500000}, {0, 250000}, {0, 125000}, {0, 063000} }
291 },
292 { /* high resolution */
293 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
294 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
295 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
296 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
297 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
298 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
299 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
300 { {16, 0}, {8, 0}, {4, 0}, {2, 0} }
301 },
302 { /* low power */
303 { {16, 0}, {8, 0}, {4, 0}, {2, 0} },
304 { {8, 0}, {4, 0}, {2, 0}, {1, 0} },
305 { {4, 0}, {2, 0}, {1, 0}, {0, 500000} },
306 { {2, 0}, {1, 0}, {0, 500000}, {0, 250000} },
307 { {1, 0}, {0, 500000}, {0, 250000}, {0, 125000} },
308 { {0, 250000}, {0, 125000}, {0, 063000}, {0, 031000} },
309 { {0, 250000}, {0, 125000}, {0, 063000}, {0, 031000} },
310 { {0, 250000}, {0, 125000}, {0, 063000}, {0, 031000} }
311 }
282}; 312};
283 313
314/* Datasheet table "MODS Oversampling modes averaging values at each ODR" */
315static const u16 mma8452_os_ratio[4][8] = {
316 /* 800 Hz, 400 Hz, ... , 1.56 Hz */
317 { 2, 4, 4, 4, 4, 16, 32, 128 }, /* normal */
318 { 2, 4, 4, 4, 4, 4, 8, 32 }, /* low power low noise */
319 { 2, 4, 8, 16, 32, 128, 256, 1024 }, /* high resolution */
320 { 2, 2, 2, 2, 2, 2, 4, 16 } /* low power */
321};
322
323static int mma8452_get_power_mode(struct mma8452_data *data)
324{
325 int reg;
326
327 reg = i2c_smbus_read_byte_data(data->client,
328 MMA8452_CTRL_REG2);
329 if (reg < 0)
330 return reg;
331
332 return ((reg & MMA8452_CTRL_REG2_MODS_MASK) >>
333 MMA8452_CTRL_REG2_MODS_SHIFT);
334}
335
284static ssize_t mma8452_show_samp_freq_avail(struct device *dev, 336static ssize_t mma8452_show_samp_freq_avail(struct device *dev,
285 struct device_attribute *attr, 337 struct device_attribute *attr,
286 char *buf) 338 char *buf)
@@ -306,10 +358,39 @@ static ssize_t mma8452_show_hp_cutoff_avail(struct device *dev,
306{ 358{
307 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 359 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
308 struct mma8452_data *data = iio_priv(indio_dev); 360 struct mma8452_data *data = iio_priv(indio_dev);
361 int i, j;
362
363 i = mma8452_get_odr_index(data);
364 j = mma8452_get_power_mode(data);
365 if (j < 0)
366 return j;
367
368 return mma8452_show_int_plus_micros(buf, mma8452_hp_filter_cutoff[j][i],
369 ARRAY_SIZE(mma8452_hp_filter_cutoff[0][0]));
370}
371
372static ssize_t mma8452_show_os_ratio_avail(struct device *dev,
373 struct device_attribute *attr,
374 char *buf)
375{
376 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
377 struct mma8452_data *data = iio_priv(indio_dev);
309 int i = mma8452_get_odr_index(data); 378 int i = mma8452_get_odr_index(data);
379 int j;
380 u16 val = 0;
381 size_t len = 0;
382
383 for (j = 0; j < ARRAY_SIZE(mma8452_os_ratio); j++) {
384 if (val == mma8452_os_ratio[j][i])
385 continue;
386
387 val = mma8452_os_ratio[j][i];
388
389 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", val);
390 }
391 buf[len - 1] = '\n';
310 392
311 return mma8452_show_int_plus_micros(buf, mma8452_hp_filter_cutoff[i], 393 return len;
312 ARRAY_SIZE(mma8452_hp_filter_cutoff[0]));
313} 394}
314 395
315static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma8452_show_samp_freq_avail); 396static IIO_DEV_ATTR_SAMP_FREQ_AVAIL(mma8452_show_samp_freq_avail);
@@ -317,6 +398,8 @@ static IIO_DEVICE_ATTR(in_accel_scale_available, S_IRUGO,
317 mma8452_show_scale_avail, NULL, 0); 398 mma8452_show_scale_avail, NULL, 0);
318static IIO_DEVICE_ATTR(in_accel_filter_high_pass_3db_frequency_available, 399static IIO_DEVICE_ATTR(in_accel_filter_high_pass_3db_frequency_available,
319 S_IRUGO, mma8452_show_hp_cutoff_avail, NULL, 0); 400 S_IRUGO, mma8452_show_hp_cutoff_avail, NULL, 0);
401static IIO_DEVICE_ATTR(in_accel_oversampling_ratio_available, S_IRUGO,
402 mma8452_show_os_ratio_avail, NULL, 0);
320 403
321static int mma8452_get_samp_freq_index(struct mma8452_data *data, 404static int mma8452_get_samp_freq_index(struct mma8452_data *data,
322 int val, int val2) 405 int val, int val2)
@@ -335,24 +418,33 @@ static int mma8452_get_scale_index(struct mma8452_data *data, int val, int val2)
335static int mma8452_get_hp_filter_index(struct mma8452_data *data, 418static int mma8452_get_hp_filter_index(struct mma8452_data *data,
336 int val, int val2) 419 int val, int val2)
337{ 420{
338 int i = mma8452_get_odr_index(data); 421 int i, j;
422
423 i = mma8452_get_odr_index(data);
424 j = mma8452_get_power_mode(data);
425 if (j < 0)
426 return j;
339 427
340 return mma8452_get_int_plus_micros_index(mma8452_hp_filter_cutoff[i], 428 return mma8452_get_int_plus_micros_index(mma8452_hp_filter_cutoff[j][i],
341 ARRAY_SIZE(mma8452_hp_filter_cutoff[0]), val, val2); 429 ARRAY_SIZE(mma8452_hp_filter_cutoff[0][0]), val, val2);
342} 430}
343 431
344static int mma8452_read_hp_filter(struct mma8452_data *data, int *hz, int *uHz) 432static int mma8452_read_hp_filter(struct mma8452_data *data, int *hz, int *uHz)
345{ 433{
346 int i, ret; 434 int j, i, ret;
347 435
348 ret = i2c_smbus_read_byte_data(data->client, MMA8452_HP_FILTER_CUTOFF); 436 ret = i2c_smbus_read_byte_data(data->client, MMA8452_HP_FILTER_CUTOFF);
349 if (ret < 0) 437 if (ret < 0)
350 return ret; 438 return ret;
351 439
352 i = mma8452_get_odr_index(data); 440 i = mma8452_get_odr_index(data);
441 j = mma8452_get_power_mode(data);
442 if (j < 0)
443 return j;
444
353 ret &= MMA8452_HP_FILTER_CUTOFF_SEL_MASK; 445 ret &= MMA8452_HP_FILTER_CUTOFF_SEL_MASK;
354 *hz = mma8452_hp_filter_cutoff[i][ret][0]; 446 *hz = mma8452_hp_filter_cutoff[j][i][ret][0];
355 *uHz = mma8452_hp_filter_cutoff[i][ret][1]; 447 *uHz = mma8452_hp_filter_cutoff[j][i][ret][1];
356 448
357 return 0; 449 return 0;
358} 450}
@@ -414,6 +506,15 @@ static int mma8452_read_raw(struct iio_dev *indio_dev,
414 } 506 }
415 507
416 return IIO_VAL_INT_PLUS_MICRO; 508 return IIO_VAL_INT_PLUS_MICRO;
509 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
510 ret = mma8452_get_power_mode(data);
511 if (ret < 0)
512 return ret;
513
514 i = mma8452_get_odr_index(data);
515
516 *val = mma8452_os_ratio[ret][i];
517 return IIO_VAL_INT;
417 } 518 }
418 519
419 return -EINVAL; 520 return -EINVAL;
@@ -480,6 +581,21 @@ fail:
480 return ret; 581 return ret;
481} 582}
482 583
584static int mma8452_set_power_mode(struct mma8452_data *data, u8 mode)
585{
586 int reg;
587
588 reg = i2c_smbus_read_byte_data(data->client,
589 MMA8452_CTRL_REG2);
590 if (reg < 0)
591 return reg;
592
593 reg &= ~MMA8452_CTRL_REG2_MODS_MASK;
594 reg |= mode << MMA8452_CTRL_REG2_MODS_SHIFT;
595
596 return mma8452_change_config(data, MMA8452_CTRL_REG2, reg);
597}
598
483/* returns >0 if in freefall mode, 0 if not or <0 if an error occurred */ 599/* returns >0 if in freefall mode, 0 if not or <0 if an error occurred */
484static int mma8452_freefall_mode_enabled(struct mma8452_data *data) 600static int mma8452_freefall_mode_enabled(struct mma8452_data *data)
485{ 601{
@@ -597,6 +713,14 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
597 return mma8452_change_config(data, MMA8452_DATA_CFG, 713 return mma8452_change_config(data, MMA8452_DATA_CFG,
598 data->data_cfg); 714 data->data_cfg);
599 715
716 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
717 ret = mma8452_get_odr_index(data);
718
719 for (i = 0; i < ARRAY_SIZE(mma8452_os_ratio); i++) {
720 if (mma8452_os_ratio[i][ret] == val)
721 return mma8452_set_power_mode(data, i);
722 }
723
600 default: 724 default:
601 return -EINVAL; 725 return -EINVAL;
602 } 726 }
@@ -610,7 +734,7 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
610 int *val, int *val2) 734 int *val, int *val2)
611{ 735{
612 struct mma8452_data *data = iio_priv(indio_dev); 736 struct mma8452_data *data = iio_priv(indio_dev);
613 int ret, us; 737 int ret, us, power_mode;
614 738
615 switch (info) { 739 switch (info) {
616 case IIO_EV_INFO_VALUE: 740 case IIO_EV_INFO_VALUE:
@@ -629,7 +753,11 @@ static int mma8452_read_thresh(struct iio_dev *indio_dev,
629 if (ret < 0) 753 if (ret < 0)
630 return ret; 754 return ret;
631 755
632 us = ret * mma8452_transient_time_step_us[ 756 power_mode = mma8452_get_power_mode(data);
757 if (power_mode < 0)
758 return power_mode;
759
760 us = ret * mma8452_transient_time_step_us[power_mode][
633 mma8452_get_odr_index(data)]; 761 mma8452_get_odr_index(data)];
634 *val = us / USEC_PER_SEC; 762 *val = us / USEC_PER_SEC;
635 *val2 = us % USEC_PER_SEC; 763 *val2 = us % USEC_PER_SEC;
@@ -677,8 +805,12 @@ static int mma8452_write_thresh(struct iio_dev *indio_dev,
677 val); 805 val);
678 806
679 case IIO_EV_INFO_PERIOD: 807 case IIO_EV_INFO_PERIOD:
808 ret = mma8452_get_power_mode(data);
809 if (ret < 0)
810 return ret;
811
680 steps = (val * USEC_PER_SEC + val2) / 812 steps = (val * USEC_PER_SEC + val2) /
681 mma8452_transient_time_step_us[ 813 mma8452_transient_time_step_us[ret][
682 mma8452_get_odr_index(data)]; 814 mma8452_get_odr_index(data)];
683 815
684 if (steps < 0 || steps > 0xff) 816 if (steps < 0 || steps > 0xff)
@@ -978,7 +1110,8 @@ static struct attribute_group mma8452_event_attribute_group = {
978 BIT(IIO_CHAN_INFO_CALIBBIAS), \ 1110 BIT(IIO_CHAN_INFO_CALIBBIAS), \
979 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 1111 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
980 BIT(IIO_CHAN_INFO_SCALE) | \ 1112 BIT(IIO_CHAN_INFO_SCALE) | \
981 BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY), \ 1113 BIT(IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY) | \
1114 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
982 .scan_index = idx, \ 1115 .scan_index = idx, \
983 .scan_type = { \ 1116 .scan_type = { \
984 .sign = 's', \ 1117 .sign = 's', \
@@ -998,7 +1131,8 @@ static struct attribute_group mma8452_event_attribute_group = {
998 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 1131 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
999 BIT(IIO_CHAN_INFO_CALIBBIAS), \ 1132 BIT(IIO_CHAN_INFO_CALIBBIAS), \
1000 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \ 1133 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) | \
1001 BIT(IIO_CHAN_INFO_SCALE), \ 1134 BIT(IIO_CHAN_INFO_SCALE) | \
1135 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \
1002 .scan_index = idx, \ 1136 .scan_index = idx, \
1003 .scan_type = { \ 1137 .scan_type = { \
1004 .sign = 's', \ 1138 .sign = 's', \
@@ -1171,6 +1305,7 @@ static struct attribute *mma8452_attributes[] = {
1171 &iio_dev_attr_sampling_frequency_available.dev_attr.attr, 1305 &iio_dev_attr_sampling_frequency_available.dev_attr.attr,
1172 &iio_dev_attr_in_accel_scale_available.dev_attr.attr, 1306 &iio_dev_attr_in_accel_scale_available.dev_attr.attr,
1173 &iio_dev_attr_in_accel_filter_high_pass_3db_frequency_available.dev_attr.attr, 1307 &iio_dev_attr_in_accel_filter_high_pass_3db_frequency_available.dev_attr.attr,
1308 &iio_dev_attr_in_accel_oversampling_ratio_available.dev_attr.attr,
1174 NULL 1309 NULL
1175}; 1310};
1176 1311
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 4d95bfc4786c..dce289aa40f2 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -758,13 +758,15 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
758 indio_dev->info = &accel_info; 758 indio_dev->info = &accel_info;
759 mutex_init(&adata->tb.buf_lock); 759 mutex_init(&adata->tb.buf_lock);
760 760
761 st_sensors_power_enable(indio_dev); 761 err = st_sensors_power_enable(indio_dev);
762 if (err)
763 return err;
762 764
763 err = st_sensors_check_device_support(indio_dev, 765 err = st_sensors_check_device_support(indio_dev,
764 ARRAY_SIZE(st_accel_sensors_settings), 766 ARRAY_SIZE(st_accel_sensors_settings),
765 st_accel_sensors_settings); 767 st_accel_sensors_settings);
766 if (err < 0) 768 if (err < 0)
767 return err; 769 goto st_accel_power_off;
768 770
769 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; 771 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
770 adata->multiread_bit = adata->sensor_settings->multi_read_bit; 772 adata->multiread_bit = adata->sensor_settings->multi_read_bit;
@@ -781,11 +783,11 @@ int st_accel_common_probe(struct iio_dev *indio_dev)
781 783
782 err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data); 784 err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data);
783 if (err < 0) 785 if (err < 0)
784 return err; 786 goto st_accel_power_off;
785 787
786 err = st_accel_allocate_ring(indio_dev); 788 err = st_accel_allocate_ring(indio_dev);
787 if (err < 0) 789 if (err < 0)
788 return err; 790 goto st_accel_power_off;
789 791
790 if (irq > 0) { 792 if (irq > 0) {
791 err = st_sensors_allocate_trigger(indio_dev, 793 err = st_sensors_allocate_trigger(indio_dev,
@@ -808,6 +810,8 @@ st_accel_device_register_error:
808 st_sensors_deallocate_trigger(indio_dev); 810 st_sensors_deallocate_trigger(indio_dev);
809st_accel_probe_trigger_error: 811st_accel_probe_trigger_error:
810 st_accel_deallocate_ring(indio_dev); 812 st_accel_deallocate_ring(indio_dev);
813st_accel_power_off:
814 st_sensors_power_disable(indio_dev);
811 815
812 return err; 816 return err;
813} 817}
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index 21e19b60e2b9..01240aeeeab0 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -154,12 +154,11 @@ static int ad7266_read_raw(struct iio_dev *indio_dev,
154 154
155 switch (m) { 155 switch (m) {
156 case IIO_CHAN_INFO_RAW: 156 case IIO_CHAN_INFO_RAW:
157 if (iio_buffer_enabled(indio_dev)) 157 ret = iio_device_claim_direct_mode(indio_dev);
158 return -EBUSY;
159
160 ret = ad7266_read_single(st, val, chan->address);
161 if (ret) 158 if (ret)
162 return ret; 159 return ret;
160 ret = ad7266_read_single(st, val, chan->address);
161 iio_device_release_direct_mode(indio_dev);
163 162
164 *val = (*val >> 2) & 0xfff; 163 *val = (*val >> 2) & 0xfff;
165 if (chan->scan_type.sign == 's') 164 if (chan->scan_type.sign == 's')
diff --git a/drivers/iio/adc/ad7476.c b/drivers/iio/adc/ad7476.c
index be85c2a0ad97..810c9a9fa62f 100644
--- a/drivers/iio/adc/ad7476.c
+++ b/drivers/iio/adc/ad7476.c
@@ -106,12 +106,11 @@ static int ad7476_read_raw(struct iio_dev *indio_dev,
106 106
107 switch (m) { 107 switch (m) {
108 case IIO_CHAN_INFO_RAW: 108 case IIO_CHAN_INFO_RAW:
109 mutex_lock(&indio_dev->mlock); 109 ret = iio_device_claim_direct_mode(indio_dev);
110 if (iio_buffer_enabled(indio_dev)) 110 if (ret)
111 ret = -EBUSY; 111 return ret;
112 else 112 ret = ad7476_scan_direct(st);
113 ret = ad7476_scan_direct(st); 113 iio_device_release_direct_mode(indio_dev);
114 mutex_unlock(&indio_dev->mlock);
115 114
116 if (ret < 0) 115 if (ret < 0)
117 return ret; 116 return ret;
diff --git a/drivers/iio/adc/ad7791.c b/drivers/iio/adc/ad7791.c
index cf172d58cd44..1dfe6410c64c 100644
--- a/drivers/iio/adc/ad7791.c
+++ b/drivers/iio/adc/ad7791.c
@@ -272,30 +272,22 @@ static ssize_t ad7791_write_frequency(struct device *dev,
272 struct ad7791_state *st = iio_priv(indio_dev); 272 struct ad7791_state *st = iio_priv(indio_dev);
273 int i, ret; 273 int i, ret;
274 274
275 mutex_lock(&indio_dev->mlock); 275 for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++)
276 if (iio_buffer_enabled(indio_dev)) { 276 if (sysfs_streq(ad7791_sample_freq_avail[i], buf))
277 mutex_unlock(&indio_dev->mlock);
278 return -EBUSY;
279 }
280 mutex_unlock(&indio_dev->mlock);
281
282 ret = -EINVAL;
283
284 for (i = 0; i < ARRAY_SIZE(ad7791_sample_freq_avail); i++) {
285 if (sysfs_streq(ad7791_sample_freq_avail[i], buf)) {
286
287 mutex_lock(&indio_dev->mlock);
288 st->filter &= ~AD7791_FILTER_RATE_MASK;
289 st->filter |= i;
290 ad_sd_write_reg(&st->sd, AD7791_REG_FILTER,
291 sizeof(st->filter), st->filter);
292 mutex_unlock(&indio_dev->mlock);
293 ret = 0;
294 break; 277 break;
295 } 278 if (i == ARRAY_SIZE(ad7791_sample_freq_avail))
296 } 279 return -EINVAL;
280
281 ret = iio_device_claim_direct_mode(indio_dev);
282 if (ret)
283 return ret;
284 st->filter &= ~AD7791_FILTER_RATE_MASK;
285 st->filter |= i;
286 ad_sd_write_reg(&st->sd, AD7791_REG_FILTER, sizeof(st->filter),
287 st->filter);
288 iio_device_release_direct_mode(indio_dev);
297 289
298 return ret ? ret : len; 290 return len;
299} 291}
300 292
301static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, 293static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index 7b07bb651671..a43722fbf03a 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -369,13 +369,6 @@ static ssize_t ad7793_write_frequency(struct device *dev,
369 long lval; 369 long lval;
370 int i, ret; 370 int i, ret;
371 371
372 mutex_lock(&indio_dev->mlock);
373 if (iio_buffer_enabled(indio_dev)) {
374 mutex_unlock(&indio_dev->mlock);
375 return -EBUSY;
376 }
377 mutex_unlock(&indio_dev->mlock);
378
379 ret = kstrtol(buf, 10, &lval); 372 ret = kstrtol(buf, 10, &lval);
380 if (ret) 373 if (ret)
381 return ret; 374 return ret;
@@ -383,20 +376,21 @@ static ssize_t ad7793_write_frequency(struct device *dev,
383 if (lval == 0) 376 if (lval == 0)
384 return -EINVAL; 377 return -EINVAL;
385 378
386 ret = -EINVAL;
387
388 for (i = 0; i < 16; i++) 379 for (i = 0; i < 16; i++)
389 if (lval == st->chip_info->sample_freq_avail[i]) { 380 if (lval == st->chip_info->sample_freq_avail[i])
390 mutex_lock(&indio_dev->mlock); 381 break;
391 st->mode &= ~AD7793_MODE_RATE(-1); 382 if (i == 16)
392 st->mode |= AD7793_MODE_RATE(i); 383 return -EINVAL;
393 ad_sd_write_reg(&st->sd, AD7793_REG_MODE,
394 sizeof(st->mode), st->mode);
395 mutex_unlock(&indio_dev->mlock);
396 ret = 0;
397 }
398 384
399 return ret ? ret : len; 385 ret = iio_device_claim_direct_mode(indio_dev);
386 if (ret)
387 return ret;
388 st->mode &= ~AD7793_MODE_RATE(-1);
389 st->mode |= AD7793_MODE_RATE(i);
390 ad_sd_write_reg(&st->sd, AD7793_REG_MODE, sizeof(st->mode), st->mode);
391 iio_device_release_direct_mode(indio_dev);
392
393 return len;
400} 394}
401 395
402static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO, 396static IIO_DEV_ATTR_SAMP_FREQ(S_IWUSR | S_IRUGO,
diff --git a/drivers/iio/adc/ad7887.c b/drivers/iio/adc/ad7887.c
index 2d3c397e66ad..ee2ccc19fab6 100644
--- a/drivers/iio/adc/ad7887.c
+++ b/drivers/iio/adc/ad7887.c
@@ -156,12 +156,11 @@ static int ad7887_read_raw(struct iio_dev *indio_dev,
156 156
157 switch (m) { 157 switch (m) {
158 case IIO_CHAN_INFO_RAW: 158 case IIO_CHAN_INFO_RAW:
159 mutex_lock(&indio_dev->mlock); 159 ret = iio_device_claim_direct_mode(indio_dev);
160 if (iio_buffer_enabled(indio_dev)) 160 if (ret)
161 ret = -EBUSY; 161 return ret;
162 else 162 ret = ad7887_scan_direct(st, chan->address);
163 ret = ad7887_scan_direct(st, chan->address); 163 iio_device_release_direct_mode(indio_dev);
164 mutex_unlock(&indio_dev->mlock);
165 164
166 if (ret < 0) 165 if (ret < 0)
167 return ret; 166 return ret;
diff --git a/drivers/iio/adc/ad7923.c b/drivers/iio/adc/ad7923.c
index 45e29ccd824f..ff444c19d749 100644
--- a/drivers/iio/adc/ad7923.c
+++ b/drivers/iio/adc/ad7923.c
@@ -233,12 +233,11 @@ static int ad7923_read_raw(struct iio_dev *indio_dev,
233 233
234 switch (m) { 234 switch (m) {
235 case IIO_CHAN_INFO_RAW: 235 case IIO_CHAN_INFO_RAW:
236 mutex_lock(&indio_dev->mlock); 236 ret = iio_device_claim_direct_mode(indio_dev);
237 if (iio_buffer_enabled(indio_dev)) 237 if (ret)
238 ret = -EBUSY; 238 return ret;
239 else 239 ret = ad7923_scan_direct(st, chan->address);
240 ret = ad7923_scan_direct(st, chan->address); 240 iio_device_release_direct_mode(indio_dev);
241 mutex_unlock(&indio_dev->mlock);
242 241
243 if (ret < 0) 242 if (ret < 0)
244 return ret; 243 return ret;
diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index a3f5254f4e51..ec0200dd52cb 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -282,12 +282,11 @@ static int ad799x_read_raw(struct iio_dev *indio_dev,
282 282
283 switch (m) { 283 switch (m) {
284 case IIO_CHAN_INFO_RAW: 284 case IIO_CHAN_INFO_RAW:
285 mutex_lock(&indio_dev->mlock); 285 ret = iio_device_claim_direct_mode(indio_dev);
286 if (iio_buffer_enabled(indio_dev)) 286 if (ret)
287 ret = -EBUSY; 287 return ret;
288 else 288 ret = ad799x_scan_direct(st, chan->scan_index);
289 ret = ad799x_scan_direct(st, chan->scan_index); 289 iio_device_release_direct_mode(indio_dev);
290 mutex_unlock(&indio_dev->mlock);
291 290
292 if (ret < 0) 291 if (ret < 0)
293 return ret; 292 return ret;
@@ -395,11 +394,9 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
395 struct ad799x_state *st = iio_priv(indio_dev); 394 struct ad799x_state *st = iio_priv(indio_dev);
396 int ret; 395 int ret;
397 396
398 mutex_lock(&indio_dev->mlock); 397 ret = iio_device_claim_direct_mode(indio_dev);
399 if (iio_buffer_enabled(indio_dev)) { 398 if (ret)
400 ret = -EBUSY; 399 return ret;
401 goto done;
402 }
403 400
404 if (state) 401 if (state)
405 st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT; 402 st->config |= BIT(chan->scan_index) << AD799X_CHANNEL_SHIFT;
@@ -412,10 +409,7 @@ static int ad799x_write_event_config(struct iio_dev *indio_dev,
412 st->config &= ~AD7998_ALERT_EN; 409 st->config &= ~AD7998_ALERT_EN;
413 410
414 ret = ad799x_write_config(st, st->config); 411 ret = ad799x_write_config(st, st->config);
415 412 iio_device_release_direct_mode(indio_dev);
416done:
417 mutex_unlock(&indio_dev->mlock);
418
419 return ret; 413 return ret;
420} 414}
421 415
diff --git a/drivers/iio/adc/mxs-lradc.c b/drivers/iio/adc/mxs-lradc.c
index ad26da1edbee..b84d37c80a94 100644
--- a/drivers/iio/adc/mxs-lradc.c
+++ b/drivers/iio/adc/mxs-lradc.c
@@ -373,13 +373,6 @@ static u32 mxs_lradc_plate_mask(struct mxs_lradc *lradc)
373 return LRADC_CTRL0_MX28_PLATE_MASK; 373 return LRADC_CTRL0_MX28_PLATE_MASK;
374} 374}
375 375
376static u32 mxs_lradc_irq_en_mask(struct mxs_lradc *lradc)
377{
378 if (lradc->soc == IMX23_LRADC)
379 return LRADC_CTRL1_MX23_LRADC_IRQ_EN_MASK;
380 return LRADC_CTRL1_MX28_LRADC_IRQ_EN_MASK;
381}
382
383static u32 mxs_lradc_irq_mask(struct mxs_lradc *lradc) 376static u32 mxs_lradc_irq_mask(struct mxs_lradc *lradc)
384{ 377{
385 if (lradc->soc == IMX23_LRADC) 378 if (lradc->soc == IMX23_LRADC)
@@ -1120,18 +1113,16 @@ static int mxs_lradc_ts_register(struct mxs_lradc *lradc)
1120{ 1113{
1121 struct input_dev *input; 1114 struct input_dev *input;
1122 struct device *dev = lradc->dev; 1115 struct device *dev = lradc->dev;
1123 int ret;
1124 1116
1125 if (!lradc->use_touchscreen) 1117 if (!lradc->use_touchscreen)
1126 return 0; 1118 return 0;
1127 1119
1128 input = input_allocate_device(); 1120 input = devm_input_allocate_device(dev);
1129 if (!input) 1121 if (!input)
1130 return -ENOMEM; 1122 return -ENOMEM;
1131 1123
1132 input->name = DRIVER_NAME; 1124 input->name = DRIVER_NAME;
1133 input->id.bustype = BUS_HOST; 1125 input->id.bustype = BUS_HOST;
1134 input->dev.parent = dev;
1135 input->open = mxs_lradc_ts_open; 1126 input->open = mxs_lradc_ts_open;
1136 input->close = mxs_lradc_ts_close; 1127 input->close = mxs_lradc_ts_close;
1137 1128
@@ -1146,20 +1137,8 @@ static int mxs_lradc_ts_register(struct mxs_lradc *lradc)
1146 1137
1147 lradc->ts_input = input; 1138 lradc->ts_input = input;
1148 input_set_drvdata(input, lradc); 1139 input_set_drvdata(input, lradc);
1149 ret = input_register_device(input);
1150 if (ret)
1151 input_free_device(lradc->ts_input);
1152
1153 return ret;
1154}
1155
1156static void mxs_lradc_ts_unregister(struct mxs_lradc *lradc)
1157{
1158 if (!lradc->use_touchscreen)
1159 return;
1160 1140
1161 mxs_lradc_disable_ts(lradc); 1141 return input_register_device(input);
1162 input_unregister_device(lradc->ts_input);
1163} 1142}
1164 1143
1165/* 1144/*
@@ -1510,7 +1489,9 @@ static void mxs_lradc_hw_stop(struct mxs_lradc *lradc)
1510{ 1489{
1511 int i; 1490 int i;
1512 1491
1513 mxs_lradc_reg_clear(lradc, mxs_lradc_irq_en_mask(lradc), LRADC_CTRL1); 1492 mxs_lradc_reg_clear(lradc,
1493 lradc->buffer_vchans << LRADC_CTRL1_LRADC_IRQ_EN_OFFSET,
1494 LRADC_CTRL1);
1514 1495
1515 for (i = 0; i < LRADC_MAX_DELAY_CHANS; i++) 1496 for (i = 0; i < LRADC_MAX_DELAY_CHANS; i++)
1516 mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(i)); 1497 mxs_lradc_reg_wrt(lradc, 0, LRADC_DELAY(i));
@@ -1721,13 +1702,11 @@ static int mxs_lradc_probe(struct platform_device *pdev)
1721 ret = iio_device_register(iio); 1702 ret = iio_device_register(iio);
1722 if (ret) { 1703 if (ret) {
1723 dev_err(dev, "Failed to register IIO device\n"); 1704 dev_err(dev, "Failed to register IIO device\n");
1724 goto err_ts; 1705 return ret;
1725 } 1706 }
1726 1707
1727 return 0; 1708 return 0;
1728 1709
1729err_ts:
1730 mxs_lradc_ts_unregister(lradc);
1731err_ts_register: 1710err_ts_register:
1732 mxs_lradc_hw_stop(lradc); 1711 mxs_lradc_hw_stop(lradc);
1733err_dev: 1712err_dev:
@@ -1745,7 +1724,6 @@ static int mxs_lradc_remove(struct platform_device *pdev)
1745 struct mxs_lradc *lradc = iio_priv(iio); 1724 struct mxs_lradc *lradc = iio_priv(iio);
1746 1725
1747 iio_device_unregister(iio); 1726 iio_device_unregister(iio);
1748 mxs_lradc_ts_unregister(lradc);
1749 mxs_lradc_hw_stop(lradc); 1727 mxs_lradc_hw_stop(lradc);
1750 mxs_lradc_trigger_remove(iio); 1728 mxs_lradc_trigger_remove(iio);
1751 iio_triggered_buffer_cleanup(iio); 1729 iio_triggered_buffer_cleanup(iio);
diff --git a/drivers/iio/adc/nau7802.c b/drivers/iio/adc/nau7802.c
index e525aa6475c4..57365c504093 100644
--- a/drivers/iio/adc/nau7802.c
+++ b/drivers/iio/adc/nau7802.c
@@ -79,10 +79,29 @@ static const struct iio_chan_spec nau7802_chan_array[] = {
79static const u16 nau7802_sample_freq_avail[] = {10, 20, 40, 80, 79static const u16 nau7802_sample_freq_avail[] = {10, 20, 40, 80,
80 10, 10, 10, 320}; 80 10, 10, 10, 320};
81 81
82static ssize_t nau7802_show_scales(struct device *dev,
83 struct device_attribute *attr, char *buf)
84{
85 struct nau7802_state *st = iio_priv(dev_to_iio_dev(dev));
86 int i, len = 0;
87
88 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++)
89 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%09d ",
90 st->scale_avail[i]);
91
92 buf[len-1] = '\n';
93
94 return len;
95}
96
82static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 40 80 320"); 97static IIO_CONST_ATTR_SAMP_FREQ_AVAIL("10 40 80 320");
83 98
99static IIO_DEVICE_ATTR(in_voltage_scale_available, S_IRUGO, nau7802_show_scales,
100 NULL, 0);
101
84static struct attribute *nau7802_attributes[] = { 102static struct attribute *nau7802_attributes[] = {
85 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 103 &iio_const_attr_sampling_frequency_available.dev_attr.attr,
104 &iio_dev_attr_in_voltage_scale_available.dev_attr.attr,
86 NULL 105 NULL
87}; 106};
88 107
diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 73cbf0b54e54..8be192a84893 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -55,6 +55,11 @@
55#define ADS1015_DEFAULT_DATA_RATE 4 55#define ADS1015_DEFAULT_DATA_RATE 4
56#define ADS1015_DEFAULT_CHAN 0 56#define ADS1015_DEFAULT_CHAN 0
57 57
58enum {
59 ADS1015,
60 ADS1115,
61};
62
58enum ads1015_channels { 63enum ads1015_channels {
59 ADS1015_AIN0_AIN1 = 0, 64 ADS1015_AIN0_AIN1 = 0,
60 ADS1015_AIN0_AIN3, 65 ADS1015_AIN0_AIN3,
@@ -71,6 +76,10 @@ static const unsigned int ads1015_data_rate[] = {
71 128, 250, 490, 920, 1600, 2400, 3300, 3300 76 128, 250, 490, 920, 1600, 2400, 3300, 3300
72}; 77};
73 78
79static const unsigned int ads1115_data_rate[] = {
80 8, 16, 32, 64, 128, 250, 475, 860
81};
82
74static const struct { 83static const struct {
75 int scale; 84 int scale;
76 int uscale; 85 int uscale;
@@ -101,6 +110,7 @@ static const struct {
101 .shift = 4, \ 110 .shift = 4, \
102 .endianness = IIO_CPU, \ 111 .endianness = IIO_CPU, \
103 }, \ 112 }, \
113 .datasheet_name = "AIN"#_chan, \
104} 114}
105 115
106#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr) { \ 116#define ADS1015_V_DIFF_CHAN(_chan, _chan2, _addr) { \
@@ -121,6 +131,45 @@ static const struct {
121 .shift = 4, \ 131 .shift = 4, \
122 .endianness = IIO_CPU, \ 132 .endianness = IIO_CPU, \
123 }, \ 133 }, \
134 .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \
135}
136
137#define ADS1115_V_CHAN(_chan, _addr) { \
138 .type = IIO_VOLTAGE, \
139 .indexed = 1, \
140 .address = _addr, \
141 .channel = _chan, \
142 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
143 BIT(IIO_CHAN_INFO_SCALE) | \
144 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
145 .scan_index = _addr, \
146 .scan_type = { \
147 .sign = 's', \
148 .realbits = 16, \
149 .storagebits = 16, \
150 .endianness = IIO_CPU, \
151 }, \
152 .datasheet_name = "AIN"#_chan, \
153}
154
155#define ADS1115_V_DIFF_CHAN(_chan, _chan2, _addr) { \
156 .type = IIO_VOLTAGE, \
157 .differential = 1, \
158 .indexed = 1, \
159 .address = _addr, \
160 .channel = _chan, \
161 .channel2 = _chan2, \
162 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
163 BIT(IIO_CHAN_INFO_SCALE) | \
164 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
165 .scan_index = _addr, \
166 .scan_type = { \
167 .sign = 's', \
168 .realbits = 16, \
169 .storagebits = 16, \
170 .endianness = IIO_CPU, \
171 }, \
172 .datasheet_name = "AIN"#_chan"-AIN"#_chan2, \
124} 173}
125 174
126struct ads1015_data { 175struct ads1015_data {
@@ -131,6 +180,8 @@ struct ads1015_data {
131 */ 180 */
132 struct mutex lock; 181 struct mutex lock;
133 struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; 182 struct ads1015_channel_data channel_data[ADS1015_CHANNELS];
183
184 unsigned int *data_rate;
134}; 185};
135 186
136static bool ads1015_is_writeable_reg(struct device *dev, unsigned int reg) 187static bool ads1015_is_writeable_reg(struct device *dev, unsigned int reg)
@@ -157,6 +208,18 @@ static const struct iio_chan_spec ads1015_channels[] = {
157 IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), 208 IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
158}; 209};
159 210
211static const struct iio_chan_spec ads1115_channels[] = {
212 ADS1115_V_DIFF_CHAN(0, 1, ADS1015_AIN0_AIN1),
213 ADS1115_V_DIFF_CHAN(0, 3, ADS1015_AIN0_AIN3),
214 ADS1115_V_DIFF_CHAN(1, 3, ADS1015_AIN1_AIN3),
215 ADS1115_V_DIFF_CHAN(2, 3, ADS1015_AIN2_AIN3),
216 ADS1115_V_CHAN(0, ADS1015_AIN0),
217 ADS1115_V_CHAN(1, ADS1015_AIN1),
218 ADS1115_V_CHAN(2, ADS1015_AIN2),
219 ADS1115_V_CHAN(3, ADS1015_AIN3),
220 IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP),
221};
222
160static int ads1015_set_power_state(struct ads1015_data *data, bool on) 223static int ads1015_set_power_state(struct ads1015_data *data, bool on)
161{ 224{
162 int ret; 225 int ret;
@@ -196,7 +259,7 @@ int ads1015_get_adc_result(struct ads1015_data *data, int chan, int *val)
196 return ret; 259 return ret;
197 260
198 if (change) { 261 if (change) {
199 conv_time = DIV_ROUND_UP(USEC_PER_SEC, ads1015_data_rate[dr]); 262 conv_time = DIV_ROUND_UP(USEC_PER_SEC, data->data_rate[dr]);
200 usleep_range(conv_time, conv_time + 1); 263 usleep_range(conv_time, conv_time + 1);
201 } 264 }
202 265
@@ -263,7 +326,7 @@ static int ads1015_set_data_rate(struct ads1015_data *data, int chan, int rate)
263 int i, ret, rindex = -1; 326 int i, ret, rindex = -1;
264 327
265 for (i = 0; i < ARRAY_SIZE(ads1015_data_rate); i++) 328 for (i = 0; i < ARRAY_SIZE(ads1015_data_rate); i++)
266 if (ads1015_data_rate[i] == rate) { 329 if (data->data_rate[i] == rate) {
267 rindex = i; 330 rindex = i;
268 break; 331 break;
269 } 332 }
@@ -291,7 +354,9 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
291 mutex_lock(&indio_dev->mlock); 354 mutex_lock(&indio_dev->mlock);
292 mutex_lock(&data->lock); 355 mutex_lock(&data->lock);
293 switch (mask) { 356 switch (mask) {
294 case IIO_CHAN_INFO_RAW: 357 case IIO_CHAN_INFO_RAW: {
358 int shift = chan->scan_type.shift;
359
295 if (iio_buffer_enabled(indio_dev)) { 360 if (iio_buffer_enabled(indio_dev)) {
296 ret = -EBUSY; 361 ret = -EBUSY;
297 break; 362 break;
@@ -307,8 +372,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
307 break; 372 break;
308 } 373 }
309 374
310 /* 12 bit res, D0 is bit 4 in conversion register */ 375 *val = sign_extend32(*val >> shift, 15 - shift);
311 *val = sign_extend32(*val >> 4, 11);
312 376
313 ret = ads1015_set_power_state(data, false); 377 ret = ads1015_set_power_state(data, false);
314 if (ret < 0) 378 if (ret < 0)
@@ -316,6 +380,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
316 380
317 ret = IIO_VAL_INT; 381 ret = IIO_VAL_INT;
318 break; 382 break;
383 }
319 case IIO_CHAN_INFO_SCALE: 384 case IIO_CHAN_INFO_SCALE:
320 idx = data->channel_data[chan->address].pga; 385 idx = data->channel_data[chan->address].pga;
321 *val = ads1015_scale[idx].scale; 386 *val = ads1015_scale[idx].scale;
@@ -324,7 +389,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,
324 break; 389 break;
325 case IIO_CHAN_INFO_SAMP_FREQ: 390 case IIO_CHAN_INFO_SAMP_FREQ:
326 idx = data->channel_data[chan->address].data_rate; 391 idx = data->channel_data[chan->address].data_rate;
327 *val = ads1015_data_rate[idx]; 392 *val = data->data_rate[idx];
328 ret = IIO_VAL_INT; 393 ret = IIO_VAL_INT;
329 break; 394 break;
330 default: 395 default:
@@ -380,12 +445,15 @@ static const struct iio_buffer_setup_ops ads1015_buffer_setup_ops = {
380}; 445};
381 446
382static IIO_CONST_ATTR(scale_available, "3 2 1 0.5 0.25 0.125"); 447static IIO_CONST_ATTR(scale_available, "3 2 1 0.5 0.25 0.125");
383static IIO_CONST_ATTR(sampling_frequency_available, 448
384 "128 250 490 920 1600 2400 3300"); 449static IIO_CONST_ATTR_NAMED(ads1015_sampling_frequency_available,
450 sampling_frequency_available, "128 250 490 920 1600 2400 3300");
451static IIO_CONST_ATTR_NAMED(ads1115_sampling_frequency_available,
452 sampling_frequency_available, "8 16 32 64 128 250 475 860");
385 453
386static struct attribute *ads1015_attributes[] = { 454static struct attribute *ads1015_attributes[] = {
387 &iio_const_attr_scale_available.dev_attr.attr, 455 &iio_const_attr_scale_available.dev_attr.attr,
388 &iio_const_attr_sampling_frequency_available.dev_attr.attr, 456 &iio_const_attr_ads1015_sampling_frequency_available.dev_attr.attr,
389 NULL, 457 NULL,
390}; 458};
391 459
@@ -393,11 +461,28 @@ static const struct attribute_group ads1015_attribute_group = {
393 .attrs = ads1015_attributes, 461 .attrs = ads1015_attributes,
394}; 462};
395 463
396static const struct iio_info ads1015_info = { 464static struct attribute *ads1115_attributes[] = {
465 &iio_const_attr_scale_available.dev_attr.attr,
466 &iio_const_attr_ads1115_sampling_frequency_available.dev_attr.attr,
467 NULL,
468};
469
470static const struct attribute_group ads1115_attribute_group = {
471 .attrs = ads1115_attributes,
472};
473
474static struct iio_info ads1015_info = {
475 .driver_module = THIS_MODULE,
476 .read_raw = ads1015_read_raw,
477 .write_raw = ads1015_write_raw,
478 .attrs = &ads1015_attribute_group,
479};
480
481static struct iio_info ads1115_info = {
397 .driver_module = THIS_MODULE, 482 .driver_module = THIS_MODULE,
398 .read_raw = ads1015_read_raw, 483 .read_raw = ads1015_read_raw,
399 .write_raw = ads1015_write_raw, 484 .write_raw = ads1015_write_raw,
400 .attrs = &ads1015_attribute_group, 485 .attrs = &ads1115_attribute_group,
401}; 486};
402 487
403#ifdef CONFIG_OF 488#ifdef CONFIG_OF
@@ -500,12 +585,24 @@ static int ads1015_probe(struct i2c_client *client,
500 mutex_init(&data->lock); 585 mutex_init(&data->lock);
501 586
502 indio_dev->dev.parent = &client->dev; 587 indio_dev->dev.parent = &client->dev;
503 indio_dev->info = &ads1015_info;
504 indio_dev->name = ADS1015_DRV_NAME; 588 indio_dev->name = ADS1015_DRV_NAME;
505 indio_dev->channels = ads1015_channels;
506 indio_dev->num_channels = ARRAY_SIZE(ads1015_channels);
507 indio_dev->modes = INDIO_DIRECT_MODE; 589 indio_dev->modes = INDIO_DIRECT_MODE;
508 590
591 switch (id->driver_data) {
592 case ADS1015:
593 indio_dev->channels = ads1015_channels;
594 indio_dev->num_channels = ARRAY_SIZE(ads1015_channels);
595 indio_dev->info = &ads1015_info;
596 data->data_rate = (unsigned int *) &ads1015_data_rate;
597 break;
598 case ADS1115:
599 indio_dev->channels = ads1115_channels;
600 indio_dev->num_channels = ARRAY_SIZE(ads1115_channels);
601 indio_dev->info = &ads1115_info;
602 data->data_rate = (unsigned int *) &ads1115_data_rate;
603 break;
604 }
605
509 /* we need to keep this ABI the same as used by hwmon ADS1015 driver */ 606 /* we need to keep this ABI the same as used by hwmon ADS1015 driver */
510 ads1015_get_channels_config(client); 607 ads1015_get_channels_config(client);
511 608
@@ -590,7 +687,8 @@ static const struct dev_pm_ops ads1015_pm_ops = {
590}; 687};
591 688
592static const struct i2c_device_id ads1015_id[] = { 689static const struct i2c_device_id ads1015_id[] = {
593 {"ads1015", 0}, 690 {"ads1015", ADS1015},
691 {"ads1115", ADS1115},
594 {} 692 {}
595}; 693};
596MODULE_DEVICE_TABLE(i2c, ads1015_id); 694MODULE_DEVICE_TABLE(i2c, ads1015_id);
diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
index c1e05532d437..8a368756881b 100644
--- a/drivers/iio/adc/ti_am335x_adc.c
+++ b/drivers/iio/adc/ti_am335x_adc.c
@@ -326,8 +326,7 @@ static int tiadc_channel_init(struct iio_dev *indio_dev, int channels)
326 int i; 326 int i;
327 327
328 indio_dev->num_channels = channels; 328 indio_dev->num_channels = channels;
329 chan_array = kcalloc(channels, 329 chan_array = kcalloc(channels, sizeof(*chan_array), GFP_KERNEL);
330 sizeof(struct iio_chan_spec), GFP_KERNEL);
331 if (chan_array == NULL) 330 if (chan_array == NULL)
332 return -ENOMEM; 331 return -ENOMEM;
333 332
@@ -467,8 +466,7 @@ static int tiadc_probe(struct platform_device *pdev)
467 return -EINVAL; 466 return -EINVAL;
468 } 467 }
469 468
470 indio_dev = devm_iio_device_alloc(&pdev->dev, 469 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*indio_dev));
471 sizeof(struct tiadc_device));
472 if (indio_dev == NULL) { 470 if (indio_dev == NULL) {
473 dev_err(&pdev->dev, "failed to allocate iio device\n"); 471 dev_err(&pdev->dev, "failed to allocate iio device\n");
474 return -ENOMEM; 472 return -ENOMEM;
@@ -531,8 +529,7 @@ static int tiadc_remove(struct platform_device *pdev)
531 return 0; 529 return 0;
532} 530}
533 531
534#ifdef CONFIG_PM 532static int __maybe_unused tiadc_suspend(struct device *dev)
535static int tiadc_suspend(struct device *dev)
536{ 533{
537 struct iio_dev *indio_dev = dev_get_drvdata(dev); 534 struct iio_dev *indio_dev = dev_get_drvdata(dev);
538 struct tiadc_device *adc_dev = iio_priv(indio_dev); 535 struct tiadc_device *adc_dev = iio_priv(indio_dev);
@@ -550,7 +547,7 @@ static int tiadc_suspend(struct device *dev)
550 return 0; 547 return 0;
551} 548}
552 549
553static int tiadc_resume(struct device *dev) 550static int __maybe_unused tiadc_resume(struct device *dev)
554{ 551{
555 struct iio_dev *indio_dev = dev_get_drvdata(dev); 552 struct iio_dev *indio_dev = dev_get_drvdata(dev);
556 struct tiadc_device *adc_dev = iio_priv(indio_dev); 553 struct tiadc_device *adc_dev = iio_priv(indio_dev);
@@ -567,14 +564,7 @@ static int tiadc_resume(struct device *dev)
567 return 0; 564 return 0;
568} 565}
569 566
570static const struct dev_pm_ops tiadc_pm_ops = { 567static SIMPLE_DEV_PM_OPS(tiadc_pm_ops, tiadc_suspend, tiadc_resume);
571 .suspend = tiadc_suspend,
572 .resume = tiadc_resume,
573};
574#define TIADC_PM_OPS (&tiadc_pm_ops)
575#else
576#define TIADC_PM_OPS NULL
577#endif
578 568
579static const struct of_device_id ti_adc_dt_ids[] = { 569static const struct of_device_id ti_adc_dt_ids[] = {
580 { .compatible = "ti,am3359-adc", }, 570 { .compatible = "ti,am3359-adc", },
@@ -585,7 +575,7 @@ MODULE_DEVICE_TABLE(of, ti_adc_dt_ids);
585static struct platform_driver tiadc_driver = { 575static struct platform_driver tiadc_driver = {
586 .driver = { 576 .driver = {
587 .name = "TI-am335x-adc", 577 .name = "TI-am335x-adc",
588 .pm = TIADC_PM_OPS, 578 .pm = &tiadc_pm_ops,
589 .of_match_table = ti_adc_dt_ids, 579 .of_match_table = ti_adc_dt_ids,
590 }, 580 },
591 .probe = tiadc_probe, 581 .probe = tiadc_probe,
diff --git a/drivers/iio/chemical/Kconfig b/drivers/iio/chemical/Kconfig
index f73290f84c90..4bcc025e8c8a 100644
--- a/drivers/iio/chemical/Kconfig
+++ b/drivers/iio/chemical/Kconfig
@@ -5,15 +5,17 @@
5menu "Chemical Sensors" 5menu "Chemical Sensors"
6 6
7config ATLAS_PH_SENSOR 7config ATLAS_PH_SENSOR
8 tristate "Atlas Scientific OEM pH-SM sensor" 8 tristate "Atlas Scientific OEM SM sensors"
9 depends on I2C 9 depends on I2C
10 select REGMAP_I2C 10 select REGMAP_I2C
11 select IIO_BUFFER 11 select IIO_BUFFER
12 select IIO_TRIGGERED_BUFFER 12 select IIO_TRIGGERED_BUFFER
13 select IRQ_WORK 13 select IRQ_WORK
14 help 14 help
15 Say Y here to build I2C interface support for the Atlas 15 Say Y here to build I2C interface support for the following
16 Scientific OEM pH-SM sensor. 16 Atlas Scientific OEM SM sensors:
17 * pH SM sensor
18 * EC SM sensor
17 19
18 To compile this driver as module, choose M here: the 20 To compile this driver as module, choose M here: the
19 module will be called atlas-ph-sensor. 21 module will be called atlas-ph-sensor.
diff --git a/drivers/iio/chemical/atlas-ph-sensor.c b/drivers/iio/chemical/atlas-ph-sensor.c
index 62b37cd8fb56..02e85db5d31f 100644
--- a/drivers/iio/chemical/atlas-ph-sensor.c
+++ b/drivers/iio/chemical/atlas-ph-sensor.c
@@ -24,6 +24,7 @@
24#include <linux/irq_work.h> 24#include <linux/irq_work.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/of_device.h>
27#include <linux/regmap.h> 28#include <linux/regmap.h>
28#include <linux/iio/iio.h> 29#include <linux/iio/iio.h>
29#include <linux/iio/buffer.h> 30#include <linux/iio/buffer.h>
@@ -43,29 +44,50 @@
43 44
44#define ATLAS_REG_PWR_CONTROL 0x06 45#define ATLAS_REG_PWR_CONTROL 0x06
45 46
46#define ATLAS_REG_CALIB_STATUS 0x0d 47#define ATLAS_REG_PH_CALIB_STATUS 0x0d
47#define ATLAS_REG_CALIB_STATUS_MASK 0x07 48#define ATLAS_REG_PH_CALIB_STATUS_MASK 0x07
48#define ATLAS_REG_CALIB_STATUS_LOW BIT(0) 49#define ATLAS_REG_PH_CALIB_STATUS_LOW BIT(0)
49#define ATLAS_REG_CALIB_STATUS_MID BIT(1) 50#define ATLAS_REG_PH_CALIB_STATUS_MID BIT(1)
50#define ATLAS_REG_CALIB_STATUS_HIGH BIT(2) 51#define ATLAS_REG_PH_CALIB_STATUS_HIGH BIT(2)
51 52
52#define ATLAS_REG_TEMP_DATA 0x0e 53#define ATLAS_REG_EC_CALIB_STATUS 0x0f
54#define ATLAS_REG_EC_CALIB_STATUS_MASK 0x0f
55#define ATLAS_REG_EC_CALIB_STATUS_DRY BIT(0)
56#define ATLAS_REG_EC_CALIB_STATUS_SINGLE BIT(1)
57#define ATLAS_REG_EC_CALIB_STATUS_LOW BIT(2)
58#define ATLAS_REG_EC_CALIB_STATUS_HIGH BIT(3)
59
60#define ATLAS_REG_PH_TEMP_DATA 0x0e
53#define ATLAS_REG_PH_DATA 0x16 61#define ATLAS_REG_PH_DATA 0x16
54 62
63#define ATLAS_REG_EC_PROBE 0x08
64#define ATLAS_REG_EC_TEMP_DATA 0x10
65#define ATLAS_REG_EC_DATA 0x18
66#define ATLAS_REG_TDS_DATA 0x1c
67#define ATLAS_REG_PSS_DATA 0x20
68
55#define ATLAS_PH_INT_TIME_IN_US 450000 69#define ATLAS_PH_INT_TIME_IN_US 450000
70#define ATLAS_EC_INT_TIME_IN_US 650000
71
72enum {
73 ATLAS_PH_SM,
74 ATLAS_EC_SM,
75};
56 76
57struct atlas_data { 77struct atlas_data {
58 struct i2c_client *client; 78 struct i2c_client *client;
59 struct iio_trigger *trig; 79 struct iio_trigger *trig;
80 struct atlas_device *chip;
60 struct regmap *regmap; 81 struct regmap *regmap;
61 struct irq_work work; 82 struct irq_work work;
62 83
63 __be32 buffer[4]; /* 32-bit pH data + 32-bit pad + 64-bit timestamp */ 84 __be32 buffer[6]; /* 96-bit data + 32-bit pad + 64-bit timestamp */
64}; 85};
65 86
66static const struct regmap_range atlas_volatile_ranges[] = { 87static const struct regmap_range atlas_volatile_ranges[] = {
67 regmap_reg_range(ATLAS_REG_INT_CONTROL, ATLAS_REG_INT_CONTROL), 88 regmap_reg_range(ATLAS_REG_INT_CONTROL, ATLAS_REG_INT_CONTROL),
68 regmap_reg_range(ATLAS_REG_PH_DATA, ATLAS_REG_PH_DATA + 4), 89 regmap_reg_range(ATLAS_REG_PH_DATA, ATLAS_REG_PH_DATA + 4),
90 regmap_reg_range(ATLAS_REG_EC_DATA, ATLAS_REG_PSS_DATA + 4),
69}; 91};
70 92
71static const struct regmap_access_table atlas_volatile_table = { 93static const struct regmap_access_table atlas_volatile_table = {
@@ -80,13 +102,14 @@ static const struct regmap_config atlas_regmap_config = {
80 .val_bits = 8, 102 .val_bits = 8,
81 103
82 .volatile_table = &atlas_volatile_table, 104 .volatile_table = &atlas_volatile_table,
83 .max_register = ATLAS_REG_PH_DATA + 4, 105 .max_register = ATLAS_REG_PSS_DATA + 4,
84 .cache_type = REGCACHE_RBTREE, 106 .cache_type = REGCACHE_RBTREE,
85}; 107};
86 108
87static const struct iio_chan_spec atlas_channels[] = { 109static const struct iio_chan_spec atlas_ph_channels[] = {
88 { 110 {
89 .type = IIO_PH, 111 .type = IIO_PH,
112 .address = ATLAS_REG_PH_DATA,
90 .info_mask_separate = 113 .info_mask_separate =
91 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 114 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
92 .scan_index = 0, 115 .scan_index = 0,
@@ -100,7 +123,7 @@ static const struct iio_chan_spec atlas_channels[] = {
100 IIO_CHAN_SOFT_TIMESTAMP(1), 123 IIO_CHAN_SOFT_TIMESTAMP(1),
101 { 124 {
102 .type = IIO_TEMP, 125 .type = IIO_TEMP,
103 .address = ATLAS_REG_TEMP_DATA, 126 .address = ATLAS_REG_PH_TEMP_DATA,
104 .info_mask_separate = 127 .info_mask_separate =
105 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), 128 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
106 .output = 1, 129 .output = 1,
@@ -108,6 +131,142 @@ static const struct iio_chan_spec atlas_channels[] = {
108 }, 131 },
109}; 132};
110 133
134#define ATLAS_EC_CHANNEL(_idx, _addr) \
135 {\
136 .type = IIO_CONCENTRATION, \
137 .indexed = 1, \
138 .channel = _idx, \
139 .address = _addr, \
140 .info_mask_separate = \
141 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), \
142 .scan_index = _idx + 1, \
143 .scan_type = { \
144 .sign = 'u', \
145 .realbits = 32, \
146 .storagebits = 32, \
147 .endianness = IIO_BE, \
148 }, \
149 }
150
151static const struct iio_chan_spec atlas_ec_channels[] = {
152 {
153 .type = IIO_ELECTRICALCONDUCTIVITY,
154 .address = ATLAS_REG_EC_DATA,
155 .info_mask_separate =
156 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
157 .scan_index = 0,
158 .scan_type = {
159 .sign = 'u',
160 .realbits = 32,
161 .storagebits = 32,
162 .endianness = IIO_BE,
163 },
164 },
165 ATLAS_EC_CHANNEL(0, ATLAS_REG_TDS_DATA),
166 ATLAS_EC_CHANNEL(1, ATLAS_REG_PSS_DATA),
167 IIO_CHAN_SOFT_TIMESTAMP(3),
168 {
169 .type = IIO_TEMP,
170 .address = ATLAS_REG_EC_TEMP_DATA,
171 .info_mask_separate =
172 BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE),
173 .output = 1,
174 .scan_index = -1
175 },
176};
177
178static int atlas_check_ph_calibration(struct atlas_data *data)
179{
180 struct device *dev = &data->client->dev;
181 int ret;
182 unsigned int val;
183
184 ret = regmap_read(data->regmap, ATLAS_REG_PH_CALIB_STATUS, &val);
185 if (ret)
186 return ret;
187
188 if (!(val & ATLAS_REG_PH_CALIB_STATUS_MASK)) {
189 dev_warn(dev, "device has not been calibrated\n");
190 return 0;
191 }
192
193 if (!(val & ATLAS_REG_PH_CALIB_STATUS_LOW))
194 dev_warn(dev, "device missing low point calibration\n");
195
196 if (!(val & ATLAS_REG_PH_CALIB_STATUS_MID))
197 dev_warn(dev, "device missing mid point calibration\n");
198
199 if (!(val & ATLAS_REG_PH_CALIB_STATUS_HIGH))
200 dev_warn(dev, "device missing high point calibration\n");
201
202 return 0;
203}
204
205static int atlas_check_ec_calibration(struct atlas_data *data)
206{
207 struct device *dev = &data->client->dev;
208 int ret;
209 unsigned int val;
210
211 ret = regmap_bulk_read(data->regmap, ATLAS_REG_EC_PROBE, &val, 2);
212 if (ret)
213 return ret;
214
215 dev_info(dev, "probe set to K = %d.%.2d", be16_to_cpu(val) / 100,
216 be16_to_cpu(val) % 100);
217
218 ret = regmap_read(data->regmap, ATLAS_REG_EC_CALIB_STATUS, &val);
219 if (ret)
220 return ret;
221
222 if (!(val & ATLAS_REG_EC_CALIB_STATUS_MASK)) {
223 dev_warn(dev, "device has not been calibrated\n");
224 return 0;
225 }
226
227 if (!(val & ATLAS_REG_EC_CALIB_STATUS_DRY))
228 dev_warn(dev, "device missing dry point calibration\n");
229
230 if (val & ATLAS_REG_EC_CALIB_STATUS_SINGLE) {
231 dev_warn(dev, "device using single point calibration\n");
232 } else {
233 if (!(val & ATLAS_REG_EC_CALIB_STATUS_LOW))
234 dev_warn(dev, "device missing low point calibration\n");
235
236 if (!(val & ATLAS_REG_EC_CALIB_STATUS_HIGH))
237 dev_warn(dev, "device missing high point calibration\n");
238 }
239
240 return 0;
241}
242
243struct atlas_device {
244 const struct iio_chan_spec *channels;
245 int num_channels;
246 int data_reg;
247
248 int (*calibration)(struct atlas_data *data);
249 int delay;
250};
251
252static struct atlas_device atlas_devices[] = {
253 [ATLAS_PH_SM] = {
254 .channels = atlas_ph_channels,
255 .num_channels = 3,
256 .data_reg = ATLAS_REG_PH_DATA,
257 .calibration = &atlas_check_ph_calibration,
258 .delay = ATLAS_PH_INT_TIME_IN_US,
259 },
260 [ATLAS_EC_SM] = {
261 .channels = atlas_ec_channels,
262 .num_channels = 5,
263 .data_reg = ATLAS_REG_EC_DATA,
264 .calibration = &atlas_check_ec_calibration,
265 .delay = ATLAS_EC_INT_TIME_IN_US,
266 },
267
268};
269
111static int atlas_set_powermode(struct atlas_data *data, int on) 270static int atlas_set_powermode(struct atlas_data *data, int on)
112{ 271{
113 return regmap_write(data->regmap, ATLAS_REG_PWR_CONTROL, on); 272 return regmap_write(data->regmap, ATLAS_REG_PWR_CONTROL, on);
@@ -178,8 +337,9 @@ static irqreturn_t atlas_trigger_handler(int irq, void *private)
178 struct atlas_data *data = iio_priv(indio_dev); 337 struct atlas_data *data = iio_priv(indio_dev);
179 int ret; 338 int ret;
180 339
181 ret = regmap_bulk_read(data->regmap, ATLAS_REG_PH_DATA, 340 ret = regmap_bulk_read(data->regmap, data->chip->data_reg,
182 (u8 *) &data->buffer, sizeof(data->buffer[0])); 341 (u8 *) &data->buffer,
342 sizeof(__be32) * (data->chip->num_channels - 2));
183 343
184 if (!ret) 344 if (!ret)
185 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer, 345 iio_push_to_buffers_with_timestamp(indio_dev, data->buffer,
@@ -200,7 +360,7 @@ static irqreturn_t atlas_interrupt_handler(int irq, void *private)
200 return IRQ_HANDLED; 360 return IRQ_HANDLED;
201} 361}
202 362
203static int atlas_read_ph_measurement(struct atlas_data *data, __be32 *val) 363static int atlas_read_measurement(struct atlas_data *data, int reg, __be32 *val)
204{ 364{
205 struct device *dev = &data->client->dev; 365 struct device *dev = &data->client->dev;
206 int suspended = pm_runtime_suspended(dev); 366 int suspended = pm_runtime_suspended(dev);
@@ -213,11 +373,9 @@ static int atlas_read_ph_measurement(struct atlas_data *data, __be32 *val)
213 } 373 }
214 374
215 if (suspended) 375 if (suspended)
216 usleep_range(ATLAS_PH_INT_TIME_IN_US, 376 usleep_range(data->chip->delay, data->chip->delay + 100000);
217 ATLAS_PH_INT_TIME_IN_US + 100000);
218 377
219 ret = regmap_bulk_read(data->regmap, ATLAS_REG_PH_DATA, 378 ret = regmap_bulk_read(data->regmap, reg, (u8 *) val, sizeof(*val));
220 (u8 *) val, sizeof(*val));
221 379
222 pm_runtime_mark_last_busy(dev); 380 pm_runtime_mark_last_busy(dev);
223 pm_runtime_put_autosuspend(dev); 381 pm_runtime_put_autosuspend(dev);
@@ -242,12 +400,15 @@ static int atlas_read_raw(struct iio_dev *indio_dev,
242 (u8 *) &reg, sizeof(reg)); 400 (u8 *) &reg, sizeof(reg));
243 break; 401 break;
244 case IIO_PH: 402 case IIO_PH:
403 case IIO_CONCENTRATION:
404 case IIO_ELECTRICALCONDUCTIVITY:
245 mutex_lock(&indio_dev->mlock); 405 mutex_lock(&indio_dev->mlock);
246 406
247 if (iio_buffer_enabled(indio_dev)) 407 if (iio_buffer_enabled(indio_dev))
248 ret = -EBUSY; 408 ret = -EBUSY;
249 else 409 else
250 ret = atlas_read_ph_measurement(data, &reg); 410 ret = atlas_read_measurement(data,
411 chan->address, &reg);
251 412
252 mutex_unlock(&indio_dev->mlock); 413 mutex_unlock(&indio_dev->mlock);
253 break; 414 break;
@@ -271,6 +432,14 @@ static int atlas_read_raw(struct iio_dev *indio_dev,
271 *val = 1; /* 0.001 */ 432 *val = 1; /* 0.001 */
272 *val2 = 1000; 433 *val2 = 1000;
273 break; 434 break;
435 case IIO_ELECTRICALCONDUCTIVITY:
436 *val = 1; /* 0.00001 */
437 *val = 100000;
438 break;
439 case IIO_CONCENTRATION:
440 *val = 0; /* 0.000000001 */
441 *val2 = 1000;
442 return IIO_VAL_INT_PLUS_NANO;
274 default: 443 default:
275 return -EINVAL; 444 return -EINVAL;
276 } 445 }
@@ -303,37 +472,26 @@ static const struct iio_info atlas_info = {
303 .write_raw = atlas_write_raw, 472 .write_raw = atlas_write_raw,
304}; 473};
305 474
306static int atlas_check_calibration(struct atlas_data *data) 475static const struct i2c_device_id atlas_id[] = {
307{ 476 { "atlas-ph-sm", ATLAS_PH_SM},
308 struct device *dev = &data->client->dev; 477 { "atlas-ec-sm", ATLAS_EC_SM},
309 int ret; 478 {}
310 unsigned int val; 479};
311 480MODULE_DEVICE_TABLE(i2c, atlas_id);
312 ret = regmap_read(data->regmap, ATLAS_REG_CALIB_STATUS, &val);
313 if (ret)
314 return ret;
315
316 if (!(val & ATLAS_REG_CALIB_STATUS_MASK)) {
317 dev_warn(dev, "device has not been calibrated\n");
318 return 0;
319 }
320
321 if (!(val & ATLAS_REG_CALIB_STATUS_LOW))
322 dev_warn(dev, "device missing low point calibration\n");
323
324 if (!(val & ATLAS_REG_CALIB_STATUS_MID))
325 dev_warn(dev, "device missing mid point calibration\n");
326
327 if (!(val & ATLAS_REG_CALIB_STATUS_HIGH))
328 dev_warn(dev, "device missing high point calibration\n");
329 481
330 return 0; 482static const struct of_device_id atlas_dt_ids[] = {
483 { .compatible = "atlas,ph-sm", .data = (void *)ATLAS_PH_SM, },
484 { .compatible = "atlas,ec-sm", .data = (void *)ATLAS_EC_SM, },
485 { }
331}; 486};
487MODULE_DEVICE_TABLE(of, atlas_dt_ids);
332 488
333static int atlas_probe(struct i2c_client *client, 489static int atlas_probe(struct i2c_client *client,
334 const struct i2c_device_id *id) 490 const struct i2c_device_id *id)
335{ 491{
336 struct atlas_data *data; 492 struct atlas_data *data;
493 struct atlas_device *chip;
494 const struct of_device_id *of_id;
337 struct iio_trigger *trig; 495 struct iio_trigger *trig;
338 struct iio_dev *indio_dev; 496 struct iio_dev *indio_dev;
339 int ret; 497 int ret;
@@ -342,10 +500,16 @@ static int atlas_probe(struct i2c_client *client,
342 if (!indio_dev) 500 if (!indio_dev)
343 return -ENOMEM; 501 return -ENOMEM;
344 502
503 of_id = of_match_device(atlas_dt_ids, &client->dev);
504 if (!of_id)
505 chip = &atlas_devices[id->driver_data];
506 else
507 chip = &atlas_devices[(unsigned long)of_id->data];
508
345 indio_dev->info = &atlas_info; 509 indio_dev->info = &atlas_info;
346 indio_dev->name = ATLAS_DRV_NAME; 510 indio_dev->name = ATLAS_DRV_NAME;
347 indio_dev->channels = atlas_channels; 511 indio_dev->channels = chip->channels;
348 indio_dev->num_channels = ARRAY_SIZE(atlas_channels); 512 indio_dev->num_channels = chip->num_channels;
349 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE; 513 indio_dev->modes = INDIO_BUFFER_SOFTWARE | INDIO_DIRECT_MODE;
350 indio_dev->dev.parent = &client->dev; 514 indio_dev->dev.parent = &client->dev;
351 515
@@ -358,6 +522,7 @@ static int atlas_probe(struct i2c_client *client,
358 data = iio_priv(indio_dev); 522 data = iio_priv(indio_dev);
359 data->client = client; 523 data->client = client;
360 data->trig = trig; 524 data->trig = trig;
525 data->chip = chip;
361 trig->dev.parent = indio_dev->dev.parent; 526 trig->dev.parent = indio_dev->dev.parent;
362 trig->ops = &atlas_interrupt_trigger_ops; 527 trig->ops = &atlas_interrupt_trigger_ops;
363 iio_trigger_set_drvdata(trig, indio_dev); 528 iio_trigger_set_drvdata(trig, indio_dev);
@@ -379,7 +544,7 @@ static int atlas_probe(struct i2c_client *client,
379 return -EINVAL; 544 return -EINVAL;
380 } 545 }
381 546
382 ret = atlas_check_calibration(data); 547 ret = chip->calibration(data);
383 if (ret) 548 if (ret)
384 return ret; 549 return ret;
385 550
@@ -480,18 +645,6 @@ static const struct dev_pm_ops atlas_pm_ops = {
480 atlas_runtime_resume, NULL) 645 atlas_runtime_resume, NULL)
481}; 646};
482 647
483static const struct i2c_device_id atlas_id[] = {
484 { "atlas-ph-sm", 0 },
485 {}
486};
487MODULE_DEVICE_TABLE(i2c, atlas_id);
488
489static const struct of_device_id atlas_dt_ids[] = {
490 { .compatible = "atlas,ph-sm" },
491 { }
492};
493MODULE_DEVICE_TABLE(of, atlas_dt_ids);
494
495static struct i2c_driver atlas_driver = { 648static struct i2c_driver atlas_driver = {
496 .driver = { 649 .driver = {
497 .name = ATLAS_DRV_NAME, 650 .name = ATLAS_DRV_NAME,
diff --git a/drivers/iio/common/st_sensors/st_sensors_buffer.c b/drivers/iio/common/st_sensors/st_sensors_buffer.c
index f1693dbebb8a..50afc0f8f16b 100644
--- a/drivers/iio/common/st_sensors/st_sensors_buffer.c
+++ b/drivers/iio/common/st_sensors/st_sensors_buffer.c
@@ -22,7 +22,7 @@
22#include <linux/iio/common/st_sensors.h> 22#include <linux/iio/common/st_sensors.h>
23 23
24 24
25int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf) 25static int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
26{ 26{
27 int i, len; 27 int i, len;
28 int total = 0; 28 int total = 0;
@@ -49,7 +49,6 @@ int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
49 49
50 return total; 50 return total;
51} 51}
52EXPORT_SYMBOL(st_sensors_get_buffer_element);
53 52
54irqreturn_t st_sensors_trigger_handler(int irq, void *p) 53irqreturn_t st_sensors_trigger_handler(int irq, void *p)
55{ 54{
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 9e59c90f6a8d..6db12ea034d3 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -228,7 +228,7 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
228} 228}
229EXPORT_SYMBOL(st_sensors_set_axis_enable); 229EXPORT_SYMBOL(st_sensors_set_axis_enable);
230 230
231void st_sensors_power_enable(struct iio_dev *indio_dev) 231int st_sensors_power_enable(struct iio_dev *indio_dev)
232{ 232{
233 struct st_sensor_data *pdata = iio_priv(indio_dev); 233 struct st_sensor_data *pdata = iio_priv(indio_dev);
234 int err; 234 int err;
@@ -237,18 +237,37 @@ void st_sensors_power_enable(struct iio_dev *indio_dev)
237 pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd"); 237 pdata->vdd = devm_regulator_get_optional(indio_dev->dev.parent, "vdd");
238 if (!IS_ERR(pdata->vdd)) { 238 if (!IS_ERR(pdata->vdd)) {
239 err = regulator_enable(pdata->vdd); 239 err = regulator_enable(pdata->vdd);
240 if (err != 0) 240 if (err != 0) {
241 dev_warn(&indio_dev->dev, 241 dev_warn(&indio_dev->dev,
242 "Failed to enable specified Vdd supply\n"); 242 "Failed to enable specified Vdd supply\n");
243 return err;
244 }
245 } else {
246 err = PTR_ERR(pdata->vdd);
247 if (err != -ENODEV)
248 return err;
243 } 249 }
244 250
245 pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio"); 251 pdata->vdd_io = devm_regulator_get_optional(indio_dev->dev.parent, "vddio");
246 if (!IS_ERR(pdata->vdd_io)) { 252 if (!IS_ERR(pdata->vdd_io)) {
247 err = regulator_enable(pdata->vdd_io); 253 err = regulator_enable(pdata->vdd_io);
248 if (err != 0) 254 if (err != 0) {
249 dev_warn(&indio_dev->dev, 255 dev_warn(&indio_dev->dev,
250 "Failed to enable specified Vdd_IO supply\n"); 256 "Failed to enable specified Vdd_IO supply\n");
257 goto st_sensors_disable_vdd;
258 }
259 } else {
260 err = PTR_ERR(pdata->vdd_io);
261 if (err != -ENODEV)
262 goto st_sensors_disable_vdd;
251 } 263 }
264
265 return 0;
266
267st_sensors_disable_vdd:
268 if (!IS_ERR_OR_NULL(pdata->vdd))
269 regulator_disable(pdata->vdd);
270 return err;
252} 271}
253EXPORT_SYMBOL(st_sensors_power_enable); 272EXPORT_SYMBOL(st_sensors_power_enable);
254 273
@@ -256,10 +275,10 @@ void st_sensors_power_disable(struct iio_dev *indio_dev)
256{ 275{
257 struct st_sensor_data *pdata = iio_priv(indio_dev); 276 struct st_sensor_data *pdata = iio_priv(indio_dev);
258 277
259 if (!IS_ERR(pdata->vdd)) 278 if (!IS_ERR_OR_NULL(pdata->vdd))
260 regulator_disable(pdata->vdd); 279 regulator_disable(pdata->vdd);
261 280
262 if (!IS_ERR(pdata->vdd_io)) 281 if (!IS_ERR_OR_NULL(pdata->vdd_io))
263 regulator_disable(pdata->vdd_io); 282 regulator_disable(pdata->vdd_io);
264} 283}
265EXPORT_SYMBOL(st_sensors_power_disable); 284EXPORT_SYMBOL(st_sensors_power_disable);
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
index 98cfee296d46..b43aa36031f8 100644
--- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -48,8 +48,8 @@ static int st_sensors_i2c_read_multiple_byte(
48 if (multiread_bit) 48 if (multiread_bit)
49 reg_addr |= ST_SENSORS_I2C_MULTIREAD; 49 reg_addr |= ST_SENSORS_I2C_MULTIREAD;
50 50
51 return i2c_smbus_read_i2c_block_data(to_i2c_client(dev), 51 return i2c_smbus_read_i2c_block_data_or_emulated(to_i2c_client(dev),
52 reg_addr, len, data); 52 reg_addr, len, data);
53} 53}
54 54
55static int st_sensors_i2c_write_byte(struct st_sensor_transfer_buffer *tb, 55static int st_sensors_i2c_write_byte(struct st_sensor_transfer_buffer *tb,
diff --git a/drivers/iio/dummy/Kconfig b/drivers/iio/dummy/Kconfig
index 71805ced1aae..aa5824d96a43 100644
--- a/drivers/iio/dummy/Kconfig
+++ b/drivers/iio/dummy/Kconfig
@@ -10,6 +10,7 @@ config IIO_DUMMY_EVGEN
10 10
11config IIO_SIMPLE_DUMMY 11config IIO_SIMPLE_DUMMY
12 tristate "An example driver with no hardware requirements" 12 tristate "An example driver with no hardware requirements"
13 depends on IIO_SW_DEVICE
13 help 14 help
14 Driver intended mainly as documentation for how to write 15 Driver intended mainly as documentation for how to write
15 a driver. May also be useful for testing userspace code 16 a driver. May also be useful for testing userspace code
diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
index 43fe4ba7d0dc..ad3410e528b6 100644
--- a/drivers/iio/dummy/iio_simple_dummy.c
+++ b/drivers/iio/dummy/iio_simple_dummy.c
@@ -17,26 +17,18 @@
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/string.h>
20 21
21#include <linux/iio/iio.h> 22#include <linux/iio/iio.h>
22#include <linux/iio/sysfs.h> 23#include <linux/iio/sysfs.h>
23#include <linux/iio/events.h> 24#include <linux/iio/events.h>
24#include <linux/iio/buffer.h> 25#include <linux/iio/buffer.h>
26#include <linux/iio/sw_device.h>
25#include "iio_simple_dummy.h" 27#include "iio_simple_dummy.h"
26 28
27/* 29static struct config_item_type iio_dummy_type = {
28 * A few elements needed to fake a bus for this driver 30 .ct_owner = THIS_MODULE,
29 * Note instances parameter controls how many of these 31};
30 * dummy devices are registered.
31 */
32static unsigned instances = 1;
33module_param(instances, uint, 0);
34
35/* Pointer array used to fake bus elements */
36static struct iio_dev **iio_dummy_devs;
37
38/* Fake a name for the part number, usually obtained from the id table */
39static const char *iio_dummy_part_number = "iio_dummy_part_no";
40 32
41/** 33/**
42 * struct iio_dummy_accel_calibscale - realworld to register mapping 34 * struct iio_dummy_accel_calibscale - realworld to register mapping
@@ -572,12 +564,18 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev)
572 * const struct i2c_device_id *id) 564 * const struct i2c_device_id *id)
573 * SPI: iio_dummy_probe(struct spi_device *spi) 565 * SPI: iio_dummy_probe(struct spi_device *spi)
574 */ 566 */
575static int iio_dummy_probe(int index) 567static struct iio_sw_device *iio_dummy_probe(const char *name)
576{ 568{
577 int ret; 569 int ret;
578 struct iio_dev *indio_dev; 570 struct iio_dev *indio_dev;
579 struct iio_dummy_state *st; 571 struct iio_dummy_state *st;
572 struct iio_sw_device *swd;
580 573
574 swd = kzalloc(sizeof(*swd), GFP_KERNEL);
575 if (!swd) {
576 ret = -ENOMEM;
577 goto error_kzalloc;
578 }
581 /* 579 /*
582 * Allocate an IIO device. 580 * Allocate an IIO device.
583 * 581 *
@@ -608,7 +606,7 @@ static int iio_dummy_probe(int index)
608 * i2c_set_clientdata(client, indio_dev); 606 * i2c_set_clientdata(client, indio_dev);
609 * spi_set_drvdata(spi, indio_dev); 607 * spi_set_drvdata(spi, indio_dev);
610 */ 608 */
611 iio_dummy_devs[index] = indio_dev; 609 swd->device = indio_dev;
612 610
613 /* 611 /*
614 * Set the device name. 612 * Set the device name.
@@ -619,7 +617,7 @@ static int iio_dummy_probe(int index)
619 * indio_dev->name = id->name; 617 * indio_dev->name = id->name;
620 * indio_dev->name = spi_get_device_id(spi)->name; 618 * indio_dev->name = spi_get_device_id(spi)->name;
621 */ 619 */
622 indio_dev->name = iio_dummy_part_number; 620 indio_dev->name = kstrdup(name, GFP_KERNEL);
623 621
624 /* Provide description of available channels */ 622 /* Provide description of available channels */
625 indio_dev->channels = iio_dummy_channels; 623 indio_dev->channels = iio_dummy_channels;
@@ -646,7 +644,9 @@ static int iio_dummy_probe(int index)
646 if (ret < 0) 644 if (ret < 0)
647 goto error_unconfigure_buffer; 645 goto error_unconfigure_buffer;
648 646
649 return 0; 647 iio_swd_group_init_type_name(swd, name, &iio_dummy_type);
648
649 return swd;
650error_unconfigure_buffer: 650error_unconfigure_buffer:
651 iio_simple_dummy_unconfigure_buffer(indio_dev); 651 iio_simple_dummy_unconfigure_buffer(indio_dev);
652error_unregister_events: 652error_unregister_events:
@@ -654,16 +654,18 @@ error_unregister_events:
654error_free_device: 654error_free_device:
655 iio_device_free(indio_dev); 655 iio_device_free(indio_dev);
656error_ret: 656error_ret:
657 return ret; 657 kfree(swd);
658error_kzalloc:
659 return ERR_PTR(ret);
658} 660}
659 661
660/** 662/**
661 * iio_dummy_remove() - device instance removal function 663 * iio_dummy_remove() - device instance removal function
662 * @index: device index. 664 * @swd: pointer to software IIO device abstraction
663 * 665 *
664 * Parameters follow those of iio_dummy_probe for buses. 666 * Parameters follow those of iio_dummy_probe for buses.
665 */ 667 */
666static void iio_dummy_remove(int index) 668static int iio_dummy_remove(struct iio_sw_device *swd)
667{ 669{
668 /* 670 /*
669 * Get a pointer to the device instance iio_dev structure 671 * Get a pointer to the device instance iio_dev structure
@@ -671,7 +673,7 @@ static void iio_dummy_remove(int index)
671 * struct iio_dev *indio_dev = i2c_get_clientdata(client); 673 * struct iio_dev *indio_dev = i2c_get_clientdata(client);
672 * struct iio_dev *indio_dev = spi_get_drvdata(spi); 674 * struct iio_dev *indio_dev = spi_get_drvdata(spi);
673 */ 675 */
674 struct iio_dev *indio_dev = iio_dummy_devs[index]; 676 struct iio_dev *indio_dev = swd->device;
675 677
676 /* Unregister the device */ 678 /* Unregister the device */
677 iio_device_unregister(indio_dev); 679 iio_device_unregister(indio_dev);
@@ -684,11 +686,13 @@ static void iio_dummy_remove(int index)
684 iio_simple_dummy_events_unregister(indio_dev); 686 iio_simple_dummy_events_unregister(indio_dev);
685 687
686 /* Free all structures */ 688 /* Free all structures */
689 kfree(indio_dev->name);
687 iio_device_free(indio_dev); 690 iio_device_free(indio_dev);
688}
689 691
692 return 0;
693}
690/** 694/**
691 * iio_dummy_init() - device driver registration 695 * module_iio_sw_device_driver() - device driver registration
692 * 696 *
693 * Varies depending on bus type of the device. As there is no device 697 * Varies depending on bus type of the device. As there is no device
694 * here, call probe directly. For information on device registration 698 * here, call probe directly. For information on device registration
@@ -697,50 +701,18 @@ static void iio_dummy_remove(int index)
697 * spi: 701 * spi:
698 * Documentation/spi/spi-summary 702 * Documentation/spi/spi-summary
699 */ 703 */
700static __init int iio_dummy_init(void) 704static const struct iio_sw_device_ops iio_dummy_device_ops = {
701{ 705 .probe = iio_dummy_probe,
702 int i, ret; 706 .remove = iio_dummy_remove,
703 707};
704 if (instances > 10) {
705 instances = 1;
706 return -EINVAL;
707 }
708
709 /* Fake a bus */
710 iio_dummy_devs = kcalloc(instances, sizeof(*iio_dummy_devs),
711 GFP_KERNEL);
712 /* Here we have no actual device so call probe */
713 for (i = 0; i < instances; i++) {
714 ret = iio_dummy_probe(i);
715 if (ret < 0)
716 goto error_remove_devs;
717 }
718 return 0;
719
720error_remove_devs:
721 while (i--)
722 iio_dummy_remove(i);
723
724 kfree(iio_dummy_devs);
725 return ret;
726}
727module_init(iio_dummy_init);
728 708
729/** 709static struct iio_sw_device_type iio_dummy_device = {
730 * iio_dummy_exit() - device driver removal 710 .name = "dummy",
731 * 711 .owner = THIS_MODULE,
732 * Varies depending on bus type of the device. 712 .ops = &iio_dummy_device_ops,
733 * As there is no device here, call remove directly. 713};
734 */
735static __exit void iio_dummy_exit(void)
736{
737 int i;
738 714
739 for (i = 0; i < instances; i++) 715module_iio_sw_device_driver(iio_dummy_device);
740 iio_dummy_remove(i);
741 kfree(iio_dummy_devs);
742}
743module_exit(iio_dummy_exit);
744 716
745MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>"); 717MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
746MODULE_DESCRIPTION("IIO dummy driver"); 718MODULE_DESCRIPTION("IIO dummy driver");
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index a8012955a1f6..aea034d8fe0f 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -426,13 +426,15 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
426 indio_dev->info = &gyro_info; 426 indio_dev->info = &gyro_info;
427 mutex_init(&gdata->tb.buf_lock); 427 mutex_init(&gdata->tb.buf_lock);
428 428
429 st_sensors_power_enable(indio_dev); 429 err = st_sensors_power_enable(indio_dev);
430 if (err)
431 return err;
430 432
431 err = st_sensors_check_device_support(indio_dev, 433 err = st_sensors_check_device_support(indio_dev,
432 ARRAY_SIZE(st_gyro_sensors_settings), 434 ARRAY_SIZE(st_gyro_sensors_settings),
433 st_gyro_sensors_settings); 435 st_gyro_sensors_settings);
434 if (err < 0) 436 if (err < 0)
435 return err; 437 goto st_gyro_power_off;
436 438
437 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; 439 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS;
438 gdata->multiread_bit = gdata->sensor_settings->multi_read_bit; 440 gdata->multiread_bit = gdata->sensor_settings->multi_read_bit;
@@ -446,11 +448,11 @@ int st_gyro_common_probe(struct iio_dev *indio_dev)
446 err = st_sensors_init_sensor(indio_dev, 448 err = st_sensors_init_sensor(indio_dev,
447 (struct st_sensors_platform_data *)&gyro_pdata); 449 (struct st_sensors_platform_data *)&gyro_pdata);
448 if (err < 0) 450 if (err < 0)
449 return err; 451 goto st_gyro_power_off;
450 452
451 err = st_gyro_allocate_ring(indio_dev); 453 err = st_gyro_allocate_ring(indio_dev);
452 if (err < 0) 454 if (err < 0)
453 return err; 455 goto st_gyro_power_off;
454 456
455 if (irq > 0) { 457 if (irq > 0) {
456 err = st_sensors_allocate_trigger(indio_dev, 458 err = st_sensors_allocate_trigger(indio_dev,
@@ -473,6 +475,8 @@ st_gyro_device_register_error:
473 st_sensors_deallocate_trigger(indio_dev); 475 st_sensors_deallocate_trigger(indio_dev);
474st_gyro_probe_trigger_error: 476st_gyro_probe_trigger_error:
475 st_gyro_deallocate_ring(indio_dev); 477 st_gyro_deallocate_ring(indio_dev);
478st_gyro_power_off:
479 st_sensors_power_disable(indio_dev);
476 480
477 return err; 481 return err;
478} 482}
diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
index 88e43f87b926..9a081465c42f 100644
--- a/drivers/iio/health/afe4403.c
+++ b/drivers/iio/health/afe4403.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters 2 * AFE4403 Heart Rate Monitors and Low-Cost Pulse Oximeters
3 * 3 *
4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 4 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
5 * Andrew F. Davis <afd@ti.com> 5 * Andrew F. Davis <afd@ti.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -39,127 +39,90 @@
39#define AFE4403_TIAGAIN 0x20 39#define AFE4403_TIAGAIN 0x20
40#define AFE4403_TIA_AMB_GAIN 0x21 40#define AFE4403_TIA_AMB_GAIN 0x21
41 41
42/* AFE4403 GAIN register fields */ 42enum afe4403_fields {
43#define AFE4403_TIAGAIN_RES_MASK GENMASK(2, 0) 43 /* Gains */
44#define AFE4403_TIAGAIN_RES_SHIFT 0 44 F_RF_LED1, F_CF_LED1,
45#define AFE4403_TIAGAIN_CAP_MASK GENMASK(7, 3) 45 F_RF_LED, F_CF_LED,
46#define AFE4403_TIAGAIN_CAP_SHIFT 3 46
47 47 /* LED Current */
48/* AFE4403 LEDCNTRL register fields */ 48 F_ILED1, F_ILED2,
49#define AFE440X_LEDCNTRL_LED1_MASK GENMASK(15, 8) 49
50#define AFE440X_LEDCNTRL_LED1_SHIFT 8 50 /* sentinel */
51#define AFE440X_LEDCNTRL_LED2_MASK GENMASK(7, 0) 51 F_MAX_FIELDS
52#define AFE440X_LEDCNTRL_LED2_SHIFT 0 52};
53#define AFE440X_LEDCNTRL_LED_RANGE_MASK GENMASK(17, 16) 53
54#define AFE440X_LEDCNTRL_LED_RANGE_SHIFT 16 54static const struct reg_field afe4403_reg_fields[] = {
55 55 /* Gains */
56/* AFE4403 CONTROL2 register fields */ 56 [F_RF_LED1] = REG_FIELD(AFE4403_TIAGAIN, 0, 2),
57#define AFE440X_CONTROL2_PWR_DWN_TX BIT(2) 57 [F_CF_LED1] = REG_FIELD(AFE4403_TIAGAIN, 3, 7),
58#define AFE440X_CONTROL2_EN_SLOW_DIAG BIT(8) 58 [F_RF_LED] = REG_FIELD(AFE4403_TIA_AMB_GAIN, 0, 2),
59#define AFE440X_CONTROL2_DIAG_OUT_TRI BIT(10) 59 [F_CF_LED] = REG_FIELD(AFE4403_TIA_AMB_GAIN, 3, 7),
60#define AFE440X_CONTROL2_TX_BRDG_MOD BIT(11) 60 /* LED Current */
61#define AFE440X_CONTROL2_TX_REF_MASK GENMASK(18, 17) 61 [F_ILED1] = REG_FIELD(AFE440X_LEDCNTRL, 0, 7),
62#define AFE440X_CONTROL2_TX_REF_SHIFT 17 62 [F_ILED2] = REG_FIELD(AFE440X_LEDCNTRL, 8, 15),
63 63};
64/* AFE4404 NULL fields */
65#define NULL_MASK 0
66#define NULL_SHIFT 0
67
68/* AFE4403 LEDCNTRL values */
69#define AFE440X_LEDCNTRL_RANGE_TX_HALF 0x1
70#define AFE440X_LEDCNTRL_RANGE_TX_FULL 0x2
71#define AFE440X_LEDCNTRL_RANGE_TX_OFF 0x3
72
73/* AFE4403 CONTROL2 values */
74#define AFE440X_CONTROL2_TX_REF_025 0x0
75#define AFE440X_CONTROL2_TX_REF_050 0x1
76#define AFE440X_CONTROL2_TX_REF_100 0x2
77#define AFE440X_CONTROL2_TX_REF_075 0x3
78
79/* AFE4403 CONTROL3 values */
80#define AFE440X_CONTROL3_CLK_DIV_2 0x0
81#define AFE440X_CONTROL3_CLK_DIV_4 0x2
82#define AFE440X_CONTROL3_CLK_DIV_6 0x3
83#define AFE440X_CONTROL3_CLK_DIV_8 0x4
84#define AFE440X_CONTROL3_CLK_DIV_12 0x5
85#define AFE440X_CONTROL3_CLK_DIV_1 0x7
86
87/* AFE4403 TIAGAIN_CAP values */
88#define AFE4403_TIAGAIN_CAP_5_P 0x0
89#define AFE4403_TIAGAIN_CAP_10_P 0x1
90#define AFE4403_TIAGAIN_CAP_20_P 0x2
91#define AFE4403_TIAGAIN_CAP_30_P 0x3
92#define AFE4403_TIAGAIN_CAP_55_P 0x8
93#define AFE4403_TIAGAIN_CAP_155_P 0x10
94
95/* AFE4403 TIAGAIN_RES values */
96#define AFE4403_TIAGAIN_RES_500_K 0x0
97#define AFE4403_TIAGAIN_RES_250_K 0x1
98#define AFE4403_TIAGAIN_RES_100_K 0x2
99#define AFE4403_TIAGAIN_RES_50_K 0x3
100#define AFE4403_TIAGAIN_RES_25_K 0x4
101#define AFE4403_TIAGAIN_RES_10_K 0x5
102#define AFE4403_TIAGAIN_RES_1_M 0x6
103#define AFE4403_TIAGAIN_RES_NONE 0x7
104 64
105/** 65/**
106 * struct afe4403_data 66 * struct afe4403_data - AFE4403 device instance data
107 * @dev - Device structure 67 * @dev: Device structure
108 * @spi - SPI device handle 68 * @spi: SPI device handle
109 * @regmap - Register map of the device 69 * @regmap: Register map of the device
110 * @regulator - Pointer to the regulator for the IC 70 * @fields: Register fields of the device
111 * @trig - IIO trigger for this device 71 * @regulator: Pointer to the regulator for the IC
112 * @irq - ADC_RDY line interrupt number 72 * @trig: IIO trigger for this device
73 * @irq: ADC_RDY line interrupt number
113 */ 74 */
114struct afe4403_data { 75struct afe4403_data {
115 struct device *dev; 76 struct device *dev;
116 struct spi_device *spi; 77 struct spi_device *spi;
117 struct regmap *regmap; 78 struct regmap *regmap;
79 struct regmap_field *fields[F_MAX_FIELDS];
118 struct regulator *regulator; 80 struct regulator *regulator;
119 struct iio_trigger *trig; 81 struct iio_trigger *trig;
120 int irq; 82 int irq;
121}; 83};
122 84
123enum afe4403_chan_id { 85enum afe4403_chan_id {
86 LED2 = 1,
87 ALED2,
124 LED1, 88 LED1,
125 ALED1, 89 ALED1,
126 LED2,
127 ALED2,
128 LED1_ALED1,
129 LED2_ALED2, 90 LED2_ALED2,
130 ILED1, 91 LED1_ALED1,
131 ILED2,
132}; 92};
133 93
134static const struct afe440x_reg_info afe4403_reg_info[] = { 94static const unsigned int afe4403_channel_values[] = {
135 [LED1] = AFE440X_REG_INFO(AFE440X_LED1VAL, 0, NULL), 95 [LED2] = AFE440X_LED2VAL,
136 [ALED1] = AFE440X_REG_INFO(AFE440X_ALED1VAL, 0, NULL), 96 [ALED2] = AFE440X_ALED2VAL,
137 [LED2] = AFE440X_REG_INFO(AFE440X_LED2VAL, 0, NULL), 97 [LED1] = AFE440X_LED1VAL,
138 [ALED2] = AFE440X_REG_INFO(AFE440X_ALED2VAL, 0, NULL), 98 [ALED1] = AFE440X_ALED1VAL,
139 [LED1_ALED1] = AFE440X_REG_INFO(AFE440X_LED1_ALED1VAL, 0, NULL), 99 [LED2_ALED2] = AFE440X_LED2_ALED2VAL,
140 [LED2_ALED2] = AFE440X_REG_INFO(AFE440X_LED2_ALED2VAL, 0, NULL), 100 [LED1_ALED1] = AFE440X_LED1_ALED1VAL,
141 [ILED1] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE440X_LEDCNTRL_LED1), 101};
142 [ILED2] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE440X_LEDCNTRL_LED2), 102
103static const unsigned int afe4403_channel_leds[] = {
104 [LED2] = F_ILED2,
105 [LED1] = F_ILED1,
143}; 106};
144 107
145static const struct iio_chan_spec afe4403_channels[] = { 108static const struct iio_chan_spec afe4403_channels[] = {
146 /* ADC values */ 109 /* ADC values */
147 AFE440X_INTENSITY_CHAN(LED1, "led1", 0), 110 AFE440X_INTENSITY_CHAN(LED2, 0),
148 AFE440X_INTENSITY_CHAN(ALED1, "led1_ambient", 0), 111 AFE440X_INTENSITY_CHAN(ALED2, 0),
149 AFE440X_INTENSITY_CHAN(LED2, "led2", 0), 112 AFE440X_INTENSITY_CHAN(LED1, 0),
150 AFE440X_INTENSITY_CHAN(ALED2, "led2_ambient", 0), 113 AFE440X_INTENSITY_CHAN(ALED1, 0),
151 AFE440X_INTENSITY_CHAN(LED1_ALED1, "led1-led1_ambient", 0), 114 AFE440X_INTENSITY_CHAN(LED2_ALED2, 0),
152 AFE440X_INTENSITY_CHAN(LED2_ALED2, "led2-led2_ambient", 0), 115 AFE440X_INTENSITY_CHAN(LED1_ALED1, 0),
153 /* LED current */ 116 /* LED current */
154 AFE440X_CURRENT_CHAN(ILED1, "led1"), 117 AFE440X_CURRENT_CHAN(LED2),
155 AFE440X_CURRENT_CHAN(ILED2, "led2"), 118 AFE440X_CURRENT_CHAN(LED1),
156}; 119};
157 120
158static const struct afe440x_val_table afe4403_res_table[] = { 121static const struct afe440x_val_table afe4403_res_table[] = {
159 { 500000 }, { 250000 }, { 100000 }, { 50000 }, 122 { 500000 }, { 250000 }, { 100000 }, { 50000 },
160 { 25000 }, { 10000 }, { 1000000 }, { 0 }, 123 { 25000 }, { 10000 }, { 1000000 }, { 0 },
161}; 124};
162AFE440X_TABLE_ATTR(tia_resistance_available, afe4403_res_table); 125AFE440X_TABLE_ATTR(in_intensity_resistance_available, afe4403_res_table);
163 126
164static const struct afe440x_val_table afe4403_cap_table[] = { 127static const struct afe440x_val_table afe4403_cap_table[] = {
165 { 0, 5000 }, { 0, 10000 }, { 0, 20000 }, { 0, 25000 }, 128 { 0, 5000 }, { 0, 10000 }, { 0, 20000 }, { 0, 25000 },
@@ -171,7 +134,7 @@ static const struct afe440x_val_table afe4403_cap_table[] = {
171 { 0, 205000 }, { 0, 210000 }, { 0, 220000 }, { 0, 225000 }, 134 { 0, 205000 }, { 0, 210000 }, { 0, 220000 }, { 0, 225000 },
172 { 0, 230000 }, { 0, 235000 }, { 0, 245000 }, { 0, 250000 }, 135 { 0, 230000 }, { 0, 235000 }, { 0, 245000 }, { 0, 250000 },
173}; 136};
174AFE440X_TABLE_ATTR(tia_capacitance_available, afe4403_cap_table); 137AFE440X_TABLE_ATTR(in_intensity_capacitance_available, afe4403_cap_table);
175 138
176static ssize_t afe440x_show_register(struct device *dev, 139static ssize_t afe440x_show_register(struct device *dev,
177 struct device_attribute *attr, 140 struct device_attribute *attr,
@@ -180,38 +143,21 @@ static ssize_t afe440x_show_register(struct device *dev,
180 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 143 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
181 struct afe4403_data *afe = iio_priv(indio_dev); 144 struct afe4403_data *afe = iio_priv(indio_dev);
182 struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr); 145 struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr);
183 unsigned int reg_val, type; 146 unsigned int reg_val;
184 int vals[2]; 147 int vals[2];
185 int ret, val_len; 148 int ret;
186 149
187 ret = regmap_read(afe->regmap, afe440x_attr->reg, &reg_val); 150 ret = regmap_field_read(afe->fields[afe440x_attr->field], &reg_val);
188 if (ret) 151 if (ret)
189 return ret; 152 return ret;
190 153
191 reg_val &= afe440x_attr->mask; 154 if (reg_val >= afe440x_attr->table_size)
192 reg_val >>= afe440x_attr->shift;
193
194 switch (afe440x_attr->type) {
195 case SIMPLE:
196 type = IIO_VAL_INT;
197 val_len = 1;
198 vals[0] = reg_val;
199 break;
200 case RESISTANCE:
201 case CAPACITANCE:
202 type = IIO_VAL_INT_PLUS_MICRO;
203 val_len = 2;
204 if (reg_val < afe440x_attr->table_size) {
205 vals[0] = afe440x_attr->val_table[reg_val].integer;
206 vals[1] = afe440x_attr->val_table[reg_val].fract;
207 break;
208 }
209 return -EINVAL;
210 default:
211 return -EINVAL; 155 return -EINVAL;
212 }
213 156
214 return iio_format_value(buf, type, val_len, vals); 157 vals[0] = afe440x_attr->val_table[reg_val].integer;
158 vals[1] = afe440x_attr->val_table[reg_val].fract;
159
160 return iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, vals);
215} 161}
216 162
217static ssize_t afe440x_store_register(struct device *dev, 163static ssize_t afe440x_store_register(struct device *dev,
@@ -227,48 +173,43 @@ static ssize_t afe440x_store_register(struct device *dev,
227 if (ret) 173 if (ret)
228 return ret; 174 return ret;
229 175
230 switch (afe440x_attr->type) { 176 for (val = 0; val < afe440x_attr->table_size; val++)
231 case SIMPLE: 177 if (afe440x_attr->val_table[val].integer == integer &&
232 val = integer; 178 afe440x_attr->val_table[val].fract == fract)
233 break; 179 break;
234 case RESISTANCE: 180 if (val == afe440x_attr->table_size)
235 case CAPACITANCE:
236 for (val = 0; val < afe440x_attr->table_size; val++)
237 if (afe440x_attr->val_table[val].integer == integer &&
238 afe440x_attr->val_table[val].fract == fract)
239 break;
240 if (val == afe440x_attr->table_size)
241 return -EINVAL;
242 break;
243 default:
244 return -EINVAL; 181 return -EINVAL;
245 }
246 182
247 ret = regmap_update_bits(afe->regmap, afe440x_attr->reg, 183 ret = regmap_field_write(afe->fields[afe440x_attr->field], val);
248 afe440x_attr->mask,
249 (val << afe440x_attr->shift));
250 if (ret) 184 if (ret)
251 return ret; 185 return ret;
252 186
253 return count; 187 return count;
254} 188}
255 189
256static AFE440X_ATTR(tia_separate_en, AFE4403_TIAGAIN, AFE440X_TIAGAIN_ENSEPGAIN, SIMPLE, NULL, 0); 190static AFE440X_ATTR(in_intensity1_resistance, F_RF_LED, afe4403_res_table);
191static AFE440X_ATTR(in_intensity1_capacitance, F_CF_LED, afe4403_cap_table);
192
193static AFE440X_ATTR(in_intensity2_resistance, F_RF_LED, afe4403_res_table);
194static AFE440X_ATTR(in_intensity2_capacitance, F_CF_LED, afe4403_cap_table);
257 195
258static AFE440X_ATTR(tia_resistance1, AFE4403_TIAGAIN, AFE4403_TIAGAIN_RES, RESISTANCE, afe4403_res_table, ARRAY_SIZE(afe4403_res_table)); 196static AFE440X_ATTR(in_intensity3_resistance, F_RF_LED1, afe4403_res_table);
259static AFE440X_ATTR(tia_capacitance1, AFE4403_TIAGAIN, AFE4403_TIAGAIN_CAP, CAPACITANCE, afe4403_cap_table, ARRAY_SIZE(afe4403_cap_table)); 197static AFE440X_ATTR(in_intensity3_capacitance, F_CF_LED1, afe4403_cap_table);
260 198
261static AFE440X_ATTR(tia_resistance2, AFE4403_TIA_AMB_GAIN, AFE4403_TIAGAIN_RES, RESISTANCE, afe4403_res_table, ARRAY_SIZE(afe4403_res_table)); 199static AFE440X_ATTR(in_intensity4_resistance, F_RF_LED1, afe4403_res_table);
262static AFE440X_ATTR(tia_capacitance2, AFE4403_TIA_AMB_GAIN, AFE4403_TIAGAIN_RES, CAPACITANCE, afe4403_cap_table, ARRAY_SIZE(afe4403_cap_table)); 200static AFE440X_ATTR(in_intensity4_capacitance, F_CF_LED1, afe4403_cap_table);
263 201
264static struct attribute *afe440x_attributes[] = { 202static struct attribute *afe440x_attributes[] = {
265 &afe440x_attr_tia_separate_en.dev_attr.attr, 203 &dev_attr_in_intensity_resistance_available.attr,
266 &afe440x_attr_tia_resistance1.dev_attr.attr, 204 &dev_attr_in_intensity_capacitance_available.attr,
267 &afe440x_attr_tia_capacitance1.dev_attr.attr, 205 &afe440x_attr_in_intensity1_resistance.dev_attr.attr,
268 &afe440x_attr_tia_resistance2.dev_attr.attr, 206 &afe440x_attr_in_intensity1_capacitance.dev_attr.attr,
269 &afe440x_attr_tia_capacitance2.dev_attr.attr, 207 &afe440x_attr_in_intensity2_resistance.dev_attr.attr,
270 &dev_attr_tia_resistance_available.attr, 208 &afe440x_attr_in_intensity2_capacitance.dev_attr.attr,
271 &dev_attr_tia_capacitance_available.attr, 209 &afe440x_attr_in_intensity3_resistance.dev_attr.attr,
210 &afe440x_attr_in_intensity3_capacitance.dev_attr.attr,
211 &afe440x_attr_in_intensity4_resistance.dev_attr.attr,
212 &afe440x_attr_in_intensity4_capacitance.dev_attr.attr,
272 NULL 213 NULL
273}; 214};
274 215
@@ -309,35 +250,26 @@ static int afe4403_read_raw(struct iio_dev *indio_dev,
309 int *val, int *val2, long mask) 250 int *val, int *val2, long mask)
310{ 251{
311 struct afe4403_data *afe = iio_priv(indio_dev); 252 struct afe4403_data *afe = iio_priv(indio_dev);
312 const struct afe440x_reg_info reg_info = afe4403_reg_info[chan->address]; 253 unsigned int reg = afe4403_channel_values[chan->address];
254 unsigned int field = afe4403_channel_leds[chan->address];
313 int ret; 255 int ret;
314 256
315 switch (chan->type) { 257 switch (chan->type) {
316 case IIO_INTENSITY: 258 case IIO_INTENSITY:
317 switch (mask) { 259 switch (mask) {
318 case IIO_CHAN_INFO_RAW: 260 case IIO_CHAN_INFO_RAW:
319 ret = afe4403_read(afe, reg_info.reg, val); 261 ret = afe4403_read(afe, reg, val);
320 if (ret)
321 return ret;
322 return IIO_VAL_INT;
323 case IIO_CHAN_INFO_OFFSET:
324 ret = regmap_read(afe->regmap, reg_info.offreg,
325 val);
326 if (ret) 262 if (ret)
327 return ret; 263 return ret;
328 *val &= reg_info.mask;
329 *val >>= reg_info.shift;
330 return IIO_VAL_INT; 264 return IIO_VAL_INT;
331 } 265 }
332 break; 266 break;
333 case IIO_CURRENT: 267 case IIO_CURRENT:
334 switch (mask) { 268 switch (mask) {
335 case IIO_CHAN_INFO_RAW: 269 case IIO_CHAN_INFO_RAW:
336 ret = regmap_read(afe->regmap, reg_info.reg, val); 270 ret = regmap_field_read(afe->fields[field], val);
337 if (ret) 271 if (ret)
338 return ret; 272 return ret;
339 *val &= reg_info.mask;
340 *val >>= reg_info.shift;
341 return IIO_VAL_INT; 273 return IIO_VAL_INT;
342 case IIO_CHAN_INFO_SCALE: 274 case IIO_CHAN_INFO_SCALE:
343 *val = 0; 275 *val = 0;
@@ -357,25 +289,13 @@ static int afe4403_write_raw(struct iio_dev *indio_dev,
357 int val, int val2, long mask) 289 int val, int val2, long mask)
358{ 290{
359 struct afe4403_data *afe = iio_priv(indio_dev); 291 struct afe4403_data *afe = iio_priv(indio_dev);
360 const struct afe440x_reg_info reg_info = afe4403_reg_info[chan->address]; 292 unsigned int field = afe4403_channel_leds[chan->address];
361 293
362 switch (chan->type) { 294 switch (chan->type) {
363 case IIO_INTENSITY:
364 switch (mask) {
365 case IIO_CHAN_INFO_OFFSET:
366 return regmap_update_bits(afe->regmap,
367 reg_info.offreg,
368 reg_info.mask,
369 (val << reg_info.shift));
370 }
371 break;
372 case IIO_CURRENT: 295 case IIO_CURRENT:
373 switch (mask) { 296 switch (mask) {
374 case IIO_CHAN_INFO_RAW: 297 case IIO_CHAN_INFO_RAW:
375 return regmap_update_bits(afe->regmap, 298 return regmap_field_write(afe->fields[field], val);
376 reg_info.reg,
377 reg_info.mask,
378 (val << reg_info.shift));
379 } 299 }
380 break; 300 break;
381 default: 301 default:
@@ -410,7 +330,7 @@ static irqreturn_t afe4403_trigger_handler(int irq, void *private)
410 for_each_set_bit(bit, indio_dev->active_scan_mask, 330 for_each_set_bit(bit, indio_dev->active_scan_mask,
411 indio_dev->masklength) { 331 indio_dev->masklength) {
412 ret = spi_write_then_read(afe->spi, 332 ret = spi_write_then_read(afe->spi,
413 &afe4403_reg_info[bit].reg, 1, 333 &afe4403_channel_values[bit], 1,
414 rx, 3); 334 rx, 3);
415 if (ret) 335 if (ret)
416 goto err; 336 goto err;
@@ -472,12 +392,8 @@ static const struct iio_trigger_ops afe4403_trigger_ops = {
472 392
473static const struct reg_sequence afe4403_reg_sequences[] = { 393static const struct reg_sequence afe4403_reg_sequences[] = {
474 AFE4403_TIMING_PAIRS, 394 AFE4403_TIMING_PAIRS,
475 { AFE440X_CONTROL1, AFE440X_CONTROL1_TIMEREN | 0x000007}, 395 { AFE440X_CONTROL1, AFE440X_CONTROL1_TIMEREN },
476 { AFE4403_TIA_AMB_GAIN, AFE4403_TIAGAIN_RES_1_M }, 396 { AFE4403_TIAGAIN, AFE440X_TIAGAIN_ENSEPGAIN },
477 { AFE440X_LEDCNTRL, (0x14 << AFE440X_LEDCNTRL_LED1_SHIFT) |
478 (0x14 << AFE440X_LEDCNTRL_LED2_SHIFT) },
479 { AFE440X_CONTROL2, AFE440X_CONTROL2_TX_REF_050 <<
480 AFE440X_CONTROL2_TX_REF_SHIFT },
481}; 397};
482 398
483static const struct regmap_range afe4403_yes_ranges[] = { 399static const struct regmap_range afe4403_yes_ranges[] = {
@@ -498,13 +414,11 @@ static const struct regmap_config afe4403_regmap_config = {
498 .volatile_table = &afe4403_volatile_table, 414 .volatile_table = &afe4403_volatile_table,
499}; 415};
500 416
501#ifdef CONFIG_OF
502static const struct of_device_id afe4403_of_match[] = { 417static const struct of_device_id afe4403_of_match[] = {
503 { .compatible = "ti,afe4403", }, 418 { .compatible = "ti,afe4403", },
504 { /* sentinel */ } 419 { /* sentinel */ }
505}; 420};
506MODULE_DEVICE_TABLE(of, afe4403_of_match); 421MODULE_DEVICE_TABLE(of, afe4403_of_match);
507#endif
508 422
509static int __maybe_unused afe4403_suspend(struct device *dev) 423static int __maybe_unused afe4403_suspend(struct device *dev)
510{ 424{
@@ -553,7 +467,7 @@ static int afe4403_probe(struct spi_device *spi)
553{ 467{
554 struct iio_dev *indio_dev; 468 struct iio_dev *indio_dev;
555 struct afe4403_data *afe; 469 struct afe4403_data *afe;
556 int ret; 470 int i, ret;
557 471
558 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*afe)); 472 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*afe));
559 if (!indio_dev) 473 if (!indio_dev)
@@ -572,6 +486,15 @@ static int afe4403_probe(struct spi_device *spi)
572 return PTR_ERR(afe->regmap); 486 return PTR_ERR(afe->regmap);
573 } 487 }
574 488
489 for (i = 0; i < F_MAX_FIELDS; i++) {
490 afe->fields[i] = devm_regmap_field_alloc(afe->dev, afe->regmap,
491 afe4403_reg_fields[i]);
492 if (IS_ERR(afe->fields[i])) {
493 dev_err(afe->dev, "Unable to allocate regmap fields\n");
494 return PTR_ERR(afe->fields[i]);
495 }
496 }
497
575 afe->regulator = devm_regulator_get(afe->dev, "tx_sup"); 498 afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
576 if (IS_ERR(afe->regulator)) { 499 if (IS_ERR(afe->regulator)) {
577 dev_err(afe->dev, "Unable to get regulator\n"); 500 dev_err(afe->dev, "Unable to get regulator\n");
@@ -694,7 +617,7 @@ MODULE_DEVICE_TABLE(spi, afe4403_ids);
694static struct spi_driver afe4403_spi_driver = { 617static struct spi_driver afe4403_spi_driver = {
695 .driver = { 618 .driver = {
696 .name = AFE4403_DRIVER_NAME, 619 .name = AFE4403_DRIVER_NAME,
697 .of_match_table = of_match_ptr(afe4403_of_match), 620 .of_match_table = afe4403_of_match,
698 .pm = &afe4403_pm_ops, 621 .pm = &afe4403_pm_ops,
699 }, 622 },
700 .probe = afe4403_probe, 623 .probe = afe4403_probe,
@@ -704,5 +627,5 @@ static struct spi_driver afe4403_spi_driver = {
704module_spi_driver(afe4403_spi_driver); 627module_spi_driver(afe4403_spi_driver);
705 628
706MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); 629MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
707MODULE_DESCRIPTION("TI AFE4403 Heart Rate and Pulse Oximeter"); 630MODULE_DESCRIPTION("TI AFE4403 Heart Rate Monitor and Pulse Oximeter AFE");
708MODULE_LICENSE("GPL v2"); 631MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
index 5096a4643784..45266404f7e3 100644
--- a/drivers/iio/health/afe4404.c
+++ b/drivers/iio/health/afe4404.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters 2 * AFE4404 Heart Rate Monitors and Low-Cost Pulse Oximeters
3 * 3 *
4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 4 * Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
5 * Andrew F. Davis <afd@ti.com> 5 * Andrew F. Davis <afd@ti.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -48,118 +48,102 @@
48#define AFE4404_AVG_LED2_ALED2VAL 0x3f 48#define AFE4404_AVG_LED2_ALED2VAL 0x3f
49#define AFE4404_AVG_LED1_ALED1VAL 0x40 49#define AFE4404_AVG_LED1_ALED1VAL 0x40
50 50
51/* AFE4404 GAIN register fields */ 51/* AFE4404 CONTROL2 register fields */
52#define AFE4404_TIA_GAIN_RES_MASK GENMASK(2, 0) 52#define AFE440X_CONTROL2_OSC_ENABLE BIT(9)
53#define AFE4404_TIA_GAIN_RES_SHIFT 0
54#define AFE4404_TIA_GAIN_CAP_MASK GENMASK(5, 3)
55#define AFE4404_TIA_GAIN_CAP_SHIFT 3
56 53
57/* AFE4404 LEDCNTRL register fields */ 54enum afe4404_fields {
58#define AFE4404_LEDCNTRL_ILED1_MASK GENMASK(5, 0) 55 /* Gains */
59#define AFE4404_LEDCNTRL_ILED1_SHIFT 0 56 F_TIA_GAIN_SEP, F_TIA_CF_SEP,
60#define AFE4404_LEDCNTRL_ILED2_MASK GENMASK(11, 6) 57 F_TIA_GAIN, TIA_CF,
61#define AFE4404_LEDCNTRL_ILED2_SHIFT 6
62#define AFE4404_LEDCNTRL_ILED3_MASK GENMASK(17, 12)
63#define AFE4404_LEDCNTRL_ILED3_SHIFT 12
64 58
65/* AFE4404 CONTROL2 register fields */ 59 /* LED Current */
66#define AFE440X_CONTROL2_ILED_2X_MASK BIT(17) 60 F_ILED1, F_ILED2, F_ILED3,
67#define AFE440X_CONTROL2_ILED_2X_SHIFT 17 61
68 62 /* Offset DAC */
69/* AFE4404 CONTROL3 register fields */ 63 F_OFFDAC_AMB2, F_OFFDAC_LED1, F_OFFDAC_AMB1, F_OFFDAC_LED2,
70#define AFE440X_CONTROL3_OSC_ENABLE BIT(9) 64
71 65 /* sentinel */
72/* AFE4404 OFFDAC register current fields */ 66 F_MAX_FIELDS
73#define AFE4404_OFFDAC_CURR_LED1_MASK GENMASK(9, 5) 67};
74#define AFE4404_OFFDAC_CURR_LED1_SHIFT 5 68
75#define AFE4404_OFFDAC_CURR_LED2_MASK GENMASK(19, 15) 69static const struct reg_field afe4404_reg_fields[] = {
76#define AFE4404_OFFDAC_CURR_LED2_SHIFT 15 70 /* Gains */
77#define AFE4404_OFFDAC_CURR_LED3_MASK GENMASK(4, 0) 71 [F_TIA_GAIN_SEP] = REG_FIELD(AFE4404_TIA_GAIN_SEP, 0, 2),
78#define AFE4404_OFFDAC_CURR_LED3_SHIFT 0 72 [F_TIA_CF_SEP] = REG_FIELD(AFE4404_TIA_GAIN_SEP, 3, 5),
79#define AFE4404_OFFDAC_CURR_ALED1_MASK GENMASK(14, 10) 73 [F_TIA_GAIN] = REG_FIELD(AFE4404_TIA_GAIN, 0, 2),
80#define AFE4404_OFFDAC_CURR_ALED1_SHIFT 10 74 [TIA_CF] = REG_FIELD(AFE4404_TIA_GAIN, 3, 5),
81#define AFE4404_OFFDAC_CURR_ALED2_MASK GENMASK(4, 0) 75 /* LED Current */
82#define AFE4404_OFFDAC_CURR_ALED2_SHIFT 0 76 [F_ILED1] = REG_FIELD(AFE440X_LEDCNTRL, 0, 5),
83 77 [F_ILED2] = REG_FIELD(AFE440X_LEDCNTRL, 6, 11),
84/* AFE4404 NULL fields */ 78 [F_ILED3] = REG_FIELD(AFE440X_LEDCNTRL, 12, 17),
85#define NULL_MASK 0 79 /* Offset DAC */
86#define NULL_SHIFT 0 80 [F_OFFDAC_AMB2] = REG_FIELD(AFE4404_OFFDAC, 0, 4),
87 81 [F_OFFDAC_LED1] = REG_FIELD(AFE4404_OFFDAC, 5, 9),
88/* AFE4404 TIA_GAIN_CAP values */ 82 [F_OFFDAC_AMB1] = REG_FIELD(AFE4404_OFFDAC, 10, 14),
89#define AFE4404_TIA_GAIN_CAP_5_P 0x0 83 [F_OFFDAC_LED2] = REG_FIELD(AFE4404_OFFDAC, 15, 19),
90#define AFE4404_TIA_GAIN_CAP_2_5_P 0x1 84};
91#define AFE4404_TIA_GAIN_CAP_10_P 0x2
92#define AFE4404_TIA_GAIN_CAP_7_5_P 0x3
93#define AFE4404_TIA_GAIN_CAP_20_P 0x4
94#define AFE4404_TIA_GAIN_CAP_17_5_P 0x5
95#define AFE4404_TIA_GAIN_CAP_25_P 0x6
96#define AFE4404_TIA_GAIN_CAP_22_5_P 0x7
97
98/* AFE4404 TIA_GAIN_RES values */
99#define AFE4404_TIA_GAIN_RES_500_K 0x0
100#define AFE4404_TIA_GAIN_RES_250_K 0x1
101#define AFE4404_TIA_GAIN_RES_100_K 0x2
102#define AFE4404_TIA_GAIN_RES_50_K 0x3
103#define AFE4404_TIA_GAIN_RES_25_K 0x4
104#define AFE4404_TIA_GAIN_RES_10_K 0x5
105#define AFE4404_TIA_GAIN_RES_1_M 0x6
106#define AFE4404_TIA_GAIN_RES_2_M 0x7
107 85
108/** 86/**
109 * struct afe4404_data 87 * struct afe4404_data - AFE4404 device instance data
110 * @dev - Device structure 88 * @dev: Device structure
111 * @regmap - Register map of the device 89 * @regmap: Register map of the device
112 * @regulator - Pointer to the regulator for the IC 90 * @fields: Register fields of the device
113 * @trig - IIO trigger for this device 91 * @regulator: Pointer to the regulator for the IC
114 * @irq - ADC_RDY line interrupt number 92 * @trig: IIO trigger for this device
93 * @irq: ADC_RDY line interrupt number
115 */ 94 */
116struct afe4404_data { 95struct afe4404_data {
117 struct device *dev; 96 struct device *dev;
118 struct regmap *regmap; 97 struct regmap *regmap;
98 struct regmap_field *fields[F_MAX_FIELDS];
119 struct regulator *regulator; 99 struct regulator *regulator;
120 struct iio_trigger *trig; 100 struct iio_trigger *trig;
121 int irq; 101 int irq;
122}; 102};
123 103
124enum afe4404_chan_id { 104enum afe4404_chan_id {
105 LED2 = 1,
106 ALED2,
125 LED1, 107 LED1,
126 ALED1, 108 ALED1,
127 LED2,
128 ALED2,
129 LED3,
130 LED1_ALED1,
131 LED2_ALED2, 109 LED2_ALED2,
132 ILED1, 110 LED1_ALED1,
133 ILED2, 111};
134 ILED3, 112
113static const unsigned int afe4404_channel_values[] = {
114 [LED2] = AFE440X_LED2VAL,
115 [ALED2] = AFE440X_ALED2VAL,
116 [LED1] = AFE440X_LED1VAL,
117 [ALED1] = AFE440X_ALED1VAL,
118 [LED2_ALED2] = AFE440X_LED2_ALED2VAL,
119 [LED1_ALED1] = AFE440X_LED1_ALED1VAL,
135}; 120};
136 121
137static const struct afe440x_reg_info afe4404_reg_info[] = { 122static const unsigned int afe4404_channel_leds[] = {
138 [LED1] = AFE440X_REG_INFO(AFE440X_LED1VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_LED1), 123 [LED2] = F_ILED2,
139 [ALED1] = AFE440X_REG_INFO(AFE440X_ALED1VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_ALED1), 124 [ALED2] = F_ILED3,
140 [LED2] = AFE440X_REG_INFO(AFE440X_LED2VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_LED2), 125 [LED1] = F_ILED1,
141 [ALED2] = AFE440X_REG_INFO(AFE440X_ALED2VAL, AFE4404_OFFDAC, AFE4404_OFFDAC_CURR_ALED2), 126};
142 [LED3] = AFE440X_REG_INFO(AFE440X_ALED2VAL, 0, NULL), 127
143 [LED1_ALED1] = AFE440X_REG_INFO(AFE440X_LED1_ALED1VAL, 0, NULL), 128static const unsigned int afe4404_channel_offdacs[] = {
144 [LED2_ALED2] = AFE440X_REG_INFO(AFE440X_LED2_ALED2VAL, 0, NULL), 129 [LED2] = F_OFFDAC_LED2,
145 [ILED1] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE4404_LEDCNTRL_ILED1), 130 [ALED2] = F_OFFDAC_AMB2,
146 [ILED2] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE4404_LEDCNTRL_ILED2), 131 [LED1] = F_OFFDAC_LED1,
147 [ILED3] = AFE440X_REG_INFO(AFE440X_LEDCNTRL, 0, AFE4404_LEDCNTRL_ILED3), 132 [ALED1] = F_OFFDAC_AMB1,
148}; 133};
149 134
150static const struct iio_chan_spec afe4404_channels[] = { 135static const struct iio_chan_spec afe4404_channels[] = {
151 /* ADC values */ 136 /* ADC values */
152 AFE440X_INTENSITY_CHAN(LED1, "led1", BIT(IIO_CHAN_INFO_OFFSET)), 137 AFE440X_INTENSITY_CHAN(LED2, BIT(IIO_CHAN_INFO_OFFSET)),
153 AFE440X_INTENSITY_CHAN(ALED1, "led1_ambient", BIT(IIO_CHAN_INFO_OFFSET)), 138 AFE440X_INTENSITY_CHAN(ALED2, BIT(IIO_CHAN_INFO_OFFSET)),
154 AFE440X_INTENSITY_CHAN(LED2, "led2", BIT(IIO_CHAN_INFO_OFFSET)), 139 AFE440X_INTENSITY_CHAN(LED1, BIT(IIO_CHAN_INFO_OFFSET)),
155 AFE440X_INTENSITY_CHAN(ALED2, "led2_ambient", BIT(IIO_CHAN_INFO_OFFSET)), 140 AFE440X_INTENSITY_CHAN(ALED1, BIT(IIO_CHAN_INFO_OFFSET)),
156 AFE440X_INTENSITY_CHAN(LED3, "led3", BIT(IIO_CHAN_INFO_OFFSET)), 141 AFE440X_INTENSITY_CHAN(LED2_ALED2, 0),
157 AFE440X_INTENSITY_CHAN(LED1_ALED1, "led1-led1_ambient", 0), 142 AFE440X_INTENSITY_CHAN(LED1_ALED1, 0),
158 AFE440X_INTENSITY_CHAN(LED2_ALED2, "led2-led2_ambient", 0),
159 /* LED current */ 143 /* LED current */
160 AFE440X_CURRENT_CHAN(ILED1, "led1"), 144 AFE440X_CURRENT_CHAN(LED2),
161 AFE440X_CURRENT_CHAN(ILED2, "led2"), 145 AFE440X_CURRENT_CHAN(ALED2),
162 AFE440X_CURRENT_CHAN(ILED3, "led3"), 146 AFE440X_CURRENT_CHAN(LED1),
163}; 147};
164 148
165static const struct afe440x_val_table afe4404_res_table[] = { 149static const struct afe440x_val_table afe4404_res_table[] = {
@@ -172,7 +156,7 @@ static const struct afe440x_val_table afe4404_res_table[] = {
172 { .integer = 1000000, .fract = 0 }, 156 { .integer = 1000000, .fract = 0 },
173 { .integer = 2000000, .fract = 0 }, 157 { .integer = 2000000, .fract = 0 },
174}; 158};
175AFE440X_TABLE_ATTR(tia_resistance_available, afe4404_res_table); 159AFE440X_TABLE_ATTR(in_intensity_resistance_available, afe4404_res_table);
176 160
177static const struct afe440x_val_table afe4404_cap_table[] = { 161static const struct afe440x_val_table afe4404_cap_table[] = {
178 { .integer = 0, .fract = 5000 }, 162 { .integer = 0, .fract = 5000 },
@@ -184,7 +168,7 @@ static const struct afe440x_val_table afe4404_cap_table[] = {
184 { .integer = 0, .fract = 25000 }, 168 { .integer = 0, .fract = 25000 },
185 { .integer = 0, .fract = 22500 }, 169 { .integer = 0, .fract = 22500 },
186}; 170};
187AFE440X_TABLE_ATTR(tia_capacitance_available, afe4404_cap_table); 171AFE440X_TABLE_ATTR(in_intensity_capacitance_available, afe4404_cap_table);
188 172
189static ssize_t afe440x_show_register(struct device *dev, 173static ssize_t afe440x_show_register(struct device *dev,
190 struct device_attribute *attr, 174 struct device_attribute *attr,
@@ -193,38 +177,21 @@ static ssize_t afe440x_show_register(struct device *dev,
193 struct iio_dev *indio_dev = dev_to_iio_dev(dev); 177 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
194 struct afe4404_data *afe = iio_priv(indio_dev); 178 struct afe4404_data *afe = iio_priv(indio_dev);
195 struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr); 179 struct afe440x_attr *afe440x_attr = to_afe440x_attr(attr);
196 unsigned int reg_val, type; 180 unsigned int reg_val;
197 int vals[2]; 181 int vals[2];
198 int ret, val_len; 182 int ret;
199 183
200 ret = regmap_read(afe->regmap, afe440x_attr->reg, &reg_val); 184 ret = regmap_field_read(afe->fields[afe440x_attr->field], &reg_val);
201 if (ret) 185 if (ret)
202 return ret; 186 return ret;
203 187
204 reg_val &= afe440x_attr->mask; 188 if (reg_val >= afe440x_attr->table_size)
205 reg_val >>= afe440x_attr->shift;
206
207 switch (afe440x_attr->type) {
208 case SIMPLE:
209 type = IIO_VAL_INT;
210 val_len = 1;
211 vals[0] = reg_val;
212 break;
213 case RESISTANCE:
214 case CAPACITANCE:
215 type = IIO_VAL_INT_PLUS_MICRO;
216 val_len = 2;
217 if (reg_val < afe440x_attr->table_size) {
218 vals[0] = afe440x_attr->val_table[reg_val].integer;
219 vals[1] = afe440x_attr->val_table[reg_val].fract;
220 break;
221 }
222 return -EINVAL;
223 default:
224 return -EINVAL; 189 return -EINVAL;
225 }
226 190
227 return iio_format_value(buf, type, val_len, vals); 191 vals[0] = afe440x_attr->val_table[reg_val].integer;
192 vals[1] = afe440x_attr->val_table[reg_val].fract;
193
194 return iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, vals);
228} 195}
229 196
230static ssize_t afe440x_store_register(struct device *dev, 197static ssize_t afe440x_store_register(struct device *dev,
@@ -240,48 +207,43 @@ static ssize_t afe440x_store_register(struct device *dev,
240 if (ret) 207 if (ret)
241 return ret; 208 return ret;
242 209
243 switch (afe440x_attr->type) { 210 for (val = 0; val < afe440x_attr->table_size; val++)
244 case SIMPLE: 211 if (afe440x_attr->val_table[val].integer == integer &&
245 val = integer; 212 afe440x_attr->val_table[val].fract == fract)
246 break; 213 break;
247 case RESISTANCE: 214 if (val == afe440x_attr->table_size)
248 case CAPACITANCE:
249 for (val = 0; val < afe440x_attr->table_size; val++)
250 if (afe440x_attr->val_table[val].integer == integer &&
251 afe440x_attr->val_table[val].fract == fract)
252 break;
253 if (val == afe440x_attr->table_size)
254 return -EINVAL;
255 break;
256 default:
257 return -EINVAL; 215 return -EINVAL;
258 }
259 216
260 ret = regmap_update_bits(afe->regmap, afe440x_attr->reg, 217 ret = regmap_field_write(afe->fields[afe440x_attr->field], val);
261 afe440x_attr->mask,
262 (val << afe440x_attr->shift));
263 if (ret) 218 if (ret)
264 return ret; 219 return ret;
265 220
266 return count; 221 return count;
267} 222}
268 223
269static AFE440X_ATTR(tia_separate_en, AFE4404_TIA_GAIN_SEP, AFE440X_TIAGAIN_ENSEPGAIN, SIMPLE, NULL, 0); 224static AFE440X_ATTR(in_intensity1_resistance, F_TIA_GAIN_SEP, afe4404_res_table);
225static AFE440X_ATTR(in_intensity1_capacitance, F_TIA_CF_SEP, afe4404_cap_table);
226
227static AFE440X_ATTR(in_intensity2_resistance, F_TIA_GAIN_SEP, afe4404_res_table);
228static AFE440X_ATTR(in_intensity2_capacitance, F_TIA_CF_SEP, afe4404_cap_table);
270 229
271static AFE440X_ATTR(tia_resistance1, AFE4404_TIA_GAIN, AFE4404_TIA_GAIN_RES, RESISTANCE, afe4404_res_table, ARRAY_SIZE(afe4404_res_table)); 230static AFE440X_ATTR(in_intensity3_resistance, F_TIA_GAIN, afe4404_res_table);
272static AFE440X_ATTR(tia_capacitance1, AFE4404_TIA_GAIN, AFE4404_TIA_GAIN_CAP, CAPACITANCE, afe4404_cap_table, ARRAY_SIZE(afe4404_cap_table)); 231static AFE440X_ATTR(in_intensity3_capacitance, TIA_CF, afe4404_cap_table);
273 232
274static AFE440X_ATTR(tia_resistance2, AFE4404_TIA_GAIN_SEP, AFE4404_TIA_GAIN_RES, RESISTANCE, afe4404_res_table, ARRAY_SIZE(afe4404_res_table)); 233static AFE440X_ATTR(in_intensity4_resistance, F_TIA_GAIN, afe4404_res_table);
275static AFE440X_ATTR(tia_capacitance2, AFE4404_TIA_GAIN_SEP, AFE4404_TIA_GAIN_CAP, CAPACITANCE, afe4404_cap_table, ARRAY_SIZE(afe4404_cap_table)); 234static AFE440X_ATTR(in_intensity4_capacitance, TIA_CF, afe4404_cap_table);
276 235
277static struct attribute *afe440x_attributes[] = { 236static struct attribute *afe440x_attributes[] = {
278 &afe440x_attr_tia_separate_en.dev_attr.attr, 237 &dev_attr_in_intensity_resistance_available.attr,
279 &afe440x_attr_tia_resistance1.dev_attr.attr, 238 &dev_attr_in_intensity_capacitance_available.attr,
280 &afe440x_attr_tia_capacitance1.dev_attr.attr, 239 &afe440x_attr_in_intensity1_resistance.dev_attr.attr,
281 &afe440x_attr_tia_resistance2.dev_attr.attr, 240 &afe440x_attr_in_intensity1_capacitance.dev_attr.attr,
282 &afe440x_attr_tia_capacitance2.dev_attr.attr, 241 &afe440x_attr_in_intensity2_resistance.dev_attr.attr,
283 &dev_attr_tia_resistance_available.attr, 242 &afe440x_attr_in_intensity2_capacitance.dev_attr.attr,
284 &dev_attr_tia_capacitance_available.attr, 243 &afe440x_attr_in_intensity3_resistance.dev_attr.attr,
244 &afe440x_attr_in_intensity3_capacitance.dev_attr.attr,
245 &afe440x_attr_in_intensity4_resistance.dev_attr.attr,
246 &afe440x_attr_in_intensity4_capacitance.dev_attr.attr,
285 NULL 247 NULL
286}; 248};
287 249
@@ -294,35 +256,32 @@ static int afe4404_read_raw(struct iio_dev *indio_dev,
294 int *val, int *val2, long mask) 256 int *val, int *val2, long mask)
295{ 257{
296 struct afe4404_data *afe = iio_priv(indio_dev); 258 struct afe4404_data *afe = iio_priv(indio_dev);
297 const struct afe440x_reg_info reg_info = afe4404_reg_info[chan->address]; 259 unsigned int value_reg = afe4404_channel_values[chan->address];
260 unsigned int led_field = afe4404_channel_leds[chan->address];
261 unsigned int offdac_field = afe4404_channel_offdacs[chan->address];
298 int ret; 262 int ret;
299 263
300 switch (chan->type) { 264 switch (chan->type) {
301 case IIO_INTENSITY: 265 case IIO_INTENSITY:
302 switch (mask) { 266 switch (mask) {
303 case IIO_CHAN_INFO_RAW: 267 case IIO_CHAN_INFO_RAW:
304 ret = regmap_read(afe->regmap, reg_info.reg, val); 268 ret = regmap_read(afe->regmap, value_reg, val);
305 if (ret) 269 if (ret)
306 return ret; 270 return ret;
307 return IIO_VAL_INT; 271 return IIO_VAL_INT;
308 case IIO_CHAN_INFO_OFFSET: 272 case IIO_CHAN_INFO_OFFSET:
309 ret = regmap_read(afe->regmap, reg_info.offreg, 273 ret = regmap_field_read(afe->fields[offdac_field], val);
310 val);
311 if (ret) 274 if (ret)
312 return ret; 275 return ret;
313 *val &= reg_info.mask;
314 *val >>= reg_info.shift;
315 return IIO_VAL_INT; 276 return IIO_VAL_INT;
316 } 277 }
317 break; 278 break;
318 case IIO_CURRENT: 279 case IIO_CURRENT:
319 switch (mask) { 280 switch (mask) {
320 case IIO_CHAN_INFO_RAW: 281 case IIO_CHAN_INFO_RAW:
321 ret = regmap_read(afe->regmap, reg_info.reg, val); 282 ret = regmap_field_read(afe->fields[led_field], val);
322 if (ret) 283 if (ret)
323 return ret; 284 return ret;
324 *val &= reg_info.mask;
325 *val >>= reg_info.shift;
326 return IIO_VAL_INT; 285 return IIO_VAL_INT;
327 case IIO_CHAN_INFO_SCALE: 286 case IIO_CHAN_INFO_SCALE:
328 *val = 0; 287 *val = 0;
@@ -342,25 +301,20 @@ static int afe4404_write_raw(struct iio_dev *indio_dev,
342 int val, int val2, long mask) 301 int val, int val2, long mask)
343{ 302{
344 struct afe4404_data *afe = iio_priv(indio_dev); 303 struct afe4404_data *afe = iio_priv(indio_dev);
345 const struct afe440x_reg_info reg_info = afe4404_reg_info[chan->address]; 304 unsigned int led_field = afe4404_channel_leds[chan->address];
305 unsigned int offdac_field = afe4404_channel_offdacs[chan->address];
346 306
347 switch (chan->type) { 307 switch (chan->type) {
348 case IIO_INTENSITY: 308 case IIO_INTENSITY:
349 switch (mask) { 309 switch (mask) {
350 case IIO_CHAN_INFO_OFFSET: 310 case IIO_CHAN_INFO_OFFSET:
351 return regmap_update_bits(afe->regmap, 311 return regmap_field_write(afe->fields[offdac_field], val);
352 reg_info.offreg,
353 reg_info.mask,
354 (val << reg_info.shift));
355 } 312 }
356 break; 313 break;
357 case IIO_CURRENT: 314 case IIO_CURRENT:
358 switch (mask) { 315 switch (mask) {
359 case IIO_CHAN_INFO_RAW: 316 case IIO_CHAN_INFO_RAW:
360 return regmap_update_bits(afe->regmap, 317 return regmap_field_write(afe->fields[led_field], val);
361 reg_info.reg,
362 reg_info.mask,
363 (val << reg_info.shift));
364 } 318 }
365 break; 319 break;
366 default: 320 default:
@@ -387,7 +341,7 @@ static irqreturn_t afe4404_trigger_handler(int irq, void *private)
387 341
388 for_each_set_bit(bit, indio_dev->active_scan_mask, 342 for_each_set_bit(bit, indio_dev->active_scan_mask,
389 indio_dev->masklength) { 343 indio_dev->masklength) {
390 ret = regmap_read(afe->regmap, afe4404_reg_info[bit].reg, 344 ret = regmap_read(afe->regmap, afe4404_channel_values[bit],
391 &buffer[i++]); 345 &buffer[i++]);
392 if (ret) 346 if (ret)
393 goto err; 347 goto err;
@@ -443,11 +397,8 @@ static const struct iio_trigger_ops afe4404_trigger_ops = {
443static const struct reg_sequence afe4404_reg_sequences[] = { 397static const struct reg_sequence afe4404_reg_sequences[] = {
444 AFE4404_TIMING_PAIRS, 398 AFE4404_TIMING_PAIRS,
445 { AFE440X_CONTROL1, AFE440X_CONTROL1_TIMEREN }, 399 { AFE440X_CONTROL1, AFE440X_CONTROL1_TIMEREN },
446 { AFE4404_TIA_GAIN, AFE4404_TIA_GAIN_RES_50_K }, 400 { AFE4404_TIA_GAIN_SEP, AFE440X_TIAGAIN_ENSEPGAIN },
447 { AFE440X_LEDCNTRL, (0xf << AFE4404_LEDCNTRL_ILED1_SHIFT) | 401 { AFE440X_CONTROL2, AFE440X_CONTROL2_OSC_ENABLE },
448 (0x3 << AFE4404_LEDCNTRL_ILED2_SHIFT) |
449 (0x3 << AFE4404_LEDCNTRL_ILED3_SHIFT) },
450 { AFE440X_CONTROL2, AFE440X_CONTROL3_OSC_ENABLE },
451}; 402};
452 403
453static const struct regmap_range afe4404_yes_ranges[] = { 404static const struct regmap_range afe4404_yes_ranges[] = {
@@ -469,13 +420,11 @@ static const struct regmap_config afe4404_regmap_config = {
469 .volatile_table = &afe4404_volatile_table, 420 .volatile_table = &afe4404_volatile_table,
470}; 421};
471 422
472#ifdef CONFIG_OF
473static const struct of_device_id afe4404_of_match[] = { 423static const struct of_device_id afe4404_of_match[] = {
474 { .compatible = "ti,afe4404", }, 424 { .compatible = "ti,afe4404", },
475 { /* sentinel */ } 425 { /* sentinel */ }
476}; 426};
477MODULE_DEVICE_TABLE(of, afe4404_of_match); 427MODULE_DEVICE_TABLE(of, afe4404_of_match);
478#endif
479 428
480static int __maybe_unused afe4404_suspend(struct device *dev) 429static int __maybe_unused afe4404_suspend(struct device *dev)
481{ 430{
@@ -525,7 +474,7 @@ static int afe4404_probe(struct i2c_client *client,
525{ 474{
526 struct iio_dev *indio_dev; 475 struct iio_dev *indio_dev;
527 struct afe4404_data *afe; 476 struct afe4404_data *afe;
528 int ret; 477 int i, ret;
529 478
530 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*afe)); 479 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*afe));
531 if (!indio_dev) 480 if (!indio_dev)
@@ -543,6 +492,15 @@ static int afe4404_probe(struct i2c_client *client,
543 return PTR_ERR(afe->regmap); 492 return PTR_ERR(afe->regmap);
544 } 493 }
545 494
495 for (i = 0; i < F_MAX_FIELDS; i++) {
496 afe->fields[i] = devm_regmap_field_alloc(afe->dev, afe->regmap,
497 afe4404_reg_fields[i]);
498 if (IS_ERR(afe->fields[i])) {
499 dev_err(afe->dev, "Unable to allocate regmap fields\n");
500 return PTR_ERR(afe->fields[i]);
501 }
502 }
503
546 afe->regulator = devm_regulator_get(afe->dev, "tx_sup"); 504 afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
547 if (IS_ERR(afe->regulator)) { 505 if (IS_ERR(afe->regulator)) {
548 dev_err(afe->dev, "Unable to get regulator\n"); 506 dev_err(afe->dev, "Unable to get regulator\n");
@@ -665,7 +623,7 @@ MODULE_DEVICE_TABLE(i2c, afe4404_ids);
665static struct i2c_driver afe4404_i2c_driver = { 623static struct i2c_driver afe4404_i2c_driver = {
666 .driver = { 624 .driver = {
667 .name = AFE4404_DRIVER_NAME, 625 .name = AFE4404_DRIVER_NAME,
668 .of_match_table = of_match_ptr(afe4404_of_match), 626 .of_match_table = afe4404_of_match,
669 .pm = &afe4404_pm_ops, 627 .pm = &afe4404_pm_ops,
670 }, 628 },
671 .probe = afe4404_probe, 629 .probe = afe4404_probe,
@@ -675,5 +633,5 @@ static struct i2c_driver afe4404_i2c_driver = {
675module_i2c_driver(afe4404_i2c_driver); 633module_i2c_driver(afe4404_i2c_driver);
676 634
677MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>"); 635MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
678MODULE_DESCRIPTION("TI AFE4404 Heart Rate and Pulse Oximeter"); 636MODULE_DESCRIPTION("TI AFE4404 Heart Rate Monitor and Pulse Oximeter AFE");
679MODULE_LICENSE("GPL v2"); 637MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/health/afe440x.h b/drivers/iio/health/afe440x.h
index c671ab78a23a..1a0f247043ca 100644
--- a/drivers/iio/health/afe440x.h
+++ b/drivers/iio/health/afe440x.h
@@ -71,8 +71,7 @@
71#define AFE440X_CONTROL1_TIMEREN BIT(8) 71#define AFE440X_CONTROL1_TIMEREN BIT(8)
72 72
73/* TIAGAIN register fields */ 73/* TIAGAIN register fields */
74#define AFE440X_TIAGAIN_ENSEPGAIN_MASK BIT(15) 74#define AFE440X_TIAGAIN_ENSEPGAIN BIT(15)
75#define AFE440X_TIAGAIN_ENSEPGAIN_SHIFT 15
76 75
77/* CONTROL2 register fields */ 76/* CONTROL2 register fields */
78#define AFE440X_CONTROL2_PDN_AFE BIT(0) 77#define AFE440X_CONTROL2_PDN_AFE BIT(0)
@@ -89,22 +88,7 @@
89#define AFE440X_CONTROL0_WRITE 0x0 88#define AFE440X_CONTROL0_WRITE 0x0
90#define AFE440X_CONTROL0_READ 0x1 89#define AFE440X_CONTROL0_READ 0x1
91 90
92struct afe440x_reg_info { 91#define AFE440X_INTENSITY_CHAN(_index, _mask) \
93 unsigned int reg;
94 unsigned int offreg;
95 unsigned int shift;
96 unsigned int mask;
97};
98
99#define AFE440X_REG_INFO(_reg, _offreg, _sm) \
100 { \
101 .reg = _reg, \
102 .offreg = _offreg, \
103 .shift = _sm ## _SHIFT, \
104 .mask = _sm ## _MASK, \
105 }
106
107#define AFE440X_INTENSITY_CHAN(_index, _name, _mask) \
108 { \ 92 { \
109 .type = IIO_INTENSITY, \ 93 .type = IIO_INTENSITY, \
110 .channel = _index, \ 94 .channel = _index, \
@@ -116,29 +100,23 @@ struct afe440x_reg_info {
116 .storagebits = 32, \ 100 .storagebits = 32, \
117 .endianness = IIO_CPU, \ 101 .endianness = IIO_CPU, \
118 }, \ 102 }, \
119 .extend_name = _name, \
120 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 103 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
121 _mask, \ 104 _mask, \
105 .indexed = true, \
122 } 106 }
123 107
124#define AFE440X_CURRENT_CHAN(_index, _name) \ 108#define AFE440X_CURRENT_CHAN(_index) \
125 { \ 109 { \
126 .type = IIO_CURRENT, \ 110 .type = IIO_CURRENT, \
127 .channel = _index, \ 111 .channel = _index, \
128 .address = _index, \ 112 .address = _index, \
129 .scan_index = _index, \ 113 .scan_index = -1, \
130 .extend_name = _name, \
131 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ 114 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
132 BIT(IIO_CHAN_INFO_SCALE), \ 115 BIT(IIO_CHAN_INFO_SCALE), \
116 .indexed = true, \
133 .output = true, \ 117 .output = true, \
134 } 118 }
135 119
136enum afe440x_reg_type {
137 SIMPLE,
138 RESISTANCE,
139 CAPACITANCE,
140};
141
142struct afe440x_val_table { 120struct afe440x_val_table {
143 int integer; 121 int integer;
144 int fract; 122 int fract;
@@ -164,10 +142,7 @@ static DEVICE_ATTR_RO(_name)
164 142
165struct afe440x_attr { 143struct afe440x_attr {
166 struct device_attribute dev_attr; 144 struct device_attribute dev_attr;
167 unsigned int reg; 145 unsigned int field;
168 unsigned int shift;
169 unsigned int mask;
170 enum afe440x_reg_type type;
171 const struct afe440x_val_table *val_table; 146 const struct afe440x_val_table *val_table;
172 unsigned int table_size; 147 unsigned int table_size;
173}; 148};
@@ -175,17 +150,14 @@ struct afe440x_attr {
175#define to_afe440x_attr(_dev_attr) \ 150#define to_afe440x_attr(_dev_attr) \
176 container_of(_dev_attr, struct afe440x_attr, dev_attr) 151 container_of(_dev_attr, struct afe440x_attr, dev_attr)
177 152
178#define AFE440X_ATTR(_name, _reg, _field, _type, _table, _size) \ 153#define AFE440X_ATTR(_name, _field, _table) \
179 struct afe440x_attr afe440x_attr_##_name = { \ 154 struct afe440x_attr afe440x_attr_##_name = { \
180 .dev_attr = __ATTR(_name, (S_IRUGO | S_IWUSR), \ 155 .dev_attr = __ATTR(_name, (S_IRUGO | S_IWUSR), \
181 afe440x_show_register, \ 156 afe440x_show_register, \
182 afe440x_store_register), \ 157 afe440x_store_register), \
183 .reg = _reg, \ 158 .field = _field, \
184 .shift = _field ## _SHIFT, \
185 .mask = _field ## _MASK, \
186 .type = _type, \
187 .val_table = _table, \ 159 .val_table = _table, \
188 .table_size = _size, \ 160 .table_size = ARRAY_SIZE(_table), \
189 } 161 }
190 162
191#endif /* _AFE440X_H */ 163#endif /* _AFE440X_H */
diff --git a/drivers/iio/humidity/am2315.c b/drivers/iio/humidity/am2315.c
index 11535911a5c6..3e200f69e886 100644
--- a/drivers/iio/humidity/am2315.c
+++ b/drivers/iio/humidity/am2315.c
@@ -276,6 +276,7 @@ static const struct i2c_device_id am2315_i2c_id[] = {
276 {"am2315", 0}, 276 {"am2315", 0},
277 {} 277 {}
278}; 278};
279MODULE_DEVICE_TABLE(i2c, am2315_i2c_id);
279 280
280static const struct acpi_device_id am2315_acpi_id[] = { 281static const struct acpi_device_id am2315_acpi_id[] = {
281 {"AOS2315", 0}, 282 {"AOS2315", 0},
diff --git a/drivers/iio/humidity/htu21.c b/drivers/iio/humidity/htu21.c
index 11cbc38b450f..0fbbd8c40894 100644
--- a/drivers/iio/humidity/htu21.c
+++ b/drivers/iio/humidity/htu21.c
@@ -236,6 +236,7 @@ static const struct i2c_device_id htu21_id[] = {
236 {"ms8607-humidity", MS8607}, 236 {"ms8607-humidity", MS8607},
237 {} 237 {}
238}; 238};
239MODULE_DEVICE_TABLE(i2c, htu21_id);
239 240
240static struct i2c_driver htu21_driver = { 241static struct i2c_driver htu21_driver = {
241 .probe = htu21_probe, 242 .probe = htu21_probe,
diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index b8a290ec984e..97928d558a15 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -20,6 +20,7 @@
20#include <linux/iio/triggered_buffer.h> 20#include <linux/iio/triggered_buffer.h>
21#include <linux/iio/trigger_consumer.h> 21#include <linux/iio/trigger_consumer.h>
22#include <linux/iio/buffer.h> 22#include <linux/iio/buffer.h>
23#include <linux/iio/sysfs.h>
23 24
24#include "bmi160.h" 25#include "bmi160.h"
25 26
@@ -466,10 +467,36 @@ static int bmi160_write_raw(struct iio_dev *indio_dev,
466 return 0; 467 return 0;
467} 468}
468 469
470static
471IIO_CONST_ATTR(in_accel_sampling_frequency_available,
472 "0.78125 1.5625 3.125 6.25 12.5 25 50 100 200 400 800 1600");
473static
474IIO_CONST_ATTR(in_anglvel_sampling_frequency_available,
475 "25 50 100 200 400 800 1600 3200");
476static
477IIO_CONST_ATTR(in_accel_scale_available,
478 "0.000598 0.001197 0.002394 0.004788");
479static
480IIO_CONST_ATTR(in_anglvel_scale_available,
481 "0.001065 0.000532 0.000266 0.000133 0.000066");
482
483static struct attribute *bmi160_attrs[] = {
484 &iio_const_attr_in_accel_sampling_frequency_available.dev_attr.attr,
485 &iio_const_attr_in_anglvel_sampling_frequency_available.dev_attr.attr,
486 &iio_const_attr_in_accel_scale_available.dev_attr.attr,
487 &iio_const_attr_in_anglvel_scale_available.dev_attr.attr,
488 NULL,
489};
490
491static const struct attribute_group bmi160_attrs_group = {
492 .attrs = bmi160_attrs,
493};
494
469static const struct iio_info bmi160_info = { 495static const struct iio_info bmi160_info = {
470 .driver_module = THIS_MODULE, 496 .driver_module = THIS_MODULE,
471 .read_raw = bmi160_read_raw, 497 .read_raw = bmi160_read_raw,
472 .write_raw = bmi160_write_raw, 498 .write_raw = bmi160_write_raw,
499 .attrs = &bmi160_attrs_group,
473}; 500};
474 501
475static const char *bmi160_match_acpi_device(struct device *dev) 502static const char *bmi160_match_acpi_device(struct device *dev)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index e6319a9346b2..2a85bd888619 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -80,6 +80,7 @@ static const char * const iio_chan_type_name_spec[] = {
80 [IIO_RESISTANCE] = "resistance", 80 [IIO_RESISTANCE] = "resistance",
81 [IIO_PH] = "ph", 81 [IIO_PH] = "ph",
82 [IIO_UVINDEX] = "uvindex", 82 [IIO_UVINDEX] = "uvindex",
83 [IIO_ELECTRICALCONDUCTIVITY] = "electricalconductivity",
83}; 84};
84 85
85static const char * const iio_modifier_names[] = { 86static const char * const iio_modifier_names[] = {
diff --git a/drivers/iio/industrialio-sw-device.c b/drivers/iio/industrialio-sw-device.c
new file mode 100644
index 000000000000..81b49cfca452
--- /dev/null
+++ b/drivers/iio/industrialio-sw-device.c
@@ -0,0 +1,182 @@
1/*
2 * The Industrial I/O core, software IIO devices functions
3 *
4 * Copyright (c) 2016 Intel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#include <linux/module.h>
12#include <linux/init.h>
13#include <linux/kmod.h>
14#include <linux/list.h>
15#include <linux/slab.h>
16
17#include <linux/iio/sw_device.h>
18#include <linux/iio/configfs.h>
19#include <linux/configfs.h>
20
21static struct config_group *iio_devices_group;
22static struct config_item_type iio_device_type_group_type;
23
24static struct config_item_type iio_devices_group_type = {
25 .ct_owner = THIS_MODULE,
26};
27
28static LIST_HEAD(iio_device_types_list);
29static DEFINE_MUTEX(iio_device_types_lock);
30
31static
32struct iio_sw_device_type *__iio_find_sw_device_type(const char *name,
33 unsigned len)
34{
35 struct iio_sw_device_type *d = NULL, *iter;
36
37 list_for_each_entry(iter, &iio_device_types_list, list)
38 if (!strcmp(iter->name, name)) {
39 d = iter;
40 break;
41 }
42
43 return d;
44}
45
46int iio_register_sw_device_type(struct iio_sw_device_type *d)
47{
48 struct iio_sw_device_type *iter;
49 int ret = 0;
50
51 mutex_lock(&iio_device_types_lock);
52 iter = __iio_find_sw_device_type(d->name, strlen(d->name));
53 if (iter)
54 ret = -EBUSY;
55 else
56 list_add_tail(&d->list, &iio_device_types_list);
57 mutex_unlock(&iio_device_types_lock);
58
59 if (ret)
60 return ret;
61
62 d->group = configfs_register_default_group(iio_devices_group, d->name,
63 &iio_device_type_group_type);
64 if (IS_ERR(d->group))
65 ret = PTR_ERR(d->group);
66
67 return ret;
68}
69EXPORT_SYMBOL(iio_register_sw_device_type);
70
71void iio_unregister_sw_device_type(struct iio_sw_device_type *dt)
72{
73 struct iio_sw_device_type *iter;
74
75 mutex_lock(&iio_device_types_lock);
76 iter = __iio_find_sw_device_type(dt->name, strlen(dt->name));
77 if (iter)
78 list_del(&dt->list);
79 mutex_unlock(&iio_device_types_lock);
80
81 configfs_unregister_default_group(dt->group);
82}
83EXPORT_SYMBOL(iio_unregister_sw_device_type);
84
85static
86struct iio_sw_device_type *iio_get_sw_device_type(const char *name)
87{
88 struct iio_sw_device_type *dt;
89
90 mutex_lock(&iio_device_types_lock);
91 dt = __iio_find_sw_device_type(name, strlen(name));
92 if (dt && !try_module_get(dt->owner))
93 dt = NULL;
94 mutex_unlock(&iio_device_types_lock);
95
96 return dt;
97}
98
99struct iio_sw_device *iio_sw_device_create(const char *type, const char *name)
100{
101 struct iio_sw_device *d;
102 struct iio_sw_device_type *dt;
103
104 dt = iio_get_sw_device_type(type);
105 if (!dt) {
106 pr_err("Invalid device type: %s\n", type);
107 return ERR_PTR(-EINVAL);
108 }
109 d = dt->ops->probe(name);
110 if (IS_ERR(d))
111 goto out_module_put;
112
113 d->device_type = dt;
114
115 return d;
116out_module_put:
117 module_put(dt->owner);
118 return d;
119}
120EXPORT_SYMBOL(iio_sw_device_create);
121
122void iio_sw_device_destroy(struct iio_sw_device *d)
123{
124 struct iio_sw_device_type *dt = d->device_type;
125
126 dt->ops->remove(d);
127 module_put(dt->owner);
128}
129EXPORT_SYMBOL(iio_sw_device_destroy);
130
131static struct config_group *device_make_group(struct config_group *group,
132 const char *name)
133{
134 struct iio_sw_device *d;
135
136 d = iio_sw_device_create(group->cg_item.ci_name, name);
137 if (IS_ERR(d))
138 return ERR_CAST(d);
139
140 config_item_set_name(&d->group.cg_item, "%s", name);
141
142 return &d->group;
143}
144
145static void device_drop_group(struct config_group *group,
146 struct config_item *item)
147{
148 struct iio_sw_device *d = to_iio_sw_device(item);
149
150 iio_sw_device_destroy(d);
151 config_item_put(item);
152}
153
154static struct configfs_group_operations device_ops = {
155 .make_group = &device_make_group,
156 .drop_item = &device_drop_group,
157};
158
159static struct config_item_type iio_device_type_group_type = {
160 .ct_group_ops = &device_ops,
161 .ct_owner = THIS_MODULE,
162};
163
164static int __init iio_sw_device_init(void)
165{
166 iio_devices_group =
167 configfs_register_default_group(&iio_configfs_subsys.su_group,
168 "devices",
169 &iio_devices_group_type);
170 return PTR_ERR_OR_ZERO(iio_devices_group);
171}
172module_init(iio_sw_device_init);
173
174static void __exit iio_sw_device_exit(void)
175{
176 configfs_unregister_default_group(iio_devices_group);
177}
178module_exit(iio_sw_device_exit);
179
180MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com>");
181MODULE_DESCRIPTION("Industrial I/O software devices support");
182MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 0c52dfe64977..7c15c3092d5d 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -68,6 +68,10 @@ int iio_trigger_register(struct iio_trigger *trig_info)
68{ 68{
69 int ret; 69 int ret;
70 70
71 /* trig_info->ops is required for the module member */
72 if (!trig_info->ops)
73 return -EINVAL;
74
71 trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL); 75 trig_info->id = ida_simple_get(&iio_trigger_ida, 0, 0, GFP_KERNEL);
72 if (trig_info->id < 0) 76 if (trig_info->id < 0)
73 return trig_info->id; 77 return trig_info->id;
@@ -164,8 +168,7 @@ EXPORT_SYMBOL(iio_trigger_poll_chained);
164 168
165void iio_trigger_notify_done(struct iio_trigger *trig) 169void iio_trigger_notify_done(struct iio_trigger *trig)
166{ 170{
167 if (atomic_dec_and_test(&trig->use_count) && trig->ops && 171 if (atomic_dec_and_test(&trig->use_count) && trig->ops->try_reenable)
168 trig->ops->try_reenable)
169 if (trig->ops->try_reenable(trig)) 172 if (trig->ops->try_reenable(trig))
170 /* Missed an interrupt so launch new poll now */ 173 /* Missed an interrupt so launch new poll now */
171 iio_trigger_poll(trig); 174 iio_trigger_poll(trig);
@@ -224,7 +227,7 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
224 goto out_put_irq; 227 goto out_put_irq;
225 228
226 /* Enable trigger in driver */ 229 /* Enable trigger in driver */
227 if (trig->ops && trig->ops->set_trigger_state && notinuse) { 230 if (trig->ops->set_trigger_state && notinuse) {
228 ret = trig->ops->set_trigger_state(trig, true); 231 ret = trig->ops->set_trigger_state(trig, true);
229 if (ret < 0) 232 if (ret < 0)
230 goto out_free_irq; 233 goto out_free_irq;
@@ -249,7 +252,7 @@ static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
249 = (bitmap_weight(trig->pool, 252 = (bitmap_weight(trig->pool,
250 CONFIG_IIO_CONSUMERS_PER_TRIGGER) 253 CONFIG_IIO_CONSUMERS_PER_TRIGGER)
251 == 1); 254 == 1);
252 if (trig->ops && trig->ops->set_trigger_state && no_other_users) { 255 if (trig->ops->set_trigger_state && no_other_users) {
253 ret = trig->ops->set_trigger_state(trig, false); 256 ret = trig->ops->set_trigger_state(trig, false);
254 if (ret) 257 if (ret)
255 return ret; 258 return ret;
@@ -371,7 +374,7 @@ static ssize_t iio_trigger_write_current(struct device *dev,
371 return ret; 374 return ret;
372 } 375 }
373 376
374 if (trig && trig->ops && trig->ops->validate_device) { 377 if (trig && trig->ops->validate_device) {
375 ret = trig->ops->validate_device(trig, indio_dev); 378 ret = trig->ops->validate_device(trig, indio_dev);
376 if (ret) 379 if (ret)
377 return ret; 380 return ret;
diff --git a/drivers/iio/light/jsa1212.c b/drivers/iio/light/jsa1212.c
index 99a62816c3b4..e8a8931b4f50 100644
--- a/drivers/iio/light/jsa1212.c
+++ b/drivers/iio/light/jsa1212.c
@@ -325,9 +325,6 @@ static int jsa1212_probe(struct i2c_client *client,
325 struct regmap *regmap; 325 struct regmap *regmap;
326 int ret; 326 int ret;
327 327
328 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
329 return -EOPNOTSUPP;
330
331 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 328 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
332 if (!indio_dev) 329 if (!indio_dev)
333 return -ENOMEM; 330 return -ENOMEM;
diff --git a/drivers/iio/magnetometer/Kconfig b/drivers/iio/magnetometer/Kconfig
index 84e6559ccc65..1f842abcb4a4 100644
--- a/drivers/iio/magnetometer/Kconfig
+++ b/drivers/iio/magnetometer/Kconfig
@@ -44,6 +44,7 @@ config BMC150_MAGN_I2C
44 This driver is only implementing magnetometer part, which has 44 This driver is only implementing magnetometer part, which has
45 its own address and register map. 45 its own address and register map.
46 46
47 This driver also supports I2C Bosch BMC156 and BMM150 chips.
47 To compile this driver as a module, choose M here: the module will be 48 To compile this driver as a module, choose M here: the module will be
48 called bmc150_magn_i2c. 49 called bmc150_magn_i2c.
49 50
@@ -60,6 +61,7 @@ config BMC150_MAGN_SPI
60 This driver is only implementing magnetometer part, which has 61 This driver is only implementing magnetometer part, which has
61 its own address and register map. 62 its own address and register map.
62 63
64 This driver also supports SPI Bosch BMC156 and BMM150 chips.
63 To compile this driver as a module, choose M here: the module will be 65 To compile this driver as a module, choose M here: the module will be
64 called bmc150_magn_spi. 66 called bmc150_magn_spi.
65 67
diff --git a/drivers/iio/magnetometer/ak8975.c b/drivers/iio/magnetometer/ak8975.c
index 609a2c401b5d..57d3654d7caf 100644
--- a/drivers/iio/magnetometer/ak8975.c
+++ b/drivers/iio/magnetometer/ak8975.c
@@ -430,8 +430,8 @@ static int ak8975_who_i_am(struct i2c_client *client,
430 * AK8975 | DEVICE_ID | NA 430 * AK8975 | DEVICE_ID | NA
431 * AK8963 | DEVICE_ID | NA 431 * AK8963 | DEVICE_ID | NA
432 */ 432 */
433 ret = i2c_smbus_read_i2c_block_data(client, AK09912_REG_WIA1, 433 ret = i2c_smbus_read_i2c_block_data_or_emulated(
434 2, wia_val); 434 client, AK09912_REG_WIA1, 2, wia_val);
435 if (ret < 0) { 435 if (ret < 0) {
436 dev_err(&client->dev, "Error reading WIA\n"); 436 dev_err(&client->dev, "Error reading WIA\n");
437 return ret; 437 return ret;
@@ -543,9 +543,9 @@ static int ak8975_setup(struct i2c_client *client)
543 } 543 }
544 544
545 /* Get asa data and store in the device data. */ 545 /* Get asa data and store in the device data. */
546 ret = i2c_smbus_read_i2c_block_data(client, 546 ret = i2c_smbus_read_i2c_block_data_or_emulated(
547 data->def->ctrl_regs[ASA_BASE], 547 client, data->def->ctrl_regs[ASA_BASE],
548 3, data->asa); 548 3, data->asa);
549 if (ret < 0) { 549 if (ret < 0) {
550 dev_err(&client->dev, "Not able to read asa data\n"); 550 dev_err(&client->dev, "Not able to read asa data\n");
551 return ret; 551 return ret;
@@ -686,6 +686,7 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
686 struct ak8975_data *data = iio_priv(indio_dev); 686 struct ak8975_data *data = iio_priv(indio_dev);
687 const struct i2c_client *client = data->client; 687 const struct i2c_client *client = data->client;
688 const struct ak_def *def = data->def; 688 const struct ak_def *def = data->def;
689 u16 buff;
689 int ret; 690 int ret;
690 691
691 mutex_lock(&data->lock); 692 mutex_lock(&data->lock);
@@ -694,14 +695,17 @@ static int ak8975_read_axis(struct iio_dev *indio_dev, int index, int *val)
694 if (ret) 695 if (ret)
695 goto exit; 696 goto exit;
696 697
697 ret = i2c_smbus_read_word_data(client, def->data_regs[index]); 698 ret = i2c_smbus_read_i2c_block_data_or_emulated(
699 client, def->data_regs[index],
700 sizeof(buff), (u8*)&buff);
698 if (ret < 0) 701 if (ret < 0)
699 goto exit; 702 goto exit;
700 703
701 mutex_unlock(&data->lock); 704 mutex_unlock(&data->lock);
702 705
703 /* Clamp to valid range. */ 706 /* Swap bytes and convert to valid range. */
704 *val = clamp_t(s16, ret, -def->range, def->range); 707 buff = le16_to_cpu(buff);
708 *val = clamp_t(s16, buff, -def->range, def->range);
705 return IIO_VAL_INT; 709 return IIO_VAL_INT;
706 710
707exit: 711exit:
diff --git a/drivers/iio/magnetometer/bmc150_magn_i2c.c b/drivers/iio/magnetometer/bmc150_magn_i2c.c
index eddc7f0d0096..ee05722587aa 100644
--- a/drivers/iio/magnetometer/bmc150_magn_i2c.c
+++ b/drivers/iio/magnetometer/bmc150_magn_i2c.c
@@ -2,6 +2,7 @@
2 * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips: 2 * 3-axis magnetometer driver supporting following I2C Bosch-Sensortec chips:
3 * - BMC150 3 * - BMC150
4 * - BMC156 4 * - BMC156
5 * - BMM150
5 * 6 *
6 * Copyright (c) 2016, Intel Corporation. 7 * Copyright (c) 2016, Intel Corporation.
7 * 8 *
@@ -49,6 +50,7 @@ static int bmc150_magn_i2c_remove(struct i2c_client *client)
49static const struct acpi_device_id bmc150_magn_acpi_match[] = { 50static const struct acpi_device_id bmc150_magn_acpi_match[] = {
50 {"BMC150B", 0}, 51 {"BMC150B", 0},
51 {"BMC156B", 0}, 52 {"BMC156B", 0},
53 {"BMM150B", 0},
52 {}, 54 {},
53}; 55};
54MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 56MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
@@ -56,6 +58,7 @@ MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
56static const struct i2c_device_id bmc150_magn_i2c_id[] = { 58static const struct i2c_device_id bmc150_magn_i2c_id[] = {
57 {"bmc150_magn", 0}, 59 {"bmc150_magn", 0},
58 {"bmc156_magn", 0}, 60 {"bmc156_magn", 0},
61 {"bmm150_magn", 0},
59 {} 62 {}
60}; 63};
61MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id); 64MODULE_DEVICE_TABLE(i2c, bmc150_magn_i2c_id);
diff --git a/drivers/iio/magnetometer/bmc150_magn_spi.c b/drivers/iio/magnetometer/bmc150_magn_spi.c
index c4c738a07695..7d4152d4d01e 100644
--- a/drivers/iio/magnetometer/bmc150_magn_spi.c
+++ b/drivers/iio/magnetometer/bmc150_magn_spi.c
@@ -2,6 +2,7 @@
2 * 3-axis magnetometer driver support following SPI Bosch-Sensortec chips: 2 * 3-axis magnetometer driver support following SPI Bosch-Sensortec chips:
3 * - BMC150 3 * - BMC150
4 * - BMC156 4 * - BMC156
5 * - BMM150
5 * 6 *
6 * Copyright (c) 2016, Intel Corporation. 7 * Copyright (c) 2016, Intel Corporation.
7 * 8 *
@@ -41,6 +42,7 @@ static int bmc150_magn_spi_remove(struct spi_device *spi)
41static const struct spi_device_id bmc150_magn_spi_id[] = { 42static const struct spi_device_id bmc150_magn_spi_id[] = {
42 {"bmc150_magn", 0}, 43 {"bmc150_magn", 0},
43 {"bmc156_magn", 0}, 44 {"bmc156_magn", 0},
45 {"bmm150_magn", 0},
44 {} 46 {}
45}; 47};
46MODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id); 48MODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id);
@@ -48,6 +50,7 @@ MODULE_DEVICE_TABLE(spi, bmc150_magn_spi_id);
48static const struct acpi_device_id bmc150_magn_acpi_match[] = { 50static const struct acpi_device_id bmc150_magn_acpi_match[] = {
49 {"BMC150B", 0}, 51 {"BMC150B", 0},
50 {"BMC156B", 0}, 52 {"BMC156B", 0},
53 {"BMM150B", 0},
51 {}, 54 {},
52}; 55};
53MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match); 56MODULE_DEVICE_TABLE(acpi, bmc150_magn_acpi_match);
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 8250fc322c56..3e1f06b2224c 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -589,13 +589,15 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
589 indio_dev->info = &magn_info; 589 indio_dev->info = &magn_info;
590 mutex_init(&mdata->tb.buf_lock); 590 mutex_init(&mdata->tb.buf_lock);
591 591
592 st_sensors_power_enable(indio_dev); 592 err = st_sensors_power_enable(indio_dev);
593 if (err)
594 return err;
593 595
594 err = st_sensors_check_device_support(indio_dev, 596 err = st_sensors_check_device_support(indio_dev,
595 ARRAY_SIZE(st_magn_sensors_settings), 597 ARRAY_SIZE(st_magn_sensors_settings),
596 st_magn_sensors_settings); 598 st_magn_sensors_settings);
597 if (err < 0) 599 if (err < 0)
598 return err; 600 goto st_magn_power_off;
599 601
600 mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS; 602 mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS;
601 mdata->multiread_bit = mdata->sensor_settings->multi_read_bit; 603 mdata->multiread_bit = mdata->sensor_settings->multi_read_bit;
@@ -608,11 +610,11 @@ int st_magn_common_probe(struct iio_dev *indio_dev)
608 610
609 err = st_sensors_init_sensor(indio_dev, NULL); 611 err = st_sensors_init_sensor(indio_dev, NULL);
610 if (err < 0) 612 if (err < 0)
611 return err; 613 goto st_magn_power_off;
612 614
613 err = st_magn_allocate_ring(indio_dev); 615 err = st_magn_allocate_ring(indio_dev);
614 if (err < 0) 616 if (err < 0)
615 return err; 617 goto st_magn_power_off;
616 618
617 if (irq > 0) { 619 if (irq > 0) {
618 err = st_sensors_allocate_trigger(indio_dev, 620 err = st_sensors_allocate_trigger(indio_dev,
@@ -635,6 +637,8 @@ st_magn_device_register_error:
635 st_sensors_deallocate_trigger(indio_dev); 637 st_sensors_deallocate_trigger(indio_dev);
636st_magn_probe_trigger_error: 638st_magn_probe_trigger_error:
637 st_magn_deallocate_ring(indio_dev); 639 st_magn_deallocate_ring(indio_dev);
640st_magn_power_off:
641 st_sensors_power_disable(indio_dev);
638 642
639 return err; 643 return err;
640} 644}
diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig
index 6acb23810bb4..0941c8d490a0 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 MAX5487
19 tristate "Maxim MAX5487/MAX5488/MAX5489 Digital Potentiometer driver"
20 depends on SPI
21 help
22 Say yes here to build support for the Maxim
23 MAX5487, MAX5488, MAX5489 digital potentiometer
24 chips.
25
26 To compile this driver as a module, choose M here: the
27 module will be called max5487.
28
18config MCP4131 29config MCP4131
19 tristate "Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X Digital Potentiometer driver" 30 tristate "Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X Digital Potentiometer driver"
20 depends on SPI 31 depends on SPI
diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile
index 6007faa2fb02..8adb58f38c0b 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_MAX5487) += max5487.o
7obj-$(CONFIG_MCP4131) += mcp4131.o 8obj-$(CONFIG_MCP4131) += mcp4131.o
8obj-$(CONFIG_MCP4531) += mcp4531.o 9obj-$(CONFIG_MCP4531) += mcp4531.o
9obj-$(CONFIG_TPL0102) += tpl0102.o 10obj-$(CONFIG_TPL0102) += tpl0102.o
diff --git a/drivers/iio/potentiometer/max5487.c b/drivers/iio/potentiometer/max5487.c
new file mode 100644
index 000000000000..6c50939a2e83
--- /dev/null
+++ b/drivers/iio/potentiometer/max5487.c
@@ -0,0 +1,161 @@
1/*
2 * max5487.c - Support for MAX5487, MAX5488, MAX5489 digital potentiometers
3 *
4 * Copyright (C) 2016 Cristina-Gabriela Moraru <cristina.moraru09@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 version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/module.h>
12#include <linux/spi/spi.h>
13#include <linux/acpi.h>
14
15#include <linux/iio/sysfs.h>
16#include <linux/iio/iio.h>
17
18#define MAX5487_WRITE_WIPER_A (0x01 << 8)
19#define MAX5487_WRITE_WIPER_B (0x02 << 8)
20
21/* copy both wiper regs to NV regs */
22#define MAX5487_COPY_AB_TO_NV (0x23 << 8)
23/* copy both NV regs to wiper regs */
24#define MAX5487_COPY_NV_TO_AB (0x33 << 8)
25
26#define MAX5487_MAX_POS 255
27
28struct max5487_data {
29 struct spi_device *spi;
30 int kohms;
31};
32
33#define MAX5487_CHANNEL(ch, addr) { \
34 .type = IIO_RESISTANCE, \
35 .indexed = 1, \
36 .output = 1, \
37 .channel = ch, \
38 .address = addr, \
39 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
40 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), \
41}
42
43static const struct iio_chan_spec max5487_channels[] = {
44 MAX5487_CHANNEL(0, MAX5487_WRITE_WIPER_A),
45 MAX5487_CHANNEL(1, MAX5487_WRITE_WIPER_B),
46};
47
48static int max5487_write_cmd(struct spi_device *spi, u16 cmd)
49{
50 return spi_write(spi, (const void *) &cmd, sizeof(u16));
51}
52
53static int max5487_read_raw(struct iio_dev *indio_dev,
54 struct iio_chan_spec const *chan,
55 int *val, int *val2, long mask)
56{
57 struct max5487_data *data = iio_priv(indio_dev);
58
59 if (mask != IIO_CHAN_INFO_SCALE)
60 return -EINVAL;
61
62 *val = 1000 * data->kohms;
63 *val2 = MAX5487_MAX_POS;
64
65 return IIO_VAL_FRACTIONAL;
66}
67
68static int max5487_write_raw(struct iio_dev *indio_dev,
69 struct iio_chan_spec const *chan,
70 int val, int val2, long mask)
71{
72 struct max5487_data *data = iio_priv(indio_dev);
73
74 if (mask != IIO_CHAN_INFO_RAW)
75 return -EINVAL;
76
77 if (val < 0 || val > MAX5487_MAX_POS)
78 return -EINVAL;
79
80 return max5487_write_cmd(data->spi, chan->address | val);
81}
82
83static const struct iio_info max5487_info = {
84 .read_raw = max5487_read_raw,
85 .write_raw = max5487_write_raw,
86 .driver_module = THIS_MODULE,
87};
88
89static int max5487_spi_probe(struct spi_device *spi)
90{
91 struct iio_dev *indio_dev;
92 struct max5487_data *data;
93 const struct spi_device_id *id = spi_get_device_id(spi);
94 int ret;
95
96 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*data));
97 if (!indio_dev)
98 return -ENOMEM;
99
100 dev_set_drvdata(&spi->dev, indio_dev);
101 data = iio_priv(indio_dev);
102
103 data->spi = spi;
104 data->kohms = id->driver_data;
105
106 indio_dev->info = &max5487_info;
107 indio_dev->name = id->name;
108 indio_dev->dev.parent = &spi->dev;
109 indio_dev->modes = INDIO_DIRECT_MODE;
110 indio_dev->channels = max5487_channels;
111 indio_dev->num_channels = ARRAY_SIZE(max5487_channels);
112
113 /* restore both wiper regs from NV regs */
114 ret = max5487_write_cmd(data->spi, MAX5487_COPY_NV_TO_AB);
115 if (ret < 0)
116 return ret;
117
118 return iio_device_register(indio_dev);
119}
120
121static int max5487_spi_remove(struct spi_device *spi)
122{
123 struct iio_dev *indio_dev = dev_get_drvdata(&spi->dev);
124
125 iio_device_unregister(indio_dev);
126
127 /* save both wiper regs to NV regs */
128 return max5487_write_cmd(spi, MAX5487_COPY_AB_TO_NV);
129}
130
131static const struct spi_device_id max5487_id[] = {
132 { "MAX5487", 10 },
133 { "MAX5488", 50 },
134 { "MAX5489", 100 },
135 { }
136};
137MODULE_DEVICE_TABLE(spi, max5487_id);
138
139static const struct acpi_device_id max5487_acpi_match[] = {
140 { "MAX5487", 10 },
141 { "MAX5488", 50 },
142 { "MAX5489", 100 },
143 { },
144};
145MODULE_DEVICE_TABLE(acpi, max5487_acpi_match);
146
147static struct spi_driver max5487_driver = {
148 .driver = {
149 .name = "max5487",
150 .owner = THIS_MODULE,
151 .acpi_match_table = ACPI_PTR(max5487_acpi_match),
152 },
153 .id_table = max5487_id,
154 .probe = max5487_spi_probe,
155 .remove = max5487_spi_remove
156};
157module_spi_driver(max5487_driver);
158
159MODULE_AUTHOR("Cristina-Gabriela Moraru <cristina.moraru09@gmail.com>");
160MODULE_DESCRIPTION("max5487 SPI driver");
161MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/potentiometer/tpl0102.c b/drivers/iio/potentiometer/tpl0102.c
index 5c304d42d713..7b6b54531ea2 100644
--- a/drivers/iio/potentiometer/tpl0102.c
+++ b/drivers/iio/potentiometer/tpl0102.c
@@ -116,10 +116,6 @@ static int tpl0102_probe(struct i2c_client *client,
116 struct tpl0102_data *data; 116 struct tpl0102_data *data;
117 struct iio_dev *indio_dev; 117 struct iio_dev *indio_dev;
118 118
119 if (!i2c_check_functionality(client->adapter,
120 I2C_FUNC_SMBUS_WORD_DATA))
121 return -EOPNOTSUPP;
122
123 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 119 indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
124 if (!indio_dev) 120 if (!indio_dev)
125 return -ENOMEM; 121 return -ENOMEM;
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index cda9f128f3a4..8d654f671b6b 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -12,7 +12,8 @@ config BMP280
12 select REGMAP_I2C 12 select REGMAP_I2C
13 help 13 help
14 Say yes here to build support for Bosch Sensortec BMP180 and BMP280 14 Say yes here to build support for Bosch Sensortec BMP180 and BMP280
15 pressure and temperature sensors. 15 pressure and temperature sensors. Also supports the BE280 with
16 an additional humidty sensor channel.
16 17
17 To compile this driver as a module, choose M here: the module 18 To compile this driver as a module, choose M here: the module
18 will be called bmp280. 19 will be called bmp280.
@@ -130,7 +131,7 @@ config IIO_ST_PRESS
130 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER) 131 select IIO_TRIGGERED_BUFFER if (IIO_BUFFER)
131 help 132 help
132 Say yes here to build support for STMicroelectronics pressure 133 Say yes here to build support for STMicroelectronics pressure
133 sensors: LPS001WP, LPS25H, LPS331AP. 134 sensors: LPS001WP, LPS25H, LPS331AP, LPS22HB.
134 135
135 This driver can also be built as a module. If so, these modules 136 This driver can also be built as a module. If so, these modules
136 will be created: 137 will be created:
diff --git a/drivers/iio/pressure/bmp280.c b/drivers/iio/pressure/bmp280.c
index 724452d61846..dbbcd6d83e3b 100644
--- a/drivers/iio/pressure/bmp280.c
+++ b/drivers/iio/pressure/bmp280.c
@@ -10,6 +10,7 @@
10 * Datasheet: 10 * Datasheet:
11 * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP180-DS000-121.pdf 11 * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP180-DS000-121.pdf
12 * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP280-DS001-12.pdf 12 * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP280-DS001-12.pdf
13 * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf
13 */ 14 */
14 15
15#define pr_fmt(fmt) "bmp280: " fmt 16#define pr_fmt(fmt) "bmp280: " fmt
@@ -23,6 +24,8 @@
23#include <linux/iio/sysfs.h> 24#include <linux/iio/sysfs.h>
24 25
25/* BMP280 specific registers */ 26/* BMP280 specific registers */
27#define BMP280_REG_HUMIDITY_LSB 0xFE
28#define BMP280_REG_HUMIDITY_MSB 0xFD
26#define BMP280_REG_TEMP_XLSB 0xFC 29#define BMP280_REG_TEMP_XLSB 0xFC
27#define BMP280_REG_TEMP_LSB 0xFB 30#define BMP280_REG_TEMP_LSB 0xFB
28#define BMP280_REG_TEMP_MSB 0xFA 31#define BMP280_REG_TEMP_MSB 0xFA
@@ -31,7 +34,17 @@
31#define BMP280_REG_PRESS_MSB 0xF7 34#define BMP280_REG_PRESS_MSB 0xF7
32 35
33#define BMP280_REG_CONFIG 0xF5 36#define BMP280_REG_CONFIG 0xF5
37#define BMP280_REG_CTRL_MEAS 0xF4
34#define BMP280_REG_STATUS 0xF3 38#define BMP280_REG_STATUS 0xF3
39#define BMP280_REG_CTRL_HUMIDITY 0xF2
40
41/* Due to non linear mapping, and data sizes we can't do a bulk read */
42#define BMP280_REG_COMP_H1 0xA1
43#define BMP280_REG_COMP_H2 0xE1
44#define BMP280_REG_COMP_H3 0xE3
45#define BMP280_REG_COMP_H4 0xE4
46#define BMP280_REG_COMP_H5 0xE5
47#define BMP280_REG_COMP_H6 0xE7
35 48
36#define BMP280_REG_COMP_TEMP_START 0x88 49#define BMP280_REG_COMP_TEMP_START 0x88
37#define BMP280_COMP_TEMP_REG_COUNT 6 50#define BMP280_COMP_TEMP_REG_COUNT 6
@@ -46,6 +59,15 @@
46#define BMP280_FILTER_8X (BIT(3) | BIT(2)) 59#define BMP280_FILTER_8X (BIT(3) | BIT(2))
47#define BMP280_FILTER_16X BIT(4) 60#define BMP280_FILTER_16X BIT(4)
48 61
62#define BMP280_OSRS_HUMIDITY_MASK (BIT(2) | BIT(1) | BIT(0))
63#define BMP280_OSRS_HUMIDITIY_X(osrs_h) ((osrs_h) << 0)
64#define BMP280_OSRS_HUMIDITY_SKIP 0
65#define BMP280_OSRS_HUMIDITY_1X BMP280_OSRS_HUMIDITIY_X(1)
66#define BMP280_OSRS_HUMIDITY_2X BMP280_OSRS_HUMIDITIY_X(2)
67#define BMP280_OSRS_HUMIDITY_4X BMP280_OSRS_HUMIDITIY_X(3)
68#define BMP280_OSRS_HUMIDITY_8X BMP280_OSRS_HUMIDITIY_X(4)
69#define BMP280_OSRS_HUMIDITY_16X BMP280_OSRS_HUMIDITIY_X(5)
70
49#define BMP280_OSRS_TEMP_MASK (BIT(7) | BIT(6) | BIT(5)) 71#define BMP280_OSRS_TEMP_MASK (BIT(7) | BIT(6) | BIT(5))
50#define BMP280_OSRS_TEMP_SKIP 0 72#define BMP280_OSRS_TEMP_SKIP 0
51#define BMP280_OSRS_TEMP_X(osrs_t) ((osrs_t) << 5) 73#define BMP280_OSRS_TEMP_X(osrs_t) ((osrs_t) << 5)
@@ -92,6 +114,7 @@
92 114
93#define BMP180_CHIP_ID 0x55 115#define BMP180_CHIP_ID 0x55
94#define BMP280_CHIP_ID 0x58 116#define BMP280_CHIP_ID 0x58
117#define BME280_CHIP_ID 0x60
95#define BMP280_SOFT_RESET_VAL 0xB6 118#define BMP280_SOFT_RESET_VAL 0xB6
96 119
97struct bmp280_data { 120struct bmp280_data {
@@ -103,6 +126,7 @@ struct bmp280_data {
103 /* log of base 2 of oversampling rate */ 126 /* log of base 2 of oversampling rate */
104 u8 oversampling_press; 127 u8 oversampling_press;
105 u8 oversampling_temp; 128 u8 oversampling_temp;
129 u8 oversampling_humid;
106 130
107 /* 131 /*
108 * Carryover value from temperature conversion, used in pressure 132 * Carryover value from temperature conversion, used in pressure
@@ -120,9 +144,13 @@ struct bmp280_chip_info {
120 const int *oversampling_press_avail; 144 const int *oversampling_press_avail;
121 int num_oversampling_press_avail; 145 int num_oversampling_press_avail;
122 146
147 const int *oversampling_humid_avail;
148 int num_oversampling_humid_avail;
149
123 int (*chip_config)(struct bmp280_data *); 150 int (*chip_config)(struct bmp280_data *);
124 int (*read_temp)(struct bmp280_data *, int *); 151 int (*read_temp)(struct bmp280_data *, int *);
125 int (*read_press)(struct bmp280_data *, int *, int *); 152 int (*read_press)(struct bmp280_data *, int *, int *);
153 int (*read_humid)(struct bmp280_data *, int *, int *);
126}; 154};
127 155
128/* 156/*
@@ -143,12 +171,18 @@ static const struct iio_chan_spec bmp280_channels[] = {
143 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | 171 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
144 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 172 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
145 }, 173 },
174 {
175 .type = IIO_HUMIDITYRELATIVE,
176 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) |
177 BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
178 },
146}; 179};
147 180
148static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg) 181static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
149{ 182{
150 switch (reg) { 183 switch (reg) {
151 case BMP280_REG_CONFIG: 184 case BMP280_REG_CONFIG:
185 case BMP280_REG_CTRL_HUMIDITY:
152 case BMP280_REG_CTRL_MEAS: 186 case BMP280_REG_CTRL_MEAS:
153 case BMP280_REG_RESET: 187 case BMP280_REG_RESET:
154 return true; 188 return true;
@@ -160,6 +194,8 @@ static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
160static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg) 194static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg)
161{ 195{
162 switch (reg) { 196 switch (reg) {
197 case BMP280_REG_HUMIDITY_LSB:
198 case BMP280_REG_HUMIDITY_MSB:
163 case BMP280_REG_TEMP_XLSB: 199 case BMP280_REG_TEMP_XLSB:
164 case BMP280_REG_TEMP_LSB: 200 case BMP280_REG_TEMP_LSB:
165 case BMP280_REG_TEMP_MSB: 201 case BMP280_REG_TEMP_MSB:
@@ -177,7 +213,7 @@ static const struct regmap_config bmp280_regmap_config = {
177 .reg_bits = 8, 213 .reg_bits = 8,
178 .val_bits = 8, 214 .val_bits = 8,
179 215
180 .max_register = BMP280_REG_TEMP_XLSB, 216 .max_register = BMP280_REG_HUMIDITY_LSB,
181 .cache_type = REGCACHE_RBTREE, 217 .cache_type = REGCACHE_RBTREE,
182 218
183 .writeable_reg = bmp280_is_writeable_reg, 219 .writeable_reg = bmp280_is_writeable_reg,
@@ -185,6 +221,70 @@ static const struct regmap_config bmp280_regmap_config = {
185}; 221};
186 222
187/* 223/*
224 * Returns humidity in percent, resolution is 0.01 percent. Output value of
225 * "47445" represents 47445/1024 = 46.333 %RH.
226 *
227 * Taken from BME280 datasheet, Section 4.2.3, "Compensation formula".
228 */
229
230static u32 bmp280_compensate_humidity(struct bmp280_data *data,
231 s32 adc_humidity)
232{
233 struct device *dev = &data->client->dev;
234 unsigned int H1, H3, tmp;
235 int H2, H4, H5, H6, ret, var;
236
237 ret = regmap_read(data->regmap, BMP280_REG_COMP_H1, &H1);
238 if (ret < 0) {
239 dev_err(dev, "failed to read H1 comp value\n");
240 return ret;
241 }
242
243 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H2, &tmp, 2);
244 if (ret < 0) {
245 dev_err(dev, "failed to read H2 comp value\n");
246 return ret;
247 }
248 H2 = sign_extend32(le16_to_cpu(tmp), 15);
249
250 ret = regmap_read(data->regmap, BMP280_REG_COMP_H3, &H3);
251 if (ret < 0) {
252 dev_err(dev, "failed to read H3 comp value\n");
253 return ret;
254 }
255
256 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H4, &tmp, 2);
257 if (ret < 0) {
258 dev_err(dev, "failed to read H4 comp value\n");
259 return ret;
260 }
261 H4 = sign_extend32(((be16_to_cpu(tmp) >> 4) & 0xff0) |
262 (be16_to_cpu(tmp) & 0xf), 11);
263
264 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_H5, &tmp, 2);
265 if (ret < 0) {
266 dev_err(dev, "failed to read H5 comp value\n");
267 return ret;
268 }
269 H5 = sign_extend32(((le16_to_cpu(tmp) >> 4) & 0xfff), 11);
270
271 ret = regmap_read(data->regmap, BMP280_REG_COMP_H6, &tmp);
272 if (ret < 0) {
273 dev_err(dev, "failed to read H6 comp value\n");
274 return ret;
275 }
276 H6 = sign_extend32(tmp, 7);
277
278 var = ((s32)data->t_fine) - 76800;
279 var = ((((adc_humidity << 14) - (H4 << 20) - (H5 * var)) + 16384) >> 15)
280 * (((((((var * H6) >> 10) * (((var * H3) >> 11) + 32768)) >> 10)
281 + 2097152) * H2 + 8192) >> 14);
282 var -= ((((var >> 15) * (var >> 15)) >> 7) * H1) >> 4;
283
284 return var >> 12;
285};
286
287/*
188 * Returns temperature in DegC, resolution is 0.01 DegC. Output value of 288 * Returns temperature in DegC, resolution is 0.01 DegC. Output value of
189 * "5123" equals 51.23 DegC. t_fine carries fine temperature as global 289 * "5123" equals 51.23 DegC. t_fine carries fine temperature as global
190 * value. 290 * value.
@@ -324,6 +424,34 @@ static int bmp280_read_press(struct bmp280_data *data,
324 return IIO_VAL_FRACTIONAL; 424 return IIO_VAL_FRACTIONAL;
325} 425}
326 426
427static int bmp280_read_humid(struct bmp280_data *data, int *val, int *val2)
428{
429 int ret;
430 __be16 tmp = 0;
431 s32 adc_humidity;
432 u32 comp_humidity;
433
434 /* Read and compensate temperature so we get a reading of t_fine. */
435 ret = bmp280_read_temp(data, NULL);
436 if (ret < 0)
437 return ret;
438
439 ret = regmap_bulk_read(data->regmap, BMP280_REG_HUMIDITY_MSB,
440 (u8 *) &tmp, 2);
441 if (ret < 0) {
442 dev_err(&data->client->dev, "failed to read humidity\n");
443 return ret;
444 }
445
446 adc_humidity = be16_to_cpu(tmp);
447 comp_humidity = bmp280_compensate_humidity(data, adc_humidity);
448
449 *val = comp_humidity;
450 *val2 = 1024;
451
452 return IIO_VAL_FRACTIONAL;
453}
454
327static int bmp280_read_raw(struct iio_dev *indio_dev, 455static int bmp280_read_raw(struct iio_dev *indio_dev,
328 struct iio_chan_spec const *chan, 456 struct iio_chan_spec const *chan,
329 int *val, int *val2, long mask) 457 int *val, int *val2, long mask)
@@ -336,6 +464,9 @@ static int bmp280_read_raw(struct iio_dev *indio_dev,
336 switch (mask) { 464 switch (mask) {
337 case IIO_CHAN_INFO_PROCESSED: 465 case IIO_CHAN_INFO_PROCESSED:
338 switch (chan->type) { 466 switch (chan->type) {
467 case IIO_HUMIDITYRELATIVE:
468 ret = data->chip_info->read_humid(data, val, val2);
469 break;
339 case IIO_PRESSURE: 470 case IIO_PRESSURE:
340 ret = data->chip_info->read_press(data, val, val2); 471 ret = data->chip_info->read_press(data, val, val2);
341 break; 472 break;
@@ -349,6 +480,10 @@ static int bmp280_read_raw(struct iio_dev *indio_dev,
349 break; 480 break;
350 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 481 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
351 switch (chan->type) { 482 switch (chan->type) {
483 case IIO_HUMIDITYRELATIVE:
484 *val = 1 << data->oversampling_humid;
485 ret = IIO_VAL_INT;
486 break;
352 case IIO_PRESSURE: 487 case IIO_PRESSURE:
353 *val = 1 << data->oversampling_press; 488 *val = 1 << data->oversampling_press;
354 ret = IIO_VAL_INT; 489 ret = IIO_VAL_INT;
@@ -372,6 +507,23 @@ static int bmp280_read_raw(struct iio_dev *indio_dev,
372 return ret; 507 return ret;
373} 508}
374 509
510static int bmp280_write_oversampling_ratio_humid(struct bmp280_data *data,
511 int val)
512{
513 int i;
514 const int *avail = data->chip_info->oversampling_humid_avail;
515 const int n = data->chip_info->num_oversampling_humid_avail;
516
517 for (i = 0; i < n; i++) {
518 if (avail[i] == val) {
519 data->oversampling_humid = ilog2(val);
520
521 return data->chip_info->chip_config(data);
522 }
523 }
524 return -EINVAL;
525}
526
375static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data, 527static int bmp280_write_oversampling_ratio_temp(struct bmp280_data *data,
376 int val) 528 int val)
377{ 529{
@@ -417,6 +569,9 @@ static int bmp280_write_raw(struct iio_dev *indio_dev,
417 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: 569 case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
418 mutex_lock(&data->lock); 570 mutex_lock(&data->lock);
419 switch (chan->type) { 571 switch (chan->type) {
572 case IIO_HUMIDITYRELATIVE:
573 ret = bmp280_write_oversampling_ratio_humid(data, val);
574 break;
420 case IIO_PRESSURE: 575 case IIO_PRESSURE:
421 ret = bmp280_write_oversampling_ratio_press(data, val); 576 ret = bmp280_write_oversampling_ratio_press(data, val);
422 break; 577 break;
@@ -535,6 +690,37 @@ static const struct bmp280_chip_info bmp280_chip_info = {
535 .read_press = bmp280_read_press, 690 .read_press = bmp280_read_press,
536}; 691};
537 692
693static int bme280_chip_config(struct bmp280_data *data)
694{
695 int ret = bmp280_chip_config(data);
696 u8 osrs = BMP280_OSRS_HUMIDITIY_X(data->oversampling_humid + 1);
697
698 if (ret < 0)
699 return ret;
700
701 return regmap_update_bits(data->regmap, BMP280_REG_CTRL_HUMIDITY,
702 BMP280_OSRS_HUMIDITY_MASK, osrs);
703}
704
705static const struct bmp280_chip_info bme280_chip_info = {
706 .regmap_config = &bmp280_regmap_config,
707
708 .oversampling_temp_avail = bmp280_oversampling_avail,
709 .num_oversampling_temp_avail = ARRAY_SIZE(bmp280_oversampling_avail),
710
711 .oversampling_press_avail = bmp280_oversampling_avail,
712 .num_oversampling_press_avail = ARRAY_SIZE(bmp280_oversampling_avail),
713
714 .oversampling_humid_avail = bmp280_oversampling_avail,
715 .num_oversampling_humid_avail = ARRAY_SIZE(bmp280_oversampling_avail),
716
717 .chip_config = bme280_chip_config,
718 .read_temp = bmp280_read_temp,
719 .read_press = bmp280_read_press,
720 .read_humid = bmp280_read_humid,
721};
722
723
538static bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg) 724static bool bmp180_is_writeable_reg(struct device *dev, unsigned int reg)
539{ 725{
540 switch (reg) { 726 switch (reg) {
@@ -849,21 +1035,29 @@ static int bmp280_probe(struct i2c_client *client,
849 indio_dev->dev.parent = &client->dev; 1035 indio_dev->dev.parent = &client->dev;
850 indio_dev->name = id->name; 1036 indio_dev->name = id->name;
851 indio_dev->channels = bmp280_channels; 1037 indio_dev->channels = bmp280_channels;
852 indio_dev->num_channels = ARRAY_SIZE(bmp280_channels);
853 indio_dev->info = &bmp280_info; 1038 indio_dev->info = &bmp280_info;
854 indio_dev->modes = INDIO_DIRECT_MODE; 1039 indio_dev->modes = INDIO_DIRECT_MODE;
855 1040
856 switch (id->driver_data) { 1041 switch (id->driver_data) {
857 case BMP180_CHIP_ID: 1042 case BMP180_CHIP_ID:
1043 indio_dev->num_channels = 2;
858 data->chip_info = &bmp180_chip_info; 1044 data->chip_info = &bmp180_chip_info;
859 data->oversampling_press = ilog2(8); 1045 data->oversampling_press = ilog2(8);
860 data->oversampling_temp = ilog2(1); 1046 data->oversampling_temp = ilog2(1);
861 break; 1047 break;
862 case BMP280_CHIP_ID: 1048 case BMP280_CHIP_ID:
1049 indio_dev->num_channels = 2;
863 data->chip_info = &bmp280_chip_info; 1050 data->chip_info = &bmp280_chip_info;
864 data->oversampling_press = ilog2(16); 1051 data->oversampling_press = ilog2(16);
865 data->oversampling_temp = ilog2(2); 1052 data->oversampling_temp = ilog2(2);
866 break; 1053 break;
1054 case BME280_CHIP_ID:
1055 indio_dev->num_channels = 3;
1056 data->chip_info = &bme280_chip_info;
1057 data->oversampling_press = ilog2(16);
1058 data->oversampling_humid = ilog2(16);
1059 data->oversampling_temp = ilog2(2);
1060 break;
867 default: 1061 default:
868 return -EINVAL; 1062 return -EINVAL;
869 } 1063 }
@@ -895,6 +1089,7 @@ static const struct acpi_device_id bmp280_acpi_match[] = {
895 {"BMP0280", BMP280_CHIP_ID }, 1089 {"BMP0280", BMP280_CHIP_ID },
896 {"BMP0180", BMP180_CHIP_ID }, 1090 {"BMP0180", BMP180_CHIP_ID },
897 {"BMP0085", BMP180_CHIP_ID }, 1091 {"BMP0085", BMP180_CHIP_ID },
1092 {"BME0280", BME280_CHIP_ID },
898 { }, 1093 { },
899}; 1094};
900MODULE_DEVICE_TABLE(acpi, bmp280_acpi_match); 1095MODULE_DEVICE_TABLE(acpi, bmp280_acpi_match);
@@ -903,6 +1098,7 @@ static const struct i2c_device_id bmp280_id[] = {
903 {"bmp280", BMP280_CHIP_ID }, 1098 {"bmp280", BMP280_CHIP_ID },
904 {"bmp180", BMP180_CHIP_ID }, 1099 {"bmp180", BMP180_CHIP_ID },
905 {"bmp085", BMP180_CHIP_ID }, 1100 {"bmp085", BMP180_CHIP_ID },
1101 {"bme280", BME280_CHIP_ID },
906 { }, 1102 { },
907}; 1103};
908MODULE_DEVICE_TABLE(i2c, bmp280_id); 1104MODULE_DEVICE_TABLE(i2c, bmp280_id);
diff --git a/drivers/iio/pressure/hp206c.c b/drivers/iio/pressure/hp206c.c
index 90f2b6e4a920..12f769e86355 100644
--- a/drivers/iio/pressure/hp206c.c
+++ b/drivers/iio/pressure/hp206c.c
@@ -401,6 +401,7 @@ static const struct i2c_device_id hp206c_id[] = {
401 {"hp206c"}, 401 {"hp206c"},
402 {} 402 {}
403}; 403};
404MODULE_DEVICE_TABLE(i2c, hp206c_id);
404 405
405#ifdef CONFIG_ACPI 406#ifdef CONFIG_ACPI
406static const struct acpi_device_id hp206c_acpi_match[] = { 407static const struct acpi_device_id hp206c_acpi_match[] = {
diff --git a/drivers/iio/pressure/ms5637.c b/drivers/iio/pressure/ms5637.c
index e68052c118e6..8fb6f7ab97e4 100644
--- a/drivers/iio/pressure/ms5637.c
+++ b/drivers/iio/pressure/ms5637.c
@@ -173,6 +173,7 @@ static const struct i2c_device_id ms5637_id[] = {
173 {"ms8607-temppressure", 1}, 173 {"ms8607-temppressure", 1},
174 {} 174 {}
175}; 175};
176MODULE_DEVICE_TABLE(i2c, ms5637_id);
176 177
177static struct i2c_driver ms5637_driver = { 178static struct i2c_driver ms5637_driver = {
178 .probe = ms5637_probe, 179 .probe = ms5637_probe,
diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h
index f5f41490060b..903a21e46874 100644
--- a/drivers/iio/pressure/st_pressure.h
+++ b/drivers/iio/pressure/st_pressure.h
@@ -17,6 +17,7 @@
17#define LPS001WP_PRESS_DEV_NAME "lps001wp" 17#define LPS001WP_PRESS_DEV_NAME "lps001wp"
18#define LPS25H_PRESS_DEV_NAME "lps25h" 18#define LPS25H_PRESS_DEV_NAME "lps25h"
19#define LPS331AP_PRESS_DEV_NAME "lps331ap" 19#define LPS331AP_PRESS_DEV_NAME "lps331ap"
20#define LPS22HB_PRESS_DEV_NAME "lps22hb"
20 21
21/** 22/**
22 * struct st_sensors_platform_data - default press platform data 23 * struct st_sensors_platform_data - default press platform data
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 92a118c3c4ac..56d8f5eb9239 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -117,6 +117,26 @@
117#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28 117#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
118#define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b 118#define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b
119 119
120/* CUSTOM VALUES FOR LPS22HB SENSOR */
121#define ST_PRESS_LPS22HB_WAI_EXP 0xb1
122#define ST_PRESS_LPS22HB_ODR_ADDR 0x10
123#define ST_PRESS_LPS22HB_ODR_MASK 0x70
124#define ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL 0x01
125#define ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL 0x02
126#define ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL 0x03
127#define ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL 0x04
128#define ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL 0x05
129#define ST_PRESS_LPS22HB_PW_ADDR 0x10
130#define ST_PRESS_LPS22HB_PW_MASK 0x70
131#define ST_PRESS_LPS22HB_BDU_ADDR 0x10
132#define ST_PRESS_LPS22HB_BDU_MASK 0x02
133#define ST_PRESS_LPS22HB_DRDY_IRQ_ADDR 0x12
134#define ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK 0x04
135#define ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK 0x08
136#define ST_PRESS_LPS22HB_IHL_IRQ_ADDR 0x12
137#define ST_PRESS_LPS22HB_IHL_IRQ_MASK 0x80
138#define ST_PRESS_LPS22HB_MULTIREAD_BIT true
139
120static const struct iio_chan_spec st_press_1_channels[] = { 140static const struct iio_chan_spec st_press_1_channels[] = {
121 { 141 {
122 .type = IIO_PRESSURE, 142 .type = IIO_PRESSURE,
@@ -189,6 +209,27 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
189 IIO_CHAN_SOFT_TIMESTAMP(1) 209 IIO_CHAN_SOFT_TIMESTAMP(1)
190}; 210};
191 211
212static const struct iio_chan_spec st_press_lps22hb_channels[] = {
213 {
214 .type = IIO_PRESSURE,
215 .channel2 = IIO_NO_MOD,
216 .address = ST_PRESS_1_OUT_XL_ADDR,
217 .scan_index = 0,
218 .scan_type = {
219 .sign = 'u',
220 .realbits = 24,
221 .storagebits = 24,
222 .endianness = IIO_LE,
223 },
224 .info_mask_separate =
225 BIT(IIO_CHAN_INFO_RAW) |
226 BIT(IIO_CHAN_INFO_SCALE),
227 .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
228 .modified = 0,
229 },
230 IIO_CHAN_SOFT_TIMESTAMP(1)
231};
232
192static const struct st_sensor_settings st_press_sensors_settings[] = { 233static const struct st_sensor_settings st_press_sensors_settings[] = {
193 { 234 {
194 .wai = ST_PRESS_LPS331AP_WAI_EXP, 235 .wai = ST_PRESS_LPS331AP_WAI_EXP,
@@ -346,6 +387,51 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
346 .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT, 387 .multi_read_bit = ST_PRESS_LPS25H_MULTIREAD_BIT,
347 .bootime = 2, 388 .bootime = 2,
348 }, 389 },
390 {
391 .wai = ST_PRESS_LPS22HB_WAI_EXP,
392 .wai_addr = ST_SENSORS_DEFAULT_WAI_ADDRESS,
393 .sensors_supported = {
394 [0] = LPS22HB_PRESS_DEV_NAME,
395 },
396 .ch = (struct iio_chan_spec *)st_press_lps22hb_channels,
397 .num_ch = ARRAY_SIZE(st_press_lps22hb_channels),
398 .odr = {
399 .addr = ST_PRESS_LPS22HB_ODR_ADDR,
400 .mask = ST_PRESS_LPS22HB_ODR_MASK,
401 .odr_avl = {
402 { 1, ST_PRESS_LPS22HB_ODR_AVL_1HZ_VAL, },
403 { 10, ST_PRESS_LPS22HB_ODR_AVL_10HZ_VAL, },
404 { 25, ST_PRESS_LPS22HB_ODR_AVL_25HZ_VAL, },
405 { 50, ST_PRESS_LPS22HB_ODR_AVL_50HZ_VAL, },
406 { 75, ST_PRESS_LPS22HB_ODR_AVL_75HZ_VAL, },
407 },
408 },
409 .pw = {
410 .addr = ST_PRESS_LPS22HB_PW_ADDR,
411 .mask = ST_PRESS_LPS22HB_PW_MASK,
412 .value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
413 },
414 .fs = {
415 .fs_avl = {
416 [0] = {
417 .num = ST_PRESS_FS_AVL_1260MB,
418 .gain = ST_PRESS_KPASCAL_NANO_SCALE,
419 },
420 },
421 },
422 .bdu = {
423 .addr = ST_PRESS_LPS22HB_BDU_ADDR,
424 .mask = ST_PRESS_LPS22HB_BDU_MASK,
425 },
426 .drdy_irq = {
427 .addr = ST_PRESS_LPS22HB_DRDY_IRQ_ADDR,
428 .mask_int1 = ST_PRESS_LPS22HB_DRDY_IRQ_INT1_MASK,
429 .mask_int2 = ST_PRESS_LPS22HB_DRDY_IRQ_INT2_MASK,
430 .addr_ihl = ST_PRESS_LPS22HB_IHL_IRQ_ADDR,
431 .mask_ihl = ST_PRESS_LPS22HB_IHL_IRQ_MASK,
432 },
433 .multi_read_bit = ST_PRESS_LPS22HB_MULTIREAD_BIT,
434 },
349}; 435};
350 436
351static int st_press_write_raw(struct iio_dev *indio_dev, 437static int st_press_write_raw(struct iio_dev *indio_dev,
@@ -462,23 +548,24 @@ int st_press_common_probe(struct iio_dev *indio_dev)
462 indio_dev->info = &press_info; 548 indio_dev->info = &press_info;
463 mutex_init(&press_data->tb.buf_lock); 549 mutex_init(&press_data->tb.buf_lock);
464 550
465 st_sensors_power_enable(indio_dev); 551 err = st_sensors_power_enable(indio_dev);
552 if (err)
553 return err;
466 554
467 err = st_sensors_check_device_support(indio_dev, 555 err = st_sensors_check_device_support(indio_dev,
468 ARRAY_SIZE(st_press_sensors_settings), 556 ARRAY_SIZE(st_press_sensors_settings),
469 st_press_sensors_settings); 557 st_press_sensors_settings);
470 if (err < 0) 558 if (err < 0)
471 return err; 559 goto st_press_power_off;
472 560
473 press_data->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS; 561 press_data->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS;
474 press_data->multiread_bit = press_data->sensor_settings->multi_read_bit; 562 press_data->multiread_bit = press_data->sensor_settings->multi_read_bit;
475 indio_dev->channels = press_data->sensor_settings->ch; 563 indio_dev->channels = press_data->sensor_settings->ch;
476 indio_dev->num_channels = press_data->sensor_settings->num_ch; 564 indio_dev->num_channels = press_data->sensor_settings->num_ch;
477 565
478 if (press_data->sensor_settings->fs.addr != 0) 566 press_data->current_fullscale =
479 press_data->current_fullscale = 567 (struct st_sensor_fullscale_avl *)
480 (struct st_sensor_fullscale_avl *) 568 &press_data->sensor_settings->fs.fs_avl[0];
481 &press_data->sensor_settings->fs.fs_avl[0];
482 569
483 press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz; 570 press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz;
484 571
@@ -490,11 +577,11 @@ int st_press_common_probe(struct iio_dev *indio_dev)
490 577
491 err = st_sensors_init_sensor(indio_dev, press_data->dev->platform_data); 578 err = st_sensors_init_sensor(indio_dev, press_data->dev->platform_data);
492 if (err < 0) 579 if (err < 0)
493 return err; 580 goto st_press_power_off;
494 581
495 err = st_press_allocate_ring(indio_dev); 582 err = st_press_allocate_ring(indio_dev);
496 if (err < 0) 583 if (err < 0)
497 return err; 584 goto st_press_power_off;
498 585
499 if (irq > 0) { 586 if (irq > 0) {
500 err = st_sensors_allocate_trigger(indio_dev, 587 err = st_sensors_allocate_trigger(indio_dev,
@@ -517,6 +604,8 @@ st_press_device_register_error:
517 st_sensors_deallocate_trigger(indio_dev); 604 st_sensors_deallocate_trigger(indio_dev);
518st_press_probe_trigger_error: 605st_press_probe_trigger_error:
519 st_press_deallocate_ring(indio_dev); 606 st_press_deallocate_ring(indio_dev);
607st_press_power_off:
608 st_sensors_power_disable(indio_dev);
520 609
521 return err; 610 return err;
522} 611}
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index 8fcf9766eaec..ed18701c68c9 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -32,6 +32,10 @@ static const struct of_device_id st_press_of_match[] = {
32 .compatible = "st,lps331ap-press", 32 .compatible = "st,lps331ap-press",
33 .data = LPS331AP_PRESS_DEV_NAME, 33 .data = LPS331AP_PRESS_DEV_NAME,
34 }, 34 },
35 {
36 .compatible = "st,lps22hb-press",
37 .data = LPS22HB_PRESS_DEV_NAME,
38 },
35 {}, 39 {},
36}; 40};
37MODULE_DEVICE_TABLE(of, st_press_of_match); 41MODULE_DEVICE_TABLE(of, st_press_of_match);
diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c
index 40c0692ff1de..550508025af1 100644
--- a/drivers/iio/pressure/st_pressure_spi.c
+++ b/drivers/iio/pressure/st_pressure_spi.c
@@ -50,6 +50,7 @@ static const struct spi_device_id st_press_id_table[] = {
50 { LPS001WP_PRESS_DEV_NAME }, 50 { LPS001WP_PRESS_DEV_NAME },
51 { LPS25H_PRESS_DEV_NAME }, 51 { LPS25H_PRESS_DEV_NAME },
52 { LPS331AP_PRESS_DEV_NAME }, 52 { LPS331AP_PRESS_DEV_NAME },
53 { LPS22HB_PRESS_DEV_NAME },
53 {}, 54 {},
54}; 55};
55MODULE_DEVICE_TABLE(spi, st_press_id_table); 56MODULE_DEVICE_TABLE(spi, st_press_id_table);
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index e2f926cdcad2..9aa2ce551ba8 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -468,4 +468,3 @@ module_spi_driver(as3935_driver);
468MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>"); 468MODULE_AUTHOR("Matt Ranostay <mranostay@gmail.com>");
469MODULE_DESCRIPTION("AS3935 lightning sensor"); 469MODULE_DESCRIPTION("AS3935 lightning sensor");
470MODULE_LICENSE("GPL"); 470MODULE_LICENSE("GPL");
471MODULE_ALIAS("spi:as3935");
diff --git a/drivers/iio/temperature/tsys02d.c b/drivers/iio/temperature/tsys02d.c
index ab6fe8f6f2d1..c0a19a000387 100644
--- a/drivers/iio/temperature/tsys02d.c
+++ b/drivers/iio/temperature/tsys02d.c
@@ -174,6 +174,7 @@ static const struct i2c_device_id tsys02d_id[] = {
174 {"tsys02d", 0}, 174 {"tsys02d", 0},
175 {} 175 {}
176}; 176};
177MODULE_DEVICE_TABLE(i2c, tsys02d_id);
177 178
178static struct i2c_driver tsys02d_driver = { 179static struct i2c_driver tsys02d_driver = {
179 .probe = tsys02d_probe, 180 .probe = tsys02d_probe,
diff --git a/drivers/iio/trigger/Kconfig b/drivers/iio/trigger/Kconfig
index 519e6772f6f5..809b2e7d58fa 100644
--- a/drivers/iio/trigger/Kconfig
+++ b/drivers/iio/trigger/Kconfig
@@ -24,6 +24,18 @@ 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_TIGHTLOOP_TRIGGER
28 tristate "A kthread based hammering loop trigger"
29 depends on IIO_SW_TRIGGER
30 help
31 An experimental trigger, used to allow sensors to be sampled as fast
32 as possible under the limitations of whatever else is going on.
33 Uses a tight loop in a kthread. Will only work with lower half only
34 trigger consumers.
35
36 To compile this driver as a module, choose M here: the
37 module will be called iio-trig-loop.
38
27config IIO_SYSFS_TRIGGER 39config IIO_SYSFS_TRIGGER
28 tristate "SYSFS trigger" 40 tristate "SYSFS trigger"
29 depends on SYSFS 41 depends on SYSFS
diff --git a/drivers/iio/trigger/Makefile b/drivers/iio/trigger/Makefile
index fe06eb564367..aab4dc23303d 100644
--- a/drivers/iio/trigger/Makefile
+++ b/drivers/iio/trigger/Makefile
@@ -7,3 +7,4 @@
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_SYSFS_TRIGGER) += iio-trig-sysfs.o 9obj-$(CONFIG_IIO_SYSFS_TRIGGER) += iio-trig-sysfs.o
10obj-$(CONFIG_IIO_TIGHTLOOP_TRIGGER) += iio-trig-loop.o
diff --git a/drivers/iio/trigger/iio-trig-loop.c b/drivers/iio/trigger/iio-trig-loop.c
new file mode 100644
index 000000000000..dc6be28f96fe
--- /dev/null
+++ b/drivers/iio/trigger/iio-trig-loop.c
@@ -0,0 +1,143 @@
1/*
2 * Copyright 2016 Jonathan Cameron <jic23@kernel.org>
3 *
4 * Licensed under the GPL-2.
5 *
6 * Based on a mashup of the hrtimer trigger and continuous sampling proposal of
7 * Gregor Boirie <gregor.boirie@parrot.com>
8 *
9 * Note this is still rather experimental and may eat babies.
10 *
11 * Todo
12 * * Protect against connection of devices that 'need' the top half
13 * handler.
14 * * Work out how to run top half handlers in this context if it is
15 * safe to do so (timestamp grabbing for example)
16 *
17 * Tested against a max1363. Used about 33% cpu for the thread and 20%
18 * for generic_buffer piping to /dev/null. Watermark set at 64 on a 128
19 * element kfifo buffer.
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/slab.h>
26#include <linux/irq_work.h>
27#include <linux/kthread.h>
28#include <linux/freezer.h>
29
30#include <linux/iio/iio.h>
31#include <linux/iio/trigger.h>
32#include <linux/iio/sw_trigger.h>
33
34struct iio_loop_info {
35 struct iio_sw_trigger swt;
36 struct task_struct *task;
37};
38
39static struct config_item_type iio_loop_type = {
40 .ct_owner = THIS_MODULE,
41};
42
43static int iio_loop_thread(void *data)
44{
45 struct iio_trigger *trig = data;
46
47 set_freezable();
48
49 do {
50 iio_trigger_poll_chained(trig);
51 } while (likely(!kthread_freezable_should_stop(NULL)));
52
53 return 0;
54}
55
56static int iio_loop_trigger_set_state(struct iio_trigger *trig, bool state)
57{
58 struct iio_loop_info *loop_trig = iio_trigger_get_drvdata(trig);
59
60 if (state) {
61 loop_trig->task = kthread_run(iio_loop_thread,
62 trig, trig->name);
63 if (unlikely(IS_ERR(loop_trig->task))) {
64 dev_err(&trig->dev,
65 "failed to create trigger loop thread\n");
66 return PTR_ERR(loop_trig->task);
67 }
68 } else {
69 kthread_stop(loop_trig->task);
70 }
71
72 return 0;
73}
74
75static const struct iio_trigger_ops iio_loop_trigger_ops = {
76 .set_trigger_state = iio_loop_trigger_set_state,
77 .owner = THIS_MODULE,
78};
79
80static struct iio_sw_trigger *iio_trig_loop_probe(const char *name)
81{
82 struct iio_loop_info *trig_info;
83 int ret;
84
85 trig_info = kzalloc(sizeof(*trig_info), GFP_KERNEL);
86 if (!trig_info)
87 return ERR_PTR(-ENOMEM);
88
89 trig_info->swt.trigger = iio_trigger_alloc("%s", name);
90 if (!trig_info->swt.trigger) {
91 ret = -ENOMEM;
92 goto err_free_trig_info;
93 }
94
95 iio_trigger_set_drvdata(trig_info->swt.trigger, trig_info);
96 trig_info->swt.trigger->ops = &iio_loop_trigger_ops;
97
98 ret = iio_trigger_register(trig_info->swt.trigger);
99 if (ret)
100 goto err_free_trigger;
101
102 iio_swt_group_init_type_name(&trig_info->swt, name, &iio_loop_type);
103
104 return &trig_info->swt;
105
106err_free_trigger:
107 iio_trigger_free(trig_info->swt.trigger);
108err_free_trig_info:
109 kfree(trig_info);
110
111 return ERR_PTR(ret);
112}
113
114static int iio_trig_loop_remove(struct iio_sw_trigger *swt)
115{
116 struct iio_loop_info *trig_info;
117
118 trig_info = iio_trigger_get_drvdata(swt->trigger);
119
120 iio_trigger_unregister(swt->trigger);
121 iio_trigger_free(swt->trigger);
122 kfree(trig_info);
123
124 return 0;
125}
126
127static const struct iio_sw_trigger_ops iio_trig_loop_ops = {
128 .probe = iio_trig_loop_probe,
129 .remove = iio_trig_loop_remove,
130};
131
132static struct iio_sw_trigger_type iio_trig_loop = {
133 .name = "loop",
134 .owner = THIS_MODULE,
135 .ops = &iio_trig_loop_ops,
136};
137
138module_iio_sw_trigger_driver(iio_trig_loop);
139
140MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
141MODULE_DESCRIPTION("Loop based trigger for the iio subsystem");
142MODULE_LICENSE("GPL v2");
143MODULE_ALIAS("platform:iio-trig-loop");
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 7c197d1a1231..af9476460023 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -102,4 +102,6 @@ source "drivers/staging/most/Kconfig"
102 102
103source "drivers/staging/i4l/Kconfig" 103source "drivers/staging/i4l/Kconfig"
104 104
105source "drivers/staging/ks7010/Kconfig"
106
105endif # STAGING 107endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index a470c7276142..9f6009dcafa8 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -40,3 +40,4 @@ obj-$(CONFIG_FSL_MC_BUS) += fsl-mc/
40obj-$(CONFIG_WILC1000) += wilc1000/ 40obj-$(CONFIG_WILC1000) += wilc1000/
41obj-$(CONFIG_MOST) += most/ 41obj-$(CONFIG_MOST) += most/
42obj-$(CONFIG_ISDN_I4L) += i4l/ 42obj-$(CONFIG_ISDN_I4L) += i4l/
43obj-$(CONFIG_KS7010) += ks7010/
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 6480f60ebf6c..06e41d24ec62 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -24,26 +24,19 @@ config ANDROID_LOW_MEMORY_KILLER
24 scripts (/init.rc), and it defines priority values with minimum free memory size 24 scripts (/init.rc), and it defines priority values with minimum free memory size
25 for each priority. 25 for each priority.
26 26
27config SYNC
28 bool "Synchronization framework"
29 default n
30 select ANON_INODES
31 select DMA_SHARED_BUFFER
32 ---help---
33 This option enables the framework for synchronization between multiple
34 drivers. Sync implementations can take advantage of hardware
35 synchronization built into devices like GPUs.
36
37config SW_SYNC 27config SW_SYNC
38 bool "Software synchronization objects" 28 bool "Software synchronization framework"
39 default n 29 default n
40 depends on SYNC
41 depends on SYNC_FILE 30 depends on SYNC_FILE
31 depends on DEBUG_FS
42 ---help--- 32 ---help---
43 A sync object driver that uses a 32bit counter to coordinate 33 A sync object driver that uses a 32bit counter to coordinate
44 synchronization. Useful when there is no hardware primitive backing 34 synchronization. Useful when there is no hardware primitive backing
45 the synchronization. 35 the synchronization.
46 36
37 WARNING: improper use of this can result in deadlocking kernel
38 drivers from userspace. Intended for test and debug only.
39
47source "drivers/staging/android/ion/Kconfig" 40source "drivers/staging/android/ion/Kconfig"
48 41
49endif # if ANDROID 42endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 980d6dc4b265..7ca61b77a8d4 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -4,5 +4,4 @@ obj-y += ion/
4 4
5obj-$(CONFIG_ASHMEM) += ashmem.o 5obj-$(CONFIG_ASHMEM) += ashmem.o
6obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o 6obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o
7obj-$(CONFIG_SYNC) += sync.o sync_debug.o 7obj-$(CONFIG_SW_SYNC) += sw_sync.o sync_debug.o
8obj-$(CONFIG_SW_SYNC) += sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index af39ff58fa33..115c9174705f 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * drivers/base/sw_sync.c 2 * drivers/dma-buf/sw_sync.c
3 * 3 *
4 * Copyright (C) 2012 Google, Inc. 4 * Copyright (C) 2012 Google, Inc.
5 * 5 *
@@ -14,76 +14,331 @@
14 * 14 *
15 */ 15 */
16 16
17#include <linux/kernel.h>
18#include <linux/init.h>
19#include <linux/export.h>
20#include <linux/file.h> 17#include <linux/file.h>
21#include <linux/fs.h> 18#include <linux/fs.h>
22#include <linux/miscdevice.h>
23#include <linux/syscalls.h>
24#include <linux/uaccess.h> 19#include <linux/uaccess.h>
20#include <linux/slab.h>
21#include <linux/sync_file.h>
25 22
26#include "sw_sync.h" 23#include "sync_debug.h"
27 24
28struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value) 25#define CREATE_TRACE_POINTS
26#include "trace/sync.h"
27
28struct sw_sync_create_fence_data {
29 __u32 value;
30 char name[32];
31 __s32 fence; /* fd of new fence */
32};
33
34#define SW_SYNC_IOC_MAGIC 'W'
35
36#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\
37 struct sw_sync_create_fence_data)
38#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32)
39
40static const struct fence_ops timeline_fence_ops;
41
42static inline struct sync_pt *fence_to_sync_pt(struct fence *fence)
43{
44 if (fence->ops != &timeline_fence_ops)
45 return NULL;
46 return container_of(fence, struct sync_pt, base);
47}
48
49/**
50 * sync_timeline_create() - creates a sync object
51 * @name: sync_timeline name
52 *
53 * Creates a new sync_timeline. Returns the sync_timeline object or NULL in
54 * case of error.
55 */
56struct sync_timeline *sync_timeline_create(const char *name)
57{
58 struct sync_timeline *obj;
59
60 obj = kzalloc(sizeof(*obj), GFP_KERNEL);
61 if (!obj)
62 return NULL;
63
64 kref_init(&obj->kref);
65 obj->context = fence_context_alloc(1);
66 strlcpy(obj->name, name, sizeof(obj->name));
67
68 INIT_LIST_HEAD(&obj->child_list_head);
69 INIT_LIST_HEAD(&obj->active_list_head);
70 spin_lock_init(&obj->child_list_lock);
71
72 sync_timeline_debug_add(obj);
73
74 return obj;
75}
76
77static void sync_timeline_free(struct kref *kref)
78{
79 struct sync_timeline *obj =
80 container_of(kref, struct sync_timeline, kref);
81
82 sync_timeline_debug_remove(obj);
83
84 kfree(obj);
85}
86
87static void sync_timeline_get(struct sync_timeline *obj)
88{
89 kref_get(&obj->kref);
90}
91
92static void sync_timeline_put(struct sync_timeline *obj)
93{
94 kref_put(&obj->kref, sync_timeline_free);
95}
96
97/**
98 * sync_timeline_signal() - signal a status change on a sync_timeline
99 * @obj: sync_timeline to signal
100 * @inc: num to increment on timeline->value
101 *
102 * A sync implementation should call this any time one of it's fences
103 * has signaled or has an error condition.
104 */
105static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
106{
107 unsigned long flags;
108 struct sync_pt *pt, *next;
109
110 trace_sync_timeline(obj);
111
112 spin_lock_irqsave(&obj->child_list_lock, flags);
113
114 obj->value += inc;
115
116 list_for_each_entry_safe(pt, next, &obj->active_list_head,
117 active_list) {
118 if (fence_is_signaled_locked(&pt->base))
119 list_del_init(&pt->active_list);
120 }
121
122 spin_unlock_irqrestore(&obj->child_list_lock, flags);
123}
124
125/**
126 * sync_pt_create() - creates a sync pt
127 * @parent: fence's parent sync_timeline
128 * @size: size to allocate for this pt
129 * @inc: value of the fence
130 *
131 * Creates a new sync_pt as a child of @parent. @size bytes will be
132 * allocated allowing for implementation specific data to be kept after
133 * the generic sync_timeline struct. Returns the sync_pt object or
134 * NULL in case of error.
135 */
136static struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size,
137 unsigned int value)
138{
139 unsigned long flags;
140 struct sync_pt *pt;
141
142 if (size < sizeof(*pt))
143 return NULL;
144
145 pt = kzalloc(size, GFP_KERNEL);
146 if (!pt)
147 return NULL;
148
149 spin_lock_irqsave(&obj->child_list_lock, flags);
150 sync_timeline_get(obj);
151 fence_init(&pt->base, &timeline_fence_ops, &obj->child_list_lock,
152 obj->context, value);
153 list_add_tail(&pt->child_list, &obj->child_list_head);
154 INIT_LIST_HEAD(&pt->active_list);
155 spin_unlock_irqrestore(&obj->child_list_lock, flags);
156 return pt;
157}
158
159static const char *timeline_fence_get_driver_name(struct fence *fence)
160{
161 return "sw_sync";
162}
163
164static const char *timeline_fence_get_timeline_name(struct fence *fence)
165{
166 struct sync_timeline *parent = fence_parent(fence);
167
168 return parent->name;
169}
170
171static void timeline_fence_release(struct fence *fence)
29{ 172{
30 struct sw_sync_pt *pt; 173 struct sync_pt *pt = fence_to_sync_pt(fence);
174 struct sync_timeline *parent = fence_parent(fence);
175 unsigned long flags;
31 176
32 pt = (struct sw_sync_pt *) 177 spin_lock_irqsave(fence->lock, flags);
33 sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt)); 178 list_del(&pt->child_list);
179 if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
180 list_del(&pt->active_list);
181 spin_unlock_irqrestore(fence->lock, flags);
34 182
35 pt->value = value; 183 sync_timeline_put(parent);
184 fence_free(fence);
185}
186
187static bool timeline_fence_signaled(struct fence *fence)
188{
189 struct sync_timeline *parent = fence_parent(fence);
36 190
37 return (struct fence *)pt; 191 return (fence->seqno > parent->value) ? false : true;
38} 192}
39EXPORT_SYMBOL(sw_sync_pt_create);
40 193
41static int sw_sync_fence_has_signaled(struct fence *fence) 194static bool timeline_fence_enable_signaling(struct fence *fence)
42{ 195{
43 struct sw_sync_pt *pt = (struct sw_sync_pt *)fence; 196 struct sync_pt *pt = fence_to_sync_pt(fence);
44 struct sw_sync_timeline *obj = 197 struct sync_timeline *parent = fence_parent(fence);
45 (struct sw_sync_timeline *)fence_parent(fence);
46 198
47 return (pt->value > obj->value) ? 0 : 1; 199 if (timeline_fence_signaled(fence))
200 return false;
201
202 list_add_tail(&pt->active_list, &parent->active_list_head);
203 return true;
48} 204}
49 205
50static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline, 206static void timeline_fence_value_str(struct fence *fence,
51 char *str, int size) 207 char *str, int size)
52{ 208{
53 struct sw_sync_timeline *timeline = 209 snprintf(str, size, "%d", fence->seqno);
54 (struct sw_sync_timeline *)sync_timeline;
55 snprintf(str, size, "%d", timeline->value);
56} 210}
57 211
58static void sw_sync_fence_value_str(struct fence *fence, char *str, int size) 212static void timeline_fence_timeline_value_str(struct fence *fence,
213 char *str, int size)
59{ 214{
60 struct sw_sync_pt *pt = (struct sw_sync_pt *)fence; 215 struct sync_timeline *parent = fence_parent(fence);
61 216
62 snprintf(str, size, "%d", pt->value); 217 snprintf(str, size, "%d", parent->value);
63} 218}
64 219
65static struct sync_timeline_ops sw_sync_timeline_ops = { 220static const struct fence_ops timeline_fence_ops = {
66 .driver_name = "sw_sync", 221 .get_driver_name = timeline_fence_get_driver_name,
67 .has_signaled = sw_sync_fence_has_signaled, 222 .get_timeline_name = timeline_fence_get_timeline_name,
68 .timeline_value_str = sw_sync_timeline_value_str, 223 .enable_signaling = timeline_fence_enable_signaling,
69 .fence_value_str = sw_sync_fence_value_str, 224 .signaled = timeline_fence_signaled,
225 .wait = fence_default_wait,
226 .release = timeline_fence_release,
227 .fence_value_str = timeline_fence_value_str,
228 .timeline_value_str = timeline_fence_timeline_value_str,
70}; 229};
71 230
72struct sw_sync_timeline *sw_sync_timeline_create(const char *name) 231/*
232 * *WARNING*
233 *
234 * improper use of this can result in deadlocking kernel drivers from userspace.
235 */
236
237/* opening sw_sync create a new sync obj */
238static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
73{ 239{
74 struct sw_sync_timeline *obj = (struct sw_sync_timeline *) 240 struct sync_timeline *obj;
75 sync_timeline_create(&sw_sync_timeline_ops, 241 char task_comm[TASK_COMM_LEN];
76 sizeof(struct sw_sync_timeline),
77 name);
78 242
79 return obj; 243 get_task_comm(task_comm, current);
244
245 obj = sync_timeline_create(task_comm);
246 if (!obj)
247 return -ENOMEM;
248
249 file->private_data = obj;
250
251 return 0;
80} 252}
81EXPORT_SYMBOL(sw_sync_timeline_create);
82 253
83void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc) 254static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
84{ 255{
85 obj->value += inc; 256 struct sync_timeline *obj = file->private_data;
257
258 smp_wmb();
259
260 sync_timeline_put(obj);
261 return 0;
262}
263
264static long sw_sync_ioctl_create_fence(struct sync_timeline *obj,
265 unsigned long arg)
266{
267 int fd = get_unused_fd_flags(O_CLOEXEC);
268 int err;
269 struct sync_pt *pt;
270 struct sync_file *sync_file;
271 struct sw_sync_create_fence_data data;
272
273 if (fd < 0)
274 return fd;
275
276 if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
277 err = -EFAULT;
278 goto err;
279 }
280
281 pt = sync_pt_create(obj, sizeof(*pt), data.value);
282 if (!pt) {
283 err = -ENOMEM;
284 goto err;
285 }
286
287 sync_file = sync_file_create(&pt->base);
288 if (!sync_file) {
289 fence_put(&pt->base);
290 err = -ENOMEM;
291 goto err;
292 }
293
294 data.fence = fd;
295 if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
296 fput(sync_file->file);
297 err = -EFAULT;
298 goto err;
299 }
300
301 fd_install(fd, sync_file->file);
302
303 return 0;
304
305err:
306 put_unused_fd(fd);
307 return err;
308}
86 309
87 sync_timeline_signal(&obj->obj); 310static long sw_sync_ioctl_inc(struct sync_timeline *obj, unsigned long arg)
311{
312 u32 value;
313
314 if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
315 return -EFAULT;
316
317 sync_timeline_signal(obj, value);
318
319 return 0;
320}
321
322static long sw_sync_ioctl(struct file *file, unsigned int cmd,
323 unsigned long arg)
324{
325 struct sync_timeline *obj = file->private_data;
326
327 switch (cmd) {
328 case SW_SYNC_IOC_CREATE_FENCE:
329 return sw_sync_ioctl_create_fence(obj, arg);
330
331 case SW_SYNC_IOC_INC:
332 return sw_sync_ioctl_inc(obj, arg);
333
334 default:
335 return -ENOTTY;
336 }
88} 337}
89EXPORT_SYMBOL(sw_sync_timeline_inc); 338
339const struct file_operations sw_sync_debugfs_fops = {
340 .open = sw_sync_debugfs_open,
341 .release = sw_sync_debugfs_release,
342 .unlocked_ioctl = sw_sync_ioctl,
343 .compat_ioctl = sw_sync_ioctl,
344};
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
deleted file mode 100644
index e18667bfb0ca..000000000000
--- a/drivers/staging/android/sw_sync.h
+++ /dev/null
@@ -1,59 +0,0 @@
1/*
2 * include/linux/sw_sync.h
3 *
4 * Copyright (C) 2012 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
17#ifndef _LINUX_SW_SYNC_H
18#define _LINUX_SW_SYNC_H
19
20#include <linux/types.h>
21#include <linux/kconfig.h>
22#include "sync.h"
23#include "uapi/sw_sync.h"
24
25struct sw_sync_timeline {
26 struct sync_timeline obj;
27
28 u32 value;
29};
30
31struct sw_sync_pt {
32 struct fence pt;
33
34 u32 value;
35};
36
37#if IS_ENABLED(CONFIG_SW_SYNC)
38struct sw_sync_timeline *sw_sync_timeline_create(const char *name);
39void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
40
41struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value);
42#else
43static inline struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
44{
45 return NULL;
46}
47
48static inline void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
49{
50}
51
52static inline struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj,
53 u32 value)
54{
55 return NULL;
56}
57#endif /* IS_ENABLED(CONFIG_SW_SYNC) */
58
59#endif /* _LINUX_SW_SYNC_H */
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
deleted file mode 100644
index 1d14c83c7f7c..000000000000
--- a/drivers/staging/android/sync.c
+++ /dev/null
@@ -1,221 +0,0 @@
1/*
2 * drivers/base/sync.c
3 *
4 * Copyright (C) 2012 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
17#include <linux/debugfs.h>
18#include <linux/export.h>
19#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/seq_file.h>
22#include <linux/slab.h>
23#include <linux/uaccess.h>
24#include <linux/anon_inodes.h>
25
26#include "sync.h"
27
28#define CREATE_TRACE_POINTS
29#include "trace/sync.h"
30
31static const struct fence_ops android_fence_ops;
32
33struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
34 int size, const char *name)
35{
36 struct sync_timeline *obj;
37
38 if (size < sizeof(struct sync_timeline))
39 return NULL;
40
41 obj = kzalloc(size, GFP_KERNEL);
42 if (!obj)
43 return NULL;
44
45 kref_init(&obj->kref);
46 obj->ops = ops;
47 obj->context = fence_context_alloc(1);
48 strlcpy(obj->name, name, sizeof(obj->name));
49
50 INIT_LIST_HEAD(&obj->child_list_head);
51 INIT_LIST_HEAD(&obj->active_list_head);
52 spin_lock_init(&obj->child_list_lock);
53
54 sync_timeline_debug_add(obj);
55
56 return obj;
57}
58EXPORT_SYMBOL(sync_timeline_create);
59
60static void sync_timeline_free(struct kref *kref)
61{
62 struct sync_timeline *obj =
63 container_of(kref, struct sync_timeline, kref);
64
65 sync_timeline_debug_remove(obj);
66
67 kfree(obj);
68}
69
70static void sync_timeline_get(struct sync_timeline *obj)
71{
72 kref_get(&obj->kref);
73}
74
75static void sync_timeline_put(struct sync_timeline *obj)
76{
77 kref_put(&obj->kref, sync_timeline_free);
78}
79
80void sync_timeline_destroy(struct sync_timeline *obj)
81{
82 obj->destroyed = true;
83 /*
84 * Ensure timeline is marked as destroyed before
85 * changing timeline's fences status.
86 */
87 smp_wmb();
88
89 sync_timeline_put(obj);
90}
91EXPORT_SYMBOL(sync_timeline_destroy);
92
93void sync_timeline_signal(struct sync_timeline *obj)
94{
95 unsigned long flags;
96 struct fence *fence, *next;
97
98 trace_sync_timeline(obj);
99
100 spin_lock_irqsave(&obj->child_list_lock, flags);
101
102 list_for_each_entry_safe(fence, next, &obj->active_list_head,
103 active_list) {
104 if (fence_is_signaled_locked(fence))
105 list_del_init(&fence->active_list);
106 }
107
108 spin_unlock_irqrestore(&obj->child_list_lock, flags);
109}
110EXPORT_SYMBOL(sync_timeline_signal);
111
112struct fence *sync_pt_create(struct sync_timeline *obj, int size)
113{
114 unsigned long flags;
115 struct fence *fence;
116
117 if (size < sizeof(*fence))
118 return NULL;
119
120 fence = kzalloc(size, GFP_KERNEL);
121 if (!fence)
122 return NULL;
123
124 spin_lock_irqsave(&obj->child_list_lock, flags);
125 sync_timeline_get(obj);
126 fence_init(fence, &android_fence_ops, &obj->child_list_lock,
127 obj->context, ++obj->value);
128 list_add_tail(&fence->child_list, &obj->child_list_head);
129 INIT_LIST_HEAD(&fence->active_list);
130 spin_unlock_irqrestore(&obj->child_list_lock, flags);
131 return fence;
132}
133EXPORT_SYMBOL(sync_pt_create);
134
135static const char *android_fence_get_driver_name(struct fence *fence)
136{
137 struct sync_timeline *parent = fence_parent(fence);
138
139 return parent->ops->driver_name;
140}
141
142static const char *android_fence_get_timeline_name(struct fence *fence)
143{
144 struct sync_timeline *parent = fence_parent(fence);
145
146 return parent->name;
147}
148
149static void android_fence_release(struct fence *fence)
150{
151 struct sync_timeline *parent = fence_parent(fence);
152 unsigned long flags;
153
154 spin_lock_irqsave(fence->lock, flags);
155 list_del(&fence->child_list);
156 if (WARN_ON_ONCE(!list_empty(&fence->active_list)))
157 list_del(&fence->active_list);
158 spin_unlock_irqrestore(fence->lock, flags);
159
160 sync_timeline_put(parent);
161 fence_free(fence);
162}
163
164static bool android_fence_signaled(struct fence *fence)
165{
166 struct sync_timeline *parent = fence_parent(fence);
167 int ret;
168
169 ret = parent->ops->has_signaled(fence);
170 if (ret < 0)
171 fence->status = ret;
172 return ret;
173}
174
175static bool android_fence_enable_signaling(struct fence *fence)
176{
177 struct sync_timeline *parent = fence_parent(fence);
178
179 if (android_fence_signaled(fence))
180 return false;
181
182 list_add_tail(&fence->active_list, &parent->active_list_head);
183 return true;
184}
185
186static void android_fence_value_str(struct fence *fence,
187 char *str, int size)
188{
189 struct sync_timeline *parent = fence_parent(fence);
190
191 if (!parent->ops->fence_value_str) {
192 if (size)
193 *str = 0;
194 return;
195 }
196 parent->ops->fence_value_str(fence, str, size);
197}
198
199static void android_fence_timeline_value_str(struct fence *fence,
200 char *str, int size)
201{
202 struct sync_timeline *parent = fence_parent(fence);
203
204 if (!parent->ops->timeline_value_str) {
205 if (size)
206 *str = 0;
207 return;
208 }
209 parent->ops->timeline_value_str(parent, str, size);
210}
211
212static const struct fence_ops android_fence_ops = {
213 .get_driver_name = android_fence_get_driver_name,
214 .get_timeline_name = android_fence_get_timeline_name,
215 .enable_signaling = android_fence_enable_signaling,
216 .signaled = android_fence_signaled,
217 .wait = fence_default_wait,
218 .release = android_fence_release,
219 .fence_value_str = android_fence_value_str,
220 .timeline_value_str = android_fence_timeline_value_str,
221};
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
deleted file mode 100644
index b56885c14839..000000000000
--- a/drivers/staging/android/sync.h
+++ /dev/null
@@ -1,154 +0,0 @@
1/*
2 * include/linux/sync.h
3 *
4 * Copyright (C) 2012 Google, Inc.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 */
12
13#ifndef _LINUX_SYNC_H
14#define _LINUX_SYNC_H
15
16#include <linux/types.h>
17#include <linux/kref.h>
18#include <linux/ktime.h>
19#include <linux/list.h>
20#include <linux/spinlock.h>
21#include <linux/fence.h>
22
23#include <linux/sync_file.h>
24#include <uapi/linux/sync_file.h>
25
26struct sync_timeline;
27
28/**
29 * struct sync_timeline_ops - sync object implementation ops
30 * @driver_name: name of the implementation
31 * @has_signaled: returns:
32 * 1 if pt has signaled
33 * 0 if pt has not signaled
34 * <0 on error
35 * @timeline_value_str: fill str with the value of the sync_timeline's counter
36 * @fence_value_str: fill str with the value of the fence
37 */
38struct sync_timeline_ops {
39 const char *driver_name;
40
41 /* required */
42 int (*has_signaled)(struct fence *fence);
43
44 /* optional */
45 void (*timeline_value_str)(struct sync_timeline *timeline, char *str,
46 int size);
47
48 /* optional */
49 void (*fence_value_str)(struct fence *fence, char *str, int size);
50};
51
52/**
53 * struct sync_timeline - sync object
54 * @kref: reference count on fence.
55 * @ops: ops that define the implementation of the sync_timeline
56 * @name: name of the sync_timeline. Useful for debugging
57 * @destroyed: set when sync_timeline is destroyed
58 * @child_list_head: list of children sync_pts for this sync_timeline
59 * @child_list_lock: lock protecting @child_list_head, destroyed, and
60 * fence.status
61 * @active_list_head: list of active (unsignaled/errored) sync_pts
62 * @sync_timeline_list: membership in global sync_timeline_list
63 */
64struct sync_timeline {
65 struct kref kref;
66 const struct sync_timeline_ops *ops;
67 char name[32];
68
69 /* protected by child_list_lock */
70 bool destroyed;
71 int context, value;
72
73 struct list_head child_list_head;
74 spinlock_t child_list_lock;
75
76 struct list_head active_list_head;
77
78#ifdef CONFIG_DEBUG_FS
79 struct list_head sync_timeline_list;
80#endif
81};
82
83static inline struct sync_timeline *fence_parent(struct fence *fence)
84{
85 return container_of(fence->lock, struct sync_timeline,
86 child_list_lock);
87}
88
89/*
90 * API for sync_timeline implementers
91 */
92
93/**
94 * sync_timeline_create() - creates a sync object
95 * @ops: specifies the implementation ops for the object
96 * @size: size to allocate for this obj
97 * @name: sync_timeline name
98 *
99 * Creates a new sync_timeline which will use the implementation specified by
100 * @ops. @size bytes will be allocated allowing for implementation specific
101 * data to be kept after the generic sync_timeline struct. Returns the
102 * sync_timeline object or NULL in case of error.
103 */
104struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
105 int size, const char *name);
106
107/**
108 * sync_timeline_destroy() - destroys a sync object
109 * @obj: sync_timeline to destroy
110 *
111 * A sync implementation should call this when the @obj is going away
112 * (i.e. module unload.) @obj won't actually be freed until all its children
113 * fences are freed.
114 */
115void sync_timeline_destroy(struct sync_timeline *obj);
116
117/**
118 * sync_timeline_signal() - signal a status change on a sync_timeline
119 * @obj: sync_timeline to signal
120 *
121 * A sync implementation should call this any time one of it's fences
122 * has signaled or has an error condition.
123 */
124void sync_timeline_signal(struct sync_timeline *obj);
125
126/**
127 * sync_pt_create() - creates a sync pt
128 * @parent: fence's parent sync_timeline
129 * @size: size to allocate for this pt
130 *
131 * Creates a new fence as a child of @parent. @size bytes will be
132 * allocated allowing for implementation specific data to be kept after
133 * the generic sync_timeline struct. Returns the fence object or
134 * NULL in case of error.
135 */
136struct fence *sync_pt_create(struct sync_timeline *parent, int size);
137
138#ifdef CONFIG_DEBUG_FS
139
140void sync_timeline_debug_add(struct sync_timeline *obj);
141void sync_timeline_debug_remove(struct sync_timeline *obj);
142void sync_file_debug_add(struct sync_file *fence);
143void sync_file_debug_remove(struct sync_file *fence);
144void sync_dump(void);
145
146#else
147# define sync_timeline_debug_add(obj)
148# define sync_timeline_debug_remove(obj)
149# define sync_file_debug_add(fence)
150# define sync_file_debug_remove(fence)
151# define sync_dump()
152#endif
153
154#endif /* _LINUX_SYNC_H */
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 5f57499c98bf..4c5a85595a85 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -15,21 +15,7 @@
15 */ 15 */
16 16
17#include <linux/debugfs.h> 17#include <linux/debugfs.h>
18#include <linux/export.h> 18#include "sync_debug.h"
19#include <linux/file.h>
20#include <linux/fs.h>
21#include <linux/kernel.h>
22#include <linux/poll.h>
23#include <linux/sched.h>
24#include <linux/seq_file.h>
25#include <linux/slab.h>
26#include <linux/uaccess.h>
27#include <linux/anon_inodes.h>
28#include <linux/time64.h>
29#include <linux/sync_file.h>
30#include "sw_sync.h"
31
32#ifdef CONFIG_DEBUG_FS
33 19
34static struct dentry *dbgfs; 20static struct dentry *dbgfs;
35 21
@@ -105,7 +91,7 @@ static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show)
105 seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec); 91 seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
106 } 92 }
107 93
108 if ((!fence || fence->ops->timeline_value_str) && 94 if (fence->ops->timeline_value_str &&
109 fence->ops->fence_value_str) { 95 fence->ops->fence_value_str) {
110 char value[64]; 96 char value[64];
111 bool success; 97 bool success;
@@ -113,10 +99,9 @@ static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show)
113 fence->ops->fence_value_str(fence, value, sizeof(value)); 99 fence->ops->fence_value_str(fence, value, sizeof(value));
114 success = strlen(value); 100 success = strlen(value);
115 101
116 if (success) 102 if (success) {
117 seq_printf(s, ": %s", value); 103 seq_printf(s, ": %s", value);
118 104
119 if (success && fence) {
120 fence->ops->timeline_value_str(fence, value, 105 fence->ops->timeline_value_str(fence, value,
121 sizeof(value)); 106 sizeof(value));
122 107
@@ -133,22 +118,13 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
133 struct list_head *pos; 118 struct list_head *pos;
134 unsigned long flags; 119 unsigned long flags;
135 120
136 seq_printf(s, "%s %s", obj->name, obj->ops->driver_name); 121 seq_printf(s, "%s: %d\n", obj->name, obj->value);
137
138 if (obj->ops->timeline_value_str) {
139 char value[64];
140
141 obj->ops->timeline_value_str(obj, value, sizeof(value));
142 seq_printf(s, ": %s", value);
143 }
144
145 seq_puts(s, "\n");
146 122
147 spin_lock_irqsave(&obj->child_list_lock, flags); 123 spin_lock_irqsave(&obj->child_list_lock, flags);
148 list_for_each(pos, &obj->child_list_head) { 124 list_for_each(pos, &obj->child_list_head) {
149 struct fence *fence = 125 struct sync_pt *pt =
150 container_of(pos, struct fence, child_list); 126 container_of(pos, struct sync_pt, child_list);
151 sync_print_fence(s, fence, false); 127 sync_print_fence(s, &pt->base, false);
152 } 128 }
153 spin_unlock_irqrestore(&obj->child_list_lock, flags); 129 spin_unlock_irqrestore(&obj->child_list_lock, flags);
154} 130}
@@ -209,126 +185,19 @@ static const struct file_operations sync_info_debugfs_fops = {
209 .release = single_release, 185 .release = single_release,
210}; 186};
211 187
212/*
213 * *WARNING*
214 *
215 * improper use of this can result in deadlocking kernel drivers from userspace.
216 */
217
218/* opening sw_sync create a new sync obj */
219static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
220{
221 struct sw_sync_timeline *obj;
222 char task_comm[TASK_COMM_LEN];
223
224 get_task_comm(task_comm, current);
225
226 obj = sw_sync_timeline_create(task_comm);
227 if (!obj)
228 return -ENOMEM;
229
230 file->private_data = obj;
231
232 return 0;
233}
234
235static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
236{
237 struct sw_sync_timeline *obj = file->private_data;
238
239 sync_timeline_destroy(&obj->obj);
240 return 0;
241}
242
243static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj,
244 unsigned long arg)
245{
246 int fd = get_unused_fd_flags(O_CLOEXEC);
247 int err;
248 struct fence *fence;
249 struct sync_file *sync_file;
250 struct sw_sync_create_fence_data data;
251
252 if (fd < 0)
253 return fd;
254
255 if (copy_from_user(&data, (void __user *)arg, sizeof(data))) {
256 err = -EFAULT;
257 goto err;
258 }
259
260 fence = sw_sync_pt_create(obj, data.value);
261 if (!fence) {
262 err = -ENOMEM;
263 goto err;
264 }
265
266 sync_file = sync_file_create(fence);
267 if (!sync_file) {
268 fence_put(fence);
269 err = -ENOMEM;
270 goto err;
271 }
272
273 data.fence = fd;
274 if (copy_to_user((void __user *)arg, &data, sizeof(data))) {
275 fput(sync_file->file);
276 err = -EFAULT;
277 goto err;
278 }
279
280 fd_install(fd, sync_file->file);
281
282 return 0;
283
284err:
285 put_unused_fd(fd);
286 return err;
287}
288
289static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
290{
291 u32 value;
292
293 if (copy_from_user(&value, (void __user *)arg, sizeof(value)))
294 return -EFAULT;
295
296 sw_sync_timeline_inc(obj, value);
297
298 return 0;
299}
300
301static long sw_sync_ioctl(struct file *file, unsigned int cmd,
302 unsigned long arg)
303{
304 struct sw_sync_timeline *obj = file->private_data;
305
306 switch (cmd) {
307 case SW_SYNC_IOC_CREATE_FENCE:
308 return sw_sync_ioctl_create_fence(obj, arg);
309
310 case SW_SYNC_IOC_INC:
311 return sw_sync_ioctl_inc(obj, arg);
312
313 default:
314 return -ENOTTY;
315 }
316}
317
318static const struct file_operations sw_sync_debugfs_fops = {
319 .open = sw_sync_debugfs_open,
320 .release = sw_sync_debugfs_release,
321 .unlocked_ioctl = sw_sync_ioctl,
322 .compat_ioctl = sw_sync_ioctl,
323};
324
325static __init int sync_debugfs_init(void) 188static __init int sync_debugfs_init(void)
326{ 189{
327 dbgfs = debugfs_create_dir("sync", NULL); 190 dbgfs = debugfs_create_dir("sync", NULL);
328 191
329 debugfs_create_file("info", 0444, dbgfs, NULL, &sync_info_debugfs_fops); 192 /*
330 debugfs_create_file("sw_sync", 0644, dbgfs, NULL, 193 * The debugfs files won't ever get removed and thus, there is
331 &sw_sync_debugfs_fops); 194 * no need to protect it against removal races. The use of
195 * debugfs_create_file_unsafe() is actually safe here.
196 */
197 debugfs_create_file_unsafe("info", 0444, dbgfs, NULL,
198 &sync_info_debugfs_fops);
199 debugfs_create_file_unsafe("sw_sync", 0644, dbgfs, NULL,
200 &sw_sync_debugfs_fops);
332 201
333 return 0; 202 return 0;
334} 203}
@@ -359,5 +228,3 @@ void sync_dump(void)
359 } 228 }
360 } 229 }
361} 230}
362
363#endif
diff --git a/drivers/staging/android/sync_debug.h b/drivers/staging/android/sync_debug.h
new file mode 100644
index 000000000000..425ebc5c32aa
--- /dev/null
+++ b/drivers/staging/android/sync_debug.h
@@ -0,0 +1,83 @@
1/*
2 * include/linux/sync.h
3 *
4 * Copyright (C) 2012 Google, Inc.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 */
12
13#ifndef _LINUX_SYNC_H
14#define _LINUX_SYNC_H
15
16#include <linux/list.h>
17#include <linux/spinlock.h>
18#include <linux/fence.h>
19
20#include <linux/sync_file.h>
21#include <uapi/linux/sync_file.h>
22
23/**
24 * struct sync_timeline - sync object
25 * @kref: reference count on fence.
26 * @name: name of the sync_timeline. Useful for debugging
27 * @child_list_head: list of children sync_pts for this sync_timeline
28 * @child_list_lock: lock protecting @child_list_head and fence.status
29 * @active_list_head: list of active (unsignaled/errored) sync_pts
30 * @sync_timeline_list: membership in global sync_timeline_list
31 */
32struct sync_timeline {
33 struct kref kref;
34 char name[32];
35
36 /* protected by child_list_lock */
37 int context, value;
38
39 struct list_head child_list_head;
40 spinlock_t child_list_lock;
41
42 struct list_head active_list_head;
43
44 struct list_head sync_timeline_list;
45};
46
47static inline struct sync_timeline *fence_parent(struct fence *fence)
48{
49 return container_of(fence->lock, struct sync_timeline,
50 child_list_lock);
51}
52
53/**
54 * struct sync_pt - sync_pt object
55 * @base: base fence object
56 * @child_list: sync timeline child's list
57 * @active_list: sync timeline active child's list
58 */
59struct sync_pt {
60 struct fence base;
61 struct list_head child_list;
62 struct list_head active_list;
63};
64
65#ifdef CONFIG_SW_SYNC
66
67extern const struct file_operations sw_sync_debugfs_fops;
68
69void sync_timeline_debug_add(struct sync_timeline *obj);
70void sync_timeline_debug_remove(struct sync_timeline *obj);
71void sync_file_debug_add(struct sync_file *fence);
72void sync_file_debug_remove(struct sync_file *fence);
73void sync_dump(void);
74
75#else
76# define sync_timeline_debug_add(obj)
77# define sync_timeline_debug_remove(obj)
78# define sync_file_debug_add(fence)
79# define sync_file_debug_remove(fence)
80# define sync_dump()
81#endif
82
83#endif /* _LINUX_SYNC_H */
diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h
index a0f80f41677e..6b5ce9640ddd 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/trace/sync.h
@@ -5,7 +5,7 @@
5#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) 5#if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_SYNC_H 6#define _TRACE_SYNC_H
7 7
8#include "../sync.h" 8#include "../sync_debug.h"
9#include <linux/tracepoint.h> 9#include <linux/tracepoint.h>
10 10
11TRACE_EVENT(sync_timeline, 11TRACE_EVENT(sync_timeline,
@@ -15,21 +15,15 @@ TRACE_EVENT(sync_timeline,
15 15
16 TP_STRUCT__entry( 16 TP_STRUCT__entry(
17 __string(name, timeline->name) 17 __string(name, timeline->name)
18 __array(char, value, 32) 18 __field(u32, value)
19 ), 19 ),
20 20
21 TP_fast_assign( 21 TP_fast_assign(
22 __assign_str(name, timeline->name); 22 __assign_str(name, timeline->name);
23 if (timeline->ops->timeline_value_str) { 23 __entry->value = timeline->value;
24 timeline->ops->timeline_value_str(timeline,
25 __entry->value,
26 sizeof(__entry->value));
27 } else {
28 __entry->value[0] = '\0';
29 }
30 ), 24 ),
31 25
32 TP_printk("name=%s value=%s", __get_str(name), __entry->value) 26 TP_printk("name=%s value=%d", __get_str(name), __entry->value)
33); 27);
34 28
35#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */ 29#endif /* if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ) */
diff --git a/drivers/staging/android/uapi/sw_sync.h b/drivers/staging/android/uapi/sw_sync.h
deleted file mode 100644
index 9b5d4869505c..000000000000
--- a/drivers/staging/android/uapi/sw_sync.h
+++ /dev/null
@@ -1,32 +0,0 @@
1/*
2 * Copyright (C) 2012 Google, Inc.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#ifndef _UAPI_LINUX_SW_SYNC_H
16#define _UAPI_LINUX_SW_SYNC_H
17
18#include <linux/types.h>
19
20struct sw_sync_create_fence_data {
21 __u32 value;
22 char name[32];
23 __s32 fence; /* fd of new fence */
24};
25
26#define SW_SYNC_IOC_MAGIC 'W'
27
28#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\
29 struct sw_sync_create_fence_data)
30#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32)
31
32#endif /* _UAPI_LINUX_SW_SYNC_H */
diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index ad5297f6d418..08fb26b51a5f 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -779,7 +779,7 @@ struct comedi_subdinfo {
779 unsigned int flags; 779 unsigned int flags;
780 unsigned int range_type; 780 unsigned int range_type;
781 unsigned int settling_time_0; 781 unsigned int settling_time_0;
782 unsigned insn_bits_support; 782 unsigned int insn_bits_support;
783 unsigned int unused[8]; 783 unsigned int unused[8];
784}; 784};
785 785
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 629080f39db0..1999eed4f4c5 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -312,8 +312,8 @@ static void comedi_file_reset(struct file *file)
312 } 312 }
313 cfp->last_attached = dev->attached; 313 cfp->last_attached = dev->attached;
314 cfp->last_detach_count = dev->detach_count; 314 cfp->last_detach_count = dev->detach_count;
315 ACCESS_ONCE(cfp->read_subdev) = read_s; 315 WRITE_ONCE(cfp->read_subdev, read_s);
316 ACCESS_ONCE(cfp->write_subdev) = write_s; 316 WRITE_ONCE(cfp->write_subdev, write_s);
317} 317}
318 318
319static void comedi_file_check(struct file *file) 319static void comedi_file_check(struct file *file)
@@ -331,7 +331,7 @@ static struct comedi_subdevice *comedi_file_read_subdevice(struct file *file)
331 struct comedi_file *cfp = file->private_data; 331 struct comedi_file *cfp = file->private_data;
332 332
333 comedi_file_check(file); 333 comedi_file_check(file);
334 return ACCESS_ONCE(cfp->read_subdev); 334 return READ_ONCE(cfp->read_subdev);
335} 335}
336 336
337static struct comedi_subdevice *comedi_file_write_subdevice(struct file *file) 337static struct comedi_subdevice *comedi_file_write_subdevice(struct file *file)
@@ -339,7 +339,7 @@ static struct comedi_subdevice *comedi_file_write_subdevice(struct file *file)
339 struct comedi_file *cfp = file->private_data; 339 struct comedi_file *cfp = file->private_data;
340 340
341 comedi_file_check(file); 341 comedi_file_check(file);
342 return ACCESS_ONCE(cfp->write_subdev); 342 return READ_ONCE(cfp->write_subdev);
343} 343}
344 344
345static int resize_async_buffer(struct comedi_device *dev, 345static int resize_async_buffer(struct comedi_device *dev,
@@ -1256,16 +1256,17 @@ static int parse_insn(struct comedi_device *dev, struct comedi_insn *insn,
1256 switch (insn->insn) { 1256 switch (insn->insn) {
1257 case INSN_GTOD: 1257 case INSN_GTOD:
1258 { 1258 {
1259 struct timeval tv; 1259 struct timespec64 tv;
1260 1260
1261 if (insn->n != 2) { 1261 if (insn->n != 2) {
1262 ret = -EINVAL; 1262 ret = -EINVAL;
1263 break; 1263 break;
1264 } 1264 }
1265 1265
1266 do_gettimeofday(&tv); 1266 ktime_get_real_ts64(&tv);
1267 data[0] = tv.tv_sec; 1267 /* unsigned data safe until 2106 */
1268 data[1] = tv.tv_usec; 1268 data[0] = (unsigned int)tv.tv_sec;
1269 data[1] = tv.tv_nsec / NSEC_PER_USEC;
1269 ret = 2; 1270 ret = 2;
1270 1271
1271 break; 1272 break;
@@ -1992,7 +1993,7 @@ static int do_setrsubd_ioctl(struct comedi_device *dev, unsigned long arg,
1992 !(s_old->async->cmd.flags & CMDF_WRITE)) 1993 !(s_old->async->cmd.flags & CMDF_WRITE))
1993 return -EBUSY; 1994 return -EBUSY;
1994 1995
1995 ACCESS_ONCE(cfp->read_subdev) = s_new; 1996 WRITE_ONCE(cfp->read_subdev, s_new);
1996 return 0; 1997 return 0;
1997} 1998}
1998 1999
@@ -2034,7 +2035,7 @@ static int do_setwsubd_ioctl(struct comedi_device *dev, unsigned long arg,
2034 (s_old->async->cmd.flags & CMDF_WRITE)) 2035 (s_old->async->cmd.flags & CMDF_WRITE))
2035 return -EBUSY; 2036 return -EBUSY;
2036 2037
2037 ACCESS_ONCE(cfp->write_subdev) = s_new; 2038 WRITE_ONCE(cfp->write_subdev, s_new);
2038 return 0; 2039 return 0;
2039} 2040}
2040 2041
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
deleted file mode 100644
index f0c0d58383ca..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
+++ /dev/null
@@ -1,187 +0,0 @@
1static int apci1564_timer_insn_config(struct comedi_device *dev,
2 struct comedi_subdevice *s,
3 struct comedi_insn *insn,
4 unsigned int *data)
5{
6 struct apci1564_private *devpriv = dev->private;
7 unsigned int ctrl;
8
9 devpriv->tsk_current = current;
10
11 /* Stop the timer */
12 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
13 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
14 ADDI_TCW_CTRL_ENA);
15 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
16
17 if (data[1] == 1) {
18 /* Enable timer int & disable all the other int sources */
19 outl(ADDI_TCW_CTRL_IRQ_ENA,
20 devpriv->timer + ADDI_TCW_CTRL_REG);
21 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
22 outl(0x0, dev->iobase + APCI1564_DO_IRQ_REG);
23 outl(0x0, dev->iobase + APCI1564_WDOG_IRQ_REG);
24 if (devpriv->counters) {
25 unsigned long iobase;
26
27 iobase = devpriv->counters + ADDI_TCW_IRQ_REG;
28 outl(0x0, iobase + APCI1564_COUNTER(0));
29 outl(0x0, iobase + APCI1564_COUNTER(1));
30 outl(0x0, iobase + APCI1564_COUNTER(2));
31 }
32 } else {
33 /* disable Timer interrupt */
34 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
35 }
36
37 /* Loading Timebase */
38 outl(data[2], devpriv->timer + ADDI_TCW_TIMEBASE_REG);
39
40 /* Loading the Reload value */
41 outl(data[3], devpriv->timer + ADDI_TCW_RELOAD_REG);
42
43 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
44 ctrl &= ~(ADDI_TCW_CTRL_CNTR_ENA | ADDI_TCW_CTRL_MODE_MASK |
45 ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
46 ADDI_TCW_CTRL_TIMER_ENA | ADDI_TCW_CTRL_RESET_ENA |
47 ADDI_TCW_CTRL_WARN_ENA | ADDI_TCW_CTRL_ENA);
48 ctrl |= ADDI_TCW_CTRL_MODE(2) | ADDI_TCW_CTRL_TIMER_ENA;
49 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
50
51 return insn->n;
52}
53
54static int apci1564_timer_insn_write(struct comedi_device *dev,
55 struct comedi_subdevice *s,
56 struct comedi_insn *insn,
57 unsigned int *data)
58{
59 struct apci1564_private *devpriv = dev->private;
60 unsigned int ctrl;
61
62 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
63 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG);
64 switch (data[1]) {
65 case 0: /* Stop The Timer */
66 ctrl &= ~ADDI_TCW_CTRL_ENA;
67 break;
68 case 1: /* Enable the Timer */
69 ctrl |= ADDI_TCW_CTRL_ENA;
70 break;
71 }
72 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
73
74 return insn->n;
75}
76
77static int apci1564_timer_insn_read(struct comedi_device *dev,
78 struct comedi_subdevice *s,
79 struct comedi_insn *insn,
80 unsigned int *data)
81{
82 struct apci1564_private *devpriv = dev->private;
83
84 /* Stores the status of the Timer */
85 data[0] = inl(devpriv->timer + ADDI_TCW_STATUS_REG) &
86 ADDI_TCW_STATUS_OVERFLOW;
87
88 /* Stores the Actual value of the Timer */
89 data[1] = inl(devpriv->timer + ADDI_TCW_VAL_REG);
90
91 return insn->n;
92}
93
94static int apci1564_counter_insn_config(struct comedi_device *dev,
95 struct comedi_subdevice *s,
96 struct comedi_insn *insn,
97 unsigned int *data)
98{
99 struct apci1564_private *devpriv = dev->private;
100 unsigned int chan = CR_CHAN(insn->chanspec);
101 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
102 unsigned int ctrl;
103
104 devpriv->tsk_current = current;
105
106 /* Stop The Timer */
107 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
108 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG |
109 ADDI_TCW_CTRL_ENA);
110 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
111
112 /* Set the reload value */
113 outl(data[3], iobase + ADDI_TCW_RELOAD_REG);
114
115 /* Set the mode */
116 ctrl &= ~(ADDI_TCW_CTRL_EXT_CLK_MASK | ADDI_TCW_CTRL_MODE_MASK |
117 ADDI_TCW_CTRL_TIMER_ENA | ADDI_TCW_CTRL_RESET_ENA |
118 ADDI_TCW_CTRL_WARN_ENA);
119 ctrl |= ADDI_TCW_CTRL_CNTR_ENA | ADDI_TCW_CTRL_MODE(data[4]);
120 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
121
122 /* Enable or Disable Interrupt */
123 if (data[1])
124 ctrl |= ADDI_TCW_CTRL_IRQ_ENA;
125 else
126 ctrl &= ~ADDI_TCW_CTRL_IRQ_ENA;
127 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
128
129 /* Set the Up/Down selection */
130 if (data[6])
131 ctrl |= ADDI_TCW_CTRL_CNT_UP;
132 else
133 ctrl &= ~ADDI_TCW_CTRL_CNT_UP;
134 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
135
136 return insn->n;
137}
138
139static int apci1564_counter_insn_write(struct comedi_device *dev,
140 struct comedi_subdevice *s,
141 struct comedi_insn *insn,
142 unsigned int *data)
143{
144 struct apci1564_private *devpriv = dev->private;
145 unsigned int chan = CR_CHAN(insn->chanspec);
146 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
147 unsigned int ctrl;
148
149 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
150 ctrl &= ~(ADDI_TCW_CTRL_GATE | ADDI_TCW_CTRL_TRIG);
151 switch (data[1]) {
152 case 0: /* Stops the Counter subdevice */
153 ctrl = 0;
154 break;
155 case 1: /* Start the Counter subdevice */
156 ctrl |= ADDI_TCW_CTRL_ENA;
157 break;
158 case 2: /* Clears the Counter subdevice */
159 ctrl |= ADDI_TCW_CTRL_GATE;
160 break;
161 }
162 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
163
164 return insn->n;
165}
166
167static int apci1564_counter_insn_read(struct comedi_device *dev,
168 struct comedi_subdevice *s,
169 struct comedi_insn *insn,
170 unsigned int *data)
171{
172 struct apci1564_private *devpriv = dev->private;
173 unsigned int chan = CR_CHAN(insn->chanspec);
174 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
175 unsigned int status;
176
177 /* Read the Counter Actual Value. */
178 data[0] = inl(iobase + ADDI_TCW_VAL_REG);
179
180 status = inl(iobase + ADDI_TCW_STATUS_REG);
181 data[1] = (status & ADDI_TCW_STATUS_SOFT_TRIG) ? 1 : 0;
182 data[2] = (status & ADDI_TCW_STATUS_HARDWARE_TRIG) ? 1 : 0;
183 data[3] = (status & ADDI_TCW_STATUS_SOFT_CLR) ? 1 : 0;
184 data[4] = (status & ADDI_TCW_STATUS_OVERFLOW) ? 1 : 0;
185
186 return insn->n;
187}
diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c
index f1ccfbd4c578..9bfb79c2e5c8 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1564.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1564.c
@@ -21,9 +21,62 @@
21 * details. 21 * details.
22 */ 22 */
23 23
24/*
25 * Driver: addi_apci_1564
26 * Description: ADDI-DATA APCI-1564 Digital I/O board
27 * Devices: [ADDI-DATA] APCI-1564 (addi_apci_1564)
28 * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
29 * Updated: Thu, 02 Jun 2016 13:12:46 -0700
30 * Status: untested
31 *
32 * Configuration Options: not applicable, uses comedi PCI auto config
33 *
34 * This board has the following features:
35 * - 32 optically isolated digital inputs (24V), 16 of which can
36 * generate change-of-state (COS) interrupts (channels 4 to 19)
37 * - 32 optically isolated digital outputs (10V to 36V)
38 * - 1 8-bit watchdog for resetting the outputs
39 * - 1 12-bit timer
40 * - 3 32-bit counters
41 * - 2 diagnostic inputs
42 *
43 * The COS, timer, and counter subdevices all use the dev->read_subdev to
44 * return the interrupt status. The sample data is updated and returned when
45 * any of these subdevices generate an interrupt. The sample data format is:
46 *
47 * Bit Description
48 * ----- ------------------------------------------
49 * 31 COS interrupt
50 * 30 timer interrupt
51 * 29 counter 2 interrupt
52 * 28 counter 1 interrupt
53 * 27 counter 0 interrupt
54 * 26:20 not used
55 * 19:4 COS digital input state (channels 19 to 4)
56 * 3:0 not used
57 *
58 * The COS interrupts must be configured using an INSN_CONFIG_DIGITAL_TRIG
59 * instruction before they can be enabled by an async command. The COS
60 * interrupts will stay active until canceled.
61 *
62 * The timer subdevice does not use an async command. All control is handled
63 * by the (*insn_config).
64 *
65 * FIXME: The format of the ADDI_TCW_TIMEBASE_REG is not descibed in the
66 * datasheet I have. The INSN_CONFIG_SET_CLOCK_SRC currently just writes
67 * the raw data[1] to this register along with the raw data[2] value to the
68 * ADDI_TCW_RELOAD_REG. If anyone tests this and can determine the actual
69 * timebase/reload operation please let me know.
70 *
71 * The counter subdevice also does not use an async command. All control is
72 * handled by the (*insn_config).
73 *
74 * FIXME: The operation of the counters is not really described in the
75 * datasheet I have. The (*insn_config) needs more work.
76 */
77
24#include <linux/module.h> 78#include <linux/module.h>
25#include <linux/interrupt.h> 79#include <linux/interrupt.h>
26#include <linux/sched.h>
27 80
28#include "../comedi_pci.h" 81#include "../comedi_pci.h"
29#include "addi_tcw.h" 82#include "addi_tcw.h"
@@ -77,6 +130,7 @@
77#define APCI1564_DI_REG 0x00 130#define APCI1564_DI_REG 0x00
78#define APCI1564_DI_INT_MODE1_REG 0x04 131#define APCI1564_DI_INT_MODE1_REG 0x04
79#define APCI1564_DI_INT_MODE2_REG 0x08 132#define APCI1564_DI_INT_MODE2_REG 0x08
133#define APCI1564_DI_INT_MODE_MASK 0x000ffff0 /* chans [19:4] */
80#define APCI1564_DI_INT_STATUS_REG 0x0c 134#define APCI1564_DI_INT_STATUS_REG 0x0c
81#define APCI1564_DI_IRQ_REG 0x10 135#define APCI1564_DI_IRQ_REG 0x10
82#define APCI1564_DI_IRQ_ENA BIT(2) 136#define APCI1564_DI_IRQ_ENA BIT(2)
@@ -90,14 +144,7 @@
90#define APCI1564_DO_INT_STATUS_VCC BIT(0) 144#define APCI1564_DO_INT_STATUS_VCC BIT(0)
91#define APCI1564_DO_IRQ_REG 0x20 145#define APCI1564_DO_IRQ_REG 0x20
92#define APCI1564_DO_IRQ_INTR BIT(0) 146#define APCI1564_DO_IRQ_INTR BIT(0)
93#define APCI1564_WDOG_REG 0x24 147#define APCI1564_WDOG_IOBASE 0x24
94#define APCI1564_WDOG_RELOAD_REG 0x28
95#define APCI1564_WDOG_TIMEBASE_REG 0x2c
96#define APCI1564_WDOG_CTRL_REG 0x30
97#define APCI1564_WDOG_STATUS_REG 0x34
98#define APCI1564_WDOG_IRQ_REG 0x38
99#define APCI1564_WDOG_WARN_TIMEVAL_REG 0x3c
100#define APCI1564_WDOG_WARN_TIMEBASE_REG 0x40
101 148
102/* 149/*
103 * devpriv->timer Register Map (see addi_tcw.h for register/bit defines) 150 * devpriv->timer Register Map (see addi_tcw.h for register/bit defines)
@@ -111,18 +158,24 @@
111 */ 158 */
112#define APCI1564_COUNTER(x) ((x) * 0x20) 159#define APCI1564_COUNTER(x) ((x) * 0x20)
113 160
161/*
162 * The dev->read_subdev is used to return the interrupt events along with
163 * the state of the interrupt capable inputs.
164 */
165#define APCI1564_EVENT_COS BIT(31)
166#define APCI1564_EVENT_TIMER BIT(30)
167#define APCI1564_EVENT_COUNTER(x) BIT(27 + (x)) /* counter 0-2 */
168#define APCI1564_EVENT_MASK 0xfff0000f /* all but [19:4] */
169
114struct apci1564_private { 170struct apci1564_private {
115 unsigned long eeprom; /* base address of EEPROM register */ 171 unsigned long eeprom; /* base address of EEPROM register */
116 unsigned long timer; /* base address of 12-bit timer */ 172 unsigned long timer; /* base address of 12-bit timer */
117 unsigned long counters; /* base address of 32-bit counters */ 173 unsigned long counters; /* base address of 32-bit counters */
118 unsigned int mode1; /* riding-edge/high level channels */ 174 unsigned int mode1; /* rising-edge/high level channels */
119 unsigned int mode2; /* falling-edge/low level channels */ 175 unsigned int mode2; /* falling-edge/low level channels */
120 unsigned int ctrl; /* interrupt mode OR (edge) . AND (level) */ 176 unsigned int ctrl; /* interrupt mode OR (edge) . AND (level) */
121 struct task_struct *tsk_current;
122}; 177};
123 178
124#include "addi-data/hwdrv_apci1564.c"
125
126static int apci1564_reset(struct comedi_device *dev) 179static int apci1564_reset(struct comedi_device *dev)
127{ 180{
128 struct apci1564_private *devpriv = dev->private; 181 struct apci1564_private *devpriv = dev->private;
@@ -138,7 +191,7 @@ static int apci1564_reset(struct comedi_device *dev)
138 outl(0x0, dev->iobase + APCI1564_DO_INT_CTRL_REG); 191 outl(0x0, dev->iobase + APCI1564_DO_INT_CTRL_REG);
139 192
140 /* Reset the watchdog registers */ 193 /* Reset the watchdog registers */
141 addi_watchdog_reset(dev->iobase + APCI1564_WDOG_REG); 194 addi_watchdog_reset(dev->iobase + APCI1564_WDOG_IOBASE);
142 195
143 /* Reset the timer registers */ 196 /* Reset the timer registers */
144 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG); 197 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
@@ -165,55 +218,54 @@ static irqreturn_t apci1564_interrupt(int irq, void *d)
165 unsigned int ctrl; 218 unsigned int ctrl;
166 unsigned int chan; 219 unsigned int chan;
167 220
221 s->state &= ~APCI1564_EVENT_MASK;
222
168 status = inl(dev->iobase + APCI1564_DI_IRQ_REG); 223 status = inl(dev->iobase + APCI1564_DI_IRQ_REG);
169 if (status & APCI1564_DI_IRQ_ENA) { 224 if (status & APCI1564_DI_IRQ_ENA) {
170 /* disable the interrupt */ 225 /* get the COS interrupt state and set the event flag */
226 s->state = inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
227 s->state &= APCI1564_DI_INT_MODE_MASK;
228 s->state |= APCI1564_EVENT_COS;
229
230 /* clear the interrupt */
171 outl(status & ~APCI1564_DI_IRQ_ENA, 231 outl(status & ~APCI1564_DI_IRQ_ENA,
172 dev->iobase + APCI1564_DI_IRQ_REG); 232 dev->iobase + APCI1564_DI_IRQ_REG);
173
174 s->state = inl(dev->iobase + APCI1564_DI_INT_STATUS_REG) &
175 0xffff;
176 comedi_buf_write_samples(s, &s->state, 1);
177 comedi_handle_events(dev, s);
178
179 /* enable the interrupt */
180 outl(status, dev->iobase + APCI1564_DI_IRQ_REG); 233 outl(status, dev->iobase + APCI1564_DI_IRQ_REG);
181 } 234 }
182 235
183 status = inl(devpriv->timer + ADDI_TCW_IRQ_REG); 236 status = inl(devpriv->timer + ADDI_TCW_IRQ_REG);
184 if (status & 0x01) { 237 if (status & ADDI_TCW_IRQ) {
185 /* Disable Timer Interrupt */ 238 s->state |= APCI1564_EVENT_TIMER;
239
240 /* clear the interrupt */
186 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG); 241 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
187 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG); 242 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
188
189 /* Send a signal to from kernel to user space */
190 send_sig(SIGIO, devpriv->tsk_current, 0);
191
192 /* Enable Timer Interrupt */
193 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG); 243 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
194 } 244 }
195 245
196 if (devpriv->counters) { 246 if (devpriv->counters) {
197 for (chan = 0; chan < 4; chan++) { 247 for (chan = 0; chan < 3; chan++) {
198 unsigned long iobase; 248 unsigned long iobase;
199 249
200 iobase = devpriv->counters + APCI1564_COUNTER(chan); 250 iobase = devpriv->counters + APCI1564_COUNTER(chan);
201 251
202 status = inl(iobase + ADDI_TCW_IRQ_REG); 252 status = inl(iobase + ADDI_TCW_IRQ_REG);
203 if (status & 0x01) { 253 if (status & ADDI_TCW_IRQ) {
204 /* Disable Counter Interrupt */ 254 s->state |= APCI1564_EVENT_COUNTER(chan);
255
256 /* clear the interrupt */
205 ctrl = inl(iobase + ADDI_TCW_CTRL_REG); 257 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
206 outl(0x0, iobase + ADDI_TCW_CTRL_REG); 258 outl(0x0, iobase + ADDI_TCW_CTRL_REG);
207
208 /* Send a signal to from kernel to user space */
209 send_sig(SIGIO, devpriv->tsk_current, 0);
210
211 /* Enable Counter Interrupt */
212 outl(ctrl, iobase + ADDI_TCW_CTRL_REG); 259 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
213 } 260 }
214 } 261 }
215 } 262 }
216 263
264 if (s->state & APCI1564_EVENT_MASK) {
265 comedi_buf_write_samples(s, &s->state, 1);
266 comedi_handle_events(dev, s);
267 }
268
217 return IRQ_HANDLED; 269 return IRQ_HANDLED;
218} 270}
219 271
@@ -255,7 +307,7 @@ static int apci1564_diag_insn_bits(struct comedi_device *dev,
255/* 307/*
256 * Change-Of-State (COS) interrupt configuration 308 * Change-Of-State (COS) interrupt configuration
257 * 309 *
258 * Channels 0 to 15 are interruptible. These channels can be configured 310 * Channels 4 to 19 are interruptible. These channels can be configured
259 * to generate interrupts based on AND/OR logic for the desired channels. 311 * to generate interrupts based on AND/OR logic for the desired channels.
260 * 312 *
261 * OR logic 313 * OR logic
@@ -343,6 +395,10 @@ static int apci1564_cos_insn_config(struct comedi_device *dev,
343 default: 395 default:
344 return -EINVAL; 396 return -EINVAL;
345 } 397 }
398
399 /* ensure the mode bits are in-range for channels [19:4] */
400 devpriv->mode1 &= APCI1564_DI_INT_MODE_MASK;
401 devpriv->mode2 &= APCI1564_DI_INT_MODE_MASK;
346 break; 402 break;
347 default: 403 default:
348 return -EINVAL; 404 return -EINVAL;
@@ -409,7 +465,7 @@ static int apci1564_cos_cmd(struct comedi_device *dev,
409{ 465{
410 struct apci1564_private *devpriv = dev->private; 466 struct apci1564_private *devpriv = dev->private;
411 467
412 if (!devpriv->ctrl) { 468 if (!devpriv->ctrl && !(devpriv->mode1 || devpriv->mode2)) {
413 dev_warn(dev->class_dev, 469 dev_warn(dev->class_dev,
414 "Interrupts disabled due to mode configuration!\n"); 470 "Interrupts disabled due to mode configuration!\n");
415 return -EINVAL; 471 return -EINVAL;
@@ -433,6 +489,173 @@ static int apci1564_cos_cancel(struct comedi_device *dev,
433 return 0; 489 return 0;
434} 490}
435 491
492static int apci1564_timer_insn_config(struct comedi_device *dev,
493 struct comedi_subdevice *s,
494 struct comedi_insn *insn,
495 unsigned int *data)
496{
497 struct apci1564_private *devpriv = dev->private;
498 unsigned int val;
499
500 switch (data[0]) {
501 case INSN_CONFIG_ARM:
502 if (data[1] > s->maxdata)
503 return -EINVAL;
504 outl(data[1], devpriv->timer + ADDI_TCW_RELOAD_REG);
505 outl(ADDI_TCW_CTRL_IRQ_ENA | ADDI_TCW_CTRL_TIMER_ENA,
506 devpriv->timer + ADDI_TCW_CTRL_REG);
507 break;
508 case INSN_CONFIG_DISARM:
509 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
510 break;
511 case INSN_CONFIG_GET_COUNTER_STATUS:
512 data[1] = 0;
513 val = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
514 if (val & ADDI_TCW_CTRL_IRQ_ENA)
515 data[1] |= COMEDI_COUNTER_ARMED;
516 if (val & ADDI_TCW_CTRL_TIMER_ENA)
517 data[1] |= COMEDI_COUNTER_COUNTING;
518 val = inl(devpriv->timer + ADDI_TCW_STATUS_REG);
519 if (val & ADDI_TCW_STATUS_OVERFLOW)
520 data[1] |= COMEDI_COUNTER_TERMINAL_COUNT;
521 data[2] = COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING |
522 COMEDI_COUNTER_TERMINAL_COUNT;
523 break;
524 case INSN_CONFIG_SET_CLOCK_SRC:
525 if (data[2] > s->maxdata)
526 return -EINVAL;
527 outl(data[1], devpriv->timer + ADDI_TCW_TIMEBASE_REG);
528 outl(data[2], devpriv->timer + ADDI_TCW_RELOAD_REG);
529 break;
530 case INSN_CONFIG_GET_CLOCK_SRC:
531 data[1] = inl(devpriv->timer + ADDI_TCW_TIMEBASE_REG);
532 data[2] = inl(devpriv->timer + ADDI_TCW_RELOAD_REG);
533 break;
534 default:
535 return -EINVAL;
536 }
537
538 return insn->n;
539}
540
541static int apci1564_timer_insn_write(struct comedi_device *dev,
542 struct comedi_subdevice *s,
543 struct comedi_insn *insn,
544 unsigned int *data)
545{
546 struct apci1564_private *devpriv = dev->private;
547
548 /* just write the last last to the reload register */
549 if (insn->n) {
550 unsigned int val = data[insn->n - 1];
551
552 outl(val, devpriv->timer + ADDI_TCW_RELOAD_REG);
553 }
554
555 return insn->n;
556}
557
558static int apci1564_timer_insn_read(struct comedi_device *dev,
559 struct comedi_subdevice *s,
560 struct comedi_insn *insn,
561 unsigned int *data)
562{
563 struct apci1564_private *devpriv = dev->private;
564 int i;
565
566 /* return the actual value of the timer */
567 for (i = 0; i < insn->n; i++)
568 data[i] = inl(devpriv->timer + ADDI_TCW_VAL_REG);
569
570 return insn->n;
571}
572
573static int apci1564_counter_insn_config(struct comedi_device *dev,
574 struct comedi_subdevice *s,
575 struct comedi_insn *insn,
576 unsigned int *data)
577{
578 struct apci1564_private *devpriv = dev->private;
579 unsigned int chan = CR_CHAN(insn->chanspec);
580 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
581 unsigned int val;
582
583 switch (data[0]) {
584 case INSN_CONFIG_ARM:
585 val = inl(iobase + ADDI_TCW_CTRL_REG);
586 val |= ADDI_TCW_CTRL_IRQ_ENA | ADDI_TCW_CTRL_CNTR_ENA;
587 outl(data[1], iobase + ADDI_TCW_RELOAD_REG);
588 outl(val, iobase + ADDI_TCW_CTRL_REG);
589 break;
590 case INSN_CONFIG_DISARM:
591 val = inl(iobase + ADDI_TCW_CTRL_REG);
592 val &= ~(ADDI_TCW_CTRL_IRQ_ENA | ADDI_TCW_CTRL_CNTR_ENA);
593 outl(val, iobase + ADDI_TCW_CTRL_REG);
594 break;
595 case INSN_CONFIG_SET_COUNTER_MODE:
596 /*
597 * FIXME: The counter operation is not described in the
598 * datasheet. For now just write the raw data[1] value to
599 * the control register.
600 */
601 outl(data[1], iobase + ADDI_TCW_CTRL_REG);
602 break;
603 case INSN_CONFIG_GET_COUNTER_STATUS:
604 data[1] = 0;
605 val = inl(iobase + ADDI_TCW_CTRL_REG);
606 if (val & ADDI_TCW_CTRL_IRQ_ENA)
607 data[1] |= COMEDI_COUNTER_ARMED;
608 if (val & ADDI_TCW_CTRL_CNTR_ENA)
609 data[1] |= COMEDI_COUNTER_COUNTING;
610 val = inl(iobase + ADDI_TCW_STATUS_REG);
611 if (val & ADDI_TCW_STATUS_OVERFLOW)
612 data[1] |= COMEDI_COUNTER_TERMINAL_COUNT;
613 data[2] = COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING |
614 COMEDI_COUNTER_TERMINAL_COUNT;
615 break;
616 default:
617 return -EINVAL;
618 }
619
620 return insn->n;
621}
622
623static int apci1564_counter_insn_write(struct comedi_device *dev,
624 struct comedi_subdevice *s,
625 struct comedi_insn *insn,
626 unsigned int *data)
627{
628 struct apci1564_private *devpriv = dev->private;
629 unsigned int chan = CR_CHAN(insn->chanspec);
630 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
631
632 /* just write the last last to the reload register */
633 if (insn->n) {
634 unsigned int val = data[insn->n - 1];
635
636 outl(val, iobase + ADDI_TCW_RELOAD_REG);
637 }
638
639 return insn->n;
640}
641
642static int apci1564_counter_insn_read(struct comedi_device *dev,
643 struct comedi_subdevice *s,
644 struct comedi_insn *insn,
645 unsigned int *data)
646{
647 struct apci1564_private *devpriv = dev->private;
648 unsigned int chan = CR_CHAN(insn->chanspec);
649 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
650 int i;
651
652 /* return the actual value of the counter */
653 for (i = 0; i < insn->n; i++)
654 data[i] = inl(iobase + ADDI_TCW_VAL_REG);
655
656 return insn->n;
657}
658
436static int apci1564_auto_attach(struct comedi_device *dev, 659static int apci1564_auto_attach(struct comedi_device *dev,
437 unsigned long context_unused) 660 unsigned long context_unused)
438{ 661{
@@ -501,7 +724,7 @@ static int apci1564_auto_attach(struct comedi_device *dev,
501 if (dev->irq) { 724 if (dev->irq) {
502 dev->read_subdev = s; 725 dev->read_subdev = s;
503 s->type = COMEDI_SUBD_DI; 726 s->type = COMEDI_SUBD_DI;
504 s->subdev_flags = SDF_READABLE | SDF_CMD_READ; 727 s->subdev_flags = SDF_READABLE | SDF_CMD_READ | SDF_LSAMPL;
505 s->n_chan = 1; 728 s->n_chan = 1;
506 s->maxdata = 1; 729 s->maxdata = 1;
507 s->range_table = &range_digital; 730 s->range_table = &range_digital;
@@ -543,7 +766,7 @@ static int apci1564_auto_attach(struct comedi_device *dev,
543 766
544 /* Initialize the watchdog subdevice */ 767 /* Initialize the watchdog subdevice */
545 s = &dev->subdevices[5]; 768 s = &dev->subdevices[5];
546 ret = addi_watchdog_init(s, dev->iobase + APCI1564_WDOG_REG); 769 ret = addi_watchdog_init(s, dev->iobase + APCI1564_WDOG_IOBASE);
547 if (ret) 770 if (ret)
548 return ret; 771 return ret;
549 772
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index 4437ea3abe8d..be70bd333807 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -570,7 +570,7 @@ static int pci9118_ai_cancel(struct comedi_device *dev,
570 /* set default config (disable burst and triggers) */ 570 /* set default config (disable burst and triggers) */
571 devpriv->ai_cfg = PCI9118_AI_CFG_PDTRG | PCI9118_AI_CFG_PETRG; 571 devpriv->ai_cfg = PCI9118_AI_CFG_PDTRG | PCI9118_AI_CFG_PETRG;
572 outl(devpriv->ai_cfg, dev->iobase + PCI9118_AI_CFG_REG); 572 outl(devpriv->ai_cfg, dev->iobase + PCI9118_AI_CFG_REG);
573 /* reset acqusition control */ 573 /* reset acquisition control */
574 devpriv->ai_ctrl = 0; 574 devpriv->ai_ctrl = 0;
575 outl(devpriv->ai_ctrl, dev->iobase + PCI9118_AI_CTRL_REG); 575 outl(devpriv->ai_ctrl, dev->iobase + PCI9118_AI_CTRL_REG);
576 outl(0, dev->iobase + PCI9118_AI_BURST_NUM_REG); 576 outl(0, dev->iobase + PCI9118_AI_BURST_NUM_REG);
@@ -1022,12 +1022,12 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1022 1022
1023 /* 1023 /*
1024 * Configure analog input and load the chanlist. 1024 * Configure analog input and load the chanlist.
1025 * The acqusition control bits are enabled later. 1025 * The acquisition control bits are enabled later.
1026 */ 1026 */
1027 pci9118_set_chanlist(dev, s, cmd->chanlist_len, cmd->chanlist, 1027 pci9118_set_chanlist(dev, s, cmd->chanlist_len, cmd->chanlist,
1028 devpriv->ai_add_front, devpriv->ai_add_back); 1028 devpriv->ai_add_front, devpriv->ai_add_back);
1029 1029
1030 /* Determine acqusition mode and calculate timing */ 1030 /* Determine acquisition mode and calculate timing */
1031 devpriv->ai_do = 0; 1031 devpriv->ai_do = 0;
1032 if (cmd->scan_begin_src != TRIG_TIMER && 1032 if (cmd->scan_begin_src != TRIG_TIMER &&
1033 cmd->convert_src == TRIG_TIMER) { 1033 cmd->convert_src == TRIG_TIMER) {
@@ -1097,7 +1097,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1097 1097
1098 if (devpriv->ai_do == 0) { 1098 if (devpriv->ai_do == 0) {
1099 dev_err(dev->class_dev, 1099 dev_err(dev->class_dev,
1100 "Unable to determine acqusition mode! BUG in (*do_cmdtest)?\n"); 1100 "Unable to determine acquisition mode! BUG in (*do_cmdtest)?\n");
1101 return -EINVAL; 1101 return -EINVAL;
1102 } 1102 }
1103 1103
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index c773b8ca6599..1f9c08a845b6 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1238,7 +1238,7 @@ static void disable_plx_interrupts(struct comedi_device *dev)
1238 1238
1239 devpriv->plx_intcsr_bits = 0; 1239 devpriv->plx_intcsr_bits = 0;
1240 writel(devpriv->plx_intcsr_bits, 1240 writel(devpriv->plx_intcsr_bits,
1241 devpriv->plx9080_iobase + PLX_INTRCS_REG); 1241 devpriv->plx9080_iobase + PLX_REG_INTCSR);
1242} 1242}
1243 1243
1244static void disable_ai_interrupts(struct comedi_device *dev) 1244static void disable_ai_interrupts(struct comedi_device *dev)
@@ -1291,14 +1291,14 @@ static void init_plx9080(struct comedi_device *dev)
1291 void __iomem *plx_iobase = devpriv->plx9080_iobase; 1291 void __iomem *plx_iobase = devpriv->plx9080_iobase;
1292 1292
1293 devpriv->plx_control_bits = 1293 devpriv->plx_control_bits =
1294 readl(devpriv->plx9080_iobase + PLX_CONTROL_REG); 1294 readl(devpriv->plx9080_iobase + PLX_REG_CNTRL);
1295 1295
1296#ifdef __BIG_ENDIAN 1296#ifdef __BIG_ENDIAN
1297 bits = BIGEND_DMA0 | BIGEND_DMA1; 1297 bits = PLX_BIGEND_DMA0 | PLX_BIGEND_DMA1;
1298#else 1298#else
1299 bits = 0; 1299 bits = 0;
1300#endif 1300#endif
1301 writel(bits, devpriv->plx9080_iobase + PLX_BIGEND_REG); 1301 writel(bits, devpriv->plx9080_iobase + PLX_REG_BIGEND);
1302 1302
1303 disable_plx_interrupts(dev); 1303 disable_plx_interrupts(dev);
1304 1304
@@ -1308,38 +1308,39 @@ static void init_plx9080(struct comedi_device *dev)
1308 /* configure dma0 mode */ 1308 /* configure dma0 mode */
1309 bits = 0; 1309 bits = 0;
1310 /* enable ready input, not sure if this is necessary */ 1310 /* enable ready input, not sure if this is necessary */
1311 bits |= PLX_DMA_EN_READYIN_BIT; 1311 bits |= PLX_DMAMODE_READYIEN;
1312 /* enable bterm, not sure if this is necessary */ 1312 /* enable bterm, not sure if this is necessary */
1313 bits |= PLX_EN_BTERM_BIT; 1313 bits |= PLX_DMAMODE_BTERMIEN;
1314 /* enable dma chaining */ 1314 /* enable dma chaining */
1315 bits |= PLX_EN_CHAIN_BIT; 1315 bits |= PLX_DMAMODE_CHAINEN;
1316 /* enable interrupt on dma done 1316 /* enable interrupt on dma done
1317 * (probably don't need this, since chain never finishes) */ 1317 * (probably don't need this, since chain never finishes) */
1318 bits |= PLX_EN_DMA_DONE_INTR_BIT; 1318 bits |= PLX_DMAMODE_DONEIEN;
1319 /* don't increment local address during transfers 1319 /* don't increment local address during transfers
1320 * (we are transferring from a fixed fifo register) */ 1320 * (we are transferring from a fixed fifo register) */
1321 bits |= PLX_LOCAL_ADDR_CONST_BIT; 1321 bits |= PLX_DMAMODE_LACONST;
1322 /* route dma interrupt to pci bus */ 1322 /* route dma interrupt to pci bus */
1323 bits |= PLX_DMA_INTR_PCI_BIT; 1323 bits |= PLX_DMAMODE_INTRPCI;
1324 /* enable demand mode */ 1324 /* enable demand mode */
1325 bits |= PLX_DEMAND_MODE_BIT; 1325 bits |= PLX_DMAMODE_DEMAND;
1326 /* enable local burst mode */ 1326 /* enable local burst mode */
1327 bits |= PLX_DMA_LOCAL_BURST_EN_BIT; 1327 bits |= PLX_DMAMODE_BURSTEN;
1328 /* 4020 uses 32 bit dma */ 1328 /* 4020 uses 32 bit dma */
1329 if (board->layout == LAYOUT_4020) 1329 if (board->layout == LAYOUT_4020)
1330 bits |= PLX_LOCAL_BUS_32_WIDE_BITS; 1330 bits |= PLX_DMAMODE_WIDTH32;
1331 else /* localspace0 bus is 16 bits wide */ 1331 else /* localspace0 bus is 16 bits wide */
1332 bits |= PLX_LOCAL_BUS_16_WIDE_BITS; 1332 bits |= PLX_DMAMODE_WIDTH16;
1333 writel(bits, plx_iobase + PLX_DMA1_MODE_REG); 1333 writel(bits, plx_iobase + PLX_REG_DMAMODE1);
1334 if (ao_cmd_is_supported(board)) 1334 if (ao_cmd_is_supported(board))
1335 writel(bits, plx_iobase + PLX_DMA0_MODE_REG); 1335 writel(bits, plx_iobase + PLX_REG_DMAMODE0);
1336 1336
1337 /* enable interrupts on plx 9080 */ 1337 /* enable interrupts on plx 9080 */
1338 devpriv->plx_intcsr_bits |= 1338 devpriv->plx_intcsr_bits |=
1339 ICS_AERR | ICS_PERR | ICS_PIE | ICS_PLIE | ICS_PAIE | ICS_LIE | 1339 PLX_INTCSR_LSEABORTEN | PLX_INTCSR_LSEPARITYEN | PLX_INTCSR_PIEN |
1340 ICS_DMA0_E | ICS_DMA1_E; 1340 PLX_INTCSR_PLIEN | PLX_INTCSR_PABORTIEN | PLX_INTCSR_LIOEN |
1341 PLX_INTCSR_DMA0IEN | PLX_INTCSR_DMA1IEN;
1341 writel(devpriv->plx_intcsr_bits, 1342 writel(devpriv->plx_intcsr_bits,
1342 devpriv->plx9080_iobase + PLX_INTRCS_REG); 1343 devpriv->plx9080_iobase + PLX_REG_INTCSR);
1343} 1344}
1344 1345
1345static void disable_ai_pacing(struct comedi_device *dev) 1346static void disable_ai_pacing(struct comedi_device *dev)
@@ -1533,8 +1534,8 @@ static int alloc_and_init_dma_members(struct comedi_device *dev)
1533 cpu_to_le32((devpriv->ai_dma_desc_bus_addr + 1534 cpu_to_le32((devpriv->ai_dma_desc_bus_addr +
1534 ((i + 1) % ai_dma_ring_count(board)) * 1535 ((i + 1) % ai_dma_ring_count(board)) *
1535 sizeof(devpriv->ai_dma_desc[0])) | 1536 sizeof(devpriv->ai_dma_desc[0])) |
1536 PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | 1537 PLX_DMADPR_DESCPCI | PLX_DMADPR_TCINTR |
1537 PLX_XFER_LOCAL_TO_PCI); 1538 PLX_DMADPR_XFERL2P);
1538 } 1539 }
1539 if (ao_cmd_is_supported(board)) { 1540 if (ao_cmd_is_supported(board)) {
1540 for (i = 0; i < AO_DMA_RING_COUNT; i++) { 1541 for (i = 0; i < AO_DMA_RING_COUNT; i++) {
@@ -1548,8 +1549,8 @@ static int alloc_and_init_dma_members(struct comedi_device *dev)
1548 cpu_to_le32((devpriv->ao_dma_desc_bus_addr + 1549 cpu_to_le32((devpriv->ao_dma_desc_bus_addr +
1549 ((i + 1) % (AO_DMA_RING_COUNT)) * 1550 ((i + 1) % (AO_DMA_RING_COUNT)) *
1550 sizeof(devpriv->ao_dma_desc[0])) | 1551 sizeof(devpriv->ao_dma_desc[0])) |
1551 PLX_DESC_IN_PCI_BIT | 1552 PLX_DMADPR_DESCPCI |
1552 PLX_INTR_TERM_COUNT); 1553 PLX_DMADPR_TCINTR);
1553 } 1554 }
1554 } 1555 }
1555 return 0; 1556 return 0;
@@ -1613,9 +1614,9 @@ static const int i2c_low_udelay = 10;
1613static void i2c_set_sda(struct comedi_device *dev, int state) 1614static void i2c_set_sda(struct comedi_device *dev, int state)
1614{ 1615{
1615 struct pcidas64_private *devpriv = dev->private; 1616 struct pcidas64_private *devpriv = dev->private;
1616 static const int data_bit = CTL_EE_W; 1617 static const int data_bit = PLX_CNTRL_EEWB;
1617 void __iomem *plx_control_addr = devpriv->plx9080_iobase + 1618 void __iomem *plx_control_addr = devpriv->plx9080_iobase +
1618 PLX_CONTROL_REG; 1619 PLX_REG_CNTRL;
1619 1620
1620 if (state) { 1621 if (state) {
1621 /* set data line high */ 1622 /* set data line high */
@@ -1634,9 +1635,9 @@ static void i2c_set_sda(struct comedi_device *dev, int state)
1634static void i2c_set_scl(struct comedi_device *dev, int state) 1635static void i2c_set_scl(struct comedi_device *dev, int state)
1635{ 1636{
1636 struct pcidas64_private *devpriv = dev->private; 1637 struct pcidas64_private *devpriv = dev->private;
1637 static const int clock_bit = CTL_USERO; 1638 static const int clock_bit = PLX_CNTRL_USERO;
1638 void __iomem *plx_control_addr = devpriv->plx9080_iobase + 1639 void __iomem *plx_control_addr = devpriv->plx9080_iobase +
1639 PLX_CONTROL_REG; 1640 PLX_REG_CNTRL;
1640 1641
1641 if (state) { 1642 if (state) {
1642 /* set clock line high */ 1643 /* set clock line high */
@@ -1707,7 +1708,7 @@ static void i2c_write(struct comedi_device *dev, unsigned int address,
1707 */ 1708 */
1708 1709
1709 /* make sure we dont send anything to eeprom */ 1710 /* make sure we dont send anything to eeprom */
1710 devpriv->plx_control_bits &= ~CTL_EE_CS; 1711 devpriv->plx_control_bits &= ~PLX_CNTRL_EECS;
1711 1712
1712 i2c_stop(dev); 1713 i2c_stop(dev);
1713 i2c_start(dev); 1714 i2c_start(dev);
@@ -2367,14 +2368,8 @@ static inline void dma_start_sync(struct comedi_device *dev,
2367 2368
2368 /* spinlock for plx dma control/status reg */ 2369 /* spinlock for plx dma control/status reg */
2369 spin_lock_irqsave(&dev->spinlock, flags); 2370 spin_lock_irqsave(&dev->spinlock, flags);
2370 if (channel) 2371 writeb(PLX_DMACSR_ENABLE | PLX_DMACSR_START | PLX_DMACSR_CLEARINTR,
2371 writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | 2372 devpriv->plx9080_iobase + PLX_REG_DMACSR(channel));
2372 PLX_CLEAR_DMA_INTR_BIT,
2373 devpriv->plx9080_iobase + PLX_DMA1_CS_REG);
2374 else
2375 writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT |
2376 PLX_CLEAR_DMA_INTR_BIT,
2377 devpriv->plx9080_iobase + PLX_DMA0_CS_REG);
2378 spin_unlock_irqrestore(&dev->spinlock, flags); 2373 spin_unlock_irqrestore(&dev->spinlock, flags);
2379} 2374}
2380 2375
@@ -2552,21 +2547,17 @@ static inline void load_first_dma_descriptor(struct comedi_device *dev,
2552 * block. Initializing them to zero seems to fix the problem. 2547 * block. Initializing them to zero seems to fix the problem.
2553 */ 2548 */
2554 if (dma_channel) { 2549 if (dma_channel) {
2555 writel(0, 2550 writel(0, devpriv->plx9080_iobase + PLX_REG_DMASIZ1);
2556 devpriv->plx9080_iobase + PLX_DMA1_TRANSFER_SIZE_REG); 2551 writel(0, devpriv->plx9080_iobase + PLX_REG_DMAPADR1);
2557 writel(0, devpriv->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG); 2552 writel(0, devpriv->plx9080_iobase + PLX_REG_DMALADR1);
2558 writel(0,
2559 devpriv->plx9080_iobase + PLX_DMA1_LOCAL_ADDRESS_REG);
2560 writel(descriptor_bits, 2553 writel(descriptor_bits,
2561 devpriv->plx9080_iobase + PLX_DMA1_DESCRIPTOR_REG); 2554 devpriv->plx9080_iobase + PLX_REG_DMADPR1);
2562 } else { 2555 } else {
2563 writel(0, 2556 writel(0, devpriv->plx9080_iobase + PLX_REG_DMASIZ0);
2564 devpriv->plx9080_iobase + PLX_DMA0_TRANSFER_SIZE_REG); 2557 writel(0, devpriv->plx9080_iobase + PLX_REG_DMAPADR0);
2565 writel(0, devpriv->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG); 2558 writel(0, devpriv->plx9080_iobase + PLX_REG_DMALADR0);
2566 writel(0,
2567 devpriv->plx9080_iobase + PLX_DMA0_LOCAL_ADDRESS_REG);
2568 writel(descriptor_bits, 2559 writel(descriptor_bits,
2569 devpriv->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG); 2560 devpriv->plx9080_iobase + PLX_REG_DMADPR0);
2570 } 2561 }
2571} 2562}
2572 2563
@@ -2643,9 +2634,9 @@ static int ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2643 /* give location of first dma descriptor */ 2634 /* give location of first dma descriptor */
2644 load_first_dma_descriptor(dev, 1, 2635 load_first_dma_descriptor(dev, 1,
2645 devpriv->ai_dma_desc_bus_addr | 2636 devpriv->ai_dma_desc_bus_addr |
2646 PLX_DESC_IN_PCI_BIT | 2637 PLX_DMADPR_DESCPCI |
2647 PLX_INTR_TERM_COUNT | 2638 PLX_DMADPR_TCINTR |
2648 PLX_XFER_LOCAL_TO_PCI); 2639 PLX_DMADPR_XFERL2P);
2649 2640
2650 dma_start_sync(dev, 1); 2641 dma_start_sync(dev, 1);
2651 } 2642 }
@@ -2803,12 +2794,7 @@ static void drain_dma_buffers(struct comedi_device *dev, unsigned int channel)
2803 int num_samples = 0; 2794 int num_samples = 0;
2804 void __iomem *pci_addr_reg; 2795 void __iomem *pci_addr_reg;
2805 2796
2806 if (channel) 2797 pci_addr_reg = devpriv->plx9080_iobase + PLX_REG_DMAPADR(channel);
2807 pci_addr_reg =
2808 devpriv->plx9080_iobase + PLX_DMA1_PCI_ADDRESS_REG;
2809 else
2810 pci_addr_reg =
2811 devpriv->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG;
2812 2798
2813 /* loop until we have read all the full buffers */ 2799 /* loop until we have read all the full buffers */
2814 for (j = 0, next_transfer_addr = readl(pci_addr_reg); 2800 for (j = 0, next_transfer_addr = readl(pci_addr_reg);
@@ -2850,12 +2836,12 @@ static void handle_ai_interrupt(struct comedi_device *dev,
2850 } 2836 }
2851 /* spin lock makes sure no one else changes plx dma control reg */ 2837 /* spin lock makes sure no one else changes plx dma control reg */
2852 spin_lock_irqsave(&dev->spinlock, flags); 2838 spin_lock_irqsave(&dev->spinlock, flags);
2853 dma1_status = readb(devpriv->plx9080_iobase + PLX_DMA1_CS_REG); 2839 dma1_status = readb(devpriv->plx9080_iobase + PLX_REG_DMACSR1);
2854 if (plx_status & ICS_DMA1_A) { /* dma chan 1 interrupt */ 2840 if (plx_status & PLX_INTCSR_DMA1IA) { /* dma chan 1 interrupt */
2855 writeb((dma1_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, 2841 writeb((dma1_status & PLX_DMACSR_ENABLE) | PLX_DMACSR_CLEARINTR,
2856 devpriv->plx9080_iobase + PLX_DMA1_CS_REG); 2842 devpriv->plx9080_iobase + PLX_REG_DMACSR1);
2857 2843
2858 if (dma1_status & PLX_DMA_EN_BIT) 2844 if (dma1_status & PLX_DMACSR_ENABLE)
2859 drain_dma_buffers(dev, 1); 2845 drain_dma_buffers(dev, 1);
2860 } 2846 }
2861 spin_unlock_irqrestore(&dev->spinlock, flags); 2847 spin_unlock_irqrestore(&dev->spinlock, flags);
@@ -2902,12 +2888,12 @@ static int last_ao_dma_load_completed(struct comedi_device *dev)
2902 unsigned short dma_status; 2888 unsigned short dma_status;
2903 2889
2904 buffer_index = prev_ao_dma_index(dev); 2890 buffer_index = prev_ao_dma_index(dev);
2905 dma_status = readb(devpriv->plx9080_iobase + PLX_DMA0_CS_REG); 2891 dma_status = readb(devpriv->plx9080_iobase + PLX_REG_DMACSR0);
2906 if ((dma_status & PLX_DMA_DONE_BIT) == 0) 2892 if ((dma_status & PLX_DMACSR_DONE) == 0)
2907 return 0; 2893 return 0;
2908 2894
2909 transfer_address = 2895 transfer_address =
2910 readl(devpriv->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG); 2896 readl(devpriv->plx9080_iobase + PLX_REG_DMAPADR0);
2911 if (transfer_address != devpriv->ao_buffer_bus_addr[buffer_index]) 2897 if (transfer_address != devpriv->ao_buffer_bus_addr[buffer_index])
2912 return 0; 2898 return 0;
2913 2899
@@ -2917,8 +2903,8 @@ static int last_ao_dma_load_completed(struct comedi_device *dev)
2917static inline int ao_dma_needs_restart(struct comedi_device *dev, 2903static inline int ao_dma_needs_restart(struct comedi_device *dev,
2918 unsigned short dma_status) 2904 unsigned short dma_status)
2919{ 2905{
2920 if ((dma_status & PLX_DMA_DONE_BIT) == 0 || 2906 if ((dma_status & PLX_DMACSR_DONE) == 0 ||
2921 (dma_status & PLX_DMA_EN_BIT) == 0) 2907 (dma_status & PLX_DMACSR_ENABLE) == 0)
2922 return 0; 2908 return 0;
2923 if (last_ao_dma_load_completed(dev)) 2909 if (last_ao_dma_load_completed(dev))
2924 return 0; 2910 return 0;
@@ -2931,9 +2917,8 @@ static void restart_ao_dma(struct comedi_device *dev)
2931 struct pcidas64_private *devpriv = dev->private; 2917 struct pcidas64_private *devpriv = dev->private;
2932 unsigned int dma_desc_bits; 2918 unsigned int dma_desc_bits;
2933 2919
2934 dma_desc_bits = 2920 dma_desc_bits = readl(devpriv->plx9080_iobase + PLX_REG_DMADPR0);
2935 readl(devpriv->plx9080_iobase + PLX_DMA0_DESCRIPTOR_REG); 2921 dma_desc_bits &= ~PLX_DMADPR_CHAINEND;
2936 dma_desc_bits &= ~PLX_END_OF_CHAIN_BIT;
2937 load_first_dma_descriptor(dev, 0, dma_desc_bits); 2922 load_first_dma_descriptor(dev, 0, dma_desc_bits);
2938 2923
2939 dma_start_sync(dev, 0); 2924 dma_start_sync(dev, 0);
@@ -2974,14 +2959,14 @@ static unsigned int load_ao_dma_buffer(struct comedi_device *dev,
2974 devpriv->ao_dma_desc[buffer_index].transfer_size = cpu_to_le32(nbytes); 2959 devpriv->ao_dma_desc[buffer_index].transfer_size = cpu_to_le32(nbytes);
2975 /* set end of chain bit so we catch underruns */ 2960 /* set end of chain bit so we catch underruns */
2976 next_bits = le32_to_cpu(devpriv->ao_dma_desc[buffer_index].next); 2961 next_bits = le32_to_cpu(devpriv->ao_dma_desc[buffer_index].next);
2977 next_bits |= PLX_END_OF_CHAIN_BIT; 2962 next_bits |= PLX_DMADPR_CHAINEND;
2978 devpriv->ao_dma_desc[buffer_index].next = cpu_to_le32(next_bits); 2963 devpriv->ao_dma_desc[buffer_index].next = cpu_to_le32(next_bits);
2979 /* 2964 /*
2980 * clear end of chain bit on previous buffer now that we have set it 2965 * clear end of chain bit on previous buffer now that we have set it
2981 * for the last buffer 2966 * for the last buffer
2982 */ 2967 */
2983 next_bits = le32_to_cpu(devpriv->ao_dma_desc[prev_buffer_index].next); 2968 next_bits = le32_to_cpu(devpriv->ao_dma_desc[prev_buffer_index].next);
2984 next_bits &= ~PLX_END_OF_CHAIN_BIT; 2969 next_bits &= ~PLX_DMADPR_CHAINEND;
2985 devpriv->ao_dma_desc[prev_buffer_index].next = cpu_to_le32(next_bits); 2970 devpriv->ao_dma_desc[prev_buffer_index].next = cpu_to_le32(next_bits);
2986 2971
2987 devpriv->ao_dma_index = (buffer_index + 1) % AO_DMA_RING_COUNT; 2972 devpriv->ao_dma_index = (buffer_index + 1) % AO_DMA_RING_COUNT;
@@ -2994,8 +2979,7 @@ static void load_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd)
2994 struct pcidas64_private *devpriv = dev->private; 2979 struct pcidas64_private *devpriv = dev->private;
2995 unsigned int num_bytes; 2980 unsigned int num_bytes;
2996 unsigned int next_transfer_addr; 2981 unsigned int next_transfer_addr;
2997 void __iomem *pci_addr_reg = 2982 void __iomem *pci_addr_reg = devpriv->plx9080_iobase + PLX_REG_DMAPADR0;
2998 devpriv->plx9080_iobase + PLX_DMA0_PCI_ADDRESS_REG;
2999 unsigned int buffer_index; 2983 unsigned int buffer_index;
3000 2984
3001 do { 2985 do {
@@ -3030,17 +3014,18 @@ static void handle_ao_interrupt(struct comedi_device *dev,
3030 3014
3031 /* spin lock makes sure no one else changes plx dma control reg */ 3015 /* spin lock makes sure no one else changes plx dma control reg */
3032 spin_lock_irqsave(&dev->spinlock, flags); 3016 spin_lock_irqsave(&dev->spinlock, flags);
3033 dma0_status = readb(devpriv->plx9080_iobase + PLX_DMA0_CS_REG); 3017 dma0_status = readb(devpriv->plx9080_iobase + PLX_REG_DMACSR0);
3034 if (plx_status & ICS_DMA0_A) { /* dma chan 0 interrupt */ 3018 if (plx_status & PLX_INTCSR_DMA0IA) { /* dma chan 0 interrupt */
3035 if ((dma0_status & PLX_DMA_EN_BIT) && 3019 if ((dma0_status & PLX_DMACSR_ENABLE) &&
3036 !(dma0_status & PLX_DMA_DONE_BIT)) 3020 !(dma0_status & PLX_DMACSR_DONE)) {
3037 writeb(PLX_DMA_EN_BIT | PLX_CLEAR_DMA_INTR_BIT, 3021 writeb(PLX_DMACSR_ENABLE | PLX_DMACSR_CLEARINTR,
3038 devpriv->plx9080_iobase + PLX_DMA0_CS_REG); 3022 devpriv->plx9080_iobase + PLX_REG_DMACSR0);
3039 else 3023 } else {
3040 writeb(PLX_CLEAR_DMA_INTR_BIT, 3024 writeb(PLX_DMACSR_CLEARINTR,
3041 devpriv->plx9080_iobase + PLX_DMA0_CS_REG); 3025 devpriv->plx9080_iobase + PLX_REG_DMACSR0);
3026 }
3042 spin_unlock_irqrestore(&dev->spinlock, flags); 3027 spin_unlock_irqrestore(&dev->spinlock, flags);
3043 if (dma0_status & PLX_DMA_EN_BIT) { 3028 if (dma0_status & PLX_DMACSR_ENABLE) {
3044 load_ao_dma(dev, cmd); 3029 load_ao_dma(dev, cmd);
3045 /* try to recover from dma end-of-chain event */ 3030 /* try to recover from dma end-of-chain event */
3046 if (ao_dma_needs_restart(dev, dma0_status)) 3031 if (ao_dma_needs_restart(dev, dma0_status))
@@ -3069,7 +3054,7 @@ static irqreturn_t handle_interrupt(int irq, void *d)
3069 uint32_t plx_status; 3054 uint32_t plx_status;
3070 uint32_t plx_bits; 3055 uint32_t plx_bits;
3071 3056
3072 plx_status = readl(devpriv->plx9080_iobase + PLX_INTRCS_REG); 3057 plx_status = readl(devpriv->plx9080_iobase + PLX_REG_INTCSR);
3073 status = readw(devpriv->main_iobase + HW_STATUS_REG); 3058 status = readw(devpriv->main_iobase + HW_STATUS_REG);
3074 3059
3075 /* 3060 /*
@@ -3083,10 +3068,11 @@ static irqreturn_t handle_interrupt(int irq, void *d)
3083 handle_ai_interrupt(dev, status, plx_status); 3068 handle_ai_interrupt(dev, status, plx_status);
3084 handle_ao_interrupt(dev, status, plx_status); 3069 handle_ao_interrupt(dev, status, plx_status);
3085 3070
3086 /* clear possible plx9080 interrupt sources */ 3071 /* clear possible plx9080 interrupt sources */
3087 if (plx_status & ICS_LDIA) { /* clear local doorbell interrupt */ 3072 if (plx_status & PLX_INTCSR_LDBIA) {
3088 plx_bits = readl(devpriv->plx9080_iobase + PLX_DBR_OUT_REG); 3073 /* clear local doorbell interrupt */
3089 writel(plx_bits, devpriv->plx9080_iobase + PLX_DBR_OUT_REG); 3074 plx_bits = readl(devpriv->plx9080_iobase + PLX_REG_L2PDBELL);
3075 writel(plx_bits, devpriv->plx9080_iobase + PLX_REG_L2PDBELL);
3090 } 3076 }
3091 3077
3092 return IRQ_HANDLED; 3078 return IRQ_HANDLED;
@@ -3324,7 +3310,7 @@ static int ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
3324 set_dac_select_reg(dev, cmd); 3310 set_dac_select_reg(dev, cmd);
3325 set_dac_interval_regs(dev, cmd); 3311 set_dac_interval_regs(dev, cmd);
3326 load_first_dma_descriptor(dev, 0, devpriv->ao_dma_desc_bus_addr | 3312 load_first_dma_descriptor(dev, 0, devpriv->ao_dma_desc_bus_addr |
3327 PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT); 3313 PLX_DMADPR_DESCPCI | PLX_DMADPR_TCINTR);
3328 3314
3329 set_dac_control1_reg(dev, cmd); 3315 set_dac_control1_reg(dev, cmd);
3330 s->async->inttrig = ao_inttrig; 3316 s->async->inttrig = ao_inttrig;
@@ -3725,19 +3711,19 @@ static uint16_t read_eeprom(struct comedi_device *dev, uint8_t address)
3725 unsigned int bitstream = (read_command << 8) | address; 3711 unsigned int bitstream = (read_command << 8) | address;
3726 unsigned int bit; 3712 unsigned int bit;
3727 void __iomem * const plx_control_addr = 3713 void __iomem * const plx_control_addr =
3728 devpriv->plx9080_iobase + PLX_CONTROL_REG; 3714 devpriv->plx9080_iobase + PLX_REG_CNTRL;
3729 uint16_t value; 3715 uint16_t value;
3730 static const int value_length = 16; 3716 static const int value_length = 16;
3731 static const int eeprom_udelay = 1; 3717 static const int eeprom_udelay = 1;
3732 3718
3733 udelay(eeprom_udelay); 3719 udelay(eeprom_udelay);
3734 devpriv->plx_control_bits &= ~CTL_EE_CLK & ~CTL_EE_CS; 3720 devpriv->plx_control_bits &= ~PLX_CNTRL_EESK & ~PLX_CNTRL_EECS;
3735 /* make sure we don't send anything to the i2c bus on 4020 */ 3721 /* make sure we don't send anything to the i2c bus on 4020 */
3736 devpriv->plx_control_bits |= CTL_USERO; 3722 devpriv->plx_control_bits |= PLX_CNTRL_USERO;
3737 writel(devpriv->plx_control_bits, plx_control_addr); 3723 writel(devpriv->plx_control_bits, plx_control_addr);
3738 /* activate serial eeprom */ 3724 /* activate serial eeprom */
3739 udelay(eeprom_udelay); 3725 udelay(eeprom_udelay);
3740 devpriv->plx_control_bits |= CTL_EE_CS; 3726 devpriv->plx_control_bits |= PLX_CNTRL_EECS;
3741 writel(devpriv->plx_control_bits, plx_control_addr); 3727 writel(devpriv->plx_control_bits, plx_control_addr);
3742 3728
3743 /* write read command and desired memory address */ 3729 /* write read command and desired memory address */
@@ -3745,16 +3731,16 @@ static uint16_t read_eeprom(struct comedi_device *dev, uint8_t address)
3745 /* set bit to be written */ 3731 /* set bit to be written */
3746 udelay(eeprom_udelay); 3732 udelay(eeprom_udelay);
3747 if (bitstream & bit) 3733 if (bitstream & bit)
3748 devpriv->plx_control_bits |= CTL_EE_W; 3734 devpriv->plx_control_bits |= PLX_CNTRL_EEWB;
3749 else 3735 else
3750 devpriv->plx_control_bits &= ~CTL_EE_W; 3736 devpriv->plx_control_bits &= ~PLX_CNTRL_EEWB;
3751 writel(devpriv->plx_control_bits, plx_control_addr); 3737 writel(devpriv->plx_control_bits, plx_control_addr);
3752 /* clock in bit */ 3738 /* clock in bit */
3753 udelay(eeprom_udelay); 3739 udelay(eeprom_udelay);
3754 devpriv->plx_control_bits |= CTL_EE_CLK; 3740 devpriv->plx_control_bits |= PLX_CNTRL_EESK;
3755 writel(devpriv->plx_control_bits, plx_control_addr); 3741 writel(devpriv->plx_control_bits, plx_control_addr);
3756 udelay(eeprom_udelay); 3742 udelay(eeprom_udelay);
3757 devpriv->plx_control_bits &= ~CTL_EE_CLK; 3743 devpriv->plx_control_bits &= ~PLX_CNTRL_EESK;
3758 writel(devpriv->plx_control_bits, plx_control_addr); 3744 writel(devpriv->plx_control_bits, plx_control_addr);
3759 } 3745 }
3760 /* read back value from eeprom memory location */ 3746 /* read back value from eeprom memory location */
@@ -3762,19 +3748,19 @@ static uint16_t read_eeprom(struct comedi_device *dev, uint8_t address)
3762 for (bit = 1 << (value_length - 1); bit; bit >>= 1) { 3748 for (bit = 1 << (value_length - 1); bit; bit >>= 1) {
3763 /* clock out bit */ 3749 /* clock out bit */
3764 udelay(eeprom_udelay); 3750 udelay(eeprom_udelay);
3765 devpriv->plx_control_bits |= CTL_EE_CLK; 3751 devpriv->plx_control_bits |= PLX_CNTRL_EESK;
3766 writel(devpriv->plx_control_bits, plx_control_addr); 3752 writel(devpriv->plx_control_bits, plx_control_addr);
3767 udelay(eeprom_udelay); 3753 udelay(eeprom_udelay);
3768 devpriv->plx_control_bits &= ~CTL_EE_CLK; 3754 devpriv->plx_control_bits &= ~PLX_CNTRL_EESK;
3769 writel(devpriv->plx_control_bits, plx_control_addr); 3755 writel(devpriv->plx_control_bits, plx_control_addr);
3770 udelay(eeprom_udelay); 3756 udelay(eeprom_udelay);
3771 if (readl(plx_control_addr) & CTL_EE_R) 3757 if (readl(plx_control_addr) & PLX_CNTRL_EERB)
3772 value |= bit; 3758 value |= bit;
3773 } 3759 }
3774 3760
3775 /* deactivate eeprom serial input */ 3761 /* deactivate eeprom serial input */
3776 udelay(eeprom_udelay); 3762 udelay(eeprom_udelay);
3777 devpriv->plx_control_bits &= ~CTL_EE_CS; 3763 devpriv->plx_control_bits &= ~PLX_CNTRL_EECS;
3778 writel(devpriv->plx_control_bits, plx_control_addr); 3764 writel(devpriv->plx_control_bits, plx_control_addr);
3779 3765
3780 return value; 3766 return value;
@@ -3962,7 +3948,8 @@ static int setup_subdevices(struct comedi_device *dev)
3962 3948
3963 /* serial EEPROM, if present */ 3949 /* serial EEPROM, if present */
3964 s = &dev->subdevices[8]; 3950 s = &dev->subdevices[8];
3965 if (readl(devpriv->plx9080_iobase + PLX_CONTROL_REG) & CTL_EECHK) { 3951 if (readl(devpriv->plx9080_iobase + PLX_REG_CNTRL) &
3952 PLX_CNTRL_EEPRESENT) {
3966 s->type = COMEDI_SUBD_MEMORY; 3953 s->type = COMEDI_SUBD_MEMORY;
3967 s->subdev_flags = SDF_READABLE | SDF_INTERNAL; 3954 s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
3968 s->n_chan = 128; 3955 s->n_chan = 128;
@@ -4019,16 +4006,16 @@ static int auto_attach(struct comedi_device *dev,
4019 } 4006 }
4020 4007
4021 /* figure out what local addresses are */ 4008 /* figure out what local addresses are */
4022 local_range = readl(devpriv->plx9080_iobase + PLX_LAS0RNG_REG) & 4009 local_range = readl(devpriv->plx9080_iobase + PLX_REG_LAS0RR) &
4023 LRNG_MEM_MASK; 4010 PLX_LASRR_MEM_MASK;
4024 local_decode = readl(devpriv->plx9080_iobase + PLX_LAS0MAP_REG) & 4011 local_decode = readl(devpriv->plx9080_iobase + PLX_REG_LAS0BA) &
4025 local_range & LMAP_MEM_MASK; 4012 local_range & PLX_LASBA_MEM_MASK;
4026 devpriv->local0_iobase = ((uint32_t)devpriv->main_phys_iobase & 4013 devpriv->local0_iobase = ((uint32_t)devpriv->main_phys_iobase &
4027 ~local_range) | local_decode; 4014 ~local_range) | local_decode;
4028 local_range = readl(devpriv->plx9080_iobase + PLX_LAS1RNG_REG) & 4015 local_range = readl(devpriv->plx9080_iobase + PLX_REG_LAS1RR) &
4029 LRNG_MEM_MASK; 4016 PLX_LASRR_MEM_MASK;
4030 local_decode = readl(devpriv->plx9080_iobase + PLX_LAS1MAP_REG) & 4017 local_decode = readl(devpriv->plx9080_iobase + PLX_REG_LAS1BA) &
4031 local_range & LMAP_MEM_MASK; 4018 local_range & PLX_LASBA_MEM_MASK;
4032 devpriv->local1_iobase = ((uint32_t)devpriv->dio_counter_phys_iobase & 4019 devpriv->local1_iobase = ((uint32_t)devpriv->dio_counter_phys_iobase &
4033 ~local_range) | local_decode; 4020 ~local_range) | local_decode;
4034 4021
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c
index 50b76eccb7d7..64a5ea3810d4 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -55,16 +55,16 @@
55 55
56struct bonded_device { 56struct bonded_device {
57 struct comedi_device *dev; 57 struct comedi_device *dev;
58 unsigned minor; 58 unsigned int minor;
59 unsigned subdev; 59 unsigned int subdev;
60 unsigned nchans; 60 unsigned int nchans;
61}; 61};
62 62
63struct comedi_bond_private { 63struct comedi_bond_private {
64 char name[256]; 64 char name[256];
65 struct bonded_device **devs; 65 struct bonded_device **devs;
66 unsigned ndevs; 66 unsigned int ndevs;
67 unsigned nchans; 67 unsigned int nchans;
68}; 68};
69 69
70static int bonding_dio_insn_bits(struct comedi_device *dev, 70static int bonding_dio_insn_bits(struct comedi_device *dev,
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index a536a15c1d30..65daef0c00d5 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -116,12 +116,12 @@
116#define DAQBOARD2000_SUBSYSTEM_IDS4 0x0004 /* Daqboard/2000 - 4 Dacs */ 116#define DAQBOARD2000_SUBSYSTEM_IDS4 0x0004 /* Daqboard/2000 - 4 Dacs */
117 117
118/* Initialization bits for the Serial EEPROM Control Register */ 118/* Initialization bits for the Serial EEPROM Control Register */
119#define DAQBOARD2000_SECRProgPinHi 0x8001767e 119#define DB2K_SECR_PROG_PIN_HI 0x8001767e
120#define DAQBOARD2000_SECRProgPinLo 0x8000767e 120#define DB2K_SECR_PROG_PIN_LO 0x8000767e
121#define DAQBOARD2000_SECRLocalBusHi 0xc000767e 121#define DB2K_SECR_LOCAL_BUS_HI 0xc000767e
122#define DAQBOARD2000_SECRLocalBusLo 0x8000767e 122#define DB2K_SECR_LOCAL_BUS_LO 0x8000767e
123#define DAQBOARD2000_SECRReloadHi 0xa000767e 123#define DB2K_SECR_RELOAD_HI 0xa000767e
124#define DAQBOARD2000_SECRReloadLo 0x8000767e 124#define DB2K_SECR_RELOAD_LO 0x8000767e
125 125
126/* SECR status bits */ 126/* SECR status bits */
127#define DAQBOARD2000_EEPROM_PRESENT 0x10000000 127#define DAQBOARD2000_EEPROM_PRESENT 0x10000000
@@ -151,119 +151,108 @@ static const struct comedi_lrange range_daqboard2000_ai = {
151/* 151/*
152 * Register Memory Map 152 * Register Memory Map
153 */ 153 */
154#define acqControl 0x00 /* u16 */ 154#define DB2K_REG_ACQ_CONTROL 0x00 /* u16 (w) */
155#define acqScanListFIFO 0x02 /* u16 */ 155#define DB2K_REG_ACQ_STATUS 0x00 /* u16 (r) */
156#define acqPacerClockDivLow 0x04 /* u32 */ 156#define DB2K_REG_ACQ_SCAN_LIST_FIFO 0x02 /* u16 */
157#define acqScanCounter 0x08 /* u16 */ 157#define DB2K_REG_ACQ_PACER_CLOCK_DIV_LOW 0x04 /* u32 */
158#define acqPacerClockDivHigh 0x0a /* u16 */ 158#define DB2K_REG_ACQ_SCAN_COUNTER 0x08 /* u16 */
159#define acqTriggerCount 0x0c /* u16 */ 159#define DB2K_REG_ACQ_PACER_CLOCK_DIV_HIGH 0x0a /* u16 */
160#define acqResultsFIFO 0x10 /* u16 */ 160#define DB2K_REG_ACQ_TRIGGER_COUNT 0x0c /* u16 */
161#define acqResultsShadow 0x14 /* u16 */ 161#define DB2K_REG_ACQ_RESULTS_FIFO 0x10 /* u16 */
162#define acqAdcResult 0x18 /* u16 */ 162#define DB2K_REG_ACQ_RESULTS_SHADOW 0x14 /* u16 */
163#define dacScanCounter 0x1c /* u16 */ 163#define DB2K_REG_ACQ_ADC_RESULT 0x18 /* u16 */
164#define dacControl 0x20 /* u16 */ 164#define DB2K_REG_DAC_SCAN_COUNTER 0x1c /* u16 */
165#define dacFIFO 0x24 /* s16 */ 165#define DB2K_REG_DAC_CONTROL 0x20 /* u16 (w) */
166#define dacPacerClockDiv 0x2a /* u16 */ 166#define DB2K_REG_DAC_STATUS 0x20 /* u16 (r) */
167#define refDacs 0x2c /* u16 */ 167#define DB2K_REG_DAC_FIFO 0x24 /* s16 */
168#define dioControl 0x30 /* u16 */ 168#define DB2K_REG_DAC_PACER_CLOCK_DIV 0x2a /* u16 */
169#define dioP3hsioData 0x32 /* s16 */ 169#define DB2K_REG_REF_DACS 0x2c /* u16 */
170#define dioP3Control 0x34 /* u16 */ 170#define DB2K_REG_DIO_CONTROL 0x30 /* u16 */
171#define calEepromControl 0x36 /* u16 */ 171#define DB2K_REG_P3_HSIO_DATA 0x32 /* s16 */
172#define dacSetting(x) (0x38 + (x)*2) /* s16 */ 172#define DB2K_REG_P3_CONTROL 0x34 /* u16 */
173#define dioP2ExpansionIO8Bit 0x40 /* s16 */ 173#define DB2K_REG_CAL_EEPROM_CONTROL 0x36 /* u16 */
174#define ctrTmrControl 0x80 /* u16 */ 174#define DB2K_REG_DAC_SETTING(x) (0x38 + (x) * 2) /* s16 */
175#define ctrInput(x) (0x88 + (x)*2) /* s16 */ 175#define DB2K_REG_DIO_P2_EXP_IO_8_BIT 0x40 /* s16 */
176#define timerDivisor(x) (0xa0 + (x)*2) /* u16 */ 176#define DB2K_REG_COUNTER_TIMER_CONTROL 0x80 /* u16 */
177#define dmaControl 0xb0 /* u16 */ 177#define DB2K_REG_COUNTER_INPUT(x) (0x88 + (x) * 2) /* s16 */
178#define trigControl 0xb2 /* u16 */ 178#define DB2K_REG_TIMER_DIV(x) (0xa0 + (x) * 2) /* u16 */
179#define calEeprom 0xb8 /* u16 */ 179#define DB2K_REG_DMA_CONTROL 0xb0 /* u16 */
180#define acqDigitalMark 0xba /* u16 */ 180#define DB2K_REG_TRIG_CONTROL 0xb2 /* u16 */
181#define trigDacs 0xbc /* u16 */ 181#define DB2K_REG_CAL_EEPROM 0xb8 /* u16 */
182#define dioP2ExpansionIO16Bit(x) (0xc0 + (x)*2) /* s16 */ 182#define DB2K_REG_ACQ_DIGITAL_MARK 0xba /* u16 */
183#define DB2K_REG_TRIG_DACS 0xbc /* u16 */
184#define DB2K_REG_DIO_P2_EXP_IO_16_BIT(x) (0xc0 + (x) * 2) /* s16 */
183 185
184/* Scan Sequencer programming */ 186/* Scan Sequencer programming */
185#define DAQBOARD2000_SeqStartScanList 0x0011 187#define DB2K_ACQ_CONTROL_SEQ_START_SCAN_LIST 0x0011
186#define DAQBOARD2000_SeqStopScanList 0x0010 188#define DB2K_ACQ_CONTROL_SEQ_STOP_SCAN_LIST 0x0010
187 189
188/* Prepare for acquisition */ 190/* Prepare for acquisition */
189#define DAQBOARD2000_AcqResetScanListFifo 0x0004 191#define DB2K_ACQ_CONTROL_RESET_SCAN_LIST_FIFO 0x0004
190#define DAQBOARD2000_AcqResetResultsFifo 0x0002 192#define DB2K_ACQ_CONTROL_RESET_RESULTS_FIFO 0x0002
191#define DAQBOARD2000_AcqResetConfigPipe 0x0001 193#define DB2K_ACQ_CONTROL_RESET_CONFIG_PIPE 0x0001
192
193/* Acqusition status bits */
194#define DAQBOARD2000_AcqResultsFIFOMore1Sample 0x0001
195#define DAQBOARD2000_AcqResultsFIFOHasValidData 0x0002
196#define DAQBOARD2000_AcqResultsFIFOOverrun 0x0004
197#define DAQBOARD2000_AcqLogicScanning 0x0008
198#define DAQBOARD2000_AcqConfigPipeFull 0x0010
199#define DAQBOARD2000_AcqScanListFIFOEmpty 0x0020
200#define DAQBOARD2000_AcqAdcNotReady 0x0040
201#define DAQBOARD2000_ArbitrationFailure 0x0080
202#define DAQBOARD2000_AcqPacerOverrun 0x0100
203#define DAQBOARD2000_DacPacerOverrun 0x0200
204#define DAQBOARD2000_AcqHardwareError 0x01c0
205
206/* Scan Sequencer programming */
207#define DAQBOARD2000_SeqStartScanList 0x0011
208#define DAQBOARD2000_SeqStopScanList 0x0010
209 194
210/* Pacer Clock Control */ 195/* Pacer Clock Control */
211#define DAQBOARD2000_AdcPacerInternal 0x0030 196#define DB2K_ACQ_CONTROL_ADC_PACER_INTERNAL 0x0030
212#define DAQBOARD2000_AdcPacerExternal 0x0032 197#define DB2K_ACQ_CONTROL_ADC_PACER_EXTERNAL 0x0032
213#define DAQBOARD2000_AdcPacerEnable 0x0031 198#define DB2K_ACQ_CONTROL_ADC_PACER_ENABLE 0x0031
214#define DAQBOARD2000_AdcPacerEnableDacPacer 0x0034 199#define DB2K_ACQ_CONTROL_ADC_PACER_ENABLE_DAC_PACER 0x0034
215#define DAQBOARD2000_AdcPacerDisable 0x0030 200#define DB2K_ACQ_CONTROL_ADC_PACER_DISABLE 0x0030
216#define DAQBOARD2000_AdcPacerNormalMode 0x0060 201#define DB2K_ACQ_CONTROL_ADC_PACER_NORMAL_MODE 0x0060
217#define DAQBOARD2000_AdcPacerCompatibilityMode 0x0061 202#define DB2K_ACQ_CONTROL_ADC_PACER_COMPATIBILITY_MODE 0x0061
218#define DAQBOARD2000_AdcPacerInternalOutEnable 0x0008 203#define DB2K_ACQ_CONTROL_ADC_PACER_INTERNAL_OUT_ENABLE 0x0008
219#define DAQBOARD2000_AdcPacerExternalRising 0x0100 204#define DB2K_ACQ_CONTROL_ADC_PACER_EXTERNAL_RISING 0x0100
205
206/* Acquisition status bits */
207#define DB2K_ACQ_STATUS_RESULTS_FIFO_MORE_1_SAMPLE 0x0001
208#define DB2K_ACQ_STATUS_RESULTS_FIFO_HAS_DATA 0x0002
209#define DB2K_ACQ_STATUS_RESULTS_FIFO_OVERRUN 0x0004
210#define DB2K_ACQ_STATUS_LOGIC_SCANNING 0x0008
211#define DB2K_ACQ_STATUS_CONFIG_PIPE_FULL 0x0010
212#define DB2K_ACQ_STATUS_SCAN_LIST_FIFO_EMPTY 0x0020
213#define DB2K_ACQ_STATUS_ADC_NOT_READY 0x0040
214#define DB2K_ACQ_STATUS_ARBITRATION_FAILURE 0x0080
215#define DB2K_ACQ_STATUS_ADC_PACER_OVERRUN 0x0100
216#define DB2K_ACQ_STATUS_DAC_PACER_OVERRUN 0x0200
220 217
221/* DAC status */ 218/* DAC status */
222#define DAQBOARD2000_DacFull 0x0001 219#define DB2K_DAC_STATUS_DAC_FULL 0x0001
223#define DAQBOARD2000_RefBusy 0x0002 220#define DB2K_DAC_STATUS_REF_BUSY 0x0002
224#define DAQBOARD2000_TrgBusy 0x0004 221#define DB2K_DAC_STATUS_TRIG_BUSY 0x0004
225#define DAQBOARD2000_CalBusy 0x0008 222#define DB2K_DAC_STATUS_CAL_BUSY 0x0008
226#define DAQBOARD2000_Dac0Busy 0x0010 223#define DB2K_DAC_STATUS_DAC_BUSY(x) (0x0010 << (x))
227#define DAQBOARD2000_Dac1Busy 0x0020
228#define DAQBOARD2000_Dac2Busy 0x0040
229#define DAQBOARD2000_Dac3Busy 0x0080
230 224
231/* DAC control */ 225/* DAC control */
232#define DAQBOARD2000_Dac0Enable 0x0021 226#define DB2K_DAC_CONTROL_ENABLE_BIT 0x0001
233#define DAQBOARD2000_Dac1Enable 0x0031 227#define DB2K_DAC_CONTROL_DATA_IS_SIGNED 0x0002
234#define DAQBOARD2000_Dac2Enable 0x0041 228#define DB2K_DAC_CONTROL_RESET_FIFO 0x0004
235#define DAQBOARD2000_Dac3Enable 0x0051 229#define DB2K_DAC_CONTROL_DAC_DISABLE(x) (0x0020 + ((x) << 4))
236#define DAQBOARD2000_DacEnableBit 0x0001 230#define DB2K_DAC_CONTROL_DAC_ENABLE(x) (0x0021 + ((x) << 4))
237#define DAQBOARD2000_Dac0Disable 0x0020 231#define DB2K_DAC_CONTROL_PATTERN_DISABLE 0x0060
238#define DAQBOARD2000_Dac1Disable 0x0030 232#define DB2K_DAC_CONTROL_PATTERN_ENABLE 0x0061
239#define DAQBOARD2000_Dac2Disable 0x0040
240#define DAQBOARD2000_Dac3Disable 0x0050
241#define DAQBOARD2000_DacResetFifo 0x0004
242#define DAQBOARD2000_DacPatternDisable 0x0060
243#define DAQBOARD2000_DacPatternEnable 0x0061
244#define DAQBOARD2000_DacSelectSignedData 0x0002
245#define DAQBOARD2000_DacSelectUnsignedData 0x0000
246 233
247/* Trigger Control */ 234/* Trigger Control */
248#define DAQBOARD2000_TrigAnalog 0x0000 235#define DB2K_TRIG_CONTROL_TYPE_ANALOG 0x0000
249#define DAQBOARD2000_TrigTTL 0x0010 236#define DB2K_TRIG_CONTROL_TYPE_TTL 0x0010
250#define DAQBOARD2000_TrigTransHiLo 0x0004 237#define DB2K_TRIG_CONTROL_EDGE_HI_LO 0x0004
251#define DAQBOARD2000_TrigTransLoHi 0x0000 238#define DB2K_TRIG_CONTROL_EDGE_LO_HI 0x0000
252#define DAQBOARD2000_TrigAbove 0x0000 239#define DB2K_TRIG_CONTROL_LEVEL_ABOVE 0x0000
253#define DAQBOARD2000_TrigBelow 0x0004 240#define DB2K_TRIG_CONTROL_LEVEL_BELOW 0x0004
254#define DAQBOARD2000_TrigLevelSense 0x0002 241#define DB2K_TRIG_CONTROL_SENSE_LEVEL 0x0002
255#define DAQBOARD2000_TrigEdgeSense 0x0000 242#define DB2K_TRIG_CONTROL_SENSE_EDGE 0x0000
256#define DAQBOARD2000_TrigEnable 0x0001 243#define DB2K_TRIG_CONTROL_ENABLE 0x0001
257#define DAQBOARD2000_TrigDisable 0x0000 244#define DB2K_TRIG_CONTROL_DISABLE 0x0000
258 245
259/* Reference Dac Selection */ 246/* Reference Dac Selection */
260#define DAQBOARD2000_PosRefDacSelect 0x0100 247#define DB2K_REF_DACS_SET 0x0080
261#define DAQBOARD2000_NegRefDacSelect 0x0000 248#define DB2K_REF_DACS_SELECT_POS_REF 0x0100
249#define DB2K_REF_DACS_SELECT_NEG_REF 0x0000
262 250
263struct daq200_boardtype { 251struct daq200_boardtype {
264 const char *name; 252 const char *name;
265 int id; 253 int id;
266}; 254};
255
267static const struct daq200_boardtype boardtypes[] = { 256static const struct daq200_boardtype boardtypes[] = {
268 {"ids2", DAQBOARD2000_SUBSYSTEM_IDS2}, 257 {"ids2", DAQBOARD2000_SUBSYSTEM_IDS2},
269 {"ids4", DAQBOARD2000_SUBSYSTEM_IDS4}, 258 {"ids4", DAQBOARD2000_SUBSYSTEM_IDS4},
@@ -276,15 +265,16 @@ struct daqboard2000_private {
276 void __iomem *plx; 265 void __iomem *plx;
277}; 266};
278 267
279static void writeAcqScanListEntry(struct comedi_device *dev, u16 entry) 268static void daqboard2000_write_acq_scan_list_entry(struct comedi_device *dev,
269 u16 entry)
280{ 270{
281 /* udelay(4); */ 271 writew(entry & 0x00ff, dev->mmio + DB2K_REG_ACQ_SCAN_LIST_FIFO);
282 writew(entry & 0x00ff, dev->mmio + acqScanListFIFO); 272 writew((entry >> 8) & 0x00ff,
283 /* udelay(4); */ 273 dev->mmio + DB2K_REG_ACQ_SCAN_LIST_FIFO);
284 writew((entry >> 8) & 0x00ff, dev->mmio + acqScanListFIFO);
285} 274}
286 275
287static void setup_sampling(struct comedi_device *dev, int chan, int gain) 276static void daqboard2000_setup_sampling(struct comedi_device *dev, int chan,
277 int gain)
288{ 278{
289 u16 word0, word1, word2, word3; 279 u16 word0, word1, word2, word3;
290 280
@@ -315,17 +305,13 @@ static void setup_sampling(struct comedi_device *dev, int chan, int gain)
315 word3 = 0; 305 word3 = 0;
316 break; 306 break;
317 } 307 }
318/*
319 dev->eeprom.correctionDACSE[i][j][k].offset = 0x800;
320 dev->eeprom.correctionDACSE[i][j][k].gain = 0xc00;
321*/
322 /* These should be read from EEPROM */ 308 /* These should be read from EEPROM */
323 word2 |= 0x0800; 309 word2 |= 0x0800; /* offset */
324 word3 |= 0xc000; 310 word3 |= 0xc000; /* gain */
325 writeAcqScanListEntry(dev, word0); 311 daqboard2000_write_acq_scan_list_entry(dev, word0);
326 writeAcqScanListEntry(dev, word1); 312 daqboard2000_write_acq_scan_list_entry(dev, word1);
327 writeAcqScanListEntry(dev, word2); 313 daqboard2000_write_acq_scan_list_entry(dev, word2);
328 writeAcqScanListEntry(dev, word3); 314 daqboard2000_write_acq_scan_list_entry(dev, word3);
329} 315}
330 316
331static int daqboard2000_ai_status(struct comedi_device *dev, 317static int daqboard2000_ai_status(struct comedi_device *dev,
@@ -335,7 +321,7 @@ static int daqboard2000_ai_status(struct comedi_device *dev,
335{ 321{
336 unsigned int status; 322 unsigned int status;
337 323
338 status = readw(dev->mmio + acqControl); 324 status = readw(dev->mmio + DB2K_REG_ACQ_STATUS);
339 if (status & context) 325 if (status & context)
340 return 0; 326 return 0;
341 return -EBUSY; 327 return -EBUSY;
@@ -350,50 +336,58 @@ static int daqboard2000_ai_insn_read(struct comedi_device *dev,
350 int ret; 336 int ret;
351 int i; 337 int i;
352 338
353 writew(DAQBOARD2000_AcqResetScanListFifo | 339 writew(DB2K_ACQ_CONTROL_RESET_SCAN_LIST_FIFO |
354 DAQBOARD2000_AcqResetResultsFifo | 340 DB2K_ACQ_CONTROL_RESET_RESULTS_FIFO |
355 DAQBOARD2000_AcqResetConfigPipe, dev->mmio + acqControl); 341 DB2K_ACQ_CONTROL_RESET_CONFIG_PIPE,
342 dev->mmio + DB2K_REG_ACQ_CONTROL);
356 343
357 /* 344 /*
358 * If pacer clock is not set to some high value (> 10 us), we 345 * If pacer clock is not set to some high value (> 10 us), we
359 * risk multiple samples to be put into the result FIFO. 346 * risk multiple samples to be put into the result FIFO.
360 */ 347 */
361 /* 1 second, should be long enough */ 348 /* 1 second, should be long enough */
362 writel(1000000, dev->mmio + acqPacerClockDivLow); 349 writel(1000000, dev->mmio + DB2K_REG_ACQ_PACER_CLOCK_DIV_LOW);
363 writew(0, dev->mmio + acqPacerClockDivHigh); 350 writew(0, dev->mmio + DB2K_REG_ACQ_PACER_CLOCK_DIV_HIGH);
364 351
365 gain = CR_RANGE(insn->chanspec); 352 gain = CR_RANGE(insn->chanspec);
366 chan = CR_CHAN(insn->chanspec); 353 chan = CR_CHAN(insn->chanspec);
367 354
368 /* This doesn't look efficient. I decided to take the conservative 355 /*
356 * This doesn't look efficient. I decided to take the conservative
369 * approach when I did the insn conversion. Perhaps it would be 357 * approach when I did the insn conversion. Perhaps it would be
370 * better to have broken it completely, then someone would have been 358 * better to have broken it completely, then someone would have been
371 * forced to fix it. --ds */ 359 * forced to fix it. --ds
360 */
372 for (i = 0; i < insn->n; i++) { 361 for (i = 0; i < insn->n; i++) {
373 setup_sampling(dev, chan, gain); 362 daqboard2000_setup_sampling(dev, chan, gain);
374 /* Enable reading from the scanlist FIFO */ 363 /* Enable reading from the scanlist FIFO */
375 writew(DAQBOARD2000_SeqStartScanList, dev->mmio + acqControl); 364 writew(DB2K_ACQ_CONTROL_SEQ_START_SCAN_LIST,
365 dev->mmio + DB2K_REG_ACQ_CONTROL);
376 366
377 ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status, 367 ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status,
378 DAQBOARD2000_AcqConfigPipeFull); 368 DB2K_ACQ_STATUS_CONFIG_PIPE_FULL);
379 if (ret) 369 if (ret)
380 return ret; 370 return ret;
381 371
382 writew(DAQBOARD2000_AdcPacerEnable, dev->mmio + acqControl); 372 writew(DB2K_ACQ_CONTROL_ADC_PACER_ENABLE,
373 dev->mmio + DB2K_REG_ACQ_CONTROL);
383 374
384 ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status, 375 ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status,
385 DAQBOARD2000_AcqLogicScanning); 376 DB2K_ACQ_STATUS_LOGIC_SCANNING);
386 if (ret) 377 if (ret)
387 return ret; 378 return ret;
388 379
389 ret = comedi_timeout(dev, s, insn, daqboard2000_ai_status, 380 ret =
390 DAQBOARD2000_AcqResultsFIFOHasValidData); 381 comedi_timeout(dev, s, insn, daqboard2000_ai_status,
382 DB2K_ACQ_STATUS_RESULTS_FIFO_HAS_DATA);
391 if (ret) 383 if (ret)
392 return ret; 384 return ret;
393 385
394 data[i] = readw(dev->mmio + acqResultsFIFO); 386 data[i] = readw(dev->mmio + DB2K_REG_ACQ_RESULTS_FIFO);
395 writew(DAQBOARD2000_AdcPacerDisable, dev->mmio + acqControl); 387 writew(DB2K_ACQ_CONTROL_ADC_PACER_DISABLE,
396 writew(DAQBOARD2000_SeqStopScanList, dev->mmio + acqControl); 388 dev->mmio + DB2K_REG_ACQ_CONTROL);
389 writew(DB2K_ACQ_CONTROL_SEQ_STOP_SCAN_LIST,
390 dev->mmio + DB2K_REG_ACQ_CONTROL);
397 } 391 }
398 392
399 return i; 393 return i;
@@ -407,8 +401,8 @@ static int daqboard2000_ao_eoc(struct comedi_device *dev,
407 unsigned int chan = CR_CHAN(insn->chanspec); 401 unsigned int chan = CR_CHAN(insn->chanspec);
408 unsigned int status; 402 unsigned int status;
409 403
410 status = readw(dev->mmio + dacControl); 404 status = readw(dev->mmio + DB2K_REG_DAC_STATUS);
411 if ((status & ((chan + 1) * 0x0010)) == 0) 405 if ((status & DB2K_DAC_STATUS_DAC_BUSY(chan)) == 0)
412 return 0; 406 return 0;
413 return -EBUSY; 407 return -EBUSY;
414} 408}
@@ -425,7 +419,7 @@ static int daqboard2000_ao_insn_write(struct comedi_device *dev,
425 unsigned int val = data[i]; 419 unsigned int val = data[i];
426 int ret; 420 int ret;
427 421
428 writew(val, dev->mmio + dacSetting(chan)); 422 writew(val, dev->mmio + DB2K_REG_DAC_SETTING(chan));
429 423
430 ret = comedi_timeout(dev, s, insn, daqboard2000_ao_eoc, 0); 424 ret = comedi_timeout(dev, s, insn, daqboard2000_ao_eoc, 0);
431 if (ret) 425 if (ret)
@@ -437,39 +431,39 @@ static int daqboard2000_ao_insn_write(struct comedi_device *dev,
437 return insn->n; 431 return insn->n;
438} 432}
439 433
440static void daqboard2000_resetLocalBus(struct comedi_device *dev) 434static void daqboard2000_reset_local_bus(struct comedi_device *dev)
441{ 435{
442 struct daqboard2000_private *devpriv = dev->private; 436 struct daqboard2000_private *devpriv = dev->private;
443 437
444 writel(DAQBOARD2000_SECRLocalBusHi, devpriv->plx + 0x6c); 438 writel(DB2K_SECR_LOCAL_BUS_HI, devpriv->plx + 0x6c);
445 mdelay(10); 439 mdelay(10);
446 writel(DAQBOARD2000_SECRLocalBusLo, devpriv->plx + 0x6c); 440 writel(DB2K_SECR_LOCAL_BUS_LO, devpriv->plx + 0x6c);
447 mdelay(10); 441 mdelay(10);
448} 442}
449 443
450static void daqboard2000_reloadPLX(struct comedi_device *dev) 444static void daqboard2000_reload_plx(struct comedi_device *dev)
451{ 445{
452 struct daqboard2000_private *devpriv = dev->private; 446 struct daqboard2000_private *devpriv = dev->private;
453 447
454 writel(DAQBOARD2000_SECRReloadLo, devpriv->plx + 0x6c); 448 writel(DB2K_SECR_RELOAD_LO, devpriv->plx + 0x6c);
455 mdelay(10); 449 mdelay(10);
456 writel(DAQBOARD2000_SECRReloadHi, devpriv->plx + 0x6c); 450 writel(DB2K_SECR_RELOAD_HI, devpriv->plx + 0x6c);
457 mdelay(10); 451 mdelay(10);
458 writel(DAQBOARD2000_SECRReloadLo, devpriv->plx + 0x6c); 452 writel(DB2K_SECR_RELOAD_LO, devpriv->plx + 0x6c);
459 mdelay(10); 453 mdelay(10);
460} 454}
461 455
462static void daqboard2000_pulseProgPin(struct comedi_device *dev) 456static void daqboard2000_pulse_prog_pin(struct comedi_device *dev)
463{ 457{
464 struct daqboard2000_private *devpriv = dev->private; 458 struct daqboard2000_private *devpriv = dev->private;
465 459
466 writel(DAQBOARD2000_SECRProgPinHi, devpriv->plx + 0x6c); 460 writel(DB2K_SECR_PROG_PIN_HI, devpriv->plx + 0x6c);
467 mdelay(10); 461 mdelay(10);
468 writel(DAQBOARD2000_SECRProgPinLo, devpriv->plx + 0x6c); 462 writel(DB2K_SECR_PROG_PIN_LO, devpriv->plx + 0x6c);
469 mdelay(10); /* Not in the original code, but I like symmetry... */ 463 mdelay(10); /* Not in the original code, but I like symmetry... */
470} 464}
471 465
472static int daqboard2000_pollCPLD(struct comedi_device *dev, int mask) 466static int daqboard2000_poll_cpld(struct comedi_device *dev, int mask)
473{ 467{
474 int result = 0; 468 int result = 0;
475 int i; 469 int i;
@@ -482,17 +476,17 @@ static int daqboard2000_pollCPLD(struct comedi_device *dev, int mask)
482 result = 1; 476 result = 1;
483 break; 477 break;
484 } 478 }
485 udelay(100); 479 usleep_range(100, 1000);
486 } 480 }
487 udelay(5); 481 udelay(5);
488 return result; 482 return result;
489} 483}
490 484
491static int daqboard2000_writeCPLD(struct comedi_device *dev, int data) 485static int daqboard2000_write_cpld(struct comedi_device *dev, int data)
492{ 486{
493 int result = 0; 487 int result = 0;
494 488
495 udelay(10); 489 usleep_range(10, 20);
496 writew(data, dev->mmio + 0x1000); 490 writew(data, dev->mmio + 0x1000);
497 if ((readw(dev->mmio + 0x1000) & DAQBOARD2000_CPLD_INIT) == 491 if ((readw(dev->mmio + 0x1000) & DAQBOARD2000_CPLD_INIT) ==
498 DAQBOARD2000_CPLD_INIT) { 492 DAQBOARD2000_CPLD_INIT) {
@@ -501,9 +495,9 @@ static int daqboard2000_writeCPLD(struct comedi_device *dev, int data)
501 return result; 495 return result;
502} 496}
503 497
504static int initialize_daqboard2000(struct comedi_device *dev, 498static int daqboard2000_load_firmware(struct comedi_device *dev,
505 const u8 *cpld_array, size_t len, 499 const u8 *cpld_array, size_t len,
506 unsigned long context) 500 unsigned long context)
507{ 501{
508 struct daqboard2000_private *devpriv = dev->private; 502 struct daqboard2000_private *devpriv = dev->private;
509 int result = -EIO; 503 int result = -EIO;
@@ -518,10 +512,10 @@ static int initialize_daqboard2000(struct comedi_device *dev,
518 return -EIO; 512 return -EIO;
519 513
520 for (retry = 0; retry < 3; retry++) { 514 for (retry = 0; retry < 3; retry++) {
521 daqboard2000_resetLocalBus(dev); 515 daqboard2000_reset_local_bus(dev);
522 daqboard2000_reloadPLX(dev); 516 daqboard2000_reload_plx(dev);
523 daqboard2000_pulseProgPin(dev); 517 daqboard2000_pulse_prog_pin(dev);
524 if (daqboard2000_pollCPLD(dev, DAQBOARD2000_CPLD_INIT)) { 518 if (daqboard2000_poll_cpld(dev, DAQBOARD2000_CPLD_INIT)) {
525 for (i = 0; i < len; i++) { 519 for (i = 0; i < len; i++) {
526 if (cpld_array[i] == 0xff && 520 if (cpld_array[i] == 0xff &&
527 cpld_array[i + 1] == 0x20) 521 cpld_array[i + 1] == 0x20)
@@ -530,12 +524,12 @@ static int initialize_daqboard2000(struct comedi_device *dev,
530 for (; i < len; i += 2) { 524 for (; i < len; i += 2) {
531 int data = 525 int data =
532 (cpld_array[i] << 8) + cpld_array[i + 1]; 526 (cpld_array[i] << 8) + cpld_array[i + 1];
533 if (!daqboard2000_writeCPLD(dev, data)) 527 if (!daqboard2000_write_cpld(dev, data))
534 break; 528 break;
535 } 529 }
536 if (i >= len) { 530 if (i >= len) {
537 daqboard2000_resetLocalBus(dev); 531 daqboard2000_reset_local_bus(dev);
538 daqboard2000_reloadPLX(dev); 532 daqboard2000_reload_plx(dev);
539 result = 0; 533 result = 0;
540 break; 534 break;
541 } 535 }
@@ -544,79 +538,83 @@ static int initialize_daqboard2000(struct comedi_device *dev,
544 return result; 538 return result;
545} 539}
546 540
547static void daqboard2000_adcStopDmaTransfer(struct comedi_device *dev) 541static void daqboard2000_adc_stop_dma_transfer(struct comedi_device *dev)
548{ 542{
549} 543}
550 544
551static void daqboard2000_adcDisarm(struct comedi_device *dev) 545static void daqboard2000_adc_disarm(struct comedi_device *dev)
552{ 546{
553 /* Disable hardware triggers */ 547 /* Disable hardware triggers */
554 udelay(2); 548 udelay(2);
555 writew(DAQBOARD2000_TrigAnalog | DAQBOARD2000_TrigDisable, 549 writew(DB2K_TRIG_CONTROL_TYPE_ANALOG | DB2K_TRIG_CONTROL_DISABLE,
556 dev->mmio + trigControl); 550 dev->mmio + DB2K_REG_TRIG_CONTROL);
557 udelay(2); 551 udelay(2);
558 writew(DAQBOARD2000_TrigTTL | DAQBOARD2000_TrigDisable, 552 writew(DB2K_TRIG_CONTROL_TYPE_TTL | DB2K_TRIG_CONTROL_DISABLE,
559 dev->mmio + trigControl); 553 dev->mmio + DB2K_REG_TRIG_CONTROL);
560 554
561 /* Stop the scan list FIFO from loading the configuration pipe */ 555 /* Stop the scan list FIFO from loading the configuration pipe */
562 udelay(2); 556 udelay(2);
563 writew(DAQBOARD2000_SeqStopScanList, dev->mmio + acqControl); 557 writew(DB2K_ACQ_CONTROL_SEQ_STOP_SCAN_LIST,
558 dev->mmio + DB2K_REG_ACQ_CONTROL);
564 559
565 /* Stop the pacer clock */ 560 /* Stop the pacer clock */
566 udelay(2); 561 udelay(2);
567 writew(DAQBOARD2000_AdcPacerDisable, dev->mmio + acqControl); 562 writew(DB2K_ACQ_CONTROL_ADC_PACER_DISABLE,
563 dev->mmio + DB2K_REG_ACQ_CONTROL);
568 564
569 /* Stop the input dma (abort channel 1) */ 565 /* Stop the input dma (abort channel 1) */
570 daqboard2000_adcStopDmaTransfer(dev); 566 daqboard2000_adc_stop_dma_transfer(dev);
571} 567}
572 568
573static void daqboard2000_activateReferenceDacs(struct comedi_device *dev) 569static void daqboard2000_activate_reference_dacs(struct comedi_device *dev)
574{ 570{
575 unsigned int val; 571 unsigned int val;
576 int timeout; 572 int timeout;
577 573
578 /* Set the + reference dac value in the FPGA */ 574 /* Set the + reference dac value in the FPGA */
579 writew(0x80 | DAQBOARD2000_PosRefDacSelect, dev->mmio + refDacs); 575 writew(DB2K_REF_DACS_SET | DB2K_REF_DACS_SELECT_POS_REF,
576 dev->mmio + DB2K_REG_REF_DACS);
580 for (timeout = 0; timeout < 20; timeout++) { 577 for (timeout = 0; timeout < 20; timeout++) {
581 val = readw(dev->mmio + dacControl); 578 val = readw(dev->mmio + DB2K_REG_DAC_STATUS);
582 if ((val & DAQBOARD2000_RefBusy) == 0) 579 if ((val & DB2K_DAC_STATUS_REF_BUSY) == 0)
583 break; 580 break;
584 udelay(2); 581 udelay(2);
585 } 582 }
586 583
587 /* Set the - reference dac value in the FPGA */ 584 /* Set the - reference dac value in the FPGA */
588 writew(0x80 | DAQBOARD2000_NegRefDacSelect, dev->mmio + refDacs); 585 writew(DB2K_REF_DACS_SET | DB2K_REF_DACS_SELECT_NEG_REF,
586 dev->mmio + DB2K_REG_REF_DACS);
589 for (timeout = 0; timeout < 20; timeout++) { 587 for (timeout = 0; timeout < 20; timeout++) {
590 val = readw(dev->mmio + dacControl); 588 val = readw(dev->mmio + DB2K_REG_DAC_STATUS);
591 if ((val & DAQBOARD2000_RefBusy) == 0) 589 if ((val & DB2K_DAC_STATUS_REF_BUSY) == 0)
592 break; 590 break;
593 udelay(2); 591 udelay(2);
594 } 592 }
595} 593}
596 594
597static void daqboard2000_initializeCtrs(struct comedi_device *dev) 595static void daqboard2000_initialize_ctrs(struct comedi_device *dev)
598{ 596{
599} 597}
600 598
601static void daqboard2000_initializeTmrs(struct comedi_device *dev) 599static void daqboard2000_initialize_tmrs(struct comedi_device *dev)
602{ 600{
603} 601}
604 602
605static void daqboard2000_dacDisarm(struct comedi_device *dev) 603static void daqboard2000_dac_disarm(struct comedi_device *dev)
606{ 604{
607} 605}
608 606
609static void daqboard2000_initializeAdc(struct comedi_device *dev) 607static void daqboard2000_initialize_adc(struct comedi_device *dev)
610{ 608{
611 daqboard2000_adcDisarm(dev); 609 daqboard2000_adc_disarm(dev);
612 daqboard2000_activateReferenceDacs(dev); 610 daqboard2000_activate_reference_dacs(dev);
613 daqboard2000_initializeCtrs(dev); 611 daqboard2000_initialize_ctrs(dev);
614 daqboard2000_initializeTmrs(dev); 612 daqboard2000_initialize_tmrs(dev);
615} 613}
616 614
617static void daqboard2000_initializeDac(struct comedi_device *dev) 615static void daqboard2000_initialize_dac(struct comedi_device *dev)
618{ 616{
619 daqboard2000_dacDisarm(dev); 617 daqboard2000_dac_disarm(dev);
620} 618}
621 619
622static int daqboard2000_8255_cb(struct comedi_device *dev, 620static int daqboard2000_8255_cb(struct comedi_device *dev,
@@ -683,12 +681,12 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
683 681
684 result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev, 682 result = comedi_load_firmware(dev, &comedi_to_pci_dev(dev)->dev,
685 DAQBOARD2000_FIRMWARE, 683 DAQBOARD2000_FIRMWARE,
686 initialize_daqboard2000, 0); 684 daqboard2000_load_firmware, 0);
687 if (result < 0) 685 if (result < 0)
688 return result; 686 return result;
689 687
690 daqboard2000_initializeAdc(dev); 688 daqboard2000_initialize_adc(dev);
691 daqboard2000_initializeDac(dev); 689 daqboard2000_initialize_dac(dev);
692 690
693 s = &dev->subdevices[0]; 691 s = &dev->subdevices[0];
694 /* ai subdevice */ 692 /* ai subdevice */
@@ -714,7 +712,7 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
714 712
715 s = &dev->subdevices[2]; 713 s = &dev->subdevices[2];
716 return subdev_8255_init(dev, s, daqboard2000_8255_cb, 714 return subdev_8255_init(dev, s, daqboard2000_8255_cb,
717 dioP2ExpansionIO8Bit); 715 DB2K_REG_DIO_P2_EXP_IO_8_BIT);
718} 716}
719 717
720static void daqboard2000_detach(struct comedi_device *dev) 718static void daqboard2000_detach(struct comedi_device *dev)
diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index fd8e0b76f764..5d157951f63f 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -92,37 +92,37 @@
92#define DAS16_AO_LSB_REG(x) ((x) ? 0x06 : 0x04) 92#define DAS16_AO_LSB_REG(x) ((x) ? 0x06 : 0x04)
93#define DAS16_AO_MSB_REG(x) ((x) ? 0x07 : 0x05) 93#define DAS16_AO_MSB_REG(x) ((x) ? 0x07 : 0x05)
94#define DAS16_STATUS_REG 0x08 94#define DAS16_STATUS_REG 0x08
95#define DAS16_STATUS_BUSY (1 << 7) 95#define DAS16_STATUS_BUSY BIT(7)
96#define DAS16_STATUS_UNIPOLAR (1 << 6) 96#define DAS16_STATUS_UNIPOLAR BIT(6)
97#define DAS16_STATUS_MUXBIT (1 << 5) 97#define DAS16_STATUS_MUXBIT BIT(5)
98#define DAS16_STATUS_INT (1 << 4) 98#define DAS16_STATUS_INT BIT(4)
99#define DAS16_CTRL_REG 0x09 99#define DAS16_CTRL_REG 0x09
100#define DAS16_CTRL_INTE (1 << 7) 100#define DAS16_CTRL_INTE BIT(7)
101#define DAS16_CTRL_IRQ(x) (((x) & 0x7) << 4) 101#define DAS16_CTRL_IRQ(x) (((x) & 0x7) << 4)
102#define DAS16_CTRL_DMAE (1 << 2) 102#define DAS16_CTRL_DMAE BIT(2)
103#define DAS16_CTRL_PACING_MASK (3 << 0) 103#define DAS16_CTRL_PACING_MASK (3 << 0)
104#define DAS16_CTRL_INT_PACER (3 << 0) 104#define DAS16_CTRL_INT_PACER (3 << 0)
105#define DAS16_CTRL_EXT_PACER (2 << 0) 105#define DAS16_CTRL_EXT_PACER (2 << 0)
106#define DAS16_CTRL_SOFT_PACER (0 << 0) 106#define DAS16_CTRL_SOFT_PACER (0 << 0)
107#define DAS16_PACER_REG 0x0a 107#define DAS16_PACER_REG 0x0a
108#define DAS16_PACER_BURST_LEN(x) (((x) & 0xf) << 4) 108#define DAS16_PACER_BURST_LEN(x) (((x) & 0xf) << 4)
109#define DAS16_PACER_CTR0 (1 << 1) 109#define DAS16_PACER_CTR0 BIT(1)
110#define DAS16_PACER_TRIG0 (1 << 0) 110#define DAS16_PACER_TRIG0 BIT(0)
111#define DAS16_GAIN_REG 0x0b 111#define DAS16_GAIN_REG 0x0b
112#define DAS16_TIMER_BASE_REG 0x0c /* to 0x0f */ 112#define DAS16_TIMER_BASE_REG 0x0c /* to 0x0f */
113 113
114#define DAS1600_CONV_REG 0x404 114#define DAS1600_CONV_REG 0x404
115#define DAS1600_CONV_DISABLE (1 << 6) 115#define DAS1600_CONV_DISABLE BIT(6)
116#define DAS1600_BURST_REG 0x405 116#define DAS1600_BURST_REG 0x405
117#define DAS1600_BURST_VAL (1 << 6) 117#define DAS1600_BURST_VAL BIT(6)
118#define DAS1600_ENABLE_REG 0x406 118#define DAS1600_ENABLE_REG 0x406
119#define DAS1600_ENABLE_VAL (1 << 6) 119#define DAS1600_ENABLE_VAL BIT(6)
120#define DAS1600_STATUS_REG 0x407 120#define DAS1600_STATUS_REG 0x407
121#define DAS1600_STATUS_BME (1 << 6) 121#define DAS1600_STATUS_BME BIT(6)
122#define DAS1600_STATUS_ME (1 << 5) 122#define DAS1600_STATUS_ME BIT(5)
123#define DAS1600_STATUS_CD (1 << 4) 123#define DAS1600_STATUS_CD BIT(4)
124#define DAS1600_STATUS_WS (1 << 1) 124#define DAS1600_STATUS_WS BIT(1)
125#define DAS1600_STATUS_CLK_10MHZ (1 << 0) 125#define DAS1600_STATUS_CLK_10MHZ BIT(0)
126 126
127static const struct comedi_lrange range_das1x01_bip = { 127static const struct comedi_lrange range_das1x01_bip = {
128 4, { 128 4, {
@@ -198,6 +198,7 @@ enum {
198 das16_pg_1601, 198 das16_pg_1601,
199 das16_pg_1602, 199 das16_pg_1602,
200}; 200};
201
201static const int *const das16_gainlists[] = { 202static const int *const das16_gainlists[] = {
202 NULL, 203 NULL,
203 das16jr_gainlist, 204 das16jr_gainlist,
@@ -428,8 +429,10 @@ static const struct das16_board das16_boards[] = {
428 }, 429 },
429}; 430};
430 431
431/* Period for timer interrupt in jiffies. It's a function 432/*
432 * to deal with possibility of dynamic HZ patches */ 433 * Period for timer interrupt in jiffies. It's a function
434 * to deal with possibility of dynamic HZ patches
435 */
433static inline int timer_period(void) 436static inline int timer_period(void)
434{ 437{
435 return HZ / 20; 438 return HZ / 20;
diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c
index 3a37373fbb6f..bb8d6ec0632e 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -1,56 +1,52 @@
1/* 1/*
2 comedi/drivers/das16m1.c 2 * Comedi driver for CIO-DAS16/M1
3 CIO-DAS16/M1 driver 3 * Author: Frank Mori Hess, based on code from the das16 driver.
4 Author: Frank Mori Hess, based on code from the das16 4 * Copyright (C) 2001 Frank Mori Hess <fmhess@users.sourceforge.net>
5 driver. 5 *
6 Copyright (C) 2001 Frank Mori Hess <fmhess@users.sourceforge.net> 6 * COMEDI - Linux Control and Measurement Device Interface
7 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 COMEDI - Linux Control and Measurement Device Interface 8 *
9 Copyright (C) 2000 David A. Schleef <ds@schleef.org> 9 * This program is free software; you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
11 This program is free software; you can redistribute it and/or modify 11 * the Free Software Foundation; either version 2 of the License, or
12 it under the terms of the GNU General Public License as published by 12 * (at your option) any later version.
13 the Free Software Foundation; either version 2 of the License, or 13 *
14 (at your option) any later version. 14 * This program is distributed in the hope that it will be useful,
15 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 This program is distributed in the hope that it will be useful, 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * GNU General Public License for more details.
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 */
19 GNU General Public License for more details. 19
20*/
21/* 20/*
22Driver: das16m1 21 * Driver: das16m1
23Description: CIO-DAS16/M1 22 * Description: CIO-DAS16/M1
24Author: Frank Mori Hess <fmhess@users.sourceforge.net> 23 * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
25Devices: [Measurement Computing] CIO-DAS16/M1 (das16m1) 24 * Devices: [Measurement Computing] CIO-DAS16/M1 (das16m1)
26Status: works 25 * Status: works
27 26 *
28This driver supports a single board - the CIO-DAS16/M1. 27 * This driver supports a single board - the CIO-DAS16/M1. As far as I know,
29As far as I know, there are no other boards that have 28 * there are no other boards that have the same register layout. Even the
30the same register layout. Even the CIO-DAS16/M1/16 is 29 * CIO-DAS16/M1/16 is significantly different.
31significantly different. 30 *
32 31 * I was _barely_ able to reach the full 1 MHz capability of this board, using
33I was _barely_ able to reach the full 1 MHz capability 32 * a hard real-time interrupt (set the TRIG_RT flag in your struct comedi_cmd
34of this board, using a hard real-time interrupt 33 * and use rtlinux or RTAI). The board can't do dma, so the bottleneck is
35(set the TRIG_RT flag in your struct comedi_cmd and use 34 * pulling the data across the ISA bus. I timed the interrupt handler, and it
36rtlinux or RTAI). The board can't do dma, so the bottleneck is 35 * took my computer ~470 microseconds to pull 512 samples from the board. So
37pulling the data across the ISA bus. I timed the interrupt 36 * at 1 Mhz sampling rate, expect your CPU to be spending almost all of its
38handler, and it took my computer ~470 microseconds to pull 512 37 * time in the interrupt handler.
39samples from the board. So at 1 Mhz sampling rate, 38 *
40expect your CPU to be spending almost all of its 39 * This board has some unusual restrictions for its channel/gain list. If the
41time in the interrupt handler. 40 * list has 2 or more channels in it, then two conditions must be satisfied:
42 41 * (1) - even/odd channels must appear at even/odd indices in the list
43This board has some unusual restrictions for its channel/gain list. If the 42 * (2) - the list must have an even number of entries.
44list has 2 or more channels in it, then two conditions must be satisfied: 43 *
45(1) - even/odd channels must appear at even/odd indices in the list 44 * Configuration options:
46(2) - the list must have an even number of entries. 45 * [0] - base io address
47 46 * [1] - irq (optional, but you probably want it)
48Options: 47 *
49 [0] - base io address 48 * irq can be omitted, although the cmd interface will not work without it.
50 [1] - irq (optional, but you probably want it) 49 */
51
52irq can be omitted, although the cmd interface will not work without it.
53*/
54 50
55#include <linux/module.h> 51#include <linux/module.h>
56#include <linux/slab.h> 52#include <linux/slab.h>
@@ -60,52 +56,38 @@ irq can be omitted, although the cmd interface will not work without it.
60#include "8255.h" 56#include "8255.h"
61#include "comedi_8254.h" 57#include "comedi_8254.h"
62 58
63#define DAS16M1_SIZE2 8
64
65#define FIFO_SIZE 1024 /* 1024 sample fifo */
66
67/* 59/*
68 CIO-DAS16_M1.pdf 60 * Register map (dev->iobase)
69 61 */
70 "cio-das16/m1" 62#define DAS16M1_AI_REG 0x00 /* 16-bit register */
71 63#define DAS16M1_AI_TO_CHAN(x) (((x) >> 0) & 0xf)
72 0 a/d bits 0-3, mux start 12 bit 64#define DAS16M1_AI_TO_SAMPLE(x) (((x) >> 4) & 0xfff)
73 1 a/d bits 4-11 unused 65#define DAS16M1_CS_REG 0x02
74 2 status control 66#define DAS16M1_CS_EXT_TRIG BIT(0)
75 3 di 4 bit do 4 bit 67#define DAS16M1_CS_OVRUN BIT(5)
76 4 unused clear interrupt 68#define DAS16M1_CS_IRQDATA BIT(7)
77 5 interrupt, pacer 69#define DAS16M1_DI_REG 0x03
78 6 channel/gain queue address 70#define DAS16M1_DO_REG 0x03
79 7 channel/gain queue data 71#define DAS16M1_CLR_INTR_REG 0x04
80 89ab 8254 72#define DAS16M1_INTR_CTRL_REG 0x05
81 cdef 8254 73#define DAS16M1_INTR_CTRL_PACER(x) (((x) & 0x3) << 0)
82 400 8255 74#define DAS16M1_INTR_CTRL_PACER_EXT DAS16M1_INTR_CTRL_PACER(2)
83 404-407 8254 75#define DAS16M1_INTR_CTRL_PACER_INT DAS16M1_INTR_CTRL_PACER(3)
84 76#define DAS16M1_INTR_CTRL_PACER_MASK DAS16M1_INTR_CTRL_PACER(3)
85*/ 77#define DAS16M1_INTR_CTRL_IRQ(x) (((x) & 0x7) << 4)
86 78#define DAS16M1_INTR_CTRL_INTE BIT(7)
87#define DAS16M1_AI 0 /* 16-bit wide register */ 79#define DAS16M1_Q_ADDR_REG 0x06
88#define AI_CHAN(x) ((x) & 0xf) 80#define DAS16M1_Q_REG 0x07
89#define DAS16M1_CS 2 81#define DAS16M1_Q_CHAN(x) (((x) & 0x7) << 0)
90#define EXT_TRIG_BIT 0x1 82#define DAS16M1_Q_RANGE(x) (((x) & 0xf) << 4)
91#define OVRUN 0x20 83#define DAS16M1_8254_IOBASE1 0x08
92#define IRQDATA 0x80 84#define DAS16M1_8254_IOBASE2 0x0c
93#define DAS16M1_DIO 3 85#define DAS16M1_8255_IOBASE 0x400
94#define DAS16M1_CLEAR_INTR 4 86#define DAS16M1_8254_IOBASE3 0x404
95#define DAS16M1_INTR_CONTROL 5 87
96#define EXT_PACER 0x2 88#define DAS16M1_SIZE2 0x08
97#define INT_PACER 0x3 89
98#define PACER_MASK 0x3 90#define DAS16M1_AI_FIFO_SZ 1024 /* # samples */
99#define INTE 0x80
100#define DAS16M1_QUEUE_ADDR 6
101#define DAS16M1_QUEUE_DATA 7
102#define Q_CHAN(x) ((x) & 0x7)
103#define Q_RANGE(x) (((x) & 0xf) << 4)
104#define UNIPOLAR 0x40
105#define DAS16M1_8254_FIRST 0x8
106#define DAS16M1_8254_SECOND 0xc
107#define DAS16M1_82C55 0x400
108#define DAS16M1_8254_THIRD 0x404
109 91
110static const struct comedi_lrange range_das16m1 = { 92static const struct comedi_lrange range_das16m1 = {
111 9, { 93 9, {
@@ -121,29 +103,46 @@ static const struct comedi_lrange range_das16m1 = {
121 } 103 }
122}; 104};
123 105
124struct das16m1_private_struct { 106struct das16m1_private {
125 struct comedi_8254 *counter; 107 struct comedi_8254 *counter;
126 unsigned int control_state; 108 unsigned int intr_ctrl;
127 unsigned int adc_count; /* number of samples completed */ 109 unsigned int adc_count;
128 /* initial value in lower half of hardware conversion counter,
129 * needed to keep track of whether new count has been loaded into
130 * counter yet (loaded by first sample conversion) */
131 u16 initial_hw_count; 110 u16 initial_hw_count;
132 unsigned short ai_buffer[FIFO_SIZE]; 111 unsigned short ai_buffer[DAS16M1_AI_FIFO_SZ];
133 unsigned long extra_iobase; 112 unsigned long extra_iobase;
134}; 113};
135 114
136static inline unsigned short munge_sample(unsigned short data) 115static void das16m1_ai_set_queue(struct comedi_device *dev,
116 unsigned int *chanspec, unsigned int len)
137{ 117{
138 return (data >> 4) & 0xfff; 118 unsigned int i;
119
120 for (i = 0; i < len; i++) {
121 unsigned int chan = CR_CHAN(chanspec[i]);
122 unsigned int range = CR_RANGE(chanspec[i]);
123
124 outb(i, dev->iobase + DAS16M1_Q_ADDR_REG);
125 outb(DAS16M1_Q_CHAN(chan) | DAS16M1_Q_RANGE(range),
126 dev->iobase + DAS16M1_Q_REG);
127 }
139} 128}
140 129
141static void munge_sample_array(unsigned short *array, unsigned int num_elements) 130static void das16m1_ai_munge(struct comedi_device *dev,
131 struct comedi_subdevice *s,
132 void *data, unsigned int num_bytes,
133 unsigned int start_chan_index)
142{ 134{
135 unsigned short *array = data;
136 unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes);
143 unsigned int i; 137 unsigned int i;
144 138
145 for (i = 0; i < num_elements; i++) 139 /*
146 array[i] = munge_sample(array[i]); 140 * The fifo values have the channel number in the lower 4-bits and
141 * the sample in the upper 12-bits. This just shifts the values
142 * to remove the channel numbers.
143 */
144 for (i = 0; i < nsamples; i++)
145 array[i] = DAS16M1_AI_TO_SAMPLE(array[i]);
147} 146}
148 147
149static int das16m1_ai_check_chanlist(struct comedi_device *dev, 148static int das16m1_ai_check_chanlist(struct comedi_device *dev,
@@ -174,8 +173,9 @@ static int das16m1_ai_check_chanlist(struct comedi_device *dev,
174 return 0; 173 return 0;
175} 174}
176 175
177static int das16m1_cmd_test(struct comedi_device *dev, 176static int das16m1_ai_cmdtest(struct comedi_device *dev,
178 struct comedi_subdevice *s, struct comedi_cmd *cmd) 177 struct comedi_subdevice *s,
178 struct comedi_cmd *cmd)
179{ 179{
180 int err = 0; 180 int err = 0;
181 181
@@ -245,17 +245,13 @@ static int das16m1_cmd_test(struct comedi_device *dev,
245 return 0; 245 return 0;
246} 246}
247 247
248static int das16m1_cmd_exec(struct comedi_device *dev, 248static int das16m1_ai_cmd(struct comedi_device *dev,
249 struct comedi_subdevice *s) 249 struct comedi_subdevice *s)
250{ 250{
251 struct das16m1_private_struct *devpriv = dev->private; 251 struct das16m1_private *devpriv = dev->private;
252 struct comedi_async *async = s->async; 252 struct comedi_async *async = s->async;
253 struct comedi_cmd *cmd = &async->cmd; 253 struct comedi_cmd *cmd = &async->cmd;
254 unsigned int byte, i; 254 unsigned int byte;
255
256 /* disable interrupts and internal pacer */
257 devpriv->control_state &= ~INTE & ~PACER_MASK;
258 outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL);
259 255
260 /* set software count */ 256 /* set software count */
261 devpriv->adc_count = 0; 257 devpriv->adc_count = 0;
@@ -274,48 +270,47 @@ static int das16m1_cmd_exec(struct comedi_device *dev,
274 */ 270 */
275 devpriv->initial_hw_count = comedi_8254_read(devpriv->counter, 1); 271 devpriv->initial_hw_count = comedi_8254_read(devpriv->counter, 1);
276 272
277 /* setup channel/gain queue */ 273 das16m1_ai_set_queue(dev, cmd->chanlist, cmd->chanlist_len);
278 for (i = 0; i < cmd->chanlist_len; i++) {
279 outb(i, dev->iobase + DAS16M1_QUEUE_ADDR);
280 byte =
281 Q_CHAN(CR_CHAN(cmd->chanlist[i])) |
282 Q_RANGE(CR_RANGE(cmd->chanlist[i]));
283 outb(byte, dev->iobase + DAS16M1_QUEUE_DATA);
284 }
285 274
286 /* enable interrupts and set internal pacer counter mode and counts */ 275 /* enable interrupts and set internal pacer counter mode and counts */
287 devpriv->control_state &= ~PACER_MASK; 276 devpriv->intr_ctrl &= ~DAS16M1_INTR_CTRL_PACER_MASK;
288 if (cmd->convert_src == TRIG_TIMER) { 277 if (cmd->convert_src == TRIG_TIMER) {
289 comedi_8254_update_divisors(dev->pacer); 278 comedi_8254_update_divisors(dev->pacer);
290 comedi_8254_pacer_enable(dev->pacer, 1, 2, true); 279 comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
291 devpriv->control_state |= INT_PACER; 280 devpriv->intr_ctrl |= DAS16M1_INTR_CTRL_PACER_INT;
292 } else { /* TRIG_EXT */ 281 } else { /* TRIG_EXT */
293 devpriv->control_state |= EXT_PACER; 282 devpriv->intr_ctrl |= DAS16M1_INTR_CTRL_PACER_EXT;
294 } 283 }
295 284
296 /* set control & status register */ 285 /* set control & status register */
297 byte = 0; 286 byte = 0;
298 /* if we are using external start trigger (also board dislikes having 287 /*
299 * both start and conversion triggers external simultaneously) */ 288 * If we are using external start trigger (also board dislikes having
289 * both start and conversion triggers external simultaneously).
290 */
300 if (cmd->start_src == TRIG_EXT && cmd->convert_src != TRIG_EXT) 291 if (cmd->start_src == TRIG_EXT && cmd->convert_src != TRIG_EXT)
301 byte |= EXT_TRIG_BIT; 292 byte |= DAS16M1_CS_EXT_TRIG;
302 293
303 outb(byte, dev->iobase + DAS16M1_CS); 294 outb(byte, dev->iobase + DAS16M1_CS_REG);
304 /* clear interrupt bit */ 295
305 outb(0, dev->iobase + DAS16M1_CLEAR_INTR); 296 /* clear interrupt */
297 outb(0, dev->iobase + DAS16M1_CLR_INTR_REG);
306 298
307 devpriv->control_state |= INTE; 299 devpriv->intr_ctrl |= DAS16M1_INTR_CTRL_INTE;
308 outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL); 300 outb(devpriv->intr_ctrl, dev->iobase + DAS16M1_INTR_CTRL_REG);
309 301
310 return 0; 302 return 0;
311} 303}
312 304
313static int das16m1_cancel(struct comedi_device *dev, struct comedi_subdevice *s) 305static int das16m1_ai_cancel(struct comedi_device *dev,
306 struct comedi_subdevice *s)
314{ 307{
315 struct das16m1_private_struct *devpriv = dev->private; 308 struct das16m1_private *devpriv = dev->private;
316 309
317 devpriv->control_state &= ~INTE & ~PACER_MASK; 310 /* disable interrupts and pacer */
318 outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL); 311 devpriv->intr_ctrl &= ~(DAS16M1_INTR_CTRL_INTE |
312 DAS16M1_INTR_CTRL_PACER_MASK);
313 outb(devpriv->intr_ctrl, dev->iobase + DAS16M1_INTR_CTRL_REG);
319 314
320 return 0; 315 return 0;
321} 316}
@@ -327,67 +322,58 @@ static int das16m1_ai_eoc(struct comedi_device *dev,
327{ 322{
328 unsigned int status; 323 unsigned int status;
329 324
330 status = inb(dev->iobase + DAS16M1_CS); 325 status = inb(dev->iobase + DAS16M1_CS_REG);
331 if (status & IRQDATA) 326 if (status & DAS16M1_CS_IRQDATA)
332 return 0; 327 return 0;
333 return -EBUSY; 328 return -EBUSY;
334} 329}
335 330
336static int das16m1_ai_rinsn(struct comedi_device *dev, 331static int das16m1_ai_insn_read(struct comedi_device *dev,
337 struct comedi_subdevice *s, 332 struct comedi_subdevice *s,
338 struct comedi_insn *insn, unsigned int *data) 333 struct comedi_insn *insn,
334 unsigned int *data)
339{ 335{
340 struct das16m1_private_struct *devpriv = dev->private;
341 int ret; 336 int ret;
342 int n; 337 int i;
343 int byte; 338
344 339 das16m1_ai_set_queue(dev, &insn->chanspec, 1);
345 /* disable interrupts and internal pacer */ 340
346 devpriv->control_state &= ~INTE & ~PACER_MASK; 341 for (i = 0; i < insn->n; i++) {
347 outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL); 342 unsigned short val;
348 343
349 /* setup channel/gain queue */ 344 /* clear interrupt */
350 outb(0, dev->iobase + DAS16M1_QUEUE_ADDR); 345 outb(0, dev->iobase + DAS16M1_CLR_INTR_REG);
351 byte =
352 Q_CHAN(CR_CHAN(insn->chanspec)) | Q_RANGE(CR_RANGE(insn->chanspec));
353 outb(byte, dev->iobase + DAS16M1_QUEUE_DATA);
354
355 for (n = 0; n < insn->n; n++) {
356 /* clear IRQDATA bit */
357 outb(0, dev->iobase + DAS16M1_CLEAR_INTR);
358 /* trigger conversion */ 346 /* trigger conversion */
359 outb(0, dev->iobase); 347 outb(0, dev->iobase + DAS16M1_AI_REG);
360 348
361 ret = comedi_timeout(dev, s, insn, das16m1_ai_eoc, 0); 349 ret = comedi_timeout(dev, s, insn, das16m1_ai_eoc, 0);
362 if (ret) 350 if (ret)
363 return ret; 351 return ret;
364 352
365 data[n] = munge_sample(inw(dev->iobase)); 353 val = inw(dev->iobase + DAS16M1_AI_REG);
354 data[i] = DAS16M1_AI_TO_SAMPLE(val);
366 } 355 }
367 356
368 return n; 357 return insn->n;
369} 358}
370 359
371static int das16m1_di_rbits(struct comedi_device *dev, 360static int das16m1_di_insn_bits(struct comedi_device *dev,
372 struct comedi_subdevice *s, 361 struct comedi_subdevice *s,
373 struct comedi_insn *insn, unsigned int *data) 362 struct comedi_insn *insn,
363 unsigned int *data)
374{ 364{
375 unsigned int bits; 365 data[1] = inb(dev->iobase + DAS16M1_DI_REG) & 0xf;
376
377 bits = inb(dev->iobase + DAS16M1_DIO) & 0xf;
378 data[1] = bits;
379 data[0] = 0;
380 366
381 return insn->n; 367 return insn->n;
382} 368}
383 369
384static int das16m1_do_wbits(struct comedi_device *dev, 370static int das16m1_do_insn_bits(struct comedi_device *dev,
385 struct comedi_subdevice *s, 371 struct comedi_subdevice *s,
386 struct comedi_insn *insn, 372 struct comedi_insn *insn,
387 unsigned int *data) 373 unsigned int *data)
388{ 374{
389 if (comedi_dio_update_state(s, data)) 375 if (comedi_dio_update_state(s, data))
390 outb(s->state, dev->iobase + DAS16M1_DIO); 376 outb(s->state, dev->iobase + DAS16M1_DO_REG);
391 377
392 data[1] = s->state; 378 data[1] = s->state;
393 379
@@ -396,33 +382,33 @@ static int das16m1_do_wbits(struct comedi_device *dev,
396 382
397static void das16m1_handler(struct comedi_device *dev, unsigned int status) 383static void das16m1_handler(struct comedi_device *dev, unsigned int status)
398{ 384{
399 struct das16m1_private_struct *devpriv = dev->private; 385 struct das16m1_private *devpriv = dev->private;
400 struct comedi_subdevice *s; 386 struct comedi_subdevice *s = dev->read_subdev;
401 struct comedi_async *async; 387 struct comedi_async *async = s->async;
402 struct comedi_cmd *cmd; 388 struct comedi_cmd *cmd = &async->cmd;
403 u16 num_samples; 389 u16 num_samples;
404 u16 hw_counter; 390 u16 hw_counter;
405 391
406 s = dev->read_subdev;
407 async = s->async;
408 cmd = &async->cmd;
409
410 /* figure out how many samples are in fifo */ 392 /* figure out how many samples are in fifo */
411 hw_counter = comedi_8254_read(devpriv->counter, 1); 393 hw_counter = comedi_8254_read(devpriv->counter, 1);
412 /* make sure hardware counter reading is not bogus due to initial value 394 /*
413 * not having been loaded yet */ 395 * Make sure hardware counter reading is not bogus due to initial
396 * value not having been loaded yet.
397 */
414 if (devpriv->adc_count == 0 && 398 if (devpriv->adc_count == 0 &&
415 hw_counter == devpriv->initial_hw_count) { 399 hw_counter == devpriv->initial_hw_count) {
416 num_samples = 0; 400 num_samples = 0;
417 } else { 401 } else {
418 /* The calculation of num_samples looks odd, but it uses the 402 /*
403 * The calculation of num_samples looks odd, but it uses the
419 * following facts. 16 bit hardware counter is initialized with 404 * following facts. 16 bit hardware counter is initialized with
420 * value of zero (which really means 0x1000). The counter 405 * value of zero (which really means 0x1000). The counter
421 * decrements by one on each conversion (when the counter 406 * decrements by one on each conversion (when the counter
422 * decrements from zero it goes to 0xffff). num_samples is a 407 * decrements from zero it goes to 0xffff). num_samples is a
423 * 16 bit variable, so it will roll over in a similar fashion 408 * 16 bit variable, so it will roll over in a similar fashion
424 * to the hardware counter. Work it out, and this is what you 409 * to the hardware counter. Work it out, and this is what you
425 * get. */ 410 * get.
411 */
426 num_samples = -hw_counter - devpriv->adc_count; 412 num_samples = -hw_counter - devpriv->adc_count;
427 } 413 }
428 /* check if we only need some of the points */ 414 /* check if we only need some of the points */
@@ -431,10 +417,9 @@ static void das16m1_handler(struct comedi_device *dev, unsigned int status)
431 num_samples = cmd->stop_arg * cmd->chanlist_len; 417 num_samples = cmd->stop_arg * cmd->chanlist_len;
432 } 418 }
433 /* make sure we dont try to get too many points if fifo has overrun */ 419 /* make sure we dont try to get too many points if fifo has overrun */
434 if (num_samples > FIFO_SIZE) 420 if (num_samples > DAS16M1_AI_FIFO_SZ)
435 num_samples = FIFO_SIZE; 421 num_samples = DAS16M1_AI_FIFO_SZ;
436 insw(dev->iobase, devpriv->ai_buffer, num_samples); 422 insw(dev->iobase, devpriv->ai_buffer, num_samples);
437 munge_sample_array(devpriv->ai_buffer, num_samples);
438 comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples); 423 comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples);
439 devpriv->adc_count += num_samples; 424 devpriv->adc_count += num_samples;
440 425
@@ -445,9 +430,11 @@ static void das16m1_handler(struct comedi_device *dev, unsigned int status)
445 } 430 }
446 } 431 }
447 432
448 /* this probably won't catch overruns since the card doesn't generate 433 /*
449 * overrun interrupts, but we might as well try */ 434 * This probably won't catch overruns since the card doesn't generate
450 if (status & OVRUN) { 435 * overrun interrupts, but we might as well try.
436 */
437 if (status & DAS16M1_CS_OVRUN) {
451 async->events |= COMEDI_CB_ERROR; 438 async->events |= COMEDI_CB_ERROR;
452 dev_err(dev->class_dev, "fifo overflow\n"); 439 dev_err(dev->class_dev, "fifo overflow\n");
453 } 440 }
@@ -455,14 +442,15 @@ static void das16m1_handler(struct comedi_device *dev, unsigned int status)
455 comedi_handle_events(dev, s); 442 comedi_handle_events(dev, s);
456} 443}
457 444
458static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s) 445static int das16m1_ai_poll(struct comedi_device *dev,
446 struct comedi_subdevice *s)
459{ 447{
460 unsigned long flags; 448 unsigned long flags;
461 unsigned int status; 449 unsigned int status;
462 450
463 /* prevent race with interrupt handler */ 451 /* prevent race with interrupt handler */
464 spin_lock_irqsave(&dev->spinlock, flags); 452 spin_lock_irqsave(&dev->spinlock, flags);
465 status = inb(dev->iobase + DAS16M1_CS); 453 status = inb(dev->iobase + DAS16M1_CS_REG);
466 das16m1_handler(dev, status); 454 das16m1_handler(dev, status);
467 spin_unlock_irqrestore(&dev->spinlock, flags); 455 spin_unlock_irqrestore(&dev->spinlock, flags);
468 456
@@ -481,9 +469,9 @@ static irqreturn_t das16m1_interrupt(int irq, void *d)
481 /* prevent race with comedi_poll() */ 469 /* prevent race with comedi_poll() */
482 spin_lock(&dev->spinlock); 470 spin_lock(&dev->spinlock);
483 471
484 status = inb(dev->iobase + DAS16M1_CS); 472 status = inb(dev->iobase + DAS16M1_CS_REG);
485 473
486 if ((status & (IRQDATA | OVRUN)) == 0) { 474 if ((status & (DAS16M1_CS_IRQDATA | DAS16M1_CS_OVRUN)) == 0) {
487 dev_err(dev->class_dev, "spurious interrupt\n"); 475 dev_err(dev->class_dev, "spurious interrupt\n");
488 spin_unlock(&dev->spinlock); 476 spin_unlock(&dev->spinlock);
489 return IRQ_NONE; 477 return IRQ_NONE;
@@ -492,7 +480,7 @@ static irqreturn_t das16m1_interrupt(int irq, void *d)
492 das16m1_handler(dev, status); 480 das16m1_handler(dev, status);
493 481
494 /* clear interrupt */ 482 /* clear interrupt */
495 outb(0, dev->iobase + DAS16M1_CLEAR_INTR); 483 outb(0, dev->iobase + DAS16M1_CLR_INTR_REG);
496 484
497 spin_unlock(&dev->spinlock); 485 spin_unlock(&dev->spinlock);
498 return IRQ_HANDLED; 486 return IRQ_HANDLED;
@@ -522,15 +510,10 @@ static int das16m1_irq_bits(unsigned int irq)
522 } 510 }
523} 511}
524 512
525/*
526 * Options list:
527 * 0 I/O base
528 * 1 IRQ
529 */
530static int das16m1_attach(struct comedi_device *dev, 513static int das16m1_attach(struct comedi_device *dev,
531 struct comedi_devconfig *it) 514 struct comedi_devconfig *it)
532{ 515{
533 struct das16m1_private_struct *devpriv; 516 struct das16m1_private *devpriv;
534 struct comedi_subdevice *s; 517 struct comedi_subdevice *s;
535 int ret; 518 int ret;
536 519
@@ -541,12 +524,12 @@ static int das16m1_attach(struct comedi_device *dev,
541 ret = comedi_request_region(dev, it->options[0], 0x10); 524 ret = comedi_request_region(dev, it->options[0], 0x10);
542 if (ret) 525 if (ret)
543 return ret; 526 return ret;
544 /* Request an additional region for the 8255 */ 527 /* Request an additional region for the 8255 and 3rd 8254 */
545 ret = __comedi_request_region(dev, dev->iobase + DAS16M1_82C55, 528 ret = __comedi_request_region(dev, dev->iobase + DAS16M1_8255_IOBASE,
546 DAS16M1_SIZE2); 529 DAS16M1_SIZE2);
547 if (ret) 530 if (ret)
548 return ret; 531 return ret;
549 devpriv->extra_iobase = dev->iobase + DAS16M1_82C55; 532 devpriv->extra_iobase = dev->iobase + DAS16M1_8255_IOBASE;
550 533
551 /* only irqs 2, 3, 4, 5, 6, 7, 10, 11, 12, 14, and 15 are valid */ 534 /* only irqs 2, 3, 4, 5, 6, 7, 10, 11, 12, 14, and 15 are valid */
552 if ((1 << it->options[1]) & 0xdcfc) { 535 if ((1 << it->options[1]) & 0xdcfc) {
@@ -556,12 +539,12 @@ static int das16m1_attach(struct comedi_device *dev,
556 dev->irq = it->options[1]; 539 dev->irq = it->options[1];
557 } 540 }
558 541
559 dev->pacer = comedi_8254_init(dev->iobase + DAS16M1_8254_SECOND, 542 dev->pacer = comedi_8254_init(dev->iobase + DAS16M1_8254_IOBASE2,
560 I8254_OSC_BASE_10MHZ, I8254_IO8, 0); 543 I8254_OSC_BASE_10MHZ, I8254_IO8, 0);
561 if (!dev->pacer) 544 if (!dev->pacer)
562 return -ENOMEM; 545 return -ENOMEM;
563 546
564 devpriv->counter = comedi_8254_init(dev->iobase + DAS16M1_8254_FIRST, 547 devpriv->counter = comedi_8254_init(dev->iobase + DAS16M1_8254_IOBASE1,
565 0, I8254_IO8, 0); 548 0, I8254_IO8, 0);
566 if (!devpriv->counter) 549 if (!devpriv->counter)
567 return -ENOMEM; 550 return -ENOMEM;
@@ -570,61 +553,62 @@ static int das16m1_attach(struct comedi_device *dev,
570 if (ret) 553 if (ret)
571 return ret; 554 return ret;
572 555
556 /* Analog Input subdevice */
573 s = &dev->subdevices[0]; 557 s = &dev->subdevices[0];
574 /* ai */ 558 s->type = COMEDI_SUBD_AI;
575 s->type = COMEDI_SUBD_AI; 559 s->subdev_flags = SDF_READABLE | SDF_DIFF;
576 s->subdev_flags = SDF_READABLE | SDF_DIFF; 560 s->n_chan = 8;
577 s->n_chan = 8; 561 s->maxdata = 0x0fff;
578 s->maxdata = (1 << 12) - 1; 562 s->range_table = &range_das16m1;
579 s->range_table = &range_das16m1; 563 s->insn_read = das16m1_ai_insn_read;
580 s->insn_read = das16m1_ai_rinsn;
581 if (dev->irq) { 564 if (dev->irq) {
582 dev->read_subdev = s; 565 dev->read_subdev = s;
583 s->subdev_flags |= SDF_CMD_READ; 566 s->subdev_flags |= SDF_CMD_READ;
584 s->len_chanlist = 256; 567 s->len_chanlist = 256;
585 s->do_cmdtest = das16m1_cmd_test; 568 s->do_cmdtest = das16m1_ai_cmdtest;
586 s->do_cmd = das16m1_cmd_exec; 569 s->do_cmd = das16m1_ai_cmd;
587 s->cancel = das16m1_cancel; 570 s->cancel = das16m1_ai_cancel;
588 s->poll = das16m1_poll; 571 s->poll = das16m1_ai_poll;
572 s->munge = das16m1_ai_munge;
589 } 573 }
590 574
575 /* Digital Input subdevice */
591 s = &dev->subdevices[1]; 576 s = &dev->subdevices[1];
592 /* di */ 577 s->type = COMEDI_SUBD_DI;
593 s->type = COMEDI_SUBD_DI; 578 s->subdev_flags = SDF_READABLE;
594 s->subdev_flags = SDF_READABLE; 579 s->n_chan = 4;
595 s->n_chan = 4; 580 s->maxdata = 1;
596 s->maxdata = 1; 581 s->range_table = &range_digital;
597 s->range_table = &range_digital; 582 s->insn_bits = das16m1_di_insn_bits;
598 s->insn_bits = das16m1_di_rbits; 583
599 584 /* Digital Output subdevice */
600 s = &dev->subdevices[2]; 585 s = &dev->subdevices[2];
601 /* do */ 586 s->type = COMEDI_SUBD_DO;
602 s->type = COMEDI_SUBD_DO; 587 s->subdev_flags = SDF_WRITABLE;
603 s->subdev_flags = SDF_WRITABLE; 588 s->n_chan = 4;
604 s->n_chan = 4; 589 s->maxdata = 1;
605 s->maxdata = 1; 590 s->range_table = &range_digital;
606 s->range_table = &range_digital; 591 s->insn_bits = das16m1_do_insn_bits;
607 s->insn_bits = das16m1_do_wbits; 592
608 593 /* Digital I/O subdevice (8255) */
609 s = &dev->subdevices[3]; 594 s = &dev->subdevices[3];
610 /* 8255 */ 595 ret = subdev_8255_init(dev, s, NULL, DAS16M1_8255_IOBASE);
611 ret = subdev_8255_init(dev, s, NULL, DAS16M1_82C55);
612 if (ret) 596 if (ret)
613 return ret; 597 return ret;
614 598
615 /* initialize digital output lines */ 599 /* initialize digital output lines */
616 outb(0, dev->iobase + DAS16M1_DIO); 600 outb(0, dev->iobase + DAS16M1_DO_REG);
617 601
618 /* set the interrupt level */ 602 /* set the interrupt level */
619 devpriv->control_state = das16m1_irq_bits(dev->irq) << 4; 603 devpriv->intr_ctrl = DAS16M1_INTR_CTRL_IRQ(das16m1_irq_bits(dev->irq));
620 outb(devpriv->control_state, dev->iobase + DAS16M1_INTR_CONTROL); 604 outb(devpriv->intr_ctrl, dev->iobase + DAS16M1_INTR_CTRL_REG);
621 605
622 return 0; 606 return 0;
623} 607}
624 608
625static void das16m1_detach(struct comedi_device *dev) 609static void das16m1_detach(struct comedi_device *dev)
626{ 610{
627 struct das16m1_private_struct *devpriv = dev->private; 611 struct das16m1_private *devpriv = dev->private;
628 612
629 if (devpriv) { 613 if (devpriv) {
630 if (devpriv->extra_iobase) 614 if (devpriv->extra_iobase)
@@ -643,5 +627,5 @@ static struct comedi_driver das16m1_driver = {
643module_comedi_driver(das16m1_driver); 627module_comedi_driver(das16m1_driver);
644 628
645MODULE_AUTHOR("Comedi http://www.comedi.org"); 629MODULE_AUTHOR("Comedi http://www.comedi.org");
646MODULE_DESCRIPTION("Comedi low-level driver"); 630MODULE_DESCRIPTION("Comedi driver for CIO-DAS16/M1 ISA cards");
647MODULE_LICENSE("GPL"); 631MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/das6402.c b/drivers/staging/comedi/drivers/das6402.c
index 1701294b79cd..0fdf5e02182f 100644
--- a/drivers/staging/comedi/drivers/das6402.c
+++ b/drivers/staging/comedi/drivers/das6402.c
@@ -50,48 +50,50 @@
50#define DAS6402_AO_LSB_REG(x) (0x04 + ((x) * 2)) 50#define DAS6402_AO_LSB_REG(x) (0x04 + ((x) * 2))
51#define DAS6402_AO_MSB_REG(x) (0x05 + ((x) * 2)) 51#define DAS6402_AO_MSB_REG(x) (0x05 + ((x) * 2))
52#define DAS6402_STATUS_REG 0x08 52#define DAS6402_STATUS_REG 0x08
53#define DAS6402_STATUS_FFNE (1 << 0) 53#define DAS6402_STATUS_FFNE BIT(0)
54#define DAS6402_STATUS_FHALF (1 << 1) 54#define DAS6402_STATUS_FHALF BIT(1)
55#define DAS6402_STATUS_FFULL (1 << 2) 55#define DAS6402_STATUS_FFULL BIT(2)
56#define DAS6402_STATUS_XINT (1 << 3) 56#define DAS6402_STATUS_XINT BIT(3)
57#define DAS6402_STATUS_INT (1 << 4) 57#define DAS6402_STATUS_INT BIT(4)
58#define DAS6402_STATUS_XTRIG (1 << 5) 58#define DAS6402_STATUS_XTRIG BIT(5)
59#define DAS6402_STATUS_INDGT (1 << 6) 59#define DAS6402_STATUS_INDGT BIT(6)
60#define DAS6402_STATUS_10MHZ (1 << 7) 60#define DAS6402_STATUS_10MHZ BIT(7)
61#define DAS6402_STATUS_W_CLRINT (1 << 0) 61#define DAS6402_STATUS_W_CLRINT BIT(0)
62#define DAS6402_STATUS_W_CLRXTR (1 << 1) 62#define DAS6402_STATUS_W_CLRXTR BIT(1)
63#define DAS6402_STATUS_W_CLRXIN (1 << 2) 63#define DAS6402_STATUS_W_CLRXIN BIT(2)
64#define DAS6402_STATUS_W_EXTEND (1 << 4) 64#define DAS6402_STATUS_W_EXTEND BIT(4)
65#define DAS6402_STATUS_W_ARMED (1 << 5) 65#define DAS6402_STATUS_W_ARMED BIT(5)
66#define DAS6402_STATUS_W_POSTMODE (1 << 6) 66#define DAS6402_STATUS_W_POSTMODE BIT(6)
67#define DAS6402_STATUS_W_10MHZ (1 << 7) 67#define DAS6402_STATUS_W_10MHZ BIT(7)
68#define DAS6402_CTRL_REG 0x09 68#define DAS6402_CTRL_REG 0x09
69#define DAS6402_CTRL_SOFT_TRIG (0 << 0) 69#define DAS6402_CTRL_TRIG(x) ((x) << 0)
70#define DAS6402_CTRL_EXT_FALL_TRIG (1 << 0) 70#define DAS6402_CTRL_SOFT_TRIG DAS6402_CTRL_TRIG(0)
71#define DAS6402_CTRL_EXT_RISE_TRIG (2 << 0) 71#define DAS6402_CTRL_EXT_FALL_TRIG DAS6402_CTRL_TRIG(1)
72#define DAS6402_CTRL_PACER_TRIG (3 << 0) 72#define DAS6402_CTRL_EXT_RISE_TRIG DAS6402_CTRL_TRIG(2)
73#define DAS6402_CTRL_BURSTEN (1 << 2) 73#define DAS6402_CTRL_PACER_TRIG DAS6402_CTRL_TRIG(3)
74#define DAS6402_CTRL_XINTE (1 << 3) 74#define DAS6402_CTRL_BURSTEN BIT(2)
75#define DAS6402_CTRL_XINTE BIT(3)
75#define DAS6402_CTRL_IRQ(x) ((x) << 4) 76#define DAS6402_CTRL_IRQ(x) ((x) << 4)
76#define DAS6402_CTRL_INTE (1 << 7) 77#define DAS6402_CTRL_INTE BIT(7)
77#define DAS6402_TRIG_REG 0x0a 78#define DAS6402_TRIG_REG 0x0a
78#define DAS6402_TRIG_TGEN (1 << 0) 79#define DAS6402_TRIG_TGEN BIT(0)
79#define DAS6402_TRIG_TGSEL (1 << 1) 80#define DAS6402_TRIG_TGSEL BIT(1)
80#define DAS6402_TRIG_TGPOL (1 << 2) 81#define DAS6402_TRIG_TGPOL BIT(2)
81#define DAS6402_TRIG_PRETRIG (1 << 3) 82#define DAS6402_TRIG_PRETRIG BIT(3)
82#define DAS6402_AO_RANGE(_chan, _range) ((_range) << ((_chan) ? 6 : 4)) 83#define DAS6402_AO_RANGE(_chan, _range) ((_range) << ((_chan) ? 6 : 4))
83#define DAS6402_AO_RANGE_MASK(_chan) (3 << ((_chan) ? 6 : 4)) 84#define DAS6402_AO_RANGE_MASK(_chan) (3 << ((_chan) ? 6 : 4))
84#define DAS6402_MODE_REG 0x0b 85#define DAS6402_MODE_REG 0x0b
85#define DAS6402_MODE_RANGE(x) ((x) << 0) 86#define DAS6402_MODE_RANGE(x) ((x) << 2)
86#define DAS6402_MODE_POLLED (0 << 2) 87#define DAS6402_MODE_POLLED DAS6402_MODE_RANGE(0)
87#define DAS6402_MODE_FIFONEPTY (1 << 2) 88#define DAS6402_MODE_FIFONEPTY DAS6402_MODE_RANGE(1)
88#define DAS6402_MODE_FIFOHFULL (2 << 2) 89#define DAS6402_MODE_FIFOHFULL DAS6402_MODE_RANGE(2)
89#define DAS6402_MODE_EOB (3 << 2) 90#define DAS6402_MODE_EOB DAS6402_MODE_RANGE(3)
90#define DAS6402_MODE_ENHANCED (1 << 4) 91#define DAS6402_MODE_ENHANCED BIT(4)
91#define DAS6402_MODE_SE (1 << 5) 92#define DAS6402_MODE_SE BIT(5)
92#define DAS6402_MODE_UNI (1 << 6) 93#define DAS6402_MODE_UNI BIT(6)
93#define DAS6402_MODE_DMA1 (0 << 7) 94#define DAS6402_MODE_DMA(x) ((x) << 7)
94#define DAS6402_MODE_DMA3 (1 << 7) 95#define DAS6402_MODE_DMA1 DAS6402_MODE_DMA(0)
96#define DAS6402_MODE_DMA3 DAS6402_MODE_DMA(1)
95#define DAS6402_TIMER_BASE 0x0c 97#define DAS6402_TIMER_BASE 0x0c
96 98
97static const struct comedi_lrange das6402_ai_ranges = { 99static const struct comedi_lrange das6402_ai_ranges = {
diff --git a/drivers/staging/comedi/drivers/das800.c b/drivers/staging/comedi/drivers/das800.c
index b02f12201cf7..fd4cb4911671 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -1,56 +1,56 @@
1/* 1/*
2 comedi/drivers/das800.c 2 * comedi/drivers/das800.c
3 Driver for Keitley das800 series boards and compatibles 3 * Driver for Keitley das800 series boards and compatibles
4 Copyright (C) 2000 Frank Mori Hess <fmhess@users.sourceforge.net> 4 * Copyright (C) 2000 Frank Mori Hess <fmhess@users.sourceforge.net>
5 5 *
6 COMEDI - Linux Control and Measurement Device Interface 6 * COMEDI - Linux Control and Measurement Device Interface
7 Copyright (C) 2000 David A. Schleef <ds@schleef.org> 7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 8 *
9 This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version. 12 * (at your option) any later version.
13 13 *
14 This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 * GNU General Public License for more details.
18*/ 18 */
19/* 19/*
20Driver: das800 20 * Driver: das800
21Description: Keithley Metrabyte DAS800 (& compatibles) 21 * Description: Keithley Metrabyte DAS800 (& compatibles)
22Author: Frank Mori Hess <fmhess@users.sourceforge.net> 22 * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
23Devices: [Keithley Metrabyte] DAS-800 (das-800), DAS-801 (das-801), 23 * Devices: [Keithley Metrabyte] DAS-800 (das-800), DAS-801 (das-801),
24 DAS-802 (das-802), 24 * DAS-802 (das-802),
25 [Measurement Computing] CIO-DAS800 (cio-das800), 25 * [Measurement Computing] CIO-DAS800 (cio-das800),
26 CIO-DAS801 (cio-das801), CIO-DAS802 (cio-das802), 26 * CIO-DAS801 (cio-das801), CIO-DAS802 (cio-das802),
27 CIO-DAS802/16 (cio-das802/16) 27 * CIO-DAS802/16 (cio-das802/16)
28Status: works, cio-das802/16 untested - email me if you have tested it 28 * Status: works, cio-das802/16 untested - email me if you have tested it
29 29 *
30Configuration options: 30 * Configuration options:
31 [0] - I/O port base address 31 * [0] - I/O port base address
32 [1] - IRQ (optional, required for timed or externally triggered conversions) 32 * [1] - IRQ (optional, required for timed or externally triggered conversions)
33 33 *
34Notes: 34 * Notes:
35 IRQ can be omitted, although the cmd interface will not work without it. 35 * IRQ can be omitted, although the cmd interface will not work without it.
36 36 *
37 All entries in the channel/gain list must use the same gain and be 37 * All entries in the channel/gain list must use the same gain and be
38 consecutive channels counting upwards in channel number (these are 38 * consecutive channels counting upwards in channel number (these are
39 hardware limitations.) 39 * hardware limitations.)
40 40 *
41 I've never tested the gain setting stuff since I only have a 41 * I've never tested the gain setting stuff since I only have a
42 DAS-800 board with fixed gain. 42 * DAS-800 board with fixed gain.
43 43 *
44 The cio-das802/16 does not have a fifo-empty status bit! Therefore 44 * The cio-das802/16 does not have a fifo-empty status bit! Therefore
45 only fifo-half-full transfers are possible with this card. 45 * only fifo-half-full transfers are possible with this card.
46 46 *
47cmd triggers supported: 47 * cmd triggers supported:
48 start_src: TRIG_NOW | TRIG_EXT 48 * start_src: TRIG_NOW | TRIG_EXT
49 scan_begin_src: TRIG_FOLLOW 49 * scan_begin_src: TRIG_FOLLOW
50 scan_end_src: TRIG_COUNT 50 * scan_end_src: TRIG_COUNT
51 convert_src: TRIG_TIMER | TRIG_EXT 51 * convert_src: TRIG_TIMER | TRIG_EXT
52 stop_src: TRIG_NONE | TRIG_COUNT 52 * stop_src: TRIG_NONE | TRIG_COUNT
53*/ 53 */
54 54
55#include <linux/module.h> 55#include <linux/module.h>
56#include <linux/interrupt.h> 56#include <linux/interrupt.h>
@@ -218,7 +218,7 @@ struct das800_private {
218}; 218};
219 219
220static void das800_ind_write(struct comedi_device *dev, 220static void das800_ind_write(struct comedi_device *dev,
221 unsigned val, unsigned reg) 221 unsigned int val, unsigned int reg)
222{ 222{
223 /* 223 /*
224 * Select dev->iobase + 2 to be desired register 224 * Select dev->iobase + 2 to be desired register
@@ -228,7 +228,7 @@ static void das800_ind_write(struct comedi_device *dev,
228 outb(val, dev->iobase + 2); 228 outb(val, dev->iobase + 2);
229} 229}
230 230
231static unsigned das800_ind_read(struct comedi_device *dev, unsigned reg) 231static unsigned int das800_ind_read(struct comedi_device *dev, unsigned int reg)
232{ 232{
233 /* 233 /*
234 * Select dev->iobase + 7 to be desired register 234 * Select dev->iobase + 7 to be desired register
diff --git a/drivers/staging/comedi/drivers/dmm32at.c b/drivers/staging/comedi/drivers/dmm32at.c
index 958c0d4aae5c..b8606ded0623 100644
--- a/drivers/staging/comedi/drivers/dmm32at.c
+++ b/drivers/staging/comedi/drivers/dmm32at.c
@@ -46,73 +46,75 @@
46#define DMM32AT_AI_START_CONV_REG 0x00 46#define DMM32AT_AI_START_CONV_REG 0x00
47#define DMM32AT_AI_LSB_REG 0x00 47#define DMM32AT_AI_LSB_REG 0x00
48#define DMM32AT_AUX_DOUT_REG 0x01 48#define DMM32AT_AUX_DOUT_REG 0x01
49#define DMM32AT_AUX_DOUT2 (1 << 2) /* J3.42 - OUT2 (OUT2EN) */ 49#define DMM32AT_AUX_DOUT2 BIT(2) /* J3.42 - OUT2 (OUT2EN) */
50#define DMM32AT_AUX_DOUT1 (1 << 1) /* J3.43 */ 50#define DMM32AT_AUX_DOUT1 BIT(1) /* J3.43 */
51#define DMM32AT_AUX_DOUT0 (1 << 0) /* J3.44 - OUT0 (OUT0EN) */ 51#define DMM32AT_AUX_DOUT0 BIT(0) /* J3.44 - OUT0 (OUT0EN) */
52#define DMM32AT_AI_MSB_REG 0x01 52#define DMM32AT_AI_MSB_REG 0x01
53#define DMM32AT_AI_LO_CHAN_REG 0x02 53#define DMM32AT_AI_LO_CHAN_REG 0x02
54#define DMM32AT_AI_HI_CHAN_REG 0x03 54#define DMM32AT_AI_HI_CHAN_REG 0x03
55#define DMM32AT_AUX_DI_REG 0x04 55#define DMM32AT_AUX_DI_REG 0x04
56#define DMM32AT_AUX_DI_DACBUSY (1 << 7) 56#define DMM32AT_AUX_DI_DACBUSY BIT(7)
57#define DMM32AT_AUX_DI_CALBUSY (1 << 6) 57#define DMM32AT_AUX_DI_CALBUSY BIT(6)
58#define DMM32AT_AUX_DI3 (1 << 3) /* J3.45 - ADCLK (CLKSEL) */ 58#define DMM32AT_AUX_DI3 BIT(3) /* J3.45 - ADCLK (CLKSEL) */
59#define DMM32AT_AUX_DI2 (1 << 2) /* J3.46 - GATE12 (GT12EN) */ 59#define DMM32AT_AUX_DI2 BIT(2) /* J3.46 - GATE12 (GT12EN) */
60#define DMM32AT_AUX_DI1 (1 << 1) /* J3.47 - GATE0 (GT0EN) */ 60#define DMM32AT_AUX_DI1 BIT(1) /* J3.47 - GATE0 (GT0EN) */
61#define DMM32AT_AUX_DI0 (1 << 0) /* J3.48 - CLK0 (SRC0) */ 61#define DMM32AT_AUX_DI0 BIT(0) /* J3.48 - CLK0 (SRC0) */
62#define DMM32AT_AO_LSB_REG 0x04 62#define DMM32AT_AO_LSB_REG 0x04
63#define DMM32AT_AO_MSB_REG 0x05 63#define DMM32AT_AO_MSB_REG 0x05
64#define DMM32AT_AO_MSB_DACH(x) ((x) << 6) 64#define DMM32AT_AO_MSB_DACH(x) ((x) << 6)
65#define DMM32AT_FIFO_DEPTH_REG 0x06 65#define DMM32AT_FIFO_DEPTH_REG 0x06
66#define DMM32AT_FIFO_CTRL_REG 0x07 66#define DMM32AT_FIFO_CTRL_REG 0x07
67#define DMM32AT_FIFO_CTRL_FIFOEN (1 << 3) 67#define DMM32AT_FIFO_CTRL_FIFOEN BIT(3)
68#define DMM32AT_FIFO_CTRL_SCANEN (1 << 2) 68#define DMM32AT_FIFO_CTRL_SCANEN BIT(2)
69#define DMM32AT_FIFO_CTRL_FIFORST (1 << 1) 69#define DMM32AT_FIFO_CTRL_FIFORST BIT(1)
70#define DMM32AT_FIFO_STATUS_REG 0x07 70#define DMM32AT_FIFO_STATUS_REG 0x07
71#define DMM32AT_FIFO_STATUS_EF (1 << 7) 71#define DMM32AT_FIFO_STATUS_EF BIT(7)
72#define DMM32AT_FIFO_STATUS_HF (1 << 6) 72#define DMM32AT_FIFO_STATUS_HF BIT(6)
73#define DMM32AT_FIFO_STATUS_FF (1 << 5) 73#define DMM32AT_FIFO_STATUS_FF BIT(5)
74#define DMM32AT_FIFO_STATUS_OVF (1 << 4) 74#define DMM32AT_FIFO_STATUS_OVF BIT(4)
75#define DMM32AT_FIFO_STATUS_FIFOEN (1 << 3) 75#define DMM32AT_FIFO_STATUS_FIFOEN BIT(3)
76#define DMM32AT_FIFO_STATUS_SCANEN (1 << 2) 76#define DMM32AT_FIFO_STATUS_SCANEN BIT(2)
77#define DMM32AT_FIFO_STATUS_PAGE_MASK (3 << 0) 77#define DMM32AT_FIFO_STATUS_PAGE_MASK (3 << 0)
78#define DMM32AT_CTRL_REG 0x08 78#define DMM32AT_CTRL_REG 0x08
79#define DMM32AT_CTRL_RESETA (1 << 5) 79#define DMM32AT_CTRL_RESETA BIT(5)
80#define DMM32AT_CTRL_RESETD (1 << 4) 80#define DMM32AT_CTRL_RESETD BIT(4)
81#define DMM32AT_CTRL_INTRST (1 << 3) 81#define DMM32AT_CTRL_INTRST BIT(3)
82#define DMM32AT_CTRL_PAGE_8254 (0 << 0) 82#define DMM32AT_CTRL_PAGE(x) ((x) << 0)
83#define DMM32AT_CTRL_PAGE_8255 (1 << 0) 83#define DMM32AT_CTRL_PAGE_8254 DMM32AT_CTRL_PAGE(0)
84#define DMM32AT_CTRL_PAGE_CALIB (3 << 0) 84#define DMM32AT_CTRL_PAGE_8255 DMM32AT_CTRL_PAGE(1)
85#define DMM32AT_CTRL_PAGE_CALIB DMM32AT_CTRL_PAGE(3)
85#define DMM32AT_AI_STATUS_REG 0x08 86#define DMM32AT_AI_STATUS_REG 0x08
86#define DMM32AT_AI_STATUS_STS (1 << 7) 87#define DMM32AT_AI_STATUS_STS BIT(7)
87#define DMM32AT_AI_STATUS_SD1 (1 << 6) 88#define DMM32AT_AI_STATUS_SD1 BIT(6)
88#define DMM32AT_AI_STATUS_SD0 (1 << 5) 89#define DMM32AT_AI_STATUS_SD0 BIT(5)
89#define DMM32AT_AI_STATUS_ADCH_MASK (0x1f << 0) 90#define DMM32AT_AI_STATUS_ADCH_MASK (0x1f << 0)
90#define DMM32AT_INTCLK_REG 0x09 91#define DMM32AT_INTCLK_REG 0x09
91#define DMM32AT_INTCLK_ADINT (1 << 7) 92#define DMM32AT_INTCLK_ADINT BIT(7)
92#define DMM32AT_INTCLK_DINT (1 << 6) 93#define DMM32AT_INTCLK_DINT BIT(6)
93#define DMM32AT_INTCLK_TINT (1 << 5) 94#define DMM32AT_INTCLK_TINT BIT(5)
94#define DMM32AT_INTCLK_CLKEN (1 << 1) /* 1=see below 0=software */ 95#define DMM32AT_INTCLK_CLKEN BIT(1) /* 1=see below 0=software */
95#define DMM32AT_INTCLK_CLKSEL (1 << 0) /* 1=OUT2 0=EXTCLK */ 96#define DMM32AT_INTCLK_CLKSEL BIT(0) /* 1=OUT2 0=EXTCLK */
96#define DMM32AT_CTRDIO_CFG_REG 0x0a 97#define DMM32AT_CTRDIO_CFG_REG 0x0a
97#define DMM32AT_CTRDIO_CFG_FREQ12 (1 << 7) /* CLK12 1=100KHz 0=10MHz */ 98#define DMM32AT_CTRDIO_CFG_FREQ12 BIT(7) /* CLK12 1=100KHz 0=10MHz */
98#define DMM32AT_CTRDIO_CFG_FREQ0 (1 << 6) /* CLK0 1=10KHz 0=10MHz */ 99#define DMM32AT_CTRDIO_CFG_FREQ0 BIT(6) /* CLK0 1=10KHz 0=10MHz */
99#define DMM32AT_CTRDIO_CFG_OUT2EN (1 << 5) /* J3.42 1=OUT2 is DOUT2 */ 100#define DMM32AT_CTRDIO_CFG_OUT2EN BIT(5) /* J3.42 1=OUT2 is DOUT2 */
100#define DMM32AT_CTRDIO_CFG_OUT0EN (1 << 4) /* J3,44 1=OUT0 is DOUT0 */ 101#define DMM32AT_CTRDIO_CFG_OUT0EN BIT(4) /* J3,44 1=OUT0 is DOUT0 */
101#define DMM32AT_CTRDIO_CFG_GT0EN (1 << 2) /* J3.47 1=DIN1 is GATE0 */ 102#define DMM32AT_CTRDIO_CFG_GT0EN BIT(2) /* J3.47 1=DIN1 is GATE0 */
102#define DMM32AT_CTRDIO_CFG_SRC0 (1 << 1) /* CLK0 is 0=FREQ0 1=J3.48 */ 103#define DMM32AT_CTRDIO_CFG_SRC0 BIT(1) /* CLK0 is 0=FREQ0 1=J3.48 */
103#define DMM32AT_CTRDIO_CFG_GT12EN (1 << 0) /* J3.46 1=DIN2 is GATE12 */ 104#define DMM32AT_CTRDIO_CFG_GT12EN BIT(0) /* J3.46 1=DIN2 is GATE12 */
104#define DMM32AT_AI_CFG_REG 0x0b 105#define DMM32AT_AI_CFG_REG 0x0b
105#define DMM32AT_AI_CFG_SCINT_20US (0 << 4) 106#define DMM32AT_AI_CFG_SCINT(x) ((x) << 4)
106#define DMM32AT_AI_CFG_SCINT_15US (1 << 4) 107#define DMM32AT_AI_CFG_SCINT_20US DMM32AT_AI_CFG_SCINT(0)
107#define DMM32AT_AI_CFG_SCINT_10US (2 << 4) 108#define DMM32AT_AI_CFG_SCINT_15US DMM32AT_AI_CFG_SCINT(1)
108#define DMM32AT_AI_CFG_SCINT_5US (3 << 4) 109#define DMM32AT_AI_CFG_SCINT_10US DMM32AT_AI_CFG_SCINT(2)
109#define DMM32AT_AI_CFG_RANGE (1 << 3) /* 0=5V 1=10V */ 110#define DMM32AT_AI_CFG_SCINT_5US DMM32AT_AI_CFG_SCINT(3)
110#define DMM32AT_AI_CFG_ADBU (1 << 2) /* 0=bipolar 1=unipolar */ 111#define DMM32AT_AI_CFG_RANGE BIT(3) /* 0=5V 1=10V */
112#define DMM32AT_AI_CFG_ADBU BIT(2) /* 0=bipolar 1=unipolar */
111#define DMM32AT_AI_CFG_GAIN(x) ((x) << 0) 113#define DMM32AT_AI_CFG_GAIN(x) ((x) << 0)
112#define DMM32AT_AI_READBACK_REG 0x0b 114#define DMM32AT_AI_READBACK_REG 0x0b
113#define DMM32AT_AI_READBACK_WAIT (1 << 7) /* DMM32AT_AI_STATUS_STS */ 115#define DMM32AT_AI_READBACK_WAIT BIT(7) /* DMM32AT_AI_STATUS_STS */
114#define DMM32AT_AI_READBACK_RANGE (1 << 3) 116#define DMM32AT_AI_READBACK_RANGE BIT(3)
115#define DMM32AT_AI_READBACK_ADBU (1 << 2) 117#define DMM32AT_AI_READBACK_ADBU BIT(2)
116#define DMM32AT_AI_READBACK_GAIN_MASK (3 << 0) 118#define DMM32AT_AI_READBACK_GAIN_MASK (3 << 0)
117 119
118#define DMM32AT_CLK1 0x0d 120#define DMM32AT_CLK1 0x0d
diff --git a/drivers/staging/comedi/drivers/dt2801.c b/drivers/staging/comedi/drivers/dt2801.c
index 6c7b4d27c27c..c2ce1eb87385 100644
--- a/drivers/staging/comedi/drivers/dt2801.c
+++ b/drivers/staging/comedi/drivers/dt2801.c
@@ -4,30 +4,30 @@
4 * 4 *
5 */ 5 */
6/* 6/*
7Driver: dt2801 7 * Driver: dt2801
8Description: Data Translation DT2801 series and DT01-EZ 8 * Description: Data Translation DT2801 series and DT01-EZ
9Author: ds 9 * Author: ds
10Status: works 10 * Status: works
11Devices: [Data Translation] DT2801 (dt2801), DT2801-A, DT2801/5716A, 11 * Devices: [Data Translation] DT2801 (dt2801), DT2801-A, DT2801/5716A,
12 DT2805, DT2805/5716A, DT2808, DT2818, DT2809, DT01-EZ 12 * DT2805, DT2805/5716A, DT2808, DT2818, DT2809, DT01-EZ
13 13 *
14This driver can autoprobe the type of board. 14 * This driver can autoprobe the type of board.
15 15 *
16Configuration options: 16 * Configuration options:
17 [0] - I/O port base address 17 * [0] - I/O port base address
18 [1] - unused 18 * [1] - unused
19 [2] - A/D reference 0=differential, 1=single-ended 19 * [2] - A/D reference 0=differential, 1=single-ended
20 [3] - A/D range 20 * [3] - A/D range
21 0 = [-10, 10] 21 * 0 = [-10, 10]
22 1 = [0,10] 22 * 1 = [0,10]
23 [4] - D/A 0 range 23 * [4] - D/A 0 range
24 0 = [-10, 10] 24 * 0 = [-10, 10]
25 1 = [-5,5] 25 * 1 = [-5,5]
26 2 = [-2.5,2.5] 26 * 2 = [-2.5,2.5]
27 3 = [0,10] 27 * 3 = [0,10]
28 4 = [0,5] 28 * 4 = [0,5]
29 [5] - D/A 1 range (same choices) 29 * [5] - D/A 1 range (same choices)
30*/ 30 */
31 31
32#include <linux/module.h> 32#include <linux/module.h>
33#include "../comedidev.h" 33#include "../comedidev.h"
@@ -65,9 +65,10 @@ Configuration options:
65#define DT_C_SET_AD 0xd 65#define DT_C_SET_AD 0xd
66#define DT_C_READ_AD 0xe 66#define DT_C_READ_AD 0xe
67 67
68/* Command modifiers (only used with read/write), EXTTRIG can be 68/*
69 used with some other commands. 69 * Command modifiers (only used with read/write), EXTTRIG can be
70*/ 70 * used with some other commands.
71 */
71#define DT_MOD_DMA BIT(4) 72#define DT_MOD_DMA BIT(4)
72#define DT_MOD_CONT BIT(5) 73#define DT_MOD_CONT BIT(5)
73#define DT_MOD_EXTCLK BIT(6) 74#define DT_MOD_EXTCLK BIT(6)
@@ -135,9 +136,10 @@ struct dt2801_board {
135 int dabits; 136 int dabits;
136}; 137};
137 138
138/* Typeid's for the different boards of the DT2801-series 139/*
139 (taken from the test-software, that comes with the board) 140 * Typeid's for the different boards of the DT2801-series
140 */ 141 * (taken from the test-software, that comes with the board)
142 */
141static const struct dt2801_board boardtypes[] = { 143static const struct dt2801_board boardtypes[] = {
142 { 144 {
143 .name = "dt2801", 145 .name = "dt2801",
@@ -209,15 +211,18 @@ struct dt2801_private {
209 const struct comedi_lrange *dac_range_types[2]; 211 const struct comedi_lrange *dac_range_types[2];
210}; 212};
211 213
212/* These are the low-level routines: 214/*
213 writecommand: write a command to the board 215 * These are the low-level routines:
214 writedata: write data byte 216 * writecommand: write a command to the board
215 readdata: read data byte 217 * writedata: write data byte
218 * readdata: read data byte
216 */ 219 */
217 220
218/* Only checks DataOutReady-flag, not the Ready-flag as it is done 221/*
219 in the examples of the manual. I don't see why this should be 222 * Only checks DataOutReady-flag, not the Ready-flag as it is done
220 necessary. */ 223 * in the examples of the manual. I don't see why this should be
224 * necessary.
225 */
221static int dt2801_readdata(struct comedi_device *dev, int *data) 226static int dt2801_readdata(struct comedi_device *dev, int *data)
222{ 227{
223 int stat = 0; 228 int stat = 0;
@@ -517,14 +522,14 @@ static int dt2801_dio_insn_config(struct comedi_device *dev,
517} 522}
518 523
519/* 524/*
520 options: 525 * options:
521 [0] - i/o base 526 * [0] - i/o base
522 [1] - unused 527 * [1] - unused
523 [2] - a/d 0=differential, 1=single-ended 528 * [2] - a/d 0=differential, 1=single-ended
524 [3] - a/d range 0=[-10,10], 1=[0,10] 529 * [3] - a/d range 0=[-10,10], 1=[0,10]
525 [4] - dac0 range 0=[-10,10], 1=[-5,5], 2=[-2.5,2.5] 3=[0,10], 4=[0,5] 530 * [4] - dac0 range 0=[-10,10], 1=[-5,5], 2=[-2.5,2.5] 3=[0,10], 4=[0,5]
526 [5] - dac1 range 0=[-10,10], 1=[-5,5], 2=[-2.5,2.5] 3=[0,10], 4=[0,5] 531 * [5] - dac1 range 0=[-10,10], 1=[-5,5], 2=[-2.5,2.5] 3=[0,10], 4=[0,5]
527*/ 532 */
528static int dt2801_attach(struct comedi_device *dev, struct comedi_devconfig *it) 533static int dt2801_attach(struct comedi_device *dev, struct comedi_devconfig *it)
529{ 534{
530 const struct dt2801_board *board; 535 const struct dt2801_board *board;
diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
index a80773291fdc..904f637797b6 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -1,224 +1,469 @@
1/* 1/*
2 comedi/drivers/dt2811.c 2 * Comedi driver for Data Translation DT2811
3 Hardware driver for Data Translation DT2811 3 *
4 4 * COMEDI - Linux Control and Measurement Device Interface
5 COMEDI - Linux Control and Measurement Device Interface 5 * Copyright (C) David A. Schleef <ds@schleef.org>
6 History: 6 *
7 Base Version - David A. Schleef <ds@schleef.org> 7 * This program is free software; you can redistribute it and/or modify
8 December 1998 - Updated to work. David does not have a DT2811 8 * it under the terms of the GNU General Public License as published by
9 board any longer so this was suffering from bitrot. 9 * the Free Software Foundation; either version 2 of the License, or
10 Updated performed by ... 10 * (at your option) any later version.
11 11 *
12 This program is free software; you can redistribute it and/or modify 12 * This program is distributed in the hope that it will be useful,
13 it under the terms of the GNU General Public License as published by 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 the Free Software Foundation; either version 2 of the License, or 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 (at your option) any later version. 15 * GNU General Public License for more details.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21 */ 16 */
17
22/* 18/*
23Driver: dt2811 19 * Driver: dt2811
24Description: Data Translation DT2811 20 * Description: Data Translation DT2811
25Author: ds 21 * Author: ds
26Devices: [Data Translation] DT2811-PGL (dt2811-pgl), DT2811-PGH (dt2811-pgh) 22 * Devices: [Data Translation] DT2811-PGL (dt2811-pgl), DT2811-PGH (dt2811-pgh)
27Status: works 23 * Status: works
28 24 *
29Configuration options: 25 * Configuration options:
30 [0] - I/O port base address 26 * [0] - I/O port base address
31 [1] - IRQ, although this is currently unused 27 * [1] - IRQ (optional, needed for async command support)
32 [2] - A/D reference 28 * [2] - A/D reference (# of analog inputs)
33 0 = signle-ended 29 * 0 = single-ended (16 channels)
34 1 = differential 30 * 1 = differential (8 channels)
35 2 = pseudo-differential (common reference) 31 * 2 = pseudo-differential (16 channels)
36 [3] - A/D range 32 * [3] - A/D range (deprecated, see below)
37 0 = [-5, 5] 33 * [4] - D/A 0 range (deprecated, see below)
38 1 = [-2.5, 2.5] 34 * [5] - D/A 1 range (deprecated, see below)
39 2 = [0, 5] 35 *
40 [4] - D/A 0 range (same choices) 36 * Notes:
41 [4] - D/A 1 range (same choices) 37 * - A/D ranges are not programmable but the gain is. The AI subdevice has
42*/ 38 * a range_table containing all the possible analog input range/gain
39 * options for the dt2811-pgh or dt2811-pgl. Use the range that matches
40 * your board configuration and the desired gain to correctly convert
41 * between data values and physical units and to set the correct output
42 * gain.
43 * - D/A ranges are not programmable. The AO subdevice has a range_table
44 * containing all the possible analog output ranges. Use the range
45 * that matches your board configuration to convert between data
46 * values and physical units.
47 */
43 48
44#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/interrupt.h>
51#include <linux/delay.h>
52
45#include "../comedidev.h" 53#include "../comedidev.h"
46 54
47static const struct comedi_lrange range_dt2811_pgh_ai_5_unipolar = { 55/*
48 4, { 56 * Register I/O map
49 UNI_RANGE(5), 57 */
50 UNI_RANGE(2.5), 58#define DT2811_ADCSR_REG 0x00 /* r/w A/D Control/Status */
51 UNI_RANGE(1.25), 59#define DT2811_ADCSR_ADDONE BIT(7) /* r 1=A/D conv done */
52 UNI_RANGE(0.625) 60#define DT2811_ADCSR_ADERROR BIT(6) /* r 1=A/D error */
53 } 61#define DT2811_ADCSR_ADBUSY BIT(5) /* r 1=A/D busy */
62#define DT2811_ADCSR_CLRERROR BIT(4)
63#define DT2811_ADCSR_DMAENB BIT(3) /* r/w 1=dma ena */
64#define DT2811_ADCSR_INTENB BIT(2) /* r/w 1=interupts ena */
65#define DT2811_ADCSR_ADMODE(x) (((x) & 0x3) << 0)
66
67#define DT2811_ADGCR_REG 0x01 /* r/w A/D Gain/Channel */
68#define DT2811_ADGCR_GAIN(x) (((x) & 0x3) << 6)
69#define DT2811_ADGCR_CHAN(x) (((x) & 0xf) << 0)
70
71#define DT2811_ADDATA_LO_REG 0x02 /* r A/D Data low byte */
72#define DT2811_ADDATA_HI_REG 0x03 /* r A/D Data high byte */
73
74#define DT2811_DADATA_LO_REG(x) (0x02 + ((x) * 2)) /* w D/A Data low */
75#define DT2811_DADATA_HI_REG(x) (0x03 + ((x) * 2)) /* w D/A Data high */
76
77#define DT2811_DI_REG 0x06 /* r Digital Input Port 0 */
78#define DT2811_DO_REG 0x06 /* w Digital Output Port 1 */
79
80#define DT2811_TMRCTR_REG 0x07 /* r/w Timer/Counter */
81#define DT2811_TMRCTR_MANTISSA(x) (((x) & 0x7) << 3)
82#define DT2811_TMRCTR_EXPONENT(x) (((x) & 0x7) << 0)
83
84#define DT2811_OSC_BASE 1666 /* 600 kHz = 1666.6667ns */
85
86/*
87 * Timer frequency control:
88 * DT2811_TMRCTR_MANTISSA DT2811_TMRCTR_EXPONENT
89 * val divisor frequency val multiply divisor/divide frequency by
90 * 0 1 600 kHz 0 1
91 * 1 10 60 kHz 1 10
92 * 2 2 300 kHz 2 100
93 * 3 3 200 kHz 3 1000
94 * 4 4 150 kHz 4 10000
95 * 5 5 120 kHz 5 100000
96 * 6 6 100 kHz 6 1000000
97 * 7 12 50 kHz 7 10000000
98 */
99const unsigned int dt2811_clk_dividers[] = {
100 1, 10, 2, 3, 4, 5, 6, 12
54}; 101};
55 102
56static const struct comedi_lrange range_dt2811_pgh_ai_2_5_bipolar = { 103const unsigned int dt2811_clk_multipliers[] = {
57 4, { 104 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000
58 BIP_RANGE(2.5),
59 BIP_RANGE(1.25),
60 BIP_RANGE(0.625),
61 BIP_RANGE(0.3125)
62 }
63}; 105};
64 106
65static const struct comedi_lrange range_dt2811_pgh_ai_5_bipolar = { 107/*
66 4, { 108 * The Analog Input range is set using jumpers on the board.
67 BIP_RANGE(5), 109 *
68 BIP_RANGE(2.5), 110 * Input Range W9 W10
69 BIP_RANGE(1.25), 111 * -5V to +5V In Out
70 BIP_RANGE(0.625) 112 * -2.5V to +2.5V In In
113 * 0V to +5V Out In
114 *
115 * The gain may be set to 1, 2, 4, or 8 (on the dt2811-pgh) or to
116 * 1, 10, 100, 500 (on the dt2811-pgl).
117 */
118static const struct comedi_lrange dt2811_pgh_ai_ranges = {
119 12, {
120 BIP_RANGE(5), /* range 0: gain=1 */
121 BIP_RANGE(2.5), /* range 1: gain=2 */
122 BIP_RANGE(1.25), /* range 2: gain=4 */
123 BIP_RANGE(0.625), /* range 3: gain=8 */
124
125 BIP_RANGE(2.5), /* range 0+4: gain=1 */
126 BIP_RANGE(1.25), /* range 1+4: gain=2 */
127 BIP_RANGE(0.625), /* range 2+4: gain=4 */
128 BIP_RANGE(0.3125), /* range 3+4: gain=8 */
129
130 UNI_RANGE(5), /* range 0+8: gain=1 */
131 UNI_RANGE(2.5), /* range 1+8: gain=2 */
132 UNI_RANGE(1.25), /* range 2+8: gain=4 */
133 UNI_RANGE(0.625) /* range 3+8: gain=8 */
71 } 134 }
72}; 135};
73 136
74static const struct comedi_lrange range_dt2811_pgl_ai_5_unipolar = { 137static const struct comedi_lrange dt2811_pgl_ai_ranges = {
75 4, { 138 12, {
76 UNI_RANGE(5), 139 BIP_RANGE(5), /* range 0: gain=1 */
77 UNI_RANGE(0.5), 140 BIP_RANGE(0.5), /* range 1: gain=10 */
78 UNI_RANGE(0.05), 141 BIP_RANGE(0.05), /* range 2: gain=100 */
79 UNI_RANGE(0.01) 142 BIP_RANGE(0.01), /* range 3: gain=500 */
143
144 BIP_RANGE(2.5), /* range 0+4: gain=1 */
145 BIP_RANGE(0.25), /* range 1+4: gain=10 */
146 BIP_RANGE(0.025), /* range 2+4: gain=100 */
147 BIP_RANGE(0.005), /* range 3+4: gain=500 */
148
149 UNI_RANGE(5), /* range 0+8: gain=1 */
150 UNI_RANGE(0.5), /* range 1+8: gain=10 */
151 UNI_RANGE(0.05), /* range 2+8: gain=100 */
152 UNI_RANGE(0.01) /* range 3+8: gain=500 */
80 } 153 }
81}; 154};
82 155
83static const struct comedi_lrange range_dt2811_pgl_ai_2_5_bipolar = { 156/*
84 4, { 157 * The Analog Output range is set per-channel using jumpers on the board.
158 *
159 * DAC0 Jumpers DAC1 Jumpers
160 * Output Range W5 W6 W7 W8 W1 W2 W3 W4
161 * -5V to +5V In Out In Out In Out In Out
162 * -2.5V to +2.5V In Out Out In In Out Out In
163 * 0 to +5V Out In Out In Out In Out In
164 */
165static const struct comedi_lrange dt2811_ao_ranges = {
166 3, {
167 BIP_RANGE(5), /* default setting from factory */
85 BIP_RANGE(2.5), 168 BIP_RANGE(2.5),
86 BIP_RANGE(0.25), 169 UNI_RANGE(5)
87 BIP_RANGE(0.025),
88 BIP_RANGE(0.005)
89 } 170 }
90}; 171};
91 172
92static const struct comedi_lrange range_dt2811_pgl_ai_5_bipolar = { 173struct dt2811_board {
93 4, { 174 const char *name;
94 BIP_RANGE(5), 175 unsigned int is_pgh:1;
95 BIP_RANGE(0.5),
96 BIP_RANGE(0.05),
97 BIP_RANGE(0.01)
98 }
99}; 176};
100 177
101/* 178static const struct dt2811_board dt2811_boards[] = {
179 {
180 .name = "dt2811-pgh",
181 .is_pgh = 1,
182 }, {
183 .name = "dt2811-pgl",
184 },
185};
102 186
103 0x00 ADCSR R/W A/D Control/Status Register 187struct dt2811_private {
104 bit 7 - (R) 1 indicates A/D conversion done 188 unsigned int ai_divisor;
105 reading ADDAT clears bit 189};
106 (W) ignored
107 bit 6 - (R) 1 indicates A/D error
108 (W) ignored
109 bit 5 - (R) 1 indicates A/D busy, cleared at end
110 of conversion
111 (W) ignored
112 bit 4 - (R) 0
113 (W)
114 bit 3 - (R) 0
115 bit 2 - (R/W) 1 indicates interrupts enabled
116 bits 1,0 - (R/W) mode bits
117 00 single conversion on ADGCR load
118 01 continuous conversion, internal clock,
119 (clock enabled on ADGCR load)
120 10 continuous conversion, internal clock,
121 external trigger
122 11 continuous conversion, external clock,
123 external trigger
124
125 0x01 ADGCR R/W A/D Gain/Channel Register
126 bit 6,7 - (R/W) gain select
127 00 gain=1, both PGH, PGL models
128 01 gain=2 PGH, 10 PGL
129 10 gain=4 PGH, 100 PGL
130 11 gain=8 PGH, 500 PGL
131 bit 4,5 - reserved
132 bit 3-0 - (R/W) channel select
133 channel number from 0-15
134
135 0x02,0x03 (R) ADDAT A/D Data Register
136 (W) DADAT0 D/A Data Register 0
137 0x02 low byte
138 0x03 high byte
139
140 0x04,0x05 (W) DADAT0 D/A Data Register 1
141
142 0x06 (R) DIO0 Digital Input Port 0
143 (W) DIO1 Digital Output Port 1
144
145 0x07 TMRCTR (R/W) Timer/Counter Register
146 bits 6,7 - reserved
147 bits 5-3 - Timer frequency control (mantissa)
148 543 divisor freqency (kHz)
149 000 1 600
150 001 10 60
151 010 2 300
152 011 3 200
153 100 4 150
154 101 5 120
155 110 6 100
156 111 12 50
157 bits 2-0 - Timer frequency control (exponent)
158 210 multiply divisor/divide frequency by
159 000 1
160 001 10
161 010 100
162 011 1000
163 100 10000
164 101 100000
165 110 1000000
166 111 10000000
167 190
168 */ 191static unsigned int dt2811_ai_read_sample(struct comedi_device *dev,
192 struct comedi_subdevice *s)
193{
194 unsigned int val;
169 195
170#define TIMEOUT 10000 196 val = inb(dev->iobase + DT2811_ADDATA_LO_REG) |
197 (inb(dev->iobase + DT2811_ADDATA_HI_REG) << 8);
171 198
172#define DT2811_ADCSR 0 199 return val & s->maxdata;
173#define DT2811_ADGCR 1 200}
174#define DT2811_ADDATLO 2
175#define DT2811_ADDATHI 3
176#define DT2811_DADAT0LO 2
177#define DT2811_DADAT0HI 3
178#define DT2811_DADAT1LO 4
179#define DT2811_DADAT1HI 5
180#define DT2811_DIO 6
181#define DT2811_TMRCTR 7
182 201
183/* 202static irqreturn_t dt2811_interrupt(int irq, void *d)
184 * flags 203{
185 */ 204 struct comedi_device *dev = d;
205 struct comedi_subdevice *s = dev->read_subdev;
206 struct comedi_async *async = s->async;
207 struct comedi_cmd *cmd = &async->cmd;
208 unsigned int status;
186 209
187/* ADCSR */ 210 if (!dev->attached)
211 return IRQ_NONE;
188 212
189#define DT2811_ADDONE 0x80 213 status = inb(dev->iobase + DT2811_ADCSR_REG);
190#define DT2811_ADERROR 0x40
191#define DT2811_ADBUSY 0x20
192#define DT2811_CLRERROR 0x10
193#define DT2811_INTENB 0x04
194#define DT2811_ADMODE 0x03
195 214
196struct dt2811_board { 215 if (status & DT2811_ADCSR_ADERROR) {
197 const char *name; 216 async->events |= COMEDI_CB_OVERFLOW;
198 const struct comedi_lrange *bip_5;
199 const struct comedi_lrange *bip_2_5;
200 const struct comedi_lrange *unip_5;
201};
202 217
203enum { card_2811_pgh, card_2811_pgl }; 218 outb(status | DT2811_ADCSR_CLRERROR,
219 dev->iobase + DT2811_ADCSR_REG);
220 }
204 221
205struct dt2811_private { 222 if (status & DT2811_ADCSR_ADDONE) {
206 int ntrig; 223 unsigned short val;
207 int curadchan;
208 enum {
209 adc_singleended, adc_diff, adc_pseudo_diff
210 } adc_mux;
211 enum {
212 dac_bipolar_5, dac_bipolar_2_5, dac_unipolar_5
213 } dac_range[2];
214 const struct comedi_lrange *range_type_list[2];
215};
216 224
217static const struct comedi_lrange *dac_range_types[] = { 225 val = dt2811_ai_read_sample(dev, s);
218 &range_bipolar5, 226 comedi_buf_write_samples(s, &val, 1);
219 &range_bipolar2_5, 227 }
220 &range_unipolar5 228
221}; 229 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
230 async->events |= COMEDI_CB_EOA;
231
232 comedi_handle_events(dev, s);
233
234 return IRQ_HANDLED;
235}
236
237static int dt2811_ai_cancel(struct comedi_device *dev,
238 struct comedi_subdevice *s)
239{
240 /*
241 * Mode 0
242 * Single conversion
243 *
244 * Loading a chanspec will trigger a conversion.
245 */
246 outb(DT2811_ADCSR_ADMODE(0), dev->iobase + DT2811_ADCSR_REG);
247
248 return 0;
249}
250
251static void dt2811_ai_set_chanspec(struct comedi_device *dev,
252 unsigned int chanspec)
253{
254 unsigned int chan = CR_CHAN(chanspec);
255 unsigned int range = CR_RANGE(chanspec);
256
257 outb(DT2811_ADGCR_CHAN(chan) | DT2811_ADGCR_GAIN(range),
258 dev->iobase + DT2811_ADGCR_REG);
259}
260
261static int dt2811_ai_cmd(struct comedi_device *dev,
262 struct comedi_subdevice *s)
263{
264 struct dt2811_private *devpriv = dev->private;
265 struct comedi_cmd *cmd = &s->async->cmd;
266 unsigned int mode;
267
268 if (cmd->start_src == TRIG_NOW) {
269 /*
270 * Mode 1
271 * Continuous conversion, internal trigger and clock
272 *
273 * This resets the trigger flip-flop, disabling A/D strobes.
274 * The timer/counter register is loaded with the division
275 * ratio which will give the required sample rate.
276 *
277 * Loading the first chanspec sets the trigger flip-flop,
278 * enabling the timer/counter. A/D strobes are then generated
279 * at the rate set by the internal clock/divider.
280 */
281 mode = DT2811_ADCSR_ADMODE(1);
282 } else { /* TRIG_EXT */
283 if (cmd->convert_src == TRIG_TIMER) {
284 /*
285 * Mode 2
286 * Continuous conversion, external trigger
287 *
288 * Similar to Mode 1, with the exception that the
289 * trigger flip-flop must be set by a negative edge
290 * on the external trigger input.
291 */
292 mode = DT2811_ADCSR_ADMODE(2);
293 } else { /* TRIG_EXT */
294 /*
295 * Mode 3
296 * Continuous conversion, external trigger, clock
297 *
298 * Similar to Mode 2, with the exception that the
299 * conversion rate is set by the frequency on the
300 * external clock/divider.
301 */
302 mode = DT2811_ADCSR_ADMODE(3);
303 }
304 }
305 outb(mode | DT2811_ADCSR_INTENB, dev->iobase + DT2811_ADCSR_REG);
306
307 /* load timer */
308 outb(devpriv->ai_divisor, dev->iobase + DT2811_TMRCTR_REG);
309
310 /* load chanspec - enables timer */
311 dt2811_ai_set_chanspec(dev, cmd->chanlist[0]);
312
313 return 0;
314}
315
316static unsigned int dt2811_ns_to_timer(unsigned int *nanosec,
317 unsigned int flags)
318{
319 unsigned long long ns = *nanosec;
320 unsigned int ns_lo = COMEDI_MIN_SPEED;
321 unsigned int ns_hi = 0;
322 unsigned int divisor_hi = 0;
323 unsigned int divisor_lo = 0;
324 unsigned int _div;
325 unsigned int _mult;
326
327 /*
328 * Work through all the divider/multiplier values to find the two
329 * closest divisors to generate the requested nanosecond timing.
330 */
331 for (_div = 0; _div <= 7; _div++) {
332 for (_mult = 0; _mult <= 7; _mult++) {
333 unsigned int div = dt2811_clk_dividers[_div];
334 unsigned int mult = dt2811_clk_multipliers[_mult];
335 unsigned long long divider = div * mult;
336 unsigned int divisor = DT2811_TMRCTR_MANTISSA(_div) |
337 DT2811_TMRCTR_EXPONENT(_mult);
338
339 /*
340 * The timer can be configured to run at a slowest
341 * speed of 0.005hz (600 Khz/120000000), which requires
342 * 37-bits to represent the nanosecond value. Limit the
343 * slowest timing to what comedi handles (32-bits).
344 */
345 ns = divider * DT2811_OSC_BASE;
346 if (ns > COMEDI_MIN_SPEED)
347 continue;
348
349 /* Check for fastest found timing */
350 if (ns <= *nanosec && ns > ns_hi) {
351 ns_hi = ns;
352 divisor_hi = divisor;
353 }
354 /* Check for slowest found timing */
355 if (ns >= *nanosec && ns < ns_lo) {
356 ns_lo = ns;
357 divisor_lo = divisor;
358 }
359 }
360 }
361
362 /*
363 * The slowest found timing will be invalid if the requested timing
364 * is faster than what can be generated by the timer. Fix it so that
365 * CMDF_ROUND_UP returns valid timing.
366 */
367 if (ns_lo == COMEDI_MIN_SPEED) {
368 ns_lo = ns_hi;
369 divisor_lo = divisor_hi;
370 }
371 /*
372 * The fastest found timing will be invalid if the requested timing
373 * is less than what can be generated by the timer. Fix it so that
374 * CMDF_ROUND_NEAREST and CMDF_ROUND_DOWN return valid timing.
375 */
376 if (ns_hi == 0) {
377 ns_hi = ns_lo;
378 divisor_hi = divisor_lo;
379 }
380
381 switch (flags & CMDF_ROUND_MASK) {
382 case CMDF_ROUND_NEAREST:
383 default:
384 if (ns_hi - *nanosec < *nanosec - ns_lo) {
385 *nanosec = ns_lo;
386 return divisor_lo;
387 }
388 *nanosec = ns_hi;
389 return divisor_hi;
390 case CMDF_ROUND_UP:
391 *nanosec = ns_lo;
392 return divisor_lo;
393 case CMDF_ROUND_DOWN:
394 *nanosec = ns_hi;
395 return divisor_hi;
396 }
397}
398
399static int dt2811_ai_cmdtest(struct comedi_device *dev,
400 struct comedi_subdevice *s,
401 struct comedi_cmd *cmd)
402{
403 struct dt2811_private *devpriv = dev->private;
404 unsigned int arg;
405 int err = 0;
406
407 /* Step 1 : check if triggers are trivially valid */
408
409 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
410 err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
411 err |= comedi_check_trigger_src(&cmd->convert_src,
412 TRIG_TIMER | TRIG_EXT);
413 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
414 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
415
416 if (err)
417 return 1;
418
419 /* Step 2a : make sure trigger sources are unique */
420
421 err |= comedi_check_trigger_is_unique(cmd->start_src);
422 err |= comedi_check_trigger_is_unique(cmd->convert_src);
423 err |= comedi_check_trigger_is_unique(cmd->stop_src);
424
425 /* Step 2b : and mutually compatible */
426
427 if (cmd->convert_src == TRIG_EXT && cmd->start_src != TRIG_EXT)
428 err |= -EINVAL;
429
430 if (err)
431 return 2;
432
433 /* Step 3: check if arguments are trivially valid */
434
435 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
436 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
437 if (cmd->convert_src == TRIG_TIMER)
438 err |= comedi_check_trigger_arg_min(&cmd->convert_arg, 12500);
439 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
440 cmd->chanlist_len);
441 if (cmd->stop_src == TRIG_COUNT)
442 err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
443 else /* TRIG_NONE */
444 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
445
446 if (err)
447 return 3;
448
449 /* Step 4: fix up any arguments */
450
451 if (cmd->convert_src == TRIG_TIMER) {
452 arg = cmd->convert_arg;
453 devpriv->ai_divisor = dt2811_ns_to_timer(&arg, cmd->flags);
454 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
455 } else { /* TRIG_EXT */
456 /* The convert_arg is used to set the divisor. */
457 devpriv->ai_divisor = cmd->convert_arg;
458 }
459
460 if (err)
461 return 4;
462
463 /* Step 5: check channel list if it exists */
464
465 return 0;
466}
222 467
223static int dt2811_ai_eoc(struct comedi_device *dev, 468static int dt2811_ai_eoc(struct comedi_device *dev,
224 struct comedi_subdevice *s, 469 struct comedi_subdevice *s,
@@ -227,32 +472,33 @@ static int dt2811_ai_eoc(struct comedi_device *dev,
227{ 472{
228 unsigned int status; 473 unsigned int status;
229 474
230 status = inb(dev->iobase + DT2811_ADCSR); 475 status = inb(dev->iobase + DT2811_ADCSR_REG);
231 if ((status & DT2811_ADBUSY) == 0) 476 if ((status & DT2811_ADCSR_ADBUSY) == 0)
232 return 0; 477 return 0;
233 return -EBUSY; 478 return -EBUSY;
234} 479}
235 480
236static int dt2811_ai_insn(struct comedi_device *dev, struct comedi_subdevice *s, 481static int dt2811_ai_insn_read(struct comedi_device *dev,
237 struct comedi_insn *insn, unsigned int *data) 482 struct comedi_subdevice *s,
483 struct comedi_insn *insn,
484 unsigned int *data)
238{ 485{
239 int chan = CR_CHAN(insn->chanspec);
240 int ret; 486 int ret;
241 int i; 487 int i;
242 488
489 /* We will already be in Mode 0 */
243 for (i = 0; i < insn->n; i++) { 490 for (i = 0; i < insn->n; i++) {
244 outb(chan, dev->iobase + DT2811_ADGCR); 491 /* load chanspec and trigger conversion */
492 dt2811_ai_set_chanspec(dev, insn->chanspec);
245 493
246 ret = comedi_timeout(dev, s, insn, dt2811_ai_eoc, 0); 494 ret = comedi_timeout(dev, s, insn, dt2811_ai_eoc, 0);
247 if (ret) 495 if (ret)
248 return ret; 496 return ret;
249 497
250 data[i] = inb(dev->iobase + DT2811_ADDATLO); 498 data[i] = dt2811_ai_read_sample(dev, s);
251 data[i] |= inb(dev->iobase + DT2811_ADDATHI) << 8;
252 data[i] &= 0xfff;
253 } 499 }
254 500
255 return i; 501 return insn->n;
256} 502}
257 503
258static int dt2811_ao_insn_write(struct comedi_device *dev, 504static int dt2811_ao_insn_write(struct comedi_device *dev,
@@ -266,9 +512,9 @@ static int dt2811_ao_insn_write(struct comedi_device *dev,
266 512
267 for (i = 0; i < insn->n; i++) { 513 for (i = 0; i < insn->n; i++) {
268 val = data[i]; 514 val = data[i];
269 outb(val & 0xff, dev->iobase + DT2811_DADAT0LO + 2 * chan); 515 outb(val & 0xff, dev->iobase + DT2811_DADATA_LO_REG(chan));
270 outb((val >> 8) & 0xff, 516 outb((val >> 8) & 0xff,
271 dev->iobase + DT2811_DADAT0HI + 2 * chan); 517 dev->iobase + DT2811_DADATA_HI_REG(chan));
272 } 518 }
273 s->readback[chan] = val; 519 s->readback[chan] = val;
274 520
@@ -277,9 +523,10 @@ static int dt2811_ao_insn_write(struct comedi_device *dev,
277 523
278static int dt2811_di_insn_bits(struct comedi_device *dev, 524static int dt2811_di_insn_bits(struct comedi_device *dev,
279 struct comedi_subdevice *s, 525 struct comedi_subdevice *s,
280 struct comedi_insn *insn, unsigned int *data) 526 struct comedi_insn *insn,
527 unsigned int *data)
281{ 528{
282 data[1] = inb(dev->iobase + DT2811_DIO); 529 data[1] = inb(dev->iobase + DT2811_DI_REG);
283 530
284 return insn->n; 531 return insn->n;
285} 532}
@@ -290,185 +537,118 @@ static int dt2811_do_insn_bits(struct comedi_device *dev,
290 unsigned int *data) 537 unsigned int *data)
291{ 538{
292 if (comedi_dio_update_state(s, data)) 539 if (comedi_dio_update_state(s, data))
293 outb(s->state, dev->iobase + DT2811_DIO); 540 outb(s->state, dev->iobase + DT2811_DO_REG);
294 541
295 data[1] = s->state; 542 data[1] = s->state;
296 543
297 return insn->n; 544 return insn->n;
298} 545}
299 546
300/* 547static void dt2811_reset(struct comedi_device *dev)
301 options[0] Board base address 548{
302 options[1] IRQ 549 /* This is the initialization sequence from the users manual */
303 options[2] Input configuration 550 outb(DT2811_ADCSR_ADMODE(0), dev->iobase + DT2811_ADCSR_REG);
304 0 == single-ended 551 usleep_range(100, 1000);
305 1 == differential 552 inb(dev->iobase + DT2811_ADDATA_LO_REG);
306 2 == pseudo-differential 553 inb(dev->iobase + DT2811_ADDATA_HI_REG);
307 options[3] Analog input range configuration 554 outb(DT2811_ADCSR_ADMODE(0) | DT2811_ADCSR_CLRERROR,
308 0 == bipolar 5 (-5V -- +5V) 555 dev->iobase + DT2811_ADCSR_REG);
309 1 == bipolar 2.5V (-2.5V -- +2.5V) 556}
310 2 == unipolar 5V (0V -- +5V) 557
311 options[4] Analog output 0 range configuration
312 0 == bipolar 5 (-5V -- +5V)
313 1 == bipolar 2.5V (-2.5V -- +2.5V)
314 2 == unipolar 5V (0V -- +5V)
315 options[5] Analog output 1 range configuration
316 0 == bipolar 5 (-5V -- +5V)
317 1 == bipolar 2.5V (-2.5V -- +2.5V)
318 2 == unipolar 5V (0V -- +5V)
319*/
320static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it) 558static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)
321{ 559{
322 /* int i; */
323 const struct dt2811_board *board = dev->board_ptr; 560 const struct dt2811_board *board = dev->board_ptr;
324 struct dt2811_private *devpriv; 561 struct dt2811_private *devpriv;
325 int ret;
326 struct comedi_subdevice *s; 562 struct comedi_subdevice *s;
563 int ret;
564
565 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
566 if (!devpriv)
567 return -ENOMEM;
327 568
328 ret = comedi_request_region(dev, it->options[0], 0x8); 569 ret = comedi_request_region(dev, it->options[0], 0x8);
329 if (ret) 570 if (ret)
330 return ret; 571 return ret;
331 572
332#if 0 573 dt2811_reset(dev);
333 outb(0, dev->iobase + DT2811_ADCSR); 574
334 udelay(100); 575 /* IRQ's 2,3,5,7 are valid for async command support */
335 i = inb(dev->iobase + DT2811_ADDATLO); 576 if (it->options[1] <= 7 && (BIT(it->options[1]) & 0xac)) {
336 i = inb(dev->iobase + DT2811_ADDATHI); 577 ret = request_irq(it->options[1], dt2811_interrupt, 0,
337#endif 578 dev->board_name, dev);
579 if (ret == 0)
580 dev->irq = it->options[1];
581 }
338 582
339 ret = comedi_alloc_subdevices(dev, 4); 583 ret = comedi_alloc_subdevices(dev, 4);
340 if (ret) 584 if (ret)
341 return ret; 585 return ret;
342 586
343 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); 587 /* Analog Input subdevice */
344 if (!devpriv)
345 return -ENOMEM;
346
347 switch (it->options[2]) {
348 case 0:
349 devpriv->adc_mux = adc_singleended;
350 break;
351 case 1:
352 devpriv->adc_mux = adc_diff;
353 break;
354 case 2:
355 devpriv->adc_mux = adc_pseudo_diff;
356 break;
357 default:
358 devpriv->adc_mux = adc_singleended;
359 break;
360 }
361 switch (it->options[4]) {
362 case 0:
363 devpriv->dac_range[0] = dac_bipolar_5;
364 break;
365 case 1:
366 devpriv->dac_range[0] = dac_bipolar_2_5;
367 break;
368 case 2:
369 devpriv->dac_range[0] = dac_unipolar_5;
370 break;
371 default:
372 devpriv->dac_range[0] = dac_bipolar_5;
373 break;
374 }
375 switch (it->options[5]) {
376 case 0:
377 devpriv->dac_range[1] = dac_bipolar_5;
378 break;
379 case 1:
380 devpriv->dac_range[1] = dac_bipolar_2_5;
381 break;
382 case 2:
383 devpriv->dac_range[1] = dac_unipolar_5;
384 break;
385 default:
386 devpriv->dac_range[1] = dac_bipolar_5;
387 break;
388 }
389
390 s = &dev->subdevices[0]; 588 s = &dev->subdevices[0];
391 /* initialize the ADC subdevice */ 589 s->type = COMEDI_SUBD_AI;
392 s->type = COMEDI_SUBD_AI; 590 s->subdev_flags = SDF_READABLE |
393 s->subdev_flags = SDF_READABLE | SDF_GROUND; 591 (it->options[2] == 1) ? SDF_DIFF :
394 s->n_chan = devpriv->adc_mux == adc_diff ? 8 : 16; 592 (it->options[2] == 2) ? SDF_COMMON : SDF_GROUND;
395 s->insn_read = dt2811_ai_insn; 593 s->n_chan = (it->options[2] == 1) ? 8 : 16;
396 s->maxdata = 0xfff; 594 s->maxdata = 0x0fff;
397 switch (it->options[3]) { 595 s->range_table = board->is_pgh ? &dt2811_pgh_ai_ranges
398 case 0: 596 : &dt2811_pgl_ai_ranges;
399 default: 597 s->insn_read = dt2811_ai_insn_read;
400 s->range_table = board->bip_5; 598 if (dev->irq) {
401 break; 599 dev->read_subdev = s;
402 case 1: 600 s->subdev_flags |= SDF_CMD_READ;
403 s->range_table = board->bip_2_5; 601 s->len_chanlist = 1;
404 break; 602 s->do_cmdtest = dt2811_ai_cmdtest;
405 case 2: 603 s->do_cmd = dt2811_ai_cmd;
406 s->range_table = board->unip_5; 604 s->cancel = dt2811_ai_cancel;
407 break;
408 } 605 }
409 606
607 /* Analog Output subdevice */
410 s = &dev->subdevices[1]; 608 s = &dev->subdevices[1];
411 /* ao subdevice */ 609 s->type = COMEDI_SUBD_AO;
412 s->type = COMEDI_SUBD_AO; 610 s->subdev_flags = SDF_WRITABLE;
413 s->subdev_flags = SDF_WRITABLE; 611 s->n_chan = 2;
414 s->n_chan = 2; 612 s->maxdata = 0x0fff;
415 s->maxdata = 0xfff; 613 s->range_table = &dt2811_ao_ranges;
416 s->range_table_list = devpriv->range_type_list; 614 s->insn_write = dt2811_ao_insn_write;
417 devpriv->range_type_list[0] = dac_range_types[devpriv->dac_range[0]];
418 devpriv->range_type_list[1] = dac_range_types[devpriv->dac_range[1]];
419 s->insn_write = dt2811_ao_insn_write;
420 615
421 ret = comedi_alloc_subdev_readback(s); 616 ret = comedi_alloc_subdev_readback(s);
422 if (ret) 617 if (ret)
423 return ret; 618 return ret;
424 619
620 /* Digital Input subdevice */
425 s = &dev->subdevices[2]; 621 s = &dev->subdevices[2];
426 /* di subdevice */ 622 s->type = COMEDI_SUBD_DI;
427 s->type = COMEDI_SUBD_DI; 623 s->subdev_flags = SDF_READABLE;
428 s->subdev_flags = SDF_READABLE; 624 s->n_chan = 8;
429 s->n_chan = 8; 625 s->maxdata = 1;
430 s->insn_bits = dt2811_di_insn_bits; 626 s->range_table = &range_digital;
431 s->maxdata = 1; 627 s->insn_bits = dt2811_di_insn_bits;
432 s->range_table = &range_digital; 628
433 629 /* Digital Output subdevice */
434 s = &dev->subdevices[3]; 630 s = &dev->subdevices[3];
435 /* do subdevice */ 631 s->type = COMEDI_SUBD_DO;
436 s->type = COMEDI_SUBD_DO; 632 s->subdev_flags = SDF_WRITABLE;
437 s->subdev_flags = SDF_WRITABLE; 633 s->n_chan = 8;
438 s->n_chan = 8; 634 s->maxdata = 1;
439 s->insn_bits = dt2811_do_insn_bits; 635 s->range_table = &range_digital;
440 s->maxdata = 1; 636 s->insn_bits = dt2811_do_insn_bits;
441 s->state = 0;
442 s->range_table = &range_digital;
443 637
444 return 0; 638 return 0;
445} 639}
446 640
447static const struct dt2811_board boardtypes[] = {
448 {
449 .name = "dt2811-pgh",
450 .bip_5 = &range_dt2811_pgh_ai_5_bipolar,
451 .bip_2_5 = &range_dt2811_pgh_ai_2_5_bipolar,
452 .unip_5 = &range_dt2811_pgh_ai_5_unipolar,
453 }, {
454 .name = "dt2811-pgl",
455 .bip_5 = &range_dt2811_pgl_ai_5_bipolar,
456 .bip_2_5 = &range_dt2811_pgl_ai_2_5_bipolar,
457 .unip_5 = &range_dt2811_pgl_ai_5_unipolar,
458 },
459};
460
461static struct comedi_driver dt2811_driver = { 641static struct comedi_driver dt2811_driver = {
462 .driver_name = "dt2811", 642 .driver_name = "dt2811",
463 .module = THIS_MODULE, 643 .module = THIS_MODULE,
464 .attach = dt2811_attach, 644 .attach = dt2811_attach,
465 .detach = comedi_legacy_detach, 645 .detach = comedi_legacy_detach,
466 .board_name = &boardtypes[0].name, 646 .board_name = &dt2811_boards[0].name,
467 .num_names = ARRAY_SIZE(boardtypes), 647 .num_names = ARRAY_SIZE(dt2811_boards),
468 .offset = sizeof(struct dt2811_board), 648 .offset = sizeof(struct dt2811_board),
469}; 649};
470module_comedi_driver(dt2811_driver); 650module_comedi_driver(dt2811_driver);
471 651
472MODULE_AUTHOR("Comedi http://www.comedi.org"); 652MODULE_AUTHOR("Comedi http://www.comedi.org");
473MODULE_DESCRIPTION("Comedi low-level driver"); 653MODULE_DESCRIPTION("Comedi driver for Data Translation DT2811 series boards");
474MODULE_LICENSE("GPL"); 654MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/dt2814.c b/drivers/staging/comedi/drivers/dt2814.c
index 66705f9a0621..2f903bedcefa 100644
--- a/drivers/staging/comedi/drivers/dt2814.c
+++ b/drivers/staging/comedi/drivers/dt2814.c
@@ -1,38 +1,38 @@
1/* 1/*
2 comedi/drivers/dt2814.c 2 * comedi/drivers/dt2814.c
3 Hardware driver for Data Translation DT2814 3 * Hardware driver for Data Translation DT2814
4 4 *
5 COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1998 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17*/ 17 */
18/* 18/*
19Driver: dt2814 19 * Driver: dt2814
20Description: Data Translation DT2814 20 * Description: Data Translation DT2814
21Author: ds 21 * Author: ds
22Status: complete 22 * Status: complete
23Devices: [Data Translation] DT2814 (dt2814) 23 * Devices: [Data Translation] DT2814 (dt2814)
24 24 *
25Configuration options: 25 * Configuration options:
26 [0] - I/O port base address 26 * [0] - I/O port base address
27 [1] - IRQ 27 * [1] - IRQ
28 28 *
29This card has 16 analog inputs multiplexed onto a 12 bit ADC. There 29 * This card has 16 analog inputs multiplexed onto a 12 bit ADC. There
30is a minimally useful onboard clock. The base frequency for the 30 * is a minimally useful onboard clock. The base frequency for the
31clock is selected by jumpers, and the clock divider can be selected 31 * clock is selected by jumpers, and the clock divider can be selected
32via programmed I/O. Unfortunately, the clock divider can only be 32 * via programmed I/O. Unfortunately, the clock divider can only be
33a power of 10, from 1 to 10^7, of which only 3 or 4 are useful. In 33 * a power of 10, from 1 to 10^7, of which only 3 or 4 are useful. In
34addition, the clock does not seem to be very accurate. 34 * addition, the clock does not seem to be very accurate.
35*/ 35 */
36 36
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/interrupt.h> 38#include <linux/interrupt.h>
@@ -215,8 +215,10 @@ static irqreturn_t dt2814_interrupt(int irq, void *d)
215 int i; 215 int i;
216 216
217 outb(0, dev->iobase + DT2814_CSR); 217 outb(0, dev->iobase + DT2814_CSR);
218 /* note: turning off timed mode triggers another 218 /*
219 sample. */ 219 * note: turning off timed mode triggers another
220 * sample.
221 */
220 222
221 for (i = 0; i < DT2814_TIMEOUT; i++) { 223 for (i = 0; i < DT2814_TIMEOUT; i++) {
222 if (inb(dev->iobase + DT2814_CSR) & DT2814_FINISH) 224 if (inb(dev->iobase + DT2814_CSR) & DT2814_FINISH)
diff --git a/drivers/staging/comedi/drivers/dt2815.c b/drivers/staging/comedi/drivers/dt2815.c
index fb08569c1ac1..0be77cc40a79 100644
--- a/drivers/staging/comedi/drivers/dt2815.c
+++ b/drivers/staging/comedi/drivers/dt2815.c
@@ -1,55 +1,55 @@
1/* 1/*
2 comedi/drivers/dt2815.c 2 * comedi/drivers/dt2815.c
3 Hardware driver for Data Translation DT2815 3 * Hardware driver for Data Translation DT2815
4 4 *
5 COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se> 6 * Copyright (C) 1999 Anders Blomdell <anders.blomdell@control.lth.se>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18/* 18/*
19Driver: dt2815 19 * Driver: dt2815
20Description: Data Translation DT2815 20 * Description: Data Translation DT2815
21Author: ds 21 * Author: ds
22Status: mostly complete, untested 22 * Status: mostly complete, untested
23Devices: [Data Translation] DT2815 (dt2815) 23 * Devices: [Data Translation] DT2815 (dt2815)
24 24 *
25I'm not sure anyone has ever tested this board. If you have information 25 * I'm not sure anyone has ever tested this board. If you have information
26contrary, please update. 26 * contrary, please update.
27 27 *
28Configuration options: 28 * Configuration options:
29 [0] - I/O port base base address 29 * [0] - I/O port base base address
30 [1] - IRQ (unused) 30 * [1] - IRQ (unused)
31 [2] - Voltage unipolar/bipolar configuration 31 * [2] - Voltage unipolar/bipolar configuration
32 0 == unipolar 5V (0V -- +5V) 32 * 0 == unipolar 5V (0V -- +5V)
33 1 == bipolar 5V (-5V -- +5V) 33 * 1 == bipolar 5V (-5V -- +5V)
34 [3] - Current offset configuration 34 * [3] - Current offset configuration
35 0 == disabled (0mA -- +32mAV) 35 * 0 == disabled (0mA -- +32mAV)
36 1 == enabled (+4mA -- +20mAV) 36 * 1 == enabled (+4mA -- +20mAV)
37 [4] - Firmware program configuration 37 * [4] - Firmware program configuration
38 0 == program 1 (see manual table 5-4) 38 * 0 == program 1 (see manual table 5-4)
39 1 == program 2 (see manual table 5-4) 39 * 1 == program 2 (see manual table 5-4)
40 2 == program 3 (see manual table 5-4) 40 * 2 == program 3 (see manual table 5-4)
41 3 == program 4 (see manual table 5-4) 41 * 3 == program 4 (see manual table 5-4)
42 [5] - Analog output 0 range configuration 42 * [5] - Analog output 0 range configuration
43 0 == voltage 43 * 0 == voltage
44 1 == current 44 * 1 == current
45 [6] - Analog output 1 range configuration (same options) 45 * [6] - Analog output 1 range configuration (same options)
46 [7] - Analog output 2 range configuration (same options) 46 * [7] - Analog output 2 range configuration (same options)
47 [8] - Analog output 3 range configuration (same options) 47 * [8] - Analog output 3 range configuration (same options)
48 [9] - Analog output 4 range configuration (same options) 48 * [9] - Analog output 4 range configuration (same options)
49 [10] - Analog output 5 range configuration (same options) 49 * [10] - Analog output 5 range configuration (same options)
50 [11] - Analog output 6 range configuration (same options) 50 * [11] - Analog output 6 range configuration (same options)
51 [12] - Analog output 7 range configuration (same options) 51 * [12] - Analog output 7 range configuration (same options)
52*/ 52 */
53 53
54#include <linux/module.h> 54#include <linux/module.h>
55#include "../comedidev.h" 55#include "../comedidev.h"
@@ -120,27 +120,27 @@ static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
120} 120}
121 121
122/* 122/*
123 options[0] Board base address 123 * options[0] Board base address
124 options[1] IRQ (not applicable) 124 * options[1] IRQ (not applicable)
125 options[2] Voltage unipolar/bipolar configuration 125 * options[2] Voltage unipolar/bipolar configuration
126 0 == unipolar 5V (0V -- +5V) 126 * 0 == unipolar 5V (0V -- +5V)
127 1 == bipolar 5V (-5V -- +5V) 127 * 1 == bipolar 5V (-5V -- +5V)
128 options[3] Current offset configuration 128 * options[3] Current offset configuration
129 0 == disabled (0mA -- +32mAV) 129 * 0 == disabled (0mA -- +32mAV)
130 1 == enabled (+4mA -- +20mAV) 130 * 1 == enabled (+4mA -- +20mAV)
131 options[4] Firmware program configuration 131 * options[4] Firmware program configuration
132 0 == program 1 (see manual table 5-4) 132 * 0 == program 1 (see manual table 5-4)
133 1 == program 2 (see manual table 5-4) 133 * 1 == program 2 (see manual table 5-4)
134 2 == program 3 (see manual table 5-4) 134 * 2 == program 3 (see manual table 5-4)
135 3 == program 4 (see manual table 5-4) 135 * 3 == program 4 (see manual table 5-4)
136 options[5] Analog output 0 range configuration 136 * options[5] Analog output 0 range configuration
137 0 == voltage 137 * 0 == voltage
138 1 == current 138 * 1 == current
139 options[6] Analog output 1 range configuration 139 * options[6] Analog output 1 range configuration
140 ... 140 * ...
141 options[12] Analog output 7 range configuration 141 * options[12] Analog output 7 range configuration
142 0 == voltage 142 * 0 == voltage
143 1 == current 143 * 1 == current
144 */ 144 */
145 145
146static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it) 146static int dt2815_attach(struct comedi_device *dev, struct comedi_devconfig *it)
diff --git a/drivers/staging/comedi/drivers/dt2817.c b/drivers/staging/comedi/drivers/dt2817.c
index 5131deebf66f..39d2566e49bf 100644
--- a/drivers/staging/comedi/drivers/dt2817.c
+++ b/drivers/staging/comedi/drivers/dt2817.c
@@ -1,37 +1,37 @@
1/* 1/*
2 comedi/drivers/dt2817.c 2 * comedi/drivers/dt2817.c
3 Hardware driver for Data Translation DT2817 3 * Hardware driver for Data Translation DT2817
4 4 *
5 COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1998 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17*/ 17 */
18/* 18/*
19Driver: dt2817 19 * Driver: dt2817
20Description: Data Translation DT2817 20 * Description: Data Translation DT2817
21Author: ds 21 * Author: ds
22Status: complete 22 * Status: complete
23Devices: [Data Translation] DT2817 (dt2817) 23 * Devices: [Data Translation] DT2817 (dt2817)
24 24 *
25A very simple digital I/O card. Four banks of 8 lines, each bank 25 * A very simple digital I/O card. Four banks of 8 lines, each bank
26is configurable for input or output. One wonders why it takes a 26 * is configurable for input or output. One wonders why it takes a
2750 page manual to describe this thing. 27 * 50 page manual to describe this thing.
28 28 *
29The driver (which, btw, is much less than 50 pages) has 1 subdevice 29 * The driver (which, btw, is much less than 50 pages) has 1 subdevice
30with 32 channels, configurable in groups of 8. 30 * with 32 channels, configurable in groups of 8.
31 31 *
32Configuration options: 32 * Configuration options:
33 [0] - I/O port base base address 33 * [0] - I/O port base base address
34*/ 34 */
35 35
36#include <linux/module.h> 36#include <linux/module.h>
37#include "../comedidev.h" 37#include "../comedidev.h"
diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c
index 63b5cbc44bda..af4b4175af4d 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -158,10 +158,7 @@ static void gsc_hpdi_drain_dma(struct comedi_device *dev, unsigned int channel)
158 unsigned int size; 158 unsigned int size;
159 unsigned int next; 159 unsigned int next;
160 160
161 if (channel) 161 next = readl(devpriv->plx9080_mmio + PLX_REG_DMAPADR(channel));
162 next = readl(devpriv->plx9080_mmio + PLX_DMA1_PCI_ADDRESS_REG);
163 else
164 next = readl(devpriv->plx9080_mmio + PLX_DMA0_PCI_ADDRESS_REG);
165 162
166 idx = devpriv->dma_desc_index; 163 idx = devpriv->dma_desc_index;
167 start = le32_to_cpu(devpriv->dma_desc[idx].pci_start_addr); 164 start = le32_to_cpu(devpriv->dma_desc[idx].pci_start_addr);
@@ -201,8 +198,9 @@ static irqreturn_t gsc_hpdi_interrupt(int irq, void *d)
201 if (!dev->attached) 198 if (!dev->attached)
202 return IRQ_NONE; 199 return IRQ_NONE;
203 200
204 plx_status = readl(devpriv->plx9080_mmio + PLX_INTRCS_REG); 201 plx_status = readl(devpriv->plx9080_mmio + PLX_REG_INTCSR);
205 if ((plx_status & (ICS_DMA0_A | ICS_DMA1_A | ICS_LIA)) == 0) 202 if ((plx_status &
203 (PLX_INTCSR_DMA0IA | PLX_INTCSR_DMA1IA | PLX_INTCSR_PLIA)) == 0)
206 return IRQ_NONE; 204 return IRQ_NONE;
207 205
208 hpdi_intr_status = readl(dev->mmio + INTERRUPT_STATUS_REG); 206 hpdi_intr_status = readl(dev->mmio + INTERRUPT_STATUS_REG);
@@ -213,32 +211,32 @@ static irqreturn_t gsc_hpdi_interrupt(int irq, void *d)
213 211
214 /* spin lock makes sure no one else changes plx dma control reg */ 212 /* spin lock makes sure no one else changes plx dma control reg */
215 spin_lock_irqsave(&dev->spinlock, flags); 213 spin_lock_irqsave(&dev->spinlock, flags);
216 dma0_status = readb(devpriv->plx9080_mmio + PLX_DMA0_CS_REG); 214 dma0_status = readb(devpriv->plx9080_mmio + PLX_REG_DMACSR0);
217 if (plx_status & ICS_DMA0_A) { 215 if (plx_status & PLX_INTCSR_DMA0IA) {
218 /* dma chan 0 interrupt */ 216 /* dma chan 0 interrupt */
219 writeb((dma0_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, 217 writeb((dma0_status & PLX_DMACSR_ENABLE) | PLX_DMACSR_CLEARINTR,
220 devpriv->plx9080_mmio + PLX_DMA0_CS_REG); 218 devpriv->plx9080_mmio + PLX_REG_DMACSR0);
221 219
222 if (dma0_status & PLX_DMA_EN_BIT) 220 if (dma0_status & PLX_DMACSR_ENABLE)
223 gsc_hpdi_drain_dma(dev, 0); 221 gsc_hpdi_drain_dma(dev, 0);
224 } 222 }
225 spin_unlock_irqrestore(&dev->spinlock, flags); 223 spin_unlock_irqrestore(&dev->spinlock, flags);
226 224
227 /* spin lock makes sure no one else changes plx dma control reg */ 225 /* spin lock makes sure no one else changes plx dma control reg */
228 spin_lock_irqsave(&dev->spinlock, flags); 226 spin_lock_irqsave(&dev->spinlock, flags);
229 dma1_status = readb(devpriv->plx9080_mmio + PLX_DMA1_CS_REG); 227 dma1_status = readb(devpriv->plx9080_mmio + PLX_REG_DMACSR1);
230 if (plx_status & ICS_DMA1_A) { 228 if (plx_status & PLX_INTCSR_DMA1IA) {
231 /* XXX */ /* dma chan 1 interrupt */ 229 /* XXX */ /* dma chan 1 interrupt */
232 writeb((dma1_status & PLX_DMA_EN_BIT) | PLX_CLEAR_DMA_INTR_BIT, 230 writeb((dma1_status & PLX_DMACSR_ENABLE) | PLX_DMACSR_CLEARINTR,
233 devpriv->plx9080_mmio + PLX_DMA1_CS_REG); 231 devpriv->plx9080_mmio + PLX_REG_DMACSR1);
234 } 232 }
235 spin_unlock_irqrestore(&dev->spinlock, flags); 233 spin_unlock_irqrestore(&dev->spinlock, flags);
236 234
237 /* clear possible plx9080 interrupt sources */ 235 /* clear possible plx9080 interrupt sources */
238 if (plx_status & ICS_LDIA) { 236 if (plx_status & PLX_INTCSR_LDBIA) {
239 /* clear local doorbell interrupt */ 237 /* clear local doorbell interrupt */
240 plx_bits = readl(devpriv->plx9080_mmio + PLX_DBR_OUT_REG); 238 plx_bits = readl(devpriv->plx9080_mmio + PLX_REG_L2PDBELL);
241 writel(plx_bits, devpriv->plx9080_mmio + PLX_DBR_OUT_REG); 239 writel(plx_bits, devpriv->plx9080_mmio + PLX_REG_L2PDBELL);
242 } 240 }
243 241
244 if (hpdi_board_status & RX_OVERRUN_BIT) { 242 if (hpdi_board_status & RX_OVERRUN_BIT) {
@@ -307,19 +305,19 @@ static int gsc_hpdi_cmd(struct comedi_device *dev,
307 * occasionally cause problems with transfer of first dma 305 * occasionally cause problems with transfer of first dma
308 * block. Initializing them to zero seems to fix the problem. 306 * block. Initializing them to zero seems to fix the problem.
309 */ 307 */
310 writel(0, devpriv->plx9080_mmio + PLX_DMA0_TRANSFER_SIZE_REG); 308 writel(0, devpriv->plx9080_mmio + PLX_REG_DMASIZ0);
311 writel(0, devpriv->plx9080_mmio + PLX_DMA0_PCI_ADDRESS_REG); 309 writel(0, devpriv->plx9080_mmio + PLX_REG_DMAPADR0);
312 writel(0, devpriv->plx9080_mmio + PLX_DMA0_LOCAL_ADDRESS_REG); 310 writel(0, devpriv->plx9080_mmio + PLX_REG_DMALADR0);
313 311
314 /* give location of first dma descriptor */ 312 /* give location of first dma descriptor */
315 bits = devpriv->dma_desc_phys_addr | PLX_DESC_IN_PCI_BIT | 313 bits = devpriv->dma_desc_phys_addr | PLX_DMADPR_DESCPCI |
316 PLX_INTR_TERM_COUNT | PLX_XFER_LOCAL_TO_PCI; 314 PLX_DMADPR_TCINTR | PLX_DMADPR_XFERL2P;
317 writel(bits, devpriv->plx9080_mmio + PLX_DMA0_DESCRIPTOR_REG); 315 writel(bits, devpriv->plx9080_mmio + PLX_REG_DMADPR0);
318 316
319 /* enable dma transfer */ 317 /* enable dma transfer */
320 spin_lock_irqsave(&dev->spinlock, flags); 318 spin_lock_irqsave(&dev->spinlock, flags);
321 writeb(PLX_DMA_EN_BIT | PLX_DMA_START_BIT | PLX_CLEAR_DMA_INTR_BIT, 319 writeb(PLX_DMACSR_ENABLE | PLX_DMACSR_START | PLX_DMACSR_CLEARINTR,
322 devpriv->plx9080_mmio + PLX_DMA0_CS_REG); 320 devpriv->plx9080_mmio + PLX_REG_DMACSR0);
323 spin_unlock_irqrestore(&dev->spinlock, flags); 321 spin_unlock_irqrestore(&dev->spinlock, flags);
324 322
325 if (cmd->stop_src == TRIG_COUNT) 323 if (cmd->stop_src == TRIG_COUNT)
@@ -424,8 +422,8 @@ static int gsc_hpdi_setup_dma_descriptors(struct comedi_device *dev,
424{ 422{
425 struct hpdi_private *devpriv = dev->private; 423 struct hpdi_private *devpriv = dev->private;
426 dma_addr_t phys_addr = devpriv->dma_desc_phys_addr; 424 dma_addr_t phys_addr = devpriv->dma_desc_phys_addr;
427 u32 next_bits = PLX_DESC_IN_PCI_BIT | PLX_INTR_TERM_COUNT | 425 u32 next_bits = PLX_DMADPR_DESCPCI | PLX_DMADPR_TCINTR |
428 PLX_XFER_LOCAL_TO_PCI; 426 PLX_DMADPR_XFERL2P;
429 unsigned int offset = 0; 427 unsigned int offset = 0;
430 unsigned int idx = 0; 428 unsigned int idx = 0;
431 unsigned int i; 429 unsigned int i;
@@ -536,9 +534,10 @@ static int gsc_hpdi_init(struct comedi_device *dev)
536 534
537 /* enable interrupts */ 535 /* enable interrupts */
538 plx_intcsr_bits = 536 plx_intcsr_bits =
539 ICS_AERR | ICS_PERR | ICS_PIE | ICS_PLIE | ICS_PAIE | ICS_LIE | 537 PLX_INTCSR_LSEABORTEN | PLX_INTCSR_LSEPARITYEN | PLX_INTCSR_PIEN |
540 ICS_DMA0_E; 538 PLX_INTCSR_PLIEN | PLX_INTCSR_PABORTIEN | PLX_INTCSR_LIOEN |
541 writel(plx_intcsr_bits, devpriv->plx9080_mmio + PLX_INTRCS_REG); 539 PLX_INTCSR_DMA0IEN;
540 writel(plx_intcsr_bits, devpriv->plx9080_mmio + PLX_REG_INTCSR);
542 541
543 return 0; 542 return 0;
544} 543}
@@ -550,13 +549,13 @@ static void gsc_hpdi_init_plx9080(struct comedi_device *dev)
550 void __iomem *plx_iobase = devpriv->plx9080_mmio; 549 void __iomem *plx_iobase = devpriv->plx9080_mmio;
551 550
552#ifdef __BIG_ENDIAN 551#ifdef __BIG_ENDIAN
553 bits = BIGEND_DMA0 | BIGEND_DMA1; 552 bits = PLX_BIGEND_DMA0 | PLX_BIGEND_DMA1;
554#else 553#else
555 bits = 0; 554 bits = 0;
556#endif 555#endif
557 writel(bits, devpriv->plx9080_mmio + PLX_BIGEND_REG); 556 writel(bits, devpriv->plx9080_mmio + PLX_REG_BIGEND);
558 557
559 writel(0, devpriv->plx9080_mmio + PLX_INTRCS_REG); 558 writel(0, devpriv->plx9080_mmio + PLX_REG_INTCSR);
560 559
561 gsc_hpdi_abort_dma(dev, 0); 560 gsc_hpdi_abort_dma(dev, 0);
562 gsc_hpdi_abort_dma(dev, 1); 561 gsc_hpdi_abort_dma(dev, 1);
@@ -564,27 +563,27 @@ static void gsc_hpdi_init_plx9080(struct comedi_device *dev)
564 /* configure dma0 mode */ 563 /* configure dma0 mode */
565 bits = 0; 564 bits = 0;
566 /* enable ready input */ 565 /* enable ready input */
567 bits |= PLX_DMA_EN_READYIN_BIT; 566 bits |= PLX_DMAMODE_READYIEN;
568 /* enable dma chaining */ 567 /* enable dma chaining */
569 bits |= PLX_EN_CHAIN_BIT; 568 bits |= PLX_DMAMODE_CHAINEN;
570 /* 569 /*
571 * enable interrupt on dma done 570 * enable interrupt on dma done
572 * (probably don't need this, since chain never finishes) 571 * (probably don't need this, since chain never finishes)
573 */ 572 */
574 bits |= PLX_EN_DMA_DONE_INTR_BIT; 573 bits |= PLX_DMAMODE_DONEIEN;
575 /* 574 /*
576 * don't increment local address during transfers 575 * don't increment local address during transfers
577 * (we are transferring from a fixed fifo register) 576 * (we are transferring from a fixed fifo register)
578 */ 577 */
579 bits |= PLX_LOCAL_ADDR_CONST_BIT; 578 bits |= PLX_DMAMODE_LACONST;
580 /* route dma interrupt to pci bus */ 579 /* route dma interrupt to pci bus */
581 bits |= PLX_DMA_INTR_PCI_BIT; 580 bits |= PLX_DMAMODE_INTRPCI;
582 /* enable demand mode */ 581 /* enable demand mode */
583 bits |= PLX_DEMAND_MODE_BIT; 582 bits |= PLX_DMAMODE_DEMAND;
584 /* enable local burst mode */ 583 /* enable local burst mode */
585 bits |= PLX_DMA_LOCAL_BURST_EN_BIT; 584 bits |= PLX_DMAMODE_BURSTEN;
586 bits |= PLX_LOCAL_BUS_32_WIDE_BITS; 585 bits |= PLX_DMAMODE_WIDTH32;
587 writel(bits, plx_iobase + PLX_DMA0_MODE_REG); 586 writel(bits, plx_iobase + PLX_REG_DMAMODE0);
588} 587}
589 588
590static int gsc_hpdi_auto_attach(struct comedi_device *dev, 589static int gsc_hpdi_auto_attach(struct comedi_device *dev,
@@ -680,7 +679,7 @@ static void gsc_hpdi_detach(struct comedi_device *dev)
680 free_irq(dev->irq, dev); 679 free_irq(dev->irq, dev);
681 if (devpriv) { 680 if (devpriv) {
682 if (devpriv->plx9080_mmio) { 681 if (devpriv->plx9080_mmio) {
683 writel(0, devpriv->plx9080_mmio + PLX_INTRCS_REG); 682 writel(0, devpriv->plx9080_mmio + PLX_REG_INTCSR);
684 iounmap(devpriv->plx9080_mmio); 683 iounmap(devpriv->plx9080_mmio);
685 } 684 }
686 if (dev->mmio) 685 if (dev->mmio)
diff --git a/drivers/staging/comedi/drivers/jr3_pci.c b/drivers/staging/comedi/drivers/jr3_pci.c
index b87192e0f9aa..6c4ff023717f 100644
--- a/drivers/staging/comedi/drivers/jr3_pci.c
+++ b/drivers/staging/comedi/drivers/jr3_pci.c
@@ -1,20 +1,20 @@
1/* 1/*
2 comedi/drivers/jr3_pci.c 2 * comedi/drivers/jr3_pci.c
3 hardware driver for JR3/PCI force sensor board 3 * hardware driver for JR3/PCI force sensor board
4 4 *
5 COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2007 Anders Blomdell <anders.blomdell@control.lth.se> 6 * Copyright (C) 2007 Anders Blomdell <anders.blomdell@control.lth.se>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17*/ 17 */
18/* 18/*
19 * Driver: jr3_pci 19 * Driver: jr3_pci
20 * Description: JR3/PCI force sensor board 20 * Description: JR3/PCI force sensor board
@@ -231,7 +231,7 @@ static unsigned int jr3_pci_ai_read_chan(struct comedi_device *dev,
231 231
232 if (chan < 56) { 232 if (chan < 56) {
233 unsigned int axis = chan % 8; 233 unsigned int axis = chan % 8;
234 unsigned filter = chan / 8; 234 unsigned int filter = chan / 8;
235 235
236 switch (axis) { 236 switch (axis) {
237 case 0: 237 case 0:
@@ -690,7 +690,7 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
690 if (sizeof(struct jr3_channel) != 0xc00) { 690 if (sizeof(struct jr3_channel) != 0xc00) {
691 dev_err(dev->class_dev, 691 dev_err(dev->class_dev,
692 "sizeof(struct jr3_channel) = %x [expected %x]\n", 692 "sizeof(struct jr3_channel) = %x [expected %x]\n",
693 (unsigned)sizeof(struct jr3_channel), 0xc00); 693 (unsigned int)sizeof(struct jr3_channel), 0xc00);
694 return -EINVAL; 694 return -EINVAL;
695 } 695 }
696 696
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c
index 3bf0caa18ab0..c0b7a300e428 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -150,7 +150,7 @@ struct me_private_data {
150 unsigned short dac_ctrl; /* Mirror of the DAC_CONTROL register */ 150 unsigned short dac_ctrl; /* Mirror of the DAC_CONTROL register */
151}; 151};
152 152
153static inline void sleep(unsigned sec) 153static inline void sleep(unsigned int sec)
154{ 154{
155 schedule_timeout_interruptible(sec * HZ); 155 schedule_timeout_interruptible(sec * HZ);
156} 156}
diff --git a/drivers/staging/comedi/drivers/mpc624.c b/drivers/staging/comedi/drivers/mpc624.c
index 826e4399c87e..9bda761433c2 100644
--- a/drivers/staging/comedi/drivers/mpc624.c
+++ b/drivers/staging/comedi/drivers/mpc624.c
@@ -103,7 +103,7 @@ static const struct comedi_lrange range_mpc624_bipolar1 = {
103/* BIP_RANGE(1.01) this is correct, */ 103/* BIP_RANGE(1.01) this is correct, */
104 /* but my MPC-624 actually seems to have a range of 2.02 */ 104 /* but my MPC-624 actually seems to have a range of 2.02 */
105 BIP_RANGE(2.02) 105 BIP_RANGE(2.02)
106 } 106 }
107}; 107};
108 108
109static const struct comedi_lrange range_mpc624_bipolar10 = { 109static const struct comedi_lrange range_mpc624_bipolar10 = {
@@ -112,7 +112,7 @@ static const struct comedi_lrange range_mpc624_bipolar10 = {
112/* BIP_RANGE(10.1) this is correct, */ 112/* BIP_RANGE(10.1) this is correct, */
113 /* but my MPC-624 actually seems to have a range of 20.2 */ 113 /* but my MPC-624 actually seems to have a range of 20.2 */
114 BIP_RANGE(20.2) 114 BIP_RANGE(20.2)
115 } 115 }
116}; 116};
117 117
118static unsigned int mpc624_ai_get_sample(struct comedi_device *dev, 118static unsigned int mpc624_ai_get_sample(struct comedi_device *dev,
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 251117be1205..07f38e385469 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -151,10 +151,10 @@ enum ni_65xx_boardid {
151 151
152struct ni_65xx_board { 152struct ni_65xx_board {
153 const char *name; 153 const char *name;
154 unsigned num_dio_ports; 154 unsigned int num_dio_ports;
155 unsigned num_di_ports; 155 unsigned int num_di_ports;
156 unsigned num_do_ports; 156 unsigned int num_do_ports;
157 unsigned legacy_invert:1; 157 unsigned int legacy_invert:1;
158}; 158};
159 159
160static const struct ni_65xx_board ni_65xx_boards[] = { 160static const struct ni_65xx_board ni_65xx_boards[] = {
@@ -360,7 +360,7 @@ static int ni_65xx_dio_insn_config(struct comedi_device *dev,
360 unsigned long base_port = (unsigned long)s->private; 360 unsigned long base_port = (unsigned long)s->private;
361 unsigned int chan = CR_CHAN(insn->chanspec); 361 unsigned int chan = CR_CHAN(insn->chanspec);
362 unsigned int chan_mask = NI_65XX_CHAN_TO_MASK(chan); 362 unsigned int chan_mask = NI_65XX_CHAN_TO_MASK(chan);
363 unsigned port = base_port + NI_65XX_CHAN_TO_PORT(chan); 363 unsigned int port = base_port + NI_65XX_CHAN_TO_PORT(chan);
364 unsigned int interval; 364 unsigned int interval;
365 unsigned int val; 365 unsigned int val;
366 366
@@ -428,14 +428,14 @@ static int ni_65xx_dio_insn_bits(struct comedi_device *dev,
428 unsigned long base_port = (unsigned long)s->private; 428 unsigned long base_port = (unsigned long)s->private;
429 unsigned int base_chan = CR_CHAN(insn->chanspec); 429 unsigned int base_chan = CR_CHAN(insn->chanspec);
430 int last_port_offset = NI_65XX_CHAN_TO_PORT(s->n_chan - 1); 430 int last_port_offset = NI_65XX_CHAN_TO_PORT(s->n_chan - 1);
431 unsigned read_bits = 0; 431 unsigned int read_bits = 0;
432 int port_offset; 432 int port_offset;
433 433
434 for (port_offset = NI_65XX_CHAN_TO_PORT(base_chan); 434 for (port_offset = NI_65XX_CHAN_TO_PORT(base_chan);
435 port_offset <= last_port_offset; port_offset++) { 435 port_offset <= last_port_offset; port_offset++) {
436 unsigned port = base_port + port_offset; 436 unsigned int port = base_port + port_offset;
437 int base_port_channel = NI_65XX_PORT_TO_CHAN(port_offset); 437 int base_port_channel = NI_65XX_PORT_TO_CHAN(port_offset);
438 unsigned port_mask, port_data, bits; 438 unsigned int port_mask, port_data, bits;
439 int bitshift = base_port_channel - base_chan; 439 int bitshift = base_port_channel - base_chan;
440 440
441 if (bitshift >= 32) 441 if (bitshift >= 32)
@@ -640,7 +640,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
640 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 640 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
641 const struct ni_65xx_board *board = NULL; 641 const struct ni_65xx_board *board = NULL;
642 struct comedi_subdevice *s; 642 struct comedi_subdevice *s;
643 unsigned i; 643 unsigned int i;
644 int ret; 644 int ret;
645 645
646 if (context < ARRAY_SIZE(ni_65xx_boards)) 646 if (context < ARRAY_SIZE(ni_65xx_boards))
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index 02a532990979..35ef1925703f 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -170,12 +170,12 @@ comedi_nonfree_firmware tarball available from http://www.comedi.org
170#define DMA_Line_Control_Group1 76 170#define DMA_Line_Control_Group1 76
171#define DMA_Line_Control_Group2 108 171#define DMA_Line_Control_Group2 108
172/* channel zero is none */ 172/* channel zero is none */
173static inline unsigned primary_DMAChannel_bits(unsigned channel) 173static inline unsigned int primary_DMAChannel_bits(unsigned int channel)
174{ 174{
175 return channel & 0x3; 175 return channel & 0x3;
176} 176}
177 177
178static inline unsigned secondary_DMAChannel_bits(unsigned channel) 178static inline unsigned int secondary_DMAChannel_bits(unsigned int channel)
179{ 179{
180 return (channel << 2) & 0xc; 180 return (channel << 2) & 0xc;
181} 181}
diff --git a/drivers/staging/comedi/drivers/ni_pcimio.c b/drivers/staging/comedi/drivers/ni_pcimio.c
index 344aa343e5e1..d8917392b9f9 100644
--- a/drivers/staging/comedi/drivers/ni_pcimio.c
+++ b/drivers/staging/comedi/drivers/ni_pcimio.c
@@ -1064,12 +1064,12 @@ static void m_series_init_eeprom_buffer(struct comedi_device *dev)
1064 struct mite *mite = devpriv->mite; 1064 struct mite *mite = devpriv->mite;
1065 resource_size_t daq_phys_addr; 1065 resource_size_t daq_phys_addr;
1066 static const int Start_Cal_EEPROM = 0x400; 1066 static const int Start_Cal_EEPROM = 0x400;
1067 static const unsigned window_size = 10; 1067 static const unsigned int window_size = 10;
1068 static const int serial_number_eeprom_offset = 0x4; 1068 static const int serial_number_eeprom_offset = 0x4;
1069 static const int serial_number_eeprom_length = 0x4; 1069 static const int serial_number_eeprom_length = 0x4;
1070 unsigned old_iodwbsr_bits; 1070 unsigned int old_iodwbsr_bits;
1071 unsigned old_iodwbsr1_bits; 1071 unsigned int old_iodwbsr1_bits;
1072 unsigned old_iodwcr1_bits; 1072 unsigned int old_iodwcr1_bits;
1073 int i; 1073 int i;
1074 1074
1075 /* IO Window 1 needs to be temporarily mapped to read the eeprom */ 1075 /* IO Window 1 needs to be temporarily mapped to read the eeprom */
diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c
index 10472e6dd002..70ad497dd20b 100644
--- a/drivers/staging/comedi/drivers/pcmmio.c
+++ b/drivers/staging/comedi/drivers/pcmmio.c
@@ -84,25 +84,25 @@
84#define PCMMIO_AI_LSB_REG 0x00 84#define PCMMIO_AI_LSB_REG 0x00
85#define PCMMIO_AI_MSB_REG 0x01 85#define PCMMIO_AI_MSB_REG 0x01
86#define PCMMIO_AI_CMD_REG 0x02 86#define PCMMIO_AI_CMD_REG 0x02
87#define PCMMIO_AI_CMD_SE (1 << 7) 87#define PCMMIO_AI_CMD_SE BIT(7)
88#define PCMMIO_AI_CMD_ODD_CHAN (1 << 6) 88#define PCMMIO_AI_CMD_ODD_CHAN BIT(6)
89#define PCMMIO_AI_CMD_CHAN_SEL(x) (((x) & 0x3) << 4) 89#define PCMMIO_AI_CMD_CHAN_SEL(x) (((x) & 0x3) << 4)
90#define PCMMIO_AI_CMD_RANGE(x) (((x) & 0x3) << 2) 90#define PCMMIO_AI_CMD_RANGE(x) (((x) & 0x3) << 2)
91#define PCMMIO_RESOURCE_REG 0x02 91#define PCMMIO_RESOURCE_REG 0x02
92#define PCMMIO_RESOURCE_IRQ(x) (((x) & 0xf) << 0) 92#define PCMMIO_RESOURCE_IRQ(x) (((x) & 0xf) << 0)
93#define PCMMIO_AI_STATUS_REG 0x03 93#define PCMMIO_AI_STATUS_REG 0x03
94#define PCMMIO_AI_STATUS_DATA_READY (1 << 7) 94#define PCMMIO_AI_STATUS_DATA_READY BIT(7)
95#define PCMMIO_AI_STATUS_DATA_DMA_PEND (1 << 6) 95#define PCMMIO_AI_STATUS_DATA_DMA_PEND BIT(6)
96#define PCMMIO_AI_STATUS_CMD_DMA_PEND (1 << 5) 96#define PCMMIO_AI_STATUS_CMD_DMA_PEND BIT(5)
97#define PCMMIO_AI_STATUS_IRQ_PEND (1 << 4) 97#define PCMMIO_AI_STATUS_IRQ_PEND BIT(4)
98#define PCMMIO_AI_STATUS_DATA_DRQ_ENA (1 << 2) 98#define PCMMIO_AI_STATUS_DATA_DRQ_ENA BIT(2)
99#define PCMMIO_AI_STATUS_REG_SEL (1 << 3) 99#define PCMMIO_AI_STATUS_REG_SEL BIT(3)
100#define PCMMIO_AI_STATUS_CMD_DRQ_ENA (1 << 1) 100#define PCMMIO_AI_STATUS_CMD_DRQ_ENA BIT(1)
101#define PCMMIO_AI_STATUS_IRQ_ENA (1 << 0) 101#define PCMMIO_AI_STATUS_IRQ_ENA BIT(0)
102#define PCMMIO_AI_RES_ENA_REG 0x03 102#define PCMMIO_AI_RES_ENA_REG 0x03
103#define PCMMIO_AI_RES_ENA_CMD_REG_ACCESS (0 << 3) 103#define PCMMIO_AI_RES_ENA_CMD_REG_ACCESS (0 << 3)
104#define PCMMIO_AI_RES_ENA_AI_RES_ACCESS (1 << 3) 104#define PCMMIO_AI_RES_ENA_AI_RES_ACCESS BIT(3)
105#define PCMMIO_AI_RES_ENA_DIO_RES_ACCESS (1 << 4) 105#define PCMMIO_AI_RES_ENA_DIO_RES_ACCESS BIT(4)
106#define PCMMIO_AI_2ND_ADC_OFFSET 0x04 106#define PCMMIO_AI_2ND_ADC_OFFSET 0x04
107 107
108#define PCMMIO_AO_LSB_REG 0x08 108#define PCMMIO_AO_LSB_REG 0x08
@@ -125,14 +125,14 @@
125#define PCMMIO_AO_CMD_CHAN_SEL(x) (((x) & 0x03) << 1) 125#define PCMMIO_AO_CMD_CHAN_SEL(x) (((x) & 0x03) << 1)
126#define PCMMIO_AO_CMD_CHAN_SEL_ALL (0x0f << 0) 126#define PCMMIO_AO_CMD_CHAN_SEL_ALL (0x0f << 0)
127#define PCMMIO_AO_STATUS_REG 0x0b 127#define PCMMIO_AO_STATUS_REG 0x0b
128#define PCMMIO_AO_STATUS_DATA_READY (1 << 7) 128#define PCMMIO_AO_STATUS_DATA_READY BIT(7)
129#define PCMMIO_AO_STATUS_DATA_DMA_PEND (1 << 6) 129#define PCMMIO_AO_STATUS_DATA_DMA_PEND BIT(6)
130#define PCMMIO_AO_STATUS_CMD_DMA_PEND (1 << 5) 130#define PCMMIO_AO_STATUS_CMD_DMA_PEND BIT(5)
131#define PCMMIO_AO_STATUS_IRQ_PEND (1 << 4) 131#define PCMMIO_AO_STATUS_IRQ_PEND BIT(4)
132#define PCMMIO_AO_STATUS_DATA_DRQ_ENA (1 << 2) 132#define PCMMIO_AO_STATUS_DATA_DRQ_ENA BIT(2)
133#define PCMMIO_AO_STATUS_REG_SEL (1 << 3) 133#define PCMMIO_AO_STATUS_REG_SEL BIT(3)
134#define PCMMIO_AO_STATUS_CMD_DRQ_ENA (1 << 1) 134#define PCMMIO_AO_STATUS_CMD_DRQ_ENA BIT(1)
135#define PCMMIO_AO_STATUS_IRQ_ENA (1 << 0) 135#define PCMMIO_AO_STATUS_IRQ_ENA BIT(0)
136#define PCMMIO_AO_RESOURCE_ENA_REG 0x0b 136#define PCMMIO_AO_RESOURCE_ENA_REG 0x0b
137#define PCMMIO_AO_2ND_DAC_OFFSET 0x04 137#define PCMMIO_AO_2ND_DAC_OFFSET 0x04
138 138
diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c
index 7ea813022ff6..8ad64f2625fe 100644
--- a/drivers/staging/comedi/drivers/pcmuio.c
+++ b/drivers/staging/comedi/drivers/pcmuio.c
@@ -307,7 +307,7 @@ static void pcmuio_stop_intr(struct comedi_device *dev,
307 307
308static void pcmuio_handle_intr_subdev(struct comedi_device *dev, 308static void pcmuio_handle_intr_subdev(struct comedi_device *dev,
309 struct comedi_subdevice *s, 309 struct comedi_subdevice *s,
310 unsigned triggered) 310 unsigned int triggered)
311{ 311{
312 struct pcmuio_private *devpriv = dev->private; 312 struct pcmuio_private *devpriv = dev->private;
313 int asic = pcmuio_subdevice_to_asic(s); 313 int asic = pcmuio_subdevice_to_asic(s);
diff --git a/drivers/staging/comedi/drivers/plx9080.h b/drivers/staging/comedi/drivers/plx9080.h
index 8d1aee00b19f..0e20cc5c9a69 100644
--- a/drivers/staging/comedi/drivers/plx9080.h
+++ b/drivers/staging/comedi/drivers/plx9080.h
@@ -3,15 +3,6 @@
3 * 3 *
4 * Copyright (C) 2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net> 4 * Copyright (C) 2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
5 * 5 *
6 * I modified this file from the plx9060.h header for the
7 * wanXL device driver in the linux kernel,
8 * for the register offsets and bit definitions. Made minor modifications,
9 * added plx9080 registers and
10 * stripped out stuff that was specifically for the wanXL driver.
11 * Note: I've only made sure the definitions are correct as far
12 * as I make use of them. There are still various plx9060-isms
13 * left in this header file.
14 *
15 ******************************************************************** 6 ********************************************************************
16 * 7 *
17 * Copyright (C) 1999 RG Studio s.c. 8 * Copyright (C) 1999 RG Studio s.c.
@@ -28,392 +19,611 @@
28#ifndef __COMEDI_PLX9080_H 19#ifndef __COMEDI_PLX9080_H
29#define __COMEDI_PLX9080_H 20#define __COMEDI_PLX9080_H
30 21
31/* descriptor block used for chained dma transfers */ 22#include <linux/compiler.h>
23#include <linux/types.h>
24#include <linux/bitops.h>
25#include <linux/delay.h>
26#include <linux/errno.h>
27#include <linux/io.h>
28
29/**
30 * struct plx_dma_desc - DMA descriptor format for PLX PCI 9080
31 * @pci_start_addr: PCI Bus address for transfer (DMAPADR).
32 * @local_start_addr: Local Bus address for transfer (DMALADR).
33 * @transfer_size: Transfer size in bytes (max 8 MiB) (DMASIZ).
34 * @next: Address of next descriptor + flags (DMADPR).
35 *
36 * Describes the format of a scatter-gather DMA descriptor for the PLX
37 * PCI 9080. All members are raw, little-endian register values that
38 * will be transferred by the DMA engine from local or PCI memory into
39 * corresponding registers for the DMA channel.
40 *
41 * The DMA descriptors must be aligned on a 16-byte boundary. Bits 3:0
42 * of @next contain flags describing the address space of the next
43 * descriptor (local or PCI), an "end of chain" marker, an "interrupt on
44 * terminal count" bit, and a data transfer direction.
45 */
32struct plx_dma_desc { 46struct plx_dma_desc {
33 __le32 pci_start_addr; 47 __le32 pci_start_addr;
34 __le32 local_start_addr; 48 __le32 local_start_addr;
35 /* transfer_size is in bytes, only first 23 bits of register are used */
36 __le32 transfer_size; 49 __le32 transfer_size;
37 /*
38 * address of next descriptor (quad word aligned), plus some
39 * additional bits (see PLX_DMA0_DESCRIPTOR_REG)
40 */
41 __le32 next; 50 __le32 next;
42}; 51};
43 52
44/**********************************************************************
45** Register Offsets and Bit Definitions
46**
47** Note: All offsets zero relative. IE. Some standard base address
48** must be added to the Register Number to properly access the register.
49**
50**********************************************************************/
51
52/* L, Local Addr Space 0 Range Register */
53#define PLX_LAS0RNG_REG 0x0000
54/* L, Local Addr Space 1 Range Register */
55#define PLX_LAS1RNG_REG 0x00f0
56#define LRNG_IO 0x00000001 /* Map to: 1=I/O, 0=Mem */
57#define LRNG_ANY32 0x00000000 /* Locate anywhere in 32 bit */
58#define LRNG_LT1MB 0x00000002 /* Locate in 1st meg */
59#define LRNG_ANY64 0x00000004 /* Locate anywhere in 64 bit */
60/* bits that specify range for memory io */
61#define LRNG_MEM_MASK 0xfffffff0
62/* bits that specify range for normal io */
63#define LRNG_IO_MASK 0xfffffffa
64/* L, Local Addr Space 0 Remap Register */
65#define PLX_LAS0MAP_REG 0x0004
66/* L, Local Addr Space 1 Remap Register */
67#define PLX_LAS1MAP_REG 0x00f4
68#define LMAP_EN 0x00000001 /* Enable slave decode */
69/* bits that specify decode for memory io */
70#define LMAP_MEM_MASK 0xfffffff0
71/* bits that specify decode bits for normal io */
72#define LMAP_IO_MASK 0xfffffffa
73
74/* 53/*
75 * Mode/Arbitration Register. 54 * Register Offsets and Bit Definitions
76 */ 55 */
77#define PLX_MARB_REG 0x8 /* L, Local Arbitration Register */
78#define PLX_DMAARB_REG 0xac
79enum marb_bits {
80 MARB_LLT_MASK = 0x000000ff, /* Local Bus Latency Timer */
81 MARB_LPT_MASK = 0x0000ff00, /* Local Bus Pause Timer */
82 MARB_LTEN = 0x00010000, /* Latency Timer Enable */
83 MARB_LPEN = 0x00020000, /* Pause Timer Enable */
84 MARB_BREQ = 0x00040000, /* Local Bus BREQ Enable */
85 MARB_DMA_PRIORITY_MASK = 0x00180000,
86 /* local bus direct slave give up bus mode */
87 MARB_LBDS_GIVE_UP_BUS_MODE = 0x00200000,
88 /* direct slave LLOCKo# enable */
89 MARB_DS_LLOCK_ENABLE = 0x00400000,
90 MARB_PCI_REQUEST_MODE = 0x00800000,
91 MARB_PCIV21_MODE = 0x01000000, /* pci specification v2.1 mode */
92 MARB_PCI_READ_NO_WRITE_MODE = 0x02000000,
93 MARB_PCI_READ_WITH_WRITE_FLUSH_MODE = 0x04000000,
94 /* gate local bus latency timer with BREQ */
95 MARB_GATE_TIMER_WITH_BREQ = 0x08000000,
96 MARB_PCI_READ_NO_FLUSH_MODE = 0x10000000,
97 MARB_USE_SUBSYSTEM_IDS = 0x20000000,
98};
99
100#define PLX_BIGEND_REG 0xc
101enum bigend_bits {
102 /* use big endian ordering for configuration register accesses */
103 BIGEND_CONFIG = 0x1,
104 BIGEND_DIRECT_MASTER = 0x2,
105 BIGEND_DIRECT_SLAVE_LOCAL0 = 0x4,
106 BIGEND_ROM = 0x8,
107 /*
108 * use byte lane consisting of most significant bits instead of
109 * least significant
110 */
111 BIGEND_BYTE_LANE = 0x10,
112 BIGEND_DIRECT_SLAVE_LOCAL1 = 0x20,
113 BIGEND_DMA1 = 0x40,
114 BIGEND_DMA0 = 0x80,
115};
116 56
57/* Local Address Space 0 Range Register */
58#define PLX_REG_LAS0RR 0x0000
59/* Local Address Space 1 Range Register */
60#define PLX_REG_LAS1RR 0x00f0
61
62#define PLX_LASRR_IO BIT(0) /* Map to: 1=I/O, 0=Mem */
63#define PLX_LASRR_ANY32 (BIT(1) * 0) /* Locate anywhere in 32 bit */
64#define PLX_LASRR_LT1MB (BIT(1) * 1) /* Locate in 1st meg */
65#define PLX_LASRR_ANY64 (BIT(1) * 2) /* Locate anywhere in 64 bit */
66#define PLX_LASRR_MLOC_MASK GENMASK(2, 1) /* Memory location bits */
67#define PLX_LASRR_PREFETCH BIT(3) /* Memory is prefetchable */
68/* bits that specify range for memory space decode bits */
69#define PLX_LASRR_MEM_MASK GENMASK(31, 4)
70/* bits that specify range for i/o space decode bits */
71#define PLX_LASRR_IO_MASK GENMASK(31, 2)
72
73/* Local Address Space 0 Local Base Address (Remap) Register */
74#define PLX_REG_LAS0BA 0x0004
75/* Local Address Space 1 Local Base Address (Remap) Register */
76#define PLX_REG_LAS1BA 0x00f4
77
78#define PLX_LASBA_EN BIT(0) /* Enable slave decode */
79/* bits that specify local base address for memory space */
80#define PLX_LASBA_MEM_MASK GENMASK(31, 4)
81/* bits that specify local base address for i/o space */
82#define PLX_LASBA_IO_MASK GENMASK(31, 2)
83
84/* Mode/Arbitration Register */
85#define PLX_REG_MARBR 0x0008
86/* DMA Arbitration Register (alias of MARBR). */
87#define PLX_REG_DMAARB 0x00ac
88
89/* Local Bus Latency Timer */
90#define PLX_MARBR_LT(x) (BIT(0) * ((x) & 0xff))
91#define PLX_MARBR_LT_MASK GENMASK(7, 0)
92#define PLX_MARBR_LT_SHIFT 0
93/* Local Bus Pause Timer */
94#define PLX_MARBR_PT(x) (BIT(8) * ((x) & 0xff))
95#define PLX_MARBR_PT_MASK GENMASK(15, 8)
96#define PLX_MARBR_PT_SHIFT 8
97/* Local Bus Latency Timer Enable */
98#define PLX_MARBR_LTEN BIT(16)
99/* Local Bus Pause Timer Enable */
100#define PLX_MARBR_PTEN BIT(17)
101/* Local Bus BREQ Enable */
102#define PLX_MARBR_BREQEN BIT(18)
103/* DMA Channel Priority */
104#define PLX_MARBR_PRIO_ROT (BIT(19) * 0) /* Rotational priority */
105#define PLX_MARBR_PRIO_DMA0 (BIT(19) * 1) /* DMA channel 0 has priority */
106#define PLX_MARBR_PRIO_DMA1 (BIT(19) * 2) /* DMA channel 1 has priority */
107#define PLX_MARBR_PRIO_MASK GENMASK(20, 19)
108/* Local Bus Direct Slave Give Up Bus Mode */
109#define PLX_MARBR_DSGUBM BIT(21)
110/* Direct Slace LLOCKo# Enable */
111#define PLX_MARBR_DSLLOCKOEN BIT(22)
112/* PCI Request Mode */
113#define PLX_MARBR_PCIREQM BIT(23)
114/* PCI Specification v2.1 Mode */
115#define PLX_MARBR_PCIV21M BIT(24)
116/* PCI Read No Write Mode */
117#define PLX_MARBR_PCIRNWM BIT(25)
118/* PCI Read with Write Flush Mode */
119#define PLX_MARBR_PCIRWFM BIT(26)
120/* Gate Local Bus Latency Timer with BREQ */
121#define PLX_MARBR_GLTBREQ BIT(27)
122/* PCI Read No Flush Mode */
123#define PLX_MARBR_PCIRNFM BIT(28)
117/* 124/*
118** Note: The Expansion ROM stuff is only relevant to the PC environment. 125 * Make reads from PCI Configuration register 0 return Subsystem ID and
119** This expansion ROM code is executed by the host CPU at boot time. 126 * Subsystem Vendor ID instead of Device ID and Vendor ID
120** For this reason no bit definitions are provided here.
121 */ 127 */
122#define PLX_ROMRNG_REG 0x0010 /* L, Expn ROM Space Range Register */ 128#define PLX_MARBR_SUBSYSIDS BIT(29)
123/* L, Local Addr Space Range Register */ 129
124#define PLX_ROMMAP_REG 0x0014 130/* Big/Little Endian Descriptor Register */
125 131#define PLX_REG_BIGEND 0x000c
126#define PLX_REGION0_REG 0x0018 /* L, Local Bus Region 0 Descriptor */ 132
127#define RGN_WIDTH 0x00000002 /* Local bus width bits */ 133/* Configuration Register Big Endian Mode */
128#define RGN_8BITS 0x00000000 /* 08 bit Local Bus */ 134#define PLX_BIGEND_CONFIG BIT(0)
129#define RGN_16BITS 0x00000001 /* 16 bit Local Bus */ 135/* Direct Master Big Endian Mode */
130#define RGN_32BITS 0x00000002 /* 32 bit Local Bus */ 136#define PLX_BIGEND_DM BIT(1)
131#define RGN_MWS 0x0000003C /* Memory Access Wait States */ 137/* Direct Slave Address Space 0 Big Endian Mode */
132#define RGN_0MWS 0x00000000 138#define PLX_BIGEND_DSAS0 BIT(2)
133#define RGN_1MWS 0x00000004 139/* Direct Slave Expansion ROM Big Endian Mode */
134#define RGN_2MWS 0x00000008 140#define PLX_BIGEND_EROM BIT(3)
135#define RGN_3MWS 0x0000000C 141/* Big Endian Byte Lane Mode - use most significant byte lanes */
136#define RGN_4MWS 0x00000010 142#define PLX_BIGEND_BEBLM BIT(4)
137#define RGN_6MWS 0x00000018 143/* Direct Slave Address Space 1 Big Endian Mode */
138#define RGN_8MWS 0x00000020 144#define PLX_BIGEND_DSAS1 BIT(5)
139#define RGN_MRE 0x00000040 /* Memory Space Ready Input Enable */ 145/* DMA Channel 1 Big Endian Mode */
140#define RGN_MBE 0x00000080 /* Memory Space Bterm Input Enable */ 146#define PLX_BIGEND_DMA1 BIT(6)
141#define RGN_READ_PREFETCH_DISABLE 0x00000100 147/* DMA Channel 0 Big Endian Mode */
142#define RGN_ROM_PREFETCH_DISABLE 0x00000200 148#define PLX_BIGEND_DMA0 BIT(7)
143#define RGN_READ_PREFETCH_COUNT_ENABLE 0x00000400 149/* DMA Channel N Big Endian Mode (N <= 1) */
144#define RGN_RWS 0x003C0000 /* Expn ROM Wait States */ 150#define PLX_BIGEND_DMA(n) ((n) ? PLX_BIGEND_DMA1 : PLX_BIGEND_DMA0)
145#define RGN_RRE 0x00400000 /* ROM Space Ready Input Enable */
146#define RGN_RBE 0x00800000 /* ROM Space Bterm Input Enable */
147#define RGN_MBEN 0x01000000 /* Memory Space Burst Enable */
148#define RGN_RBEN 0x04000000 /* ROM Space Burst Enable */
149#define RGN_THROT 0x08000000 /* De-assert TRDY when FIFO full */
150#define RGN_TRD 0xF0000000 /* Target Ready Delay /8 */
151
152#define PLX_REGION1_REG 0x00f8 /* L, Local Bus Region 1 Descriptor */
153
154#define PLX_DMRNG_REG 0x001C /* L, Direct Master Range Register */
155
156#define PLX_LBAPMEM_REG 0x0020 /* L, Lcl Base Addr for PCI mem space */
157
158#define PLX_LBAPIO_REG 0x0024 /* L, Lcl Base Addr for PCI I/O space */
159
160#define PLX_DMMAP_REG 0x0028 /* L, Direct Master Remap Register */
161#define DMM_MAE 0x00000001 /* Direct Mstr Memory Acc Enable */
162#define DMM_IAE 0x00000002 /* Direct Mstr I/O Acc Enable */
163#define DMM_LCK 0x00000004 /* LOCK Input Enable */
164#define DMM_PF4 0x00000008 /* Prefetch 4 Mode Enable */
165#define DMM_THROT 0x00000010 /* Assert IRDY when read FIFO full */
166#define DMM_PAF0 0x00000000 /* Programmable Almost fill level */
167#define DMM_PAF1 0x00000020 /* Programmable Almost fill level */
168#define DMM_PAF2 0x00000040 /* Programmable Almost fill level */
169#define DMM_PAF3 0x00000060 /* Programmable Almost fill level */
170#define DMM_PAF4 0x00000080 /* Programmable Almost fill level */
171#define DMM_PAF5 0x000000A0 /* Programmable Almost fill level */
172#define DMM_PAF6 0x000000C0 /* Programmable Almost fill level */
173#define DMM_PAF7 0x000000D0 /* Programmable Almost fill level */
174#define DMM_MAP 0xFFFF0000 /* Remap Address Bits */
175
176#define PLX_CAR_REG 0x002C /* L, Configuration Address Register */
177#define CAR_CT0 0x00000000 /* Config Type 0 */
178#define CAR_CT1 0x00000001 /* Config Type 1 */
179#define CAR_REG 0x000000FC /* Register Number Bits */
180#define CAR_FUN 0x00000700 /* Function Number Bits */
181#define CAR_DEV 0x0000F800 /* Device Number Bits */
182#define CAR_BUS 0x00FF0000 /* Bus Number Bits */
183#define CAR_CFG 0x80000000 /* Config Spc Access Enable */
184
185#define PLX_DBR_IN_REG 0x0060 /* L, PCI to Local Doorbell Register */
186
187#define PLX_DBR_OUT_REG 0x0064 /* L, Local to PCI Doorbell Register */
188
189#define PLX_INTRCS_REG 0x0068 /* L, Interrupt Control/Status Reg */
190#define ICS_AERR 0x00000001 /* Assert LSERR on ABORT */
191#define ICS_PERR 0x00000002 /* Assert LSERR on Parity Error */
192#define ICS_SERR 0x00000004 /* Generate PCI SERR# */
193#define ICS_MBIE 0x00000008 /* mailbox interrupt enable */
194#define ICS_PIE 0x00000100 /* PCI Interrupt Enable */
195#define ICS_PDIE 0x00000200 /* PCI Doorbell Interrupt Enable */
196#define ICS_PAIE 0x00000400 /* PCI Abort Interrupt Enable */
197#define ICS_PLIE 0x00000800 /* PCI Local Int Enable */
198#define ICS_RAE 0x00001000 /* Retry Abort Enable */
199#define ICS_PDIA 0x00002000 /* PCI Doorbell Interrupt Active */
200#define ICS_PAIA 0x00004000 /* PCI Abort Interrupt Active */
201#define ICS_LIA 0x00008000 /* Local Interrupt Active */
202#define ICS_LIE 0x00010000 /* Local Interrupt Enable */
203#define ICS_LDIE 0x00020000 /* Local Doorbell Int Enable */
204#define ICS_DMA0_E 0x00040000 /* DMA #0 Interrupt Enable */
205#define ICS_DMA1_E 0x00080000 /* DMA #1 Interrupt Enable */
206#define ICS_LDIA 0x00100000 /* Local Doorbell Int Active */
207#define ICS_DMA0_A 0x00200000 /* DMA #0 Interrupt Active */
208#define ICS_DMA1_A 0x00400000 /* DMA #1 Interrupt Active */
209#define ICS_BIA 0x00800000 /* BIST Interrupt Active */
210#define ICS_TA_DM 0x01000000 /* Target Abort - Direct Master */
211#define ICS_TA_DMA0 0x02000000 /* Target Abort - DMA #0 */
212#define ICS_TA_DMA1 0x04000000 /* Target Abort - DMA #1 */
213#define ICS_TA_RA 0x08000000 /* Target Abort - Retry Timeout */
214/* mailbox x is active */
215#define ICS_MBIA(x) (0x10000000 << ((x) & 0x3))
216
217#define PLX_CONTROL_REG 0x006C /* L, EEPROM Cntl & PCI Cmd Codes */
218#define CTL_RDMA 0x0000000E /* DMA Read Command */
219#define CTL_WDMA 0x00000070 /* DMA Write Command */
220#define CTL_RMEM 0x00000600 /* Memory Read Command */
221#define CTL_WMEM 0x00007000 /* Memory Write Command */
222#define CTL_USERO 0x00010000 /* USERO output pin control bit */
223#define CTL_USERI 0x00020000 /* USERI input pin bit */
224#define CTL_EE_CLK 0x01000000 /* EEPROM Clock line */
225#define CTL_EE_CS 0x02000000 /* EEPROM Chip Select */
226#define CTL_EE_W 0x04000000 /* EEPROM Write bit */
227#define CTL_EE_R 0x08000000 /* EEPROM Read bit */
228#define CTL_EECHK 0x10000000 /* EEPROM Present bit */
229#define CTL_EERLD 0x20000000 /* EEPROM Reload Register */
230#define CTL_RESET 0x40000000 /* !! Adapter Reset !! */
231#define CTL_READY 0x80000000 /* Local Init Done */
232
233#define PLX_ID_REG 0x70 /* hard-coded plx vendor and device ids */
234
235#define PLX_REVISION_REG 0x74 /* silicon revision */
236
237#define PLX_DMA0_MODE_REG 0x80 /* dma channel 0 mode register */
238#define PLX_DMA1_MODE_REG 0x94 /* dma channel 0 mode register */
239#define PLX_LOCAL_BUS_16_WIDE_BITS 0x1
240#define PLX_LOCAL_BUS_32_WIDE_BITS 0x3
241#define PLX_LOCAL_BUS_WIDTH_MASK 0x3
242#define PLX_DMA_EN_READYIN_BIT 0x40 /* enable ready in input */
243#define PLX_EN_BTERM_BIT 0x80 /* enable BTERM# input */
244#define PLX_DMA_LOCAL_BURST_EN_BIT 0x100 /* enable local burst mode */
245#define PLX_EN_CHAIN_BIT 0x200 /* enables chaining */
246/* enables interrupt on dma done */
247#define PLX_EN_DMA_DONE_INTR_BIT 0x400
248/* hold local address constant (don't increment) */
249#define PLX_LOCAL_ADDR_CONST_BIT 0x800
250/* enables demand-mode for dma transfer */
251#define PLX_DEMAND_MODE_BIT 0x1000
252#define PLX_EOT_ENABLE_BIT 0x4000
253#define PLX_STOP_MODE_BIT 0x8000
254/* routes dma interrupt to pci bus (instead of local bus) */
255#define PLX_DMA_INTR_PCI_BIT 0x20000
256
257/* pci address that dma transfers start at */
258#define PLX_DMA0_PCI_ADDRESS_REG 0x84
259#define PLX_DMA1_PCI_ADDRESS_REG 0x98
260
261/* local address that dma transfers start at */
262#define PLX_DMA0_LOCAL_ADDRESS_REG 0x88
263#define PLX_DMA1_LOCAL_ADDRESS_REG 0x9c
264
265/* number of bytes to transfer (first 23 bits) */
266#define PLX_DMA0_TRANSFER_SIZE_REG 0x8c
267#define PLX_DMA1_TRANSFER_SIZE_REG 0xa0
268
269#define PLX_DMA0_DESCRIPTOR_REG 0x90 /* descriptor pointer register */
270#define PLX_DMA1_DESCRIPTOR_REG 0xa4
271/* descriptor is located in pci space (not local space) */
272#define PLX_DESC_IN_PCI_BIT 0x1
273#define PLX_END_OF_CHAIN_BIT 0x2 /* end of chain bit */
274/* interrupt when this descriptor's transfer is finished */
275#define PLX_INTR_TERM_COUNT 0x4
276/* transfer from local to pci bus (not pci to local) */
277#define PLX_XFER_LOCAL_TO_PCI 0x8
278
279#define PLX_DMA0_CS_REG 0xa8 /* command status register */
280#define PLX_DMA1_CS_REG 0xa9
281#define PLX_DMA_EN_BIT 0x1 /* enable dma channel */
282#define PLX_DMA_START_BIT 0x2 /* start dma transfer */
283#define PLX_DMA_ABORT_BIT 0x4 /* abort dma transfer */
284#define PLX_CLEAR_DMA_INTR_BIT 0x8 /* clear dma interrupt */
285#define PLX_DMA_DONE_BIT 0x10 /* transfer done status bit */
286
287#define PLX_DMA0_THRESHOLD_REG 0xb0 /* command status register */
288 151
289/* 152/*
290 * Accesses near the end of memory can cause the PLX chip 153 * Note: The Expansion ROM stuff is only relevant to the PC environment.
291 * to pre-fetch data off of end-of-ram. Limit the size of 154 * This expansion ROM code is executed by the host CPU at boot time.
292 * memory so host-side accesses cannot occur. 155 * For this reason no bit definitions are provided here.
293 */ 156 */
294 157
295#define PLX_PREFETCH 32 158/* Expansion ROM Range Register */
159#define PLX_REG_EROMRR 0x0010
160/* Expansion ROM Local Base Address (Remap) Register */
161#define PLX_REG_EROMBA 0x0014
162
163/* Local Address Space 0/Expansion ROM Bus Region Descriptor Register */
164#define PLX_REG_LBRD0 0x0018
165/* Local Address Space 1 Bus Region Descriptor Register */
166#define PLX_REG_LBRD1 0x00f8
167
168/* Memory Space Local Bus Width */
169#define PLX_LBRD_MSWIDTH8 (BIT(0) * 0) /* 8 bits wide */
170#define PLX_LBRD_MSWIDTH16 (BIT(0) * 1) /* 16 bits wide */
171#define PLX_LBRD_MSWIDTH32 (BIT(0) * 2) /* 32 bits wide */
172#define PLX_LBRD_MSWIDTH32A (BIT(0) * 3) /* 32 bits wide */
173#define PLX_LBRD_MSWIDTH_MASK GENMASK(1, 0)
174#define PLX_LBRD_MSWIDTH_SHIFT 0
175/* Memory Space Internal Wait States */
176#define PLX_LBRD_MSIWS(x) (BIT(2) * ((x) & 0xf))
177#define PLX_LBRD_MSIWS_MASK GENMASK(5, 2)
178#define PLX_LBRD_MSIWS_SHIFT 2
179/* Memory Space Ready Input Enable */
180#define PLX_LBRD_MSREADYIEN BIT(6)
181/* Memory Space BTERM# Input Enable */
182#define PLX_LBRD_MSBTERMIEN BIT(7)
183/* Memory Space 0 Prefetch Disable (LBRD0 only) */
184#define PLX_LBRD0_MSPREDIS BIT(8)
185/* Memory Space 1 Burst Enable (LBRD1 only) */
186#define PLX_LBRD1_MSBURSTEN BIT(8)
187/* Expansion ROM Space Prefetch Disable (LBRD0 only) */
188#define PLX_LBRD0_EROMPREDIS BIT(9)
189/* Memory Space 1 Prefetch Disable (LBRD1 only) */
190#define PLX_LBRD1_MSPREDIS BIT(9)
191/* Read Prefetch Count Enable */
192#define PLX_LBRD_RPFCOUNTEN BIT(10)
193/* Prefetch Counter */
194#define PLX_LBRD_PFCOUNT(x) (BIT(11) * ((x) & 0xf))
195#define PLX_LBRD_PFCOUNT_MASK GENMASK(14, 11)
196#define PLX_LBRD_PFCOUNT_SHIFT 11
197/* Expansion ROM Space Local Bus Width (LBRD0 only) */
198#define PLX_LBRD0_EROMWIDTH8 (BIT(16) * 0) /* 8 bits wide */
199#define PLX_LBRD0_EROMWIDTH16 (BIT(16) * 1) /* 16 bits wide */
200#define PLX_LBRD0_EROMWIDTH32 (BIT(16) * 2) /* 32 bits wide */
201#define PLX_LBRD0_EROMWIDTH32A (BIT(16) * 3) /* 32 bits wide */
202#define PLX_LBRD0_EROMWIDTH_MASK GENMASK(17, 16)
203#define PLX_LBRD0_EROMWIDTH_SHIFT 16
204/* Expansion ROM Space Internal Wait States (LBRD0 only) */
205#define PLX_LBRD0_EROMIWS(x) (BIT(18) * ((x) & 0xf))
206#define PLX_LBRD0_EROMIWS_MASK GENMASK(21, 18)
207#define PLX_LBRD0_EROMIWS_SHIFT 18
208/* Expansion ROM Space Ready Input Enable (LBDR0 only) */
209#define PLX_LBRD0_EROMREADYIEN BIT(22)
210/* Expansion ROM Space BTERM# Input Enable (LBRD0 only) */
211#define PLX_LBRD0_EROMBTERMIEN BIT(23)
212/* Memory Space 0 Burst Enable (LBRD0 only) */
213#define PLX_LBRD0_MSBURSTEN BIT(24)
214/* Extra Long Load From Serial EEPROM (LBRD0 only) */
215#define PLX_LBRD0_EELONGLOAD BIT(25)
216/* Expansion ROM Space Burst Enable (LBRD0 only) */
217#define PLX_LBRD0_EROMBURSTEN BIT(26)
218/* Direct Slave PCI Write Mode - assert TRDY# when FIFO full (LBRD0 only) */
219#define PLX_LBRD0_DSWMTRDY BIT(27)
220/* PCI Target Retry Delay Clocks / 8 (LBRD0 only) */
221#define PLX_LBRD0_TRDELAY(x) (BIT(28) * ((x) & 0xF))
222#define PLX_LBRD0_TRDELAY_MASK GENMASK(31, 28)
223#define PLX_LBRD0_TRDELAY_SHIFT 28
224
225/* Local Range Register for Direct Master to PCI */
226#define PLX_REG_DMRR 0x001c
227
228/* Local Bus Base Address Register for Direct Master to PCI Memory */
229#define PLX_REG_DMLBAM 0x0020
230
231/* Local Base Address Register for Direct Master to PCI IO/CFG */
232#define PLX_REG_DMLBAI 0x0024
233
234/* PCI Base Address (Remap) Register for Direct Master to PCI Memory */
235#define PLX_REG_DMPBAM 0x0028
236
237/* Direct Master Memory Access Enable */
238#define PLX_DMPBAM_MEMACCEN BIT(0)
239/* Direct Master I/O Access Enable */
240#define PLX_DMPBAM_IOACCEN BIT(1)
241/* LLOCK# Input Enable */
242#define PLX_DMPBAM_LLOCKIEN BIT(2)
243/* Direct Master Read Prefetch Size Control (bits 12, 3) */
244#define PLX_DMPBAM_RPSIZECONT ((BIT(12) * 0) | (BIT(3) * 0))
245#define PLX_DMPBAM_RPSIZE4 ((BIT(12) * 0) | (BIT(3) * 1))
246#define PLX_DMPBAM_RPSIZE8 ((BIT(12) * 1) | (BIT(3) * 0))
247#define PLX_DMPBAM_RPSIZE16 ((BIT(12) * 1) | (BIT(3) * 1))
248#define PLX_DMPBAM_RPSIZE_MASK (BIT(12) | BIT(3))
249/* Direct Master PCI Read Mode - deassert IRDY when FIFO full */
250#define PLX_DMPBAM_RMIRDY BIT(4)
251/* Programmable Almost Full Level (bits 10, 8:5) */
252#define PLX_DMPBAM_PAFL(x) ((BIT(10) * !!((x) & 0x10)) | \
253 (BIT(5) * ((x) & 0xf)))
254#define PLX_DMPBAM_TO_PAFL(v) ((((BIT(10) & (v)) >> 1) | \
255 (GENMASK(8, 5) & (v))) >> 5)
256#define PLX_DMPBAM_PAFL_MASK (BIT(10) | GENMASK(8, 5))
257/* Write And Invalidate Mode */
258#define PLX_DMPBAM_WIM BIT(9)
259/* Direct Master Prefetch Limit */
260#define PLX_DBPBAM_PFLIMIT BIT(11)
261/* I/O Remap Select */
262#define PLX_DMPBAM_IOREMAPSEL BIT(13)
263/* Direct Master Write Delay */
264#define PLX_DMPBAM_WDELAYNONE (BIT(14) * 0)
265#define PLX_DMPBAM_WDELAY4 (BIT(14) * 1)
266#define PLX_DMPBAM_WDELAY8 (BIT(14) * 2)
267#define PLX_DMPBAM_WDELAY16 (BIT(14) * 3)
268#define PLX_DMPBAM_WDELAY_MASK GENMASK(15, 14)
269/* Remap of Local-to-PCI Space Into PCI Address Space */
270#define PLX_DMPBAM_REMAP_MASK GENMASK(31, 16)
271
272/* PCI Configuration Address Register for Direct Master to PCI IO/CFG */
273#define PLX_REG_DMCFGA 0x002c
274
275/* Congiguration Type */
276#define PLX_DMCFGA_TYPE0 (BIT(0) * 0)
277#define PLX_DMCFGA_TYPE1 (BIT(0) * 1)
278#define PLX_DMCFGA_TYPE_MASK GENMASK(1, 0)
279/* Register Number */
280#define PLX_DMCFGA_REGNUM(x) (BIT(2) * ((x) & 0x3f))
281#define PLX_DMCFGA_REGNUM_MASK GENMASK(7, 2)
282#define PLX_DMCFGA_REGNUM_SHIFT 2
283/* Function Number */
284#define PLX_DMCFGA_FUNCNUM(x) (BIT(8) * ((x) & 0x7))
285#define PLX_DMCFGA_FUNCNUM_MASK GENMASK(10, 8)
286#define PLX_DMCFGA_FUNCNUM_SHIFT 8
287/* Device Number */
288#define PLX_DMCFGA_DEVNUM(x) (BIT(11) * ((x) & 0x1f))
289#define PLX_DMCFGA_DEVNUM_MASK GENMASK(15, 11)
290#define PLX_DMCFGA_DEVNUM_SHIFT 11
291/* Bus Number */
292#define PLX_DMCFGA_BUSNUM(x) (BIT(16) * ((x) & 0xff))
293#define PLX_DMCFGA_BUSNUM_MASK GENMASK(23, 16)
294#define PLX_DMCFGA_BUSNUM_SHIFT 16
295/* Configuration Enable */
296#define PLX_DMCFGA_CONFIGEN BIT(31)
296 297
297/* 298/*
298 * The PCI Interface, via the PCI-9060 Chip, has up to eight (8) Mailbox 299 * Mailbox Register N (N <= 7)
299 * Registers. The PUTS (Power-Up Test Suite) handles the board-side 300 *
300 * interface/interaction using the first 4 registers. Specifications for 301 * Note that if the I2O feature is enabled (QSR[0] is set), Mailbox Register 0
301 * the use of the full PUTS' command and status interface is contained 302 * is replaced by the Inbound Queue Port, and Mailbox Register 1 is replaced
302 * within a separate SBE PUTS Manual. The Host-Side Device Driver only 303 * by the Outbound Queue Port. However, Mailbox Register 0 and 1 are always
303 * uses a subset of the full PUTS interface. 304 * accessible at alternative offsets if the I2O feature is enabled.
304 */ 305 */
306#define PLX_REG_MBOX(n) (0x0040 + (n) * 4)
307#define PLX_REG_MBOX0 PLX_REG_MBOX(0)
308#define PLX_REG_MBOX1 PLX_REG_MBOX(1)
309#define PLX_REG_MBOX2 PLX_REG_MBOX(2)
310#define PLX_REG_MBOX3 PLX_REG_MBOX(3)
311#define PLX_REG_MBOX4 PLX_REG_MBOX(4)
312#define PLX_REG_MBOX5 PLX_REG_MBOX(5)
313#define PLX_REG_MBOX6 PLX_REG_MBOX(6)
314#define PLX_REG_MBOX7 PLX_REG_MBOX(7)
315
316/* Alternative offsets for Mailbox Registers 0 and 1 (in case I2O is enabled) */
317#define PLX_REG_ALT_MBOX(n) ((n) < 2 ? 0x0078 + (n) * 4 : PLX_REG_MBOX(n))
318#define PLX_REG_ALT_MBOX0 PLX_REG_ALT_MBOX(0)
319#define PLX_REG_ALT_MBOX1 PLX_REG_ALT_MBOX(1)
320
321/* PCI-to-Local Doorbell Register */
322#define PLX_REG_P2LDBELL 0x0060
323
324/* Local-to-PCI Doorbell Register */
325#define PLX_REG_L2PDBELL 0x0064
326
327/* Interrupt Control/Status Register */
328#define PLX_REG_INTCSR 0x0068
329
330/* Enable Local Bus LSERR# when PCI Bus Target Abort or Master Abort occurs */
331#define PLX_INTCSR_LSEABORTEN BIT(0)
332/* Enable Local Bus LSERR# when PCI parity error occurs */
333#define PLX_INTCSR_LSEPARITYEN BIT(1)
334/* Generate PCI Bus SERR# when set to 1 */
335#define PLX_INTCSR_GENSERR BIT(2)
336/* Mailbox Interrupt Enable (local bus interrupts on PCI write to MBOX0-3) */
337#define PLX_INTCSR_MBIEN BIT(3)
338/* PCI Interrupt Enable */
339#define PLX_INTCSR_PIEN BIT(8)
340/* PCI Doorbell Interrupt Enable */
341#define PLX_INTCSR_PDBIEN BIT(9)
342/* PCI Abort Interrupt Enable */
343#define PLX_INTCSR_PABORTIEN BIT(10)
344/* PCI Local Interrupt Enable */
345#define PLX_INTCSR_PLIEN BIT(11)
346/* Retry Abort Enable (for diagnostic purposes only) */
347#define PLX_INTCSR_RAEN BIT(12)
348/* PCI Doorbell Interrupt Active (read-only) */
349#define PLX_INTCSR_PDBIA BIT(13)
350/* PCI Abort Interrupt Active (read-only) */
351#define PLX_INTCSR_PABORTIA BIT(14)
352/* Local Interrupt (LINTi#) Active (read-only) */
353#define PLX_INTCSR_PLIA BIT(15)
354/* Local Interrupt Output (LINTo#) Enable */
355#define PLX_INTCSR_LIOEN BIT(16)
356/* Local Doorbell Interrupt Enable */
357#define PLX_INTCSR_LDBIEN BIT(17)
358/* DMA Channel 0 Interrupt Enable */
359#define PLX_INTCSR_DMA0IEN BIT(18)
360/* DMA Channel 1 Interrupt Enable */
361#define PLX_INTCSR_DMA1IEN BIT(19)
362/* DMA Channel N Interrupt Enable (N <= 1) */
363#define PLX_INTCSR_DMAIEN(n) ((n) ? PLX_INTCSR_DMA1IEN : PLX_INTCSR_DMA0IEN)
364/* Local Doorbell Interrupt Active (read-only) */
365#define PLX_INTCSR_LDBIA BIT(20)
366/* DMA Channel 0 Interrupt Active (read-only) */
367#define PLX_INTCSR_DMA0IA BIT(21)
368/* DMA Channel 1 Interrupt Active (read-only) */
369#define PLX_INTCSR_DMA1IA BIT(22)
370/* DMA Channel N Interrupt Active (N <= 1) (read-only) */
371#define PLX_INTCSR_DMAIA(n) ((n) ? PLX_INTCSR_DMA1IA : PLX_INTCSR_DMA0IA)
372/* BIST Interrupt Active (read-only) */
373#define PLX_INTCSR_BISTIA BIT(23)
374/* Direct Master Not Bus Master During Master Or Target Abort (read-only) */
375#define PLX_INTCSR_ABNOTDM BIT(24)
376/* DMA Channel 0 Not Bus Master During Master Or Target Abort (read-only) */
377#define PLX_INTCSR_ABNOTDMA0 BIT(25)
378/* DMA Channel 1 Not Bus Master During Master Or Target Abort (read-only) */
379#define PLX_INTCSR_ABNOTDMA1 BIT(26)
380/* DMA Channel N Not Bus Master During Master Or Target Abort (read-only) */
381#define PLX_INTCSR_ABNOTDMA(n) ((n) ? PLX_INTCSR_ABNOTDMA1 \
382 : PLX_INTCSR_ABNOTDMA0)
383/* Target Abort Not Generated After 256 Master Retries (read-only) */
384#define PLX_INTCSR_ABNOTRETRY BIT(27)
385/* PCI Wrote Mailbox 0 (enabled if bit 3 set) (read-only) */
386#define PLX_INTCSR_MB0IA BIT(28)
387/* PCI Wrote Mailbox 1 (enabled if bit 3 set) (read-only) */
388#define PLX_INTCSR_MB1IA BIT(29)
389/* PCI Wrote Mailbox 2 (enabled if bit 3 set) (read-only) */
390#define PLX_INTCSR_MB2IA BIT(30)
391/* PCI Wrote Mailbox 3 (enabled if bit 3 set) (read-only) */
392#define PLX_INTCSR_MB3IA BIT(31)
393/* PCI Wrote Mailbox N (N <= 3) (enabled if bit 3 set) (read-only) */
394#define PLX_INTCSR_MBIA(n) BIT(28 + (n))
305 395
306/*****************************************/
307/*** MAILBOX #(-1) - MEM ACCESS STS ***/
308/*****************************************/
309
310#define MBX_STS_VALID 0x57584744 /* 'WXGD' */
311#define MBX_STS_DILAV 0x44475857 /* swapped = 'DGXW' */
312
313/*****************************************/
314/*** MAILBOX #0 - PUTS STATUS ***/
315/*****************************************/
316
317#define MBX_STS_MASK 0x000000ff /* PUTS Status Register bits */
318#define MBX_STS_TMASK 0x0000000f /* register bits for TEST number */
319
320#define MBX_STS_PCIRESET 0x00000100 /* Host issued PCI reset request */
321#define MBX_STS_BUSY 0x00000080 /* PUTS is in progress */
322#define MBX_STS_ERROR 0x00000040 /* PUTS has failed */
323/* 396/*
324 * Undefined -> status in transition. We are in process of changing bits; 397 * Serial EEPROM Control, PCI Command Codes, User I/O Control,
325 * we SET Error bit before RESET of Busy bit 398 * Init Control Register
326 */ 399 */
327#define MBX_STS_RESERVED 0x000000c0 400#define PLX_REG_CNTRL 0x006c
328 401
329#define MBX_RESERVED_5 0x00000020 /* FYI: reserved/unused bit */ 402/* PCI Read Command Code For DMA */
330#define MBX_RESERVED_4 0x00000010 /* FYI: reserved/unused bit */ 403#define PLX_CNTRL_CCRDMA(x) (BIT(0) * ((x) & 0xf))
331 404#define PLX_CNTRL_CCRDMA_MASK GENMASK(3, 0)
332/******************************************/ 405#define PLX_CNTRL_CCRDMA_SHIFT 0
333/*** MAILBOX #1 - PUTS COMMANDS ***/ 406#define PLX_CNTRL_CCRDMA_NORMAL PLX_CNTRL_CCRDMA(14) /* value after reset */
334/******************************************/ 407/* PCI Write Command Code For DMA 0 */
335 408#define PLX_CNTRL_CCWDMA(x) (BIT(4) * ((x) & 0xf))
409#define PLX_CNTRL_CCWDMA_MASK GENMASK(7, 4)
410#define PLX_CNTRL_CCWDMA_SHIFT 4
411#define PLX_CNTRL_CCWDMA_NORMAL PLX_CNTRL_CCWDMA(7) /* value after reset */
412/* PCI Memory Read Command Code For Direct Master */
413#define PLX_CNTRL_CCRDM(x) (BIT(8) * ((x) & 0xf))
414#define PLX_CNTRL_CCRDM_MASK GENMASK(11, 8)
415#define PLX_CNTRL_CCRDM_SHIFT 8
416#define PLX_CNTRL_CCRDM_NORMAL PLX_CNTRL_CCRDM(6) /* value after reset */
417/* PCI Memory Write Command Code For Direct Master */
418#define PLX_CNTRL_CCWDM(x) (BIT(12) * ((x) & 0xf))
419#define PLX_CNTRL_CCWDM_MASK GENMASK(15, 12)
420#define PLX_CNTRL_CCWDM_SHIFT 12
421#define PLX_CNTRL_CCWDM_NORMAL PLX_CNTRL_CCWDM(7) /* value after reset */
422/* General Purpose Output (USERO) */
423#define PLX_CNTRL_USERO BIT(16)
424/* General Purpose Input (USERI) (read-only) */
425#define PLX_CNTRL_USERI BIT(17)
426/* Serial EEPROM Clock Output (EESK) */
427#define PLX_CNTRL_EESK BIT(24)
428/* Serial EEPROM Chip Select Output (EECS) */
429#define PLX_CNTRL_EECS BIT(25)
430/* Serial EEPROM Data Write Bit (EEDI (sic)) */
431#define PLX_CNTRL_EEWB BIT(26)
432/* Serial EEPROM Data Read Bit (EEDO (sic)) (read-only) */
433#define PLX_CNTRL_EERB BIT(27)
434/* Serial EEPROM Present (read-only) */
435#define PLX_CNTRL_EEPRESENT BIT(28)
436/* Reload Configuration Registers from EEPROM */
437#define PLX_CNTRL_EERELOAD BIT(29)
438/* PCI Adapter Software Reset (asserts LRESETo#) */
439#define PLX_CNTRL_RESET BIT(30)
440/* Local Init Status (read-only) */
441#define PLX_CNTRL_INITDONE BIT(31)
336/* 442/*
337 * Any attempt to execute an unimplement command results in the PUTS 443 * Combined command code stuff for convenience.
338 * interface executing a NOOP and continuing as if the offending command
339 * completed normally. Note: this supplies a simple method to interrogate
340 * mailbox command processing functionality.
341 */ 444 */
445#define PLX_CNTRL_CC_MASK \
446 (PLX_CNTRL_CCRDMA_MASK | PLX_CNTRL_CCWDMA_MASK | \
447 PLX_CNTRL_CCRDM_MASK | PLX_CNTRL_CCWDM_MASK)
448#define PLX_CNTRL_CC_NORMAL \
449 (PLX_CNTRL_CCRDMA_NORMAL | PLX_CNTRL_CCWDMA_NORMAL | \
450 PLX_CNTRL_CCRDM_NORMAL | PLX_CNTRL_CCWDM_NORMAL) /* val after reset */
451
452/* PCI Permanent Configuration ID Register (hard-coded PLX vendor and device) */
453#define PLX_REG_PCIHIDR 0x0070
454
455/* Hard-coded ID for PLX PCI 9080 */
456#define PLX_PCIHIDR_9080 0x908010b5
457
458/* PCI Permanent Revision ID Register (hard-coded silicon revision) (8-bit). */
459#define PLX_REG_PCIHREV 0x0074
460
461/* DMA Channel N Mode Register (N <= 1) */
462#define PLX_REG_DMAMODE(n) ((n) ? PLX_REG_DMAMODE1 : PLX_REG_DMAMODE0)
463#define PLX_REG_DMAMODE0 0x0080
464#define PLX_REG_DMAMODE1 0x0094
465
466/* Local Bus Width */
467#define PLX_DMAMODE_WIDTH8 (BIT(0) * 0) /* 8 bits wide */
468#define PLX_DMAMODE_WIDTH16 (BIT(0) * 1) /* 16 bits wide */
469#define PLX_DMAMODE_WIDTH32 (BIT(0) * 2) /* 32 bits wide */
470#define PLX_DMAMODE_WIDTH32A (BIT(0) * 3) /* 32 bits wide */
471#define PLX_DMAMODE_WIDTH_MASK GENMASK(1, 0)
472#define PLX_DMAMODE_WIDTH_SHIFT 0
473/* Internal Wait States */
474#define PLX_DMAMODE_IWS(x) (BIT(2) * ((x) & 0xf))
475#define PLX_DMAMODE_IWS_MASK GENMASK(5, 2)
476#define PLX_DMAMODE_SHIFT 2
477/* Ready Input Enable */
478#define PLX_DMAMODE_READYIEN BIT(6)
479/* BTERM# Input Enable */
480#define PLX_DMAMODE_BTERMIEN BIT(7)
481/* Local Burst Enable */
482#define PLX_DMAMODE_BURSTEN BIT(8)
483/* Chaining Enable */
484#define PLX_DMAMODE_CHAINEN BIT(9)
485/* Done Interrupt Enable */
486#define PLX_DMAMODE_DONEIEN BIT(10)
487/* Hold Local Address Constant */
488#define PLX_DMAMODE_LACONST BIT(11)
489/* Demand Mode */
490#define PLX_DMAMODE_DEMAND BIT(12)
491/* Write And Invalidate Mode */
492#define PLX_DMAMODE_WINVALIDATE BIT(13)
493/* DMA EOT Enable - enables EOT0# or EOT1# input pin */
494#define PLX_DMAMODE_EOTEN BIT(14)
495/* DMA Stop Data Transfer Mode - 0:BLAST; 1:EOT asserted or DREQ deasserted */
496#define PLX_DMAMODE_STOP BIT(15)
497/* DMA Clear Count Mode - count in descriptor cleared on completion */
498#define PLX_DMAMODE_CLRCOUNT BIT(16)
499/* DMA Channel Interrupt Select - 0:local bus interrupt; 1:PCI interrupt */
500#define PLX_DMAMODE_INTRPCI BIT(17)
501
502/* DMA Channel N PCI Address Register (N <= 1) */
503#define PLX_REG_DMAPADR(n) ((n) ? PLX_REG_DMAPADR1 : PLX_REG_DMAPADR0)
504#define PLX_REG_DMAPADR0 0x0084
505#define PLX_REG_DMAPADR1 0x0098
506
507/* DMA Channel N Local Address Register (N <= 1) */
508#define PLX_REG_DMALADR(n) ((n) ? PLX_REG_DMALADR1 : PLX_REG_DMALADR0)
509#define PLX_REG_DMALADR0 0x0088
510#define PLX_REG_DMALADR1 0x009c
511
512/* DMA Channel N Transfer Size (Bytes) Register (N <= 1) (first 23 bits) */
513#define PLX_REG_DMASIZ(n) ((n) ? PLX_REG_DMASIZ1 : PLX_REG_DMASIZ0)
514#define PLX_REG_DMASIZ0 0x008c
515#define PLX_REG_DMASIZ1 0x00a0
516
517/* DMA Channel N Descriptor Pointer Register (N <= 1) */
518#define PLX_REG_DMADPR(n) ((n) ? PLX_REG_DMADPR1 : PLX_REG_DMADPR0)
519#define PLX_REG_DMADPR0 0x0090
520#define PLX_REG_DMADPR1 0x00a4
521
522/* Descriptor Located In PCI Address Space (not local address space) */
523#define PLX_DMADPR_DESCPCI BIT(0)
524/* End Of Chain */
525#define PLX_DMADPR_CHAINEND BIT(1)
526/* Interrupt After Terminal Count */
527#define PLX_DMADPR_TCINTR BIT(2)
528/* Direction Of Transfer Local Bus To PCI (not PCI to local) */
529#define PLX_DMADPR_XFERL2P BIT(3)
530/* Next Descriptor Address Bits 31:4 (16 byte boundary) */
531#define PLX_DMADPR_NEXT_MASK GENMASK(31, 4)
532
533/* DMA Channel N Command/Status Register (N <= 1) (8-bit) */
534#define PLX_REG_DMACSR(n) ((n) ? PLX_REG_DMACSR1 : PLX_REG_DMACSR0)
535#define PLX_REG_DMACSR0 0x00a8
536#define PLX_REG_DMACSR1 0x00a9
537
538/* Channel Enable */
539#define PLX_DMACSR_ENABLE BIT(0)
540/* Channel Start - write 1 to start transfer (write-only) */
541#define PLX_DMACSR_START BIT(1)
542/* Channel Abort - write 1 to abort transfer (write-only) */
543#define PLX_DMACSR_ABORT BIT(2)
544/* Clear Interrupt - write 1 to clear DMA Channel Interrupt (write-only) */
545#define PLX_DMACSR_CLEARINTR BIT(3)
546/* Channel Done - transfer complete/inactive (read-only) */
547#define PLX_DMACSR_DONE BIT(4)
548
549/* DMA Threshold Register */
550#define PLX_REG_DMATHR 0x00b0
342 551
343#define MBX_CMD_MASK 0xffff0000 /* PUTS Command Register bits */ 552/*
344 553 * DMA Threshold constraints:
345#define MBX_CMD_ABORTJ 0x85000000 /* abort and jump */ 554 * (C0PLAF + 1) + (C0PLAE + 1) <= 32
346#define MBX_CMD_RESETP 0x86000000 /* reset and pause at start */ 555 * (C0LPAF + 1) + (C0LPAE + 1) <= 32
347#define MBX_CMD_PAUSE 0x87000000 /* pause immediately */ 556 * (C1PLAF + 1) + (C1PLAE + 1) <= 16
348#define MBX_CMD_PAUSEC 0x88000000 /* pause on completion */ 557 * (C1LPAF + 1) + (C1LPAE + 1) <= 16
349#define MBX_CMD_RESUME 0x89000000 /* resume operation */ 558 */
350#define MBX_CMD_STEP 0x8a000000 /* single step tests */
351
352#define MBX_CMD_BSWAP 0x8c000000 /* identify byte swap scheme */
353#define MBX_CMD_BSWAP_0 0x8c000000 /* use scheme 0 */
354#define MBX_CMD_BSWAP_1 0x8c000001 /* use scheme 1 */
355
356/* setup host memory access window size */
357#define MBX_CMD_SETHMS 0x8d000000
358/* setup host memory access base address */
359#define MBX_CMD_SETHBA 0x8e000000
360/* perform memory setup and continue (IE. Done) */
361#define MBX_CMD_MGO 0x8f000000
362#define MBX_CMD_NOOP 0xFF000000 /* dummy, illegal command */
363
364/*****************************************/
365/*** MAILBOX #2 - MEMORY SIZE ***/
366/*****************************************/
367
368#define MBX_MEMSZ_MASK 0xffff0000 /* PUTS Memory Size Register bits */
369
370#define MBX_MEMSZ_128KB 0x00020000 /* 128 kilobyte board */
371#define MBX_MEMSZ_256KB 0x00040000 /* 256 kilobyte board */
372#define MBX_MEMSZ_512KB 0x00080000 /* 512 kilobyte board */
373#define MBX_MEMSZ_1MB 0x00100000 /* 1 megabyte board */
374#define MBX_MEMSZ_2MB 0x00200000 /* 2 megabyte board */
375#define MBX_MEMSZ_4MB 0x00400000 /* 4 megabyte board */
376#define MBX_MEMSZ_8MB 0x00800000 /* 8 megabyte board */
377#define MBX_MEMSZ_16MB 0x01000000 /* 16 megabyte board */
378
379/***************************************/
380/*** MAILBOX #2 - BOARD TYPE ***/
381/***************************************/
382
383#define MBX_BTYPE_MASK 0x0000ffff /* PUTS Board Type Register */
384/* PUTS Board Family Register */
385#define MBX_BTYPE_FAMILY_MASK 0x0000ff00
386#define MBX_BTYPE_SUBTYPE_MASK 0x000000ff /* PUTS Board Subtype */
387
388#define MBX_BTYPE_PLX9060 0x00000100 /* PLX family type */
389#define MBX_BTYPE_PLX9080 0x00000300 /* PLX wanXL100s family type */
390
391#define MBX_BTYPE_WANXL_4 0x00000104 /* wanXL400, 4-port */
392#define MBX_BTYPE_WANXL_2 0x00000102 /* wanXL200, 2-port */
393#define MBX_BTYPE_WANXL_1s 0x00000301 /* wanXL100s, 1-port */
394#define MBX_BTYPE_WANXL_1t 0x00000401 /* wanXL100T1, 1-port */
395 559
396/*****************************************/ 560/* DMA Channel 0 PCI-to-Local Almost Full (divided by 2, minus 1) */
397/*** MAILBOX #3 - SHMQ MAILBOX ***/ 561#define PLX_DMATHR_C0PLAF(x) (BIT(0) * ((x) & 0xf))
398/*****************************************/ 562#define PLX_DMATHR_C0PLAF_MASK GENMASK(3, 0)
563#define PLX_DMATHR_C0PLAF_SHIFT 0
564/* DMA Channel 0 Local-to-PCI Almost Empty (divided by 2, minus 1) */
565#define PLX_DMATHR_C0LPAE(x) (BIT(4) * ((x) & 0xf))
566#define PLX_DMATHR_C0LPAE_MASK GENMASK(7, 4)
567#define PLX_DMATHR_C0LPAE_SHIFT 4
568/* DMA Channel 0 Local-to-PCI Almost Full (divided by 2, minus 1) */
569#define PLX_DMATHR_C0LPAF(x) (BIT(8) * ((x) & 0xf))
570#define PLX_DMATHR_C0LPAF_MASK GENMASK(11, 8)
571#define PLX_DMATHR_C0LPAF_SHIFT 8
572/* DMA Channel 0 PCI-to-Local Almost Empty (divided by 2, minus 1) */
573#define PLX_DMATHR_C0PLAE(x) (BIT(12) * ((x) & 0xf))
574#define PLX_DMATHR_C0PLAE_MASK GENMASK(15, 12)
575#define PLX_DMATHR_C0PLAE_SHIFT 12
576/* DMA Channel 1 PCI-to-Local Almost Full (divided by 2, minus 1) */
577#define PLX_DMATHR_C1PLAF(x) (BIT(16) * ((x) & 0xf))
578#define PLX_DMATHR_C1PLAF_MASK GENMASK(19, 16)
579#define PLX_DMATHR_C1PLAF_SHIFT 16
580/* DMA Channel 1 Local-to-PCI Almost Empty (divided by 2, minus 1) */
581#define PLX_DMATHR_C1LPAE(x) (BIT(20) * ((x) & 0xf))
582#define PLX_DMATHR_C1LPAE_MASK GENMASK(23, 20)
583#define PLX_DMATHR_C1LPAE_SHIFT 20
584/* DMA Channel 1 Local-to-PCI Almost Full (divided by 2, minus 1) */
585#define PLX_DMATHR_C1LPAF(x) (BIT(24) * ((x) & 0xf))
586#define PLX_DMATHR_C1LPAF_MASK GENMASK(27, 24)
587#define PLX_DMATHR_C1LPAF_SHIFT 24
588/* DMA Channel 1 PCI-to-Local Almost Empty (divided by 2, minus 1) */
589#define PLX_DMATHR_C1PLAE(x) (BIT(28) * ((x) & 0xf))
590#define PLX_DMATHR_C1PLAE_MASK GENMASK(31, 28)
591#define PLX_DMATHR_C1PLAE_SHIFT 28
399 592
400#define MBX_SMBX_MASK 0x000000ff /* PUTS SHMQ Mailbox bits */ 593/*
594 * Messaging Queue Registers OPLFIS, OPLFIM, IQP, OQP, MQCR, QBAR, IFHPR,
595 * IFTPR, IPHPR, IPTPR, OFHPR, OFTPR, OPHPR, OPTPR, and QSR have been omitted.
596 * They are used by the I2O feature. (IQP and OQP occupy the usual offsets of
597 * the MBOX0 and MBOX1 registers if the I2O feature is enabled, but MBOX0 and
598 * MBOX1 are accessible via alternative offsets.
599 */
401 600
402/***************************************/ 601/* Queue Status/Control Register */
403/*** GENERIC HOST-SIDE DRIVER ***/ 602#define PLX_REG_QSR 0x00e8
404/***************************************/
405 603
406#define MBX_ERR 0 604/* Value of QSR after reset - disables I2O feature completely. */
407#define MBX_OK 1 605#define PLX_QSR_VALUE_AFTER_RESET 0x00000050
408 606
409/* mailbox check routine - type of testing */ 607/*
410#define MBXCHK_STS 0x00 /* check for PUTS status */ 608 * Accesses near the end of memory can cause the PLX chip
411#define MBXCHK_NOWAIT 0x01 /* dont care about PUTS status */ 609 * to pre-fetch data off of end-of-ram. Limit the size of
610 * memory so host-side accesses cannot occur.
611 */
412 612
413/* system allocates this many bytes for address mapping mailbox space */ 613#define PLX_PREFETCH 32
414#define MBX_ADDR_SPACE_360 0x80 /* wanXL100s/200/400 */
415#define MBX_ADDR_MASK_360 (MBX_ADDR_SPACE_360 - 1)
416 614
615/**
616 * plx9080_abort_dma - Abort a PLX PCI 9080 DMA transfer
617 * @iobase: Remapped base address of configuration registers.
618 * @channel: DMA channel number (0 or 1).
619 *
620 * Aborts the DMA transfer on the channel, which must have been enabled
621 * and started beforehand.
622 *
623 * Return:
624 * %0 on success.
625 * -%ETIMEDOUT if timed out waiting for abort to complete.
626 */
417static inline int plx9080_abort_dma(void __iomem *iobase, unsigned int channel) 627static inline int plx9080_abort_dma(void __iomem *iobase, unsigned int channel)
418{ 628{
419 void __iomem *dma_cs_addr; 629 void __iomem *dma_cs_addr;
@@ -421,29 +631,26 @@ static inline int plx9080_abort_dma(void __iomem *iobase, unsigned int channel)
421 const int timeout = 10000; 631 const int timeout = 10000;
422 unsigned int i; 632 unsigned int i;
423 633
424 if (channel) 634 dma_cs_addr = iobase + PLX_REG_DMACSR(channel);
425 dma_cs_addr = iobase + PLX_DMA1_CS_REG;
426 else
427 dma_cs_addr = iobase + PLX_DMA0_CS_REG;
428 635
429 /* abort dma transfer if necessary */ 636 /* abort dma transfer if necessary */
430 dma_status = readb(dma_cs_addr); 637 dma_status = readb(dma_cs_addr);
431 if ((dma_status & PLX_DMA_EN_BIT) == 0) 638 if ((dma_status & PLX_DMACSR_ENABLE) == 0)
432 return 0; 639 return 0;
433 640
434 /* wait to make sure done bit is zero */ 641 /* wait to make sure done bit is zero */
435 for (i = 0; (dma_status & PLX_DMA_DONE_BIT) && i < timeout; i++) { 642 for (i = 0; (dma_status & PLX_DMACSR_DONE) && i < timeout; i++) {
436 udelay(1); 643 udelay(1);
437 dma_status = readb(dma_cs_addr); 644 dma_status = readb(dma_cs_addr);
438 } 645 }
439 if (i == timeout) 646 if (i == timeout)
440 return -ETIMEDOUT; 647 return -ETIMEDOUT;
441 648
442 /* disable and abort channel */ 649 /* disable and abort channel */
443 writeb(PLX_DMA_ABORT_BIT, dma_cs_addr); 650 writeb(PLX_DMACSR_ABORT, dma_cs_addr);
444 /* wait for dma done bit */ 651 /* wait for dma done bit */
445 dma_status = readb(dma_cs_addr); 652 dma_status = readb(dma_cs_addr);
446 for (i = 0; (dma_status & PLX_DMA_DONE_BIT) == 0 && i < timeout; i++) { 653 for (i = 0; (dma_status & PLX_DMACSR_DONE) == 0 && i < timeout; i++) {
447 udelay(1); 654 udelay(1);
448 dma_status = readb(dma_cs_addr); 655 dma_status = readb(dma_cs_addr);
449 } 656 }
diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index e9e43139157d..802f51e46405 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -643,7 +643,7 @@ static int daqp_ao_insn_write(struct comedi_device *dev,
643 outb(0, dev->iobase + DAQP_AUX_REG); 643 outb(0, dev->iobase + DAQP_AUX_REG);
644 644
645 for (i = 0; i > insn->n; i++) { 645 for (i = 0; i > insn->n; i++) {
646 unsigned val = data[i]; 646 unsigned int val = data[i];
647 int ret; 647 int ret;
648 648
649 /* D/A transfer rate is about 8ms */ 649 /* D/A transfer rate is about 8ms */
diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c
index 9b6c56773247..e00e9c6268ae 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -362,7 +362,7 @@ struct rtd_private {
362 long ai_count; /* total transfer size (samples) */ 362 long ai_count; /* total transfer size (samples) */
363 int xfer_count; /* # to transfer data. 0->1/2FIFO */ 363 int xfer_count; /* # to transfer data. 0->1/2FIFO */
364 int flags; /* flag event modes */ 364 int flags; /* flag event modes */
365 unsigned fifosz; 365 unsigned int fifosz;
366 366
367 /* 8254 Timer/Counter gate and clock sources */ 367 /* 8254 Timer/Counter gate and clock sources */
368 unsigned char timer_gate_src[3]; 368 unsigned char timer_gate_src[3];
@@ -491,9 +491,9 @@ static void rtd_load_channelgain_list(struct comedi_device *dev,
491static int rtd520_probe_fifo_depth(struct comedi_device *dev) 491static int rtd520_probe_fifo_depth(struct comedi_device *dev)
492{ 492{
493 unsigned int chanspec = CR_PACK(0, 0, AREF_GROUND); 493 unsigned int chanspec = CR_PACK(0, 0, AREF_GROUND);
494 unsigned i; 494 unsigned int i;
495 static const unsigned limit = 0x2000; 495 static const unsigned int limit = 0x2000;
496 unsigned fifo_size = 0; 496 unsigned int fifo_size = 0;
497 497
498 writel(0, dev->mmio + LAS0_ADC_FIFO_CLEAR); 498 writel(0, dev->mmio + LAS0_ADC_FIFO_CLEAR);
499 rtd_load_channelgain_list(dev, 1, &chanspec); 499 rtd_load_channelgain_list(dev, 1, &chanspec);
@@ -501,7 +501,7 @@ static int rtd520_probe_fifo_depth(struct comedi_device *dev)
501 writel(0, dev->mmio + LAS0_ADC_CONVERSION); 501 writel(0, dev->mmio + LAS0_ADC_CONVERSION);
502 /* convert samples */ 502 /* convert samples */
503 for (i = 0; i < limit; ++i) { 503 for (i = 0; i < limit; ++i) {
504 unsigned fifo_status; 504 unsigned int fifo_status;
505 /* trigger conversion */ 505 /* trigger conversion */
506 writew(0, dev->mmio + LAS0_ADC); 506 writew(0, dev->mmio + LAS0_ADC);
507 usleep_range(1, 1000); 507 usleep_range(1, 1000);
@@ -1175,7 +1175,7 @@ static void rtd_reset(struct comedi_device *dev)
1175 1175
1176 writel(0, dev->mmio + LAS0_BOARD_RESET); 1176 writel(0, dev->mmio + LAS0_BOARD_RESET);
1177 usleep_range(100, 1000); /* needed? */ 1177 usleep_range(100, 1000); /* needed? */
1178 writel(0, devpriv->lcfg + PLX_INTRCS_REG); 1178 writel(0, devpriv->lcfg + PLX_REG_INTCSR);
1179 writew(0, dev->mmio + LAS0_IT); 1179 writew(0, dev->mmio + LAS0_IT);
1180 writew(~0, dev->mmio + LAS0_CLEAR); 1180 writew(~0, dev->mmio + LAS0_CLEAR);
1181 readw(dev->mmio + LAS0_CLEAR); 1181 readw(dev->mmio + LAS0_CLEAR);
@@ -1316,7 +1316,8 @@ static int rtd_auto_attach(struct comedi_device *dev,
1316 devpriv->fifosz = ret; 1316 devpriv->fifosz = ret;
1317 1317
1318 if (dev->irq) 1318 if (dev->irq)
1319 writel(ICS_PIE | ICS_PLIE, devpriv->lcfg + PLX_INTRCS_REG); 1319 writel(PLX_INTCSR_PIEN | PLX_INTCSR_PLIEN,
1320 devpriv->lcfg + PLX_REG_INTCSR);
1320 1321
1321 return 0; 1322 return 0;
1322} 1323}
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index c5e08635e01e..4a87b4b52400 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -708,7 +708,7 @@ static uint16_t s626_get_mode_a(struct comedi_device *dev,
708 uint16_t cra; 708 uint16_t cra;
709 uint16_t crb; 709 uint16_t crb;
710 uint16_t setup; 710 uint16_t setup;
711 unsigned cntsrc, clkmult, clkpol, encmode; 711 unsigned int cntsrc, clkmult, clkpol, encmode;
712 712
713 /* Fetch CRA and CRB register images. */ 713 /* Fetch CRA and CRB register images. */
714 cra = s626_debi_read(dev, S626_LP_CRA(chan)); 714 cra = s626_debi_read(dev, S626_LP_CRA(chan));
@@ -763,7 +763,7 @@ static uint16_t s626_get_mode_b(struct comedi_device *dev,
763 uint16_t cra; 763 uint16_t cra;
764 uint16_t crb; 764 uint16_t crb;
765 uint16_t setup; 765 uint16_t setup;
766 unsigned cntsrc, clkmult, clkpol, encmode; 766 unsigned int cntsrc, clkmult, clkpol, encmode;
767 767
768 /* Fetch CRA and CRB register images. */ 768 /* Fetch CRA and CRB register images. */
769 cra = s626_debi_read(dev, S626_LP_CRA(chan)); 769 cra = s626_debi_read(dev, S626_LP_CRA(chan));
@@ -838,7 +838,7 @@ static void s626_set_mode_a(struct comedi_device *dev,
838 struct s626_private *devpriv = dev->private; 838 struct s626_private *devpriv = dev->private;
839 uint16_t cra; 839 uint16_t cra;
840 uint16_t crb; 840 uint16_t crb;
841 unsigned cntsrc, clkmult, clkpol; 841 unsigned int cntsrc, clkmult, clkpol;
842 842
843 /* Initialize CRA and CRB images. */ 843 /* Initialize CRA and CRB images. */
844 /* Preload trigger is passed through. */ 844 /* Preload trigger is passed through. */
@@ -916,7 +916,7 @@ static void s626_set_mode_b(struct comedi_device *dev,
916 struct s626_private *devpriv = dev->private; 916 struct s626_private *devpriv = dev->private;
917 uint16_t cra; 917 uint16_t cra;
918 uint16_t crb; 918 uint16_t crb;
919 unsigned cntsrc, clkmult, clkpol; 919 unsigned int cntsrc, clkmult, clkpol;
920 920
921 /* Initialize CRA and CRB images. */ 921 /* Initialize CRA and CRB images. */
922 /* IndexSrc is passed through. */ 922 /* IndexSrc is passed through. */
diff --git a/drivers/staging/comedi/drivers/s626.h b/drivers/staging/comedi/drivers/s626.h
index b83424e7507b..6a00a64c6f3a 100644
--- a/drivers/staging/comedi/drivers/s626.h
+++ b/drivers/staging/comedi/drivers/s626.h
@@ -29,8 +29,10 @@
29#define S626_ENCODER_CHANNELS 6 29#define S626_ENCODER_CHANNELS 6
30#define S626_DIO_CHANNELS 48 30#define S626_DIO_CHANNELS 48
31#define S626_DIO_BANKS 3 /* Number of DIO groups. */ 31#define S626_DIO_BANKS 3 /* Number of DIO groups. */
32#define S626_DIO_EXTCHANS 40 /* Number of extended-capability 32#define S626_DIO_EXTCHANS 40 /*
33 * DIO channels. */ 33 * Number of extended-capability
34 * DIO channels.
35 */
34 36
35#define S626_NUM_TRIMDACS 12 /* Number of valid TrimDAC channels. */ 37#define S626_NUM_TRIMDACS 12 /* Number of valid TrimDAC channels. */
36 38
@@ -48,21 +50,29 @@
48#define S626_GSEL_BIPOLAR10V 0x00A0 /* S626_LP_GSEL setting 10V bipolar. */ 50#define S626_GSEL_BIPOLAR10V 0x00A0 /* S626_LP_GSEL setting 10V bipolar. */
49 51
50/* Error codes that must be visible to this base class. */ 52/* Error codes that must be visible to this base class. */
51#define S626_ERR_ILLEGAL_PARM 0x00010000 /* Illegal function parameter 53#define S626_ERR_ILLEGAL_PARM 0x00010000 /*
52 * value was specified. */ 54 * Illegal function parameter
55 * value was specified.
56 */
53#define S626_ERR_I2C 0x00020000 /* I2C error. */ 57#define S626_ERR_I2C 0x00020000 /* I2C error. */
54#define S626_ERR_COUNTERSETUP 0x00200000 /* Illegal setup specified for 58#define S626_ERR_COUNTERSETUP 0x00200000 /*
55 * counter channel. */ 59 * Illegal setup specified for
60 * counter channel.
61 */
56#define S626_ERR_DEBI_TIMEOUT 0x00400000 /* DEBI transfer timed out. */ 62#define S626_ERR_DEBI_TIMEOUT 0x00400000 /* DEBI transfer timed out. */
57 63
58/* 64/*
59 * Organization (physical order) and size (in DWORDs) of logical DMA buffers 65 * Organization (physical order) and size (in DWORDs) of logical DMA buffers
60 * contained by ANA_DMABUF. 66 * contained by ANA_DMABUF.
61 */ 67 */
62#define S626_ADC_DMABUF_DWORDS 40 /* ADC DMA buffer must hold 16 samples, 68#define S626_ADC_DMABUF_DWORDS 40 /*
63 * plus pre/post garbage samples. */ 69 * ADC DMA buffer must hold 16 samples,
64#define S626_DAC_WDMABUF_DWORDS 1 /* DAC output DMA buffer holds a single 70 * plus pre/post garbage samples.
65 * sample. */ 71 */
72#define S626_DAC_WDMABUF_DWORDS 1 /*
73 * DAC output DMA buffer holds a single
74 * sample.
75 */
66 76
67/* All remaining space in 4KB DMA buffer is available for the RPS1 program. */ 77/* All remaining space in 4KB DMA buffer is available for the RPS1 program. */
68 78
@@ -95,60 +105,90 @@
95#define S626_RPS_IRQ 0x60000000 /* IRQ */ 105#define S626_RPS_IRQ 0x60000000 /* IRQ */
96 106
97#define S626_RPS_LOGICAL_OR 0x08000000 /* Logical OR conditionals. */ 107#define S626_RPS_LOGICAL_OR 0x08000000 /* Logical OR conditionals. */
98#define S626_RPS_INVERT 0x04000000 /* Test for negated 108#define S626_RPS_INVERT 0x04000000 /*
99 * semaphores. */ 109 * Test for negated
110 * semaphores.
111 */
100#define S626_RPS_DEBI 0x00000002 /* DEBI done */ 112#define S626_RPS_DEBI 0x00000002 /* DEBI done */
101 113
102#define S626_RPS_SIG0 0x00200000 /* RPS semaphore 0 114#define S626_RPS_SIG0 0x00200000 /*
103 * (used by ADC). */ 115 * RPS semaphore 0
104#define S626_RPS_SIG1 0x00400000 /* RPS semaphore 1 116 * (used by ADC).
105 * (used by DAC). */ 117 */
106#define S626_RPS_SIG2 0x00800000 /* RPS semaphore 2 118#define S626_RPS_SIG1 0x00400000 /*
107 * (not used). */ 119 * RPS semaphore 1
120 * (used by DAC).
121 */
122#define S626_RPS_SIG2 0x00800000 /*
123 * RPS semaphore 2
124 * (not used).
125 */
108#define S626_RPS_GPIO2 0x00080000 /* RPS GPIO2 */ 126#define S626_RPS_GPIO2 0x00080000 /* RPS GPIO2 */
109#define S626_RPS_GPIO3 0x00100000 /* RPS GPIO3 */ 127#define S626_RPS_GPIO3 0x00100000 /* RPS GPIO3 */
110 128
111#define S626_RPS_SIGADC S626_RPS_SIG0 /* Trigger/status for 129#define S626_RPS_SIGADC S626_RPS_SIG0 /*
112 * ADC's RPS program. */ 130 * Trigger/status for
113#define S626_RPS_SIGDAC S626_RPS_SIG1 /* Trigger/status for 131 * ADC's RPS program.
114 * DAC's RPS program. */ 132 */
133#define S626_RPS_SIGDAC S626_RPS_SIG1 /*
134 * Trigger/status for
135 * DAC's RPS program.
136 */
115 137
116/* RPS clock parameters. */ 138/* RPS clock parameters. */
117#define S626_RPSCLK_SCALAR 8 /* This is apparent ratio of 139#define S626_RPSCLK_SCALAR 8 /*
118 * PCI/RPS clks (undocumented!!). */ 140 * This is apparent ratio of
141 * PCI/RPS clks (undocumented!!).
142 */
119#define S626_RPSCLK_PER_US (33 / S626_RPSCLK_SCALAR) 143#define S626_RPSCLK_PER_US (33 / S626_RPSCLK_SCALAR)
120 /* Number of RPS clocks in one 144 /*
121 * microsecond. */ 145 * Number of RPS clocks in one
146 * microsecond.
147 */
122 148
123/* Event counter source addresses. */ 149/* Event counter source addresses. */
124#define S626_SBA_RPS_A0 0x27 /* Time of RPS0 busy, in PCI clocks. */ 150#define S626_SBA_RPS_A0 0x27 /* Time of RPS0 busy, in PCI clocks. */
125 151
126/* GPIO constants. */ 152/* GPIO constants. */
127#define S626_GPIO_BASE 0x10004000 /* GPIO 0,2,3 = inputs, 153#define S626_GPIO_BASE 0x10004000 /*
128 * GPIO3 = IRQ; GPIO1 = out. */ 154 * GPIO 0,2,3 = inputs,
155 * GPIO3 = IRQ; GPIO1 = out.
156 */
129#define S626_GPIO1_LO 0x00000000 /* GPIO1 set to LOW. */ 157#define S626_GPIO1_LO 0x00000000 /* GPIO1 set to LOW. */
130#define S626_GPIO1_HI 0x00001000 /* GPIO1 set to HIGH. */ 158#define S626_GPIO1_HI 0x00001000 /* GPIO1 set to HIGH. */
131 159
132/* Primary Status Register (PSR) constants. */ 160/* Primary Status Register (PSR) constants. */
133#define S626_PSR_DEBI_E 0x00040000 /* DEBI event flag. */ 161#define S626_PSR_DEBI_E 0x00040000 /* DEBI event flag. */
134#define S626_PSR_DEBI_S 0x00080000 /* DEBI status flag. */ 162#define S626_PSR_DEBI_S 0x00080000 /* DEBI status flag. */
135#define S626_PSR_A2_IN 0x00008000 /* Audio output DMA2 protection 163#define S626_PSR_A2_IN 0x00008000 /*
136 * address reached. */ 164 * Audio output DMA2 protection
137#define S626_PSR_AFOU 0x00000800 /* Audio FIFO under/overflow 165 * address reached.
138 * detected. */ 166 */
139#define S626_PSR_GPIO2 0x00000020 /* GPIO2 input pin: 0=AdcBusy, 167#define S626_PSR_AFOU 0x00000800 /*
140 * 1=AdcIdle. */ 168 * Audio FIFO under/overflow
141#define S626_PSR_EC0S 0x00000001 /* Event counter 0 threshold 169 * detected.
142 * reached. */ 170 */
171#define S626_PSR_GPIO2 0x00000020 /*
172 * GPIO2 input pin: 0=AdcBusy,
173 * 1=AdcIdle.
174 */
175#define S626_PSR_EC0S 0x00000001 /*
176 * Event counter 0 threshold
177 * reached.
178 */
143 179
144/* Secondary Status Register (SSR) constants. */ 180/* Secondary Status Register (SSR) constants. */
145#define S626_SSR_AF2_OUT 0x00000200 /* Audio 2 output FIFO 181#define S626_SSR_AF2_OUT 0x00000200 /*
146 * under/overflow detected. */ 182 * Audio 2 output FIFO
183 * under/overflow detected.
184 */
147 185
148/* Master Control Register 1 (MC1) constants. */ 186/* Master Control Register 1 (MC1) constants. */
149#define S626_MC1_SOFT_RESET 0x80000000 /* Invoke 7146 soft reset. */ 187#define S626_MC1_SOFT_RESET 0x80000000 /* Invoke 7146 soft reset. */
150#define S626_MC1_SHUTDOWN 0x3FFF0000 /* Shut down all MC1-controlled 188#define S626_MC1_SHUTDOWN 0x3FFF0000 /*
151 * enables. */ 189 * Shut down all MC1-controlled
190 * enables.
191 */
152 192
153#define S626_MC1_ERPS1 0x2000 /* Enab/disable RPS task 1. */ 193#define S626_MC1_ERPS1 0x2000 /* Enab/disable RPS task 1. */
154#define S626_MC1_ERPS0 0x1000 /* Enab/disable RPS task 0. */ 194#define S626_MC1_ERPS0 0x1000 /* Enab/disable RPS task 0. */
@@ -177,15 +217,23 @@
177#define S626_P_DEBIAD 0x0088 /* DEBI target address. */ 217#define S626_P_DEBIAD 0x0088 /* DEBI target address. */
178#define S626_P_I2CCTRL 0x008C /* I2C control. */ 218#define S626_P_I2CCTRL 0x008C /* I2C control. */
179#define S626_P_I2CSTAT 0x0090 /* I2C status. */ 219#define S626_P_I2CSTAT 0x0090 /* I2C status. */
180#define S626_P_BASEA2_IN 0x00AC /* Audio input 2 base physical DMAbuf 220#define S626_P_BASEA2_IN 0x00AC /*
181 * address. */ 221 * Audio input 2 base physical DMAbuf
182#define S626_P_PROTA2_IN 0x00B0 /* Audio input 2 physical DMAbuf 222 * address.
183 * protection address. */ 223 */
224#define S626_P_PROTA2_IN 0x00B0 /*
225 * Audio input 2 physical DMAbuf
226 * protection address.
227 */
184#define S626_P_PAGEA2_IN 0x00B4 /* Audio input 2 paging attributes. */ 228#define S626_P_PAGEA2_IN 0x00B4 /* Audio input 2 paging attributes. */
185#define S626_P_BASEA2_OUT 0x00B8 /* Audio output 2 base physical DMAbuf 229#define S626_P_BASEA2_OUT 0x00B8 /*
186 * address. */ 230 * Audio output 2 base physical DMAbuf
187#define S626_P_PROTA2_OUT 0x00BC /* Audio output 2 physical DMAbuf 231 * address.
188 * protection address. */ 232 */
233#define S626_P_PROTA2_OUT 0x00BC /*
234 * Audio output 2 physical DMAbuf
235 * protection address.
236 */
189#define S626_P_PAGEA2_OUT 0x00C0 /* Audio output 2 paging attributes. */ 237#define S626_P_PAGEA2_OUT 0x00C0 /* Audio output 2 paging attributes. */
190#define S626_P_RPSPAGE0 0x00C4 /* RPS0 page. */ 238#define S626_P_RPSPAGE0 0x00C4 /* RPS0 page. */
191#define S626_P_RPSPAGE1 0x00C8 /* RPS1 page. */ 239#define S626_P_RPSPAGE1 0x00C8 /* RPS1 page. */
@@ -205,8 +253,10 @@
205#define S626_P_PSR 0x0110 /* Primary status. */ 253#define S626_P_PSR 0x0110 /* Primary status. */
206#define S626_P_SSR 0x0114 /* Secondary status. */ 254#define S626_P_SSR 0x0114 /* Secondary status. */
207#define S626_P_EC1R 0x0118 /* Event counter set 1. */ 255#define S626_P_EC1R 0x0118 /* Event counter set 1. */
208#define S626_P_ADP4 0x0138 /* Logical audio DMA pointer of audio 256#define S626_P_ADP4 0x0138 /*
209 * input FIFO A2_IN. */ 257 * Logical audio DMA pointer of audio
258 * input FIFO A2_IN.
259 */
210#define S626_P_FB_BUFFER1 0x0144 /* Audio feedback buffer 1. */ 260#define S626_P_FB_BUFFER1 0x0144 /* Audio feedback buffer 1. */
211#define S626_P_FB_BUFFER2 0x0148 /* Audio feedback buffer 2. */ 261#define S626_P_FB_BUFFER2 0x0148 /* Audio feedback buffer 2. */
212#define S626_P_TSL1 0x0180 /* Audio time slot list 1. */ 262#define S626_P_TSL1 0x0180 /* Audio time slot list 1. */
@@ -243,13 +293,19 @@
243#define S626_LP_RDMISC2 0x0082 /* Read Misc2. */ 293#define S626_LP_RDMISC2 0x0082 /* Read Misc2. */
244 294
245/* Bit masks for MISC1 register that are the same for reads and writes. */ 295/* Bit masks for MISC1 register that are the same for reads and writes. */
246#define S626_MISC1_WENABLE 0x8000 /* enab writes to MISC2 (except Clear 296#define S626_MISC1_WENABLE 0x8000 /*
247 * Watchdog bit). */ 297 * enab writes to MISC2 (except Clear
298 * Watchdog bit).
299 */
248#define S626_MISC1_WDISABLE 0x0000 /* Disable writes to MISC2. */ 300#define S626_MISC1_WDISABLE 0x0000 /* Disable writes to MISC2. */
249#define S626_MISC1_EDCAP 0x1000 /* Enable edge capture on DIO chans 301#define S626_MISC1_EDCAP 0x1000 /*
250 * specified by S626_LP_WRCAPSELx. */ 302 * Enable edge capture on DIO chans
251#define S626_MISC1_NOEDCAP 0x0000 /* Disable edge capture on specified 303 * specified by S626_LP_WRCAPSELx.
252 * DIO chans. */ 304 */
305#define S626_MISC1_NOEDCAP 0x0000 /*
306 * Disable edge capture on specified
307 * DIO chans.
308 */
253 309
254/* Bit masks for MISC1 register reads. */ 310/* Bit masks for MISC1 register reads. */
255#define S626_RDMISC1_WDTIMEOUT 0x4000 /* Watchdog timer timed out. */ 311#define S626_RDMISC1_WDTIMEOUT 0x4000 /* Watchdog timer timed out. */
@@ -268,35 +324,49 @@
268#define S626_A1_RUN 0x20000000 /* Run A1 based on TSL1. */ 324#define S626_A1_RUN 0x20000000 /* Run A1 based on TSL1. */
269#define S626_A1_SWAP 0x00200000 /* Use big-endian for A1. */ 325#define S626_A1_SWAP 0x00200000 /* Use big-endian for A1. */
270#define S626_A2_SWAP 0x00100000 /* Use big-endian for A2. */ 326#define S626_A2_SWAP 0x00100000 /* Use big-endian for A2. */
271#define S626_WS_MODES 0x00019999 /* WS0 = TSL1 trigger input, 327#define S626_WS_MODES 0x00019999 /*
272 * WS1-WS4 = CS* outputs. */ 328 * WS0 = TSL1 trigger input,
273 329 * WS1-WS4 = CS* outputs.
274#if S626_PLATFORM == S626_INTEL /* Base ACON1 config: always run 330 */
275 * A1 based on TSL1. */ 331
332#if S626_PLATFORM == S626_INTEL /*
333 * Base ACON1 config: always run
334 * A1 based on TSL1.
335 */
276#define S626_ACON1_BASE (S626_WS_MODES | S626_A1_RUN) 336#define S626_ACON1_BASE (S626_WS_MODES | S626_A1_RUN)
277#elif S626_PLATFORM == S626_MOTOROLA 337#elif S626_PLATFORM == S626_MOTOROLA
278#define S626_ACON1_BASE \ 338#define S626_ACON1_BASE \
279 (S626_WS_MODES | S626_A1_RUN | S626_A1_SWAP | S626_A2_SWAP) 339 (S626_WS_MODES | S626_A1_RUN | S626_A1_SWAP | S626_A2_SWAP)
280#endif 340#endif
281 341
282#define S626_ACON1_ADCSTART S626_ACON1_BASE /* Start ADC: run A1 342#define S626_ACON1_ADCSTART S626_ACON1_BASE /*
283 * based on TSL1. */ 343 * Start ADC: run A1
344 * based on TSL1.
345 */
284#define S626_ACON1_DACSTART (S626_ACON1_BASE | S626_A2_RUN) 346#define S626_ACON1_DACSTART (S626_ACON1_BASE | S626_A2_RUN)
285/* Start transmit to DAC: run A2 based on TSL2. */ 347/* Start transmit to DAC: run A2 based on TSL2. */
286#define S626_ACON1_DACSTOP S626_ACON1_BASE /* Halt A2. */ 348#define S626_ACON1_DACSTOP S626_ACON1_BASE /* Halt A2. */
287 349
288/* Bit masks for ACON2 register. */ 350/* Bit masks for ACON2 register. */
289#define S626_A1_CLKSRC_BCLK1 0x00000000 /* A1 bit rate = BCLK1 (ADC). */ 351#define S626_A1_CLKSRC_BCLK1 0x00000000 /* A1 bit rate = BCLK1 (ADC). */
290#define S626_A2_CLKSRC_X1 0x00800000 /* A2 bit rate = ACLK/1 352#define S626_A2_CLKSRC_X1 0x00800000 /*
291 * (DACs). */ 353 * A2 bit rate = ACLK/1
292#define S626_A2_CLKSRC_X2 0x00C00000 /* A2 bit rate = ACLK/2 354 * (DACs).
293 * (DACs). */ 355 */
294#define S626_A2_CLKSRC_X4 0x01400000 /* A2 bit rate = ACLK/4 356#define S626_A2_CLKSRC_X2 0x00C00000 /*
295 * (DACs). */ 357 * A2 bit rate = ACLK/2
358 * (DACs).
359 */
360#define S626_A2_CLKSRC_X4 0x01400000 /*
361 * A2 bit rate = ACLK/4
362 * (DACs).
363 */
296#define S626_INVERT_BCLK2 0x00100000 /* Invert BCLK2 (DACs). */ 364#define S626_INVERT_BCLK2 0x00100000 /* Invert BCLK2 (DACs). */
297#define S626_BCLK2_OE 0x00040000 /* Enable BCLK2 (DACs). */ 365#define S626_BCLK2_OE 0x00040000 /* Enable BCLK2 (DACs). */
298#define S626_ACON2_XORMASK 0x000C0000 /* XOR mask for ACON2 366#define S626_ACON2_XORMASK 0x000C0000 /*
299 * active-low bits. */ 367 * XOR mask for ACON2
368 * active-low bits.
369 */
300 370
301#define S626_ACON2_INIT (S626_ACON2_XORMASK ^ \ 371#define S626_ACON2_INIT (S626_ACON2_XORMASK ^ \
302 (S626_A1_CLKSRC_BCLK1 | S626_A2_CLKSRC_X2 | \ 372 (S626_A1_CLKSRC_BCLK1 | S626_A2_CLKSRC_X2 | \
@@ -308,12 +378,18 @@
308#define S626_WS3 0x10000000 378#define S626_WS3 0x10000000
309#define S626_WS4 0x08000000 379#define S626_WS4 0x08000000
310#define S626_RSD1 0x01000000 /* Shift A1 data in on SD1. */ 380#define S626_RSD1 0x01000000 /* Shift A1 data in on SD1. */
311#define S626_SDW_A1 0x00800000 /* Store rcv'd char at next char 381#define S626_SDW_A1 0x00800000 /*
312 * slot of DWORD1 buffer. */ 382 * Store rcv'd char at next char
313#define S626_SIB_A1 0x00400000 /* Store rcv'd char at next 383 * slot of DWORD1 buffer.
314 * char slot of FB1 buffer. */ 384 */
315#define S626_SF_A1 0x00200000 /* Write unsigned long 385#define S626_SIB_A1 0x00400000 /*
316 * buffer to input FIFO. */ 386 * Store rcv'd char at next
387 * char slot of FB1 buffer.
388 */
389#define S626_SF_A1 0x00200000 /*
390 * Write unsigned long
391 * buffer to input FIFO.
392 */
317 393
318/* Select parallel-to-serial converter's data source: */ 394/* Select parallel-to-serial converter's data source: */
319#define S626_XFIFO_0 0x00000000 /* Data fifo byte 0. */ 395#define S626_XFIFO_0 0x00000000 /* Data fifo byte 0. */
@@ -324,31 +400,45 @@
324#define S626_XFB1 0x00000050 /* FB_BUFFER byte 1. */ 400#define S626_XFB1 0x00000050 /* FB_BUFFER byte 1. */
325#define S626_XFB2 0x00000060 /* FB_BUFFER byte 2. */ 401#define S626_XFB2 0x00000060 /* FB_BUFFER byte 2. */
326#define S626_XFB3 0x00000070 /* FB_BUFFER byte 3. */ 402#define S626_XFB3 0x00000070 /* FB_BUFFER byte 3. */
327#define S626_SIB_A2 0x00000200 /* Store next dword from A2's 403#define S626_SIB_A2 0x00000200 /*
404 * Store next dword from A2's
328 * input shifter to FB2 405 * input shifter to FB2
329 * buffer. */ 406 * buffer.
330#define S626_SF_A2 0x00000100 /* Store next dword from A2's 407 */
408#define S626_SF_A2 0x00000100 /*
409 * Store next dword from A2's
331 * input shifter to its input 410 * input shifter to its input
332 * fifo. */ 411 * fifo.
333#define S626_LF_A2 0x00000080 /* Load next dword from A2's 412 */
413#define S626_LF_A2 0x00000080 /*
414 * Load next dword from A2's
334 * output fifo into its 415 * output fifo into its
335 * output dword buffer. */ 416 * output dword buffer.
417 */
336#define S626_XSD2 0x00000008 /* Shift data out on SD2. */ 418#define S626_XSD2 0x00000008 /* Shift data out on SD2. */
337#define S626_RSD3 0x00001800 /* Shift data in on SD3. */ 419#define S626_RSD3 0x00001800 /* Shift data in on SD3. */
338#define S626_RSD2 0x00001000 /* Shift data in on SD2. */ 420#define S626_RSD2 0x00001000 /* Shift data in on SD2. */
339#define S626_LOW_A2 0x00000002 /* Drive last SD low for 7 clks, 421#define S626_LOW_A2 0x00000002 /*
340 * then tri-state. */ 422 * Drive last SD low for 7 clks,
423 * then tri-state.
424 */
341#define S626_EOS 0x00000001 /* End of superframe. */ 425#define S626_EOS 0x00000001 /* End of superframe. */
342 426
343/* I2C configuration constants. */ 427/* I2C configuration constants. */
344#define S626_I2C_CLKSEL 0x0400 /* I2C bit rate = 428#define S626_I2C_CLKSEL 0x0400 /*
345 * PCIclk/480 = 68.75 KHz. */ 429 * I2C bit rate =
346#define S626_I2C_BITRATE 68.75 /* I2C bus data bit rate 430 * PCIclk/480 = 68.75 KHz.
431 */
432#define S626_I2C_BITRATE 68.75 /*
433 * I2C bus data bit rate
347 * (determined by 434 * (determined by
348 * S626_I2C_CLKSEL) in KHz. */ 435 * S626_I2C_CLKSEL) in KHz.
349#define S626_I2C_WRTIME 15.0 /* Worst case time, in msec, 436 */
437#define S626_I2C_WRTIME 15.0 /*
438 * Worst case time, in msec,
350 * for EEPROM internal write 439 * for EEPROM internal write
351 * op. */ 440 * op.
441 */
352 442
353/* I2C manifest constants. */ 443/* I2C manifest constants. */
354 444
@@ -368,8 +458,10 @@
368#define S626_I2C_B0(ATTR, VAL) (((ATTR) << 2) | ((VAL) << 8)) 458#define S626_I2C_B0(ATTR, VAL) (((ATTR) << 2) | ((VAL) << 8))
369 459
370/* DEBI command constants. */ 460/* DEBI command constants. */
371#define S626_DEBI_CMD_SIZE16 (2 << 17) /* Transfer size is always 461#define S626_DEBI_CMD_SIZE16 (2 << 17) /*
372 * 2 bytes. */ 462 * Transfer size is always
463 * 2 bytes.
464 */
373#define S626_DEBI_CMD_READ 0x00010000 /* Read operation. */ 465#define S626_DEBI_CMD_READ 0x00010000 /* Read operation. */
374#define S626_DEBI_CMD_WRITE 0x00000000 /* Write operation. */ 466#define S626_DEBI_CMD_WRITE 0x00000000 /* Write operation. */
375 467
@@ -380,42 +472,58 @@
380#define S626_DEBI_CMD_WRWORD (S626_DEBI_CMD_WRITE | S626_DEBI_CMD_SIZE16) 472#define S626_DEBI_CMD_WRWORD (S626_DEBI_CMD_WRITE | S626_DEBI_CMD_SIZE16)
381 473
382/* DEBI configuration constants. */ 474/* DEBI configuration constants. */
383#define S626_DEBI_CFG_XIRQ_EN 0x80000000 /* Enable external interrupt 475#define S626_DEBI_CFG_XIRQ_EN 0x80000000 /*
384 * on GPIO3. */ 476 * Enable external interrupt
477 * on GPIO3.
478 */
385#define S626_DEBI_CFG_XRESUME 0x40000000 /* Resume block */ 479#define S626_DEBI_CFG_XRESUME 0x40000000 /* Resume block */
386 /* Transfer when XIRQ 480 /*
387 * deasserted. */ 481 * Transfer when XIRQ
482 * deasserted.
483 */
388#define S626_DEBI_CFG_TOQ 0x03C00000 /* Timeout (15 PCI cycles). */ 484#define S626_DEBI_CFG_TOQ 0x03C00000 /* Timeout (15 PCI cycles). */
389#define S626_DEBI_CFG_FAST 0x10000000 /* Fast mode enable. */ 485#define S626_DEBI_CFG_FAST 0x10000000 /* Fast mode enable. */
390 486
391/* 4-bit field that specifies DEBI timeout value in PCI clock cycles: */ 487/* 4-bit field that specifies DEBI timeout value in PCI clock cycles: */
392#define S626_DEBI_CFG_TOUT_BIT 22 /* Finish DEBI cycle after this many 488#define S626_DEBI_CFG_TOUT_BIT 22 /*
393 * clocks. */ 489 * Finish DEBI cycle after this many
490 * clocks.
491 */
394 492
395/* 2-bit field that specifies Endian byte lane steering: */ 493/* 2-bit field that specifies Endian byte lane steering: */
396#define S626_DEBI_CFG_SWAP_NONE 0x00000000 /* Straight - don't swap any 494#define S626_DEBI_CFG_SWAP_NONE 0x00000000 /*
397 * bytes (Intel). */ 495 * Straight - don't swap any
496 * bytes (Intel).
497 */
398#define S626_DEBI_CFG_SWAP_2 0x00100000 /* 2-byte swap (Motorola). */ 498#define S626_DEBI_CFG_SWAP_2 0x00100000 /* 2-byte swap (Motorola). */
399#define S626_DEBI_CFG_SWAP_4 0x00200000 /* 4-byte swap. */ 499#define S626_DEBI_CFG_SWAP_4 0x00200000 /* 4-byte swap. */
400#define S626_DEBI_CFG_SLAVE16 0x00080000 /* Slave is able to serve 500#define S626_DEBI_CFG_SLAVE16 0x00080000 /*
401 * 16-bit cycles. */ 501 * Slave is able to serve
402#define S626_DEBI_CFG_INC 0x00040000 /* Enable address increment 502 * 16-bit cycles.
403 * for block transfers. */ 503 */
504#define S626_DEBI_CFG_INC 0x00040000 /*
505 * Enable address increment
506 * for block transfers.
507 */
404#define S626_DEBI_CFG_INTEL 0x00020000 /* Intel style local bus. */ 508#define S626_DEBI_CFG_INTEL 0x00020000 /* Intel style local bus. */
405#define S626_DEBI_CFG_TIMEROFF 0x00010000 /* Disable timer. */ 509#define S626_DEBI_CFG_TIMEROFF 0x00010000 /* Disable timer. */
406 510
407#if S626_PLATFORM == S626_INTEL 511#if S626_PLATFORM == S626_INTEL
408 512
409#define S626_DEBI_TOUT 7 /* Wait 7 PCI clocks (212 ns) before 513#define S626_DEBI_TOUT 7 /*
410 * polling RDY. */ 514 * Wait 7 PCI clocks (212 ns) before
515 * polling RDY.
516 */
411 517
412/* Intel byte lane steering (pass through all byte lanes). */ 518/* Intel byte lane steering (pass through all byte lanes). */
413#define S626_DEBI_SWAP S626_DEBI_CFG_SWAP_NONE 519#define S626_DEBI_SWAP S626_DEBI_CFG_SWAP_NONE
414 520
415#elif S626_PLATFORM == S626_MOTOROLA 521#elif S626_PLATFORM == S626_MOTOROLA
416 522
417#define S626_DEBI_TOUT 15 /* Wait 15 PCI clocks (454 ns) maximum 523#define S626_DEBI_TOUT 15 /*
418 * before timing out. */ 524 * Wait 15 PCI clocks (454 ns) maximum
525 * before timing out.
526 */
419 527
420/* Motorola byte lane steering. */ 528/* Motorola byte lane steering. */
421#define S626_DEBI_SWAP S626_DEBI_CFG_SWAP_2 529#define S626_DEBI_SWAP S626_DEBI_CFG_SWAP_2
@@ -429,10 +537,14 @@
429 537
430/* LoadSrc values: */ 538/* LoadSrc values: */
431#define S626_LOADSRC_INDX 0 /* Preload core in response to Index. */ 539#define S626_LOADSRC_INDX 0 /* Preload core in response to Index. */
432#define S626_LOADSRC_OVER 1 /* Preload core in response to 540#define S626_LOADSRC_OVER 1 /*
433 * Overflow. */ 541 * Preload core in response to
434#define S626_LOADSRCB_OVERA 2 /* Preload B core in response to 542 * Overflow.
435 * A Overflow. */ 543 */
544#define S626_LOADSRCB_OVERA 2 /*
545 * Preload B core in response to
546 * A Overflow.
547 */
436#define S626_LOADSRC_NONE 3 /* Never preload core. */ 548#define S626_LOADSRC_NONE 3 /* Never preload core. */
437 549
438/* IntSrc values: */ 550/* IntSrc values: */
@@ -469,10 +581,14 @@
469#define S626_CNTSRC_SYSCLK_DOWN 3 /* System clock down */ 581#define S626_CNTSRC_SYSCLK_DOWN 3 /* System clock down */
470 582
471/* ClkPol values: */ 583/* ClkPol values: */
472#define S626_CLKPOL_POS 0 /* Counter/Extender clock is 584#define S626_CLKPOL_POS 0 /*
473 * active high. */ 585 * Counter/Extender clock is
474#define S626_CLKPOL_NEG 1 /* Counter/Extender clock is 586 * active high.
475 * active low. */ 587 */
588#define S626_CLKPOL_NEG 1 /*
589 * Counter/Extender clock is
590 * active low.
591 */
476#define S626_CNTDIR_UP 0 /* Timer counts up. */ 592#define S626_CNTDIR_UP 0 /* Timer counts up. */
477#define S626_CNTDIR_DOWN 1 /* Timer counts down. */ 593#define S626_CNTDIR_DOWN 1 /* Timer counts down. */
478 594
@@ -488,8 +604,10 @@
488 604
489/* Sanity-check limits for parameters. */ 605/* Sanity-check limits for parameters. */
490 606
491#define S626_NUM_COUNTERS 6 /* Maximum valid counter 607#define S626_NUM_COUNTERS 6 /*
492 * logical channel number. */ 608 * Maximum valid counter
609 * logical channel number.
610 */
493#define S626_NUM_INTSOURCES 4 611#define S626_NUM_INTSOURCES 4
494#define S626_NUM_LATCHSOURCES 4 612#define S626_NUM_LATCHSOURCES 4
495#define S626_NUM_CLKMULTS 4 613#define S626_NUM_CLKMULTS 4
diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index 7a1defcf2102..0d33e520f635 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -95,7 +95,7 @@ struct serial_data {
95#define S2002_CFG_SIGN(x) (((x) >> 13) & 0x1) 95#define S2002_CFG_SIGN(x) (((x) >> 13) & 0x1)
96#define S2002_CFG_BASE(x) (((x) >> 14) & 0xfffff) 96#define S2002_CFG_BASE(x) (((x) >> 14) & 0xfffff)
97 97
98static long serial2002_tty_ioctl(struct file *f, unsigned op, 98static long serial2002_tty_ioctl(struct file *f, unsigned int op,
99 unsigned long param) 99 unsigned long param)
100{ 100{
101 if (f->f_op->unlocked_ioctl) 101 if (f->f_op->unlocked_ioctl)
@@ -379,7 +379,10 @@ static int serial2002_setup_subdevice(struct comedi_subdevice *s,
379 range_table_list[chan] = 379 range_table_list[chan] =
380 (const struct comedi_lrange *)&range[j]; 380 (const struct comedi_lrange *)&range[j];
381 } 381 }
382 maxdata_list[chan] = ((long long)1 << cfg[j].bits) - 1; 382 if (cfg[j].bits < 32)
383 maxdata_list[chan] = (1u << cfg[j].bits) - 1;
384 else
385 maxdata_list[chan] = 0xffffffff;
383 chan++; 386 chan++;
384 } 387 }
385 } 388 }
diff --git a/drivers/staging/ks7010/Kconfig b/drivers/staging/ks7010/Kconfig
new file mode 100644
index 000000000000..0b9217674d5b
--- /dev/null
+++ b/drivers/staging/ks7010/Kconfig
@@ -0,0 +1,10 @@
1config KS7010
2 tristate "KeyStream KS7010 SDIO support"
3 depends on MMC && WIRELESS
4 select WIRELESS_EXT
5 select WEXT_PRIV
6 select FW_LOADER
7 help
8 This is a driver for KeyStream KS7010 based SDIO WIFI cards. It is
9 found on at least later Spectec SDW-821 (FCC-ID "S2Y-WLAN-11G-K" only,
10 sadly not FCC-ID "S2Y-WLAN-11B-G") and Spectec SDW-823 microSD cards.
diff --git a/drivers/staging/ks7010/Makefile b/drivers/staging/ks7010/Makefile
new file mode 100644
index 000000000000..69fcf8d655c7
--- /dev/null
+++ b/drivers/staging/ks7010/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_KS7010) += ks7010.o
2
3ccflags-y += -DKS_WLAN_DEBUG=0
4ks7010-y := michael_mic.o ks_hostif.o ks_wlan_net.o ks7010_sdio.o
diff --git a/drivers/staging/ks7010/TODO b/drivers/staging/ks7010/TODO
new file mode 100644
index 000000000000..2938d35be5bb
--- /dev/null
+++ b/drivers/staging/ks7010/TODO
@@ -0,0 +1,36 @@
1KS7010 Linux driver
2===================
3
4This driver is based on source code from the Ben Nanonote extra repository [1]
5which is based on the original v007 release from Renesas [2]. Some more
6background info about the chipset can be found here [3] and here [4]. Thank
7you to all which already participated in cleaning up the driver so far!
8
9[1] http://projects.qi-hardware.com/index.php/p/openwrt-packages/source/tree/master/ks7010/src
10[2] http://downloads.qi-hardware.com/software/ks7010_sdio_v007.tar.bz2
11[3] http://en.qi-hardware.com/wiki/Ben_NanoNote_Wi-Fi
12[4] https://wikidevi.com/wiki/Renesas
13
14TODO
15----
16
17First a few words what not to do (at least not blindly):
18
19- don't be overly strict with the 80 char limit. Only if it REALLY makes the
20 code more readable
21- No '#if 0/1' removal unless the surrounding code is understood and removal is
22 really OK. There might be some hints hidden there.
23
24Now the TODOs:
25
26- fix codechecker warnings (checkpatch, sparse, smatch). But PLEASE make sure
27 that you are not only silencing the warning but really fixing code. You
28 should understand the change you submit.
29- fix the 'card removal' event when card is inserted when booting
30- check what other upstream wireless mechanisms can be used instead of the
31 custom ones here
32
33Please send any patches to:
34Greg Kroah-Hartman <gregkh@linuxfoundation.org>
35Wolfram Sang <wsa@the-dreams.de>
36Linux Driver Project Developer List <driverdev-devel@linuxdriverproject.org>
diff --git a/drivers/staging/ks7010/eap_packet.h b/drivers/staging/ks7010/eap_packet.h
new file mode 100644
index 000000000000..16a392abdaec
--- /dev/null
+++ b/drivers/staging/ks7010/eap_packet.h
@@ -0,0 +1,129 @@
1#ifndef EAP_PACKET_H
2#define EAP_PACKET_H
3
4#define WBIT(n) (1 << (n))
5
6#ifndef ETH_ALEN
7#define ETH_ALEN 6
8#endif
9
10struct ether_hdr {
11 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
12 unsigned char h_source[ETH_ALEN]; /* source ether addr */
13 unsigned char h_dest_snap;
14 unsigned char h_source_snap;
15 unsigned char h_command;
16 unsigned char h_vendor_id[3];
17 unsigned short h_proto; /* packet type ID field */
18#define ETHER_PROTOCOL_TYPE_EAP 0x888e
19#define ETHER_PROTOCOL_TYPE_IP 0x0800
20#define ETHER_PROTOCOL_TYPE_ARP 0x0806
21 /* followed by length octets of data */
22} __attribute__ ((packed));
23
24struct ieee802_1x_hdr {
25 unsigned char version;
26 unsigned char type;
27 unsigned short length;
28 /* followed by length octets of data */
29} __attribute__ ((packed));
30
31#define EAPOL_VERSION 2
32
33enum { IEEE802_1X_TYPE_EAP_PACKET = 0,
34 IEEE802_1X_TYPE_EAPOL_START = 1,
35 IEEE802_1X_TYPE_EAPOL_LOGOFF = 2,
36 IEEE802_1X_TYPE_EAPOL_KEY = 3,
37 IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT = 4
38};
39
40enum { EAPOL_KEY_TYPE_RC4 = 1, EAPOL_KEY_TYPE_RSN = 2,
41 EAPOL_KEY_TYPE_WPA = 254
42};
43
44#define IEEE8021X_REPLAY_COUNTER_LEN 8
45#define IEEE8021X_KEY_SIGN_LEN 16
46#define IEEE8021X_KEY_IV_LEN 16
47
48#define IEEE8021X_KEY_INDEX_FLAG 0x80
49#define IEEE8021X_KEY_INDEX_MASK 0x03
50
51struct ieee802_1x_eapol_key {
52 unsigned char type;
53 unsigned short key_length;
54 /* does not repeat within the life of the keying material used to
55 * encrypt the Key field; 64-bit NTP timestamp MAY be used here */
56 unsigned char replay_counter[IEEE8021X_REPLAY_COUNTER_LEN];
57 unsigned char key_iv[IEEE8021X_KEY_IV_LEN]; /* cryptographically random number */
58 unsigned char key_index; /* key flag in the most significant bit:
59 * 0 = broadcast (default key),
60 * 1 = unicast (key mapping key); key index is in the
61 * 7 least significant bits */
62 /* HMAC-MD5 message integrity check computed with MS-MPPE-Send-Key as
63 * the key */
64 unsigned char key_signature[IEEE8021X_KEY_SIGN_LEN];
65
66 /* followed by key: if packet body length = 44 + key length, then the
67 * key field (of key_length bytes) contains the key in encrypted form;
68 * if packet body length = 44, key field is absent and key_length
69 * represents the number of least significant octets from
70 * MS-MPPE-Send-Key attribute to be used as the keying material;
71 * RC4 key used in encryption = Key-IV + MS-MPPE-Recv-Key */
72} __attribute__ ((packed));
73
74#define WPA_NONCE_LEN 32
75#define WPA_REPLAY_COUNTER_LEN 8
76
77struct wpa_eapol_key {
78 unsigned char type;
79 unsigned short key_info;
80 unsigned short key_length;
81 unsigned char replay_counter[WPA_REPLAY_COUNTER_LEN];
82 unsigned char key_nonce[WPA_NONCE_LEN];
83 unsigned char key_iv[16];
84 unsigned char key_rsc[8];
85 unsigned char key_id[8]; /* Reserved in IEEE 802.11i/RSN */
86 unsigned char key_mic[16];
87 unsigned short key_data_length;
88 /* followed by key_data_length bytes of key_data */
89} __attribute__ ((packed));
90
91#define WPA_KEY_INFO_TYPE_MASK (WBIT(0) | WBIT(1) | WBIT(2))
92#define WPA_KEY_INFO_TYPE_HMAC_MD5_RC4 WBIT(0)
93#define WPA_KEY_INFO_TYPE_HMAC_SHA1_AES WBIT(1)
94#define WPA_KEY_INFO_KEY_TYPE WBIT(3) /* 1 = Pairwise, 0 = Group key */
95/* bit4..5 is used in WPA, but is reserved in IEEE 802.11i/RSN */
96#define WPA_KEY_INFO_KEY_INDEX_MASK (WBIT(4) | WBIT(5))
97#define WPA_KEY_INFO_KEY_INDEX_SHIFT 4
98#define WPA_KEY_INFO_INSTALL WBIT(6) /* pairwise */
99#define WPA_KEY_INFO_TXRX WBIT(6) /* group */
100#define WPA_KEY_INFO_ACK WBIT(7)
101#define WPA_KEY_INFO_MIC WBIT(8)
102#define WPA_KEY_INFO_SECURE WBIT(9)
103#define WPA_KEY_INFO_ERROR WBIT(10)
104#define WPA_KEY_INFO_REQUEST WBIT(11)
105#define WPA_KEY_INFO_ENCR_KEY_DATA WBIT(12) /* IEEE 802.11i/RSN only */
106
107#define WPA_CAPABILITY_PREAUTH WBIT(0)
108
109#define GENERIC_INFO_ELEM 0xdd
110#define RSN_INFO_ELEM 0x30
111
112enum {
113 REASON_UNSPECIFIED = 1,
114 REASON_DEAUTH_LEAVING = 3,
115 REASON_INVALID_IE = 13,
116 REASON_MICHAEL_MIC_FAILURE = 14,
117 REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
118 REASON_GROUP_KEY_UPDATE_TIMEOUT = 16,
119 REASON_IE_IN_4WAY_DIFFERS = 17,
120 REASON_GROUP_CIPHER_NOT_VALID = 18,
121 REASON_PAIRWISE_CIPHER_NOT_VALID = 19,
122 REASON_AKMP_NOT_VALID = 20,
123 REASON_UNSUPPORTED_RSN_IE_VERSION = 21,
124 REASON_INVALID_RSN_IE_CAPAB = 22,
125 REASON_IEEE_802_1X_AUTH_FAILED = 23,
126 REASON_CIPHER_SUITE_REJECTED = 24
127};
128
129#endif /* EAP_PACKET_H */
diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
new file mode 100644
index 000000000000..b7337fd813d5
--- /dev/null
+++ b/drivers/staging/ks7010/ks7010_sdio.c
@@ -0,0 +1,1236 @@
1/*
2 * Driver for KeyStream, KS7010 based SDIO cards.
3 *
4 * Copyright (C) 2006-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 * Copyright (C) 2016 Sang Engineering, Wolfram Sang
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#include <linux/firmware.h>
14#include <linux/mmc/card.h>
15#include <linux/mmc/sdio_func.h>
16#include <linux/workqueue.h>
17#include <asm/atomic.h>
18
19#include "ks_wlan.h"
20#include "ks_wlan_ioctl.h"
21#include "ks_hostif.h"
22#include "ks7010_sdio.h"
23
24#define KS7010_FUNC_NUM 1
25#define KS7010_IO_BLOCK_SIZE 512
26#define KS7010_MAX_CLOCK 25000000
27
28static const struct sdio_device_id ks7010_sdio_ids[] = {
29 {SDIO_DEVICE(SDIO_VENDOR_ID_KS_CODE_A, SDIO_DEVICE_ID_KS_7010)},
30 {SDIO_DEVICE(SDIO_VENDOR_ID_KS_CODE_B, SDIO_DEVICE_ID_KS_7010)},
31 { /* all zero */ }
32};
33MODULE_DEVICE_TABLE(sdio, ks7010_sdio_ids);
34
35/* macro */
36
37#define inc_txqhead(priv) \
38 ( priv->tx_dev.qhead = (priv->tx_dev.qhead + 1) % TX_DEVICE_BUFF_SIZE )
39#define inc_txqtail(priv) \
40 ( priv->tx_dev.qtail = (priv->tx_dev.qtail + 1) % TX_DEVICE_BUFF_SIZE )
41#define cnt_txqbody(priv) \
42 (((priv->tx_dev.qtail + TX_DEVICE_BUFF_SIZE) - (priv->tx_dev.qhead)) % TX_DEVICE_BUFF_SIZE )
43
44#define inc_rxqhead(priv) \
45 ( priv->rx_dev.qhead = (priv->rx_dev.qhead + 1) % RX_DEVICE_BUFF_SIZE )
46#define inc_rxqtail(priv) \
47 ( priv->rx_dev.qtail = (priv->rx_dev.qtail + 1) % RX_DEVICE_BUFF_SIZE )
48#define cnt_rxqbody(priv) \
49 (((priv->rx_dev.qtail + RX_DEVICE_BUFF_SIZE) - (priv->rx_dev.qhead)) % RX_DEVICE_BUFF_SIZE )
50
51static int ks7010_sdio_read(struct ks_wlan_private *priv, unsigned int address,
52 unsigned char *buffer, int length)
53{
54 struct ks_sdio_card *card;
55 int rc;
56
57 card = priv->ks_wlan_hw.sdio_card;
58
59 if (length == 1) /* CMD52 */
60 *buffer = sdio_readb(card->func, address, &rc);
61 else /* CMD53 multi-block transfer */
62 rc = sdio_memcpy_fromio(card->func, buffer, address, length);
63
64 if (rc != 0)
65 DPRINTK(1, "sdio error=%d size=%d\n", rc, length);
66
67 return rc;
68}
69
70static int ks7010_sdio_write(struct ks_wlan_private *priv, unsigned int address,
71 unsigned char *buffer, int length)
72{
73 struct ks_sdio_card *card;
74 int rc;
75
76 card = priv->ks_wlan_hw.sdio_card;
77
78 if (length == 1) /* CMD52 */
79 sdio_writeb(card->func, *buffer, (unsigned int)address, &rc);
80 else /* CMD53 */
81 rc = sdio_memcpy_toio(card->func, (unsigned int)address, buffer,
82 length);
83
84 if (rc != 0)
85 DPRINTK(1, "sdio error=%d size=%d\n", rc, length);
86
87 return rc;
88}
89
90void ks_wlan_hw_sleep_doze_request(struct ks_wlan_private *priv)
91{
92 unsigned char rw_data;
93 int retval;
94
95 DPRINTK(4, "\n");
96
97 /* clear request */
98 atomic_set(&priv->sleepstatus.doze_request, 0);
99
100 if (atomic_read(&priv->sleepstatus.status) == 0) {
101 rw_data = GCR_B_DOZE;
102 retval =
103 ks7010_sdio_write(priv, GCR_B, &rw_data, sizeof(rw_data));
104 if (retval) {
105 DPRINTK(1, " error : GCR_B=%02X\n", rw_data);
106 goto out;
107 }
108 DPRINTK(4, "PMG SET!! : GCR_B=%02X\n", rw_data);
109 DPRINTK(3, "sleep_mode=SLP_SLEEP\n");
110 atomic_set(&priv->sleepstatus.status, 1);
111 priv->last_doze = jiffies;
112 } else {
113 DPRINTK(1, "sleep_mode=%d\n", priv->sleep_mode);
114 }
115
116 out:
117 priv->sleep_mode = atomic_read(&priv->sleepstatus.status);
118 return;
119}
120
121void ks_wlan_hw_sleep_wakeup_request(struct ks_wlan_private *priv)
122{
123 unsigned char rw_data;
124 int retval;
125
126 DPRINTK(4, "\n");
127
128 /* clear request */
129 atomic_set(&priv->sleepstatus.wakeup_request, 0);
130
131 if (atomic_read(&priv->sleepstatus.status) == 1) {
132 rw_data = WAKEUP_REQ;
133 retval =
134 ks7010_sdio_write(priv, WAKEUP, &rw_data, sizeof(rw_data));
135 if (retval) {
136 DPRINTK(1, " error : WAKEUP=%02X\n", rw_data);
137 goto out;
138 }
139 DPRINTK(4, "wake up : WAKEUP=%02X\n", rw_data);
140 atomic_set(&priv->sleepstatus.status, 0);
141 priv->last_wakeup = jiffies;
142 ++priv->wakeup_count;
143 } else {
144 DPRINTK(1, "sleep_mode=%d\n", priv->sleep_mode);
145 }
146
147 out:
148 priv->sleep_mode = atomic_read(&priv->sleepstatus.status);
149 return;
150}
151
152void ks_wlan_hw_wakeup_request(struct ks_wlan_private *priv)
153{
154 unsigned char rw_data;
155 int retval;
156
157 DPRINTK(4, "\n");
158 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) {
159 rw_data = WAKEUP_REQ;
160 retval =
161 ks7010_sdio_write(priv, WAKEUP, &rw_data, sizeof(rw_data));
162 if (retval) {
163 DPRINTK(1, " error : WAKEUP=%02X\n", rw_data);
164 }
165 DPRINTK(4, "wake up : WAKEUP=%02X\n", rw_data);
166 priv->last_wakeup = jiffies;
167 ++priv->wakeup_count;
168 } else {
169 DPRINTK(1, "psstatus=%d\n",
170 atomic_read(&priv->psstatus.status));
171 }
172}
173
174int _ks_wlan_hw_power_save(struct ks_wlan_private *priv)
175{
176 int rc = 0;
177 unsigned char rw_data;
178 int retval;
179
180 if (priv->reg.powermgt == POWMGT_ACTIVE_MODE)
181 return rc;
182
183 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE &&
184 (priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
185
186 //DPRINTK(1,"psstatus.status=%d\n",atomic_read(&priv->psstatus.status));
187 if (priv->dev_state == DEVICE_STATE_SLEEP) {
188 switch (atomic_read(&priv->psstatus.status)) {
189 case PS_SNOOZE: /* 4 */
190 break;
191 default:
192 DPRINTK(5, "\npsstatus.status=%d\npsstatus.confirm_wait=%d\npsstatus.snooze_guard=%d\ncnt_txqbody=%d\n",
193 atomic_read(&priv->psstatus.status),
194 atomic_read(&priv->psstatus.confirm_wait),
195 atomic_read(&priv->psstatus.snooze_guard),
196 cnt_txqbody(priv));
197
198 if (!atomic_read(&priv->psstatus.confirm_wait)
199 && !atomic_read(&priv->psstatus.snooze_guard)
200 && !cnt_txqbody(priv)) {
201 retval =
202 ks7010_sdio_read(priv, INT_PENDING,
203 &rw_data,
204 sizeof(rw_data));
205 if (retval) {
206 DPRINTK(1,
207 " error : INT_PENDING=%02X\n",
208 rw_data);
209 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
210 &priv->ks_wlan_hw.rw_wq, 1);
211 break;
212 }
213 if (!rw_data) {
214 rw_data = GCR_B_DOZE;
215 retval =
216 ks7010_sdio_write(priv,
217 GCR_B,
218 &rw_data,
219 sizeof(rw_data));
220 if (retval) {
221 DPRINTK(1,
222 " error : GCR_B=%02X\n",
223 rw_data);
224 queue_delayed_work
225 (priv->ks_wlan_hw.ks7010sdio_wq,
226 &priv->ks_wlan_hw.rw_wq, 1);
227 break;
228 }
229 DPRINTK(4,
230 "PMG SET!! : GCR_B=%02X\n",
231 rw_data);
232 atomic_set(&priv->psstatus.
233 status, PS_SNOOZE);
234 DPRINTK(3,
235 "psstatus.status=PS_SNOOZE\n");
236 } else {
237 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
238 &priv->ks_wlan_hw.rw_wq, 1);
239 }
240 } else {
241 queue_delayed_work(priv->ks_wlan_hw.
242 ks7010sdio_wq,
243 &priv->ks_wlan_hw.rw_wq,
244 0);
245 }
246 break;
247 }
248 }
249
250 }
251
252 return rc;
253}
254
255int ks_wlan_hw_power_save(struct ks_wlan_private *priv)
256{
257 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
258 &priv->ks_wlan_hw.rw_wq, 1);
259 return 0;
260}
261
262static int enqueue_txdev(struct ks_wlan_private *priv, unsigned char *p,
263 unsigned long size,
264 void (*complete_handler) (void *arg1, void *arg2),
265 void *arg1, void *arg2)
266{
267 struct tx_device_buffer *sp;
268
269 if (priv->dev_state < DEVICE_STATE_BOOT) {
270 kfree(p);
271 if (complete_handler != NULL)
272 (*complete_handler) (arg1, arg2);
273 return 1;
274 }
275
276 if ((TX_DEVICE_BUFF_SIZE - 1) <= cnt_txqbody(priv)) {
277 /* in case of buffer overflow */
278 DPRINTK(1, "tx buffer overflow\n");
279 kfree(p);
280 if (complete_handler != NULL)
281 (*complete_handler) (arg1, arg2);
282 return 1;
283 }
284
285 sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qtail];
286 sp->sendp = p;
287 sp->size = size;
288 sp->complete_handler = complete_handler;
289 sp->arg1 = arg1;
290 sp->arg2 = arg2;
291 inc_txqtail(priv);
292
293 return 0;
294}
295
296/* write data */
297static int write_to_device(struct ks_wlan_private *priv, unsigned char *buffer,
298 unsigned long size)
299{
300 int rc, retval;
301 unsigned char rw_data;
302 struct hostif_hdr *hdr;
303 hdr = (struct hostif_hdr *)buffer;
304 rc = 0;
305
306 DPRINTK(4, "size=%d\n", hdr->size);
307 if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
308 DPRINTK(1, "unknown event=%04X\n", hdr->event);
309 return 0;
310 }
311
312 retval = ks7010_sdio_write(priv, DATA_WINDOW, buffer, size);
313 if (retval) {
314 DPRINTK(1, " write error : retval=%d\n", retval);
315 return -4;
316 }
317
318 rw_data = WRITE_STATUS_BUSY;
319 retval =
320 ks7010_sdio_write(priv, WRITE_STATUS, &rw_data, sizeof(rw_data));
321 if (retval) {
322 DPRINTK(1, " error : WRITE_STATUS=%02X\n", rw_data);
323 return -3;
324 }
325
326 return 0;
327}
328
329static void tx_device_task(void *dev)
330{
331 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
332 struct tx_device_buffer *sp;
333 int rc = 0;
334
335 DPRINTK(4, "\n");
336 if (cnt_txqbody(priv) > 0
337 && atomic_read(&priv->psstatus.status) != PS_SNOOZE) {
338 sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
339 if (priv->dev_state >= DEVICE_STATE_BOOT) {
340 rc = write_to_device(priv, sp->sendp, sp->size);
341 if (rc) {
342 DPRINTK(1, "write_to_device error !!(%d)\n",
343 rc);
344 queue_delayed_work(priv->ks_wlan_hw.
345 ks7010sdio_wq,
346 &priv->ks_wlan_hw.rw_wq, 1);
347 return;
348 }
349
350 }
351 kfree(sp->sendp); /* allocated memory free */
352 if (sp->complete_handler != NULL) /* TX Complete */
353 (*sp->complete_handler) (sp->arg1, sp->arg2);
354 inc_txqhead(priv);
355
356 if (cnt_txqbody(priv) > 0) {
357 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
358 &priv->ks_wlan_hw.rw_wq, 0);
359 }
360 }
361 return;
362}
363
364int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p, unsigned long size,
365 void (*complete_handler) (void *arg1, void *arg2),
366 void *arg1, void *arg2)
367{
368 int result = 0;
369 struct hostif_hdr *hdr;
370 hdr = (struct hostif_hdr *)p;
371
372 if (hdr->event < HIF_DATA_REQ || HIF_REQ_MAX < hdr->event) {
373 DPRINTK(1, "unknown event=%04X\n", hdr->event);
374 return 0;
375 }
376
377 /* add event to hostt buffer */
378 priv->hostt.buff[priv->hostt.qtail] = hdr->event;
379 priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
380
381 DPRINTK(4, "event=%04X\n", hdr->event);
382 spin_lock(&priv->tx_dev.tx_dev_lock);
383 result = enqueue_txdev(priv, p, size, complete_handler, arg1, arg2);
384 spin_unlock(&priv->tx_dev.tx_dev_lock);
385
386 if (cnt_txqbody(priv) > 0) {
387 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
388 &priv->ks_wlan_hw.rw_wq, 0);
389 }
390 return result;
391}
392
393static void rx_event_task(unsigned long dev)
394{
395 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
396 struct rx_device_buffer *rp;
397
398 DPRINTK(4, "\n");
399
400 if (cnt_rxqbody(priv) > 0 && priv->dev_state >= DEVICE_STATE_BOOT) {
401 rp = &priv->rx_dev.rx_dev_buff[priv->rx_dev.qhead];
402 hostif_receive(priv, rp->data, rp->size);
403 inc_rxqhead(priv);
404
405 if (cnt_rxqbody(priv) > 0) {
406 tasklet_schedule(&priv->ks_wlan_hw.rx_bh_task);
407 }
408 }
409
410 return;
411}
412
413static void ks_wlan_hw_rx(void *dev, uint16_t size)
414{
415 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
416 int retval;
417 struct rx_device_buffer *rx_buffer;
418 struct hostif_hdr *hdr;
419 unsigned char read_status;
420 unsigned short event = 0;
421
422 DPRINTK(4, "\n");
423
424 /* receive data */
425 if (cnt_rxqbody(priv) >= (RX_DEVICE_BUFF_SIZE - 1)) {
426 /* in case of buffer overflow */
427 DPRINTK(1, "rx buffer overflow \n");
428 goto error_out;
429 }
430 rx_buffer = &priv->rx_dev.rx_dev_buff[priv->rx_dev.qtail];
431
432 retval =
433 ks7010_sdio_read(priv, DATA_WINDOW, &rx_buffer->data[0],
434 hif_align_size(size));
435 if (retval) {
436 goto error_out;
437 }
438
439 /* length check */
440 if (size > 2046 || size == 0) {
441#ifdef KS_WLAN_DEBUG
442 if (KS_WLAN_DEBUG > 5)
443 print_hex_dump_bytes("INVALID DATA dump: ",
444 DUMP_PREFIX_OFFSET,
445 rx_buffer->data, 32);
446#endif
447 /* rx_status update */
448 read_status = READ_STATUS_IDLE;
449 retval =
450 ks7010_sdio_write(priv, READ_STATUS, &read_status,
451 sizeof(read_status));
452 if (retval) {
453 DPRINTK(1, " error : READ_STATUS=%02X\n", read_status);
454 }
455 goto error_out;
456 }
457
458 hdr = (struct hostif_hdr *)&rx_buffer->data[0];
459 rx_buffer->size = le16_to_cpu(hdr->size) + sizeof(hdr->size);
460 event = hdr->event;
461 inc_rxqtail(priv);
462
463 /* read status update */
464 read_status = READ_STATUS_IDLE;
465 retval =
466 ks7010_sdio_write(priv, READ_STATUS, &read_status,
467 sizeof(read_status));
468 if (retval) {
469 DPRINTK(1, " error : READ_STATUS=%02X\n", read_status);
470 }
471 DPRINTK(4, "READ_STATUS=%02X\n", read_status);
472
473 if (atomic_read(&priv->psstatus.confirm_wait)) {
474 if (IS_HIF_CONF(event)) {
475 DPRINTK(4, "IS_HIF_CONF true !!\n");
476 atomic_dec(&priv->psstatus.confirm_wait);
477 }
478 }
479
480 /* rx_event_task((void *)priv); */
481 tasklet_schedule(&priv->ks_wlan_hw.rx_bh_task);
482
483 error_out:
484 return;
485}
486
487static void ks7010_rw_function(struct work_struct *work)
488{
489 struct hw_info_t *hw;
490 struct ks_wlan_private *priv;
491 unsigned char rw_data;
492 int retval;
493
494 hw = container_of(work, struct hw_info_t, rw_wq.work);
495 priv = container_of(hw, struct ks_wlan_private, ks_wlan_hw);
496
497 DPRINTK(4, "\n");
498
499 /* wiat after DOZE */
500 if (time_after(priv->last_doze + ((30 * HZ) / 1000), jiffies)) {
501 DPRINTK(4, "wait after DOZE \n");
502 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
503 &priv->ks_wlan_hw.rw_wq, 1);
504 return;
505 }
506
507 /* wiat after WAKEUP */
508 while (time_after(priv->last_wakeup + ((30 * HZ) / 1000), jiffies)) {
509 DPRINTK(4, "wait after WAKEUP \n");
510/* queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,&priv->ks_wlan_hw.rw_wq,
511 (priv->last_wakeup + ((30*HZ)/1000) - jiffies));*/
512 printk("wake: %lu %lu\n", priv->last_wakeup + (30 * HZ) / 1000,
513 jiffies);
514 msleep(30);
515 }
516
517 sdio_claim_host(priv->ks_wlan_hw.sdio_card->func);
518
519 /* power save wakeup */
520 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) {
521 if (cnt_txqbody(priv) > 0) {
522 ks_wlan_hw_wakeup_request(priv);
523 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
524 &priv->ks_wlan_hw.rw_wq, 1);
525 }
526 goto err_out;
527 }
528
529 /* sleep mode doze */
530 if (atomic_read(&priv->sleepstatus.doze_request) == 1) {
531 ks_wlan_hw_sleep_doze_request(priv);
532 goto err_out;
533 }
534 /* sleep mode wakeup */
535 if (atomic_read(&priv->sleepstatus.wakeup_request) == 1) {
536 ks_wlan_hw_sleep_wakeup_request(priv);
537 goto err_out;
538 }
539
540 /* read (WriteStatus/ReadDataSize FN1:00_0014) */
541 retval =
542 ks7010_sdio_read(priv, WSTATUS_RSIZE, &rw_data, sizeof(rw_data));
543 if (retval) {
544 DPRINTK(1, " error : WSTATUS_RSIZE=%02X psstatus=%d\n", rw_data,
545 atomic_read(&priv->psstatus.status));
546 goto err_out;
547 }
548 DPRINTK(4, "WSTATUS_RSIZE=%02X\n", rw_data);
549
550 if (rw_data & RSIZE_MASK) { /* Read schedule */
551 ks_wlan_hw_rx((void *)priv,
552 (uint16_t) (((rw_data & RSIZE_MASK) << 4)));
553 }
554 if ((rw_data & WSTATUS_MASK)) {
555 tx_device_task((void *)priv);
556 }
557 _ks_wlan_hw_power_save(priv);
558
559 err_out:
560 sdio_release_host(priv->ks_wlan_hw.sdio_card->func);
561
562 return;
563}
564
565static void ks_sdio_interrupt(struct sdio_func *func)
566{
567 int retval;
568 struct ks_sdio_card *card;
569 struct ks_wlan_private *priv;
570 unsigned char status, rsize, rw_data;
571
572 card = sdio_get_drvdata(func);
573 priv = card->priv;
574 DPRINTK(4, "\n");
575
576 if (priv->dev_state >= DEVICE_STATE_BOOT) {
577 retval =
578 ks7010_sdio_read(priv, INT_PENDING, &status,
579 sizeof(status));
580 if (retval) {
581 DPRINTK(1, "read INT_PENDING Failed!!(%d)\n", retval);
582 goto intr_out;
583 }
584 DPRINTK(4, "INT_PENDING=%02X\n", rw_data);
585
586 /* schedule task for interrupt status */
587 /* bit7 -> Write General Communication B register */
588 /* read (General Communication B register) */
589 /* bit5 -> Write Status Idle */
590 /* bit2 -> Read Status Busy */
591 if (status & INT_GCR_B
592 || atomic_read(&priv->psstatus.status) == PS_SNOOZE) {
593 retval =
594 ks7010_sdio_read(priv, GCR_B, &rw_data,
595 sizeof(rw_data));
596 if (retval) {
597 DPRINTK(1, " error : GCR_B=%02X\n", rw_data);
598 goto intr_out;
599 }
600 /* DPRINTK(1, "GCR_B=%02X\n", rw_data); */
601 if (rw_data == GCR_B_ACTIVE) {
602 if (atomic_read(&priv->psstatus.status) ==
603 PS_SNOOZE) {
604 atomic_set(&priv->psstatus.status,
605 PS_WAKEUP);
606 priv->wakeup_count = 0;
607 }
608 complete(&priv->psstatus.wakeup_wait);
609 }
610
611 }
612
613 do {
614 /* read (WriteStatus/ReadDataSize FN1:00_0014) */
615 retval =
616 ks7010_sdio_read(priv, WSTATUS_RSIZE, &rw_data,
617 sizeof(rw_data));
618 if (retval) {
619 DPRINTK(1, " error : WSTATUS_RSIZE=%02X\n",
620 rw_data);
621 goto intr_out;
622 }
623 DPRINTK(4, "WSTATUS_RSIZE=%02X\n", rw_data);
624 rsize = rw_data & RSIZE_MASK;
625 if (rsize) { /* Read schedule */
626 ks_wlan_hw_rx((void *)priv,
627 (uint16_t) (((rsize) << 4)));
628 }
629 if (rw_data & WSTATUS_MASK) {
630#if 0
631 if (status & INT_WRITE_STATUS
632 && !cnt_txqbody(priv)) {
633 /* dummy write for interrupt clear */
634 rw_data = 0;
635 retval =
636 ks7010_sdio_write(priv, DATA_WINDOW,
637 &rw_data,
638 sizeof(rw_data));
639 if (retval) {
640 DPRINTK(1,
641 "write DATA_WINDOW Failed!!(%d)\n",
642 retval);
643 }
644 status &= ~INT_WRITE_STATUS;
645 } else {
646#endif
647 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) {
648 if (cnt_txqbody(priv)) {
649 ks_wlan_hw_wakeup_request(priv);
650 queue_delayed_work
651 (priv->ks_wlan_hw.
652 ks7010sdio_wq,
653 &priv->ks_wlan_hw.
654 rw_wq, 1);
655 return;
656 }
657 } else {
658 tx_device_task((void *)priv);
659 }
660#if 0
661 }
662#endif
663 }
664 } while (rsize);
665 }
666
667 intr_out:
668 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
669 &priv->ks_wlan_hw.rw_wq, 0);
670 return;
671}
672
673static int trx_device_init(struct ks_wlan_private *priv)
674{
675 /* initialize values (tx) */
676 priv->tx_dev.qtail = priv->tx_dev.qhead = 0;
677
678 /* initialize values (rx) */
679 priv->rx_dev.qtail = priv->rx_dev.qhead = 0;
680
681 /* initialize spinLock (tx,rx) */
682 spin_lock_init(&priv->tx_dev.tx_dev_lock);
683 spin_lock_init(&priv->rx_dev.rx_dev_lock);
684
685 tasklet_init(&priv->ks_wlan_hw.rx_bh_task, rx_event_task,
686 (unsigned long)priv);
687
688 return 0;
689}
690
691static void trx_device_exit(struct ks_wlan_private *priv)
692{
693 struct tx_device_buffer *sp;
694
695 /* tx buffer clear */
696 while (cnt_txqbody(priv) > 0) {
697 sp = &priv->tx_dev.tx_dev_buff[priv->tx_dev.qhead];
698 kfree(sp->sendp); /* allocated memory free */
699 if (sp->complete_handler != NULL) /* TX Complete */
700 (*sp->complete_handler) (sp->arg1, sp->arg2);
701 inc_txqhead(priv);
702 }
703
704 tasklet_kill(&priv->ks_wlan_hw.rx_bh_task);
705
706 return;
707}
708
709static int ks7010_sdio_update_index(struct ks_wlan_private *priv, u32 index)
710{
711 int rc = 0;
712 int retval;
713 unsigned char *data_buf;
714 data_buf = NULL;
715
716 data_buf = kmalloc(sizeof(u32), GFP_KERNEL);
717 if (!data_buf) {
718 rc = 1;
719 goto error_out;
720 }
721
722 memcpy(data_buf, &index, sizeof(index));
723 retval = ks7010_sdio_write(priv, WRITE_INDEX, data_buf, sizeof(index));
724 if (retval) {
725 rc = 2;
726 goto error_out;
727 }
728
729 retval = ks7010_sdio_write(priv, READ_INDEX, data_buf, sizeof(index));
730 if (retval) {
731 rc = 3;
732 goto error_out;
733 }
734 error_out:
735 if (data_buf)
736 kfree(data_buf);
737 return rc;
738}
739
740#define ROM_BUFF_SIZE (64*1024)
741static int ks7010_sdio_data_compare(struct ks_wlan_private *priv, u32 address,
742 unsigned char *data, unsigned int size)
743{
744 int rc = 0;
745 int retval;
746 unsigned char *read_buf;
747 read_buf = NULL;
748 read_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
749 if (!read_buf) {
750 rc = 1;
751 goto error_out;
752 }
753 retval = ks7010_sdio_read(priv, address, read_buf, size);
754 if (retval) {
755 rc = 2;
756 goto error_out;
757 }
758 retval = memcmp(data, read_buf, size);
759
760 if (retval) {
761 DPRINTK(0, "data compare error (%d) \n", retval);
762 rc = 3;
763 goto error_out;
764 }
765 error_out:
766 if (read_buf)
767 kfree(read_buf);
768 return rc;
769}
770
771static int ks7010_upload_firmware(struct ks_wlan_private *priv,
772 struct ks_sdio_card *card)
773{
774 unsigned int size, offset, n = 0;
775 unsigned char *rom_buf;
776 unsigned char rw_data = 0;
777 int retval, rc = 0;
778 int length;
779 const struct firmware *fw_entry = NULL;
780
781 rom_buf = NULL;
782
783 /* buffer allocate */
784 rom_buf = kmalloc(ROM_BUFF_SIZE, GFP_KERNEL);
785 if (!rom_buf) {
786 rc = 3;
787 goto error_out0;
788 }
789
790 sdio_claim_host(card->func);
791
792 /* Firmware running ? */
793 retval = ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
794 if (rw_data == GCR_A_RUN) {
795 DPRINTK(0, "MAC firmware running ...\n");
796 rc = 0;
797 goto error_out0;
798 }
799
800 retval = request_firmware(&fw_entry, ROM_FILE, &priv->ks_wlan_hw.sdio_card->func->dev);
801 if (retval)
802 return retval;
803
804 length = fw_entry->size;
805
806 /* Load Program */
807 n = 0;
808 do {
809 if (length >= ROM_BUFF_SIZE) {
810 size = ROM_BUFF_SIZE;
811 length = length - ROM_BUFF_SIZE;
812 } else {
813 size = length;
814 length = 0;
815 }
816 DPRINTK(4, "size = %d\n", size);
817 if (size == 0)
818 break;
819 memcpy(rom_buf, fw_entry->data + n, size);
820 /* Update write index */
821 offset = n;
822 retval =
823 ks7010_sdio_update_index(priv,
824 KS7010_IRAM_ADDRESS + offset);
825 if (retval) {
826 rc = 6;
827 goto error_out1;
828 }
829
830 /* Write data */
831 retval = ks7010_sdio_write(priv, DATA_WINDOW, rom_buf, size);
832 if (retval) {
833 rc = 8;
834 goto error_out1;
835 }
836
837 /* compare */
838 retval =
839 ks7010_sdio_data_compare(priv, DATA_WINDOW, rom_buf, size);
840 if (retval) {
841 rc = 9;
842 goto error_out1;
843 }
844 n += size;
845
846 } while (size);
847
848 /* Remap request */
849 rw_data = GCR_A_REMAP;
850 retval = ks7010_sdio_write(priv, GCR_A, &rw_data, sizeof(rw_data));
851 if (retval) {
852 rc = 11;
853 goto error_out1;
854 }
855 DPRINTK(4, " REMAP Request : GCR_A=%02X\n", rw_data);
856
857 /* Firmware running check */
858 for (n = 0; n < 50; ++n) {
859 mdelay(10); /* wait_ms(10); */
860 retval =
861 ks7010_sdio_read(priv, GCR_A, &rw_data, sizeof(rw_data));
862 if (retval) {
863 rc = 11;
864 goto error_out1;
865 }
866 if (rw_data == GCR_A_RUN)
867 break;
868 }
869 DPRINTK(4, "firmware wakeup (%d)!!!!\n", n);
870 if ((50) <= n) {
871 DPRINTK(1, "firmware can't start\n");
872 rc = 12;
873 goto error_out1;
874 }
875
876 rc = 0;
877
878 error_out1:
879 release_firmware(fw_entry);
880 error_out0:
881 sdio_release_host(card->func);
882 if (rom_buf)
883 kfree(rom_buf);
884 return rc;
885}
886
887static void ks7010_card_init(struct ks_wlan_private *priv)
888{
889 DPRINTK(5, "\ncard_init_task()\n");
890
891 /* init_waitqueue_head(&priv->confirm_wait); */
892 init_completion(&priv->confirm_wait);
893
894 DPRINTK(5, "init_completion()\n");
895
896 /* get mac address & firmware version */
897 hostif_sme_enqueue(priv, SME_START);
898
899 DPRINTK(5, "hostif_sme_enqueu()\n");
900
901 if (!wait_for_completion_interruptible_timeout
902 (&priv->confirm_wait, 5 * HZ)) {
903 DPRINTK(1, "wait time out!! SME_START\n");
904 }
905
906 if (priv->mac_address_valid && priv->version_size) {
907 priv->dev_state = DEVICE_STATE_PREINIT;
908 }
909
910 hostif_sme_enqueue(priv, SME_GET_EEPROM_CKSUM);
911
912 /* load initial wireless parameter */
913 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
914
915 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
916 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
917
918 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
919 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
920 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
921 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
922 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
923
924 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
925 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
926 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
927 hostif_sme_enqueue(priv, SME_START_REQUEST);
928
929 if (!wait_for_completion_interruptible_timeout
930 (&priv->confirm_wait, 5 * HZ)) {
931 DPRINTK(1, "wait time out!! wireless parameter set\n");
932 }
933
934 if (priv->dev_state >= DEVICE_STATE_PREINIT) {
935 DPRINTK(1, "DEVICE READY!!\n");
936 priv->dev_state = DEVICE_STATE_READY;
937 } else {
938 DPRINTK(1, "dev_state=%d\n", priv->dev_state);
939 }
940}
941
942static void ks7010_init_defaults(struct ks_wlan_private *priv)
943{
944 priv->reg.tx_rate = TX_RATE_AUTO;
945 priv->reg.preamble = LONG_PREAMBLE;
946 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
947 priv->reg.scan_type = ACTIVE_SCAN;
948 priv->reg.beacon_lost_count = 20;
949 priv->reg.rts = 2347UL;
950 priv->reg.fragment = 2346UL;
951 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
952 priv->reg.cts_mode = CTS_MODE_FALSE;
953 priv->reg.rate_set.body[11] = TX_RATE_54M;
954 priv->reg.rate_set.body[10] = TX_RATE_48M;
955 priv->reg.rate_set.body[9] = TX_RATE_36M;
956 priv->reg.rate_set.body[8] = TX_RATE_18M;
957 priv->reg.rate_set.body[7] = TX_RATE_9M;
958 priv->reg.rate_set.body[6] = TX_RATE_24M | BASIC_RATE;
959 priv->reg.rate_set.body[5] = TX_RATE_12M | BASIC_RATE;
960 priv->reg.rate_set.body[4] = TX_RATE_6M | BASIC_RATE;
961 priv->reg.rate_set.body[3] = TX_RATE_11M | BASIC_RATE;
962 priv->reg.rate_set.body[2] = TX_RATE_5M | BASIC_RATE;
963 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
964 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
965 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
966 priv->reg.rate_set.size = 12;
967}
968
969static int ks7010_sdio_probe(struct sdio_func *func,
970 const struct sdio_device_id *device)
971{
972 struct ks_wlan_private *priv;
973 struct ks_sdio_card *card;
974 struct net_device *netdev;
975 unsigned char rw_data;
976 int ret;
977
978 DPRINTK(5, "ks7010_sdio_probe()\n");
979
980 priv = NULL;
981 netdev = NULL;
982
983 /* initilize ks_sdio_card */
984 card = kzalloc(sizeof(struct ks_sdio_card), GFP_KERNEL);
985 if (!card)
986 return -ENOMEM;
987
988 card->func = func;
989 spin_lock_init(&card->lock);
990
991 /*** Initialize SDIO ***/
992 sdio_claim_host(func);
993
994 /* bus setting */
995 /* Issue config request to override clock rate */
996
997 /* function blocksize set */
998 ret = sdio_set_block_size(func, KS7010_IO_BLOCK_SIZE);
999 DPRINTK(5, "multi_block=%d sdio_set_block_size()=%d %d\n",
1000 func->card->cccr.multi_block, func->cur_blksize, ret);
1001
1002 /* Allocate the slot current */
1003
1004 /* function enable */
1005 ret = sdio_enable_func(func);
1006 DPRINTK(5, "sdio_enable_func() %d\n", ret);
1007 if (ret)
1008 goto error_free_card;
1009
1010 /* interrupt disable */
1011 sdio_writeb(func, 0, INT_ENABLE, &ret);
1012 if (ret)
1013 goto error_free_card;
1014 sdio_writeb(func, 0xff, INT_PENDING, &ret);
1015 if (ret)
1016 goto error_disable_func;
1017
1018 /* setup interrupt handler */
1019 ret = sdio_claim_irq(func, ks_sdio_interrupt);
1020 if (ret)
1021 goto error_disable_func;
1022
1023 sdio_release_host(func);
1024
1025 sdio_set_drvdata(func, card);
1026
1027 DPRINTK(5, "class = 0x%X, vendor = 0x%X, "
1028 "device = 0x%X\n", func->class, func->vendor, func->device);
1029
1030 /* private memory allocate */
1031 netdev = alloc_etherdev(sizeof(*priv));
1032 if (netdev == NULL) {
1033 printk(KERN_ERR "ks7010 : Unable to alloc new net device\n");
1034 goto error_release_irq;
1035 }
1036 if (dev_alloc_name(netdev, "wlan%d") < 0) {
1037 printk(KERN_ERR "ks7010 : Couldn't get name!\n");
1038 goto error_free_netdev;
1039 }
1040
1041 priv = netdev_priv(netdev);
1042
1043 card->priv = priv;
1044 SET_NETDEV_DEV(netdev, &card->func->dev); /* for create sysfs symlinks */
1045
1046 /* private memory initialize */
1047 priv->ks_wlan_hw.sdio_card = card;
1048 init_completion(&priv->ks_wlan_hw.ks7010_sdio_wait);
1049 priv->ks_wlan_hw.read_buf = NULL;
1050 priv->ks_wlan_hw.read_buf = kmalloc(RX_DATA_SIZE, GFP_KERNEL);
1051 if (!priv->ks_wlan_hw.read_buf) {
1052 goto error_free_netdev;
1053 }
1054 priv->dev_state = DEVICE_STATE_PREBOOT;
1055 priv->net_dev = netdev;
1056 priv->firmware_version[0] = '\0';
1057 priv->version_size = 0;
1058 priv->last_doze = jiffies; /* set current jiffies */
1059 priv->last_wakeup = jiffies;
1060 memset(&priv->nstats, 0, sizeof(priv->nstats));
1061 memset(&priv->wstats, 0, sizeof(priv->wstats));
1062
1063 /* sleep mode */
1064 atomic_set(&priv->sleepstatus.doze_request, 0);
1065 atomic_set(&priv->sleepstatus.wakeup_request, 0);
1066 atomic_set(&priv->sleepstatus.wakeup_request, 0);
1067
1068 trx_device_init(priv);
1069 hostif_init(priv);
1070 ks_wlan_net_start(netdev);
1071
1072 ks7010_init_defaults(priv);
1073
1074 /* Upload firmware */
1075 ret = ks7010_upload_firmware(priv, card); /* firmware load */
1076 if (ret) {
1077 printk(KERN_ERR
1078 "ks7010: firmware load failed !! retern code = %d\n",
1079 ret);
1080 goto error_free_read_buf;
1081 }
1082
1083 /* interrupt setting */
1084 /* clear Interrupt status write (ARMtoSD_InterruptPending FN1:00_0024) */
1085 rw_data = 0xff;
1086 sdio_claim_host(func);
1087 ret = ks7010_sdio_write(priv, INT_PENDING, &rw_data, sizeof(rw_data));
1088 sdio_release_host(func);
1089 if (ret) {
1090 DPRINTK(1, " error : INT_PENDING=%02X\n", rw_data);
1091 }
1092 DPRINTK(4, " clear Interrupt : INT_PENDING=%02X\n", rw_data);
1093
1094 /* enable ks7010sdio interrupt (INT_GCR_B|INT_READ_STATUS|INT_WRITE_STATUS) */
1095 rw_data = (INT_GCR_B | INT_READ_STATUS | INT_WRITE_STATUS);
1096 sdio_claim_host(func);
1097 ret = ks7010_sdio_write(priv, INT_ENABLE, &rw_data, sizeof(rw_data));
1098 sdio_release_host(func);
1099 if (ret) {
1100 DPRINTK(1, " error : INT_ENABLE=%02X\n", rw_data);
1101 }
1102 DPRINTK(4, " enable Interrupt : INT_ENABLE=%02X\n", rw_data);
1103 priv->dev_state = DEVICE_STATE_BOOT;
1104
1105 priv->ks_wlan_hw.ks7010sdio_wq = create_workqueue("ks7010sdio_wq");
1106 if (!priv->ks_wlan_hw.ks7010sdio_wq) {
1107 DPRINTK(1, "create_workqueue failed !!\n");
1108 goto error_free_read_buf;
1109 }
1110
1111 INIT_DELAYED_WORK(&priv->ks_wlan_hw.rw_wq, ks7010_rw_function);
1112 ks7010_card_init(priv);
1113
1114 ret = register_netdev(priv->net_dev);
1115 if (ret)
1116 goto error_free_read_buf;
1117
1118 return 0;
1119
1120 error_free_read_buf:
1121 kfree(priv->ks_wlan_hw.read_buf);
1122 priv->ks_wlan_hw.read_buf = NULL;
1123 error_free_netdev:
1124 free_netdev(priv->net_dev);
1125 card->priv = NULL;
1126 error_release_irq:
1127 sdio_claim_host(func);
1128 sdio_release_irq(func);
1129 error_disable_func:
1130 sdio_disable_func(func);
1131 error_free_card:
1132 sdio_release_host(func);
1133 sdio_set_drvdata(func, NULL);
1134 kfree(card);
1135
1136 return -ENODEV;
1137}
1138
1139static void ks7010_sdio_remove(struct sdio_func *func)
1140{
1141 int ret;
1142 struct ks_sdio_card *card;
1143 struct ks_wlan_private *priv;
1144 struct net_device *netdev;
1145 DPRINTK(1, "ks7010_sdio_remove()\n");
1146
1147 card = sdio_get_drvdata(func);
1148
1149 if (card == NULL)
1150 return;
1151
1152 DPRINTK(1, "priv = card->priv\n");
1153 priv = card->priv;
1154 netdev = priv->net_dev;
1155 if (priv) {
1156 ks_wlan_net_stop(netdev);
1157 DPRINTK(1, "ks_wlan_net_stop\n");
1158
1159 /* interrupt disable */
1160 sdio_claim_host(func);
1161 sdio_writeb(func, 0, INT_ENABLE, &ret);
1162 sdio_writeb(func, 0xff, INT_PENDING, &ret);
1163 sdio_release_host(func);
1164 DPRINTK(1, "interrupt disable\n");
1165
1166 /* send stop request to MAC */
1167 {
1168 struct hostif_stop_request_t *pp;
1169 pp = (struct hostif_stop_request_t *)
1170 kzalloc(hif_align_size(sizeof(*pp)), GFP_KERNEL);
1171 if (pp == NULL) {
1172 DPRINTK(3, "allocate memory failed..\n");
1173 return; /* to do goto ni suru */
1174 }
1175 pp->header.size =
1176 cpu_to_le16((uint16_t)
1177 (sizeof(*pp) -
1178 sizeof(pp->header.size)));
1179 pp->header.event = cpu_to_le16((uint16_t) HIF_STOP_REQ);
1180
1181 sdio_claim_host(func);
1182 write_to_device(priv, (unsigned char *)pp,
1183 hif_align_size(sizeof(*pp)));
1184 sdio_release_host(func);
1185 kfree(pp);
1186 }
1187 DPRINTK(1, "STOP Req\n");
1188
1189 if (priv->ks_wlan_hw.ks7010sdio_wq) {
1190 flush_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1191 destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);
1192 }
1193 DPRINTK(1,
1194 "destroy_workqueue(priv->ks_wlan_hw.ks7010sdio_wq);\n");
1195
1196 hostif_exit(priv);
1197 DPRINTK(1, "hostif_exit\n");
1198
1199 unregister_netdev(netdev);
1200
1201 trx_device_exit(priv);
1202 if (priv->ks_wlan_hw.read_buf) {
1203 kfree(priv->ks_wlan_hw.read_buf);
1204 }
1205 free_netdev(priv->net_dev);
1206 card->priv = NULL;
1207 }
1208
1209 sdio_claim_host(func);
1210 sdio_release_irq(func);
1211 DPRINTK(1, "sdio_release_irq()\n");
1212 sdio_disable_func(func);
1213 DPRINTK(1, "sdio_disable_func()\n");
1214 sdio_release_host(func);
1215
1216 sdio_set_drvdata(func, NULL);
1217
1218 kfree(card);
1219 DPRINTK(1, "kfree()\n");
1220
1221 DPRINTK(5, " Bye !!\n");
1222 return;
1223}
1224
1225static struct sdio_driver ks7010_sdio_driver = {
1226 .name = "ks7010_sdio",
1227 .id_table = ks7010_sdio_ids,
1228 .probe = ks7010_sdio_probe,
1229 .remove = ks7010_sdio_remove,
1230};
1231
1232module_driver(ks7010_sdio_driver, sdio_register_driver, sdio_unregister_driver);
1233MODULE_AUTHOR("Sang Engineering, Qi-Hardware, KeyStream");
1234MODULE_DESCRIPTION("Driver for KeyStream KS7010 based SDIO cards");
1235MODULE_LICENSE("GPL v2");
1236MODULE_FIRMWARE(ROM_FILE);
diff --git a/drivers/staging/ks7010/ks7010_sdio.h b/drivers/staging/ks7010/ks7010_sdio.h
new file mode 100644
index 000000000000..c72064b48bd8
--- /dev/null
+++ b/drivers/staging/ks7010/ks7010_sdio.h
@@ -0,0 +1,147 @@
1/*
2 * Driver for KeyStream, KS7010 based SDIO cards.
3 *
4 * Copyright (C) 2006-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _KS7010_SDIO_H
12#define _KS7010_SDIO_H
13
14#ifdef DEVICE_ALIGNMENT
15#undef DEVICE_ALIGNMENT
16#endif
17#define DEVICE_ALIGNMENT 32
18
19/* SDIO KeyStream vendor and device */
20#define SDIO_VENDOR_ID_KS_CODE_A 0x005b
21#define SDIO_VENDOR_ID_KS_CODE_B 0x0023
22/* Older sources suggest earlier versions were named 7910 or 79xx */
23#define SDIO_DEVICE_ID_KS_7010 0x7910
24
25/* Read Status Register */
26#define READ_STATUS 0x000000
27#define READ_STATUS_BUSY 0
28#define READ_STATUS_IDLE 1
29
30/* Read Index Register */
31#define READ_INDEX 0x000004
32
33/* Read Data Size Register */
34#define READ_DATA_SIZE 0x000008
35
36/* Write Status Register */
37#define WRITE_STATUS 0x00000C
38#define WRITE_STATUS_BUSY 0
39#define WRITE_STATUS_IDLE 1
40
41/* Write Index Register */
42#define WRITE_INDEX 0x000010
43
44/* Write Status/Read Data Size Register
45 * for network packet (less than 2048 bytes data)
46 */
47#define WSTATUS_RSIZE 0x000014
48#define WSTATUS_MASK 0x80 /* Write Status Register value */
49#define RSIZE_MASK 0x7F /* Read Data Size Register value [10:4] */
50
51/* ARM to SD interrupt Enable */
52#define INT_ENABLE 0x000020
53/* ARM to SD interrupt Pending */
54#define INT_PENDING 0x000024
55
56#define INT_GCR_B (1<<7)
57#define INT_GCR_A (1<<6)
58#define INT_WRITE_STATUS (1<<5)
59#define INT_WRITE_INDEX (1<<4)
60#define INT_WRITE_SIZE (1<<3)
61#define INT_READ_STATUS (1<<2)
62#define INT_READ_INDEX (1<<1)
63#define INT_READ_SIZE (1<<0)
64
65/* General Communication Register A */
66#define GCR_A 0x000028
67#define GCR_A_INIT 0
68#define GCR_A_REMAP 1
69#define GCR_A_RUN 2
70
71/* General Communication Register B */
72#define GCR_B 0x00002C
73#define GCR_B_ACTIVE 0
74#define GCR_B_DOZE 1
75
76/* Wakeup Register */
77/* #define WAKEUP 0x008104 */
78/* #define WAKEUP_REQ 0x00 */
79#define WAKEUP 0x008018
80#define WAKEUP_REQ 0x5a
81
82/* AHB Data Window 0x010000-0x01FFFF */
83#define DATA_WINDOW 0x010000
84#define WINDOW_SIZE 64*1024
85
86#define KS7010_IRAM_ADDRESS 0x06000000
87
88/*
89 * struct define
90 */
91struct hw_info_t {
92 struct ks_sdio_card *sdio_card;
93 struct completion ks7010_sdio_wait;
94 struct workqueue_struct *ks7010sdio_wq;
95 struct delayed_work rw_wq;
96 unsigned char *read_buf;
97 struct tasklet_struct rx_bh_task;
98};
99
100struct ks_sdio_packet {
101 struct ks_sdio_packet *next;
102 u16 nb;
103 u8 buffer[0] __attribute__ ((aligned(4)));
104};
105
106struct ks_sdio_card {
107 struct sdio_func *func;
108 struct ks_wlan_private *priv;
109 spinlock_t lock;
110};
111
112/* Tx Device struct */
113#define TX_DEVICE_BUFF_SIZE 1024
114
115struct tx_device_buffer {
116 unsigned char *sendp; /* pointer of send req data */
117 unsigned int size;
118 void (*complete_handler) (void *arg1, void *arg2);
119 void *arg1;
120 void *arg2;
121};
122
123struct tx_device {
124 struct tx_device_buffer tx_dev_buff[TX_DEVICE_BUFF_SIZE];
125 unsigned int qhead; /* tx buffer queue first pointer */
126 unsigned int qtail; /* tx buffer queue last pointer */
127 spinlock_t tx_dev_lock;
128};
129
130/* Rx Device struct */
131#define RX_DATA_SIZE (2 + 2 + 2347 + 1)
132#define RX_DEVICE_BUFF_SIZE 32
133
134struct rx_device_buffer {
135 unsigned char data[RX_DATA_SIZE];
136 unsigned int size;
137};
138
139struct rx_device {
140 struct rx_device_buffer rx_dev_buff[RX_DEVICE_BUFF_SIZE];
141 unsigned int qhead; /* rx buffer queue first pointer */
142 unsigned int qtail; /* rx buffer queue last pointer */
143 spinlock_t rx_dev_lock;
144};
145#define ROM_FILE "ks7010sd.rom"
146
147#endif /* _KS7010_SDIO_H */
diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c
new file mode 100644
index 000000000000..a8822fe2bd60
--- /dev/null
+++ b/drivers/staging/ks7010/ks_hostif.c
@@ -0,0 +1,2760 @@
1/*
2 * Driver for KeyStream wireless LAN cards.
3 *
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include "ks_wlan.h"
13#include "ks_hostif.h"
14#include "eap_packet.h"
15#include "michael_mic.h"
16
17#include <linux/if_ether.h>
18#include <linux/if_arp.h>
19
20/* Include Wireless Extension definition and check version */
21#include <net/iw_handler.h> /* New driver API */
22
23extern int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p,
24 unsigned long size,
25 void (*complete_handler) (void *arg1, void *arg2),
26 void *arg1, void *arg2);
27extern void send_packet_complete(void *, void *);
28
29extern void ks_wlan_hw_wakeup_request(struct ks_wlan_private *priv);
30extern int ks_wlan_hw_power_save(struct ks_wlan_private *priv);
31
32/* macro */
33#define inc_smeqhead(priv) \
34 ( priv->sme_i.qhead = (priv->sme_i.qhead + 1) % SME_EVENT_BUFF_SIZE )
35#define inc_smeqtail(priv) \
36 ( priv->sme_i.qtail = (priv->sme_i.qtail + 1) % SME_EVENT_BUFF_SIZE )
37#define cnt_smeqbody(priv) \
38 (((priv->sme_i.qtail + SME_EVENT_BUFF_SIZE) - (priv->sme_i.qhead)) % SME_EVENT_BUFF_SIZE )
39
40#define KS_WLAN_MEM_FLAG (GFP_ATOMIC)
41
42static
43inline u8 get_BYTE(struct ks_wlan_private *priv)
44{
45 u8 data;
46 data = *(priv->rxp)++;
47 /* length check in advance ! */
48 --(priv->rx_size);
49 return data;
50}
51
52static
53inline u16 get_WORD(struct ks_wlan_private *priv)
54{
55 u16 data;
56 data = (get_BYTE(priv) & 0xff);
57 data |= ((get_BYTE(priv) << 8) & 0xff00);
58 return data;
59}
60
61static
62inline u32 get_DWORD(struct ks_wlan_private *priv)
63{
64 u32 data;
65 data = (get_BYTE(priv) & 0xff);
66 data |= ((get_BYTE(priv) << 8) & 0x0000ff00);
67 data |= ((get_BYTE(priv) << 16) & 0x00ff0000);
68 data |= ((get_BYTE(priv) << 24) & 0xff000000);
69 return data;
70}
71
72void ks_wlan_hw_wakeup_task(struct work_struct *work)
73{
74 struct ks_wlan_private *priv =
75 container_of(work, struct ks_wlan_private, ks_wlan_wakeup_task);
76 int ps_status = atomic_read(&priv->psstatus.status);
77
78 if (ps_status == PS_SNOOZE) {
79 ks_wlan_hw_wakeup_request(priv);
80 if (!wait_for_completion_interruptible_timeout(&priv->psstatus.wakeup_wait, HZ / 50)) { /* 20ms timeout */
81 DPRINTK(1, "wake up timeout !!!\n");
82 schedule_work(&priv->ks_wlan_wakeup_task);
83 return;
84 }
85 } else {
86 DPRINTK(1, "ps_status=%d\n", ps_status);
87 }
88
89 /* power save */
90 if (atomic_read(&priv->sme_task.count) > 0) {
91 DPRINTK(4, "sme task enable.\n");
92 tasklet_enable(&priv->sme_task);
93 }
94}
95
96static
97int ks_wlan_do_power_save(struct ks_wlan_private *priv)
98{
99 int rc = 0;
100
101 DPRINTK(4, "psstatus.status=%d\n", atomic_read(&priv->psstatus.status));
102
103 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
104 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
105 } else {
106 priv->dev_state = DEVICE_STATE_READY;
107 }
108 return rc;
109}
110
111static
112int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
113{
114 struct local_ap_t *ap;
115 union iwreq_data wrqu;
116 struct net_device *netdev = priv->net_dev;
117 int rc = 0;
118
119 DPRINTK(3, "\n");
120 ap = &(priv->current_ap);
121
122 if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) {
123 memset(ap, 0, sizeof(struct local_ap_t));
124 return 1;
125 }
126
127 /* bssid */
128 memcpy(&(ap->bssid[0]), &(ap_info->bssid[0]), ETH_ALEN);
129 /* essid */
130 memcpy(&(ap->ssid.body[0]), &(priv->reg.ssid.body[0]),
131 priv->reg.ssid.size);
132 ap->ssid.size = priv->reg.ssid.size;
133 /* rate_set */
134 memcpy(&(ap->rate_set.body[0]), &(ap_info->rate_set.body[0]),
135 ap_info->rate_set.size);
136 ap->rate_set.size = ap_info->rate_set.size;
137 if (ap_info->ext_rate_set.size) {
138 /* rate_set */
139 memcpy(&(ap->rate_set.body[ap->rate_set.size]),
140 &(ap_info->ext_rate_set.body[0]),
141 ap_info->ext_rate_set.size);
142 ap->rate_set.size += ap_info->ext_rate_set.size;
143 }
144 /* channel */
145 ap->channel = ap_info->ds_parameter.channel;
146 /* rssi */
147 ap->rssi = ap_info->rssi;
148 /* sq */
149 ap->sq = ap_info->sq;
150 /* noise */
151 ap->noise = ap_info->noise;
152 /* capability */
153 ap->capability = ap_info->capability;
154 /* rsn */
155 if ((ap_info->rsn_mode & RSN_MODE_WPA2)
156 && (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)) {
157 ap->rsn_ie.id = 0x30;
158 if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
159 ap->rsn_ie.size = ap_info->rsn.size;
160 memcpy(&(ap->rsn_ie.body[0]), &(ap_info->rsn.body[0]),
161 ap_info->rsn.size);
162 } else {
163 ap->rsn_ie.size = RSN_IE_BODY_MAX;
164 memcpy(&(ap->rsn_ie.body[0]), &(ap_info->rsn.body[0]),
165 RSN_IE_BODY_MAX);
166 }
167 } else if ((ap_info->rsn_mode & RSN_MODE_WPA)
168 && (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA)) {
169 ap->wpa_ie.id = 0xdd;
170 if (ap_info->rsn.size <= RSN_IE_BODY_MAX) {
171 ap->wpa_ie.size = ap_info->rsn.size;
172 memcpy(&(ap->wpa_ie.body[0]), &(ap_info->rsn.body[0]),
173 ap_info->rsn.size);
174 } else {
175 ap->wpa_ie.size = RSN_IE_BODY_MAX;
176 memcpy(&(ap->wpa_ie.body[0]), &(ap_info->rsn.body[0]),
177 RSN_IE_BODY_MAX);
178 }
179 } else {
180 ap->rsn_ie.id = 0;
181 ap->rsn_ie.size = 0;
182 ap->wpa_ie.id = 0;
183 ap->wpa_ie.size = 0;
184 }
185
186 wrqu.data.length = 0;
187 wrqu.data.flags = 0;
188 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
189 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
190 memcpy(wrqu.ap_addr.sa_data,
191 &(priv->current_ap.bssid[0]), ETH_ALEN);
192 DPRINTK(3,
193 "IWEVENT: connect bssid=%02x:%02x:%02x:%02x:%02x:%02x\n",
194 (unsigned char)wrqu.ap_addr.sa_data[0],
195 (unsigned char)wrqu.ap_addr.sa_data[1],
196 (unsigned char)wrqu.ap_addr.sa_data[2],
197 (unsigned char)wrqu.ap_addr.sa_data[3],
198 (unsigned char)wrqu.ap_addr.sa_data[4],
199 (unsigned char)wrqu.ap_addr.sa_data[5]);
200 wireless_send_event(netdev, SIOCGIWAP, &wrqu, NULL);
201 }
202 DPRINTK(4, "\n Link AP\n");
203 DPRINTK(4, " bssid=%02X:%02X:%02X:%02X:%02X:%02X\n \
204 essid=%s\n rate_set=%02X,%02X,%02X,%02X,%02X,%02X,%02X,%02X\n channel=%d\n \
205 rssi=%d\n sq=%d\n capability=%04X\n", ap->bssid[0], ap->bssid[1], ap->bssid[2], ap->bssid[3], ap->bssid[4], ap->bssid[5], &(ap->ssid.body[0]), ap->rate_set.body[0], ap->rate_set.body[1], ap->rate_set.body[2], ap->rate_set.body[3], ap->rate_set.body[4], ap->rate_set.body[5], ap->rate_set.body[6], ap->rate_set.body[7], ap->channel, ap->rssi, ap->sq, ap->capability);
206 DPRINTK(4, "\n Link AP\n rsn.mode=%d\n rsn.size=%d\n",
207 ap_info->rsn_mode, ap_info->rsn.size);
208 DPRINTK(4, "\n ext_rate_set_size=%d\n rate_set_size=%d\n",
209 ap_info->ext_rate_set.size, ap_info->rate_set.size);
210
211 return rc;
212}
213
214static
215int get_ap_information(struct ks_wlan_private *priv, struct ap_info_t *ap_info,
216 struct local_ap_t *ap)
217{
218 unsigned char *bp;
219 int bsize, offset;
220 int rc = 0;
221
222 DPRINTK(3, "\n");
223 memset(ap, 0, sizeof(struct local_ap_t));
224
225 /* bssid */
226 memcpy(&(ap->bssid[0]), &(ap_info->bssid[0]), ETH_ALEN);
227 /* rssi */
228 ap->rssi = ap_info->rssi;
229 /* sq */
230 ap->sq = ap_info->sq;
231 /* noise */
232 ap->noise = ap_info->noise;
233 /* capability */
234 ap->capability = ap_info->capability;
235 /* channel */
236 ap->channel = ap_info->ch_info;
237
238 bp = &(ap_info->body[0]);
239 bsize = ap_info->body_size;
240 offset = 0;
241
242 while (bsize > offset) {
243 /* DPRINTK(4, "Element ID=%d \n",*bp); */
244 switch (*bp) {
245 case 0: /* ssid */
246 if (*(bp + 1) <= SSID_MAX_SIZE) {
247 ap->ssid.size = *(bp + 1);
248 } else {
249 DPRINTK(1, "size over :: ssid size=%d \n",
250 *(bp + 1));
251 ap->ssid.size = SSID_MAX_SIZE;
252 }
253 memcpy(&(ap->ssid.body[0]), bp + 2, ap->ssid.size);
254 break;
255 case 1: /* rate */
256 case 50: /* ext rate */
257 if ((*(bp + 1) + ap->rate_set.size) <=
258 RATE_SET_MAX_SIZE) {
259 memcpy(&(ap->rate_set.body[ap->rate_set.size]),
260 bp + 2, *(bp + 1));
261 ap->rate_set.size += *(bp + 1);
262 } else {
263 DPRINTK(1, "size over :: rate size=%d \n",
264 (*(bp + 1) + ap->rate_set.size));
265 memcpy(&(ap->rate_set.body[ap->rate_set.size]),
266 bp + 2,
267 RATE_SET_MAX_SIZE - ap->rate_set.size);
268 ap->rate_set.size +=
269 (RATE_SET_MAX_SIZE - ap->rate_set.size);
270 }
271 break;
272 case 3: /* DS parameter */
273 break;
274 case 48: /* RSN(WPA2) */
275 ap->rsn_ie.id = *bp;
276 if (*(bp + 1) <= RSN_IE_BODY_MAX) {
277 ap->rsn_ie.size = *(bp + 1);
278 } else {
279 DPRINTK(1, "size over :: rsn size=%d \n",
280 *(bp + 1));
281 ap->rsn_ie.size = RSN_IE_BODY_MAX;
282 }
283 memcpy(&(ap->rsn_ie.body[0]), bp + 2, ap->rsn_ie.size);
284 break;
285 case 221: /* WPA */
286 if (!memcmp(bp + 2, "\x00\x50\xf2\x01", 4)) { /* WPA OUI check */
287 ap->wpa_ie.id = *bp;
288 if (*(bp + 1) <= RSN_IE_BODY_MAX) {
289 ap->wpa_ie.size = *(bp + 1);
290 } else {
291 DPRINTK(1,
292 "size over :: wpa size=%d \n",
293 *(bp + 1));
294 ap->wpa_ie.size = RSN_IE_BODY_MAX;
295 }
296 memcpy(&(ap->wpa_ie.body[0]), bp + 2,
297 ap->wpa_ie.size);
298 }
299 break;
300
301 case 2: /* FH parameter */
302 case 4: /* CF parameter */
303 case 5: /* TIM */
304 case 6: /* IBSS parameter */
305 case 7: /* Country */
306 case 42: /* ERP information */
307 case 47: /* Reserve ID 47 Broadcom AP */
308 break;
309 default:
310 DPRINTK(4, "unknown Element ID=%d \n", *bp);
311 break;
312 }
313 offset += 2; /* id & size field */
314 offset += *(bp + 1); /* +size offset */
315 bp += (*(bp + 1) + 2); /* pointer update */
316 }
317
318 return rc;
319}
320
321static
322void hostif_data_indication(struct ks_wlan_private *priv)
323{
324 unsigned int rx_ind_size; /* indicate data size */
325 struct sk_buff *skb;
326 unsigned short auth_type;
327 unsigned char temp[256];
328
329 unsigned char RecvMIC[8];
330 char buf[128];
331 struct ether_hdr *eth_hdr;
332 unsigned short eth_proto;
333 unsigned long now;
334 struct mic_failure_t *mic_failure;
335 struct ieee802_1x_hdr *aa1x_hdr;
336 struct wpa_eapol_key *eap_key;
337 struct michel_mic_t michel_mic;
338 union iwreq_data wrqu;
339
340 DPRINTK(3, "\n");
341
342 /* min length check */
343 if (priv->rx_size <= ETH_HLEN) {
344 DPRINTK(3, "rx_size = %d\n", priv->rx_size);
345 priv->nstats.rx_errors++;
346 return;
347 }
348
349 auth_type = get_WORD(priv); /* AuthType */
350 get_WORD(priv); /* Reserve Area */
351
352 eth_hdr = (struct ether_hdr *)(priv->rxp);
353 eth_proto = ntohs(eth_hdr->h_proto);
354 DPRINTK(3, "ether protocol = %04X\n", eth_proto);
355
356 /* source address check */
357 if (!memcmp(&priv->eth_addr[0], eth_hdr->h_source, ETH_ALEN)) {
358 DPRINTK(1, "invalid : source is own mac address !!\n");
359 DPRINTK(1,
360 "eth_hdrernet->h_dest=%02X:%02X:%02X:%02X:%02X:%02X\n",
361 eth_hdr->h_source[0], eth_hdr->h_source[1],
362 eth_hdr->h_source[2], eth_hdr->h_source[3],
363 eth_hdr->h_source[4], eth_hdr->h_source[5]);
364 priv->nstats.rx_errors++;
365 return;
366 }
367
368 /* for WPA */
369 if (auth_type != TYPE_DATA && priv->wpa.rsn_enabled) {
370 if (memcmp(&eth_hdr->h_source[0], &priv->eth_addr[0], ETH_ALEN)) { /* source address check */
371 if (eth_hdr->h_dest_snap != eth_hdr->h_source_snap) {
372 DPRINTK(1, "invalid data format\n");
373 priv->nstats.rx_errors++;
374 return;
375 }
376 if (((auth_type == TYPE_PMK1
377 && priv->wpa.pairwise_suite ==
378 IW_AUTH_CIPHER_TKIP) || (auth_type == TYPE_GMK1
379 && priv->wpa.
380 group_suite ==
381 IW_AUTH_CIPHER_TKIP)
382 || (auth_type == TYPE_GMK2
383 && priv->wpa.group_suite ==
384 IW_AUTH_CIPHER_TKIP))
385 && priv->wpa.key[auth_type - 1].key_len) {
386 DPRINTK(4, "TKIP: protocol=%04X: size=%u\n",
387 eth_proto, priv->rx_size);
388 /* MIC save */
389 memcpy(&RecvMIC[0],
390 (priv->rxp) + ((priv->rx_size) - 8), 8);
391 priv->rx_size = priv->rx_size - 8;
392 if (auth_type > 0 && auth_type < 4) { /* auth_type check */
393 MichaelMICFunction(&michel_mic, (uint8_t *) priv->wpa.key[auth_type - 1].rx_mic_key, (uint8_t *) priv->rxp, (int)priv->rx_size, (uint8_t) 0, /* priority */
394 (uint8_t *)
395 michel_mic.Result);
396 }
397 if (memcmp(michel_mic.Result, RecvMIC, 8)) {
398 now = jiffies;
399 mic_failure = &priv->wpa.mic_failure;
400 /* MIC FAILURE */
401 if (mic_failure->last_failure_time &&
402 (now -
403 mic_failure->last_failure_time) /
404 HZ >= 60) {
405 mic_failure->failure = 0;
406 }
407 DPRINTK(4, "MIC FAILURE \n");
408 if (mic_failure->failure == 0) {
409 mic_failure->failure = 1;
410 mic_failure->counter = 0;
411 } else if (mic_failure->failure == 1) {
412 mic_failure->failure = 2;
413 mic_failure->counter =
414 (uint16_t) ((now -
415 mic_failure->
416 last_failure_time)
417 / HZ);
418 if (!mic_failure->counter) /* mic_failure counter value range 1-60 */
419 mic_failure->counter =
420 1;
421 }
422 priv->wpa.mic_failure.
423 last_failure_time = now;
424 /* needed parameters: count, keyid, key type, TSC */
425 sprintf(buf,
426 "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr="
427 "%02x:%02x:%02x:%02x:%02x:%02x)",
428 auth_type - 1,
429 eth_hdr->
430 h_dest[0] & 0x01 ? "broad" :
431 "uni", eth_hdr->h_source[0],
432 eth_hdr->h_source[1],
433 eth_hdr->h_source[2],
434 eth_hdr->h_source[3],
435 eth_hdr->h_source[4],
436 eth_hdr->h_source[5]);
437 memset(&wrqu, 0, sizeof(wrqu));
438 wrqu.data.length = strlen(buf);
439 DPRINTK(4,
440 "IWEVENT:MICHAELMICFAILURE\n");
441 wireless_send_event(priv->net_dev,
442 IWEVCUSTOM, &wrqu,
443 buf);
444 return;
445 }
446 }
447 }
448 }
449
450 if ((priv->connect_status & FORCE_DISCONNECT) ||
451 priv->wpa.mic_failure.failure == 2) {
452 return;
453 }
454
455 /* check 13th byte at rx data */
456 switch (*(priv->rxp + 12)) {
457 case 0xAA: /* SNAP */
458 rx_ind_size = priv->rx_size - 6;
459 skb = dev_alloc_skb(rx_ind_size);
460 DPRINTK(4, "SNAP, rx_ind_size = %d\n", rx_ind_size);
461
462 if (skb) {
463 memcpy(skb_put(skb, 12), priv->rxp, 12); /* 8802/FDDI MAC copy */
464 /* (SNAP+UI..) skip */
465 memcpy(skb_put(skb, rx_ind_size - 12), priv->rxp + 18, rx_ind_size - 12); /* copy after Type */
466
467 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 20);
468 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY
469 && priv->wpa.rsn_enabled) {
470 eap_key =
471 (struct wpa_eapol_key *)(aa1x_hdr + 1);
472 atomic_set(&priv->psstatus.snooze_guard, 1);
473 }
474
475 /* rx indication */
476 skb->dev = priv->net_dev;
477 skb->protocol = eth_type_trans(skb, skb->dev);
478 priv->nstats.rx_packets++;
479 priv->nstats.rx_bytes += rx_ind_size;
480 skb->dev->last_rx = jiffies;
481 netif_rx(skb);
482 } else {
483 printk(KERN_WARNING
484 "%s: Memory squeeze, dropping packet.\n",
485 skb->dev->name);
486 priv->nstats.rx_dropped++;
487 }
488 break;
489 case 0xF0: /* NETBEUI/NetBIOS */
490 rx_ind_size = (priv->rx_size + 2);
491 skb = dev_alloc_skb(rx_ind_size);
492 DPRINTK(3, "NETBEUI/NetBIOS rx_ind_size=%d\n", rx_ind_size);
493
494 if (skb) {
495 memcpy(skb_put(skb, 12), priv->rxp, 12); /* 8802/FDDI MAC copy */
496
497 temp[0] = (((rx_ind_size - 12) >> 8) & 0xff); /* NETBEUI size add */
498 temp[1] = ((rx_ind_size - 12) & 0xff);
499 memcpy(skb_put(skb, 2), temp, 2);
500
501 memcpy(skb_put(skb, rx_ind_size - 14), priv->rxp + 12, rx_ind_size - 14); /* copy after Type */
502
503 aa1x_hdr = (struct ieee802_1x_hdr *)(priv->rxp + 14);
504 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY
505 && priv->wpa.rsn_enabled) {
506 eap_key =
507 (struct wpa_eapol_key *)(aa1x_hdr + 1);
508 atomic_set(&priv->psstatus.snooze_guard, 1);
509 }
510
511 /* rx indication */
512 skb->dev = priv->net_dev;
513 skb->protocol = eth_type_trans(skb, skb->dev);
514 priv->nstats.rx_packets++;
515 priv->nstats.rx_bytes += rx_ind_size;
516 skb->dev->last_rx = jiffies;
517 netif_rx(skb);
518 } else {
519 printk(KERN_WARNING
520 "%s: Memory squeeze, dropping packet.\n",
521 skb->dev->name);
522 priv->nstats.rx_dropped++;
523 }
524 break;
525 default: /* other rx data */
526 DPRINTK(2, "invalid data format\n");
527 priv->nstats.rx_errors++;
528 }
529}
530
531static
532void hostif_mib_get_confirm(struct ks_wlan_private *priv)
533{
534 struct net_device *dev = priv->net_dev;
535 uint32_t mib_status;
536 uint32_t mib_attribute;
537 uint16_t mib_val_size;
538 uint16_t mib_val_type;
539
540 DPRINTK(3, "\n");
541
542 mib_status = get_DWORD(priv); /* MIB status */
543 mib_attribute = get_DWORD(priv); /* MIB atttibute */
544 mib_val_size = get_WORD(priv); /* MIB value size */
545 mib_val_type = get_WORD(priv); /* MIB value type */
546
547 if (mib_status != 0) {
548 /* in case of error */
549 DPRINTK(1, "attribute=%08X, status=%08X\n", mib_attribute,
550 mib_status);
551 return;
552 }
553
554 switch (mib_attribute) {
555 case DOT11_MAC_ADDRESS:
556 /* MAC address */
557 DPRINTK(3, " mib_attribute=DOT11_MAC_ADDRESS\n");
558 hostif_sme_enqueue(priv, SME_GET_MAC_ADDRESS);
559 memcpy(priv->eth_addr, priv->rxp, ETH_ALEN);
560 priv->mac_address_valid = 1;
561 dev->dev_addr[0] = priv->eth_addr[0];
562 dev->dev_addr[1] = priv->eth_addr[1];
563 dev->dev_addr[2] = priv->eth_addr[2];
564 dev->dev_addr[3] = priv->eth_addr[3];
565 dev->dev_addr[4] = priv->eth_addr[4];
566 dev->dev_addr[5] = priv->eth_addr[5];
567 dev->dev_addr[6] = 0x00;
568 dev->dev_addr[7] = 0x00;
569 printk(KERN_INFO
570 "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
571 priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
572 priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
573 break;
574 case DOT11_PRODUCT_VERSION:
575 /* firmware version */
576 DPRINTK(3, " mib_attribute=DOT11_PRODUCT_VERSION\n");
577 priv->version_size = priv->rx_size;
578 memcpy(priv->firmware_version, priv->rxp, priv->rx_size);
579 priv->firmware_version[priv->rx_size] = '\0';
580 printk(KERN_INFO "ks_wlan: firmware ver. = %s\n",
581 priv->firmware_version);
582 hostif_sme_enqueue(priv, SME_GET_PRODUCT_VERSION);
583 /* wake_up_interruptible_all(&priv->confirm_wait); */
584 complete(&priv->confirm_wait);
585 break;
586 case LOCAL_GAIN:
587 memcpy(&priv->gain, priv->rxp, sizeof(priv->gain));
588 DPRINTK(3, "TxMode=%d, RxMode=%d, TxGain=%d, RxGain=%d\n",
589 priv->gain.TxMode, priv->gain.RxMode, priv->gain.TxGain,
590 priv->gain.RxGain);
591 break;
592 case LOCAL_EEPROM_SUM:
593 memcpy(&priv->eeprom_sum, priv->rxp, sizeof(priv->eeprom_sum));
594 DPRINTK(1, "eeprom_sum.type=%x, eeprom_sum.result=%x\n",
595 priv->eeprom_sum.type, priv->eeprom_sum.result);
596 if (priv->eeprom_sum.type == 0) {
597 priv->eeprom_checksum = EEPROM_CHECKSUM_NONE;
598 } else if (priv->eeprom_sum.type == 1) {
599 if (priv->eeprom_sum.result == 0) {
600 priv->eeprom_checksum = EEPROM_NG;
601 printk("LOCAL_EEPROM_SUM NG\n");
602 } else if (priv->eeprom_sum.result == 1) {
603 priv->eeprom_checksum = EEPROM_OK;
604 }
605 } else {
606 printk("LOCAL_EEPROM_SUM error!\n");
607 }
608 break;
609 default:
610 DPRINTK(1, "mib_attribute=%08x\n", (unsigned int)mib_attribute);
611 break;
612 }
613}
614
615static
616void hostif_mib_set_confirm(struct ks_wlan_private *priv)
617{
618 uint32_t mib_status; /* +04 MIB Status */
619 uint32_t mib_attribute; /* +08 MIB attribute */
620
621 DPRINTK(3, "\n");
622
623 mib_status = get_DWORD(priv); /* MIB Status */
624 mib_attribute = get_DWORD(priv); /* MIB attribute */
625
626 if (mib_status != 0) {
627 /* in case of error */
628 DPRINTK(1, "error :: attribute=%08X, status=%08X\n",
629 mib_attribute, mib_status);
630 }
631
632 switch (mib_attribute) {
633 case DOT11_RTS_THRESHOLD:
634 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_CONFIRM);
635 break;
636 case DOT11_FRAGMENTATION_THRESHOLD:
637 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_CONFIRM);
638 break;
639 case DOT11_WEP_DEFAULT_KEY_ID:
640 if (!priv->wpa.wpa_enabled)
641 hostif_sme_enqueue(priv, SME_WEP_INDEX_CONFIRM);
642 break;
643 case DOT11_WEP_DEFAULT_KEY_VALUE1:
644 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE1:mib_status=%d\n",
645 (int)mib_status);
646 if (priv->wpa.rsn_enabled)
647 hostif_sme_enqueue(priv, SME_SET_PMK_TSC);
648 else
649 hostif_sme_enqueue(priv, SME_WEP_KEY1_CONFIRM);
650 break;
651 case DOT11_WEP_DEFAULT_KEY_VALUE2:
652 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE2:mib_status=%d\n",
653 (int)mib_status);
654 if (priv->wpa.rsn_enabled)
655 hostif_sme_enqueue(priv, SME_SET_GMK1_TSC);
656 else
657 hostif_sme_enqueue(priv, SME_WEP_KEY2_CONFIRM);
658 break;
659 case DOT11_WEP_DEFAULT_KEY_VALUE3:
660 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE3:mib_status=%d\n",
661 (int)mib_status);
662 if (priv->wpa.rsn_enabled)
663 hostif_sme_enqueue(priv, SME_SET_GMK2_TSC);
664 else
665 hostif_sme_enqueue(priv, SME_WEP_KEY3_CONFIRM);
666 break;
667 case DOT11_WEP_DEFAULT_KEY_VALUE4:
668 DPRINTK(2, "DOT11_WEP_DEFAULT_KEY_VALUE4:mib_status=%d\n",
669 (int)mib_status);
670 if (!priv->wpa.rsn_enabled)
671 hostif_sme_enqueue(priv, SME_WEP_KEY4_CONFIRM);
672 break;
673 case DOT11_PRIVACY_INVOKED:
674 if (!priv->wpa.rsn_enabled)
675 hostif_sme_enqueue(priv, SME_WEP_FLAG_CONFIRM);
676 break;
677 case DOT11_RSN_ENABLED:
678 DPRINTK(2, "DOT11_RSN_ENABLED:mib_status=%d\n",
679 (int)mib_status);
680 hostif_sme_enqueue(priv, SME_RSN_ENABLED_CONFIRM);
681 break;
682 case LOCAL_RSN_MODE:
683 hostif_sme_enqueue(priv, SME_RSN_MODE_CONFIRM);
684 break;
685 case LOCAL_MULTICAST_ADDRESS:
686 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
687 break;
688 case LOCAL_MULTICAST_FILTER:
689 hostif_sme_enqueue(priv, SME_MULTICAST_CONFIRM);
690 break;
691 case LOCAL_CURRENTADDRESS:
692 priv->mac_address_valid = 1;
693 break;
694 case DOT11_RSN_CONFIG_MULTICAST_CIPHER:
695 DPRINTK(2, "DOT11_RSN_CONFIG_MULTICAST_CIPHER:mib_status=%d\n",
696 (int)mib_status);
697 hostif_sme_enqueue(priv, SME_RSN_MCAST_CONFIRM);
698 break;
699 case DOT11_RSN_CONFIG_UNICAST_CIPHER:
700 DPRINTK(2, "DOT11_RSN_CONFIG_UNICAST_CIPHER:mib_status=%d\n",
701 (int)mib_status);
702 hostif_sme_enqueue(priv, SME_RSN_UCAST_CONFIRM);
703 break;
704 case DOT11_RSN_CONFIG_AUTH_SUITE:
705 DPRINTK(2, "DOT11_RSN_CONFIG_AUTH_SUITE:mib_status=%d\n",
706 (int)mib_status);
707 hostif_sme_enqueue(priv, SME_RSN_AUTH_CONFIRM);
708 break;
709 case DOT11_PMK_TSC:
710 DPRINTK(2, "DOT11_PMK_TSC:mib_status=%d\n", (int)mib_status);
711 break;
712 case DOT11_GMK1_TSC:
713 DPRINTK(2, "DOT11_GMK1_TSC:mib_status=%d\n", (int)mib_status);
714 if (atomic_read(&priv->psstatus.snooze_guard)) {
715 atomic_set(&priv->psstatus.snooze_guard, 0);
716 }
717 break;
718 case DOT11_GMK2_TSC:
719 DPRINTK(2, "DOT11_GMK2_TSC:mib_status=%d\n", (int)mib_status);
720 if (atomic_read(&priv->psstatus.snooze_guard)) {
721 atomic_set(&priv->psstatus.snooze_guard, 0);
722 }
723 break;
724 case LOCAL_PMK:
725 DPRINTK(2, "LOCAL_PMK:mib_status=%d\n", (int)mib_status);
726 break;
727 case LOCAL_GAIN:
728 DPRINTK(2, "LOCAL_GAIN:mib_status=%d\n", (int)mib_status);
729 break;
730#ifdef WPS
731 case LOCAL_WPS_ENABLE:
732 DPRINTK(2, "LOCAL_WPS_ENABLE:mib_status=%d\n", (int)mib_status);
733 break;
734 case LOCAL_WPS_PROBE_REQ:
735 DPRINTK(2, "LOCAL_WPS_PROBE_REQ:mib_status=%d\n",
736 (int)mib_status);
737 break;
738#endif /* WPS */
739 case LOCAL_REGION:
740 DPRINTK(2, "LOCAL_REGION:mib_status=%d\n", (int)mib_status);
741 default:
742 break;
743 }
744}
745
746static
747void hostif_power_mngmt_confirm(struct ks_wlan_private *priv)
748{
749 DPRINTK(3, "\n");
750
751 if (priv->reg.powermgt > POWMGT_ACTIVE_MODE &&
752 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
753 atomic_set(&priv->psstatus.confirm_wait, 0);
754 priv->dev_state = DEVICE_STATE_SLEEP;
755 ks_wlan_hw_power_save(priv);
756 } else {
757 priv->dev_state = DEVICE_STATE_READY;
758 }
759
760}
761
762static
763void hostif_sleep_confirm(struct ks_wlan_private *priv)
764{
765 DPRINTK(3, "\n");
766
767 atomic_set(&priv->sleepstatus.doze_request, 1);
768 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
769 &priv->ks_wlan_hw.rw_wq, 1);
770}
771
772static
773void hostif_start_confirm(struct ks_wlan_private *priv)
774{
775#ifdef WPS
776 union iwreq_data wrqu;
777 wrqu.data.length = 0;
778 wrqu.data.flags = 0;
779 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
780 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
781 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
782 DPRINTK(3, "IWEVENT: disconnect\n");
783 wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
784 }
785#endif
786 DPRINTK(3, " scan_ind_count=%d\n", priv->scan_ind_count);
787 hostif_sme_enqueue(priv, SME_START_CONFIRM);
788}
789
790static
791void hostif_connect_indication(struct ks_wlan_private *priv)
792{
793 unsigned short connect_code;
794 unsigned int tmp = 0;
795 unsigned int old_status = priv->connect_status;
796 struct net_device *netdev = priv->net_dev;
797 union iwreq_data wrqu0;
798 connect_code = get_WORD(priv);
799
800 switch (connect_code) {
801 case RESULT_CONNECT: /* connect */
802 DPRINTK(3, "connect :: scan_ind_count=%d\n",
803 priv->scan_ind_count);
804 if (!(priv->connect_status & FORCE_DISCONNECT))
805 netif_carrier_on(netdev);
806 tmp = FORCE_DISCONNECT & priv->connect_status;
807 priv->connect_status = tmp + CONNECT_STATUS;
808 break;
809 case RESULT_DISCONNECT: /* disconnect */
810 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
811 priv->scan_ind_count);
812 netif_carrier_off(netdev);
813 tmp = FORCE_DISCONNECT & priv->connect_status;
814 priv->connect_status = tmp + DISCONNECT_STATUS;
815 break;
816 default:
817 DPRINTK(1, "unknown connect_code=%d :: scan_ind_count=%d\n",
818 connect_code, priv->scan_ind_count);
819 netif_carrier_off(netdev);
820 tmp = FORCE_DISCONNECT & priv->connect_status;
821 priv->connect_status = tmp + DISCONNECT_STATUS;
822 break;
823 }
824
825 get_current_ap(priv, (struct link_ap_info_t *)priv->rxp);
826 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS &&
827 (old_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) {
828 /* for power save */
829 atomic_set(&priv->psstatus.snooze_guard, 0);
830 atomic_set(&priv->psstatus.confirm_wait, 0);
831 }
832 ks_wlan_do_power_save(priv);
833
834 wrqu0.data.length = 0;
835 wrqu0.data.flags = 0;
836 wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
837 if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS &&
838 (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
839 memset(wrqu0.ap_addr.sa_data, '\0', ETH_ALEN);
840 DPRINTK(3, "IWEVENT: disconnect\n");
841 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
842 priv->scan_ind_count);
843 wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
844 }
845 priv->scan_ind_count = 0;
846}
847
848static
849void hostif_scan_indication(struct ks_wlan_private *priv)
850{
851 int i;
852 struct ap_info_t *ap_info;
853
854 DPRINTK(3, "scan_ind_count = %d\n", priv->scan_ind_count);
855 ap_info = (struct ap_info_t *)(priv->rxp);
856
857 if (priv->scan_ind_count != 0) {
858 for (i = 0; i < priv->aplist.size; i++) { /* bssid check */
859 if (!memcmp
860 (&(ap_info->bssid[0]),
861 &(priv->aplist.ap[i].bssid[0]), ETH_ALEN)) {
862 if (ap_info->frame_type ==
863 FRAME_TYPE_PROBE_RESP)
864 get_ap_information(priv, ap_info,
865 &(priv->aplist.
866 ap[i]));
867 return;
868 }
869 }
870 }
871 priv->scan_ind_count++;
872 if (priv->scan_ind_count < LOCAL_APLIST_MAX + 1) {
873 DPRINTK(4, " scan_ind_count=%d :: aplist.size=%d\n",
874 priv->scan_ind_count, priv->aplist.size);
875 get_ap_information(priv, (struct ap_info_t *)(priv->rxp),
876 &(priv->aplist.
877 ap[priv->scan_ind_count - 1]));
878 priv->aplist.size = priv->scan_ind_count;
879 } else {
880 DPRINTK(4, " count over :: scan_ind_count=%d\n",
881 priv->scan_ind_count);
882 }
883
884}
885
886static
887void hostif_stop_confirm(struct ks_wlan_private *priv)
888{
889 unsigned int tmp = 0;
890 unsigned int old_status = priv->connect_status;
891 struct net_device *netdev = priv->net_dev;
892 union iwreq_data wrqu0;
893
894 DPRINTK(3, "\n");
895 if (priv->dev_state == DEVICE_STATE_SLEEP)
896 priv->dev_state = DEVICE_STATE_READY;
897
898 /* disconnect indication */
899 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
900 netif_carrier_off(netdev);
901 tmp = FORCE_DISCONNECT & priv->connect_status;
902 priv->connect_status = tmp | DISCONNECT_STATUS;
903 printk("IWEVENT: disconnect\n");
904
905 wrqu0.data.length = 0;
906 wrqu0.data.flags = 0;
907 wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
908 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
909 DISCONNECT_STATUS
910 && (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
911 memset(wrqu0.ap_addr.sa_data, '\0', ETH_ALEN);
912 DPRINTK(3, "IWEVENT: disconnect\n");
913 printk("IWEVENT: disconnect\n");
914 DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
915 priv->scan_ind_count);
916 wireless_send_event(netdev, SIOCGIWAP, &wrqu0, NULL);
917 }
918 priv->scan_ind_count = 0;
919 }
920
921 hostif_sme_enqueue(priv, SME_STOP_CONFIRM);
922}
923
924static
925void hostif_ps_adhoc_set_confirm(struct ks_wlan_private *priv)
926{
927 DPRINTK(3, "\n");
928 priv->infra_status = 0; /* infrastructure mode cancel */
929 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
930
931}
932
933static
934void hostif_infrastructure_set_confirm(struct ks_wlan_private *priv)
935{
936 uint16_t result_code;
937 DPRINTK(3, "\n");
938 result_code = get_WORD(priv);
939 DPRINTK(3, "result code = %d\n", result_code);
940 priv->infra_status = 1; /* infrastructure mode set */
941 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
942}
943
944static
945void hostif_adhoc_set_confirm(struct ks_wlan_private *priv)
946{
947 DPRINTK(3, "\n");
948 priv->infra_status = 1; /* infrastructure mode set */
949 hostif_sme_enqueue(priv, SME_MODE_SET_CONFIRM);
950}
951
952static
953void hostif_associate_indication(struct ks_wlan_private *priv)
954{
955 struct association_request_t *assoc_req;
956 struct association_response_t *assoc_resp;
957 unsigned char *pb;
958 union iwreq_data wrqu;
959 char buf[IW_CUSTOM_MAX];
960 char *pbuf = &buf[0];
961 int i;
962
963 static const char associnfo_leader0[] = "ASSOCINFO(ReqIEs=";
964 static const char associnfo_leader1[] = " RespIEs=";
965
966 DPRINTK(3, "\n");
967 assoc_req = (struct association_request_t *)(priv->rxp);
968 assoc_resp = (struct association_response_t *)(assoc_req + 1);
969 pb = (unsigned char *)(assoc_resp + 1);
970
971 memset(&wrqu, 0, sizeof(wrqu));
972 memcpy(pbuf, associnfo_leader0, sizeof(associnfo_leader0) - 1);
973 wrqu.data.length += sizeof(associnfo_leader0) - 1;
974 pbuf += sizeof(associnfo_leader0) - 1;
975
976 for (i = 0; i < assoc_req->reqIEs_size; i++)
977 pbuf += sprintf(pbuf, "%02x", *(pb + i));
978 wrqu.data.length += (assoc_req->reqIEs_size) * 2;
979
980 memcpy(pbuf, associnfo_leader1, sizeof(associnfo_leader1) - 1);
981 wrqu.data.length += sizeof(associnfo_leader1) - 1;
982 pbuf += sizeof(associnfo_leader1) - 1;
983
984 pb += assoc_req->reqIEs_size;
985 for (i = 0; i < assoc_resp->respIEs_size; i++)
986 pbuf += sprintf(pbuf, "%02x", *(pb + i));
987 wrqu.data.length += (assoc_resp->respIEs_size) * 2;
988
989 pbuf += sprintf(pbuf, ")");
990 wrqu.data.length += 1;
991
992 DPRINTK(3, "IWEVENT:ASSOCINFO\n");
993 wireless_send_event(priv->net_dev, IWEVCUSTOM, &wrqu, buf);
994}
995
996static
997void hostif_bss_scan_confirm(struct ks_wlan_private *priv)
998{
999 unsigned int result_code;
1000 struct net_device *dev = priv->net_dev;
1001 union iwreq_data wrqu;
1002 result_code = get_DWORD(priv);
1003 DPRINTK(2, "result=%d :: scan_ind_count=%d\n", result_code,
1004 priv->scan_ind_count);
1005
1006 priv->sme_i.sme_flag &= ~SME_AP_SCAN;
1007 hostif_sme_enqueue(priv, SME_BSS_SCAN_CONFIRM);
1008
1009 wrqu.data.length = 0;
1010 wrqu.data.flags = 0;
1011 DPRINTK(3, "IWEVENT: SCAN CONFIRM\n");
1012 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1013 priv->scan_ind_count = 0;
1014}
1015
1016static
1017void hostif_phy_information_confirm(struct ks_wlan_private *priv)
1018{
1019 struct iw_statistics *wstats = &priv->wstats;
1020 unsigned char rssi, signal, noise;
1021 unsigned char LinkSpeed;
1022 unsigned int TransmittedFrameCount, ReceivedFragmentCount;
1023 unsigned int FailedCount, FCSErrorCount;
1024
1025 DPRINTK(3, "\n");
1026 rssi = get_BYTE(priv);
1027 signal = get_BYTE(priv);
1028 noise = get_BYTE(priv);
1029 LinkSpeed = get_BYTE(priv);
1030 TransmittedFrameCount = get_DWORD(priv);
1031 ReceivedFragmentCount = get_DWORD(priv);
1032 FailedCount = get_DWORD(priv);
1033 FCSErrorCount = get_DWORD(priv);
1034
1035 DPRINTK(4, "phyinfo confirm rssi=%d signal=%d\n", rssi, signal);
1036 priv->current_rate = (LinkSpeed & RATE_MASK);
1037 wstats->qual.qual = signal;
1038 wstats->qual.level = 256 - rssi;
1039 wstats->qual.noise = 0; /* invalid noise value */
1040 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1041
1042 DPRINTK(3, "\n rssi=%u\n signal=%u\n LinkSpeed=%ux500Kbps\n \
1043 TransmittedFrameCount=%u\n ReceivedFragmentCount=%u\n FailedCount=%u\n \
1044 FCSErrorCount=%u\n", rssi, signal, LinkSpeed, TransmittedFrameCount, ReceivedFragmentCount, FailedCount, FCSErrorCount);
1045
1046 /* wake_up_interruptible_all(&priv->confirm_wait); */
1047 complete(&priv->confirm_wait);
1048}
1049
1050static
1051void hostif_mic_failure_confirm(struct ks_wlan_private *priv)
1052{
1053 DPRINTK(3, "mic_failure=%u\n", priv->wpa.mic_failure.failure);
1054 hostif_sme_enqueue(priv, SME_MIC_FAILURE_CONFIRM);
1055}
1056
1057static
1058void hostif_event_check(struct ks_wlan_private *priv)
1059{
1060 unsigned short event;
1061
1062 DPRINTK(4, "\n");
1063 event = get_WORD(priv); /* get event */
1064 switch (event) {
1065 case HIF_DATA_IND:
1066 hostif_data_indication(priv);
1067 break;
1068 case HIF_MIB_GET_CONF:
1069 hostif_mib_get_confirm(priv);
1070 break;
1071 case HIF_MIB_SET_CONF:
1072 hostif_mib_set_confirm(priv);
1073 break;
1074 case HIF_POWERMGT_CONF:
1075 hostif_power_mngmt_confirm(priv);
1076 break;
1077 case HIF_SLEEP_CONF:
1078 hostif_sleep_confirm(priv);
1079 break;
1080 case HIF_START_CONF:
1081 hostif_start_confirm(priv);
1082 break;
1083 case HIF_CONNECT_IND:
1084 hostif_connect_indication(priv);
1085 break;
1086 case HIF_STOP_CONF:
1087 hostif_stop_confirm(priv);
1088 break;
1089 case HIF_PS_ADH_SET_CONF:
1090 hostif_ps_adhoc_set_confirm(priv);
1091 break;
1092 case HIF_INFRA_SET_CONF:
1093 case HIF_INFRA_SET2_CONF:
1094 hostif_infrastructure_set_confirm(priv);
1095 break;
1096 case HIF_ADH_SET_CONF:
1097 case HIF_ADH_SET2_CONF:
1098 hostif_adhoc_set_confirm(priv);
1099 break;
1100 case HIF_ASSOC_INFO_IND:
1101 hostif_associate_indication(priv);
1102 break;
1103 case HIF_MIC_FAILURE_CONF:
1104 hostif_mic_failure_confirm(priv);
1105 break;
1106 case HIF_SCAN_CONF:
1107 hostif_bss_scan_confirm(priv);
1108 break;
1109 case HIF_PHY_INFO_CONF:
1110 case HIF_PHY_INFO_IND:
1111 hostif_phy_information_confirm(priv);
1112 break;
1113 case HIF_SCAN_IND:
1114 hostif_scan_indication(priv);
1115 break;
1116 case HIF_AP_SET_CONF:
1117 default:
1118 //DPRINTK(1, "undefined event[%04X]\n", event);
1119 printk("undefined event[%04X]\n", event);
1120 /* wake_up_all(&priv->confirm_wait); */
1121 complete(&priv->confirm_wait);
1122 break;
1123 }
1124
1125 /* add event to hostt buffer */
1126 priv->hostt.buff[priv->hostt.qtail] = event;
1127 priv->hostt.qtail = (priv->hostt.qtail + 1) % SME_EVENT_BUFF_SIZE;
1128}
1129
1130#define CHECK_ALINE(size) (size%4 ? (size+(4-(size%4))):size)
1131
1132int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *packet)
1133{
1134 unsigned int packet_len = 0;
1135
1136 unsigned char *buffer = NULL;
1137 unsigned int length = 0;
1138 struct hostif_data_request_t *pp;
1139 unsigned char *p;
1140 int result = 0;
1141 unsigned short eth_proto;
1142 struct ether_hdr *eth_hdr;
1143 struct michel_mic_t michel_mic;
1144 unsigned short keyinfo = 0;
1145 struct ieee802_1x_hdr *aa1x_hdr;
1146 struct wpa_eapol_key *eap_key;
1147 struct ethhdr *eth;
1148
1149 packet_len = packet->len;
1150 if (packet_len > ETH_FRAME_LEN) {
1151 DPRINTK(1, "bad length packet_len=%d \n", packet_len);
1152 dev_kfree_skb(packet);
1153 return -1;
1154 }
1155
1156 if (((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS)
1157 || (priv->connect_status & FORCE_DISCONNECT)
1158 || priv->wpa.mic_failure.stop) {
1159 DPRINTK(3, " DISCONNECT\n");
1160 if (netif_queue_stopped(priv->net_dev))
1161 netif_wake_queue(priv->net_dev);
1162 if (packet)
1163 dev_kfree_skb(packet);
1164
1165 return 0;
1166 }
1167
1168 /* for PowerSave */
1169 if (atomic_read(&priv->psstatus.status) == PS_SNOOZE) { /* power save wakeup */
1170 if (!netif_queue_stopped(priv->net_dev))
1171 netif_stop_queue(priv->net_dev);
1172 }
1173
1174 DPRINTK(4, "skb_buff length=%d\n", packet_len);
1175 pp = (struct hostif_data_request_t *)
1176 kmalloc(hif_align_size(sizeof(*pp) + 6 + packet_len + 8),
1177 KS_WLAN_MEM_FLAG);
1178
1179 if (pp == NULL) {
1180 DPRINTK(3, "allocate memory failed..\n");
1181 dev_kfree_skb(packet);
1182 return -2;
1183 }
1184
1185 p = (unsigned char *)pp->data;
1186
1187 buffer = packet->data;
1188 length = packet->len;
1189
1190 /* packet check */
1191 eth = (struct ethhdr *)packet->data;
1192 if (memcmp(&priv->eth_addr[0], eth->h_source, ETH_ALEN)) {
1193 DPRINTK(1, "invalid mac address !!\n");
1194 DPRINTK(1, "ethernet->h_source=%02X:%02X:%02X:%02X:%02X:%02X\n",
1195 eth->h_source[0], eth->h_source[1], eth->h_source[2],
1196 eth->h_source[3], eth->h_source[4], eth->h_source[5]);
1197 return -3;
1198 }
1199
1200 /* MAC address copy */
1201 memcpy(p, buffer, 12); /* DST/SRC MAC address */
1202 p += 12;
1203 buffer += 12;
1204 length -= 12;
1205 /* EtherType/Length check */
1206 if (*(buffer + 1) + (*buffer << 8) > 1500) {
1207 /* ProtocolEAP = *(buffer+1) + (*buffer << 8); */
1208 /* DPRINTK(2, "Send [SNAP]Type %x\n",ProtocolEAP); */
1209 /* SAP/CTL/OUI(6 byte) add */
1210 *p++ = 0xAA; /* DSAP */
1211 *p++ = 0xAA; /* SSAP */
1212 *p++ = 0x03; /* CTL */
1213 *p++ = 0x00; /* OUI ("000000") */
1214 *p++ = 0x00; /* OUI ("000000") */
1215 *p++ = 0x00; /* OUI ("000000") */
1216 packet_len += 6;
1217 } else {
1218 DPRINTK(4, "DIX\n");
1219 /* Length(2 byte) delete */
1220 buffer += 2;
1221 length -= 2;
1222 packet_len -= 2;
1223 }
1224
1225 /* pp->data copy */
1226 memcpy(p, buffer, length);
1227
1228 p += length;
1229
1230 /* for WPA */
1231 eth_hdr = (struct ether_hdr *)&pp->data[0];
1232 eth_proto = ntohs(eth_hdr->h_proto);
1233
1234 /* for MIC FAILUER REPORT check */
1235 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP
1236 && priv->wpa.mic_failure.failure > 0) {
1237 aa1x_hdr = (struct ieee802_1x_hdr *)(eth_hdr + 1);
1238 if (aa1x_hdr->type == IEEE802_1X_TYPE_EAPOL_KEY) {
1239 eap_key = (struct wpa_eapol_key *)(aa1x_hdr + 1);
1240 keyinfo = ntohs(eap_key->key_info);
1241 }
1242 }
1243
1244 if (priv->wpa.rsn_enabled && priv->wpa.key[0].key_len) {
1245 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP
1246 && !(priv->wpa.key[1].key_len)
1247 && !(priv->wpa.key[2].key_len)
1248 && !(priv->wpa.key[3].key_len)) {
1249 pp->auth_type = cpu_to_le16((uint16_t) TYPE_AUTH); /* no encryption */
1250 } else {
1251 if (priv->wpa.pairwise_suite == IW_AUTH_CIPHER_TKIP) {
1252 MichaelMICFunction(&michel_mic, (uint8_t *) priv->wpa.key[0].tx_mic_key, (uint8_t *) & pp->data[0], (int)packet_len, (uint8_t) 0, /* priority */
1253 (uint8_t *) michel_mic.
1254 Result);
1255 memcpy(p, michel_mic.Result, 8);
1256 length += 8;
1257 packet_len += 8;
1258 p += 8;
1259 pp->auth_type =
1260 cpu_to_le16((uint16_t) TYPE_DATA);
1261
1262 } else if (priv->wpa.pairwise_suite ==
1263 IW_AUTH_CIPHER_CCMP) {
1264 pp->auth_type =
1265 cpu_to_le16((uint16_t) TYPE_DATA);
1266 }
1267 }
1268 } else {
1269 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP)
1270 pp->auth_type = cpu_to_le16((uint16_t) TYPE_AUTH);
1271 else
1272 pp->auth_type = cpu_to_le16((uint16_t) TYPE_DATA);
1273 }
1274
1275 /* header value set */
1276 pp->header.size =
1277 cpu_to_le16((uint16_t)
1278 (sizeof(*pp) - sizeof(pp->header.size) + packet_len));
1279 pp->header.event = cpu_to_le16((uint16_t) HIF_DATA_REQ);
1280
1281 /* tx request */
1282 result =
1283 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + packet_len),
1284 (void *)send_packet_complete, (void *)priv,
1285 (void *)packet);
1286
1287 /* MIC FAILUER REPORT check */
1288 if (eth_proto == ETHER_PROTOCOL_TYPE_EAP
1289 && priv->wpa.mic_failure.failure > 0) {
1290 if (keyinfo & WPA_KEY_INFO_ERROR
1291 && keyinfo & WPA_KEY_INFO_REQUEST) {
1292 DPRINTK(3, " MIC ERROR Report SET : %04X\n", keyinfo);
1293 hostif_sme_enqueue(priv, SME_MIC_FAILURE_REQUEST);
1294 }
1295 if (priv->wpa.mic_failure.failure == 2)
1296 priv->wpa.mic_failure.stop = 1;
1297 }
1298
1299 return result;
1300}
1301
1302#define ps_confirm_wait_inc(priv) do{if(atomic_read(&priv->psstatus.status) > PS_ACTIVE_SET){ \
1303 atomic_inc(&priv->psstatus.confirm_wait); \
1304 /* atomic_set(&priv->psstatus.status, PS_CONF_WAIT);*/ \
1305 } }while(0)
1306
1307static
1308void hostif_mib_get_request(struct ks_wlan_private *priv,
1309 unsigned long mib_attribute)
1310{
1311 struct hostif_mib_get_request_t *pp;
1312
1313 DPRINTK(3, "\n");
1314
1315 /* make primitive */
1316 pp = (struct hostif_mib_get_request_t *)
1317 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1318 if (pp == NULL) {
1319 DPRINTK(3, "allocate memory failed..\n");
1320 return;
1321 }
1322 pp->header.size =
1323 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1324 pp->header.event = cpu_to_le16((uint16_t) HIF_MIB_GET_REQ);
1325 pp->mib_attribute = cpu_to_le32((uint32_t) mib_attribute);
1326
1327 /* send to device request */
1328 ps_confirm_wait_inc(priv);
1329 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1330}
1331
1332static
1333void hostif_mib_set_request(struct ks_wlan_private *priv,
1334 unsigned long mib_attribute, unsigned short size,
1335 unsigned short type, void *vp)
1336{
1337 struct hostif_mib_set_request_t *pp;
1338
1339 DPRINTK(3, "\n");
1340
1341 if (priv->dev_state < DEVICE_STATE_BOOT) {
1342 DPRINTK(3, "DeviceRemove\n");
1343 return;
1344 }
1345
1346 /* make primitive */
1347 pp = (struct hostif_mib_set_request_t *)
1348 kmalloc(hif_align_size(sizeof(*pp) + size), KS_WLAN_MEM_FLAG);
1349 if (pp == NULL) {
1350 DPRINTK(3, "allocate memory failed..\n");
1351 return;
1352 }
1353
1354 pp->header.size =
1355 cpu_to_le16((uint16_t)
1356 (sizeof(*pp) - sizeof(pp->header.size) + size));
1357 pp->header.event = cpu_to_le16((uint16_t) HIF_MIB_SET_REQ);
1358 pp->mib_attribute = cpu_to_le32((uint32_t) mib_attribute);
1359 pp->mib_value.size = cpu_to_le16((uint16_t) size);
1360 pp->mib_value.type = cpu_to_le16((uint16_t) type);
1361 memcpy(&pp->mib_value.body, vp, size);
1362
1363 /* send to device request */
1364 ps_confirm_wait_inc(priv);
1365 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp) + size), NULL, NULL,
1366 NULL);
1367}
1368
1369static
1370void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode)
1371{
1372 struct hostif_start_request_t *pp;
1373
1374 DPRINTK(3, "\n");
1375
1376 /* make primitive */
1377 pp = (struct hostif_start_request_t *)
1378 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1379 if (pp == NULL) {
1380 DPRINTK(3, "allocate memory failed..\n");
1381 return;
1382 }
1383 pp->header.size =
1384 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1385 pp->header.event = cpu_to_le16((uint16_t) HIF_START_REQ);
1386 pp->mode = cpu_to_le16((uint16_t) mode);
1387
1388 /* send to device request */
1389 ps_confirm_wait_inc(priv);
1390 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1391
1392 priv->aplist.size = 0;
1393 priv->scan_ind_count = 0;
1394}
1395
1396static
1397void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv)
1398{
1399 struct hostif_ps_adhoc_set_request_t *pp;
1400 uint16_t capability;
1401
1402 DPRINTK(3, "\n");
1403
1404 /* make primitive */
1405 pp = (struct hostif_ps_adhoc_set_request_t *)
1406 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1407 if (pp == NULL) {
1408 DPRINTK(3, "allocate memory failed..\n");
1409 return;
1410 }
1411 memset(pp, 0, sizeof(*pp));
1412 pp->header.size =
1413 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1414 pp->header.event = cpu_to_le16((uint16_t) HIF_PS_ADH_SET_REQ);
1415 pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1416 pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1417 pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1418 pp->channel = cpu_to_le16((uint16_t) (priv->reg.channel));
1419 pp->rate_set.size = priv->reg.rate_set.size;
1420 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1421 priv->reg.rate_set.size);
1422
1423 capability = 0x0000;
1424 if (priv->reg.preamble == SHORT_PREAMBLE) {
1425 /* short preamble */
1426 capability |= BSS_CAP_SHORT_PREAMBLE;
1427 }
1428 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1429 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1430 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1431 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM */
1432 }
1433 pp->capability = cpu_to_le16((uint16_t) capability);
1434
1435 /* send to device request */
1436 ps_confirm_wait_inc(priv);
1437 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1438}
1439
1440static
1441void hostif_infrastructure_set_request(struct ks_wlan_private *priv)
1442{
1443 struct hostif_infrastructure_set_request_t *pp;
1444 uint16_t capability;
1445
1446 DPRINTK(3, "ssid.size=%d \n", priv->reg.ssid.size);
1447
1448 /* make primitive */
1449 pp = (struct hostif_infrastructure_set_request_t *)
1450 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1451 if (pp == NULL) {
1452 DPRINTK(3, "allocate memory failed..\n");
1453 return;
1454 }
1455 pp->header.size =
1456 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1457 pp->header.event = cpu_to_le16((uint16_t) HIF_INFRA_SET_REQ);
1458 pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1459 pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1460 pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1461
1462 pp->rate_set.size = priv->reg.rate_set.size;
1463 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1464 priv->reg.rate_set.size);
1465 pp->ssid.size = priv->reg.ssid.size;
1466 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1467
1468 capability = 0x0000;
1469 if (priv->reg.preamble == SHORT_PREAMBLE) {
1470 /* short preamble */
1471 capability |= BSS_CAP_SHORT_PREAMBLE;
1472 }
1473 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1474 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1475 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1476 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1477 }
1478 pp->capability = cpu_to_le16((uint16_t) capability);
1479 pp->beacon_lost_count =
1480 cpu_to_le16((uint16_t) (priv->reg.beacon_lost_count));
1481 pp->auth_type = cpu_to_le16((uint16_t) (priv->reg.authenticate_type));
1482
1483 pp->channel_list.body[0] = 1;
1484 pp->channel_list.body[1] = 8;
1485 pp->channel_list.body[2] = 2;
1486 pp->channel_list.body[3] = 9;
1487 pp->channel_list.body[4] = 3;
1488 pp->channel_list.body[5] = 10;
1489 pp->channel_list.body[6] = 4;
1490 pp->channel_list.body[7] = 11;
1491 pp->channel_list.body[8] = 5;
1492 pp->channel_list.body[9] = 12;
1493 pp->channel_list.body[10] = 6;
1494 pp->channel_list.body[11] = 13;
1495 pp->channel_list.body[12] = 7;
1496 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1497 pp->channel_list.size = 13;
1498 } else {
1499 pp->channel_list.body[13] = 14;
1500 pp->channel_list.size = 14;
1501 }
1502
1503 /* send to device request */
1504 ps_confirm_wait_inc(priv);
1505 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1506}
1507
1508void hostif_infrastructure_set2_request(struct ks_wlan_private *priv)
1509{
1510 struct hostif_infrastructure_set2_request_t *pp;
1511 uint16_t capability;
1512
1513 DPRINTK(2, "ssid.size=%d \n", priv->reg.ssid.size);
1514
1515 /* make primitive */
1516 pp = (struct hostif_infrastructure_set2_request_t *)
1517 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1518 if (pp == NULL) {
1519 DPRINTK(3, "allocate memory failed..\n");
1520 return;
1521 }
1522 pp->header.size =
1523 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1524 pp->header.event = cpu_to_le16((uint16_t) HIF_INFRA_SET2_REQ);
1525 pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1526 pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1527 pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1528
1529 pp->rate_set.size = priv->reg.rate_set.size;
1530 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1531 priv->reg.rate_set.size);
1532 pp->ssid.size = priv->reg.ssid.size;
1533 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1534
1535 capability = 0x0000;
1536 if (priv->reg.preamble == SHORT_PREAMBLE) {
1537 /* short preamble */
1538 capability |= BSS_CAP_SHORT_PREAMBLE;
1539 }
1540 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1541 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1542 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1543 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1544 }
1545 pp->capability = cpu_to_le16((uint16_t) capability);
1546 pp->beacon_lost_count =
1547 cpu_to_le16((uint16_t) (priv->reg.beacon_lost_count));
1548 pp->auth_type = cpu_to_le16((uint16_t) (priv->reg.authenticate_type));
1549
1550 pp->channel_list.body[0] = 1;
1551 pp->channel_list.body[1] = 8;
1552 pp->channel_list.body[2] = 2;
1553 pp->channel_list.body[3] = 9;
1554 pp->channel_list.body[4] = 3;
1555 pp->channel_list.body[5] = 10;
1556 pp->channel_list.body[6] = 4;
1557 pp->channel_list.body[7] = 11;
1558 pp->channel_list.body[8] = 5;
1559 pp->channel_list.body[9] = 12;
1560 pp->channel_list.body[10] = 6;
1561 pp->channel_list.body[11] = 13;
1562 pp->channel_list.body[12] = 7;
1563 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1564 pp->channel_list.size = 13;
1565 } else {
1566 pp->channel_list.body[13] = 14;
1567 pp->channel_list.size = 14;
1568 }
1569
1570 memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1571
1572 /* send to device request */
1573 ps_confirm_wait_inc(priv);
1574 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1575}
1576
1577static
1578void hostif_adhoc_set_request(struct ks_wlan_private *priv)
1579{
1580 struct hostif_adhoc_set_request_t *pp;
1581 uint16_t capability;
1582
1583 DPRINTK(3, "\n");
1584
1585 /* make primitive */
1586 pp = (struct hostif_adhoc_set_request_t *)
1587 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1588 if (pp == NULL) {
1589 DPRINTK(3, "allocate memory failed..\n");
1590 return;
1591 }
1592 memset(pp, 0, sizeof(*pp));
1593 pp->header.size =
1594 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1595 pp->header.event = cpu_to_le16((uint16_t) HIF_ADH_SET_REQ);
1596 pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1597 pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1598 pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1599 pp->channel = cpu_to_le16((uint16_t) (priv->reg.channel));
1600 pp->rate_set.size = priv->reg.rate_set.size;
1601 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1602 priv->reg.rate_set.size);
1603 pp->ssid.size = priv->reg.ssid.size;
1604 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1605
1606 capability = 0x0000;
1607 if (priv->reg.preamble == SHORT_PREAMBLE) {
1608 /* short preamble */
1609 capability |= BSS_CAP_SHORT_PREAMBLE;
1610 }
1611 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1612 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1613 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1614 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1615 }
1616 pp->capability = cpu_to_le16((uint16_t) capability);
1617
1618 /* send to device request */
1619 ps_confirm_wait_inc(priv);
1620 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1621}
1622
1623static
1624void hostif_adhoc_set2_request(struct ks_wlan_private *priv)
1625{
1626 struct hostif_adhoc_set2_request_t *pp;
1627 uint16_t capability;
1628
1629 DPRINTK(3, "\n");
1630
1631 /* make primitive */
1632 pp = (struct hostif_adhoc_set2_request_t *)
1633 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1634 if (pp == NULL) {
1635 DPRINTK(3, "allocate memory failed..\n");
1636 return;
1637 }
1638 memset(pp, 0, sizeof(*pp));
1639 pp->header.size =
1640 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1641 pp->header.event = cpu_to_le16((uint16_t) HIF_ADH_SET_REQ);
1642 pp->phy_type = cpu_to_le16((uint16_t) (priv->reg.phy_type));
1643 pp->cts_mode = cpu_to_le16((uint16_t) (priv->reg.cts_mode));
1644 pp->scan_type = cpu_to_le16((uint16_t) (priv->reg.scan_type));
1645 pp->rate_set.size = priv->reg.rate_set.size;
1646 memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0],
1647 priv->reg.rate_set.size);
1648 pp->ssid.size = priv->reg.ssid.size;
1649 memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size);
1650
1651 capability = 0x0000;
1652 if (priv->reg.preamble == SHORT_PREAMBLE) {
1653 /* short preamble */
1654 capability |= BSS_CAP_SHORT_PREAMBLE;
1655 }
1656 capability &= ~(BSS_CAP_PBCC); /* pbcc not support */
1657 if (priv->reg.phy_type != D_11B_ONLY_MODE) {
1658 capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */
1659 capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */
1660 }
1661 pp->capability = cpu_to_le16((uint16_t) capability);
1662
1663 pp->channel_list.body[0] = priv->reg.channel;
1664 pp->channel_list.size = 1;
1665 memcpy(pp->bssid, priv->reg.bssid, ETH_ALEN);
1666
1667 /* send to device request */
1668 ps_confirm_wait_inc(priv);
1669 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1670}
1671
1672static
1673void hostif_stop_request(struct ks_wlan_private *priv)
1674{
1675 struct hostif_stop_request_t *pp;
1676
1677 DPRINTK(3, "\n");
1678
1679 /* make primitive */
1680 pp = (struct hostif_stop_request_t *)
1681 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1682 if (pp == NULL) {
1683 DPRINTK(3, "allocate memory failed..\n");
1684 return;
1685 }
1686 pp->header.size =
1687 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1688 pp->header.event = cpu_to_le16((uint16_t) HIF_STOP_REQ);
1689
1690 /* send to device request */
1691 ps_confirm_wait_inc(priv);
1692 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1693}
1694
1695static
1696void hostif_phy_information_request(struct ks_wlan_private *priv)
1697{
1698 struct hostif_phy_information_request_t *pp;
1699
1700 DPRINTK(3, "\n");
1701
1702 /* make primitive */
1703 pp = (struct hostif_phy_information_request_t *)
1704 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1705 if (pp == NULL) {
1706 DPRINTK(3, "allocate memory failed..\n");
1707 return;
1708 }
1709 pp->header.size =
1710 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1711 pp->header.event = cpu_to_le16((uint16_t) HIF_PHY_INFO_REQ);
1712 if (priv->reg.phy_info_timer) {
1713 pp->type = cpu_to_le16((uint16_t) TIME_TYPE);
1714 pp->time = cpu_to_le16((uint16_t) (priv->reg.phy_info_timer));
1715 } else {
1716 pp->type = cpu_to_le16((uint16_t) NORMAL_TYPE);
1717 pp->time = cpu_to_le16((uint16_t) 0);
1718 }
1719
1720 /* send to device request */
1721 ps_confirm_wait_inc(priv);
1722 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1723}
1724
1725static
1726void hostif_power_mngmt_request(struct ks_wlan_private *priv,
1727 unsigned long mode, unsigned long wake_up,
1728 unsigned long receiveDTIMs)
1729{
1730 struct hostif_power_mngmt_request_t *pp;
1731
1732 DPRINTK(3, "mode=%lu wake_up=%lu receiveDTIMs=%lu\n", mode, wake_up,
1733 receiveDTIMs);
1734 /* make primitive */
1735 pp = (struct hostif_power_mngmt_request_t *)
1736 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1737 if (pp == NULL) {
1738 DPRINTK(3, "allocate memory failed..\n");
1739 return;
1740 }
1741 pp->header.size =
1742 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1743 pp->header.event = cpu_to_le16((uint16_t) HIF_POWERMGT_REQ);
1744 pp->mode = cpu_to_le32((uint32_t) mode);
1745 pp->wake_up = cpu_to_le32((uint32_t) wake_up);
1746 pp->receiveDTIMs = cpu_to_le32((uint32_t) receiveDTIMs);
1747
1748 /* send to device request */
1749 ps_confirm_wait_inc(priv);
1750 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1751}
1752
1753static
1754void hostif_sleep_request(struct ks_wlan_private *priv, unsigned long mode)
1755{
1756 struct hostif_sleep_request_t *pp;
1757
1758 DPRINTK(3, "mode=%lu \n", mode);
1759
1760 if (mode == SLP_SLEEP) {
1761 /* make primitive */
1762 pp = (struct hostif_sleep_request_t *)
1763 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1764 if (pp == NULL) {
1765 DPRINTK(3, "allocate memory failed..\n");
1766 return;
1767 }
1768 pp->header.size =
1769 cpu_to_le16((uint16_t)
1770 (sizeof(*pp) - sizeof(pp->header.size)));
1771 pp->header.event = cpu_to_le16((uint16_t) HIF_SLEEP_REQ);
1772
1773 /* send to device request */
1774 ps_confirm_wait_inc(priv);
1775 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL,
1776 NULL);
1777 } else if (mode == SLP_ACTIVE) {
1778 atomic_set(&priv->sleepstatus.wakeup_request, 1);
1779 queue_delayed_work(priv->ks_wlan_hw.ks7010sdio_wq,
1780 &priv->ks_wlan_hw.rw_wq, 1);
1781 } else {
1782 DPRINTK(3, "invalid mode %ld \n", mode);
1783 return;
1784 }
1785}
1786
1787static
1788void hostif_bss_scan_request(struct ks_wlan_private *priv,
1789 unsigned long scan_type, uint8_t * scan_ssid,
1790 uint8_t scan_ssid_len)
1791{
1792 struct hostif_bss_scan_request_t *pp;
1793
1794 DPRINTK(2, "\n");
1795 /* make primitive */
1796 pp = (struct hostif_bss_scan_request_t *)
1797 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1798 if (pp == NULL) {
1799 DPRINTK(3, "allocate memory failed..\n");
1800 return;
1801 }
1802 pp->header.size =
1803 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1804 pp->header.event = cpu_to_le16((uint16_t) HIF_SCAN_REQ);
1805 pp->scan_type = scan_type;
1806
1807 pp->ch_time_min = cpu_to_le32((uint32_t) 110); /* default value */
1808 pp->ch_time_max = cpu_to_le32((uint32_t) 130); /* default value */
1809 pp->channel_list.body[0] = 1;
1810 pp->channel_list.body[1] = 8;
1811 pp->channel_list.body[2] = 2;
1812 pp->channel_list.body[3] = 9;
1813 pp->channel_list.body[4] = 3;
1814 pp->channel_list.body[5] = 10;
1815 pp->channel_list.body[6] = 4;
1816 pp->channel_list.body[7] = 11;
1817 pp->channel_list.body[8] = 5;
1818 pp->channel_list.body[9] = 12;
1819 pp->channel_list.body[10] = 6;
1820 pp->channel_list.body[11] = 13;
1821 pp->channel_list.body[12] = 7;
1822 if (priv->reg.phy_type == D_11G_ONLY_MODE) {
1823 pp->channel_list.size = 13;
1824 } else {
1825 pp->channel_list.body[13] = 14;
1826 pp->channel_list.size = 14;
1827 }
1828 pp->ssid.size = 0;
1829
1830 /* specified SSID SCAN */
1831 if (scan_ssid_len > 0 && scan_ssid_len <= 32) {
1832 pp->ssid.size = scan_ssid_len;
1833 memcpy(&pp->ssid.body[0], scan_ssid, scan_ssid_len);
1834 }
1835
1836 /* send to device request */
1837 ps_confirm_wait_inc(priv);
1838 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1839
1840 priv->aplist.size = 0;
1841 priv->scan_ind_count = 0;
1842}
1843
1844static
1845void hostif_mic_failure_request(struct ks_wlan_private *priv,
1846 unsigned short failure_count,
1847 unsigned short timer)
1848{
1849 struct hostif_mic_failure_request_t *pp;
1850
1851 DPRINTK(3, "count=%d :: timer=%d\n", failure_count, timer);
1852 /* make primitive */
1853 pp = (struct hostif_mic_failure_request_t *)
1854 kmalloc(hif_align_size(sizeof(*pp)), KS_WLAN_MEM_FLAG);
1855 if (pp == NULL) {
1856 DPRINTK(3, "allocate memory failed..\n");
1857 return;
1858 }
1859 pp->header.size =
1860 cpu_to_le16((uint16_t) (sizeof(*pp) - sizeof(pp->header.size)));
1861 pp->header.event = cpu_to_le16((uint16_t) HIF_MIC_FAILURE_REQ);
1862 pp->failure_count = cpu_to_le16((uint16_t) failure_count);
1863 pp->timer = cpu_to_le16((uint16_t) timer);
1864
1865 /* send to device request */
1866 ps_confirm_wait_inc(priv);
1867 ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL, NULL);
1868}
1869
1870/* Device I/O Recieve indicate */
1871static void devio_rec_ind(struct ks_wlan_private *priv, unsigned char *p,
1872 unsigned int size)
1873{
1874 if (priv->device_open_status) {
1875 spin_lock(&priv->dev_read_lock); /* request spin lock */
1876 priv->dev_data[atomic_read(&priv->rec_count)] = p;
1877 priv->dev_size[atomic_read(&priv->rec_count)] = size;
1878
1879 if (atomic_read(&priv->event_count) != DEVICE_STOCK_COUNT) {
1880 /* rx event count inc */
1881 atomic_inc(&priv->event_count);
1882 }
1883 atomic_inc(&priv->rec_count);
1884 if (atomic_read(&priv->rec_count) == DEVICE_STOCK_COUNT)
1885 atomic_set(&priv->rec_count, 0);
1886
1887 wake_up_interruptible_all(&priv->devread_wait);
1888
1889 /* release spin lock */
1890 spin_unlock(&priv->dev_read_lock);
1891 }
1892}
1893
1894void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
1895 unsigned int size)
1896{
1897 DPRINTK(4, "\n");
1898
1899 devio_rec_ind(priv, p, size);
1900
1901 priv->rxp = p;
1902 priv->rx_size = size;
1903
1904 if (get_WORD(priv) == priv->rx_size) { /* length check !! */
1905 hostif_event_check(priv); /* event check */
1906 }
1907}
1908
1909static
1910void hostif_sme_set_wep(struct ks_wlan_private *priv, int type)
1911{
1912 uint32_t val;
1913 switch (type) {
1914 case SME_WEP_INDEX_REQUEST:
1915 val = cpu_to_le32((uint32_t) (priv->reg.wep_index));
1916 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
1917 sizeof(val), MIB_VALUE_TYPE_INT, &val);
1918 break;
1919 case SME_WEP_KEY1_REQUEST:
1920 if (!priv->wpa.wpa_enabled)
1921 hostif_mib_set_request(priv,
1922 DOT11_WEP_DEFAULT_KEY_VALUE1,
1923 priv->reg.wep_key[0].size,
1924 MIB_VALUE_TYPE_OSTRING,
1925 &priv->reg.wep_key[0].val[0]);
1926 break;
1927 case SME_WEP_KEY2_REQUEST:
1928 if (!priv->wpa.wpa_enabled)
1929 hostif_mib_set_request(priv,
1930 DOT11_WEP_DEFAULT_KEY_VALUE2,
1931 priv->reg.wep_key[1].size,
1932 MIB_VALUE_TYPE_OSTRING,
1933 &priv->reg.wep_key[1].val[0]);
1934 break;
1935 case SME_WEP_KEY3_REQUEST:
1936 if (!priv->wpa.wpa_enabled)
1937 hostif_mib_set_request(priv,
1938 DOT11_WEP_DEFAULT_KEY_VALUE3,
1939 priv->reg.wep_key[2].size,
1940 MIB_VALUE_TYPE_OSTRING,
1941 &priv->reg.wep_key[2].val[0]);
1942 break;
1943 case SME_WEP_KEY4_REQUEST:
1944 if (!priv->wpa.wpa_enabled)
1945 hostif_mib_set_request(priv,
1946 DOT11_WEP_DEFAULT_KEY_VALUE4,
1947 priv->reg.wep_key[3].size,
1948 MIB_VALUE_TYPE_OSTRING,
1949 &priv->reg.wep_key[3].val[0]);
1950 break;
1951 case SME_WEP_FLAG_REQUEST:
1952 val = cpu_to_le32((uint32_t) (priv->reg.privacy_invoked));
1953 hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
1954 sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
1955 break;
1956 }
1957
1958 return;
1959}
1960
1961struct wpa_suite_t {
1962 unsigned short size;
1963 unsigned char suite[4][CIPHER_ID_LEN];
1964} __attribute__ ((packed));
1965
1966struct rsn_mode_t {
1967 uint32_t rsn_mode;
1968 uint16_t rsn_capability;
1969} __attribute__ ((packed));
1970
1971static
1972void hostif_sme_set_rsn(struct ks_wlan_private *priv, int type)
1973{
1974 struct wpa_suite_t wpa_suite;
1975 struct rsn_mode_t rsn_mode;
1976 uint32_t val;
1977
1978 memset(&wpa_suite, 0, sizeof(wpa_suite));
1979
1980 switch (type) {
1981 case SME_RSN_UCAST_REQUEST:
1982 wpa_suite.size = cpu_to_le16((uint16_t) 1);
1983 switch (priv->wpa.pairwise_suite) {
1984 case IW_AUTH_CIPHER_NONE:
1985 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1986 memcpy(&wpa_suite.suite[0][0],
1987 CIPHER_ID_WPA2_NONE, CIPHER_ID_LEN);
1988 else
1989 memcpy(&wpa_suite.suite[0][0],
1990 CIPHER_ID_WPA_NONE, CIPHER_ID_LEN);
1991 break;
1992 case IW_AUTH_CIPHER_WEP40:
1993 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
1994 memcpy(&wpa_suite.suite[0][0],
1995 CIPHER_ID_WPA2_WEP40, CIPHER_ID_LEN);
1996 else
1997 memcpy(&wpa_suite.suite[0][0],
1998 CIPHER_ID_WPA_WEP40, CIPHER_ID_LEN);
1999 break;
2000 case IW_AUTH_CIPHER_TKIP:
2001 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2002 memcpy(&wpa_suite.suite[0][0],
2003 CIPHER_ID_WPA2_TKIP, CIPHER_ID_LEN);
2004 else
2005 memcpy(&wpa_suite.suite[0][0],
2006 CIPHER_ID_WPA_TKIP, CIPHER_ID_LEN);
2007 break;
2008 case IW_AUTH_CIPHER_CCMP:
2009 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2010 memcpy(&wpa_suite.suite[0][0],
2011 CIPHER_ID_WPA2_CCMP, CIPHER_ID_LEN);
2012 else
2013 memcpy(&wpa_suite.suite[0][0],
2014 CIPHER_ID_WPA_CCMP, CIPHER_ID_LEN);
2015 break;
2016 case IW_AUTH_CIPHER_WEP104:
2017 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2018 memcpy(&wpa_suite.suite[0][0],
2019 CIPHER_ID_WPA2_WEP104, CIPHER_ID_LEN);
2020 else
2021 memcpy(&wpa_suite.suite[0][0],
2022 CIPHER_ID_WPA_WEP104, CIPHER_ID_LEN);
2023 break;
2024 }
2025
2026 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_UNICAST_CIPHER,
2027 sizeof(wpa_suite.size) +
2028 CIPHER_ID_LEN * wpa_suite.size,
2029 MIB_VALUE_TYPE_OSTRING, &wpa_suite);
2030 break;
2031 case SME_RSN_MCAST_REQUEST:
2032 switch (priv->wpa.group_suite) {
2033 case IW_AUTH_CIPHER_NONE:
2034 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2035 memcpy(&wpa_suite.suite[0][0],
2036 CIPHER_ID_WPA2_NONE, CIPHER_ID_LEN);
2037 else
2038 memcpy(&wpa_suite.suite[0][0],
2039 CIPHER_ID_WPA_NONE, CIPHER_ID_LEN);
2040 break;
2041 case IW_AUTH_CIPHER_WEP40:
2042 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2043 memcpy(&wpa_suite.suite[0][0],
2044 CIPHER_ID_WPA2_WEP40, CIPHER_ID_LEN);
2045 else
2046 memcpy(&wpa_suite.suite[0][0],
2047 CIPHER_ID_WPA_WEP40, CIPHER_ID_LEN);
2048 break;
2049 case IW_AUTH_CIPHER_TKIP:
2050 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2051 memcpy(&wpa_suite.suite[0][0],
2052 CIPHER_ID_WPA2_TKIP, CIPHER_ID_LEN);
2053 else
2054 memcpy(&wpa_suite.suite[0][0],
2055 CIPHER_ID_WPA_TKIP, CIPHER_ID_LEN);
2056 break;
2057 case IW_AUTH_CIPHER_CCMP:
2058 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2059 memcpy(&wpa_suite.suite[0][0],
2060 CIPHER_ID_WPA2_CCMP, CIPHER_ID_LEN);
2061 else
2062 memcpy(&wpa_suite.suite[0][0],
2063 CIPHER_ID_WPA_CCMP, CIPHER_ID_LEN);
2064 break;
2065 case IW_AUTH_CIPHER_WEP104:
2066 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2067 memcpy(&wpa_suite.suite[0][0],
2068 CIPHER_ID_WPA2_WEP104, CIPHER_ID_LEN);
2069 else
2070 memcpy(&wpa_suite.suite[0][0],
2071 CIPHER_ID_WPA_WEP104, CIPHER_ID_LEN);
2072 break;
2073 }
2074
2075 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_MULTICAST_CIPHER,
2076 CIPHER_ID_LEN, MIB_VALUE_TYPE_OSTRING,
2077 &wpa_suite.suite[0][0]);
2078 break;
2079 case SME_RSN_AUTH_REQUEST:
2080 wpa_suite.size = cpu_to_le16((uint16_t) 1);
2081 switch (priv->wpa.key_mgmt_suite) {
2082 case IW_AUTH_KEY_MGMT_802_1X:
2083 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2084 memcpy(&wpa_suite.suite[0][0],
2085 KEY_MGMT_ID_WPA2_1X, KEY_MGMT_ID_LEN);
2086 else
2087 memcpy(&wpa_suite.suite[0][0],
2088 KEY_MGMT_ID_WPA_1X, KEY_MGMT_ID_LEN);
2089 break;
2090 case IW_AUTH_KEY_MGMT_PSK:
2091 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2092 memcpy(&wpa_suite.suite[0][0],
2093 KEY_MGMT_ID_WPA2_PSK, KEY_MGMT_ID_LEN);
2094 else
2095 memcpy(&wpa_suite.suite[0][0],
2096 KEY_MGMT_ID_WPA_PSK, KEY_MGMT_ID_LEN);
2097 break;
2098 case 0:
2099 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2100 memcpy(&wpa_suite.suite[0][0],
2101 KEY_MGMT_ID_WPA2_NONE, KEY_MGMT_ID_LEN);
2102 else
2103 memcpy(&wpa_suite.suite[0][0],
2104 KEY_MGMT_ID_WPA_NONE, KEY_MGMT_ID_LEN);
2105 break;
2106 case 4:
2107 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2)
2108 memcpy(&wpa_suite.suite[0][0],
2109 KEY_MGMT_ID_WPA2_WPANONE,
2110 KEY_MGMT_ID_LEN);
2111 else
2112 memcpy(&wpa_suite.suite[0][0],
2113 KEY_MGMT_ID_WPA_WPANONE,
2114 KEY_MGMT_ID_LEN);
2115 break;
2116 }
2117
2118 hostif_mib_set_request(priv, DOT11_RSN_CONFIG_AUTH_SUITE,
2119 sizeof(wpa_suite.size) +
2120 KEY_MGMT_ID_LEN * wpa_suite.size,
2121 MIB_VALUE_TYPE_OSTRING, &wpa_suite);
2122 break;
2123 case SME_RSN_ENABLED_REQUEST:
2124 val = cpu_to_le32((uint32_t) (priv->wpa.rsn_enabled));
2125 hostif_mib_set_request(priv, DOT11_RSN_ENABLED,
2126 sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
2127 break;
2128 case SME_RSN_MODE_REQUEST:
2129 if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA2) {
2130 rsn_mode.rsn_mode =
2131 cpu_to_le32((uint32_t) RSN_MODE_WPA2);
2132 rsn_mode.rsn_capability = cpu_to_le16((uint16_t) 0);
2133 } else if (priv->wpa.version == IW_AUTH_WPA_VERSION_WPA) {
2134 rsn_mode.rsn_mode =
2135 cpu_to_le32((uint32_t) RSN_MODE_WPA);
2136 rsn_mode.rsn_capability = cpu_to_le16((uint16_t) 0);
2137 } else {
2138 rsn_mode.rsn_mode =
2139 cpu_to_le32((uint32_t) RSN_MODE_NONE);
2140 rsn_mode.rsn_capability = cpu_to_le16((uint16_t) 0);
2141 }
2142 hostif_mib_set_request(priv, LOCAL_RSN_MODE, sizeof(rsn_mode),
2143 MIB_VALUE_TYPE_OSTRING, &rsn_mode);
2144 break;
2145
2146 }
2147 return;
2148}
2149
2150static
2151void hostif_sme_mode_setup(struct ks_wlan_private *priv)
2152{
2153 unsigned char rate_size;
2154 unsigned char rate_octet[RATE_SET_MAX_SIZE];
2155 int i = 0;
2156
2157 /* rate setting if rate segging is auto for changing phy_type (#94) */
2158 if (priv->reg.tx_rate == TX_RATE_FULL_AUTO) {
2159 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
2160 priv->reg.rate_set.body[3] = TX_RATE_11M;
2161 priv->reg.rate_set.body[2] = TX_RATE_5M;
2162 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
2163 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
2164 priv->reg.rate_set.size = 4;
2165 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2166 priv->reg.rate_set.body[11] = TX_RATE_54M;
2167 priv->reg.rate_set.body[10] = TX_RATE_48M;
2168 priv->reg.rate_set.body[9] = TX_RATE_36M;
2169 priv->reg.rate_set.body[8] = TX_RATE_18M;
2170 priv->reg.rate_set.body[7] = TX_RATE_9M;
2171 priv->reg.rate_set.body[6] = TX_RATE_24M | BASIC_RATE;
2172 priv->reg.rate_set.body[5] = TX_RATE_12M | BASIC_RATE;
2173 priv->reg.rate_set.body[4] = TX_RATE_6M | BASIC_RATE;
2174 priv->reg.rate_set.body[3] = TX_RATE_11M | BASIC_RATE;
2175 priv->reg.rate_set.body[2] = TX_RATE_5M | BASIC_RATE;
2176 priv->reg.rate_set.body[1] = TX_RATE_2M | BASIC_RATE;
2177 priv->reg.rate_set.body[0] = TX_RATE_1M | BASIC_RATE;
2178 priv->reg.rate_set.size = 12;
2179 }
2180 }
2181
2182 /* rate mask by phy setting */
2183 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
2184 for (i = 0; i < priv->reg.rate_set.size; i++) {
2185 if (IS_11B_RATE(priv->reg.rate_set.body[i])) {
2186 if ((priv->reg.rate_set.body[i] & RATE_MASK) >=
2187 TX_RATE_5M)
2188 rate_octet[i] =
2189 priv->reg.rate_set.
2190 body[i] & RATE_MASK;
2191 else
2192 rate_octet[i] =
2193 priv->reg.rate_set.body[i];
2194 } else
2195 break;
2196 }
2197
2198 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
2199 for (i = 0; i < priv->reg.rate_set.size; i++) {
2200 if (IS_11BG_RATE(priv->reg.rate_set.body[i])) {
2201 if (IS_OFDM_EXT_RATE
2202 (priv->reg.rate_set.body[i]))
2203 rate_octet[i] =
2204 priv->reg.rate_set.
2205 body[i] & RATE_MASK;
2206 else
2207 rate_octet[i] =
2208 priv->reg.rate_set.body[i];
2209 } else
2210 break;
2211 }
2212 }
2213 rate_size = i;
2214 if (rate_size == 0) {
2215 if (priv->reg.phy_type == D_11G_ONLY_MODE)
2216 rate_octet[0] = TX_RATE_6M | BASIC_RATE;
2217 else
2218 rate_octet[0] = TX_RATE_2M | BASIC_RATE;
2219 rate_size = 1;
2220 }
2221
2222 /* rate set update */
2223 priv->reg.rate_set.size = rate_size;
2224 memcpy(&priv->reg.rate_set.body[0], &rate_octet[0], rate_size);
2225
2226 switch (priv->reg.operation_mode) {
2227 case MODE_PSEUDO_ADHOC:
2228 /* Pseudo Ad-Hoc mode */
2229 hostif_ps_adhoc_set_request(priv);
2230 break;
2231 case MODE_INFRASTRUCTURE:
2232 /* Infrastructure mode */
2233 if (!is_valid_ether_addr((u8 *) priv->reg.bssid)) {
2234 hostif_infrastructure_set_request(priv);
2235 } else {
2236 hostif_infrastructure_set2_request(priv);
2237 DPRINTK(2,
2238 "Infra bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
2239 priv->reg.bssid[0], priv->reg.bssid[1],
2240 priv->reg.bssid[2], priv->reg.bssid[3],
2241 priv->reg.bssid[4], priv->reg.bssid[5]);
2242 }
2243 break;
2244 case MODE_ADHOC:
2245 /* IEEE802.11 Ad-Hoc mode */
2246 if (!is_valid_ether_addr((u8 *) priv->reg.bssid)) {
2247 hostif_adhoc_set_request(priv);
2248 } else {
2249 hostif_adhoc_set2_request(priv);
2250 DPRINTK(2,
2251 "Adhoc bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
2252 priv->reg.bssid[0], priv->reg.bssid[1],
2253 priv->reg.bssid[2], priv->reg.bssid[3],
2254 priv->reg.bssid[4], priv->reg.bssid[5]);
2255 }
2256 break;
2257 default:
2258 break;
2259 }
2260
2261 return;
2262}
2263
2264static
2265void hostif_sme_multicast_set(struct ks_wlan_private *priv)
2266{
2267
2268 struct net_device *dev = priv->net_dev;
2269 int mc_count;
2270 struct netdev_hw_addr *ha;
2271 char set_address[NIC_MAX_MCAST_LIST * ETH_ALEN];
2272 unsigned long filter_type;
2273 int i = 0;
2274
2275 DPRINTK(3, "\n");
2276
2277 spin_lock(&priv->multicast_spin);
2278
2279 memset(set_address, 0, NIC_MAX_MCAST_LIST * ETH_ALEN);
2280
2281 if (dev->flags & IFF_PROMISC) {
2282 filter_type = cpu_to_le32((uint32_t) MCAST_FILTER_PROMISC);
2283 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2284 sizeof(filter_type), MIB_VALUE_TYPE_BOOL,
2285 &filter_type);
2286 } else if ((netdev_mc_count(dev) > NIC_MAX_MCAST_LIST)
2287 || (dev->flags & IFF_ALLMULTI)) {
2288 filter_type = cpu_to_le32((uint32_t) MCAST_FILTER_MCASTALL);
2289 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2290 sizeof(filter_type), MIB_VALUE_TYPE_BOOL,
2291 &filter_type);
2292 } else {
2293 if (priv->sme_i.sme_flag & SME_MULTICAST) {
2294 mc_count = netdev_mc_count(dev);
2295 netdev_for_each_mc_addr(ha, dev) {
2296 memcpy(&set_address[i * ETH_ALEN], ha->addr,
2297 ETH_ALEN);
2298 i++;
2299 }
2300 priv->sme_i.sme_flag &= ~SME_MULTICAST;
2301 hostif_mib_set_request(priv, LOCAL_MULTICAST_ADDRESS,
2302 (ETH_ALEN * mc_count),
2303 MIB_VALUE_TYPE_OSTRING,
2304 &set_address[0]);
2305 } else {
2306 filter_type =
2307 cpu_to_le32((uint32_t) MCAST_FILTER_MCAST);
2308 priv->sme_i.sme_flag |= SME_MULTICAST;
2309 hostif_mib_set_request(priv, LOCAL_MULTICAST_FILTER,
2310 sizeof(filter_type),
2311 MIB_VALUE_TYPE_BOOL,
2312 &filter_type);
2313 }
2314 }
2315
2316 spin_unlock(&priv->multicast_spin);
2317
2318}
2319
2320static
2321void hostif_sme_powermgt_set(struct ks_wlan_private *priv)
2322{
2323 unsigned long mode, wake_up, receiveDTIMs;
2324
2325 DPRINTK(3, "\n");
2326 switch (priv->reg.powermgt) {
2327 case POWMGT_ACTIVE_MODE:
2328 mode = POWER_ACTIVE;
2329 wake_up = 0;
2330 receiveDTIMs = 0;
2331 break;
2332 case POWMGT_SAVE1_MODE:
2333 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2334 mode = POWER_SAVE;
2335 wake_up = 0;
2336 receiveDTIMs = 0;
2337 } else {
2338 mode = POWER_ACTIVE;
2339 wake_up = 0;
2340 receiveDTIMs = 0;
2341 }
2342 break;
2343 case POWMGT_SAVE2_MODE:
2344 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2345 mode = POWER_SAVE;
2346 wake_up = 0;
2347 receiveDTIMs = 1;
2348 } else {
2349 mode = POWER_ACTIVE;
2350 wake_up = 0;
2351 receiveDTIMs = 0;
2352 }
2353 break;
2354 default:
2355 mode = POWER_ACTIVE;
2356 wake_up = 0;
2357 receiveDTIMs = 0;
2358 break;
2359 }
2360 hostif_power_mngmt_request(priv, mode, wake_up, receiveDTIMs);
2361
2362 return;
2363}
2364
2365static
2366void hostif_sme_sleep_set(struct ks_wlan_private *priv)
2367{
2368 DPRINTK(3, "\n");
2369 switch (priv->sleep_mode) {
2370 case SLP_SLEEP:
2371 hostif_sleep_request(priv, priv->sleep_mode);
2372 break;
2373 case SLP_ACTIVE:
2374 hostif_sleep_request(priv, priv->sleep_mode);
2375 break;
2376 default:
2377 break;
2378 }
2379
2380 return;
2381}
2382
2383static
2384void hostif_sme_set_key(struct ks_wlan_private *priv, int type)
2385{
2386 uint32_t val;
2387 switch (type) {
2388 case SME_SET_FLAG:
2389 val = cpu_to_le32((uint32_t) (priv->reg.privacy_invoked));
2390 hostif_mib_set_request(priv, DOT11_PRIVACY_INVOKED,
2391 sizeof(val), MIB_VALUE_TYPE_BOOL, &val);
2392 break;
2393 case SME_SET_TXKEY:
2394 val = cpu_to_le32((uint32_t) (priv->wpa.txkey));
2395 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_ID,
2396 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2397 break;
2398 case SME_SET_KEY1:
2399 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE1,
2400 priv->wpa.key[0].key_len,
2401 MIB_VALUE_TYPE_OSTRING,
2402 &priv->wpa.key[0].key_val[0]);
2403 break;
2404 case SME_SET_KEY2:
2405 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE2,
2406 priv->wpa.key[1].key_len,
2407 MIB_VALUE_TYPE_OSTRING,
2408 &priv->wpa.key[1].key_val[0]);
2409 break;
2410 case SME_SET_KEY3:
2411 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE3,
2412 priv->wpa.key[2].key_len,
2413 MIB_VALUE_TYPE_OSTRING,
2414 &priv->wpa.key[2].key_val[0]);
2415 break;
2416 case SME_SET_KEY4:
2417 hostif_mib_set_request(priv, DOT11_WEP_DEFAULT_KEY_VALUE4,
2418 priv->wpa.key[3].key_len,
2419 MIB_VALUE_TYPE_OSTRING,
2420 &priv->wpa.key[3].key_val[0]);
2421 break;
2422 case SME_SET_PMK_TSC:
2423 hostif_mib_set_request(priv, DOT11_PMK_TSC,
2424 WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2425 &priv->wpa.key[0].rx_seq[0]);
2426 break;
2427 case SME_SET_GMK1_TSC:
2428 hostif_mib_set_request(priv, DOT11_GMK1_TSC,
2429 WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2430 &priv->wpa.key[1].rx_seq[0]);
2431 break;
2432 case SME_SET_GMK2_TSC:
2433 hostif_mib_set_request(priv, DOT11_GMK2_TSC,
2434 WPA_RX_SEQ_LEN, MIB_VALUE_TYPE_OSTRING,
2435 &priv->wpa.key[2].rx_seq[0]);
2436 break;
2437 }
2438 return;
2439}
2440
2441static
2442void hostif_sme_set_pmksa(struct ks_wlan_private *priv)
2443{
2444 struct pmk_cache_t {
2445 uint16_t size;
2446 struct {
2447 uint8_t bssid[ETH_ALEN];
2448 uint8_t pmkid[IW_PMKID_LEN];
2449 } __attribute__ ((packed)) list[PMK_LIST_MAX];
2450 } __attribute__ ((packed)) pmkcache;
2451 struct pmk_t *pmk;
2452 struct list_head *ptr;
2453 int i;
2454
2455 DPRINTK(4, "pmklist.size=%d\n", priv->pmklist.size);
2456 i = 0;
2457 list_for_each(ptr, &priv->pmklist.head) {
2458 pmk = list_entry(ptr, struct pmk_t, list);
2459 if (i < PMK_LIST_MAX) {
2460 memcpy(pmkcache.list[i].bssid, pmk->bssid, ETH_ALEN);
2461 memcpy(pmkcache.list[i].pmkid, pmk->pmkid,
2462 IW_PMKID_LEN);
2463 i++;
2464 }
2465 }
2466 pmkcache.size = cpu_to_le16((uint16_t) (priv->pmklist.size));
2467 hostif_mib_set_request(priv, LOCAL_PMK,
2468 sizeof(priv->pmklist.size) + (ETH_ALEN +
2469 IW_PMKID_LEN) *
2470 (priv->pmklist.size), MIB_VALUE_TYPE_OSTRING,
2471 &pmkcache);
2472}
2473
2474/* execute sme */
2475static
2476void hostif_sme_execute(struct ks_wlan_private *priv, int event)
2477{
2478 uint32_t val;
2479
2480 DPRINTK(3, "event=%d\n", event);
2481 switch (event) {
2482 case SME_START:
2483 if (priv->dev_state == DEVICE_STATE_BOOT) {
2484 hostif_mib_get_request(priv, DOT11_MAC_ADDRESS);
2485 }
2486 break;
2487 case SME_MULTICAST_REQUEST:
2488 hostif_sme_multicast_set(priv);
2489 break;
2490 case SME_MACADDRESS_SET_REQUEST:
2491 hostif_mib_set_request(priv, LOCAL_CURRENTADDRESS, ETH_ALEN,
2492 MIB_VALUE_TYPE_OSTRING,
2493 &priv->eth_addr[0]);
2494 break;
2495 case SME_BSS_SCAN_REQUEST:
2496 hostif_bss_scan_request(priv, priv->reg.scan_type,
2497 priv->scan_ssid, priv->scan_ssid_len);
2498 break;
2499 case SME_POW_MNGMT_REQUEST:
2500 hostif_sme_powermgt_set(priv);
2501 break;
2502 case SME_PHY_INFO_REQUEST:
2503 hostif_phy_information_request(priv);
2504 break;
2505 case SME_MIC_FAILURE_REQUEST:
2506 if (priv->wpa.mic_failure.failure == 1) {
2507 hostif_mic_failure_request(priv,
2508 priv->wpa.mic_failure.
2509 failure - 1, 0);
2510 } else if (priv->wpa.mic_failure.failure == 2) {
2511 hostif_mic_failure_request(priv,
2512 priv->wpa.mic_failure.
2513 failure - 1,
2514 priv->wpa.mic_failure.
2515 counter);
2516 } else
2517 DPRINTK(4,
2518 "SME_MIC_FAILURE_REQUEST: failure count=%u error?\n",
2519 priv->wpa.mic_failure.failure);
2520 break;
2521 case SME_MIC_FAILURE_CONFIRM:
2522 if (priv->wpa.mic_failure.failure == 2) {
2523 if (priv->wpa.mic_failure.stop)
2524 priv->wpa.mic_failure.stop = 0;
2525 priv->wpa.mic_failure.failure = 0;
2526 hostif_start_request(priv, priv->reg.operation_mode);
2527 }
2528 break;
2529 case SME_GET_MAC_ADDRESS:
2530 if (priv->dev_state == DEVICE_STATE_BOOT) {
2531 hostif_mib_get_request(priv, DOT11_PRODUCT_VERSION);
2532 }
2533 break;
2534 case SME_GET_PRODUCT_VERSION:
2535 if (priv->dev_state == DEVICE_STATE_BOOT) {
2536 priv->dev_state = DEVICE_STATE_PREINIT;
2537 }
2538 break;
2539 case SME_STOP_REQUEST:
2540 hostif_stop_request(priv);
2541 break;
2542 case SME_RTS_THRESHOLD_REQUEST:
2543 val = cpu_to_le32((uint32_t) (priv->reg.rts));
2544 hostif_mib_set_request(priv, DOT11_RTS_THRESHOLD,
2545 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2546 break;
2547 case SME_FRAGMENTATION_THRESHOLD_REQUEST:
2548 val = cpu_to_le32((uint32_t) (priv->reg.fragment));
2549 hostif_mib_set_request(priv, DOT11_FRAGMENTATION_THRESHOLD,
2550 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2551 break;
2552 case SME_WEP_INDEX_REQUEST:
2553 case SME_WEP_KEY1_REQUEST:
2554 case SME_WEP_KEY2_REQUEST:
2555 case SME_WEP_KEY3_REQUEST:
2556 case SME_WEP_KEY4_REQUEST:
2557 case SME_WEP_FLAG_REQUEST:
2558 hostif_sme_set_wep(priv, event);
2559 break;
2560 case SME_RSN_UCAST_REQUEST:
2561 case SME_RSN_MCAST_REQUEST:
2562 case SME_RSN_AUTH_REQUEST:
2563 case SME_RSN_ENABLED_REQUEST:
2564 case SME_RSN_MODE_REQUEST:
2565 hostif_sme_set_rsn(priv, event);
2566 break;
2567 case SME_SET_FLAG:
2568 case SME_SET_TXKEY:
2569 case SME_SET_KEY1:
2570 case SME_SET_KEY2:
2571 case SME_SET_KEY3:
2572 case SME_SET_KEY4:
2573 case SME_SET_PMK_TSC:
2574 case SME_SET_GMK1_TSC:
2575 case SME_SET_GMK2_TSC:
2576 hostif_sme_set_key(priv, event);
2577 break;
2578 case SME_SET_PMKSA:
2579 hostif_sme_set_pmksa(priv);
2580 break;
2581#ifdef WPS
2582 case SME_WPS_ENABLE_REQUEST:
2583 hostif_mib_set_request(priv, LOCAL_WPS_ENABLE,
2584 sizeof(priv->wps.wps_enabled),
2585 MIB_VALUE_TYPE_INT,
2586 &priv->wps.wps_enabled);
2587 break;
2588 case SME_WPS_PROBE_REQUEST:
2589 hostif_mib_set_request(priv, LOCAL_WPS_PROBE_REQ,
2590 priv->wps.ielen,
2591 MIB_VALUE_TYPE_OSTRING, priv->wps.ie);
2592 break;
2593#endif /* WPS */
2594 case SME_MODE_SET_REQUEST:
2595 hostif_sme_mode_setup(priv);
2596 break;
2597 case SME_SET_GAIN:
2598 hostif_mib_set_request(priv, LOCAL_GAIN,
2599 sizeof(priv->gain),
2600 MIB_VALUE_TYPE_OSTRING, &priv->gain);
2601 break;
2602 case SME_GET_GAIN:
2603 hostif_mib_get_request(priv, LOCAL_GAIN);
2604 break;
2605 case SME_GET_EEPROM_CKSUM:
2606 priv->eeprom_checksum = EEPROM_FW_NOT_SUPPORT; /* initialize */
2607 hostif_mib_get_request(priv, LOCAL_EEPROM_SUM);
2608 break;
2609 case SME_START_REQUEST:
2610 hostif_start_request(priv, priv->reg.operation_mode);
2611 break;
2612 case SME_START_CONFIRM:
2613 /* for power save */
2614 atomic_set(&priv->psstatus.snooze_guard, 0);
2615 atomic_set(&priv->psstatus.confirm_wait, 0);
2616 if (priv->dev_state == DEVICE_STATE_PREINIT) {
2617 priv->dev_state = DEVICE_STATE_INIT;
2618 }
2619 /* wake_up_interruptible_all(&priv->confirm_wait); */
2620 complete(&priv->confirm_wait);
2621 break;
2622 case SME_SLEEP_REQUEST:
2623 hostif_sme_sleep_set(priv);
2624 break;
2625 case SME_SET_REGION:
2626 val = cpu_to_le32((uint32_t) (priv->region));
2627 hostif_mib_set_request(priv, LOCAL_REGION,
2628 sizeof(val), MIB_VALUE_TYPE_INT, &val);
2629 break;
2630 case SME_MULTICAST_CONFIRM:
2631 case SME_BSS_SCAN_CONFIRM:
2632 case SME_POW_MNGMT_CONFIRM:
2633 case SME_PHY_INFO_CONFIRM:
2634 case SME_STOP_CONFIRM:
2635 case SME_RTS_THRESHOLD_CONFIRM:
2636 case SME_FRAGMENTATION_THRESHOLD_CONFIRM:
2637 case SME_WEP_INDEX_CONFIRM:
2638 case SME_WEP_KEY1_CONFIRM:
2639 case SME_WEP_KEY2_CONFIRM:
2640 case SME_WEP_KEY3_CONFIRM:
2641 case SME_WEP_KEY4_CONFIRM:
2642 case SME_WEP_FLAG_CONFIRM:
2643 case SME_RSN_UCAST_CONFIRM:
2644 case SME_RSN_MCAST_CONFIRM:
2645 case SME_RSN_AUTH_CONFIRM:
2646 case SME_RSN_ENABLED_CONFIRM:
2647 case SME_RSN_MODE_CONFIRM:
2648 case SME_MODE_SET_CONFIRM:
2649 break;
2650 case SME_TERMINATE:
2651 default:
2652 break;
2653 }
2654}
2655
2656static
2657void hostif_sme_task(unsigned long dev)
2658{
2659 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev;
2660
2661 DPRINTK(3, "\n");
2662
2663 if (priv->dev_state >= DEVICE_STATE_BOOT) {
2664 if (0 < cnt_smeqbody(priv)
2665 && priv->dev_state >= DEVICE_STATE_BOOT) {
2666 hostif_sme_execute(priv,
2667 priv->sme_i.event_buff[priv->sme_i.
2668 qhead]);
2669 inc_smeqhead(priv);
2670 if (0 < cnt_smeqbody(priv))
2671 tasklet_schedule(&priv->sme_task);
2672 }
2673 }
2674 return;
2675}
2676
2677/* send to Station Management Entity module */
2678void hostif_sme_enqueue(struct ks_wlan_private *priv, unsigned short event)
2679{
2680 DPRINTK(3, "\n");
2681
2682 /* enqueue sme event */
2683 if (cnt_smeqbody(priv) < (SME_EVENT_BUFF_SIZE - 1)) {
2684 priv->sme_i.event_buff[priv->sme_i.qtail] = event;
2685 inc_smeqtail(priv);
2686 //DPRINTK(3,"inc_smeqtail \n");
2687#ifdef KS_WLAN_DEBUG
2688 if (priv->sme_i.max_event_count < cnt_smeqbody(priv))
2689 priv->sme_i.max_event_count = cnt_smeqbody(priv);
2690#endif /* KS_WLAN_DEBUG */
2691 } else {
2692 /* in case of buffer overflow */
2693 //DPRINTK(2,"sme queue buffer overflow\n");
2694 printk("sme queue buffer overflow\n");
2695 }
2696
2697 tasklet_schedule(&priv->sme_task);
2698
2699}
2700
2701int hostif_init(struct ks_wlan_private *priv)
2702{
2703 int rc = 0;
2704 int i;
2705
2706 DPRINTK(3, "\n");
2707
2708 priv->aplist.size = 0;
2709 for (i = 0; i < LOCAL_APLIST_MAX; i++)
2710 memset(&(priv->aplist.ap[i]), 0, sizeof(struct local_ap_t));
2711 priv->infra_status = 0;
2712 priv->current_rate = 4;
2713 priv->connect_status = DISCONNECT_STATUS;
2714
2715 spin_lock_init(&priv->multicast_spin);
2716
2717 spin_lock_init(&priv->dev_read_lock);
2718 init_waitqueue_head(&priv->devread_wait);
2719 priv->dev_count = 0;
2720 atomic_set(&priv->event_count, 0);
2721 atomic_set(&priv->rec_count, 0);
2722
2723 /* for power save */
2724 atomic_set(&priv->psstatus.status, PS_NONE);
2725 atomic_set(&priv->psstatus.confirm_wait, 0);
2726 atomic_set(&priv->psstatus.snooze_guard, 0);
2727 /* init_waitqueue_head(&priv->psstatus.wakeup_wait); */
2728 init_completion(&priv->psstatus.wakeup_wait);
2729 //INIT_WORK(&priv->ks_wlan_wakeup_task, ks_wlan_hw_wakeup_task, (void *)priv);
2730 INIT_WORK(&priv->ks_wlan_wakeup_task, ks_wlan_hw_wakeup_task);
2731
2732 /* WPA */
2733 memset(&(priv->wpa), 0, sizeof(priv->wpa));
2734 priv->wpa.rsn_enabled = 0;
2735 priv->wpa.mic_failure.failure = 0;
2736 priv->wpa.mic_failure.last_failure_time = 0;
2737 priv->wpa.mic_failure.stop = 0;
2738 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2739 INIT_LIST_HEAD(&priv->pmklist.head);
2740 for (i = 0; i < PMK_LIST_MAX; i++)
2741 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2742
2743 priv->sme_i.sme_status = SME_IDLE;
2744 priv->sme_i.qhead = priv->sme_i.qtail = 0;
2745#ifdef KS_WLAN_DEBUG
2746 priv->sme_i.max_event_count = 0;
2747#endif
2748 spin_lock_init(&priv->sme_i.sme_spin);
2749 priv->sme_i.sme_flag = 0;
2750
2751 tasklet_init(&priv->sme_task, hostif_sme_task, (unsigned long)priv);
2752
2753 return rc;
2754}
2755
2756void hostif_exit(struct ks_wlan_private *priv)
2757{
2758 tasklet_kill(&priv->sme_task);
2759 return;
2760}
diff --git a/drivers/staging/ks7010/ks_hostif.h b/drivers/staging/ks7010/ks_hostif.h
new file mode 100644
index 000000000000..dc806b5b47be
--- /dev/null
+++ b/drivers/staging/ks7010/ks_hostif.h
@@ -0,0 +1,644 @@
1/*
2 * Driver for KeyStream wireless LAN
3 *
4 * Copyright (c) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _KS_HOSTIF_H_
13#define _KS_HOSTIF_H_
14/*
15 * HOST-MAC I/F events
16 */
17#define HIF_DATA_REQ 0xE001
18#define HIF_DATA_IND 0xE801
19#define HIF_MIB_GET_REQ 0xE002
20#define HIF_MIB_GET_CONF 0xE802
21#define HIF_MIB_SET_REQ 0xE003
22#define HIF_MIB_SET_CONF 0xE803
23#define HIF_POWERMGT_REQ 0xE004
24#define HIF_POWERMGT_CONF 0xE804
25#define HIF_START_REQ 0xE005
26#define HIF_START_CONF 0xE805
27#define HIF_CONNECT_IND 0xE806
28#define HIF_STOP_REQ 0xE006
29#define HIF_STOP_CONF 0xE807
30#define HIF_PS_ADH_SET_REQ 0xE007
31#define HIF_PS_ADH_SET_CONF 0xE808
32#define HIF_INFRA_SET_REQ 0xE008
33#define HIF_INFRA_SET_CONF 0xE809
34#define HIF_ADH_SET_REQ 0xE009
35#define HIF_ADH_SET_CONF 0xE80A
36#define HIF_AP_SET_REQ 0xE00A
37#define HIF_AP_SET_CONF 0xE80B
38#define HIF_ASSOC_INFO_IND 0xE80C
39#define HIF_MIC_FAILURE_REQ 0xE00B
40#define HIF_MIC_FAILURE_CONF 0xE80D
41#define HIF_SCAN_REQ 0xE00C
42#define HIF_SCAN_CONF 0xE80E
43#define HIF_PHY_INFO_REQ 0xE00D
44#define HIF_PHY_INFO_CONF 0xE80F
45#define HIF_SLEEP_REQ 0xE00E
46#define HIF_SLEEP_CONF 0xE810
47#define HIF_PHY_INFO_IND 0xE811
48#define HIF_SCAN_IND 0xE812
49#define HIF_INFRA_SET2_REQ 0xE00F
50#define HIF_INFRA_SET2_CONF 0xE813
51#define HIF_ADH_SET2_REQ 0xE010
52#define HIF_ADH_SET2_CONF 0xE814
53
54#define HIF_REQ_MAX 0xE010
55
56/*
57 * HOST-MAC I/F data structure
58 * Byte alignmet Little Endian
59 */
60
61struct hostif_hdr {
62 uint16_t size;
63 uint16_t event;
64} __attribute__ ((packed));
65
66struct hostif_data_request_t {
67 struct hostif_hdr header;
68 uint16_t auth_type;
69#define TYPE_DATA 0x0000
70#define TYPE_AUTH 0x0001
71 uint16_t reserved;
72 uint8_t data[0];
73} __attribute__ ((packed));
74
75struct hostif_data_indication_t {
76 struct hostif_hdr header;
77 uint16_t auth_type;
78/* #define TYPE_DATA 0x0000 */
79#define TYPE_PMK1 0x0001
80#define TYPE_GMK1 0x0002
81#define TYPE_GMK2 0x0003
82 uint16_t reserved;
83 uint8_t data[0];
84} __attribute__ ((packed));
85
86#define CHANNEL_LIST_MAX_SIZE 14
87struct channel_list_t {
88 uint8_t size;
89 uint8_t body[CHANNEL_LIST_MAX_SIZE];
90 uint8_t pad;
91} __attribute__ ((packed));
92
93/* MIB Attribute */
94#define DOT11_MAC_ADDRESS 0x21010100 /* MAC Address (R) */
95#define DOT11_PRODUCT_VERSION 0x31024100 /* FirmWare Version (R) */
96#define DOT11_RTS_THRESHOLD 0x21020100 /* RTS Threshold (R/W) */
97#define DOT11_FRAGMENTATION_THRESHOLD 0x21050100 /* Fragment Threshold (R/W) */
98#define DOT11_PRIVACY_INVOKED 0x15010100 /* WEP ON/OFF (W) */
99#define DOT11_WEP_DEFAULT_KEY_ID 0x15020100 /* WEP Index (W) */
100#define DOT11_WEP_DEFAULT_KEY_VALUE1 0x13020101 /* WEP Key#1(TKIP AES: PairwiseTemporalKey) (W) */
101#define DOT11_WEP_DEFAULT_KEY_VALUE2 0x13020102 /* WEP Key#2(TKIP AES: GroupKey1) (W) */
102#define DOT11_WEP_DEFAULT_KEY_VALUE3 0x13020103 /* WEP Key#3(TKIP AES: GroupKey2) (W) */
103#define DOT11_WEP_DEFAULT_KEY_VALUE4 0x13020104 /* WEP Key#4 (W) */
104#define DOT11_WEP_LIST 0x13020100 /* WEP LIST */
105#define DOT11_DESIRED_SSID 0x11090100 /* SSID */
106#define DOT11_CURRENT_CHANNEL 0x45010100 /* channel set */
107#define DOT11_OPERATION_RATE_SET 0x11110100 /* rate set */
108
109#define LOCAL_AP_SEARCH_INTEAVAL 0xF1010100 /* AP search interval (R/W) */
110#define LOCAL_CURRENTADDRESS 0xF1050100 /* MAC Adress change (W) */
111#define LOCAL_MULTICAST_ADDRESS 0xF1060100 /* Multicast Adress (W) */
112#define LOCAL_MULTICAST_FILTER 0xF1060200 /* Multicast Adress Filter enable/disable (W) */
113#define LOCAL_SEARCHED_AP_LIST 0xF1030100 /* AP list (R) */
114#define LOCAL_LINK_AP_STATUS 0xF1040100 /* Link AP status (R) */
115#define LOCAL_PACKET_STATISTICS 0xF1020100 /* tx,rx packets statistics */
116#define LOCAL_AP_SCAN_LIST_TYPE_SET 0xF1030200 /* AP_SCAN_LIST_TYPE */
117
118#define DOT11_RSN_ENABLED 0x15070100 /* WPA enable/disable (W) */
119#define LOCAL_RSN_MODE 0x56010100 /* RSN mode WPA/WPA2 (W) */
120#define DOT11_RSN_CONFIG_MULTICAST_CIPHER 0x51040100 /* GroupKeyCipherSuite (W) */
121#define DOT11_RSN_CONFIG_UNICAST_CIPHER 0x52020100 /* PairwiseKeyCipherSuite (W) */
122#define DOT11_RSN_CONFIG_AUTH_SUITE 0x53020100 /* AuthenticationKeyManagementSuite (W) */
123#define DOT11_RSN_CONFIG_VERSION 0x51020100 /* RSN version (W) */
124#define LOCAL_RSN_CONFIG_ALL 0x5F010100 /* RSN CONFIG ALL (W) */
125#define DOT11_PMK_TSC 0x55010100 /* PMK_TSC (W) */
126#define DOT11_GMK1_TSC 0x55010101 /* GMK1_TSC (W) */
127#define DOT11_GMK2_TSC 0x55010102 /* GMK2_TSC (W) */
128#define DOT11_GMK3_TSC 0x55010103 /* GMK3_TSC */
129#define LOCAL_PMK 0x58010100 /* Pairwise Master Key cache (W) */
130
131#define LOCAL_REGION 0xF10A0100 /* Region setting */
132
133#ifdef WPS
134#define LOCAL_WPS_ENABLE 0xF10B0100 /* WiFi Protected Setup */
135#define LOCAL_WPS_PROBE_REQ 0xF10C0100 /* WPS Probe Request */
136#endif /* WPS */
137
138#define LOCAL_GAIN 0xF10D0100 /* Carrer sense threshold for demo ato show */
139#define LOCAL_EEPROM_SUM 0xF10E0100 /* EEPROM checksum information */
140
141struct hostif_mib_get_request_t {
142 struct hostif_hdr header;
143 uint32_t mib_attribute;
144} __attribute__ ((packed));
145
146struct hostif_mib_value_t {
147 uint16_t size;
148 uint16_t type;
149#define MIB_VALUE_TYPE_NULL 0
150#define MIB_VALUE_TYPE_INT 1
151#define MIB_VALUE_TYPE_BOOL 2
152#define MIB_VALUE_TYPE_COUNT32 3
153#define MIB_VALUE_TYPE_OSTRING 4
154 uint8_t body[0];
155} __attribute__ ((packed));
156
157struct hostif_mib_get_confirm_t {
158 struct hostif_hdr header;
159 uint32_t mib_status;
160#define MIB_SUCCESS 0
161#define MIB_INVALID 1
162#define MIB_READ_ONLY 2
163#define MIB_WRITE_ONLY 3
164 uint32_t mib_attribute;
165 struct hostif_mib_value_t mib_value;
166} __attribute__ ((packed));
167
168struct hostif_mib_set_request_t {
169 struct hostif_hdr header;
170 uint32_t mib_attribute;
171 struct hostif_mib_value_t mib_value;
172} __attribute__ ((packed));
173
174struct hostif_mib_set_confirm_t {
175 struct hostif_hdr header;
176 uint32_t mib_status;
177 uint32_t mib_attribute;
178} __attribute__ ((packed));
179
180struct hostif_power_mngmt_request_t {
181 struct hostif_hdr header;
182 uint32_t mode;
183#define POWER_ACTIVE 1
184#define POWER_SAVE 2
185 uint32_t wake_up;
186#define SLEEP_FALSE 0
187#define SLEEP_TRUE 1 /* not used */
188 uint32_t receiveDTIMs;
189#define DTIM_FALSE 0
190#define DTIM_TRUE 1
191} __attribute__ ((packed));
192
193/* power management mode */
194enum {
195 POWMGT_ACTIVE_MODE = 0,
196 POWMGT_SAVE1_MODE,
197 POWMGT_SAVE2_MODE
198};
199
200#define RESULT_SUCCESS 0
201#define RESULT_INVALID_PARAMETERS 1
202#define RESULT_NOT_SUPPORTED 2
203/* #define RESULT_ALREADY_RUNNING 3 */
204#define RESULT_ALREADY_RUNNING 7
205
206struct hostif_power_mngmt_confirm_t {
207 struct hostif_hdr header;
208 uint16_t result_code;
209} __attribute__ ((packed));
210
211struct hostif_start_request_t {
212 struct hostif_hdr header;
213 uint16_t mode;
214#define MODE_PSEUDO_ADHOC 0
215#define MODE_INFRASTRUCTURE 1
216#define MODE_AP 2 /* not used */
217#define MODE_ADHOC 3
218} __attribute__ ((packed));
219
220struct hostif_start_confirm_t {
221 struct hostif_hdr header;
222 uint16_t result_code;
223} __attribute__ ((packed));
224
225#define SSID_MAX_SIZE 32
226struct ssid_t {
227 uint8_t size;
228 uint8_t body[SSID_MAX_SIZE];
229 uint8_t ssid_pad;
230} __attribute__ ((packed));
231
232#define RATE_SET_MAX_SIZE 16
233struct rate_set8_t {
234 uint8_t size;
235 uint8_t body[8];
236 uint8_t rate_pad;
237} __attribute__ ((packed));
238
239struct FhParms_t {
240 uint16_t dwellTime;
241 uint8_t hopSet;
242 uint8_t hopPattern;
243 uint8_t hopIndex;
244} __attribute__ ((packed));
245
246struct DsParms_t {
247 uint8_t channel;
248} __attribute__ ((packed));
249
250struct CfParms_t {
251 uint8_t count;
252 uint8_t period;
253 uint16_t maxDuration;
254 uint16_t durRemaining;
255} __attribute__ ((packed));
256
257struct IbssParms_t {
258 uint16_t atimWindow;
259} __attribute__ ((packed));
260
261struct rsn_t {
262 uint8_t size;
263#define RSN_BODY_SIZE 64
264 uint8_t body[RSN_BODY_SIZE];
265} __attribute__ ((packed));
266
267struct ErpParams_t {
268 uint8_t erp_info;
269} __attribute__ ((packed));
270
271struct rate_set16_t {
272 uint8_t size;
273 uint8_t body[16];
274 uint8_t rate_pad;
275} __attribute__ ((packed));
276
277struct ap_info_t {
278 uint8_t bssid[6]; /* +00 */
279 uint8_t rssi; /* +06 */
280 uint8_t sq; /* +07 */
281 uint8_t noise; /* +08 */
282 uint8_t pad0; /* +09 */
283 uint16_t beacon_period; /* +10 */
284 uint16_t capability; /* +12 */
285#define BSS_CAP_ESS (1<<0)
286#define BSS_CAP_IBSS (1<<1)
287#define BSS_CAP_CF_POLABLE (1<<2)
288#define BSS_CAP_CF_POLL_REQ (1<<3)
289#define BSS_CAP_PRIVACY (1<<4)
290#define BSS_CAP_SHORT_PREAMBLE (1<<5)
291#define BSS_CAP_PBCC (1<<6)
292#define BSS_CAP_CHANNEL_AGILITY (1<<7)
293#define BSS_CAP_SHORT_SLOT_TIME (1<<10)
294#define BSS_CAP_DSSS_OFDM (1<<13)
295 uint8_t frame_type; /* +14 */
296 uint8_t ch_info; /* +15 */
297#define FRAME_TYPE_BEACON 0x80
298#define FRAME_TYPE_PROBE_RESP 0x50
299 uint16_t body_size; /* +16 */
300 uint8_t body[1024]; /* +18 */
301 /* +1032 */
302} __attribute__ ((packed));
303
304struct link_ap_info_t {
305 uint8_t bssid[6]; /* +00 */
306 uint8_t rssi; /* +06 */
307 uint8_t sq; /* +07 */
308 uint8_t noise; /* +08 */
309 uint8_t pad0; /* +09 */
310 uint16_t beacon_period; /* +10 */
311 uint16_t capability; /* +12 */
312 struct rate_set8_t rate_set; /* +14 */
313 struct FhParms_t fh_parameter; /* +24 */
314 struct DsParms_t ds_parameter; /* +29 */
315 struct CfParms_t cf_parameter; /* +30 */
316 struct IbssParms_t ibss_parameter; /* +36 */
317 struct ErpParams_t erp_parameter; /* +38 */
318 uint8_t pad1; /* +39 */
319 struct rate_set8_t ext_rate_set; /* +40 */
320 uint8_t DTIM_period; /* +50 */
321 uint8_t rsn_mode; /* +51 */
322#define RSN_MODE_NONE 0
323#define RSN_MODE_WPA 1
324#define RSN_MODE_WPA2 2
325 struct {
326 uint8_t size; /* +52 */
327 uint8_t body[128]; /* +53 */
328 } __attribute__ ((packed)) rsn;
329} __attribute__ ((packed));
330
331struct hostif_connect_indication_t {
332 struct hostif_hdr header;
333 uint16_t connect_code;
334#define RESULT_CONNECT 0
335#define RESULT_DISCONNECT 1
336 struct link_ap_info_t link_ap_info;
337} __attribute__ ((packed));
338
339struct hostif_stop_request_t {
340 struct hostif_hdr header;
341} __attribute__ ((packed));
342
343struct hostif_stop_confirm_t {
344 struct hostif_hdr header;
345 uint16_t result_code;
346} __attribute__ ((packed));
347
348struct hostif_ps_adhoc_set_request_t {
349 struct hostif_hdr header;
350 uint16_t phy_type;
351#define D_11B_ONLY_MODE 0
352#define D_11G_ONLY_MODE 1
353#define D_11BG_COMPATIBLE_MODE 2
354#define D_11A_ONLY_MODE 3
355 uint16_t cts_mode;
356#define CTS_MODE_FALSE 0
357#define CTS_MODE_TRUE 1
358 uint16_t channel;
359 struct rate_set16_t rate_set;
360 uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
361 * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
362 uint16_t scan_type;
363} __attribute__ ((packed));
364
365struct hostif_ps_adhoc_set_confirm_t {
366 struct hostif_hdr header;
367 uint16_t result_code;
368} __attribute__ ((packed));
369
370struct hostif_infrastructure_set_request_t {
371 struct hostif_hdr header;
372 uint16_t phy_type;
373 uint16_t cts_mode;
374 struct rate_set16_t rate_set;
375 struct ssid_t ssid;
376 uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
377 * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
378 uint16_t beacon_lost_count;
379 uint16_t auth_type;
380#define AUTH_TYPE_OPEN_SYSTEM 0
381#define AUTH_TYPE_SHARED_KEY 1
382 struct channel_list_t channel_list;
383 uint16_t scan_type;
384} __attribute__ ((packed));
385
386struct hostif_infrastructure_set2_request_t {
387 struct hostif_hdr header;
388 uint16_t phy_type;
389 uint16_t cts_mode;
390 struct rate_set16_t rate_set;
391 struct ssid_t ssid;
392 uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
393 * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
394 uint16_t beacon_lost_count;
395 uint16_t auth_type;
396#define AUTH_TYPE_OPEN_SYSTEM 0
397#define AUTH_TYPE_SHARED_KEY 1
398 struct channel_list_t channel_list;
399 uint16_t scan_type;
400 uint8_t bssid[ETH_ALEN];
401} __attribute__ ((packed));
402
403struct hostif_infrastructure_set_confirm_t {
404 struct hostif_hdr header;
405 uint16_t result_code;
406} __attribute__ ((packed));
407
408struct hostif_adhoc_set_request_t {
409 struct hostif_hdr header;
410 uint16_t phy_type;
411 uint16_t cts_mode;
412 uint16_t channel;
413 struct rate_set16_t rate_set;
414 struct ssid_t ssid;
415 uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
416 * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
417 uint16_t scan_type;
418} __attribute__ ((packed));
419
420struct hostif_adhoc_set2_request_t {
421 struct hostif_hdr header;
422 uint16_t phy_type;
423 uint16_t cts_mode;
424 uint16_t reserved;
425 struct rate_set16_t rate_set;
426 struct ssid_t ssid;
427 uint16_t capability; /* bit5:preamble bit6:pbcc pbcc not supported always 0
428 * bit10:ShortSlotTime bit13:DSSS-OFDM DSSS-OFDM not supported always 0 */
429 uint16_t scan_type;
430 struct channel_list_t channel_list;
431 uint8_t bssid[ETH_ALEN];
432} __attribute__ ((packed));
433
434struct hostif_adhoc_set_confirm_t {
435 struct hostif_hdr header;
436 uint16_t result_code;
437} __attribute__ ((packed));
438
439struct last_associate_t {
440 uint8_t type;
441 uint8_t status;
442} __attribute__ ((packed));
443
444struct association_request_t {
445 uint8_t type;
446#define FRAME_TYPE_ASSOC_REQ 0x00
447#define FRAME_TYPE_REASSOC_REQ 0x20
448 uint8_t pad;
449 uint16_t capability;
450 uint16_t listen_interval;
451 uint8_t ap_address[6];
452 uint16_t reqIEs_size;
453} __attribute__ ((packed));
454
455struct association_response_t {
456 uint8_t type;
457#define FRAME_TYPE_ASSOC_RESP 0x10
458#define FRAME_TYPE_REASSOC_RESP 0x30
459 uint8_t pad;
460 uint16_t capability;
461 uint16_t status;
462 uint16_t association_id;
463 uint16_t respIEs_size;
464} __attribute__ ((packed));
465
466struct hostif_associate_indication_t {
467 struct hostif_hdr header;
468 struct association_request_t assoc_req;
469 struct association_response_t assoc_resp;
470 /* followed by (reqIEs_size + respIEs_size) octets of data */
471 /* reqIEs data *//* respIEs data */
472} __attribute__ ((packed));
473
474struct hostif_bss_scan_request_t {
475 struct hostif_hdr header;
476 uint8_t scan_type;
477#define ACTIVE_SCAN 0
478#define PASSIVE_SCAN 1
479 uint8_t pad[3];
480 uint32_t ch_time_min;
481 uint32_t ch_time_max;
482 struct channel_list_t channel_list;
483 struct ssid_t ssid;
484} __attribute__ ((packed));
485
486struct hostif_bss_scan_confirm_t {
487 struct hostif_hdr header;
488 uint16_t result_code;
489 uint16_t reserved;
490} __attribute__ ((packed));
491
492struct hostif_phy_information_request_t {
493 struct hostif_hdr header;
494 uint16_t type;
495#define NORMAL_TYPE 0
496#define TIME_TYPE 1
497 uint16_t time; /* unit 100ms */
498} __attribute__ ((packed));
499
500struct hostif_phy_information_confirm_t {
501 struct hostif_hdr header;
502 uint8_t rssi;
503 uint8_t sq;
504 uint8_t noise;
505 uint8_t link_speed;
506 uint32_t tx_frame;
507 uint32_t rx_frame;
508 uint32_t tx_error;
509 uint32_t rx_error;
510} __attribute__ ((packed));
511
512/* sleep mode */
513#define SLP_ACTIVE 0
514#define SLP_SLEEP 1
515struct hostif_sleep_request_t {
516 struct hostif_hdr header;
517} __attribute__ ((packed));
518
519struct hostif_sleep_confirm_t {
520 struct hostif_hdr header;
521 uint16_t result_code;
522} __attribute__ ((packed));
523
524struct hostif_mic_failure_request_t {
525 struct hostif_hdr header;
526 uint16_t failure_count;
527 uint16_t timer;
528} __attribute__ ((packed));
529
530struct hostif_mic_failure_confirm_t {
531 struct hostif_hdr header;
532 uint16_t result_code;
533} __attribute__ ((packed));
534
535#define BASIC_RATE 0x80
536#define RATE_MASK 0x7F
537
538#define TX_RATE_AUTO 0xff
539#define TX_RATE_1M_FIXED 0
540#define TX_RATE_2M_FIXED 1
541#define TX_RATE_1_2M_AUTO 2
542#define TX_RATE_5M_FIXED 3
543#define TX_RATE_11M_FIXED 4
544
545#define TX_RATE_FULL_AUTO 0
546#define TX_RATE_11_AUTO 1
547#define TX_RATE_11B_AUTO 2
548#define TX_RATE_11BG_AUTO 3
549#define TX_RATE_MANUAL_AUTO 4
550#define TX_RATE_FIXED 5
551
552/* 11b rate */
553#define TX_RATE_1M (uint8_t)(10/5) /* 11b 11g basic rate */
554#define TX_RATE_2M (uint8_t)(20/5) /* 11b 11g basic rate */
555#define TX_RATE_5M (uint8_t)(55/5) /* 11g basic rate */
556#define TX_RATE_11M (uint8_t)(110/5) /* 11g basic rate */
557
558/* 11g rate */
559#define TX_RATE_6M (uint8_t)(60/5) /* 11g basic rate */
560#define TX_RATE_12M (uint8_t)(120/5) /* 11g basic rate */
561#define TX_RATE_24M (uint8_t)(240/5) /* 11g basic rate */
562#define TX_RATE_9M (uint8_t)(90/5)
563#define TX_RATE_18M (uint8_t)(180/5)
564#define TX_RATE_36M (uint8_t)(360/5)
565#define TX_RATE_48M (uint8_t)(480/5)
566#define TX_RATE_54M (uint8_t)(540/5)
567
568#define IS_11B_RATE(A) (((A&RATE_MASK)==TX_RATE_1M)||((A&RATE_MASK)==TX_RATE_2M)||\
569 ((A&RATE_MASK)==TX_RATE_5M)||((A&RATE_MASK)==TX_RATE_11M))
570
571#define IS_OFDM_RATE(A) (((A&RATE_MASK)==TX_RATE_6M)||((A&RATE_MASK)==TX_RATE_12M)||\
572 ((A&RATE_MASK)==TX_RATE_24M)||((A&RATE_MASK)==TX_RATE_9M)||\
573 ((A&RATE_MASK)==TX_RATE_18M)||((A&RATE_MASK)==TX_RATE_36M)||\
574 ((A&RATE_MASK)==TX_RATE_48M)||((A&RATE_MASK)==TX_RATE_54M))
575
576#define IS_11BG_RATE(A) (IS_11B_RATE(A)||IS_OFDM_RATE(A))
577
578#define IS_OFDM_EXT_RATE(A) (((A&RATE_MASK)==TX_RATE_9M)||((A&RATE_MASK)==TX_RATE_18M)||\
579 ((A&RATE_MASK)==TX_RATE_36M)||((A&RATE_MASK)==TX_RATE_48M)||\
580 ((A&RATE_MASK)==TX_RATE_54M))
581
582enum {
583 CONNECT_STATUS = 0,
584 DISCONNECT_STATUS
585};
586
587/* preamble type */
588enum {
589 LONG_PREAMBLE = 0,
590 SHORT_PREAMBLE
591};
592
593/* multicast filter */
594#define MCAST_FILTER_MCAST 0
595#define MCAST_FILTER_MCASTALL 1
596#define MCAST_FILTER_PROMISC 2
597
598#define NIC_MAX_MCAST_LIST 32
599
600/* macro function */
601#define HIF_EVENT_MASK 0xE800
602#define IS_HIF_IND(_EVENT) ((_EVENT&HIF_EVENT_MASK)==0xE800 && \
603 ((_EVENT&~HIF_EVENT_MASK)==0x0001 || \
604 (_EVENT&~HIF_EVENT_MASK)==0x0006 || \
605 (_EVENT&~HIF_EVENT_MASK)==0x000C || \
606 (_EVENT&~HIF_EVENT_MASK)==0x0011 || \
607 (_EVENT&~HIF_EVENT_MASK)==0x0012))
608
609#define IS_HIF_CONF(_EVENT) ((_EVENT&HIF_EVENT_MASK)==0xE800 && \
610 (_EVENT&~HIF_EVENT_MASK)>0x0000 && \
611 (_EVENT&~HIF_EVENT_MASK)<0x0012 && \
612 !IS_HIF_IND(_EVENT) )
613
614#ifdef __KERNEL__
615
616#include "ks_wlan.h"
617
618/* function prototype */
619extern int hostif_data_request(struct ks_wlan_private *priv,
620 struct sk_buff *packet);
621extern void hostif_receive(struct ks_wlan_private *priv, unsigned char *p,
622 unsigned int size);
623extern void hostif_sme_enqueue(struct ks_wlan_private *priv, uint16_t event);
624extern int hostif_init(struct ks_wlan_private *priv);
625extern void hostif_exit(struct ks_wlan_private *priv);
626
627static
628inline int hif_align_size(int size)
629{
630#ifdef KS_ATOM
631 if (size < 1024)
632 size = 1024;
633#endif
634#ifdef DEVICE_ALIGNMENT
635 return (size % DEVICE_ALIGNMENT) ? size + DEVICE_ALIGNMENT -
636 (size % DEVICE_ALIGNMENT) : size;
637#else
638 return size;
639#endif
640}
641
642#endif /* __KERNEL__ */
643
644#endif /* _KS_HOSTIF_H_ */
diff --git a/drivers/staging/ks7010/ks_wlan.h b/drivers/staging/ks7010/ks_wlan.h
new file mode 100644
index 000000000000..f05dc0122fcb
--- /dev/null
+++ b/drivers/staging/ks7010/ks_wlan.h
@@ -0,0 +1,505 @@
1/*
2 * Driver for KeyStream IEEE802.11 b/g wireless LAN cards.
3 *
4 * Copyright (C) 2006-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _KS_WLAN_H
13#define _KS_WLAN_H
14
15#define WPS
16
17#include <linux/version.h>
18#include <linux/interrupt.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21
22#include <linux/spinlock.h> /* spinlock_t */
23#include <linux/sched.h> /* wait_queue_head_t */
24#include <linux/types.h> /* pid_t */
25#include <linux/netdevice.h> /* struct net_device_stats, struct sk_buff */
26#include <linux/etherdevice.h>
27#include <linux/wireless.h>
28#include <asm/atomic.h> /* struct atmic_t */
29#include <linux/timer.h> /* struct timer_list */
30#include <linux/string.h>
31#include <linux/completion.h> /* struct completion */
32#include <linux/workqueue.h>
33
34#include <asm/io.h>
35
36#include "ks7010_sdio.h"
37
38#ifdef KS_WLAN_DEBUG
39#define DPRINTK(n, fmt, args...) \
40 if (KS_WLAN_DEBUG>(n)) printk(KERN_NOTICE "%s: "fmt, __FUNCTION__, ## args)
41#else
42#define DPRINTK(n, fmt, args...)
43#endif
44
45struct ks_wlan_parameter {
46 uint8_t operation_mode; /* Operation Mode */
47 uint8_t channel; /* Channel */
48 uint8_t tx_rate; /* Transmit Rate */
49 struct {
50 uint8_t size;
51 uint8_t body[16];
52 } rate_set;
53 uint8_t bssid[ETH_ALEN]; /* BSSID */
54 struct {
55 uint8_t size;
56 uint8_t body[32 + 1];
57 } ssid; /* SSID */
58 uint8_t preamble; /* Preamble */
59 uint8_t powermgt; /* PowerManagementMode */
60 uint32_t scan_type; /* AP List Scan Type */
61#define BEACON_LOST_COUNT_MIN 0
62#define BEACON_LOST_COUNT_MAX 65535
63 uint32_t beacon_lost_count; /* Beacon Lost Count */
64 uint32_t rts; /* RTS Threashold */
65 uint32_t fragment; /* Fragmentation Threashold */
66 uint32_t privacy_invoked;
67 uint32_t wep_index;
68 struct {
69 uint8_t size;
70 uint8_t val[13 * 2 + 1];
71 } wep_key[4];
72 uint16_t authenticate_type;
73 uint16_t phy_type; /* 11b/11g/11bg mode type */
74 uint16_t cts_mode; /* for 11g/11bg mode cts mode */
75 uint16_t phy_info_timer; /* phy information timer */
76};
77
78enum {
79 DEVICE_STATE_OFF = 0, /* this means hw_unavailable is != 0 */
80 DEVICE_STATE_PREBOOT, /* we are in a pre-boot state (empty RAM) */
81 DEVICE_STATE_BOOT, /* boot state (fw upload, run fw) */
82 DEVICE_STATE_PREINIT, /* pre-init state */
83 DEVICE_STATE_INIT, /* init state (restore MIB backup to device) */
84 DEVICE_STATE_READY, /* driver&device are in operational state */
85 DEVICE_STATE_SLEEP /* device in sleep mode */
86};
87
88/* SME flag */
89#define SME_MODE_SET (1<<0)
90#define SME_RTS (1<<1)
91#define SME_FRAG (1<<2)
92#define SME_WEP_FLAG (1<<3)
93#define SME_WEP_INDEX (1<<4)
94#define SME_WEP_VAL1 (1<<5)
95#define SME_WEP_VAL2 (1<<6)
96#define SME_WEP_VAL3 (1<<7)
97#define SME_WEP_VAL4 (1<<8)
98#define SME_WEP_VAL_MASK (SME_WEP_VAL1|SME_WEP_VAL2|SME_WEP_VAL3|SME_WEP_VAL4)
99#define SME_RSN (1<<9)
100#define SME_RSN_MULTICAST (1<<10)
101#define SME_RSN_UNICAST (1<<11)
102#define SME_RSN_AUTH (1<<12)
103
104#define SME_AP_SCAN (1<<13)
105#define SME_MULTICAST (1<<14)
106
107/* SME Event */
108enum {
109 SME_START,
110
111 SME_MULTICAST_REQUEST,
112 SME_MACADDRESS_SET_REQUEST,
113 SME_BSS_SCAN_REQUEST,
114 SME_SET_FLAG,
115 SME_SET_TXKEY,
116 SME_SET_KEY1,
117 SME_SET_KEY2,
118 SME_SET_KEY3,
119 SME_SET_KEY4,
120 SME_SET_PMK_TSC,
121 SME_SET_GMK1_TSC,
122 SME_SET_GMK2_TSC,
123 SME_SET_GMK3_TSC,
124 SME_SET_PMKSA,
125 SME_POW_MNGMT_REQUEST,
126 SME_PHY_INFO_REQUEST,
127 SME_MIC_FAILURE_REQUEST,
128 SME_GET_MAC_ADDRESS,
129 SME_GET_PRODUCT_VERSION,
130 SME_STOP_REQUEST,
131 SME_RTS_THRESHOLD_REQUEST,
132 SME_FRAGMENTATION_THRESHOLD_REQUEST,
133 SME_WEP_INDEX_REQUEST,
134 SME_WEP_KEY1_REQUEST,
135 SME_WEP_KEY2_REQUEST,
136 SME_WEP_KEY3_REQUEST,
137 SME_WEP_KEY4_REQUEST,
138 SME_WEP_FLAG_REQUEST,
139 SME_RSN_UCAST_REQUEST,
140 SME_RSN_MCAST_REQUEST,
141 SME_RSN_AUTH_REQUEST,
142 SME_RSN_ENABLED_REQUEST,
143 SME_RSN_MODE_REQUEST,
144#ifdef WPS
145 SME_WPS_ENABLE_REQUEST,
146 SME_WPS_PROBE_REQUEST,
147#endif
148 SME_SET_GAIN,
149 SME_GET_GAIN,
150 SME_SLEEP_REQUEST,
151 SME_SET_REGION,
152 SME_MODE_SET_REQUEST,
153 SME_START_REQUEST,
154 SME_GET_EEPROM_CKSUM,
155
156 SME_MIC_FAILURE_CONFIRM,
157 SME_START_CONFIRM,
158
159 SME_MULTICAST_CONFIRM,
160 SME_BSS_SCAN_CONFIRM,
161 SME_GET_CURRENT_AP,
162 SME_POW_MNGMT_CONFIRM,
163 SME_PHY_INFO_CONFIRM,
164 SME_STOP_CONFIRM,
165 SME_RTS_THRESHOLD_CONFIRM,
166 SME_FRAGMENTATION_THRESHOLD_CONFIRM,
167 SME_WEP_INDEX_CONFIRM,
168 SME_WEP_KEY1_CONFIRM,
169 SME_WEP_KEY2_CONFIRM,
170 SME_WEP_KEY3_CONFIRM,
171 SME_WEP_KEY4_CONFIRM,
172 SME_WEP_FLAG_CONFIRM,
173 SME_RSN_UCAST_CONFIRM,
174 SME_RSN_MCAST_CONFIRM,
175 SME_RSN_AUTH_CONFIRM,
176 SME_RSN_ENABLED_CONFIRM,
177 SME_RSN_MODE_CONFIRM,
178 SME_MODE_SET_CONFIRM,
179 SME_SLEEP_CONFIRM,
180
181 SME_RSN_SET_CONFIRM,
182 SME_WEP_SET_CONFIRM,
183 SME_TERMINATE,
184
185 SME_EVENT_SIZE /* end */
186};
187
188/* SME Status */
189enum {
190 SME_IDLE,
191 SME_SETUP,
192 SME_DISCONNECT,
193 SME_CONNECT
194};
195
196#define SME_EVENT_BUFF_SIZE 128
197
198struct sme_info {
199 int sme_status;
200 int event_buff[SME_EVENT_BUFF_SIZE];
201 unsigned int qhead;
202 unsigned int qtail;
203#ifdef KS_WLAN_DEBUG
204 /* for debug */
205 unsigned int max_event_count;
206#endif
207 spinlock_t sme_spin;
208 unsigned long sme_flag;
209};
210
211struct hostt_t {
212 int buff[SME_EVENT_BUFF_SIZE];
213 unsigned int qhead;
214 unsigned int qtail;
215};
216
217#define RSN_IE_BODY_MAX 64
218struct rsn_ie_t {
219 uint8_t id; /* 0xdd = WPA or 0x30 = RSN */
220 uint8_t size; /* max ? 255 ? */
221 uint8_t body[RSN_IE_BODY_MAX];
222} __attribute__ ((packed));
223
224#ifdef WPS
225#define WPS_IE_BODY_MAX 255
226struct wps_ie_t {
227 uint8_t id; /* 221 'dd <len> 00 50 F2 04' */
228 uint8_t size; /* max ? 255 ? */
229 uint8_t body[WPS_IE_BODY_MAX];
230} __attribute__ ((packed));
231#endif /* WPS */
232
233struct local_ap_t {
234 uint8_t bssid[6];
235 uint8_t rssi;
236 uint8_t sq;
237 struct {
238 uint8_t size;
239 uint8_t body[32];
240 uint8_t ssid_pad;
241 } ssid;
242 struct {
243 uint8_t size;
244 uint8_t body[16];
245 uint8_t rate_pad;
246 } rate_set;
247 uint16_t capability;
248 uint8_t channel;
249 uint8_t noise;
250 struct rsn_ie_t wpa_ie;
251 struct rsn_ie_t rsn_ie;
252#ifdef WPS
253 struct wps_ie_t wps_ie;
254#endif /* WPS */
255};
256
257#define LOCAL_APLIST_MAX 31
258#define LOCAL_CURRENT_AP LOCAL_APLIST_MAX
259struct local_aplist_t {
260 int size;
261 struct local_ap_t ap[LOCAL_APLIST_MAX + 1];
262};
263
264struct local_gain_t {
265 uint8_t TxMode;
266 uint8_t RxMode;
267 uint8_t TxGain;
268 uint8_t RxGain;
269};
270
271struct local_eeprom_sum_t {
272 uint8_t type;
273 uint8_t result;
274};
275
276enum {
277 EEPROM_OK,
278 EEPROM_CHECKSUM_NONE,
279 EEPROM_FW_NOT_SUPPORT,
280 EEPROM_NG,
281};
282
283/* Power Save Status */
284enum {
285 PS_NONE,
286 PS_ACTIVE_SET,
287 PS_SAVE_SET,
288 PS_CONF_WAIT,
289 PS_SNOOZE,
290 PS_WAKEUP
291};
292
293struct power_save_status_t {
294 atomic_t status; /* initialvalue 0 */
295 struct completion wakeup_wait;
296 atomic_t confirm_wait;
297 atomic_t snooze_guard;
298};
299
300struct sleep_status_t {
301 atomic_t status; /* initialvalue 0 */
302 atomic_t doze_request;
303 atomic_t wakeup_request;
304};
305
306/* WPA */
307struct scan_ext_t {
308 unsigned int flag;
309 char ssid[IW_ESSID_MAX_SIZE + 1];
310};
311
312enum {
313 CIPHER_NONE,
314 CIPHER_WEP40,
315 CIPHER_TKIP,
316 CIPHER_CCMP,
317 CIPHER_WEP104
318};
319
320#define CIPHER_ID_WPA_NONE "\x00\x50\xf2\x00"
321#define CIPHER_ID_WPA_WEP40 "\x00\x50\xf2\x01"
322#define CIPHER_ID_WPA_TKIP "\x00\x50\xf2\x02"
323#define CIPHER_ID_WPA_CCMP "\x00\x50\xf2\x04"
324#define CIPHER_ID_WPA_WEP104 "\x00\x50\xf2\x05"
325
326#define CIPHER_ID_WPA2_NONE "\x00\x0f\xac\x00"
327#define CIPHER_ID_WPA2_WEP40 "\x00\x0f\xac\x01"
328#define CIPHER_ID_WPA2_TKIP "\x00\x0f\xac\x02"
329#define CIPHER_ID_WPA2_CCMP "\x00\x0f\xac\x04"
330#define CIPHER_ID_WPA2_WEP104 "\x00\x0f\xac\x05"
331
332#define CIPHER_ID_LEN 4
333
334enum {
335 KEY_MGMT_802_1X,
336 KEY_MGMT_PSK,
337 KEY_MGMT_WPANONE,
338};
339
340#define KEY_MGMT_ID_WPA_NONE "\x00\x50\xf2\x00"
341#define KEY_MGMT_ID_WPA_1X "\x00\x50\xf2\x01"
342#define KEY_MGMT_ID_WPA_PSK "\x00\x50\xf2\x02"
343#define KEY_MGMT_ID_WPA_WPANONE "\x00\x50\xf2\xff"
344
345#define KEY_MGMT_ID_WPA2_NONE "\x00\x0f\xac\x00"
346#define KEY_MGMT_ID_WPA2_1X "\x00\x0f\xac\x01"
347#define KEY_MGMT_ID_WPA2_PSK "\x00\x0f\xac\x02"
348#define KEY_MGMT_ID_WPA2_WPANONE "\x00\x0f\xac\xff"
349
350#define KEY_MGMT_ID_LEN 4
351
352#define MIC_KEY_SIZE 8
353
354struct wpa_key_t {
355 uint32_t ext_flags; /* IW_ENCODE_EXT_xxx */
356 uint8_t tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
357 uint8_t rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */
358 struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast
359 * (group) keys or unicast address for
360 * individual keys */
361 uint16_t alg;
362 uint16_t key_len; /* WEP: 5 or 13, TKIP: 32, CCMP: 16 */
363 uint8_t key_val[IW_ENCODING_TOKEN_MAX];
364 uint8_t tx_mic_key[MIC_KEY_SIZE];
365 uint8_t rx_mic_key[MIC_KEY_SIZE];
366};
367#define WPA_KEY_INDEX_MAX 4
368#define WPA_RX_SEQ_LEN 6
369
370struct mic_failure_t {
371 uint16_t failure; /* MIC Failure counter 0 or 1 or 2 */
372 uint16_t counter; /* 1sec counter 0-60 */
373 uint32_t last_failure_time;
374 int stop; /* stop flag */
375};
376
377struct wpa_status_t {
378 int wpa_enabled;
379 unsigned int rsn_enabled;
380 int version;
381 int pairwise_suite; /* unicast cipher */
382 int group_suite; /* multicast cipher */
383 int key_mgmt_suite; /* authentication key management suite */
384 int auth_alg;
385 int txkey;
386 struct wpa_key_t key[WPA_KEY_INDEX_MAX];
387 struct scan_ext_t scan_ext;
388 struct mic_failure_t mic_failure;
389};
390
391#include <linux/list.h>
392#define PMK_LIST_MAX 8
393struct pmk_list_t {
394 uint16_t size;
395 struct list_head head;
396 struct pmk_t {
397 struct list_head list;
398 uint8_t bssid[ETH_ALEN];
399 uint8_t pmkid[IW_PMKID_LEN];
400 } pmk[PMK_LIST_MAX];
401};
402
403#ifdef WPS
404struct wps_status_t {
405 int wps_enabled;
406 int ielen;
407 uint8_t ie[255];
408};
409#endif /* WPS */
410
411struct ks_wlan_private {
412
413 struct hw_info_t ks_wlan_hw; /* hardware information */
414
415 struct net_device *net_dev;
416 int reg_net; /* register_netdev */
417 struct net_device_stats nstats;
418 struct iw_statistics wstats;
419
420 struct completion confirm_wait;
421
422 /* trx device & sme */
423 struct tx_device tx_dev;
424 struct rx_device rx_dev;
425 struct sme_info sme_i;
426 u8 *rxp;
427 unsigned int rx_size;
428 struct tasklet_struct sme_task;
429 struct work_struct ks_wlan_wakeup_task;
430 int scan_ind_count;
431
432 unsigned char eth_addr[ETH_ALEN];
433
434 struct local_aplist_t aplist;
435 struct local_ap_t current_ap;
436 struct power_save_status_t psstatus;
437 struct sleep_status_t sleepstatus;
438 struct wpa_status_t wpa;
439 struct pmk_list_t pmklist;
440 /* wireless parameter */
441 struct ks_wlan_parameter reg;
442 uint8_t current_rate;
443
444 char nick[IW_ESSID_MAX_SIZE + 1];
445
446 spinlock_t multicast_spin;
447
448 spinlock_t dev_read_lock;
449 wait_queue_head_t devread_wait;
450
451 unsigned int need_commit; /* for ioctl */
452
453 /* DeviceIoControl */
454 int device_open_status;
455 atomic_t event_count;
456 atomic_t rec_count;
457 int dev_count;
458#define DEVICE_STOCK_COUNT 20
459 unsigned char *dev_data[DEVICE_STOCK_COUNT];
460 int dev_size[DEVICE_STOCK_COUNT];
461
462 /* ioctl : IOCTL_FIRMWARE_VERSION */
463 unsigned char firmware_version[128 + 1];
464 int version_size;
465
466 int mac_address_valid; /* Mac Address Status */
467
468 int dev_state;
469
470 struct sk_buff *skb;
471 unsigned int cur_rx; /* Index into the Rx buffer of next Rx pkt. */
472 /* spinlock_t lock; */
473#define FORCE_DISCONNECT 0x80000000
474#define CONNECT_STATUS_MASK 0x7FFFFFFF
475 uint32_t connect_status; /* connect status */
476 int infra_status; /* Infractructure status */
477
478 uint8_t data_buff[0x1000];
479
480 uint8_t scan_ssid_len;
481 uint8_t scan_ssid[IW_ESSID_MAX_SIZE + 1];
482 struct local_gain_t gain;
483#ifdef WPS
484 struct net_device *l2_dev;
485 int l2_fd;
486 struct wps_status_t wps;
487#endif /* WPS */
488 uint8_t sleep_mode;
489
490 uint8_t region;
491 struct local_eeprom_sum_t eeprom_sum;
492 uint8_t eeprom_checksum;
493
494 struct hostt_t hostt;
495
496 unsigned long last_doze;
497 unsigned long last_wakeup;
498
499 uint wakeup_count; /* for detect wakeup loop */
500};
501
502extern int ks_wlan_net_start(struct net_device *dev);
503extern int ks_wlan_net_stop(struct net_device *dev);
504
505#endif /* _KS_WLAN_H */
diff --git a/drivers/staging/ks7010/ks_wlan_ioctl.h b/drivers/staging/ks7010/ks_wlan_ioctl.h
new file mode 100644
index 000000000000..49369e497808
--- /dev/null
+++ b/drivers/staging/ks7010/ks_wlan_ioctl.h
@@ -0,0 +1,67 @@
1/*
2 * Driver for KeyStream 11b/g wireless LAN
3 *
4 * Copyright (c) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _KS_WLAN_IOCTL_H
13#define _KS_WLAN_IOCTL_H
14
15#include <linux/wireless.h>
16/* The low order bit identify a SET (0) or a GET (1) ioctl. */
17
18/* SIOCIWFIRSTPRIV+0 */
19/* former KS_WLAN_GET_DRIVER_VERSION SIOCIWFIRSTPRIV+1 */
20/* SIOCIWFIRSTPRIV+2 */
21#define KS_WLAN_GET_FIRM_VERSION SIOCIWFIRSTPRIV+3
22#ifdef WPS
23#define KS_WLAN_SET_WPS_ENABLE SIOCIWFIRSTPRIV+4
24#define KS_WLAN_GET_WPS_ENABLE SIOCIWFIRSTPRIV+5
25#define KS_WLAN_SET_WPS_PROBE_REQ SIOCIWFIRSTPRIV+6
26#endif
27#define KS_WLAN_GET_EEPROM_CKSUM SIOCIWFIRSTPRIV+7
28#define KS_WLAN_SET_PREAMBLE SIOCIWFIRSTPRIV+8
29#define KS_WLAN_GET_PREAMBLE SIOCIWFIRSTPRIV+9
30#define KS_WLAN_SET_POWER_SAVE SIOCIWFIRSTPRIV+10
31#define KS_WLAN_GET_POWER_SAVE SIOCIWFIRSTPRIV+11
32#define KS_WLAN_SET_SCAN_TYPE SIOCIWFIRSTPRIV+12
33#define KS_WLAN_GET_SCAN_TYPE SIOCIWFIRSTPRIV+13
34#define KS_WLAN_SET_RX_GAIN SIOCIWFIRSTPRIV+14
35#define KS_WLAN_GET_RX_GAIN SIOCIWFIRSTPRIV+15
36#define KS_WLAN_HOSTT SIOCIWFIRSTPRIV+16 /* unused */
37//#define KS_WLAN_SET_REGION SIOCIWFIRSTPRIV+17
38#define KS_WLAN_SET_BEACON_LOST SIOCIWFIRSTPRIV+18
39#define KS_WLAN_GET_BEACON_LOST SIOCIWFIRSTPRIV+19
40
41#define KS_WLAN_SET_TX_GAIN SIOCIWFIRSTPRIV+20
42#define KS_WLAN_GET_TX_GAIN SIOCIWFIRSTPRIV+21
43
44/* for KS7010 */
45#define KS_WLAN_SET_PHY_TYPE SIOCIWFIRSTPRIV+22
46#define KS_WLAN_GET_PHY_TYPE SIOCIWFIRSTPRIV+23
47#define KS_WLAN_SET_CTS_MODE SIOCIWFIRSTPRIV+24
48#define KS_WLAN_GET_CTS_MODE SIOCIWFIRSTPRIV+25
49/* SIOCIWFIRSTPRIV+26 */
50/* SIOCIWFIRSTPRIV+27 */
51#define KS_WLAN_SET_SLEEP_MODE SIOCIWFIRSTPRIV+28 /* sleep mode */
52#define KS_WLAN_GET_SLEEP_MODE SIOCIWFIRSTPRIV+29 /* sleep mode */
53/* SIOCIWFIRSTPRIV+30 */
54/* SIOCIWFIRSTPRIV+31 */
55
56#ifdef __KERNEL__
57
58#include "ks_wlan.h"
59#include <linux/netdevice.h>
60
61extern int ks_wlan_read_config_file(struct ks_wlan_private *priv);
62extern int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
63 unsigned int commit_flag);
64
65#endif /* __KERNEL__ */
66
67#endif /* _KS_WLAN_IOCTL_H */
diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
new file mode 100644
index 000000000000..1e21eb1c4667
--- /dev/null
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -0,0 +1,3528 @@
1/*
2 * Driver for KeyStream 11b/g wireless LAN
3 *
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/version.h>
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/compiler.h>
16#include <linux/init.h>
17#include <linux/ioport.h>
18#include <linux/netdevice.h>
19#include <linux/etherdevice.h>
20#include <linux/if_arp.h>
21#include <linux/rtnetlink.h>
22#include <linux/delay.h>
23#include <linux/completion.h>
24#include <linux/mii.h>
25#include <linux/pci.h>
26#include <linux/ctype.h>
27#include <linux/timer.h>
28#include <asm/atomic.h>
29#include <linux/io.h>
30#include <asm/uaccess.h>
31
32static int wep_on_off;
33#define WEP_OFF 0
34#define WEP_ON_64BIT 1
35#define WEP_ON_128BIT 2
36
37#include "ks_wlan.h"
38#include "ks_hostif.h"
39#include "ks_wlan_ioctl.h"
40
41/* Include Wireless Extension definition and check version */
42#include <linux/wireless.h>
43#define WIRELESS_SPY /* enable iwspy support */
44#include <net/iw_handler.h> /* New driver API */
45
46/* Frequency list (map channels to frequencies) */
47static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
48 2447, 2452, 2457, 2462, 2467, 2472, 2484
49};
50
51/* A few details needed for WEP (Wireless Equivalent Privacy) */
52#define MAX_KEY_SIZE 13 /* 128 (?) bits */
53#define MIN_KEY_SIZE 5 /* 40 bits RC4 - WEP */
54typedef struct wep_key_t {
55 u16 len;
56 u8 key[16]; /* 40-bit and 104-bit keys */
57} wep_key_t;
58
59/* Backward compatibility */
60#ifndef IW_ENCODE_NOKEY
61#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
62#define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
63#endif /* IW_ENCODE_NOKEY */
64
65/* List of Wireless Handlers (new API) */
66static const struct iw_handler_def ks_wlan_handler_def;
67
68#define KSC_OPNOTSUPP /* Operation Not Support */
69
70/*
71 * function prototypes
72 */
73extern int ks_wlan_hw_tx(struct ks_wlan_private *priv, void *p,
74 unsigned long size,
75 void (*complete_handler) (void *arg1, void *arg2),
76 void *arg1, void *arg2);
77static int ks_wlan_open(struct net_device *dev);
78static void ks_wlan_tx_timeout(struct net_device *dev);
79static int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev);
80static int ks_wlan_close(struct net_device *dev);
81static void ks_wlan_set_multicast_list(struct net_device *dev);
82static struct net_device_stats *ks_wlan_get_stats(struct net_device *dev);
83static int ks_wlan_set_mac_address(struct net_device *dev, void *addr);
84static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
85 int cmd);
86
87static atomic_t update_phyinfo;
88static struct timer_list update_phyinfo_timer;
89static
90int ks_wlan_update_phy_information(struct ks_wlan_private *priv)
91{
92 struct iw_statistics *wstats = &priv->wstats;
93
94 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
95
96 if (priv->dev_state < DEVICE_STATE_READY) {
97 return -1; /* not finished initialize */
98 }
99 if (atomic_read(&update_phyinfo))
100 return 1;
101
102 /* The status */
103 wstats->status = priv->reg.operation_mode; /* Operation mode */
104
105 /* Signal quality and co. But where is the noise level ??? */
106 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
107
108 /* interruptible_sleep_on_timeout(&priv->confirm_wait, HZ/2); */
109 if (!wait_for_completion_interruptible_timeout
110 (&priv->confirm_wait, HZ / 2)) {
111 DPRINTK(1, "wait time out!!\n");
112 }
113
114 atomic_inc(&update_phyinfo);
115 update_phyinfo_timer.expires = jiffies + HZ; /* 1sec */
116 add_timer(&update_phyinfo_timer);
117
118 return 0;
119}
120
121static
122void ks_wlan_update_phyinfo_timeout(unsigned long ptr)
123{
124 DPRINTK(4, "in_interrupt = %ld\n", in_interrupt());
125 atomic_set(&update_phyinfo, 0);
126}
127
128int ks_wlan_setup_parameter(struct ks_wlan_private *priv,
129 unsigned int commit_flag)
130{
131 DPRINTK(2, "\n");
132
133 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
134
135 if (commit_flag & SME_RTS)
136 hostif_sme_enqueue(priv, SME_RTS_THRESHOLD_REQUEST);
137 if (commit_flag & SME_FRAG)
138 hostif_sme_enqueue(priv, SME_FRAGMENTATION_THRESHOLD_REQUEST);
139
140 if (commit_flag & SME_WEP_INDEX)
141 hostif_sme_enqueue(priv, SME_WEP_INDEX_REQUEST);
142 if (commit_flag & SME_WEP_VAL1)
143 hostif_sme_enqueue(priv, SME_WEP_KEY1_REQUEST);
144 if (commit_flag & SME_WEP_VAL2)
145 hostif_sme_enqueue(priv, SME_WEP_KEY2_REQUEST);
146 if (commit_flag & SME_WEP_VAL3)
147 hostif_sme_enqueue(priv, SME_WEP_KEY3_REQUEST);
148 if (commit_flag & SME_WEP_VAL4)
149 hostif_sme_enqueue(priv, SME_WEP_KEY4_REQUEST);
150 if (commit_flag & SME_WEP_FLAG)
151 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
152
153 if (commit_flag & SME_RSN) {
154 hostif_sme_enqueue(priv, SME_RSN_ENABLED_REQUEST);
155 hostif_sme_enqueue(priv, SME_RSN_MODE_REQUEST);
156 }
157 if (commit_flag & SME_RSN_MULTICAST)
158 hostif_sme_enqueue(priv, SME_RSN_MCAST_REQUEST);
159 if (commit_flag & SME_RSN_UNICAST)
160 hostif_sme_enqueue(priv, SME_RSN_UCAST_REQUEST);
161 if (commit_flag & SME_RSN_AUTH)
162 hostif_sme_enqueue(priv, SME_RSN_AUTH_REQUEST);
163
164 hostif_sme_enqueue(priv, SME_MODE_SET_REQUEST);
165
166 hostif_sme_enqueue(priv, SME_START_REQUEST);
167
168 return 0;
169}
170
171/*
172 * Initial Wireless Extension code for Ks_Wlannet driver by :
173 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
174 * Conversion to new driver API by :
175 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
176 * Javier also did a good amount of work here, adding some new extensions
177 * and fixing my code. Let's just say that without him this code just
178 * would not work at all... - Jean II
179 */
180
181/*------------------------------------------------------------------*/
182/* Wireless Handler : get protocol name */
183static int ks_wlan_get_name(struct net_device *dev,
184 struct iw_request_info *info, char *cwrq,
185 char *extra)
186{
187 struct ks_wlan_private *priv =
188 (struct ks_wlan_private *)netdev_priv(dev);
189
190 if (priv->sleep_mode == SLP_SLEEP) {
191 return -EPERM;
192 }
193 /* for SLEEP MODE */
194 if (priv->dev_state < DEVICE_STATE_READY) {
195 strcpy(cwrq, "NOT READY!");
196 } else if (priv->reg.phy_type == D_11B_ONLY_MODE) {
197 strcpy(cwrq, "IEEE 802.11b");
198 } else if (priv->reg.phy_type == D_11G_ONLY_MODE) {
199 strcpy(cwrq, "IEEE 802.11g");
200 } else {
201 strcpy(cwrq, "IEEE 802.11b/g");
202 }
203
204 return 0;
205}
206
207/*------------------------------------------------------------------*/
208/* Wireless Handler : set frequency */
209static int ks_wlan_set_freq(struct net_device *dev,
210 struct iw_request_info *info, struct iw_freq *fwrq,
211 char *extra)
212{
213 struct ks_wlan_private *priv =
214 (struct ks_wlan_private *)netdev_priv(dev);
215 int rc = -EINPROGRESS; /* Call commit handler */
216
217 if (priv->sleep_mode == SLP_SLEEP) {
218 return -EPERM;
219 }
220
221 /* for SLEEP MODE */
222 /* If setting by frequency, convert to a channel */
223 if ((fwrq->e == 1) &&
224 (fwrq->m >= (int)2.412e8) && (fwrq->m <= (int)2.487e8)) {
225 int f = fwrq->m / 100000;
226 int c = 0;
227 while ((c < 14) && (f != frequency_list[c]))
228 c++;
229 /* Hack to fall through... */
230 fwrq->e = 0;
231 fwrq->m = c + 1;
232 }
233 /* Setting by channel number */
234 if ((fwrq->m > 1000) || (fwrq->e > 0))
235 rc = -EOPNOTSUPP;
236 else {
237 int channel = fwrq->m;
238 /* We should do a better check than that,
239 * based on the card capability !!! */
240 if ((channel < 1) || (channel > 14)) {
241 printk(KERN_DEBUG
242 "%s: New channel value of %d is invalid!\n",
243 dev->name, fwrq->m);
244 rc = -EINVAL;
245 } else {
246 /* Yes ! We can set it !!! */
247 priv->reg.channel = (u8) (channel);
248 priv->need_commit |= SME_MODE_SET;
249 }
250 }
251
252 return rc;
253}
254
255/*------------------------------------------------------------------*/
256/* Wireless Handler : get frequency */
257static int ks_wlan_get_freq(struct net_device *dev,
258 struct iw_request_info *info, struct iw_freq *fwrq,
259 char *extra)
260{
261 struct ks_wlan_private *priv =
262 (struct ks_wlan_private *)netdev_priv(dev);
263 int f;
264
265 if (priv->sleep_mode == SLP_SLEEP) {
266 return -EPERM;
267 }
268 /* for SLEEP MODE */
269 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
270 f = (int)priv->current_ap.channel;
271 } else
272 f = (int)priv->reg.channel;
273 fwrq->m = frequency_list[f - 1] * 100000;
274 fwrq->e = 1;
275
276 return 0;
277}
278
279/*------------------------------------------------------------------*/
280/* Wireless Handler : set ESSID */
281static int ks_wlan_set_essid(struct net_device *dev,
282 struct iw_request_info *info,
283 struct iw_point *dwrq, char *extra)
284{
285 struct ks_wlan_private *priv =
286 (struct ks_wlan_private *)netdev_priv(dev);
287 size_t len;
288
289 DPRINTK(2, " %d\n", dwrq->flags);
290
291 if (priv->sleep_mode == SLP_SLEEP) {
292 return -EPERM;
293 }
294
295 /* for SLEEP MODE */
296 /* Check if we asked for `any' */
297 if (dwrq->flags == 0) {
298 /* Just send an empty SSID list */
299 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
300 priv->reg.ssid.size = 0;
301 } else {
302#if 1
303 len = dwrq->length;
304 /* iwconfig uses nul termination in SSID.. */
305 if (len > 0 && extra[len - 1] == '\0')
306 len--;
307
308 /* Check the size of the string */
309 if (len > IW_ESSID_MAX_SIZE) {
310 return -EINVAL;
311 }
312#else
313 /* Check the size of the string */
314 if (dwrq->length > IW_ESSID_MAX_SIZE + 1) {
315 return -E2BIG;
316 }
317#endif
318
319 /* Set the SSID */
320 memset(priv->reg.ssid.body, 0, sizeof(priv->reg.ssid.body));
321
322#if 1
323 memcpy(priv->reg.ssid.body, extra, len);
324 priv->reg.ssid.size = len;
325#else
326 memcpy(priv->reg.ssid.body, extra, dwrq->length);
327 priv->reg.ssid.size = dwrq->length;
328#endif
329 }
330 /* Write it to the card */
331 priv->need_commit |= SME_MODE_SET;
332
333// return -EINPROGRESS; /* Call commit handler */
334 ks_wlan_setup_parameter(priv, priv->need_commit);
335 priv->need_commit = 0;
336 return 0;
337}
338
339/*------------------------------------------------------------------*/
340/* Wireless Handler : get ESSID */
341static int ks_wlan_get_essid(struct net_device *dev,
342 struct iw_request_info *info,
343 struct iw_point *dwrq, char *extra)
344{
345 struct ks_wlan_private *priv =
346 (struct ks_wlan_private *)netdev_priv(dev);
347
348 if (priv->sleep_mode == SLP_SLEEP) {
349 return -EPERM;
350 }
351
352 /* for SLEEP MODE */
353 /* Note : if dwrq->flags != 0, we should
354 * get the relevant SSID from the SSID list... */
355 if (priv->reg.ssid.size) {
356 /* Get the current SSID */
357 memcpy(extra, priv->reg.ssid.body, priv->reg.ssid.size);
358#if 0
359 extra[priv->reg.ssid.size] = '\0';
360#endif
361 /* If none, we may want to get the one that was set */
362
363 /* Push it out ! */
364#if 1
365 dwrq->length = priv->reg.ssid.size;
366#else
367 dwrq->length = priv->reg.ssid.size + 1;
368#endif
369 dwrq->flags = 1; /* active */
370 } else {
371#if 1
372 dwrq->length = 0;
373#else
374 extra[0] = '\0';
375 dwrq->length = 1;
376#endif
377 dwrq->flags = 0; /* ANY */
378 }
379
380 return 0;
381}
382
383/*------------------------------------------------------------------*/
384/* Wireless Handler : set AP address */
385static int ks_wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
386 struct sockaddr *ap_addr, char *extra)
387{
388 struct ks_wlan_private *priv =
389 (struct ks_wlan_private *)netdev_priv(dev);
390
391 DPRINTK(2, "\n");
392
393 if (priv->sleep_mode == SLP_SLEEP) {
394 return -EPERM;
395 }
396 /* for SLEEP MODE */
397 if (priv->reg.operation_mode == MODE_ADHOC ||
398 priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
399 memcpy(priv->reg.bssid, (u8 *) & ap_addr->sa_data, ETH_ALEN);
400
401 if (is_valid_ether_addr((u8 *) priv->reg.bssid)) {
402 priv->need_commit |= SME_MODE_SET;
403 }
404 } else {
405 memset(priv->reg.bssid, 0x0, ETH_ALEN);
406 return -EOPNOTSUPP;
407 }
408
409 DPRINTK(2, "bssid = %02x:%02x:%02x:%02x:%02x:%02x\n",
410 priv->reg.bssid[0], priv->reg.bssid[1], priv->reg.bssid[2],
411 priv->reg.bssid[3], priv->reg.bssid[4], priv->reg.bssid[5]);
412
413 /* Write it to the card */
414 if (priv->need_commit) {
415 priv->need_commit |= SME_MODE_SET;
416 return -EINPROGRESS; /* Call commit handler */
417 }
418 return 0;
419}
420
421/*------------------------------------------------------------------*/
422/* Wireless Handler : get AP address */
423static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
424 struct sockaddr *awrq, char *extra)
425{
426 struct ks_wlan_private *priv =
427 (struct ks_wlan_private *)netdev_priv(dev);
428
429 if (priv->sleep_mode == SLP_SLEEP) {
430 return -EPERM;
431 }
432 /* for SLEEP MODE */
433 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
434 memcpy(awrq->sa_data, &(priv->current_ap.bssid[0]), ETH_ALEN);
435 } else {
436 memset(awrq->sa_data, 0, ETH_ALEN);
437 }
438
439 awrq->sa_family = ARPHRD_ETHER;
440
441 return 0;
442}
443
444/*------------------------------------------------------------------*/
445/* Wireless Handler : set Nickname */
446static int ks_wlan_set_nick(struct net_device *dev,
447 struct iw_request_info *info, struct iw_point *dwrq,
448 char *extra)
449{
450 struct ks_wlan_private *priv =
451 (struct ks_wlan_private *)netdev_priv(dev);
452
453 if (priv->sleep_mode == SLP_SLEEP) {
454 return -EPERM;
455 }
456
457 /* for SLEEP MODE */
458 /* Check the size of the string */
459 if (dwrq->length > 16 + 1) {
460 return -E2BIG;
461 }
462 memset(priv->nick, 0, sizeof(priv->nick));
463 memcpy(priv->nick, extra, dwrq->length);
464
465 return -EINPROGRESS; /* Call commit handler */
466}
467
468/*------------------------------------------------------------------*/
469/* Wireless Handler : get Nickname */
470static int ks_wlan_get_nick(struct net_device *dev,
471 struct iw_request_info *info, struct iw_point *dwrq,
472 char *extra)
473{
474 struct ks_wlan_private *priv =
475 (struct ks_wlan_private *)netdev_priv(dev);
476
477 if (priv->sleep_mode == SLP_SLEEP) {
478 return -EPERM;
479 }
480 /* for SLEEP MODE */
481 strncpy(extra, priv->nick, 16);
482 extra[16] = '\0';
483 dwrq->length = strlen(extra) + 1;
484
485 return 0;
486}
487
488/*------------------------------------------------------------------*/
489/* Wireless Handler : set Bit-Rate */
490static int ks_wlan_set_rate(struct net_device *dev,
491 struct iw_request_info *info, struct iw_param *vwrq,
492 char *extra)
493{
494 struct ks_wlan_private *priv =
495 (struct ks_wlan_private *)netdev_priv(dev);
496 int i = 0;
497
498 if (priv->sleep_mode == SLP_SLEEP) {
499 return -EPERM;
500 }
501 /* for SLEEP MODE */
502 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
503 if (vwrq->fixed == 1) {
504 switch (vwrq->value) {
505 case 11000000:
506 case 5500000:
507 priv->reg.rate_set.body[0] =
508 (uint8_t) (vwrq->value / 500000);
509 break;
510 case 2000000:
511 case 1000000:
512 priv->reg.rate_set.body[0] =
513 ((uint8_t) (vwrq->value / 500000)) |
514 BASIC_RATE;
515 break;
516 default:
517 return -EINVAL;
518 }
519 priv->reg.tx_rate = TX_RATE_FIXED;
520 priv->reg.rate_set.size = 1;
521 } else { /* vwrq->fixed == 0 */
522 if (vwrq->value > 0) {
523 switch (vwrq->value) {
524 case 11000000:
525 priv->reg.rate_set.body[3] =
526 TX_RATE_11M;
527 i++;
528 case 5500000:
529 priv->reg.rate_set.body[2] = TX_RATE_5M;
530 i++;
531 case 2000000:
532 priv->reg.rate_set.body[1] =
533 TX_RATE_2M | BASIC_RATE;
534 i++;
535 case 1000000:
536 priv->reg.rate_set.body[0] =
537 TX_RATE_1M | BASIC_RATE;
538 i++;
539 break;
540 default:
541 return -EINVAL;
542 }
543 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
544 priv->reg.rate_set.size = i;
545 } else {
546 priv->reg.rate_set.body[3] = TX_RATE_11M;
547 priv->reg.rate_set.body[2] = TX_RATE_5M;
548 priv->reg.rate_set.body[1] =
549 TX_RATE_2M | BASIC_RATE;
550 priv->reg.rate_set.body[0] =
551 TX_RATE_1M | BASIC_RATE;
552 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
553 priv->reg.rate_set.size = 4;
554 }
555 }
556 } else { /* D_11B_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
557 if (vwrq->fixed == 1) {
558 switch (vwrq->value) {
559 case 54000000:
560 case 48000000:
561 case 36000000:
562 case 18000000:
563 case 9000000:
564 priv->reg.rate_set.body[0] =
565 (uint8_t) (vwrq->value / 500000);
566 break;
567 case 24000000:
568 case 12000000:
569 case 11000000:
570 case 6000000:
571 case 5500000:
572 case 2000000:
573 case 1000000:
574 priv->reg.rate_set.body[0] =
575 ((uint8_t) (vwrq->value / 500000)) |
576 BASIC_RATE;
577 break;
578 default:
579 return -EINVAL;
580 }
581 priv->reg.tx_rate = TX_RATE_FIXED;
582 priv->reg.rate_set.size = 1;
583 } else { /* vwrq->fixed == 0 */
584 if (vwrq->value > 0) {
585 switch (vwrq->value) {
586 case 54000000:
587 priv->reg.rate_set.body[11] =
588 TX_RATE_54M;
589 i++;
590 case 48000000:
591 priv->reg.rate_set.body[10] =
592 TX_RATE_48M;
593 i++;
594 case 36000000:
595 priv->reg.rate_set.body[9] =
596 TX_RATE_36M;
597 i++;
598 case 24000000:
599 case 18000000:
600 case 12000000:
601 case 11000000:
602 case 9000000:
603 case 6000000:
604 if (vwrq->value == 24000000) {
605 priv->reg.rate_set.body[8] =
606 TX_RATE_18M;
607 i++;
608 priv->reg.rate_set.body[7] =
609 TX_RATE_9M;
610 i++;
611 priv->reg.rate_set.body[6] =
612 TX_RATE_24M | BASIC_RATE;
613 i++;
614 priv->reg.rate_set.body[5] =
615 TX_RATE_12M | BASIC_RATE;
616 i++;
617 priv->reg.rate_set.body[4] =
618 TX_RATE_6M | BASIC_RATE;
619 i++;
620 priv->reg.rate_set.body[3] =
621 TX_RATE_11M | BASIC_RATE;
622 i++;
623 } else if (vwrq->value == 18000000) {
624 priv->reg.rate_set.body[7] =
625 TX_RATE_18M;
626 i++;
627 priv->reg.rate_set.body[6] =
628 TX_RATE_9M;
629 i++;
630 priv->reg.rate_set.body[5] =
631 TX_RATE_12M | BASIC_RATE;
632 i++;
633 priv->reg.rate_set.body[4] =
634 TX_RATE_6M | BASIC_RATE;
635 i++;
636 priv->reg.rate_set.body[3] =
637 TX_RATE_11M | BASIC_RATE;
638 i++;
639 } else if (vwrq->value == 12000000) {
640 priv->reg.rate_set.body[6] =
641 TX_RATE_9M;
642 i++;
643 priv->reg.rate_set.body[5] =
644 TX_RATE_12M | BASIC_RATE;
645 i++;
646 priv->reg.rate_set.body[4] =
647 TX_RATE_6M | BASIC_RATE;
648 i++;
649 priv->reg.rate_set.body[3] =
650 TX_RATE_11M | BASIC_RATE;
651 i++;
652 } else if (vwrq->value == 11000000) {
653 priv->reg.rate_set.body[5] =
654 TX_RATE_9M;
655 i++;
656 priv->reg.rate_set.body[4] =
657 TX_RATE_6M | BASIC_RATE;
658 i++;
659 priv->reg.rate_set.body[3] =
660 TX_RATE_11M | BASIC_RATE;
661 i++;
662 } else if (vwrq->value == 9000000) {
663 priv->reg.rate_set.body[4] =
664 TX_RATE_9M;
665 i++;
666 priv->reg.rate_set.body[3] =
667 TX_RATE_6M | BASIC_RATE;
668 i++;
669 } else { /* vwrq->value == 6000000 */
670 priv->reg.rate_set.body[3] =
671 TX_RATE_6M | BASIC_RATE;
672 i++;
673 }
674 case 5500000:
675 priv->reg.rate_set.body[2] =
676 TX_RATE_5M | BASIC_RATE;
677 i++;
678 case 2000000:
679 priv->reg.rate_set.body[1] =
680 TX_RATE_2M | BASIC_RATE;
681 i++;
682 case 1000000:
683 priv->reg.rate_set.body[0] =
684 TX_RATE_1M | BASIC_RATE;
685 i++;
686 break;
687 default:
688 return -EINVAL;
689 }
690 priv->reg.tx_rate = TX_RATE_MANUAL_AUTO;
691 priv->reg.rate_set.size = i;
692 } else {
693 priv->reg.rate_set.body[11] = TX_RATE_54M;
694 priv->reg.rate_set.body[10] = TX_RATE_48M;
695 priv->reg.rate_set.body[9] = TX_RATE_36M;
696 priv->reg.rate_set.body[8] = TX_RATE_18M;
697 priv->reg.rate_set.body[7] = TX_RATE_9M;
698 priv->reg.rate_set.body[6] =
699 TX_RATE_24M | BASIC_RATE;
700 priv->reg.rate_set.body[5] =
701 TX_RATE_12M | BASIC_RATE;
702 priv->reg.rate_set.body[4] =
703 TX_RATE_6M | BASIC_RATE;
704 priv->reg.rate_set.body[3] =
705 TX_RATE_11M | BASIC_RATE;
706 priv->reg.rate_set.body[2] =
707 TX_RATE_5M | BASIC_RATE;
708 priv->reg.rate_set.body[1] =
709 TX_RATE_2M | BASIC_RATE;
710 priv->reg.rate_set.body[0] =
711 TX_RATE_1M | BASIC_RATE;
712 priv->reg.tx_rate = TX_RATE_FULL_AUTO;
713 priv->reg.rate_set.size = 12;
714 }
715 }
716 }
717
718 priv->need_commit |= SME_MODE_SET;
719
720 return -EINPROGRESS; /* Call commit handler */
721}
722
723/*------------------------------------------------------------------*/
724/* Wireless Handler : get Bit-Rate */
725static int ks_wlan_get_rate(struct net_device *dev,
726 struct iw_request_info *info, struct iw_param *vwrq,
727 char *extra)
728{
729 struct ks_wlan_private *priv =
730 (struct ks_wlan_private *)netdev_priv(dev);
731
732 DPRINTK(2, "in_interrupt = %ld update_phyinfo = %d\n",
733 in_interrupt(), atomic_read(&update_phyinfo));
734
735 if (priv->sleep_mode == SLP_SLEEP) {
736 return -EPERM;
737 }
738 /* for SLEEP MODE */
739 if (!atomic_read(&update_phyinfo)) {
740 ks_wlan_update_phy_information(priv);
741 }
742 vwrq->value = ((priv->current_rate) & RATE_MASK) * 500000;
743 if (priv->reg.tx_rate == TX_RATE_FIXED)
744 vwrq->fixed = 1;
745 else
746 vwrq->fixed = 0;
747
748 return 0;
749}
750
751/*------------------------------------------------------------------*/
752/* Wireless Handler : set RTS threshold */
753static int ks_wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
754 struct iw_param *vwrq, char *extra)
755{
756 struct ks_wlan_private *priv =
757 (struct ks_wlan_private *)netdev_priv(dev);
758 int rthr = vwrq->value;
759
760 if (priv->sleep_mode == SLP_SLEEP) {
761 return -EPERM;
762 }
763 /* for SLEEP MODE */
764 if (vwrq->disabled)
765 rthr = 2347;
766 if ((rthr < 0) || (rthr > 2347)) {
767 return -EINVAL;
768 }
769 priv->reg.rts = rthr;
770 priv->need_commit |= SME_RTS;
771
772 return -EINPROGRESS; /* Call commit handler */
773}
774
775/*------------------------------------------------------------------*/
776/* Wireless Handler : get RTS threshold */
777static int ks_wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
778 struct iw_param *vwrq, char *extra)
779{
780 struct ks_wlan_private *priv =
781 (struct ks_wlan_private *)netdev_priv(dev);
782
783 if (priv->sleep_mode == SLP_SLEEP) {
784 return -EPERM;
785 }
786 /* for SLEEP MODE */
787 vwrq->value = priv->reg.rts;
788 vwrq->disabled = (vwrq->value >= 2347);
789 vwrq->fixed = 1;
790
791 return 0;
792}
793
794/*------------------------------------------------------------------*/
795/* Wireless Handler : set Fragmentation threshold */
796static int ks_wlan_set_frag(struct net_device *dev,
797 struct iw_request_info *info, struct iw_param *vwrq,
798 char *extra)
799{
800 struct ks_wlan_private *priv =
801 (struct ks_wlan_private *)netdev_priv(dev);
802 int fthr = vwrq->value;
803
804 if (priv->sleep_mode == SLP_SLEEP) {
805 return -EPERM;
806 }
807 /* for SLEEP MODE */
808 if (vwrq->disabled)
809 fthr = 2346;
810 if ((fthr < 256) || (fthr > 2346)) {
811 return -EINVAL;
812 }
813 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
814 priv->reg.fragment = fthr;
815 priv->need_commit |= SME_FRAG;
816
817 return -EINPROGRESS; /* Call commit handler */
818}
819
820/*------------------------------------------------------------------*/
821/* Wireless Handler : get Fragmentation threshold */
822static int ks_wlan_get_frag(struct net_device *dev,
823 struct iw_request_info *info, struct iw_param *vwrq,
824 char *extra)
825{
826 struct ks_wlan_private *priv =
827 (struct ks_wlan_private *)netdev_priv(dev);
828
829 if (priv->sleep_mode == SLP_SLEEP) {
830 return -EPERM;
831 }
832 /* for SLEEP MODE */
833 vwrq->value = priv->reg.fragment;
834 vwrq->disabled = (vwrq->value >= 2346);
835 vwrq->fixed = 1;
836
837 return 0;
838}
839
840/*------------------------------------------------------------------*/
841/* Wireless Handler : set Mode of Operation */
842static int ks_wlan_set_mode(struct net_device *dev,
843 struct iw_request_info *info, __u32 * uwrq,
844 char *extra)
845{
846 struct ks_wlan_private *priv =
847 (struct ks_wlan_private *)netdev_priv(dev);
848
849 DPRINTK(2, "mode=%d\n", *uwrq);
850
851 if (priv->sleep_mode == SLP_SLEEP) {
852 return -EPERM;
853 }
854 /* for SLEEP MODE */
855 switch (*uwrq) {
856 case IW_MODE_ADHOC:
857 priv->reg.operation_mode = MODE_ADHOC;
858 priv->need_commit |= SME_MODE_SET;
859 break;
860 case IW_MODE_INFRA:
861 priv->reg.operation_mode = MODE_INFRASTRUCTURE;
862 priv->need_commit |= SME_MODE_SET;
863 break;
864 case IW_MODE_AUTO:
865 case IW_MODE_MASTER:
866 case IW_MODE_REPEAT:
867 case IW_MODE_SECOND:
868 case IW_MODE_MONITOR:
869 default:
870 return -EINVAL;
871 }
872
873 return -EINPROGRESS; /* Call commit handler */
874}
875
876/*------------------------------------------------------------------*/
877/* Wireless Handler : get Mode of Operation */
878static int ks_wlan_get_mode(struct net_device *dev,
879 struct iw_request_info *info, __u32 * uwrq,
880 char *extra)
881{
882 struct ks_wlan_private *priv =
883 (struct ks_wlan_private *)netdev_priv(dev);
884
885 if (priv->sleep_mode == SLP_SLEEP) {
886 return -EPERM;
887 }
888
889 /* for SLEEP MODE */
890 /* If not managed, assume it's ad-hoc */
891 switch (priv->reg.operation_mode) {
892 case MODE_INFRASTRUCTURE:
893 *uwrq = IW_MODE_INFRA;
894 break;
895 case MODE_ADHOC:
896 *uwrq = IW_MODE_ADHOC;
897 break;
898 default:
899 *uwrq = IW_MODE_ADHOC;
900 }
901
902 return 0;
903}
904
905/*------------------------------------------------------------------*/
906/* Wireless Handler : set Encryption Key */
907static int ks_wlan_set_encode(struct net_device *dev,
908 struct iw_request_info *info,
909 struct iw_point *dwrq, char *extra)
910{
911 struct ks_wlan_private *priv =
912 (struct ks_wlan_private *)netdev_priv(dev);
913
914 wep_key_t key;
915 int index = (dwrq->flags & IW_ENCODE_INDEX);
916 int current_index = priv->reg.wep_index;
917 int i;
918
919 DPRINTK(2, "flags=%04X\n", dwrq->flags);
920
921 if (priv->sleep_mode == SLP_SLEEP) {
922 return -EPERM;
923 }
924
925 /* for SLEEP MODE */
926 /* index check */
927 if ((index < 0) || (index > 4))
928 return -EINVAL;
929 else if (index == 0)
930 index = current_index;
931 else
932 index--;
933
934 /* Is WEP supported ? */
935 /* Basic checking: do we have a key to set ? */
936 if (dwrq->length > 0) {
937 if (dwrq->length > MAX_KEY_SIZE) { /* Check the size of the key */
938 return -EINVAL;
939 }
940 if (dwrq->length > MIN_KEY_SIZE) { /* Set the length */
941 key.len = MAX_KEY_SIZE;
942 priv->reg.privacy_invoked = 0x01;
943 priv->need_commit |= SME_WEP_FLAG;
944 wep_on_off = WEP_ON_128BIT;
945 } else {
946 if (dwrq->length > 0) {
947 key.len = MIN_KEY_SIZE;
948 priv->reg.privacy_invoked = 0x01;
949 priv->need_commit |= SME_WEP_FLAG;
950 wep_on_off = WEP_ON_64BIT;
951 } else { /* Disable the key */
952 key.len = 0;
953 }
954 }
955 /* Check if the key is not marked as invalid */
956 if (!(dwrq->flags & IW_ENCODE_NOKEY)) {
957 /* Cleanup */
958 memset(key.key, 0, MAX_KEY_SIZE);
959 /* Copy the key in the driver */
960 if (copy_from_user
961 (key.key, dwrq->pointer, dwrq->length)) {
962 key.len = 0;
963 return -EFAULT;
964 }
965 /* Send the key to the card */
966 priv->reg.wep_key[index].size = key.len;
967 for (i = 0; i < (priv->reg.wep_key[index].size); i++) {
968 priv->reg.wep_key[index].val[i] = key.key[i];
969 }
970 priv->need_commit |= (SME_WEP_VAL1 << index);
971 priv->reg.wep_index = index;
972 priv->need_commit |= SME_WEP_INDEX;
973 }
974 } else {
975 if (dwrq->flags & IW_ENCODE_DISABLED) {
976 priv->reg.wep_key[0].size = 0;
977 priv->reg.wep_key[1].size = 0;
978 priv->reg.wep_key[2].size = 0;
979 priv->reg.wep_key[3].size = 0;
980 priv->reg.privacy_invoked = 0x00;
981 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
982 priv->need_commit |= SME_MODE_SET;
983 }
984 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
985 wep_on_off = WEP_OFF;
986 priv->need_commit |= SME_WEP_FLAG;
987 } else {
988 /* Do we want to just set the transmit key index ? */
989 if ((index >= 0) && (index < 4)) {
990 /* set_wep_key(priv, index, 0, 0, 1); xxx */
991 if (priv->reg.wep_key[index].size) {
992 priv->reg.wep_index = index;
993 priv->need_commit |= SME_WEP_INDEX;
994 } else
995 return -EINVAL;
996 }
997 }
998 }
999
1000 /* Commit the changes if needed */
1001 if (dwrq->flags & IW_ENCODE_MODE)
1002 priv->need_commit |= SME_WEP_FLAG;
1003
1004 if (dwrq->flags & IW_ENCODE_OPEN) {
1005 if (priv->reg.authenticate_type == AUTH_TYPE_SHARED_KEY) {
1006 priv->need_commit |= SME_MODE_SET;
1007 }
1008 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1009 } else if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1010 if (priv->reg.authenticate_type == AUTH_TYPE_OPEN_SYSTEM) {
1011 priv->need_commit |= SME_MODE_SET;
1012 }
1013 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1014 }
1015// return -EINPROGRESS; /* Call commit handler */
1016 if (priv->need_commit) {
1017 ks_wlan_setup_parameter(priv, priv->need_commit);
1018 priv->need_commit = 0;
1019 }
1020 return 0;
1021}
1022
1023/*------------------------------------------------------------------*/
1024/* Wireless Handler : get Encryption Key */
1025static int ks_wlan_get_encode(struct net_device *dev,
1026 struct iw_request_info *info,
1027 struct iw_point *dwrq, char *extra)
1028{
1029 struct ks_wlan_private *priv =
1030 (struct ks_wlan_private *)netdev_priv(dev);
1031 char zeros[16];
1032 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1033
1034 if (priv->sleep_mode == SLP_SLEEP) {
1035 return -EPERM;
1036 }
1037 /* for SLEEP MODE */
1038 dwrq->flags = IW_ENCODE_DISABLED;
1039
1040 /* Check encryption mode */
1041 switch (priv->reg.authenticate_type) {
1042 case AUTH_TYPE_OPEN_SYSTEM:
1043 dwrq->flags = IW_ENCODE_OPEN;
1044 break;
1045 case AUTH_TYPE_SHARED_KEY:
1046 dwrq->flags = IW_ENCODE_RESTRICTED;
1047 break;
1048 }
1049
1050 memset(zeros, 0, sizeof(zeros));
1051
1052 /* Which key do we want ? -1 -> tx index */
1053 if ((index < 0) || (index >= 4))
1054 index = priv->reg.wep_index;
1055 if (priv->reg.privacy_invoked) {
1056 dwrq->flags &= ~IW_ENCODE_DISABLED;
1057 /* dwrq->flags |= IW_ENCODE_NOKEY; */
1058 }
1059 dwrq->flags |= index + 1;
1060 DPRINTK(2, "encoding flag = 0x%04X\n", dwrq->flags);
1061 /* Copy the key to the user buffer */
1062 if ((index >= 0) && (index < 4))
1063 dwrq->length = priv->reg.wep_key[index].size;
1064 if (dwrq->length > 16) {
1065 dwrq->length = 0;
1066 }
1067#if 1 /* IW_ENCODE_NOKEY; */
1068 if (dwrq->length) {
1069 if ((index >= 0) && (index < 4))
1070 memcpy(extra, priv->reg.wep_key[index].val,
1071 dwrq->length);
1072 } else
1073 memcpy(extra, zeros, dwrq->length);
1074#endif
1075 return 0;
1076}
1077
1078#ifndef KSC_OPNOTSUPP
1079/*------------------------------------------------------------------*/
1080/* Wireless Handler : set Tx-Power */
1081static int ks_wlan_set_txpow(struct net_device *dev,
1082 struct iw_request_info *info,
1083 struct iw_param *vwrq, char *extra)
1084{
1085 return -EOPNOTSUPP; /* Not Support */
1086}
1087
1088/*------------------------------------------------------------------*/
1089/* Wireless Handler : get Tx-Power */
1090static int ks_wlan_get_txpow(struct net_device *dev,
1091 struct iw_request_info *info,
1092 struct iw_param *vwrq, char *extra)
1093{
1094 if (priv->sleep_mode == SLP_SLEEP) {
1095 return -EPERM;
1096 }
1097
1098 /* for SLEEP MODE */
1099 /* Not Support */
1100 vwrq->value = 0;
1101 vwrq->disabled = (vwrq->value == 0);
1102 vwrq->fixed = 1;
1103 return 0;
1104}
1105
1106/*------------------------------------------------------------------*/
1107/* Wireless Handler : set Retry limits */
1108static int ks_wlan_set_retry(struct net_device *dev,
1109 struct iw_request_info *info,
1110 struct iw_param *vwrq, char *extra)
1111{
1112 return -EOPNOTSUPP; /* Not Support */
1113}
1114
1115/*------------------------------------------------------------------*/
1116/* Wireless Handler : get Retry limits */
1117static int ks_wlan_get_retry(struct net_device *dev,
1118 struct iw_request_info *info,
1119 struct iw_param *vwrq, char *extra)
1120{
1121 if (priv->sleep_mode == SLP_SLEEP) {
1122 return -EPERM;
1123 }
1124
1125 /* for SLEEP MODE */
1126 /* Not Support */
1127 vwrq->value = 0;
1128 vwrq->disabled = (vwrq->value == 0);
1129 vwrq->fixed = 1;
1130 return 0;
1131}
1132#endif /* KSC_OPNOTSUPP */
1133
1134/*------------------------------------------------------------------*/
1135/* Wireless Handler : get range info */
1136static int ks_wlan_get_range(struct net_device *dev,
1137 struct iw_request_info *info,
1138 struct iw_point *dwrq, char *extra)
1139{
1140 struct ks_wlan_private *priv =
1141 (struct ks_wlan_private *)netdev_priv(dev);
1142 struct iw_range *range = (struct iw_range *)extra;
1143 int i, k;
1144
1145 DPRINTK(2, "\n");
1146
1147 if (priv->sleep_mode == SLP_SLEEP) {
1148 return -EPERM;
1149 }
1150 /* for SLEEP MODE */
1151 dwrq->length = sizeof(struct iw_range);
1152 memset(range, 0, sizeof(*range));
1153 range->min_nwid = 0x0000;
1154 range->max_nwid = 0x0000;
1155 range->num_channels = 14;
1156 /* Should be based on cap_rid.country to give only
1157 * what the current card support */
1158 k = 0;
1159 for (i = 0; i < 13; i++) { /* channel 1 -- 13 */
1160 range->freq[k].i = i + 1; /* List index */
1161 range->freq[k].m = frequency_list[i] * 100000;
1162 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1163 }
1164 range->num_frequency = k;
1165 if (priv->reg.phy_type == D_11B_ONLY_MODE || priv->reg.phy_type == D_11BG_COMPATIBLE_MODE) { /* channel 14 */
1166 range->freq[13].i = 14; /* List index */
1167 range->freq[13].m = frequency_list[13] * 100000;
1168 range->freq[13].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
1169 range->num_frequency = 14;
1170 }
1171
1172 /* Hum... Should put the right values there */
1173 range->max_qual.qual = 100;
1174 range->max_qual.level = 256 - 128; /* 0 dBm? */
1175 range->max_qual.noise = 256 - 128;
1176 range->sensitivity = 1;
1177
1178 if (priv->reg.phy_type == D_11B_ONLY_MODE) {
1179 range->bitrate[0] = 1e6;
1180 range->bitrate[1] = 2e6;
1181 range->bitrate[2] = 5.5e6;
1182 range->bitrate[3] = 11e6;
1183 range->num_bitrates = 4;
1184 } else { /* D_11G_ONLY_MODE or D_11BG_COMPATIBLE_MODE */
1185 range->bitrate[0] = 1e6;
1186 range->bitrate[1] = 2e6;
1187 range->bitrate[2] = 5.5e6;
1188 range->bitrate[3] = 11e6;
1189
1190 range->bitrate[4] = 6e6;
1191 range->bitrate[5] = 9e6;
1192 range->bitrate[6] = 12e6;
1193 if (IW_MAX_BITRATES < 9) {
1194 range->bitrate[7] = 54e6;
1195 range->num_bitrates = 8;
1196 } else {
1197 range->bitrate[7] = 18e6;
1198 range->bitrate[8] = 24e6;
1199 range->bitrate[9] = 36e6;
1200 range->bitrate[10] = 48e6;
1201 range->bitrate[11] = 54e6;
1202
1203 range->num_bitrates = 12;
1204 }
1205 }
1206
1207 /* Set an indication of the max TCP throughput
1208 * in bit/s that we can expect using this interface.
1209 * May be use for QoS stuff... Jean II */
1210 if (i > 2)
1211 range->throughput = 5000 * 1000;
1212 else
1213 range->throughput = 1500 * 1000;
1214
1215 range->min_rts = 0;
1216 range->max_rts = 2347;
1217 range->min_frag = 256;
1218 range->max_frag = 2346;
1219
1220 range->encoding_size[0] = 5; /* WEP: RC4 40 bits */
1221 range->encoding_size[1] = 13; /* WEP: RC4 ~128 bits */
1222 range->num_encoding_sizes = 2;
1223 range->max_encoding_tokens = 4;
1224
1225 /* power management not support */
1226 range->pmp_flags = IW_POWER_ON;
1227 range->pmt_flags = IW_POWER_ON;
1228 range->pm_capa = 0;
1229
1230 /* Transmit Power - values are in dBm( or mW) */
1231 range->txpower[0] = -256;
1232 range->num_txpower = 1;
1233 range->txpower_capa = IW_TXPOW_DBM;
1234 /* range->txpower_capa = IW_TXPOW_MWATT; */
1235
1236 range->we_version_source = 21;
1237 range->we_version_compiled = WIRELESS_EXT;
1238
1239 range->retry_capa = IW_RETRY_ON;
1240 range->retry_flags = IW_RETRY_ON;
1241 range->r_time_flags = IW_RETRY_ON;
1242
1243 /* Experimental measurements - boundary 11/5.5 Mb/s */
1244 /* Note : with or without the (local->rssi), results
1245 * are somewhat different. - Jean II */
1246 range->avg_qual.qual = 50;
1247 range->avg_qual.level = 186; /* -70 dBm */
1248 range->avg_qual.noise = 0;
1249
1250 /* Event capability (kernel + driver) */
1251 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1252 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1253 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1254 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1255 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1256 IW_EVENT_CAPA_MASK(IWEVMICHAELMICFAILURE));
1257
1258 /* encode extension (WPA) capability */
1259 range->enc_capa = (IW_ENC_CAPA_WPA |
1260 IW_ENC_CAPA_WPA2 |
1261 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP);
1262 return 0;
1263}
1264
1265/*------------------------------------------------------------------*/
1266/* Wireless Handler : set Power Management */
1267static int ks_wlan_set_power(struct net_device *dev,
1268 struct iw_request_info *info,
1269 struct iw_param *vwrq, char *extra)
1270{
1271 struct ks_wlan_private *priv =
1272 (struct ks_wlan_private *)netdev_priv(dev);
1273 short enabled;
1274
1275 if (priv->sleep_mode == SLP_SLEEP) {
1276 return -EPERM;
1277 }
1278 /* for SLEEP MODE */
1279 enabled = vwrq->disabled ? 0 : 1;
1280 if (enabled == 0) { /* 0 */
1281 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
1282 } else if (enabled) { /* 1 */
1283 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1284 priv->reg.powermgt = POWMGT_SAVE1_MODE;
1285 else
1286 return -EINVAL;
1287 } else if (enabled) { /* 2 */
1288 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
1289 priv->reg.powermgt = POWMGT_SAVE2_MODE;
1290 else
1291 return -EINVAL;
1292 } else
1293 return -EINVAL;
1294
1295 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
1296
1297 return 0;
1298}
1299
1300/*------------------------------------------------------------------*/
1301/* Wireless Handler : get Power Management */
1302static int ks_wlan_get_power(struct net_device *dev,
1303 struct iw_request_info *info,
1304 struct iw_param *vwrq, char *extra)
1305{
1306 struct ks_wlan_private *priv =
1307 (struct ks_wlan_private *)netdev_priv(dev);
1308
1309 if (priv->sleep_mode == SLP_SLEEP) {
1310 return -EPERM;
1311 }
1312 /* for SLEEP MODE */
1313 if (priv->reg.powermgt > 0)
1314 vwrq->disabled = 0;
1315 else
1316 vwrq->disabled = 1;
1317
1318 return 0;
1319}
1320
1321/*------------------------------------------------------------------*/
1322/* Wireless Handler : get wirless statistics */
1323static int ks_wlan_get_iwstats(struct net_device *dev,
1324 struct iw_request_info *info,
1325 struct iw_quality *vwrq, char *extra)
1326{
1327 struct ks_wlan_private *priv =
1328 (struct ks_wlan_private *)netdev_priv(dev);
1329
1330 if (priv->sleep_mode == SLP_SLEEP) {
1331 return -EPERM;
1332 }
1333 /* for SLEEP MODE */
1334 vwrq->qual = 0; /* not supported */
1335 vwrq->level = priv->wstats.qual.level;
1336 vwrq->noise = 0; /* not supported */
1337 vwrq->updated = 0;
1338
1339 return 0;
1340}
1341
1342#ifndef KSC_OPNOTSUPP
1343/*------------------------------------------------------------------*/
1344/* Wireless Handler : set Sensitivity */
1345static int ks_wlan_set_sens(struct net_device *dev,
1346 struct iw_request_info *info, struct iw_param *vwrq,
1347 char *extra)
1348{
1349 return -EOPNOTSUPP; /* Not Support */
1350}
1351
1352/*------------------------------------------------------------------*/
1353/* Wireless Handler : get Sensitivity */
1354static int ks_wlan_get_sens(struct net_device *dev,
1355 struct iw_request_info *info, struct iw_param *vwrq,
1356 char *extra)
1357{
1358 /* Not Support */
1359 vwrq->value = 0;
1360 vwrq->disabled = (vwrq->value == 0);
1361 vwrq->fixed = 1;
1362 return 0;
1363}
1364#endif /* KSC_OPNOTSUPP */
1365
1366/*------------------------------------------------------------------*/
1367/* Wireless Handler : get AP List */
1368/* Note : this is deprecated in favor of IWSCAN */
1369static int ks_wlan_get_aplist(struct net_device *dev,
1370 struct iw_request_info *info,
1371 struct iw_point *dwrq, char *extra)
1372{
1373 struct ks_wlan_private *priv =
1374 (struct ks_wlan_private *)netdev_priv(dev);
1375 struct sockaddr *address = (struct sockaddr *)extra;
1376 struct iw_quality qual[LOCAL_APLIST_MAX];
1377
1378 int i;
1379
1380 if (priv->sleep_mode == SLP_SLEEP) {
1381 return -EPERM;
1382 }
1383 /* for SLEEP MODE */
1384 for (i = 0; i < priv->aplist.size; i++) {
1385 memcpy(address[i].sa_data, &(priv->aplist.ap[i].bssid[0]),
1386 ETH_ALEN);
1387 address[i].sa_family = ARPHRD_ETHER;
1388 qual[i].level = 256 - priv->aplist.ap[i].rssi;
1389 qual[i].qual = priv->aplist.ap[i].sq;
1390 qual[i].noise = 0; /* invalid noise value */
1391 qual[i].updated = 7;
1392 }
1393 if (i) {
1394 dwrq->flags = 1; /* Should be define'd */
1395 memcpy(extra + sizeof(struct sockaddr) * i,
1396 &qual, sizeof(struct iw_quality) * i);
1397 }
1398 dwrq->length = i;
1399
1400 return 0;
1401}
1402
1403/*------------------------------------------------------------------*/
1404/* Wireless Handler : Initiate Scan */
1405static int ks_wlan_set_scan(struct net_device *dev,
1406 struct iw_request_info *info,
1407 union iwreq_data *wrqu, char *extra)
1408{
1409 struct ks_wlan_private *priv =
1410 (struct ks_wlan_private *)netdev_priv(dev);
1411 struct iw_scan_req *req = NULL;
1412 DPRINTK(2, "\n");
1413
1414 if (priv->sleep_mode == SLP_SLEEP) {
1415 return -EPERM;
1416 }
1417
1418 /* for SLEEP MODE */
1419 /* specified SSID SCAN */
1420 if (wrqu->data.length == sizeof(struct iw_scan_req)
1421 && wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1422 req = (struct iw_scan_req *)extra;
1423 priv->scan_ssid_len = req->essid_len;
1424 memcpy(priv->scan_ssid, req->essid, priv->scan_ssid_len);
1425 } else {
1426 priv->scan_ssid_len = 0;
1427 }
1428
1429 priv->sme_i.sme_flag |= SME_AP_SCAN;
1430 hostif_sme_enqueue(priv, SME_BSS_SCAN_REQUEST);
1431
1432 /* At this point, just return to the user. */
1433
1434 return 0;
1435}
1436
1437/*------------------------------------------------------------------*/
1438/*
1439 * Translate scan data returned from the card to a card independent
1440 * format that the Wireless Tools will understand - Jean II
1441 */
1442static inline char *ks_wlan_translate_scan(struct net_device *dev,
1443 struct iw_request_info *info,
1444 char *current_ev, char *end_buf,
1445 struct local_ap_t *ap)
1446{
1447 /* struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv; */
1448 struct iw_event iwe; /* Temporary buffer */
1449 u16 capabilities;
1450 char *current_val; /* For rates */
1451 int i;
1452 static const char rsn_leader[] = "rsn_ie=";
1453 static const char wpa_leader[] = "wpa_ie=";
1454 char buf0[RSN_IE_BODY_MAX * 2 + 30];
1455 char buf1[RSN_IE_BODY_MAX * 2 + 30];
1456 char *pbuf;
1457 /* First entry *MUST* be the AP MAC address */
1458 iwe.cmd = SIOCGIWAP;
1459 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1460 memcpy(iwe.u.ap_addr.sa_data, ap->bssid, ETH_ALEN);
1461 current_ev =
1462 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1463 IW_EV_ADDR_LEN);
1464
1465 /* Other entries will be displayed in the order we give them */
1466
1467 /* Add the ESSID */
1468 iwe.u.data.length = ap->ssid.size;
1469 if (iwe.u.data.length > 32)
1470 iwe.u.data.length = 32;
1471 iwe.cmd = SIOCGIWESSID;
1472 iwe.u.data.flags = 1;
1473 current_ev =
1474 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1475 &(ap->ssid.body[0]));
1476
1477 /* Add mode */
1478 iwe.cmd = SIOCGIWMODE;
1479 capabilities = le16_to_cpu(ap->capability);
1480 if (capabilities & (BSS_CAP_ESS | BSS_CAP_IBSS)) {
1481 if (capabilities & BSS_CAP_ESS)
1482 iwe.u.mode = IW_MODE_INFRA;
1483 else
1484 iwe.u.mode = IW_MODE_ADHOC;
1485 current_ev =
1486 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1487 IW_EV_UINT_LEN);
1488 }
1489
1490 /* Add frequency */
1491 iwe.cmd = SIOCGIWFREQ;
1492 iwe.u.freq.m = ap->channel;
1493 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
1494 iwe.u.freq.e = 1;
1495 current_ev =
1496 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1497 IW_EV_FREQ_LEN);
1498
1499 /* Add quality statistics */
1500 iwe.cmd = IWEVQUAL;
1501 iwe.u.qual.level = 256 - ap->rssi;
1502 iwe.u.qual.qual = ap->sq;
1503 iwe.u.qual.noise = 0; /* invalid noise value */
1504 current_ev =
1505 iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1506 IW_EV_QUAL_LEN);
1507
1508 /* Add encryption capability */
1509 iwe.cmd = SIOCGIWENCODE;
1510 if (capabilities & BSS_CAP_PRIVACY)
1511 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1512 else
1513 iwe.u.data.flags = IW_ENCODE_DISABLED;
1514 iwe.u.data.length = 0;
1515 current_ev =
1516 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1517 &(ap->ssid.body[0]));
1518
1519 /* Rate : stuffing multiple values in a single event require a bit
1520 * more of magic - Jean II */
1521 current_val = current_ev + IW_EV_LCP_LEN;
1522
1523 iwe.cmd = SIOCGIWRATE;
1524 /* Those two flags are ignored... */
1525 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1526
1527 /* Max 16 values */
1528 for (i = 0; i < 16; i++) {
1529 /* NULL terminated */
1530 if (i >= ap->rate_set.size)
1531 break;
1532 /* Bit rate given in 500 kb/s units (+ 0x80) */
1533 iwe.u.bitrate.value = ((ap->rate_set.body[i] & 0x7f) * 500000);
1534 /* Add new value to event */
1535 current_val =
1536 iwe_stream_add_value(info, current_ev, current_val, end_buf,
1537 &iwe, IW_EV_PARAM_LEN);
1538 }
1539 /* Check if we added any event */
1540 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1541 current_ev = current_val;
1542
1543#define GENERIC_INFO_ELEM_ID 0xdd
1544#define RSN_INFO_ELEM_ID 0x30
1545 if (ap->rsn_ie.id == RSN_INFO_ELEM_ID && ap->rsn_ie.size != 0) {
1546 pbuf = &buf0[0];
1547 memset(&iwe, 0, sizeof(iwe));
1548 iwe.cmd = IWEVCUSTOM;
1549 memcpy(buf0, rsn_leader, sizeof(rsn_leader) - 1);
1550 iwe.u.data.length += sizeof(rsn_leader) - 1;
1551 pbuf += sizeof(rsn_leader) - 1;
1552
1553 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.id);
1554 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.size);
1555 iwe.u.data.length += 4;
1556
1557 for (i = 0; i < ap->rsn_ie.size; i++)
1558 pbuf += sprintf(pbuf, "%02x", ap->rsn_ie.body[i]);
1559 iwe.u.data.length += (ap->rsn_ie.size) * 2;
1560
1561 DPRINTK(4, "ap->rsn.size=%d\n", ap->rsn_ie.size);
1562
1563 current_ev =
1564 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1565 &buf0[0]);
1566 }
1567 if (ap->wpa_ie.id == GENERIC_INFO_ELEM_ID && ap->wpa_ie.size != 0) {
1568 pbuf = &buf1[0];
1569 memset(&iwe, 0, sizeof(iwe));
1570 iwe.cmd = IWEVCUSTOM;
1571 memcpy(buf1, wpa_leader, sizeof(wpa_leader) - 1);
1572 iwe.u.data.length += sizeof(wpa_leader) - 1;
1573 pbuf += sizeof(wpa_leader) - 1;
1574
1575 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.id);
1576 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.size);
1577 iwe.u.data.length += 4;
1578
1579 for (i = 0; i < ap->wpa_ie.size; i++)
1580 pbuf += sprintf(pbuf, "%02x", ap->wpa_ie.body[i]);
1581 iwe.u.data.length += (ap->wpa_ie.size) * 2;
1582
1583 DPRINTK(4, "ap->rsn.size=%d\n", ap->wpa_ie.size);
1584 DPRINTK(4, "iwe.u.data.length=%d\n", iwe.u.data.length);
1585
1586 current_ev =
1587 iwe_stream_add_point(info, current_ev, end_buf, &iwe,
1588 &buf1[0]);
1589 }
1590
1591 /* The other data in the scan result are not really
1592 * interesting, so for now drop it - Jean II */
1593 return current_ev;
1594}
1595
1596/*------------------------------------------------------------------*/
1597/* Wireless Handler : Read Scan Results */
1598static int ks_wlan_get_scan(struct net_device *dev,
1599 struct iw_request_info *info, struct iw_point *dwrq,
1600 char *extra)
1601{
1602 struct ks_wlan_private *priv =
1603 (struct ks_wlan_private *)netdev_priv(dev);
1604 int i;
1605 char *current_ev = extra;
1606 DPRINTK(2, "\n");
1607
1608 if (priv->sleep_mode == SLP_SLEEP) {
1609 return -EPERM;
1610 }
1611 /* for SLEEP MODE */
1612 if (priv->sme_i.sme_flag & SME_AP_SCAN) {
1613 DPRINTK(2, "flag AP_SCAN\n");
1614 return -EAGAIN;
1615 }
1616
1617 if (priv->aplist.size == 0) {
1618 /* Client error, no scan results...
1619 * The caller need to restart the scan. */
1620 DPRINTK(2, "aplist 0\n");
1621 return -ENODATA;
1622 }
1623#if 0
1624 /* current connect ap */
1625 if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
1626 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1627 dwrq->length = 0;
1628 return -E2BIG;
1629 }
1630 current_ev = ks_wlan_translate_scan(dev, current_ev,
1631// extra + IW_SCAN_MAX_DATA,
1632 extra + dwrq->length,
1633 &(priv->current_ap));
1634 }
1635#endif
1636 /* Read and parse all entries */
1637 for (i = 0; i < priv->aplist.size; i++) {
1638 if ((extra + dwrq->length) - current_ev <= IW_EV_ADDR_LEN) {
1639 dwrq->length = 0;
1640 return -E2BIG;
1641 }
1642 /* Translate to WE format this entry */
1643 current_ev = ks_wlan_translate_scan(dev, info, current_ev,
1644// extra + IW_SCAN_MAX_DATA,
1645 extra + dwrq->length,
1646 &(priv->aplist.ap[i]));
1647 }
1648 /* Length of data */
1649 dwrq->length = (current_ev - extra);
1650 dwrq->flags = 0;
1651
1652 return 0;
1653}
1654
1655/*------------------------------------------------------------------*/
1656/* Commit handler : called after a bunch of SET operations */
1657static int ks_wlan_config_commit(struct net_device *dev,
1658 struct iw_request_info *info, void *zwrq,
1659 char *extra)
1660{
1661 struct ks_wlan_private *priv =
1662 (struct ks_wlan_private *)netdev_priv(dev);
1663
1664 if (!priv->need_commit)
1665 return 0;
1666
1667 ks_wlan_setup_parameter(priv, priv->need_commit);
1668 priv->need_commit = 0;
1669 return 0;
1670}
1671
1672/*------------------------------------------------------------------*/
1673/* Wireless handler : set association ie params */
1674static int ks_wlan_set_genie(struct net_device *dev,
1675 struct iw_request_info *info,
1676 struct iw_point *dwrq, char *extra)
1677{
1678 struct ks_wlan_private *priv =
1679 (struct ks_wlan_private *)netdev_priv(dev);
1680
1681 DPRINTK(2, "\n");
1682
1683 if (priv->sleep_mode == SLP_SLEEP) {
1684 return -EPERM;
1685 }
1686 /* for SLEEP MODE */
1687 return 0;
1688// return -EOPNOTSUPP;
1689}
1690
1691/*------------------------------------------------------------------*/
1692/* Wireless handler : set authentication mode params */
1693static int ks_wlan_set_auth_mode(struct net_device *dev,
1694 struct iw_request_info *info,
1695 struct iw_param *vwrq, char *extra)
1696{
1697 struct ks_wlan_private *priv =
1698 (struct ks_wlan_private *)netdev_priv(dev);
1699 int index = (vwrq->flags & IW_AUTH_INDEX);
1700 int value = vwrq->value;
1701
1702 DPRINTK(2, "index=%d:value=%08X\n", index, value);
1703
1704 if (priv->sleep_mode == SLP_SLEEP) {
1705 return -EPERM;
1706 }
1707 /* for SLEEP MODE */
1708 switch (index) {
1709 case IW_AUTH_WPA_VERSION: /* 0 */
1710 switch (value) {
1711 case IW_AUTH_WPA_VERSION_DISABLED:
1712 priv->wpa.version = value;
1713 if (priv->wpa.rsn_enabled) {
1714 priv->wpa.rsn_enabled = 0;
1715 }
1716 priv->need_commit |= SME_RSN;
1717 break;
1718 case IW_AUTH_WPA_VERSION_WPA:
1719 case IW_AUTH_WPA_VERSION_WPA2:
1720 priv->wpa.version = value;
1721 if (!(priv->wpa.rsn_enabled)) {
1722 priv->wpa.rsn_enabled = 1;
1723 }
1724 priv->need_commit |= SME_RSN;
1725 break;
1726 default:
1727 return -EOPNOTSUPP;
1728 }
1729 break;
1730 case IW_AUTH_CIPHER_PAIRWISE: /* 1 */
1731 switch (value) {
1732 case IW_AUTH_CIPHER_NONE:
1733 if (priv->reg.privacy_invoked) {
1734 priv->reg.privacy_invoked = 0x00;
1735 priv->need_commit |= SME_WEP_FLAG;
1736 }
1737 break;
1738 case IW_AUTH_CIPHER_WEP40:
1739 case IW_AUTH_CIPHER_TKIP:
1740 case IW_AUTH_CIPHER_CCMP:
1741 case IW_AUTH_CIPHER_WEP104:
1742 if (!priv->reg.privacy_invoked) {
1743 priv->reg.privacy_invoked = 0x01;
1744 priv->need_commit |= SME_WEP_FLAG;
1745 }
1746 priv->wpa.pairwise_suite = value;
1747 priv->need_commit |= SME_RSN_UNICAST;
1748 break;
1749 default:
1750 return -EOPNOTSUPP;
1751 }
1752 break;
1753 case IW_AUTH_CIPHER_GROUP: /* 2 */
1754 switch (value) {
1755 case IW_AUTH_CIPHER_NONE:
1756 if (priv->reg.privacy_invoked) {
1757 priv->reg.privacy_invoked = 0x00;
1758 priv->need_commit |= SME_WEP_FLAG;
1759 }
1760 break;
1761 case IW_AUTH_CIPHER_WEP40:
1762 case IW_AUTH_CIPHER_TKIP:
1763 case IW_AUTH_CIPHER_CCMP:
1764 case IW_AUTH_CIPHER_WEP104:
1765 if (!priv->reg.privacy_invoked) {
1766 priv->reg.privacy_invoked = 0x01;
1767 priv->need_commit |= SME_WEP_FLAG;
1768 }
1769 priv->wpa.group_suite = value;
1770 priv->need_commit |= SME_RSN_MULTICAST;
1771 break;
1772 default:
1773 return -EOPNOTSUPP;
1774 }
1775 break;
1776 case IW_AUTH_KEY_MGMT: /* 3 */
1777 switch (value) {
1778 case IW_AUTH_KEY_MGMT_802_1X:
1779 case IW_AUTH_KEY_MGMT_PSK:
1780 case 0: /* NONE or 802_1X_NO_WPA */
1781 case 4: /* WPA_NONE */
1782 priv->wpa.key_mgmt_suite = value;
1783 priv->need_commit |= SME_RSN_AUTH;
1784 break;
1785 default:
1786 return -EOPNOTSUPP;
1787 }
1788 break;
1789 case IW_AUTH_80211_AUTH_ALG: /* 6 */
1790 switch (value) {
1791 case IW_AUTH_ALG_OPEN_SYSTEM:
1792 priv->wpa.auth_alg = value;
1793 priv->reg.authenticate_type = AUTH_TYPE_OPEN_SYSTEM;
1794 break;
1795 case IW_AUTH_ALG_SHARED_KEY:
1796 priv->wpa.auth_alg = value;
1797 priv->reg.authenticate_type = AUTH_TYPE_SHARED_KEY;
1798 break;
1799 case IW_AUTH_ALG_LEAP:
1800 default:
1801 return -EOPNOTSUPP;
1802 }
1803 priv->need_commit |= SME_MODE_SET;
1804 break;
1805 case IW_AUTH_WPA_ENABLED: /* 7 */
1806 priv->wpa.wpa_enabled = value;
1807 break;
1808 case IW_AUTH_PRIVACY_INVOKED: /* 10 */
1809 if ((value && !priv->reg.privacy_invoked) ||
1810 (!value && priv->reg.privacy_invoked)) {
1811 priv->reg.privacy_invoked = value ? 0x01 : 0x00;
1812 priv->need_commit |= SME_WEP_FLAG;
1813 }
1814 break;
1815 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* 4 */
1816 case IW_AUTH_TKIP_COUNTERMEASURES: /* 5 */
1817 case IW_AUTH_DROP_UNENCRYPTED: /* 8 */
1818 case IW_AUTH_ROAMING_CONTROL: /* 9 */
1819 default:
1820 break;
1821 }
1822
1823 /* return -EINPROGRESS; */
1824 if (priv->need_commit) {
1825 ks_wlan_setup_parameter(priv, priv->need_commit);
1826 priv->need_commit = 0;
1827 }
1828 return 0;
1829}
1830
1831/*------------------------------------------------------------------*/
1832/* Wireless handler : get authentication mode params */
1833static int ks_wlan_get_auth_mode(struct net_device *dev,
1834 struct iw_request_info *info,
1835 struct iw_param *vwrq, char *extra)
1836{
1837 struct ks_wlan_private *priv =
1838 (struct ks_wlan_private *)netdev_priv(dev);
1839 int index = (vwrq->flags & IW_AUTH_INDEX);
1840 DPRINTK(2, "index=%d\n", index);
1841
1842 if (priv->sleep_mode == SLP_SLEEP) {
1843 return -EPERM;
1844 }
1845
1846 /* for SLEEP MODE */
1847 /* WPA (not used ?? wpa_supplicant) */
1848 switch (index) {
1849 case IW_AUTH_WPA_VERSION:
1850 vwrq->value = priv->wpa.version;
1851 break;
1852 case IW_AUTH_CIPHER_PAIRWISE:
1853 vwrq->value = priv->wpa.pairwise_suite;
1854 break;
1855 case IW_AUTH_CIPHER_GROUP:
1856 vwrq->value = priv->wpa.group_suite;
1857 break;
1858 case IW_AUTH_KEY_MGMT:
1859 vwrq->value = priv->wpa.key_mgmt_suite;
1860 break;
1861 case IW_AUTH_80211_AUTH_ALG:
1862 vwrq->value = priv->wpa.auth_alg;
1863 break;
1864 case IW_AUTH_WPA_ENABLED:
1865 vwrq->value = priv->wpa.rsn_enabled;
1866 break;
1867 case IW_AUTH_RX_UNENCRYPTED_EAPOL: /* OK??? */
1868 case IW_AUTH_TKIP_COUNTERMEASURES:
1869 case IW_AUTH_DROP_UNENCRYPTED:
1870 default:
1871 /* return -EOPNOTSUPP; */
1872 break;
1873 }
1874 return 0;
1875}
1876
1877/*------------------------------------------------------------------*/
1878/* Wireless Handler : set encoding token & mode (WPA)*/
1879static int ks_wlan_set_encode_ext(struct net_device *dev,
1880 struct iw_request_info *info,
1881 struct iw_point *dwrq, char *extra)
1882{
1883 struct ks_wlan_private *priv =
1884 (struct ks_wlan_private *)netdev_priv(dev);
1885 struct iw_encode_ext *enc;
1886 int index = dwrq->flags & IW_ENCODE_INDEX;
1887 unsigned int commit = 0;
1888
1889 enc = (struct iw_encode_ext *)extra;
1890
1891 DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
1892 enc->ext_flags);
1893
1894 if (priv->sleep_mode == SLP_SLEEP) {
1895 return -EPERM;
1896 }
1897 /* for SLEEP MODE */
1898 if (index < 1 || index > 4)
1899 return -EINVAL;
1900 else
1901 index--;
1902
1903 if (dwrq->flags & IW_ENCODE_DISABLED) {
1904 priv->wpa.key[index].key_len = 0;
1905 }
1906
1907 if (enc) {
1908 priv->wpa.key[index].ext_flags = enc->ext_flags;
1909 if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
1910 priv->wpa.txkey = index;
1911 commit |= SME_WEP_INDEX;
1912 } else if (enc->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1913 memcpy(&priv->wpa.key[index].rx_seq[0],
1914 enc->rx_seq, IW_ENCODE_SEQ_MAX_SIZE);
1915 }
1916
1917 memcpy(&priv->wpa.key[index].addr.sa_data[0],
1918 &enc->addr.sa_data[0], ETH_ALEN);
1919
1920 switch (enc->alg) {
1921 case IW_ENCODE_ALG_NONE:
1922 if (priv->reg.privacy_invoked) {
1923 priv->reg.privacy_invoked = 0x00;
1924 commit |= SME_WEP_FLAG;
1925 }
1926 priv->wpa.key[index].key_len = 0;
1927
1928 break;
1929 case IW_ENCODE_ALG_WEP:
1930 case IW_ENCODE_ALG_CCMP:
1931 if (!priv->reg.privacy_invoked) {
1932 priv->reg.privacy_invoked = 0x01;
1933 commit |= SME_WEP_FLAG;
1934 }
1935 if (enc->key_len) {
1936 memcpy(&priv->wpa.key[index].key_val[0],
1937 &enc->key[0], enc->key_len);
1938 priv->wpa.key[index].key_len = enc->key_len;
1939 commit |= (SME_WEP_VAL1 << index);
1940 }
1941 break;
1942 case IW_ENCODE_ALG_TKIP:
1943 if (!priv->reg.privacy_invoked) {
1944 priv->reg.privacy_invoked = 0x01;
1945 commit |= SME_WEP_FLAG;
1946 }
1947 if (enc->key_len == 32) {
1948 memcpy(&priv->wpa.key[index].key_val[0],
1949 &enc->key[0], enc->key_len - 16);
1950 priv->wpa.key[index].key_len =
1951 enc->key_len - 16;
1952 if (priv->wpa.key_mgmt_suite == 4) { /* WPA_NONE */
1953 memcpy(&priv->wpa.key[index].
1954 tx_mic_key[0], &enc->key[16], 8);
1955 memcpy(&priv->wpa.key[index].
1956 rx_mic_key[0], &enc->key[16], 8);
1957 } else {
1958 memcpy(&priv->wpa.key[index].
1959 tx_mic_key[0], &enc->key[16], 8);
1960 memcpy(&priv->wpa.key[index].
1961 rx_mic_key[0], &enc->key[24], 8);
1962 }
1963 commit |= (SME_WEP_VAL1 << index);
1964 }
1965 break;
1966 default:
1967 return -EINVAL;
1968 }
1969 priv->wpa.key[index].alg = enc->alg;
1970 } else
1971 return -EINVAL;
1972
1973 if (commit) {
1974 if (commit & SME_WEP_INDEX)
1975 hostif_sme_enqueue(priv, SME_SET_TXKEY);
1976 if (commit & SME_WEP_VAL_MASK)
1977 hostif_sme_enqueue(priv, SME_SET_KEY1 + index);
1978 if (commit & SME_WEP_FLAG)
1979 hostif_sme_enqueue(priv, SME_WEP_FLAG_REQUEST);
1980 }
1981
1982 return 0;
1983}
1984
1985/*------------------------------------------------------------------*/
1986/* Wireless Handler : get encoding token & mode (WPA)*/
1987static int ks_wlan_get_encode_ext(struct net_device *dev,
1988 struct iw_request_info *info,
1989 struct iw_point *dwrq, char *extra)
1990{
1991 struct ks_wlan_private *priv =
1992 (struct ks_wlan_private *)netdev_priv(dev);
1993
1994 if (priv->sleep_mode == SLP_SLEEP) {
1995 return -EPERM;
1996 }
1997
1998 /* for SLEEP MODE */
1999 /* WPA (not used ?? wpa_supplicant)
2000 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2001 struct iw_encode_ext *enc;
2002 enc = (struct iw_encode_ext *)extra;
2003 int index = dwrq->flags & IW_ENCODE_INDEX;
2004 WPA (not used ?? wpa_supplicant) */
2005 return 0;
2006}
2007
2008/*------------------------------------------------------------------*/
2009/* Wireless Handler : PMKSA cache operation (WPA2) */
2010static int ks_wlan_set_pmksa(struct net_device *dev,
2011 struct iw_request_info *info,
2012 struct iw_point *dwrq, char *extra)
2013{
2014 struct ks_wlan_private *priv =
2015 (struct ks_wlan_private *)netdev_priv(dev);
2016 struct iw_pmksa *pmksa;
2017 int i;
2018 struct pmk_t *pmk;
2019 struct list_head *ptr;
2020
2021 DPRINTK(2, "\n");
2022
2023 if (priv->sleep_mode == SLP_SLEEP) {
2024 return -EPERM;
2025 }
2026 /* for SLEEP MODE */
2027 if (!extra) {
2028 return -EINVAL;
2029 }
2030 pmksa = (struct iw_pmksa *)extra;
2031 DPRINTK(2, "cmd=%d\n", pmksa->cmd);
2032
2033 switch (pmksa->cmd) {
2034 case IW_PMKSA_ADD:
2035 if (list_empty(&priv->pmklist.head)) { /* new list */
2036 for (i = 0; i < PMK_LIST_MAX; i++) {
2037 pmk = &priv->pmklist.pmk[i];
2038 if (!memcmp
2039 ("\x00\x00\x00\x00\x00\x00", pmk->bssid,
2040 ETH_ALEN))
2041 break;
2042 }
2043 memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN);
2044 memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN);
2045 list_add(&pmk->list, &priv->pmklist.head);
2046 priv->pmklist.size++;
2047 } else { /* search cache data */
2048 list_for_each(ptr, &priv->pmklist.head) {
2049 pmk = list_entry(ptr, struct pmk_t, list);
2050 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list move to head. */
2051 memcpy(pmk->pmkid, pmksa->pmkid,
2052 IW_PMKID_LEN);
2053 list_move(&pmk->list,
2054 &priv->pmklist.head);
2055 break;
2056 }
2057 }
2058 if (ptr == &priv->pmklist.head) { /* not find address. */
2059 if (PMK_LIST_MAX > priv->pmklist.size) { /* new cache data */
2060 for (i = 0; i < PMK_LIST_MAX; i++) {
2061 pmk = &priv->pmklist.pmk[i];
2062 if (!memcmp
2063 ("\x00\x00\x00\x00\x00\x00",
2064 pmk->bssid, ETH_ALEN))
2065 break;
2066 }
2067 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2068 ETH_ALEN);
2069 memcpy(pmk->pmkid, pmksa->pmkid,
2070 IW_PMKID_LEN);
2071 list_add(&pmk->list,
2072 &priv->pmklist.head);
2073 priv->pmklist.size++;
2074 } else { /* overwrite old cache data */
2075 pmk =
2076 list_entry(priv->pmklist.head.prev,
2077 struct pmk_t, list);
2078 memcpy(pmk->bssid, pmksa->bssid.sa_data,
2079 ETH_ALEN);
2080 memcpy(pmk->pmkid, pmksa->pmkid,
2081 IW_PMKID_LEN);
2082 list_move(&pmk->list,
2083 &priv->pmklist.head);
2084 }
2085 }
2086 }
2087 break;
2088 case IW_PMKSA_REMOVE:
2089 if (list_empty(&priv->pmklist.head)) { /* list empty */
2090 return -EINVAL;
2091 } else { /* search cache data */
2092 list_for_each(ptr, &priv->pmklist.head) {
2093 pmk = list_entry(ptr, struct pmk_t, list);
2094 if (!memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN)) { /* match address! list del. */
2095 memset(pmk->bssid, 0, ETH_ALEN);
2096 memset(pmk->pmkid, 0, IW_PMKID_LEN);
2097 list_del_init(&pmk->list);
2098 break;
2099 }
2100 }
2101 if (ptr == &priv->pmklist.head) { /* not find address. */
2102 return 0;
2103 }
2104 }
2105 break;
2106 case IW_PMKSA_FLUSH:
2107 memset(&(priv->pmklist), 0, sizeof(priv->pmklist));
2108 INIT_LIST_HEAD(&priv->pmklist.head);
2109 for (i = 0; i < PMK_LIST_MAX; i++)
2110 INIT_LIST_HEAD(&priv->pmklist.pmk[i].list);
2111 break;
2112 default:
2113 return -EINVAL;
2114 }
2115
2116 hostif_sme_enqueue(priv, SME_SET_PMKSA);
2117 return 0;
2118}
2119
2120static struct iw_statistics *ks_get_wireless_stats(struct net_device *dev)
2121{
2122
2123 struct ks_wlan_private *priv =
2124 (struct ks_wlan_private *)netdev_priv(dev);
2125 struct iw_statistics *wstats = &priv->wstats;
2126
2127 if (!atomic_read(&update_phyinfo)) {
2128 if (priv->dev_state < DEVICE_STATE_READY)
2129 return NULL; /* not finished initialize */
2130 else
2131 return wstats;
2132 }
2133
2134 /* Packets discarded in the wireless adapter due to wireless
2135 * specific problems */
2136 wstats->discard.nwid = 0; /* Rx invalid nwid */
2137 wstats->discard.code = 0; /* Rx invalid crypt */
2138 wstats->discard.fragment = 0; /* Rx invalid frag */
2139 wstats->discard.retries = 0; /* Tx excessive retries */
2140 wstats->discard.misc = 0; /* Invalid misc */
2141 wstats->miss.beacon = 0; /* Missed beacon */
2142
2143 return wstats;
2144}
2145
2146/*------------------------------------------------------------------*/
2147/* Private handler : set stop request */
2148static int ks_wlan_set_stop_request(struct net_device *dev,
2149 struct iw_request_info *info, __u32 * uwrq,
2150 char *extra)
2151{
2152 struct ks_wlan_private *priv =
2153 (struct ks_wlan_private *)netdev_priv(dev);
2154 DPRINTK(2, "\n");
2155
2156 if (priv->sleep_mode == SLP_SLEEP) {
2157 return -EPERM;
2158 }
2159 /* for SLEEP MODE */
2160 if (!(*uwrq))
2161 return -EINVAL;
2162
2163 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2164 return 0;
2165}
2166
2167/*------------------------------------------------------------------*/
2168/* Wireless Handler : set MLME */
2169#include <linux/ieee80211.h>
2170static int ks_wlan_set_mlme(struct net_device *dev,
2171 struct iw_request_info *info, struct iw_point *dwrq,
2172 char *extra)
2173{
2174 struct ks_wlan_private *priv =
2175 (struct ks_wlan_private *)netdev_priv(dev);
2176 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2177 __u32 mode;
2178
2179 DPRINTK(2, ":%d :%d\n", mlme->cmd, mlme->reason_code);
2180
2181 if (priv->sleep_mode == SLP_SLEEP) {
2182 return -EPERM;
2183 }
2184 /* for SLEEP MODE */
2185 switch (mlme->cmd) {
2186 case IW_MLME_DEAUTH:
2187 if (mlme->reason_code == WLAN_REASON_MIC_FAILURE) {
2188 return 0;
2189 }
2190 case IW_MLME_DISASSOC:
2191 mode = 1;
2192 return ks_wlan_set_stop_request(dev, NULL, &mode, NULL);
2193 default:
2194 return -EOPNOTSUPP; /* Not Support */
2195 }
2196}
2197
2198/*------------------------------------------------------------------*/
2199/* Private handler : get firemware version */
2200static int ks_wlan_get_firmware_version(struct net_device *dev,
2201 struct iw_request_info *info,
2202 struct iw_point *dwrq, char *extra)
2203{
2204 struct ks_wlan_private *priv =
2205 (struct ks_wlan_private *)netdev_priv(dev);
2206 strcpy(extra, &(priv->firmware_version[0]));
2207 dwrq->length = priv->version_size + 1;
2208 return 0;
2209}
2210
2211#if 0
2212/*------------------------------------------------------------------*/
2213/* Private handler : set force disconnect status */
2214static int ks_wlan_set_detach(struct net_device *dev,
2215 struct iw_request_info *info, __u32 * uwrq,
2216 char *extra)
2217{
2218 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2219
2220 if (priv->sleep_mode == SLP_SLEEP) {
2221 return -EPERM;
2222 }
2223 /* for SLEEP MODE */
2224 if (*uwrq == CONNECT_STATUS) { /* 0 */
2225 priv->connect_status &= ~FORCE_DISCONNECT;
2226 if ((priv->connect_status & CONNECT_STATUS_MASK) ==
2227 CONNECT_STATUS)
2228 netif_carrier_on(dev);
2229 } else if (*uwrq == DISCONNECT_STATUS) { /* 1 */
2230 priv->connect_status |= FORCE_DISCONNECT;
2231 netif_carrier_off(dev);
2232 } else
2233 return -EINVAL;
2234 return 0;
2235}
2236
2237/*------------------------------------------------------------------*/
2238/* Private handler : get force disconnect status */
2239static int ks_wlan_get_detach(struct net_device *dev,
2240 struct iw_request_info *info, __u32 * uwrq,
2241 char *extra)
2242{
2243 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2244
2245 if (priv->sleep_mode == SLP_SLEEP) {
2246 return -EPERM;
2247 }
2248 /* for SLEEP MODE */
2249 *uwrq = ((priv->connect_status & FORCE_DISCONNECT) ? 1 : 0);
2250 return 0;
2251}
2252
2253/*------------------------------------------------------------------*/
2254/* Private handler : get connect status */
2255static int ks_wlan_get_connect(struct net_device *dev,
2256 struct iw_request_info *info, __u32 * uwrq,
2257 char *extra)
2258{
2259 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2260
2261 if (priv->sleep_mode == SLP_SLEEP) {
2262 return -EPERM;
2263 }
2264 /* for SLEEP MODE */
2265 *uwrq = (priv->connect_status & CONNECT_STATUS_MASK);
2266 return 0;
2267}
2268#endif
2269
2270/*------------------------------------------------------------------*/
2271/* Private handler : set preamble */
2272static int ks_wlan_set_preamble(struct net_device *dev,
2273 struct iw_request_info *info, __u32 * uwrq,
2274 char *extra)
2275{
2276 struct ks_wlan_private *priv =
2277 (struct ks_wlan_private *)netdev_priv(dev);
2278
2279 if (priv->sleep_mode == SLP_SLEEP) {
2280 return -EPERM;
2281 }
2282 /* for SLEEP MODE */
2283 if (*uwrq == LONG_PREAMBLE) { /* 0 */
2284 priv->reg.preamble = LONG_PREAMBLE;
2285 } else if (*uwrq == SHORT_PREAMBLE) { /* 1 */
2286 priv->reg.preamble = SHORT_PREAMBLE;
2287 } else
2288 return -EINVAL;
2289
2290 priv->need_commit |= SME_MODE_SET;
2291 return -EINPROGRESS; /* Call commit handler */
2292
2293}
2294
2295/*------------------------------------------------------------------*/
2296/* Private handler : get preamble */
2297static int ks_wlan_get_preamble(struct net_device *dev,
2298 struct iw_request_info *info, __u32 * uwrq,
2299 char *extra)
2300{
2301 struct ks_wlan_private *priv =
2302 (struct ks_wlan_private *)netdev_priv(dev);
2303
2304 if (priv->sleep_mode == SLP_SLEEP) {
2305 return -EPERM;
2306 }
2307 /* for SLEEP MODE */
2308 *uwrq = priv->reg.preamble;
2309 return 0;
2310}
2311
2312/*------------------------------------------------------------------*/
2313/* Private handler : set power save mode */
2314static int ks_wlan_set_powermgt(struct net_device *dev,
2315 struct iw_request_info *info, __u32 * uwrq,
2316 char *extra)
2317{
2318 struct ks_wlan_private *priv =
2319 (struct ks_wlan_private *)netdev_priv(dev);
2320
2321 if (priv->sleep_mode == SLP_SLEEP) {
2322 return -EPERM;
2323 }
2324 /* for SLEEP MODE */
2325 if (*uwrq == POWMGT_ACTIVE_MODE) { /* 0 */
2326 priv->reg.powermgt = POWMGT_ACTIVE_MODE;
2327 } else if (*uwrq == POWMGT_SAVE1_MODE) { /* 1 */
2328 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2329 priv->reg.powermgt = POWMGT_SAVE1_MODE;
2330 else
2331 return -EINVAL;
2332 } else if (*uwrq == POWMGT_SAVE2_MODE) { /* 2 */
2333 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE)
2334 priv->reg.powermgt = POWMGT_SAVE2_MODE;
2335 else
2336 return -EINVAL;
2337 } else
2338 return -EINVAL;
2339
2340 hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
2341
2342 return 0;
2343}
2344
2345/*------------------------------------------------------------------*/
2346/* Private handler : get power save made */
2347static int ks_wlan_get_powermgt(struct net_device *dev,
2348 struct iw_request_info *info, __u32 * uwrq,
2349 char *extra)
2350{
2351 struct ks_wlan_private *priv =
2352 (struct ks_wlan_private *)netdev_priv(dev);
2353
2354 if (priv->sleep_mode == SLP_SLEEP) {
2355 return -EPERM;
2356 }
2357 /* for SLEEP MODE */
2358 *uwrq = priv->reg.powermgt;
2359 return 0;
2360}
2361
2362/*------------------------------------------------------------------*/
2363/* Private handler : set scan type */
2364static int ks_wlan_set_scan_type(struct net_device *dev,
2365 struct iw_request_info *info, __u32 * uwrq,
2366 char *extra)
2367{
2368 struct ks_wlan_private *priv =
2369 (struct ks_wlan_private *)netdev_priv(dev);
2370
2371 if (priv->sleep_mode == SLP_SLEEP) {
2372 return -EPERM;
2373 }
2374 /* for SLEEP MODE */
2375 if (*uwrq == ACTIVE_SCAN) { /* 0 */
2376 priv->reg.scan_type = ACTIVE_SCAN;
2377 } else if (*uwrq == PASSIVE_SCAN) { /* 1 */
2378 priv->reg.scan_type = PASSIVE_SCAN;
2379 } else
2380 return -EINVAL;
2381
2382 return 0;
2383}
2384
2385/*------------------------------------------------------------------*/
2386/* Private handler : get scan type */
2387static int ks_wlan_get_scan_type(struct net_device *dev,
2388 struct iw_request_info *info, __u32 * uwrq,
2389 char *extra)
2390{
2391 struct ks_wlan_private *priv =
2392 (struct ks_wlan_private *)netdev_priv(dev);
2393
2394 if (priv->sleep_mode == SLP_SLEEP) {
2395 return -EPERM;
2396 }
2397 /* for SLEEP MODE */
2398 *uwrq = priv->reg.scan_type;
2399 return 0;
2400}
2401
2402#if 0
2403/*------------------------------------------------------------------*/
2404/* Private handler : write raw data to device */
2405static int ks_wlan_data_write(struct net_device *dev,
2406 struct iw_request_info *info,
2407 struct iw_point *dwrq, char *extra)
2408{
2409 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2410 unsigned char *wbuff = NULL;
2411
2412 if (priv->sleep_mode == SLP_SLEEP) {
2413 return -EPERM;
2414 }
2415 /* for SLEEP MODE */
2416 wbuff = (unsigned char *)kmalloc(dwrq->length, GFP_ATOMIC);
2417 if (!wbuff)
2418 return -EFAULT;
2419 memcpy(wbuff, extra, dwrq->length);
2420
2421 /* write to device */
2422 ks_wlan_hw_tx(priv, wbuff, dwrq->length, NULL, NULL, NULL);
2423
2424 return 0;
2425}
2426
2427/*------------------------------------------------------------------*/
2428/* Private handler : read raw data form device */
2429static int ks_wlan_data_read(struct net_device *dev,
2430 struct iw_request_info *info,
2431 struct iw_point *dwrq, char *extra)
2432{
2433 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2434 unsigned short read_length;
2435
2436 if (priv->sleep_mode == SLP_SLEEP) {
2437 return -EPERM;
2438 }
2439 /* for SLEEP MODE */
2440 if (!atomic_read(&priv->event_count)) {
2441 if (priv->dev_state < DEVICE_STATE_BOOT) { /* Remove device */
2442 read_length = 4;
2443 memset(extra, 0xff, read_length);
2444 dwrq->length = read_length;
2445 return 0;
2446 }
2447 read_length = 0;
2448 memset(extra, 0, 1);
2449 dwrq->length = 0;
2450 return 0;
2451 }
2452
2453 if (atomic_read(&priv->event_count) > 0)
2454 atomic_dec(&priv->event_count);
2455
2456 spin_lock(&priv->dev_read_lock); /* request spin lock */
2457
2458 /* Copy length max size 0x07ff */
2459 if (priv->dev_size[priv->dev_count] > 2047)
2460 read_length = 2047;
2461 else
2462 read_length = priv->dev_size[priv->dev_count];
2463
2464 /* Copy data */
2465 memcpy(extra, &(priv->dev_data[priv->dev_count][0]), read_length);
2466
2467 spin_unlock(&priv->dev_read_lock); /* release spin lock */
2468
2469 /* Initialize */
2470 priv->dev_data[priv->dev_count] = 0;
2471 priv->dev_size[priv->dev_count] = 0;
2472
2473 priv->dev_count++;
2474 if (priv->dev_count == DEVICE_STOCK_COUNT)
2475 priv->dev_count = 0;
2476
2477 /* Set read size */
2478 dwrq->length = read_length;
2479
2480 return 0;
2481}
2482#endif
2483
2484#if 0
2485/*------------------------------------------------------------------*/
2486/* Private handler : get wep string */
2487#define WEP_ASCII_BUFF_SIZE (17+64*4+1)
2488static int ks_wlan_get_wep_ascii(struct net_device *dev,
2489 struct iw_request_info *info,
2490 struct iw_point *dwrq, char *extra)
2491{
2492 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2493 int i, j, len = 0;
2494 char tmp[WEP_ASCII_BUFF_SIZE];
2495
2496 if (priv->sleep_mode == SLP_SLEEP) {
2497 return -EPERM;
2498 }
2499 /* for SLEEP MODE */
2500 strcpy(tmp, " WEP keys ASCII \n");
2501 len += strlen(" WEP keys ASCII \n");
2502
2503 for (i = 0; i < 4; i++) {
2504 strcpy(tmp + len, "\t[");
2505 len += strlen("\t[");
2506 tmp[len] = '1' + i;
2507 len++;
2508 strcpy(tmp + len, "] ");
2509 len += strlen("] ");
2510 if (priv->reg.wep_key[i].size) {
2511 strcpy(tmp + len,
2512 (priv->reg.wep_key[i].size <
2513 6 ? "(40bits) [" : "(104bits) ["));
2514 len +=
2515 strlen((priv->reg.wep_key[i].size <
2516 6 ? "(40bits) [" : "(104bits) ["));
2517 for (j = 0; j < priv->reg.wep_key[i].size; j++, len++)
2518 tmp[len] =
2519 (isprint(priv->reg.wep_key[i].val[j]) ?
2520 priv->reg.wep_key[i].val[j] : ' ');
2521
2522 strcpy(tmp + len, "]\n");
2523 len += strlen("]\n");
2524 } else {
2525 strcpy(tmp + len, "off\n");
2526 len += strlen("off\n");
2527 }
2528 }
2529
2530 memcpy(extra, tmp, len);
2531 dwrq->length = len + 1;
2532 return 0;
2533}
2534#endif
2535
2536/*------------------------------------------------------------------*/
2537/* Private handler : set beacon lost count */
2538static int ks_wlan_set_beacon_lost(struct net_device *dev,
2539 struct iw_request_info *info, __u32 * uwrq,
2540 char *extra)
2541{
2542 struct ks_wlan_private *priv =
2543 (struct ks_wlan_private *)netdev_priv(dev);
2544
2545 if (priv->sleep_mode == SLP_SLEEP) {
2546 return -EPERM;
2547 }
2548 /* for SLEEP MODE */
2549 if (*uwrq >= BEACON_LOST_COUNT_MIN && *uwrq <= BEACON_LOST_COUNT_MAX) {
2550 priv->reg.beacon_lost_count = *uwrq;
2551 } else
2552 return -EINVAL;
2553
2554 if (priv->reg.operation_mode == MODE_INFRASTRUCTURE) {
2555 priv->need_commit |= SME_MODE_SET;
2556 return -EINPROGRESS; /* Call commit handler */
2557 } else
2558 return 0;
2559}
2560
2561/*------------------------------------------------------------------*/
2562/* Private handler : get beacon lost count */
2563static int ks_wlan_get_beacon_lost(struct net_device *dev,
2564 struct iw_request_info *info, __u32 * uwrq,
2565 char *extra)
2566{
2567 struct ks_wlan_private *priv =
2568 (struct ks_wlan_private *)netdev_priv(dev);
2569
2570 if (priv->sleep_mode == SLP_SLEEP) {
2571 return -EPERM;
2572 }
2573 /* for SLEEP MODE */
2574 *uwrq = priv->reg.beacon_lost_count;
2575 return 0;
2576}
2577
2578/*------------------------------------------------------------------*/
2579/* Private handler : set phy type */
2580static int ks_wlan_set_phy_type(struct net_device *dev,
2581 struct iw_request_info *info, __u32 * uwrq,
2582 char *extra)
2583{
2584 struct ks_wlan_private *priv =
2585 (struct ks_wlan_private *)netdev_priv(dev);
2586
2587 if (priv->sleep_mode == SLP_SLEEP) {
2588 return -EPERM;
2589 }
2590 /* for SLEEP MODE */
2591 if (*uwrq == D_11B_ONLY_MODE) { /* 0 */
2592 priv->reg.phy_type = D_11B_ONLY_MODE;
2593 } else if (*uwrq == D_11G_ONLY_MODE) { /* 1 */
2594 priv->reg.phy_type = D_11G_ONLY_MODE;
2595 } else if (*uwrq == D_11BG_COMPATIBLE_MODE) { /* 2 */
2596 priv->reg.phy_type = D_11BG_COMPATIBLE_MODE;
2597 } else
2598 return -EINVAL;
2599
2600 priv->need_commit |= SME_MODE_SET;
2601 return -EINPROGRESS; /* Call commit handler */
2602}
2603
2604/*------------------------------------------------------------------*/
2605/* Private handler : get phy type */
2606static int ks_wlan_get_phy_type(struct net_device *dev,
2607 struct iw_request_info *info, __u32 * uwrq,
2608 char *extra)
2609{
2610 struct ks_wlan_private *priv =
2611 (struct ks_wlan_private *)netdev_priv(dev);
2612
2613 if (priv->sleep_mode == SLP_SLEEP) {
2614 return -EPERM;
2615 }
2616 /* for SLEEP MODE */
2617 *uwrq = priv->reg.phy_type;
2618 return 0;
2619}
2620
2621/*------------------------------------------------------------------*/
2622/* Private handler : set cts mode */
2623static int ks_wlan_set_cts_mode(struct net_device *dev,
2624 struct iw_request_info *info, __u32 * uwrq,
2625 char *extra)
2626{
2627 struct ks_wlan_private *priv =
2628 (struct ks_wlan_private *)netdev_priv(dev);
2629
2630 if (priv->sleep_mode == SLP_SLEEP) {
2631 return -EPERM;
2632 }
2633 /* for SLEEP MODE */
2634 if (*uwrq == CTS_MODE_FALSE) { /* 0 */
2635 priv->reg.cts_mode = CTS_MODE_FALSE;
2636 } else if (*uwrq == CTS_MODE_TRUE) { /* 1 */
2637 if (priv->reg.phy_type == D_11G_ONLY_MODE ||
2638 priv->reg.phy_type == D_11BG_COMPATIBLE_MODE)
2639 priv->reg.cts_mode = CTS_MODE_TRUE;
2640 else
2641 priv->reg.cts_mode = CTS_MODE_FALSE;
2642 } else
2643 return -EINVAL;
2644
2645 priv->need_commit |= SME_MODE_SET;
2646 return -EINPROGRESS; /* Call commit handler */
2647}
2648
2649/*------------------------------------------------------------------*/
2650/* Private handler : get cts mode */
2651static int ks_wlan_get_cts_mode(struct net_device *dev,
2652 struct iw_request_info *info, __u32 * uwrq,
2653 char *extra)
2654{
2655 struct ks_wlan_private *priv =
2656 (struct ks_wlan_private *)netdev_priv(dev);
2657
2658 if (priv->sleep_mode == SLP_SLEEP) {
2659 return -EPERM;
2660 }
2661 /* for SLEEP MODE */
2662 *uwrq = priv->reg.cts_mode;
2663 return 0;
2664}
2665
2666/*------------------------------------------------------------------*/
2667/* Private handler : set sleep mode */
2668static int ks_wlan_set_sleep_mode(struct net_device *dev,
2669 struct iw_request_info *info,
2670 __u32 * uwrq, char *extra)
2671{
2672 struct ks_wlan_private *priv =
2673 (struct ks_wlan_private *)netdev_priv(dev);
2674
2675 DPRINTK(2, "\n");
2676
2677 if (*uwrq == SLP_SLEEP) {
2678 priv->sleep_mode = *uwrq;
2679 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2680
2681 hostif_sme_enqueue(priv, SME_STOP_REQUEST);
2682 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2683
2684 } else if (*uwrq == SLP_ACTIVE) {
2685 priv->sleep_mode = *uwrq;
2686 printk("SET_SLEEP_MODE %d\n", priv->sleep_mode);
2687 hostif_sme_enqueue(priv, SME_SLEEP_REQUEST);
2688 } else {
2689 printk("SET_SLEEP_MODE %d errror\n", *uwrq);
2690 return -EINVAL;
2691 }
2692
2693 return 0;
2694}
2695
2696/*------------------------------------------------------------------*/
2697/* Private handler : get sleep mode */
2698static int ks_wlan_get_sleep_mode(struct net_device *dev,
2699 struct iw_request_info *info,
2700 __u32 * uwrq, char *extra)
2701{
2702 struct ks_wlan_private *priv =
2703 (struct ks_wlan_private *)netdev_priv(dev);
2704
2705 DPRINTK(2, "GET_SLEEP_MODE %d\n", priv->sleep_mode);
2706 *uwrq = priv->sleep_mode;
2707
2708 return 0;
2709}
2710
2711#if 0
2712/*------------------------------------------------------------------*/
2713/* Private handler : set phy information timer */
2714static int ks_wlan_set_phy_information_timer(struct net_device *dev,
2715 struct iw_request_info *info,
2716 __u32 * uwrq, char *extra)
2717{
2718 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2719
2720 if (priv->sleep_mode == SLP_SLEEP) {
2721 return -EPERM;
2722 }
2723 /* for SLEEP MODE */
2724 if (*uwrq >= 0 && *uwrq <= 0xFFFF) /* 0-65535 */
2725 priv->reg.phy_info_timer = (uint16_t) * uwrq;
2726 else
2727 return -EINVAL;
2728
2729 hostif_sme_enqueue(priv, SME_PHY_INFO_REQUEST);
2730
2731 return 0;
2732}
2733
2734/*------------------------------------------------------------------*/
2735/* Private handler : get phy information timer */
2736static int ks_wlan_get_phy_information_timer(struct net_device *dev,
2737 struct iw_request_info *info,
2738 __u32 * uwrq, char *extra)
2739{
2740 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2741
2742 if (priv->sleep_mode == SLP_SLEEP) {
2743 return -EPERM;
2744 }
2745 /* for SLEEP MODE */
2746 *uwrq = priv->reg.phy_info_timer;
2747 return 0;
2748}
2749#endif
2750
2751#ifdef WPS
2752/*------------------------------------------------------------------*/
2753/* Private handler : set WPS enable */
2754static int ks_wlan_set_wps_enable(struct net_device *dev,
2755 struct iw_request_info *info, __u32 * uwrq,
2756 char *extra)
2757{
2758 struct ks_wlan_private *priv =
2759 (struct ks_wlan_private *)netdev_priv(dev);
2760 DPRINTK(2, "\n");
2761
2762 if (priv->sleep_mode == SLP_SLEEP) {
2763 return -EPERM;
2764 }
2765 /* for SLEEP MODE */
2766 if (*uwrq == 0 || *uwrq == 1)
2767 priv->wps.wps_enabled = *uwrq;
2768 else
2769 return -EINVAL;
2770
2771 hostif_sme_enqueue(priv, SME_WPS_ENABLE_REQUEST);
2772
2773 return 0;
2774}
2775
2776/*------------------------------------------------------------------*/
2777/* Private handler : get WPS enable */
2778static int ks_wlan_get_wps_enable(struct net_device *dev,
2779 struct iw_request_info *info, __u32 * uwrq,
2780 char *extra)
2781{
2782 struct ks_wlan_private *priv =
2783 (struct ks_wlan_private *)netdev_priv(dev);
2784 DPRINTK(2, "\n");
2785
2786 if (priv->sleep_mode == SLP_SLEEP) {
2787 return -EPERM;
2788 }
2789 /* for SLEEP MODE */
2790 *uwrq = priv->wps.wps_enabled;
2791 printk("return=%d\n", *uwrq);
2792
2793 return 0;
2794}
2795
2796/*------------------------------------------------------------------*/
2797/* Private handler : set WPS probe req */
2798static int ks_wlan_set_wps_probe_req(struct net_device *dev,
2799 struct iw_request_info *info,
2800 struct iw_point *dwrq, char *extra)
2801{
2802 uint8_t *p = extra;
2803 unsigned char len;
2804 struct ks_wlan_private *priv =
2805 (struct ks_wlan_private *)netdev_priv(dev);
2806
2807 DPRINTK(2, "\n");
2808
2809 if (priv->sleep_mode == SLP_SLEEP) {
2810 return -EPERM;
2811 }
2812 /* for SLEEP MODE */
2813 DPRINTK(2, "dwrq->length=%d\n", dwrq->length);
2814
2815 /* length check */
2816 if (p[1] + 2 != dwrq->length || dwrq->length > 256) {
2817 return -EINVAL;
2818 }
2819
2820 priv->wps.ielen = p[1] + 2 + 1; /* IE header + IE + sizeof(len) */
2821 len = p[1] + 2; /* IE header + IE */
2822
2823 memcpy(priv->wps.ie, &len, sizeof(len));
2824 p = memcpy(priv->wps.ie + 1, p, len);
2825
2826 DPRINTK(2, "%d(%#x): %02X %02X %02X %02X ... %02X %02X %02X\n",
2827 priv->wps.ielen, priv->wps.ielen, p[0], p[1], p[2], p[3],
2828 p[priv->wps.ielen - 3], p[priv->wps.ielen - 2],
2829 p[priv->wps.ielen - 1]);
2830
2831 hostif_sme_enqueue(priv, SME_WPS_PROBE_REQUEST);
2832
2833 return 0;
2834}
2835
2836#if 0
2837/*------------------------------------------------------------------*/
2838/* Private handler : get WPS probe req */
2839static int ks_wlan_get_wps_probe_req(struct net_device *dev,
2840 struct iw_request_info *info,
2841 __u32 * uwrq, char *extra)
2842{
2843 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2844 DPRINTK(2, "\n");
2845
2846 if (priv->sleep_mode == SLP_SLEEP) {
2847 return -EPERM;
2848 }
2849 /* for SLEEP MODE */
2850 return 0;
2851}
2852#endif
2853#endif /* WPS */
2854
2855/*------------------------------------------------------------------*/
2856/* Private handler : set tx gain control value */
2857static int ks_wlan_set_tx_gain(struct net_device *dev,
2858 struct iw_request_info *info, __u32 * uwrq,
2859 char *extra)
2860{
2861 struct ks_wlan_private *priv =
2862 (struct ks_wlan_private *)netdev_priv(dev);
2863
2864 if (priv->sleep_mode == SLP_SLEEP) {
2865 return -EPERM;
2866 }
2867 /* for SLEEP MODE */
2868 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2869 priv->gain.TxGain = (uint8_t) * uwrq;
2870 else
2871 return -EINVAL;
2872
2873 if (priv->gain.TxGain < 0xFF)
2874 priv->gain.TxMode = 1;
2875 else
2876 priv->gain.TxMode = 0;
2877
2878 hostif_sme_enqueue(priv, SME_SET_GAIN);
2879 return 0;
2880}
2881
2882/*------------------------------------------------------------------*/
2883/* Private handler : get tx gain control value */
2884static int ks_wlan_get_tx_gain(struct net_device *dev,
2885 struct iw_request_info *info, __u32 * uwrq,
2886 char *extra)
2887{
2888 struct ks_wlan_private *priv =
2889 (struct ks_wlan_private *)netdev_priv(dev);
2890
2891 if (priv->sleep_mode == SLP_SLEEP) {
2892 return -EPERM;
2893 }
2894 /* for SLEEP MODE */
2895 *uwrq = priv->gain.TxGain;
2896 hostif_sme_enqueue(priv, SME_GET_GAIN);
2897 return 0;
2898}
2899
2900/*------------------------------------------------------------------*/
2901/* Private handler : set rx gain control value */
2902static int ks_wlan_set_rx_gain(struct net_device *dev,
2903 struct iw_request_info *info, __u32 * uwrq,
2904 char *extra)
2905{
2906 struct ks_wlan_private *priv =
2907 (struct ks_wlan_private *)netdev_priv(dev);
2908
2909 if (priv->sleep_mode == SLP_SLEEP) {
2910 return -EPERM;
2911 }
2912 /* for SLEEP MODE */
2913 if (*uwrq >= 0 && *uwrq <= 0xFF) /* 0-255 */
2914 priv->gain.RxGain = (uint8_t) * uwrq;
2915 else
2916 return -EINVAL;
2917
2918 if (priv->gain.RxGain < 0xFF)
2919 priv->gain.RxMode = 1;
2920 else
2921 priv->gain.RxMode = 0;
2922
2923 hostif_sme_enqueue(priv, SME_SET_GAIN);
2924 return 0;
2925}
2926
2927/*------------------------------------------------------------------*/
2928/* Private handler : get rx gain control value */
2929static int ks_wlan_get_rx_gain(struct net_device *dev,
2930 struct iw_request_info *info, __u32 * uwrq,
2931 char *extra)
2932{
2933 struct ks_wlan_private *priv =
2934 (struct ks_wlan_private *)netdev_priv(dev);
2935
2936 if (priv->sleep_mode == SLP_SLEEP) {
2937 return -EPERM;
2938 }
2939 /* for SLEEP MODE */
2940 *uwrq = priv->gain.RxGain;
2941 hostif_sme_enqueue(priv, SME_GET_GAIN);
2942 return 0;
2943}
2944
2945#if 0
2946/*------------------------------------------------------------------*/
2947/* Private handler : set region value */
2948static int ks_wlan_set_region(struct net_device *dev,
2949 struct iw_request_info *info, __u32 * uwrq,
2950 char *extra)
2951{
2952 struct ks_wlan_private *priv = (struct ks_wlan_private *)dev->priv;
2953
2954 if (priv->sleep_mode == SLP_SLEEP) {
2955 return -EPERM;
2956 }
2957 /* for SLEEP MODE */
2958 if (*uwrq >= 0x9 && *uwrq <= 0xF) /* 0x9-0xf */
2959 priv->region = (uint8_t) * uwrq;
2960 else
2961 return -EINVAL;
2962
2963 hostif_sme_enqueue(priv, SME_SET_REGION);
2964 return 0;
2965}
2966#endif
2967
2968/*------------------------------------------------------------------*/
2969/* Private handler : get eeprom checksum result */
2970static int ks_wlan_get_eeprom_cksum(struct net_device *dev,
2971 struct iw_request_info *info, __u32 * uwrq,
2972 char *extra)
2973{
2974 struct ks_wlan_private *priv =
2975 (struct ks_wlan_private *)netdev_priv(dev);
2976
2977 *uwrq = priv->eeprom_checksum;
2978 return 0;
2979}
2980
2981static void print_hif_event(int event)
2982{
2983
2984 switch (event) {
2985 case HIF_DATA_REQ:
2986 printk("HIF_DATA_REQ\n");
2987 break;
2988 case HIF_DATA_IND:
2989 printk("HIF_DATA_IND\n");
2990 break;
2991 case HIF_MIB_GET_REQ:
2992 printk("HIF_MIB_GET_REQ\n");
2993 break;
2994 case HIF_MIB_GET_CONF:
2995 printk("HIF_MIB_GET_CONF\n");
2996 break;
2997 case HIF_MIB_SET_REQ:
2998 printk("HIF_MIB_SET_REQ\n");
2999 break;
3000 case HIF_MIB_SET_CONF:
3001 printk("HIF_MIB_SET_CONF\n");
3002 break;
3003 case HIF_POWERMGT_REQ:
3004 printk("HIF_POWERMGT_REQ\n");
3005 break;
3006 case HIF_POWERMGT_CONF:
3007 printk("HIF_POWERMGT_CONF\n");
3008 break;
3009 case HIF_START_REQ:
3010 printk("HIF_START_REQ\n");
3011 break;
3012 case HIF_START_CONF:
3013 printk("HIF_START_CONF\n");
3014 break;
3015 case HIF_CONNECT_IND:
3016 printk("HIF_CONNECT_IND\n");
3017 break;
3018 case HIF_STOP_REQ:
3019 printk("HIF_STOP_REQ\n");
3020 break;
3021 case HIF_STOP_CONF:
3022 printk("HIF_STOP_CONF\n");
3023 break;
3024 case HIF_PS_ADH_SET_REQ:
3025 printk("HIF_PS_ADH_SET_REQ\n");
3026 break;
3027 case HIF_PS_ADH_SET_CONF:
3028 printk("HIF_PS_ADH_SET_CONF\n");
3029 break;
3030 case HIF_INFRA_SET_REQ:
3031 printk("HIF_INFRA_SET_REQ\n");
3032 break;
3033 case HIF_INFRA_SET_CONF:
3034 printk("HIF_INFRA_SET_CONF\n");
3035 break;
3036 case HIF_ADH_SET_REQ:
3037 printk("HIF_ADH_SET_REQ\n");
3038 break;
3039 case HIF_ADH_SET_CONF:
3040 printk("HIF_ADH_SET_CONF\n");
3041 break;
3042 case HIF_AP_SET_REQ:
3043 printk("HIF_AP_SET_REQ\n");
3044 break;
3045 case HIF_AP_SET_CONF:
3046 printk("HIF_AP_SET_CONF\n");
3047 break;
3048 case HIF_ASSOC_INFO_IND:
3049 printk("HIF_ASSOC_INFO_IND\n");
3050 break;
3051 case HIF_MIC_FAILURE_REQ:
3052 printk("HIF_MIC_FAILURE_REQ\n");
3053 break;
3054 case HIF_MIC_FAILURE_CONF:
3055 printk("HIF_MIC_FAILURE_CONF\n");
3056 break;
3057 case HIF_SCAN_REQ:
3058 printk("HIF_SCAN_REQ\n");
3059 break;
3060 case HIF_SCAN_CONF:
3061 printk("HIF_SCAN_CONF\n");
3062 break;
3063 case HIF_PHY_INFO_REQ:
3064 printk("HIF_PHY_INFO_REQ\n");
3065 break;
3066 case HIF_PHY_INFO_CONF:
3067 printk("HIF_PHY_INFO_CONF\n");
3068 break;
3069 case HIF_SLEEP_REQ:
3070 printk("HIF_SLEEP_REQ\n");
3071 break;
3072 case HIF_SLEEP_CONF:
3073 printk("HIF_SLEEP_CONF\n");
3074 break;
3075 case HIF_PHY_INFO_IND:
3076 printk("HIF_PHY_INFO_IND\n");
3077 break;
3078 case HIF_SCAN_IND:
3079 printk("HIF_SCAN_IND\n");
3080 break;
3081 case HIF_INFRA_SET2_REQ:
3082 printk("HIF_INFRA_SET2_REQ\n");
3083 break;
3084 case HIF_INFRA_SET2_CONF:
3085 printk("HIF_INFRA_SET2_CONF\n");
3086 break;
3087 case HIF_ADH_SET2_REQ:
3088 printk("HIF_ADH_SET2_REQ\n");
3089 break;
3090 case HIF_ADH_SET2_CONF:
3091 printk("HIF_ADH_SET2_CONF\n");
3092 }
3093}
3094
3095/*------------------------------------------------------------------*/
3096/* Private handler : get host command history */
3097static int ks_wlan_hostt(struct net_device *dev, struct iw_request_info *info,
3098 __u32 * uwrq, char *extra)
3099{
3100 int i, event;
3101 struct ks_wlan_private *priv =
3102 (struct ks_wlan_private *)netdev_priv(dev);
3103
3104 for (i = 63; i >= 0; i--) {
3105 event =
3106 priv->hostt.buff[(priv->hostt.qtail - 1 - i) %
3107 SME_EVENT_BUFF_SIZE];
3108 print_hif_event(event);
3109 }
3110 return 0;
3111}
3112
3113/* Structures to export the Wireless Handlers */
3114
3115static const struct iw_priv_args ks_wlan_private_args[] = {
3116/*{ cmd, set_args, get_args, name[16] } */
3117 {KS_WLAN_GET_FIRM_VERSION, IW_PRIV_TYPE_NONE,
3118 IW_PRIV_TYPE_CHAR | (128 + 1), "GetFirmwareVer"},
3119#ifdef WPS
3120 {KS_WLAN_SET_WPS_ENABLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3121 IW_PRIV_TYPE_NONE, "SetWPSEnable"},
3122 {KS_WLAN_GET_WPS_ENABLE, IW_PRIV_TYPE_NONE,
3123 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetW"},
3124 {KS_WLAN_SET_WPS_PROBE_REQ, IW_PRIV_TYPE_BYTE | 2047, IW_PRIV_TYPE_NONE,
3125 "SetWPSProbeReq"},
3126#endif /* WPS */
3127 {KS_WLAN_SET_PREAMBLE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3128 IW_PRIV_TYPE_NONE, "SetPreamble"},
3129 {KS_WLAN_GET_PREAMBLE, IW_PRIV_TYPE_NONE,
3130 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPreamble"},
3131 {KS_WLAN_SET_POWER_SAVE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3132 IW_PRIV_TYPE_NONE, "SetPowerSave"},
3133 {KS_WLAN_GET_POWER_SAVE, IW_PRIV_TYPE_NONE,
3134 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPowerSave"},
3135 {KS_WLAN_SET_SCAN_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3136 IW_PRIV_TYPE_NONE, "SetScanType"},
3137 {KS_WLAN_GET_SCAN_TYPE, IW_PRIV_TYPE_NONE,
3138 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetScanType"},
3139 {KS_WLAN_SET_RX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3140 IW_PRIV_TYPE_NONE, "SetRxGain"},
3141 {KS_WLAN_GET_RX_GAIN, IW_PRIV_TYPE_NONE,
3142 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetRxGain"},
3143 {KS_WLAN_HOSTT, IW_PRIV_TYPE_NONE, IW_PRIV_TYPE_CHAR | (128 + 1),
3144 "hostt"},
3145 {KS_WLAN_SET_BEACON_LOST, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3146 IW_PRIV_TYPE_NONE, "SetBeaconLost"},
3147 {KS_WLAN_GET_BEACON_LOST, IW_PRIV_TYPE_NONE,
3148 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetBeaconLost"},
3149 {KS_WLAN_SET_SLEEP_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3150 IW_PRIV_TYPE_NONE, "SetSleepMode"},
3151 {KS_WLAN_GET_SLEEP_MODE, IW_PRIV_TYPE_NONE,
3152 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetSleepMode"},
3153 {KS_WLAN_SET_TX_GAIN, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3154 IW_PRIV_TYPE_NONE, "SetTxGain"},
3155 {KS_WLAN_GET_TX_GAIN, IW_PRIV_TYPE_NONE,
3156 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetTxGain"},
3157 {KS_WLAN_SET_PHY_TYPE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3158 IW_PRIV_TYPE_NONE, "SetPhyType"},
3159 {KS_WLAN_GET_PHY_TYPE, IW_PRIV_TYPE_NONE,
3160 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetPhyType"},
3161 {KS_WLAN_SET_CTS_MODE, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3162 IW_PRIV_TYPE_NONE, "SetCtsMode"},
3163 {KS_WLAN_GET_CTS_MODE, IW_PRIV_TYPE_NONE,
3164 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetCtsMode"},
3165 {KS_WLAN_GET_EEPROM_CKSUM, IW_PRIV_TYPE_NONE,
3166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "GetChecksum"},
3167};
3168
3169static const iw_handler ks_wlan_handler[] = {
3170 (iw_handler) ks_wlan_config_commit, /* SIOCSIWCOMMIT */
3171 (iw_handler) ks_wlan_get_name, /* SIOCGIWNAME */
3172 (iw_handler) NULL, /* SIOCSIWNWID */
3173 (iw_handler) NULL, /* SIOCGIWNWID */
3174 (iw_handler) ks_wlan_set_freq, /* SIOCSIWFREQ */
3175 (iw_handler) ks_wlan_get_freq, /* SIOCGIWFREQ */
3176 (iw_handler) ks_wlan_set_mode, /* SIOCSIWMODE */
3177 (iw_handler) ks_wlan_get_mode, /* SIOCGIWMODE */
3178#ifndef KSC_OPNOTSUPP
3179 (iw_handler) ks_wlan_set_sens, /* SIOCSIWSENS */
3180 (iw_handler) ks_wlan_get_sens, /* SIOCGIWSENS */
3181#else /* KSC_OPNOTSUPP */
3182 (iw_handler) NULL, /* SIOCSIWSENS */
3183 (iw_handler) NULL, /* SIOCGIWSENS */
3184#endif /* KSC_OPNOTSUPP */
3185 (iw_handler) NULL, /* SIOCSIWRANGE */
3186 (iw_handler) ks_wlan_get_range, /* SIOCGIWRANGE */
3187 (iw_handler) NULL, /* SIOCSIWPRIV */
3188 (iw_handler) NULL, /* SIOCGIWPRIV */
3189 (iw_handler) NULL, /* SIOCSIWSTATS */
3190 (iw_handler) ks_wlan_get_iwstats, /* SIOCGIWSTATS */
3191 (iw_handler) NULL, /* SIOCSIWSPY */
3192 (iw_handler) NULL, /* SIOCGIWSPY */
3193 (iw_handler) NULL, /* SIOCSIWTHRSPY */
3194 (iw_handler) NULL, /* SIOCGIWTHRSPY */
3195 (iw_handler) ks_wlan_set_wap, /* SIOCSIWAP */
3196 (iw_handler) ks_wlan_get_wap, /* SIOCGIWAP */
3197// (iw_handler) NULL, /* SIOCSIWMLME */
3198 (iw_handler) ks_wlan_set_mlme, /* SIOCSIWMLME */
3199 (iw_handler) ks_wlan_get_aplist, /* SIOCGIWAPLIST */
3200 (iw_handler) ks_wlan_set_scan, /* SIOCSIWSCAN */
3201 (iw_handler) ks_wlan_get_scan, /* SIOCGIWSCAN */
3202 (iw_handler) ks_wlan_set_essid, /* SIOCSIWESSID */
3203 (iw_handler) ks_wlan_get_essid, /* SIOCGIWESSID */
3204 (iw_handler) ks_wlan_set_nick, /* SIOCSIWNICKN */
3205 (iw_handler) ks_wlan_get_nick, /* SIOCGIWNICKN */
3206 (iw_handler) NULL, /* -- hole -- */
3207 (iw_handler) NULL, /* -- hole -- */
3208 (iw_handler) ks_wlan_set_rate, /* SIOCSIWRATE */
3209 (iw_handler) ks_wlan_get_rate, /* SIOCGIWRATE */
3210 (iw_handler) ks_wlan_set_rts, /* SIOCSIWRTS */
3211 (iw_handler) ks_wlan_get_rts, /* SIOCGIWRTS */
3212 (iw_handler) ks_wlan_set_frag, /* SIOCSIWFRAG */
3213 (iw_handler) ks_wlan_get_frag, /* SIOCGIWFRAG */
3214#ifndef KSC_OPNOTSUPP
3215 (iw_handler) ks_wlan_set_txpow, /* SIOCSIWTXPOW */
3216 (iw_handler) ks_wlan_get_txpow, /* SIOCGIWTXPOW */
3217 (iw_handler) ks_wlan_set_retry, /* SIOCSIWRETRY */
3218 (iw_handler) ks_wlan_get_retry, /* SIOCGIWRETRY */
3219#else /* KSC_OPNOTSUPP */
3220 (iw_handler) NULL, /* SIOCSIWTXPOW */
3221 (iw_handler) NULL, /* SIOCGIWTXPOW */
3222 (iw_handler) NULL, /* SIOCSIWRETRY */
3223 (iw_handler) NULL, /* SIOCGIWRETRY */
3224#endif /* KSC_OPNOTSUPP */
3225 (iw_handler) ks_wlan_set_encode, /* SIOCSIWENCODE */
3226 (iw_handler) ks_wlan_get_encode, /* SIOCGIWENCODE */
3227 (iw_handler) ks_wlan_set_power, /* SIOCSIWPOWER */
3228 (iw_handler) ks_wlan_get_power, /* SIOCGIWPOWER */
3229 (iw_handler) NULL, /* -- hole -- */
3230 (iw_handler) NULL, /* -- hole -- */
3231// (iw_handler) NULL, /* SIOCSIWGENIE */
3232 (iw_handler) ks_wlan_set_genie, /* SIOCSIWGENIE */
3233 (iw_handler) NULL, /* SIOCGIWGENIE */
3234 (iw_handler) ks_wlan_set_auth_mode, /* SIOCSIWAUTH */
3235 (iw_handler) ks_wlan_get_auth_mode, /* SIOCGIWAUTH */
3236 (iw_handler) ks_wlan_set_encode_ext, /* SIOCSIWENCODEEXT */
3237 (iw_handler) ks_wlan_get_encode_ext, /* SIOCGIWENCODEEXT */
3238 (iw_handler) ks_wlan_set_pmksa, /* SIOCSIWPMKSA */
3239 (iw_handler) NULL, /* -- hole -- */
3240};
3241
3242/* private_handler */
3243static const iw_handler ks_wlan_private_handler[] = {
3244 (iw_handler) NULL, /* 0 */
3245 (iw_handler) NULL, /* 1, used to be: KS_WLAN_GET_DRIVER_VERSION */
3246 (iw_handler) NULL, /* 2 */
3247 (iw_handler) ks_wlan_get_firmware_version, /* 3 KS_WLAN_GET_FIRM_VERSION */
3248#ifdef WPS
3249 (iw_handler) ks_wlan_set_wps_enable, /* 4 KS_WLAN_SET_WPS_ENABLE */
3250 (iw_handler) ks_wlan_get_wps_enable, /* 5 KS_WLAN_GET_WPS_ENABLE */
3251 (iw_handler) ks_wlan_set_wps_probe_req, /* 6 KS_WLAN_SET_WPS_PROBE_REQ */
3252#else
3253 (iw_handler) NULL, /* 4 */
3254 (iw_handler) NULL, /* 5 */
3255 (iw_handler) NULL, /* 6 */
3256#endif /* WPS */
3257
3258 (iw_handler) ks_wlan_get_eeprom_cksum, /* 7 KS_WLAN_GET_CONNECT */
3259 (iw_handler) ks_wlan_set_preamble, /* 8 KS_WLAN_SET_PREAMBLE */
3260 (iw_handler) ks_wlan_get_preamble, /* 9 KS_WLAN_GET_PREAMBLE */
3261 (iw_handler) ks_wlan_set_powermgt, /* 10 KS_WLAN_SET_POWER_SAVE */
3262 (iw_handler) ks_wlan_get_powermgt, /* 11 KS_WLAN_GET_POWER_SAVE */
3263 (iw_handler) ks_wlan_set_scan_type, /* 12 KS_WLAN_SET_SCAN_TYPE */
3264 (iw_handler) ks_wlan_get_scan_type, /* 13 KS_WLAN_GET_SCAN_TYPE */
3265 (iw_handler) ks_wlan_set_rx_gain, /* 14 KS_WLAN_SET_RX_GAIN */
3266 (iw_handler) ks_wlan_get_rx_gain, /* 15 KS_WLAN_GET_RX_GAIN */
3267 (iw_handler) ks_wlan_hostt, /* 16 KS_WLAN_HOSTT */
3268 (iw_handler) NULL, /* 17 */
3269 (iw_handler) ks_wlan_set_beacon_lost, /* 18 KS_WLAN_SET_BECAN_LOST */
3270 (iw_handler) ks_wlan_get_beacon_lost, /* 19 KS_WLAN_GET_BECAN_LOST */
3271 (iw_handler) ks_wlan_set_tx_gain, /* 20 KS_WLAN_SET_TX_GAIN */
3272 (iw_handler) ks_wlan_get_tx_gain, /* 21 KS_WLAN_GET_TX_GAIN */
3273 (iw_handler) ks_wlan_set_phy_type, /* 22 KS_WLAN_SET_PHY_TYPE */
3274 (iw_handler) ks_wlan_get_phy_type, /* 23 KS_WLAN_GET_PHY_TYPE */
3275 (iw_handler) ks_wlan_set_cts_mode, /* 24 KS_WLAN_SET_CTS_MODE */
3276 (iw_handler) ks_wlan_get_cts_mode, /* 25 KS_WLAN_GET_CTS_MODE */
3277 (iw_handler) NULL, /* 26 */
3278 (iw_handler) NULL, /* 27 */
3279 (iw_handler) ks_wlan_set_sleep_mode, /* 28 KS_WLAN_SET_SLEEP_MODE */
3280 (iw_handler) ks_wlan_get_sleep_mode, /* 29 KS_WLAN_GET_SLEEP_MODE */
3281 (iw_handler) NULL, /* 30 */
3282 (iw_handler) NULL, /* 31 */
3283};
3284
3285static const struct iw_handler_def ks_wlan_handler_def = {
3286 .num_standard = sizeof(ks_wlan_handler) / sizeof(iw_handler),
3287 .num_private = sizeof(ks_wlan_private_handler) / sizeof(iw_handler),
3288 .num_private_args =
3289 sizeof(ks_wlan_private_args) / sizeof(struct iw_priv_args),
3290 .standard = (iw_handler *) ks_wlan_handler,
3291 .private = (iw_handler *) ks_wlan_private_handler,
3292 .private_args = (struct iw_priv_args *)ks_wlan_private_args,
3293 .get_wireless_stats = ks_get_wireless_stats,
3294};
3295
3296static int ks_wlan_netdev_ioctl(struct net_device *dev, struct ifreq *rq,
3297 int cmd)
3298{
3299 int rc = 0;
3300 struct iwreq *wrq = (struct iwreq *)rq;
3301 switch (cmd) {
3302 case SIOCIWFIRSTPRIV + 20: /* KS_WLAN_SET_STOP_REQ */
3303 rc = ks_wlan_set_stop_request(dev, NULL, &(wrq->u.mode), NULL);
3304 break;
3305 // All other calls are currently unsupported
3306 default:
3307 rc = -EOPNOTSUPP;
3308 }
3309
3310 DPRINTK(5, "return=%d\n", rc);
3311 return rc;
3312}
3313
3314static
3315struct net_device_stats *ks_wlan_get_stats(struct net_device *dev)
3316{
3317 struct ks_wlan_private *priv = netdev_priv(dev);
3318
3319 if (priv->dev_state < DEVICE_STATE_READY) {
3320 return NULL; /* not finished initialize */
3321 }
3322
3323 return &priv->nstats;
3324}
3325
3326static
3327int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
3328{
3329 struct ks_wlan_private *priv = netdev_priv(dev);
3330 struct sockaddr *mac_addr = (struct sockaddr *)addr;
3331 if (netif_running(dev))
3332 return -EBUSY;
3333 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
3334 memcpy(priv->eth_addr, mac_addr->sa_data, ETH_ALEN);
3335
3336 priv->mac_address_valid = 0;
3337 hostif_sme_enqueue(priv, SME_MACADDRESS_SET_REQUEST);
3338 printk(KERN_INFO
3339 "ks_wlan: MAC ADDRESS = %02x:%02x:%02x:%02x:%02x:%02x\n",
3340 priv->eth_addr[0], priv->eth_addr[1], priv->eth_addr[2],
3341 priv->eth_addr[3], priv->eth_addr[4], priv->eth_addr[5]);
3342 return 0;
3343}
3344
3345static
3346void ks_wlan_tx_timeout(struct net_device *dev)
3347{
3348 struct ks_wlan_private *priv = netdev_priv(dev);
3349
3350 DPRINTK(1, "head(%d) tail(%d)!!\n", priv->tx_dev.qhead,
3351 priv->tx_dev.qtail);
3352 if (!netif_queue_stopped(dev)) {
3353 netif_stop_queue(dev);
3354 }
3355 priv->nstats.tx_errors++;
3356 netif_wake_queue(dev);
3357
3358 return;
3359}
3360
3361static
3362int ks_wlan_start_xmit(struct sk_buff *skb, struct net_device *dev)
3363{
3364 struct ks_wlan_private *priv = netdev_priv(dev);
3365 int rc = 0;
3366
3367 DPRINTK(3, "in_interrupt()=%ld\n", in_interrupt());
3368
3369 if (skb == NULL) {
3370 printk(KERN_ERR "ks_wlan: skb == NULL!!!\n");
3371 return 0;
3372 }
3373 if (priv->dev_state < DEVICE_STATE_READY) {
3374 dev_kfree_skb(skb);
3375 return 0; /* not finished initialize */
3376 }
3377
3378 if (netif_running(dev))
3379 netif_stop_queue(dev);
3380
3381 rc = hostif_data_request(priv, skb);
3382 netif_trans_update(dev);
3383
3384 DPRINTK(4, "rc=%d\n", rc);
3385 if (rc) {
3386 rc = 0;
3387 }
3388
3389 return rc;
3390}
3391
3392void send_packet_complete(void *arg1, void *arg2)
3393{
3394 struct ks_wlan_private *priv = (struct ks_wlan_private *)arg1;
3395 struct sk_buff *packet = (struct sk_buff *)arg2;
3396
3397 DPRINTK(3, "\n");
3398
3399 priv->nstats.tx_bytes += packet->len;
3400 priv->nstats.tx_packets++;
3401
3402 if (netif_queue_stopped(priv->net_dev))
3403 netif_wake_queue(priv->net_dev);
3404
3405 if (packet) {
3406 dev_kfree_skb(packet);
3407 packet = NULL;
3408 }
3409
3410}
3411
3412/* Set or clear the multicast filter for this adaptor.
3413 This routine is not state sensitive and need not be SMP locked. */
3414static
3415void ks_wlan_set_multicast_list(struct net_device *dev)
3416{
3417 struct ks_wlan_private *priv = netdev_priv(dev);
3418
3419 DPRINTK(4, "\n");
3420 if (priv->dev_state < DEVICE_STATE_READY) {
3421 return; /* not finished initialize */
3422 }
3423 hostif_sme_enqueue(priv, SME_MULTICAST_REQUEST);
3424
3425 return;
3426}
3427
3428static
3429int ks_wlan_open(struct net_device *dev)
3430{
3431 struct ks_wlan_private *priv = netdev_priv(dev);
3432
3433 priv->cur_rx = 0;
3434
3435 if (!priv->mac_address_valid) {
3436 printk(KERN_ERR "ks_wlan : %s Not READY !!\n", dev->name);
3437 return -EBUSY;
3438 } else
3439 netif_start_queue(dev);
3440
3441 return 0;
3442}
3443
3444static
3445int ks_wlan_close(struct net_device *dev)
3446{
3447
3448 netif_stop_queue(dev);
3449
3450 DPRINTK(4, "%s: Shutting down ethercard, status was 0x%4.4x.\n",
3451 dev->name, 0x00);
3452
3453 return 0;
3454}
3455
3456/* Operational parameters that usually are not changed. */
3457/* Time in jiffies before concluding the transmitter is hung. */
3458#define TX_TIMEOUT (3*HZ)
3459static const unsigned char dummy_addr[] =
3460 { 0x00, 0x0b, 0xe3, 0x00, 0x00, 0x00 };
3461
3462static const struct net_device_ops ks_wlan_netdev_ops = {
3463 .ndo_start_xmit = ks_wlan_start_xmit,
3464 .ndo_open = ks_wlan_open,
3465 .ndo_stop = ks_wlan_close,
3466 .ndo_do_ioctl = ks_wlan_netdev_ioctl,
3467 .ndo_set_mac_address = ks_wlan_set_mac_address,
3468 .ndo_get_stats = ks_wlan_get_stats,
3469 .ndo_tx_timeout = ks_wlan_tx_timeout,
3470 .ndo_set_rx_mode = ks_wlan_set_multicast_list,
3471};
3472
3473int ks_wlan_net_start(struct net_device *dev)
3474{
3475 struct ks_wlan_private *priv;
3476 /* int rc; */
3477
3478 priv = netdev_priv(dev);
3479 priv->mac_address_valid = 0;
3480 priv->need_commit = 0;
3481
3482 priv->device_open_status = 1;
3483
3484 /* phy information update timer */
3485 atomic_set(&update_phyinfo, 0);
3486 init_timer(&update_phyinfo_timer);
3487 update_phyinfo_timer.function = ks_wlan_update_phyinfo_timeout;
3488 update_phyinfo_timer.data = (unsigned long)priv;
3489
3490 /* dummy address set */
3491 memcpy(priv->eth_addr, dummy_addr, ETH_ALEN);
3492 dev->dev_addr[0] = priv->eth_addr[0];
3493 dev->dev_addr[1] = priv->eth_addr[1];
3494 dev->dev_addr[2] = priv->eth_addr[2];
3495 dev->dev_addr[3] = priv->eth_addr[3];
3496 dev->dev_addr[4] = priv->eth_addr[4];
3497 dev->dev_addr[5] = priv->eth_addr[5];
3498 dev->dev_addr[6] = 0x00;
3499 dev->dev_addr[7] = 0x00;
3500
3501 /* The ks_wlan-specific entries in the device structure. */
3502 dev->netdev_ops = &ks_wlan_netdev_ops;
3503 dev->wireless_handlers = (struct iw_handler_def *)&ks_wlan_handler_def;
3504 dev->watchdog_timeo = TX_TIMEOUT;
3505
3506 netif_carrier_off(dev);
3507
3508 return 0;
3509}
3510
3511int ks_wlan_net_stop(struct net_device *dev)
3512{
3513 struct ks_wlan_private *priv = netdev_priv(dev);
3514
3515 int ret = 0;
3516 priv->device_open_status = 0;
3517 del_timer_sync(&update_phyinfo_timer);
3518
3519 if (netif_running(dev))
3520 netif_stop_queue(dev);
3521
3522 return ret;
3523}
3524
3525int ks_wlan_reset(struct net_device *dev)
3526{
3527 return 0;
3528}
diff --git a/drivers/staging/ks7010/michael_mic.c b/drivers/staging/ks7010/michael_mic.c
new file mode 100644
index 000000000000..e14c109b3cab
--- /dev/null
+++ b/drivers/staging/ks7010/michael_mic.c
@@ -0,0 +1,139 @@
1/*
2 * Driver for KeyStream wireless LAN
3 *
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/types.h>
13#include <linux/string.h>
14#include "michael_mic.h"
15
16// Rotation functions on 32 bit values
17#define ROL32( A, n ) ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) )
18#define ROR32( A, n ) ROL32( (A), 32-(n) )
19// Convert from Byte[] to UInt32 in a portable way
20#define getUInt32( A, B ) (uint32_t)(A[B+0] << 0) + (A[B+1] << 8) + (A[B+2] << 16) + (A[B+3] << 24)
21
22// Convert from UInt32 to Byte[] in a portable way
23#define putUInt32( A, B, C ) A[B+0] = (uint8_t) (C & 0xff); \
24 A[B+1] = (uint8_t) ((C>>8) & 0xff); \
25 A[B+2] = (uint8_t) ((C>>16) & 0xff); \
26 A[B+3] = (uint8_t) ((C>>24) & 0xff)
27
28// Reset the state to the empty message.
29#define MichaelClear( A ) A->L = A->K0; \
30 A->R = A->K1; \
31 A->nBytesInM = 0;
32
33static
34void MichaelInitializeFunction(struct michel_mic_t *Mic, uint8_t * key)
35{
36 // Set the key
37 Mic->K0 = getUInt32(key, 0);
38 Mic->K1 = getUInt32(key, 4);
39
40 //clear();
41 MichaelClear(Mic);
42}
43
44#define MichaelBlockFunction(L, R) \
45do{ \
46 R ^= ROL32( L, 17 ); \
47 L += R; \
48 R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8); \
49 L += R; \
50 R ^= ROL32( L, 3 ); \
51 L += R; \
52 R ^= ROR32( L, 2 ); \
53 L += R; \
54}while(0)
55
56static
57void MichaelAppend(struct michel_mic_t *Mic, uint8_t * src, int nBytes)
58{
59 int addlen;
60 if (Mic->nBytesInM) {
61 addlen = 4 - Mic->nBytesInM;
62 if (addlen > nBytes)
63 addlen = nBytes;
64 memcpy(&Mic->M[Mic->nBytesInM], src, addlen);
65 Mic->nBytesInM += addlen;
66 src += addlen;
67 nBytes -= addlen;
68
69 if (Mic->nBytesInM < 4)
70 return;
71
72 Mic->L ^= getUInt32(Mic->M, 0);
73 MichaelBlockFunction(Mic->L, Mic->R);
74 Mic->nBytesInM = 0;
75 }
76
77 while (nBytes >= 4) {
78 Mic->L ^= getUInt32(src, 0);
79 MichaelBlockFunction(Mic->L, Mic->R);
80 src += 4;
81 nBytes -= 4;
82 }
83
84 if (nBytes > 0) {
85 Mic->nBytesInM = nBytes;
86 memcpy(Mic->M, src, nBytes);
87 }
88}
89
90static
91void MichaelGetMIC(struct michel_mic_t *Mic, uint8_t * dst)
92{
93 uint8_t *data = Mic->M;
94 switch (Mic->nBytesInM) {
95 case 0:
96 Mic->L ^= 0x5a;
97 break;
98 case 1:
99 Mic->L ^= data[0] | 0x5a00;
100 break;
101 case 2:
102 Mic->L ^= data[0] | (data[1] << 8) | 0x5a0000;
103 break;
104 case 3:
105 Mic->L ^= data[0] | (data[1] << 8) | (data[2] << 16) |
106 0x5a000000;
107 break;
108 }
109 MichaelBlockFunction(Mic->L, Mic->R);
110 MichaelBlockFunction(Mic->L, Mic->R);
111 // The appendByte function has already computed the result.
112 putUInt32(dst, 0, Mic->L);
113 putUInt32(dst, 4, Mic->R);
114
115 // Reset to the empty message.
116 MichaelClear(Mic);
117}
118
119void MichaelMICFunction(struct michel_mic_t *Mic, uint8_t * Key,
120 uint8_t * Data, int Len, uint8_t priority,
121 uint8_t * Result)
122{
123 uint8_t pad_data[4] = { priority, 0, 0, 0 };
124 // Compute the MIC value
125 /*
126 * IEEE802.11i page 47
127 * Figure 43g TKIP MIC processing format
128 * +--+--+--------+--+----+--+--+--+--+--+--+--+--+
129 * |6 |6 |1 |3 |M |1 |1 |1 |1 |1 |1 |1 |1 | Octet
130 * +--+--+--------+--+----+--+--+--+--+--+--+--+--+
131 * |DA|SA|Priority|0 |Data|M0|M1|M2|M3|M4|M5|M6|M7|
132 * +--+--+--------+--+----+--+--+--+--+--+--+--+--+
133 */
134 MichaelInitializeFunction(Mic, Key);
135 MichaelAppend(Mic, (uint8_t *) Data, 12); /* |DA|SA| */
136 MichaelAppend(Mic, pad_data, 4); /* |Priority|0|0|0| */
137 MichaelAppend(Mic, (uint8_t *) (Data + 12), Len - 12); /* |Data| */
138 MichaelGetMIC(Mic, Result);
139}
diff --git a/drivers/staging/ks7010/michael_mic.h b/drivers/staging/ks7010/michael_mic.h
new file mode 100644
index 000000000000..c7e4eb280961
--- /dev/null
+++ b/drivers/staging/ks7010/michael_mic.h
@@ -0,0 +1,26 @@
1/*
2 * Driver for KeyStream wireless LAN
3 *
4 * Copyright (C) 2005-2008 KeyStream Corp.
5 * Copyright (C) 2009 Renesas Technology Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12/* MichelMIC routine define */
13struct michel_mic_t {
14 uint32_t K0; // Key
15 uint32_t K1; // Key
16 uint32_t L; // Current state
17 uint32_t R; // Current state
18 uint8_t M[4]; // Message accumulator (single word)
19 int nBytesInM; // # bytes in M
20 uint8_t Result[8];
21};
22
23extern
24void MichaelMICFunction(struct michel_mic_t *Mic, uint8_t * Key,
25 uint8_t * Data, int Len, uint8_t priority,
26 uint8_t * Result);
diff --git a/drivers/staging/lustre/include/linux/libcfs/curproc.h b/drivers/staging/lustre/include/linux/libcfs/curproc.h
index 1edfca58c1c6..be0675d8ff5e 100644
--- a/drivers/staging/lustre/include/linux/libcfs/curproc.h
+++ b/drivers/staging/lustre/include/linux/libcfs/curproc.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index 4141afb101bb..3f6447c65042 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
index 455c54d0d17c..25adab19fd86 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
index 2e008bffc89a..d3f9a6020ee3 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_fail.h
@@ -16,10 +16,6 @@
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see http://www.gnu.org/licenses 17 * version 2 along with this program; If not, see http://www.gnu.org/licenses
18 * 18 *
19 * Please contact Oracle Corporation, Inc., 500 Oracle Parkway, Redwood Shores,
20 * CA 94065 USA or visit www.oracle.com if you need additional information or
21 * have any questions.
22 *
23 * GPL HEADER END 19 * GPL HEADER END
24 */ 20 */
25/* 21/*
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h
index 119986bc7961..6949a1846635 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_hash.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
index 4b9102bd95d5..cce6b58e3682 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_prim.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_prim.h
index ac4e8cfe6c8c..8c75d5075590 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_prim.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_prim.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
index 2fd2a9690a34..4daa3823f60a 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
index e02cde5aeca1..0ee60ff336f2 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h
index 2c7ec2d28f38..008da4497bda 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_time.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h
index f9b20c5accbf..a7e1340e69a1 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_workitem.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h
index a268ef7aa19d..e8695e4a39d1 100644
--- a/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h
index 7656b09b8752..b646acd1f7e7 100644
--- a/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h
+++ b/drivers/staging/lustre/include/linux/libcfs/linux/linux-time.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/include/linux/lnet/lib-dlc.h b/drivers/staging/lustre/include/linux/lnet/lib-dlc.h
index 6ce9accb91ad..dfff17088403 100644
--- a/drivers/staging/lustre/include/linux/lnet/lib-dlc.h
+++ b/drivers/staging/lustre/include/linux/lnet/lib-dlc.h
@@ -35,7 +35,7 @@
35#define MAX_NUM_SHOW_ENTRIES 32 35#define MAX_NUM_SHOW_ENTRIES 32
36#define LNET_MAX_STR_LEN 128 36#define LNET_MAX_STR_LEN 128
37#define LNET_MAX_SHOW_NUM_CPT 128 37#define LNET_MAX_SHOW_NUM_CPT 128
38#define LNET_UNDEFINED_HOPS ((__u32) -1) 38#define LNET_UNDEFINED_HOPS ((__u32)(-1))
39 39
40struct lnet_ioctl_config_lnd_cmn_tunables { 40struct lnet_ioctl_config_lnd_cmn_tunables {
41 __u32 lct_version; 41 __u32 lct_version;
diff --git a/drivers/staging/lustre/include/linux/lnet/lib-types.h b/drivers/staging/lustre/include/linux/lnet/lib-types.h
index 24c4a08e6dc6..7967b013cbae 100644
--- a/drivers/staging/lustre/include/linux/lnet/lib-types.h
+++ b/drivers/staging/lustre/include/linux/lnet/lib-types.h
@@ -38,6 +38,7 @@
38#include <linux/kthread.h> 38#include <linux/kthread.h>
39#include <linux/uio.h> 39#include <linux/uio.h>
40#include <linux/types.h> 40#include <linux/types.h>
41#include <linux/completion.h>
41 42
42#include "types.h" 43#include "types.h"
43#include "lnetctl.h" 44#include "lnetctl.h"
@@ -610,7 +611,7 @@ typedef struct {
610 /* rcd ready for free */ 611 /* rcd ready for free */
611 struct list_head ln_rcd_zombie; 612 struct list_head ln_rcd_zombie;
612 /* serialise startup/shutdown */ 613 /* serialise startup/shutdown */
613 struct semaphore ln_rc_signal; 614 struct completion ln_rc_signal;
614 615
615 struct mutex ln_api_mutex; 616 struct mutex ln_api_mutex;
616 struct mutex ln_lnd_mutex; 617 struct mutex ln_lnd_mutex;
diff --git a/drivers/staging/lustre/include/linux/lnet/types.h b/drivers/staging/lustre/include/linux/lnet/types.h
index 1c679cb72785..e098b6c086e1 100644
--- a/drivers/staging/lustre/include/linux/lnet/types.h
+++ b/drivers/staging/lustre/include/linux/lnet/types.h
@@ -68,9 +68,9 @@ typedef __u64 lnet_nid_t;
68typedef __u32 lnet_pid_t; 68typedef __u32 lnet_pid_t;
69 69
70/** wildcard NID that matches any end-point address */ 70/** wildcard NID that matches any end-point address */
71#define LNET_NID_ANY ((lnet_nid_t) -1) 71#define LNET_NID_ANY ((lnet_nid_t)(-1))
72/** wildcard PID that matches any lnet_pid_t */ 72/** wildcard PID that matches any lnet_pid_t */
73#define LNET_PID_ANY ((lnet_pid_t) -1) 73#define LNET_PID_ANY ((lnet_pid_t)(-1))
74 74
75#define LNET_PID_RESERVED 0xf0000000 /* reserved bits in PID */ 75#define LNET_PID_RESERVED 0xf0000000 /* reserved bits in PID */
76#define LNET_PID_USERFLAG 0x80000000 /* set in userspace peers */ 76#define LNET_PID_USERFLAG 0x80000000 /* set in userspace peers */
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 6c59f2ff2220..4f5978b3767b 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -44,7 +40,7 @@
44 40
45static lnd_t the_o2iblnd; 41static lnd_t the_o2iblnd;
46 42
47kib_data_t kiblnd_data; 43struct kib_data kiblnd_data;
48 44
49static __u32 kiblnd_cksum(void *ptr, int nob) 45static __u32 kiblnd_cksum(void *ptr, int nob)
50{ 46{
@@ -98,40 +94,40 @@ static char *kiblnd_msgtype2str(int type)
98 94
99static int kiblnd_msgtype2size(int type) 95static int kiblnd_msgtype2size(int type)
100{ 96{
101 const int hdr_size = offsetof(kib_msg_t, ibm_u); 97 const int hdr_size = offsetof(struct kib_msg, ibm_u);
102 98
103 switch (type) { 99 switch (type) {
104 case IBLND_MSG_CONNREQ: 100 case IBLND_MSG_CONNREQ:
105 case IBLND_MSG_CONNACK: 101 case IBLND_MSG_CONNACK:
106 return hdr_size + sizeof(kib_connparams_t); 102 return hdr_size + sizeof(struct kib_connparams);
107 103
108 case IBLND_MSG_NOOP: 104 case IBLND_MSG_NOOP:
109 return hdr_size; 105 return hdr_size;
110 106
111 case IBLND_MSG_IMMEDIATE: 107 case IBLND_MSG_IMMEDIATE:
112 return offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[0]); 108 return offsetof(struct kib_msg, ibm_u.immediate.ibim_payload[0]);
113 109
114 case IBLND_MSG_PUT_REQ: 110 case IBLND_MSG_PUT_REQ:
115 return hdr_size + sizeof(kib_putreq_msg_t); 111 return hdr_size + sizeof(struct kib_putreq_msg);
116 112
117 case IBLND_MSG_PUT_ACK: 113 case IBLND_MSG_PUT_ACK:
118 return hdr_size + sizeof(kib_putack_msg_t); 114 return hdr_size + sizeof(struct kib_putack_msg);
119 115
120 case IBLND_MSG_GET_REQ: 116 case IBLND_MSG_GET_REQ:
121 return hdr_size + sizeof(kib_get_msg_t); 117 return hdr_size + sizeof(struct kib_get_msg);
122 118
123 case IBLND_MSG_PUT_NAK: 119 case IBLND_MSG_PUT_NAK:
124 case IBLND_MSG_PUT_DONE: 120 case IBLND_MSG_PUT_DONE:
125 case IBLND_MSG_GET_DONE: 121 case IBLND_MSG_GET_DONE:
126 return hdr_size + sizeof(kib_completion_msg_t); 122 return hdr_size + sizeof(struct kib_completion_msg);
127 default: 123 default:
128 return -1; 124 return -1;
129 } 125 }
130} 126}
131 127
132static int kiblnd_unpack_rd(kib_msg_t *msg, int flip) 128static int kiblnd_unpack_rd(struct kib_msg *msg, int flip)
133{ 129{
134 kib_rdma_desc_t *rd; 130 struct kib_rdma_desc *rd;
135 int nob; 131 int nob;
136 int n; 132 int n;
137 int i; 133 int i;
@@ -156,7 +152,7 @@ static int kiblnd_unpack_rd(kib_msg_t *msg, int flip)
156 return 1; 152 return 1;
157 } 153 }
158 154
159 nob = offsetof(kib_msg_t, ibm_u) + 155 nob = offsetof(struct kib_msg, ibm_u) +
160 kiblnd_rd_msg_size(rd, msg->ibm_type, n); 156 kiblnd_rd_msg_size(rd, msg->ibm_type, n);
161 157
162 if (msg->ibm_nob < nob) { 158 if (msg->ibm_nob < nob) {
@@ -176,10 +172,10 @@ static int kiblnd_unpack_rd(kib_msg_t *msg, int flip)
176 return 0; 172 return 0;
177} 173}
178 174
179void kiblnd_pack_msg(lnet_ni_t *ni, kib_msg_t *msg, int version, 175void kiblnd_pack_msg(lnet_ni_t *ni, struct kib_msg *msg, int version,
180 int credits, lnet_nid_t dstnid, __u64 dststamp) 176 int credits, lnet_nid_t dstnid, __u64 dststamp)
181{ 177{
182 kib_net_t *net = ni->ni_data; 178 struct kib_net *net = ni->ni_data;
183 179
184 /* 180 /*
185 * CAVEAT EMPTOR! all message fields not set here should have been 181 * CAVEAT EMPTOR! all message fields not set here should have been
@@ -202,9 +198,9 @@ void kiblnd_pack_msg(lnet_ni_t *ni, kib_msg_t *msg, int version,
202 } 198 }
203} 199}
204 200
205int kiblnd_unpack_msg(kib_msg_t *msg, int nob) 201int kiblnd_unpack_msg(struct kib_msg *msg, int nob)
206{ 202{
207 const int hdr_size = offsetof(kib_msg_t, ibm_u); 203 const int hdr_size = offsetof(struct kib_msg, ibm_u);
208 __u32 msg_cksum; 204 __u32 msg_cksum;
209 __u16 version; 205 __u16 version;
210 int msg_nob; 206 int msg_nob;
@@ -315,10 +311,10 @@ int kiblnd_unpack_msg(kib_msg_t *msg, int nob)
315 return 0; 311 return 0;
316} 312}
317 313
318int kiblnd_create_peer(lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid) 314int kiblnd_create_peer(lnet_ni_t *ni, struct kib_peer **peerp, lnet_nid_t nid)
319{ 315{
320 kib_peer_t *peer; 316 struct kib_peer *peer;
321 kib_net_t *net = ni->ni_data; 317 struct kib_net *net = ni->ni_data;
322 int cpt = lnet_cpt_of_nid(nid); 318 int cpt = lnet_cpt_of_nid(nid);
323 unsigned long flags; 319 unsigned long flags;
324 320
@@ -357,9 +353,9 @@ int kiblnd_create_peer(lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid)
357 return 0; 353 return 0;
358} 354}
359 355
360void kiblnd_destroy_peer(kib_peer_t *peer) 356void kiblnd_destroy_peer(struct kib_peer *peer)
361{ 357{
362 kib_net_t *net = peer->ibp_ni->ni_data; 358 struct kib_net *net = peer->ibp_ni->ni_data;
363 359
364 LASSERT(net); 360 LASSERT(net);
365 LASSERT(!atomic_read(&peer->ibp_refcount)); 361 LASSERT(!atomic_read(&peer->ibp_refcount));
@@ -378,7 +374,7 @@ void kiblnd_destroy_peer(kib_peer_t *peer)
378 atomic_dec(&net->ibn_npeers); 374 atomic_dec(&net->ibn_npeers);
379} 375}
380 376
381kib_peer_t *kiblnd_find_peer_locked(lnet_nid_t nid) 377struct kib_peer *kiblnd_find_peer_locked(lnet_nid_t nid)
382{ 378{
383 /* 379 /*
384 * the caller is responsible for accounting the additional reference 380 * the caller is responsible for accounting the additional reference
@@ -386,10 +382,10 @@ kib_peer_t *kiblnd_find_peer_locked(lnet_nid_t nid)
386 */ 382 */
387 struct list_head *peer_list = kiblnd_nid2peerlist(nid); 383 struct list_head *peer_list = kiblnd_nid2peerlist(nid);
388 struct list_head *tmp; 384 struct list_head *tmp;
389 kib_peer_t *peer; 385 struct kib_peer *peer;
390 386
391 list_for_each(tmp, peer_list) { 387 list_for_each(tmp, peer_list) {
392 peer = list_entry(tmp, kib_peer_t, ibp_list); 388 peer = list_entry(tmp, struct kib_peer, ibp_list);
393 LASSERT(!kiblnd_peer_idle(peer)); 389 LASSERT(!kiblnd_peer_idle(peer));
394 390
395 if (peer->ibp_nid != nid) 391 if (peer->ibp_nid != nid)
@@ -404,7 +400,7 @@ kib_peer_t *kiblnd_find_peer_locked(lnet_nid_t nid)
404 return NULL; 400 return NULL;
405} 401}
406 402
407void kiblnd_unlink_peer_locked(kib_peer_t *peer) 403void kiblnd_unlink_peer_locked(struct kib_peer *peer)
408{ 404{
409 LASSERT(list_empty(&peer->ibp_conns)); 405 LASSERT(list_empty(&peer->ibp_conns));
410 406
@@ -417,7 +413,7 @@ void kiblnd_unlink_peer_locked(kib_peer_t *peer)
417static int kiblnd_get_peer_info(lnet_ni_t *ni, int index, 413static int kiblnd_get_peer_info(lnet_ni_t *ni, int index,
418 lnet_nid_t *nidp, int *count) 414 lnet_nid_t *nidp, int *count)
419{ 415{
420 kib_peer_t *peer; 416 struct kib_peer *peer;
421 struct list_head *ptmp; 417 struct list_head *ptmp;
422 int i; 418 int i;
423 unsigned long flags; 419 unsigned long flags;
@@ -426,7 +422,7 @@ static int kiblnd_get_peer_info(lnet_ni_t *ni, int index,
426 422
427 for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) { 423 for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
428 list_for_each(ptmp, &kiblnd_data.kib_peers[i]) { 424 list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
429 peer = list_entry(ptmp, kib_peer_t, ibp_list); 425 peer = list_entry(ptmp, struct kib_peer, ibp_list);
430 LASSERT(!kiblnd_peer_idle(peer)); 426 LASSERT(!kiblnd_peer_idle(peer));
431 427
432 if (peer->ibp_ni != ni) 428 if (peer->ibp_ni != ni)
@@ -448,17 +444,17 @@ static int kiblnd_get_peer_info(lnet_ni_t *ni, int index,
448 return -ENOENT; 444 return -ENOENT;
449} 445}
450 446
451static void kiblnd_del_peer_locked(kib_peer_t *peer) 447static void kiblnd_del_peer_locked(struct kib_peer *peer)
452{ 448{
453 struct list_head *ctmp; 449 struct list_head *ctmp;
454 struct list_head *cnxt; 450 struct list_head *cnxt;
455 kib_conn_t *conn; 451 struct kib_conn *conn;
456 452
457 if (list_empty(&peer->ibp_conns)) { 453 if (list_empty(&peer->ibp_conns)) {
458 kiblnd_unlink_peer_locked(peer); 454 kiblnd_unlink_peer_locked(peer);
459 } else { 455 } else {
460 list_for_each_safe(ctmp, cnxt, &peer->ibp_conns) { 456 list_for_each_safe(ctmp, cnxt, &peer->ibp_conns) {
461 conn = list_entry(ctmp, kib_conn_t, ibc_list); 457 conn = list_entry(ctmp, struct kib_conn, ibc_list);
462 458
463 kiblnd_close_conn_locked(conn, 0); 459 kiblnd_close_conn_locked(conn, 0);
464 } 460 }
@@ -475,7 +471,7 @@ static int kiblnd_del_peer(lnet_ni_t *ni, lnet_nid_t nid)
475 LIST_HEAD(zombies); 471 LIST_HEAD(zombies);
476 struct list_head *ptmp; 472 struct list_head *ptmp;
477 struct list_head *pnxt; 473 struct list_head *pnxt;
478 kib_peer_t *peer; 474 struct kib_peer *peer;
479 int lo; 475 int lo;
480 int hi; 476 int hi;
481 int i; 477 int i;
@@ -494,7 +490,7 @@ static int kiblnd_del_peer(lnet_ni_t *ni, lnet_nid_t nid)
494 490
495 for (i = lo; i <= hi; i++) { 491 for (i = lo; i <= hi; i++) {
496 list_for_each_safe(ptmp, pnxt, &kiblnd_data.kib_peers[i]) { 492 list_for_each_safe(ptmp, pnxt, &kiblnd_data.kib_peers[i]) {
497 peer = list_entry(ptmp, kib_peer_t, ibp_list); 493 peer = list_entry(ptmp, struct kib_peer, ibp_list);
498 LASSERT(!kiblnd_peer_idle(peer)); 494 LASSERT(!kiblnd_peer_idle(peer));
499 495
500 if (peer->ibp_ni != ni) 496 if (peer->ibp_ni != ni)
@@ -522,11 +518,11 @@ static int kiblnd_del_peer(lnet_ni_t *ni, lnet_nid_t nid)
522 return rc; 518 return rc;
523} 519}
524 520
525static kib_conn_t *kiblnd_get_conn_by_idx(lnet_ni_t *ni, int index) 521static struct kib_conn *kiblnd_get_conn_by_idx(lnet_ni_t *ni, int index)
526{ 522{
527 kib_peer_t *peer; 523 struct kib_peer *peer;
528 struct list_head *ptmp; 524 struct list_head *ptmp;
529 kib_conn_t *conn; 525 struct kib_conn *conn;
530 struct list_head *ctmp; 526 struct list_head *ctmp;
531 int i; 527 int i;
532 unsigned long flags; 528 unsigned long flags;
@@ -535,7 +531,7 @@ static kib_conn_t *kiblnd_get_conn_by_idx(lnet_ni_t *ni, int index)
535 531
536 for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) { 532 for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
537 list_for_each(ptmp, &kiblnd_data.kib_peers[i]) { 533 list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
538 peer = list_entry(ptmp, kib_peer_t, ibp_list); 534 peer = list_entry(ptmp, struct kib_peer, ibp_list);
539 LASSERT(!kiblnd_peer_idle(peer)); 535 LASSERT(!kiblnd_peer_idle(peer));
540 536
541 if (peer->ibp_ni != ni) 537 if (peer->ibp_ni != ni)
@@ -545,7 +541,7 @@ static kib_conn_t *kiblnd_get_conn_by_idx(lnet_ni_t *ni, int index)
545 if (index-- > 0) 541 if (index-- > 0)
546 continue; 542 continue;
547 543
548 conn = list_entry(ctmp, kib_conn_t, 544 conn = list_entry(ctmp, struct kib_conn,
549 ibc_list); 545 ibc_list);
550 kiblnd_conn_addref(conn); 546 kiblnd_conn_addref(conn);
551 read_unlock_irqrestore( 547 read_unlock_irqrestore(
@@ -594,7 +590,7 @@ static void kiblnd_setup_mtu_locked(struct rdma_cm_id *cmid)
594 cmid->route.path_rec->mtu = mtu; 590 cmid->route.path_rec->mtu = mtu;
595} 591}
596 592
597static int kiblnd_get_completion_vector(kib_conn_t *conn, int cpt) 593static int kiblnd_get_completion_vector(struct kib_conn *conn, int cpt)
598{ 594{
599 cpumask_t *mask; 595 cpumask_t *mask;
600 int vectors; 596 int vectors;
@@ -621,7 +617,7 @@ static int kiblnd_get_completion_vector(kib_conn_t *conn, int cpt)
621 return 1; 617 return 1;
622} 618}
623 619
624kib_conn_t *kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid, 620struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cmid,
625 int state, int version) 621 int state, int version)
626{ 622{
627 /* 623 /*
@@ -634,12 +630,12 @@ kib_conn_t *kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid,
634 * its ref on 'cmid'). 630 * its ref on 'cmid').
635 */ 631 */
636 rwlock_t *glock = &kiblnd_data.kib_global_lock; 632 rwlock_t *glock = &kiblnd_data.kib_global_lock;
637 kib_net_t *net = peer->ibp_ni->ni_data; 633 struct kib_net *net = peer->ibp_ni->ni_data;
638 kib_dev_t *dev; 634 struct kib_dev *dev;
639 struct ib_qp_init_attr *init_qp_attr; 635 struct ib_qp_init_attr *init_qp_attr;
640 struct kib_sched_info *sched; 636 struct kib_sched_info *sched;
641 struct ib_cq_init_attr cq_attr = {}; 637 struct ib_cq_init_attr cq_attr = {};
642 kib_conn_t *conn; 638 struct kib_conn *conn;
643 struct ib_cq *cq; 639 struct ib_cq *cq;
644 unsigned long flags; 640 unsigned long flags;
645 int cpt; 641 int cpt;
@@ -723,7 +719,7 @@ kib_conn_t *kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid,
723 write_unlock_irqrestore(glock, flags); 719 write_unlock_irqrestore(glock, flags);
724 720
725 LIBCFS_CPT_ALLOC(conn->ibc_rxs, lnet_cpt_table(), cpt, 721 LIBCFS_CPT_ALLOC(conn->ibc_rxs, lnet_cpt_table(), cpt,
726 IBLND_RX_MSGS(conn) * sizeof(kib_rx_t)); 722 IBLND_RX_MSGS(conn) * sizeof(struct kib_rx));
727 if (!conn->ibc_rxs) { 723 if (!conn->ibc_rxs) {
728 CERROR("Cannot allocate RX buffers\n"); 724 CERROR("Cannot allocate RX buffers\n");
729 goto failed_2; 725 goto failed_2;
@@ -833,10 +829,10 @@ kib_conn_t *kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid,
833 return NULL; 829 return NULL;
834} 830}
835 831
836void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn) 832void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn)
837{ 833{
838 struct rdma_cm_id *cmid = conn->ibc_cmid; 834 struct rdma_cm_id *cmid = conn->ibc_cmid;
839 kib_peer_t *peer = conn->ibc_peer; 835 struct kib_peer *peer = conn->ibc_peer;
840 int rc; 836 int rc;
841 837
842 LASSERT(!in_interrupt()); 838 LASSERT(!in_interrupt());
@@ -879,7 +875,7 @@ void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn)
879 875
880 if (conn->ibc_rxs) { 876 if (conn->ibc_rxs) {
881 LIBCFS_FREE(conn->ibc_rxs, 877 LIBCFS_FREE(conn->ibc_rxs,
882 IBLND_RX_MSGS(conn) * sizeof(kib_rx_t)); 878 IBLND_RX_MSGS(conn) * sizeof(struct kib_rx));
883 } 879 }
884 880
885 if (conn->ibc_connvars) 881 if (conn->ibc_connvars)
@@ -890,7 +886,7 @@ void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn)
890 886
891 /* See CAVEAT EMPTOR above in kiblnd_create_conn */ 887 /* See CAVEAT EMPTOR above in kiblnd_create_conn */
892 if (conn->ibc_state != IBLND_CONN_INIT) { 888 if (conn->ibc_state != IBLND_CONN_INIT) {
893 kib_net_t *net = peer->ibp_ni->ni_data; 889 struct kib_net *net = peer->ibp_ni->ni_data;
894 890
895 kiblnd_peer_decref(peer); 891 kiblnd_peer_decref(peer);
896 rdma_destroy_id(cmid); 892 rdma_destroy_id(cmid);
@@ -900,15 +896,15 @@ void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn)
900 LIBCFS_FREE(conn, sizeof(*conn)); 896 LIBCFS_FREE(conn, sizeof(*conn));
901} 897}
902 898
903int kiblnd_close_peer_conns_locked(kib_peer_t *peer, int why) 899int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why)
904{ 900{
905 kib_conn_t *conn; 901 struct kib_conn *conn;
906 struct list_head *ctmp; 902 struct list_head *ctmp;
907 struct list_head *cnxt; 903 struct list_head *cnxt;
908 int count = 0; 904 int count = 0;
909 905
910 list_for_each_safe(ctmp, cnxt, &peer->ibp_conns) { 906 list_for_each_safe(ctmp, cnxt, &peer->ibp_conns) {
911 conn = list_entry(ctmp, kib_conn_t, ibc_list); 907 conn = list_entry(ctmp, struct kib_conn, ibc_list);
912 908
913 CDEBUG(D_NET, "Closing conn -> %s, version: %x, reason: %d\n", 909 CDEBUG(D_NET, "Closing conn -> %s, version: %x, reason: %d\n",
914 libcfs_nid2str(peer->ibp_nid), 910 libcfs_nid2str(peer->ibp_nid),
@@ -921,16 +917,16 @@ int kiblnd_close_peer_conns_locked(kib_peer_t *peer, int why)
921 return count; 917 return count;
922} 918}
923 919
924int kiblnd_close_stale_conns_locked(kib_peer_t *peer, 920int kiblnd_close_stale_conns_locked(struct kib_peer *peer,
925 int version, __u64 incarnation) 921 int version, __u64 incarnation)
926{ 922{
927 kib_conn_t *conn; 923 struct kib_conn *conn;
928 struct list_head *ctmp; 924 struct list_head *ctmp;
929 struct list_head *cnxt; 925 struct list_head *cnxt;
930 int count = 0; 926 int count = 0;
931 927
932 list_for_each_safe(ctmp, cnxt, &peer->ibp_conns) { 928 list_for_each_safe(ctmp, cnxt, &peer->ibp_conns) {
933 conn = list_entry(ctmp, kib_conn_t, ibc_list); 929 conn = list_entry(ctmp, struct kib_conn, ibc_list);
934 930
935 if (conn->ibc_version == version && 931 if (conn->ibc_version == version &&
936 conn->ibc_incarnation == incarnation) 932 conn->ibc_incarnation == incarnation)
@@ -951,7 +947,7 @@ int kiblnd_close_stale_conns_locked(kib_peer_t *peer,
951 947
952static int kiblnd_close_matching_conns(lnet_ni_t *ni, lnet_nid_t nid) 948static int kiblnd_close_matching_conns(lnet_ni_t *ni, lnet_nid_t nid)
953{ 949{
954 kib_peer_t *peer; 950 struct kib_peer *peer;
955 struct list_head *ptmp; 951 struct list_head *ptmp;
956 struct list_head *pnxt; 952 struct list_head *pnxt;
957 int lo; 953 int lo;
@@ -972,7 +968,7 @@ static int kiblnd_close_matching_conns(lnet_ni_t *ni, lnet_nid_t nid)
972 968
973 for (i = lo; i <= hi; i++) { 969 for (i = lo; i <= hi; i++) {
974 list_for_each_safe(ptmp, pnxt, &kiblnd_data.kib_peers[i]) { 970 list_for_each_safe(ptmp, pnxt, &kiblnd_data.kib_peers[i]) {
975 peer = list_entry(ptmp, kib_peer_t, ibp_list); 971 peer = list_entry(ptmp, struct kib_peer, ibp_list);
976 LASSERT(!kiblnd_peer_idle(peer)); 972 LASSERT(!kiblnd_peer_idle(peer));
977 973
978 if (peer->ibp_ni != ni) 974 if (peer->ibp_ni != ni)
@@ -1016,7 +1012,7 @@ static int kiblnd_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
1016 break; 1012 break;
1017 } 1013 }
1018 case IOC_LIBCFS_GET_CONN: { 1014 case IOC_LIBCFS_GET_CONN: {
1019 kib_conn_t *conn; 1015 struct kib_conn *conn;
1020 1016
1021 rc = 0; 1017 rc = 0;
1022 conn = kiblnd_get_conn_by_idx(ni, data->ioc_count); 1018 conn = kiblnd_get_conn_by_idx(ni, data->ioc_count);
@@ -1052,7 +1048,7 @@ static void kiblnd_query(lnet_ni_t *ni, lnet_nid_t nid, unsigned long *when)
1052 unsigned long last_alive = 0; 1048 unsigned long last_alive = 0;
1053 unsigned long now = cfs_time_current(); 1049 unsigned long now = cfs_time_current();
1054 rwlock_t *glock = &kiblnd_data.kib_global_lock; 1050 rwlock_t *glock = &kiblnd_data.kib_global_lock;
1055 kib_peer_t *peer; 1051 struct kib_peer *peer;
1056 unsigned long flags; 1052 unsigned long flags;
1057 1053
1058 read_lock_irqsave(glock, flags); 1054 read_lock_irqsave(glock, flags);
@@ -1078,7 +1074,7 @@ static void kiblnd_query(lnet_ni_t *ni, lnet_nid_t nid, unsigned long *when)
1078 last_alive ? cfs_duration_sec(now - last_alive) : -1); 1074 last_alive ? cfs_duration_sec(now - last_alive) : -1);
1079} 1075}
1080 1076
1081static void kiblnd_free_pages(kib_pages_t *p) 1077static void kiblnd_free_pages(struct kib_pages *p)
1082{ 1078{
1083 int npages = p->ibp_npages; 1079 int npages = p->ibp_npages;
1084 int i; 1080 int i;
@@ -1088,22 +1084,22 @@ static void kiblnd_free_pages(kib_pages_t *p)
1088 __free_page(p->ibp_pages[i]); 1084 __free_page(p->ibp_pages[i]);
1089 } 1085 }
1090 1086
1091 LIBCFS_FREE(p, offsetof(kib_pages_t, ibp_pages[npages])); 1087 LIBCFS_FREE(p, offsetof(struct kib_pages, ibp_pages[npages]));
1092} 1088}
1093 1089
1094int kiblnd_alloc_pages(kib_pages_t **pp, int cpt, int npages) 1090int kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages)
1095{ 1091{
1096 kib_pages_t *p; 1092 struct kib_pages *p;
1097 int i; 1093 int i;
1098 1094
1099 LIBCFS_CPT_ALLOC(p, lnet_cpt_table(), cpt, 1095 LIBCFS_CPT_ALLOC(p, lnet_cpt_table(), cpt,
1100 offsetof(kib_pages_t, ibp_pages[npages])); 1096 offsetof(struct kib_pages, ibp_pages[npages]));
1101 if (!p) { 1097 if (!p) {
1102 CERROR("Can't allocate descriptor for %d pages\n", npages); 1098 CERROR("Can't allocate descriptor for %d pages\n", npages);
1103 return -ENOMEM; 1099 return -ENOMEM;
1104 } 1100 }
1105 1101
1106 memset(p, 0, offsetof(kib_pages_t, ibp_pages[npages])); 1102 memset(p, 0, offsetof(struct kib_pages, ibp_pages[npages]));
1107 p->ibp_npages = npages; 1103 p->ibp_npages = npages;
1108 1104
1109 for (i = 0; i < npages; i++) { 1105 for (i = 0; i < npages; i++) {
@@ -1121,9 +1117,9 @@ int kiblnd_alloc_pages(kib_pages_t **pp, int cpt, int npages)
1121 return 0; 1117 return 0;
1122} 1118}
1123 1119
1124void kiblnd_unmap_rx_descs(kib_conn_t *conn) 1120void kiblnd_unmap_rx_descs(struct kib_conn *conn)
1125{ 1121{
1126 kib_rx_t *rx; 1122 struct kib_rx *rx;
1127 int i; 1123 int i;
1128 1124
1129 LASSERT(conn->ibc_rxs); 1125 LASSERT(conn->ibc_rxs);
@@ -1145,9 +1141,9 @@ void kiblnd_unmap_rx_descs(kib_conn_t *conn)
1145 conn->ibc_rx_pages = NULL; 1141 conn->ibc_rx_pages = NULL;
1146} 1142}
1147 1143
1148void kiblnd_map_rx_descs(kib_conn_t *conn) 1144void kiblnd_map_rx_descs(struct kib_conn *conn)
1149{ 1145{
1150 kib_rx_t *rx; 1146 struct kib_rx *rx;
1151 struct page *pg; 1147 struct page *pg;
1152 int pg_off; 1148 int pg_off;
1153 int ipg; 1149 int ipg;
@@ -1158,7 +1154,7 @@ void kiblnd_map_rx_descs(kib_conn_t *conn)
1158 rx = &conn->ibc_rxs[i]; 1154 rx = &conn->ibc_rxs[i];
1159 1155
1160 rx->rx_conn = conn; 1156 rx->rx_conn = conn;
1161 rx->rx_msg = (kib_msg_t *)(((char *)page_address(pg)) + pg_off); 1157 rx->rx_msg = (struct kib_msg *)(((char *)page_address(pg)) + pg_off);
1162 1158
1163 rx->rx_msgaddr = kiblnd_dma_map_single(conn->ibc_hdev->ibh_ibdev, 1159 rx->rx_msgaddr = kiblnd_dma_map_single(conn->ibc_hdev->ibh_ibdev,
1164 rx->rx_msg, 1160 rx->rx_msg,
@@ -1183,10 +1179,10 @@ void kiblnd_map_rx_descs(kib_conn_t *conn)
1183 } 1179 }
1184} 1180}
1185 1181
1186static void kiblnd_unmap_tx_pool(kib_tx_pool_t *tpo) 1182static void kiblnd_unmap_tx_pool(struct kib_tx_pool *tpo)
1187{ 1183{
1188 kib_hca_dev_t *hdev = tpo->tpo_hdev; 1184 struct kib_hca_dev *hdev = tpo->tpo_hdev;
1189 kib_tx_t *tx; 1185 struct kib_tx *tx;
1190 int i; 1186 int i;
1191 1187
1192 LASSERT(!tpo->tpo_pool.po_allocated); 1188 LASSERT(!tpo->tpo_pool.po_allocated);
@@ -1206,9 +1202,9 @@ static void kiblnd_unmap_tx_pool(kib_tx_pool_t *tpo)
1206 tpo->tpo_hdev = NULL; 1202 tpo->tpo_hdev = NULL;
1207} 1203}
1208 1204
1209static kib_hca_dev_t *kiblnd_current_hdev(kib_dev_t *dev) 1205static struct kib_hca_dev *kiblnd_current_hdev(struct kib_dev *dev)
1210{ 1206{
1211 kib_hca_dev_t *hdev; 1207 struct kib_hca_dev *hdev;
1212 unsigned long flags; 1208 unsigned long flags;
1213 int i = 0; 1209 int i = 0;
1214 1210
@@ -1232,14 +1228,14 @@ static kib_hca_dev_t *kiblnd_current_hdev(kib_dev_t *dev)
1232 return hdev; 1228 return hdev;
1233} 1229}
1234 1230
1235static void kiblnd_map_tx_pool(kib_tx_pool_t *tpo) 1231static void kiblnd_map_tx_pool(struct kib_tx_pool *tpo)
1236{ 1232{
1237 kib_pages_t *txpgs = tpo->tpo_tx_pages; 1233 struct kib_pages *txpgs = tpo->tpo_tx_pages;
1238 kib_pool_t *pool = &tpo->tpo_pool; 1234 struct kib_pool *pool = &tpo->tpo_pool;
1239 kib_net_t *net = pool->po_owner->ps_net; 1235 struct kib_net *net = pool->po_owner->ps_net;
1240 kib_dev_t *dev; 1236 struct kib_dev *dev;
1241 struct page *page; 1237 struct page *page;
1242 kib_tx_t *tx; 1238 struct kib_tx *tx;
1243 int page_offset; 1239 int page_offset;
1244 int ipage; 1240 int ipage;
1245 int i; 1241 int i;
@@ -1260,7 +1256,7 @@ static void kiblnd_map_tx_pool(kib_tx_pool_t *tpo)
1260 page = txpgs->ibp_pages[ipage]; 1256 page = txpgs->ibp_pages[ipage];
1261 tx = &tpo->tpo_tx_descs[i]; 1257 tx = &tpo->tpo_tx_descs[i];
1262 1258
1263 tx->tx_msg = (kib_msg_t *)(((char *)page_address(page)) + 1259 tx->tx_msg = (struct kib_msg *)(((char *)page_address(page)) +
1264 page_offset); 1260 page_offset);
1265 1261
1266 tx->tx_msgaddr = kiblnd_dma_map_single( 1262 tx->tx_msgaddr = kiblnd_dma_map_single(
@@ -1283,11 +1279,11 @@ static void kiblnd_map_tx_pool(kib_tx_pool_t *tpo)
1283 } 1279 }
1284} 1280}
1285 1281
1286struct ib_mr *kiblnd_find_rd_dma_mr(struct lnet_ni *ni, kib_rdma_desc_t *rd, 1282struct ib_mr *kiblnd_find_rd_dma_mr(struct lnet_ni *ni, struct kib_rdma_desc *rd,
1287 int negotiated_nfrags) 1283 int negotiated_nfrags)
1288{ 1284{
1289 kib_net_t *net = ni->ni_data; 1285 struct kib_net *net = ni->ni_data;
1290 kib_hca_dev_t *hdev = net->ibn_dev->ibd_hdev; 1286 struct kib_hca_dev *hdev = net->ibn_dev->ibd_hdev;
1291 struct lnet_ioctl_config_o2iblnd_tunables *tunables; 1287 struct lnet_ioctl_config_o2iblnd_tunables *tunables;
1292 __u16 nfrags; 1288 __u16 nfrags;
1293 int mod; 1289 int mod;
@@ -1304,7 +1300,7 @@ struct ib_mr *kiblnd_find_rd_dma_mr(struct lnet_ni *ni, kib_rdma_desc_t *rd,
1304 return hdev->ibh_mrs; 1300 return hdev->ibh_mrs;
1305} 1301}
1306 1302
1307static void kiblnd_destroy_fmr_pool(kib_fmr_pool_t *fpo) 1303static void kiblnd_destroy_fmr_pool(struct kib_fmr_pool *fpo)
1308{ 1304{
1309 LASSERT(!fpo->fpo_map_count); 1305 LASSERT(!fpo->fpo_map_count);
1310 1306
@@ -1335,7 +1331,7 @@ static void kiblnd_destroy_fmr_pool(kib_fmr_pool_t *fpo)
1335 1331
1336static void kiblnd_destroy_fmr_pool_list(struct list_head *head) 1332static void kiblnd_destroy_fmr_pool_list(struct list_head *head)
1337{ 1333{
1338 kib_fmr_pool_t *fpo, *tmp; 1334 struct kib_fmr_pool *fpo, *tmp;
1339 1335
1340 list_for_each_entry_safe(fpo, tmp, head, fpo_list) { 1336 list_for_each_entry_safe(fpo, tmp, head, fpo_list) {
1341 list_del(&fpo->fpo_list); 1337 list_del(&fpo->fpo_list);
@@ -1361,7 +1357,7 @@ kiblnd_fmr_flush_trigger(struct lnet_ioctl_config_o2iblnd_tunables *tunables,
1361 return max(IBLND_FMR_POOL_FLUSH, size); 1357 return max(IBLND_FMR_POOL_FLUSH, size);
1362} 1358}
1363 1359
1364static int kiblnd_alloc_fmr_pool(kib_fmr_poolset_t *fps, kib_fmr_pool_t *fpo) 1360static int kiblnd_alloc_fmr_pool(struct kib_fmr_poolset *fps, struct kib_fmr_pool *fpo)
1365{ 1361{
1366 struct ib_fmr_pool_param param = { 1362 struct ib_fmr_pool_param param = {
1367 .max_pages_per_fmr = LNET_MAX_PAYLOAD / PAGE_SIZE, 1363 .max_pages_per_fmr = LNET_MAX_PAYLOAD / PAGE_SIZE,
@@ -1388,7 +1384,7 @@ static int kiblnd_alloc_fmr_pool(kib_fmr_poolset_t *fps, kib_fmr_pool_t *fpo)
1388 return rc; 1384 return rc;
1389} 1385}
1390 1386
1391static int kiblnd_alloc_freg_pool(kib_fmr_poolset_t *fps, kib_fmr_pool_t *fpo) 1387static int kiblnd_alloc_freg_pool(struct kib_fmr_poolset *fps, struct kib_fmr_pool *fpo)
1392{ 1388{
1393 struct kib_fast_reg_descriptor *frd, *tmp; 1389 struct kib_fast_reg_descriptor *frd, *tmp;
1394 int i, rc; 1390 int i, rc;
@@ -1438,12 +1434,12 @@ out:
1438 return rc; 1434 return rc;
1439} 1435}
1440 1436
1441static int kiblnd_create_fmr_pool(kib_fmr_poolset_t *fps, 1437static int kiblnd_create_fmr_pool(struct kib_fmr_poolset *fps,
1442 kib_fmr_pool_t **pp_fpo) 1438 struct kib_fmr_pool **pp_fpo)
1443{ 1439{
1444 kib_dev_t *dev = fps->fps_net->ibn_dev; 1440 struct kib_dev *dev = fps->fps_net->ibn_dev;
1445 struct ib_device_attr *dev_attr; 1441 struct ib_device_attr *dev_attr;
1446 kib_fmr_pool_t *fpo; 1442 struct kib_fmr_pool *fpo;
1447 int rc; 1443 int rc;
1448 1444
1449 LIBCFS_CPT_ALLOC(fpo, lnet_cpt_table(), fps->fps_cpt, sizeof(*fpo)); 1445 LIBCFS_CPT_ALLOC(fpo, lnet_cpt_table(), fps->fps_cpt, sizeof(*fpo));
@@ -1488,7 +1484,7 @@ out_fpo:
1488 return rc; 1484 return rc;
1489} 1485}
1490 1486
1491static void kiblnd_fail_fmr_poolset(kib_fmr_poolset_t *fps, 1487static void kiblnd_fail_fmr_poolset(struct kib_fmr_poolset *fps,
1492 struct list_head *zombies) 1488 struct list_head *zombies)
1493{ 1489{
1494 if (!fps->fps_net) /* intialized? */ 1490 if (!fps->fps_net) /* intialized? */
@@ -1497,8 +1493,8 @@ static void kiblnd_fail_fmr_poolset(kib_fmr_poolset_t *fps,
1497 spin_lock(&fps->fps_lock); 1493 spin_lock(&fps->fps_lock);
1498 1494
1499 while (!list_empty(&fps->fps_pool_list)) { 1495 while (!list_empty(&fps->fps_pool_list)) {
1500 kib_fmr_pool_t *fpo = list_entry(fps->fps_pool_list.next, 1496 struct kib_fmr_pool *fpo = list_entry(fps->fps_pool_list.next,
1501 kib_fmr_pool_t, fpo_list); 1497 struct kib_fmr_pool, fpo_list);
1502 fpo->fpo_failed = 1; 1498 fpo->fpo_failed = 1;
1503 list_del(&fpo->fpo_list); 1499 list_del(&fpo->fpo_list);
1504 if (!fpo->fpo_map_count) 1500 if (!fpo->fpo_map_count)
@@ -1510,7 +1506,7 @@ static void kiblnd_fail_fmr_poolset(kib_fmr_poolset_t *fps,
1510 spin_unlock(&fps->fps_lock); 1506 spin_unlock(&fps->fps_lock);
1511} 1507}
1512 1508
1513static void kiblnd_fini_fmr_poolset(kib_fmr_poolset_t *fps) 1509static void kiblnd_fini_fmr_poolset(struct kib_fmr_poolset *fps)
1514{ 1510{
1515 if (fps->fps_net) { /* initialized? */ 1511 if (fps->fps_net) { /* initialized? */
1516 kiblnd_destroy_fmr_pool_list(&fps->fps_failed_pool_list); 1512 kiblnd_destroy_fmr_pool_list(&fps->fps_failed_pool_list);
@@ -1519,11 +1515,11 @@ static void kiblnd_fini_fmr_poolset(kib_fmr_poolset_t *fps)
1519} 1515}
1520 1516
1521static int 1517static int
1522kiblnd_init_fmr_poolset(kib_fmr_poolset_t *fps, int cpt, int ncpts, 1518kiblnd_init_fmr_poolset(struct kib_fmr_poolset *fps, int cpt, int ncpts,
1523 kib_net_t *net, 1519 struct kib_net *net,
1524 struct lnet_ioctl_config_o2iblnd_tunables *tunables) 1520 struct lnet_ioctl_config_o2iblnd_tunables *tunables)
1525{ 1521{
1526 kib_fmr_pool_t *fpo; 1522 struct kib_fmr_pool *fpo;
1527 int rc; 1523 int rc;
1528 1524
1529 memset(fps, 0, sizeof(*fps)); 1525 memset(fps, 0, sizeof(*fps));
@@ -1546,7 +1542,7 @@ kiblnd_init_fmr_poolset(kib_fmr_poolset_t *fps, int cpt, int ncpts,
1546 return rc; 1542 return rc;
1547} 1543}
1548 1544
1549static int kiblnd_fmr_pool_is_idle(kib_fmr_pool_t *fpo, unsigned long now) 1545static int kiblnd_fmr_pool_is_idle(struct kib_fmr_pool *fpo, unsigned long now)
1550{ 1546{
1551 if (fpo->fpo_map_count) /* still in use */ 1547 if (fpo->fpo_map_count) /* still in use */
1552 return 0; 1548 return 0;
@@ -1556,10 +1552,10 @@ static int kiblnd_fmr_pool_is_idle(kib_fmr_pool_t *fpo, unsigned long now)
1556} 1552}
1557 1553
1558static int 1554static int
1559kiblnd_map_tx_pages(kib_tx_t *tx, kib_rdma_desc_t *rd) 1555kiblnd_map_tx_pages(struct kib_tx *tx, struct kib_rdma_desc *rd)
1560{ 1556{
1561 __u64 *pages = tx->tx_pages; 1557 __u64 *pages = tx->tx_pages;
1562 kib_hca_dev_t *hdev; 1558 struct kib_hca_dev *hdev;
1563 int npages; 1559 int npages;
1564 int size; 1560 int size;
1565 int i; 1561 int i;
@@ -1577,13 +1573,13 @@ kiblnd_map_tx_pages(kib_tx_t *tx, kib_rdma_desc_t *rd)
1577 return npages; 1573 return npages;
1578} 1574}
1579 1575
1580void kiblnd_fmr_pool_unmap(kib_fmr_t *fmr, int status) 1576void kiblnd_fmr_pool_unmap(struct kib_fmr *fmr, int status)
1581{ 1577{
1582 LIST_HEAD(zombies); 1578 LIST_HEAD(zombies);
1583 kib_fmr_pool_t *fpo = fmr->fmr_pool; 1579 struct kib_fmr_pool *fpo = fmr->fmr_pool;
1584 kib_fmr_poolset_t *fps; 1580 struct kib_fmr_poolset *fps;
1585 unsigned long now = cfs_time_current(); 1581 unsigned long now = cfs_time_current();
1586 kib_fmr_pool_t *tmp; 1582 struct kib_fmr_pool *tmp;
1587 int rc; 1583 int rc;
1588 1584
1589 if (!fpo) 1585 if (!fpo)
@@ -1633,14 +1629,14 @@ void kiblnd_fmr_pool_unmap(kib_fmr_t *fmr, int status)
1633 kiblnd_destroy_fmr_pool_list(&zombies); 1629 kiblnd_destroy_fmr_pool_list(&zombies);
1634} 1630}
1635 1631
1636int kiblnd_fmr_pool_map(kib_fmr_poolset_t *fps, kib_tx_t *tx, 1632int kiblnd_fmr_pool_map(struct kib_fmr_poolset *fps, struct kib_tx *tx,
1637 kib_rdma_desc_t *rd, __u32 nob, __u64 iov, 1633 struct kib_rdma_desc *rd, __u32 nob, __u64 iov,
1638 kib_fmr_t *fmr) 1634 struct kib_fmr *fmr)
1639{ 1635{
1640 __u64 *pages = tx->tx_pages; 1636 __u64 *pages = tx->tx_pages;
1641 bool is_rx = (rd != tx->tx_rd); 1637 bool is_rx = (rd != tx->tx_rd);
1642 bool tx_pages_mapped = 0; 1638 bool tx_pages_mapped = 0;
1643 kib_fmr_pool_t *fpo; 1639 struct kib_fmr_pool *fpo;
1644 int npages = 0; 1640 int npages = 0;
1645 __u64 version; 1641 __u64 version;
1646 int rc; 1642 int rc;
@@ -1780,7 +1776,7 @@ int kiblnd_fmr_pool_map(kib_fmr_poolset_t *fps, kib_tx_t *tx,
1780 goto again; 1776 goto again;
1781} 1777}
1782 1778
1783static void kiblnd_fini_pool(kib_pool_t *pool) 1779static void kiblnd_fini_pool(struct kib_pool *pool)
1784{ 1780{
1785 LASSERT(list_empty(&pool->po_free_list)); 1781 LASSERT(list_empty(&pool->po_free_list));
1786 LASSERT(!pool->po_allocated); 1782 LASSERT(!pool->po_allocated);
@@ -1788,7 +1784,7 @@ static void kiblnd_fini_pool(kib_pool_t *pool)
1788 CDEBUG(D_NET, "Finalize %s pool\n", pool->po_owner->ps_name); 1784 CDEBUG(D_NET, "Finalize %s pool\n", pool->po_owner->ps_name);
1789} 1785}
1790 1786
1791static void kiblnd_init_pool(kib_poolset_t *ps, kib_pool_t *pool, int size) 1787static void kiblnd_init_pool(struct kib_poolset *ps, struct kib_pool *pool, int size)
1792{ 1788{
1793 CDEBUG(D_NET, "Initialize %s pool\n", ps->ps_name); 1789 CDEBUG(D_NET, "Initialize %s pool\n", ps->ps_name);
1794 1790
@@ -1801,10 +1797,10 @@ static void kiblnd_init_pool(kib_poolset_t *ps, kib_pool_t *pool, int size)
1801 1797
1802static void kiblnd_destroy_pool_list(struct list_head *head) 1798static void kiblnd_destroy_pool_list(struct list_head *head)
1803{ 1799{
1804 kib_pool_t *pool; 1800 struct kib_pool *pool;
1805 1801
1806 while (!list_empty(head)) { 1802 while (!list_empty(head)) {
1807 pool = list_entry(head->next, kib_pool_t, po_list); 1803 pool = list_entry(head->next, struct kib_pool, po_list);
1808 list_del(&pool->po_list); 1804 list_del(&pool->po_list);
1809 1805
1810 LASSERT(pool->po_owner); 1806 LASSERT(pool->po_owner);
@@ -1812,15 +1808,15 @@ static void kiblnd_destroy_pool_list(struct list_head *head)
1812 } 1808 }
1813} 1809}
1814 1810
1815static void kiblnd_fail_poolset(kib_poolset_t *ps, struct list_head *zombies) 1811static void kiblnd_fail_poolset(struct kib_poolset *ps, struct list_head *zombies)
1816{ 1812{
1817 if (!ps->ps_net) /* intialized? */ 1813 if (!ps->ps_net) /* intialized? */
1818 return; 1814 return;
1819 1815
1820 spin_lock(&ps->ps_lock); 1816 spin_lock(&ps->ps_lock);
1821 while (!list_empty(&ps->ps_pool_list)) { 1817 while (!list_empty(&ps->ps_pool_list)) {
1822 kib_pool_t *po = list_entry(ps->ps_pool_list.next, 1818 struct kib_pool *po = list_entry(ps->ps_pool_list.next,
1823 kib_pool_t, po_list); 1819 struct kib_pool, po_list);
1824 po->po_failed = 1; 1820 po->po_failed = 1;
1825 list_del(&po->po_list); 1821 list_del(&po->po_list);
1826 if (!po->po_allocated) 1822 if (!po->po_allocated)
@@ -1831,7 +1827,7 @@ static void kiblnd_fail_poolset(kib_poolset_t *ps, struct list_head *zombies)
1831 spin_unlock(&ps->ps_lock); 1827 spin_unlock(&ps->ps_lock);
1832} 1828}
1833 1829
1834static void kiblnd_fini_poolset(kib_poolset_t *ps) 1830static void kiblnd_fini_poolset(struct kib_poolset *ps)
1835{ 1831{
1836 if (ps->ps_net) { /* initialized? */ 1832 if (ps->ps_net) { /* initialized? */
1837 kiblnd_destroy_pool_list(&ps->ps_failed_pool_list); 1833 kiblnd_destroy_pool_list(&ps->ps_failed_pool_list);
@@ -1839,14 +1835,14 @@ static void kiblnd_fini_poolset(kib_poolset_t *ps)
1839 } 1835 }
1840} 1836}
1841 1837
1842static int kiblnd_init_poolset(kib_poolset_t *ps, int cpt, 1838static int kiblnd_init_poolset(struct kib_poolset *ps, int cpt,
1843 kib_net_t *net, char *name, int size, 1839 struct kib_net *net, char *name, int size,
1844 kib_ps_pool_create_t po_create, 1840 kib_ps_pool_create_t po_create,
1845 kib_ps_pool_destroy_t po_destroy, 1841 kib_ps_pool_destroy_t po_destroy,
1846 kib_ps_node_init_t nd_init, 1842 kib_ps_node_init_t nd_init,
1847 kib_ps_node_fini_t nd_fini) 1843 kib_ps_node_fini_t nd_fini)
1848{ 1844{
1849 kib_pool_t *pool; 1845 struct kib_pool *pool;
1850 int rc; 1846 int rc;
1851 1847
1852 memset(ps, 0, sizeof(*ps)); 1848 memset(ps, 0, sizeof(*ps));
@@ -1874,7 +1870,7 @@ static int kiblnd_init_poolset(kib_poolset_t *ps, int cpt,
1874 return rc; 1870 return rc;
1875} 1871}
1876 1872
1877static int kiblnd_pool_is_idle(kib_pool_t *pool, unsigned long now) 1873static int kiblnd_pool_is_idle(struct kib_pool *pool, unsigned long now)
1878{ 1874{
1879 if (pool->po_allocated) /* still in use */ 1875 if (pool->po_allocated) /* still in use */
1880 return 0; 1876 return 0;
@@ -1883,11 +1879,11 @@ static int kiblnd_pool_is_idle(kib_pool_t *pool, unsigned long now)
1883 return cfs_time_aftereq(now, pool->po_deadline); 1879 return cfs_time_aftereq(now, pool->po_deadline);
1884} 1880}
1885 1881
1886void kiblnd_pool_free_node(kib_pool_t *pool, struct list_head *node) 1882void kiblnd_pool_free_node(struct kib_pool *pool, struct list_head *node)
1887{ 1883{
1888 LIST_HEAD(zombies); 1884 LIST_HEAD(zombies);
1889 kib_poolset_t *ps = pool->po_owner; 1885 struct kib_poolset *ps = pool->po_owner;
1890 kib_pool_t *tmp; 1886 struct kib_pool *tmp;
1891 unsigned long now = cfs_time_current(); 1887 unsigned long now = cfs_time_current();
1892 1888
1893 spin_lock(&ps->ps_lock); 1889 spin_lock(&ps->ps_lock);
@@ -1913,10 +1909,10 @@ void kiblnd_pool_free_node(kib_pool_t *pool, struct list_head *node)
1913 kiblnd_destroy_pool_list(&zombies); 1909 kiblnd_destroy_pool_list(&zombies);
1914} 1910}
1915 1911
1916struct list_head *kiblnd_pool_alloc_node(kib_poolset_t *ps) 1912struct list_head *kiblnd_pool_alloc_node(struct kib_poolset *ps)
1917{ 1913{
1918 struct list_head *node; 1914 struct list_head *node;
1919 kib_pool_t *pool; 1915 struct kib_pool *pool;
1920 unsigned int interval = 1; 1916 unsigned int interval = 1;
1921 unsigned long time_before; 1917 unsigned long time_before;
1922 unsigned int trips = 0; 1918 unsigned int trips = 0;
@@ -1986,9 +1982,9 @@ struct list_head *kiblnd_pool_alloc_node(kib_poolset_t *ps)
1986 goto again; 1982 goto again;
1987} 1983}
1988 1984
1989static void kiblnd_destroy_tx_pool(kib_pool_t *pool) 1985static void kiblnd_destroy_tx_pool(struct kib_pool *pool)
1990{ 1986{
1991 kib_tx_pool_t *tpo = container_of(pool, kib_tx_pool_t, tpo_pool); 1987 struct kib_tx_pool *tpo = container_of(pool, struct kib_tx_pool, tpo_pool);
1992 int i; 1988 int i;
1993 1989
1994 LASSERT(!pool->po_allocated); 1990 LASSERT(!pool->po_allocated);
@@ -2002,7 +1998,7 @@ static void kiblnd_destroy_tx_pool(kib_pool_t *pool)
2002 goto out; 1998 goto out;
2003 1999
2004 for (i = 0; i < pool->po_size; i++) { 2000 for (i = 0; i < pool->po_size; i++) {
2005 kib_tx_t *tx = &tpo->tpo_tx_descs[i]; 2001 struct kib_tx *tx = &tpo->tpo_tx_descs[i];
2006 2002
2007 list_del(&tx->tx_list); 2003 list_del(&tx->tx_list);
2008 if (tx->tx_pages) 2004 if (tx->tx_pages)
@@ -2011,8 +2007,8 @@ static void kiblnd_destroy_tx_pool(kib_pool_t *pool)
2011 sizeof(*tx->tx_pages)); 2007 sizeof(*tx->tx_pages));
2012 if (tx->tx_frags) 2008 if (tx->tx_frags)
2013 LIBCFS_FREE(tx->tx_frags, 2009 LIBCFS_FREE(tx->tx_frags,
2014 IBLND_MAX_RDMA_FRAGS * 2010 (1 + IBLND_MAX_RDMA_FRAGS) *
2015 sizeof(*tx->tx_frags)); 2011 sizeof(*tx->tx_frags));
2016 if (tx->tx_wrq) 2012 if (tx->tx_wrq)
2017 LIBCFS_FREE(tx->tx_wrq, 2013 LIBCFS_FREE(tx->tx_wrq,
2018 (1 + IBLND_MAX_RDMA_FRAGS) * 2014 (1 + IBLND_MAX_RDMA_FRAGS) *
@@ -2023,12 +2019,12 @@ static void kiblnd_destroy_tx_pool(kib_pool_t *pool)
2023 sizeof(*tx->tx_sge)); 2019 sizeof(*tx->tx_sge));
2024 if (tx->tx_rd) 2020 if (tx->tx_rd)
2025 LIBCFS_FREE(tx->tx_rd, 2021 LIBCFS_FREE(tx->tx_rd,
2026 offsetof(kib_rdma_desc_t, 2022 offsetof(struct kib_rdma_desc,
2027 rd_frags[IBLND_MAX_RDMA_FRAGS])); 2023 rd_frags[IBLND_MAX_RDMA_FRAGS]));
2028 } 2024 }
2029 2025
2030 LIBCFS_FREE(tpo->tpo_tx_descs, 2026 LIBCFS_FREE(tpo->tpo_tx_descs,
2031 pool->po_size * sizeof(kib_tx_t)); 2027 pool->po_size * sizeof(struct kib_tx));
2032out: 2028out:
2033 kiblnd_fini_pool(pool); 2029 kiblnd_fini_pool(pool);
2034 LIBCFS_FREE(tpo, sizeof(*tpo)); 2030 LIBCFS_FREE(tpo, sizeof(*tpo));
@@ -2041,13 +2037,13 @@ static int kiblnd_tx_pool_size(int ncpts)
2041 return max(IBLND_TX_POOL, ntx); 2037 return max(IBLND_TX_POOL, ntx);
2042} 2038}
2043 2039
2044static int kiblnd_create_tx_pool(kib_poolset_t *ps, int size, 2040static int kiblnd_create_tx_pool(struct kib_poolset *ps, int size,
2045 kib_pool_t **pp_po) 2041 struct kib_pool **pp_po)
2046{ 2042{
2047 int i; 2043 int i;
2048 int npg; 2044 int npg;
2049 kib_pool_t *pool; 2045 struct kib_pool *pool;
2050 kib_tx_pool_t *tpo; 2046 struct kib_tx_pool *tpo;
2051 2047
2052 LIBCFS_CPT_ALLOC(tpo, lnet_cpt_table(), ps->ps_cpt, sizeof(*tpo)); 2048 LIBCFS_CPT_ALLOC(tpo, lnet_cpt_table(), ps->ps_cpt, sizeof(*tpo));
2053 if (!tpo) { 2049 if (!tpo) {
@@ -2068,17 +2064,17 @@ static int kiblnd_create_tx_pool(kib_poolset_t *ps, int size,
2068 } 2064 }
2069 2065
2070 LIBCFS_CPT_ALLOC(tpo->tpo_tx_descs, lnet_cpt_table(), ps->ps_cpt, 2066 LIBCFS_CPT_ALLOC(tpo->tpo_tx_descs, lnet_cpt_table(), ps->ps_cpt,
2071 size * sizeof(kib_tx_t)); 2067 size * sizeof(struct kib_tx));
2072 if (!tpo->tpo_tx_descs) { 2068 if (!tpo->tpo_tx_descs) {
2073 CERROR("Can't allocate %d tx descriptors\n", size); 2069 CERROR("Can't allocate %d tx descriptors\n", size);
2074 ps->ps_pool_destroy(pool); 2070 ps->ps_pool_destroy(pool);
2075 return -ENOMEM; 2071 return -ENOMEM;
2076 } 2072 }
2077 2073
2078 memset(tpo->tpo_tx_descs, 0, size * sizeof(kib_tx_t)); 2074 memset(tpo->tpo_tx_descs, 0, size * sizeof(struct kib_tx));
2079 2075
2080 for (i = 0; i < size; i++) { 2076 for (i = 0; i < size; i++) {
2081 kib_tx_t *tx = &tpo->tpo_tx_descs[i]; 2077 struct kib_tx *tx = &tpo->tpo_tx_descs[i];
2082 2078
2083 tx->tx_pool = tpo; 2079 tx->tx_pool = tpo;
2084 if (ps->ps_net->ibn_fmr_ps) { 2080 if (ps->ps_net->ibn_fmr_ps) {
@@ -2090,11 +2086,12 @@ static int kiblnd_create_tx_pool(kib_poolset_t *ps, int size,
2090 } 2086 }
2091 2087
2092 LIBCFS_CPT_ALLOC(tx->tx_frags, lnet_cpt_table(), ps->ps_cpt, 2088 LIBCFS_CPT_ALLOC(tx->tx_frags, lnet_cpt_table(), ps->ps_cpt,
2093 IBLND_MAX_RDMA_FRAGS * sizeof(*tx->tx_frags)); 2089 (1 + IBLND_MAX_RDMA_FRAGS) *
2090 sizeof(*tx->tx_frags));
2094 if (!tx->tx_frags) 2091 if (!tx->tx_frags)
2095 break; 2092 break;
2096 2093
2097 sg_init_table(tx->tx_frags, IBLND_MAX_RDMA_FRAGS); 2094 sg_init_table(tx->tx_frags, IBLND_MAX_RDMA_FRAGS + 1);
2098 2095
2099 LIBCFS_CPT_ALLOC(tx->tx_wrq, lnet_cpt_table(), ps->ps_cpt, 2096 LIBCFS_CPT_ALLOC(tx->tx_wrq, lnet_cpt_table(), ps->ps_cpt,
2100 (1 + IBLND_MAX_RDMA_FRAGS) * 2097 (1 + IBLND_MAX_RDMA_FRAGS) *
@@ -2109,7 +2106,7 @@ static int kiblnd_create_tx_pool(kib_poolset_t *ps, int size,
2109 break; 2106 break;
2110 2107
2111 LIBCFS_CPT_ALLOC(tx->tx_rd, lnet_cpt_table(), ps->ps_cpt, 2108 LIBCFS_CPT_ALLOC(tx->tx_rd, lnet_cpt_table(), ps->ps_cpt,
2112 offsetof(kib_rdma_desc_t, 2109 offsetof(struct kib_rdma_desc,
2113 rd_frags[IBLND_MAX_RDMA_FRAGS])); 2110 rd_frags[IBLND_MAX_RDMA_FRAGS]));
2114 if (!tx->tx_rd) 2111 if (!tx->tx_rd)
2115 break; 2112 break;
@@ -2125,22 +2122,23 @@ static int kiblnd_create_tx_pool(kib_poolset_t *ps, int size,
2125 return -ENOMEM; 2122 return -ENOMEM;
2126} 2123}
2127 2124
2128static void kiblnd_tx_init(kib_pool_t *pool, struct list_head *node) 2125static void kiblnd_tx_init(struct kib_pool *pool, struct list_head *node)
2129{ 2126{
2130 kib_tx_poolset_t *tps = container_of(pool->po_owner, kib_tx_poolset_t, 2127 struct kib_tx_poolset *tps = container_of(pool->po_owner,
2131 tps_poolset); 2128 struct kib_tx_poolset,
2132 kib_tx_t *tx = list_entry(node, kib_tx_t, tx_list); 2129 tps_poolset);
2130 struct kib_tx *tx = list_entry(node, struct kib_tx, tx_list);
2133 2131
2134 tx->tx_cookie = tps->tps_next_tx_cookie++; 2132 tx->tx_cookie = tps->tps_next_tx_cookie++;
2135} 2133}
2136 2134
2137static void kiblnd_net_fini_pools(kib_net_t *net) 2135static void kiblnd_net_fini_pools(struct kib_net *net)
2138{ 2136{
2139 int i; 2137 int i;
2140 2138
2141 cfs_cpt_for_each(i, lnet_cpt_table()) { 2139 cfs_cpt_for_each(i, lnet_cpt_table()) {
2142 kib_tx_poolset_t *tps; 2140 struct kib_tx_poolset *tps;
2143 kib_fmr_poolset_t *fps; 2141 struct kib_fmr_poolset *fps;
2144 2142
2145 if (net->ibn_tx_ps) { 2143 if (net->ibn_tx_ps) {
2146 tps = net->ibn_tx_ps[i]; 2144 tps = net->ibn_tx_ps[i];
@@ -2164,7 +2162,7 @@ static void kiblnd_net_fini_pools(kib_net_t *net)
2164 } 2162 }
2165} 2163}
2166 2164
2167static int kiblnd_net_init_pools(kib_net_t *net, lnet_ni_t *ni, __u32 *cpts, 2165static int kiblnd_net_init_pools(struct kib_net *net, lnet_ni_t *ni, __u32 *cpts,
2168 int ncpts) 2166 int ncpts)
2169{ 2167{
2170 struct lnet_ioctl_config_o2iblnd_tunables *tunables; 2168 struct lnet_ioctl_config_o2iblnd_tunables *tunables;
@@ -2206,7 +2204,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, lnet_ni_t *ni, __u32 *cpts,
2206 * number of CPTs that exist, i.e net->ibn_fmr_ps[cpt]. 2204 * number of CPTs that exist, i.e net->ibn_fmr_ps[cpt].
2207 */ 2205 */
2208 net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(), 2206 net->ibn_fmr_ps = cfs_percpt_alloc(lnet_cpt_table(),
2209 sizeof(kib_fmr_poolset_t)); 2207 sizeof(struct kib_fmr_poolset));
2210 if (!net->ibn_fmr_ps) { 2208 if (!net->ibn_fmr_ps) {
2211 CERROR("Failed to allocate FMR pool array\n"); 2209 CERROR("Failed to allocate FMR pool array\n");
2212 rc = -ENOMEM; 2210 rc = -ENOMEM;
@@ -2234,7 +2232,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, lnet_ni_t *ni, __u32 *cpts,
2234 * number of CPTs that exist, i.e net->ibn_tx_ps[cpt]. 2232 * number of CPTs that exist, i.e net->ibn_tx_ps[cpt].
2235 */ 2233 */
2236 net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(), 2234 net->ibn_tx_ps = cfs_percpt_alloc(lnet_cpt_table(),
2237 sizeof(kib_tx_poolset_t)); 2235 sizeof(struct kib_tx_poolset));
2238 if (!net->ibn_tx_ps) { 2236 if (!net->ibn_tx_ps) {
2239 CERROR("Failed to allocate tx pool array\n"); 2237 CERROR("Failed to allocate tx pool array\n");
2240 rc = -ENOMEM; 2238 rc = -ENOMEM;
@@ -2263,7 +2261,7 @@ static int kiblnd_net_init_pools(kib_net_t *net, lnet_ni_t *ni, __u32 *cpts,
2263 return rc; 2261 return rc;
2264} 2262}
2265 2263
2266static int kiblnd_hdev_get_attr(kib_hca_dev_t *hdev) 2264static int kiblnd_hdev_get_attr(struct kib_hca_dev *hdev)
2267{ 2265{
2268 /* 2266 /*
2269 * It's safe to assume a HCA can handle a page size 2267 * It's safe to assume a HCA can handle a page size
@@ -2283,7 +2281,7 @@ static int kiblnd_hdev_get_attr(kib_hca_dev_t *hdev)
2283 return -EINVAL; 2281 return -EINVAL;
2284} 2282}
2285 2283
2286static void kiblnd_hdev_cleanup_mrs(kib_hca_dev_t *hdev) 2284static void kiblnd_hdev_cleanup_mrs(struct kib_hca_dev *hdev)
2287{ 2285{
2288 if (!hdev->ibh_mrs) 2286 if (!hdev->ibh_mrs)
2289 return; 2287 return;
@@ -2293,7 +2291,7 @@ static void kiblnd_hdev_cleanup_mrs(kib_hca_dev_t *hdev)
2293 hdev->ibh_mrs = NULL; 2291 hdev->ibh_mrs = NULL;
2294} 2292}
2295 2293
2296void kiblnd_hdev_destroy(kib_hca_dev_t *hdev) 2294void kiblnd_hdev_destroy(struct kib_hca_dev *hdev)
2297{ 2295{
2298 kiblnd_hdev_cleanup_mrs(hdev); 2296 kiblnd_hdev_cleanup_mrs(hdev);
2299 2297
@@ -2306,7 +2304,7 @@ void kiblnd_hdev_destroy(kib_hca_dev_t *hdev)
2306 LIBCFS_FREE(hdev, sizeof(*hdev)); 2304 LIBCFS_FREE(hdev, sizeof(*hdev));
2307} 2305}
2308 2306
2309static int kiblnd_hdev_setup_mrs(kib_hca_dev_t *hdev) 2307static int kiblnd_hdev_setup_mrs(struct kib_hca_dev *hdev)
2310{ 2308{
2311 struct ib_mr *mr; 2309 struct ib_mr *mr;
2312 int rc; 2310 int rc;
@@ -2335,7 +2333,7 @@ static int kiblnd_dummy_callback(struct rdma_cm_id *cmid,
2335 return 0; 2333 return 0;
2336} 2334}
2337 2335
2338static int kiblnd_dev_need_failover(kib_dev_t *dev) 2336static int kiblnd_dev_need_failover(struct kib_dev *dev)
2339{ 2337{
2340 struct rdma_cm_id *cmid; 2338 struct rdma_cm_id *cmid;
2341 struct sockaddr_in srcaddr; 2339 struct sockaddr_in srcaddr;
@@ -2389,15 +2387,15 @@ static int kiblnd_dev_need_failover(kib_dev_t *dev)
2389 return rc; 2387 return rc;
2390} 2388}
2391 2389
2392int kiblnd_dev_failover(kib_dev_t *dev) 2390int kiblnd_dev_failover(struct kib_dev *dev)
2393{ 2391{
2394 LIST_HEAD(zombie_tpo); 2392 LIST_HEAD(zombie_tpo);
2395 LIST_HEAD(zombie_ppo); 2393 LIST_HEAD(zombie_ppo);
2396 LIST_HEAD(zombie_fpo); 2394 LIST_HEAD(zombie_fpo);
2397 struct rdma_cm_id *cmid = NULL; 2395 struct rdma_cm_id *cmid = NULL;
2398 kib_hca_dev_t *hdev = NULL; 2396 struct kib_hca_dev *hdev = NULL;
2399 struct ib_pd *pd; 2397 struct ib_pd *pd;
2400 kib_net_t *net; 2398 struct kib_net *net;
2401 struct sockaddr_in addr; 2399 struct sockaddr_in addr;
2402 unsigned long flags; 2400 unsigned long flags;
2403 int rc = 0; 2401 int rc = 0;
@@ -2522,7 +2520,7 @@ int kiblnd_dev_failover(kib_dev_t *dev)
2522 return rc; 2520 return rc;
2523} 2521}
2524 2522
2525void kiblnd_destroy_dev(kib_dev_t *dev) 2523void kiblnd_destroy_dev(struct kib_dev *dev)
2526{ 2524{
2527 LASSERT(!dev->ibd_nnets); 2525 LASSERT(!dev->ibd_nnets);
2528 LASSERT(list_empty(&dev->ibd_nets)); 2526 LASSERT(list_empty(&dev->ibd_nets));
@@ -2536,10 +2534,10 @@ void kiblnd_destroy_dev(kib_dev_t *dev)
2536 LIBCFS_FREE(dev, sizeof(*dev)); 2534 LIBCFS_FREE(dev, sizeof(*dev));
2537} 2535}
2538 2536
2539static kib_dev_t *kiblnd_create_dev(char *ifname) 2537static struct kib_dev *kiblnd_create_dev(char *ifname)
2540{ 2538{
2541 struct net_device *netdev; 2539 struct net_device *netdev;
2542 kib_dev_t *dev; 2540 struct kib_dev *dev;
2543 __u32 netmask; 2541 __u32 netmask;
2544 __u32 ip; 2542 __u32 ip;
2545 int up; 2543 int up;
@@ -2654,7 +2652,7 @@ static void kiblnd_base_shutdown(void)
2654 2652
2655static void kiblnd_shutdown(lnet_ni_t *ni) 2653static void kiblnd_shutdown(lnet_ni_t *ni)
2656{ 2654{
2657 kib_net_t *net = ni->ni_data; 2655 struct kib_net *net = ni->ni_data;
2658 rwlock_t *g_lock = &kiblnd_data.kib_global_lock; 2656 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
2659 int i; 2657 int i;
2660 unsigned long flags; 2658 unsigned long flags;
@@ -2851,7 +2849,7 @@ static int kiblnd_start_schedulers(struct kib_sched_info *sched)
2851 return rc; 2849 return rc;
2852} 2850}
2853 2851
2854static int kiblnd_dev_start_threads(kib_dev_t *dev, int newdev, __u32 *cpts, 2852static int kiblnd_dev_start_threads(struct kib_dev *dev, int newdev, __u32 *cpts,
2855 int ncpts) 2853 int ncpts)
2856{ 2854{
2857 int cpt; 2855 int cpt;
@@ -2877,10 +2875,10 @@ static int kiblnd_dev_start_threads(kib_dev_t *dev, int newdev, __u32 *cpts,
2877 return 0; 2875 return 0;
2878} 2876}
2879 2877
2880static kib_dev_t *kiblnd_dev_search(char *ifname) 2878static struct kib_dev *kiblnd_dev_search(char *ifname)
2881{ 2879{
2882 kib_dev_t *alias = NULL; 2880 struct kib_dev *alias = NULL;
2883 kib_dev_t *dev; 2881 struct kib_dev *dev;
2884 char *colon; 2882 char *colon;
2885 char *colon2; 2883 char *colon2;
2886 2884
@@ -2912,8 +2910,8 @@ static kib_dev_t *kiblnd_dev_search(char *ifname)
2912static int kiblnd_startup(lnet_ni_t *ni) 2910static int kiblnd_startup(lnet_ni_t *ni)
2913{ 2911{
2914 char *ifname; 2912 char *ifname;
2915 kib_dev_t *ibdev = NULL; 2913 struct kib_dev *ibdev = NULL;
2916 kib_net_t *net; 2914 struct kib_net *net;
2917 struct timespec64 tv; 2915 struct timespec64 tv;
2918 unsigned long flags; 2916 unsigned long flags;
2919 int rc; 2917 int rc;
@@ -3020,11 +3018,11 @@ static void __exit ko2iblnd_exit(void)
3020 3018
3021static int __init ko2iblnd_init(void) 3019static int __init ko2iblnd_init(void)
3022{ 3020{
3023 CLASSERT(sizeof(kib_msg_t) <= IBLND_MSG_SIZE); 3021 CLASSERT(sizeof(struct kib_msg) <= IBLND_MSG_SIZE);
3024 CLASSERT(offsetof(kib_msg_t, 3022 CLASSERT(offsetof(struct kib_msg,
3025 ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) 3023 ibm_u.get.ibgm_rd.rd_frags[IBLND_MAX_RDMA_FRAGS])
3026 <= IBLND_MSG_SIZE); 3024 <= IBLND_MSG_SIZE);
3027 CLASSERT(offsetof(kib_msg_t, 3025 CLASSERT(offsetof(struct kib_msg,
3028 ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS]) 3026 ibm_u.putack.ibpam_rd.rd_frags[IBLND_MAX_RDMA_FRAGS])
3029 <= IBLND_MSG_SIZE); 3027 <= IBLND_MSG_SIZE);
3030 3028
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
index b22984fd9ad3..078a0c3e8845 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -78,12 +74,12 @@
78#define IBLND_N_SCHED 2 74#define IBLND_N_SCHED 2
79#define IBLND_N_SCHED_HIGH 4 75#define IBLND_N_SCHED_HIGH 4
80 76
81typedef struct { 77struct kib_tunables {
82 int *kib_dev_failover; /* HCA failover */ 78 int *kib_dev_failover; /* HCA failover */
83 unsigned int *kib_service; /* IB service number */ 79 unsigned int *kib_service; /* IB service number */
84 int *kib_min_reconnect_interval; /* first failed connection retry... */ 80 int *kib_min_reconnect_interval; /* first failed connection retry... */
85 int *kib_max_reconnect_interval; /* exponentially increasing to this */ 81 int *kib_max_reconnect_interval; /* exponentially increasing to this */
86 int *kib_cksum; /* checksum kib_msg_t? */ 82 int *kib_cksum; /* checksum struct kib_msg? */
87 int *kib_timeout; /* comms timeout (seconds) */ 83 int *kib_timeout; /* comms timeout (seconds) */
88 int *kib_keepalive; /* keepalive timeout (seconds) */ 84 int *kib_keepalive; /* keepalive timeout (seconds) */
89 int *kib_ntx; /* # tx descs */ 85 int *kib_ntx; /* # tx descs */
@@ -94,22 +90,22 @@ typedef struct {
94 int *kib_require_priv_port; /* accept only privileged ports */ 90 int *kib_require_priv_port; /* accept only privileged ports */
95 int *kib_use_priv_port; /* use privileged port for active connect */ 91 int *kib_use_priv_port; /* use privileged port for active connect */
96 int *kib_nscheds; /* # threads on each CPT */ 92 int *kib_nscheds; /* # threads on each CPT */
97} kib_tunables_t; 93};
98 94
99extern kib_tunables_t kiblnd_tunables; 95extern struct kib_tunables kiblnd_tunables;
100 96
101#define IBLND_MSG_QUEUE_SIZE_V1 8 /* V1 only : # messages/RDMAs in-flight */ 97#define IBLND_MSG_QUEUE_SIZE_V1 8 /* V1 only : # messages/RDMAs in-flight */
102#define IBLND_CREDIT_HIGHWATER_V1 7 /* V1 only : when eagerly to return credits */ 98#define IBLND_CREDIT_HIGHWATER_V1 7 /* V1 only : when eagerly to return credits */
103 99
104#define IBLND_CREDITS_DEFAULT 8 /* default # of peer credits */ 100#define IBLND_CREDITS_DEFAULT 8 /* default # of peer credits */
105#define IBLND_CREDITS_MAX ((typeof(((kib_msg_t *) 0)->ibm_credits)) - 1) /* Max # of peer credits */ 101#define IBLND_CREDITS_MAX ((typeof(((struct kib_msg *)0)->ibm_credits)) - 1) /* Max # of peer credits */
106 102
107/* when eagerly to return credits */ 103/* when eagerly to return credits */
108#define IBLND_CREDITS_HIGHWATER(t, v) ((v) == IBLND_MSG_VERSION_1 ? \ 104#define IBLND_CREDITS_HIGHWATER(t, v) ((v) == IBLND_MSG_VERSION_1 ? \
109 IBLND_CREDIT_HIGHWATER_V1 : \ 105 IBLND_CREDIT_HIGHWATER_V1 : \
110 t->lnd_peercredits_hiw) 106 t->lnd_peercredits_hiw)
111 107
112#define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(&init_net, \ 108#define kiblnd_rdma_create_id(cb, dev, ps, qpt) rdma_create_id(current->nsproxy->net_ns, \
113 cb, dev, \ 109 cb, dev, \
114 ps, qpt) 110 ps, qpt)
115 111
@@ -150,7 +146,7 @@ struct kib_hca_dev;
150#define KIB_IFNAME_SIZE 256 146#define KIB_IFNAME_SIZE 256
151#endif 147#endif
152 148
153typedef struct { 149struct kib_dev {
154 struct list_head ibd_list; /* chain on kib_devs */ 150 struct list_head ibd_list; /* chain on kib_devs */
155 struct list_head ibd_fail_list; /* chain on kib_failed_devs */ 151 struct list_head ibd_fail_list; /* chain on kib_failed_devs */
156 __u32 ibd_ifip; /* IPoIB interface IP */ 152 __u32 ibd_ifip; /* IPoIB interface IP */
@@ -165,9 +161,9 @@ typedef struct {
165 unsigned int ibd_can_failover; /* IPoIB interface is a bonding master */ 161 unsigned int ibd_can_failover; /* IPoIB interface is a bonding master */
166 struct list_head ibd_nets; 162 struct list_head ibd_nets;
167 struct kib_hca_dev *ibd_hdev; 163 struct kib_hca_dev *ibd_hdev;
168} kib_dev_t; 164};
169 165
170typedef struct kib_hca_dev { 166struct kib_hca_dev {
171 struct rdma_cm_id *ibh_cmid; /* listener cmid */ 167 struct rdma_cm_id *ibh_cmid; /* listener cmid */
172 struct ib_device *ibh_ibdev; /* IB device */ 168 struct ib_device *ibh_ibdev; /* IB device */
173 int ibh_page_shift; /* page shift of current HCA */ 169 int ibh_page_shift; /* page shift of current HCA */
@@ -177,19 +173,19 @@ typedef struct kib_hca_dev {
177 __u64 ibh_mr_size; /* size of MR */ 173 __u64 ibh_mr_size; /* size of MR */
178 struct ib_mr *ibh_mrs; /* global MR */ 174 struct ib_mr *ibh_mrs; /* global MR */
179 struct ib_pd *ibh_pd; /* PD */ 175 struct ib_pd *ibh_pd; /* PD */
180 kib_dev_t *ibh_dev; /* owner */ 176 struct kib_dev *ibh_dev; /* owner */
181 atomic_t ibh_ref; /* refcount */ 177 atomic_t ibh_ref; /* refcount */
182} kib_hca_dev_t; 178};
183 179
184/** # of seconds to keep pool alive */ 180/** # of seconds to keep pool alive */
185#define IBLND_POOL_DEADLINE 300 181#define IBLND_POOL_DEADLINE 300
186/** # of seconds to retry if allocation failed */ 182/** # of seconds to retry if allocation failed */
187#define IBLND_POOL_RETRY 1 183#define IBLND_POOL_RETRY 1
188 184
189typedef struct { 185struct kib_pages {
190 int ibp_npages; /* # pages */ 186 int ibp_npages; /* # pages */
191 struct page *ibp_pages[0]; /* page array */ 187 struct page *ibp_pages[0]; /* page array */
192} kib_pages_t; 188};
193 189
194struct kib_pool; 190struct kib_pool;
195struct kib_poolset; 191struct kib_poolset;
@@ -204,7 +200,7 @@ struct kib_net;
204 200
205#define IBLND_POOL_NAME_LEN 32 201#define IBLND_POOL_NAME_LEN 32
206 202
207typedef struct kib_poolset { 203struct kib_poolset {
208 spinlock_t ps_lock; /* serialize */ 204 spinlock_t ps_lock; /* serialize */
209 struct kib_net *ps_net; /* network it belongs to */ 205 struct kib_net *ps_net; /* network it belongs to */
210 char ps_name[IBLND_POOL_NAME_LEN]; /* pool set name */ 206 char ps_name[IBLND_POOL_NAME_LEN]; /* pool set name */
@@ -220,31 +216,31 @@ typedef struct kib_poolset {
220 kib_ps_pool_destroy_t ps_pool_destroy; /* destroy a pool */ 216 kib_ps_pool_destroy_t ps_pool_destroy; /* destroy a pool */
221 kib_ps_node_init_t ps_node_init; /* initialize new allocated node */ 217 kib_ps_node_init_t ps_node_init; /* initialize new allocated node */
222 kib_ps_node_fini_t ps_node_fini; /* finalize node */ 218 kib_ps_node_fini_t ps_node_fini; /* finalize node */
223} kib_poolset_t; 219};
224 220
225typedef struct kib_pool { 221struct kib_pool {
226 struct list_head po_list; /* chain on pool list */ 222 struct list_head po_list; /* chain on pool list */
227 struct list_head po_free_list; /* pre-allocated node */ 223 struct list_head po_free_list; /* pre-allocated node */
228 kib_poolset_t *po_owner; /* pool_set of this pool */ 224 struct kib_poolset *po_owner; /* pool_set of this pool */
229 unsigned long po_deadline; /* deadline of this pool */ 225 unsigned long po_deadline; /* deadline of this pool */
230 int po_allocated; /* # of elements in use */ 226 int po_allocated; /* # of elements in use */
231 int po_failed; /* pool is created on failed HCA */ 227 int po_failed; /* pool is created on failed HCA */
232 int po_size; /* # of pre-allocated elements */ 228 int po_size; /* # of pre-allocated elements */
233} kib_pool_t; 229};
234 230
235typedef struct { 231struct kib_tx_poolset {
236 kib_poolset_t tps_poolset; /* pool-set */ 232 struct kib_poolset tps_poolset; /* pool-set */
237 __u64 tps_next_tx_cookie; /* cookie of TX */ 233 __u64 tps_next_tx_cookie; /* cookie of TX */
238} kib_tx_poolset_t; 234};
239 235
240typedef struct { 236struct kib_tx_pool {
241 kib_pool_t tpo_pool; /* pool */ 237 struct kib_pool tpo_pool; /* pool */
242 struct kib_hca_dev *tpo_hdev; /* device for this pool */ 238 struct kib_hca_dev *tpo_hdev; /* device for this pool */
243 struct kib_tx *tpo_tx_descs; /* all the tx descriptors */ 239 struct kib_tx *tpo_tx_descs; /* all the tx descriptors */
244 kib_pages_t *tpo_tx_pages; /* premapped tx msg pages */ 240 struct kib_pages *tpo_tx_pages; /* premapped tx msg pages */
245} kib_tx_pool_t; 241};
246 242
247typedef struct { 243struct kib_fmr_poolset {
248 spinlock_t fps_lock; /* serialize */ 244 spinlock_t fps_lock; /* serialize */
249 struct kib_net *fps_net; /* IB network */ 245 struct kib_net *fps_net; /* IB network */
250 struct list_head fps_pool_list; /* FMR pool list */ 246 struct list_head fps_pool_list; /* FMR pool list */
@@ -257,7 +253,7 @@ typedef struct {
257 int fps_increasing; /* is allocating new pool */ 253 int fps_increasing; /* is allocating new pool */
258 unsigned long fps_next_retry; /* time stamp for retry if*/ 254 unsigned long fps_next_retry; /* time stamp for retry if*/
259 /* failed to allocate */ 255 /* failed to allocate */
260} kib_fmr_poolset_t; 256};
261 257
262struct kib_fast_reg_descriptor { /* For fast registration */ 258struct kib_fast_reg_descriptor { /* For fast registration */
263 struct list_head frd_list; 259 struct list_head frd_list;
@@ -267,10 +263,10 @@ struct kib_fast_reg_descriptor { /* For fast registration */
267 bool frd_valid; 263 bool frd_valid;
268}; 264};
269 265
270typedef struct { 266struct kib_fmr_pool {
271 struct list_head fpo_list; /* chain on pool list */ 267 struct list_head fpo_list; /* chain on pool list */
272 struct kib_hca_dev *fpo_hdev; /* device for this pool */ 268 struct kib_hca_dev *fpo_hdev; /* device for this pool */
273 kib_fmr_poolset_t *fpo_owner; /* owner of this pool */ 269 struct kib_fmr_poolset *fpo_owner; /* owner of this pool */
274 union { 270 union {
275 struct { 271 struct {
276 struct ib_fmr_pool *fpo_fmr_pool; /* IB FMR pool */ 272 struct ib_fmr_pool *fpo_fmr_pool; /* IB FMR pool */
@@ -284,17 +280,17 @@ typedef struct {
284 int fpo_failed; /* fmr pool is failed */ 280 int fpo_failed; /* fmr pool is failed */
285 int fpo_map_count; /* # of mapped FMR */ 281 int fpo_map_count; /* # of mapped FMR */
286 int fpo_is_fmr; 282 int fpo_is_fmr;
287} kib_fmr_pool_t; 283};
288 284
289typedef struct { 285struct kib_fmr {
290 kib_fmr_pool_t *fmr_pool; /* pool of FMR */ 286 struct kib_fmr_pool *fmr_pool; /* pool of FMR */
291 struct ib_pool_fmr *fmr_pfmr; /* IB pool fmr */ 287 struct ib_pool_fmr *fmr_pfmr; /* IB pool fmr */
292 struct kib_fast_reg_descriptor *fmr_frd; 288 struct kib_fast_reg_descriptor *fmr_frd;
293 u32 fmr_key; 289 u32 fmr_key;
294} kib_fmr_t; 290};
295 291
296typedef struct kib_net { 292struct kib_net {
297 struct list_head ibn_list; /* chain on kib_dev_t::ibd_nets */ 293 struct list_head ibn_list; /* chain on struct kib_dev::ibd_nets */
298 __u64 ibn_incarnation;/* my epoch */ 294 __u64 ibn_incarnation;/* my epoch */
299 int ibn_init; /* initialisation state */ 295 int ibn_init; /* initialisation state */
300 int ibn_shutdown; /* shutting down? */ 296 int ibn_shutdown; /* shutting down? */
@@ -302,11 +298,11 @@ typedef struct kib_net {
302 atomic_t ibn_npeers; /* # peers extant */ 298 atomic_t ibn_npeers; /* # peers extant */
303 atomic_t ibn_nconns; /* # connections extant */ 299 atomic_t ibn_nconns; /* # connections extant */
304 300
305 kib_tx_poolset_t **ibn_tx_ps; /* tx pool-set */ 301 struct kib_tx_poolset **ibn_tx_ps; /* tx pool-set */
306 kib_fmr_poolset_t **ibn_fmr_ps; /* fmr pool-set */ 302 struct kib_fmr_poolset **ibn_fmr_ps; /* fmr pool-set */
307 303
308 kib_dev_t *ibn_dev; /* underlying IB device */ 304 struct kib_dev *ibn_dev; /* underlying IB device */
309} kib_net_t; 305};
310 306
311#define KIB_THREAD_SHIFT 16 307#define KIB_THREAD_SHIFT 16
312#define KIB_THREAD_ID(cpt, tid) ((cpt) << KIB_THREAD_SHIFT | (tid)) 308#define KIB_THREAD_ID(cpt, tid) ((cpt) << KIB_THREAD_SHIFT | (tid))
@@ -322,7 +318,7 @@ struct kib_sched_info {
322 int ibs_cpt; /* CPT id */ 318 int ibs_cpt; /* CPT id */
323}; 319};
324 320
325typedef struct { 321struct kib_data {
326 int kib_init; /* initialisation state */ 322 int kib_init; /* initialisation state */
327 int kib_shutdown; /* shut down? */ 323 int kib_shutdown; /* shut down? */
328 struct list_head kib_devs; /* IB devices extant */ 324 struct list_head kib_devs; /* IB devices extant */
@@ -349,7 +345,7 @@ typedef struct {
349 spinlock_t kib_connd_lock; /* serialise */ 345 spinlock_t kib_connd_lock; /* serialise */
350 struct ib_qp_attr kib_error_qpa; /* QP->ERROR */ 346 struct ib_qp_attr kib_error_qpa; /* QP->ERROR */
351 struct kib_sched_info **kib_scheds; /* percpt data for schedulers */ 347 struct kib_sched_info **kib_scheds; /* percpt data for schedulers */
352} kib_data_t; 348};
353 349
354#define IBLND_INIT_NOTHING 0 350#define IBLND_INIT_NOTHING 0
355#define IBLND_INIT_DATA 1 351#define IBLND_INIT_DATA 1
@@ -360,51 +356,51 @@ typedef struct {
360 * These are sent in sender's byte order (i.e. receiver flips). 356 * These are sent in sender's byte order (i.e. receiver flips).
361 */ 357 */
362 358
363typedef struct kib_connparams { 359struct kib_connparams {
364 __u16 ibcp_queue_depth; 360 __u16 ibcp_queue_depth;
365 __u16 ibcp_max_frags; 361 __u16 ibcp_max_frags;
366 __u32 ibcp_max_msg_size; 362 __u32 ibcp_max_msg_size;
367} WIRE_ATTR kib_connparams_t; 363} WIRE_ATTR;
368 364
369typedef struct { 365struct kib_immediate_msg {
370 lnet_hdr_t ibim_hdr; /* portals header */ 366 lnet_hdr_t ibim_hdr; /* portals header */
371 char ibim_payload[0]; /* piggy-backed payload */ 367 char ibim_payload[0]; /* piggy-backed payload */
372} WIRE_ATTR kib_immediate_msg_t; 368} WIRE_ATTR;
373 369
374typedef struct { 370struct kib_rdma_frag {
375 __u32 rf_nob; /* # bytes this frag */ 371 __u32 rf_nob; /* # bytes this frag */
376 __u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */ 372 __u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */
377} WIRE_ATTR kib_rdma_frag_t; 373} WIRE_ATTR;
378 374
379typedef struct { 375struct kib_rdma_desc {
380 __u32 rd_key; /* local/remote key */ 376 __u32 rd_key; /* local/remote key */
381 __u32 rd_nfrags; /* # fragments */ 377 __u32 rd_nfrags; /* # fragments */
382 kib_rdma_frag_t rd_frags[0]; /* buffer frags */ 378 struct kib_rdma_frag rd_frags[0]; /* buffer frags */
383} WIRE_ATTR kib_rdma_desc_t; 379} WIRE_ATTR;
384 380
385typedef struct { 381struct kib_putreq_msg {
386 lnet_hdr_t ibprm_hdr; /* portals header */ 382 lnet_hdr_t ibprm_hdr; /* portals header */
387 __u64 ibprm_cookie; /* opaque completion cookie */ 383 __u64 ibprm_cookie; /* opaque completion cookie */
388} WIRE_ATTR kib_putreq_msg_t; 384} WIRE_ATTR;
389 385
390typedef struct { 386struct kib_putack_msg {
391 __u64 ibpam_src_cookie; /* reflected completion cookie */ 387 __u64 ibpam_src_cookie; /* reflected completion cookie */
392 __u64 ibpam_dst_cookie; /* opaque completion cookie */ 388 __u64 ibpam_dst_cookie; /* opaque completion cookie */
393 kib_rdma_desc_t ibpam_rd; /* sender's sink buffer */ 389 struct kib_rdma_desc ibpam_rd; /* sender's sink buffer */
394} WIRE_ATTR kib_putack_msg_t; 390} WIRE_ATTR;
395 391
396typedef struct { 392struct kib_get_msg {
397 lnet_hdr_t ibgm_hdr; /* portals header */ 393 lnet_hdr_t ibgm_hdr; /* portals header */
398 __u64 ibgm_cookie; /* opaque completion cookie */ 394 __u64 ibgm_cookie; /* opaque completion cookie */
399 kib_rdma_desc_t ibgm_rd; /* rdma descriptor */ 395 struct kib_rdma_desc ibgm_rd; /* rdma descriptor */
400} WIRE_ATTR kib_get_msg_t; 396} WIRE_ATTR;
401 397
402typedef struct { 398struct kib_completion_msg {
403 __u64 ibcm_cookie; /* opaque completion cookie */ 399 __u64 ibcm_cookie; /* opaque completion cookie */
404 __s32 ibcm_status; /* < 0 failure: >= 0 length */ 400 __s32 ibcm_status; /* < 0 failure: >= 0 length */
405} WIRE_ATTR kib_completion_msg_t; 401} WIRE_ATTR;
406 402
407typedef struct { 403struct kib_msg {
408 /* First 2 fields fixed FOR ALL TIME */ 404 /* First 2 fields fixed FOR ALL TIME */
409 __u32 ibm_magic; /* I'm an ibnal message */ 405 __u32 ibm_magic; /* I'm an ibnal message */
410 __u16 ibm_version; /* this is my version number */ 406 __u16 ibm_version; /* this is my version number */
@@ -419,14 +415,14 @@ typedef struct {
419 __u64 ibm_dststamp; /* destination's incarnation */ 415 __u64 ibm_dststamp; /* destination's incarnation */
420 416
421 union { 417 union {
422 kib_connparams_t connparams; 418 struct kib_connparams connparams;
423 kib_immediate_msg_t immediate; 419 struct kib_immediate_msg immediate;
424 kib_putreq_msg_t putreq; 420 struct kib_putreq_msg putreq;
425 kib_putack_msg_t putack; 421 struct kib_putack_msg putack;
426 kib_get_msg_t get; 422 struct kib_get_msg get;
427 kib_completion_msg_t completion; 423 struct kib_completion_msg completion;
428 } WIRE_ATTR ibm_u; 424 } WIRE_ATTR ibm_u;
429} WIRE_ATTR kib_msg_t; 425} WIRE_ATTR;
430 426
431#define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */ 427#define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */
432 428
@@ -445,14 +441,14 @@ typedef struct {
445#define IBLND_MSG_GET_REQ 0xd6 /* getreq (sink->src) */ 441#define IBLND_MSG_GET_REQ 0xd6 /* getreq (sink->src) */
446#define IBLND_MSG_GET_DONE 0xd7 /* completion (src->sink: all OK) */ 442#define IBLND_MSG_GET_DONE 0xd7 /* completion (src->sink: all OK) */
447 443
448typedef struct { 444struct kib_rej {
449 __u32 ibr_magic; /* sender's magic */ 445 __u32 ibr_magic; /* sender's magic */
450 __u16 ibr_version; /* sender's version */ 446 __u16 ibr_version; /* sender's version */
451 __u8 ibr_why; /* reject reason */ 447 __u8 ibr_why; /* reject reason */
452 __u8 ibr_padding; /* padding */ 448 __u8 ibr_padding; /* padding */
453 __u64 ibr_incarnation; /* incarnation of peer */ 449 __u64 ibr_incarnation; /* incarnation of peer */
454 kib_connparams_t ibr_cp; /* connection parameters */ 450 struct kib_connparams ibr_cp; /* connection parameters */
455} WIRE_ATTR kib_rej_t; 451} WIRE_ATTR;
456 452
457/* connection rejection reasons */ 453/* connection rejection reasons */
458#define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */ 454#define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */
@@ -467,28 +463,26 @@ typedef struct {
467 463
468/***********************************************************************/ 464/***********************************************************************/
469 465
470typedef struct kib_rx /* receive message */ 466struct kib_rx { /* receive message */
471{
472 struct list_head rx_list; /* queue for attention */ 467 struct list_head rx_list; /* queue for attention */
473 struct kib_conn *rx_conn; /* owning conn */ 468 struct kib_conn *rx_conn; /* owning conn */
474 int rx_nob; /* # bytes received (-1 while posted) */ 469 int rx_nob; /* # bytes received (-1 while posted) */
475 enum ib_wc_status rx_status; /* completion status */ 470 enum ib_wc_status rx_status; /* completion status */
476 kib_msg_t *rx_msg; /* message buffer (host vaddr) */ 471 struct kib_msg *rx_msg; /* message buffer (host vaddr) */
477 __u64 rx_msgaddr; /* message buffer (I/O addr) */ 472 __u64 rx_msgaddr; /* message buffer (I/O addr) */
478 DECLARE_PCI_UNMAP_ADDR(rx_msgunmap); /* for dma_unmap_single() */ 473 DECLARE_PCI_UNMAP_ADDR(rx_msgunmap); /* for dma_unmap_single() */
479 struct ib_recv_wr rx_wrq; /* receive work item... */ 474 struct ib_recv_wr rx_wrq; /* receive work item... */
480 struct ib_sge rx_sge; /* ...and its memory */ 475 struct ib_sge rx_sge; /* ...and its memory */
481} kib_rx_t; 476};
482 477
483#define IBLND_POSTRX_DONT_POST 0 /* don't post */ 478#define IBLND_POSTRX_DONT_POST 0 /* don't post */
484#define IBLND_POSTRX_NO_CREDIT 1 /* post: no credits */ 479#define IBLND_POSTRX_NO_CREDIT 1 /* post: no credits */
485#define IBLND_POSTRX_PEER_CREDIT 2 /* post: give peer back 1 credit */ 480#define IBLND_POSTRX_PEER_CREDIT 2 /* post: give peer back 1 credit */
486#define IBLND_POSTRX_RSRVD_CREDIT 3 /* post: give self back 1 reserved credit */ 481#define IBLND_POSTRX_RSRVD_CREDIT 3 /* post: give self back 1 reserved credit */
487 482
488typedef struct kib_tx /* transmit message */ 483struct kib_tx { /* transmit message */
489{
490 struct list_head tx_list; /* queue on idle_txs ibc_tx_queue etc. */ 484 struct list_head tx_list; /* queue on idle_txs ibc_tx_queue etc. */
491 kib_tx_pool_t *tx_pool; /* pool I'm from */ 485 struct kib_tx_pool *tx_pool; /* pool I'm from */
492 struct kib_conn *tx_conn; /* owning conn */ 486 struct kib_conn *tx_conn; /* owning conn */
493 short tx_sending; /* # tx callbacks outstanding */ 487 short tx_sending; /* # tx callbacks outstanding */
494 short tx_queued; /* queued for sending */ 488 short tx_queued; /* queued for sending */
@@ -497,28 +491,28 @@ typedef struct kib_tx /* transmit message */
497 unsigned long tx_deadline; /* completion deadline */ 491 unsigned long tx_deadline; /* completion deadline */
498 __u64 tx_cookie; /* completion cookie */ 492 __u64 tx_cookie; /* completion cookie */
499 lnet_msg_t *tx_lntmsg[2]; /* lnet msgs to finalize on completion */ 493 lnet_msg_t *tx_lntmsg[2]; /* lnet msgs to finalize on completion */
500 kib_msg_t *tx_msg; /* message buffer (host vaddr) */ 494 struct kib_msg *tx_msg; /* message buffer (host vaddr) */
501 __u64 tx_msgaddr; /* message buffer (I/O addr) */ 495 __u64 tx_msgaddr; /* message buffer (I/O addr) */
502 DECLARE_PCI_UNMAP_ADDR(tx_msgunmap); /* for dma_unmap_single() */ 496 DECLARE_PCI_UNMAP_ADDR(tx_msgunmap); /* for dma_unmap_single() */
503 int tx_nwrq; /* # send work items */ 497 int tx_nwrq; /* # send work items */
504 struct ib_rdma_wr *tx_wrq; /* send work items... */ 498 struct ib_rdma_wr *tx_wrq; /* send work items... */
505 struct ib_sge *tx_sge; /* ...and their memory */ 499 struct ib_sge *tx_sge; /* ...and their memory */
506 kib_rdma_desc_t *tx_rd; /* rdma descriptor */ 500 struct kib_rdma_desc *tx_rd; /* rdma descriptor */
507 int tx_nfrags; /* # entries in... */ 501 int tx_nfrags; /* # entries in... */
508 struct scatterlist *tx_frags; /* dma_map_sg descriptor */ 502 struct scatterlist *tx_frags; /* dma_map_sg descriptor */
509 __u64 *tx_pages; /* rdma phys page addrs */ 503 __u64 *tx_pages; /* rdma phys page addrs */
510 kib_fmr_t fmr; /* FMR */ 504 struct kib_fmr fmr; /* FMR */
511 int tx_dmadir; /* dma direction */ 505 int tx_dmadir; /* dma direction */
512} kib_tx_t; 506};
513 507
514typedef struct kib_connvars { 508struct kib_connvars {
515 kib_msg_t cv_msg; /* connection-in-progress variables */ 509 struct kib_msg cv_msg; /* connection-in-progress variables */
516} kib_connvars_t; 510};
517 511
518typedef struct kib_conn { 512struct kib_conn {
519 struct kib_sched_info *ibc_sched; /* scheduler information */ 513 struct kib_sched_info *ibc_sched; /* scheduler information */
520 struct kib_peer *ibc_peer; /* owning peer */ 514 struct kib_peer *ibc_peer; /* owning peer */
521 kib_hca_dev_t *ibc_hdev; /* HCA bound on */ 515 struct kib_hca_dev *ibc_hdev; /* HCA bound on */
522 struct list_head ibc_list; /* stash on peer's conn list */ 516 struct list_head ibc_list; /* stash on peer's conn list */
523 struct list_head ibc_sched_list; /* schedule for attention */ 517 struct list_head ibc_sched_list; /* schedule for attention */
524 __u16 ibc_version; /* version of connection */ 518 __u16 ibc_version; /* version of connection */
@@ -553,14 +547,14 @@ typedef struct kib_conn {
553 /* reserve an ACK/DONE msg */ 547 /* reserve an ACK/DONE msg */
554 struct list_head ibc_active_txs; /* active tx awaiting completion */ 548 struct list_head ibc_active_txs; /* active tx awaiting completion */
555 spinlock_t ibc_lock; /* serialise */ 549 spinlock_t ibc_lock; /* serialise */
556 kib_rx_t *ibc_rxs; /* the rx descs */ 550 struct kib_rx *ibc_rxs; /* the rx descs */
557 kib_pages_t *ibc_rx_pages; /* premapped rx msg pages */ 551 struct kib_pages *ibc_rx_pages; /* premapped rx msg pages */
558 552
559 struct rdma_cm_id *ibc_cmid; /* CM id */ 553 struct rdma_cm_id *ibc_cmid; /* CM id */
560 struct ib_cq *ibc_cq; /* completion queue */ 554 struct ib_cq *ibc_cq; /* completion queue */
561 555
562 kib_connvars_t *ibc_connvars; /* in-progress connection state */ 556 struct kib_connvars *ibc_connvars; /* in-progress connection state */
563} kib_conn_t; 557};
564 558
565#define IBLND_CONN_INIT 0 /* being initialised */ 559#define IBLND_CONN_INIT 0 /* being initialised */
566#define IBLND_CONN_ACTIVE_CONNECT 1 /* active sending req */ 560#define IBLND_CONN_ACTIVE_CONNECT 1 /* active sending req */
@@ -569,7 +563,7 @@ typedef struct kib_conn {
569#define IBLND_CONN_CLOSING 4 /* being closed */ 563#define IBLND_CONN_CLOSING 4 /* being closed */
570#define IBLND_CONN_DISCONNECTED 5 /* disconnected */ 564#define IBLND_CONN_DISCONNECTED 5 /* disconnected */
571 565
572typedef struct kib_peer { 566struct kib_peer {
573 struct list_head ibp_list; /* stash on global peer list */ 567 struct list_head ibp_list; /* stash on global peer list */
574 lnet_nid_t ibp_nid; /* who's on the other end(s) */ 568 lnet_nid_t ibp_nid; /* who's on the other end(s) */
575 lnet_ni_t *ibp_ni; /* LNet interface */ 569 lnet_ni_t *ibp_ni; /* LNet interface */
@@ -596,11 +590,11 @@ typedef struct kib_peer {
596 __u16 ibp_max_frags; 590 __u16 ibp_max_frags;
597 /* max_peer_credits */ 591 /* max_peer_credits */
598 __u16 ibp_queue_depth; 592 __u16 ibp_queue_depth;
599} kib_peer_t; 593};
600 594
601extern kib_data_t kiblnd_data; 595extern struct kib_data kiblnd_data;
602 596
603void kiblnd_hdev_destroy(kib_hca_dev_t *hdev); 597void kiblnd_hdev_destroy(struct kib_hca_dev *hdev);
604 598
605int kiblnd_msg_queue_size(int version, struct lnet_ni *ni); 599int kiblnd_msg_queue_size(int version, struct lnet_ni *ni);
606 600
@@ -645,14 +639,14 @@ kiblnd_concurrent_sends(int version, struct lnet_ni *ni)
645} 639}
646 640
647static inline void 641static inline void
648kiblnd_hdev_addref_locked(kib_hca_dev_t *hdev) 642kiblnd_hdev_addref_locked(struct kib_hca_dev *hdev)
649{ 643{
650 LASSERT(atomic_read(&hdev->ibh_ref) > 0); 644 LASSERT(atomic_read(&hdev->ibh_ref) > 0);
651 atomic_inc(&hdev->ibh_ref); 645 atomic_inc(&hdev->ibh_ref);
652} 646}
653 647
654static inline void 648static inline void
655kiblnd_hdev_decref(kib_hca_dev_t *hdev) 649kiblnd_hdev_decref(struct kib_hca_dev *hdev)
656{ 650{
657 LASSERT(atomic_read(&hdev->ibh_ref) > 0); 651 LASSERT(atomic_read(&hdev->ibh_ref) > 0);
658 if (atomic_dec_and_test(&hdev->ibh_ref)) 652 if (atomic_dec_and_test(&hdev->ibh_ref))
@@ -660,7 +654,7 @@ kiblnd_hdev_decref(kib_hca_dev_t *hdev)
660} 654}
661 655
662static inline int 656static inline int
663kiblnd_dev_can_failover(kib_dev_t *dev) 657kiblnd_dev_can_failover(struct kib_dev *dev)
664{ 658{
665 if (!list_empty(&dev->ibd_fail_list)) /* already scheduled */ 659 if (!list_empty(&dev->ibd_fail_list)) /* already scheduled */
666 return 0; 660 return 0;
@@ -716,7 +710,7 @@ do { \
716} while (0) 710} while (0)
717 711
718static inline bool 712static inline bool
719kiblnd_peer_connecting(kib_peer_t *peer) 713kiblnd_peer_connecting(struct kib_peer *peer)
720{ 714{
721 return peer->ibp_connecting || 715 return peer->ibp_connecting ||
722 peer->ibp_reconnecting || 716 peer->ibp_reconnecting ||
@@ -724,7 +718,7 @@ kiblnd_peer_connecting(kib_peer_t *peer)
724} 718}
725 719
726static inline bool 720static inline bool
727kiblnd_peer_idle(kib_peer_t *peer) 721kiblnd_peer_idle(struct kib_peer *peer)
728{ 722{
729 return !kiblnd_peer_connecting(peer) && list_empty(&peer->ibp_conns); 723 return !kiblnd_peer_connecting(peer) && list_empty(&peer->ibp_conns);
730} 724}
@@ -739,23 +733,23 @@ kiblnd_nid2peerlist(lnet_nid_t nid)
739} 733}
740 734
741static inline int 735static inline int
742kiblnd_peer_active(kib_peer_t *peer) 736kiblnd_peer_active(struct kib_peer *peer)
743{ 737{
744 /* Am I in the peer hash table? */ 738 /* Am I in the peer hash table? */
745 return !list_empty(&peer->ibp_list); 739 return !list_empty(&peer->ibp_list);
746} 740}
747 741
748static inline kib_conn_t * 742static inline struct kib_conn *
749kiblnd_get_conn_locked(kib_peer_t *peer) 743kiblnd_get_conn_locked(struct kib_peer *peer)
750{ 744{
751 LASSERT(!list_empty(&peer->ibp_conns)); 745 LASSERT(!list_empty(&peer->ibp_conns));
752 746
753 /* just return the first connection */ 747 /* just return the first connection */
754 return list_entry(peer->ibp_conns.next, kib_conn_t, ibc_list); 748 return list_entry(peer->ibp_conns.next, struct kib_conn, ibc_list);
755} 749}
756 750
757static inline int 751static inline int
758kiblnd_send_keepalive(kib_conn_t *conn) 752kiblnd_send_keepalive(struct kib_conn *conn)
759{ 753{
760 return (*kiblnd_tunables.kib_keepalive > 0) && 754 return (*kiblnd_tunables.kib_keepalive > 0) &&
761 cfs_time_after(jiffies, conn->ibc_last_send + 755 cfs_time_after(jiffies, conn->ibc_last_send +
@@ -764,7 +758,7 @@ kiblnd_send_keepalive(kib_conn_t *conn)
764} 758}
765 759
766static inline int 760static inline int
767kiblnd_need_noop(kib_conn_t *conn) 761kiblnd_need_noop(struct kib_conn *conn)
768{ 762{
769 struct lnet_ioctl_config_o2iblnd_tunables *tunables; 763 struct lnet_ioctl_config_o2iblnd_tunables *tunables;
770 lnet_ni_t *ni = conn->ibc_peer->ibp_ni; 764 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
@@ -800,14 +794,14 @@ kiblnd_need_noop(kib_conn_t *conn)
800} 794}
801 795
802static inline void 796static inline void
803kiblnd_abort_receives(kib_conn_t *conn) 797kiblnd_abort_receives(struct kib_conn *conn)
804{ 798{
805 ib_modify_qp(conn->ibc_cmid->qp, 799 ib_modify_qp(conn->ibc_cmid->qp,
806 &kiblnd_data.kib_error_qpa, IB_QP_STATE); 800 &kiblnd_data.kib_error_qpa, IB_QP_STATE);
807} 801}
808 802
809static inline const char * 803static inline const char *
810kiblnd_queue2str(kib_conn_t *conn, struct list_head *q) 804kiblnd_queue2str(struct kib_conn *conn, struct list_head *q)
811{ 805{
812 if (q == &conn->ibc_tx_queue) 806 if (q == &conn->ibc_tx_queue)
813 return "tx_queue"; 807 return "tx_queue";
@@ -858,21 +852,21 @@ kiblnd_wreqid2type(__u64 wreqid)
858} 852}
859 853
860static inline void 854static inline void
861kiblnd_set_conn_state(kib_conn_t *conn, int state) 855kiblnd_set_conn_state(struct kib_conn *conn, int state)
862{ 856{
863 conn->ibc_state = state; 857 conn->ibc_state = state;
864 mb(); 858 mb();
865} 859}
866 860
867static inline void 861static inline void
868kiblnd_init_msg(kib_msg_t *msg, int type, int body_nob) 862kiblnd_init_msg(struct kib_msg *msg, int type, int body_nob)
869{ 863{
870 msg->ibm_type = type; 864 msg->ibm_type = type;
871 msg->ibm_nob = offsetof(kib_msg_t, ibm_u) + body_nob; 865 msg->ibm_nob = offsetof(struct kib_msg, ibm_u) + body_nob;
872} 866}
873 867
874static inline int 868static inline int
875kiblnd_rd_size(kib_rdma_desc_t *rd) 869kiblnd_rd_size(struct kib_rdma_desc *rd)
876{ 870{
877 int i; 871 int i;
878 int size; 872 int size;
@@ -884,25 +878,25 @@ kiblnd_rd_size(kib_rdma_desc_t *rd)
884} 878}
885 879
886static inline __u64 880static inline __u64
887kiblnd_rd_frag_addr(kib_rdma_desc_t *rd, int index) 881kiblnd_rd_frag_addr(struct kib_rdma_desc *rd, int index)
888{ 882{
889 return rd->rd_frags[index].rf_addr; 883 return rd->rd_frags[index].rf_addr;
890} 884}
891 885
892static inline __u32 886static inline __u32
893kiblnd_rd_frag_size(kib_rdma_desc_t *rd, int index) 887kiblnd_rd_frag_size(struct kib_rdma_desc *rd, int index)
894{ 888{
895 return rd->rd_frags[index].rf_nob; 889 return rd->rd_frags[index].rf_nob;
896} 890}
897 891
898static inline __u32 892static inline __u32
899kiblnd_rd_frag_key(kib_rdma_desc_t *rd, int index) 893kiblnd_rd_frag_key(struct kib_rdma_desc *rd, int index)
900{ 894{
901 return rd->rd_key; 895 return rd->rd_key;
902} 896}
903 897
904static inline int 898static inline int
905kiblnd_rd_consume_frag(kib_rdma_desc_t *rd, int index, __u32 nob) 899kiblnd_rd_consume_frag(struct kib_rdma_desc *rd, int index, __u32 nob)
906{ 900{
907 if (nob < rd->rd_frags[index].rf_nob) { 901 if (nob < rd->rd_frags[index].rf_nob) {
908 rd->rd_frags[index].rf_addr += nob; 902 rd->rd_frags[index].rf_addr += nob;
@@ -915,14 +909,14 @@ kiblnd_rd_consume_frag(kib_rdma_desc_t *rd, int index, __u32 nob)
915} 909}
916 910
917static inline int 911static inline int
918kiblnd_rd_msg_size(kib_rdma_desc_t *rd, int msgtype, int n) 912kiblnd_rd_msg_size(struct kib_rdma_desc *rd, int msgtype, int n)
919{ 913{
920 LASSERT(msgtype == IBLND_MSG_GET_REQ || 914 LASSERT(msgtype == IBLND_MSG_GET_REQ ||
921 msgtype == IBLND_MSG_PUT_ACK); 915 msgtype == IBLND_MSG_PUT_ACK);
922 916
923 return msgtype == IBLND_MSG_GET_REQ ? 917 return msgtype == IBLND_MSG_GET_REQ ?
924 offsetof(kib_get_msg_t, ibgm_rd.rd_frags[n]) : 918 offsetof(struct kib_get_msg, ibgm_rd.rd_frags[n]) :
925 offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[n]); 919 offsetof(struct kib_putack_msg, ibpam_rd.rd_frags[n]);
926} 920}
927 921
928static inline __u64 922static inline __u64
@@ -981,17 +975,17 @@ static inline unsigned int kiblnd_sg_dma_len(struct ib_device *dev,
981#define KIBLND_CONN_PARAM(e) ((e)->param.conn.private_data) 975#define KIBLND_CONN_PARAM(e) ((e)->param.conn.private_data)
982#define KIBLND_CONN_PARAM_LEN(e) ((e)->param.conn.private_data_len) 976#define KIBLND_CONN_PARAM_LEN(e) ((e)->param.conn.private_data_len)
983 977
984struct ib_mr *kiblnd_find_rd_dma_mr(struct lnet_ni *ni, kib_rdma_desc_t *rd, 978struct ib_mr *kiblnd_find_rd_dma_mr(struct lnet_ni *ni, struct kib_rdma_desc *rd,
985 int negotiated_nfrags); 979 int negotiated_nfrags);
986void kiblnd_map_rx_descs(kib_conn_t *conn); 980void kiblnd_map_rx_descs(struct kib_conn *conn);
987void kiblnd_unmap_rx_descs(kib_conn_t *conn); 981void kiblnd_unmap_rx_descs(struct kib_conn *conn);
988void kiblnd_pool_free_node(kib_pool_t *pool, struct list_head *node); 982void kiblnd_pool_free_node(struct kib_pool *pool, struct list_head *node);
989struct list_head *kiblnd_pool_alloc_node(kib_poolset_t *ps); 983struct list_head *kiblnd_pool_alloc_node(struct kib_poolset *ps);
990 984
991int kiblnd_fmr_pool_map(kib_fmr_poolset_t *fps, kib_tx_t *tx, 985int kiblnd_fmr_pool_map(struct kib_fmr_poolset *fps, struct kib_tx *tx,
992 kib_rdma_desc_t *rd, __u32 nob, __u64 iov, 986 struct kib_rdma_desc *rd, __u32 nob, __u64 iov,
993 kib_fmr_t *fmr); 987 struct kib_fmr *fmr);
994void kiblnd_fmr_pool_unmap(kib_fmr_t *fmr, int status); 988void kiblnd_fmr_pool_unmap(struct kib_fmr *fmr, int status);
995 989
996int kiblnd_tunables_setup(struct lnet_ni *ni); 990int kiblnd_tunables_setup(struct lnet_ni *ni);
997void kiblnd_tunables_init(void); 991void kiblnd_tunables_init(void);
@@ -1001,30 +995,31 @@ int kiblnd_scheduler(void *arg);
1001int kiblnd_thread_start(int (*fn)(void *arg), void *arg, char *name); 995int kiblnd_thread_start(int (*fn)(void *arg), void *arg, char *name);
1002int kiblnd_failover_thread(void *arg); 996int kiblnd_failover_thread(void *arg);
1003 997
1004int kiblnd_alloc_pages(kib_pages_t **pp, int cpt, int npages); 998int kiblnd_alloc_pages(struct kib_pages **pp, int cpt, int npages);
1005 999
1006int kiblnd_cm_callback(struct rdma_cm_id *cmid, 1000int kiblnd_cm_callback(struct rdma_cm_id *cmid,
1007 struct rdma_cm_event *event); 1001 struct rdma_cm_event *event);
1008int kiblnd_translate_mtu(int value); 1002int kiblnd_translate_mtu(int value);
1009 1003
1010int kiblnd_dev_failover(kib_dev_t *dev); 1004int kiblnd_dev_failover(struct kib_dev *dev);
1011int kiblnd_create_peer(lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid); 1005int kiblnd_create_peer(lnet_ni_t *ni, struct kib_peer **peerp, lnet_nid_t nid);
1012void kiblnd_destroy_peer(kib_peer_t *peer); 1006void kiblnd_destroy_peer(struct kib_peer *peer);
1013bool kiblnd_reconnect_peer(kib_peer_t *peer); 1007bool kiblnd_reconnect_peer(struct kib_peer *peer);
1014void kiblnd_destroy_dev(kib_dev_t *dev); 1008void kiblnd_destroy_dev(struct kib_dev *dev);
1015void kiblnd_unlink_peer_locked(kib_peer_t *peer); 1009void kiblnd_unlink_peer_locked(struct kib_peer *peer);
1016kib_peer_t *kiblnd_find_peer_locked(lnet_nid_t nid); 1010struct kib_peer *kiblnd_find_peer_locked(lnet_nid_t nid);
1017int kiblnd_close_stale_conns_locked(kib_peer_t *peer, 1011int kiblnd_close_stale_conns_locked(struct kib_peer *peer,
1018 int version, __u64 incarnation); 1012 int version, __u64 incarnation);
1019int kiblnd_close_peer_conns_locked(kib_peer_t *peer, int why); 1013int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why);
1020 1014
1021kib_conn_t *kiblnd_create_conn(kib_peer_t *peer, struct rdma_cm_id *cmid, 1015struct kib_conn *kiblnd_create_conn(struct kib_peer *peer,
1022 int state, int version); 1016 struct rdma_cm_id *cmid,
1023void kiblnd_destroy_conn(kib_conn_t *conn, bool free_conn); 1017 int state, int version);
1024void kiblnd_close_conn(kib_conn_t *conn, int error); 1018void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn);
1025void kiblnd_close_conn_locked(kib_conn_t *conn, int error); 1019void kiblnd_close_conn(struct kib_conn *conn, int error);
1020void kiblnd_close_conn_locked(struct kib_conn *conn, int error);
1026 1021
1027void kiblnd_launch_tx(lnet_ni_t *ni, kib_tx_t *tx, lnet_nid_t nid); 1022void kiblnd_launch_tx(lnet_ni_t *ni, struct kib_tx *tx, lnet_nid_t nid);
1028void kiblnd_txlist_done(lnet_ni_t *ni, struct list_head *txlist, 1023void kiblnd_txlist_done(lnet_ni_t *ni, struct list_head *txlist,
1029 int status); 1024 int status);
1030 1025
@@ -1032,10 +1027,10 @@ void kiblnd_qp_event(struct ib_event *event, void *arg);
1032void kiblnd_cq_event(struct ib_event *event, void *arg); 1027void kiblnd_cq_event(struct ib_event *event, void *arg);
1033void kiblnd_cq_completion(struct ib_cq *cq, void *arg); 1028void kiblnd_cq_completion(struct ib_cq *cq, void *arg);
1034 1029
1035void kiblnd_pack_msg(lnet_ni_t *ni, kib_msg_t *msg, int version, 1030void kiblnd_pack_msg(lnet_ni_t *ni, struct kib_msg *msg, int version,
1036 int credits, lnet_nid_t dstnid, __u64 dststamp); 1031 int credits, lnet_nid_t dstnid, __u64 dststamp);
1037int kiblnd_unpack_msg(kib_msg_t *msg, int nob); 1032int kiblnd_unpack_msg(struct kib_msg *msg, int nob);
1038int kiblnd_post_rx(kib_rx_t *rx, int credit); 1033int kiblnd_post_rx(struct kib_rx *rx, int credit);
1039 1034
1040int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg); 1035int kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg);
1041int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed, 1036int kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
index 845e49a52430..596a697b9d39 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -40,22 +36,22 @@
40 36
41#include "o2iblnd.h" 37#include "o2iblnd.h"
42 38
43static void kiblnd_peer_alive(kib_peer_t *peer); 39static void kiblnd_peer_alive(struct kib_peer *peer);
44static void kiblnd_peer_connect_failed(kib_peer_t *peer, int active, int error); 40static void kiblnd_peer_connect_failed(struct kib_peer *peer, int active, int error);
45static void kiblnd_check_sends(kib_conn_t *conn); 41static void kiblnd_check_sends(struct kib_conn *conn);
46static void kiblnd_init_tx_msg(lnet_ni_t *ni, kib_tx_t *tx, 42static void kiblnd_init_tx_msg(lnet_ni_t *ni, struct kib_tx *tx,
47 int type, int body_nob); 43 int type, int body_nob);
48static int kiblnd_init_rdma(kib_conn_t *conn, kib_tx_t *tx, int type, 44static int kiblnd_init_rdma(struct kib_conn *conn, struct kib_tx *tx, int type,
49 int resid, kib_rdma_desc_t *dstrd, __u64 dstcookie); 45 int resid, struct kib_rdma_desc *dstrd, __u64 dstcookie);
50static void kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn); 46static void kiblnd_queue_tx_locked(struct kib_tx *tx, struct kib_conn *conn);
51static void kiblnd_queue_tx(kib_tx_t *tx, kib_conn_t *conn); 47static void kiblnd_queue_tx(struct kib_tx *tx, struct kib_conn *conn);
52static void kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx); 48static void kiblnd_unmap_tx(lnet_ni_t *ni, struct kib_tx *tx);
53 49
54static void 50static void
55kiblnd_tx_done(lnet_ni_t *ni, kib_tx_t *tx) 51kiblnd_tx_done(lnet_ni_t *ni, struct kib_tx *tx)
56{ 52{
57 lnet_msg_t *lntmsg[2]; 53 lnet_msg_t *lntmsg[2];
58 kib_net_t *net = ni->ni_data; 54 struct kib_net *net = ni->ni_data;
59 int rc; 55 int rc;
60 int i; 56 int i;
61 57
@@ -97,10 +93,10 @@ kiblnd_tx_done(lnet_ni_t *ni, kib_tx_t *tx)
97void 93void
98kiblnd_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int status) 94kiblnd_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int status)
99{ 95{
100 kib_tx_t *tx; 96 struct kib_tx *tx;
101 97
102 while (!list_empty(txlist)) { 98 while (!list_empty(txlist)) {
103 tx = list_entry(txlist->next, kib_tx_t, tx_list); 99 tx = list_entry(txlist->next, struct kib_tx, tx_list);
104 100
105 list_del(&tx->tx_list); 101 list_del(&tx->tx_list);
106 /* complete now */ 102 /* complete now */
@@ -110,19 +106,19 @@ kiblnd_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int status)
110 } 106 }
111} 107}
112 108
113static kib_tx_t * 109static struct kib_tx *
114kiblnd_get_idle_tx(lnet_ni_t *ni, lnet_nid_t target) 110kiblnd_get_idle_tx(lnet_ni_t *ni, lnet_nid_t target)
115{ 111{
116 kib_net_t *net = (kib_net_t *)ni->ni_data; 112 struct kib_net *net = (struct kib_net *)ni->ni_data;
117 struct list_head *node; 113 struct list_head *node;
118 kib_tx_t *tx; 114 struct kib_tx *tx;
119 kib_tx_poolset_t *tps; 115 struct kib_tx_poolset *tps;
120 116
121 tps = net->ibn_tx_ps[lnet_cpt_of_nid(target)]; 117 tps = net->ibn_tx_ps[lnet_cpt_of_nid(target)];
122 node = kiblnd_pool_alloc_node(&tps->tps_poolset); 118 node = kiblnd_pool_alloc_node(&tps->tps_poolset);
123 if (!node) 119 if (!node)
124 return NULL; 120 return NULL;
125 tx = list_entry(node, kib_tx_t, tx_list); 121 tx = list_entry(node, struct kib_tx, tx_list);
126 122
127 LASSERT(!tx->tx_nwrq); 123 LASSERT(!tx->tx_nwrq);
128 LASSERT(!tx->tx_queued); 124 LASSERT(!tx->tx_queued);
@@ -138,9 +134,9 @@ kiblnd_get_idle_tx(lnet_ni_t *ni, lnet_nid_t target)
138} 134}
139 135
140static void 136static void
141kiblnd_drop_rx(kib_rx_t *rx) 137kiblnd_drop_rx(struct kib_rx *rx)
142{ 138{
143 kib_conn_t *conn = rx->rx_conn; 139 struct kib_conn *conn = rx->rx_conn;
144 struct kib_sched_info *sched = conn->ibc_sched; 140 struct kib_sched_info *sched = conn->ibc_sched;
145 unsigned long flags; 141 unsigned long flags;
146 142
@@ -153,10 +149,10 @@ kiblnd_drop_rx(kib_rx_t *rx)
153} 149}
154 150
155int 151int
156kiblnd_post_rx(kib_rx_t *rx, int credit) 152kiblnd_post_rx(struct kib_rx *rx, int credit)
157{ 153{
158 kib_conn_t *conn = rx->rx_conn; 154 struct kib_conn *conn = rx->rx_conn;
159 kib_net_t *net = conn->ibc_peer->ibp_ni->ni_data; 155 struct kib_net *net = conn->ibc_peer->ibp_ni->ni_data;
160 struct ib_recv_wr *bad_wrq = NULL; 156 struct ib_recv_wr *bad_wrq = NULL;
161 struct ib_mr *mr = conn->ibc_hdev->ibh_mrs; 157 struct ib_mr *mr = conn->ibc_hdev->ibh_mrs;
162 int rc; 158 int rc;
@@ -223,13 +219,13 @@ out:
223 return rc; 219 return rc;
224} 220}
225 221
226static kib_tx_t * 222static struct kib_tx *
227kiblnd_find_waiting_tx_locked(kib_conn_t *conn, int txtype, __u64 cookie) 223kiblnd_find_waiting_tx_locked(struct kib_conn *conn, int txtype, __u64 cookie)
228{ 224{
229 struct list_head *tmp; 225 struct list_head *tmp;
230 226
231 list_for_each(tmp, &conn->ibc_active_txs) { 227 list_for_each(tmp, &conn->ibc_active_txs) {
232 kib_tx_t *tx = list_entry(tmp, kib_tx_t, tx_list); 228 struct kib_tx *tx = list_entry(tmp, struct kib_tx, tx_list);
233 229
234 LASSERT(!tx->tx_queued); 230 LASSERT(!tx->tx_queued);
235 LASSERT(tx->tx_sending || tx->tx_waiting); 231 LASSERT(tx->tx_sending || tx->tx_waiting);
@@ -249,9 +245,9 @@ kiblnd_find_waiting_tx_locked(kib_conn_t *conn, int txtype, __u64 cookie)
249} 245}
250 246
251static void 247static void
252kiblnd_handle_completion(kib_conn_t *conn, int txtype, int status, __u64 cookie) 248kiblnd_handle_completion(struct kib_conn *conn, int txtype, int status, __u64 cookie)
253{ 249{
254 kib_tx_t *tx; 250 struct kib_tx *tx;
255 lnet_ni_t *ni = conn->ibc_peer->ibp_ni; 251 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
256 int idle; 252 int idle;
257 253
@@ -287,10 +283,10 @@ kiblnd_handle_completion(kib_conn_t *conn, int txtype, int status, __u64 cookie)
287} 283}
288 284
289static void 285static void
290kiblnd_send_completion(kib_conn_t *conn, int type, int status, __u64 cookie) 286kiblnd_send_completion(struct kib_conn *conn, int type, int status, __u64 cookie)
291{ 287{
292 lnet_ni_t *ni = conn->ibc_peer->ibp_ni; 288 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
293 kib_tx_t *tx = kiblnd_get_idle_tx(ni, conn->ibc_peer->ibp_nid); 289 struct kib_tx *tx = kiblnd_get_idle_tx(ni, conn->ibc_peer->ibp_nid);
294 290
295 if (!tx) { 291 if (!tx) {
296 CERROR("Can't get tx for completion %x for %s\n", 292 CERROR("Can't get tx for completion %x for %s\n",
@@ -300,19 +296,19 @@ kiblnd_send_completion(kib_conn_t *conn, int type, int status, __u64 cookie)
300 296
301 tx->tx_msg->ibm_u.completion.ibcm_status = status; 297 tx->tx_msg->ibm_u.completion.ibcm_status = status;
302 tx->tx_msg->ibm_u.completion.ibcm_cookie = cookie; 298 tx->tx_msg->ibm_u.completion.ibcm_cookie = cookie;
303 kiblnd_init_tx_msg(ni, tx, type, sizeof(kib_completion_msg_t)); 299 kiblnd_init_tx_msg(ni, tx, type, sizeof(struct kib_completion_msg));
304 300
305 kiblnd_queue_tx(tx, conn); 301 kiblnd_queue_tx(tx, conn);
306} 302}
307 303
308static void 304static void
309kiblnd_handle_rx(kib_rx_t *rx) 305kiblnd_handle_rx(struct kib_rx *rx)
310{ 306{
311 kib_msg_t *msg = rx->rx_msg; 307 struct kib_msg *msg = rx->rx_msg;
312 kib_conn_t *conn = rx->rx_conn; 308 struct kib_conn *conn = rx->rx_conn;
313 lnet_ni_t *ni = conn->ibc_peer->ibp_ni; 309 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
314 int credits = msg->ibm_credits; 310 int credits = msg->ibm_credits;
315 kib_tx_t *tx; 311 struct kib_tx *tx;
316 int rc = 0; 312 int rc = 0;
317 int rc2; 313 int rc2;
318 int post_credit; 314 int post_credit;
@@ -467,12 +463,12 @@ kiblnd_handle_rx(kib_rx_t *rx)
467} 463}
468 464
469static void 465static void
470kiblnd_rx_complete(kib_rx_t *rx, int status, int nob) 466kiblnd_rx_complete(struct kib_rx *rx, int status, int nob)
471{ 467{
472 kib_msg_t *msg = rx->rx_msg; 468 struct kib_msg *msg = rx->rx_msg;
473 kib_conn_t *conn = rx->rx_conn; 469 struct kib_conn *conn = rx->rx_conn;
474 lnet_ni_t *ni = conn->ibc_peer->ibp_ni; 470 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
475 kib_net_t *net = ni->ni_data; 471 struct kib_net *net = ni->ni_data;
476 int rc; 472 int rc;
477 int err = -EIO; 473 int err = -EIO;
478 474
@@ -561,10 +557,10 @@ kiblnd_kvaddr_to_page(unsigned long vaddr)
561} 557}
562 558
563static int 559static int
564kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, __u32 nob) 560kiblnd_fmr_map_tx(struct kib_net *net, struct kib_tx *tx, struct kib_rdma_desc *rd, __u32 nob)
565{ 561{
566 kib_hca_dev_t *hdev; 562 struct kib_hca_dev *hdev;
567 kib_fmr_poolset_t *fps; 563 struct kib_fmr_poolset *fps;
568 int cpt; 564 int cpt;
569 int rc; 565 int rc;
570 566
@@ -593,9 +589,9 @@ kiblnd_fmr_map_tx(kib_net_t *net, kib_tx_t *tx, kib_rdma_desc_t *rd, __u32 nob)
593 return 0; 589 return 0;
594} 590}
595 591
596static void kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx) 592static void kiblnd_unmap_tx(lnet_ni_t *ni, struct kib_tx *tx)
597{ 593{
598 kib_net_t *net = ni->ni_data; 594 struct kib_net *net = ni->ni_data;
599 595
600 LASSERT(net); 596 LASSERT(net);
601 597
@@ -609,11 +605,11 @@ static void kiblnd_unmap_tx(lnet_ni_t *ni, kib_tx_t *tx)
609 } 605 }
610} 606}
611 607
612static int kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd, 608static int kiblnd_map_tx(lnet_ni_t *ni, struct kib_tx *tx, struct kib_rdma_desc *rd,
613 int nfrags) 609 int nfrags)
614{ 610{
615 kib_net_t *net = ni->ni_data; 611 struct kib_net *net = ni->ni_data;
616 kib_hca_dev_t *hdev = net->ibn_dev->ibd_hdev; 612 struct kib_hca_dev *hdev = net->ibn_dev->ibd_hdev;
617 struct ib_mr *mr = NULL; 613 struct ib_mr *mr = NULL;
618 __u32 nob; 614 __u32 nob;
619 int i; 615 int i;
@@ -651,10 +647,10 @@ static int kiblnd_map_tx(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
651} 647}
652 648
653static int 649static int
654kiblnd_setup_rd_iov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd, 650kiblnd_setup_rd_iov(lnet_ni_t *ni, struct kib_tx *tx, struct kib_rdma_desc *rd,
655 unsigned int niov, struct kvec *iov, int offset, int nob) 651 unsigned int niov, struct kvec *iov, int offset, int nob)
656{ 652{
657 kib_net_t *net = ni->ni_data; 653 struct kib_net *net = ni->ni_data;
658 struct page *page; 654 struct page *page;
659 struct scatterlist *sg; 655 struct scatterlist *sg;
660 unsigned long vaddr; 656 unsigned long vaddr;
@@ -689,6 +685,10 @@ kiblnd_setup_rd_iov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
689 685
690 sg_set_page(sg, page, fragnob, page_offset); 686 sg_set_page(sg, page, fragnob, page_offset);
691 sg = sg_next(sg); 687 sg = sg_next(sg);
688 if (!sg) {
689 CERROR("lacking enough sg entries to map tx\n");
690 return -EFAULT;
691 }
692 692
693 if (offset + fragnob < iov->iov_len) { 693 if (offset + fragnob < iov->iov_len) {
694 offset += fragnob; 694 offset += fragnob;
@@ -704,10 +704,10 @@ kiblnd_setup_rd_iov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
704} 704}
705 705
706static int 706static int
707kiblnd_setup_rd_kiov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd, 707kiblnd_setup_rd_kiov(lnet_ni_t *ni, struct kib_tx *tx, struct kib_rdma_desc *rd,
708 int nkiov, lnet_kiov_t *kiov, int offset, int nob) 708 int nkiov, lnet_kiov_t *kiov, int offset, int nob)
709{ 709{
710 kib_net_t *net = ni->ni_data; 710 struct kib_net *net = ni->ni_data;
711 struct scatterlist *sg; 711 struct scatterlist *sg;
712 int fragnob; 712 int fragnob;
713 713
@@ -733,6 +733,10 @@ kiblnd_setup_rd_kiov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
733 sg_set_page(sg, kiov->kiov_page, fragnob, 733 sg_set_page(sg, kiov->kiov_page, fragnob,
734 kiov->kiov_offset + offset); 734 kiov->kiov_offset + offset);
735 sg = sg_next(sg); 735 sg = sg_next(sg);
736 if (!sg) {
737 CERROR("lacking enough sg entries to map tx\n");
738 return -EFAULT;
739 }
736 740
737 offset = 0; 741 offset = 0;
738 kiov++; 742 kiov++;
@@ -744,11 +748,11 @@ kiblnd_setup_rd_kiov(lnet_ni_t *ni, kib_tx_t *tx, kib_rdma_desc_t *rd,
744} 748}
745 749
746static int 750static int
747kiblnd_post_tx_locked(kib_conn_t *conn, kib_tx_t *tx, int credit) 751kiblnd_post_tx_locked(struct kib_conn *conn, struct kib_tx *tx, int credit)
748 __must_hold(&conn->ibc_lock) 752 __must_hold(&conn->ibc_lock)
749{ 753{
750 kib_msg_t *msg = tx->tx_msg; 754 struct kib_msg *msg = tx->tx_msg;
751 kib_peer_t *peer = conn->ibc_peer; 755 struct kib_peer *peer = conn->ibc_peer;
752 struct lnet_ni *ni = peer->ibp_ni; 756 struct lnet_ni *ni = peer->ibp_ni;
753 int ver = conn->ibc_version; 757 int ver = conn->ibc_version;
754 int rc; 758 int rc;
@@ -901,11 +905,11 @@ kiblnd_post_tx_locked(kib_conn_t *conn, kib_tx_t *tx, int credit)
901} 905}
902 906
903static void 907static void
904kiblnd_check_sends(kib_conn_t *conn) 908kiblnd_check_sends(struct kib_conn *conn)
905{ 909{
906 int ver = conn->ibc_version; 910 int ver = conn->ibc_version;
907 lnet_ni_t *ni = conn->ibc_peer->ibp_ni; 911 lnet_ni_t *ni = conn->ibc_peer->ibp_ni;
908 kib_tx_t *tx; 912 struct kib_tx *tx;
909 913
910 /* Don't send anything until after the connection is established */ 914 /* Don't send anything until after the connection is established */
911 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) { 915 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) {
@@ -924,7 +928,7 @@ kiblnd_check_sends(kib_conn_t *conn)
924 while (conn->ibc_reserved_credits > 0 && 928 while (conn->ibc_reserved_credits > 0 &&
925 !list_empty(&conn->ibc_tx_queue_rsrvd)) { 929 !list_empty(&conn->ibc_tx_queue_rsrvd)) {
926 tx = list_entry(conn->ibc_tx_queue_rsrvd.next, 930 tx = list_entry(conn->ibc_tx_queue_rsrvd.next,
927 kib_tx_t, tx_list); 931 struct kib_tx, tx_list);
928 list_del(&tx->tx_list); 932 list_del(&tx->tx_list);
929 list_add_tail(&tx->tx_list, &conn->ibc_tx_queue); 933 list_add_tail(&tx->tx_list, &conn->ibc_tx_queue);
930 conn->ibc_reserved_credits--; 934 conn->ibc_reserved_credits--;
@@ -948,16 +952,16 @@ kiblnd_check_sends(kib_conn_t *conn)
948 if (!list_empty(&conn->ibc_tx_queue_nocred)) { 952 if (!list_empty(&conn->ibc_tx_queue_nocred)) {
949 credit = 0; 953 credit = 0;
950 tx = list_entry(conn->ibc_tx_queue_nocred.next, 954 tx = list_entry(conn->ibc_tx_queue_nocred.next,
951 kib_tx_t, tx_list); 955 struct kib_tx, tx_list);
952 } else if (!list_empty(&conn->ibc_tx_noops)) { 956 } else if (!list_empty(&conn->ibc_tx_noops)) {
953 LASSERT(!IBLND_OOB_CAPABLE(ver)); 957 LASSERT(!IBLND_OOB_CAPABLE(ver));
954 credit = 1; 958 credit = 1;
955 tx = list_entry(conn->ibc_tx_noops.next, 959 tx = list_entry(conn->ibc_tx_noops.next,
956 kib_tx_t, tx_list); 960 struct kib_tx, tx_list);
957 } else if (!list_empty(&conn->ibc_tx_queue)) { 961 } else if (!list_empty(&conn->ibc_tx_queue)) {
958 credit = 1; 962 credit = 1;
959 tx = list_entry(conn->ibc_tx_queue.next, 963 tx = list_entry(conn->ibc_tx_queue.next,
960 kib_tx_t, tx_list); 964 struct kib_tx, tx_list);
961 } else { 965 } else {
962 break; 966 break;
963 } 967 }
@@ -970,10 +974,10 @@ kiblnd_check_sends(kib_conn_t *conn)
970} 974}
971 975
972static void 976static void
973kiblnd_tx_complete(kib_tx_t *tx, int status) 977kiblnd_tx_complete(struct kib_tx *tx, int status)
974{ 978{
975 int failed = (status != IB_WC_SUCCESS); 979 int failed = (status != IB_WC_SUCCESS);
976 kib_conn_t *conn = tx->tx_conn; 980 struct kib_conn *conn = tx->tx_conn;
977 int idle; 981 int idle;
978 982
979 LASSERT(tx->tx_sending > 0); 983 LASSERT(tx->tx_sending > 0);
@@ -1025,12 +1029,12 @@ kiblnd_tx_complete(kib_tx_t *tx, int status)
1025} 1029}
1026 1030
1027static void 1031static void
1028kiblnd_init_tx_msg(lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob) 1032kiblnd_init_tx_msg(lnet_ni_t *ni, struct kib_tx *tx, int type, int body_nob)
1029{ 1033{
1030 kib_hca_dev_t *hdev = tx->tx_pool->tpo_hdev; 1034 struct kib_hca_dev *hdev = tx->tx_pool->tpo_hdev;
1031 struct ib_sge *sge = &tx->tx_sge[tx->tx_nwrq]; 1035 struct ib_sge *sge = &tx->tx_sge[tx->tx_nwrq];
1032 struct ib_rdma_wr *wrq = &tx->tx_wrq[tx->tx_nwrq]; 1036 struct ib_rdma_wr *wrq = &tx->tx_wrq[tx->tx_nwrq];
1033 int nob = offsetof(kib_msg_t, ibm_u) + body_nob; 1037 int nob = offsetof(struct kib_msg, ibm_u) + body_nob;
1034 struct ib_mr *mr = hdev->ibh_mrs; 1038 struct ib_mr *mr = hdev->ibh_mrs;
1035 1039
1036 LASSERT(tx->tx_nwrq >= 0); 1040 LASSERT(tx->tx_nwrq >= 0);
@@ -1057,11 +1061,11 @@ kiblnd_init_tx_msg(lnet_ni_t *ni, kib_tx_t *tx, int type, int body_nob)
1057} 1061}
1058 1062
1059static int 1063static int
1060kiblnd_init_rdma(kib_conn_t *conn, kib_tx_t *tx, int type, 1064kiblnd_init_rdma(struct kib_conn *conn, struct kib_tx *tx, int type,
1061 int resid, kib_rdma_desc_t *dstrd, __u64 dstcookie) 1065 int resid, struct kib_rdma_desc *dstrd, __u64 dstcookie)
1062{ 1066{
1063 kib_msg_t *ibmsg = tx->tx_msg; 1067 struct kib_msg *ibmsg = tx->tx_msg;
1064 kib_rdma_desc_t *srcrd = tx->tx_rd; 1068 struct kib_rdma_desc *srcrd = tx->tx_rd;
1065 struct ib_sge *sge = &tx->tx_sge[0]; 1069 struct ib_sge *sge = &tx->tx_sge[0];
1066 struct ib_rdma_wr *wrq, *next; 1070 struct ib_rdma_wr *wrq, *next;
1067 int rc = resid; 1071 int rc = resid;
@@ -1099,7 +1103,7 @@ kiblnd_init_rdma(kib_conn_t *conn, kib_tx_t *tx, int type,
1099 1103
1100 wrknob = min(min(kiblnd_rd_frag_size(srcrd, srcidx), 1104 wrknob = min(min(kiblnd_rd_frag_size(srcrd, srcidx),
1101 kiblnd_rd_frag_size(dstrd, dstidx)), 1105 kiblnd_rd_frag_size(dstrd, dstidx)),
1102 (__u32) resid); 1106 (__u32)resid);
1103 1107
1104 sge = &tx->tx_sge[tx->tx_nwrq]; 1108 sge = &tx->tx_sge[tx->tx_nwrq];
1105 sge->addr = kiblnd_rd_frag_addr(srcrd, srcidx); 1109 sge->addr = kiblnd_rd_frag_addr(srcrd, srcidx);
@@ -1135,13 +1139,13 @@ kiblnd_init_rdma(kib_conn_t *conn, kib_tx_t *tx, int type,
1135 ibmsg->ibm_u.completion.ibcm_status = rc; 1139 ibmsg->ibm_u.completion.ibcm_status = rc;
1136 ibmsg->ibm_u.completion.ibcm_cookie = dstcookie; 1140 ibmsg->ibm_u.completion.ibcm_cookie = dstcookie;
1137 kiblnd_init_tx_msg(conn->ibc_peer->ibp_ni, tx, 1141 kiblnd_init_tx_msg(conn->ibc_peer->ibp_ni, tx,
1138 type, sizeof(kib_completion_msg_t)); 1142 type, sizeof(struct kib_completion_msg));
1139 1143
1140 return rc; 1144 return rc;
1141} 1145}
1142 1146
1143static void 1147static void
1144kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn) 1148kiblnd_queue_tx_locked(struct kib_tx *tx, struct kib_conn *conn)
1145{ 1149{
1146 struct list_head *q; 1150 struct list_head *q;
1147 1151
@@ -1196,7 +1200,7 @@ kiblnd_queue_tx_locked(kib_tx_t *tx, kib_conn_t *conn)
1196} 1200}
1197 1201
1198static void 1202static void
1199kiblnd_queue_tx(kib_tx_t *tx, kib_conn_t *conn) 1203kiblnd_queue_tx(struct kib_tx *tx, struct kib_conn *conn)
1200{ 1204{
1201 spin_lock(&conn->ibc_lock); 1205 spin_lock(&conn->ibc_lock);
1202 kiblnd_queue_tx_locked(tx, conn); 1206 kiblnd_queue_tx_locked(tx, conn);
@@ -1243,11 +1247,11 @@ static int kiblnd_resolve_addr(struct rdma_cm_id *cmid,
1243} 1247}
1244 1248
1245static void 1249static void
1246kiblnd_connect_peer(kib_peer_t *peer) 1250kiblnd_connect_peer(struct kib_peer *peer)
1247{ 1251{
1248 struct rdma_cm_id *cmid; 1252 struct rdma_cm_id *cmid;
1249 kib_dev_t *dev; 1253 struct kib_dev *dev;
1250 kib_net_t *net = peer->ibp_ni->ni_data; 1254 struct kib_net *net = peer->ibp_ni->ni_data;
1251 struct sockaddr_in srcaddr; 1255 struct sockaddr_in srcaddr;
1252 struct sockaddr_in dstaddr; 1256 struct sockaddr_in dstaddr;
1253 int rc; 1257 int rc;
@@ -1311,7 +1315,7 @@ kiblnd_connect_peer(kib_peer_t *peer)
1311} 1315}
1312 1316
1313bool 1317bool
1314kiblnd_reconnect_peer(kib_peer_t *peer) 1318kiblnd_reconnect_peer(struct kib_peer *peer)
1315{ 1319{
1316 rwlock_t *glock = &kiblnd_data.kib_global_lock; 1320 rwlock_t *glock = &kiblnd_data.kib_global_lock;
1317 char *reason = NULL; 1321 char *reason = NULL;
@@ -1361,11 +1365,11 @@ no_reconnect:
1361} 1365}
1362 1366
1363void 1367void
1364kiblnd_launch_tx(lnet_ni_t *ni, kib_tx_t *tx, lnet_nid_t nid) 1368kiblnd_launch_tx(lnet_ni_t *ni, struct kib_tx *tx, lnet_nid_t nid)
1365{ 1369{
1366 kib_peer_t *peer; 1370 struct kib_peer *peer;
1367 kib_peer_t *peer2; 1371 struct kib_peer *peer2;
1368 kib_conn_t *conn; 1372 struct kib_conn *conn;
1369 rwlock_t *g_lock = &kiblnd_data.kib_global_lock; 1373 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
1370 unsigned long flags; 1374 unsigned long flags;
1371 int rc; 1375 int rc;
@@ -1468,7 +1472,7 @@ kiblnd_launch_tx(lnet_ni_t *ni, kib_tx_t *tx, lnet_nid_t nid)
1468 peer->ibp_connecting = 1; 1472 peer->ibp_connecting = 1;
1469 1473
1470 /* always called with a ref on ni, which prevents ni being shutdown */ 1474 /* always called with a ref on ni, which prevents ni being shutdown */
1471 LASSERT(!((kib_net_t *)ni->ni_data)->ibn_shutdown); 1475 LASSERT(!((struct kib_net *)ni->ni_data)->ibn_shutdown);
1472 1476
1473 if (tx) 1477 if (tx)
1474 list_add_tail(&tx->tx_list, &peer->ibp_tx_queue); 1478 list_add_tail(&tx->tx_list, &peer->ibp_tx_queue);
@@ -1495,9 +1499,9 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1495 lnet_kiov_t *payload_kiov = lntmsg->msg_kiov; 1499 lnet_kiov_t *payload_kiov = lntmsg->msg_kiov;
1496 unsigned int payload_offset = lntmsg->msg_offset; 1500 unsigned int payload_offset = lntmsg->msg_offset;
1497 unsigned int payload_nob = lntmsg->msg_len; 1501 unsigned int payload_nob = lntmsg->msg_len;
1498 kib_msg_t *ibmsg; 1502 struct kib_msg *ibmsg;
1499 kib_rdma_desc_t *rd; 1503 struct kib_rdma_desc *rd;
1500 kib_tx_t *tx; 1504 struct kib_tx *tx;
1501 int nob; 1505 int nob;
1502 int rc; 1506 int rc;
1503 1507
@@ -1528,7 +1532,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1528 break; /* send IMMEDIATE */ 1532 break; /* send IMMEDIATE */
1529 1533
1530 /* is the REPLY message too small for RDMA? */ 1534 /* is the REPLY message too small for RDMA? */
1531 nob = offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[lntmsg->msg_md->md_length]); 1535 nob = offsetof(struct kib_msg, ibm_u.immediate.ibim_payload[lntmsg->msg_md->md_length]);
1532 if (nob <= IBLND_MSG_SIZE) 1536 if (nob <= IBLND_MSG_SIZE)
1533 break; /* send IMMEDIATE */ 1537 break; /* send IMMEDIATE */
1534 1538
@@ -1558,7 +1562,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1558 return -EIO; 1562 return -EIO;
1559 } 1563 }
1560 1564
1561 nob = offsetof(kib_get_msg_t, ibgm_rd.rd_frags[rd->rd_nfrags]); 1565 nob = offsetof(struct kib_get_msg, ibgm_rd.rd_frags[rd->rd_nfrags]);
1562 ibmsg->ibm_u.get.ibgm_cookie = tx->tx_cookie; 1566 ibmsg->ibm_u.get.ibgm_cookie = tx->tx_cookie;
1563 ibmsg->ibm_u.get.ibgm_hdr = *hdr; 1567 ibmsg->ibm_u.get.ibgm_hdr = *hdr;
1564 1568
@@ -1580,7 +1584,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1580 case LNET_MSG_REPLY: 1584 case LNET_MSG_REPLY:
1581 case LNET_MSG_PUT: 1585 case LNET_MSG_PUT:
1582 /* Is the payload small enough not to need RDMA? */ 1586 /* Is the payload small enough not to need RDMA? */
1583 nob = offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[payload_nob]); 1587 nob = offsetof(struct kib_msg, ibm_u.immediate.ibim_payload[payload_nob]);
1584 if (nob <= IBLND_MSG_SIZE) 1588 if (nob <= IBLND_MSG_SIZE)
1585 break; /* send IMMEDIATE */ 1589 break; /* send IMMEDIATE */
1586 1590
@@ -1610,7 +1614,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1610 ibmsg = tx->tx_msg; 1614 ibmsg = tx->tx_msg;
1611 ibmsg->ibm_u.putreq.ibprm_hdr = *hdr; 1615 ibmsg->ibm_u.putreq.ibprm_hdr = *hdr;
1612 ibmsg->ibm_u.putreq.ibprm_cookie = tx->tx_cookie; 1616 ibmsg->ibm_u.putreq.ibprm_cookie = tx->tx_cookie;
1613 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_PUT_REQ, sizeof(kib_putreq_msg_t)); 1617 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_PUT_REQ, sizeof(struct kib_putreq_msg));
1614 1618
1615 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg on completion */ 1619 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg on completion */
1616 tx->tx_waiting = 1; /* waiting for PUT_{ACK,NAK} */ 1620 tx->tx_waiting = 1; /* waiting for PUT_{ACK,NAK} */
@@ -1620,7 +1624,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1620 1624
1621 /* send IMMEDIATE */ 1625 /* send IMMEDIATE */
1622 1626
1623 LASSERT(offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[payload_nob]) 1627 LASSERT(offsetof(struct kib_msg, ibm_u.immediate.ibim_payload[payload_nob])
1624 <= IBLND_MSG_SIZE); 1628 <= IBLND_MSG_SIZE);
1625 1629
1626 tx = kiblnd_get_idle_tx(ni, target.nid); 1630 tx = kiblnd_get_idle_tx(ni, target.nid);
@@ -1635,16 +1639,16 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1635 1639
1636 if (payload_kiov) 1640 if (payload_kiov)
1637 lnet_copy_kiov2flat(IBLND_MSG_SIZE, ibmsg, 1641 lnet_copy_kiov2flat(IBLND_MSG_SIZE, ibmsg,
1638 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload), 1642 offsetof(struct kib_msg, ibm_u.immediate.ibim_payload),
1639 payload_niov, payload_kiov, 1643 payload_niov, payload_kiov,
1640 payload_offset, payload_nob); 1644 payload_offset, payload_nob);
1641 else 1645 else
1642 lnet_copy_iov2flat(IBLND_MSG_SIZE, ibmsg, 1646 lnet_copy_iov2flat(IBLND_MSG_SIZE, ibmsg,
1643 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload), 1647 offsetof(struct kib_msg, ibm_u.immediate.ibim_payload),
1644 payload_niov, payload_iov, 1648 payload_niov, payload_iov,
1645 payload_offset, payload_nob); 1649 payload_offset, payload_nob);
1646 1650
1647 nob = offsetof(kib_immediate_msg_t, ibim_payload[payload_nob]); 1651 nob = offsetof(struct kib_immediate_msg, ibim_payload[payload_nob]);
1648 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_IMMEDIATE, nob); 1652 kiblnd_init_tx_msg(ni, tx, IBLND_MSG_IMMEDIATE, nob);
1649 1653
1650 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg on completion */ 1654 tx->tx_lntmsg[0] = lntmsg; /* finalise lntmsg on completion */
@@ -1653,7 +1657,7 @@ kiblnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
1653} 1657}
1654 1658
1655static void 1659static void
1656kiblnd_reply(lnet_ni_t *ni, kib_rx_t *rx, lnet_msg_t *lntmsg) 1660kiblnd_reply(lnet_ni_t *ni, struct kib_rx *rx, lnet_msg_t *lntmsg)
1657{ 1661{
1658 lnet_process_id_t target = lntmsg->msg_target; 1662 lnet_process_id_t target = lntmsg->msg_target;
1659 unsigned int niov = lntmsg->msg_niov; 1663 unsigned int niov = lntmsg->msg_niov;
@@ -1661,7 +1665,7 @@ kiblnd_reply(lnet_ni_t *ni, kib_rx_t *rx, lnet_msg_t *lntmsg)
1661 lnet_kiov_t *kiov = lntmsg->msg_kiov; 1665 lnet_kiov_t *kiov = lntmsg->msg_kiov;
1662 unsigned int offset = lntmsg->msg_offset; 1666 unsigned int offset = lntmsg->msg_offset;
1663 unsigned int nob = lntmsg->msg_len; 1667 unsigned int nob = lntmsg->msg_len;
1664 kib_tx_t *tx; 1668 struct kib_tx *tx;
1665 int rc; 1669 int rc;
1666 1670
1667 tx = kiblnd_get_idle_tx(ni, rx->rx_conn->ibc_peer->ibp_nid); 1671 tx = kiblnd_get_idle_tx(ni, rx->rx_conn->ibc_peer->ibp_nid);
@@ -1718,10 +1722,10 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
1718 unsigned int niov, struct kvec *iov, lnet_kiov_t *kiov, 1722 unsigned int niov, struct kvec *iov, lnet_kiov_t *kiov,
1719 unsigned int offset, unsigned int mlen, unsigned int rlen) 1723 unsigned int offset, unsigned int mlen, unsigned int rlen)
1720{ 1724{
1721 kib_rx_t *rx = private; 1725 struct kib_rx *rx = private;
1722 kib_msg_t *rxmsg = rx->rx_msg; 1726 struct kib_msg *rxmsg = rx->rx_msg;
1723 kib_conn_t *conn = rx->rx_conn; 1727 struct kib_conn *conn = rx->rx_conn;
1724 kib_tx_t *tx; 1728 struct kib_tx *tx;
1725 int nob; 1729 int nob;
1726 int post_credit = IBLND_POSTRX_PEER_CREDIT; 1730 int post_credit = IBLND_POSTRX_PEER_CREDIT;
1727 int rc = 0; 1731 int rc = 0;
@@ -1736,7 +1740,7 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
1736 LBUG(); 1740 LBUG();
1737 1741
1738 case IBLND_MSG_IMMEDIATE: 1742 case IBLND_MSG_IMMEDIATE:
1739 nob = offsetof(kib_msg_t, ibm_u.immediate.ibim_payload[rlen]); 1743 nob = offsetof(struct kib_msg, ibm_u.immediate.ibim_payload[rlen]);
1740 if (nob > rx->rx_nob) { 1744 if (nob > rx->rx_nob) {
1741 CERROR("Immediate message from %s too big: %d(%d)\n", 1745 CERROR("Immediate message from %s too big: %d(%d)\n",
1742 libcfs_nid2str(rxmsg->ibm_u.immediate.ibim_hdr.src_nid), 1746 libcfs_nid2str(rxmsg->ibm_u.immediate.ibim_hdr.src_nid),
@@ -1748,19 +1752,19 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
1748 if (kiov) 1752 if (kiov)
1749 lnet_copy_flat2kiov(niov, kiov, offset, 1753 lnet_copy_flat2kiov(niov, kiov, offset,
1750 IBLND_MSG_SIZE, rxmsg, 1754 IBLND_MSG_SIZE, rxmsg,
1751 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload), 1755 offsetof(struct kib_msg, ibm_u.immediate.ibim_payload),
1752 mlen); 1756 mlen);
1753 else 1757 else
1754 lnet_copy_flat2iov(niov, iov, offset, 1758 lnet_copy_flat2iov(niov, iov, offset,
1755 IBLND_MSG_SIZE, rxmsg, 1759 IBLND_MSG_SIZE, rxmsg,
1756 offsetof(kib_msg_t, ibm_u.immediate.ibim_payload), 1760 offsetof(struct kib_msg, ibm_u.immediate.ibim_payload),
1757 mlen); 1761 mlen);
1758 lnet_finalize(ni, lntmsg, 0); 1762 lnet_finalize(ni, lntmsg, 0);
1759 break; 1763 break;
1760 1764
1761 case IBLND_MSG_PUT_REQ: { 1765 case IBLND_MSG_PUT_REQ: {
1762 kib_msg_t *txmsg; 1766 struct kib_msg *txmsg;
1763 kib_rdma_desc_t *rd; 1767 struct kib_rdma_desc *rd;
1764 1768
1765 if (!mlen) { 1769 if (!mlen) {
1766 lnet_finalize(ni, lntmsg, 0); 1770 lnet_finalize(ni, lntmsg, 0);
@@ -1796,7 +1800,7 @@ kiblnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, int delayed,
1796 break; 1800 break;
1797 } 1801 }
1798 1802
1799 nob = offsetof(kib_putack_msg_t, ibpam_rd.rd_frags[rd->rd_nfrags]); 1803 nob = offsetof(struct kib_putack_msg, ibpam_rd.rd_frags[rd->rd_nfrags]);
1800 txmsg->ibm_u.putack.ibpam_src_cookie = rxmsg->ibm_u.putreq.ibprm_cookie; 1804 txmsg->ibm_u.putack.ibpam_src_cookie = rxmsg->ibm_u.putreq.ibprm_cookie;
1801 txmsg->ibm_u.putack.ibpam_dst_cookie = tx->tx_cookie; 1805 txmsg->ibm_u.putack.ibpam_dst_cookie = tx->tx_cookie;
1802 1806
@@ -1847,7 +1851,7 @@ kiblnd_thread_fini(void)
1847} 1851}
1848 1852
1849static void 1853static void
1850kiblnd_peer_alive(kib_peer_t *peer) 1854kiblnd_peer_alive(struct kib_peer *peer)
1851{ 1855{
1852 /* This is racy, but everyone's only writing cfs_time_current() */ 1856 /* This is racy, but everyone's only writing cfs_time_current() */
1853 peer->ibp_last_alive = cfs_time_current(); 1857 peer->ibp_last_alive = cfs_time_current();
@@ -1855,7 +1859,7 @@ kiblnd_peer_alive(kib_peer_t *peer)
1855} 1859}
1856 1860
1857static void 1861static void
1858kiblnd_peer_notify(kib_peer_t *peer) 1862kiblnd_peer_notify(struct kib_peer *peer)
1859{ 1863{
1860 int error = 0; 1864 int error = 0;
1861 unsigned long last_alive = 0; 1865 unsigned long last_alive = 0;
@@ -1878,7 +1882,7 @@ kiblnd_peer_notify(kib_peer_t *peer)
1878} 1882}
1879 1883
1880void 1884void
1881kiblnd_close_conn_locked(kib_conn_t *conn, int error) 1885kiblnd_close_conn_locked(struct kib_conn *conn, int error)
1882{ 1886{
1883 /* 1887 /*
1884 * This just does the immediate housekeeping. 'error' is zero for a 1888 * This just does the immediate housekeeping. 'error' is zero for a
@@ -1888,8 +1892,8 @@ kiblnd_close_conn_locked(kib_conn_t *conn, int error)
1888 * already dealing with it (either to set it up or tear it down). 1892 * already dealing with it (either to set it up or tear it down).
1889 * Caller holds kib_global_lock exclusively in irq context 1893 * Caller holds kib_global_lock exclusively in irq context
1890 */ 1894 */
1891 kib_peer_t *peer = conn->ibc_peer; 1895 struct kib_peer *peer = conn->ibc_peer;
1892 kib_dev_t *dev; 1896 struct kib_dev *dev;
1893 unsigned long flags; 1897 unsigned long flags;
1894 1898
1895 LASSERT(error || conn->ibc_state >= IBLND_CONN_ESTABLISHED); 1899 LASSERT(error || conn->ibc_state >= IBLND_CONN_ESTABLISHED);
@@ -1918,7 +1922,7 @@ kiblnd_close_conn_locked(kib_conn_t *conn, int error)
1918 list_empty(&conn->ibc_active_txs) ? "" : "(waiting)"); 1922 list_empty(&conn->ibc_active_txs) ? "" : "(waiting)");
1919 } 1923 }
1920 1924
1921 dev = ((kib_net_t *)peer->ibp_ni->ni_data)->ibn_dev; 1925 dev = ((struct kib_net *)peer->ibp_ni->ni_data)->ibn_dev;
1922 list_del(&conn->ibc_list); 1926 list_del(&conn->ibc_list);
1923 /* connd (see below) takes over ibc_list's ref */ 1927 /* connd (see below) takes over ibc_list's ref */
1924 1928
@@ -1948,7 +1952,7 @@ kiblnd_close_conn_locked(kib_conn_t *conn, int error)
1948} 1952}
1949 1953
1950void 1954void
1951kiblnd_close_conn(kib_conn_t *conn, int error) 1955kiblnd_close_conn(struct kib_conn *conn, int error)
1952{ 1956{
1953 unsigned long flags; 1957 unsigned long flags;
1954 1958
@@ -1960,11 +1964,11 @@ kiblnd_close_conn(kib_conn_t *conn, int error)
1960} 1964}
1961 1965
1962static void 1966static void
1963kiblnd_handle_early_rxs(kib_conn_t *conn) 1967kiblnd_handle_early_rxs(struct kib_conn *conn)
1964{ 1968{
1965 unsigned long flags; 1969 unsigned long flags;
1966 kib_rx_t *rx; 1970 struct kib_rx *rx;
1967 kib_rx_t *tmp; 1971 struct kib_rx *tmp;
1968 1972
1969 LASSERT(!in_interrupt()); 1973 LASSERT(!in_interrupt());
1970 LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED); 1974 LASSERT(conn->ibc_state >= IBLND_CONN_ESTABLISHED);
@@ -1982,17 +1986,17 @@ kiblnd_handle_early_rxs(kib_conn_t *conn)
1982} 1986}
1983 1987
1984static void 1988static void
1985kiblnd_abort_txs(kib_conn_t *conn, struct list_head *txs) 1989kiblnd_abort_txs(struct kib_conn *conn, struct list_head *txs)
1986{ 1990{
1987 LIST_HEAD(zombies); 1991 LIST_HEAD(zombies);
1988 struct list_head *tmp; 1992 struct list_head *tmp;
1989 struct list_head *nxt; 1993 struct list_head *nxt;
1990 kib_tx_t *tx; 1994 struct kib_tx *tx;
1991 1995
1992 spin_lock(&conn->ibc_lock); 1996 spin_lock(&conn->ibc_lock);
1993 1997
1994 list_for_each_safe(tmp, nxt, txs) { 1998 list_for_each_safe(tmp, nxt, txs) {
1995 tx = list_entry(tmp, kib_tx_t, tx_list); 1999 tx = list_entry(tmp, struct kib_tx, tx_list);
1996 2000
1997 if (txs == &conn->ibc_active_txs) { 2001 if (txs == &conn->ibc_active_txs) {
1998 LASSERT(!tx->tx_queued); 2002 LASSERT(!tx->tx_queued);
@@ -2017,7 +2021,7 @@ kiblnd_abort_txs(kib_conn_t *conn, struct list_head *txs)
2017} 2021}
2018 2022
2019static void 2023static void
2020kiblnd_finalise_conn(kib_conn_t *conn) 2024kiblnd_finalise_conn(struct kib_conn *conn)
2021{ 2025{
2022 LASSERT(!in_interrupt()); 2026 LASSERT(!in_interrupt());
2023 LASSERT(conn->ibc_state > IBLND_CONN_INIT); 2027 LASSERT(conn->ibc_state > IBLND_CONN_INIT);
@@ -2045,7 +2049,7 @@ kiblnd_finalise_conn(kib_conn_t *conn)
2045} 2049}
2046 2050
2047static void 2051static void
2048kiblnd_peer_connect_failed(kib_peer_t *peer, int active, int error) 2052kiblnd_peer_connect_failed(struct kib_peer *peer, int active, int error)
2049{ 2053{
2050 LIST_HEAD(zombies); 2054 LIST_HEAD(zombies);
2051 unsigned long flags; 2055 unsigned long flags;
@@ -2099,11 +2103,11 @@ kiblnd_peer_connect_failed(kib_peer_t *peer, int active, int error)
2099} 2103}
2100 2104
2101static void 2105static void
2102kiblnd_connreq_done(kib_conn_t *conn, int status) 2106kiblnd_connreq_done(struct kib_conn *conn, int status)
2103{ 2107{
2104 kib_peer_t *peer = conn->ibc_peer; 2108 struct kib_peer *peer = conn->ibc_peer;
2105 kib_tx_t *tx; 2109 struct kib_tx *tx;
2106 kib_tx_t *tmp; 2110 struct kib_tx *tmp;
2107 struct list_head txs; 2111 struct list_head txs;
2108 unsigned long flags; 2112 unsigned long flags;
2109 int active; 2113 int active;
@@ -2209,7 +2213,7 @@ kiblnd_connreq_done(kib_conn_t *conn, int status)
2209} 2213}
2210 2214
2211static void 2215static void
2212kiblnd_reject(struct rdma_cm_id *cmid, kib_rej_t *rej) 2216kiblnd_reject(struct rdma_cm_id *cmid, struct kib_rej *rej)
2213{ 2217{
2214 int rc; 2218 int rc;
2215 2219
@@ -2223,17 +2227,17 @@ static int
2223kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob) 2227kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
2224{ 2228{
2225 rwlock_t *g_lock = &kiblnd_data.kib_global_lock; 2229 rwlock_t *g_lock = &kiblnd_data.kib_global_lock;
2226 kib_msg_t *reqmsg = priv; 2230 struct kib_msg *reqmsg = priv;
2227 kib_msg_t *ackmsg; 2231 struct kib_msg *ackmsg;
2228 kib_dev_t *ibdev; 2232 struct kib_dev *ibdev;
2229 kib_peer_t *peer; 2233 struct kib_peer *peer;
2230 kib_peer_t *peer2; 2234 struct kib_peer *peer2;
2231 kib_conn_t *conn; 2235 struct kib_conn *conn;
2232 lnet_ni_t *ni = NULL; 2236 lnet_ni_t *ni = NULL;
2233 kib_net_t *net = NULL; 2237 struct kib_net *net = NULL;
2234 lnet_nid_t nid; 2238 lnet_nid_t nid;
2235 struct rdma_conn_param cp; 2239 struct rdma_conn_param cp;
2236 kib_rej_t rej; 2240 struct kib_rej rej;
2237 int version = IBLND_MSG_VERSION; 2241 int version = IBLND_MSG_VERSION;
2238 unsigned long flags; 2242 unsigned long flags;
2239 int rc; 2243 int rc;
@@ -2242,7 +2246,7 @@ kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
2242 LASSERT(!in_interrupt()); 2246 LASSERT(!in_interrupt());
2243 2247
2244 /* cmid inherits 'context' from the corresponding listener id */ 2248 /* cmid inherits 'context' from the corresponding listener id */
2245 ibdev = (kib_dev_t *)cmid->context; 2249 ibdev = (struct kib_dev *)cmid->context;
2246 LASSERT(ibdev); 2250 LASSERT(ibdev);
2247 2251
2248 memset(&rej, 0, sizeof(rej)); 2252 memset(&rej, 0, sizeof(rej));
@@ -2260,7 +2264,7 @@ kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
2260 goto failed; 2264 goto failed;
2261 } 2265 }
2262 2266
2263 if (priv_nob < offsetof(kib_msg_t, ibm_type)) { 2267 if (priv_nob < offsetof(struct kib_msg, ibm_type)) {
2264 CERROR("Short connection request\n"); 2268 CERROR("Short connection request\n");
2265 goto failed; 2269 goto failed;
2266 } 2270 }
@@ -2295,7 +2299,7 @@ kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
2295 ni = lnet_net2ni(LNET_NIDNET(reqmsg->ibm_dstnid)); 2299 ni = lnet_net2ni(LNET_NIDNET(reqmsg->ibm_dstnid));
2296 2300
2297 if (ni) { 2301 if (ni) {
2298 net = (kib_net_t *)ni->ni_data; 2302 net = (struct kib_net *)ni->ni_data;
2299 rej.ibr_incarnation = net->ibn_incarnation; 2303 rej.ibr_incarnation = net->ibn_incarnation;
2300 } 2304 }
2301 2305
@@ -2534,11 +2538,11 @@ kiblnd_passive_connect(struct rdma_cm_id *cmid, void *priv, int priv_nob)
2534} 2538}
2535 2539
2536static void 2540static void
2537kiblnd_check_reconnect(kib_conn_t *conn, int version, 2541kiblnd_check_reconnect(struct kib_conn *conn, int version,
2538 __u64 incarnation, int why, kib_connparams_t *cp) 2542 __u64 incarnation, int why, struct kib_connparams *cp)
2539{ 2543{
2540 rwlock_t *glock = &kiblnd_data.kib_global_lock; 2544 rwlock_t *glock = &kiblnd_data.kib_global_lock;
2541 kib_peer_t *peer = conn->ibc_peer; 2545 struct kib_peer *peer = conn->ibc_peer;
2542 char *reason; 2546 char *reason;
2543 int msg_size = IBLND_MSG_SIZE; 2547 int msg_size = IBLND_MSG_SIZE;
2544 int frag_num = -1; 2548 int frag_num = -1;
@@ -2647,9 +2651,9 @@ out:
2647} 2651}
2648 2652
2649static void 2653static void
2650kiblnd_rejected(kib_conn_t *conn, int reason, void *priv, int priv_nob) 2654kiblnd_rejected(struct kib_conn *conn, int reason, void *priv, int priv_nob)
2651{ 2655{
2652 kib_peer_t *peer = conn->ibc_peer; 2656 struct kib_peer *peer = conn->ibc_peer;
2653 2657
2654 LASSERT(!in_interrupt()); 2658 LASSERT(!in_interrupt());
2655 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT); 2659 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT);
@@ -2667,9 +2671,9 @@ kiblnd_rejected(kib_conn_t *conn, int reason, void *priv, int priv_nob)
2667 break; 2671 break;
2668 2672
2669 case IB_CM_REJ_CONSUMER_DEFINED: 2673 case IB_CM_REJ_CONSUMER_DEFINED:
2670 if (priv_nob >= offsetof(kib_rej_t, ibr_padding)) { 2674 if (priv_nob >= offsetof(struct kib_rej, ibr_padding)) {
2671 kib_rej_t *rej = priv; 2675 struct kib_rej *rej = priv;
2672 kib_connparams_t *cp = NULL; 2676 struct kib_connparams *cp = NULL;
2673 int flip = 0; 2677 int flip = 0;
2674 __u64 incarnation = -1; 2678 __u64 incarnation = -1;
2675 2679
@@ -2692,7 +2696,7 @@ kiblnd_rejected(kib_conn_t *conn, int reason, void *priv, int priv_nob)
2692 flip = 1; 2696 flip = 1;
2693 } 2697 }
2694 2698
2695 if (priv_nob >= sizeof(kib_rej_t) && 2699 if (priv_nob >= sizeof(struct kib_rej) &&
2696 rej->ibr_version > IBLND_MSG_VERSION_1) { 2700 rej->ibr_version > IBLND_MSG_VERSION_1) {
2697 /* 2701 /*
2698 * priv_nob is always 148 in current version 2702 * priv_nob is always 148 in current version
@@ -2775,12 +2779,12 @@ kiblnd_rejected(kib_conn_t *conn, int reason, void *priv, int priv_nob)
2775} 2779}
2776 2780
2777static void 2781static void
2778kiblnd_check_connreply(kib_conn_t *conn, void *priv, int priv_nob) 2782kiblnd_check_connreply(struct kib_conn *conn, void *priv, int priv_nob)
2779{ 2783{
2780 kib_peer_t *peer = conn->ibc_peer; 2784 struct kib_peer *peer = conn->ibc_peer;
2781 lnet_ni_t *ni = peer->ibp_ni; 2785 lnet_ni_t *ni = peer->ibp_ni;
2782 kib_net_t *net = ni->ni_data; 2786 struct kib_net *net = ni->ni_data;
2783 kib_msg_t *msg = priv; 2787 struct kib_msg *msg = priv;
2784 int ver = conn->ibc_version; 2788 int ver = conn->ibc_version;
2785 int rc = kiblnd_unpack_msg(msg, priv_nob); 2789 int rc = kiblnd_unpack_msg(msg, priv_nob);
2786 unsigned long flags; 2790 unsigned long flags;
@@ -2877,9 +2881,9 @@ kiblnd_check_connreply(kib_conn_t *conn, void *priv, int priv_nob)
2877static int 2881static int
2878kiblnd_active_connect(struct rdma_cm_id *cmid) 2882kiblnd_active_connect(struct rdma_cm_id *cmid)
2879{ 2883{
2880 kib_peer_t *peer = (kib_peer_t *)cmid->context; 2884 struct kib_peer *peer = (struct kib_peer *)cmid->context;
2881 kib_conn_t *conn; 2885 struct kib_conn *conn;
2882 kib_msg_t *msg; 2886 struct kib_msg *msg;
2883 struct rdma_conn_param cp; 2887 struct rdma_conn_param cp;
2884 int version; 2888 int version;
2885 __u64 incarnation; 2889 __u64 incarnation;
@@ -2944,8 +2948,8 @@ kiblnd_active_connect(struct rdma_cm_id *cmid)
2944int 2948int
2945kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event) 2949kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
2946{ 2950{
2947 kib_peer_t *peer; 2951 struct kib_peer *peer;
2948 kib_conn_t *conn; 2952 struct kib_conn *conn;
2949 int rc; 2953 int rc;
2950 2954
2951 switch (event->event) { 2955 switch (event->event) {
@@ -2963,7 +2967,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
2963 return rc; 2967 return rc;
2964 2968
2965 case RDMA_CM_EVENT_ADDR_ERROR: 2969 case RDMA_CM_EVENT_ADDR_ERROR:
2966 peer = (kib_peer_t *)cmid->context; 2970 peer = (struct kib_peer *)cmid->context;
2967 CNETERR("%s: ADDR ERROR %d\n", 2971 CNETERR("%s: ADDR ERROR %d\n",
2968 libcfs_nid2str(peer->ibp_nid), event->status); 2972 libcfs_nid2str(peer->ibp_nid), event->status);
2969 kiblnd_peer_connect_failed(peer, 1, -EHOSTUNREACH); 2973 kiblnd_peer_connect_failed(peer, 1, -EHOSTUNREACH);
@@ -2971,7 +2975,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
2971 return -EHOSTUNREACH; /* rc destroys cmid */ 2975 return -EHOSTUNREACH; /* rc destroys cmid */
2972 2976
2973 case RDMA_CM_EVENT_ADDR_RESOLVED: 2977 case RDMA_CM_EVENT_ADDR_RESOLVED:
2974 peer = (kib_peer_t *)cmid->context; 2978 peer = (struct kib_peer *)cmid->context;
2975 2979
2976 CDEBUG(D_NET, "%s Addr resolved: %d\n", 2980 CDEBUG(D_NET, "%s Addr resolved: %d\n",
2977 libcfs_nid2str(peer->ibp_nid), event->status); 2981 libcfs_nid2str(peer->ibp_nid), event->status);
@@ -2994,7 +2998,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
2994 return rc; /* rc destroys cmid */ 2998 return rc; /* rc destroys cmid */
2995 2999
2996 case RDMA_CM_EVENT_ROUTE_ERROR: 3000 case RDMA_CM_EVENT_ROUTE_ERROR:
2997 peer = (kib_peer_t *)cmid->context; 3001 peer = (struct kib_peer *)cmid->context;
2998 CNETERR("%s: ROUTE ERROR %d\n", 3002 CNETERR("%s: ROUTE ERROR %d\n",
2999 libcfs_nid2str(peer->ibp_nid), event->status); 3003 libcfs_nid2str(peer->ibp_nid), event->status);
3000 kiblnd_peer_connect_failed(peer, 1, -EHOSTUNREACH); 3004 kiblnd_peer_connect_failed(peer, 1, -EHOSTUNREACH);
@@ -3002,7 +3006,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
3002 return -EHOSTUNREACH; /* rc destroys cmid */ 3006 return -EHOSTUNREACH; /* rc destroys cmid */
3003 3007
3004 case RDMA_CM_EVENT_ROUTE_RESOLVED: 3008 case RDMA_CM_EVENT_ROUTE_RESOLVED:
3005 peer = (kib_peer_t *)cmid->context; 3009 peer = (struct kib_peer *)cmid->context;
3006 CDEBUG(D_NET, "%s Route resolved: %d\n", 3010 CDEBUG(D_NET, "%s Route resolved: %d\n",
3007 libcfs_nid2str(peer->ibp_nid), event->status); 3011 libcfs_nid2str(peer->ibp_nid), event->status);
3008 3012
@@ -3016,7 +3020,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
3016 return event->status; /* rc destroys cmid */ 3020 return event->status; /* rc destroys cmid */
3017 3021
3018 case RDMA_CM_EVENT_UNREACHABLE: 3022 case RDMA_CM_EVENT_UNREACHABLE:
3019 conn = (kib_conn_t *)cmid->context; 3023 conn = (struct kib_conn *)cmid->context;
3020 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT || 3024 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT ||
3021 conn->ibc_state == IBLND_CONN_PASSIVE_WAIT); 3025 conn->ibc_state == IBLND_CONN_PASSIVE_WAIT);
3022 CNETERR("%s: UNREACHABLE %d\n", 3026 CNETERR("%s: UNREACHABLE %d\n",
@@ -3026,7 +3030,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
3026 return 0; 3030 return 0;
3027 3031
3028 case RDMA_CM_EVENT_CONNECT_ERROR: 3032 case RDMA_CM_EVENT_CONNECT_ERROR:
3029 conn = (kib_conn_t *)cmid->context; 3033 conn = (struct kib_conn *)cmid->context;
3030 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT || 3034 LASSERT(conn->ibc_state == IBLND_CONN_ACTIVE_CONNECT ||
3031 conn->ibc_state == IBLND_CONN_PASSIVE_WAIT); 3035 conn->ibc_state == IBLND_CONN_PASSIVE_WAIT);
3032 CNETERR("%s: CONNECT ERROR %d\n", 3036 CNETERR("%s: CONNECT ERROR %d\n",
@@ -3036,7 +3040,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
3036 return 0; 3040 return 0;
3037 3041
3038 case RDMA_CM_EVENT_REJECTED: 3042 case RDMA_CM_EVENT_REJECTED:
3039 conn = (kib_conn_t *)cmid->context; 3043 conn = (struct kib_conn *)cmid->context;
3040 switch (conn->ibc_state) { 3044 switch (conn->ibc_state) {
3041 default: 3045 default:
3042 LBUG(); 3046 LBUG();
@@ -3058,7 +3062,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
3058 return 0; 3062 return 0;
3059 3063
3060 case RDMA_CM_EVENT_ESTABLISHED: 3064 case RDMA_CM_EVENT_ESTABLISHED:
3061 conn = (kib_conn_t *)cmid->context; 3065 conn = (struct kib_conn *)cmid->context;
3062 switch (conn->ibc_state) { 3066 switch (conn->ibc_state) {
3063 default: 3067 default:
3064 LBUG(); 3068 LBUG();
@@ -3084,7 +3088,7 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
3084 CDEBUG(D_NET, "Ignore TIMEWAIT_EXIT event\n"); 3088 CDEBUG(D_NET, "Ignore TIMEWAIT_EXIT event\n");
3085 return 0; 3089 return 0;
3086 case RDMA_CM_EVENT_DISCONNECTED: 3090 case RDMA_CM_EVENT_DISCONNECTED:
3087 conn = (kib_conn_t *)cmid->context; 3091 conn = (struct kib_conn *)cmid->context;
3088 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) { 3092 if (conn->ibc_state < IBLND_CONN_ESTABLISHED) {
3089 CERROR("%s DISCONNECTED\n", 3093 CERROR("%s DISCONNECTED\n",
3090 libcfs_nid2str(conn->ibc_peer->ibp_nid)); 3094 libcfs_nid2str(conn->ibc_peer->ibp_nid));
@@ -3113,13 +3117,13 @@ kiblnd_cm_callback(struct rdma_cm_id *cmid, struct rdma_cm_event *event)
3113} 3117}
3114 3118
3115static int 3119static int
3116kiblnd_check_txs_locked(kib_conn_t *conn, struct list_head *txs) 3120kiblnd_check_txs_locked(struct kib_conn *conn, struct list_head *txs)
3117{ 3121{
3118 kib_tx_t *tx; 3122 struct kib_tx *tx;
3119 struct list_head *ttmp; 3123 struct list_head *ttmp;
3120 3124
3121 list_for_each(ttmp, txs) { 3125 list_for_each(ttmp, txs) {
3122 tx = list_entry(ttmp, kib_tx_t, tx_list); 3126 tx = list_entry(ttmp, struct kib_tx, tx_list);
3123 3127
3124 if (txs != &conn->ibc_active_txs) { 3128 if (txs != &conn->ibc_active_txs) {
3125 LASSERT(tx->tx_queued); 3129 LASSERT(tx->tx_queued);
@@ -3140,7 +3144,7 @@ kiblnd_check_txs_locked(kib_conn_t *conn, struct list_head *txs)
3140} 3144}
3141 3145
3142static int 3146static int
3143kiblnd_conn_timed_out_locked(kib_conn_t *conn) 3147kiblnd_conn_timed_out_locked(struct kib_conn *conn)
3144{ 3148{
3145 return kiblnd_check_txs_locked(conn, &conn->ibc_tx_queue) || 3149 return kiblnd_check_txs_locked(conn, &conn->ibc_tx_queue) ||
3146 kiblnd_check_txs_locked(conn, &conn->ibc_tx_noops) || 3150 kiblnd_check_txs_locked(conn, &conn->ibc_tx_noops) ||
@@ -3156,10 +3160,10 @@ kiblnd_check_conns(int idx)
3156 LIST_HEAD(checksends); 3160 LIST_HEAD(checksends);
3157 struct list_head *peers = &kiblnd_data.kib_peers[idx]; 3161 struct list_head *peers = &kiblnd_data.kib_peers[idx];
3158 struct list_head *ptmp; 3162 struct list_head *ptmp;
3159 kib_peer_t *peer; 3163 struct kib_peer *peer;
3160 kib_conn_t *conn; 3164 struct kib_conn *conn;
3161 kib_conn_t *temp; 3165 struct kib_conn *temp;
3162 kib_conn_t *tmp; 3166 struct kib_conn *tmp;
3163 struct list_head *ctmp; 3167 struct list_head *ctmp;
3164 unsigned long flags; 3168 unsigned long flags;
3165 3169
@@ -3171,13 +3175,13 @@ kiblnd_check_conns(int idx)
3171 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags); 3175 read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
3172 3176
3173 list_for_each(ptmp, peers) { 3177 list_for_each(ptmp, peers) {
3174 peer = list_entry(ptmp, kib_peer_t, ibp_list); 3178 peer = list_entry(ptmp, struct kib_peer, ibp_list);
3175 3179
3176 list_for_each(ctmp, &peer->ibp_conns) { 3180 list_for_each(ctmp, &peer->ibp_conns) {
3177 int timedout; 3181 int timedout;
3178 int sendnoop; 3182 int sendnoop;
3179 3183
3180 conn = list_entry(ctmp, kib_conn_t, ibc_list); 3184 conn = list_entry(ctmp, struct kib_conn, ibc_list);
3181 3185
3182 LASSERT(conn->ibc_state == IBLND_CONN_ESTABLISHED); 3186 LASSERT(conn->ibc_state == IBLND_CONN_ESTABLISHED);
3183 3187
@@ -3235,7 +3239,7 @@ kiblnd_check_conns(int idx)
3235} 3239}
3236 3240
3237static void 3241static void
3238kiblnd_disconnect_conn(kib_conn_t *conn) 3242kiblnd_disconnect_conn(struct kib_conn *conn)
3239{ 3243{
3240 LASSERT(!in_interrupt()); 3244 LASSERT(!in_interrupt());
3241 LASSERT(current == kiblnd_data.kib_connd); 3245 LASSERT(current == kiblnd_data.kib_connd);
@@ -3264,7 +3268,7 @@ kiblnd_connd(void *arg)
3264 spinlock_t *lock= &kiblnd_data.kib_connd_lock; 3268 spinlock_t *lock= &kiblnd_data.kib_connd_lock;
3265 wait_queue_t wait; 3269 wait_queue_t wait;
3266 unsigned long flags; 3270 unsigned long flags;
3267 kib_conn_t *conn; 3271 struct kib_conn *conn;
3268 int timeout; 3272 int timeout;
3269 int i; 3273 int i;
3270 int dropped_lock; 3274 int dropped_lock;
@@ -3284,10 +3288,10 @@ kiblnd_connd(void *arg)
3284 dropped_lock = 0; 3288 dropped_lock = 0;
3285 3289
3286 if (!list_empty(&kiblnd_data.kib_connd_zombies)) { 3290 if (!list_empty(&kiblnd_data.kib_connd_zombies)) {
3287 kib_peer_t *peer = NULL; 3291 struct kib_peer *peer = NULL;
3288 3292
3289 conn = list_entry(kiblnd_data.kib_connd_zombies.next, 3293 conn = list_entry(kiblnd_data.kib_connd_zombies.next,
3290 kib_conn_t, ibc_list); 3294 struct kib_conn, ibc_list);
3291 list_del(&conn->ibc_list); 3295 list_del(&conn->ibc_list);
3292 if (conn->ibc_reconnect) { 3296 if (conn->ibc_reconnect) {
3293 peer = conn->ibc_peer; 3297 peer = conn->ibc_peer;
@@ -3314,7 +3318,7 @@ kiblnd_connd(void *arg)
3314 3318
3315 if (!list_empty(&kiblnd_data.kib_connd_conns)) { 3319 if (!list_empty(&kiblnd_data.kib_connd_conns)) {
3316 conn = list_entry(kiblnd_data.kib_connd_conns.next, 3320 conn = list_entry(kiblnd_data.kib_connd_conns.next,
3317 kib_conn_t, ibc_list); 3321 struct kib_conn, ibc_list);
3318 list_del(&conn->ibc_list); 3322 list_del(&conn->ibc_list);
3319 3323
3320 spin_unlock_irqrestore(lock, flags); 3324 spin_unlock_irqrestore(lock, flags);
@@ -3338,7 +3342,7 @@ kiblnd_connd(void *arg)
3338 break; 3342 break;
3339 3343
3340 conn = list_entry(kiblnd_data.kib_reconn_list.next, 3344 conn = list_entry(kiblnd_data.kib_reconn_list.next,
3341 kib_conn_t, ibc_list); 3345 struct kib_conn, ibc_list);
3342 list_del(&conn->ibc_list); 3346 list_del(&conn->ibc_list);
3343 3347
3344 spin_unlock_irqrestore(lock, flags); 3348 spin_unlock_irqrestore(lock, flags);
@@ -3409,7 +3413,7 @@ kiblnd_connd(void *arg)
3409void 3413void
3410kiblnd_qp_event(struct ib_event *event, void *arg) 3414kiblnd_qp_event(struct ib_event *event, void *arg)
3411{ 3415{
3412 kib_conn_t *conn = arg; 3416 struct kib_conn *conn = arg;
3413 3417
3414 switch (event->event) { 3418 switch (event->event) {
3415 case IB_EVENT_COMM_EST: 3419 case IB_EVENT_COMM_EST:
@@ -3471,7 +3475,7 @@ kiblnd_cq_completion(struct ib_cq *cq, void *arg)
3471 * occurred. But in this case, !ibc_nrx && !ibc_nsends_posted 3475 * occurred. But in this case, !ibc_nrx && !ibc_nsends_posted
3472 * and this CQ is about to be destroyed so I NOOP. 3476 * and this CQ is about to be destroyed so I NOOP.
3473 */ 3477 */
3474 kib_conn_t *conn = arg; 3478 struct kib_conn *conn = arg;
3475 struct kib_sched_info *sched = conn->ibc_sched; 3479 struct kib_sched_info *sched = conn->ibc_sched;
3476 unsigned long flags; 3480 unsigned long flags;
3477 3481
@@ -3498,7 +3502,7 @@ kiblnd_cq_completion(struct ib_cq *cq, void *arg)
3498void 3502void
3499kiblnd_cq_event(struct ib_event *event, void *arg) 3503kiblnd_cq_event(struct ib_event *event, void *arg)
3500{ 3504{
3501 kib_conn_t *conn = arg; 3505 struct kib_conn *conn = arg;
3502 3506
3503 CERROR("%s: async CQ event type %d\n", 3507 CERROR("%s: async CQ event type %d\n",
3504 libcfs_nid2str(conn->ibc_peer->ibp_nid), event->event); 3508 libcfs_nid2str(conn->ibc_peer->ibp_nid), event->event);
@@ -3509,7 +3513,7 @@ kiblnd_scheduler(void *arg)
3509{ 3513{
3510 long id = (long)arg; 3514 long id = (long)arg;
3511 struct kib_sched_info *sched; 3515 struct kib_sched_info *sched;
3512 kib_conn_t *conn; 3516 struct kib_conn *conn;
3513 wait_queue_t wait; 3517 wait_queue_t wait;
3514 unsigned long flags; 3518 unsigned long flags;
3515 struct ib_wc wc; 3519 struct ib_wc wc;
@@ -3544,7 +3548,7 @@ kiblnd_scheduler(void *arg)
3544 did_something = 0; 3548 did_something = 0;
3545 3549
3546 if (!list_empty(&sched->ibs_conns)) { 3550 if (!list_empty(&sched->ibs_conns)) {
3547 conn = list_entry(sched->ibs_conns.next, kib_conn_t, 3551 conn = list_entry(sched->ibs_conns.next, struct kib_conn,
3548 ibc_sched_list); 3552 ibc_sched_list);
3549 /* take over kib_sched_conns' ref on conn... */ 3553 /* take over kib_sched_conns' ref on conn... */
3550 LASSERT(conn->ibc_scheduled); 3554 LASSERT(conn->ibc_scheduled);
@@ -3644,7 +3648,7 @@ int
3644kiblnd_failover_thread(void *arg) 3648kiblnd_failover_thread(void *arg)
3645{ 3649{
3646 rwlock_t *glock = &kiblnd_data.kib_global_lock; 3650 rwlock_t *glock = &kiblnd_data.kib_global_lock;
3647 kib_dev_t *dev; 3651 struct kib_dev *dev;
3648 wait_queue_t wait; 3652 wait_queue_t wait;
3649 unsigned long flags; 3653 unsigned long flags;
3650 int rc; 3654 int rc;
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
index f8fdd4ae3dbf..44e960f60833 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -145,7 +141,7 @@ static int use_privileged_port = 1;
145module_param(use_privileged_port, int, 0644); 141module_param(use_privileged_port, int, 0644);
146MODULE_PARM_DESC(use_privileged_port, "use privileged port when initiating connection"); 142MODULE_PARM_DESC(use_privileged_port, "use privileged port when initiating connection");
147 143
148kib_tunables_t kiblnd_tunables = { 144struct kib_tunables kiblnd_tunables = {
149 .kib_dev_failover = &dev_failover, 145 .kib_dev_failover = &dev_failover,
150 .kib_service = &service, 146 .kib_service = &service,
151 .kib_cksum = &cksum, 147 .kib_cksum = &cksum,
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
index 406c0e7a57b9..07ec540946cd 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -44,14 +40,14 @@
44#include "socklnd.h" 40#include "socklnd.h"
45 41
46static lnd_t the_ksocklnd; 42static lnd_t the_ksocklnd;
47ksock_nal_data_t ksocknal_data; 43struct ksock_nal_data ksocknal_data;
48 44
49static ksock_interface_t * 45static struct ksock_interface *
50ksocknal_ip2iface(lnet_ni_t *ni, __u32 ip) 46ksocknal_ip2iface(lnet_ni_t *ni, __u32 ip)
51{ 47{
52 ksock_net_t *net = ni->ni_data; 48 struct ksock_net *net = ni->ni_data;
53 int i; 49 int i;
54 ksock_interface_t *iface; 50 struct ksock_interface *iface;
55 51
56 for (i = 0; i < net->ksnn_ninterfaces; i++) { 52 for (i = 0; i < net->ksnn_ninterfaces; i++) {
57 LASSERT(i < LNET_MAX_INTERFACES); 53 LASSERT(i < LNET_MAX_INTERFACES);
@@ -64,10 +60,10 @@ ksocknal_ip2iface(lnet_ni_t *ni, __u32 ip)
64 return NULL; 60 return NULL;
65} 61}
66 62
67static ksock_route_t * 63static struct ksock_route *
68ksocknal_create_route(__u32 ipaddr, int port) 64ksocknal_create_route(__u32 ipaddr, int port)
69{ 65{
70 ksock_route_t *route; 66 struct ksock_route *route;
71 67
72 LIBCFS_ALLOC(route, sizeof(*route)); 68 LIBCFS_ALLOC(route, sizeof(*route));
73 if (!route) 69 if (!route)
@@ -89,7 +85,7 @@ ksocknal_create_route(__u32 ipaddr, int port)
89} 85}
90 86
91void 87void
92ksocknal_destroy_route(ksock_route_t *route) 88ksocknal_destroy_route(struct ksock_route *route)
93{ 89{
94 LASSERT(!atomic_read(&route->ksnr_refcount)); 90 LASSERT(!atomic_read(&route->ksnr_refcount));
95 91
@@ -100,11 +96,11 @@ ksocknal_destroy_route(ksock_route_t *route)
100} 96}
101 97
102static int 98static int
103ksocknal_create_peer(ksock_peer_t **peerp, lnet_ni_t *ni, lnet_process_id_t id) 99ksocknal_create_peer(struct ksock_peer **peerp, lnet_ni_t *ni, lnet_process_id_t id)
104{ 100{
105 int cpt = lnet_cpt_of_nid(id.nid); 101 int cpt = lnet_cpt_of_nid(id.nid);
106 ksock_net_t *net = ni->ni_data; 102 struct ksock_net *net = ni->ni_data;
107 ksock_peer_t *peer; 103 struct ksock_peer *peer;
108 104
109 LASSERT(id.nid != LNET_NID_ANY); 105 LASSERT(id.nid != LNET_NID_ANY);
110 LASSERT(id.pid != LNET_PID_ANY); 106 LASSERT(id.pid != LNET_PID_ANY);
@@ -148,9 +144,9 @@ ksocknal_create_peer(ksock_peer_t **peerp, lnet_ni_t *ni, lnet_process_id_t id)
148} 144}
149 145
150void 146void
151ksocknal_destroy_peer(ksock_peer_t *peer) 147ksocknal_destroy_peer(struct ksock_peer *peer)
152{ 148{
153 ksock_net_t *net = peer->ksnp_ni->ni_data; 149 struct ksock_net *net = peer->ksnp_ni->ni_data;
154 150
155 CDEBUG(D_NET, "peer %s %p deleted\n", 151 CDEBUG(D_NET, "peer %s %p deleted\n",
156 libcfs_id2str(peer->ksnp_id), peer); 152 libcfs_id2str(peer->ksnp_id), peer);
@@ -175,15 +171,15 @@ ksocknal_destroy_peer(ksock_peer_t *peer)
175 spin_unlock_bh(&net->ksnn_lock); 171 spin_unlock_bh(&net->ksnn_lock);
176} 172}
177 173
178ksock_peer_t * 174struct ksock_peer *
179ksocknal_find_peer_locked(lnet_ni_t *ni, lnet_process_id_t id) 175ksocknal_find_peer_locked(lnet_ni_t *ni, lnet_process_id_t id)
180{ 176{
181 struct list_head *peer_list = ksocknal_nid2peerlist(id.nid); 177 struct list_head *peer_list = ksocknal_nid2peerlist(id.nid);
182 struct list_head *tmp; 178 struct list_head *tmp;
183 ksock_peer_t *peer; 179 struct ksock_peer *peer;
184 180
185 list_for_each(tmp, peer_list) { 181 list_for_each(tmp, peer_list) {
186 peer = list_entry(tmp, ksock_peer_t, ksnp_list); 182 peer = list_entry(tmp, struct ksock_peer, ksnp_list);
187 183
188 LASSERT(!peer->ksnp_closing); 184 LASSERT(!peer->ksnp_closing);
189 185
@@ -202,10 +198,10 @@ ksocknal_find_peer_locked(lnet_ni_t *ni, lnet_process_id_t id)
202 return NULL; 198 return NULL;
203} 199}
204 200
205ksock_peer_t * 201struct ksock_peer *
206ksocknal_find_peer(lnet_ni_t *ni, lnet_process_id_t id) 202ksocknal_find_peer(lnet_ni_t *ni, lnet_process_id_t id)
207{ 203{
208 ksock_peer_t *peer; 204 struct ksock_peer *peer;
209 205
210 read_lock(&ksocknal_data.ksnd_global_lock); 206 read_lock(&ksocknal_data.ksnd_global_lock);
211 peer = ksocknal_find_peer_locked(ni, id); 207 peer = ksocknal_find_peer_locked(ni, id);
@@ -217,11 +213,11 @@ ksocknal_find_peer(lnet_ni_t *ni, lnet_process_id_t id)
217} 213}
218 214
219static void 215static void
220ksocknal_unlink_peer_locked(ksock_peer_t *peer) 216ksocknal_unlink_peer_locked(struct ksock_peer *peer)
221{ 217{
222 int i; 218 int i;
223 __u32 ip; 219 __u32 ip;
224 ksock_interface_t *iface; 220 struct ksock_interface *iface;
225 221
226 for (i = 0; i < peer->ksnp_n_passive_ips; i++) { 222 for (i = 0; i < peer->ksnp_n_passive_ips; i++) {
227 LASSERT(i < LNET_MAX_INTERFACES); 223 LASSERT(i < LNET_MAX_INTERFACES);
@@ -253,9 +249,9 @@ ksocknal_get_peer_info(lnet_ni_t *ni, int index,
253 lnet_process_id_t *id, __u32 *myip, __u32 *peer_ip, 249 lnet_process_id_t *id, __u32 *myip, __u32 *peer_ip,
254 int *port, int *conn_count, int *share_count) 250 int *port, int *conn_count, int *share_count)
255{ 251{
256 ksock_peer_t *peer; 252 struct ksock_peer *peer;
257 struct list_head *ptmp; 253 struct list_head *ptmp;
258 ksock_route_t *route; 254 struct ksock_route *route;
259 struct list_head *rtmp; 255 struct list_head *rtmp;
260 int i; 256 int i;
261 int j; 257 int j;
@@ -265,7 +261,7 @@ ksocknal_get_peer_info(lnet_ni_t *ni, int index,
265 261
266 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) { 262 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
267 list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) { 263 list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
268 peer = list_entry(ptmp, ksock_peer_t, ksnp_list); 264 peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
269 265
270 if (peer->ksnp_ni != ni) 266 if (peer->ksnp_ni != ni)
271 continue; 267 continue;
@@ -303,7 +299,7 @@ ksocknal_get_peer_info(lnet_ni_t *ni, int index,
303 if (index-- > 0) 299 if (index-- > 0)
304 continue; 300 continue;
305 301
306 route = list_entry(rtmp, ksock_route_t, 302 route = list_entry(rtmp, struct ksock_route,
307 ksnr_list); 303 ksnr_list);
308 304
309 *id = peer->ksnp_id; 305 *id = peer->ksnp_id;
@@ -323,11 +319,11 @@ ksocknal_get_peer_info(lnet_ni_t *ni, int index,
323} 319}
324 320
325static void 321static void
326ksocknal_associate_route_conn_locked(ksock_route_t *route, ksock_conn_t *conn) 322ksocknal_associate_route_conn_locked(struct ksock_route *route, struct ksock_conn *conn)
327{ 323{
328 ksock_peer_t *peer = route->ksnr_peer; 324 struct ksock_peer *peer = route->ksnr_peer;
329 int type = conn->ksnc_type; 325 int type = conn->ksnc_type;
330 ksock_interface_t *iface; 326 struct ksock_interface *iface;
331 327
332 conn->ksnc_route = route; 328 conn->ksnc_route = route;
333 ksocknal_route_addref(route); 329 ksocknal_route_addref(route);
@@ -369,11 +365,11 @@ ksocknal_associate_route_conn_locked(ksock_route_t *route, ksock_conn_t *conn)
369} 365}
370 366
371static void 367static void
372ksocknal_add_route_locked(ksock_peer_t *peer, ksock_route_t *route) 368ksocknal_add_route_locked(struct ksock_peer *peer, struct ksock_route *route)
373{ 369{
374 struct list_head *tmp; 370 struct list_head *tmp;
375 ksock_conn_t *conn; 371 struct ksock_conn *conn;
376 ksock_route_t *route2; 372 struct ksock_route *route2;
377 373
378 LASSERT(!peer->ksnp_closing); 374 LASSERT(!peer->ksnp_closing);
379 LASSERT(!route->ksnr_peer); 375 LASSERT(!route->ksnr_peer);
@@ -383,7 +379,7 @@ ksocknal_add_route_locked(ksock_peer_t *peer, ksock_route_t *route)
383 379
384 /* LASSERT(unique) */ 380 /* LASSERT(unique) */
385 list_for_each(tmp, &peer->ksnp_routes) { 381 list_for_each(tmp, &peer->ksnp_routes) {
386 route2 = list_entry(tmp, ksock_route_t, ksnr_list); 382 route2 = list_entry(tmp, struct ksock_route, ksnr_list);
387 383
388 if (route2->ksnr_ipaddr == route->ksnr_ipaddr) { 384 if (route2->ksnr_ipaddr == route->ksnr_ipaddr) {
389 CERROR("Duplicate route %s %pI4h\n", 385 CERROR("Duplicate route %s %pI4h\n",
@@ -399,7 +395,7 @@ ksocknal_add_route_locked(ksock_peer_t *peer, ksock_route_t *route)
399 list_add_tail(&route->ksnr_list, &peer->ksnp_routes); 395 list_add_tail(&route->ksnr_list, &peer->ksnp_routes);
400 396
401 list_for_each(tmp, &peer->ksnp_conns) { 397 list_for_each(tmp, &peer->ksnp_conns) {
402 conn = list_entry(tmp, ksock_conn_t, ksnc_list); 398 conn = list_entry(tmp, struct ksock_conn, ksnc_list);
403 399
404 if (conn->ksnc_ipaddr != route->ksnr_ipaddr) 400 if (conn->ksnc_ipaddr != route->ksnr_ipaddr)
405 continue; 401 continue;
@@ -410,11 +406,11 @@ ksocknal_add_route_locked(ksock_peer_t *peer, ksock_route_t *route)
410} 406}
411 407
412static void 408static void
413ksocknal_del_route_locked(ksock_route_t *route) 409ksocknal_del_route_locked(struct ksock_route *route)
414{ 410{
415 ksock_peer_t *peer = route->ksnr_peer; 411 struct ksock_peer *peer = route->ksnr_peer;
416 ksock_interface_t *iface; 412 struct ksock_interface *iface;
417 ksock_conn_t *conn; 413 struct ksock_conn *conn;
418 struct list_head *ctmp; 414 struct list_head *ctmp;
419 struct list_head *cnxt; 415 struct list_head *cnxt;
420 416
@@ -422,7 +418,7 @@ ksocknal_del_route_locked(ksock_route_t *route)
422 418
423 /* Close associated conns */ 419 /* Close associated conns */
424 list_for_each_safe(ctmp, cnxt, &peer->ksnp_conns) { 420 list_for_each_safe(ctmp, cnxt, &peer->ksnp_conns) {
425 conn = list_entry(ctmp, ksock_conn_t, ksnc_list); 421 conn = list_entry(ctmp, struct ksock_conn, ksnc_list);
426 422
427 if (conn->ksnc_route != route) 423 if (conn->ksnc_route != route)
428 continue; 424 continue;
@@ -455,10 +451,10 @@ int
455ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ipaddr, int port) 451ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ipaddr, int port)
456{ 452{
457 struct list_head *tmp; 453 struct list_head *tmp;
458 ksock_peer_t *peer; 454 struct ksock_peer *peer;
459 ksock_peer_t *peer2; 455 struct ksock_peer *peer2;
460 ksock_route_t *route; 456 struct ksock_route *route;
461 ksock_route_t *route2; 457 struct ksock_route *route2;
462 int rc; 458 int rc;
463 459
464 if (id.nid == LNET_NID_ANY || 460 if (id.nid == LNET_NID_ANY ||
@@ -479,7 +475,7 @@ ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ipaddr, int port)
479 write_lock_bh(&ksocknal_data.ksnd_global_lock); 475 write_lock_bh(&ksocknal_data.ksnd_global_lock);
480 476
481 /* always called with a ref on ni, so shutdown can't have started */ 477 /* always called with a ref on ni, so shutdown can't have started */
482 LASSERT(!((ksock_net_t *) ni->ni_data)->ksnn_shutdown); 478 LASSERT(!((struct ksock_net *)ni->ni_data)->ksnn_shutdown);
483 479
484 peer2 = ksocknal_find_peer_locked(ni, id); 480 peer2 = ksocknal_find_peer_locked(ni, id);
485 if (peer2) { 481 if (peer2) {
@@ -493,7 +489,7 @@ ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ipaddr, int port)
493 489
494 route2 = NULL; 490 route2 = NULL;
495 list_for_each(tmp, &peer->ksnp_routes) { 491 list_for_each(tmp, &peer->ksnp_routes) {
496 route2 = list_entry(tmp, ksock_route_t, ksnr_list); 492 route2 = list_entry(tmp, struct ksock_route, ksnr_list);
497 493
498 if (route2->ksnr_ipaddr == ipaddr) 494 if (route2->ksnr_ipaddr == ipaddr)
499 break; 495 break;
@@ -514,10 +510,10 @@ ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ipaddr, int port)
514} 510}
515 511
516static void 512static void
517ksocknal_del_peer_locked(ksock_peer_t *peer, __u32 ip) 513ksocknal_del_peer_locked(struct ksock_peer *peer, __u32 ip)
518{ 514{
519 ksock_conn_t *conn; 515 struct ksock_conn *conn;
520 ksock_route_t *route; 516 struct ksock_route *route;
521 struct list_head *tmp; 517 struct list_head *tmp;
522 struct list_head *nxt; 518 struct list_head *nxt;
523 int nshared; 519 int nshared;
@@ -528,7 +524,7 @@ ksocknal_del_peer_locked(ksock_peer_t *peer, __u32 ip)
528 ksocknal_peer_addref(peer); 524 ksocknal_peer_addref(peer);
529 525
530 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) { 526 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) {
531 route = list_entry(tmp, ksock_route_t, ksnr_list); 527 route = list_entry(tmp, struct ksock_route, ksnr_list);
532 528
533 /* no match */ 529 /* no match */
534 if (!(!ip || route->ksnr_ipaddr == ip)) 530 if (!(!ip || route->ksnr_ipaddr == ip))
@@ -541,7 +537,7 @@ ksocknal_del_peer_locked(ksock_peer_t *peer, __u32 ip)
541 537
542 nshared = 0; 538 nshared = 0;
543 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) { 539 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) {
544 route = list_entry(tmp, ksock_route_t, ksnr_list); 540 route = list_entry(tmp, struct ksock_route, ksnr_list);
545 nshared += route->ksnr_share_count; 541 nshared += route->ksnr_share_count;
546 } 542 }
547 543
@@ -551,7 +547,7 @@ ksocknal_del_peer_locked(ksock_peer_t *peer, __u32 ip)
551 * left 547 * left
552 */ 548 */
553 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) { 549 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) {
554 route = list_entry(tmp, ksock_route_t, ksnr_list); 550 route = list_entry(tmp, struct ksock_route, ksnr_list);
555 551
556 /* we should only be removing auto-entries */ 552 /* we should only be removing auto-entries */
557 LASSERT(!route->ksnr_share_count); 553 LASSERT(!route->ksnr_share_count);
@@ -559,7 +555,7 @@ ksocknal_del_peer_locked(ksock_peer_t *peer, __u32 ip)
559 } 555 }
560 556
561 list_for_each_safe(tmp, nxt, &peer->ksnp_conns) { 557 list_for_each_safe(tmp, nxt, &peer->ksnp_conns) {
562 conn = list_entry(tmp, ksock_conn_t, ksnc_list); 558 conn = list_entry(tmp, struct ksock_conn, ksnc_list);
563 559
564 ksocknal_close_conn_locked(conn, 0); 560 ksocknal_close_conn_locked(conn, 0);
565 } 561 }
@@ -575,7 +571,7 @@ ksocknal_del_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip)
575 LIST_HEAD(zombies); 571 LIST_HEAD(zombies);
576 struct list_head *ptmp; 572 struct list_head *ptmp;
577 struct list_head *pnxt; 573 struct list_head *pnxt;
578 ksock_peer_t *peer; 574 struct ksock_peer *peer;
579 int lo; 575 int lo;
580 int hi; 576 int hi;
581 int i; 577 int i;
@@ -593,7 +589,7 @@ ksocknal_del_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip)
593 589
594 for (i = lo; i <= hi; i++) { 590 for (i = lo; i <= hi; i++) {
595 list_for_each_safe(ptmp, pnxt, &ksocknal_data.ksnd_peers[i]) { 591 list_for_each_safe(ptmp, pnxt, &ksocknal_data.ksnd_peers[i]) {
596 peer = list_entry(ptmp, ksock_peer_t, ksnp_list); 592 peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
597 593
598 if (peer->ksnp_ni != ni) 594 if (peer->ksnp_ni != ni)
599 continue; 595 continue;
@@ -628,12 +624,12 @@ ksocknal_del_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip)
628 return rc; 624 return rc;
629} 625}
630 626
631static ksock_conn_t * 627static struct ksock_conn *
632ksocknal_get_conn_by_idx(lnet_ni_t *ni, int index) 628ksocknal_get_conn_by_idx(lnet_ni_t *ni, int index)
633{ 629{
634 ksock_peer_t *peer; 630 struct ksock_peer *peer;
635 struct list_head *ptmp; 631 struct list_head *ptmp;
636 ksock_conn_t *conn; 632 struct ksock_conn *conn;
637 struct list_head *ctmp; 633 struct list_head *ctmp;
638 int i; 634 int i;
639 635
@@ -641,7 +637,7 @@ ksocknal_get_conn_by_idx(lnet_ni_t *ni, int index)
641 637
642 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) { 638 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
643 list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) { 639 list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
644 peer = list_entry(ptmp, ksock_peer_t, ksnp_list); 640 peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
645 641
646 LASSERT(!peer->ksnp_closing); 642 LASSERT(!peer->ksnp_closing);
647 643
@@ -652,7 +648,7 @@ ksocknal_get_conn_by_idx(lnet_ni_t *ni, int index)
652 if (index-- > 0) 648 if (index-- > 0)
653 continue; 649 continue;
654 650
655 conn = list_entry(ctmp, ksock_conn_t, 651 conn = list_entry(ctmp, struct ksock_conn,
656 ksnc_list); 652 ksnc_list);
657 ksocknal_conn_addref(conn); 653 ksocknal_conn_addref(conn);
658 read_unlock(&ksocknal_data.ksnd_global_lock); 654 read_unlock(&ksocknal_data.ksnd_global_lock);
@@ -665,11 +661,11 @@ ksocknal_get_conn_by_idx(lnet_ni_t *ni, int index)
665 return NULL; 661 return NULL;
666} 662}
667 663
668static ksock_sched_t * 664static struct ksock_sched *
669ksocknal_choose_scheduler_locked(unsigned int cpt) 665ksocknal_choose_scheduler_locked(unsigned int cpt)
670{ 666{
671 struct ksock_sched_info *info = ksocknal_data.ksnd_sched_info[cpt]; 667 struct ksock_sched_info *info = ksocknal_data.ksnd_sched_info[cpt];
672 ksock_sched_t *sched; 668 struct ksock_sched *sched;
673 int i; 669 int i;
674 670
675 LASSERT(info->ksi_nthreads > 0); 671 LASSERT(info->ksi_nthreads > 0);
@@ -691,7 +687,7 @@ ksocknal_choose_scheduler_locked(unsigned int cpt)
691static int 687static int
692ksocknal_local_ipvec(lnet_ni_t *ni, __u32 *ipaddrs) 688ksocknal_local_ipvec(lnet_ni_t *ni, __u32 *ipaddrs)
693{ 689{
694 ksock_net_t *net = ni->ni_data; 690 struct ksock_net *net = ni->ni_data;
695 int i; 691 int i;
696 int nip; 692 int nip;
697 693
@@ -719,7 +715,7 @@ ksocknal_local_ipvec(lnet_ni_t *ni, __u32 *ipaddrs)
719} 715}
720 716
721static int 717static int
722ksocknal_match_peerip(ksock_interface_t *iface, __u32 *ips, int nips) 718ksocknal_match_peerip(struct ksock_interface *iface, __u32 *ips, int nips)
723{ 719{
724 int best_netmatch = 0; 720 int best_netmatch = 0;
725 int best_xor = 0; 721 int best_xor = 0;
@@ -751,12 +747,12 @@ ksocknal_match_peerip(ksock_interface_t *iface, __u32 *ips, int nips)
751} 747}
752 748
753static int 749static int
754ksocknal_select_ips(ksock_peer_t *peer, __u32 *peerips, int n_peerips) 750ksocknal_select_ips(struct ksock_peer *peer, __u32 *peerips, int n_peerips)
755{ 751{
756 rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock; 752 rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
757 ksock_net_t *net = peer->ksnp_ni->ni_data; 753 struct ksock_net *net = peer->ksnp_ni->ni_data;
758 ksock_interface_t *iface; 754 struct ksock_interface *iface;
759 ksock_interface_t *best_iface; 755 struct ksock_interface *best_iface;
760 int n_ips; 756 int n_ips;
761 int i; 757 int i;
762 int j; 758 int j;
@@ -862,17 +858,17 @@ ksocknal_select_ips(ksock_peer_t *peer, __u32 *peerips, int n_peerips)
862} 858}
863 859
864static void 860static void
865ksocknal_create_routes(ksock_peer_t *peer, int port, 861ksocknal_create_routes(struct ksock_peer *peer, int port,
866 __u32 *peer_ipaddrs, int npeer_ipaddrs) 862 __u32 *peer_ipaddrs, int npeer_ipaddrs)
867{ 863{
868 ksock_route_t *newroute = NULL; 864 struct ksock_route *newroute = NULL;
869 rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock; 865 rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
870 lnet_ni_t *ni = peer->ksnp_ni; 866 lnet_ni_t *ni = peer->ksnp_ni;
871 ksock_net_t *net = ni->ni_data; 867 struct ksock_net *net = ni->ni_data;
872 struct list_head *rtmp; 868 struct list_head *rtmp;
873 ksock_route_t *route; 869 struct ksock_route *route;
874 ksock_interface_t *iface; 870 struct ksock_interface *iface;
875 ksock_interface_t *best_iface; 871 struct ksock_interface *best_iface;
876 int best_netmatch; 872 int best_netmatch;
877 int this_netmatch; 873 int this_netmatch;
878 int best_nroutes; 874 int best_nroutes;
@@ -919,7 +915,7 @@ ksocknal_create_routes(ksock_peer_t *peer, int port,
919 /* Already got a route? */ 915 /* Already got a route? */
920 route = NULL; 916 route = NULL;
921 list_for_each(rtmp, &peer->ksnp_routes) { 917 list_for_each(rtmp, &peer->ksnp_routes) {
922 route = list_entry(rtmp, ksock_route_t, ksnr_list); 918 route = list_entry(rtmp, struct ksock_route, ksnr_list);
923 919
924 if (route->ksnr_ipaddr == newroute->ksnr_ipaddr) 920 if (route->ksnr_ipaddr == newroute->ksnr_ipaddr)
925 break; 921 break;
@@ -941,7 +937,7 @@ ksocknal_create_routes(ksock_peer_t *peer, int port,
941 937
942 /* Using this interface already? */ 938 /* Using this interface already? */
943 list_for_each(rtmp, &peer->ksnp_routes) { 939 list_for_each(rtmp, &peer->ksnp_routes) {
944 route = list_entry(rtmp, ksock_route_t, 940 route = list_entry(rtmp, struct ksock_route,
945 ksnr_list); 941 ksnr_list);
946 942
947 if (route->ksnr_myipaddr == iface->ksni_ipaddr) 943 if (route->ksnr_myipaddr == iface->ksni_ipaddr)
@@ -985,7 +981,7 @@ ksocknal_create_routes(ksock_peer_t *peer, int port,
985int 981int
986ksocknal_accept(lnet_ni_t *ni, struct socket *sock) 982ksocknal_accept(lnet_ni_t *ni, struct socket *sock)
987{ 983{
988 ksock_connreq_t *cr; 984 struct ksock_connreq *cr;
989 int rc; 985 int rc;
990 __u32 peer_ip; 986 __u32 peer_ip;
991 int peer_port; 987 int peer_port;
@@ -1014,9 +1010,9 @@ ksocknal_accept(lnet_ni_t *ni, struct socket *sock)
1014} 1010}
1015 1011
1016static int 1012static int
1017ksocknal_connecting(ksock_peer_t *peer, __u32 ipaddr) 1013ksocknal_connecting(struct ksock_peer *peer, __u32 ipaddr)
1018{ 1014{
1019 ksock_route_t *route; 1015 struct ksock_route *route;
1020 1016
1021 list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) { 1017 list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
1022 if (route->ksnr_ipaddr == ipaddr) 1018 if (route->ksnr_ipaddr == ipaddr)
@@ -1026,7 +1022,7 @@ ksocknal_connecting(ksock_peer_t *peer, __u32 ipaddr)
1026} 1022}
1027 1023
1028int 1024int
1029ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route, 1025ksocknal_create_conn(lnet_ni_t *ni, struct ksock_route *route,
1030 struct socket *sock, int type) 1026 struct socket *sock, int type)
1031{ 1027{
1032 rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock; 1028 rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
@@ -1034,15 +1030,15 @@ ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route,
1034 lnet_process_id_t peerid; 1030 lnet_process_id_t peerid;
1035 struct list_head *tmp; 1031 struct list_head *tmp;
1036 __u64 incarnation; 1032 __u64 incarnation;
1037 ksock_conn_t *conn; 1033 struct ksock_conn *conn;
1038 ksock_conn_t *conn2; 1034 struct ksock_conn *conn2;
1039 ksock_peer_t *peer = NULL; 1035 struct ksock_peer *peer = NULL;
1040 ksock_peer_t *peer2; 1036 struct ksock_peer *peer2;
1041 ksock_sched_t *sched; 1037 struct ksock_sched *sched;
1042 ksock_hello_msg_t *hello; 1038 ksock_hello_msg_t *hello;
1043 int cpt; 1039 int cpt;
1044 ksock_tx_t *tx; 1040 struct ksock_tx *tx;
1045 ksock_tx_t *txtmp; 1041 struct ksock_tx *txtmp;
1046 int rc; 1042 int rc;
1047 int active; 1043 int active;
1048 char *warn = NULL; 1044 char *warn = NULL;
@@ -1150,7 +1146,7 @@ ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route,
1150 write_lock_bh(global_lock); 1146 write_lock_bh(global_lock);
1151 1147
1152 /* called with a ref on ni, so shutdown can't have started */ 1148 /* called with a ref on ni, so shutdown can't have started */
1153 LASSERT(!((ksock_net_t *) ni->ni_data)->ksnn_shutdown); 1149 LASSERT(!((struct ksock_net *)ni->ni_data)->ksnn_shutdown);
1154 1150
1155 peer2 = ksocknal_find_peer_locked(ni, peerid); 1151 peer2 = ksocknal_find_peer_locked(ni, peerid);
1156 if (!peer2) { 1152 if (!peer2) {
@@ -1233,7 +1229,7 @@ ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route,
1233 */ 1229 */
1234 if (conn->ksnc_ipaddr != conn->ksnc_myipaddr) { 1230 if (conn->ksnc_ipaddr != conn->ksnc_myipaddr) {
1235 list_for_each(tmp, &peer->ksnp_conns) { 1231 list_for_each(tmp, &peer->ksnp_conns) {
1236 conn2 = list_entry(tmp, ksock_conn_t, ksnc_list); 1232 conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
1237 1233
1238 if (conn2->ksnc_ipaddr != conn->ksnc_ipaddr || 1234 if (conn2->ksnc_ipaddr != conn->ksnc_ipaddr ||
1239 conn2->ksnc_myipaddr != conn->ksnc_myipaddr || 1235 conn2->ksnc_myipaddr != conn->ksnc_myipaddr ||
@@ -1273,7 +1269,7 @@ ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route,
1273 * continually create duplicate routes. 1269 * continually create duplicate routes.
1274 */ 1270 */
1275 list_for_each(tmp, &peer->ksnp_routes) { 1271 list_for_each(tmp, &peer->ksnp_routes) {
1276 route = list_entry(tmp, ksock_route_t, ksnr_list); 1272 route = list_entry(tmp, struct ksock_route, ksnr_list);
1277 1273
1278 if (route->ksnr_ipaddr != conn->ksnc_ipaddr) 1274 if (route->ksnr_ipaddr != conn->ksnc_ipaddr)
1279 continue; 1275 continue;
@@ -1432,16 +1428,16 @@ failed_0:
1432} 1428}
1433 1429
1434void 1430void
1435ksocknal_close_conn_locked(ksock_conn_t *conn, int error) 1431ksocknal_close_conn_locked(struct ksock_conn *conn, int error)
1436{ 1432{
1437 /* 1433 /*
1438 * This just does the immmediate housekeeping, and queues the 1434 * This just does the immmediate housekeeping, and queues the
1439 * connection for the reaper to terminate. 1435 * connection for the reaper to terminate.
1440 * Caller holds ksnd_global_lock exclusively in irq context 1436 * Caller holds ksnd_global_lock exclusively in irq context
1441 */ 1437 */
1442 ksock_peer_t *peer = conn->ksnc_peer; 1438 struct ksock_peer *peer = conn->ksnc_peer;
1443 ksock_route_t *route; 1439 struct ksock_route *route;
1444 ksock_conn_t *conn2; 1440 struct ksock_conn *conn2;
1445 struct list_head *tmp; 1441 struct list_head *tmp;
1446 1442
1447 LASSERT(!peer->ksnp_error); 1443 LASSERT(!peer->ksnp_error);
@@ -1459,7 +1455,7 @@ ksocknal_close_conn_locked(ksock_conn_t *conn, int error)
1459 1455
1460 conn2 = NULL; 1456 conn2 = NULL;
1461 list_for_each(tmp, &peer->ksnp_conns) { 1457 list_for_each(tmp, &peer->ksnp_conns) {
1462 conn2 = list_entry(tmp, ksock_conn_t, ksnc_list); 1458 conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
1463 1459
1464 if (conn2->ksnc_route == route && 1460 if (conn2->ksnc_route == route &&
1465 conn2->ksnc_type == conn->ksnc_type) 1461 conn2->ksnc_type == conn->ksnc_type)
@@ -1484,7 +1480,7 @@ ksocknal_close_conn_locked(ksock_conn_t *conn, int error)
1484 /* No more connections to this peer */ 1480 /* No more connections to this peer */
1485 1481
1486 if (!list_empty(&peer->ksnp_tx_queue)) { 1482 if (!list_empty(&peer->ksnp_tx_queue)) {
1487 ksock_tx_t *tx; 1483 struct ksock_tx *tx;
1488 1484
1489 LASSERT(conn->ksnc_proto == &ksocknal_protocol_v3x); 1485 LASSERT(conn->ksnc_proto == &ksocknal_protocol_v3x);
1490 1486
@@ -1524,7 +1520,7 @@ ksocknal_close_conn_locked(ksock_conn_t *conn, int error)
1524} 1520}
1525 1521
1526void 1522void
1527ksocknal_peer_failed(ksock_peer_t *peer) 1523ksocknal_peer_failed(struct ksock_peer *peer)
1528{ 1524{
1529 int notify = 0; 1525 int notify = 0;
1530 unsigned long last_alive = 0; 1526 unsigned long last_alive = 0;
@@ -1552,12 +1548,12 @@ ksocknal_peer_failed(ksock_peer_t *peer)
1552} 1548}
1553 1549
1554void 1550void
1555ksocknal_finalize_zcreq(ksock_conn_t *conn) 1551ksocknal_finalize_zcreq(struct ksock_conn *conn)
1556{ 1552{
1557 ksock_peer_t *peer = conn->ksnc_peer; 1553 struct ksock_peer *peer = conn->ksnc_peer;
1558 ksock_tx_t *tx; 1554 struct ksock_tx *tx;
1559 ksock_tx_t *temp; 1555 struct ksock_tx *temp;
1560 ksock_tx_t *tmp; 1556 struct ksock_tx *tmp;
1561 LIST_HEAD(zlist); 1557 LIST_HEAD(zlist);
1562 1558
1563 /* 1559 /*
@@ -1589,7 +1585,7 @@ ksocknal_finalize_zcreq(ksock_conn_t *conn)
1589} 1585}
1590 1586
1591void 1587void
1592ksocknal_terminate_conn(ksock_conn_t *conn) 1588ksocknal_terminate_conn(struct ksock_conn *conn)
1593{ 1589{
1594 /* 1590 /*
1595 * This gets called by the reaper (guaranteed thread context) to 1591 * This gets called by the reaper (guaranteed thread context) to
@@ -1597,8 +1593,8 @@ ksocknal_terminate_conn(ksock_conn_t *conn)
1597 * ksnc_refcount will eventually hit zero, and then the reaper will 1593 * ksnc_refcount will eventually hit zero, and then the reaper will
1598 * destroy it. 1594 * destroy it.
1599 */ 1595 */
1600 ksock_peer_t *peer = conn->ksnc_peer; 1596 struct ksock_peer *peer = conn->ksnc_peer;
1601 ksock_sched_t *sched = conn->ksnc_scheduler; 1597 struct ksock_sched *sched = conn->ksnc_scheduler;
1602 int failed = 0; 1598 int failed = 0;
1603 1599
1604 LASSERT(conn->ksnc_closing); 1600 LASSERT(conn->ksnc_closing);
@@ -1656,7 +1652,7 @@ ksocknal_terminate_conn(ksock_conn_t *conn)
1656} 1652}
1657 1653
1658void 1654void
1659ksocknal_queue_zombie_conn(ksock_conn_t *conn) 1655ksocknal_queue_zombie_conn(struct ksock_conn *conn)
1660{ 1656{
1661 /* Queue the conn for the reaper to destroy */ 1657 /* Queue the conn for the reaper to destroy */
1662 1658
@@ -1670,7 +1666,7 @@ ksocknal_queue_zombie_conn(ksock_conn_t *conn)
1670} 1666}
1671 1667
1672void 1668void
1673ksocknal_destroy_conn(ksock_conn_t *conn) 1669ksocknal_destroy_conn(struct ksock_conn *conn)
1674{ 1670{
1675 unsigned long last_rcv; 1671 unsigned long last_rcv;
1676 1672
@@ -1730,15 +1726,15 @@ ksocknal_destroy_conn(ksock_conn_t *conn)
1730} 1726}
1731 1727
1732int 1728int
1733ksocknal_close_peer_conns_locked(ksock_peer_t *peer, __u32 ipaddr, int why) 1729ksocknal_close_peer_conns_locked(struct ksock_peer *peer, __u32 ipaddr, int why)
1734{ 1730{
1735 ksock_conn_t *conn; 1731 struct ksock_conn *conn;
1736 struct list_head *ctmp; 1732 struct list_head *ctmp;
1737 struct list_head *cnxt; 1733 struct list_head *cnxt;
1738 int count = 0; 1734 int count = 0;
1739 1735
1740 list_for_each_safe(ctmp, cnxt, &peer->ksnp_conns) { 1736 list_for_each_safe(ctmp, cnxt, &peer->ksnp_conns) {
1741 conn = list_entry(ctmp, ksock_conn_t, ksnc_list); 1737 conn = list_entry(ctmp, struct ksock_conn, ksnc_list);
1742 1738
1743 if (!ipaddr || conn->ksnc_ipaddr == ipaddr) { 1739 if (!ipaddr || conn->ksnc_ipaddr == ipaddr) {
1744 count++; 1740 count++;
@@ -1750,9 +1746,9 @@ ksocknal_close_peer_conns_locked(ksock_peer_t *peer, __u32 ipaddr, int why)
1750} 1746}
1751 1747
1752int 1748int
1753ksocknal_close_conn_and_siblings(ksock_conn_t *conn, int why) 1749ksocknal_close_conn_and_siblings(struct ksock_conn *conn, int why)
1754{ 1750{
1755 ksock_peer_t *peer = conn->ksnc_peer; 1751 struct ksock_peer *peer = conn->ksnc_peer;
1756 __u32 ipaddr = conn->ksnc_ipaddr; 1752 __u32 ipaddr = conn->ksnc_ipaddr;
1757 int count; 1753 int count;
1758 1754
@@ -1768,7 +1764,7 @@ ksocknal_close_conn_and_siblings(ksock_conn_t *conn, int why)
1768int 1764int
1769ksocknal_close_matching_conns(lnet_process_id_t id, __u32 ipaddr) 1765ksocknal_close_matching_conns(lnet_process_id_t id, __u32 ipaddr)
1770{ 1766{
1771 ksock_peer_t *peer; 1767 struct ksock_peer *peer;
1772 struct list_head *ptmp; 1768 struct list_head *ptmp;
1773 struct list_head *pnxt; 1769 struct list_head *pnxt;
1774 int lo; 1770 int lo;
@@ -1789,7 +1785,7 @@ ksocknal_close_matching_conns(lnet_process_id_t id, __u32 ipaddr)
1789 for (i = lo; i <= hi; i++) { 1785 for (i = lo; i <= hi; i++) {
1790 list_for_each_safe(ptmp, pnxt, 1786 list_for_each_safe(ptmp, pnxt,
1791 &ksocknal_data.ksnd_peers[i]) { 1787 &ksocknal_data.ksnd_peers[i]) {
1792 peer = list_entry(ptmp, ksock_peer_t, ksnp_list); 1788 peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
1793 1789
1794 if (!((id.nid == LNET_NID_ANY || id.nid == peer->ksnp_id.nid) && 1790 if (!((id.nid == LNET_NID_ANY || id.nid == peer->ksnp_id.nid) &&
1795 (id.pid == LNET_PID_ANY || id.pid == peer->ksnp_id.pid))) 1791 (id.pid == LNET_PID_ANY || id.pid == peer->ksnp_id.pid)))
@@ -1844,7 +1840,7 @@ ksocknal_query(lnet_ni_t *ni, lnet_nid_t nid, unsigned long *when)
1844 int connect = 1; 1840 int connect = 1;
1845 unsigned long last_alive = 0; 1841 unsigned long last_alive = 0;
1846 unsigned long now = cfs_time_current(); 1842 unsigned long now = cfs_time_current();
1847 ksock_peer_t *peer = NULL; 1843 struct ksock_peer *peer = NULL;
1848 rwlock_t *glock = &ksocknal_data.ksnd_global_lock; 1844 rwlock_t *glock = &ksocknal_data.ksnd_global_lock;
1849 lnet_process_id_t id = { 1845 lnet_process_id_t id = {
1850 .nid = nid, 1846 .nid = nid,
@@ -1856,11 +1852,11 @@ ksocknal_query(lnet_ni_t *ni, lnet_nid_t nid, unsigned long *when)
1856 peer = ksocknal_find_peer_locked(ni, id); 1852 peer = ksocknal_find_peer_locked(ni, id);
1857 if (peer) { 1853 if (peer) {
1858 struct list_head *tmp; 1854 struct list_head *tmp;
1859 ksock_conn_t *conn; 1855 struct ksock_conn *conn;
1860 int bufnob; 1856 int bufnob;
1861 1857
1862 list_for_each(tmp, &peer->ksnp_conns) { 1858 list_for_each(tmp, &peer->ksnp_conns) {
1863 conn = list_entry(tmp, ksock_conn_t, ksnc_list); 1859 conn = list_entry(tmp, struct ksock_conn, ksnc_list);
1864 bufnob = conn->ksnc_sock->sk->sk_wmem_queued; 1860 bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
1865 1861
1866 if (bufnob < conn->ksnc_tx_bufnob) { 1862 if (bufnob < conn->ksnc_tx_bufnob) {
@@ -1902,12 +1898,12 @@ ksocknal_query(lnet_ni_t *ni, lnet_nid_t nid, unsigned long *when)
1902} 1898}
1903 1899
1904static void 1900static void
1905ksocknal_push_peer(ksock_peer_t *peer) 1901ksocknal_push_peer(struct ksock_peer *peer)
1906{ 1902{
1907 int index; 1903 int index;
1908 int i; 1904 int i;
1909 struct list_head *tmp; 1905 struct list_head *tmp;
1910 ksock_conn_t *conn; 1906 struct ksock_conn *conn;
1911 1907
1912 for (index = 0; ; index++) { 1908 for (index = 0; ; index++) {
1913 read_lock(&ksocknal_data.ksnd_global_lock); 1909 read_lock(&ksocknal_data.ksnd_global_lock);
@@ -1917,7 +1913,7 @@ ksocknal_push_peer(ksock_peer_t *peer)
1917 1913
1918 list_for_each(tmp, &peer->ksnp_conns) { 1914 list_for_each(tmp, &peer->ksnp_conns) {
1919 if (i++ == index) { 1915 if (i++ == index) {
1920 conn = list_entry(tmp, ksock_conn_t, 1916 conn = list_entry(tmp, struct ksock_conn,
1921 ksnc_list); 1917 ksnc_list);
1922 ksocknal_conn_addref(conn); 1918 ksocknal_conn_addref(conn);
1923 break; 1919 break;
@@ -1954,7 +1950,7 @@ static int ksocknal_push(lnet_ni_t *ni, lnet_process_id_t id)
1954 int peer_off; /* searching offset in peer hash table */ 1950 int peer_off; /* searching offset in peer hash table */
1955 1951
1956 for (peer_off = 0; ; peer_off++) { 1952 for (peer_off = 0; ; peer_off++) {
1957 ksock_peer_t *peer; 1953 struct ksock_peer *peer;
1958 int i = 0; 1954 int i = 0;
1959 1955
1960 read_lock(&ksocknal_data.ksnd_global_lock); 1956 read_lock(&ksocknal_data.ksnd_global_lock);
@@ -1986,15 +1982,15 @@ static int ksocknal_push(lnet_ni_t *ni, lnet_process_id_t id)
1986static int 1982static int
1987ksocknal_add_interface(lnet_ni_t *ni, __u32 ipaddress, __u32 netmask) 1983ksocknal_add_interface(lnet_ni_t *ni, __u32 ipaddress, __u32 netmask)
1988{ 1984{
1989 ksock_net_t *net = ni->ni_data; 1985 struct ksock_net *net = ni->ni_data;
1990 ksock_interface_t *iface; 1986 struct ksock_interface *iface;
1991 int rc; 1987 int rc;
1992 int i; 1988 int i;
1993 int j; 1989 int j;
1994 struct list_head *ptmp; 1990 struct list_head *ptmp;
1995 ksock_peer_t *peer; 1991 struct ksock_peer *peer;
1996 struct list_head *rtmp; 1992 struct list_head *rtmp;
1997 ksock_route_t *route; 1993 struct ksock_route *route;
1998 1994
1999 if (!ipaddress || !netmask) 1995 if (!ipaddress || !netmask)
2000 return -EINVAL; 1996 return -EINVAL;
@@ -2017,7 +2013,7 @@ ksocknal_add_interface(lnet_ni_t *ni, __u32 ipaddress, __u32 netmask)
2017 2013
2018 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) { 2014 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
2019 list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) { 2015 list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
2020 peer = list_entry(ptmp, ksock_peer_t, 2016 peer = list_entry(ptmp, struct ksock_peer,
2021 ksnp_list); 2017 ksnp_list);
2022 2018
2023 for (j = 0; j < peer->ksnp_n_passive_ips; j++) 2019 for (j = 0; j < peer->ksnp_n_passive_ips; j++)
@@ -2025,7 +2021,7 @@ ksocknal_add_interface(lnet_ni_t *ni, __u32 ipaddress, __u32 netmask)
2025 iface->ksni_npeers++; 2021 iface->ksni_npeers++;
2026 2022
2027 list_for_each(rtmp, &peer->ksnp_routes) { 2023 list_for_each(rtmp, &peer->ksnp_routes) {
2028 route = list_entry(rtmp, ksock_route_t, 2024 route = list_entry(rtmp, struct ksock_route,
2029 ksnr_list); 2025 ksnr_list);
2030 2026
2031 if (route->ksnr_myipaddr == ipaddress) 2027 if (route->ksnr_myipaddr == ipaddress)
@@ -2044,12 +2040,12 @@ ksocknal_add_interface(lnet_ni_t *ni, __u32 ipaddress, __u32 netmask)
2044} 2040}
2045 2041
2046static void 2042static void
2047ksocknal_peer_del_interface_locked(ksock_peer_t *peer, __u32 ipaddr) 2043ksocknal_peer_del_interface_locked(struct ksock_peer *peer, __u32 ipaddr)
2048{ 2044{
2049 struct list_head *tmp; 2045 struct list_head *tmp;
2050 struct list_head *nxt; 2046 struct list_head *nxt;
2051 ksock_route_t *route; 2047 struct ksock_route *route;
2052 ksock_conn_t *conn; 2048 struct ksock_conn *conn;
2053 int i; 2049 int i;
2054 int j; 2050 int j;
2055 2051
@@ -2063,7 +2059,7 @@ ksocknal_peer_del_interface_locked(ksock_peer_t *peer, __u32 ipaddr)
2063 } 2059 }
2064 2060
2065 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) { 2061 list_for_each_safe(tmp, nxt, &peer->ksnp_routes) {
2066 route = list_entry(tmp, ksock_route_t, ksnr_list); 2062 route = list_entry(tmp, struct ksock_route, ksnr_list);
2067 2063
2068 if (route->ksnr_myipaddr != ipaddr) 2064 if (route->ksnr_myipaddr != ipaddr)
2069 continue; 2065 continue;
@@ -2077,7 +2073,7 @@ ksocknal_peer_del_interface_locked(ksock_peer_t *peer, __u32 ipaddr)
2077 } 2073 }
2078 2074
2079 list_for_each_safe(tmp, nxt, &peer->ksnp_conns) { 2075 list_for_each_safe(tmp, nxt, &peer->ksnp_conns) {
2080 conn = list_entry(tmp, ksock_conn_t, ksnc_list); 2076 conn = list_entry(tmp, struct ksock_conn, ksnc_list);
2081 2077
2082 if (conn->ksnc_myipaddr == ipaddr) 2078 if (conn->ksnc_myipaddr == ipaddr)
2083 ksocknal_close_conn_locked(conn, 0); 2079 ksocknal_close_conn_locked(conn, 0);
@@ -2087,11 +2083,11 @@ ksocknal_peer_del_interface_locked(ksock_peer_t *peer, __u32 ipaddr)
2087static int 2083static int
2088ksocknal_del_interface(lnet_ni_t *ni, __u32 ipaddress) 2084ksocknal_del_interface(lnet_ni_t *ni, __u32 ipaddress)
2089{ 2085{
2090 ksock_net_t *net = ni->ni_data; 2086 struct ksock_net *net = ni->ni_data;
2091 int rc = -ENOENT; 2087 int rc = -ENOENT;
2092 struct list_head *tmp; 2088 struct list_head *tmp;
2093 struct list_head *nxt; 2089 struct list_head *nxt;
2094 ksock_peer_t *peer; 2090 struct ksock_peer *peer;
2095 __u32 this_ip; 2091 __u32 this_ip;
2096 int i; 2092 int i;
2097 int j; 2093 int j;
@@ -2115,7 +2111,7 @@ ksocknal_del_interface(lnet_ni_t *ni, __u32 ipaddress)
2115 for (j = 0; j < ksocknal_data.ksnd_peer_hash_size; j++) { 2111 for (j = 0; j < ksocknal_data.ksnd_peer_hash_size; j++) {
2116 list_for_each_safe(tmp, nxt, 2112 list_for_each_safe(tmp, nxt,
2117 &ksocknal_data.ksnd_peers[j]) { 2113 &ksocknal_data.ksnd_peers[j]) {
2118 peer = list_entry(tmp, ksock_peer_t, ksnp_list); 2114 peer = list_entry(tmp, struct ksock_peer, ksnp_list);
2119 2115
2120 if (peer->ksnp_ni != ni) 2116 if (peer->ksnp_ni != ni)
2121 continue; 2117 continue;
@@ -2139,8 +2135,8 @@ ksocknal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
2139 2135
2140 switch (cmd) { 2136 switch (cmd) {
2141 case IOC_LIBCFS_GET_INTERFACE: { 2137 case IOC_LIBCFS_GET_INTERFACE: {
2142 ksock_net_t *net = ni->ni_data; 2138 struct ksock_net *net = ni->ni_data;
2143 ksock_interface_t *iface; 2139 struct ksock_interface *iface;
2144 2140
2145 read_lock(&ksocknal_data.ksnd_global_lock); 2141 read_lock(&ksocknal_data.ksnd_global_lock);
2146 2142
@@ -2209,7 +2205,7 @@ ksocknal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
2209 int txmem; 2205 int txmem;
2210 int rxmem; 2206 int rxmem;
2211 int nagle; 2207 int nagle;
2212 ksock_conn_t *conn = ksocknal_get_conn_by_idx(ni, data->ioc_count); 2208 struct ksock_conn *conn = ksocknal_get_conn_by_idx(ni, data->ioc_count);
2213 2209
2214 if (!conn) 2210 if (!conn)
2215 return -ENOENT; 2211 return -ENOENT;
@@ -2284,8 +2280,8 @@ ksocknal_free_buffers(void)
2284 2280
2285 if (!list_empty(&ksocknal_data.ksnd_idle_noop_txs)) { 2281 if (!list_empty(&ksocknal_data.ksnd_idle_noop_txs)) {
2286 struct list_head zlist; 2282 struct list_head zlist;
2287 ksock_tx_t *tx; 2283 struct ksock_tx *tx;
2288 ksock_tx_t *temp; 2284 struct ksock_tx *temp;
2289 2285
2290 list_add(&zlist, &ksocknal_data.ksnd_idle_noop_txs); 2286 list_add(&zlist, &ksocknal_data.ksnd_idle_noop_txs);
2291 list_del_init(&ksocknal_data.ksnd_idle_noop_txs); 2287 list_del_init(&ksocknal_data.ksnd_idle_noop_txs);
@@ -2304,7 +2300,7 @@ static void
2304ksocknal_base_shutdown(void) 2300ksocknal_base_shutdown(void)
2305{ 2301{
2306 struct ksock_sched_info *info; 2302 struct ksock_sched_info *info;
2307 ksock_sched_t *sched; 2303 struct ksock_sched *sched;
2308 int i; 2304 int i;
2309 int j; 2305 int j;
2310 2306
@@ -2446,7 +2442,7 @@ ksocknal_base_startup(void)
2446 goto failed; 2442 goto failed;
2447 2443
2448 cfs_percpt_for_each(info, i, ksocknal_data.ksnd_sched_info) { 2444 cfs_percpt_for_each(info, i, ksocknal_data.ksnd_sched_info) {
2449 ksock_sched_t *sched; 2445 struct ksock_sched *sched;
2450 int nthrs; 2446 int nthrs;
2451 2447
2452 nthrs = cfs_cpt_weight(lnet_cpt_table(), i); 2448 nthrs = cfs_cpt_weight(lnet_cpt_table(), i);
@@ -2534,7 +2530,7 @@ ksocknal_base_startup(void)
2534static void 2530static void
2535ksocknal_debug_peerhash(lnet_ni_t *ni) 2531ksocknal_debug_peerhash(lnet_ni_t *ni)
2536{ 2532{
2537 ksock_peer_t *peer = NULL; 2533 struct ksock_peer *peer = NULL;
2538 struct list_head *tmp; 2534 struct list_head *tmp;
2539 int i; 2535 int i;
2540 2536
@@ -2542,7 +2538,7 @@ ksocknal_debug_peerhash(lnet_ni_t *ni)
2542 2538
2543 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) { 2539 for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
2544 list_for_each(tmp, &ksocknal_data.ksnd_peers[i]) { 2540 list_for_each(tmp, &ksocknal_data.ksnd_peers[i]) {
2545 peer = list_entry(tmp, ksock_peer_t, ksnp_list); 2541 peer = list_entry(tmp, struct ksock_peer, ksnp_list);
2546 2542
2547 if (peer->ksnp_ni == ni) 2543 if (peer->ksnp_ni == ni)
2548 break; 2544 break;
@@ -2552,8 +2548,8 @@ ksocknal_debug_peerhash(lnet_ni_t *ni)
2552 } 2548 }
2553 2549
2554 if (peer) { 2550 if (peer) {
2555 ksock_route_t *route; 2551 struct ksock_route *route;
2556 ksock_conn_t *conn; 2552 struct ksock_conn *conn;
2557 2553
2558 CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n", 2554 CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
2559 libcfs_id2str(peer->ksnp_id), 2555 libcfs_id2str(peer->ksnp_id),
@@ -2565,7 +2561,7 @@ ksocknal_debug_peerhash(lnet_ni_t *ni)
2565 !list_empty(&peer->ksnp_zc_req_list)); 2561 !list_empty(&peer->ksnp_zc_req_list));
2566 2562
2567 list_for_each(tmp, &peer->ksnp_routes) { 2563 list_for_each(tmp, &peer->ksnp_routes) {
2568 route = list_entry(tmp, ksock_route_t, ksnr_list); 2564 route = list_entry(tmp, struct ksock_route, ksnr_list);
2569 CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n", 2565 CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
2570 atomic_read(&route->ksnr_refcount), 2566 atomic_read(&route->ksnr_refcount),
2571 route->ksnr_scheduled, route->ksnr_connecting, 2567 route->ksnr_scheduled, route->ksnr_connecting,
@@ -2573,7 +2569,7 @@ ksocknal_debug_peerhash(lnet_ni_t *ni)
2573 } 2569 }
2574 2570
2575 list_for_each(tmp, &peer->ksnp_conns) { 2571 list_for_each(tmp, &peer->ksnp_conns) {
2576 conn = list_entry(tmp, ksock_conn_t, ksnc_list); 2572 conn = list_entry(tmp, struct ksock_conn, ksnc_list);
2577 CWARN("Conn: ref %d, sref %d, t %d, c %d\n", 2573 CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
2578 atomic_read(&conn->ksnc_conn_refcount), 2574 atomic_read(&conn->ksnc_conn_refcount),
2579 atomic_read(&conn->ksnc_sock_refcount), 2575 atomic_read(&conn->ksnc_sock_refcount),
@@ -2587,7 +2583,7 @@ ksocknal_debug_peerhash(lnet_ni_t *ni)
2587void 2583void
2588ksocknal_shutdown(lnet_ni_t *ni) 2584ksocknal_shutdown(lnet_ni_t *ni)
2589{ 2585{
2590 ksock_net_t *net = ni->ni_data; 2586 struct ksock_net *net = ni->ni_data;
2591 int i; 2587 int i;
2592 lnet_process_id_t anyid = {0}; 2588 lnet_process_id_t anyid = {0};
2593 2589
@@ -2637,7 +2633,7 @@ ksocknal_shutdown(lnet_ni_t *ni)
2637} 2633}
2638 2634
2639static int 2635static int
2640ksocknal_enumerate_interfaces(ksock_net_t *net) 2636ksocknal_enumerate_interfaces(struct ksock_net *net)
2641{ 2637{
2642 char **names; 2638 char **names;
2643 int i; 2639 int i;
@@ -2694,7 +2690,7 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
2694} 2690}
2695 2691
2696static int 2692static int
2697ksocknal_search_new_ipif(ksock_net_t *net) 2693ksocknal_search_new_ipif(struct ksock_net *net)
2698{ 2694{
2699 int new_ipif = 0; 2695 int new_ipif = 0;
2700 int i; 2696 int i;
@@ -2703,7 +2699,7 @@ ksocknal_search_new_ipif(ksock_net_t *net)
2703 char *ifnam = &net->ksnn_interfaces[i].ksni_name[0]; 2699 char *ifnam = &net->ksnn_interfaces[i].ksni_name[0];
2704 char *colon = strchr(ifnam, ':'); 2700 char *colon = strchr(ifnam, ':');
2705 int found = 0; 2701 int found = 0;
2706 ksock_net_t *tmp; 2702 struct ksock_net *tmp;
2707 int j; 2703 int j;
2708 2704
2709 if (colon) /* ignore alias device */ 2705 if (colon) /* ignore alias device */
@@ -2760,7 +2756,7 @@ ksocknal_start_schedulers(struct ksock_sched_info *info)
2760 for (i = 0; i < nthrs; i++) { 2756 for (i = 0; i < nthrs; i++) {
2761 long id; 2757 long id;
2762 char name[20]; 2758 char name[20];
2763 ksock_sched_t *sched; 2759 struct ksock_sched *sched;
2764 2760
2765 id = KSOCK_THREAD_ID(info->ksi_cpt, info->ksi_nthreads + i); 2761 id = KSOCK_THREAD_ID(info->ksi_cpt, info->ksi_nthreads + i);
2766 sched = &info->ksi_scheds[KSOCK_THREAD_SID(id)]; 2762 sched = &info->ksi_scheds[KSOCK_THREAD_SID(id)];
@@ -2782,7 +2778,7 @@ ksocknal_start_schedulers(struct ksock_sched_info *info)
2782} 2778}
2783 2779
2784static int 2780static int
2785ksocknal_net_start_threads(ksock_net_t *net, __u32 *cpts, int ncpts) 2781ksocknal_net_start_threads(struct ksock_net *net, __u32 *cpts, int ncpts)
2786{ 2782{
2787 int newif = ksocknal_search_new_ipif(net); 2783 int newif = ksocknal_search_new_ipif(net);
2788 int rc; 2784 int rc;
@@ -2810,7 +2806,7 @@ ksocknal_net_start_threads(ksock_net_t *net, __u32 *cpts, int ncpts)
2810int 2806int
2811ksocknal_startup(lnet_ni_t *ni) 2807ksocknal_startup(lnet_ni_t *ni)
2812{ 2808{
2813 ksock_net_t *net; 2809 struct ksock_net *net;
2814 int rc; 2810 int rc;
2815 int i; 2811 int i;
2816 2812
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
index a60d72f9432f..a56632b4ee37 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
@@ -77,8 +77,7 @@
77 77
78struct ksock_sched_info; 78struct ksock_sched_info;
79 79
80typedef struct /* per scheduler state */ 80struct ksock_sched { /* per scheduler state */
81{
82 spinlock_t kss_lock; /* serialise */ 81 spinlock_t kss_lock; /* serialise */
83 struct list_head kss_rx_conns; /* conn waiting to be read */ 82 struct list_head kss_rx_conns; /* conn waiting to be read */
84 struct list_head kss_tx_conns; /* conn waiting to be written */ 83 struct list_head kss_tx_conns; /* conn waiting to be written */
@@ -89,13 +88,13 @@ typedef struct /* per scheduler state */
89 struct ksock_sched_info *kss_info; /* owner of it */ 88 struct ksock_sched_info *kss_info; /* owner of it */
90 struct page *kss_rx_scratch_pgs[LNET_MAX_IOV]; 89 struct page *kss_rx_scratch_pgs[LNET_MAX_IOV];
91 struct kvec kss_scratch_iov[LNET_MAX_IOV]; 90 struct kvec kss_scratch_iov[LNET_MAX_IOV];
92} ksock_sched_t; 91};
93 92
94struct ksock_sched_info { 93struct ksock_sched_info {
95 int ksi_nthreads_max; /* max allowed threads */ 94 int ksi_nthreads_max; /* max allowed threads */
96 int ksi_nthreads; /* number of threads */ 95 int ksi_nthreads; /* number of threads */
97 int ksi_cpt; /* CPT id */ 96 int ksi_cpt; /* CPT id */
98 ksock_sched_t *ksi_scheds; /* array of schedulers */ 97 struct ksock_sched *ksi_scheds; /* array of schedulers */
99}; 98};
100 99
101#define KSOCK_CPT_SHIFT 16 100#define KSOCK_CPT_SHIFT 16
@@ -103,16 +102,15 @@ struct ksock_sched_info {
103#define KSOCK_THREAD_CPT(id) ((id) >> KSOCK_CPT_SHIFT) 102#define KSOCK_THREAD_CPT(id) ((id) >> KSOCK_CPT_SHIFT)
104#define KSOCK_THREAD_SID(id) ((id) & ((1UL << KSOCK_CPT_SHIFT) - 1)) 103#define KSOCK_THREAD_SID(id) ((id) & ((1UL << KSOCK_CPT_SHIFT) - 1))
105 104
106typedef struct /* in-use interface */ 105struct ksock_interface { /* in-use interface */
107{
108 __u32 ksni_ipaddr; /* interface's IP address */ 106 __u32 ksni_ipaddr; /* interface's IP address */
109 __u32 ksni_netmask; /* interface's network mask */ 107 __u32 ksni_netmask; /* interface's network mask */
110 int ksni_nroutes; /* # routes using (active) */ 108 int ksni_nroutes; /* # routes using (active) */
111 int ksni_npeers; /* # peers using (passive) */ 109 int ksni_npeers; /* # peers using (passive) */
112 char ksni_name[IFNAMSIZ]; /* interface name */ 110 char ksni_name[IFNAMSIZ]; /* interface name */
113} ksock_interface_t; 111};
114 112
115typedef struct { 113struct ksock_tunables {
116 int *ksnd_timeout; /* "stuck" socket timeout 114 int *ksnd_timeout; /* "stuck" socket timeout
117 * (seconds) */ 115 * (seconds) */
118 int *ksnd_nscheds; /* # scheduler threads in each 116 int *ksnd_nscheds; /* # scheduler threads in each
@@ -155,24 +153,24 @@ typedef struct {
155 * Chelsio TOE) */ 153 * Chelsio TOE) */
156 int *ksnd_zc_recv_min_nfrags; /* minimum # of fragments to 154 int *ksnd_zc_recv_min_nfrags; /* minimum # of fragments to
157 * enable ZC receive */ 155 * enable ZC receive */
158} ksock_tunables_t; 156};
159 157
160typedef struct { 158struct ksock_net {
161 __u64 ksnn_incarnation; /* my epoch */ 159 __u64 ksnn_incarnation; /* my epoch */
162 spinlock_t ksnn_lock; /* serialise */ 160 spinlock_t ksnn_lock; /* serialise */
163 struct list_head ksnn_list; /* chain on global list */ 161 struct list_head ksnn_list; /* chain on global list */
164 int ksnn_npeers; /* # peers */ 162 int ksnn_npeers; /* # peers */
165 int ksnn_shutdown; /* shutting down? */ 163 int ksnn_shutdown; /* shutting down? */
166 int ksnn_ninterfaces; /* IP interfaces */ 164 int ksnn_ninterfaces; /* IP interfaces */
167 ksock_interface_t ksnn_interfaces[LNET_MAX_INTERFACES]; 165 struct ksock_interface ksnn_interfaces[LNET_MAX_INTERFACES];
168} ksock_net_t; 166};
169 167
170/** connd timeout */ 168/** connd timeout */
171#define SOCKNAL_CONND_TIMEOUT 120 169#define SOCKNAL_CONND_TIMEOUT 120
172/** reserved thread for accepting & creating new connd */ 170/** reserved thread for accepting & creating new connd */
173#define SOCKNAL_CONND_RESV 1 171#define SOCKNAL_CONND_RESV 1
174 172
175typedef struct { 173struct ksock_nal_data {
176 int ksnd_init; /* initialisation state 174 int ksnd_init; /* initialisation state
177 */ 175 */
178 int ksnd_nnets; /* # networks set up */ 176 int ksnd_nnets; /* # networks set up */
@@ -229,7 +227,7 @@ typedef struct {
229 spinlock_t ksnd_tx_lock; /* serialise, g_lock 227 spinlock_t ksnd_tx_lock; /* serialise, g_lock
230 * unsafe */ 228 * unsafe */
231 229
232} ksock_nal_data_t; 230};
233 231
234#define SOCKNAL_INIT_NOTHING 0 232#define SOCKNAL_INIT_NOTHING 0
235#define SOCKNAL_INIT_DATA 1 233#define SOCKNAL_INIT_DATA 1
@@ -250,8 +248,7 @@ struct ksock_peer; /* forward ref */
250struct ksock_route; /* forward ref */ 248struct ksock_route; /* forward ref */
251struct ksock_proto; /* forward ref */ 249struct ksock_proto; /* forward ref */
252 250
253typedef struct /* transmit packet */ 251struct ksock_tx { /* transmit packet */
254{
255 struct list_head tx_list; /* queue on conn for transmission etc 252 struct list_head tx_list; /* queue on conn for transmission etc
256 */ 253 */
257 struct list_head tx_zc_list; /* queue on peer for ZC request */ 254 struct list_head tx_zc_list; /* queue on peer for ZC request */
@@ -281,20 +278,20 @@ typedef struct /* transmit packet */
281 struct kvec iov[1]; /* virt hdr + payload */ 278 struct kvec iov[1]; /* virt hdr + payload */
282 } virt; 279 } virt;
283 } tx_frags; 280 } tx_frags;
284} ksock_tx_t; 281};
285 282
286#define KSOCK_NOOP_TX_SIZE (offsetof(ksock_tx_t, tx_frags.paged.kiov[0])) 283#define KSOCK_NOOP_TX_SIZE (offsetof(struct ksock_tx, tx_frags.paged.kiov[0]))
287 284
288/* network zero copy callback descriptor embedded in ksock_tx_t */ 285/* network zero copy callback descriptor embedded in struct ksock_tx */
289 286
290/* 287/*
291 * space for the rx frag descriptors; we either read a single contiguous 288 * space for the rx frag descriptors; we either read a single contiguous
292 * header, or up to LNET_MAX_IOV frags of payload of either type. 289 * header, or up to LNET_MAX_IOV frags of payload of either type.
293 */ 290 */
294typedef union { 291union ksock_rxiovspace {
295 struct kvec iov[LNET_MAX_IOV]; 292 struct kvec iov[LNET_MAX_IOV];
296 lnet_kiov_t kiov[LNET_MAX_IOV]; 293 lnet_kiov_t kiov[LNET_MAX_IOV];
297} ksock_rxiovspace_t; 294};
298 295
299#define SOCKNAL_RX_KSM_HEADER 1 /* reading ksock message header */ 296#define SOCKNAL_RX_KSM_HEADER 1 /* reading ksock message header */
300#define SOCKNAL_RX_LNET_HEADER 2 /* reading lnet message header */ 297#define SOCKNAL_RX_LNET_HEADER 2 /* reading lnet message header */
@@ -303,7 +300,7 @@ typedef union {
303#define SOCKNAL_RX_LNET_PAYLOAD 5 /* reading lnet payload (to deliver here) */ 300#define SOCKNAL_RX_LNET_PAYLOAD 5 /* reading lnet payload (to deliver here) */
304#define SOCKNAL_RX_SLOP 6 /* skipping body */ 301#define SOCKNAL_RX_SLOP 6 /* skipping body */
305 302
306typedef struct ksock_conn { 303struct ksock_conn {
307 struct ksock_peer *ksnc_peer; /* owning peer */ 304 struct ksock_peer *ksnc_peer; /* owning peer */
308 struct ksock_route *ksnc_route; /* owning route */ 305 struct ksock_route *ksnc_route; /* owning route */
309 struct list_head ksnc_list; /* stash on peer's conn list */ 306 struct list_head ksnc_list; /* stash on peer's conn list */
@@ -314,8 +311,8 @@ typedef struct ksock_conn {
314 * write_space() callback */ 311 * write_space() callback */
315 atomic_t ksnc_conn_refcount;/* conn refcount */ 312 atomic_t ksnc_conn_refcount;/* conn refcount */
316 atomic_t ksnc_sock_refcount;/* sock refcount */ 313 atomic_t ksnc_sock_refcount;/* sock refcount */
317 ksock_sched_t *ksnc_scheduler; /* who schedules this connection 314 struct ksock_sched *ksnc_scheduler; /* who schedules this connection
318 */ 315 */
319 __u32 ksnc_myipaddr; /* my IP */ 316 __u32 ksnc_myipaddr; /* my IP */
320 __u32 ksnc_ipaddr; /* peer's IP */ 317 __u32 ksnc_ipaddr; /* peer's IP */
321 int ksnc_port; /* peer's port */ 318 int ksnc_port; /* peer's port */
@@ -341,7 +338,7 @@ typedef struct ksock_conn {
341 struct kvec *ksnc_rx_iov; /* the iovec frags */ 338 struct kvec *ksnc_rx_iov; /* the iovec frags */
342 int ksnc_rx_nkiov; /* # page frags */ 339 int ksnc_rx_nkiov; /* # page frags */
343 lnet_kiov_t *ksnc_rx_kiov; /* the page frags */ 340 lnet_kiov_t *ksnc_rx_kiov; /* the page frags */
344 ksock_rxiovspace_t ksnc_rx_iov_space; /* space for frag descriptors */ 341 union ksock_rxiovspace ksnc_rx_iov_space; /* space for frag descriptors */
345 __u32 ksnc_rx_csum; /* partial checksum for incoming 342 __u32 ksnc_rx_csum; /* partial checksum for incoming
346 * data */ 343 * data */
347 void *ksnc_cookie; /* rx lnet_finalize passthru arg 344 void *ksnc_cookie; /* rx lnet_finalize passthru arg
@@ -357,7 +354,7 @@ typedef struct ksock_conn {
357 struct list_head ksnc_tx_list; /* where I enq waiting for output 354 struct list_head ksnc_tx_list; /* where I enq waiting for output
358 * space */ 355 * space */
359 struct list_head ksnc_tx_queue; /* packets waiting to be sent */ 356 struct list_head ksnc_tx_queue; /* packets waiting to be sent */
360 ksock_tx_t *ksnc_tx_carrier; /* next TX that can carry a LNet 357 struct ksock_tx *ksnc_tx_carrier; /* next TX that can carry a LNet
361 * message or ZC-ACK */ 358 * message or ZC-ACK */
362 unsigned long ksnc_tx_deadline; /* when (in jiffies) tx times out 359 unsigned long ksnc_tx_deadline; /* when (in jiffies) tx times out
363 */ 360 */
@@ -367,9 +364,9 @@ typedef struct ksock_conn {
367 int ksnc_tx_scheduled; /* being progressed */ 364 int ksnc_tx_scheduled; /* being progressed */
368 unsigned long ksnc_tx_last_post; /* time stamp of the last posted 365 unsigned long ksnc_tx_last_post; /* time stamp of the last posted
369 * TX */ 366 * TX */
370} ksock_conn_t; 367};
371 368
372typedef struct ksock_route { 369struct ksock_route {
373 struct list_head ksnr_list; /* chain on peer route list */ 370 struct list_head ksnr_list; /* chain on peer route list */
374 struct list_head ksnr_connd_list; /* chain on ksnr_connd_routes */ 371 struct list_head ksnr_connd_list; /* chain on ksnr_connd_routes */
375 struct ksock_peer *ksnr_peer; /* owning peer */ 372 struct ksock_peer *ksnr_peer; /* owning peer */
@@ -389,11 +386,11 @@ typedef struct ksock_route {
389 unsigned int ksnr_share_count; /* created explicitly? */ 386 unsigned int ksnr_share_count; /* created explicitly? */
390 int ksnr_conn_count; /* # conns established by this 387 int ksnr_conn_count; /* # conns established by this
391 * route */ 388 * route */
392} ksock_route_t; 389};
393 390
394#define SOCKNAL_KEEPALIVE_PING 1 /* cookie for keepalive ping */ 391#define SOCKNAL_KEEPALIVE_PING 1 /* cookie for keepalive ping */
395 392
396typedef struct ksock_peer { 393struct ksock_peer {
397 struct list_head ksnp_list; /* stash on global peer list */ 394 struct list_head ksnp_list; /* stash on global peer list */
398 unsigned long ksnp_last_alive; /* when (in jiffies) I was last 395 unsigned long ksnp_last_alive; /* when (in jiffies) I was last
399 * alive */ 396 * alive */
@@ -420,49 +417,49 @@ typedef struct ksock_peer {
420 417
421 /* preferred local interfaces */ 418 /* preferred local interfaces */
422 __u32 ksnp_passive_ips[LNET_MAX_INTERFACES]; 419 __u32 ksnp_passive_ips[LNET_MAX_INTERFACES];
423} ksock_peer_t; 420};
424 421
425typedef struct ksock_connreq { 422struct ksock_connreq {
426 struct list_head ksncr_list; /* stash on ksnd_connd_connreqs */ 423 struct list_head ksncr_list; /* stash on ksnd_connd_connreqs */
427 lnet_ni_t *ksncr_ni; /* chosen NI */ 424 lnet_ni_t *ksncr_ni; /* chosen NI */
428 struct socket *ksncr_sock; /* accepted socket */ 425 struct socket *ksncr_sock; /* accepted socket */
429} ksock_connreq_t; 426};
430 427
431extern ksock_nal_data_t ksocknal_data; 428extern struct ksock_nal_data ksocknal_data;
432extern ksock_tunables_t ksocknal_tunables; 429extern struct ksock_tunables ksocknal_tunables;
433 430
434#define SOCKNAL_MATCH_NO 0 /* TX can't match type of connection */ 431#define SOCKNAL_MATCH_NO 0 /* TX can't match type of connection */
435#define SOCKNAL_MATCH_YES 1 /* TX matches type of connection */ 432#define SOCKNAL_MATCH_YES 1 /* TX matches type of connection */
436#define SOCKNAL_MATCH_MAY 2 /* TX can be sent on the connection, but not 433#define SOCKNAL_MATCH_MAY 2 /* TX can be sent on the connection, but not
437 * preferred */ 434 * preferred */
438 435
439typedef struct ksock_proto { 436struct ksock_proto {
440 /* version number of protocol */ 437 /* version number of protocol */
441 int pro_version; 438 int pro_version;
442 439
443 /* handshake function */ 440 /* handshake function */
444 int (*pro_send_hello)(ksock_conn_t *, ksock_hello_msg_t *); 441 int (*pro_send_hello)(struct ksock_conn *, ksock_hello_msg_t *);
445 442
446 /* handshake function */ 443 /* handshake function */
447 int (*pro_recv_hello)(ksock_conn_t *, ksock_hello_msg_t *, int); 444 int (*pro_recv_hello)(struct ksock_conn *, ksock_hello_msg_t *, int);
448 445
449 /* message pack */ 446 /* message pack */
450 void (*pro_pack)(ksock_tx_t *); 447 void (*pro_pack)(struct ksock_tx *);
451 448
452 /* message unpack */ 449 /* message unpack */
453 void (*pro_unpack)(ksock_msg_t *); 450 void (*pro_unpack)(ksock_msg_t *);
454 451
455 /* queue tx on the connection */ 452 /* queue tx on the connection */
456 ksock_tx_t *(*pro_queue_tx_msg)(ksock_conn_t *, ksock_tx_t *); 453 struct ksock_tx *(*pro_queue_tx_msg)(struct ksock_conn *, struct ksock_tx *);
457 454
458 /* queue ZC ack on the connection */ 455 /* queue ZC ack on the connection */
459 int (*pro_queue_tx_zcack)(ksock_conn_t *, ksock_tx_t *, __u64); 456 int (*pro_queue_tx_zcack)(struct ksock_conn *, struct ksock_tx *, __u64);
460 457
461 /* handle ZC request */ 458 /* handle ZC request */
462 int (*pro_handle_zcreq)(ksock_conn_t *, __u64, int); 459 int (*pro_handle_zcreq)(struct ksock_conn *, __u64, int);
463 460
464 /* handle ZC ACK */ 461 /* handle ZC ACK */
465 int (*pro_handle_zcack)(ksock_conn_t *, __u64, __u64); 462 int (*pro_handle_zcack)(struct ksock_conn *, __u64, __u64);
466 463
467 /* 464 /*
468 * msg type matches the connection type: 465 * msg type matches the connection type:
@@ -471,12 +468,12 @@ typedef struct ksock_proto {
471 * return MATCH_YES : matching type 468 * return MATCH_YES : matching type
472 * return MATCH_MAY : can be backup 469 * return MATCH_MAY : can be backup
473 */ 470 */
474 int (*pro_match_tx)(ksock_conn_t *, ksock_tx_t *, int); 471 int (*pro_match_tx)(struct ksock_conn *, struct ksock_tx *, int);
475} ksock_proto_t; 472};
476 473
477extern ksock_proto_t ksocknal_protocol_v1x; 474extern struct ksock_proto ksocknal_protocol_v1x;
478extern ksock_proto_t ksocknal_protocol_v2x; 475extern struct ksock_proto ksocknal_protocol_v2x;
479extern ksock_proto_t ksocknal_protocol_v3x; 476extern struct ksock_proto ksocknal_protocol_v3x;
480 477
481#define KSOCK_PROTO_V1_MAJOR LNET_PROTO_TCP_VERSION_MAJOR 478#define KSOCK_PROTO_V1_MAJOR LNET_PROTO_TCP_VERSION_MAJOR
482#define KSOCK_PROTO_V1_MINOR LNET_PROTO_TCP_VERSION_MINOR 479#define KSOCK_PROTO_V1_MINOR LNET_PROTO_TCP_VERSION_MINOR
@@ -517,17 +514,17 @@ ksocknal_nid2peerlist(lnet_nid_t nid)
517} 514}
518 515
519static inline void 516static inline void
520ksocknal_conn_addref(ksock_conn_t *conn) 517ksocknal_conn_addref(struct ksock_conn *conn)
521{ 518{
522 LASSERT(atomic_read(&conn->ksnc_conn_refcount) > 0); 519 LASSERT(atomic_read(&conn->ksnc_conn_refcount) > 0);
523 atomic_inc(&conn->ksnc_conn_refcount); 520 atomic_inc(&conn->ksnc_conn_refcount);
524} 521}
525 522
526void ksocknal_queue_zombie_conn(ksock_conn_t *conn); 523void ksocknal_queue_zombie_conn(struct ksock_conn *conn);
527void ksocknal_finalize_zcreq(ksock_conn_t *conn); 524void ksocknal_finalize_zcreq(struct ksock_conn *conn);
528 525
529static inline void 526static inline void
530ksocknal_conn_decref(ksock_conn_t *conn) 527ksocknal_conn_decref(struct ksock_conn *conn)
531{ 528{
532 LASSERT(atomic_read(&conn->ksnc_conn_refcount) > 0); 529 LASSERT(atomic_read(&conn->ksnc_conn_refcount) > 0);
533 if (atomic_dec_and_test(&conn->ksnc_conn_refcount)) 530 if (atomic_dec_and_test(&conn->ksnc_conn_refcount))
@@ -535,7 +532,7 @@ ksocknal_conn_decref(ksock_conn_t *conn)
535} 532}
536 533
537static inline int 534static inline int
538ksocknal_connsock_addref(ksock_conn_t *conn) 535ksocknal_connsock_addref(struct ksock_conn *conn)
539{ 536{
540 int rc = -ESHUTDOWN; 537 int rc = -ESHUTDOWN;
541 538
@@ -551,7 +548,7 @@ ksocknal_connsock_addref(ksock_conn_t *conn)
551} 548}
552 549
553static inline void 550static inline void
554ksocknal_connsock_decref(ksock_conn_t *conn) 551ksocknal_connsock_decref(struct ksock_conn *conn)
555{ 552{
556 LASSERT(atomic_read(&conn->ksnc_sock_refcount) > 0); 553 LASSERT(atomic_read(&conn->ksnc_sock_refcount) > 0);
557 if (atomic_dec_and_test(&conn->ksnc_sock_refcount)) { 554 if (atomic_dec_and_test(&conn->ksnc_sock_refcount)) {
@@ -563,17 +560,17 @@ ksocknal_connsock_decref(ksock_conn_t *conn)
563} 560}
564 561
565static inline void 562static inline void
566ksocknal_tx_addref(ksock_tx_t *tx) 563ksocknal_tx_addref(struct ksock_tx *tx)
567{ 564{
568 LASSERT(atomic_read(&tx->tx_refcount) > 0); 565 LASSERT(atomic_read(&tx->tx_refcount) > 0);
569 atomic_inc(&tx->tx_refcount); 566 atomic_inc(&tx->tx_refcount);
570} 567}
571 568
572void ksocknal_tx_prep(ksock_conn_t *, ksock_tx_t *tx); 569void ksocknal_tx_prep(struct ksock_conn *, struct ksock_tx *tx);
573void ksocknal_tx_done(lnet_ni_t *ni, ksock_tx_t *tx); 570void ksocknal_tx_done(lnet_ni_t *ni, struct ksock_tx *tx);
574 571
575static inline void 572static inline void
576ksocknal_tx_decref(ksock_tx_t *tx) 573ksocknal_tx_decref(struct ksock_tx *tx)
577{ 574{
578 LASSERT(atomic_read(&tx->tx_refcount) > 0); 575 LASSERT(atomic_read(&tx->tx_refcount) > 0);
579 if (atomic_dec_and_test(&tx->tx_refcount)) 576 if (atomic_dec_and_test(&tx->tx_refcount))
@@ -581,16 +578,16 @@ ksocknal_tx_decref(ksock_tx_t *tx)
581} 578}
582 579
583static inline void 580static inline void
584ksocknal_route_addref(ksock_route_t *route) 581ksocknal_route_addref(struct ksock_route *route)
585{ 582{
586 LASSERT(atomic_read(&route->ksnr_refcount) > 0); 583 LASSERT(atomic_read(&route->ksnr_refcount) > 0);
587 atomic_inc(&route->ksnr_refcount); 584 atomic_inc(&route->ksnr_refcount);
588} 585}
589 586
590void ksocknal_destroy_route(ksock_route_t *route); 587void ksocknal_destroy_route(struct ksock_route *route);
591 588
592static inline void 589static inline void
593ksocknal_route_decref(ksock_route_t *route) 590ksocknal_route_decref(struct ksock_route *route)
594{ 591{
595 LASSERT(atomic_read(&route->ksnr_refcount) > 0); 592 LASSERT(atomic_read(&route->ksnr_refcount) > 0);
596 if (atomic_dec_and_test(&route->ksnr_refcount)) 593 if (atomic_dec_and_test(&route->ksnr_refcount))
@@ -598,16 +595,16 @@ ksocknal_route_decref(ksock_route_t *route)
598} 595}
599 596
600static inline void 597static inline void
601ksocknal_peer_addref(ksock_peer_t *peer) 598ksocknal_peer_addref(struct ksock_peer *peer)
602{ 599{
603 LASSERT(atomic_read(&peer->ksnp_refcount) > 0); 600 LASSERT(atomic_read(&peer->ksnp_refcount) > 0);
604 atomic_inc(&peer->ksnp_refcount); 601 atomic_inc(&peer->ksnp_refcount);
605} 602}
606 603
607void ksocknal_destroy_peer(ksock_peer_t *peer); 604void ksocknal_destroy_peer(struct ksock_peer *peer);
608 605
609static inline void 606static inline void
610ksocknal_peer_decref(ksock_peer_t *peer) 607ksocknal_peer_decref(struct ksock_peer *peer)
611{ 608{
612 LASSERT(atomic_read(&peer->ksnp_refcount) > 0); 609 LASSERT(atomic_read(&peer->ksnp_refcount) > 0);
613 if (atomic_dec_and_test(&peer->ksnp_refcount)) 610 if (atomic_dec_and_test(&peer->ksnp_refcount))
@@ -625,71 +622,71 @@ int ksocknal_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
625int ksocknal_accept(lnet_ni_t *ni, struct socket *sock); 622int ksocknal_accept(lnet_ni_t *ni, struct socket *sock);
626 623
627int ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip, int port); 624int ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ip, int port);
628ksock_peer_t *ksocknal_find_peer_locked(lnet_ni_t *ni, lnet_process_id_t id); 625struct ksock_peer *ksocknal_find_peer_locked(lnet_ni_t *ni, lnet_process_id_t id);
629ksock_peer_t *ksocknal_find_peer(lnet_ni_t *ni, lnet_process_id_t id); 626struct ksock_peer *ksocknal_find_peer(lnet_ni_t *ni, lnet_process_id_t id);
630void ksocknal_peer_failed(ksock_peer_t *peer); 627void ksocknal_peer_failed(struct ksock_peer *peer);
631int ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route, 628int ksocknal_create_conn(lnet_ni_t *ni, struct ksock_route *route,
632 struct socket *sock, int type); 629 struct socket *sock, int type);
633void ksocknal_close_conn_locked(ksock_conn_t *conn, int why); 630void ksocknal_close_conn_locked(struct ksock_conn *conn, int why);
634void ksocknal_terminate_conn(ksock_conn_t *conn); 631void ksocknal_terminate_conn(struct ksock_conn *conn);
635void ksocknal_destroy_conn(ksock_conn_t *conn); 632void ksocknal_destroy_conn(struct ksock_conn *conn);
636int ksocknal_close_peer_conns_locked(ksock_peer_t *peer, 633int ksocknal_close_peer_conns_locked(struct ksock_peer *peer,
637 __u32 ipaddr, int why); 634 __u32 ipaddr, int why);
638int ksocknal_close_conn_and_siblings(ksock_conn_t *conn, int why); 635int ksocknal_close_conn_and_siblings(struct ksock_conn *conn, int why);
639int ksocknal_close_matching_conns(lnet_process_id_t id, __u32 ipaddr); 636int ksocknal_close_matching_conns(lnet_process_id_t id, __u32 ipaddr);
640ksock_conn_t *ksocknal_find_conn_locked(ksock_peer_t *peer, 637struct ksock_conn *ksocknal_find_conn_locked(struct ksock_peer *peer,
641 ksock_tx_t *tx, int nonblk); 638 struct ksock_tx *tx, int nonblk);
642 639
643int ksocknal_launch_packet(lnet_ni_t *ni, ksock_tx_t *tx, 640int ksocknal_launch_packet(lnet_ni_t *ni, struct ksock_tx *tx,
644 lnet_process_id_t id); 641 lnet_process_id_t id);
645ksock_tx_t *ksocknal_alloc_tx(int type, int size); 642struct ksock_tx *ksocknal_alloc_tx(int type, int size);
646void ksocknal_free_tx(ksock_tx_t *tx); 643void ksocknal_free_tx(struct ksock_tx *tx);
647ksock_tx_t *ksocknal_alloc_tx_noop(__u64 cookie, int nonblk); 644struct ksock_tx *ksocknal_alloc_tx_noop(__u64 cookie, int nonblk);
648void ksocknal_next_tx_carrier(ksock_conn_t *conn); 645void ksocknal_next_tx_carrier(struct ksock_conn *conn);
649void ksocknal_queue_tx_locked(ksock_tx_t *tx, ksock_conn_t *conn); 646void ksocknal_queue_tx_locked(struct ksock_tx *tx, struct ksock_conn *conn);
650void ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int error); 647void ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int error);
651void ksocknal_notify(lnet_ni_t *ni, lnet_nid_t gw_nid, int alive); 648void ksocknal_notify(lnet_ni_t *ni, lnet_nid_t gw_nid, int alive);
652void ksocknal_query(struct lnet_ni *ni, lnet_nid_t nid, unsigned long *when); 649void ksocknal_query(struct lnet_ni *ni, lnet_nid_t nid, unsigned long *when);
653int ksocknal_thread_start(int (*fn)(void *arg), void *arg, char *name); 650int ksocknal_thread_start(int (*fn)(void *arg), void *arg, char *name);
654void ksocknal_thread_fini(void); 651void ksocknal_thread_fini(void);
655void ksocknal_launch_all_connections_locked(ksock_peer_t *peer); 652void ksocknal_launch_all_connections_locked(struct ksock_peer *peer);
656ksock_route_t *ksocknal_find_connectable_route_locked(ksock_peer_t *peer); 653struct ksock_route *ksocknal_find_connectable_route_locked(struct ksock_peer *peer);
657ksock_route_t *ksocknal_find_connecting_route_locked(ksock_peer_t *peer); 654struct ksock_route *ksocknal_find_connecting_route_locked(struct ksock_peer *peer);
658int ksocknal_new_packet(ksock_conn_t *conn, int skip); 655int ksocknal_new_packet(struct ksock_conn *conn, int skip);
659int ksocknal_scheduler(void *arg); 656int ksocknal_scheduler(void *arg);
660int ksocknal_connd(void *arg); 657int ksocknal_connd(void *arg);
661int ksocknal_reaper(void *arg); 658int ksocknal_reaper(void *arg);
662int ksocknal_send_hello(lnet_ni_t *ni, ksock_conn_t *conn, 659int ksocknal_send_hello(lnet_ni_t *ni, struct ksock_conn *conn,
663 lnet_nid_t peer_nid, ksock_hello_msg_t *hello); 660 lnet_nid_t peer_nid, ksock_hello_msg_t *hello);
664int ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn, 661int ksocknal_recv_hello(lnet_ni_t *ni, struct ksock_conn *conn,
665 ksock_hello_msg_t *hello, lnet_process_id_t *id, 662 ksock_hello_msg_t *hello, lnet_process_id_t *id,
666 __u64 *incarnation); 663 __u64 *incarnation);
667void ksocknal_read_callback(ksock_conn_t *conn); 664void ksocknal_read_callback(struct ksock_conn *conn);
668void ksocknal_write_callback(ksock_conn_t *conn); 665void ksocknal_write_callback(struct ksock_conn *conn);
669 666
670int ksocknal_lib_zc_capable(ksock_conn_t *conn); 667int ksocknal_lib_zc_capable(struct ksock_conn *conn);
671void ksocknal_lib_save_callback(struct socket *sock, ksock_conn_t *conn); 668void ksocknal_lib_save_callback(struct socket *sock, struct ksock_conn *conn);
672void ksocknal_lib_set_callback(struct socket *sock, ksock_conn_t *conn); 669void ksocknal_lib_set_callback(struct socket *sock, struct ksock_conn *conn);
673void ksocknal_lib_reset_callback(struct socket *sock, ksock_conn_t *conn); 670void ksocknal_lib_reset_callback(struct socket *sock, struct ksock_conn *conn);
674void ksocknal_lib_push_conn(ksock_conn_t *conn); 671void ksocknal_lib_push_conn(struct ksock_conn *conn);
675int ksocknal_lib_get_conn_addrs(ksock_conn_t *conn); 672int ksocknal_lib_get_conn_addrs(struct ksock_conn *conn);
676int ksocknal_lib_setup_sock(struct socket *so); 673int ksocknal_lib_setup_sock(struct socket *so);
677int ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx); 674int ksocknal_lib_send_iov(struct ksock_conn *conn, struct ksock_tx *tx);
678int ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx); 675int ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx);
679void ksocknal_lib_eager_ack(ksock_conn_t *conn); 676void ksocknal_lib_eager_ack(struct ksock_conn *conn);
680int ksocknal_lib_recv_iov(ksock_conn_t *conn); 677int ksocknal_lib_recv_iov(struct ksock_conn *conn);
681int ksocknal_lib_recv_kiov(ksock_conn_t *conn); 678int ksocknal_lib_recv_kiov(struct ksock_conn *conn);
682int ksocknal_lib_get_conn_tunables(ksock_conn_t *conn, int *txmem, 679int ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem,
683 int *rxmem, int *nagle); 680 int *rxmem, int *nagle);
684 681
685void ksocknal_read_callback(ksock_conn_t *conn); 682void ksocknal_read_callback(struct ksock_conn *conn);
686void ksocknal_write_callback(ksock_conn_t *conn); 683void ksocknal_write_callback(struct ksock_conn *conn);
687 684
688int ksocknal_tunables_init(void); 685int ksocknal_tunables_init(void);
689 686
690void ksocknal_lib_csum_tx(ksock_tx_t *tx); 687void ksocknal_lib_csum_tx(struct ksock_tx *tx);
691 688
692int ksocknal_lib_memory_pressure(ksock_conn_t *conn); 689int ksocknal_lib_memory_pressure(struct ksock_conn *conn);
693int ksocknal_lib_bind_thread_to_cpu(int id); 690int ksocknal_lib_bind_thread_to_cpu(int id);
694 691
695#endif /* _SOCKLND_SOCKLND_H_ */ 692#endif /* _SOCKLND_SOCKLND_H_ */
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index 976fd78926e0..303576d815c6 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -23,10 +23,10 @@
23 23
24#include "socklnd.h" 24#include "socklnd.h"
25 25
26ksock_tx_t * 26struct ksock_tx *
27ksocknal_alloc_tx(int type, int size) 27ksocknal_alloc_tx(int type, int size)
28{ 28{
29 ksock_tx_t *tx = NULL; 29 struct ksock_tx *tx = NULL;
30 30
31 if (type == KSOCK_MSG_NOOP) { 31 if (type == KSOCK_MSG_NOOP) {
32 LASSERT(size == KSOCK_NOOP_TX_SIZE); 32 LASSERT(size == KSOCK_NOOP_TX_SIZE);
@@ -36,7 +36,7 @@ ksocknal_alloc_tx(int type, int size)
36 36
37 if (!list_empty(&ksocknal_data.ksnd_idle_noop_txs)) { 37 if (!list_empty(&ksocknal_data.ksnd_idle_noop_txs)) {
38 tx = list_entry(ksocknal_data.ksnd_idle_noop_txs. \ 38 tx = list_entry(ksocknal_data.ksnd_idle_noop_txs. \
39 next, ksock_tx_t, tx_list); 39 next, struct ksock_tx, tx_list);
40 LASSERT(tx->tx_desc_size == size); 40 LASSERT(tx->tx_desc_size == size);
41 list_del(&tx->tx_list); 41 list_del(&tx->tx_list);
42 } 42 }
@@ -61,10 +61,10 @@ ksocknal_alloc_tx(int type, int size)
61 return tx; 61 return tx;
62} 62}
63 63
64ksock_tx_t * 64struct ksock_tx *
65ksocknal_alloc_tx_noop(__u64 cookie, int nonblk) 65ksocknal_alloc_tx_noop(__u64 cookie, int nonblk)
66{ 66{
67 ksock_tx_t *tx; 67 struct ksock_tx *tx;
68 68
69 tx = ksocknal_alloc_tx(KSOCK_MSG_NOOP, KSOCK_NOOP_TX_SIZE); 69 tx = ksocknal_alloc_tx(KSOCK_MSG_NOOP, KSOCK_NOOP_TX_SIZE);
70 if (!tx) { 70 if (!tx) {
@@ -87,7 +87,7 @@ ksocknal_alloc_tx_noop(__u64 cookie, int nonblk)
87} 87}
88 88
89void 89void
90ksocknal_free_tx(ksock_tx_t *tx) 90ksocknal_free_tx(struct ksock_tx *tx)
91{ 91{
92 atomic_dec(&ksocknal_data.ksnd_nactive_txs); 92 atomic_dec(&ksocknal_data.ksnd_nactive_txs);
93 93
@@ -104,7 +104,7 @@ ksocknal_free_tx(ksock_tx_t *tx)
104} 104}
105 105
106static int 106static int
107ksocknal_send_iov(ksock_conn_t *conn, ksock_tx_t *tx) 107ksocknal_send_iov(struct ksock_conn *conn, struct ksock_tx *tx)
108{ 108{
109 struct kvec *iov = tx->tx_iov; 109 struct kvec *iov = tx->tx_iov;
110 int nob; 110 int nob;
@@ -126,7 +126,7 @@ ksocknal_send_iov(ksock_conn_t *conn, ksock_tx_t *tx)
126 do { 126 do {
127 LASSERT(tx->tx_niov > 0); 127 LASSERT(tx->tx_niov > 0);
128 128
129 if (nob < (int) iov->iov_len) { 129 if (nob < (int)iov->iov_len) {
130 iov->iov_base = (void *)((char *)iov->iov_base + nob); 130 iov->iov_base = (void *)((char *)iov->iov_base + nob);
131 iov->iov_len -= nob; 131 iov->iov_len -= nob;
132 return rc; 132 return rc;
@@ -141,7 +141,7 @@ ksocknal_send_iov(ksock_conn_t *conn, ksock_tx_t *tx)
141} 141}
142 142
143static int 143static int
144ksocknal_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx) 144ksocknal_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx)
145{ 145{
146 lnet_kiov_t *kiov = tx->tx_kiov; 146 lnet_kiov_t *kiov = tx->tx_kiov;
147 int nob; 147 int nob;
@@ -179,7 +179,7 @@ ksocknal_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx)
179} 179}
180 180
181static int 181static int
182ksocknal_transmit(ksock_conn_t *conn, ksock_tx_t *tx) 182ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx)
183{ 183{
184 int rc; 184 int rc;
185 int bufnob; 185 int bufnob;
@@ -247,7 +247,7 @@ ksocknal_transmit(ksock_conn_t *conn, ksock_tx_t *tx)
247} 247}
248 248
249static int 249static int
250ksocknal_recv_iov(ksock_conn_t *conn) 250ksocknal_recv_iov(struct ksock_conn *conn)
251{ 251{
252 struct kvec *iov = conn->ksnc_rx_iov; 252 struct kvec *iov = conn->ksnc_rx_iov;
253 int nob; 253 int nob;
@@ -294,7 +294,7 @@ ksocknal_recv_iov(ksock_conn_t *conn)
294} 294}
295 295
296static int 296static int
297ksocknal_recv_kiov(ksock_conn_t *conn) 297ksocknal_recv_kiov(struct ksock_conn *conn)
298{ 298{
299 lnet_kiov_t *kiov = conn->ksnc_rx_kiov; 299 lnet_kiov_t *kiov = conn->ksnc_rx_kiov;
300 int nob; 300 int nob;
@@ -326,7 +326,7 @@ ksocknal_recv_kiov(ksock_conn_t *conn)
326 do { 326 do {
327 LASSERT(conn->ksnc_rx_nkiov > 0); 327 LASSERT(conn->ksnc_rx_nkiov > 0);
328 328
329 if (nob < (int) kiov->kiov_len) { 329 if (nob < (int)kiov->kiov_len) {
330 kiov->kiov_offset += nob; 330 kiov->kiov_offset += nob;
331 kiov->kiov_len -= nob; 331 kiov->kiov_len -= nob;
332 return -EAGAIN; 332 return -EAGAIN;
@@ -341,7 +341,7 @@ ksocknal_recv_kiov(ksock_conn_t *conn)
341} 341}
342 342
343static int 343static int
344ksocknal_receive(ksock_conn_t *conn) 344ksocknal_receive(struct ksock_conn *conn)
345{ 345{
346 /* 346 /*
347 * Return 1 on success, 0 on EOF, < 0 on error. 347 * Return 1 on success, 0 on EOF, < 0 on error.
@@ -391,7 +391,7 @@ ksocknal_receive(ksock_conn_t *conn)
391} 391}
392 392
393void 393void
394ksocknal_tx_done(lnet_ni_t *ni, ksock_tx_t *tx) 394ksocknal_tx_done(lnet_ni_t *ni, struct ksock_tx *tx)
395{ 395{
396 lnet_msg_t *lnetmsg = tx->tx_lnetmsg; 396 lnet_msg_t *lnetmsg = tx->tx_lnetmsg;
397 int rc = (!tx->tx_resid && !tx->tx_zc_aborted) ? 0 : -EIO; 397 int rc = (!tx->tx_resid && !tx->tx_zc_aborted) ? 0 : -EIO;
@@ -412,10 +412,10 @@ ksocknal_tx_done(lnet_ni_t *ni, ksock_tx_t *tx)
412void 412void
413ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int error) 413ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int error)
414{ 414{
415 ksock_tx_t *tx; 415 struct ksock_tx *tx;
416 416
417 while (!list_empty(txlist)) { 417 while (!list_empty(txlist)) {
418 tx = list_entry(txlist->next, ksock_tx_t, tx_list); 418 tx = list_entry(txlist->next, struct ksock_tx, tx_list);
419 419
420 if (error && tx->tx_lnetmsg) { 420 if (error && tx->tx_lnetmsg) {
421 CNETERR("Deleting packet type %d len %d %s->%s\n", 421 CNETERR("Deleting packet type %d len %d %s->%s\n",
@@ -435,10 +435,10 @@ ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int error)
435} 435}
436 436
437static void 437static void
438ksocknal_check_zc_req(ksock_tx_t *tx) 438ksocknal_check_zc_req(struct ksock_tx *tx)
439{ 439{
440 ksock_conn_t *conn = tx->tx_conn; 440 struct ksock_conn *conn = tx->tx_conn;
441 ksock_peer_t *peer = conn->ksnc_peer; 441 struct ksock_peer *peer = conn->ksnc_peer;
442 442
443 /* 443 /*
444 * Set tx_msg.ksm_zc_cookies[0] to a unique non-zero cookie and add tx 444 * Set tx_msg.ksm_zc_cookies[0] to a unique non-zero cookie and add tx
@@ -482,9 +482,9 @@ ksocknal_check_zc_req(ksock_tx_t *tx)
482} 482}
483 483
484static void 484static void
485ksocknal_uncheck_zc_req(ksock_tx_t *tx) 485ksocknal_uncheck_zc_req(struct ksock_tx *tx)
486{ 486{
487 ksock_peer_t *peer = tx->tx_conn->ksnc_peer; 487 struct ksock_peer *peer = tx->tx_conn->ksnc_peer;
488 488
489 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP); 489 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
490 LASSERT(tx->tx_zc_capable); 490 LASSERT(tx->tx_zc_capable);
@@ -508,7 +508,7 @@ ksocknal_uncheck_zc_req(ksock_tx_t *tx)
508} 508}
509 509
510static int 510static int
511ksocknal_process_transmit(ksock_conn_t *conn, ksock_tx_t *tx) 511ksocknal_process_transmit(struct ksock_conn *conn, struct ksock_tx *tx)
512{ 512{
513 int rc; 513 int rc;
514 514
@@ -583,7 +583,7 @@ ksocknal_process_transmit(ksock_conn_t *conn, ksock_tx_t *tx)
583} 583}
584 584
585static void 585static void
586ksocknal_launch_connection_locked(ksock_route_t *route) 586ksocknal_launch_connection_locked(struct ksock_route *route)
587{ 587{
588 /* called holding write lock on ksnd_global_lock */ 588 /* called holding write lock on ksnd_global_lock */
589 589
@@ -604,9 +604,9 @@ ksocknal_launch_connection_locked(ksock_route_t *route)
604} 604}
605 605
606void 606void
607ksocknal_launch_all_connections_locked(ksock_peer_t *peer) 607ksocknal_launch_all_connections_locked(struct ksock_peer *peer)
608{ 608{
609 ksock_route_t *route; 609 struct ksock_route *route;
610 610
611 /* called holding write lock on ksnd_global_lock */ 611 /* called holding write lock on ksnd_global_lock */
612 for (;;) { 612 for (;;) {
@@ -619,18 +619,18 @@ ksocknal_launch_all_connections_locked(ksock_peer_t *peer)
619 } 619 }
620} 620}
621 621
622ksock_conn_t * 622struct ksock_conn *
623ksocknal_find_conn_locked(ksock_peer_t *peer, ksock_tx_t *tx, int nonblk) 623ksocknal_find_conn_locked(struct ksock_peer *peer, struct ksock_tx *tx, int nonblk)
624{ 624{
625 struct list_head *tmp; 625 struct list_head *tmp;
626 ksock_conn_t *conn; 626 struct ksock_conn *conn;
627 ksock_conn_t *typed = NULL; 627 struct ksock_conn *typed = NULL;
628 ksock_conn_t *fallback = NULL; 628 struct ksock_conn *fallback = NULL;
629 int tnob = 0; 629 int tnob = 0;
630 int fnob = 0; 630 int fnob = 0;
631 631
632 list_for_each(tmp, &peer->ksnp_conns) { 632 list_for_each(tmp, &peer->ksnp_conns) {
633 ksock_conn_t *c = list_entry(tmp, ksock_conn_t, ksnc_list); 633 struct ksock_conn *c = list_entry(tmp, struct ksock_conn, ksnc_list);
634 int nob = atomic_read(&c->ksnc_tx_nob) + 634 int nob = atomic_read(&c->ksnc_tx_nob) +
635 c->ksnc_sock->sk->sk_wmem_queued; 635 c->ksnc_sock->sk->sk_wmem_queued;
636 int rc; 636 int rc;
@@ -677,7 +677,7 @@ ksocknal_find_conn_locked(ksock_peer_t *peer, ksock_tx_t *tx, int nonblk)
677} 677}
678 678
679void 679void
680ksocknal_tx_prep(ksock_conn_t *conn, ksock_tx_t *tx) 680ksocknal_tx_prep(struct ksock_conn *conn, struct ksock_tx *tx)
681{ 681{
682 conn->ksnc_proto->pro_pack(tx); 682 conn->ksnc_proto->pro_pack(tx);
683 683
@@ -687,11 +687,11 @@ ksocknal_tx_prep(ksock_conn_t *conn, ksock_tx_t *tx)
687} 687}
688 688
689void 689void
690ksocknal_queue_tx_locked(ksock_tx_t *tx, ksock_conn_t *conn) 690ksocknal_queue_tx_locked(struct ksock_tx *tx, struct ksock_conn *conn)
691{ 691{
692 ksock_sched_t *sched = conn->ksnc_scheduler; 692 struct ksock_sched *sched = conn->ksnc_scheduler;
693 ksock_msg_t *msg = &tx->tx_msg; 693 ksock_msg_t *msg = &tx->tx_msg;
694 ksock_tx_t *ztx = NULL; 694 struct ksock_tx *ztx = NULL;
695 int bufnob = 0; 695 int bufnob = 0;
696 696
697 /* 697 /*
@@ -784,15 +784,15 @@ ksocknal_queue_tx_locked(ksock_tx_t *tx, ksock_conn_t *conn)
784 spin_unlock_bh(&sched->kss_lock); 784 spin_unlock_bh(&sched->kss_lock);
785} 785}
786 786
787ksock_route_t * 787struct ksock_route *
788ksocknal_find_connectable_route_locked(ksock_peer_t *peer) 788ksocknal_find_connectable_route_locked(struct ksock_peer *peer)
789{ 789{
790 unsigned long now = cfs_time_current(); 790 unsigned long now = cfs_time_current();
791 struct list_head *tmp; 791 struct list_head *tmp;
792 ksock_route_t *route; 792 struct ksock_route *route;
793 793
794 list_for_each(tmp, &peer->ksnp_routes) { 794 list_for_each(tmp, &peer->ksnp_routes) {
795 route = list_entry(tmp, ksock_route_t, ksnr_list); 795 route = list_entry(tmp, struct ksock_route, ksnr_list);
796 796
797 LASSERT(!route->ksnr_connecting || route->ksnr_scheduled); 797 LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
798 798
@@ -820,14 +820,14 @@ ksocknal_find_connectable_route_locked(ksock_peer_t *peer)
820 return NULL; 820 return NULL;
821} 821}
822 822
823ksock_route_t * 823struct ksock_route *
824ksocknal_find_connecting_route_locked(ksock_peer_t *peer) 824ksocknal_find_connecting_route_locked(struct ksock_peer *peer)
825{ 825{
826 struct list_head *tmp; 826 struct list_head *tmp;
827 ksock_route_t *route; 827 struct ksock_route *route;
828 828
829 list_for_each(tmp, &peer->ksnp_routes) { 829 list_for_each(tmp, &peer->ksnp_routes) {
830 route = list_entry(tmp, ksock_route_t, ksnr_list); 830 route = list_entry(tmp, struct ksock_route, ksnr_list);
831 831
832 LASSERT(!route->ksnr_connecting || route->ksnr_scheduled); 832 LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
833 833
@@ -839,10 +839,10 @@ ksocknal_find_connecting_route_locked(ksock_peer_t *peer)
839} 839}
840 840
841int 841int
842ksocknal_launch_packet(lnet_ni_t *ni, ksock_tx_t *tx, lnet_process_id_t id) 842ksocknal_launch_packet(lnet_ni_t *ni, struct ksock_tx *tx, lnet_process_id_t id)
843{ 843{
844 ksock_peer_t *peer; 844 struct ksock_peer *peer;
845 ksock_conn_t *conn; 845 struct ksock_conn *conn;
846 rwlock_t *g_lock; 846 rwlock_t *g_lock;
847 int retry; 847 int retry;
848 int rc; 848 int rc;
@@ -942,7 +942,7 @@ ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
942 lnet_kiov_t *payload_kiov = lntmsg->msg_kiov; 942 lnet_kiov_t *payload_kiov = lntmsg->msg_kiov;
943 unsigned int payload_offset = lntmsg->msg_offset; 943 unsigned int payload_offset = lntmsg->msg_offset;
944 unsigned int payload_nob = lntmsg->msg_len; 944 unsigned int payload_nob = lntmsg->msg_len;
945 ksock_tx_t *tx; 945 struct ksock_tx *tx;
946 int desc_size; 946 int desc_size;
947 int rc; 947 int rc;
948 948
@@ -960,10 +960,10 @@ ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
960 LASSERT(!in_interrupt()); 960 LASSERT(!in_interrupt());
961 961
962 if (payload_iov) 962 if (payload_iov)
963 desc_size = offsetof(ksock_tx_t, 963 desc_size = offsetof(struct ksock_tx,
964 tx_frags.virt.iov[1 + payload_niov]); 964 tx_frags.virt.iov[1 + payload_niov]);
965 else 965 else
966 desc_size = offsetof(ksock_tx_t, 966 desc_size = offsetof(struct ksock_tx,
967 tx_frags.paged.kiov[payload_niov]); 967 tx_frags.paged.kiov[payload_niov]);
968 968
969 if (lntmsg->msg_vmflush) 969 if (lntmsg->msg_vmflush)
@@ -1037,7 +1037,7 @@ ksocknal_thread_fini(void)
1037} 1037}
1038 1038
1039int 1039int
1040ksocknal_new_packet(ksock_conn_t *conn, int nob_to_skip) 1040ksocknal_new_packet(struct ksock_conn *conn, int nob_to_skip)
1041{ 1041{
1042 static char ksocknal_slop_buffer[4096]; 1042 static char ksocknal_slop_buffer[4096];
1043 1043
@@ -1120,7 +1120,7 @@ ksocknal_new_packet(ksock_conn_t *conn, int nob_to_skip)
1120} 1120}
1121 1121
1122static int 1122static int
1123ksocknal_process_receive(ksock_conn_t *conn) 1123ksocknal_process_receive(struct ksock_conn *conn)
1124{ 1124{
1125 lnet_hdr_t *lhdr; 1125 lnet_hdr_t *lhdr;
1126 lnet_process_id_t *id; 1126 lnet_process_id_t *id;
@@ -1328,8 +1328,8 @@ ksocknal_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
1328 unsigned int niov, struct kvec *iov, lnet_kiov_t *kiov, 1328 unsigned int niov, struct kvec *iov, lnet_kiov_t *kiov,
1329 unsigned int offset, unsigned int mlen, unsigned int rlen) 1329 unsigned int offset, unsigned int mlen, unsigned int rlen)
1330{ 1330{
1331 ksock_conn_t *conn = private; 1331 struct ksock_conn *conn = private;
1332 ksock_sched_t *sched = conn->ksnc_scheduler; 1332 struct ksock_sched *sched = conn->ksnc_scheduler;
1333 1333
1334 LASSERT(mlen <= rlen); 1334 LASSERT(mlen <= rlen);
1335 LASSERT(niov <= LNET_MAX_IOV); 1335 LASSERT(niov <= LNET_MAX_IOV);
@@ -1382,7 +1382,7 @@ ksocknal_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
1382} 1382}
1383 1383
1384static inline int 1384static inline int
1385ksocknal_sched_cansleep(ksock_sched_t *sched) 1385ksocknal_sched_cansleep(struct ksock_sched *sched)
1386{ 1386{
1387 int rc; 1387 int rc;
1388 1388
@@ -1399,9 +1399,9 @@ ksocknal_sched_cansleep(ksock_sched_t *sched)
1399int ksocknal_scheduler(void *arg) 1399int ksocknal_scheduler(void *arg)
1400{ 1400{
1401 struct ksock_sched_info *info; 1401 struct ksock_sched_info *info;
1402 ksock_sched_t *sched; 1402 struct ksock_sched *sched;
1403 ksock_conn_t *conn; 1403 struct ksock_conn *conn;
1404 ksock_tx_t *tx; 1404 struct ksock_tx *tx;
1405 int rc; 1405 int rc;
1406 int nloops = 0; 1406 int nloops = 0;
1407 long id = (long)arg; 1407 long id = (long)arg;
@@ -1426,7 +1426,7 @@ int ksocknal_scheduler(void *arg)
1426 1426
1427 if (!list_empty(&sched->kss_rx_conns)) { 1427 if (!list_empty(&sched->kss_rx_conns)) {
1428 conn = list_entry(sched->kss_rx_conns.next, 1428 conn = list_entry(sched->kss_rx_conns.next,
1429 ksock_conn_t, ksnc_rx_list); 1429 struct ksock_conn, ksnc_rx_list);
1430 list_del(&conn->ksnc_rx_list); 1430 list_del(&conn->ksnc_rx_list);
1431 1431
1432 LASSERT(conn->ksnc_rx_scheduled); 1432 LASSERT(conn->ksnc_rx_scheduled);
@@ -1481,7 +1481,7 @@ int ksocknal_scheduler(void *arg)
1481 } 1481 }
1482 1482
1483 conn = list_entry(sched->kss_tx_conns.next, 1483 conn = list_entry(sched->kss_tx_conns.next,
1484 ksock_conn_t, ksnc_tx_list); 1484 struct ksock_conn, ksnc_tx_list);
1485 list_del(&conn->ksnc_tx_list); 1485 list_del(&conn->ksnc_tx_list);
1486 1486
1487 LASSERT(conn->ksnc_tx_scheduled); 1487 LASSERT(conn->ksnc_tx_scheduled);
@@ -1489,7 +1489,7 @@ int ksocknal_scheduler(void *arg)
1489 LASSERT(!list_empty(&conn->ksnc_tx_queue)); 1489 LASSERT(!list_empty(&conn->ksnc_tx_queue));
1490 1490
1491 tx = list_entry(conn->ksnc_tx_queue.next, 1491 tx = list_entry(conn->ksnc_tx_queue.next,
1492 ksock_tx_t, tx_list); 1492 struct ksock_tx, tx_list);
1493 1493
1494 if (conn->ksnc_tx_carrier == tx) 1494 if (conn->ksnc_tx_carrier == tx)
1495 ksocknal_next_tx_carrier(conn); 1495 ksocknal_next_tx_carrier(conn);
@@ -1575,9 +1575,9 @@ int ksocknal_scheduler(void *arg)
1575 * Add connection to kss_rx_conns of scheduler 1575 * Add connection to kss_rx_conns of scheduler
1576 * and wakeup the scheduler. 1576 * and wakeup the scheduler.
1577 */ 1577 */
1578void ksocknal_read_callback(ksock_conn_t *conn) 1578void ksocknal_read_callback(struct ksock_conn *conn)
1579{ 1579{
1580 ksock_sched_t *sched; 1580 struct ksock_sched *sched;
1581 1581
1582 sched = conn->ksnc_scheduler; 1582 sched = conn->ksnc_scheduler;
1583 1583
@@ -1600,9 +1600,9 @@ void ksocknal_read_callback(ksock_conn_t *conn)
1600 * Add connection to kss_tx_conns of scheduler 1600 * Add connection to kss_tx_conns of scheduler
1601 * and wakeup the scheduler. 1601 * and wakeup the scheduler.
1602 */ 1602 */
1603void ksocknal_write_callback(ksock_conn_t *conn) 1603void ksocknal_write_callback(struct ksock_conn *conn)
1604{ 1604{
1605 ksock_sched_t *sched; 1605 struct ksock_sched *sched;
1606 1606
1607 sched = conn->ksnc_scheduler; 1607 sched = conn->ksnc_scheduler;
1608 1608
@@ -1623,7 +1623,7 @@ void ksocknal_write_callback(ksock_conn_t *conn)
1623 spin_unlock_bh(&sched->kss_lock); 1623 spin_unlock_bh(&sched->kss_lock);
1624} 1624}
1625 1625
1626static ksock_proto_t * 1626static struct ksock_proto *
1627ksocknal_parse_proto_version(ksock_hello_msg_t *hello) 1627ksocknal_parse_proto_version(ksock_hello_msg_t *hello)
1628{ 1628{
1629 __u32 version = 0; 1629 __u32 version = 0;
@@ -1666,11 +1666,11 @@ ksocknal_parse_proto_version(ksock_hello_msg_t *hello)
1666} 1666}
1667 1667
1668int 1668int
1669ksocknal_send_hello(lnet_ni_t *ni, ksock_conn_t *conn, 1669ksocknal_send_hello(lnet_ni_t *ni, struct ksock_conn *conn,
1670 lnet_nid_t peer_nid, ksock_hello_msg_t *hello) 1670 lnet_nid_t peer_nid, ksock_hello_msg_t *hello)
1671{ 1671{
1672 /* CAVEAT EMPTOR: this byte flips 'ipaddrs' */ 1672 /* CAVEAT EMPTOR: this byte flips 'ipaddrs' */
1673 ksock_net_t *net = (ksock_net_t *)ni->ni_data; 1673 struct ksock_net *net = (struct ksock_net *)ni->ni_data;
1674 1674
1675 LASSERT(hello->kshm_nips <= LNET_MAX_INTERFACES); 1675 LASSERT(hello->kshm_nips <= LNET_MAX_INTERFACES);
1676 1676
@@ -1704,7 +1704,7 @@ ksocknal_invert_type(int type)
1704} 1704}
1705 1705
1706int 1706int
1707ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn, 1707ksocknal_recv_hello(lnet_ni_t *ni, struct ksock_conn *conn,
1708 ksock_hello_msg_t *hello, lnet_process_id_t *peerid, 1708 ksock_hello_msg_t *hello, lnet_process_id_t *peerid,
1709 __u64 *incarnation) 1709 __u64 *incarnation)
1710{ 1710{
@@ -1718,7 +1718,7 @@ ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn,
1718 int timeout; 1718 int timeout;
1719 int proto_match; 1719 int proto_match;
1720 int rc; 1720 int rc;
1721 ksock_proto_t *proto; 1721 struct ksock_proto *proto;
1722 lnet_process_id_t recv_id; 1722 lnet_process_id_t recv_id;
1723 1723
1724 /* socket type set on active connections - not set on passive */ 1724 /* socket type set on active connections - not set on passive */
@@ -1847,10 +1847,10 @@ ksocknal_recv_hello(lnet_ni_t *ni, ksock_conn_t *conn,
1847} 1847}
1848 1848
1849static int 1849static int
1850ksocknal_connect(ksock_route_t *route) 1850ksocknal_connect(struct ksock_route *route)
1851{ 1851{
1852 LIST_HEAD(zombies); 1852 LIST_HEAD(zombies);
1853 ksock_peer_t *peer = route->ksnr_peer; 1853 struct ksock_peer *peer = route->ksnr_peer;
1854 int type; 1854 int type;
1855 int wanted; 1855 int wanted;
1856 struct socket *sock; 1856 struct socket *sock;
@@ -1989,7 +1989,7 @@ ksocknal_connect(ksock_route_t *route)
1989 if (!list_empty(&peer->ksnp_tx_queue) && 1989 if (!list_empty(&peer->ksnp_tx_queue) &&
1990 !peer->ksnp_accepting && 1990 !peer->ksnp_accepting &&
1991 !ksocknal_find_connecting_route_locked(peer)) { 1991 !ksocknal_find_connecting_route_locked(peer)) {
1992 ksock_conn_t *conn; 1992 struct ksock_conn *conn;
1993 1993
1994 /* 1994 /*
1995 * ksnp_tx_queue is queued on a conn on successful 1995 * ksnp_tx_queue is queued on a conn on successful
@@ -1997,7 +1997,7 @@ ksocknal_connect(ksock_route_t *route)
1997 */ 1997 */
1998 if (!list_empty(&peer->ksnp_conns)) { 1998 if (!list_empty(&peer->ksnp_conns)) {
1999 conn = list_entry(peer->ksnp_conns.next, 1999 conn = list_entry(peer->ksnp_conns.next,
2000 ksock_conn_t, ksnc_list); 2000 struct ksock_conn, ksnc_list);
2001 LASSERT(conn->ksnc_proto == &ksocknal_protocol_v3x); 2001 LASSERT(conn->ksnc_proto == &ksocknal_protocol_v3x);
2002 } 2002 }
2003 2003
@@ -2131,10 +2131,10 @@ ksocknal_connd_check_stop(time64_t sec, long *timeout)
2131 * Go through connd_routes queue looking for a route that we can process 2131 * Go through connd_routes queue looking for a route that we can process
2132 * right now, @timeout_p can be updated if we need to come back later 2132 * right now, @timeout_p can be updated if we need to come back later
2133 */ 2133 */
2134static ksock_route_t * 2134static struct ksock_route *
2135ksocknal_connd_get_route_locked(signed long *timeout_p) 2135ksocknal_connd_get_route_locked(signed long *timeout_p)
2136{ 2136{
2137 ksock_route_t *route; 2137 struct ksock_route *route;
2138 unsigned long now; 2138 unsigned long now;
2139 2139
2140 now = cfs_time_current(); 2140 now = cfs_time_current();
@@ -2158,7 +2158,7 @@ int
2158ksocknal_connd(void *arg) 2158ksocknal_connd(void *arg)
2159{ 2159{
2160 spinlock_t *connd_lock = &ksocknal_data.ksnd_connd_lock; 2160 spinlock_t *connd_lock = &ksocknal_data.ksnd_connd_lock;
2161 ksock_connreq_t *cr; 2161 struct ksock_connreq *cr;
2162 wait_queue_t wait; 2162 wait_queue_t wait;
2163 int nloops = 0; 2163 int nloops = 0;
2164 int cons_retry = 0; 2164 int cons_retry = 0;
@@ -2174,7 +2174,7 @@ ksocknal_connd(void *arg)
2174 ksocknal_data.ksnd_connd_running++; 2174 ksocknal_data.ksnd_connd_running++;
2175 2175
2176 while (!ksocknal_data.ksnd_shuttingdown) { 2176 while (!ksocknal_data.ksnd_shuttingdown) {
2177 ksock_route_t *route = NULL; 2177 struct ksock_route *route = NULL;
2178 time64_t sec = ktime_get_real_seconds(); 2178 time64_t sec = ktime_get_real_seconds();
2179 long timeout = MAX_SCHEDULE_TIMEOUT; 2179 long timeout = MAX_SCHEDULE_TIMEOUT;
2180 int dropped_lock = 0; 2180 int dropped_lock = 0;
@@ -2192,8 +2192,8 @@ ksocknal_connd(void *arg)
2192 2192
2193 if (!list_empty(&ksocknal_data.ksnd_connd_connreqs)) { 2193 if (!list_empty(&ksocknal_data.ksnd_connd_connreqs)) {
2194 /* Connection accepted by the listener */ 2194 /* Connection accepted by the listener */
2195 cr = list_entry(ksocknal_data.ksnd_connd_connreqs. \ 2195 cr = list_entry(ksocknal_data.ksnd_connd_connreqs.next,
2196 next, ksock_connreq_t, ksncr_list); 2196 struct ksock_connreq, ksncr_list);
2197 2197
2198 list_del(&cr->ksncr_list); 2198 list_del(&cr->ksncr_list);
2199 spin_unlock_bh(connd_lock); 2199 spin_unlock_bh(connd_lock);
@@ -2267,17 +2267,17 @@ ksocknal_connd(void *arg)
2267 return 0; 2267 return 0;
2268} 2268}
2269 2269
2270static ksock_conn_t * 2270static struct ksock_conn *
2271ksocknal_find_timed_out_conn(ksock_peer_t *peer) 2271ksocknal_find_timed_out_conn(struct ksock_peer *peer)
2272{ 2272{
2273 /* We're called with a shared lock on ksnd_global_lock */ 2273 /* We're called with a shared lock on ksnd_global_lock */
2274 ksock_conn_t *conn; 2274 struct ksock_conn *conn;
2275 struct list_head *ctmp; 2275 struct list_head *ctmp;
2276 2276
2277 list_for_each(ctmp, &peer->ksnp_conns) { 2277 list_for_each(ctmp, &peer->ksnp_conns) {
2278 int error; 2278 int error;
2279 2279
2280 conn = list_entry(ctmp, ksock_conn_t, ksnc_list); 2280 conn = list_entry(ctmp, struct ksock_conn, ksnc_list);
2281 2281
2282 /* Don't need the {get,put}connsock dance to deref ksnc_sock */ 2282 /* Don't need the {get,put}connsock dance to deref ksnc_sock */
2283 LASSERT(!conn->ksnc_closing); 2283 LASSERT(!conn->ksnc_closing);
@@ -2351,10 +2351,10 @@ ksocknal_find_timed_out_conn(ksock_peer_t *peer)
2351} 2351}
2352 2352
2353static inline void 2353static inline void
2354ksocknal_flush_stale_txs(ksock_peer_t *peer) 2354ksocknal_flush_stale_txs(struct ksock_peer *peer)
2355{ 2355{
2356 ksock_tx_t *tx; 2356 struct ksock_tx *tx;
2357 ksock_tx_t *tmp; 2357 struct ksock_tx *tmp;
2358 LIST_HEAD(stale_txs); 2358 LIST_HEAD(stale_txs);
2359 2359
2360 write_lock_bh(&ksocknal_data.ksnd_global_lock); 2360 write_lock_bh(&ksocknal_data.ksnd_global_lock);
@@ -2374,12 +2374,12 @@ ksocknal_flush_stale_txs(ksock_peer_t *peer)
2374} 2374}
2375 2375
2376static int 2376static int
2377ksocknal_send_keepalive_locked(ksock_peer_t *peer) 2377ksocknal_send_keepalive_locked(struct ksock_peer *peer)
2378 __must_hold(&ksocknal_data.ksnd_global_lock) 2378 __must_hold(&ksocknal_data.ksnd_global_lock)
2379{ 2379{
2380 ksock_sched_t *sched; 2380 struct ksock_sched *sched;
2381 ksock_conn_t *conn; 2381 struct ksock_conn *conn;
2382 ksock_tx_t *tx; 2382 struct ksock_tx *tx;
2383 2383
2384 if (list_empty(&peer->ksnp_conns)) /* last_alive will be updated by create_conn */ 2384 if (list_empty(&peer->ksnp_conns)) /* last_alive will be updated by create_conn */
2385 return 0; 2385 return 0;
@@ -2440,9 +2440,9 @@ static void
2440ksocknal_check_peer_timeouts(int idx) 2440ksocknal_check_peer_timeouts(int idx)
2441{ 2441{
2442 struct list_head *peers = &ksocknal_data.ksnd_peers[idx]; 2442 struct list_head *peers = &ksocknal_data.ksnd_peers[idx];
2443 ksock_peer_t *peer; 2443 struct ksock_peer *peer;
2444 ksock_conn_t *conn; 2444 struct ksock_conn *conn;
2445 ksock_tx_t *tx; 2445 struct ksock_tx *tx;
2446 2446
2447 again: 2447 again:
2448 /* 2448 /*
@@ -2483,8 +2483,8 @@ ksocknal_check_peer_timeouts(int idx)
2483 * holding only shared lock 2483 * holding only shared lock
2484 */ 2484 */
2485 if (!list_empty(&peer->ksnp_tx_queue)) { 2485 if (!list_empty(&peer->ksnp_tx_queue)) {
2486 ksock_tx_t *tx = list_entry(peer->ksnp_tx_queue.next, 2486 struct ksock_tx *tx = list_entry(peer->ksnp_tx_queue.next,
2487 ksock_tx_t, tx_list); 2487 struct ksock_tx, tx_list);
2488 2488
2489 if (cfs_time_aftereq(cfs_time_current(), 2489 if (cfs_time_aftereq(cfs_time_current(),
2490 tx->tx_deadline)) { 2490 tx->tx_deadline)) {
@@ -2518,7 +2518,7 @@ ksocknal_check_peer_timeouts(int idx)
2518 } 2518 }
2519 2519
2520 tx = list_entry(peer->ksnp_zc_req_list.next, 2520 tx = list_entry(peer->ksnp_zc_req_list.next,
2521 ksock_tx_t, tx_zc_list); 2521 struct ksock_tx, tx_zc_list);
2522 deadline = tx->tx_deadline; 2522 deadline = tx->tx_deadline;
2523 resid = tx->tx_resid; 2523 resid = tx->tx_resid;
2524 conn = tx->tx_conn; 2524 conn = tx->tx_conn;
@@ -2544,8 +2544,8 @@ int
2544ksocknal_reaper(void *arg) 2544ksocknal_reaper(void *arg)
2545{ 2545{
2546 wait_queue_t wait; 2546 wait_queue_t wait;
2547 ksock_conn_t *conn; 2547 struct ksock_conn *conn;
2548 ksock_sched_t *sched; 2548 struct ksock_sched *sched;
2549 struct list_head enomem_conns; 2549 struct list_head enomem_conns;
2550 int nenomem_conns; 2550 int nenomem_conns;
2551 long timeout; 2551 long timeout;
@@ -2563,7 +2563,7 @@ ksocknal_reaper(void *arg)
2563 while (!ksocknal_data.ksnd_shuttingdown) { 2563 while (!ksocknal_data.ksnd_shuttingdown) {
2564 if (!list_empty(&ksocknal_data.ksnd_deathrow_conns)) { 2564 if (!list_empty(&ksocknal_data.ksnd_deathrow_conns)) {
2565 conn = list_entry(ksocknal_data.ksnd_deathrow_conns.next, 2565 conn = list_entry(ksocknal_data.ksnd_deathrow_conns.next,
2566 ksock_conn_t, ksnc_list); 2566 struct ksock_conn, ksnc_list);
2567 list_del(&conn->ksnc_list); 2567 list_del(&conn->ksnc_list);
2568 2568
2569 spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock); 2569 spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
@@ -2577,7 +2577,7 @@ ksocknal_reaper(void *arg)
2577 2577
2578 if (!list_empty(&ksocknal_data.ksnd_zombie_conns)) { 2578 if (!list_empty(&ksocknal_data.ksnd_zombie_conns)) {
2579 conn = list_entry(ksocknal_data.ksnd_zombie_conns.next, 2579 conn = list_entry(ksocknal_data.ksnd_zombie_conns.next,
2580 ksock_conn_t, ksnc_list); 2580 struct ksock_conn, ksnc_list);
2581 list_del(&conn->ksnc_list); 2581 list_del(&conn->ksnc_list);
2582 2582
2583 spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock); 2583 spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
@@ -2599,7 +2599,7 @@ ksocknal_reaper(void *arg)
2599 /* reschedule all the connections that stalled with ENOMEM... */ 2599 /* reschedule all the connections that stalled with ENOMEM... */
2600 nenomem_conns = 0; 2600 nenomem_conns = 0;
2601 while (!list_empty(&enomem_conns)) { 2601 while (!list_empty(&enomem_conns)) {
2602 conn = list_entry(enomem_conns.next, ksock_conn_t, 2602 conn = list_entry(enomem_conns.next, struct ksock_conn,
2603 ksnc_tx_list); 2603 ksnc_tx_list);
2604 list_del(&conn->ksnc_tx_list); 2604 list_del(&conn->ksnc_tx_list);
2605 2605
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c
index 964b4e338fe0..6a17757fce1e 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -37,7 +33,7 @@
37#include "socklnd.h" 33#include "socklnd.h"
38 34
39int 35int
40ksocknal_lib_get_conn_addrs(ksock_conn_t *conn) 36ksocknal_lib_get_conn_addrs(struct ksock_conn *conn)
41{ 37{
42 int rc = lnet_sock_getaddr(conn->ksnc_sock, 1, &conn->ksnc_ipaddr, 38 int rc = lnet_sock_getaddr(conn->ksnc_sock, 1, &conn->ksnc_ipaddr,
43 &conn->ksnc_port); 39 &conn->ksnc_port);
@@ -60,7 +56,7 @@ ksocknal_lib_get_conn_addrs(ksock_conn_t *conn)
60} 56}
61 57
62int 58int
63ksocknal_lib_zc_capable(ksock_conn_t *conn) 59ksocknal_lib_zc_capable(struct ksock_conn *conn)
64{ 60{
65 int caps = conn->ksnc_sock->sk->sk_route_caps; 61 int caps = conn->ksnc_sock->sk->sk_route_caps;
66 62
@@ -75,7 +71,7 @@ ksocknal_lib_zc_capable(ksock_conn_t *conn)
75} 71}
76 72
77int 73int
78ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx) 74ksocknal_lib_send_iov(struct ksock_conn *conn, struct ksock_tx *tx)
79{ 75{
80 struct socket *sock = conn->ksnc_sock; 76 struct socket *sock = conn->ksnc_sock;
81 int nob; 77 int nob;
@@ -118,7 +114,7 @@ ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx)
118} 114}
119 115
120int 116int
121ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx) 117ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx)
122{ 118{
123 struct socket *sock = conn->ksnc_sock; 119 struct socket *sock = conn->ksnc_sock;
124 lnet_kiov_t *kiov = tx->tx_kiov; 120 lnet_kiov_t *kiov = tx->tx_kiov;
@@ -187,7 +183,7 @@ ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx)
187} 183}
188 184
189void 185void
190ksocknal_lib_eager_ack(ksock_conn_t *conn) 186ksocknal_lib_eager_ack(struct ksock_conn *conn)
191{ 187{
192 int opt = 1; 188 int opt = 1;
193 struct socket *sock = conn->ksnc_sock; 189 struct socket *sock = conn->ksnc_sock;
@@ -203,7 +199,7 @@ ksocknal_lib_eager_ack(ksock_conn_t *conn)
203} 199}
204 200
205int 201int
206ksocknal_lib_recv_iov(ksock_conn_t *conn) 202ksocknal_lib_recv_iov(struct ksock_conn *conn)
207{ 203{
208#if SOCKNAL_SINGLE_FRAG_RX 204#if SOCKNAL_SINGLE_FRAG_RX
209 struct kvec scratch; 205 struct kvec scratch;
@@ -309,7 +305,7 @@ ksocknal_lib_kiov_vmap(lnet_kiov_t *kiov, int niov,
309} 305}
310 306
311int 307int
312ksocknal_lib_recv_kiov(ksock_conn_t *conn) 308ksocknal_lib_recv_kiov(struct ksock_conn *conn)
313{ 309{
314#if SOCKNAL_SINGLE_FRAG_RX || !SOCKNAL_RISK_KMAP_DEADLOCK 310#if SOCKNAL_SINGLE_FRAG_RX || !SOCKNAL_RISK_KMAP_DEADLOCK
315 struct kvec scratch; 311 struct kvec scratch;
@@ -393,7 +389,7 @@ ksocknal_lib_recv_kiov(ksock_conn_t *conn)
393} 389}
394 390
395void 391void
396ksocknal_lib_csum_tx(ksock_tx_t *tx) 392ksocknal_lib_csum_tx(struct ksock_tx *tx)
397{ 393{
398 int i; 394 int i;
399 __u32 csum; 395 __u32 csum;
@@ -432,7 +428,7 @@ ksocknal_lib_csum_tx(ksock_tx_t *tx)
432} 428}
433 429
434int 430int
435ksocknal_lib_get_conn_tunables(ksock_conn_t *conn, int *txmem, int *rxmem, int *nagle) 431ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem, int *rxmem, int *nagle)
436{ 432{
437 struct socket *sock = conn->ksnc_sock; 433 struct socket *sock = conn->ksnc_sock;
438 int len; 434 int len;
@@ -562,7 +558,7 @@ ksocknal_lib_setup_sock(struct socket *sock)
562} 558}
563 559
564void 560void
565ksocknal_lib_push_conn(ksock_conn_t *conn) 561ksocknal_lib_push_conn(struct ksock_conn *conn)
566{ 562{
567 struct sock *sk; 563 struct sock *sk;
568 struct tcp_sock *tp; 564 struct tcp_sock *tp;
@@ -599,7 +595,7 @@ ksocknal_lib_push_conn(ksock_conn_t *conn)
599static void 595static void
600ksocknal_data_ready(struct sock *sk) 596ksocknal_data_ready(struct sock *sk)
601{ 597{
602 ksock_conn_t *conn; 598 struct ksock_conn *conn;
603 599
604 /* interleave correctly with closing sockets... */ 600 /* interleave correctly with closing sockets... */
605 LASSERT(!in_irq()); 601 LASSERT(!in_irq());
@@ -619,7 +615,7 @@ ksocknal_data_ready(struct sock *sk)
619static void 615static void
620ksocknal_write_space(struct sock *sk) 616ksocknal_write_space(struct sock *sk)
621{ 617{
622 ksock_conn_t *conn; 618 struct ksock_conn *conn;
623 int wspace; 619 int wspace;
624 int min_wpace; 620 int min_wpace;
625 621
@@ -663,14 +659,14 @@ ksocknal_write_space(struct sock *sk)
663} 659}
664 660
665void 661void
666ksocknal_lib_save_callback(struct socket *sock, ksock_conn_t *conn) 662ksocknal_lib_save_callback(struct socket *sock, struct ksock_conn *conn)
667{ 663{
668 conn->ksnc_saved_data_ready = sock->sk->sk_data_ready; 664 conn->ksnc_saved_data_ready = sock->sk->sk_data_ready;
669 conn->ksnc_saved_write_space = sock->sk->sk_write_space; 665 conn->ksnc_saved_write_space = sock->sk->sk_write_space;
670} 666}
671 667
672void 668void
673ksocknal_lib_set_callback(struct socket *sock, ksock_conn_t *conn) 669ksocknal_lib_set_callback(struct socket *sock, struct ksock_conn *conn)
674{ 670{
675 sock->sk->sk_user_data = conn; 671 sock->sk->sk_user_data = conn;
676 sock->sk->sk_data_ready = ksocknal_data_ready; 672 sock->sk->sk_data_ready = ksocknal_data_ready;
@@ -678,7 +674,7 @@ ksocknal_lib_set_callback(struct socket *sock, ksock_conn_t *conn)
678} 674}
679 675
680void 676void
681ksocknal_lib_reset_callback(struct socket *sock, ksock_conn_t *conn) 677ksocknal_lib_reset_callback(struct socket *sock, struct ksock_conn *conn)
682{ 678{
683 /* 679 /*
684 * Remove conn's network callbacks. 680 * Remove conn's network callbacks.
@@ -697,10 +693,10 @@ ksocknal_lib_reset_callback(struct socket *sock, ksock_conn_t *conn)
697} 693}
698 694
699int 695int
700ksocknal_lib_memory_pressure(ksock_conn_t *conn) 696ksocknal_lib_memory_pressure(struct ksock_conn *conn)
701{ 697{
702 int rc = 0; 698 int rc = 0;
703 ksock_sched_t *sched; 699 struct ksock_sched *sched;
704 700
705 sched = conn->ksnc_scheduler; 701 sched = conn->ksnc_scheduler;
706 spin_lock_bh(&sched->kss_lock); 702 spin_lock_bh(&sched->kss_lock);
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c
index 6329cbe66573..fc7eec83ac07 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_modparams.c
@@ -139,7 +139,7 @@ module_param(protocol, int, 0644);
139MODULE_PARM_DESC(protocol, "protocol version"); 139MODULE_PARM_DESC(protocol, "protocol version");
140#endif 140#endif
141 141
142ksock_tunables_t ksocknal_tunables; 142struct ksock_tunables ksocknal_tunables;
143 143
144int ksocknal_tunables_init(void) 144int ksocknal_tunables_init(void)
145{ 145{
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
index 32cc31e4cc29..82e174f6d9fe 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
@@ -38,8 +38,8 @@
38 * pro_match_tx() : Called holding glock 38 * pro_match_tx() : Called holding glock
39 */ 39 */
40 40
41static ksock_tx_t * 41static struct ksock_tx *
42ksocknal_queue_tx_msg_v1(ksock_conn_t *conn, ksock_tx_t *tx_msg) 42ksocknal_queue_tx_msg_v1(struct ksock_conn *conn, struct ksock_tx *tx_msg)
43{ 43{
44 /* V1.x, just enqueue it */ 44 /* V1.x, just enqueue it */
45 list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue); 45 list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
@@ -47,9 +47,9 @@ ksocknal_queue_tx_msg_v1(ksock_conn_t *conn, ksock_tx_t *tx_msg)
47} 47}
48 48
49void 49void
50ksocknal_next_tx_carrier(ksock_conn_t *conn) 50ksocknal_next_tx_carrier(struct ksock_conn *conn)
51{ 51{
52 ksock_tx_t *tx = conn->ksnc_tx_carrier; 52 struct ksock_tx *tx = conn->ksnc_tx_carrier;
53 53
54 /* Called holding BH lock: conn->ksnc_scheduler->kss_lock */ 54 /* Called holding BH lock: conn->ksnc_scheduler->kss_lock */
55 LASSERT(!list_empty(&conn->ksnc_tx_queue)); 55 LASSERT(!list_empty(&conn->ksnc_tx_queue));
@@ -66,10 +66,10 @@ ksocknal_next_tx_carrier(ksock_conn_t *conn)
66} 66}
67 67
68static int 68static int
69ksocknal_queue_tx_zcack_v2(ksock_conn_t *conn, 69ksocknal_queue_tx_zcack_v2(struct ksock_conn *conn,
70 ksock_tx_t *tx_ack, __u64 cookie) 70 struct ksock_tx *tx_ack, __u64 cookie)
71{ 71{
72 ksock_tx_t *tx = conn->ksnc_tx_carrier; 72 struct ksock_tx *tx = conn->ksnc_tx_carrier;
73 73
74 LASSERT(!tx_ack || 74 LASSERT(!tx_ack ||
75 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP); 75 tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
@@ -112,10 +112,10 @@ ksocknal_queue_tx_zcack_v2(ksock_conn_t *conn,
112 return 1; 112 return 1;
113} 113}
114 114
115static ksock_tx_t * 115static struct ksock_tx *
116ksocknal_queue_tx_msg_v2(ksock_conn_t *conn, ksock_tx_t *tx_msg) 116ksocknal_queue_tx_msg_v2(struct ksock_conn *conn, struct ksock_tx *tx_msg)
117{ 117{
118 ksock_tx_t *tx = conn->ksnc_tx_carrier; 118 struct ksock_tx *tx = conn->ksnc_tx_carrier;
119 119
120 /* 120 /*
121 * Enqueue tx_msg: 121 * Enqueue tx_msg:
@@ -149,10 +149,10 @@ ksocknal_queue_tx_msg_v2(ksock_conn_t *conn, ksock_tx_t *tx_msg)
149} 149}
150 150
151static int 151static int
152ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn, 152ksocknal_queue_tx_zcack_v3(struct ksock_conn *conn,
153 ksock_tx_t *tx_ack, __u64 cookie) 153 struct ksock_tx *tx_ack, __u64 cookie)
154{ 154{
155 ksock_tx_t *tx; 155 struct ksock_tx *tx;
156 156
157 if (conn->ksnc_type != SOCKLND_CONN_ACK) 157 if (conn->ksnc_type != SOCKLND_CONN_ACK)
158 return ksocknal_queue_tx_zcack_v2(conn, tx_ack, cookie); 158 return ksocknal_queue_tx_zcack_v2(conn, tx_ack, cookie);
@@ -267,7 +267,7 @@ ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
267} 267}
268 268
269static int 269static int
270ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk) 270ksocknal_match_tx(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
271{ 271{
272 int nob; 272 int nob;
273 273
@@ -311,7 +311,7 @@ ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
311} 311}
312 312
313static int 313static int
314ksocknal_match_tx_v3(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk) 314ksocknal_match_tx_v3(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
315{ 315{
316 int nob; 316 int nob;
317 317
@@ -355,18 +355,18 @@ ksocknal_match_tx_v3(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
355 355
356/* (Sink) handle incoming ZC request from sender */ 356/* (Sink) handle incoming ZC request from sender */
357static int 357static int
358ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote) 358ksocknal_handle_zcreq(struct ksock_conn *c, __u64 cookie, int remote)
359{ 359{
360 ksock_peer_t *peer = c->ksnc_peer; 360 struct ksock_peer *peer = c->ksnc_peer;
361 ksock_conn_t *conn; 361 struct ksock_conn *conn;
362 ksock_tx_t *tx; 362 struct ksock_tx *tx;
363 int rc; 363 int rc;
364 364
365 read_lock(&ksocknal_data.ksnd_global_lock); 365 read_lock(&ksocknal_data.ksnd_global_lock);
366 366
367 conn = ksocknal_find_conn_locked(peer, NULL, !!remote); 367 conn = ksocknal_find_conn_locked(peer, NULL, !!remote);
368 if (conn) { 368 if (conn) {
369 ksock_sched_t *sched = conn->ksnc_scheduler; 369 struct ksock_sched *sched = conn->ksnc_scheduler;
370 370
371 LASSERT(conn->ksnc_proto->pro_queue_tx_zcack); 371 LASSERT(conn->ksnc_proto->pro_queue_tx_zcack);
372 372
@@ -399,12 +399,12 @@ ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote)
399 399
400/* (Sender) handle ZC_ACK from sink */ 400/* (Sender) handle ZC_ACK from sink */
401static int 401static int
402ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2) 402ksocknal_handle_zcack(struct ksock_conn *conn, __u64 cookie1, __u64 cookie2)
403{ 403{
404 ksock_peer_t *peer = conn->ksnc_peer; 404 struct ksock_peer *peer = conn->ksnc_peer;
405 ksock_tx_t *tx; 405 struct ksock_tx *tx;
406 ksock_tx_t *temp; 406 struct ksock_tx *temp;
407 ksock_tx_t *tmp; 407 struct ksock_tx *tmp;
408 LIST_HEAD(zlist); 408 LIST_HEAD(zlist);
409 int count; 409 int count;
410 410
@@ -446,7 +446,7 @@ ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2)
446} 446}
447 447
448static int 448static int
449ksocknal_send_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello) 449ksocknal_send_hello_v1(struct ksock_conn *conn, ksock_hello_msg_t *hello)
450{ 450{
451 struct socket *sock = conn->ksnc_sock; 451 struct socket *sock = conn->ksnc_sock;
452 lnet_hdr_t *hdr; 452 lnet_hdr_t *hdr;
@@ -503,7 +503,7 @@ ksocknal_send_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello)
503 if (!hello->kshm_nips) 503 if (!hello->kshm_nips)
504 goto out; 504 goto out;
505 505
506 for (i = 0; i < (int) hello->kshm_nips; i++) 506 for (i = 0; i < (int)hello->kshm_nips; i++)
507 hello->kshm_ips[i] = __cpu_to_le32(hello->kshm_ips[i]); 507 hello->kshm_ips[i] = __cpu_to_le32(hello->kshm_ips[i]);
508 508
509 rc = lnet_sock_write(sock, hello->kshm_ips, 509 rc = lnet_sock_write(sock, hello->kshm_ips,
@@ -521,7 +521,7 @@ out:
521} 521}
522 522
523static int 523static int
524ksocknal_send_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello) 524ksocknal_send_hello_v2(struct ksock_conn *conn, ksock_hello_msg_t *hello)
525{ 525{
526 struct socket *sock = conn->ksnc_sock; 526 struct socket *sock = conn->ksnc_sock;
527 int rc; 527 int rc;
@@ -563,7 +563,7 @@ ksocknal_send_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello)
563} 563}
564 564
565static int 565static int
566ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello, 566ksocknal_recv_hello_v1(struct ksock_conn *conn, ksock_hello_msg_t *hello,
567 int timeout) 567 int timeout)
568{ 568{
569 struct socket *sock = conn->ksnc_sock; 569 struct socket *sock = conn->ksnc_sock;
@@ -622,7 +622,7 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,
622 goto out; 622 goto out;
623 } 623 }
624 624
625 for (i = 0; i < (int) hello->kshm_nips; i++) { 625 for (i = 0; i < (int)hello->kshm_nips; i++) {
626 hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]); 626 hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
627 627
628 if (!hello->kshm_ips[i]) { 628 if (!hello->kshm_ips[i]) {
@@ -639,7 +639,7 @@ out:
639} 639}
640 640
641static int 641static int
642ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeout) 642ksocknal_recv_hello_v2(struct ksock_conn *conn, ksock_hello_msg_t *hello, int timeout)
643{ 643{
644 struct socket *sock = conn->ksnc_sock; 644 struct socket *sock = conn->ksnc_sock;
645 int rc; 645 int rc;
@@ -690,7 +690,7 @@ ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeout
690 return rc; 690 return rc;
691 } 691 }
692 692
693 for (i = 0; i < (int) hello->kshm_nips; i++) { 693 for (i = 0; i < (int)hello->kshm_nips; i++) {
694 if (conn->ksnc_flip) 694 if (conn->ksnc_flip)
695 __swab32s(&hello->kshm_ips[i]); 695 __swab32s(&hello->kshm_ips[i]);
696 696
@@ -705,7 +705,7 @@ ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello, int timeout
705} 705}
706 706
707static void 707static void
708ksocknal_pack_msg_v1(ksock_tx_t *tx) 708ksocknal_pack_msg_v1(struct ksock_tx *tx)
709{ 709{
710 /* V1.x has no KSOCK_MSG_NOOP */ 710 /* V1.x has no KSOCK_MSG_NOOP */
711 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP); 711 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
@@ -719,7 +719,7 @@ ksocknal_pack_msg_v1(ksock_tx_t *tx)
719} 719}
720 720
721static void 721static void
722ksocknal_pack_msg_v2(ksock_tx_t *tx) 722ksocknal_pack_msg_v2(struct ksock_tx *tx)
723{ 723{
724 tx->tx_iov[0].iov_base = &tx->tx_msg; 724 tx->tx_iov[0].iov_base = &tx->tx_msg;
725 725
@@ -755,7 +755,7 @@ ksocknal_unpack_msg_v2(ksock_msg_t *msg)
755 return; /* Do nothing */ 755 return; /* Do nothing */
756} 756}
757 757
758ksock_proto_t ksocknal_protocol_v1x = { 758struct ksock_proto ksocknal_protocol_v1x = {
759 .pro_version = KSOCK_PROTO_V1, 759 .pro_version = KSOCK_PROTO_V1,
760 .pro_send_hello = ksocknal_send_hello_v1, 760 .pro_send_hello = ksocknal_send_hello_v1,
761 .pro_recv_hello = ksocknal_recv_hello_v1, 761 .pro_recv_hello = ksocknal_recv_hello_v1,
@@ -768,7 +768,7 @@ ksock_proto_t ksocknal_protocol_v1x = {
768 .pro_match_tx = ksocknal_match_tx 768 .pro_match_tx = ksocknal_match_tx
769}; 769};
770 770
771ksock_proto_t ksocknal_protocol_v2x = { 771struct ksock_proto ksocknal_protocol_v2x = {
772 .pro_version = KSOCK_PROTO_V2, 772 .pro_version = KSOCK_PROTO_V2,
773 .pro_send_hello = ksocknal_send_hello_v2, 773 .pro_send_hello = ksocknal_send_hello_v2,
774 .pro_recv_hello = ksocknal_recv_hello_v2, 774 .pro_recv_hello = ksocknal_recv_hello_v2,
@@ -781,7 +781,7 @@ ksock_proto_t ksocknal_protocol_v2x = {
781 .pro_match_tx = ksocknal_match_tx 781 .pro_match_tx = ksocknal_match_tx
782}; 782};
783 783
784ksock_proto_t ksocknal_protocol_v3x = { 784struct ksock_proto ksocknal_protocol_v3x = {
785 .pro_version = KSOCK_PROTO_V3, 785 .pro_version = KSOCK_PROTO_V3,
786 .pro_send_hello = ksocknal_send_hello_v2, 786 .pro_send_hello = ksocknal_send_hello_v2,
787 .pro_recv_hello = ksocknal_recv_hello_v2, 787 .pro_recv_hello = ksocknal_recv_hello_v2,
diff --git a/drivers/staging/lustre/lnet/libcfs/debug.c b/drivers/staging/lustre/lnet/libcfs/debug.c
index 8c260c3d5da4..75a2a42f7d0c 100644
--- a/drivers/staging/lustre/lnet/libcfs/debug.c
+++ b/drivers/staging/lustre/lnet/libcfs/debug.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/fail.c b/drivers/staging/lustre/lnet/libcfs/fail.c
index 086e690bd6f2..9288ee08d1f7 100644
--- a/drivers/staging/lustre/lnet/libcfs/fail.c
+++ b/drivers/staging/lustre/lnet/libcfs/fail.c
@@ -16,10 +16,6 @@
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see http://www.gnu.org/licenses 17 * version 2 along with this program; If not, see http://www.gnu.org/licenses
18 * 18 *
19 * Please contact Oracle Corporation, Inc., 500 Oracle Parkway, Redwood Shores,
20 * CA 94065 USA or visit www.oracle.com if you need additional information or
21 * have any questions.
22 *
23 * GPL HEADER END 19 * GPL HEADER END
24 */ 20 */
25/* 21/*
diff --git a/drivers/staging/lustre/lnet/libcfs/hash.c b/drivers/staging/lustre/lnet/libcfs/hash.c
index cc45ed82b2be..23283b6e09ab 100644
--- a/drivers/staging/lustre/lnet/libcfs/hash.c
+++ b/drivers/staging/lustre/lnet/libcfs/hash.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c
index 50ac1536db4b..fc697cdfcdaf 100644
--- a/drivers/staging/lustre/lnet/libcfs/libcfs_string.c
+++ b/drivers/staging/lustre/lnet/libcfs/libcfs_string.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
index 84f9b7b47581..5c0116ade909 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c
@@ -99,6 +99,7 @@ static int cfs_crypto_hash_alloc(enum cfs_crypto_hash_alg hash_alg,
99 (*type)->cht_size); 99 (*type)->cht_size);
100 100
101 if (err != 0) { 101 if (err != 0) {
102 ahash_request_free(*req);
102 crypto_free_ahash(tfm); 103 crypto_free_ahash(tfm);
103 return err; 104 return err;
104 } 105 }
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c
index 13d31e8a931d..3e22cad18a8b 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-curproc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-debug.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-debug.c
index 638e4b33d3a9..435b784c52f8 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-debug.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-debug.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c
index 86f32ffc5d04..a6a76a681ea9 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-mem.c
@@ -11,7 +11,7 @@
11 * 11 *
12 * You should have received a copy of the GNU General Public License 12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; If not, see 13 * version 2 along with this program; If not, see
14 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 14 * http://www.gnu.org/licenses/gpl-2.0.html
15 * 15 *
16 */ 16 */
17/* 17/*
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
index d89f71ee45b2..38308f8b6aae 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-module.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c
index bbe19a684c81..291d286eab48 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-prim.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/linux/linux-tracefile.c b/drivers/staging/lustre/lnet/libcfs/linux/linux-tracefile.c
index 91c2ae8f9d67..8b551d2708ba 100644
--- a/drivers/staging/lustre/lnet/libcfs/linux/linux-tracefile.c
+++ b/drivers/staging/lustre/lnet/libcfs/linux/linux-tracefile.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/lustre/lnet/libcfs/module.c
index f2d041118cf7..86b4d25cad46 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/prng.c b/drivers/staging/lustre/lnet/libcfs/prng.c
index c75ae9a68e76..a9bdb284fd15 100644
--- a/drivers/staging/lustre/lnet/libcfs/prng.c
+++ b/drivers/staging/lustre/lnet/libcfs/prng.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/tracefile.c b/drivers/staging/lustre/lnet/libcfs/tracefile.c
index 7739b9469c5a..1c7efdfaffcf 100644
--- a/drivers/staging/lustre/lnet/libcfs/tracefile.c
+++ b/drivers/staging/lustre/lnet/libcfs/tracefile.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/tracefile.h b/drivers/staging/lustre/lnet/libcfs/tracefile.h
index ac84e7f4c859..d878676bc375 100644
--- a/drivers/staging/lustre/lnet/libcfs/tracefile.h
+++ b/drivers/staging/lustre/lnet/libcfs/tracefile.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/libcfs/workitem.c b/drivers/staging/lustre/lnet/libcfs/workitem.c
index 92236ae59e49..e98c818a14fb 100644
--- a/drivers/staging/lustre/lnet/libcfs/workitem.c
+++ b/drivers/staging/lustre/lnet/libcfs/workitem.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/acceptor.c b/drivers/staging/lustre/lnet/lnet/acceptor.c
index 1452bb3ad9eb..8c50c99d82d5 100644
--- a/drivers/staging/lustre/lnet/lnet/acceptor.c
+++ b/drivers/staging/lustre/lnet/lnet/acceptor.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c
index fe0dbe7468e7..346db892f275 100644
--- a/drivers/staging/lustre/lnet/lnet/api-ni.c
+++ b/drivers/staging/lustre/lnet/lnet/api-ni.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1677,7 +1673,7 @@ lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_data *config)
1677 if (!ni || !config) 1673 if (!ni || !config)
1678 return; 1674 return;
1679 1675
1680 net_config = (struct lnet_ioctl_net_config *) config->cfg_bulk; 1676 net_config = (struct lnet_ioctl_net_config *)config->cfg_bulk;
1681 if (!net_config) 1677 if (!net_config)
1682 return; 1678 return;
1683 1679
diff --git a/drivers/staging/lustre/lnet/lnet/config.c b/drivers/staging/lustre/lnet/lnet/config.c
index 480cc9c6caab..a72afdf68bb2 100644
--- a/drivers/staging/lustre/lnet/lnet/config.c
+++ b/drivers/staging/lustre/lnet/lnet/config.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/lib-eq.c b/drivers/staging/lustre/lnet/lnet/lib-eq.c
index adbcadbab1be..d05c6cc797f6 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-eq.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-eq.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/lib-md.c b/drivers/staging/lustre/lnet/lnet/lib-md.c
index 75d31217bf92..1834bf7a27ef 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-md.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-md.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/lib-me.c b/drivers/staging/lustre/lnet/lnet/lib-me.c
index e671aed373df..b430046dc294 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-me.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-me.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c
index c5d5bedb3128..e6d3b801d87d 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-move.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-move.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/lib-msg.c b/drivers/staging/lustre/lnet/lnet/lib-msg.c
index f879d7f28708..910e106e221d 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-msg.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-msg.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/lo.c b/drivers/staging/lustre/lnet/lnet/lo.c
index 468eda611bf8..08402712a452 100644
--- a/drivers/staging/lustre/lnet/lnet/lo.c
+++ b/drivers/staging/lustre/lnet/lnet/lo.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/module.c b/drivers/staging/lustre/lnet/lnet/module.c
index 246b5c141d01..4ffbd3e441e8 100644
--- a/drivers/staging/lustre/lnet/lnet/module.c
+++ b/drivers/staging/lustre/lnet/lnet/module.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -200,7 +196,7 @@ static int __init lnet_init(void)
200 * Have to schedule a separate thread to avoid deadlocking 196 * Have to schedule a separate thread to avoid deadlocking
201 * in modload 197 * in modload
202 */ 198 */
203 (void) kthread_run(lnet_configure, NULL, "lnet_initd"); 199 (void)kthread_run(lnet_configure, NULL, "lnet_initd");
204 } 200 }
205 201
206 return 0; 202 return 0;
diff --git a/drivers/staging/lustre/lnet/lnet/net_fault.c b/drivers/staging/lustre/lnet/lnet/net_fault.c
index 7d76f28d3a7a..e4aceb71c4ec 100644
--- a/drivers/staging/lustre/lnet/lnet/net_fault.c
+++ b/drivers/staging/lustre/lnet/lnet/net_fault.c
@@ -760,9 +760,7 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr)
760 wait_event(delay_dd.dd_ctl_waitq, delay_dd.dd_running); 760 wait_event(delay_dd.dd_ctl_waitq, delay_dd.dd_running);
761 } 761 }
762 762
763 init_timer(&rule->dl_timer); 763 setup_timer(&rule->dl_timer, delay_timer_cb, (unsigned long)rule);
764 rule->dl_timer.function = delay_timer_cb;
765 rule->dl_timer.data = (unsigned long)rule;
766 764
767 spin_lock_init(&rule->dl_lock); 765 spin_lock_init(&rule->dl_lock);
768 INIT_LIST_HEAD(&rule->dl_msg_list); 766 INIT_LIST_HEAD(&rule->dl_msg_list);
diff --git a/drivers/staging/lustre/lnet/lnet/nidstrings.c b/drivers/staging/lustre/lnet/lnet/nidstrings.c
index ebf468fbc64f..a6d7a6159b8f 100644
--- a/drivers/staging/lustre/lnet/lnet/nidstrings.c
+++ b/drivers/staging/lustre/lnet/lnet/nidstrings.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/peer.c b/drivers/staging/lustre/lnet/lnet/peer.c
index b026feebc03a..e8061916c241 100644
--- a/drivers/staging/lustre/lnet/lnet/peer.c
+++ b/drivers/staging/lustre/lnet/lnet/peer.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c
index b01dc424c514..063543233035 100644
--- a/drivers/staging/lustre/lnet/lnet/router.c
+++ b/drivers/staging/lustre/lnet/lnet/router.c
@@ -18,6 +18,7 @@
18 */ 18 */
19 19
20#define DEBUG_SUBSYSTEM S_LNET 20#define DEBUG_SUBSYSTEM S_LNET
21#include <linux/completion.h>
21#include "../../include/linux/lnet/lib-lnet.h" 22#include "../../include/linux/lnet/lib-lnet.h"
22 23
23#define LNET_NRB_TINY_MIN 512 /* min value for each CPT */ 24#define LNET_NRB_TINY_MIN 512 /* min value for each CPT */
@@ -1065,7 +1066,7 @@ lnet_router_checker_start(void)
1065 return -EINVAL; 1066 return -EINVAL;
1066 } 1067 }
1067 1068
1068 sema_init(&the_lnet.ln_rc_signal, 0); 1069 init_completion(&the_lnet.ln_rc_signal);
1069 1070
1070 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh); 1071 rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
1071 if (rc) { 1072 if (rc) {
@@ -1079,7 +1080,7 @@ lnet_router_checker_start(void)
1079 rc = PTR_ERR(task); 1080 rc = PTR_ERR(task);
1080 CERROR("Can't start router checker thread: %d\n", rc); 1081 CERROR("Can't start router checker thread: %d\n", rc);
1081 /* block until event callback signals exit */ 1082 /* block until event callback signals exit */
1082 down(&the_lnet.ln_rc_signal); 1083 wait_for_completion(&the_lnet.ln_rc_signal);
1083 rc = LNetEQFree(the_lnet.ln_rc_eqh); 1084 rc = LNetEQFree(the_lnet.ln_rc_eqh);
1084 LASSERT(!rc); 1085 LASSERT(!rc);
1085 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN; 1086 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
@@ -1112,7 +1113,7 @@ lnet_router_checker_stop(void)
1112 wake_up(&the_lnet.ln_rc_waitq); 1113 wake_up(&the_lnet.ln_rc_waitq);
1113 1114
1114 /* block until event callback signals exit */ 1115 /* block until event callback signals exit */
1115 down(&the_lnet.ln_rc_signal); 1116 wait_for_completion(&the_lnet.ln_rc_signal);
1116 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN); 1117 LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
1117 1118
1118 rc = LNetEQFree(the_lnet.ln_rc_eqh); 1119 rc = LNetEQFree(the_lnet.ln_rc_eqh);
@@ -1295,7 +1296,7 @@ rescan:
1295 lnet_prune_rc_data(1); /* wait for UNLINK */ 1296 lnet_prune_rc_data(1); /* wait for UNLINK */
1296 1297
1297 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN; 1298 the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
1298 up(&the_lnet.ln_rc_signal); 1299 complete(&the_lnet.ln_rc_signal);
1299 /* The unlink event callback will signal final completion */ 1300 /* The unlink event callback will signal final completion */
1300 return 0; 1301 return 0;
1301} 1302}
diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
index a63d86c4c10d..13d0454e7fcb 100644
--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c
index 408c614b6ca3..b786f8b4a73d 100644
--- a/drivers/staging/lustre/lnet/selftest/conctl.c
+++ b/drivers/staging/lustre/lnet/selftest/conctl.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c
index 6f687581117d..1be3cad727ae 100644
--- a/drivers/staging/lustre/lnet/selftest/conrpc.c
+++ b/drivers/staging/lustre/lnet/selftest/conrpc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.h b/drivers/staging/lustre/lnet/selftest/conrpc.h
index 90c3385a355c..7ec6fc96959e 100644
--- a/drivers/staging/lustre/lnet/selftest/conrpc.h
+++ b/drivers/staging/lustre/lnet/selftest/conrpc.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c
index a03e52d29d3f..4c33621f06da 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/console.h b/drivers/staging/lustre/lnet/selftest/console.h
index becd22e41da9..78b147732615 100644
--- a/drivers/staging/lustre/lnet/selftest/console.h
+++ b/drivers/staging/lustre/lnet/selftest/console.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
index 30e4f71f14c2..c2f121f44d33 100644
--- a/drivers/staging/lustre/lnet/selftest/framework.c
+++ b/drivers/staging/lustre/lnet/selftest/framework.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c
index cc046b1d4d0a..71485f992297 100644
--- a/drivers/staging/lustre/lnet/selftest/module.c
+++ b/drivers/staging/lustre/lnet/selftest/module.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
index ad26fe9dd4af..9331ca4e3606 100644
--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c
index 3c45a7cfae18..3b26d6eb4240 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.c
+++ b/drivers/staging/lustre/lnet/selftest/rpc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.h b/drivers/staging/lustre/lnet/selftest/rpc.h
index c9b904cade16..4ab2ee264004 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.h
+++ b/drivers/staging/lustre/lnet/selftest/rpc.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h
index 4eac1c9e639f..d033ac03d953 100644
--- a/drivers/staging/lustre/lnet/selftest/selftest.h
+++ b/drivers/staging/lustre/lnet/selftest/selftest.h
@@ -15,12 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 * copy of GPLv2].
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 * 19 *
25 * GPL HEADER END 20 * GPL HEADER END
26 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/timer.c b/drivers/staging/lustre/lnet/selftest/timer.c
index b6c4aae007af..dcd22580b1f0 100644
--- a/drivers/staging/lustre/lnet/selftest/timer.c
+++ b/drivers/staging/lustre/lnet/selftest/timer.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lnet/selftest/timer.h b/drivers/staging/lustre/lnet/selftest/timer.h
index f1fbebd8a67c..441d6d6b4f8e 100644
--- a/drivers/staging/lustre/lnet/selftest/timer.h
+++ b/drivers/staging/lustre/lnet/selftest/timer.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/Kconfig b/drivers/staging/lustre/lustre/Kconfig
index 8ac7cd4d6fdb..9f5d75f166e7 100644
--- a/drivers/staging/lustre/lustre/Kconfig
+++ b/drivers/staging/lustre/lustre/Kconfig
@@ -54,9 +54,3 @@ config LUSTRE_TRANSLATE_ERRNOS
54 bool 54 bool
55 depends on LUSTRE_FS && !X86 55 depends on LUSTRE_FS && !X86
56 default y 56 default y
57
58config LUSTRE_LLITE_LLOOP
59 tristate "Lustre virtual block device"
60 depends on LUSTRE_FS && BLOCK
61 depends on !PPC_64K_PAGES && !ARM64_64K_PAGES && !MICROBLAZE_64K_PAGES && !PAGE_SIZE_64KB && !IA64_PAGE_SIZE_64KB && !PARISC_PAGE_SIZE_64KB
62 default m
diff --git a/drivers/staging/lustre/lustre/fid/fid_internal.h b/drivers/staging/lustre/lustre/fid/fid_internal.h
index b79a813977cf..5c53773ecc5a 100644
--- a/drivers/staging/lustre/lustre/fid/fid_internal.h
+++ b/drivers/staging/lustre/lustre/fid/fid_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/fid/fid_lib.c b/drivers/staging/lustre/lustre/fid/fid_lib.c
index dd65159ebb38..99ae7eb6720e 100644
--- a/drivers/staging/lustre/lustre/fid/fid_lib.c
+++ b/drivers/staging/lustre/lustre/fid/fid_lib.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/fid/fid_request.c b/drivers/staging/lustre/lustre/fid/fid_request.c
index 3a4df626462f..454744d25956 100644
--- a/drivers/staging/lustre/lustre/fid/fid_request.c
+++ b/drivers/staging/lustre/lustre/fid/fid_request.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -98,8 +94,10 @@ static int seq_client_rpc(struct lu_client_seq *seq,
98 * request here, otherwise if MDT0 is failed(umounted), 94 * request here, otherwise if MDT0 is failed(umounted),
99 * it can not release the export of MDT0 95 * it can not release the export of MDT0
100 */ 96 */
101 if (seq->lcs_type == LUSTRE_SEQ_DATA) 97 if (seq->lcs_type == LUSTRE_SEQ_DATA) {
102 req->rq_no_delay = req->rq_no_resend = 1; 98 req->rq_no_delay = 1;
99 req->rq_no_resend = 1;
100 }
103 debug_mask = D_CONSOLE; 101 debug_mask = D_CONSOLE;
104 } else { 102 } else {
105 if (seq->lcs_type == LUSTRE_SEQ_METADATA) { 103 if (seq->lcs_type == LUSTRE_SEQ_METADATA) {
diff --git a/drivers/staging/lustre/lustre/fid/lproc_fid.c b/drivers/staging/lustre/lustre/fid/lproc_fid.c
index 1f0e78686278..81b7ca9ea2fd 100644
--- a/drivers/staging/lustre/lustre/fid/lproc_fid.c
+++ b/drivers/staging/lustre/lustre/fid/lproc_fid.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/fld/fld_cache.c b/drivers/staging/lustre/lustre/fld/fld_cache.c
index 5a04e99d9249..0100a935f4ff 100644
--- a/drivers/staging/lustre/lustre/fld/fld_cache.c
+++ b/drivers/staging/lustre/lustre/fld/fld_cache.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/fld/fld_internal.h b/drivers/staging/lustre/lustre/fld/fld_internal.h
index 75d6a48637a9..f0efe5b9fbec 100644
--- a/drivers/staging/lustre/lustre/fld/fld_internal.h
+++ b/drivers/staging/lustre/lustre/fld/fld_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/fld/fld_request.c b/drivers/staging/lustre/lustre/fld/fld_request.c
index 304c0ec268c9..e59d626a1548 100644
--- a/drivers/staging/lustre/lustre/fld/fld_request.c
+++ b/drivers/staging/lustre/lustre/fld/fld_request.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/fld/lproc_fld.c b/drivers/staging/lustre/lustre/fld/lproc_fld.c
index ca898befeba6..61ac420798af 100644
--- a/drivers/staging/lustre/lustre/fld/lproc_fld.c
+++ b/drivers/staging/lustre/lustre/fld/lproc_fld.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/cl_object.h b/drivers/staging/lustre/lustre/include/cl_object.h
index d4c33dd110ab..36ca93548e80 100644
--- a/drivers/staging/lustre/lustre/include/cl_object.h
+++ b/drivers/staging/lustre/lustre/include/cl_object.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/interval_tree.h b/drivers/staging/lustre/lustre/include/interval_tree.h
index f6df3f33e770..4a15228b5570 100644
--- a/drivers/staging/lustre/lustre/include/interval_tree.h
+++ b/drivers/staging/lustre/lustre/include/interval_tree.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h b/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
index 79d8f93075d1..1eb64ec4bed4 100644
--- a/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
+++ b/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/linux/lustre_lite.h b/drivers/staging/lustre/lustre/include/linux/lustre_lite.h
index 3420cfd1278d..d18e8a76bb25 100644
--- a/drivers/staging/lustre/lustre/include/linux/lustre_lite.h
+++ b/drivers/staging/lustre/lustre/include/linux/lustre_lite.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h b/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h
index c6c7f54637fb..5842cb18b49e 100644
--- a/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h
+++ b/drivers/staging/lustre/lustre/include/linux/lustre_patchless_compat.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/linux/lustre_user.h b/drivers/staging/lustre/lustre/include/linux/lustre_user.h
index 9cc2849f3f85..e967950e8536 100644
--- a/drivers/staging/lustre/lustre/include/linux/lustre_user.h
+++ b/drivers/staging/lustre/lustre/include/linux/lustre_user.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lprocfs_status.h b/drivers/staging/lustre/lustre/include/lprocfs_status.h
index 4146c9c3999f..d68e60e7fef7 100644
--- a/drivers/staging/lustre/lustre/include/lprocfs_status.h
+++ b/drivers/staging/lustre/lustre/include/lprocfs_status.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lu_object.h b/drivers/staging/lustre/lustre/include/lu_object.h
index 2816512185af..c6281e61beed 100644
--- a/drivers/staging/lustre/lustre/include/lu_object.h
+++ b/drivers/staging/lustre/lustre/include/lu_object.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h b/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h
index 07d45de69dd9..c2340d643e84 100644
--- a/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h
+++ b/drivers/staging/lustre/lustre/include/lustre/ll_fiemap.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
index 9c53c1792dc8..fac7215cb2ba 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_idl.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -386,7 +382,7 @@ static inline __u64 fid_ver_oid(const struct lu_fid *fid)
386 * used for other purposes and not risk collisions with existing inodes. 382 * used for other purposes and not risk collisions with existing inodes.
387 * 383 *
388 * Different FID Format 384 * Different FID Format
389 * http://arch.lustre.org/index.php?title=Interoperability_fids_zfs#NEW.0 385 * http://wiki.old.lustre.org/index.php/Architecture_-_Interoperability_fids_zfs
390 */ 386 */
391enum fid_seq { 387enum fid_seq {
392 FID_SEQ_OST_MDT0 = 0, 388 FID_SEQ_OST_MDT0 = 0,
@@ -704,7 +700,7 @@ static inline int fid_set_id(struct lu_fid *fid, __u64 oid)
704 * be passed through unchanged. Only legacy OST objects in "group 0" 700 * be passed through unchanged. Only legacy OST objects in "group 0"
705 * will be mapped into the IDIF namespace so that they can fit into the 701 * will be mapped into the IDIF namespace so that they can fit into the
706 * struct lu_fid fields without loss. For reference see: 702 * struct lu_fid fields without loss. For reference see:
707 * http://arch.lustre.org/index.php?title=Interoperability_fids_zfs 703 * http://wiki.old.lustre.org/index.php/Architecture_-_Interoperability_fids_zfs
708 */ 704 */
709static inline int ostid_to_fid(struct lu_fid *fid, struct ost_id *ostid, 705static inline int ostid_to_fid(struct lu_fid *fid, struct ost_id *ostid,
710 __u32 ost_idx) 706 __u32 ost_idx)
diff --git a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
index 59ba48ac31a7..a6e351a95466 100644
--- a/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
+++ b/drivers/staging/lustre/lustre/include/lustre/lustre_user.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_acl.h b/drivers/staging/lustre/lustre/include/lustre_acl.h
index aa4cfa7b749d..fecabe139b1f 100644
--- a/drivers/staging/lustre/lustre/include/lustre_acl.h
+++ b/drivers/staging/lustre/lustre/include/lustre_acl.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_cfg.h b/drivers/staging/lustre/lustre/include/lustre_cfg.h
index e229e91f7f56..95a0be13c0fb 100644
--- a/drivers/staging/lustre/lustre/include/lustre_cfg.h
+++ b/drivers/staging/lustre/lustre/include/lustre_cfg.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_debug.h b/drivers/staging/lustre/lustre/include/lustre_debug.h
index 8a089413c92e..93c1bdaf71a4 100644
--- a/drivers/staging/lustre/lustre/include/lustre_debug.h
+++ b/drivers/staging/lustre/lustre/include/lustre_debug.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h
index b36821ffb252..8886458748c1 100644
--- a/drivers/staging/lustre/lustre/include/lustre_disk.h
+++ b/drivers/staging/lustre/lustre/include/lustre_disk.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
index 9cade144faca..63085a0e504f 100644
--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_eacl.h b/drivers/staging/lustre/lustre/include/lustre_eacl.h
index 0b66593a9526..e5eadc4d4ce0 100644
--- a/drivers/staging/lustre/lustre/include/lustre_eacl.h
+++ b/drivers/staging/lustre/lustre/include/lustre_eacl.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_export.h b/drivers/staging/lustre/lustre/include/lustre_export.h
index 3014d27e6dc2..7c3ed55b3834 100644
--- a/drivers/staging/lustre/lustre/include/lustre_export.h
+++ b/drivers/staging/lustre/lustre/include/lustre_export.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_fid.h b/drivers/staging/lustre/lustre/include/lustre_fid.h
index 12e8b585c2b4..743671a547ef 100644
--- a/drivers/staging/lustre/lustre/include/lustre_fid.h
+++ b/drivers/staging/lustre/lustre/include/lustre_fid.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -45,7 +41,7 @@
45 * 41 *
46 * @{ 42 * @{
47 * 43 *
48 * http://wiki.lustre.org/index.php/Architecture_-_Interoperability_fids_zfs 44 * http://wiki.old.lustre.org/index.php/Architecture_-_Interoperability_fids_zfs
49 * describes the FID namespace and interoperability requirements for FIDs. 45 * describes the FID namespace and interoperability requirements for FIDs.
50 * The important parts of that document are included here for reference. 46 * The important parts of that document are included here for reference.
51 * 47 *
diff --git a/drivers/staging/lustre/lustre/include/lustre_fld.h b/drivers/staging/lustre/lustre/include/lustre_fld.h
index 4cf2b0e61672..932410d3e3cc 100644
--- a/drivers/staging/lustre/lustre/include/lustre_fld.h
+++ b/drivers/staging/lustre/lustre/include/lustre_fld.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_ha.h b/drivers/staging/lustre/lustre/include/lustre_ha.h
index 5488a698dabd..cde7ed702c86 100644
--- a/drivers/staging/lustre/lustre/include/lustre_ha.h
+++ b/drivers/staging/lustre/lustre/include/lustre_ha.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_handles.h b/drivers/staging/lustre/lustre/include/lustre_handles.h
index 27f169d2ed34..1a63a6b9e116 100644
--- a/drivers/staging/lustre/lustre/include/lustre_handles.h
+++ b/drivers/staging/lustre/lustre/include/lustre_handles.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_import.h b/drivers/staging/lustre/lustre/include/lustre_import.h
index 8325c82b3ebf..4445be7a59dd 100644
--- a/drivers/staging/lustre/lustre/include/lustre_import.h
+++ b/drivers/staging/lustre/lustre/include/lustre_import.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_intent.h b/drivers/staging/lustre/lustre/include/lustre_intent.h
index c491d52d86a2..fdc6236f52d9 100644
--- a/drivers/staging/lustre/lustre/include/lustre_intent.h
+++ b/drivers/staging/lustre/lustre/include/lustre_intent.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h
index 00b976766aef..06958f217fc8 100644
--- a/drivers/staging/lustre/lustre/include/lustre_lib.h
+++ b/drivers/staging/lustre/lustre/include/lustre_lib.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_lite.h b/drivers/staging/lustre/lustre/include/lustre_lite.h
index fcc5ebbceed8..b16897702559 100644
--- a/drivers/staging/lustre/lustre/include/lustre_lite.h
+++ b/drivers/staging/lustre/lustre/include/lustre_lite.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_log.h b/drivers/staging/lustre/lustre/include/lustre_log.h
index 49618e186824..b96e02317bfc 100644
--- a/drivers/staging/lustre/lustre/include/lustre_log.h
+++ b/drivers/staging/lustre/lustre/include/lustre_log.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_mdc.h b/drivers/staging/lustre/lustre/include/lustre_mdc.h
index f267ff8a6ec8..0ef4226da1bb 100644
--- a/drivers/staging/lustre/lustre/include/lustre_mdc.h
+++ b/drivers/staging/lustre/lustre/include/lustre_mdc.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_mds.h b/drivers/staging/lustre/lustre/include/lustre_mds.h
index 95d27ddecfb3..4104bd9bd5c4 100644
--- a/drivers/staging/lustre/lustre/include/lustre_mds.h
+++ b/drivers/staging/lustre/lustre/include/lustre_mds.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h
index a7973d5de168..dba4d1d7afac 100644
--- a/drivers/staging/lustre/lustre/include/lustre_net.h
+++ b/drivers/staging/lustre/lustre/include/lustre_net.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_param.h b/drivers/staging/lustre/lustre/include/lustre_param.h
index a42cf90c1cd8..82aadd32c2b8 100644
--- a/drivers/staging/lustre/lustre/include/lustre_param.h
+++ b/drivers/staging/lustre/lustre/include/lustre_param.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_req_layout.h b/drivers/staging/lustre/lustre/include/lustre_req_layout.h
index 0aac4391ea16..d00aae54e849 100644
--- a/drivers/staging/lustre/lustre/include/lustre_req_layout.h
+++ b/drivers/staging/lustre/lustre/include/lustre_req_layout.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/lustre_sec.h b/drivers/staging/lustre/lustre/include/lustre_sec.h
index 01b4e6726a68..90c183424802 100644
--- a/drivers/staging/lustre/lustre/include/lustre_sec.h
+++ b/drivers/staging/lustre/lustre/include/lustre_sec.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -221,13 +217,13 @@ enum sptlrpc_bulk_service {
221 217
222#define SPTLRPC_FLVR_DEFAULT SPTLRPC_FLVR_NULL 218#define SPTLRPC_FLVR_DEFAULT SPTLRPC_FLVR_NULL
223 219
224#define SPTLRPC_FLVR_INVALID ((__u32) 0xFFFFFFFF) 220#define SPTLRPC_FLVR_INVALID ((__u32)0xFFFFFFFF)
225#define SPTLRPC_FLVR_ANY ((__u32) 0xFFF00000) 221#define SPTLRPC_FLVR_ANY ((__u32)0xFFF00000)
226 222
227/** 223/**
228 * extract the useful part from wire flavor 224 * extract the useful part from wire flavor
229 */ 225 */
230#define WIRE_FLVR(wflvr) (((__u32) (wflvr)) & 0x000FFFFF) 226#define WIRE_FLVR(wflvr) (((__u32)(wflvr)) & 0x000FFFFF)
231 227
232/** @} flavor */ 228/** @} flavor */
233 229
diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
index 2d926e0ee647..e654d42dc8cc 100644
--- a/drivers/staging/lustre/lustre/include/obd.h
+++ b/drivers/staging/lustre/lustre/include/obd.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/obd_cksum.h b/drivers/staging/lustre/lustre/include/obd_cksum.h
index f6c18df906a8..a8a81e662a56 100644
--- a/drivers/staging/lustre/lustre/include/obd_cksum.h
+++ b/drivers/staging/lustre/lustre/include/obd_cksum.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h
index 32863bcb30b9..21967440b46a 100644
--- a/drivers/staging/lustre/lustre/include/obd_class.h
+++ b/drivers/staging/lustre/lustre/include/obd_class.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/include/obd_support.h b/drivers/staging/lustre/lustre/include/obd_support.h
index 60034d39b00d..cdf20d6470d7 100644
--- a/drivers/staging/lustre/lustre/include/obd_support.h
+++ b/drivers/staging/lustre/lustre/include/obd_support.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/interval_tree.c b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
index 323060626fdf..f4a70ebddeaf 100644
--- a/drivers/staging/lustre/lustre/ldlm/interval_tree.c
+++ b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/l_lock.c b/drivers/staging/lustre/lustre/ldlm/l_lock.c
index 621323f6ee60..ea8840cb9056 100644
--- a/drivers/staging/lustre/lustre/ldlm/l_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/l_lock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index cf1f1783632f..f5023d9b78f5 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
index 349bfcc9b331..d6b61bc39135 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -259,14 +255,13 @@ reprocess:
259 * overflow and underflow. 255 * overflow and underflow.
260 */ 256 */
261 if ((new->l_policy_data.l_flock.start > 257 if ((new->l_policy_data.l_flock.start >
262 (lock->l_policy_data.l_flock.end + 1)) 258 (lock->l_policy_data.l_flock.end + 1)) &&
263 && (lock->l_policy_data.l_flock.end != 259 (lock->l_policy_data.l_flock.end != OBD_OBJECT_EOF))
264 OBD_OBJECT_EOF))
265 continue; 260 continue;
266 261
267 if ((new->l_policy_data.l_flock.end < 262 if ((new->l_policy_data.l_flock.end <
268 (lock->l_policy_data.l_flock.start - 1)) 263 (lock->l_policy_data.l_flock.start - 1)) &&
269 && (lock->l_policy_data.l_flock.start != 0)) 264 (lock->l_policy_data.l_flock.start != 0))
270 break; 265 break;
271 266
272 if (new->l_policy_data.l_flock.start < 267 if (new->l_policy_data.l_flock.start <
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c b/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
index b1bed1e17d32..79f4e6fa193e 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
index 32f227f37799..e4cf65d2d3b1 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
index b4ffbe2fc4ed..7c832aae7d5e 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -345,7 +341,8 @@ int client_obd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg)
345 * Set cl_chksum* to CRC32 for now to avoid returning screwed info 341 * Set cl_chksum* to CRC32 for now to avoid returning screwed info
346 * through procfs. 342 * through procfs.
347 */ 343 */
348 cli->cl_cksum_type = cli->cl_supp_cksum_types = OBD_CKSUM_CRC32; 344 cli->cl_cksum_type = OBD_CKSUM_CRC32;
345 cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
349 atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS); 346 atomic_set(&cli->cl_resends, OSC_DEFAULT_RESENDS);
350 347
351 /* This value may be reduced at connect time in 348 /* This value may be reduced at connect time in
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index bff94ea12d6f..1ecdfa2021f5 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index ab739f079a48..3eab0591caa9 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1011,9 +1007,11 @@ static int ldlm_setup(void)
1011 blp->blp_min_threads = LDLM_NTHRS_INIT; 1007 blp->blp_min_threads = LDLM_NTHRS_INIT;
1012 blp->blp_max_threads = LDLM_NTHRS_MAX; 1008 blp->blp_max_threads = LDLM_NTHRS_MAX;
1013 } else { 1009 } else {
1014 blp->blp_min_threads = blp->blp_max_threads = 1010 blp->blp_min_threads = min_t(int, LDLM_NTHRS_MAX,
1015 min_t(int, LDLM_NTHRS_MAX, max_t(int, LDLM_NTHRS_INIT, 1011 max_t(int, LDLM_NTHRS_INIT,
1016 ldlm_num_threads)); 1012 ldlm_num_threads));
1013
1014 blp->blp_max_threads = blp->blp_min_threads;
1017 } 1015 }
1018 1016
1019 for (i = 0; i < blp->blp_min_threads; i++) { 1017 for (i = 0; i < blp->blp_min_threads; i++) {
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_plain.c b/drivers/staging/lustre/lustre/ldlm/ldlm_plain.c
index 0c1965ddabb9..0aed39c46154 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_plain.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_plain.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
index b913ba9cf97c..657ed4012776 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
index 107314e284a0..471ab0865a75 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index e99c89c34cd0..f7c95b7ebe92 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/Makefile b/drivers/staging/lustre/lustre/llite/Makefile
index 2ce10ff01b80..19701e781328 100644
--- a/drivers/staging/lustre/lustre/llite/Makefile
+++ b/drivers/staging/lustre/lustre/llite/Makefile
@@ -1,5 +1,4 @@
1obj-$(CONFIG_LUSTRE_FS) += lustre.o 1obj-$(CONFIG_LUSTRE_FS) += lustre.o
2obj-$(CONFIG_LUSTRE_LLITE_LLOOP) += llite_lloop.o
3lustre-y := dcache.o dir.o file.o llite_close.o llite_lib.o llite_nfs.o \ 2lustre-y := dcache.o dir.o file.o llite_close.o llite_lib.o llite_nfs.o \
4 rw.o namei.o symlink.o llite_mmap.o \ 3 rw.o namei.o symlink.o llite_mmap.o \
5 xattr.o xattr_cache.o remote_perm.o llite_rmtacl.o \ 4 xattr.o xattr_cache.o remote_perm.o llite_rmtacl.o \
@@ -7,5 +6,3 @@ lustre-y := dcache.o dir.o file.o llite_close.o llite_lib.o llite_nfs.o \
7 glimpse.o lcommon_cl.o lcommon_misc.o \ 6 glimpse.o lcommon_cl.o lcommon_misc.o \
8 vvp_dev.o vvp_page.o vvp_lock.o vvp_io.o vvp_object.o vvp_req.o \ 7 vvp_dev.o vvp_page.o vvp_lock.o vvp_io.o vvp_object.o vvp_req.o \
9 lproc_llite.o 8 lproc_llite.o
10
11llite_lloop-y := lloop.o
diff --git a/drivers/staging/lustre/lustre/llite/dcache.c b/drivers/staging/lustre/lustre/llite/dcache.c
index 1b6f82a1a435..9d13d5e933ba 100644
--- a/drivers/staging/lustre/lustre/llite/dcache.c
+++ b/drivers/staging/lustre/lustre/llite/dcache.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
index 4b00d1ac84fb..99735f6e9cd6 100644
--- a/drivers/staging/lustre/lustre/llite/dir.c
+++ b/drivers/staging/lustre/lustre/llite/dir.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1076,17 +1072,11 @@ static int copy_and_ioctl(int cmd, struct obd_export *exp,
1076 void *copy; 1072 void *copy;
1077 int rc; 1073 int rc;
1078 1074
1079 copy = kzalloc(size, GFP_NOFS); 1075 copy = memdup_user(data, size);
1080 if (!copy) 1076 if (IS_ERR(copy))
1081 return -ENOMEM; 1077 return PTR_ERR(copy);
1082
1083 if (copy_from_user(copy, data, size)) {
1084 rc = -EFAULT;
1085 goto out;
1086 }
1087 1078
1088 rc = obd_iocontrol(cmd, exp, size, copy, NULL); 1079 rc = obd_iocontrol(cmd, exp, size, copy, NULL);
1089out:
1090 kfree(copy); 1080 kfree(copy);
1091 1081
1092 return rc; 1082 return rc;
diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index f47f2acaf90c..b0c4548245dd 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -519,6 +515,11 @@ static int ll_local_open(struct file *file, struct lookup_intent *it,
519 LUSTRE_FPRIVATE(file) = fd; 515 LUSTRE_FPRIVATE(file) = fd;
520 ll_readahead_init(inode, &fd->fd_ras); 516 ll_readahead_init(inode, &fd->fd_ras);
521 fd->fd_omode = it->it_flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC); 517 fd->fd_omode = it->it_flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
518
519 /* ll_cl_context initialize */
520 rwlock_init(&fd->fd_lock);
521 INIT_LIST_HEAD(&fd->fd_lccs);
522
522 return 0; 523 return 0;
523} 524}
524 525
@@ -1178,7 +1179,9 @@ restart:
1178 CERROR("Unknown IO type - %u\n", vio->vui_io_subtype); 1179 CERROR("Unknown IO type - %u\n", vio->vui_io_subtype);
1179 LBUG(); 1180 LBUG();
1180 } 1181 }
1182 ll_cl_add(file, env, io);
1181 result = cl_io_loop(env, io); 1183 result = cl_io_loop(env, io);
1184 ll_cl_remove(file, env);
1182 if (args->via_io_subtype == IO_NORMAL) 1185 if (args->via_io_subtype == IO_NORMAL)
1183 up_read(&lli->lli_trunc_sem); 1186 up_read(&lli->lli_trunc_sem);
1184 if (write_mutex_locked) 1187 if (write_mutex_locked)
@@ -1410,7 +1413,7 @@ out_unlock:
1410out: 1413out:
1411 return rc; 1414 return rc;
1412out_req_free: 1415out_req_free:
1413 ptlrpc_req_finished((struct ptlrpc_request *) oit.d.lustre.it_data); 1416 ptlrpc_req_finished((struct ptlrpc_request *)oit.d.lustre.it_data);
1414 goto out; 1417 goto out;
1415} 1418}
1416 1419
@@ -3124,6 +3127,9 @@ struct posix_acl *ll_get_acl(struct inode *inode, int type)
3124 spin_lock(&lli->lli_lock); 3127 spin_lock(&lli->lli_lock);
3125 /* VFS' acl_permission_check->check_acl will release the refcount */ 3128 /* VFS' acl_permission_check->check_acl will release the refcount */
3126 acl = posix_acl_dup(lli->lli_posix_acl); 3129 acl = posix_acl_dup(lli->lli_posix_acl);
3130#ifdef CONFIG_FS_POSIX_ACL
3131 forget_cached_acl(inode, type);
3132#endif
3127 spin_unlock(&lli->lli_lock); 3133 spin_unlock(&lli->lli_lock);
3128 3134
3129 return acl; 3135 return acl;
diff --git a/drivers/staging/lustre/lustre/llite/glimpse.c b/drivers/staging/lustre/lustre/llite/glimpse.c
index d8ea75424e2f..92004a05f9ee 100644
--- a/drivers/staging/lustre/lustre/llite/glimpse.c
+++ b/drivers/staging/lustre/lustre/llite/glimpse.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/lcommon_cl.c b/drivers/staging/lustre/lustre/llite/lcommon_cl.c
index 6c00715b438f..396e4e4f0715 100644
--- a/drivers/staging/lustre/lustre/llite/lcommon_cl.c
+++ b/drivers/staging/lustre/lustre/llite/lcommon_cl.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/lcommon_misc.c b/drivers/staging/lustre/lustre/llite/lcommon_misc.c
index 12f3e71f48c2..8a508ed1136d 100644
--- a/drivers/staging/lustre/lustre/llite/lcommon_misc.c
+++ b/drivers/staging/lustre/lustre/llite/lcommon_misc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/llite_close.c b/drivers/staging/lustre/lustre/llite/llite_close.c
index 2df551d3ae6c..2326b40a0870 100644
--- a/drivers/staging/lustre/lustre/llite/llite_close.c
+++ b/drivers/staging/lustre/lustre/llite/llite_close.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h
index 3f2f30b6542c..7c1a3254a24e 100644
--- a/drivers/staging/lustre/lustre/llite/llite_internal.h
+++ b/drivers/staging/lustre/lustre/llite/llite_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -640,6 +636,8 @@ struct ll_file_data {
640 * false: unknown failure, should report. 636 * false: unknown failure, should report.
641 */ 637 */
642 bool fd_write_failed; 638 bool fd_write_failed;
639 rwlock_t fd_lock; /* protect lcc list */
640 struct list_head fd_lccs; /* list of ll_cl_context */
643}; 641};
644 642
645struct lov_stripe_md; 643struct lov_stripe_md;
@@ -715,8 +713,9 @@ void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
715int ll_readahead(const struct lu_env *env, struct cl_io *io, 713int ll_readahead(const struct lu_env *env, struct cl_io *io,
716 struct cl_page_list *queue, struct ll_readahead_state *ras, 714 struct cl_page_list *queue, struct ll_readahead_state *ras,
717 bool hit); 715 bool hit);
718struct ll_cl_context *ll_cl_init(struct file *file, struct page *vmpage); 716struct ll_cl_context *ll_cl_find(struct file *file);
719void ll_cl_fini(struct ll_cl_context *lcc); 717void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io);
718void ll_cl_remove(struct file *file, const struct lu_env *env);
720 719
721extern const struct address_space_operations ll_aops; 720extern const struct address_space_operations ll_aops;
722 721
@@ -858,11 +857,11 @@ struct vvp_io_args {
858}; 857};
859 858
860struct ll_cl_context { 859struct ll_cl_context {
860 struct list_head lcc_list;
861 void *lcc_cookie; 861 void *lcc_cookie;
862 const struct lu_env *lcc_env;
862 struct cl_io *lcc_io; 863 struct cl_io *lcc_io;
863 struct cl_page *lcc_page; 864 struct cl_page *lcc_page;
864 struct lu_env *lcc_env;
865 int lcc_refcheck;
866}; 865};
867 866
868struct ll_thread_info { 867struct ll_thread_info {
diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 96c7e9fc6e5f..ac833dbeb6e6 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -864,7 +860,8 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
864 try_module_get(THIS_MODULE); 860 try_module_get(THIS_MODULE);
865 861
866 /* client additional sb info */ 862 /* client additional sb info */
867 lsi->lsi_llsbi = sbi = ll_init_sbi(sb); 863 sbi = ll_init_sbi(sb);
864 lsi->lsi_llsbi = sbi;
868 if (!sbi) { 865 if (!sbi) {
869 module_put(THIS_MODULE); 866 module_put(THIS_MODULE);
870 kfree(cfg); 867 kfree(cfg);
diff --git a/drivers/staging/lustre/lustre/llite/llite_mmap.c b/drivers/staging/lustre/lustre/llite/llite_mmap.c
index 88ef1cac9e0f..fb1c3b613f59 100644
--- a/drivers/staging/lustre/lustre/llite/llite_mmap.c
+++ b/drivers/staging/lustre/lustre/llite/llite_mmap.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -315,8 +311,13 @@ static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
315 vio->u.fault.ft_flags = 0; 311 vio->u.fault.ft_flags = 0;
316 vio->u.fault.ft_flags_valid = false; 312 vio->u.fault.ft_flags_valid = false;
317 313
314 /* May call ll_readpage() */
315 ll_cl_add(vma->vm_file, env, io);
316
318 result = cl_io_loop(env, io); 317 result = cl_io_loop(env, io);
319 318
319 ll_cl_remove(vma->vm_file, env);
320
320 /* ft_flags are only valid if we reached 321 /* ft_flags are only valid if we reached
321 * the call to filemap_fault 322 * the call to filemap_fault
322 */ 323 */
diff --git a/drivers/staging/lustre/lustre/llite/llite_nfs.c b/drivers/staging/lustre/lustre/llite/llite_nfs.c
index c1eef6198b25..d7878e504aca 100644
--- a/drivers/staging/lustre/lustre/llite/llite_nfs.c
+++ b/drivers/staging/lustre/lustre/llite/llite_nfs.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/llite_rmtacl.c b/drivers/staging/lustre/lustre/llite/llite_rmtacl.c
index 8509b07cb5c7..edb92f9f2d70 100644
--- a/drivers/staging/lustre/lustre/llite/llite_rmtacl.c
+++ b/drivers/staging/lustre/lustre/llite/llite_rmtacl.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/lloop.c b/drivers/staging/lustre/lustre/llite/lloop.c
deleted file mode 100644
index 813a9a354e5f..000000000000
--- a/drivers/staging/lustre/lustre/llite/lloop.c
+++ /dev/null
@@ -1,883 +0,0 @@
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.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36
37/*
38 * linux/drivers/block/loop.c
39 *
40 * Written by Theodore Ts'o, 3/29/93
41 *
42 * Copyright 1993 by Theodore Ts'o. Redistribution of this file is
43 * permitted under the GNU General Public License.
44 *
45 * Modularized and updated for 1.1.16 kernel - Mitch Dsouza 28th May 1994
46 * Adapted for 1.3.59 kernel - Andries Brouwer, 1 Feb 1996
47 *
48 * Fixed do_loop_request() re-entrancy - Vincent.Renardias@waw.com Mar 20, 1997
49 *
50 * Added devfs support - Richard Gooch <rgooch@atnf.csiro.au> 16-Jan-1998
51 *
52 * Handle sparse backing files correctly - Kenn Humborg, Jun 28, 1998
53 *
54 * Loadable modules and other fixes by AK, 1998
55 *
56 * Maximum number of loop devices now dynamic via max_loop module parameter.
57 * Russell Kroll <rkroll@exploits.org> 19990701
58 *
59 * Maximum number of loop devices when compiled-in now selectable by passing
60 * max_loop=<1-255> to the kernel on boot.
61 * Erik I. Bols?, <eriki@himolde.no>, Oct 31, 1999
62 *
63 * Completely rewrite request handling to be make_request_fn style and
64 * non blocking, pushing work to a helper thread. Lots of fixes from
65 * Al Viro too.
66 * Jens Axboe <axboe@suse.de>, Nov 2000
67 *
68 * Support up to 256 loop devices
69 * Heinz Mauelshagen <mge@sistina.com>, Feb 2002
70 *
71 * Support for falling back on the write file operation when the address space
72 * operations prepare_write and/or commit_write are not available on the
73 * backing filesystem.
74 * Anton Altaparmakov, 16 Feb 2005
75 *
76 * Still To Fix:
77 * - Advisory locking is ignored here.
78 * - Should use an own CAP_* category instead of CAP_SYS_ADMIN
79 *
80 */
81
82#include <linux/module.h>
83
84#include <linux/sched.h>
85#include <linux/fs.h>
86#include <linux/file.h>
87#include <linux/stat.h>
88#include <linux/errno.h>
89#include <linux/major.h>
90#include <linux/wait.h>
91#include <linux/blkdev.h>
92#include <linux/blkpg.h>
93#include <linux/init.h>
94#include <linux/swap.h>
95#include <linux/slab.h>
96#include <linux/suspend.h>
97#include <linux/writeback.h>
98#include <linux/buffer_head.h> /* for invalidate_bdev() */
99#include <linux/completion.h>
100#include <linux/highmem.h>
101#include <linux/gfp.h>
102#include <linux/pagevec.h>
103#include <linux/uaccess.h>
104
105#include "../include/lustre_lib.h"
106#include "../include/lustre_lite.h"
107#include "llite_internal.h"
108
109#define LLOOP_MAX_SEGMENTS LNET_MAX_IOV
110
111/* Possible states of device */
112enum {
113 LLOOP_UNBOUND,
114 LLOOP_BOUND,
115 LLOOP_RUNDOWN,
116};
117
118struct lloop_device {
119 int lo_number;
120 int lo_refcnt;
121 loff_t lo_offset;
122 loff_t lo_sizelimit;
123 int lo_flags;
124 struct file *lo_backing_file;
125 struct block_device *lo_device;
126 unsigned lo_blocksize;
127
128 gfp_t old_gfp_mask;
129
130 spinlock_t lo_lock;
131 struct bio *lo_bio;
132 struct bio *lo_biotail;
133 int lo_state;
134 struct semaphore lo_sem;
135 struct mutex lo_ctl_mutex;
136 atomic_t lo_pending;
137 wait_queue_head_t lo_bh_wait;
138
139 struct request_queue *lo_queue;
140
141 const struct lu_env *lo_env;
142 struct cl_io lo_io;
143 struct ll_dio_pages lo_pvec;
144
145 /* data to handle bio for lustre. */
146 struct lo_request_data {
147 struct page *lrd_pages[LLOOP_MAX_SEGMENTS];
148 loff_t lrd_offsets[LLOOP_MAX_SEGMENTS];
149 } lo_requests[1];
150};
151
152/*
153 * Loop flags
154 */
155enum {
156 LO_FLAGS_READ_ONLY = 1,
157};
158
159static int lloop_major;
160#define MAX_LOOP_DEFAULT 16
161static int max_loop = MAX_LOOP_DEFAULT;
162static struct lloop_device *loop_dev;
163static struct gendisk **disks;
164static struct mutex lloop_mutex;
165static void *ll_iocontrol_magic;
166
167static loff_t get_loop_size(struct lloop_device *lo, struct file *file)
168{
169 loff_t size, offset, loopsize;
170
171 /* Compute loopsize in bytes */
172 size = i_size_read(file->f_mapping->host);
173 offset = lo->lo_offset;
174 loopsize = size - offset;
175 if (lo->lo_sizelimit > 0 && lo->lo_sizelimit < loopsize)
176 loopsize = lo->lo_sizelimit;
177
178 /*
179 * Unfortunately, if we want to do I/O on the device,
180 * the number of 512-byte sectors has to fit into a sector_t.
181 */
182 return loopsize >> 9;
183}
184
185static int do_bio_lustrebacked(struct lloop_device *lo, struct bio *head)
186{
187 const struct lu_env *env = lo->lo_env;
188 struct cl_io *io = &lo->lo_io;
189 struct inode *inode = file_inode(lo->lo_backing_file);
190 struct cl_object *obj = ll_i2info(inode)->lli_clob;
191 pgoff_t offset;
192 int ret;
193 int rw;
194 u32 page_count = 0;
195 struct bio_vec bvec;
196 struct bvec_iter iter;
197 struct bio *bio;
198 ssize_t bytes;
199
200 struct ll_dio_pages *pvec = &lo->lo_pvec;
201 struct page **pages = pvec->ldp_pages;
202 loff_t *offsets = pvec->ldp_offsets;
203
204 truncate_inode_pages(inode->i_mapping, 0);
205
206 /* initialize the IO */
207 memset(io, 0, sizeof(*io));
208 io->ci_obj = obj;
209 ret = cl_io_init(env, io, CIT_MISC, obj);
210 if (ret)
211 return io->ci_result;
212 io->ci_lockreq = CILR_NEVER;
213
214 rw = head->bi_rw;
215 for (bio = head; bio ; bio = bio->bi_next) {
216 LASSERT(rw == bio->bi_rw);
217
218 offset = (pgoff_t)(bio->bi_iter.bi_sector << 9) + lo->lo_offset;
219 bio_for_each_segment(bvec, bio, iter) {
220 BUG_ON(bvec.bv_offset != 0);
221 BUG_ON(bvec.bv_len != PAGE_SIZE);
222
223 pages[page_count] = bvec.bv_page;
224 offsets[page_count] = offset;
225 page_count++;
226 offset += bvec.bv_len;
227 }
228 LASSERT(page_count <= LLOOP_MAX_SEGMENTS);
229 }
230
231 ll_stats_ops_tally(ll_i2sbi(inode),
232 (rw == WRITE) ? LPROC_LL_BRW_WRITE : LPROC_LL_BRW_READ,
233 page_count);
234
235 pvec->ldp_size = page_count << PAGE_SHIFT;
236 pvec->ldp_nr = page_count;
237
238 /* FIXME: in ll_direct_rw_pages, it has to allocate many cl_page{}s to
239 * write those pages into OST. Even worse case is that more pages
240 * would be asked to write out to swap space, and then finally get here
241 * again.
242 * Unfortunately this is NOT easy to fix.
243 * Thoughts on solution:
244 * 0. Define a reserved pool for cl_pages, which could be a list of
245 * pre-allocated cl_pages;
246 * 1. Define a new operation in cl_object_operations{}, says clo_depth,
247 * which measures how many layers for this lustre object. Generally
248 * speaking, the depth would be 2, one for llite, and one for lovsub.
249 * However, for SNS, there will be more since we need additional page
250 * to store parity;
251 * 2. Reserve the # of (page_count * depth) cl_pages from the reserved
252 * pool. Afterwards, the clio would allocate the pages from reserved
253 * pool, this guarantees we needn't allocate the cl_pages from
254 * generic cl_page slab cache.
255 * Of course, if there is NOT enough pages in the pool, we might
256 * be asked to write less pages once, this purely depends on
257 * implementation. Anyway, we should be careful to avoid deadlocking.
258 */
259 inode_lock(inode);
260 bytes = ll_direct_rw_pages(env, io, rw, inode, pvec);
261 inode_unlock(inode);
262 cl_io_fini(env, io);
263 return (bytes == pvec->ldp_size) ? 0 : (int)bytes;
264}
265
266/*
267 * Add bio to back of pending list
268 */
269static void loop_add_bio(struct lloop_device *lo, struct bio *bio)
270{
271 unsigned long flags;
272
273 spin_lock_irqsave(&lo->lo_lock, flags);
274 if (lo->lo_biotail) {
275 lo->lo_biotail->bi_next = bio;
276 lo->lo_biotail = bio;
277 } else {
278 lo->lo_bio = lo->lo_biotail = bio;
279 }
280 spin_unlock_irqrestore(&lo->lo_lock, flags);
281
282 atomic_inc(&lo->lo_pending);
283 if (waitqueue_active(&lo->lo_bh_wait))
284 wake_up(&lo->lo_bh_wait);
285}
286
287/*
288 * Grab first pending buffer
289 */
290static unsigned int loop_get_bio(struct lloop_device *lo, struct bio **req)
291{
292 struct bio *first;
293 struct bio **bio;
294 unsigned int count = 0;
295 unsigned int page_count = 0;
296 int rw;
297
298 spin_lock_irq(&lo->lo_lock);
299 first = lo->lo_bio;
300 if (unlikely(!first)) {
301 spin_unlock_irq(&lo->lo_lock);
302 return 0;
303 }
304
305 /* TODO: need to split the bio, too bad. */
306 LASSERT(first->bi_vcnt <= LLOOP_MAX_SEGMENTS);
307
308 rw = first->bi_rw;
309 bio = &lo->lo_bio;
310 while (*bio && (*bio)->bi_rw == rw) {
311 CDEBUG(D_INFO, "bio sector %llu size %u count %u vcnt%u\n",
312 (unsigned long long)(*bio)->bi_iter.bi_sector,
313 (*bio)->bi_iter.bi_size,
314 page_count, (*bio)->bi_vcnt);
315 if (page_count + (*bio)->bi_vcnt > LLOOP_MAX_SEGMENTS)
316 break;
317
318 page_count += (*bio)->bi_vcnt;
319 count++;
320 bio = &(*bio)->bi_next;
321 }
322 if (*bio) {
323 /* Some of bios can't be mergeable. */
324 lo->lo_bio = *bio;
325 *bio = NULL;
326 } else {
327 /* Hit the end of queue */
328 lo->lo_biotail = NULL;
329 lo->lo_bio = NULL;
330 }
331 *req = first;
332 spin_unlock_irq(&lo->lo_lock);
333 return count;
334}
335
336static blk_qc_t loop_make_request(struct request_queue *q, struct bio *old_bio)
337{
338 struct lloop_device *lo = q->queuedata;
339 int rw = bio_rw(old_bio);
340 int inactive;
341
342 blk_queue_split(q, &old_bio, q->bio_split);
343
344 if (!lo)
345 goto err;
346
347 CDEBUG(D_INFO, "submit bio sector %llu size %u\n",
348 (unsigned long long)old_bio->bi_iter.bi_sector,
349 old_bio->bi_iter.bi_size);
350
351 spin_lock_irq(&lo->lo_lock);
352 inactive = lo->lo_state != LLOOP_BOUND;
353 spin_unlock_irq(&lo->lo_lock);
354 if (inactive)
355 goto err;
356
357 if (rw == WRITE) {
358 if (lo->lo_flags & LO_FLAGS_READ_ONLY)
359 goto err;
360 } else if (rw == READA) {
361 rw = READ;
362 } else if (rw != READ) {
363 CERROR("lloop: unknown command (%x)\n", rw);
364 goto err;
365 }
366 loop_add_bio(lo, old_bio);
367 return BLK_QC_T_NONE;
368err:
369 bio_io_error(old_bio);
370 return BLK_QC_T_NONE;
371}
372
373static inline void loop_handle_bio(struct lloop_device *lo, struct bio *bio)
374{
375 int ret;
376
377 ret = do_bio_lustrebacked(lo, bio);
378 while (bio) {
379 struct bio *tmp = bio->bi_next;
380
381 bio->bi_next = NULL;
382 bio->bi_error = ret;
383 bio_endio(bio);
384 bio = tmp;
385 }
386}
387
388static inline int loop_active(struct lloop_device *lo)
389{
390 return atomic_read(&lo->lo_pending) ||
391 (lo->lo_state == LLOOP_RUNDOWN);
392}
393
394/*
395 * worker thread that handles reads/writes to file backed loop devices,
396 * to avoid blocking in our make_request_fn.
397 */
398static int loop_thread(void *data)
399{
400 struct lloop_device *lo = data;
401 struct bio *bio;
402 unsigned int count;
403 unsigned long times = 0;
404 unsigned long total_count = 0;
405
406 struct lu_env *env;
407 int refcheck;
408 int ret = 0;
409
410 set_user_nice(current, MIN_NICE);
411
412 lo->lo_state = LLOOP_BOUND;
413
414 env = cl_env_get(&refcheck);
415 if (IS_ERR(env)) {
416 ret = PTR_ERR(env);
417 goto out;
418 }
419
420 lo->lo_env = env;
421 memset(&lo->lo_pvec, 0, sizeof(lo->lo_pvec));
422 lo->lo_pvec.ldp_pages = lo->lo_requests[0].lrd_pages;
423 lo->lo_pvec.ldp_offsets = lo->lo_requests[0].lrd_offsets;
424
425 /*
426 * up sem, we are running
427 */
428 up(&lo->lo_sem);
429
430 for (;;) {
431 wait_event(lo->lo_bh_wait, loop_active(lo));
432 if (!atomic_read(&lo->lo_pending)) {
433 int exiting = 0;
434
435 spin_lock_irq(&lo->lo_lock);
436 exiting = (lo->lo_state == LLOOP_RUNDOWN);
437 spin_unlock_irq(&lo->lo_lock);
438 if (exiting)
439 break;
440 }
441
442 bio = NULL;
443 count = loop_get_bio(lo, &bio);
444 if (!count) {
445 CWARN("lloop(minor: %d): missing bio\n", lo->lo_number);
446 continue;
447 }
448
449 total_count += count;
450 if (total_count < count) { /* overflow */
451 total_count = count;
452 times = 1;
453 } else {
454 times++;
455 }
456 if ((times & 127) == 0) {
457 CDEBUG(D_INFO, "total: %lu, count: %lu, avg: %lu\n",
458 total_count, times, total_count / times);
459 }
460
461 LASSERT(bio);
462 LASSERT(count <= atomic_read(&lo->lo_pending));
463 loop_handle_bio(lo, bio);
464 atomic_sub(count, &lo->lo_pending);
465 }
466 cl_env_put(env, &refcheck);
467
468out:
469 up(&lo->lo_sem);
470 return ret;
471}
472
473static int loop_set_fd(struct lloop_device *lo, struct file *unused,
474 struct block_device *bdev, struct file *file)
475{
476 struct inode *inode;
477 struct address_space *mapping;
478 int lo_flags = 0;
479 int error;
480 loff_t size;
481
482 if (!try_module_get(THIS_MODULE))
483 return -ENODEV;
484
485 error = -EBUSY;
486 if (lo->lo_state != LLOOP_UNBOUND)
487 goto out;
488
489 mapping = file->f_mapping;
490 inode = mapping->host;
491
492 error = -EINVAL;
493 if (!S_ISREG(inode->i_mode) || inode->i_sb->s_magic != LL_SUPER_MAGIC)
494 goto out;
495
496 if (!(file->f_mode & FMODE_WRITE))
497 lo_flags |= LO_FLAGS_READ_ONLY;
498
499 size = get_loop_size(lo, file);
500
501 if ((loff_t)(sector_t)size != size) {
502 error = -EFBIG;
503 goto out;
504 }
505
506 /* remove all pages in cache so as dirty pages not to be existent. */
507 truncate_inode_pages(mapping, 0);
508
509 set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0);
510
511 lo->lo_blocksize = PAGE_SIZE;
512 lo->lo_device = bdev;
513 lo->lo_flags = lo_flags;
514 lo->lo_backing_file = file;
515 lo->lo_sizelimit = 0;
516 lo->old_gfp_mask = mapping_gfp_mask(mapping);
517 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
518
519 lo->lo_bio = lo->lo_biotail = NULL;
520
521 /*
522 * set queue make_request_fn, and add limits based on lower level
523 * device
524 */
525 blk_queue_make_request(lo->lo_queue, loop_make_request);
526 lo->lo_queue->queuedata = lo;
527
528 /* queue parameters */
529 CLASSERT(PAGE_SIZE < (1 << (sizeof(unsigned short) * 8)));
530 blk_queue_logical_block_size(lo->lo_queue,
531 (unsigned short)PAGE_SIZE);
532 blk_queue_max_hw_sectors(lo->lo_queue,
533 LLOOP_MAX_SEGMENTS << (PAGE_SHIFT - 9));
534 blk_queue_max_segments(lo->lo_queue, LLOOP_MAX_SEGMENTS);
535
536 set_capacity(disks[lo->lo_number], size);
537 bd_set_size(bdev, size << 9);
538
539 set_blocksize(bdev, lo->lo_blocksize);
540
541 kthread_run(loop_thread, lo, "lloop%d", lo->lo_number);
542 down(&lo->lo_sem);
543 return 0;
544
545out:
546 /* This is safe: open() is still holding a reference. */
547 module_put(THIS_MODULE);
548 return error;
549}
550
551static int loop_clr_fd(struct lloop_device *lo, struct block_device *bdev,
552 int count)
553{
554 struct file *filp = lo->lo_backing_file;
555 gfp_t gfp = lo->old_gfp_mask;
556
557 if (lo->lo_state != LLOOP_BOUND)
558 return -ENXIO;
559
560 if (lo->lo_refcnt > count) /* we needed one fd for the ioctl */
561 return -EBUSY;
562
563 if (!filp)
564 return -EINVAL;
565
566 spin_lock_irq(&lo->lo_lock);
567 lo->lo_state = LLOOP_RUNDOWN;
568 spin_unlock_irq(&lo->lo_lock);
569 wake_up(&lo->lo_bh_wait);
570
571 down(&lo->lo_sem);
572 lo->lo_backing_file = NULL;
573 lo->lo_device = NULL;
574 lo->lo_offset = 0;
575 lo->lo_sizelimit = 0;
576 lo->lo_flags = 0;
577 invalidate_bdev(bdev);
578 set_capacity(disks[lo->lo_number], 0);
579 bd_set_size(bdev, 0);
580 mapping_set_gfp_mask(filp->f_mapping, gfp);
581 lo->lo_state = LLOOP_UNBOUND;
582 fput(filp);
583 /* This is safe: open() is still holding a reference. */
584 module_put(THIS_MODULE);
585 return 0;
586}
587
588static int lo_open(struct block_device *bdev, fmode_t mode)
589{
590 struct lloop_device *lo = bdev->bd_disk->private_data;
591
592 mutex_lock(&lo->lo_ctl_mutex);
593 lo->lo_refcnt++;
594 mutex_unlock(&lo->lo_ctl_mutex);
595
596 return 0;
597}
598
599static void lo_release(struct gendisk *disk, fmode_t mode)
600{
601 struct lloop_device *lo = disk->private_data;
602
603 mutex_lock(&lo->lo_ctl_mutex);
604 --lo->lo_refcnt;
605 mutex_unlock(&lo->lo_ctl_mutex);
606}
607
608/* lloop device node's ioctl function. */
609static int lo_ioctl(struct block_device *bdev, fmode_t mode,
610 unsigned int cmd, unsigned long arg)
611{
612 struct lloop_device *lo = bdev->bd_disk->private_data;
613 struct inode *inode = NULL;
614 int err = 0;
615
616 mutex_lock(&lloop_mutex);
617 switch (cmd) {
618 case LL_IOC_LLOOP_DETACH: {
619 err = loop_clr_fd(lo, bdev, 2);
620 if (err == 0)
621 blkdev_put(bdev, 0); /* grabbed in LLOOP_ATTACH */
622 break;
623 }
624
625 case LL_IOC_LLOOP_INFO: {
626 struct lu_fid fid;
627
628 if (!lo->lo_backing_file) {
629 err = -ENOENT;
630 break;
631 }
632 if (!inode)
633 inode = file_inode(lo->lo_backing_file);
634 if (lo->lo_state == LLOOP_BOUND)
635 fid = ll_i2info(inode)->lli_fid;
636 else
637 fid_zero(&fid);
638
639 if (copy_to_user((void __user *)arg, &fid, sizeof(fid)))
640 err = -EFAULT;
641 break;
642 }
643
644 default:
645 err = -EINVAL;
646 break;
647 }
648 mutex_unlock(&lloop_mutex);
649
650 return err;
651}
652
653static struct block_device_operations lo_fops = {
654 .owner = THIS_MODULE,
655 .open = lo_open,
656 .release = lo_release,
657 .ioctl = lo_ioctl,
658};
659
660/* dynamic iocontrol callback.
661 * This callback is registered in lloop_init and will be called by
662 * ll_iocontrol_call.
663 *
664 * This is a llite regular file ioctl function. It takes the responsibility
665 * of attaching or detaching a file by a lloop's device number.
666 */
667static enum llioc_iter lloop_ioctl(struct inode *unused, struct file *file,
668 unsigned int cmd, unsigned long arg,
669 void *magic, int *rcp)
670{
671 struct lloop_device *lo = NULL;
672 struct block_device *bdev = NULL;
673 int err = 0;
674 dev_t dev;
675
676 if (magic != ll_iocontrol_magic)
677 return LLIOC_CONT;
678
679 if (!disks) {
680 err = -ENODEV;
681 goto out1;
682 }
683
684 CWARN("Enter llop_ioctl\n");
685
686 mutex_lock(&lloop_mutex);
687 switch (cmd) {
688 case LL_IOC_LLOOP_ATTACH: {
689 struct lloop_device *lo_free = NULL;
690 int i;
691
692 for (i = 0; i < max_loop; i++, lo = NULL) {
693 lo = &loop_dev[i];
694 if (lo->lo_state == LLOOP_UNBOUND) {
695 if (!lo_free)
696 lo_free = lo;
697 continue;
698 }
699 if (file_inode(lo->lo_backing_file) == file_inode(file))
700 break;
701 }
702 if (lo || !lo_free) {
703 err = -EBUSY;
704 goto out;
705 }
706
707 lo = lo_free;
708 dev = MKDEV(lloop_major, lo->lo_number);
709
710 /* quit if the used pointer is writable */
711 if (put_user((long)old_encode_dev(dev), (long __user *)arg)) {
712 err = -EFAULT;
713 goto out;
714 }
715
716 bdev = blkdev_get_by_dev(dev, file->f_mode, NULL);
717 if (IS_ERR(bdev)) {
718 err = PTR_ERR(bdev);
719 goto out;
720 }
721
722 get_file(file);
723 err = loop_set_fd(lo, NULL, bdev, file);
724 if (err) {
725 fput(file);
726 blkdev_put(bdev, 0);
727 }
728
729 break;
730 }
731
732 case LL_IOC_LLOOP_DETACH_BYDEV: {
733 int minor;
734
735 dev = old_decode_dev(arg);
736 if (MAJOR(dev) != lloop_major) {
737 err = -EINVAL;
738 goto out;
739 }
740
741 minor = MINOR(dev);
742 if (minor > max_loop - 1) {
743 err = -EINVAL;
744 goto out;
745 }
746
747 lo = &loop_dev[minor];
748 if (lo->lo_state != LLOOP_BOUND) {
749 err = -EINVAL;
750 goto out;
751 }
752
753 bdev = lo->lo_device;
754 err = loop_clr_fd(lo, bdev, 1);
755 if (err == 0)
756 blkdev_put(bdev, 0); /* grabbed in LLOOP_ATTACH */
757
758 break;
759 }
760
761 default:
762 err = -EINVAL;
763 break;
764 }
765
766out:
767 mutex_unlock(&lloop_mutex);
768out1:
769 if (rcp)
770 *rcp = err;
771 return LLIOC_STOP;
772}
773
774static int __init lloop_init(void)
775{
776 int i;
777 unsigned int cmdlist[] = {
778 LL_IOC_LLOOP_ATTACH,
779 LL_IOC_LLOOP_DETACH_BYDEV,
780 };
781
782 if (max_loop < 1 || max_loop > 256) {
783 max_loop = MAX_LOOP_DEFAULT;
784 CWARN("lloop: invalid max_loop (must be between 1 and 256), using default (%u)\n",
785 max_loop);
786 }
787
788 lloop_major = register_blkdev(0, "lloop");
789 if (lloop_major < 0)
790 return -EIO;
791
792 CDEBUG(D_CONFIG, "registered lloop major %d with %u minors\n",
793 lloop_major, max_loop);
794
795 ll_iocontrol_magic = ll_iocontrol_register(lloop_ioctl, 2, cmdlist);
796 if (!ll_iocontrol_magic)
797 goto out_mem1;
798
799 loop_dev = kcalloc(max_loop, sizeof(*loop_dev), GFP_KERNEL);
800 if (!loop_dev)
801 goto out_mem1;
802
803 disks = kcalloc(max_loop, sizeof(*disks), GFP_KERNEL);
804 if (!disks)
805 goto out_mem2;
806
807 for (i = 0; i < max_loop; i++) {
808 disks[i] = alloc_disk(1);
809 if (!disks[i])
810 goto out_mem3;
811 }
812
813 mutex_init(&lloop_mutex);
814
815 for (i = 0; i < max_loop; i++) {
816 struct lloop_device *lo = &loop_dev[i];
817 struct gendisk *disk = disks[i];
818
819 lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
820 if (!lo->lo_queue)
821 goto out_mem4;
822
823 mutex_init(&lo->lo_ctl_mutex);
824 sema_init(&lo->lo_sem, 0);
825 init_waitqueue_head(&lo->lo_bh_wait);
826 lo->lo_number = i;
827 spin_lock_init(&lo->lo_lock);
828 disk->major = lloop_major;
829 disk->first_minor = i;
830 disk->fops = &lo_fops;
831 sprintf(disk->disk_name, "lloop%d", i);
832 disk->private_data = lo;
833 disk->queue = lo->lo_queue;
834 }
835
836 /* We cannot fail after we call this, so another loop!*/
837 for (i = 0; i < max_loop; i++)
838 add_disk(disks[i]);
839 return 0;
840
841out_mem4:
842 while (i--)
843 blk_cleanup_queue(loop_dev[i].lo_queue);
844 i = max_loop;
845out_mem3:
846 while (i--)
847 put_disk(disks[i]);
848 kfree(disks);
849out_mem2:
850 kfree(loop_dev);
851out_mem1:
852 unregister_blkdev(lloop_major, "lloop");
853 ll_iocontrol_unregister(ll_iocontrol_magic);
854 CERROR("lloop: ran out of memory\n");
855 return -ENOMEM;
856}
857
858static void lloop_exit(void)
859{
860 int i;
861
862 ll_iocontrol_unregister(ll_iocontrol_magic);
863 for (i = 0; i < max_loop; i++) {
864 del_gendisk(disks[i]);
865 blk_cleanup_queue(loop_dev[i].lo_queue);
866 put_disk(disks[i]);
867 }
868
869 unregister_blkdev(lloop_major, "lloop");
870
871 kfree(disks);
872 kfree(loop_dev);
873}
874
875module_param(max_loop, int, 0444);
876MODULE_PARM_DESC(max_loop, "maximum of lloop_device");
877MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
878MODULE_DESCRIPTION("Lustre virtual block device");
879MODULE_VERSION(LUSTRE_VERSION_STRING);
880MODULE_LICENSE("GPL");
881
882module_init(lloop_init);
883module_exit(lloop_exit);
diff --git a/drivers/staging/lustre/lustre/llite/lproc_llite.c b/drivers/staging/lustre/lustre/llite/lproc_llite.c
index 55d62eb11957..6e9a8a5920c0 100644
--- a/drivers/staging/lustre/lustre/llite/lproc_llite.c
+++ b/drivers/staging/lustre/lustre/llite/lproc_llite.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
index 5eba0ebae10f..d7459bdea82e 100644
--- a/drivers/staging/lustre/lustre/llite/namei.c
+++ b/drivers/staging/lustre/lustre/llite/namei.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -318,7 +314,8 @@ static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
318 if (hlist_empty(&inode->i_dentry)) 314 if (hlist_empty(&inode->i_dentry))
319 return NULL; 315 return NULL;
320 316
321 discon_alias = invalid_alias = NULL; 317 discon_alias = NULL;
318 invalid_alias = NULL;
322 319
323 ll_lock_dcache(inode); 320 ll_lock_dcache(inode);
324 hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { 321 hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
diff --git a/drivers/staging/lustre/lustre/llite/remote_perm.c b/drivers/staging/lustre/lustre/llite/remote_perm.c
index e9d25317cd28..9df9e784ae3e 100644
--- a/drivers/staging/lustre/lustre/llite/remote_perm.c
+++ b/drivers/staging/lustre/lustre/llite/remote_perm.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/rw.c b/drivers/staging/lustre/lustre/llite/rw.c
index 336397773fbb..87393c4bd51e 100644
--- a/drivers/staging/lustre/lustre/llite/rw.c
+++ b/drivers/staging/lustre/lustre/llite/rw.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -59,84 +55,6 @@
59#include "llite_internal.h" 55#include "llite_internal.h"
60#include "../include/linux/lustre_compat25.h" 56#include "../include/linux/lustre_compat25.h"
61 57
62/**
63 * Finalizes cl-data before exiting typical address_space operation. Dual to
64 * ll_cl_init().
65 */
66void ll_cl_fini(struct ll_cl_context *lcc)
67{
68 struct lu_env *env = lcc->lcc_env;
69 struct cl_io *io = lcc->lcc_io;
70 struct cl_page *page = lcc->lcc_page;
71
72 LASSERT(lcc->lcc_cookie == current);
73 LASSERT(env);
74
75 if (page) {
76 lu_ref_del(&page->cp_reference, "cl_io", io);
77 cl_page_put(env, page);
78 }
79
80 cl_env_put(env, &lcc->lcc_refcheck);
81}
82
83/**
84 * Initializes common cl-data at the typical address_space operation entry
85 * point.
86 */
87struct ll_cl_context *ll_cl_init(struct file *file, struct page *vmpage)
88{
89 struct ll_cl_context *lcc;
90 struct lu_env *env;
91 struct cl_io *io;
92 struct cl_object *clob;
93 struct vvp_io *vio;
94
95 int refcheck;
96 int result = 0;
97
98 clob = ll_i2info(file_inode(file))->lli_clob;
99 LASSERT(clob);
100
101 env = cl_env_get(&refcheck);
102 if (IS_ERR(env))
103 return ERR_CAST(env);
104
105 lcc = &ll_env_info(env)->lti_io_ctx;
106 memset(lcc, 0, sizeof(*lcc));
107 lcc->lcc_env = env;
108 lcc->lcc_refcheck = refcheck;
109 lcc->lcc_cookie = current;
110
111 vio = vvp_env_io(env);
112 io = vio->vui_cl.cis_io;
113 lcc->lcc_io = io;
114 if (!io)
115 result = -EIO;
116
117 if (result == 0 && vmpage) {
118 struct cl_page *page;
119
120 LASSERT(io->ci_state == CIS_IO_GOING);
121 LASSERT(vio->vui_fd == LUSTRE_FPRIVATE(file));
122 page = cl_page_find(env, clob, vmpage->index, vmpage,
123 CPT_CACHEABLE);
124 if (!IS_ERR(page)) {
125 lcc->lcc_page = page;
126 lu_ref_add(&page->cp_reference, "cl_io", io);
127 result = 0;
128 } else {
129 result = PTR_ERR(page);
130 }
131 }
132 if (result) {
133 ll_cl_fini(lcc);
134 lcc = ERR_PTR(result);
135 }
136
137 return lcc;
138}
139
140static void ll_ra_stats_inc_sbi(struct ll_sb_info *sbi, enum ra_stat which); 58static void ll_ra_stats_inc_sbi(struct ll_sb_info *sbi, enum ra_stat which);
141 59
142/** 60/**
@@ -1112,17 +1030,70 @@ int ll_writepages(struct address_space *mapping, struct writeback_control *wbc)
1112 return result; 1030 return result;
1113} 1031}
1114 1032
1033struct ll_cl_context *ll_cl_find(struct file *file)
1034{
1035 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1036 struct ll_cl_context *lcc;
1037 struct ll_cl_context *found = NULL;
1038
1039 read_lock(&fd->fd_lock);
1040 list_for_each_entry(lcc, &fd->fd_lccs, lcc_list) {
1041 if (lcc->lcc_cookie == current) {
1042 found = lcc;
1043 break;
1044 }
1045 }
1046 read_unlock(&fd->fd_lock);
1047
1048 return found;
1049}
1050
1051void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io)
1052{
1053 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1054 struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx;
1055
1056 memset(lcc, 0, sizeof(*lcc));
1057 INIT_LIST_HEAD(&lcc->lcc_list);
1058 lcc->lcc_cookie = current;
1059 lcc->lcc_env = env;
1060 lcc->lcc_io = io;
1061
1062 write_lock(&fd->fd_lock);
1063 list_add(&lcc->lcc_list, &fd->fd_lccs);
1064 write_unlock(&fd->fd_lock);
1065}
1066
1067void ll_cl_remove(struct file *file, const struct lu_env *env)
1068{
1069 struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1070 struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx;
1071
1072 write_lock(&fd->fd_lock);
1073 list_del_init(&lcc->lcc_list);
1074 write_unlock(&fd->fd_lock);
1075}
1076
1115int ll_readpage(struct file *file, struct page *vmpage) 1077int ll_readpage(struct file *file, struct page *vmpage)
1116{ 1078{
1079 struct cl_object *clob = ll_i2info(file_inode(file))->lli_clob;
1117 struct ll_cl_context *lcc; 1080 struct ll_cl_context *lcc;
1081 const struct lu_env *env;
1082 struct cl_io *io;
1083 struct cl_page *page;
1118 int result; 1084 int result;
1119 1085
1120 lcc = ll_cl_init(file, vmpage); 1086 lcc = ll_cl_find(file);
1121 if (!IS_ERR(lcc)) { 1087 if (!lcc) {
1122 struct lu_env *env = lcc->lcc_env; 1088 unlock_page(vmpage);
1123 struct cl_io *io = lcc->lcc_io; 1089 return -EIO;
1124 struct cl_page *page = lcc->lcc_page; 1090 }
1125 1091
1092 env = lcc->lcc_env;
1093 io = lcc->lcc_io;
1094 LASSERT(io->ci_state == CIS_IO_GOING);
1095 page = cl_page_find(env, clob, vmpage->index, vmpage, CPT_CACHEABLE);
1096 if (!IS_ERR(page)) {
1126 LASSERT(page->cp_type == CPT_CACHEABLE); 1097 LASSERT(page->cp_type == CPT_CACHEABLE);
1127 if (likely(!PageUptodate(vmpage))) { 1098 if (likely(!PageUptodate(vmpage))) {
1128 cl_page_assume(env, io, page); 1099 cl_page_assume(env, io, page);
@@ -1132,10 +1103,10 @@ int ll_readpage(struct file *file, struct page *vmpage)
1132 unlock_page(vmpage); 1103 unlock_page(vmpage);
1133 result = 0; 1104 result = 0;
1134 } 1105 }
1135 ll_cl_fini(lcc); 1106 cl_page_put(env, page);
1136 } else { 1107 } else {
1137 unlock_page(vmpage); 1108 unlock_page(vmpage);
1138 result = PTR_ERR(lcc); 1109 result = PTR_ERR(page);
1139 } 1110 }
1140 return result; 1111 return result;
1141} 1112}
diff --git a/drivers/staging/lustre/lustre/llite/rw26.c b/drivers/staging/lustre/lustre/llite/rw26.c
index c12a048fce59..d98c7acc0832 100644
--- a/drivers/staging/lustre/lustre/llite/rw26.c
+++ b/drivers/staging/lustre/lustre/llite/rw26.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -489,7 +485,7 @@ static int ll_write_begin(struct file *file, struct address_space *mapping,
489 struct page **pagep, void **fsdata) 485 struct page **pagep, void **fsdata)
490{ 486{
491 struct ll_cl_context *lcc; 487 struct ll_cl_context *lcc;
492 struct lu_env *env; 488 const struct lu_env *env;
493 struct cl_io *io; 489 struct cl_io *io;
494 struct cl_page *page; 490 struct cl_page *page;
495 struct cl_object *clob = ll_i2info(mapping->host)->lli_clob; 491 struct cl_object *clob = ll_i2info(mapping->host)->lli_clob;
@@ -501,9 +497,9 @@ static int ll_write_begin(struct file *file, struct address_space *mapping,
501 497
502 CDEBUG(D_VFSTRACE, "Writing %lu of %d to %d bytes\n", index, from, len); 498 CDEBUG(D_VFSTRACE, "Writing %lu of %d to %d bytes\n", index, from, len);
503 499
504 lcc = ll_cl_init(file, NULL); 500 lcc = ll_cl_find(file);
505 if (IS_ERR(lcc)) { 501 if (!lcc) {
506 result = PTR_ERR(lcc); 502 result = -EIO;
507 goto out; 503 goto out;
508 } 504 }
509 505
@@ -579,8 +575,6 @@ out:
579 unlock_page(vmpage); 575 unlock_page(vmpage);
580 put_page(vmpage); 576 put_page(vmpage);
581 } 577 }
582 if (!IS_ERR(lcc))
583 ll_cl_fini(lcc);
584 } else { 578 } else {
585 *pagep = vmpage; 579 *pagep = vmpage;
586 *fsdata = lcc; 580 *fsdata = lcc;
@@ -593,7 +587,7 @@ static int ll_write_end(struct file *file, struct address_space *mapping,
593 struct page *vmpage, void *fsdata) 587 struct page *vmpage, void *fsdata)
594{ 588{
595 struct ll_cl_context *lcc = fsdata; 589 struct ll_cl_context *lcc = fsdata;
596 struct lu_env *env; 590 const struct lu_env *env;
597 struct cl_io *io; 591 struct cl_io *io;
598 struct vvp_io *vio; 592 struct vvp_io *vio;
599 struct cl_page *page; 593 struct cl_page *page;
@@ -631,6 +625,10 @@ static int ll_write_end(struct file *file, struct address_space *mapping,
631 } else { 625 } else {
632 cl_page_disown(env, io, page); 626 cl_page_disown(env, io, page);
633 627
628 lcc->lcc_page = NULL;
629 lu_ref_del(&page->cp_reference, "cl_io", io);
630 cl_page_put(env, page);
631
634 /* page list is not contiguous now, commit it now */ 632 /* page list is not contiguous now, commit it now */
635 unplug = true; 633 unplug = true;
636 } 634 }
@@ -639,7 +637,6 @@ static int ll_write_end(struct file *file, struct address_space *mapping,
639 file->f_flags & O_SYNC || IS_SYNC(file_inode(file))) 637 file->f_flags & O_SYNC || IS_SYNC(file_inode(file)))
640 result = vvp_io_write_commit(env, io); 638 result = vvp_io_write_commit(env, io);
641 639
642 ll_cl_fini(lcc);
643 return result >= 0 ? copied : result; 640 return result >= 0 ? copied : result;
644} 641}
645 642
diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c
index 6322f88661e8..03ad858039f0 100644
--- a/drivers/staging/lustre/lustre/llite/statahead.c
+++ b/drivers/staging/lustre/lustre/llite/statahead.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/super25.c b/drivers/staging/lustre/lustre/llite/super25.c
index 415750b0bff4..b40ea79bb6f2 100644
--- a/drivers/staging/lustre/lustre/llite/super25.c
+++ b/drivers/staging/lustre/lustre/llite/super25.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/symlink.c b/drivers/staging/lustre/lustre/llite/symlink.c
index 3fc736ccf85e..8c8bdfe1ad71 100644
--- a/drivers/staging/lustre/lustre/llite/symlink.c
+++ b/drivers/staging/lustre/lustre/llite/symlink.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/vvp_dev.c b/drivers/staging/lustre/lustre/llite/vvp_dev.c
index 47101de1c020..e623216e962d 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_dev.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_dev.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -150,8 +146,8 @@ struct lu_context_key vvp_session_key = {
150 .lct_fini = vvp_session_key_fini 146 .lct_fini = vvp_session_key_fini
151}; 147};
152 148
153void *vvp_thread_key_init(const struct lu_context *ctx, 149static void *vvp_thread_key_init(const struct lu_context *ctx,
154 struct lu_context_key *key) 150 struct lu_context_key *key)
155{ 151{
156 struct vvp_thread_info *vti; 152 struct vvp_thread_info *vti;
157 153
@@ -161,8 +157,8 @@ void *vvp_thread_key_init(const struct lu_context *ctx,
161 return vti; 157 return vti;
162} 158}
163 159
164void vvp_thread_key_fini(const struct lu_context *ctx, 160static void vvp_thread_key_fini(const struct lu_context *ctx,
165 struct lu_context_key *key, void *data) 161 struct lu_context_key *key, void *data)
166{ 162{
167 struct vvp_thread_info *vti = data; 163 struct vvp_thread_info *vti = data;
168 164
@@ -564,7 +560,7 @@ static int vvp_pgcache_show(struct seq_file *f, void *v)
564 560
565 env = cl_env_get(&refcheck); 561 env = cl_env_get(&refcheck);
566 if (!IS_ERR(env)) { 562 if (!IS_ERR(env)) {
567 pos = *(loff_t *) v; 563 pos = *(loff_t *)v;
568 vvp_pgcache_id_unpack(pos, &id); 564 vvp_pgcache_id_unpack(pos, &id);
569 sbi = f->private; 565 sbi = f->private;
570 clob = vvp_pgcache_obj(env, &sbi->ll_cl->cd_lu_dev, &id); 566 clob = vvp_pgcache_obj(env, &sbi->ll_cl->cd_lu_dev, &id);
diff --git a/drivers/staging/lustre/lustre/llite/vvp_internal.h b/drivers/staging/lustre/lustre/llite/vvp_internal.h
index 27b9b0a01f32..79fc428461ed 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_internal.h
+++ b/drivers/staging/lustre/lustre/llite/vvp_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c
index 5bf9592ae5d2..94916dcc6caa 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_io.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_io.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -47,8 +43,8 @@
47#include "llite_internal.h" 43#include "llite_internal.h"
48#include "vvp_internal.h" 44#include "vvp_internal.h"
49 45
50struct vvp_io *cl2vvp_io(const struct lu_env *env, 46static struct vvp_io *cl2vvp_io(const struct lu_env *env,
51 const struct cl_io_slice *slice) 47 const struct cl_io_slice *slice)
52{ 48{
53 struct vvp_io *vio; 49 struct vvp_io *vio;
54 50
@@ -954,7 +950,8 @@ static int vvp_io_write_start(const struct lu_env *env,
954 * out-of-order writes. 950 * out-of-order writes.
955 */ 951 */
956 ll_merge_attr(env, inode); 952 ll_merge_attr(env, inode);
957 pos = io->u.ci_wr.wr.crw_pos = i_size_read(inode); 953 pos = i_size_read(inode);
954 io->u.ci_wr.wr.crw_pos = pos;
958 vio->vui_iocb->ki_pos = pos; 955 vio->vui_iocb->ki_pos = pos;
959 } else { 956 } else {
960 LASSERT(vio->vui_iocb->ki_pos == pos); 957 LASSERT(vio->vui_iocb->ki_pos == pos);
@@ -1259,7 +1256,7 @@ static int vvp_io_read_page(const struct lu_env *env,
1259 return 0; 1256 return 0;
1260} 1257}
1261 1258
1262void vvp_io_end(const struct lu_env *env, const struct cl_io_slice *ios) 1259static void vvp_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
1263{ 1260{
1264 CLOBINVRNT(env, ios->cis_io->ci_obj, 1261 CLOBINVRNT(env, ios->cis_io->ci_obj,
1265 vvp_object_invariant(ios->cis_io->ci_obj)); 1262 vvp_object_invariant(ios->cis_io->ci_obj));
diff --git a/drivers/staging/lustre/lustre/llite/vvp_lock.c b/drivers/staging/lustre/lustre/llite/vvp_lock.c
index f5bd6c22e112..64be0c9df35b 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_lock.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_lock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/vvp_object.c b/drivers/staging/lustre/lustre/llite/vvp_object.c
index 18c9df7ebdda..2c520b0bf6ca 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_object.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_object.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/vvp_page.c b/drivers/staging/lustre/lustre/llite/vvp_page.c
index 6cd2af7a958f..2e566d90bb94 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_page.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_page.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/llite/vvp_req.c b/drivers/staging/lustre/lustre/llite/vvp_req.c
index fb886291a4e2..9fe9d6c0a7d1 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_req.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_req.c
@@ -60,10 +60,10 @@ static inline struct vvp_req *cl2vvp_req(const struct cl_req_slice *slice)
60 * - o_ioepoch, 60 * - o_ioepoch,
61 * 61 *
62 */ 62 */
63void vvp_req_attr_set(const struct lu_env *env, 63static void vvp_req_attr_set(const struct lu_env *env,
64 const struct cl_req_slice *slice, 64 const struct cl_req_slice *slice,
65 const struct cl_object *obj, 65 const struct cl_object *obj,
66 struct cl_req_attr *attr, u64 flags) 66 struct cl_req_attr *attr, u64 flags)
67{ 67{
68 struct inode *inode; 68 struct inode *inode;
69 struct obdo *oa; 69 struct obdo *oa;
@@ -87,8 +87,8 @@ void vvp_req_attr_set(const struct lu_env *env,
87 JOBSTATS_JOBID_SIZE); 87 JOBSTATS_JOBID_SIZE);
88} 88}
89 89
90void vvp_req_completion(const struct lu_env *env, 90static void vvp_req_completion(const struct lu_env *env,
91 const struct cl_req_slice *slice, int ioret) 91 const struct cl_req_slice *slice, int ioret)
92{ 92{
93 struct vvp_req *vrq; 93 struct vvp_req *vrq;
94 94
diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 608014b0dbcd..6ce790e1aa58 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_fld.c b/drivers/staging/lustre/lustre/lmv/lmv_fld.c
index 378691b2a062..a3d170aa6fd2 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_fld.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_fld.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_intent.c b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
index e0958eaed054..980c9d45afb2 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_intent.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_internal.h b/drivers/staging/lustre/lustre/lmv/lmv_internal.h
index 7007e4c48035..0beafc49b8d2 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_internal.h
+++ b/drivers/staging/lustre/lustre/lmv/lmv_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
index 9e31f6b03f9e..ab4f4fbf0951 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -2686,7 +2682,7 @@ static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2686 struct lmv_obd *lmv = &obd->u.lmv; 2682 struct lmv_obd *lmv = &obd->u.lmv;
2687 struct lmv_tgt_desc *tgt = lmv->tgts[0]; 2683 struct lmv_tgt_desc *tgt = lmv->tgts[0];
2688 int rc = 0, i; 2684 int rc = 0, i;
2689 __u64 curspace, curinodes; 2685 __u64 curspace = 0, curinodes = 0;
2690 2686
2691 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active || 2687 if (!tgt || !tgt->ltd_exp || !tgt->ltd_active ||
2692 !lmv->desc.ld_tgt_count) { 2688 !lmv->desc.ld_tgt_count) {
@@ -2699,7 +2695,6 @@ static int lmv_quotactl(struct obd_device *unused, struct obd_export *exp,
2699 return rc; 2695 return rc;
2700 } 2696 }
2701 2697
2702 curspace = curinodes = 0;
2703 for (i = 0; i < lmv->desc.ld_tgt_count; i++) { 2698 for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
2704 int err; 2699 int err;
2705 2700
diff --git a/drivers/staging/lustre/lustre/lmv/lproc_lmv.c b/drivers/staging/lustre/lustre/lmv/lproc_lmv.c
index b39e364a29ab..c29c361eb0cc 100644
--- a/drivers/staging/lustre/lustre/lmv/lproc_lmv.c
+++ b/drivers/staging/lustre/lustre/lmv/lproc_lmv.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_cl_internal.h b/drivers/staging/lustre/lustre/lov/lov_cl_internal.h
index ac9744e887ae..9740568d9521 100644
--- a/drivers/staging/lustre/lustre/lov/lov_cl_internal.h
+++ b/drivers/staging/lustre/lustre/lov/lov_cl_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_dev.c b/drivers/staging/lustre/lustre/lov/lov_dev.c
index dae8e89bcf6d..b1f260d43bc7 100644
--- a/drivers/staging/lustre/lustre/lov/lov_dev.c
+++ b/drivers/staging/lustre/lustre/lov/lov_dev.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_ea.c b/drivers/staging/lustre/lustre/lov/lov_ea.c
index 460f0fa5e6b1..5053dead17bb 100644
--- a/drivers/staging/lustre/lustre/lov/lov_ea.c
+++ b/drivers/staging/lustre/lustre/lov/lov_ea.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_internal.h b/drivers/staging/lustre/lustre/lov/lov_internal.h
index eef9afac8467..12bd511e8988 100644
--- a/drivers/staging/lustre/lustre/lov/lov_internal.h
+++ b/drivers/staging/lustre/lustre/lov/lov_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_io.c b/drivers/staging/lustre/lustre/lov/lov_io.c
index 86cb3f8f9246..84032a510254 100644
--- a/drivers/staging/lustre/lustre/lov/lov_io.c
+++ b/drivers/staging/lustre/lustre/lov/lov_io.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_lock.c b/drivers/staging/lustre/lustre/lov/lov_lock.c
index 1b203d18c6e9..f3a0583f28f5 100644
--- a/drivers/staging/lustre/lustre/lov/lov_lock.c
+++ b/drivers/staging/lustre/lustre/lov/lov_lock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_merge.c b/drivers/staging/lustre/lustre/lov/lov_merge.c
index 56ef41d17ad7..b9c90865fdfc 100644
--- a/drivers/staging/lustre/lustre/lov/lov_merge.c
+++ b/drivers/staging/lustre/lustre/lov/lov_merge.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index e15ef2ece893..c87096ee8d38 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1772,7 +1768,8 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key,
1772 fm_start = fiemap->fm_start; 1768 fm_start = fiemap->fm_start;
1773 fm_length = fiemap->fm_length; 1769 fm_length = fiemap->fm_length;
1774 /* Calculate start stripe, last stripe and length of mapping */ 1770 /* Calculate start stripe, last stripe and length of mapping */
1775 actual_start_stripe = start_stripe = lov_stripe_number(lsm, fm_start); 1771 start_stripe = lov_stripe_number(lsm, fm_start);
1772 actual_start_stripe = start_stripe;
1776 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size : 1773 fm_end = (fm_length == ~0ULL ? fm_key->oa.o_size :
1777 fm_start + fm_length - 1); 1774 fm_start + fm_length - 1);
1778 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */ 1775 /* If fm_length != ~0ULL but fm_start+fm_length-1 exceeds file size */
@@ -2095,11 +2092,9 @@ static int lov_set_info_async(const struct lu_env *env, struct obd_export *exp,
2095 u32 count; 2092 u32 count;
2096 int i, rc = 0, err; 2093 int i, rc = 0, err;
2097 struct lov_tgt_desc *tgt; 2094 struct lov_tgt_desc *tgt;
2098 unsigned incr, check_uuid, 2095 unsigned int incr = 0, check_uuid = 0, do_inactive = 0, no_set = 0;
2099 do_inactive, no_set; 2096 unsigned int next_id = 0, mds_con = 0;
2100 unsigned next_id = 0, mds_con = 0;
2101 2097
2102 incr = check_uuid = do_inactive = no_set = 0;
2103 if (!set) { 2098 if (!set) {
2104 no_set = 1; 2099 no_set = 1;
2105 set = ptlrpc_prep_set(); 2100 set = ptlrpc_prep_set();
diff --git a/drivers/staging/lustre/lustre/lov/lov_object.c b/drivers/staging/lustre/lustre/lov/lov_object.c
index 561d493b2cdf..ec55b8837270 100644
--- a/drivers/staging/lustre/lustre/lov/lov_object.c
+++ b/drivers/staging/lustre/lustre/lov/lov_object.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_offset.c b/drivers/staging/lustre/lustre/lov/lov_offset.c
index 9302f06c34ef..ecca74fbff00 100644
--- a/drivers/staging/lustre/lustre/lov/lov_offset.c
+++ b/drivers/staging/lustre/lustre/lov/lov_offset.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -74,7 +70,7 @@ pgoff_t lov_stripe_pgoff(struct lov_stripe_md *lsm, pgoff_t stripe_index,
74{ 70{
75 loff_t offset; 71 loff_t offset;
76 72
77 offset = lov_stripe_size(lsm, stripe_index << PAGE_SHIFT, stripe); 73 offset = lov_stripe_size(lsm, (stripe_index << PAGE_SHIFT) + 1, stripe);
78 return offset >> PAGE_SHIFT; 74 return offset >> PAGE_SHIFT;
79} 75}
80 76
diff --git a/drivers/staging/lustre/lustre/lov/lov_pack.c b/drivers/staging/lustre/lustre/lov/lov_pack.c
index 0215ea54df8d..869ef41b13ca 100644
--- a/drivers/staging/lustre/lustre/lov/lov_pack.c
+++ b/drivers/staging/lustre/lustre/lov/lov_pack.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_page.c b/drivers/staging/lustre/lustre/lov/lov_page.c
index 0306f00c3f33..c17026f14896 100644
--- a/drivers/staging/lustre/lustre/lov/lov_page.c
+++ b/drivers/staging/lustre/lustre/lov/lov_page.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_pool.c b/drivers/staging/lustre/lustre/lov/lov_pool.c
index 690292ecebdc..4c2d21729589 100644
--- a/drivers/staging/lustre/lustre/lov/lov_pool.c
+++ b/drivers/staging/lustre/lustre/lov/lov_pool.c
@@ -14,12 +14,8 @@
14 * in the LICENSE file that accompanied this code). 14 * in the LICENSE file that accompanied this code).
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see [sun.com URL with a 17 * version 2 along with this program; If not, see
18 * copy of GPLv2]. 18 * http://http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lov_request.c b/drivers/staging/lustre/lustre/lov/lov_request.c
index 1be4b921c01f..4099b51f826e 100644
--- a/drivers/staging/lustre/lustre/lov/lov_request.c
+++ b/drivers/staging/lustre/lustre/lov/lov_request.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lovsub_dev.c b/drivers/staging/lustre/lustre/lov/lovsub_dev.c
index 35f6b1d66ff4..b519a1940e1e 100644
--- a/drivers/staging/lustre/lustre/lov/lovsub_dev.c
+++ b/drivers/staging/lustre/lustre/lov/lovsub_dev.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lovsub_io.c b/drivers/staging/lustre/lustre/lov/lovsub_io.c
index 783ec687a4e7..6a9820218a3e 100644
--- a/drivers/staging/lustre/lustre/lov/lovsub_io.c
+++ b/drivers/staging/lustre/lustre/lov/lovsub_io.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lovsub_lock.c b/drivers/staging/lustre/lustre/lov/lovsub_lock.c
index e92edfb618b7..38f9b735c241 100644
--- a/drivers/staging/lustre/lustre/lov/lovsub_lock.c
+++ b/drivers/staging/lustre/lustre/lov/lovsub_lock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lovsub_object.c b/drivers/staging/lustre/lustre/lov/lovsub_object.c
index bcaae1e5b840..fb2f2660b3e9 100644
--- a/drivers/staging/lustre/lustre/lov/lovsub_object.c
+++ b/drivers/staging/lustre/lustre/lov/lovsub_object.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lovsub_page.c b/drivers/staging/lustre/lustre/lov/lovsub_page.c
index 9badedcce2bf..b2e68c3e820d 100644
--- a/drivers/staging/lustre/lustre/lov/lovsub_page.c
+++ b/drivers/staging/lustre/lustre/lov/lovsub_page.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/lov/lproc_lov.c b/drivers/staging/lustre/lustre/lov/lproc_lov.c
index 0dcb6b6a7782..eb6d30d34e3a 100644
--- a/drivers/staging/lustre/lustre/lov/lproc_lov.c
+++ b/drivers/staging/lustre/lustre/lov/lproc_lov.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mdc/lproc_mdc.c b/drivers/staging/lustre/lustre/mdc/lproc_mdc.c
index 5c7a15dd7bd2..98d15fb247bc 100644
--- a/drivers/staging/lustre/lustre/mdc/lproc_mdc.c
+++ b/drivers/staging/lustre/lustre/mdc/lproc_mdc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_internal.h b/drivers/staging/lustre/lustre/mdc/mdc_internal.h
index c5519aeb0d8a..58f2841cabe4 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_internal.h
+++ b/drivers/staging/lustre/lustre/mdc/mdc_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_lib.c b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
index 856c54e03b6b..2703113f32c8 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_lib.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_locks.c b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
index 3b1bc9111b93..b3954204c4df 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_locks.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_reint.c b/drivers/staging/lustre/lustre/mdc/mdc_reint.c
index 4ef3db147f87..661488ee03f3 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_reint.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_reint.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 86b7445365f4..f371e1df47a4 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1807,7 +1803,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1807 case IOC_OBD_STATFS: { 1803 case IOC_OBD_STATFS: {
1808 struct obd_statfs stat_buf = {0}; 1804 struct obd_statfs stat_buf = {0};
1809 1805
1810 if (*((__u32 *) data->ioc_inlbuf2) != 0) { 1806 if (*((__u32 *)data->ioc_inlbuf2) != 0) {
1811 rc = -ENODEV; 1807 rc = -ENODEV;
1812 goto out; 1808 goto out;
1813 } 1809 }
@@ -2001,7 +1997,7 @@ static int mdc_hsm_copytool_send(int len, void *val)
2001 1997
2002 if (len < sizeof(*lh) + sizeof(*hal)) { 1998 if (len < sizeof(*lh) + sizeof(*hal)) {
2003 CERROR("Short HSM message %d < %d\n", len, 1999 CERROR("Short HSM message %d < %d\n", len,
2004 (int) (sizeof(*lh) + sizeof(*hal))); 2000 (int)(sizeof(*lh) + sizeof(*hal)));
2005 return -EPROTO; 2001 return -EPROTO;
2006 } 2002 }
2007 if (lh->kuc_magic == __swab16(KUC_MAGIC)) { 2003 if (lh->kuc_magic == __swab16(KUC_MAGIC)) {
diff --git a/drivers/staging/lustre/lustre/mgc/lproc_mgc.c b/drivers/staging/lustre/lustre/mgc/lproc_mgc.c
index 8d5bc5a751a4..0735220b2a18 100644
--- a/drivers/staging/lustre/lustre/mgc/lproc_mgc.c
+++ b/drivers/staging/lustre/lustre/mgc/lproc_mgc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mgc/mgc_internal.h b/drivers/staging/lustre/lustre/mgc/mgc_internal.h
index 82fb8f46e037..f146f7521c92 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_internal.h
+++ b/drivers/staging/lustre/lustre/mgc/mgc_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index 2311a437c441..fbbf2762ac84 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1034,7 +1030,7 @@ static int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
1034 rc = sptlrpc_parse_flavor(val, &flvr); 1030 rc = sptlrpc_parse_flavor(val, &flvr);
1035 if (rc) { 1031 if (rc) {
1036 CERROR("invalid sptlrpc flavor %s to MGS\n", 1032 CERROR("invalid sptlrpc flavor %s to MGS\n",
1037 (char *) val); 1033 (char *)val);
1038 return rc; 1034 return rc;
1039 } 1035 }
1040 1036
@@ -1050,7 +1046,7 @@ static int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
1050 sptlrpc_flavor2name(&cli->cl_flvr_mgc, 1046 sptlrpc_flavor2name(&cli->cl_flvr_mgc,
1051 str, sizeof(str)); 1047 str, sizeof(str));
1052 LCONSOLE_ERROR("asking sptlrpc flavor %s to MGS but currently %s is in use\n", 1048 LCONSOLE_ERROR("asking sptlrpc flavor %s to MGS but currently %s is in use\n",
1053 (char *) val, str); 1049 (char *)val, str);
1054 rc = -EPERM; 1050 rc = -EPERM;
1055 } 1051 }
1056 return rc; 1052 return rc;
diff --git a/drivers/staging/lustre/lustre/obdclass/acl.c b/drivers/staging/lustre/lustre/obdclass/acl.c
index 0e02ae97b7ed..30d8b4209716 100644
--- a/drivers/staging/lustre/lustre/obdclass/acl.c
+++ b/drivers/staging/lustre/lustre/obdclass/acl.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_internal.h b/drivers/staging/lustre/lustre/obdclass/cl_internal.h
index 7eb0ad7b3644..e866754a42d5 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_internal.h
+++ b/drivers/staging/lustre/lustre/obdclass/cl_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c
index 583fb5f33889..e72f1fc00a13 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_io.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
index 26a576b63a72..9d7b5939b0fd 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
index 5940f30318ec..91a5806d0239 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -577,7 +573,7 @@ static inline struct cl_env *cl_env_fetch(void)
577{ 573{
578 struct cl_env *cle; 574 struct cl_env *cle;
579 575
580 cle = cfs_hash_lookup(cl_env_hash, (void *) (long) current->pid); 576 cle = cfs_hash_lookup(cl_env_hash, (void *)(long)current->pid);
581 LASSERT(ergo(cle, cle->ce_magic == &cl_env_init0)); 577 LASSERT(ergo(cle, cle->ce_magic == &cl_env_init0));
582 return cle; 578 return cle;
583} 579}
@@ -588,7 +584,7 @@ static inline void cl_env_attach(struct cl_env *cle)
588 int rc; 584 int rc;
589 585
590 LASSERT(!cle->ce_owner); 586 LASSERT(!cle->ce_owner);
591 cle->ce_owner = (void *) (long) current->pid; 587 cle->ce_owner = (void *)(long)current->pid;
592 rc = cfs_hash_add_unique(cl_env_hash, cle->ce_owner, 588 rc = cfs_hash_add_unique(cl_env_hash, cle->ce_owner,
593 &cle->ce_node); 589 &cle->ce_node);
594 LASSERT(rc == 0); 590 LASSERT(rc == 0);
@@ -599,7 +595,7 @@ static inline void cl_env_do_detach(struct cl_env *cle)
599{ 595{
600 void *cookie; 596 void *cookie;
601 597
602 LASSERT(cle->ce_owner == (void *) (long) current->pid); 598 LASSERT(cle->ce_owner == (void *)(long)current->pid);
603 cookie = cfs_hash_del(cl_env_hash, cle->ce_owner, 599 cookie = cfs_hash_del(cl_env_hash, cle->ce_owner,
604 &cle->ce_node); 600 &cle->ce_node);
605 LASSERT(cookie == cle); 601 LASSERT(cookie == cle);
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c
index b754f516e557..71bff493cfc7 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_page.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
index f48816af8be7..d9d2a1952b8b 100644
--- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/debug.c b/drivers/staging/lustre/lustre/obdclass/debug.c
index e4edfb2c0a20..8acf67239fa8 100644
--- a/drivers/staging/lustre/lustre/obdclass/debug.c
+++ b/drivers/staging/lustre/lustre/obdclass/debug.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
index d95f11d62a32..99c2da632b51 100644
--- a/drivers/staging/lustre/lustre/obdclass/genops.c
+++ b/drivers/staging/lustre/lustre/obdclass/genops.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/kernelcomm.c b/drivers/staging/lustre/lustre/obdclass/kernelcomm.c
index 8405eccdac19..a0f65c470f4d 100644
--- a/drivers/staging/lustre/lustre/obdclass/kernelcomm.c
+++ b/drivers/staging/lustre/lustre/obdclass/kernelcomm.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
index 2cd4522462d9..33342bfcc90e 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
index b41b65e2f021..c6cc6a7666e3 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
index e6bf414a4444..8f70dd2686f9 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
index 79194d8cb587..1784ca063428 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -123,8 +119,10 @@ static int llog_read_header(const struct lu_env *env,
123 handle->lgh_last_idx = 0; /* header is record with index 0 */ 119 handle->lgh_last_idx = 0; /* header is record with index 0 */
124 llh->llh_count = 1; /* for the header record */ 120 llh->llh_count = 1; /* for the header record */
125 llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC; 121 llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC;
126 llh->llh_hdr.lrh_len = llh->llh_tail.lrt_len = LLOG_CHUNK_SIZE; 122 llh->llh_hdr.lrh_len = LLOG_CHUNK_SIZE;
127 llh->llh_hdr.lrh_index = llh->llh_tail.lrt_index = 0; 123 llh->llh_tail.lrt_len = LLOG_CHUNK_SIZE;
124 llh->llh_hdr.lrh_index = 0;
125 llh->llh_tail.lrt_index = 0;
128 llh->llh_timestamp = ktime_get_real_seconds(); 126 llh->llh_timestamp = ktime_get_real_seconds();
129 if (uuid) 127 if (uuid)
130 memcpy(&llh->llh_tgtuuid, uuid, 128 memcpy(&llh->llh_tgtuuid, uuid,
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_cat.c b/drivers/staging/lustre/lustre/obdclass/llog_cat.c
index c27d4ec1df9e..a82a2950295a 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_cat.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_cat.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_internal.h b/drivers/staging/lustre/lustre/obdclass/llog_internal.h
index 7fb48dda355e..f7949525d952 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_internal.h
+++ b/drivers/staging/lustre/lustre/obdclass/llog_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
index 826623f528da..6ace7e097859 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_swab.c b/drivers/staging/lustre/lustre/obdclass/llog_swab.c
index 967ba2e1bfcb..f7b9b190350c 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_swab.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_swab.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 5a1eae1de2ec..279b625f1afe 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
index e04385760f21..9b03059f34d6 100644
--- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_ref.c b/drivers/staging/lustre/lustre/obdclass/lu_ref.c
index 993697b660f6..e9f6040d19eb 100644
--- a/drivers/staging/lustre/lustre/obdclass/lu_ref.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_ref.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
index 403ceea06186..082f530c527c 100644
--- a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
+++ b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
index b1abe023bb35..5974a9bf77c0 100644
--- a/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
+++ b/drivers/staging/lustre/lustre/obdclass/lustre_peer.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
index cb1d65c3d95d..0eab1236501b 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1021,8 +1017,8 @@ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
1021 /* Search proc entries */ 1017 /* Search proc entries */
1022 while (lvars[j].name) { 1018 while (lvars[j].name) {
1023 var = &lvars[j]; 1019 var = &lvars[j];
1024 if (!class_match_param(key, var->name, NULL) 1020 if (!class_match_param(key, var->name, NULL) &&
1025 && keylen == strlen(var->name)) { 1021 keylen == strlen(var->name)) {
1026 matched++; 1022 matched++;
1027 rc = -EROFS; 1023 rc = -EROFS;
1028 if (var->fops && var->fops->write) { 1024 if (var->fops && var->fops->write) {
@@ -1077,7 +1073,7 @@ int class_config_llog_handler(const struct lu_env *env,
1077{ 1073{
1078 struct config_llog_instance *clli = data; 1074 struct config_llog_instance *clli = data;
1079 int cfg_len = rec->lrh_len; 1075 int cfg_len = rec->lrh_len;
1080 char *cfg_buf = (char *) (rec + 1); 1076 char *cfg_buf = (char *)(rec + 1);
1081 int rc = 0; 1077 int rc = 0;
1082 1078
1083 switch (rec->lrh_type) { 1079 switch (rec->lrh_type) {
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index e0c90adc72a7..aa84a50e9904 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -192,7 +188,7 @@ static int lustre_start_simple(char *obdname, char *type, char *uuid,
192 return rc; 188 return rc;
193} 189}
194 190
195DEFINE_MUTEX(mgc_start_lock); 191static DEFINE_MUTEX(mgc_start_lock);
196 192
197/** Set up a mgc obd to process startup logs 193/** Set up a mgc obd to process startup logs
198 * 194 *
diff --git a/drivers/staging/lustre/lustre/obdclass/obdo.c b/drivers/staging/lustre/lustre/obdclass/obdo.c
index 748e33f017d5..8583a4a8c206 100644
--- a/drivers/staging/lustre/lustre/obdclass/obdo.c
+++ b/drivers/staging/lustre/lustre/obdclass/obdo.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/statfs_pack.c b/drivers/staging/lustre/lustre/obdclass/statfs_pack.c
index fb4e3ae845e0..4bad1fa27d40 100644
--- a/drivers/staging/lustre/lustre/obdclass/statfs_pack.c
+++ b/drivers/staging/lustre/lustre/obdclass/statfs_pack.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdclass/uuid.c b/drivers/staging/lustre/lustre/obdclass/uuid.c
index b0b0157a6334..abd9b1ae72cd 100644
--- a/drivers/staging/lustre/lustre/obdclass/uuid.c
+++ b/drivers/staging/lustre/lustre/obdclass/uuid.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c
index 91ef06f17934..5b29c4a44fe5 100644
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/osc/lproc_osc.c b/drivers/staging/lustre/lustre/osc/lproc_osc.c
index 33a113213bf5..7e83d395b998 100644
--- a/drivers/staging/lustre/lustre/osc/lproc_osc.c
+++ b/drivers/staging/lustre/lustre/osc/lproc_osc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c
index 5a14bea961b4..1a6df43dfd4f 100644
--- a/drivers/staging/lustre/lustre/osc/osc_cache.c
+++ b/drivers/staging/lustre/lustre/osc/osc_cache.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -2773,7 +2769,8 @@ int osc_queue_sync_pages(const struct lu_env *env, struct osc_object *obj,
2773 ext->oe_sync = 1; 2769 ext->oe_sync = 1;
2774 ext->oe_urgent = 1; 2770 ext->oe_urgent = 1;
2775 ext->oe_start = start; 2771 ext->oe_start = start;
2776 ext->oe_end = ext->oe_max_end = end; 2772 ext->oe_end = end;
2773 ext->oe_max_end = end;
2777 ext->oe_obj = obj; 2774 ext->oe_obj = obj;
2778 ext->oe_srvlock = !!(brw_flags & OBD_BRW_SRVLOCK); 2775 ext->oe_srvlock = !!(brw_flags & OBD_BRW_SRVLOCK);
2779 ext->oe_nr_pages = page_count; 2776 ext->oe_nr_pages = page_count;
@@ -3308,7 +3305,8 @@ int osc_lock_discard_pages(const struct lu_env *env, struct osc_object *osc,
3308 goto out; 3305 goto out;
3309 3306
3310 cb = mode == CLM_READ ? check_and_discard_cb : discard_cb; 3307 cb = mode == CLM_READ ? check_and_discard_cb : discard_cb;
3311 info->oti_fn_index = info->oti_next_index = start; 3308 info->oti_fn_index = start;
3309 info->oti_next_index = start;
3312 do { 3310 do {
3313 res = osc_page_gang_lookup(env, io, osc, 3311 res = osc_page_gang_lookup(env, io, osc,
3314 info->oti_next_index, end, cb, osc); 3312 info->oti_next_index, end, cb, osc);
diff --git a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
index ae19d396b537..437c6595a6cf 100644
--- a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
+++ b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -356,11 +352,6 @@ struct osc_page {
356 */ 352 */
357 unsigned ops_transfer_pinned:1, 353 unsigned ops_transfer_pinned:1,
358 /** 354 /**
359 * True for a `temporary page' created by read-ahead code, probably
360 * outside of any DLM lock.
361 */
362 ops_temp:1,
363 /**
364 * in LRU? 355 * in LRU?
365 */ 356 */
366 ops_in_lru:1, 357 ops_in_lru:1,
diff --git a/drivers/staging/lustre/lustre/osc/osc_dev.c b/drivers/staging/lustre/lustre/osc/osc_dev.c
index d4fe507f165f..83d30c135ba4 100644
--- a/drivers/staging/lustre/lustre/osc/osc_dev.c
+++ b/drivers/staging/lustre/lustre/osc/osc_dev.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/osc/osc_internal.h b/drivers/staging/lustre/lustre/osc/osc_internal.h
index 7fad8278150f..7a27f0961955 100644
--- a/drivers/staging/lustre/lustre/osc/osc_internal.h
+++ b/drivers/staging/lustre/lustre/osc/osc_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/osc/osc_io.c b/drivers/staging/lustre/lustre/osc/osc_io.c
index d534b0e0edf6..6e3dcd38913f 100644
--- a/drivers/staging/lustre/lustre/osc/osc_io.c
+++ b/drivers/staging/lustre/lustre/osc/osc_io.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -221,7 +217,8 @@ static void osc_page_touch_at(const struct lu_env *env,
221 kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms, 217 kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
222 loi->loi_lvb.lvb_size); 218 loi->loi_lvb.lvb_size);
223 219
224 attr->cat_mtime = attr->cat_ctime = LTIME_S(CURRENT_TIME); 220 attr->cat_ctime = LTIME_S(CURRENT_TIME);
221 attr->cat_mtime = attr->cat_ctime;
225 valid = CAT_MTIME | CAT_CTIME; 222 valid = CAT_MTIME | CAT_CTIME;
226 if (kms > loi->loi_kms) { 223 if (kms > loi->loi_kms) {
227 attr->cat_kms = kms; 224 attr->cat_kms = kms;
@@ -458,7 +455,8 @@ static int osc_io_setattr_start(const struct lu_env *env,
458 unsigned int cl_valid = 0; 455 unsigned int cl_valid = 0;
459 456
460 if (ia_valid & ATTR_SIZE) { 457 if (ia_valid & ATTR_SIZE) {
461 attr->cat_size = attr->cat_kms = size; 458 attr->cat_size = size;
459 attr->cat_kms = size;
462 cl_valid = CAT_SIZE | CAT_KMS; 460 cl_valid = CAT_SIZE | CAT_KMS;
463 } 461 }
464 if (ia_valid & ATTR_MTIME_SET) { 462 if (ia_valid & ATTR_MTIME_SET) {
@@ -526,7 +524,8 @@ static void osc_io_setattr_end(const struct lu_env *env,
526 524
527 if (cbargs->opc_rpc_sent) { 525 if (cbargs->opc_rpc_sent) {
528 wait_for_completion(&cbargs->opc_sync); 526 wait_for_completion(&cbargs->opc_sync);
529 result = io->ci_result = cbargs->opc_rc; 527 result = cbargs->opc_rc;
528 io->ci_result = cbargs->opc_rc;
530 } 529 }
531 if (result == 0) { 530 if (result == 0) {
532 if (oio->oi_lockless) { 531 if (oio->oi_lockless) {
@@ -575,7 +574,8 @@ static int osc_io_write_start(const struct lu_env *env,
575 574
576 OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_DELAY_SETTIME, 1); 575 OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_DELAY_SETTIME, 1);
577 cl_object_attr_lock(obj); 576 cl_object_attr_lock(obj);
578 attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds(); 577 attr->cat_ctime = ktime_get_real_seconds();
578 attr->cat_mtime = attr->cat_ctime;
579 rc = cl_object_attr_set(env, obj, attr, CAT_MTIME | CAT_CTIME); 579 rc = cl_object_attr_set(env, obj, attr, CAT_MTIME | CAT_CTIME);
580 cl_object_attr_unlock(obj); 580 cl_object_attr_unlock(obj);
581 581
diff --git a/drivers/staging/lustre/lustre/osc/osc_lock.c b/drivers/staging/lustre/lustre/osc/osc_lock.c
index 16f9cd9d3b12..42def38d998b 100644
--- a/drivers/staging/lustre/lustre/osc/osc_lock.c
+++ b/drivers/staging/lustre/lustre/osc/osc_lock.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1120,7 +1116,8 @@ static void osc_lock_set_writer(const struct lu_env *env,
1120 } 1116 }
1121 } else { 1117 } else {
1122 LASSERT(cl_io_is_mkwrite(io)); 1118 LASSERT(cl_io_is_mkwrite(io));
1123 io_start = io_end = io->u.ci_fault.ft_index; 1119 io_start = io->u.ci_fault.ft_index;
1120 io_end = io->u.ci_fault.ft_index;
1124 } 1121 }
1125 1122
1126 if (descr->cld_mode >= CLM_WRITE && 1123 if (descr->cld_mode >= CLM_WRITE &&
diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c
index 738ab10ab274..d211d1905e83 100644
--- a/drivers/staging/lustre/lustre/osc/osc_object.c
+++ b/drivers/staging/lustre/lustre/osc/osc_object.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c
index c29c2eabe39c..57d8a5aa8bfb 100644
--- a/drivers/staging/lustre/lustre/osc/osc_page.c
+++ b/drivers/staging/lustre/lustre/osc/osc_page.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -52,13 +48,6 @@ static int osc_lru_reserve(const struct lu_env *env, struct osc_object *obj,
52 * @{ 48 * @{
53 */ 49 */
54 50
55static int osc_page_protected(const struct lu_env *env,
56 const struct osc_page *opg,
57 enum cl_lock_mode mode, int unref)
58{
59 return 1;
60}
61
62/***************************************************************************** 51/*****************************************************************************
63 * 52 *
64 * Page operations. 53 * Page operations.
@@ -110,8 +99,6 @@ int osc_page_cache_add(const struct lu_env *env,
110 struct osc_page *opg = cl2osc_page(slice); 99 struct osc_page *opg = cl2osc_page(slice);
111 int result; 100 int result;
112 101
113 LINVRNT(osc_page_protected(env, opg, CLM_WRITE, 0));
114
115 osc_page_transfer_get(opg, "transfer\0cache"); 102 osc_page_transfer_get(opg, "transfer\0cache");
116 result = osc_queue_async_io(env, io, opg); 103 result = osc_queue_async_io(env, io, opg);
117 if (result != 0) 104 if (result != 0)
@@ -214,8 +201,6 @@ static void osc_page_delete(const struct lu_env *env,
214 struct osc_object *obj = cl2osc(opg->ops_cl.cpl_obj); 201 struct osc_object *obj = cl2osc(opg->ops_cl.cpl_obj);
215 int rc; 202 int rc;
216 203
217 LINVRNT(opg->ops_temp || osc_page_protected(env, opg, CLM_READ, 1));
218
219 CDEBUG(D_TRACE, "%p\n", opg); 204 CDEBUG(D_TRACE, "%p\n", opg);
220 osc_page_transfer_put(env, opg); 205 osc_page_transfer_put(env, opg);
221 rc = osc_teardown_async_page(env, obj, opg); 206 rc = osc_teardown_async_page(env, obj, opg);
@@ -254,8 +239,6 @@ static void osc_page_clip(const struct lu_env *env,
254 struct osc_page *opg = cl2osc_page(slice); 239 struct osc_page *opg = cl2osc_page(slice);
255 struct osc_async_page *oap = &opg->ops_oap; 240 struct osc_async_page *oap = &opg->ops_oap;
256 241
257 LINVRNT(osc_page_protected(env, opg, CLM_READ, 0));
258
259 opg->ops_from = from; 242 opg->ops_from = from;
260 opg->ops_to = to; 243 opg->ops_to = to;
261 spin_lock(&oap->oap_lock); 244 spin_lock(&oap->oap_lock);
@@ -269,8 +252,6 @@ static int osc_page_cancel(const struct lu_env *env,
269 struct osc_page *opg = cl2osc_page(slice); 252 struct osc_page *opg = cl2osc_page(slice);
270 int rc = 0; 253 int rc = 0;
271 254
272 LINVRNT(osc_page_protected(env, opg, CLM_READ, 0));
273
274 /* Check if the transferring against this page 255 /* Check if the transferring against this page
275 * is completed, or not even queued. 256 * is completed, or not even queued.
276 */ 257 */
@@ -320,10 +301,6 @@ int osc_page_init(const struct lu_env *env, struct cl_object *obj,
320 cl_page_slice_add(page, &opg->ops_cl, obj, index, 301 cl_page_slice_add(page, &opg->ops_cl, obj, index,
321 &osc_page_ops); 302 &osc_page_ops);
322 } 303 }
323 /*
324 * Cannot assert osc_page_protected() here as read-ahead
325 * creates temporary pages outside of a lock.
326 */
327 /* ops_inflight and ops_lru are the same field, but it doesn't 304 /* ops_inflight and ops_lru are the same field, but it doesn't
328 * hurt to initialize it twice :-) 305 * hurt to initialize it twice :-)
329 */ 306 */
@@ -382,9 +359,6 @@ void osc_page_submit(const struct lu_env *env, struct osc_page *opg,
382 struct osc_async_page *oap = &opg->ops_oap; 359 struct osc_async_page *oap = &opg->ops_oap;
383 struct osc_object *obj = oap->oap_obj; 360 struct osc_object *obj = oap->oap_obj;
384 361
385 LINVRNT(osc_page_protected(env, opg,
386 crt == CRT_WRITE ? CLM_WRITE : CLM_READ, 1));
387
388 LASSERTF(oap->oap_magic == OAP_MAGIC, "Bad oap magic: oap %p, magic 0x%x\n", 362 LASSERTF(oap->oap_magic == OAP_MAGIC, "Bad oap magic: oap %p, magic 0x%x\n",
389 oap, oap->oap_magic); 363 oap, oap->oap_magic);
390 LASSERT(oap->oap_async_flags & ASYNC_READY); 364 LASSERT(oap->oap_async_flags & ASYNC_READY);
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 47417f88fe3c..7260027bb595 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -474,7 +470,8 @@ static int osc_real_create(struct obd_export *exp, struct obdo *oa,
474 DEBUG_REQ(D_HA, req, 470 DEBUG_REQ(D_HA, req,
475 "delorphan from OST integration"); 471 "delorphan from OST integration");
476 /* Don't resend the delorphan req */ 472 /* Don't resend the delorphan req */
477 req->rq_no_resend = req->rq_no_delay = 1; 473 req->rq_no_resend = 1;
474 req->rq_no_delay = 1;
478 } 475 }
479 476
480 rc = ptlrpc_queue_wait(req); 477 rc = ptlrpc_queue_wait(req);
@@ -2775,7 +2772,8 @@ static int osc_get_info(const struct lu_env *env, struct obd_export *exp,
2775 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY); 2772 tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
2776 memcpy(tmp, key, keylen); 2773 memcpy(tmp, key, keylen);
2777 2774
2778 req->rq_no_delay = req->rq_no_resend = 1; 2775 req->rq_no_delay = 1;
2776 req->rq_no_resend = 1;
2779 ptlrpc_request_set_replen(req); 2777 ptlrpc_request_set_replen(req);
2780 rc = ptlrpc_queue_wait(req); 2778 rc = ptlrpc_queue_wait(req);
2781 if (rc) 2779 if (rc)
diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index 4b7912a2cb52..22bf8930433b 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -3024,8 +3020,10 @@ void *ptlrpcd_alloc_work(struct obd_import *imp,
3024 req->rq_interpret_reply = work_interpreter; 3020 req->rq_interpret_reply = work_interpreter;
3025 /* don't want reply */ 3021 /* don't want reply */
3026 req->rq_receiving_reply = 0; 3022 req->rq_receiving_reply = 0;
3027 req->rq_req_unlink = req->rq_reply_unlink = 0; 3023 req->rq_req_unlink = 0;
3028 req->rq_no_delay = req->rq_no_resend = 1; 3024 req->rq_reply_unlink = 0;
3025 req->rq_no_delay = 1;
3026 req->rq_no_resend = 1;
3029 req->rq_pill.rc_fmt = (void *)&worker_format; 3027 req->rq_pill.rc_fmt = (void *)&worker_format;
3030 3028
3031 spin_lock_init(&req->rq_lock); 3029 spin_lock_init(&req->rq_lock);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/connection.c b/drivers/staging/lustre/lustre/ptlrpc/connection.c
index a14daff3fca0..177a379da9fa 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/connection.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/connection.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
index fdcde9bbd788..b8ca7d60867a 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/events.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c
index a4f7544f46b8..914bbd2956fb 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/import.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/import.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -698,7 +694,8 @@ int ptlrpc_connect_import(struct obd_import *imp)
698 694
699 lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER); 695 lustre_msg_add_op_flags(request->rq_reqmsg, MSG_CONNECT_NEXT_VER);
700 696
701 request->rq_no_resend = request->rq_no_delay = 1; 697 request->rq_no_resend = 1;
698 request->rq_no_delay = 1;
702 request->rq_send_state = LUSTRE_IMP_CONNECTING; 699 request->rq_send_state = LUSTRE_IMP_CONNECTING;
703 /* Allow a slightly larger reply for future growth compatibility */ 700 /* Allow a slightly larger reply for future growth compatibility */
704 req_capsule_set_size(&request->rq_pill, &RMF_CONNECT_DATA, RCL_SERVER, 701 req_capsule_set_size(&request->rq_pill, &RMF_CONNECT_DATA, RCL_SERVER,
diff --git a/drivers/staging/lustre/lustre/ptlrpc/layout.c b/drivers/staging/lustre/lustre/ptlrpc/layout.c
index c0ecd1625dc4..e6ff97daefa4 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/layout.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/layout.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
index a23ac5f9ae96..0f55c01feba8 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/llog_net.c b/drivers/staging/lustre/lustre/ptlrpc/llog_net.c
index fbccb62213b5..bccdace7e51f 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/llog_net.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/llog_net.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
index 64c0f1e17f36..bc93b75744e1 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -872,7 +868,8 @@ ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
872 868
873 if (i > srhi->srhi_idx) { /* reset iterator for a new CPT */ 869 if (i > srhi->srhi_idx) { /* reset iterator for a new CPT */
874 srhi->srhi_req = NULL; 870 srhi->srhi_req = NULL;
875 seq = srhi->srhi_seq = 0; 871 seq = 0;
872 srhi->srhi_seq = 0;
876 } else { /* the next sequence */ 873 } else { /* the next sequence */
877 seq = srhi->srhi_seq + (1 << svc->srv_cpt_bits); 874 seq = srhi->srhi_seq + (1 << svc->srv_cpt_bits);
878 } 875 }
@@ -1161,7 +1158,6 @@ void ptlrpc_lprocfs_brw(struct ptlrpc_request *req, int bytes)
1161 1158
1162 lprocfs_counter_add(svc_stats, idx, bytes); 1159 lprocfs_counter_add(svc_stats, idx, bytes);
1163} 1160}
1164
1165EXPORT_SYMBOL(ptlrpc_lprocfs_brw); 1161EXPORT_SYMBOL(ptlrpc_lprocfs_brw);
1166 1162
1167void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc) 1163void ptlrpc_lprocfs_unregister_service(struct ptlrpc_service *svc)
diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
index 10b8fe82a342..ff9a95cb1832 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/nrs.c b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
index c444f516856f..d88faf61e740 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
@@ -769,7 +769,7 @@ static int nrs_policy_register(struct ptlrpc_nrs *nrs,
769 spin_unlock(&nrs->nrs_lock); 769 spin_unlock(&nrs->nrs_lock);
770 770
771 if (rc != 0) 771 if (rc != 0)
772 (void) nrs_policy_unregister(nrs, policy->pol_desc->pd_name); 772 (void)nrs_policy_unregister(nrs, policy->pol_desc->pd_name);
773 773
774 return rc; 774 return rc;
775} 775}
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
index 811acf6fc786..9ff58a1cad42 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pers.c b/drivers/staging/lustre/lustre/ptlrpc/pers.c
index ec3af109a1d7..6c820e944171 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pers.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pers.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
index 8a869315c258..c0529d808d81 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -57,7 +53,8 @@ ptlrpc_prep_ping(struct obd_import *imp)
57 LUSTRE_OBD_VERSION, OBD_PING); 53 LUSTRE_OBD_VERSION, OBD_PING);
58 if (req) { 54 if (req) {
59 ptlrpc_request_set_replen(req); 55 ptlrpc_request_set_replen(req);
60 req->rq_no_resend = req->rq_no_delay = 1; 56 req->rq_no_resend = 1;
57 req->rq_no_delay = 1;
61 } 58 }
62 return req; 59 return req;
63} 60}
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
index 6ca26c98de1b..97e97e22b866 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_internal.h
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
index a8ec0e9d7b2e..a70d5843f30e 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpc_module.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
index 76a355a9db8b..b0cf5859b1f1 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c
index 30d9a164e52d..718b3a8d61c6 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/recover.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec.c b/drivers/staging/lustre/lustre/ptlrpc/sec.c
index 187fd1d6898c..f3b477305df6 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -1104,7 +1100,7 @@ int sptlrpc_cli_unwrap_early_reply(struct ptlrpc_request *req,
1104 early_req->rq_flvr = req->rq_flvr; 1100 early_req->rq_flvr = req->rq_flvr;
1105 early_req->rq_repbuf = early_buf; 1101 early_req->rq_repbuf = early_buf;
1106 early_req->rq_repbuf_len = early_bufsz; 1102 early_req->rq_repbuf_len = early_bufsz;
1107 early_req->rq_repdata = (struct lustre_msg *) early_buf; 1103 early_req->rq_repdata = (struct lustre_msg *)early_buf;
1108 early_req->rq_repdata_len = early_size; 1104 early_req->rq_repdata_len = early_size;
1109 early_req->rq_early = 1; 1105 early_req->rq_early = 1;
1110 early_req->rq_reqmsg = req->rq_reqmsg; 1106 early_req->rq_reqmsg = req->rq_reqmsg;
@@ -1556,7 +1552,7 @@ void _sptlrpc_enlarge_msg_inplace(struct lustre_msg *msg,
1556 /* move from segment + 1 to end segment */ 1552 /* move from segment + 1 to end segment */
1557 LASSERT(msg->lm_magic == LUSTRE_MSG_MAGIC_V2); 1553 LASSERT(msg->lm_magic == LUSTRE_MSG_MAGIC_V2);
1558 oldmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens); 1554 oldmsg_size = lustre_msg_size_v2(msg->lm_bufcount, msg->lm_buflens);
1559 movesize = oldmsg_size - ((unsigned long) src - (unsigned long) msg); 1555 movesize = oldmsg_size - ((unsigned long)src - (unsigned long)msg);
1560 LASSERT(movesize >= 0); 1556 LASSERT(movesize >= 0);
1561 1557
1562 if (movesize) 1558 if (movesize)
@@ -2196,6 +2192,9 @@ int sptlrpc_pack_user_desc(struct lustre_msg *msg, int offset)
2196 2192
2197 pud = lustre_msg_buf(msg, offset, 0); 2193 pud = lustre_msg_buf(msg, offset, 0);
2198 2194
2195 if (!pud)
2196 return -EINVAL;
2197
2199 pud->pud_uid = from_kuid(&init_user_ns, current_uid()); 2198 pud->pud_uid = from_kuid(&init_user_ns, current_uid());
2200 pud->pud_gid = from_kgid(&init_user_ns, current_gid()); 2199 pud->pud_gid = from_kgid(&init_user_ns, current_gid());
2201 pud->pud_fsuid = from_kuid(&init_user_ns, current_fsuid()); 2200 pud->pud_fsuid = from_kuid(&init_user_ns, current_fsuid());
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
index 02e6cda4c995..5f4d79718589 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -273,7 +269,7 @@ static unsigned long enc_pools_shrink_scan(struct shrinker *s,
273static inline 269static inline
274int npages_to_npools(unsigned long npages) 270int npages_to_npools(unsigned long npages)
275{ 271{
276 return (int) ((npages + PAGES_PER_POOL - 1) / PAGES_PER_POOL); 272 return (int)((npages + PAGES_PER_POOL - 1) / PAGES_PER_POOL);
277} 273}
278 274
279/* 275/*
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
index a51b18bbfd34..1238c873bfdf 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_config.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -648,7 +644,7 @@ static int logname2fsname(const char *logname, char *buf, int buflen)
648 return -EINVAL; 644 return -EINVAL;
649 } 645 }
650 646
651 len = min((int) (ptr - logname), buflen - 1); 647 len = min((int)(ptr - logname), buflen - 1);
652 648
653 memcpy(buf, logname, len); 649 memcpy(buf, logname, len);
654 buf[len] = '\0'; 650 buf[len] = '\0';
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c
index 9082da06b28a..9b9801ece582 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_gc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_lproc.c b/drivers/staging/lustre/lustre/ptlrpc/sec_lproc.c
index e610a8ddd223..07273f577969 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_lproc.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_lproc.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_null.c b/drivers/staging/lustre/lustre/ptlrpc/sec_null.c
index 40e5349de38c..70a61e12bb7b 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_null.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_null.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -60,7 +56,7 @@ static struct ptlrpc_svc_ctx null_svc_ctx;
60static inline 56static inline
61void null_encode_sec_part(struct lustre_msg *msg, enum lustre_sec_part sp) 57void null_encode_sec_part(struct lustre_msg *msg, enum lustre_sec_part sp)
62{ 58{
63 msg->lm_secflvr |= (((__u32) sp) & 0xFF) << 24; 59 msg->lm_secflvr |= (((__u32)sp) & 0xFF) << 24;
64} 60}
65 61
66static inline 62static inline
@@ -265,7 +261,8 @@ int null_enlarge_reqbuf(struct ptlrpc_sec *sec,
265 memcpy(newbuf, req->rq_reqbuf, req->rq_reqlen); 261 memcpy(newbuf, req->rq_reqbuf, req->rq_reqlen);
266 262
267 kvfree(req->rq_reqbuf); 263 kvfree(req->rq_reqbuf);
268 req->rq_reqbuf = req->rq_reqmsg = newbuf; 264 req->rq_reqbuf = newbuf;
265 req->rq_reqmsg = newbuf;
269 req->rq_reqbuf_len = alloc_size; 266 req->rq_reqbuf_len = alloc_size;
270 267
271 if (req->rq_import) 268 if (req->rq_import)
@@ -329,7 +326,7 @@ int null_alloc_rs(struct ptlrpc_request *req, int msgsize)
329 rs->rs_svc_ctx = req->rq_svc_ctx; 326 rs->rs_svc_ctx = req->rq_svc_ctx;
330 atomic_inc(&req->rq_svc_ctx->sc_refcount); 327 atomic_inc(&req->rq_svc_ctx->sc_refcount);
331 328
332 rs->rs_repbuf = (struct lustre_msg *) (rs + 1); 329 rs->rs_repbuf = (struct lustre_msg *)(rs + 1);
333 rs->rs_repbuf_len = rs_size - sizeof(*rs); 330 rs->rs_repbuf_len = rs_size - sizeof(*rs);
334 rs->rs_msg = rs->rs_repbuf; 331 rs->rs_msg = rs->rs_repbuf;
335 332
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
index 37c9f4c453de..5c4590b0c521 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
@@ -298,7 +294,7 @@ int plain_cli_wrap_bulk(struct ptlrpc_cli_ctx *ctx,
298 LASSERT(req->rq_reqbuf->lm_bufcount == PLAIN_PACK_SEGMENTS); 294 LASSERT(req->rq_reqbuf->lm_bufcount == PLAIN_PACK_SEGMENTS);
299 295
300 bsd = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0); 296 bsd = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0);
301 token = (struct plain_bulk_token *) bsd->bsd_data; 297 token = (struct plain_bulk_token *)bsd->bsd_data;
302 298
303 bsd->bsd_version = 0; 299 bsd->bsd_version = 0;
304 bsd->bsd_flags = 0; 300 bsd->bsd_flags = 0;
@@ -343,7 +339,7 @@ int plain_cli_unwrap_bulk(struct ptlrpc_cli_ctx *ctx,
343 LASSERT(req->rq_repdata->lm_bufcount == PLAIN_PACK_SEGMENTS); 339 LASSERT(req->rq_repdata->lm_bufcount == PLAIN_PACK_SEGMENTS);
344 340
345 bsdv = lustre_msg_buf(req->rq_repdata, PLAIN_PACK_BULK_OFF, 0); 341 bsdv = lustre_msg_buf(req->rq_repdata, PLAIN_PACK_BULK_OFF, 0);
346 tokenv = (struct plain_bulk_token *) bsdv->bsd_data; 342 tokenv = (struct plain_bulk_token *)bsdv->bsd_data;
347 343
348 if (req->rq_bulk_write) { 344 if (req->rq_bulk_write) {
349 if (bsdv->bsd_flags & BSD_FL_ERR) 345 if (bsdv->bsd_flags & BSD_FL_ERR)
@@ -574,8 +570,12 @@ int plain_alloc_reqbuf(struct ptlrpc_sec *sec,
574 lustre_init_msg_v2(req->rq_reqbuf, PLAIN_PACK_SEGMENTS, buflens, NULL); 570 lustre_init_msg_v2(req->rq_reqbuf, PLAIN_PACK_SEGMENTS, buflens, NULL);
575 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_MSG_OFF, 0); 571 req->rq_reqmsg = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_MSG_OFF, 0);
576 572
577 if (req->rq_pack_udesc) 573 if (req->rq_pack_udesc) {
578 sptlrpc_pack_user_desc(req->rq_reqbuf, PLAIN_PACK_USER_OFF); 574 int rc = sptlrpc_pack_user_desc(req->rq_reqbuf,
575 PLAIN_PACK_USER_OFF);
576 if (rc < 0)
577 return rc;
578 }
579 579
580 return 0; 580 return 0;
581} 581}
@@ -811,7 +811,7 @@ int plain_alloc_rs(struct ptlrpc_request *req, int msgsize)
811 811
812 rs->rs_svc_ctx = req->rq_svc_ctx; 812 rs->rs_svc_ctx = req->rq_svc_ctx;
813 atomic_inc(&req->rq_svc_ctx->sc_refcount); 813 atomic_inc(&req->rq_svc_ctx->sc_refcount);
814 rs->rs_repbuf = (struct lustre_msg *) (rs + 1); 814 rs->rs_repbuf = (struct lustre_msg *)(rs + 1);
815 rs->rs_repbuf_len = rs_size - sizeof(*rs); 815 rs->rs_repbuf_len = rs_size - sizeof(*rs);
816 816
817 lustre_init_msg_v2(rs->rs_repbuf, PLAIN_PACK_SEGMENTS, buflens, NULL); 817 lustre_init_msg_v2(rs->rs_repbuf, PLAIN_PACK_SEGMENTS, buflens, NULL);
@@ -891,7 +891,7 @@ int plain_svc_unwrap_bulk(struct ptlrpc_request *req,
891 LASSERT(req->rq_pack_bulk); 891 LASSERT(req->rq_pack_bulk);
892 892
893 bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0); 893 bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0);
894 tokenr = (struct plain_bulk_token *) bsdr->bsd_data; 894 tokenr = (struct plain_bulk_token *)bsdr->bsd_data;
895 bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0); 895 bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0);
896 896
897 bsdv->bsd_version = 0; 897 bsdv->bsd_version = 0;
@@ -926,7 +926,7 @@ int plain_svc_wrap_bulk(struct ptlrpc_request *req,
926 926
927 bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0); 927 bsdr = lustre_msg_buf(req->rq_reqbuf, PLAIN_PACK_BULK_OFF, 0);
928 bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0); 928 bsdv = lustre_msg_buf(rs->rs_repbuf, PLAIN_PACK_BULK_OFF, 0);
929 tokenv = (struct plain_bulk_token *) bsdv->bsd_data; 929 tokenv = (struct plain_bulk_token *)bsdv->bsd_data;
930 930
931 bsdv->bsd_version = 0; 931 bsdv->bsd_version = 0;
932 bsdv->bsd_type = SPTLRPC_BULK_DEFAULT; 932 bsdv->bsd_type = SPTLRPC_BULK_DEFAULT;
diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
index 17c7b9749f67..4788c4940c2a 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/wiretest.c b/drivers/staging/lustre/lustre/ptlrpc/wiretest.c
index aacc8108391d..9fd9de958fe2 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/wiretest.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/wiretest.c
@@ -15,11 +15,7 @@
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see 17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf 18 * http://www.gnu.org/licenses/gpl-2.0.html
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 * 19 *
24 * GPL HEADER END 20 * GPL HEADER END
25 */ 21 */
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index 68931e5ecd8f..09e9499b7f9d 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -1799,8 +1799,8 @@ struct ieee80211_device {
1799 short scanning; 1799 short scanning;
1800 short proto_started; 1800 short proto_started;
1801 1801
1802 struct semaphore wx_sem; 1802 struct mutex wx_mutex;
1803 struct semaphore scan_sem; 1803 struct mutex scan_mutex;
1804 1804
1805 spinlock_t mgmt_tx_lock; 1805 spinlock_t mgmt_tx_lock;
1806 spinlock_t beacon_lock; 1806 spinlock_t beacon_lock;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index d705595766a9..49db1b75cd05 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -427,7 +427,7 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
427 short ch = 0; 427 short ch = 0;
428 u8 channel_map[MAX_CHANNEL_NUMBER+1]; 428 u8 channel_map[MAX_CHANNEL_NUMBER+1];
429 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 429 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
430 down(&ieee->scan_sem); 430 mutex_lock(&ieee->scan_mutex);
431 431
432 while(1) 432 while(1)
433 { 433 {
@@ -475,13 +475,13 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee)
475out: 475out:
476 if(ieee->state < IEEE80211_LINKED){ 476 if(ieee->state < IEEE80211_LINKED){
477 ieee->actscanning = false; 477 ieee->actscanning = false;
478 up(&ieee->scan_sem); 478 mutex_unlock(&ieee->scan_mutex);
479 } 479 }
480 else{ 480 else{
481 ieee->sync_scan_hurryup = 0; 481 ieee->sync_scan_hurryup = 0;
482 if(IS_DOT11D_ENABLE(ieee)) 482 if(IS_DOT11D_ENABLE(ieee))
483 DOT11D_ScanComplete(ieee); 483 DOT11D_ScanComplete(ieee);
484 up(&ieee->scan_sem); 484 mutex_unlock(&ieee->scan_mutex);
485} 485}
486} 486}
487EXPORT_SYMBOL(ieee80211_softmac_scan_syncro); 487EXPORT_SYMBOL(ieee80211_softmac_scan_syncro);
@@ -495,7 +495,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct *work)
495 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1); 495 memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, MAX_CHANNEL_NUMBER+1);
496 if(!ieee->ieee_up) 496 if(!ieee->ieee_up)
497 return; 497 return;
498 down(&ieee->scan_sem); 498 mutex_lock(&ieee->scan_mutex);
499 do{ 499 do{
500 ieee->current_network.channel = 500 ieee->current_network.channel =
501 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER; 501 (ieee->current_network.channel + 1) % MAX_CHANNEL_NUMBER;
@@ -517,7 +517,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct *work)
517 517
518 schedule_delayed_work(&ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME); 518 schedule_delayed_work(&ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
519 519
520 up(&ieee->scan_sem); 520 mutex_unlock(&ieee->scan_mutex);
521 return; 521 return;
522out: 522out:
523 if(IS_DOT11D_ENABLE(ieee)) 523 if(IS_DOT11D_ENABLE(ieee))
@@ -525,7 +525,7 @@ out:
525 ieee->actscanning = false; 525 ieee->actscanning = false;
526 watchdog = 0; 526 watchdog = 0;
527 ieee->scanning = 0; 527 ieee->scanning = 0;
528 up(&ieee->scan_sem); 528 mutex_unlock(&ieee->scan_mutex);
529} 529}
530 530
531 531
@@ -579,7 +579,7 @@ static void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
579 579
580 //ieee->sync_scan_hurryup = 1; 580 //ieee->sync_scan_hurryup = 1;
581 581
582 down(&ieee->scan_sem); 582 mutex_lock(&ieee->scan_mutex);
583// spin_lock_irqsave(&ieee->lock, flags); 583// spin_lock_irqsave(&ieee->lock, flags);
584 584
585 if (ieee->scanning == 1) { 585 if (ieee->scanning == 1) {
@@ -589,7 +589,7 @@ static void ieee80211_softmac_stop_scan(struct ieee80211_device *ieee)
589 } 589 }
590 590
591// spin_unlock_irqrestore(&ieee->lock, flags); 591// spin_unlock_irqrestore(&ieee->lock, flags);
592 up(&ieee->scan_sem); 592 mutex_unlock(&ieee->scan_mutex);
593} 593}
594 594
595void ieee80211_stop_scan(struct ieee80211_device *ieee) 595void ieee80211_stop_scan(struct ieee80211_device *ieee)
@@ -621,7 +621,7 @@ static void ieee80211_start_scan(struct ieee80211_device *ieee)
621 621
622} 622}
623 623
624/* called with wx_sem held */ 624/* called with wx_mutex held */
625void ieee80211_start_scan_syncro(struct ieee80211_device *ieee) 625void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
626{ 626{
627 if (IS_DOT11D_ENABLE(ieee) ) 627 if (IS_DOT11D_ENABLE(ieee) )
@@ -1389,7 +1389,7 @@ static void ieee80211_associate_procedure_wq(struct work_struct *work)
1389{ 1389{
1390 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq); 1390 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, associate_procedure_wq);
1391 ieee->sync_scan_hurryup = 1; 1391 ieee->sync_scan_hurryup = 1;
1392 down(&ieee->wx_sem); 1392 mutex_lock(&ieee->wx_mutex);
1393 1393
1394 if (ieee->data_hard_stop) 1394 if (ieee->data_hard_stop)
1395 ieee->data_hard_stop(ieee->dev); 1395 ieee->data_hard_stop(ieee->dev);
@@ -1402,7 +1402,7 @@ static void ieee80211_associate_procedure_wq(struct work_struct *work)
1402 ieee->associate_seq = 1; 1402 ieee->associate_seq = 1;
1403 ieee80211_associate_step1(ieee); 1403 ieee80211_associate_step1(ieee);
1404 1404
1405 up(&ieee->wx_sem); 1405 mutex_unlock(&ieee->wx_mutex);
1406} 1406}
1407 1407
1408inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net) 1408inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net)
@@ -2331,7 +2331,7 @@ static void ieee80211_start_ibss_wq(struct work_struct *work)
2331 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq); 2331 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, start_ibss_wq);
2332 /* iwconfig mode ad-hoc will schedule this and return 2332 /* iwconfig mode ad-hoc will schedule this and return
2333 * on the other hand this will block further iwconfig SET 2333 * on the other hand this will block further iwconfig SET
2334 * operations because of the wx_sem hold. 2334 * operations because of the wx_mutex hold.
2335 * Anyway some most set operations set a flag to speed-up 2335 * Anyway some most set operations set a flag to speed-up
2336 * (abort) this wq (when syncro scanning) before sleeping 2336 * (abort) this wq (when syncro scanning) before sleeping
2337 * on the semaphore 2337 * on the semaphore
@@ -2340,7 +2340,7 @@ static void ieee80211_start_ibss_wq(struct work_struct *work)
2340 printk("==========oh driver down return\n"); 2340 printk("==========oh driver down return\n");
2341 return; 2341 return;
2342 } 2342 }
2343 down(&ieee->wx_sem); 2343 mutex_lock(&ieee->wx_mutex);
2344 2344
2345 if (ieee->current_network.ssid_len == 0) { 2345 if (ieee->current_network.ssid_len == 0) {
2346 strcpy(ieee->current_network.ssid, IEEE80211_DEFAULT_TX_ESSID); 2346 strcpy(ieee->current_network.ssid, IEEE80211_DEFAULT_TX_ESSID);
@@ -2431,7 +2431,7 @@ static void ieee80211_start_ibss_wq(struct work_struct *work)
2431 ieee->data_hard_resume(ieee->dev); 2431 ieee->data_hard_resume(ieee->dev);
2432 netif_carrier_on(ieee->dev); 2432 netif_carrier_on(ieee->dev);
2433 2433
2434 up(&ieee->wx_sem); 2434 mutex_unlock(&ieee->wx_mutex);
2435} 2435}
2436 2436
2437inline void ieee80211_start_ibss(struct ieee80211_device *ieee) 2437inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
@@ -2439,7 +2439,7 @@ inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
2439 schedule_delayed_work(&ieee->start_ibss_wq, 150); 2439 schedule_delayed_work(&ieee->start_ibss_wq, 150);
2440} 2440}
2441 2441
2442/* this is called only in user context, with wx_sem held */ 2442/* this is called only in user context, with wx_mutex held */
2443void ieee80211_start_bss(struct ieee80211_device *ieee) 2443void ieee80211_start_bss(struct ieee80211_device *ieee)
2444{ 2444{
2445 unsigned long flags; 2445 unsigned long flags;
@@ -2505,7 +2505,7 @@ static void ieee80211_associate_retry_wq(struct work_struct *work)
2505 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq); 2505 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, associate_retry_wq);
2506 unsigned long flags; 2506 unsigned long flags;
2507 2507
2508 down(&ieee->wx_sem); 2508 mutex_lock(&ieee->wx_mutex);
2509 if(!ieee->proto_started) 2509 if(!ieee->proto_started)
2510 goto exit; 2510 goto exit;
2511 2511
@@ -2537,7 +2537,7 @@ static void ieee80211_associate_retry_wq(struct work_struct *work)
2537 spin_unlock_irqrestore(&ieee->lock, flags); 2537 spin_unlock_irqrestore(&ieee->lock, flags);
2538 2538
2539exit: 2539exit:
2540 up(&ieee->wx_sem); 2540 mutex_unlock(&ieee->wx_mutex);
2541} 2541}
2542 2542
2543struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee) 2543struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
@@ -2583,9 +2583,9 @@ EXPORT_SYMBOL(ieee80211_get_beacon);
2583void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee) 2583void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
2584{ 2584{
2585 ieee->sync_scan_hurryup = 1; 2585 ieee->sync_scan_hurryup = 1;
2586 down(&ieee->wx_sem); 2586 mutex_lock(&ieee->wx_mutex);
2587 ieee80211_stop_protocol(ieee); 2587 ieee80211_stop_protocol(ieee);
2588 up(&ieee->wx_sem); 2588 mutex_unlock(&ieee->wx_mutex);
2589} 2589}
2590EXPORT_SYMBOL(ieee80211_softmac_stop_protocol); 2590EXPORT_SYMBOL(ieee80211_softmac_stop_protocol);
2591 2591
@@ -2609,9 +2609,9 @@ void ieee80211_stop_protocol(struct ieee80211_device *ieee)
2609void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee) 2609void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee)
2610{ 2610{
2611 ieee->sync_scan_hurryup = 0; 2611 ieee->sync_scan_hurryup = 0;
2612 down(&ieee->wx_sem); 2612 mutex_lock(&ieee->wx_mutex);
2613 ieee80211_start_protocol(ieee); 2613 ieee80211_start_protocol(ieee);
2614 up(&ieee->wx_sem); 2614 mutex_unlock(&ieee->wx_mutex);
2615} 2615}
2616EXPORT_SYMBOL(ieee80211_softmac_start_protocol); 2616EXPORT_SYMBOL(ieee80211_softmac_start_protocol);
2617 2617
@@ -2728,8 +2728,8 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
2728 INIT_WORK(&ieee->wx_sync_scan_wq, ieee80211_wx_sync_scan_wq); 2728 INIT_WORK(&ieee->wx_sync_scan_wq, ieee80211_wx_sync_scan_wq);
2729 2729
2730 2730
2731 sema_init(&ieee->wx_sem, 1); 2731 mutex_init(&ieee->wx_mutex);
2732 sema_init(&ieee->scan_sem, 1); 2732 mutex_init(&ieee->scan_mutex);
2733 2733
2734 spin_lock_init(&ieee->mgmt_tx_lock); 2734 spin_lock_init(&ieee->mgmt_tx_lock);
2735 spin_lock_init(&ieee->beacon_lock); 2735 spin_lock_init(&ieee->beacon_lock);
@@ -2742,14 +2742,14 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
2742 2742
2743void ieee80211_softmac_free(struct ieee80211_device *ieee) 2743void ieee80211_softmac_free(struct ieee80211_device *ieee)
2744{ 2744{
2745 down(&ieee->wx_sem); 2745 mutex_lock(&ieee->wx_mutex);
2746 kfree(ieee->pDot11dInfo); 2746 kfree(ieee->pDot11dInfo);
2747 ieee->pDot11dInfo = NULL; 2747 ieee->pDot11dInfo = NULL;
2748 del_timer_sync(&ieee->associate_timer); 2748 del_timer_sync(&ieee->associate_timer);
2749 2749
2750 cancel_delayed_work(&ieee->associate_retry_wq); 2750 cancel_delayed_work(&ieee->associate_retry_wq);
2751 2751
2752 up(&ieee->wx_sem); 2752 mutex_unlock(&ieee->wx_mutex);
2753} 2753}
2754 2754
2755/******************************************************** 2755/********************************************************
@@ -3138,7 +3138,7 @@ int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_poin
3138 struct ieee_param *param; 3138 struct ieee_param *param;
3139 int ret=0; 3139 int ret=0;
3140 3140
3141 down(&ieee->wx_sem); 3141 mutex_lock(&ieee->wx_mutex);
3142 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length); 3142 //IEEE_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
3143 3143
3144 if (p->length < sizeof(struct ieee_param) || !p->pointer) { 3144 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
@@ -3183,7 +3183,7 @@ int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_poin
3183 3183
3184 kfree(param); 3184 kfree(param);
3185out: 3185out:
3186 up(&ieee->wx_sem); 3186 mutex_unlock(&ieee->wx_mutex);
3187 3187
3188 return ret; 3188 return ret;
3189} 3189}
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
index aad288a1f9e3..21bd0dc40888 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
@@ -34,7 +34,7 @@ int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info
34 int ret; 34 int ret;
35 struct iw_freq *fwrq = &wrqu->freq; 35 struct iw_freq *fwrq = &wrqu->freq;
36 36
37 down(&ieee->wx_sem); 37 mutex_lock(&ieee->wx_mutex);
38 38
39 if (ieee->iw_mode == IW_MODE_INFRA) { 39 if (ieee->iw_mode == IW_MODE_INFRA) {
40 ret = -EOPNOTSUPP; 40 ret = -EOPNOTSUPP;
@@ -79,7 +79,7 @@ int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info
79 79
80 ret = 0; 80 ret = 0;
81out: 81out:
82 up(&ieee->wx_sem); 82 mutex_unlock(&ieee->wx_mutex);
83 return ret; 83 return ret;
84} 84}
85EXPORT_SYMBOL(ieee80211_wx_set_freq); 85EXPORT_SYMBOL(ieee80211_wx_set_freq);
@@ -145,7 +145,7 @@ int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
145 145
146 ieee->sync_scan_hurryup = 1; 146 ieee->sync_scan_hurryup = 1;
147 147
148 down(&ieee->wx_sem); 148 mutex_lock(&ieee->wx_mutex);
149 /* use ifconfig hw ether */ 149 /* use ifconfig hw ether */
150 if (ieee->iw_mode == IW_MODE_MASTER) { 150 if (ieee->iw_mode == IW_MODE_MASTER) {
151 ret = -1; 151 ret = -1;
@@ -173,7 +173,7 @@ int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
173 if (ifup) 173 if (ifup)
174 ieee80211_start_protocol(ieee); 174 ieee80211_start_protocol(ieee);
175out: 175out:
176 up(&ieee->wx_sem); 176 mutex_unlock(&ieee->wx_mutex);
177 return ret; 177 return ret;
178} 178}
179EXPORT_SYMBOL(ieee80211_wx_set_wap); 179EXPORT_SYMBOL(ieee80211_wx_set_wap);
@@ -274,7 +274,7 @@ int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info
274 274
275 ieee->sync_scan_hurryup = 1; 275 ieee->sync_scan_hurryup = 1;
276 276
277 down(&ieee->wx_sem); 277 mutex_lock(&ieee->wx_mutex);
278 278
279 if (wrqu->mode == ieee->iw_mode) 279 if (wrqu->mode == ieee->iw_mode)
280 goto out; 280 goto out;
@@ -293,7 +293,7 @@ int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info
293 } 293 }
294 294
295out: 295out:
296 up(&ieee->wx_sem); 296 mutex_unlock(&ieee->wx_mutex);
297 return 0; 297 return 0;
298} 298}
299EXPORT_SYMBOL(ieee80211_wx_set_mode); 299EXPORT_SYMBOL(ieee80211_wx_set_mode);
@@ -353,7 +353,7 @@ void ieee80211_wx_sync_scan_wq(struct work_struct *work)
353 ieee80211_start_send_beacons(ieee); 353 ieee80211_start_send_beacons(ieee);
354 354
355 netif_carrier_on(ieee->dev); 355 netif_carrier_on(ieee->dev);
356 up(&ieee->wx_sem); 356 mutex_unlock(&ieee->wx_mutex);
357 357
358} 358}
359 359
@@ -362,7 +362,7 @@ int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info
362{ 362{
363 int ret = 0; 363 int ret = 0;
364 364
365 down(&ieee->wx_sem); 365 mutex_lock(&ieee->wx_mutex);
366 366
367 if (ieee->iw_mode == IW_MODE_MONITOR || !(ieee->proto_started)) { 367 if (ieee->iw_mode == IW_MODE_MONITOR || !(ieee->proto_started)) {
368 ret = -1; 368 ret = -1;
@@ -376,7 +376,7 @@ int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info
376 } 376 }
377 377
378out: 378out:
379 up(&ieee->wx_sem); 379 mutex_unlock(&ieee->wx_mutex);
380 return ret; 380 return ret;
381} 381}
382EXPORT_SYMBOL(ieee80211_wx_set_scan); 382EXPORT_SYMBOL(ieee80211_wx_set_scan);
@@ -391,7 +391,7 @@ int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
391 unsigned long flags; 391 unsigned long flags;
392 392
393 ieee->sync_scan_hurryup = 1; 393 ieee->sync_scan_hurryup = 1;
394 down(&ieee->wx_sem); 394 mutex_lock(&ieee->wx_mutex);
395 395
396 proto_started = ieee->proto_started; 396 proto_started = ieee->proto_started;
397 397
@@ -430,7 +430,7 @@ int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
430 if (proto_started) 430 if (proto_started)
431 ieee80211_start_protocol(ieee); 431 ieee80211_start_protocol(ieee);
432out: 432out:
433 up(&ieee->wx_sem); 433 mutex_unlock(&ieee->wx_mutex);
434 return ret; 434 return ret;
435} 435}
436EXPORT_SYMBOL(ieee80211_wx_set_essid); 436EXPORT_SYMBOL(ieee80211_wx_set_essid);
@@ -453,7 +453,7 @@ int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
453 int enable = (parms[0] > 0); 453 int enable = (parms[0] > 0);
454 short prev = ieee->raw_tx; 454 short prev = ieee->raw_tx;
455 455
456 down(&ieee->wx_sem); 456 mutex_lock(&ieee->wx_mutex);
457 457
458 if (enable) 458 if (enable)
459 ieee->raw_tx = 1; 459 ieee->raw_tx = 1;
@@ -475,7 +475,7 @@ int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
475 netif_carrier_off(ieee->dev); 475 netif_carrier_off(ieee->dev);
476 } 476 }
477 477
478 up(&ieee->wx_sem); 478 mutex_unlock(&ieee->wx_mutex);
479 479
480 return 0; 480 return 0;
481} 481}
@@ -514,7 +514,7 @@ int ieee80211_wx_set_power(struct ieee80211_device *ieee,
514{ 514{
515 int ret = 0; 515 int ret = 0;
516 516
517 down(&ieee->wx_sem); 517 mutex_lock(&ieee->wx_mutex);
518 518
519 if (wrqu->power.disabled) { 519 if (wrqu->power.disabled) {
520 ieee->ps = IEEE80211_PS_DISABLED; 520 ieee->ps = IEEE80211_PS_DISABLED;
@@ -553,7 +553,7 @@ int ieee80211_wx_set_power(struct ieee80211_device *ieee,
553 553
554 } 554 }
555exit: 555exit:
556 up(&ieee->wx_sem); 556 mutex_unlock(&ieee->wx_mutex);
557 return ret; 557 return ret;
558 558
559} 559}
@@ -564,7 +564,7 @@ int ieee80211_wx_get_power(struct ieee80211_device *ieee,
564 struct iw_request_info *info, 564 struct iw_request_info *info,
565 union iwreq_data *wrqu, char *extra) 565 union iwreq_data *wrqu, char *extra)
566{ 566{
567 down(&ieee->wx_sem); 567 mutex_lock(&ieee->wx_mutex);
568 568
569 if (ieee->ps == IEEE80211_PS_DISABLED) { 569 if (ieee->ps == IEEE80211_PS_DISABLED) {
570 wrqu->power.disabled = 1; 570 wrqu->power.disabled = 1;
@@ -592,7 +592,7 @@ int ieee80211_wx_get_power(struct ieee80211_device *ieee,
592 wrqu->power.flags |= IW_POWER_UNICAST_R; 592 wrqu->power.flags |= IW_POWER_UNICAST_R;
593 593
594exit: 594exit:
595 up(&ieee->wx_sem); 595 mutex_unlock(&ieee->wx_mutex);
596 return 0; 596 return 0;
597 597
598} 598}
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
index 208be5fc527a..563d7fed6e1c 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
@@ -253,7 +253,7 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
253 int i = 0; 253 int i = 0;
254 int err = 0; 254 int err = 0;
255 IEEE80211_DEBUG_WX("Getting scan\n"); 255 IEEE80211_DEBUG_WX("Getting scan\n");
256 down(&ieee->wx_sem); 256 mutex_lock(&ieee->wx_mutex);
257 spin_lock_irqsave(&ieee->lock, flags); 257 spin_lock_irqsave(&ieee->lock, flags);
258 258
259 list_for_each_entry(network, &ieee->network_list, list) { 259 list_for_each_entry(network, &ieee->network_list, list) {
@@ -262,7 +262,7 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
262 { 262 {
263 err = -E2BIG; 263 err = -E2BIG;
264 break; 264 break;
265 } 265 }
266 if (ieee->scan_age == 0 || 266 if (ieee->scan_age == 0 ||
267 time_after(network->last_scanned + ieee->scan_age, jiffies)) 267 time_after(network->last_scanned + ieee->scan_age, jiffies))
268 ev = rtl819x_translate_scan(ieee, ev, stop, network, info); 268 ev = rtl819x_translate_scan(ieee, ev, stop, network, info);
@@ -277,7 +277,7 @@ int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
277 } 277 }
278 278
279 spin_unlock_irqrestore(&ieee->lock, flags); 279 spin_unlock_irqrestore(&ieee->lock, flags);
280 up(&ieee->wx_sem); 280 mutex_unlock(&ieee->wx_mutex);
281 wrqu->data.length = ev - extra; 281 wrqu->data.length = ev - extra;
282 wrqu->data.flags = 0; 282 wrqu->data.flags = 0;
283 283
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.c b/drivers/staging/rtl8192u/r8180_93cx6.c
index 97d9b3f49114..f35defc36fd9 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.c
+++ b/drivers/staging/rtl8192u/r8180_93cx6.c
@@ -23,8 +23,11 @@
23static void eprom_cs(struct net_device *dev, short bit) 23static void eprom_cs(struct net_device *dev, short bit)
24{ 24{
25 u8 cmdreg; 25 u8 cmdreg;
26 int err;
26 27
27 read_nic_byte_E(dev, EPROM_CMD, &cmdreg); 28 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
29 if (err)
30 return;
28 if (bit) 31 if (bit)
29 /* enable EPROM */ 32 /* enable EPROM */
30 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CS_BIT); 33 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CS_BIT);
@@ -40,8 +43,11 @@ static void eprom_cs(struct net_device *dev, short bit)
40static void eprom_ck_cycle(struct net_device *dev) 43static void eprom_ck_cycle(struct net_device *dev)
41{ 44{
42 u8 cmdreg; 45 u8 cmdreg;
46 int err;
43 47
44 read_nic_byte_E(dev, EPROM_CMD, &cmdreg); 48 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
49 if (err)
50 return;
45 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CK_BIT); 51 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CK_BIT);
46 force_pci_posting(dev); 52 force_pci_posting(dev);
47 udelay(EPROM_DELAY); 53 udelay(EPROM_DELAY);
@@ -56,8 +62,11 @@ static void eprom_ck_cycle(struct net_device *dev)
56static void eprom_w(struct net_device *dev, short bit) 62static void eprom_w(struct net_device *dev, short bit)
57{ 63{
58 u8 cmdreg; 64 u8 cmdreg;
65 int err;
59 66
60 read_nic_byte_E(dev, EPROM_CMD, &cmdreg); 67 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
68 if (err)
69 return;
61 if (bit) 70 if (bit)
62 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_W_BIT); 71 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_W_BIT);
63 else 72 else
@@ -71,8 +80,12 @@ static void eprom_w(struct net_device *dev, short bit)
71static short eprom_r(struct net_device *dev) 80static short eprom_r(struct net_device *dev)
72{ 81{
73 u8 bit; 82 u8 bit;
83 int err;
84
85 err = read_nic_byte_E(dev, EPROM_CMD, &bit);
86 if (err)
87 return err;
74 88
75 read_nic_byte_E(dev, EPROM_CMD, &bit);
76 udelay(EPROM_DELAY); 89 udelay(EPROM_DELAY);
77 90
78 if (bit & EPROM_R_BIT) 91 if (bit & EPROM_R_BIT)
@@ -93,7 +106,7 @@ static void eprom_send_bits_string(struct net_device *dev, short b[], int len)
93} 106}
94 107
95 108
96u32 eprom_read(struct net_device *dev, u32 addr) 109int eprom_read(struct net_device *dev, u32 addr)
97{ 110{
98 struct r8192_priv *priv = ieee80211_priv(dev); 111 struct r8192_priv *priv = ieee80211_priv(dev);
99 short read_cmd[] = {1, 1, 0}; 112 short read_cmd[] = {1, 1, 0};
@@ -101,6 +114,7 @@ u32 eprom_read(struct net_device *dev, u32 addr)
101 int i; 114 int i;
102 int addr_len; 115 int addr_len;
103 u32 ret; 116 u32 ret;
117 int err;
104 118
105 ret = 0; 119 ret = 0;
106 /* enable EPROM programming */ 120 /* enable EPROM programming */
@@ -144,7 +158,11 @@ u32 eprom_read(struct net_device *dev, u32 addr)
144 * and reading data. (eeprom outs a dummy 0) 158 * and reading data. (eeprom outs a dummy 0)
145 */ 159 */
146 eprom_ck_cycle(dev); 160 eprom_ck_cycle(dev);
147 ret |= (eprom_r(dev)<<(15-i)); 161 err = eprom_r(dev);
162 if (err < 0)
163 return err;
164
165 ret |= err<<(15-i);
148 } 166 }
149 167
150 eprom_cs(dev, 0); 168 eprom_cs(dev, 0);
diff --git a/drivers/staging/rtl8192u/r8180_93cx6.h b/drivers/staging/rtl8192u/r8180_93cx6.h
index b840348eb5e3..9cf7f587c3ab 100644
--- a/drivers/staging/rtl8192u/r8180_93cx6.h
+++ b/drivers/staging/rtl8192u/r8180_93cx6.h
@@ -40,4 +40,4 @@
40#define EPROM_TXPW1 0x3d 40#define EPROM_TXPW1 0x3d
41 41
42 42
43u32 eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */ 43int eprom_read(struct net_device *dev, u32 addr); /* reads a 16 bits word */
diff --git a/drivers/staging/rtl8192u/r8192U.h b/drivers/staging/rtl8192u/r8192U.h
index ee1c72267811..821afc0ddac5 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -879,8 +879,7 @@ typedef struct r8192_priv {
879 /* If 1, allow bad crc frame, reception in monitor mode */ 879 /* If 1, allow bad crc frame, reception in monitor mode */
880 short crcmon; 880 short crcmon;
881 881
882 struct semaphore wx_sem; 882 struct mutex wx_mutex;
883 struct semaphore rf_sem; /* Used to lock rf write operation */
884 883
885 u8 rf_type; /* 0: 1T2R, 1: 2T4R */ 884 u8 rf_type; /* 0: 1T2R, 1: 2T4R */
886 RT_RF_TYPE_819xU rf_chip; 885 RT_RF_TYPE_819xU rf_chip;
@@ -1129,10 +1128,10 @@ int read_nic_byte(struct net_device *dev, int x, u8 *data);
1129int read_nic_byte_E(struct net_device *dev, int x, u8 *data); 1128int read_nic_byte_E(struct net_device *dev, int x, u8 *data);
1130int read_nic_dword(struct net_device *dev, int x, u32 *data); 1129int read_nic_dword(struct net_device *dev, int x, u32 *data);
1131int read_nic_word(struct net_device *dev, int x, u16 *data); 1130int read_nic_word(struct net_device *dev, int x, u16 *data);
1132void write_nic_byte(struct net_device *dev, int x, u8 y); 1131int write_nic_byte(struct net_device *dev, int x, u8 y);
1133void write_nic_byte_E(struct net_device *dev, int x, u8 y); 1132int write_nic_byte_E(struct net_device *dev, int x, u8 y);
1134void write_nic_word(struct net_device *dev, int x, u16 y); 1133int write_nic_word(struct net_device *dev, int x, u16 y);
1135void write_nic_dword(struct net_device *dev, int x, u32 y); 1134int write_nic_dword(struct net_device *dev, int x, u32 y);
1136void force_pci_posting(struct net_device *dev); 1135void force_pci_posting(struct net_device *dev);
1137 1136
1138void rtl8192_rtx_disable(struct net_device *); 1137void rtl8192_rtx_disable(struct net_device *);
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 8c1d73719147..dd0970facdf5 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -253,7 +253,7 @@ u32 read_cam(struct net_device *dev, u8 addr)
253 return data; 253 return data;
254} 254}
255 255
256void write_nic_byte_E(struct net_device *dev, int indx, u8 data) 256int write_nic_byte_E(struct net_device *dev, int indx, u8 data)
257{ 257{
258 int status; 258 int status;
259 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); 259 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
@@ -261,7 +261,7 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
261 u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL); 261 u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
262 262
263 if (!usbdata) 263 if (!usbdata)
264 return; 264 return -ENOMEM;
265 *usbdata = data; 265 *usbdata = data;
266 266
267 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 267 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -269,9 +269,12 @@ void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
269 indx | 0xfe00, 0, usbdata, 1, HZ / 2); 269 indx | 0xfe00, 0, usbdata, 1, HZ / 2);
270 kfree(usbdata); 270 kfree(usbdata);
271 271
272 if (status < 0) 272 if (status < 0){
273 netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n", 273 netdev_err(dev, "write_nic_byte_E TimeOut! status: %d\n",
274 status); 274 status);
275 return status;
276 }
277 return 0;
275} 278}
276 279
277int read_nic_byte_E(struct net_device *dev, int indx, u8 *data) 280int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
@@ -299,7 +302,7 @@ int read_nic_byte_E(struct net_device *dev, int indx, u8 *data)
299} 302}
300 303
301/* as 92U has extend page from 4 to 16, so modify functions below. */ 304/* as 92U has extend page from 4 to 16, so modify functions below. */
302void write_nic_byte(struct net_device *dev, int indx, u8 data) 305int write_nic_byte(struct net_device *dev, int indx, u8 data)
303{ 306{
304 int status; 307 int status;
305 308
@@ -308,7 +311,7 @@ void write_nic_byte(struct net_device *dev, int indx, u8 data)
308 u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL); 311 u8 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
309 312
310 if (!usbdata) 313 if (!usbdata)
311 return; 314 return -ENOMEM;
312 *usbdata = data; 315 *usbdata = data;
313 316
314 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 317 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -317,12 +320,16 @@ void write_nic_byte(struct net_device *dev, int indx, u8 data)
317 usbdata, 1, HZ / 2); 320 usbdata, 1, HZ / 2);
318 kfree(usbdata); 321 kfree(usbdata);
319 322
320 if (status < 0) 323 if (status < 0) {
321 netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status); 324 netdev_err(dev, "write_nic_byte TimeOut! status: %d\n", status);
325 return status;
326 }
327
328 return 0;
322} 329}
323 330
324 331
325void write_nic_word(struct net_device *dev, int indx, u16 data) 332int write_nic_word(struct net_device *dev, int indx, u16 data)
326{ 333{
327 int status; 334 int status;
328 335
@@ -331,7 +338,7 @@ void write_nic_word(struct net_device *dev, int indx, u16 data)
331 u16 *usbdata = kzalloc(sizeof(data), GFP_KERNEL); 338 u16 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
332 339
333 if (!usbdata) 340 if (!usbdata)
334 return; 341 return -ENOMEM;
335 *usbdata = data; 342 *usbdata = data;
336 343
337 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 344 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -340,12 +347,16 @@ void write_nic_word(struct net_device *dev, int indx, u16 data)
340 usbdata, 2, HZ / 2); 347 usbdata, 2, HZ / 2);
341 kfree(usbdata); 348 kfree(usbdata);
342 349
343 if (status < 0) 350 if (status < 0) {
344 netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status); 351 netdev_err(dev, "write_nic_word TimeOut! status: %d\n", status);
352 return status;
353 }
354
355 return 0;
345} 356}
346 357
347 358
348void write_nic_dword(struct net_device *dev, int indx, u32 data) 359int write_nic_dword(struct net_device *dev, int indx, u32 data)
349{ 360{
350 int status; 361 int status;
351 362
@@ -354,7 +365,7 @@ void write_nic_dword(struct net_device *dev, int indx, u32 data)
354 u32 *usbdata = kzalloc(sizeof(data), GFP_KERNEL); 365 u32 *usbdata = kzalloc(sizeof(data), GFP_KERNEL);
355 366
356 if (!usbdata) 367 if (!usbdata)
357 return; 368 return -ENOMEM;
358 *usbdata = data; 369 *usbdata = data;
359 370
360 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 371 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
@@ -364,9 +375,13 @@ void write_nic_dword(struct net_device *dev, int indx, u32 data)
364 kfree(usbdata); 375 kfree(usbdata);
365 376
366 377
367 if (status < 0) 378 if (status < 0) {
368 netdev_err(dev, "write_nic_dword TimeOut! status: %d\n", 379 netdev_err(dev, "write_nic_dword TimeOut! status: %d\n",
369 status); 380 status);
381 return status;
382 }
383
384 return 0;
370} 385}
371 386
372 387
@@ -2361,8 +2376,7 @@ static void rtl8192_init_priv_lock(struct r8192_priv *priv)
2361{ 2376{
2362 spin_lock_init(&priv->tx_lock); 2377 spin_lock_init(&priv->tx_lock);
2363 spin_lock_init(&priv->irq_lock); 2378 spin_lock_init(&priv->irq_lock);
2364 sema_init(&priv->wx_sem, 1); 2379 mutex_init(&priv->wx_mutex);
2365 sema_init(&priv->rf_sem, 1);
2366 mutex_init(&priv->mutex); 2380 mutex_init(&priv->mutex);
2367} 2381}
2368 2382
@@ -2421,7 +2435,7 @@ static inline u16 endian_swap(u16 *data)
2421 return *data; 2435 return *data;
2422} 2436}
2423 2437
2424static void rtl8192_read_eeprom_info(struct net_device *dev) 2438static int rtl8192_read_eeprom_info(struct net_device *dev)
2425{ 2439{
2426 u16 wEPROM_ID = 0; 2440 u16 wEPROM_ID = 0;
2427 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02}; 2441 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
@@ -2429,9 +2443,13 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
2429 struct r8192_priv *priv = ieee80211_priv(dev); 2443 struct r8192_priv *priv = ieee80211_priv(dev);
2430 u16 tmpValue = 0; 2444 u16 tmpValue = 0;
2431 int i; 2445 int i;
2446 int ret;
2432 2447
2433 RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__); 2448 RT_TRACE(COMP_EPROM, "===========>%s()\n", __func__);
2434 wEPROM_ID = eprom_read(dev, 0); /* first read EEPROM ID out; */ 2449 ret = eprom_read(dev, 0); /* first read EEPROM ID out; */
2450 if (ret < 0)
2451 return ret;
2452 wEPROM_ID = (u16)ret;
2435 RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID); 2453 RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
2436 2454
2437 if (wEPROM_ID != RTL8190_EEPROM_ID) 2455 if (wEPROM_ID != RTL8190_EEPROM_ID)
@@ -2443,13 +2461,25 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
2443 2461
2444 if (bLoad_From_EEPOM) { 2462 if (bLoad_From_EEPOM) {
2445 tmpValue = eprom_read(dev, EEPROM_VID >> 1); 2463 tmpValue = eprom_read(dev, EEPROM_VID >> 1);
2464 ret = eprom_read(dev, EEPROM_VID >> 1);
2465 if (ret < 0)
2466 return ret;
2467 tmpValue = (u16)ret;
2446 priv->eeprom_vid = endian_swap(&tmpValue); 2468 priv->eeprom_vid = endian_swap(&tmpValue);
2447 priv->eeprom_pid = eprom_read(dev, EEPROM_PID >> 1); 2469 ret = eprom_read(dev, EEPROM_PID >> 1);
2448 tmpValue = eprom_read(dev, EEPROM_ChannelPlan >> 1); 2470 if (ret < 0)
2471 return ret;
2472 priv->eeprom_pid = (u16)ret;
2473 ret = eprom_read(dev, EEPROM_ChannelPlan >> 1);
2474 if (ret < 0)
2475 return ret;
2476 tmpValue = (u16)ret;
2449 priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8; 2477 priv->eeprom_ChannelPlan = (tmpValue & 0xff00) >> 8;
2450 priv->btxpowerdata_readfromEEPORM = true; 2478 priv->btxpowerdata_readfromEEPORM = true;
2451 priv->eeprom_CustomerID = 2479 ret = eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8;
2452 eprom_read(dev, (EEPROM_Customer_ID >> 1)) >> 8; 2480 if (ret < 0)
2481 return ret;
2482 priv->eeprom_CustomerID = (u16)ret;
2453 } else { 2483 } else {
2454 priv->eeprom_vid = 0; 2484 priv->eeprom_vid = 0;
2455 priv->eeprom_pid = 0; 2485 priv->eeprom_pid = 0;
@@ -2467,10 +2497,10 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
2467 int i; 2497 int i;
2468 2498
2469 for (i = 0; i < 6; i += 2) { 2499 for (i = 0; i < 6; i += 2) {
2470 u16 tmp = 0; 2500 ret = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
2471 2501 if (ret < 0)
2472 tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1)); 2502 return ret;
2473 *(u16 *)(&dev->dev_addr[i]) = tmp; 2503 *(u16 *)(&dev->dev_addr[i]) = (u16)ret;
2474 } 2504 }
2475 } else { 2505 } else {
2476 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6); 2506 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
@@ -2482,52 +2512,72 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
2482 2512
2483 if (priv->card_8192_version == (u8)VERSION_819xU_A) { 2513 if (priv->card_8192_version == (u8)VERSION_819xU_A) {
2484 /* read Tx power gain offset of legacy OFDM to HT rate */ 2514 /* read Tx power gain offset of legacy OFDM to HT rate */
2485 if (bLoad_From_EEPOM) 2515 if (bLoad_From_EEPOM) {
2486 priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff >> 1)) & 0xff00) >> 8; 2516 ret = eprom_read(dev, (EEPROM_TxPowerDiff >> 1));
2487 else 2517 if (ret < 0)
2518 return ret;
2519 priv->EEPROMTxPowerDiff = ((u16)ret & 0xff00) >> 8;
2520 } else
2488 priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower; 2521 priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
2489 RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff); 2522 RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
2490 /* read ThermalMeter from EEPROM */ 2523 /* read ThermalMeter from EEPROM */
2491 if (bLoad_From_EEPOM) 2524 if (bLoad_From_EEPOM) {
2492 priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter >> 1)) & 0x00ff); 2525 ret = eprom_read(dev, (EEPROM_ThermalMeter >> 1));
2493 else 2526 if (ret < 0)
2527 return ret;
2528 priv->EEPROMThermalMeter = (u8)((u16)ret & 0x00ff);
2529 } else
2494 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter; 2530 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
2495 RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter); 2531 RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
2496 /* for tx power track */ 2532 /* for tx power track */
2497 priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100; 2533 priv->TSSI_13dBm = priv->EEPROMThermalMeter * 100;
2498 /* read antenna tx power offset of B/C/D to A from EEPROM */ 2534 /* read antenna tx power offset of B/C/D to A from EEPROM */
2499 if (bLoad_From_EEPOM) 2535 if (bLoad_From_EEPOM) {
2500 priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff >> 1)) & 0x0f00) >> 8; 2536 ret = eprom_read(dev, (EEPROM_PwDiff >> 1));
2501 else 2537 if (ret < 0)
2538 return ret;
2539 priv->EEPROMPwDiff = ((u16)ret & 0x0f00) >> 8;
2540 } else
2502 priv->EEPROMPwDiff = EEPROM_Default_PwDiff; 2541 priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
2503 RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff); 2542 RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
2504 /* Read CrystalCap from EEPROM */ 2543 /* Read CrystalCap from EEPROM */
2505 if (bLoad_From_EEPOM) 2544 if (bLoad_From_EEPOM) {
2506 priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap >> 1)) & 0x0f); 2545 ret = eprom_read(dev, (EEPROM_CrystalCap >> 1));
2507 else 2546 if (ret < 0)
2547 return ret;
2548 priv->EEPROMCrystalCap = (u16)ret & 0x0f;
2549 } else
2508 priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap; 2550 priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
2509 RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap); 2551 RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
2510 /* get per-channel Tx power level */ 2552 /* get per-channel Tx power level */
2511 if (bLoad_From_EEPOM) 2553 if (bLoad_From_EEPOM) {
2512 priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1)) & 0xff00) >> 8; 2554 ret = eprom_read(dev, (EEPROM_TxPwIndex_Ver >> 1));
2513 else 2555 if (ret < 0)
2556 return ret;
2557 priv->EEPROM_Def_Ver = ((u16)ret & 0xff00) >> 8;
2558 } else
2514 priv->EEPROM_Def_Ver = 1; 2559 priv->EEPROM_Def_Ver = 1;
2515 RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver); 2560 RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
2516 if (priv->EEPROM_Def_Ver == 0) { /* old eeprom definition */ 2561 if (priv->EEPROM_Def_Ver == 0) { /* old eeprom definition */
2517 int i; 2562 int i;
2518 2563
2519 if (bLoad_From_EEPOM) 2564 if (bLoad_From_EEPOM) {
2520 priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1)) & 0xff) >> 8; 2565 ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK >> 1));
2521 else 2566 if (ret < 0)
2567 return ret;
2568 priv->EEPROMTxPowerLevelCCK = ((u16)ret & 0xff) >> 8;
2569 } else
2522 priv->EEPROMTxPowerLevelCCK = 0x10; 2570 priv->EEPROMTxPowerLevelCCK = 0x10;
2523 RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK); 2571 RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
2524 for (i = 0; i < 3; i++) { 2572 for (i = 0; i < 3; i++) {
2525 if (bLoad_From_EEPOM) { 2573 if (bLoad_From_EEPOM) {
2526 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1); 2574 ret = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G + i) >> 1);
2575 if ( ret < 0)
2576 return ret;
2527 if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0) 2577 if (((EEPROM_TxPwIndex_OFDM_24G + i) % 2) == 0)
2528 tmpValue = tmpValue & 0x00ff; 2578 tmpValue = (u16)ret & 0x00ff;
2529 else 2579 else
2530 tmpValue = (tmpValue & 0xff00) >> 8; 2580 tmpValue = ((u16)ret & 0xff00) >> 8;
2531 } else { 2581 } else {
2532 tmpValue = 0x10; 2582 tmpValue = 0x10;
2533 } 2583 }
@@ -2536,17 +2586,21 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
2536 } 2586 }
2537 } else if (priv->EEPROM_Def_Ver == 1) { 2587 } else if (priv->EEPROM_Def_Ver == 1) {
2538 if (bLoad_From_EEPOM) { 2588 if (bLoad_From_EEPOM) {
2539 tmpValue = eprom_read(dev, 2589 ret = eprom_read(dev, EEPROM_TxPwIndex_CCK_V1 >> 1);
2540 EEPROM_TxPwIndex_CCK_V1 >> 1); 2590 if (ret < 0)
2541 tmpValue = (tmpValue & 0xff00) >> 8; 2591 return ret;
2592 tmpValue = ((u16)ret & 0xff00) >> 8;
2542 } else { 2593 } else {
2543 tmpValue = 0x10; 2594 tmpValue = 0x10;
2544 } 2595 }
2545 priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue; 2596 priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
2546 2597
2547 if (bLoad_From_EEPOM) 2598 if (bLoad_From_EEPOM) {
2548 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1); 2599 ret = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2) >> 1);
2549 else 2600 if (ret < 0)
2601 return ret;
2602 tmpValue = (u16)ret;
2603 } else
2550 tmpValue = 0x1010; 2604 tmpValue = 0x1010;
2551 *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue; 2605 *((u16 *)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
2552 if (bLoad_From_EEPOM) 2606 if (bLoad_From_EEPOM)
@@ -2644,6 +2698,8 @@ static void rtl8192_read_eeprom_info(struct net_device *dev)
2644 init_rate_adaptive(dev); 2698 init_rate_adaptive(dev);
2645 2699
2646 RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__); 2700 RT_TRACE(COMP_EPROM, "<===========%s()\n", __func__);
2701
2702 return 0;
2647} 2703}
2648 2704
2649static short rtl8192_get_channel_map(struct net_device *dev) 2705static short rtl8192_get_channel_map(struct net_device *dev)
@@ -2664,6 +2720,7 @@ static short rtl8192_get_channel_map(struct net_device *dev)
2664static short rtl8192_init(struct net_device *dev) 2720static short rtl8192_init(struct net_device *dev)
2665{ 2721{
2666 struct r8192_priv *priv = ieee80211_priv(dev); 2722 struct r8192_priv *priv = ieee80211_priv(dev);
2723 int err;
2667 2724
2668 memset(&(priv->stats), 0, sizeof(struct Stats)); 2725 memset(&(priv->stats), 0, sizeof(struct Stats));
2669 memset(priv->txqueue_to_outpipemap, 0, 9); 2726 memset(priv->txqueue_to_outpipemap, 0, 9);
@@ -2685,7 +2742,14 @@ static short rtl8192_init(struct net_device *dev)
2685 rtl8192_init_priv_lock(priv); 2742 rtl8192_init_priv_lock(priv);
2686 rtl8192_init_priv_task(dev); 2743 rtl8192_init_priv_task(dev);
2687 rtl8192_get_eeprom_size(dev); 2744 rtl8192_get_eeprom_size(dev);
2688 rtl8192_read_eeprom_info(dev); 2745 err = rtl8192_read_eeprom_info(dev);
2746 if (err) {
2747 DMESG("Reading EEPROM info failed");
2748 kfree(priv->pFirmware);
2749 priv->pFirmware = NULL;
2750 free_ieee80211(dev);
2751 return err;
2752 }
2689 rtl8192_get_channel_map(dev); 2753 rtl8192_get_channel_map(dev);
2690 init_hal_dm(dev); 2754 init_hal_dm(dev);
2691 setup_timer(&priv->watch_dog_timer, watch_dog_timer_callback, 2755 setup_timer(&priv->watch_dog_timer, watch_dog_timer_callback,
@@ -3303,12 +3367,12 @@ RESET_START:
3303 3367
3304 /* Set the variable for reset. */ 3368 /* Set the variable for reset. */
3305 priv->ResetProgress = RESET_TYPE_SILENT; 3369 priv->ResetProgress = RESET_TYPE_SILENT;
3306 down(&priv->wx_sem); 3370 mutex_lock(&priv->wx_mutex);
3307 if (priv->up == 0) { 3371 if (priv->up == 0) {
3308 RT_TRACE(COMP_ERR, 3372 RT_TRACE(COMP_ERR,
3309 "%s():the driver is not up! return\n", 3373 "%s():the driver is not up! return\n",
3310 __func__); 3374 __func__);
3311 up(&priv->wx_sem); 3375 mutex_unlock(&priv->wx_mutex);
3312 return; 3376 return;
3313 } 3377 }
3314 priv->up = 0; 3378 priv->up = 0;
@@ -3323,19 +3387,19 @@ RESET_START:
3323 3387
3324 ieee->sync_scan_hurryup = 1; 3388 ieee->sync_scan_hurryup = 1;
3325 if (ieee->state == IEEE80211_LINKED) { 3389 if (ieee->state == IEEE80211_LINKED) {
3326 down(&ieee->wx_sem); 3390 mutex_lock(&ieee->wx_mutex);
3327 netdev_dbg(dev, "ieee->state is IEEE80211_LINKED\n"); 3391 netdev_dbg(dev, "ieee->state is IEEE80211_LINKED\n");
3328 ieee80211_stop_send_beacons(priv->ieee80211); 3392 ieee80211_stop_send_beacons(priv->ieee80211);
3329 del_timer_sync(&ieee->associate_timer); 3393 del_timer_sync(&ieee->associate_timer);
3330 cancel_delayed_work(&ieee->associate_retry_wq); 3394 cancel_delayed_work(&ieee->associate_retry_wq);
3331 ieee80211_stop_scan(ieee); 3395 ieee80211_stop_scan(ieee);
3332 netif_carrier_off(dev); 3396 netif_carrier_off(dev);
3333 up(&ieee->wx_sem); 3397 mutex_unlock(&ieee->wx_mutex);
3334 } else { 3398 } else {
3335 netdev_dbg(dev, "ieee->state is NOT LINKED\n"); 3399 netdev_dbg(dev, "ieee->state is NOT LINKED\n");
3336 ieee80211_softmac_stop_protocol(priv->ieee80211); 3400 ieee80211_softmac_stop_protocol(priv->ieee80211);
3337 } 3401 }
3338 up(&priv->wx_sem); 3402 mutex_unlock(&priv->wx_mutex);
3339 RT_TRACE(COMP_RESET, 3403 RT_TRACE(COMP_RESET,
3340 "%s():<==========down process is finished\n", 3404 "%s():<==========down process is finished\n",
3341 __func__); 3405 __func__);
@@ -3533,9 +3597,9 @@ static int rtl8192_open(struct net_device *dev)
3533 struct r8192_priv *priv = ieee80211_priv(dev); 3597 struct r8192_priv *priv = ieee80211_priv(dev);
3534 int ret; 3598 int ret;
3535 3599
3536 down(&priv->wx_sem); 3600 mutex_lock(&priv->wx_mutex);
3537 ret = rtl8192_up(dev); 3601 ret = rtl8192_up(dev);
3538 up(&priv->wx_sem); 3602 mutex_unlock(&priv->wx_mutex);
3539 return ret; 3603 return ret;
3540} 3604}
3541 3605
@@ -3556,11 +3620,11 @@ static int rtl8192_close(struct net_device *dev)
3556 struct r8192_priv *priv = ieee80211_priv(dev); 3620 struct r8192_priv *priv = ieee80211_priv(dev);
3557 int ret; 3621 int ret;
3558 3622
3559 down(&priv->wx_sem); 3623 mutex_lock(&priv->wx_mutex);
3560 3624
3561 ret = rtl8192_down(dev); 3625 ret = rtl8192_down(dev);
3562 3626
3563 up(&priv->wx_sem); 3627 mutex_unlock(&priv->wx_mutex);
3564 3628
3565 return ret; 3629 return ret;
3566} 3630}
@@ -3632,11 +3696,11 @@ static void rtl8192_restart(struct work_struct *work)
3632 reset_wq); 3696 reset_wq);
3633 struct net_device *dev = priv->ieee80211->dev; 3697 struct net_device *dev = priv->ieee80211->dev;
3634 3698
3635 down(&priv->wx_sem); 3699 mutex_lock(&priv->wx_mutex);
3636 3700
3637 rtl8192_commit(dev); 3701 rtl8192_commit(dev);
3638 3702
3639 up(&priv->wx_sem); 3703 mutex_unlock(&priv->wx_mutex);
3640} 3704}
3641 3705
3642static void r8192_set_multicast(struct net_device *dev) 3706static void r8192_set_multicast(struct net_device *dev)
@@ -3659,12 +3723,12 @@ static int r8192_set_mac_adr(struct net_device *dev, void *mac)
3659 struct r8192_priv *priv = ieee80211_priv(dev); 3723 struct r8192_priv *priv = ieee80211_priv(dev);
3660 struct sockaddr *addr = mac; 3724 struct sockaddr *addr = mac;
3661 3725
3662 down(&priv->wx_sem); 3726 mutex_lock(&priv->wx_mutex);
3663 3727
3664 ether_addr_copy(dev->dev_addr, addr->sa_data); 3728 ether_addr_copy(dev->dev_addr, addr->sa_data);
3665 3729
3666 schedule_work(&priv->reset_wq); 3730 schedule_work(&priv->reset_wq);
3667 up(&priv->wx_sem); 3731 mutex_unlock(&priv->wx_mutex);
3668 3732
3669 return 0; 3733 return 0;
3670} 3734}
@@ -3681,7 +3745,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3681 struct iw_point *p = &wrq->u.data; 3745 struct iw_point *p = &wrq->u.data;
3682 struct ieee_param *ipw = NULL; 3746 struct ieee_param *ipw = NULL;
3683 3747
3684 down(&priv->wx_sem); 3748 mutex_lock(&priv->wx_mutex);
3685 3749
3686 3750
3687 if (p->length < sizeof(struct ieee_param) || !p->pointer) { 3751 if (p->length < sizeof(struct ieee_param) || !p->pointer) {
@@ -3774,7 +3838,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3774 kfree(ipw); 3838 kfree(ipw);
3775 ipw = NULL; 3839 ipw = NULL;
3776out: 3840out:
3777 up(&priv->wx_sem); 3841 mutex_unlock(&priv->wx_mutex);
3778 return ret; 3842 return ret;
3779} 3843}
3780 3844
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c
index 837704de3ea4..d2f2f246063f 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.c
+++ b/drivers/staging/rtl8192u/r8192U_wx.c
@@ -67,11 +67,11 @@ static int r8192_wx_set_rate(struct net_device *dev,
67 int ret; 67 int ret;
68 struct r8192_priv *priv = ieee80211_priv(dev); 68 struct r8192_priv *priv = ieee80211_priv(dev);
69 69
70 down(&priv->wx_sem); 70 mutex_lock(&priv->wx_mutex);
71 71
72 ret = ieee80211_wx_set_rate(priv->ieee80211, info, wrqu, extra); 72 ret = ieee80211_wx_set_rate(priv->ieee80211, info, wrqu, extra);
73 73
74 up(&priv->wx_sem); 74 mutex_unlock(&priv->wx_mutex);
75 75
76 return ret; 76 return ret;
77} 77}
@@ -83,11 +83,11 @@ static int r8192_wx_set_rts(struct net_device *dev,
83 int ret; 83 int ret;
84 struct r8192_priv *priv = ieee80211_priv(dev); 84 struct r8192_priv *priv = ieee80211_priv(dev);
85 85
86 down(&priv->wx_sem); 86 mutex_lock(&priv->wx_mutex);
87 87
88 ret = ieee80211_wx_set_rts(priv->ieee80211, info, wrqu, extra); 88 ret = ieee80211_wx_set_rts(priv->ieee80211, info, wrqu, extra);
89 89
90 up(&priv->wx_sem); 90 mutex_unlock(&priv->wx_mutex);
91 91
92 return ret; 92 return ret;
93} 93}
@@ -108,11 +108,11 @@ static int r8192_wx_set_power(struct net_device *dev,
108 int ret; 108 int ret;
109 struct r8192_priv *priv = ieee80211_priv(dev); 109 struct r8192_priv *priv = ieee80211_priv(dev);
110 110
111 down(&priv->wx_sem); 111 mutex_lock(&priv->wx_mutex);
112 112
113 ret = ieee80211_wx_set_power(priv->ieee80211, info, wrqu, extra); 113 ret = ieee80211_wx_set_power(priv->ieee80211, info, wrqu, extra);
114 114
115 up(&priv->wx_sem); 115 mutex_unlock(&priv->wx_mutex);
116 116
117 return ret; 117 return ret;
118} 118}
@@ -132,11 +132,11 @@ static int r8192_wx_force_reset(struct net_device *dev,
132{ 132{
133 struct r8192_priv *priv = ieee80211_priv(dev); 133 struct r8192_priv *priv = ieee80211_priv(dev);
134 134
135 down(&priv->wx_sem); 135 mutex_lock(&priv->wx_mutex);
136 136
137 netdev_dbg(dev, "%s(): force reset ! extra is %d\n", __func__, *extra); 137 netdev_dbg(dev, "%s(): force reset ! extra is %d\n", __func__, *extra);
138 priv->force_reset = *extra; 138 priv->force_reset = *extra;
139 up(&priv->wx_sem); 139 mutex_unlock(&priv->wx_mutex);
140 return 0; 140 return 0;
141 141
142} 142}
@@ -148,11 +148,11 @@ static int r8192_wx_set_rawtx(struct net_device *dev,
148 struct r8192_priv *priv = ieee80211_priv(dev); 148 struct r8192_priv *priv = ieee80211_priv(dev);
149 int ret; 149 int ret;
150 150
151 down(&priv->wx_sem); 151 mutex_lock(&priv->wx_mutex);
152 152
153 ret = ieee80211_wx_set_rawtx(priv->ieee80211, info, wrqu, extra); 153 ret = ieee80211_wx_set_rawtx(priv->ieee80211, info, wrqu, extra);
154 154
155 up(&priv->wx_sem); 155 mutex_unlock(&priv->wx_mutex);
156 156
157 return ret; 157 return ret;
158 158
@@ -166,7 +166,7 @@ static int r8192_wx_set_crcmon(struct net_device *dev,
166 int *parms = (int *)extra; 166 int *parms = (int *)extra;
167 int enable = (parms[0] > 0); 167 int enable = (parms[0] > 0);
168 168
169 down(&priv->wx_sem); 169 mutex_lock(&priv->wx_mutex);
170 170
171 if (enable) 171 if (enable)
172 priv->crcmon = 1; 172 priv->crcmon = 1;
@@ -176,7 +176,7 @@ static int r8192_wx_set_crcmon(struct net_device *dev,
176 DMESG("bad CRC in monitor mode are %s", 176 DMESG("bad CRC in monitor mode are %s",
177 priv->crcmon ? "accepted" : "rejected"); 177 priv->crcmon ? "accepted" : "rejected");
178 178
179 up(&priv->wx_sem); 179 mutex_unlock(&priv->wx_mutex);
180 180
181 return 0; 181 return 0;
182} 182}
@@ -187,13 +187,13 @@ static int r8192_wx_set_mode(struct net_device *dev, struct iw_request_info *a,
187 struct r8192_priv *priv = ieee80211_priv(dev); 187 struct r8192_priv *priv = ieee80211_priv(dev);
188 int ret; 188 int ret;
189 189
190 down(&priv->wx_sem); 190 mutex_lock(&priv->wx_mutex);
191 191
192 ret = ieee80211_wx_set_mode(priv->ieee80211, a, wrqu, b); 192 ret = ieee80211_wx_set_mode(priv->ieee80211, a, wrqu, b);
193 193
194 rtl8192_set_rxconf(dev); 194 rtl8192_set_rxconf(dev);
195 195
196 up(&priv->wx_sem); 196 mutex_unlock(&priv->wx_mutex);
197 return ret; 197 return ret;
198} 198}
199 199
@@ -338,7 +338,7 @@ static int r8192_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
338 } 338 }
339 } 339 }
340 340
341 down(&priv->wx_sem); 341 mutex_lock(&priv->wx_mutex);
342 if (priv->ieee80211->state != IEEE80211_LINKED) { 342 if (priv->ieee80211->state != IEEE80211_LINKED) {
343 priv->ieee80211->scanning = 0; 343 priv->ieee80211->scanning = 0;
344 ieee80211_softmac_scan_syncro(priv->ieee80211); 344 ieee80211_softmac_scan_syncro(priv->ieee80211);
@@ -346,7 +346,7 @@ static int r8192_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
346 } else { 346 } else {
347 ret = ieee80211_wx_set_scan(priv->ieee80211, a, wrqu, b); 347 ret = ieee80211_wx_set_scan(priv->ieee80211, a, wrqu, b);
348 } 348 }
349 up(&priv->wx_sem); 349 mutex_unlock(&priv->wx_mutex);
350 return ret; 350 return ret;
351} 351}
352 352
@@ -361,11 +361,11 @@ static int r8192_wx_get_scan(struct net_device *dev, struct iw_request_info *a,
361 if (!priv->up) 361 if (!priv->up)
362 return -ENETDOWN; 362 return -ENETDOWN;
363 363
364 down(&priv->wx_sem); 364 mutex_lock(&priv->wx_mutex);
365 365
366 ret = ieee80211_wx_get_scan(priv->ieee80211, a, wrqu, b); 366 ret = ieee80211_wx_get_scan(priv->ieee80211, a, wrqu, b);
367 367
368 up(&priv->wx_sem); 368 mutex_unlock(&priv->wx_mutex);
369 369
370 return ret; 370 return ret;
371} 371}
@@ -377,11 +377,11 @@ static int r8192_wx_set_essid(struct net_device *dev,
377 struct r8192_priv *priv = ieee80211_priv(dev); 377 struct r8192_priv *priv = ieee80211_priv(dev);
378 int ret; 378 int ret;
379 379
380 down(&priv->wx_sem); 380 mutex_lock(&priv->wx_mutex);
381 381
382 ret = ieee80211_wx_set_essid(priv->ieee80211, a, wrqu, b); 382 ret = ieee80211_wx_set_essid(priv->ieee80211, a, wrqu, b);
383 383
384 up(&priv->wx_sem); 384 mutex_unlock(&priv->wx_mutex);
385 385
386 return ret; 386 return ret;
387} 387}
@@ -393,11 +393,11 @@ static int r8192_wx_get_essid(struct net_device *dev,
393 int ret; 393 int ret;
394 struct r8192_priv *priv = ieee80211_priv(dev); 394 struct r8192_priv *priv = ieee80211_priv(dev);
395 395
396 down(&priv->wx_sem); 396 mutex_lock(&priv->wx_mutex);
397 397
398 ret = ieee80211_wx_get_essid(priv->ieee80211, a, wrqu, b); 398 ret = ieee80211_wx_get_essid(priv->ieee80211, a, wrqu, b);
399 399
400 up(&priv->wx_sem); 400 mutex_unlock(&priv->wx_mutex);
401 401
402 return ret; 402 return ret;
403} 403}
@@ -408,11 +408,11 @@ static int r8192_wx_set_freq(struct net_device *dev, struct iw_request_info *a,
408 int ret; 408 int ret;
409 struct r8192_priv *priv = ieee80211_priv(dev); 409 struct r8192_priv *priv = ieee80211_priv(dev);
410 410
411 down(&priv->wx_sem); 411 mutex_lock(&priv->wx_mutex);
412 412
413 ret = ieee80211_wx_set_freq(priv->ieee80211, a, wrqu, b); 413 ret = ieee80211_wx_set_freq(priv->ieee80211, a, wrqu, b);
414 414
415 up(&priv->wx_sem); 415 mutex_unlock(&priv->wx_mutex);
416 return ret; 416 return ret;
417} 417}
418 418
@@ -468,11 +468,11 @@ static int r8192_wx_set_wap(struct net_device *dev,
468 int ret; 468 int ret;
469 struct r8192_priv *priv = ieee80211_priv(dev); 469 struct r8192_priv *priv = ieee80211_priv(dev);
470 /* struct sockaddr *temp = (struct sockaddr *)awrq; */ 470 /* struct sockaddr *temp = (struct sockaddr *)awrq; */
471 down(&priv->wx_sem); 471 mutex_lock(&priv->wx_mutex);
472 472
473 ret = ieee80211_wx_set_wap(priv->ieee80211, info, awrq, extra); 473 ret = ieee80211_wx_set_wap(priv->ieee80211, info, awrq, extra);
474 474
475 up(&priv->wx_sem); 475 mutex_unlock(&priv->wx_mutex);
476 476
477 return ret; 477 return ret;
478 478
@@ -515,12 +515,12 @@ static int r8192_wx_set_enc(struct net_device *dev,
515 if (!priv->up) 515 if (!priv->up)
516 return -ENETDOWN; 516 return -ENETDOWN;
517 517
518 down(&priv->wx_sem); 518 mutex_lock(&priv->wx_mutex);
519 519
520 RT_TRACE(COMP_SEC, "Setting SW wep key"); 520 RT_TRACE(COMP_SEC, "Setting SW wep key");
521 ret = ieee80211_wx_set_encode(priv->ieee80211, info, wrqu, key); 521 ret = ieee80211_wx_set_encode(priv->ieee80211, info, wrqu, key);
522 522
523 up(&priv->wx_sem); 523 mutex_unlock(&priv->wx_mutex);
524 524
525 525
526 526
@@ -619,7 +619,7 @@ static int r8192_wx_set_retry(struct net_device *dev,
619 struct r8192_priv *priv = ieee80211_priv(dev); 619 struct r8192_priv *priv = ieee80211_priv(dev);
620 int err = 0; 620 int err = 0;
621 621
622 down(&priv->wx_sem); 622 mutex_lock(&priv->wx_mutex);
623 623
624 if (wrqu->retry.flags & IW_RETRY_LIFETIME || 624 if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
625 wrqu->retry.disabled){ 625 wrqu->retry.disabled){
@@ -652,7 +652,7 @@ static int r8192_wx_set_retry(struct net_device *dev,
652 652
653 rtl8192_commit(dev); 653 rtl8192_commit(dev);
654exit: 654exit:
655 up(&priv->wx_sem); 655 mutex_unlock(&priv->wx_mutex);
656 656
657 return err; 657 return err;
658} 658}
@@ -701,7 +701,7 @@ static int r8192_wx_set_sens(struct net_device *dev,
701 struct r8192_priv *priv = ieee80211_priv(dev); 701 struct r8192_priv *priv = ieee80211_priv(dev);
702 short err = 0; 702 short err = 0;
703 703
704 down(&priv->wx_sem); 704 mutex_lock(&priv->wx_mutex);
705 if (priv->rf_set_sens == NULL) { 705 if (priv->rf_set_sens == NULL) {
706 err = -1; /* we have not this support for this radio */ 706 err = -1; /* we have not this support for this radio */
707 goto exit; 707 goto exit;
@@ -712,7 +712,7 @@ static int r8192_wx_set_sens(struct net_device *dev,
712 err = -EINVAL; 712 err = -EINVAL;
713 713
714exit: 714exit:
715 up(&priv->wx_sem); 715 mutex_unlock(&priv->wx_mutex);
716 716
717 return err; 717 return err;
718} 718}
@@ -727,7 +727,7 @@ static int r8192_wx_set_enc_ext(struct net_device *dev,
727 struct ieee80211_device *ieee = priv->ieee80211; 727 struct ieee80211_device *ieee = priv->ieee80211;
728 728
729 729
730 down(&priv->wx_sem); 730 mutex_lock(&priv->wx_mutex);
731 ret = ieee80211_wx_set_encode_ext(priv->ieee80211, info, wrqu, extra); 731 ret = ieee80211_wx_set_encode_ext(priv->ieee80211, info, wrqu, extra);
732 732
733 { 733 {
@@ -790,7 +790,7 @@ static int r8192_wx_set_enc_ext(struct net_device *dev,
790 790
791end_hw_sec: 791end_hw_sec:
792 792
793 up(&priv->wx_sem); 793 mutex_unlock(&priv->wx_mutex);
794 return ret; 794 return ret;
795 795
796} 796}
@@ -801,9 +801,9 @@ static int r8192_wx_set_auth(struct net_device *dev,
801 int ret = 0; 801 int ret = 0;
802 struct r8192_priv *priv = ieee80211_priv(dev); 802 struct r8192_priv *priv = ieee80211_priv(dev);
803 803
804 down(&priv->wx_sem); 804 mutex_lock(&priv->wx_mutex);
805 ret = ieee80211_wx_set_auth(priv->ieee80211, info, &(data->param), extra); 805 ret = ieee80211_wx_set_auth(priv->ieee80211, info, &(data->param), extra);
806 up(&priv->wx_sem); 806 mutex_unlock(&priv->wx_mutex);
807 return ret; 807 return ret;
808} 808}
809 809
@@ -815,10 +815,10 @@ static int r8192_wx_set_mlme(struct net_device *dev,
815 int ret = 0; 815 int ret = 0;
816 struct r8192_priv *priv = ieee80211_priv(dev); 816 struct r8192_priv *priv = ieee80211_priv(dev);
817 817
818 down(&priv->wx_sem); 818 mutex_lock(&priv->wx_mutex);
819 ret = ieee80211_wx_set_mlme(priv->ieee80211, info, wrqu, extra); 819 ret = ieee80211_wx_set_mlme(priv->ieee80211, info, wrqu, extra);
820 820
821 up(&priv->wx_sem); 821 mutex_unlock(&priv->wx_mutex);
822 return ret; 822 return ret;
823} 823}
824 824
@@ -829,9 +829,9 @@ static int r8192_wx_set_gen_ie(struct net_device *dev,
829 int ret = 0; 829 int ret = 0;
830 struct r8192_priv *priv = ieee80211_priv(dev); 830 struct r8192_priv *priv = ieee80211_priv(dev);
831 831
832 down(&priv->wx_sem); 832 mutex_lock(&priv->wx_mutex);
833 ret = ieee80211_wx_set_gen_ie(priv->ieee80211, extra, data->data.length); 833 ret = ieee80211_wx_set_gen_ie(priv->ieee80211, extra, data->data.length);
834 up(&priv->wx_sem); 834 mutex_unlock(&priv->wx_mutex);
835 return ret; 835 return ret;
836 836
837 837
diff --git a/drivers/staging/unisys/visorbus/iovmcall_gnuc.h b/drivers/staging/unisys/visorbus/iovmcall_gnuc.h
index b08b6ecc8d31..98ea7f381a3c 100644
--- a/drivers/staging/unisys/visorbus/iovmcall_gnuc.h
+++ b/drivers/staging/unisys/visorbus/iovmcall_gnuc.h
@@ -22,7 +22,7 @@ __unisys_vmcall_gnuc(unsigned long tuple, unsigned long reg_ebx,
22 22
23 cpuid(0x00000001, &cpuid_eax, &cpuid_ebx, &cpuid_ecx, &cpuid_edx); 23 cpuid(0x00000001, &cpuid_eax, &cpuid_ebx, &cpuid_ecx, &cpuid_edx);
24 if (!(cpuid_ecx & 0x80000000)) 24 if (!(cpuid_ecx & 0x80000000))
25 return -1; 25 return -EPERM;
26 26
27 __asm__ __volatile__(".byte 0x00f, 0x001, 0x0c1" : "=a"(result) : 27 __asm__ __volatile__(".byte 0x00f, 0x001, 0x0c1" : "=a"(result) :
28 "a"(tuple), "b"(reg_ebx), "c"(reg_ecx)); 28 "a"(tuple), "b"(reg_ebx), "c"(reg_ecx));
@@ -40,7 +40,7 @@ __unisys_extended_vmcall_gnuc(unsigned long long tuple,
40 40
41 cpuid(0x00000001, &cpuid_eax, &cpuid_ebx, &cpuid_ecx, &cpuid_edx); 41 cpuid(0x00000001, &cpuid_eax, &cpuid_ebx, &cpuid_ecx, &cpuid_edx);
42 if (!(cpuid_ecx & 0x80000000)) 42 if (!(cpuid_ecx & 0x80000000))
43 return -1; 43 return -EPERM;
44 44
45 __asm__ __volatile__(".byte 0x00f, 0x001, 0x0c1" : "=a"(result) : 45 __asm__ __volatile__(".byte 0x00f, 0x001, 0x0c1" : "=a"(result) :
46 "a"(tuple), "b"(reg_ebx), "c"(reg_ecx), "d"(reg_edx)); 46 "a"(tuple), "b"(reg_ebx), "c"(reg_ecx), "d"(reg_edx));
diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c
index 3a147dbbd7b5..d32b8980a1cf 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -876,10 +876,10 @@ write_vbus_chp_info(struct visorchannel *chan,
876 int off = sizeof(struct channel_header) + hdr_info->chp_info_offset; 876 int off = sizeof(struct channel_header) + hdr_info->chp_info_offset;
877 877
878 if (hdr_info->chp_info_offset == 0) 878 if (hdr_info->chp_info_offset == 0)
879 return -1; 879 return -EFAULT;
880 880
881 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) 881 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
882 return -1; 882 return -EFAULT;
883 return 0; 883 return 0;
884} 884}
885 885
@@ -895,10 +895,10 @@ write_vbus_bus_info(struct visorchannel *chan,
895 int off = sizeof(struct channel_header) + hdr_info->bus_info_offset; 895 int off = sizeof(struct channel_header) + hdr_info->bus_info_offset;
896 896
897 if (hdr_info->bus_info_offset == 0) 897 if (hdr_info->bus_info_offset == 0)
898 return -1; 898 return -EFAULT;
899 899
900 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) 900 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
901 return -1; 901 return -EFAULT;
902 return 0; 902 return 0;
903} 903}
904 904
@@ -915,10 +915,10 @@ write_vbus_dev_info(struct visorchannel *chan,
915 (hdr_info->device_info_struct_bytes * devix); 915 (hdr_info->device_info_struct_bytes * devix);
916 916
917 if (hdr_info->dev_info_offset == 0) 917 if (hdr_info->dev_info_offset == 0)
918 return -1; 918 return -EFAULT;
919 919
920 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0) 920 if (visorchannel_write(chan, off, info, sizeof(*info)) < 0)
921 return -1; 921 return -EFAULT;
922 return 0; 922 return 0;
923} 923}
924 924
diff --git a/drivers/staging/unisys/visorbus/visorchipset.c b/drivers/staging/unisys/visorbus/visorchipset.c
index 5ba5936e2203..d248c946a13b 100644
--- a/drivers/staging/unisys/visorbus/visorchipset.c
+++ b/drivers/staging/unisys/visorbus/visorchipset.c
@@ -1613,7 +1613,7 @@ parahotplug_request_complete(int id, u16 active)
1613 } 1613 }
1614 1614
1615 spin_unlock(&parahotplug_request_list_lock); 1615 spin_unlock(&parahotplug_request_list_lock);
1616 return -1; 1616 return -EINVAL;
1617} 1617}
1618 1618
1619/* 1619/*
diff --git a/drivers/staging/unisys/visorhba/visorhba_main.c b/drivers/staging/unisys/visorhba/visorhba_main.c
index 6a4570d10642..120ba2097e02 100644
--- a/drivers/staging/unisys/visorhba/visorhba_main.c
+++ b/drivers/staging/unisys/visorhba/visorhba_main.c
@@ -16,6 +16,8 @@
16#include <linux/debugfs.h> 16#include <linux/debugfs.h>
17#include <linux/skbuff.h> 17#include <linux/skbuff.h>
18#include <linux/kthread.h> 18#include <linux/kthread.h>
19#include <linux/idr.h>
20#include <linux/seq_file.h>
19#include <scsi/scsi.h> 21#include <scsi/scsi.h>
20#include <scsi/scsi_host.h> 22#include <scsi/scsi_host.h>
21#include <scsi/scsi_cmnd.h> 23#include <scsi/scsi_cmnd.h>
@@ -33,7 +35,6 @@
33#define MAX_BUF 8192 35#define MAX_BUF 8192
34#define MAX_PENDING_REQUESTS (MIN_NUMSIGNALS * 2) 36#define MAX_PENDING_REQUESTS (MIN_NUMSIGNALS * 2)
35#define VISORHBA_ERROR_COUNT 30 37#define VISORHBA_ERROR_COUNT 30
36#define VISORHBA_OPEN_MAX 1
37 38
38static int visorhba_queue_command_lck(struct scsi_cmnd *scsicmd, 39static int visorhba_queue_command_lck(struct scsi_cmnd *scsicmd,
39 void (*visorhba_cmnd_done) 40 void (*visorhba_cmnd_done)
@@ -50,14 +51,7 @@ static int visorhba_pause(struct visor_device *dev,
50static int visorhba_resume(struct visor_device *dev, 51static int visorhba_resume(struct visor_device *dev,
51 visorbus_state_complete_func complete_func); 52 visorbus_state_complete_func complete_func);
52 53
53static ssize_t info_debugfs_read(struct file *file, char __user *buf,
54 size_t len, loff_t *offset);
55static int set_no_disk_inquiry_result(unsigned char *buf,
56 size_t len, bool is_lun0);
57static struct dentry *visorhba_debugfs_dir; 54static struct dentry *visorhba_debugfs_dir;
58static const struct file_operations debugfs_info_fops = {
59 .read = info_debugfs_read,
60};
61 55
62/* GUIDS for HBA channel type supported by this driver */ 56/* GUIDS for HBA channel type supported by this driver */
63static struct visor_channeltype_descriptor visorhba_channel_types[] = { 57static struct visor_channeltype_descriptor visorhba_channel_types[] = {
@@ -99,14 +93,6 @@ struct scsipending {
99 char cmdtype; /* Type of pointer that is being stored */ 93 char cmdtype; /* Type of pointer that is being stored */
100}; 94};
101 95
102/* Work Data for dar_work_queue */
103struct diskaddremove {
104 u8 add; /* 0-remove, 1-add */
105 struct Scsi_Host *shost; /* Scsi Host for this visorhba instance */
106 u32 channel, id, lun; /* Disk Path */
107 struct diskaddremove *next;
108};
109
110/* Each scsi_host has a host_data area that contains this struct. */ 96/* Each scsi_host has a host_data area that contains this struct. */
111struct visorhba_devdata { 97struct visorhba_devdata {
112 struct Scsi_Host *scsihost; 98 struct Scsi_Host *scsihost;
@@ -133,14 +119,21 @@ struct visorhba_devdata {
133 int devnum; 119 int devnum;
134 struct task_struct *thread; 120 struct task_struct *thread;
135 int thread_wait_ms; 121 int thread_wait_ms;
122
123 /*
124 * allows us to pass int handles back-and-forth between us and
125 * iovm, instead of raw pointers
126 */
127 struct idr idr;
128
129 struct dentry *debugfs_dir;
130 struct dentry *debugfs_info;
136}; 131};
137 132
138struct visorhba_devices_open { 133struct visorhba_devices_open {
139 struct visorhba_devdata *devdata; 134 struct visorhba_devdata *devdata;
140}; 135};
141 136
142static struct visorhba_devices_open visorhbas_open[VISORHBA_OPEN_MAX];
143
144#define for_each_vdisk_match(iter, list, match) \ 137#define for_each_vdisk_match(iter, list, match) \
145 for (iter = &list->head; iter->next; iter = iter->next) \ 138 for (iter = &list->head; iter->next; iter = iter->next) \
146 if ((iter->channel == match->channel) && \ 139 if ((iter->channel == match->channel) && \
@@ -191,7 +184,7 @@ static void visor_thread_stop(struct task_struct *task)
191 * Partition so that it can be handled when it completes. If new is 184 * Partition so that it can be handled when it completes. If new is
192 * NULL it is assumed the entry refers only to the cmdrsp. 185 * NULL it is assumed the entry refers only to the cmdrsp.
193 * Returns insert_location where entry was added, 186 * Returns insert_location where entry was added,
194 * SCSI_MLQUEUE_DEVICE_BUSY if it can't 187 * -EBUSY if it can't
195 */ 188 */
196static int add_scsipending_entry(struct visorhba_devdata *devdata, 189static int add_scsipending_entry(struct visorhba_devdata *devdata,
197 char cmdtype, void *new) 190 char cmdtype, void *new)
@@ -206,7 +199,7 @@ static int add_scsipending_entry(struct visorhba_devdata *devdata,
206 insert_location = (insert_location + 1) % MAX_PENDING_REQUESTS; 199 insert_location = (insert_location + 1) % MAX_PENDING_REQUESTS;
207 if (insert_location == (int)devdata->nextinsert) { 200 if (insert_location == (int)devdata->nextinsert) {
208 spin_unlock_irqrestore(&devdata->privlock, flags); 201 spin_unlock_irqrestore(&devdata->privlock, flags);
209 return -1; 202 return -EBUSY;
210 } 203 }
211 } 204 }
212 205
@@ -269,6 +262,62 @@ static struct uiscmdrsp *get_scsipending_cmdrsp(struct visorhba_devdata *ddata,
269} 262}
270 263
271/** 264/**
265 * simple_idr_get - associate a provided pointer with an int value
266 * 1 <= value <= INT_MAX, and return this int value;
267 * the pointer value can be obtained later by passing
268 * this int value to idr_find()
269 * @idrtable: the data object maintaining the pointer<-->int mappings
270 * @p: the pointer value to be remembered
271 * @lock: a spinlock used when exclusive access to idrtable is needed
272 */
273static unsigned int simple_idr_get(struct idr *idrtable, void *p,
274 spinlock_t *lock)
275{
276 int id;
277 unsigned long flags;
278
279 idr_preload(GFP_KERNEL);
280 spin_lock_irqsave(lock, flags);
281 id = idr_alloc(idrtable, p, 1, INT_MAX, GFP_NOWAIT);
282 spin_unlock_irqrestore(lock, flags);
283 idr_preload_end();
284 if (id < 0)
285 return 0; /* failure */
286 return (unsigned int)(id); /* idr_alloc() guarantees > 0 */
287}
288
289/**
290 * setup_scsitaskmgmt_handles - stash the necessary handles so that the
291 * completion processing logic for a taskmgmt
292 * cmd will be able to find who to wake up
293 * and where to stash the result
294 */
295static void setup_scsitaskmgmt_handles(struct idr *idrtable, spinlock_t *lock,
296 struct uiscmdrsp *cmdrsp,
297 wait_queue_head_t *event, int *result)
298{
299 /* specify the event that has to be triggered when this */
300 /* cmd is complete */
301 cmdrsp->scsitaskmgmt.notify_handle =
302 simple_idr_get(idrtable, event, lock);
303 cmdrsp->scsitaskmgmt.notifyresult_handle =
304 simple_idr_get(idrtable, result, lock);
305}
306
307/**
308 * cleanup_scsitaskmgmt_handles - forget handles created by
309 * setup_scsitaskmgmt_handles()
310 */
311static void cleanup_scsitaskmgmt_handles(struct idr *idrtable,
312 struct uiscmdrsp *cmdrsp)
313{
314 if (cmdrsp->scsitaskmgmt.notify_handle)
315 idr_remove(idrtable, cmdrsp->scsitaskmgmt.notify_handle);
316 if (cmdrsp->scsitaskmgmt.notifyresult_handle)
317 idr_remove(idrtable, cmdrsp->scsitaskmgmt.notifyresult_handle);
318}
319
320/**
272 * forward_taskmgmt_command - send taskmegmt command to the Service 321 * forward_taskmgmt_command - send taskmegmt command to the Service
273 * Partition 322 * Partition
274 * @tasktype: Type of taskmgmt command 323 * @tasktype: Type of taskmgmt command
@@ -303,10 +352,8 @@ static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
303 352
304 /* issue TASK_MGMT_ABORT_TASK */ 353 /* issue TASK_MGMT_ABORT_TASK */
305 cmdrsp->cmdtype = CMD_SCSITASKMGMT_TYPE; 354 cmdrsp->cmdtype = CMD_SCSITASKMGMT_TYPE;
306 /* specify the event that has to be triggered when this */ 355 setup_scsitaskmgmt_handles(&devdata->idr, &devdata->privlock, cmdrsp,
307 /* cmd is complete */ 356 &notifyevent, &notifyresult);
308 cmdrsp->scsitaskmgmt.notify_handle = (u64)&notifyevent;
309 cmdrsp->scsitaskmgmt.notifyresult_handle = (u64)&notifyresult;
310 357
311 /* save destination */ 358 /* save destination */
312 cmdrsp->scsitaskmgmt.tasktype = tasktype; 359 cmdrsp->scsitaskmgmt.tasktype = tasktype;
@@ -315,6 +362,8 @@ static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
315 cmdrsp->scsitaskmgmt.vdest.lun = scsidev->lun; 362 cmdrsp->scsitaskmgmt.vdest.lun = scsidev->lun;
316 cmdrsp->scsitaskmgmt.handle = scsicmd_id; 363 cmdrsp->scsitaskmgmt.handle = scsicmd_id;
317 364
365 dev_dbg(&scsidev->sdev_gendev,
366 "visorhba: initiating type=%d taskmgmt command\n", tasktype);
318 if (!visorchannel_signalinsert(devdata->dev->visorchannel, 367 if (!visorchannel_signalinsert(devdata->dev->visorchannel,
319 IOCHAN_TO_IOPART, 368 IOCHAN_TO_IOPART,
320 cmdrsp)) 369 cmdrsp))
@@ -327,17 +376,23 @@ static int forward_taskmgmt_command(enum task_mgmt_types tasktype,
327 msecs_to_jiffies(45000))) 376 msecs_to_jiffies(45000)))
328 goto err_del_scsipending_ent; 377 goto err_del_scsipending_ent;
329 378
379 dev_dbg(&scsidev->sdev_gendev,
380 "visorhba: taskmgmt type=%d success; result=0x%x\n",
381 tasktype, notifyresult);
330 if (tasktype == TASK_MGMT_ABORT_TASK) 382 if (tasktype == TASK_MGMT_ABORT_TASK)
331 scsicmd->result = DID_ABORT << 16; 383 scsicmd->result = DID_ABORT << 16;
332 else 384 else
333 scsicmd->result = DID_RESET << 16; 385 scsicmd->result = DID_RESET << 16;
334 386
335 scsicmd->scsi_done(scsicmd); 387 scsicmd->scsi_done(scsicmd);
336 388 cleanup_scsitaskmgmt_handles(&devdata->idr, cmdrsp);
337 return SUCCESS; 389 return SUCCESS;
338 390
339err_del_scsipending_ent: 391err_del_scsipending_ent:
392 dev_dbg(&scsidev->sdev_gendev,
393 "visorhba: taskmgmt type=%d not executed\n", tasktype);
340 del_scsipending_ent(devdata, scsicmd_id); 394 del_scsipending_ent(devdata, scsicmd_id);
395 cleanup_scsitaskmgmt_handles(&devdata->idr, cmdrsp);
341 return FAILED; 396 return FAILED;
342} 397}
343 398
@@ -606,64 +661,76 @@ static struct scsi_host_template visorhba_driver_template = {
606}; 661};
607 662
608/** 663/**
609 * info_debugfs_read - debugfs interface to dump visorhba states 664 * info_debugfs_show - debugfs interface to dump visorhba states
610 * @file: Debug file
611 * @buf: buffer to send back to user
612 * @len: len that can be written to buf
613 * @offset: offset into buf
614 * 665 *
615 * Dumps information about the visorhba driver and devices 666 * This presents a file in the debugfs tree named:
616 * TODO: Make this per vhba 667 * /visorhba/vbus<x>:dev<y>/info
617 * Returns bytes_read
618 */ 668 */
619static ssize_t info_debugfs_read(struct file *file, char __user *buf, 669static int info_debugfs_show(struct seq_file *seq, void *v)
620 size_t len, loff_t *offset)
621{ 670{
622 ssize_t bytes_read = 0; 671 struct visorhba_devdata *devdata = seq->private;
623 int str_pos = 0; 672
624 u64 phys_flags_addr; 673 seq_printf(seq, "max_buff_len = %u\n", devdata->max_buff_len);
625 int i; 674 seq_printf(seq, "interrupts_rcvd = %llu\n", devdata->interrupts_rcvd);
626 struct visorhba_devdata *devdata; 675 seq_printf(seq, "interrupts_disabled = %llu\n",
627 char *vbuf; 676 devdata->interrupts_disabled);
677 seq_printf(seq, "interrupts_notme = %llu\n",
678 devdata->interrupts_notme);
679 seq_printf(seq, "flags_addr = %p\n", devdata->flags_addr);
680 if (devdata->flags_addr) {
681 u64 phys_flags_addr =
682 virt_to_phys((__force void *)devdata->flags_addr);
683 seq_printf(seq, "phys_flags_addr = 0x%016llx\n",
684 phys_flags_addr);
685 seq_printf(seq, "FeatureFlags = %llu\n",
686 (__le64)readq(devdata->flags_addr));
687 }
688 seq_printf(seq, "acquire_failed_cnt = %llu\n",
689 devdata->acquire_failed_cnt);
628 690
629 if (len > MAX_BUF) 691 return 0;
630 len = MAX_BUF; 692}
631 vbuf = kzalloc(len, GFP_KERNEL); 693
632 if (!vbuf) 694static int info_debugfs_open(struct inode *inode, struct file *file)
633 return -ENOMEM; 695{
696 return single_open(file, info_debugfs_show, inode->i_private);
697}
634 698
635 for (i = 0; i < VISORHBA_OPEN_MAX; i++) { 699static const struct file_operations info_debugfs_fops = {
636 if (!visorhbas_open[i].devdata) 700 .owner = THIS_MODULE,
637 continue; 701 .open = info_debugfs_open,
638 702 .read = seq_read,
639 devdata = visorhbas_open[i].devdata; 703 .llseek = seq_lseek,
640 704 .release = single_release,
641 str_pos += scnprintf(vbuf + str_pos, 705};
642 len - str_pos, "max_buff_len:%u\n", 706
643 devdata->max_buff_len); 707/**
644 708 * complete_taskmgmt_command - complete task management
645 str_pos += scnprintf(vbuf + str_pos, len - str_pos, 709 * @cmdrsp: Response from the IOVM
646 "\ninterrupts_rcvd = %llu, interrupts_disabled = %llu\n", 710 *
647 devdata->interrupts_rcvd, 711 * Service Partition returned the result of the task management
648 devdata->interrupts_disabled); 712 * command. Wake up anyone waiting for it.
649 str_pos += scnprintf(vbuf + str_pos, 713 * Returns void
650 len - str_pos, "\ninterrupts_notme = %llu,\n", 714 */
651 devdata->interrupts_notme); 715static inline void complete_taskmgmt_command
652 phys_flags_addr = virt_to_phys((__force void *) 716(struct idr *idrtable, struct uiscmdrsp *cmdrsp, int result)
653 devdata->flags_addr); 717{
654 str_pos += scnprintf(vbuf + str_pos, len - str_pos, 718 wait_queue_head_t *wq =
655 "flags_addr = %p, phys_flags_addr=0x%016llx, FeatureFlags=%llu\n", 719 idr_find(idrtable, cmdrsp->scsitaskmgmt.notify_handle);
656 devdata->flags_addr, phys_flags_addr, 720 int *scsi_result_ptr =
657 (__le64)readq(devdata->flags_addr)); 721 idr_find(idrtable, cmdrsp->scsitaskmgmt.notifyresult_handle);
658 str_pos += scnprintf(vbuf + str_pos, 722
659 len - str_pos, "acquire_failed_cnt:%llu\n", 723 if (unlikely(!(wq && scsi_result_ptr))) {
660 devdata->acquire_failed_cnt); 724 pr_err("visorhba: no completion context; cmd will time out\n");
661 str_pos += scnprintf(vbuf + str_pos, len - str_pos, "\n"); 725 return;
662 } 726 }
663 727
664 bytes_read = simple_read_from_buffer(buf, len, offset, vbuf, str_pos); 728 /* copy the result of the taskmgmt and
665 kfree(vbuf); 729 * wake up the error handler that is waiting for this
666 return bytes_read; 730 */
731 pr_debug("visorhba: notifying initiator with result=0x%x\n", result);
732 *scsi_result_ptr = result;
733 wake_up_all(wq);
667} 734}
668 735
669/** 736/**
@@ -701,17 +768,8 @@ static void visorhba_serverdown_complete(struct visorhba_devdata *devdata)
701 break; 768 break;
702 case CMD_SCSITASKMGMT_TYPE: 769 case CMD_SCSITASKMGMT_TYPE:
703 cmdrsp = pendingdel->sent; 770 cmdrsp = pendingdel->sent;
704 cmdrsp->scsitaskmgmt.notifyresult_handle 771 complete_taskmgmt_command(&devdata->idr, cmdrsp,
705 = TASK_MGMT_FAILED; 772 TASK_MGMT_FAILED);
706 wake_up_all((wait_queue_head_t *)
707 cmdrsp->scsitaskmgmt.notify_handle);
708 break;
709 case CMD_VDISKMGMT_TYPE:
710 cmdrsp = pendingdel->sent;
711 cmdrsp->vdiskmgmt.notifyresult_handle
712 = VDISK_MGMT_FAILED;
713 wake_up_all((wait_queue_head_t *)
714 cmdrsp->vdiskmgmt.notify_handle);
715 break; 773 break;
716 default: 774 default:
717 break; 775 break;
@@ -878,89 +936,6 @@ complete_scsi_command(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd)
878 scsicmd->scsi_done(scsicmd); 936 scsicmd->scsi_done(scsicmd);
879} 937}
880 938
881/* DELETE VDISK TASK MGMT COMMANDS */
882static inline void complete_vdiskmgmt_command(struct uiscmdrsp *cmdrsp)
883{
884 /* copy the result of the taskmgmt and
885 * wake up the error handler that is waiting for this
886 */
887 cmdrsp->vdiskmgmt.notifyresult_handle = cmdrsp->vdiskmgmt.result;
888 wake_up_all((wait_queue_head_t *)cmdrsp->vdiskmgmt.notify_handle);
889}
890
891/**
892 * complete_taskmgmt_command - complete task management
893 * @cmdrsp: Response from the IOVM
894 *
895 * Service Partition returned the result of the task management
896 * command. Wake up anyone waiting for it.
897 * Returns void
898 */
899static inline void complete_taskmgmt_command(struct uiscmdrsp *cmdrsp)
900{
901 /* copy the result of the taskgmgt and
902 * wake up the error handler that is waiting for this
903 */
904 cmdrsp->vdiskmgmt.notifyresult_handle = cmdrsp->vdiskmgmt.result;
905 wake_up_all((wait_queue_head_t *)cmdrsp->scsitaskmgmt.notify_handle);
906}
907
908static struct work_struct dar_work_queue;
909static struct diskaddremove *dar_work_queue_head;
910static spinlock_t dar_work_queue_lock; /* Lock to protet dar_work_queue_head */
911static unsigned short dar_work_queue_sched;
912
913/**
914 * queue_disk_add_remove - IOSP has sent us a add/remove request
915 * @dar: disk add/remove request
916 *
917 * Queue the work needed to add/remove a disk.
918 * Returns void
919 */
920static inline void queue_disk_add_remove(struct diskaddremove *dar)
921{
922 unsigned long flags;
923
924 spin_lock_irqsave(&dar_work_queue_lock, flags);
925 if (!dar_work_queue_head) {
926 dar_work_queue_head = dar;
927 dar->next = NULL;
928 } else {
929 dar->next = dar_work_queue_head;
930 dar_work_queue_head = dar;
931 }
932 if (!dar_work_queue_sched) {
933 schedule_work(&dar_work_queue);
934 dar_work_queue_sched = 1;
935 }
936 spin_unlock_irqrestore(&dar_work_queue_lock, flags);
937}
938
939/**
940 * process_disk_notify - IOSP has sent a process disk notify event
941 * @shost: Scsi hot
942 * @cmdrsp: Response from the IOSP
943 *
944 * Queue it to the work queue.
945 * Return void.
946 */
947static void process_disk_notify(struct Scsi_Host *shost,
948 struct uiscmdrsp *cmdrsp)
949{
950 struct diskaddremove *dar;
951
952 dar = kzalloc(sizeof(*dar), GFP_ATOMIC);
953 if (!dar)
954 return;
955
956 dar->add = cmdrsp->disknotify.add;
957 dar->shost = shost;
958 dar->channel = cmdrsp->disknotify.channel;
959 dar->id = cmdrsp->disknotify.id;
960 dar->lun = cmdrsp->disknotify.lun;
961 queue_disk_add_remove(dar);
962}
963
964/** 939/**
965 * drain_queue - pull responses out of iochannel 940 * drain_queue - pull responses out of iochannel
966 * @cmdrsp: Response from the IOSP 941 * @cmdrsp: Response from the IOSP
@@ -973,7 +948,6 @@ static void
973drain_queue(struct uiscmdrsp *cmdrsp, struct visorhba_devdata *devdata) 948drain_queue(struct uiscmdrsp *cmdrsp, struct visorhba_devdata *devdata)
974{ 949{
975 struct scsi_cmnd *scsicmd; 950 struct scsi_cmnd *scsicmd;
976 struct Scsi_Host *shost = devdata->scsihost;
977 951
978 while (1) { 952 while (1) {
979 if (!visorchannel_signalremove(devdata->dev->visorchannel, 953 if (!visorchannel_signalremove(devdata->dev->visorchannel,
@@ -995,21 +969,12 @@ drain_queue(struct uiscmdrsp *cmdrsp, struct visorhba_devdata *devdata)
995 if (!del_scsipending_ent(devdata, 969 if (!del_scsipending_ent(devdata,
996 cmdrsp->scsitaskmgmt.handle)) 970 cmdrsp->scsitaskmgmt.handle))
997 break; 971 break;
998 complete_taskmgmt_command(cmdrsp); 972 complete_taskmgmt_command(&devdata->idr, cmdrsp,
999 } else if (cmdrsp->cmdtype == CMD_NOTIFYGUEST_TYPE) { 973 cmdrsp->scsitaskmgmt.result);
1000 /* The vHba pointer has no meaning in a 974 } else if (cmdrsp->cmdtype == CMD_NOTIFYGUEST_TYPE)
1001 * guest partition. Let's be safe and set it 975 dev_err_once(&devdata->dev->device,
1002 * to NULL now. Do not use it here! 976 "ignoring unsupported NOTIFYGUEST\n");
1003 */ 977 /* cmdrsp is now available for re-use */
1004 cmdrsp->disknotify.v_hba = NULL;
1005 process_disk_notify(shost, cmdrsp);
1006 } else if (cmdrsp->cmdtype == CMD_VDISKMGMT_TYPE) {
1007 if (!del_scsipending_ent(devdata,
1008 cmdrsp->vdiskmgmt.handle))
1009 break;
1010 complete_vdiskmgmt_command(cmdrsp);
1011 }
1012 /* cmdrsp is now available for resuse */
1013 } 978 }
1014} 979}
1015 980
@@ -1107,7 +1072,7 @@ static int visorhba_probe(struct visor_device *dev)
1107 struct Scsi_Host *scsihost; 1072 struct Scsi_Host *scsihost;
1108 struct vhba_config_max max; 1073 struct vhba_config_max max;
1109 struct visorhba_devdata *devdata = NULL; 1074 struct visorhba_devdata *devdata = NULL;
1110 int i, err, channel_offset; 1075 int err, channel_offset;
1111 u64 features; 1076 u64 features;
1112 1077
1113 scsihost = scsi_host_alloc(&visorhba_driver_template, 1078 scsihost = scsi_host_alloc(&visorhba_driver_template,
@@ -1122,9 +1087,9 @@ static int visorhba_probe(struct visor_device *dev)
1122 if (err < 0) 1087 if (err < 0)
1123 goto err_scsi_host_put; 1088 goto err_scsi_host_put;
1124 1089
1125 scsihost->max_id = (unsigned)max.max_id; 1090 scsihost->max_id = (unsigned int)max.max_id;
1126 scsihost->max_lun = (unsigned)max.max_lun; 1091 scsihost->max_lun = (unsigned int)max.max_lun;
1127 scsihost->cmd_per_lun = (unsigned)max.cmd_per_lun; 1092 scsihost->cmd_per_lun = (unsigned int)max.cmd_per_lun;
1128 scsihost->max_sectors = 1093 scsihost->max_sectors =
1129 (unsigned short)(max.max_io_size >> 9); 1094 (unsigned short)(max.max_io_size >> 9);
1130 scsihost->sg_tablesize = 1095 scsihost->sg_tablesize =
@@ -1136,16 +1101,24 @@ static int visorhba_probe(struct visor_device *dev)
1136 goto err_scsi_host_put; 1101 goto err_scsi_host_put;
1137 1102
1138 devdata = (struct visorhba_devdata *)scsihost->hostdata; 1103 devdata = (struct visorhba_devdata *)scsihost->hostdata;
1139 for (i = 0; i < VISORHBA_OPEN_MAX; i++) {
1140 if (!visorhbas_open[i].devdata) {
1141 visorhbas_open[i].devdata = devdata;
1142 break;
1143 }
1144 }
1145
1146 devdata->dev = dev; 1104 devdata->dev = dev;
1147 dev_set_drvdata(&dev->device, devdata); 1105 dev_set_drvdata(&dev->device, devdata);
1148 1106
1107 devdata->debugfs_dir = debugfs_create_dir(dev_name(&dev->device),
1108 visorhba_debugfs_dir);
1109 if (!devdata->debugfs_dir) {
1110 err = -ENOMEM;
1111 goto err_scsi_remove_host;
1112 }
1113 devdata->debugfs_info =
1114 debugfs_create_file("info", S_IRUSR | S_IRGRP,
1115 devdata->debugfs_dir, devdata,
1116 &info_debugfs_fops);
1117 if (!devdata->debugfs_info) {
1118 err = -ENOMEM;
1119 goto err_debugfs_dir;
1120 }
1121
1149 init_waitqueue_head(&devdata->rsp_queue); 1122 init_waitqueue_head(&devdata->rsp_queue);
1150 spin_lock_init(&devdata->privlock); 1123 spin_lock_init(&devdata->privlock);
1151 devdata->serverdown = false; 1124 devdata->serverdown = false;
@@ -1156,11 +1129,13 @@ static int visorhba_probe(struct visor_device *dev)
1156 channel_header.features); 1129 channel_header.features);
1157 err = visorbus_read_channel(dev, channel_offset, &features, 8); 1130 err = visorbus_read_channel(dev, channel_offset, &features, 8);
1158 if (err) 1131 if (err)
1159 goto err_scsi_remove_host; 1132 goto err_debugfs_info;
1160 features |= ULTRA_IO_CHANNEL_IS_POLLING; 1133 features |= ULTRA_IO_CHANNEL_IS_POLLING;
1161 err = visorbus_write_channel(dev, channel_offset, &features, 8); 1134 err = visorbus_write_channel(dev, channel_offset, &features, 8);
1162 if (err) 1135 if (err)
1163 goto err_scsi_remove_host; 1136 goto err_debugfs_info;
1137
1138 idr_init(&devdata->idr);
1164 1139
1165 devdata->thread_wait_ms = 2; 1140 devdata->thread_wait_ms = 2;
1166 devdata->thread = visor_thread_start(process_incoming_rsps, devdata, 1141 devdata->thread = visor_thread_start(process_incoming_rsps, devdata,
@@ -1170,6 +1145,12 @@ static int visorhba_probe(struct visor_device *dev)
1170 1145
1171 return 0; 1146 return 0;
1172 1147
1148err_debugfs_info:
1149 debugfs_remove(devdata->debugfs_info);
1150
1151err_debugfs_dir:
1152 debugfs_remove_recursive(devdata->debugfs_dir);
1153
1173err_scsi_remove_host: 1154err_scsi_remove_host:
1174 scsi_remove_host(scsihost); 1155 scsi_remove_host(scsihost);
1175 1156
@@ -1198,7 +1179,11 @@ static void visorhba_remove(struct visor_device *dev)
1198 scsi_remove_host(scsihost); 1179 scsi_remove_host(scsihost);
1199 scsi_host_put(scsihost); 1180 scsi_host_put(scsihost);
1200 1181
1182 idr_destroy(&devdata->idr);
1183
1201 dev_set_drvdata(&dev->device, NULL); 1184 dev_set_drvdata(&dev->device, NULL);
1185 debugfs_remove(devdata->debugfs_info);
1186 debugfs_remove_recursive(devdata->debugfs_dir);
1202} 1187}
1203 1188
1204/** 1189/**
@@ -1209,26 +1194,17 @@ static void visorhba_remove(struct visor_device *dev)
1209 */ 1194 */
1210static int visorhba_init(void) 1195static int visorhba_init(void)
1211{ 1196{
1212 struct dentry *ret;
1213 int rc = -ENOMEM; 1197 int rc = -ENOMEM;
1214 1198
1215 visorhba_debugfs_dir = debugfs_create_dir("visorhba", NULL); 1199 visorhba_debugfs_dir = debugfs_create_dir("visorhba", NULL);
1216 if (!visorhba_debugfs_dir) 1200 if (!visorhba_debugfs_dir)
1217 return -ENOMEM; 1201 return -ENOMEM;
1218 1202
1219 ret = debugfs_create_file("info", S_IRUSR, visorhba_debugfs_dir, NULL,
1220 &debugfs_info_fops);
1221
1222 if (!ret) {
1223 rc = -EIO;
1224 goto cleanup_debugfs;
1225 }
1226
1227 rc = visorbus_register_visor_driver(&visorhba_driver); 1203 rc = visorbus_register_visor_driver(&visorhba_driver);
1228 if (rc) 1204 if (rc)
1229 goto cleanup_debugfs; 1205 goto cleanup_debugfs;
1230 1206
1231 return rc; 1207 return 0;
1232 1208
1233cleanup_debugfs: 1209cleanup_debugfs:
1234 debugfs_remove_recursive(visorhba_debugfs_dir); 1210 debugfs_remove_recursive(visorhba_debugfs_dir);
diff --git a/drivers/staging/unisys/visorinput/visorinput.c b/drivers/staging/unisys/visorinput/visorinput.c
index 12a3570780fc..d67cd76327c0 100644
--- a/drivers/staging/unisys/visorinput/visorinput.c
+++ b/drivers/staging/unisys/visorinput/visorinput.c
@@ -506,7 +506,7 @@ calc_button(int x)
506 case 3: 506 case 3:
507 return BTN_RIGHT; 507 return BTN_RIGHT;
508 default: 508 default:
509 return -1; 509 return -EINVAL;
510 } 510 }
511} 511}
512 512
diff --git a/drivers/staging/unisys/visornic/visornic_main.c b/drivers/staging/unisys/visornic/visornic_main.c
index fd7c9a6cb6f3..a28388d3ddc2 100644
--- a/drivers/staging/unisys/visornic/visornic_main.c
+++ b/drivers/staging/unisys/visornic/visornic_main.c
@@ -1000,25 +1000,28 @@ visornic_set_multi(struct net_device *netdev)
1000 struct uiscmdrsp *cmdrsp; 1000 struct uiscmdrsp *cmdrsp;
1001 struct visornic_devdata *devdata = netdev_priv(netdev); 1001 struct visornic_devdata *devdata = netdev_priv(netdev);
1002 1002
1003 /* any filtering changes */ 1003 if (devdata->old_flags == netdev->flags)
1004 if (devdata->old_flags != netdev->flags) { 1004 return;
1005 if ((netdev->flags & IFF_PROMISC) != 1005
1006 (devdata->old_flags & IFF_PROMISC)) { 1006 if ((netdev->flags & IFF_PROMISC) ==
1007 cmdrsp = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC); 1007 (devdata->old_flags & IFF_PROMISC))
1008 if (!cmdrsp) 1008 goto out_save_flags;
1009 return; 1009
1010 cmdrsp->cmdtype = CMD_NET_TYPE; 1010 cmdrsp = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC);
1011 cmdrsp->net.type = NET_RCV_PROMISC; 1011 if (!cmdrsp)
1012 cmdrsp->net.enbdis.context = netdev; 1012 return;
1013 cmdrsp->net.enbdis.enable = 1013 cmdrsp->cmdtype = CMD_NET_TYPE;
1014 netdev->flags & IFF_PROMISC; 1014 cmdrsp->net.type = NET_RCV_PROMISC;
1015 visorchannel_signalinsert(devdata->dev->visorchannel, 1015 cmdrsp->net.enbdis.context = netdev;
1016 IOCHAN_TO_IOPART, 1016 cmdrsp->net.enbdis.enable =
1017 cmdrsp); 1017 netdev->flags & IFF_PROMISC;
1018 kfree(cmdrsp); 1018 visorchannel_signalinsert(devdata->dev->visorchannel,
1019 } 1019 IOCHAN_TO_IOPART,
1020 devdata->old_flags = netdev->flags; 1020 cmdrsp);
1021 } 1021 kfree(cmdrsp);
1022
1023out_save_flags:
1024 devdata->old_flags = netdev->flags;
1022} 1025}
1023 1026
1024/** 1027/**
@@ -1134,7 +1137,7 @@ repost_return(struct uiscmdrsp *cmdrsp, struct visornic_devdata *devdata,
1134 * 1137 *
1135 * Got a receive packet back from the IO Part, handle it and send 1138 * Got a receive packet back from the IO Part, handle it and send
1136 * it up the stack. 1139 * it up the stack.
1137 * Returns void 1140 * Returns 1 iff an skb was receieved, otherwise 0
1138 */ 1141 */
1139static int 1142static int
1140visornic_rx(struct uiscmdrsp *cmdrsp) 1143visornic_rx(struct uiscmdrsp *cmdrsp)
@@ -1145,7 +1148,6 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1145 int cc, currsize, off; 1148 int cc, currsize, off;
1146 struct ethhdr *eth; 1149 struct ethhdr *eth;
1147 unsigned long flags; 1150 unsigned long flags;
1148 int rx_count = 0;
1149 1151
1150 /* post new rcv buf to the other end using the cmdrsp we have at hand 1152 /* post new rcv buf to the other end using the cmdrsp we have at hand
1151 * post it without holding lock - but we'll use the signal lock to 1153 * post it without holding lock - but we'll use the signal lock to
@@ -1177,7 +1179,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1177 */ 1179 */
1178 spin_unlock_irqrestore(&devdata->priv_lock, flags); 1180 spin_unlock_irqrestore(&devdata->priv_lock, flags);
1179 repost_return(cmdrsp, devdata, skb, netdev); 1181 repost_return(cmdrsp, devdata, skb, netdev);
1180 return rx_count; 1182 return 0;
1181 } 1183 }
1182 1184
1183 spin_unlock_irqrestore(&devdata->priv_lock, flags); 1185 spin_unlock_irqrestore(&devdata->priv_lock, flags);
@@ -1196,7 +1198,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1196 if (repost_return(cmdrsp, devdata, skb, netdev) < 0) 1198 if (repost_return(cmdrsp, devdata, skb, netdev) < 0)
1197 dev_err(&devdata->netdev->dev, 1199 dev_err(&devdata->netdev->dev,
1198 "repost_return failed"); 1200 "repost_return failed");
1199 return rx_count; 1201 return 0;
1200 } 1202 }
1201 /* length rcvd is greater than firstfrag in this skb rcv buf */ 1203 /* length rcvd is greater than firstfrag in this skb rcv buf */
1202 skb->tail += RCVPOST_BUF_SIZE; /* amount in skb->data */ 1204 skb->tail += RCVPOST_BUF_SIZE; /* amount in skb->data */
@@ -1212,7 +1214,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1212 if (repost_return(cmdrsp, devdata, skb, netdev) < 0) 1214 if (repost_return(cmdrsp, devdata, skb, netdev) < 0)
1213 dev_err(&devdata->netdev->dev, 1215 dev_err(&devdata->netdev->dev,
1214 "repost_return failed"); 1216 "repost_return failed");
1215 return rx_count; 1217 return 0;
1216 } 1218 }
1217 skb->tail += skb->len; 1219 skb->tail += skb->len;
1218 skb->data_len = 0; /* nothing rcvd in frag_list */ 1220 skb->data_len = 0; /* nothing rcvd in frag_list */
@@ -1231,7 +1233,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1231 if (cmdrsp->net.rcv.rcvbuf[0] != skb) { 1233 if (cmdrsp->net.rcv.rcvbuf[0] != skb) {
1232 if (repost_return(cmdrsp, devdata, skb, netdev) < 0) 1234 if (repost_return(cmdrsp, devdata, skb, netdev) < 0)
1233 dev_err(&devdata->netdev->dev, "repost_return failed"); 1235 dev_err(&devdata->netdev->dev, "repost_return failed");
1234 return rx_count; 1236 return 0;
1235 } 1237 }
1236 1238
1237 if (cmdrsp->net.rcv.numrcvbufs > 1) { 1239 if (cmdrsp->net.rcv.numrcvbufs > 1) {
@@ -1313,10 +1315,9 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1313 /* drop packet - don't forward it up to OS */ 1315 /* drop packet - don't forward it up to OS */
1314 devdata->n_rcv_packets_not_accepted++; 1316 devdata->n_rcv_packets_not_accepted++;
1315 repost_return(cmdrsp, devdata, skb, netdev); 1317 repost_return(cmdrsp, devdata, skb, netdev);
1316 return rx_count; 1318 return 0;
1317 } while (0); 1319 } while (0);
1318 1320
1319 rx_count++;
1320 netif_receive_skb(skb); 1321 netif_receive_skb(skb);
1321 /* netif_rx returns various values, but "in practice most drivers 1322 /* netif_rx returns various values, but "in practice most drivers
1322 * ignore the return value 1323 * ignore the return value
@@ -1329,7 +1330,7 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1329 * new rcv buffer. 1330 * new rcv buffer.
1330 */ 1331 */
1331 repost_return(cmdrsp, devdata, skb, netdev); 1332 repost_return(cmdrsp, devdata, skb, netdev);
1332 return rx_count; 1333 return 1;
1333} 1334}
1334 1335
1335/** 1336/**
@@ -1339,13 +1340,11 @@ visornic_rx(struct uiscmdrsp *cmdrsp)
1339 * 1340 *
1340 * Setup initial values for the visornic based on channel and default 1341 * Setup initial values for the visornic based on channel and default
1341 * values. 1342 * values.
1342 * Returns a pointer to the devdata if successful, else NULL 1343 * Returns a pointer to the devdata structure
1343 */ 1344 */
1344static struct visornic_devdata * 1345static struct visornic_devdata *
1345devdata_initialize(struct visornic_devdata *devdata, struct visor_device *dev) 1346devdata_initialize(struct visornic_devdata *devdata, struct visor_device *dev)
1346{ 1347{
1347 if (!devdata)
1348 return NULL;
1349 devdata->dev = dev; 1348 devdata->dev = dev;
1350 devdata->incarnation_id = get_jiffies_64(); 1349 devdata->incarnation_id = get_jiffies_64();
1351 return devdata; 1350 return devdata;
@@ -1793,7 +1792,7 @@ static int visornic_probe(struct visor_device *dev)
1793 sizeof(struct sk_buff *), GFP_KERNEL); 1792 sizeof(struct sk_buff *), GFP_KERNEL);
1794 if (!devdata->rcvbuf) { 1793 if (!devdata->rcvbuf) {
1795 err = -ENOMEM; 1794 err = -ENOMEM;
1796 goto cleanup_rcvbuf; 1795 goto cleanup_netdev;
1797 } 1796 }
1798 1797
1799 /* set the net_xmit outstanding threshold */ 1798 /* set the net_xmit outstanding threshold */
@@ -1814,12 +1813,12 @@ static int visornic_probe(struct visor_device *dev)
1814 devdata->cmdrsp_rcv = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC); 1813 devdata->cmdrsp_rcv = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC);
1815 if (!devdata->cmdrsp_rcv) { 1814 if (!devdata->cmdrsp_rcv) {
1816 err = -ENOMEM; 1815 err = -ENOMEM;
1817 goto cleanup_cmdrsp_rcv; 1816 goto cleanup_rcvbuf;
1818 } 1817 }
1819 devdata->xmit_cmdrsp = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC); 1818 devdata->xmit_cmdrsp = kmalloc(SIZEOF_CMDRSP, GFP_ATOMIC);
1820 if (!devdata->xmit_cmdrsp) { 1819 if (!devdata->xmit_cmdrsp) {
1821 err = -ENOMEM; 1820 err = -ENOMEM;
1822 goto cleanup_xmit_cmdrsp; 1821 goto cleanup_cmdrsp_rcv;
1823 } 1822 }
1824 INIT_WORK(&devdata->timeout_reset, visornic_timeout_reset); 1823 INIT_WORK(&devdata->timeout_reset, visornic_timeout_reset);
1825 devdata->server_down = false; 1824 devdata->server_down = false;
@@ -2088,8 +2087,10 @@ static int visornic_init(void)
2088 goto cleanup_debugfs; 2087 goto cleanup_debugfs;
2089 2088
2090 err = visorbus_register_visor_driver(&visornic_driver); 2089 err = visorbus_register_visor_driver(&visornic_driver);
2091 if (!err) 2090 if (err)
2092 return 0; 2091 goto cleanup_debugfs;
2092
2093 return 0;
2093 2094
2094cleanup_debugfs: 2095cleanup_debugfs:
2095 debugfs_remove_recursive(visornic_debugfs_dir); 2096 debugfs_remove_recursive(visornic_debugfs_dir);
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 2056e9fd0138..1de1b3f6fb76 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -81,8 +81,6 @@ struct fence {
81 unsigned long flags; 81 unsigned long flags;
82 ktime_t timestamp; 82 ktime_t timestamp;
83 int status; 83 int status;
84 struct list_head child_list;
85 struct list_head active_list;
86}; 84};
87 85
88enum fence_flag_bits { 86enum fence_flag_bits {
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index 99403b19092f..28052cddaa03 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -256,8 +256,6 @@ struct st_sensor_data {
256 256
257#ifdef CONFIG_IIO_BUFFER 257#ifdef CONFIG_IIO_BUFFER
258irqreturn_t st_sensors_trigger_handler(int irq, void *p); 258irqreturn_t st_sensors_trigger_handler(int irq, void *p);
259
260int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf);
261#endif 259#endif
262 260
263#ifdef CONFIG_IIO_TRIGGER 261#ifdef CONFIG_IIO_TRIGGER
@@ -287,7 +285,7 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable);
287 285
288int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable); 286int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable);
289 287
290void st_sensors_power_enable(struct iio_dev *indio_dev); 288int st_sensors_power_enable(struct iio_dev *indio_dev);
291 289
292void st_sensors_power_disable(struct iio_dev *indio_dev); 290void st_sensors_power_disable(struct iio_dev *indio_dev);
293 291
diff --git a/include/linux/iio/sw_device.h b/include/linux/iio/sw_device.h
new file mode 100644
index 000000000000..23ca41515527
--- /dev/null
+++ b/include/linux/iio/sw_device.h
@@ -0,0 +1,70 @@
1/*
2 * Industrial I/O software device interface
3 *
4 * Copyright (c) 2016 Intel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#ifndef __IIO_SW_DEVICE
12#define __IIO_SW_DEVICE
13
14#include <linux/module.h>
15#include <linux/device.h>
16#include <linux/iio/iio.h>
17#include <linux/configfs.h>
18
19#define module_iio_sw_device_driver(__iio_sw_device_type) \
20 module_driver(__iio_sw_device_type, iio_register_sw_device_type, \
21 iio_unregister_sw_device_type)
22
23struct iio_sw_device_ops;
24
25struct iio_sw_device_type {
26 const char *name;
27 struct module *owner;
28 const struct iio_sw_device_ops *ops;
29 struct list_head list;
30 struct config_group *group;
31};
32
33struct iio_sw_device {
34 struct iio_dev *device;
35 struct iio_sw_device_type *device_type;
36 struct config_group group;
37};
38
39struct iio_sw_device_ops {
40 struct iio_sw_device* (*probe)(const char *);
41 int (*remove)(struct iio_sw_device *);
42};
43
44static inline
45struct iio_sw_device *to_iio_sw_device(struct config_item *item)
46{
47 return container_of(to_config_group(item), struct iio_sw_device,
48 group);
49}
50
51int iio_register_sw_device_type(struct iio_sw_device_type *dt);
52void iio_unregister_sw_device_type(struct iio_sw_device_type *dt);
53
54struct iio_sw_device *iio_sw_device_create(const char *, const char *);
55void iio_sw_device_destroy(struct iio_sw_device *);
56
57int iio_sw_device_type_configfs_register(struct iio_sw_device_type *dt);
58void iio_sw_device_type_configfs_unregister(struct iio_sw_device_type *dt);
59
60static inline
61void iio_swd_group_init_type_name(struct iio_sw_device *d,
62 const char *name,
63 struct config_item_type *type)
64{
65#ifdef CONFIG_CONFIGFS_FS
66 config_group_init_type_name(&d->group, name, type);
67#endif
68}
69
70#endif /* __IIO_SW_DEVICE */
diff --git a/include/uapi/linux/iio/types.h b/include/uapi/linux/iio/types.h
index b0916fc72cce..22e5e589a274 100644
--- a/include/uapi/linux/iio/types.h
+++ b/include/uapi/linux/iio/types.h
@@ -39,6 +39,7 @@ enum iio_chan_type {
39 IIO_RESISTANCE, 39 IIO_RESISTANCE,
40 IIO_PH, 40 IIO_PH,
41 IIO_UVINDEX, 41 IIO_UVINDEX,
42 IIO_ELECTRICALCONDUCTIVITY,
42}; 43};
43 44
44enum iio_modifier { 45enum iio_modifier {
diff --git a/tools/iio/Makefile b/tools/iio/Makefile
index 3a7a54f59713..5446d625e17d 100644
--- a/tools/iio/Makefile
+++ b/tools/iio/Makefile
@@ -1,16 +1,31 @@
1CC = $(CROSS_COMPILE)gcc 1CC = $(CROSS_COMPILE)gcc
2CFLAGS += -Wall -g -D_GNU_SOURCE 2CFLAGS += -Wall -g -D_GNU_SOURCE
3 3
4all: iio_event_monitor lsiio generic_buffer 4BINDIR=usr/bin
5INSTALL_PROGRAM=install -m 755 -p
6DEL_FILE=rm -f
7
8all: iio_event_monitor lsiio iio_generic_buffer
5 9
6iio_event_monitor: iio_event_monitor.o iio_utils.o 10iio_event_monitor: iio_event_monitor.o iio_utils.o
7 11
8lsiio: lsiio.o iio_utils.o 12lsiio: lsiio.o iio_utils.o
9 13
10generic_buffer: generic_buffer.o iio_utils.o 14iio_generic_buffer: iio_generic_buffer.o iio_utils.o
11 15
12%.o: %.c iio_utils.h 16%.o: %.c iio_utils.h
13 17
18install:
19 - mkdir -p $(INSTALL_ROOT)/$(BINDIR)
20 - $(INSTALL_PROGRAM) "iio_event_monitor" "$(INSTALL_ROOT)/$(BINDIR)/iio_event_monitor"
21 - $(INSTALL_PROGRAM) "lsiio" "$(INSTALL_ROOT)/$(BINDIR)/lsiio"
22 - $(INSTALL_PROGRAM) "iio_generic_buffer" "$(INSTALL_ROOT)/$(BINDIR)/iio_generic_buffer"
23
24uninstall:
25 $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/iio_event_monitor"
26 $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/lsiio"
27 $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/iio_generic_buffer"
28
14.PHONY: clean 29.PHONY: clean
15clean: 30clean:
16 rm -f *.o iio_event_monitor lsiio generic_buffer 31 rm -f *.o iio_event_monitor lsiio iio_generic_buffer
diff --git a/tools/iio/generic_buffer.c b/tools/iio/iio_generic_buffer.c
index 2429c78de940..e8c30521e99c 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/iio_generic_buffer.c
@@ -32,6 +32,8 @@
32#include <endian.h> 32#include <endian.h>
33#include <getopt.h> 33#include <getopt.h>
34#include <inttypes.h> 34#include <inttypes.h>
35#include <stdbool.h>
36#include <signal.h>
35#include "iio_utils.h" 37#include "iio_utils.h"
36 38
37/** 39/**
@@ -249,11 +251,82 @@ void print_usage(void)
249 " -e Disable wait for event (new data)\n" 251 " -e Disable wait for event (new data)\n"
250 " -g Use trigger-less mode\n" 252 " -g Use trigger-less mode\n"
251 " -l <n> Set buffer length to n samples\n" 253 " -l <n> Set buffer length to n samples\n"
252 " -n <name> Set device name (mandatory)\n" 254 " --device-name -n <name>\n"
253 " -t <name> Set trigger name\n" 255 " --device-num -N <num>\n"
256 " Set device by name or number (mandatory)\n"
257 " --trigger-name -t <name>\n"
258 " --trigger-num -T <num>\n"
259 " Set trigger by name or number\n"
254 " -w <n> Set delay between reads in us (event-less mode)\n"); 260 " -w <n> Set delay between reads in us (event-less mode)\n");
255} 261}
256 262
263enum autochan autochannels = AUTOCHANNELS_DISABLED;
264char *dev_dir_name = NULL;
265char *buf_dir_name = NULL;
266bool current_trigger_set = false;
267
268void cleanup(void)
269{
270 int ret;
271
272 /* Disable trigger */
273 if (dev_dir_name && current_trigger_set) {
274 /* Disconnect the trigger - just write a dummy name. */
275 ret = write_sysfs_string("trigger/current_trigger",
276 dev_dir_name, "NULL");
277 if (ret < 0)
278 fprintf(stderr, "Failed to disable trigger: %s\n",
279 strerror(-ret));
280 current_trigger_set = false;
281 }
282
283 /* Disable buffer */
284 if (buf_dir_name) {
285 ret = write_sysfs_int("enable", buf_dir_name, 0);
286 if (ret < 0)
287 fprintf(stderr, "Failed to disable buffer: %s\n",
288 strerror(-ret));
289 }
290
291 /* Disable channels if auto-enabled */
292 if (dev_dir_name && autochannels == AUTOCHANNELS_ACTIVE) {
293 ret = enable_disable_all_channels(dev_dir_name, 0);
294 if (ret)
295 fprintf(stderr, "Failed to disable all channels\n");
296 autochannels = AUTOCHANNELS_DISABLED;
297 }
298}
299
300void sig_handler(int signum)
301{
302 fprintf(stderr, "Caught signal %d\n", signum);
303 cleanup();
304 exit(-signum);
305}
306
307void register_cleanup(void)
308{
309 struct sigaction sa = { .sa_handler = sig_handler };
310 const int signums[] = { SIGINT, SIGTERM, SIGABRT };
311 int ret, i;
312
313 for (i = 0; i < ARRAY_SIZE(signums); ++i) {
314 ret = sigaction(signums[i], &sa, NULL);
315 if (ret) {
316 perror("Failed to register signal handler");
317 exit(-1);
318 }
319 }
320}
321
322static const struct option longopts[] = {
323 { "device-name", 1, 0, 'n' },
324 { "device-num", 1, 0, 'N' },
325 { "trigger-name", 1, 0, 't' },
326 { "trigger-num", 1, 0, 'T' },
327 { },
328};
329
257int main(int argc, char **argv) 330int main(int argc, char **argv)
258{ 331{
259 unsigned long num_loops = 2; 332 unsigned long num_loops = 2;
@@ -261,26 +334,25 @@ int main(int argc, char **argv)
261 unsigned long buf_len = 128; 334 unsigned long buf_len = 128;
262 335
263 int ret, c, i, j, toread; 336 int ret, c, i, j, toread;
264 int fp; 337 int fp = -1;
265 338
266 int num_channels; 339 int num_channels = 0;
267 char *trigger_name = NULL, *device_name = NULL; 340 char *trigger_name = NULL, *device_name = NULL;
268 char *dev_dir_name, *buf_dir_name;
269 341
270 int datardytrigger = 1; 342 char *data = NULL;
271 char *data;
272 ssize_t read_size; 343 ssize_t read_size;
273 int dev_num, trig_num; 344 int dev_num = -1, trig_num;
274 char *buffer_access; 345 char *buffer_access = NULL;
275 int scan_size; 346 int scan_size;
276 int noevents = 0; 347 int noevents = 0;
277 int notrigger = 0; 348 int notrigger = 0;
278 enum autochan autochannels = AUTOCHANNELS_DISABLED;
279 char *dummy; 349 char *dummy;
280 350
281 struct iio_channel_info *channels; 351 struct iio_channel_info *channels;
282 352
283 while ((c = getopt(argc, argv, "ac:egl:n:t:w:")) != -1) { 353 register_cleanup();
354
355 while ((c = getopt_long(argc, argv, "ac:egl:n:N:t:T:w:", longopts, NULL)) != -1) {
284 switch (c) { 356 switch (c) {
285 case 'a': 357 case 'a':
286 autochannels = AUTOCHANNELS_ENABLED; 358 autochannels = AUTOCHANNELS_ENABLED;
@@ -288,8 +360,10 @@ int main(int argc, char **argv)
288 case 'c': 360 case 'c':
289 errno = 0; 361 errno = 0;
290 num_loops = strtoul(optarg, &dummy, 10); 362 num_loops = strtoul(optarg, &dummy, 10);
291 if (errno) 363 if (errno) {
292 return -errno; 364 ret = -errno;
365 goto error;
366 }
293 367
294 break; 368 break;
295 case 'e': 369 case 'e':
@@ -301,49 +375,102 @@ int main(int argc, char **argv)
301 case 'l': 375 case 'l':
302 errno = 0; 376 errno = 0;
303 buf_len = strtoul(optarg, &dummy, 10); 377 buf_len = strtoul(optarg, &dummy, 10);
304 if (errno) 378 if (errno) {
305 return -errno; 379 ret = -errno;
380 goto error;
381 }
306 382
307 break; 383 break;
308 case 'n': 384 case 'n':
309 device_name = optarg; 385 device_name = strdup(optarg);
386 break;
387 case 'N':
388 errno = 0;
389 dev_num = strtoul(optarg, &dummy, 10);
390 if (errno) {
391 ret = -errno;
392 goto error;
393 }
310 break; 394 break;
311 case 't': 395 case 't':
312 trigger_name = optarg; 396 trigger_name = strdup(optarg);
313 datardytrigger = 0;
314 break; 397 break;
315 case 'w': 398 case 'T':
316 errno = 0; 399 errno = 0;
317 timedelay = strtoul(optarg, &dummy, 10); 400 trig_num = strtoul(optarg, &dummy, 10);
318 if (errno) 401 if (errno)
319 return -errno; 402 return -errno;
320 break; 403 break;
404 case 'w':
405 errno = 0;
406 timedelay = strtoul(optarg, &dummy, 10);
407 if (errno) {
408 ret = -errno;
409 goto error;
410 }
411 break;
321 case '?': 412 case '?':
322 print_usage(); 413 print_usage();
323 return -1; 414 ret = -1;
415 goto error;
324 } 416 }
325 } 417 }
326 418
327 if (!device_name) {
328 fprintf(stderr, "Device name not set\n");
329 print_usage();
330 return -1;
331 }
332
333 /* Find the device requested */ 419 /* Find the device requested */
334 dev_num = find_type_by_name(device_name, "iio:device"); 420 if (dev_num < 0 && !device_name) {
335 if (dev_num < 0) { 421 fprintf(stderr, "Device not set\n");
336 fprintf(stderr, "Failed to find the %s\n", device_name); 422 print_usage();
337 return dev_num; 423 ret = -1;
424 goto error;
425 } else if (dev_num >= 0 && device_name) {
426 fprintf(stderr, "Only one of --device-num or --device-name needs to be set\n");
427 print_usage();
428 ret = -1;
429 goto error;
430 } else if (dev_num < 0) {
431 dev_num = find_type_by_name(device_name, "iio:device");
432 if (dev_num < 0) {
433 fprintf(stderr, "Failed to find the %s\n", device_name);
434 ret = dev_num;
435 goto error;
436 }
338 } 437 }
339
340 printf("iio device number being used is %d\n", dev_num); 438 printf("iio device number being used is %d\n", dev_num);
341 439
342 ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); 440 ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
343 if (ret < 0) 441 if (ret < 0)
344 return -ENOMEM; 442 return -ENOMEM;
443 /* Fetch device_name if specified by number */
444 if (!device_name) {
445 device_name = malloc(IIO_MAX_NAME_LENGTH);
446 if (!device_name) {
447 ret = -ENOMEM;
448 goto error;
449 }
450 ret = read_sysfs_string("name", dev_dir_name, device_name);
451 if (ret < 0) {
452 fprintf(stderr, "Failed to read name of device %d\n", dev_num);
453 goto error;
454 }
455 }
345 456
346 if (!notrigger) { 457 if (notrigger) {
458 printf("trigger-less mode selected\n");
459 } if (trig_num > 0) {
460 char *trig_dev_name;
461 ret = asprintf(&trig_dev_name, "%strigger%d", iio_dir, trig_num);
462 if (ret < 0) {
463 return -ENOMEM;
464 }
465 trigger_name = malloc(IIO_MAX_NAME_LENGTH);
466 ret = read_sysfs_string("name", trig_dev_name, trigger_name);
467 free(trig_dev_name);
468 if (ret < 0) {
469 fprintf(stderr, "Failed to read trigger%d name from\n", trig_num);
470 return ret;
471 }
472 printf("iio trigger number being used is %d\n", trig_num);
473 } else {
347 if (!trigger_name) { 474 if (!trigger_name) {
348 /* 475 /*
349 * Build the trigger name. If it is device associated 476 * Build the trigger name. If it is device associated
@@ -354,7 +481,7 @@ int main(int argc, char **argv)
354 "%s-dev%d", device_name, dev_num); 481 "%s-dev%d", device_name, dev_num);
355 if (ret < 0) { 482 if (ret < 0) {
356 ret = -ENOMEM; 483 ret = -ENOMEM;
357 goto error_free_dev_dir_name; 484 goto error;
358 } 485 }
359 } 486 }
360 487
@@ -367,7 +494,7 @@ int main(int argc, char **argv)
367 "%s-trigger", device_name); 494 "%s-trigger", device_name);
368 if (ret < 0) { 495 if (ret < 0) {
369 ret = -ENOMEM; 496 ret = -ENOMEM;
370 goto error_free_dev_dir_name; 497 goto error;
371 } 498 }
372 } 499 }
373 500
@@ -376,12 +503,10 @@ int main(int argc, char **argv)
376 fprintf(stderr, "Failed to find the trigger %s\n", 503 fprintf(stderr, "Failed to find the trigger %s\n",
377 trigger_name); 504 trigger_name);
378 ret = trig_num; 505 ret = trig_num;
379 goto error_free_triggername; 506 goto error;
380 } 507 }
381 508
382 printf("iio trigger number being used is %d\n", trig_num); 509 printf("iio trigger number being used is %d\n", trig_num);
383 } else {
384 printf("trigger-less mode selected\n");
385 } 510 }
386 511
387 /* 512 /*
@@ -392,7 +517,7 @@ int main(int argc, char **argv)
392 if (ret) { 517 if (ret) {
393 fprintf(stderr, "Problem reading scan element information\n" 518 fprintf(stderr, "Problem reading scan element information\n"
394 "diag %s\n", dev_dir_name); 519 "diag %s\n", dev_dir_name);
395 goto error_free_triggername; 520 goto error;
396 } 521 }
397 if (num_channels && autochannels == AUTOCHANNELS_ENABLED) { 522 if (num_channels && autochannels == AUTOCHANNELS_ENABLED) {
398 fprintf(stderr, "Auto-channels selected but some channels " 523 fprintf(stderr, "Auto-channels selected but some channels "
@@ -407,7 +532,7 @@ int main(int argc, char **argv)
407 ret = enable_disable_all_channels(dev_dir_name, 1); 532 ret = enable_disable_all_channels(dev_dir_name, 1);
408 if (ret) { 533 if (ret) {
409 fprintf(stderr, "Failed to enable all channels\n"); 534 fprintf(stderr, "Failed to enable all channels\n");
410 goto error_free_triggername; 535 goto error;
411 } 536 }
412 537
413 /* This flags that we need to disable the channels again */ 538 /* This flags that we need to disable the channels again */
@@ -419,12 +544,12 @@ int main(int argc, char **argv)
419 fprintf(stderr, "Problem reading scan element " 544 fprintf(stderr, "Problem reading scan element "
420 "information\n" 545 "information\n"
421 "diag %s\n", dev_dir_name); 546 "diag %s\n", dev_dir_name);
422 goto error_disable_channels; 547 goto error;
423 } 548 }
424 if (!num_channels) { 549 if (!num_channels) {
425 fprintf(stderr, "Still no channels after " 550 fprintf(stderr, "Still no channels after "
426 "auto-enabling, giving up\n"); 551 "auto-enabling, giving up\n");
427 goto error_disable_channels; 552 goto error;
428 } 553 }
429 } 554 }
430 555
@@ -436,7 +561,7 @@ int main(int argc, char **argv)
436 "/*_en or pass -a to autoenable channels and " 561 "/*_en or pass -a to autoenable channels and "
437 "try again.\n", dev_dir_name); 562 "try again.\n", dev_dir_name);
438 ret = -ENOENT; 563 ret = -ENOENT;
439 goto error_free_triggername; 564 goto error;
440 } 565 }
441 566
442 /* 567 /*
@@ -448,7 +573,7 @@ int main(int argc, char **argv)
448 "%siio:device%d/buffer", iio_dir, dev_num); 573 "%siio:device%d/buffer", iio_dir, dev_num);
449 if (ret < 0) { 574 if (ret < 0) {
450 ret = -ENOMEM; 575 ret = -ENOMEM;
451 goto error_free_channels; 576 goto error;
452 } 577 }
453 578
454 if (!notrigger) { 579 if (!notrigger) {
@@ -463,34 +588,34 @@ int main(int argc, char **argv)
463 if (ret < 0) { 588 if (ret < 0) {
464 fprintf(stderr, 589 fprintf(stderr,
465 "Failed to write current_trigger file\n"); 590 "Failed to write current_trigger file\n");
466 goto error_free_buf_dir_name; 591 goto error;
467 } 592 }
468 } 593 }
469 594
470 /* Setup ring buffer parameters */ 595 /* Setup ring buffer parameters */
471 ret = write_sysfs_int("length", buf_dir_name, buf_len); 596 ret = write_sysfs_int("length", buf_dir_name, buf_len);
472 if (ret < 0) 597 if (ret < 0)
473 goto error_free_buf_dir_name; 598 goto error;
474 599
475 /* Enable the buffer */ 600 /* Enable the buffer */
476 ret = write_sysfs_int("enable", buf_dir_name, 1); 601 ret = write_sysfs_int("enable", buf_dir_name, 1);
477 if (ret < 0) { 602 if (ret < 0) {
478 fprintf(stderr, 603 fprintf(stderr,
479 "Failed to enable buffer: %s\n", strerror(-ret)); 604 "Failed to enable buffer: %s\n", strerror(-ret));
480 goto error_free_buf_dir_name; 605 goto error;
481 } 606 }
482 607
483 scan_size = size_from_channelarray(channels, num_channels); 608 scan_size = size_from_channelarray(channels, num_channels);
484 data = malloc(scan_size * buf_len); 609 data = malloc(scan_size * buf_len);
485 if (!data) { 610 if (!data) {
486 ret = -ENOMEM; 611 ret = -ENOMEM;
487 goto error_free_buf_dir_name; 612 goto error;
488 } 613 }
489 614
490 ret = asprintf(&buffer_access, "/dev/iio:device%d", dev_num); 615 ret = asprintf(&buffer_access, "/dev/iio:device%d", dev_num);
491 if (ret < 0) { 616 if (ret < 0) {
492 ret = -ENOMEM; 617 ret = -ENOMEM;
493 goto error_free_data; 618 goto error;
494 } 619 }
495 620
496 /* Attempt to open non blocking the access dev */ 621 /* Attempt to open non blocking the access dev */
@@ -498,7 +623,7 @@ int main(int argc, char **argv)
498 if (fp == -1) { /* TODO: If it isn't there make the node */ 623 if (fp == -1) { /* TODO: If it isn't there make the node */
499 ret = -errno; 624 ret = -errno;
500 fprintf(stderr, "Failed to open %s\n", buffer_access); 625 fprintf(stderr, "Failed to open %s\n", buffer_access);
501 goto error_free_buffer_access; 626 goto error;
502 } 627 }
503 628
504 for (j = 0; j < num_loops; j++) { 629 for (j = 0; j < num_loops; j++) {
@@ -511,7 +636,7 @@ int main(int argc, char **argv)
511 ret = poll(&pfd, 1, -1); 636 ret = poll(&pfd, 1, -1);
512 if (ret < 0) { 637 if (ret < 0) {
513 ret = -errno; 638 ret = -errno;
514 goto error_close_buffer_access; 639 goto error;
515 } else if (ret == 0) { 640 } else if (ret == 0) {
516 continue; 641 continue;
517 } 642 }
@@ -536,45 +661,21 @@ int main(int argc, char **argv)
536 num_channels); 661 num_channels);
537 } 662 }
538 663
539 /* Stop the buffer */ 664error:
540 ret = write_sysfs_int("enable", buf_dir_name, 0); 665 cleanup();
541 if (ret < 0)
542 goto error_close_buffer_access;
543 666
544 if (!notrigger) 667 if (fp >= 0 && close(fp) == -1)
545 /* Disconnect the trigger - just write a dummy name. */
546 ret = write_sysfs_string("trigger/current_trigger",
547 dev_dir_name, "NULL");
548 if (ret < 0)
549 fprintf(stderr, "Failed to write to %s\n",
550 dev_dir_name);
551
552error_close_buffer_access:
553 if (close(fp) == -1)
554 perror("Failed to close buffer"); 668 perror("Failed to close buffer");
555
556error_free_buffer_access:
557 free(buffer_access); 669 free(buffer_access);
558error_free_data:
559 free(data); 670 free(data);
560error_free_buf_dir_name:
561 free(buf_dir_name); 671 free(buf_dir_name);
562error_free_channels:
563 for (i = num_channels - 1; i >= 0; i--) { 672 for (i = num_channels - 1; i >= 0; i--) {
564 free(channels[i].name); 673 free(channels[i].name);
565 free(channels[i].generic_name); 674 free(channels[i].generic_name);
566 } 675 }
567 free(channels); 676 free(channels);
568error_free_triggername: 677 free(trigger_name);
569 if (datardytrigger) 678 free(device_name);
570 free(trigger_name);
571error_disable_channels:
572 if (autochannels == AUTOCHANNELS_ACTIVE) {
573 ret = enable_disable_all_channels(dev_dir_name, 0);
574 if (ret)
575 fprintf(stderr, "Failed to disable all channels\n");
576 }
577error_free_dev_dir_name:
578 free(dev_dir_name); 679 free(dev_dir_name);
579 680
580 return ret; 681 return ret;